From 11e58042afc120616e5bda75e1072ff3c4468174 Mon Sep 17 00:00:00 2001 From: nodemode-ai Date: Fri, 27 Nov 2026 14:10:52 -0500 Subject: [PATCH 01/16] fix(items): refuse an empty title on create and update A blank or white-space title is refused with the normal 422 line on interactive create and on update that would blank a held title. Import paths keep their old behaviour. --- backend/app/store/items.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/app/store/items.py b/backend/app/store/items.py index e815db2..437d999 100644 --- a/backend/app/store/items.py +++ b/backend/app/store/items.py @@ -176,6 +176,8 @@ def require(conn: sqlite3.Connection, item_id: str) -> None: def create(conn: sqlite3.Connection, csl: dict, *, batch_id: str | None = None) -> dict: fields = from_csl(csl) + if batch_id is None and not fields["title"].strip(): + raise Invalid("A title is required.") item_id = new_id() stamp = now() with tx(conn): @@ -197,6 +199,10 @@ def update(conn: sqlite3.Connection, item_id: str, csl: dict) -> dict: fields = from_csl(csl) with tx(conn): require(conn, item_id) + if not fields["title"].strip(): + held = conn.execute("SELECT title FROM items WHERE id = ?", (item_id,)).fetchone() + if held is not None and str(held[0] or "").strip(): + raise Invalid("A title is required.") conn.execute( "UPDATE items SET type = ?, title = ?, container_title = ?, issued = ?, year = ?, doi = ?, isbn = ?, url = ?, " "abstract = ?, first_creator = ?, csl = ?, updated_at = ? WHERE id = ?", From 2dcd67c819a9c0d28a215b240f044ead2d96cf75 Mon Sep 17 00:00:00 2001 From: nodemode-ai Date: Fri, 27 Nov 2026 14:11:10 -0500 Subject: [PATCH 02/16] feat(window): position route can rank a trashed item The position route takes include_trashed so it can answer where a just-trashed item sat in the current sort and filter, with the same ordering as the rows route. --- backend/app/routers/window.py | 12 +++++++++++- backend/app/services/window_rows.py | 9 +++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/backend/app/routers/window.py b/backend/app/routers/window.py index 3315fa6..0c33c2b 100644 --- a/backend/app/routers/window.py +++ b/backend/app/routers/window.py @@ -49,8 +49,18 @@ def row_position( q: str | None = None, sort: str = "title", desc: bool = False, + include_trashed: bool = False, ) -> dict: - return _run(window_rows.row_position, item_id, scope=scope, scope_id=id, q=q, sort=sort, desc=desc) + return _run( + window_rows.row_position, + item_id, + scope=scope, + scope_id=id, + q=q, + sort=sort, + desc=desc, + include_trashed=include_trashed, + ) @router.get("/rows/{item_id}") diff --git a/backend/app/services/window_rows.py b/backend/app/services/window_rows.py index e897af5..354459d 100644 --- a/backend/app/services/window_rows.py +++ b/backend/app/services/window_rows.py @@ -116,6 +116,7 @@ def position( q: str | None = None, sort: str = "title", desc: bool = False, + include_trashed: bool = False, ) -> dict: if sort not in SORTS: raise Invalid(f"sort must be one of {', '.join(SORTS)}") @@ -125,11 +126,15 @@ def position( where = " WHERE " + " AND ".join(clauses) total = conn.execute("SELECT COUNT(*) FROM items i" + where, args).fetchone()[0] direction = "DESC" if desc else "ASC" + ranked_where, ranked_args = where, args + if include_trashed: + ranked_where = " WHERE " + " AND ".join(["(i.trashed_at IS NULL OR i.id = ?)", *clauses[1:]]) + ranked_args = [item_id, *args] ranked = ( f"SELECT n FROM (SELECT i.id AS id, ROW_NUMBER() OVER (ORDER BY {SORTS[sort]} {direction}, " - f"i.id {direction}) - 1 AS n FROM items i{where}) WHERE id = ?" + f"i.id {direction}) - 1 AS n FROM items i{ranked_where}) WHERE id = ?" ) - found = conn.execute(ranked, [*args, item_id]).fetchone() + found = conn.execute(ranked, [*ranked_args, item_id]).fetchone() return {"index": found[0] if found else -1, "total": total} From cb1c02dd064b840082792d7d037d6b2df5a0c8f7 Mon Sep 17 00:00:00 2001 From: nodemode-ai Date: Fri, 27 Nov 2026 14:12:11 -0500 Subject: [PATCH 03/16] feat(window): mark answers that ranked a trashed item A position answer asked with include_trashed carries include_trashed true, so a window can tell an older engine that ignored the flag. --- backend/app/services/window_rows.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/app/services/window_rows.py b/backend/app/services/window_rows.py index 354459d..01b4f69 100644 --- a/backend/app/services/window_rows.py +++ b/backend/app/services/window_rows.py @@ -135,7 +135,10 @@ def position( f"i.id {direction}) - 1 AS n FROM items i{ranked_where}) WHERE id = ?" ) found = conn.execute(ranked, [*ranked_args, item_id]).fetchone() - return {"index": found[0] if found else -1, "total": total} + answer = {"index": found[0] if found else -1, "total": total} + if include_trashed: + answer["include_trashed"] = True + return answer def row_position(item_id: str, **kwargs) -> dict: From 8e0210cc9400da73afd772fcc3ea667d518d6c9f Mon Sep 17 00:00:00 2001 From: nodemode-ai Date: Fri, 27 Nov 2026 14:12:11 -0500 Subject: [PATCH 04/16] feat(itemlist): tell an unknown id from an older engine fetchPosition answers unknown for a 404 that carries the engine detail, and null only for a 405, a bare Not Found or a trashed ask the engine did not honour. --- frontend/src/io/itemlist.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/frontend/src/io/itemlist.ts b/frontend/src/io/itemlist.ts index 82781d4..ebb9658 100644 --- a/frontend/src/io/itemlist.ts +++ b/frontend/src/io/itemlist.ts @@ -86,13 +86,24 @@ export async function fetchRows(rq: RowQuery, signal?: AbortSignal): Promise): Promise { +export function isUnknown(e: unknown): boolean { + return e instanceof EngineError && e.status === 404 && e.message !== 'Not Found'; +} + +export type PositionAnswer = RowPosition | 'unknown' | null; + +export async function fetchPosition(id: string, rq: Omit, trashed = false): Promise { if (rowsRoute === false) return null; const p = scopeParams(rq.scope, false); if (rq.q) p.set('q', rq.q); p.set('sort', rq.sort.key); p.set('desc', String(rq.sort.desc)); - try { return await api.get(`/library/rows/${encodeURIComponent(id)}/position?${p}`); } catch (e) { + if (trashed) p.set('include_trashed', 'true'); + try { + const pos = await api.get(`/library/rows/${encodeURIComponent(id)}/position?${p}`); + return trashed && pos.include_trashed !== true ? null : { index: pos.index, total: pos.total }; + } catch (e) { + if (e instanceof EngineError && e.status === 404 && e.message !== 'Not Found') return 'unknown'; if (e instanceof EngineError && (e.status === 404 || e.status === 405)) return null; throw e; } From b735cf1006c86866257a38fd19da75ef1ff763d9 Mon Sep 17 00:00:00 2001 From: nodemode-ai Date: Fri, 27 Nov 2026 14:12:11 -0500 Subject: [PATCH 05/16] feat(itemlist): shift the cache once for several removes or adds Never-loaded removes ask the position route with include_trashed and adds ask for all positions at once, then the cache shifts in one pass and only the holes are read. --- frontend/src/engine/itemlist.ts | 126 +++++++++++++++++++++----------- 1 file changed, 85 insertions(+), 41 deletions(-) diff --git a/frontend/src/engine/itemlist.ts b/frontend/src/engine/itemlist.ts index bd860c0..6458870 100644 --- a/frontend/src/engine/itemlist.ts +++ b/frontend/src/engine/itemlist.ts @@ -1,5 +1,5 @@ import type { Library } from './library'; -import { fetchPosition, fetchRow, fetchRows, type Row } from '../io/itemlist'; +import { fetchPosition, fetchRow, fetchRows, isUnknown, type PositionAnswer, type Row, type RowPosition, type RowQuery } from '../io/itemlist'; export const PAGE = 200; @@ -80,62 +80,106 @@ export class ItemListModel { } } - remove(ids: string[]): void { - if (!this.ready) return; - const gone = new Set(); - let unknown = 0; - for (const id of ids) { const i = this.indexOf(id); if (i >= 0) gone.add(i); else unknown++; } - if (unknown) { this.reload(); return; } - if (!gone.size) return; - const order = Array.from(gone).sort((a, b) => a - b); - const next = new Map(); - for (const [i, r] of this.cache) { - if (gone.has(i)) continue; - let lo = 0, hi = order.length; - while (lo < hi) { const m = (lo + hi) >> 1; if (order[m] < i) lo = m + 1; else hi = m; } - next.set(i - lo, r); - } + private where(): Omit { + return { scope: this.lib.scope, q: this.lib.query, sort: this.lib.sort }; + } + + private commit(next: Map, total: number): void { this.cache = next; this.index.clear(); for (const [i, r] of this.cache) this.index.set(r.id, i); for (const c of this.pending.values()) c.abort(); this.pending.clear(); this.spans.clear(); - this.total =Math.max(0, this.total - gone.size); + this.total = Math.max(0, total); this.lib.setCounts({ shown: this.total, total: this.total }); this.sink.reset(this.total); } - async insert(ids: string[]): Promise { + private queue: Promise = Promise.resolve(); + + remove(ids: string[]): Promise { + this.queue = this.queue.then(() => this.removeNow(ids)); + return this.queue; + } + + insert(ids: string[]): Promise { + this.queue = this.queue.then(() => this.insertNow(ids)); + return this.queue; + } + + private async removeNow(ids: string[]): Promise { if (!this.ready) return; const gen = this.generation; - for (const id of ids) { - if (this.indexOf(id) >= 0) continue; - try { - const r = await fetchRow(id); - if (gen !== this.generation) return; - const pos = await fetchPosition(id, { scope: this.lib.scope, q: this.lib.query, sort: this.lib.sort }); - if (gen !== this.generation) return; - if (!pos || (pos.index >= 0 && pos.total !== this.total + 1)) { this.reload(); return; } - if (pos.index < 0) continue; - const at = pos.index; - const next = new Map(); - for (const [i, x] of this.cache) next.set(i >= at ? i + 1 : i, x); - next.set(at, r); - this.cache = next; - this.index.clear(); - for (const [i, x] of this.cache) this.index.set(x.id, i); - for (const c of this.pending.values()) c.abort(); - this.pending.clear(); - this.spans.clear(); - this.total = pos.total; - this.lib.setCounts({ shown: this.total, total: this.total }); - this.sink.reset(this.total); - } catch (e) { + const gone = new Set(); + const unseen: string[] = []; + for (const id of new Set(ids)) { const i = this.indexOf(id); if (i >= 0) gone.add(i); else unseen.push(id); } + if (unseen.length) { + let answers: PositionAnswer[]; + try { answers = await Promise.all(unseen.map((id) => fetchPosition(id, this.where(), true))); } catch (e) { if (gen === this.generation) this.sink.error(e instanceof Error ? e.message : String(e)); return; } + if (gen !== this.generation) return; + for (const a of answers) { + if (a === null || a === 'unknown') { this.reload(); return; } + if (a.index >= 0) gone.add(a.index); + } + const after = (answers[0] as RowPosition).total; + if (after !== this.total - gone.size) { this.reload(); return; } + } + if (!gone.size) return; + const order = Array.from(gone).sort((a, b) => a - b); + const next = new Map(); + for (const [i, r] of this.cache) { + if (gone.has(i)) continue; + let lo = 0, hi = order.length; + while (lo < hi) { const m = (lo + hi) >> 1; if (order[m] < i) lo = m + 1; else hi = m; } + next.set(i - lo, r); + } + this.commit(next, this.total - gone.size); + } + + private async insertNow(ids: string[]): Promise { + if (!this.ready) return; + const gen = this.generation; + const fresh = Array.from(new Set(ids)).filter((id) => this.indexOf(id) < 0); + if (!fresh.length) return; + let answers: PositionAnswer[]; + try { answers = await Promise.all(fresh.map((id) => fetchPosition(id, this.where()))); } catch (e) { + if (gen === this.generation) this.sink.error(e instanceof Error ? e.message : String(e)); + return; + } + if (gen !== this.generation) return; + const placed: { at: number; id: string; row?: Row }[] = []; + let total = this.total; + for (let k = 0; k < fresh.length; k++) { + const a = answers[k]; + if (a === 'unknown') continue; + if (a === null) { this.reload(); return; } + if (a.index >= 0) { placed.push({ at: a.index, id: fresh[k] }); total = a.total; } + } + if (!placed.length) return; + if (total !== this.total + placed.length) { this.reload(); return; } + let rows: Row[]; + try { rows = await Promise.all(placed.map((p) => fetchRow(p.id))); } catch (e) { + if (gen !== this.generation) return; + if (isUnknown(e)) { this.reload(); return; } + this.sink.error(e instanceof Error ? e.message : String(e)); + return; + } + if (gen !== this.generation) return; + placed.forEach((p, k) => { p.row = rows[k]; }); + placed.sort((a, b) => a.at - b.at); + const ats = placed.map((p) => p.at); + const next = new Map(); + let c = 0; + for (const i of Array.from(this.cache.keys()).sort((a, b) => a - b)) { + while (c < ats.length && ats[c] <= i + c) c++; + next.set(i + c, this.cache.get(i) as Row); } + for (const p of placed) next.set(p.at, p.row as Row); + this.commit(next, total); } async refreshOne(id: string): Promise { From f7dd005f4770538886d94b64676dd9c4b1e49be3 Mon Sep 17 00:00:00 2001 From: nodemode-ai Date: Fri, 27 Nov 2026 14:12:45 -0500 Subject: [PATCH 06/16] feat(detail): send several item fields in one patch The detail client can send a whole fields object in one PATCH, so every creator role goes in one request. --- frontend/src/io/detail.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/io/detail.ts b/frontend/src/io/detail.ts index 3547a43..c5c7e90 100644 --- a/frontend/src/io/detail.ts +++ b/frontend/src/io/detail.ts @@ -51,6 +51,7 @@ const enc = encodeURIComponent; export const detailApi = { item: (id: string, signal?: AbortSignal) => api.get(`/library/items/${enc(id)}`, signal), editField: (id: string, key: string, value: unknown) => patch(`/library/items/${enc(id)}`, { fields: { [key]: value } }), + editFields: (id: string, fields: Record) => patch(`/library/items/${enc(id)}`, { fields }), addTags: (id: string, names: string[]) => api.post<{ item_id: string; tags: string[] }>(`/library/items/${enc(id)}/tags`, { names }), removeTags: (id: string, names: string[]) => delWith<{ item_id: string; tags: string[] }>(`/library/items/${enc(id)}/tags`, { names }), trash: (id: string) => api.post(`/library/items/${enc(id)}/trash`, {}), From f617c8fba2cd36caf6d84486c08cca7d079afeb3 Mon Sep 17 00:00:00 2001 From: nodemode-ai Date: Fri, 27 Nov 2026 14:12:45 -0500 Subject: [PATCH 07/16] feat(detail): model creators as an ordered list of rows The detail model reads creators from every CSL name role into keyed rows, keeps keys across reloads, and saves the whole ordered list in one PATCH. --- frontend/src/engine/detail.ts | 80 ++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/frontend/src/engine/detail.ts b/frontend/src/engine/detail.ts index 0a9649c..a371b4d 100644 --- a/frontend/src/engine/detail.ts +++ b/frontend/src/engine/detail.ts @@ -8,7 +8,6 @@ export interface FieldSpec { key: string; label: string; kind: FieldKind; sendKe export const FIELDS: FieldSpec[] = [ { key: 'type', label: 'Type', kind: 'type', sendKey: 'type' }, { key: 'title', label: 'Title', kind: 'line', sendKey: 'title' }, - { key: 'author', label: 'Creators', kind: 'line', sendKey: 'author' }, { key: 'issued', label: 'Date', kind: 'line', sendKey: 'issued' }, { key: 'container-title', label: 'Container', kind: 'line', sendKey: 'container-title' }, { key: 'volume', label: 'Volume', kind: 'line', sendKey: 'volume' }, @@ -24,6 +23,59 @@ export const TYPES = [ 'report', 'thesis', 'webpage', 'dataset', 'software', 'manuscript', 'article', 'document', ]; +export const ROLES = [ + 'author', 'editor', 'translator', 'container-author', 'collection-editor', 'composer', 'director', + 'editorial-director', 'illustrator', 'interviewer', 'original-author', 'recipient', 'reviewed-author', + 'chair', 'compiler', 'contributor', 'curator', 'executive-producer', 'guest', 'host', 'narrator', + 'organizer', 'performer', 'producer', 'script-writer', 'series-creator', +]; + +export interface Creator { key: string; role: string; family: string; given: string; literal: string; single: boolean } + +let creatorSeq = 0; +export function newCreator(role = 'author'): Creator { + return { key: `c${++creatorSeq}`, role, family: '', given: '', literal: '', single: false }; +} + +export function creatorBlank(c: Creator): boolean { + return c.single ? !c.literal.trim() : !c.family.trim() && !c.given.trim(); +} + +function sameCreator(a: Creator, b: Creator): boolean { + return a.role === b.role && a.single === b.single && a.family === b.family && a.given === b.given && a.literal === b.literal; +} + +function readCreators(item: ItemDetail): Creator[] { + const out: Creator[] = []; + const csl = item.csl ?? {}; + for (const role of ROLES) { + const list = csl[role]; + if (!Array.isArray(list)) continue; + for (const n of list as CslName[]) { + const literal = n.literal ?? ''; + out.push({ ...newCreator(role), family: n.family ?? '', given: n.given ?? '', literal, single: !!literal && !n.family && !n.given }); + } + } + return out; +} + +function creatorFields(next: Creator[], before: Creator[]): Record { + const fields: Record = {}; + for (const c of before) fields[c.role] = ''; + for (const c of next) { + if (creatorBlank(c)) continue; + const name: CslName = c.single ? { literal: c.literal.trim() } : {}; + if (!c.single) { + if (c.family.trim()) name.family = c.family.trim(); + if (c.given.trim()) name.given = c.given.trim(); + } + const list = Array.isArray(fields[c.role]) ? (fields[c.role] as CslName[]) : []; + list.push(name); + fields[c.role] = list; + } + return fields; +} + function nameText(n: CslName): string { if (n.literal) return n.literal; return [n.family, n.given].filter(Boolean).join(', '); @@ -64,6 +116,7 @@ export class DetailModel { private seq = 0; private abort: AbortController | null = null; current: ItemDetail | null = null; + creators: Creator[] = []; constructor(private readonly library: Library, private readonly out: DetailListener) { library.events.on('selected', (id) => { void this.load(id); }); @@ -82,6 +135,7 @@ export class DetailModel { try { const item = await detailApi.item(id, ctl.signal); if (mine !== this.seq) return; + this.creators = this.reconcile(item); this.current = item; this.out.item(item); this.out.state('ready', ''); @@ -103,6 +157,30 @@ export class DetailModel { return true; } + private reconcile(item: ItemDetail): Creator[] { + const fresh = readCreators(item); + if (item.id !== this.current?.id) return fresh; + const pool = [...this.creators]; + const matched = fresh.map((c) => { + const i = pool.findIndex((p) => sameCreator(p, c)); + return i < 0 ? c : { ...c, key: pool.splice(i, 1)[0].key }; + }); + if (pool.length || matched.some((c) => !this.creators.some((p) => p.key === c.key))) return matched; + return this.creators.map((p) => matched.find((c) => c.key === p.key) ?? p); + } + + async saveCreators(next: Creator[]): Promise { + const item = this.current; + if (!item) return []; + const kept = next.filter((c) => !creatorBlank(c)).map((c) => ({ ...c })); + const same = kept.length === this.creators.length && kept.every((c, i) => c.key === this.creators[i].key && sameCreator(c, this.creators[i])); + if (same) return this.creators; + const updated = await detailApi.editFields(item.id, creatorFields(kept, this.creators)); + if (this.current?.id === item.id) { this.current = updated; this.creators = kept; } + this.library.itemChanged(item.id); + return kept; + } + async addTag(name: string): Promise { const item = this.current; const clean = name.trim(); From e997b233e9b1f17284a9617d6d99980ea6a04228 Mon Sep 17 00:00:00 2001 From: nodemode-ai Date: Fri, 27 Nov 2026 14:12:45 -0500 Subject: [PATCH 08/16] feat(detail): structured creators box in the item pane The one-line creators field is replaced by a fixed-height scrolling box with a row per creator, role select, institution toggle, reorder and a confirmed remove. --- frontend/src/styles/detail.css | 15 +++ frontend/src/ui/detail.ts | 216 ++++++++++++++++++++++++++++++++- 2 files changed, 230 insertions(+), 1 deletion(-) diff --git a/frontend/src/styles/detail.css b/frontend/src/styles/detail.css index fabeef5..cb12a91 100644 --- a/frontend/src/styles/detail.css +++ b/frontend/src/styles/detail.css @@ -40,6 +40,21 @@ .fc-dt-row.is-error .fc-dt-mark { background: var(--danger); } .fc-dt-row.is-error .fc-dt-input { border-color: var(--danger); } +.fc-dt-cr-sec { --dt-cr-h: 120px; --dt-cr-btn: 22px; --dt-cr-role-w: 96px; display: flex; flex-direction: column; gap: var(--space-1); flex: none; } +.fc-dt-cr-head { display: flex; align-items: center; justify-content: space-between; height: var(--dt-row-h); } +.fc-dt-cr-head.is-saving .fc-dt-mark { background: var(--text-muted); } +.fc-dt-cr-box { display: flex; flex-direction: column; gap: var(--space-1); box-sizing: border-box; height: var(--dt-cr-h); padding: var(--space-1); overflow: auto; border: 1px solid var(--line-1); border-radius: var(--radius-sm); } +.fc-dt-cr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) var(--dt-cr-role-w) repeat(4, var(--dt-cr-btn)); align-items: center; gap: var(--space-1); flex: none; height: var(--dt-row-h); } +.fc-dt-cr.is-single .fc-dt-cr-family { grid-column: 1 / 3; } +.fc-dt-cr.is-single .fc-dt-cr-given { display: none; } +.fc-dt-cr.is-error .fc-dt-input { border-color: var(--danger); } +.fc-dt-cr-btn { display: inline-grid; place-items: center; width: var(--dt-cr-btn); height: var(--dt-cr-btn); padding: 0; border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; color: var(--text-muted); cursor: pointer; } +.fc-dt-cr-btn:hover { color: var(--text-primary); background: var(--bg-hover); } +.fc-dt-cr-single[aria-pressed="true"] { color: var(--accent-color); border-color: var(--line-2); } +.fc-dt-cr-x.is-armed { border-color: var(--danger); color: var(--danger-text); } +.fc-dt-cr:first-child .fc-dt-cr-up, .fc-dt-cr:last-child .fc-dt-cr-down { visibility: hidden; } +.fc-dt-cr-foot { display: flex; height: var(--dt-row-h); } + .fc-dt-sec { display: flex; flex-direction: column; gap: var(--space-1); } .fc-dt-sec-title { display: flex; gap: var(--space-2); height: var(--dt-row-h); align-items: center; margin: 0; font-size: var(--fs-12); font-weight: 600; color: var(--text-muted); } .fc-dt-count { display: inline-block; min-width: 3ch; font-weight: 400; font-variant-numeric: tabular-nums; } diff --git a/frontend/src/ui/detail.ts b/frontend/src/ui/detail.ts index a839eff..c3d01a8 100644 --- a/frontend/src/ui/detail.ts +++ b/frontend/src/ui/detail.ts @@ -1,5 +1,5 @@ import type { Engine } from '../engine'; -import { DetailModel, FIELDS, TYPES, fieldText, sizeText, type DetailState, type FieldSpec } from '../engine/detail'; +import { DetailModel, FIELDS, ROLES, TYPES, creatorBlank, fieldText, newCreator, sizeText, type Creator, type DetailState, type FieldSpec } from '../engine/detail'; import type { Attachment, ItemDetail, Note } from '../io/detail'; import { delayedIndicator, el, escapeHtml, patchList, q, setClass, setDisabled, setHidden, setText, setTitle, setValue, type Disposer } from './dom'; import { toast } from './toast'; @@ -8,8 +8,58 @@ const ICON = { trash: '', open: '', remove: '', + up: '', + down: '', + org: '', + add: '', }; +const ROLE_OPTIONS = ROLES.map((r) => ``).join(''); + +const CREATORS = `
+
Creators
+
+
+ +
`; + +function creatorRow(c: Creator): HTMLElement { + const node = el(`
+ + + + + + + +
`); + fillCreator(node, c); + return node; +} + +function fillCreator(node: HTMLElement, c: Creator): void { + const family = q(node, '.fc-dt-cr-family'); + const given = q(node, '.fc-dt-cr-given'); + const role = q(node, '.fc-dt-cr-role'); + setClass(node, 'is-single', c.single); + const single = q(node, '.fc-dt-cr-single'); + if (single.getAttribute('aria-pressed') !== String(c.single)) single.setAttribute('aria-pressed', String(c.single)); + const famText = c.single ? c.literal : c.family; + if (family.value !== famText) family.value = famText; + if (given.value !== c.given) given.value = c.given; + const ph = c.single ? 'Institution name' : 'Family'; + if (family.placeholder !== ph) family.placeholder = ph; + if (role.value !== c.role) role.value = c.role; + setClass(node, 'is-error', false); +} + +function readRow(node: HTMLElement, base: Creator): Creator { + const family = q(node, '.fc-dt-cr-family').value; + const given = q(node, '.fc-dt-cr-given').value; + const role = q(node, '.fc-dt-cr-role').value; + return base.single ? { ...base, role, literal: family, given: '', family: '' } : { ...base, role, family, given, literal: '' }; +} + type Control = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement; interface Row { spec: FieldSpec; node: HTMLElement; control: Control; busy: Disposer | null } @@ -80,6 +130,169 @@ export function mountDetail(engine: Engine, host: HTMLElement): void { return { spec, node, control: q(node, '.fc-dt-input'), busy: null }; }); + const crSec = el(CREATORS); + (rows.find((r) => r.spec.key === 'title')?.node ?? fieldsHost.firstElementChild)?.after(crSec); + const crBox = q(crSec, '.fc-dt-cr-box'); + const crError = q(crSec, '.fc-dt-cr-error'); + const crHead = q(crSec, '.fc-dt-cr-head'); + const showCrError = (text: string): void => { setText(crError, text); setTitle(crError, text); }; + let draft: Creator[] = []; + let draftFor = ''; + let crBusy: Disposer | null = null; + + function paintCreators(): void { + const id = model.current?.id ?? ''; + const saved = model.creators.map((c) => ({ ...c })); + const extra = id === draftFor ? draft.filter((d) => !saved.some((s) => s.key === d.key) && !model.creators.some((s) => s.key === d.key) && creatorBlank(d)) : []; + draftFor = id; + draft = [...saved, ...extra]; + patchList(crBox, draft, { key: (c) => c.key, create: creatorRow, update: fillCreator }); + } + + const nodeOf = (key: string): HTMLElement | null => crBox.querySelector(`.fc-dt-cr[data-key="${CSS.escape(key)}"]`); + const indexOf = (node: HTMLElement): number => draft.findIndex((c) => c.key === node.dataset.key); + + function syncDraft(): void { + for (const node of crBox.querySelectorAll('.fc-dt-cr')) { + const i = indexOf(node); + if (i >= 0) draft[i] = readRow(node, draft[i]); + } + } + + async function saveCreators(next: Creator[], row: HTMLElement | null): Promise { + crBusy?.(); + crBusy = delayedIndicator(() => setClass(crHead, 'is-saving', true), () => setClass(crHead, 'is-saving', false)); + draft = next; + try { + await model.saveCreators(next); + showCrError(''); + paintCreators(); + } catch (err) { + const msg = err instanceof Error ? err.message : String(err); + showCrError(`Creators: ${msg}`); + draft = model.creators.map((c) => ({ ...c })); + patchList(crBox, draft, { key: (c) => c.key, create: creatorRow, update: fillCreator }); + if (row?.isConnected) setClass(row, 'is-error', true); + } finally { + crBusy?.(); + crBusy = null; + } + } + + function commitRow(node: HTMLElement): void { + if (!model.current) return; + syncDraft(); + const i = indexOf(node); + if (i < 0) return; + if (creatorBlank(draft[i]) && !model.creators.some((c) => c.key === draft[i].key)) return; + void saveCreators([...draft], node); + } + + function addCreator(): void { + if (!model.current) return; + syncDraft(); + const c = newCreator(draft.length ? draft[draft.length - 1].role : 'author'); + draft.push(c); + patchList(crBox, draft, { key: (x) => x.key, create: creatorRow, update: fillCreator }); + const node = nodeOf(c.key); + if (node) { q(node, '.fc-dt-cr-family').focus(); node.scrollIntoView({ block: 'nearest' }); } + } + + function moveRow(node: HTMLElement, by: number): void { + syncDraft(); + const i = indexOf(node); + const j = i + by; + if (i < 0 || j < 0 || j >= draft.length) return; + const next = [...draft]; + [next[i], next[j]] = [next[j], next[i]]; + draft = next; + patchList(crBox, draft, { key: (x) => x.key, create: creatorRow, update: fillCreator }); + node.scrollIntoView({ block: 'nearest' }); + void saveCreators(next, node); + } + + const crArmed = new Map(); + function removeRow(node: HTMLElement, btn: HTMLElement): void { + const key = node.dataset.key ?? ''; + const disarm = (): void => { clearTimeout(crArmed.get(key)); crArmed.delete(key); setClass(btn, 'is-armed', false); setTitle(btn, 'Remove creator'); }; + if (!crArmed.has(key)) { + setClass(btn, 'is-armed', true); + setTitle(btn, 'Click again to remove'); + crArmed.set(key, window.setTimeout(disarm, 3000)); + return; + } + disarm(); + syncDraft(); + const next = draft.filter((c) => c.key !== key); + draft = next; + patchList(crBox, draft, { key: (x) => x.key, create: creatorRow, update: fillCreator }); + void saveCreators(next, null); + } + + function toggleSingle(node: HTMLElement): void { + syncDraft(); + const i = indexOf(node); + if (i < 0) return; + const c = draft[i]; + draft[i] = c.single + ? { ...c, single: false, family: c.literal, given: '', literal: '' } + : { ...c, single: true, literal: [c.given, c.family].filter((s) => s.trim()).join(' '), family: '', given: '' }; + fillCreator(node, draft[i]); + q(node, '.fc-dt-cr-family').focus(); + if (!creatorBlank(draft[i])) void saveCreators([...draft], node); + } + + q(crSec, '.fc-dt-cr-add').addEventListener('click', addCreator); + crBox.addEventListener('click', (e) => { + const btn = (e.target as Element).closest('.fc-dt-cr-btn'); + const node = btn?.closest('.fc-dt-cr'); + if (!btn || !node || !model.current) return; + if (btn.classList.contains('fc-dt-cr-up')) moveRow(node, -1); + else if (btn.classList.contains('fc-dt-cr-down')) moveRow(node, 1); + else if (btn.classList.contains('fc-dt-cr-x')) removeRow(node, btn); + else if (btn.classList.contains('fc-dt-cr-single')) toggleSingle(node); + }); + crBox.addEventListener('change', (e) => { + const node = (e.target as Element).closest('.fc-dt-cr'); + if (node && (e.target as Element).classList.contains('fc-dt-cr-role')) commitRow(node); + }); + crBox.addEventListener('focusout', (e) => { + const node = (e.target as Element).closest('.fc-dt-cr'); + const to = e.relatedTarget as Node | null; + if (!node || (to && node.contains(to))) return; + if (!(e.target instanceof HTMLInputElement)) return; + syncDraft(); + const i = indexOf(node); + if (i >= 0 && creatorBlank(draft[i]) && !model.creators.some((c) => c.key === draft[i].key)) { + draft.splice(i, 1); + node.remove(); + return; + } + commitRow(node); + }); + crBox.addEventListener('keydown', (e) => { + const target = e.target as HTMLElement; + const node = target.closest('.fc-dt-cr'); + if (!node || !(target instanceof HTMLInputElement || target instanceof HTMLSelectElement)) return; + if (e.key === 'Escape') { + const saved = model.creators.find((c) => c.key === node.dataset.key); + const i = indexOf(node); + if (saved && i >= 0) { draft[i] = { ...saved }; fillCreator(node, saved); } + else if (i >= 0) { draft.splice(i, 1); node.remove(); } + showCrError(''); + target.blur(); + } else if (e.key === 'Enter' && target instanceof HTMLInputElement) { + e.preventDefault(); + const last = node === crBox.lastElementChild; + commitRow(node); + if (last && (target.classList.contains('fc-dt-cr-given') || node.classList.contains('is-single'))) addCreator(); + } else if (e.altKey && (e.key === 'ArrowUp' || e.key === 'ArrowDown')) { + e.preventDefault(); + moveRow(node, e.key === 'ArrowUp' ? -1 : 1); + target.focus(); + } + }); + let loadBusy: Disposer | null = null; const showError = (text: string): void => { setText(error, text); setTitle(error, text); }; @@ -108,6 +321,7 @@ export function mountDetail(engine: Engine, host: HTMLElement): void { } else setValue(r.control, text); setClass(r.node, 'is-error', false); } + paintCreators(); paintTags(item.tags); paintAttachments(item.attachments ?? []); paintNotes(item.notes ?? []); From 47898b08fda26070a81812df2c1968a0f8e1fe76 Mon Sep 17 00:00:00 2001 From: nodemode-ai Date: Fri, 27 Nov 2026 14:20:04 -0500 Subject: [PATCH 09/16] fix(detail): save a creator row when focus leaves its role select Leaving a creator row from the role select now saves the row, and reordering swaps the two rows' contents in place so no row node moves. --- frontend/src/ui/detail.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/frontend/src/ui/detail.ts b/frontend/src/ui/detail.ts index c3d01a8..5455e8f 100644 --- a/frontend/src/ui/detail.ts +++ b/frontend/src/ui/detail.ts @@ -206,8 +206,14 @@ export function mountDetail(engine: Engine, host: HTMLElement): void { const next = [...draft]; [next[i], next[j]] = [next[j], next[i]]; draft = next; - patchList(crBox, draft, { key: (x) => x.key, create: creatorRow, update: fillCreator }); - node.scrollIntoView({ block: 'nearest' }); + const other = nodeOf(next[i].key); + if (other) { + other.dataset.key = next[j].key; + node.dataset.key = next[i].key; + fillCreator(node, next[i]); + fillCreator(other, next[j]); + other.scrollIntoView({ block: 'nearest' }); + } void saveCreators(next, node); } @@ -260,7 +266,6 @@ export function mountDetail(engine: Engine, host: HTMLElement): void { const node = (e.target as Element).closest('.fc-dt-cr'); const to = e.relatedTarget as Node | null; if (!node || (to && node.contains(to))) return; - if (!(e.target instanceof HTMLInputElement)) return; syncDraft(); const i = indexOf(node); if (i >= 0 && creatorBlank(draft[i]) && !model.creators.some((c) => c.key === draft[i].key)) { @@ -288,8 +293,11 @@ export function mountDetail(engine: Engine, host: HTMLElement): void { if (last && (target.classList.contains('fc-dt-cr-given') || node.classList.contains('is-single'))) addCreator(); } else if (e.altKey && (e.key === 'ArrowUp' || e.key === 'ArrowDown')) { e.preventDefault(); + const key = node.dataset.key ?? ''; moveRow(node, e.key === 'ArrowUp' ? -1 : 1); - target.focus(); + const moved = nodeOf(key); + const cls = Array.from(target.classList).find((c) => c.startsWith('fc-dt-cr-')); + if (moved && cls) q(moved, `.${cls}`).focus(); } }); From 9df7f9e21d3cd4d07068edd362ff2f17b710c4ae Mon Sep 17 00:00:00 2001 From: nodemode-ai Date: Fri, 27 Nov 2026 14:24:08 -0500 Subject: [PATCH 10/16] docs(window): describe never-loaded removes and batched adds WINDOW.md now says when the list still re-reads after a remove or add. --- docs/WINDOW.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/WINDOW.md b/docs/WINDOW.md index e50c192..8474237 100644 --- a/docs/WINDOW.md +++ b/docs/WINDOW.md @@ -21,7 +21,7 @@ The **Items** view has three panes side by side. - Columns: title, creator, year, type and date added. Click a column head to sort by it, click again to reverse. - The search box filters the list by words in titles, creators, container titles, abstracts, notes and tags. - Click a row or use the arrow keys to select it. The list stays smooth with thousands of items: only the rows on screen exist, and scrolling rewrites them. -- When an item is added or restored, the window asks the engine where that one row falls in the current list (`GET /api/library/rows/{id}/position`) and inserts only that row. When an item is removed, the rows below move up and only rows that were not yet loaded are fetched. If the engine cannot say where a row falls, or a removed item was never loaded, the list is read again. +- When an item is added or restored, the window asks the engine where that one row falls in the current list (`GET /api/library/rows/{id}/position`) and inserts only that row. When an item is removed, the rows below move up and only rows that were not yet loaded are fetched. A removed item the window never loaded is asked for with `include_trashed=true`, which answers where the trashed item sat in the same sort and filter. Several ids in one change are placed in one pass. An unknown id (404 with the engine's `detail`) is skipped on add. The list is read again only when the engine is older (405, or a bare `Not Found`), when an item was deleted for good before the window placed it, or when the count the engine returns does not agree, which today includes a never-loaded remove under a search filter. - The creator column shows the first author, "A and B" for two authors, or "A et al." for more. Items with no year sort after the rest. ### Detail pane (right) From a5f0f9d56d2d6f449521d690beb5a0e8751939fc Mon Sep 17 00:00:00 2001 From: nodemode-ai Date: Fri, 27 Nov 2026 14:24:08 -0500 Subject: [PATCH 11/16] docs(itemlist): log the one-pass shift and the trashed position Both logs record the include_trashed ranking, the unknown id rule and the checked numbers. --- backend/HASHOUT_LOG.md | 4 ++++ frontend/HASHOUT_LOG.md | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/backend/HASHOUT_LOG.md b/backend/HASHOUT_LOG.md index b9c5f93..018418d 100644 --- a/backend/HASHOUT_LOG.md +++ b/backend/HASHOUT_LOG.md @@ -1661,3 +1661,7 @@ New in v0.7.0 (2026-11-27). `POST /api/library/identify/upload?name=` reads the ## app/routers/window.py, app/services/window_rows.py {#app-window-row-position} New in v0.8.0 (2026-11-27). `GET /api/library/rows/{id}/position` takes the same `scope`, `id`, `q`, `sort` and `desc` as `GET /api/library/rows` and returns `{index, total}`. The index is `ROW_NUMBER() OVER (ORDER BY ...) - 1` built from the same `SORTS` expression, direction and `i.id` tie-break, under the same `_where`, so it can never disagree with the rows route. It is `-1` when the item exists but is outside the scope or filter (a trashed item is always `-1`), and the route answers 404 when no item has that id. Checked against `list_rows` on 2,002 items: year descending at offsets 700 to 702 and title with `q=river` at offsets 100 and 101 all matched. + +## app/routers/window.py, app/services/window_rows.py {#app-window-position-trashed} + +New in v0.9.0 (2026-11-27). `include_trashed=true` on the position route replaces the first `_where` clause (`i.trashed_at IS NULL`) with `(i.trashed_at IS NULL OR i.id = ?)` for the ranking only, so a just-trashed item is ranked among the live rows under the same `SORTS` order and `i.id` tie-break, and `total` still counts live rows. The answer then carries `include_trashed: true` so a window can tell an engine that ignored the flag. A purged item has no row and answers 404 `no item {id}`; Starlette's missing-route 404 says `Not Found`, which is how the window tells them apart. diff --git a/frontend/HASHOUT_LOG.md b/frontend/HASHOUT_LOG.md index d7a9c17..84e9862 100644 --- a/frontend/HASHOUT_LOG.md +++ b/frontend/HASHOUT_LOG.md @@ -408,3 +408,7 @@ New in v0.8.0 (2026-11-27). The engine stores an empty title without complaint, ## src/io/detail.ts, src/engine/detail.ts, src/ui/detail.ts, src/styles/detail.css {#src-detail-notes} New in v0.8.0 (2026-11-27). Notes are editable in the pane through `POST /api/library/items/{id}/notes`, `PATCH /api/library/notes/{id}` and `DELETE /api/library/notes/{id}`, each with `{body}`. Each note is a one-line textarea inside the fixed-height notes box; it saves on blur or Ctrl or Cmd plus Enter, Escape puts back the stored text (kept in `data-saved`), and an empty edit is refused with a sentence in the reserved `.fc-dt-note-error` line. A line under the box adds a note on Enter. Delete asks for a second click within 3 seconds and its label box is sized for "Confirm", so the icon does not move. Notes are shown and sent as plain text: an HTML body from an import is flattened the first time it is saved. Checked in a fresh copy from HEAD with the 2,000-item library under CPU 4x, 400 ms and about 400 kbit/s: add, edit, Escape, delete and a reload all held, the box height did not change, and layout shift was 0 with and without input. + +## src/engine/itemlist.ts, src/io/itemlist.ts {#src-itemlist-one-pass} + +New in v0.9.0 (2026-11-27). `remove` and `insert` run through one queue so two notices never shift the cache at once. A removed id the cache never loaded is asked for with `fetchPosition(id, where, true)` (`include_trashed=true`); all answers come back together, the indices are sorted and the cache shifts once, then `ensure` reads only the holes. Adds and restores ask every position at once, check that the returned total grew by the number placed, read the rows with `GET /api/library/rows/{id}` in parallel and shift once. `fetchPosition` answers `unknown` for a 404 whose `detail` is not Starlette's bare `Not Found`, and `null` (older engine) for a 405, a bare `Not Found`, or a trashed ask whose answer lacks `include_trashed: true`. Unknown ids are skipped on add; on remove they mean the item was purged and its place cannot be known, so the list re-reads. Under a search filter a trashed item no longer matches the search index, the position comes back -1, the total check sees the count fell anyway and the list re-reads. Checked in a private built copy (with a `window.__fc` hook added only in the copy) with 2,000 items, CPU 4x, 400 ms and 50 kB/s, added-descending sort: never-loaded remove in all and in a tag, three removes and three restores in all, a 500-item collection, a 300-item tag and a `ledger` filter, and three adds in all, each with no `limit=200` read, zero pool nodes added or removed, pool 55, cached and painted ids equal to the engine's rows at the scroll top, scroll top and selection kept, and layout shift 0 with and without input except 0.0002 without input once in the collection. From 7fa839f0914f4db1fbacd63c286fe3b9eeca1712 Mon Sep 17 00:00:00 2001 From: nodemode-ai Date: Fri, 27 Nov 2026 14:24:15 -0500 Subject: [PATCH 12/16] fix(side): stop rewriting unchanged tag attributes and keep focus on list patches Tag and collection rows write data and aria-current only when the value changes, a tag rename moves the row to its sorted place at once, and focus is restored when a list patch or rename moves the focused row. --- frontend/src/ui/side.ts | 61 ++++++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/frontend/src/ui/side.ts b/frontend/src/ui/side.ts index 9d82ecd..50d0585 100644 --- a/frontend/src/ui/side.ts +++ b/frontend/src/ui/side.ts @@ -60,16 +60,32 @@ function markActive(pane: Pane, scope: Scope): void { } } +function setData(node: HTMLElement, key: string, value: string): void { + if (node.dataset[key] !== value) node.dataset[key] = value; +} + +function setCurrent(node: HTMLElement, on: boolean): void { + setClass(node, 'is-active', on); + const btn = node.querySelector('.fc-side-entry'); + if (btn && btn.getAttribute('aria-current') !== String(on)) btn.setAttribute('aria-current', String(on)); +} + +function keepFocus(run: () => void): void { + const was = document.activeElement as HTMLElement | null; + run(); + if (was && was !== document.body && document.activeElement !== was && was.isConnected) was.focus({ preventScroll: true }); +} + function updateCollection(node: HTMLElement, entry: TreeEntry, pane: Pane): void { setText(node.querySelector('.fc-side-name'), entry.name); setText(node.querySelector('.fc-side-count'), formatCount(entry.count)); setStyleVar(node, '--fc-side-depth', String(entry.depth)); - node.dataset.scope = scopeKey({ kind: 'collection', id: entry.id }); - node.dataset.name = entry.name; - node.dataset.parent = entry.parentId ?? ''; + setData(node, 'scope', scopeKey({ kind: 'collection', id: entry.id })); + setData(node, 'name', entry.name); + setData(node, 'parent', entry.parentId ?? ''); const btn = node.querySelector('.fc-side-entry'); if (btn && btn.getAttribute('aria-level') !== String(entry.depth + 1)) btn.setAttribute('aria-level', String(entry.depth + 1)); - setClass(node, 'is-active', node.dataset.scope === scopeKey(pane.engine.library.scope)); + setCurrent(node, node.dataset.scope === scopeKey(pane.engine.library.scope)); } function treeRows(pane: Pane): HTMLElement[] { @@ -143,11 +159,11 @@ async function loadCollections(pane: Pane): Promise { const done = pendingClass(pane.tree); try { const entries = flattenTree(await sideApi.collections()); - patchList(pane.tree, entries, { + keepFocus(() => patchList(pane.tree, entries, { key: (e) => e.id, create: (e) => { const n = rowShell('collection', 'folder'); updateCollection(n, e, pane); return n; }, update: (n, e) => updateCollection(n, e, pane), - }); + })); applyTree(pane); setText(pane.collMsg, entries.length ? '' : 'No collections yet.'); setClass(pane.collMsg, 'is-error', false); @@ -162,20 +178,20 @@ async function loadCollections(pane: Pane): Promise { function updateTag(node: HTMLElement, tag: TagRow, pane: Pane): void { setText(node.querySelector('.fc-side-name'), tag.name); setText(node.querySelector('.fc-side-count'), formatCount(tag.item_count)); - node.dataset.scope = scopeKey({ kind: 'tag', id: tag.id }); - node.dataset.name = tag.name; - setClass(node, 'is-active', node.dataset.scope === scopeKey(pane.engine.library.scope)); + setData(node, 'scope', scopeKey({ kind: 'tag', id: tag.id })); + setData(node, 'name', tag.name); + setCurrent(node, node.dataset.scope === scopeKey(pane.engine.library.scope)); } async function loadTags(pane: Pane): Promise { const done = pendingClass(pane.tags); try { const tags = sortTags(await sideApi.tags()); - patchList(pane.tags, tags, { + keepFocus(() => patchList(pane.tags, tags, { key: (t) => t.id, create: (t) => { const n = rowShell('tag', 'tag'); updateTag(n, t, pane); return n; }, update: (n, t) => updateTag(n, t, pane), - }); + })); setText(pane.tagMsg, tags.length ? '' : 'No tags yet.'); setClass(pane.tagMsg, 'is-error', false); } catch (err) { @@ -240,6 +256,13 @@ function endEdit(row: HTMLElement): void { if (input) input.tabIndex = -1; } +function placeTag(pane: Pane, row: HTMLElement, name: string): void { + const others = (Array.from(pane.tags.children) as HTMLElement[]).filter((r) => r !== row); + const next = others.find((r) => (r.dataset.name ?? '').localeCompare(name, undefined, { sensitivity: 'base' }) > 0) ?? null; + if (next === row.nextElementSibling) return; + keepFocus(() => pane.tags.insertBefore(row, next)); +} + async function commitRename(pane: Pane, row: HTMLElement): Promise { const input = row.querySelector('.fc-side-edit'); if (!input || !row.classList.contains('is-editing')) return; @@ -248,17 +271,23 @@ async function commitRename(pane: Pane, row: HTMLElement): Promise { const id = row.dataset.key ?? ''; if (!name || name === row.dataset.name) return; const lib = pane.engine.library; + const before = row.dataset.name ?? ''; + const tagged = row.dataset.kind === 'tag'; + if (tagged) { setData(row, 'name', name); setText(row.querySelector('.fc-side-name'), name); placeTag(pane, row, name); } try { if (row.dataset.kind === 'collection') await sideApi.renameCollection(id, name); else await sideApi.renameTag(id, name); row.dataset.name = name; setText(row.querySelector('.fc-side-name'), name); - if (row.classList.contains('is-active')) { - lib.setScope({ kind: row.dataset.kind === 'tag' ? 'tag' : 'collection', id, label: name }); - } - if (row.dataset.kind === 'collection') lib.collectionsChanged(); - else lib.tagsChanged(); + keepFocus(() => { + if (row.classList.contains('is-active')) { + lib.setScope({ kind: row.dataset.kind === 'tag' ? 'tag' : 'collection', id, label: name }); + } + if (row.dataset.kind === 'collection') lib.collectionsChanged(); + else lib.tagsChanged(); + }); } catch (err) { + if (tagged) { setData(row, 'name', before); setText(row.querySelector('.fc-side-name'), before); placeTag(pane, row, before); } showError(pane, row, err); } } From 892ef35ef4cf6368047b0d430422fb36c2da9ffd Mon Sep 17 00:00:00 2001 From: nodemode-ai Date: Fri, 27 Nov 2026 14:24:27 -0500 Subject: [PATCH 13/16] docs(hashout): tag list measurement and title rule Log the side pane tag measurement and the title-required rule. --- backend/HASHOUT_LOG.md | 4 ++++ frontend/HASHOUT_LOG.md | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/backend/HASHOUT_LOG.md b/backend/HASHOUT_LOG.md index 018418d..d124dfb 100644 --- a/backend/HASHOUT_LOG.md +++ b/backend/HASHOUT_LOG.md @@ -1665,3 +1665,7 @@ New in v0.8.0 (2026-11-27). `GET /api/library/rows/{id}/position` takes the same ## app/routers/window.py, app/services/window_rows.py {#app-window-position-trashed} New in v0.9.0 (2026-11-27). `include_trashed=true` on the position route replaces the first `_where` clause (`i.trashed_at IS NULL`) with `(i.trashed_at IS NULL OR i.id = ?)` for the ranking only, so a just-trashed item is ranked among the live rows under the same `SORTS` order and `i.id` tie-break, and `total` still counts live rows. The answer then carries `include_trashed: true` so a window can tell an engine that ignored the flag. A purged item has no row and answers 404 `no item {id}`; Starlette's missing-route 404 says `Not Found`, which is how the window tells them apart. + +## app/store/items.py {#app-items-title-required} + +New in v0.9.0 (2026-11-27). `create` refuses a title that is empty or only white space with `Invalid("A title is required.")` (HTTP 422 through the routers, a line on stderr in the CLI) when no `batch_id` is given, which is every interactive path (`POST /api/library/items`, `item add`, the MCP add tool); `update` refuses it only when the item holds a non-blank title, so an old title-less item can still be edited in other fields. The model has no type that exempts a title (`title` is TEXT for ALL types in `record/fields.py`), so the rule covers every type, as the window already did. Import, lookup and identify pass a `batch_id` and keep their old behaviour: a BibTeX, RIS and CSL JSON entry with no title still imports with an empty title (checked: 2 of 2, 2 of 2 and 1 of 1 added, 0 failed). The twelve style regression cases pass. diff --git a/frontend/HASHOUT_LOG.md b/frontend/HASHOUT_LOG.md index 84e9862..61a32bf 100644 --- a/frontend/HASHOUT_LOG.md +++ b/frontend/HASHOUT_LOG.md @@ -412,3 +412,7 @@ New in v0.8.0 (2026-11-27). Notes are editable in the pane through `POST /api/li ## src/engine/itemlist.ts, src/io/itemlist.ts {#src-itemlist-one-pass} New in v0.9.0 (2026-11-27). `remove` and `insert` run through one queue so two notices never shift the cache at once. A removed id the cache never loaded is asked for with `fetchPosition(id, where, true)` (`include_trashed=true`); all answers come back together, the indices are sorted and the cache shifts once, then `ensure` reads only the holes. Adds and restores ask every position at once, check that the returned total grew by the number placed, read the rows with `GET /api/library/rows/{id}` in parallel and shift once. `fetchPosition` answers `unknown` for a 404 whose `detail` is not Starlette's bare `Not Found`, and `null` (older engine) for a 405, a bare `Not Found`, or a trashed ask whose answer lacks `include_trashed: true`. Unknown ids are skipped on add; on remove they mean the item was purged and its place cannot be known, so the list re-reads. Under a search filter a trashed item no longer matches the search index, the position comes back -1, the total check sees the count fell anyway and the list re-reads. Checked in a private built copy (with a `window.__fc` hook added only in the copy) with 2,000 items, CPU 4x, 400 ms and 50 kB/s, added-descending sort: never-loaded remove in all and in a tag, three removes and three restores in all, a 500-item collection, a 300-item tag and a `ledger` filter, and three adds in all, each with no `limit=200` read, zero pool nodes added or removed, pool 55, cached and painted ids equal to the engine's rows at the scroll top, scroll top and selection kept, and layout shift 0 with and without input except 0.0002 without input once in the collection. + +## src/ui/side.ts {#src-side-tags-measured} + +New in v0.9.0 (2026-11-27). The tag list was measured with 28 to 31 real tags on a 2,000-item library (a few hundred items tagged), CPU 4x, 400 ms and 50 kB/s, fresh engine. First fill: 30 rows inserted at once, 35 to 39 mutations in the pane, layout shift 0. `data-scope`, `data-name`, `data-parent` and `aria-current` were being rewritten on every row at every refresh (95 mutations for one scope pick, 64 for one delete); they now go through `setData` and `setCurrent`, which write only a changed value, and new rows get `aria-current` when built (60 and 8). A rename moves the row to its sorted place at the click through `placeTag` (reverted on an error), so the later refresh finds the order already right. `keepFocus` puts focus back on the focused node when a list patch or the post-rename scope change moves it. Still seen: after a rename under throttle, focus was lost to the body once in three runs about a second after the answer, from something outside `ui/side.ts` that was not found; a brand-new tag added from the item pane inserts a row in sorted place and shifts the rows below by 0.0013 without input; adding an existing tag only raises its count in place (20 to 21, shift 0). From 7078a758cf71e3aaac4ac02b08dc7964307e48a3 Mon Sep 17 00:00:00 2001 From: nodemode-ai Date: Fri, 27 Nov 2026 14:25:25 -0500 Subject: [PATCH 14/16] fix(detail): lay each creator row out on two lines Names take the first line and role with the row controls the second, so family and given names stay readable in the narrow pane; the box is a fixed 144 px. --- frontend/src/styles/detail.css | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/frontend/src/styles/detail.css b/frontend/src/styles/detail.css index cb12a91..992c401 100644 --- a/frontend/src/styles/detail.css +++ b/frontend/src/styles/detail.css @@ -40,12 +40,20 @@ .fc-dt-row.is-error .fc-dt-mark { background: var(--danger); } .fc-dt-row.is-error .fc-dt-input { border-color: var(--danger); } -.fc-dt-cr-sec { --dt-cr-h: 120px; --dt-cr-btn: 22px; --dt-cr-role-w: 96px; display: flex; flex-direction: column; gap: var(--space-1); flex: none; } +.fc-dt-cr-sec { --dt-cr-h: 144px; --dt-cr-btn: 22px; --dt-cr-role-w: 96px; display: flex; flex-direction: column; gap: var(--space-1); flex: none; } .fc-dt-cr-head { display: flex; align-items: center; justify-content: space-between; height: var(--dt-row-h); } .fc-dt-cr-head.is-saving .fc-dt-mark { background: var(--text-muted); } .fc-dt-cr-box { display: flex; flex-direction: column; gap: var(--space-1); box-sizing: border-box; height: var(--dt-cr-h); padding: var(--space-1); overflow: auto; border: 1px solid var(--line-1); border-radius: var(--radius-sm); } -.fc-dt-cr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) var(--dt-cr-role-w) repeat(4, var(--dt-cr-btn)); align-items: center; gap: var(--space-1); flex: none; height: var(--dt-row-h); } -.fc-dt-cr.is-single .fc-dt-cr-family { grid-column: 1 / 3; } +.fc-dt-cr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, calc(50% - 4 * var(--dt-cr-btn) - 4 * var(--space-1))) repeat(4, var(--dt-cr-btn)); grid-template-rows: var(--dt-row-h) var(--dt-row-h); grid-template-areas: "fam giv giv giv giv giv" "role role single up down x"; align-items: center; gap: var(--space-1); flex: none; padding-bottom: var(--space-1); border-bottom: 1px solid var(--line-1); } +.fc-dt-cr:last-child { border-bottom-color: transparent; } +.fc-dt-cr-family { grid-area: fam; } +.fc-dt-cr-given { grid-area: giv; } +.fc-dt-cr-role { grid-area: role; } +.fc-dt-cr-single { grid-area: single; } +.fc-dt-cr-up { grid-area: up; } +.fc-dt-cr-down { grid-area: down; } +.fc-dt-cr-x { grid-area: x; } +.fc-dt-cr.is-single .fc-dt-cr-family { grid-column: 1 / -1; } .fc-dt-cr.is-single .fc-dt-cr-given { display: none; } .fc-dt-cr.is-error .fc-dt-input { border-color: var(--danger); } .fc-dt-cr-btn { display: inline-grid; place-items: center; width: var(--dt-cr-btn); height: var(--dt-cr-btn); padding: 0; border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; color: var(--text-muted); cursor: pointer; } From 1afd19e792bd6b0a49969faee16efa5d7ff12111 Mon Sep 17 00:00:00 2001 From: nodemode-ai Date: Fri, 27 Nov 2026 14:26:30 -0500 Subject: [PATCH 15/16] docs(detail): log structured creator editing Records how creators map to CSL name roles, what the PATCH carries, and what was measured in a private built copy. --- frontend/HASHOUT_LOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontend/HASHOUT_LOG.md b/frontend/HASHOUT_LOG.md index 61a32bf..4d1a078 100644 --- a/frontend/HASHOUT_LOG.md +++ b/frontend/HASHOUT_LOG.md @@ -416,3 +416,7 @@ New in v0.9.0 (2026-11-27). `remove` and `insert` run through one queue so two n ## src/ui/side.ts {#src-side-tags-measured} New in v0.9.0 (2026-11-27). The tag list was measured with 28 to 31 real tags on a 2,000-item library (a few hundred items tagged), CPU 4x, 400 ms and 50 kB/s, fresh engine. First fill: 30 rows inserted at once, 35 to 39 mutations in the pane, layout shift 0. `data-scope`, `data-name`, `data-parent` and `aria-current` were being rewritten on every row at every refresh (95 mutations for one scope pick, 64 for one delete); they now go through `setData` and `setCurrent`, which write only a changed value, and new rows get `aria-current` when built (60 and 8). A rename moves the row to its sorted place at the click through `placeTag` (reverted on an error), so the later refresh finds the order already right. `keepFocus` puts focus back on the focused node when a list patch or the post-rename scope change moves it. Still seen: after a rename under throttle, focus was lost to the body once in three runs about a second after the answer, from something outside `ui/side.ts` that was not found; a brand-new tag added from the item pane inserts a row in sorted place and shifts the rows below by 0.0013 without input; adding an existing tag only raises its count in place (20 to 21, shift 0). + +## src/io/detail.ts, src/engine/detail.ts, src/ui/detail.ts, src/styles/detail.css {#src-detail-creators} + +New in v0.9.0 (2026-11-27). Creators are edited in a fixed 144 px box under Title, one two-line row per creator: family and given on the first line, role (the 26 CSL name roles `NAME_ROLES` in `backend/app/store/items.py` accepts) with institution toggle, move up, move down and remove on the second. The engine keeps creators per role (`csl.author`, `csl.editor`, ...), each role ordered, with no order across roles; a save sends one `PATCH /api/library/items/{id}` whose `fields` carries every role that had or has names, an emptied role as `""` (which drops it). So the session keeps the order the user set, but after a reload the rows come back grouped by role in `NAME_ROLES` order. An institution is `{literal}`. `DetailModel.reconcile` keeps row keys across the quiet reload after a save, so `patchList` writes no row; a move swaps the two rows' contents and keys in place so no node moves. A row saves on blur out of the row, on Enter, and on a role change; Escape puts the stored row back (a new unsaved row is dropped); a refused save shows in `.fc-dt-cr-error` and puts the stored list back. The row buttons are `tabindex="-1"` so Tab runs family, given, role, next row; Alt plus Up or Down moves a row from the keyboard. Checked in a private built copy with 2,000 items under CPU 4x, 400 ms and 50 kB/s, fresh engine: add, reorder, role to editor, institution, refused save (routed 422) and remove each sent one PATCH (200), a reload read `author: [Castillo]`, `editor: [Second Ann, {literal: Acme Institute}]` through the API, the list creator cell went from "Haddad et al." to "Novak et al." to "Novak and Tanaka", the box stayed 144 px, and layout shift was 0 without input and 0.00085 with input (the rows under a removed row move up). From 9fb8793b00f8be29dd915b647be7c212c5723e10 Mon Sep 17 00:00:00 2001 From: nodemode-ai Date: Fri, 27 Nov 2026 14:34:07 -0500 Subject: [PATCH 16/16] chore(release): 0.9.0 Moves every version site to 0.9.0 and adds the changelog section. --- CHANGELOG.md | 23 +++++++++++++++++++++++ backend/HASHOUT_LOG.md | 2 +- backend/app/__init__.py | 2 +- frontend/HASHOUT_LOG.md | 2 +- frontend/package-lock.json | 4 ++-- frontend/package.json | 2 +- frontend/src/version.ts | 2 +- native/formcite-style/Cargo.lock | 2 +- native/formcite-style/Cargo.toml | 2 +- native/formcite-style/pyproject.toml | 2 +- setup/HASHOUT_LOG.md | 2 +- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/HASHOUT_LOG.md | 2 +- src-tauri/tauri.conf.json | 2 +- 15 files changed, 38 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d28e3b..2e74492 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,28 @@ # Changelog +## 0.9.0 + +A small release that closes what the library window had left open. + +### New +- Creators are edited one per row in the item pane: family name, given name, role, a single-name switch for institutions, move up, move down and remove. The item list's creator column follows a save. + +### Changed +- A title can no longer be saved empty through the command line or the API either. Imports are not affected: an entry with no title still imports as it did. +- Removing an item the list had not loaded, or several items at once, now moves only the rows that change. The list reads itself again only for an item deleted for good, and for a never-loaded item removed while a search filter is on. +- Renaming a tag moves its row to its sorted place at once. + +### Known issues +- After a tag rename, keyboard focus is sometimes lost about a second later on a slow machine. The cause has not been found. +- A brand-new tag added from the item pane pushes the tag rows under it down by one row. +- Creators come back grouped by role after a reload, because the library keeps one ordered list per role. +- Imported keywords are kept as text on the item and do not become tags. +- "Open in FormPDF" still opens the system viewer. +- The desktop app has not been built yet; the window runs in a browser against the engine. + +### Under the hood +- The row position route can rank an item that is in the trash, and tells an unknown item apart from an older engine. + ## 0.8.0 The library window is finished: everything in it now stays still while it loads and while you work. diff --git a/backend/HASHOUT_LOG.md b/backend/HASHOUT_LOG.md index d124dfb..e0ab10e 100644 --- a/backend/HASHOUT_LOG.md +++ b/backend/HASHOUT_LOG.md @@ -2,7 +2,7 @@ Living log of all comment content, explainers, rationale, TODOs, & removed (hashed-out) code for this side of the repo. Source files stay comment-free per dev-rules `sub-skills/hashout-log/SUB-SKILL.md`; everything they would have said lives here, indexed. This file is also the compressed contextual map of this side: read it first, then edit code surgically. -Current build version: v0.8.0 +Current build version: v0.9.0 Last updated: 2026-11-27 (US Eastern) · the lean rows route for the window's list and opening an attachment --- diff --git a/backend/app/__init__.py b/backend/app/__init__.py index 777f190..3e2f46a 100644 --- a/backend/app/__init__.py +++ b/backend/app/__init__.py @@ -1 +1 @@ -__version__ = "0.8.0" +__version__ = "0.9.0" diff --git a/frontend/HASHOUT_LOG.md b/frontend/HASHOUT_LOG.md index 4d1a078..ae2fc1d 100644 --- a/frontend/HASHOUT_LOG.md +++ b/frontend/HASHOUT_LOG.md @@ -2,7 +2,7 @@ Living log of all comment content, explainers, rationale, TODOs, & removed (hashed-out) code for this side of the repo. Source files stay comment-free per dev-rules `sub-skills/hashout-log/SUB-SKILL.md`; everything they would have said lives here, indexed. This file is also the compressed contextual map of this side: read it first, then edit code surgically. -Current build version: v0.8.0 +Current build version: v0.9.0 Last updated: 2026-11-26 (US Eastern) · window skeleton: shell, engine store, window key, health status --- diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 81a9f70..84de156 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "formcite", - "version": "0.8.0", + "version": "0.9.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "formcite", - "version": "0.8.0", + "version": "0.9.0", "license": "GPL-3.0-only", "devDependencies": { "typescript": "7.0.2", diff --git a/frontend/package.json b/frontend/package.json index 78a47d2..83ebb09 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "formcite", "private": true, - "version": "0.8.0", + "version": "0.9.0", "description": "FormCite: a local-first personal research library from the Form family", "license": "GPL-3.0-only", "type": "module", diff --git a/frontend/src/version.ts b/frontend/src/version.ts index ca24a8e..b336f57 100644 --- a/frontend/src/version.ts +++ b/frontend/src/version.ts @@ -1 +1 @@ -export const VERSION = '0.8.0'; +export const VERSION = '0.9.0'; diff --git a/native/formcite-style/Cargo.lock b/native/formcite-style/Cargo.lock index 5b596ec..dcce086 100644 --- a/native/formcite-style/Cargo.lock +++ b/native/formcite-style/Cargo.lock @@ -81,7 +81,7 @@ dependencies = [ [[package]] name = "formcite-style" -version = "0.8.0" +version = "0.9.0" dependencies = [ "hayagriva", "pyo3", diff --git a/native/formcite-style/Cargo.toml b/native/formcite-style/Cargo.toml index ed26cf5..efe4c0c 100644 --- a/native/formcite-style/Cargo.toml +++ b/native/formcite-style/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "formcite-style" -version = "0.8.0" +version = "0.9.0" edition = "2024" rust-version = "1.95" license = "Apache-2.0" diff --git a/native/formcite-style/pyproject.toml b/native/formcite-style/pyproject.toml index 2effc06..6f91f9a 100644 --- a/native/formcite-style/pyproject.toml +++ b/native/formcite-style/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "formcite-style" -version = "0.8.0" +version = "0.9.0" description = "FormCite citation style engine for the FormCite engine service" license = { text = "Apache-2.0" } requires-python = ">=3.10" diff --git a/setup/HASHOUT_LOG.md b/setup/HASHOUT_LOG.md index dd9d81c..21eccc9 100644 --- a/setup/HASHOUT_LOG.md +++ b/setup/HASHOUT_LOG.md @@ -2,7 +2,7 @@ Living log of all comment content, explainers, rationale, TODOs, and removed code for the root launcher scripts and the `setup/` suite. The scripts stay comment-free; everything they would have said lives here, indexed. Read this first, then edit the scripts surgically. -Current build version: v0.8.0 +Current build version: v0.9.0 Last updated: 2026-11-27 · initial port of the launcher and setup suite --- diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 29488e1..65d760c 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -918,7 +918,7 @@ dependencies = [ [[package]] name = "formcite" -version = "0.8.0" +version = "0.9.0" dependencies = [ "fontdb", "objc2", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 03a01ee..041ff50 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "formcite" -version = "0.8.0" +version = "0.9.0" description = "FormCite desktop shell" authors = ["NodeAgentc, Inc."] license = "GPL-3.0-only" diff --git a/src-tauri/HASHOUT_LOG.md b/src-tauri/HASHOUT_LOG.md index 3d6fcf0..5753ddd 100644 --- a/src-tauri/HASHOUT_LOG.md +++ b/src-tauri/HASHOUT_LOG.md @@ -2,7 +2,7 @@ Living log of all comment content, explainers, rationale, TODOs, & removed (hashed-out) code for the desktop shell side of the repo. Source files stay comment-free per dev-rules `sub-skills/hashout-log/SUB-SKILL.md`; everything they would have said lives here, indexed. This file is also the compressed contextual map of this side: read it first, then edit code surgically. -Current build version: v0.8.0 +Current build version: v0.9.0 Last updated: 2026-11-26 (US Eastern) · Tauri 2 shell ported from FormTxt, renamed, launch code added --- diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index fc6aa04..2aa9151 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "FormCite", - "version": "0.8.0", + "version": "0.9.0", "identifier": "ai.nodemode.formcite", "build": { "devUrl": "http://localhost:5330",