Initial commit - LoreMind project

This commit is contained in:
2026-04-19 12:08:16 +02:00
parent 95928b7165
commit 094c759f2c
213 changed files with 25358 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
<nav class="breadcrumb" aria-label="Fil d'Ariane" *ngIf="items.length">
<ol>
<li *ngFor="let item of items; let last = last; trackBy: trackByIndex"
class="breadcrumb-item"
[class.current]="last">
<a *ngIf="item.route && !last"
[routerLink]="item.route"
class="breadcrumb-link">{{ item.label }}</a>
<span *ngIf="!item.route || last" class="breadcrumb-text">{{ item.label }}</span>
</li>
</ol>
</nav>

View File

@@ -0,0 +1,50 @@
.breadcrumb {
font-size: 0.82rem;
color: #6b7280;
margin-bottom: 1rem;
ol {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.35rem;
list-style: none;
margin: 0;
padding: 0;
}
}
.breadcrumb-item {
display: inline-flex;
align-items: center;
gap: 0.35rem;
&::before {
content: '';
color: #4b5563;
}
&:first-child::before {
content: none;
}
&.current .breadcrumb-text {
color: #e5e7eb;
font-weight: 500;
}
}
.breadcrumb-link {
color: #9ca3af;
text-decoration: none;
transition: color 0.15s;
&:hover {
color: #a5b4fc;
text-decoration: underline;
}
}
.breadcrumb-text {
color: inherit;
}

View File

@@ -0,0 +1,35 @@
import { Component, Input } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterLink } from '@angular/router';
/**
* Un niveau dans le fil d'Ariane.
* Si `route` est défini, l'item est cliquable (navigation).
* Sinon, c'est la position courante (dernier niveau, non-cliquable).
*/
export interface BreadcrumbItem {
label: string;
route?: string | any[];
}
/**
* Composant réutilisable de fil d'Ariane.
* Utilisation type :
* <app-breadcrumb [items]="[
* { label: 'Mon Univers', route: ['/lore', loreId] },
* { label: 'PNJ', route: ['/lore', loreId, 'folders', nodeId, 'edit'] },
* { label: 'Aldric' }
* ]"></app-breadcrumb>
*/
@Component({
selector: 'app-breadcrumb',
standalone: true,
imports: [CommonModule, RouterLink],
templateUrl: './breadcrumb.component.html',
styleUrls: ['./breadcrumb.component.scss']
})
export class BreadcrumbComponent {
@Input() items: BreadcrumbItem[] = [];
trackByIndex = (i: number) => i;
}

View File

@@ -0,0 +1,15 @@
<div class="chips-wrapper">
<span class="chip" *ngFor="let tag of value; let i = index">
{{ tag }}
<button type="button" class="chip-remove" (click)="remove(i)" title="Retirer">
<lucide-icon [img]="X" [size]="12"></lucide-icon>
</button>
</span>
<input
type="text"
class="chip-input"
[placeholder]="placeholder"
[(ngModel)]="current"
(keydown)="onKeyDown($event)"
(blur)="add()" />
</div>

View File

