Mache die Breite der Ablage ziehbar und merkbar, verdichte die Zeilen und löse Vorgänge aus einer Akte, ohne sie zu löschen.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5f60e1fe40
commit
7b2d0c298e
8 files changed
+201
-7
No files matched your search
@@ -4,7 +4,7 @@ import { api } from "../api.js";
|
||||
import { isEmployee, shareTargets } from "../admin/admin-core.js";
|
||||
import { ErrorNote } from "../pages/widgets.jsx";
|
||||
import { SessionContext } from "../session.js";
|
||||
import { effectText } from "./library-core.js";
|
||||
import { clampTreeWidth, effectText, readTreeWidth, writeTreeWidth } from "./library-core.js";
|
||||
import { NavTree } from "./NavTree.jsx";
|
||||
|
||||
export const LibraryContext = createContext(null);
|
||||
@@ -39,6 +39,7 @@ export function LibraryLayout() {
|
||||
const [error, setError] = useState("");
|
||||
const [message, setMessage] = useState("");
|
||||
const [treeOpen, setTreeOpen] = useState(false);
|
||||
const [treeWidth, setTreeWidth] = useState(readTreeWidth);
|
||||
const timer = useRef(null);
|
||||
const actionsRef = useRef({});
|
||||
const pending = useRef(new Set());
|
||||
@@ -91,6 +92,40 @@ export function LibraryLayout() {
|
||||
setTreeOpen(false);
|
||||
}, [location.pathname, location.search]);
|
||||
|
||||
// Dragging the edge resizes the tree. The width is stored and the page layout is told to measure again.
|
||||
function startResize(event) {
|
||||
event.preventDefault();
|
||||
const startX = event.clientX;
|
||||
const startWidth = treeWidth;
|
||||
let latest = startWidth;
|
||||
const move = (moveEvent) => {
|
||||
latest = clampTreeWidth(startWidth + moveEvent.clientX - startX);
|
||||
setTreeWidth(latest);
|
||||
};
|
||||
const stop = () => {
|
||||
window.removeEventListener("pointermove", move);
|
||||
window.removeEventListener("pointerup", stop);
|
||||
document.body.classList.remove("is-resizing");
|
||||
writeTreeWidth(latest);
|
||||
window.dispatchEvent(new Event("resize"));
|
||||
};
|
||||
document.body.classList.add("is-resizing");
|
||||
window.addEventListener("pointermove", move);
|
||||
window.addEventListener("pointerup", stop);
|
||||
}
|
||||
|
||||
function resizeByKey(event) {
|
||||
const step = event.shiftKey ? 48 : 16;
|
||||
let next = null;
|
||||
if (event.key === "ArrowLeft") next = treeWidth - step;
|
||||
else if (event.key === "ArrowRight") next = treeWidth + step;
|
||||
else if (event.key === "Home" || event.key === "Enter") next = undefined;
|
||||
if (next === null) return;
|
||||
event.preventDefault();
|
||||
setTreeWidth(writeTreeWidth(next));
|
||||
window.dispatchEvent(new Event("resize"));
|
||||
}
|
||||
|
||||
const notify = useCallback((text) => {
|
||||
setMessage(text);
|
||||
clearTimeout(timer.current);
|
||||
@@ -137,12 +172,26 @@ export function LibraryLayout() {
|
||||
|
||||
return (
|
||||
<LibraryContext.Provider value={value}>
|
||||
<div className="library">
|
||||
<div className="library" style={{ "--tree-width": `${treeWidth}px` }}>
|
||||
<button type="button" className="quiet library__toggle" aria-expanded={treeOpen} onClick={() => setTreeOpen((open) => !open)}>
|
||||
{treeOpen ? "Ordner ausblenden" : "Ordner anzeigen"}
|
||||
</button>
|
||||
<aside className={`library__tree${treeOpen ? " is-open" : ""}`}>
|
||||
<NavTree cases={data.cases} matters={data.matters} rooms={data.rooms} employee={employee} onDropOnRoom={value.dropOnRoom} />
|
||||
<div
|
||||
className="library__resizer"
|
||||
role="separator"
|
||||
aria-orientation="vertical"
|
||||
aria-label="Breite der Ablage ändern"
|
||||
aria-valuenow={treeWidth}
|
||||
aria-valuemin={200}
|
||||
aria-valuemax={560}
|
||||
tabIndex={0}
|
||||
onPointerDown={startResize}
|
||||
onKeyDown={resizeByKey}
|
||||
onDoubleClick={() => { setTreeWidth(writeTreeWidth(264)); window.dispatchEvent(new Event("resize")); }}
|
||||
title="Ziehen zum Ändern der Breite, Doppelklick setzt zurück"
|
||||
/>
|
||||
</aside>
|
||||
<div className="library__main">
|
||||
<ErrorNote error={error} />
|
||||
|
||||
@@ -188,3 +188,35 @@ export function outlineSignature(record) {
|
||||
const submatters = (record.submatters || []).map((item) => item.id).join(",");
|
||||
return [record.id, record.title, chapters, subcases, matters.join(","), submatters].join("#");
|
||||
}
|
||||
|
||||
// ---- Width of the navigation tree: set by dragging, remembered per browser ----
|
||||
|
||||
export const TREE_WIDTH_KEY = "tsumugu-tree-width";
|
||||
export const TREE_DEFAULT = 264;
|
||||
export const TREE_MIN = 200;
|
||||
export const TREE_MAX = 560;
|
||||
|
||||
export function clampTreeWidth(value) {
|
||||
const number = Number(value);
|
||||
if (!Number.isFinite(number)) return TREE_DEFAULT;
|
||||
return Math.min(TREE_MAX, Math.max(TREE_MIN, Math.round(number)));
|
||||
}
|
||||
|
||||
export function readTreeWidth(storage = typeof window === "undefined" ? null : window.localStorage) {
|
||||
try {
|
||||
const raw = storage?.getItem(TREE_WIDTH_KEY);
|
||||
return raw ? clampTreeWidth(raw) : TREE_DEFAULT;
|
||||
} catch {
|
||||
return TREE_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
export function writeTreeWidth(value, storage = typeof window === "undefined" ? null : window.localStorage) {
|
||||
const width = clampTreeWidth(value);
|
||||
try {
|
||||
storage?.setItem(TREE_WIDTH_KEY, String(width));
|
||||
} catch {
|
||||
/* The width then only lasts for this visit. */
|
||||
}
|
||||
return width;
|
||||
}
|
||||
@@ -127,3 +127,30 @@ test("the outline signature changes with chapters, subcases and matters", () =>
|
||||
assert.notEqual(outlineSignature({ ...base, matters: [] }), same);
|
||||
assert.equal(outlineSignature(null), "");
|
||||
});
|
||||
|
||||
import { TREE_DEFAULT, TREE_MAX, TREE_MIN, clampTreeWidth, readTreeWidth, writeTreeWidth } from "./library-core.js";
|
||||
|
||||
function memory(initial = {}) {
|
||||
const data = { ...initial };
|
||||
return { getItem: (key) => (key in data ? data[key] : null), setItem: (key, value) => { data[key] = value; }, data };
|
||||
}
|
||||
|
||||
test("the tree width stays within its limits and falls back to the default", () => {
|
||||
assert.equal(clampTreeWidth(10), TREE_MIN);
|
||||
assert.equal(clampTreeWidth(9999), TREE_MAX);
|
||||
assert.equal(clampTreeWidth(300.4), 300);
|
||||
assert.equal(clampTreeWidth("abc"), TREE_DEFAULT);
|
||||
assert.equal(clampTreeWidth(undefined), TREE_DEFAULT);
|
||||
});
|
||||
|
||||
test("the tree width is remembered and a broken store does not matter", () => {
|
||||
const store = memory();
|
||||
assert.equal(readTreeWidth(store), TREE_DEFAULT);
|
||||
assert.equal(writeTreeWidth(380, store), 380);
|
||||
assert.equal(readTreeWidth(store), 380);
|
||||
assert.equal(readTreeWidth(memory({ "tsumugu-tree-width": "99999" })), TREE_MAX);
|
||||
const broken = { getItem() { throw new Error("blocked"); }, setItem() { throw new Error("blocked"); } };
|
||||
assert.equal(readTreeWidth(broken), TREE_DEFAULT);
|
||||
assert.equal(writeTreeWidth(300, broken), 300);
|
||||
assert.equal(readTreeWidth(null), TREE_DEFAULT);
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Library: folder tree and tiles. Colors come from the theme variables, so light and dark follow. */
|
||||
.library { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: 100%; }
|
||||
.library__tree { border-right: 1px solid var(--border); background: var(--surface2); overflow: auto; padding: 14px 10px 24px; }
|
||||
.library { --tree-width: 264px; display: grid; grid-template-columns: var(--tree-width) minmax(0, 1fr); min-height: 100%; }
|
||||
.library__tree { position: relative; border-right: 1px solid var(--border); background: var(--surface2); overflow: auto; padding: 12px 6px 24px 8px; }
|
||||
.library__main { min-width: 0; }
|
||||
.library__toggle { display: none; margin: 10px 16px 0; }
|
||||
.library-page .page-head { align-items: flex-start; }
|
||||
@@ -117,3 +117,20 @@ a.button.quiet { background: var(--surface2); border: 1px solid var(--border2);
|
||||
.library-tree__list { min-width: 0; }
|
||||
.library-tree__section > .library-tree__row > .library-tree__root { flex: 1; }
|
||||
.mini-icon--plus { color: var(--accent-dark); }
|
||||
|
||||
/* Compact rows and less indentation, so deep structures fit */
|
||||
.library-tree__root, .library-tree__link { min-height: 28px; padding: 3px 6px; gap: 6px; }
|
||||
.library-tree__list { padding: 0 0 0 4px; gap: 0; }
|
||||
.library-tree__list .library-tree__list { margin-left: 8px; padding-left: 3px; }
|
||||
.library-tree__toggle { width: 20px; min-width: 20px; min-height: 26px; }
|
||||
.library-tree__heading { margin: 10px 6px 2px; }
|
||||
.library-tree__title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
|
||||
/* Handle on the right edge of the tree */
|
||||
.library__resizer { position: absolute; top: 0; right: -3px; width: 7px; height: 100%; cursor: col-resize; z-index: 5; touch-action: none; }
|
||||
.library__resizer:hover, .library__resizer:focus-visible { background: color-mix(in srgb, var(--accent) 35%, transparent); outline: none; }
|
||||
body.is-resizing { cursor: col-resize; user-select: none; }
|
||||
body.is-resizing .library__resizer { background: color-mix(in srgb, var(--accent) 50%, transparent); }
|
||||
@media (max-width: 900px) { .library__resizer { display: none; } }
|
||||
|
||||
.inline-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
|
||||
Reference in new issue
Block a user