Hi,
My goal is to be able to drag some node out of the text editor. For instance, it is possible to select some text, and to drop it in the browser url bar. I want to do something similar, but with more complex data than text/html content.
I’ve defined a custom node type in my schema. The definition is as-is (including comments about things I partially understand):
someCustomNode: {
// TODO: this prevents editing text within the node?
atom: true,
// TODO: not sure if it means draggable within the editor or out of it or both
draggable: true,
// TODO: not sure about the difference between group:"inline" and inline: true
group: "inline",
inline: true,
// TODO: not sure of the impact?
selectable: true,
attrs: { type: "FOO", },
toDOM(node) {
/* some logic to render a web component */
},
parseDOM: [/* some logic to retrieve the node type based on the type*/]
I am using a custom element (so a web component) for the display. It defines it’s own “dragstart” event that will fill the drag event with relevant data:
@dragstart=${(e: DragEvent) => {
ev.dataTransfer.clearData()
ev.dataTransfer.effectAllowed = "copy"
ev.dataTransfer.setData("SOME_CUSTOM_NODE", JSON.stringify({ someData: "foo" })
}}
Notice the “setData” call. This adds some custom data in the drag event, that you can later test during a drop to detect the kind of data.
However, when the element is dropped out of the text-editor, the type is “text/html” while it should be “SOME_CUSTOM_NODE”. Therefore I guess the drag event is also caught somewhere by prose-mirror, and it overrides my data. This is probably to be able to move nodes around within the text editor, but that prevents dropping out of it.
Any lead on how to prevent that? Calling preventDefault()
or stopPropagation
seems to totally prevent dragging. I am not sure where to start, the only plugin I use is dropCursor
.