pragmatic-drag-and-drop icon indicating copy to clipboard operation
pragmatic-drag-and-drop copied to clipboard

IFrame Support

Open edge-rps opened this issue 1 year ago • 9 comments

I'm interested in using Pragmatic Drag-and-Drop within an iframe component like react-frame-component. Is this supported?

I've seen some discussions online suggesting it might be possible with limitations, but I couldn't find any official documentation on this.

edge-rps avatar Apr 06 '24 02:04 edge-rps

+1. Original Ads showed iframe process. Where is it? This is the most interesting part how to get it worked between windows

glani avatar Apr 06 '24 19:04 glani

For those that need a quick fix, it's possible to use react-dnd as an alternative and it works with sortable.

https://github.com/react-dnd/react-dnd/ https://react-dnd.github.io/react-dnd/examples/sortable/simple https://codesandbox.io/p/sandbox/iframe-example-ilfwt

edge-rps avatar Apr 06 '24 23:04 edge-rps

Great news! Pragmatic drag and drop works with iframes. If it's possible with the web platform, it's possible with Pragmatic drag and drop.

For iframes, you will want to use the external adapter

I hope to post a video with more detail about this whole flow soon.

Here is the demoed example. I would caveat that this example takes some shortcuts that you will need to think about for a production experience. I'll elaborate in the planned video

alexreardon avatar Apr 07 '24 06:04 alexreardon

Hi! I'm also trying to use Pragmatic drag and drop to drop elements into an iframe within the same document but it doesn't seem to work? I'm most certainly doing something wrong, so I made a basic reproduction here in case you could help me figure it out 😅 https://stackblitz.com/edit/vitejs-vite-fpbsjy?file=src%2FApp.vue

Thanks for all your work!

yassilah avatar Apr 29 '24 11:04 yassilah

👋 The provided example leveraging react-frame-component is an interesting one. It is rendering content into an iframe, but then trying to control the iframe contents from outside the iframe. Right now that is not supported. Pragmatic drag and drop expects each window to manage it's own drag and drop rather than one window trying to manage another. This approach has the benefit of allowing drag and drop between completely independent iframes.

If the provided example was updated so that the iframe loaded in Pragmatic drag and drop and registered the elements with Pragmatic drag an drop, you would find things would start working.

For reference, here is an example of drag and drop working across iframes:

alexreardon avatar Aug 15 '24 00:08 alexreardon

Reopened issue to leave room for the conversation to continue

alexreardon avatar Aug 15 '24 00:08 alexreardon

I have an remix app and inside it i have an iframe[same-origin]. i'm able to manually add eventListener and everything works [drag,drop etc] but when i use dropTargets from "pragmatic-drag-and-drop" it doesn't work.

WebX47 avatar Dec 11 '24 15:12 WebX47

Did anyone find a solution for this using react-frame-component?

sami616 avatar Jan 30 '25 07:01 sami616

Hi, will allowing the document to be passed as an argument to the draggable function solve the issue?

Or maybe change it to something like that: element.ownerDocument,

Another option might be to export the makeAdapter function so we can reuse it for our needs.

https://github.com/atlassian/pragmatic-drag-and-drop/blob/8aa0418bf518dc67befdd4ca48cf93df624be17c/packages/core/src/adapter/element-adapter.ts#L95

I will love to send a PR about it if it's possible.

@alexreardon

Edit: After some investigation, there are a lot of event bindings to the current window, so seems like big refactor, but if possible I will love to help.

Nevoss avatar Jul 09 '25 09:07 Nevoss