@prosekit/lit 0.1.8 → 0.2.0

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.
@@ -1,16 +1,23 @@
1
1
  import { AutoUpdateOptions } from '@floating-ui/dom';
2
- import { ComputePositionConfig } from '@floating-ui/dom';
2
+ import type { Boundary } from '@floating-ui/dom';
3
+ import type { ComputePositionReturn } from '@floating-ui/dom';
3
4
  import { CSSResult } from 'lit';
4
5
  import { Editor } from '@prosekit/core';
5
6
  import type { EditorView } from '@prosekit/pm/view';
7
+ import { Extension } from '@prosekit/core';
8
+ import type { FloatingElement } from '@floating-ui/dom';
9
+ import { FocusChangeHandler } from '@prosekit/core';
6
10
  import { Keymap } from '@prosekit/core';
7
11
  import { LitElement } from 'lit';
8
12
  import { Options } from 'tsup';
13
+ import type { Placement } from '@floating-ui/dom';
9
14
  import { PropertyValues } from 'lit';
10
15
  import { ReactiveController } from 'lit';
11
16
  import { ReactiveControllerHost } from 'lit';
17
+ import type { ReferenceElement } from '@floating-ui/dom';
12
18
  import type { Selection as Selection_2 } from '@prosekit/pm/state';
13
19
  import { TemplateResult } from 'lit';
20
+ import { UpdateHandler } from '@prosekit/core';
14
21
  import { VirtualElement } from '@floating-ui/dom';
15
22
 
