@prosekit/web 0.8.0-beta.6 → 0.8.1
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.
- package/dist/autocomplete.d.ts +19 -2
- package/dist/autocomplete.d.ts.map +1 -1
- package/dist/autocomplete.js +30 -17
- package/dist/autocomplete.js.map +1 -1
- package/dist/block-handle.d.ts.map +1 -1
- package/dist/block-handle.js +16 -10
- package/dist/block-handle.js.map +1 -1
- package/dist/drop-indicator.js.map +1 -1
- package/dist/get-safe-editor-view.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/inline-popover.js +4 -11
- package/dist/inline-popover.js.map +1 -1
- package/dist/menu.js.map +1 -1
- package/dist/popover.js.map +1 -1
- package/dist/resizable.js.map +1 -1
- package/dist/table-handle.js +11 -22
- package/dist/table-handle.js.map +1 -1
- package/dist/tooltip.js.map +1 -1
- package/dist/use-editor-extension.js.map +1 -1
- package/dist/use-editor-update-event.js +11 -0
- package/dist/use-editor-update-event.js.map +1 -0
- package/dist/use-scrolling.js.map +1 -1
- package/package.json +10 -10
- package/src/components/autocomplete/autocomplete-positioner.ts +14 -5
- package/src/components/autocomplete/autocomplete-root.ts +36 -13
- package/src/components/block-handle/block-handle-add.ts +1 -1
- package/src/components/block-handle/block-handle-draggable.ts +1 -1
- package/src/components/block-handle/block-handle-positioner.ts +1 -1
- package/src/components/block-handle/block-handle-root.ts +5 -2
- package/src/components/block-handle/use-has-text-selection.ts +13 -0
- package/src/components/inline-popover/inline-popover-positioner.ts +1 -1
- package/src/components/inline-popover/inline-popover-root.ts +1 -1
- package/src/components/table-handle/shared.ts +6 -6
- package/src/components/table-handle/table-handle-column-menu-trigger.ts +1 -1
- package/src/components/table-handle/table-handle-drag-preview.ts +1 -1
- package/src/components/table-handle/table-handle-drop-indicator.ts +1 -1
- package/src/components/table-handle/table-handle-root.ts +1 -1
- package/src/components/table-handle/table-handle-row-menu-trigger.ts +1 -1
package/dist/autocomplete.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { HostElement, HostElementConstructor, PropsDeclaration, State } from "@a
|
|
|
2
2
|
import { ItemFilter, ListboxEmptyProps, ListboxItemEvents, ListboxItemProps, ListboxRootEvents, SelectEvent, ValueChangeEvent, ValuesChangeEvent } from "@aria-ui/elements/listbox";
|
|
3
3
|
import { OpenChangeEvent, OverlayPopupProps, OverlayPositionerProps } from "@aria-ui/elements/overlay";
|
|
4
4
|
import { Editor } from "@prosekit/core";
|
|
5
|
+
import { VirtualElement } from "@floating-ui/dom";
|
|
5
6
|
interface AutocompleteEmptyProps extends ListboxEmptyProps {}
|
|
6
7
|
/** @internal */
|
|
7
8
|
declare const AutocompleteEmptyPropsDeclaration: PropsDeclaration<AutocompleteEmptyProps>;
|
|
@@ -92,11 +93,18 @@ interface AutocompletePositionerProps extends OverlayPositionerProps {
|
|
|
92
93
|
*/
|
|
93
94
|
placement: OverlayPositionerProps['placement'];
|
|
94
95
|
/**
|
|
95
|
-
* The distance between the popover and the
|
|
96
|
+
* The distance between the popover and the text selection.
|
|
96
97
|
*
|
|
97
|
-
* @default 4
|
|
98
|
+
* @default { mainAxis: 8, crossAxis: -4 }
|
|
98
99
|
*/
|
|
99
100
|
offset: OverlayPositionerProps['offset'];
|
|
101
|
+
/**
|
|
102
|
+
* Whether to hide the floating element when the reference element or the
|
|
103
|
+
* floating element is fully clipped.
|
|
104
|
+
*
|
|
105
|
+
* @default true
|
|
106
|
+
*/
|
|
107
|
+
hide: OverlayPositionerProps['hide'];
|
|
100
108
|
/**
|
|
101
109
|
* @default true
|
|
102
110
|
*/
|
|
@@ -166,6 +174,15 @@ interface AutocompleteRootProps {
|
|
|
166
174
|
* @default defaultItemFilter
|
|
167
175
|
*/
|
|
168
176
|
filter: ItemFilter | null;
|
|
177
|
+
/**
|
|
178
|
+
* The reference to position the popup against. This can be a DOM element, a
|
|
179
|
+
* Floating UI virtual element, or a function that returns either of them.
|
|
180
|
+
* By default, the popup will be positioned against the text content that
|
|
181
|
+
* triggers the autocomplete.
|
|
182
|
+
*
|
|
183
|
+
* @default null
|
|
184
|
+
*/
|
|
185
|
+
anchor: Element | VirtualElement | (() => Element | VirtualElement | null) | null;
|
|
169
186
|
}
|
|
170
187
|
/** @internal */
|
|
171
188
|
declare const AutocompleteRootPropsDeclaration: PropsDeclaration<AutocompleteRootProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocomplete.d.ts","names":[],"sources":["../src/components/autocomplete/autocomplete-empty.ts","../src/components/autocomplete/autocomplete-item.ts","../src/components/autocomplete/autocomplete-popup.ts","../src/components/autocomplete/autocomplete-positioner.ts","../src/components/autocomplete/autocomplete-root.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"autocomplete.d.ts","names":[],"sources":["../src/components/autocomplete/autocomplete-empty.ts","../src/components/autocomplete/autocomplete-item.ts","../src/components/autocomplete/autocomplete-popup.ts","../src/components/autocomplete/autocomplete-positioner.ts","../src/components/autocomplete/autocomplete-root.ts"],"mappings":";;;;;UAWiB,sBAAA,SAA+B,iBAAA;;cAGnC,iCAAA,EAAmC,gBAAA,CAAiB,sBAAA;AAHjE;;;AAAA,iBAUgB,sBAAA,CACd,IAAA,EAAM,WAAA,EACN,KAAA,EAAO,KAAA,CAAM,sBAAA;AAAA,cAKT,4BAAA,EAA8B,sBAAA,CAAuB,sBAAA;AAd3D;;;;;AAAA,cAwBa,wBAAA,SAAiC,4BAAA;;iBAG9B,gCAAA,CAAA;AAAA,UCzBC,qBAAA,SAA8B,gBAAA;;;ADL/C;;;;;ECaE,KAAA;AAAA;;cAIW,gCAAA,EAAkC,gBAAA,CAAiB,qBAAA;AAAA,UAO/C,sBAAA,SAA+B,iBAAA;;;;iBAKhC,qBAAA,CACd,IAAA,EAAM,WAAA,EACN,KAAA,EAAO,KAAA,CAAM,qBAAA;AAAA,cAST,2BAAA,EAA6B,sBAAA,CAAuB,qBAAA;;;;;;;;;;ADzBzD;;;;cC2CY,uBAAA,SAAgC,2BAA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AAA,SAAyB,KAAA;;;;WAI3B,MAAA;cAEG,KAAA;AAAA;;;;UASG,sBAAA,SAA+B,iBAAA;EH1D/C;;;EG8DC,UAAA,EAAY,eAAA;EH5DG;;;EGiEf,WAAA,EAAa,gBAAA;AAAA;AH5Df;;;AAAA,iBG8EgB,qBAAA,CACd,IAAA,EAAM,WAAA,EACN,KAAA,EAAO,KAAA,CAAM,qBAAA;AAAA,cAyKT,2BAAA,EAA6B,sBAAA,CAAuB,qBAAA;;;;;;;;cAY7C,uBAAA,SAAgC,2BAAA;;iBAG7B,+BAAA,CAAA"}
|
package/dist/autocomplete.js
CHANGED
|
@@ -149,9 +149,16 @@ const AutocompletePositionerPropsDeclaration = /* @__PURE__ */ defineProps({
|
|
|
149
149
|
type: "string"
|
|
150
150
|
},
|
|
151
151
|
offset: {
|
|
152
|
-
default:
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
default: {
|
|
153
|
+
mainAxis: 8,
|
|
154
|
+
crossAxis: -4
|
|
155
|
+
},
|
|
156
|
+
attribute: false
|
|
157
|
+
},
|
|
158
|
+
hide: {
|
|
159
|
+
default: true,
|
|
160
|
+
attribute: "hide",
|
|
161
|
+
type: "boolean"
|
|
155
162
|
},
|
|
156
163
|
inline: {
|
|
157
164
|
default: true,
|
|
@@ -170,8 +177,7 @@ const AutocompletePositionerPropsDeclaration = /* @__PURE__ */ defineProps({
|
|
|
170
177
|
},
|
|
171
178
|
boundary: {
|
|
172
179
|
default: defaultBoundary,
|
|
173
|
-
attribute: false
|
|
174
|
-
type: "json"
|
|
180
|
+
attribute: false
|
|
175
181
|
},
|
|
176
182
|
overflowPadding: {
|
|
177
183
|
default: 8,
|
|
@@ -240,18 +246,19 @@ function defaultQueryBuilder(match) {
|
|
|
240
246
|
const AutocompleteRootPropsDeclaration = /* @__PURE__ */ defineProps({
|
|
241
247
|
editor: {
|
|
242
248
|
default: null,
|
|
243
|
-
attribute: false
|
|
244
|
-
type: "json"
|
|
249
|
+
attribute: false
|
|
245
250
|
},
|
|
246
251
|
regex: {
|
|
247
252
|
default: null,
|
|
248
|
-
attribute: false
|
|
249
|
-
type: "json"
|
|
253
|
+
attribute: false
|
|
250
254
|
},
|
|
251
255
|
filter: {
|
|
252
256
|
default: defaultItemFilter,
|
|
253
|
-
attribute: false
|
|
254
|
-
|
|
257
|
+
attribute: false
|
|
258
|
+
},
|
|
259
|
+
anchor: {
|
|
260
|
+
default: null,
|
|
261
|
+
attribute: false
|
|
255
262
|
}
|
|
256
263
|
});
|
|
257
264
|
/**
|
|
@@ -299,7 +306,13 @@ function setupAutocompleteRoot(host, props) {
|
|
|
299
306
|
query.set(next);
|
|
300
307
|
host.dispatchEvent(new QueryChangeEvent(next));
|
|
301
308
|
};
|
|
302
|
-
|
|
309
|
+
const getAnchor = () => {
|
|
310
|
+
const customAnchor = props.anchor.get();
|
|
311
|
+
if (customAnchor) if (typeof customAnchor === "function") return customAnchor() || null;
|
|
312
|
+
else return customAnchor;
|
|
313
|
+
return getSafeEditorView(getEditor())?.dom.querySelector(".prosekit-autocomplete-match") || null;
|
|
314
|
+
};
|
|
315
|
+
useAutocompleteExtension(host, getEditor, props.regex.get, getAnchor, {
|
|
303
316
|
reference,
|
|
304
317
|
handlers,
|
|
305
318
|
setQuery,
|
|
@@ -322,20 +335,20 @@ function useKeyboardBridge(host, getEditor, getOpen, target) {
|
|
|
322
335
|
return event.defaultPrevented;
|
|
323
336
|
}), 4));
|
|
324
337
|
}
|
|
325
|
-
function useAutocompleteExtension(host, getEditor, getRegex, deps) {
|
|
338
|
+
function useAutocompleteExtension(host, getEditor, getRegex, getAnchor, deps) {
|
|
326
339
|
useEffect(host, () => {
|
|
327
340
|
const editor = getEditor();
|
|
328
341
|
const regex = getRegex();
|
|
329
342
|
if (!editor || !regex) return;
|
|
330
|
-
const extension = defineAutocomplete(createAutocompleteRule(editor, regex, deps));
|
|
343
|
+
const extension = defineAutocomplete(createAutocompleteRule(editor, regex, getAnchor, deps));
|
|
331
344
|
return editor.use(extension);
|
|
332
345
|
});
|
|
333
346
|
}
|
|
334
|
-
function createAutocompleteRule(editor, regex, deps) {
|
|
347
|
+
function createAutocompleteRule(editor, regex, getAnchor, deps) {
|
|
335
348
|
const { reference, handlers, setQuery, requestOpenChange } = deps;
|
|
336
349
|
const handleEnter = (options) => {
|
|
337
|
-
const
|
|
338
|
-
|
|
350
|
+
const anchor = getAnchor();
|
|
351
|
+
reference.set(anchor || void 0);
|
|
339
352
|
handlers.submit = options.deleteMatch;
|
|
340
353
|
handlers.dismiss = options.ignoreMatch;
|
|
341
354
|
setQuery(defaultQueryBuilder(options.match));
|
package/dist/autocomplete.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocomplete.js","names":[],"sources":["../src/components/autocomplete/autocomplete-empty.ts","../src/utils/prevent-default.ts","../src/components/autocomplete/autocomplete-item.ts","../src/utils/lazy-signal.ts","../src/utils/use-no-focus.ts","../src/components/autocomplete/context.ts","../src/components/autocomplete/autocomplete-popup.ts","../src/components/autocomplete/autocomplete-positioner.ts","../src/utils/event.ts","../src/components/autocomplete/helpers.ts","../src/components/autocomplete/autocomplete-root.ts"],"sourcesContent":["import {\n defineCustomElement,\n defineProps,\n registerCustomElement,\n type HostElement,\n type HostElementConstructor,\n type PropsDeclaration,\n type State,\n} from '@aria-ui/core'\nimport { setupListboxEmpty, type ListboxEmptyProps } from '@aria-ui/elements/listbox'\n\nexport interface AutocompleteEmptyProps extends ListboxEmptyProps {}\n\n/** @internal */\nexport const AutocompleteEmptyPropsDeclaration: PropsDeclaration<AutocompleteEmptyProps> = /* @__PURE__ */ defineProps<\n AutocompleteEmptyProps\n>({})\n\n/**\n * @internal\n */\nexport function setupAutocompleteEmpty(\n host: HostElement,\n props: State<AutocompleteEmptyProps>,\n): void {\n setupListboxEmpty(host, props)\n}\n\nconst AutocompleteEmptyElementBase: HostElementConstructor<AutocompleteEmptyProps> = defineCustomElement(\n setupAutocompleteEmpty,\n AutocompleteEmptyPropsDeclaration,\n)\n\n/**\n * `<prosekit-autocomplete-empty>` custom element.\n *\n * Properties: {@link AutocompleteEmptyProps}\n */\nexport class AutocompleteEmptyElement extends AutocompleteEmptyElementBase {}\n\n/** @internal */\nexport function registerAutocompleteEmptyElement(): void {\n registerCustomElement('prosekit-autocomplete-empty', AutocompleteEmptyElement)\n}\n","export function preventDefault(event: Event): void {\n event.preventDefault()\n}\n","import {\n defineCustomElement,\n defineProps,\n registerCustomElement,\n type HostElement,\n type HostElementConstructor,\n type PropsDeclaration,\n type State,\n} from '@aria-ui/core'\nimport { SelectEvent, setupListboxItem, type ListboxItemEvents, type ListboxItemProps } from '@aria-ui/elements/listbox'\nimport { useEventListener } from '@aria-ui/utils'\n\nimport { preventDefault } from '../../utils/prevent-default.ts'\n\nexport { SelectEvent }\n\nexport interface AutocompleteItemProps extends ListboxItemProps {\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 AutocompleteItemPropsDeclaration: PropsDeclaration<AutocompleteItemProps> = /* @__PURE__ */ defineProps<AutocompleteItemProps>(\n {\n value: { default: '', attribute: 'value', type: 'string' },\n disabled: { default: false, attribute: 'disabled', type: 'boolean' },\n },\n)\n\nexport interface AutocompleteItemEvents extends ListboxItemEvents {}\n\n/**\n * @internal\n */\nexport function setupAutocompleteItem(\n host: HostElement,\n props: State<AutocompleteItemProps>,\n): void {\n setupListboxItem(host, props)\n\n // Prevent the editor from losing focus\n useEventListener(host, 'pointerdown', preventDefault)\n useEventListener(host, 'mousedown', preventDefault)\n}\n\nconst AutocompleteItemElementBase: HostElementConstructor<AutocompleteItemProps> = defineCustomElement(\n setupAutocompleteItem,\n AutocompleteItemPropsDeclaration,\n)\n\n/**\n * `<prosekit-autocomplete-item>` custom element.\n *\n * Properties: {@link AutocompleteItemProps}\n *\n * Events: {@link AutocompleteItemEvents}\n *\n * Data attributes:\n *\n * | Attribute | Description |\n * | --- | --- |\n * | `data-highlighted` | Present when the item is the currently highlighted option |\n */\nexport class AutocompleteItemElement extends AutocompleteItemElementBase {}\n\n/** @internal */\nexport function registerAutocompleteItemElement(): void {\n registerCustomElement('prosekit-autocomplete-item', AutocompleteItemElement)\n}\n","import type { Signal } from '@aria-ui/core'\n\nexport function createLazySignal<T>(\n getRemote: () => Signal<T> | undefined,\n fallback: T,\n): Signal<T> {\n return {\n get: (): T => {\n const remote = getRemote()\n return remote ? remote.get() : fallback\n },\n set: (value: T): void => {\n const remote = getRemote()\n if (remote) remote.set(value)\n },\n }\n}\n","import { onMount, type HostElement } from '@aria-ui/core'\n\nexport function useNoFocus(host: HostElement): void {\n onMount(host, () => {\n host.tabIndex = -1\n })\n}\n","import { createContext, type Context, type Signal } from '@aria-ui/core'\nimport type { ItemFilter } from '@aria-ui/elements/listbox'\nimport type { OverlayStore } from '@aria-ui/elements/overlay'\n\n/**\n * @internal\n */\nexport interface AutocompleteStore {\n overlayStore: OverlayStore\n query: Signal<string>\n eventTarget: Signal<EventTarget | null>\n filter: Signal<ItemFilter | null>\n}\n\n/**\n * @internal\n */\nexport const autocompleteStoreContext: Context<AutocompleteStore> = createContext<AutocompleteStore>('prosekit-autocomplete-store')\n","import {\n createSignal,\n defineCustomElement,\n defineProps,\n registerCustomElement,\n type HostElement,\n type HostElementConstructor,\n type PropsDeclaration,\n type Signal,\n type State,\n} from '@aria-ui/core'\nimport {\n defaultItemFilter,\n setupListboxRoot,\n type ItemFilter,\n type ListboxRootEvents,\n type ListboxRootProps,\n} from '@aria-ui/elements/listbox'\nimport { OverlayPopupPropsDeclaration, setupOverlayPopup, type OverlayPopupProps } from '@aria-ui/elements/overlay'\n\nimport { createLazySignal } from '../../utils/lazy-signal.ts'\nimport { useNoFocus } from '../../utils/use-no-focus.ts'\n\nimport { autocompleteStoreContext } from './context.ts'\n\n/**\n * @public\n */\nexport interface AutocompletePopupProps extends OverlayPopupProps {}\n\n/**\n * @public\n */\nexport interface AutocompletePopupEvents extends ListboxRootEvents {}\n\n/** @internal */\nexport const AutocompletePopupPropsDeclaration: PropsDeclaration<AutocompletePopupProps> = /* @__PURE__ */ defineProps<\n AutocompletePopupProps\n>(OverlayPopupPropsDeclaration)\n\n/** @internal */\nexport function setupAutocompletePopup(\n host: HostElement,\n _props: State<AutocompletePopupProps>,\n): void {\n const getStore = autocompleteStoreContext.consume(host)\n const getOverlayStore = () => getStore()?.overlayStore\n\n setupOverlayPopup(host, getOverlayStore)\n\n const query = createLazySignal<string>(() => getStore()?.query, ' ')\n const eventTarget = createLazySignal<EventTarget | null>(() => getStore()?.eventTarget, null)\n const filter = createLazySignal<ItemFilter | null>(() => getStore()?.filter, defaultItemFilter)\n const getDisabled = () => (!(getOverlayStore()?.getIsOpen?.()))\n const disabled: Signal<boolean> = { get: getDisabled, set: () => {} }\n const listboxProps = createPopupListboxProps(filter, query, eventTarget, disabled)\n\n setupListboxRoot(host, listboxProps)\n useNoFocus(host)\n}\n\nfunction createPopupListboxProps(\n filter: Signal<ItemFilter | null>,\n query: Signal<string>,\n eventTarget: Signal<EventTarget | null>,\n disabled: Signal<boolean>,\n): State<ListboxRootProps> {\n return {\n value: createSignal(''),\n values: createSignal<string[]>([]),\n multiple: createSignal(false),\n disabled,\n orientation: createSignal<'vertical' | 'horizontal'>('vertical'),\n loop: createSignal(false),\n autoHighlight: createSignal(true),\n query,\n eventTarget,\n filter,\n }\n}\n\nconst AutocompletePopupElementBase: HostElementConstructor<AutocompletePopupProps> = defineCustomElement(\n setupAutocompletePopup,\n AutocompletePopupPropsDeclaration,\n)\n\n/**\n * `<prosekit-autocomplete-popup>` custom element.\n *\n * Properties: {@link AutocompletePopupProps}\n *\n * Events: {@link AutocompletePopupEvents}\n *\n * Data attributes:\n *\n * | Attribute | Description |\n * | --- | --- |\n * | `data-state` | `\"open\"` when the autocomplete is visible, `\"closed\"` otherwise |\n */\nexport class AutocompletePopupElement extends AutocompletePopupElementBase {}\n\n/** @internal */\nexport function registerAutocompletePopupElement(): void {\n registerCustomElement('prosekit-autocomplete-popup', AutocompletePopupElement)\n}\n","import {\n defineCustomElement,\n defineProps,\n registerCustomElement,\n type HostElement,\n type HostElementConstructor,\n type PropsDeclaration,\n type State,\n} from '@aria-ui/core'\nimport { OverlayPositionerPropsDeclaration, setupOverlayPositioner, type OverlayPositionerProps } from '@aria-ui/elements/overlay'\n\nimport { autocompleteStoreContext } from './context.ts'\n\nconst body = typeof document !== 'undefined' && document.querySelector('body')\nconst defaultBoundary = body || 'clippingAncestors'\n\n/**\n * @public\n */\nexport interface AutocompletePositionerProps extends OverlayPositionerProps {\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\n/** @internal */\nexport const AutocompletePositionerPropsDeclaration: PropsDeclaration<AutocompletePositionerProps> = /* @__PURE__ */ defineProps<\n AutocompletePositionerProps\n>({\n ...OverlayPositionerPropsDeclaration,\n placement: { default: 'bottom-start', attribute: 'placement', type: 'string' },\n offset: { default: 4, attribute: false, type: 'json' },\n inline: { default: true, attribute: 'inline', type: 'boolean' },\n hoist: { default: true, attribute: 'hoist', type: 'boolean' },\n fitViewport: { default: true, attribute: 'fit-viewport', type: 'boolean' },\n boundary: { default: defaultBoundary, attribute: false, type: 'json' },\n overflowPadding: { default: 8, attribute: 'overflow-padding', type: 'number' },\n})\n\n/** @internal */\nexport function setupAutocompletePositioner(\n host: HostElement,\n props: State<AutocompletePositionerProps>,\n): void {\n const getStore = autocompleteStoreContext.consume(host)\n const getOverlayStore = () => getStore()?.overlayStore\n setupOverlayPositioner(host, props as unknown as State<OverlayPositionerProps>, getOverlayStore)\n}\n\nconst AutocompletePositionerElementBase: HostElementConstructor<AutocompletePositionerProps> = defineCustomElement(\n setupAutocompletePositioner,\n AutocompletePositionerPropsDeclaration,\n)\n\n/**\n * `<prosekit-autocomplete-positioner>` custom element.\n *\n * Properties: {@link AutocompletePositionerProps}\n *\n * Data attributes:\n *\n * | Attribute | Description |\n * | --- | --- |\n * | `data-state` | `\"open\"` when the autocomplete is visible, `\"closed\"` otherwise |\n * | `data-side` | The side of the anchor element the positioner is on |\n * | `data-align` | The alignment of the positioner relative to the anchor element |\n *\n * CSS variables:\n *\n * | Variable | Description |\n * | --- | --- |\n * | `--transform-origin` | The coordinates that this element is anchored to. Useful for scale animations. |\n */\nexport class AutocompletePositionerElement extends AutocompletePositionerElementBase {}\n\n/** @internal */\nexport function registerAutocompletePositionerElement(): void {\n registerCustomElement('prosekit-autocomplete-positioner', AutocompletePositionerElement)\n}\n","function cloneKeyboardEvent(source: KeyboardEvent): KeyboardEvent {\n return new KeyboardEvent(source.type, {\n code: source.code,\n key: source.key,\n location: source.location,\n repeat: source.repeat,\n altKey: source.altKey,\n ctrlKey: source.ctrlKey,\n metaKey: source.metaKey,\n shiftKey: source.shiftKey,\n\n view: source.view,\n // internal bridge target; events don't need to bubble\"\n bubbles: false,\n cancelable: true,\n })\n}\n\nexport class KeyboardEventTarget extends EventTarget {\n override dispatchEvent(event: KeyboardEvent): boolean {\n const newEvent = cloneKeyboardEvent(event)\n const result: boolean = super.dispatchEvent(newEvent)\n if (newEvent.defaultPrevented) {\n event.preventDefault()\n }\n return result\n }\n}\n","export function defaultQueryBuilder(match: RegExpExecArray): string {\n return match[0]\n .toLowerCase()\n .replaceAll(/[!\"#$%&'()*+,-./:;<=>?@[\\\\\\]^_`{|}~]/g, '')\n .replaceAll(/\\s\\s+/g, ' ')\n .trim()\n}\n","import {\n createSignal,\n defineCustomElement,\n defineProps,\n registerCustomElement,\n useEffect,\n type HostElement,\n type HostElementConstructor,\n type PropsDeclaration,\n type Signal,\n type State,\n} from '@aria-ui/core'\nimport { defaultItemFilter, type ItemFilter, type ListboxRootEvents } from '@aria-ui/elements/listbox'\nimport { createOverlayStore, OpenChangeEvent, type OverlayStore } from '@aria-ui/elements/overlay'\nimport { useEventListener } from '@aria-ui/utils'\nimport { defineDOMEventHandler, defineKeymap, withPriority, type Editor, type Extension, type Priority } from '@prosekit/core'\nimport { AutocompleteRule, defineAutocomplete, type MatchHandler } from '@prosekit/extensions/autocomplete'\n\nimport { useEditorExtension } from '../../hooks/use-editor-extension.ts'\nimport { KeyboardEventTarget } from '../../utils/event.ts'\nimport { getSafeEditorView } from '../../utils/get-safe-editor-view.ts'\n\nimport { autocompleteStoreContext, type AutocompleteStore } from './context.ts'\nimport { defaultQueryBuilder } from './helpers.ts'\n\nexport { OpenChangeEvent }\n\nexport interface AutocompleteRootProps {\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 filter function to determine if an item should be shown in the\n * listbox.\n *\n * @default defaultItemFilter\n */\n filter: ItemFilter | null\n}\n\n/** @internal */\nexport const AutocompleteRootPropsDeclaration: PropsDeclaration<AutocompleteRootProps> = /* @__PURE__ */ defineProps<\n AutocompleteRootProps\n>({\n editor: { default: null, attribute: false, type: 'json' },\n regex: { default: null, attribute: false, type: 'json' },\n filter: { default: defaultItemFilter, attribute: false, type: 'json' },\n})\n\n/**\n * @public\n */\nexport class QueryChangeEvent extends Event {\n /**\n * The current query string.\n */\n readonly detail: string\n\n constructor(query: string) {\n super('queryChange', { bubbles: true })\n this.detail = query\n }\n}\n\n/**\n * @public\n */\nexport interface AutocompleteRootEvents extends ListboxRootEvents {\n /**\n * Fired when the open state changes.\n */\n openChange: OpenChangeEvent\n\n /**\n * Fired when the query changes.\n */\n queryChange: QueryChangeEvent\n}\n\ninterface RuleHandlers {\n submit?: VoidFunction\n dismiss?: VoidFunction\n}\n\ninterface AutocompleteRuleDeps {\n reference: Signal<Element | undefined>\n handlers: RuleHandlers\n setQuery: (next: string) => void\n requestOpenChange: (open: boolean) => void\n}\n\n/**\n * @internal\n */\nexport function setupAutocompleteRoot(\n host: HostElement,\n props: State<AutocompleteRootProps>,\n): void {\n const getEditor = props.editor.get\n\n const reference = createSignal<Element | undefined>(undefined)\n const open = createSignal(false)\n const query = createSignal('')\n const keyboardTarget = new KeyboardEventTarget()\n const eventTarget = createSignal<EventTarget | null>(keyboardTarget)\n const handlers: RuleHandlers = {}\n\n // Create overlay store for positioning. The open state is managed by the\n // overlay store via requestOpenChange(), which dispatches OpenChangeEvent and\n // updates the open signal.\n const overlayStore: OverlayStore = createOverlayStore(\n open.get,\n open.set,\n () => false,\n () => false,\n (event) => host.dispatchEvent(event),\n )\n\n useEffect(host, () => {\n overlayStore.setAnchorElement(reference.get())\n })\n\n const autocompleteStore: AutocompleteStore = {\n overlayStore,\n query,\n eventTarget,\n filter: props.filter,\n }\n\n autocompleteStoreContext.provide(host, autocompleteStore)\n\n useEventListener(host, 'valueChange', () => {\n handlers.submit?.()\n })\n\n useKeyboardBridge(host, getEditor, open.get, keyboardTarget)\n\n useEscapeKeydown(host, getEditor, () => {\n if (!open.get() || !handlers.dismiss) return false\n handlers.dismiss()\n return true\n })\n\n const setQuery = (next: string): void => {\n if (query.get() === next) return\n query.set(next)\n host.dispatchEvent(new QueryChangeEvent(next))\n }\n\n useAutocompleteExtension(host, getEditor, props.regex.get, {\n reference,\n handlers,\n setQuery,\n requestOpenChange: (open) => overlayStore.requestOpenChange(open),\n })\n}\n\nconst EVENT_KEYS = [\n 'ArrowDown',\n 'ArrowRight',\n 'ArrowUp',\n 'ArrowLeft',\n 'Home',\n 'End',\n 'Enter',\n] as const\n\nfunction useKeyboardBridge(\n host: HostElement,\n getEditor: () => Editor | null,\n getOpen: () => boolean,\n target: EventTarget,\n): void {\n const extension: Extension = defineDOMEventHandler('keydown', (view, event): boolean => {\n if (\n view.composing\n || event.defaultPrevented\n || !getOpen()\n || !EVENT_KEYS.includes(event.key as (typeof EVENT_KEYS)[number])\n ) {\n return false\n }\n target.dispatchEvent(event)\n return event.defaultPrevented\n })\n useEditorExtension(host, getEditor, withPriority(extension, 4 satisfies typeof Priority.highest))\n}\n\nfunction useAutocompleteExtension(\n host: HostElement,\n getEditor: () => Editor | null,\n getRegex: () => RegExp | null,\n deps: AutocompleteRuleDeps,\n) {\n useEffect(host, () => {\n const editor = getEditor()\n const regex = getRegex()\n\n if (!editor || !regex) {\n return\n }\n\n const rule = createAutocompleteRule(editor, regex, deps)\n const extension = defineAutocomplete(rule)\n return editor.use(extension)\n })\n}\n\nfunction createAutocompleteRule(\n editor: Editor,\n regex: RegExp,\n deps: AutocompleteRuleDeps,\n) {\n const { reference, handlers, setQuery, requestOpenChange } = deps\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 handlers.submit = options.deleteMatch\n handlers.dismiss = options.ignoreMatch\n setQuery(defaultQueryBuilder(options.match))\n requestOpenChange(true)\n }\n\n const handleLeave = () => {\n reference.set(undefined)\n setQuery('')\n handlers.submit = undefined\n handlers.dismiss = undefined\n requestOpenChange(false)\n }\n\n return new AutocompleteRule({\n regex,\n onEnter: handleEnter,\n onLeave: handleLeave,\n })\n}\n\nfunction useEscapeKeydown(\n host: HostElement,\n getEditor: () => Editor | null,\n handler: () => boolean,\n): void {\n const keymap = { Escape: handler }\n const extension = withPriority(defineKeymap(keymap), 4 satisfies typeof Priority.highest)\n useEditorExtension(host, getEditor, extension)\n}\n\nconst AutocompleteRootElementBase: HostElementConstructor<AutocompleteRootProps> = defineCustomElement(\n setupAutocompleteRoot,\n AutocompleteRootPropsDeclaration,\n)\n\n/**\n * `<prosekit-autocomplete-root>` custom element.\n *\n * Properties: {@link AutocompleteRootProps}\n *\n * Events: {@link AutocompleteRootEvents}\n */\nexport class AutocompleteRootElement extends AutocompleteRootElementBase {}\n\n/** @internal */\nexport function registerAutocompleteRootElement(): void {\n registerCustomElement('prosekit-autocomplete-root', AutocompleteRootElement)\n}\n"],"mappings":";;;;;;;;;AAcA,MAAa,oCAA8F,4BAEzG,EAAE,CAAC;;;;AAKL,SAAgB,uBACd,MACA,OACM;AACN,mBAAkB,MAAM,MAAM;;AAGhC,MAAM,+BAA+E,oBACnF,wBACA,kCACD;;;;;;AAOD,IAAa,2BAAb,cAA8C,6BAA6B;;AAG3E,SAAgB,mCAAyC;AACvD,uBAAsB,+BAA+B,yBAAyB;;AC1ChF,SAAgB,eAAe,OAAoB;AACjD,OAAM,gBAAgB;;;AC2BxB,MAAa,mCAA4F,4BACvG;CACE,OAAO;EAAE,SAAS;EAAI,WAAW;EAAS,MAAM;EAAU;CAC1D,UAAU;EAAE,SAAS;EAAO,WAAW;EAAY,MAAM;EAAW;CACrE,CACF;;;;AAOD,SAAgB,sBACd,MACA,OACM;AACN,kBAAiB,MAAM,MAAM;AAG7B,kBAAiB,MAAM,eAAe,eAAe;AACrD,kBAAiB,MAAM,aAAa,eAAe;;AAGrD,MAAM,8BAA6E,oBACjF,uBACA,iCACD;;;;;;;;;;;;;;AAeD,IAAa,0BAAb,cAA6C,4BAA4B;;AAGzE,SAAgB,kCAAwC;AACtD,uBAAsB,8BAA8B,wBAAwB;;ACvE9E,SAAgB,iBACd,WACA,UACW;AACX,QAAO;EACL,WAAc;GACZ,MAAM,SAAS,WAAW;AAC1B,UAAO,SAAS,OAAO,KAAK,GAAG;;EAEjC,MAAM,UAAmB;GACvB,MAAM,SAAS,WAAW;AAC1B,OAAI,OAAQ,QAAO,IAAI,MAAM;;EAEhC;;ACbH,SAAgB,WAAW,MAAyB;AAClD,SAAQ,YAAY;AAClB,OAAK,WAAW;GAChB;;;;;ACYJ,MAAa,2BAAuD,cAA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ete.js","names":[],"sources":["../src/components/autocomplete/autocomplete-empty.ts","../src/utils/prevent-default.ts","../src/components/autocomplete/autocomplete-item.ts","../src/utils/lazy-signal.ts","../src/utils/use-no-focus.ts","../src/components/autocomplete/context.ts","../src/components/autocomplete/autocomplete-popup.ts","../src/components/autocomplete/autocomplete-positioner.ts","../src/utils/event.ts","../src/components/autocomplete/helpers.ts","../src/components/autocomplete/autocomplete-root.ts"],"sourcesContent":["import {\n defineCustomElement,\n defineProps,\n registerCustomElement,\n type HostElement,\n type HostElementConstructor,\n type PropsDeclaration,\n type State,\n} from '@aria-ui/core'\nimport { setupListboxEmpty, type ListboxEmptyProps } from '@aria-ui/elements/listbox'\n\nexport interface AutocompleteEmptyProps extends ListboxEmptyProps {}\n\n/** @internal */\nexport const AutocompleteEmptyPropsDeclaration: PropsDeclaration<AutocompleteEmptyProps> = /* @__PURE__ */ defineProps<\n AutocompleteEmptyProps\n>({})\n\n/**\n * @internal\n */\nexport function setupAutocompleteEmpty(\n host: HostElement,\n props: State<AutocompleteEmptyProps>,\n): void {\n setupListboxEmpty(host, props)\n}\n\nconst AutocompleteEmptyElementBase: HostElementConstructor<AutocompleteEmptyProps> = defineCustomElement(\n setupAutocompleteEmpty,\n AutocompleteEmptyPropsDeclaration,\n)\n\n/**\n * `<prosekit-autocomplete-empty>` custom element.\n *\n * Properties: {@link AutocompleteEmptyProps}\n */\nexport class AutocompleteEmptyElement extends AutocompleteEmptyElementBase {}\n\n/** @internal */\nexport function registerAutocompleteEmptyElement(): void {\n registerCustomElement('prosekit-autocomplete-empty', AutocompleteEmptyElement)\n}\n","export function preventDefault(event: Event): void {\n event.preventDefault()\n}\n","import {\n defineCustomElement,\n defineProps,\n registerCustomElement,\n type HostElement,\n type HostElementConstructor,\n type PropsDeclaration,\n type State,\n} from '@aria-ui/core'\nimport { SelectEvent, setupListboxItem, type ListboxItemEvents, type ListboxItemProps } from '@aria-ui/elements/listbox'\nimport { useEventListener } from '@aria-ui/utils'\n\nimport { preventDefault } from '../../utils/prevent-default.ts'\n\nexport { SelectEvent }\n\nexport interface AutocompleteItemProps extends ListboxItemProps {\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 AutocompleteItemPropsDeclaration: PropsDeclaration<AutocompleteItemProps> = /* @__PURE__ */ defineProps<AutocompleteItemProps>(\n {\n value: { default: '', attribute: 'value', type: 'string' },\n disabled: { default: false, attribute: 'disabled', type: 'boolean' },\n },\n)\n\nexport interface AutocompleteItemEvents extends ListboxItemEvents {}\n\n/**\n * @internal\n */\nexport function setupAutocompleteItem(\n host: HostElement,\n props: State<AutocompleteItemProps>,\n): void {\n setupListboxItem(host, props)\n\n // Prevent the editor from losing focus\n useEventListener(host, 'pointerdown', preventDefault)\n useEventListener(host, 'mousedown', preventDefault)\n}\n\nconst AutocompleteItemElementBase: HostElementConstructor<AutocompleteItemProps> = defineCustomElement(\n setupAutocompleteItem,\n AutocompleteItemPropsDeclaration,\n)\n\n/**\n * `<prosekit-autocomplete-item>` custom element.\n *\n * Properties: {@link AutocompleteItemProps}\n *\n * Events: {@link AutocompleteItemEvents}\n *\n * Data attributes:\n *\n * | Attribute | Description |\n * | --- | --- |\n * | `data-highlighted` | Present when the item is the currently highlighted option |\n */\nexport class AutocompleteItemElement extends AutocompleteItemElementBase {}\n\n/** @internal */\nexport function registerAutocompleteItemElement(): void {\n registerCustomElement('prosekit-autocomplete-item', AutocompleteItemElement)\n}\n","import type { Signal } from '@aria-ui/core'\n\nexport function createLazySignal<T>(\n getRemote: () => Signal<T> | undefined,\n fallback: T,\n): Signal<T> {\n return {\n get: (): T => {\n const remote = getRemote()\n return remote ? remote.get() : fallback\n },\n set: (value: T): void => {\n const remote = getRemote()\n if (remote) remote.set(value)\n },\n }\n}\n","import { onMount, type HostElement } from '@aria-ui/core'\n\nexport function useNoFocus(host: HostElement): void {\n onMount(host, () => {\n host.tabIndex = -1\n })\n}\n","import { createContext, type Context, type Signal } from '@aria-ui/core'\nimport type { ItemFilter } from '@aria-ui/elements/listbox'\nimport type { OverlayStore } from '@aria-ui/elements/overlay'\n\n/**\n * @internal\n */\nexport interface AutocompleteStore {\n overlayStore: OverlayStore\n query: Signal<string>\n eventTarget: Signal<EventTarget | null>\n filter: Signal<ItemFilter | null>\n}\n\n/**\n * @internal\n */\nexport const autocompleteStoreContext: Context<AutocompleteStore> = createContext<AutocompleteStore>('prosekit-autocomplete-store')\n","import {\n createSignal,\n defineCustomElement,\n defineProps,\n registerCustomElement,\n type HostElement,\n type HostElementConstructor,\n type PropsDeclaration,\n type Signal,\n type State,\n} from '@aria-ui/core'\nimport {\n defaultItemFilter,\n setupListboxRoot,\n type ItemFilter,\n type ListboxRootEvents,\n type ListboxRootProps,\n} from '@aria-ui/elements/listbox'\nimport { OverlayPopupPropsDeclaration, setupOverlayPopup, type OverlayPopupProps } from '@aria-ui/elements/overlay'\n\nimport { createLazySignal } from '../../utils/lazy-signal.ts'\nimport { useNoFocus } from '../../utils/use-no-focus.ts'\n\nimport { autocompleteStoreContext } from './context.ts'\n\n/**\n * @public\n */\nexport interface AutocompletePopupProps extends OverlayPopupProps {}\n\n/**\n * @public\n */\nexport interface AutocompletePopupEvents extends ListboxRootEvents {}\n\n/** @internal */\nexport const AutocompletePopupPropsDeclaration: PropsDeclaration<AutocompletePopupProps> = /* @__PURE__ */ defineProps<\n AutocompletePopupProps\n>(OverlayPopupPropsDeclaration)\n\n/** @internal */\nexport function setupAutocompletePopup(\n host: HostElement,\n _props: State<AutocompletePopupProps>,\n): void {\n const getStore = autocompleteStoreContext.consume(host)\n const getOverlayStore = () => getStore()?.overlayStore\n\n setupOverlayPopup(host, getOverlayStore)\n\n const query = createLazySignal<string>(() => getStore()?.query, ' ')\n const eventTarget = createLazySignal<EventTarget | null>(() => getStore()?.eventTarget, null)\n const filter = createLazySignal<ItemFilter | null>(() => getStore()?.filter, defaultItemFilter)\n const getDisabled = () => (!(getOverlayStore()?.getIsOpen?.()))\n const disabled: Signal<boolean> = { get: getDisabled, set: () => {} }\n const listboxProps = createPopupListboxProps(filter, query, eventTarget, disabled)\n\n setupListboxRoot(host, listboxProps)\n useNoFocus(host)\n}\n\nfunction createPopupListboxProps(\n filter: Signal<ItemFilter | null>,\n query: Signal<string>,\n eventTarget: Signal<EventTarget | null>,\n disabled: Signal<boolean>,\n): State<ListboxRootProps> {\n return {\n value: createSignal(''),\n values: createSignal<string[]>([]),\n multiple: createSignal(false),\n disabled,\n orientation: createSignal<'vertical' | 'horizontal'>('vertical'),\n loop: createSignal(false),\n autoHighlight: createSignal(true),\n query,\n eventTarget,\n filter,\n }\n}\n\nconst AutocompletePopupElementBase: HostElementConstructor<AutocompletePopupProps> = defineCustomElement(\n setupAutocompletePopup,\n AutocompletePopupPropsDeclaration,\n)\n\n/**\n * `<prosekit-autocomplete-popup>` custom element.\n *\n * Properties: {@link AutocompletePopupProps}\n *\n * Events: {@link AutocompletePopupEvents}\n *\n * Data attributes:\n *\n * | Attribute | Description |\n * | --- | --- |\n * | `data-state` | `\"open\"` when the autocomplete is visible, `\"closed\"` otherwise |\n */\nexport class AutocompletePopupElement extends AutocompletePopupElementBase {}\n\n/** @internal */\nexport function registerAutocompletePopupElement(): void {\n registerCustomElement('prosekit-autocomplete-popup', AutocompletePopupElement)\n}\n","import {\n defineCustomElement,\n defineProps,\n registerCustomElement,\n type HostElement,\n type HostElementConstructor,\n type PropsDeclaration,\n type State,\n} from '@aria-ui/core'\nimport { OverlayPositionerPropsDeclaration, setupOverlayPositioner, type OverlayPositionerProps } from '@aria-ui/elements/overlay'\n\nimport { autocompleteStoreContext } from './context.ts'\n\nconst body = typeof document !== 'undefined' && document.querySelector('body')\nconst defaultBoundary = body || 'clippingAncestors'\n\n/**\n * @public\n */\nexport interface AutocompletePositionerProps extends OverlayPositionerProps {\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 text selection.\n *\n * @default { mainAxis: 8, crossAxis: -4 }\n */\n offset: OverlayPositionerProps['offset']\n\n /**\n * Whether to hide the floating element when the reference element or the\n * floating element is fully clipped.\n *\n * @default true\n */\n hide: OverlayPositionerProps['hide']\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\n/** @internal */\nexport const AutocompletePositionerPropsDeclaration: PropsDeclaration<AutocompletePositionerProps> = /* @__PURE__ */ defineProps<\n AutocompletePositionerProps\n>({\n ...OverlayPositionerPropsDeclaration,\n placement: { default: 'bottom-start', attribute: 'placement', type: 'string' },\n offset: { default: { mainAxis: 8, crossAxis: -4 }, attribute: false },\n hide: { default: true, attribute: 'hide', type: 'boolean' },\n inline: { default: true, attribute: 'inline', type: 'boolean' },\n hoist: { default: true, attribute: 'hoist', type: 'boolean' },\n fitViewport: { default: true, attribute: 'fit-viewport', type: 'boolean' },\n boundary: { default: defaultBoundary, attribute: false },\n overflowPadding: { default: 8, attribute: 'overflow-padding', type: 'number' },\n})\n\n/** @internal */\nexport function setupAutocompletePositioner(\n host: HostElement,\n props: State<AutocompletePositionerProps>,\n): void {\n const getStore = autocompleteStoreContext.consume(host)\n const getOverlayStore = () => getStore()?.overlayStore\n setupOverlayPositioner(host, props satisfies State<OverlayPositionerProps>, getOverlayStore)\n}\n\nconst AutocompletePositionerElementBase: HostElementConstructor<AutocompletePositionerProps> = defineCustomElement(\n setupAutocompletePositioner,\n AutocompletePositionerPropsDeclaration,\n)\n\n/**\n * `<prosekit-autocomplete-positioner>` custom element.\n *\n * Properties: {@link AutocompletePositionerProps}\n *\n * Data attributes:\n *\n * | Attribute | Description |\n * | --- | --- |\n * | `data-state` | `\"open\"` when the autocomplete is visible, `\"closed\"` otherwise |\n * | `data-side` | The side of the anchor element the positioner is on |\n * | `data-align` | The alignment of the positioner relative to the anchor element |\n *\n * CSS variables:\n *\n * | Variable | Description |\n * | --- | --- |\n * | `--transform-origin` | The coordinates that this element is anchored to. Useful for scale animations. |\n */\nexport class AutocompletePositionerElement extends AutocompletePositionerElementBase {}\n\n/** @internal */\nexport function registerAutocompletePositionerElement(): void {\n registerCustomElement('prosekit-autocomplete-positioner', AutocompletePositionerElement)\n}\n","function cloneKeyboardEvent(source: KeyboardEvent): KeyboardEvent {\n return new KeyboardEvent(source.type, {\n code: source.code,\n key: source.key,\n location: source.location,\n repeat: source.repeat,\n altKey: source.altKey,\n ctrlKey: source.ctrlKey,\n metaKey: source.metaKey,\n shiftKey: source.shiftKey,\n\n view: source.view,\n // internal bridge target; events don't need to bubble\"\n bubbles: false,\n cancelable: true,\n })\n}\n\nexport class KeyboardEventTarget extends EventTarget {\n override dispatchEvent(event: KeyboardEvent): boolean {\n const newEvent = cloneKeyboardEvent(event)\n const result: boolean = super.dispatchEvent(newEvent)\n if (newEvent.defaultPrevented) {\n event.preventDefault()\n }\n return result\n }\n}\n","export function defaultQueryBuilder(match: RegExpExecArray): string {\n return match[0]\n .toLowerCase()\n .replaceAll(/[!\"#$%&'()*+,-./:;<=>?@[\\\\\\]^_`{|}~]/g, '')\n .replaceAll(/\\s\\s+/g, ' ')\n .trim()\n}\n","import {\n createSignal,\n defineCustomElement,\n defineProps,\n registerCustomElement,\n useEffect,\n type HostElement,\n type HostElementConstructor,\n type PropsDeclaration,\n type Signal,\n type State,\n} from '@aria-ui/core'\nimport { defaultItemFilter, type ItemFilter, type ListboxRootEvents } from '@aria-ui/elements/listbox'\nimport { createOverlayStore, OpenChangeEvent, type OverlayStore } from '@aria-ui/elements/overlay'\nimport { useEventListener } from '@aria-ui/utils'\nimport type { ReferenceElement, VirtualElement } from '@floating-ui/dom'\nimport { defineDOMEventHandler, defineKeymap, withPriority, type Editor, type Extension, type Priority } from '@prosekit/core'\nimport { AutocompleteRule, defineAutocomplete, type MatchHandler } from '@prosekit/extensions/autocomplete'\n\nimport { useEditorExtension } from '../../hooks/use-editor-extension.ts'\nimport { KeyboardEventTarget } from '../../utils/event.ts'\nimport { getSafeEditorView } from '../../utils/get-safe-editor-view.ts'\n\nimport { autocompleteStoreContext, type AutocompleteStore } from './context.ts'\nimport { defaultQueryBuilder } from './helpers.ts'\n\nexport { OpenChangeEvent }\n\nexport interface AutocompleteRootProps {\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 filter function to determine if an item should be shown in the\n * listbox.\n *\n * @default defaultItemFilter\n */\n filter: ItemFilter | null\n\n /**\n * The reference to position the popup against. This can be a DOM element, a\n * Floating UI virtual element, or a function that returns either of them.\n * By default, the popup will be positioned against the text content that\n * triggers the autocomplete.\n *\n * @default null\n */\n anchor: Element | VirtualElement | (() => Element | VirtualElement | null) | null\n}\n\n/** @internal */\nexport const AutocompleteRootPropsDeclaration: PropsDeclaration<AutocompleteRootProps> = /* @__PURE__ */ defineProps<\n AutocompleteRootProps\n>({\n editor: { default: null, attribute: false },\n regex: { default: null, attribute: false },\n filter: { default: defaultItemFilter, attribute: false },\n anchor: { default: null, attribute: false },\n})\n\n/**\n * @public\n */\nexport class QueryChangeEvent extends Event {\n /**\n * The current query string.\n */\n readonly detail: string\n\n constructor(query: string) {\n super('queryChange', { bubbles: true })\n this.detail = query\n }\n}\n\n/**\n * @public\n */\nexport interface AutocompleteRootEvents extends ListboxRootEvents {\n /**\n * Fired when the open state changes.\n */\n openChange: OpenChangeEvent\n\n /**\n * Fired when the query changes.\n */\n queryChange: QueryChangeEvent\n}\n\ninterface RuleHandlers {\n submit?: VoidFunction\n dismiss?: VoidFunction\n}\n\ninterface AutocompleteRuleDeps {\n reference: Signal<ReferenceElement | undefined>\n handlers: RuleHandlers\n setQuery: (next: string) => void\n requestOpenChange: (open: boolean) => void\n}\n\n/**\n * @internal\n */\nexport function setupAutocompleteRoot(\n host: HostElement,\n props: State<AutocompleteRootProps>,\n): void {\n const getEditor = props.editor.get\n\n const reference = createSignal<ReferenceElement | undefined>(undefined)\n const open = createSignal(false)\n const query = createSignal('')\n const keyboardTarget = new KeyboardEventTarget()\n const eventTarget = createSignal<EventTarget | null>(keyboardTarget)\n const handlers: RuleHandlers = {}\n\n // Create overlay store for positioning. The open state is managed by the\n // overlay store via requestOpenChange(), which dispatches OpenChangeEvent and\n // updates the open signal.\n const overlayStore: OverlayStore = createOverlayStore(\n open.get,\n open.set,\n () => false,\n () => false,\n (event) => host.dispatchEvent(event),\n )\n\n useEffect(host, () => {\n overlayStore.setAnchorElement(reference.get())\n })\n\n const autocompleteStore: AutocompleteStore = {\n overlayStore,\n query,\n eventTarget,\n filter: props.filter,\n }\n\n autocompleteStoreContext.provide(host, autocompleteStore)\n\n useEventListener(host, 'valueChange', () => {\n handlers.submit?.()\n })\n\n useKeyboardBridge(host, getEditor, open.get, keyboardTarget)\n\n useEscapeKeydown(host, getEditor, () => {\n if (!open.get() || !handlers.dismiss) return false\n handlers.dismiss()\n return true\n })\n\n const setQuery = (next: string): void => {\n if (query.get() === next) return\n query.set(next)\n host.dispatchEvent(new QueryChangeEvent(next))\n }\n\n const getAnchor = (): ReferenceElement | null => {\n const customAnchor = props.anchor.get()\n if (customAnchor) {\n if (typeof customAnchor === 'function') {\n return customAnchor() || null\n } else {\n return customAnchor\n }\n }\n const view = getSafeEditorView(getEditor())\n return view?.dom.querySelector('.prosekit-autocomplete-match') || null\n }\n\n useAutocompleteExtension(host, getEditor, props.regex.get, getAnchor, {\n reference,\n handlers,\n setQuery,\n requestOpenChange: (open) => overlayStore.requestOpenChange(open),\n })\n}\n\nconst EVENT_KEYS = [\n 'ArrowDown',\n 'ArrowRight',\n 'ArrowUp',\n 'ArrowLeft',\n 'Home',\n 'End',\n 'Enter',\n] as const\n\nfunction useKeyboardBridge(\n host: HostElement,\n getEditor: () => Editor | null,\n getOpen: () => boolean,\n target: EventTarget,\n): void {\n const extension: Extension = defineDOMEventHandler('keydown', (view, event): boolean => {\n if (\n view.composing\n || event.defaultPrevented\n || !getOpen()\n || !EVENT_KEYS.includes(event.key as (typeof EVENT_KEYS)[number])\n ) {\n return false\n }\n target.dispatchEvent(event)\n return event.defaultPrevented\n })\n useEditorExtension(host, getEditor, withPriority(extension, 4 satisfies typeof Priority.highest))\n}\n\nfunction useAutocompleteExtension(\n host: HostElement,\n getEditor: () => Editor | null,\n getRegex: () => RegExp | null,\n getAnchor: () => ReferenceElement | null,\n deps: AutocompleteRuleDeps,\n) {\n useEffect(host, () => {\n const editor = getEditor()\n const regex = getRegex()\n\n if (!editor || !regex) {\n return\n }\n\n const rule = createAutocompleteRule(editor, regex, getAnchor, deps)\n const extension = defineAutocomplete(rule)\n return editor.use(extension)\n })\n}\n\nfunction createAutocompleteRule(\n editor: Editor,\n regex: RegExp,\n getAnchor: () => ReferenceElement | null,\n deps: AutocompleteRuleDeps,\n) {\n const { reference, handlers, setQuery, requestOpenChange } = deps\n\n const handleEnter: MatchHandler = (options) => {\n const anchor = getAnchor()\n reference.set(anchor || undefined)\n\n handlers.submit = options.deleteMatch\n handlers.dismiss = options.ignoreMatch\n setQuery(defaultQueryBuilder(options.match))\n requestOpenChange(true)\n }\n\n const handleLeave = () => {\n reference.set(undefined)\n setQuery('')\n handlers.submit = undefined\n handlers.dismiss = undefined\n requestOpenChange(false)\n }\n\n return new AutocompleteRule({\n regex,\n onEnter: handleEnter,\n onLeave: handleLeave,\n })\n}\n\nfunction useEscapeKeydown(\n host: HostElement,\n getEditor: () => Editor | null,\n handler: () => boolean,\n): void {\n const keymap = { Escape: handler }\n const extension = withPriority(defineKeymap(keymap), 4 satisfies typeof Priority.highest)\n useEditorExtension(host, getEditor, extension)\n}\n\nconst AutocompleteRootElementBase: HostElementConstructor<AutocompleteRootProps> = defineCustomElement(\n setupAutocompleteRoot,\n AutocompleteRootPropsDeclaration,\n)\n\n/**\n * `<prosekit-autocomplete-root>` custom element.\n *\n * Properties: {@link AutocompleteRootProps}\n *\n * Events: {@link AutocompleteRootEvents}\n */\nexport class AutocompleteRootElement extends AutocompleteRootElementBase {}\n\n/** @internal */\nexport function registerAutocompleteRootElement(): void {\n registerCustomElement('prosekit-autocomplete-root', AutocompleteRootElement)\n}\n"],"mappings":";;;;;;;;;AAcA,MAAa,oCAA8F,4BAEzG,EAAE,CAAC;;;;AAKL,SAAgB,uBACd,MACA,OACM;CACN,kBAAkB,MAAM,MAAM;;AAGhC,MAAM,+BAA+E,oBACnF,wBACA,kCACD;;;;;;AAOD,IAAa,2BAAb,cAA8C,6BAA6B;;AAG3E,SAAgB,mCAAyC;CACvD,sBAAsB,+BAA+B,yBAAyB;;AC1ChF,SAAgB,eAAe,OAAoB;CACjD,MAAM,gBAAgB;;;AC2BxB,MAAa,mCAA4F,4BACvG;CACE,OAAO;EAAE,SAAS;EAAI,WAAW;EAAS,MAAM;EAAU;CAC1D,UAAU;EAAE,SAAS;EAAO,WAAW;EAAY,MAAM;EAAW;CACrE,CACF;;;;AAOD,SAAgB,sBACd,MACA,OACM;CACN,iBAAiB,MAAM,MAAM;CAG7B,iBAAiB,MAAM,eAAe,eAAe;CACrD,iBAAiB,MAAM,aAAa,eAAe;;AAGrD,MAAM,8BAA6E,oBACjF,uBACA,iCACD;;;;;;;;;;;;;;AAeD,IAAa,0BAAb,cAA6C,4BAA4B;;AAGzE,SAAgB,kCAAwC;CACtD,sBAAsB,8BAA8B,wBAAwB;;ACvE9E,SAAgB,iBACd,WACA,UACW;CACX,OAAO;EACL,WAAc;GACZ,MAAM,SAAS,WAAW;GAC1B,OAAO,SAAS,OAAO,KAAK,GAAG;;EAEjC,MAAM,UAAmB;GACvB,MAAM,SAAS,WAAW;GAC1B,IAAI,QAAQ,OAAO,IAAI,MAAM;;EAEhC;;ACbH,SAAgB,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O,IAAI,iBAAiB;EAC1B;EACA,SAAS;EACT,SAAS;EACV,CAAC;;AAGJ,SAAS,iBACP,MACA,WACA,SACM;CAGN,mBAAmB,MAAM,WADP,aAAa,aAAa,EAD3B,QAAQ,SACyB,CAAC,EAAE,EACR,CAAC;;AAGhD,MAAM,8BAA6E,oBACjF,uBACA,iCACD;;;;;;;;AASD,IAAa,0BAAb,cAA6C,4BAA4B;;AAGzE,SAAgB,kCAAwC;CACtD,sBAAsB,8BAA8B,wBAAwB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-handle.d.ts","names":[],"sources":["../src/components/block-handle/block-handle-add.ts","../src/components/block-handle/block-handle-draggable.ts","../src/components/block-handle/block-handle-popup.ts","../src/components/block-handle/block-handle-positioner.ts","../src/components/block-handle/block-handle-root.ts"],"mappings":";;;;;UAciB,mBAAA;;;;AAAjB;;;EAOE,MAAA,EAAQ,MAAA;AAAA;AAIV;AAAA,cAAa,8BAAA,EAAgC,gBAAA,CAAiB,mBAAA;;;;iBAO9C,mBAAA,CACd,IAAA,EAAM,WAAA,EACN,KAAA,EAAO,KAAA,CAAM,mBAAA;AAAA,cAuBT,yBAAA,EAA2B,sBAAA,CAAuB,mBAAA;;;;;;cAU3C,qBAAA,SAA8B,yBAAA;;iBAG3B,6BAAA,CAAA;AAAA,UC7CC,yBAAA;;;;ADXjB;;;ECkBE,MAAA,EAAQ,MAAA;AAAA;ADPV;AAAA,cCWa,oCAAA,EAAsC,gBAAA,CAAiB,yBAAA;;;;iBASpD,yBAAA,CACd,IAAA,EAAM,WAAA,EACN,KAAA,EAAO,KAAA,CAAM,yBAAA;AAAA,cAgGT,+BAAA,EAAiC,sBAAA,CAAuB,yBAAA;;;;;;;;;;;;cAgBjD,2BAAA,SAAoC,+BAAA;ADxGhD;AAAA,iBC2Ge,mCAAA,CAAA;;;;UCnJC,qBAAA,SAA8B,iBAAA;;cAGlC,gCAAA,EAAkC,gBAAA,CAAiB,qBAAA;;iBAGhD,qBAAA,CACd,IAAA,EAAM,WAAA,EACN,MAAA,EAAQ,KAAA,CAAM,qBAAA;AAAA,cAMV,2BAAA,EAA6B,sBAAA,CAAuB,qBAAA;;;;;AFG1D;;;;;;;cEaa,uBAAA,SAAgC,2BAAA;;iBAG7B,+BAAA,CAAA;;;;UC/BC,0BAAA,SAAmC,IAAA,CAAK,sBAAA;EHHrB;;;;AAWpC;EGFE,SAAA,EAAW,SAAA;;;;AHSb;;;EGDE,KAAA;EHGa;;;;EGGb,IAAA;EHJA;;;;EGUA,KAAA;EHTiC;AAqBlC;;;EGNC,IAAA;AAAA;AHkBF;AAAA,cGda,qCAAA,EAAuC,gBAAA,CAAiB,0BAAA;;iBAcrD,0BAAA,CACd,IAAA,EAAM,WAAA,EACN,KAAA,EAAO,KAAA,CAAM,0BAAA;AAAA,cAMT,gCAAA,EAAkC,sBAAA,CAAuB,0BAAA;AHL/D;;;;;;AC7CA;;;;;AAWA;;;;;AASA;;;ADyBA,cG6Ba,4BAAA,SAAqC,gCAAA;;iBAGlC,oCAAA,CAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"block-handle.d.ts","names":[],"sources":["../src/components/block-handle/block-handle-add.ts","../src/components/block-handle/block-handle-draggable.ts","../src/components/block-handle/block-handle-popup.ts","../src/components/block-handle/block-handle-positioner.ts","../src/components/block-handle/block-handle-root.ts"],"mappings":";;;;;UAciB,mBAAA;;;;AAAjB;;;EAOE,MAAA,EAAQ,MAAA;AAAA;AAIV;AAAA,cAAa,8BAAA,EAAgC,gBAAA,CAAiB,mBAAA;;;;iBAO9C,mBAAA,CACd,IAAA,EAAM,WAAA,EACN,KAAA,EAAO,KAAA,CAAM,mBAAA;AAAA,cAuBT,yBAAA,EAA2B,sBAAA,CAAuB,mBAAA;;;;;;cAU3C,qBAAA,SAA8B,yBAAA;;iBAG3B,6BAAA,CAAA;AAAA,UC7CC,yBAAA;;;;ADXjB;;;ECkBE,MAAA,EAAQ,MAAA;AAAA;ADPV;AAAA,cCWa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AiB,GAAA;EAAA;AAAA;;AJO7C;;UIEgB,qBAAA;EJAgB;;AAUjC;EINE,WAAA,EAAa,2BAAA;AAAA;;;AJSf;iBIHgB,oBAAA,CACd,IAAA,EAAM,WAAA,EACN,KAAA,EAAO,KAAA,CAAM,oBAAA;AAAA,cAoCT,0BAAA,EAA4B,sBAAA,CAAuB,oBAAA;;;;AHhFzD;;;;cG4Fa,sBAAA,SAA+B,0BAAA;;iBAG5B,8BAAA,CAAA"}
|
package/dist/block-handle.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { t as useEditorExtension } from "./use-editor-extension.js";
|
|
2
2
|
import { t as getSafeEditorView } from "./get-safe-editor-view.js";
|
|
3
3
|
import { n as assignStyles, t as useScrolling } from "./use-scrolling.js";
|
|
4
|
+
import { t as useEditorUpdateEvent } from "./use-editor-update-event.js";
|
|
4
5
|
import { computed, createContext, createSignal, defineCustomElement, defineProps, onMount, registerCustomElement, useEffect } from "@aria-ui/core";
|
|
5
6
|
import { useAttribute, useEventListener } from "@aria-ui/utils";
|
|
6
7
|
import { OverlayPopupPropsDeclaration, OverlayPositionerPropsDeclaration, createOverlayStore, setupOverlayPopup, setupOverlayPositioner } from "@aria-ui/elements/overlay";
|
|
7
|
-
import { defineDOMEventHandler, insertDefaultBlock, union } from "@prosekit/core";
|
|
8
|
+
import { defineDOMEventHandler, insertDefaultBlock, isTextSelection, union } from "@prosekit/core";
|
|
8
9
|
import { isElement, isHTMLElement, isTextNode, throttle } from "@ocavue/utils";
|
|
9
10
|
import { Fragment, Slice } from "@prosekit/pm/model";
|
|
10
11
|
import { NodeSelection } from "@prosekit/pm/state";
|
|
@@ -28,8 +29,7 @@ const blockHandleOverlayStoreContext = createContext("prosekit-block-handle-over
|
|
|
28
29
|
/** @internal */
|
|
29
30
|
const BlockHandleAddPropsDeclaration = /* @__PURE__ */ defineProps({ editor: {
|
|
30
31
|
default: null,
|
|
31
|
-
attribute: false
|
|
32
|
-
type: "json"
|
|
32
|
+
attribute: false
|
|
33
33
|
} });
|
|
34
34
|
/**
|
|
35
35
|
* @internal
|
|
@@ -167,8 +167,7 @@ function setDragPreview(event, element) {
|
|
|
167
167
|
/** @internal */
|
|
168
168
|
const BlockHandleDraggablePropsDeclaration = /* @__PURE__ */ defineProps({ editor: {
|
|
169
169
|
default: null,
|
|
170
|
-
attribute: false
|
|
171
|
-
type: "json"
|
|
170
|
+
attribute: false
|
|
172
171
|
} });
|
|
173
172
|
/**
|
|
174
173
|
* @internal
|
|
@@ -282,8 +281,7 @@ const BlockHandlePositionerPropsDeclaration = /* @__PURE__ */ defineProps({
|
|
|
282
281
|
},
|
|
283
282
|
flip: {
|
|
284
283
|
default: false,
|
|
285
|
-
attribute: false
|
|
286
|
-
type: "json"
|
|
284
|
+
attribute: false
|
|
287
285
|
},
|
|
288
286
|
shift: {
|
|
289
287
|
default: false,
|
|
@@ -325,6 +323,14 @@ var BlockHandlePositionerElement = class extends BlockHandlePositionerElementBas
|
|
|
325
323
|
function registerBlockHandlePositionerElement() {
|
|
326
324
|
registerCustomElement("prosekit-block-handle-positioner", BlockHandlePositionerElement);
|
|
327
325
|
}
|
|
326
|
+
function useHasTextSelection(host, getEditor) {
|
|
327
|
+
const state = createSignal(false);
|
|
328
|
+
useEditorUpdateEvent(host, getEditor, (view) => {
|
|
329
|
+
const { selection } = view.state;
|
|
330
|
+
state.set(!selection.empty && isTextSelection(selection));
|
|
331
|
+
});
|
|
332
|
+
return state.get;
|
|
333
|
+
}
|
|
328
334
|
function prefersReducedMotion() {
|
|
329
335
|
if (typeof window === "undefined") return false;
|
|
330
336
|
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
@@ -536,8 +542,7 @@ function useHoverExtension(host, getEditor, handler) {
|
|
|
536
542
|
/** @internal */
|
|
537
543
|
const BlockHandleRootPropsDeclaration = /* @__PURE__ */ defineProps({ editor: {
|
|
538
544
|
default: null,
|
|
539
|
-
attribute: false
|
|
540
|
-
type: "json"
|
|
545
|
+
attribute: false
|
|
541
546
|
} });
|
|
542
547
|
/**
|
|
543
548
|
* @public
|
|
@@ -557,7 +562,8 @@ function setupBlockHandleRoot(host, props) {
|
|
|
557
562
|
blockHandleStoreContext.provide(host, store);
|
|
558
563
|
const reference = createSignal(void 0);
|
|
559
564
|
const getScrolling = useScrolling(host);
|
|
560
|
-
const
|
|
565
|
+
const getHasTextSelection = useHasTextSelection(host, getEditor);
|
|
566
|
+
const overlayStore = createOverlayStore(computed(() => !!store.hoverState.get() && !getScrolling() && !getHasTextSelection()), () => {}, () => true, () => false, (event) => host.dispatchEvent(event));
|
|
561
567
|
useHoverExtension(host, getEditor, (ref, hoverState) => {
|
|
562
568
|
reference.set(ref ?? void 0);
|
|
563
569
|
store.hoverState.set(hoverState);
|
package/dist/block-handle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-handle.js","names":[],"sources":["../src/components/block-handle/context.ts","../src/components/block-handle/block-handle-add.ts","../src/constants.ts","../src/utils/get-client-rect.ts","../src/utils/max-z-index.ts","../src/components/block-handle/set-drag-preview.ts","../src/components/block-handle/block-handle-draggable.ts","../src/components/block-handle/block-handle-popup.ts","../src/components/block-handle/block-handle-positioner.ts","../src/utils/prefers-reduced-motion.ts","../src/components/block-handle/hover-state.ts","../src/components/block-handle/pointer-move.ts","../src/components/block-handle/use-hover-extension.ts","../src/components/block-handle/block-handle-root.ts"],"sourcesContent":["import { createContext, createSignal, type Context, type Signal } from '@aria-ui/core'\nimport type { OverlayStore } from '@aria-ui/elements/overlay'\n\nimport type { HoverState } from './hover-state.ts'\n\n/**\n * @internal\n */\nexport class BlockHandleStore {\n readonly hoverState: Signal<HoverState | undefined> = createSignal<HoverState | undefined>(undefined)\n readonly dragging: Signal<boolean> = createSignal(false)\n}\n\n/**\n * @internal\n */\nexport const blockHandleStoreContext: Context<BlockHandleStore> = createContext<BlockHandleStore>('prosekit-block-handle-store')\n\n/**\n * @internal\n */\nexport const blockHandleOverlayStoreContext: Context<OverlayStore> = createContext<OverlayStore>('prosekit-block-handle-overlay-store')\n","import {\n defineCustomElement,\n defineProps,\n registerCustomElement,\n type HostElement,\n type HostElementConstructor,\n type PropsDeclaration,\n type State,\n} from '@aria-ui/core'\nimport { useEventListener } from '@aria-ui/utils'\nimport { insertDefaultBlock, type Editor } from '@prosekit/core'\n\nimport { blockHandleStoreContext } from './context.ts'\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 BlockHandleAddPropsDeclaration: PropsDeclaration<BlockHandleAddProps> = /* @__PURE__ */ defineProps<BlockHandleAddProps>({\n editor: { default: null, attribute: false, type: 'json' },\n})\n\n/**\n * @internal\n */\nexport function setupBlockHandleAdd(\n host: HostElement,\n props: State<BlockHandleAddProps>,\n): void {\n const getStore = blockHandleStoreContext.consume(host)\n\n useEventListener(host, 'pointerdown', (event) => {\n event.preventDefault()\n\n const store = getStore()\n const editor = props.editor.get()\n const hoverState = store?.hoverState.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 store?.hoverState.set(undefined)\n })\n}\n\nconst BlockHandleAddElementBase: HostElementConstructor<BlockHandleAddProps> = defineCustomElement(\n setupBlockHandleAdd,\n BlockHandleAddPropsDeclaration,\n)\n\n/**\n * `<prosekit-block-handle-add>` custom element.\n *\n * Properties: {@link BlockHandleAddProps}\n */\nexport class BlockHandleAddElement extends BlockHandleAddElementBase {}\n\n/** @internal */\nexport function registerBlockHandleAddElement(): void {\n registerCustomElement('prosekit-block-handle-add', BlockHandleAddElement)\n}\n","export const DRAGGING_CLASS_NAME = 'prosekit-dragging'\n","interface Rect {\n top: number\n bottom: number\n right: number\n left: number\n}\n\ninterface IncludeExtraOptions {\n top?: boolean\n bottom?: boolean\n right?: boolean\n left?: boolean\n}\n\n/**\n * Similar to `element.getBoundingClientRect`, but handles `display: contents` CSS\n * property and optionally includes margins and outlines.\n */\nexport function getClientRect(element: Element, includeExtra?: IncludeExtraOptions | false): Rect {\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 = [...element.children]\n const rects = children.map(child => getClientRect(child, includeExtra))\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 includeExtra ? addExtra(element, rect, includeExtra) : rect\n}\n\nfunction addExtra(element: Element, rect: Rect, options: IncludeExtraOptions): Rect {\n const view = element.ownerDocument?.defaultView\n if (!view) {\n return rect\n }\n\n const style = view.getComputedStyle(element)\n const marginTop = options.top ? Number.parseFloat(style.marginTop) || 0 : 0\n const marginBottom = options.bottom ? Number.parseFloat(style.marginBottom) || 0 : 0\n const marginRight = options.right ? Number.parseFloat(style.marginRight) || 0 : 0\n const marginLeft = options.left ? Number.parseFloat(style.marginLeft) || 0 : 0\n\n const outlineWidth = Number.parseFloat(style.outlineWidth) || 0\n const outlineOffset = Number.parseFloat(style.outlineOffset) || 0\n const outline = Math.max(outlineWidth + outlineOffset, 0)\n const outlineTop = options.top ? outline : 0\n const outlineBottom = options.bottom ? outline : 0\n const outlineRight = options.right ? outline : 0\n const outlineLeft = options.left ? outline : 0\n\n return {\n top: rect.top - Math.max(marginTop, outlineTop),\n bottom: rect.bottom + Math.max(marginBottom, outlineBottom),\n right: rect.right + Math.max(marginRight, outlineRight),\n left: rect.left - Math.max(marginLeft, outlineLeft),\n }\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 { DRAGGING_CLASS_NAME } from '../../constants.ts'\nimport { assignStyles } from '../../utils/assign-styles.ts'\nimport { getClientRect } from '../../utils/get-client-rect.ts'\nimport { maxZIndex } from '../../utils/max-z-index.ts'\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, { left: true, right: true, top: true, bottom: true })\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 // Add some class names so that all styles applied to\n // given class names can also be applied to the drag preview.\n container.classList.add('ProseMirror', DRAGGING_CLASS_NAME)\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 = element.cloneNode(true) as HTMLElement\n\n // A hardcoded opacity.\n clonedElement.style.setProperty('opacity', '0.8', 'important')\n // Hide the outline of the cloned element.\n clonedElement.style.setProperty('outline-color', 'transparent', 'important')\n\n container.appendChild(clonedElement)\n document.body.appendChild(container)\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 defineCustomElement,\n defineProps,\n onMount,\n registerCustomElement,\n type HostElement,\n type HostElementConstructor,\n type PropsDeclaration,\n type State,\n} from '@aria-ui/core'\nimport { useAttribute, useEventListener } from '@aria-ui/utils'\nimport { isHTMLElement } from '@ocavue/utils'\nimport type { Editor } from '@prosekit/core'\nimport type { ViewDragging } from '@prosekit/extensions/drop-indicator'\nimport { Fragment, Slice } from '@prosekit/pm/model'\nimport { NodeSelection } from '@prosekit/pm/state'\nimport type { EditorView } from '@prosekit/pm/view'\n\nimport { DRAGGING_CLASS_NAME } from '../../constants.ts'\nimport { getSafeEditorView } from '../../utils/get-safe-editor-view.ts'\n\nimport { blockHandleStoreContext } from './context.ts'\nimport type { HoverState } from './hover-state.ts'\nimport { setDragPreview } from './set-drag-preview.ts'\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 BlockHandleDraggablePropsDeclaration: PropsDeclaration<BlockHandleDraggableProps> = /* @__PURE__ */ defineProps<\n BlockHandleDraggableProps\n>({\n editor: { default: null, attribute: false, type: 'json' },\n})\n\n/**\n * @internal\n */\nexport function setupBlockHandleDraggable(\n host: HostElement,\n props: State<BlockHandleDraggableProps>,\n): void {\n const getStore = blockHandleStoreContext.consume(host)\n\n onMount(host, () => {\n host.draggable = true\n })\n\n usePointerDownHandler(host, () => getStore()?.hoverState.get() ?? null, props.editor.get)\n\n useEventListener(host, 'dragstart', (event) => {\n const store = getStore()\n store?.dragging.set(true)\n\n const view = getSafeEditorView(props.editor.get())\n const hoverState = store?.hoverState.get()\n\n if (view && hoverState) {\n view.dom.classList.add(DRAGGING_CLASS_NAME)\n createDraggingPreview(view, hoverState, event)\n setViewDragging(view, hoverState)\n }\n })\n\n useEventListener(host, 'dragend', () => {\n const store = getStore()\n store?.dragging.set(false)\n\n const view = getSafeEditorView(props.editor.get())\n if (view) {\n view.dom.classList.remove(DRAGGING_CLASS_NAME)\n }\n })\n\n useAttribute(host, 'data-dragging', () => (getStore()?.dragging.get() ? '' : undefined))\n}\n\nfunction usePointerDownHandler(\n host: HostElement,\n getHoverState: () => HoverState | null,\n getEditor: () => Editor | null,\n) {\n useEventListener(host, 'pointerdown', () => {\n const hoverState = getHoverState()\n const editor = getEditor()\n\n if (hoverState?.pos == null || !editor?.view) {\n return\n }\n\n const { view } = editor\n view.dispatch(\n view.state.tr.setSelection(NodeSelection.create(view.state.doc, hoverState.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 event.dataTransfer.clearData()\n event.dataTransfer.setData('text/html', element.outerHTML)\n event.dataTransfer.effectAllowed = 'copyMove'\n setDragPreview(event, element)\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\nconst BlockHandleDraggableElementBase: HostElementConstructor<BlockHandleDraggableProps> = defineCustomElement(\n setupBlockHandleDraggable,\n BlockHandleDraggablePropsDeclaration,\n)\n\n/**\n * `<prosekit-block-handle-draggable>` custom element.\n *\n * Properties: {@link BlockHandleDraggableProps}\n *\n * Data attributes:\n *\n * | Attribute | Description |\n * | --- | --- |\n * | `data-dragging` | Present when the element is being dragged |\n */\nexport class BlockHandleDraggableElement extends BlockHandleDraggableElementBase {}\n\n/** @internal */\nexport function registerBlockHandleDraggableElement(): void {\n registerCustomElement('prosekit-block-handle-draggable', BlockHandleDraggableElement)\n}\n","import {\n defineCustomElement,\n registerCustomElement,\n type HostElement,\n type HostElementConstructor,\n type PropsDeclaration,\n type State,\n} from '@aria-ui/core'\nimport { OverlayPopupPropsDeclaration, setupOverlayPopup, type OverlayPopupProps } from '@aria-ui/elements/overlay'\n\nimport { blockHandleOverlayStoreContext } from './context.ts'\n\n/**\n * @public\n */\nexport interface BlockHandlePopupProps extends OverlayPopupProps {}\n\n/** @internal */\nexport const BlockHandlePopupPropsDeclaration: PropsDeclaration<BlockHandlePopupProps> = OverlayPopupPropsDeclaration\n\n/** @internal */\nexport function setupBlockHandlePopup(\n host: HostElement,\n _props: State<BlockHandlePopupProps>,\n): void {\n const getOverlayStore = blockHandleOverlayStoreContext.consume(host)\n setupOverlayPopup(host, getOverlayStore)\n}\n\nconst BlockHandlePopupElementBase: HostElementConstructor<BlockHandlePopupProps> = defineCustomElement(\n setupBlockHandlePopup,\n BlockHandlePopupPropsDeclaration,\n)\n\n/**\n * `<prosekit-block-handle-popup>` custom element.\n *\n * Properties: {@link BlockHandlePopupProps}\n *\n * Data attributes:\n *\n * | Attribute | Description |\n * | --- | --- |\n * | `data-state` | `\"open\"` when the block handle is visible, `\"closed\"` otherwise |\n */\nexport class BlockHandlePopupElement extends BlockHandlePopupElementBase {}\n\n/** @internal */\nexport function registerBlockHandlePopupElement(): void {\n registerCustomElement('prosekit-block-handle-popup', BlockHandlePopupElement)\n}\n","import {\n defineCustomElement,\n defineProps,\n registerCustomElement,\n type HostElement,\n type HostElementConstructor,\n type PropsDeclaration,\n type State,\n} from '@aria-ui/core'\nimport { OverlayPositionerPropsDeclaration, setupOverlayPositioner, type OverlayPositionerProps } from '@aria-ui/elements/overlay'\nimport type { Placement } from '@floating-ui/dom'\n\nimport { blockHandleOverlayStoreContext } from './context.ts'\n\n/**\n * @public\n */\nexport interface BlockHandlePositionerProps extends Omit<OverlayPositionerProps, 'placement' | 'hoist' | 'flip' | 'shift' | 'hide'> {\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 BlockHandlePositionerPropsDeclaration: PropsDeclaration<BlockHandlePositionerProps> = /* @__PURE__ */ defineProps<\n BlockHandlePositionerProps\n>({\n ...OverlayPositionerPropsDeclaration,\n placement: { default: 'left', attribute: 'placement', type: 'string' },\n // Enabling `hoist` will cause the popover to have a small delay when\n // scrolling the page.\n hoist: { default: false, attribute: 'hoist', type: 'boolean' },\n flip: { default: false, attribute: false, type: 'json' },\n shift: { default: false, attribute: 'shift', type: 'boolean' },\n hide: { default: true, attribute: 'hide', type: 'boolean' },\n})\n\n/** @internal */\nexport function setupBlockHandlePositioner(\n host: HostElement,\n props: State<BlockHandlePositionerProps>,\n): void {\n const getOverlayStore = blockHandleOverlayStoreContext.consume(host)\n setupOverlayPositioner(host, props as unknown as State<OverlayPositionerProps>, getOverlayStore)\n}\n\nconst BlockHandlePositionerElementBase: HostElementConstructor<BlockHandlePositionerProps> = defineCustomElement(\n setupBlockHandlePositioner,\n BlockHandlePositionerPropsDeclaration,\n)\n\n/**\n * `<prosekit-block-handle-positioner>` custom element.\n *\n * Properties: {@link BlockHandlePositionerProps}\n *\n * Data attributes:\n *\n * | Attribute | Description |\n * | --- | --- |\n * | `data-state` | `\"open\"` when the block handle is visible, `\"closed\"` otherwise |\n * | `data-side` | The side of the anchor element the positioner is on |\n * | `data-align` | The alignment of the positioner relative to the anchor element |\n *\n * CSS variables:\n *\n * | Variable | Description |\n * | --- | --- |\n * | `--transform-origin` | The coordinates that this element is anchored to. Useful for scale animations. |\n */\nexport class BlockHandlePositionerElement extends BlockHandlePositionerElementBase {}\n\n/** @internal */\nexport function registerBlockHandlePositionerElement(): void {\n registerCustomElement('prosekit-block-handle-positioner', BlockHandlePositionerElement)\n}\n","export function prefersReducedMotion(): boolean {\n if (typeof window === 'undefined') {\n return false\n }\n return window.matchMedia('(prefers-reduced-motion: reduce)').matches\n}\n","import 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 function isHoverStateEqual(a: HoverState, b: HoverState): boolean {\n return a.pos === b.pos && a.node.eq(b.node)\n}\n","import type { VirtualElement } from '@floating-ui/dom'\nimport { isElement, isHTMLElement, isTextNode, throttle } from '@ocavue/utils'\nimport { defineDOMEventHandler, union, type PlainExtension } 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.ts'\n\nimport type { HoverState } from './hover-state.ts'\n\nexport type ElementHoverHandler = (\n reference?: VirtualElement,\n hoverState?: HoverState,\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()\n return\n }\n\n const { node, pos } = block\n const element = view.nodeDOM(pos)\n if (!element || !isHTMLElement(element)) {\n handler()\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()),\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 return getClientRect(node, { left: true, right: true })\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 type { HostElement } from '@aria-ui/core'\nimport type { Editor } from '@prosekit/core'\n\nimport { useEditorExtension } from '../../hooks/use-editor-extension.ts'\nimport { prefersReducedMotion } from '../../utils/prefers-reduced-motion.ts'\n\nimport { isHoverStateEqual, type HoverState } from './hover-state.ts'\nimport { defineElementHoverHandler, type ElementHoverHandler } from './pointer-move.ts'\n\nexport function useHoverExtension(\n host: HostElement,\n getEditor: () => Editor | null,\n handler: ElementHoverHandler,\n): void {\n const invalidTimeoutMs = prefersReducedMotion() ? 0 : 180\n\n let invalidTimeoutId: ReturnType<typeof setTimeout> | undefined\n\n let prevHoverState: HoverState | undefined\n\n const callHandler: ElementHoverHandler = (reference, hoverState) => {\n prevHoverState = hoverState\n handler(reference, hoverState)\n }\n\n const extension = defineElementHoverHandler((reference, hoverState) => {\n if (hoverState && invalidTimeoutId != null) {\n clearTimeout(invalidTimeoutId)\n invalidTimeoutId = undefined\n }\n\n if (prevHoverState && hoverState) {\n if (isHoverStateEqual(prevHoverState, hoverState)) {\n return\n }\n callHandler(reference, hoverState)\n return\n }\n\n if (!prevHoverState && !hoverState) {\n return\n }\n\n if (!prevHoverState && hoverState) {\n callHandler(reference, hoverState)\n return\n }\n\n if (prevHoverState && !hoverState) {\n if (invalidTimeoutId != null) {\n return\n }\n\n // Wait for a short period of time before invalidating the hover state.\n // This ensures smoother animation when the pointer moves between two\n // blocks with a small gap.\n invalidTimeoutId = setTimeout(() => {\n callHandler(reference, undefined)\n invalidTimeoutId = undefined\n }, invalidTimeoutMs)\n }\n })\n\n useEditorExtension(host, getEditor, extension)\n}\n","import {\n computed,\n createSignal,\n defineCustomElement,\n defineProps,\n registerCustomElement,\n useEffect,\n type HostElement,\n type HostElementConstructor,\n type PropsDeclaration,\n type State,\n} from '@aria-ui/core'\nimport { createOverlayStore } from '@aria-ui/elements/overlay'\nimport type { VirtualElement } from '@floating-ui/dom'\nimport type { Editor } from '@prosekit/core'\nimport type { ProseMirrorNode } from '@prosekit/pm/model'\n\nimport { useScrolling } from '../../hooks/use-scrolling.ts'\n\nimport { blockHandleOverlayStoreContext, BlockHandleStore, blockHandleStoreContext } from './context.ts'\nimport { useHoverExtension } from './use-hover-extension.ts'\n\nexport interface BlockHandleRootProps {\n /**\n * The ProseKit editor instance.\n *\n * @default null\n * @hidden\n */\n editor: Editor | null\n}\n\n/** @internal */\nexport const BlockHandleRootPropsDeclaration: PropsDeclaration<BlockHandleRootProps> = /* @__PURE__ */ defineProps<\n BlockHandleRootProps\n>({\n editor: { default: null, attribute: false, type: 'json' },\n})\n\n/**\n * @public\n */\nexport class BlockHandleStateChangeEvent extends Event {\n /**\n * The currently hovered block's node and position, or `null` if no block is hovered.\n */\n detail: { node: ProseMirrorNode; pos: number } | null\n constructor(state: { node: ProseMirrorNode; pos: number } | null) {\n super('stateChange', { bubbles: true })\n this.detail = state\n }\n}\n\n/**\n * @public\n */\nexport interface BlockHandleRootEvents {\n /**\n * Fired when the hovered block changes.\n */\n stateChange: BlockHandleStateChangeEvent\n}\n\n/**\n * @internal\n */\nexport function setupBlockHandleRoot(\n host: HostElement,\n props: State<BlockHandleRootProps>,\n): void {\n const getEditor = props.editor.get\n\n const store = new BlockHandleStore()\n blockHandleStoreContext.provide(host, store)\n\n const reference = createSignal<VirtualElement | undefined>(undefined)\n const getScrolling = useScrolling(host)\n\n const getOpen = computed(() => !!store.hoverState.get() && !getScrolling())\n\n const overlayStore = createOverlayStore(\n getOpen,\n () => {},\n () => true,\n () => false,\n (event) => host.dispatchEvent(event),\n )\n\n useHoverExtension(host, getEditor, (ref, hoverState) => {\n reference.set(ref ?? undefined)\n store.hoverState.set(hoverState)\n const state = hoverState ? { node: hoverState.node, pos: hoverState.pos } : null\n host.dispatchEvent(new BlockHandleStateChangeEvent(state))\n })\n\n useEffect(host, () => {\n overlayStore.setAnchorElement(reference.get())\n })\n\n blockHandleOverlayStoreContext.provide(host, overlayStore)\n}\n\nconst BlockHandleRootElementBase: HostElementConstructor<BlockHandleRootProps> = defineCustomElement(\n setupBlockHandleRoot,\n BlockHandleRootPropsDeclaration,\n)\n\n/**\n * `<prosekit-block-handle-root>` custom element.\n *\n * Properties: {@link BlockHandleRootProps}\n *\n * Events: {@link BlockHandleRootEvents}\n */\nexport class BlockHandleRootElement extends BlockHandleRootElementBase {}\n\n/** @internal */\nexport function registerBlockHandleRootElement(): void {\n registerCustomElement('prosekit-block-handle-root', BlockHandleRootElement)\n}\n"],"mappings":";;;;;;;;;;;;;AAQA,IAAa,mBAAb,MAA8B;;oBAC0B,aAAqC,KAAA,EAAU;kBAChE,aAAa,MAAM;;;;;;AAM1D,MAAa,0BAAqD,cAAgC,8BAA8B;;;;AAKhI,MAAa,iCAAwD,cAA4B,sCAAsC;;ACIvI,MAAa,iCAAwF,4BAAiC,EACpI,QAAQ;CAAE,SAAS;CAAM,WAAW;CAAO,MAAM;CAAQ,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KrD,YAAY,OAAsD;AAChE,QAAM,eAAe,EAAE,SAAS,MAAM,CAAC;AACvC,OAAK,SAAS;;;;;;AAiBlB,SAAgB,qBACd,MACA,OACM;CACN,MAAM,YAAY,MAAM,OAAO;CAE/B,MAAM,QAAQ,IAAI,kBAAkB;AACpC,yBAAwB,QAAQ,MAAM,MAAM;CAE5C,MAAM,YAAY,aAAyC,KAAA,EAAU;CACrE,MAAM,eAAe,aAAa,KAAK;CAIvC,MAAM,eAAe,mBAFL,eAAe,CAAC,CAAC,MAAM,WAAW,KAAK,IAAI,CAAC,cAAc,CAAC,QAInE,UACA,YACA,QACL,UAAU,KAAK,cAAc,MAAM,CACrC;AAED,mBAAkB,MAAM,YAAY,KAAK,eAAe;AACtD,YAAU,IAAI,OAAO,KAAA,EAAU;AAC/B,QAAM,WAAW,IAAI,WAAW;EAChC,MAAM,QAAQ,aAAa;GAAE,MAAM,WAAW;GAAM,KAAK,WAAW;GAAK,GAAG;AAC5E,OAAK,cAAc,IAAI,4BAA4B,MAAM,CAAC;GAC1D;AAEF,WAAU,YAAY;AACpB,eAAa,iBAAiB,UAAU,KAAK,CAAC;GAC9C;AAEF,gCAA+B,QAAQ,MAAM,aAAa;;AAG5D,MAAM,6BAA2E,oBAC/E,sBACA,gCACD;;;;;;;;AASD,IAAa,yBAAb,cAA4C,2BAA2B;;AAGvE,SAAgB,iCAAuC;AACrD,uBAAsB,8BAA8B,uBAAuB"}
|
|
1
|
+
{"version":3,"file":"block-handle.js","names":[],"sources":["../src/components/block-handle/context.ts","../src/components/block-handle/block-handle-add.ts","../src/constants.ts","../src/utils/get-client-rect.ts","../src/utils/max-z-index.ts","../src/components/block-handle/set-drag-preview.ts","../src/components/block-handle/block-handle-draggable.ts","../src/components/block-handle/block-handle-popup.ts","../src/components/block-handle/block-handle-positioner.ts","../src/components/block-handle/use-has-text-selection.ts","../src/utils/prefers-reduced-motion.ts","../src/components/block-handle/hover-state.ts","../src/components/block-handle/pointer-move.ts","../src/components/block-handle/use-hover-extension.ts","../src/components/block-handle/block-handle-root.ts"],"sourcesContent":["import { createContext, createSignal, type Context, type Signal } from '@aria-ui/core'\nimport type { OverlayStore } from '@aria-ui/elements/overlay'\n\nimport type { HoverState } from './hover-state.ts'\n\n/**\n * @internal\n */\nexport class BlockHandleStore {\n readonly hoverState: Signal<HoverState | undefined> = createSignal<HoverState | undefined>(undefined)\n readonly dragging: Signal<boolean> = createSignal(false)\n}\n\n/**\n * @internal\n */\nexport const blockHandleStoreContext: Context<BlockHandleStore> = createContext<BlockHandleStore>('prosekit-block-handle-store')\n\n/**\n * @internal\n */\nexport const blockHandleOverlayStoreContext: Context<OverlayStore> = createContext<OverlayStore>('prosekit-block-handle-overlay-store')\n","import {\n defineCustomElement,\n defineProps,\n registerCustomElement,\n type HostElement,\n type HostElementConstructor,\n type PropsDeclaration,\n type State,\n} from '@aria-ui/core'\nimport { useEventListener } from '@aria-ui/utils'\nimport { insertDefaultBlock, type Editor } from '@prosekit/core'\n\nimport { blockHandleStoreContext } from './context.ts'\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 BlockHandleAddPropsDeclaration: PropsDeclaration<BlockHandleAddProps> = /* @__PURE__ */ defineProps<BlockHandleAddProps>({\n editor: { default: null, attribute: false },\n})\n\n/**\n * @internal\n */\nexport function setupBlockHandleAdd(\n host: HostElement,\n props: State<BlockHandleAddProps>,\n): void {\n const getStore = blockHandleStoreContext.consume(host)\n\n useEventListener(host, 'pointerdown', (event) => {\n event.preventDefault()\n\n const store = getStore()\n const editor = props.editor.get()\n const hoverState = store?.hoverState.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 store?.hoverState.set(undefined)\n })\n}\n\nconst BlockHandleAddElementBase: HostElementConstructor<BlockHandleAddProps> = defineCustomElement(\n setupBlockHandleAdd,\n BlockHandleAddPropsDeclaration,\n)\n\n/**\n * `<prosekit-block-handle-add>` custom element.\n *\n * Properties: {@link BlockHandleAddProps}\n */\nexport class BlockHandleAddElement extends BlockHandleAddElementBase {}\n\n/** @internal */\nexport function registerBlockHandleAddElement(): void {\n registerCustomElement('prosekit-block-handle-add', BlockHandleAddElement)\n}\n","export const DRAGGING_CLASS_NAME = 'prosekit-dragging'\n","interface Rect {\n top: number\n bottom: number\n right: number\n left: number\n}\n\ninterface IncludeExtraOptions {\n top?: boolean\n bottom?: boolean\n right?: boolean\n left?: boolean\n}\n\n/**\n * Similar to `element.getBoundingClientRect`, but handles `display: contents` CSS\n * property and optionally includes margins and outlines.\n */\nexport function getClientRect(element: Element, includeExtra?: IncludeExtraOptions | false): Rect {\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 = [...element.children]\n const rects = children.map(child => getClientRect(child, includeExtra))\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 includeExtra ? addExtra(element, rect, includeExtra) : rect\n}\n\nfunction addExtra(element: Element, rect: Rect, options: IncludeExtraOptions): Rect {\n const view = element.ownerDocument?.defaultView\n if (!view) {\n return rect\n }\n\n const style = view.getComputedStyle(element)\n const marginTop = options.top ? Number.parseFloat(style.marginTop) || 0 : 0\n const marginBottom = options.bottom ? Number.parseFloat(style.marginBottom) || 0 : 0\n const marginRight = options.right ? Number.parseFloat(style.marginRight) || 0 : 0\n const marginLeft = options.left ? Number.parseFloat(style.marginLeft) || 0 : 0\n\n const outlineWidth = Number.parseFloat(style.outlineWidth) || 0\n const outlineOffset = Number.parseFloat(style.outlineOffset) || 0\n const outline = Math.max(outlineWidth + outlineOffset, 0)\n const outlineTop = options.top ? outline : 0\n const outlineBottom = options.bottom ? outline : 0\n const outlineRight = options.right ? outline : 0\n const outlineLeft = options.left ? outline : 0\n\n return {\n top: rect.top - Math.max(marginTop, outlineTop),\n bottom: rect.bottom + Math.max(marginBottom, outlineBottom),\n right: rect.right + Math.max(marginRight, outlineRight),\n left: rect.left - Math.max(marginLeft, outlineLeft),\n }\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 { DRAGGING_CLASS_NAME } from '../../constants.ts'\nimport { assignStyles } from '../../utils/assign-styles.ts'\nimport { getClientRect } from '../../utils/get-client-rect.ts'\nimport { maxZIndex } from '../../utils/max-z-index.ts'\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, { left: true, right: true, top: true, bottom: true })\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 // Add some class names so that all styles applied to\n // given class names can also be applied to the drag preview.\n container.classList.add('ProseMirror', DRAGGING_CLASS_NAME)\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 = element.cloneNode(true) as HTMLElement\n\n // A hardcoded opacity.\n clonedElement.style.setProperty('opacity', '0.8', 'important')\n // Hide the outline of the cloned element.\n clonedElement.style.setProperty('outline-color', 'transparent', 'important')\n\n container.appendChild(clonedElement)\n document.body.appendChild(container)\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 defineCustomElement,\n defineProps,\n onMount,\n registerCustomElement,\n type HostElement,\n type HostElementConstructor,\n type PropsDeclaration,\n type State,\n} from '@aria-ui/core'\nimport { useAttribute, useEventListener } from '@aria-ui/utils'\nimport { isHTMLElement } from '@ocavue/utils'\nimport type { Editor } from '@prosekit/core'\nimport type { ViewDragging } from '@prosekit/extensions/drop-indicator'\nimport { Fragment, Slice } from '@prosekit/pm/model'\nimport { NodeSelection } from '@prosekit/pm/state'\nimport type { EditorView } from '@prosekit/pm/view'\n\nimport { DRAGGING_CLASS_NAME } from '../../constants.ts'\nimport { getSafeEditorView } from '../../utils/get-safe-editor-view.ts'\n\nimport { blockHandleStoreContext } from './context.ts'\nimport type { HoverState } from './hover-state.ts'\nimport { setDragPreview } from './set-drag-preview.ts'\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 BlockHandleDraggablePropsDeclaration: PropsDeclaration<BlockHandleDraggableProps> = /* @__PURE__ */ defineProps<\n BlockHandleDraggableProps\n>({\n editor: { default: null, attribute: false },\n})\n\n/**\n * @internal\n */\nexport function setupBlockHandleDraggable(\n host: HostElement,\n props: State<BlockHandleDraggableProps>,\n): void {\n const getStore = blockHandleStoreContext.consume(host)\n\n onMount(host, () => {\n host.draggable = true\n })\n\n usePointerDownHandler(host, () => getStore()?.hoverState.get() ?? null, props.editor.get)\n\n useEventListener(host, 'dragstart', (event) => {\n const store = getStore()\n store?.dragging.set(true)\n\n const view = getSafeEditorView(props.editor.get())\n const hoverState = store?.hoverState.get()\n\n if (view && hoverState) {\n view.dom.classList.add(DRAGGING_CLASS_NAME)\n createDraggingPreview(view, hoverState, event)\n setViewDragging(view, hoverState)\n }\n })\n\n useEventListener(host, 'dragend', () => {\n const store = getStore()\n store?.dragging.set(false)\n\n const view = getSafeEditorView(props.editor.get())\n if (view) {\n view.dom.classList.remove(DRAGGING_CLASS_NAME)\n }\n })\n\n useAttribute(host, 'data-dragging', () => (getStore()?.dragging.get() ? '' : undefined))\n}\n\nfunction usePointerDownHandler(\n host: HostElement,\n getHoverState: () => HoverState | null,\n getEditor: () => Editor | null,\n) {\n useEventListener(host, 'pointerdown', () => {\n const hoverState = getHoverState()\n const editor = getEditor()\n\n if (hoverState?.pos == null || !editor?.view) {\n return\n }\n\n const { view } = editor\n view.dispatch(\n view.state.tr.setSelection(NodeSelection.create(view.state.doc, hoverState.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 event.dataTransfer.clearData()\n event.dataTransfer.setData('text/html', element.outerHTML)\n event.dataTransfer.effectAllowed = 'copyMove'\n setDragPreview(event, element)\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\nconst BlockHandleDraggableElementBase: HostElementConstructor<BlockHandleDraggableProps> = defineCustomElement(\n setupBlockHandleDraggable,\n BlockHandleDraggablePropsDeclaration,\n)\n\n/**\n * `<prosekit-block-handle-draggable>` custom element.\n *\n * Properties: {@link BlockHandleDraggableProps}\n *\n * Data attributes:\n *\n * | Attribute | Description |\n * | --- | --- |\n * | `data-dragging` | Present when the element is being dragged |\n */\nexport class BlockHandleDraggableElement extends BlockHandleDraggableElementBase {}\n\n/** @internal */\nexport function registerBlockHandleDraggableElement(): void {\n registerCustomElement('prosekit-block-handle-draggable', BlockHandleDraggableElement)\n}\n","import {\n defineCustomElement,\n registerCustomElement,\n type HostElement,\n type HostElementConstructor,\n type PropsDeclaration,\n type State,\n} from '@aria-ui/core'\nimport { OverlayPopupPropsDeclaration, setupOverlayPopup, type OverlayPopupProps } from '@aria-ui/elements/overlay'\n\nimport { blockHandleOverlayStoreContext } from './context.ts'\n\n/**\n * @public\n */\nexport interface BlockHandlePopupProps extends OverlayPopupProps {}\n\n/** @internal */\nexport const BlockHandlePopupPropsDeclaration: PropsDeclaration<BlockHandlePopupProps> = OverlayPopupPropsDeclaration\n\n/** @internal */\nexport function setupBlockHandlePopup(\n host: HostElement,\n _props: State<BlockHandlePopupProps>,\n): void {\n const getOverlayStore = blockHandleOverlayStoreContext.consume(host)\n setupOverlayPopup(host, getOverlayStore)\n}\n\nconst BlockHandlePopupElementBase: HostElementConstructor<BlockHandlePopupProps> = defineCustomElement(\n setupBlockHandlePopup,\n BlockHandlePopupPropsDeclaration,\n)\n\n/**\n * `<prosekit-block-handle-popup>` custom element.\n *\n * Properties: {@link BlockHandlePopupProps}\n *\n * Data attributes:\n *\n * | Attribute | Description |\n * | --- | --- |\n * | `data-state` | `\"open\"` when the block handle is visible, `\"closed\"` otherwise |\n */\nexport class BlockHandlePopupElement extends BlockHandlePopupElementBase {}\n\n/** @internal */\nexport function registerBlockHandlePopupElement(): void {\n registerCustomElement('prosekit-block-handle-popup', BlockHandlePopupElement)\n}\n","import {\n defineCustomElement,\n defineProps,\n registerCustomElement,\n type HostElement,\n type HostElementConstructor,\n type PropsDeclaration,\n type State,\n} from '@aria-ui/core'\nimport { OverlayPositionerPropsDeclaration, setupOverlayPositioner, type OverlayPositionerProps } from '@aria-ui/elements/overlay'\nimport type { Placement } from '@floating-ui/dom'\n\nimport { blockHandleOverlayStoreContext } from './context.ts'\n\n/**\n * @public\n */\nexport interface BlockHandlePositionerProps extends Omit<OverlayPositionerProps, 'placement' | 'hoist' | 'flip' | 'shift' | 'hide'> {\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 BlockHandlePositionerPropsDeclaration: PropsDeclaration<BlockHandlePositionerProps> = /* @__PURE__ */ defineProps<\n BlockHandlePositionerProps\n>({\n ...OverlayPositionerPropsDeclaration,\n placement: { default: 'left', attribute: 'placement', type: 'string' },\n // Enabling `hoist` will cause the popover to have a small delay when\n // scrolling the page.\n hoist: { default: false, attribute: 'hoist', type: 'boolean' },\n flip: { default: false, attribute: false },\n shift: { default: false, attribute: 'shift', type: 'boolean' },\n hide: { default: true, attribute: 'hide', type: 'boolean' },\n})\n\n/** @internal */\nexport function setupBlockHandlePositioner(\n host: HostElement,\n props: State<BlockHandlePositionerProps>,\n): void {\n const getOverlayStore = blockHandleOverlayStoreContext.consume(host)\n setupOverlayPositioner(host, props as unknown as State<OverlayPositionerProps>, getOverlayStore)\n}\n\nconst BlockHandlePositionerElementBase: HostElementConstructor<BlockHandlePositionerProps> = defineCustomElement(\n setupBlockHandlePositioner,\n BlockHandlePositionerPropsDeclaration,\n)\n\n/**\n * `<prosekit-block-handle-positioner>` custom element.\n *\n * Properties: {@link BlockHandlePositionerProps}\n *\n * Data attributes:\n *\n * | Attribute | Description |\n * | --- | --- |\n * | `data-state` | `\"open\"` when the block handle is visible, `\"closed\"` otherwise |\n * | `data-side` | The side of the anchor element the positioner is on |\n * | `data-align` | The alignment of the positioner relative to the anchor element |\n *\n * CSS variables:\n *\n * | Variable | Description |\n * | --- | --- |\n * | `--transform-origin` | The coordinates that this element is anchored to. Useful for scale animations. |\n */\nexport class BlockHandlePositionerElement extends BlockHandlePositionerElementBase {}\n\n/** @internal */\nexport function registerBlockHandlePositionerElement(): void {\n registerCustomElement('prosekit-block-handle-positioner', BlockHandlePositionerElement)\n}\n","import { createSignal, type HostElement } from '@aria-ui/core'\nimport { isTextSelection, type Editor } from '@prosekit/core'\n\nimport { useEditorUpdateEvent } from '../../hooks/use-editor-update-event.ts'\n\nexport function useHasTextSelection(host: HostElement, getEditor: () => Editor | null): () => boolean {\n const state = createSignal(false)\n useEditorUpdateEvent(host, getEditor, (view) => {\n const { selection } = view.state\n state.set(!selection.empty && isTextSelection(selection))\n })\n return state.get\n}\n","export function prefersReducedMotion(): boolean {\n if (typeof window === 'undefined') {\n return false\n }\n return window.matchMedia('(prefers-reduced-motion: reduce)').matches\n}\n","import 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 function isHoverStateEqual(a: HoverState, b: HoverState): boolean {\n return a.pos === b.pos && a.node.eq(b.node)\n}\n","import type { VirtualElement } from '@floating-ui/dom'\nimport { isElement, isHTMLElement, isTextNode, throttle } from '@ocavue/utils'\nimport { defineDOMEventHandler, union, type PlainExtension } 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.ts'\n\nimport type { HoverState } from './hover-state.ts'\n\nexport type ElementHoverHandler = (\n reference?: VirtualElement,\n hoverState?: HoverState,\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()\n return\n }\n\n const { node, pos } = block\n const element = view.nodeDOM(pos)\n if (!element || !isHTMLElement(element)) {\n handler()\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()),\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 return getClientRect(node, { left: true, right: true })\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 type { HostElement } from '@aria-ui/core'\nimport type { Editor } from '@prosekit/core'\n\nimport { useEditorExtension } from '../../hooks/use-editor-extension.ts'\nimport { prefersReducedMotion } from '../../utils/prefers-reduced-motion.ts'\n\nimport { isHoverStateEqual, type HoverState } from './hover-state.ts'\nimport { defineElementHoverHandler, type ElementHoverHandler } from './pointer-move.ts'\n\nexport function useHoverExtension(\n host: HostElement,\n getEditor: () => Editor | null,\n handler: ElementHoverHandler,\n): void {\n const invalidTimeoutMs = prefersReducedMotion() ? 0 : 180\n\n let invalidTimeoutId: ReturnType<typeof setTimeout> | undefined\n\n let prevHoverState: HoverState | undefined\n\n const callHandler: ElementHoverHandler = (reference, hoverState) => {\n prevHoverState = hoverState\n handler(reference, hoverState)\n }\n\n const extension = defineElementHoverHandler((reference, hoverState) => {\n if (hoverState && invalidTimeoutId != null) {\n clearTimeout(invalidTimeoutId)\n invalidTimeoutId = undefined\n }\n\n if (prevHoverState && hoverState) {\n if (isHoverStateEqual(prevHoverState, hoverState)) {\n return\n }\n callHandler(reference, hoverState)\n return\n }\n\n if (!prevHoverState && !hoverState) {\n return\n }\n\n if (!prevHoverState && hoverState) {\n callHandler(reference, hoverState)\n return\n }\n\n if (prevHoverState && !hoverState) {\n if (invalidTimeoutId != null) {\n return\n }\n\n // Wait for a short period of time before invalidating the hover state.\n // This ensures smoother animation when the pointer moves between two\n // blocks with a small gap.\n invalidTimeoutId = setTimeout(() => {\n callHandler(reference, undefined)\n invalidTimeoutId = undefined\n }, invalidTimeoutMs)\n }\n })\n\n useEditorExtension(host, getEditor, extension)\n}\n","import {\n computed,\n createSignal,\n defineCustomElement,\n defineProps,\n registerCustomElement,\n useEffect,\n type HostElement,\n type HostElementConstructor,\n type PropsDeclaration,\n type State,\n} from '@aria-ui/core'\nimport { createOverlayStore } from '@aria-ui/elements/overlay'\nimport type { VirtualElement } from '@floating-ui/dom'\nimport type { Editor } from '@prosekit/core'\nimport type { ProseMirrorNode } from '@prosekit/pm/model'\n\nimport { useScrolling } from '../../hooks/use-scrolling.ts'\n\nimport { blockHandleOverlayStoreContext, BlockHandleStore, blockHandleStoreContext } from './context.ts'\nimport { useHasTextSelection } from './use-has-text-selection.ts'\nimport { useHoverExtension } from './use-hover-extension.ts'\n\nexport interface BlockHandleRootProps {\n /**\n * The ProseKit editor instance.\n *\n * @default null\n * @hidden\n */\n editor: Editor | null\n}\n\n/** @internal */\nexport const BlockHandleRootPropsDeclaration: PropsDeclaration<BlockHandleRootProps> = /* @__PURE__ */ defineProps<\n BlockHandleRootProps\n>({\n editor: { default: null, attribute: false },\n})\n\n/**\n * @public\n */\nexport class BlockHandleStateChangeEvent extends Event {\n /**\n * The currently hovered block's node and position, or `null` if no block is hovered.\n */\n detail: { node: ProseMirrorNode; pos: number } | null\n constructor(state: { node: ProseMirrorNode; pos: number } | null) {\n super('stateChange', { bubbles: true })\n this.detail = state\n }\n}\n\n/**\n * @public\n */\nexport interface BlockHandleRootEvents {\n /**\n * Fired when the hovered block changes.\n */\n stateChange: BlockHandleStateChangeEvent\n}\n\n/**\n * @internal\n */\nexport function setupBlockHandleRoot(\n host: HostElement,\n props: State<BlockHandleRootProps>,\n): void {\n const getEditor = props.editor.get\n\n const store = new BlockHandleStore()\n blockHandleStoreContext.provide(host, store)\n\n const reference = createSignal<VirtualElement | undefined>(undefined)\n const getScrolling = useScrolling(host)\n // Hide the block handle when there is a text selection to avoid the block handle overlapping with inline menu\n const getHasTextSelection = useHasTextSelection(host, getEditor)\n\n const getOpen = computed(() => !!store.hoverState.get() && !getScrolling() && !getHasTextSelection())\n\n const overlayStore = createOverlayStore(\n getOpen,\n () => {},\n () => true,\n () => false,\n (event) => host.dispatchEvent(event),\n )\n\n useHoverExtension(host, getEditor, (ref, hoverState) => {\n reference.set(ref ?? undefined)\n store.hoverState.set(hoverState)\n const state = hoverState ? { node: hoverState.node, pos: hoverState.pos } : null\n host.dispatchEvent(new BlockHandleStateChangeEvent(state))\n })\n\n useEffect(host, () => {\n overlayStore.setAnchorElement(reference.get())\n })\n\n blockHandleOverlayStoreContext.provide(host, overlayStore)\n}\n\nconst BlockHandleRootElementBase: HostElementConstructor<BlockHandleRootProps> = defineCustomElement(\n setupBlockHandleRoot,\n BlockHandleRootPropsDeclaration,\n)\n\n/**\n * `<prosekit-block-handle-root>` custom element.\n *\n * Properties: {@link BlockHandleRootProps}\n *\n * Events: {@link BlockHandleRootEvents}\n */\nexport class BlockHandleRootElement extends BlockHandleRootElementBase {}\n\n/** @internal */\nexport function registerBlockHandleRootElement(): void {\n registerCustomElement('prosekit-block-handle-root', BlockHandleRootElement)\n}\n"],"mappings":";;;;;;;;;;;;;;AAQA,IAAa,mBAAb,MAA8B;;oBAC0B,aAAqC,KAAA,EAAU;kBAChE,aAAa,MAAM;;;;;;AAM1D,MAAa,0BAAqD,cAAgC,8BAA8B;;;;AAKhI,MAAa,iCAAwD,cAA4B,sCAAsC;;ACIvI,MAAa,iCAAwF,4BAAiC,EACpI,QAAQ;CAAE,SAAS;CAAM,WAAW;CAAO,EAC5C,CAAC;;;;AAKF,SAAgB,oBACd,MACA,OACM;CACN,MAAM,WAAW,wBAAwB,QAAQ,KAAK;CAEtD,iBAAiB,MAAM,gBAAgB,UAAU;EAC/C,MAAM,gBAAgB;EAEtB,MAAM,QAAQ,UAAU;EACxB,MAAM,SAAS,MAAM,OAAO,KAAK;EACjC,MAAM,aAAa,OAAO,WAAW,KAAK;EAC1C,IAAI,CAAC,UAAU,CAAC,YACd;EAGF,MAAM,EAAE,MAAM,QAAQ;EACtB,OAAO,KAAK,mBAAmB,EAAE,KAAK,MAAM,KAAK,UAAU,CAAC,CAAC;EAC7D,OAAO,OAAO;EAGd,OAAO,WAAW,IAAI,KAAA,EAAU;GAChC;;AAGJ,MAAM,4BAAyE,oBAC7E,qBACA,+BACD;;;;;;AAOD,IA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