Mobile et tablette : arborescence en navigation par niveaux
Avant : sur téléphone, toucher un arc ouvrait sa page et refermait le volet ; pour voir chapitres et scènes il fallait viser une flèche de 12 px. - En mode tiroir (< 1024 px), un niveau à la fois : toucher un nœud qui a des enfants entre dedans sans quitter le volet, bouton « retour » vers le niveau parent ; seule une feuille (scène, page…) navigue et ferme le volet. - En-tête de niveau : titre, « Ouvrir la fiche » et actions de création du nœud (« Nouveau chapitre », « Nouvelle scène », « Nouvelle page »…). - Lignes de 48 px minimum, titres sur deux lignes au plus, compteur d'éléments, pastilles de readiness conservées ; glisser-déposer réservé à l'ordinateur ; volet de 400 px sur tablette. - Le volet rouvert montre le niveau de la page courante (élément surligné) ; l'accueil de la section n'est pas pris pour la page courante. - Campagnes et Lore (panneau Templates gardé à la racine). Ordinateur inchangé : arbre classique. Vérifié : web build + 342 vitest (logique de navigation testée), lint sans erreur, e2e 80/80 dont le parcours mobile hub → scène réécrit pour les niveaux, essais au doigt à 375 et 768 px (campagne et Lore). À redéployer : web.
This commit is contained in:
@@ -13,61 +13,122 @@
|
||||
}
|
||||
|
||||
@if (!collapsed) {
|
||||
@if (titleRoute) {
|
||||
<button
|
||||
type="button"
|
||||
class="sidebar-title sidebar-title--link"
|
||||
[class.active]="isTitleActive()"
|
||||
[title]="'secondarySidebar.backToCampaignHome' | translate"
|
||||
(click)="clickTitle()">
|
||||
<lucide-icon [img]="Home" [size]="14" class="sidebar-title-icon"></lucide-icon>
|
||||
<span class="sidebar-title-text">{{ title }}</span>
|
||||
</button>
|
||||
} @else {
|
||||
<h2 class="sidebar-title">{{ title }}</h2>
|
||||
}
|
||||
@if (createActions.length) {
|
||||
<div class="actions-row">
|
||||
@for (action of createActions; track action) {
|
||||
<button
|
||||
class="btn-pill"
|
||||
[class.primary]="action.variant === 'primary'"
|
||||
[class.secondary]="action.variant === 'secondary'"
|
||||
(click)="runAction(action)">
|
||||
{{ action.label }}
|
||||
</button>
|
||||
<!-- Niveau ouvert en mode tiroir : son propre en-tête (retour, titre, actions). -->
|
||||
@if (drawerMode && drillLevel; as level) {
|
||||
<div class="drill-header">
|
||||
<button type="button" class="drill-back" (click)="drillBack()">
|
||||
<lucide-icon [img]="ArrowLeft" [size]="18"></lucide-icon>
|
||||
<span class="drill-back-label">{{ drillBackLabel }}</span>
|
||||
</button>
|
||||
<h2 #drillTitle class="drill-title" tabindex="-1">{{ level.label }}</h2>
|
||||
@if (level.route || level.createActions?.length) {
|
||||
<div class="drill-actions">
|
||||
@if (level.route) {
|
||||
<button type="button" class="drill-action" (click)="openDrillLevel()">
|
||||
<lucide-icon [img]="ExternalLink" [size]="15"></lucide-icon>
|
||||
{{ 'treeDrill.open' | translate }}
|
||||
</button>
|
||||
}
|
||||
@for (a of level.createActions; track a.id) {
|
||||
<button type="button" class="drill-action" (click)="runCreateAction($event, a)">
|
||||
<lucide-icon [img]="iconForAction(a)" [size]="15"></lucide-icon>
|
||||
{{ a.label }}
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
} @else {
|
||||
@if (titleRoute) {
|
||||
<button
|
||||
type="button"
|
||||
class="sidebar-title sidebar-title--link"
|
||||
[class.active]="isTitleActive()"
|
||||
[title]="'secondarySidebar.backToCampaignHome' | translate"
|
||||
(click)="clickTitle()">
|
||||
<lucide-icon [img]="Home" [size]="14" class="sidebar-title-icon"></lucide-icon>
|
||||
<span class="sidebar-title-text">{{ title }}</span>
|
||||
</button>
|
||||
} @else {
|
||||
<h2 class="sidebar-title">{{ title }}</h2>
|
||||
}
|
||||
@if (createActions.length) {
|
||||
<div class="actions-row">
|
||||
@for (action of createActions; track action) {
|
||||
<button
|
||||
class="btn-pill"
|
||||
[class.primary]="action.variant === 'primary'"
|
||||
[class.secondary]="action.variant === 'secondary'"
|
||||
(click)="runAction(action)">
|
||||
{{ action.label }}
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
<!-- cdkDropListGroup : connecte toutes les drop lists de l'arbre (déplacement d'un
|
||||
nœud d'une liste à l'autre). Chaque ligne est un <app-sidebar-tree-node> :
|
||||
comme c'est un VRAI composant déclaré statiquement dans la drop list, son
|
||||
cdkDrag résout sa drop list par DI (impossible via un template outlet-é). -->
|
||||
<div class="tree">
|
||||
<div class="tree-list" cdkDropList
|
||||
id="sidebar-root"
|
||||
[cdkDropListData]="rootDragData"
|
||||
[cdkDropListConnectedTo]="dropListIds"
|
||||
[cdkDropListDisabled]="!dndEnabled()"
|
||||
[cdkDropListEnterPredicate]="rootEnterPredicate"
|
||||
(cdkDropListDropped)="onDrop(null, $event)">
|
||||
@for (item of items; track item.id; let first = $first) {
|
||||
<!-- En-tête de section RENDU HORS du nœud (sinon il serait emporté par le
|
||||
drag du premier item). C'est un élément non-déplaçable de la drop list. -->
|
||||
@if (item.sectionHeaderBefore) {
|
||||
@if (drawerMode) {
|
||||
<nav class="drill-list" [attr.aria-label]="drillLevel?.label || title">
|
||||
@for (item of drillRows; track item.id; let first = $first) {
|
||||
@if (!drillLevel && item.sectionHeaderBefore) {
|
||||
<div class="tree-section-header" [class.first]="first">{{ item.sectionHeaderBefore }}</div>
|
||||
}
|
||||
@if (dndEnabled() && item.dragKind) {
|
||||
<app-sidebar-tree-node cdkDrag [cdkDragData]="item" cdkDragLockAxis="y"
|
||||
[item]="item" [level]="0"></app-sidebar-tree-node>
|
||||
} @else {
|
||||
<app-sidebar-tree-node [item]="item" [level]="0"></app-sidebar-tree-node>
|
||||
}
|
||||
<button type="button" class="drill-row"
|
||||
[class.active]="isActive(item)"
|
||||
[class.action]="item.isAction"
|
||||
[attr.aria-current]="isActive(item) ? 'page' : null"
|
||||
(click)="tapDrillRow(item)">
|
||||
@if (iconFor(item); as icon) {
|
||||
<lucide-icon [img]="icon" [size]="17" class="drill-icon"></lucide-icon>
|
||||
}
|
||||
@if (item.statusDot) {
|
||||
<span class="status-dot"
|
||||
[class.blocking]="item.statusDot === 'blocking'"
|
||||
[class.recommended]="item.statusDot === 'recommended'"
|
||||
[title]="item.statusDotTitle || (('readiness.dot.' + item.statusDot) | translate)"></span>
|
||||
}
|
||||
<span class="drill-label">{{ item.label }}</span>
|
||||
@if (!item.isAction && drillCount(item); as count) {
|
||||
<span class="drill-count">{{ count }}</span>
|
||||
}
|
||||
@if (canDrill(item)) {
|
||||
<lucide-icon [img]="ChevronRight" [size]="18" class="drill-chevron"></lucide-icon>
|
||||
}
|
||||
</button>
|
||||
} @empty {
|
||||
<p class="drill-empty">{{ 'treeDrill.empty' | translate }}</p>
|
||||
}
|
||||
</nav>
|
||||
} @else {
|
||||
<div class="tree">
|
||||
<div class="tree-list" cdkDropList
|
||||
id="sidebar-root"
|
||||
[cdkDropListData]="rootDragData"
|
||||
[cdkDropListConnectedTo]="dropListIds"
|
||||
[cdkDropListDisabled]="!dndEnabled()"
|
||||
[cdkDropListEnterPredicate]="rootEnterPredicate"
|
||||
(cdkDropListDropped)="onDrop(null, $event)">
|
||||
@for (item of items; track item.id; let first = $first) {
|
||||
<!-- En-tête de section RENDU HORS du nœud (sinon il serait emporté par le
|
||||
drag du premier item). C'est un élément non-déplaçable de la drop list. -->
|
||||
@if (item.sectionHeaderBefore) {
|
||||
<div class="tree-section-header" [class.first]="first">{{ item.sectionHeaderBefore }}</div>
|
||||
}
|
||||
@if (dndEnabled() && item.dragKind) {
|
||||
<app-sidebar-tree-node cdkDrag [cdkDragData]="item" cdkDragLockAxis="y"
|
||||
[item]="item" [level]="0"></app-sidebar-tree-node>
|
||||
} @else {
|
||||
<app-sidebar-tree-node [item]="item" [level]="0"></app-sidebar-tree-node>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Panneau bas (ex: Templates) ------------------------------------ -->
|
||||
@if (bottomPanel) {
|
||||
}
|
||||
<!-- Panneau bas (ex: Templates) : à la racine seulement en mode tiroir. -->
|
||||
@if (bottomPanel && !(drawerMode && drillLevel)) {
|
||||
<section class="bottom-panel">
|
||||
<div class="panel-header-row">
|
||||
<button class="panel-header" (click)="togglePanel()">
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
|
||||
// Tiroir (shell < 1024 px) : largeur confortable au doigt, plafonnée par l'écran.
|
||||
&.drawer {
|
||||
width: min(320px, 88vw);
|
||||
// Téléphone : presque tout l'écran ; tablette : assez large pour des titres sur une ligne.
|
||||
width: min(400px, 88vw);
|
||||
padding: 1rem 0.75rem;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
&.collapsed {
|
||||
@@ -264,3 +266,143 @@
|
||||
.panel-header-action { width: 36px; height: 36px; }
|
||||
.panel-header, .panel-item { min-height: 40px; }
|
||||
}
|
||||
|
||||
// --- Navigation par niveaux (mode tiroir) ------------------------------------------------
|
||||
.drill-header {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
padding-bottom: 0.75rem;
|
||||
border-bottom: 1px solid #1e1e3a;
|
||||
}
|
||||
|
||||
.drill-back {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
align-self: flex-start;
|
||||
max-width: 100%;
|
||||
min-height: 44px;
|
||||
padding: 0 0.6rem 0 0.25rem;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
background: transparent;
|
||||
color: #a5b4fc;
|
||||
font-size: 0.92rem;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover { background: rgba(138, 123, 200, 0.12); }
|
||||
&:focus-visible { outline: 2px solid #6c63ff; }
|
||||
}
|
||||
|
||||
.drill-back-label {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.drill-title {
|
||||
margin: 0;
|
||||
padding: 0 0.25rem;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 700;
|
||||
line-height: 1.3;
|
||||
color: white;
|
||||
overflow-wrap: anywhere;
|
||||
|
||||
&:focus { outline: none; }
|
||||
}
|
||||
|
||||
.drill-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.drill-action {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
min-height: 44px;
|
||||
padding: 0 0.85rem;
|
||||
border: 1px solid #2a2a45;
|
||||
border-radius: 8px;
|
||||
background: #161628;
|
||||
color: #e5e7eb;
|
||||
font-size: 0.88rem;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover { border-color: #6c63ff; }
|
||||
&:focus-visible { outline: 2px solid #6c63ff; outline-offset: 2px; }
|
||||
}
|
||||
|
||||
.drill-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.drill-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
width: 100%;
|
||||
min-height: 48px;
|
||||
padding: 0.55rem 0.5rem;
|
||||
border: none;
|
||||
border-bottom: 1px solid rgba(30, 30, 58, 0.8);
|
||||
border-radius: 0;
|
||||
background: transparent;
|
||||
color: #e5e7eb;
|
||||
font-size: 0.95rem;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover { background: rgba(138, 123, 200, 0.08); }
|
||||
&:focus-visible { outline: 2px solid #6c63ff; outline-offset: -2px; }
|
||||
&.active { background: rgba(108, 99, 255, 0.16); color: white; }
|
||||
&.action { color: #a5b4fc; }
|
||||
|
||||
.status-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
|
||||
&.blocking { background: #ef4444; }
|
||||
&.recommended { background: #fb923c; }
|
||||
}
|
||||
}
|
||||
|
||||
.drill-icon { flex-shrink: 0; color: #9ca3af; }
|
||||
|
||||
// Titres longs : deux lignes au plus, puis points de suspension.
|
||||
.drill-label {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.drill-count {
|
||||
flex-shrink: 0;
|
||||
min-width: 1.6rem;
|
||||
padding: 0.1rem 0.45rem;
|
||||
border-radius: 999px;
|
||||
background: #1f2937;
|
||||
color: #9ca3af;
|
||||
font-size: 0.75rem;
|
||||
text-align: center;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.drill-chevron { flex-shrink: 0; color: #6b7280; }
|
||||
|
||||
.drill-empty {
|
||||
margin: 1rem 0.5rem;
|
||||
color: #6b7280;
|
||||
font-size: 0.88rem;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { Component, Input, Output, EventEmitter, HostListener, OnDestroy, ElementRef, forwardRef } from '@angular/core';
|
||||
import { Component, Input, Output, EventEmitter, HostListener, OnDestroy, ElementRef, ViewChild, forwardRef } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Router } from '@angular/router';
|
||||
import { NavigationEnd, Router } from '@angular/router';
|
||||
import { Subscription, filter } from 'rxjs';
|
||||
import { TranslatePipe } from '@ngx-translate/core';
|
||||
import { CdkDropList, CdkDrag, CdkDragDrop, moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop';
|
||||
import { LucideAngularModule, ChevronRight, ChevronDown, PanelLeftClose, PanelLeftOpen, Plus, FolderPlus, FilePlus, Home, LucideIconData } from 'lucide-angular';
|
||||
import { LucideAngularModule, ChevronRight, ChevronDown, PanelLeftClose, PanelLeftOpen, Plus, FolderPlus, FilePlus, Home, ArrowLeft, ExternalLink, LucideIconData } from 'lucide-angular';
|
||||
import { TreeItem, TreeCreateAction, SidebarAction, BottomPanel, BottomPanelItem, LayoutService, ReorderKind, SidebarReorderContext } from '../../services/layout.service';
|
||||
import { SidebarReorderService } from '../../services/sidebar-reorder.service';
|
||||
import { SidebarTreeNodeComponent } from './sidebar-tree-node.component';
|
||||
import { resolveIcon } from '../../lore/lore-icons';
|
||||
import { countLabel, hasChildren as nodeHasChildren, resolveStack, stackForActive } from './tree-drilldown';
|
||||
|
||||
@Component({
|
||||
selector: 'app-secondary-sidebar',
|
||||
@@ -29,7 +31,21 @@ export class SecondarySidebarComponent implements OnDestroy {
|
||||
* Mode tiroir (shell < 1024 px) : largeur fixée par le CSS, pas de repli 44 px
|
||||
* ni de poignée de redimensionnement — le tiroir se ferme depuis la barre haute.
|
||||
*/
|
||||
@Input() drawerMode = false;
|
||||
@Input() set drawerMode(value: boolean) {
|
||||
this._drawerMode = value;
|
||||
if (value) this.syncDrillToActive();
|
||||
}
|
||||
get drawerMode(): boolean { return this._drawerMode; }
|
||||
private _drawerMode = false;
|
||||
|
||||
// --- Navigation par niveaux (mode tiroir : téléphone, tablette) ---------------------
|
||||
// Un niveau à la fois au lieu de l'arbre indenté : toucher un nœud qui a des enfants
|
||||
// « entre » dedans (sans naviguer ni fermer le tiroir), « retour » remonte. Seule une
|
||||
// feuille (scène, page…) navigue — le tiroir se ferme alors au changement de route.
|
||||
/** Pile des nœuds ouverts, de la racine vers le niveau affiché. */
|
||||
drill: TreeItem[] = [];
|
||||
@ViewChild('drillTitle') private drillTitle?: ElementRef<HTMLElement>;
|
||||
private routerSub?: Subscription;
|
||||
@Output() collapsedChange = new EventEmitter<boolean>();
|
||||
|
||||
/** true = ouvert (on affiche les items) ; false = replié (titre seul). */
|
||||
@@ -43,6 +59,8 @@ export class SecondarySidebarComponent implements OnDestroy {
|
||||
readonly FolderPlus = FolderPlus;
|
||||
readonly FilePlus = FilePlus;
|
||||
readonly Home = Home;
|
||||
readonly ArrowLeft = ArrowLeft;
|
||||
readonly ExternalLink = ExternalLink;
|
||||
|
||||
isCollapsed = false;
|
||||
|
||||
@@ -79,6 +97,10 @@ export class SecondarySidebarComponent implements OnDestroy {
|
||||
this._items = value ?? [];
|
||||
this._buildDragMaps();
|
||||
this.autoExpandActiveAncestors();
|
||||
// Arbre reconstruit (même ids, nouveaux objets) : on garde le niveau où l'on était.
|
||||
this.drill = this.drill.length
|
||||
? resolveStack(this._items, this.drill.map(n => n.id))
|
||||
: resolveStack(this._items, stackForActive(this._items, i => this.isDrillActive(i)));
|
||||
}
|
||||
get items(): TreeItem[] { return this._items; }
|
||||
|
||||
@@ -94,6 +116,10 @@ export class SecondarySidebarComponent implements OnDestroy {
|
||||
private elementRef: ElementRef<HTMLElement>,
|
||||
private reorderService: SidebarReorderService
|
||||
) {
|
||||
// Après chaque navigation, le tiroir rouvert montre le niveau de la page courante.
|
||||
this.routerSub = this.router.events
|
||||
.pipe(filter(e => e instanceof NavigationEnd))
|
||||
.subscribe(() => { if (this._drawerMode) this.syncDrillToActive(); });
|
||||
try {
|
||||
const stored = localStorage.getItem(SecondarySidebarComponent.WIDTH_STORAGE_KEY);
|
||||
const parsed = stored ? parseInt(stored, 10) : NaN;
|
||||
@@ -142,6 +168,7 @@ export class SecondarySidebarComponent implements OnDestroy {
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.routerSub?.unsubscribe();
|
||||
// Sécurité : si le composant est détruit en plein drag, on restaure le curseur global.
|
||||
if (this.isResizing) {
|
||||
document.body.style.userSelect = '';
|
||||
@@ -149,6 +176,68 @@ export class SecondarySidebarComponent implements OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
/** Niveau affiché : le dernier nœud ouvert, ou null à la racine. */
|
||||
get drillLevel(): TreeItem | null {
|
||||
return this.drill.length ? this.drill[this.drill.length - 1] : null;
|
||||
}
|
||||
|
||||
/** Lignes du niveau affiché. */
|
||||
get drillRows(): TreeItem[] {
|
||||
return this.drillLevel ? this.drillLevel.children ?? [] : this._items;
|
||||
}
|
||||
|
||||
/** Libellé du bouton retour : le niveau parent, ou le titre de la section. */
|
||||
get drillBackLabel(): string {
|
||||
return this.drill.length > 1 ? this.drill[this.drill.length - 2].label : this.title;
|
||||
}
|
||||
|
||||
drillCount(item: TreeItem): string | null {
|
||||
return countLabel(item);
|
||||
}
|
||||
|
||||
canDrill(item: TreeItem): boolean {
|
||||
return !item.isAction && nodeHasChildren(item);
|
||||
}
|
||||
|
||||
/** Toucher une ligne : entrer si elle a des enfants, sinon ouvrir sa page. */
|
||||
tapDrillRow(item: TreeItem): void {
|
||||
if (this.canDrill(item)) {
|
||||
this.drill = [...this.drill, item];
|
||||
this.focusDrillTitle();
|
||||
} else if (item.route) {
|
||||
this.router.navigate([item.route]);
|
||||
}
|
||||
}
|
||||
|
||||
drillBack(): void {
|
||||
this.drill = this.drill.slice(0, -1);
|
||||
this.focusDrillTitle();
|
||||
}
|
||||
|
||||
/** « Ouvrir la fiche » du niveau affiché (arc, chapitre, dossier…). */
|
||||
openDrillLevel(): void {
|
||||
const route = this.drillLevel?.route;
|
||||
if (route) this.router.navigate([route]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Page courante pour le choix du niveau. L'accueil de la section (route du titre) ne
|
||||
* compte pas : un nœud qui y pointe (ex. « Parties » → hub) ouvrirait sinon le tiroir
|
||||
* dans ce nœud au lieu de la racine.
|
||||
*/
|
||||
private isDrillActive(item: TreeItem): boolean {
|
||||
return item.route !== this.titleRoute && this.isActive(item);
|
||||
}
|
||||
|
||||
private syncDrillToActive(): void {
|
||||
this.drill = resolveStack(this._items, stackForActive(this._items, i => this.isDrillActive(i)));
|
||||
}
|
||||
|
||||
/** Lecteurs d'écran / clavier : le focus suit le changement de niveau. */
|
||||
private focusDrillTitle(): void {
|
||||
setTimeout(() => this.drillTitle?.nativeElement.focus());
|
||||
}
|
||||
|
||||
runAction(action: SidebarAction): void {
|
||||
if (action.route) { this.router.navigate([action.route]); }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import { TreeItem } from '../../services/layout.service';
|
||||
import { countLabel, findPath, resolveStack, stackForActive } from './tree-drilldown';
|
||||
|
||||
const scene = (id: string): TreeItem => ({ id, label: id, route: `/s/${id}` });
|
||||
const tree = (): TreeItem[] => [
|
||||
{ id: 'parties', label: 'Parties', children: [scene('p1')] },
|
||||
{
|
||||
id: 'arc1', label: 'Acte I', route: '/arc1', children: [
|
||||
{ id: 'ch1', label: 'Chapitre 1', route: '/ch1', children: [scene('s1'), scene('s2')] },
|
||||
{ id: 'ch2', label: 'Chapitre 2', route: '/ch2' }
|
||||
]
|
||||
},
|
||||
{ id: 'npcs', label: 'PNJ', meta: '3', children: [{ id: 'new', label: '+ PNJ', isAction: true, route: '/new' }] },
|
||||
{ id: 'tables', label: 'Tables', route: '/tables' }
|
||||
];
|
||||
|
||||
describe('tree drill-down', () => {
|
||||
it('finds the path from the root to a node', () => {
|
||||
expect(findPath(tree(), 's2')?.map(n => n.id)).toEqual(['arc1', 'ch1', 's2']);
|
||||
expect(findPath(tree(), 'nope')).toBeNull();
|
||||
});
|
||||
|
||||
it('resolves a stack of ids against a rebuilt tree, stopping at what disappeared', () => {
|
||||
expect(resolveStack(tree(), ['arc1', 'ch1']).map(n => n.id)).toEqual(['arc1', 'ch1']);
|
||||
expect(resolveStack(tree(), ['arc1', 'gone', 'x']).map(n => n.id)).toEqual(['arc1']);
|
||||
// ch2 n'a pas d'enfants : on ne peut pas « entrer » dedans.
|
||||
expect(resolveStack(tree(), ['arc1', 'ch2']).map(n => n.id)).toEqual(['arc1']);
|
||||
});
|
||||
|
||||
it('opens the level of the current page', () => {
|
||||
// Sur une scène : on voit ses sœurs (le chapitre).
|
||||
expect(stackForActive(tree(), i => i.id === 's2')).toEqual(['arc1', 'ch1']);
|
||||
// Sur un arc : on voit son contenu.
|
||||
expect(stackForActive(tree(), i => i.id === 'arc1')).toEqual(['arc1']);
|
||||
// Sur une feuille racine, ou nulle part : la racine.
|
||||
expect(stackForActive(tree(), i => i.id === 'tables')).toEqual([]);
|
||||
expect(stackForActive(tree(), () => false)).toEqual([]);
|
||||
});
|
||||
|
||||
it('prefers the deepest active node', () => {
|
||||
expect(stackForActive(tree(), i => i.id === 'arc1' || i.id === 'ch1')).toEqual(['arc1', 'ch1']);
|
||||
});
|
||||
|
||||
it('shows the given badge, else the number of real children', () => {
|
||||
const [parties, arc1, npcs, tables] = tree();
|
||||
expect(countLabel(parties)).toBe('1');
|
||||
expect(countLabel(arc1)).toBe('2');
|
||||
expect(countLabel(npcs)).toBe('3');
|
||||
expect(countLabel(tables)).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,68 @@
|
||||
import { TreeItem } from '../../services/layout.service';
|
||||
|
||||
/**
|
||||
* Navigation PAR NIVEAUX dans l'arborescence (mode tiroir : téléphone, tablette).
|
||||
* Au lieu d'un arbre indenté à minuscules chevrons, on affiche un niveau à la fois :
|
||||
* toucher un nœud qui a des enfants « entre » dedans, un bouton retour remonte.
|
||||
* Logique pure, sans Angular (testée en vitest).
|
||||
*/
|
||||
|
||||
/** Chemin racine → nœud (inclus), ou null si l'id n'existe pas. */
|
||||
export function findPath(items: TreeItem[], id: string): TreeItem[] | null {
|
||||
for (const item of items) {
|
||||
if (item.id === id) return [item];
|
||||
const sub = findPath(item.children ?? [], id);
|
||||
if (sub) return [item, ...sub];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ré-résout une pile d'ids après une reconstruction de l'arbre (les objets changent,
|
||||
* les ids restent) : on suit les ids niveau par niveau et on s'arrête au premier
|
||||
* qui a disparu (nœud supprimé, ou plus d'enfants).
|
||||
*/
|
||||
export function resolveStack(items: TreeItem[], ids: string[]): TreeItem[] {
|
||||
const stack: TreeItem[] = [];
|
||||
let level = items;
|
||||
for (const id of ids) {
|
||||
const node = level.find(i => i.id === id);
|
||||
if (!node || !hasChildren(node)) break;
|
||||
stack.push(node);
|
||||
level = node.children ?? [];
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Niveau à afficher pour la page courante : les ancêtres du nœud actif le plus
|
||||
* profond, plus le nœud lui-même s'il a des enfants (sur la page d'un arc, on voit
|
||||
* ses chapitres). Aucun nœud actif → racine.
|
||||
*/
|
||||
export function stackForActive(items: TreeItem[], isActive: (item: TreeItem) => boolean): string[] {
|
||||
const path = deepestActivePath(items, isActive);
|
||||
if (!path) return [];
|
||||
const active = path[path.length - 1];
|
||||
const containers = hasChildren(active) ? path : path.slice(0, -1);
|
||||
return containers.map(n => n.id);
|
||||
}
|
||||
|
||||
function deepestActivePath(items: TreeItem[], isActive: (item: TreeItem) => boolean): TreeItem[] | null {
|
||||
for (const item of items) {
|
||||
const sub = deepestActivePath(item.children ?? [], isActive);
|
||||
if (sub) return [item, ...sub];
|
||||
if (isActive(item)) return [item];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function hasChildren(item: TreeItem): boolean {
|
||||
return !!item.children && item.children.length > 0;
|
||||
}
|
||||
|
||||
/** Compteur affiché à droite d'une ligne : le badge fourni, sinon le nombre d'enfants réels. */
|
||||
export function countLabel(item: TreeItem): string | null {
|
||||
if (item.meta) return item.meta;
|
||||
const n = (item.children ?? []).filter(c => !c.isAction).length;
|
||||
return n > 0 ? String(n) : null;
|
||||
}
|
||||
@@ -2514,5 +2514,9 @@
|
||||
"chooseSystem": "Choose the campaign's system",
|
||||
"noRules": "The \"{{name}}\" system has no rules yet.",
|
||||
"addRules": "Add rules to the system"
|
||||
},
|
||||
"treeDrill": {
|
||||
"open": "Open page",
|
||||
"empty": "Nothing here yet."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2514,5 +2514,9 @@
|
||||
"chooseSystem": "Choisir le système de la campagne",
|
||||
"noRules": "Le système « {{name}} » n'a pas encore de règles.",
|
||||
"addRules": "Ajouter des règles au système"
|
||||
},
|
||||
"treeDrill": {
|
||||
"open": "Ouvrir la fiche",
|
||||
"empty": "Rien ici pour le moment."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"treeDrill": {
|
||||
"open": "Open page",
|
||||
"empty": "Nothing here yet."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"treeDrill": {
|
||||
"open": "Ouvrir la fiche",
|
||||
"empty": "Rien ici pour le moment."
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user