@prosekit/web 0.8.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/autocomplete.d.ts +10 -15
- package/dist/autocomplete.d.ts.map +1 -1
- package/dist/autocomplete.js +16 -9
- package/dist/autocomplete.js.map +1 -1
- package/dist/block-handle.d.ts +0 -12
- package/dist/block-handle.d.ts.map +1 -1
- package/dist/block-handle.js +0 -3
- package/dist/block-handle.js.map +1 -1
- package/dist/drop-indicator.d.ts.map +1 -1
- package/dist/drop-indicator.js.map +1 -1
- package/dist/get-safe-editor-view.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/inline-popover.d.ts +0 -12
- package/dist/inline-popover.d.ts.map +1 -1
- package/dist/inline-popover.js.map +1 -1
- package/dist/menu.d.ts.map +1 -1
- package/dist/menu.js.map +1 -1
- package/dist/popover.d.ts.map +1 -1
- package/dist/popover.js.map +1 -1
- package/dist/resizable.d.ts +0 -15
- package/dist/resizable.d.ts.map +1 -1
- package/dist/resizable.js +0 -6
- package/dist/resizable.js.map +1 -1
- package/dist/table-handle.d.ts.map +1 -1
- package/dist/table-handle.js.map +1 -1
- package/dist/tooltip.d.ts.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.map +1 -1
- package/dist/use-scrolling.js.map +1 -1
- package/package.json +11 -11
- package/src/components/autocomplete/autocomplete-popup.ts +0 -6
- package/src/components/autocomplete/autocomplete-positioner.ts +1 -4
- package/src/components/autocomplete/autocomplete-root.ts +33 -16
- package/src/components/block-handle/block-handle-popup.ts +0 -3
- package/src/components/block-handle/block-handle-positioner.ts +0 -3
- package/src/components/block-handle/block-handle-root.ts +0 -6
- package/src/components/inline-popover/inline-popover-popup.ts +0 -3
- package/src/components/inline-popover/inline-popover-positioner.ts +0 -3
- package/src/components/inline-popover/inline-popover-root.ts +0 -6
- package/src/components/resizable/resizable-handle.ts +0 -3
- package/src/components/resizable/resizable-root.ts +0 -12
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>;
|
|
@@ -52,13 +53,7 @@ declare const AutocompleteItemElementBase: HostElementConstructor<AutocompleteIt
|
|
|
52
53
|
declare class AutocompleteItemElement extends AutocompleteItemElementBase {}
|
|
53
54
|
/** @internal */
|
|
54
55
|
declare function registerAutocompleteItemElement(): void;
|
|
55
|
-
/**
|
|
56
|
-
* @public
|
|
57
|
-
*/
|
|
58
56
|
interface AutocompletePopupProps extends OverlayPopupProps {}
|
|
59
|
-
/**
|
|
60
|
-
* @public
|
|
61
|
-
*/
|
|
62
57
|
interface AutocompletePopupEvents extends ListboxRootEvents {}
|
|
63
58
|
/** @internal */
|
|
64
59
|
declare const AutocompletePopupPropsDeclaration: PropsDeclaration<AutocompletePopupProps>;
|
|
@@ -81,9 +76,6 @@ declare const AutocompletePopupElementBase: HostElementConstructor<AutocompleteP
|
|
|
81
76
|
declare class AutocompletePopupElement extends AutocompletePopupElementBase {}
|
|
82
77
|
/** @internal */
|
|
83
78
|
declare function registerAutocompletePopupElement(): void;
|
|
84
|
-
/**
|
|
85
|
-
* @public
|
|
86
|
-
*/
|
|
87
79
|
interface AutocompletePositionerProps extends OverlayPositionerProps {
|
|
88
80
|
/**
|
|
89
81
|
* The placement of the popover, relative to the text cursor.
|
|
@@ -173,12 +165,18 @@ interface AutocompleteRootProps {
|
|
|
173
165
|
* @default defaultItemFilter
|
|
174
166
|
*/
|
|
175
167
|
filter: ItemFilter | null;
|
|
168
|
+
/**
|
|
169
|
+
* The reference to position the popup against. This can be a DOM element, a
|
|
170
|
+
* Floating UI virtual element, or a function that returns either of them.
|
|
171
|
+
* By default, the popup will be positioned against the text content that
|
|
172
|
+
* triggers the autocomplete.
|
|
173
|
+
*
|
|
174
|
+
* @default null
|
|
175
|
+
*/
|
|
176
|
+
anchor: Element | VirtualElement | (() => Element | VirtualElement | null) | null;
|
|
176
177
|
}
|
|
177
178
|
/** @internal */
|
|
178
179
|
declare const AutocompleteRootPropsDeclaration: PropsDeclaration<AutocompleteRootProps>;
|
|
179
|
-
/**
|
|
180
|
-
* @public
|
|
181
|
-
*/
|
|
182
180
|
declare class QueryChangeEvent extends Event {
|
|
183
181
|
/**
|
|
184
182
|
* The current query string.
|
|
@@ -186,9 +184,6 @@ declare class QueryChangeEvent extends Event {
|
|
|
186
184
|
readonly detail: string;
|
|
187
185
|
constructor(query: string);
|
|
188
186
|
}
|
|
189
|
-
/**
|
|
190
|
-
* @public
|
|
191
|
-
*/
|
|
192
187
|
interface AutocompleteRootEvents extends ListboxRootEvents {
|
|
193
188
|
/**
|
|
194
189
|
* Fired when the open state changes.
|
|
@@ -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/autocompl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,CAAA"}
|
package/dist/autocomplete.js
CHANGED
|
@@ -255,11 +255,12 @@ const AutocompleteRootPropsDeclaration = /* @__PURE__ */ defineProps({
|
|
|
255
255
|
filter: {
|
|
256
256
|
default: defaultItemFilter,
|
|
257
257
|
attribute: false
|
|
258
|
+
},
|
|
259
|
+
anchor: {
|
|
260
|
+
default: null,
|
|
261
|
+
attribute: false
|
|
258
262
|
}
|
|
259
263
|
});
|
|
260
|
-
/**
|
|
261
|
-
* @public
|
|
262
|
-
*/
|
|
263
264
|
var QueryChangeEvent = class extends Event {
|
|
264
265
|
constructor(query) {
|
|
265
266
|
super("queryChange", { bubbles: true });
|
|
@@ -302,7 +303,13 @@ function setupAutocompleteRoot(host, props) {
|
|
|
302
303
|
query.set(next);
|
|
303
304
|
host.dispatchEvent(new QueryChangeEvent(next));
|
|
304
305
|
};
|
|
305
|
-
|
|
306
|
+
const getAnchor = () => {
|
|
307
|
+
const customAnchor = props.anchor.get();
|
|
308
|
+
if (customAnchor) if (typeof customAnchor === "function") return customAnchor() || null;
|
|
309
|
+
else return customAnchor;
|
|
310
|
+
return getSafeEditorView(getEditor())?.dom.querySelector(".prosekit-autocomplete-match") || null;
|
|
311
|
+
};
|
|
312
|
+
useAutocompleteExtension(host, getEditor, props.regex.get, getAnchor, {
|
|
306
313
|
reference,
|
|
307
314
|
handlers,
|
|
308
315
|
setQuery,
|
|
@@ -325,20 +332,20 @@ function useKeyboardBridge(host, getEditor, getOpen, target) {
|
|
|
325
332
|
return event.defaultPrevented;
|
|
326
333
|
}), 4));
|
|
327
334
|
}
|
|
328
|
-
function useAutocompleteExtension(host, getEditor, getRegex, deps) {
|
|
335
|
+
function useAutocompleteExtension(host, getEditor, getRegex, getAnchor, deps) {
|
|
329
336
|
useEffect(host, () => {
|
|
330
337
|
const editor = getEditor();
|
|
331
338
|
const regex = getRegex();
|
|
332
339
|
if (!editor || !regex) return;
|
|
333
|
-
const extension = defineAutocomplete(createAutocompleteRule(editor, regex, deps));
|
|
340
|
+
const extension = defineAutocomplete(createAutocompleteRule(editor, regex, getAnchor, deps));
|
|
334
341
|
return editor.use(extension);
|
|
335
342
|
});
|
|
336
343
|
}
|
|
337
|
-
function createAutocompleteRule(editor, regex, deps) {
|
|
344
|
+
function createAutocompleteRule(editor, regex, getAnchor, deps) {
|
|
338
345
|
const { reference, handlers, setQuery, requestOpenChange } = deps;
|
|
339
346
|
const handleEnter = (options) => {
|
|
340
|
-
const
|
|
341
|
-
|
|
347
|
+
const anchor = getAnchor();
|
|
348
|
+
reference.set(anchor || void 0);
|
|
342
349
|
handlers.submit = options.deleteMatch;
|
|
343
350
|
handlers.dismiss = options.ignoreMatch;
|
|
344
351
|
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 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 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 },\n regex: { default: null, attribute: false },\n filter: { default: defaultItemFilter, 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<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;;EAEj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B,QAAQ,SACyB,CAAC,EAAE,EACR,CAAC;;AAGhD,MAAM,8BAA6E,oBACjF,uBACA,iCACD;;;;;;;;AASD,IAAa,0BAAb,cAA6C,4BAA4B;;AAGzE,SAAgB,kCAAwC;AACtD,uBAAsB,8BAA8B,wBAAwB"}
|
|
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\nexport interface AutocompletePopupProps extends OverlayPopupProps {}\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\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\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\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,CAAC,CAAC;;;;AAKJ,SAAgB,uBACd,MACA,OACM;CACN,kBAAkB,MAAM,KAAK;AAC/B;AAEA,MAAM,+BAA+E,oBACnF,wBACA,iCACF;;;;;;AAOA,IAAa,2BAAb,cAA8C,6BAA6B,CAAC;;AAG5E,SAAgB,mCAAyC;CACvD,sBAAsB,+BAA+B,wBAAwB;AAC/E;AC3CA,SAAgB,eAAe,OAAoB;CACjD,MAAM,eAAe;AACvB;;AC0BA,MAAa,mCAA4F,4BACvG;CACE,OAAO;EAAE,SAAS;EAAI,WAAW;EAAS,MAAM;CAAS;CACzD,UAAU;EAAE,SAAS;EAAO,WAAW;EAAY,MAAM;CAAU;AACrE,CACF;;;;AAOA,SAAgB,sBACd,MACA,OACM;CACN,iBAAiB,MAAM,KAAK;CAG5B,iBAAiB,MAAM,eAAe,cAAc;CACpD,iBAAiB,MAAM,aAAa,cAAc;AACpD;AAEA,MAAM,8BAA6E,oBACjF,uBACA,gCACF;;;;;;;;;;;;;;AAeA,IAAa,0BAAb,cAA6C,4BAA4B,CAAC;;AAG1E,SAAgB,kCAAwC;CACtD,sBAAsB,8BAA8B,uBAAuB;AAC7E;ACxEA,SAAgB,iBACd,WACA,UACW;CACX,OAAO;EACL,WAAc;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KAAA,CAAS;EAEjC,SAAS,SAAS,QAAQ;EAC1B,SAAS,UAAU,QAAQ;EAC3B,SAAS,oBAAoB,QAAQ,KAAK,CAAC;EAC3C,kBAAkB,IAAI;CACxB;CAEA,MAAM,oBAAoB;EACxB,UAAU,IAAI,KAAA,CAAS;EACvB,SAAS,EAAE;EACX,SAAS,SAAS,KAAA;EAClB,SAAS,UAAU,KAAA;EACnB,kBAAkB,KAAK;CACzB;CAEA,OAAO,IAAI,iBAAiB;EAC1B;EACA,SAAS;EACT,SAAS;CACX,CAAC;AACH;AAEA,SAAS,iBACP,MACA,WACA,SACM;CAGN,mBAAmB,MAAM,WADP,aAAa,aAAa,EAD3B,QAAQ,QACwB,CAAC,GAAG,CACT,CAAC;AAC/C;AAEA,MAAM,8BAA6E,oBACjF,uBACA,gCACF;;;;;;;;AASA,IAAa,0BAAb,cAA6C,4BAA4B,CAAC;;AAG1E,SAAgB,kCAAwC;CACtD,sBAAsB,8BAA8B,uBAAuB;AAC7E"}
|
package/dist/block-handle.d.ts
CHANGED
|
@@ -57,9 +57,6 @@ declare const BlockHandleDraggableElementBase: HostElementConstructor<BlockHandl
|
|
|
57
57
|
declare class BlockHandleDraggableElement extends BlockHandleDraggableElementBase {}
|
|
58
58
|
/** @internal */
|
|
59
59
|
declare function registerBlockHandleDraggableElement(): void;
|
|
60
|
-
/**
|
|
61
|
-
* @public
|
|
62
|
-
*/
|
|
63
60
|
interface BlockHandlePopupProps extends OverlayPopupProps {}
|
|
64
61
|
/** @internal */
|
|
65
62
|
declare const BlockHandlePopupPropsDeclaration: PropsDeclaration<BlockHandlePopupProps>;
|
|
@@ -80,9 +77,6 @@ declare const BlockHandlePopupElementBase: HostElementConstructor<BlockHandlePop
|
|
|
80
77
|
declare class BlockHandlePopupElement extends BlockHandlePopupElementBase {}
|
|
81
78
|
/** @internal */
|
|
82
79
|
declare function registerBlockHandlePopupElement(): void;
|
|
83
|
-
/**
|
|
84
|
-
* @public
|
|
85
|
-
*/
|
|
86
80
|
interface BlockHandlePositionerProps extends Omit<OverlayPositionerProps, 'placement' | 'hoist' | 'flip' | 'shift' | 'hide'> {
|
|
87
81
|
/**
|
|
88
82
|
* The placement of the popover, relative to the hovered block.
|
|
@@ -151,9 +145,6 @@ interface BlockHandleRootProps {
|
|
|
151
145
|
}
|
|
152
146
|
/** @internal */
|
|
153
147
|
declare const BlockHandleRootPropsDeclaration: PropsDeclaration<BlockHandleRootProps>;
|
|
154
|
-
/**
|
|
155
|
-
* @public
|
|
156
|
-
*/
|
|
157
148
|
declare class BlockHandleStateChangeEvent extends Event {
|
|
158
149
|
/**
|
|
159
150
|
* The currently hovered block's node and position, or `null` if no block is hovered.
|
|
@@ -167,9 +158,6 @@ declare class BlockHandleStateChangeEvent extends Event {
|
|
|
167
158
|
pos: number;
|
|
168
159
|
} | null);
|
|
169
160
|
}
|
|
170
|
-
/**
|
|
171
|
-
* @public
|
|
172
|
-
*/
|
|
173
161
|
interface BlockHandleRootEvents {
|
|
174
162
|
/**
|
|
175
163
|
* Fired when the hovered block changes.
|
|
@@ -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,
|
|
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,MAAM;AAAA;AAIhB;AAAA,cAAa,8BAAA,EAAgC,gBAAgB,CAAC,mBAAA;;;AAAmB;iBAOjE,mBAAA,C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gB;AAIhB;;;;AAA6F;cE4DhF,4BAAA,SAAqC,gCAAgC;;iBAGlE,oCAAA,CAAA;AAAA,UC5EC,oBAAA;;;AJTjB;;;;EIgBE,MAAA,EAAQ,MAAM;AAAA;;cAIH,+BAAA,EAAiC,gBAAgB,CAAC,oBAAA;AAAA,cAMlD,2BAAA,SAAoC,KAAA;EJfgC;AAOjF;;EIYE,MAAA;IAAU,IAAA,EAAM,eAAA;IAAiB,GAAA;EAAA;cACrB,KAAA;IAAS,IAAA,EAAM,eAAA;IAAiB,GAAA;EAAA;AAAA;AAAA,UAM7B,qBAAA;EJjBf;;AAAiC;EIqBjC,WAAA,EAAa,2BAA2B;AAAA;;;AJEiC;iBII3D,oBAAA,CACd,IAAA,EAAM,WAAA,EACN,KAAA,EAAO,KAAA,CAAM,oBAAA;AAAA,cAoCT,0BAAA,EAA4B,sBAAsB,CAAC,oBAAA;;;AJhCW;AAGpE;;;;cIyCa,sBAAA,SAA+B,0BAA0B;AHtFtE;AAAA,iBGyFgB,8BAAA,CAAA"}
|
package/dist/block-handle.js
CHANGED
|
@@ -544,9 +544,6 @@ const BlockHandleRootPropsDeclaration = /* @__PURE__ */ defineProps({ editor: {
|
|
|
544
544
|
default: null,
|
|
545
545
|
attribute: false
|
|
546
546
|
} });
|
|
547
|
-
/**
|
|
548
|
-
* @public
|
|
549
|
-
*/
|
|
550
547
|
var BlockHandleStateChangeEvent = class extends Event {
|
|
551
548
|
constructor(state) {
|
|
552
549
|
super("stateChange", { bubbles: true });
|
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/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;AAEtD,kBAAiB,MAAM,gBAAgB,UAAU;AAC/C,QAAM,gBAAgB;EAEtB,MAAM,QAAQ,UAAU;EACxB,MAAM,SAAS,MAAM,OAAO,KAAK;EACjC,MAAM,aAAa,OAAO,WAAW,KAAK;AAC1C,MAAI,CAAC,UAAU,CAAC,WACd;EAGF,MAAM,EAAE,MAAM,QAAQ;AACtB,SAAO,KAAK,mBAAmB,EAAE,KAAK,MAAM,KAAK,UAAU,CAAC,CAAC;AAC7D,SAAO,OAAO;AAGd,SAA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AAA,EAAU;CACrE,MAAM,eAAe,aAAa,KAAK;CAEvC,MAAM,sBAAsB,oBAAoB,MAAM,UAAU;CAIhE,MAAM,eAAe,mBAFL,eAAe,CAAC,CAAC,MAAM,WAAW,KAAK,IAAI,CAAC,cAAc,IAAI,CAAC,qBAAqB,CAG3F,QACD,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\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\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\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\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,CAAS;kBAC/D,aAAa,KAAK;;AACzD;;;;AAKA,MAAa,0BAAqD,cAAgC,6BAA6B;;;;AAK/H,MAAa,iCAAwD,cAA4B,qCAAqC;;ACItI,MAAa,iCAAwF,4BAAiC,EACpI,QAAQ;CAAE,SAAS;CAAM,WAAW;AAAM,EAC5C,CAAC;;;;AAKD,SAAgB,oBACd,MACA,OACM;CACN,MAAM,WAAW,wBAAwB,QAAQ,IAAI;CAErD,iBAAiB,MAAM,gBAAgB,UAAU;EAC/C,MAAM,eAAe;EAErB,MAAM,QAAQ,SAAS;EACvB,MAAM,SAAS,MAAM,OAAO,IAAI;EAChC,MAAM,aAAa,OAAO,WAAW,IAAI;EACzC,IAAI,CAAC,UAAU,CAAC,YACd;EAGF,MAAM,EAAE,MAAM,QAAQ;EACtB,OAAO,KAAK,mBAAmB,EAAE,KAAK,MAAM,KAAK,SAAS,CAAC,CAAC;EAC5D,OAAO,MAAM;EAGb,OAAO,WAAW,IAAI,KAAA,CAAS;CACjC,CAAC;AACH;AAEA,MAAM,4BAAyE,oBAC7E,qBACA,8BACF;;;;;;AAOA,IAAa,wBAAb,cAA2C,0BAA0B,CAAC;;AAGtE,SAAgB,gCAAsC;CACpD,sBAAsB,6BAA6B,qBAAqB;AAC1E;ACxEA,MAAa,sBAAsB;;;;;ACkBnC,SAAgB,cAAc,SAAkB,cAAkD;CAChG,MAAM,OAAO,QAAQ,sBAAsB;CAC3C,IAAI,KAAK,UAAU,KAAK,KAAK,W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sB,oBAAoB,MAAM,SAAS;CAI/D,MAAM,eAAe,mBAFL,eAAe,CAAC,CAAC,MAAM,WAAW,IAAI,KAAK,CAAC,aAAa,KAAK,CAAC,oBAAoB,CAG3F,SACA,CAAC,SACD,YACA,QACL,UAAU,KAAK,cAAc,KAAK,CACrC;CAEA,kBAAkB,MAAM,YAAY,KAAK,eAAe;EACtD,UAAU,IAAI,OAAO,KAAA,CAAS;EAC9B,MAAM,WAAW,IAAI,UAAU;EAC/B,MAAM,QAAQ,aAAa;GAAE,MAAM,WAAW;GAAM,KAAK,WAAW;EAAI,IAAI;EAC5E,KAAK,cAAc,IAAI,4BAA4B,KAAK,CAAC;CAC3D,CAAC;CAED,UAAU,YAAY;EACpB,aAAa,iBAAiB,UAAU,IAAI,CAAC;CAC/C,CAAC;CAED,+BAA+B,QAAQ,MAAM,YAAY;AAC3D;AAEA,MAAM,6BAA2E,oBAC/E,sBACA,+BACF;;;;;;;;AASA,IAAa,yBAAb,cAA4C,2BAA2B,CAAC;;AAGxE,SAAgB,iCAAuC;CACrD,sBAAsB,8BAA8B,sBAAsB;AAC5E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drop-indicator.d.ts","names":[],"sources":["../src/components/drop-indicator/drop-indicator.ts"],"mappings":";;UAoBiB,kBAAA;EAAA;;;;;;EAOf,MAAA,EAAQ,
|
|
1
|
+
{"version":3,"file":"drop-indicator.d.ts","names":[],"sources":["../src/components/drop-indicator/drop-indicator.ts"],"mappings":";;UAoBiB,kBAAA;EAAA;;;;;;EAOf,MAAA,EAAQ,MAAM;EAOT;AAAA;AAIP;;;EAJE,KAAA;AAAA;AAoBF;AAAA,cAhBa,6BAAA,EAA+B,gBAAgB,CAAC,kBAAA;;;;iBAgB7C,kBAAA,CACd,IAAA,EAAM,WAAA,EACN,KAAA,EAAO,KAAA,CAAM,kBAAA;AAAA,cAwDT,wBAAA,EAA0B,sBAAsB,CAAC,kBAAA;;;;;;cAU1C,oBAAA,SAA6B,wBAAwB;AAlEhC;AAsDjC;;AAtDiC,iBAuElB,4BAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drop-indicator.js","names":[],"sources":["../src/components/drop-indicator/drop-indicator.ts"],"sourcesContent":["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 { usePresence } from '@aria-ui/utils'\nimport type { Editor } from '@prosekit/core'\nimport { defineDropIndicator, type ShowHandlerOptions } from '@prosekit/extensions/drop-indicator'\n\nimport { useEditorExtension } from '../../hooks/use-editor-extension.ts'\nimport { useScrolling } from '../../hooks/use-scrolling.ts'\nimport { assignStyles } from '../../utils/assign-styles.ts'\n\nexport interface DropIndicatorProps {\n /**\n * The ProseKit editor instance.\n *\n * @default null\n * @hidden\n */\n editor: Editor | null\n\n /**\n * The line width in pixels.\n *\n * @default 2\n */\n width: number\n}\n\n/** @internal */\nexport const DropIndicatorPropsDeclaration: PropsDeclaration<DropIndicatorProps> = /* @__PURE__ */ defineProps<DropIndicatorProps>({\n editor: {\n default: null,\n attribute: false,\n type: 'json',\n },\n width: {\n default: 2,\n attribute: 'width',\n type: 'number',\n },\n})\n\n/**\n * @internal\n */\nexport function setupDropIndicator(\n host: HostElement,\n props: State<DropIndicatorProps>,\n): void {\n type DropIndicatorContext = ShowHandlerOptions | null\n const context = createSignal<DropIndicatorContext>(null)\n\n const extension = defineDropIndicator({\n onShow: (options) => context.set(options),\n onHide: () => context.set(null),\n })\n\n useEditorExtension(host, props.editor.get, extension)\n\n const getLine = computed(() => context.get()?.line)\n const getScrolling = useScrolling(host)\n const getPresence = computed(() => !!context.get() && !getScrolling())\n usePresence(host, getPresence)\n\n useEffect(host, () => {\n const lineValue = getLine()\n const lineWidth = props.width.get()\n\n if (!lineValue) return\n\n const { p1: { x: x1, y: y1 }, p2: { x: x2, y: y2 } } = lineValue\n const horizontal = y1 === y2\n\n let width: number\n let height: number\n let top: number = y1\n let left: number = x1\n\n if (horizontal) {\n width = x2 - x1\n height = lineWidth\n top -= lineWidth / 2\n } else {\n width = lineWidth\n height = y2 - y1\n left -= lineWidth / 2\n }\n\n top = Math.round(top)\n left = Math.round(left)\n\n assignStyles(host, {\n position: 'fixed',\n pointerEvents: 'none',\n width: `${width}px`,\n height: `${height}px`,\n transform: `translate(${left}px, ${top}px)`,\n left: '0px',\n top: '0px',\n })\n })\n}\n\nconst DropIndicatorElementBase: HostElementConstructor<DropIndicatorProps> = defineCustomElement(\n setupDropIndicator,\n DropIndicatorPropsDeclaration,\n)\n\n/**\n * `<prosekit-drop-indicator>` custom element.\n *\n * Properties: {@link DropIndicatorProps}\n */\nexport class DropIndicatorElement extends DropIndicatorElementBase {}\n\n/**\n * @internal\n */\nexport function registerDropIndicatorElement(): void {\n registerCustomElement('prosekit-drop-indicator', DropIndicatorElement)\n}\n"],"mappings":";;;;;;AAsCA,MAAa,gCAAsF,4BAAgC;CACjI,QAAQ;EACN,SAAS;EACT,WAAW;EACX,MAAM;
|
|
1
|
+
{"version":3,"file":"drop-indicator.js","names":[],"sources":["../src/components/drop-indicator/drop-indicator.ts"],"sourcesContent":["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 { usePresence } from '@aria-ui/utils'\nimport type { Editor } from '@prosekit/core'\nimport { defineDropIndicator, type ShowHandlerOptions } from '@prosekit/extensions/drop-indicator'\n\nimport { useEditorExtension } from '../../hooks/use-editor-extension.ts'\nimport { useScrolling } from '../../hooks/use-scrolling.ts'\nimport { assignStyles } from '../../utils/assign-styles.ts'\n\nexport interface DropIndicatorProps {\n /**\n * The ProseKit editor instance.\n *\n * @default null\n * @hidden\n */\n editor: Editor | null\n\n /**\n * The line width in pixels.\n *\n * @default 2\n */\n width: number\n}\n\n/** @internal */\nexport const DropIndicatorPropsDeclaration: PropsDeclaration<DropIndicatorProps> = /* @__PURE__ */ defineProps<DropIndicatorProps>({\n editor: {\n default: null,\n attribute: false,\n type: 'json',\n },\n width: {\n default: 2,\n attribute: 'width',\n type: 'number',\n },\n})\n\n/**\n * @internal\n */\nexport function setupDropIndicator(\n host: HostElement,\n props: State<DropIndicatorProps>,\n): void {\n type DropIndicatorContext = ShowHandlerOptions | null\n const context = createSignal<DropIndicatorContext>(null)\n\n const extension = defineDropIndicator({\n onShow: (options) => context.set(options),\n onHide: () => context.set(null),\n })\n\n useEditorExtension(host, props.editor.get, extension)\n\n const getLine = computed(() => context.get()?.line)\n const getScrolling = useScrolling(host)\n const getPresence = computed(() => !!context.get() && !getScrolling())\n usePresence(host, getPresence)\n\n useEffect(host, () => {\n const lineValue = getLine()\n const lineWidth = props.width.get()\n\n if (!lineValue) return\n\n const { p1: { x: x1, y: y1 }, p2: { x: x2, y: y2 } } = lineValue\n const horizontal = y1 === y2\n\n let width: number\n let height: number\n let top: number = y1\n let left: number = x1\n\n if (horizontal) {\n width = x2 - x1\n height = lineWidth\n top -= lineWidth / 2\n } else {\n width = lineWidth\n height = y2 - y1\n left -= lineWidth / 2\n }\n\n top = Math.round(top)\n left = Math.round(left)\n\n assignStyles(host, {\n position: 'fixed',\n pointerEvents: 'none',\n width: `${width}px`,\n height: `${height}px`,\n transform: `translate(${left}px, ${top}px)`,\n left: '0px',\n top: '0px',\n })\n })\n}\n\nconst DropIndicatorElementBase: HostElementConstructor<DropIndicatorProps> = defineCustomElement(\n setupDropIndicator,\n DropIndicatorPropsDeclaration,\n)\n\n/**\n * `<prosekit-drop-indicator>` custom element.\n *\n * Properties: {@link DropIndicatorProps}\n */\nexport class DropIndicatorElement extends DropIndicatorElementBase {}\n\n/**\n * @internal\n */\nexport function registerDropIndicatorElement(): void {\n registerCustomElement('prosekit-drop-indicator', DropIndicatorElement)\n}\n"],"mappings":";;;;;;AAsCA,MAAa,gCAAsF,4BAAg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pE,SAAgB,+BAAqC;CACnD,sBAAsB,2BAA2B,oBAAoB;AACvE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-safe-editor-view.js","names":[],"sources":["../src/utils/get-safe-editor-view.ts"],"sourcesContent":["import type { Editor } from '@prosekit/core'\nimport type { EditorView } from '@prosekit/pm/view'\n\n/**\n * @internal\n */\nexport function getSafeEditorView(editor?: Editor | null): EditorView | undefined {\n if (!editor || !editor.mounted) return\n return editor.view\n}\n"],"mappings":";;;AAMA,SAAgB,kBAAkB,QAAgD;
|
|
1
|
+
{"version":3,"file":"get-safe-editor-view.js","names":[],"sources":["../src/utils/get-safe-editor-view.ts"],"sourcesContent":["import type { Editor } from '@prosekit/core'\nimport type { EditorView } from '@prosekit/pm/view'\n\n/**\n * @internal\n */\nexport function getSafeEditorView(editor?: Editor | null): EditorView | undefined {\n if (!editor || !editor.mounted) return\n return editor.view\n}\n"],"mappings":";;;AAMA,SAAgB,kBAAkB,QAAgD;CAChF,IAAI,CAAC,UAAU,CAAC,OAAO,SAAS;CAChC,OAAO,OAAO;AAChB"}
|