generated from CodelyTV/figma-plugin-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfigma-entrypoint.ts
54 lines (45 loc) · 1.42 KB
/
figma-entrypoint.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { Command } from "./commands-setup/Command";
import { handleCommand } from "./commands-setup/handleCommand";
registerPluginMenuCommandHandlers();
registerPluginMenuCommandParametersSuggestions();
registerPluginUiCommandHandlers();
function registerPluginMenuCommandHandlers() {
figma.on("run", async (event: RunEvent) => {
const hasToAccessPluginIframe = event.command === "showUi";
if (hasToAccessPluginIframe) {
figma.showUI(__html__, { themeColors: true });
figma.ui.resize(450, 300);
return;
}
createInvisibleUiForBrowserApiAccess();
const command = {
type: event.command,
payload: event.parameters,
};
await handleCommand(command);
});
}
function registerPluginMenuCommandParametersSuggestions() {
figma.parameters.on(
"input",
async ({ key, query, result }: ParameterInputEvent) => {
switch (key) {
case "typeOfShapes":
const shapes = ["Rectangle", "Ellipse"];
const queryMatchingShapes = shapes.filter((s) => s.startsWith(query));
result.setSuggestions(queryMatchingShapes);
break;
default:
break;
}
}
);
}
function registerPluginUiCommandHandlers() {
figma.ui.onmessage = async <CommandType extends Command>(
command: CommandType
) => await handleCommand(command);
}
function createInvisibleUiForBrowserApiAccess() {
figma.showUI(__html__, { visible: false });
}