@prosekit/lit 0.2.8 → 0.3.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.
Files changed (53) hide show
  1. package/dist/_tsup-dts-rollup.d.ts +24 -1111
  2. package/dist/prosekit-lit-autocomplete.d.ts +4 -0
  3. package/dist/prosekit-lit-autocomplete.js +11 -0
  4. package/dist/prosekit-lit-block-handle.d.ts +2 -0
  5. package/dist/prosekit-lit-block-handle.js +7 -0
  6. package/dist/prosekit-lit-inline-popover.d.ts +0 -3
  7. package/dist/prosekit-lit-inline-popover.js +2 -191
  8. package/dist/prosekit-lit-popover.d.ts +3 -6
  9. package/dist/prosekit-lit-popover.js +7 -9
  10. package/dist/prosekit-lit-resizable.d.ts +2 -3
  11. package/dist/prosekit-lit-resizable.js +5 -110
  12. package/dist/prosekit-lit-tooltip.d.ts +3 -0
  13. package/dist/prosekit-lit-tooltip.js +9 -0
  14. package/package.json +24 -121
  15. package/dist/chunk-5CI65R73.js +0 -9
  16. package/dist/chunk-7E5POS6D.js +0 -53
  17. package/dist/chunk-BFBBTEVM.js +0 -204
  18. package/dist/chunk-C4MW43I4.js +0 -9
  19. package/dist/chunk-FKSZFUL3.js +0 -371
  20. package/dist/chunk-LCDA7GFP.js +0 -11
  21. package/dist/chunk-MZAHIYA5.js +0 -114
  22. package/dist/chunk-S72UTR5M.js +0 -9
  23. package/dist/chunk-UIHDPY7W.js +0 -30
  24. package/dist/chunk-VPUV5WUG.js +0 -62
  25. package/dist/chunk-WEUGKLVB.js +0 -9
  26. package/dist/prosekit-lit-autocomplete-empty.d.ts +0 -3
  27. package/dist/prosekit-lit-autocomplete-empty.js +0 -46
  28. package/dist/prosekit-lit-autocomplete-item.d.ts +0 -3
  29. package/dist/prosekit-lit-autocomplete-item.js +0 -11
  30. package/dist/prosekit-lit-autocomplete-list.d.ts +0 -3
  31. package/dist/prosekit-lit-autocomplete-list.js +0 -13
  32. package/dist/prosekit-lit-autocomplete-popover.d.ts +0 -4
  33. package/dist/prosekit-lit-autocomplete-popover.js +0 -200
  34. package/dist/prosekit-lit-block-popover.d.ts +0 -3
  35. package/dist/prosekit-lit-block-popover.js +0 -170
  36. package/dist/prosekit-lit-combo-box-input.d.ts +0 -3
  37. package/dist/prosekit-lit-combo-box-input.js +0 -94
  38. package/dist/prosekit-lit-combo-box-item.d.ts +0 -3
  39. package/dist/prosekit-lit-combo-box-item.js +0 -11
  40. package/dist/prosekit-lit-combo-box-list.d.ts +0 -3
  41. package/dist/prosekit-lit-combo-box-list.js +0 -46
  42. package/dist/prosekit-lit-combo-box.d.ts +0 -3
  43. package/dist/prosekit-lit-combo-box.js +0 -131
  44. package/dist/prosekit-lit-drag-handle.d.ts +0 -3
  45. package/dist/prosekit-lit-drag-handle.js +0 -96
  46. package/dist/prosekit-lit-popover-content.d.ts +0 -3
  47. package/dist/prosekit-lit-popover-content.js +0 -17
  48. package/dist/prosekit-lit-popover-root.d.ts +0 -3
  49. package/dist/prosekit-lit-popover-root.js +0 -17
  50. package/dist/prosekit-lit-popover-trigger.d.ts +0 -3
  51. package/dist/prosekit-lit-popover-trigger.js +0 -12
  52. package/dist/prosekit-lit-resizable-handle.d.ts +0 -3
  53. package/dist/prosekit-lit-resizable-handle.js +0 -161
