@styloviz/tree-view 0.4.0 → 1.0.1

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.
@@ -1,228 +1,331 @@
1
- import * as i0 from '@angular/core';
2
- import { input, output, model, signal, inject, ElementRef, computed, effect, ChangeDetectionStrategy, Component } from '@angular/core';
3
- import { SvIconComponent } from '@styloviz/icons';
4
- import { SvSkeletonShellComponent, SvErrorShellComponent, SvEmptyShellComponent } from '@styloviz/core';
5
-
6
- // ─── Component ────────────────────────────────────────────────────────────────
7
- /**
8
- * SvTreeViewComponent (Free) — Collapsible single-select tree.
9
- *
10
- * For the full 8-variant suite (file explorer, checkbox tri-state,
11
- * org chart, tree table, searchable, draggable, lazy-load) upgrade to
12
- * `@styloviz-pro/tree-view`.
13
- *
14
- * @example
15
- * ```html
16
- * <sv-tree-view [nodes]="nodes" (nodeClick)="onNodeClick($event)" />
17
- * ```
18
- */
19
- class SvTreeViewComponent {
20
- /** Tree node data (nested children, optional icons). */
21
- nodes = input([], ...(ngDevMode ? [{ debugName: "nodes" }] : /* istanbul ignore next */ []));
22
- /** Enable single-row selection highlight. @default true */
23
- selectable = input(true, ...(ngDevMode ? [{ debugName: "selectable" }] : /* istanbul ignore next */ []));
24
- /** Show vertical connector guide lines. @default true */
25
- showLines = input(true, ...(ngDevMode ? [{ debugName: "showLines" }] : /* istanbul ignore next */ []));
26
- /**
27
- * True while the tree is being fetched. Replaces it with a placeholder.
28
- * @default false
29
- */
30
- loading = input(false, ...(ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []));
31
- /**
32
- * Load failure. Use `toSvDataError()` from `@styloviz/core` to normalize an
33
- * `HttpErrorResponse`.
34
- * @default null
35
- */
36
- error = input(null, ...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
37
- /** Copy for the empty state. @default 'No items to display' */
38
- emptyText = input('No items to display', ...(ngDevMode ? [{ debugName: "emptyText" }] : /* istanbul ignore next */ []));
39
- nodeClick = output();
40
- nodeExpand = output();
41
- nodeCollapse = output();
42
- nodeSelect = output();
43
- /** The host should re-run the failed load. */
44
- retry = output();
45
- /**
46
- * Expanded node ids. Two-way bindable, so an expansion state loaded from the
47
- * server — or restored from a URL — survives a reload.
48
- */
49
- expandedIds = model(new Set(), ...(ngDevMode ? [{ debugName: "expandedIds" }] : /* istanbul ignore next */ []));
50
- /** The selected node id. Two-way bindable. */
51
- selectedId = model(null, ...(ngDevMode ? [{ debugName: "selectedId" }] : /* istanbul ignore next */ []));
52
- /** The treeitem currently in the tab order (roving tabindex). */
53
- activeId = signal(null, ...(ngDevMode ? [{ debugName: "activeId" }] : /* istanbul ignore next */ []));
54
- _nodes = signal([], ...(ngDevMode ? [{ debugName: "_nodes" }] : /* istanbul ignore next */ []));
55
- host = inject(ElementRef);
56
- visibleNodes = computed(() => this._flatten(this._nodes(), 0, this.expandedIds()), ...(ngDevMode ? [{ debugName: "visibleNodes" }] : /* istanbul ignore next */ []));
57
- /** Applied only on the first non-empty node set — after that the user owns it. */
58
- _seededFromNodes = false;
59
- constructor() {
60
- // `nodes` used to be read once in ngOnInit, so a host that fetched the tree
61
- // asynchronously and bound the result saw an empty component forever.
62
- effect(() => {
63
- const incoming = this.nodes();
64
- this._nodes.set(incoming);
65
- if (this._seededFromNodes || incoming.length === 0)
66
- return;
67
- this._seededFromNodes = true;
68
- const ids = new Set();
69
- this._collectExpanded(incoming, ids);
70
- if (ids.size)
71
- this.expandedIds.set(ids);
72
- // Seed the roving tabindex on the first node so the tree is tab-reachable.
73
- // ★ UNREACHABLE BRANCH — the `?? null` right operand can never be taken.
74
- // The guard four lines up already returned for `incoming.length === 0`,
75
- // `_nodes` was set to `incoming` synchronously above, and `_flatten` of a
76
- // non-empty list always yields at least one row — so `[0]` is defined and
77
- // the `?.` never short-circuits. Kept because the expression is what
78
- // makes the `activeId` type honest; counted as unreachable, not uncovered.
79
- this.activeId.set(this.visibleNodes()[0]?.node.id ?? null);
80
- });
81
- }
82
- toggle(node) {
83
- if (node.disabled)
84
- return;
85
- const ids = new Set(this.expandedIds());
86
- if (ids.has(node.id)) {
87
- ids.delete(node.id);
88
- this.nodeCollapse.emit(node);
89
- }
90
- else {
91
- ids.add(node.id);
92
- this.nodeExpand.emit(node);
93
- }
94
- this.expandedIds.set(ids);
95
- }
96
- /** One entry per ancestor level, for the indentation spacers. */
97
- depthArray(depth) {
98
- return Array.from({ length: depth }, (_, i) => i);
99
- }
100
- select(node, depth) {
101
- if (node.disabled || !this.selectable())
102
- return;
103
- this.selectedId.set(node.id);
104
- this.nodeSelect.emit(node);
105
- this.nodeClick.emit({ node, depth });
106
- }
107
- isSelected(id) { return this.selectedId() === id; }
108
- // ── Keyboard navigation (WAI-ARIA tree) ─────────────────────────────────────
109
- /** Roving tabindex: only the active treeitem is in the tab order. */
110
- treeTabIndex(id) {
111
- const active = this.activeId() ?? this.visibleNodes()[0]?.node.id ?? null;
112
- return id === active ? 0 : -1;
113
- }
114
- setActive(id) { this.activeId.set(id); }
115
- /**
116
- * Arrow / Home / End / Enter / Space handling per the WAI-ARIA tree pattern.
117
- * Arrow Up/Down move between visible rows; Right expands or steps into a
118
- * child; Left collapses or steps to the parent; Enter/Space selects.
119
- */
120
- onKeydown(event, fn, index) {
121
- const list = this.visibleNodes();
122
- switch (event.key) {
123
- case 'ArrowDown':
124
- event.preventDefault();
125
- this._focusStep(list, index, +1);
126
- break;
127
- case 'ArrowUp':
128
- event.preventDefault();
129
- this._focusStep(list, index, -1);
130
- break;
131
- case 'Home':
132
- event.preventDefault();
133
- this._focusFrom(list, 0, +1);
134
- break;
135
- case 'End':
136
- event.preventDefault();
137
- this._focusFrom(list, list.length - 1, -1);
138
- break;
139
- case 'ArrowRight':
140
- event.preventDefault();
141
- if (fn.hasChildren && !fn.isExpanded) {
142
- this.toggle(fn.node);
143
- }
144
- else if (fn.hasChildren && fn.isExpanded) {
145
- this._focusStep(list, index, +1);
146
- }
147
- break;
148
- case 'ArrowLeft':
149
- event.preventDefault();
150
- if (fn.hasChildren && fn.isExpanded) {
151
- this.toggle(fn.node);
152
- }
153
- else {
154
- this._focusParent(list, index, fn.depth);
155
- }
156
- break;
157
- case 'Enter':
158
- case ' ':
159
- event.preventDefault();
160
- this.select(fn.node, fn.depth);
161
- this.setActive(fn.node.id);
162
- break;
163
- default:
164
- return;
165
- }
166
- }
167
- /** Move focus by `dir` steps from `from`, skipping disabled rows. */
168
- _focusStep(list, from, dir) {
169
- for (let i = from + dir; i >= 0 && i < list.length; i += dir) {
170
- if (!list[i].node.disabled) {
171
- this._focus(list[i].node.id);
172
- return;
173
- }
174
- }
175
- }
176
- /** From `start`, find the first enabled row in direction `dir` and focus it. */
177
- _focusFrom(list, start, dir) {
178
- for (let i = start; i >= 0 && i < list.length; i += dir) {
179
- if (!list[i].node.disabled) {
180
- this._focus(list[i].node.id);
181
- return;
182
- }
183
- }
184
- }
185
- /** Focus the parent row (nearest previous row with a smaller depth). */
186
- _focusParent(list, index, depth) {
187
- for (let i = index - 1; i >= 0; i--) {
188
- if (list[i].depth < depth) {
189
- this._focus(list[i].node.id);
190
- return;
191
- }
192
- }
193
- }
194
- /** Set the active id and move DOM focus to that row (after any re-render). */
195
- _focus(id) {
196
- this.setActive(id);
197
- queueMicrotask(() => {
198
- const rows = this.host.nativeElement.querySelectorAll('[data-tree-id]');
199
- rows.forEach(el => { if (el.dataset['treeId'] === id)
200
- el.focus(); });
201
- });
202
- }
203
- _flatten(nodes, depth, expanded) {
204
- const result = [];
205
- for (let i = 0; i < nodes.length; i++) {
206
- const node = nodes[i];
207
- const hasChildren = !!node.children?.length;
208
- const isExp = expanded.has(node.id);
209
- result.push({ node, depth, isLast: i === nodes.length - 1, hasChildren, isExpanded: isExp });
210
- if (isExp && node.children?.length) {
211
- result.push(...this._flatten(node.children, depth + 1, expanded));
212
- }
213
- }
214
- return result;
215
- }
216
- _collectExpanded(nodes, ids) {
217
- for (const n of nodes) {
218
- if (n.expanded)
219
- ids.add(n.id);
220
- if (n.children)
221
- this._collectExpanded(n.children, ids);
222
- }
223
- }
224
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.18", ngImport: i0, type: SvTreeViewComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
225
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.18", type: SvTreeViewComponent, isStandalone: true, selector: "sv-tree-view", inputs: { nodes: { classPropertyName: "nodes", publicName: "nodes", isSignal: true, isRequired: false, transformFunction: null }, selectable: { classPropertyName: "selectable", publicName: "selectable", isSignal: true, isRequired: false, transformFunction: null }, showLines: { classPropertyName: "showLines", publicName: "showLines", isSignal: true, isRequired: false, transformFunction: null }, loading: { classPropertyName: "loading", publicName: "loading", isSignal: true, isRequired: false, transformFunction: null }, error: { classPropertyName: "error", publicName: "error", isSignal: true, isRequired: false, transformFunction: null }, emptyText: { classPropertyName: "emptyText", publicName: "emptyText", isSignal: true, isRequired: false, transformFunction: null }, expandedIds: { classPropertyName: "expandedIds", publicName: "expandedIds", isSignal: true, isRequired: false, transformFunction: null }, selectedId: { classPropertyName: "selectedId", publicName: "selectedId", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { nodeClick: "nodeClick", nodeExpand: "nodeExpand", nodeCollapse: "nodeCollapse", nodeSelect: "nodeSelect", retry: "retry", expandedIds: "expandedIdsChange", selectedId: "selectedIdChange" }, ngImport: i0, template: `
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: `
226
329
  @if (loading()) {
227
330
  <div class="p-2" data-sv-state="loading">
228
331
  <sv-skeleton-shell variant="list" [rows]="5" ariaLabel="Loading tree" />
@@ -236,13 +339,13 @@ class SvTreeViewComponent {
236
339
  />
237
340
  } @else {
238
341
 
239
- <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">
240
343
  @for (fn of visibleNodes(); track fn.node.id) {
241
- <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-indigo-400"
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"
242
345
  [class]="fn.node.disabled
243
346
  ? 'opacity-40 cursor-not-allowed py-1.5'
244
347
  : isSelected(fn.node.id)
245
- ? 'py-1.5 bg-indigo-50 dark:bg-indigo-900/25'
348
+ ? 'py-1.5 bg-brandaccent-50 dark:bg-brandaccent-900/25'
246
349
  : 'py-1.5 hover:bg-gray-100/70 dark:hover:bg-gray-800/50'"
247
350
  (click)="select(fn.node, fn.depth); setActive(fn.node.id)"
248
351
  (keydown)="onKeydown($event, fn, $index)"
@@ -251,7 +354,7 @@ class SvTreeViewComponent {
251
354
  [attr.tabindex]="treeTabIndex(fn.node.id)"
252
355
  [attr.aria-level]="fn.depth + 1"
253
356
  [attr.aria-expanded]="fn.hasChildren ? fn.isExpanded : null"
254
- [attr.aria-selected]="isSelected(fn.node.id)">
357
+ [attr.aria-selected]="selectable() ? isSelected(fn.node.id) : null">
255
358
 
256
359
  <!--
257
360
  Depth spacers, one per level, carrying the optional connector guide.
@@ -271,13 +374,16 @@ class SvTreeViewComponent {
271
374
  }
272
375
 
273
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. -->
274
379
  <button type="button"
380
+ tabindex="-1"
275
381
  class="flex h-5 w-5 shrink-0 items-center justify-center rounded
276
382
  text-gray-400 transition-all hover:text-gray-700 dark:hover:text-gray-200
277
- focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-indigo-400"
383
+ focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-brandaccent-400"
278
384
  [class.invisible]="!fn.hasChildren"
279
385
  (click)="toggle(fn.node); $event.stopPropagation()"
280
- [attr.aria-label]="fn.isExpanded ? 'Collapse' : 'Expand'">
386
+ [attr.aria-label]="(fn.isExpanded ? 'Collapse ' : 'Expand ') + fn.node.label">
281
387
  <sv-icon name="chevron-right"
282
388
  [cssClass]="'h-3.5 w-3.5 transition-transform duration-150' + (fn.isExpanded ? ' rotate-90' : '')"
283
389
  [strokeWidth]="2" />
@@ -291,7 +397,7 @@ class SvTreeViewComponent {
291
397
  <!-- Label -->
292
398
  <span class="flex-1 truncate text-[13px] font-medium"
293
399
  [class]="isSelected(fn.node.id)
294
- ? 'text-indigo-700 dark:text-indigo-300'
400
+ ? 'text-brandaccent-700 dark:text-brandaccent-300'
295
401
  : 'text-gray-800 dark:text-gray-100'">
296
402
  {{ fn.node.label }}
297
403
  </span>
@@ -313,16 +419,88 @@ class SvTreeViewComponent {
313
419
  </div>
314
420
  }
315
421
 
316
- `, isInline: true, dependencies: [{ kind: "component", type: SvIconComponent, selector: "sv-icon", inputs: ["name", "size", "strokeWidth", "weight", "title", "flip", "rotate", "cssClass"] }, { kind: "component", type: SvSkeletonShellComponent, selector: "sv-skeleton-shell", inputs: ["variant", "rows", "columns", "chartHeight", "ariaLabel", "customClass"] }, { kind: "component", type: SvErrorShellComponent, selector: "sv-error-shell", inputs: ["error", "title", "retryLabel", "retryable", "compact", "showStatus", "customClass"], outputs: ["retry"] }, { kind: "component", type: SvEmptyShellComponent, selector: "sv-empty-shell", inputs: ["reason", "title", "message", "actionLabel", "compact", "customClass"], outputs: ["action"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
317
- }
318
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.18", ngImport: i0, type: SvTreeViewComponent, decorators: [{
319
- type: Component,
320
- args: [{
321
- imports: [SvIconComponent, SvSkeletonShellComponent, SvErrorShellComponent, SvEmptyShellComponent],
322
- selector: 'sv-tree-view',
323
- standalone: true,
324
- changeDetection: ChangeDetectionStrategy.OnPush,
325
- template: `
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: `
326
504
  @if (loading()) {
327
505
  <div class="p-2" data-sv-state="loading">
328
506
  <sv-skeleton-shell variant="list" [rows]="5" ariaLabel="Loading tree" />
@@ -336,13 +514,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.18", ngImpo
336
514
  />
337
515
  } @else {
338
516
 
339
- <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">
340
518
  @for (fn of visibleNodes(); track fn.node.id) {
341
- <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-indigo-400"
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"
342
520
  [class]="fn.node.disabled
343
521
  ? 'opacity-40 cursor-not-allowed py-1.5'
344
522
  : isSelected(fn.node.id)
345
- ? 'py-1.5 bg-indigo-50 dark:bg-indigo-900/25'
523
+ ? 'py-1.5 bg-brandaccent-50 dark:bg-brandaccent-900/25'
346
524
  : 'py-1.5 hover:bg-gray-100/70 dark:hover:bg-gray-800/50'"
347
525
  (click)="select(fn.node, fn.depth); setActive(fn.node.id)"
348
526
  (keydown)="onKeydown($event, fn, $index)"
@@ -351,7 +529,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.18", ngImpo
351
529
  [attr.tabindex]="treeTabIndex(fn.node.id)"
352
530
  [attr.aria-level]="fn.depth + 1"
353
531
  [attr.aria-expanded]="fn.hasChildren ? fn.isExpanded : null"
354
- [attr.aria-selected]="isSelected(fn.node.id)">
532
+ [attr.aria-selected]="selectable() ? isSelected(fn.node.id) : null">
355
533
 
356
534
  <!--
357
535
  Depth spacers, one per level, carrying the optional connector guide.
@@ -371,13 +549,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.18", ngImpo
371
549
  }
372
550
 
373
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. -->
374
554
  <button type="button"
555
+ tabindex="-1"
375
556
  class="flex h-5 w-5 shrink-0 items-center justify-center rounded
376
557
  text-gray-400 transition-all hover:text-gray-700 dark:hover:text-gray-200
377
- focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-indigo-400"
558
+ focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-brandaccent-400"
378
559
  [class.invisible]="!fn.hasChildren"
379
560
  (click)="toggle(fn.node); $event.stopPropagation()"
380
- [attr.aria-label]="fn.isExpanded ? 'Collapse' : 'Expand'">
561
+ [attr.aria-label]="(fn.isExpanded ? 'Collapse ' : 'Expand ') + fn.node.label">
381
562
  <sv-icon name="chevron-right"
382
563
  [cssClass]="'h-3.5 w-3.5 transition-transform duration-150' + (fn.isExpanded ? ' rotate-90' : '')"
383
564
  [strokeWidth]="2" />
@@ -391,7 +572,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.18", ngImpo
391
572
  <!-- Label -->
392
573
  <span class="flex-1 truncate text-[13px] font-medium"
393
574
  [class]="isSelected(fn.node.id)
394
- ? 'text-indigo-700 dark:text-indigo-300'
575
+ ? 'text-brandaccent-700 dark:text-brandaccent-300'
395
576
  : 'text-gray-800 dark:text-gray-100'">
396
577
  {{ fn.node.label }}
397
578
  </span>
@@ -413,13 +594,111 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.18", ngImpo
413
594
  </div>
414
595
  }
415
596
 
416
- `,
417
- }]
418
- }], ctorParameters: () => [], propDecorators: { nodes: [{ type: i0.Input, args: [{ isSignal: true, alias: "nodes", required: false }] }], selectable: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectable", required: false }] }], showLines: [{ type: i0.Input, args: [{ isSignal: true, alias: "showLines", required: false }] }], loading: [{ type: i0.Input, args: [{ isSignal: true, alias: "loading", required: false }] }], error: [{ type: i0.Input, args: [{ isSignal: true, alias: "error", required: false }] }], emptyText: [{ type: i0.Input, args: [{ isSignal: true, alias: "emptyText", required: false }] }], nodeClick: [{ type: i0.Output, args: ["nodeClick"] }], nodeExpand: [{ type: i0.Output, args: ["nodeExpand"] }], nodeCollapse: [{ type: i0.Output, args: ["nodeCollapse"] }], nodeSelect: [{ type: i0.Output, args: ["nodeSelect"] }], retry: [{ type: i0.Output, args: ["retry"] }], expandedIds: [{ type: i0.Input, args: [{ isSignal: true, alias: "expandedIds", required: false }] }, { type: i0.Output, args: ["expandedIdsChange"] }], selectedId: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectedId", required: false }] }, { type: i0.Output, args: ["selectedIdChange"] }] } });
419
-
420
- /**
421
- * Generated bundle index. Do not edit.
422
- */
423
-
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
+ });
424
702
  export { SvTreeViewComponent };
425
- //# sourceMappingURL=styloviz-tree-view.mjs.map
703
+
704
+ //# sourceMappingURL=styloviz-tree-view.mjs.map