@mintplayer/web-components 1.2.0 → 1.4.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 (42) hide show
  1. package/accordion/src/styles/accordion.styles.d.ts +2 -0
  2. package/card/index.mjs +246 -363
  3. package/card/src/card-classes.d.ts +0 -7
  4. package/card/src/card-global.styles.d.ts +2 -0
  5. package/card/src/index.d.ts +0 -9
  6. package/card/src/mp-card.element.d.ts +45 -18
  7. package/chunks/{mp-treeview-Bfq4_IVW.mjs → mp-treeview-C48F63xb.mjs} +8 -8
  8. package/file-manager/index.mjs +1 -1
  9. package/package.json +1 -1
  10. package/timeline/index.mjs +716 -0
  11. package/timeline/src/components/index.d.ts +2 -0
  12. package/timeline/src/components/mp-timeline-item.d.ts +63 -0
  13. package/timeline/src/components/mp-timeline.d.ts +85 -0
  14. package/timeline/src/index.d.ts +5 -0
  15. package/timeline/src/styles/index.d.ts +2 -0
  16. package/timeline/src/styles/timeline-item.styles.d.ts +2 -0
  17. package/timeline/src/styles/timeline.styles.d.ts +2 -0
  18. package/timeline-core/index.mjs +23 -0
  19. package/timeline-core/src/index.d.ts +2 -0
  20. package/timeline-core/src/models/context.d.ts +39 -0
  21. package/timeline-core/src/models/index.d.ts +2 -0
  22. package/timeline-core/src/models/timeline-item.d.ts +44 -0
  23. package/timeline-core/src/resolve-sides.d.ts +12 -0
  24. package/tree-select/index.mjs +717 -0
  25. package/tree-select/src/components/index.d.ts +2 -0
  26. package/tree-select/src/components/mp-tree-select.d.ts +122 -0
  27. package/tree-select/src/index.d.ts +6 -0
  28. package/tree-select/src/providers/in-memory-provider.d.ts +29 -0
  29. package/tree-select/src/styles/index.d.ts +1 -0
  30. package/tree-select/src/styles/tree-select.styles.d.ts +2 -0
  31. package/tree-select/src/types/index.d.ts +1 -0
  32. package/tree-select/src/types/tree-select.d.ts +51 -0
  33. package/treeview/index.mjs +1 -1
  34. package/card/src/mp-card-body.element.d.ts +0 -12
  35. package/card/src/mp-card-footer.element.d.ts +0 -14
  36. package/card/src/mp-card-group.element.d.ts +0 -9
  37. package/card/src/mp-card-header.element.d.ts +0 -24
  38. package/card/src/mp-card-img.element.d.ts +0 -28
  39. package/card/src/mp-card-link.element.d.ts +0 -24
  40. package/card/src/mp-card-subtitle.element.d.ts +0 -9
  41. package/card/src/mp-card-text.element.d.ts +0 -9
  42. package/card/src/mp-card-title.element.d.ts +0 -13
