@prosekit/lit 0.2.0 → 0.2.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.
@@ -419,6 +419,9 @@ export declare class InlinePopover extends Popover implements Partial<InlinePopo
419
419
  editor: {
420
420
  attribute: false;
421
421
  };
422
+ available: {
423
+ attribute: false;
424
+ };
422
425
  reference: {
423
426
  attribute: false;
424
427
  };
@@ -437,6 +440,7 @@ export declare class InlinePopover extends Popover implements Partial<InlinePopo
437
440
  };
438
441
  };
439
442
  editor?: Editor;
443
+ available?: boolean;
440
444
  positioning?: PositioningOptions;
441
445
  /**
442
446
  * @hidden
@@ -454,6 +458,15 @@ export declare class InlinePopover extends Popover implements Partial<InlinePopo
454
458
 
455
459
  export declare type InlinePopoverProps = {
456
460
  editor: Editor;
461
+ /**
462
+ * Whether the popover is available to be shown.
463
+ *
464
+ * If `true`, the popover will be shown when the editor selection is not empty.
465
+ * If `false`, the popover will always be hidden.
466
+ *
467
+ * @default `true`
468
+ */
469
+ available?: boolean;
457
470
  } & PopoverProps;
458
471
 
459
472
  export declare function isAutocompleteItem(element?: Element | null): element is AutocompleteItem;
@@ -473,7 +486,13 @@ export declare class LightElement extends LitElement {
473
486
  * @hidden
474
487
  */
475
488
  constructor();
489
+ /**
490
+ * @hidden
491
+ */
476
492
  createRenderRoot(): this;
493
+ /**
494
+ * @hidden
495
+ */
477
496
  setHidden(hidden: boolean): void;
478
497
  }
479
498
 
@@ -755,7 +774,7 @@ declare const propNames_7: readonly [];
755
774
  export { propNames_7 as propNames_alias_16 }
756
775
  export { propNames_7 as propNames_alias_17 }
757
776
 
758
- export declare const propNames_alias_12: readonly ["editor", "open", "onOpenChange", "reference", "positioning"];
777
+ export declare const propNames_alias_12: readonly ["editor", "available", "open", "onOpenChange", "reference", "positioning"];
759
778
 
760
779
  export declare const propNames_alias_5: readonly ["editor", "regex", "positioning"];
761
780
 
@@ -922,6 +941,9 @@ export declare function roundByDPR(value: number): number;
922
941
 
923
942
  export declare function setFloatingStyles(element: HTMLElement, options: PositioningOptions): void;
924
943
 
944
+ /**
945
+ * @internal
946
+ */
925
947
  export declare function useDismissable(host: LitElement, { onEscapeKeyDown, onPointerDownOutside, onDismiss, getReference, }: {
926
948
  onEscapeKeyDown: (event: KeyboardEvent) => void;
927
949
  onPointerDownOutside: (event: Event) => void;
@@ -929,16 +951,34 @@ export declare function useDismissable(host: LitElement, { onEscapeKeyDown, onPo
929
951
  getReference?: () => ReferenceElement | null | undefined;
930
952
  }): void;
931
953
 
954
+ /**
955
+ * @internal
956
+ */
932
957
  export declare function useEditorExtension(host: WithEditor<ReactiveControllerHost>, extension: Extension): void;
933
958
 
959
+ /**
960
+ * @internal
961
+ */
934
962
  export declare function useEditorFocusChangeEvent(host: WithEditor<ReactiveControllerHost>, handler: FocusChangeHandler): void;
935
963
 
964
+ /**
965
+ * @internal
966
+ */
936
967
  export declare function useEditorUpdateEvent(host: WithEditor<ReactiveControllerHost>, handler: UpdateHandler): void;
937
968
 
969
+ /**
970
+ * @internal
971
+ */
938
972
  export declare function useEffect<T>(host: ReactiveControllerHost, getValue: () => T, onChange: (value: T) => void): void;
939
973
 
974
+ /**
975
+ * @internal
976
+ */
940
977
  export declare function useInlinePopover(host: WithEditor<LitElement>, onReferenceChange: (reference: ReferenceElement | undefined) => void): () => ReferenceElement | undefined;
941
978
 
979
+ /**
980
+ * @internal
981
+ */
942
982
  export declare function usePointerDownEvent(host: LitElement, handler: (event: PointerEvent) => void): void;
943
983
 
944
984
  export declare function usePopover(host: LitElement, getReference: () => ReferenceElement | null, getPositioning: () => PositioningOptions | null): void;
@@ -15,9 +15,15 @@ var LightElement = class extends LitElement {
15
15
  constructor() {
16
16
  super();
17
17
  }
18
+ /**
19
+ * @hidden
20
+ */
18
21
  createRenderRoot() {
19
22
  return this;
20
23
  }
24
+ /**
25
+ * @hidden
26
+ */
21
27
  setHidden(hidden) {
22
28
  if (this.hidden !== hidden) {
23
29
  this.hidden = hidden;
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  LightElement,
6
6
  defineCustomElement
7
- } from "./chunk-S32IZIQF.js";
7
+ } from "./chunk-3AZDRLDR.js";
8
8
 
9
9
  // src/components/combo-box-item/component.ts
10
10
  import { ContextConsumer } from "@lit/context";
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  LightElement,
6
6
  defineCustomElement
7
- } from "./chunk-S32IZIQF.js";
7
+ } from "./chunk-3AZDRLDR.js";
8
8
 
9
9
  // src/components/autocomplete-item/component.ts
10
10
  import { ContextConsumer } from "@lit/context";
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  LightElement,
9
9
  defineCustomElement
10
- } from "./chunk-S32IZIQF.js";
10
+ } from "./chunk-3AZDRLDR.js";
11
11
 
