DocumentNode
The Document node is the root node. Each browser tab can have only one document node, and each of its children must be a PageNode
.
Most plugins do not need to use this node unless they are creating new pages or performing document-wide operations. In the latter case, it is recommended to only read and not write, as the user may not see the changes made on a different page.
Document node properties
type
- Readonly:
true
- Type:
BOOLEAN_OPERATION
The node type, which for DocumentNode nodes is the string DOCUMENT
.
children
- Readonly:
true
- Type:
ReadonlyArray<PageNode>
The direct child of the current node.
appendChild
- Type:
appendChild(child: PageNode): void
Adds the given node child
as a direct child of the current node.
After
appendChild
, therelativeTransform
of thechild
node is maintained by default. Due to changes in the parent layer ofchild
, the position of thechild
node on the canvas may change; if you want to maintain the position of thechild
node, you can SetpreserveAbsolutePostion
totrue
.
insertChild
- Type:
insertChild(index: number, child: PageNode): void
Suppose a group has three children, A, B, and C. Now call the insertChild method to insert layer node D.
insertChild(0, D)
, the order of child nodes is: D, A, B, C.insertChild(1, D)
, the order of child nodes is: A, D, B, C.insertChild(2, D)
, the order of child nodes is: A, B, D, C.insertChild(3, D)
, the order of child nodes is: A, B, C, D.
findChildren
- Type:
findChildren(callback?: (node: PageNode) => boolean): PageNode[]
Similar to findAll
, except that findChildren
will only look in the direct children of the current node (not the children of the children).
findChild
- Type:
findChild(callback: (node: PageNode) => boolean): PageNode | null
Similar to findOne
, except that findChild
will only look in the direct children of the current node (excluding children of children).
findAll
- Type:
findAll(callback?: (node: PageNode) => boolean): PageNode[]
Finds the entire subtree starting from the current node, calls the callback
function for each node, and returns all nodes whose return value is true
for the callback
function.
findOne
- Type:
findOne(callback: (node: PageNode) => boolean): PageNode | null
Find the entire node tree starting from the current node, call the callback
function for each node, and return the first node whose return value is true
for the callback
function.
findAllWithCriteria
- Type:
findAllWithCriteria<T extends NodeType[]>(criteria: { types: T }): Array<{ type: T[number] } & (PageNode | SceneNode)>
Searches the entire subtree (children of this node, children of its children, etc.). Returns all nodes that satisfy any of the types defined in the condition.
Base node properties
id
- Readonly:
true
- Type:
string
The ID of current node.
parent
- Readonly:
true
- Type:
(BaseNode & ChildrenMixin) | null
Get the parent node of the current node.
index
- Readonly:
true
- Type: number
Get the sequential index of the current node at the same level.
name
- Type:
string
The name of the layer that appears in the layers panel.
removed
- Readonly:
true
- Type:
boolean
Returns true
if the node was removed. if the plugin stays open for a while and stores references to the node, you should defensively write code and check that the node has not been removed by the user.
toString
- Type:
string
Returns a string representation of the node.
remove
- Type:
remove():void
Removes this node and all of its children from the document.
setRelaunchData
- Type:
data: {[command: string]: string}): void
Sets state on the node to show a button and description when the node is selected.
getRelaunchData
- Type:
getRelaunchData(): { [command: string]: string }
Retreives the reluanch data stored on this node using setRelaunchData
getPluginData
- Type:
getPluginData(key: string): string
Retrieves custom information that was stored on this node or style. To get a value type other than a string, decode it first via JSON.parse
.
setPluginData
- Type:
setPluginData(key: string, value: string): void
Lets you store custom information on any node or style, private to your plugin. If you want to store a value type other than a string, please encode it first via JSON.stringify
.
getPluginDataKeys
- Type:
getPluginDataKeys(): string[]
Retrieves a list of all keys stored on this node or style.
getSharedPluginData
- Type:
getSharedPluginData(namespace: string, key: string): string
Get the shared data stored on a specific namespace.
setSharedPluginData
- Type:
setSharedPluginData(namespace: string, key: string, value: string): void
This allows you to store custom information on any node. You can retrieve it later by calling getSharedPluginData with the same namespace and key. To find all the data on a node stored in a specific namespace, use getSharpedPluginDataKeys
.
Any data you write using this API can be read by any plug-in. The purpose is to allow plugins to interoperate with each other. If you do not want other plugins to be able to read your data, use setPluginData
instead.
You must also provide the namespace parameter to avoid key conflicts with other plugins. This parameter is mandatory to prevent multiple plugins from using common key names (such as data) and overwriting each other. We recommend passing a value that identifies your plugin. This namespace can be provided to the authors of other plugins so that they can read data from your plugin.
namespace is a unique string used to identify your plugin and avoid key conflicts with other plugins. The namespace must contain at least 3 alphanumeric characters.
getSharedPluginDataKeys
- Type:
getSharedPluginDataKeys(namespace: string): string[]
Retrieves a list of all keys stored on this node or style using setSharedPluginData
. This enables iterating through all data stored in a given namespace.