@prosekit/web 0.7.3 → 0.7.5

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.
Files changed (172) hide show
  1. package/dist/{get-default-state-CIEy7xrl.js → get-default-state-BzBimBWi.js} +2 -1
  2. package/dist/get-default-state-BzBimBWi.js.map +1 -0
  3. package/dist/{get-safe-editor-view-DENm4avv.js → get-safe-editor-view-Dt9Amrcn.js} +2 -1
  4. package/dist/get-safe-editor-view-Dt9Amrcn.js.map +1 -0
  5. package/dist/{inject-style-D5jj7cme.js → inject-style-Dm6W58W3.js} +6 -9
  6. package/dist/inject-style-Dm6W58W3.js.map +1 -0
  7. package/dist/prosekit-web-autocomplete.d.ts +2 -1
  8. package/dist/prosekit-web-autocomplete.d.ts.map +1 -0
  9. package/dist/prosekit-web-autocomplete.js +9 -13
  10. package/dist/prosekit-web-autocomplete.js.map +1 -0
  11. package/dist/prosekit-web-block-handle.d.ts +2 -1
  12. package/dist/prosekit-web-block-handle.d.ts.map +1 -0
  13. package/dist/prosekit-web-block-handle.js +31 -31
  14. package/dist/prosekit-web-block-handle.js.map +1 -0
  15. package/dist/prosekit-web-drop-indicator.d.ts +2 -1
  16. package/dist/prosekit-web-drop-indicator.d.ts.map +1 -0
  17. package/dist/prosekit-web-drop-indicator.js +6 -6
  18. package/dist/prosekit-web-drop-indicator.js.map +1 -0
  19. package/dist/prosekit-web-inline-popover.d.ts +2 -1
  20. package/dist/prosekit-web-inline-popover.d.ts.map +1 -0
  21. package/dist/prosekit-web-inline-popover.js +8 -12
  22. package/dist/prosekit-web-inline-popover.js.map +1 -0
  23. package/dist/prosekit-web-popover.d.ts +2 -1
  24. package/dist/prosekit-web-popover.d.ts.map +1 -0
  25. package/dist/prosekit-web-popover.js +2 -1
  26. package/dist/prosekit-web-popover.js.map +1 -0
  27. package/dist/prosekit-web-resizable.d.ts +2 -1
  28. package/dist/prosekit-web-resizable.d.ts.map +1 -0
  29. package/dist/prosekit-web-resizable.js +5 -7
  30. package/dist/prosekit-web-resizable.js.map +1 -0
  31. package/dist/prosekit-web-table-handle.d.ts +2 -1
  32. package/dist/prosekit-web-table-handle.d.ts.map +1 -0
  33. package/dist/prosekit-web-table-handle.js +39 -72
  34. package/dist/prosekit-web-table-handle.js.map +1 -0
  35. package/dist/prosekit-web-tooltip.d.ts +2 -1
  36. package/dist/prosekit-web-tooltip.d.ts.map +1 -0
  37. package/dist/prosekit-web-tooltip.js +2 -1
  38. package/dist/prosekit-web-tooltip.js.map +1 -0
  39. package/dist/prosekit-web.js +1 -0
  40. package/dist/{use-editor-extension-Cc7ZG7uj.js → use-editor-extension-B2WuUfnd.js} +2 -1
  41. package/dist/use-editor-extension-B2WuUfnd.js.map +1 -0
  42. package/dist/{use-scrolling-BNfsQs3S.js → use-scrolling-BOvyjDvH.js} +2 -1
  43. package/dist/use-scrolling-BOvyjDvH.js.map +1 -0
  44. package/package.json +21 -21
  45. package/src/components/autocomplete/autocomplete-empty/element.gen.ts +18 -0
  46. package/src/components/autocomplete/autocomplete-empty/setup.ts +6 -0
  47. package/src/components/autocomplete/autocomplete-empty/types.ts +16 -0
  48. package/src/components/autocomplete/autocomplete-item/element.gen.ts +18 -0
  49. package/src/components/autocomplete/autocomplete-item/setup.ts +38 -0
  50. package/src/components/autocomplete/autocomplete-item/types.ts +31 -0
  51. package/src/components/autocomplete/autocomplete-list/element.gen.ts +18 -0
  52. package/src/components/autocomplete/autocomplete-list/setup.ts +140 -0
  53. package/src/components/autocomplete/autocomplete-list/types.ts +30 -0
  54. package/src/components/autocomplete/autocomplete-popover/element.gen.ts +18 -0
  55. package/src/components/autocomplete/autocomplete-popover/helpers.spec.ts +21 -0
  56. package/src/components/autocomplete/autocomplete-popover/helpers.ts +7 -0
  57. package/src/components/autocomplete/autocomplete-popover/setup.ts +185 -0
  58. package/src/components/autocomplete/autocomplete-popover/types.ts +103 -0
  59. package/src/components/autocomplete/context.ts +19 -0
  60. package/src/components/autocomplete/index.gen.ts +17 -0
  61. package/src/components/block-handle/block-handle-add/element.gen.ts +18 -0
  62. package/src/components/block-handle/block-handle-add/setup.ts +37 -0
  63. package/src/components/block-handle/block-handle-add/types.ts +26 -0
  64. package/src/components/block-handle/block-handle-draggable/element.gen.ts +18 -0
  65. package/src/components/block-handle/block-handle-draggable/set-drag-preview.ts +88 -0
  66. package/src/components/block-handle/block-handle-draggable/setup.ts +133 -0
  67. package/src/components/block-handle/block-handle-draggable/types.ts +26 -0
  68. package/src/components/block-handle/block-handle-popover/element.gen.ts +18 -0
  69. package/src/components/block-handle/block-handle-popover/pointer-move.ts +262 -0
  70. package/src/components/block-handle/block-handle-popover/setup.ts +88 -0
  71. package/src/components/block-handle/block-handle-popover/types.ts +84 -0
  72. package/src/components/block-handle/context.ts +34 -0
  73. package/src/components/block-handle/index.gen.ts +13 -0
  74. package/src/components/drop-indicator/drop-indicator/element.gen.ts +18 -0
  75. package/src/components/drop-indicator/drop-indicator/setup.ts +87 -0
  76. package/src/components/drop-indicator/drop-indicator/types.ts +34 -0
  77. package/src/components/drop-indicator/index.gen.ts +5 -0
  78. package/src/components/inline-popover/index.gen.ts +5 -0
  79. package/src/components/inline-popover/inline-popover/element.gen.ts +18 -0
  80. package/src/components/inline-popover/inline-popover/setup.ts +97 -0
  81. package/src/components/inline-popover/inline-popover/types.ts +115 -0
  82. package/src/components/inline-popover/inline-popover/virtual-selection-element.ts +75 -0
  83. package/src/components/popover/index.gen.ts +13 -0
  84. package/src/components/popover/popover-content/element.gen.ts +18 -0
  85. package/src/components/popover/popover-content/setup.ts +1 -0
  86. package/src/components/popover/popover-content/types.ts +12 -0
  87. package/src/components/popover/popover-root/element.gen.ts +18 -0
  88. package/src/components/popover/popover-root/setup.ts +1 -0
  89. package/src/components/popover/popover-root/types.ts +12 -0
  90. package/src/components/popover/popover-trigger/element.gen.ts +18 -0
  91. package/src/components/popover/popover-trigger/setup.ts +1 -0
  92. package/src/components/popover/popover-trigger/types.ts +12 -0
  93. package/src/components/resizable/context.ts +45 -0
  94. package/src/components/resizable/index.gen.ts +9 -0
  95. package/src/components/resizable/resizable-handle/calc-resize.spec.ts +280 -0
  96. package/src/components/resizable/resizable-handle/calc-resize.ts +121 -0
  97. package/src/components/resizable/resizable-handle/element.gen.ts +18 -0
  98. package/src/components/resizable/resizable-handle/setup.ts +112 -0
  99. package/src/components/resizable/resizable-handle/types.ts +32 -0
  100. package/src/components/resizable/resizable-root/element.gen.ts +18 -0
  101. package/src/components/resizable/resizable-root/setup.ts +93 -0
  102. package/src/components/resizable/resizable-root/types.ts +28 -0
  103. package/src/components/table-handle/context.ts +49 -0
  104. package/src/components/table-handle/dnd.ts +135 -0
  105. package/src/components/table-handle/hooks/use-drop.ts +94 -0
  106. package/src/components/table-handle/hooks/use-empty-image.ts +30 -0
  107. package/src/components/table-handle/index.gen.ts +37 -0
  108. package/src/components/table-handle/table-handle-column-root/element.gen.ts +18 -0
  109. package/src/components/table-handle/table-handle-column-root/setup.ts +71 -0
  110. package/src/components/table-handle/table-handle-column-root/types.ts +76 -0
  111. package/src/components/table-handle/table-handle-column-trigger/element.gen.ts +18 -0
  112. package/src/components/table-handle/table-handle-column-trigger/setup.ts +75 -0
  113. package/src/components/table-handle/table-handle-column-trigger/types.ts +23 -0
  114. package/src/components/table-handle/table-handle-drag-preview/element.gen.ts +18 -0
  115. package/src/components/table-handle/table-handle-drag-preview/render-preview.ts +80 -0
  116. package/src/components/table-handle/table-handle-drag-preview/setup.ts +67 -0
  117. package/src/components/table-handle/table-handle-drag-preview/types.ts +17 -0
  118. package/src/components/table-handle/table-handle-drag-preview/updater.ts +101 -0
  119. package/src/components/table-handle/table-handle-drop-indicator/calc-drag-over.ts +44 -0
  120. package/src/components/table-handle/table-handle-drop-indicator/element.gen.ts +18 -0
  121. package/src/components/table-handle/table-handle-drop-indicator/setup.ts +56 -0
  122. package/src/components/table-handle/table-handle-drop-indicator/types.ts +18 -0
  123. package/src/components/table-handle/table-handle-drop-indicator/updater.ts +110 -0
  124. package/src/components/table-handle/table-handle-popover-content/element.gen.ts +18 -0
  125. package/src/components/table-handle/table-handle-popover-content/setup.ts +90 -0
  126. package/src/components/table-handle/table-handle-popover-content/types.ts +40 -0
  127. package/src/components/table-handle/table-handle-popover-item/element.gen.ts +18 -0
  128. package/src/components/table-handle/table-handle-popover-item/setup.ts +23 -0
  129. package/src/components/table-handle/table-handle-popover-item/types.ts +24 -0
  130. package/src/components/table-handle/table-handle-root/element.gen.ts +18 -0
  131. package/src/components/table-handle/table-handle-root/setup.ts +93 -0
  132. package/src/components/table-handle/table-handle-root/types.ts +26 -0
  133. package/src/components/table-handle/table-handle-row-root/element.gen.ts +18 -0
  134. package/src/components/table-handle/table-handle-row-root/setup.ts +77 -0
  135. package/src/components/table-handle/table-handle-row-root/types.ts +75 -0
  136. package/src/components/table-handle/table-handle-row-trigger/element.gen.ts +18 -0
  137. package/src/components/table-handle/table-handle-row-trigger/setup.ts +74 -0
  138. package/src/components/table-handle/table-handle-row-trigger/types.ts +26 -0
  139. package/src/components/table-handle/utils.ts +107 -0
  140. package/src/components/tooltip/index.gen.ts +13 -0
  141. package/src/components/tooltip/tooltip-content/element.gen.ts +18 -0
  142. package/src/components/tooltip/tooltip-content/setup.ts +1 -0
  143. package/src/components/tooltip/tooltip-content/types.ts +12 -0
  144. package/src/components/tooltip/tooltip-root/element.gen.ts +18 -0
  145. package/src/components/tooltip/tooltip-root/setup.ts +1 -0
  146. package/src/components/tooltip/tooltip-root/types.ts +12 -0
  147. package/src/components/tooltip/tooltip-trigger/element.gen.ts +18 -0
  148. package/src/components/tooltip/tooltip-trigger/setup.ts +1 -0
  149. package/src/components/tooltip/tooltip-trigger/types.ts +12 -0
  150. package/src/hooks/use-editor-extension.ts +19 -0
  151. package/src/hooks/use-editor-focus-event.ts +23 -0
  152. package/src/hooks/use-editor-typing.ts +36 -0
  153. package/src/hooks/use-editor-update-event.ts +23 -0
  154. package/src/hooks/use-first-rendering.ts +20 -0
  155. package/src/hooks/use-keymap.ts +20 -0
  156. package/src/hooks/use-scrolling.ts +33 -0
  157. package/src/hooks/use-selecting.ts +63 -0
  158. package/src/index.ts +1 -0
  159. package/src/utils/assign-styles.ts +14 -0
  160. package/src/utils/clone-element.ts +110 -0
  161. package/src/utils/css-feature-detection.ts +9 -0
  162. package/src/utils/fade-color.ts +15 -0
  163. package/src/utils/get-box-element.ts +20 -0
  164. package/src/utils/get-client-rect.ts +35 -0
  165. package/src/utils/get-default-state.spec.ts +50 -0
  166. package/src/utils/get-default-state.ts +22 -0
  167. package/src/utils/get-effective-background-color.ts +21 -0
  168. package/src/utils/get-safe-editor-view.ts +10 -0
  169. package/src/utils/inject-style.ts +11 -0
  170. package/src/utils/is-finite-positive-number.ts +3 -0
  171. package/src/utils/max-z-index.ts +3 -0
  172. package/src/utils/throttle.ts +17 -0
@@ -8,4 +8,5 @@ function getStateWithDefaults(state, props) {
8
8
  }
9
9
 
10
10
  //#endregion
