Skip to content

Latest commit

 

History

History
1729 lines (923 loc) · 47.4 KB

File metadata and controls

1729 lines (923 loc) · 47.4 KB

CodeBlockNode

Interface: CodeBlockNode

Defined in: figmaPluginTypes.ts:9200

See

https://www.figma.com/plugin-docs/api/CodeBlockNode

Extends

Properties

absoluteBoundingBox

readonly absoluteBoundingBox: null | Rect

Defined in: figmaPluginTypes.ts:5712

The bounds of the node that does not include rendered properties like drop shadows or strokes. The x and y inside this property represent the absolute position of the node on the page.

Inherited from

OpaqueNodeMixin.absoluteBoundingBox


absoluteTransform

readonly absoluteTransform: Transform

Defined in: figmaPluginTypes.ts:5708

The position of a node relative to its containing page as a Transform matrix.

Inherited from

OpaqueNodeMixin.absoluteTransform


attachedConnectors

readonly attachedConnectors: ConnectorNode[]

Defined in: figmaPluginTypes.ts:5183

An array of ConnectorNodes that are attached to a node.

Inherited from

OpaqueNodeMixin.attachedConnectors


blendMode

blendMode: BlendMode

Defined in: figmaPluginTypes.ts:7182

Blend mode of this node, as shown in the Layer panel. In addition to the blend modes that paints & effects support, the layer blend mode can also have the value PASS_THROUGH.

Inherited from

MinimalBlendMixin.blendMode


boundVariables?

readonly optional boundVariables: object & object & object

Defined in: figmaPluginTypes.ts:5195

The variables bound to a particular field on this node. Please see the Working with Variables guide for how to get and set variable bindings.

Type declaration

bottomLeftRadius?

optional bottomLeftRadius: VariableAlias

bottomRightRadius?

optional bottomRightRadius: VariableAlias

characters?

optional characters: VariableAlias

counterAxisSpacing?

optional counterAxisSpacing: VariableAlias

height?

optional height: VariableAlias

itemSpacing?

optional itemSpacing: VariableAlias

maxHeight?

optional maxHeight: VariableAlias

maxWidth?

optional maxWidth: VariableAlias

minHeight?

optional minHeight: VariableAlias

minWidth?

optional minWidth: VariableAlias

opacity?

optional opacity: VariableAlias

paddingBottom?

optional paddingBottom: VariableAlias

paddingLeft?

optional paddingLeft: VariableAlias

paddingRight?

optional paddingRight: VariableAlias

paddingTop?

optional paddingTop: VariableAlias

strokeBottomWeight?

optional strokeBottomWeight: VariableAlias

strokeLeftWeight?

optional strokeLeftWeight: VariableAlias

strokeRightWeight?

optional strokeRightWeight: VariableAlias

strokeTopWeight?

optional strokeTopWeight: VariableAlias

strokeWeight?

optional strokeWeight: VariableAlias

topLeftRadius?

optional topLeftRadius: VariableAlias

topRightRadius?

optional topRightRadius: VariableAlias

visible?

optional visible: VariableAlias

width?

optional width: VariableAlias

Type declaration

fontFamily?

optional fontFamily: VariableAlias[]

fontSize?

optional fontSize: VariableAlias[]

fontStyle?

optional fontStyle: VariableAlias[]

fontWeight?

optional fontWeight: VariableAlias[]

letterSpacing?

optional letterSpacing: VariableAlias[]

lineHeight?

optional lineHeight: VariableAlias[]

paragraphIndent?

optional paragraphIndent: VariableAlias[]

paragraphSpacing?

optional paragraphSpacing: VariableAlias[]

Type declaration

componentProperties?

readonly optional componentProperties: object

Index Signature

[propertyName: string]: VariableAlias

effects?

readonly optional effects: VariableAlias[]

fills?

readonly optional fills: VariableAlias[]

layoutGrids?

readonly optional layoutGrids: VariableAlias[]

strokes?

readonly optional strokes: VariableAlias[]

textRangeFills?

readonly optional textRangeFills: VariableAlias[]

Inherited from

OpaqueNodeMixin.boundVariables


code

code: string

Defined in: figmaPluginTypes.ts:9208

The contents of the code block.


codeLanguage

codeLanguage: "TYPESCRIPT" | "CPP" | "RUBY" | "CSS" | "JAVASCRIPT" | "HTML" | "JSON" | "GRAPHQL" | "PYTHON" | "GO" | "SQL" | "SWIFT" | "KOTLIN" | "RUST" | "BASH" | "PLAINTEXT" | "DART"