16
23
  export declare class AutocompleteEmpty extends LightElement implements AutocompleteEmptyProps {
@@ -135,43 +142,33 @@ export declare class AutocompletePopover extends Popover implements Partial<Auto
135
142
  */
136
143
  static properties: {
137
144
  editor: {
145
+ type: ObjectConstructor;
146
+ reflect: false;
138
147
  attribute: false;
139
148
  };
140
149
  regex: {
141
150
  attribute: false;
142
151
  };
143
- popoverOptions: {
152
+ positioning: {
153
+ type: ObjectConstructor;
154
+ reflect: false;
144
155
  attribute: false;
145
156
  };
146
- onSelect: {
157
+ reference: {
147
158
  attribute: false;
148
159
  };
149
- active: {
160
+ open: {
150
161
  type: BooleanConstructor;
151
- reflect: true;
152
- };
153
- reference: {
162
+ reflect: false;
154
163
  attribute: false;
155
164
  };
156
- options: {
165
+ onOpenChange: {
157
166
  attribute: false;
158
167
  };
159
- autoUpdate: {
160
- type: BooleanConstructor;
161
- reflect: true;
162
- };
163
- autoUpdateOptions: {
164
- type: ObjectConstructor;
165
- };
166
- dismiss: {
167
- type: StringConstructor;
168
- reflect: true;
169
- };
170
168
  };
171
169
  editor?: Editor;
172
170
  regex?: RegExp;
173
- popoverOptions: PopoverOptions;
174
- onSelect?: VoidFunction;
171
+ positioning?: PositioningOptions;
175
172
  private context;
176
173
  private get list();
177
174
  private updateContext;
@@ -215,20 +212,13 @@ export declare class AutocompletePopoverController implements ReactiveController
215
212
  export declare interface AutocompletePopoverProps {
216
213
  editor: Editor;
217
214
  regex: RegExp;
218
- popoverOptions?: PopoverOptions;
215
+ positioning?: PositioningOptions;
219
216
  }
220
217
 
221
218
  export { AutoUpdateOptions }
222
219
 
223
220
  export declare const blockComponentStyles: CSSResult;
224
221
 
225
- /**
226
- * If the browser supports the Popover API, we use the body as the boundary
227
- * since we don't need to worry about the popover overflowing the parent
228
- * element.
229
- */
230
- export declare const boundary: HTMLElement | undefined;
231
-
232
222
  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];
233
223
 
234
224
  /**
@@ -242,26 +232,21 @@ export declare class ComboBox extends Popover {
242
232
  onDismiss: {
243
233
  attribute: false;
244
234
  };
245
- active: {
246
- type: BooleanConstructor;
247
- reflect: true;
248
- };
249
235
  reference: {
250
236
  attribute: false;
251
237
  };
252
- options: {
238
+ open: {
239
+ type: BooleanConstructor;
240
+ reflect: false;
253
241
  attribute: false;
254
242
  };
255
- autoUpdate: {
256
- type: BooleanConstructor;
257
- reflect: true;
243
+ onOpenChange: {
244
+ attribute: false;
258
245
  };
259
- autoUpdateOptions: {
246
+ positioning: {
260
247
  type: ObjectConstructor;
261
- };
262
- dismiss: {
263
- type: StringConstructor;
264
- reflect: true;
248
+ reflect: false;
249
+ attribute: false;
265
250
  };
266
251
  };
267
252
  onDismiss?: VoidFunction;
@@ -405,22 +390,26 @@ export declare const default_alias_1: {
405
390
  };
406
391
 
407
392
  /**
408
- * Default popover options.
393
+ * If the browser supports the Popover API, we use the body as the boundary
394
+ * since we don't need to worry about the popover overflowing the parent
395
+ * element.
409
396
  */
410
- export declare const defaultPopoverOptions: PopoverOptions;
397
+ export declare const defaultBoundary: HTMLElement | undefined;
411
398
 
412
399
  /**
413
- * Default popover options.
400
+ * @internal
414
401
  */
415
- export declare const defaultPopoverOptions_alias_1: PopoverOptions;
416
-
417
- export declare const defaultPopoverOptions_alias_2: PopoverOptions;
402
+ export declare const defaultOptions: PositioningOptions;
418
403
 
419
404
  export declare function defaultQueryBuilder(match: RegExpExecArray): string;
420
405
 
421
406
  export declare function defineCustomElement(name: string, constructor: CustomElementConstructor, options?: ElementDefinitionOptions): void;
422
407
 
423
- export declare function getVirtualSelectionElement(view: EditorView): Range | undefined;
408
+ export declare function getPlacement(reference: ReferenceElement | null, floating: FloatingElement | null, options: PositioningOptions): (() => void) | undefined;
409
+
410
+ export declare function getReferenceContextElement(reference: HTMLElement | VirtualElement | undefined | null): HTMLElement | null;
411
+
412
+ export declare function getVirtualSelectionElement(view: EditorView): ReferenceElement | undefined;
424
413
 
425
414
  export declare class InlinePopover extends Popover implements Partial<InlinePopoverProps> {
426
415
  /**
@@ -430,67 +419,42 @@ export declare class InlinePopover extends Popover implements Partial<InlinePopo
430
419
  editor: {
431
420
  attribute: false;
432
421
  };
433
- popoverOptions: {
422
+ reference: {
434
423
  attribute: false;
435
424
  };
436
- active: {
425
+ open: {
437
426
  type: BooleanConstructor;
438
- reflect: true;
439
- };
440
- reference: {
427
+ reflect: false;
441
428
  attribute: false;
442
429
  };
443
- options: {
430
+ onOpenChange: {
444
431
  attribute: false;
445
432
  };
446
- autoUpdate: {
447
- type: BooleanConstructor;
448
- reflect: true;
449
- };
450
- autoUpdateOptions: {
433
+ positioning: {
451
434
  type: ObjectConstructor;
452
- };
453
- dismiss: {
454
- type: StringConstructor;
455
- reflect: true;
435
+ reflect: false;
436
+ attribute: false;
456
437
  };
457
438
  };
458
439
  editor?: Editor;
459
- popoverOptions: PopoverOptions;
460
- dismiss: "escape";
440
+ positioning?: PositioningOptions;
461
441
  /**
462
442
  * @hidden
463
443
  */
464
- private controller;
444
+ constructor();
465
445
  /**
466
446
  * @hidden
467
447
  */
468
- willUpdate(): void;
448
+ protected updated(changedProperties: PropertyValues<this>): void;
469
449
  /**
470
450
  * @hidden
471
451
  */
472
452
  hide(): void;
473
453
  }
474
454
 
475
- export declare class InlinePopoverController implements ReactiveController {
476
- private host;
477
- reference?: VirtualElement;
478
- private editor?;
479
- private cleanupExtension?;
480
- private cleanupEventListener?;
481
- private mouseHovering;
482
- constructor(host: ReactiveControllerHost);
483
- setEditor(editor: Editor): void;
484
- hostConnected(): void;
485
- hostDisconnected(): void;
486
- private update;
487
- private defineExtension;
488
- }
489
-
490
- export declare interface InlinePopoverProps {
455
+ export declare type InlinePopoverProps = {
491
456
  editor: Editor;
492
- popoverOptions?: PopoverOptions;
493
- }
457
+ } & PopoverProps;
494
458
 
495
459
  export declare function isAutocompleteItem(element?: Element | null): element is AutocompleteItem;
496
460
 
@@ -561,35 +525,61 @@ export declare class Popover extends LightElement implements Partial<PopoverProp
561
525
  * @hidden
562
526
  */
563
527
  static properties: {
564
- active: {
565
- type: BooleanConstructor;
566
- reflect: true;
567
- };
568
528
  reference: {
569
529
  attribute: false;
570
530
  };
571
- options: {
531
+ open: {
532
+ type: BooleanConstructor;
533
+ reflect: false;
572
534
  attribute: false;
573
535
  };
574
- autoUpdate: {
575
- type: BooleanConstructor;
576
- reflect: true;
536
+ onOpenChange: {
537
+ attribute: false;
577
538
  };
578
- autoUpdateOptions: {
539
+ positioning: {
579
540
  type: ObjectConstructor;
580
- };
581
- dismiss: {
582
- type: StringConstructor;
583
- reflect: true;
541
+ reflect: false;
542
+ attribute: false;
584
543
  };
585
544
  };
545
+ reference?: HTMLElement | VirtualElement;
546
+ open?: boolean;
547
+ onOpenChange?: ((open: boolean) => void) | undefined;
548
+ positioning?: PositioningOptions;
586
549
  /**
587
- * Controls the visibility of the popover element. When set to `true`, the
588
- * popover is displayed and positioned relative to its reference element. When
589
- * set to `false`, the popover is hidden and its positioning logic is
590
- * deactivated.
550
+ * @hidden
591
551
  */
592
- active: boolean;
552
+ constructor();
553
+ /**
554
+ * @hidden
555
+ */
556
+ connectedCallback(): void;
557
+ private updatePopoverAttribute;
558
+ private updateDateAttributes;
559
+ /**
560
+ * @hidden
561
+ */
562
+ protected updated(changedProperties: PropertyValues<this>): void;
563
+ /**
564
+ * @hidden
565
+ */
566
+ hide(): void;
567
+ }
568
+
569
+ /**
570
+ * Whether the browser supports the [Popover API](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API).
571
+ */
572
+ export declare const popoverAvailable: boolean;
573
+
574
+ export declare interface PopoverProps {
575
+ /**
576
+ * Whether the popover is open.
577
+ */
578
+ open?: boolean;
579
+ /**
580
+ * Function invoked when the popover opens or closes.
581
+ */
582
+ onOpenChange?: (open: boolean) => void;
593
583
  /**
594
584
  * The element that the popover is anchored to. This can be either a DOM
595
585
  * element or an object that implements the virtual element interface from
@@ -597,105 +587,132 @@ export declare class Popover extends LightElement implements Partial<PopoverProp
597
587
  */
598
588
  reference?: Element | VirtualElement;
599
589
  /**
600
- * The options that are passed to the `computePosition` function from Floating
601
- * UI. These options are used to configure the positioning of the popover
602
- * element relative to its reference element. For more information on the
603
- * available options, please refer to the Floating UI documentation.
590
+ * The user provided options used to position the popover content.
604
591
  */
605
- options?: PopoverOptions;
592
+ positioning?: PositioningOptions;
593
+ }
594
+
595
+ declare const popoverPropsNames: readonly ["open", "onOpenChange", "reference", "positioning"];
596
+ export { popoverPropsNames }
597
+ export { popoverPropsNames as propNames_alias_13 }
598
+
599
+ /**
600
+ * @public
601
+ */
602
+ declare interface PositioningOptions {
606
603
  /**
607
- * Controls whether the popover position is automatically updated when the
608
- * reference element changes position. When set to `true`, the popover
609
- * position is updated automatically. When set to `false`, the popover
610
- * position is only updated when the given properties are changed.
604
+ * The strategy to use for positioning
611
605
  *
612
- * @default false
606
+ * @default 'absolute'
613
607
  */
614
- autoUpdate: boolean;
608
+ strategy?: 'absolute' | 'fixed';
615
609
  /**
616
- * The options that are passed to the `autoUpdate` function from Floating UI.
617
- * These options are used to configure the automatic update behavior of the
618
- * popover position. For more information on the available options, please
619
- * refer to the Floating UI documentation. This property is only used when the
620
- * `autoUpdate` property is set to `true`.
610
+ * The initial placement of the floating element
611
+ *
612
+ * @default 'bottom'
621
613
  */
622
- autoUpdateOptions?: AutoUpdateOptions;
614
+ placement?: Placement;
623
615
  /**
624
- * Controls whether the popover should be dismissed based on user interaction.
616
+ * Options to activate auto-update listeners
625
617
  *
626
- * Available options:
618
+ * @default true
619
+ */
620
+ autoUpdate?: boolean | AutoUpdateOptions;
621
+ /**
622
+ * The virtual padding around the viewport edges to check for overflow
627
623
  *
628
- * - "off": The popover is not dismissed.
629
- * - "on": The popover is dismissed when the user clicks outside of the popover or presses the escape key.
630
- * - "click": The popover is dismissed when the user clicks outside of the popover.
631
- * - "escape": The popover is dismissed when the user presses the escape key.
624
+ * @default 8
625
+ */
626
+ overflowPadding?: number;
627
+ /**
628
+ * Whether to flip the placement
632
629
  *
633
- * @default "on"
630
+ * @default true
634
631
  */
635
- dismiss: 'off' | 'on' | 'click' | 'escape';
632
+ flip?: boolean | Placement[];
636
633
  /**
637
- * @hidden
634
+ * Whether the floating element should shift to keep it in view.
635
+ *
636
+ * @default true
638
637
  */
639
- private disposeAutoUpdate?;
638
+ shift?: boolean;
640
639
  /**
641
- * @hidden
640
+ * Whether the floating element can overlap the reference element
641
+ *
642
+ * @default false
642
643
  */
643
- private disposeEventListeners?;
644
+ overlap?: boolean;
644
645
  /**
645
- * @hidden
646
+ * Whether to improve positioning for inline reference elements that span over
647
+ * multiple lines.
648
+ *
649
+ * @default false
646
650
  */
647
- connectedCallback(): void;
651
+ inline?: boolean;
648
652
  /**
649
- * @hidden
653
+ * Whether to hide the floating element when the reference element is fully clipped.
654
+ *
655
+ * @default true
650
656
  */
651
- disconnectedCallback(): void;
657
+ hide?: boolean;
652
658
  /**
653
- * @hidden
659
+ * Whether to make the floating element same width as the reference element
660
+ *
661
+ * @default false
654
662
  */
655
- protected updated(changedProperties: PropertyValues<this>): void;
663
+ sameWidth?: boolean;
656
664
  /**
657
- * @hidden
665
+ * Whether the popover should fit the viewport.
666
+ *
667
+ * @default false
658
668
  */
659
- private start;
669
+ fitViewport?: boolean;
660
670
  /**
661
- * @hidden
671
+ * The distance between the reference and floating element.
672
+ *
673
+ * @default 8
674
+ */
675
+ offset?: number | {
676
+ mainAxis?: number;
677
+ crossAxis?: number;
678
+ alignmentAxis?: number;
679
+ };
680
+ /**
681
+ * The overflow boundary of the reference element
682
+ *
683
+ * @default undefined
662
684
  */
663
- private compute;
685
+ boundary?: Boundary | (() => Boundary);
664
686
  /**
665
- * @hidden
687
+ * Function called when the placement is computed
688
+ *
689
+ * @default undefined
666
690
  */
667
- hide(): void;
668
- private handleDocumentMouseDown;
669
- private handleDocumentKeyDown;
670
- }
671
-
672
- /**
673
- * Whether the browser supports the [Popover API](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API).
674
- */
675
- export declare const popoverAvailable: boolean;
676
-
677
- /**
678
- * The `PopoverOptions` interface defines the options that can be passed to the
679
- * `computePosition` function from Floating UI. These options are used to
680
- * configure the positioning of the popover element relative to its reference
681
- * element. For more information on the available options, please refer to the
682
- * Floating UI documentation.
683
- *
684
- * https://floating-ui.com/docs/computeposition#options
685
- */
686
- declare type PopoverOptions = ComputePositionConfig;
687
- export { PopoverOptions }
688
- export { PopoverOptions as PopoverOptions_alias_1 }
689
- export { PopoverOptions as PopoverOptions_alias_2 }
690
- export { PopoverOptions as PopoverOptions_alias_3 }
691
-
692
- export declare interface PopoverProps {
693
- active: boolean;
694
- reference?: Element | VirtualElement;
695
- options?: PopoverOptions;
696
- autoUpdate?: boolean;
697
- autoUpdateOptions?: AutoUpdateOptions;
691
+ onComplete?(data: ComputePositionReturn): void;
692
+ /**
693
+ * Function called on cleanup of all listeners
694
+ *
695
+ * @default undefined
696
+ */
697
+ onCleanup?: VoidFunction;
698
+ /**
699
+ * Function called when the escape key is down. By default, the popover is
700
+ * hidden when the escape key is down. It can be prevented by calling
701
+ * `event.preventDefault`.
702
+ */
703
+ onEscapeKeyDown?: (event: KeyboardEvent) => void;
704
+ /**
705
+ * Function called when when pointer down event happens outside of the
706
+ * popover. By default, the popover is hidden when the pointer down event
707
+ * happens outside of the popover. It can be prevented by calling
708
+ * `event.preventDefault`.
709
+ */
710
+ onPointerDownOutside?: (event: Event) => void;
698
711
  }
712
+ export { PositioningOptions }
713
+ export { PositioningOptions as PositioningOptions_alias_1 }
714
+ export { PositioningOptions as PositioningOptions_alias_2 }
715
+ export { PositioningOptions as PositioningOptions_alias_3 }
699
716
 
700
717
  /**
701
718
  * @internal
@@ -738,11 +755,9 @@ declare const propNames_7: readonly [];
738
755
  export { propNames_7 as propNames_alias_16 }
739
756
  export { propNames_7 as propNames_alias_17 }
740
757
 
741
- export declare const propNames_alias_12: readonly ["editor", "popoverOptions"];
742
-
743
- export declare const propNames_alias_13: readonly ["active", "reference", "options", "autoUpdate", "autoUpdateOptions"];
758
+ export declare const propNames_alias_12: readonly ["editor", "open", "onOpenChange", "reference", "positioning"];
744
759
 
745
- export declare const propNames_alias_5: readonly ["editor", "regex", "popoverOptions"];
760
+ export declare const propNames_alias_5: readonly ["editor", "regex", "positioning"];
746
761
 
747
762
  /**
748
763
  * @internal
@@ -787,6 +802,10 @@ declare class Resizable extends LightElement implements Partial<ResizableProps>
787
802
  reflect: true;
788
803
  };
789
804
  };
805
+ /**
806
+ * @hidden
807
+ */
808
+ constructor();
790
809
  width?: number | string;
791
810
  height?: number | string;
792
811
  aspectRatio?: number;
@@ -806,7 +825,6 @@ declare class Resizable extends LightElement implements Partial<ResizableProps>
806
825
  width: number;
807
826
  height: number;
808
827
  }) => void;
809
- private context;
810
828
  private startWidth;
811
829
  private startHeight;
812
830
  private handleResizeStart;
@@ -902,4 +920,31 @@ export { ResizableProps as ResizableProps_alias_1 }
902
920
  /** Rounds a value to the nearest device pixel ratio. */
903
921
  export declare function roundByDPR(value: number): number;
904
922
 
923
+ export declare function setFloatingStyles(element: HTMLElement, options: PositioningOptions): void;
924
+
925
+ export declare function useDismissable(host: LitElement, { onEscapeKeyDown, onPointerDownOutside, onDismiss, getReference, }: {
926
+ onEscapeKeyDown: (event: KeyboardEvent) => void;
927
+ onPointerDownOutside: (event: Event) => void;
928
+ onDismiss?: VoidFunction;
929
+ getReference?: () => ReferenceElement | null | undefined;
930
+ }): void;
931
+
932
+ export declare function useEditorExtension(host: WithEditor<ReactiveControllerHost>, extension: Extension): void;
933
+
934
+ export declare function useEditorFocusChangeEvent(host: WithEditor<ReactiveControllerHost>, handler: FocusChangeHandler): void;
935
+
936
+ export declare function useEditorUpdateEvent(host: WithEditor<ReactiveControllerHost>, handler: UpdateHandler): void;
937
+
938
+ export declare function useEffect<T>(host: ReactiveControllerHost, getValue: () => T, onChange: (value: T) => void): void;
939
+
940
+ export declare function useInlinePopover(host: WithEditor<LitElement>, onReferenceChange: (reference: ReferenceElement | undefined) => void): () => ReferenceElement | undefined;
941
+
942
+ export declare function usePointerDownEvent(host: LitElement, handler: (event: PointerEvent) => void): void;
943
+
944
+ export declare function usePopover(host: LitElement, getReference: () => ReferenceElement | null, getPositioning: () => PositioningOptions | null): void;
945
+
946
+ export declare type WithEditor<T> = T & {
947
+ editor?: Editor | undefined | null;
948
+ };
949
+
905
950
  export { }