@@ -1,204 +0,0 @@
1
- import {
2
- autocompleteListContext
3
- } from "./chunk-5CI65R73.js";
4
- import {
5
- ListManager
6
- } from "./chunk-MZAHIYA5.js";
7
- import {
8
- LightElement
9
- } from "./chunk-UIHDPY7W.js";
10
- import {
11
- defineCustomElement
12
- } from "./chunk-LCDA7GFP.js";
13
-
14
- // src/components/autocomplete-popover/context.ts
15
- import { createContext } from "@lit/context";
16
- var autocompletePopoverContext = createContext(
17
- "prosekit-autocomplete-popover-context"
18
- );
19
-
20
- // src/components/autocomplete-list/component.ts
21
- import { ContextConsumer, ContextProvider } from "@lit/context";
22
- import "@prosekit/core";
23
- import "lit";
24
-
25
- // src/utils/command-score.ts
26
- import commandScoreModule from "@superhuman/command-score";
27
- var commandScore = commandScoreModule;
28
-
29
- // src/components/autocomplete-item/helpers.ts
30
- function isAutocompleteItem(element) {
31
- var _a;
32
- return ((_a = element == null ? void 0 : element.tagName) == null ? void 0 : _a.toLowerCase()) === "prosekit-autocomplete-item";
33
- }
34
- function queryClosestAutocompleteItem(element) {
35
- if (!element) {
36
- return null;
37
- }
38
- if (isAutocompleteItem(element)) {
39
- return element;
40
- }
41
- const item = element.closest("prosekit-autocomplete-item");
42
- if (isAutocompleteItem(item)) {
43
- return item;
44
- }
45
- return null;
46
- }
47
-
48
- // src/components/autocomplete-list/controller.ts
49
- import {
50
- defineKeymap,
51
- withPriority,
52
- Priority
53
- } from "@prosekit/core";
54
- import "lit";
55
- var AutocompleteListController = class {
56
- constructor(host, keymap) {
57
- this.host = host;
58
- this.keymap = keymap;
59
- this.editor = null;
60
- this.cleanup = null;
61
- this.host.addController(this);
62
- }
63
- setEditor(editor) {
64
- if (this.editor !== editor) {
65
- this.editor = editor;
66
- this.defineExtension();
67
- }
68
- }
69
- hostDisconnected() {
70
- var _a;
71
- (_a = this.cleanup) == null ? void 0 : _a.call(this);
72
- this.cleanup = null;
73
- }
74
- defineExtension() {
75
- var _a;
76
- (_a = this.cleanup) == null ? void 0 : _a.call(this);
77
- this.cleanup = null;
78
- if (!this.editor || !this.keymap) {
79
- return;
80
- }
81
- const extension = withPriority(defineKeymap(this.keymap), Priority.highest);
82
- this.cleanup = this.editor.use(extension);
83
- }
84
- };
85
-
86
- // src/components/autocomplete-list/component.ts
87
- var propNames = ["editor"];
88
- var AutocompleteList = class extends LightElement {
89
- constructor() {
90
- super(...arguments);
91
- /**
92
- * @hidden
93
- */
94
- this.listManager = new ListManager({
95
- getItems: () => this.items,
96
- getSelectedValue: () => this.context.value.selectedValue,
97
- setSelectedValue: (value, reason) => this.updateValue(value, reason),
98
- getItemValue: (item) => item.content,
99
- queryClosestItem: queryClosestAutocompleteItem,
100
- getActive: () => this.active,
101
- onDismiss: () => {
102
- var _a, _b;
103
- return (_b = (_a = this.popoverContext.value) == null ? void 0 : _a.handleDismiss) == null ? void 0 : _b.call(_a);
104
- },
105
- onSelect: (item) => {
106
- var _a, _b;
107
- if (item == null ? void 0 : item.onSelect) {
108
- (_b = (_a = this.popoverContext.value) == null ? void 0 : _a.handleSubmit) == null ? void 0 : _b.call(_a);
109
- item.onSelect();
110
- return true;
111
- }
112
- return false;
113
- }
114
- });
115
- /**
116
- * @hidden
117
- */
118
- this.controller = new AutocompleteListController(this, {
119
- ArrowUp: () => this.listManager.handleArrowUp(),
120
- ArrowDown: () => this.listManager.handleArrowDown(),
121
- Escape: () => this.listManager.handleEscape(),
122
- Enter: () => this.listManager.handleEnter()
123
- });
124
- this.popoverContext = new ContextConsumer(this, {
125
- context: autocompletePopoverContext,
126
- subscribe: true
127
- });
128
- this.context = new ContextProvider(this, {
129
- context: autocompleteListContext,
130
- initialValue: {
131
- scores: /* @__PURE__ */ new Map(),
132
- selectedValue: "",
133
- selectedReason: "keyboard"
134
- }
135
- });
136
- }
137
- get active() {
138
- var _a, _b;
139
- return (_b = (_a = this.popoverContext.value) == null ? void 0 : _a.active) != null ? _b : false;
140
- }
141
- connectedCallback() {
142
- super.connectedCallback();
143
- this.listManager.selectFirstItem();
144
- this.addEventListener("mousemove", (event) => {
145
- this.listManager.handleMouseMove(event);
146
- });
147
- this.addEventListener("mouseover", (event) => {
148
- this.listManager.handleMouseOver(event);
149
- });
150
- this.addEventListener("mousedown", (event) => {
151
- this.listManager.handleMouseDown(event);
152
- });
153
- this.addEventListener("click", (event) => {
154
- this.listManager.handleClick(event);
155
- });
156
- }
157
- get items() {
158
- return Array.from(
159
- this.querySelectorAll("prosekit-autocomplete-item")
160
- ).filter(isAutocompleteItem);
161
- }
162
- selectFirstItem() {
163
- this.listManager.selectFirstItem();
164
- }
165
- updateValue(selectedValue, selectedReason) {
166
- const context = this.context.value;
167
- if (context.selectedValue === selectedValue) {
168
- return;
169
- }
170
- this.context.setValue({ ...context, selectedValue, selectedReason });
171
- }
172
- /**
173
- * @hidden
174
- */
175
- willUpdate(changedProperties) {
176
- var _a, _b;
177
- if (changedProperties.has("editor") && this.editor) {
178
- this.controller.setEditor(this.editor);
179
- }
180
- const query = (_b = (_a = this.popoverContext.value) == null ? void 0 : _a.query) != null ? _b : "";
181
- const scores = new Map(
182
- this.items.map((item) => {
183
- const content = item.content;
184
- const score = commandScore(content, query);
185
- return [content, score];
186
- })
187
- );
188
- const context = this.context.value;
189
- this.context.setValue({ ...context, scores });
190
- }
191
- };
192
- /**
193
- * @hidden
194
- */
195
- AutocompleteList.properties = {
196
- editor: { attribute: false }
197
- };
198
- defineCustomElement("prosekit-autocomplete-list", AutocompleteList);
199
-
200
- export {
201
- autocompletePopoverContext,
202
- propNames,
203
- AutocompleteList
204
- };
@@ -1,9 +0,0 @@
1
- // src/components/combo-box/context.ts
2
- import { createContext } from "@lit/context";
3
- var comboBoxContext = createContext(
4
- "prosekit-combo-box-context"
5
- );
6
-
7
- export {
8
- comboBoxContext
9
- };
@@ -1,371 +0,0 @@
1
- import {
2
- LightElement
3
- } from "./chunk-UIHDPY7W.js";
4
- import {
5
- defineCustomElement
6
- } from "./chunk-LCDA7GFP.js";
7
-
8
- // src/components/popover/index.ts
9
- import "@floating-ui/dom";
10
-
11
- // src/controllers/use-dismissable.ts
12
- import { trackDismissableElement } from "@zag-js/dismissable";
13
-
14
- // src/utils/get-reference-context-element.ts
15
- import { isHTMLElement } from "@zag-js/dom-query";
16
- function getReferenceContextElement(reference) {
17
- if (!reference) {
18
- return null;
19
- }
20
- if (isHTMLElement(reference)) {
21
- return reference;
22
- }
23
- const contextElement = reference.contextElement;
24
- if (isHTMLElement(contextElement)) {
25
- return contextElement;
26
- }
27
- return null;
28
- }
29
-
30
- // src/controllers/use-dismissable.ts
31
- function useDismissable(host, {
32
- onEscapeKeyDown,
33
- onPointerDownOutside,
34
- onDismiss,
35
- getReference
36
- }) {
37
- let cleanup;
38
- const hostConnected = () => {
39
- cleanup == null ? void 0 : cleanup();
40
- cleanup = trackDismissableElement(host, {
41
- defer: false,
42
- pointerBlocking: false,
43
- exclude: () => {
44
- return getReferenceContextElement(getReference == null ? void 0 : getReference());
45
- },
46
- onDismiss: () => {
47
- onDismiss == null ? void 0 : onDismiss();
48
- },
49
- onEscapeKeyDown: (event) => {
50
- onEscapeKeyDown(event);
51
- },
52
- onPointerDownOutside: (event) => {
53
- onPointerDownOutside(event);
54
- }
55
- });
56
- };
57
- const hostDisconnected = () => {
58
- cleanup == null ? void 0 : cleanup();
59
- cleanup = void 0;
60
- };
61
- host.addController({ hostConnected, hostDisconnected });
62
- }
63
-
64
- // src/controllers/use-effect.ts
65
- function useEffect(host, getValue, onChange) {
66
- let value = getValue();
67
- const hostUpdated = () => {
68
- const v = getValue();
69
- if (v !== value) {
70
- value = v;
71
- onChange(value);
72
- }
73
- };
74
- host.addController({ hostUpdated });
75
- }
76
-
77
- // src/utils/popover-api.ts
78
- var popoverAvailable = typeof HTMLElement !== "undefined" && HTMLElement.prototype.hasOwnProperty("popover");
79
- var defaultBoundary = popoverAvailable && typeof document !== "undefined" && document.body || void 0;
80
-
81
- // src/components/popover/get-placement.ts
82
- import {
83
- autoUpdate,
84
- computePosition,
85
- flip,
86
- hide,
87
- inline,
88
- offset,
89
- shift,
90
- size
91
- } from "@floating-ui/dom";
92
- import { getWindow } from "@zag-js/dom-query";
93
- import { runIfFn } from "@zag-js/utils";
94
- function dpr(win, value) {
95
- const dpr2 = win.devicePixelRatio || 1;
96
- return Math.round(value * dpr2) / dpr2;
97
- }
98
- function _boundary(opts) {
99
- return runIfFn(opts.boundary);
100
- }
101
- function _offset(opts) {
102
- if (opts.offset == null)
103
- return;
104
- return offset(opts.offset);
105
- }
106
- function _flip(opts) {
107
- if (!opts.flip)
108
- return;
109
- return flip({
110
- boundary: _boundary(opts),
111
- padding: opts.overflowPadding,
112
- altBoundary: true,
113
- fallbackPlacements: opts.flip === true ? void 0 : opts.flip
114
- });
115
- }
116
- function _shift(opts) {
117
- if (!opts.shift)
118
- return;
119
- return shift({
120
- boundary: _boundary(opts),
121
- padding: opts.overflowPadding,
122
- altBoundary: true,
123
- mainAxis: opts.shift,
124
- crossAxis: opts.overlap
125
- });
126
- }
127
- function _size(opts) {
128
- return size({
129
- boundary: _boundary(opts),
130
- padding: opts.overflowPadding,
131
- altBoundary: true,
132
- apply({ elements, rects, availableHeight, availableWidth }) {
133
- const floating = elements.floating;
134
- const referenceWidth = Math.round(rects.reference.width);
135
- availableWidth = Math.floor(availableWidth);
136
- availableHeight = Math.floor(availableHeight);
137
- floating.style.setProperty("--reference-width", `${referenceWidth}px`);
138
- floating.style.setProperty("--available-width", `${availableWidth}px`);
139
- floating.style.setProperty("--available-height", `${availableHeight}px`);
140
- }
141
- });
142
- }
143
- function _inline(opts) {
144
- if (!opts.inline)
145
- return;
146
- return inline();
147
- }
148
- function _hide(opts) {
149
- if (!opts.hide)
150
- return;
151
- return hide({
152
- padding: opts.overflowPadding,
153
- elementContext: "reference"
154
- });
155
- }
156
- function getPlacement(reference, floating, options) {
157
- if (!floating || !reference)
158
- return;
159
- const middleware = [
160
- _offset(options),
161
- _flip(options),
162
- _shift(options),
163
- _size(options),
164
- _inline(options),
165
- _hide(options)
166
- ];
167
- const { placement, strategy } = options;
168
- const update = async () => {
169
- var _a, _b, _c;
170
- if (!reference || !floating)
171
- return;
172
- const pos = await computePosition(reference, floating, {
173
- placement,
174
- middleware,
175
- strategy
176
- });
177
- const hidden = ((_a = pos.middlewareData.hide) == null ? void 0 : _a.escaped) || ((_b = pos.middlewareData.hide) == null ? void 0 : _b.referenceHidden);
178
- (_c = options.onComplete) == null ? void 0 : _c.call(options, pos);
179
- const win = getWindow(floating);
180
- const x = dpr(win, pos.x);
181
- const y = dpr(win, pos.y);
182
- floating.style.setProperty("--x", `${x}px`);
183
- floating.style.setProperty("--y", `${y}px`);
184
- floating.style.setProperty("opacity", hidden ? "0" : "1");
185
- const contentEl = floating.firstElementChild;
186
- if (contentEl) {
187
- const zIndex = win.getComputedStyle(contentEl).zIndex;
188
- floating.style.setProperty("--z-index", zIndex);
189
- }
190
- };
191
- const autoUpdateOptions = typeof options.autoUpdate === "boolean" ? void 0 : options.autoUpdate;
192
- const cancelAutoUpdate = options.autoUpdate ? autoUpdate(reference, floating, update, autoUpdateOptions) : void 0;
193
- void update();
194
- return () => {
195
- var _a;
196
- cancelAutoUpdate == null ? void 0 : cancelAutoUpdate();
197
- (_a = options.onCleanup) == null ? void 0 : _a.call(options);
198
- };
199
- }
200
-
201
- // src/components/popover/options.ts
202
- var defaultOptions = {
203
- strategy: "absolute",
204
- placement: "bottom",
205
- autoUpdate: true,
206
- overflowPadding: 10,
207
- flip: true,
208
- shift: true,
209
- overlap: false,
210
- inline: false,
211
- hide: true,
212
- sameWidth: false,
213
- fitViewport: false,
214
- offset: 8,
215
- boundary: defaultBoundary
216
- };
217
-
218
- // src/components/popover/set-floating-styles.ts
219
- function setFloatingStyles(element, options) {
220
- const { placement, sameWidth, fitViewport, strategy = "absolute" } = options;
221
- element.style.position = strategy;
222
- element.style.isolation = "isolate";
223
- element.style.minWidth = sameWidth ? "" : "max-content";
224
- element.style.width = sameWidth ? "var(--reference-width)" : "";
225
- element.style.maxWidth = fitViewport ? "var(--available-width)" : "";
226
- element.style.maxHeight = fitViewport ? "var(--available-height)" : "";
227
- element.style.top = "0px";
228
- element.style.left = "0px";
229
- element.style.transform = placement ? "translate3d(var(--x), var(--y), 0)" : "translate3d(0, -100vh, 0)";
230
- element.style.zIndex = "var(--z-index)";
231
- }
232
-
233
- // src/components/popover/use-popover.ts
234
- function usePopover(host, getReference, getPositioning) {
235
- let cleanup;
236
- const hostUpdated = () => {
237
- const reference = getReference();
238
- const positioning = { ...defaultOptions, ...getPositioning() };
239
- cleanup == null ? void 0 : cleanup();
240
- cleanup = getPlacement(reference, host, {
241
- ...positioning,
242
- onComplete: (data) => {
243
- var _a;
244
- (_a = positioning == null ? void 0 : positioning.onComplete) == null ? void 0 : _a.call(positioning, data);
245
- setFloatingStyles(host, { ...positioning, placement: data.placement });
246
- }
247
- });
248
- };
249
- const hostDisconnected = () => {
250
- cleanup == null ? void 0 : cleanup();
251
- cleanup = void 0;
252
- };
253
- host.addController({ hostUpdated, hostDisconnected });
254
- }
255
-
256
- // src/components/popover/index.ts
257
- var popoverPropsNames = [
258
- "open",
259
- "onOpenChange",
260
- "reference",
261
- "positioning"
262
- ];
263
- var Popover = class extends LightElement {
264
- /**
265
- * @hidden
266
- */
267
- constructor() {
268
- super();
269
- this.elevated = true;
270
- useDismissable(this, {
271
- onPointerDownOutside: (event) => {
272
- var _a, _b;
273
- (_b = (_a = this.positioning) == null ? void 0 : _a.onPointerDownOutside) == null ? void 0 : _b.call(_a, event);
274
- if (!event.defaultPrevented) {
275
- this.requestUpdate();
276
- }
277
- },
278
- onEscapeKeyDown: (event) => {
279
- var _a, _b;
280
- (_b = (_a = this.positioning) == null ? void 0 : _a.onEscapeKeyDown) == null ? void 0 : _b.call(_a, event);
281
- if (!event.defaultPrevented) {
282
- this.requestUpdate();
283
- }
284
- },
285
- getReference: () => {
286
- return this.reference;
287
- }
288
- });
289
- useEffect(
290
- this,
291
- () => {
292
- var _a;
293
- return (_a = this.open) != null ? _a : false;
294
- },
295
- (open) => {
296
- var _a;
297
- return (_a = this.onOpenChange) == null ? void 0 : _a.call(this, open);
298
- }
299
- );
300
- usePopover(
301
- this,
302
- () => {
303
- var _a;
304
- return (_a = this.reference) != null ? _a : null;
305
- },
306
- () => {
307
- var _a;
308
- return (_a = this.positioning) != null ? _a : null;
309
- }
310
- );
311
- }
312
- /**
313
- * @hidden
314
- */
315
- connectedCallback() {
316
- super.connectedCallback();
317
- this.tabIndex = -1;
318
- this.role = "dialog";
319
- this.updatePopoverAttribute();
320
- this.updateDateAttributes();
321
- }
322
- updatePopoverAttribute() {
323
- var _a;
324
- if (!popoverAvailable) {
325
- return;
326
- }
327
- if (!this.elevated)
328
- return;
329
- this.setAttribute("popover", "manual");
330
- (_a = this.showPopover) == null ? void 0 : _a.call(this);
331
- this.style.setProperty("margin", "unset");
332
- }
333
- updateDateAttributes() {
334
- this.setAttribute("data-state", this.open ? "open" : "closed");
335
- if (this.open) {
336
- this.setAttribute("data-expanded", "");
337
- } else {
338
- this.removeAttribute("data-expanded");
339
- }
340
- }
341
- /**
342
- * @hidden
343
- */
344
- updated(changedProperties) {
345
- super.updated(changedProperties);
346
- this.setHidden(!this.open);
347
- this.updateDateAttributes();
348
- }
349
- /**
350
- * @hidden
351
- */
352
- hide() {
353
- this.open = false;
354
- }
355
- };
356
- /**
357
- * @hidden
358
- */
359
- Popover.properties = {
360
- reference: { attribute: false },
361
- open: { type: Boolean, reflect: false, attribute: false },
362
- onOpenChange: { attribute: false },
363
- positioning: { type: Object, reflect: false, attribute: false },
364
- elevated: { type: Boolean, reflect: false, attribute: false }
365
- };
366
- defineCustomElement("prosekit-popover", Popover);
367
-
368
- export {
369
- popoverPropsNames,
370
- Popover
371
- };
@@ -1,11 +0,0 @@
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
- export {
10
- defineCustomElement
11
- };
@@ -1,114 +0,0 @@
1
- // src/manager/list-manager.ts
2
- var ListManager = class {
3
- constructor(options) {
4
- this.lastMouseMoveTime = 0;
5
- this.getItems = options.getItems;
6
- this.getSelectedValue = options.getSelectedValue;
7
- this.setSelectedValue = options.setSelectedValue;
8
- this.getItemValue = options.getItemValue;
9
- this.queryClosestItem = options.queryClosestItem;
10
- this.getActive = options.getActive;
11
- this.onDismiss = options.onDismiss;
12
- this.onSelect = options.onSelect;
13
- }
14
- get items() {
15
- return this.getItems();
16
- }
17
- get active() {
18
- return this.getActive();
19
- }
20
- get availableItems() {
21
- var _a, _b;
22
- return (_b = (_a = this.items) == null ? void 0 : _a.filter((item) => !item.hidden)) != null ? _b : [];
23
- }
24
- get firstItem() {
25
- var _a;
26
- return (_a = this.availableItems[0]) != null ? _a : null;
27
- }
28
- get selectedItem() {
29
- var _a;
30
- return (_a = this.availableItems.find(
31
- (item) => this.getItemValue(item) === this.getSelectedValue()
32
- )) != null ? _a : null;
33
- }
34
- updateSelectedByChange(change) {
35
- const items = this.availableItems;
36
- if (items.length === 0) {
37
- return;
38
- }
39
- const selectedItem = this.selectedItem;
40
- const selectedIndex = selectedItem ? items.indexOf(selectedItem) : -1;
41
- let nextIndex = selectedIndex + change;
42
- if (nextIndex < 0) {
43
- nextIndex = 0;
44
- } else if (nextIndex >= items.length) {
45
- nextIndex = items.length - 1;
46
- }
47
- if (selectedIndex !== nextIndex) {
48
- this.setSelectedValue(this.getItemValue(items[nextIndex]), "keyboard");
49
- }
50
- }
51
- handleSelect(item, reason) {
52
- this.setSelectedValue(this.getItemValue(item), reason);
53
- }
54
- selectFirstItem() {
55
- if (!this.active)
56
- return;
57
- const item = this.firstItem;
58
- const value = item ? this.getItemValue(item) : "";
59
- this.setSelectedValue(value, "keyboard");
60
- item == null ? void 0 : item.scrollIntoView({ block: "nearest" });
61
- }
62
- handleMouseMove(_event) {
63
- this.lastMouseMoveTime = Date.now();
64
- }
65
- handleMouseOver(event) {
66
- if (this.lastMouseMoveTime + 500 < Date.now()) {
67
- return;
68
- }
69
- const target = event.target;
70
- const item = target && this.queryClosestItem(target);
71
- if (item) {
72
- this.setSelectedValue(this.getItemValue(item), "mouse");
73
- }
74
- }
75
- handleMouseDown(event) {
76
- event.preventDefault();
77
- }
78
- handleClick(event) {
79
- event.preventDefault();
80
- const target = event.target;
81
- const item = target && this.queryClosestItem(target);
82
- if (item) {
83
- this.handleSelect(item, "mouse");
84
- this.onSelect(item);
85
- }
86
- }
87
- handleArrowUp() {
88
- if (!this.active)
89
- return false;
90
- this.updateSelectedByChange(-1);
91
- return true;
92
- }
93
- handleArrowDown() {
94
- if (!this.active)
95
- return false;
96
- this.updateSelectedByChange(1);
97
- return true;
98
- }
99
- handleEscape() {
100
- if (!this.active)
101
- return false;
102
- this.onDismiss();
103
- return true;
104
- }
105
- handleEnter() {
106
- if (!this.active)
107
- return false;
108
- return this.onSelect(this.selectedItem);
109
- }
110
- };
111
-
112
- export {
113
- ListManager
114
- };