@tiptap/extension-drag-handle-vue-3 3.15.3 → 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 +26 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -3
- package/dist/index.d.ts +22 -3
- package/dist/index.js +29 -8
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/DragHandle.ts +46 -9
package/dist/index.cjs
CHANGED
|
@@ -58,20 +58,24 @@ var DragHandle = (0, import_vue.defineComponent)({
|
|
|
58
58
|
class: {
|
|
59
59
|
type: String,
|
|
60
60
|
default: "drag-handle"
|
|
61
|
+
},
|
|
62
|
+
nested: {
|
|
63
|
+
type: [Boolean, Object],
|
|
64
|
+
default: false
|
|
61
65
|
}
|
|
62
66
|
},
|
|
63
67
|
setup(props, { slots }) {
|
|
64
68
|
const root = (0, import_vue.ref)(null);
|
|
65
69
|
const pluginHandle = (0, import_vue.shallowRef)(null);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const { editor, pluginKey, onNodeChange, onElementDragEnd, onElementDragStart, computePositionConfig } = props;
|
|
70
|
+
const initPlugin = () => {
|
|
71
|
+
const { editor, pluginKey, onNodeChange, onElementDragEnd, onElementDragStart, computePositionConfig, nested } = props;
|
|
69
72
|
if (!root.value) {
|
|
70
73
|
return;
|
|
71
74
|
}
|
|
72
75
|
if (!props.editor || props.editor.isDestroyed) {
|
|
73
76
|
return;
|
|
74
77
|
}
|
|
78
|
+
const nestedOptions = (0, import_extension_drag_handle.normalizeNestedOptions)(nested);
|
|
75
79
|
const init = (0, import_extension_drag_handle.DragHandlePlugin)({
|
|
76
80
|
editor,
|
|
77
81
|
element: root.value,
|
|
@@ -79,12 +83,13 @@ var DragHandle = (0, import_vue.defineComponent)({
|
|
|
79
83
|
computePositionConfig: { ...import_extension_drag_handle.defaultComputePositionConfig, ...computePositionConfig },
|
|
80
84
|
onNodeChange,
|
|
81
85
|
onElementDragStart,
|
|
82
|
-
onElementDragEnd
|
|
86
|
+
onElementDragEnd,
|
|
87
|
+
nestedOptions
|
|
83
88
|
});
|
|
84
89
|
pluginHandle.value = init;
|
|
85
90
|
props.editor.registerPlugin(init.plugin);
|
|
86
|
-
}
|
|
87
|
-
|
|
91
|
+
};
|
|
92
|
+
const destroyPlugin = () => {
|
|
88
93
|
var _a, _b;
|
|
89
94
|
if (!pluginHandle.value) {
|
|
90
95
|
return;
|
|
@@ -94,6 +99,21 @@ var DragHandle = (0, import_vue.defineComponent)({
|
|
|
94
99
|
}
|
|
95
100
|
(_b = (_a = pluginHandle.value).unbind) == null ? void 0 : _b.call(_a);
|
|
96
101
|
pluginHandle.value = null;
|
|
102
|
+
};
|
|
103
|
+
(0, import_vue.onMounted)(async () => {
|
|
104
|
+
await (0, import_vue.nextTick)();
|
|
105
|
+
initPlugin();
|
|
106
|
+
});
|
|
107
|
+
(0, import_vue.watch)(
|
|
108
|
+
() => props.nested,
|
|
109
|
+
() => {
|
|
110
|
+
destroyPlugin();
|
|
111
|
+
initPlugin();
|
|
112
|
+
},
|
|
113
|
+
{ deep: true }
|
|
114
|
+
);
|
|
115
|
+
(0, import_vue.onBeforeUnmount)(() => {
|
|
116
|
+
destroyPlugin();
|
|
97
117
|
});
|
|
98
118
|
return () => {
|
|
99
119
|
var _a;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/DragHandle.ts"],"sourcesContent":["import { DragHandle } from './DragHandle.js'\n\nexport * from './DragHandle.js'\n\nexport default DragHandle\n","import type { DragHandlePluginProps } from '@tiptap/extension-drag-handle'\nimport {\n defaultComputePositionConfig,\n DragHandlePlugin,\n dragHandlePluginDefaultKey,\n} from '@tiptap/extension-drag-handle'\nimport type { Node } from '@tiptap/pm/model'\nimport type { Plugin, PluginKey } from '@tiptap/pm/state'\nimport type { Editor } from '@tiptap/vue-3'\nimport type { PropType } from 'vue'\nimport { defineComponent, h, nextTick, onBeforeUnmount, onMounted, ref, shallowRef } from 'vue'\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 class?: string\n onNodeChange?: (data: { node: Node | null; editor: Editor; pos: number }) => void\n}\n\nexport const DragHandle = defineComponent({\n name: 'DragHandleVue',\n\n props: {\n pluginKey: {\n type: [String, Object] as PropType<PluginKey | string>,\n default: dragHandlePluginDefaultKey,\n },\n\n editor: {\n type: Object as PropType<DragHandleProps['editor']>,\n required: true,\n },\n\n computePositionConfig: {\n type: Object as PropType<DragHandleProps['computePositionConfig']>,\n default: () => ({}),\n },\n\n onNodeChange: {\n type: Function as PropType<DragHandleProps['onNodeChange']>,\n default: null,\n },\n\n onElementDragStart: {\n type: Function as PropType<DragHandleProps['onElementDragStart']>,\n default: null,\n },\n\n onElementDragEnd: {\n type: Function as PropType<DragHandleProps['onElementDragEnd']>,\n default: null,\n },\n\n class: {\n type: String as PropType<DragHandleProps['class']>,\n default: 'drag-handle',\n },\n },\n\n setup(props, { slots }) {\n const root = ref<HTMLElement | null>(null)\n const pluginHandle = shallowRef<{ plugin: Plugin; unbind: () => void } | null>(null)\n\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/DragHandle.ts"],"sourcesContent":["import { DragHandle } from './DragHandle.js'\n\nexport * from './DragHandle.js'\n\nexport default DragHandle\n","import type { DragHandlePluginProps, NestedOptions } from '@tiptap/extension-drag-handle'\nimport {\n defaultComputePositionConfig,\n DragHandlePlugin,\n dragHandlePluginDefaultKey,\n normalizeNestedOptions,\n} from '@tiptap/extension-drag-handle'\nimport type { Node } from '@tiptap/pm/model'\nimport type { Plugin, PluginKey } from '@tiptap/pm/state'\nimport type { Editor } from '@tiptap/vue-3'\nimport type { PropType } from 'vue'\nimport { defineComponent, h, nextTick, onBeforeUnmount, onMounted, ref, shallowRef, watch } from 'vue'\n\ntype Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>\n\nexport type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey' | 'nestedOptions'>, 'element'> & {\n class?: string\n onNodeChange?: (data: { node: Node | null; editor: Editor; pos: number }) => void\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 nested?: boolean | NestedOptions\n}\n\nexport const DragHandle = defineComponent({\n name: 'DragHandleVue',\n\n props: {\n pluginKey: {\n type: [String, Object] as PropType<PluginKey | string>,\n default: dragHandlePluginDefaultKey,\n },\n\n editor: {\n type: Object as PropType<DragHandleProps['editor']>,\n required: true,\n },\n\n computePositionConfig: {\n type: Object as PropType<DragHandleProps['computePositionConfig']>,\n default: () => ({}),\n },\n\n onNodeChange: {\n type: Function as PropType<DragHandleProps['onNodeChange']>,\n default: null,\n },\n\n onElementDragStart: {\n type: Function as PropType<DragHandleProps['onElementDragStart']>,\n default: null,\n },\n\n onElementDragEnd: {\n type: Function as PropType<DragHandleProps['onElementDragEnd']>,\n default: null,\n },\n\n class: {\n type: String as PropType<DragHandleProps['class']>,\n default: 'drag-handle',\n },\n\n nested: {\n type: [Boolean, Object] as PropType<DragHandleProps['nested']>,\n default: false,\n },\n },\n\n setup(props, { slots }) {\n const root = ref<HTMLElement | null>(null)\n const pluginHandle = shallowRef<{ plugin: Plugin; unbind: () => void } | null>(null)\n\n const initPlugin = () => {\n const { editor, pluginKey, onNodeChange, onElementDragEnd, onElementDragStart, computePositionConfig, nested } =\n props\n\n if (!root.value) {\n return\n }\n if (!props.editor || props.editor.isDestroyed) {\n return\n }\n\n const nestedOptions = normalizeNestedOptions(nested)\n\n const init = DragHandlePlugin({\n editor,\n element: root.value,\n pluginKey,\n computePositionConfig: { ...defaultComputePositionConfig, ...computePositionConfig },\n onNodeChange,\n onElementDragStart,\n onElementDragEnd,\n nestedOptions,\n })\n\n pluginHandle.value = init\n props.editor.registerPlugin(init.plugin)\n }\n\n const destroyPlugin = () => {\n if (!pluginHandle.value) {\n return\n }\n\n if (props.editor && !props.editor.isDestroyed) {\n props.editor.unregisterPlugin(props.pluginKey)\n }\n\n pluginHandle.value.unbind?.()\n pluginHandle.value = null\n }\n\n onMounted(async () => {\n await nextTick()\n initPlugin()\n })\n\n // Reinitialize plugin when nested option changes\n watch(\n () => props.nested,\n () => {\n destroyPlugin()\n initPlugin()\n },\n { deep: true },\n )\n\n onBeforeUnmount(() => {\n destroyPlugin()\n })\n\n return () =>\n h(\n 'div',\n {\n ref: root,\n class: props.class,\n style: { visibility: 'hidden', position: 'absolute' },\n 'data-dragging': 'false',\n },\n slots.default?.(),\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,mCAKO;AAKP,iBAAiG;AAmB1F,IAAM,iBAAa,4BAAgB;AAAA,EACxC,MAAM;AAAA,EAEN,OAAO;AAAA,IACL,WAAW;AAAA,MACT,MAAM,CAAC,QAAQ,MAAM;AAAA,MACrB,SAAS;AAAA,IACX;AAAA,IAEA,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,IAEA,uBAAuB;AAAA,MACrB,MAAM;AAAA,MACN,SAAS,OAAO,CAAC;AAAA,IACnB;AAAA,IAEA,cAAc;AAAA,MACZ,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AAAA,IAEA,oBAAoB;AAAA,MAClB,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AAAA,IAEA,kBAAkB;AAAA,MAChB,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AAAA,IAEA,OAAO;AAAA,MACL,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AAAA,IAEA,QAAQ;AAAA,MACN,MAAM,CAAC,SAAS,MAAM;AAAA,MACtB,SAAS;AAAA,IACX;AAAA,EACF;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AAW;AAAA,UACpD,iBAAiB;AAAA,QACnB;AAAA,SACA,WAAM,YAAN;AAAA,MACF;AAAA;AAAA,EACJ;AACF,CAAC;;;ADnJD,IAAO,gBAAQ;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as _floating_ui_dom from '@floating-ui/dom';
|
|
2
2
|
import { EditorState, Plugin, Transaction, PluginKey } from '@tiptap/pm/state';
|
|
3
3
|
import { MarkType as MarkType$1, MarkSpec, Mark as Mark$1, DOMOutputSpec, NodeType as NodeType$1, NodeSpec, Node as Node$1, Slice, ParseOptions, Schema, ResolvedPos, Fragment } from '@tiptap/pm/model';
|
|
4
|
-
import {
|
|
4
|
+
import { NodeViewConstructor, NodeView, MarkViewConstructor, MarkView, EditorProps, EditorView } from '@tiptap/pm/view';
|
|
5
5
|
import { Transform, MapResult } from '@tiptap/pm/transform';
|
|
6
6
|
import * as vue from 'vue';
|
|
7
7
|
import { PropType } from 'vue';
|
|
8
|
-
import { DragHandlePluginProps } from '@tiptap/extension-drag-handle';
|
|
8
|
+
import { DragHandlePluginProps, NestedOptions } from '@tiptap/extension-drag-handle';
|
|
9
9
|
import { Editor as Editor$1 } from '@tiptap/vue-3';
|
|
10
10
|
|
|
11
11
|
type StringKeyOf<T> = Extract<keyof T, string>;
|
|
@@ -2925,13 +2925,23 @@ interface Storage {
|
|
|
2925
2925
|
}
|
|
2926
2926
|
|
|
2927
2927
|
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
2928
|
-
type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element'> & {
|
|
2928
|
+
type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey' | 'nestedOptions'>, 'element'> & {
|
|
2929
2929
|
class?: string;
|
|
2930
2930
|
onNodeChange?: (data: {
|
|
2931
2931
|
node: Node$1 | null;
|
|
2932
2932
|
editor: Editor$1;
|
|
2933
2933
|
pos: number;
|
|
2934
2934
|
}) => void;
|
|
2935
|
+
/**
|
|
2936
|
+
* Enable drag handles for nested content (list items, blockquotes, etc.).
|
|
2937
|
+
*
|
|
2938
|
+
* When enabled, the drag handle will appear for nested blocks, not just
|
|
2939
|
+
* top-level blocks. A rule-based scoring system determines which node
|
|
2940
|
+
* to target based on cursor position and configured rules.
|
|
2941
|
+
*
|
|
2942
|
+
* @default false
|
|
2943
|
+
*/
|
|
2944
|
+
nested?: boolean | NestedOptions;
|
|
2935
2945
|
};
|
|
2936
2946
|
declare const DragHandle: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
2937
2947
|
pluginKey: {
|
|
@@ -2962,6 +2972,10 @@ declare const DragHandle: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
2962
2972
|
type: PropType<DragHandleProps["class"]>;
|
|
2963
2973
|
default: string;
|
|
2964
2974
|
};
|
|
2975
|
+
nested: {
|
|
2976
|
+
type: PropType<DragHandleProps["nested"]>;
|
|
2977
|
+
default: boolean;
|
|
2978
|
+
};
|
|
2965
2979
|
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
2966
2980
|
[key: string]: any;
|
|
2967
2981
|
}>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
@@ -2993,6 +3007,10 @@ declare const DragHandle: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
2993
3007
|
type: PropType<DragHandleProps["class"]>;
|
|
2994
3008
|
default: string;
|
|
2995
3009
|
};
|
|
3010
|
+
nested: {
|
|
3011
|
+
type: PropType<DragHandleProps["nested"]>;
|
|
3012
|
+
default: boolean;
|
|
3013
|
+
};
|
|
2996
3014
|
}>> & Readonly<{}>, {
|
|
2997
3015
|
pluginKey: string | PluginKey<any>;
|
|
2998
3016
|
onNodeChange: (((data: {
|
|
@@ -3013,6 +3031,7 @@ declare const DragHandle: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
3013
3031
|
platform?: _floating_ui_dom.Platform | undefined;
|
|
3014
3032
|
} | undefined;
|
|
3015
3033
|
class: string | undefined;
|
|
3034
|
+
nested: boolean | NestedOptions | undefined;
|
|
3016
3035
|
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
3017
3036
|
|
|
3018
3037
|
export { DragHandle, type DragHandleProps, DragHandle as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as _floating_ui_dom from '@floating-ui/dom';
|
|
2
2
|
import { EditorState, Plugin, Transaction, PluginKey } from '@tiptap/pm/state';
|
|
3
3
|
import { MarkType as MarkType$1, MarkSpec, Mark as Mark$1, DOMOutputSpec, NodeType as NodeType$1, NodeSpec, Node as Node$1, Slice, ParseOptions, Schema, ResolvedPos, Fragment } from '@tiptap/pm/model';
|
|
4
|
-
import {
|
|
4
|
+
import { NodeViewConstructor, NodeView, MarkViewConstructor, MarkView, EditorProps, EditorView } from '@tiptap/pm/view';
|
|
5
5
|
import { Transform, MapResult } from '@tiptap/pm/transform';
|
|
6
6
|
import * as vue from 'vue';
|
|
7
7
|
import { PropType } from 'vue';
|
|
8
|
-
import { DragHandlePluginProps } from '@tiptap/extension-drag-handle';
|
|
8
|
+
import { DragHandlePluginProps, NestedOptions } from '@tiptap/extension-drag-handle';
|
|
9
9
|
import { Editor as Editor$1 } from '@tiptap/vue-3';
|
|
10
10
|
|
|
11
11
|
type StringKeyOf<T> = Extract<keyof T, string>;
|
|
@@ -2925,13 +2925,23 @@ interface Storage {
|
|
|
2925
2925
|
}
|
|
2926
2926
|
|
|
2927
2927
|
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
2928
|
-
type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element'> & {
|
|
2928
|
+
type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey' | 'nestedOptions'>, 'element'> & {
|
|
2929
2929
|
class?: string;
|
|
2930
2930
|
onNodeChange?: (data: {
|
|
2931
2931
|
node: Node$1 | null;
|
|
2932
2932
|
editor: Editor$1;
|
|
2933
2933
|
pos: number;
|
|
2934
2934
|
}) => void;
|
|
2935
|
+
/**
|
|
2936
|
+
* Enable drag handles for nested content (list items, blockquotes, etc.).
|
|
2937
|
+
*
|
|
2938
|
+
* When enabled, the drag handle will appear for nested blocks, not just
|
|
2939
|
+
* top-level blocks. A rule-based scoring system determines which node
|
|
2940
|
+
* to target based on cursor position and configured rules.
|
|
2941
|
+
*
|
|
2942
|
+
* @default false
|
|
2943
|
+
*/
|
|
2944
|
+
nested?: boolean | NestedOptions;
|
|
2935
2945
|
};
|
|
2936
2946
|
declare const DragHandle: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
2937
2947
|
pluginKey: {
|
|
@@ -2962,6 +2972,10 @@ declare const DragHandle: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
2962
2972
|
type: PropType<DragHandleProps["class"]>;
|
|
2963
2973
|
default: string;
|
|
2964
2974
|
};
|
|
2975
|
+
nested: {
|
|
2976
|
+
type: PropType<DragHandleProps["nested"]>;
|
|
2977
|
+
default: boolean;
|
|
2978
|
+
};
|
|
2965
2979
|
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
2966
2980
|
[key: string]: any;
|
|
2967
2981
|
}>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
@@ -2993,6 +3007,10 @@ declare const DragHandle: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
2993
3007
|
type: PropType<DragHandleProps["class"]>;
|
|
2994
3008
|
default: string;
|
|
2995
3009
|
};
|
|
3010
|
+
nested: {
|
|
3011
|
+
type: PropType<DragHandleProps["nested"]>;
|
|
3012
|
+
default: boolean;
|
|
3013
|
+
};
|
|
2996
3014
|
}>> & Readonly<{}>, {
|
|
2997
3015
|
pluginKey: string | PluginKey<any>;
|
|
2998
3016
|
onNodeChange: (((data: {
|
|
@@ -3013,6 +3031,7 @@ declare const DragHandle: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
3013
3031
|
platform?: _floating_ui_dom.Platform | undefined;
|
|
3014
3032
|
} | undefined;
|
|
3015
3033
|
class: string | undefined;
|
|
3034
|
+
nested: boolean | NestedOptions | undefined;
|
|
3016
3035
|
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
3017
3036
|
|
|
3018
3037
|
export { DragHandle, type DragHandleProps, DragHandle as default };
|
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 { defineComponent, h, nextTick, onBeforeUnmount, onMounted, ref, shallowRef } from "vue";
|
|
8
|
+
import { defineComponent, h, nextTick, onBeforeUnmount, onMounted, ref, shallowRef, watch } from "vue";
|
|
8
9
|
var DragHandle = defineComponent({
|
|
9
10
|
name: "DragHandleVue",
|
|
10
11
|
props: {
|
|
@@ -35,20 +36,24 @@ var DragHandle = defineComponent({
|
|
|
35
36
|
class: {
|
|
36
37
|
type: String,
|
|
37
38
|
default: "drag-handle"
|
|
39
|
+
},
|
|
40
|
+
nested: {
|
|
41
|
+
type: [Boolean, Object],
|
|
42
|
+
default: false
|
|
38
43
|
}
|
|
39
44
|
},
|
|
40
45
|
setup(props, { slots }) {
|
|
41
46
|
const root = ref(null);
|
|
42
47
|
const pluginHandle = shallowRef(null);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const { editor, pluginKey, onNodeChange, onElementDragEnd, onElementDragStart, computePositionConfig } = props;
|
|
48
|
+
const initPlugin = () => {
|
|
49
|
+
const { editor, pluginKey, onNodeChange, onElementDragEnd, onElementDragStart, computePositionConfig, nested } = props;
|
|
46
50
|
if (!root.value) {
|
|
47
51
|
return;
|
|
48
52
|
}
|
|
49
53
|
if (!props.editor || props.editor.isDestroyed) {
|
|
50
54
|
return;
|
|
51
55
|
}
|
|
56
|
+
const nestedOptions = normalizeNestedOptions(nested);
|
|
52
57
|
const init = DragHandlePlugin({
|
|
53
58
|
editor,
|
|
54
59
|
element: root.value,
|
|
@@ -56,12 +61,13 @@ var DragHandle = defineComponent({
|
|
|
56
61
|
computePositionConfig: { ...defaultComputePositionConfig, ...computePositionConfig },
|
|
57
62
|
onNodeChange,
|
|
58
63
|
onElementDragStart,
|
|
59
|
-
onElementDragEnd
|
|
64
|
+
onElementDragEnd,
|
|
65
|
+
nestedOptions
|
|
60
66
|
});
|
|
61
67
|
pluginHandle.value = init;
|
|
62
68
|
props.editor.registerPlugin(init.plugin);
|
|
63
|
-
}
|
|
64
|
-
|
|
69
|
+
};
|
|
70
|
+
const destroyPlugin = () => {
|
|
65
71
|
var _a, _b;
|
|
66
72
|
if (!pluginHandle.value) {
|
|
67
73
|
return;
|
|
@@ -71,6 +77,21 @@ var DragHandle = defineComponent({
|
|
|
71
77
|
}
|
|
72
78
|
(_b = (_a = pluginHandle.value).unbind) == null ? void 0 : _b.call(_a);
|
|
73
79
|
pluginHandle.value = null;
|
|
80
|
+
};
|
|
81
|
+
onMounted(async () => {
|
|
82
|
+
await nextTick();
|
|
83
|
+
initPlugin();
|
|
84
|
+
});
|
|
85
|
+
watch(
|
|
86
|
+
() => props.nested,
|
|
87
|
+
() => {
|
|
88
|
+
destroyPlugin();
|
|
89
|
+
initPlugin();
|
|
90
|
+
},
|
|
91
|
+
{ deep: true }
|
|
92
|
+
);
|
|
93
|
+
onBeforeUnmount(() => {
|
|
94
|
+
destroyPlugin();
|
|
74
95
|
});
|
|
75
96
|
return () => {
|
|
76
97
|
var _a;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/DragHandle.ts","../src/index.ts"],"sourcesContent":["import type { DragHandlePluginProps } from '@tiptap/extension-drag-handle'\nimport {\n defaultComputePositionConfig,\n DragHandlePlugin,\n dragHandlePluginDefaultKey,\n} from '@tiptap/extension-drag-handle'\nimport type { Node } from '@tiptap/pm/model'\nimport type { Plugin, PluginKey } from '@tiptap/pm/state'\nimport type { Editor } from '@tiptap/vue-3'\nimport type { PropType } from 'vue'\nimport { defineComponent, h, nextTick, onBeforeUnmount, onMounted, ref, shallowRef } from 'vue'\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 class?: string\n onNodeChange?: (data: { node: Node | null; editor: Editor; pos: number }) => void\n}\n\nexport const DragHandle = defineComponent({\n name: 'DragHandleVue',\n\n props: {\n pluginKey: {\n type: [String, Object] as PropType<PluginKey | string>,\n default: dragHandlePluginDefaultKey,\n },\n\n editor: {\n type: Object as PropType<DragHandleProps['editor']>,\n required: true,\n },\n\n computePositionConfig: {\n type: Object as PropType<DragHandleProps['computePositionConfig']>,\n default: () => ({}),\n },\n\n onNodeChange: {\n type: Function as PropType<DragHandleProps['onNodeChange']>,\n default: null,\n },\n\n onElementDragStart: {\n type: Function as PropType<DragHandleProps['onElementDragStart']>,\n default: null,\n },\n\n onElementDragEnd: {\n type: Function as PropType<DragHandleProps['onElementDragEnd']>,\n default: null,\n },\n\n class: {\n type: String as PropType<DragHandleProps['class']>,\n default: 'drag-handle',\n },\n },\n\n setup(props, { slots }) {\n const root = ref<HTMLElement | null>(null)\n const pluginHandle = shallowRef<{ plugin: Plugin; unbind: () => void } | null>(null)\n\n
|
|
1
|
+
{"version":3,"sources":["../src/DragHandle.ts","../src/index.ts"],"sourcesContent":["import type { DragHandlePluginProps, NestedOptions } from '@tiptap/extension-drag-handle'\nimport {\n defaultComputePositionConfig,\n DragHandlePlugin,\n dragHandlePluginDefaultKey,\n normalizeNestedOptions,\n} from '@tiptap/extension-drag-handle'\nimport type { Node } from '@tiptap/pm/model'\nimport type { Plugin, PluginKey } from '@tiptap/pm/state'\nimport type { Editor } from '@tiptap/vue-3'\nimport type { PropType } from 'vue'\nimport { defineComponent, h, nextTick, onBeforeUnmount, onMounted, ref, shallowRef, watch } from 'vue'\n\ntype Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>\n\nexport type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey' | 'nestedOptions'>, 'element'> & {\n class?: string\n onNodeChange?: (data: { node: Node | null; editor: Editor; pos: number }) => void\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 nested?: boolean | NestedOptions\n}\n\nexport const DragHandle = defineComponent({\n name: 'DragHandleVue',\n\n props: {\n pluginKey: {\n type: [String, Object] as PropType<PluginKey | string>,\n default: dragHandlePluginDefaultKey,\n },\n\n editor: {\n type: Object as PropType<DragHandleProps['editor']>,\n required: true,\n },\n\n computePositionConfig: {\n type: Object as PropType<DragHandleProps['computePositionConfig']>,\n default: () => ({}),\n },\n\n onNodeChange: {\n type: Function as PropType<DragHandleProps['onNodeChange']>,\n default: null,\n },\n\n onElementDragStart: {\n type: Function as PropType<DragHandleProps['onElementDragStart']>,\n default: null,\n },\n\n onElementDragEnd: {\n type: Function as PropType<DragHandleProps['onElementDragEnd']>,\n default: null,\n },\n\n class: {\n type: String as PropType<DragHandleProps['class']>,\n default: 'drag-handle',\n },\n\n nested: {\n type: [Boolean, Object] as PropType<DragHandleProps['nested']>,\n default: false,\n },\n },\n\n setup(props, { slots }) {\n const root = ref<HTMLElement | null>(null)\n const pluginHandle = shallowRef<{ plugin: Plugin; unbind: () => void } | null>(null)\n\n const initPlugin = () => {\n const { editor, pluginKey, onNodeChange, onElementDragEnd, onElementDragStart, computePositionConfig, nested } =\n props\n\n if (!root.value) {\n return\n }\n if (!props.editor || props.editor.isDestroyed) {\n return\n }\n\n const nestedOptions = normalizeNestedOptions(nested)\n\n const init = DragHandlePlugin({\n editor,\n element: root.value,\n pluginKey,\n computePositionConfig: { ...defaultComputePositionConfig, ...computePositionConfig },\n onNodeChange,\n onElementDragStart,\n onElementDragEnd,\n nestedOptions,\n })\n\n pluginHandle.value = init\n props.editor.registerPlugin(init.plugin)\n }\n\n const destroyPlugin = () => {\n if (!pluginHandle.value) {\n return\n }\n\n if (props.editor && !props.editor.isDestroyed) {\n props.editor.unregisterPlugin(props.pluginKey)\n }\n\n pluginHandle.value.unbind?.()\n pluginHandle.value = null\n }\n\n onMounted(async () => {\n await nextTick()\n initPlugin()\n })\n\n // Reinitialize plugin when nested option changes\n watch(\n () => props.nested,\n () => {\n destroyPlugin()\n initPlugin()\n },\n { deep: true },\n )\n\n onBeforeUnmount(() => {\n destroyPlugin()\n })\n\n return () =>\n h(\n 'div',\n {\n ref: root,\n class: props.class,\n style: { visibility: 'hidden', position: 'absolute' },\n 'data-dragging': 'false',\n },\n slots.default?.(),\n )\n },\n})\n","import { DragHandle } from './DragHandle.js'\n\nexport * from './DragHandle.js'\n\nexport default DragHandle\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAKP,SAAS,iBAAiB,GAAG,UAAU,iBAAiB,WAAW,KAAK,YAAY,aAAa;AAmB1F,IAAM,aAAa,gBAAgB;AAAA,EACxC,MAAM;AAAA,EAEN,OAAO;AAAA,IACL,WAAW;AAAA,MACT,MAAM,CAAC,QAAQ,MAAM;AAAA,MACrB,SAAS;AAAA,IACX;AAAA,IAEA,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,IAEA,uBAAuB;AAAA,MACrB,MAAM;AAAA,MACN,SAAS,OAAO,CAAC;AAAA,IACnB;AAAA,IAEA,cAAc;AAAA,MACZ,MAAM;AAAA,M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AAA,MACE,MAAM,MAAM;AAAA,MACZ,MAAM;AACJ,sBAAc;AACd,mBAAW;AAAA,MACb;AAAA,MACA,EAAE,MAAM,KAAK;AAAA,IACf;AAEA,oBAAgB,MAAM;AACpB,oBAAc;AAAA,IAChB,CAAC;AAED,WAAO,MAAG;AA3Id;AA4IM;AAAA,QACE;AAAA,QACA;AAAA,UACE,KAAK;AAAA,UACL,OAAO,MAAM;AAAA,UACb,OAAO,EAAE,YAAY,UAAU,UAAU,WAAW;AAAA,UACpD,iBAAiB;AAAA,QACnB;AAAA,SACA,WAAM,YAAN;AAAA,MACF;AAAA;AAAA,EACJ;AACF,CAAC;;;ACnJD,IAAO,gBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/extension-drag-handle-vue-3",
|
|
3
3
|
"description": "drag handle extension for tiptap with vue 3",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.17.0",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -37,15 +37,15 @@
|
|
|
37
37
|
],
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"vue": "^3.0.0",
|
|
40
|
-
"@tiptap/extension-drag-handle": "^3.
|
|
41
|
-
"@tiptap/
|
|
42
|
-
"@tiptap/
|
|
40
|
+
"@tiptap/extension-drag-handle": "^3.17.0",
|
|
41
|
+
"@tiptap/pm": "^3.17.0",
|
|
42
|
+
"@tiptap/vue-3": "^3.17.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"vue": "^3.0.0",
|
|
46
|
-
"@tiptap/extension-drag-handle": "^3.
|
|
47
|
-
"@tiptap/pm": "^3.
|
|
48
|
-
"@tiptap/vue-3": "^3.
|
|
46
|
+
"@tiptap/extension-drag-handle": "^3.17.0",
|
|
47
|
+
"@tiptap/pm": "^3.17.0",
|
|
48
|
+
"@tiptap/vue-3": "^3.17.0"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "tsup",
|
package/src/DragHandle.ts
CHANGED
|
@@ -1,20 +1,31 @@
|
|
|
1
|
-
import type { DragHandlePluginProps } from '@tiptap/extension-drag-handle'
|
|
1
|
+
import type { DragHandlePluginProps, NestedOptions } from '@tiptap/extension-drag-handle'
|
|
2
2
|
import {
|
|
3
3
|
defaultComputePositionConfig,
|
|
4
4
|
DragHandlePlugin,
|
|
5
5
|
dragHandlePluginDefaultKey,
|
|
6
|
+
normalizeNestedOptions,
|
|
6
7
|
} from '@tiptap/extension-drag-handle'
|
|
7
8
|
import type { Node } from '@tiptap/pm/model'
|
|
8
9
|
import type { Plugin, PluginKey } from '@tiptap/pm/state'
|
|
9
10
|
import type { Editor } from '@tiptap/vue-3'
|
|
10
11
|
import type { PropType } from 'vue'
|
|
11
|
-
import { defineComponent, h, nextTick, onBeforeUnmount, onMounted, ref, shallowRef } from 'vue'
|
|
12
|
+
import { defineComponent, h, nextTick, onBeforeUnmount, onMounted, ref, shallowRef, watch } from 'vue'
|
|
12
13
|
|
|
13
14
|
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>
|
|
14
15
|
|
|
15
|
-
export type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element'> & {
|
|
16
|
+
export type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey' | 'nestedOptions'>, 'element'> & {
|
|
16
17
|
class?: string
|
|
17
18
|
onNodeChange?: (data: { node: Node | null; editor: Editor; pos: number }) => void
|
|
19
|
+
/**
|
|
20
|
+
* Enable drag handles for nested content (list items, blockquotes, etc.).
|
|
21
|
+
*
|
|
22
|
+
* When enabled, the drag handle will appear for nested blocks, not just
|
|
23
|
+
* top-level blocks. A rule-based scoring system determines which node
|
|
24
|
+
* to target based on cursor position and configured rules.
|
|
25
|
+
*
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
nested?: boolean | NestedOptions
|
|
18
29
|
}
|
|
19
30
|
|
|
20
31
|
export const DragHandle = defineComponent({
|
|
@@ -55,16 +66,20 @@ export const DragHandle = defineComponent({
|
|
|
55
66
|
type: String as PropType<DragHandleProps['class']>,
|
|
56
67
|
default: 'drag-handle',
|
|
57
68
|
},
|
|
69
|
+
|
|
70
|
+
nested: {
|
|
71
|
+
type: [Boolean, Object] as PropType<DragHandleProps['nested']>,
|
|
72
|
+
default: false,
|
|
73
|
+
},
|
|
58
74
|
},
|
|
59
75
|
|
|
60
76
|
setup(props, { slots }) {
|
|
61
77
|
const root = ref<HTMLElement | null>(null)
|
|
62
78
|
const pluginHandle = shallowRef<{ plugin: Plugin; unbind: () => void } | null>(null)
|
|
63
79
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const { editor, pluginKey, onNodeChange, onElementDragEnd, onElementDragStart, computePositionConfig } = props
|
|
80
|
+
const initPlugin = () => {
|
|
81
|
+
const { editor, pluginKey, onNodeChange, onElementDragEnd, onElementDragStart, computePositionConfig, nested } =
|
|
82
|
+
props
|
|
68
83
|
|
|
69
84
|
if (!root.value) {
|
|
70
85
|
return
|
|
@@ -73,6 +88,8 @@ export const DragHandle = defineComponent({
|
|
|
73
88
|
return
|
|
74
89
|
}
|
|
75
90
|
|
|
91
|
+
const nestedOptions = normalizeNestedOptions(nested)
|
|
92
|
+
|
|
76
93
|
const init = DragHandlePlugin({
|
|
77
94
|
editor,
|
|
78
95
|
element: root.value,
|
|
@@ -81,13 +98,14 @@ export const DragHandle = defineComponent({
|
|
|
81
98
|
onNodeChange,
|
|
82
99
|
onElementDragStart,
|
|
83
100
|
onElementDragEnd,
|
|
101
|
+
nestedOptions,
|
|
84
102
|
})
|
|
85
103
|
|
|
86
104
|
pluginHandle.value = init
|
|
87
105
|
props.editor.registerPlugin(init.plugin)
|
|
88
|
-
}
|
|
106
|
+
}
|
|
89
107
|
|
|
90
|
-
|
|
108
|
+
const destroyPlugin = () => {
|
|
91
109
|
if (!pluginHandle.value) {
|
|
92
110
|
return
|
|
93
111
|
}
|
|
@@ -98,6 +116,25 @@ export const DragHandle = defineComponent({
|
|
|
98
116
|
|
|
99
117
|
pluginHandle.value.unbind?.()
|
|
100
118
|
pluginHandle.value = null
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
onMounted(async () => {
|
|
122
|
+
await nextTick()
|
|
123
|
+
initPlugin()
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
// Reinitialize plugin when nested option changes
|
|
127
|
+
watch(
|
|
128
|
+
() => props.nested,
|
|
129
|
+
() => {
|
|
130
|
+
destroyPlugin()
|
|
131
|
+
initPlugin()
|
|
132
|
+
},
|
|
133
|
+
{ deep: true },
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
onBeforeUnmount(() => {
|
|
137
|
+
destroyPlugin()
|
|
101
138
|
})
|
|
102
139
|
|
|
103
140
|
return () =>
|