Ziehe die Struktur enger und merke die Paperless-Auswahl, damit Kapitel ohne Extraeintrag zuklappbar bleiben.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
deb5d662fe
commit
f21c64a944
5 files changed
+97
-34
No files matched your search
@@ -159,13 +159,15 @@ function scopeContents({ chapters, chapterId, allLabel, overview, onChapter, can
|
||||
onSelect: overview.onSelect,
|
||||
});
|
||||
}
|
||||
items.push({
|
||||
id: "all-contents",
|
||||
title: allLabel,
|
||||
kind: "Inhalte",
|
||||
current: !chapterId && !overview?.active,
|
||||
onSelect: () => onChapter?.(""),
|
||||
});
|
||||
if (allLabel) {
|
||||
items.push({
|
||||
id: "all-contents",
|
||||
title: allLabel,
|
||||
kind: "Inhalte",
|
||||
current: !chapterId && !overview?.active,
|
||||
onSelect: () => onChapter?.(""),
|
||||
});
|
||||
}
|
||||
const byParent = new Map();
|
||||
chapters.forEach((chapter) => {
|
||||
const key = chapter.parent_chapter_id || "";
|
||||
@@ -192,16 +194,23 @@ function scopeContents({ chapters, chapterId, allLabel, overview, onChapter, can
|
||||
return items;
|
||||
}
|
||||
|
||||
function attachScope(nodes, extras) {
|
||||
function attachScope(nodes, extras, onContainerSelect) {
|
||||
return (nodes || []).map((node) => {
|
||||
const children = attachScope(node.children, extras);
|
||||
const children = attachScope(node.children, extras, onContainerSelect);
|
||||
if (!node.current) return { ...node, children };
|
||||
return { ...node, children: [...extras, ...children] };
|
||||
const nested = [...extras, ...children];
|
||||
const childCurrent = Boolean(onContainerSelect) && nested.some(branchHasCurrent);
|
||||
return {
|
||||
...node,
|
||||
current: onContainerSelect ? !childCurrent : node.current,
|
||||
...(onContainerSelect ? { onSelect: onContainerSelect } : {}),
|
||||
children: nested,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function treeWithScope(nodes, extras) {
|
||||
const attached = attachScope(nodes, extras);
|
||||
function treeWithScope(nodes, extras, onContainerSelect) {
|
||||
const attached = attachScope(nodes, extras, onContainerSelect);
|
||||
if (attached.some(branchHasCurrent)) return attached;
|
||||
return [...extras, ...attached];
|
||||
}
|
||||
@@ -224,7 +233,8 @@ export function StructureNavigator({
|
||||
}) {
|
||||
const [opened, setOpened] = useState(() => new Set());
|
||||
const [closed, setClosed] = useState(() => new Set());
|
||||
const tree = treeWithScope(nodes, scopeContents({ chapters, chapterId, allLabel, overview, onChapter, canReorder, onMoveChapter }));
|
||||
const extras = scopeContents({ chapters, chapterId, allLabel, overview, onChapter, canReorder, onMoveChapter });
|
||||
const tree = treeWithScope(nodes, extras, allLabel ? null : () => onChapter?.(""));
|
||||
|
||||
function isOpen(node, unfold) {
|
||||
if (!node.children?.length) return false;
|
||||
|
||||
Reference in new issue
Block a user