@fluid-topics/ft-tree-selector 1.2.43 → 1.2.45
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/build/ft-tree-selector.d.ts +4 -8
- package/build/ft-tree-selector.js +54 -48
- package/build/ft-tree-selector.light.js +163 -162
- package/build/ft-tree-selector.min.js +157 -156
- package/build/ft-tree-selector.styles.js +20 -27
- package/build/model/FtTree.d.ts +0 -4
- package/package.json +4 -4
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import { PropertyValues } from "lit";
|
|
2
2
|
import { ElementDefinitionsMap, FtLitElement } from "@fluid-topics/ft-wc-utils";
|
|
3
|
-
import { FtTree, FtTreeChangedDetail,
|
|
3
|
+
import { FtTree, FtTreeChangedDetail, FtTreeNode } from "./model/FtTree";
|
|
4
4
|
import { FtButton } from "@fluid-topics/ft-button";
|
|
5
5
|
export declare class TreeNodeChangeEvent extends CustomEvent<FtTreeChangedDetail> {
|
|
6
6
|
constructor(values: FtTreeChangedDetail);
|
|
7
7
|
}
|
|
8
|
-
export declare class TreeNodeExpandedChangeEvent extends CustomEvent<FtTreeExpandedChangeDetail> {
|
|
9
|
-
constructor(values: FtTreeExpandedChangeDetail);
|
|
10
|
-
}
|
|
11
|
-
export declare class TreeNodeAllNodeCollapsedEvent extends CustomEvent<void> {
|
|
12
|
-
constructor();
|
|
13
|
-
}
|
|
14
8
|
export declare class TreeNodeClearAll extends CustomEvent<void> {
|
|
15
9
|
constructor();
|
|
16
10
|
}
|
|
@@ -33,15 +27,17 @@ export declare class FtTreeSelector extends FtLitElement {
|
|
|
33
27
|
clearLabel: string;
|
|
34
28
|
protected update(changedProperties: PropertyValues): void;
|
|
35
29
|
protected render(): import("lit-html").TemplateResult<1>;
|
|
30
|
+
private clear;
|
|
36
31
|
protected renderNode(node: FtTreeNode): unknown;
|
|
32
|
+
private toggleNode;
|
|
37
33
|
private renderOpenCloseButton;
|
|
38
34
|
private userChangeNodeExpandStatus;
|
|
39
|
-
private sendAllNodeCollapseEventIfNeeded;
|
|
40
35
|
private onKeydown;
|
|
41
36
|
private focusPreviousButton;
|
|
42
37
|
private focusNextButton;
|
|
43
38
|
private isNodeExpanded;
|
|
44
39
|
private hasExpandableChildren;
|
|
40
|
+
toggleExpandAll(): void;
|
|
45
41
|
expandAll(): void;
|
|
46
42
|
private getAllClosedNodes;
|
|
47
43
|
collapseAll(): void;
|
|
@@ -6,7 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
import { html, nothing } from "lit";
|
|
8
8
|
import { classMap } from "lit/directives/class-map.js";
|
|
9
|
-
import { FtLitElement, hasChanged, ParametrizedLabelResolver, } from "@fluid-topics/ft-wc-utils";
|
|
9
|
+
import { flatDeep, FtLitElement, hasChanged, ParametrizedLabelResolver, } from "@fluid-topics/ft-wc-utils";
|
|
10
10
|
import { styles } from "./ft-tree-selector.styles";
|
|
11
11
|
import { FtCheckbox } from "@fluid-topics/ft-checkbox";
|
|
12
12
|
import { FtTypography } from "@fluid-topics/ft-typography";
|
|
@@ -18,16 +18,6 @@ export class TreeNodeChangeEvent extends CustomEvent {
|
|
|
18
18
|
super("treenode-change", { detail: values, bubbles: true, composed: true });
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
export class TreeNodeExpandedChangeEvent extends CustomEvent {
|
|
22
|
-
constructor(values) {
|
|
23
|
-
super("treenode-expanded-change", { detail: values, bubbles: true, composed: true });
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export class TreeNodeAllNodeCollapsedEvent extends CustomEvent {
|
|
27
|
-
constructor() {
|
|
28
|
-
super("treenode-all-node-collapsed", { bubbles: true, composed: true });
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
21
|
export class TreeNodeClearAll extends CustomEvent {
|
|
32
22
|
constructor() {
|
|
33
23
|
super("treenode-clear-all", { bubbles: true, composed: true });
|
|
@@ -60,29 +50,25 @@ class FtTreeSelector extends FtLitElement {
|
|
|
60
50
|
return html `
|
|
61
51
|
<div class="ft-tree-selector ${atLeastOneRootNodeIsExpandable ? "with-expandable" : ""}">
|
|
62
52
|
<div part="header">
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
this.collapseAll();
|
|
79
|
-
this.isTreeSelectorCollapsed = true;
|
|
80
|
-
}}">
|
|
81
|
-
</ft-button>
|
|
53
|
+
${this.label.length > 0 ? html `
|
|
54
|
+
<ft-typography variant="overline" part="label">
|
|
55
|
+
${this.label}
|
|
56
|
+
</ft-typography>
|
|
57
|
+
` : nothing}
|
|
58
|
+
${atLeastOneRootNodeIsExpandable ? html `
|
|
59
|
+
<ft-button dense
|
|
60
|
+
tooltipposition="bottom"
|
|
61
|
+
part="expand-button"
|
|
62
|
+
icon=${this.isTreeSelectorCollapsed ? "ICON_EXPAND" : "ICON_COLLAPSE"}
|
|
63
|
+
label="${this.isTreeSelectorCollapsed ? this.expandAllLabel : this.collapseAllLabel}"
|
|
64
|
+
aria-expanded="${this.isTreeSelectorCollapsed}"
|
|
65
|
+
@click="${() => this.toggleExpandAll()}">
|
|
66
|
+
</ft-button>
|
|
67
|
+
` : nothing}
|
|
82
68
|
|
|
83
69
|
${((_a = this.data) === null || _a === void 0 ? void 0 : _a.rootNodes.some(node => node.selected || node.indeterminate)) ?
|
|
84
70
|
html `
|
|
85
|
-
<ft-button icon="close" dense @click=${() => this.
|
|
71
|
+
<ft-button icon="close" dense @click=${() => this.clear()} part="clear-button">
|
|
86
72
|
${this.clearLabel}
|
|
87
73
|
</ft-button>
|
|
88
74
|
` : nothing}
|
|
@@ -94,6 +80,14 @@ class FtTreeSelector extends FtLitElement {
|
|
|
94
80
|
</div>
|
|
95
81
|
`;
|
|
96
82
|
}
|
|
83
|
+
clear() {
|
|
84
|
+
flatDeep(this.data.rootNodes, n => n.children).forEach(n => {
|
|
85
|
+
n.selected = false;
|
|
86
|
+
n.indeterminate = false;
|
|
87
|
+
});
|
|
88
|
+
this.requestUpdate();
|
|
89
|
+
this.dispatchEvent(new TreeNodeClearAll());
|
|
90
|
+
}
|
|
97
91
|
renderNode(node) {
|
|
98
92
|
const isNodeExpanded = this.isNodeExpanded(node);
|
|
99
93
|
const childrenClasses = {
|
|
@@ -105,13 +99,12 @@ class FtTreeSelector extends FtLitElement {
|
|
|
105
99
|
<div part="level" class="${node.children.length != 0 ? "expandable" : "leaf"}"
|
|
106
100
|
data-value="${node.value}">
|
|
107
101
|
<div part="actions">
|
|
108
|
-
${
|
|
109
|
-
<ft-checkbox part="checkbox"
|
|
102
|
+
${this.renderOpenCloseButton(node)}
|
|
103
|
+
<ft-checkbox part="checkbox"
|
|
104
|
+
name="${node.label}"
|
|
105
|
+
?checked="${node.selected}"
|
|
110
106
|
?indeterminate="${node.indeterminate}"
|
|
111
|
-
@change=${(e) => this.
|
|
112
|
-
value: node.value,
|
|
113
|
-
selected: e.detail
|
|
114
|
-
}))}>
|
|
107
|
+
@change=${(e) => this.toggleNode(node, e)}>
|
|
115
108
|
${node.label}
|
|
116
109
|
</ft-checkbox>
|
|
117
110
|
</div>
|
|
@@ -126,7 +119,21 @@ class FtTreeSelector extends FtLitElement {
|
|
|
126
119
|
</div>
|
|
127
120
|
`;
|
|
128
121
|
}
|
|
122
|
+
toggleNode(node, e) {
|
|
123
|
+
node.selected = e.detail;
|
|
124
|
+
node.indeterminate = false;
|
|
125
|
+
this.requestUpdate();
|
|
126
|
+
return this.dispatchEvent(new TreeNodeChangeEvent({
|
|
127
|
+
value: node.value,
|
|
128
|
+
selected: e.detail
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
129
131
|
renderOpenCloseButton(node) {
|
|
132
|
+
if (node.children.length === 0) {
|
|
133
|
+
return html `
|
|
134
|
+
<div part="expand"></div>
|
|
135
|
+
`;
|
|
136
|
+
}
|
|
130
137
|
let isNodeExpanded = this.isNodeExpanded(node);
|
|
131
138
|
return html `
|
|
132
139
|
<ft-button dense part="expand" tooltipposition="bottom"
|
|
@@ -159,18 +166,8 @@ class FtTreeSelector extends FtLitElement {
|
|
|
159
166
|
this.userClosedNodes.add(currentNodeValue);
|
|
160
167
|
}
|
|
161
168
|
}
|
|
162
|
-
this.dispatchEvent(new TreeNodeExpandedChangeEvent({
|
|
163
|
-
value: currentNodeValue,
|
|
164
|
-
expanded: expanded
|
|
165
|
-
}));
|
|
166
|
-
this.sendAllNodeCollapseEventIfNeeded();
|
|
167
169
|
this.requestUpdate();
|
|
168
170
|
}
|
|
169
|
-
sendAllNodeCollapseEventIfNeeded() {
|
|
170
|
-
if (this.data.rootNodes.every(node => !this.isNodeExpanded(node))) {
|
|
171
|
-
this.dispatchEvent(new TreeNodeAllNodeCollapsedEvent());
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
171
|
onKeydown(event, node) {
|
|
175
172
|
let needToStopPropagation = false;
|
|
176
173
|
switch (event.key) {
|
|
@@ -215,9 +212,18 @@ class FtTreeSelector extends FtLitElement {
|
|
|
215
212
|
hasExpandableChildren(node) {
|
|
216
213
|
return node.children.some(child => child.children.length > 0);
|
|
217
214
|
}
|
|
215
|
+
toggleExpandAll() {
|
|
216
|
+
if (this.isTreeSelectorCollapsed) {
|
|
217
|
+
this.expandAll();
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
this.collapseAll();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
218
223
|
expandAll() {
|
|
219
224
|
this.userClosedNodes = new Set();
|
|
220
225
|
this.userOpenedNodes = new Set(this.data.rootNodes.flatMap((n) => this.getAllClosedNodes(n)));
|
|
226
|
+
this.isTreeSelectorCollapsed = false;
|
|
221
227
|
}
|
|
222
228
|
getAllClosedNodes(node) {
|
|
223
229
|
if (node.children.length !== 0) {
|
|
@@ -230,7 +236,7 @@ class FtTreeSelector extends FtLitElement {
|
|
|
230
236
|
collapseAll() {
|
|
231
237
|
this.userOpenedNodes = new Set();
|
|
232
238
|
this.userClosedNodes = new Set(this.data.rootNodes.filter((n) => n.expanded).map(n => n.value));
|
|
233
|
-
this.
|
|
239
|
+
this.isTreeSelectorCollapsed = true;
|
|
234
240
|
}
|
|
235
241
|
getAriaControlId(node) {
|
|
236
242
|
return node.value.replace(" ", "").replace("|", "-") + "-children";
|