Defined in: figmaPluginTypes.ts:9212

The language of the code block. New languages will be added to this enum without the major version updating, so be careful not to exhaustively match on this type without a default case.


componentPropertyReferences

componentPropertyReferences: null | { characters?: string; mainComponent?: string; visible?: string; }

Defined in: figmaPluginTypes.ts:5187

All component properties that are attached on this node. A node can only have componentPropertyReferences if it is a component sublayer or an instance sublayer. It will be null otherwise. The value in the key-value pair refers to the component property name as returned by componentPropertyDefinitions on the containing component, component set or main component (for instances).

Inherited from

OpaqueNodeMixin.componentPropertyReferences


explicitVariableModes

explicitVariableModes: object

Defined in: figmaPluginTypes.ts:8250

The explicitly set modes for this node. For SceneNodes, represents a subset of SceneNodeMixin.resolvedVariableModes. Note that this does not include workspace and team-default modes.

Index Signature

[collectionId: string]: string

Inherited from

OpaqueNodeMixin.explicitVariableModes


exportSettings

exportSettings: readonly ExportSettings[]

Defined in: figmaPluginTypes.ts:6748

List of export settings stored on the node. For help on how to change this value, see Editing Properties.

Inherited from

OpaqueNodeMixin.exportSettings


height

readonly height: number

Defined in: figmaPluginTypes.ts:5642

The height of the node. Use a resizing method to change this value.

Inherited from

OpaqueNodeMixin.height


id

readonly id: string

Defined in: figmaPluginTypes.ts:4878

The unique identifier of a node. For example, 1:3. The node id can be used with methods such as PluginAPI.getNodeByIdAsync, but plugins typically don't need to use this since you can usually just access a node directly.

Remarks

One possible use case for using the id is to have a serializable representation of a Figma node. To "deserialize" an id back into a node, pass it to PluginAPI.getNodeByIdAsync. This will return null if the node is no longer present in the document.

In the URLs for Figma files, node ids are hyphenated. However, for use with the API, node ids must use colons. For example, if a Figma file URL has the node id 1-3, you must convert it to 1:3.

Inherited from

OpaqueNodeMixin.id


inferredVariables?

readonly optional inferredVariables: object & object

Defined in: figmaPluginTypes.ts:5248

An object, keyed by field, returning any variables that match the raw value of that field for the mode of the node (or the default variable value if no mode is set)

Type declaration

bottomLeftRadius?

optional bottomLeftRadius: VariableAlias[]

bottomRightRadius?

optional bottomRightRadius: VariableAlias[]

characters?

optional characters: VariableAlias[]

counterAxisSpacing?

optional counterAxisSpacing: VariableAlias[]

height?

optional height: VariableAlias[]

itemSpacing?

optional itemSpacing: VariableAlias[]

maxHeight?

optional maxHeight: VariableAlias[]

maxWidth?

optional maxWidth: VariableAlias[]

minHeight?

optional minHeight: VariableAlias[]

minWidth?

optional minWidth: VariableAlias[]

opacity?

optional opacity: VariableAlias[]

paddingBottom?

optional paddingBottom: VariableAlias[]

paddingLeft?

optional paddingLeft: VariableAlias[]

paddingRight?

optional paddingRight: VariableAlias[]

paddingTop?

optional paddingTop: VariableAlias[]

strokeBottomWeight?

optional strokeBottomWeight: VariableAlias[]

strokeLeftWeight?

optional strokeLeftWeight: VariableAlias[]

strokeRightWeight?

optional strokeRightWeight: VariableAlias[]

strokeTopWeight?

optional strokeTopWeight: VariableAlias[]

strokeWeight?

optional strokeWeight: VariableAlias[]

topLeftRadius?

optional topLeftRadius: VariableAlias[]

topRightRadius?

optional topRightRadius: VariableAlias[]

visible?

optional visible: VariableAlias[]

width?

optional width: VariableAlias[]

Type declaration

fills?

readonly optional fills: VariableAlias[][]

strokes?

readonly optional strokes: VariableAlias[][]

Remarks

Inferred variables are only returned for a field when it is not using a bound variable.

Variables can be inferred from:

  • The collections of variables used in the file
  • Variables from subscribed libraries, provided the variable is used in the file

