{"version":3,"sources":["jsdelivr-header.js","/npm/prosemirror-drop-indicator@0.1.3/src/drop-target.ts","/npm/prosemirror-drop-indicator@0.1.3/src/drop-indicator-plugin.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,qHCUA,SAAS,iBAAiB,GAExB,IAAI,EAAqB,CAAC,EAAC,EAAI,EAAK,MAAM,MACtC,EAAwB,GAE5B,KAAO,EAAM,OAAS,GAAG,CACvB,MAAO,EAAK,GAAQ,EAAM,MAC1B,GAAI,GAAO,EAAG,CACZ,IAAI,EAAM,EAAK,QAAQ,GACvB,GAAI,GAAO,cAAc,GAAM,CAE7B,IAAI,IAAE,EAAA,OAAK,EAAQ,KAAM,EAAI,MAAO,GADzB,EAAI,wBAEf,EAAQ,KACN,CAAC,EAAK,CAAC,EAAI,EAAK,EAAI,IACpB,CAAC,EAAM,EAAK,SAAU,CAAC,EAAI,EAAQ,EAAI,I,EAI7C,GAAI,EAAK,UAAY,EAAK,YAAa,CACrC,IAAI,EAAW,EAAM,EACrB,IAAK,IAAI,KAAS,EAAK,SACrB,EAAM,KAAK,CAAC,EAAU,IACtB,GAAY,EAAM,Q,EAKxB,OAAO,C,CAcT,SAAgB,eACd,EACA,GAEA,IACI,EACA,EAFA,EAA4B,GAIhC,MAuBM,GAA4B,EAAO,KACvC,IAAK,EAAK,UAAY,EAAK,YACzB,OAYF,IAAI,EArCA,MACJ,MAAM,EAAO,EAAK,IAAI,wBAChB,EAAM,EAAK,MAAM,IAEvB,OACE,GACA,GACA,GACA,EAAK,QAAU,EAAS,OACxB,EAAK,SAAW,EAAS,QACzB,EAAK,IAAM,EAAS,GACpB,EAAK,IAAM,EAAS,GACpB,EAAQ,GAAG,KAKb,EAAW,EACX,EAAU,EACV,EAAc,iBAAiB,IALtB,CAMF,EAiBO,GACd,EAAQ,MAVF,CAAW,EAAgB,KAC/B,MAAO,EAAM,GAAS,GACf,EAAM,GAAS,EAItB,OAHmB,kBAAkB,EAAO,GACzB,kB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EAER,IAAI,EAAS,EAAU,CAAC,EAAS,GAAU,GAE3C,GAAK,EAGE,CACL,MAAO,GAAM,EAAI,EAAI,EAAI,IAAO,EAC1B,EAAO,CAAE,GAAI,CAAE,EAAG,EAAI,EAAG,GAAM,GAAI,CAAE,EAAG,EAAI,EAAG,IACrD,EAAQ,SAAS,CAAE,OAAM,MAAK,Q,MAL9B,G,EASJ,EAAI,iBAAiB,WAAY,GACjC,EAAI,iBAAiB,UAAW,GAChC,EAAI,iBAAiB,OAAQ,GAC7B,EAAI,iBAAiB,YAAa,GASlC,MAAO,CAAE,QAPH,KACJ,EAAI,oBAAoB,WAAY,GACpC,EAAI,oBAAoB,UAAW,GACnC,EAAI,oBAAoB,OAAQ,GAChC,EAAI,oBAAoB,YAAa,EAAa,E","file":"/npm/prosemirror-drop-indicator@0.1.3/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/prosemirror-drop-indicator@0.1.3/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import { isHTMLElement } from '@ocavue/utils'\nimport type { Node as ProseMirrorNode } from 'prosemirror-model'\nimport { NodeSelection } from 'prosemirror-state'\nimport type { EditorView } from 'prosemirror-view'\n\nimport type { DragEventHandler } from './types'\n\ntype Point = readonly [x: number, y: number]\n\ntype Line = readonly [x1: number, y1: number, x2: number, y2: number]\n\n/**\n * @internal\n */\ntype DropTarget = readonly [pos: number, line: Line]\n\nfunction getTargetsByView(view: EditorView): DropTarget[] {\n  type StackItem = [pos: number, node: ProseMirrorNode]\n  let stack: StackItem[] = [[-1, view.state.doc]]\n  let targets: DropTarget[] = []\n\n  while (stack.length > 0) {\n    const [pos, node] = stack.pop()!\n    if (pos >= 0) {\n      let dom = view.nodeDOM(pos)\n      if (dom && isHTMLElement(dom)) {\n        let rect = dom.getBoundingClientRect()\n        let { top, bottom, left: x1, right: x2 } = rect\n        targets.push(\n          [pos, [x1, top, x2, top]],\n          [pos + node.nodeSize, [x1, bottom, x2, bottom]],\n        )\n      }\n    }\n    if (node.isBlock && !node.isTextblock) {\n      let childPos = pos + 1\n      for (let child of node.children) {\n        stack.push([childPos, child])\n        childPos += child.nodeSize\n      }\n    }\n  }\n\n  return targets\n}\n\n/**\n * @internal\n */\nexport type GetTarget = (\n  point: Point,\n  event: DragEvent,\n) => DropTarget | undefined\n\n/**\n * @internal\n */\nexport function buildGetTarget(\n  view: EditorView,\n  onDrag?: DragEventHandler,\n): GetTarget {\n  let prevTargets: DropTarget[] = []\n  let prevDoc: ProseMirrorNode | undefined\n  let prevRect: DOMRect | undefined\n\n  const getTargets = (): DropTarget[] => {\n    const rect = view.dom.getBoundingClientRect()\n    const doc = view.state.doc\n\n    if (\n      prevTargets &&\n      prevDoc &&\n      prevRect &&\n      rect.width === prevRect.width &&\n      rect.height === prevRect.height &&\n      rect.x === prevRect.x &&\n      rect.y === prevRect.y &&\n      prevDoc.eq(doc)\n    ) {\n      return prevTargets\n    }\n\n    prevRect = rect\n    prevDoc = doc\n    prevTargets = getTargetsByView(view)\n    return prevTargets\n  }\n\n  const getTargetImpl: GetTarget = (point, event) => {\n    if (!view.editable || view.isDestroyed) {\n      return\n    }\n\n    const compare = (p1: DropTarget, p2: DropTarget): number => {\n      const [pos1, line1] = p1\n      const [pos2, line2] = p2\n      const p1Distance = pointLineDistance(point, line1)\n      const p2Distance = pointLineDistance(point, line2)\n\n      return p1Distance - p2Distance || pos1 - pos2\n    }\n\n    let targets = getTargets()\n    targets.sort(compare)\n\n    // Only consider the first few targets for performance reasons.\n    targets = targets.slice(0, 8)\n\n    // Find the closest valid target.\n    const target = targets.find(\n      (target) => onDrag?.({ view, pos: target[0], event }) !== false,\n    )\n\n    // If the dragging node is already at the target position, we ignore this\n    // target. Notice that we don't pick the second better target here.\n    if (target && isDraggingToItself(view, target[0])) {\n      return undefined\n    }\n\n    return target\n  }\n\n  let prevPoint: Point | undefined\n  let prevTarget: DropTarget | undefined\n\n  const getTargetCached: GetTarget = (point, event) => {\n    if (prevPoint && pointEqual(prevPoint, point)) {\n      return prevTarget\n    }\n\n    prevPoint = point\n    prevTarget = getTargetImpl(point, event)\n    return prevTarget\n  }\n\n  return getTargetCached\n}\n\nfunction pointEqual(a: Point, b: Point) {\n  return a[0] === b[0] && a[1] === b[1]\n}\n\nfunction pointPointDistance(a: Point, b: Point) {\n  // Manhattan distance\n  return Math.abs(a[0] - b[0]) + Math.abs(a[1] - b[1])\n}\n\nfunction pointLineDistance(point: Point, line: Line) {\n  // Notice that we are actually not calculating the distance between the point\n  // and the line. Instead, we are calculating the distance between the point\n  // and the two endpoints of the line.\n  return Math.min(\n    pointPointDistance(point, [line[0], line[1]]),\n    pointPointDistance(point, [line[2], line[3]]),\n  )\n}\n\n/**\n * Whether the dragging node is being dragged to the same position. For example,\n * dragging a list node into a new position that is just below the list node, or\n * dragging a nested quoteblock into itself.\n */\nfunction isDraggingToItself(view: EditorView, pos: number) {\n  const dragging = view.dragging\n  if (!dragging) return\n\n  const { move } = dragging\n  if (!move) return\n\n  const selection = view.state.selection\n  if (!(selection instanceof NodeSelection)) return\n\n  const { from, to } = selection\n  return from <= pos && pos <= to\n}\n","import type { ResolvedPos } from 'prosemirror-model'\nimport {\n  NodeSelection,\n  Plugin,\n  PluginKey,\n  TextSelection,\n  type PluginView,\n} from 'prosemirror-state'\nimport type { EditorView } from 'prosemirror-view'\n\nimport { buildGetTarget, type GetTarget } from './drop-target'\nimport type { DragEventHandler, ShowHandler, ViewDragging } from './types'\n\n/**\n * @public\n */\nexport interface DropIndicatorPluginOptions {\n  /**\n   * A callback that is called when the drop indicator should be shown.\n   */\n  onShow?: ShowHandler\n\n  /**\n   * A callback that is called when the drop indicator should be hidden.\n   */\n  onHide?: VoidFunction\n\n  /**\n   * A callback that is called when the `dragover` event is fired. You can\n   * return `false` to disable the current drop point and thus hide the drop\n   * indicator.\n   */\n  onDrag?: DragEventHandler\n}\n\n/**\n * @public\n *\n * @param options - The options for the drop indicator plugin.\n */\nexport function createDropIndicatorPlugin(\n  options: DropIndicatorPluginOptions,\n): Plugin {\n  let getTarget: GetTarget | undefined\n\n  return new Plugin({\n    key: new PluginKey('prosekit-drop-indicator'),\n    view: (view) => {\n      getTarget = buildGetTarget(view, options.onDrag)\n      return createDropIndicatorView(view, getTarget, options)\n    },\n    props: {\n      handleDrop(view, event, slice, move): boolean {\n        if (!getTarget) return false\n\n        const target = getTarget([event.clientX, event.clientY], event)\n\n        if (!target) return false\n\n        event.preventDefault()\n        let insertPos = target[0]\n\n        let tr = view.state.tr\n        if (move) {\n          let { node } = (view.dragging as ViewDragging | null) || {}\n          if (node) node.replace(tr)\n          else tr.deleteSelection()\n        }\n\n        let pos = tr.mapping.map(insertPos)\n        let isNode =\n          slice.openStart == 0 &&\n          slice.openEnd == 0 &&\n          slice.content.childCount == 1\n        let beforeInsert = tr.doc\n        if (isNode) tr.replaceRangeWith(pos, pos, slice.content.firstChild!)\n        else tr.replaceRange(pos, pos, slice)\n        if (tr.doc.eq(beforeInsert)) {\n          return true\n        }\n\n        let $pos = tr.doc.resolve(pos)\n        if (\n          isNode &&\n          NodeSelection.isSelectable(slice.content.firstChild!) &&\n          $pos.nodeAfter &&\n          $pos.nodeAfter.sameMarkup(slice.content.firstChild!)\n        ) {\n          tr.setSelection(new NodeSelection($pos))\n        } else {\n          let end = tr.mapping.map(insertPos)\n          tr.mapping.maps[tr.mapping.maps.length - 1].forEach(\n            (_from, _to, _newFrom, newTo) => (end = newTo),\n          )\n          tr.setSelection(selectionBetween(view, $pos, tr.doc.resolve(end)))\n        }\n        view.focus()\n        view.dispatch(tr.setMeta('uiEvent', 'drop'))\n        return true\n      },\n    },\n  })\n}\n\nfunction selectionBetween(\n  view: EditorView,\n  $anchor: ResolvedPos,\n  $head: ResolvedPos,\n  bias?: number,\n) {\n  return (\n    view.someProp('createSelectionBetween', (f) => f(view, $anchor, $head)) ||\n    TextSelection.between($anchor, $head, bias)\n  )\n}\n\nfunction createDropIndicatorView(\n  view: EditorView,\n  getTarget: GetTarget,\n  options: DropIndicatorPluginOptions,\n): PluginView {\n  let dom = view.dom\n  let hideId: ReturnType<typeof setTimeout> | undefined\n  let prevX: number | undefined\n  let prevY: number | undefined\n  let hasDragOverEvent: boolean = false\n\n  const scheduleHide = () => {\n    if (hideId) {\n      clearTimeout(hideId)\n    }\n\n    hasDragOverEvent = false\n    hideId = setTimeout(() => {\n      if (hasDragOverEvent) return\n      options.onHide?.()\n    }, 30)\n  }\n\n  const handleDragOver = (event: DragEvent): void => {\n    hasDragOverEvent = true\n\n    const { clientX, clientY } = event\n    if (prevX === clientX && prevY === clientY) {\n      return\n    }\n    prevX = clientX\n    prevY = clientY\n\n    let target = getTarget([clientX, clientY], event)\n\n    if (!target) {\n      scheduleHide()\n      return\n    } else {\n      const [pos, [x1, y1, x2, y2]] = target\n      const line = { p1: { x: x1, y: y1 }, p2: { x: x2, y: y2 } }\n      options.onShow?.({ view, pos, line })\n    }\n  }\n\n  dom.addEventListener('dragover', handleDragOver)\n  dom.addEventListener('dragend', scheduleHide)\n  dom.addEventListener('drop', scheduleHide)\n  dom.addEventListener('dragleave', scheduleHide)\n\n  const destroy = () => {\n    dom.removeEventListener('dragover', handleDragOver)\n    dom.removeEventListener('dragend', scheduleHide)\n    dom.removeEventListener('drop', scheduleHide)\n    dom.removeEventListener('dragleave', scheduleHide)\n  }\n\n  return { destroy }\n}\n"]}