@styloviz/tree-view 1.0.2 → 2.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,16 +1,56 @@
1
1
  import * as i0 from "@angular/core";
2
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";
3
+ import { DOCUMENT, NgTemplateOutlet } from "@angular/common";
4
+ import { SvIconComponent, registerSvIcons } from "@styloviz/icons";
5
+ import { createTypeahead, svCollectionTarget, svIsRtl, svIsTypeaheadKey, svWarnUnvirtualizedCeiling } from "@styloviz/core/a11y";
6
+ import { SvEmptyShellComponent, SvErrorShellComponent, SvSkeletonShellComponent, svCutHierarchyCycles, warnOnDuplicateItemKeys } from "@styloviz/core/data";
7
+ import { svWarn } from "@styloviz/core/dev";
8
+ import { SvLabelPipe, injectSvLabels } from "@styloviz/core/i18n";
9
+ import { svRecoverFocus, svSuccessorIndex } from "@styloviz/core/overlay";
10
+ import { svAttrSelector } from "@styloviz/core/security";
11
+ import { chevronRightIcon } from "@styloviz/icons/glyph/chevron-right";
12
+ const SV_TREE_VIEW_LABELS = {
13
+ expandNode: "Expand {name}",
14
+ collapseNode: "Collapse {name}",
15
+ errorTitle: "Could not load this tree",
16
+ emptyText: "No items to display",
17
+ orgChart: "Org chart"
18
+ };
19
+ const registerTreeViewIcons = () => registerSvIcons([chevronRightIcon]);
20
+ function nestForOrg(rows) {
21
+ const roots = [];
22
+ const groups = [roots];
23
+ const open = [];
24
+ rows.forEach((fn, index) => {
25
+ const box = {
26
+ fn,
27
+ index,
28
+ posinset: 0,
29
+ setsize: 0,
30
+ children: []
31
+ };
32
+ groups.push(box.children);
33
+ const siblings = fn.depth > 0 && open[fn.depth - 1] ? open[fn.depth - 1].children : roots;
34
+ siblings.push(box);
35
+ box.posinset = siblings.length;
36
+ open[fn.depth] = box;
37
+ open.length = fn.depth + 1;
38
+ });
39
+ for (const group of groups) for (const box of group) box.setsize = group.length;
40
+ return roots;
41
+ }
6
42
  var SvTreeViewComponent = class SvTreeViewComponent {
43
+ svIcons = registerTreeViewIcons();
44
+ labels = injectSvLabels("treeView", SV_TREE_VIEW_LABELS);
7
45
  nodes = input([], ...ngDevMode ? [{ debugName: "nodes" }] : /* istanbul ignore next */ []);
8
46
  selectable = input(true, ...ngDevMode ? [{ debugName: "selectable" }] : /* istanbul ignore next */ []);
9
47
  showLines = input(true, ...ngDevMode ? [{ debugName: "showLines" }] : /* istanbul ignore next */ []);
48
+ layout = input("list", ...ngDevMode ? [{ debugName: "layout" }] : /* istanbul ignore next */ []);
10
49
  ariaLabel = input("", ...ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []);
11
50
  loading = input(false, ...ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []);
12
51
  error = input(null, ...ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []);
13
- emptyText = input("No items to display", ...ngDevMode ? [{ debugName: "emptyText" }] : /* istanbul ignore next */ []);
52
+ iconTemplate = input(null, ...ngDevMode ? [{ debugName: "iconTemplate" }] : /* istanbul ignore next */ []);
53
+ emptyText = input(this.labels.emptyText, ...ngDevMode ? [{ debugName: "emptyText" }] : /* istanbul ignore next */ []);
14
54
  nodeClick = output();
15
55
  nodeExpand = output();
16
56
  nodeCollapse = output();
@@ -28,6 +68,7 @@ var SvTreeViewComponent = class SvTreeViewComponent {
28
68
  warnOnDuplicateItemKeys(rows, (n) => n.node.id, "sv-tree-view [nodes]");
29
69
  return rows;
30
70
  }, ...ngDevMode ? [{ debugName: "visibleNodes" }] : /* istanbul ignore next */ []);
71
+ orgBoxes = computed(() => this.layout() === "org" ? nestForOrg(this.visibleNodes()) : [], ...ngDevMode ? [{ debugName: "orgBoxes" }] : /* istanbul ignore next */ []);
31
72
  _seededFromNodes = false;
