chore(types): add element data typing

This commit is contained in:
Braks
2022-04-04 21:42:48 +02:00
parent 59ac64564a
commit 4d901ae4e8
3 changed files with 15 additions and 15 deletions
+5 -5
View File
@@ -1,4 +1,4 @@
import { XYPosition, Dimensions } from './flow'
import { XYPosition, Dimensions, ElementData } from './flow'
import { NodeHandleBounds, Node } from './node'
import { Edge } from './edge'
@@ -27,12 +27,12 @@ export type NodeRemoveChange = {
type: 'remove'
}
export type NodeAddChange<NodeData = any> = {
export type NodeAddChange<NodeData = ElementData> = {
item: Node<NodeData>
type: 'add'
}
export type NodeResetChange<NodeData = any> = {
export type NodeResetChange<NodeData = ElementData> = {
item: Node<NodeData>
type: 'reset'
}
@@ -47,11 +47,11 @@ export type NodeChange =
export type EdgeSelectionChange = NodeSelectionChange
export type EdgeRemoveChange = NodeRemoveChange
export type EdgeAddChange<EdgeData = any> = {
export type EdgeAddChange<EdgeData = ElementData> = {
item: Edge<EdgeData>
type: 'add'
}
export type EdgeResetChange<EdgeData = any> = {
export type EdgeResetChange<EdgeData = ElementData> = {
item: Edge<EdgeData>
type: 'reset'
}
+6 -6
View File
@@ -62,14 +62,14 @@ export interface ControlEvents {
}
/** expects a node and returns a color value */
export type MiniMapNodeFunc<Data = any> = (node: Node<Data> | GraphNode<Data>) => string
export type MiniMapNodeFunc<Data = ElementData> = (node: Node<Data> | GraphNode<Data>) => string
// hack for vue-type imports
type MiniMapNodeFunc2<Data = any> = (node: Node<Data> | GraphNode<Data>) => string
type MiniMapNodeFunc3<Data = any> = (node: Node<Data> | GraphNode<Data>) => string
type MiniMapNodeFunc2<Data = ElementData> = (node: Node<Data> | GraphNode<Data>) => string
type MiniMapNodeFunc3<Data = ElementData> = (node: Node<Data> | GraphNode<Data>) => string
export type ShapeRendering = 'inherit' | 'auto' | 'geometricPrecision' | 'optimizeSpeed' | 'crispEdges' | undefined
export type ShapeRendering = CSSProperties['shapeRendering']
export interface MiniMapProps<Data = any> {
export interface MiniMapProps<Data = ElementData> {
/** Node color, can be either a string or a string func that receives the current node */
nodeColor?: string | MiniMapNodeFunc<Data>
/** Node stroke color, can be either a string or a string func that receives the current node */
@@ -90,7 +90,7 @@ export interface MiniMapNodeProps {
dimensions: Dimensions
borderRadius?: number
color?: string
shapeRendering?: CSSProperties['shapeRendering']
shapeRendering?: ShapeRendering
strokeColor?: string
strokeWidth?: number
}
+4 -4
View File
@@ -10,7 +10,7 @@ export type NodeHandleBounds = {
target?: HandleElement[]
}
export interface Node<T = ElementData> extends Element<T> {
export interface Node<Data = ElementData> extends Element<Data> {
/** node position x, y */
position: XYPosition
/** node type, can be a default type or a custom type */
@@ -37,7 +37,7 @@ export interface Node<T = ElementData> extends Element<T> {
parentNode?: string
}
export interface GraphNode<T = ElementData> extends Node<T> {
export interface GraphNode<Data = ElementData> extends Node<Data> {
/** absolute position in relation to parent elements + z-index */
computedPosition: XYZPosition
handleBounds: NodeHandleBounds
@@ -49,12 +49,12 @@ export interface GraphNode<T = ElementData> extends Node<T> {
}
/** these props are passed to node components */
export interface NodeProps<T = ElementData> {
export interface NodeProps<Data = ElementData> {
id: string
/** node DOM-element */
nodeElement: HTMLDivElement
type: string
data: T
data: Data
selected: boolean
connectable: boolean
/** absolute position in relation to parent elements + z-index */