NodeHelpers
Methods that helps describe a specified Node
.
#
Usage#
useEditor hookYou can access the NodeHelpers via the node
query method in the useEditor
hook.
#
User Component rulesNodeHelpers can also be accessed via the last parameter of each User Component rules.
#
Methods#
getGet Node
object from id
#
ReturnsNode
#
descendantsReturns an array of Node ids of all child Nodes of a given Node.
#
Parametersdeep
booleanIf 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
#
ReturnsNodeId[]
#
ancestorsReturns an array of Node ids of all ancestors
#
ReturnsNodeId[]
#
linkedNodesReturns an array of linked Node ids
#
ReturnsNodeId[]
#
childNodesReturns an array of child Node ids
#
ReturnsNodeId[]
#
isRootReturns true
if a given Node is the Root Node
#
Returnsboolean
#
isCanvasCheck if a given Node is a Canvas
#
Returnsboolean
#
isLinkedNodeCheck if a given Node is linked to the parent Node via an arbitary id
#
Returnsboolean
#
isDeletableA Node may be deleted as long as it is not one of the following:
- Root Node
- Top-level Node
#
Parametersnode
NodeThe Node object to check
#
Returnsboolean
#
isTopLevelNodeA Node is considered top-level if it's one of the following:
- The Root Node
- A linked Node defined inside a User Component
#
Parametersnode
NodeThe Node object to check
#
Returnsboolean
#
isParentOfTopLevelNodeThis returns true
if a Node's User Component defines a <Element />
in its render method.
#
Returnsboolean
#
isDraggableA 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
canDrag
rule allows it to be moved
#
ParametersonError
(err: string) => voidError callback
#
Returnsboolean
#
isDroppableCheck if a Node is Droppable relative to the target Node.
#
ParameterstargetId
NodeIdThe target NodeonError
(err: string) => voidError callback
#
Returnsboolean
#
ExampleIn the following example, we're checking if our MyCanvas
component would be able to accept the current selected Node in the editor.
#
toSerializedNodeGets the current Node in it's SerializedNode
form
#
ReturnsSerializedNode
#
toNodeTreeGets the current Node and its descendants in its NodeTree
form
#
ParametersincludeOnly?
'childNodes' | 'linkedNodes'Get descendants that are either childNodes or linkedNodes. If unset, get all descendants
#
ReturnsNodeTree