@prosekit/lit 0.2.1 → 0.2.3

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
 
@@ -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";
@@ -119,6 +119,7 @@ var AutocompletePopover = class extends Popover {
119
119
  this.positioning = {
120
120
  strategy: "fixed",
121
121
  placement: "bottom-start",
122
+ fitViewport: true,
122
123
  flip: false,
123
124
  inline: true
124
125
  };
@@ -144,10 +145,11 @@ var AutocompletePopover = class extends Popover {
144
145
  }
145
146
  updateContext(query, active) {
146
147
  const context = this.context.value;
147
- if (context.query === query && context.active === active) {
148
+ if (context.query !== query || context.active !== active) {
149
+ this.context.setValue({ ...context, query, active });
150
+ } else if (!active) {
148
151
  return;
149
152
  }
150
- this.context.setValue({ ...context, query, active });
151
153
  this.requestUpdate();
152
154
  requestAnimationFrame(() => {
153
155
  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,7 +58,7 @@ function useEditorUpdateEvent(host, handler) {
58
58
  useEditorExtension(host, extension);
59
59
  }
60
60
 
61
- // src/components/inline-popover/helpers.ts
61
+ // src/components/inline-popover/virtual-selection-element.ts
62
62
  import { isNodeSelection, isTextSelection } from "@prosekit/core";
63
63
 
64
64
  // src/utils/is-in-code-block.ts
@@ -67,21 +67,25 @@ function isInCodeBlock(selection) {
67
67
  return type.spec.code && type.isBlock;
68
68
  }
69
69
 
70
- // src/components/inline-popover/helpers.ts
70
+ // src/components/inline-popover/virtual-selection-element.ts
71
71
  function getVirtualSelectionElement(view) {
72
72
  if (typeof window === "undefined" || view.isDestroyed) {
73
73
  return;
74
74
  }
75
75
  const selection = view.state.selection;
76
76
  if (!selection.empty && !isInCodeBlock(selection) && (isTextSelection(selection) || isNodeSelection(selection))) {
77
+ const decoration = getInlineDecoration(view);
78
+ if (decoration) {
79
+ return decoration;
80
+ }
77
81
  const range = getDomRange();
78
- if (!range)
79
- return;
80
- return {
81
- contextElement: view.dom,
82
- getBoundingClientRect: () => range.getBoundingClientRect(),
83
- getClientRects: () => range.getClientRects()
84
- };
82
+ if (range) {
83
+ return {
84
+ contextElement: view.dom,
85
+ getBoundingClientRect: () => range.getBoundingClientRect(),
86
+ getClientRects: () => range.getClientRects()
87
+ };
88
+ }
85
89
  }
86
90
  }
87
91
  function getDomRange() {
@@ -95,6 +99,21 @@ function getDomRange() {
95
99
  }
96
100
  return range;
97
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
+ }
98
117
 
99
118
  // src/components/inline-popover/use-inline-popover.ts
100
119
  function useInlinePopover(host, onReferenceChange) {
@@ -121,13 +140,14 @@ function useInlinePopover(host, onReferenceChange) {
121
140
  }
122
141
 
123
142
  // src/components/inline-popover/index.ts
124
- var propNames = ["editor", ...popoverPropsNames];
143
+ var propNames = ["editor", "available", ...popoverPropsNames];
125
144
  var InlinePopover = class extends Popover {
126
145
  /**
127
146
  * @hidden
128
147
  */
129
148
  constructor() {
130
149
  super();
150
+ this.available = true;
131
151
  this.positioning = {
132
152
  strategy: "fixed",
133
153
  placement: "top",
@@ -136,7 +156,7 @@ var InlinePopover = class extends Popover {
136
156
  hide: true,
137
157
  shift: true,
138
158
  overlap: true,
139
- fitViewport: false,
159
+ fitViewport: true,
140
160
  inline: true
141
161
  };
142
162
  useInlinePopover(this, (reference) => {
@@ -148,7 +168,7 @@ var InlinePopover = class extends Popover {
148
168
  */
149
169
  updated(changedProperties) {
150
170
  super.updated(changedProperties);
151
- this.open = !!this.reference;
171
+ this.open = !!(this.reference && this.available);
152
172
  }
153
173
  /**
154
174
  * @hidden
@@ -163,7 +183,8 @@ var InlinePopover = class extends Popover {
163
183
  */
164
184
  InlinePopover.properties = {
165
185
  ...Popover.properties,
166
- editor: { attribute: false }
186
+ editor: { attribute: false },
187
+ available: { attribute: false }
167
188
  };
168
189
  defineCustomElement("prosekit-inline-popover", InlinePopover);
169
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.1",
4
+ "version": "0.2.3",
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.4",
98
+ "@floating-ui/dom": "^1.6.1",
99
99
  "@lit/context": "^1.1.0",
100
- "@prosekit/core": "^0.2.6",
101
- "@prosekit/extensions": "^0.2.5",
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.1",
105
- "@zag-js/dom-query": "^0.32.1",
106
- "@zag-js/utils": "^0.32.1",
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.1"
114
+ "vitest": "^1.2.2"
115
115
  },
116
116
  "scripts": {
117
117
  "build:tsup": "tsup",