@@ -0,0 +1,717 @@
1
+ import { unsafeCSS as c, LitElement as u, html as a, nothing as o } from "lit";
2
+ import { repeat as p } from "lit/directives/repeat.js";
3
+ import { OverlayController as b } from "../overlay/index.mjs";
4
+ import "../chunks/mp-treeview-C48F63xb.mjs";
5
+ const m = c(`:host {
6
+ display: inline-block;
7
+ width: 100%;
8
+ position: relative;
9
+ font-family: inherit;
10
+ font-size: 1rem;
11
+ color: var(--bs-body-color, #212529);
12
+ --ts-border: var(--bs-border-color, #dee2e6);
13
+ --ts-primary: var(--bs-primary, #0d6efd);
14
+ --ts-radius: var(--bs-border-radius, 0.375rem);
15
+ --ts-muted: var(--bs-secondary-color, #6c757d);
16
+ }
17
+
18
+ :host([disabled]) {
19
+ opacity: 0.65;
20
+ pointer-events: none;
21
+ }
22
+
23
+ * {
24
+ box-sizing: border-box;
25
+ }
26
+
27
+ button {
28
+ font-family: inherit;
29
+ font-size: inherit;
30
+ }
31
+
32
+ .ts-control {
33
+ display: flex;
34
+ align-items: center;
35
+ flex-wrap: wrap;
36
+ gap: 0.25rem;
37
+ width: 100%;
38
+ min-height: calc(1.5em + 0.75rem + 2px);
39
+ padding: 0.25rem 0.5rem;
40
+ background: var(--bs-body-bg, #fff);
41
+ border: 1px solid var(--ts-border);
42
+ border-radius: var(--ts-radius);
43
+ cursor: text;
44
+ }
45
+
46
+ .ts-control:focus-within {
47
+ border-color: var(--ts-primary);
48
+ box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
49
+ }
50
+
51
+ .ts-button {
52
+ display: flex;
53
+ align-items: center;
54
+ justify-content: space-between;
55
+ gap: 0.5rem;
56
+ width: 100%;
57
+ min-height: calc(1.5em + 0.75rem + 2px);
58
+ padding: 0.375rem 0.75rem;
59
+ background: var(--bs-body-bg, #fff);
60
+ border: 1px solid var(--ts-border);
61
+ border-radius: var(--ts-radius);
62
+ cursor: pointer;
63
+ text-align: start;
64
+ }
65
+
66
+ .ts-button:focus-visible {
67
+ outline: none;
68
+ border-color: var(--ts-primary);
69
+ box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
70
+ }
71
+
72
+ .ts-button-body {
73
+ display: flex;
74
+ align-items: center;
75
+ flex-wrap: wrap;
76
+ gap: 0.25rem;
77
+ flex: 1 1 auto;
78
+ min-width: 0;
79
+ }
80
+
81
+ .ts-placeholder {
82
+ color: var(--ts-muted);
83
+ }
84
+
85
+ .ts-single-value {
86
+ flex: 1 1 auto;
87
+ min-width: 0;
88
+ overflow: hidden;
89
+ text-overflow: ellipsis;
90
+ white-space: nowrap;
91
+ }
92
+
93
+ .ts-search {
94
+ flex: 1 1 4rem;
95
+ min-width: 4rem;
96
+ border: 0;
97
+ outline: 0;
98
+ padding: 0.125rem;
99
+ background: transparent;
100
+ color: inherit;
101
+ font: inherit;
102
+ }
103
+
104
+ .ts-search.panel-search {
105
+ flex: 1 1 auto;
106
+ width: 100%;
107
+ border: 1px solid var(--ts-border);
108
+ border-radius: var(--ts-radius);
109
+ padding: 0.375rem 0.5rem;
110
+ }
111
+
112
+ .ts-chip {
113
+ display: inline-flex;
114
+ align-items: center;
115
+ gap: 0.25rem;
116
+ flex: 0 0 auto;
117
+ max-width: 100%;
118
+ padding: 0.125rem 0.375rem;
119
+ background: var(--bs-secondary-bg, #e9ecef);
120
+ border-radius: var(--ts-radius);
121
+ font-size: 0.875em;
122
+ line-height: 1.2;
123
+ }
124
+
125
+ .ts-chip-label {
126
+ overflow: hidden;
127
+ text-overflow: ellipsis;
128
+ white-space: nowrap;
129
+ }
130
+
131
+ .ts-chip-remove,
132
+ .ts-clear {
133
+ display: inline-flex;
134
+ align-items: center;
135
+ justify-content: center;
136
+ border: 0;
137
+ background: transparent;
138
+ color: inherit;
139
+ cursor: pointer;
140
+ padding: 0;
141
+ line-height: 1;
142
+ font-size: 1em;
143
+ opacity: 0.7;
144
+ }
145
+
146
+ .ts-chip-remove:hover,
147
+ .ts-clear:hover {
148
+ opacity: 1;
149
+ }
150
+
151
+ .ts-clear {
152
+ flex: 0 0 auto;
153
+ margin-inline-start: auto;
154
+ font-size: 1.1em;
155
+ }
156
+
157
+ .ts-caret {
158
+ flex: 0 0 auto;
159
+ display: inline-flex;
160
+ width: 0.8em;
161
+ height: 0.8em;
162
+ color: var(--ts-muted);
163
+ transition: transform 0.15s ease;
164
+ }
165
+
166
+ :host([data-menu-open]) .ts-caret {
167
+ transform: rotate(180deg);
168
+ }
169
+
170
+ .ts-panel {
171
+ position: fixed;
172
+ z-index: 1056;
173
+ display: none;
174
+ flex-direction: column;
175
+ background: var(--bs-body-bg, #fff);
176
+ border: 1px solid var(--ts-border);
177
+ border-radius: var(--ts-radius);
178
+ box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
179
+ overflow: hidden;
180
+ }
181
+
182
+ :host([data-menu-open]) .ts-panel {
183
+ display: flex;
184
+ }
185
+
186
+ .ts-panel-header,
187
+ .ts-panel-footer {
188
+ flex: 0 0 auto;
189
+ padding: 0.5rem;
190
+ border-bottom: 1px solid var(--ts-border);
191
+ }
192
+
193
+ .ts-panel-footer {
194
+ border-bottom: 0;
195
+ border-top: 1px solid var(--ts-border);
196
+ }
197
+
198
+ .ts-panel-body {
199
+ flex: 1 1 auto;
200
+ overflow: auto;
201
+ }
202
+
203
+ .ts-state {
204
+ padding: 0.75rem;
205
+ color: var(--ts-muted);
206
+ text-align: center;
207
+ }
208
+
209
+ .ts-load-more {
210
+ display: block;
211
+ width: 100%;
212
+ padding: 0.375rem;
213
+ border: 0;
214
+ border-top: 1px solid var(--ts-border);
215
+ background: transparent;
216
+ color: var(--ts-primary);
217
+ cursor: pointer;
218
+ font: inherit;
219
+ }
220
+
221
+ .ts-load-more:hover {
222
+ background: var(--bs-secondary-bg, #e9ecef);
223
+ }
224
+
225
+ .ts-spinner {
226
+ display: inline-block;
227
+ width: 1rem;
228
+ height: 1rem;
229
+ border: 0.15em solid currentColor;
230
+ border-right-color: transparent;
231
+ border-radius: 50%;
232
+ animation: ts-spin 0.75s linear infinite;
233
+ vertical-align: -0.125em;
234
+ }
235
+
236
+ @keyframes ts-spin {
237
+ to {
238
+ transform: rotate(360deg);
239
+ }
240
+ }
241
+ .ts-node {
242
+ display: inline-flex;
243
+ align-items: center;
244
+ gap: 0.4rem;
245
+ }
246
+
247
+ .ts-node-check {
248
+ flex: 0 0 auto;
249
+ margin: 0;
250
+ cursor: pointer;
251
+ }`), _ = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true" width="100%" height="100%"><path d="M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z"/></svg>';
252
+ class g extends u {
253
+ constructor() {
254
+ super(...arguments), this._mode = "single", this._variant = "textbox", this._cascadeSelect = !1, this._placeholder = "", this._showClear = !1, this._scrollHeight = "300px", this._disabled = !1, this._searchDebounceMs = 200, this._nodes = [], this._searchResults = null, this._query = "", this._loading = !1, this._rootsLoaded = !1, this._rootsHasMore = !1, this._searchHasMore = !1, this._byId = /* @__PURE__ */ new Map(), this._parentById = /* @__PURE__ */ new Map(), this._selected = /* @__PURE__ */ new Map(), this._indeterminate = /* @__PURE__ */ new Set(), this._debounceTimer = 0, this.overlay = new b(this, {
255
+ anchor: () => this.renderRoot.querySelector(".ts-anchor"),
256
+ panel: () => this.renderRoot.querySelector(".ts-panel"),
257
+ panelWidth: "anchor-min",
258
+ scrollStrategy: "reposition",
259
+ onClose: () => this.onPanelClosed()
260
+ }), this.treeviewLoadChildren = async (e) => {
261
+ if (!this._provider) return [];
262
+ const s = new AbortController();
263
+ try {
264
+ const t = await this._provider.loadChildren(e, { offset: 0, signal: s.signal }), i = this._byId.get(e);
265
+ if (i && (i.children = t.nodes, this._searchResults ? this._searchResults = [...this._searchResults] : this._nodes = [...this._nodes], this.reindexActive()), this._mode === "checkbox" && this._cascadeSelect && i && this._selected.has(e)) {
266
+ for (const r of t.nodes) this.applyDown(r, !0);
267
+ this.recomputeIndeterminate();
268
+ }
269
+ return this.requestUpdate(), t.nodes;
270
+ } catch (t) {
271
+ return this.dispatchEvent(
272
+ new CustomEvent("load-error", { detail: { error: t }, bubbles: !0, composed: !0 })
273
+ ), [];
274
+ }
275
+ }, this._nodeRendererKey = "";
276
+ }
277
+ static {
278
+ this.styles = [m];
279
+ }
280
+ static get observedAttributes() {
281
+ return [
282
+ ...super.observedAttributes ?? [],
283
+ "mode",
284
+ "variant",
285
+ "cascade-select",
286
+ "placeholder",
287
+ "show-clear",
288
+ "scroll-height",
289
+ "disabled",
290
+ "search-debounce-ms"
291
+ ];
292
+ }
293
+ // ---- public reactive properties ----------------------------------------
294
+ get provider() {
295
+ return this._provider;
296
+ }
297
+ set provider(e) {
298
+ e !== this._provider && (this._provider = e, this._rootsLoaded = !1, this._nodes = [], this._byId.clear(), this._parentById.clear(), this.overlay.isOpen && this.ensureRoots(), this.requestUpdate());
299
+ }
300
+ get value() {
301
+ return this._mode === "single" ? this._selected.size ? this._selected.values().next().value : null : [...this._selected.values()];
302
+ }
303
+ set value(e) {
304
+ this._selected = /* @__PURE__ */ new Map();
305
+ const s = Array.isArray(e) ? e : e ? [e] : [];
306
+ for (const t of s)
307
+ t && (this._selected.set(t.id, t), this._byId.set(t.id, t));
308
+ this.recomputeIndeterminate(), this.syncTreeviewSelection(), this.requestUpdate();
309
+ }
310
+ get mode() {
311
+ return this._mode;
312
+ }
313
+ set mode(e) {
314
+ if (this._mode = e, e === "single" && this._selected.size > 1) {
315
+ const s = this._selected.values().next().value;
316
+ this._selected = /* @__PURE__ */ new Map([[s.id, s]]);
317
+ }
318
+ this.requestUpdate();
319
+ }
320
+ get variant() {
321
+ return this._variant;
322
+ }
323
+ set variant(e) {
324
+ this._variant = e, this.requestUpdate();
325
+ }
326
+ get cascadeSelect() {
327
+ return this._cascadeSelect;
328
+ }
329
+ set cascadeSelect(e) {
330
+ this._cascadeSelect = !!e, this.requestUpdate();
331
+ }
332
+ get placeholder() {
333
+ return this._placeholder;
334
+ }
335
+ set placeholder(e) {
336
+ this._placeholder = e ?? "", this.requestUpdate();
337
+ }
338
+ get showClear() {
339
+ return this._showClear;
340
+ }
341
+ set showClear(e) {
342
+ this._showClear = !!e, this.requestUpdate();
343
+ }
344
+ // NB: cannot be named `scrollHeight` — that's a readonly DOM property on HTMLElement.
345
+ get panelScrollHeight() {
346
+ return this._scrollHeight;
347
+ }
348
+ set panelScrollHeight(e) {
349
+ this._scrollHeight = e || "300px", this.requestUpdate();
350
+ }
351
+ get disabled() {
352
+ return this._disabled;
353
+ }
354
+ set disabled(e) {
355
+ this._disabled = !!e, this.toggleAttribute("disabled", this._disabled), this._disabled && this.overlay.close(!1), this.requestUpdate();
356
+ }
357
+ get searchDebounceMs() {
358
+ return this._searchDebounceMs;
359
+ }
360
+ set searchDebounceMs(e) {
361
+ this._searchDebounceMs = Math.max(0, Number(e) || 0);
362
+ }
363
+ attributeChangedCallback(e, s, t) {
364
+ switch (super.attributeChangedCallback(e, s, t), e) {
365
+ case "mode":
366
+ this.mode = t ?? "single";
367
+ break;
368
+ case "variant":
369
+ this.variant = t ?? "textbox";
370
+ break;
371
+ case "cascade-select":
372
+ this.cascadeSelect = t !== null;
373
+ break;
374
+ case "placeholder":
375
+ this.placeholder = t ?? "";
376
+ break;
377
+ case "show-clear":
378
+ this.showClear = t !== null;
379
+ break;
380
+ case "scroll-height":
381
+ this.panelScrollHeight = t ?? "300px";
382
+ break;
383
+ case "disabled":
384
+ this.disabled = t !== null;
385
+ break;
386
+ case "search-debounce-ms":
387
+ this.searchDebounceMs = Number(t);
388
+ break;
389
+ }
390
+ }
391
+ disconnectedCallback() {
392
+ super.disconnectedCallback(), this._abort?.abort(), this._debounceTimer && clearTimeout(this._debounceTimer);
393
+ }
394
+ // ---- index helpers -----------------------------------------------------
395
+ indexNodes(e, s) {
396
+ for (const t of e)
397
+ this._byId.set(t.id, t), this._parentById.set(t.id, s), t.children?.length && this.indexNodes(t.children, t);
398
+ }
399
+ /**
400
+ * Rebuild the id/parent index from the *currently displayed* tree
401
+ * (search results when searching, else the browse tree). Providers hand
402
+ * back fresh shallow node copies per call, so search must not pollute the
403
+ * browse index — re-indexing the active set keeps cascade + lazy-expand
404
+ * pointing at the objects actually rendered, and restores the browse index
405
+ * when a search is cleared.
406
+ */
407
+ reindexActive() {
408
+ this._byId.clear(), this._parentById.clear(), this.indexNodes(this._searchResults ?? this._nodes, null);
409
+ }
410
+ // ---- data loading ------------------------------------------------------
411
+ async ensureRoots() {
412
+ this._rootsLoaded || !this._provider || await this.loadRoots(!1);
413
+ }
414
+ async loadRoots(e) {
415
+ if (!this._provider) return;
416
+ const s = e ? this._nodes.length : 0, t = await this.runRequest((i) => this._provider.loadRoots({ offset: s, signal: i }));
417
+ t && (this._nodes = e ? [...this._nodes, ...t.nodes] : t.nodes, this._rootsHasMore = !!t.hasMore, this._rootsLoaded = !0, this.reindexActive(), this.requestUpdate());
418
+ }
419
+ async runSearch(e) {
420
+ if (!this._provider) return;
421
+ const s = this._query, t = e ? this._searchResults?.length ?? 0 : 0, i = await this.runRequest((r) => this._provider.search(s, { offset: t, signal: r }));
422
+ i && (this._searchResults = e ? [...this._searchResults ?? [], ...i.nodes] : i.nodes, this._searchHasMore = !!i.hasMore, this.reindexActive(), this.requestUpdate());
423
+ }
424
+ /** Run a provider call with abort + loading bookkeeping. Returns null on abort/error. */
425
+ async runRequest(e) {
426
+ this._abort?.abort();
427
+ const s = new AbortController();
428
+ this._abort = s, this._loading = !0, this.requestUpdate();
429
+ try {
430
+ const t = await e(s.signal);
431
+ return s.signal.aborted ? null : (this._loading = !1, this.requestUpdate(), t);
432
+ } catch (t) {
433
+ return s.signal.aborted || t?.name === "AbortError" || (this._loading = !1, this.dispatchEvent(
434
+ new CustomEvent("load-error", { detail: { error: t }, bubbles: !0, composed: !0 })
435
+ ), this.requestUpdate()), null;
436
+ }
437
+ }
438
+ onLoadMore() {
439
+ this._query ? this.runSearch(!0) : this.loadRoots(!0);
440
+ }
441
+ // ---- search input ------------------------------------------------------
442
+ onSearchInput(e) {
443
+ this._query = e.target.value, this.overlay.isOpen || this.open(), this._debounceTimer && clearTimeout(this._debounceTimer);
444
+ const s = () => {
445
+ this._query.trim() ? this.runSearch(!1) : (this._abort?.abort(), this._searchResults = null, this._loading = !1, this.reindexActive(), this.requestUpdate()), this.dispatchEvent(
446
+ new CustomEvent("search", { detail: { query: this._query }, bubbles: !0, composed: !0 })
447
+ );
448
+ };
449
+ this._searchDebounceMs > 0 ? this._debounceTimer = window.setTimeout(s, this._searchDebounceMs) : s();
450
+ }
451
+ // ---- open / close ------------------------------------------------------
452
+ async open() {
453
+ this._disabled || !this._provider || (await this.ensureRoots(), await this.overlay.open(), this.dispatchEvent(new CustomEvent("open", { bubbles: !0, composed: !0 })));
454
+ }
455
+ close() {
456
+ this.overlay.close();
457
+ }
458
+ onPanelClosed() {
459
+ (this._query || this._searchResults) && (this._abort?.abort(), this._query = "", this._searchResults = null, this._loading = !1, this.reindexActive(), this.requestUpdate()), this.dispatchEvent(new CustomEvent("close", { bubbles: !0, composed: !0 }));
460
+ }
461
+ onTriggerClick() {
462
+ this.overlay.isOpen ? this.overlay.close() : this.open();
463
+ }
464
+ focusSearchAndOpen() {
465
+ this.open(), requestAnimationFrame(() => {
466
+ this.renderRoot.querySelector(".ts-search")?.focus();
467
+ });
468
+ }
469
+ // ---- selection ---------------------------------------------------------
470
+ onTreeSelect(e) {
471
+ if (this._mode !== "single") return;
472
+ const s = e.detail;
473
+ this._selected = /* @__PURE__ */ new Map([[s.node.id, s.node]]), this._byId.set(s.node.id, s.node), this.emitChange(s.node, void 0), this.requestUpdate(), this.overlay.close();
474
+ }
475
+ onCheckboxToggle(e, s) {
476
+ this._mode === "checkbox" && this._cascadeSelect ? (this.applyDown(e, s), this.applyUp(e), this.recomputeIndeterminate()) : s ? this._selected.set(e.id, e) : this._selected.delete(e.id), this.emitChange(s ? e : void 0, s ? void 0 : e), this.syncTreeviewSelection(), this.requestUpdate();
477
+ }
478
+ removeNode(e) {
479
+ this._mode === "checkbox" && this._cascadeSelect ? (this.applyDown(e, !1), this.applyUp(e), this.recomputeIndeterminate()) : this._selected.delete(e.id), this.emitChange(void 0, e), this.syncTreeviewSelection(), this.requestUpdate();
480
+ }
481
+ clearAll(e) {
482
+ e?.stopPropagation(), this._selected = /* @__PURE__ */ new Map(), this._indeterminate.clear(), this.dispatchEvent(new CustomEvent("clear", { bubbles: !0, composed: !0 })), this.emitChange(void 0, void 0), this.syncTreeviewSelection(), this.requestUpdate();
483
+ }
484
+ /** Cascade membership down over LOADED descendants only. */
485
+ applyDown(e, s) {
486
+ s ? this._selected.set(e.id, e) : this._selected.delete(e.id);
487
+ for (const t of e.children ?? []) this.applyDown(t, s);
488
+ }
489
+ /** Roll membership up: an ancestor is selected iff all its LOADED children are. */
490
+ applyUp(e) {
491
+ let s = this._parentById.get(e.id) ?? null;
492
+ for (; s; ) {
493
+ const t = s.children ?? [];
494
+ t.length > 0 && t.every((r) => this._selected.has(r.id)) ? this._selected.set(s.id, s) : this._selected.delete(s.id), s = this._parentById.get(s.id) ?? null;
495
+ }
496
+ }
497
+ /** Indeterminate = not selected, but ≥1 loaded descendant selected. */
498
+ recomputeIndeterminate() {
499
+ this._indeterminate.clear();
500
+ const e = (t) => {
501
+ let i = !1;
502
+ for (const l of t.children ?? [])
503
+ e(l) && (i = !0);
504
+ const r = this._selected.has(t.id);
505
+ return !r && i && this._indeterminate.add(t.id), r || i;
506
+ }, s = this._searchResults ?? this._nodes;
507
+ for (const t of s) e(t);
508
+ }
509
+ emitChange(e, s) {
510
+ this.dispatchEvent(
511
+ new CustomEvent("value-change", {
512
+ detail: { value: this.value, added: e, removed: s },
513
+ bubbles: !0,
514
+ composed: !0
515
+ })
516
+ );
517
+ }
518
+ syncTreeviewSelection() {
519
+ const e = this.renderRoot.querySelector("mp-treeview");
520
+ e && (e.selectedIds = [...this._selected.keys()]);
521
+ }
522
+ get nodeRenderer() {
523
+ const e = this._mode === "multiple" || this._mode === "checkbox", s = `${this._mode}|${this.suggestionTemplate ? "1" : "0"}`;
524
+ return s === this._nodeRendererKey ? this._nodeRendererFn : (this._nodeRendererKey = s, this._nodeRendererFn = !e && !this.suggestionTemplate ? void 0 : (t) => {
525
+ const i = document.createElement("span");
526
+ if (i.className = "ts-node", e) {
527
+ const n = document.createElement("input");
528
+ n.type = "checkbox", n.className = "ts-node-check", n.checked = this._selected.has(t.id), n.indeterminate = this._indeterminate.has(t.id), n.addEventListener("click", (d) => d.stopPropagation()), n.addEventListener("change", (d) => {
529
+ d.stopPropagation(), this.onCheckboxToggle(t, d.target.checked);
530
+ }), i.appendChild(n);
531
+ }
532
+ const r = document.createElement("span");
533
+ r.className = "treeview-label";
534
+ const l = this.suggestionTemplate?.(t, this._query);
535
+ return l ? r.appendChild(l) : r.textContent = t.label, i.appendChild(r), i;
536
+ }, this._nodeRendererFn);
537
+ }
538
+ // ---- render ------------------------------------------------------------
539
+ render() {
540
+ return a`${this.renderTrigger()}${this.renderPanel()}`;
541
+ }
542
+ get hasSelection() {
543
+ return this._selected.size > 0;
544
+ }
545
+ renderTrigger() {
546
+ return this._variant === "button" ? this.renderButtonTrigger() : this.renderTextboxTrigger();
547
+ }
548
+ renderButtonTrigger() {
549
+ return a`
550
+ <button
551
+ class="ts-button ts-anchor"
552
+ type="button"
553
+ ?disabled=${this._disabled}
554
+ aria-haspopup="tree"
555
+ aria-expanded=${this.overlay.isOpen ? "true" : "false"}
556
+ @click=${() => this.onTriggerClick()}
557
+ >
558
+ <span class="ts-button-body">${this.renderTriggerBody()}</span>
559
+ ${this.renderClear()}
560
+ <span class="ts-caret">${this.renderCaret()}</span>
561
+ </button>
562
+ `;
563
+ }
564
+ renderTextboxTrigger() {
565
+ const e = this._mode === "single" && this.hasSelection && !this._query;
566
+ return a`
567
+ <div class="ts-control ts-anchor" @click=${() => this.focusSearchAndOpen()}>
568
+ ${this.renderChips()}
569
+ ${e ? a`<span class="ts-single-value">${this.renderSelectedLabel()}</span>` : o}
570
+ <input
571
+ class="ts-search"
572
+ type="text"
573
+ .value=${this._query}
574
+ ?disabled=${this._disabled}
575
+ placeholder=${this.hasSelection ? "" : this._placeholder}
576
+ aria-label=${this._placeholder || "Search"}
577
+ @input=${(s) => this.onSearchInput(s)}
578
+ @focus=${() => this.open()}
579
+ />
580
+ ${this.renderClear()}
581
+ <span class="ts-caret">${this.renderCaret()}</span>
582
+ </div>
583
+ `;
584
+ }
585
+ renderTriggerBody() {
586
+ return this.buttonTemplate ? this.buttonTemplate(this.value) : this.hasSelection ? this._mode === "single" ? this.renderSelectedLabel() : this.renderChips() : a`<span class="ts-placeholder">${this._placeholder}</span>`;
587
+ }
588
+ renderSelectedLabel() {
589
+ const e = this._selected.values().next().value;
590
+ return e ? this.itemTemplate ? this.itemTemplate(e, this._query) : e.label : o;
591
+ }
592
+ renderChips() {
593
+ return this._mode === "single" || !this.hasSelection ? o : p(
594
+ [...this._selected.values()],
595
+ (e) => e.id,
596
+ (e) => a`
597
+ <span class="ts-chip">
598
+ <span class="ts-chip-label"
599
+ >${this.itemTemplate ? this.itemTemplate(e, this._query) : e.label}</span
600
+ >
601
+ <button
602
+ class="ts-chip-remove"
603
+ type="button"
604
+ aria-label="Remove"
605
+ @click=${(s) => {
606
+ s.stopPropagation(), this.removeNode(e);
607
+ }}
608
+ >
609
+ ×
610
+ </button>
611
+ </span>
612
+ `
613
+ );
614
+ }
615
+ renderClear() {
616
+ return !this._showClear || !this.hasSelection ? o : a`<button
617
+ class="ts-clear"
618
+ type="button"
619
+ aria-label="Clear"
620
+ @click=${(e) => this.clearAll(e)}
621
+ >
622
+ ×
623
+ </button>`;
624
+ }
625
+ renderCaret() {
626
+ const e = document.createElement("span");
627
+ return e.style.display = "inline-flex", e.style.width = "100%", e.style.height = "100%", e.innerHTML = _, e;
628
+ }
629
+ renderPanel() {
630
+ return a`
631
+ <div class="ts-panel" role="dialog">
632
+ ${this.headerTemplate ? a`<div class="ts-panel-header">${this.headerTemplate()}</div>` : o}
633
+ ${this._variant === "button" ? a`<div class="ts-panel-header">
634
+ <input
635
+ class="ts-search panel-search"
636
+ type="text"
637
+ .value=${this._query}
638
+ placeholder=${this._placeholder || "Search"}
639
+ aria-label="Search"
640
+ @input=${(e) => this.onSearchInput(e)}
641
+ />
642
+ </div>` : o}
643
+ <div class="ts-panel-body" style=${`max-height:${this._scrollHeight}`}>${this.renderBody()}</div>
644
+ ${this.renderLoadMore()}
645
+ ${this.footerTemplate ? a`<div class="ts-panel-footer">${this.footerTemplate()}</div>` : o}
646
+ </div>
647
+ `;
648
+ }
649
+ renderBody() {
650
+ if (!this._provider) return a`<div class="ts-state">No data provider</div>`;
651
+ const e = !!this._query.trim();
652
+ return this._loading && (e ? this._searchResults === null : !this._rootsLoaded) ? a`<div class="ts-state"><span class="ts-spinner"></span></div>` : e ? this._searchResults?.length ? this.renderTreeview(this._searchResults) : a`<div class="ts-state">${this.noResultsTemplate ? this.noResultsTemplate() : "No results"}</div>` : this._nodes.length ? this.renderTreeview(this._nodes) : a`<div class="ts-state">${this.enterSearchTermTemplate ? this.enterSearchTermTemplate() : "No items"}</div>`;
653
+ }
654
+ renderTreeview(e) {
655
+ const s = this._mode === "single" ? "single" : "none";
656
+ return a`
657
+ <mp-treeview
658
+ hide-borders
659
+ .items=${e}
660
+ .selectionMode=${s}
661
+ .selectedIds=${[...this._selected.keys()]}
662
+ .loadChildren=${this.treeviewLoadChildren}
663
+ .nodeRenderer=${this.nodeRenderer}
664
+ @tree-node-select=${(t) => this.onTreeSelect(t)}
665
+ ></mp-treeview>
666
+ `;
667
+ }
668
+ renderLoadMore() {
669
+ return (this._query ? this._searchHasMore : this._rootsHasMore) ? a`<button class="ts-load-more" type="button" @click=${() => this.onLoadMore()}>
670
+ ${this._loading ? a`<span class="ts-spinner"></span>` : "Load more"}
671
+ </button>` : o;
672
+ }
673
+ }
674
+ typeof customElements < "u" && !customElements.get("mp-tree-select") && customElements.define("mp-tree-select", g);
675
+ class x {
676
+ constructor(e, s = {}) {
677
+ this.tree = e, this.byId = /* @__PURE__ */ new Map(), this.flat = [], this.pageSize = s.pageSize ?? 50, this.delayMs = s.delayMs ?? 0;
678
+ const t = (i) => {
679
+ for (const r of i)
680
+ this.byId.set(r.id, r), this.flat.push(r), r.children?.length && t(r.children);
681
+ };
682
+ t(e);
683
+ }
684
+ loadRoots(e) {
685
+ return this.page(this.tree, e);
686
+ }
687
+ loadChildren(e, s) {
688
+ const t = this.byId.get(e);
689
+ return this.page(t?.children ?? [], s);
690
+ }
691
+ search(e, s) {
692
+ const t = e.trim().toLowerCase();
693
+ if (!t) return this.page([], s);
694
+ const i = this.flat.filter(
695
+ (r) => r.label.toLowerCase().includes(t) || r.id.toLowerCase().includes(t)
696
+ );
697
+ return this.page(i, s);
698
+ }
699
+ async page(e, s) {
700
+ if (this.delayMs > 0 && await new Promise((r) => setTimeout(r, this.delayMs)), s.signal.aborted) throw new DOMException("Aborted", "AbortError");
701
+ const t = Math.max(0, s.offset ?? 0);
702
+ return {
703
+ nodes: e.slice(t, t + this.pageSize).map((r) => this.toShallow(r)),
704
+ hasMore: t + this.pageSize < e.length
705
+ };
706
+ }
707
+ /** Strip children; flag `lazy` when the source node actually has children. */
708
+ toShallow(e) {
709
+ const s = !!e.children?.length;
710
+ return { ...e, children: void 0, lazy: s };
711
+ }
712
+ }
713
+ export {
714
+ x as InMemoryTreeSelectProvider,
715
+ g as MpTreeSelect,
716
+ m as treeSelectStyles
717
+ };