NodeHelpers
Methods that helps describe a specified Node.
Usage#
useEditor hook#
You can access the NodeHelpers via the node query method in the useEditor hook.
User Component rules#
NodeHelpers can also be accessed via the last parameter of each User Component rules.
Methods#
get#
Get Node object from id
Returns#
Node
descendants#
Returns an array of Node ids of all child Nodes of a given Node.
Parameters#
deepbooleanIf set to true, retrieve all descendants in nested levels. Default is falseincludeOnly?'childNodes' | 'linkedNodes'Get descendants that are either childNodes or linkedNodes. If unset, get all descendants
Returns#
NodeId[]
ancestors#
Returns an array of Node ids of all ancestors
Returns#
NodeId[]
linkedNodes#
Returns an array of linked Node ids
Returns#
NodeId[]
childNodes#
Returns an array of child Node ids
Returns#
NodeId[]
isRoot#
Returns true if a given Node is the Root Node
Returns#
boolean
isCanvas#
Check if a given Node is a Canvas
Returns#
boolean
isLinkedNode#
Check if a given Node is linked to the parent Node via an arbitary id
Returns#
boolean
isDeletable#
A Node may be deleted as long as it is not one of the following:
- Root Node
- Top-level Node
Parameters#
nodeNodeThe Node object to check
Returns#
boolean
isTopLevelNode#
A Node is considered top-level if it's one of the following:
- The Root Node
- A linked Node defined inside a User Component
Parameters#
nodeNodeThe Node object to check
Returns#
boolean
isParentOfTopLevelNode#
This returns true if a Node's User Component defines a <Element /> in its render method.
Returns#
boolean
isDraggable#
A Node may be dragged and moved if it satisfies both of the following conditions:
- The Node is an immediate child of a Canvas Node, hence it's draggable
- The Node's
canDragrule allows it to be moved
Parameters#
onError(err: string) => voidError callback
Returns#
boolean
isDroppable#
Check if a Node is Droppable relative to the target Node.
Parameters#
targetIdNodeIdThe target NodeonError(err: string) => voidError callback
Returns#
boolean
Example#
In the following example, we're checking if our MyCanvas component would be able to accept the current selected Node in the editor.
toSerializedNode#
Gets the current Node in it's SerializedNode form
Returns#
SerializedNode
toNodeTree#
Gets the current Node and its descendants in its NodeTree form
Parameters#
includeOnly?'childNodes' | 'linkedNodes'Get descendants that are either childNodes or linkedNodes. If unset, get all descendants
Returns#
NodeTree