Variables can only be inferred when there is a single variable that matches the raw value used for the scope of the variable.

  • i.e. For a property set to width: 100px, where there are two variables set to a value of 100 with the default scope, a value cannot be inferred as there are two matches.
  • i.e. For a property set to width: 100px, where there is a variable set to 100 with a scope of "Width and height" and a variable set to 100 with a scope of "Corner radius", a value can be inferred as there is a single match for the given scope.

Inferred variables for fills and strokes return a list of results where the index matches that of node.fills and node.strokes.

  • i.e. node.inferredVariables.fills[0] holds the inferred variables for node.fills[0]

Inherited from

OpaqueNodeMixin.inferredVariables


isAsset

readonly isAsset: boolean

Defined in: figmaPluginTypes.ts:5010

Returns true if Figma detects that a node is an asset, otherwise returns false. An asset is is either an icon or a raster image.

This property is useful if you’re building a plugin for code generation.

Note: This property uses a set of heuristics to determine if a node is an asset. At a high level an icon is a small vector graphic and an image is a node with an image fill.

Inherited from

OpaqueNodeMixin.isAsset


locked

locked: boolean

Defined in: figmaPluginTypes.ts:5167

Whether the node is locked or not, preventing certain user interactions on the canvas such as selecting and dragging. Does not affect a plugin's ability to write to those properties.

Remarks

The value that this property returns is independent from the node's parent. i.e.

  • The node isn't necessarily locked if this is .locked === true.
  • The node isn't necessarily unlocked if this is .locked === false.
  • An object is locked if .locked == true for itself or any of its parents.

Inherited from

OpaqueNodeMixin.locked


maxHeight

maxHeight: null | number

Defined in: figmaPluginTypes.ts:5658

Applicable only to auto-layout frames and their direct children. Value must be positive. Set to null to remove maxHeight.

Inherited from

OpaqueNodeMixin.maxHeight


maxWidth

maxWidth: null | number

Defined in: figmaPluginTypes.ts:5650

Applicable only to auto-layout frames and their direct children. Value must be positive. Set to null to remove maxWidth.

Inherited from

OpaqueNodeMixin.maxWidth


minHeight

minHeight: null | number

Defined in: figmaPluginTypes.ts:5654

Applicable only to auto-layout frames and their direct children. Value must be positive. Set to null to remove minHeight.

Inherited from

OpaqueNodeMixin.minHeight


minWidth

minWidth: null | number

Defined in: figmaPluginTypes.ts:5646

Applicable only to auto-layout frames and their direct children. Value must be positive. Set to null to remove minWidth.

Inherited from

OpaqueNodeMixin.minWidth


name

name: string

Defined in: figmaPluginTypes.ts:4898

The name of the layer that appears in the layers panel. Calling figma.root.name will return the name, read-only, of the current file.

Remarks

If the node is a TextNode, the name will update automatically by default based on the characters property (autoRename is true). If you manually override the text node's name, it will set autoRename to false. This matches the behavior in the editor.

If the node is a PageNode with no children and the name is a page divider name, it will set isPageDivider to true. A page divider name consists of all asterisks, all en dashes, all em dashes, or all spaces.

Inherited from

OpaqueNodeMixin.name


opacity

opacity: number

Defined in: figmaPluginTypes.ts:7178

Opacity of the node, as shown in the Layer panel. Must be between 0 and 1.

Inherited from

MinimalBlendMixin.opacity


parent

readonly parent: null | BaseNode & ChildrenMixin

Defined in: figmaPluginTypes.ts:4888

Returns the parent of this node, if any. This property is not meant to be directly edited. To reparent, see ChildrenMixin.appendChild.

Remarks

The root node (i.e. figma.root) doesn't have a parent.

Components accessed via instance.getMainComponentAsync() or instance.mainComponent do not always have a parent. They could be remote components or soft-deleted components.

Inherited from

OpaqueNodeMixin.parent


relativeTransform

relativeTransform: Transform

Defined in: figmaPluginTypes.ts:5704

The position of a node relative to its containing parent as a Transform matrix. Not used for scaling, see width and height instead. Read the details page to understand the nuances of this property.

Remarks

Scale

The relativeTransform is not used for scaling a node. The transform always has unit axes. That is, sqrt(m00^2 + m10^2) == sqrt(m01^2 + m11^2) == 1. In order to set the size of a node, use LayoutMixin.resize or LayoutMixin.resizeWithoutConstraints.

