Halte die Vorgangsleiste sichtbar und nimm die ueberfluessigen Kapitelworte weg, damit Datum, Bezuege, Titel und mehrere Belege direkt gesetzt werden koennen.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
cbd45a8997
commit
deb5d662fe
13 files changed
+423
-101
No files matched your search
@@ -5,6 +5,7 @@ import { api, fetchFile, fetchPaperless } from "../api.js";
|
||||
import { contentSourceSymbol, contentSymbol, symbolUrl } from "../content-symbol.mjs";
|
||||
import { bezugCount, counterpartLabel, directionSymbol } from "../list-meta.mjs";
|
||||
import { MarkdownView } from "../markdown.jsx";
|
||||
import { NavIcon } from "./icons.jsx";
|
||||
import { Modal } from "./Modal.jsx";
|
||||
import { ErrorNote } from "./widgets.jsx";
|
||||
import {
|
||||
@@ -22,6 +23,56 @@ export function formatDate(value) {
|
||||
return `${day}.${month}.${year}`;
|
||||
}
|
||||
|
||||
function completeDate(value) {
|
||||
return /^\d{4}-\d{2}-\d{2}$/.test(value || "");
|
||||
}
|
||||
|
||||
export function DateField({ value = "", onChange, disabled = false, ...rest }) {
|
||||
const ref = useRef(null);
|
||||
const committed = useRef(value || "");
|
||||
// Chromium setzt bei einem gesteuerten Datumsfeld nach jeder Ziffer `value`
|
||||
// neu. Die Jahresstelle springt dann auf eine einstellige Zahl wie 0002
|
||||
// und der Fokus verlässt das Feld. Das Feld bleibt deshalb ungesteuert.
|
||||
useEffect(() => {
|
||||
const next = value || "";
|
||||
const node = ref.current;
|
||||
if (node && document.activeElement === node) return;
|
||||
committed.current = next;
|
||||
if (node && node.value !== next) node.value = next;
|
||||
}, [value]);
|
||||
|
||||
function commit(next) {
|
||||
if (next === committed.current) return;
|
||||
committed.current = next;
|
||||
onChange(next);
|
||||
}
|
||||
|
||||
function commitFrom(node) {
|
||||
if (node.validity?.badInput) {
|
||||
node.value = committed.current || "";
|
||||
return;
|
||||
}
|
||||
const next = node.value || "";
|
||||
if (next && !completeDate(next)) return;
|
||||
commit(next);
|
||||
}
|
||||
|
||||
return (
|
||||
<input
|
||||
{...rest}
|
||||
ref={ref}
|
||||
type="date"
|
||||
defaultValue={value || ""}
|
||||
disabled={disabled}
|
||||
autoComplete="off"
|
||||
onChange={(event) => {
|
||||
if (completeDate(event.target.value)) commit(event.target.value);
|
||||
}}
|
||||
onBlur={(event) => commitFrom(event.target)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function formatStamp(value) {
|
||||
if (!value) return "";
|
||||
const [day, time = ""] = String(value).split("T");
|
||||
@@ -351,12 +402,15 @@ function MenuPopover({ open, anchorRef, onClose, label, children, sheet = false
|
||||
}
|
||||
function onScroll(event) {
|
||||
if (panelRef.current?.contains(event.target)) return;
|
||||
const active = document.activeElement;
|
||||
if (active && panelRef.current?.contains(active) && /^(INPUT|TEXTAREA|SELECT)$/.test(active.tagName)) return;
|
||||
position();
|
||||
}
|
||||
window.addEventListener("keydown", onKey);
|
||||
window.addEventListener("resize", position);
|
||||
window.addEventListener("scroll", onScroll, true);
|
||||
const frame = requestAnimationFrame(() => {
|
||||
if (panelRef.current?.contains(document.activeElement)) return;
|
||||
const selected = panelRef.current?.querySelector("[aria-selected='true']")
|
||||
|| panelRef.current?.querySelector("button, a, input, select");
|
||||
selected?.focus();
|
||||
@@ -496,17 +550,22 @@ function BezugTarget({ item, source, onOpen, itemHref, onDone }) {
|
||||
return <p>{caption}</p>;
|
||||
}
|
||||
|
||||
function BezugMenu({ element, source, onOpen, itemHref }) {
|
||||
function BezugMenu({ element, source, onOpen, itemHref, canEdit = false, onClearBezug }) {
|
||||
const refers = element.refers_to || [];
|
||||
const replies = element.referred_by || [];
|
||||
const count = bezugCount(element);
|
||||
const anchorRef = useRef(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const canClear = Boolean(canEdit && onClearBezug);
|
||||
if (!count) return null;
|
||||
function close() {
|
||||
setOpen(false);
|
||||
anchorRef.current?.focus();
|
||||
}
|
||||
function dissolve(sourceId, targetId) {
|
||||
close();
|
||||
onClearBezug(sourceId, targetId);
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
@@ -529,11 +588,17 @@ function BezugMenu({ element, source, onOpen, itemHref }) {
|
||||
<MenuPopover open={open} anchorRef={anchorRef} onClose={close} label={`Bezüge ${count}`} sheet>
|
||||
{refers.length ? <p className="menu-popover__label">Bezug auf</p> : null}
|
||||
{refers.map((item) => (
|
||||
<BezugTarget key={`to-${item.id}`} item={item} source={source} onOpen={onOpen} itemHref={itemHref} onDone={close} />
|
||||
<div key={`to-${item.id}`} className="bezug-entry">
|
||||
<BezugTarget item={item} source={source} onOpen={onOpen} itemHref={itemHref} onDone={close} />
|
||||
{canClear ? <button type="button" onClick={() => dissolve(element.id, item.id)}>Bezug lösen</button> : null}
|
||||
</div>
|
||||
))}
|
||||
{replies.length ? <p className="menu-popover__label">Darauf bezogen</p> : null}
|
||||
{replies.map((item) => (
|
||||
<BezugTarget key={`by-${item.id}`} item={item} source={source} onOpen={onOpen} itemHref={itemHref} onDone={close} />
|
||||
<div key={`by-${item.id}`} className="bezug-entry">
|
||||
<BezugTarget item={item} source={source} onOpen={onOpen} itemHref={itemHref} onDone={close} />
|
||||
{canClear ? <button type="button" onClick={() => dissolve(item.id, element.id)}>Bezug lösen</button> : null}
|
||||
</div>
|
||||
))}
|
||||
</MenuPopover>
|
||||
</>
|
||||
@@ -560,6 +625,7 @@ function ChapterHeading({
|
||||
onDate,
|
||||
onMove,
|
||||
onAddSubchapter,
|
||||
onAddContent,
|
||||
onChange,
|
||||
onError,
|
||||
onPending,
|
||||
@@ -574,10 +640,23 @@ function ChapterHeading({
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<h3 className="chapter-title">
|
||||
{real ? <span className="chapter-kind">{section.parentId ? "Unterkapitel" : "Kapitel"}</span> : null}
|
||||
{section.title}
|
||||
<h3 className={`chapter-title${section.parentId ? " is-nested" : ""}`}>
|
||||
{real ? <NavIcon name="chapter" /> : null}
|
||||
<span>{section.title}</span>
|
||||
</h3>
|
||||
{canEdit && onAddContent ? (
|
||||
<button
|
||||
type="button"
|
||||
className="chapter-plus"
|
||||
aria-label={`Inhalt in ${section.title} hinzufügen`}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onAddContent(section.id);
|
||||
}}
|
||||
>
|
||||
<NavIcon name="plus" />
|
||||
</button>
|
||||
) : null}
|
||||
<span className="count">{count}</span>
|
||||
{section.documentOn ? <span className="chapter-date">{formatDate(section.documentOn)}</span> : null}
|
||||
{showMenu ? (
|
||||
@@ -603,7 +682,7 @@ function ChapterHeading({
|
||||
{canDate ? (
|
||||
<label>
|
||||
Kapiteldatum
|
||||
<input type="date" aria-label={`Kapiteldatum für ${section.title}`} value={section.documentOn || ""} disabled={pending} onChange={(event) => onDate(event.target.value)} />
|
||||
<DateField aria-label={`Kapiteldatum für ${section.title}`} value={section.documentOn || ""} onChange={onDate} />
|
||||
</label>
|
||||
) : null}
|
||||
{movable ? <button type="button" disabled={pending || siblingIndex <= 0} onClick={() => { close(); onMove(-1); }}>Nach oben</button> : null}
|
||||
@@ -659,6 +738,7 @@ function EntryActions({
|
||||
pending,
|
||||
onSetBezug,
|
||||
onClearBezug,
|
||||
onRenameTitle,
|
||||
onRemove,
|
||||
onMove,
|
||||
onPlaceChapter,
|
||||
@@ -692,6 +772,7 @@ function EntryActions({
|
||||
<MenuPopover open={open} anchorRef={anchorRef} onClose={close} label={`Aktionen für ${element.title}`} sheet>
|
||||
{canEdit ? (
|
||||
<>
|
||||
<button type="button" onClick={() => { close(); onRenameTitle(element); }}>Titel ändern</button>
|
||||
<p className="menu-popover__label">Bezug</p>
|
||||
<label>
|
||||
Bezug auf
|
||||
@@ -705,10 +786,16 @@ function EntryActions({
|
||||
</select>
|
||||
</label>
|
||||
{(element.refers_to || []).map((item) => (
|
||||
<button key={item.id} type="button" onClick={() => { close(); onClearBezug(element.id, item.id); }}>
|
||||
<button key={`to-${item.id}`} type="button" onClick={() => { close(); onClearBezug(element.id, item.id); }}>
|
||||
Bezug auf {item.title} lösen
|
||||
</button>
|
||||
))}
|
||||
{(element.referred_by || []).length ? <p className="menu-popover__label">Darauf bezogen</p> : null}
|
||||
{(element.referred_by || []).map((item) => (
|
||||
<button key={`by-${item.id}`} type="button" onClick={() => { close(); onClearBezug(item.id, element.id); }}>
|
||||
Bezug von {item.title} lösen
|
||||
</button>
|
||||
))}
|
||||
</>
|
||||
) : null}
|
||||
{canSort && chapters.length ? (
|
||||
@@ -811,6 +898,7 @@ export function ContentBoard({
|
||||
selectedId = "",
|
||||
onOpen,
|
||||
onAddSubchapter,
|
||||
onAddContent,
|
||||
listTitle = "",
|
||||
}) {
|
||||
const source = bindings || record?.bindings || [];
|
||||
@@ -883,6 +971,24 @@ export function ContentBoard({
|
||||
}
|
||||
}
|
||||
|
||||
async function renameElement(element) {
|
||||
const title = window.prompt("Titel", element.title);
|
||||
if (!title || title.trim() === element.title) return;
|
||||
setPending(true);
|
||||
setError("");
|
||||
try {
|
||||
await api(`/api/v1/elements/${element.id}/title`, {
|
||||
method: "PATCH",
|
||||
body: { expected_version: element.version, title: title.trim(), context: actionContext() },
|
||||
});
|
||||
await onChange();
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
} finally {
|
||||
setPending(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function clearBezug(elementId, refersToId) {
|
||||
setPending(true);
|
||||
setError("");
|
||||
@@ -1429,6 +1535,7 @@ export function ContentBoard({
|
||||
onDate={(value) => saveChapterDate(section.id, value)}
|
||||
onMove={(delta) => moveChapter(section.id, delta)}
|
||||
onAddSubchapter={onAddSubchapter}
|
||||
onAddContent={section.id === "loose" ? null : onAddContent}
|
||||
onChange={onChange}
|
||||
onError={setError}
|
||||
onPending={setPending}
|
||||
@@ -1535,7 +1642,7 @@ export function ContentBoard({
|
||||
</span>
|
||||
) : null}
|
||||
<span className="preview-row__facts">{facts}</span>
|
||||
<BezugMenu element={element} source={source} onOpen={onOpen} itemHref={itemHref} />
|
||||
<BezugMenu element={element} source={source} onOpen={onOpen} itemHref={itemHref} canEdit={canEdit} onClearBezug={clearBezug} />
|
||||
</div>
|
||||
{text ? (
|
||||
<Link className="preview-row__text" to={href} onClick={openFromList}>{text}</Link>
|
||||
@@ -1556,6 +1663,7 @@ export function ContentBoard({
|
||||
pending={pending}
|
||||
onSetBezug={setBezug}
|
||||
onClearBezug={clearBezug}
|
||||
onRenameTitle={renameElement}
|
||||
onRemove={removeBinding}
|
||||
onMove={move}
|
||||
onPlaceChapter={placeChapter}
|
||||
|
||||
Reference in new issue
Block a user