How to drag svg from figma plugin and drop to figma canvas?

Drag svg from figma plugin and drop to figma file.

Like they did Drag & Drop | Figma Community

I’m wanna develop this type of feature in my plugin.

Is this a question? :thinking:

sorry yeah

Can you explain further? This depends heavily on the plugin that you’re using.

1 Like

Please look back at my question again. And actually, Figma not allowing to create SVG Instance directly.

I got this error “‘postMessage’ on ‘Window’: SVGSVGElement object could not be cloned.”
in my plugin.

Use the “Drop” event in code.js.
Check out the following official examples:

2 Likes

I’m not sure why but when I try to use figma.on(‘drop’,…) it’s throwing errors

I don’t see any errors here. But you probably need to update plugin typings.

1 Like

I had update plugin typings but still

Since you are using Typescript, you need to respect its syntax and also return false:

figma.on('drop', (event: DropEvent) => {
    // Your code
    return false
})

Also add a condition for line 9 (on which you supposedly have an error) as in the example I gave you a link to:

Thank you so much for your help. It’s working now. But one typescript error still showing

if (node.appendChild) {
   node.appendChild(newNode);
}

Showing this “Property ‘appendChild’ does not exist on type 'DocumentNode | PageNode | SliceNode | FrameNode… etc”

This condition is just written in order to bypass the error you indicated.

1 Like

Okay thank you