forked from ueberdosis/tiptap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDragHandle.ts
More file actions
77 lines (64 loc) · 1.84 KB
/
DragHandle.ts
File metadata and controls
77 lines (64 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import type { Editor } from '@tiptap/core'
import {
type DragHandlePluginProps,
defaultComputePositionConfig,
DragHandlePlugin,
dragHandlePluginDefaultKey,
} from '@tiptap/extension-drag-handle'
import Vue, { type PropType } from 'vue'
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>
export type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element'> & {
class?: string
onNodeChange?: (data: { node: Node | null; editor: Editor; pos: number }) => void
}
export const DragHandle = Vue.extend({
name: 'DragHandleVue',
props: {
pluginKey: {
type: [String, Object] as PropType<DragHandleProps['pluginKey']>,
default: () => dragHandlePluginDefaultKey,
},
editor: {
type: Object as PropType<DragHandleProps['editor']>,
required: true,
},
computePositionConfig: {
type: Object as PropType<DragHandleProps['computePositionConfig']>,
default: () => ({}),
},
onNodeChange: {
type: Function as PropType<DragHandleProps['onNodeChange']>,
default: null,
},
class: {
type: String as PropType<DragHandleProps['class']>,
default: 'drag-handle',
},
},
mounted() {
const { editor, pluginKey, onNodeChange } = this.$props
editor.registerPlugin(
DragHandlePlugin({
editor,
element: this.$el as HTMLElement,
pluginKey,
computePositionConfig: { ...defaultComputePositionConfig, ...this.computePositionConfig },
onNodeChange,
}).plugin,
)
},
// eslint-disable-next-line vue/no-deprecated-destroyed-lifecycle
beforeDestroy() {
const { pluginKey, editor } = this.$props
editor.unregisterPlugin(pluginKey as string)
},
render(h) {
return h(
'div',
{
class: this.class,
},
this.$slots.default,
)
},
})