@prosekit/web 0.8.0 → 0.8.2

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 (43) hide show
  1. package/dist/autocomplete.d.ts +10 -15
  2. package/dist/autocomplete.d.ts.map +1 -1
  3. package/dist/autocomplete.js +16 -9
  4. package/dist/autocomplete.js.map +1 -1
  5. package/dist/block-handle.d.ts +0 -12
  6. package/dist/block-handle.d.ts.map +1 -1
  7. package/dist/block-handle.js +0 -3
  8. package/dist/block-handle.js.map +1 -1
  9. package/dist/drop-indicator.d.ts.map +1 -1
  10. package/dist/drop-indicator.js.map +1 -1
  11. package/dist/get-safe-editor-view.js.map +1 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/inline-popover.d.ts +0 -12
  15. package/dist/inline-popover.d.ts.map +1 -1
  16. package/dist/inline-popover.js.map +1 -1
  17. package/dist/menu.d.ts.map +1 -1
  18. package/dist/menu.js.map +1 -1
  19. package/dist/popover.d.ts.map +1 -1
  20. package/dist/popover.js.map +1 -1
  21. package/dist/resizable.d.ts +0 -15
  22. package/dist/resizable.d.ts.map +1 -1
  23. package/dist/resizable.js +0 -6
  24. package/dist/resizable.js.map +1 -1
  25. package/dist/table-handle.d.ts.map +1 -1
  26. package/dist/table-handle.js.map +1 -1
  27. package/dist/tooltip.d.ts.map +1 -1
  28. package/dist/tooltip.js.map +1 -1
  29. package/dist/use-editor-extension.js.map +1 -1
  30. package/dist/use-editor-update-event.js.map +1 -1
  31. package/dist/use-scrolling.js.map +1 -1
  32. package/package.json +11 -11
  33. package/src/components/autocomplete/autocomplete-popup.ts +0 -6
  34. package/src/components/autocomplete/autocomplete-positioner.ts +1 -4
  35. package/src/components/autocomplete/autocomplete-root.ts +33 -16
  36. package/src/components/block-handle/block-handle-popup.ts +0 -3
  37. package/src/components/block-handle/block-handle-positioner.ts +0 -3
  38. package/src/components/block-handle/block-handle-root.ts +0 -6
  39. package/src/components/inline-popover/inline-popover-popup.ts +0 -3
  40. package/src/components/inline-popover/inline-popover-positioner.ts +0 -3
  41. package/src/components/inline-popover/inline-popover-root.ts +0 -6
  42. package/src/components/resizable/resizable-handle.ts +0 -3
  43. package/src/components/resizable/resizable-root.ts +0 -12
@@ -13,6 +13,7 @@ import {
13
13
  import { defaultItemFilter, type ItemFilter, type ListboxRootEvents } from '@aria-ui/elements/listbox'
14
14
  import { createOverlayStore, OpenChangeEvent, type OverlayStore } from '@aria-ui/elements/overlay'
15
15
  import { useEventListener } from '@aria-ui/utils'
16
+ import type { ReferenceElement, VirtualElement } from '@floating-ui/dom'
16
17
  import { defineDOMEventHandler, defineKeymap, withPriority, type Editor, type Extension, type Priority } from '@prosekit/core'
17
18
  import { AutocompleteRule, defineAutocomplete, type MatchHandler } from '@prosekit/extensions/autocomplete'
18
19
 
@@ -48,6 +49,16 @@ export interface AutocompleteRootProps {
48
49
  * @default defaultItemFilter
49
50
  */
50
51
  filter: ItemFilter | null
52
+
53
+ /**
54
+ * The reference to position the popup against. This can be a DOM element, a
55
+ * Floating UI virtual element, or a function that returns either of them.
56
+ * By default, the popup will be positioned against the text content that
57
+ * triggers the autocomplete.
58
+ *
59
+ * @default null
60
+ */
61
+ anchor: Element | VirtualElement | (() => Element | VirtualElement | null) | null
51
62
  }
52
63
 
53
64
  /** @internal */
@@ -57,11 +68,9 @@ export const AutocompleteRootPropsDeclaration: PropsDeclaration<AutocompleteRoot
57
68
  editor: { default: null, attribute: false },
58
69
  regex: { default: null, attribute: false },
59
70
  filter: { default: defaultItemFilter, attribute: false },
71
+ anchor: { default: null, attribute: false },
60
72
  })
61
73
 