12
12
  // src/components/autocomplete-popover/context.ts
13
13
  import { createContext } from "@lit/context";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  LightElement,
3
3
  defineCustomElement
4
- } from "./chunk-S32IZIQF.js";
4
+ } from "./chunk-3AZDRLDR.js";
5
5
 
6
6
  // src/components/popover/index.ts
7
7
  import "@floating-ui/dom";
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  LightElement,
6
6
  defineCustomElement
7
- } from "./chunk-S32IZIQF.js";
7
+ } from "./chunk-3AZDRLDR.js";
8
8
 
9
9
  // src/components/autocomplete-empty/index.ts
10
10
  import { ContextConsumer } from "@lit/context";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  AutocompleteItem,
3
3
  propNames
4
- } from "./chunk-MLUELLVA.js";
4
+ } from "./chunk-I5EMQRE4.js";
5
5
  import "./chunk-5CI65R73.js";
6
- import "./chunk-S32IZIQF.js";
6
+ import "./chunk-3AZDRLDR.js";
7
7
  export {
8
8
  AutocompleteItem,
9
9
  propNames
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  AutocompleteList,
3
3
  propNames
4
- } from "./chunk-WWRKI6AU.js";
5
- import "./chunk-MLUELLVA.js";
4
+ } from "./chunk-JMZWTLTD.js";
5
+ import "./chunk-I5EMQRE4.js";
6
6
  import "./chunk-5CI65R73.js";
7
7
  import "./chunk-GZRUCYLP.js";
8
- import "./chunk-S32IZIQF.js";
8
+ import "./chunk-3AZDRLDR.js";
9
9
  export {
10
10
  AutocompleteList,
11
11
  propNames
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  autocompletePopoverContext
3
- } from "./chunk-WWRKI6AU.js";
4
- import "./chunk-MLUELLVA.js";
3
+ } from "./chunk-JMZWTLTD.js";
4
+ import "./chunk-I5EMQRE4.js";
5
5
  import "./chunk-5CI65R73.js";
6
6
  import {
7
7
  Popover
8
- } from "./chunk-OZUEYWYU.js";
8
+ } from "./chunk-YOZJWJGG.js";
9
9
  import "./chunk-GZRUCYLP.js";
10
10
  import {
11
11
  defineCustomElement
12
- } from "./chunk-S32IZIQF.js";
12
+ } from "./chunk-3AZDRLDR.js";
13
13
 
14
14
  // src/components/autocomplete-popover/index.ts
15
15
  import { ContextProvider } from "@lit/context";
@@ -144,10 +144,11 @@ var AutocompletePopover = class extends Popover {
144
144
  }
145
145
  updateContext(query, active) {
146
146
  const context = this.context.value;
147
- if (context.query === query && context.active === active) {
147
+ if (context.query !== query || context.active !== active) {
148
+ this.context.setValue({ ...context, query, active });
149
+ } else if (!active) {
148
150
  return;
149
151
  }
150
- this.context.setValue({ ...context, query, active });
151
152
  this.requestUpdate();
152
153
  requestAnimationFrame(() => {
153
154
  var _a;
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  LightElement,
6
6
  defineCustomElement
7
- } from "./chunk-S32IZIQF.js";
7
+ } from "./chunk-3AZDRLDR.js";
8
8
 
9
9
  // src/components/combo-box-input/index.ts
10
10
  import { ContextConsumer } from "@lit/context";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  ComboBoxItem,
3
3
  propNames
4
- } from "./chunk-7RGGPFFK.js";
4
+ } from "./chunk-3TPE2GKD.js";
5
5
  import "./chunk-C4MW43I4.js";