11
- export { getStateWithDefaults };
11
+ export { getStateWithDefaults as t };
12
+ //# sourceMappingURL=get-default-state-BzBimBWi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-default-state-BzBimBWi.js","names":[],"sources":["../src/utils/get-default-state.ts"],"sourcesContent":["import {\n createSignal,\n type PropDeclarations,\n type SignalState,\n} from '@aria-ui/core'\n\nexport function getStateWithDefaults<\n Props extends Record<string, any> = Record<string, any>,\n>(\n state: Partial<SignalState<Props>>,\n props: PropDeclarations<Props>,\n): SignalState<Props> {\n const merged = { ...state } as SignalState<Props>\n\n for (const key of Object.keys(props) as (keyof Props)[]) {\n if (!merged[key]) {\n merged[key] = createSignal(props[key].default)\n }\n }\n\n return merged\n}\n"],"mappings":";;;AAMA,SAAgB,qBAGd,OACA,OACoB;CACpB,MAAM,SAAS,EAAE,GAAG,OAAO;AAE3B,MAAK,MAAM,OAAO,OAAO,KAAK,MAAM,CAClC,KAAI,CAAC,OAAO,KACV,QAAO,OAAO,aAAa,MAAM,KAAK,QAAQ;AAIlD,QAAO"}
@@ -8,4 +8,5 @@ function getSafeEditorView(editor) {
8
8
  }
9
9
 
10
10
  //#endregion
11
- export { getSafeEditorView };
11
+ export { getSafeEditorView as t };
12
+ //# sourceMappingURL=get-safe-editor-view-Dt9Amrcn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-safe-editor-view-Dt9Amrcn.js","names":[],"sources":["../src/utils/get-safe-editor-view.ts"],"sourcesContent":["import type { Editor } from '@prosekit/core'\nimport type { EditorView } from '@prosekit/pm/view'\n\n/**\n * @internal\n */\nexport function getSafeEditorView(editor?: Editor | null): EditorView | undefined {\n if (!editor || !editor.mounted) return\n return editor.view\n}\n"],"mappings":";;;;AAMA,SAAgB,kBAAkB,QAAgD;AAChF,KAAI,CAAC,UAAU,CAAC,OAAO,QAAS;AAChC,QAAO,OAAO"}
@@ -7,8 +7,7 @@ import { getDocument, getId } from "@ocavue/utils";
7
7
  */
8
8
  function deepCloneElement(element, important = false) {
9
9
  const clonedElement = element.cloneNode(true);
10
- const style = deepCopyStyles(element, clonedElement, important);
11
- return [clonedElement, style];
10
+ return [clonedElement, deepCopyStyles(element, clonedElement, important)];
12
11
  }
13
12
  /**
14
13
  * Creates a clone of an Element, including all computed styles so that
@@ -16,8 +15,7 @@ function deepCloneElement(element, important = false) {
16
15
  */
17
16
  function cloneElement(element, important = false) {
18
17
  const clonedElement = element.cloneNode();
19
- const style = copyStyles(element, clonedElement, important);
20
- return [clonedElement, style];
18
+ return [clonedElement, copyStyles(element, clonedElement, important)];
21
19
  }
