@mintplayer/web-components 1.3.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.
- package/chunks/{mp-treeview-Bfq4_IVW.mjs → mp-treeview-C48F63xb.mjs} +8 -8
- package/file-manager/index.mjs +1 -1
- package/package.json +1 -1
- package/tree-select/index.mjs +717 -0
- package/tree-select/src/components/index.d.ts +2 -0
- package/tree-select/src/components/mp-tree-select.d.ts +122 -0
- package/tree-select/src/index.d.ts +6 -0
- package/tree-select/src/providers/in-memory-provider.d.ts +29 -0
- package/tree-select/src/styles/index.d.ts +1 -0
- package/tree-select/src/styles/tree-select.styles.d.ts +2 -0
- package/tree-select/src/types/index.d.ts +1 -0
- package/tree-select/src/types/tree-select.d.ts +51 -0
- package/treeview/index.mjs +1 -1
|
@@ -271,12 +271,12 @@ class R extends y {
|
|
|
271
271
|
`;
|
|
272
272
|
}
|
|
273
273
|
renderNode(e, t, s, i) {
|
|
274
|
-
const r = !!(e.children && e.children.length > 0), c = !!e.lazy && !r,
|
|
274
|
+
const r = !!(e.children && e.children.length > 0), c = !!e.lazy && !r, p = r || c, l = this._loadingIds.has(e.id), v = this._errorIds.get(e.id), a = this._expandedIds.has(e.id), u = this._selectedIds.has(e.id), f = this._focusedId === e.id, m = f ? 0 : -1, w = e.iconKey && this._iconResolver ? this._iconResolver(e.iconKey, e) : void 0, _ = (t - 1) * 20, x = `${this.instanceId}-row-${e.id}`, g = this._nodeRenderer ? this._nodeRenderer(e, {
|
|
275
275
|
level: t,
|
|
276
276
|
expanded: a,
|
|
277
|
-
selected:
|
|
277
|
+
selected: u,
|
|
278
278
|
focused: f,
|
|
279
|
-
hasChildren:
|
|
279
|
+
hasChildren: p
|
|
280
280
|
}) : void 0;
|
|
281
281
|
return d`
|
|
282
282
|
<li role="none">
|
|
@@ -285,15 +285,15 @@ class R extends y {
|
|
|
285
285
|
class="treeview-row"
|
|
286
286
|
role="treeitem"
|
|
287
287
|
data-node-id=${e.id}
|
|
288
|
-
data-selected=${
|
|
288
|
+
data-selected=${u ? "true" : "false"}
|
|
289
289
|
data-loading=${l ? "true" : "false"}
|
|
290
290
|
data-error=${v ? "true" : "false"}
|
|
291
291
|
aria-level=${t}
|
|
292
292
|
aria-setsize=${i}
|
|
293
293
|
aria-posinset=${s + 1}
|
|
294
|
-
aria-expanded=${
|
|
294
|
+
aria-expanded=${p ? a ? "true" : "false" : n}
|
|
295
295
|
aria-busy=${l ? "true" : n}
|
|
296
|
-
aria-selected=${this._selectionMode !== "none" ?
|
|
296
|
+
aria-selected=${this._selectionMode !== "none" ? u ? "true" : "false" : n}
|
|
297
297
|
tabindex=${m}
|
|
298
298
|
style=${`padding-left:${_ + 12}px`}
|
|
299
299
|
@click=${(o) => this.onRowClick(e, o)}
|
|
@@ -301,7 +301,7 @@ class R extends y {
|
|
|
301
301
|
title=${v ?? n}
|
|
302
302
|
>
|
|
303
303
|
<span
|
|
304
|
-
class=${`treeview-chevron${
|
|
304
|
+
class=${`treeview-chevron${p ? "" : " invisible"}${l ? " loading" : ""}`}
|
|
305
305
|
data-expanded=${a ? "true" : "false"}
|
|
306
306
|
@click=${(o) => this.onChevronClick(e, o)}
|
|
307
307
|
aria-hidden="true"
|
|
@@ -337,7 +337,7 @@ class R extends y {
|
|
|
337
337
|
t.stopPropagation(), this.focusNode(e.id), this.toggleSelection(e, t.ctrlKey || t.metaKey), e.children && e.children.length > 0 && this.toggleExpansion(e);
|
|
338
338
|
}
|
|
339
339
|
onChevronClick(e, t) {
|
|
340
|
-
|
|
340
|
+
((e.children?.length ?? 0) > 0 || e.lazy) && (t.stopPropagation(), this.focusNode(e.id), this.toggleExpansion(e));
|
|
341
341
|
}
|
|
342
342
|
onRowKeydown(e, t) {
|
|
343
343
|
const s = !!(e.children && e.children.length > 0), i = this._expandedIds.has(e.id);
|
package/file-manager/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { unsafeHTML as u } from "lit/directives/unsafe-html.js";
|
|
|
4
4
|
import { createRef as v, ref as w } from "lit/directives/ref.js";
|
|
5
5
|
import { styleMap as y } from "lit/directives/style-map.js";
|
|
6
6
|
import "../chunks/mp-splitter-C8cGCmac.mjs";
|
|
7
|
-
import "../chunks/mp-treeview-
|
|
7
|
+
import "../chunks/mp-treeview-C48F63xb.mjs";
|
|
8
8
|
import "../chunks/mp-datatable-Con0yQue.mjs";
|
|
9
9
|
const $ = b(`:host {
|
|
10
10
|
display: flex;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mintplayer/web-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Framework-agnostic Lit web components for the @mintplayer/bootstrap design system. Consumed by @mintplayer/ng-bootstrap, @mintplayer/react-bootstrap, and @mintplayer/vue-bootstrap.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { LitElement, TemplateResult } from 'lit';
|
|
2
|
+
import { TreeNode, TreeSelectMode, TreeSelectProvider, TreeSelectVariant } from '../types';
|
|
3
|
+
/** A render-callback the wrappers bridge to their native templating. */
|
|
4
|
+
export type NodeTemplate = (node: TreeNode, query: string) => Node;
|
|
5
|
+
export type ValueTemplate = (value: TreeNode | TreeNode[] | null) => Node;
|
|
6
|
+
export type PanelTemplate = () => Node;
|
|
7
|
+
/**
|
|
8
|
+
* `<mp-tree-select>` — a hierarchical, async, searchable select.
|
|
9
|
+
*
|
|
10
|
+
* Replaces the legacy select2 / searchbox / multiselect controls. Data is
|
|
11
|
+
* async-only via a {@link TreeSelectProvider}; selection is held as full
|
|
12
|
+
* `TreeNode` objects. See the issue #342 PRD for the full contract.
|
|
13
|
+
*/
|
|
14
|
+
export declare class MpTreeSelect extends LitElement {
|
|
15
|
+
static styles: import('lit').CSSResult[];
|
|
16
|
+
static get observedAttributes(): string[];
|
|
17
|
+
private _mode;
|
|
18
|
+
private _variant;
|
|
19
|
+
private _cascadeSelect;
|
|
20
|
+
private _placeholder;
|
|
21
|
+
private _showClear;
|
|
22
|
+
private _scrollHeight;
|
|
23
|
+
private _disabled;
|
|
24
|
+
private _searchDebounceMs;
|
|
25
|
+
itemTemplate?: NodeTemplate;
|
|
26
|
+
suggestionTemplate?: NodeTemplate;
|
|
27
|
+
buttonTemplate?: ValueTemplate;
|
|
28
|
+
headerTemplate?: PanelTemplate;
|
|
29
|
+
footerTemplate?: PanelTemplate;
|
|
30
|
+
noResultsTemplate?: PanelTemplate;
|
|
31
|
+
enterSearchTermTemplate?: PanelTemplate;
|
|
32
|
+
private _provider?;
|
|
33
|
+
private _nodes;
|
|
34
|
+
private _searchResults;
|
|
35
|
+
private _query;
|
|
36
|
+
private _loading;
|
|
37
|
+
private _rootsLoaded;
|
|
38
|
+
private _rootsHasMore;
|
|
39
|
+
private _searchHasMore;
|
|
40
|
+
private readonly _byId;
|
|
41
|
+
private readonly _parentById;
|
|
42
|
+
private _selected;
|
|
43
|
+
private readonly _indeterminate;
|
|
44
|
+
private _abort?;
|
|
45
|
+
private _debounceTimer;
|
|
46
|
+
private readonly overlay;
|
|
47
|
+
get provider(): TreeSelectProvider | undefined;
|
|
48
|
+
set provider(value: TreeSelectProvider | undefined);
|
|
49
|
+
get value(): TreeNode | TreeNode[] | null;
|
|
50
|
+
set value(value: TreeNode | TreeNode[] | null);
|
|
51
|
+
get mode(): TreeSelectMode;
|
|
52
|
+
set mode(value: TreeSelectMode);
|
|
53
|
+
get variant(): TreeSelectVariant;
|
|
54
|
+
set variant(value: TreeSelectVariant);
|
|
55
|
+
get cascadeSelect(): boolean;
|
|
56
|
+
set cascadeSelect(value: boolean);
|
|
57
|
+
get placeholder(): string;
|
|
58
|
+
set placeholder(value: string);
|
|
59
|
+
get showClear(): boolean;
|
|
60
|
+
set showClear(value: boolean);
|
|
61
|
+
get panelScrollHeight(): string;
|
|
62
|
+
set panelScrollHeight(value: string);
|
|
63
|
+
get disabled(): boolean;
|
|
64
|
+
set disabled(value: boolean);
|
|
65
|
+
get searchDebounceMs(): number;
|
|
66
|
+
set searchDebounceMs(value: number);
|
|
67
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
68
|
+
disconnectedCallback(): void;
|
|
69
|
+
private indexNodes;
|
|
70
|
+
/**
|
|
71
|
+
* Rebuild the id/parent index from the *currently displayed* tree
|
|
72
|
+
* (search results when searching, else the browse tree). Providers hand
|
|
73
|
+
* back fresh shallow node copies per call, so search must not pollute the
|
|
74
|
+
* browse index — re-indexing the active set keeps cascade + lazy-expand
|
|
75
|
+
* pointing at the objects actually rendered, and restores the browse index
|
|
76
|
+
* when a search is cleared.
|
|
77
|
+
*/
|
|
78
|
+
private reindexActive;
|
|
79
|
+
private ensureRoots;
|
|
80
|
+
private loadRoots;
|
|
81
|
+
private runSearch;
|
|
82
|
+
/** Run a provider call with abort + loading bookkeeping. Returns null on abort/error. */
|
|
83
|
+
private runRequest;
|
|
84
|
+
/** Lazy children loader wired into the embedded `mp-treeview`. */
|
|
85
|
+
private readonly treeviewLoadChildren;
|
|
86
|
+
private onLoadMore;
|
|
87
|
+
private onSearchInput;
|
|
88
|
+
open(): Promise<void>;
|
|
89
|
+
close(): void;
|
|
90
|
+
private onPanelClosed;
|
|
91
|
+
private onTriggerClick;
|
|
92
|
+
private focusSearchAndOpen;
|
|
93
|
+
private onTreeSelect;
|
|
94
|
+
private onCheckboxToggle;
|
|
95
|
+
private removeNode;
|
|
96
|
+
private clearAll;
|
|
97
|
+
/** Cascade membership down over LOADED descendants only. */
|
|
98
|
+
private applyDown;
|
|
99
|
+
/** Roll membership up: an ancestor is selected iff all its LOADED children are. */
|
|
100
|
+
private applyUp;
|
|
101
|
+
/** Indeterminate = not selected, but ≥1 loaded descendant selected. */
|
|
102
|
+
private recomputeIndeterminate;
|
|
103
|
+
private emitChange;
|
|
104
|
+
private syncTreeviewSelection;
|
|
105
|
+
private _nodeRendererFn;
|
|
106
|
+
private _nodeRendererKey;
|
|
107
|
+
private get nodeRenderer();
|
|
108
|
+
render(): TemplateResult;
|
|
109
|
+
private get hasSelection();
|
|
110
|
+
private renderTrigger;
|
|
111
|
+
private renderButtonTrigger;
|
|
112
|
+
private renderTextboxTrigger;
|
|
113
|
+
private renderTriggerBody;
|
|
114
|
+
private renderSelectedLabel;
|
|
115
|
+
private renderChips;
|
|
116
|
+
private renderClear;
|
|
117
|
+
private renderCaret;
|
|
118
|
+
private renderPanel;
|
|
119
|
+
private renderBody;
|
|
120
|
+
private renderTreeview;
|
|
121
|
+
private renderLoadMore;
|
|
122
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { MpTreeSelect } from './components';
|
|
2
|
+
export type { NodeTemplate, ValueTemplate, PanelTemplate } from './components';
|
|
3
|
+
export type { TreeSelectMode, TreeSelectVariant, NodePage, NodeRequest, TreeSelectProvider, TreeSelectChangeEventDetail, TreeNode, } from './types';
|
|
4
|
+
export { InMemoryTreeSelectProvider } from './providers/in-memory-provider';
|
|
5
|
+
export type { InMemoryProviderOptions } from './providers/in-memory-provider';
|
|
6
|
+
export { treeSelectStyles } from './styles';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { TreeNode } from '@mintplayer/web-components/treeview';
|
|
2
|
+
import { NodePage, NodeRequest, TreeSelectProvider } from '../types';
|
|
3
|
+
export interface InMemoryProviderOptions {
|
|
4
|
+
/** Rows per page for roots / children / search. Default: 50. */
|
|
5
|
+
pageSize?: number;
|
|
6
|
+
/** Artificial latency in ms — exercises loading/race states. Default: 0. */
|
|
7
|
+
delayMs?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A {@link TreeSelectProvider} backed by an in-memory tree. Backs unit tests,
|
|
11
|
+
* demos, and e2e without a network. Returned nodes are **shallow** — children
|
|
12
|
+
* are stripped and `lazy` is set when the source node has children — so the
|
|
13
|
+
* component lazy-loads each level through `loadChildren`, mirroring a real
|
|
14
|
+
* paged backend.
|
|
15
|
+
*/
|
|
16
|
+
export declare class InMemoryTreeSelectProvider implements TreeSelectProvider {
|
|
17
|
+
private readonly tree;
|
|
18
|
+
private readonly byId;
|
|
19
|
+
private readonly flat;
|
|
20
|
+
private readonly pageSize;
|
|
21
|
+
private readonly delayMs;
|
|
22
|
+
constructor(tree: TreeNode[], options?: InMemoryProviderOptions);
|
|
23
|
+
loadRoots(req: NodeRequest): Promise<NodePage>;
|
|
24
|
+
loadChildren(parentId: string, req: NodeRequest): Promise<NodePage>;
|
|
25
|
+
search(query: string, req: NodeRequest): Promise<NodePage>;
|
|
26
|
+
private page;
|
|
27
|
+
/** Strip children; flag `lazy` when the source node actually has children. */
|
|
28
|
+
private toShallow;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { treeSelectStyles } from './tree-select.styles';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { TreeSelectMode, TreeSelectVariant, NodePage, NodeRequest, TreeSelectProvider, TreeSelectChangeEventDetail, TreeNode, } from './tree-select';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { TreeNode } from '@mintplayer/web-components/treeview';
|
|
2
|
+
/**
|
|
3
|
+
* Selection arity / affordance.
|
|
4
|
+
* - `single` — one node; `value` is a scalar `TreeNode | null`.
|
|
5
|
+
* - `multiple` — many nodes shown as chips; `value` is a `TreeNode[]`.
|
|
6
|
+
* - `checkbox` — many nodes with a checkbox per row; `value` is a `TreeNode[]`.
|
|
7
|
+
* Pair with `cascadeSelect` for parent/child propagation.
|
|
8
|
+
*/
|
|
9
|
+
export type TreeSelectMode = 'single' | 'multiple' | 'checkbox';
|
|
10
|
+
/**
|
|
11
|
+
* Trigger shape.
|
|
12
|
+
* - `textbox` — an inline search input that opens the panel (select2-style).
|
|
13
|
+
* - `button` — a button that opens a panel containing the search box.
|
|
14
|
+
*/
|
|
15
|
+
export type TreeSelectVariant = 'textbox' | 'button';
|
|
16
|
+
/** A page of nodes returned by the {@link TreeSelectProvider}. */
|
|
17
|
+
export interface NodePage {
|
|
18
|
+
nodes: TreeNode[];
|
|
19
|
+
/** `true` when more rows exist beyond this page (drives "load more"). */
|
|
20
|
+
hasMore?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** Per-call request metadata handed to every provider method. */
|
|
23
|
+
export interface NodeRequest {
|
|
24
|
+
/** Cursor for paging — number of rows already loaded for this list. */
|
|
25
|
+
offset?: number;
|
|
26
|
+
/** Aborts when a newer request supersedes this one (stale-search guard). */
|
|
27
|
+
signal: AbortSignal;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The single external data port. Data is async-only — there is no static
|
|
31
|
+
* `items` input. Each method is abortable and paged.
|
|
32
|
+
*
|
|
33
|
+
* - `loadRoots` — top-level nodes (called on first open / "load more" root).
|
|
34
|
+
* - `search` — server-side search across the whole tree for `query`.
|
|
35
|
+
* - `loadChildren` — lazy children of an expandable node (`ChildCount > 0`).
|
|
36
|
+
*/
|
|
37
|
+
export interface TreeSelectProvider {
|
|
38
|
+
loadRoots(req: NodeRequest): Promise<NodePage>;
|
|
39
|
+
search(query: string, req: NodeRequest): Promise<NodePage>;
|
|
40
|
+
loadChildren(parentId: string, req: NodeRequest): Promise<NodePage>;
|
|
41
|
+
}
|
|
42
|
+
/** Detail of the `value-change` event. */
|
|
43
|
+
export interface TreeSelectChangeEventDetail {
|
|
44
|
+
/** Scalar in `single` mode, array otherwise. */
|
|
45
|
+
value: TreeNode | TreeNode[] | null;
|
|
46
|
+
/** The node toggled on, when this change added one. */
|
|
47
|
+
added?: TreeNode;
|
|
48
|
+
/** The node toggled off, when this change removed one. */
|
|
49
|
+
removed?: TreeNode;
|
|
50
|
+
}
|
|
51
|
+
export type { TreeNode };
|
package/treeview/index.mjs
CHANGED