6
- import "./chunk-S32IZIQF.js";
6
+ import "./chunk-3AZDRLDR.js";
7
7
  export {
8
8
  ComboBoxItem,
9
9
  propNames
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  LightElement,
6
6
  defineCustomElement
7
- } from "./chunk-S32IZIQF.js";
7
+ } from "./chunk-3AZDRLDR.js";
8
8
 
9
9
  // src/components/combo-box-list/component.ts
10
10
  import { ContextConsumer } from "@lit/context";
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  Popover
3
- } from "./chunk-OZUEYWYU.js";
3
+ } from "./chunk-YOZJWJGG.js";
4
4
  import {
5
5
  ListManager
6
6
  } from "./chunk-GZRUCYLP.js";
7
- import "./chunk-7RGGPFFK.js";
7
+ import "./chunk-3TPE2GKD.js";
8
8
  import {
9
9
  comboBoxContext
10
10
  } from "./chunk-C4MW43I4.js";
11
11
  import {
12
12
  defineCustomElement
13
- } from "./chunk-S32IZIQF.js";
13
+ } from "./chunk-3AZDRLDR.js";
14
14
 
15
15
  // src/components/combo-box/index.ts
16
16
  import { ContextProvider } from "@lit/context";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  Popover,
3
3
  popoverPropsNames
4
- } from "./chunk-OZUEYWYU.js";
4
+ } from "./chunk-YOZJWJGG.js";
5
5
  import {
6
6
  defineCustomElement
7
- } from "./chunk-S32IZIQF.js";
7
+ } from "./chunk-3AZDRLDR.js";
8
8
 
9
9
  // src/components/inline-popover/index.ts
10
10
  import "@prosekit/core";
@@ -58,19 +58,7 @@ function useEditorUpdateEvent(host, handler) {
58
58
  useEditorExtension(host, extension);
59
59
  }
60
60
 
61
- // src/controllers/use-pointer-down-event.ts
62
- function usePointerDownEvent(host, handler) {
63
- host.addController({
64
- hostConnected: () => {
65
- host.addEventListener("pointerdown", handler);
66
- },
67
- hostDisconnected: () => {
68
- host.removeEventListener("pointerdown", handler);
69
- }
70
- });
71
- }
72
-
73
- // src/components/inline-popover/helpers.ts
61
+ // src/components/inline-popover/virtual-selection-element.ts
74
62
  import { isNodeSelection, isTextSelection } from "@prosekit/core";
75
63
 
76
64
  // src/utils/is-in-code-block.ts
@@ -79,21 +67,25 @@ function isInCodeBlock(selection) {
79
67
  return type.spec.code && type.isBlock;
80
68
  }
81
69
 
82
- // src/components/inline-popover/helpers.ts
70
+ // src/components/inline-popover/virtual-selection-element.ts
83
71
  function getVirtualSelectionElement(view) {
84
72
  if (typeof window === "undefined" || view.isDestroyed) {
85
73
  return;
86
74
  }
87
75
  const selection = view.state.selection;
88
76
  if (!selection.empty && !isInCodeBlock(selection) && (isTextSelection(selection) || isNodeSelection(selection))) {
77
+ const decoration = getInlineDecoration(view);
78
+ if (decoration) {
79
+ return decoration;
80
+ }
89
81
  const range = getDomRange();
90
- if (!range)
91
- return;
92
- return {
93
- contextElement: view.dom,
94
- getBoundingClientRect: () => range.getBoundingClientRect(),
95
- getClientRects: () => range.getClientRects()
96
- };
82
+ if (range) {
83
+ return {
84
+ contextElement: view.dom,
85
+ getBoundingClientRect: () => range.getBoundingClientRect(),
86
+ getClientRects: () => range.getClientRects()
87
+ };
88
+ }
97
89
  }
98
90
  }
99
91
  function getDomRange() {
@@ -107,23 +99,35 @@ function getDomRange() {
107
99
  }
108
100
  return range;
109
101
  }
102
+ function getInlineDecoration(view) {
103
+ const match = view.dom.querySelectorAll(".prosekit-virtual-selection");
104
+ if (match.length === 0) {
105
+ return;
106
+ }
107
+ if (match.length === 1) {
108
+ return match[0];
109
+ }
110
+ const items = Array.from(match);
111
+ return {
112
+ contextElement: items[0],
113
+ getBoundingClientRect: () => items[0].getBoundingClientRect(),
114
+ getClientRects: () => items.map((item) => item.getBoundingClientRect())
115
+ };
116
+ }
110
117
 
111
118
  // src/components/inline-popover/use-inline-popover.ts