@@ -0,0 +1,53 @@
.chips-wrapper {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.4rem;
padding: 0.55rem 0.65rem;
background: #1a1a2e;
border: 1px solid #2a2a3d;
border-radius: 6px;
&:focus-within {
border-color: #6c63ff;
}
}
.chip {
display: inline-flex;
align-items: center;
gap: 0.3rem;
padding: 0.2rem 0.55rem;
background: #1e1c3a;
color: #a5b4fc;
border-radius: 999px;
font-size: 0.8rem;
line-height: 1.2;
.chip-remove {
display: inline-flex;
align-items: center;
justify-content: center;
background: transparent;
border: none;
color: inherit;
cursor: pointer;
padding: 0;
opacity: 0.7;
&:hover { opacity: 1; color: #fca5a5; }
}
}
.chip-input {
flex: 1;
min-width: 140px;
background: transparent;
border: none;
color: white;
font-size: 0.88rem;
padding: 0.15rem 0;
outline: none;
&::placeholder { color: #6b7280; }
}

View File

@@ -0,0 +1,68 @@
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { LucideAngularModule, X } from 'lucide-angular';
/**
* Composant réutilisable de saisie de chips (étiquettes textuelles).
*
* Usage :
* <app-chips-input
* [value]="tags"
* (valueChange)="tags = $event"
* placeholder="Ajouter un tag..."></app-chips-input>
*
* Règles UX :
* - Entrée valide la saisie en cours
* - Virgule valide aussi (pratique pour enchaîner plusieurs tags)
* - Doublons silencieusement ignorés
* - Espaces en début/fin trimmés
* - Clic sur X retire le chip
*/
@Component({
selector: 'app-chips-input',
standalone: true,
imports: [CommonModule, FormsModule, LucideAngularModule],
templateUrl: './chips-input.component.html',
styleUrls: ['./chips-input.component.scss']
})
export class ChipsInputComponent {
readonly X = X;
@Input() value: string[] = [];
@Input() placeholder = 'Ajouter...';
@Output() valueChange = new EventEmitter<string[]>();
/** Texte de l'input en cours de saisie. */
current = '';
/** Ajoute le texte courant s'il est non vide et non déjà présent. */
add(): void {
const raw = this.current.trim().replace(/,$/, '').trim();
if (!raw) return;
if (this.value.includes(raw)) {
this.current = '';
return;
}
this.valueChange.emit([...this.value, raw]);
this.current = '';
}
/** Retire le chip à l'index donné. */
remove(index: number): void {
const next = [...this.value];
next.splice(index, 1);
this.valueChange.emit(next);
}
/** Gère Enter et virgule comme déclencheurs d'ajout. */
onKeyDown(event: KeyboardEvent): void {
if (event.key === 'Enter' || event.key === ',') {
event.preventDefault();
this.add();
} else if (event.key === 'Backspace' && this.current === '' && this.value.length > 0) {
// Backspace sur input vide retire le dernier chip (UX courante).
this.remove(this.value.length - 1);
}
}
}

View File

@@ -0,0 +1,15 @@
<div class="expandable-section" [class.private]="variant === 'private'">
<button type="button" class="section-header" (click)="toggle()">
<span class="section-title">
<span class="section-icon" *ngIf="icon">{{ icon }}</span>
{{ title }}
</span>
<lucide-icon [img]="isOpen ? ChevronUp : ChevronDown" [size]="16"></lucide-icon>
</button>
<div class="section-content" *ngIf="isOpen">
<ng-content></ng-content>
</div>
</div>

View File

@@ -0,0 +1,49 @@
.expandable-section {
background: #1f2937;
border: 1px solid #374151;
border-radius: 8px;
overflow: hidden;
&.private {
border-color: #7f1d1d;
.section-header { background: rgba(127, 29, 29, 0.12); }
.section-title { color: #fca5a5; }
}
}
.section-header {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0.9rem 1.1rem;
background: transparent;
border: none;
cursor: pointer;
color: #d1d5db;
transition: background 0.15s;
&:hover { background: #374151; }
}
.section-title {
display: inline-flex;
align-items: center;
gap: 0.6rem;
font-size: 0.9rem;
font-weight: 600;
color: #e5e7eb;
}
.section-icon {
font-size: 1rem;
}
.section-content {
padding: 1rem 1.1rem 1.2rem 1.1rem;
border-top: 1px solid #374151;
display: flex;
flex-direction: column;
gap: 1rem;
}

View File

@@ -0,0 +1,39 @@
import { Component, Input } from '@angular/core';
import { CommonModule } from '@angular/common';
import { LucideAngularModule, ChevronDown, ChevronUp } from 'lucide-angular';
/**
* Section repliable avec titre (icône + texte) et contenu projeté via ng-content.
* Utilisé dans les écrans d'édition de Scene pour structurer les champs narratifs.
*
* Usage :
* <app-expandable-section title="Contexte et ambiance" icon="📍" [initiallyOpen]="true">
* <!-- champs de formulaire -->
* </app-expandable-section>
*/
@Component({
selector: 'app-expandable-section',
standalone: true,
imports: [CommonModule, LucideAngularModule],
templateUrl: './expandable-section.component.html',
styleUrls: ['./expandable-section.component.scss']
})
export class ExpandableSectionComponent {
readonly ChevronDown = ChevronDown;
readonly ChevronUp = ChevronUp;
@Input() title = '';
@Input() icon = ''; // Emoji ou caractère unicode (ex: '📍', '📖')
@Input() initiallyOpen = false;
@Input() variant: 'default' | 'private' = 'default'; // 'private' = notes MJ (couleur différente)
isOpen = false;
ngOnInit(): void {
this.isOpen = this.initiallyOpen;
}
toggle(): void {
this.isOpen = !this.isOpen;
}
}

View File

@@ -0,0 +1,51 @@
<div class="gs-overlay" *ngIf="open" (click)="close()">
<div class="gs-modal" (click)="$event.stopPropagation()">
<div class="gs-input-row">
<lucide-icon [img]="Search" [size]="18" class="gs-search-icon"></lucide-icon>
<input
#searchInput
type="text"
class="gs-input"
placeholder="Rechercher dans LoreMind..."
[ngModel]="query"
(ngModelChange)="onQueryChange($event)" />
<span class="gs-kbd">ESC</span>
</div>
<div class="gs-results" *ngIf="results.length > 0">
<button
*ngFor="let r of results; let i = index"
class="gs-result"
[class.active]="i === activeIndex"
(mouseenter)="activeIndex = i"
(click)="select(r)">
<lucide-icon [img]="iconFor(r.kind)" [size]="16" class="gs-result-icon"></lucide-icon>
<div class="gs-result-body">
<div class="gs-result-title">{{ r.title }}</div>
<div class="gs-result-subtitle" *ngIf="r.subtitle">{{ r.subtitle }}</div>
<div class="gs-result-tag">{{ r.tag }}</div>
</div>
</button>
</div>
<div class="gs-empty" *ngIf="!loading && query.trim().length >= 2 && results.length === 0">
Aucun résultat
</div>
<div class="gs-empty" *ngIf="query.trim().length < 2">
Tape au moins 2 caractères
</div>
<div class="gs-footer">
<div class="gs-hints">
<span><kbd></kbd><kbd></kbd> naviguer</span>
<span><kbd></kbd> sélectionner</span>
<span><kbd>ESC</kbd> fermer</span>
</div>
<span class="gs-count" *ngIf="results.length > 0">
{{ results.length }} résultat{{ results.length > 1 ? 's' : '' }}
</span>
</div>
</div>
</div>

View File

@@ -0,0 +1,118 @@
.gs-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.6);
z-index: 1000;
display: flex;
align-items: flex-start;
justify-content: center;
padding-top: 10vh;
}
.gs-modal {
width: min(640px, 92vw);
background: #1f2232;
border: 1px solid #2d3145;
border-radius: 12px;
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
display: flex;
flex-direction: column;
overflow: hidden;
}
.gs-input-row {
display: flex;
align-items: center;
gap: 0.75rem;
padding: 1rem 1.25rem;
border-bottom: 1px solid #2d3145;
}
.gs-search-icon { color: #6b7280; flex-shrink: 0; }
.gs-input {
flex: 1;
background: transparent;
border: none;
outline: none;
color: #e5e7eb;
font-size: 1rem;
&::placeholder { color: #6b7280; }
}
.gs-kbd,
.gs-hints kbd {
background: #2d3145;
color: #9ca3af;
font-size: 0.7rem;
padding: 0.15rem 0.4rem;
border-radius: 4px;
border: 1px solid #3a3f55;
font-family: inherit;
}
.gs-results {
max-height: 50vh;
overflow-y: auto;
}
.gs-result {
display: flex;
align-items: flex-start;
gap: 0.75rem;
padding: 0.75rem 1.25rem;
background: transparent;
border: none;
color: #e5e7eb;
width: 100%;
text-align: left;
cursor: pointer;
&.active { background: rgba(99, 102, 241, 0.18); }
}
.gs-result-icon { color: #9ca3af; margin-top: 2px; flex-shrink: 0; }
.gs-result-body {
flex: 1;
min-width: 0;
}
.gs-result-title { font-weight: 600; color: #e5e7eb; }
.gs-result-subtitle {
color: #9ca3af;
font-size: 0.85rem;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.gs-result-tag {
color: #6b7280;
font-size: 0.75rem;
margin-top: 0.15rem;
}
.gs-empty {
padding: 1.5rem;
text-align: center;
color: #6b7280;
font-size: 0.9rem;
}
.gs-footer {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0.6rem 1.25rem;
border-top: 1px solid #2d3145;
font-size: 0.75rem;
color: #9ca3af;
}
.gs-hints {
display: flex;
gap: 1rem;
span { display: flex; align-items: center; gap: 0.3rem; }
}

View File

@@ -0,0 +1,216 @@
import { Component, ElementRef, HostListener, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { Router } from '@angular/router';
import { BehaviorSubject, Subject, forkJoin, of } from 'rxjs';
import { catchError, debounceTime, distinctUntilChanged, switchMap, takeUntil } from 'rxjs/operators';
import { LucideAngularModule, Search, BookOpen, Folder, Users, FileText, Scroll } from 'lucide-angular';
import { GlobalSearchService } from '../../services/global-search.service';
import { LoreService } from '../../services/lore.service';
import { PageService } from '../../services/page.service';
import { TemplateService } from '../../services/template.service';
import { CampaignService } from '../../services/campaign.service';
type ResultKind = 'lore' | 'node' | 'template' | 'page' | 'campaign';
interface SearchResult {
id: string;
kind: ResultKind;
title: string;
subtitle: string;
/** Tag affiché sous le titre (ex: "Lore", "Dossier", "Template", "Page"). */
tag: string;
/** Route Angular (array pour router.navigate). */
route: any[];
}
/**
* Command palette globale (Ctrl+K / Cmd+K).
* Agrège 4 endpoints search (Lore, LoreNode, Template, Page) côté frontend.
* Navigation clavier : ↑↓ ↵ Esc.
*/
@Component({
selector: 'app-global-search',
standalone: true,
imports: [CommonModule, FormsModule, LucideAngularModule],
templateUrl: './global-search.component.html',
styleUrls: ['./global-search.component.scss']
})
export class GlobalSearchComponent implements OnInit, OnDestroy {
readonly Search = Search;
readonly BookOpen = BookOpen;
readonly Folder = Folder;
readonly Users = Users;
readonly FileText = FileText;
readonly Scroll = Scroll;
@ViewChild('searchInput') searchInput?: ElementRef<HTMLInputElement>;
open = false;
query = '';
loading = false;
results: SearchResult[] = [];
activeIndex = 0;
private readonly queryChanges$ = new BehaviorSubject<string>('');
private readonly destroy$ = new Subject<void>();
constructor(
private globalSearch: GlobalSearchService,
private router: Router,
private loreService: LoreService,
private pageService: PageService,
private templateService: TemplateService,
private campaignService: CampaignService
) {}
ngOnInit(): void {
this.globalSearch.open$.pipe(takeUntil(this.destroy$)).subscribe(open => {
this.open = open;
if (open) {
this.query = '';
this.results = [];
this.activeIndex = 0;
// focus après le tick de rendu (ngIf du template)
setTimeout(() => this.searchInput?.nativeElement.focus(), 0);
}
});
this.queryChanges$.pipe(
debounceTime(200),
distinctUntilChanged(),
switchMap(q => {
const trimmed = q.trim();
if (trimmed.length < 2) {
this.loading = false;
return of<SearchResult[]>([]);
}
this.loading = true;
return forkJoin({
lores: this.loreService.searchLores(trimmed).pipe(catchError(() => of([]))),
nodes: this.loreService.searchLoreNodes(trimmed).pipe(catchError(() => of([]))),
templates: this.templateService.search(trimmed).pipe(catchError(() => of([]))),
pages: this.pageService.search(trimmed).pipe(catchError(() => of([]))),
campaigns: this.campaignService.search(trimmed).pipe(catchError(() => of([])))
}).pipe(
switchMap(({ lores, nodes, templates, pages, campaigns }) => of(this.buildResults(lores, nodes, templates, pages, campaigns))),
catchError(() => of<SearchResult[]>([]))
);
}),
takeUntil(this.destroy$)
).subscribe(results => {
this.results = results;
this.activeIndex = 0;
this.loading = false;
});
}
onQueryChange(value: string): void {
this.query = value;
this.queryChanges$.next(value);
}
/**
* Construit la liste unifiée. Ordre d'affichage : pages d'abord (le plus recherché),
* puis noeuds, templates, campagnes, et lores — les entités racines apparaissent en dernier.
*/
private buildResults(
lores: any[], nodes: any[], templates: any[], pages: any[], campaigns: any[]
): SearchResult[] {
const pageResults: SearchResult[] = pages.map(p => ({
id: p.id,
kind: 'page' as ResultKind,
title: p.title,
subtitle: p.notes ? this.firstLine(p.notes) : '',
tag: 'Page',
route: ['/lore', p.loreId, 'pages', p.id]
}));
const nodeResults: SearchResult[] = nodes.map(n => ({
id: n.id,
kind: 'node' as ResultKind,
title: n.name,
subtitle: '',
tag: 'Dossier',
route: ['/lore', n.loreId, 'folders', n.id, 'edit']
}));
const templateResults: SearchResult[] = templates.map(t => ({
id: t.id,
kind: 'template' as ResultKind,
title: t.name,
subtitle: t.description ?? '',
tag: 'Template',
route: ['/lore', t.loreId, 'templates', t.id]
}));
const loreResults: SearchResult[] = lores.map(l => ({
id: l.id,
kind: 'lore' as ResultKind,
title: l.name,
subtitle: l.description ?? '',
tag: 'Lore',
route: ['/lore', l.id]
}));
const campaignResults: SearchResult[] = campaigns.map(c => ({
id: c.id,
kind: 'campaign' as ResultKind,
title: c.name,
subtitle: c.description ?? '',
tag: 'Campagne',
route: ['/campaigns', c.id]
}));
return [...pageResults, ...nodeResults, ...templateResults, ...campaignResults, ...loreResults];
}
private firstLine(text: string): string {
const line = text.split('\n')[0] ?? '';
return line.length > 120 ? line.slice(0, 117) + '…' : line;
}
select(result: SearchResult): void {
this.router.navigate(result.route);
this.globalSearch.close();
}
close(): void {
this.globalSearch.close();
}
/** Raccourcis clavier globaux — actifs uniquement quand la modale est ouverte. */
@HostListener('document:keydown', ['$event'])
onKeydown(event: KeyboardEvent): void {
if (!this.open) return;
if (event.key === 'Escape') {
event.preventDefault();
this.close();
} else if (event.key === 'ArrowDown') {
event.preventDefault();
if (this.results.length > 0) {
this.activeIndex = (this.activeIndex + 1) % this.results.length;
}
} else if (event.key === 'ArrowUp') {
event.preventDefault();
if (this.results.length > 0) {
this.activeIndex = (this.activeIndex - 1 + this.results.length) % this.results.length;
}
} else if (event.key === 'Enter') {
event.preventDefault();
const r = this.results[this.activeIndex];
if (r) this.select(r);
}
}
iconFor(kind: ResultKind) {
switch (kind) {
case 'lore': return this.BookOpen;
case 'node': return this.Folder;
case 'template': return this.Users;
case 'page': return this.FileText;
case 'campaign': return this.Scroll;
default: return this.FileText;
}
}
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}
}

View File

@@ -0,0 +1,42 @@
<div class="picker">
<!-- Chips des pages déjà liées -->
<div class="linked-chips" *ngIf="linkedPages.length > 0">
<span class="chip" *ngFor="let p of linkedPages">
<a
class="chip-label"
[href]="pageUrl(p.id!)"
target="_blank"
rel="noopener"
title="Ouvrir dans un nouvel onglet">
<lucide-icon [img]="Link2" [size]="12"></lucide-icon>
{{ p.title }}
</a>
<button type="button" class="chip-remove" (click)="remove(p.id!)" title="Retirer le lien">
<lucide-icon [img]="X" [size]="12"></lucide-icon>
</button>
</span>
</div>
<!-- Input + dropdown de suggestions -->
<div class="search-wrapper">
<input
type="text"
class="search-input"
placeholder="Rechercher une page à lier..."
[(ngModel)]="query"
(focus)="dropdownOpen = true"
(blur)="onBlur()" />
<ul class="suggestions" *ngIf="dropdownOpen && suggestions.length > 0">
<li *ngFor="let p of suggestions" (mousedown)="add(p)">
{{ p.title }}
</li>
</ul>
<p class="empty-hint" *ngIf="dropdownOpen && query && suggestions.length === 0">
Aucune page ne correspond
</p>
</div>
</div>

View File

@@ -0,0 +1,114 @@
.picker {
display: flex;
flex-direction: column;
gap: 0.6rem;
}
.linked-chips {
display: flex;
flex-wrap: wrap;
gap: 0.4rem;
}
.chip {
display: inline-flex;
align-items: center;
background: #1e1c3a;
color: #a5b4fc;
border-radius: 999px;
font-size: 0.82rem;
overflow: hidden;
.chip-label {
display: inline-flex;
align-items: center;
gap: 0.35rem;
padding: 0.25rem 0.6rem;
background: transparent;
border: none;
color: inherit;
cursor: pointer;
text-decoration: none;
&:hover { color: #c7d2fe; }
}
.chip-remove {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0.25rem 0.5rem;
background: transparent;
border: none;
border-left: 1px solid #2a2a3d;
color: inherit;
cursor: pointer;
opacity: 0.7;
&:hover { opacity: 1; color: #fca5a5; background: #2a2a3d; }
}
}
.search-wrapper {
position: relative;
}
.search-input {
width: 100%;
box-sizing: border-box;
background: #1a1a2e;
border: 1px solid #2a2a3d;
color: white;
padding: 0.65rem 0.9rem;
border-radius: 6px;
font-size: 0.88rem;
&:focus {
outline: none;
border-color: #6c63ff;
}
&::placeholder { color: #6b7280; }
}
.suggestions {
position: absolute;
top: calc(100% + 4px);
left: 0;
right: 0;
list-style: none;
padding: 0.25rem 0;
margin: 0;
background: #1a1a2e;
border: 1px solid #2a2a3d;
border-radius: 6px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
max-height: 280px;
overflow-y: auto;
z-index: 10;
li {
padding: 0.55rem 0.9rem;
color: #d1d5db;
font-size: 0.88rem;
cursor: pointer;
&:hover { background: #20203a; color: white; }
}
}
.empty-hint {
position: absolute;
top: calc(100% + 4px);
left: 0;
right: 0;
padding: 0.55rem 0.9rem;
margin: 0;
background: #1a1a2e;
border: 1px solid #2a2a3d;
border-radius: 6px;
color: #6b7280;
font-size: 0.82rem;
font-style: italic;
z-index: 10;
}

View File

@@ -0,0 +1,96 @@
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { LucideAngularModule, X, Link2 } from 'lucide-angular';
import { Page } from '../../services/page.model';
/**
* Composant pour lier une entité (Page, Arc, Chapter, Scene...) à un ensemble
* de Pages du Lore par leurs IDs.
*
* Prévu pour être réutilisé en Phase cross-context Campagne↔Lore (sous-tâche 4) :
* un Arc/Chapter/Scene pourra pointer vers des Pages du Lore via ce même picker.
*
* Usage :
* <app-lore-link-picker
* [value]="relatedPageIds"
* [availablePages]="allPages"
* [excludePageId]="currentPageId"
* [loreId]="loreId"
* (valueChange)="relatedPageIds = $event"></app-lore-link-picker>
*
* Design :
* - Liste des pages liées = chips cliquables (clic → navigation vers la page)
* - Input de recherche avec dropdown de suggestions filtrées (max 8 résultats)
* - Exclut la page courante et les pages déjà sélectionnées
*/
@Component({
selector: 'app-lore-link-picker',
standalone: true,
imports: [CommonModule, FormsModule, LucideAngularModule],
templateUrl: './lore-link-picker.component.html',
styleUrls: ['./lore-link-picker.component.scss']
})
export class LoreLinkPickerComponent {
readonly X = X;
readonly Link2 = Link2;
/** IDs des pages actuellement liées (contrôlées par le parent). */
@Input() value: string[] = [];
/** Référentiel de pages dans lequel on peut piocher. */
@Input() availablePages: Page[] = [];
/** ID de la page courante (exclue des suggestions) — optionnel. */
@Input() excludePageId: string | null = null;
/** ID du lore courant, utilisé pour construire les URLs des chips cliquables. */
@Input() loreId = '';
@Output() valueChange = new EventEmitter<string[]>();
/** Texte de recherche courant. */
query = '';
/** true tant que l'input a le focus (pour afficher le dropdown). */
dropdownOpen = false;
/** Pages actuellement liées (résolues en objets complets pour affichage). */
get linkedPages(): Page[] {
return this.value
.map(id => this.availablePages.find(p => p.id === id))
.filter((p): p is Page => !!p);
}
/** Pages proposables dans le dropdown — filtrées par query, exclut current + déjà liées. */
get suggestions(): Page[] {
const q = this.query.trim().toLowerCase();
return this.availablePages
.filter(p => p.id !== this.excludePageId)
.filter(p => !this.value.includes(p.id!))
.filter(p => q === '' || p.title.toLowerCase().includes(q))
.slice(0, 8);
}
/** Ajoute une page aux liens. */
add(page: Page): void {
if (!page.id || this.value.includes(page.id)) return;
this.valueChange.emit([...this.value, page.id]);
this.query = '';
}
/** Retire une page des liens. */
remove(pageId: string): void {
this.valueChange.emit(this.value.filter(id => id !== pageId));
}
/**
* URL vers la page liée — utilisée par un <a target="_blank"> dans le template.
* Ouverture en nouvel onglet : on consulte la fiche d'un PNJ/lieu sans perdre
* le contexte de la page/scène en cours d'édition.
*/
pageUrl(pageId: string): string {
return `/lore/${this.loreId}/pages/${pageId}`;
}
/** Retarde la fermeture du dropdown pour laisser le temps au clic de se propager. */
onBlur(): void {
setTimeout(() => { this.dropdownOpen = false; }, 150);
}
}

View File

@@ -0,0 +1,82 @@
<aside class="secondary-sidebar" [class.collapsed]="isCollapsed">
<div class="collapse-toggle" (click)="toggleCollapse()">
<lucide-icon [img]="isCollapsed ? PanelLeftOpen : PanelLeftClose" [size]="16"></lucide-icon>
</div>
<ng-container *ngIf="!isCollapsed">
<h2 class="sidebar-title">{{ title }}</h2>
<div class="actions-row" *ngIf="createActions.length">
<button
*ngFor="let action of createActions"
class="btn-pill"
[class.primary]="action.variant === 'primary'"
[class.secondary]="action.variant === 'secondary'"
(click)="runAction(action)">
{{ action.label }}
</button>
</div>
<div class="tree">
<ng-container *ngFor="let item of items">
<ng-container *ngTemplateOutlet="treeNode; context: { $implicit: item, level: 0 }"></ng-container>
</ng-container>
</div>
<!-- Template récursif : un noeud d'arbre rend son bouton, puis ses enfants via ce même template -->
<ng-template #treeNode let-item let-level="level">
<div class="tree-item" [style.padding-left.px]="level * 12">
<button class="tree-btn" [class.action]="item.isAction" (click)="clickItem(item)">
<span
*ngIf="!item.isAction && item.children?.length"
class="chevron-zone"
(click)="clickChevron($event, item)">
<lucide-icon
[img]="isExpanded(item.id) ? ChevronDown : ChevronRight"
[size]="12">
</lucide-icon>
</span>
<lucide-icon
*ngIf="iconFor(item) as icon"
[img]="icon"
[size]="14"
class="item-icon">
</lucide-icon>
{{ item.label }}
<span class="tree-item-meta" *ngIf="!item.isAction && item.meta">{{ item.meta }}</span>
</button>
<div class="tree-children" *ngIf="isExpanded(item.id) && item.children?.length">
<ng-container *ngFor="let child of item.children">
<ng-container *ngTemplateOutlet="treeNode; context: { $implicit: child, level: level + 1 }"></ng-container>
</ng-container>
</div>
</div>
</ng-template>
<!-- Panneau bas (ex: Templates) ------------------------------------ -->
<section class="bottom-panel" *ngIf="bottomPanel">
<button class="panel-header" (click)="togglePanel()">
<span class="panel-title">{{ bottomPanel.title }}</span>
<lucide-icon
[img]="panelOpen ? ChevronDown : ChevronRight"
[size]="14">
</lucide-icon>
</button>
<ul class="panel-list" *ngIf="panelOpen">
<li *ngFor="let item of bottomPanel.items">
<button
class="panel-item"
[class.action]="item.isAction"
(click)="clickPanelItem(item)">
<span class="panel-item-label">{{ item.label }}</span>
<span class="panel-item-meta" *ngIf="item.meta">{{ item.meta }}</span>
</button>
</li>
</ul>
</section>
</ng-container>
</aside>

View File

@@ -0,0 +1,217 @@
.secondary-sidebar {
width: 220px;
height: 100vh;
background: #0d0d1f;
border-right: 1px solid #1e1e3a;
display: flex;
flex-direction: column;
padding: 1.25rem 0.75rem;
gap: 0.75rem;
overflow-y: auto;
transition: width 0.25s ease;
&.collapsed {
width: 44px;
padding: 1.25rem 0.5rem;
overflow: hidden;
}
}
.collapse-toggle {
display: flex;
align-items: center;
justify-content: center;
width: 28px;
height: 28px;
border-radius: 6px;
cursor: pointer;
color: #6b7280;
transition: color 0.2s, background 0.2s;
flex-shrink: 0;
&:hover { color: white; background: #1f2937; }
}
.btn-back {
display: flex;
align-items: center;
gap: 0.4rem;
background: transparent;
border: none;
color: #6b7280;
font-size: 0.8rem;
cursor: pointer;
padding: 0.25rem 0.5rem;
border-radius: 6px;
transition: color 0.2s;
width: fit-content;
&:hover { color: white; }
}
.sidebar-title {
font-size: 1rem;
font-weight: 700;
color: white;
padding: 0 0.5rem;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.actions-row {
display: flex;
gap: 0.4rem;
}
.btn-pill {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
padding: 0.5rem 0.6rem;
font-size: 0.82rem;
font-weight: 500;
border: none;
border-radius: 6px;
cursor: pointer;
transition: background 0.15s, filter 0.15s;
&.primary { background: #6c63ff; color: white; }
&.primary:hover { background: #5a52e0; }
&.secondary { background: #2a2a3d; color: #d1d5db; }
&.secondary:hover { background: #363650; }
}
.tree {
flex: 1;
display: flex;
flex-direction: column;
gap: 0.15rem;
overflow-y: auto;
padding: 0.25rem 0;
}
.tree-btn {
display: flex;
align-items: center;
gap: 0.5rem;
width: 100%;
background: transparent;
border: none;
color: #d1d5db;
font-size: 0.82rem;
padding: 0.4rem 0.5rem;
border-radius: 6px;
cursor: pointer;
text-align: left;
transition: background 0.15s;
&:hover { background: #1f2937; }
&.action { color: #6b7280; font-style: italic; }
&.action:hover { color: #a5b4fc; background: #1f2937; }
.tree-item-meta {
margin-left: auto;
font-size: 0.72rem;
color: #6b7280;
flex-shrink: 0;
}
}
.item-icon {
display: inline-flex;
align-items: center;
color: #a5b4fc;
flex-shrink: 0;
margin-right: 0.1rem;
}
.chevron-zone {
display: inline-flex;
align-items: center;
justify-content: center;
width: 16px;
height: 16px;
border-radius: 3px;
cursor: pointer;
color: #6b7280;
&:hover { background: #374151; color: white; }
}
.tree-children {
display: flex;
flex-direction: column;
gap: 0.1rem;
}
/* --- Bottom panel (ex: Templates) ------------------------------------- */
.bottom-panel {
border-top: 1px solid #1e1e3a;
padding-top: 0.5rem;
margin-top: auto; /* colle en bas de la sidebar flex */
display: flex;
flex-direction: column;
gap: 0.25rem;
}
.panel-header {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
background: transparent;
border: none;
color: #a5b4fc;
font-size: 0.82rem;
font-weight: 600;
padding: 0.4rem 0.5rem;
border-radius: 6px;
cursor: pointer;
transition: background 0.15s;
&:hover { background: #1f2937; }
.panel-title { letter-spacing: 0.02em; }
}
.panel-list {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
gap: 0.1rem;
}
.panel-item {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
background: transparent;
border: none;
color: #d1d5db;
font-size: 0.82rem;
padding: 0.4rem 0.6rem;
border-radius: 6px;
cursor: pointer;
text-align: left;
transition: background 0.15s;
&:hover { background: #1f2937; }
&.action {
color: #6b7280;
font-style: italic;
}
&.action:hover { color: #a5b4fc; }
.panel-item-meta {
font-size: 0.72rem;
color: #6b7280;
flex-shrink: 0;
}
}

View File

@@ -0,0 +1,115 @@
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Router } from '@angular/router';
import { LucideAngularModule, ChevronRight, ChevronDown, PanelLeftClose, PanelLeftOpen, LucideIconData } from 'lucide-angular';
import { TreeItem, SidebarAction, BottomPanel, BottomPanelItem, LayoutService } from '../../services/layout.service';
import { resolveIcon } from '../../lore/lore-icons';
@Component({
selector: 'app-secondary-sidebar',
standalone: true,
imports: [CommonModule, LucideAngularModule],
templateUrl: './secondary-sidebar.component.html',
styleUrls: ['./secondary-sidebar.component.scss']
})
export class SecondarySidebarComponent {
@Input() title = '';
@Input() createActions: SidebarAction[] = [];
@Input() bottomPanel: BottomPanel | null = null;
@Output() collapsedChange = new EventEmitter<boolean>();
/** true = ouvert (on affiche les items) ; false = replié (titre seul). */
panelOpen = true;
readonly ChevronDown = ChevronDown;
readonly ChevronRight = ChevronRight;
readonly PanelLeftClose = PanelLeftClose;
readonly PanelLeftOpen = PanelLeftOpen;
isCollapsed = false;
private _items: TreeItem[] = [];
@Input() set items(value: TreeItem[]) {
this._items = value ?? [];
this.autoExpandActiveAncestors();
}
get items(): TreeItem[] { return this._items; }
constructor(private router: Router, private layoutService: LayoutService) {}
runAction(action: SidebarAction): void {
if (action.route) { this.router.navigate([action.route]); }
}
clickItem(item: TreeItem): void {
if (item.route) { this.router.navigate([item.route]); return; }
this.toggleItem(item.id);
}
/**
* Clic sur le chevron : toggle uniquement (ne navigue jamais).
* stopPropagation évite que l'event remonte au bouton parent.
*/
clickChevron(event: Event, item: TreeItem): void {
event.stopPropagation();
this.toggleItem(item.id);
}
toggleCollapse(): void {
this.isCollapsed = !this.isCollapsed;
this.collapsedChange.emit(this.isCollapsed);
}
toggleItem(id: string): void {
this.layoutService.toggleExpanded(id);
}
isExpanded(id: string): boolean {
return this.layoutService.isExpanded(id);
}
togglePanel(): void {
this.panelOpen = !this.panelOpen;
}
clickPanelItem(item: BottomPanelItem): void {
if (item.route) { this.router.navigate([item.route]); }
}
/** Résout la clé d'icône d'un TreeItem en icône lucide pour le template. */
iconFor(item: TreeItem): LucideIconData | null {
return item.iconKey ? resolveIcon(item.iconKey) : null;
}
/**
* Auto-déplie la chaîne d'ancêtres du item dont `route` matche l'URL active.
* Nécessaire car la sidebar est détruite/recréée à chaque navigation (ngIf
* dans app.component.html) : sans ça, même si on persiste `expandedItems`
* dans le service, un deep-link sur une page profonde arriverait tout replié.
*/
private autoExpandActiveAncestors(): void {
const url = this.router.url;
// On descend d'abord dans les enfants pour trouver le match le plus profond :
// sinon, un parent qui matche par préfixe (ex. /campaigns/A/arcs/X matche
// aussi /campaigns/A/arcs/X/chapters/M) court-circuiterait la descente et
// on ne déplierait pas l'arc pour montrer le chapitre actif.
const walk = (item: TreeItem, ancestors: string[]): boolean => {
if (item.children) {
const nextAncestors = [...ancestors, item.id];
for (const child of item.children) {
if (walk(child, nextAncestors)) return true;
}
}
const matches = !!item.route && (item.route === url || url.startsWith(item.route + '/'));
if (matches) {
ancestors.forEach(id => this.layoutService.setExpanded(id, true));
return true;
}
return false;
};
for (const root of this._items) {
walk(root, []);
}
}
}