Stelle die Struktur als Hierarchie des gewaehlten Objekts dar und halte die Ordnerschrift im Postfach klein, ausser auf dem gewaehlten Pfad.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
f27df3ff35
commit
20625b4596
4 files changed
+170
-118
No files matched your search
@@ -51,53 +51,132 @@ export function Workspace({ width, structureOpen, setStructureOpen, hasEntry, na
|
||||
);
|
||||
}
|
||||
|
||||
function TreeNodes({ nodes, onNavigate }) {
|
||||
function structureIcon(kind) {
|
||||
if (kind === "Akte" || kind === "Unterakte") return "folder";
|
||||
if (kind === "Kapitel") return "chapter";
|
||||
if (kind === "Inhalte") return "contents";
|
||||
if (kind === "Querverweis" || kind === "Weitere Akte") return "link";
|
||||
return "layers";
|
||||
}
|
||||
|
||||
function branchHasCurrent(node) {
|
||||
if (node.current) return true;
|
||||
return (node.children || []).some(branchHasCurrent);
|
||||
}
|
||||
|
||||
function TreeRow({ node, onNavigate, ancestor = false }) {
|
||||
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}`;
|
||||
let row;
|
||||
if (node.onSelect) {
|
||||
row = (
|
||||
<button type="button" className={className} aria-current={node.current ? "true" : undefined} aria-label={name} title={name} onClick={() => { node.onSelect(); onNavigate?.(); }}>
|
||||
{icon}
|
||||
{label}
|
||||
</button>
|
||||
);
|
||||
} else if (node.href) {
|
||||
row = (
|
||||
<Link className={className} to={node.href} aria-current={node.current ? "page" : undefined} aria-label={name} title={name} onClick={onNavigate}>
|
||||
{icon}
|
||||
{label}
|
||||
</Link>
|
||||
);
|
||||
} else {
|
||||
row = (
|
||||
<span className={className} title={name}>
|
||||
{icon}
|
||||
{label}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
if (node.moveUp === undefined && node.moveDown === undefined) return row;
|
||||
return (
|
||||
<div className="nav-tree__line">
|
||||
{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>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function TreeNodes({ nodes, onNavigate, unfold = false }) {
|
||||
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>
|
||||
))}
|
||||
{nodes.map((node) => {
|
||||
const open = unfold || node.current || branchHasCurrent(node);
|
||||
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} />
|
||||
) : null}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
function scopeContents({ chapters, chapterId, allLabel, overview, onChapter, canReorder, onMoveChapter }) {
|
||||
const items = [];
|
||||
if (overview) {
|
||||
items.push({
|
||||
id: "overview",
|
||||
title: "Überblick",
|
||||
kind: "Inhalte",
|
||||
current: Boolean(overview.active),
|
||||
onSelect: overview.onSelect,
|
||||
});
|
||||
}
|
||||
items.push({
|
||||
id: "all-contents",
|
||||
title: allLabel,
|
||||
kind: "Inhalte",
|
||||
current: !chapterId && !overview?.active,
|
||||
onSelect: () => onChapter?.(""),
|
||||
});
|
||||
chapters.forEach((chapter, index) => {
|
||||
items.push({
|
||||
id: chapter.id,
|
||||
title: chapter.title,
|
||||
kind: "Kapitel",
|
||||
current: chapterId === chapter.id,
|
||||
onSelect: () => onChapter?.(chapter.id),
|
||||
...(canReorder ? {
|
||||
moveUp: index > 0 ? () => onMoveChapter(chapter.id, -1) : null,
|
||||
moveDown: index < chapters.length - 1 ? () => onMoveChapter(chapter.id, 1) : null,
|
||||
} : {}),
|
||||
});
|
||||
});
|
||||
return items;
|
||||
}
|
||||
|
||||
function attachScope(nodes, extras) {
|
||||
return (nodes || []).map((node) => {
|
||||
const children = attachScope(node.children, extras);
|
||||
if (!node.current) return { ...node, children };
|
||||
return { ...node, children: [...extras, ...children] };
|
||||
});
|
||||
}
|
||||
|
||||
function treeWithScope(nodes, extras) {
|
||||
const attached = attachScope(nodes, extras);
|
||||
if (attached.some(branchHasCurrent)) return attached;
|
||||
return [...extras, ...attached];
|
||||
}
|
||||
|
||||
export function StructureNavigator({
|
||||
contexts = [],
|
||||
contextValue = "",
|
||||
onContext,
|
||||
nodes = [],
|
||||
chapters = [],
|
||||
chapterId = "",
|
||||
allCount = 0,
|
||||
allLabel = "Alle Inhalte",
|
||||
overview = null,
|
||||
chapterHeading,
|
||||
onChapter,
|
||||
onAddChapter,
|
||||
canAddChapter = false,
|
||||
@@ -107,6 +186,7 @@ export function StructureNavigator({
|
||||
onNavigate,
|
||||
onClose,
|
||||
}) {
|
||||
const tree = treeWithScope(nodes, scopeContents({ chapters, chapterId, allLabel, overview, onChapter, canReorder, onMoveChapter }));
|
||||
return (
|
||||
<nav className="structure" aria-label="Struktur">
|
||||
<div className="structure__bar">
|
||||
@@ -118,71 +198,13 @@ export function StructureNavigator({
|
||||
) : null}
|
||||
</div>
|
||||
<div className="structure__tree">
|
||||
<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} />
|
||||
{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}
|
||||
</div>
|
||||
<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>
|
||||
<TreeNodes nodes={tree} onNavigate={onNavigate} />
|
||||
{links.length ? (
|
||||
<div className="structure__links">
|
||||
<h3>Weitere Zuordnungen</h3>
|
||||
<TreeNodes nodes={links} onNavigate={onNavigate} unfold />
|
||||
</div>
|
||||
) : null}
|
||||
<button type="button" className={!chapterId && !overview?.active ? "chapter-link is-current" : "chapter-link"} onClick={() => onChapter("")}>
|
||||
<span>{allLabel}</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 ? (
|
||||
<span className="chapter-link__move">
|
||||
<button type="button" aria-label={`${chapter.title} nach oben`} disabled={index === 0} onClick={() => onMoveChapter(chapter.id, -1)}>↑</button>
|
||||
<button type="button" aria-label={`${chapter.title} nach unten`} disabled={index === chapters.length - 1} onClick={() => onMoveChapter(chapter.id, 1)}>↓</button>
|
||||
</span>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{canAddChapter ? (
|
||||
<button type="button" className="quiet chapter-add" onClick={onAddChapter}>
|
||||
<NavIcon name="plus" /> Kapitel
|
||||
|
||||
Reference in new issue
Block a user