Verkuerze die Inhaltsliste und fuehre Unterkapitel ein, damit Richtung, Bezuge und Struktur ohne Zusatzzeilen bedienbar bleiben.
Deploy Development / deploy (push) Successful in 29s
Test Suite / pytest-backend (push) Successful in 1m24s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 9s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-17 21:13:21 +02:00
1 parent eeeb81148a
commit e4380261fc
30 files changed
+2384 -430

No files matched your search

+89 -23
View File
@@ -1,5 +1,6 @@
import { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import { chapterPathLabel } from "./chapters.js";
import { NavIcon } from "./icons.jsx";
export function useWorkspaceLayout() {
@@ -53,7 +54,7 @@ export function Workspace({ width, structureOpen, setStructureOpen, hasEntry, na
function structureIcon(kind) {
if (kind === "Akte" || kind === "Unterakte") return "folder";
if (kind === "Kapitel") return "chapter";
if (kind === "Kapitel" || kind === "Unterkapitel") return "chapter";
if (kind === "Inhalte") return "contents";
if (kind === "Querverweis" || kind === "Weitere Akte") return "link";
return "layers";
@@ -64,11 +65,18 @@ function branchHasCurrent(node) {
return (node.children || []).some(branchHasCurrent);
}
function TreeRow({ node, onNavigate, ancestor = false }) {
function TreeRow({ node, onNavigate, ancestor = false, toggle = null }) {
const className = node.current ? "nav-tree__link is-current" : ancestor ? "nav-tree__link is-ancestor" : "nav-tree__link";
const icon = <NavIcon name={structureIcon(node.kind)} />;
const label = <span className="nav-tree__title">{node.title}</span>;
const name = `${node.kind}: ${node.title}`;
const name = node.path ? `${node.kind}: ${node.path}` : `${node.kind}: ${node.title}`;
const label = (
<span className="nav-tree__title">
{node.title}
{node.kind === "Kapitel" || node.kind === "Unterkapitel" || node.kind === "Teilvorgang" ? (
<span className="nav-tree__kind">{node.kind}</span>
) : null}
</span>
);
let row;
if (node.onSelect) {
row = (
@@ -92,29 +100,46 @@ function TreeRow({ node, onNavigate, ancestor = false }) {
</span>
);
}
if (node.moveUp === undefined && node.moveDown === undefined) return row;
const moves = node.moveUp !== undefined || node.moveDown !== undefined ? (
<span className="chapter-link__move">
<button type="button" aria-label={`${node.title} nach oben`} disabled={!node.moveUp} onClick={node.moveUp}>↑</button>
<button type="button" aria-label={`${node.title} nach unten`} disabled={!node.moveDown} onClick={node.moveDown}>↓</button>
</span>
) : null;
return (
<div className="nav-tree__line">
{toggle}
{row}
<span className="chapter-link__move">
<button type="button" aria-label={`${node.title} nach oben`} disabled={!node.moveUp} onClick={node.moveUp}>↑</button>
<button type="button" aria-label={`${node.title} nach unten`} disabled={!node.moveDown} onClick={node.moveDown}>↓</button>
</span>
{moves}
</div>
);
}
function TreeNodes({ nodes, onNavigate, unfold = false }) {
function TreeNodes({ nodes, onNavigate, unfold = false, isOpen, onToggle }) {
if (!nodes?.length) return null;
return (
<ul className="nav-tree">
{nodes.map((node) => {
const open = unfold || node.current || branchHasCurrent(node);
const hasChildren = Boolean(node.children?.length);
const open = hasChildren && isOpen(node, unfold);
const toggle = hasChildren ? (
<button
type="button"
className="nav-tree__toggle"
aria-expanded={open}
aria-label={open ? `${node.title} einklappen` : `${node.title} ausklappen`}
onClick={() => onToggle(node, open)}
>
{open ? "▾" : "▸"}
</button>
) : (
<span className="nav-tree__toggle is-empty" aria-hidden="true" />
);
return (
<li key={node.id}>
<TreeRow node={node} onNavigate={onNavigate} ancestor={!node.current && branchHasCurrent(node)} />
{open && node.children?.length ? (
<TreeNodes nodes={node.children} onNavigate={onNavigate} unfold={unfold || node.current} />
<TreeRow node={node} onNavigate={onNavigate} ancestor={!node.current && branchHasCurrent(node)} toggle={toggle} />
{open ? (
<TreeNodes nodes={node.children} onNavigate={onNavigate} unfold={unfold || node.current} isOpen={isOpen} onToggle={onToggle} />
) : null}
</li>
);
@@ -141,19 +166,29 @@ function scopeContents({ chapters, chapterId, allLabel, overview, onChapter, can
current: !chapterId && !overview?.active,
onSelect: () => onChapter?.(""),
});
chapters.forEach((chapter, index) => {
items.push({
const byParent = new Map();
chapters.forEach((chapter) => {
const key = chapter.parent_chapter_id || "";
const list = byParent.get(key) || [];
list.push(chapter);
byParent.set(key, list);
});
function chapterNodes(parentId) {
return (byParent.get(parentId) || []).map((chapter, index, siblings) => ({
id: chapter.id,
title: chapter.title,
kind: "Kapitel",
path: chapterPathLabel(chapters, chapter.id),
kind: parentId ? "Unterkapitel" : "Kapitel",
current: chapterId === chapter.id,
onSelect: () => onChapter?.(chapter.id),
children: chapterNodes(chapter.id),
...(canReorder ? {
moveUp: index > 0 ? () => onMoveChapter(chapter.id, -1) : null,
moveDown: index < chapters.length - 1 ? () => onMoveChapter(chapter.id, 1) : null,
moveDown: index < siblings.length - 1 ? () => onMoveChapter(chapter.id, 1) : null,
} : {}),
});
});
}));
}
items.push(...chapterNodes(""));
return items;
}
@@ -179,6 +214,7 @@ export function StructureNavigator({
overview = null,
onChapter,
onAddChapter,
onAddRootChapter,
canAddChapter = false,
onMoveChapter,
canReorder = false,
@@ -186,7 +222,32 @@ export function StructureNavigator({
onNavigate,
onClose,
}) {
const [opened, setOpened] = useState(() => new Set());
const [closed, setClosed] = useState(() => new Set());
const tree = treeWithScope(nodes, scopeContents({ chapters, chapterId, allLabel, overview, onChapter, canReorder, onMoveChapter }));
function isOpen(node, unfold) {
if (!node.children?.length) return false;
if (closed.has(node.id)) return false;
if (opened.has(node.id) || unfold || node.current || branchHasCurrent(node)) return true;
return false;
}
function toggle(node, currently) {
setOpened((current) => {
const next = new Set(current);
if (currently) next.delete(node.id);
else next.add(node.id);
return next;
});
setClosed((current) => {
const next = new Set(current);
if (currently) next.add(node.id);
else next.delete(node.id);
return next;
});
}
return (
<nav className="structure" aria-label="Struktur">
<div className="structure__bar">
@@ -198,16 +259,21 @@ export function StructureNavigator({
) : null}
</div>
<div className="structure__tree">
<TreeNodes nodes={tree} onNavigate={onNavigate} />
<TreeNodes nodes={tree} onNavigate={onNavigate} isOpen={isOpen} onToggle={toggle} />
{links.length ? (
<div className="structure__links">
<h3>Weitere Zuordnungen</h3>
<TreeNodes nodes={links} onNavigate={onNavigate} unfold />
<TreeNodes nodes={links} onNavigate={onNavigate} unfold isOpen={() => true} onToggle={() => {}} />
</div>
) : null}
{canAddChapter ? (
<button type="button" className="quiet chapter-add" onClick={onAddChapter}>
<NavIcon name="plus" /> Kapitel
<NavIcon name="plus" /> {chapterId ? "Unterkapitel" : "Kapitel"}
</button>
) : null}
{canAddChapter && chapterId && onAddRootChapter ? (
<button type="button" className="quiet chapter-add" onClick={onAddRootChapter}>
<NavIcon name="plus" /> Kapitel auf oberster Ebene
</button>
) : null}
</div>