-
Notifications
You must be signed in to change notification settings - Fork 325
/
Copy pathcode.ts
32 lines (25 loc) · 924 Bytes
/
code.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
figma.showUI(__html__);
// Receive the drop event from the UI
figma.on('drop', (event) => {
const { files, node, dropMetadata } = event;
if (files.length > 0 && files[0].type === 'image/svg+xml') {
files[0].getTextAsync().then((text) => {
if (dropMetadata.parentingStrategy === 'page') {
const newNode = figma.createNodeFromSvg(text);
newNode.x = event.absoluteX;
newNode.y = event.absoluteY;
figma.currentPage.selection = [newNode];
} else if (dropMetadata.parentingStrategy === 'immediate') {
const newNode = figma.createNodeFromSvg(text);
// We can only append page nodes to documents
if ('appendChild' in node && node.type !== 'DOCUMENT') {
node.appendChild(newNode);
}
newNode.x = event.x;
newNode.y = event.y;
figma.currentPage.selection = [newNode];
}
});
return false;
}
});