@tiptap/extension-drag-handle-react 3.16.0 → 3.17.0
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 +15 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +44 -2
- package/dist/index.d.ts +44 -2
- package/dist/index.js +18 -5
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/DragHandle.tsx +62 -3
package/dist/index.cjs
CHANGED
|
@@ -38,10 +38,12 @@ var DragHandle = (props) => {
|
|
|
38
38
|
onNodeChange,
|
|
39
39
|
onElementDragStart,
|
|
40
40
|
onElementDragEnd,
|
|
41
|
-
computePositionConfig = import_extension_drag_handle.defaultComputePositionConfig
|
|
41
|
+
computePositionConfig = import_extension_drag_handle.defaultComputePositionConfig,
|
|
42
|
+
nested = false
|
|
42
43
|
} = props;
|
|
43
44
|
const [element, setElement] = (0, import_react.useState)(null);
|
|
44
45
|
const plugin = (0, import_react.useRef)(null);
|
|
46
|
+
const nestedOptions = (0, import_react.useMemo)(() => (0, import_extension_drag_handle.normalizeNestedOptions)(nested), [JSON.stringify(nested)]);
|
|
45
47
|
(0, import_react.useEffect)(() => {
|
|
46
48
|
let initPlugin = null;
|
|
47
49
|
if (!element) {
|
|
@@ -65,7 +67,8 @@ var DragHandle = (props) => {
|
|
|
65
67
|
},
|
|
66
68
|
onElementDragStart,
|
|
67
69
|
onElementDragEnd,
|
|
68
|
-
onNodeChange
|
|
70
|
+
onNodeChange,
|
|
71
|
+
nestedOptions
|
|
69
72
|
});
|
|
70
73
|
plugin.current = initPlugin.plugin;
|
|
71
74
|
editor.registerPlugin(plugin.current);
|
|
@@ -78,7 +81,16 @@ var DragHandle = (props) => {
|
|
|
78
81
|
initPlugin = null;
|
|
79
82
|
}
|
|
80
83
|
};
|
|
81
|
-
}, [
|
|
84
|
+
}, [
|
|
85
|
+
element,
|
|
86
|
+
editor,
|
|
87
|
+
onNodeChange,
|
|
88
|
+
pluginKey,
|
|
89
|
+
computePositionConfig,
|
|
90
|
+
onElementDragStart,
|
|
91
|
+
onElementDragEnd,
|
|
92
|
+
nestedOptions
|
|
93
|
+
]);
|
|
82
94
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
83
95
|
"div",
|
|
84
96
|
{
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/DragHandle.tsx"],"sourcesContent":["import { DragHandle } from './DragHandle.js'\n\nexport * from './DragHandle.js'\n\nexport default DragHandle\n","import {\n type DragHandlePluginProps,\n defaultComputePositionConfig,\n DragHandlePlugin,\n dragHandlePluginDefaultKey,\n} from '@tiptap/extension-drag-handle'\nimport type { Node } from '@tiptap/pm/model'\nimport type { Plugin } from '@tiptap/pm/state'\nimport type { Editor } from '@tiptap/react'\nimport { type ReactNode, useEffect, useRef, useState } from 'react'\n\ntype Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>\n\nexport type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element'> & {\n className?: string\n onNodeChange?: (data: { node: Node | null; editor: Editor; pos: number }) => void\n children: ReactNode\n}\n\nexport const DragHandle = (props: DragHandleProps) => {\n const {\n className = 'drag-handle',\n children,\n editor,\n pluginKey = dragHandlePluginDefaultKey,\n onNodeChange,\n onElementDragStart,\n onElementDragEnd,\n computePositionConfig = defaultComputePositionConfig,\n } = props\n const [element, setElement] = useState<HTMLDivElement | null>(null)\n const plugin = useRef<Plugin | null>(null)\n\n useEffect(() => {\n let initPlugin: {\n plugin: Plugin\n unbind: () => void\n } | null = null\n\n if (!element) {\n return () => {\n plugin.current = null\n }\n }\n\n if (editor.isDestroyed) {\n return () => {\n plugin.current = null\n }\n }\n\n if (!plugin.current) {\n initPlugin = DragHandlePlugin({\n editor,\n element,\n pluginKey,\n computePositionConfig: {\n ...defaultComputePositionConfig,\n ...computePositionConfig,\n },\n onElementDragStart,\n onElementDragEnd,\n onNodeChange,\n })\n plugin.current = initPlugin.plugin\n\n editor.registerPlugin(plugin.current)\n }\n\n return () => {\n editor.unregisterPlugin(pluginKey)\n plugin.current = null\n if (initPlugin) {\n initPlugin.unbind()\n initPlugin = null\n }\n }\n }, [element
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/DragHandle.tsx"],"sourcesContent":["import { DragHandle } from './DragHandle.js'\n\nexport * from './DragHandle.js'\n\nexport default DragHandle\n","import {\n type DragHandlePluginProps,\n type NestedOptions,\n defaultComputePositionConfig,\n DragHandlePlugin,\n dragHandlePluginDefaultKey,\n normalizeNestedOptions,\n} from '@tiptap/extension-drag-handle'\nimport type { Node } from '@tiptap/pm/model'\nimport type { Plugin } from '@tiptap/pm/state'\nimport type { Editor } from '@tiptap/react'\nimport { type ReactNode, useEffect, useMemo, useRef, useState } from 'react'\n\ntype Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>\n\nexport type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element' | 'nestedOptions'> & {\n className?: string\n onNodeChange?: (data: { node: Node | null; editor: Editor; pos: number }) => void\n children: ReactNode\n\n /**\n * Enable drag handles for nested content (list items, blockquotes, etc.).\n *\n * When enabled, the drag handle will appear for nested blocks, not just\n * top-level blocks. A rule-based scoring system determines which node\n * to target based on cursor position and configured rules.\n *\n * @default false\n *\n * @example\n * // Simple enable with sensible defaults\n * <DragHandle editor={editor} nested>\n * <GripIcon />\n * </DragHandle>\n *\n * @example\n * // With custom configuration\n * <DragHandle\n * editor={editor}\n * nested={{\n * edgeDetection: 'left',\n * allowedContainers: ['bulletList', 'orderedList'],\n * }}\n * >\n * <GripIcon />\n * </DragHandle>\n *\n * @example\n * // With custom rules\n * <DragHandle\n * editor={editor}\n * nested={{\n * rules: [{\n * id: 'excludeCodeBlocks',\n * evaluate: ({ node }) => node.type.name === 'codeBlock' ? 1000 : 0,\n * }],\n * }}\n * >\n * <GripIcon />\n * </DragHandle>\n */\n nested?: boolean | NestedOptions\n}\n\nexport const DragHandle = (props: DragHandleProps) => {\n const {\n className = 'drag-handle',\n children,\n editor,\n pluginKey = dragHandlePluginDefaultKey,\n onNodeChange,\n onElementDragStart,\n onElementDragEnd,\n computePositionConfig = defaultComputePositionConfig,\n nested = false,\n } = props\n const [element, setElement] = useState<HTMLDivElement | null>(null)\n const plugin = useRef<Plugin | null>(null)\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const nestedOptions = useMemo(() => normalizeNestedOptions(nested), [JSON.stringify(nested)])\n\n useEffect(() => {\n let initPlugin: {\n plugin: Plugin\n unbind: () => void\n } | null = null\n\n if (!element) {\n return () => {\n plugin.current = null\n }\n }\n\n if (editor.isDestroyed) {\n return () => {\n plugin.current = null\n }\n }\n\n if (!plugin.current) {\n initPlugin = DragHandlePlugin({\n editor,\n element,\n pluginKey,\n computePositionConfig: {\n ...defaultComputePositionConfig,\n ...computePositionConfig,\n },\n onElementDragStart,\n onElementDragEnd,\n onNodeChange,\n nestedOptions,\n })\n plugin.current = initPlugin.plugin\n\n editor.registerPlugin(plugin.current)\n }\n\n return () => {\n editor.unregisterPlugin(pluginKey)\n plugin.current = null\n if (initPlugin) {\n initPlugin.unbind()\n initPlugin = null\n }\n }\n }, [\n element,\n editor,\n onNodeChange,\n pluginKey,\n computePositionConfig,\n onElementDragStart,\n onElementDragEnd,\n nestedOptions,\n ])\n\n return (\n <div\n className={className}\n style={{ visibility: 'hidden', position: 'absolute' }}\n data-dragging=\"false\"\n ref={setElement}\n >\n {children}\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mCAOO;AAIP,mBAAqE;AAgIjE;AA3EG,IAAM,aAAa,CAAC,UAA2B;AACpD,QAAM;AAAA,IACJ,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA,wBAAwB;AAAA,IACxB,SAAS;AAAA,EACX,IAAI;AACJ,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAgC,IAAI;AAClE,QAAM,aAAS,qBAAsB,IAAI;AAGzC,QAAM,oBAAgB,sBAAQ,UAAM,qDAAuB,MAAM,GAAG,CAAC,KAAK,UAAU,MAAM,CAAC,CAAC;AAE5F,8BAAU,MAAM;AACd,QAAI,aAGO;AAEX,QAAI,CAAC,SAAS;AACZ,aAAO,MAAM;AACX,eAAO,UAAU;AAAA,MACnB;AAAA,IACF;AAEA,QAAI,OAAO,aAAa;AACtB,aAAO,MAAM;AACX,eAAO,UAAU;AAAA,MACnB;AAAA,IACF;AAEA,QAAI,CAAC,OAAO,SAAS;AACnB,uBAAa,+CAAiB;AAAA,QAC5B;AAAA,QACA;AAAA,QACA;AAAA,QACA,uBAAuB;AAAA,UACrB,GAAG;AAAA,UACH,GAAG;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AACD,aAAO,UAAU,WAAW;AAE5B,aAAO,eAAe,OAAO,OAAO;AAAA,IACtC;AAEA,WAAO,MAAM;AACX,aAAO,iBAAiB,SAAS;AACjC,aAAO,UAAU;AACjB,UAAI,YAAY;AACd,mBAAW,OAAO;AAClB,qBAAa;AAAA,MACf;AAAA,IACF;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,OAAO,EAAE,YAAY,UAAU,UAAU,WAAW;AAAA,MACpD,iBAAc;AAAA,MACd,KAAK;AAAA,MAEJ;AAAA;AAAA,EACH;AAEJ;;;ADhJA,IAAO,gBAAQ;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { DragHandlePluginProps } from '@tiptap/extension-drag-handle';
|
|
2
|
+
import { DragHandlePluginProps, NestedOptions } from '@tiptap/extension-drag-handle';
|
|
3
3
|
import { Node } from '@tiptap/pm/model';
|
|
4
4
|
import { Editor } from '@tiptap/react';
|
|
5
5
|
import { ReactNode } from 'react';
|
|
6
6
|
|
|
7
7
|
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
8
|
-
type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element'> & {
|
|
8
|
+
type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element' | 'nestedOptions'> & {
|
|
9
9
|
className?: string;
|
|
10
10
|
onNodeChange?: (data: {
|
|
11
11
|
node: Node | null;
|
|
@@ -13,6 +13,48 @@ type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'eleme
|
|
|
13
13
|
pos: number;
|
|
14
14
|
}) => void;
|
|
15
15
|
children: ReactNode;
|
|
16
|
+
/**
|
|
17
|
+
* Enable drag handles for nested content (list items, blockquotes, etc.).
|
|
18
|
+
*
|
|
19
|
+
* When enabled, the drag handle will appear for nested blocks, not just
|
|
20
|
+
* top-level blocks. A rule-based scoring system determines which node
|
|
21
|
+
* to target based on cursor position and configured rules.
|
|
22
|
+
*
|
|
23
|
+
* @default false
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Simple enable with sensible defaults
|
|
27
|
+
* <DragHandle editor={editor} nested>
|
|
28
|
+
* <GripIcon />
|
|
29
|
+
* </DragHandle>
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* // With custom configuration
|
|
33
|
+
* <DragHandle
|
|
34
|
+
* editor={editor}
|
|
35
|
+
* nested={{
|
|
36
|
+
* edgeDetection: 'left',
|
|
37
|
+
* allowedContainers: ['bulletList', 'orderedList'],
|
|
38
|
+
* }}
|
|
39
|
+
* >
|
|
40
|
+
* <GripIcon />
|
|
41
|
+
* </DragHandle>
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* // With custom rules
|
|
45
|
+
* <DragHandle
|
|
46
|
+
* editor={editor}
|
|
47
|
+
* nested={{
|
|
48
|
+
* rules: [{
|
|
49
|
+
* id: 'excludeCodeBlocks',
|
|
50
|
+
* evaluate: ({ node }) => node.type.name === 'codeBlock' ? 1000 : 0,
|
|
51
|
+
* }],
|
|
52
|
+
* }}
|
|
53
|
+
* >
|
|
54
|
+
* <GripIcon />
|
|
55
|
+
* </DragHandle>
|
|
56
|
+
*/
|
|
57
|
+
nested?: boolean | NestedOptions;
|
|
16
58
|
};
|
|
17
59
|
declare const DragHandle: (props: DragHandleProps) => react_jsx_runtime.JSX.Element;
|
|
18
60
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { DragHandlePluginProps } from '@tiptap/extension-drag-handle';
|
|
2
|
+
import { DragHandlePluginProps, NestedOptions } from '@tiptap/extension-drag-handle';
|
|
3
3
|
import { Node } from '@tiptap/pm/model';
|
|
4
4
|
import { Editor } from '@tiptap/react';
|
|
5
5
|
import { ReactNode } from 'react';
|
|
6
6
|
|
|
7
7
|
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
8
|
-
type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element'> & {
|
|
8
|
+
type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element' | 'nestedOptions'> & {
|
|
9
9
|
className?: string;
|
|
10
10
|
onNodeChange?: (data: {
|
|
11
11
|
node: Node | null;
|
|
@@ -13,6 +13,48 @@ type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'eleme
|
|
|
13
13
|
pos: number;
|
|
14
14
|
}) => void;
|
|
15
15
|
children: ReactNode;
|
|
16
|
+
/**
|
|
17
|
+
* Enable drag handles for nested content (list items, blockquotes, etc.).
|
|
18
|
+
*
|
|
19
|
+
* When enabled, the drag handle will appear for nested blocks, not just
|
|
20
|
+
* top-level blocks. A rule-based scoring system determines which node
|
|
21
|
+
* to target based on cursor position and configured rules.
|
|
22
|
+
*
|
|
23
|
+
* @default false
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Simple enable with sensible defaults
|
|
27
|
+
* <DragHandle editor={editor} nested>
|
|
28
|
+
* <GripIcon />
|
|
29
|
+
* </DragHandle>
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* // With custom configuration
|
|
33
|
+
* <DragHandle
|
|
34
|
+
* editor={editor}
|
|
35
|
+
* nested={{
|
|
36
|
+
* edgeDetection: 'left',
|
|
37
|
+
* allowedContainers: ['bulletList', 'orderedList'],
|
|
38
|
+
* }}
|
|
39
|
+
* >
|
|
40
|
+
* <GripIcon />
|
|
41
|
+
* </DragHandle>
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* // With custom rules
|
|
45
|
+
* <DragHandle
|
|
46
|
+
* editor={editor}
|
|
47
|
+
* nested={{
|
|
48
|
+
* rules: [{
|
|
49
|
+
* id: 'excludeCodeBlocks',
|
|
50
|
+
* evaluate: ({ node }) => node.type.name === 'codeBlock' ? 1000 : 0,
|
|
51
|
+
* }],
|
|
52
|
+
* }}
|
|
53
|
+
* >
|
|
54
|
+
* <GripIcon />
|
|
55
|
+
* </DragHandle>
|
|
56
|
+
*/
|
|
57
|
+
nested?: boolean | NestedOptions;
|
|
16
58
|
};
|
|
17
59
|
declare const DragHandle: (props: DragHandleProps) => react_jsx_runtime.JSX.Element;
|
|
18
60
|
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
import {
|
|
3
3
|
defaultComputePositionConfig,
|
|
4
4
|
DragHandlePlugin,
|
|
5
|
-
dragHandlePluginDefaultKey
|
|
5
|
+
dragHandlePluginDefaultKey,
|
|
6
|
+
normalizeNestedOptions
|
|
6
7
|
} from "@tiptap/extension-drag-handle";
|
|
7
|
-
import { useEffect, useRef, useState } from "react";
|
|
8
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
8
9
|
import { jsx } from "react/jsx-runtime";
|
|
9
10
|
var DragHandle = (props) => {
|
|
10
11
|
const {
|
|
@@ -15,10 +16,12 @@ var DragHandle = (props) => {
|
|
|
15
16
|
onNodeChange,
|
|
16
17
|
onElementDragStart,
|
|
17
18
|
onElementDragEnd,
|
|
18
|
-
computePositionConfig = defaultComputePositionConfig
|
|
19
|
+
computePositionConfig = defaultComputePositionConfig,
|
|
20
|
+
nested = false
|
|
19
21
|
} = props;
|
|
20
22
|
const [element, setElement] = useState(null);
|
|
21
23
|
const plugin = useRef(null);
|
|
24
|
+
const nestedOptions = useMemo(() => normalizeNestedOptions(nested), [JSON.stringify(nested)]);
|
|
22
25
|
useEffect(() => {
|
|
23
26
|
let initPlugin = null;
|
|
24
27
|
if (!element) {
|
|
@@ -42,7 +45,8 @@ var DragHandle = (props) => {
|
|
|
42
45
|
},
|
|
43
46
|
onElementDragStart,
|
|
44
47
|
onElementDragEnd,
|
|
45
|
-
onNodeChange
|
|
48
|
+
onNodeChange,
|
|
49
|
+
nestedOptions
|
|
46
50
|
});
|
|
47
51
|
plugin.current = initPlugin.plugin;
|
|
48
52
|
editor.registerPlugin(plugin.current);
|
|
@@ -55,7 +59,16 @@ var DragHandle = (props) => {
|
|
|
55
59
|
initPlugin = null;
|
|
56
60
|
}
|
|
57
61
|
};
|
|
58
|
-
}, [
|
|
62
|
+
}, [
|
|
63
|
+
element,
|
|
64
|
+
editor,
|
|
65
|
+
onNodeChange,
|
|
66
|
+
pluginKey,
|
|
67
|
+
computePositionConfig,
|
|
68
|
+
onElementDragStart,
|
|
69
|
+
onElementDragEnd,
|
|
70
|
+
nestedOptions
|
|
71
|
+
]);
|
|
59
72
|
return /* @__PURE__ */ jsx(
|
|
60
73
|
"div",
|
|
61
74
|
{
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/DragHandle.tsx","../src/index.ts"],"sourcesContent":["import {\n type DragHandlePluginProps,\n defaultComputePositionConfig,\n DragHandlePlugin,\n dragHandlePluginDefaultKey,\n} from '@tiptap/extension-drag-handle'\nimport type { Node } from '@tiptap/pm/model'\nimport type { Plugin } from '@tiptap/pm/state'\nimport type { Editor } from '@tiptap/react'\nimport { type ReactNode, useEffect, useRef, useState } from 'react'\n\ntype Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>\n\nexport type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element'> & {\n className?: string\n onNodeChange?: (data: { node: Node | null; editor: Editor; pos: number }) => void\n children: ReactNode\n}\n\nexport const DragHandle = (props: DragHandleProps) => {\n const {\n className = 'drag-handle',\n children,\n editor,\n pluginKey = dragHandlePluginDefaultKey,\n onNodeChange,\n onElementDragStart,\n onElementDragEnd,\n computePositionConfig = defaultComputePositionConfig,\n } = props\n const [element, setElement] = useState<HTMLDivElement | null>(null)\n const plugin = useRef<Plugin | null>(null)\n\n useEffect(() => {\n let initPlugin: {\n plugin: Plugin\n unbind: () => void\n } | null = null\n\n if (!element) {\n return () => {\n plugin.current = null\n }\n }\n\n if (editor.isDestroyed) {\n return () => {\n plugin.current = null\n }\n }\n\n if (!plugin.current) {\n initPlugin = DragHandlePlugin({\n editor,\n element,\n pluginKey,\n computePositionConfig: {\n ...defaultComputePositionConfig,\n ...computePositionConfig,\n },\n onElementDragStart,\n onElementDragEnd,\n onNodeChange,\n })\n plugin.current = initPlugin.plugin\n\n editor.registerPlugin(plugin.current)\n }\n\n return () => {\n editor.unregisterPlugin(pluginKey)\n plugin.current = null\n if (initPlugin) {\n initPlugin.unbind()\n initPlugin = null\n }\n }\n }, [element
|
|
1
|
+
{"version":3,"sources":["../src/DragHandle.tsx","../src/index.ts"],"sourcesContent":["import {\n type DragHandlePluginProps,\n type NestedOptions,\n defaultComputePositionConfig,\n DragHandlePlugin,\n dragHandlePluginDefaultKey,\n normalizeNestedOptions,\n} from '@tiptap/extension-drag-handle'\nimport type { Node } from '@tiptap/pm/model'\nimport type { Plugin } from '@tiptap/pm/state'\nimport type { Editor } from '@tiptap/react'\nimport { type ReactNode, useEffect, useMemo, useRef, useState } from 'react'\n\ntype Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>\n\nexport type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element' | 'nestedOptions'> & {\n className?: string\n onNodeChange?: (data: { node: Node | null; editor: Editor; pos: number }) => void\n children: ReactNode\n\n /**\n * Enable drag handles for nested content (list items, blockquotes, etc.).\n *\n * When enabled, the drag handle will appear for nested blocks, not just\n * top-level blocks. A rule-based scoring system determines which node\n * to target based on cursor position and configured rules.\n *\n * @default false\n *\n * @example\n * // Simple enable with sensible defaults\n * <DragHandle editor={editor} nested>\n * <GripIcon />\n * </DragHandle>\n *\n * @example\n * // With custom configuration\n * <DragHandle\n * editor={editor}\n * nested={{\n * edgeDetection: 'left',\n * allowedContainers: ['bulletList', 'orderedList'],\n * }}\n * >\n * <GripIcon />\n * </DragHandle>\n *\n * @example\n * // With custom rules\n * <DragHandle\n * editor={editor}\n * nested={{\n * rules: [{\n * id: 'excludeCodeBlocks',\n * evaluate: ({ node }) => node.type.name === 'codeBlock' ? 1000 : 0,\n * }],\n * }}\n * >\n * <GripIcon />\n * </DragHandle>\n */\n nested?: boolean | NestedOptions\n}\n\nexport const DragHandle = (props: DragHandleProps) => {\n const {\n className = 'drag-handle',\n children,\n editor,\n pluginKey = dragHandlePluginDefaultKey,\n onNodeChange,\n onElementDragStart,\n onElementDragEnd,\n computePositionConfig = defaultComputePositionConfig,\n nested = false,\n } = props\n const [element, setElement] = useState<HTMLDivElement | null>(null)\n const plugin = useRef<Plugin | null>(null)\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const nestedOptions = useMemo(() => normalizeNestedOptions(nested), [JSON.stringify(nested)])\n\n useEffect(() => {\n let initPlugin: {\n plugin: Plugin\n unbind: () => void\n } | null = null\n\n if (!element) {\n return () => {\n plugin.current = null\n }\n }\n\n if (editor.isDestroyed) {\n return () => {\n plugin.current = null\n }\n }\n\n if (!plugin.current) {\n initPlugin = DragHandlePlugin({\n editor,\n element,\n pluginKey,\n computePositionConfig: {\n ...defaultComputePositionConfig,\n ...computePositionConfig,\n },\n onElementDragStart,\n onElementDragEnd,\n onNodeChange,\n nestedOptions,\n })\n plugin.current = initPlugin.plugin\n\n editor.registerPlugin(plugin.current)\n }\n\n return () => {\n editor.unregisterPlugin(pluginKey)\n plugin.current = null\n if (initPlugin) {\n initPlugin.unbind()\n initPlugin = null\n }\n }\n }, [\n element,\n editor,\n onNodeChange,\n pluginKey,\n computePositionConfig,\n onElementDragStart,\n onElementDragEnd,\n nestedOptions,\n ])\n\n return (\n <div\n className={className}\n style={{ visibility: 'hidden', position: 'absolute' }}\n data-dragging=\"false\"\n ref={setElement}\n >\n {children}\n </div>\n )\n}\n","import { DragHandle } from './DragHandle.js'\n\nexport * from './DragHandle.js'\n\nexport default DragHandle\n"],"mappings":";AAAA;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAIP,SAAyB,WAAW,SAAS,QAAQ,gBAAgB;AAgIjE;AA3EG,IAAM,aAAa,CAAC,UAA2B;AACpD,QAAM;AAAA,IACJ,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA,wBAAwB;AAAA,IACxB,SAAS;AAAA,EACX,IAAI;AACJ,QAAM,CAAC,SAAS,UAAU,IAAI,SAAgC,IAAI;AAClE,QAAM,SAAS,OAAsB,IAAI;AAGzC,QAAM,gBAAgB,QAAQ,MAAM,uBAAuB,MAAM,GAAG,CAAC,KAAK,UAAU,MAAM,CAAC,CAAC;AAE5F,YAAU,MAAM;AACd,QAAI,aAGO;AAEX,QAAI,CAAC,SAAS;AACZ,aAAO,MAAM;AACX,eAAO,UAAU;AAAA,MACnB;AAAA,IACF;AAEA,QAAI,OAAO,aAAa;AACtB,aAAO,MAAM;AACX,eAAO,UAAU;AAAA,MACnB;AAAA,IACF;AAEA,QAAI,CAAC,OAAO,SAAS;AACnB,mBAAa,iBAAiB;AAAA,QAC5B;AAAA,QACA;AAAA,QACA;AAAA,QACA,uBAAuB;AAAA,UACrB,GAAG;AAAA,UACH,GAAG;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AACD,aAAO,UAAU,WAAW;AAE5B,aAAO,eAAe,OAAO,OAAO;AAAA,IACtC;AAEA,WAAO,MAAM;AACX,aAAO,iBAAiB,SAAS;AACjC,aAAO,UAAU;AACjB,UAAI,YAAY;AACd,mBAAW,OAAO;AAClB,qBAAa;AAAA,MACf;AAAA,IACF;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,OAAO,EAAE,YAAY,UAAU,UAAU,WAAW;AAAA,MACpD,iBAAc;AAAA,MACd,KAAK;AAAA,MAEJ;AAAA;AAAA,EACH;AAEJ;;;AChJA,IAAO,gBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/extension-drag-handle-react",
|
|
3
3
|
"description": "drag handle extension for tiptap with react",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.17.0",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -38,18 +38,18 @@
|
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"react": "^16.8 || ^17 || ^18 || ^19",
|
|
40
40
|
"react-dom": "^16.8 || ^17 || ^18 || ^19",
|
|
41
|
-
"@tiptap/extension-drag-handle": "^3.
|
|
42
|
-
"@tiptap/pm": "^3.
|
|
43
|
-
"@tiptap/react": "^3.
|
|
41
|
+
"@tiptap/extension-drag-handle": "^3.17.0",
|
|
42
|
+
"@tiptap/pm": "^3.17.0",
|
|
43
|
+
"@tiptap/react": "^3.17.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/react": "^18.0.0",
|
|
47
47
|
"@types/react-dom": "^18.0.0",
|
|
48
48
|
"react": "^18.0.0",
|
|
49
49
|
"react-dom": "^18.0.0",
|
|
50
|
-
"@tiptap/extension-drag-handle": "^3.
|
|
51
|
-
"@tiptap/pm": "^3.
|
|
52
|
-
"@tiptap/react": "^3.
|
|
50
|
+
"@tiptap/extension-drag-handle": "^3.17.0",
|
|
51
|
+
"@tiptap/pm": "^3.17.0",
|
|
52
|
+
"@tiptap/react": "^3.17.0"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "tsup",
|
package/src/DragHandle.tsx
CHANGED
|
@@ -1,20 +1,65 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type DragHandlePluginProps,
|
|
3
|
+
type NestedOptions,
|
|
3
4
|
defaultComputePositionConfig,
|
|
4
5
|
DragHandlePlugin,
|
|
5
6
|
dragHandlePluginDefaultKey,
|
|
7
|
+
normalizeNestedOptions,
|
|
6
8
|
} from '@tiptap/extension-drag-handle'
|
|
7
9
|
import type { Node } from '@tiptap/pm/model'
|
|
8
10
|
import type { Plugin } from '@tiptap/pm/state'
|
|
9
11
|
import type { Editor } from '@tiptap/react'
|
|
10
|
-
import { type ReactNode, useEffect, useRef, useState } from 'react'
|
|
12
|
+
import { type ReactNode, useEffect, useMemo, useRef, useState } from 'react'
|
|
11
13
|
|
|
12
14
|
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>
|
|
13
15
|
|
|
14
|
-
export type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element'> & {
|
|
16
|
+
export type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element' | 'nestedOptions'> & {
|
|
15
17
|
className?: string
|
|
16
18
|
onNodeChange?: (data: { node: Node | null; editor: Editor; pos: number }) => void
|
|
17
19
|
children: ReactNode
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Enable drag handles for nested content (list items, blockquotes, etc.).
|
|
23
|
+
*
|
|
24
|
+
* When enabled, the drag handle will appear for nested blocks, not just
|
|
25
|
+
* top-level blocks. A rule-based scoring system determines which node
|
|
26
|
+
* to target based on cursor position and configured rules.
|
|
27
|
+
*
|
|
28
|
+
* @default false
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // Simple enable with sensible defaults
|
|
32
|
+
* <DragHandle editor={editor} nested>
|
|
33
|
+
* <GripIcon />
|
|
34
|
+
* </DragHandle>
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // With custom configuration
|
|
38
|
+
* <DragHandle
|
|
39
|
+
* editor={editor}
|
|
40
|
+
* nested={{
|
|
41
|
+
* edgeDetection: 'left',
|
|
42
|
+
* allowedContainers: ['bulletList', 'orderedList'],
|
|
43
|
+
* }}
|
|
44
|
+
* >
|
|
45
|
+
* <GripIcon />
|
|
46
|
+
* </DragHandle>
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* // With custom rules
|
|
50
|
+
* <DragHandle
|
|
51
|
+
* editor={editor}
|
|
52
|
+
* nested={{
|
|
53
|
+
* rules: [{
|
|
54
|
+
* id: 'excludeCodeBlocks',
|
|
55
|
+
* evaluate: ({ node }) => node.type.name === 'codeBlock' ? 1000 : 0,
|
|
56
|
+
* }],
|
|
57
|
+
* }}
|
|
58
|
+
* >
|
|
59
|
+
* <GripIcon />
|
|
60
|
+
* </DragHandle>
|
|
61
|
+
*/
|
|
62
|
+
nested?: boolean | NestedOptions
|
|
18
63
|
}
|
|
19
64
|
|
|
20
65
|
export const DragHandle = (props: DragHandleProps) => {
|
|
@@ -27,10 +72,14 @@ export const DragHandle = (props: DragHandleProps) => {
|
|
|
27
72
|
onElementDragStart,
|
|
28
73
|
onElementDragEnd,
|
|
29
74
|
computePositionConfig = defaultComputePositionConfig,
|
|
75
|
+
nested = false,
|
|
30
76
|
} = props
|
|
31
77
|
const [element, setElement] = useState<HTMLDivElement | null>(null)
|
|
32
78
|
const plugin = useRef<Plugin | null>(null)
|
|
33
79
|
|
|
80
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
81
|
+
const nestedOptions = useMemo(() => normalizeNestedOptions(nested), [JSON.stringify(nested)])
|
|
82
|
+
|
|
34
83
|
useEffect(() => {
|
|
35
84
|
let initPlugin: {
|
|
36
85
|
plugin: Plugin
|
|
@@ -61,6 +110,7 @@ export const DragHandle = (props: DragHandleProps) => {
|
|
|
61
110
|
onElementDragStart,
|
|
62
111
|
onElementDragEnd,
|
|
63
112
|
onNodeChange,
|
|
113
|
+
nestedOptions,
|
|
64
114
|
})
|
|
65
115
|
plugin.current = initPlugin.plugin
|
|
66
116
|
|
|
@@ -75,7 +125,16 @@ export const DragHandle = (props: DragHandleProps) => {
|
|
|
75
125
|
initPlugin = null
|
|
76
126
|
}
|
|
77
127
|
}
|
|
78
|
-
}, [
|
|
128
|
+
}, [
|
|
129
|
+
element,
|
|
130
|
+
editor,
|
|
131
|
+
onNodeChange,
|
|
132
|
+
pluginKey,
|
|
133
|
+
computePositionConfig,
|
|
134
|
+
onElementDragStart,
|
|
135
|
+
onElementDragEnd,
|
|
136
|
+
nestedOptions,
|
|
137
|
+
])
|
|
79
138
|
|
|
80
139
|
return (
|
|
81
140
|
<div
|