@prosekit/web 0.7.7 → 0.7.8

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.
@@ -227,7 +227,7 @@ function useAutocompleteExtension(host, editor, regex, reference, query, onDismi
227
227
  }
228
228
  function createAutocompleteRule(editor, regex, reference, query, onDismiss, onSubmit) {
229
229
  const handleEnter = (options) => {
230
- const span = getSafeEditorView(editor)?.dom.querySelector(".prosemirror-prediction-match");
230
+ const span = getSafeEditorView(editor)?.dom.querySelector(".prosekit-autocomplete-match");
231
231
  if (span) reference.set(span);
232
232
  query.set(defaultQueryBuilder(options.match));
233
233
  onDismiss.set(options.ignoreMatch);
@@ -1 +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":";;;;;;;;;;;;;;;AAKA,MAAaA,uBAA+C;;;;;ACI5D,MAAaC,yBAAmE,EAAE;;AAMlF,MAAaC,0BAAsE,EAAE;;;;ACVrF,MAAMC,+BAA+E,oBAGnF;CACA,OAAO;CACP,QAAQ;CACR,OAAO;CACR,CAAC;AACF,IAAM,2BAAN,cAAuC,6BAA6B;AAEpE,sBAAsB,+BAA+B,yBAAyB;;;;ACV9E,MAAaC,eAAgC,cAC3C,uCACA,GACD;AAED,MAAaC,kBAAgD,cAC3D,0CACA,KACD;AAED,MAAaC,cAAgC,cAC3C,sCACA,MACD;;;;;;;ACAD,SAAgB,oBACd,SACA,EAAE,OAAO,QACH;AACN,gBAAe,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C,+BAA+B;AAExE,sBAAsB,iCAAiC,2BAA2B"}
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('.prosekit-autocomplete-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":";;;;;;;;;;;;;;;AAKA,MAAaA,uBAA+C;;;;;ACI5D,MAAaC,yBAAmE,EAAE;;AAMlF,MAAaC,0BAAsE,EAAE;;;;ACVrF,MAAMC,+BAA+E,oBAGnF;CACA,OAAO;CACP,QAAQ;CACR,OAAO;CACR,CAAC;AACF,IAAM,2BAAN,cAAuC,6BAA6B;AAEpE,sBAAsB,+BAA+B,yBAAyB;;;;ACV9E,MAAaC,eAAgC,cAC3C,uCACA,GACD;AAED,MAAaC,kBAAgD,cAC3D,0CACA,KACD;AAED,MAAaC,cAAgC,cAC3C,sCACA,MACD;;;;;;;ACAD,SAAgB,oBACd,SACA,EAAE,OAAO,QACH;AACN,gBAAe,SAAS;EAAE;EAAO;EAAM,CAAC;CAExC,MAAM,OAAO,YAAY,QAAQ,QAAQ;AAEzC,WAAU,eAAe;AAEvB,MAAI,CAAC,MAAM,MAAM,MAAM,IAAI,KAAK,KAAK,CACnC,OAAM,MAAM,IAAI,QAAQ,eAAe,GAAG;GAE5C;AAEF,kBAAiB,SAAS,gBAAgB,UAAU;AAElD,QAAM,gBAAgB;GACtB;;;;;;ACfJ,MAAaC,wBAAiE,EAC5E,OAAO,EACL,SAAS,IACV,EACF;;AAKD,MAAaC,yBAAoE;;;;ACzBjF,MAAMC,8BAA6E,oBAGjF;CACA,OAAO;CACP,QA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,SACA;AACA,cAAsB;AACpB,MAAI,CAAC,QAAQ,KAAK,CAChB,QAAO;EAGT,MAAM,KAAK,QAAQ,MAAM;AACzB,MAAI,CAAC,GAAI,QAAO;AAChB,MAAI;AACJ,SAAO;;;AAIX,SAAS,iBACP,MACA,QACA,SACM;AAGN,oBAAmB,MAAM,QADP,aAAa,aADhB,EAAE,QAAQ,SAAS,CACiB,EAAE,SAAS,QAAQ,CAC3B;;;;;AClH7C,MAAM,kBADO,OAAO,aAAa,eAAe,SAAS,cAAc,OAAO,IAC9C;;AAGhC,MAAaC,2BAAuE;CAClF,GAAG;CACH,QAAQ,EAAE,SAAS,MAAM;CACzB,OAAO,EAAE,SAAS,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"}
@@ -1 +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"}
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;;;;ACuBtD;;;EAEW,IAAA,EAAA,OAAA;EAAqB;;;;;;;;;;aF6BnB;;;;UAKH;;;;QAKF;;;;WAKG;;;;UAKD;;;;mBAKS;;;cAIN,oBAAoB,iBAAiB;UAejC,mBAAA,SAA4B;;;;cAI/B;;;cAID,qBAAqB,kBAAkB;;;cC1G9C,0BAA0B,uBAAuB;cAQjD,oBAAA,SAA6B,wBAAA;;;;;;ADDlB,iBEgBD,gBAAA,CFhBoB,IAAA,EEiB5B,kBFjB4B,EAAA;EAAA,KAAA;EAAA;AAAA,CAAA,EEkBjB,YFlBiB,CEkBJ,kBFlBI,EEkBgB,mBFlBhB,CAAA,CAAA,EAAA,IAAA"}
@@ -99,8 +99,13 @@ function useInlinePopoverReference(host, editor) {
99
99
  useEditorFocusChangeEvent(host, editor, (focus) => {
100
100
  editorFocused = focus;
101
101
  });
102
+ let prevSelection;
102
103
  useEditorUpdateEvent(host, editor, (view) => {
103
104
  if (!editorFocused && host.contains(host.ownerDocument.activeElement)) return;
105
+ const { selection } = view.state;
106
+ const selectionUnchanged = prevSelection?.eq(selection);
107
+ prevSelection = selection;
108
+ if (selectionUnchanged) return;
104
109
  reference.set(getVirtualSelectionElement(view) || null);
105
110
  });
106
111
  return reference;
@@ -1 +1 @@
1
- {"version":3,"file":"prosekit-web-inline-popover.js","names":["inlinePopoverProps: PropDeclarations<InlinePopoverProps>","overlayPositionerProps","inlinePopoverEvents: EventDeclarations<InlinePopoverEvents>","overlayPositionerEvents","InlinePopoverElementBase: BaseElementConstructor<InlinePopoverProps>"],"sources":["../src/hooks/use-editor-focus-event.ts","../src/hooks/use-editor-update-event.ts","../src/hooks/use-keymap.ts","../src/components/inline-popover/inline-popover/virtual-selection-element.ts","../src/components/inline-popover/inline-popover/setup.ts","../src/components/inline-popover/inline-popover/types.ts","../src/components/inline-popover/inline-popover/element.gen.ts"],"sourcesContent":["import type {\n ConnectableElement,\n ReadonlySignal,\n} from '@aria-ui/core'\nimport {\n defineFocusChangeHandler,\n type Editor,\n type FocusChangeHandler,\n} from '@prosekit/core'\n\nimport { useEditorExtension } from './use-editor-extension'\n\n/**\n * @internal\n */\nexport function useEditorFocusChangeEvent(\n host: ConnectableElement,\n editor: ReadonlySignal<Editor | null>,\n handler: FocusChangeHandler,\n): void {\n const extension = defineFocusChangeHandler(handler)\n useEditorExtension(host, editor, extension)\n}\n","import type {\n ConnectableElement,\n ReadonlySignal,\n} from '@aria-ui/core'\nimport {\n defineUpdateHandler,\n type Editor,\n type UpdateHandler,\n} from '@prosekit/core'\n\nimport { useEditorExtension } from './use-editor-extension'\n\n/**\n * @internal\n */\nexport function useEditorUpdateEvent(\n host: ConnectableElement,\n editor: ReadonlySignal<Editor | null>,\n handler: UpdateHandler,\n): void {\n const extension = defineUpdateHandler(handler)\n useEditorExtension(host, editor, extension)\n}\n","import type {\n ConnectableElement,\n ReadonlySignal,\n} from '@aria-ui/core'\nimport {\n defineKeymap,\n type Editor,\n type Keymap,\n} from '@prosekit/core'\n\nimport { useEditorExtension } from './use-editor-extension'\n\nexport function useKeymap(\n host: ConnectableElement,\n editor: ReadonlySignal<Editor | null>,\n keymap: Keymap,\n): void {\n const extension = defineKeymap(keymap)\n useEditorExtension(host, editor, extension)\n}\n","import type { ReferenceElement } from '@floating-ui/dom'\nimport {\n containsInlineNode,\n isInCodeBlock,\n isTextSelection,\n} from '@prosekit/core'\nimport type { EditorView } from '@prosekit/pm/view'\n\nexport function getVirtualSelectionElement(\n view: EditorView,\n): ReferenceElement | undefined {\n if (typeof window === 'undefined' || view.isDestroyed) {\n return\n }\n\n const selection = view.state.selection\n\n if (\n !selection.empty\n && !isInCodeBlock(selection)\n && isTextSelection(selection)\n && containsInlineNode(view.state.doc, selection.from, selection.to)\n ) {\n return getDomDecoration(view) || getInlineDecoration(view)\n }\n}\n\nfunction getDomDecoration(view: EditorView): ReferenceElement | undefined {\n const range = getDomRange(view)\n if (range) {\n // To get it work properly in Safari, we cannot return the range directly.\n // We have to return a contextElement.\n return {\n contextElement: view.dom,\n getBoundingClientRect: () => range.getBoundingClientRect(),\n getClientRects: () => range.getClientRects(),\n }\n }\n}\n\nfunction getDomRange(view: EditorView): Range | undefined {\n const win = view.dom.ownerDocument.defaultView\n const selection = win?.getSelection()\n if (!selection || selection.isCollapsed) {\n return\n }\n\n const range = typeof selection.rangeCount === 'number'\n && selection.rangeCount > 0\n && selection.getRangeAt(0)\n\n if (!range) {\n return\n }\n\n return range\n}\n\nfunction getInlineDecoration(view: EditorView): ReferenceElement | undefined {\n const match = view.dom.querySelectorAll('.prosekit-virtual-selection')\n\n if (match.length === 0) {\n return\n }\n if (match.length === 1) {\n return match[0]\n }\n\n const items = Array.from(match)\n return {\n contextElement: items[0],\n getBoundingClientRect: () => items[0].getBoundingClientRect(),\n getClientRects: () => items.map((item) => item.getBoundingClientRect()),\n }\n}\n","import {\n createComputed,\n createSignal,\n useAttribute,\n useEffect,\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 { ReferenceElement } from '@floating-ui/dom'\nimport type { Editor } from '@prosekit/core'\n\nimport { useEditorFocusChangeEvent } from '../../../hooks/use-editor-focus-event'\nimport { useEditorUpdateEvent } from '../../../hooks/use-editor-update-event'\nimport { useKeymap } from '../../../hooks/use-keymap'\n\nimport type {\n InlinePopoverEvents,\n InlinePopoverProps,\n} from './types'\nimport { getVirtualSelectionElement } from './virtual-selection-element'\n\n/**\n * @internal\n */\nexport function useInlinePopover(\n host: ConnectableElement,\n { state, emit }: SetupOptions<InlinePopoverProps, InlinePopoverEvents>,\n): void {\n const { editor, defaultOpen, open, ...overlayState } = state\n\n const reference = useInlinePopoverReference(host, editor)\n const hasReference = createComputed(() => !!reference.get())\n\n useEffect(host, () => {\n const hasReferenceValue = hasReference.get()\n const defaultOpenValue = defaultOpen.peek()\n const openValue = open.peek()\n\n if (defaultOpenValue || openValue) {\n emit('openChange', hasReferenceValue)\n }\n })\n\n useEffect(host, () => {\n const hasReferenceValue = hasReference.get()\n const defaultOpenValue = defaultOpen.peek()\n\n if (hasReferenceValue && defaultOpenValue) {\n open.set(true)\n } else if (!hasReferenceValue) {\n open.set(false)\n }\n })\n\n useKeymap(host, editor, {\n Escape: () => {\n if (!state.dismissOnEscape.peek() || !open.peek()) {\n return false\n }\n open.set(false)\n emit('openChange', false)\n return true\n },\n })\n\n useOverlayPositionerState(host, overlayState, { reference })\n\n useAttribute(host, 'data-state', () => (open.get() ? 'open' : 'closed'))\n usePresence(host, open)\n}\n\nfunction useInlinePopoverReference(\n host: ConnectableElement,\n editor: ReadonlySignal<Editor | null>,\n) {\n const reference = createSignal<ReferenceElement | null>(null)\n let editorFocused = false\n\n useEditorFocusChangeEvent(host, editor, (focus) => {\n editorFocused = focus\n })\n\n useEditorUpdateEvent(host, editor, (view) => {\n const isPopoverFocused = !editorFocused && host.contains(host.ownerDocument.activeElement)\n\n if (isPopoverFocused) {\n return\n }\n\n reference.set(getVirtualSelectionElement(view) || null)\n })\n\n return reference\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'\nimport type { Editor } from '@prosekit/core'\n\nexport interface InlinePopoverProps extends\n Omit<\n OverlayPositionerProps,\n 'placement' | 'offset' | 'hide' | 'overlap' | 'inline' | 'overflowPadding'\n >\n{\n /**\n * The ProseKit editor instance.\n *\n * @default null\n * @hidden\n */\n editor: Editor | null\n\n /**\n * Whether the popover is open by default when some inline content is\n * selected.\n *\n * When `defaultOpen` is true, the popover will open or close based on the\n * inline selection. When `defaultOpen` is false, the popover will never be\n * opened unless the `open` prop is true.\n *\n * @default true\n */\n defaultOpen: boolean\n\n /**\n * Whether the popover is open.\n *\n * Notice that the popover will be always hidden if the inline selection is\n * empty.\n *\n * @default false\n */\n open: boolean\n\n /**\n * Whether the inline popover should be dismissed when the editor receives an\n * Escape key press.\n *\n * @default true\n */\n dismissOnEscape: boolean\n\n /**\n * @default \"top\"\n */\n placement: OverlayPositionerProps['placement']\n\n /**\n * @default 12\n */\n offset: OverlayPositionerProps['offset']\n\n /**\n * @default true\n */\n hide: OverlayPositionerProps['hide']\n\n /**\n * @default true\n */\n overlap: OverlayPositionerProps['overlap']\n\n /**\n * @default true\n */\n inline: OverlayPositionerProps['inline']\n\n /**\n * @default 8\n */\n overflowPadding: OverlayPositionerProps['overflowPadding']\n}\n\n/** @internal */\nexport const inlinePopoverProps: PropDeclarations<InlinePopoverProps> = Object.freeze({\n ...overlayPositionerProps,\n editor: { default: null },\n defaultOpen: { default: true },\n open: { default: false },\n dismissOnEscape: { default: true },\n\n placement: { default: 'top' },\n offset: { default: 12 },\n hide: { default: true },\n overlap: { default: true },\n inline: { default: true },\n overflowPadding: { default: 8 },\n})\n\nexport interface InlinePopoverEvents extends OverlayPositionerEvents {\n /**\n * Fired when the open state changes.\n */\n openChange: CustomEvent<boolean>\n}\n\n/** @internal */\nexport const inlinePopoverEvents: EventDeclarations<InlinePopoverEvents> = {\n ...overlayPositionerEvents,\n openChange: {},\n}\n","import { defineCustomElement, registerCustomElement, type BaseElementConstructor } from \"@aria-ui/core\"\n\nimport { useInlinePopover } from \"./setup\"\nimport { inlinePopoverEvents, inlinePopoverProps, type InlinePopoverEvents, type InlinePopoverProps } from \"./types\"\n\nconst InlinePopoverElementBase: BaseElementConstructor<InlinePopoverProps> = defineCustomElement<\n InlinePopoverProps,\n InlinePopoverEvents\n>({\n props: inlinePopoverProps,\n events: inlinePopoverEvents,\n setup: useInlinePopover,\n})\nclass InlinePopoverElement extends InlinePopoverElementBase {}\n\nregisterCustomElement('prosekit-inline-popover', InlinePopoverElement)\n \nexport { InlinePopoverElement }\n"],"mappings":";;;;;;;;;;;AAeA,SAAgB,0BACd,MACA,QACA,SACM;AAEN,oBAAmB,MAAM,QADP,yBAAyB,QAAQ,CACR;;;;;;;;ACN7C,SAAgB,qBACd,MACA,QACA,SACM;AAEN,oBAAmB,MAAM,QADP,oBAAoB,QAAQ,CACH;;;;;ACT7C,SAAgB,UACd,MACA,QACA,QACM;AAEN,oBAAmB,MAAM,QADP,aAAa,OAAO,CACK;;;;;ACV7C,SAAgB,2BACd,MAC8B;AAC9B,KAAI,OAAO,WAAW,eAAe,KAAK,YACxC;CAGF,MAAM,YAAY,KAAK,MAAM;AAE7B,KACE,CAAC,UAAU,SACR,CAAC,cAAc,UAAU,IACzB,gBAAgB,UAAU,IAC1B,mBAAmB,KAAK,MAAM,KAAK,UAAU,MAAM,UAAU,GAAG,CAEnE,QAAO,iBAAiB,KAAK,IAAI,oBAAoB,KAAK;;AAI9D,SAAS,iBAAiB,MAAgD;CACxE,MAAM,QAAQ,YAAY,KAAK;AAC/B,KAAI,MAGF,QAAO;EACL,gBAAgB,KAAK;EACrB,6B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AAK,MAAM,CAC/C,QAAO;AAET,OAAK,IAAI,MAAM;AACf,OAAK,cAAc,MAAM;AACzB,SAAO;IAEV,CAAC;AAEF,2BAA0B,MAAM,cAAc,EAAE,WAAW,CAAC;AAE5D,cAAa,MAAM,oBAAqB,KAAK,KAAK,GAAG,SAAS,SAAU;AACxE,aAAY,MAAM,KAAK;;AAGzB,SAAS,0BACP,MACA,QACA;CACA,MAAM,YAAY,aAAsC,KAAK;CAC7D,IAAI,gBAAgB;AAEpB,2BAA0B,MAAM,SAAS,UAAU;AACjD,kBAAgB;GAChB;AAEF,sBAAqB,MAAM,SAAS,SAAS;AAG3C,MAFyB,CAAC,iBAAiB,KAAK,SAAS,KAAK,cAAc,cAAc,CAGxF;AAGF,YAAU,IAAI,2BAA2B,KAAK,IAAI,KAAK;GACvD;AAEF,QAAO;;;;;;ACPT,MAAaA,qBAA2D,OAAO,OAAO;CACpF,GAAGC;CACH,QAAQ,EAAE,SAAS,MAAM;CACzB,aAAa,EAAE,SAAS,MAAM;CAC9B,MAAM,EAAE,SAAS,OAAO;CACxB,iBAAiB,EAAE,SAAS,MAAM;CAElC,WAAW,EAAE,SAAS,OAAO;CAC7B,QAAQ,EAAE,SAAS,IAAI;CACvB,MAAM,EAAE,SAAS,MAAM;CACvB,SAAS,EAAE,SAAS,MAAM;CAC1B,QAAQ,EAAE,SAAS,MAAM;CACzB,iBAAiB,EAAE,SAAS,GAAG;CAChC,CAAC;;AAUF,MAAaC,sBAA8D;CACzE,GAAGC;CACH,YAAY,EAAE;CACf;;;;AC7GD,MAAMC,2BAAuE,oBAG3E;CACA,OAAO;CACP,QAAQ;CACR,OAAO;CACR,CAAC;AACF,IAAM,uBAAN,cAAmC,yBAAyB;AAE5D,sBAAsB,2BAA2B,qBAAqB"}
1
+ {"version":3,"file":"prosekit-web-inline-popover.js","names":["prevSelection: Selection | undefined","inlinePopoverProps: PropDeclarations<InlinePopoverProps>","overlayPositionerProps","inlinePopoverEvents: EventDeclarations<InlinePopoverEvents>","overlayPositionerEvents","InlinePopoverElementBase: BaseElementConstructor<InlinePopoverProps>"],"sources":["../src/hooks/use-editor-focus-event.ts","../src/hooks/use-editor-update-event.ts","../src/hooks/use-keymap.ts","../src/components/inline-popover/inline-popover/virtual-selection-element.ts","../src/components/inline-popover/inline-popover/setup.ts","../src/components/inline-popover/inline-popover/types.ts","../src/components/inline-popover/inline-popover/element.gen.ts"],"sourcesContent":["import type {\n ConnectableElement,\n ReadonlySignal,\n} from '@aria-ui/core'\nimport {\n defineFocusChangeHandler,\n type Editor,\n type FocusChangeHandler,\n} from '@prosekit/core'\n\nimport { useEditorExtension } from './use-editor-extension'\n\n/**\n * @internal\n */\nexport function useEditorFocusChangeEvent(\n host: ConnectableElement,\n editor: ReadonlySignal<Editor | null>,\n handler: FocusChangeHandler,\n): void {\n const extension = defineFocusChangeHandler(handler)\n useEditorExtension(host, editor, extension)\n}\n","import type {\n ConnectableElement,\n ReadonlySignal,\n} from '@aria-ui/core'\nimport {\n defineUpdateHandler,\n type Editor,\n type UpdateHandler,\n} from '@prosekit/core'\n\nimport { useEditorExtension } from './use-editor-extension'\n\n/**\n * @internal\n */\nexport function useEditorUpdateEvent(\n host: ConnectableElement,\n editor: ReadonlySignal<Editor | null>,\n handler: UpdateHandler,\n): void {\n const extension = defineUpdateHandler(handler)\n useEditorExtension(host, editor, extension)\n}\n","import type {\n ConnectableElement,\n ReadonlySignal,\n} from '@aria-ui/core'\nimport {\n defineKeymap,\n type Editor,\n type Keymap,\n} from '@prosekit/core'\n\nimport { useEditorExtension } from './use-editor-extension'\n\nexport function useKeymap(\n host: ConnectableElement,\n editor: ReadonlySignal<Editor | null>,\n keymap: Keymap,\n): void {\n const extension = defineKeymap(keymap)\n useEditorExtension(host, editor, extension)\n}\n","import type { ReferenceElement } from '@floating-ui/dom'\nimport {\n containsInlineNode,\n isInCodeBlock,\n isTextSelection,\n} from '@prosekit/core'\nimport type { EditorView } from '@prosekit/pm/view'\n\nexport function getVirtualSelectionElement(\n view: EditorView,\n): ReferenceElement | undefined {\n if (typeof window === 'undefined' || view.isDestroyed) {\n return\n }\n\n const selection = view.state.selection\n\n if (\n !selection.empty\n && !isInCodeBlock(selection)\n && isTextSelection(selection)\n && containsInlineNode(view.state.doc, selection.from, selection.to)\n ) {\n return getDomDecoration(view) || getInlineDecoration(view)\n }\n}\n\nfunction getDomDecoration(view: EditorView): ReferenceElement | undefined {\n const range = getDomRange(view)\n if (range) {\n // To get it work properly in Safari, we cannot return the range directly.\n // We have to return a contextElement.\n return {\n contextElement: view.dom,\n getBoundingClientRect: () => range.getBoundingClientRect(),\n getClientRects: () => range.getClientRects(),\n }\n }\n}\n\nfunction getDomRange(view: EditorView): Range | undefined {\n const win = view.dom.ownerDocument.defaultView\n const selection = win?.getSelection()\n if (!selection || selection.isCollapsed) {\n return\n }\n\n const range = typeof selection.rangeCount === 'number'\n && selection.rangeCount > 0\n && selection.getRangeAt(0)\n\n if (!range) {\n return\n }\n\n return range\n}\n\nfunction getInlineDecoration(view: EditorView): ReferenceElement | undefined {\n const match = view.dom.querySelectorAll('.prosekit-virtual-selection')\n\n if (match.length === 0) {\n return\n }\n if (match.length === 1) {\n return match[0]\n }\n\n const items = Array.from(match)\n return {\n contextElement: items[0],\n getBoundingClientRect: () => items[0].getBoundingClientRect(),\n getClientRects: () => items.map((item) => item.getBoundingClientRect()),\n }\n}\n","import {\n createComputed,\n createSignal,\n useAttribute,\n useEffect,\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 { ReferenceElement } from '@floating-ui/dom'\nimport type { Editor } from '@prosekit/core'\nimport type { Selection } from '@prosekit/pm/state'\n\nimport { useEditorFocusChangeEvent } from '../../../hooks/use-editor-focus-event'\nimport { useEditorUpdateEvent } from '../../../hooks/use-editor-update-event'\nimport { useKeymap } from '../../../hooks/use-keymap'\n\nimport type {\n InlinePopoverEvents,\n InlinePopoverProps,\n} from './types'\nimport { getVirtualSelectionElement } from './virtual-selection-element'\n\n/**\n * @internal\n */\nexport function useInlinePopover(\n host: ConnectableElement,\n { state, emit }: SetupOptions<InlinePopoverProps, InlinePopoverEvents>,\n): void {\n const { editor, defaultOpen, open, ...overlayState } = state\n\n const reference = useInlinePopoverReference(host, editor)\n const hasReference = createComputed(() => !!reference.get())\n\n useEffect(host, () => {\n const hasReferenceValue = hasReference.get()\n const defaultOpenValue = defaultOpen.peek()\n const openValue = open.peek()\n\n if (defaultOpenValue || openValue) {\n emit('openChange', hasReferenceValue)\n }\n })\n\n useEffect(host, () => {\n const hasReferenceValue = hasReference.get()\n const defaultOpenValue = defaultOpen.peek()\n\n if (hasReferenceValue && defaultOpenValue) {\n open.set(true)\n } else if (!hasReferenceValue) {\n open.set(false)\n }\n })\n\n useKeymap(host, editor, {\n Escape: () => {\n if (!state.dismissOnEscape.peek() || !open.peek()) {\n return false\n }\n open.set(false)\n emit('openChange', false)\n return true\n },\n })\n\n useOverlayPositionerState(host, overlayState, { reference })\n\n useAttribute(host, 'data-state', () => (open.get() ? 'open' : 'closed'))\n usePresence(host, open)\n}\n\nfunction useInlinePopoverReference(\n host: ConnectableElement,\n editor: ReadonlySignal<Editor | null>,\n) {\n const reference = createSignal<ReferenceElement | null>(null)\n let editorFocused = false\n\n useEditorFocusChangeEvent(host, editor, (focus) => {\n editorFocused = focus\n })\n\n let prevSelection: Selection | undefined\n\n useEditorUpdateEvent(host, editor, (view) => {\n const isPopoverFocused = !editorFocused && host.contains(host.ownerDocument.activeElement)\n\n if (isPopoverFocused) {\n return\n }\n\n const { selection } = view.state\n const selectionUnchanged = prevSelection?.eq(selection)\n prevSelection = selection\n\n // Skip reference update if only the document content has changed, not the\n // selection itself.\n //\n // Example: If the user selects text and then applies mark bold using the\n // popover, the selection may widen, but we don't want to reposition the\n // popover.\n if (selectionUnchanged) {\n return\n }\n\n reference.set(getVirtualSelectionElement(view) || null)\n })\n\n return reference\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'\nimport type { Editor } from '@prosekit/core'\n\nexport interface InlinePopoverProps extends\n Omit<\n OverlayPositionerProps,\n 'placement' | 'offset' | 'hide' | 'overlap' | 'inline' | 'overflowPadding'\n >\n{\n /**\n * The ProseKit editor instance.\n *\n * @default null\n * @hidden\n */\n editor: Editor | null\n\n /**\n * Whether the popover is open by default when some inline content is\n * selected.\n *\n * When `defaultOpen` is true, the popover will open or close based on the\n * inline selection. When `defaultOpen` is false, the popover will never be\n * opened unless the `open` prop is true.\n *\n * @default true\n */\n defaultOpen: boolean\n\n /**\n * Whether the popover is open.\n *\n * Notice that the popover will be always hidden if the inline selection is\n * empty.\n *\n * @default false\n */\n open: boolean\n\n /**\n * Whether the inline popover should be dismissed when the editor receives an\n * Escape key press.\n *\n * @default true\n */\n dismissOnEscape: boolean\n\n /**\n * @default \"top\"\n */\n placement: OverlayPositionerProps['placement']\n\n /**\n * @default 12\n */\n offset: OverlayPositionerProps['offset']\n\n /**\n * @default true\n */\n hide: OverlayPositionerProps['hide']\n\n /**\n * @default true\n */\n overlap: OverlayPositionerProps['overlap']\n\n /**\n * @default true\n */\n inline: OverlayPositionerProps['inline']\n\n /**\n * @default 8\n */\n overflowPadding: OverlayPositionerProps['overflowPadding']\n}\n\n/** @internal */\nexport const inlinePopoverProps: PropDeclarations<InlinePopoverProps> = Object.freeze({\n ...overlayPositionerProps,\n editor: { default: null },\n defaultOpen: { default: true },\n open: { default: false },\n dismissOnEscape: { default: true },\n\n placement: { default: 'top' },\n offset: { default: 12 },\n hide: { default: true },\n overlap: { default: true },\n inline: { default: true },\n overflowPadding: { default: 8 },\n})\n\nexport interface InlinePopoverEvents extends OverlayPositionerEvents {\n /**\n * Fired when the open state changes.\n */\n openChange: CustomEvent<boolean>\n}\n\n/** @internal */\nexport const inlinePopoverEvents: EventDeclarations<InlinePopoverEvents> = {\n ...overlayPositionerEvents,\n openChange: {},\n}\n","import { defineCustomElement, registerCustomElement, type BaseElementConstructor } from \"@aria-ui/core\"\n\nimport { useInlinePopover } from \"./setup\"\nimport { inlinePopoverEvents, inlinePopoverProps, type InlinePopoverEvents, type InlinePopoverProps } from \"./types\"\n\nconst InlinePopoverElementBase: BaseElementConstructor<InlinePopoverProps> = defineCustomElement<\n InlinePopoverProps,\n InlinePopoverEvents\n>({\n props: inlinePopoverProps,\n events: inlinePopoverEvents,\n setup: useInlinePopover,\n})\nclass InlinePopoverElement extends InlinePopoverElementBase {}\n\nregisterCustomElement('prosekit-inline-popover', InlinePopoverElement)\n \nexport { InlinePopoverElement }\n"],"mappings":";;;;;;;;;;;AAeA,SAAgB,0BACd,MACA,QACA,SACM;AAEN,oBAAmB,MAAM,QADP,yBAAyB,QAAQ,CACR;;;;;;;;ACN7C,SAAgB,qBACd,MACA,QACA,SACM;AAEN,oBAAmB,MAAM,QADP,oBAAoB,QAAQ,CACH;;;;;ACT7C,SAAgB,UACd,MACA,QACA,QACM;AAEN,oBAAmB,MAAM,QADP,aAAa,OAAO,CACK;;;;;ACV7C,SAAgB,2BACd,MAC8B;AAC9B,KAAI,OAAO,WAAW,eAAe,KAAK,YACxC;CAGF,MAAM,YAAY,KAAK,MAAM;AAE7B,KACE,CAAC,UAAU,SACR,CAAC,cAAc,UAAU,IACzB,gBAAgB,UAAU,IAC1B,mBAAmB,KAAK,MAAM,KAAK,UAAU,MAAM,UAAU,GAAG,CAEnE,QAAO,iBAAiB,KAAK,IAAI,oBAAoB,KAAK;;AAI9D,SAAS,iBAAiB,MAAgD;CACxE,MAAM,QAAQ,YAAY,KAAK;AAC/B,KAAI,MAGF,QAAO;EACL,gBAAgB,KAAK;EACrB,6BAA6B,MAAM,uBAAuB;EAC1D,sBAAsB,MAAM,gBAAgB;EAC7C;;AAIL,SAAS,YAAY,MAAqC;CAExD,M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.7.8",
5
5
  "private": false,
6
6
  "description": "A collection of web components for ProseKit",
7
7
  "author": {
@@ -76,18 +76,18 @@
76
76
  "@aria-ui/presence": "^0.0.20",
77
77
  "@aria-ui/tooltip": "^0.0.30",
78
78
  "@floating-ui/dom": "^1.7.4",
79
- "@ocavue/utils": "^0.8.1",
80
- "@zag-js/dom-query": "^1.28.0",
81
- "prosemirror-tables": "^1.8.1",
82
- "@prosekit/core": "^0.8.7",
83
- "@prosekit/extensions": "^0.12.2",
84
- "@prosekit/pm": "^0.1.14"
79
+ "@ocavue/utils": "^1.2.0",
80
+ "@zag-js/dom-query": "^1.31.0",
81
+ "prosemirror-tables": "^1.8.3",
82
+ "@prosekit/core": "^0.9.0",
83
+ "@prosekit/extensions": "^0.13.0",
84
+ "@prosekit/pm": "^0.1.15"
85
85
  },
86
86
  "devDependencies": {
87
- "tsdown": "^0.16.5",
88
- "type-fest": "^5.2.0",
87
+ "tsdown": "^0.17.0",
88
+ "type-fest": "^5.3.1",
89
89
  "typescript": "~5.9.3",
90
- "vitest": "^4.0.10",
90
+ "vitest": "^4.0.15",
91
91
  "@prosekit/config-tsdown": "0.0.0",
92
92
  "@prosekit/config-vitest": "0.0.0"
93
93
  },
@@ -135,7 +135,7 @@ function createAutocompleteRule(
135
135
  ) {
136
136
  const handleEnter: MatchHandler = (options) => {
137
137
  const view = getSafeEditorView(editor)
138
- const span = view?.dom.querySelector('.prosemirror-prediction-match')
138
+ const span = view?.dom.querySelector('.prosekit-autocomplete-match')
139
139
 
140
140
  if (span) {
141
141
  reference.set(span)
@@ -11,6 +11,7 @@ import { useOverlayPositionerState } from '@aria-ui/overlay/elements'
11
11
  import { usePresence } from '@aria-ui/presence'
12
12
  import type { ReferenceElement } from '@floating-ui/dom'
13
13
  import type { Editor } from '@prosekit/core'
14
+ import type { Selection } from '@prosekit/pm/state'
14
15
 
15
16
  import { useEditorFocusChangeEvent } from '../../../hooks/use-editor-focus-event'
16
17
  import { useEditorUpdateEvent } from '../../../hooks/use-editor-update-event'
@@ -83,6 +84,8 @@ function useInlinePopoverReference(
83
84
  editorFocused = focus
84
85
  })
85
86
 
87
+ let prevSelection: Selection | undefined
88
+
86
89
  useEditorUpdateEvent(host, editor, (view) => {
87
90
  const isPopoverFocused = !editorFocused && host.contains(host.ownerDocument.activeElement)
88
91
 
@@ -90,6 +93,20 @@ function useInlinePopoverReference(
90
93
  return
91
94
  }
92
95
 
96
+ const { selection } = view.state
97
+ const selectionUnchanged = prevSelection?.eq(selection)
98
+ prevSelection = selection
99
+
100
+ // Skip reference update if only the document content has changed, not the
101
+ // selection itself.
102
+ //
103
+ // Example: If the user selects text and then applies mark bold using the
104
+ // popover, the selection may widen, but we don't want to reposition the
105
+ // popover.
106
+ if (selectionUnchanged) {
107
+ return
108
+ }
109
+
93
110
  reference.set(getVirtualSelectionElement(view) || null)
94
111
  })
95
112