@fluid-topics/ftds-tree-list 2.1.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/README.md +19 -0
- package/build/define.d.ts +1 -0
- package/build/define.js +3 -0
- package/build/definitions.d.ts +5 -0
- package/build/definitions.js +4 -0
- package/build/ftds-tree-list.d.ts +73 -0
- package/build/ftds-tree-list.js +579 -0
- package/build/ftds-tree-list.light.js +1951 -0
- package/build/ftds-tree-list.min.js +2066 -0
- package/build/ftds-tree-list.properties.d.ts +21 -0
- package/build/ftds-tree-list.properties.js +1 -0
- package/build/ftds-tree-list.styles.d.ts +2 -0
- package/build/ftds-tree-list.styles.js +254 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +4 -0
- package/build/model/FtdsTreeListData.d.ts +19 -0
- package/build/model/FtdsTreeListData.js +50 -0
- package/package.json +34 -0
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { html, nothing, } from "lit";
|
|
8
|
+
import { property, state, } from "lit/decorators.js";
|
|
9
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
10
|
+
import { when } from "lit/directives/when.js";
|
|
11
|
+
import { ifDefined } from "lit/directives/if-defined.js";
|
|
12
|
+
import { classMap } from "lit/directives/class-map.js";
|
|
13
|
+
import { DesignSystemFamily, FtLitElement, hasChanged, jsonProperty, numberProperty, } from "@fluid-topics/ft-wc-utils";
|
|
14
|
+
import { FtdsTypography, FtdsTypographyVariants, } from "@fluid-topics/ftds-typography";
|
|
15
|
+
import { FtdsIcon, FtdsIcons, FtdsIconVariants, } from "@fluid-topics/ftds-icon";
|
|
16
|
+
import { FtdsButton } from "@fluid-topics/ftds-button";
|
|
17
|
+
import { styles } from "./ftds-tree-list.styles";
|
|
18
|
+
import { createLoadMoreNode, getPathToNode, TraversalInstruction, traverseVisibleTree, } from "./model/FtdsTreeListData";
|
|
19
|
+
import { cactusSvg } from "@fluid-topics/ft-assets";
|
|
20
|
+
import { FtSkeleton } from "@fluid-topics/ft-skeleton";
|
|
21
|
+
export class NodeSelectedEvent extends CustomEvent {
|
|
22
|
+
constructor(node) {
|
|
23
|
+
super("node-selected", { detail: node });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export class FtdsTreeList extends FtLitElement {
|
|
27
|
+
constructor() {
|
|
28
|
+
super(...arguments);
|
|
29
|
+
this.label = "";
|
|
30
|
+
this.pageSize = 10;
|
|
31
|
+
this.expandLabel = "Expand";
|
|
32
|
+
this.collapseLabel = "Collapse";
|
|
33
|
+
this.loadMoreLabel = "Load more";
|
|
34
|
+
this.expandParametrizedLabel = "Expand {0}";
|
|
35
|
+
this.collapseParametrizedLabel = "Collapse {0}";
|
|
36
|
+
this.expandAllLabel = "Expand all";
|
|
37
|
+
this.collapseAllLabel = "Collapse all";
|
|
38
|
+
this.loading = false;
|
|
39
|
+
this.childrenCounts = new Map();
|
|
40
|
+
this.userOpenedNodes = new Set();
|
|
41
|
+
this.userClosedNodes = new Set();
|
|
42
|
+
}
|
|
43
|
+
expandAll() {
|
|
44
|
+
this.userClosedNodes = new Set();
|
|
45
|
+
this.userOpenedNodes = new Set(this.data.rootNodes.flatMap((n) => this.getAllClosedNodes(n)));
|
|
46
|
+
this.isTreeSelectorCollapsed = false;
|
|
47
|
+
}
|
|
48
|
+
collapseAll() {
|
|
49
|
+
this.userOpenedNodes = new Set();
|
|
50
|
+
this.userClosedNodes = new Set(this.data.rootNodes.filter((n) => n.expanded).map((n) => n.value));
|
|
51
|
+
this.isTreeSelectorCollapsed = true;
|
|
52
|
+
}
|
|
53
|
+
getItemSelector(item) {
|
|
54
|
+
var _a;
|
|
55
|
+
return (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector(`[data-value="${item.value}"]`);
|
|
56
|
+
}
|
|
57
|
+
isNodeExpanded(node) {
|
|
58
|
+
return (!this.userClosedNodes.has(node.value)
|
|
59
|
+
&& (node.expanded || this.userOpenedNodes.has(node.value)));
|
|
60
|
+
}
|
|
61
|
+
setFocusToTreeItem(item) {
|
|
62
|
+
var _a, _b;
|
|
63
|
+
(_b = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector(`[tabindex="0"]`)) === null || _b === void 0 ? void 0 : _b.setAttribute("tabindex", "-1");
|
|
64
|
+
const itemEl = this.getItemSelector(item);
|
|
65
|
+
itemEl === null || itemEl === void 0 ? void 0 : itemEl.focus();
|
|
66
|
+
itemEl === null || itemEl === void 0 ? void 0 : itemEl.setAttribute("tabindex", "0");
|
|
67
|
+
}
|
|
68
|
+
async selectNodeByBreadcrumb(breadcrumb) {
|
|
69
|
+
let currentNode = this.data.rootNodes.find((root) => root.value === breadcrumb[0]);
|
|
70
|
+
for (let i = 0; i < breadcrumb.length - 1; i++) {
|
|
71
|
+
currentNode = this.displayChild(currentNode, breadcrumb[i + 1]);
|
|
72
|
+
}
|
|
73
|
+
await this.updateComplete;
|
|
74
|
+
this.selectNode(currentNode);
|
|
75
|
+
}
|
|
76
|
+
render() {
|
|
77
|
+
const atLeastOneRootNodeIsExpandable = this.data && this.data.rootNodes && this.data.rootNodes.length > 0
|
|
78
|
+
? this.data.rootNodes.some((rootNode) => rootNode.children.length > 0)
|
|
79
|
+
: false;
|
|
80
|
+
return html `
|
|
81
|
+
<div part="header">
|
|
82
|
+
${when(this.label.length > 0, () => this.renderLeftHeader())}
|
|
83
|
+
${when(atLeastOneRootNodeIsExpandable, () => html `
|
|
84
|
+
<ftds-button
|
|
85
|
+
dense
|
|
86
|
+
tooltipposition="bottom"
|
|
87
|
+
part="expand-button"
|
|
88
|
+
family="${DesignSystemFamily.neutral}"
|
|
89
|
+
icon="${FtdsIcons.ARROWS_TO_LINE}"
|
|
90
|
+
label="${this.collapseAllLabel}"
|
|
91
|
+
@click=${() => this.collapseAll()}
|
|
92
|
+
>
|
|
93
|
+
${this.collapseAllLabel}
|
|
94
|
+
</ftds-button>
|
|
95
|
+
`)}
|
|
96
|
+
</div>
|
|
97
|
+
${this.renderBody()}
|
|
98
|
+
`;
|
|
99
|
+
}
|
|
100
|
+
renderBody() {
|
|
101
|
+
var _a;
|
|
102
|
+
if (this.loading) {
|
|
103
|
+
return this.renderLoadingState();
|
|
104
|
+
}
|
|
105
|
+
else if (!((_a = this.data) === null || _a === void 0 ? void 0 : _a.rootNodes) || this.data.rootNodes.length <= 0) {
|
|
106
|
+
return this.renderEmptyState();
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
return html `
|
|
110
|
+
<ul role="tree" class="ftds-tree-list" aria-labelledby="${this.label}">
|
|
111
|
+
${repeat(this.data.rootNodes, (node) => node.value, (node) => this.renderNode(node))}
|
|
112
|
+
</ul>`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
renderLoadingState() {
|
|
116
|
+
const skeletons = [
|
|
117
|
+
50, 45, 30, 35, 25,
|
|
118
|
+
44, 35, 27, 42, 25,
|
|
119
|
+
47, 30, 29, 45, 49,
|
|
120
|
+
].map((width) => html `
|
|
121
|
+
<li>
|
|
122
|
+
<div class="ftds-tree-list--item">
|
|
123
|
+
<ft-skeleton style="--ft-skeleton--width: ${width}%"></ft-skeleton>
|
|
124
|
+
</div>
|
|
125
|
+
</li>`);
|
|
126
|
+
return html `
|
|
127
|
+
<ul class="ftds-tree-list loading-state">${skeletons}</ul>`;
|
|
128
|
+
}
|
|
129
|
+
renderLeftHeader() {
|
|
130
|
+
if (this.loading) {
|
|
131
|
+
return html `
|
|
132
|
+
<div class="header-left">
|
|
133
|
+
<ftds-typography class="header-label" variant="${FtdsTypographyVariants.body1semibold}">
|
|
134
|
+
${this.label}
|
|
135
|
+
</ftds-typography>
|
|
136
|
+
<ft-skeleton class="node-count-loader"></ft-skeleton>
|
|
137
|
+
</div>
|
|
138
|
+
`;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
return html `
|
|
142
|
+
<ftds-typography class="header-label" variant="${FtdsTypographyVariants.body1semibold}">
|
|
143
|
+
${this.label}
|
|
144
|
+
<ftds-typography variant="${FtdsTypographyVariants.body2medium}" class="node-children-count">
|
|
145
|
+
(${this.getEntriesCount()})
|
|
146
|
+
</ftds-typography>
|
|
147
|
+
</ftds-typography>
|
|
148
|
+
`;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
renderNode(node) {
|
|
152
|
+
var _a;
|
|
153
|
+
const isNodeExpanded = this.isNodeExpanded(node);
|
|
154
|
+
node.loadedCount = (_a = node.loadedCount) !== null && _a !== void 0 ? _a : this.pageSize;
|
|
155
|
+
if (!node.loadedCount) {
|
|
156
|
+
node.loadedCount = node.children.length;
|
|
157
|
+
}
|
|
158
|
+
const visibleChildren = node.children.slice(0, node.loadedCount);
|
|
159
|
+
const childrenClasses = {
|
|
160
|
+
expanded: isNodeExpanded,
|
|
161
|
+
collapsed: isNodeExpanded,
|
|
162
|
+
"with-expandable": this.hasExpandableChildren(node),
|
|
163
|
+
"with-children": this.hasChildren(node),
|
|
164
|
+
};
|
|
165
|
+
return html `
|
|
166
|
+
<li role="none">
|
|
167
|
+
<a
|
|
168
|
+
part="node-container"
|
|
169
|
+
role="treeitem"
|
|
170
|
+
data-value="${node.value}"
|
|
171
|
+
aria-expanded="${ifDefined(isNodeExpanded)}"
|
|
172
|
+
class="ftds-tree-list--item ${classMap(childrenClasses)}"
|
|
173
|
+
tabindex="-1"
|
|
174
|
+
@keydown=${(e) => this.onKeydown(e, node, false)}
|
|
175
|
+
>
|
|
176
|
+
${when(this.hasChildren(node), () => html `
|
|
177
|
+
<ftds-icon
|
|
178
|
+
part="node-expand"
|
|
179
|
+
icon="${isNodeExpanded ? FtdsIcons.ANGLE_DOWN : FtdsIcons.ANGLE_RIGHT}"
|
|
180
|
+
variant="${FtdsIconVariants.regular}"
|
|
181
|
+
@click=${() => this.expandNode(!isNodeExpanded, node.value)}
|
|
182
|
+
></ftds-icon>
|
|
183
|
+
`)}
|
|
184
|
+
<div class="node-label-container" @click=${(e) => this.handleNodeSelectEvent(e, node)}>
|
|
185
|
+
<ftds-typography
|
|
186
|
+
part="node-label"
|
|
187
|
+
variant="${FtdsTypographyVariants.body2medium}"
|
|
188
|
+
>
|
|
189
|
+
${node.label}
|
|
190
|
+
</ftds-typography>
|
|
191
|
+
${when(this.hasChildren(node), () => html `
|
|
192
|
+
<ftds-typography variant="${FtdsTypographyVariants.body2medium}" class="node-children-count">
|
|
193
|
+
(${this.getChildrenCount(node)})
|
|
194
|
+
</ftds-typography>
|
|
195
|
+
`)}
|
|
196
|
+
</div>
|
|
197
|
+
</a>
|
|
198
|
+
${this.hasChildren(node) ? this.renderChildNodes(isNodeExpanded, visibleChildren, node, childrenClasses) : nothing}
|
|
199
|
+
</li>
|
|
200
|
+
`;
|
|
201
|
+
}
|
|
202
|
+
renderChildNodes(isNodeExpanded, visibleChildren, node, childrenClasses) {
|
|
203
|
+
return html `
|
|
204
|
+
<ul role="group">
|
|
205
|
+
${when(isNodeExpanded, () => html `
|
|
206
|
+
${repeat(visibleChildren, (c) => c.value, (c) => this.renderNode(c))}
|
|
207
|
+
${node.loadedCount && node.children.length > node.loadedCount
|
|
208
|
+
? this.renderShowMore(node, childrenClasses) : nothing}`)}
|
|
209
|
+
</ul>
|
|
210
|
+
`;
|
|
211
|
+
}
|
|
212
|
+
renderShowMore(node, childrenClasses) {
|
|
213
|
+
return html `
|
|
214
|
+
<li role="none">
|
|
215
|
+
<a part="load-more"
|
|
216
|
+
role="treeitem"
|
|
217
|
+
data-value="load-more-${node.value}"
|
|
218
|
+
icon="${FtdsIcons.ARROW_DOWN}"
|
|
219
|
+
tabindex="-1"
|
|
220
|
+
aria-expanded="false"
|
|
221
|
+
class="ftds-tree-list--item ${classMap(childrenClasses)}"
|
|
222
|
+
@click=${() => this.loadMore(node)}
|
|
223
|
+
@keydown=${(e) => this.onKeydown(e, createLoadMoreNode(node), true, node)}>
|
|
224
|
+
<ftds-icon icon="${FtdsIcons.ARROW_DOWN}" variant="${FtdsIconVariants.regular}"></ftds-icon>
|
|
225
|
+
<ftds-typography
|
|
226
|
+
part="node-label"
|
|
227
|
+
variant="${FtdsTypographyVariants.body2medium}"
|
|
228
|
+
>
|
|
229
|
+
${this.loadMoreLabel}
|
|
230
|
+
</ftds-typography>
|
|
231
|
+
</a>
|
|
232
|
+
</li>
|
|
233
|
+
`;
|
|
234
|
+
}
|
|
235
|
+
renderEmptyState() {
|
|
236
|
+
var _a;
|
|
237
|
+
return html `
|
|
238
|
+
<div class="empty-state">
|
|
239
|
+
${((_a = this.emptyState) === null || _a === void 0 ? void 0 : _a.noImage) ? nothing : cactusSvg}
|
|
240
|
+
${this.renderEmptyStateTitle()}
|
|
241
|
+
${this.renderEmptyStateDescription()}
|
|
242
|
+
</div>
|
|
243
|
+
`;
|
|
244
|
+
}
|
|
245
|
+
renderEmptyStateTitle() {
|
|
246
|
+
if (!this.emptyState) {
|
|
247
|
+
return nothing;
|
|
248
|
+
}
|
|
249
|
+
if (typeof this.emptyState.title === "string") {
|
|
250
|
+
return html `
|
|
251
|
+
<ftds-typography class="empty-state--title" variant="${FtdsTypographyVariants.body1medium}">
|
|
252
|
+
${this.emptyState.title}
|
|
253
|
+
</ftds-typography>`;
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
return this.emptyState.title;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
renderEmptyStateDescription() {
|
|
260
|
+
var _a;
|
|
261
|
+
if (!((_a = this.emptyState) === null || _a === void 0 ? void 0 : _a.description)) {
|
|
262
|
+
return nothing;
|
|
263
|
+
}
|
|
264
|
+
if (typeof this.emptyState.description === "string") {
|
|
265
|
+
this.emptyState.description = [this.emptyState.description];
|
|
266
|
+
}
|
|
267
|
+
if (this.emptyState.description instanceof Array) {
|
|
268
|
+
const labels = this.emptyState.description.map((label) => html `
|
|
269
|
+
<ftds-typography variant="${FtdsTypographyVariants.body1medium}">
|
|
270
|
+
${label}
|
|
271
|
+
</ftds-typography>`);
|
|
272
|
+
return html `
|
|
273
|
+
<div class="empty-state--description">${labels}</div>`;
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
return this.emptyState.description;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
willUpdate(props) {
|
|
280
|
+
var _a, _b;
|
|
281
|
+
super.willUpdate(props);
|
|
282
|
+
if (!this.selectedNode && ((_a = this.data) === null || _a === void 0 ? void 0 : _a.rootNodes)) {
|
|
283
|
+
this.selectedNode = (_b = this.data) === null || _b === void 0 ? void 0 : _b.rootNodes[0];
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
updated(props) {
|
|
287
|
+
super.updated(props);
|
|
288
|
+
if (this.nodeToFocus) {
|
|
289
|
+
this.setFocusToTreeItem(this.nodeToFocus);
|
|
290
|
+
this.nodeToFocus = undefined;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
onKeydown(event, currentNode, isLoadMore, parentNode) {
|
|
294
|
+
let needToStopPropagation = false;
|
|
295
|
+
const tree = this.data.rootNodes;
|
|
296
|
+
const visibleItems = this.getAdjacentVisibleTreeItems(tree, currentNode);
|
|
297
|
+
const currentNodeIndex = visibleItems.findIndex((node) => node.value === currentNode.value);
|
|
298
|
+
if (event.shiftKey && (event.key === " " || event.key === "Space")) {
|
|
299
|
+
event.stopPropagation();
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
const nodeExpanded = this.isNodeExpanded(currentNode);
|
|
303
|
+
switch (event.key) {
|
|
304
|
+
case "Enter":
|
|
305
|
+
case " ":
|
|
306
|
+
case "Space":
|
|
307
|
+
if (isLoadMore && parentNode) {
|
|
308
|
+
this.loadMore(parentNode);
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
this.handleNodeSelectEvent(event, currentNode);
|
|
312
|
+
}
|
|
313
|
+
needToStopPropagation = true;
|
|
314
|
+
break;
|
|
315
|
+
case "ArrowDown":
|
|
316
|
+
this.setFocusToNextNode(visibleItems, currentNodeIndex);
|
|
317
|
+
needToStopPropagation = true;
|
|
318
|
+
break;
|
|
319
|
+
case "ArrowUp":
|
|
320
|
+
this.setFocusToPreviousNode(visibleItems, currentNodeIndex);
|
|
321
|
+
needToStopPropagation = true;
|
|
322
|
+
break;
|
|
323
|
+
case "ArrowRight":
|
|
324
|
+
if (nodeExpanded) {
|
|
325
|
+
if (currentNode.children.length > 0) {
|
|
326
|
+
this.setFocusToTreeItem(currentNode.children[0]);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
this.expandNode(!nodeExpanded, currentNode.value);
|
|
331
|
+
}
|
|
332
|
+
needToStopPropagation = true;
|
|
333
|
+
break;
|
|
334
|
+
case "ArrowLeft":
|
|
335
|
+
if (nodeExpanded) {
|
|
336
|
+
this.expandNode(!nodeExpanded, currentNode.value);
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
const breadcrumb = getPathToNode(tree, currentNode.value);
|
|
340
|
+
if (breadcrumb && breadcrumb.length > 1) {
|
|
341
|
+
const parent = breadcrumb[breadcrumb.length - 2];
|
|
342
|
+
this.setFocusToTreeItem(parent);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
needToStopPropagation = true;
|
|
346
|
+
break;
|
|
347
|
+
case "Home":
|
|
348
|
+
this.setFocusToTreeItem(visibleItems[0]);
|
|
349
|
+
needToStopPropagation = true;
|
|
350
|
+
break;
|
|
351
|
+
case "End":
|
|
352
|
+
this.setFocusToTreeItem(visibleItems[visibleItems.length - 1]);
|
|
353
|
+
needToStopPropagation = true;
|
|
354
|
+
break;
|
|
355
|
+
case "*":
|
|
356
|
+
const breadcrumb = getPathToNode(tree, currentNode.value);
|
|
357
|
+
if (breadcrumb && breadcrumb.length > 1) {
|
|
358
|
+
const siblings = breadcrumb[breadcrumb.length - 2].children;
|
|
359
|
+
for (const node of siblings) {
|
|
360
|
+
this.expandNode(true, node.value);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
else if ((breadcrumb === null || breadcrumb === void 0 ? void 0 : breadcrumb.length) == 1) {
|
|
364
|
+
for (const rootNode of this.data.rootNodes) {
|
|
365
|
+
this.expandNode(true, rootNode.value);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
needToStopPropagation = true;
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
if (needToStopPropagation) {
|
|
373
|
+
event.stopPropagation();
|
|
374
|
+
event.preventDefault();
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
setFocusToPreviousNode(visibleItems, currentNodeIndex) {
|
|
378
|
+
if (visibleItems[currentNodeIndex - 1]) {
|
|
379
|
+
this.setFocusToTreeItem(visibleItems[currentNodeIndex - 1]);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
setFocusToNextNode(visibleItems, currentNodeIndex) {
|
|
383
|
+
if (visibleItems[currentNodeIndex + 1]) {
|
|
384
|
+
this.setFocusToTreeItem(visibleItems[currentNodeIndex + 1]);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
getAdjacentVisibleTreeItems(tree, currentNode) {
|
|
388
|
+
const visibleTreeItems = [];
|
|
389
|
+
let stopAfterNext = false;
|
|
390
|
+
let push = false;
|
|
391
|
+
traverseVisibleTree(tree, (node) => {
|
|
392
|
+
const last = stopAfterNext;
|
|
393
|
+
if (node.value === currentNode.value) {
|
|
394
|
+
stopAfterNext = true;
|
|
395
|
+
push = true;
|
|
396
|
+
}
|
|
397
|
+
if (this.isVisible(node)) {
|
|
398
|
+
if (push) {
|
|
399
|
+
visibleTreeItems.push(node);
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
visibleTreeItems[0] = node;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return new TraversalInstruction(last, !this.isNodeExpanded(node));
|
|
406
|
+
});
|
|
407
|
+
return visibleTreeItems;
|
|
408
|
+
}
|
|
409
|
+
isVisible(treeitem) {
|
|
410
|
+
var _a, _b;
|
|
411
|
+
const tree = this.data.rootNodes;
|
|
412
|
+
if (treeitem.value.includes("load-more-")) {
|
|
413
|
+
const parentValue = treeitem.value.replace("load-more-", "");
|
|
414
|
+
const parentItem = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector(`[data-value="${parentValue}"]`);
|
|
415
|
+
if (!parentItem || parentItem.getAttribute("aria-expanded") === "false") {
|
|
416
|
+
return false;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
const pathToNode = getPathToNode(tree, treeitem.value);
|
|
420
|
+
if (pathToNode && pathToNode.length > 1) {
|
|
421
|
+
const parentNode = pathToNode[(pathToNode === null || pathToNode === void 0 ? void 0 : pathToNode.length) - 2];
|
|
422
|
+
const parentItem = this.getItemSelector(parentNode);
|
|
423
|
+
const childIndex = parentNode.children.findIndex((child) => child.value === treeitem.value);
|
|
424
|
+
if (!parentItem || parentItem.getAttribute("aria-expanded") === "false" || childIndex >= ((_b = parentNode.loadedCount) !== null && _b !== void 0 ? _b : Infinity)) {
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return true;
|
|
429
|
+
}
|
|
430
|
+
expandNode(expanded, currentNodeValue) {
|
|
431
|
+
if (expanded) {
|
|
432
|
+
if (this.userClosedNodes.has(currentNodeValue)) {
|
|
433
|
+
this.userClosedNodes.delete(currentNodeValue);
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
this.userOpenedNodes.add(currentNodeValue);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
if (this.userOpenedNodes.has(currentNodeValue)) {
|
|
441
|
+
this.userOpenedNodes.delete(currentNodeValue);
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
this.userClosedNodes.add(currentNodeValue);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
this.requestUpdate();
|
|
448
|
+
}
|
|
449
|
+
toggleExpandAll() {
|
|
450
|
+
if (this.isTreeSelectorCollapsed) {
|
|
451
|
+
this.expandAll();
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
this.collapseAll();
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
getAllClosedNodes(node) {
|
|
458
|
+
if (node.children.length !== 0) {
|
|
459
|
+
return [
|
|
460
|
+
...(node.expanded ? [] : [node.value]),
|
|
461
|
+
...node.children.flatMap((c) => this.getAllClosedNodes(c)),
|
|
462
|
+
];
|
|
463
|
+
}
|
|
464
|
+
else {
|
|
465
|
+
return [];
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
getChildrenCount(node) {
|
|
469
|
+
if (this.childrenCounts.has(node.value)) {
|
|
470
|
+
return this.childrenCounts.get(node.value);
|
|
471
|
+
}
|
|
472
|
+
const childrenCount = node.children.reduce((count, child) => count + this.getChildrenCount(child) + 1, 0);
|
|
473
|
+
this.childrenCounts.set(node.value, childrenCount);
|
|
474
|
+
return childrenCount;
|
|
475
|
+
}
|
|
476
|
+
getEntriesCount() {
|
|
477
|
+
var _a, _b;
|
|
478
|
+
return (_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a.rootNodes.reduce((count, node) => count + this.getChildrenCount(node) + 1, 0)) !== null && _b !== void 0 ? _b : 0;
|
|
479
|
+
}
|
|
480
|
+
hasExpandableChildren(node) {
|
|
481
|
+
return node.children.some((child) => child.children.length > 0);
|
|
482
|
+
}
|
|
483
|
+
hasChildren(node) {
|
|
484
|
+
return node.children.length > 0;
|
|
485
|
+
}
|
|
486
|
+
loadMore(node) {
|
|
487
|
+
var _a;
|
|
488
|
+
if (this.pageSize) {
|
|
489
|
+
const prevLoadedCount = (_a = node.loadedCount) !== null && _a !== void 0 ? _a : this.pageSize;
|
|
490
|
+
node.loadedCount = prevLoadedCount + this.pageSize;
|
|
491
|
+
this.nodeToFocus = node.children[prevLoadedCount];
|
|
492
|
+
this.requestUpdate();
|
|
493
|
+
this.setFocusToTreeItem(node.children[prevLoadedCount]);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
displayChild(currentNode, childValue) {
|
|
497
|
+
var _a;
|
|
498
|
+
this.expandNode(true, currentNode.value);
|
|
499
|
+
const childIndex = currentNode.children.findIndex((child) => child.value === childValue);
|
|
500
|
+
currentNode.loadedCount = Math.max((_a = currentNode.loadedCount) !== null && _a !== void 0 ? _a : this.pageSize, childIndex + 1);
|
|
501
|
+
return currentNode.children[childIndex];
|
|
502
|
+
}
|
|
503
|
+
handleNodeSelectEvent(e, node) {
|
|
504
|
+
e.preventDefault();
|
|
505
|
+
this.selectNode(node);
|
|
506
|
+
e.stopPropagation();
|
|
507
|
+
}
|
|
508
|
+
selectNode(node) {
|
|
509
|
+
var _a, _b;
|
|
510
|
+
const oldNode = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector("[aria-selected]");
|
|
511
|
+
oldNode === null || oldNode === void 0 ? void 0 : oldNode.removeAttribute("aria-selected");
|
|
512
|
+
const nodeContainer = (_b = this.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector(`[data-value="${node.value}"]`);
|
|
513
|
+
nodeContainer.setAttribute("aria-selected", "true");
|
|
514
|
+
this.selectedNode = node;
|
|
515
|
+
this.dispatchEvent(new NodeSelectedEvent(node));
|
|
516
|
+
this.setFocusToTreeItem(node);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
FtdsTreeList.elementDefinitions = {
|
|
520
|
+
"ftds-typography": FtdsTypography,
|
|
521
|
+
"ftds-button": FtdsButton,
|
|
522
|
+
"ftds-icon": FtdsIcon,
|
|
523
|
+
"ft-skeleton": FtSkeleton,
|
|
524
|
+
};
|
|
525
|
+
FtdsTreeList.styles = styles;
|
|
526
|
+
__decorate([
|
|
527
|
+
property()
|
|
528
|
+
], FtdsTreeList.prototype, "data", void 0);
|
|
529
|
+
__decorate([
|
|
530
|
+
property()
|
|
531
|
+
], FtdsTreeList.prototype, "label", void 0);
|
|
532
|
+
__decorate([
|
|
533
|
+
numberProperty()
|
|
534
|
+
], FtdsTreeList.prototype, "pageSize", void 0);
|
|
535
|
+
__decorate([
|
|
536
|
+
property()
|
|
537
|
+
], FtdsTreeList.prototype, "selectedNode", void 0);
|
|
538
|
+
__decorate([
|
|
539
|
+
property()
|
|
540
|
+
], FtdsTreeList.prototype, "expandLabel", void 0);
|
|
541
|
+
__decorate([
|
|
542
|
+
property()
|
|
543
|
+
], FtdsTreeList.prototype, "collapseLabel", void 0);
|
|
544
|
+
__decorate([
|
|
545
|
+
property()
|
|
546
|
+
], FtdsTreeList.prototype, "loadMoreLabel", void 0);
|
|
547
|
+
__decorate([
|
|
548
|
+
property()
|
|
549
|
+
], FtdsTreeList.prototype, "expandParametrizedLabel", void 0);
|
|
550
|
+
__decorate([
|
|
551
|
+
property()
|
|
552
|
+
], FtdsTreeList.prototype, "collapseParametrizedLabel", void 0);
|
|
553
|
+
__decorate([
|
|
554
|
+
property()
|
|
555
|
+
], FtdsTreeList.prototype, "expandAllLabel", void 0);
|
|
556
|
+
__decorate([
|
|
557
|
+
property()
|
|
558
|
+
], FtdsTreeList.prototype, "collapseAllLabel", void 0);
|
|
559
|
+
__decorate([
|
|
560
|
+
jsonProperty(undefined)
|
|
561
|
+
], FtdsTreeList.prototype, "emptyState", void 0);
|
|
562
|
+
__decorate([
|
|
563
|
+
property({ type: Boolean })
|
|
564
|
+
], FtdsTreeList.prototype, "loading", void 0);
|
|
565
|
+
__decorate([
|
|
566
|
+
state()
|
|
567
|
+
], FtdsTreeList.prototype, "nodeToFocus", void 0);
|
|
568
|
+
__decorate([
|
|
569
|
+
state()
|
|
570
|
+
], FtdsTreeList.prototype, "isTreeSelectorCollapsed", void 0);
|
|
571
|
+
__decorate([
|
|
572
|
+
state()
|
|
573
|
+
], FtdsTreeList.prototype, "childrenCounts", void 0);
|
|
574
|
+
__decorate([
|
|
575
|
+
state({ hasChanged })
|
|
576
|
+
], FtdsTreeList.prototype, "userOpenedNodes", void 0);
|
|
577
|
+
__decorate([
|
|
578
|
+
state({ hasChanged })
|
|
579
|
+
], FtdsTreeList.prototype, "userClosedNodes", void 0);
|