@prosekit/lit
Advanced tools
Comparing version 0.1.9 to 0.2.0
import { AutoUpdateOptions } from '@floating-ui/dom'; | ||
import { ComputePositionConfig } from '@floating-ui/dom'; | ||
import type { Boundary } from '@floating-ui/dom'; | ||
import type { ComputePositionReturn } from '@floating-ui/dom'; | ||
import { CSSResult } from 'lit'; | ||
import { Editor } from '@prosekit/core'; | ||
import type { EditorView } from '@prosekit/pm/view'; | ||
import { Extension } from '@prosekit/core'; | ||
import type { FloatingElement } from '@floating-ui/dom'; | ||
import { FocusChangeHandler } from '@prosekit/core'; | ||
import { Keymap } from '@prosekit/core'; | ||
import { LitElement } from 'lit'; | ||
import { Options } from 'tsup'; | ||
import type { Placement } from '@floating-ui/dom'; | ||
import { PropertyValues } from 'lit'; | ||
import { ReactiveController } from 'lit'; | ||
import { ReactiveControllerHost } from 'lit'; | ||
import type { ReferenceElement } from '@floating-ui/dom'; | ||
import type { Selection as Selection_2 } from '@prosekit/pm/state'; | ||
import { TemplateResult } from 'lit'; | ||
import { UpdateHandler } from '@prosekit/core'; | ||
import { VirtualElement } from '@floating-ui/dom'; | ||
@@ -138,2 +145,4 @@ | ||
editor: { | ||
type: ObjectConstructor; | ||
reflect: false; | ||
attribute: false; | ||
@@ -144,34 +153,22 @@ }; | ||
}; | ||
popoverOptions: { | ||
positioning: { | ||
type: ObjectConstructor; | ||
reflect: false; | ||
attribute: false; | ||
}; | ||
onSelect: { | ||
reference: { | ||
attribute: false; | ||
}; | ||
active: { | ||
open: { | ||
type: BooleanConstructor; | ||
reflect: true; | ||
}; | ||
reference: { | ||
reflect: false; | ||
attribute: false; | ||
}; | ||
options: { | ||
onOpenChange: { | ||
attribute: false; | ||
}; | ||
autoUpdate: { | ||
type: BooleanConstructor; | ||
reflect: true; | ||
}; | ||
autoUpdateOptions: { | ||
type: ObjectConstructor; | ||
}; | ||
dismiss: { | ||
type: StringConstructor; | ||
reflect: true; | ||
}; | ||
}; | ||
editor?: Editor; | ||
regex?: RegExp; | ||
popoverOptions: PopoverOptions; | ||
onSelect?: VoidFunction; | ||
positioning?: PositioningOptions; | ||
private context; | ||
@@ -220,3 +217,3 @@ private get list(); | ||
regex: RegExp; | ||
popoverOptions?: PopoverOptions; | ||
positioning?: PositioningOptions; | ||
} | ||
@@ -228,9 +225,2 @@ | ||
/** | ||
* If the browser supports the Popover API, we use the body as the boundary | ||
* since we don't need to worry about the popover overflowing the parent | ||
* element. | ||
*/ | ||
export declare const boundary: HTMLElement | undefined; | ||
export declare function calcResize(position: 'top' | 'right' | 'bottom' | 'left' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right', w: number, h: number, dx: number, dy: number, aspectRatio: number | null | undefined): [w: number, h: number]; | ||
@@ -249,23 +239,18 @@ | ||
}; | ||
active: { | ||
type: BooleanConstructor; | ||
reflect: true; | ||
}; | ||
reference: { | ||
attribute: false; | ||
}; | ||
options: { | ||
open: { | ||
type: BooleanConstructor; | ||
reflect: false; | ||
attribute: false; | ||
}; | ||
autoUpdate: { | ||
type: BooleanConstructor; | ||
reflect: true; | ||
onOpenChange: { | ||
attribute: false; | ||
}; | ||
autoUpdateOptions: { | ||
positioning: { | ||
type: ObjectConstructor; | ||
reflect: false; | ||
attribute: false; | ||
}; | ||
dismiss: { | ||
type: StringConstructor; | ||
reflect: true; | ||
}; | ||
}; | ||
@@ -413,13 +398,13 @@ onDismiss?: VoidFunction; | ||
/** | ||
* Default popover options. | ||
* If the browser supports the Popover API, we use the body as the boundary | ||
* since we don't need to worry about the popover overflowing the parent | ||
* element. | ||
*/ | ||
export declare const defaultPopoverOptions: PopoverOptions; | ||
export declare const defaultBoundary: HTMLElement | undefined; | ||
/** | ||
* Default popover options. | ||
* @internal | ||
*/ | ||
export declare const defaultPopoverOptions_alias_1: PopoverOptions; | ||
export declare const defaultOptions: PositioningOptions; | ||
export declare const defaultPopoverOptions_alias_2: PopoverOptions; | ||
export declare function defaultQueryBuilder(match: RegExpExecArray): string; | ||
@@ -429,4 +414,8 @@ | ||
export declare function getVirtualSelectionElement(view: EditorView): Range | undefined; | ||
export declare function getPlacement(reference: ReferenceElement | null, floating: FloatingElement | null, options: PositioningOptions): (() => void) | undefined; | ||
export declare function getReferenceContextElement(reference: HTMLElement | VirtualElement | undefined | null): HTMLElement | null; | ||
export declare function getVirtualSelectionElement(view: EditorView): ReferenceElement | undefined; | ||
export declare class InlinePopover extends Popover implements Partial<InlinePopoverProps> { | ||
@@ -440,38 +429,29 @@ /** | ||
}; | ||
popoverOptions: { | ||
reference: { | ||
attribute: false; | ||
}; | ||
active: { | ||
open: { | ||
type: BooleanConstructor; | ||
reflect: true; | ||
}; | ||
reference: { | ||
reflect: false; | ||
attribute: false; | ||
}; | ||
options: { | ||
onOpenChange: { | ||
attribute: false; | ||
}; | ||
autoUpdate: { | ||
type: BooleanConstructor; | ||
reflect: true; | ||
}; | ||
autoUpdateOptions: { | ||
positioning: { | ||
type: ObjectConstructor; | ||
reflect: false; | ||
attribute: false; | ||
}; | ||
dismiss: { | ||
type: StringConstructor; | ||
reflect: true; | ||
}; | ||
}; | ||
editor?: Editor; | ||
popoverOptions: PopoverOptions; | ||
dismiss: "escape"; | ||
positioning?: PositioningOptions; | ||
/** | ||
* @hidden | ||
*/ | ||
private controller; | ||
constructor(); | ||
/** | ||
* @hidden | ||
*/ | ||
willUpdate(): void; | ||
protected updated(changedProperties: PropertyValues<this>): void; | ||
/** | ||
@@ -483,21 +463,5 @@ * @hidden | ||
export declare class InlinePopoverController implements ReactiveController { | ||
private host; | ||
reference?: VirtualElement; | ||
private editor?; | ||
private cleanupExtension?; | ||
private cleanupEventListener?; | ||
private interacting; | ||
constructor(host: LitElement); | ||
setEditor(editor: Editor): void; | ||
hostConnected(): void; | ||
hostDisconnected(): void; | ||
private update; | ||
private defineExtension; | ||
} | ||
export declare interface InlinePopoverProps { | ||
export declare type InlinePopoverProps = { | ||
editor: Editor; | ||
popoverOptions?: PopoverOptions; | ||
} | ||
} & PopoverProps; | ||
@@ -573,32 +537,58 @@ export declare function isAutocompleteItem(element?: Element | null): element is AutocompleteItem; | ||
static properties: { | ||
active: { | ||
type: BooleanConstructor; | ||
reflect: true; | ||
}; | ||
reference: { | ||
attribute: false; | ||
}; | ||
options: { | ||
open: { | ||
type: BooleanConstructor; | ||
reflect: false; | ||
attribute: false; | ||
}; | ||
autoUpdate: { | ||
type: BooleanConstructor; | ||
reflect: true; | ||
onOpenChange: { | ||
attribute: false; | ||
}; | ||
autoUpdateOptions: { | ||
positioning: { | ||
type: ObjectConstructor; | ||
reflect: false; | ||
attribute: false; | ||
}; | ||
dismiss: { | ||
type: StringConstructor; | ||
reflect: true; | ||
}; | ||
}; | ||
reference?: HTMLElement | VirtualElement; | ||
open?: boolean; | ||
onOpenChange?: ((open: boolean) => void) | undefined; | ||
positioning?: PositioningOptions; | ||
/** | ||
* Controls the visibility of the popover element. When set to `true`, the | ||
* popover is displayed and positioned relative to its reference element. When | ||
* set to `false`, the popover is hidden and its positioning logic is | ||
* deactivated. | ||
* @hidden | ||
*/ | ||
active: boolean; | ||
constructor(); | ||
/** | ||
* @hidden | ||
*/ | ||
connectedCallback(): void; | ||
private updatePopoverAttribute; | ||
private updateDateAttributes; | ||
/** | ||
* @hidden | ||
*/ | ||
protected updated(changedProperties: PropertyValues<this>): void; | ||
/** | ||
* @hidden | ||
*/ | ||
hide(): void; | ||
} | ||
/** | ||
* Whether the browser supports the [Popover API](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API). | ||
*/ | ||
export declare const popoverAvailable: boolean; | ||
export declare interface PopoverProps { | ||
/** | ||
* Whether the popover is open. | ||
*/ | ||
open?: boolean; | ||
/** | ||
* Function invoked when the popover opens or closes. | ||
*/ | ||
onOpenChange?: (open: boolean) => void; | ||
/** | ||
* The element that the popover is anchored to. This can be either a DOM | ||
@@ -610,103 +600,130 @@ * element or an object that implements the virtual element interface from | ||
/** | ||
* The options that are passed to the `computePosition` function from Floating | ||
* UI. These options are used to configure the positioning of the popover | ||
* element relative to its reference element. For more information on the | ||
* available options, please refer to the Floating UI documentation. | ||
* The user provided options used to position the popover content. | ||
*/ | ||
options?: PopoverOptions; | ||
positioning?: PositioningOptions; | ||
} | ||
declare const popoverPropsNames: readonly ["open", "onOpenChange", "reference", "positioning"]; | ||
export { popoverPropsNames } | ||
export { popoverPropsNames as propNames_alias_13 } | ||
/** | ||
* @public | ||
*/ | ||
declare interface PositioningOptions { | ||
/** | ||
* Controls whether the popover position is automatically updated when the | ||
* reference element changes position. When set to `true`, the popover | ||
* position is updated automatically. When set to `false`, the popover | ||
* position is only updated when the given properties are changed. | ||
* The strategy to use for positioning | ||
* | ||
* @default false | ||
* @default 'absolute' | ||
*/ | ||
autoUpdate: boolean; | ||
strategy?: 'absolute' | 'fixed'; | ||
/** | ||
* The options that are passed to the `autoUpdate` function from Floating UI. | ||
* These options are used to configure the automatic update behavior of the | ||
* popover position. For more information on the available options, please | ||
* refer to the Floating UI documentation. This property is only used when the | ||
* `autoUpdate` property is set to `true`. | ||
* The initial placement of the floating element | ||
* | ||
* @default 'bottom' | ||
*/ | ||
autoUpdateOptions?: AutoUpdateOptions; | ||
placement?: Placement; | ||
/** | ||
* Controls whether the popover should be dismissed based on user interaction. | ||
* Options to activate auto-update listeners | ||
* | ||
* Available options: | ||
* @default true | ||
*/ | ||
autoUpdate?: boolean | AutoUpdateOptions; | ||
/** | ||
* The virtual padding around the viewport edges to check for overflow | ||
* | ||
* - "off": The popover is not dismissed. | ||
* - "on": The popover is dismissed when the user clicks outside of the popover or presses the escape key. | ||
* - "click": The popover is dismissed when the user clicks outside of the popover. | ||
* - "escape": The popover is dismissed when the user presses the escape key. | ||
* @default 8 | ||
*/ | ||
overflowPadding?: number; | ||
/** | ||
* Whether to flip the placement | ||
* | ||
* @default "on" | ||
* @default true | ||
*/ | ||
dismiss: 'off' | 'on' | 'click' | 'escape'; | ||
flip?: boolean | Placement[]; | ||
/** | ||
* @hidden | ||
* Whether the floating element should shift to keep it in view. | ||
* | ||
* @default true | ||
*/ | ||
private disposeAutoUpdate?; | ||
shift?: boolean; | ||
/** | ||
* @hidden | ||
* Whether the floating element can overlap the reference element | ||
* | ||
* @default false | ||
*/ | ||
private disposeEventListeners?; | ||
overlap?: boolean; | ||
/** | ||
* @hidden | ||
* Whether to improve positioning for inline reference elements that span over | ||
* multiple lines. | ||
* | ||
* @default false | ||
*/ | ||
connectedCallback(): void; | ||
inline?: boolean; | ||
/** | ||
* @hidden | ||
* Whether to hide the floating element when the reference element is fully clipped. | ||
* | ||
* @default true | ||
*/ | ||
disconnectedCallback(): void; | ||
hide?: boolean; | ||
/** | ||
* @hidden | ||
* Whether to make the floating element same width as the reference element | ||
* | ||
* @default false | ||
*/ | ||
protected updated(changedProperties: PropertyValues<this>): void; | ||
sameWidth?: boolean; | ||
/** | ||
* @hidden | ||
* Whether the popover should fit the viewport. | ||
* | ||
* @default false | ||
*/ | ||
private start; | ||
fitViewport?: boolean; | ||
/** | ||
* @hidden | ||
* The distance between the reference and floating element. | ||
* | ||
* @default 8 | ||
*/ | ||
private compute; | ||
offset?: number | { | ||
mainAxis?: number; | ||
crossAxis?: number; | ||
alignmentAxis?: number; | ||
}; | ||
/** | ||
* @hidden | ||
* The overflow boundary of the reference element | ||
* | ||
* @default undefined | ||
*/ | ||
hide(): void; | ||
private handleDocumentMouseDown; | ||
private handleDocumentKeyDown; | ||
boundary?: Boundary | (() => Boundary); | ||
/** | ||
* Function called when the placement is computed | ||
* | ||
* @default undefined | ||
*/ | ||
onComplete?(data: ComputePositionReturn): void; | ||
/** | ||
* Function called on cleanup of all listeners | ||
* | ||
* @default undefined | ||
*/ | ||
onCleanup?: VoidFunction; | ||
/** | ||
* Function called when the escape key is down. By default, the popover is | ||
* hidden when the escape key is down. It can be prevented by calling | ||
* `event.preventDefault`. | ||
*/ | ||
onEscapeKeyDown?: (event: KeyboardEvent) => void; | ||
/** | ||
* Function called when when pointer down event happens outside of the | ||
* popover. By default, the popover is hidden when the pointer down event | ||
* happens outside of the popover. It can be prevented by calling | ||
* `event.preventDefault`. | ||
*/ | ||
onPointerDownOutside?: (event: Event) => void; | ||
} | ||
export { PositioningOptions } | ||
export { PositioningOptions as PositioningOptions_alias_1 } | ||
export { PositioningOptions as PositioningOptions_alias_2 } | ||
export { PositioningOptions as PositioningOptions_alias_3 } | ||
/** | ||
* Whether the browser supports the [Popover API](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API). | ||
*/ | ||
export declare const popoverAvailable: boolean; | ||
/** | ||
* The `PopoverOptions` interface defines the options that can be passed to the | ||
* `computePosition` function from Floating UI. These options are used to | ||
* configure the positioning of the popover element relative to its reference | ||
* element. For more information on the available options, please refer to the | ||
* Floating UI documentation. | ||
* | ||
* https://floating-ui.com/docs/computeposition#options | ||
*/ | ||
declare type PopoverOptions = ComputePositionConfig; | ||
export { PopoverOptions } | ||
export { PopoverOptions as PopoverOptions_alias_1 } | ||
export { PopoverOptions as PopoverOptions_alias_2 } | ||
export { PopoverOptions as PopoverOptions_alias_3 } | ||
export declare interface PopoverProps { | ||
active: boolean; | ||
reference?: Element | VirtualElement; | ||
options?: PopoverOptions; | ||
autoUpdate?: boolean; | ||
autoUpdateOptions?: AutoUpdateOptions; | ||
} | ||
/** | ||
* @internal | ||
@@ -752,8 +769,6 @@ */ | ||
export declare const propNames_alias_12: readonly ["editor", "popoverOptions"]; | ||
export declare const propNames_alias_12: readonly ["editor", "open", "onOpenChange", "reference", "positioning"]; | ||
export declare const propNames_alias_13: readonly ["active", "reference", "options", "autoUpdate", "autoUpdateOptions"]; | ||
export declare const propNames_alias_5: readonly ["editor", "regex", "positioning"]; | ||
export declare const propNames_alias_5: readonly ["editor", "regex", "popoverOptions"]; | ||
/** | ||
@@ -920,2 +935,29 @@ * @internal | ||
export declare function setFloatingStyles(element: HTMLElement, options: PositioningOptions): void; | ||
export declare function useDismissable(host: LitElement, { onEscapeKeyDown, onPointerDownOutside, onDismiss, getReference, }: { | ||
onEscapeKeyDown: (event: KeyboardEvent) => void; | ||
onPointerDownOutside: (event: Event) => void; | ||
onDismiss?: VoidFunction; | ||
getReference?: () => ReferenceElement | null | undefined; | ||
}): void; | ||
export declare function useEditorExtension(host: WithEditor<ReactiveControllerHost>, extension: Extension): void; | ||
export declare function useEditorFocusChangeEvent(host: WithEditor<ReactiveControllerHost>, handler: FocusChangeHandler): void; | ||
export declare function useEditorUpdateEvent(host: WithEditor<ReactiveControllerHost>, handler: UpdateHandler): void; | ||
export declare function useEffect<T>(host: ReactiveControllerHost, getValue: () => T, onChange: (value: T) => void): void; | ||
export declare function useInlinePopover(host: WithEditor<LitElement>, onReferenceChange: (reference: ReferenceElement | undefined) => void): () => ReferenceElement | undefined; | ||
export declare function usePointerDownEvent(host: LitElement, handler: (event: PointerEvent) => void): void; | ||
export declare function usePopover(host: LitElement, getReference: () => ReferenceElement | null, getPositioning: () => PositioningOptions | null): void; | ||
export declare type WithEditor<T> = T & { | ||
editor?: Editor | undefined | null; | ||
}; | ||
export { } |
@@ -1,4 +0,4 @@ | ||
export { PopoverOptions } from './_tsup-dts-rollup'; | ||
export { PositioningOptions } from './_tsup-dts-rollup'; | ||
export { propNames_alias_5 as propNames } from './_tsup-dts-rollup'; | ||
export { AutocompletePopoverProps } from './_tsup-dts-rollup'; | ||
export { AutocompletePopover } from './_tsup-dts-rollup'; |
@@ -7,5 +7,4 @@ import { | ||
import { | ||
Popover, | ||
boundary | ||
} from "./chunk-CUH6G34Q.js"; | ||
Popover | ||
} from "./chunk-OZUEYWYU.js"; | ||
import "./chunk-GZRUCYLP.js"; | ||
@@ -109,64 +108,4 @@ import { | ||
// src/components/autocomplete-popover/default-popover-options.ts | ||
import { | ||
flip, | ||
inline, | ||
offset, | ||
shift, | ||
size | ||
} from "@floating-ui/dom"; | ||
var defaultDetectOverflowOptions = { | ||
padding: 8, | ||
boundary | ||
}; | ||
var defaultPopoverOptions = { | ||
// The main axis is the y axis, and we place the popover at the bottom of the | ||
// reference element. | ||
// | ||
// The cross axis is the x axis, and we place the popover at the start of the | ||
// reference element. The reference element and the popover are left-aligned. | ||
placement: "bottom-start", | ||
middleware: [ | ||
// Use the text caret as the reference point | ||
inline(), | ||
offset({ | ||
// Move down the popover by 4px | ||
mainAxis: 4 | ||
}), | ||
// Flip the popover to the top if it's overflowing the viewport | ||
// | ||
// When `flipAlignment` is true, which is the default, ensure `flip() `is | ||
// placed before `shift()` in your middleware array. | ||
// | ||
// https://floating-ui.com/docs/flip#flipalignment | ||
flip({ | ||
// Flip the popover to the top if necessary. | ||
mainAxis: true, | ||
// We don't want to flip the popover to the left or right, since `shift()` | ||
// will handle this. | ||
crossAxis: false, | ||
...defaultDetectOverflowOptions | ||
}), | ||
// We need to place `shift()` after `flip()`. See https://floating-ui.com/docs/flip#flipalignment | ||
shift({ | ||
...defaultDetectOverflowOptions | ||
}), | ||
size({ | ||
apply: ({ availableWidth, availableHeight, elements }) => { | ||
elements.floating.style.setProperty( | ||
"max-width", | ||
`${Math.floor(availableWidth)}px` | ||
); | ||
elements.floating.style.setProperty( | ||
"max-height", | ||
`${Math.floor(availableHeight)}px` | ||
); | ||
}, | ||
...defaultDetectOverflowOptions | ||
}) | ||
] | ||
}; | ||
// src/components/autocomplete-popover/index.ts | ||
var propNames = ["editor", "regex", "popoverOptions"]; | ||
var propNames = ["editor", "regex", "positioning"]; | ||
var AutocompletePopover = class extends Popover { | ||
@@ -182,3 +121,8 @@ constructor() { | ||
); | ||
this.popoverOptions = defaultPopoverOptions; | ||
this.positioning = { | ||
strategy: "fixed", | ||
placement: "bottom-start", | ||
flip: false, | ||
inline: true | ||
}; | ||
this.context = new ContextProvider(this, { | ||
@@ -228,5 +172,4 @@ context: autocompletePopoverContext, | ||
} | ||
this.active = !!((_a = this.controller) == null ? void 0 : _a.reference); | ||
this.open = !!((_a = this.controller) == null ? void 0 : _a.reference); | ||
this.reference = (_b = this.controller.reference) != null ? _b : void 0; | ||
this.options = this.popoverOptions; | ||
} | ||
@@ -250,6 +193,5 @@ /** | ||
...Popover.properties, | ||
editor: { attribute: false }, | ||
editor: { type: Object, reflect: false, attribute: false }, | ||
regex: { attribute: false }, | ||
popoverOptions: { attribute: false }, | ||
onSelect: { attribute: false } | ||
positioning: { type: Object, reflect: false, attribute: false } | ||
}; | ||
@@ -256,0 +198,0 @@ defineCustomElement("prosekit-autocomplete-popover", AutocompletePopover); |
import { | ||
Popover | ||
} from "./chunk-CUH6G34Q.js"; | ||
} from "./chunk-OZUEYWYU.js"; | ||
import { | ||
@@ -5,0 +5,0 @@ ListManager |
@@ -1,4 +0,4 @@ | ||
export { PopoverOptions_alias_1 as PopoverOptions } from './_tsup-dts-rollup'; | ||
export { PositioningOptions_alias_1 as PositioningOptions } from './_tsup-dts-rollup'; | ||
export { propNames_alias_12 as propNames } from './_tsup-dts-rollup'; | ||
export { InlinePopoverProps } from './_tsup-dts-rollup'; | ||
export { InlinePopover } from './_tsup-dts-rollup'; |
import { | ||
Popover | ||
} from "./chunk-CUH6G34Q.js"; | ||
Popover, | ||
popoverPropsNames | ||
} from "./chunk-OZUEYWYU.js"; | ||
import { | ||
@@ -11,6 +12,63 @@ defineCustomElement | ||
// src/components/inline-popover/controller.ts | ||
// src/controllers/use-editor-focus-event.ts | ||
import { | ||
defineFocusChangeHandler | ||
} from "@prosekit/core"; | ||
// src/controllers/use-editor-extension.ts | ||
import "@prosekit/core"; | ||
function useEditorExtension(host, extension) { | ||
let cleanup; | ||
let editor; | ||
const update = () => { | ||
cleanup == null ? void 0 : cleanup(); | ||
cleanup = editor == null ? void 0 : editor.use(extension); | ||
}; | ||
const hostConnected = () => { | ||
editor = host.editor; | ||
update(); | ||
}; | ||
const hostUpdated = () => { | ||
const newEditor = host.editor; | ||
if (editor !== newEditor) { | ||
editor = newEditor; | ||
update(); | ||
} | ||
}; | ||
const hostDisconnected = () => { | ||
cleanup == null ? void 0 : cleanup(); | ||
cleanup = void 0; | ||
}; | ||
host.addController({ | ||
hostConnected, | ||
hostDisconnected, | ||
hostUpdated | ||
}); | ||
} | ||
// src/controllers/use-editor-focus-event.ts | ||
function useEditorFocusChangeEvent(host, handler) { | ||
const extension = defineFocusChangeHandler(handler); | ||
useEditorExtension(host, extension); | ||
} | ||
// src/controllers/use-editor-update-event.ts | ||
import { defineUpdateHandler } from "@prosekit/core"; | ||
import { trackDismissableElement } from "@zag-js/dismissable"; | ||
function useEditorUpdateEvent(host, handler) { | ||
const extension = defineUpdateHandler(handler); | ||
useEditorExtension(host, extension); | ||
} | ||
// src/controllers/use-pointer-down-event.ts | ||
function usePointerDownEvent(host, handler) { | ||
host.addController({ | ||
hostConnected: () => { | ||
host.addEventListener("pointerdown", handler); | ||
}, | ||
hostDisconnected: () => { | ||
host.removeEventListener("pointerdown", handler); | ||
} | ||
}); | ||
} | ||
// src/components/inline-popover/helpers.ts | ||
@@ -32,3 +90,10 @@ import { isNodeSelection, isTextSelection } from "@prosekit/core"; | ||
if (!selection.empty && !isInCodeBlock(selection) && (isTextSelection(selection) || isNodeSelection(selection))) { | ||
return getDomRange(); | ||
const range = getDomRange(); | ||
if (!range) | ||
return; | ||
return { | ||
contextElement: view.dom, | ||
getBoundingClientRect: () => range.getBoundingClientRect(), | ||
getClientRects: () => range.getClientRects() | ||
}; | ||
} | ||
@@ -48,88 +113,51 @@ } | ||
// src/components/inline-popover/controller.ts | ||
var InlinePopoverController = class { | ||
constructor(host) { | ||
this.host = host; | ||
this.interacting = false; | ||
this.host.addController(this); | ||
} | ||
setEditor(editor) { | ||
if (this.editor !== editor) { | ||
this.editor = editor; | ||
this.defineExtension(); | ||
this.host.requestUpdate(); | ||
// src/components/inline-popover/use-inline-popover.ts | ||
function useInlinePopover(host, onReferenceChange) { | ||
let interacting = false; | ||
let reference; | ||
usePointerDownEvent(host, () => { | ||
interacting = true; | ||
}); | ||
useEditorFocusChangeEvent(host, (focus) => { | ||
if (focus) { | ||
interacting = false; | ||
} | ||
} | ||
hostConnected() { | ||
var _a; | ||
const handlePointerDown = () => { | ||
this.interacting = true; | ||
}; | ||
this.host.addEventListener("pointerdown", handlePointerDown); | ||
const cleanupDismissable = trackDismissableElement(this.host, { | ||
defer: true, | ||
pointerBlocking: false, | ||
onDismiss: () => { | ||
this.interacting = false; | ||
} | ||
}); | ||
(_a = this.cleanupEventListener) == null ? void 0 : _a.call(this); | ||
this.cleanupEventListener = () => { | ||
this.host.removeEventListener("pointerdown", handlePointerDown); | ||
cleanupDismissable(); | ||
}; | ||
} | ||
hostDisconnected() { | ||
var _a, _b; | ||
(_a = this.cleanupExtension) == null ? void 0 : _a.call(this); | ||
this.cleanupExtension = void 0; | ||
(_b = this.cleanupEventListener) == null ? void 0 : _b.call(this); | ||
this.cleanupEventListener = void 0; | ||
} | ||
update() { | ||
const editor = this.editor; | ||
if (!editor || this.interacting) { | ||
}); | ||
useEditorUpdateEvent(host, (view) => { | ||
if (interacting) { | ||
return; | ||
} | ||
const reference = getVirtualSelectionElement(editor.view); | ||
if (this.reference !== reference) { | ||
this.reference = reference; | ||
this.host.requestUpdate(); | ||
const ref = getVirtualSelectionElement(view); | ||
if (reference !== ref) { | ||
reference = ref; | ||
onReferenceChange(reference); | ||
host.requestUpdate(); | ||
} | ||
} | ||
defineExtension() { | ||
var _a; | ||
const editor = this.editor; | ||
if (!editor) { | ||
return; | ||
} | ||
const extension = defineUpdateHandler(() => this.update()); | ||
(_a = this.cleanupExtension) == null ? void 0 : _a.call(this); | ||
this.cleanupExtension = editor.use(extension); | ||
} | ||
}; | ||
}); | ||
const getReference = () => reference; | ||
return getReference; | ||
} | ||
// src/components/inline-popover/default-popover-options.ts | ||
import { inline, offset, shift } from "@floating-ui/dom"; | ||
var defaultPopoverOptions = { | ||
placement: "top", | ||
strategy: "absolute", | ||
middleware: [ | ||
inline(), | ||
offset(8), | ||
shift({ mainAxis: true, crossAxis: true, padding: 8 }) | ||
] | ||
}; | ||
// src/components/inline-popover/index.ts | ||
var propNames = ["editor", "popoverOptions"]; | ||
var propNames = ["editor", ...popoverPropsNames]; | ||
var InlinePopover = class extends Popover { | ||
/** | ||
* @hidden | ||
*/ | ||
constructor() { | ||
super(...arguments); | ||
this.popoverOptions = defaultPopoverOptions; | ||
this.dismiss = "escape"; | ||
/** | ||
* @hidden | ||
*/ | ||
this.controller = new InlinePopoverController(this); | ||
super(); | ||
this.positioning = { | ||
strategy: "fixed", | ||
placement: "top", | ||
offset: 12, | ||
flip: false, | ||
hide: true, | ||
shift: true, | ||
overlap: true, | ||
fitViewport: false, | ||
inline: true | ||
}; | ||
useInlinePopover(this, (reference) => { | ||
this.reference = reference; | ||
}); | ||
} | ||
@@ -139,10 +167,5 @@ /** | ||
*/ | ||
willUpdate() { | ||
var _a, _b; | ||
if (this.editor) { | ||
this.controller.setEditor(this.editor); | ||
} | ||
this.active = !!((_a = this.controller) == null ? void 0 : _a.reference); | ||
this.reference = (_b = this.controller.reference) != null ? _b : void 0; | ||
this.options = this.popoverOptions; | ||
updated(changedProperties) { | ||
super.updated(changedProperties); | ||
this.open = !!this.reference; | ||
} | ||
@@ -153,8 +176,4 @@ /** | ||
hide() { | ||
var _a; | ||
super.hide(); | ||
if ((_a = this.controller) == null ? void 0 : _a.reference) { | ||
this.controller.reference = void 0; | ||
this.reference = void 0; | ||
} | ||
this.reference = void 0; | ||
} | ||
@@ -167,4 +186,3 @@ }; | ||
...Popover.properties, | ||
editor: { attribute: false }, | ||
popoverOptions: { attribute: false } | ||
editor: { attribute: false } | ||
}; | ||
@@ -171,0 +189,0 @@ defineCustomElement("prosekit-inline-popover", InlinePopover); |
export { AutoUpdateOptions } from './_tsup-dts-rollup'; | ||
export { PopoverOptions_alias_2 as PopoverOptions } from './_tsup-dts-rollup'; | ||
export { PositioningOptions_alias_2 as PositioningOptions } from './_tsup-dts-rollup'; | ||
export { popoverPropsNames } from './_tsup-dts-rollup'; | ||
export { propNames_alias_13 as propNames } from './_tsup-dts-rollup'; | ||
export { PopoverProps } from './_tsup-dts-rollup'; | ||
export { Popover } from './_tsup-dts-rollup'; |
import { | ||
Popover, | ||
propNames | ||
} from "./chunk-CUH6G34Q.js"; | ||
popoverPropsNames | ||
} from "./chunk-OZUEYWYU.js"; | ||
import "./chunk-S32IZIQF.js"; | ||
export { | ||
Popover, | ||
propNames | ||
popoverPropsNames, | ||
popoverPropsNames as propNames | ||
}; |
{ | ||
"name": "@prosekit/lit", | ||
"type": "module", | ||
"version": "0.1.9", | ||
"version": "0.2.0", | ||
"private": false, | ||
@@ -98,9 +98,11 @@ "author": { | ||
"dependencies": { | ||
"@floating-ui/dom": "^1.5.4", | ||
"@floating-ui/dom": "^1.5.3", | ||
"@lit/context": "^1.1.0", | ||
"@prosekit/core": "^0.2.4", | ||
"@prosekit/extensions": "^0.2.3", | ||
"@prosekit/extensions": "^0.2.4", | ||
"@prosekit/pm": "^0.1.1", | ||
"@superhuman/command-score": "^0.5.0", | ||
"@zag-js/dismissable": "^0.32.0", | ||
"@zag-js/dom-query": "^0.32.0", | ||
"@zag-js/utils": "^0.32.0", | ||
"lit": "^3.1.1" | ||
@@ -113,3 +115,3 @@ }, | ||
"typescript": "^5.3.3", | ||
"vitest": "^1.1.3" | ||
"vitest": "^1.2.0" | ||
}, | ||
@@ -116,0 +118,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
84131
2694
10
+ Added@zag-js/dom-query@^0.32.0
+ Added@zag-js/utils@^0.32.0
Updated@floating-ui/dom@^1.5.3
Updated@prosekit/extensions@^0.2.4