Note: If you have a background in computer graphics, you may find it odd that we use the transform matrix in such a manner. This is because in 2D UI design, it's rare that you would want to scale the children when resizing a frame. And even if you did, it would be through more nuanced constraint settings that aren't captured by a transformation matrix.

Also, if nodes had both a width and a separate m00 scale property, it would be confusing to the users which one they're changing, especially during interactions like dragging.

Container parent

The relative transform of a node is shown relative to its container parent, which includes canvas nodes, frame nodes, component nodes, and instance nodes. Just like in the properties panel, it is not relative to its direct parent if the parent is a group or a boolean operation.

Example 1: In the following hierarchy, the relative transform of rectangle is relative to page (which is just its position on the canvas).

page
  group
    rectangle

Example 2: In the following hierarchy, the relative transform of rectangle is relative to frame.

page
  frame
    boolean operation
      rectangle

One implication is that to calculate the absolute position of a node, you have to either use the DimensionAndPositionMixin.absoluteTransform property or multiply relative transform matrices while traversing up the node hierarchy while ignoring groups and boolean operations.

Note: Why this complication? We do it this way because groups and boolean operations automatically resize to fit their children. While you can set the relative transform of a group to move it, it's a property derived from the position and size of its children. If the relative transform was always relative to it’s immediate parent, you could get into confusing situations where moving a layer inside a group by setting the relative transform changes the position of the parent, which then requires changing the relative transform of the child in order to preserve its on-screen position!

Skew

While it is possible to skew a layer by setting m00, m01, m10, m11 to the right values, be aware that the skew will not be surfaced in the properties panel and may be confusing to the user dealing with a skewed node.

Auto-layout frames

The translation components m02 and m12 of the transform matrix is automatically computed in children of auto-layout frames. Setting relativeTransform on those layers will ignore the translation components, but do keep the rotation components.

Inherited from

OpaqueNodeMixin.relativeTransform


removed

readonly removed: boolean

Defined in: figmaPluginTypes.ts:4911

Returns true if this node has been removed since it was first accessed. If your plugin stays open for a while and stores references to nodes, you should write your code defensively and check that the nodes haven't been removed by the user.

Remarks

A node can be removed for any number of reasons. Some examples:

  • Your plugin called node.remove() on it
  • Someone else deleted the node using multiplayer
  • The user triggered an undo action and the node was removed
  • The user simply deleted the node
  • You removed all children out of a group, and the group auto-deleted itself

Inherited from

OpaqueNodeMixin.removed


resolvedVariableModes

resolvedVariableModes: object

Defined in: figmaPluginTypes.ts:5292

The resolved mode for this node for each variable collection in this file.

Index Signature

[collectionId: string]: string

Remarks

The set of resolved modes on a node includes the explicitly set modes on the node, as well as the explicitly set modes on ancestors of the node. By default, nodes automatically inherit the modes of their parents.

// Create two collections with two modes each
const collection1 = figma.variables.createVariableCollection("Collection 1");
const collection1Mode1Id = collection1.modes[0].modeId;
const collection1Mode2Id = collection1.addMode("Mode 2");
const collection2 = figma.variables.createVariableCollection("Collection 2");
const collection2Mode1Id = collection2.modes[0].modeId;
const collection2Mode2Id = collection2.addMode("Mode 2");

const parentFrame = figma.createFrame();
const childFrame = figma.createFrame();
parentFrame.appendChild(childFrame);

parentFrame.setExplicitVariableModeForCollection(
  collection1,
  collection1Mode2Id
);
childFrame.setExplicitVariableModeForCollection(
  collection2,
  collection2Mode1Id
);

// Example output (only collection2 is present):
// { 'VariableCollectionId:1:3': '1:2' }
console.log(childFrame.explicitVariableModes);

// Example output (both collections are present):
// { 'VariableCollectionId:1:2': '1:1', 'VariableCollectionId:1:3': '1:2' }
console.log(childFrame.resolvedVariableModes);

Inherited from

OpaqueNodeMixin.resolvedVariableModes


stuckNodes

readonly stuckNodes: SceneNode[]

Defined in: figmaPluginTypes.ts:5179

An array of nodes that are "stuck" to this node. In FigJam, stamps, highlights, and some widgets can "stick" to other nodes if they are dragged on top of another node.

Remarks

This property is only available in FigJam.

In FigJam a stickable host that means that stickables, like 'STAMP' nodes, are allowed to attach themselves to the node. If the stickable host moves all nodes that are in stuckNodes move along with it.

Inherited from

