Oeffne Kapitel und Dokument auf derselben Arbeitsflaeche, damit Pfad, Rechte und eigene Reihenfolge beim Lesen erhalten bleiben.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
94ef46d8eb
commit
448e9a06ff
34 files changed
+2998
-696
No files matched your search
@@ -0,0 +1,201 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { NavIcon } from "./icons.jsx";
|
||||
|
||||
export function useWorkspaceLayout() {
|
||||
const [width, setWidth] = useState(() => (typeof window === "undefined" ? 1280 : window.innerWidth));
|
||||
const [structureOpen, setStructureOpen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const onResize = () => setWidth(window.innerWidth);
|
||||
window.addEventListener("resize", onResize);
|
||||
return () => window.removeEventListener("resize", onResize);
|
||||
}, []);
|
||||
|
||||
return { width, structureOpen, setStructureOpen };
|
||||
}
|
||||
|
||||
export function Workspace({ width, structureOpen, setStructureOpen, hasEntry, nav, reader, listRef, children }) {
|
||||
const phone = width < 760;
|
||||
const navColumn = width >= 1500;
|
||||
const split = width >= 1180 && hasEntry;
|
||||
const showNav = phone ? structureOpen && !hasEntry : navColumn || structureOpen;
|
||||
const showList = phone ? !structureOpen && !hasEntry : !(hasEntry && width < 1180);
|
||||
const showReader = hasEntry && (phone ? !structureOpen : true);
|
||||
const overlay = showNav && !phone && !navColumn;
|
||||
|
||||
useEffect(() => {
|
||||
document.body.classList.toggle("is-phone-reading", phone && hasEntry && !structureOpen);
|
||||
return () => document.body.classList.remove("is-phone-reading");
|
||||
}, [phone, hasEntry, structureOpen]);
|
||||
|
||||
const classes = ["workspace"];
|
||||
if (phone && structureOpen && !hasEntry) classes.push("is-structure");
|
||||
else if (!showNav || overlay) classes.push("is-nav-hidden");
|
||||
if (split && showList && showReader) classes.push("is-split");
|
||||
if (!showList && showReader) classes.push("is-reader-focus");
|
||||
|
||||
return (
|
||||
<div className={classes.join(" ")}>
|
||||
{showNav ? <div className={overlay ? "workspace-nav is-overlay" : "workspace-nav"}>{nav}</div> : null}
|
||||
{overlay ? (
|
||||
<button type="button" className="workspace-scrim" aria-label="Struktur schließen" onClick={() => setStructureOpen(false)} />
|
||||
) : null}
|
||||
{showList ? (
|
||||
<div className="workspace-main" ref={listRef}>
|
||||
{children}
|
||||
</div>
|
||||
) : null}
|
||||
{showReader ? <div className="workspace-reader">{reader}</div> : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function TreeNodes({ nodes, onNavigate }) {
|
||||
if (!nodes?.length) return null;
|
||||
return (
|
||||
<ul className="nav-tree">
|
||||
{nodes.map((node) => (
|
||||
<li key={node.id}>
|
||||
{node.href ? (
|
||||
<Link
|
||||
className={node.current ? "nav-tree__link is-current" : "nav-tree__link"}
|
||||
to={node.href}
|
||||
aria-current={node.current ? "page" : undefined}
|
||||
title={node.title}
|
||||
onClick={onNavigate}
|
||||
>
|
||||
<NavIcon name={node.kind === "Querverweis" ? "link" : node.kind === "Akte" || node.kind === "Unterakte" ? "folder" : "layers"} />
|
||||
<span>
|
||||
<span className="nav-tree__kind">{node.kind}</span>
|
||||
<span className="nav-tree__title">{node.title}</span>
|
||||
</span>
|
||||
</Link>
|
||||
) : (
|
||||
<span className="nav-tree__link is-current">
|
||||
<NavIcon name="layers" />
|
||||
<span>
|
||||
<span className="nav-tree__kind">{node.kind}</span>
|
||||
<span className="nav-tree__title">{node.title}</span>
|
||||
</span>
|
||||
</span>
|
||||
)}
|
||||
{node.children?.length ? <TreeNodes nodes={node.children} onNavigate={onNavigate} /> : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
export function StructureNavigator({
|
||||
contexts = [],
|
||||
contextValue = "",
|
||||
onContext,
|
||||
nodes = [],
|
||||
chapters = [],
|
||||
chapterId = "",
|
||||
allCount = 0,
|
||||
overview = null,
|
||||
chapterHeading,
|
||||
onChapter,
|
||||
onAddChapter,
|
||||
canAddChapter = false,
|
||||
onMoveChapter,
|
||||
canReorder = false,
|
||||
links = [],
|
||||
onNavigate,
|
||||
onClose,
|
||||
}) {
|
||||
return (
|
||||
<nav className="structure" aria-label="Struktur">
|
||||
<div className="structure__bar">
|
||||
<h2>Struktur</h2>
|
||||
{onClose ? (
|
||||
<button type="button" className="icon-button" aria-label="Struktur schließen" onClick={onClose}>
|
||||
<NavIcon name="close" />
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
<label className="context-select">
|
||||
Aktenkontext
|
||||
<select
|
||||
aria-label="Aktenkontext"
|
||||
value={contextValue}
|
||||
onChange={(event) => onContext?.(event.target.value)}
|
||||
disabled={!onContext || contexts.length < 2}
|
||||
>
|
||||
{contexts.length ? contexts.map((item) => (
|
||||
<option key={item.id} value={item.id}>{item.label}</option>
|
||||
)) : <option value="">Ohne Akte</option>}
|
||||
</select>
|
||||
</label>
|
||||
<TreeNodes nodes={nodes} onNavigate={onNavigate} />
|
||||
<div className="structure__chapters">
|
||||
<h3>{chapterHeading}</h3>
|
||||
{overview ? (
|
||||
<button type="button" className={overview.active ? "chapter-link is-current" : "chapter-link"} onClick={overview.onSelect}>
|
||||
<span>Überblick</span>
|
||||
<span className="count">{overview.count}</span>
|
||||
</button>
|
||||
) : null}
|
||||
<button type="button" className={!chapterId && !overview?.active ? "chapter-link is-current" : "chapter-link"} onClick={() => onChapter("")}>
|
||||
<span>Alle Inhalte</span>
|
||||
<span className="count">{allCount}</span>
|
||||
</button>
|
||||
<ul className="chapter-links">
|
||||
{chapters.map((chapter, index) => (
|
||||
<li key={chapter.id}>
|
||||
<button
|
||||
type="button"
|
||||
className={chapterId === chapter.id ? "chapter-link is-current" : "chapter-link"}
|
||||
onClick={() => onChapter(chapter.id)}
|
||||
>
|
||||
<span>{chapter.title}</span>
|
||||
<span className="count">{chapter.count}</span>
|
||||
</button>
|
||||
{canReorder && chapterId === chapter.id ? (
|
||||
<span className="chapter-link__move">
|
||||
<button type="button" aria-label={`${chapter.title} nach oben`} disabled={index === 0} onClick={() => onMoveChapter(chapter.id, -1)}>Nach oben</button>
|
||||
<button type="button" aria-label={`${chapter.title} nach unten`} disabled={index === chapters.length - 1} onClick={() => onMoveChapter(chapter.id, 1)}>Nach unten</button>
|
||||
</span>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{canAddChapter ? (
|
||||
<button type="button" className="quiet chapter-add" onClick={onAddChapter}>
|
||||
<NavIcon name="plus" /> Kapitel
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
{links.length ? (
|
||||
<div className="structure__links">
|
||||
<h3>Weitere Zuordnungen</h3>
|
||||
<ul className="nav-tree">
|
||||
{links.map((item) => (
|
||||
<li key={item.id}>
|
||||
<Link className="nav-tree__link" to={item.href} onClick={onNavigate}>
|
||||
<NavIcon name="link" />
|
||||
<span>
|
||||
<span className="nav-tree__kind">{item.kind}</span>
|
||||
<span className="nav-tree__title">{item.title}</span>
|
||||
</span>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
) : null}
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
||||
export function rememberScroll(node, key) {
|
||||
if (node && key) sessionStorage.setItem(key, String(node.scrollTop));
|
||||
}
|
||||
|
||||
export function restoreScroll(node, key) {
|
||||
if (!node || !key) return;
|
||||
const saved = sessionStorage.getItem(key);
|
||||
if (saved) node.scrollTop = Number(saved);
|
||||
}
|
||||
Reference in new issue
Block a user