Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/dirty-mugs-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@tiptap/extension-drag-handle': minor
'@tiptap/extension-drag-handle-vue-2': minor
'@tiptap/extension-drag-handle-vue-3': minor
---

Expose `onElementDragStart` and `onElementDragEnd` callbacks from DragHandlePlugin.
14 changes: 13 additions & 1 deletion packages/extension-drag-handle-vue-2/src/DragHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,24 @@ export const DragHandle = Vue.extend({
default: null,
},

onElementDragStart: {
type: Function as PropType<DragHandleProps['onElementDragStart']>,
default: undefined,
},

onElementDragEnd: {
type: Function as PropType<DragHandleProps['onElementDragEnd']>,
default: undefined,
},

class: {
type: String as PropType<DragHandleProps['class']>,
default: 'drag-handle',
},
},

mounted() {
const { editor, pluginKey, onNodeChange } = this.$props
const { editor, pluginKey, onNodeChange, onElementDragStart, onElementDragEnd } = this.$props

editor.registerPlugin(
DragHandlePlugin({
Expand All @@ -54,6 +64,8 @@ export const DragHandle = Vue.extend({
pluginKey,
computePositionConfig: { ...defaultComputePositionConfig, ...this.computePositionConfig },
onNodeChange,
onElementDragStart,
onElementDragEnd,
}).plugin,
)
},
Expand Down
14 changes: 13 additions & 1 deletion packages/extension-drag-handle-vue-3/src/DragHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ export const DragHandle = defineComponent({
default: null,
},

onElementDragStart: {
type: Function as PropType<DragHandleProps['onElementDragStart']>,
default: undefined,
},

onElementDragEnd: {
type: Function as PropType<DragHandleProps['onElementDragEnd']>,
default: undefined,
},

class: {
type: String as PropType<DragHandleProps['class']>,
default: 'drag-handle',
Expand All @@ -49,7 +59,7 @@ export const DragHandle = defineComponent({
const root = ref<HTMLElement | null>(null)

onMounted(() => {
const { editor, pluginKey, onNodeChange, computePositionConfig } = props
const { editor, pluginKey, onNodeChange, computePositionConfig, onElementDragStart, onElementDragEnd } = props

editor.registerPlugin(
DragHandlePlugin({
Expand All @@ -58,6 +68,8 @@ export const DragHandle = defineComponent({
pluginKey,
computePositionConfig: { ...defaultComputePositionConfig, ...computePositionConfig },
onNodeChange,
onElementDragStart,
onElementDragEnd,
}).plugin,
)
})
Expand Down
12 changes: 12 additions & 0 deletions packages/extension-drag-handle/src/drag-handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ export interface DragHandleOptions {
* Returns a node or null when a node is hovered over
*/
onNodeChange?: (options: { node: Node | null; editor: Editor }) => void
/**
* The callback function that will be called when drag start.
*/
onElementDragStart?: (e: DragEvent) => void
/**
* The callback function that will be called when drag end.
*/
onElementDragEnd?: (e: DragEvent) => void
}

declare module '@tiptap/core' {
Expand Down Expand Up @@ -65,6 +73,8 @@ export const DragHandle = Extension.create<DragHandleOptions>({
onNodeChange: () => {
return null
},
onElementDragStart: undefined,
onElementDragEnd: undefined,
}
},

Expand Down Expand Up @@ -100,6 +110,8 @@ export const DragHandle = Extension.create<DragHandleOptions>({
element,
editor: this.editor,
onNodeChange: this.options.onNodeChange,
onElementDragStart: this.options.onElementDragStart,
onElementDragEnd: this.options.onElementDragEnd,
}).plugin,
]
},
Expand Down