feat(nodes): Add PositionFunc as node position type
* Allows position to be set relative to another node
This commit is contained in:
@@ -10,13 +10,17 @@ export type NodeHandleBounds = {
|
||||
target?: HandleElement[]
|
||||
}
|
||||
|
||||
type WidthHeight = number | `${`parent` | string}(${`+` | `-`}${number})`
|
||||
type PositionFunc = <Data = ElementData>(
|
||||
node: GraphNode<Data>,
|
||||
currNodes: GraphNode<Data>[],
|
||||
parentNode: GraphNode<Data>,
|
||||
) => XYPosition
|
||||
type WidthFunc = <Data = ElementData>(node: GraphNode<Data>) => number | string | void
|
||||
type HeightFunc = <Data = ElementData>(node: GraphNode<Data>) => number | string | void
|
||||
|
||||
export interface Node<Data = ElementData> extends Element<Data> {
|
||||
/** node position x, y */
|
||||
position: XYPosition
|
||||
/** initial node position x, y */
|
||||
position: XYPosition | PositionFunc
|
||||
/** node type, can be a default type or a custom type */
|
||||
type?: keyof DefaultNodeTypes | string
|
||||
/** handle position */
|
||||
@@ -56,6 +60,8 @@ export interface Node<Data = ElementData> extends Element<Data> {
|
||||
}
|
||||
|
||||
export interface GraphNode<Data = ElementData> extends Node<Data> {
|
||||
/** current node position x, y */
|
||||
position: XYPosition
|
||||
/** absolute position in relation to parent elements + z-index */
|
||||
computedPosition: XYZPosition
|
||||
handleBounds: NodeHandleBounds
|
||||
|
||||
Reference in New Issue
Block a user