Lass ein Kapitel im Vorgang am Kopf ziehen, damit die Reihenfolge samt Inhalt erhalten bleibt.
Deploy Development / deploy (push) Successful in 25s
Test Suite / pytest-backend (push) Successful in 1m6s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 5s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-17 12:46:06 +02:00
1 parent 7ef73ad500
commit 1621a7eb2f
3 files changed
+150 -110

No files matched your search

+138 -108
View File
@@ -288,11 +288,15 @@ export function ContentBoard({
const custom = record?.content_order === "position";
const direction = record?.content_order_dir === "desc" ? "desc" : "asc";
const sections = sectionsOf(chapters, source);
const visibleSections = onlyChapter ? sections.filter((section) => section.id === onlyChapter) : sections;
const visibleSections = onlyChapter ? sections.filter((section) => section.id !== "loose") : sections;
const canSort = sortable && record?.rights?.edit;
const canMoveChapters = Boolean(canSort && chapters.length > 1);
const orderPath = `/api/v1/${containerKind === "case" ? "cases" : "matters"}/${containerId}`;
const orderContext = context && containerKind === "matter" ? { context } : {};
const finishDragRef = useRef(finishDrag);
finishDragRef.current = finishDrag;
useEffect(() => {
function onKey(event) {
if (event.key !== "Escape" || !dragRef.current) return;
@@ -304,6 +308,37 @@ export function ContentBoard({
return () => window.removeEventListener("keydown", onKey);
}, []);
useEffect(() => {
const node = rootRef.current;
if (!node) return undefined;
function place(event) {
const drag = dragRef.current;
if (!drag?.html5) return;
event.preventDefault();
if (drag.kind === "chapter") {
drag.index = chapterUnder(event.clientY);
setIndicator({ sectionId: drag.chapterId, index: drag.index, kind: "chapter" });
return;
}
const sectionId = event.target?.closest?.("[data-section]")?.getAttribute("data-section");
if (!sectionId) return;
drag.targetSectionId = sectionId;
drag.index = indexAt(sectionId, event.clientY);
setIndicator({ sectionId, index: drag.index });
}
function drop(event) {
if (!dragRef.current?.html5) return;
place(event);
finishDragRef.current(dragRef.current);
}
node.addEventListener("dragover", place);
node.addEventListener("drop", drop);
return () => {
node.removeEventListener("dragover", place);
node.removeEventListener("drop", drop);
};
}, []);
async function saveMode(mode, nextDirection) {
setError("");
setPending(true);
@@ -344,9 +379,17 @@ export function ContentBoard({
setError("");
setPending(true);
try {
let version = record.version;
if (!custom) {
const switched = await api(`${orderPath}/content-order`, {
method: "PATCH",
body: { expected_version: version, mode: "position", direction, ...orderContext },
});
version = switched.version;
}
await api(`${orderPath}/chapters/order`, {
method: "POST",
body: { expected_version: record.version, chapter_ids: ids, ...orderContext },
body: { expected_version: version, chapter_ids: ids, ...orderContext },
});
onChange();
} catch (err) {
@@ -431,13 +474,15 @@ export function ContentBoard({
return hit?.getAttribute("data-section") || null;
}
function chapterIndexAt(clientY) {
const nodes = [...(rootRef.current?.querySelectorAll("[data-chapter]") || [])];
function chapterUnder(clientY) {
const nodes = [...(rootRef.current?.querySelectorAll("[data-chapter] .chapter-head") || [])];
if (!nodes.length) return 0;
for (let i = 0; i < nodes.length; i += 1) {
const rect = nodes[i].getBoundingClientRect();
if (clientY < rect.top + rect.height / 2) return i;
const next = nodes[i + 1]?.getBoundingClientRect();
const bottom = next ? next.top : Number.POSITIVE_INFINITY;
if (clientY < bottom) return i;
}
return nodes.length;
return nodes.length - 1;
}
function finishDrag(drag) {
@@ -448,14 +493,10 @@ export function ContentBoard({
if (drag.kind === "chapter") {
const ids = chapters.map((chapter) => chapter.id);
const from = ids.indexOf(drag.chapterId);
if (from < 0) return;
let target = drag.index;
if (from < target) target -= 1;
if (target < 0) target = 0;
if (target > ids.length - 1) target = ids.length - 1;
if (target === from) return;
const target = drag.index;
if (from < 0 || target == null || target === from) return;
const [id] = ids.splice(from, 1);
ids.splice(target, 0, id);
ids.splice(Math.max(0, Math.min(target, ids.length)), 0, id);
reorderChapters(ids);
return;
}
@@ -498,7 +539,7 @@ export function ContentBoard({
if (event.clientY < 72) window.scrollBy(0, -16);
if (event.clientY > window.innerHeight - 72) window.scrollBy(0, 16);
if (drag.kind === "chapter") {
drag.index = chapterIndexAt(event.clientY);
drag.index = chapterUnder(event.clientY);
setIndicator({ sectionId: drag.chapterId, index: drag.index, kind: "chapter" });
return;
}
@@ -517,69 +558,49 @@ export function ContentBoard({
}
function cancel() {
const drag = dragRef.current;
window.removeEventListener("pointermove", track);
window.removeEventListener("pointerup", release);
window.removeEventListener("pointercancel", cancel);
if (drag?.html5) return;
dragRef.current = null;
setDraggingId("");
setIndicator(null);
}
function onHandleDown(event, bindingId, sectionId) {
if (event.button != null && event.button !== 0) return;
dragRef.current = { pointerId: event.pointerId, bindingId, sectionId, startY: event.clientY, moved: false, index: null };
setDraggingId(bindingId);
function markHtml5(drag) {
const current = dragRef.current;
if (current && (current.chapterId === drag.chapterId || current.bindingId === drag.bindingId)) {
current.html5 = true;
current.moved = true;
return;
}
dragRef.current = { ...drag, html5: true, moved: true, index: null, pointerId: "html5", startY: 0 };
}
function endHtml5() {
setTimeout(() => {
const drag = dragRef.current;
if (!drag?.html5) return;
dragRef.current = null;
setDraggingId("");
setIndicator(null);
}, 0);
}
function beginDrag(event, drag) {
if (pending || (event.button != null && event.button !== 0)) return;
event.preventDefault();
dragRef.current = { ...drag, pointerId: event.pointerId, startY: event.clientY, moved: false, index: null };
setDraggingId(drag.bindingId || drag.chapterId || "");
window.addEventListener("pointermove", track);
window.addEventListener("pointerup", release);
window.addEventListener("pointercancel", cancel);
}
function onDragStart(event, bindingId, sectionId) {
event.dataTransfer.effectAllowed = "move";
event.dataTransfer.setData("text/plain", bindingId);
dragRef.current = { pointerId: "html5", bindingId, sectionId, targetSectionId: sectionId, startY: event.clientY, moved: true, index: null, html5: true };
setDraggingId(bindingId);
}
function onChapterDragStart(event, chapterId) {
event.dataTransfer.effectAllowed = "move";
event.dataTransfer.setData("text/plain", chapterId);
dragRef.current = { kind: "chapter", pointerId: "html5", chapterId, startY: event.clientY, moved: true, index: null, html5: true };
setDraggingId(chapterId);
}
function onDragOver(event, sectionId) {
const drag = dragRef.current;
if (!drag?.html5 || drag.kind === "chapter") return;
event.preventDefault();
drag.targetSectionId = sectionId;
drag.index = indexAt(sectionId, event.clientY);
setIndicator({ sectionId, index: drag.index });
}
function onChapterDragOver(event) {
const drag = dragRef.current;
if (!drag?.html5 || drag.kind !== "chapter") return;
event.preventDefault();
drag.index = chapterIndexAt(event.clientY);
setIndicator({ sectionId: drag.chapterId, index: drag.index, kind: "chapter" });
}
function onDrop(event, sectionId) {
const drag = dragRef.current;
if (!drag?.html5 || drag.kind === "chapter") return;
event.preventDefault();
drag.targetSectionId = sectionId;
drag.index = indexAt(sectionId, event.clientY);
finishDrag(drag);
}
function onChapterDrop(event) {
const drag = dragRef.current;
if (!drag?.html5 || drag.kind !== "chapter") return;
event.preventDefault();
drag.index = chapterIndexAt(event.clientY);
finishDrag(drag);
try {
event.currentTarget.setPointerCapture?.(event.pointerId);
} catch {
// The window listeners still follow the pointer when capture is unavailable.
}
}
return (
@@ -598,47 +619,50 @@ export function ContentBoard({
{pending ? <p className="muted">Ordnung wird gespeichert …</p> : null}
<ErrorNote error={error} />
{source.length || chapters.length ? (
visibleSections.map((section) => (
visibleSections.map((section) => {
const chapterIndex = chapters.findIndex((chapter) => chapter.id === section.id);
const expanded = !onlyChapter || section.id === onlyChapter;
const movable = canMoveChapters && section.id !== "loose";
const classes = ["content-section"];
if (draggingId === section.id) classes.push("is-dragging");
if (!expanded) classes.push("is-collapsed");
if (indicator?.kind === "chapter" && chapterIndex === indicator.index && draggingId !== section.id) classes.push("is-chapter-target");
return (
<section
key={section.id}
className={indicator?.kind === "chapter" && indicator.index === chapters.findIndex((chapter) => chapter.id === section.id) ? "content-section is-chapter-target" : "content-section"}
className={classes.join(" ")}
data-section={section.id}
data-chapter={section.id === "loose" ? undefined : section.id}
onDragOver={(event) => {
if (dragRef.current?.kind === "chapter") onChapterDragOver(event);
else onDragOver(event, section.id);
}}
onDrop={(event) => {
if (dragRef.current?.kind === "chapter") onChapterDrop(event);
else onDrop(event, section.id);
}}
>
{section.title ? (
<div className="chapter-head">
{canSort && custom && section.id !== "loose" && !onlyChapter ? (
<button
type="button"
className="handle"
aria-label={`${section.title} verschieben`}
draggable={!pending}
disabled={pending}
onPointerDown={(event) => {
if (event.button != null && event.button !== 0) return;
dragRef.current = { kind: "chapter", pointerId: event.pointerId, chapterId: section.id, startY: event.clientY, moved: false, index: null };
setDraggingId(section.id);
window.addEventListener("pointermove", track);
window.addEventListener("pointerup", release);
window.addEventListener("pointercancel", cancel);
}}
onDragStart={(event) => onChapterDragStart(event, section.id)}
onDragEnd={cancel}
>
<span className="handle__grip" aria-hidden="true" />
</button>
<div
className={movable ? "chapter-head is-movable" : "chapter-head"}
draggable={movable && !pending}
onPointerDownCapture={(event) => {
if (!movable) return;
if (event.target.closest("input, textarea, select, a, label, .chapter-move")) return;
beginDrag(event, { kind: "chapter", chapterId: section.id });
}}
onDragStart={(event) => {
if (!movable || event.target.closest("input, textarea, select, a, label, .chapter-move")) {
event.preventDefault();
return;
}
event.dataTransfer.effectAllowed = "move";
event.dataTransfer.setData("text/plain", section.id);
markHtml5({ kind: "chapter", chapterId: section.id });
setDraggingId(section.id);
}}
onDragEnd={endHtml5}
>
{movable ? (
<span className="handle" aria-hidden="true">
<span className="handle__grip" />
</span>
) : null}
<h3 className="chapter-title">{section.title}</h3>
{section.documentOn ? <span className="muted">{formatDate(section.documentOn)}</span> : null}
{canSort && custom && section.id !== "loose" && !onlyChapter ? (
{movable ? (
<span className="chapter-move">
<button type="button" className="quiet" aria-label={`${section.title} nach oben`} disabled={pending || chapters[0]?.id === section.id} onClick={() => moveChapter(section.id, -1)}>Nach oben</button>
<button type="button" className="quiet" aria-label={`${section.title} nach unten`} disabled={pending || chapters[chapters.length - 1]?.id === section.id} onClick={() => moveChapter(section.id, 1)}>Nach unten</button>
@@ -658,15 +682,15 @@ export function ContentBoard({
) : null}
</div>
) : null}
{section.title && !section.items.length ? <p className="muted">Noch nichts in diesem Kapitel.</p> : null}
<ol className="preview-list">
{expanded && section.title && !section.items.length ? <p className="muted">Noch nichts in diesem Kapitel.</p> : null}
{expanded ? <ol className="preview-list">
{section.items.map((binding, index) => {
const element = binding.element;
const href = itemHref(binding);
const text = blurb(element);
return (
<li key={binding.id} data-binding={binding.id} className={draggingId === binding.id ? "preview-row is-dragging" : "preview-row"}>
{indicator?.sectionId === section.id && indicator.index === index ? <div className="insert-line" /> : null}
{indicator?.sectionId === section.id && indicator?.kind !== "chapter" && indicator.index === index ? <div className="insert-line" /> : null}
{canSort && custom ? (
<button
type="button"
@@ -674,9 +698,14 @@ export function ContentBoard({
aria-label={`${element.title} ziehen`}
draggable={!pending}
disabled={pending}
onPointerDown={(event) => onHandleDown(event, binding.id, section.id)}
onDragStart={(event) => onDragStart(event, binding.id, section.id)}
onDragEnd={cancel}
onPointerDown={(event) => beginDrag(event, { bindingId: binding.id, sectionId: section.id })}
onDragStart={(event) => {
event.dataTransfer.effectAllowed = "move";
event.dataTransfer.setData("text/plain", binding.id);
markHtml5({ bindingId: binding.id, sectionId: section.id, targetSectionId: section.id });
setDraggingId(binding.id);
}}
onDragEnd={endHtml5}
>
<span className="handle__grip" aria-hidden="true" />
</button>
@@ -714,10 +743,11 @@ export function ContentBoard({
</li>
);
})}
{indicator?.sectionId === section.id && indicator.index === section.items.length ? <li className="insert-line" aria-hidden="true" /> : null}
</ol>
{indicator?.sectionId === section.id && indicator?.kind !== "chapter" && indicator.index === section.items.length ? <li className="insert-line" aria-hidden="true" /> : null}
</ol> : null}
</section>
))
);
})
) : (
<p className="muted">Noch keine Unterlage und keine Notiz.</p>
)}
+10
View File
@@ -440,13 +440,19 @@ label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(-
.content-row__kind { color: var(--text3); font-size: 13px; }
.content-row__move { display: flex; gap: 4px; }
.chapter-head { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-top: 18px; }
.chapter-head.is-movable { cursor: grab; touch-action: none; user-select: none; }
.chapter-head.is-movable:active { cursor: grabbing; }
.chapter-head.is-movable .chapter-date,
.chapter-head.is-movable .chapter-move { cursor: auto; touch-action: auto; user-select: auto; }
.chapter-title { margin: 22px 0 4px; font-size: 15px; letter-spacing: 0; text-transform: none; color: var(--text1); font-weight: 700; }
.chapter-head .chapter-title { margin: 0; flex: 1 1 8rem; }
.chapter-date { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--text3); font-size: 13px; }
.chapter-date input { width: auto; }
.chapter-move { display: flex; gap: 4px; }
.chapter-move button { min-height: 32px; padding: 4px 8px; font-size: 13px; }
.content-section.is-dragging { opacity: 0.45; }
.content-section.is-chapter-target { box-shadow: inset 0 3px 0 var(--accent); }
.content-section.is-chapter-after { box-shadow: inset 0 -3px 0 var(--accent); }
.folder-tree, .folder-tree ul { list-style: none; margin: 0; padding: 0; }
.folder-tree ul { margin-left: 8px; padding-left: 8px; border-left: 1px solid var(--border); }
.folder-row { display: flex; align-items: center; gap: 2px; min-height: 32px; border-radius: 6px; }
@@ -551,6 +557,9 @@ button.hierarchy__row { width: 100%; min-height: 34px; padding: 6px 8px; border:
}
.thumb--pdf { pointer-events: none; }
.handle {
display: inline-flex;
align-items: center;
justify-content: center;
width: 28px;
min-width: 28px;
min-height: 44px;
@@ -562,6 +571,7 @@ button.hierarchy__row { width: 100%; min-height: 34px; padding: 6px 8px; border:
}
.handle:hover, .handle:focus-visible { background: var(--surface2); }
.handle__grip {
display: block;
width: 10px;
height: 16px;
background-image: radial-gradient(currentColor 1.15px, transparent 1.25px);