@styloviz/tree-view 0.3.0 → 1.0.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 +29 -9
- package/fesm2022/styloviz-tree-view.mjs +577 -259
- package/fesm2022/styloviz-tree-view.mjs.map +1 -1
- package/package.json +10 -6
- package/types/styloviz-tree-view.d.ts +215 -85
- package/types/styloviz-tree-view.d.ts.map +1 -1
|
@@ -1,217 +1,331 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { ChangeDetectionStrategy, Component, ElementRef, computed, effect, inject, input, model, output, signal, untracked } from "@angular/core";
|
|
3
|
+
import { DOCUMENT } from "@angular/common";
|
|
4
|
+
import { SvIconComponent } from "@styloviz/icons";
|
|
5
|
+
import { SvEmptyShellComponent, SvErrorShellComponent, SvSkeletonShellComponent, createTypeahead, svAttrSelector, svCollectionTarget, svCutHierarchyCycles, svIsTypeaheadKey, svRecoverFocus, svSuccessorIndex, svWarnUnvirtualizedCeiling, warnOnDuplicateItemKeys } from "@styloviz/core";
|
|
6
|
+
var SvTreeViewComponent = class SvTreeViewComponent {
|
|
7
|
+
nodes = input([], ...ngDevMode ? [{ debugName: "nodes" }] : /* istanbul ignore next */ []);
|
|
8
|
+
selectable = input(true, ...ngDevMode ? [{ debugName: "selectable" }] : /* istanbul ignore next */ []);
|
|
9
|
+
showLines = input(true, ...ngDevMode ? [{ debugName: "showLines" }] : /* istanbul ignore next */ []);
|
|
10
|
+
ariaLabel = input("", ...ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []);
|
|
11
|
+
loading = input(false, ...ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []);
|
|
12
|
+
error = input(null, ...ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []);
|
|
13
|
+
emptyText = input("No items to display", ...ngDevMode ? [{ debugName: "emptyText" }] : /* istanbul ignore next */ []);
|
|
14
|
+
nodeClick = output();
|
|
15
|
+
nodeExpand = output();
|
|
16
|
+
nodeCollapse = output();
|
|
17
|
+
nodeSelect = output();
|
|
18
|
+
retry = output();
|
|
19
|
+
expandedIds = model(/* @__PURE__ */ new Set(), ...ngDevMode ? [{ debugName: "expandedIds" }] : /* istanbul ignore next */ []);
|
|
20
|
+
selectedId = model(null, ...ngDevMode ? [{ debugName: "selectedId" }] : /* istanbul ignore next */ []);
|
|
21
|
+
activeId = signal(null, ...ngDevMode ? [{ debugName: "activeId" }] : /* istanbul ignore next */ []);
|
|
22
|
+
_nodes = signal([], ...ngDevMode ? [{ debugName: "_nodes" }] : /* istanbul ignore next */ []);
|
|
23
|
+
_warnedBindings = /* @__PURE__ */ new Set();
|
|
24
|
+
host = inject(ElementRef);
|
|
25
|
+
_doc = inject(DOCUMENT);
|
|
26
|
+
visibleNodes = computed(() => {
|
|
27
|
+
const rows = this._flatten(this._nodes(), 0, this.expandedIds());
|
|
28
|
+
warnOnDuplicateItemKeys(rows, (n) => n.node.id, "sv-tree-view [nodes]");
|
|
29
|
+
return rows;
|
|
30
|
+
}, ...ngDevMode ? [{ debugName: "visibleNodes" }] : /* istanbul ignore next */ []);
|
|
31
|
+
_seededFromNodes = false;
|
|
32
|
+
constructor() {
|
|
33
|
+
effect(() => {
|
|
34
|
+
const incoming = svCutHierarchyCycles(this.nodes(), "sv-tree-view").nodes;
|
|
35
|
+
const focusedRow = untracked(() => this._focusedRowSnapshot());
|
|
36
|
+
this._nodes.set(incoming);
|
|
37
|
+
if (focusedRow) this._recoverAfterNodesChange(focusedRow);
|
|
38
|
+
if (this._seededFromNodes || incoming.length === 0) return;
|
|
39
|
+
this._seededFromNodes = true;
|
|
40
|
+
const ids = /* @__PURE__ */ new Set();
|
|
41
|
+
this._collectExpanded(incoming, ids);
|
|
42
|
+
if (ids.size && untracked(this.expandedIds).size === 0) this.expandedIds.set(ids);
|
|
43
|
+
this.activeId.set(this.visibleNodes()[0]?.node.id ?? null);
|
|
44
|
+
});
|
|
45
|
+
effect(() => svWarnUnvirtualizedCeiling("sv-tree-view", this.visibleNodes().length, false));
|
|
46
|
+
effect(() => this._warnIgnoredBindings());
|
|
47
|
+
}
|
|
48
|
+
_warnIgnoredBindings() {
|
|
49
|
+
if (typeof ngDevMode === "undefined" || !ngDevMode) return;
|
|
50
|
+
if (!this.ariaLabel().trim() && !this.host.nativeElement.hasAttribute("aria-labelledby") && !this._warnedBindings.has("no-name")) {
|
|
51
|
+
this._warnedBindings.add("no-name");
|
|
52
|
+
console.warn("[styloviz] sv-tree-view: the tree has no accessible name — [ariaLabel] is empty and the host has no aria-labelledby, so a screen reader announces only \"tree\". Pass [ariaLabel]=\"'Project files'\" (or similar).");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
_focusedRowSnapshot() {
|
|
56
|
+
const active = this._doc.activeElement;
|
|
57
|
+
if (!active || !this.host.nativeElement.contains(active)) return null;
|
|
58
|
+
const id = active.closest("[data-tree-id]")?.dataset["treeId"];
|
|
59
|
+
if (id === void 0) return null;
|
|
60
|
+
return {
|
|
61
|
+
id,
|
|
62
|
+
index: this.visibleNodes().findIndex((fn) => fn.node.id === id)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
_recoverAfterNodesChange(was) {
|
|
66
|
+
setTimeout(() => {
|
|
67
|
+
const list = this.visibleNodes();
|
|
68
|
+
if (list.some((fn) => fn.node.id === was.id)) return;
|
|
69
|
+
const next = list[svSuccessorIndex(was.index, list.length)];
|
|
70
|
+
if (next) this.setActive(next.node.id);
|
|
71
|
+
const root = this.host.nativeElement;
|
|
72
|
+
const successor = next ? root.querySelector(svAttrSelector("data-tree-id", next.node.id)) : null;
|
|
73
|
+
if (successor && !next?.node.disabled) successor.tabIndex = 0;
|
|
74
|
+
svRecoverFocus({
|
|
75
|
+
to: [successor],
|
|
76
|
+
fallback: root.querySelector("[role=\"tree\"]")
|
|
77
|
+
});
|
|
78
|
+
}, 0);
|
|
79
|
+
}
|
|
80
|
+
toggle(node) {
|
|
81
|
+
if (node.disabled) return;
|
|
82
|
+
const ids = new Set(this.expandedIds());
|
|
83
|
+
const collapsing = ids.has(node.id);
|
|
84
|
+
if (collapsing) ids.delete(node.id);
|
|
85
|
+
else ids.add(node.id);
|
|
86
|
+
this.expandedIds.set(ids);
|
|
87
|
+
if (collapsing) this._repairFocus(node.id);
|
|
88
|
+
if (collapsing) this.nodeCollapse.emit(node);
|
|
89
|
+
else this.nodeExpand.emit(node);
|
|
90
|
+
}
|
|
91
|
+
_repairFocus(preferredId) {
|
|
92
|
+
const active = this._doc.activeElement;
|
|
93
|
+
if (!active || !this.host.nativeElement.contains(active)) return;
|
|
94
|
+
const activeRowId = active.closest("[data-tree-id]")?.dataset["treeId"] ?? null;
|
|
95
|
+
if (activeRowId === null) return;
|
|
96
|
+
const list = this.visibleNodes();
|
|
97
|
+
if (list.some((fn) => fn.node.id === activeRowId)) return;
|
|
98
|
+
const target = list.some((fn) => fn.node.id === preferredId) ? preferredId : this._tabStopId();
|
|
99
|
+
if (target) this._focus(target);
|
|
100
|
+
}
|
|
101
|
+
depthArray(depth) {
|
|
102
|
+
return Array.from({ length: depth }, (_, i) => i);
|
|
103
|
+
}
|
|
104
|
+
select(node, depth) {
|
|
105
|
+
if (node.disabled || !this.selectable()) return;
|
|
106
|
+
this.selectedId.set(node.id);
|
|
107
|
+
this.nodeSelect.emit(node);
|
|
108
|
+
this.nodeClick.emit({
|
|
109
|
+
node,
|
|
110
|
+
depth
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
isSelected(id) {
|
|
114
|
+
return this.selectedId() === id;
|
|
115
|
+
}
|
|
116
|
+
_tabStopId = computed(() => {
|
|
117
|
+
const list = this.visibleNodes();
|
|
118
|
+
const active = this.activeId();
|
|
119
|
+
if (active !== null && list.some((fn) => fn.node.id === active)) return active;
|
|
120
|
+
return list[0]?.node.id ?? null;
|
|
121
|
+
}, ...ngDevMode ? [{ debugName: "_tabStopId" }] : /* istanbul ignore next */ []);
|
|
122
|
+
treeTabIndex(id) {
|
|
123
|
+
return id === this._tabStopId() ? 0 : -1;
|
|
124
|
+
}
|
|
125
|
+
setActive(id) {
|
|
126
|
+
this.activeId.set(id);
|
|
127
|
+
}
|
|
128
|
+
onKeydown(event, fn, index) {
|
|
129
|
+
const list = this.visibleNodes();
|
|
130
|
+
switch (event.key) {
|
|
131
|
+
case "ArrowDown":
|
|
132
|
+
event.preventDefault();
|
|
133
|
+
this._focusStep(list, index, 1);
|
|
134
|
+
break;
|
|
135
|
+
case "ArrowUp":
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
this._focusStep(list, index, -1);
|
|
138
|
+
break;
|
|
139
|
+
case "Home":
|
|
140
|
+
event.preventDefault();
|
|
141
|
+
this._focusFrom(list, 0, 1);
|
|
142
|
+
break;
|
|
143
|
+
case "End":
|
|
144
|
+
event.preventDefault();
|
|
145
|
+
this._focusFrom(list, list.length - 1, -1);
|
|
146
|
+
break;
|
|
147
|
+
case "PageDown":
|
|
148
|
+
case "PageUp": {
|
|
149
|
+
event.preventDefault();
|
|
150
|
+
const next = svCollectionTarget(event.key, list.length, index, { pageSize: 10 }) ?? index;
|
|
151
|
+
const dir = event.key === "PageDown" ? 1 : -1;
|
|
152
|
+
if (list[next]?.node.disabled) this._focusFrom(list, next, dir);
|
|
153
|
+
else if (list[next]) this._focus(list[next].node.id);
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
case "ArrowRight":
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
if (fn.hasChildren && !fn.isExpanded) this.toggle(fn.node);
|
|
159
|
+
else if (fn.hasChildren && fn.isExpanded) this._focusStep(list, index, 1);
|
|
160
|
+
break;
|
|
161
|
+
case "ArrowLeft":
|
|
162
|
+
event.preventDefault();
|
|
163
|
+
if (fn.hasChildren && fn.isExpanded) this.toggle(fn.node);
|
|
164
|
+
else this._focusParent(list, index, fn.depth);
|
|
165
|
+
break;
|
|
166
|
+
case "Enter":
|
|
167
|
+
case " ":
|
|
168
|
+
event.preventDefault();
|
|
169
|
+
this.select(fn.node, fn.depth);
|
|
170
|
+
this.setActive(fn.node.id);
|
|
171
|
+
break;
|
|
172
|
+
default:
|
|
173
|
+
this._typeahead(event, list, index);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
_typeaheadBuffer = createTypeahead({ labelOf: (fn) => fn.node.label });
|
|
178
|
+
_typeahead(event, list, index) {
|
|
179
|
+
if (!svIsTypeaheadKey(event)) return;
|
|
180
|
+
const enabled = list.filter((fn) => !fn.node.disabled);
|
|
181
|
+
const current = enabled.findIndex((fn) => fn.node.id === list[index]?.node.id);
|
|
182
|
+
const next = this._typeaheadBuffer.handle(event.key, enabled, current);
|
|
183
|
+
if (next === null) return;
|
|
184
|
+
event.preventDefault();
|
|
185
|
+
this._focus(enabled[next].node.id);
|
|
186
|
+
}
|
|
187
|
+
_focusStep(list, from, dir) {
|
|
188
|
+
for (let i = from + dir; i >= 0 && i < list.length; i += dir) if (!list[i].node.disabled) {
|
|
189
|
+
this._focus(list[i].node.id);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
_focusFrom(list, start, dir) {
|
|
194
|
+
for (let i = start; i >= 0 && i < list.length; i += dir) if (!list[i].node.disabled) {
|
|
195
|
+
this._focus(list[i].node.id);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
_focusParent(list, index, depth) {
|
|
200
|
+
for (let i = index - 1; i >= 0; i--) if (list[i].depth < depth) {
|
|
201
|
+
this._focus(list[i].node.id);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
_focus(id) {
|
|
206
|
+
this.setActive(id);
|
|
207
|
+
setTimeout(() => {
|
|
208
|
+
this.host.nativeElement.querySelectorAll("[data-tree-id]").forEach((el) => {
|
|
209
|
+
if (el.dataset["treeId"] === id) el.focus();
|
|
210
|
+
});
|
|
211
|
+
}, 0);
|
|
212
|
+
}
|
|
213
|
+
_flatten(nodes, depth, expanded) {
|
|
214
|
+
const out = [];
|
|
215
|
+
this._flattenInto(out, nodes, depth, expanded);
|
|
216
|
+
return out;
|
|
217
|
+
}
|
|
218
|
+
_flattenInto(out, nodes, depth, expanded) {
|
|
219
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
220
|
+
const node = nodes[i];
|
|
221
|
+
const hasChildren = !!node.children?.length;
|
|
222
|
+
const isExp = expanded.has(node.id);
|
|
223
|
+
out.push({
|
|
224
|
+
node,
|
|
225
|
+
depth,
|
|
226
|
+
isLast: i === nodes.length - 1,
|
|
227
|
+
hasChildren,
|
|
228
|
+
isExpanded: isExp
|
|
229
|
+
});
|
|
230
|
+
if (isExp && node.children?.length) this._flattenInto(out, node.children, depth + 1, expanded);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
_collectExpanded(nodes, ids) {
|
|
234
|
+
for (const n of nodes) {
|
|
235
|
+
if (n.expanded) ids.add(n.id);
|
|
236
|
+
if (n.children) this._collectExpanded(n.children, ids);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
240
|
+
minVersion: "12.0.0",
|
|
241
|
+
version: "22.2.0",
|
|
242
|
+
ngImport: i0,
|
|
243
|
+
type: SvTreeViewComponent,
|
|
244
|
+
deps: [],
|
|
245
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
246
|
+
});
|
|
247
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
248
|
+
minVersion: "17.0.0",
|
|
249
|
+
version: "22.2.0",
|
|
250
|
+
type: SvTreeViewComponent,
|
|
251
|
+
isStandalone: true,
|
|
252
|
+
selector: "sv-tree-view",
|
|
253
|
+
inputs: {
|
|
254
|
+
nodes: {
|
|
255
|
+
classPropertyName: "nodes",
|
|
256
|
+
publicName: "nodes",
|
|
257
|
+
isSignal: true,
|
|
258
|
+
isRequired: false,
|
|
259
|
+
transformFunction: null
|
|
260
|
+
},
|
|
261
|
+
selectable: {
|
|
262
|
+
classPropertyName: "selectable",
|
|
263
|
+
publicName: "selectable",
|
|
264
|
+
isSignal: true,
|
|
265
|
+
isRequired: false,
|
|
266
|
+
transformFunction: null
|
|
267
|
+
},
|
|
268
|
+
showLines: {
|
|
269
|
+
classPropertyName: "showLines",
|
|
270
|
+
publicName: "showLines",
|
|
271
|
+
isSignal: true,
|
|
272
|
+
isRequired: false,
|
|
273
|
+
transformFunction: null
|
|
274
|
+
},
|
|
275
|
+
ariaLabel: {
|
|
276
|
+
classPropertyName: "ariaLabel",
|
|
277
|
+
publicName: "ariaLabel",
|
|
278
|
+
isSignal: true,
|
|
279
|
+
isRequired: false,
|
|
280
|
+
transformFunction: null
|
|
281
|
+
},
|
|
282
|
+
loading: {
|
|
283
|
+
classPropertyName: "loading",
|
|
284
|
+
publicName: "loading",
|
|
285
|
+
isSignal: true,
|
|
286
|
+
isRequired: false,
|
|
287
|
+
transformFunction: null
|
|
288
|
+
},
|
|
289
|
+
error: {
|
|
290
|
+
classPropertyName: "error",
|
|
291
|
+
publicName: "error",
|
|
292
|
+
isSignal: true,
|
|
293
|
+
isRequired: false,
|
|
294
|
+
transformFunction: null
|
|
295
|
+
},
|
|
296
|
+
emptyText: {
|
|
297
|
+
classPropertyName: "emptyText",
|
|
298
|
+
publicName: "emptyText",
|
|
299
|
+
isSignal: true,
|
|
300
|
+
isRequired: false,
|
|
301
|
+
transformFunction: null
|
|
302
|
+
},
|
|
303
|
+
expandedIds: {
|
|
304
|
+
classPropertyName: "expandedIds",
|
|
305
|
+
publicName: "expandedIds",
|
|
306
|
+
isSignal: true,
|
|
307
|
+
isRequired: false,
|
|
308
|
+
transformFunction: null
|
|
309
|
+
},
|
|
310
|
+
selectedId: {
|
|
311
|
+
classPropertyName: "selectedId",
|
|
312
|
+
publicName: "selectedId",
|
|
313
|
+
isSignal: true,
|
|
314
|
+
isRequired: false,
|
|
315
|
+
transformFunction: null
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
outputs: {
|
|
319
|
+
nodeClick: "nodeClick",
|
|
320
|
+
nodeExpand: "nodeExpand",
|
|
321
|
+
nodeCollapse: "nodeCollapse",
|
|
322
|
+
nodeSelect: "nodeSelect",
|
|
323
|
+
retry: "retry",
|
|
324
|
+
expandedIds: "expandedIdsChange",
|
|
325
|
+
selectedId: "selectedIdChange"
|
|
326
|
+
},
|
|
327
|
+
ngImport: i0,
|
|
328
|
+
template: `
|
|
215
329
|
@if (loading()) {
|
|
216
330
|
<div class="p-2" data-sv-state="loading">
|
|
217
331
|
<sv-skeleton-shell variant="list" [rows]="5" ariaLabel="Loading tree" />
|
|
@@ -225,15 +339,14 @@ class SvTreeViewComponent {
|
|
|
225
339
|
/>
|
|
226
340
|
} @else {
|
|
227
341
|
|
|
228
|
-
<div class="sv-tree-view select-none" role="tree">
|
|
342
|
+
<div class="sv-tree-view select-none" role="tree" [attr.aria-label]="ariaLabel().trim() || null">
|
|
229
343
|
@for (fn of visibleNodes(); track fn.node.id) {
|
|
230
|
-
<div class="group flex items-center gap-1 rounded-lg px-1 outline-none transition-colors duration-100 cursor-pointer focus-visible:ring-2 focus-visible:ring-
|
|
344
|
+
<div class="group flex items-center gap-1 rounded-lg px-1 outline-none transition-colors duration-100 cursor-pointer focus-visible:ring-2 focus-visible:ring-brandaccent-400"
|
|
231
345
|
[class]="fn.node.disabled
|
|
232
346
|
? 'opacity-40 cursor-not-allowed py-1.5'
|
|
233
347
|
: isSelected(fn.node.id)
|
|
234
|
-
? 'py-1.5 bg-
|
|
348
|
+
? 'py-1.5 bg-brandaccent-50 dark:bg-brandaccent-900/25'
|
|
235
349
|
: 'py-1.5 hover:bg-gray-100/70 dark:hover:bg-gray-800/50'"
|
|
236
|
-
[style.paddingLeft.px]="fn.depth * 20 + 4"
|
|
237
350
|
(click)="select(fn.node, fn.depth); setActive(fn.node.id)"
|
|
238
351
|
(keydown)="onKeydown($event, fn, $index)"
|
|
239
352
|
role="treeitem"
|
|
@@ -241,21 +354,39 @@ class SvTreeViewComponent {
|
|
|
241
354
|
[attr.tabindex]="treeTabIndex(fn.node.id)"
|
|
242
355
|
[attr.aria-level]="fn.depth + 1"
|
|
243
356
|
[attr.aria-expanded]="fn.hasChildren ? fn.isExpanded : null"
|
|
244
|
-
[attr.aria-selected]="isSelected(fn.node.id)">
|
|
357
|
+
[attr.aria-selected]="selectable() ? isSelected(fn.node.id) : null">
|
|
358
|
+
|
|
359
|
+
<!--
|
|
360
|
+
Depth spacers, one per level, carrying the optional connector guide.
|
|
361
|
+
Indentation used to be a paddingLeft on the row, which left
|
|
362
|
+
showLines - declared, documented, default true - with nothing to
|
|
363
|
+
hang a line on, so it did nothing at all. The Pro twin has rendered
|
|
364
|
+
these all along; this is the same 20px-per-level geometry.
|
|
365
|
+
(No backticks in here: this template is an inline JS literal.)
|
|
366
|
+
-->
|
|
367
|
+
@for (d of depthArray(fn.depth); track d) {
|
|
368
|
+
<span class="relative w-5 shrink-0 self-stretch" aria-hidden="true">
|
|
369
|
+
@if (showLines()) {
|
|
370
|
+
<span class="absolute inset-y-0 left-1/2 w-px -translate-x-1/2
|
|
371
|
+
bg-gray-200 dark:bg-gray-700/70"></span>
|
|
372
|
+
}
|
|
373
|
+
</span>
|
|
374
|
+
}
|
|
245
375
|
|
|
246
376
|
<!-- Chevron toggle -->
|
|
377
|
+
<!-- Out of the tab order (X-10): ArrowRight/ArrowLeft on the row
|
|
378
|
+
expand and collapse, so a 1,500-row tree stays ONE tab stop. -->
|
|
247
379
|
<button type="button"
|
|
380
|
+
tabindex="-1"
|
|
248
381
|
class="flex h-5 w-5 shrink-0 items-center justify-center rounded
|
|
249
382
|
text-gray-400 transition-all hover:text-gray-700 dark:hover:text-gray-200
|
|
250
|
-
focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-
|
|
383
|
+
focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-brandaccent-400"
|
|
251
384
|
[class.invisible]="!fn.hasChildren"
|
|
252
385
|
(click)="toggle(fn.node); $event.stopPropagation()"
|
|
253
|
-
[attr.aria-label]="fn.isExpanded ? 'Collapse' : 'Expand'">
|
|
254
|
-
<
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
<path stroke-linecap="round" stroke-linejoin="round" d="m8.25 4.5 7.5 7.5-7.5 7.5"/>
|
|
258
|
-
</svg>
|
|
386
|
+
[attr.aria-label]="(fn.isExpanded ? 'Collapse ' : 'Expand ') + fn.node.label">
|
|
387
|
+
<sv-icon name="chevron-right"
|
|
388
|
+
[cssClass]="'h-3.5 w-3.5 transition-transform duration-150' + (fn.isExpanded ? ' rotate-90' : '')"
|
|
389
|
+
[strokeWidth]="2" />
|
|
259
390
|
</button>
|
|
260
391
|
|
|
261
392
|
<!-- Icon -->
|
|
@@ -266,7 +397,7 @@ class SvTreeViewComponent {
|
|
|
266
397
|
<!-- Label -->
|
|
267
398
|
<span class="flex-1 truncate text-[13px] font-medium"
|
|
268
399
|
[class]="isSelected(fn.node.id)
|
|
269
|
-
? 'text-
|
|
400
|
+
? 'text-brandaccent-700 dark:text-brandaccent-300'
|
|
270
401
|
: 'text-gray-800 dark:text-gray-100'">
|
|
271
402
|
{{ fn.node.label }}
|
|
272
403
|
</span>
|
|
@@ -288,16 +419,88 @@ class SvTreeViewComponent {
|
|
|
288
419
|
</div>
|
|
289
420
|
}
|
|
290
421
|
|
|
291
|
-
`,
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
422
|
+
`,
|
|
423
|
+
isInline: true,
|
|
424
|
+
dependencies: [
|
|
425
|
+
{
|
|
426
|
+
kind: "component",
|
|
427
|
+
type: SvIconComponent,
|
|
428
|
+
selector: "sv-icon",
|
|
429
|
+
inputs: [
|
|
430
|
+
"name",
|
|
431
|
+
"size",
|
|
432
|
+
"strokeWidth",
|
|
433
|
+
"weight",
|
|
434
|
+
"title",
|
|
435
|
+
"flip",
|
|
436
|
+
"rotate",
|
|
437
|
+
"cssClass"
|
|
438
|
+
]
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
kind: "component",
|
|
442
|
+
type: SvSkeletonShellComponent,
|
|
443
|
+
selector: "sv-skeleton-shell",
|
|
444
|
+
inputs: [
|
|
445
|
+
"variant",
|
|
446
|
+
"rows",
|
|
447
|
+
"columns",
|
|
448
|
+
"chartHeight",
|
|
449
|
+
"ariaLabel",
|
|
450
|
+
"customClass"
|
|
451
|
+
]
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
kind: "component",
|
|
455
|
+
type: SvErrorShellComponent,
|
|
456
|
+
selector: "sv-error-shell",
|
|
457
|
+
inputs: [
|
|
458
|
+
"error",
|
|
459
|
+
"title",
|
|
460
|
+
"retryLabel",
|
|
461
|
+
"retryable",
|
|
462
|
+
"compact",
|
|
463
|
+
"showStatus",
|
|
464
|
+
"customClass"
|
|
465
|
+
],
|
|
466
|
+
outputs: ["retry"]
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
kind: "component",
|
|
470
|
+
type: SvEmptyShellComponent,
|
|
471
|
+
selector: "sv-empty-shell",
|
|
472
|
+
inputs: [
|
|
473
|
+
"reason",
|
|
474
|
+
"title",
|
|
475
|
+
"message",
|
|
476
|
+
"actionLabel",
|
|
477
|
+
"compact",
|
|
478
|
+
"customClass"
|
|
479
|
+
],
|
|
480
|
+
outputs: ["action"]
|
|
481
|
+
}
|
|
482
|
+
],
|
|
483
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
484
|
+
});
|
|
485
|
+
};
|
|
486
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
487
|
+
minVersion: "12.0.0",
|
|
488
|
+
version: "22.2.0",
|
|
489
|
+
ngImport: i0,
|
|
490
|
+
type: SvTreeViewComponent,
|
|
491
|
+
decorators: [{
|
|
492
|
+
type: Component,
|
|
493
|
+
args: [{
|
|
494
|
+
imports: [
|
|
495
|
+
SvIconComponent,
|
|
496
|
+
SvSkeletonShellComponent,
|
|
497
|
+
SvErrorShellComponent,
|
|
498
|
+
SvEmptyShellComponent
|
|
499
|
+
],
|
|
500
|
+
selector: "sv-tree-view",
|
|
501
|
+
standalone: true,
|
|
502
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
503
|
+
template: `
|
|
301
504
|
@if (loading()) {
|
|
302
505
|
<div class="p-2" data-sv-state="loading">
|
|
303
506
|
<sv-skeleton-shell variant="list" [rows]="5" ariaLabel="Loading tree" />
|
|
@@ -311,15 +514,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.18", ngImpo
|
|
|
311
514
|
/>
|
|
312
515
|
} @else {
|
|
313
516
|
|
|
314
|
-
<div class="sv-tree-view select-none" role="tree">
|
|
517
|
+
<div class="sv-tree-view select-none" role="tree" [attr.aria-label]="ariaLabel().trim() || null">
|
|
315
518
|
@for (fn of visibleNodes(); track fn.node.id) {
|
|
316
|
-
<div class="group flex items-center gap-1 rounded-lg px-1 outline-none transition-colors duration-100 cursor-pointer focus-visible:ring-2 focus-visible:ring-
|
|
519
|
+
<div class="group flex items-center gap-1 rounded-lg px-1 outline-none transition-colors duration-100 cursor-pointer focus-visible:ring-2 focus-visible:ring-brandaccent-400"
|
|
317
520
|
[class]="fn.node.disabled
|
|
318
521
|
? 'opacity-40 cursor-not-allowed py-1.5'
|
|
319
522
|
: isSelected(fn.node.id)
|
|
320
|
-
? 'py-1.5 bg-
|
|
523
|
+
? 'py-1.5 bg-brandaccent-50 dark:bg-brandaccent-900/25'
|
|
321
524
|
: 'py-1.5 hover:bg-gray-100/70 dark:hover:bg-gray-800/50'"
|
|
322
|
-
[style.paddingLeft.px]="fn.depth * 20 + 4"
|
|
323
525
|
(click)="select(fn.node, fn.depth); setActive(fn.node.id)"
|
|
324
526
|
(keydown)="onKeydown($event, fn, $index)"
|
|
325
527
|
role="treeitem"
|
|
@@ -327,21 +529,39 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.18", ngImpo
|
|
|
327
529
|
[attr.tabindex]="treeTabIndex(fn.node.id)"
|
|
328
530
|
[attr.aria-level]="fn.depth + 1"
|
|
329
531
|
[attr.aria-expanded]="fn.hasChildren ? fn.isExpanded : null"
|
|
330
|
-
[attr.aria-selected]="isSelected(fn.node.id)">
|
|
532
|
+
[attr.aria-selected]="selectable() ? isSelected(fn.node.id) : null">
|
|
533
|
+
|
|
534
|
+
<!--
|
|
535
|
+
Depth spacers, one per level, carrying the optional connector guide.
|
|
536
|
+
Indentation used to be a paddingLeft on the row, which left
|
|
537
|
+
showLines - declared, documented, default true - with nothing to
|
|
538
|
+
hang a line on, so it did nothing at all. The Pro twin has rendered
|
|
539
|
+
these all along; this is the same 20px-per-level geometry.
|
|
540
|
+
(No backticks in here: this template is an inline JS literal.)
|
|
541
|
+
-->
|
|
542
|
+
@for (d of depthArray(fn.depth); track d) {
|
|
543
|
+
<span class="relative w-5 shrink-0 self-stretch" aria-hidden="true">
|
|
544
|
+
@if (showLines()) {
|
|
545
|
+
<span class="absolute inset-y-0 left-1/2 w-px -translate-x-1/2
|
|
546
|
+
bg-gray-200 dark:bg-gray-700/70"></span>
|
|
547
|
+
}
|
|
548
|
+
</span>
|
|
549
|
+
}
|
|
331
550
|
|
|
332
551
|
<!-- Chevron toggle -->
|
|
552
|
+
<!-- Out of the tab order (X-10): ArrowRight/ArrowLeft on the row
|
|
553
|
+
expand and collapse, so a 1,500-row tree stays ONE tab stop. -->
|
|
333
554
|
<button type="button"
|
|
555
|
+
tabindex="-1"
|
|
334
556
|
class="flex h-5 w-5 shrink-0 items-center justify-center rounded
|
|
335
557
|
text-gray-400 transition-all hover:text-gray-700 dark:hover:text-gray-200
|
|
336
|
-
focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-
|
|
558
|
+
focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-brandaccent-400"
|
|
337
559
|
[class.invisible]="!fn.hasChildren"
|
|
338
560
|
(click)="toggle(fn.node); $event.stopPropagation()"
|
|
339
|
-
[attr.aria-label]="fn.isExpanded ? 'Collapse' : 'Expand'">
|
|
340
|
-
<
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
<path stroke-linecap="round" stroke-linejoin="round" d="m8.25 4.5 7.5 7.5-7.5 7.5"/>
|
|
344
|
-
</svg>
|
|
561
|
+
[attr.aria-label]="(fn.isExpanded ? 'Collapse ' : 'Expand ') + fn.node.label">
|
|
562
|
+
<sv-icon name="chevron-right"
|
|
563
|
+
[cssClass]="'h-3.5 w-3.5 transition-transform duration-150' + (fn.isExpanded ? ' rotate-90' : '')"
|
|
564
|
+
[strokeWidth]="2" />
|
|
345
565
|
</button>
|
|
346
566
|
|
|
347
567
|
<!-- Icon -->
|
|
@@ -352,7 +572,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.18", ngImpo
|
|
|
352
572
|
<!-- Label -->
|
|
353
573
|
<span class="flex-1 truncate text-[13px] font-medium"
|
|
354
574
|
[class]="isSelected(fn.node.id)
|
|
355
|
-
? 'text-
|
|
575
|
+
? 'text-brandaccent-700 dark:text-brandaccent-300'
|
|
356
576
|
: 'text-gray-800 dark:text-gray-100'">
|
|
357
577
|
{{ fn.node.label }}
|
|
358
578
|
</span>
|
|
@@ -374,13 +594,111 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.18", ngImpo
|
|
|
374
594
|
</div>
|
|
375
595
|
}
|
|
376
596
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
597
|
+
`
|
|
598
|
+
}]
|
|
599
|
+
}],
|
|
600
|
+
ctorParameters: () => [],
|
|
601
|
+
propDecorators: {
|
|
602
|
+
nodes: [{
|
|
603
|
+
type: i0.Input,
|
|
604
|
+
args: [{
|
|
605
|
+
isSignal: true,
|
|
606
|
+
alias: "nodes",
|
|
607
|
+
required: false
|
|
608
|
+
}]
|
|
609
|
+
}],
|
|
610
|
+
selectable: [{
|
|
611
|
+
type: i0.Input,
|
|
612
|
+
args: [{
|
|
613
|
+
isSignal: true,
|
|
614
|
+
alias: "selectable",
|
|
615
|
+
required: false
|
|
616
|
+
}]
|
|
617
|
+
}],
|
|
618
|
+
showLines: [{
|
|
619
|
+
type: i0.Input,
|
|
620
|
+
args: [{
|
|
621
|
+
isSignal: true,
|
|
622
|
+
alias: "showLines",
|
|
623
|
+
required: false
|
|
624
|
+
}]
|
|
625
|
+
}],
|
|
626
|
+
ariaLabel: [{
|
|
627
|
+
type: i0.Input,
|
|
628
|
+
args: [{
|
|
629
|
+
isSignal: true,
|
|
630
|
+
alias: "ariaLabel",
|
|
631
|
+
required: false
|
|
632
|
+
}]
|
|
633
|
+
}],
|
|
634
|
+
loading: [{
|
|
635
|
+
type: i0.Input,
|
|
636
|
+
args: [{
|
|
637
|
+
isSignal: true,
|
|
638
|
+
alias: "loading",
|
|
639
|
+
required: false
|
|
640
|
+
}]
|
|
641
|
+
}],
|
|
642
|
+
error: [{
|
|
643
|
+
type: i0.Input,
|
|
644
|
+
args: [{
|
|
645
|
+
isSignal: true,
|
|
646
|
+
alias: "error",
|
|
647
|
+
required: false
|
|
648
|
+
}]
|
|
649
|
+
}],
|
|
650
|
+
emptyText: [{
|
|
651
|
+
type: i0.Input,
|
|
652
|
+
args: [{
|
|
653
|
+
isSignal: true,
|
|
654
|
+
alias: "emptyText",
|
|
655
|
+
required: false
|
|
656
|
+
}]
|
|
657
|
+
}],
|
|
658
|
+
nodeClick: [{
|
|
659
|
+
type: i0.Output,
|
|
660
|
+
args: ["nodeClick"]
|
|
661
|
+
}],
|
|
662
|
+
nodeExpand: [{
|
|
663
|
+
type: i0.Output,
|
|
664
|
+
args: ["nodeExpand"]
|
|
665
|
+
}],
|
|
666
|
+
nodeCollapse: [{
|
|
667
|
+
type: i0.Output,
|
|
668
|
+
args: ["nodeCollapse"]
|
|
669
|
+
}],
|
|
670
|
+
nodeSelect: [{
|
|
671
|
+
type: i0.Output,
|
|
672
|
+
args: ["nodeSelect"]
|
|
673
|
+
}],
|
|
674
|
+
retry: [{
|
|
675
|
+
type: i0.Output,
|
|
676
|
+
args: ["retry"]
|
|
677
|
+
}],
|
|
678
|
+
expandedIds: [{
|
|
679
|
+
type: i0.Input,
|
|
680
|
+
args: [{
|
|
681
|
+
isSignal: true,
|
|
682
|
+
alias: "expandedIds",
|
|
683
|
+
required: false
|
|
684
|
+
}]
|
|
685
|
+
}, {
|
|
686
|
+
type: i0.Output,
|
|
687
|
+
args: ["expandedIdsChange"]
|
|
688
|
+
}],
|
|
689
|
+
selectedId: [{
|
|
690
|
+
type: i0.Input,
|
|
691
|
+
args: [{
|
|
692
|
+
isSignal: true,
|
|
693
|
+
alias: "selectedId",
|
|
694
|
+
required: false
|
|
695
|
+
}]
|
|
696
|
+
}, {
|
|
697
|
+
type: i0.Output,
|
|
698
|
+
args: ["selectedIdChange"]
|
|
699
|
+
}]
|
|
700
|
+
}
|
|
701
|
+
});
|
|
385
702
|
export { SvTreeViewComponent };
|
|
386
|
-
|
|
703
|
+
|
|
704
|
+
//# sourceMappingURL=styloviz-tree-view.mjs.map
|