62
- /**
63
- * @public
64
- */
65
74
  export class QueryChangeEvent extends Event {
66
75
  /**
67
76
  * The current query string.
@@ -74,9 +83,6 @@ export class QueryChangeEvent extends Event {
74
83
  }
75
84
  }
76
85
 
77
- /**
78
- * @public
79
- */
80
86
  export interface AutocompleteRootEvents extends ListboxRootEvents {
81
87
  /**
82
88
  * Fired when the open state changes.
@@ -95,7 +101,7 @@ interface RuleHandlers {
95
101
  }
96
102
 
97
103
  interface AutocompleteRuleDeps {
98
- reference: Signal<Element | undefined>
104
+ reference: Signal<ReferenceElement | undefined>
99
105
  handlers: RuleHandlers
100
106
  setQuery: (next: string) => void
101
107
  requestOpenChange: (open: boolean) => void
@@ -110,7 +116,7 @@ export function setupAutocompleteRoot(
110
116
  ): void {
111
117
  const getEditor = props.editor.get
112
118
 
113
- const reference = createSignal<Element | undefined>(undefined)
119
+ const reference = createSignal<ReferenceElement | undefined>(undefined)
114
120
  const open = createSignal(false)
115
121
  const query = createSignal('')
116
122
  const keyboardTarget = new KeyboardEventTarget()
@@ -159,7 +165,20 @@ export function setupAutocompleteRoot(
159
165
  host.dispatchEvent(new QueryChangeEvent(next))
160
166
  }
161
167
 
162
- useAutocompleteExtension(host, getEditor, props.regex.get, {
168
+ const getAnchor = (): ReferenceElement | null => {
169
+ const customAnchor = props.anchor.get()
170
+ if (customAnchor) {
171
+ if (typeof customAnchor === 'function') {
172
+ return customAnchor() || null
173
+ } else {
174
+ return customAnchor
175
+ }
176
+ }
177
+ const view = getSafeEditorView(getEditor())
178
+ return view?.dom.querySelector('.prosekit-autocomplete-match') || null
179
+ }
180
+
181
+ useAutocompleteExtension(host, getEditor, props.regex.get, getAnchor, {
163
182
  reference,
164
183
  handlers,
165
184
  setQuery,
@@ -202,6 +221,7 @@ function useAutocompleteExtension(
202
221
  host: HostElement,
203
222
  getEditor: () => Editor | null,
204
223
  getRegex: () => RegExp | null,
224
+ getAnchor: () => ReferenceElement | null,
205
225
  deps: AutocompleteRuleDeps,
206
226
  ) {
207
227
  useEffect(host, () => {
@@ -212,7 +232,7 @@ function useAutocompleteExtension(
212
232
  return
213
233
  }
214
234
 
215
- const rule = createAutocompleteRule(editor, regex, deps)
235
+ const rule = createAutocompleteRule(editor, regex, getAnchor, deps)
216
236
  const extension = defineAutocomplete(rule)
217
237
  return editor.use(extension)
218
238
  })
@@ -221,17 +241,14 @@ function useAutocompleteExtension(
221
241
  function createAutocompleteRule(
222
242
  editor: Editor,
223
243
  regex: RegExp,
244
+ getAnchor: () => ReferenceElement | null,
224
245
  deps: AutocompleteRuleDeps,
225
246
  ) {
226
247
  const { reference, handlers, setQuery, requestOpenChange } = deps
227
248
 
228
249
  const handleEnter: MatchHandler = (options) => {
229
- const view = getSafeEditorView(editor)
230
- const span = view?.dom.querySelector('.prosekit-autocomplete-match')
231
-
232
- if (span) {
233
- reference.set(span)
234
- }
250
+ const anchor = getAnchor()
251
+ reference.set(anchor || undefined)
235
252
 
236
253
  handlers.submit = options.deleteMatch
237
254
  handlers.dismiss = options.ignoreMatch
@@ -10,9 +10,6 @@ import { OverlayPopupPropsDeclaration, setupOverlayPopup, type OverlayPopupProps
10
10
 
11
11
  import { blockHandleOverlayStoreContext } from './context.ts'
12
12
 
13
- /**
14
- * @public
15
- */
16
13
  export interface BlockHandlePopupProps extends OverlayPopupProps {}
17
14
 
18
15
  /** @internal */
@@ -12,9 +12,6 @@ import type { Placement } from '@floating-ui/dom'
12
12
 
13
13
  import { blockHandleOverlayStoreContext } from './context.ts'
14
14
 
15
- /**
16
- * @public
17
- */
18
15
  export interface BlockHandlePositionerProps extends Omit<OverlayPositionerProps, 'placement' | 'hoist' | 'flip' | 'shift' | 'hide'> {
19
16
  /**
20
17
  * The placement of the popover, relative to the hovered block.
@@ -38,9 +38,6 @@ export const BlockHandleRootPropsDeclaration: PropsDeclaration<BlockHandleRootPr
38
38
  editor: { default: null, attribute: false },
39
39
  })
40
40
 
41
- /**
42
- * @public
43
- */
44
41
  export class BlockHandleStateChangeEvent extends Event {
45
42
  /**
46
43
  * The currently hovered block's node and position, or `null` if no block is hovered.
@@ -52,9 +49,6 @@ export class BlockHandleStateChangeEvent extends Event {
52
49
  }
53
50
  }
54
51
 
55
- /**
56
- * @public
57
- */
58
52
  export interface BlockHandleRootEvents {
59
53
  /**
60
54
  * Fired when the hovered block changes.
@@ -13,9 +13,6 @@ import { usePresence } from '@aria-ui/utils'
13
13
 
14
14
  import { InlinePopoverStoreContext } from './store.ts'
15
15
 
16
- /**
17
- * @public
18
- */
19
16
  export interface InlinePopoverPopupProps extends OverlayPopupProps {}
20
17
 
21
18
  /** @internal */
@@ -11,9 +11,6 @@ import { OverlayPositionerPropsDeclaration, setupOverlayPositioner, type Overlay
11
11
 
12
12
  import { InlinePopoverStoreContext } from './store.ts'
13
13
 
14
- /**
15
- * @public
16
- */
17
14
  export interface InlinePopoverPositionerProps extends
18
15
  Omit<
19
16
  OverlayPositionerProps,
@@ -19,9 +19,6 @@ import { useKeymap } from '../../hooks/use-keymap.ts'
19
19
  import { InlinePopoverStoreContext } from './store.ts'
20
20
  import { getVirtualSelectionElement } from './virtual-selection-element.ts'
21
21
 
22
- /**
23
- * @public
24
- */
25
22
  export interface InlinePopoverRootProps extends OverlayRootProps {
26
23
  /**
27
24
  * The ProseKit editor instance.
@@ -58,9 +55,6 @@ export const InlinePopoverRootPropsDeclaration: PropsDeclaration<InlinePopoverRo
58
55
  dismissOnEscape: { default: true, attribute: 'dismiss-on-escape', type: 'boolean' },
59
56
  })
60
57
 
61
- /**
62
- * @public
63
- */
64
58
  export interface InlinePopoverRootEvents {
65
59
  /**
66
60
  * Emitted when the open state of the popover changes.
@@ -5,9 +5,6 @@ import { getWindow } from '@ocavue/utils'
5
5
  import { calcResize } from './calc-resize.ts'
6
6
  import { onResizeContext, onResizeEndContext, onResizeStartContext } from './context.ts'
7
7
 
8
- /**
9
- * @public
10
- */
11
8
  export interface ResizableHandleProps {
12
9
  /**
13
10
  * The position of the handle.
@@ -13,9 +13,6 @@ import {
13
13
  type OnResizeStart,
14
14
  } from './context.ts'
15
15
 
16
- /**
17
- * @public
18
- */
19
16
  export interface ResizableRootProps {
20
17
  /**
21
18
  * The width of the resizable element.
@@ -48,9 +45,6 @@ export const ResizableRootPropsDeclaration: PropsDeclaration<ResizableRootProps>
48
45
  aspectRatio: { default: null, attribute: 'data-aspect-ratio', type: 'json' },
49
46
  })
50
47
 
51
- /**
52
- * @public
53
- */
54
48
  export interface ResizableRootEvents {
55
49
  /**
56
50
  * Emitted when a resize operation starts.
@@ -63,9 +57,6 @@ export interface ResizableRootEvents {
63
57
  resizeEnd: ResizeEndEvent
64
58
  }
65
59
 
66
- /**
67
- * @public
68
- */
69
60
  export class ResizeStartEvent extends Event {
70
61
  readonly detail: {
71
62
  readonly width: number
@@ -77,9 +68,6 @@ export class ResizeStartEvent extends Event {
77
68
  }
78
69
  }
79
70
 
80
- /**
81
- * @public
82
- */
83
71
  export class ResizeEndEvent extends Event {
84
72
  readonly detail: {
85
73
  readonly width: number