OpaqueNodeMixin.stuckNodes


type

readonly type: "CODE_BLOCK"

Defined in: figmaPluginTypes.ts:9204

The type of this node, represented by the string literal "CODE_BLOCK"


visible

visible: boolean

Defined in: figmaPluginTypes.ts:5156

Whether the node is visible or not. Does not affect a plugin's ability to access the node.

Remarks

The value that this property returns is independent from the node's parent. i.e.

  • The node isn't necessarily visible if this is .visible === true.
  • The node isn't necessarily invisible if this is .visible === false.
  • An object is visible if .visible == true for itself and all its parents.

Inherited from

OpaqueNodeMixin.visible


width

readonly width: number

Defined in: figmaPluginTypes.ts:5638

The width of the node. Use a resizing method to change this value.

Inherited from

OpaqueNodeMixin.width


x

x: number

Defined in: figmaPluginTypes.ts:5626

The position of the node. Identical to relativeTransform[0][2].

Remarks

This value is automatically computed in children of auto-layout frames. Setting this property for these auto-layout children will no-op.

Inherited from

OpaqueNodeMixin.x


y

y: number

Defined in: figmaPluginTypes.ts:5634

The position of the node. Identical to relativeTransform[1][2].

Remarks

This value is automatically computed in children of auto-layout frames. Setting this property for these auto-layout children will no-op.

Inherited from

OpaqueNodeMixin.y

Methods

addDevResourceAsync()

addDevResourceAsync(url, name?): Promise<void>

Defined in: figmaPluginTypes.ts:5100

Adds a dev resource to a node. This will fail if the node already has a dev resource with the same url.

Parameters

url

string

The url of the dev resource.

name?

string

The name of the dev resource. If not provided, Figma will get the name from the url.

Returns

Promise<void>

Inherited from

OpaqueNodeMixin.addDevResourceAsync


clearExplicitVariableModeForCollection()

Call Signature

clearExplicitVariableModeForCollection(collectionId): void

Defined in: figmaPluginTypes.ts:8258

Clears an explicit mode for the given collection on this node

Parameters
collectionId

string

Returns

void

Deprecated

Use clearExplicitVariableModeForCollection(VariableCollection) instead. This function will throw an exception if the plugin manifest contains "documentAccess": "dynamic-page".

Inherited from

OpaqueNodeMixin.clearExplicitVariableModeForCollection

Call Signature

clearExplicitVariableModeForCollection(collection): void

Defined in: figmaPluginTypes.ts:8264

Clears an explicit mode for the given collection on this node

Parameters
collection

VariableCollection

A variable collection. Make sure to pass a collection object here; passing a variable collection ID is deprecated.

Returns

void

Inherited from

OpaqueNodeMixin.clearExplicitVariableModeForCollection


clone()

clone(): CodeBlockNode

Defined in: figmaPluginTypes.ts:9233

Duplicates the node. By default, the duplicate will be parented under figma.currentPage.

Returns

CodeBlockNode


deleteDevResourceAsync()

deleteDevResourceAsync(url): Promise<void>

Defined in: figmaPluginTypes.ts:5122

Deletes a dev resource on a node. This will fail if the node does not have a dev resource with the same url.

Parameters

url

string

The url of the dev resource.

Returns

Promise<void>

Inherited from

OpaqueNodeMixin.deleteDevResourceAsync


editDevResourceAsync()

editDevResourceAsync(currentUrl, newValue): Promise<void>

Defined in: figmaPluginTypes.ts:5109

Edits a dev resource on a node. This will fail if the node does not have a dev resource with the same url.

Parameters

currentUrl

string

The current url of the dev resource.

newValue

The new name and/or url of the dev resource.

name?

string

url?

string

Returns

Promise<void>

Inherited from

OpaqueNodeMixin.editDevResourceAsync


exportAsync()

Call Signature

exportAsync(settings?): Promise<Uint8Array<ArrayBufferLike>>

Defined in: figmaPluginTypes.ts:6811

Exports the node as an encoded image.

If the manifest contains "documentAccess": "dynamic-page", and the node is a PageNode, you must first call PageNode.loadAsync to access this function.

Parameters
settings?

ExportSettings

When this parameter is absent, this function defaults to exporting as a PNG at 1x resolution.

Note that the result is a Uint8Array, representing the bytes of the image file (encoded in the specified format).

