-
Notifications
You must be signed in to change notification settings - Fork 347
Expand file tree
/
Copy pathcode.js
More file actions
48 lines (41 loc) · 1.23 KB
/
code.js
File metadata and controls
48 lines (41 loc) · 1.23 KB
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
const selectionNodes = figma.currentPage.selection;
const nodes =
selectionNodes.length === 0 ? [figma.currentPage] : selectionNodes;
nodes.forEach((node) => {
if (node.type === "INSTANCE") {
addAnnotation(node);
} else {
node.findAllWithCriteria({ types: ["INSTANCE"] }).forEach(addAnnotation);
}
});
figma.closePlugin();
function addAnnotation(instance) {
if (instance.annotations.length) {
console.log(instance.annotations);
/**
* The following deletes existing annotations
*/
/*
instance.annotations = [];
*/
/**
* The following appends to existing annotations but loses existing rich text formatting.
* Rich text is currently unsupported in the plugin API.
*/
const current = instance.annotations[0];
const currentProperties = current.properties || [];
const existingMainComponent = currentProperties.find(
(a) => a.type === "mainComponent"
);
if (!existingMainComponent) {
instance.annotations = [
{
labelMarkdown: current.labelMarkdown,
properties: [{ type: "mainComponent" }].concat(currentProperties),
},
];
}
} else {
instance.annotations = [{ properties: [{ type: "mainComponent" }] }];
}
}