112
119
  function useInlinePopover(host, onReferenceChange) {
113
- let interacting = false;
114
120
  let reference;
115
- usePointerDownEvent(host, () => {
116
- interacting = true;
117
- });
121
+ let editorFocused = false;
122
+ const isPopoverFocused = () => {
123
+ return !editorFocused && host.contains(host.ownerDocument.activeElement);
124
+ };
118
125
  useEditorFocusChangeEvent(host, (focus) => {
119
- if (focus) {
120
- interacting = false;
121
- }
126
+ editorFocused = focus;
122
127
  });
123
128
  useEditorUpdateEvent(host, (view) => {
124
- if (interacting) {
129
+ if (isPopoverFocused())
125
130
  return;
126
- }
127
131
  const ref = getVirtualSelectionElement(view);
128
132
  if (reference !== ref) {
129
133
  reference = ref;
@@ -136,13 +140,14 @@ function useInlinePopover(host, onReferenceChange) {
136
140
  }
137
141
 
138
142
  // src/components/inline-popover/index.ts
139
- var propNames = ["editor", ...popoverPropsNames];
143
+ var propNames = ["editor", "available", ...popoverPropsNames];
140
144
  var InlinePopover = class extends Popover {
141
145
  /**
142
146
  * @hidden
143
147
  */
144
148
  constructor() {
145
149
  super();
150
+ this.available = true;
146
151
  this.positioning = {
147
152
  strategy: "fixed",
148
153
  placement: "top",
@@ -163,7 +168,7 @@ var InlinePopover = class extends Popover {
163
168
  */
164
169
  updated(changedProperties) {
165
170
  super.updated(changedProperties);
166
- this.open = !!this.reference;
171
+ this.open = !!(this.reference && this.available);
167
172
  }
168
173
  /**
169
174
  * @hidden
@@ -178,7 +183,8 @@ var InlinePopover = class extends Popover {
178
183
  */
179
184
  InlinePopover.properties = {
180
185
  ...Popover.properties,
181
- editor: { attribute: false }
186
+ editor: { attribute: false },
187
+ available: { attribute: false }
182
188
  };
183
189
  defineCustomElement("prosekit-inline-popover", InlinePopover);
184
190
  export {
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  Popover,
3
3
  popoverPropsNames
4
- } from "./chunk-OZUEYWYU.js";
5
- import "./chunk-S32IZIQF.js";
4
+ } from "./chunk-YOZJWJGG.js";
5
+ import "./chunk-3AZDRLDR.js";
6
6
  export {
7
7
  Popover,
8
8
  popoverPropsNames,
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  LightElement,
6
6
  defineCustomElement
7
- } from "./chunk-S32IZIQF.js";
7
+ } from "./chunk-3AZDRLDR.js";
8
8
 
9
9
  // src/components/resizable-handle/component.ts
10
10
  import { ContextConsumer } from "@lit/context";
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  LightElement,
6
6
  defineCustomElement
7
- } from "./chunk-S32IZIQF.js";
7
+ } from "./chunk-3AZDRLDR.js";
8
8
 
9
9
  // src/components/resizable/component.ts
10
10
  import { ContextProvider } from "@lit/context";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/lit",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.2.2",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -95,23 +95,23 @@
95
95
  "dist"
96
96
  ],
97
97
  "dependencies": {
98
- "@floating-ui/dom": "^1.5.3",
98
+ "@floating-ui/dom": "^1.6.1",
99
99
  "@lit/context": "^1.1.0",
100
- "@prosekit/core": "^0.2.4",
101
- "@prosekit/extensions": "^0.2.4",
100
+ "@prosekit/core": "^0.3.0",
101
+ "@prosekit/extensions": "^0.3.0",
102
102
  "@prosekit/pm": "^0.1.1",
103
103
  "@superhuman/command-score": "^0.5.0",
104
- "@zag-js/dismissable": "^0.32.0",
105
- "@zag-js/dom-query": "^0.32.0",
106
- "@zag-js/utils": "^0.32.0",
107
- "lit": "^3.1.1"
104
+ "@zag-js/dismissable": "^0.34.0",
105
+ "@zag-js/dom-query": "^0.34.0",
106
+ "@zag-js/utils": "^0.34.0",
107
+ "lit": "^3.1.2"
108
108
  },
109
109
  "devDependencies": {
110
110
  "@prosekit/dev": "*",
111
111
  "minify-literals": "^1.0.8",
112
112
  "tsup": "^8.0.1",
113
113
  "typescript": "^5.3.3",
114
- "vitest": "^1.2.0"
114
+ "vitest": "^1.2.2"
115
115
  },
116
116
  "scripts": {
117
117
  "build:tsup": "tsup",
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export {}