(async () => {
  const polygon = figma.createPolygon();
  polygon.pointCount = 6;
  polygon.fills = [{ type: "SOLID", color: { r: 1, g: 0, b: 0 } }];

  // highlight-start
  // Export a 2x resolution PNG of the node
  const bytes = await polygon.exportAsync({
    format: "PNG",
    constraint: { type: "SCALE", value: 2 },
  });
  // highlight-end

  // Add the image onto the canvas as an image fill in a frame
  const image = figma.createImage(bytes);
  const frame = figma.createFrame();
  frame.x = 200;
  frame.resize(200, 230);
  frame.fills = [
    {
      imageHash: image.hash,
      scaleMode: "FILL",
      scalingFactor: 1,
      type: "IMAGE",
    },
  ];
})();
(async () => {
  // Create a triangle using the VectorPath API
  const vector = figma.createVector();
  vector.vectorPaths = [
    {
      windingRule: "EVENODD",
      data: "M 0 100 L 100 100 L 50 0 Z",
    },
  ];

  // highlight-start
  // Export the vector to SVG
  const svg = await vector.exportAsync({ format: "SVG_STRING" });
  // highlight-end
  console.log(svg);
})();
(async () => {
  const json = await figma.currentPage.selection[0].exportAsync({
    format: "JSON_REST_V1",
  });
  // Return a JSON object in the same format as the Figma REST API response
  console.log(json.document);
})();
Returns

Promise<Uint8Array<ArrayBufferLike>>

Inherited from

OpaqueNodeMixin.exportAsync

Call Signature

exportAsync(settings): Promise<string>

Defined in: figmaPluginTypes.ts:6812

Parameters
settings

ExportSettingsSVGString

Returns

Promise<string>

Inherited from

OpaqueNodeMixin.exportAsync

Call Signature

exportAsync(settings): Promise<Object>

Defined in: figmaPluginTypes.ts:6813

Parameters
settings

ExportSettingsREST

Returns

Promise<Object>

Inherited from

OpaqueNodeMixin.exportAsync


getCSSAsync()

getCSSAsync(): Promise<{[key: string]: string; }>

Defined in: figmaPluginTypes.ts:5014

Resolves to a JSON object of CSS properties of the node. This is the same CSS that Figma shows in the inspect panel and is helpful if you are building a plugin for code generation.

Returns

Promise<{[key: string]: string; }>

Inherited from

OpaqueNodeMixin.getCSSAsync


getDevResourcesAsync()

getDevResourcesAsync(options?): Promise<DevResourceWithNodeId[]>

Defined in: figmaPluginTypes.ts:5091

Gets all of the dev resources on a node. This includes any inherited dev resources from components and component sets.

Parameters

options?

An optional parameter to include getting all of the dev resources on the children of the node. Defaults to false.

includeChildren?

boolean

Returns

Promise<DevResourceWithNodeId[]>

Inherited from

OpaqueNodeMixin.getDevResourcesAsync


getPluginData()

getPluginData(key): string

Defined in: figmaPluginTypes.ts:5031

Retrieves custom information that was stored on this node or style using PluginDataMixin.setPluginData. If there is no data stored for the provided key, an empty string is returned.

Parameters

key

string

Returns

string

Inherited from

OpaqueNodeMixin.getPluginData


getPluginDataKeys()

getPluginDataKeys(): string[]

Defined in: figmaPluginTypes.ts:5053

Retrieves a list of all keys stored on this node or style using using PluginDataMixin.setPluginData. This enables iterating through all data stored privately on a node or style by your plugin.

Returns

string[]

Inherited from

OpaqueNodeMixin.getPluginDataKeys


getRelaunchData()

getRelaunchData(): object

Defined in: figmaPluginTypes.ts:5000

Retreives the reluanch data stored on this node using BaseNodeMixin.setRelaunchData

Returns

object

Inherited from

OpaqueNodeMixin.getRelaunchData


getSharedPluginData()

getSharedPluginData(namespace, key): string

Defined in: figmaPluginTypes.ts:5057

Retrieves custom information that was stored on this node or style using PluginDataMixin.setSharedPluginData. If there is no data stored for the provided namespace and key, an empty string is returned.

Parameters

namespace

string

key

string

Returns

string

Inherited from

OpaqueNodeMixin.getSharedPluginData


getSharedPluginDataKeys()

getSharedPluginDataKeys(namespace): string[]

Defined in: figmaPluginTypes.ts:5079

Retrieves a list of all keys stored on this node or style using PluginDataMixin.setSharedPluginData. This enables iterating through all data stored in a given namespace.

