@prosekit/lit 0.1.3 → 0.1.5

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,14 +1,17 @@
1
1
  import {
2
2
  LightElement,
3
- __decorateClass
4
- } from "./chunk-O5JP3B34.js";
3
+ defineCustomElement
4
+ } from "./chunk-S32IZIQF.js";
5
5
 
6
6
  // src/components/popover/index.ts
7
7
  import {
8
8
  autoUpdate,
9
9
  computePosition
10
10
  } from "@floating-ui/dom";
11
- import { customElement, property } from "lit/decorators.js";
11
+
12
+ // src/utils/popover-api.ts
13
+ var popoverAvailable = typeof HTMLElement !== "undefined" && HTMLElement.prototype.hasOwnProperty("popover");
14
+ var boundary = popoverAvailable && typeof document !== "undefined" && document.body || void 0;
12
15
 
13
16
  // src/utils/round-by-dpr.ts
14
17
  function roundByDPR(value) {
@@ -17,17 +20,25 @@ function roundByDPR(value) {
17
20
  }
18
21
 
19
22
  // src/components/popover/default-popover-options.ts
20
- import { offset, shift, size } from "@floating-ui/dom";
23
+ import {
24
+ offset,
25
+ shift,
26
+ size
27
+ } from "@floating-ui/dom";
21
28
 
22
29
  // src/components/popover/options.ts
23
30
  import "@floating-ui/dom";
24
31
 
25
32
  // src/components/popover/default-popover-options.ts
33
+ var defaultDetectOverflowOptions = {
34
+ padding: 8,
35
+ boundary
36
+ };
26
37
  var defaultPopoverOptions = {
27
38
  placement: "bottom",
28
39
  middleware: [
29
40
  offset({ mainAxis: 8, crossAxis: 8 }),
30
- shift({ padding: 8 }),
41
+ shift({ ...defaultDetectOverflowOptions }),
31
42
  size({
32
43
  apply: ({ availableWidth, availableHeight, elements }) => {
33
44
  elements.floating.style.setProperty(
@@ -39,7 +50,7 @@ var defaultPopoverOptions = {
39
50
  `${Math.floor(availableHeight)}px`
40
51
  );
41
52
  },
42
- padding: 8
53
+ ...defaultDetectOverflowOptions
43
54
  })
44
55
  ]
45
56
  };
@@ -53,11 +64,36 @@ var propNames = [
53
64
  "autoUpdateOptions"
54
65
  ];
55
66
  var Popover = class extends LightElement {
56
- /** @hidden */
57
67
  constructor() {
58
- super();
68
+ super(...arguments);
69
+ /**
70
+ * Controls the visibility of the popover element. When set to `true`, the
71
+ * popover is displayed and positioned relative to its reference element. When
72
+ * set to `false`, the popover is hidden and its positioning logic is
73
+ * deactivated.
74
+ */
59
75
  this.active = false;
76
+ /**
77
+ * Controls whether the popover position is automatically updated when the
78
+ * reference element changes position. When set to `true`, the popover
79
+ * position is updated automatically. When set to `false`, the popover
80
+ * position is only updated when the given properties are changed.
81
+ *
82
+ * @default false
83
+ */
60
84
  this.autoUpdate = false;
85
+ /**
86
+ * Controls whether the popover should be dismissed based on user interaction.
87
+ *
88
+ * Available options:
89
+ *
90
+ * - "off": The popover is not dismissed.
91
+ * - "on": The popover is dismissed when the user clicks outside of the popover or presses the escape key.
92
+ * - "click": The popover is dismissed when the user clicks outside of the popover.
93
+ * - "escape": The popover is dismissed when the user presses the escape key.
94
+ *
95
+ * @default "on"
96
+ */
61
97
  this.dismiss = "on";
62
98
  this.handleDocumentMouseDown = (event) => {
63
99
  const path = event.composedPath();
@@ -73,7 +109,9 @@ var Popover = class extends LightElement {
73
109
  }
74
110
  };
75
111
  }
76
- /** @hidden */
112
+ /**
113
+ * @hidden
114
+ */
77
115
  connectedCallback() {
78
116
  super.connectedCallback();
79
117
  const clickEnabled = this.dismiss === "on" || this.dismiss === "click";
@@ -87,7 +125,9 @@ var Popover = class extends LightElement {
87
125
  handleKeyDown && document.removeEventListener("keydown", handleKeyDown);
88
126
  };
89
127
  }
90
- /** @hidden */
128
+ /**
129
+ * @hidden
130
+ */
91
131
  disconnectedCallback() {
92
132
  var _a, _b;
93
133
  super.disconnectedCallback();
@@ -96,13 +136,22 @@ var Popover = class extends LightElement {
96
136
  (_b = this.disposeEventListeners) == null ? void 0 : _b.call(this);
97
137
  this.disposeEventListeners = void 0;
98
138
  }
99
- /** @hidden */
139
+ /**
140
+ * @hidden
141
+ */
100
142
  updated(changedProperties) {
143
+ var _a;
101
144
  super.updated(changedProperties);
145
+ if (popoverAvailable && this.isConnected) {
146
+ this.popover = "manual";
147
+ (_a = this.togglePopover) == null ? void 0 : _a.call(this, this.active);
148
+ }
102
149
  this.start();
103
150
  this.setHidden(!this.active);
104
151
  }
105
- /** @hidden */
152
+ /**
153
+ * @hidden
154
+ */
106
155
  start() {
107
156
  var _a;
108
157
  (_a = this.disposeAutoUpdate) == null ? void 0 : _a.call(this);
@@ -123,7 +172,9 @@ var Popover = class extends LightElement {
123
172
  void this.compute();
124
173
  }
125
174
  }
126
- /** @hidden */
175
+ /**
176
+ * @hidden
177
+ */
127
178
  async compute() {
128
179
  var _a, _b, _c;
129
180
  const reference = this.reference;
@@ -132,6 +183,7 @@ var Popover = class extends LightElement {
132
183
  if (!this.active)
133
184
  return;
134
185
  this.setHidden(false);
186
+ this.style.setProperty("margin", "0");
135
187
  this.style.setProperty("top", "0");
136
188
  this.style.setProperty("left", "0");
137
189
  this.style.setProperty("position", (_b = (_a = this.options) == null ? void 0 : _a.strategy) != null ? _b : "absolute");
@@ -145,40 +197,28 @@ var Popover = class extends LightElement {
145
197
  `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`
146
198
  );
147
199
  }
148
- /** @hidden */
200
+ /**
201
+ * @hidden
202
+ */
149
203
  hide() {
150
204
  this.active = false;
151
205
  }
152
206
  };
153
- __decorateClass([
154
- property({ type: Boolean, reflect: true })
155
- ], Popover.prototype, "active", 2);
156
- __decorateClass([
157
- property({ attribute: false })
158
- ], Popover.prototype, "reference", 2);
159
- __decorateClass([
160
- property({ attribute: false })
161
- ], Popover.prototype, "options", 2);
162
- __decorateClass([
163
- property({
164
- type: Boolean,
165
- reflect: true
166
- })
167
- ], Popover.prototype, "autoUpdate", 2);
168
- __decorateClass([
169
- property({ type: Object })
170
- ], Popover.prototype, "autoUpdateOptions", 2);
171
- __decorateClass([
172
- property({
173
- type: String,
174
- reflect: true
175
- })
176
- ], Popover.prototype, "dismiss", 2);
177
- Popover = __decorateClass([
178
- customElement("prosekit-popover")
179
- ], Popover);
207
+ /**
208
+ * @hidden
209
+ */
210
+ Popover.properties = {
211
+ active: { type: Boolean, reflect: true },
212
+ reference: { attribute: false },
213
+ options: { attribute: false },
214
+ autoUpdate: { type: Boolean, reflect: true },
215
+ autoUpdateOptions: { type: Object },
216
+ dismiss: { type: String, reflect: true }
217
+ };
218
+ defineCustomElement("prosekit-popover", Popover);
180
219
 
181
220
  export {
221
+ boundary,
182
222
  propNames,
183
223
  Popover
184
224
  };
@@ -0,0 +1,60 @@
1
+ import {
2
+ autocompleteListContext
3
+ } from "./chunk-5CI65R73.js";
4
+ import {
5
+ LightElement,
6
+ defineCustomElement
7
+ } from "./chunk-S32IZIQF.js";
8
+
9
+ // src/components/autocomplete-item/component.ts
10
+ import { ContextConsumer } from "@lit/context";
11
+ import "lit";
12
+ var propNames = ["value", "onSelect"];
13
+ var AutocompleteItem = class extends LightElement {
14
+ constructor() {
15
+ super(...arguments);
16
+ this.listContext = new ContextConsumer(this, {
17
+ context: autocompleteListContext,
18
+ subscribe: true
19
+ });
20
+ this.value = "";
21
+ this.selected = false;
22
+ }
23
+ get content() {
24
+ const text = this.value || this.textContent || "";
25
+ return text.trim().toLowerCase();
26
+ }
27
+ connectedCallback() {
28
+ super.connectedCallback();
29
+ this.role = "option";
30
+ }
31
+ willUpdate() {
32
+ var _a, _b;
33
+ const content = this.content;
34
+ const score = ((_a = this.listContext.value) == null ? void 0 : _a.scores.get(content)) || 0;
35
+ const hidden = score <= 0;
36
+ this.selected = !hidden && content === ((_b = this.listContext.value) == null ? void 0 : _b.selectedValue);
37
+ this.setHidden(hidden);
38
+ }
39
+ updated(changedProperties) {
40
+ var _a;
41
+ this.ariaSelected = String(this.selected);
42
+ if (this.selected && changedProperties.has("selected") && !changedProperties.get("selected") && ((_a = this.listContext.value) == null ? void 0 : _a.selectedReason) === "keyboard") {
43
+ this.scrollIntoView({ block: "nearest" });
44
+ }
45
+ }
46
+ };
47
+ /**
48
+ * @hidden
49
+ */
50
+ AutocompleteItem.properties = {
51
+ value: { type: String, reflect: true, attribute: "data-value" },
52
+ selected: { type: Boolean, reflect: true, attribute: "data-selected" },
53
+ onSelect: { attribute: false }
54
+ };
55
+ defineCustomElement("prosekit-autocomplete-item", AutocompleteItem);
56
+
57
+ export {
58
+ propNames,
59
+ AutocompleteItem
60
+ };
@@ -0,0 +1,33 @@
1
+ // src/utils/define-custom-element.ts
2
+ function defineCustomElement(name, constructor, options) {
3
+ if (typeof customElements === "undefined") {
4
+ return;
5
+ }
6
+ customElements.define(name, constructor, options);
7
+ }
8
+
9
+ // src/components/block-element/index.ts
10
+ import { LitElement } from "lit";
11
+ var LightElement = class extends LitElement {
12
+ /**
13
+ * @hidden
14
+ */
15
+ constructor() {
16
+ super();
17
+ }
18
+ createRenderRoot() {
19
+ return this;
20
+ }
21
+ setHidden(hidden) {
22
+ if (this.hidden !== hidden) {
23
+ this.hidden = hidden;
24
+ const display = this.style.display;
25
+ this.style.display = hidden ? "none" : display === "none" ? "" : display;
26
+ }
27
+ }
28
+ };
29
+
30
+ export {
31
+ defineCustomElement,
32
+ LightElement
33
+ };
@@ -1,25 +1,24 @@
1
1
  import {
2
- commandListContext
3
- } from "./chunk-6P3YKUWI.js";
2
+ autocompleteListContext
3
+ } from "./chunk-5CI65R73.js";
4
4
  import {
5
5
  ListManager
6
- } from "./chunk-IDDQA3VV.js";
6
+ } from "./chunk-GZRUCYLP.js";
7
7
  import {
8
8
  LightElement,
9
- __decorateClass
10
- } from "./chunk-O5JP3B34.js";
9
+ defineCustomElement
10
+ } from "./chunk-S32IZIQF.js";
11
11
 
12
12
  // src/components/autocomplete-popover/context.ts
13
13
  import { createContext } from "@lit/context";
14
- var commandPopoverContext = createContext(
14
+ var autocompletePopoverContext = createContext(
15
15
  "prosekit-autocomplete-popover-context"
16
16
  );
17
17
 
18
18
  // src/components/autocomplete-list/component.ts
19
- import { consume, provide } from "@lit/context";
19
+ import { ContextConsumer, ContextProvider } from "@lit/context";
20
20
  import "@prosekit/core";
21
21
  import "lit";
22
- import { customElement, property, state } from "lit/decorators.js";
23
22
 
24
23
  // src/utils/command-score.ts
25
24
  import commandScoreModule from "@superhuman/command-score";
@@ -87,41 +86,51 @@ var propNames = ["editor"];
87
86
  var AutocompleteList = class extends LightElement {
88
87
  constructor() {
89
88
  super(...arguments);
90
- /** @hidden */
89
+ /**
90
+ * @hidden
91
+ */
91
92
  this.listManager = new ListManager({
92
93
  getItems: () => this.items,
93
- getSelectedValue: () => this.context.selectedValue,
94
+ getSelectedValue: () => this.context.value.selectedValue,
94
95
  setSelectedValue: (value, reason) => this.updateValue(value, reason),
95
96
  getItemValue: (item) => item.content,
96
97
  queryClosestItem: queryClosestAutocompleteItem,
97
98
  getActive: () => this.active,
98
99
  onDismiss: () => {
99
100
  var _a, _b;
100
- return (_b = (_a = this.popoverContext) == null ? void 0 : _a.handleDismiss) == null ? void 0 : _b.call(_a);
101
+ return (_b = (_a = this.popoverContext.value) == null ? void 0 : _a.handleDismiss) == null ? void 0 : _b.call(_a);
101
102
  },
102
103
  onSelect: (item) => {
103
104
  var _a, _b, _c;
104
- (_b = (_a = this.popoverContext) == null ? void 0 : _a.handleSubmit) == null ? void 0 : _b.call(_a);
105
+ (_b = (_a = this.popoverContext.value) == null ? void 0 : _a.handleSubmit) == null ? void 0 : _b.call(_a);
105
106
  (_c = item == null ? void 0 : item.onSelect) == null ? void 0 : _c.call(item);
106
107
  }
107
108
  });
108
- /** @hidden */
109
+ /**
110
+ * @hidden
111
+ */
109
112
  this.controller = new AutocompleteListController(this, {
110
113
  ArrowUp: () => this.listManager.handleArrowUp(),
111
114
  ArrowDown: () => this.listManager.handleArrowDown(),
112
115
  Escape: () => this.listManager.handleEscape(),
113
116
  Enter: () => this.listManager.handleEnter()
114
117
  });
115
- this.popoverContext = null;
116
- this.context = {
117
- scores: /* @__PURE__ */ new Map(),
118
- selectedValue: "",
119
- selectedReason: "keyboard"
120
- };
118
+ this.popoverContext = new ContextConsumer(this, {
119
+ context: autocompletePopoverContext,
120
+ subscribe: true
121
+ });
122
+ this.context = new ContextProvider(this, {
123
+ context: autocompleteListContext,
124
+ initialValue: {
125
+ scores: /* @__PURE__ */ new Map(),
126
+ selectedValue: "",
127
+ selectedReason: "keyboard"
128
+ }
129
+ });
121
130
  }
122
131
  get active() {
123
132
  var _a, _b;
124
- return (_b = (_a = this.popoverContext) == null ? void 0 : _a.active) != null ? _b : false;
133
+ return (_b = (_a = this.popoverContext.value) == null ? void 0 : _a.active) != null ? _b : false;
125
134
  }
126
135
  connectedCallback() {
127
136
  super.connectedCallback();
@@ -148,18 +157,21 @@ var AutocompleteList = class extends LightElement {
148
157
  this.listManager.selectFirstItem();
149
158
  }
150
159
  updateValue(selectedValue, selectedReason) {
151
- if (this.context.selectedValue === selectedValue) {
160
+ const context = this.context.value;
161
+ if (context.selectedValue === selectedValue) {
152
162
  return;
153
163
  }
154
- this.context = { ...this.context, selectedValue, selectedReason };
164
+ this.context.setValue({ ...context, selectedValue, selectedReason });
155
165
  }
156
- /** @hidden */
166
+ /**
167
+ * @hidden
168
+ */
157
169
  willUpdate(changedProperties) {
158
170
  var _a, _b;
159
171
  if (changedProperties.has("editor") && this.editor) {
160
172
  this.controller.setEditor(this.editor);
161
173
  }
162
- const query = (_b = (_a = this.popoverContext) == null ? void 0 : _a.query) != null ? _b : "";
174
+ const query = (_b = (_a = this.popoverContext.value) == null ? void 0 : _a.query) != null ? _b : "";
163
175
  const scores = new Map(
164
176
  this.items.map((item) => {
165
177
  const content = item.content;
@@ -167,26 +179,20 @@ var AutocompleteList = class extends LightElement {
167
179
  return [content, score];
168
180
  })
169
181
  );
170
- this.context = { ...this.context, scores };
182
+ const context = this.context.value;
183
+ this.context.setValue({ ...context, scores });
171
184
  }
172
185
  };
173
- __decorateClass([
174
- property({ attribute: false })
175
- ], AutocompleteList.prototype, "editor", 2);
176
- __decorateClass([
177
- consume({ context: commandPopoverContext, subscribe: true }),
178
- state()
179
- ], AutocompleteList.prototype, "popoverContext", 2);
180
- __decorateClass([
181
- provide({ context: commandListContext }),
182
- state()
183
- ], AutocompleteList.prototype, "context", 2);
184
- AutocompleteList = __decorateClass([
185
- customElement("prosekit-autocomplete-list")
186
- ], AutocompleteList);
186
+ /**
187
+ * @hidden
188
+ */
189
+ AutocompleteList.properties = {
190
+ editor: { attribute: false }
191
+ };
192
+ defineCustomElement("prosekit-autocomplete-list", AutocompleteList);
187
193
 
188
194
  export {
189
- commandPopoverContext,
195
+ autocompletePopoverContext,
190
196
  propNames,
191
197
  AutocompleteList
192
198
  };
@@ -1,24 +1,30 @@
1
1
  import {
2
- commandListContext
3
- } from "./chunk-6P3YKUWI.js";
2
+ autocompleteListContext
3
+ } from "./chunk-5CI65R73.js";
4
4
  import {
5
5
  LightElement,
6
- __decorateClass
7
- } from "./chunk-O5JP3B34.js";
6
+ defineCustomElement
7
+ } from "./chunk-S32IZIQF.js";
8
8
 
9
9
  // src/components/autocomplete-empty/index.ts
10
- import { consume } from "@lit/context";
10
+ import { ContextConsumer } from "@lit/context";
11
11
  import "lit";
12
- import { customElement, state } from "lit/decorators.js";
13
12
  var propNames = [];
14
13
  var AutocompleteEmpty = class extends LightElement {
14
+ constructor() {
15
+ super(...arguments);
16
+ this.listContext = new ContextConsumer(this, {
17
+ context: autocompleteListContext,
18
+ subscribe: true
19
+ });
20
+ }
15
21
  connectedCallback() {
16
22
  super.connectedCallback();
17
23
  this.role = "option";
18
24
  }
19
25
  willUpdate(_changedProperties) {
20
26
  var _a;
21
- const scores = (_a = this.listContext) == null ? void 0 : _a.scores;
27
+ const scores = (_a = this.listContext.value) == null ? void 0 : _a.scores;
22
28
  let hasMatch = false;
23
29
  if (scores) {
24
30
  for (const score of scores.values()) {
@@ -31,13 +37,7 @@ var AutocompleteEmpty = class extends LightElement {
31
37
  this.setHidden(hasMatch);
32
38
  }
33
39
  };
34
- __decorateClass([
35
- consume({ context: commandListContext, subscribe: true }),
36
- state()
37
- ], AutocompleteEmpty.prototype, "listContext", 2);
38
- AutocompleteEmpty = __decorateClass([
39
- customElement("prosekit-autocomplete-empty")
40
- ], AutocompleteEmpty);
40
+ defineCustomElement("prosekit-autocomplete-empty", AutocompleteEmpty);
41
41
  export {
42
42
  AutocompleteEmpty,
43
43
  propNames
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  AutocompleteItem,
3
3
  propNames
4
- } from "./chunk-M6MY5WGM.js";
5
- import "./chunk-6P3YKUWI.js";
6
- import "./chunk-O5JP3B34.js";
4
+ } from "./chunk-MLUELLVA.js";
5
+ import "./chunk-5CI65R73.js";
6
+ import "./chunk-S32IZIQF.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-66YTZIW6.js";
5
- import "./chunk-M6MY5WGM.js";
6
- import "./chunk-6P3YKUWI.js";
7
- import "./chunk-IDDQA3VV.js";
8
- import "./chunk-O5JP3B34.js";
4
+ } from "./chunk-WWRKI6AU.js";
5
+ import "./chunk-MLUELLVA.js";
6
+ import "./chunk-5CI65R73.js";
7
+ import "./chunk-GZRUCYLP.js";
8
+ import "./chunk-S32IZIQF.js";
9
9
  export {
10
10
  AutocompleteList,
11
11
  propNames