feat(core): allow setting node/edge type with generic

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2023-02-01 23:31:54 +01:00
committed by Braks
parent 94a094aa9e
commit 7fa9203ccb
2 changed files with 20 additions and 9 deletions

View File

@@ -147,20 +147,29 @@ export interface EdgePositions {
}
/** Internal edge type */
export type GraphEdge<Data = ElementData, CustomEvents extends Record<string, CustomEvent> = any> = Edge<Data, CustomEvents> & {
export type GraphEdge<
Data = ElementData,
CustomEvents extends Record<string, CustomEvent> = any,
Type extends string = string,
> = Edge<Data, CustomEvents> & {
selected?: boolean
sourceNode: GraphNode
targetNode: GraphNode
data: Data
events: Partial<EdgeEventsHandler<CustomEvents>>
type: Type
} & EdgePositions
/** these props are passed to edge components */
export interface EdgeProps<Data = ElementData, CustomEvents = {}> extends EdgeLabelOptions, EdgePositions {
export interface EdgeProps<Data = ElementData, CustomEvents = {}, Type extends string = string>
extends EdgeLabelOptions,
EdgePositions {
id: string
sourceNode: GraphNode
targetNode: GraphNode
type?: keyof DefaultEdgeTypes | string
source: string
target: string
type?: Type
label?: string | VNode | Component<EdgeTextProps> | Object
style?: CSSProperties
selected?: boolean
@@ -168,8 +177,6 @@ export interface EdgeProps<Data = ElementData, CustomEvents = {}> extends EdgeLa
targetPosition: Position
sourceHandleId?: string
targetHandleId?: string
source: string
target: string
animated?: boolean
updatable?: boolean
markerStart: string

View File

@@ -86,8 +86,11 @@ export interface Node<Data = ElementData, CustomEvents extends Record<string, Cu
ariaLabel?: string
}
export interface GraphNode<Data = ElementData, CustomEvents extends Record<string, CustomEvent> = any>
extends Node<Data, CustomEvents> {
export interface GraphNode<
Data = ElementData,
CustomEvents extends Record<string, CustomEvent> = any,
Type extends string = string,
> extends Node<Data, CustomEvents> {
/** absolute position in relation to parent elements + z-index */
computedPosition: XYZPosition
handleBounds: NodeHandleBounds
@@ -100,14 +103,15 @@ export interface GraphNode<Data = ElementData, CustomEvents extends Record<strin
initialized: boolean
data: Data
events: Partial<NodeEventsHandler<CustomEvents>>
type: Type
}
/** these props are passed to node components */
export interface NodeProps<Data = ElementData, CustomEvents = {}> {
export interface NodeProps<Data = ElementData, CustomEvents = {}, Type extends string = keyof DefaultNodeTypes> {
/** unique node id */
id: string
/** node type */
type: keyof DefaultNodeTypes | string
type?: Type
/** is node selected */
selected: boolean
/** can node handles be connected */