Parameters

namespace

string

Returns

string[]

Inherited from

OpaqueNodeMixin.getSharedPluginDataKeys


getTopLevelFrame()

getTopLevelFrame(): undefined | FrameNode

Defined in: figmaPluginTypes.ts:5022

Returns the top-most frame that contains this node. If the node is not inside a frame, this will return undefined.

Note: This function will only work in Figma Design and will throw an error if called in FigJam or Slides.

Returns

undefined | FrameNode

Inherited from

OpaqueNodeMixin.getTopLevelFrame


remove()

remove(): void

Defined in: figmaPluginTypes.ts:4933

Removes this node and all of its children from the document.

Returns

void

Remarks

If you want to only remove this node but not its children, you will have to first move them to another node before calling remove().

Inherited from

OpaqueNodeMixin.remove


setBoundVariable()

Call Signature

setBoundVariable(field, variableId): void

Defined in: figmaPluginTypes.ts:5214

Binds the provided field on this node to the given variable. Please see the Working with Variables guide for how to get and set variable bindings.

Parameters
field

VariableBindableTextField | VariableBindableNodeField

variableId

null | string

Returns

void

Deprecated

Use setBoundVariable(VariableBindableNodeField, Variable) instead. This function will throw an exception if the plugin manifest contains "documentAccess": "dynamic-page".

Inherited from

OpaqueNodeMixin.setBoundVariable

Call Signature

setBoundVariable(field, variable): void

Defined in: figmaPluginTypes.ts:5226

Binds the provided field on this node to the given variable. Please see the Working with Variables guide for how to get and set variable bindings.

If null is provided as the variable, the given field will be unbound from any variables.

Parameters
field

The field to bind the variable to.

VariableBindableTextField | VariableBindableNodeField

variable

The variable to bind to the field. If null is provided, the field will be unbound from any variables. Make sure to pass a Variable object or null; passing a variable ID is deprecated.

null | Variable

Returns

void

Inherited from

OpaqueNodeMixin.setBoundVariable


setDevResourcePreviewAsync()

setDevResourcePreviewAsync(url, preview): Promise<void>

Defined in: figmaPluginTypes.ts:5127

Caution: This is a private API only available to Figma partners

Parameters

url

string

preview

PlainTextElement

Returns

Promise<void>

Inherited from

OpaqueNodeMixin.setDevResourcePreviewAsync


setExplicitVariableModeForCollection()

Call Signature

setExplicitVariableModeForCollection(collectionId, modeId): void

Defined in: figmaPluginTypes.ts:8270

Sets an explicit mode for the given collection on this node

Parameters
collectionId

string

modeId

string

Returns

void

Deprecated

Use setExplicitVariableModeForCollection(VariableCollection, Variable) instead. This function will throw an exception if the plugin manifest contains "documentAccess": "dynamic-page".

Inherited from

OpaqueNodeMixin.setExplicitVariableModeForCollection

Call Signature

setExplicitVariableModeForCollection(collection, modeId): void

Defined in: figmaPluginTypes.ts:8277

Sets an explicit mode for the given collection on this node

Parameters
collection

VariableCollection

A variable collection. Make sure to pass a collection object here; passing a variable collection ID is deprecated.

modeId

string

A variable mode ID.

Returns

void

Inherited from

OpaqueNodeMixin.setExplicitVariableModeForCollection


setPluginData()

setPluginData(key, value): void

Defined in: figmaPluginTypes.ts:5049

Lets you store custom information on any node or style, private to your plugin. The total size of your entry (pluginId, key, value) cannot exceed 100 kB.

Parameters

key

string

The key under which to store the data. This is similar to writing to a plain object via obj[key] = value.

value

string

The data you want to store. If you want to store a value type other than a string, encode it as a JSON string first via JSON.stringify and JSON.parse. If you set the value to the empty string (""), the key/value pair is removed.

Returns

void

Remarks

The data is specific to your plugin ID. Plugins with other IDs won't be able to read this data. You can retrieve it later by calling getPluginData with the same key. To find all data stored on a node or style by your plugin use getPluginDataKeys.

Caution: ⚠ The data is stored privately for stability, not security. It prevents other plugins from accessing with your data. It does not, however, prevent users from seeing the data given sufficient effort. For example, they could export the document as a .fig file and try to decode it.

Caution: ⚠ Data will become inaccessible if your plugin ID changes.

Caution: ⚠ Total entry size cannot exceed 100 kB.

