Verkuerze die Inhaltsliste und fuehre Unterkapitel ein, damit Richtung, Bezuge und Struktur ohne Zusatzzeilen bedienbar bleiben.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
eeeb81148a
commit
e4380261fc
30 files changed
+2384
-430
No files matched your search
@@ -2,13 +2,14 @@ import { useContext, useEffect, useRef, useState } from "react";
|
||||
import { Link, useNavigate, useParams, useSearchParams } from "react-router-dom";
|
||||
import { api, markDirty, textToDocument } from "../api.js";
|
||||
import { SessionContext } from "../session.js";
|
||||
import { chapterPathLabel, siblingChapterIds, trailWithChapter } from "./chapters.js";
|
||||
import { Modal } from "./Modal.jsx";
|
||||
import { MailPicker, PaperlessPicker } from "./Sources.jsx";
|
||||
import { ErrorNote, ShareBox } from "./widgets.jsx";
|
||||
import { ContentBoard, DirectionChoice, MarkdownEditor, ObjectMenu, OrderChoice, RecordTree, SurfaceView, TargetLine, Trail, WorkLists, WorkSwitch, saveChapterOrder, writeSelection } from "./content.jsx";
|
||||
import { ReadingPane } from "./ReadingPane.jsx";
|
||||
import { StructureNavigator, Workspace, rememberScroll, restoreScroll, useWorkspaceLayout } from "./workspace.jsx";
|
||||
import { IconButton, NavIcon } from "./icons.jsx";
|
||||
import { NavIcon } from "./icons.jsx";
|
||||
|
||||
export function CaseList() {
|
||||
const { session } = useContext(SessionContext);
|
||||
@@ -202,8 +203,8 @@ function matterOrigin(group) {
|
||||
}
|
||||
|
||||
function chapterOrigin(base, chapters, chapterId) {
|
||||
const title = (chapters || []).find((chapter) => chapter.id === chapterId)?.title;
|
||||
return title ? `${base} · Kapitel ${title}` : base;
|
||||
const path = chapterPathLabel(chapters, chapterId);
|
||||
return path ? `${base} · ${path}` : base;
|
||||
}
|
||||
|
||||
function mergedCaseItems(record, direction, caseId) {
|
||||
@@ -295,6 +296,7 @@ export function CaseDetail() {
|
||||
const [parentTree, setParentTree] = useState(null);
|
||||
const [error, setError] = useState("");
|
||||
const [modal, setModal] = useState("");
|
||||
const [chapterParentId, setChapterParentId] = useState("");
|
||||
const [view, setView] = useState("contents");
|
||||
const [dateDir, setDateDir] = useState("asc");
|
||||
const { width, structureOpen, setStructureOpen } = useWorkspaceLayout();
|
||||
@@ -434,8 +436,13 @@ export function CaseDetail() {
|
||||
setParams(updated, { replace: true });
|
||||
}
|
||||
|
||||
function openChapter(parentId = "") {
|
||||
setChapterParentId(parentId || "");
|
||||
setModal("chapter");
|
||||
}
|
||||
|
||||
async function moveChapter(chapterIdToMove, delta) {
|
||||
const ids = (record?.chapters || []).map((chapter) => chapter.id);
|
||||
const ids = siblingChapterIds(record?.chapters || [], chapterIdToMove);
|
||||
const index = ids.indexOf(chapterIdToMove);
|
||||
const target = index + delta;
|
||||
if (!record || index < 0 || target < 0 || target >= ids.length) return;
|
||||
@@ -488,7 +495,8 @@ export function CaseDetail() {
|
||||
overview={hasContained ? { active: overview, count: merged.length, onSelect: showOverview } : null}
|
||||
chapterHeading={`Kapitel in ${record.title}`}
|
||||
onChapter={chooseChapter}
|
||||
onAddChapter={canEdit ? () => setModal("chapter") : null}
|
||||
onAddChapter={canEdit ? () => openChapter(chapterId) : null}
|
||||
onAddRootChapter={canEdit ? () => openChapter("") : null}
|
||||
canAddChapter={canEdit}
|
||||
onMoveChapter={moveChapter}
|
||||
canReorder={canEdit && chapters.length > 1}
|
||||
@@ -515,17 +523,10 @@ export function CaseDetail() {
|
||||
>
|
||||
<header className="workspace-head">
|
||||
<div>
|
||||
<Trail items={record.trail} />
|
||||
<Trail items={trailWithChapter(record.trail, record.chapters, overview ? "" : chapterId, `/cases/${id}`)} />
|
||||
<div className="title-row">
|
||||
<h1>{record.title}</h1>
|
||||
<span className={record.status === "open" ? "status-pill" : "status-pill is-closed"}>{record.status === "open" ? "Offen" : "Geschlossen"}</span>
|
||||
{record.rights.edit ? (
|
||||
<span className="record-tools">
|
||||
<IconButton name="pencil" label="Umbenennen" onClick={renameCase} />
|
||||
<IconButton name={record.status === "closed" ? "restore" : "archive"} label={record.status === "closed" ? "Wieder öffnen" : "Archivieren"} onClick={archiveCase} />
|
||||
<IconButton name="trash" label="Löschen" onClick={deleteCase} />
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
<div className="page-actions">
|
||||
@@ -536,6 +537,9 @@ export function CaseDetail() {
|
||||
</button>
|
||||
) : null}
|
||||
<ObjectMenu view={view} onView={setView}>
|
||||
{record.rights.edit ? <button type="button" className="quiet" onClick={renameCase}>Umbenennen</button> : null}
|
||||
{record.rights.edit ? <button type="button" className="quiet" onClick={archiveCase}>{record.status === "closed" ? "Wieder öffnen" : "Archivieren"}</button> : null}
|
||||
{record.rights.edit ? <button type="button" className="danger" onClick={deleteCase}>Löschen</button> : null}
|
||||
{record.rights.edit ? <button type="button" className="quiet" onClick={() => setModal("matter")}>Vorgang anlegen und zuordnen</button> : null}
|
||||
{record.rights.edit ? <button type="button" className="quiet" onClick={() => setModal("assign")}>Vorhandenen Vorgang zuordnen</button> : null}
|
||||
{record.rights.edit ? <button type="button" className="quiet" onClick={() => setModal("subcase")}>Unterakte anlegen</button> : null}
|
||||
@@ -569,7 +573,8 @@ export function CaseDetail() {
|
||||
containerId={id}
|
||||
onlyChapter={chapterId}
|
||||
selectedId={entryId}
|
||||
listTitle={activeChapter ? activeChapter.title : "Direkt in dieser Akte"}
|
||||
listTitle={activeChapter ? chapterPathLabel(record.chapters, activeChapter.id) : "Direkt in dieser Akte"}
|
||||
onAddSubchapter={canEdit ? openChapter : null}
|
||||
context={context}
|
||||
onOpen={openEntry}
|
||||
onChange={load}
|
||||
@@ -611,7 +616,8 @@ export function CaseDetail() {
|
||||
<p className="muted">Dieser Inhalt liegt direkt in der Akte. Er erscheint unter „Direkt in dieser Akte“ und im Überblick, nicht in einem Vorgang.</p>
|
||||
<TargetLine label={targetLabel} chapters={record.chapters} chapterId={activeChapter?.id || ""} />
|
||||
<div className="add-choices">
|
||||
<button type="button" onClick={() => setModal("chapter")}>Kapitel</button>
|
||||
<button type="button" onClick={() => openChapter(activeChapter?.id || "")}>{activeChapter ? "Unterkapitel" : "Kapitel"}</button>
|
||||
{activeChapter ? <button type="button" onClick={() => openChapter("")}>Kapitel auf oberster Ebene</button> : null}
|
||||
<button type="button" onClick={() => setModal("note")}>Notiz</button>
|
||||
<button type="button" onClick={() => setModal("file")}>Datei</button>
|
||||
<button type="button" onClick={() => setModal("paperless")}>Paperless</button>
|
||||
@@ -625,17 +631,19 @@ export function CaseDetail() {
|
||||
<FileForm context={context} chapters={record.chapters} initialChapter={activeChapter?.id || ""} targetLabel={targetLabel} onChange={() => { setModal(""); load(); }} />
|
||||
</Modal>
|
||||
<Modal open={modal === "paperless"} title="Aus Paperless" onClose={() => setModal("")}>
|
||||
<PaperlessPicker context={context} chapterId={activeChapter?.id || ""} chapterTitle={activeChapter?.title || ""} targetLabel={targetLabel} onDone={() => { setModal(""); load(); }} />
|
||||
<PaperlessPicker context={context} chapterId={activeChapter?.id || ""} chapterTitle={activeChapter ? chapterPathLabel(record.chapters, activeChapter.id) : ""} targetLabel={targetLabel} onDone={() => { setModal(""); load(); }} />
|
||||
</Modal>
|
||||
<Modal open={modal === "mail"} title="E-Mail verbinden" wide split onClose={() => setModal("")}>
|
||||
<MailPicker context={context} chapterId={activeChapter?.id || ""} chapterTitle={activeChapter?.title || ""} targetLabel={targetLabel} onDone={() => { setModal(""); load(); }} />
|
||||
<MailPicker context={context} chapterId={activeChapter?.id || ""} chapterTitle={activeChapter ? chapterPathLabel(record.chapters, activeChapter.id) : ""} targetLabel={targetLabel} onDone={() => { setModal(""); load(); }} />
|
||||
</Modal>
|
||||
<Modal open={modal === "subcase"} title="Unterakte anlegen" onClose={() => setModal("")}>
|
||||
<NewSubcase parentId={id} onChange={() => { setModal(""); load(); }} />
|
||||
</Modal>
|
||||
<Modal open={modal === "chapter"} title={`Kapitel in ${targetLabel} hinzufügen`} onClose={() => setModal("")}>
|
||||
<Modal open={modal === "chapter"} title={chapterParentId ? `Unterkapitel in ${targetLabel}` : `Kapitel in ${targetLabel}`} onClose={() => setModal("")}>
|
||||
<ChapterForm
|
||||
path={`/api/v1/cases/${id}/chapters`}
|
||||
targetLabel={targetLabel}
|
||||
parentChapter={chapterParentId ? { id: chapterParentId, title: chapterPathLabel(record.chapters, chapterParentId) } : null}
|
||||
onChange={(created) => {
|
||||
setModal("");
|
||||
if (created?.id) {
|
||||
@@ -802,11 +810,11 @@ function caseTrail(record, caseId, group, scope, chapter) {
|
||||
href: chapter ? `/cases/${caseId}?bereich=${group.matter_id}` : null,
|
||||
});
|
||||
}
|
||||
if (chapter && (group || scope === "direct")) items.push({ label: `Kapitel ${chapter.title}`, href: null });
|
||||
if (chapter && (group || scope === "direct")) items.push({ label: chapter.title, href: null });
|
||||
return items;
|
||||
}
|
||||
|
||||
export function ChapterForm({ path, onChange }) {
|
||||
export function ChapterForm({ path, onChange, targetLabel = "", parentChapter = null }) {
|
||||
const [title, setTitle] = useState("");
|
||||
const [dated, setDated] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
@@ -815,7 +823,14 @@ export function ChapterForm({ path, onChange }) {
|
||||
event.preventDefault();
|
||||
setError("");
|
||||
try {
|
||||
const created = await api(path, { method: "POST", body: { title, ...(dated ? { document_on: dated } : {}) } });
|
||||
const created = await api(path, {
|
||||
method: "POST",
|
||||
body: {
|
||||
title,
|
||||
...(dated ? { document_on: dated } : {}),
|
||||
...(parentChapter?.id ? { parent_chapter_id: parentChapter.id } : {}),
|
||||
},
|
||||
});
|
||||
setTitle("");
|
||||
setDated("");
|
||||
onChange(created);
|
||||
@@ -826,7 +841,11 @@ export function ChapterForm({ path, onChange }) {
|
||||
|
||||
return (
|
||||
<form onSubmit={submit} className="stack compact">
|
||||
<label>Titel <input value={title} onChange={(event) => setTitle(event.target.value)} placeholder="Kapitel" required /></label>
|
||||
{targetLabel ? <p className="target-line">Ziel: <strong>{targetLabel}</strong></p> : null}
|
||||
<p className="target-line">
|
||||
{parentChapter ? <>Elternkapitel: <strong>{parentChapter.title}</strong></> : <>Ebene: <strong>oberste Kapitel</strong></>}
|
||||
</p>
|
||||
<label>Titel <input value={title} onChange={(event) => setTitle(event.target.value)} placeholder={parentChapter ? "Unterkapitel" : "Kapitel"} required /></label>
|
||||
<label>Fachliches Datum, optional <input type="date" value={dated} onChange={(event) => setDated(event.target.value)} /></label>
|
||||
<button type="submit">Hinzufügen</button>
|
||||
<ErrorNote error={error} />
|
||||
@@ -852,7 +871,7 @@ function chapterSelect(chapters, value, setValue) {
|
||||
<select value={value} onChange={(event) => setValue(event.target.value)}>
|
||||
<option value="">Ohne Kapitel</option>
|
||||
{chapters.map((chapter) => (
|
||||
<option key={chapter.id} value={chapter.id}>{chapter.title}</option>
|
||||
<option key={chapter.id} value={chapter.id}>{chapterPathLabel(chapters, chapter.id)}</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
|
||||
@@ -5,11 +5,12 @@ import { SessionContext } from "../session.js";
|
||||
import { Modal } from "./Modal.jsx";
|
||||
import { MailPicker, PaperlessPicker } from "./Sources.jsx";
|
||||
import { ErrorNote, ShareBox } from "./widgets.jsx";
|
||||
import { chapterPathLabel, siblingChapterIds, trailWithChapter } from "./chapters.js";
|
||||
import { ChapterForm, FileForm, NoteForm } from "./Cases.jsx";
|
||||
import { ContentBoard, ObjectMenu, Placements, RecordTree, SurfaceView, TargetLine, Trail, WorkLists, WorkSwitch, matterOpenHref, saveChapterOrder, writeChapter } from "./content.jsx";
|
||||
import { ReadingPane } from "./ReadingPane.jsx";
|
||||
import { StructureNavigator, Workspace, rememberScroll, restoreScroll, useWorkspaceLayout } from "./workspace.jsx";
|
||||
import { IconButton, NavIcon } from "./icons.jsx";
|
||||
import { NavIcon } from "./icons.jsx";
|
||||
import { ExportPackage } from "./ExportPackage.jsx";
|
||||
|
||||
function pageContext(params) {
|
||||
@@ -197,6 +198,7 @@ export function MatterDetail() {
|
||||
const [record, setRecord] = useState(null);
|
||||
const [error, setError] = useState("");
|
||||
const [modal, setModal] = useState("");
|
||||
const [chapterParentId, setChapterParentId] = useState("");
|
||||
const rightsContext = inherited || { kind: "matter", id };
|
||||
const placement = inherited?.kind === "case" ? { kind: "matter", id } : null;
|
||||
const [view, setView] = useState("contents");
|
||||
@@ -367,8 +369,13 @@ export function MatterDetail() {
|
||||
setStructureOpen(false);
|
||||
}
|
||||
|
||||
function openChapter(parentId = "") {
|
||||
setChapterParentId(parentId || "");
|
||||
setModal("chapter");
|
||||
}
|
||||
|
||||
async function moveChapter(chapterIdToMove, delta) {
|
||||
const ids = (record?.chapters || []).map((chapter) => chapter.id);
|
||||
const ids = siblingChapterIds(record?.chapters || [], chapterIdToMove);
|
||||
const index = ids.indexOf(chapterIdToMove);
|
||||
const target = index + delta;
|
||||
if (!record || index < 0 || target < 0 || target >= ids.length) return;
|
||||
@@ -435,7 +442,8 @@ export function MatterDetail() {
|
||||
allCount={(record.bindings || []).length}
|
||||
chapterHeading={`Kapitel in ${record.title}`}
|
||||
onChapter={chooseChapter}
|
||||
onAddChapter={canEdit ? () => setModal("chapter") : null}
|
||||
onAddChapter={canEdit ? () => openChapter(chapterId) : null}
|
||||
onAddRootChapter={canEdit ? () => openChapter("") : null}
|
||||
canAddChapter={canEdit}
|
||||
onMoveChapter={moveChapter}
|
||||
canReorder={canEdit && chapters.length > 1}
|
||||
@@ -462,30 +470,26 @@ export function MatterDetail() {
|
||||
>
|
||||
<header className="workspace-head">
|
||||
<div>
|
||||
<Trail items={record.trail?.length ? record.trail : objectTrail(record, query)} />
|
||||
<Trail items={trailWithChapter(record.trail?.length ? record.trail : objectTrail(record, query), record.chapters, chapterId, `/matters/${id}${query}`)} />
|
||||
<Placements items={record.placements} />
|
||||
<div className="title-row">
|
||||
<h1>{record.title}</h1>
|
||||
<span className={record.status === "open" ? "status-pill" : "status-pill is-closed"}>{record.status === "open" ? "Offen" : "Geschlossen"}</span>
|
||||
{canEdit ? (
|
||||
<span className="record-tools">
|
||||
<IconButton name="pencil" label="Umbenennen" onClick={renameMatter} />
|
||||
<IconButton name={record.status === "closed" ? "restore" : "archive"} label={record.status === "closed" ? "Wieder öffnen" : "Archivieren"} onClick={archiveMatter} />
|
||||
<IconButton name="move" label="Verschieben" onClick={() => setModal("move")} />
|
||||
<IconButton name="trash" label="Löschen" onClick={deleteMatter} />
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
<div className="page-actions">
|
||||
{width < 1500 ? <button type="button" className="quiet" onClick={() => setStructureOpen(true)}>Struktur</button> : null}
|
||||
<button type="button" className="quiet" onClick={() => setModal("export")}>Übergabepaket</button>
|
||||
{canEdit ? (
|
||||
<button type="button" className="desktop-add" onClick={() => setModal("add")}>
|
||||
<NavIcon name="plus" /> Inhalt hinzufügen
|
||||
</button>
|
||||
) : null}
|
||||
<ObjectMenu view={view} onView={setView}>
|
||||
<button type="button" className="quiet" onClick={() => setModal("export")}>Übergabepaket</button>
|
||||
{canEdit ? <button type="button" className="quiet" onClick={renameMatter}>Umbenennen</button> : null}
|
||||
{canEdit ? <button type="button" className="quiet" onClick={archiveMatter}>{record.status === "closed" ? "Wieder öffnen" : "Archivieren"}</button> : null}
|
||||
{canEdit ? <button type="button" className="quiet" onClick={() => setModal("move")}>Verschieben</button> : null}
|
||||
{canEdit ? <button type="button" className="danger" onClick={deleteMatter}>Löschen</button> : null}
|
||||
{canEdit ? <button type="button" className="quiet" onClick={() => setModal("submatter")}>Teilvorgang anlegen</button> : null}
|
||||
{canEdit ? <button type="button" className="quiet" onClick={() => setModal("cross")}>Querverweis</button> : null}
|
||||
{record.rights.share || record.is_owner ? <button type="button" className="quiet" onClick={() => setModal("share")}>Teilen</button> : null}
|
||||
@@ -503,7 +507,8 @@ export function MatterDetail() {
|
||||
containerId={id}
|
||||
onlyChapter={chapterId}
|
||||
selectedId={entryId}
|
||||
listTitle={activeChapter ? activeChapter.title : "Alle Inhalte"}
|
||||
listTitle={activeChapter ? chapterPathLabel(record.chapters, activeChapter.id) : "Alle Inhalte"}
|
||||
onAddSubchapter={canEdit ? openChapter : null}
|
||||
onOpen={(binding) => {
|
||||
rememberScroll(listRef.current, scrollKey);
|
||||
openEntry(binding);
|
||||
@@ -553,7 +558,8 @@ export function MatterDetail() {
|
||||
<Modal open={modal === "add"} title={`Hinzufügen in ${targetLabel}`} onClose={() => setModal("")}>
|
||||
<TargetLine label={targetLabel} chapters={record.chapters} chapterId={activeChapter?.id || ""} />
|
||||
<div className="add-choices">
|
||||
<button type="button" onClick={() => setModal("chapter")}>Kapitel</button>
|
||||
<button type="button" onClick={() => openChapter(activeChapter?.id || "")}>{activeChapter ? "Unterkapitel" : "Kapitel"}</button>
|
||||
{activeChapter ? <button type="button" onClick={() => openChapter("")}>Kapitel auf oberster Ebene</button> : null}
|
||||
<button type="button" onClick={() => setModal("note")}>Notiz</button>
|
||||
<button type="button" onClick={() => setModal("file")}>Datei</button>
|
||||
<button type="button" onClick={() => setModal("paperless")}>Paperless</button>
|
||||
@@ -567,10 +573,10 @@ export function MatterDetail() {
|
||||
<FileForm context={rightsContext} placement={placement} chapters={record.chapters} initialChapter={activeChapter?.id || ""} targetLabel={targetLabel} onChange={() => { setModal(""); load(); }} />
|
||||
</Modal>
|
||||
<Modal open={modal === "paperless"} title="Aus Paperless" onClose={() => setModal("")}>
|
||||
<PaperlessPicker context={rightsContext} placement={placement} chapterId={activeChapter?.id || ""} chapterTitle={activeChapter?.title || ""} targetLabel={targetLabel} onDone={() => { setModal(""); load(); }} />
|
||||
<PaperlessPicker context={rightsContext} placement={placement} chapterId={activeChapter?.id || ""} chapterTitle={activeChapter ? chapterPathLabel(record.chapters, activeChapter.id) : ""} targetLabel={targetLabel} onDone={() => { setModal(""); load(); }} />
|
||||
</Modal>
|
||||
<Modal open={modal === "mail"} title="E-Mail verbinden" wide split onClose={() => setModal("")}>
|
||||
<MailPicker context={rightsContext} placement={placement} chapterId={activeChapter?.id || ""} chapterTitle={activeChapter?.title || ""} targetLabel={targetLabel} onDone={() => { setModal(""); load(); }} />
|
||||
<MailPicker context={rightsContext} placement={placement} chapterId={activeChapter?.id || ""} chapterTitle={activeChapter ? chapterPathLabel(record.chapters, activeChapter.id) : ""} targetLabel={targetLabel} onDone={() => { setModal(""); load(); }} />
|
||||
</Modal>
|
||||
<Modal open={modal === "submatter"} title="Teilvorgang anlegen" onClose={() => setModal("")}>
|
||||
<SubmatterForm parentId={id} context={inherited} onChange={() => { setModal(""); load(); }} />
|
||||
@@ -578,9 +584,11 @@ export function MatterDetail() {
|
||||
<Modal open={modal === "cross"} title="Querverweis" onClose={() => setModal("")}>
|
||||
<CrossLinkForm matterId={id} context={inherited} onChange={() => { setModal(""); load(); }} />
|
||||
</Modal>
|
||||
<Modal open={modal === "chapter"} title={`Kapitel in ${targetLabel} hinzufügen`} onClose={() => setModal("")}>
|
||||
<Modal open={modal === "chapter"} title={chapterParentId ? `Unterkapitel in ${targetLabel}` : `Kapitel in ${targetLabel}`} onClose={() => setModal("")}>
|
||||
<ChapterForm
|
||||
path={`/api/v1/matters/${id}/chapters${inherited ? `?context_kind=${inherited.kind}&context_id=${inherited.id}` : ""}`}
|
||||
targetLabel={targetLabel}
|
||||
parentChapter={chapterParentId ? { id: chapterParentId, title: chapterPathLabel(record.chapters, chapterParentId) } : null}
|
||||
onChange={(created) => {
|
||||
setModal("");
|
||||
if (created?.id) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useContext, useEffect, useState } from "react";
|
||||
import { useContext, useEffect, useRef, useState } from "react";
|
||||
import { NavLink, Outlet, useLocation, useNavigate } from "react-router-dom";
|
||||
import { SessionContext } from "../session.js";
|
||||
import { Mark, NavIcon } from "./icons.jsx";
|
||||
@@ -30,6 +30,8 @@ export function Shell() {
|
||||
}
|
||||
});
|
||||
const [query, setQuery] = useState("");
|
||||
const [searchOpen, setSearchOpen] = useState(false);
|
||||
const searchRef = useRef(null);
|
||||
const [more, setMore] = useState(false);
|
||||
const [width, setWidth] = useState(() => window.innerWidth);
|
||||
const [markIntroDone, setMarkIntroDone] = useState(false);
|
||||
@@ -149,15 +151,23 @@ export function Shell() {
|
||||
</aside>
|
||||
<div className="app-shell__column">
|
||||
<header className="app-header mobile-only">
|
||||
<NavLink to="/" className="app-logo" aria-label="Tsumugu">
|
||||
<span className="jk-logo-frame jk-logo-frame--plain" style={{ "--jk-frame-size": "36px" }}>
|
||||
<Mark size={28} motion={markMotion} onIntroComplete={() => setMarkIntroDone(true)} />
|
||||
</span>
|
||||
<span>Tsumugu</span>
|
||||
</NavLink>
|
||||
<form className="search" onSubmit={onSearch}>
|
||||
<input value={query} onChange={(event) => setQuery(event.target.value)} placeholder="Suchen" aria-label="Suchen" />
|
||||
</form>
|
||||
<div className="app-header__bar">
|
||||
<NavLink to="/" className="app-logo" aria-label="Tsumugu">
|
||||
<span className="jk-logo-frame jk-logo-frame--plain" style={{ "--jk-frame-size": "36px" }}>
|
||||
<Mark size={28} motion={markMotion} onIntroComplete={() => setMarkIntroDone(true)} />
|
||||
</span>
|
||||
<span>Tsumugu</span>
|
||||
</NavLink>
|
||||
<button type="button" className="icon-button" aria-label="Suchen" aria-expanded={searchOpen} onClick={() => setSearchOpen((value) => !value)}>
|
||||
<NavIcon name="search" />
|
||||
</button>
|
||||
</div>
|
||||
{searchOpen ? (
|
||||
<form className="search" onSubmit={onSearch}>
|
||||
<input ref={searchRef} value={query} onChange={(event) => setQuery(event.target.value)} placeholder="Suchen" aria-label="Suchen" autoFocus />
|
||||
<button type="button" className="quiet" onClick={() => setSearchOpen(false)}>Schließen</button>
|
||||
</form>
|
||||
) : null}
|
||||
</header>
|
||||
<div className="app-main">
|
||||
<Outlet />
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
export function chapterPath(chapters, chapterId) {
|
||||
const byId = new Map((chapters || []).map((chapter) => [chapter.id, chapter]));
|
||||
const names = [];
|
||||
const seen = new Set();
|
||||
let current = byId.get(chapterId);
|
||||
while (current && !seen.has(current.id)) {
|
||||
seen.add(current.id);
|
||||
names.unshift(current.title);
|
||||
current = current.parent_chapter_id ? byId.get(current.parent_chapter_id) : null;
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
export function chapterPathLabel(chapters, chapterId) {
|
||||
return chapterPath(chapters, chapterId).join(" / ");
|
||||
}
|
||||
|
||||
export function siblingChapterIds(chapters, chapterId) {
|
||||
const current = (chapters || []).find((chapter) => chapter.id === chapterId);
|
||||
const parent = current?.parent_chapter_id || null;
|
||||
return (chapters || [])
|
||||
.filter((chapter) => (chapter.parent_chapter_id || null) === parent)
|
||||
.map((chapter) => chapter.id);
|
||||
}
|
||||
|
||||
export function descendantChapterIds(chapters, chapterId) {
|
||||
const children = (chapters || []).filter((chapter) => chapter.parent_chapter_id === chapterId);
|
||||
return children.flatMap((chapter) => [chapter.id, ...descendantChapterIds(chapters, chapter.id)]);
|
||||
}
|
||||
|
||||
export function buildChapterSections(chapters, bindings) {
|
||||
const buckets = new Map();
|
||||
const loose = [];
|
||||
const known = new Set((chapters || []).map((chapter) => chapter.id));
|
||||
for (const binding of bindings || []) {
|
||||
if (binding.chapter_id && known.has(binding.chapter_id)) {
|
||||
const list = buckets.get(binding.chapter_id) || [];
|
||||
list.push(binding);
|
||||
buckets.set(binding.chapter_id, list);
|
||||
} else {
|
||||
loose.push(binding);
|
||||
}
|
||||
}
|
||||
const nodes = new Map();
|
||||
for (const chapter of chapters || []) {
|
||||
nodes.set(chapter.id, {
|
||||
id: chapter.id,
|
||||
title: chapter.title,
|
||||
documentOn: chapter.document_on || "",
|
||||
parentId: chapter.parent_chapter_id || "",
|
||||
items: buckets.get(chapter.id) || [],
|
||||
children: [],
|
||||
});
|
||||
}
|
||||
const roots = [];
|
||||
for (const chapter of chapters || []) {
|
||||
const node = nodes.get(chapter.id);
|
||||
const parent = chapter.parent_chapter_id ? nodes.get(chapter.parent_chapter_id) : null;
|
||||
if (parent) parent.children.push(node);
|
||||
else roots.push(node);
|
||||
}
|
||||
return { roots, loose };
|
||||
}
|
||||
|
||||
export function trailWithChapter(items, chapters, chapterId, backHref) {
|
||||
if (!chapterId) return items;
|
||||
const path = chapterPath(chapters, chapterId);
|
||||
if (!path.length) return items || [];
|
||||
const base = (items || []).map((item, index, all) => (
|
||||
index === all.length - 1 && !item.href ? { ...item, href: backHref } : item
|
||||
));
|
||||
return [...base, { label: path.join(" / "), href: null }];
|
||||
}
|
||||
|
||||
export function findSection(nodes, id) {
|
||||
for (const node of nodes || []) {
|
||||
if (node.id === id) return node;
|
||||
const found = findSection(node.children, id);
|
||||
if (found) return found;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
+670
-228
File diff suppressed because it is too large.
Load diff
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user