@fluid-topics/ft-tree-list 1.2.67
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 +31 -0
- package/build/ft-tree-list.light.js +1410 -0
- package/build/ft-tree-list.min.js +1609 -0
- package/build/ftds-tree-list.d.ts +64 -0
- package/build/ftds-tree-list.js +489 -0
- package/build/ftds-tree-list.properties.d.ts +18 -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 +211 -0
- package/build/index.d.ts +3 -0
- package/build/index.js +6 -0
- package/build/model/FtTreeListData.d.ts +18 -0
- package/build/model/FtTreeListData.js +50 -0
- package/package.json +31 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { PropertyValues } from "lit";
|
|
2
|
+
import { ElementDefinitionsMap, FtLitElement } from "@fluid-topics/ft-wc-utils";
|
|
3
|
+
import { EmptyStateConfiguration, FtdsTreeListProperties } from "./ftds-tree-list.properties";
|
|
4
|
+
import { FtTreeListData, FtTreeNode } from "./model/FtTreeListData";
|
|
5
|
+
import { TemplateResult } from "lit/development";
|
|
6
|
+
export declare class NodeSelectedEvent extends CustomEvent<FtTreeNode> {
|
|
7
|
+
constructor(node: FtTreeNode);
|
|
8
|
+
}
|
|
9
|
+
export declare class FtdsTreeList extends FtLitElement implements FtdsTreeListProperties {
|
|
10
|
+
static elementDefinitions: ElementDefinitionsMap;
|
|
11
|
+
static styles: import("lit").CSSResult;
|
|
12
|
+
data?: FtTreeListData;
|
|
13
|
+
label: string;
|
|
14
|
+
pageSize?: number;
|
|
15
|
+
selectedNode?: FtTreeNode;
|
|
16
|
+
expandLabel: string;
|
|
17
|
+
collapseLabel: string;
|
|
18
|
+
showMoreLabel: string;
|
|
19
|
+
expandParametrizedLabel: string;
|
|
20
|
+
collapseParametrizedLabel: string;
|
|
21
|
+
expandAllLabel: string;
|
|
22
|
+
collapseAllLabel: string;
|
|
23
|
+
emptyState?: EmptyStateConfiguration;
|
|
24
|
+
nodeToFocus?: FtTreeNode;
|
|
25
|
+
isTreeSelectorCollapsed?: boolean;
|
|
26
|
+
userOpenedNodes: Set<string>;
|
|
27
|
+
userClosedNodes: Set<string>;
|
|
28
|
+
expandAll(): void;
|
|
29
|
+
collapseAll(): void;
|
|
30
|
+
getItemSelector(item: FtTreeNode): HTMLElement;
|
|
31
|
+
isNodeExpanded(node: FtTreeNode): boolean;
|
|
32
|
+
setFocusToTreeItem(item: FtTreeNode): void;
|
|
33
|
+
protected render(): TemplateResult<1>;
|
|
34
|
+
protected renderNode(node: FtTreeNode): unknown;
|
|
35
|
+
protected renderChildNodes(isNodeExpanded: boolean, visibleChildren: FtTreeNode[], node: FtTreeNode, childrenClasses: {
|
|
36
|
+
expanded: boolean;
|
|
37
|
+
collapsed: boolean;
|
|
38
|
+
"with-expandable": boolean;
|
|
39
|
+
"with-children": boolean;
|
|
40
|
+
}): TemplateResult<1>;
|
|
41
|
+
protected renderShowMore(node: FtTreeNode, childrenClasses: {
|
|
42
|
+
expanded: boolean;
|
|
43
|
+
collapsed: boolean;
|
|
44
|
+
"with-expandable": boolean;
|
|
45
|
+
"with-children": boolean;
|
|
46
|
+
}): TemplateResult<1>;
|
|
47
|
+
protected renderEmptyState(): TemplateResult<1>;
|
|
48
|
+
protected willUpdate(props: PropertyValues): void;
|
|
49
|
+
protected updated(props: PropertyValues): void;
|
|
50
|
+
protected onKeydown(event: KeyboardEvent, currentNode: FtTreeNode, isLoadMore: boolean, parentNode?: FtTreeNode): void;
|
|
51
|
+
protected setFocusToPreviousNode(visibleItems: FtTreeNode[], currentNodeIndex: number): void;
|
|
52
|
+
protected setFocusToNextNode(visibleItems: FtTreeNode[], currentNodeIndex: number): void;
|
|
53
|
+
protected getAdjacentVisibleTreeItems(tree: FtTreeNode[], currentNode: FtTreeNode): FtTreeNode[];
|
|
54
|
+
protected isVisible(treeitem: FtTreeNode): boolean;
|
|
55
|
+
protected expandNode(expanded: boolean, currentNodeValue: string): void;
|
|
56
|
+
protected toggleExpandAll(): void;
|
|
57
|
+
protected getAllClosedNodes(node: FtTreeNode): string[];
|
|
58
|
+
protected getChildrenCount(node: FtTreeNode): number;
|
|
59
|
+
protected getEntriesCount(): number;
|
|
60
|
+
protected hasExpandableChildren(node: FtTreeNode): boolean;
|
|
61
|
+
protected hasChildren(node: FtTreeNode): boolean;
|
|
62
|
+
protected loadMore(node: FtTreeNode): void;
|
|
63
|
+
protected selectNode(e: MouseEvent | KeyboardEvent, node: FtTreeNode): void;
|
|
64
|
+
}
|
|
@@ -0,0 +1,489 @@
|
|
|
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 } from "@fluid-topics/ft-wc-utils";
|
|
14
|
+
import { FtTypography, FtTypographyVariants } from "@fluid-topics/ft-typography";
|
|
15
|
+
import { FtIcon, FtIcons } from "@fluid-topics/ft-icon";
|
|
16
|
+
import { FtdsButton } from "@fluid-topics/ft-button";
|
|
17
|
+
import { styles } from "./ftds-tree-list.styles";
|
|
18
|
+
import { createLoadMoreNode, getPathToNode, TraversalInstruction, traverseVisibleTree } from "./model/FtTreeListData";
|
|
19
|
+
import { cactusSvg } from "@fluid-topics/ft-assets";
|
|
20
|
+
export class NodeSelectedEvent extends CustomEvent {
|
|
21
|
+
constructor(node) {
|
|
22
|
+
super("node-selected", { detail: node });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
class FtdsTreeList extends FtLitElement {
|
|
26
|
+
constructor() {
|
|
27
|
+
super(...arguments);
|
|
28
|
+
this.label = "";
|
|
29
|
+
this.expandLabel = "Expand";
|
|
30
|
+
this.collapseLabel = "Collapse";
|
|
31
|
+
this.showMoreLabel = "Show more";
|
|
32
|
+
this.expandParametrizedLabel = "Expand {0}";
|
|
33
|
+
this.collapseParametrizedLabel = "Collapse {0}";
|
|
34
|
+
this.expandAllLabel = "Expand all";
|
|
35
|
+
this.collapseAllLabel = "Collapse all";
|
|
36
|
+
this.userOpenedNodes = new Set();
|
|
37
|
+
this.userClosedNodes = new Set();
|
|
38
|
+
}
|
|
39
|
+
expandAll() {
|
|
40
|
+
this.userClosedNodes = new Set();
|
|
41
|
+
this.userOpenedNodes = new Set(this.data.rootNodes.flatMap((n) => this.getAllClosedNodes(n)));
|
|
42
|
+
this.isTreeSelectorCollapsed = false;
|
|
43
|
+
}
|
|
44
|
+
collapseAll() {
|
|
45
|
+
this.userOpenedNodes = new Set();
|
|
46
|
+
this.userClosedNodes = new Set(this.data.rootNodes.filter((n) => n.expanded).map((n) => n.value));
|
|
47
|
+
this.isTreeSelectorCollapsed = true;
|
|
48
|
+
}
|
|
49
|
+
getItemSelector(item) {
|
|
50
|
+
var _a;
|
|
51
|
+
return (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector(`[data-value="${item.value}"]`);
|
|
52
|
+
}
|
|
53
|
+
isNodeExpanded(node) {
|
|
54
|
+
return (!this.userClosedNodes.has(node.value) &&
|
|
55
|
+
(node.expanded || this.userOpenedNodes.has(node.value)));
|
|
56
|
+
}
|
|
57
|
+
setFocusToTreeItem(item) {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
(_b = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector(`[tabindex="0"]`)) === null || _b === void 0 ? void 0 : _b.setAttribute("tabindex", "-1");
|
|
60
|
+
const itemEl = this.getItemSelector(item);
|
|
61
|
+
itemEl === null || itemEl === void 0 ? void 0 : itemEl.focus();
|
|
62
|
+
itemEl === null || itemEl === void 0 ? void 0 : itemEl.setAttribute("tabindex", "0");
|
|
63
|
+
}
|
|
64
|
+
render() {
|
|
65
|
+
var _a;
|
|
66
|
+
const atLeastOneRootNodeIsExpandable = this.data && this.data.rootNodes && this.data.rootNodes.length > 0
|
|
67
|
+
? this.data.rootNodes.some((rootNode) => rootNode.children.length > 0)
|
|
68
|
+
: false;
|
|
69
|
+
return html `
|
|
70
|
+
<div part="header">
|
|
71
|
+
${when(this.label.length > 0, () => html `
|
|
72
|
+
<ft-typography class="header-label" variant="${FtTypographyVariants.body1semibold}">
|
|
73
|
+
${this.label}
|
|
74
|
+
<ft-typography variant="${FtTypographyVariants.body2medium}" class="node-children-count">
|
|
75
|
+
(${this.getEntriesCount()})
|
|
76
|
+
</ft-typography>
|
|
77
|
+
</ft-typography>
|
|
78
|
+
`)}
|
|
79
|
+
${when(atLeastOneRootNodeIsExpandable, () => html `
|
|
80
|
+
<ftds-button
|
|
81
|
+
dense
|
|
82
|
+
tooltipposition="bottom"
|
|
83
|
+
part="expand-button"
|
|
84
|
+
family="${DesignSystemFamily.neutral}"
|
|
85
|
+
icon=${FtIcons.ICON_COLLAPSE}
|
|
86
|
+
label="${this.collapseAllLabel}"
|
|
87
|
+
@click="${() => this.collapseAll()}"
|
|
88
|
+
>
|
|
89
|
+
${this.collapseAllLabel}
|
|
90
|
+
</ftds-button>
|
|
91
|
+
`)}
|
|
92
|
+
</div>
|
|
93
|
+
${(!((_a = this.data) === null || _a === void 0 ? void 0 : _a.rootNodes) || this.data.rootNodes.length <= 0) ? this.renderEmptyState() : html `
|
|
94
|
+
<ul role="tree" class="ft-tree-list" aria-labelledby="${this.label}">
|
|
95
|
+
${repeat(this.data.rootNodes, (node) => node.value, (node) => this.renderNode(node))}
|
|
96
|
+
</ul>
|
|
97
|
+
`}
|
|
98
|
+
`;
|
|
99
|
+
}
|
|
100
|
+
renderNode(node) {
|
|
101
|
+
var _a;
|
|
102
|
+
const isNodeExpanded = this.isNodeExpanded(node);
|
|
103
|
+
node.loadedCount = (_a = node.loadedCount) !== null && _a !== void 0 ? _a : this.pageSize;
|
|
104
|
+
if (!node.loadedCount) {
|
|
105
|
+
node.loadedCount = node.children.length;
|
|
106
|
+
}
|
|
107
|
+
const visibleChildren = node.children.slice(0, node.loadedCount);
|
|
108
|
+
const childrenClasses = {
|
|
109
|
+
expanded: isNodeExpanded,
|
|
110
|
+
collapsed: isNodeExpanded,
|
|
111
|
+
"with-expandable": this.hasExpandableChildren(node),
|
|
112
|
+
"with-children": this.hasChildren(node)
|
|
113
|
+
};
|
|
114
|
+
return html `
|
|
115
|
+
<li role="none">
|
|
116
|
+
<a
|
|
117
|
+
part="node-container"
|
|
118
|
+
role="treeitem"
|
|
119
|
+
data-value="${node.value}"
|
|
120
|
+
aria-expanded="${ifDefined(isNodeExpanded)}"
|
|
121
|
+
class="${classMap(childrenClasses)}"
|
|
122
|
+
tabindex="-1"
|
|
123
|
+
@keydown="${(e) => this.onKeydown(e, node, false)}"
|
|
124
|
+
>
|
|
125
|
+
${when(this.hasChildren(node), () => html `
|
|
126
|
+
<ft-icon
|
|
127
|
+
part="node-expand"
|
|
128
|
+
value=${isNodeExpanded ? FtIcons.THIN_ARROW : FtIcons.THIN_ARROW_RIGHT}
|
|
129
|
+
@click="${() => this.expandNode(!isNodeExpanded, node.value)}"
|
|
130
|
+
></ft-icon>
|
|
131
|
+
`)}
|
|
132
|
+
<div class="node-label-container" @click=${(e) => this.selectNode(e, node)}>
|
|
133
|
+
<ft-typography
|
|
134
|
+
part="node-label"
|
|
135
|
+
variant="${FtTypographyVariants.body2medium}"
|
|
136
|
+
>
|
|
137
|
+
${node.label}
|
|
138
|
+
</ft-typography>
|
|
139
|
+
${when(this.hasChildren(node), () => html `
|
|
140
|
+
<ft-typography variant="${FtTypographyVariants.body2medium}" class="node-children-count">
|
|
141
|
+
(${this.getChildrenCount(node)})
|
|
142
|
+
</ft-typography>
|
|
143
|
+
`)}
|
|
144
|
+
</div>
|
|
145
|
+
</a>
|
|
146
|
+
${this.hasChildren(node) ? this.renderChildNodes(isNodeExpanded, visibleChildren, node, childrenClasses) : nothing}
|
|
147
|
+
</li>
|
|
148
|
+
`;
|
|
149
|
+
}
|
|
150
|
+
renderChildNodes(isNodeExpanded, visibleChildren, node, childrenClasses) {
|
|
151
|
+
return html `
|
|
152
|
+
<ul role="group">
|
|
153
|
+
${when(isNodeExpanded, () => html `
|
|
154
|
+
${repeat(visibleChildren, (c) => c.value, (c) => this.renderNode(c))}
|
|
155
|
+
${node.loadedCount && node.children.length > node.loadedCount
|
|
156
|
+
? this.renderShowMore(node, childrenClasses) : nothing}`)}
|
|
157
|
+
</ul>
|
|
158
|
+
`;
|
|
159
|
+
}
|
|
160
|
+
renderShowMore(node, childrenClasses) {
|
|
161
|
+
return html `
|
|
162
|
+
<li role="none">
|
|
163
|
+
<a part="load-more"
|
|
164
|
+
role="treeitem"
|
|
165
|
+
data-value="load-more-${node.value}"
|
|
166
|
+
icon="${FtIcons.ARROW_DOWN}"
|
|
167
|
+
tabindex="-1"
|
|
168
|
+
aria-expanded="false"
|
|
169
|
+
class="${classMap(childrenClasses)}"
|
|
170
|
+
@click="${() => this.loadMore(node)}"
|
|
171
|
+
@keydown="${(e) => this.onKeydown(e, createLoadMoreNode(node), true, node)}">
|
|
172
|
+
<ft-icon value=${FtIcons.ARROW_DOWN}></ft-icon>
|
|
173
|
+
<ft-typography
|
|
174
|
+
part="node-label"
|
|
175
|
+
variant="${FtTypographyVariants.body2medium}"
|
|
176
|
+
>
|
|
177
|
+
${this.showMoreLabel}
|
|
178
|
+
</ft-typography>
|
|
179
|
+
</a>
|
|
180
|
+
</li>
|
|
181
|
+
`;
|
|
182
|
+
}
|
|
183
|
+
renderEmptyState() {
|
|
184
|
+
var _a, _b;
|
|
185
|
+
return html `
|
|
186
|
+
<div class="empty-state">
|
|
187
|
+
${((_a = this.emptyState) === null || _a === void 0 ? void 0 : _a.noImage) ? nothing : cactusSvg}
|
|
188
|
+
<ft-typography variant="${FtTypographyVariants.body2medium}">
|
|
189
|
+
${(_b = this.emptyState) === null || _b === void 0 ? void 0 : _b.content}
|
|
190
|
+
</ft-typography>
|
|
191
|
+
</div>
|
|
192
|
+
`;
|
|
193
|
+
}
|
|
194
|
+
willUpdate(props) {
|
|
195
|
+
var _a, _b;
|
|
196
|
+
super.willUpdate(props);
|
|
197
|
+
if (!this.selectedNode && ((_a = this.data) === null || _a === void 0 ? void 0 : _a.rootNodes)) {
|
|
198
|
+
this.selectedNode = (_b = this.data) === null || _b === void 0 ? void 0 : _b.rootNodes[0];
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
updated(props) {
|
|
202
|
+
super.updated(props);
|
|
203
|
+
if (this.nodeToFocus) {
|
|
204
|
+
this.setFocusToTreeItem(this.nodeToFocus);
|
|
205
|
+
this.nodeToFocus = undefined;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
onKeydown(event, currentNode, isLoadMore, parentNode) {
|
|
209
|
+
let needToStopPropagation = false;
|
|
210
|
+
const tree = this.data.rootNodes;
|
|
211
|
+
const visibleItems = this.getAdjacentVisibleTreeItems(tree, currentNode);
|
|
212
|
+
let currentNodeIndex = visibleItems.findIndex(node => node.value === currentNode.value);
|
|
213
|
+
if (event.shiftKey && (event.key === " " || event.key === "Space")) {
|
|
214
|
+
event.stopPropagation();
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
let nodeExpanded = this.isNodeExpanded(currentNode);
|
|
218
|
+
switch (event.key) {
|
|
219
|
+
case "Enter":
|
|
220
|
+
case " ":
|
|
221
|
+
case "Space":
|
|
222
|
+
if (isLoadMore && parentNode) {
|
|
223
|
+
this.loadMore(parentNode);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
this.selectNode(event, currentNode);
|
|
227
|
+
}
|
|
228
|
+
needToStopPropagation = true;
|
|
229
|
+
break;
|
|
230
|
+
case "ArrowDown":
|
|
231
|
+
this.setFocusToNextNode(visibleItems, currentNodeIndex);
|
|
232
|
+
needToStopPropagation = true;
|
|
233
|
+
break;
|
|
234
|
+
case "ArrowUp":
|
|
235
|
+
this.setFocusToPreviousNode(visibleItems, currentNodeIndex);
|
|
236
|
+
needToStopPropagation = true;
|
|
237
|
+
break;
|
|
238
|
+
case "ArrowRight":
|
|
239
|
+
if (nodeExpanded) {
|
|
240
|
+
if (currentNode.children.length > 0) {
|
|
241
|
+
this.setFocusToTreeItem(currentNode.children[0]);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
this.expandNode(!nodeExpanded, currentNode.value);
|
|
246
|
+
}
|
|
247
|
+
needToStopPropagation = true;
|
|
248
|
+
break;
|
|
249
|
+
case "ArrowLeft":
|
|
250
|
+
if (nodeExpanded) {
|
|
251
|
+
this.expandNode(!nodeExpanded, currentNode.value);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
let breadcrumb = getPathToNode(tree, currentNode.value);
|
|
255
|
+
if (breadcrumb && breadcrumb.length > 1) {
|
|
256
|
+
let parent = breadcrumb[breadcrumb.length - 2];
|
|
257
|
+
this.setFocusToTreeItem(parent);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
needToStopPropagation = true;
|
|
261
|
+
break;
|
|
262
|
+
case "Home":
|
|
263
|
+
this.setFocusToTreeItem(visibleItems[0]);
|
|
264
|
+
needToStopPropagation = true;
|
|
265
|
+
break;
|
|
266
|
+
case "End":
|
|
267
|
+
this.setFocusToTreeItem(visibleItems[visibleItems.length - 1]);
|
|
268
|
+
needToStopPropagation = true;
|
|
269
|
+
break;
|
|
270
|
+
case "*":
|
|
271
|
+
let breadcrumb = getPathToNode(tree, currentNode.value);
|
|
272
|
+
if (breadcrumb && breadcrumb.length > 1) {
|
|
273
|
+
let siblings = breadcrumb[breadcrumb.length - 2].children;
|
|
274
|
+
for (const node of siblings) {
|
|
275
|
+
this.expandNode(true, node.value);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
else if ((breadcrumb === null || breadcrumb === void 0 ? void 0 : breadcrumb.length) == 1) {
|
|
279
|
+
for (const rootNode of this.data.rootNodes) {
|
|
280
|
+
this.expandNode(true, rootNode.value);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
needToStopPropagation = true;
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (needToStopPropagation) {
|
|
288
|
+
event.stopPropagation();
|
|
289
|
+
event.preventDefault();
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
setFocusToPreviousNode(visibleItems, currentNodeIndex) {
|
|
293
|
+
if (visibleItems[currentNodeIndex - 1]) {
|
|
294
|
+
this.setFocusToTreeItem(visibleItems[currentNodeIndex - 1]);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
setFocusToNextNode(visibleItems, currentNodeIndex) {
|
|
298
|
+
if (visibleItems[currentNodeIndex + 1]) {
|
|
299
|
+
this.setFocusToTreeItem(visibleItems[currentNodeIndex + 1]);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
getAdjacentVisibleTreeItems(tree, currentNode) {
|
|
303
|
+
const visibleTreeItems = [];
|
|
304
|
+
let stopAfterNext = false;
|
|
305
|
+
let push = false;
|
|
306
|
+
traverseVisibleTree(tree, (node) => {
|
|
307
|
+
const last = stopAfterNext;
|
|
308
|
+
if (node.value === currentNode.value) {
|
|
309
|
+
stopAfterNext = true;
|
|
310
|
+
push = true;
|
|
311
|
+
}
|
|
312
|
+
if (this.isVisible(node)) {
|
|
313
|
+
if (push) {
|
|
314
|
+
visibleTreeItems.push(node);
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
visibleTreeItems[0] = node;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return new TraversalInstruction(last, !this.isNodeExpanded(node));
|
|
321
|
+
});
|
|
322
|
+
return visibleTreeItems;
|
|
323
|
+
}
|
|
324
|
+
isVisible(treeitem) {
|
|
325
|
+
var _a, _b;
|
|
326
|
+
const tree = this.data.rootNodes;
|
|
327
|
+
if (treeitem.value.includes("load-more-")) {
|
|
328
|
+
const parentValue = treeitem.value.replace("load-more-", "");
|
|
329
|
+
const parentItem = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector(`[data-value="${parentValue}"]`);
|
|
330
|
+
if (!parentItem || parentItem.getAttribute("aria-expanded") === "false") {
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
let pathToNode = getPathToNode(tree, treeitem.value);
|
|
335
|
+
if (pathToNode && pathToNode.length > 1) {
|
|
336
|
+
const parentNode = pathToNode[(pathToNode === null || pathToNode === void 0 ? void 0 : pathToNode.length) - 2];
|
|
337
|
+
const parentItem = this.getItemSelector(parentNode);
|
|
338
|
+
const childIndex = parentNode.children.findIndex((child => child.value === treeitem.value));
|
|
339
|
+
if (!parentItem || parentItem.getAttribute("aria-expanded") === "false" || childIndex >= ((_b = parentNode.loadedCount) !== null && _b !== void 0 ? _b : Infinity)) {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
expandNode(expanded, currentNodeValue) {
|
|
346
|
+
if (expanded) {
|
|
347
|
+
if (this.userClosedNodes.has(currentNodeValue)) {
|
|
348
|
+
this.userClosedNodes.delete(currentNodeValue);
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
this.userOpenedNodes.add(currentNodeValue);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
if (this.userOpenedNodes.has(currentNodeValue)) {
|
|
356
|
+
this.userOpenedNodes.delete(currentNodeValue);
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
this.userClosedNodes.add(currentNodeValue);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
this.requestUpdate();
|
|
363
|
+
}
|
|
364
|
+
toggleExpandAll() {
|
|
365
|
+
if (this.isTreeSelectorCollapsed) {
|
|
366
|
+
this.expandAll();
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
this.collapseAll();
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
getAllClosedNodes(node) {
|
|
373
|
+
if (node.children.length !== 0) {
|
|
374
|
+
return [
|
|
375
|
+
...(node.expanded ? [] : [node.value]),
|
|
376
|
+
...node.children.flatMap((c) => this.getAllClosedNodes(c))
|
|
377
|
+
];
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
return [];
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
getChildrenCount(node) {
|
|
384
|
+
let count = 0;
|
|
385
|
+
traverseVisibleTree(node.children, () => {
|
|
386
|
+
count++;
|
|
387
|
+
});
|
|
388
|
+
return count;
|
|
389
|
+
}
|
|
390
|
+
getEntriesCount() {
|
|
391
|
+
var _a;
|
|
392
|
+
let count = 0;
|
|
393
|
+
if ((_a = this.data) === null || _a === void 0 ? void 0 : _a.rootNodes) {
|
|
394
|
+
traverseVisibleTree(this.data.rootNodes, () => {
|
|
395
|
+
count++;
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
return count;
|
|
399
|
+
}
|
|
400
|
+
hasExpandableChildren(node) {
|
|
401
|
+
return node.children.some((child) => child.children.length > 0);
|
|
402
|
+
}
|
|
403
|
+
hasChildren(node) {
|
|
404
|
+
return node.children.length > 0;
|
|
405
|
+
}
|
|
406
|
+
loadMore(node) {
|
|
407
|
+
var _a;
|
|
408
|
+
if (this.pageSize) {
|
|
409
|
+
const prevLoadedCount = (_a = node.loadedCount) !== null && _a !== void 0 ? _a : this.pageSize;
|
|
410
|
+
node.loadedCount = prevLoadedCount + this.pageSize;
|
|
411
|
+
this.nodeToFocus = node.children[prevLoadedCount];
|
|
412
|
+
this.requestUpdate();
|
|
413
|
+
this.setFocusToTreeItem(node.children[prevLoadedCount]);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
selectNode(e, node) {
|
|
417
|
+
var _a;
|
|
418
|
+
e.preventDefault();
|
|
419
|
+
const oldNode = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector("[aria-selected]");
|
|
420
|
+
oldNode === null || oldNode === void 0 ? void 0 : oldNode.removeAttribute("aria-selected");
|
|
421
|
+
const currentTarget = e.currentTarget;
|
|
422
|
+
if (e.type === "click") {
|
|
423
|
+
const item = currentTarget === null || currentTarget === void 0 ? void 0 : currentTarget.parentElement;
|
|
424
|
+
item === null || item === void 0 ? void 0 : item.setAttribute("aria-selected", "true");
|
|
425
|
+
}
|
|
426
|
+
else if (e.type === "keydown") {
|
|
427
|
+
currentTarget === null || currentTarget === void 0 ? void 0 : currentTarget.setAttribute("aria-selected", "true");
|
|
428
|
+
}
|
|
429
|
+
this.selectedNode = node;
|
|
430
|
+
this.dispatchEvent(new NodeSelectedEvent(node));
|
|
431
|
+
this.setFocusToTreeItem(node);
|
|
432
|
+
e.stopPropagation();
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
FtdsTreeList.elementDefinitions = {
|
|
436
|
+
"ft-typography": FtTypography,
|
|
437
|
+
"ftds-button": FtdsButton,
|
|
438
|
+
"ft-icon": FtIcon
|
|
439
|
+
};
|
|
440
|
+
FtdsTreeList.styles = styles;
|
|
441
|
+
__decorate([
|
|
442
|
+
property()
|
|
443
|
+
], FtdsTreeList.prototype, "data", void 0);
|
|
444
|
+
__decorate([
|
|
445
|
+
property()
|
|
446
|
+
], FtdsTreeList.prototype, "label", void 0);
|
|
447
|
+
__decorate([
|
|
448
|
+
property()
|
|
449
|
+
], FtdsTreeList.prototype, "pageSize", void 0);
|
|
450
|
+
__decorate([
|
|
451
|
+
property()
|
|
452
|
+
], FtdsTreeList.prototype, "selectedNode", void 0);
|
|
453
|
+
__decorate([
|
|
454
|
+
property()
|
|
455
|
+
], FtdsTreeList.prototype, "expandLabel", void 0);
|
|
456
|
+
__decorate([
|
|
457
|
+
property()
|
|
458
|
+
], FtdsTreeList.prototype, "collapseLabel", void 0);
|
|
459
|
+
__decorate([
|
|
460
|
+
property()
|
|
461
|
+
], FtdsTreeList.prototype, "showMoreLabel", void 0);
|
|
462
|
+
__decorate([
|
|
463
|
+
property()
|
|
464
|
+
], FtdsTreeList.prototype, "expandParametrizedLabel", void 0);
|
|
465
|
+
__decorate([
|
|
466
|
+
property()
|
|
467
|
+
], FtdsTreeList.prototype, "collapseParametrizedLabel", void 0);
|
|
468
|
+
__decorate([
|
|
469
|
+
property()
|
|
470
|
+
], FtdsTreeList.prototype, "expandAllLabel", void 0);
|
|
471
|
+
__decorate([
|
|
472
|
+
property()
|
|
473
|
+
], FtdsTreeList.prototype, "collapseAllLabel", void 0);
|
|
474
|
+
__decorate([
|
|
475
|
+
jsonProperty([])
|
|
476
|
+
], FtdsTreeList.prototype, "emptyState", void 0);
|
|
477
|
+
__decorate([
|
|
478
|
+
state()
|
|
479
|
+
], FtdsTreeList.prototype, "nodeToFocus", void 0);
|
|
480
|
+
__decorate([
|
|
481
|
+
state()
|
|
482
|
+
], FtdsTreeList.prototype, "isTreeSelectorCollapsed", void 0);
|
|
483
|
+
__decorate([
|
|
484
|
+
state({ hasChanged })
|
|
485
|
+
], FtdsTreeList.prototype, "userOpenedNodes", void 0);
|
|
486
|
+
__decorate([
|
|
487
|
+
state({ hasChanged })
|
|
488
|
+
], FtdsTreeList.prototype, "userClosedNodes", void 0);
|
|
489
|
+
export { FtdsTreeList };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FtTree, FtTreeNode } from "@fluid-topics/ft-tree-selector/build/model/FtTree";
|
|
2
|
+
import { TemplateResult } from "lit/development";
|
|
3
|
+
export interface FtdsTreeListProperties {
|
|
4
|
+
label?: string;
|
|
5
|
+
data?: FtTree;
|
|
6
|
+
selectedNode?: FtTreeNode;
|
|
7
|
+
pageSize?: number;
|
|
8
|
+
expandLabel: string;
|
|
9
|
+
collapseLabel: string;
|
|
10
|
+
expandParametrizedLabel: string;
|
|
11
|
+
collapseParametrizedLabel: string;
|
|
12
|
+
expandAllLabel: string;
|
|
13
|
+
collapseAllLabel: string;
|
|
14
|
+
}
|
|
15
|
+
export interface EmptyStateConfiguration {
|
|
16
|
+
noImage: boolean;
|
|
17
|
+
content: string | TemplateResult;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|