32
73
  constructor() {
33
74
  effect(() => {
@@ -49,7 +90,7 @@ var SvTreeViewComponent = class SvTreeViewComponent {
49
90
  if (typeof ngDevMode === "undefined" || !ngDevMode) return;
50
91
  if (!this.ariaLabel().trim() && !this.host.nativeElement.hasAttribute("aria-labelledby") && !this._warnedBindings.has("no-name")) {
51
92
  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).");
93
+ svWarn("[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
94
  }
54
95
  }
55
96
  _focusedRowSnapshot() {
@@ -73,7 +114,7 @@ var SvTreeViewComponent = class SvTreeViewComponent {
73
114
  if (successor && !next?.node.disabled) successor.tabIndex = 0;
74
115
  svRecoverFocus({
75
116
  to: [successor],
76
- fallback: root.querySelector("[role=\"tree\"]")
117
+ fallback: root.querySelector("[data-sv-tree-root], [role=\"tree\"]")
77
118
  });
78
119
  }, 0);
79
120
  }
@@ -98,6 +139,34 @@ var SvTreeViewComponent = class SvTreeViewComponent {
98
139
  const target = list.some((fn) => fn.node.id === preferredId) ? preferredId : this._tabStopId();
99
140
  if (target) this._focus(target);
100
141
  }
142
+ orgBox(box) {
143
+ return box;
144
+ }
145
+ orgItemLabel(node) {
146
+ return [
147
+ node.label,
148
+ node.role,
149
+ node.department,
150
+ node.badge
151
+ ].filter(Boolean).join(", ");
152
+ }
153
+ orgInitials(label) {
154
+ const parts = label.trim().split(/\s+/).filter(Boolean);
155
+ if (parts.length >= 2) return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();
156
+ return (parts[0]?.slice(0, 2) ?? "?").toUpperCase();
157
+ }
158
+ onOrgKeydown(event, box) {
159
+ if (!this._ownsOrgEvent(event)) return;
160
+ this.onKeydown(event, box.fn, box.index);
161
+ }
162
+ onOrgClick(event, box) {
163
+ if (!this._ownsOrgEvent(event) || !event.target.closest("[data-sv-org-card]")) return;
164
+ this.select(box.fn.node, box.fn.depth);
165
+ this.setActive(box.fn.node.id);
166
+ }
167
+ _ownsOrgEvent(event) {
168
+ return event.target?.closest("[role=\"treeitem\"]") === event.currentTarget;
169
+ }
101
170
  depthArray(depth) {
102
171
  return Array.from({ length: depth }, (_, i) => i);
103
172
  }
@@ -127,7 +196,7 @@ var SvTreeViewComponent = class SvTreeViewComponent {
127
196
  }
128
197
  onKeydown(event, fn, index) {
129
198
  const list = this.visibleNodes();
130
- switch (event.key) {
199
+ switch (this._inlineArrow(event.key)) {
131
200
  case "ArrowDown":
132
201
  event.preventDefault();
133
202
  this._focusStep(list, index, 1);
@@ -174,6 +243,10 @@ var SvTreeViewComponent = class SvTreeViewComponent {
174
243
  return;
175
244
  }
176
245
  }
246
+ _inlineArrow(key) {
247
+ if (key !== "ArrowLeft" && key !== "ArrowRight" || !svIsRtl(this.host.nativeElement)) return key;
248
+ return key === "ArrowLeft" ? "ArrowRight" : "ArrowLeft";
249
+ }
177
250
  _typeaheadBuffer = createTypeahead({ labelOf: (fn) => fn.node.label });
178
251
  _typeahead(event, list, index) {
179
252
  if (!svIsTypeaheadKey(event)) return;
@@ -272,6 +345,13 @@ var SvTreeViewComponent = class SvTreeViewComponent {
272
345
  isRequired: false,
273
346
  transformFunction: null
274
347
  },
348
+ layout: {
349
+ classPropertyName: "layout",
350
+ publicName: "layout",
351
+ isSignal: true,
352
+ isRequired: false,
353
+ transformFunction: null
354
+ },
275
355
  ariaLabel: {
276
356
  classPropertyName: "ariaLabel",
277
357
  publicName: "ariaLabel",
@@ -293,6 +373,13 @@ var SvTreeViewComponent = class SvTreeViewComponent {
293
373
  isRequired: false,
294
374
  transformFunction: null
295
375
  },
376
+ iconTemplate: {
377
+ classPropertyName: "iconTemplate",
378
+ publicName: "iconTemplate",
379
+ isSignal: true,
380
+ isRequired: false,
381
+ transformFunction: null
382
+ },
296
383
  emptyText: {
297
384
  classPropertyName: "emptyText",
298
385
  publicName: "emptyText",
@@ -333,13 +420,41 @@ var SvTreeViewComponent = class SvTreeViewComponent {
333
420
  } @else if (error()) {
334
421
  <sv-error-shell
335
422
  [error]="error()"
336
- title="Could not load this tree"
423
+ [title]="labels.errorTitle"
337
424
  (retry)="retry.emit()"
338
425
  data-sv-state="error"
339
426
  />
427
+ } @else if (layout() === 'org') {
428
+ @if (!visibleNodes().length) {
429
+ <sv-empty-shell reason="no-data" [title]="emptyText()" data-sv-state="empty" />
430
+ } @else {
431
+ <!--
432
+ The org layout. A wide chart scrolls sideways inside this labelled
433
+ region, never the page; on paper the region lets go and the whole
434
+ chart prints. The tree inside is the SAME tree as the list layout:
435
+ role tree, treeitem and group, one tab stop, one keyboard engine.
436
+ -->
437
+ <div class="sv-tree-view-org overflow-x-auto rounded-xl outline-none
438
+ focus-visible:ring-2 focus-visible:ring-brandaccent-400 print:overflow-visible"
439
+ role="region"
440
+ tabindex="0"
441
+ data-sv-tree-layout="org"
442
+ [attr.aria-label]="ariaLabel().trim() || labels.orgChart">
443
+ <ul class="flex w-max min-w-full select-none items-start justify-center gap-8 p-4"
444
+ role="tree"
445
+ [attr.aria-label]="ariaLabel().trim() || null">
446
+ @for (box of orgBoxes(); track box.fn.node.id) {
447
+ <ng-container [ngTemplateOutlet]="orgBranch" [ngTemplateOutletContext]="{ $implicit: box }" />
448
+ }
449
+ </ul>
450
+ </div>
451
+ }
340
452
  } @else {
341
453
 
342
- <div class="sv-tree-view select-none" role="tree" [attr.aria-label]="ariaLabel().trim() || null">
454
+ <!-- A tree must own a treeitem (axe aria-required-children, critical), so
455
+ with no rows it is a named group around the empty shell. -->
456
+ <div class="sv-tree-view select-none" [attr.role]="visibleNodes().length ? 'tree' : 'group'"
457
+ [attr.aria-label]="ariaLabel().trim() || null" data-sv-tree-root>
343
458
  @for (fn of visibleNodes(); track fn.node.id) {
344
459
  <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"
345
460
  [class]="fn.node.disabled
@@ -367,6 +482,7 @@ var SvTreeViewComponent = class SvTreeViewComponent {
367
482
  @for (d of depthArray(fn.depth); track d) {
368
483
  <span class="relative w-5 shrink-0 self-stretch" aria-hidden="true">
369
484
  @if (showLines()) {
485
+ <!-- sv-physical: centring — the guide line is centred in its indent cell -->
370
486
  <span class="absolute inset-y-0 left-1/2 w-px -translate-x-1/2
371
487
  bg-gray-200 dark:bg-gray-700/70"></span>
372
488
  }
@@ -374,23 +490,28 @@ var SvTreeViewComponent = class SvTreeViewComponent {
374
490
  }
375
491
 
376
492
  <!-- Chevron toggle -->
377
- <!-- Out of the tab order (X-10): ArrowRight/ArrowLeft on the row
493
+ <!-- Out of the tab order: ArrowRight/ArrowLeft on the row
378
494
  expand and collapse, so a 1,500-row tree stays ONE tab stop. -->
379
495
  <button type="button"
380
496
  tabindex="-1"
381
- class="flex h-5 w-5 shrink-0 items-center justify-center rounded
497
+ class="sv-target flex h-5 w-5 shrink-0 items-center justify-center rounded
382
498
  text-gray-400 transition-all hover:text-gray-700 dark:hover:text-gray-200
383
499
  focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-brandaccent-400"
384
500
  [class.invisible]="!fn.hasChildren"
385
501
  (click)="toggle(fn.node); $event.stopPropagation()"
386
- [attr.aria-label]="(fn.isExpanded ? 'Collapse ' : 'Expand ') + fn.node.label">
502
+ [attr.aria-label]="(fn.isExpanded ? labels.collapseNode : labels.expandNode) | svLabel: { name: fn.node.label }">
387
503
  <sv-icon name="chevron-right"
388
- [cssClass]="'h-3.5 w-3.5 transition-transform duration-150' + (fn.isExpanded ? ' rotate-90' : '')"
504
+ [cssClass]="'h-3.5 w-3.5 transition-transform duration-150 rtl:-scale-x-100' + (fn.isExpanded ? ' rotate-90 rtl:-rotate-90' : '')"
389
505
  [strokeWidth]="2" />
390
506
  </button>
391
507
 
392
- <!-- Icon -->
393
- @if (fn.node.icon) {
508
+ <!-- Icon: the host's template when given (a glyph per node), else the text icon. -->
509
+ @if (iconTemplate(); as iconTpl) {
510
+ <span class="flex shrink-0 items-center" aria-hidden="true" data-sv-tree-icon>
511
+ <ng-container [ngTemplateOutlet]="iconTpl"
512
+ [ngTemplateOutletContext]="{ $implicit: fn.node, expanded: fn.isExpanded, depth: fn.depth }" />
513
+ </span>
514
+ } @else if (fn.node.icon) {
394
515
  <span class="shrink-0 text-sm" aria-hidden="true">{{ fn.node.icon }}</span>
395
516
  }
396
517
 
@@ -404,7 +525,7 @@ var SvTreeViewComponent = class SvTreeViewComponent {
404
525
 
405
526
  <!-- Badge -->
406
527
  @if (fn.node.badge) {
407
- <span class="ml-auto shrink-0 rounded-full bg-gray-100 px-1.5 py-px
528
+ <span class="ms-auto shrink-0 rounded-full bg-gray-100 px-1.5 py-px
408
529
  text-[10px] font-semibold text-gray-600
409
530
  dark:bg-gray-800 dark:text-gray-300">
410
531
  {{ fn.node.badge }}
@@ -419,9 +540,135 @@ var SvTreeViewComponent = class SvTreeViewComponent {
419
540
  </div>
420
541
  }
421
542
 
543
+ <!--
544
+ One box of the org layout, and its subtree. The treeitem is the li, so
545
+ its group of children sits INSIDE it as the pattern requires; its name is
546
+ set explicitly, because a name taken from content would read out every
547
+ descendant below it.
548
+
549
+ Connectors are CSS borders on two half-width spans across the top of each
550
+ child: the start half carries the bar from the previous sibling, the end
551
+ half the bar to the next one plus the drop into this box. First and last
552
+ children leave off the outer half, an only child keeps just the drop.
553
+ Logical sides throughout, so RTL mirrors with no extra rule.
554
+ -->
555
+ <ng-template #orgBranch let-box>
556
+ @let b = orgBox(box);
557
+ <li class="relative flex flex-col items-center px-2 outline-none
558
+ [&:focus-visible>.sv-org-card]:ring-2 [&:focus-visible>.sv-org-card]:ring-brandaccent-400"
559
+ [class.pt-6]="b.fn.depth > 0"
560
+ [class.pb-3]="b.fn.hasChildren && !b.fn.isExpanded"
561
+ role="treeitem"
562
+ [attr.data-tree-id]="b.fn.node.id"
563
+ [attr.tabindex]="treeTabIndex(b.fn.node.id)"
564
+ [attr.aria-label]="orgItemLabel(b.fn.node)"
565
+ [attr.aria-level]="b.fn.depth + 1"
566
+ [attr.aria-setsize]="b.setsize"
567
+ [attr.aria-posinset]="b.posinset"
568
+ [attr.aria-expanded]="b.fn.hasChildren ? b.fn.isExpanded : null"
569
+ [attr.aria-selected]="selectable() ? isSelected(b.fn.node.id) : null"
570
+ [attr.aria-disabled]="b.fn.node.disabled || null"
571
+ (click)="onOrgClick($event, b)"
572
+ (keydown)="onOrgKeydown($event, b)">
573
+
574
+ @if (b.fn.depth > 0) {
575
+ <span class="pointer-events-none absolute inset-x-0 top-0 h-6" aria-hidden="true" data-sv-org-connector>
576
+ <span class="absolute start-0 top-0 h-full w-1/2 border-gray-300 dark:border-gray-600"
577
+ [class.border-t]="b.posinset > 1"
578
+ [class.border-e]="b.setsize > 1 && b.posinset === b.setsize"
579
+ [class.rounded-se-lg]="b.setsize > 1 && b.posinset === b.setsize"></span>
580
+ <span class="absolute end-0 top-0 h-full w-1/2 border-gray-300 dark:border-gray-600"
581
+ [class.border-t]="b.posinset < b.setsize"
582
+ [class.border-s]="b.posinset < b.setsize || b.setsize === 1"
583
+ [class.rounded-ss-lg]="b.posinset === 1 && b.setsize > 1"></span>
584
+ </span>
585
+ }
586
+
587
+ <div class="sv-org-card relative w-52 rounded-xl border px-3 py-2.5 text-start shadow-sm
588
+ transition-colors duration-100 print:break-inside-avoid print:shadow-none"
589
+ [class]="b.fn.node.disabled
590
+ ? 'cursor-not-allowed border-gray-200 bg-white opacity-40 dark:border-gray-700 dark:bg-gray-900'
591
+ : isSelected(b.fn.node.id)
592
+ ? 'cursor-pointer border-brandaccent-400 bg-brandaccent-50 dark:border-brandaccent-500 dark:bg-brandaccent-950'
593
+ : 'cursor-pointer border-gray-200 bg-white hover:border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:hover:border-gray-600'"
594
+ data-sv-org-card>
595
+ <div class="flex items-center gap-2.5">
596
+ <span class="flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-brandaccent-100
597
+ text-xs font-bold text-brandaccent-700 dark:bg-brandaccent-900/40 dark:text-brandaccent-200"
598
+ aria-hidden="true">{{ b.fn.node.icon || orgInitials(b.fn.node.label) }}</span>
599
+ <span class="flex min-w-0 flex-1 flex-col">
600
+ <span class="truncate text-[13px] font-semibold leading-tight"
601
+ [class]="isSelected(b.fn.node.id)
602
+ ? 'text-brandaccent-700 dark:text-brandaccent-300'
603
+ : 'text-gray-900 dark:text-gray-100'">{{ b.fn.node.label }}</span>
604
+ @if (b.fn.node.role) {
605
+ <span class="truncate text-[11px] leading-tight text-gray-500 dark:text-gray-400">{{ b.fn.node.role }}</span>
606
+ }
607
+ </span>
608
+ </div>
609
+ @if (b.fn.node.department || b.fn.node.badge) {
610
+ <span class="mt-2 flex items-center gap-1.5">
611
+ @if (b.fn.node.department) {
612
+ <span class="truncate rounded-md bg-gray-100 px-1.5 py-0.5 text-[10px] font-medium
613
+ text-gray-600 dark:bg-gray-800 dark:text-gray-300">{{ b.fn.node.department }}</span>
614
+ }
615
+ @if (b.fn.node.badge) {
616
+ <span class="ms-auto shrink-0 rounded-full bg-gray-100 px-1.5 py-px text-[10px] font-semibold
617
+ text-gray-600 dark:bg-gray-800 dark:text-gray-300">{{ b.fn.node.badge }}</span>
618
+ }
619
+ </span>
620
+ }
621
+
622
+ <!-- Out of the tab order like the list chevron: ArrowRight and
623
+ ArrowLeft on the box expand and collapse it. Collapsed, it says
624
+ how many boxes are folded away under it. -->
625
+ @if (b.fn.hasChildren) {
626
+ <span class="absolute inset-x-0 -bottom-3 flex justify-center">
627
+ <button type="button"
628
+ tabindex="-1"
629
+ class="sv-target flex h-6 min-w-6 items-center justify-center gap-0.5 rounded-full border
630
+ border-gray-300 bg-white px-1.5 text-[10px] font-semibold text-gray-600 shadow-sm
631
+ transition-colors hover:border-brandaccent-400 hover:text-brandaccent-700
632
+ focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brandaccent-400
633
+ dark:border-gray-600 dark:bg-gray-800 dark:text-gray-300
634
+ dark:hover:border-brandaccent-400 dark:hover:text-brandaccent-300 print:hidden"
635
+ data-sv-org-toggle
636
+ (click)="toggle(b.fn.node); setActive(b.fn.node.id); $event.stopPropagation()"
637
+ [attr.aria-label]="(b.fn.isExpanded ? labels.collapseNode : labels.expandNode) | svLabel: { name: b.fn.node.label }">
638
+ @if (!b.fn.isExpanded) {
639
+ <span aria-hidden="true">{{ b.fn.node.children?.length }}</span>
640
+ }
641
+ <sv-icon name="chevron-right"
642
+ [cssClass]="'h-3 w-3 transition-transform duration-150 ' + (b.fn.isExpanded ? '-rotate-90' : 'rotate-90')"
643
+ [strokeWidth]="2.5" />
644
+ </button>
645
+ </span>
646
+ }
647
+ </div>
648
+
649
+ @if (b.children.length) {
650
+ <span class="h-6 w-px shrink-0 bg-gray-300 dark:bg-gray-600" aria-hidden="true" data-sv-org-stem></span>
651
+ <ul class="flex items-start justify-center" role="group">
652
+ @for (child of b.children; track child.fn.node.id) {
653
+ <ng-container [ngTemplateOutlet]="orgBranch" [ngTemplateOutletContext]="{ $implicit: child }" />
654
+ }
655
+ </ul>
656
+ }
657
+ </li>
658
+ </ng-template>
422
659
  `,
423
660
  isInline: true,
424
661
  dependencies: [
662
+ {
663
+ kind: "directive",
664
+ type: NgTemplateOutlet,
665
+ selector: "[ngTemplateOutlet]",
666
+ inputs: [
667
+ "ngTemplateOutletContext",
668
+ "ngTemplateOutlet",
669
+ "ngTemplateOutletInjector"
670
+ ]
671
+ },
425
672
  {
426
673
  kind: "component",
427
674
  type: SvIconComponent,
@@ -478,6 +725,11 @@ var SvTreeViewComponent = class SvTreeViewComponent {
478
725
  "customClass"
479
726
  ],
480
727
  outputs: ["action"]
728
+ },
729
+ {
730
+ kind: "pipe",
731
+ type: SvLabelPipe,
732
+ name: "svLabel"
481
733
  }
482
734
  ],
483
735
  changeDetection: i0.ChangeDetectionStrategy.OnPush
@@ -492,10 +744,12 @@ i0.ɵɵngDeclareClassMetadata({
492
744
  type: Component,
493
745
  args: [{
494
746
  imports: [
747
+ NgTemplateOutlet,
495
748
  SvIconComponent,
496
749
  SvSkeletonShellComponent,
497
750
  SvErrorShellComponent,
498
- SvEmptyShellComponent
751
+ SvEmptyShellComponent,
752
+ SvLabelPipe
499
753
  ],
500
754
  selector: "sv-tree-view",
501
755
  standalone: true,
@@ -508,13 +762,41 @@ i0.ɵɵngDeclareClassMetadata({
508
762
  } @else if (error()) {
509
763
  <sv-error-shell
510
764
  [error]="error()"
511
- title="Could not load this tree"
765
+ [title]="labels.errorTitle"
512
766
  (retry)="retry.emit()"
513
767
  data-sv-state="error"
514
768
  />
769
+ } @else if (layout() === 'org') {
770
+ @if (!visibleNodes().length) {
771
+ <sv-empty-shell reason="no-data" [title]="emptyText()" data-sv-state="empty" />
772
+ } @else {
773
+ <!--
774
+ The org layout. A wide chart scrolls sideways inside this labelled
775
+ region, never the page; on paper the region lets go and the whole
776
+ chart prints. The tree inside is the SAME tree as the list layout:
777
+ role tree, treeitem and group, one tab stop, one keyboard engine.
778
+ -->
779
+ <div class="sv-tree-view-org overflow-x-auto rounded-xl outline-none
780
+ focus-visible:ring-2 focus-visible:ring-brandaccent-400 print:overflow-visible"
781
+ role="region"
782
+ tabindex="0"
783
+ data-sv-tree-layout="org"
784
+ [attr.aria-label]="ariaLabel().trim() || labels.orgChart">
785
+ <ul class="flex w-max min-w-full select-none items-start justify-center gap-8 p-4"
786
+ role="tree"
787
+ [attr.aria-label]="ariaLabel().trim() || null">
788
+ @for (box of orgBoxes(); track box.fn.node.id) {
789
+ <ng-container [ngTemplateOutlet]="orgBranch" [ngTemplateOutletContext]="{ $implicit: box }" />
790
+ }
791
+ </ul>
792
+ </div>
793
+ }
515
794
  } @else {
516
795
 
517
- <div class="sv-tree-view select-none" role="tree" [attr.aria-label]="ariaLabel().trim() || null">
796
+ <!-- A tree must own a treeitem (axe aria-required-children, critical), so
797
+ with no rows it is a named group around the empty shell. -->
798
+ <div class="sv-tree-view select-none" [attr.role]="visibleNodes().length ? 'tree' : 'group'"
799
+ [attr.aria-label]="ariaLabel().trim() || null" data-sv-tree-root>
518
800
  @for (fn of visibleNodes(); track fn.node.id) {
519
801
  <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"
520
802
  [class]="fn.node.disabled
@@ -542,6 +824,7 @@ i0.ɵɵngDeclareClassMetadata({
542
824
  @for (d of depthArray(fn.depth); track d) {
543
825
  <span class="relative w-5 shrink-0 self-stretch" aria-hidden="true">
544
826
  @if (showLines()) {
827
+ <!-- sv-physical: centring — the guide line is centred in its indent cell -->
545
828
  <span class="absolute inset-y-0 left-1/2 w-px -translate-x-1/2
546
829
  bg-gray-200 dark:bg-gray-700/70"></span>
547
830
  }
@@ -549,23 +832,28 @@ i0.ɵɵngDeclareClassMetadata({
549
832
  }
550
833
 
551
834
  <!-- Chevron toggle -->
552
- <!-- Out of the tab order (X-10): ArrowRight/ArrowLeft on the row
835
+ <!-- Out of the tab order: ArrowRight/ArrowLeft on the row
553
836
  expand and collapse, so a 1,500-row tree stays ONE tab stop. -->
554
837
  <button type="button"
555
838
  tabindex="-1"
556
- class="flex h-5 w-5 shrink-0 items-center justify-center rounded
839
+ class="sv-target flex h-5 w-5 shrink-0 items-center justify-center rounded
557
840
  text-gray-400 transition-all hover:text-gray-700 dark:hover:text-gray-200
558
841
  focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-brandaccent-400"
559
842
  [class.invisible]="!fn.hasChildren"
560
843
  (click)="toggle(fn.node); $event.stopPropagation()"
561
- [attr.aria-label]="(fn.isExpanded ? 'Collapse ' : 'Expand ') + fn.node.label">
844
+ [attr.aria-label]="(fn.isExpanded ? labels.collapseNode : labels.expandNode) | svLabel: { name: fn.node.label }">
562
845
  <sv-icon name="chevron-right"
563
- [cssClass]="'h-3.5 w-3.5 transition-transform duration-150' + (fn.isExpanded ? ' rotate-90' : '')"
846
+ [cssClass]="'h-3.5 w-3.5 transition-transform duration-150 rtl:-scale-x-100' + (fn.isExpanded ? ' rotate-90 rtl:-rotate-90' : '')"
564
847
  [strokeWidth]="2" />
565
848
  </button>
566
849
 
567
- <!-- Icon -->
568
- @if (fn.node.icon) {
850
+ <!-- Icon: the host's template when given (a glyph per node), else the text icon. -->
851
+ @if (iconTemplate(); as iconTpl) {
852
+ <span class="flex shrink-0 items-center" aria-hidden="true" data-sv-tree-icon>
853
+ <ng-container [ngTemplateOutlet]="iconTpl"
854
+ [ngTemplateOutletContext]="{ $implicit: fn.node, expanded: fn.isExpanded, depth: fn.depth }" />
855
+ </span>
856
+ } @else if (fn.node.icon) {
569
857
  <span class="shrink-0 text-sm" aria-hidden="true">{{ fn.node.icon }}</span>
570
858
  }
571
859
 
@@ -579,7 +867,7 @@ i0.ɵɵngDeclareClassMetadata({
579
867
 
580
868
  <!-- Badge -->
581
869
  @if (fn.node.badge) {
582
- <span class="ml-auto shrink-0 rounded-full bg-gray-100 px-1.5 py-px
870
+ <span class="ms-auto shrink-0 rounded-full bg-gray-100 px-1.5 py-px
583
871
  text-[10px] font-semibold text-gray-600
584
872
  dark:bg-gray-800 dark:text-gray-300">
585
873
  {{ fn.node.badge }}
@@ -594,6 +882,122 @@ i0.ɵɵngDeclareClassMetadata({
594
882
  </div>
595
883
  }
596
884
 
885
+ <!--
886
+ One box of the org layout, and its subtree. The treeitem is the li, so
887
+ its group of children sits INSIDE it as the pattern requires; its name is
888
+ set explicitly, because a name taken from content would read out every
889
+ descendant below it.
890
+
891
+ Connectors are CSS borders on two half-width spans across the top of each
892
+ child: the start half carries the bar from the previous sibling, the end
893
+ half the bar to the next one plus the drop into this box. First and last
894
+ children leave off the outer half, an only child keeps just the drop.
895
+ Logical sides throughout, so RTL mirrors with no extra rule.
896
+ -->
897
+ <ng-template #orgBranch let-box>
898
+ @let b = orgBox(box);
899
+ <li class="relative flex flex-col items-center px-2 outline-none
900
+ [&:focus-visible>.sv-org-card]:ring-2 [&:focus-visible>.sv-org-card]:ring-brandaccent-400"
901
+ [class.pt-6]="b.fn.depth > 0"
902
+ [class.pb-3]="b.fn.hasChildren && !b.fn.isExpanded"
903
+ role="treeitem"
904
+ [attr.data-tree-id]="b.fn.node.id"
905
+ [attr.tabindex]="treeTabIndex(b.fn.node.id)"
906
+ [attr.aria-label]="orgItemLabel(b.fn.node)"
907
+ [attr.aria-level]="b.fn.depth + 1"
908
+ [attr.aria-setsize]="b.setsize"
909
+ [attr.aria-posinset]="b.posinset"
910
+ [attr.aria-expanded]="b.fn.hasChildren ? b.fn.isExpanded : null"
911
+ [attr.aria-selected]="selectable() ? isSelected(b.fn.node.id) : null"
912
+ [attr.aria-disabled]="b.fn.node.disabled || null"
913
+ (click)="onOrgClick($event, b)"
914
+ (keydown)="onOrgKeydown($event, b)">
915
+
916
+ @if (b.fn.depth > 0) {
917
+ <span class="pointer-events-none absolute inset-x-0 top-0 h-6" aria-hidden="true" data-sv-org-connector>
918
+ <span class="absolute start-0 top-0 h-full w-1/2 border-gray-300 dark:border-gray-600"
919
+ [class.border-t]="b.posinset > 1"
920
+ [class.border-e]="b.setsize > 1 && b.posinset === b.setsize"
921
+ [class.rounded-se-lg]="b.setsize > 1 && b.posinset === b.setsize"></span>
922
+ <span class="absolute end-0 top-0 h-full w-1/2 border-gray-300 dark:border-gray-600"
923
+ [class.border-t]="b.posinset < b.setsize"
924
+ [class.border-s]="b.posinset < b.setsize || b.setsize === 1"
925
+ [class.rounded-ss-lg]="b.posinset === 1 && b.setsize > 1"></span>
926
+ </span>
927
+ }
928
+
929
+ <div class="sv-org-card relative w-52 rounded-xl border px-3 py-2.5 text-start shadow-sm
930
+ transition-colors duration-100 print:break-inside-avoid print:shadow-none"
931
+ [class]="b.fn.node.disabled
932
+ ? 'cursor-not-allowed border-gray-200 bg-white opacity-40 dark:border-gray-700 dark:bg-gray-900'
933
+ : isSelected(b.fn.node.id)
934
+ ? 'cursor-pointer border-brandaccent-400 bg-brandaccent-50 dark:border-brandaccent-500 dark:bg-brandaccent-950'
935
+ : 'cursor-pointer border-gray-200 bg-white hover:border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:hover:border-gray-600'"
936
+ data-sv-org-card>
937
+ <div class="flex items-center gap-2.5">
938
+ <span class="flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-brandaccent-100
939
+ text-xs font-bold text-brandaccent-700 dark:bg-brandaccent-900/40 dark:text-brandaccent-200"
940
+ aria-hidden="true">{{ b.fn.node.icon || orgInitials(b.fn.node.label) }}</span>
941
+ <span class="flex min-w-0 flex-1 flex-col">
942
+ <span class="truncate text-[13px] font-semibold leading-tight"
943
+ [class]="isSelected(b.fn.node.id)
944
+ ? 'text-brandaccent-700 dark:text-brandaccent-300'
945
+ : 'text-gray-900 dark:text-gray-100'">{{ b.fn.node.label }}</span>
946
+ @if (b.fn.node.role) {
947
+ <span class="truncate text-[11px] leading-tight text-gray-500 dark:text-gray-400">{{ b.fn.node.role }}</span>
948
+ }
949
+ </span>
950
+ </div>
951
+ @if (b.fn.node.department || b.fn.node.badge) {
952
+ <span class="mt-2 flex items-center gap-1.5">
953
+ @if (b.fn.node.department) {
954
+ <span class="truncate rounded-md bg-gray-100 px-1.5 py-0.5 text-[10px] font-medium
955
+ text-gray-600 dark:bg-gray-800 dark:text-gray-300">{{ b.fn.node.department }}</span>
956
+ }
957
+ @if (b.fn.node.badge) {
958
+ <span class="ms-auto shrink-0 rounded-full bg-gray-100 px-1.5 py-px text-[10px] font-semibold
959
+ text-gray-600 dark:bg-gray-800 dark:text-gray-300">{{ b.fn.node.badge }}</span>
960
+ }
961
+ </span>
962
+ }
963
+
964
+ <!-- Out of the tab order like the list chevron: ArrowRight and
965
+ ArrowLeft on the box expand and collapse it. Collapsed, it says
966
+ how many boxes are folded away under it. -->
967
+ @if (b.fn.hasChildren) {
968
+ <span class="absolute inset-x-0 -bottom-3 flex justify-center">
969
+ <button type="button"
970
+ tabindex="-1"
971
+ class="sv-target flex h-6 min-w-6 items-center justify-center gap-0.5 rounded-full border
972
+ border-gray-300 bg-white px-1.5 text-[10px] font-semibold text-gray-600 shadow-sm
973
+ transition-colors hover:border-brandaccent-400 hover:text-brandaccent-700
974
+ focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brandaccent-400
975
+ dark:border-gray-600 dark:bg-gray-800 dark:text-gray-300
976
+ dark:hover:border-brandaccent-400 dark:hover:text-brandaccent-300 print:hidden"
977
+ data-sv-org-toggle
978
+ (click)="toggle(b.fn.node); setActive(b.fn.node.id); $event.stopPropagation()"
979
+ [attr.aria-label]="(b.fn.isExpanded ? labels.collapseNode : labels.expandNode) | svLabel: { name: b.fn.node.label }">
980
+ @if (!b.fn.isExpanded) {
981
+ <span aria-hidden="true">{{ b.fn.node.children?.length }}</span>
982
+ }
983
+ <sv-icon name="chevron-right"
984
+ [cssClass]="'h-3 w-3 transition-transform duration-150 ' + (b.fn.isExpanded ? '-rotate-90' : 'rotate-90')"
985
+ [strokeWidth]="2.5" />
986
+ </button>
987
+ </span>
988
+ }
989
+ </div>
990
+
991
+ @if (b.children.length) {
992
+ <span class="h-6 w-px shrink-0 bg-gray-300 dark:bg-gray-600" aria-hidden="true" data-sv-org-stem></span>
993
+ <ul class="flex items-start justify-center" role="group">
994
+ @for (child of b.children; track child.fn.node.id) {
995
+ <ng-container [ngTemplateOutlet]="orgBranch" [ngTemplateOutletContext]="{ $implicit: child }" />
996
+ }
997
+ </ul>
998
+ }
999
+ </li>
1000
+ </ng-template>
597
1001
  `
598
1002
  }]
599
1003
  }],
@@ -623,6 +1027,14 @@ i0.ɵɵngDeclareClassMetadata({
623
1027
  required: false
624
1028
  }]
625
1029
  }],
1030
+ layout: [{
1031
+ type: i0.Input,
1032
+ args: [{
1033
+ isSignal: true,
1034
+ alias: "layout",
1035
+ required: false
1036
+ }]
1037
+ }],
626
1038
  ariaLabel: [{
627
1039
  type: i0.Input,
628
1040
  args: [{
@@ -647,6 +1059,14 @@ i0.ɵɵngDeclareClassMetadata({
647
1059
  required: false
648
1060
  }]
649
1061
  }],
1062
+ iconTemplate: [{
1063
+ type: i0.Input,
1064
+ args: [{
1065
+ isSignal: true,
1066
+ alias: "iconTemplate",
1067
+ required: false
1068
+ }]
1069
+ }],
650
1070
  emptyText: [{
651
1071
  type: i0.Input,
652
1072
  args: [{
@@ -699,6 +1119,84 @@ i0.ɵɵngDeclareClassMetadata({
699
1119
  }]
700
1120
  }
701
1121
  });
702
- export { SvTreeViewComponent };
1122
+ const SV_TREE_VIEW_LABELS_EN = { treeView: SV_TREE_VIEW_LABELS };
1123
+ const SV_TREE_VIEW_LABELS_DE = { treeView: {
1124
+ expandNode: "{name} aufklappen",
1125
+ collapseNode: "{name} zuklappen",
1126
+ errorTitle: "Diese Baumansicht konnte nicht geladen werden",
1127
+ emptyText: "Keine Elemente vorhanden",
1128
+ orgChart: "Organigramm"
1129
+ } };
1130
+ const SV_TREE_VIEW_LABELS_FR = { treeView: {
1131
+ expandNode: "Développer {name}",
1132
+ collapseNode: "Réduire {name}",
1133
+ errorTitle: "Impossible de charger cette arborescence",
1134
+ emptyText: "Aucun élément à afficher",
1135
+ orgChart: "Organigramme"
1136
+ } };
1137
+ const SV_TREE_VIEW_LABELS_ES = { treeView: {
1138
+ expandNode: "Expandir {name}",
1139
+ collapseNode: "Contraer {name}",
1140
+ errorTitle: "No se pudo cargar este árbol",
1141
+ emptyText: "No hay elementos para mostrar",
1142
+ orgChart: "Organigrama"
1143
+ } };
1144
+ const SV_TREE_VIEW_LABELS_PT_BR = { treeView: {
1145
+ expandNode: "Expandir {name}",
1146
+ collapseNode: "Recolher {name}",
1147
+ errorTitle: "Não foi possível carregar esta árvore",
1148
+ emptyText: "Nenhum item para exibir",
1149
+ orgChart: "Organograma"
1150
+ } };
1151
+ const SV_TREE_VIEW_LABELS_IT = { treeView: {
1152
+ expandNode: "Espandi {name}",
1153
+ collapseNode: "Comprimi {name}",
1154
+ errorTitle: "Impossibile caricare questo albero",
1155
+ emptyText: "Nessun elemento da visualizzare",
1156
+ orgChart: "Organigramma"
1157
+ } };
1158
+ const SV_TREE_VIEW_LABELS_NL = { treeView: {
1159
+ expandNode: "{name} uitvouwen",
1160
+ collapseNode: "{name} samenvouwen",
1161
+ errorTitle: "Kan deze boom niet laden",
1162
+ emptyText: "Geen items om weer te geven",
1163
+ orgChart: "Organogram"
1164
+ } };
1165
+ const SV_TREE_VIEW_LABELS_PL = { treeView: {
1166
+ expandNode: "Rozwiń {name}",
1167
+ collapseNode: "Zwiń {name}",
1168
+ errorTitle: "Nie udało się wczytać tego drzewa",
1169
+ emptyText: "Brak elementów do wyświetlenia",
1170
+ orgChart: "Schemat organizacyjny"
1171
+ } };
1172
+ const SV_TREE_VIEW_LABELS_TR = { treeView: {
1173
+ expandNode: "{name} genişlet",
1174
+ collapseNode: "{name} daralt",
1175
+ errorTitle: "Bu ağaç yüklenemedi",
1176
+ emptyText: "Görüntülenecek öğe yok",
1177
+ orgChart: "Organizasyon şeması"
1178
+ } };
1179
+ const SV_TREE_VIEW_LABELS_JA = { treeView: {
1180
+ expandNode: "{name} を展開",
1181
+ collapseNode: "{name} を折りたたむ",
1182
+ errorTitle: "このツリーを読み込めませんでした",
1183
+ emptyText: "表示する項目はありません",
1184
+ orgChart: "組織図"
1185
+ } };
1186
+ const SV_TREE_VIEW_LABELS_ZH_CN = { treeView: {
1187
+ expandNode: "展开{name}",
1188
+ collapseNode: "折叠{name}",
1189
+ errorTitle: "无法加载此树",
1190
+ emptyText: "没有可显示的项目",
1191
+ orgChart: "组织结构图"
1192
+ } };
1193
+ const SV_TREE_VIEW_LABELS_AR = { treeView: {
1194
+ expandNode: "توسيع {name}",
1195
+ collapseNode: "طي {name}",
1196
+ errorTitle: "تعذّر تحميل هذه الشجرة",
1197
+ emptyText: "لا توجد عناصر لعرضها",
1198
+ orgChart: "الهيكل التنظيمي"
1199
+ } };
1200
+ export { SV_TREE_VIEW_LABELS, SV_TREE_VIEW_LABELS_AR, SV_TREE_VIEW_LABELS_DE, SV_TREE_VIEW_LABELS_EN, SV_TREE_VIEW_LABELS_ES, SV_TREE_VIEW_LABELS_FR, SV_TREE_VIEW_LABELS_IT, SV_TREE_VIEW_LABELS_JA, SV_TREE_VIEW_LABELS_NL, SV_TREE_VIEW_LABELS_PL, SV_TREE_VIEW_LABELS_PT_BR, SV_TREE_VIEW_LABELS_TR, SV_TREE_VIEW_LABELS_ZH_CN, SvTreeViewComponent };
703
1201
 
704
1202
  //# sourceMappingURL=styloviz-tree-view.mjs.map