From 1621a7eb2f6bcc4e11b43d40bee66c7cf7dbe75b Mon Sep 17 00:00:00 2001 From: Lars Date: Sat, 17 Oct 2026 12:46:06 +0200 Subject: [PATCH] Lass ein Kapitel im Vorgang am Kopf ziehen, damit die Reihenfolge samt Inhalt erhalten bleibt. Co-authored-by: Cursor --- docs/product/TSUMUGU_UX_MVP_ERGAENZUNG.md | 4 +- frontend/src/pages/content.jsx | 246 ++++++++++++---------- frontend/src/styles.css | 10 + 3 files changed, 150 insertions(+), 110 deletions(-) diff --git a/docs/product/TSUMUGU_UX_MVP_ERGAENZUNG.md b/docs/product/TSUMUGU_UX_MVP_ERGAENZUNG.md index b6069e0..0c07b1e 100644 --- a/docs/product/TSUMUGU_UX_MVP_ERGAENZUNG.md +++ b/docs/product/TSUMUGU_UX_MVP_ERGAENZUNG.md @@ -173,10 +173,10 @@ Weitere frei kombinierbare Sortierregeln oder ein allgemeiner Regelbaukasten sin - Neue Einträge stehen im Modus „Eigene Reihenfolge“ zunächst am Ende des gewählten Abschnitts; eine gezielte Einfügeposition ist möglich, falls bereits einfach unterstützt. Keine unvorhersehbare Umordnung bestehender Einträge. - Ein Wechsel zur Datumssortierung zerstört die eigene Reihenfolge nicht. Die Rückkehr stellt sie wieder her. Für neue Container ist „Fachliches Datum, aufsteigend“ der einfache Default; vorhandene Reihenfolgen werden bei der Einführung nicht ungefragt ersetzt. - Drag-and-drop ist im Modus „Eigene Reihenfolge“ verpflichtend: sichtbarer Ziehgriff, erkennbar mitbewegter Eintrag, eindeutige Einfügelinie vor beziehungsweise nach dem Ziel, Abbruch ohne Änderung und nach dem Ablegen zuverlässig gespeicherte Position. Auch an Anfang und Ende eines Abschnitts ablegen können. Bei langen Listen erforderliches Scrollen während des Ziehens unterstützen. -- Im Datumssortiermodus kein wirkungsloses Ziehen anbieten. Für manuelles Ordnen muss der Modus sichtbar gewechselt werden. In einer zusammengesetzten Lesesicht zunächst den einzelnen bearbeitbaren Container wählen. +- Im Datumssortiermodus kein wirkungsloses Ziehen von Einträgen anbieten. Für die manuelle Eintragsordnung muss der Modus sichtbar gewechselt werden. In einer zusammengesetzten Lesesicht zunächst den einzelnen bearbeitbaren Container wählen. - Tastatur und Touch erhalten zusätzlich einen vollständigen Weg ohne Drag-and-drop, beispielsweise kleine Menüaktionen „Nach oben“/„Nach unten“. Leser erhalten keine aktiven Verschiebeaktionen. Erfolgreiches Speichern, laufender Vorgang, Fehler und Versionskonflikt verständlich anzeigen; eine fehlgeschlagene Speicherung darf nicht wie eine dauerhaft übernommene Ordnung erscheinen. - Der Pflichtumfang für Drag-and-drop ist die Reihenfolge innerhalb eines Kapitels beziehungsweise des ungegliederten Bereichs und das Ziehen eines Eintrags in ein anderes Kapitel desselben Containers. Der Kapitelwechsel bleibt zusätzlich über „In Kapitel einordnen“ möglich. Ein Kapitelwechsel innerhalb desselben Containers ändert keine Ownership oder Freigabe. -- Kapitel tragen eine eigene Reihenfolge und optional ein fachliches Datum. Im Modus „Eigene Reihenfolge“ lassen sich Kapitel samt ihren Einträgen verschieben. Im Datumsmodus bestimmt das Kapiteldatum die Reihenfolge der Kapitel; Kapitel ohne Datum stehen am Ende. Die Einträge bleiben in ihrem Kapitel. Die Aktion „In Kapitel einordnen“ und das Verschieben eines Kapitels ändern weder gemeinsame Inhalte noch Freigaben. +- Kapitel tragen eine eigene Reihenfolge und optional ein fachliches Datum. Am Kapitelkopf ziehen oder „Nach oben“/„Nach unten“ verschiebt das Kapitel samt seinen Einträgen, auch wenn der Vorgang noch nach Datum sortiert ist. Das Ablegen stellt die Ordnung sichtbar auf „Eigene Reihenfolge“ und speichert die Position. Solange die Kapitel nicht von Hand verschoben werden, bestimmt im Datumsmodus das Kapiteldatum die Reihenfolge; Kapitel ohne Datum stehen am Ende. Die Einträge bleiben in ihrem Kapitel. Die Aktion „In Kapitel einordnen“ und das Verschieben eines Kapitels ändern weder gemeinsame Inhalte noch Freigaben. - Sortieren ist kein Verschieben in einen anderen Vorgang und verändert keine Rechte, Inhalte, Ownership oder Freigaben. - Reorder-Anfragen werden serverseitig geprüft. Fremde oder nicht lesbare Einträge dürfen nicht über übermittelte IDs bearbeitet oder offengelegt werden. Die Reihenfolge ausschließlich sichtbarer Einträge darf verborgene Positionen nicht als Lücken oder Anzahl verraten. Verdeckte Einbindungen dürfen beim Speichern nicht verloren gehen. - Gleichzeitige Änderungen dürfen keine fremden Einbindungen oder Reihenfolgen still überschreiben. Eine einfache Versionsprüfung mit verständlicher Aufforderung zum Neuladen genügt. diff --git a/frontend/src/pages/content.jsx b/frontend/src/pages/content.jsx index d9e5983..2abe832 100644 --- a/frontend/src/pages/content.jsx +++ b/frontend/src/pages/content.jsx @@ -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 ?

Ordnung wird gespeichert …

: null} {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 (
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 ? ( -
- {canSort && custom && section.id !== "loose" && !onlyChapter ? ( - +
{ + 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 ? ( +
) : null} - {section.title && !section.items.length ?

Noch nichts in diesem Kapitel.

: null} -
    + {expanded && section.title && !section.items.length ?

    Noch nichts in diesem Kapitel.

    : null} + {expanded ?
      {section.items.map((binding, index) => { const element = binding.element; const href = itemHref(binding); const text = blurb(element); return (
    1. - {indicator?.sectionId === section.id && indicator.index === index ?
      : null} + {indicator?.sectionId === section.id && indicator?.kind !== "chapter" && indicator.index === index ?
      : null} {canSort && custom ? ( @@ -714,10 +743,11 @@ export function ContentBoard({
    2. ); })} - {indicator?.sectionId === section.id && indicator.index === section.items.length ?
    + {indicator?.sectionId === section.id && indicator?.kind !== "chapter" && indicator.index === section.items.length ?
: null}
- )) + ); + }) ) : (

Noch keine Unterlage und keine Notiz.

)} diff --git a/frontend/src/styles.css b/frontend/src/styles.css index abfdc85..06c02a8 100644 --- a/frontend/src/styles.css +++ b/frontend/src/styles.css @@ -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);