22
20
  function deepCopyStyles(source, target, important) {
23
21
  const sources = [source];
@@ -48,8 +46,7 @@ function copyStyles(source, target, important) {
48
46
  const targetPseudoStyle = view.getComputedStyle(target, pseudoSelector);
49
47
  if (!sourcePseudoStyle) continue;
50
48
  const content = sourcePseudoStyle.getPropertyValue("content");
51
- const hasPseudoElement = content && content !== "none" && content !== "normal";
52
- if (!hasPseudoElement) continue;
49
+ if (!(content && content !== "none" && content !== "normal")) continue;
53
50
  const cssProps = [];
54
51
  for (const property of sourcePseudoStyle) {
55
52
  const sourceValue = sourcePseudoStyle.getPropertyValue(property);
@@ -69,11 +66,11 @@ function copyStyles(source, target, important) {
69
66
  //#region src/utils/inject-style.ts
70
67
  function injectStyle(container, styleText) {
71
68
  if (!styleText) return;
72
- const document = getDocument(container);
73
- const style = document.createElement("style");
69
+ const style = getDocument(container).createElement("style");
74
70
  style.textContent = styleText;
75
71
  container.appendChild(style);
76
72
  }
77
73
 
78
74
  //#endregion
79
- export { cloneElement, deepCloneElement, injectStyle };
75
+ export { cloneElement as n, deepCloneElement as r, injectStyle as t };
76
+ //# sourceMappingURL=inject-style-Dm6W58W3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inject-style-Dm6W58W3.js","names":["styles: string[]","source","target","cssProps: string[]"],"sources":["../src/utils/clone-element.ts","../src/utils/inject-style.ts"],"sourcesContent":["import { getId } from '@ocavue/utils'\n\n/**\n * Creates a deep clone of an Element, including all computed styles so that\n * it looks almost exactly the same as the original element.\n */\nexport function deepCloneElement<T extends Element>(element: T, important = false): [T, string] {\n const clonedElement = element.cloneNode(true) as T\n const style = deepCopyStyles(element, clonedElement, important)\n return [clonedElement, style]\n}\n\n/**\n * Creates a clone of an Element, including all computed styles so that\n * it looks similar enough to the original element.\n */\nexport function cloneElement<T extends Element>(element: T, important = false): [T, string] {\n const clonedElement = element.cloneNode() as T\n const style = copyStyles(element, clonedElement, important)\n return [clonedElement, style]\n}\n\nfunction deepCopyStyles(source: Element, target: Element, important: boolean): string {\n const sources = [source]\n const targets = [target]\n const styles: string[] = []\n\n while (sources.length > 0 && sources.length === targets.length) {\n const source = sources.pop()\n const target = targets.pop()\n\n if (!source || !target) {\n break\n }\n\n const style = copyStyles(source, target, important)\n if (style) {\n styles.push(style)\n }\n\n sources.push(...source.children)\n targets.push(...target.children)\n }\n\n return styles.join('\\n')\n}\n\nfunction copyStyles(source: Element, target: Element, important: boolean): string {\n if (!source || !target) {\n return ''\n }\n\n const view = source.ownerDocument?.defaultView\n if (!view) {\n return ''\n }\n\n // Known issue: pseudo styles are not copied.\n const sourceStyle = view.getComputedStyle(source)\n const targetStyle = (target as HTMLElement | SVGElement | MathMLElement).style\n\n if (!sourceStyle || !targetStyle) {\n return ''\n }\n\n for (const key of sourceStyle) {\n targetStyle.setProperty(\n key,\n sourceStyle.getPropertyValue(key),\n // Enforce important to avoid the style being overridden when the element\n // is connected to the page.\n // See https://github.com/prosekit/prosekit/issues/1185 for more details.\n important ? 'important' : (sourceStyle.getPropertyPriority(key) || ''),\n )\n }\n\n const styles: string[] = []\n for (const pseudoSelector of [':before', ':after']) {\n const sourcePseudoStyle = view.getComputedStyle(source, pseudoSelector)\n const targetPseudoStyle = view.getComputedStyle(target, pseudoSelector)\n\n if (!sourcePseudoStyle) {\n continue\n }\n\n const content = sourcePseudoStyle.getPropertyValue('content')\n const hasPseudoElement = content && content !== 'none' && content !== 'normal'\n\n if (!hasPseudoElement) {\n continue\n }\n\n const cssProps: string[] = []\n for (const property of sourcePseudoStyle) {\n const sourceValue = sourcePseudoStyle.getPropertyValue(property)\n const sourcePriority = sourcePseudoStyle.getPropertyPriority(property)\n const targetValue = targetPseudoStyle.getPropertyValue(property)\n const targetPriority = targetPseudoStyle.getPropertyPriority(property)\n if (sourceValue !== targetValue || sourcePriority !== targetPriority) {\n cssProps.push(`${property}: ${sourceValue}${sourcePriority ? ' !important' : ''};`)\n }\n }\n\n const uniqueClassName = `clone-pseudo-element-${getId()}`\n target.classList.add(uniqueClassName)\n styles.push(`.${uniqueClassName}${pseudoSelector} { ${cssProps.join(' ')} }`)\n }\n\n return styles.join('\\n')\n}\n","import { getDocument } from '@ocavue/utils'\n\nexport function injectStyle(container: HTMLElement, styleText: string): void {\n if (!styleText) {\n return\n }\n const document = getDocument(container)\n const style = document.createElement('style')\n style.textContent = styleText\n container.appendChild(style)\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,iBAAoC,SAAY,YAAY,OAAoB;CAC9F,MAAM,gBAAg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,eAAe;AAEvE,MAAI,CAAC,kBACH;EAGF,MAAM,UAAU,kBAAkB,iBAAiB,UAAU;AAG7D,MAAI,EAFqB,WAAW,YAAY,UAAU,YAAY,UAGpE;EAGF,MAAMG,WAAqB,EAAE;AAC7B,OAAK,MAAM,YAAY,mBAAmB;GACxC,MAAM,cAAc,kBAAkB,iBAAiB,SAAS;GAChE,MAAM,iBAAiB,kBAAkB,oBAAoB,SAAS;GACtE,MAAM,cAAc,kBAAkB,iBAAiB,SAAS;GAChE,MAAM,iBAAiB,kBAAkB,oBAAoB,SAAS;AACtE,OAAI,gBAAgB,eAAe,mBAAmB,eACpD,UAAS,KAAK,GAAG,SAAS,IAAI,cAAc,iBAAiB,gBAAgB,GAAG,GAAG;;EAIvF,MAAM,kBAAkB,wBAAwB,OAAO;AACvD,SAAO,UAAU,IAAI,gBAAgB;AACrC,SAAO,KAAK,IAAI,kBAAkB,eAAe,KAAK,SAAS,KAAK,IAAI,CAAC,IAAI;;AAG/E,QAAO,OAAO,KAAK,KAAK;;;;;AC1G1B,SAAgB,YAAY,WAAwB,WAAyB;AAC3E,KAAI,CAAC,UACH;CAGF,MAAM,QADW,YAAY,UAAU,CAChB,cAAc,QAAQ;AAC7C,OAAM,cAAc;AACpB,WAAU,YAAY,MAAM"}
@@ -157,4 +157,5 @@ declare function useAutocompletePopover(host: ConnectableElement, {
157
157
  emit
158
158
  }: SetupOptions<AutocompletePopoverProps, AutocompletePopoverEvents>): void;
159
159
  //#endregion
160
- export { AutocompleteEmptyElement, type AutocompleteEmptyEvents, type AutocompleteEmptyProps, AutocompleteItemElement, type AutocompleteItemEvents, type AutocompleteItemProps, AutocompleteListElement, type AutocompleteListEvents, type AutocompleteListProps, AutocompletePopoverElement, type AutocompletePopoverEvents, type AutocompletePopoverProps, autocompleteEmptyEvents, autocompleteEmptyProps, autocompleteItemEvents, autocompleteItemProps, autocompleteListEvents, autocompleteListProps, autocompletePopoverEvents, autocompletePopoverProps, useAutocompleteEmpty, useAutocompleteItem, useAutocompleteList, useAutocompletePopover };
160
+ export { AutocompleteEmptyElement, type AutocompleteEmptyEvents, type AutocompleteEmptyProps, AutocompleteItemElement, type AutocompleteItemEvents, type AutocompleteItemProps, AutocompleteListElement, type AutocompleteListEvents, type AutocompleteListProps, AutocompletePopoverElement, type AutocompletePopoverEvents, type AutocompletePopoverProps, autocompleteEmptyEvents, autocompleteEmptyProps, autocompleteItemEvents, autocompleteItemProps, autocompleteListEvents, autocompleteListProps, autocompletePopoverEvents, autocompletePopoverProps, useAutocompleteEmpty, useAutocompleteItem, useAutocompleteList, useAutocompletePopover };
161
+ //# sourceMappingURL=prosekit-web-autocomplete.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prosekit-web-autocomplete.d.ts","names":[],"sources":["../src/components/autocomplete/autocomplete-empty/types.ts","../src/components/autocomplete/autocomplete-empty/element.gen.ts","../src/components/autocomplete/autocomplete-empty/setup.ts","../src/components/autocomplete/autocomplete-item/types.ts","../src/components/autocomplete/autocomplete-item/element.gen.ts","../src/components/autocomplete/autocomplete-item/setup.ts","../src/components/autocomplete/autocomplete-list/types.ts","../src/components/autocomplete/autocomplete-list/element.gen.ts","../src/components/autocomplete/autocomplete-list/setup.ts","../src/components/autocomplete/autocomplete-popover/types.ts","../src/components/autocomplete/autocomplete-popover/element.gen.ts","../src/components/autocomplete/autocomplete-popover/setup.ts"],"sourcesContent":[],"mappings":";;;;;;;;UAMiB,sBAAA;;cAGJ,wBAAwB,iBAAiB;;AAHrC,UAMA,uBAAA,CANsB,CAGvC;AAGA;AAGa,cAAA,uBAA2C,EAAlB,iBAAkB,CAAA,uBAAD,CAAA;;;cCVjD,8BAA8B,uBAAuB;cAQrD,wBAAA,SAAiC,4BAAA;;;;;;cCR1B,6BAA6B;;;UCIzB,qBAAA;;;;;AHHjB;AAGA;AAGA;EAGa,KAAA,EAAA,MAAA;;;cGMA,uBAAuB,iBAAiB;AFhB/C,UEsBW,sBAAA,SAA+B,iBFtBW,CAAA,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./use-editor-extension-Cc7ZG7uj.js";
3
- import { getSafeEditorView } from "./get-safe-editor-view-DENm4avv.js";
1
+ import { t as getStateWithDefaults } from "./get-default-state-BzBimBWi.js";
2
+ import { t as useEditorExtension } from "./use-editor-extension-B2WuUfnd.js";
3
+ import { t as getSafeEditorView } from "./get-safe-editor-view-Dt9Amrcn.js";
4
4
  import { createComputed, createContext, createSignal, defineCustomElement, registerCustomElement, useAnimationFrame, useAttribute, useEffect, useEventListener } from "@aria-ui/core";
5
5
  import { listboxProps, useListbox, useListboxEmpty, useListboxItem } from "@aria-ui/listbox/elements";
6
6
  import { listboxEvents, listboxItemEvents, listboxProps as listboxProps$1 } from "@aria-ui/listbox";
@@ -221,15 +221,13 @@ function useAutocompleteExtension(host, editor, regex, reference, query, onDismi
221
221
  const editorValue = editor.get();
222
222
  const regexValue = regex.get();
223
223
  if (!editorValue || !regexValue) return;
224
- const rule = createAutocompleteRule(editorValue, regexValue, reference, query, onDismiss, onSubmit);
225
- const extension = defineAutocomplete(rule);
224
+ const extension = defineAutocomplete(createAutocompleteRule(editorValue, regexValue, reference, query, onDismiss, onSubmit));
226
225
  return editorValue.use(extension);
227
226
  });
228
227
  }
229
228
  function createAutocompleteRule(editor, regex, reference, query, onDismiss, onSubmit) {
230
229
  const handleEnter = (options) => {
231
- const view = getSafeEditorView(editor);
232
- const span = view?.dom.querySelector(".prosemirror-prediction-match");
230
+ const span = getSafeEditorView(editor)?.dom.querySelector(".prosemirror-prediction-match");
233
231
  if (span) reference.set(span);
234
232
  query.set(defaultQueryBuilder(options.match));
235
233
  onDismiss.set(options.ignoreMatch);
@@ -255,15 +253,12 @@ function createKeymapHandler(handler, enabled) {
255
253
  };
256
254
  }
257
255
  function useEscapeKeydown(host, editor, handler) {
258
- const keymap = { Escape: handler };
259
- const extension = withPriority(defineKeymap(keymap), Priority.highest);
260
- useEditorExtension(host, editor, extension);
256
+ useEditorExtension(host, editor, withPriority(defineKeymap({ Escape: handler }), Priority.highest));
261
257
  }
262
258
 
263
259
  //#endregion
264
260
  //#region src/components/autocomplete/autocomplete-popover/types.ts
265
- const body = typeof document !== "undefined" && document.querySelector("body");
266
- const defaultBoundary = body || "clippingAncestors";
261
+ const defaultBoundary = typeof document !== "undefined" && document.querySelector("body") || "clippingAncestors";
267
262
  /** @internal */
268
263
  const autocompletePopoverProps = {
269
264
  ...overlayPositionerProps,
@@ -295,4 +290,5 @@ var AutocompletePopoverElement = class extends AutocompletePopoverElementBase {}
295
290
  registerCustomElement("prosekit-autocomplete-popover", AutocompletePopoverElement);
296
291
 
297
292
  //#endregion
298
- export { AutocompleteEmptyElement, AutocompleteItemElement, AutocompleteListElement, AutocompletePopoverElement, autocompleteEmptyEvents, autocompleteEmptyProps, autocompleteItemEvents, autocompleteItemProps, autocompleteListEvents, autocompleteListProps, autocompletePopoverEvents, autocompletePopoverProps, useAutocompleteEmpty, useAutocompleteItem, useAutocompleteList, useAutocompletePopover };
293
+ export { AutocompleteEmptyElement, AutocompleteItemElement, AutocompleteListElement, AutocompletePopoverElement, autocompleteEmptyEvents, autocompleteEmptyProps, autocompleteItemEvents, autocompleteItemProps, autocompleteListEvents, autocompleteListProps, autocompletePopoverEvents, autocompletePopoverProps, useAutocompleteEmpty, useAutocompleteItem, useAutocompleteList, useAutocompletePopover };
294
+ //# sourceMappingURL=prosekit-web-autocomplete.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prosekit-web-autocomplete.js","names":["useAutocompleteEmpty: typeof useListboxEmpty","autocompleteEmptyProps: PropDeclarations<AutocompleteEmptyProps>","autocompleteEmptyEvents: EventDeclarations<AutocompleteEmptyEvents>","AutocompleteEmptyElementBase: BaseElementConstructor<AutocompleteEmptyProps>","queryContext: Context<string>","onSubmitContext: Context<VoidFunction | null>","openContext: Context<boolean>","autocompleteItemProps: PropDeclarations<AutocompleteItemProps>","autocompleteItemEvents: EventDeclarations<AutocompleteItemEvents>","AutocompleteItemElementBase: BaseElementConstructor<AutocompleteItemProps>","keydownHandlers: ((event: KeyboardEvent) => void)[]","autocompleteListProps: PropDeclarations<AutocompleteListProps>","listboxProps","autocompleteListEvents: EventDeclarations<AutocompleteListEvents>","AutocompleteListElementBase: BaseElementConstructor<AutocompleteListProps>","handleEnter: MatchHandler","autocompletePopoverProps: PropDeclarations<AutocompletePopoverProps>","autocompletePopoverEvents: EventDeclarations<AutocompletePopoverEvents>","AutocompletePopoverElementBase: BaseElementConstructor<AutocompletePopoverProps>"],"sources":["../src/components/autocomplete/autocomplete-empty/setup.ts","../src/components/autocomplete/autocomplete-empty/types.ts","../src/components/autocomplete/autocomplete-empty/element.gen.ts","../src/components/autocomplete/context.ts","../src/components/autocomplete/autocomplete-item/setup.ts","../src/components/autocomplete/autocomplete-item/types.ts","../src/components/autocomplete/autocomplete-item/element.gen.ts","../src/components/autocomplete/autocomplete-list/setup.ts","../src/components/autocomplete/autocomplete-list/types.ts","../src/components/autocomplete/autocomplete-list/element.gen.ts","../src/hooks/use-first-rendering.ts","../src/components/autocomplete/autocomplete-popover/helpers.ts","../src/components/autocomplete/autocomplete-popover/setup.ts","../src/components/autocomplete/autocomplete-popover/types.ts","../src/components/autocomplete/autocomplete-popover/element.gen.ts"],"sourcesContent":["import { useListboxEmpty } from '@aria-ui/listbox/elements'\n\n/**\n * @internal\n */\nexport const useAutocompleteEmpty: typeof useListboxEmpty = useListboxEmpty\n","import type {\n EventDeclarations,\n PropDeclarations,\n} from '@aria-ui/core'\n\n/** @internal */\nexport interface AutocompleteEmptyProps {}\n\n/** @internal */\nexport const autocompleteEmptyProps: PropDeclarations<AutocompleteEmptyProps> = {}\n\n/** @internal */\nexport interface AutocompleteEmptyEvents {}\n\n/** @internal */\nexport const autocompleteEmptyEvents: EventDeclarations<AutocompleteEmptyEvents> = {}\n","import { defineCustomElement, registerCustomElement, type BaseElementConstructor } from \"@aria-ui/core\"\n\nimport { useAutocompleteEmpty } from \"./setup\"\nimport { autocompleteEmptyEvents, autocompleteEmptyProps, type AutocompleteEmptyEvents, type AutocompleteEmptyProps } from \"./types\"\n\nconst AutocompleteEmptyElementBase: BaseElementConstructor<AutocompleteEmptyProps> = defineCustomElement<\n AutocompleteEmptyProps,\n AutocompleteEmptyEvents\n>({\n props: autocompleteEmptyProps,\n events: autocompleteEmptyEvents,\n setup: useAutocompleteEmpty,\n})\nclass AutocompleteEmptyElement extends AutocompleteEmptyElementBase {}\n\nregisterCustomElement('prosekit-autocomplete-empty', AutocompleteEmptyElement)\n \nexport { AutocompleteEmptyElement }\n","import {\n createContext,\n type Context,\n} from '@aria-ui/core'\n\nexport const queryContext: Context<string> = createContext(\n 'prosekit/autocomplete-popover/query',\n '',\n)\n\nexport const onSubmitContext: Context<VoidFunction | null> = createContext(\n 'prosekit/autocomplete-popover/onSubmit',\n null,\n)\n\nexport const openContext: Context<boolean> = createContext(\n 'prosekit/autocomplete-popover/open',\n false,\n)\n","import {\n useEffect,\n useEventListener,\n type ConnectableElement,\n type SetupOptions,\n} from '@aria-ui/core'\nimport { useListboxItem } from '@aria-ui/listbox/elements'\n\nimport { openContext } from '../context'\n\nimport type {\n AutocompleteItemEvents,\n AutocompleteItemProps,\n} from './types'\n\n/**\n * @internal\n */\nexport function useAutocompleteItem(\n element: ConnectableElement,\n { state, emit }: SetupOptions<AutocompleteItemProps, AutocompleteItemEvents>,\n): void {\n useListboxItem(element, { state, emit })\n\n const open = openContext.consume(element)\n\n useEffect(element, () => {\n // Check the text content again when the open state changes\n if (!state.value.peek() && open.get()) {\n state.value.set(element.textContent ?? '')\n }\n })\n\n useEventListener(element, 'pointerdown', (event) => {\n // Prevent the editor from losing focus\n event.preventDefault()\n })\n}\n","import type {\n EventDeclarations,\n PropDeclarations,\n} from '@aria-ui/core'\nimport {\n listboxItemEvents,\n type ListboxItemEvents,\n} from '@aria-ui/listbox'\n\nexport interface AutocompleteItemProps {\n /**\n * The value of the item, which will be matched against the query.\n *\n * If not provided, the value is the item's text content.\n *\n * @default \"\"\n */\n value: string\n}\n\n/** @internal */\nexport const autocompleteItemProps: PropDeclarations<AutocompleteItemProps> = {\n value: {\n default: '',\n },\n}\n\nexport interface AutocompleteItemEvents extends ListboxItemEvents {}\n\n/** @internal */\nexport const autocompleteItemEvents: EventDeclarations<AutocompleteItemEvents> = listboxItemEvents\n","import { defineCustomElement, registerCustomElement, type BaseElementConstructor } from \"@aria-ui/core\"\n\nimport { useAutocompleteItem } from \"./setup\"\nimport { autocompleteItemEvents, autocompleteItemProps, type AutocompleteItemEvents, type AutocompleteItemProps } from \"./types\"\n\nconst AutocompleteItemElementBase: BaseElementConstructor<AutocompleteItemProps> = defineCustomElement<\n AutocompleteItemProps,\n AutocompleteItemEvents\n>({\n props: autocompleteItemProps,\n events: autocompleteItemEvents,\n setup: useAutocompleteItem,\n})\nclass AutocompleteItemElement extends AutocompleteItemElementBase {}\n\nregisterCustomElement('prosekit-autocomplete-item', AutocompleteItemElement)\n \nexport { AutocompleteItemElement }\n","import {\n createSignal,\n useEffect,\n type ConnectableElement,\n type ReadonlySignal,\n type SetupOptions,\n type TypedEventTarget,\n} from '@aria-ui/core'\nimport {\n listboxProps,\n useListbox,\n type ListboxProps,\n} from '@aria-ui/listbox/elements'\nimport {\n defineDOMEventHandler,\n Priority,\n withPriority,\n type Editor,\n} from '@prosekit/core'\n\nimport { getStateWithDefaults } from '../../../utils/get-default-state'\nimport {\n onSubmitContext,\n openContext,\n queryContext,\n} from '../context'\n\nimport type {\n AutocompleteListEvents,\n AutocompleteListProps,\n} from './types'\n\n/**\n * @internal\n */\nexport function useAutocompleteList(\n element: ConnectableElement,\n { state, emit }: SetupOptions<AutocompleteListProps, AutocompleteListEvents>,\n): void {\n const open = openContext.consume(element)\n const query = queryContext.consume(element)\n const onSubmit = onSubmitContext.consume(element)\n\n const keydownTarget = useKeyDownTarget(element, open, state.editor)\n\n const listboxState = getStateWithDefaults<ListboxProps>(\n { filter: state.filter, eventTarget: createSignal(keydownTarget) },\n listboxProps,\n )\n\n useEffect(element, () => {\n element.addEventListener('valueChange', () => {\n if (onSubmit) {\n onSubmit.get()?.()\n }\n })\n })\n\n useListbox(element, { state: listboxState, emit })\n\n useEffect(element, () => {\n listboxState.query.set(query.get())\n })\n\n useEffect(element, () => {\n if (!open.get()) {\n listboxState.value.set('')\n query.set('')\n }\n })\n\n // Reset the focused item when the popover is open\n useEffect(element, () => {\n if (!open.get()) {\n listboxState.autoFocus.set(false)\n } else {\n let canceled = false\n\n requestAnimationFrame(() => {\n if (canceled) return\n listboxState.autoFocus.set(true)\n })\n\n return () => {\n canceled = true\n }\n }\n })\n\n // The autocomplete list should not be focusable because the editor will get\n // the focus during typing.\n useEffect(element, () => {\n element.tabIndex = -1\n })\n}\n\nfunction useKeyDownTarget(\n element: ConnectableElement,\n open: ReadonlySignal<boolean>,\n editor: ReadonlySignal<Editor | null>,\n): TypedEventTarget<'keydown'> {\n const keydownHandlers: ((event: KeyboardEvent) => void)[] = []\n\n useEffect(element, () => {\n const editorValue = editor.get()\n\n if (!editorValue) {\n return\n }\n\n const extension = defineDOMEventHandler(\n 'keydown',\n (view, event): boolean => {\n if (view.composing || event.defaultPrevented || !open.get()) {\n return false\n }\n keydownHandlers.forEach((handler) => handler(event))\n return event.defaultPrevented\n },\n )\n\n return editorValue.use(withPriority(extension, Priority.highest))\n })\n\n return {\n addEventListener: (type, listener) => {\n if (type === 'keydown') {\n keydownHandlers.push(listener)\n }\n },\n removeEventListener: (type, listener) => {\n if (type === 'keydown') {\n const index = keydownHandlers.indexOf(listener)\n if (index !== -1) {\n keydownHandlers.splice(index, 1)\n }\n }\n },\n }\n}\n","import type {\n EventDeclarations,\n PropDeclarations,\n} from '@aria-ui/core'\nimport {\n listboxEvents,\n listboxProps,\n type ListboxEvents,\n type ListboxProps,\n} from '@aria-ui/listbox'\nimport type { Editor } from '@prosekit/core'\n\nexport interface AutocompleteListProps extends Pick<ListboxProps, 'filter'> {\n /**\n * The ProseKit editor instance.\n *\n * @default null\n * @hidden\n */\n editor: Editor | null\n}\n\nexport const autocompleteListProps: PropDeclarations<AutocompleteListProps> = {\n filter: listboxProps.filter,\n editor: { default: null },\n}\n\nexport interface AutocompleteListEvents extends ListboxEvents {}\n\nexport const autocompleteListEvents: EventDeclarations<AutocompleteListEvents> = { ...listboxEvents }\n","import { defineCustomElement, registerCustomElement, type BaseElementConstructor } from \"@aria-ui/core\"\n\nimport { useAutocompleteList } from \"./setup\"\nimport { autocompleteListEvents, autocompleteListProps, type AutocompleteListEvents, type AutocompleteListProps } from \"./types\"\n\nconst AutocompleteListElementBase: BaseElementConstructor<AutocompleteListProps> = defineCustomElement<\n AutocompleteListProps,\n AutocompleteListEvents\n>({\n props: autocompleteListProps,\n events: autocompleteListEvents,\n setup: useAutocompleteList,\n})\nclass AutocompleteListElement extends AutocompleteListElementBase {}\n\nregisterCustomElement('prosekit-autocomplete-list', AutocompleteListElement)\n \nexport { AutocompleteListElement }\n","import {\n createSignal,\n useEffect,\n type ConnectableElement,\n type ReadonlySignal,\n} from '@aria-ui/core'\n\nexport function useFirstRendering(\n host: ConnectableElement,\n): ReadonlySignal<boolean> {\n const firstRendering = createSignal(true)\n\n useEffect(host, () => {\n requestAnimationFrame(() => {\n firstRendering.set(false)\n })\n })\n\n return firstRendering\n}\n","export function defaultQueryBuilder(match: RegExpExecArray): string {\n return match[0]\n .toLowerCase()\n .replace(/[!\"#$%&'()*+,-./:;<=>?@[\\\\\\]^_`{|}~]/g, '')\n .replace(/\\s\\s+/g, ' ')\n .trim()\n}\n","import {\n createComputed,\n createSignal,\n useAnimationFrame,\n useAttribute,\n useEffect,\n type ConnectableElement,\n type ReadonlySignal,\n type SetupOptions,\n type Signal,\n} from '@aria-ui/core'\nimport { useOverlayPositionerState } from '@aria-ui/overlay/elements'\nimport { usePresence } from '@aria-ui/presence'\nimport {\n defineKeymap,\n Priority,\n withPriority,\n type Editor,\n} from '@prosekit/core'\nimport {\n AutocompleteRule,\n defineAutocomplete,\n type MatchHandler,\n} from '@prosekit/extensions/autocomplete'\n\nimport { useEditorExtension } from '../../../hooks/use-editor-extension'\nimport { useFirstRendering } from '../../../hooks/use-first-rendering'\nimport { getSafeEditorView } from '../../../utils/get-safe-editor-view'\nimport {\n onSubmitContext,\n openContext,\n queryContext,\n} from '../context'\n\nimport { defaultQueryBuilder } from './helpers'\nimport type {\n AutocompletePopoverEvents,\n AutocompletePopoverProps,\n} from './types'\n\n/**\n * @internal\n */\nexport function useAutocompletePopover(\n host: ConnectableElement,\n {\n state,\n emit,\n }: SetupOptions<AutocompletePopoverProps, AutocompletePopoverEvents>,\n): void {\n const { editor, regex, ...overlayState } = state\n\n const reference = createSignal<Element | null>(null)\n const query = createSignal<string>('')\n const onDismiss = createSignal<VoidFunction | null>(null)\n const onSubmit = createSignal<VoidFunction | null>(null)\n const presence = createComputed(() => !!reference.get())\n\n queryContext.provide(host, query)\n onSubmitContext.provide(host, onSubmit)\n openContext.provide(host, presence)\n\n useEscapeKeydown(host, editor, createKeymapHandler(onDismiss, presence))\n\n useAutocompleteExtension(\n host,\n editor,\n regex,\n reference,\n query,\n onDismiss,\n onSubmit,\n )\n\n useOverlayPositionerState(host, overlayState, { reference })\n\n useAttribute(host, 'data-state', () => (presence.get() ? 'open' : 'closed'))\n usePresence(host, presence)\n\n const firstRendering = useFirstRendering(host)\n\n useEffect(host, () => {\n const queryValue = query.get()\n\n if (!firstRendering.peek()) {\n emit('queryChange', queryValue)\n }\n })\n\n useAnimationFrame(host, () => {\n const presenceValue = presence.get()\n return () => {\n emit('openChange', presenceValue)\n }\n })\n}\n\nfunction useAutocompleteExtension(\n host: ConnectableElement,\n editor: ReadonlySignal<Editor | null>,\n regex: ReadonlySignal<RegExp | null>,\n reference: Signal<Element | null>,\n query: Signal<string>,\n onDismiss: Signal<VoidFunction | null>,\n onSubmit: Signal<VoidFunction | null>,\n) {\n useEffect(host, () => {\n const editorValue = editor.get()\n const regexValue = regex.get()\n\n if (!editorValue || !regexValue) {\n return\n }\n\n const rule = createAutocompleteRule(\n editorValue,\n regexValue,\n reference,\n query,\n onDismiss,\n onSubmit,\n )\n const extension = defineAutocomplete(rule)\n return editorValue.use(extension)\n })\n}\n\nfunction createAutocompleteRule(\n editor: Editor,\n regex: RegExp,\n reference: Signal<Element | null>,\n query: Signal<string>,\n onDismiss: Signal<VoidFunction | null>,\n onSubmit: Signal<VoidFunction | null>,\n) {\n const handleEnter: MatchHandler = (options) => {\n const view = getSafeEditorView(editor)\n const span = view?.dom.querySelector('.prosemirror-prediction-match')\n\n if (span) {\n reference.set(span)\n }\n\n query.set(defaultQueryBuilder(options.match))\n onDismiss.set(options.ignoreMatch)\n onSubmit.set(options.deleteMatch)\n }\n\n const handleLeave = () => {\n reference.set(null)\n query.set('')\n }\n\n return new AutocompleteRule({\n regex,\n onEnter: handleEnter,\n onLeave: handleLeave,\n })\n}\n\nfunction createKeymapHandler(\n handler: ReadonlySignal<VoidFunction | null>,\n enabled: ReadonlySignal<boolean>,\n) {\n return (): boolean => {\n if (!enabled.get()) {\n return false\n }\n\n const fn = handler.peek()\n if (!fn) return false\n fn()\n return true\n }\n}\n\nfunction useEscapeKeydown(\n host: ConnectableElement,\n editor: ReadonlySignal<Editor | null>,\n handler: () => boolean,\n): void {\n const keymap = { Escape: handler }\n const extension = withPriority(defineKeymap(keymap), Priority.highest)\n useEditorExtension(host, editor, extension)\n}\n","import type {\n EventDeclarations,\n PropDeclarations,\n} from '@aria-ui/core'\nimport {\n overlayPositionerEvents,\n overlayPositionerProps,\n type OverlayPositionerEvents,\n type OverlayPositionerProps,\n} from '@aria-ui/overlay/elements'\nimport type { Editor } from '@prosekit/core'\n\nexport interface AutocompletePopoverProps extends OverlayPositionerProps {\n /**\n * The ProseKit editor instance.\n *\n * @default null\n * @hidden\n */\n editor: Editor | null\n\n /**\n * The regular expression to match the query text to autocomplete.\n *\n * @default null\n */\n regex: RegExp | null\n\n /**\n * The placement of the popover, relative to the text cursor.\n *\n * @default \"bottom-start\"\n */\n placement: OverlayPositionerProps['placement']\n\n /**\n * The distance between the popover and the hovered block.\n *\n * @default 4\n */\n offset: OverlayPositionerProps['offset']\n\n /**\n * @default true\n */\n inline: OverlayPositionerProps['inline']\n\n /**\n * @default true\n */\n hoist: OverlayPositionerProps['hoist']\n\n /**\n * @default true\n */\n fitViewport: OverlayPositionerProps['fitViewport']\n\n /**\n * @default \"The body element\"\n */\n boundary: OverlayPositionerProps['boundary']\n\n /**\n * @default 8\n */\n overflowPadding: OverlayPositionerProps['overflowPadding']\n}\n\nconst body = typeof document !== 'undefined' && document.querySelector('body')\nconst defaultBoundary = body || 'clippingAncestors'\n\n/** @internal */\nexport const autocompletePopoverProps: PropDeclarations<AutocompletePopoverProps> = {\n ...overlayPositionerProps,\n editor: { default: null },\n regex: { default: null },\n placement: { default: 'bottom-start' },\n offset: { default: 4 },\n inline: { default: true },\n hoist: { default: true },\n fitViewport: { default: true },\n boundary: { default: defaultBoundary },\n overflowPadding: { default: 8 },\n}\n\nexport interface AutocompletePopoverEvents extends OverlayPositionerEvents {\n /**\n * Fired when the open state changes.\n */\n openChange: CustomEvent<boolean>\n\n /**\n * Fired when the query changes.\n */\n queryChange: CustomEvent<string>\n}\n\n/** @internal */\nexport const autocompletePopoverEvents: EventDeclarations<AutocompletePopoverEvents> = {\n ...overlayPositionerEvents,\n openChange: {},\n queryChange: {},\n}\n","import { defineCustomElement, registerCustomElement, type BaseElementConstructor } from \"@aria-ui/core\"\n\nimport { useAutocompletePopover } from \"./setup\"\nimport { autocompletePopoverEvents, autocompletePopoverProps, type AutocompletePopoverEvents, type AutocompletePopoverProps } from \"./types\"\n\nconst AutocompletePopoverElementBase: BaseElementConstructor<AutocompletePopoverProps> = defineCustomElement<\n AutocompletePopoverProps,\n AutocompletePopoverEvents\n>({\n props: autocompletePopoverProps,\n events: autocompletePopoverEvents,\n setup: useAutocompletePopover,\n})\nclass AutocompletePopoverElement extends AutocompletePopoverElementBase {}\n\nregisterCustomElement('prosekit-autocomplete-popover', AutocompletePopoverElement)\n \nexport { AutocompletePopoverElement }\n"],"mappings":";;;;;;;;;;;;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AS,MAAM;CACxB,WAAW,EAAE,SAAS,gBAAgB;CACtC,QAAQ,EAAE,SAAS,GAAG;CACtB,QAAQ,EAAE,SAAS,MAAM;CACzB,OAAO,EAAE,SAAS,MAAM;CACxB,aAAa,EAAE,SAAS,MAAM;CAC9B,UAAU,EAAE,SAAS,iBAAiB;CACtC,iBAAiB,EAAE,SAAS,GAAG;CAChC;;AAeD,MAAaC,4BAA0E;CACrF,GAAG;CACH,YAAY,EAAE;CACd,aAAa,EAAE;CAChB;;;;ACjGD,MAAMC,iCAAmF,oBAGvF;CACA,OAAO;CACP,QAAQ;CACR,OAAO;CACR,CAAC;AACF,IAAM,6BAAN,cAAyC,+BAA+B;AAExE,sBAAsB,iCAAiC,2BAA2B"}
@@ -131,4 +131,5 @@ declare function useBlockHandlePopover(host: ConnectableElement, {
131
131
  emit
132
132
  }: SetupOptions<BlockHandlePopoverProps, BlockHandlePopoverEvents>): void;
133
133
  //#endregion
134
- export { BlockHandleAddElement, type BlockHandleAddEvents, type BlockHandleAddProps, BlockHandleDraggableElement, type BlockHandleDraggableEvents, type BlockHandleDraggableProps, BlockHandlePopoverElement, type BlockHandlePopoverEvents, type BlockHandlePopoverProps, blockHandleAddEvents, blockHandleAddProps, blockHandleDraggableEvents, blockHandleDraggableProps, blockHandlePopoverEvents, blockHandlePopoverProps, useBlockHandleAdd, useBlockHandleDraggable, useBlockHandlePopover };
134
+ export { BlockHandleAddElement, type BlockHandleAddEvents, type BlockHandleAddProps, BlockHandleDraggableElement, type BlockHandleDraggableEvents, type BlockHandleDraggableProps, BlockHandlePopoverElement, type BlockHandlePopoverEvents, type BlockHandlePopoverProps, blockHandleAddEvents, blockHandleAddProps, blockHandleDraggableEvents, blockHandleDraggableProps, blockHandlePopoverEvents, blockHandlePopoverProps, useBlockHandleAdd, useBlockHandleDraggable, useBlockHandlePopover };
135
+ //# sourceMappingURL=prosekit-web-block-handle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prosekit-web-block-handle.d.ts","names":[],"sources":["../src/components/block-handle/block-handle-add/types.ts","../src/components/block-handle/block-handle-add/element.gen.ts","../src/components/block-handle/block-handle-add/setup.ts","../src/components/block-handle/block-handle-draggable/types.ts","../src/components/block-handle/block-handle-draggable/element.gen.ts","../src/components/block-handle/block-handle-draggable/setup.ts","../src/components/block-handle/block-handle-popover/types.ts","../src/components/block-handle/block-handle-popover/element.gen.ts","../src/components/block-handle/block-handle-popover/setup.ts"],"sourcesContent":[],"mappings":";;;;;;;UAMiB,mBAAA;;;;;AAAjB;AAWA;EAKiB,MAAA,EATP,MASO,GAAA,IAAA;AAGjB;;cARa,qBAAqB,iBAAiB;;ACZ7C,UDiBW,oBAAA,CCVf,CAPqD;;cDoB1C,sBAAsB,kBAAkB;;;cCpB/C,2BAA2B,uBAAuB;cAQlD,qBAAA,SAA8B,yBAAA;;;;;;iBCCpB,iBAAA,OACR;;AFTR;SEUsB,YAAY;AFVlC,CAAA,CAAA,EAAiB,IAAA;;;UGAA,yBAAA;;;;;AHAjB;AAWA;EAKiB,MAAA,EGTP,MHSO,GAAA,IAAA;AAGjB;;cGRa,2BAA2B,iBAAiB;;AFZnD,UEiBW,0BAAA,CFjBuC,CAAD;;cEoB1C,4BAA4B,kBAAkB;;;cCpBrD,iCAAiC,uBAAuB;cAQxD,2BAAA,SAAoC,+BAAA;;;;;;iBCoB1B,uBAAA,OACR;;AL5BR;SK6BsB,YAAY;AL7BlC,CAAA,CAAA,EAAiB,IAAA;;;UMQA,uBAAA,SAAgC,KAAK;;ANRtD;AAWA;AAKA;AAGA;;UMJU;;ALlB8G;AAEjE;;;aKuB1C;EJdG;;;;;;;;;ACRhB;AAWA;EAKiB,IAAA,EAAA,OAAA;EAGJ;;;;ECpBP,KAAA,EAAA,OAAA;EAQA;;;;ECoBU,IAAA,EAAA,OAAA;;;AAEkB,cCuBrB,uBDvBqB,ECuBI,gBDvBJ,CCuBqB,uBDvBrB,CAAA;AAAZ,UCqCL,wBAAA,SAAiC,uBDrC5B,CAAA;EAAW;;;eCyClB;IA9DE,IAAA,EA8DkB,eA9DlB;IAAqC,GAAA,EAAA,MAAA;EAO5C,CAAA,GAAA,IAAA,CAAA;;;AAP2C,cAkExC,wBAlEwC,EAkEd,iBAlEc,CAkEI,wBAlEJ,CAAA;;;cCT/C,+BAA+B,uBAAuB;cAQtD,yBAAA,SAAkC,6BAAA;;;;;;iBCqBxB,qBAAA,OACR;;;GACW,aAAa,yBAAyB"}
@@ -1,7 +1,7 @@
1
- import { useEditorExtension } from "./use-editor-extension-Cc7ZG7uj.js";
2
- import { getSafeEditorView } from "./get-safe-editor-view-DENm4avv.js";
3
- import { assignStyles, useScrolling } from "./use-scrolling-BNfsQs3S.js";
4
- import { deepCloneElement, injectStyle } from "./inject-style-D5jj7cme.js";
1
+ import { t as useEditorExtension } from "./use-editor-extension-B2WuUfnd.js";
2
+ import { t as getSafeEditorView } from "./get-safe-editor-view-Dt9Amrcn.js";
3
+ import { n as assignStyles, t as useScrolling } from "./use-scrolling-BOvyjDvH.js";
4
+ import { r as deepCloneElement, t as injectStyle } from "./inject-style-Dm6W58W3.js";
5
5
  import { createComputed, createContext, createSignal, defineCustomElement, registerCustomElement, useAttribute, useEffect, useEventListener } from "@aria-ui/core";
6
6
  import { defineDOMEventHandler, insertDefaultBlock, union } from "@prosekit/core";
7
7
  import { overlayPositionerEvents, overlayPositionerProps, useOverlayPositionerState } from "@aria-ui/overlay/elements";
@@ -64,8 +64,7 @@ registerCustomElement("prosekit-block-handle-add", BlockHandleAddElement);
64
64
  function getBoxElement(element) {
65
65
  const window = element.ownerDocument.defaultView;
66
66
  if (!window) return;
67
- const style = window.getComputedStyle(element);
68
- const display = style.display;
67
+ const display = window.getComputedStyle(element).display;
69
68
  if (display === "contents" && element.childElementCount === 1) return element.firstElementChild;
70
69
  else if (display === "none") return;
71
70
  return element;
@@ -80,8 +79,7 @@ function getClientRect(element) {
80
79
  const rect = element.getBoundingClientRect();
81
80
  if (rect.width === 0 && rect.height === 0 && rect.x === 0 && rect.y === 0) {
82
81
  if (element.getClientRects().length === 0) {
83
- const children = Array.from(element.children);
84
- const rects = children.map((child) => getClientRect(child));
82
+ const rects = Array.from(element.children).map((child) => getClientRect(child));
85
83
  if (rects.length === 0) return rect;
86
84
  if (rects.length === 1) return rects[0];
87
85
  let { top, bottom, left, right } = rects[0];
@@ -212,12 +210,11 @@ function createDraggingPreview(view, hoverState, event) {
212
210
  }
213
211
  function setViewDragging(view, hoverState) {
214
212
  const { node, pos } = hoverState;
215
- const dragging = {
213
+ view.dragging = {
216
214
  slice: new Slice(Fragment.from(node), 0, 0),
217
215
  move: true,
218
216
  node: NodeSelection.create(view.state.doc, pos)
219
217
  };
220
- view.dragging = dragging;
221
218
  }
222
219
 
223
220
  //#endregion
@@ -257,20 +254,29 @@ function throttle(callback, wait) {
257
254
  //#region src/components/block-handle/block-handle-popover/pointer-move.ts
258
255
  function defineElementHoverHandler(handler) {
259
256
  const handleElement = (node, pos, element, parentElement) => {
260
- const reference = {
257
+ handler({
261
258
  contextElement: element,
262
259
  getBoundingClientRect: () => {
263
260
  const rect = findFirstLineRect(parentElement, element);
264
261
  return rect ? fulfillRect(rect) : fallbackRect;
265
262
  }
266
- };
267
- handler(reference, {
263
+ }, {
268
264
  node,
269
265
  pos
270
266
  });
271
267
  };
268
+ let lastX = -1;
269
+ let lastY = -1;
270
+ let lastTime = -1;
272
271
  const handlePointerEvent = (view, event) => {
273
272
  const { x, y } = event;
273
+ if (lastX === x && lastY === y) {
274
+ const now = Date.now();
275
+ if (now - lastTime < 100) return;
276
+ lastTime = now;
277
+ }
278
+ lastX = x;
279
+ lastY = y;
274
280
  const block = findBlockByCoords(view, x, y);
275
281
  if (!block) {
276
282
  handler(null, null);
@@ -286,15 +292,13 @@ function defineElementHoverHandler(handler) {
286
292
  if ($pos.depth > 0 && $pos.index($pos.depth) === 0) {
287
293
  const parentPos = $pos.before($pos.depth);
288
294
  const parentNode = $pos.parent;
289
- const parentElement = view.nodeDOM(parentPos);
290
- handleElement(parentNode, parentPos, element, parentElement);
295
+ handleElement(parentNode, parentPos, element, view.nodeDOM(parentPos));
291
296
  } else handleElement(node, pos, element);
292
297
  };
293
- return union(defineDOMEventHandler("pointermove", throttle(handlePointerEvent, 200)), defineDOMEventHandler("pointerout", handlePointerEvent), defineDOMEventHandler("keypress", () => handler(null, null)));
298
+ return union(defineDOMEventHandler("pointermove", throttle(handlePointerEvent, 200)), defineDOMEventHandler("pointerenter", handlePointerEvent), defineDOMEventHandler("pointerout", handlePointerEvent), defineDOMEventHandler("keypress", () => handler(null, null)));
294
299
  }
295
300
  function findBlockByCoords(view, x, y) {
296
- const rect = getClientRect(view.dom);
297
- if (!isWithinRect(rect, x, y)) return;
301
+ if (!isWithinRect(getClientRect(view.dom), x, y)) return;
298
302
  let parent = view.state.doc;
299
303
  let pos = -1;
300
304
  while (parent) {
@@ -312,8 +316,7 @@ function findBlockByCoords(view, x, y) {
312
316
  let hi = children.length - 1;
313
317
  while (lo <= hi) {
314
318
  const i = hi - (hi - lo >> 1);
315
- const childDOM = view.nodeDOM(positions[i]);
316
- const childRect = getNodeRect(childDOM);
319
+ const childRect = getNodeRect(view.nodeDOM(positions[i]));
317
320
  if (!childRect) {
318
321
  console.warn(`[prosekit] Unable to get rect at position: ${positions[i]}`);
319
322
  return;
@@ -380,8 +383,7 @@ function findFirstLineRectInTextNode(node) {
380
383
  const range = ownerDocument.createRange();
381
384
  range.setStart(node, 0);
382
385
  range.setEnd(node, 0);
383
- const rects = range.getClientRects();
384
- return rects[0];
386
+ return range.getClientRects()[0];
385
387
  }
386
388
  function findFirstLineRectInElement(element) {
387
389
  if (element.nodeName === "BR") return element.getBoundingClientRect();
@@ -395,10 +397,9 @@ function findFirstLineRectInElement(element) {
395
397
  const paddingTop = style && Number.parseInt(style.paddingTop, 10) || 0;
396
398
  const borderTop = style && Number.parseInt(style.borderTopWidth, 10) || 0;
397
399
  const top = rect.top + paddingTop + borderTop;
398
- const bottom = top + lineHeight;
399
400
  return {
400
401
  top,
401
- bottom,
402
+ bottom: top + lineHeight,
402
403
  left,
403
404
  right
404
405
  };
@@ -446,23 +447,21 @@ function useBlockHandlePopover(host, { state, emit }) {
446
447
  useHoverExtension(host, editor, (referenceValue, hoverState) => {
447
448
  reference.set(referenceValue);
448
449
  context.set(hoverState);
449
- const stateChangeDetails = hoverState ? {
450
+ emit("stateChange", hoverState ? {
450
451
  node: hoverState.node,
451
452
  pos: hoverState.pos
452
- } : null;
453
- emit("stateChange", stateChangeDetails);
453
+ } : null);
454
454
  });
455
455
  useAttribute(host, "data-state", () => open.get() ? "open" : "closed");
456
456
  usePresence(host, open);
457
457
  }
458
458
  function useHoverExtension(host, editor, handler) {
459
459
  let prevHoverState = null;
460
- const extension = defineElementHoverHandler((reference, hoverState) => {
460
+ useEditorExtension(host, editor, defineElementHoverHandler((reference, hoverState) => {
461
461
  if (isHoverStateEqual(prevHoverState, hoverState)) return;
462
462
  prevHoverState = hoverState;
463
463
  handler(reference, hoverState);
464
- });
465
- useEditorExtension(host, editor, extension);
464
+ }));
466
465
  }
467
466
  function isHoverStateEqual(a, b) {
468
467
  if (!a && !b) return true;
@@ -499,4 +498,5 @@ var BlockHandlePopoverElement = class extends BlockHandlePopoverElementBase {};
499
498
  registerCustomElement("prosekit-block-handle-popover", BlockHandlePopoverElement);
500
499
 
501
500
  //#endregion
502
- export { BlockHandleAddElement, BlockHandleDraggableElement, BlockHandlePopoverElement, blockHandleAddEvents, blockHandleAddProps, blockHandleDraggableEvents, blockHandleDraggableProps, blockHandlePopoverEvents, blockHandlePopoverProps, useBlockHandleAdd, useBlockHandleDraggable, useBlockHandlePopover };
501
+ export { BlockHandleAddElement, BlockHandleDraggableElement, BlockHandlePopoverElement, blockHandleAddEvents, blockHandleAddProps, blockHandleDraggableEvents, blockHandleDraggableProps, blockHandlePopoverEvents, blockHandlePopoverProps, useBlockHandleAdd, useBlockHandleDraggable, useBlockHandlePopover };
502
+ //# sourceMappingURL=prosekit-web-block-handle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prosekit-web-block-handle.js","names":["blockPopoverContext: Context<BlockPopoverContext>","draggingContext: Context<boolean>","blockHandleAddProps: PropDeclarations<BlockHandleAddProps>","blockHandleAddEvents: EventDeclarations<BlockHandleAddEvents>","BlockHandleAddElementBase: BaseElementConstructor<BlockHandleAddProps>","blockHandleDraggableProps: PropDeclarations<BlockHandleDraggableProps>","blockHandleDraggableEvents: EventDeclarations<BlockHandleDraggableEvents>","BlockHandleDraggableElementBase: BaseElementConstructor<BlockHandleDraggableProps>","parent: ProseMirrorNode | undefined","children: ProseMirrorNode[]","positions: number[]","prevHoverState: HoverState | null","blockHandlePopoverProps: PropDeclarations<BlockHandlePopoverProps>","blockHandlePopoverEvents: EventDeclarations<BlockHandlePopoverEvents>","BlockHandlePopoverElementBase: BaseElementConstructor<BlockHandlePopoverProps>"],"sources":["../src/components/block-handle/context.ts","../src/components/block-handle/block-handle-add/setup.ts","../src/components/block-handle/block-handle-add/types.ts","../src/components/block-handle/block-handle-add/element.gen.ts","../src/utils/get-box-element.ts","../src/utils/get-client-rect.ts","../src/utils/max-z-index.ts","../src/components/block-handle/block-handle-draggable/set-drag-preview.ts","../src/components/block-handle/block-handle-draggable/setup.ts","../src/components/block-handle/block-handle-draggable/types.ts","../src/components/block-handle/block-handle-draggable/element.gen.ts","../src/utils/throttle.ts","../src/components/block-handle/block-handle-popover/pointer-move.ts","../src/components/block-handle/block-handle-popover/setup.ts","../src/components/block-handle/block-handle-popover/types.ts","../src/components/block-handle/block-handle-popover/element.gen.ts"],"sourcesContent":["import {\n createContext,\n type Context,\n} from '@aria-ui/core'\nimport type { ProseMirrorNode } from '@prosekit/pm/model'\n\n/**\n * @internal\n */\nexport interface HoverState {\n node: ProseMirrorNode\n pos: number\n}\n\n/**\n * @internal\n */\nexport type BlockPopoverContext = HoverState | null\n\n/**\n * @internal\n */\nexport const blockPopoverContext: Context<BlockPopoverContext> = createContext(\n 'prosekit-block-popover-context',\n null,\n)\n\n/**\n * @internal\n */\nexport const draggingContext: Context<boolean> = createContext(\n 'prosekit-block-handle-dragging-context',\n false,\n)\n","import {\n useEventListener,\n type ConnectableElement,\n type SignalState,\n} from '@aria-ui/core'\nimport { insertDefaultBlock } from '@prosekit/core'\n\nimport { blockPopoverContext } from '../context'\n\nimport type { BlockHandleAddProps } from './types'\n\n/**\n * @internal\n */\nexport function useBlockHandleAdd(\n host: ConnectableElement,\n { state }: { state: SignalState<BlockHandleAddProps> },\n): void {\n const context = blockPopoverContext.consume(host)\n\n useEventListener(host, 'pointerdown', (event) => {\n event.preventDefault()\n\n const editor = state.editor.get()\n const hoverState = context.get()\n if (!editor || !hoverState) {\n return\n }\n\n const { node, pos } = hoverState\n editor.exec(insertDefaultBlock({ pos: pos + node.nodeSize }))\n editor.focus()\n\n // Hide the drag handle\n context.set(null)\n })\n}\n","import type {\n EventDeclarations,\n PropDeclarations,\n} from '@aria-ui/core'\nimport type { Editor } from '@prosekit/core'\n\nexport interface BlockHandleAddProps {\n /**\n * The ProseKit editor instance.\n *\n * @default null\n * @hidden\n */\n editor: Editor | null\n}\n\n/** @internal */\nexport const blockHandleAddProps: PropDeclarations<BlockHandleAddProps> = {\n editor: { default: null },\n}\n\n/** @internal */\nexport interface BlockHandleAddEvents {}\n\n/** @internal */\nexport const blockHandleAddEvents: EventDeclarations<BlockHandleAddEvents> = {}\n","import { defineCustomElement, registerCustomElement, type BaseElementConstructor } from \"@aria-ui/core\"\n\nimport { useBlockHandleAdd } from \"./setup\"\nimport { blockHandleAddEvents, blockHandleAddProps, type BlockHandleAddEvents, type BlockHandleAddProps } from \"./types\"\n\nconst BlockHandleAddElementBase: BaseElementConstructor<BlockHandleAddProps> = defineCustomElement<\n BlockHandleAddProps,\n BlockHandleAddEvents\n>({\n props: blockHandleAddProps,\n events: blockHandleAddEvents,\n setup: useBlockHandleAdd,\n})\nclass BlockHandleAddElement extends BlockHandleAddElementBase {}\n\nregisterCustomElement('prosekit-block-handle-add', BlockHandleAddElement)\n \nexport { BlockHandleAddElement }\n","/**\n * Returns the element that has a box.\n */\nexport function getBoxElement(element: Element): Element | null | undefined {\n const window = element.ownerDocument.defaultView\n if (!window) {\n return\n }\n\n const style = window.getComputedStyle(element)\n const display = style.display\n\n if (display === 'contents' && element.childElementCount === 1) {\n return element.firstElementChild\n } else if (display === 'none') {\n return\n }\n\n return element\n}\n","/**\n * Similar to `element.getBoundingClientRect`, but handles `display: contents` elements.\n */\nexport function getClientRect(element: Element): {\n top: number\n right: number\n bottom: number\n left: number\n} {\n const rect = element.getBoundingClientRect()\n if (rect.width === 0 && rect.height === 0 && rect.x === 0 && rect.y === 0) {\n // Suspiciously rect, probably an element with `display: contents`, in\n // which case `element.getClientRects()` will return an empty array.\n if (element.getClientRects().length === 0) {\n const children = Array.from(element.children)\n const rects = children.map(child => getClientRect(child))\n if (rects.length === 0) {\n return rect\n }\n if (rects.length === 1) {\n return rects[0]\n }\n let { top, bottom, left, right } = rects[0]\n for (let i = 1; i < rects.length; i++) {\n const r = rects[i]\n if (r.top < top) top = r.top\n if (r.bottom > bottom) bottom = r.bottom\n if (r.left < left) left = r.left\n if (r.right > right) right = r.right\n }\n return { top, bottom, left, right }\n }\n }\n return rect\n}\n","// Maximum possible z-index\n// https://stackoverflow.com/questions/491052/minimum-and-maximum-value-of-z-index\nexport const maxZIndex = '2147483647'\n","import { assignStyles } from '../../../utils/assign-styles'\nimport { deepCloneElement } from '../../../utils/clone-element'\nimport { getClientRect } from '../../../utils/get-client-rect'\nimport { injectStyle } from '../../../utils/inject-style'\nimport { maxZIndex } from '../../../utils/max-z-index'\n\n/**\n * Sets a drag preview image for the given element and ensures the preview position\n * relative to the pointer is correct.\n *\n * This function does the following:\n *\n * - Creates a temporary container element.\n * - Puts the container at the end of the document body.\n * - Sets event's drag image.\n * - Removes the container from the document body after the next frame.\n */\nexport function setDragPreview(event: DragEvent, element: HTMLElement): void {\n const { top, bottom, left, right } = getClientRect(element)\n const width = right - left\n const height = bottom - top\n const elementX = left\n const elementY = top\n\n const { clientX, clientY } = event\n\n const document = element.ownerDocument\n\n const container = document.createElement('div')\n\n // If outsideX is positive, the point is at the left side of the element.\n const outsideX = Math.round(elementX - clientX)\n // If outsideY is positive, the point is above the element.\n const outsideY = Math.round(elementY - clientY)\n\n const borderX = Math.max(outsideX, 0)\n const borderY = Math.max(outsideY, 0)\n assignStyles(container, {\n // Ensuring we don't cause reflow when adding the element to the page using\n // `position:fixed` rather than `position:absolute` so we are positioned on\n // the current viewport. `position:fixed` also creates a new stacking\n // context, so we don't need to do that here.\n // https://github.com/atlassian/pragmatic-drag-and-drop/blob/56276552/packages/core/src/public-utils/element/custom-native-drag-preview/set-custom-native-drag-preview.ts#L60\n position: 'fixed',\n\n // The element is positioned off-screen to avoid capturing the content of\n // the page on Safari when the dragging element has a transparent background\n // on Safari. See https://github.com/prosekit/prosekit/issues/1153 for more\n // details.\n top: '-1000vh',\n left: '-1000vw',\n\n // The element should not be interactive.\n pointerEvents: 'none',\n\n zIndex: maxZIndex,\n\n // Only reliable cross browser technique found to push a drag preview away\n // from the cursor is to use transparent borders on the container.\n // https://github.com/atlassian/pragmatic-drag-and-drop/blob/56276552/packages/core/src/public-utils/element/custom-native-drag-preview/pointer-outside-of-preview.ts#L13-L18\n borderLeft: `${borderX}px solid transparent`,\n borderTop: `${borderY}px solid transparent`,\n\n boxSizing: 'border-box',\n width: `${width + borderX}px`,\n height: `${height + borderY}px`,\n })\n\n const [clonedElement, styleText] = deepCloneElement(element, true)\n\n // A hardcoded opacity.\n clonedElement.style.setProperty('opacity', '0.5', 'important')\n // The bounding client rect doesn't include the margin, so we need to remove\n // the margin too from the cloned element so that it can fit the container.\n clonedElement.style.setProperty('margin', '0', 'important')\n // Hide the outline of the cloned element.\n clonedElement.style.setProperty('outline-color', 'transparent', 'important')\n\n document.body.appendChild(container)\n container.appendChild(clonedElement)\n injectStyle(container, styleText)\n\n event.dataTransfer?.setDragImage(container, Math.max(-outsideX, 0), Math.max(-outsideY, 0))\n\n requestAnimationFrame(() => {\n container.remove()\n })\n}\n","import {\n useAttribute,\n useEffect,\n useEventListener,\n type ConnectableElement,\n type ReadonlySignal,\n type SignalState,\n} from '@aria-ui/core'\nimport { isHTMLElement } from '@ocavue/utils'\nimport type { Editor } from '@prosekit/core'\nimport type { ViewDragging } from '@prosekit/extensions/drop-indicator'\nimport {\n Fragment,\n Slice,\n} from '@prosekit/pm/model'\nimport { NodeSelection } from '@prosekit/pm/state'\nimport type { EditorView } from '@prosekit/pm/view'\n\nimport { getBoxElement } from '../../../utils/get-box-element'\nimport { getSafeEditorView } from '../../../utils/get-safe-editor-view'\nimport {\n blockPopoverContext,\n draggingContext,\n type BlockPopoverContext,\n type HoverState,\n} from '../context'\n\nimport { setDragPreview } from './set-drag-preview'\nimport type { BlockHandleDraggableProps } from './types'\n\n/**\n * @internal\n */\nexport function useBlockHandleDraggable(\n host: ConnectableElement,\n { state }: { state: SignalState<BlockHandleDraggableProps> },\n): void {\n const context = blockPopoverContext.consume(host)\n const dragging = draggingContext.consume(host)\n\n useEffect(host, () => {\n host.draggable = true\n })\n\n usePointerDownHandler(host, context, state.editor)\n\n useEventListener(host, 'dragstart', (event) => {\n dragging.set(true)\n\n const view = getSafeEditorView(state.editor.get())\n const hoverState = context.get()\n\n if (view && hoverState) {\n view.dom.classList.add('prosekit-dragging')\n createDraggingPreview(view, hoverState, event)\n setViewDragging(view, hoverState)\n }\n })\n\n useEventListener(host, 'dragend', () => {\n dragging.set(false)\n\n const view = getSafeEditorView(state.editor.get())\n if (view) {\n view.dom.classList.remove('prosekit-dragging')\n }\n })\n\n useAttribute(host, 'data-dragging', () => (dragging.get() ? '' : undefined))\n}\n\nfunction usePointerDownHandler(\n host: ConnectableElement,\n context: ReadonlySignal<BlockPopoverContext>,\n editor: ReadonlySignal<Editor | null>,\n) {\n useEventListener(host, 'pointerdown', () => {\n const { pos } = context.get() ?? {}\n const { view } = editor.get() ?? {}\n\n if (pos == null || view == null) {\n return\n }\n\n view.dispatch(\n view.state.tr.setSelection(NodeSelection.create(view.state.doc, pos)),\n )\n\n // Clicking the handle will blur the editor, so we need to focus it again.\n // We cannot call `event.preventDefault()` here to prevent the blur\n // because it will prevent the drag event from firing.\n requestAnimationFrame(() => {\n view.focus()\n })\n })\n}\n\nfunction createDraggingPreview(view: EditorView, hoverState: HoverState, event: DragEvent): void {\n if (!event.dataTransfer) {\n return\n }\n\n const { pos } = hoverState\n\n const element = view.nodeDOM(pos)\n if (!element || !isHTMLElement(element)) {\n return\n }\n\n const boxElement = getBoxElement(element)\n if (!boxElement || !isHTMLElement(boxElement)) {\n return\n }\n\n event.dataTransfer.clearData()\n event.dataTransfer.setData('text/html', boxElement.outerHTML)\n event.dataTransfer.effectAllowed = 'copyMove'\n setDragPreview(event, boxElement)\n\n return\n}\n\nfunction setViewDragging(view: EditorView, hoverState: HoverState): void {\n const { node, pos } = hoverState\n\n const dragging: ViewDragging = {\n slice: new Slice(Fragment.from(node), 0, 0),\n move: true,\n node: NodeSelection.create(view.state.doc, pos),\n }\n\n view.dragging = dragging\n}\n","import type {\n EventDeclarations,\n PropDeclarations,\n} from '@aria-ui/core'\nimport type { Editor } from '@prosekit/core'\n\nexport interface BlockHandleDraggableProps {\n /**\n * The ProseKit editor instance.\n *\n * @default null\n * @hidden\n */\n editor: Editor | null\n}\n\n/** @internal */\nexport const blockHandleDraggableProps: PropDeclarations<BlockHandleDraggableProps> = {\n editor: { default: null },\n}\n\n/** @internal */\nexport interface BlockHandleDraggableEvents {}\n\n/** @internal */\nexport const blockHandleDraggableEvents: EventDeclarations<BlockHandleDraggableEvents> = {}\n","import { defineCustomElement, registerCustomElement, type BaseElementConstructor } from \"@aria-ui/core\"\n\nimport { useBlockHandleDraggable } from \"./setup\"\nimport { blockHandleDraggableEvents, blockHandleDraggableProps, type BlockHandleDraggableEvents, type BlockHandleDraggableProps } from \"./types\"\n\nconst BlockHandleDraggableElementBase: BaseElementConstructor<BlockHandleDraggableProps> = defineCustomElement<\n BlockHandleDraggableProps,\n BlockHandleDraggableEvents\n>({\n props: blockHandleDraggableProps,\n events: blockHandleDraggableEvents,\n setup: useBlockHandleDraggable,\n})\nclass BlockHandleDraggableElement extends BlockHandleDraggableElementBase {}\n\nregisterCustomElement('prosekit-block-handle-draggable', BlockHandleDraggableElement)\n \nexport { BlockHandleDraggableElement }\n","/**\n * @internal\n */\nexport function throttle<Args extends any[]>(\n callback: (...args: Args) => void,\n wait: number,\n): (...args: Args) => void {\n let lastTime = 0\n\n return (...args: Args) => {\n const now = Date.now()\n if (now - lastTime >= wait) {\n callback(...args)\n lastTime = now\n }\n }\n}\n","import type { VirtualElement } from '@floating-ui/dom'\nimport {\n isElement,\n isHTMLElement,\n isTextNode,\n} from '@ocavue/utils'\nimport {\n defineDOMEventHandler,\n union,\n type PlainExtension,\n} from '@prosekit/core'\nimport type { ProseMirrorNode } from '@prosekit/pm/model'\nimport type { EditorView } from '@prosekit/pm/view'\n\nimport { getClientRect } from '../../../utils/get-client-rect'\nimport { throttle } from '../../../utils/throttle'\nimport type { HoverState } from '../context'\n\nexport type ElementHoverHandler = (\n reference: VirtualElement | null,\n hoverState: HoverState | null,\n) => void\n\nexport function defineElementHoverHandler(handler: ElementHoverHandler): PlainExtension {\n const handleElement = (\n node: ProseMirrorNode,\n pos: number,\n element: HTMLElement,\n parentElement?: Node | null,\n ) => {\n const reference: VirtualElement = {\n contextElement: element,\n\n getBoundingClientRect: () => {\n const rect = findFirstLineRect(parentElement, element)\n return rect ? fulfillRect(rect) : fallbackRect\n },\n }\n\n handler(reference, { node, pos })\n }\n\n let lastX = -1\n let lastY = -1\n let lastTime = -1\n\n const handlePointerEvent = (view: EditorView, event: PointerEvent) => {\n const { x, y } = event\n\n // Simple performance optimization. If the pointer is not moving, we don't\n // want to recalculate the block handle position within a short period of\n // time window.\n if (lastX === x && lastY === y) {\n const now = Date.now()\n if (now - lastTime < 100) {\n return\n }\n lastTime = now\n }\n lastX = x\n lastY = y\n\n const block = findBlockByCoords(view, x, y)\n if (!block) {\n handler(null, null)\n return\n }\n\n const { node, pos } = block\n const element = view.nodeDOM(pos)\n if (!element || !isHTMLElement(element)) {\n handler(null, null)\n return\n }\n\n // If `node` is the first child of another non-doc block node, for example a\n // list node or a blockquote node, we want to put the block handle agains\n // the parent node.\n const $pos = view.state.doc.resolve(pos)\n if ($pos.depth > 0 && $pos.index($pos.depth) === 0) {\n const parentPos = $pos.before($pos.depth)\n const parentNode = $pos.parent\n const parentElement = view.nodeDOM(parentPos)\n handleElement(parentNode, parentPos, element, parentElement)\n } else {\n handleElement(node, pos, element)\n }\n }\n\n return union(\n defineDOMEventHandler('pointermove', throttle(handlePointerEvent, 200)),\n defineDOMEventHandler('pointerenter', handlePointerEvent),\n defineDOMEventHandler('pointerout', handlePointerEvent),\n defineDOMEventHandler('keypress', () => handler(null, null)),\n )\n}\n\nfunction findBlockByCoords(view: EditorView, x: number, y: number): { node: ProseMirrorNode; pos: number } | undefined {\n const rect = getClientRect(view.dom)\n if (!isWithinRect(rect, x, y)) {\n return\n }\n\n let parent: ProseMirrorNode | undefined = view.state.doc\n let pos = -1\n\n while (parent) {\n if (parent.isBlock && (parent.isTextblock || parent.isAtom || parent.type.spec.isolating)) {\n return { node: parent, pos }\n }\n\n // Collect all children and their positions\n const children: ProseMirrorNode[] = []\n const positions: number[] = []\n parent.forEach((child, offset) => {\n children.push(child)\n positions.push(offset + pos + 1)\n })\n\n let lo = 0\n let hi = children.length - 1\n\n while (lo <= hi) {\n const i = hi - ((hi - lo) >> 1)\n const childDOM = view.nodeDOM(positions[i])\n const childRect = getNodeRect(childDOM)\n if (!childRect) {\n console.warn(`[prosekit] Unable to get rect at position: ${positions[i]}`)\n return\n }\n if (childRect.top > y) {\n hi = i - 1\n } else if (childRect.bottom < y) {\n lo = i + 1\n } else {\n lo = i\n break\n }\n }\n\n if (lo > hi) {\n return\n }\n\n parent = children[lo]\n pos = positions[lo]\n }\n}\n\nfunction getNodeRect(node: Node | null | undefined): Rect | undefined {\n if (node && isElement(node) && node.isConnected) {\n return getClientRect(node)\n }\n}\n\nfunction isWithinRect(rect: Rect, x: number, y: number) {\n return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom\n}\n\ninterface Rect {\n top: number\n right: number\n bottom: number\n left: number\n}\n\nfunction findFirstLineRect(outer?: Node | null, inner?: Node | null): Rect | undefined {\n if (outer && !outer.isConnected) {\n return\n }\n if (inner && !inner.isConnected) {\n return\n }\n\n if (outer && inner) {\n const outerRect = findOuterRect(outer)\n const innerRect = findFirstLineRectInNode(inner)\n if (outerRect && innerRect) {\n const { top, bottom } = innerRect\n const { left, right } = outerRect\n return { top, bottom, left, right }\n } else {\n return outerRect || innerRect\n }\n } else if (outer) {\n return findFirstLineRectInNode(outer)\n } else if (inner) {\n return findFirstLineRectInNode(inner)\n }\n}\n\nfunction findOuterRect(node: Node): Rect | undefined {\n if (!isElement(node)) {\n return\n }\n\n const rect = getClientRect(node)\n const style = node.ownerDocument.defaultView?.getComputedStyle(node)\n const marginLeft = style && Number.parseInt(style.marginLeft, 10) || 0\n const marginRight = style && Number.parseInt(style.marginRight, 10) || 0\n const left = rect.left - marginLeft\n const right = rect.right + marginRight\n\n return { top: rect.top, bottom: rect.bottom, left, right }\n}\n\nfunction findFirstLineRectInNode(node: Node): Rect | undefined {\n if (isElement(node)) {\n return findFirstLineRectInElement(node)\n } else if (isTextNode(node)) {\n return findFirstLineRectInTextNode(node)\n }\n}\n\nfunction findFirstLineRectInTextNode(node: Text): Rect | undefined {\n const ownerDocument = node.ownerDocument\n if (!ownerDocument) {\n return\n }\n const range = ownerDocument.createRange()\n range.setStart(node, 0)\n range.setEnd(node, 0)\n const rects = range.getClientRects()\n return rects[0]\n}\n\nfunction findFirstLineRectInElement(element: Element): Rect | undefined {\n if (element.nodeName === 'BR') {\n return element.getBoundingClientRect()\n }\n\n const rect = getClientRect(element)\n const style = element.ownerDocument.defaultView?.getComputedStyle(element)\n const marginLeft = style && Number.parseInt(style.marginLeft, 10) || 0\n const marginRight = style && Number.parseInt(style.marginRight, 10) || 0\n const left = rect.left - marginLeft\n const right = rect.right + marginRight\n\n const lineHeight = style && Number.parseInt(style.lineHeight, 10) || 24\n const paddingTop = style && Number.parseInt(style.paddingTop, 10) || 0\n const borderTop = style && Number.parseInt(style.borderTopWidth, 10) || 0\n const top = rect.top + paddingTop + borderTop\n const bottom = top + lineHeight\n\n return { top, bottom, left, right }\n}\n\nfunction fulfillRect({ top, right, bottom, left }: Rect) {\n return { top, right, bottom, left, width: right - left, height: bottom - top, x: left, y: top }\n}\n\n// A fallback rect that is far away from the screen. It should not be used through.\nconst fallbackRect = Object.freeze({\n top: -9999,\n right: -9999,\n bottom: -9999,\n left: -9999,\n width: 0,\n height: 0,\n x: -9999,\n y: -9999,\n})\n","import {\n createComputed,\n createSignal,\n useAttribute,\n type ConnectableElement,\n type ReadonlySignal,\n type SetupOptions,\n} from '@aria-ui/core'\nimport { useOverlayPositionerState } from '@aria-ui/overlay/elements'\nimport { usePresence } from '@aria-ui/presence'\nimport type { VirtualElement } from '@floating-ui/dom'\nimport type { Editor } from '@prosekit/core'\n\nimport { useEditorExtension } from '../../../hooks/use-editor-extension'\nimport { useScrolling } from '../../../hooks/use-scrolling'\nimport {\n blockPopoverContext,\n draggingContext,\n type BlockPopoverContext,\n type HoverState,\n} from '../context'\n\nimport {\n defineElementHoverHandler,\n type ElementHoverHandler,\n} from './pointer-move'\nimport type {\n BlockHandlePopoverEvents,\n BlockHandlePopoverProps,\n} from './types'\n\n/**\n * @internal\n */\nexport function useBlockHandlePopover(\n host: ConnectableElement,\n { state, emit }: SetupOptions<BlockHandlePopoverProps, BlockHandlePopoverEvents>,\n): void {\n const { editor, ...overlayState } = state\n const reference = createSignal<VirtualElement | null>(null)\n useOverlayPositionerState(host, overlayState, { reference })\n\n const context = createSignal<BlockPopoverContext>(null)\n blockPopoverContext.provide(host, context)\n\n const dragging = createSignal(false)\n draggingContext.provide(host, dragging)\n\n const scrolling = useScrolling(host)\n const open = createComputed(() => {\n return !!context.get() && !scrolling.get()\n })\n\n useHoverExtension(host, editor, (referenceValue, hoverState) => {\n reference.set(referenceValue)\n context.set(hoverState)\n const stateChangeDetails = hoverState ? { node: hoverState.node, pos: hoverState.pos } : null\n emit('stateChange', stateChangeDetails)\n })\n\n useAttribute(host, 'data-state', () => (open.get() ? 'open' : 'closed'))\n usePresence(host, open)\n}\n\nfunction useHoverExtension(\n host: ConnectableElement,\n editor: ReadonlySignal<Editor | null>,\n handler: ElementHoverHandler,\n) {\n let prevHoverState: HoverState | null = null\n\n const extension = defineElementHoverHandler((reference, hoverState) => {\n if (isHoverStateEqual(prevHoverState, hoverState)) {\n return\n }\n\n prevHoverState = hoverState\n handler(reference, hoverState)\n })\n\n useEditorExtension(host, editor, extension)\n}\n\nfunction isHoverStateEqual(a: HoverState | null, b: HoverState | null) {\n if (!a && !b) return true\n if (!a || !b) return false\n return a.pos === b.pos && a.node.eq(b.node)\n}\n","import type {\n EventDeclarations,\n PropDeclarations,\n} from '@aria-ui/core'\nimport {\n overlayPositionerEvents,\n overlayPositionerProps,\n type OverlayPositionerEvents,\n type OverlayPositionerProps,\n} from '@aria-ui/overlay/elements'\nimport type { Placement } from '@floating-ui/dom'\nimport type { Editor } from '@prosekit/core'\nimport type { ProseMirrorNode } from '@prosekit/pm/model'\n\nexport interface BlockHandlePopoverProps extends Omit<OverlayPositionerProps, 'placement' | 'hoist' | 'flip' | 'shift' | 'hide'> {\n /**\n * The ProseKit editor instance.\n *\n * @default null\n * @hidden\n */\n editor: Editor | null\n\n /**\n * The placement of the popover, relative to the hovered block.\n *\n * @default \"left\"\n */\n placement: Placement\n\n /**\n * Whether to use the browser [Popover API](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API)\n * to place the floating element on top of other page content.\n *\n * @default false\n */\n hoist: boolean\n\n /**\n * @default false\n * @hidden\n */\n flip: boolean\n\n /**\n * @default false\n * @hidden\n */\n shift: boolean\n\n /**\n * @default true\n * @hidden\n */\n hide: boolean\n}\n\n/** @internal */\nexport const blockHandlePopoverProps: PropDeclarations<BlockHandlePopoverProps> = {\n ...overlayPositionerProps,\n editor: { default: null },\n placement: { default: 'left' },\n\n // Enabling `hoist` will cause the popover to have a small delay when\n // scrolling the page.\n hoist: { default: false },\n\n flip: { default: false },\n shift: { default: false },\n hide: { default: true },\n}\n\nexport interface BlockHandlePopoverEvents extends OverlayPositionerEvents {\n /**\n * Fired when the hovered block changes.\n */\n stateChange: CustomEvent<{ node: ProseMirrorNode; pos: number } | null>\n}\n\n/** @internal */\nexport const blockHandlePopoverEvents: EventDeclarations<BlockHandlePopoverEvents> = {\n ...overlayPositionerEvents,\n stateChange: {},\n}\n","import { defineCustomElement, registerCustomElement, type BaseElementConstructor } from \"@aria-ui/core\"\n\nimport { useBlockHandlePopover } from \"./setup\"\nimport { blockHandlePopoverEvents, blockHandlePopoverProps, type BlockHandlePopoverEvents, type BlockHandlePopoverProps } from \"./types\"\n\nconst BlockHandlePopoverElementBase: BaseElementConstructor<BlockHandlePopoverProps> = defineCustomElement<\n BlockHandlePopoverProps,\n BlockHandlePopoverEvents\n>({\n props: blockHandlePopoverProps,\n events: blockHandlePopoverEvents,\n setup: useBlockHandlePopover,\n})\nclass BlockHandlePopoverElement extends BlockHandlePopoverElementBase {}\n\nregisterCustomElement('prosekit-block-handle-popover', BlockHandlePopoverElement)\n \nexport { BlockHandlePopoverElement }\n"],"mappings":";;;;;;;;;;;;;;;;AAsBA,MAAaA,sBAAoD,cAC/D,kCACA,KACD;;;;AAKD,MAAaC,kBAAoC,cAC/C,0CACA,MACD;;;;;;;ACnBD,SAAgB,kBACd,MACA,EAAE,SACI;CACN,MAAM,UAAU,oBAAoB,QAAQ,KAAK;AAEjD,kBAAiB,MAAM,gBAAgB,UAAU;AAC/C,QAAM,gBAAgB;EAEtB,MAAM,SAAS,MAAM,OAAO,KAAK;EACjC,MAAM,aAAa,QAAQ,KAAK;AAChC,MAAI,CAAC,UAAU,CAAC,WACd;EA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AAG,EAAE,KAAK;;;;;;AC5B7C,MAAaC,0BAAqE;CAChF,GAAG;CACH,QAAQ,EAAE,SAAS,MAAM;CACzB,WAAW,EAAE,SAAS,QAAQ;CAI9B,OAAO,EAAE,SAAS,OAAO;CAEzB,MAAM,EAAE,SAAS,OAAO;CACxB,OAAO,EAAE,SAAS,OAAO;CACzB,MAAM,EAAE,SAAS,MAAM;CACxB;;AAUD,MAAaC,2BAAwE;CACnF,GAAG;CACH,aAAa,EAAE;CAChB;;;;AC9ED,MAAMC,gCAAiF,oBAGrF;CACA,OAAO;CACP,QAAQ;CACR,OAAO;CACR,CAAC;AACF,IAAM,4BAAN,cAAwC,8BAA8B;AAEtE,sBAAsB,iCAAiC,0BAA0B"}
@@ -35,4 +35,5 @@ declare function useDropIndicator(host: ConnectableElement, {
35
35
  state
36
36
  }: SetupOptions<DropIndicatorProps, DropIndicatorEvents>): void;
37
37
  //#endregion
38
- export { DropIndicatorElement, type DropIndicatorEvents, type DropIndicatorProps, dropIndicatorEvents, dropIndicatorProps, useDropIndicator };
38
+ export { DropIndicatorElement, type DropIndicatorEvents, type DropIndicatorProps, dropIndicatorEvents, dropIndicatorProps, useDropIndicator };
39
+ //# sourceMappingURL=prosekit-web-drop-indicator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prosekit-web-drop-indicator.d.ts","names":[],"sources":["../src/components/drop-indicator/drop-indicator/types.ts","../src/components/drop-indicator/drop-indicator/element.gen.ts","../src/components/drop-indicator/drop-indicator/setup.ts"],"sourcesContent":[],"mappings":";;;;UAMiB,kBAAA;;AAAjB;AAkBA;AAKA;AAIA;;UApBU;;ACV0G;AAE9D;;;;ACoBtD;;AAEI,cFHS,kBEGT,EFH6B,gBEG7B,CFH8C,kBEG9C,CAAA;AAAsB,UFET,mBAAA,CEFS;;AAAD,cFMZ,mBENY,EFMS,iBENT,CFM2B,mBEN3B,CAAA;;;cDtBnB,0BAA0B,uBAAuB;cAQjD,oBAAA,SAA6B,wBAAA;;;;;ADPnC;AAkBa,iBECG,gBAAA,CFDkC,IAAA,EEE1C,kBFFyB,EAAA;EAAA;AAAgB,CAAA,EEGpC,YFHoC,CEGvB,kBFHuB,EEGH,mBFHG,CAAA,CAAA,EAAA,IAAA"}
@@ -1,5 +1,5 @@
1
- import { useEditorExtension } from "./use-editor-extension-Cc7ZG7uj.js";
2
- import { assignStyles, useScrolling } from "./use-scrolling-BNfsQs3S.js";
1
+ import { t as useEditorExtension } from "./use-editor-extension-B2WuUfnd.js";
2
+ import { n as assignStyles, t as useScrolling } from "./use-scrolling-BOvyjDvH.js";
3
3
  import { createComputed, createSignal, defineCustomElement, registerCustomElement, useEffect } from "@aria-ui/core";
4
4
  import { usePresence } from "@aria-ui/presence";
5
5
  import { defineDropIndicator } from "@prosekit/extensions/drop-indicator";
@@ -17,10 +17,9 @@ function useDropIndicator(host, { state }) {
17
17
  useEditorExtension(host, state.editor, extension);
18
18
  const line = createComputed(() => context.get()?.line);
19
19
  const scrolling = useScrolling(host);
20
- const presence = createComputed(() => {
20
+ usePresence(host, createComputed(() => {
21
21
  return !!context.get() && !scrolling.get();
22
- });
23
- usePresence(host, presence);
22
+ }));
24
23
  useEffect(host, () => {
25
24
  const lineValue = line.get();
26
25
  const lineWidth = state.width.get();
@@ -75,4 +74,5 @@ var DropIndicatorElement = class extends DropIndicatorElementBase {};
75
74
  registerCustomElement("prosekit-drop-indicator", DropIndicatorElement);
76
75
 
77
76
  //#endregion
78
- export { DropIndicatorElement, dropIndicatorEvents, dropIndicatorProps, useDropIndicator };
77
+ export { DropIndicatorElement, dropIndicatorEvents, dropIndicatorProps, useDropIndicator };
78
+ //# sourceMappingURL=prosekit-web-drop-indicator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prosekit-web-drop-indicator.js","names":["width: number","height: number","top: number","left: number","dropIndicatorProps: PropDeclarations<DropIndicatorProps>","dropIndicatorEvents: EventDeclarations<DropIndicatorEvents>","DropIndicatorElementBase: BaseElementConstructor<DropIndicatorProps>"],"sources":["../src/components/drop-indicator/drop-indicator/setup.ts","../src/components/drop-indicator/drop-indicator/types.ts","../src/components/drop-indicator/drop-indicator/element.gen.ts"],"sourcesContent":["import {\n createComputed,\n createSignal,\n useEffect,\n type ConnectableElement,\n type SetupOptions,\n} from '@aria-ui/core'\nimport { usePresence } from '@aria-ui/presence'\nimport {\n defineDropIndicator,\n type ShowHandlerOptions,\n} from '@prosekit/extensions/drop-indicator'\n\nimport { useEditorExtension } from '../../../hooks/use-editor-extension'\nimport { useScrolling } from '../../../hooks/use-scrolling'\nimport { assignStyles } from '../../../utils/assign-styles'\n\nimport type {\n DropIndicatorEvents,\n DropIndicatorProps,\n} from './types'\n\n/**\n * @internal\n */\nexport function useDropIndicator(\n host: ConnectableElement,\n { state }: SetupOptions<DropIndicatorProps, DropIndicatorEvents>,\n): void {\n type DropIndicatorContext = ShowHandlerOptions | null\n const context = createSignal<DropIndicatorContext>(null)\n\n const extension = defineDropIndicator({\n onShow: (options) => context.set(options),\n onHide: () => context.set(null),\n })\n\n useEditorExtension(host, state.editor, extension)\n\n const line = createComputed(() => context.get()?.line)\n const scrolling = useScrolling(host)\n const presence = createComputed(() => {\n return !!context.get() && !scrolling.get()\n })\n usePresence(host, presence)\n\n useEffect(\n host,\n () => {\n const lineValue = line.get()\n const lineWidth = state.width.get()\n\n if (!lineValue) return\n\n const { p1: { x: x1, y: y1 }, p2: { x: x2, y: y2 } } = lineValue\n const horizontal = y1 === y2\n\n let width: number\n let height: number\n let top: number = y1\n let left: number = x1\n\n if (horizontal) {\n width = x2 - x1\n height = lineWidth\n top -= lineWidth / 2\n } else {\n width = lineWidth\n height = y2 - y1\n left -= lineWidth / 2\n }\n\n top = Math.round(top)\n left = Math.round(left)\n\n assignStyles(host, {\n position: 'fixed',\n pointerEvents: 'none',\n width: `${width}px`,\n height: `${height}px`,\n transform: `translate(${left}px, ${top}px)`,\n left: '0px',\n top: '0px',\n })\n },\n )\n}\n","import type {\n EventDeclarations,\n PropDeclarations,\n} from '@aria-ui/core'\nimport type { Editor } from '@prosekit/core'\n\nexport interface DropIndicatorProps {\n /**\n * The ProseKit editor instance.\n *\n * @default null\n * @hidden\n */\n editor: Editor | null\n\n /**\n * The line width in pixels.\n *\n * @default 2\n */\n width: number\n}\n\n/** @internal */\nexport const dropIndicatorProps: PropDeclarations<DropIndicatorProps> = Object.freeze({\n editor: { default: null },\n width: { default: 2 },\n})\n\nexport interface DropIndicatorEvents {\n}\n\n/** @internal */\nexport const dropIndicatorEvents: EventDeclarations<DropIndicatorEvents> = {}\n","import { defineCustomElement, registerCustomElement, type BaseElementConstructor } from \"@aria-ui/core\"\n\nimport { useDropIndicator } from \"./setup\"\nimport { dropIndicatorEvents, dropIndicatorProps, type DropIndicatorEvents, type DropIndicatorProps } from \"./types\"\n\nconst DropIndicatorElementBase: BaseElementConstructor<DropIndicatorProps> = defineCustomElement<\n DropIndicatorProps,\n DropIndicatorEvents\n>({\n props: dropIndicatorProps,\n events: dropIndicatorEvents,\n setup: useDropIndicator,\n})\nclass DropIndicatorElement extends DropIndicatorElementBase {}\n\nregisterCustomElement('prosekit-drop-indicator', DropIndicatorElement)\n \nexport { DropIndicatorElement }\n"],"mappings":";;;;;;;;;;AAyBA,SAAgB,iBACd,MACA,EAAE,SACI;CAEN,MAAM,UAAU,aAAmC,KAAK;CAExD,MAAM,YAAY,oBAAoB;EACpC,SAAS,YAAY,QAAQ,IAAI,QAAQ;EACzC,cAAc,QAAQ,IAAI,KAAK;EAChC,CAAC;AAEF,oBAAmB,MAAM,MAAM,QAAQ,UAAU;CAEjD,MAAM,OAAO,qBAAqB,QAAQ,KAAK,EAAE,KAAK;CACtD,MAAM,YAAY,aAAa,KAAK;AAIpC,aAAY,MAHK,qBAAqB;AACpC,SAAO,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,UAAU,KAAK;GAC1C,CACyB;AAE3B,WACE,YACM;EACJ,MAAM,YAAY,KAAK,KAAK;EAC5B,MAAM,YAAY,MAAM,MAAM,KAAK;AAEnC,MAAI,CAAC,UAAW;EAEhB,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,GAAG,MAAM,IAAI,EAAE,GAAG,IAAI,GAAG,SAAS;EACvD,MAAM,aAAa,OAAO;EAE1B,IAAIA;EACJ,IAAIC;EACJ,IAAIC,MAAc;EAClB,IAAIC,OAAe;AAEnB,MAAI,YAAY;AACd,WAAQ,KAAK;AACb,YAAS;AACT,UAAO,YAAY;SACd;AACL,WAAQ;AACR,YAAS,KAAK;AACd,WAAQ,YAAY;;AAGtB,QAAM,KAAK,MAAM,IAAI;AACrB,SAAO,KAAK,MAAM,KAAK;AAEvB,eAAa,MAAM;GACjB,UAAU;GACV,eAAe;GACf,OAAO,GAAG,MAAM;GAChB,QAAQ,GAAG,OAAO;GAClB,WAAW,aAAa,KAAK,MAAM,IAAI;GACvC,MAAM;GACN,KAAK;GACN,CAAC;GAEL;;;;;;AC7DH,MAAaC,qBAA2D,OAAO,OAAO;CACpF,QAAQ,EAAE,SAAS,MAAM;CACzB,OAAO,EAAE,SAAS,GAAG;CACtB,CAAC;;AAMF,MAAaC,sBAA8D,EAAE;;;;AC5B7E,MAAMC,2BAAuE,oBAG3E;CACA,OAAO;CACP,QAAQ;CACR,OAAO;CACR,CAAC;AACF,IAAM,uBAAN,cAAmC,yBAAyB;AAE5D,sBAAsB,2BAA2B,qBAAqB"}
@@ -87,4 +87,5 @@ declare function useInlinePopover(host: ConnectableElement, {
87
87
  emit
88
88
  }: SetupOptions<InlinePopoverProps, InlinePopoverEvents>): void;
89
89
  //#endregion
90
- export { InlinePopoverElement, type InlinePopoverEvents, type InlinePopoverProps, inlinePopoverEvents, inlinePopoverProps, useInlinePopover };
90
+ export { InlinePopoverElement, type InlinePopoverEvents, type InlinePopoverProps, inlinePopoverEvents, inlinePopoverProps, useInlinePopover };
91
+ //# sourceMappingURL=prosekit-web-inline-popover.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prosekit-web-inline-popover.d.ts","names":[],"sources":["../src/components/inline-popover/inline-popover/types.ts","../src/components/inline-popover/inline-popover/element.gen.ts","../src/components/inline-popover/inline-popover/setup.ts"],"sourcesContent":[],"mappings":";;;;;UAYiB,kBAAA,SACf,KACE;;AAFJ;;;;;EAyDQ,MAAA,EA7CE,MA6CF,GAAA,IAAA;EAKG;;;;;AAcX;AAeA;AAQA;;;;EC1GM;AAAgD;;;;ACsBtD;;;EAEW,IAAA,EAAA,OAAA;EAAqB;;;;;;;;;;aF8BnB;;;;UAKH;;;;QAKF;;;;WAKG;;;;UAKD;;;;mBAKS;;;cAIN,oBAAoB,iBAAiB;UAejC,mBAAA,SAA4B;;;;cAI/B;;;cAID,qBAAqB,kBAAkB;;;cC1G9C,0BAA0B,uBAAuB;cAQjD,oBAAA,SAA6B,wBAAA;;;;;;ADDlB,iBEeD,gBAAA,CFfoB,IAAA,EEgB5B,kBFhB4B,EAAA;EAAA,KAAA;EAAA;AAAA,CAAA,EEiBjB,YFjBiB,CEiBJ,kBFjBI,EEiBgB,mBFjBhB,CAAA,CAAA,EAAA,IAAA"}