@tiptap/extension-drag-handle 3.3.0 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -61,37 +61,30 @@ function cloneElement(node) {
61
61
 
62
62
  // src/helpers/findNextElementFromCursor.ts
63
63
  var findElementNextToCoords = (options) => {
64
- const { x, y, direction, editor } = options;
65
- let resultElement = null;
66
- let resultNode = null;
67
- let pos = null;
68
- let currentX = x;
69
- while (resultNode === null && currentX < window.innerWidth && currentX > 0) {
70
- const allElements = document.elementsFromPoint(currentX, y);
71
- const prosemirrorIndex = allElements.findIndex((element) => element.classList.contains("ProseMirror"));
72
- const filteredElements = allElements.slice(0, prosemirrorIndex);
73
- if (filteredElements.length > 0) {
74
- const target = filteredElements[0];
75
- resultElement = target;
76
- pos = editor.view.posAtDOM(target, 0);
77
- if (pos >= 0) {
78
- resultNode = editor.state.doc.nodeAt(Math.max(pos - 1, 0));
79
- if (resultNode == null ? void 0 : resultNode.isText) {
80
- resultNode = editor.state.doc.nodeAt(Math.max(pos - 1, 0));
81
- }
82
- if (!resultNode) {
83
- resultNode = editor.state.doc.nodeAt(Math.max(pos, 0));
84
- }
85
- break;
86
- }
87
- }
88
- if (direction === "left") {
89
- currentX -= 1;
90
- } else {
91
- currentX += 1;
92
- }
64
+ const { x, y, direction = "right", editor, bandHeight = 5 } = options;
65
+ const rect = {
66
+ top: y - bandHeight,
67
+ bottom: y + bandHeight,
68
+ left: direction === "right" ? x : 0,
69
+ right: direction === "right" ? window.innerWidth - x : x
70
+ };
71
+ const root = editor.view.dom;
72
+ const candidates = [...root.querySelectorAll("*")].filter((candidate) => {
73
+ return editor.view.posAtDOM(candidate, 0) >= 0;
74
+ }).filter((candidate) => {
75
+ const candidateRect = candidate.getBoundingClientRect();
76
+ return !(candidateRect.bottom < rect.top || candidateRect.top > rect.bottom || candidateRect.right < rect.left || candidateRect.left > rect.right);
77
+ });
78
+ if (!candidates || candidates.length === 0) {
79
+ return { resultElement: null, resultNode: null, pos: null };
93
80
  }
94
- return { resultElement, resultNode, pos: pos != null ? pos : null };
81
+ const finalCandidate = candidates[0];
82
+ const candidatePos = editor.view.posAtDOM(finalCandidate, 0);
83
+ if (candidatePos === -1) {
84
+ return { resultElement: finalCandidate, resultNode: null, pos: null };
85
+ }
86
+ const candidateNode = editor.state.doc.nodeAt(candidatePos - 1);
87
+ return { resultElement: finalCandidate, resultNode: candidateNode, pos: candidatePos };
95
88
  };
96
89
 
97
90
  // src/helpers/getComputedStyle.ts
@@ -256,6 +249,8 @@ var DragHandlePlugin = ({
256
249
  let currentNode = null;
257
250
  let currentNodePos = -1;
258
251
  let currentNodeRelPos;
252
+ let rafId = null;
253
+ let pendingMouseCoords = null;
259
254
  function hideHandle() {
260
255
  if (!element) {
261
256
  return;
@@ -309,6 +304,11 @@ var DragHandlePlugin = ({
309
304
  unbind() {
310
305
  element.removeEventListener("dragstart", onDragStart);
311
306
  element.removeEventListener("dragend", onDragEnd);
307
+ if (rafId) {
308
+ cancelAnimationFrame(rafId);
309
+ rafId = null;
310
+ pendingMouseCoords = null;
311
+ }
312
312
  },
313
313
  plugin: new import_state.Plugin({
314
314
  key: typeof pluginKey === "string" ? new import_state.PluginKey(pluginKey) : pluginKey,
@@ -392,6 +392,11 @@ var DragHandlePlugin = ({
392
392
  },
393
393
  // TODO: Kills even on hot reload
394
394
  destroy() {
395
+ if (rafId) {
396
+ cancelAnimationFrame(rafId);
397
+ rafId = null;
398
+ pendingMouseCoords = null;
399
+ }
395
400
  if (element) {
396
401
  removeNode(wrapper);
397
402
  }
@@ -429,34 +434,46 @@ var DragHandlePlugin = ({
429
434
  if (!element || locked) {
430
435
  return false;
431
436
  }
432
- const nodeData = findElementNextToCoords({
433
- x: e.clientX,
434
- y: e.clientY,
435
- direction: "right",
436
- editor
437
- });
438
- if (!nodeData.resultElement) {
437
+ pendingMouseCoords = { x: e.clientX, y: e.clientY };
438
+ if (rafId) {
439
439
  return false;
440
440
  }
441
- let domNode = nodeData.resultElement;
442
- domNode = getOuterDomNode(view, domNode);
443
- if (domNode === view.dom) {
444
- return false;
445
- }
446
- if ((domNode == null ? void 0 : domNode.nodeType) !== 1) {
447
- return false;
448
- }
449
- const domNodePos = view.posAtDOM(domNode, 0);
450
- const outerNode = getOuterNode(editor.state.doc, domNodePos);
451
- if (outerNode !== currentNode) {
452
- const outerNodePos = getOuterNodePos(editor.state.doc, domNodePos);
453
- currentNode = outerNode;
454
- currentNodePos = outerNodePos;
455
- currentNodeRelPos = getRelativePos(view.state, currentNodePos);
456
- onNodeChange == null ? void 0 : onNodeChange({ editor, node: currentNode, pos: currentNodePos });
457
- repositionDragHandle(domNode);
458
- showHandle();
459
- }
441
+ rafId = requestAnimationFrame(() => {
442
+ rafId = null;
443
+ if (!pendingMouseCoords) {
444
+ return;
445
+ }
446
+ const { x, y } = pendingMouseCoords;
447
+ pendingMouseCoords = null;
448
+ const nodeData = findElementNextToCoords({
449
+ x,
450
+ y,
451
+ direction: "right",
452
+ editor
453
+ });
454
+ if (!nodeData.resultElement) {
455
+ return;
456
+ }
457
+ let domNode = nodeData.resultElement;
458
+ domNode = getOuterDomNode(view, domNode);
459
+ if (domNode === view.dom) {
460
+ return;
461
+ }
462
+ if ((domNode == null ? void 0 : domNode.nodeType) !== 1) {
463
+ return;
464
+ }
465
+ const domNodePos = view.posAtDOM(domNode, 0);
466
+ const outerNode = getOuterNode(editor.state.doc, domNodePos);
467
+ if (outerNode !== currentNode) {
468
+ const outerNodePos = getOuterNodePos(editor.state.doc, domNodePos);
469
+ currentNode = outerNode;
470
+ currentNodePos = outerNodePos;
471
+ currentNodeRelPos = getRelativePos(view.state, currentNodePos);
472
+ onNodeChange == null ? void 0 : onNodeChange({ editor, node: currentNode, pos: currentNodePos });
473
+ repositionDragHandle(domNode);
474
+ showHandle();
475
+ }
476
+ });
460
477
  return false;
461
478
  }
462
479
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/drag-handle.ts","../src/drag-handle-plugin.ts","../src/helpers/dragHandler.ts","../src/helpers/cloneElement.ts","../src/helpers/findNextElementFromCursor.ts","../src/helpers/getComputedStyle.ts","../src/helpers/minMax.ts","../src/helpers/getInnerCoords.ts","../src/helpers/removeNode.ts","../src/helpers/getOuterNode.ts"],"sourcesContent":["import { DragHandle } from './drag-handle.js'\n\nexport * from './drag-handle.js'\nexport * from './drag-handle-plugin.js'\n\nexport default DragHandle\n","import type { ComputePositionConfig } from '@floating-ui/dom'\nimport { type Editor, Extension } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\n\nimport { DragHandlePlugin } from './drag-handle-plugin.js'\n\nexport const defaultComputePositionConfig: ComputePositionConfig = {\n placement: 'left-start',\n strategy: 'absolute',\n}\n\nexport interface DragHandleOptions {\n /**\n * Renders an element that is positioned with the floating-ui/dom package\n */\n render(): HTMLElement\n /**\n * Configuration for position computation of the drag handle\n * using the floating-ui/dom package\n */\n computePositionConfig?: ComputePositionConfig\n /**\n * Locks the draghandle in place and visibility\n */\n locked?: boolean\n /**\n * Returns a node or null when a node is hovered over\n */\n onNodeChange?: (options: { node: Node | null; editor: Editor }) => void\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n dragHandle: {\n /**\n * Locks the draghandle in place and visibility\n */\n lockDragHandle: () => ReturnType\n /**\n * Unlocks the draghandle\n */\n unlockDragHandle: () => ReturnType\n /**\n * Toggle draghandle lock state\n */\n toggleDragHandle: () => ReturnType\n }\n }\n}\n\nexport const DragHandle = Extension.create<DragHandleOptions>({\n name: 'dragHandle',\n\n addOptions() {\n return {\n render() {\n const element = document.createElement('div')\n\n element.classList.add('drag-handle')\n\n return element\n },\n computePositionConfig: {},\n locked: false,\n onNodeChange: () => {\n return null\n },\n }\n },\n\n addCommands() {\n return {\n lockDragHandle:\n () =>\n ({ editor }) => {\n this.options.locked = true\n return editor.commands.setMeta('lockDragHandle', this.options.locked)\n },\n unlockDragHandle:\n () =>\n ({ editor }) => {\n this.options.locked = false\n return editor.commands.setMeta('lockDragHandle', this.options.locked)\n },\n toggleDragHandle:\n () =>\n ({ editor }) => {\n this.options.locked = !this.options.locked\n return editor.commands.setMeta('lockDragHandle', this.options.locked)\n },\n }\n },\n\n addProseMirrorPlugins() {\n const element = this.options.render()\n\n return [\n DragHandlePlugin({\n computePositionConfig: { ...defaultComputePositionConfig, ...this.options.computePositionConfig },\n element,\n editor: this.editor,\n onNodeChange: this.options.onNodeChange,\n }).plugin,\n ]\n },\n})\n","import { type ComputePositionConfig, computePosition } from '@floating-ui/dom'\nimport type { Editor } from '@tiptap/core'\nimport { isChangeOrigin } from '@tiptap/extension-collaboration'\nimport type { Node } from '@tiptap/pm/model'\nimport { type EditorState, type Transaction, Plugin, PluginKey } from '@tiptap/pm/state'\nimport type { EditorView } from '@tiptap/pm/view'\nimport {\n absolutePositionToRelativePosition,\n relativePositionToAbsolutePosition,\n ySyncPluginKey,\n} from '@tiptap/y-tiptap'\n\nimport { dragHandler } from './helpers/dragHandler.js'\nimport { findElementNextToCoords } from './helpers/findNextElementFromCursor.js'\nimport { getOuterNode, getOuterNodePos } from './helpers/getOuterNode.js'\nimport { removeNode } from './helpers/removeNode.js'\n\ntype PluginState = {\n locked: boolean\n}\n\nconst getRelativePos = (state: EditorState, absolutePos: number) => {\n const ystate = ySyncPluginKey.getState(state)\n\n if (!ystate) {\n return null\n }\n\n return absolutePositionToRelativePosition(absolutePos, ystate.type, ystate.binding.mapping)\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: y-prosemirror (and y-tiptap by extension) does not have types for relative positions\nconst getAbsolutePos = (state: EditorState, relativePos: any) => {\n const ystate = ySyncPluginKey.getState(state)\n\n if (!ystate) {\n return -1\n }\n\n return relativePositionToAbsolutePosition(ystate.doc, ystate.type, relativePos, ystate.binding.mapping) || 0\n}\n\nconst getOuterDomNode = (view: EditorView, domNode: HTMLElement) => {\n let tmpDomNode = domNode\n\n // Traverse to top level node.\n while (tmpDomNode?.parentNode) {\n if (tmpDomNode.parentNode === view.dom) {\n break\n }\n\n tmpDomNode = tmpDomNode.parentNode as HTMLElement\n }\n\n return tmpDomNode\n}\n\nexport interface DragHandlePluginProps {\n pluginKey?: PluginKey | string\n editor: Editor\n element: HTMLElement\n onNodeChange?: (data: { editor: Editor; node: Node | null; pos: number }) => void\n onElementDragStart?: (e: DragEvent) => void\n onElementDragEnd?: (e: DragEvent) => void\n computePositionConfig?: ComputePositionConfig\n}\n\nexport const dragHandlePluginDefaultKey = new PluginKey('dragHandle')\n\nexport const DragHandlePlugin = ({\n pluginKey = dragHandlePluginDefaultKey,\n element,\n editor,\n computePositionConfig,\n onNodeChange,\n onElementDragStart,\n onElementDragEnd,\n}: DragHandlePluginProps) => {\n const wrapper = document.createElement('div')\n let locked = false\n let currentNode: Node | null = null\n let currentNodePos = -1\n // biome-ignore lint/suspicious/noExplicitAny: See above - relative positions in y-prosemirror are not typed\n let currentNodeRelPos: any\n\n function hideHandle() {\n if (!element) {\n return\n }\n\n element.style.visibility = 'hidden'\n element.style.pointerEvents = 'none'\n }\n\n function showHandle() {\n if (!element) {\n return\n }\n\n if (!editor.isEditable) {\n hideHandle()\n return\n }\n\n element.style.visibility = ''\n element.style.pointerEvents = 'auto'\n }\n\n function repositionDragHandle(dom: Element) {\n const virtualElement = {\n getBoundingClientRect: () => dom.getBoundingClientRect(),\n }\n\n computePosition(virtualElement, element, computePositionConfig).then(val => {\n Object.assign(element.style, {\n position: val.strategy,\n left: `${val.x}px`,\n top: `${val.y}px`,\n })\n })\n }\n\n function onDragStart(e: DragEvent) {\n onElementDragStart?.(e)\n // Push this to the end of the event cue\n // Fixes bug where incorrect drag pos is returned if drag handle has position: absolute\n // @ts-ignore\n dragHandler(e, editor)\n\n setTimeout(() => {\n if (element) {\n element.style.pointerEvents = 'none'\n }\n }, 0)\n }\n\n function onDragEnd(e: DragEvent) {\n onElementDragEnd?.(e)\n hideHandle()\n if (element) {\n element.style.pointerEvents = 'auto'\n }\n }\n\n element.addEventListener('dragstart', onDragStart)\n element.addEventListener('dragend', onDragEnd)\n\n wrapper.appendChild(element)\n\n return {\n unbind() {\n element.removeEventListener('dragstart', onDragStart)\n element.removeEventListener('dragend', onDragEnd)\n },\n plugin: new Plugin({\n key: typeof pluginKey === 'string' ? new PluginKey(pluginKey) : pluginKey,\n\n state: {\n init() {\n return { locked: false }\n },\n apply(tr: Transaction, value: PluginState, _oldState: EditorState, state: EditorState) {\n const isLocked = tr.getMeta('lockDragHandle')\n const hideDragHandle = tr.getMeta('hideDragHandle')\n\n if (isLocked !== undefined) {\n locked = isLocked\n }\n\n if (hideDragHandle) {\n hideHandle()\n\n locked = false\n currentNode = null\n currentNodePos = -1\n\n onNodeChange?.({ editor, node: null, pos: -1 })\n\n return value\n }\n\n // Something has changed and drag handler is visible…\n if (tr.docChanged && currentNodePos !== -1 && element) {\n // Yjs replaces the entire document on every incoming change and needs a special handling.\n // If change comes from another user …\n if (isChangeOrigin(tr)) {\n // https://discuss.yjs.dev/t/y-prosemirror-mapping-a-single-relative-position-when-doc-changes/851/3\n const newPos = getAbsolutePos(state, currentNodeRelPos)\n\n if (newPos !== currentNodePos) {\n // Set the new position for our current node.\n currentNodePos = newPos\n\n // We will get the outer node with data and position in views update method.\n }\n } else {\n // … otherwise use ProseMirror mapping to update the position.\n const newPos = tr.mapping.map(currentNodePos)\n\n if (newPos !== currentNodePos) {\n // TODO: Remove\n // console.log('Position has changed …', { old: currentNodePos, new: newPos }, tr);\n\n // Set the new position for our current node.\n currentNodePos = newPos\n\n // Memorize relative position to retrieve absolute position in case of collaboration\n currentNodeRelPos = getRelativePos(state, currentNodePos)\n\n // We will get the outer node with data and position in views update method.\n }\n }\n }\n\n return value\n },\n },\n\n view: view => {\n element.draggable = true\n element.style.pointerEvents = 'auto'\n\n editor.view.dom.parentElement?.appendChild(wrapper)\n\n wrapper.style.pointerEvents = 'none'\n wrapper.style.position = 'absolute'\n wrapper.style.top = '0'\n wrapper.style.left = '0'\n\n return {\n update(_, oldState) {\n if (!element) {\n return\n }\n\n if (!editor.isEditable) {\n hideHandle()\n return\n }\n\n // Prevent element being draggend while being open.\n if (locked) {\n element.draggable = false\n } else {\n element.draggable = true\n }\n\n // Recalculate popup position if doc has changend and drag handler is visible.\n if (view.state.doc.eq(oldState.doc) || currentNodePos === -1) {\n return\n }\n\n // Get domNode from (new) position.\n let domNode = view.nodeDOM(currentNodePos) as HTMLElement\n\n // Since old element could have been wrapped, we need to find\n // the outer node and take its position and node data.\n domNode = getOuterDomNode(view, domNode)\n\n // Skip if domNode is editor dom.\n if (domNode === view.dom) {\n return\n }\n\n // We only want `Element`.\n if (domNode?.nodeType !== 1) {\n return\n }\n\n const domNodePos = view.posAtDOM(domNode, 0)\n const outerNode = getOuterNode(editor.state.doc, domNodePos)\n const outerNodePos = getOuterNodePos(editor.state.doc, domNodePos) // TODO: needed?\n\n currentNode = outerNode\n currentNodePos = outerNodePos\n\n // Memorize relative position to retrieve absolute position in case of collaboration\n currentNodeRelPos = getRelativePos(view.state, currentNodePos)\n\n onNodeChange?.({ editor, node: currentNode, pos: currentNodePos })\n\n repositionDragHandle(domNode as Element)\n },\n\n // TODO: Kills even on hot reload\n destroy() {\n if (element) {\n removeNode(wrapper)\n }\n },\n }\n },\n\n props: {\n handleDOMEvents: {\n keydown(view) {\n if (!element || locked) {\n return false\n }\n\n if (view.hasFocus()) {\n hideHandle()\n currentNode = null\n currentNodePos = -1\n onNodeChange?.({ editor, node: null, pos: -1 })\n\n // We want to still continue with other keydown events.\n return false\n }\n\n return false\n },\n mouseleave(_view, e) {\n // Do not hide open popup on mouseleave.\n if (locked) {\n return false\n }\n\n // If e.target is not inside the wrapper, hide.\n if (e.target && !wrapper.contains(e.relatedTarget as HTMLElement)) {\n hideHandle()\n\n currentNode = null\n currentNodePos = -1\n\n onNodeChange?.({ editor, node: null, pos: -1 })\n }\n\n return false\n },\n\n mousemove(view, e) {\n // Do not continue if popup is not initialized or open.\n if (!element || locked) {\n return false\n }\n\n const nodeData = findElementNextToCoords({\n x: e.clientX,\n y: e.clientY,\n direction: 'right',\n editor,\n })\n\n // Skip if there is no node next to coords\n if (!nodeData.resultElement) {\n return false\n }\n\n let domNode = nodeData.resultElement as HTMLElement\n\n domNode = getOuterDomNode(view, domNode)\n\n // Skip if domNode is editor dom.\n if (domNode === view.dom) {\n return false\n }\n\n // We only want `Element`.\n if (domNode?.nodeType !== 1) {\n return false\n }\n\n const domNodePos = view.posAtDOM(domNode, 0)\n const outerNode = getOuterNode(editor.state.doc, domNodePos)\n\n if (outerNode !== currentNode) {\n const outerNodePos = getOuterNodePos(editor.state.doc, domNodePos)\n\n currentNode = outerNode\n currentNodePos = outerNodePos\n\n // Memorize relative position to retrieve absolute position in case of collaboration\n currentNodeRelPos = getRelativePos(view.state, currentNodePos)\n\n onNodeChange?.({ editor, node: currentNode, pos: currentNodePos })\n\n // Set nodes clientRect.\n repositionDragHandle(domNode as Element)\n\n showHandle()\n }\n\n return false\n },\n },\n },\n }),\n }\n}\n","import type { Editor } from '@tiptap/core'\nimport { getSelectionRanges, NodeRangeSelection } from '@tiptap/extension-node-range'\nimport type { SelectionRange } from '@tiptap/pm/state'\n\nimport { cloneElement } from './cloneElement.js'\nimport { findElementNextToCoords } from './findNextElementFromCursor.js'\nimport { getInnerCoords } from './getInnerCoords.js'\nimport { removeNode } from './removeNode.js'\n\nfunction getDragHandleRanges(event: DragEvent, editor: Editor): SelectionRange[] {\n const { doc } = editor.view.state\n\n const result = findElementNextToCoords({\n editor,\n x: event.clientX,\n y: event.clientY,\n direction: 'right',\n })\n\n if (!result.resultNode || result.pos === null) {\n return []\n }\n\n const x = event.clientX\n\n // @ts-ignore\n const coords = getInnerCoords(editor.view, x, event.clientY)\n const posAtCoords = editor.view.posAtCoords(coords)\n\n if (!posAtCoords) {\n return []\n }\n\n const { pos } = posAtCoords\n const nodeAt = doc.resolve(pos).parent\n\n if (!nodeAt) {\n return []\n }\n\n const $from = doc.resolve(result.pos)\n const $to = doc.resolve(result.pos + 1)\n\n return getSelectionRanges($from, $to, 0)\n}\n\nexport function dragHandler(event: DragEvent, editor: Editor) {\n const { view } = editor\n\n if (!event.dataTransfer) {\n return\n }\n\n const { empty, $from, $to } = view.state.selection\n\n const dragHandleRanges = getDragHandleRanges(event, editor)\n\n const selectionRanges = getSelectionRanges($from, $to, 0)\n const isDragHandleWithinSelection = selectionRanges.some(range => {\n return dragHandleRanges.find(dragHandleRange => {\n return dragHandleRange.$from === range.$from && dragHandleRange.$to === range.$to\n })\n })\n\n const ranges = empty || !isDragHandleWithinSelection ? dragHandleRanges : selectionRanges\n\n if (!ranges.length) {\n return\n }\n\n const { tr } = view.state\n const wrapper = document.createElement('div')\n const from = ranges[0].$from.pos\n const to = ranges[ranges.length - 1].$to.pos\n\n const selection = NodeRangeSelection.create(view.state.doc, from, to)\n const slice = selection.content()\n\n ranges.forEach(range => {\n const element = view.nodeDOM(range.$from.pos) as HTMLElement\n const clonedElement = cloneElement(element)\n\n wrapper.append(clonedElement)\n })\n\n wrapper.style.position = 'absolute'\n wrapper.style.top = '-10000px'\n document.body.append(wrapper)\n\n event.dataTransfer.clearData()\n event.dataTransfer.setDragImage(wrapper, 0, 0)\n\n // tell ProseMirror the dragged content\n view.dragging = { slice, move: true }\n\n tr.setSelection(selection)\n\n view.dispatch(tr)\n\n // clean up\n document.addEventListener('drop', () => removeNode(wrapper), { once: true })\n}\n","function getCSSText(element: Element) {\n let value = ''\n const style = getComputedStyle(element)\n\n for (let i = 0; i < style.length; i += 1) {\n value += `${style[i]}:${style.getPropertyValue(style[i])};`\n }\n\n return value\n}\n\nexport function cloneElement(node: HTMLElement) {\n const clonedNode = node.cloneNode(true) as HTMLElement\n const sourceElements = [node, ...Array.from(node.getElementsByTagName('*'))] as HTMLElement[]\n const targetElements = [clonedNode, ...Array.from(clonedNode.getElementsByTagName('*'))] as HTMLElement[]\n\n sourceElements.forEach((sourceElement, index) => {\n targetElements[index].style.cssText = getCSSText(sourceElement)\n })\n\n return clonedNode\n}\n","import type { Editor } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\n\nexport type FindElementNextToCoords = {\n x: number\n y: number\n direction?: 'left' | 'right'\n editor: Editor\n}\n\nexport const findElementNextToCoords = (options: FindElementNextToCoords) => {\n const { x, y, direction, editor } = options\n let resultElement: HTMLElement | null = null\n let resultNode: Node | null = null\n let pos: number | null = null\n\n let currentX = x\n\n while (resultNode === null && currentX < window.innerWidth && currentX > 0) {\n const allElements = document.elementsFromPoint(currentX, y)\n const prosemirrorIndex = allElements.findIndex(element => element.classList.contains('ProseMirror'))\n const filteredElements = allElements.slice(0, prosemirrorIndex)\n\n if (filteredElements.length > 0) {\n const target = filteredElements[0]\n\n resultElement = target as HTMLElement\n pos = editor.view.posAtDOM(target, 0)\n\n if (pos >= 0) {\n resultNode = editor.state.doc.nodeAt(Math.max(pos - 1, 0))\n\n if (resultNode?.isText) {\n resultNode = editor.state.doc.nodeAt(Math.max(pos - 1, 0))\n }\n\n if (!resultNode) {\n resultNode = editor.state.doc.nodeAt(Math.max(pos, 0))\n }\n\n break\n }\n }\n\n if (direction === 'left') {\n currentX -= 1\n } else {\n currentX += 1\n }\n }\n\n return { resultElement, resultNode, pos: pos ?? null }\n}\n","export function getComputedStyle(node: Element, property: keyof CSSStyleDeclaration): any {\n const style = window.getComputedStyle(node)\n\n return style[property]\n}\n","export function minMax(value = 0, min = 0, max = 0): number {\n return Math.min(Math.max(value, min), max)\n}\n","import type { EditorView } from '@tiptap/pm/view'\n\nimport { getComputedStyle } from './getComputedStyle.js'\nimport { minMax } from './minMax.js'\n\nexport function getInnerCoords(view: EditorView, x: number, y: number): { left: number; top: number } {\n const paddingLeft = parseInt(getComputedStyle(view.dom, 'paddingLeft'), 10)\n const paddingRight = parseInt(getComputedStyle(view.dom, 'paddingRight'), 10)\n const borderLeft = parseInt(getComputedStyle(view.dom, 'borderLeftWidth'), 10)\n const borderRight = parseInt(getComputedStyle(view.dom, 'borderLeftWidth'), 10)\n const bounds = view.dom.getBoundingClientRect()\n const coords = {\n left: minMax(x, bounds.left + paddingLeft + borderLeft, bounds.right - paddingRight - borderRight),\n top: y,\n }\n\n return coords\n}\n","export function removeNode(node: HTMLElement) {\n node.parentNode?.removeChild(node)\n}\n","import type { Node } from '@tiptap/pm/model'\n\nexport const getOuterNodePos = (doc: Node, pos: number): number => {\n const resolvedPos = doc.resolve(pos)\n const { depth } = resolvedPos\n\n if (depth === 0) {\n return pos\n }\n\n const a = resolvedPos.pos - resolvedPos.parentOffset\n\n return a - 1\n}\n\nexport const getOuterNode = (doc: Node, pos: number): Node | null => {\n const node = doc.nodeAt(pos)\n const resolvedPos = doc.resolve(pos)\n\n let { depth } = resolvedPos\n let parent = node\n\n while (depth > 0) {\n const currentNode = resolvedPos.node(depth)\n\n depth -= 1\n\n if (depth === 0) {\n parent = currentNode\n }\n }\n\n return parent\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,kBAAuC;;;ACDvC,iBAA4D;AAE5D,qCAA+B;AAE/B,mBAAsE;AAEtE,sBAIO;;;ACTP,kCAAuD;;;ACDvD,SAAS,WAAW,SAAkB;AACpC,MAAI,QAAQ;AACZ,QAAM,QAAQ,iBAAiB,OAAO;AAEtC,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,GAAG;AACxC,aAAS,GAAG,MAAM,CAAC,CAAC,IAAI,MAAM,iBAAiB,MAAM,CAAC,CAAC,CAAC;AAAA,EAC1D;AAEA,SAAO;AACT;AAEO,SAAS,aAAa,MAAmB;AAC9C,QAAM,aAAa,KAAK,UAAU,IAAI;AACtC,QAAM,iBAAiB,CAAC,MAAM,GAAG,MAAM,KAAK,KAAK,qBAAqB,GAAG,CAAC,CAAC;AAC3E,QAAM,iBAAiB,CAAC,YAAY,GAAG,MAAM,KAAK,WAAW,qBAAqB,GAAG,CAAC,CAAC;AAEvF,iBAAe,QAAQ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ts","../src/drag-handle-plugin.ts","../src/helpers/dragHandler.ts","../src/helpers/cloneElement.ts","../src/helpers/findNextElementFromCursor.ts","../src/helpers/getComputedStyle.ts","../src/helpers/minMax.ts","../src/helpers/getInnerCoords.ts","../src/helpers/removeNode.ts","../src/helpers/getOuterNode.ts"],"sourcesContent":["import { DragHandle } from './drag-handle.js'\n\nexport * from './drag-handle.js'\nexport * from './drag-handle-plugin.js'\n\nexport default DragHandle\n","import type { ComputePositionConfig } from '@floating-ui/dom'\nimport { type Editor, Extension } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\n\nimport { DragHandlePlugin } from './drag-handle-plugin.js'\n\nexport const defaultComputePositionConfig: ComputePositionConfig = {\n placement: 'left-start',\n strategy: 'absolute',\n}\n\nexport interface DragHandleOptions {\n /**\n * Renders an element that is positioned with the floating-ui/dom package\n */\n render(): HTMLElement\n /**\n * Configuration for position computation of the drag handle\n * using the floating-ui/dom package\n */\n computePositionConfig?: ComputePositionConfig\n /**\n * Locks the draghandle in place and visibility\n */\n locked?: boolean\n /**\n * Returns a node or null when a node is hovered over\n */\n onNodeChange?: (options: { node: Node | null; editor: Editor }) => void\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n dragHandle: {\n /**\n * Locks the draghandle in place and visibility\n */\n lockDragHandle: () => ReturnType\n /**\n * Unlocks the draghandle\n */\n unlockDragHandle: () => ReturnType\n /**\n * Toggle draghandle lock state\n */\n toggleDragHandle: () => ReturnType\n }\n }\n}\n\nexport const DragHandle = Extension.create<DragHandleOptions>({\n name: 'dragHandle',\n\n addOptions() {\n return {\n render() {\n const element = document.createElement('div')\n\n element.classList.add('drag-handle')\n\n return element\n },\n computePositionConfig: {},\n locked: false,\n onNodeChange: () => {\n return null\n },\n }\n },\n\n addCommands() {\n return {\n lockDragHandle:\n () =>\n ({ editor }) => {\n this.options.locked = true\n return editor.commands.setMeta('lockDragHandle', this.options.locked)\n },\n unlockDragHandle:\n () =>\n ({ editor }) => {\n this.options.locked = false\n return editor.commands.setMeta('lockDragHandle', this.options.locked)\n },\n toggleDragHandle:\n () =>\n ({ editor }) => {\n this.options.locked = !this.options.locked\n return editor.commands.setMeta('lockDragHandle', this.options.locked)\n },\n }\n },\n\n addProseMirrorPlugins() {\n const element = this.options.render()\n\n return [\n DragHandlePlugin({\n computePositionConfig: { ...defaultComputePositionConfig, ...this.options.computePositionConfig },\n element,\n editor: this.editor,\n onNodeChange: this.options.onNodeChange,\n }).plugin,\n ]\n },\n})\n","import { type ComputePositionConfig, computePosition } from '@floating-ui/dom'\nimport type { Editor } from '@tiptap/core'\nimport { isChangeOrigin } from '@tiptap/extension-collaboration'\nimport type { Node } from '@tiptap/pm/model'\nimport { type EditorState, type Transaction, Plugin, PluginKey } from '@tiptap/pm/state'\nimport type { EditorView } from '@tiptap/pm/view'\nimport {\n absolutePositionToRelativePosition,\n relativePositionToAbsolutePosition,\n ySyncPluginKey,\n} from '@tiptap/y-tiptap'\n\nimport { dragHandler } from './helpers/dragHandler.js'\nimport { findElementNextToCoords } from './helpers/findNextElementFromCursor.js'\nimport { getOuterNode, getOuterNodePos } from './helpers/getOuterNode.js'\nimport { removeNode } from './helpers/removeNode.js'\n\ntype PluginState = {\n locked: boolean\n}\n\nconst getRelativePos = (state: EditorState, absolutePos: number) => {\n const ystate = ySyncPluginKey.getState(state)\n\n if (!ystate) {\n return null\n }\n\n return absolutePositionToRelativePosition(absolutePos, ystate.type, ystate.binding.mapping)\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: y-prosemirror (and y-tiptap by extension) does not have types for relative positions\nconst getAbsolutePos = (state: EditorState, relativePos: any) => {\n const ystate = ySyncPluginKey.getState(state)\n\n if (!ystate) {\n return -1\n }\n\n return relativePositionToAbsolutePosition(ystate.doc, ystate.type, relativePos, ystate.binding.mapping) || 0\n}\n\nconst getOuterDomNode = (view: EditorView, domNode: HTMLElement) => {\n let tmpDomNode = domNode\n\n // Traverse to top level node.\n while (tmpDomNode?.parentNode) {\n if (tmpDomNode.parentNode === view.dom) {\n break\n }\n\n tmpDomNode = tmpDomNode.parentNode as HTMLElement\n }\n\n return tmpDomNode\n}\n\nexport interface DragHandlePluginProps {\n pluginKey?: PluginKey | string\n editor: Editor\n element: HTMLElement\n onNodeChange?: (data: { editor: Editor; node: Node | null; pos: number }) => void\n onElementDragStart?: (e: DragEvent) => void\n onElementDragEnd?: (e: DragEvent) => void\n computePositionConfig?: ComputePositionConfig\n}\n\nexport const dragHandlePluginDefaultKey = new PluginKey('dragHandle')\n\nexport const DragHandlePlugin = ({\n pluginKey = dragHandlePluginDefaultKey,\n element,\n editor,\n computePositionConfig,\n onNodeChange,\n onElementDragStart,\n onElementDragEnd,\n}: DragHandlePluginProps) => {\n const wrapper = document.createElement('div')\n let locked = false\n let currentNode: Node | null = null\n let currentNodePos = -1\n // biome-ignore lint/suspicious/noExplicitAny: See above - relative positions in y-prosemirror are not typed\n let currentNodeRelPos: any\n let rafId: number | null = null\n let pendingMouseCoords: { x: number; y: number } | null = null\n\n function hideHandle() {\n if (!element) {\n return\n }\n\n element.style.visibility = 'hidden'\n element.style.pointerEvents = 'none'\n }\n\n function showHandle() {\n if (!element) {\n return\n }\n\n if (!editor.isEditable) {\n hideHandle()\n return\n }\n\n element.style.visibility = ''\n element.style.pointerEvents = 'auto'\n }\n\n function repositionDragHandle(dom: Element) {\n const virtualElement = {\n getBoundingClientRect: () => dom.getBoundingClientRect(),\n }\n\n computePosition(virtualElement, element, computePositionConfig).then(val => {\n Object.assign(element.style, {\n position: val.strategy,\n left: `${val.x}px`,\n top: `${val.y}px`,\n })\n })\n }\n\n function onDragStart(e: DragEvent) {\n onElementDragStart?.(e)\n // Push this to the end of the event cue\n // Fixes bug where incorrect drag pos is returned if drag handle has position: absolute\n // @ts-ignore\n dragHandler(e, editor)\n\n setTimeout(() => {\n if (element) {\n element.style.pointerEvents = 'none'\n }\n }, 0)\n }\n\n function onDragEnd(e: DragEvent) {\n onElementDragEnd?.(e)\n hideHandle()\n if (element) {\n element.style.pointerEvents = 'auto'\n }\n }\n\n element.addEventListener('dragstart', onDragStart)\n element.addEventListener('dragend', onDragEnd)\n\n wrapper.appendChild(element)\n\n return {\n unbind() {\n element.removeEventListener('dragstart', onDragStart)\n element.removeEventListener('dragend', onDragEnd)\n if (rafId) {\n cancelAnimationFrame(rafId)\n rafId = null\n pendingMouseCoords = null\n }\n },\n plugin: new Plugin({\n key: typeof pluginKey === 'string' ? new PluginKey(pluginKey) : pluginKey,\n\n state: {\n init() {\n return { locked: false }\n },\n apply(tr: Transaction, value: PluginState, _oldState: EditorState, state: EditorState) {\n const isLocked = tr.getMeta('lockDragHandle')\n const hideDragHandle = tr.getMeta('hideDragHandle')\n\n if (isLocked !== undefined) {\n locked = isLocked\n }\n\n if (hideDragHandle) {\n hideHandle()\n\n locked = false\n currentNode = null\n currentNodePos = -1\n\n onNodeChange?.({ editor, node: null, pos: -1 })\n\n return value\n }\n\n // Something has changed and drag handler is visible…\n if (tr.docChanged && currentNodePos !== -1 && element) {\n // Yjs replaces the entire document on every incoming change and needs a special handling.\n // If change comes from another user …\n if (isChangeOrigin(tr)) {\n // https://discuss.yjs.dev/t/y-prosemirror-mapping-a-single-relative-position-when-doc-changes/851/3\n const newPos = getAbsolutePos(state, currentNodeRelPos)\n\n if (newPos !== currentNodePos) {\n // Set the new position for our current node.\n currentNodePos = newPos\n\n // We will get the outer node with data and position in views update method.\n }\n } else {\n // … otherwise use ProseMirror mapping to update the position.\n const newPos = tr.mapping.map(currentNodePos)\n\n if (newPos !== currentNodePos) {\n // TODO: Remove\n // console.log('Position has changed …', { old: currentNodePos, new: newPos }, tr);\n\n // Set the new position for our current node.\n currentNodePos = newPos\n\n // Memorize relative position to retrieve absolute position in case of collaboration\n currentNodeRelPos = getRelativePos(state, currentNodePos)\n\n // We will get the outer node with data and position in views update method.\n }\n }\n }\n\n return value\n },\n },\n\n view: view => {\n element.draggable = true\n element.style.pointerEvents = 'auto'\n\n editor.view.dom.parentElement?.appendChild(wrapper)\n\n wrapper.style.pointerEvents = 'none'\n wrapper.style.position = 'absolute'\n wrapper.style.top = '0'\n wrapper.style.left = '0'\n\n return {\n update(_, oldState) {\n if (!element) {\n return\n }\n\n if (!editor.isEditable) {\n hideHandle()\n return\n }\n\n // Prevent element being draggend while being open.\n if (locked) {\n element.draggable = false\n } else {\n element.draggable = true\n }\n\n // Recalculate popup position if doc has changend and drag handler is visible.\n if (view.state.doc.eq(oldState.doc) || currentNodePos === -1) {\n return\n }\n\n // Get domNode from (new) position.\n let domNode = view.nodeDOM(currentNodePos) as HTMLElement\n\n // Since old element could have been wrapped, we need to find\n // the outer node and take its position and node data.\n domNode = getOuterDomNode(view, domNode)\n\n // Skip if domNode is editor dom.\n if (domNode === view.dom) {\n return\n }\n\n // We only want `Element`.\n if (domNode?.nodeType !== 1) {\n return\n }\n\n const domNodePos = view.posAtDOM(domNode, 0)\n const outerNode = getOuterNode(editor.state.doc, domNodePos)\n const outerNodePos = getOuterNodePos(editor.state.doc, domNodePos) // TODO: needed?\n\n currentNode = outerNode\n currentNodePos = outerNodePos\n\n // Memorize relative position to retrieve absolute position in case of collaboration\n currentNodeRelPos = getRelativePos(view.state, currentNodePos)\n\n onNodeChange?.({ editor, node: currentNode, pos: currentNodePos })\n\n repositionDragHandle(domNode as Element)\n },\n\n // TODO: Kills even on hot reload\n destroy() {\n if (rafId) {\n cancelAnimationFrame(rafId)\n rafId = null\n pendingMouseCoords = null\n }\n\n if (element) {\n removeNode(wrapper)\n }\n },\n }\n },\n\n props: {\n handleDOMEvents: {\n keydown(view) {\n if (!element || locked) {\n return false\n }\n\n if (view.hasFocus()) {\n hideHandle()\n currentNode = null\n currentNodePos = -1\n onNodeChange?.({ editor, node: null, pos: -1 })\n\n // We want to still continue with other keydown events.\n return false\n }\n\n return false\n },\n mouseleave(_view, e) {\n // Do not hide open popup on mouseleave.\n if (locked) {\n return false\n }\n\n // If e.target is not inside the wrapper, hide.\n if (e.target && !wrapper.contains(e.relatedTarget as HTMLElement)) {\n hideHandle()\n\n currentNode = null\n currentNodePos = -1\n\n onNodeChange?.({ editor, node: null, pos: -1 })\n }\n\n return false\n },\n\n mousemove(view, e) {\n // Do not continue if popup is not initialized or open.\n if (!element || locked) {\n return false\n }\n\n // Store latest mouse coords and schedule a single RAF per frame\n pendingMouseCoords = { x: e.clientX, y: e.clientY }\n\n if (rafId) {\n return false\n }\n\n rafId = requestAnimationFrame(() => {\n rafId = null\n\n if (!pendingMouseCoords) {\n return\n }\n\n const { x, y } = pendingMouseCoords\n pendingMouseCoords = null\n\n const nodeData = findElementNextToCoords({\n x,\n y,\n direction: 'right',\n editor,\n })\n\n // Skip if there is no node next to coords\n if (!nodeData.resultElement) {\n return\n }\n\n let domNode = nodeData.resultElement as HTMLElement\n\n domNode = getOuterDomNode(view, domNode)\n\n // Skip if domNode is editor dom.\n if (domNode === view.dom) {\n return\n }\n\n // We only want `Element`.\n if (domNode?.nodeType !== 1) {\n return\n }\n\n const domNodePos = view.posAtDOM(domNode, 0)\n const outerNode = getOuterNode(editor.state.doc, domNodePos)\n\n if (outerNode !== currentNode) {\n const outerNodePos = getOuterNodePos(editor.state.doc, domNodePos)\n\n currentNode = outerNode\n currentNodePos = outerNodePos\n\n // Memorize relative position to retrieve absolute position in case of collaboration\n currentNodeRelPos = getRelativePos(view.state, currentNodePos)\n\n onNodeChange?.({ editor, node: currentNode, pos: currentNodePos })\n\n // Set nodes clientRect.\n repositionDragHandle(domNode as Element)\n\n showHandle()\n }\n })\n\n return false\n },\n },\n },\n }),\n }\n}\n","import type { Editor } from '@tiptap/core'\nimport { getSelectionRanges, NodeRangeSelection } from '@tiptap/extension-node-range'\nimport type { SelectionRange } from '@tiptap/pm/state'\n\nimport { cloneElement } from './cloneElement.js'\nimport { findElementNextToCoords } from './findNextElementFromCursor.js'\nimport { getInnerCoords } from './getInnerCoords.js'\nimport { removeNode } from './removeNode.js'\n\nfunction getDragHandleRanges(event: DragEvent, editor: Editor): SelectionRange[] {\n const { doc } = editor.view.state\n\n const result = findElementNextToCoords({\n editor,\n x: event.clientX,\n y: event.clientY,\n direction: 'right',\n })\n\n if (!result.resultNode || result.pos === null) {\n return []\n }\n\n const x = event.clientX\n\n // @ts-ignore\n const coords = getInnerCoords(editor.view, x, event.clientY)\n const posAtCoords = editor.view.posAtCoords(coords)\n\n if (!posAtCoords) {\n return []\n }\n\n const { pos } = posAtCoords\n const nodeAt = doc.resolve(pos).parent\n\n if (!nodeAt) {\n return []\n }\n\n const $from = doc.resolve(result.pos)\n const $to = doc.resolve(result.pos + 1)\n\n return getSelectionRanges($from, $to, 0)\n}\n\nexport function dragHandler(event: DragEvent, editor: Editor) {\n const { view } = editor\n\n if (!event.dataTransfer) {\n return\n }\n\n const { empty, $from, $to } = view.state.selection\n\n const dragHandleRanges = getDragHandleRanges(event, editor)\n\n const selectionRanges = getSelectionRanges($from, $to, 0)\n const isDragHandleWithinSelection = selectionRanges.some(range => {\n return dragHandleRanges.find(dragHandleRange => {\n return dragHandleRange.$from === range.$from && dragHandleRange.$to === range.$to\n })\n })\n\n const ranges = empty || !isDragHandleWithinSelection ? dragHandleRanges : selectionRanges\n\n if (!ranges.length) {\n return\n }\n\n const { tr } = view.state\n const wrapper = document.createElement('div')\n const from = ranges[0].$from.pos\n const to = ranges[ranges.length - 1].$to.pos\n\n const selection = NodeRangeSelection.create(view.state.doc, from, to)\n const slice = selection.content()\n\n ranges.forEach(range => {\n const element = view.nodeDOM(range.$from.pos) as HTMLElement\n const clonedElement = cloneElement(element)\n\n wrapper.append(clonedElement)\n })\n\n wrapper.style.position = 'absolute'\n wrapper.style.top = '-10000px'\n document.body.append(wrapper)\n\n event.dataTransfer.clearData()\n event.dataTransfer.setDragImage(wrapper, 0, 0)\n\n // tell ProseMirror the dragged content\n view.dragging = { slice, move: true }\n\n tr.setSelection(selection)\n\n view.dispatch(tr)\n\n // clean up\n document.addEventListener('drop', () => removeNode(wrapper), { once: true })\n}\n","function getCSSText(element: Element) {\n let value = ''\n const style = getComputedStyle(element)\n\n for (let i = 0; i < style.length; i += 1) {\n value += `${style[i]}:${style.getPropertyValue(style[i])};`\n }\n\n return value\n}\n\nexport function cloneElement(node: HTMLElement) {\n const clonedNode = node.cloneNode(true) as HTMLElement\n const sourceElements = [node, ...Array.from(node.getElementsByTagName('*'))] as HTMLElement[]\n const targetElements = [clonedNode, ...Array.from(clonedNode.getElementsByTagName('*'))] as HTMLElement[]\n\n sourceElements.forEach((sourceElement, index) => {\n targetElements[index].style.cssText = getCSSText(sourceElement)\n })\n\n return clonedNode\n}\n","import type { Editor } from '@tiptap/core'\n\nexport type FindElementNextToCoords = {\n x: number\n y: number\n direction?: 'left' | 'right'\n editor: Editor\n bandHeight?: number\n}\n\nexport const findElementNextToCoords = (options: FindElementNextToCoords) => {\n const { x, y, direction = 'right', editor, bandHeight = 5 } = options\n\n const rect = {\n top: y - bandHeight,\n bottom: y + bandHeight,\n left: direction === 'right' ? x : 0,\n right: direction === 'right' ? window.innerWidth - x : x,\n }\n\n const root = editor.view.dom as HTMLElement\n\n // Get potential candidates from prosemirror child elements and filter\n // by removing decorations and non prosemirror-elements\n const candidates = [...root.querySelectorAll<HTMLElement>('*')]\n .filter(candidate => {\n return editor.view.posAtDOM(candidate, 0) >= 0\n })\n .filter(candidate => {\n const candidateRect = candidate.getBoundingClientRect()\n return !(\n candidateRect.bottom < rect.top ||\n candidateRect.top > rect.bottom ||\n candidateRect.right < rect.left ||\n candidateRect.left > rect.right\n )\n })\n\n if (!candidates || candidates.length === 0) {\n return { resultElement: null, resultNode: null, pos: null }\n }\n\n const finalCandidate = candidates[0]\n const candidatePos = editor.view.posAtDOM(finalCandidate, 0)\n if (candidatePos === -1) {\n return { resultElement: finalCandidate, resultNode: null, pos: null }\n }\n\n const candidateNode = editor.state.doc.nodeAt(candidatePos - 1)\n\n return { resultElement: finalCandidate, resultNode: candidateNode, pos: candidatePos }\n}\n","export function getComputedStyle(node: Element, property: keyof CSSStyleDeclaration): any {\n const style = window.getComputedStyle(node)\n\n return style[property]\n}\n","export function minMax(value = 0, min = 0, max = 0): number {\n return Math.min(Math.max(value, min), max)\n}\n","import type { EditorView } from '@tiptap/pm/view'\n\nimport { getComputedStyle } from './getComputedStyle.js'\nimport { minMax } from './minMax.js'\n\nexport function getInnerCoords(view: EditorView, x: number, y: number): { left: number; top: number } {\n const paddingLeft = parseInt(getComputedStyle(view.dom, 'paddingLeft'), 10)\n const paddingRight = parseInt(getComputedStyle(view.dom, 'paddingRight'), 10)\n const borderLeft = parseInt(getComputedStyle(view.dom, 'borderLeftWidth'), 10)\n const borderRight = parseInt(getComputedStyle(view.dom, 'borderLeftWidth'), 10)\n const bounds = view.dom.getBoundingClientRect()\n const coords = {\n left: minMax(x, bounds.left + paddingLeft + borderLeft, bounds.right - paddingRight - borderRight),\n top: y,\n }\n\n return coords\n}\n","export function removeNode(node: HTMLElement) {\n node.parentNode?.removeChild(node)\n}\n","import type { Node } from '@tiptap/pm/model'\n\nexport const getOuterNodePos = (doc: Node, pos: number): number => {\n const resolvedPos = doc.resolve(pos)\n const { depth } = resolvedPos\n\n if (depth === 0) {\n return pos\n }\n\n const a = resolvedPos.pos - resolvedPos.parentOffset\n\n return a - 1\n}\n\nexport const getOuterNode = (doc: Node, pos: number): Node | null => {\n const node = doc.nodeAt(pos)\n const resolvedPos = doc.resolve(pos)\n\n let { depth } = resolvedPos\n let parent = node\n\n while (depth > 0) {\n const currentNode = resolvedPos.node(depth)\n\n depth -= 1\n\n if (depth === 0) {\n parent = currentNode\n }\n }\n\n return parent\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,kBAAuC;;;ACDvC,iBAA4D;AAE5D,qCAA+B;AAE/B,mBAAsE;AAEtE,sBAIO;;;ACTP,kCAAuD;;;ACDvD,SAAS,WAAW,SAAkB;AACpC,MAAI,QAAQ;AACZ,QAAM,QAAQ,iBAAiB,OAAO;AAEtC,WAAS,I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;AACZ,WAAO;AAAA,MACL,gBACE,MACA,CAAC,EAAE,OAAO,MAAM;AACd,aAAK,QAAQ,SAAS;AACtB,eAAO,OAAO,SAAS,QAAQ,kBAAkB,KAAK,QAAQ,MAAM;AAAA,MACtE;AAAA,MACF,kBACE,MACA,CAAC,EAAE,OAAO,MAAM;AACd,aAAK,QAAQ,SAAS;AACtB,eAAO,OAAO,SAAS,QAAQ,kBAAkB,KAAK,QAAQ,MAAM;AAAA,MACtE;AAAA,MACF,kBACE,MACA,CAAC,EAAE,OAAO,MAAM;AACd,aAAK,QAAQ,SAAS,CAAC,KAAK,QAAQ;AACpC,eAAO,OAAO,SAAS,QAAQ,kBAAkB,KAAK,QAAQ,MAAM;AAAA,MACtE;AAAA,IACJ;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,UAAM,UAAU,KAAK,QAAQ,OAAO;AAEpC,WAAO;AAAA,MACL,iBAAiB;AAAA,QACf,uBAAuB,EAAE,GAAG,8BAA8B,GAAG,KAAK,QAAQ,sBAAsB;AAAA,QAChG;AAAA,QACA,QAAQ,KAAK;AAAA,QACb,cAAc,KAAK,QAAQ;AAAA,MAC7B,CAAC,EAAE;AAAA,IACL;AAAA,EACF;AACF,CAAC;;;ADpGD,IAAO,gBAAQ;","names":["getComputedStyle","getComputedStyle"]}
package/dist/index.js CHANGED
@@ -35,37 +35,30 @@ function cloneElement(node) {
35
35
 
36
36
  // src/helpers/findNextElementFromCursor.ts
37
37
  var findElementNextToCoords = (options) => {
38
- const { x, y, direction, editor } = options;
39
- let resultElement = null;
40
- let resultNode = null;
41
- let pos = null;
42
- let currentX = x;
43
- while (resultNode === null && currentX < window.innerWidth && currentX > 0) {
44
- const allElements = document.elementsFromPoint(currentX, y);
45
- const prosemirrorIndex = allElements.findIndex((element) => element.classList.contains("ProseMirror"));
46
- const filteredElements = allElements.slice(0, prosemirrorIndex);
47
- if (filteredElements.length > 0) {
48
- const target = filteredElements[0];
49
- resultElement = target;
50
- pos = editor.view.posAtDOM(target, 0);
51
- if (pos >= 0) {
52
- resultNode = editor.state.doc.nodeAt(Math.max(pos - 1, 0));
53
- if (resultNode == null ? void 0 : resultNode.isText) {
54
- resultNode = editor.state.doc.nodeAt(Math.max(pos - 1, 0));
55
- }
56
- if (!resultNode) {
57
- resultNode = editor.state.doc.nodeAt(Math.max(pos, 0));
58
- }
59
- break;
60
- }
61
- }
62
- if (direction === "left") {
63
- currentX -= 1;
64
- } else {
65
- currentX += 1;
66
- }
38
+ const { x, y, direction = "right", editor, bandHeight = 5 } = options;
39
+ const rect = {
40
+ top: y - bandHeight,
41
+ bottom: y + bandHeight,
42
+ left: direction === "right" ? x : 0,
43
+ right: direction === "right" ? window.innerWidth - x : x
44
+ };
45
+ const root = editor.view.dom;
46
+ const candidates = [...root.querySelectorAll("*")].filter((candidate) => {
47
+ return editor.view.posAtDOM(candidate, 0) >= 0;
48
+ }).filter((candidate) => {
49
+ const candidateRect = candidate.getBoundingClientRect();
50
+ return !(candidateRect.bottom < rect.top || candidateRect.top > rect.bottom || candidateRect.right < rect.left || candidateRect.left > rect.right);
51
+ });
52
+ if (!candidates || candidates.length === 0) {
53
+ return { resultElement: null, resultNode: null, pos: null };
67
54
  }
68
- return { resultElement, resultNode, pos: pos != null ? pos : null };
55
+ const finalCandidate = candidates[0];
56
+ const candidatePos = editor.view.posAtDOM(finalCandidate, 0);
57
+ if (candidatePos === -1) {
58
+ return { resultElement: finalCandidate, resultNode: null, pos: null };
59
+ }
60
+ const candidateNode = editor.state.doc.nodeAt(candidatePos - 1);
61
+ return { resultElement: finalCandidate, resultNode: candidateNode, pos: candidatePos };
69
62
  };
70
63
 
71
64
  // src/helpers/getComputedStyle.ts
@@ -230,6 +223,8 @@ var DragHandlePlugin = ({
230
223
  let currentNode = null;
231
224
  let currentNodePos = -1;
232
225
  let currentNodeRelPos;
226
+ let rafId = null;
227
+ let pendingMouseCoords = null;
233
228
  function hideHandle() {
234
229
  if (!element) {
235
230
  return;
@@ -283,6 +278,11 @@ var DragHandlePlugin = ({
283
278
  unbind() {
284
279
  element.removeEventListener("dragstart", onDragStart);
285
280
  element.removeEventListener("dragend", onDragEnd);
281
+ if (rafId) {
282
+ cancelAnimationFrame(rafId);
283
+ rafId = null;
284
+ pendingMouseCoords = null;
285
+ }
286
286
  },
287
287
  plugin: new Plugin({
288
288
  key: typeof pluginKey === "string" ? new PluginKey(pluginKey) : pluginKey,
@@ -366,6 +366,11 @@ var DragHandlePlugin = ({
366
366
  },
367
367
  // TODO: Kills even on hot reload
368
368
  destroy() {
369
+ if (rafId) {
370
+ cancelAnimationFrame(rafId);
371
+ rafId = null;
372
+ pendingMouseCoords = null;
373
+ }
369
374
  if (element) {
370
375
  removeNode(wrapper);
371
376
  }
@@ -403,34 +408,46 @@ var DragHandlePlugin = ({
403
408
  if (!element || locked) {
404
409
  return false;
405
410
  }
406
- const nodeData = findElementNextToCoords({
407
- x: e.clientX,
408
- y: e.clientY,
409
- direction: "right",
410
- editor
411
- });
412
- if (!nodeData.resultElement) {
411
+ pendingMouseCoords = { x: e.clientX, y: e.clientY };
412
+ if (rafId) {
413
413
  return false;
414
414
  }
415
- let domNode = nodeData.resultElement;
416
- domNode = getOuterDomNode(view, domNode);
417
- if (domNode === view.dom) {
418
- return false;
419
- }
420
- if ((domNode == null ? void 0 : domNode.nodeType) !== 1) {
421
- return false;
422
- }
423
- const domNodePos = view.posAtDOM(domNode, 0);
424
- const outerNode = getOuterNode(editor.state.doc, domNodePos);
425
- if (outerNode !== currentNode) {
426
- const outerNodePos = getOuterNodePos(editor.state.doc, domNodePos);
427
- currentNode = outerNode;
428
- currentNodePos = outerNodePos;
429
- currentNodeRelPos = getRelativePos(view.state, currentNodePos);
430
- onNodeChange == null ? void 0 : onNodeChange({ editor, node: currentNode, pos: currentNodePos });
431
- repositionDragHandle(domNode);
432
- showHandle();
433
- }
415
+ rafId = requestAnimationFrame(() => {
416
+ rafId = null;
417
+ if (!pendingMouseCoords) {
418
+ return;
419
+ }
420
+ const { x, y } = pendingMouseCoords;
421
+ pendingMouseCoords = null;
422
+ const nodeData = findElementNextToCoords({
423
+ x,
424
+ y,
425
+ direction: "right",
426
+ editor
427
+ });
428
+ if (!nodeData.resultElement) {
429
+ return;
430
+ }
431
+ let domNode = nodeData.resultElement;
432
+ domNode = getOuterDomNode(view, domNode);
433
+ if (domNode === view.dom) {
434
+ return;
435
+ }
436
+ if ((domNode == null ? void 0 : domNode.nodeType) !== 1) {
437
+ return;
438
+ }
439
+ const domNodePos = view.posAtDOM(domNode, 0);
440
+ const outerNode = getOuterNode(editor.state.doc, domNodePos);
441
+ if (outerNode !== currentNode) {
442
+ const outerNodePos = getOuterNodePos(editor.state.doc, domNodePos);
443
+ currentNode = outerNode;
444
+ currentNodePos = outerNodePos;
445
+ currentNodeRelPos = getRelativePos(view.state, currentNodePos);
446
+ onNodeChange == null ? void 0 : onNodeChange({ editor, node: currentNode, pos: currentNodePos });
447
+ repositionDragHandle(domNode);
448
+ showHandle();
449
+ }
450
+ });
434
451
  return false;
435
452
  }
436
453
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/drag-handle.ts","../src/drag-handle-plugin.ts","../src/helpers/dragHandler.ts","../src/helpers/cloneElement.ts","../src/helpers/findNextElementFromCursor.ts","../src/helpers/getComputedStyle.ts","../src/helpers/minMax.ts","../src/helpers/getInnerCoords.ts","../src/helpers/removeNode.ts","../src/helpers/getOuterNode.ts","../src/index.ts"],"sourcesContent":["import type { ComputePositionConfig } from '@floating-ui/dom'\nimport { type Editor, Extension } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\n\nimport { DragHandlePlugin } from './drag-handle-plugin.js'\n\nexport const defaultComputePositionConfig: ComputePositionConfig = {\n placement: 'left-start',\n strategy: 'absolute',\n}\n\nexport interface DragHandleOptions {\n /**\n * Renders an element that is positioned with the floating-ui/dom package\n */\n render(): HTMLElement\n /**\n * Configuration for position computation of the drag handle\n * using the floating-ui/dom package\n */\n computePositionConfig?: ComputePositionConfig\n /**\n * Locks the draghandle in place and visibility\n */\n locked?: boolean\n /**\n * Returns a node or null when a node is hovered over\n */\n onNodeChange?: (options: { node: Node | null; editor: Editor }) => void\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n dragHandle: {\n /**\n * Locks the draghandle in place and visibility\n */\n lockDragHandle: () => ReturnType\n /**\n * Unlocks the draghandle\n */\n unlockDragHandle: () => ReturnType\n /**\n * Toggle draghandle lock state\n */\n toggleDragHandle: () => ReturnType\n }\n }\n}\n\nexport const DragHandle = Extension.create<DragHandleOptions>({\n name: 'dragHandle',\n\n addOptions() {\n return {\n render() {\n const element = document.createElement('div')\n\n element.classList.add('drag-handle')\n\n return element\n },\n computePositionConfig: {},\n locked: false,\n onNodeChange: () => {\n return null\n },\n }\n },\n\n addCommands() {\n return {\n lockDragHandle:\n () =>\n ({ editor }) => {\n this.options.locked = true\n return editor.commands.setMeta('lockDragHandle', this.options.locked)\n },\n unlockDragHandle:\n () =>\n ({ editor }) => {\n this.options.locked = false\n return editor.commands.setMeta('lockDragHandle', this.options.locked)\n },\n toggleDragHandle:\n () =>\n ({ editor }) => {\n this.options.locked = !this.options.locked\n return editor.commands.setMeta('lockDragHandle', this.options.locked)\n },\n }\n },\n\n addProseMirrorPlugins() {\n const element = this.options.render()\n\n return [\n DragHandlePlugin({\n computePositionConfig: { ...defaultComputePositionConfig, ...this.options.computePositionConfig },\n element,\n editor: this.editor,\n onNodeChange: this.options.onNodeChange,\n }).plugin,\n ]\n },\n})\n","import { type ComputePositionConfig, computePosition } from '@floating-ui/dom'\nimport type { Editor } from '@tiptap/core'\nimport { isChangeOrigin } from '@tiptap/extension-collaboration'\nimport type { Node } from '@tiptap/pm/model'\nimport { type EditorState, type Transaction, Plugin, PluginKey } from '@tiptap/pm/state'\nimport type { EditorView } from '@tiptap/pm/view'\nimport {\n absolutePositionToRelativePosition,\n relativePositionToAbsolutePosition,\n ySyncPluginKey,\n} from '@tiptap/y-tiptap'\n\nimport { dragHandler } from './helpers/dragHandler.js'\nimport { findElementNextToCoords } from './helpers/findNextElementFromCursor.js'\nimport { getOuterNode, getOuterNodePos } from './helpers/getOuterNode.js'\nimport { removeNode } from './helpers/removeNode.js'\n\ntype PluginState = {\n locked: boolean\n}\n\nconst getRelativePos = (state: EditorState, absolutePos: number) => {\n const ystate = ySyncPluginKey.getState(state)\n\n if (!ystate) {\n return null\n }\n\n return absolutePositionToRelativePosition(absolutePos, ystate.type, ystate.binding.mapping)\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: y-prosemirror (and y-tiptap by extension) does not have types for relative positions\nconst getAbsolutePos = (state: EditorState, relativePos: any) => {\n const ystate = ySyncPluginKey.getState(state)\n\n if (!ystate) {\n return -1\n }\n\n return relativePositionToAbsolutePosition(ystate.doc, ystate.type, relativePos, ystate.binding.mapping) || 0\n}\n\nconst getOuterDomNode = (view: EditorView, domNode: HTMLElement) => {\n let tmpDomNode = domNode\n\n // Traverse to top level node.\n while (tmpDomNode?.parentNode) {\n if (tmpDomNode.parentNode === view.dom) {\n break\n }\n\n tmpDomNode = tmpDomNode.parentNode as HTMLElement\n }\n\n return tmpDomNode\n}\n\nexport interface DragHandlePluginProps {\n pluginKey?: PluginKey | string\n editor: Editor\n element: HTMLElement\n onNodeChange?: (data: { editor: Editor; node: Node | null; pos: number }) => void\n onElementDragStart?: (e: DragEvent) => void\n onElementDragEnd?: (e: DragEvent) => void\n computePositionConfig?: ComputePositionConfig\n}\n\nexport const dragHandlePluginDefaultKey = new PluginKey('dragHandle')\n\nexport const DragHandlePlugin = ({\n pluginKey = dragHandlePluginDefaultKey,\n element,\n editor,\n computePositionConfig,\n onNodeChange,\n onElementDragStart,\n onElementDragEnd,\n}: DragHandlePluginProps) => {\n const wrapper = document.createElement('div')\n let locked = false\n let currentNode: Node | null = null\n let currentNodePos = -1\n // biome-ignore lint/suspicious/noExplicitAny: See above - relative positions in y-prosemirror are not typed\n let currentNodeRelPos: any\n\n function hideHandle() {\n if (!element) {\n return\n }\n\n element.style.visibility = 'hidden'\n element.style.pointerEvents = 'none'\n }\n\n function showHandle() {\n if (!element) {\n return\n }\n\n if (!editor.isEditable) {\n hideHandle()\n return\n }\n\n element.style.visibility = ''\n element.style.pointerEvents = 'auto'\n }\n\n function repositionDragHandle(dom: Element) {\n const virtualElement = {\n getBoundingClientRect: () => dom.getBoundingClientRect(),\n }\n\n computePosition(virtualElement, element, computePositionConfig).then(val => {\n Object.assign(element.style, {\n position: val.strategy,\n left: `${val.x}px`,\n top: `${val.y}px`,\n })\n })\n }\n\n function onDragStart(e: DragEvent) {\n onElementDragStart?.(e)\n // Push this to the end of the event cue\n // Fixes bug where incorrect drag pos is returned if drag handle has position: absolute\n // @ts-ignore\n dragHandler(e, editor)\n\n setTimeout(() => {\n if (element) {\n element.style.pointerEvents = 'none'\n }\n }, 0)\n }\n\n function onDragEnd(e: DragEvent) {\n onElementDragEnd?.(e)\n hideHandle()\n if (element) {\n element.style.pointerEvents = 'auto'\n }\n }\n\n element.addEventListener('dragstart', onDragStart)\n element.addEventListener('dragend', onDragEnd)\n\n wrapper.appendChild(element)\n\n return {\n unbind() {\n element.removeEventListener('dragstart', onDragStart)\n element.removeEventListener('dragend', onDragEnd)\n },\n plugin: new Plugin({\n key: typeof pluginKey === 'string' ? new PluginKey(pluginKey) : pluginKey,\n\n state: {\n init() {\n return { locked: false }\n },\n apply(tr: Transaction, value: PluginState, _oldState: EditorState, state: EditorState) {\n const isLocked = tr.getMeta('lockDragHandle')\n const hideDragHandle = tr.getMeta('hideDragHandle')\n\n if (isLocked !== undefined) {\n locked = isLocked\n }\n\n if (hideDragHandle) {\n hideHandle()\n\n locked = false\n currentNode = null\n currentNodePos = -1\n\n onNodeChange?.({ editor, node: null, pos: -1 })\n\n return value\n }\n\n // Something has changed and drag handler is visible…\n if (tr.docChanged && currentNodePos !== -1 && element) {\n // Yjs replaces the entire document on every incoming change and needs a special handling.\n // If change comes from another user …\n if (isChangeOrigin(tr)) {\n // https://discuss.yjs.dev/t/y-prosemirror-mapping-a-single-relative-position-when-doc-changes/851/3\n const newPos = getAbsolutePos(state, currentNodeRelPos)\n\n if (newPos !== currentNodePos) {\n // Set the new position for our current node.\n currentNodePos = newPos\n\n // We will get the outer node with data and position in views update method.\n }\n } else {\n // … otherwise use ProseMirror mapping to update the position.\n const newPos = tr.mapping.map(currentNodePos)\n\n if (newPos !== currentNodePos) {\n // TODO: Remove\n // console.log('Position has changed …', { old: currentNodePos, new: newPos }, tr);\n\n // Set the new position for our current node.\n currentNodePos = newPos\n\n // Memorize relative position to retrieve absolute position in case of collaboration\n currentNodeRelPos = getRelativePos(state, currentNodePos)\n\n // We will get the outer node with data and position in views update method.\n }\n }\n }\n\n return value\n },\n },\n\n view: view => {\n element.draggable = true\n element.style.pointerEvents = 'auto'\n\n editor.view.dom.parentElement?.appendChild(wrapper)\n\n wrapper.style.pointerEvents = 'none'\n wrapper.style.position = 'absolute'\n wrapper.style.top = '0'\n wrapper.style.left = '0'\n\n return {\n update(_, oldState) {\n if (!element) {\n return\n }\n\n if (!editor.isEditable) {\n hideHandle()\n return\n }\n\n // Prevent element being draggend while being open.\n if (locked) {\n element.draggable = false\n } else {\n element.draggable = true\n }\n\n // Recalculate popup position if doc has changend and drag handler is visible.\n if (view.state.doc.eq(oldState.doc) || currentNodePos === -1) {\n return\n }\n\n // Get domNode from (new) position.\n let domNode = view.nodeDOM(currentNodePos) as HTMLElement\n\n // Since old element could have been wrapped, we need to find\n // the outer node and take its position and node data.\n domNode = getOuterDomNode(view, domNode)\n\n // Skip if domNode is editor dom.\n if (domNode === view.dom) {\n return\n }\n\n // We only want `Element`.\n if (domNode?.nodeType !== 1) {\n return\n }\n\n const domNodePos = view.posAtDOM(domNode, 0)\n const outerNode = getOuterNode(editor.state.doc, domNodePos)\n const outerNodePos = getOuterNodePos(editor.state.doc, domNodePos) // TODO: needed?\n\n currentNode = outerNode\n currentNodePos = outerNodePos\n\n // Memorize relative position to retrieve absolute position in case of collaboration\n currentNodeRelPos = getRelativePos(view.state, currentNodePos)\n\n onNodeChange?.({ editor, node: currentNode, pos: currentNodePos })\n\n repositionDragHandle(domNode as Element)\n },\n\n // TODO: Kills even on hot reload\n destroy() {\n if (element) {\n removeNode(wrapper)\n }\n },\n }\n },\n\n props: {\n handleDOMEvents: {\n keydown(view) {\n if (!element || locked) {\n return false\n }\n\n if (view.hasFocus()) {\n hideHandle()\n currentNode = null\n currentNodePos = -1\n onNodeChange?.({ editor, node: null, pos: -1 })\n\n // We want to still continue with other keydown events.\n return false\n }\n\n return false\n },\n mouseleave(_view, e) {\n // Do not hide open popup on mouseleave.\n if (locked) {\n return false\n }\n\n // If e.target is not inside the wrapper, hide.\n if (e.target && !wrapper.contains(e.relatedTarget as HTMLElement)) {\n hideHandle()\n\n currentNode = null\n currentNodePos = -1\n\n onNodeChange?.({ editor, node: null, pos: -1 })\n }\n\n return false\n },\n\n mousemove(view, e) {\n // Do not continue if popup is not initialized or open.\n if (!element || locked) {\n return false\n }\n\n const nodeData = findElementNextToCoords({\n x: e.clientX,\n y: e.clientY,\n direction: 'right',\n editor,\n })\n\n // Skip if there is no node next to coords\n if (!nodeData.resultElement) {\n return false\n }\n\n let domNode = nodeData.resultElement as HTMLElement\n\n domNode = getOuterDomNode(view, domNode)\n\n // Skip if domNode is editor dom.\n if (domNode === view.dom) {\n return false\n }\n\n // We only want `Element`.\n if (domNode?.nodeType !== 1) {\n return false\n }\n\n const domNodePos = view.posAtDOM(domNode, 0)\n const outerNode = getOuterNode(editor.state.doc, domNodePos)\n\n if (outerNode !== currentNode) {\n const outerNodePos = getOuterNodePos(editor.state.doc, domNodePos)\n\n currentNode = outerNode\n currentNodePos = outerNodePos\n\n // Memorize relative position to retrieve absolute position in case of collaboration\n currentNodeRelPos = getRelativePos(view.state, currentNodePos)\n\n onNodeChange?.({ editor, node: currentNode, pos: currentNodePos })\n\n // Set nodes clientRect.\n repositionDragHandle(domNode as Element)\n\n showHandle()\n }\n\n return false\n },\n },\n },\n }),\n }\n}\n","import type { Editor } from '@tiptap/core'\nimport { getSelectionRanges, NodeRangeSelection } from '@tiptap/extension-node-range'\nimport type { SelectionRange } from '@tiptap/pm/state'\n\nimport { cloneElement } from './cloneElement.js'\nimport { findElementNextToCoords } from './findNextElementFromCursor.js'\nimport { getInnerCoords } from './getInnerCoords.js'\nimport { removeNode } from './removeNode.js'\n\nfunction getDragHandleRanges(event: DragEvent, editor: Editor): SelectionRange[] {\n const { doc } = editor.view.state\n\n const result = findElementNextToCoords({\n editor,\n x: event.clientX,\n y: event.clientY,\n direction: 'right',\n })\n\n if (!result.resultNode || result.pos === null) {\n return []\n }\n\n const x = event.clientX\n\n // @ts-ignore\n const coords = getInnerCoords(editor.view, x, event.clientY)\n const posAtCoords = editor.view.posAtCoords(coords)\n\n if (!posAtCoords) {\n return []\n }\n\n const { pos } = posAtCoords\n const nodeAt = doc.resolve(pos).parent\n\n if (!nodeAt) {\n return []\n }\n\n const $from = doc.resolve(result.pos)\n const $to = doc.resolve(result.pos + 1)\n\n return getSelectionRanges($from, $to, 0)\n}\n\nexport function dragHandler(event: DragEvent, editor: Editor) {\n const { view } = editor\n\n if (!event.dataTransfer) {\n return\n }\n\n const { empty, $from, $to } = view.state.selection\n\n const dragHandleRanges = getDragHandleRanges(event, editor)\n\n const selectionRanges = getSelectionRanges($from, $to, 0)\n const isDragHandleWithinSelection = selectionRanges.some(range => {\n return dragHandleRanges.find(dragHandleRange => {\n return dragHandleRange.$from === range.$from && dragHandleRange.$to === range.$to\n })\n })\n\n const ranges = empty || !isDragHandleWithinSelection ? dragHandleRanges : selectionRanges\n\n if (!ranges.length) {\n return\n }\n\n const { tr } = view.state\n const wrapper = document.createElement('div')\n const from = ranges[0].$from.pos\n const to = ranges[ranges.length - 1].$to.pos\n\n const selection = NodeRangeSelection.create(view.state.doc, from, to)\n const slice = selection.content()\n\n ranges.forEach(range => {\n const element = view.nodeDOM(range.$from.pos) as HTMLElement\n const clonedElement = cloneElement(element)\n\n wrapper.append(clonedElement)\n })\n\n wrapper.style.position = 'absolute'\n wrapper.style.top = '-10000px'\n document.body.append(wrapper)\n\n event.dataTransfer.clearData()\n event.dataTransfer.setDragImage(wrapper, 0, 0)\n\n // tell ProseMirror the dragged content\n view.dragging = { slice, move: true }\n\n tr.setSelection(selection)\n\n view.dispatch(tr)\n\n // clean up\n document.addEventListener('drop', () => removeNode(wrapper), { once: true })\n}\n","function getCSSText(element: Element) {\n let value = ''\n const style = getComputedStyle(element)\n\n for (let i = 0; i < style.length; i += 1) {\n value += `${style[i]}:${style.getPropertyValue(style[i])};`\n }\n\n return value\n}\n\nexport function cloneElement(node: HTMLElement) {\n const clonedNode = node.cloneNode(true) as HTMLElement\n const sourceElements = [node, ...Array.from(node.getElementsByTagName('*'))] as HTMLElement[]\n const targetElements = [clonedNode, ...Array.from(clonedNode.getElementsByTagName('*'))] as HTMLElement[]\n\n sourceElements.forEach((sourceElement, index) => {\n targetElements[index].style.cssText = getCSSText(sourceElement)\n })\n\n return clonedNode\n}\n","import type { Editor } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\n\nexport type FindElementNextToCoords = {\n x: number\n y: number\n direction?: 'left' | 'right'\n editor: Editor\n}\n\nexport const findElementNextToCoords = (options: FindElementNextToCoords) => {\n const { x, y, direction, editor } = options\n let resultElement: HTMLElement | null = null\n let resultNode: Node | null = null\n let pos: number | null = null\n\n let currentX = x\n\n while (resultNode === null && currentX < window.innerWidth && currentX > 0) {\n const allElements = document.elementsFromPoint(currentX, y)\n const prosemirrorIndex = allElements.findIndex(element => element.classList.contains('ProseMirror'))\n const filteredElements = allElements.slice(0, prosemirrorIndex)\n\n if (filteredElements.length > 0) {\n const target = filteredElements[0]\n\n resultElement = target as HTMLElement\n pos = editor.view.posAtDOM(target, 0)\n\n if (pos >= 0) {\n resultNode = editor.state.doc.nodeAt(Math.max(pos - 1, 0))\n\n if (resultNode?.isText) {\n resultNode = editor.state.doc.nodeAt(Math.max(pos - 1, 0))\n }\n\n if (!resultNode) {\n resultNode = editor.state.doc.nodeAt(Math.max(pos, 0))\n }\n\n break\n }\n }\n\n if (direction === 'left') {\n currentX -= 1\n } else {\n currentX += 1\n }\n }\n\n return { resultElement, resultNode, pos: pos ?? null }\n}\n","export function getComputedStyle(node: Element, property: keyof CSSStyleDeclaration): any {\n const style = window.getComputedStyle(node)\n\n return style[property]\n}\n","export function minMax(value = 0, min = 0, max = 0): number {\n return Math.min(Math.max(value, min), max)\n}\n","import type { EditorView } from '@tiptap/pm/view'\n\nimport { getComputedStyle } from './getComputedStyle.js'\nimport { minMax } from './minMax.js'\n\nexport function getInnerCoords(view: EditorView, x: number, y: number): { left: number; top: number } {\n const paddingLeft = parseInt(getComputedStyle(view.dom, 'paddingLeft'), 10)\n const paddingRight = parseInt(getComputedStyle(view.dom, 'paddingRight'), 10)\n const borderLeft = parseInt(getComputedStyle(view.dom, 'borderLeftWidth'), 10)\n const borderRight = parseInt(getComputedStyle(view.dom, 'borderLeftWidth'), 10)\n const bounds = view.dom.getBoundingClientRect()\n const coords = {\n left: minMax(x, bounds.left + paddingLeft + borderLeft, bounds.right - paddingRight - borderRight),\n top: y,\n }\n\n return coords\n}\n","export function removeNode(node: HTMLElement) {\n node.parentNode?.removeChild(node)\n}\n","import type { Node } from '@tiptap/pm/model'\n\nexport const getOuterNodePos = (doc: Node, pos: number): number => {\n const resolvedPos = doc.resolve(pos)\n const { depth } = resolvedPos\n\n if (depth === 0) {\n return pos\n }\n\n const a = resolvedPos.pos - resolvedPos.parentOffset\n\n return a - 1\n}\n\nexport const getOuterNode = (doc: Node, pos: number): Node | null => {\n const node = doc.nodeAt(pos)\n const resolvedPos = doc.resolve(pos)\n\n let { depth } = resolvedPos\n let parent = node\n\n while (depth > 0) {\n const currentNode = resolvedPos.node(depth)\n\n depth -= 1\n\n if (depth === 0) {\n parent = currentNode\n }\n }\n\n return parent\n}\n","import { DragHandle } from './drag-handle.js'\n\nexport * from './drag-handle.js'\nexport * from './drag-handle-plugin.js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;AAAA,MACF,kBACE,MACA,CAAC,EAAE,OAAO,MAAM;AACd,aAAK,QAAQ,SAAS;AACtB,eAAO,OAAO,SAAS,QAAQ,kBAAkB,KAAK,QAAQ,MAAM;AAAA,MACtE;AAAA,MACF,kBACE,MACA,CAAC,EAAE,OAAO,MAAM;AACd,aAAK,QAAQ,SAAS,CAAC,KAAK,QAAQ;AACpC,eAAO,OAAO,SAAS,QAAQ,kBAAkB,KAAK,QAAQ,MAAM;AAAA,MACtE;AAAA,IACJ;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,UAAM,UAAU,KAAK,QAAQ,OAAO;AAEpC,WAAO;AAAA,MACL,iBAAiB;AAAA,QACf,uBAAuB,EAAE,GAAG,8BAA8B,GAAG,KAAK,QAAQ,sBAAsB;AAAA,QAChG;AAAA,QACA,QAAQ,KAAK;AAAA,QACb,cAAc,KAAK,QAAQ;AAAA,MAC7B,CAAC,EAAE;AAAA,IACL;AAAA,EACF;AACF,CAAC;;;AUpGD,IAAO,gBAAQ;","names":["getComputedStyle","getComputedStyle"]}
1
+ {"version":3,"sources":["../src/drag-handle.ts","../src/drag-handle-plugin.ts","../src/helpers/dragHandler.ts","../src/helpers/cloneElement.ts","../src/helpers/findNextElementFromCursor.ts","../src/helpers/getComputedStyle.ts","../src/helpers/minMax.ts","../src/helpers/getInnerCoords.ts","../src/helpers/removeNode.ts","../src/helpers/getOuterNode.ts","../src/index.ts"],"sourcesContent":["import type { ComputePositionConfig } from '@floating-ui/dom'\nimport { type Editor, Extension } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\n\nimport { DragHandlePlugin } from './drag-handle-plugin.js'\n\nexport const defaultComputePositionConfig: ComputePositionConfig = {\n placement: 'left-start',\n strategy: 'absolute',\n}\n\nexport interface DragHandleOptions {\n /**\n * Renders an element that is positioned with the floating-ui/dom package\n */\n render(): HTMLElement\n /**\n * Configuration for position computation of the drag handle\n * using the floating-ui/dom package\n */\n computePositionConfig?: ComputePositionConfig\n /**\n * Locks the draghandle in place and visibility\n */\n locked?: boolean\n /**\n * Returns a node or null when a node is hovered over\n */\n onNodeChange?: (options: { node: Node | null; editor: Editor }) => void\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n dragHandle: {\n /**\n * Locks the draghandle in place and visibility\n */\n lockDragHandle: () => ReturnType\n /**\n * Unlocks the draghandle\n */\n unlockDragHandle: () => ReturnType\n /**\n * Toggle draghandle lock state\n */\n toggleDragHandle: () => ReturnType\n }\n }\n}\n\nexport const DragHandle = Extension.create<DragHandleOptions>({\n name: 'dragHandle',\n\n addOptions() {\n return {\n render() {\n const element = document.createElement('div')\n\n element.classList.add('drag-handle')\n\n return element\n },\n computePositionConfig: {},\n locked: false,\n onNodeChange: () => {\n return null\n },\n }\n },\n\n addCommands() {\n return {\n lockDragHandle:\n () =>\n ({ editor }) => {\n this.options.locked = true\n return editor.commands.setMeta('lockDragHandle', this.options.locked)\n },\n unlockDragHandle:\n () =>\n ({ editor }) => {\n this.options.locked = false\n return editor.commands.setMeta('lockDragHandle', this.options.locked)\n },\n toggleDragHandle:\n () =>\n ({ editor }) => {\n this.options.locked = !this.options.locked\n return editor.commands.setMeta('lockDragHandle', this.options.locked)\n },\n }\n },\n\n addProseMirrorPlugins() {\n const element = this.options.render()\n\n return [\n DragHandlePlugin({\n computePositionConfig: { ...defaultComputePositionConfig, ...this.options.computePositionConfig },\n element,\n editor: this.editor,\n onNodeChange: this.options.onNodeChange,\n }).plugin,\n ]\n },\n})\n","import { type ComputePositionConfig, computePosition } from '@floating-ui/dom'\nimport type { Editor } from '@tiptap/core'\nimport { isChangeOrigin } from '@tiptap/extension-collaboration'\nimport type { Node } from '@tiptap/pm/model'\nimport { type EditorState, type Transaction, Plugin, PluginKey } from '@tiptap/pm/state'\nimport type { EditorView } from '@tiptap/pm/view'\nimport {\n absolutePositionToRelativePosition,\n relativePositionToAbsolutePosition,\n ySyncPluginKey,\n} from '@tiptap/y-tiptap'\n\nimport { dragHandler } from './helpers/dragHandler.js'\nimport { findElementNextToCoords } from './helpers/findNextElementFromCursor.js'\nimport { getOuterNode, getOuterNodePos } from './helpers/getOuterNode.js'\nimport { removeNode } from './helpers/removeNode.js'\n\ntype PluginState = {\n locked: boolean\n}\n\nconst getRelativePos = (state: EditorState, absolutePos: number) => {\n const ystate = ySyncPluginKey.getState(state)\n\n if (!ystate) {\n return null\n }\n\n return absolutePositionToRelativePosition(absolutePos, ystate.type, ystate.binding.mapping)\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: y-prosemirror (and y-tiptap by extension) does not have types for relative positions\nconst getAbsolutePos = (state: EditorState, relativePos: any) => {\n const ystate = ySyncPluginKey.getState(state)\n\n if (!ystate) {\n return -1\n }\n\n return relativePositionToAbsolutePosition(ystate.doc, ystate.type, relativePos, ystate.binding.mapping) || 0\n}\n\nconst getOuterDomNode = (view: EditorView, domNode: HTMLElement) => {\n let tmpDomNode = domNode\n\n // Traverse to top level node.\n while (tmpDomNode?.parentNode) {\n if (tmpDomNode.parentNode === view.dom) {\n break\n }\n\n tmpDomNode = tmpDomNode.parentNode as HTMLElement\n }\n\n return tmpDomNode\n}\n\nexport interface DragHandlePluginProps {\n pluginKey?: PluginKey | string\n editor: Editor\n element: HTMLElement\n onNodeChange?: (data: { editor: Editor; node: Node | null; pos: number }) => void\n onElementDragStart?: (e: DragEvent) => void\n onElementDragEnd?: (e: DragEvent) => void\n computePositionConfig?: ComputePositionConfig\n}\n\nexport const dragHandlePluginDefaultKey = new PluginKey('dragHandle')\n\nexport const DragHandlePlugin = ({\n pluginKey = dragHandlePluginDefaultKey,\n element,\n editor,\n computePositionConfig,\n onNodeChange,\n onElementDragStart,\n onElementDragEnd,\n}: DragHandlePluginProps) => {\n const wrapper = document.createElement('div')\n let locked = false\n let currentNode: Node | null = null\n let currentNodePos = -1\n // biome-ignore lint/suspicious/noExplicitAny: See above - relative positions in y-prosemirror are not typed\n let currentNodeRelPos: any\n let rafId: number | null = null\n let pendingMouseCoords: { x: number; y: number } | null = null\n\n function hideHandle() {\n if (!element) {\n return\n }\n\n element.style.visibility = 'hidden'\n element.style.pointerEvents = 'none'\n }\n\n function showHandle() {\n if (!element) {\n return\n }\n\n if (!editor.isEditable) {\n hideHandle()\n return\n }\n\n element.style.visibility = ''\n element.style.pointerEvents = 'auto'\n }\n\n function repositionDragHandle(dom: Element) {\n const virtualElement = {\n getBoundingClientRect: () => dom.getBoundingClientRect(),\n }\n\n computePosition(virtualElement, element, computePositionConfig).then(val => {\n Object.assign(element.style, {\n position: val.strategy,\n left: `${val.x}px`,\n top: `${val.y}px`,\n })\n })\n }\n\n function onDragStart(e: DragEvent) {\n onElementDragStart?.(e)\n // Push this to the end of the event cue\n // Fixes bug where incorrect drag pos is returned if drag handle has position: absolute\n // @ts-ignore\n dragHandler(e, editor)\n\n setTimeout(() => {\n if (element) {\n element.style.pointerEvents = 'none'\n }\n }, 0)\n }\n\n function onDragEnd(e: DragEvent) {\n onElementDragEnd?.(e)\n hideHandle()\n if (element) {\n element.style.pointerEvents = 'auto'\n }\n }\n\n element.addEventListener('dragstart', onDragStart)\n element.addEventListener('dragend', onDragEnd)\n\n wrapper.appendChild(element)\n\n return {\n unbind() {\n element.removeEventListener('dragstart', onDragStart)\n element.removeEventListener('dragend', onDragEnd)\n if (rafId) {\n cancelAnimationFrame(rafId)\n rafId = null\n pendingMouseCoords = null\n }\n },\n plugin: new Plugin({\n key: typeof pluginKey === 'string' ? new PluginKey(pluginKey) : pluginKey,\n\n state: {\n init() {\n return { locked: false }\n },\n apply(tr: Transaction, value: PluginState, _oldState: EditorState, state: EditorState) {\n const isLocked = tr.getMeta('lockDragHandle')\n const hideDragHandle = tr.getMeta('hideDragHandle')\n\n if (isLocked !== undefined) {\n locked = isLocked\n }\n\n if (hideDragHandle) {\n hideHandle()\n\n locked = false\n currentNode = null\n currentNodePos = -1\n\n onNodeChange?.({ editor, node: null, pos: -1 })\n\n return value\n }\n\n // Something has changed and drag handler is visible…\n if (tr.docChanged && currentNodePos !== -1 && element) {\n // Yjs replaces the entire document on every incoming change and needs a special handling.\n // If change comes from another user …\n if (isChangeOrigin(tr)) {\n // https://discuss.yjs.dev/t/y-prosemirror-mapping-a-single-relative-position-when-doc-changes/851/3\n const newPos = getAbsolutePos(state, currentNodeRelPos)\n\n if (newPos !== currentNodePos) {\n // Set the new position for our current node.\n currentNodePos = newPos\n\n // We will get the outer node with data and position in views update method.\n }\n } else {\n // … otherwise use ProseMirror mapping to update the position.\n const newPos = tr.mapping.map(currentNodePos)\n\n if (newPos !== currentNodePos) {\n // TODO: Remove\n // console.log('Position has changed …', { old: currentNodePos, new: newPos }, tr);\n\n // Set the new position for our current node.\n currentNodePos = newPos\n\n // Memorize relative position to retrieve absolute position in case of collaboration\n currentNodeRelPos = getRelativePos(state, currentNodePos)\n\n // We will get the outer node with data and position in views update method.\n }\n }\n }\n\n return value\n },\n },\n\n view: view => {\n element.draggable = true\n element.style.pointerEvents = 'auto'\n\n editor.view.dom.parentElement?.appendChild(wrapper)\n\n wrapper.style.pointerEvents = 'none'\n wrapper.style.position = 'absolute'\n wrapper.style.top = '0'\n wrapper.style.left = '0'\n\n return {\n update(_, oldState) {\n if (!element) {\n return\n }\n\n if (!editor.isEditable) {\n hideHandle()\n return\n }\n\n // Prevent element being draggend while being open.\n if (locked) {\n element.draggable = false\n } else {\n element.draggable = true\n }\n\n // Recalculate popup position if doc has changend and drag handler is visible.\n if (view.state.doc.eq(oldState.doc) || currentNodePos === -1) {\n return\n }\n\n // Get domNode from (new) position.\n let domNode = view.nodeDOM(currentNodePos) as HTMLElement\n\n // Since old element could have been wrapped, we need to find\n // the outer node and take its position and node data.\n domNode = getOuterDomNode(view, domNode)\n\n // Skip if domNode is editor dom.\n if (domNode === view.dom) {\n return\n }\n\n // We only want `Element`.\n if (domNode?.nodeType !== 1) {\n return\n }\n\n const domNodePos = view.posAtDOM(domNode, 0)\n const outerNode = getOuterNode(editor.state.doc, domNodePos)\n const outerNodePos = getOuterNodePos(editor.state.doc, domNodePos) // TODO: needed?\n\n currentNode = outerNode\n currentNodePos = outerNodePos\n\n // Memorize relative position to retrieve absolute position in case of collaboration\n currentNodeRelPos = getRelativePos(view.state, currentNodePos)\n\n onNodeChange?.({ editor, node: currentNode, pos: currentNodePos })\n\n repositionDragHandle(domNode as Element)\n },\n\n // TODO: Kills even on hot reload\n destroy() {\n if (rafId) {\n cancelAnimationFrame(rafId)\n rafId = null\n pendingMouseCoords = null\n }\n\n if (element) {\n removeNode(wrapper)\n }\n },\n }\n },\n\n props: {\n handleDOMEvents: {\n keydown(view) {\n if (!element || locked) {\n return false\n }\n\n if (view.hasFocus()) {\n hideHandle()\n currentNode = null\n currentNodePos = -1\n onNodeChange?.({ editor, node: null, pos: -1 })\n\n // We want to still continue with other keydown events.\n return false\n }\n\n return false\n },\n mouseleave(_view, e) {\n // Do not hide open popup on mouseleave.\n if (locked) {\n return false\n }\n\n // If e.target is not inside the wrapper, hide.\n if (e.target && !wrapper.contains(e.relatedTarget as HTMLElement)) {\n hideHandle()\n\n currentNode = null\n currentNodePos = -1\n\n onNodeChange?.({ editor, node: null, pos: -1 })\n }\n\n return false\n },\n\n mousemove(view, e) {\n // Do not continue if popup is not initialized or open.\n if (!element || locked) {\n return false\n }\n\n // Store latest mouse coords and schedule a single RAF per frame\n pendingMouseCoords = { x: e.clientX, y: e.clientY }\n\n if (rafId) {\n return false\n }\n\n rafId = requestAnimationFrame(() => {\n rafId = null\n\n if (!pendingMouseCoords) {\n return\n }\n\n const { x, y } = pendingMouseCoords\n pendingMouseCoords = null\n\n const nodeData = findElementNextToCoords({\n x,\n y,\n direction: 'right',\n editor,\n })\n\n // Skip if there is no node next to coords\n if (!nodeData.resultElement) {\n return\n }\n\n let domNode = nodeData.resultElement as HTMLElement\n\n domNode = getOuterDomNode(view, domNode)\n\n // Skip if domNode is editor dom.\n if (domNode === view.dom) {\n return\n }\n\n // We only want `Element`.\n if (domNode?.nodeType !== 1) {\n return\n }\n\n const domNodePos = view.posAtDOM(domNode, 0)\n const outerNode = getOuterNode(editor.state.doc, domNodePos)\n\n if (outerNode !== currentNode) {\n const outerNodePos = getOuterNodePos(editor.state.doc, domNodePos)\n\n currentNode = outerNode\n currentNodePos = outerNodePos\n\n // Memorize relative position to retrieve absolute position in case of collaboration\n currentNodeRelPos = getRelativePos(view.state, currentNodePos)\n\n onNodeChange?.({ editor, node: currentNode, pos: currentNodePos })\n\n // Set nodes clientRect.\n repositionDragHandle(domNode as Element)\n\n showHandle()\n }\n })\n\n return false\n },\n },\n },\n }),\n }\n}\n","import type { Editor } from '@tiptap/core'\nimport { getSelectionRanges, NodeRangeSelection } from '@tiptap/extension-node-range'\nimport type { SelectionRange } from '@tiptap/pm/state'\n\nimport { cloneElement } from './cloneElement.js'\nimport { findElementNextToCoords } from './findNextElementFromCursor.js'\nimport { getInnerCoords } from './getInnerCoords.js'\nimport { removeNode } from './removeNode.js'\n\nfunction getDragHandleRanges(event: DragEvent, editor: Editor): SelectionRange[] {\n const { doc } = editor.view.state\n\n const result = findElementNextToCoords({\n editor,\n x: event.clientX,\n y: event.clientY,\n direction: 'right',\n })\n\n if (!result.resultNode || result.pos === null) {\n return []\n }\n\n const x = event.clientX\n\n // @ts-ignore\n const coords = getInnerCoords(editor.view, x, event.clientY)\n const posAtCoords = editor.view.posAtCoords(coords)\n\n if (!posAtCoords) {\n return []\n }\n\n const { pos } = posAtCoords\n const nodeAt = doc.resolve(pos).parent\n\n if (!nodeAt) {\n return []\n }\n\n const $from = doc.resolve(result.pos)\n const $to = doc.resolve(result.pos + 1)\n\n return getSelectionRanges($from, $to, 0)\n}\n\nexport function dragHandler(event: DragEvent, editor: Editor) {\n const { view } = editor\n\n if (!event.dataTransfer) {\n return\n }\n\n const { empty, $from, $to } = view.state.selection\n\n const dragHandleRanges = getDragHandleRanges(event, editor)\n\n const selectionRanges = getSelectionRanges($from, $to, 0)\n const isDragHandleWithinSelection = selectionRanges.some(range => {\n return dragHandleRanges.find(dragHandleRange => {\n return dragHandleRange.$from === range.$from && dragHandleRange.$to === range.$to\n })\n })\n\n const ranges = empty || !isDragHandleWithinSelection ? dragHandleRanges : selectionRanges\n\n if (!ranges.length) {\n return\n }\n\n const { tr } = view.state\n const wrapper = document.createElement('div')\n const from = ranges[0].$from.pos\n const to = ranges[ranges.length - 1].$to.pos\n\n const selection = NodeRangeSelection.create(view.state.doc, from, to)\n const slice = selection.content()\n\n ranges.forEach(range => {\n const element = view.nodeDOM(range.$from.pos) as HTMLElement\n const clonedElement = cloneElement(element)\n\n wrapper.append(clonedElement)\n })\n\n wrapper.style.position = 'absolute'\n wrapper.style.top = '-10000px'\n document.body.append(wrapper)\n\n event.dataTransfer.clearData()\n event.dataTransfer.setDragImage(wrapper, 0, 0)\n\n // tell ProseMirror the dragged content\n view.dragging = { slice, move: true }\n\n tr.setSelection(selection)\n\n view.dispatch(tr)\n\n // clean up\n document.addEventListener('drop', () => removeNode(wrapper), { once: true })\n}\n","function getCSSText(element: Element) {\n let value = ''\n const style = getComputedStyle(element)\n\n for (let i = 0; i < style.length; i += 1) {\n value += `${style[i]}:${style.getPropertyValue(style[i])};`\n }\n\n return value\n}\n\nexport function cloneElement(node: HTMLElement) {\n const clonedNode = node.cloneNode(true) as HTMLElement\n const sourceElements = [node, ...Array.from(node.getElementsByTagName('*'))] as HTMLElement[]\n const targetElements = [clonedNode, ...Array.from(clonedNode.getElementsByTagName('*'))] as HTMLElement[]\n\n sourceElements.forEach((sourceElement, index) => {\n targetElements[index].style.cssText = getCSSText(sourceElement)\n })\n\n return clonedNode\n}\n","import type { Editor } from '@tiptap/core'\n\nexport type FindElementNextToCoords = {\n x: number\n y: number\n direction?: 'left' | 'right'\n editor: Editor\n bandHeight?: number\n}\n\nexport const findElementNextToCoords = (options: FindElementNextToCoords) => {\n const { x, y, direction = 'right', editor, bandHeight = 5 } = options\n\n const rect = {\n top: y - bandHeight,\n bottom: y + bandHeight,\n left: direction === 'right' ? x : 0,\n right: direction === 'right' ? window.innerWidth - x : x,\n }\n\n const root = editor.view.dom as HTMLElement\n\n // Get potential candidates from prosemirror child elements and filter\n // by removing decorations and non prosemirror-elements\n const candidates = [...root.querySelectorAll<HTMLElement>('*')]\n .filter(candidate => {\n return editor.view.posAtDOM(candidate, 0) >= 0\n })\n .filter(candidate => {\n const candidateRect = candidate.getBoundingClientRect()\n return !(\n candidateRect.bottom < rect.top ||\n candidateRect.top > rect.bottom ||\n candidateRect.right < rect.left ||\n candidateRect.left > rect.right\n )\n })\n\n if (!candidates || candidates.length === 0) {\n return { resultElement: null, resultNode: null, pos: null }\n }\n\n const finalCandidate = candidates[0]\n const candidatePos = editor.view.posAtDOM(finalCandidate, 0)\n if (candidatePos === -1) {\n return { resultElement: finalCandidate, resultNode: null, pos: null }\n }\n\n const candidateNode = editor.state.doc.nodeAt(candidatePos - 1)\n\n return { resultElement: finalCandidate, resultNode: candidateNode, pos: candidatePos }\n}\n","export function getComputedStyle(node: Element, property: keyof CSSStyleDeclaration): any {\n const style = window.getComputedStyle(node)\n\n return style[property]\n}\n","export function minMax(value = 0, min = 0, max = 0): number {\n return Math.min(Math.max(value, min), max)\n}\n","import type { EditorView } from '@tiptap/pm/view'\n\nimport { getComputedStyle } from './getComputedStyle.js'\nimport { minMax } from './minMax.js'\n\nexport function getInnerCoords(view: EditorView, x: number, y: number): { left: number; top: number } {\n const paddingLeft = parseInt(getComputedStyle(view.dom, 'paddingLeft'), 10)\n const paddingRight = parseInt(getComputedStyle(view.dom, 'paddingRight'), 10)\n const borderLeft = parseInt(getComputedStyle(view.dom, 'borderLeftWidth'), 10)\n const borderRight = parseInt(getComputedStyle(view.dom, 'borderLeftWidth'), 10)\n const bounds = view.dom.getBoundingClientRect()\n const coords = {\n left: minMax(x, bounds.left + paddingLeft + borderLeft, bounds.right - paddingRight - borderRight),\n top: y,\n }\n\n return coords\n}\n","export function removeNode(node: HTMLElement) {\n node.parentNode?.removeChild(node)\n}\n","import type { Node } from '@tiptap/pm/model'\n\nexport const getOuterNodePos = (doc: Node, pos: number): number => {\n const resolvedPos = doc.resolve(pos)\n const { depth } = resolvedPos\n\n if (depth === 0) {\n return pos\n }\n\n const a = resolvedPos.pos - resolvedPos.parentOffset\n\n return a - 1\n}\n\nexport const getOuterNode = (doc: Node, pos: number): Node | null => {\n const node = doc.nodeAt(pos)\n const resolvedPos = doc.resolve(pos)\n\n let { depth } = resolvedPos\n let parent = node\n\n while (depth > 0) {\n const currentNode = resolvedPos.node(depth)\n\n depth -= 1\n\n if (depth === 0) {\n parent = currentNode\n }\n }\n\n return parent\n}\n","import { DragHandle } from './drag-handle.js'\n\nexport * from './drag-handle.js'\nexport * from './drag-handle-plugin.js'\n\nexport default DragHandle\n"],"mappings":";AACA,SAAsB,iBAAiB;;;ACDvC,SAAqC,uBAAuB;AAE5D,SAAS,sBAAsB;AAE/B,SAA6C,QAAQ,iBAAiB;AAEtE;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACTP,SAAS,oBAAoB,0BAA0B;;;ACDvD,SAAS,WAAW,SAAkB;AACpC,MAAI,QAAQ;AACZ,QAAM,QAAQ,iBAAiB,OAAO;AAEtC,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,GAAG;AACxC,aAAS,GAAG,MAAM,CAAC,CAAC,IAAI,MAAM,iBAAiB,MAAM,CAAC,CAAC,CAAC;AAAA,EAC1D;AAEA,SAAO;AACT;AAEO,SAAS,aAAa,MAAmB;AAC9C,QAAM,aAAa,KAAK,UAAU,IAAI;AACtC,QAAM,iBAAiB,CAAC,MAAM,GAAG,MAAM,KAAK,KAAK,qBAAqB,GAAG,CAAC,CAAC;AAC3E,QAAM,iBAAiB,CAAC,YAAY,GAAG,MAAM,KAAK,WAAW,qBAAqB,GAAG,CAAC,CAAC;AAEvF,iBAAe,QAAQ,CAAC,eAAe,UAAU;AAC/C,mBAAe,KAAK,EAAE,MAAM,UAAU,WAAW,aAAa;AAAA,EAChE,CAAC;AAED,SAAO;AACT;;;ACXO,IAAM,0BAA0B,C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pC,WAAO;AAAA,MACL,iBAAiB;AAAA,QACf,uBAAuB,EAAE,GAAG,8BAA8B,GAAG,KAAK,QAAQ,sBAAsB;AAAA,QAChG;AAAA,QACA,QAAQ,KAAK;AAAA,QACb,cAAc,KAAK,QAAQ;AAAA,MAC7B,CAAC,EAAE;AAAA,IACL;AAAA,EACF;AACF,CAAC;;;AUpGD,IAAO,gBAAQ;","names":["getComputedStyle","getComputedStyle"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/extension-drag-handle",
3
3
  "description": "drag handle extension for tiptap",
4
- "version": "3.3.0",
4
+ "version": "3.3.1",
5
5
  "homepage": "https://tiptap.dev/docs/editor/extensions/functionality/drag-handle",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -37,10 +37,10 @@
37
37
  ],
38
38
  "peerDependencies": {
39
39
  "@tiptap/y-tiptap": "^3.0.0-beta.3",
40
- "@tiptap/extension-node-range": "^3.3.0",
41
- "@tiptap/core": "^3.3.0",
42
- "@tiptap/extension-collaboration": "^3.3.0",
43
- "@tiptap/pm": "^3.3.0"
40
+ "@tiptap/extension-node-range": "^3.3.1",
41
+ "@tiptap/core": "^3.3.1",
42
+ "@tiptap/extension-collaboration": "^3.3.1",
43
+ "@tiptap/pm": "^3.3.1"
44
44
  },
45
45
  "dependencies": {
46
46
  "@floating-ui/dom": "^1.6.13"
@@ -48,10 +48,10 @@
48
48
  "devDependencies": {
49
49
  "@floating-ui/dom": "^1.6.13",
50
50
  "@tiptap/y-tiptap": "^3.0.0-beta.3",
51
- "@tiptap/extension-node-range": "^3.3.0",
52
- "@tiptap/core": "^3.3.0",
53
- "@tiptap/extension-collaboration": "^3.3.0",
54
- "@tiptap/pm": "^3.3.0"
51
+ "@tiptap/extension-node-range": "^3.3.1",
52
+ "@tiptap/core": "^3.3.1",
53
+ "@tiptap/extension-collaboration": "^3.3.1",
54
+ "@tiptap/pm": "^3.3.1"
55
55
  },
56
56
  "scripts": {
57
57
  "build": "tsup",
@@ -82,6 +82,8 @@ export const DragHandlePlugin = ({
82
82
  let currentNodePos = -1
83
83
  // biome-ignore lint/suspicious/noExplicitAny: See above - relative positions in y-prosemirror are not typed
84
84
  let currentNodeRelPos: any
85
+ let rafId: number | null = null
86
+ let pendingMouseCoords: { x: number; y: number } | null = null
85
87
 
86
88
  function hideHandle() {
87
89
  if (!element) {
@@ -151,6 +153,11 @@ export const DragHandlePlugin = ({
151
153
  unbind() {
152
154
  element.removeEventListener('dragstart', onDragStart)
153
155
  element.removeEventListener('dragend', onDragEnd)
156
+ if (rafId) {
157
+ cancelAnimationFrame(rafId)
158
+ rafId = null
159
+ pendingMouseCoords = null
160
+ }
154
161
  },
155
162
  plugin: new Plugin({
156
163
  key: typeof pluginKey === 'string' ? new PluginKey(pluginKey) : pluginKey,
@@ -284,6 +291,12 @@ export const DragHandlePlugin = ({
284
291
 
285
292
  // TODO: Kills even on hot reload
286
293
  destroy() {
294
+ if (rafId) {
295
+ cancelAnimationFrame(rafId)
296
+ rafId = null
297
+ pendingMouseCoords = null
298
+ }
299
+
287
300
  if (element) {
288
301
  removeNode(wrapper)
289
302
  }
@@ -335,51 +348,69 @@ export const DragHandlePlugin = ({
335
348
  return false
336
349
  }
337
350
 
338
- const nodeData = findElementNextToCoords({
339
- x: e.clientX,
340
- y: e.clientY,
341
- direction: 'right',
342
- editor,
343
- })
351
+ // Store latest mouse coords and schedule a single RAF per frame
352
+ pendingMouseCoords = { x: e.clientX, y: e.clientY }
344
353
 
345
- // Skip if there is no node next to coords
346
- if (!nodeData.resultElement) {
354
+ if (rafId) {
347
355
  return false
348
356
  }
349
357
 
350
- let domNode = nodeData.resultElement as HTMLElement
358
+ rafId = requestAnimationFrame(() => {
359
+ rafId = null
351
360
 
352
- domNode = getOuterDomNode(view, domNode)
361
+ if (!pendingMouseCoords) {
362
+ return
363
+ }
353
364
 
354
- // Skip if domNode is editor dom.
355
- if (domNode === view.dom) {
356
- return false
357
- }
365
+ const { x, y } = pendingMouseCoords
366
+ pendingMouseCoords = null
358
367
 
359
- // We only want `Element`.
360
- if (domNode?.nodeType !== 1) {
361
- return false
362
- }
368
+ const nodeData = findElementNextToCoords({
369
+ x,
370
+ y,
371
+ direction: 'right',
372
+ editor,
373
+ })
363
374
 
364
- const domNodePos = view.posAtDOM(domNode, 0)
365
- const outerNode = getOuterNode(editor.state.doc, domNodePos)
375
+ // Skip if there is no node next to coords
376
+ if (!nodeData.resultElement) {
377
+ return
378
+ }
366
379
 
367
- if (outerNode !== currentNode) {
368
- const outerNodePos = getOuterNodePos(editor.state.doc, domNodePos)
380
+ let domNode = nodeData.resultElement as HTMLElement
369
381
 
370
- currentNode = outerNode
371
- currentNodePos = outerNodePos
382
+ domNode = getOuterDomNode(view, domNode)
372
383
 
373
- // Memorize relative position to retrieve absolute position in case of collaboration
374
- currentNodeRelPos = getRelativePos(view.state, currentNodePos)
384
+ // Skip if domNode is editor dom.
385
+ if (domNode === view.dom) {
386
+ return
387
+ }
375
388
 
376
- onNodeChange?.({ editor, node: currentNode, pos: currentNodePos })
389
+ // We only want `Element`.
390
+ if (domNode?.nodeType !== 1) {
391
+ return
392
+ }
377
393
 
378
- // Set nodes clientRect.
379
- repositionDragHandle(domNode as Element)
394
+ const domNodePos = view.posAtDOM(domNode, 0)
395
+ const outerNode = getOuterNode(editor.state.doc, domNodePos)
380
396
 
381
- showHandle()
382
- }
397
+ if (outerNode !== currentNode) {
398
+ const outerNodePos = getOuterNodePos(editor.state.doc, domNodePos)
399
+
400
+ currentNode = outerNode
401
+ currentNodePos = outerNodePos
402
+
403
+ // Memorize relative position to retrieve absolute position in case of collaboration
404
+ currentNodeRelPos = getRelativePos(view.state, currentNodePos)
405
+
406
+ onNodeChange?.({ editor, node: currentNode, pos: currentNodePos })
407
+
408
+ // Set nodes clientRect.
409
+ repositionDragHandle(domNode as Element)
410
+
411
+ showHandle()
412
+ }
413
+ })
383
414
 
384
415
  return false
385
416
  },
@@ -1,53 +1,52 @@
1
1
  import type { Editor } from '@tiptap/core'
2
- import type { Node } from '@tiptap/pm/model'
3
2
 
4
3
  export type FindElementNextToCoords = {
5
4
  x: number
6
5
  y: number
7
6
  direction?: 'left' | 'right'
8
7
  editor: Editor
8
+ bandHeight?: number
9
9
  }
10
10
 
11
11
  export const findElementNextToCoords = (options: FindElementNextToCoords) => {
12
- const { x, y, direction, editor } = options
13
- let resultElement: HTMLElement | null = null
14
- let resultNode: Node | null = null
15
- let pos: number | null = null
12
+ const { x, y, direction = 'right', editor, bandHeight = 5 } = options
16
13
 
17
- let currentX = x
18
-
19
- while (resultNode === null && currentX < window.innerWidth && currentX > 0) {
20
- const allElements = document.elementsFromPoint(currentX, y)
21
- const prosemirrorIndex = allElements.findIndex(element => element.classList.contains('ProseMirror'))
22
- const filteredElements = allElements.slice(0, prosemirrorIndex)
23
-
24
- if (filteredElements.length > 0) {
25
- const target = filteredElements[0]
26
-
27
- resultElement = target as HTMLElement
28
- pos = editor.view.posAtDOM(target, 0)
29
-
30
- if (pos >= 0) {
31
- resultNode = editor.state.doc.nodeAt(Math.max(pos - 1, 0))
32
-
33
- if (resultNode?.isText) {
34
- resultNode = editor.state.doc.nodeAt(Math.max(pos - 1, 0))
35
- }
36
-
37
- if (!resultNode) {
38
- resultNode = editor.state.doc.nodeAt(Math.max(pos, 0))
39
- }
14
+ const rect = {
15
+ top: y - bandHeight,
16
+ bottom: y + bandHeight,
17
+ left: direction === 'right' ? x : 0,
18
+ right: direction === 'right' ? window.innerWidth - x : x,
19
+ }
40
20
 
41
- break
42
- }
43
- }
21
+ const root = editor.view.dom as HTMLElement
22
+
23
+ // Get potential candidates from prosemirror child elements and filter
24
+ // by removing decorations and non prosemirror-elements
25
+ const candidates = [...root.querySelectorAll<HTMLElement>('*')]
26
+ .filter(candidate => {
27
+ return editor.view.posAtDOM(candidate, 0) >= 0
28
+ })
29
+ .filter(candidate => {
30
+ const candidateRect = candidate.getBoundingClientRect()
31
+ return !(
32
+ candidateRect.bottom < rect.top ||
33
+ candidateRect.top > rect.bottom ||
34
+ candidateRect.right < rect.left ||
35
+ candidateRect.left > rect.right
36
+ )
37
+ })
38
+
39
+ if (!candidates || candidates.length === 0) {
40
+ return { resultElement: null, resultNode: null, pos: null }
41
+ }
44
42
 
45
- if (direction === 'left') {
46
- currentX -= 1
47
- } else {
48
- currentX += 1
49
- }
43
+ const finalCandidate = candidates[0]
44
+ const candidatePos = editor.view.posAtDOM(finalCandidate, 0)
45
+ if (candidatePos === -1) {
46
+ return { resultElement: finalCandidate, resultNode: null, pos: null }
50
47
  }
51
48
 
52
- return { resultElement, resultNode, pos: pos ?? null }
49
+ const candidateNode = editor.state.doc.nodeAt(candidatePos - 1)
50
+
51
+ return { resultElement: finalCandidate, resultNode: candidateNode, pos: candidatePos }
53
52
  }