@tiptap/extension-drag-handle-vue-3 3.8.0 → 3.9.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 +38 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +46 -29
- package/dist/index.d.ts +46 -29
- package/dist/index.js +39 -14
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/DragHandle.ts +48 -16
package/dist/index.cjs
CHANGED
|
@@ -47,6 +47,14 @@ var DragHandle = (0, import_vue.defineComponent)({
|
|
|
47
47
|
type: Function,
|
|
48
48
|
default: null
|
|
49
49
|
},
|
|
50
|
+
onElementDragStart: {
|
|
51
|
+
type: Function,
|
|
52
|
+
default: null
|
|
53
|
+
},
|
|
54
|
+
onElementDragEnd: {
|
|
55
|
+
type: Function,
|
|
56
|
+
default: null
|
|
57
|
+
},
|
|
50
58
|
class: {
|
|
51
59
|
type: String,
|
|
52
60
|
default: "drag-handle"
|
|
@@ -54,21 +62,38 @@ var DragHandle = (0, import_vue.defineComponent)({
|
|
|
54
62
|
},
|
|
55
63
|
setup(props, { slots }) {
|
|
56
64
|
const root = (0, import_vue.ref)(null);
|
|
57
|
-
(0, import_vue.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
)
|
|
65
|
+
const pluginHandle = (0, import_vue.shallowRef)(null);
|
|
66
|
+
(0, import_vue.onMounted)(async () => {
|
|
67
|
+
await (0, import_vue.nextTick)();
|
|
68
|
+
const { editor, pluginKey, onNodeChange, onElementDragEnd, onElementDragStart, computePositionConfig } = props;
|
|
69
|
+
if (!root.value) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (!props.editor || props.editor.isDestroyed) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const init = (0, import_extension_drag_handle.DragHandlePlugin)({
|
|
76
|
+
editor,
|
|
77
|
+
element: root.value,
|
|
78
|
+
pluginKey,
|
|
79
|
+
computePositionConfig: { ...import_extension_drag_handle.defaultComputePositionConfig, ...computePositionConfig },
|
|
80
|
+
onNodeChange,
|
|
81
|
+
onElementDragStart,
|
|
82
|
+
onElementDragEnd
|
|
83
|
+
});
|
|
84
|
+
pluginHandle.value = init;
|
|
85
|
+
props.editor.registerPlugin(init.plugin);
|
|
68
86
|
});
|
|
69
87
|
(0, import_vue.onBeforeUnmount)(() => {
|
|
70
|
-
|
|
71
|
-
|
|
88
|
+
var _a, _b;
|
|
89
|
+
if (!pluginHandle.value) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (props.editor && !props.editor.isDestroyed) {
|
|
93
|
+
props.editor.unregisterPlugin(props.pluginKey);
|
|
94
|
+
}
|
|
95
|
+
(_b = (_a = pluginHandle.value).unbind) == null ? void 0 : _b.call(_a);
|
|
96
|
+
pluginHandle.value = null;
|
|
72
97
|
});
|
|
73
98
|
return () => {
|
|
74
99
|
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 { Editor } from '@tiptap/vue-3'\nimport type { PropType } from 'vue'\nimport { defineComponent, h, onBeforeUnmount, onMounted, ref } 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<
|
|
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 onMounted(async () => {\n await nextTick()\n\n const { editor, pluginKey, onNodeChange, onElementDragEnd, onElementDragStart, computePositionConfig } = props\n\n if (!root.value) {\n return\n }\n if (!props.editor || props.editor.isDestroyed) {\n return\n }\n\n const init = DragHandlePlugin({\n editor,\n element: root.value,\n pluginKey,\n computePositionConfig: { ...defaultComputePositionConfig, ...computePositionConfig },\n onNodeChange,\n onElementDragStart,\n onElementDragEnd,\n })\n\n pluginHandle.value = init\n props.editor.registerPlugin(init.plugin)\n })\n\n onBeforeUnmount(() => {\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 return () =>\n h(\n 'div',\n {\n ref: root,\n class: props.class,\n style: { visibility: 'hidden', position: 'absolute' },\n },\n slots.default?.(),\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,mCAIO;AAKP,iBAA0F;AASnF,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,EACF;AAAA,EAEA,MAAM,OAAO,EAAE,MAAM,GAAG;AACtB,UAAM,WAAO,gBAAwB,IAAI;AACzC,UAAM,mBAAe,uBAA0D,IAAI;AAEnF,8BAAU,YAAY;AACpB,gBAAM,qBAAS;AAEf,YAAM,EAAE,QAAQ,WAAW,cAAc,kBAAkB,oBAAoB,sBAAsB,IAAI;AAEzG,UAAI,CAAC,KAAK,OAAO;AACf;AAAA,MACF;AACA,UAAI,CAAC,MAAM,UAAU,MAAM,OAAO,aAAa;AAC7C;AAAA,MACF;AAEA,YAAM,WAAO,+CAAiB;AAAA,QAC5B;AAAA,QACA,SAAS,KAAK;AAAA,QACd;AAAA,QACA,uBAAuB,EAAE,GAAG,2DAA8B,GAAG,sBAAsB;AAAA,QACnF;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAED,mBAAa,QAAQ;AACrB,YAAM,OAAO,eAAe,KAAK,MAAM;AAAA,IACzC,CAAC;AAED,oCAAgB,MAAM;AAzF1B;AA0FM,UAAI,CAAC,aAAa,OAAO;AACvB;AAAA,MACF;AAEA,UAAI,MAAM,UAAU,CAAC,MAAM,OAAO,aAAa;AAC7C,cAAM,OAAO,iBAAiB,MAAM,SAAS;AAAA,MAC/C;AAEA,+BAAa,OAAM,WAAnB;AACA,mBAAa,QAAQ;AAAA,IACvB,CAAC;AAED,WAAO,MAAG;AAtGd;AAuGM;AAAA,QACE;AAAA,QACA;AAAA,UACE,KAAK;AAAA,UACL,OAAO,MAAM;AAAA,UACb,OAAO,EAAE,YAAY,UAAU,UAAU,WAAW;AAAA,QACtD;AAAA,SACA,WAAM,YAAN;AAAA,MACF;AAAA;AAAA,EACJ;AACF,CAAC;;;AD7GD,IAAO,gBAAQ;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import * as _floating_ui_dom from '@floating-ui/dom';
|
|
2
|
-
import { Node as Node$3 } from 'prosemirror-model';
|
|
3
2
|
import { Plugin, PluginKey, Transaction, EditorState } from '@tiptap/pm/state';
|
|
4
|
-
import { NodeType as NodeType$1, MarkType as MarkType$1, Node as Node$
|
|
3
|
+
import { NodeType as NodeType$1, MarkType as MarkType$1, Node as Node$1, Fragment, ParseOptions, Schema, Slice, Mark as Mark$1, ResolvedPos, MarkSpec, DOMOutputSpec, NodeSpec } from '@tiptap/pm/model';
|
|
5
4
|
import { EditorView, EditorProps, NodeViewConstructor, MarkViewConstructor, NodeView, MarkView } from '@tiptap/pm/view';
|
|
6
5
|
import { Transform } from '@tiptap/pm/transform';
|
|
7
6
|
import * as vue from 'vue';
|
|
8
7
|
import { PropType } from 'vue';
|
|
9
|
-
import { PluginKey as PluginKey$1 } from 'prosemirror-state';
|
|
10
8
|
import { DragHandlePluginProps } from '@tiptap/extension-drag-handle';
|
|
11
9
|
import { Editor as Editor$1 } from '@tiptap/vue-3';
|
|
12
10
|
|
|
@@ -425,7 +423,7 @@ interface NodeConfig<Options = any, Storage = any> extends ExtendableConfig<Opti
|
|
|
425
423
|
parent: ParentConfig<NodeConfig<Options, Storage>>['renderHTML'];
|
|
426
424
|
editor?: Editor;
|
|
427
425
|
}, props: {
|
|
428
|
-
node: Node$
|
|
426
|
+
node: Node$1;
|
|
429
427
|
HTMLAttributes: Record<string, any>;
|
|
430
428
|
}) => DOMOutputSpec) | null;
|
|
431
429
|
/**
|
|
@@ -439,9 +437,9 @@ interface NodeConfig<Options = any, Storage = any> extends ExtendableConfig<Opti
|
|
|
439
437
|
parent: ParentConfig<NodeConfig<Options, Storage>>['renderText'];
|
|
440
438
|
editor?: Editor;
|
|
441
439
|
}, props: {
|
|
442
|
-
node: Node$
|
|
440
|
+
node: Node$1;
|
|
443
441
|
pos: number;
|
|
444
|
-
parent: Node$
|
|
442
|
+
parent: Node$1;
|
|
445
443
|
index: number;
|
|
446
444
|
}) => string) | null;
|
|
447
445
|
/**
|
|
@@ -460,21 +458,21 @@ interface NodeConfig<Options = any, Storage = any> extends ExtendableConfig<Opti
|
|
|
460
458
|
* The Node class is used to create custom node extensions.
|
|
461
459
|
* @see https://tiptap.dev/api/extensions#create-a-new-extension
|
|
462
460
|
*/
|
|
463
|
-
declare class Node
|
|
461
|
+
declare class Node<Options = any, Storage = any> extends Extendable<Options, Storage, NodeConfig<Options, Storage>> {
|
|
464
462
|
type: string;
|
|
465
463
|
/**
|
|
466
464
|
* Create a new Node instance
|
|
467
465
|
* @param config - Node configuration object or a function that returns a configuration object
|
|
468
466
|
*/
|
|
469
|
-
static create<O = any, S = any>(config?: Partial<NodeConfig<O, S>> | (() => Partial<NodeConfig<O, S>>)): Node
|
|
470
|
-
configure(options?: Partial<Options>): Node
|
|
467
|
+
static create<O = any, S = any>(config?: Partial<NodeConfig<O, S>> | (() => Partial<NodeConfig<O, S>>)): Node<O, S>;
|
|
468
|
+
configure(options?: Partial<Options>): Node<Options, Storage>;
|
|
471
469
|
extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig = NodeConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: (() => Partial<ExtendedConfig>) | (Partial<ExtendedConfig> & ThisType<{
|
|
472
470
|
name: string;
|
|
473
471
|
options: ExtendedOptions;
|
|
474
472
|
storage: ExtendedStorage;
|
|
475
473
|
editor: Editor;
|
|
476
474
|
type: NodeType$1;
|
|
477
|
-
}>)): Node
|
|
475
|
+
}>)): Node<ExtendedOptions, ExtendedStorage>;
|
|
478
476
|
}
|
|
479
477
|
|
|
480
478
|
type PasteRuleMatch = {
|
|
@@ -589,7 +587,7 @@ interface ExtendableConfig<Options = any, Storage = any, Config extends Extensio
|
|
|
589
587
|
name: string;
|
|
590
588
|
options: Options;
|
|
591
589
|
storage: Storage;
|
|
592
|
-
extensions: (Node
|
|
590
|
+
extensions: (Node | Mark)[];
|
|
593
591
|
parent: ParentConfig<Config>['addGlobalAttributes'];
|
|
594
592
|
}) => GlobalAttributes;
|
|
595
593
|
/**
|
|
@@ -755,7 +753,7 @@ interface ExtendableConfig<Options = any, Storage = any, Config extends Extensio
|
|
|
755
753
|
options: Options;
|
|
756
754
|
storage: Storage;
|
|
757
755
|
parent: ParentConfig<Config>['extendNodeSchema'];
|
|
758
|
-
}, extension: Node
|
|
756
|
+
}, extension: Node) => Record<string, any>) | null;
|
|
759
757
|
/**
|
|
760
758
|
* This function extends the schema of the mark.
|
|
761
759
|
* @example
|
|
@@ -1073,7 +1071,7 @@ interface EditorEvents {
|
|
|
1073
1071
|
* The node which the deletion occurred in
|
|
1074
1072
|
* @note This can be a parent node of the deleted content
|
|
1075
1073
|
*/
|
|
1076
|
-
node: Node$
|
|
1074
|
+
node: Node$1;
|
|
1077
1075
|
/**
|
|
1078
1076
|
* The new start position of the node in the document (after the deletion)
|
|
1079
1077
|
*/
|
|
@@ -1387,7 +1385,7 @@ interface NodeViewRendererProps {
|
|
|
1387
1385
|
/**
|
|
1388
1386
|
* The extension that is responsible for the node.
|
|
1389
1387
|
*/
|
|
1390
|
-
extension: Node
|
|
1388
|
+
extension: Node;
|
|
1391
1389
|
/**
|
|
1392
1390
|
* The HTML attributes that should be added to the node's DOM element.
|
|
1393
1391
|
*/
|
|
@@ -1443,9 +1441,9 @@ type Range = {
|
|
|
1443
1441
|
to: number;
|
|
1444
1442
|
};
|
|
1445
1443
|
type TextSerializer = (props: {
|
|
1446
|
-
node: Node$
|
|
1444
|
+
node: Node$1;
|
|
1447
1445
|
pos: number;
|
|
1448
|
-
parent: Node$
|
|
1446
|
+
parent: Node$1;
|
|
1449
1447
|
index: number;
|
|
1450
1448
|
range: Range;
|
|
1451
1449
|
}) => string;
|
|
@@ -1628,9 +1626,9 @@ declare class NodePos {
|
|
|
1628
1626
|
private isBlock;
|
|
1629
1627
|
private editor;
|
|
1630
1628
|
private get name();
|
|
1631
|
-
constructor(pos: ResolvedPos, editor: Editor, isBlock?: boolean, node?: Node$
|
|
1629
|
+
constructor(pos: ResolvedPos, editor: Editor, isBlock?: boolean, node?: Node$1 | null);
|
|
1632
1630
|
private currentNode;
|
|
1633
|
-
get node(): Node$
|
|
1631
|
+
get node(): Node$1;
|
|
1634
1632
|
get element(): HTMLElement;
|
|
1635
1633
|
actualDepth: number | null;
|
|
1636
1634
|
get depth(): number;
|
|
@@ -1967,7 +1965,7 @@ declare module '@tiptap/core' {
|
|
|
1967
1965
|
/**
|
|
1968
1966
|
* The ProseMirror content to insert.
|
|
1969
1967
|
*/
|
|
1970
|
-
value: Content | Node$
|
|
1968
|
+
value: Content | Node$1 | Fragment,
|
|
1971
1969
|
/**
|
|
1972
1970
|
* Optional options
|
|
1973
1971
|
*/
|
|
@@ -1990,7 +1988,7 @@ declare module '@tiptap/core' {
|
|
|
1990
1988
|
/**
|
|
1991
1989
|
* The ProseMirror content to insert.
|
|
1992
1990
|
*/
|
|
1993
|
-
value: Content | Node$
|
|
1991
|
+
value: Content | Node$1 | Fragment,
|
|
1994
1992
|
/**
|
|
1995
1993
|
* Optional options
|
|
1996
1994
|
*/
|
|
@@ -2258,7 +2256,7 @@ declare module '@tiptap/core' {
|
|
|
2258
2256
|
/**
|
|
2259
2257
|
* The new content.
|
|
2260
2258
|
*/
|
|
2261
|
-
content: Content | Fragment | Node$
|
|
2259
|
+
content: Content | Fragment | Node$1,
|
|
2262
2260
|
/**
|
|
2263
2261
|
* Options for `setContent`.
|
|
2264
2262
|
*/
|
|
@@ -2550,6 +2548,7 @@ declare class Editor extends EventEmitter<EditorEvents> {
|
|
|
2550
2548
|
private commandManager;
|
|
2551
2549
|
extensionManager: ExtensionManager;
|
|
2552
2550
|
private css;
|
|
2551
|
+
private className;
|
|
2553
2552
|
schema: Schema;
|
|
2554
2553
|
private editorView;
|
|
2555
2554
|
isFocused: boolean;
|
|
@@ -2725,15 +2724,15 @@ type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
|
2725
2724
|
type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element'> & {
|
|
2726
2725
|
class?: string;
|
|
2727
2726
|
onNodeChange?: (data: {
|
|
2728
|
-
node: Node | null;
|
|
2727
|
+
node: Node$1 | null;
|
|
2729
2728
|
editor: Editor$1;
|
|
2730
2729
|
pos: number;
|
|
2731
2730
|
}) => void;
|
|
2732
2731
|
};
|
|
2733
2732
|
declare const DragHandle: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
2734
2733
|
pluginKey: {
|
|
2735
|
-
type: PropType<
|
|
2736
|
-
default: PluginKey
|
|
2734
|
+
type: PropType<PluginKey | string>;
|
|
2735
|
+
default: PluginKey<any>;
|
|
2737
2736
|
};
|
|
2738
2737
|
editor: {
|
|
2739
2738
|
type: PropType<DragHandleProps["editor"]>;
|
|
@@ -2747,6 +2746,14 @@ declare const DragHandle: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
2747
2746
|
type: PropType<DragHandleProps["onNodeChange"]>;
|
|
2748
2747
|
default: null;
|
|
2749
2748
|
};
|
|
2749
|
+
onElementDragStart: {
|
|
2750
|
+
type: PropType<DragHandleProps["onElementDragStart"]>;
|
|
2751
|
+
default: null;
|
|
2752
|
+
};
|
|
2753
|
+
onElementDragEnd: {
|
|
2754
|
+
type: PropType<DragHandleProps["onElementDragEnd"]>;
|
|
2755
|
+
default: null;
|
|
2756
|
+
};
|
|
2750
2757
|
class: {
|
|
2751
2758
|
type: PropType<DragHandleProps["class"]>;
|
|
2752
2759
|
default: string;
|
|
@@ -2755,8 +2762,8 @@ declare const DragHandle: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
2755
2762
|
[key: string]: any;
|
|
2756
2763
|
}>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
2757
2764
|
pluginKey: {
|
|
2758
|
-
type: PropType<
|
|
2759
|
-
default: PluginKey
|
|
2765
|
+
type: PropType<PluginKey | string>;
|
|
2766
|
+
default: PluginKey<any>;
|
|
2760
2767
|
};
|
|
2761
2768
|
editor: {
|
|
2762
2769
|
type: PropType<DragHandleProps["editor"]>;
|
|
@@ -2770,21 +2777,31 @@ declare const DragHandle: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
2770
2777
|
type: PropType<DragHandleProps["onNodeChange"]>;
|
|
2771
2778
|
default: null;
|
|
2772
2779
|
};
|
|
2780
|
+
onElementDragStart: {
|
|
2781
|
+
type: PropType<DragHandleProps["onElementDragStart"]>;
|
|
2782
|
+
default: null;
|
|
2783
|
+
};
|
|
2784
|
+
onElementDragEnd: {
|
|
2785
|
+
type: PropType<DragHandleProps["onElementDragEnd"]>;
|
|
2786
|
+
default: null;
|
|
2787
|
+
};
|
|
2773
2788
|
class: {
|
|
2774
2789
|
type: PropType<DragHandleProps["class"]>;
|
|
2775
2790
|
default: string;
|
|
2776
2791
|
};
|
|
2777
2792
|
}>> & Readonly<{}>, {
|
|
2778
|
-
pluginKey: string | PluginKey
|
|
2793
|
+
pluginKey: string | PluginKey<any>;
|
|
2779
2794
|
onNodeChange: (((data: {
|
|
2780
2795
|
editor: Editor;
|
|
2781
|
-
node: Node$
|
|
2796
|
+
node: Node$1 | null;
|
|
2782
2797
|
pos: number;
|
|
2783
2798
|
}) => void) & ((data: {
|
|
2784
|
-
node: Node | null;
|
|
2799
|
+
node: Node$1 | null;
|
|
2785
2800
|
editor: Editor$1;
|
|
2786
2801
|
pos: number;
|
|
2787
2802
|
}) => void)) | undefined;
|
|
2803
|
+
onElementDragStart: ((e: DragEvent) => void) | undefined;
|
|
2804
|
+
onElementDragEnd: ((e: DragEvent) => void) | undefined;
|
|
2788
2805
|
computePositionConfig: {
|
|
2789
2806
|
placement?: _floating_ui_dom.Placement | undefined;
|
|
2790
2807
|
strategy?: _floating_ui_dom.Strategy | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import * as _floating_ui_dom from '@floating-ui/dom';
|
|
2
|
-
import { Node as Node$3 } from 'prosemirror-model';
|
|
3
2
|
import { Plugin, PluginKey, Transaction, EditorState } from '@tiptap/pm/state';
|
|
4
|
-
import { NodeType as NodeType$1, MarkType as MarkType$1, Node as Node$
|
|
3
|
+
import { NodeType as NodeType$1, MarkType as MarkType$1, Node as Node$1, Fragment, ParseOptions, Schema, Slice, Mark as Mark$1, ResolvedPos, MarkSpec, DOMOutputSpec, NodeSpec } from '@tiptap/pm/model';
|
|
5
4
|
import { EditorView, EditorProps, NodeViewConstructor, MarkViewConstructor, NodeView, MarkView } from '@tiptap/pm/view';
|
|
6
5
|
import { Transform } from '@tiptap/pm/transform';
|
|
7
6
|
import * as vue from 'vue';
|
|
8
7
|
import { PropType } from 'vue';
|
|
9
|
-
import { PluginKey as PluginKey$1 } from 'prosemirror-state';
|
|
10
8
|
import { DragHandlePluginProps } from '@tiptap/extension-drag-handle';
|
|
11
9
|
import { Editor as Editor$1 } from '@tiptap/vue-3';
|
|
12
10
|
|
|
@@ -425,7 +423,7 @@ interface NodeConfig<Options = any, Storage = any> extends ExtendableConfig<Opti
|
|
|
425
423
|
parent: ParentConfig<NodeConfig<Options, Storage>>['renderHTML'];
|
|
426
424
|
editor?: Editor;
|
|
427
425
|
}, props: {
|
|
428
|
-
node: Node$
|
|
426
|
+
node: Node$1;
|
|
429
427
|
HTMLAttributes: Record<string, any>;
|
|
430
428
|
}) => DOMOutputSpec) | null;
|
|
431
429
|
/**
|
|
@@ -439,9 +437,9 @@ interface NodeConfig<Options = any, Storage = any> extends ExtendableConfig<Opti
|
|
|
439
437
|
parent: ParentConfig<NodeConfig<Options, Storage>>['renderText'];
|
|
440
438
|
editor?: Editor;
|
|
441
439
|
}, props: {
|
|
442
|
-
node: Node$
|
|
440
|
+
node: Node$1;
|
|
443
441
|
pos: number;
|
|
444
|
-
parent: Node$
|
|
442
|
+
parent: Node$1;
|
|
445
443
|
index: number;
|
|
446
444
|
}) => string) | null;
|
|
447
445
|
/**
|
|
@@ -460,21 +458,21 @@ interface NodeConfig<Options = any, Storage = any> extends ExtendableConfig<Opti
|
|
|
460
458
|
* The Node class is used to create custom node extensions.
|
|
461
459
|
* @see https://tiptap.dev/api/extensions#create-a-new-extension
|
|
462
460
|
*/
|
|
463
|
-
declare class Node
|
|
461
|
+
declare class Node<Options = any, Storage = any> extends Extendable<Options, Storage, NodeConfig<Options, Storage>> {
|
|
464
462
|
type: string;
|
|
465
463
|
/**
|
|
466
464
|
* Create a new Node instance
|
|
467
465
|
* @param config - Node configuration object or a function that returns a configuration object
|
|
468
466
|
*/
|
|
469
|
-
static create<O = any, S = any>(config?: Partial<NodeConfig<O, S>> | (() => Partial<NodeConfig<O, S>>)): Node
|
|
470
|
-
configure(options?: Partial<Options>): Node
|
|
467
|
+
static create<O = any, S = any>(config?: Partial<NodeConfig<O, S>> | (() => Partial<NodeConfig<O, S>>)): Node<O, S>;
|
|
468
|
+
configure(options?: Partial<Options>): Node<Options, Storage>;
|
|
471
469
|
extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig = NodeConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: (() => Partial<ExtendedConfig>) | (Partial<ExtendedConfig> & ThisType<{
|
|
472
470
|
name: string;
|
|
473
471
|
options: ExtendedOptions;
|
|
474
472
|
storage: ExtendedStorage;
|
|
475
473
|
editor: Editor;
|
|
476
474
|
type: NodeType$1;
|
|
477
|
-
}>)): Node
|
|
475
|
+
}>)): Node<ExtendedOptions, ExtendedStorage>;
|
|
478
476
|
}
|
|
479
477
|
|
|
480
478
|
type PasteRuleMatch = {
|
|
@@ -589,7 +587,7 @@ interface ExtendableConfig<Options = any, Storage = any, Config extends Extensio
|
|
|
589
587
|
name: string;
|
|
590
588
|
options: Options;
|
|
591
589
|
storage: Storage;
|
|
592
|
-
extensions: (Node
|
|
590
|
+
extensions: (Node | Mark)[];
|
|
593
591
|
parent: ParentConfig<Config>['addGlobalAttributes'];
|
|
594
592
|
}) => GlobalAttributes;
|
|
595
593
|
/**
|
|
@@ -755,7 +753,7 @@ interface ExtendableConfig<Options = any, Storage = any, Config extends Extensio
|
|
|
755
753
|
options: Options;
|
|
756
754
|
storage: Storage;
|
|
757
755
|
parent: ParentConfig<Config>['extendNodeSchema'];
|
|
758
|
-
}, extension: Node
|
|
756
|
+
}, extension: Node) => Record<string, any>) | null;
|
|
759
757
|
/**
|
|
760
758
|
* This function extends the schema of the mark.
|
|
761
759
|
* @example
|
|
@@ -1073,7 +1071,7 @@ interface EditorEvents {
|
|
|
1073
1071
|
* The node which the deletion occurred in
|
|
1074
1072
|
* @note This can be a parent node of the deleted content
|
|
1075
1073
|
*/
|
|
1076
|
-
node: Node$
|
|
1074
|
+
node: Node$1;
|
|
1077
1075
|
/**
|
|
1078
1076
|
* The new start position of the node in the document (after the deletion)
|
|
1079
1077
|
*/
|
|
@@ -1387,7 +1385,7 @@ interface NodeViewRendererProps {
|
|
|
1387
1385
|
/**
|
|
1388
1386
|
* The extension that is responsible for the node.
|
|
1389
1387
|
*/
|
|
1390
|
-
extension: Node
|
|
1388
|
+
extension: Node;
|
|
1391
1389
|
/**
|
|
1392
1390
|
* The HTML attributes that should be added to the node's DOM element.
|
|
1393
1391
|
*/
|
|
@@ -1443,9 +1441,9 @@ type Range = {
|
|
|
1443
1441
|
to: number;
|
|
1444
1442
|
};
|
|
1445
1443
|
type TextSerializer = (props: {
|
|
1446
|
-
node: Node$
|
|
1444
|
+
node: Node$1;
|
|
1447
1445
|
pos: number;
|
|
1448
|
-
parent: Node$
|
|
1446
|
+
parent: Node$1;
|
|
1449
1447
|
index: number;
|
|
1450
1448
|
range: Range;
|
|
1451
1449
|
}) => string;
|
|
@@ -1628,9 +1626,9 @@ declare class NodePos {
|
|
|
1628
1626
|
private isBlock;
|
|
1629
1627
|
private editor;
|
|
1630
1628
|
private get name();
|
|
1631
|
-
constructor(pos: ResolvedPos, editor: Editor, isBlock?: boolean, node?: Node$
|
|
1629
|
+
constructor(pos: ResolvedPos, editor: Editor, isBlock?: boolean, node?: Node$1 | null);
|
|
1632
1630
|
private currentNode;
|
|
1633
|
-
get node(): Node$
|
|
1631
|
+
get node(): Node$1;
|
|
1634
1632
|
get element(): HTMLElement;
|
|
1635
1633
|
actualDepth: number | null;
|
|
1636
1634
|
get depth(): number;
|
|
@@ -1967,7 +1965,7 @@ declare module '@tiptap/core' {
|
|
|
1967
1965
|
/**
|
|
1968
1966
|
* The ProseMirror content to insert.
|
|
1969
1967
|
*/
|
|
1970
|
-
value: Content | Node$
|
|
1968
|
+
value: Content | Node$1 | Fragment,
|
|
1971
1969
|
/**
|
|
1972
1970
|
* Optional options
|
|
1973
1971
|
*/
|
|
@@ -1990,7 +1988,7 @@ declare module '@tiptap/core' {
|
|
|
1990
1988
|
/**
|
|
1991
1989
|
* The ProseMirror content to insert.
|
|
1992
1990
|
*/
|
|
1993
|
-
value: Content | Node$
|
|
1991
|
+
value: Content | Node$1 | Fragment,
|
|
1994
1992
|
/**
|
|
1995
1993
|
* Optional options
|
|
1996
1994
|
*/
|
|
@@ -2258,7 +2256,7 @@ declare module '@tiptap/core' {
|
|
|
2258
2256
|
/**
|
|
2259
2257
|
* The new content.
|
|
2260
2258
|
*/
|
|
2261
|
-
content: Content | Fragment | Node$
|
|
2259
|
+
content: Content | Fragment | Node$1,
|
|
2262
2260
|
/**
|
|
2263
2261
|
* Options for `setContent`.
|
|
2264
2262
|
*/
|
|
@@ -2550,6 +2548,7 @@ declare class Editor extends EventEmitter<EditorEvents> {
|
|
|
2550
2548
|
private commandManager;
|
|
2551
2549
|
extensionManager: ExtensionManager;
|
|
2552
2550
|
private css;
|
|
2551
|
+
private className;
|
|
2553
2552
|
schema: Schema;
|
|
2554
2553
|
private editorView;
|
|
2555
2554
|
isFocused: boolean;
|
|
@@ -2725,15 +2724,15 @@ type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
|
2725
2724
|
type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element'> & {
|
|
2726
2725
|
class?: string;
|
|
2727
2726
|
onNodeChange?: (data: {
|
|
2728
|
-
node: Node | null;
|
|
2727
|
+
node: Node$1 | null;
|
|
2729
2728
|
editor: Editor$1;
|
|
2730
2729
|
pos: number;
|
|
2731
2730
|
}) => void;
|
|
2732
2731
|
};
|
|
2733
2732
|
declare const DragHandle: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
2734
2733
|
pluginKey: {
|
|
2735
|
-
type: PropType<
|
|
2736
|
-
default: PluginKey
|
|
2734
|
+
type: PropType<PluginKey | string>;
|
|
2735
|
+
default: PluginKey<any>;
|
|
2737
2736
|
};
|
|
2738
2737
|
editor: {
|
|
2739
2738
|
type: PropType<DragHandleProps["editor"]>;
|
|
@@ -2747,6 +2746,14 @@ declare const DragHandle: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
2747
2746
|
type: PropType<DragHandleProps["onNodeChange"]>;
|
|
2748
2747
|
default: null;
|
|
2749
2748
|
};
|
|
2749
|
+
onElementDragStart: {
|
|
2750
|
+
type: PropType<DragHandleProps["onElementDragStart"]>;
|
|
2751
|
+
default: null;
|
|
2752
|
+
};
|
|
2753
|
+
onElementDragEnd: {
|
|
2754
|
+
type: PropType<DragHandleProps["onElementDragEnd"]>;
|
|
2755
|
+
default: null;
|
|
2756
|
+
};
|
|
2750
2757
|
class: {
|
|
2751
2758
|
type: PropType<DragHandleProps["class"]>;
|
|
2752
2759
|
default: string;
|
|
@@ -2755,8 +2762,8 @@ declare const DragHandle: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
2755
2762
|
[key: string]: any;
|
|
2756
2763
|
}>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
2757
2764
|
pluginKey: {
|
|
2758
|
-
type: PropType<
|
|
2759
|
-
default: PluginKey
|
|
2765
|
+
type: PropType<PluginKey | string>;
|
|
2766
|
+
default: PluginKey<any>;
|
|
2760
2767
|
};
|
|
2761
2768
|
editor: {
|
|
2762
2769
|
type: PropType<DragHandleProps["editor"]>;
|
|
@@ -2770,21 +2777,31 @@ declare const DragHandle: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
2770
2777
|
type: PropType<DragHandleProps["onNodeChange"]>;
|
|
2771
2778
|
default: null;
|
|
2772
2779
|
};
|
|
2780
|
+
onElementDragStart: {
|
|
2781
|
+
type: PropType<DragHandleProps["onElementDragStart"]>;
|
|
2782
|
+
default: null;
|
|
2783
|
+
};
|
|
2784
|
+
onElementDragEnd: {
|
|
2785
|
+
type: PropType<DragHandleProps["onElementDragEnd"]>;
|
|
2786
|
+
default: null;
|
|
2787
|
+
};
|
|
2773
2788
|
class: {
|
|
2774
2789
|
type: PropType<DragHandleProps["class"]>;
|
|
2775
2790
|
default: string;
|
|
2776
2791
|
};
|
|
2777
2792
|
}>> & Readonly<{}>, {
|
|
2778
|
-
pluginKey: string | PluginKey
|
|
2793
|
+
pluginKey: string | PluginKey<any>;
|
|
2779
2794
|
onNodeChange: (((data: {
|
|
2780
2795
|
editor: Editor;
|
|
2781
|
-
node: Node$
|
|
2796
|
+
node: Node$1 | null;
|
|
2782
2797
|
pos: number;
|
|
2783
2798
|
}) => void) & ((data: {
|
|
2784
|
-
node: Node | null;
|
|
2799
|
+
node: Node$1 | null;
|
|
2785
2800
|
editor: Editor$1;
|
|
2786
2801
|
pos: number;
|
|
2787
2802
|
}) => void)) | undefined;
|
|
2803
|
+
onElementDragStart: ((e: DragEvent) => void) | undefined;
|
|
2804
|
+
onElementDragEnd: ((e: DragEvent) => void) | undefined;
|
|
2788
2805
|
computePositionConfig: {
|
|
2789
2806
|
placement?: _floating_ui_dom.Placement | undefined;
|
|
2790
2807
|
strategy?: _floating_ui_dom.Strategy | undefined;
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
DragHandlePlugin,
|
|
5
5
|
dragHandlePluginDefaultKey
|
|
6
6
|
} from "@tiptap/extension-drag-handle";
|
|
7
|
-
import { defineComponent, h, onBeforeUnmount, onMounted, ref } from "vue";
|
|
7
|
+
import { defineComponent, h, nextTick, onBeforeUnmount, onMounted, ref, shallowRef } from "vue";
|
|
8
8
|
var DragHandle = defineComponent({
|
|
9
9
|
name: "DragHandleVue",
|
|
10
10
|
props: {
|
|
@@ -24,6 +24,14 @@ var DragHandle = defineComponent({
|
|
|
24
24
|
type: Function,
|
|
25
25
|
default: null
|
|
26
26
|
},
|
|
27
|
+
onElementDragStart: {
|
|
28
|
+
type: Function,
|
|
29
|
+
default: null
|
|
30
|
+
},
|
|
31
|
+
onElementDragEnd: {
|
|
32
|
+
type: Function,
|
|
33
|
+
default: null
|
|
34
|
+
},
|
|
27
35
|
class: {
|
|
28
36
|
type: String,
|
|
29
37
|
default: "drag-handle"
|
|
@@ -31,21 +39,38 @@ var DragHandle = defineComponent({
|
|
|
31
39
|
},
|
|
32
40
|
setup(props, { slots }) {
|
|
33
41
|
const root = ref(null);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
const pluginHandle = shallowRef(null);
|
|
43
|
+
onMounted(async () => {
|
|
44
|
+
await nextTick();
|
|
45
|
+
const { editor, pluginKey, onNodeChange, onElementDragEnd, onElementDragStart, computePositionConfig } = props;
|
|
46
|
+
if (!root.value) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!props.editor || props.editor.isDestroyed) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const init = DragHandlePlugin({
|
|
53
|
+
editor,
|
|
54
|
+
element: root.value,
|
|
55
|
+
pluginKey,
|
|
56
|
+
computePositionConfig: { ...defaultComputePositionConfig, ...computePositionConfig },
|
|
57
|
+
onNodeChange,
|
|
58
|
+
onElementDragStart,
|
|
59
|
+
onElementDragEnd
|
|
60
|
+
});
|
|
61
|
+
pluginHandle.value = init;
|
|
62
|
+
props.editor.registerPlugin(init.plugin);
|
|
45
63
|
});
|
|
46
64
|
onBeforeUnmount(() => {
|
|
47
|
-
|
|
48
|
-
|
|
65
|
+
var _a, _b;
|
|
66
|
+
if (!pluginHandle.value) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (props.editor && !props.editor.isDestroyed) {
|
|
70
|
+
props.editor.unregisterPlugin(props.pluginKey);
|
|
71
|
+
}
|
|
72
|
+
(_b = (_a = pluginHandle.value).unbind) == null ? void 0 : _b.call(_a);
|
|
73
|
+
pluginHandle.value = null;
|
|
49
74
|
});
|
|
50
75
|
return () => {
|
|
51
76
|
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 { Editor } from '@tiptap/vue-3'\nimport type { PropType } from 'vue'\nimport { defineComponent, h, onBeforeUnmount, onMounted, ref } 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<
|
|
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 onMounted(async () => {\n await nextTick()\n\n const { editor, pluginKey, onNodeChange, onElementDragEnd, onElementDragStart, computePositionConfig } = props\n\n if (!root.value) {\n return\n }\n if (!props.editor || props.editor.isDestroyed) {\n return\n }\n\n const init = DragHandlePlugin({\n editor,\n element: root.value,\n pluginKey,\n computePositionConfig: { ...defaultComputePositionConfig, ...computePositionConfig },\n onNodeChange,\n onElementDragStart,\n onElementDragEnd,\n })\n\n pluginHandle.value = init\n props.editor.registerPlugin(init.plugin)\n })\n\n onBeforeUnmount(() => {\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 return () =>\n h(\n 'div',\n {\n ref: root,\n class: props.class,\n style: { visibility: 'hidden', position: 'absolute' },\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,OACK;AAKP,SAAS,iBAAiB,GAAG,UAAU,iBAAiB,WAAW,KAAK,kBAAkB;AASnF,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,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,EACF;AAAA,EAEA,MAAM,OAAO,EAAE,MAAM,GAAG;AACtB,UAAM,OAAO,IAAwB,IAAI;AACzC,UAAM,eAAe,WAA0D,IAAI;AAEnF,cAAU,YAAY;AACpB,YAAM,SAAS;AAEf,YAAM,EAAE,QAAQ,WAAW,cAAc,kBAAkB,oBAAoB,sBAAsB,IAAI;AAEzG,UAAI,CAAC,KAAK,OAAO;AACf;AAAA,MACF;AACA,UAAI,CAAC,MAAM,UAAU,MAAM,OAAO,aAAa;AAC7C;AAAA,MACF;AAEA,YAAM,OAAO,iBAAiB;AAAA,QAC5B;AAAA,QACA,SAAS,KAAK;AAAA,QACd;AAAA,QACA,uBAAuB,EAAE,GAAG,8BAA8B,GAAG,sBAAsB;AAAA,QACnF;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAED,mBAAa,QAAQ;AACrB,YAAM,OAAO,eAAe,KAAK,MAAM;AAAA,IACzC,CAAC;AAED,oBAAgB,MAAM;AAzF1B;AA0FM,UAAI,CAAC,aAAa,OAAO;AACvB;AAAA,MACF;AAEA,UAAI,MAAM,UAAU,CAAC,MAAM,OAAO,aAAa;AAC7C,cAAM,OAAO,iBAAiB,MAAM,SAAS;AAAA,MAC/C;AAEA,+BAAa,OAAM,WAAnB;AACA,mBAAa,QAAQ;AAAA,IACvB,CAAC;AAED,WAAO,MAAG;AAtGd;AAuGM;AAAA,QACE;AAAA,QACA;AAAA,UACE,KAAK;AAAA,UACL,OAAO,MAAM;AAAA,UACb,OAAO,EAAE,YAAY,UAAU,UAAU,WAAW;AAAA,QACtD;AAAA,SACA,WAAM,YAAN;AAAA,MACF;AAAA;AAAA,EACJ;AACF,CAAC;;;AC7GD,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.9.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/pm": "^3.
|
|
42
|
-
"@tiptap/vue-3": "^3.
|
|
40
|
+
"@tiptap/extension-drag-handle": "^3.9.0",
|
|
41
|
+
"@tiptap/pm": "^3.9.0",
|
|
42
|
+
"@tiptap/vue-3": "^3.9.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.9.0",
|
|
47
|
+
"@tiptap/pm": "^3.9.0",
|
|
48
|
+
"@tiptap/vue-3": "^3.9.0"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "tsup",
|
package/src/DragHandle.ts
CHANGED
|
@@ -4,9 +4,11 @@ import {
|
|
|
4
4
|
DragHandlePlugin,
|
|
5
5
|
dragHandlePluginDefaultKey,
|
|
6
6
|
} from '@tiptap/extension-drag-handle'
|
|
7
|
+
import type { Node } from '@tiptap/pm/model'
|
|
8
|
+
import type { Plugin, PluginKey } from '@tiptap/pm/state'
|
|
7
9
|
import type { Editor } from '@tiptap/vue-3'
|
|
8
10
|
import type { PropType } from 'vue'
|
|
9
|
-
import { defineComponent, h, onBeforeUnmount, onMounted, ref } from 'vue'
|
|
11
|
+
import { defineComponent, h, nextTick, onBeforeUnmount, onMounted, ref, shallowRef } from 'vue'
|
|
10
12
|
|
|
11
13
|
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>
|
|
12
14
|
|
|
@@ -20,7 +22,7 @@ export const DragHandle = defineComponent({
|
|
|
20
22
|
|
|
21
23
|
props: {
|
|
22
24
|
pluginKey: {
|
|
23
|
-
type: [String, Object] as PropType<
|
|
25
|
+
type: [String, Object] as PropType<PluginKey | string>,
|
|
24
26
|
default: dragHandlePluginDefaultKey,
|
|
25
27
|
},
|
|
26
28
|
|
|
@@ -39,6 +41,16 @@ export const DragHandle = defineComponent({
|
|
|
39
41
|
default: null,
|
|
40
42
|
},
|
|
41
43
|
|
|
44
|
+
onElementDragStart: {
|
|
45
|
+
type: Function as PropType<DragHandleProps['onElementDragStart']>,
|
|
46
|
+
default: null,
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
onElementDragEnd: {
|
|
50
|
+
type: Function as PropType<DragHandleProps['onElementDragEnd']>,
|
|
51
|
+
default: null,
|
|
52
|
+
},
|
|
53
|
+
|
|
42
54
|
class: {
|
|
43
55
|
type: String as PropType<DragHandleProps['class']>,
|
|
44
56
|
default: 'drag-handle',
|
|
@@ -47,25 +59,45 @@ export const DragHandle = defineComponent({
|
|
|
47
59
|
|
|
48
60
|
setup(props, { slots }) {
|
|
49
61
|
const root = ref<HTMLElement | null>(null)
|
|
62
|
+
const pluginHandle = shallowRef<{ plugin: Plugin; unbind: () => void } | null>(null)
|
|
50
63
|
|
|
51
|
-
onMounted(() => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
editor
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
onMounted(async () => {
|
|
65
|
+
await nextTick()
|
|
66
|
+
|
|
67
|
+
const { editor, pluginKey, onNodeChange, onElementDragEnd, onElementDragStart, computePositionConfig } = props
|
|
68
|
+
|
|
69
|
+
if (!root.value) {
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
if (!props.editor || props.editor.isDestroyed) {
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const init = DragHandlePlugin({
|
|
77
|
+
editor,
|
|
78
|
+
element: root.value,
|
|
79
|
+
pluginKey,
|
|
80
|
+
computePositionConfig: { ...defaultComputePositionConfig, ...computePositionConfig },
|
|
81
|
+
onNodeChange,
|
|
82
|
+
onElementDragStart,
|
|
83
|
+
onElementDragEnd,
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
pluginHandle.value = init
|
|
87
|
+
props.editor.registerPlugin(init.plugin)
|
|
63
88
|
})
|
|
64
89
|
|
|
65
90
|
onBeforeUnmount(() => {
|
|
66
|
-
|
|
91
|
+
if (!pluginHandle.value) {
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (props.editor && !props.editor.isDestroyed) {
|
|
96
|
+
props.editor.unregisterPlugin(props.pluginKey)
|
|
97
|
+
}
|
|
67
98
|
|
|
68
|
-
|
|
99
|
+
pluginHandle.value.unbind?.()
|
|
100
|
+
pluginHandle.value = null
|
|
69
101
|
})
|
|
70
102
|
|
|
71
103
|
return () =>
|