{"version":3,"file":"index.js","names":[],"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 {\n defineComponent,\n h,\n nextTick,\n onBeforeUnmount,\n onMounted,\n ref,\n shallowRef,\n watch,\n} from 'vue'\n\ntype Optional = Pick, K> & Omit\n\nexport type DragHandleProps = Omit<\n Optional,\n 'element'\n> & {\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,\n default: dragHandlePluginDefaultKey,\n },\n\n editor: {\n type: Object as PropType,\n required: true,\n },\n\n computePositionConfig: {\n type: Object as PropType,\n default: () => ({}),\n },\n\n onNodeChange: {\n type: Function as PropType,\n default: null,\n },\n\n onElementDragStart: {\n type: Function as PropType,\n default: null,\n },\n\n onElementDragEnd: {\n type: Function as PropType,\n default: null,\n },\n\n class: {\n type: String as PropType,\n default: 'drag-handle',\n },\n\n nested: {\n type: [Boolean, Object] as PropType,\n default: false,\n },\n },\n\n setup(props, { slots }) {\n const root = ref(null)\n const pluginHandle = shallowRef<{ plugin: Plugin; unbind: () => void } | null>(null)\n\n const initPlugin = () => {\n const {\n editor,\n pluginKey,\n onNodeChange,\n onElementDragEnd,\n onElementDragStart,\n computePositionConfig,\n nested,\n } = props\n\n if (!root.value) {\n return\n }\n if (!props.editor || props.editor.isDestroyed) {\n return\n }\n\n // Set initial visibility to hidden (let the plugin control it from here)\n root.value.style.visibility = 'hidden'\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: { 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":";;;AA0CA,MAAa,aAAa,gBAAgB;CACxC,MAAM;CAEN,OAAO;EACL,WAAW;GACT,MAAM,CAAC,QAAQ,MAAM;GACrB,SAAS;EACX;EAEA,QAAQ;GACN,MAAM;GACN,UAAU;EACZ;EAEA,uBAAuB;GACrB,MAAM;GACN,gBAAgB,CAAC;EACnB;EAEA,cAAc;GACZ,MAAM;GACN,SAAS;EACX;EAEA,oBAAoB;GAClB,MAAM;GACN,SAAS;EACX;EAEA,kBAAkB;GAChB,MAAM;GACN,SAAS;EACX;EAEA,OAAO;GACL,MAAM;GACN,SAAS;EACX;EAEA,QAAQ;GACN,MAAM,CAAC,SAAS,MAAM;GACtB,SA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