diff --git a/Packages/editor/src/database/cells.ts b/Packages/editor/src/database/cells.ts index 4e5529c..17b612d 100644 --- a/Packages/editor/src/database/cells.ts +++ b/Packages/editor/src/database/cells.ts @@ -117,11 +117,7 @@ export function renderCell(ctx: DbContext, row: Row, col: Column): Node { case "checkbox": return h( "span", - { - class: v === true ? "dw-db-check is-on" : "dw-db-check", - role: "img", - "aria-label": v === true ? l.checked : l.unchecked, - }, + { class: v === true ? "dw-db-check is-on" : "dw-db-check", role: "img", "aria-label": v === true ? l.checked : l.unchecked }, v === true ? icon("check", 13) : null, ); case "select": { @@ -149,11 +145,7 @@ export function renderCell(ctx: DbContext, row: Row, col: Column): Node { return h( "span", { class: "dw-db-progress" }, - h( - "span", - { class: "dw-db-progress__bar" }, - h("span", { class: "dw-db-progress__fill", style: { width: `${pct}%` } }), - ), + h("span", { class: "dw-db-progress__bar" }, h("span", { class: "dw-db-progress__fill", style: { width: `${pct}%` } })), h("span", { class: "dw-db-progress__num" }, `${pct}%`), ); } @@ -174,12 +166,7 @@ export function renderCell(ctx: DbContext, row: Row, col: Column): Node { { class: "dw-db-tags" }, asList(v).map((f) => { const href = ctx.files ? ctx.files.resolve(f.src) : f.src; - const a = h( - "a", - { class: "dw-db-file", href, target: "_blank", rel: "noopener noreferrer" }, - icon("paperclip", 12), - f.name, - ); + const a = h("a", { class: "dw-db-file", href, target: "_blank", rel: "noopener noreferrer" }, icon("paperclip", 12), f.name); a.addEventListener("click", (e) => { if (!e.ctrlKey && !e.metaKey) e.preventDefault(); }); @@ -191,14 +178,7 @@ export function renderCell(ctx: DbContext, row: Row, col: Column): Node { return h( "span", { class: "dw-db-tags" }, - asList(v).map((p) => - h( - "span", - { class: "dw-db-person" }, - h("span", { class: "dw-db-person__dot" }, (p?.name || "?").slice(0, 1).toUpperCase()), - p?.name ?? "", - ), - ), + asList(v).map((p) => h("span", { class: "dw-db-person" }, h("span", { class: "dw-db-person__dot" }, (p?.name || "?").slice(0, 1).toUpperCase()), p?.name ?? "")), ); case "relation": return renderRelation(ctx, row, col); @@ -240,8 +220,7 @@ export function editCell(ctx: DbContext, el: HTMLElement, row: Row, col: Column, opts.onDone(move); }; if (inlineTypes.includes(col.type)) { - const start = - opts.initial ?? (col.type === "number" ? (asNumber(v)?.toString() ?? "") : typeof v === "string" ? v : ""); + const start = opts.initial ?? (col.type === "number" ? (asNumber(v)?.toString() ?? "") : typeof v === "string" ? v : ""); let move: "down" | "right" | "left" | undefined; const input = textInput(start, { class: "dw-db-cell__input", @@ -293,11 +272,7 @@ export function editCell(ctx: DbContext, el: HTMLElement, row: Row, col: Column, const today = h("button", { type: "button", class: "dw-db__btn" }, ctx.labels.today); today.addEventListener("click", () => { const d = new Date(); - store.setCell( - row.id, - col.id, - `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`, - ); + store.setCell(row.id, col.id, `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`); close(); }); box.append(input, h("div", { class: "dw-db-pop__row" }, today, clear)); @@ -307,14 +282,7 @@ export function editCell(ctx: DbContext, el: HTMLElement, row: Row, col: Column, case "progress": panel((box, close) => { const n = asNumber(v) ?? 0; - const range = h("input", { - type: "range", - min: "0", - max: "100", - step: "1", - class: "dw-db-range", - "aria-label": col.name, - }); + const range = h("input", { type: "range", min: "0", max: "100", step: "1", class: "dw-db-range", "aria-label": col.name }); range.value = String(n); const num = h("span", { class: "dw-db-progress__num" }, `${n}%`); range.addEventListener("input", () => (num.textContent = `${range.value}%`)); @@ -346,9 +314,7 @@ function choicePanel(ctx: DbContext, box: HTMLDivElement, row: Row, col: Column, const l = ctx.labels; const multi = col.type === "multiSelect"; let options: SelectOption[] = [...(col.options ?? [])]; - let picked: string[] = multi - ? asList(cellValue(row, col)) - : [String(cellValue(row, col) ?? "")].filter(Boolean); + let picked: string[] = multi ? asList(cellValue(row, col)) : [String(cellValue(row, col) ?? "")].filter(Boolean); let active = 0; const chosen = h("div", { class: "dw-db-tags dw-db-pop__chosen" }); const input = h("input", { class: "dw-db-input", placeholder: l.searchOptions, "aria-label": l.searchOptions }); @@ -452,11 +418,7 @@ function choicePanel(ctx: DbContext, box: HTMLDivElement, row: Row, col: Column, h("span", { class: "dw-db-pop__check" }, picked.includes(it.o.id) ? icon("check", 13) : null), tag(it.o.name, it.o.color), ); - const more = h( - "button", - { type: "button", class: "dw-db__btn dw-db__btn--icon dw-db-pop__more", "aria-label": l.optionColor }, - icon("more", 14), - ); + const more = h("button", { type: "button", class: "dw-db__btn dw-db__btn--icon dw-db-pop__more", "aria-label": l.optionColor }, icon("more", 14)); more.addEventListener("click", (e) => { e.stopPropagation(); editOption(more, it.o); @@ -464,10 +426,7 @@ function choicePanel(ctx: DbContext, box: HTMLDivElement, row: Row, col: Column, rowEl.append(more); rowEl.addEventListener("click", () => toggle(it.o.id)); } else { - rowEl.append( - h("span", { class: "dw-db-pop__check" }, icon("plus", 13)), - h("span", {}, fill(l.createOption, it.name)), - ); + rowEl.append(h("span", { class: "dw-db-pop__check" }, icon("plus", 13)), h("span", {}, fill(l.createOption, it.name))); rowEl.addEventListener("click", () => create(it.name)); } return rowEl; @@ -583,11 +542,7 @@ function attachmentPanel(ctx: DbContext, box: HTMLDivElement, row: Row, col: Col list.replaceChildren( ...files.map((f, i) => { const href = ctx.files ? ctx.files.resolve(f.src) : f.src; - const rm = h( - "button", - { type: "button", class: "dw-db__btn dw-db__btn--icon", "aria-label": l.remove, title: l.remove }, - icon("trash", 14), - ); + const rm = h("button", { type: "button", class: "dw-db__btn dw-db__btn--icon", "aria-label": l.remove, title: l.remove }, icon("trash", 14)); rm.addEventListener("click", () => { files = files.filter((_, j) => j !== i); store.setCell(row.id, col.id, files); @@ -596,12 +551,7 @@ function attachmentPanel(ctx: DbContext, box: HTMLDivElement, row: Row, col: Col return h( "div", { class: "dw-db-pop__item" }, - h( - "a", - { class: "dw-db-file", href, target: "_blank", rel: "noopener noreferrer" }, - icon("paperclip", 12), - f.name, - ), + h("a", { class: "dw-db-file", href, target: "_blank", rel: "noopener noreferrer" }, icon("paperclip", 12), f.name), rm, ); }), diff --git a/Packages/editor/src/database/database.test.ts b/Packages/editor/src/database/database.test.ts index 6eedaa4..d19f8f0 100644 --- a/Packages/editor/src/database/database.test.ts +++ b/Packages/editor/src/database/database.test.ts @@ -3,23 +3,7 @@ import { describe, expect, it } from "vitest"; import * as Y from "yjs"; import { formatDelimited, fromCSV, parseDelimited, toCSV } from "./csv"; -import { - convertValue, - addDays, - coverImage, - daysBetween, - timelineSpan, - timelineStart, - defaultView, - groupRows, - monthGrid, - moveToGroup, - normalize, - viewRows, - type Column, - type DbData, - type Row, -} from "./model"; +import { addDays, convertValue, coverImage, daysBetween, defaultView, timelineSpan, timelineStart, groupRows, monthGrid, moveToGroup, normalize, viewRows, type Column, type DbData, type Row } from "./model"; import { blocksOf, DbStore, readDb, seedDb } from "./store"; const title: Column = { id: "t", name: "Name", type: "title" }; @@ -39,11 +23,7 @@ function sample(): DbData { return { title: "Tasks", columns: [title, status, points], - rows: [ - row("a", { t: "Write", s: "todo", p: 3 }), - row("b", { t: "Read", s: "done", p: 1 }), - row("c", { t: "Ship", p: 5 }), - ], + rows: [row("a", { t: "Write", s: "todo", p: 3 }), row("b", { t: "Read", s: "done", p: 1 }), row("c", { t: "Ship", p: 5 })], views: [defaultView("table", "Table", [title, status, points])], }; } @@ -101,23 +81,13 @@ describe("CSV", () => { ["a", "b,c", 'd "e"\nf'], ["1", "2", "3"], ]); - expect( - formatDelimited([ - ["a", "b,c"], - ['x"y', ""], - ]), - ).toBe('a,"b,c"\r\n"x""y",'); + expect(formatDelimited([["a", "b,c"], ['x"y', ""]])).toBe('a,"b,c"\r\n"x""y",'); }); it("guesses column types on import and writes them back", () => { const { columns, rows } = fromCSV("Name,Points,Due,Done\nA,1,2026-11-01,yes\nB,2.5,2026-11-02,no\n"); expect(columns.map((c) => c.type)).toEqual(["title", "number", "date", "checkbox"]); - expect(rows[1]).toEqual({ - [columns[0]!.id]: "B", - [columns[1]!.id]: 2.5, - [columns[2]!.id]: "2026-11-02", - [columns[3]!.id]: false, - }); + expect(rows[1]).toEqual({ [columns[0]!.id]: "B", [columns[1]!.id]: 2.5, [columns[2]!.id]: "2026-11-02", [columns[3]!.id]: false }); const db = sample(); expect(toCSV(db, db.columns, db.rows).split("\r\n")[1]).toBe("Write,To do,3"); }); @@ -181,12 +151,7 @@ describe("list and gallery views", () => { }); it("covers a card with the first image of the cell", () => { - expect( - coverImage([ - { name: "notes.pdf", src: "/f/1", mime: "application/pdf" }, - { name: "a.png", src: "/f/2", mime: "image/png" }, - ]), - ).toBe("/f/2"); + expect(coverImage([{ name: "notes.pdf", src: "/f/1", mime: "application/pdf" }, { name: "a.png", src: "/f/2", mime: "image/png" }])).toBe("/f/2"); expect(coverImage([{ name: "photo.JPG", src: "/f/3" }])).toBe("/f/3"); expect(coverImage([{ name: "notes.pdf", src: "/f/1" }])).toBe(""); expect(coverImage("nope")).toBe(""); @@ -200,10 +165,7 @@ describe("timeline view", () => { it("starts on the first date property and ends on the second", () => { const v = defaultView("timeline", "T", [title, start, end]); expect([v.dateColumn, v.endColumn, v.scale]).toEqual(["a", "b", "week"]); - expect( - normalize({ columns: [title, start], views: [{ id: "t", type: "timeline", dateColumn: "a", scale: "year" }] }) - .views[0]!.scale, - ).toBe("week"); + expect(normalize({ columns: [title, start], views: [{ id: "t", type: "timeline", dateColumn: "a", scale: "year" }] }).views[0]!.scale).toBe("week"); }); it("counts days across months and years", () => { @@ -213,18 +175,9 @@ describe("timeline view", () => { }); it("spans a record from its start to its end, or one day", () => { - expect(timelineSpan(row("x", { a: "2026-11-10", b: "2026-11-12" }), start, end)).toEqual({ - from: "2026-11-10", - to: "2026-11-12", - }); - expect(timelineSpan(row("x", { a: "2026-11-10", b: "2026-11-01" }), start, end)).toEqual({ - from: "2026-11-10", - to: "2026-11-10", - }); - expect(timelineSpan(row("x", { a: "2026-11-10" }), start, undefined)).toEqual({ - from: "2026-11-10", - to: "2026-11-10", - }); + expect(timelineSpan(row("x", { a: "2026-11-10", b: "2026-11-12" }), start, end)).toEqual({ from: "2026-11-10", to: "2026-11-12" }); + expect(timelineSpan(row("x", { a: "2026-11-10", b: "2026-11-01" }), start, end)).toEqual({ from: "2026-11-10", to: "2026-11-10" }); + expect(timelineSpan(row("x", { a: "2026-11-10" }), start, undefined)).toEqual({ from: "2026-11-10", to: "2026-11-10" }); expect(timelineSpan(row("x", { b: "2026-11-10" }), start, end)).toBeNull(); }); diff --git a/Packages/editor/src/database/dom.ts b/Packages/editor/src/database/dom.ts index b01ab37..24d72b8 100644 --- a/Packages/editor/src/database/dom.ts +++ b/Packages/editor/src/database/dom.ts @@ -124,14 +124,7 @@ export function closePopover() { /** A text input that commits on Enter or blur and cancels on Escape. */ export function textInput( value: string, - opts: { - placeholder?: string; - label?: string; - class?: string; - type?: string; - onCommit: (v: string) => void; - onCancel?: () => void; - }, + opts: { placeholder?: string; label?: string; class?: string; type?: string; onCommit: (v: string) => void; onCancel?: () => void }, ): HTMLInputElement { const input = h("input", { type: opts.type ?? "text", diff --git a/Packages/editor/src/database/index.ts b/Packages/editor/src/database/index.ts index 1077397..a9445aa 100644 --- a/Packages/editor/src/database/index.ts +++ b/Packages/editor/src/database/index.ts @@ -8,12 +8,7 @@ import { Editor, mergeAttributes, Node, type AnyExtension, type JSONContent } from "@tiptap/core"; import { Fragment, Slice, type Node as PMNode } from "@tiptap/pm/model"; import { NodeSelection, Plugin, PluginKey } from "@tiptap/pm/state"; -import { - prosemirrorJSONToYXmlFragment, - ySyncPluginKey, - yUndoPluginKey, - yXmlFragmentToProsemirrorJSON, -} from "@tiptap/y-tiptap"; +import { prosemirrorJSONToYXmlFragment, ySyncPluginKey, yUndoPluginKey, yXmlFragmentToProsemirrorJSON } from "@tiptap/y-tiptap"; import * as Y from "yjs"; import type { FileHost } from "../files"; import { englishLabels, type EditorLabels } from "../labels"; @@ -24,17 +19,7 @@ import type { CollabProvider } from "../provider"; import { computeLinked, relationIds, type DatabaseChoice, type RelationTarget } from "./linked"; import type { LinkedHost } from "./relationui"; import { h } from "./dom"; -import { - cellText, - defaultView, - newId, - normalize, - titleColumn, - type Column, - type DbData, - type Person, - type Row, -} from "./model"; +import { cellText, defaultView, newId, normalize, titleColumn, type Column, type DbData, type Person, type Row } from "./model"; import { RowPeek } from "./peek"; import { blocksOf, DbStore, emptyDb, exportDb, readDb, seedDb } from "./store"; import { DatabaseView } from "./view"; @@ -286,8 +271,7 @@ export const Database = Node.create({ if (!live) return n.type.create({ ...n.attrs, id }); const source = n.attrs.data ? normalize(n.attrs.data) : null; const m = blocksOf(live).get(String(n.attrs.id)); - const data = - source ?? (m instanceof Y.Map ? exportDb(m, bodyJSON) : emptyDb(dbDefaults(this.options.labels))); + const data = source ?? (m instanceof Y.Map ? exportDb(m, bodyJSON) : emptyDb(dbDefaults(this.options.labels))); seedDb(live, id, freshIds(data), (json, f) => writeBody(editor, json, f)); return n.type.create({ id, data: null }); }); @@ -297,12 +281,7 @@ export const Database = Node.create({ // Two nodes never share one map: a duplicated block gets a copy of the records. appendTransaction: (trs, _old, state) => { if (!live || !trs.some((tr) => tr.docChanged && !tr.getMeta(ySyncPluginKey))) return null; - if ( - !trs.some((tr) => - tr.steps.some((s) => hasDatabase((s as unknown as { slice?: Slice }).slice?.content ?? Fragment.empty)), - ) - ) - return null; + if (!trs.some((tr) => tr.steps.some((s) => hasDatabase((s as unknown as { slice?: Slice }).slice?.content ?? Fragment.empty)))) return null; const seen = new Set(); const fix: { pos: number; node: PMNode }[] = []; state.doc.descendants((n, pos) => { @@ -317,8 +296,7 @@ export const Database = Node.create({ for (const { pos, node } of fix) { const m = blocksOf(live).get(String(node.attrs.id)); const id = newId(); - if (m instanceof Y.Map) - seedDb(live, id, freshIds(exportDb(m, bodyJSON)), (json, f) => writeBody(editor, json, f)); + if (m instanceof Y.Map) seedDb(live, id, freshIds(exportDb(m, bodyJSON)), (json, f) => writeBody(editor, json, f)); tr.setNodeMarkup(pos, undefined, { ...node.attrs, id, data: null }); } return tr; @@ -401,11 +379,7 @@ export const Database = Node.create({ return m instanceof Y.Map ? readDb(m) : null; }; /** Database ids in a page's text, in order, with their titles. */ - const databasesIn = ( - fragment: Y.XmlFragment, - page: string, - read: (id: string) => DbData | null, - ): DatabaseChoice[] => { + const databasesIn = (fragment: Y.XmlFragment, page: string, read: (id: string) => DbData | null): DatabaseChoice[] => { const out: DatabaseChoice[] = []; const walk = (el: Y.XmlFragment | Y.XmlElement) => { for (const c of el.toArray()) { @@ -437,10 +411,7 @@ export const Database = Node.create({ return out; }, searchPages: opts.pages - ? (q) => - opts - .pages!.search(q) - .then((list) => list.filter((p) => !isSelf(p.id)).map((p) => ({ id: p.id, title: p.title }))) + ? (q) => opts.pages!.search(q).then((list) => list.filter((p) => !isSelf(p.id)).map((p) => ({ id: p.id, title: p.title }))) : undefined, databasesOn: opts.linkedPages ? (page) => @@ -545,13 +516,10 @@ export const Database = Node.create({ element: el, editable, extensions: make(fragment), - content: fragment - ? undefined - : { type: "doc", content: (row.body as JSONContent[] | undefined) ?? [{ type: "paragraph" }] }, + content: fragment ? undefined : { type: "doc", content: (row.body as JSONContent[] | undefined) ?? [{ type: "paragraph" }] }, editorProps: { attributes: { class: "dw-prose dw-db-peek__prose" } }, }); - if (!fragment && !row.body?.length) - el.replaceChildren(h("p", { class: "dw-db-peek__note" }, labels.database.bodyReadOnly)); + if (!fragment && !row.body?.length) el.replaceChildren(h("p", { class: "dw-db-peek__note" }, labels.database.bodyReadOnly)); return () => ed.destroy(); }; @@ -623,11 +591,7 @@ export const Database = Node.create({ queueMicrotask(() => { const pos = typeof getPos === "function" ? getPos() : undefined; if (pos !== undefined && editor.state.doc.nodeAt(pos)?.type.name === "database") { - editor.view.dispatch( - editor.state.tr - .setNodeMarkup(pos, undefined, { ...node.attrs, id: key, data: null }) - .setMeta("addToHistory", false), - ); + editor.view.dispatch(editor.state.tr.setNodeMarkup(pos, undefined, { ...node.attrs, id: key, data: null }).setMeta("addToHistory", false)); } }); m = blocksOf(doc).get(key) as Y.Map; @@ -749,10 +713,7 @@ interface ListFound { * The list around the selection (or the top-level blocks it spans) as items: * each item's first line is its title, the rest its body. */ -function listAt( - $from: import("@tiptap/pm/model").ResolvedPos, - $to: import("@tiptap/pm/model").ResolvedPos, -): ListFound | null { +function listAt($from: import("@tiptap/pm/model").ResolvedPos, $to: import("@tiptap/pm/model").ResolvedPos): ListFound | null { for (let d = $from.depth; d > 0; d--) { const n = $from.node(d); if (["bulletList", "orderedList", "taskList"].includes(n.type.name)) { diff --git a/Packages/editor/src/database/linked.test.ts b/Packages/editor/src/database/linked.test.ts index 0369e87..b53288d 100644 --- a/Packages/editor/src/database/linked.test.ts +++ b/Packages/editor/src/database/linked.test.ts @@ -76,11 +76,7 @@ describe("relations and rollups", () => { it("sorts and filters rollups as numbers", () => { const db = linked(projects("sum")); - const view = { - ...db.views[0]!, - sorts: [{ column: "r", desc: true }], - filters: [{ column: "r", op: "gt" as const, value: 5 }], - }; + const view = { ...db.views[0]!, sorts: [{ column: "r", desc: true }], filters: [{ column: "r", op: "gt" as const, value: 5 }] }; expect(viewRows(db, view).map((r) => r.id)).toEqual(["p1"]); const empty = { ...db.views[0]!, filters: [{ column: "rel", op: "isEmpty" as const }] }; expect(viewRows(db, empty).map((r) => r.id)).toEqual(["p2"]); @@ -116,8 +112,7 @@ describe("two-way relations", () => { { id: "p2", cells: { t: "Docs", rel: ["k2"] } }, ], }); - const read = (found: DbData | null) => - computeLinked(twoWay, (t) => (t.database === "projects" ? found : null), englishDatabaseLabels); + const read = (found: DbData | null) => computeLinked(twoWay, (t) => (t.database === "projects" ? found : null), englishDatabaseLabels); it("keeps the mirrored column when read", () => { expect(twoWay.columns[1]!.relation).toEqual({ page: "", database: "projects", back: "rel" }); diff --git a/Packages/editor/src/database/linked.ts b/Packages/editor/src/database/linked.ts index 27424b5..40a0aee 100644 --- a/Packages/editor/src/database/linked.ts +++ b/Packages/editor/src/database/linked.ts @@ -130,9 +130,7 @@ export function rollup(fn: RollupFn, related: Row[], col: Column | null, l: Pick case "countNotEmpty": return num(filled.length); case "percentNotEmpty": - return related.length - ? { text: `${fmt((filled.length / related.length) * 100)}%`, value: (filled.length / related.length) * 100 } - : num(null); + return related.length ? { text: `${fmt((filled.length / related.length) * 100)}%`, value: (filled.length / related.length) * 100 } : num(null); case "sum": return num(nums.length ? nums.reduce((a, b) => a + b, 0) : null); case "average": @@ -162,10 +160,7 @@ export function rollup(fn: RollupFn, related: Row[], col: Column | null, l: Pick return num(values.filter((v) => v === true).length); case "percentChecked": return related.length - ? { - text: `${fmt((values.filter((v) => v === true).length / related.length) * 100)}%`, - value: (values.filter((v) => v === true).length / related.length) * 100, - } + ? { text: `${fmt((values.filter((v) => v === true).length / related.length) * 100)}%`, value: (values.filter((v) => v === true).length / related.length) * 100 } : num(null); case "showOriginal": { const shown = texts.filter(Boolean); @@ -219,9 +214,7 @@ export function computeLinked( const row = byId.get(id); return row ? [row] : []; }); - const prop = cfg.property - ? (target.columns.find((x) => x.id === cfg.property) ?? null) - : (target.columns.find((x) => x.type === "title") ?? null); + const prop = cfg.property ? (target.columns.find((x) => x.id === cfg.property) ?? null) : (target.columns.find((x) => x.type === "title") ?? null); computed[c.id] = rollup(cfg.fn, related, prop, l); } return { ...r, computed }; diff --git a/Packages/editor/src/database/model.ts b/Packages/editor/src/database/model.ts index dde818f..7dedb4a 100644 --- a/Packages/editor/src/database/model.ts +++ b/Packages/editor/src/database/model.ts @@ -143,10 +143,7 @@ export interface DbData { export function newId(): string { const bytes = new Uint8Array(6); crypto.getRandomValues(bytes); - return [...bytes] - .map((b) => b.toString(36).padStart(2, "0")) - .join("") - .slice(0, 10); + return [...bytes].map((b) => b.toString(36).padStart(2, "0")).join("").slice(0, 10); } export function defaultView(type: ViewType, name: string, columns: Column[]): View { @@ -213,15 +210,11 @@ export function normalize(raw: unknown): DbData { type, hidden: Array.isArray(v.hidden) ? v.hidden.filter((h): h is string => typeof h === "string") : [], filters: Array.isArray(v.filters) - ? v.filters.filter( - (f): f is Filter => isObject(f) && typeof f.column === "string" && typeof f.op === "string", - ) + ? v.filters.filter((f): f is Filter => isObject(f) && typeof f.column === "string" && typeof f.op === "string") : [], filterMode: v.filterMode === "or" ? "or" : "and", sorts: Array.isArray(v.sorts) - ? v.sorts.flatMap((s) => - isObject(s) && typeof s.column === "string" ? [{ column: s.column, desc: !!s.desc }] : [], - ) + ? v.sorts.flatMap((s) => (isObject(s) && typeof s.column === "string" ? [{ column: s.column, desc: !!s.desc }] : [])) : [], groupBy: typeof v.groupBy === "string" && ids.has(v.groupBy) ? v.groupBy : null, dateColumn: typeof v.dateColumn === "string" && ids.has(v.dateColumn) ? v.dateColumn : null, @@ -239,9 +232,7 @@ export function normalize(raw: unknown): DbData { function option(o: unknown): SelectOption[] { if (!isObject(o) || typeof o.id !== "string") return []; - return [ - { id: o.id, name: typeof o.name === "string" ? o.name : "", color: isPaletteColor(o.color) ? o.color : "gray" }, - ]; + return [{ id: o.id, name: typeof o.name === "string" ? o.name : "", color: isPaletteColor(o.color) ? o.color : "gray" }]; } function person(p: unknown): Person | null { @@ -380,10 +371,7 @@ export function matchesFilter(row: Row, col: Column, f: Filter): boolean { // A filter without a value yet matches everything, as in a spreadsheet. if (f.value === undefined || f.value === null || f.value === "") return true; // A rollup that counts or sums compares as a number. - const numeric = - col.type === "rollup" && - (typeof v === "number" || v === null) && - ["is", "isNot", "gt", "lt", "gte", "lte"].includes(f.op); + const numeric = col.type === "rollup" && (typeof v === "number" || v === null) && ["is", "isNot", "gt", "lt", "gte", "lte"].includes(f.op); switch (numeric ? "number" : col.type) { case "number": case "progress": { @@ -663,23 +651,14 @@ export function coverImage(v: unknown): string { if (!Array.isArray(v)) return ""; for (const f of v as Partial[]) { if (!f || typeof f.src !== "string" || !f.src) continue; - if ( - typeof f.mime === "string" - ? f.mime.startsWith("image/") - : /\.(png|jpe?g|gif|webp|avif|svg)$/i.test(f.name ?? f.src) - ) - return f.src; + if (typeof f.mime === "string" ? f.mime.startsWith("image/") : /\.(png|jpe?g|gif|webp|avif|svg)$/i.test(f.name ?? f.src)) return f.src; } return ""; } /** Days between two ISO dates (b - a). */ export function daysBetween(a: string, b: string): number { - return Math.round( - (Date.UTC(+b.slice(0, 4), +b.slice(5, 7) - 1, +b.slice(8, 10)) - - Date.UTC(+a.slice(0, 4), +a.slice(5, 7) - 1, +a.slice(8, 10))) / - 86_400_000, - ); + return Math.round((Date.UTC(+b.slice(0, 4), +b.slice(5, 7) - 1, +b.slice(8, 10)) - Date.UTC(+a.slice(0, 4), +a.slice(5, 7) - 1, +a.slice(8, 10))) / 86_400_000); } /** The ISO date n days after day. */ @@ -714,3 +693,4 @@ export function timelineStart(today: string, scale: TimelineScale): string { const dow = (new Date(`${d}T12:00:00Z`).getUTCDay() + 6) % 7; return addDays(d, -dow); } + diff --git a/Packages/editor/src/database/node.test.ts b/Packages/editor/src/database/node.test.ts index fc17d08..2cb5c7c 100644 --- a/Packages/editor/src/database/node.test.ts +++ b/Packages/editor/src/database/node.test.ts @@ -28,9 +28,7 @@ it("follows its map when the server replaces it (a restore or import)", () => { document.body.append(el); editor = new Editor({ element: el, - extensions: docwellExtensions({ - collab: { provider: { doc, awareness: new Awareness(doc) } as never, user: { name: "A", color: "#888" } }, - }), + extensions: docwellExtensions({ collab: { provider: { doc, awareness: new Awareness(doc) } as never, user: { name: "A", color: "#888" } } }), }); editor.commands.insertDatabase(db(["one", "two"])); expect(titles(el)).toEqual(["one", "two"]); diff --git a/Packages/editor/src/database/panels.ts b/Packages/editor/src/database/panels.ts index b963c7b..a6aafbd 100644 --- a/Packages/editor/src/database/panels.ts +++ b/Packages/editor/src/database/panels.ts @@ -6,7 +6,15 @@ import type { DbContext } from "./cells"; import { typeIcons } from "./cells"; import { h, icon } from "./dom"; import { opLabel, typeLabel } from "./labels"; -import { filterOps, groupableTypes, opTakesValue, type Column, type Filter, type FilterOp, type View } from "./model"; +import { + filterOps, + groupableTypes, + opTakesValue, + type Column, + type Filter, + type FilterOp, + type View, +} from "./model"; function select( value: T | "", @@ -39,23 +47,11 @@ function filterValue(ctx: DbContext, col: Column, f: Filter, set: (v: unknown) = set, ); } - const type = - col.type === "date" || col.type === "createdTime" - ? "date" - : col.type === "number" || col.type === "progress" - ? "number" - : "text"; - const input = h("input", { - class: "dw-db-input dw-db-input--small", - type, - "aria-label": l.value, - placeholder: l.value, - }); + const type = col.type === "date" || col.type === "createdTime" ? "date" : col.type === "number" || col.type === "progress" ? "number" : "text"; + const input = h("input", { class: "dw-db-input dw-db-input--small", type, "aria-label": l.value, placeholder: l.value }); input.value = f.value === undefined || f.value === null ? "" : String(f.value); input.addEventListener("keydown", (e) => e.stopPropagation()); - input.addEventListener("change", () => - set(type === "number" ? (input.value === "" ? null : Number(input.value)) : input.value), - ); + input.addEventListener("change", () => set(type === "number" ? (input.value === "" ? null : Number(input.value)) : input.value)); return input; } @@ -69,18 +65,13 @@ export function filterPanel(ctx: DbContext, box: HTMLElement, view: View) { box.replaceChildren(); if (filters.length > 1) { box.append( - select( - view.filterMode, - [ - { value: "and", label: l.matchAll }, - { value: "or", label: l.matchAny }, - ], - l.filter, - (v) => { - view.filterMode = v as "and" | "or"; - store?.updateView(view.id, { filterMode: view.filterMode }); - }, - ), + select(view.filterMode, [ + { value: "and", label: l.matchAll }, + { value: "or", label: l.matchAny }, + ], l.filter, (v) => { + view.filterMode = v as "and" | "or"; + store?.updateView(view.id, { filterMode: view.filterMode }); + }), ); } if (!filters.length) box.append(h("p", { class: "dw-db-pop__empty" }, l.noFilters)); @@ -97,17 +88,12 @@ export function filterPanel(ctx: DbContext, box: HTMLElement, view: View) { save(); draw(); }), - select( - f.op, - ops.map((op) => ({ value: op, label: opLabel(l, op) })), - l.filter, - (op) => { - filters[i] = { ...f, op }; - if (!opTakesValue(op)) delete filters[i]!.value; - save(); - draw(); - }, - ), + select(f.op, ops.map((op) => ({ value: op, label: opLabel(l, op) })), l.filter, (op) => { + filters[i] = { ...f, op }; + if (!opTakesValue(op)) delete filters[i]!.value; + save(); + draw(); + }), filterValue(ctx, col, f, (v) => { filters[i] = { ...filters[i]!, value: v }; save(); @@ -152,18 +138,13 @@ export function sortPanel(ctx: DbContext, box: HTMLElement, view: View) { sorts[i] = { ...s, column: id }; save(); }), - select( - s.desc ? "desc" : "asc", - [ - { value: "asc", label: l.ascending }, - { value: "desc", label: l.descending }, - ], - l.sort, - (v) => { - sorts[i] = { ...s, desc: v === "desc" }; - save(); - }, - ), + select(s.desc ? "desc" : "asc", [ + { value: "asc", label: l.ascending }, + { value: "desc", label: l.descending }, + ], l.sort, (v) => { + sorts[i] = { ...s, desc: v === "desc" }; + save(); + }), removeButton(l.remove, () => { sorts.splice(i, 1); save(); @@ -298,11 +279,7 @@ export function propertiesPanel(ctx: DbContext, outer: HTMLElement, view: View) } function removeButton(label: string, onClick: () => void) { - const b = h( - "button", - { type: "button", class: "dw-db__btn dw-db__btn--icon", "aria-label": label, title: label }, - icon("close", 14), - ); + const b = h("button", { type: "button", class: "dw-db__btn dw-db__btn--icon", "aria-label": label, title: label }, icon("close", 14)); b.addEventListener("click", onClick); return b; } diff --git a/Packages/editor/src/database/peek.ts b/Packages/editor/src/database/peek.ts index 2f6a052..ba5a958 100644 --- a/Packages/editor/src/database/peek.ts +++ b/Packages/editor/src/database/peek.ts @@ -42,13 +42,7 @@ export class RowPeek { private onClose: () => void, ) { this.returnFocus = document.activeElement; - this.panel = h( - "div", - { class: "dw-db-peek__panel", role: "dialog", "aria-modal": "true", tabIndex: -1 }, - this.head, - this.props, - this.bodyEl, - ); + this.panel = h("div", { class: "dw-db-peek__panel", role: "dialog", "aria-modal": "true", tabIndex: -1 }, this.head, this.props, this.bodyEl); this.dom = h("div", { class: host.page ? "dw-db-peek dw-db-peek--page" : "dw-db-peek" }, this.panel); this.dom.addEventListener("mousedown", (e) => { if (e.target === this.dom && !this.host.page) this.close(); @@ -141,11 +135,7 @@ export class RowPeek { const titleText = String(cellValue(row, title) ?? ""); const titleEl = store ? (() => { - const input = h("input", { - class: "dw-db-peek__title", - placeholder: l.untitledRow, - "aria-label": title.name || l.typeTitle, - }); + const input = h("input", { class: "dw-db-peek__title", placeholder: l.untitledRow, "aria-label": title.name || l.typeTitle }); input.value = titleText; input.addEventListener("focus", () => ctx.setEditing(true)); input.addEventListener("blur", () => { @@ -164,14 +154,7 @@ export class RowPeek { const lines = this.db.columns .filter((c) => c.type !== "title") .map((c) => { - const value = h( - "div", - { - class: `dw-db-peek__value dw-db-t__cell--${c.type}`, - tabIndex: store && !readOnlyTypes.includes(c.type) ? 0 : -1, - }, - renderCell(ctx, row, c), - ); + const value = h("div", { class: `dw-db-peek__value dw-db-t__cell--${c.type}`, tabIndex: store && !readOnlyTypes.includes(c.type) ? 0 : -1 }, renderCell(ctx, row, c)); const edit = () => { if (!store) return; editCell(ctx, value, row, c, { onDone: () => this.draw(false) }); @@ -189,33 +172,19 @@ export class RowPeek { return h( "div", { class: "dw-db-peek__prop" }, - h( - "div", - { class: "dw-db-peek__label" }, - icon(typeIcons[c.type], 14), - h("span", {}, c.name || typeLabel(l, c.type)), - ), + h("div", { class: "dw-db-peek__label" }, icon(typeIcons[c.type], 14), h("span", {}, c.name || typeLabel(l, c.type))), value, ); }); const children: Node[] = [titleEl, ...lines]; if (store) { - const add = iconButton( - "plus", - l.addColumn, - () => - openBlockMenu( - add, - editableTypes.map((t) => ({ - id: t, - label: typeLabel(l, t), - icon: typeIcons[t], - run: () => store.addColumn(t, typeLabel(l, t)), - })), - l.addColumn, - ), - l.addColumn, - ); + const add = iconButton("plus", l.addColumn, () => + openBlockMenu( + add, + editableTypes.map((t) => ({ id: t, label: typeLabel(l, t), icon: typeIcons[t], run: () => store.addColumn(t, typeLabel(l, t)) })), + l.addColumn, + ), + l.addColumn); add.classList.add("dw-db-peek__add"); children.push(add); } @@ -237,7 +206,6 @@ export class RowPeek { this.dom.remove(); this.onClose(); if (leave) this.host.page?.onLeave?.(); - if (this.returnFocus instanceof HTMLElement && this.returnFocus.isConnected) - this.returnFocus.focus({ preventScroll: true }); + if (this.returnFocus instanceof HTMLElement && this.returnFocus.isConnected) this.returnFocus.focus({ preventScroll: true }); } } diff --git a/Packages/editor/src/database/relationui.ts b/Packages/editor/src/database/relationui.ts index 7a750d4..decd395 100644 --- a/Packages/editor/src/database/relationui.ts +++ b/Packages/editor/src/database/relationui.ts @@ -6,14 +6,7 @@ import type { DbContext } from "./cells"; import { h, icon, popover } from "./dom"; import { fill, typeLabel, type DatabaseLabels } from "./labels"; -import { - linkedIds, - rollupFnsFor, - type DatabaseChoice, - type RelationTarget, - type RollupConfig, - type RollupFn, -} from "./linked"; +import { linkedIds, rollupFnsFor, type DatabaseChoice, type RelationTarget, type RollupConfig, type RollupFn } from "./linked"; import { cellText, titleColumn, type Column, type DbData, type Row } from "./model"; /** What relation cells and settings need from the block (index.ts fills it in). */ @@ -42,9 +35,7 @@ export interface LinkedHost { function mirrorable(linked: LinkedHost, t: RelationTarget): Column[] { const db = linked.read(t); if (!db || !linked.pointsHere) return []; - return db.columns.filter( - (c) => c.type === "relation" && c.relation && !c.relation.back && linked.pointsHere!(t, c.relation), - ); + return db.columns.filter((c) => c.type === "relation" && c.relation && !c.relation.back && linked.pointsHere!(t, c.relation)); } const fnKey = (fn: RollupFn) => `fn${fn[0]!.toUpperCase()}${fn.slice(1)}` as keyof DatabaseLabels; @@ -91,15 +82,10 @@ export function relationTargetPanel(ctx: DbContext, anchor: Element, col: Column close(); }), ...mirrors.map((m) => - item( - fill(l.relationMirror, m.name || l.typeRelation), - same && current!.back === m.id, - () => { - store.setRelation(col.id, { ...target, back: m.id }); - close(); - }, - l.relationTwoWay, - ), + item(fill(l.relationMirror, m.name || l.typeRelation), same && current!.back === m.id, () => { + store.setRelation(col.id, { ...target, back: m.id }); + close(); + }, l.relationTwoWay), ), ), ); @@ -111,9 +97,7 @@ export function relationTargetPanel(ctx: DbContext, anchor: Element, col: Column h("div", { class: "dw-db-pop__heading" }, l.relationThisPage), ...(local.length ? local.map((c) => - item(c.title || l.untitled, !!current && !current.page && current.database === c.database, () => - pick(c), - ), + item(c.title || l.untitled, !!current && !current.page && current.database === c.database, () => pick(c)), ) : [h("div", { class: "dw-db-pop__empty" }, l.relationNoDatabases)]), ); @@ -121,11 +105,7 @@ export function relationTargetPanel(ctx: DbContext, anchor: Element, col: Column drawLocal(); box.append(h("div", { class: "dw-db-pop__title" }, l.relationPick), list); if (linked.searchPages && linked.databasesOn) { - const input = h("input", { - class: "dw-db-input", - placeholder: l.relationSearchPage, - "aria-label": l.relationOtherPage, - }); + const input = h("input", { class: "dw-db-input", placeholder: l.relationSearchPage, "aria-label": l.relationOtherPage }); const found = h("div", { class: "dw-db-pop__list", role: "listbox" }); let seq = 0; input.addEventListener("input", async () => { @@ -143,9 +123,7 @@ export function relationTargetPanel(ctx: DbContext, anchor: Element, col: Column h("div", { class: "dw-db-pop__heading" }, p.title || l.untitled), ...(dbs.length ? dbs.map((c) => - item(c.title || l.untitled, current?.page === c.page && current.database === c.database, () => - pick(c), - ), + item(c.title || l.untitled, current?.page === c.page && current.database === c.database, () => pick(c)), ) : [h("div", { class: "dw-db-pop__empty" }, l.relationNoDatabases)]), ); @@ -302,18 +280,13 @@ export function rollupPanel(ctx: DbContext, anchor: Element, col: Column, onDone const fns = rollupFnsFor(prop ? prop.type : ""); if (!fns.includes(cfg.fn)) cfg.fn = cfg.property ? fns[0]! : "count"; box.replaceChildren( - select( - l.rollupRelation, - relations.map((c) => [c.id, c.name || l.typeRelation]), - rel.id, - (v) => { - cfg.relation = v; - cfg.property = ""; - cfg.fn = "count"; - store.setRollup(col.id, { ...cfg }); - draw(); - }, - ), + select(l.rollupRelation, relations.map((c) => [c.id, c.name || l.typeRelation]), rel.id, (v) => { + cfg.relation = v; + cfg.property = ""; + cfg.fn = "count"; + store.setRollup(col.id, { ...cfg }); + draw(); + }), select(l.rollupProperty, props, cfg.property, (v) => { cfg.property = v; const t = target?.columns.find((c) => c.id === v); @@ -321,15 +294,10 @@ export function rollupPanel(ctx: DbContext, anchor: Element, col: Column, onDone store.setRollup(col.id, { ...cfg }); draw(); }), - select( - l.rollupFn, - (cfg.property ? fns : (["count", "showOriginal"] as RollupFn[])).map((f) => [f, rollupFnLabel(l, f)]), - cfg.fn, - (v) => { - cfg.fn = v as RollupFn; - store.setRollup(col.id, { ...cfg }); - }, - ), + select(l.rollupFn, (cfg.property ? fns : (["count", "showOriginal"] as RollupFn[])).map((f) => [f, rollupFnLabel(l, f)]), cfg.fn, (v) => { + cfg.fn = v as RollupFn; + store.setRollup(col.id, { ...cfg }); + }), target ? h("span") : h("div", { class: "dw-db-pop__empty" }, l.relationMissing), ); }; @@ -348,11 +316,7 @@ export function renderRelation(ctx: DbContext, row: Row, col: Column): HTMLEleme if (c?.links && col.relation) { const target = col.relation; for (const link of c.links) { - const a = h( - "button", - { type: "button", class: "dw-db-tag dw-db-rel", dataset: { color: "gray" }, title: ctx.labels.openRelated }, - link.title || ctx.labels.untitledRow, - ); + const a = h("button", { type: "button", class: "dw-db-tag dw-db-rel", dataset: { color: "gray" }, title: ctx.labels.openRelated }, link.title || ctx.labels.untitledRow); a.addEventListener("click", (e) => { // A click on a chip opens the record; the cell itself edits. e.stopPropagation(); diff --git a/Packages/editor/src/database/store.ts b/Packages/editor/src/database/store.ts index 2bd36f2..63ee995 100644 --- a/Packages/editor/src/database/store.ts +++ b/Packages/editor/src/database/store.ts @@ -35,7 +35,7 @@ type YItem = Y.Map; export function dbToY(data: DbData): YItem { const m = new Y.Map(); m.set("title", data.title); - const list = (items: T[], toY: (x: T) => YItem) => { + const list = (items: T[], toY: (x: T) => YItem) => { const a = new Y.Array(); a.push(items.map((x, i) => withPos(toY(x), i))); return a; diff --git a/Packages/editor/src/database/touchdrag.ts b/Packages/editor/src/database/touchdrag.ts index 0710e9e..bfc37b5 100644 --- a/Packages/editor/src/database/touchdrag.ts +++ b/Packages/editor/src/database/touchdrag.ts @@ -66,10 +66,7 @@ export function touchDraggable(handle: HTMLElement, d: TouchDrag): void { const dx = x < EDGE ? -1 : x > innerWidth - EDGE ? 1 : 0; const dy = y < EDGE ? -1 : y > innerHeight - EDGE ? 1 : 0; let moved = false; - for (const [axis, dir] of [ - ["x", dx], - ["y", dy], - ] as const) { + for (const [axis, dir] of [["x", dx], ["y", dy]] as const) { if (!dir) continue; const s = scroller(d.source, axis) ?? (axis === "y" ? document.scrollingElement : null); if (!s) continue; diff --git a/Packages/editor/src/database/twoway.test.ts b/Packages/editor/src/database/twoway.test.ts index ec7be06..4cc0b87 100644 --- a/Packages/editor/src/database/twoway.test.ts +++ b/Packages/editor/src/database/twoway.test.ts @@ -44,9 +44,7 @@ const projects: DbData = { /** What a column's cells show, row by row. */ const readRelationCell = (node: HTMLElement, col: string) => - [...node.querySelectorAll(`tbody tr[data-row] td[data-col="${col}"]`)].map( - (td) => td.textContent?.trim() ?? "", - ); + [...node.querySelectorAll(`tbody tr[data-row] td[data-col="${col}"]`)].map((td) => td.textContent?.trim() ?? ""); const nodes = () => [...document.querySelectorAll(".dw-db-node")]; const clickText = (selector: string, text: string) => { const el = [...document.querySelectorAll(selector)].find((e) => e.textContent?.includes(text)); @@ -60,9 +58,7 @@ function mount(doc: Y.Doc) { document.body.append(el); editor = new Editor({ element: el, - extensions: docwellExtensions({ - collab: { provider: { doc, awareness: new Awareness(doc) } as never, user: { name: "A", color: "#888" } }, - }), + extensions: docwellExtensions({ collab: { provider: { doc, awareness: new Awareness(doc) } as never, user: { name: "A", color: "#888" } } }), }); // Seeded under fixed ids, so the relation finds its database. editor.commands.setContent({ @@ -84,9 +80,7 @@ it("adds the other side and keeps links in the relation that stores them", async expect(nodes()).toHaveLength(2); // Projects → column menu → Related database → "Show on “Tasks” too". - const head = [...nodes()[0]!.querySelectorAll(".dw-db-t__head")].find((b) => - b.textContent?.includes("Tasks"), - )!; + const head = [...nodes()[0]!.querySelectorAll(".dw-db-t__head")].find((b) => b.textContent?.includes("Tasks"))!; head.click(); clickText(".dw-block-menu [role=menuitem]", "Related database"); clickText(".dw-db-pop button", "Show on “Tasks” too"); @@ -130,9 +124,7 @@ it("offers to mirror a relation that already links here", async () => { // A new property starts as a name field; its menu sets the related database. (document.activeElement as HTMLElement | null)?.blur(); await flush(); - const head = [...nodes()[1]!.querySelectorAll(".dw-db-t__head")].find((x) => - x.textContent?.includes("Relation"), - )!; + const head = [...nodes()[1]!.querySelectorAll(".dw-db-t__head")].find((x) => x.textContent?.includes("Relation"))!; head.click(); clickText(".dw-block-menu [role=menuitem]", "Related database"); clickText(".dw-db-pop [role=option]", "Projects"); diff --git a/Packages/editor/src/database/view.ts b/Packages/editor/src/database/view.ts index 6ddfd07..d2b3e3b 100644 --- a/Packages/editor/src/database/view.ts +++ b/Packages/editor/src/database/view.ts @@ -92,12 +92,7 @@ export class DatabaseView { const now = new Date(); this.month = { y: now.getFullYear(), m: now.getMonth() }; const l = host.labels; - this.searchInput = h("input", { - class: "dw-db-input dw-db__search", - placeholder: l.search, - "aria-label": l.search, - hidden: true, - }); + this.searchInput = h("input", { class: "dw-db-input dw-db__search", placeholder: l.search, "aria-label": l.search, hidden: true }); this.searchInput.addEventListener("input", () => { this.search = this.searchInput.value; this.limit = PAGE; @@ -283,15 +278,10 @@ export class DatabaseView { const l = this.labels; this.bulk.replaceChildren( h("span", {}, fill(l.selected, ids.length)), - iconButton( - "trash", - l.deleteRows, - () => { - this.host.store?.deleteRows(ids); - this.picked.clear(); - }, - l.deleteRows, - ), + iconButton("trash", l.deleteRows, () => { + this.host.store?.deleteRows(ids); + this.picked.clear(); + }, l.deleteRows), iconButton("close", l.close, () => { this.picked.clear(); this.draw(); @@ -358,13 +348,7 @@ export class DatabaseView { }, ]; if (this.db.views.length > 1) { - actions.push({ - id: "delete", - label: l.deleteView, - icon: "trash", - danger: true, - run: () => store.deleteView(v.id), - }); + actions.push({ id: "delete", label: l.deleteView, icon: "trash", danger: true, run: () => store.deleteView(v.id) }); } openBlockMenu(anchor, actions, l.layout); } @@ -380,8 +364,7 @@ export class DatabaseView { private setLayout(v: View, type: ViewType) { const patch: Partial = { type }; const cols = this.db.columns; - if (type === "kanban" && !v.groupBy) - patch.groupBy = cols.find((c) => ["select", "multiSelect", "checkbox", "member"].includes(c.type))?.id ?? null; + if (type === "kanban" && !v.groupBy) patch.groupBy = cols.find((c) => ["select", "multiSelect", "checkbox", "member"].includes(c.type))?.id ?? null; if (type === "gallery" && !v.cover) patch.cover = cols.find((c) => c.type === "attachment")?.id ?? null; const dated = type === "calendar" || type === "timeline"; if (dated && !v.dateColumn) patch.dateColumn = cols.find((c) => c.type === "date")?.id ?? null; @@ -439,19 +422,13 @@ export class DatabaseView { ids.set(first.id, title.id); } for (const c of rest) { - const existing = this.db.columns.find( - (x) => x.name.toLowerCase() === c.name.toLowerCase() && x.type !== "title", - ); + const existing = this.db.columns.find((x) => x.name.toLowerCase() === c.name.toLowerCase() && x.type !== "title"); if (existing) store.deleteColumn(existing.id); const id = store.addColumn(c.type, c.name); if (c.options) store.setOptions(id, c.options); ids.set(c.id, id); } - store.addRows( - parsed.rows.map((cells) => - Object.fromEntries(Object.entries(cells).map(([k, val]) => [ids.get(k) ?? k, val])), - ), - ); + store.addRows(parsed.rows.map((cells) => Object.fromEntries(Object.entries(cells).map(([k, val]) => [ids.get(k) ?? k, val])))); this.host.notify?.(fill(this.labels.imported, parsed.rows.length)); return; } @@ -592,14 +569,7 @@ export class DatabaseView { const add = h("button", { type: "button", class: "dw-db-t__new" }, icon("plus", 14), h("span", {}, l.newRow)); add.addEventListener("click", () => { const cells: Record = {}; - if (group && g.key) - cells[group.id] = moveToGroup( - { id: "", cells: {}, createdAt: 0, createdBy: null }, - group, - "", - g.key, - g.rows.flatMap((x) => asPeople(cellValue(x, group))), - ); + if (group && g.key) cells[group.id] = moveToGroup({ id: "", cells: {}, createdAt: 0, createdBy: null }, group, "", g.key, g.rows.flatMap((x) => asPeople(cellValue(x, group)))); else if (group?.type === "checkbox") cells[group.id] = g.key === "true"; this.addRow(cells); }); @@ -608,19 +578,11 @@ export class DatabaseView { table.append(tbody); } const children: Node[] = []; - const wrap = h( - "div", - { class: "dw-db-t__wrap", role: "grid", tabIndex: 0, "aria-label": this.db.title || l.database }, - table, - ); + const wrap = h("div", { class: "dw-db-t__wrap", role: "grid", tabIndex: 0, "aria-label": this.db.title || l.database }, table); children.push(wrap); if (!rows.length) children.push(h("p", { class: "dw-db__empty" }, this.db.rows.length ? l.noMatches : l.noRows)); if (rows.length > shown && shown >= this.limit) { - const more = h( - "button", - { type: "button", class: "dw-db__btn dw-db__more" }, - `${l.more} (${rows.length - shown})`, - ); + const more = h("button", { type: "button", class: "dw-db__btn dw-db__more" }, `${l.more} (${rows.length - shown})`); more.addEventListener("click", () => { this.limit += PAGE; this.drawBody(); @@ -667,10 +629,7 @@ export class DatabaseView { const id = e.dataTransfer?.getData("application/x-docwell-column"); if (!id || id === c.id) return; e.preventDefault(); - this.host.store?.moveColumn( - id, - this.db.columns.findIndex((x) => x.id === c.id), - ); + this.host.store?.moveColumn(id, this.db.columns.findIndex((x) => x.id === c.id)); }); // Drag the right edge to resize; the width is saved with the view. const grip = h("span", { class: "dw-db-t__resize", title: l.resize, "aria-hidden": "true" }); @@ -715,7 +674,9 @@ export class DatabaseView { } const all = this.db.columns; const at = all.findIndex((x) => x.id === c.id); - const actions: BlockAction[] = [{ id: "rename", label: l.rename, icon: "pencil", run: () => this.renameColumn(c) }]; + const actions: BlockAction[] = [ + { id: "rename", label: l.rename, icon: "pencil", run: () => this.renameColumn(c) }, + ]; if (c.type !== "title") { actions.push({ id: "type", @@ -734,19 +695,9 @@ export class DatabaseView { }); } if (c.type === "relation") - actions.push({ - id: "relationTo", - label: l.relationTo, - icon: "relation", - run: () => this.linkSettings(anchor, c.id), - }); + actions.push({ id: "relationTo", label: l.relationTo, icon: "relation", run: () => this.linkSettings(anchor, c.id) }); if (c.type === "rollup") - actions.push({ - id: "rollup", - label: l.rollupSettings, - icon: "rollup", - run: () => this.linkSettings(anchor, c.id), - }); + actions.push({ id: "rollup", label: l.rollupSettings, icon: "rollup", run: () => this.linkSettings(anchor, c.id) }); actions.push(sortBy(false), sortBy(true), { id: "filter", label: l.filterBy, @@ -756,26 +707,13 @@ export class DatabaseView { this.buttons.filter.click(); }, }); - if (c.type !== "title") - actions.push({ - id: "hide", - label: l.hide, - icon: "close", - run: () => store.updateView(v.id, { hidden: [...v.hidden, c.id] }), - }); + if (c.type !== "title") actions.push({ id: "hide", label: l.hide, icon: "close", run: () => store.updateView(v.id, { hidden: [...v.hidden, c.id] }) }); actions.push( { id: "left", label: l.insertLeft, icon: "plus", run: () => this.insertColumn(at) }, { id: "right", label: l.insertRight, icon: "plus", run: () => this.insertColumn(at + 1) }, ); - if (at > 0) - actions.push({ id: "moveLeft", label: l.moveLeft, icon: "arrow-up", run: () => store.moveColumn(c.id, at - 1) }); - if (at < all.length - 1) - actions.push({ - id: "moveRight", - label: l.moveRight, - icon: "arrow-down", - run: () => store.moveColumn(c.id, at + 1), - }); + if (at > 0) actions.push({ id: "moveLeft", label: l.moveLeft, icon: "arrow-up", run: () => store.moveColumn(c.id, at - 1) }); + if (at < all.length - 1) actions.push({ id: "moveRight", label: l.moveRight, icon: "arrow-down", run: () => store.moveColumn(c.id, at + 1) }); if (c.type !== "title") { actions.push( { id: "duplicate", label: l.duplicate, icon: "copy", run: () => store.duplicateColumn(c.id, `${c.name} 2`) }, @@ -859,12 +797,7 @@ export class DatabaseView { const tr = h("tr", { dataset: { row: r.id }, class: this.picked.has(r.id) ? "is-picked" : "" }); const gutter = h("td", { class: "dw-db-t__gutter" }); if (this.editable) { - const check = h("input", { - type: "checkbox", - class: "dw-db-t__pick", - "aria-label": l.selectRow, - checked: this.picked.has(r.id), - }); + const check = h("input", { type: "checkbox", class: "dw-db-t__pick", "aria-label": l.selectRow, checked: this.picked.has(r.id) }); check.addEventListener("change", () => { if (check.checked) this.picked.add(r.id); else this.picked.delete(r.id); @@ -873,11 +806,7 @@ export class DatabaseView { }); gutter.append(check); if (movable) { - const grip = h( - "span", - { class: "dw-db-t__grip", draggable: true, title: l.dragRow, "aria-hidden": "true" }, - icon("grip", 14), - ); + const grip = h("span", { class: "dw-db-t__grip", draggable: true, title: l.dragRow, "aria-hidden": "true" }, icon("grip", 14)); grip.addEventListener("dragstart", (e) => { e.dataTransfer?.setData("application/x-docwell-row", r.id); if (e.dataTransfer) e.dataTransfer.effectAllowed = "move"; @@ -927,18 +856,9 @@ export class DatabaseView { } tr.append(gutter); for (const c of cols) { - const td = h( - "td", - { dataset: { col: c.id }, class: `dw-db-t__cell dw-db-t__cell--${c.type}`, role: "gridcell" }, - renderCell(this.ctx(), r, c), - ); + const td = h("td", { dataset: { col: c.id }, class: `dw-db-t__cell dw-db-t__cell--${c.type}`, role: "gridcell" }, renderCell(this.ctx(), r, c)); if (c.type === "title") { - const open = h( - "button", - { type: "button", class: "dw-db-t__open", title: l.openRow }, - icon("open", 13), - h("span", {}, l.openRow), - ); + const open = h("button", { type: "button", class: "dw-db-t__open", title: l.openRow }, icon("open", 13), h("span", {}, l.openRow)); open.addEventListener("click", (e) => { e.stopPropagation(); this.openRow(r.id); @@ -1018,8 +938,7 @@ export class DatabaseView { private markSelection() { if (!this.grid) return; - for (const el of this.grid.querySelectorAll(".is-selected, .is-in-range")) - el.classList.remove("is-selected", "is-in-range"); + for (const el of this.grid.querySelectorAll(".is-selected, .is-in-range")) el.classList.remove("is-selected", "is-in-range"); const rg = this.range(); if (!rg || !this.sel) return; for (let r = rg.r0; r <= rg.r1; r++) { @@ -1033,10 +952,7 @@ export class DatabaseView { } private cellEl(row: string, col: string): HTMLElement | null { - return ( - this.grid?.querySelector(`tr[data-row="${CSS.escape(row)}"] td[data-col="${CSS.escape(col)}"]`) ?? - null - ); + return this.grid?.querySelector(`tr[data-row="${CSS.escape(row)}"] td[data-col="${CSS.escape(col)}"]`) ?? null; } private startEdit(initial?: string) { @@ -1083,12 +999,7 @@ export class DatabaseView { return this.host.redo(); } if (mod) return; - const arrows: Record = { - ArrowUp: [-1, 0], - ArrowDown: [1, 0], - ArrowLeft: [0, -1], - ArrowRight: [0, 1], - }; + const arrows: Record = { ArrowUp: [-1, 0], ArrowDown: [1, 0], ArrowLeft: [0, -1], ArrowRight: [0, 1] }; const step = arrows[e.key]; if (step) { e.preventDefault(); @@ -1123,8 +1034,7 @@ export class DatabaseView { for (let r = rg.r0; r <= rg.r1; r++) { for (let c = rg.c0; c <= rg.c1; c++) { const col = this.tableCols[c]!; - if (!readOnlyTypes.includes(col.type) && !isBackRelation(col)) - changes.push({ row: this.tableRows[r]!.id, col: col.id, value: null }); + if (!readOnlyTypes.includes(col.type) && !isBackRelation(col)) changes.push({ row: this.tableRows[r]!.id, col: col.id, value: null }); } } this.host.store.setCells(changes); @@ -1235,13 +1145,7 @@ export class DatabaseView { for (const r of g.rows.slice(0, this.limit)) { const card = h( "div", - { - class: "dw-db-k__card", - tabIndex: 0, - role: "button", - draggable: this.editable && !readOnlyTypes.includes(col.type), - dataset: { row: r.id }, - }, + { class: "dw-db-k__card", tabIndex: 0, role: "button", draggable: this.editable && !readOnlyTypes.includes(col.type), dataset: { row: r.id } }, h("div", { class: "dw-db-k__title" }, renderCell(this.ctx(), r, title)), shown.flatMap((c) => { if (cellText(r, c) === "" || (c.type === "checkbox" && cellValue(r, c) !== true)) return []; @@ -1280,8 +1184,7 @@ export class DatabaseView { }, drop: (t) => { const at = listAt(t); - if (at) - dropCard(r.id, g.key, at.dataset.group ?? "", t?.closest(".dw-db-k__card")?.dataset.row); + if (at) dropCard(r.id, g.key, at.dataset.group ?? "", t?.closest(".dw-db-k__card")?.dataset.row); }, end: () => mark?.classList.remove("is-drop"), }); @@ -1292,10 +1195,7 @@ export class DatabaseView { const add = h("button", { type: "button", class: "dw-db-t__new" }, icon("plus", 14), h("span", {}, l.newRow)); add.addEventListener("click", () => { const blank: Row = { id: "", cells: {}, createdAt: 0, createdBy: null }; - this.addRow( - g.key || col.type === "checkbox" ? { [col.id]: moveToGroup(blank, col, "", g.key, people) } : {}, - true, - ); + this.addRow(g.key || col.type === "checkbox" ? { [col.id]: moveToGroup(blank, col, "", g.key, people) } : {}, true); }); list.append(add); list.addEventListener("dragover", (e) => { @@ -1354,9 +1254,7 @@ export class DatabaseView { h( "div", { class: src ? "dw-db-i__cover" : "dw-db-i__cover is-empty", "aria-hidden": "true" }, - src - ? h("img", { src: ctx.files ? ctx.files.resolve(src) : src, alt: "", loading: "lazy", draggable: false }) - : null, + src ? h("img", { src: ctx.files ? ctx.files.resolve(src) : src, alt: "", loading: "lazy", draggable: false }) : null, ), ); } @@ -1412,23 +1310,12 @@ export class DatabaseView { items.append(item(r)); } if (this.editable && count < this.limit) { - const add = h( - "button", - { type: "button", class: "dw-db-t__new dw-db-i__new" }, - icon("plus", 14), - h("span", {}, l.newRow), - ); + const add = h("button", { type: "button", class: "dw-db-t__new dw-db-i__new" }, icon("plus", 14), h("span", {}, l.newRow)); add.addEventListener("click", () => { const cells: Record = {}; if (group && (g.key || group.type === "checkbox")) { const blank: Row = { id: "", cells: {}, createdAt: 0, createdBy: null }; - cells[group.id] = moveToGroup( - blank, - group, - "", - g.key, - g.rows.flatMap((x) => asPeople(cellValue(x, group))), - ); + cells[group.id] = moveToGroup(blank, group, "", g.key, g.rows.flatMap((x) => asPeople(cellValue(x, group)))); } this.addRow(cells, true); }); @@ -1440,11 +1327,7 @@ export class DatabaseView { const children: Node[] = [wrap]; if (!rows.length) children.push(h("p", { class: "dw-db__empty" }, this.db.rows.length ? l.noMatches : l.noRows)); if (rows.length > count && count >= this.limit) { - const more = h( - "button", - { type: "button", class: "dw-db__btn dw-db__more" }, - `${l.more} (${rows.length - count})`, - ); + const more = h("button", { type: "button", class: "dw-db__btn dw-db__more" }, `${l.more} (${rows.length - count})`); more.addEventListener("click", () => { this.limit += PAGE; this.drawBody(); @@ -1486,8 +1369,7 @@ export class DatabaseView { else undated.push(r); } const locale = this.host.locale; - const fmt = (day: string, o: Intl.DateTimeFormatOptions) => - new Date(`${day}T12:00:00Z`).toLocaleDateString(locale, { ...o, timeZone: "UTC" }); + const fmt = (day: string, o: Intl.DateTimeFormatOptions) => new Date(`${day}T12:00:00Z`).toLocaleDateString(locale, { ...o, timeZone: "UTC" }); // Navigation and zoom. const go = (n: number) => { @@ -1497,15 +1379,7 @@ export class DatabaseView { const zoom = h("div", { class: "dw-db-tl__zoom", role: "group" }); for (const sc of timelineScales) { const label = sc === "day" ? l.scaleDay : sc === "week" ? l.scaleWeek : l.scaleMonth; - const b = h( - "button", - { - type: "button", - class: sc === scale ? "dw-db__btn is-on" : "dw-db__btn", - "aria-pressed": String(sc === scale), - }, - label, - ); + const b = h("button", { type: "button", class: sc === scale ? "dw-db__btn is-on" : "dw-db__btn", "aria-pressed": String(sc === scale) }, label); b.addEventListener("click", () => { this.tlFrom = ""; if (this.editable && this.host.store) { @@ -1521,22 +1395,13 @@ export class DatabaseView { const nav = h( "div", { class: "dw-db-c__nav" }, - h( - "strong", - { class: "dw-db-c__month" }, - `${fmt(from, { day: "numeric", month: "short" })} – ${fmt(last, { day: "numeric", month: "short", year: "numeric" })}`, - ), + h("strong", { class: "dw-db-c__month" }, `${fmt(from, { day: "numeric", month: "short" })} – ${fmt(last, { day: "numeric", month: "short", year: "numeric" })}`), iconButton("chevron-left", l.earlier, () => go(-step)), iconButton("chevron-right", l.later, () => go(step)), - iconButton( - "calendar", - l.today, - () => { - this.tlFrom = ""; - this.drawBody(); - }, - l.today, - ), + iconButton("calendar", l.today, () => { + this.tlFrom = ""; + this.drawBody(); + }, l.today), zoom, ); @@ -1549,16 +1414,12 @@ export class DatabaseView { let label = ""; if (scale === "day") label = fmt(day, { weekday: "narrow", day: "numeric" }); else if (scale === "week" && dow === 0) label = fmt(day, { day: "numeric", month: "short" }); - else if (scale === "month" && day.endsWith("-01")) - label = fmt(day, { month: "short", year: day.slice(5, 7) === "01" ? "numeric" : undefined }); + else if (scale === "month" && day.endsWith("-01")) label = fmt(day, { month: "short", year: day.slice(5, 7) === "01" ? "numeric" : undefined }); const weekend = dow >= 5 && scale !== "month"; if (!label && !weekend) continue; const tick = h( "span", - { - class: `dw-db-tl__tick${label ? "" : " is-blank"}${weekend ? " is-weekend" : ""}`, - style: { left: `${i * px}px`, width: `${px}px` }, - }, + { class: `dw-db-tl__tick${label ? "" : " is-blank"}${weekend ? " is-weekend" : ""}`, style: { left: `${i * px}px`, width: `${px}px` } }, label, ); ticks.append(tick); @@ -1566,24 +1427,14 @@ export class DatabaseView { const todayAt = daysBetween(from, today); const marks = (): Node[] => { const out: Node[] = []; - if (todayAt >= 0 && todayAt < days) - out.push( - h("span", { class: "dw-db-tl__today", style: { left: `${todayAt * px + px / 2}px` }, "aria-hidden": "true" }), - ); + if (todayAt >= 0 && todayAt < days) out.push(h("span", { class: "dw-db-tl__today", style: { left: `${todayAt * px + px / 2}px` }, "aria-hidden": "true" })); return out; }; const grid = h("div", { class: "dw-db-tl__grid" }); grid.style.setProperty("--dw-tl-width", `${width}px`); grid.style.setProperty("--dw-tl-day", `${px}px`); - grid.append( - h( - "div", - { class: "dw-db-tl__row dw-db-tl__row--head" }, - h("div", { class: "dw-db-tl__label" }), - h("div", { class: "dw-db-tl__track" }, ticks, ...marks()), - ), - ); + grid.append(h("div", { class: "dw-db-tl__row dw-db-tl__row--head" }, h("div", { class: "dw-db-tl__label" }), h("div", { class: "dw-db-tl__track" }, ticks, ...marks()))); for (const { r, span } of placed.slice(0, this.limit)) { const name = cellText(r, title) || l.untitledRow; @@ -1613,32 +1464,23 @@ export class DatabaseView { this.openRow(r.id); } }); - const handle = - movable && end && b <= days - ? h("span", { class: "dw-db-tl__handle", title: l.dragEnd, "aria-hidden": "true" }) - : null; + const handle = movable && end && b <= days ? h("span", { class: "dw-db-tl__handle", title: l.dragEnd, "aria-hidden": "true" }) : null; if (handle) bar.append(handle); - this.dragBar( - bar, - handle, - px, - (moved, resized) => { - const store = this.host.store; - if (!store) return; - if (!moved && !resized) return this.openRow(r.id); - store.tx(() => { - if (resized) { - const to = addDays(span.to, resized); - if (end) store.setCell(r.id, end.id, to < span.from ? span.from : to); - return; - } - store.setCell(r.id, start.id, addDays(span.from, moved)); - // A record with an end keeps its length. - if (end && dateOf(cellValue(r, end))) store.setCell(r.id, end.id, addDays(span.to, moved)); - }); - }, - movable, - ); + this.dragBar(bar, handle, px, (moved, resized) => { + const store = this.host.store; + if (!store) return; + if (!moved && !resized) return this.openRow(r.id); + store.tx(() => { + if (resized) { + const to = addDays(span.to, resized); + if (end) store.setCell(r.id, end.id, to < span.from ? span.from : to); + return; + } + store.setCell(r.id, start.id, addDays(span.from, moved)); + // A record with an end keeps its length. + if (end && dateOf(cellValue(r, end))) store.setCell(r.id, end.id, addDays(span.to, moved)); + }); + }, movable); track.append(bar); } grid.append(h("div", { class: "dw-db-tl__row" }, label, track)); @@ -1652,11 +1494,7 @@ export class DatabaseView { const children: Node[] = [nav, scroller]; if (!rows.length) children.push(h("p", { class: "dw-db__empty" }, this.db.rows.length ? l.noMatches : l.noRows)); if (placed.length > this.limit) { - const more = h( - "button", - { type: "button", class: "dw-db__btn dw-db__more" }, - `${l.more} (${placed.length - this.limit})`, - ); + const more = h("button", { type: "button", class: "dw-db__btn dw-db__more" }, `${l.more} (${placed.length - this.limit})`); more.addEventListener("click", () => { this.limit += PAGE; this.drawBody(); @@ -1669,14 +1507,7 @@ export class DatabaseView { chip.addEventListener("click", () => this.openRow(r.id)); return chip; }); - children.push( - h( - "details", - { class: "dw-db-c__undated" }, - h("summary", {}, fill(l.noDate, undated.length)), - h("div", { class: "dw-db-c__chips" }, chips), - ), - ); + children.push(h("details", { class: "dw-db-c__undated" }, h("summary", {}, fill(l.noDate, undated.length)), h("div", { class: "dw-db-c__chips" }, chips))); } this.body.replaceChildren(h("div", { class: "dw-db-tl" }, children)); } @@ -1687,13 +1518,7 @@ export class DatabaseView { * plain click or tap). Touch drags go sideways only, so the page still * scrolls up and down. */ - private dragBar( - bar: HTMLElement, - handle: HTMLElement | null, - px: number, - done: (moved: number, resized: number) => void, - movable: boolean, - ) { + private dragBar(bar: HTMLElement, handle: HTMLElement | null, px: number, done: (moved: number, resized: number) => void, movable: boolean) { // The block around it is draggable; a bar must not start the browser's own drag. bar.addEventListener("dragstart", (e) => { e.preventDefault(); @@ -1789,24 +1614,15 @@ export class DatabaseView { h("strong", { class: "dw-db-c__month" }, monthName), iconButton("chevron-left", l.previousMonth, () => go(-1)), iconButton("chevron-right", l.nextMonth, () => go(1)), - iconButton( - "calendar", - l.today, - () => { - const d = new Date(); - this.month = { y: d.getFullYear(), m: d.getMonth() }; - this.drawBody(); - }, - l.today, - ), + iconButton("calendar", l.today, () => { + const d = new Date(); + this.month = { y: d.getFullYear(), m: d.getMonth() }; + this.drawBody(); + }, l.today), ); const week = days.slice(0, 7).map((d) => { const [yy, mm, dd] = d.split("-").map(Number); - return h( - "div", - { class: "dw-db-c__wd" }, - new Date(yy!, mm! - 1, dd!).toLocaleDateString(this.host.locale, { weekday: "short" }), - ); + return h("div", { class: "dw-db-c__wd" }, new Date(yy!, mm! - 1, dd!).toLocaleDateString(this.host.locale, { weekday: "short" })); }); const chip = (r: Row) => { const el = h( @@ -1847,20 +1663,12 @@ export class DatabaseView { const inMonth = Number(d.slice(5, 7)) === m + 1; const cell = h( "div", - { - class: `dw-db-c__day${inMonth ? "" : " is-out"}${d === today ? " is-today" : ""}`, - role: "gridcell", - dataset: { day: d }, - }, + { class: `dw-db-c__day${inMonth ? "" : " is-out"}${d === today ? " is-today" : ""}`, role: "gridcell", dataset: { day: d } }, h("span", { class: "dw-db-c__num" }, String(Number(d.slice(8)))), (byDay.get(d) ?? []).map(chip), ); if (this.editable && col.type === "date") { - const add = h( - "button", - { type: "button", class: "dw-db-c__add", "aria-label": `${l.newRow} ${d}`, title: l.newRow }, - icon("plus", 12), - ); + const add = h("button", { type: "button", class: "dw-db-c__add", "aria-label": `${l.newRow} ${d}`, title: l.newRow }, icon("plus", 12)); add.addEventListener("click", () => this.addRow({ [col.id]: d }, true)); cell.append(add); } @@ -1928,3 +1736,4 @@ const groupedLayouts: ViewType[] = ["table", "list", "gallery"]; function asPeople(v: unknown) { return Array.isArray(v) ? (v as { id: string; name: string }[]).filter((p) => p && typeof p.id === "string") : []; } +