Inherited from

OpaqueNodeMixin.setPluginData


setRelaunchData()

setRelaunchData(data): void

Defined in: figmaPluginTypes.ts:4996

Sets state on the node to show a button and description when the node is selected. Clears the button and description when relaunchData is {}.

Note: In Figma and Dev Mode, this shows up in the properties panel. In FigJam, this shows up in the property menu. See here for examples.

Parameters

data
{
  [command: string]: string // description
}

e.g. data = { myCommand: 'Short description' }

Returns

void

Remarks

Each call to this method sets entirely new relaunch data, removing any relaunch data and associated buttons/descriptions from before. To maintain buttons from a previous call one can store the button information using setPluginData and later fetch it with getPluginData before passing it on to setRelaunchData.

To use this API, the plugin manifest must include a relaunchButtons section: see the manifest guide for more information.

Note: Note that if the command passed to this method does not match a command in the manifest, nothing will be displayed. Similarly if the name of a command in the manifest changes or is removed, then all buttons with that command will disappear. This behavior can be used to remove buttons when a particular action is no longer supported by the plugin.

In Figma design, the relaunch data can also be placed on the PageNode or DocumentNode, to show a button and description when nothing is selected. Relaunch buttons added to the PageNode will be displayed on that page, combined with buttons from the DocumentNode that show on every page. This is not supported in FigJam.

Examples

// With the following in the manifest:
"relaunchButtons": [
  {"command": "edit", "name": "Edit shape"},
  {"command": "open", "name": "Open Shaper", "multipleSelection": true}
]
// Add two buttons (ordered by the above array from the manifest):
// * an "Edit shape" button with a description of "Edit this trapezoid
//   with Shaper" that runs the plugin with `figma.command === 'edit'`.
// * an "Open Shaper" button with no description that runs the plugin with
//   `figma.command === 'open'`.
node.setRelaunchData({ edit: 'Edit this trapezoid with Shaper', open: '' })

// With the following in the manifest:
"relaunchButtons": [
  {"command": "relaunch", "name": "Run again", "multipleSelection": true}
]

// Pass an empty description to show only a button
node.setRelaunchData({ relaunch: '' })

// Remove the button and description
node.setRelaunchData({})

Example Figma Design UI

Relaunch UI in Figma Design

Example FigJam UI

Relaunch UI in FigJam

Inherited from

OpaqueNodeMixin.setRelaunchData


setSharedPluginData()

setSharedPluginData(namespace, key, value): void

Defined in: figmaPluginTypes.ts:5075

Lets you store custom information on any node or style, public to all plugins. The total size of your entry (namespace, key, value) cannot exceed 100 kB.

Parameters

namespace

string

A unique string to identify your plugin and avoid key collisions with other plugins. The namespace must be at least 3 alphanumeric characters.

key

string

The key under which to store the data. This is similar to writing to a plain object via obj[key] = value.

value

string

The data you want to store. If you want to store a value type other than a string, encode it as a JSON string first via JSON.stringify and JSON.parse. If you set the value to the empty string (""), the key/value pair is removed.

Returns

void

Remarks

This lets you store custom information on any node or style. You can retrieve it later by calling PluginDataMixin.getSharedPluginData with the same namespace and key. To find all data stored on a node or style in a particular namespace, use PluginDataMixin.getSharedPluginDataKeys.

Any data you write using this API will be readable by any plugin. The intent is to allow plugins to interoperate with each other. Use PluginDataMixin.setPluginData instead if you don't want other plugins to be able to read your data.

You must also provide a namespace argument to avoid key collisions with other plugins. This argument is mandatory to prevent multiple plugins from using generic key names like data and overwriting one another. We recommend passing a value that identifies your plugin. This namespace can be given to authors of other plugins so that they can read data from your plugin.

Caution: ⚠ Total entry size cannot exceed 100 kB.

Inherited from

OpaqueNodeMixin.setSharedPluginData


toString()

toString(): string

Defined in: figmaPluginTypes.ts:4925

Returns a string representation of the node. For debugging purposes only, do not rely on the exact output of this string in production code.

Returns

string

Remarks

This currently returns a string of the form [Node ID] where ID is the id of the node. This is just for debugging convenience so the node displays something useful when converted to a string. We recommend not relying on this in production.

Example:

// e.g. [Node 0:5]
console.log(`Current selected node ${figma.currentPage.selection[0]}`);

Inherited from

OpaqueNodeMixin.toString