Skip to content

Commit e87762d

Browse files
committed
Update go-to for Dynamic Page Loading
1 parent 170808e commit e87762d

File tree

3 files changed

+17
-29
lines changed

3 files changed

+17
-29
lines changed

go-to/.eslintrc.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* eslint-env node */
2+
module.exports = {
3+
extends: ["eslint:recommended", "plugin:@figma/figma-plugins/recommended"],
4+
parser: "@typescript-eslint/parser",
5+
parserOptions: {
6+
project: "./tsconfig.json",
7+
},
8+
root: true,
9+
};

go-to/code.ts

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,4 @@
1-
const types = [
2-
"BOOLEAN_OPERATION",
3-
"COMPONENT",
4-
"COMPONENT_SET",
5-
"CONNECTOR",
6-
"DOCUMENT",
7-
"ELLIPSE",
8-
"FRAME",
9-
"GROUP",
10-
"INSTANCE",
11-
"LINE",
12-
"PAGE",
13-
"POLYGON",
14-
"RECTANGLE",
15-
"SHAPE_WITH_TEXT",
16-
"SLICE",
17-
"STAMP",
18-
"STAR",
19-
"STICKY",
20-
"TEXT",
21-
"VECTOR",
22-
];
1+
/* eslint-disable no-case-declarations */
232

243
// The 'input' event listens for text change in the Quick Actions box after a plugin is 'Tabbed' into.
254
figma.parameters.on('input', ({ key, query, result }) => {
@@ -50,25 +29,25 @@ figma.parameters.on('input', ({ key, query, result }) => {
5029

5130
// When the user presses Enter after inputting all parameters, the 'run' event is fired.
5231
figma.on('run', ({ parameters }) => {
53-
startPluginWithParameters(parameters!);
32+
startPluginWithParameters(parameters);
5433
});
5534

5635
// Start the plugin with parameters
57-
function startPluginWithParameters(parameters) {
36+
async function startPluginWithParameters(parameters) {
5837
const { name, id } = parameters['name'];
59-
const node = figma.getNodeById(id);
38+
const node = await figma.getNodeByIdAsync(id);
6039
if (node) {
6140
// Node found, so we need to go to that node
6241
if (node.type === "PAGE") {
63-
figma.currentPage = node;
42+
await figma.setCurrentPageAsync(node);
6443
} else {
6544
// Figure out if the node is on the right page,
6645
// otherwise, we need to switch to that page before zooming into the view
6746
let currentParent = node.parent;
6847
while (currentParent.type !== "PAGE") {
6948
currentParent = currentParent.parent;
7049
}
71-
figma.currentPage = currentParent;
50+
await figma.setCurrentPageAsync(currentParent);
7251
figma.viewport.scrollAndZoomIntoView([node]);
7352
figma.currentPage.selection = [node as SceneNode];
7453
}
@@ -78,4 +57,3 @@ function startPluginWithParameters(parameters) {
7857
}
7958
figma.closePlugin();
8059
}
81-
;

go-to/manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
],
1414
"networkAccess": {
1515
"allowedDomains": ["none"]
16-
}
16+
},
17+
"documentAccess": "dynamic-page"
1718
}

0 commit comments

Comments
 (0)