Skip to content

Commit

Permalink
refactor(core,nodes)!: use NodeProps from system
Browse files Browse the repository at this point in the history
Signed-off-by: braks <[email protected]>
  • Loading branch information
bcakmakoglu committed Aug 19, 2024
1 parent 9d3b534 commit ee74bee
Showing 1 changed file with 6 additions and 86 deletions.
92 changes: 6 additions & 86 deletions packages/core/src/types/node.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { Component, VNode } from 'vue'
import type { NodeBase } from '@xyflow/system'
import type { Dimensions, Position, Styles, XYPosition, XYZPosition } from './flow'
import type { HandleConnectable, HandleElement, ValidConnectionFunc } from './handle'
import type { NodeEventsOn } from './hooks'
import type { NodeBase, NodeProps as NodePropsBase } from '@xyflow/system'
import type { Styles } from './flow'
import type { HandleConnectable, HandleElement } from './handle'

export type ElementData = Record<string, unknown>

Expand All @@ -25,17 +23,11 @@ export interface NodeHandleBounds {
target?: HandleElement[]
}

/** @deprecated will be removed in next major release */
export type WidthFunc = (node: GraphNode) => number | string | void

/** @deprecated will be removed in next major release */
export type HeightFunc = (node: GraphNode) => number | string | void

/**
* The node data structure that gets used for the nodes prop.
* @public
*/
export interface Node<NodeData extends Record<string, unknown> = Record<string, unknown>, NodeType extends string = string>
export interface Node<NodeData extends ElementData = ElementData, NodeType extends string = string>
extends Omit<NodeBase<NodeData, NodeType>, 'connectable' | 'extent' | 'origin'> {
/** Disable/enable connecting node */
connectable?: HandleConnectable
Expand All @@ -47,80 +39,8 @@ export interface Node<NodeData extends Record<string, unknown> = Record<string,
style?: Styles
}

export interface GraphNode<Data extends ElementData = ElementData, Type extends string = string> extends Node<Data, Type> {
/** absolute position in relation to parent elements + z-index */
computedPosition: XYZPosition
handleBounds: NodeHandleBounds
/** node width, height */
dimensions: Dimensions
isParent: boolean
selected: boolean
resizing: boolean
dragging: boolean
}

/** these props are passed to node components */
export interface NodeProps<Data = ElementData, CustomEvents = object, Type extends string = string> {
/** unique node id */
id: string
/** node type */
type: Type
/** is node selected */
selected: boolean
export interface NodeProps<NodeType extends NodeBase = NodeBase> extends Omit<NodePropsBase<NodeType>, 'isConnectable'> {
/** can node handles be connected, you need to forward this to your handles for this prop to have any effect */
connectable: HandleConnectable
/**
* @deprecated - will be removed in next major release and replaced with `computedPosition`
* node x, y (relative) position on graph
*/
position: XYPosition
/** dom element dimensions (width, height) */
dimensions: Dimensions
/**
* @deprecated - will be removed in next major release and replaced with `{ data: { label: string | VNode | Component } }`
* node label, either pass a string or a VNode
* For example like this: `h('div', props, children)`)
* Object is just a type-hack for Vue, ignore that
*/
label?: string | VNode | Component | object
/**
* @deprecated will be removed in next major release
* called when used as target for new connection
*/
isValidTargetPos?: ValidConnectionFunc
/**
* @deprecated will be removed in next major release
* called when used as source for new connection
*/
isValidSourcePos?: ValidConnectionFunc
/**
* @deprecated - will be removed in next major release. Use `parentNodeId` instead
* parent node id
*/
parent?: string
/**
* todo: rename to `parentId` in next major release
* parent node id
*/
parentNodeId?: string
/** is node currently dragging */
dragging: boolean
/** is node currently resizing */
resizing: boolean
/** node z-index */
zIndex: number
/** handle position */
targetPosition?: Position
/** handle position */
sourcePosition?: Position
/** drag handle query selector */
dragHandle?: string

/** additional data of node */
data: Data
/**
* @deprecated - will be removed in next major release
* contextual and custom events of node
*/
events: NodeEventsOn<CustomEvents>
isConnectable: HandleConnectable
}

0 comments on commit ee74bee

Please sign in to comment.