@jsudc/react 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"TreeRenderer.js","names":[],"sources":["../../src/tree/TreeRenderer.tsx"],"sourcesContent":["import {\n type CollisionDetection,\n DndContext,\n type DragEndEvent,\n DragOverlay,\n type DragStartEvent,\n PointerSensor,\n pointerWithin,\n TouchSensor,\n useSensor,\n useSensors,\n} from \"@dnd-kit/core\";\nimport {\n type FilterNode,\n isVersionConflict,\n type Row,\n type TreeOptions,\n UdcError,\n} from \"@jsudc/core\";\nimport { useQueryClient } from \"@tanstack/react-query\";\nimport { ChevronsDownUp, ChevronsUpDown, ListTree } from \"lucide-react\";\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { useI18n } from \"../i18n/i18n.js\";\nimport { CardDetailDialog } from \"../kanban/CardDetailDialog.js\";\nimport { AllRowsStatus } from \"../renderers/AllRowsStatus.js\";\nimport type { RendererProps } from \"../renderers/types.js\";\nimport { EmptyState, ErrorState } from \"../table/states.js\";\nimport { useUdcAllRows, useUdcCollection, useUdcMutate } from \"../udc/hooks.js\";\nimport { udcKeys } from \"../udc/keys.js\";\nimport { useUdcClient } from \"../udc/provider.js\";\nimport { useUiKit } from \"../ui-kit/context.js\";\nimport { type TreeExpand, useTreeExpand } from \"./expand.js\";\nimport {\n type BuiltTree,\n buildTree,\n canDrop,\n type DropTarget,\n dropParent,\n idOf,\n lazyChildrenQuery,\n lazyRootsQuery,\n numberOf,\n parentOf,\n parseDropId,\n planDrop,\n reparentRequest,\n replyRow,\n searchExpansion,\n siblingsQuery,\n sortSiblings,\n} from \"./model.js\";\nimport { TreeNode, TreeNodeLabel } from \"./TreeNode.js\";\n\n/** A node moved in this session, drawn at its new place until the lists are read again. */\ninterface Moved {\n row: Row;\n parent: string | null;\n order: number;\n}\n\nexport interface TreeCtx {\n collection: string;\n opts: TreeOptions;\n describe: RendererProps[\"describe\"];\n lazy: boolean;\n /** What every lazy branch adds to its own condition: the data view's filter. */\n dataFilter: FilterNode | undefined;\n /** The text sent as `search` with every list (a source that answers search); absent otherwise. */\n dataSearch?: string | undefined;\n /** The highlighted search term (\"\" when none). */\n term: string;\n isOpen: (id: string, depth: number) => boolean;\n setOpen: (id: string, open: boolean) => void;\n /** Non-lazy: the children of a node as built from the loaded rows. */\n childrenOf: (id: string) => Row[];\n /** Rows moved in this session, by id. */\n moved: ReadonlyMap<string, Moved>;\n orphans: ReadonlySet<string>;\n can: { rename: boolean; reply: boolean; reparent: boolean };\n /** The id being dragged, and the loaded rows the drop targets are checked against. */\n drag: { id: string; rowsById: ReadonlyMap<string, Row> } | null;\n /** Lazy branches report the rows they loaded (for drop gating). */\n report: (parent: string, rows: Row[]) => void;\n onOpenDetail: (row: Row) => void;\n onRename: (row: Row, label: string) => Promise<void>;\n onReply: (parent: Row, text: string) => Promise<void>;\n}\n\nconst Ctx = createContext<TreeCtx | null>(null);\n\nexport function useTree(): TreeCtx {\n const ctx = useContext(Ctx);\n if (!ctx) throw new Error(\"useTree needs a <TreeRenderer> above it\");\n return ctx;\n}\n\n/** Rows as drawn under `parent`: the loaded ones minus those moved away, plus those moved here. */\nexport function withMoves(\n rows: readonly Row[],\n parent: string | null,\n moved: ReadonlyMap<string, Moved>,\n ctx: Pick<TreeCtx, \"opts\">,\n): Row[] {\n const { opts } = ctx;\n const stay = rows.filter((r) => {\n const m = moved.get(idOf(r));\n return !m || m.parent === parent;\n });\n const here = [...moved.values()]\n .filter((m) => m.parent === parent && !stay.some((r) => idOf(r) === idOf(m.row)))\n .map((m) => m.row);\n const patched = [...stay, ...here].map((r) => {\n const m = moved.get(idOf(r));\n return m ? { ...r, [opts.parent_field]: m.parent, [opts.order_field]: m.order } : r;\n });\n return sortSiblings(patched, opts.sibling_sort);\n}\n\nexport function TreeRenderer(props: RendererProps) {\n const { t } = useI18n();\n const opts = props.describe.view.tree_options;\n if (!opts) {\n return (\n <div className=\"udc:p-6 udc:text-sm udc:text-muted-foreground\" data-testid=\"tree-no-options\">\n {t(\"APP\", \"TREE_NO_OPTIONS\")}\n </div>\n );\n }\n return <Tree {...props} opts={opts} />;\n}\n\nconst SKELETON = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"];\n\nfunction Tree({\n collection,\n describe,\n filter,\n baseFilter,\n search,\n listSearch,\n filtered,\n onClearFilters,\n onCount,\n opts,\n}: RendererProps & { opts: TreeOptions }) {\n const { Button, Skeleton, useToast } = useUiKit();\n const { t } = useI18n();\n const { toast } = useToast();\n const client = useUdcClient();\n const qc = useQueryClient();\n const { capabilities, schema, view } = describe;\n const lazy = opts.lazy;\n const term = search.trim();\n // highlight_and_expand on a loaded tree searches in the browser; anything else asks the server.\n const clientSearch = !lazy && opts.on_search.mode === \"highlight_and_expand\";\n // A source that answers search gets the text, unless the tree searches what it loaded.\n const serverSearch = clientSearch ? undefined : listSearch;\n // A lazy tree lists the matches of a filter flat; a source search alone is such a filter too.\n const dataFilter: FilterNode | undefined = clientSearch\n ? baseFilter\n : (filter ?? (serverSearch === undefined ? undefined : { and: [] }));\n const highlight = opts.on_search.mode === \"highlight_and_expand\" ? term : \"\";\n\n // --- rows ----------------------------------------------------------------------\n const all = useUdcAllRows({\n collection,\n filter: dataFilter,\n sort: opts.sibling_sort,\n capabilities,\n enabled: !lazy,\n refetchInterval: describe.view.refresh_interval_ms,\n search: serverSearch,\n });\n const rootsQ = lazyRootsQuery(opts, dataFilter);\n const roots = useUdcCollection({\n collection,\n filter: rootsQ.filter,\n sort: rootsQ.sort ?? [],\n mode: \"pages\",\n pageLimit: rootsQ.limit,\n enabled: lazy,\n search: serverSearch,\n });\n const totalQ = useUdcCollection({\n collection,\n filter: dataFilter,\n mode: \"pages\",\n pageLimit: 1,\n enabled: lazy,\n search: serverSearch,\n });\n\n const [moved, setMoved] = useState<ReadonlyMap<string, Moved>>(new Map());\n const tree: BuiltTree = useMemo(\n () =>\n buildTree(\n all.rows.map((r) => {\n const m = moved.get(idOf(r));\n return m ? { ...r, [opts.parent_field]: m.parent, [opts.order_field]: m.order } : r;\n }),\n opts,\n ),\n [all.rows, moved, opts],\n );\n\n // A filtered lazy tree lists every match; those under a listed parent show when it opens.\n const lazyRoots = useMemo(() => {\n const ids = new Set(roots.rows.map(idOf));\n const top = roots.rows.filter((r) => {\n const p = parentOf(r, opts);\n return p === null || !ids.has(p);\n });\n return withMoves(top, null, moved, { opts });\n }, [roots.rows, moved, opts]);\n const lazyOrphans = useMemo(\n () => new Set(lazyRoots.filter((r) => parentOf(r, opts) !== null).map(idOf)),\n [lazyRoots, opts],\n );\n\n useEffect(() => {\n onCount(\n lazy\n ? totalQ.total === null\n ? null\n : { shown: lazyRoots.length, total: totalQ.total, unit: \"nodes\" }\n : all.total === null\n ? null\n : { shown: all.rows.length, total: all.rows.length, unit: \"nodes\" },\n );\n }, [onCount, lazy, lazyRoots.length, totalQ.total, all.rows.length, all.total]);\n useEffect(() => () => onCount(null), [onCount]);\n\n // --- expand state (with the search's own, while there is a term) ---------------------\n const expand: TreeExpand = useTreeExpand(opts, collection);\n const expansion = useMemo(\n () =>\n clientSearch && term\n ? searchExpansion(tree, term, view.search?.fields ?? [opts.label_field], opts)\n : null,\n [clientSearch, term, tree, view.search?.fields, opts],\n );\n const [searchToggles, setSearchToggles] = useState<ReadonlyMap<string, boolean>>(new Map());\n // biome-ignore lint/correctness/useExhaustiveDependencies: a new term starts from its own expansion\n useEffect(() => setSearchToggles(new Map()), [term]);\n // A filtered lazy tree lists matches at every depth: none is opened by default.\n const defaultsOn = !(lazy && dataFilter !== undefined);\n\n const isOpen = useCallback(\n (id: string, depth: number) => {\n if (expansion) {\n const toggled = searchToggles.get(id);\n if (toggled !== undefined) return toggled;\n if (expansion.open.has(id)) return true;\n return !opts.on_search.collapse_others && expand.isOpen(id, depth);\n }\n return expand.isOpen(id, defaultsOn ? depth : Number.POSITIVE_INFINITY);\n },\n [expansion, searchToggles, opts.on_search.collapse_others, expand, defaultsOn],\n );\n const setOpen = useCallback(\n (id: string, open: boolean) => {\n if (expansion) setSearchToggles((m) => new Map(m).set(id, open));\n else expand.set(id, open);\n },\n [expansion, expand],\n );\n\n // --- writes -------------------------------------------------------------------------\n const can = {\n rename: opts.interactive.rename && capabilities.mutate,\n reply: opts.interactive.reply && capabilities.mutate,\n reparent: opts.interactive.reparent && capabilities.mutate && capabilities.tree_reparent,\n };\n const mutate = useUdcMutate(collection);\n const fail = useCallback(\n (err: unknown, title: string) => {\n if (isVersionConflict(err)) {\n toast({\n variant: \"warning\",\n title: t(\"APP\", \"TREE_CONFLICT_TITLE\"),\n description: t(\"APP\", \"TREE_CONFLICT_BODY\"),\n });\n } else {\n toast({ variant: \"danger\", title, description: (err as Error).message });\n }\n },\n [toast, t],\n );\n\n const onRename = async (row: Row, label: string) => {\n try {\n await mutate.mutateAsync({\n op: \"update\",\n id: idOf(row),\n row: { [opts.label_field]: label },\n expected_version: row.__meta.version,\n });\n } catch (err) {\n fail(err, t(\"APP\", \"TREE_RENAME_FAILED\"));\n }\n };\n\n const onReply = async (parent: Row, text: string) => {\n try {\n await mutate.mutateAsync({\n op: \"insert\",\n row: replyRow(\n opts,\n schema,\n parent,\n tree.children.get(idOf(parent)) ?? [],\n text,\n new Date(),\n ),\n });\n setOpen(idOf(parent), true);\n } catch (err) {\n fail(err, t(\"APP\", \"TREE_REPLY_FAILED\"));\n throw err;\n }\n };\n\n // --- drag and drop ---------------------------------------------------------------------\n const branches = useRef(new Map<string, Row[]>());\n const report = useCallback((parent: string, rows: Row[]) => {\n branches.current.set(parent, rows);\n }, []);\n const loadedRows = (): Map<string, Row> => {\n if (!lazy) return new Map(tree.byId);\n const map = new Map<string, Row>();\n for (const r of roots.rows) map.set(idOf(r), r);\n for (const rows of branches.current.values()) for (const r of rows) map.set(idOf(r), r);\n for (const m of moved.values()) {\n map.set(idOf(m.row), {\n ...m.row,\n [opts.parent_field]: m.parent,\n [opts.order_field]: m.order,\n });\n }\n return map;\n };\n const [drag, setDrag] = useState<TreeCtx[\"drag\"]>(null);\n const sensors = useSensors(\n useSensor(PointerSensor, { activationConstraint: { distance: 5 } }),\n useSensor(TouchSensor, { activationConstraint: { delay: 180, tolerance: 6 } }),\n );\n // The gap strip above a row wins over the row it overlaps.\n const collision: CollisionDetection = (args) =>\n pointerWithin(args).sort(\n (a, b) =>\n Number(String(b.id).startsWith(\"before:\")) - Number(String(a.id).startsWith(\"before:\")),\n );\n\n const onDragStart = (e: DragStartEvent) =>\n setDrag({ id: String(e.active.id), rowsById: loadedRows() });\n\n const siblingOrders = async (parent: string | null) => {\n const q = siblingsQuery(opts, parent);\n const res = await client.list({ collection, ...q, page: { limit: q.limit } });\n return res.rows.map((r) => ({ id: idOf(r), order: numberOf(r, opts.order_field), row: r }));\n };\n\n const move = async (dragId: string, target: DropTarget, rowsById: ReadonlyMap<string, Row>) => {\n const parent = dropParent(target, rowsById, opts);\n const row = rowsById.get(dragId);\n if (parent === undefined || !row) return;\n // Drawn at once: last under the new parent, or just above the target.\n const above = numberOf(rowsById.get(target.id), opts.order_field);\n const provisional =\n target.kind === \"before\" && above !== null ? above - 0.5 : Number.MAX_SAFE_INTEGER;\n setMoved((m) => new Map(m).set(dragId, { row, parent, order: provisional }));\n if (parent !== null) setOpen(parent, true);\n try {\n let siblings = await siblingOrders(parent);\n let plan = planDrop(dragId, target, parent, siblings);\n let version = row.__meta.version;\n if (plan.collision) {\n if (parent === null) throw new UdcError(\"internal\", t(\"APP\", \"TREE_NO_ROOM\"));\n await client.reindex({\n collection,\n scope: { [opts.parent_field]: parent },\n order_field: opts.order_field,\n });\n siblings = await siblingOrders(parent);\n plan = planDrop(dragId, target, parent, siblings);\n if (plan.collision) throw new UdcError(\"internal\", t(\"APP\", \"TREE_NO_ROOM\"));\n // A reindex of the node's own siblings bumped its version too.\n version = siblings.find((s) => s.id === dragId)?.row.__meta.version ?? version;\n }\n await client.treeReparent(reparentRequest(collection, opts, plan, version));\n } catch (err) {\n fail(err, t(\"APP\", \"TREE_MOVE_FAILED\"));\n } finally {\n await qc.invalidateQueries({ queryKey: udcKeys.lists(collection) });\n setMoved((m) => {\n const next = new Map(m);\n next.delete(dragId);\n return next;\n });\n }\n };\n\n const onDragEnd = (e: DragEndEvent) => {\n const current = drag;\n setDrag(null);\n const target = e.over ? parseDropId(String(e.over.id)) : null;\n if (!current || !target || !canDrop(current.id, target, current.rowsById, opts)) return;\n void move(current.id, target, current.rowsById);\n };\n\n // --- detail -------------------------------------------------------------------------------\n const [detail, setDetail] = useState<Row | null>(null);\n\n const ctx: TreeCtx = {\n collection,\n opts,\n describe,\n lazy,\n dataFilter,\n dataSearch: serverSearch,\n term: highlight,\n isOpen,\n setOpen,\n childrenOf: (id) => tree.children.get(id) ?? [],\n moved,\n orphans: lazy ? lazyOrphans : tree.orphans,\n can,\n drag,\n report,\n onOpenDetail: setDetail,\n onRename,\n onReply,\n };\n\n const topRows = lazy ? lazyRoots : tree.roots;\n const loading = lazy ? roots.isLoading : all.isLoading;\n const error = lazy ? roots.error : all.error;\n const allIds = () => [...tree.children.keys()];\n const dragRow = drag ? drag.rowsById.get(drag.id) : undefined;\n\n return (\n <Ctx.Provider value={ctx}>\n <div\n className=\"udc-tree udc:flex udc:min-h-0 udc:flex-1 udc:flex-col\"\n data-testid=\"tree\"\n data-lazy={lazy || undefined}\n data-searching={expansion ? true : undefined}\n >\n {lazy ? null : <AllRowsStatus result={all} />}\n <div className=\"udc:flex udc:items-center udc:gap-1 udc:border-b udc:border-border udc:bg-muted/30 udc:px-3 udc:py-1.5\">\n {lazy ? null : (\n <Button\n size=\"sm\"\n variant=\"ghost\"\n data-testid=\"tree-expand-all\"\n onClick={() => expand.expandAll(allIds())}\n >\n <ChevronsUpDown />\n {t(\"APP\", \"TREE_EXPAND_ALL\")}\n </Button>\n )}\n <Button\n size=\"sm\"\n variant=\"ghost\"\n data-testid=\"tree-collapse-all\"\n onClick={() => {\n setSearchToggles(new Map([...tree.children.keys()].map((id) => [id, false])));\n expand.collapseAll();\n }}\n >\n <ChevronsDownUp />\n {t(\"APP\", \"TREE_COLLAPSE_ALL\")}\n </Button>\n </div>\n <div className=\"udc-scroll-thin udc:min-h-0 udc:flex-1 udc:overflow-auto udc:py-1\">\n {error ? (\n <ErrorState\n error={error}\n onRetry={() => void (lazy ? roots.refetch() : all.refetch())}\n />\n ) : loading ? (\n <div className=\"udc:flex udc:flex-col udc:gap-2 udc:p-4\">\n {SKELETON.map((k, i) => (\n <Skeleton key={k} className=\"udc:h-6\" style={{ marginLeft: (i % 3) * 20 }} />\n ))}\n </div>\n ) : topRows.length === 0 ? (\n <EmptyState collection={collection} filtered={filtered} onClear={onClearFilters} />\n ) : (\n <DndContext\n sensors={sensors}\n collisionDetection={collision}\n onDragStart={onDragStart}\n onDragEnd={onDragEnd}\n onDragCancel={() => setDrag(null)}\n >\n <div role=\"tree\" aria-label={t(\"COLLECTIONS\", collection)} data-testid=\"tree-root\">\n <NodeList rows={topRows} depth={0} />\n </div>\n <DragOverlay dropAnimation={null}>\n {dragRow ? (\n <div className=\"udc:flex udc:max-w-md udc:items-center udc:gap-2 udc:rounded-md udc:border udc:border-border udc:bg-surface udc:px-3 udc:py-1.5 udc:text-[13px] udc:shadow-lg udc:shadow-black/15\">\n <ListTree className=\"udc:size-3.5 udc:text-muted-foreground\" />\n <TreeNodeLabel row={dragRow} />\n </div>\n ) : null}\n </DragOverlay>\n </DndContext>\n )}\n </div>\n </div>\n <CardDetailDialog\n row={detail ?? undefined}\n describe={describe}\n collection={collection}\n labels={{}}\n titleField={opts.label_field}\n bodyField={undefined}\n testId=\"tree-detail\"\n onClose={() => setDetail(null)}\n />\n </Ctx.Provider>\n );\n}\n\nexport function NodeList({ rows, depth }: { rows: readonly Row[]; depth: number }) {\n return (\n // biome-ignore lint/a11y/useSemanticElements: an ARIA tree group has no native element\n <div role=\"group\">\n {rows.map((row) => (\n <TreeNode key={idOf(row)} row={row} depth={depth} />\n ))}\n </div>\n );\n}\n\n/** One level of a lazy tree, read when its parent opens. */\nexport function LazyChildren({ parent, depth }: { parent: string; depth: number }) {\n const { Spinner } = useUiKit();\n const { t } = useI18n();\n const ctx = useTree();\n const { opts, collection, moved, report, dataFilter, dataSearch } = ctx;\n const q = lazyChildrenQuery(opts, parent, dataFilter);\n const res = useUdcCollection({\n collection,\n filter: q.filter,\n sort: q.sort ?? [],\n mode: \"pages\",\n pageLimit: q.limit,\n search: dataSearch,\n });\n useEffect(() => report(parent, res.rows), [report, parent, res.rows]);\n const rows = withMoves(res.rows, parent, moved, ctx);\n if (res.isLoading) {\n return (\n <div\n className=\"udc:flex udc:items-center udc:gap-2 udc:py-1 udc:text-xs udc:text-muted-foreground\"\n style={{ paddingLeft: 12 + (depth + 1) * 20 }}\n data-testid=\"tree-branch-loading\"\n >\n <Spinner className=\"udc:size-3.5\" />\n {t(\"APP\", \"TREE_LOADING\")}\n </div>\n );\n }\n return <NodeList rows={rows} depth={depth + 1} />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgGA,IAAM,MAAM,cAA8B,IAAI;AAE9C,SAAgB,UAAmB;CACjC,MAAM,MAAM,WAAW,GAAG;CAC1B,IAAI,CAAC,KAAK,MAAM,IAAI,MAAM,yCAAyC;CACnE,OAAO;AACT;;AAGA,SAAgB,UACd,MACA,QACA,OACA,KACO;CACP,MAAM,EAAE,SAAS;CACjB,MAAM,OAAO,KAAK,QAAQ,MAAM;EAC9B,MAAM,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC;EAC3B,OAAO,CAAC,KAAK,EAAE,WAAW;CAC5B,CAAC;CACD,MAAM,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,CAAC,CAC7B,QAAQ,MAAM,EAAE,WAAW,UAAU,CAAC,KAAK,MAAM,MAAM,KAAK,CAAC,MAAM,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAChF,KAAK,MAAM,EAAE,GAAG;CACnB,MAAM,UAA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WAAW,KAAA;GACX,QAAO;GACP,eAAe,UAAU,IAAI;EAC9B,CAAA,CACW;;AAElB;AAEA,SAAgB,SAAS,EAAE,MAAM,SAAkD;CACjF,OAEE,oBAAC,OAAD;EAAK,MAAK;EACP,UAAA,KAAK,KAAK,QACT,oBAAC,UAAD;GAA+B;GAAY;EAAQ,GAApC,KAAK,GAAG,CAA4B,CACpD;CACE,CAAA;AAET;;AAGA,SAAgB,aAAa,EAAE,QAAQ,SAA4C;CACjF,MAAM,EAAE,YAAY,SAAS;CAC7B,MAAM,EAAE,MAAM,QAAQ;CACtB,MAAM,MAAM,QAAQ;CACpB,MAAM,EAAE,MAAM,YAAY,OAAO,QAAQ,YAAY,eAAe;CACpE,MAAM,IAAI,kBAAkB,MAAM,QAAQ,UAAU;CACpD,MAAM,MAAM,iBAAiB;EAC3B;EACA,QAAQ,EAAE;EACV,MAAM,EAAE,QAAQ,CAAC;EACjB,MAAM;EACN,WAAW,EAAE;EACb,QAAQ;CACV,CAAC;CACD,gBAAgB,OAAO,QAAQ,IAAI,IAAI,GAAG;EAAC;EAAQ;EAAQ,IAAI;CAAI,CAAC;CACpE,MAAM,OAAO,UAAU,IAAI,MAAM,QAAQ,OAAO,GAAG;CACnD,IAAI,IAAI,WACN,OACE,qBAAC,OAAD;EACE,WAAU;EACV,OAAO,EAAE,aAAa,MAAM,QAAQ,KAAK,GAAG;EAC5C,eAAY;EAHd,UAAA,CAKE,oBAAC,SAAD,EAAS,WAAU,eAAgB,CAAA,GAClC,EAAE,OAAO,cAAc,CACrB;;CAGT,OAAO,oBAAC,UAAD;EAAgB;EAAM,OAAO,QAAQ;CAAI,CAAA;AAClD"}
1
+ {"version":3,"file":"TreeRenderer.js","names":[],"sources":["../../src/tree/TreeRenderer.tsx"],"sourcesContent":["import {\n type CollisionDetection,\n DndContext,\n type DragEndEvent,\n DragOverlay,\n type DragStartEvent,\n PointerSensor,\n pointerWithin,\n TouchSensor,\n useSensor,\n useSensors,\n} from \"@dnd-kit/core\";\nimport {\n type FilterNode,\n isVersionConflict,\n type Row,\n type TreeOptions,\n UdcError,\n} from \"@jsudc/core\";\nimport { useQueryClient } from \"@tanstack/react-query\";\nimport { ChevronsDownUp, ChevronsUpDown, ListTree } from \"lucide-react\";\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { useI18n } from \"../i18n/i18n.js\";\nimport { CardDetailDialog } from \"../kanban/CardDetailDialog.js\";\nimport { AllRowsStatus } from \"../renderers/AllRowsStatus.js\";\nimport type { RendererProps } from \"../renderers/types.js\";\nimport { EmptyState, ErrorState } from \"../table/states.js\";\nimport { busyToast } from \"../udc/busy.js\";\nimport { useUdcAllRows, useUdcCollection, useUdcMutate } from \"../udc/hooks.js\";\nimport { udcKeys } from \"../udc/keys.js\";\nimport { useUdcClient } from \"../udc/provider.js\";\nimport { useUiKit } from \"../ui-kit/context.js\";\nimport { type TreeExpand, useTreeExpand } from \"./expand.js\";\nimport {\n type BuiltTree,\n buildTree,\n canDrop,\n type DropTarget,\n dropParent,\n idOf,\n lazyChildrenQuery,\n lazyRootsQuery,\n numberOf,\n parentOf,\n parseDropId,\n planDrop,\n reparentRequest,\n replyRow,\n searchExpansion,\n siblingsQuery,\n sortSiblings,\n} from \"./model.js\";\nimport { TreeNode, TreeNodeLabel } from \"./TreeNode.js\";\n\n/** A node moved in this session, drawn at its new place until the lists are read again. */\ninterface Moved {\n row: Row;\n parent: string | null;\n order: number;\n}\n\nexport interface TreeCtx {\n collection: string;\n opts: TreeOptions;\n describe: RendererProps[\"describe\"];\n lazy: boolean;\n /** What every lazy branch adds to its own condition: the data view's filter. */\n dataFilter: FilterNode | undefined;\n /** The text sent as `search` with every list (a source that answers search); absent otherwise. */\n dataSearch?: string | undefined;\n /** The highlighted search term (\"\" when none). */\n term: string;\n isOpen: (id: string, depth: number) => boolean;\n setOpen: (id: string, open: boolean) => void;\n /** Non-lazy: the children of a node as built from the loaded rows. */\n childrenOf: (id: string) => Row[];\n /** Rows moved in this session, by id. */\n moved: ReadonlyMap<string, Moved>;\n orphans: ReadonlySet<string>;\n can: { rename: boolean; reply: boolean; reparent: boolean };\n /** The id being dragged, and the loaded rows the drop targets are checked against. */\n drag: { id: string; rowsById: ReadonlyMap<string, Row> } | null;\n /** Lazy branches report the rows they loaded (for drop gating). */\n report: (parent: string, rows: Row[]) => void;\n onOpenDetail: (row: Row) => void;\n onRename: (row: Row, label: string) => Promise<void>;\n onReply: (parent: Row, text: string) => Promise<void>;\n}\n\nconst Ctx = createContext<TreeCtx | null>(null);\n\nexport function useTree(): TreeCtx {\n const ctx = useContext(Ctx);\n if (!ctx) throw new Error(\"useTree needs a <TreeRenderer> above it\");\n return ctx;\n}\n\n/** Rows as drawn under `parent`: the loaded ones minus those moved away, plus those moved here. */\nexport function withMoves(\n rows: readonly Row[],\n parent: string | null,\n moved: ReadonlyMap<string, Moved>,\n ctx: Pick<TreeCtx, \"opts\">,\n): Row[] {\n const { opts } = ctx;\n const stay = rows.filter((r) => {\n const m = moved.get(idOf(r));\n return !m || m.parent === parent;\n });\n const here = [...moved.values()]\n .filter((m) => m.parent === parent && !stay.some((r) => idOf(r) === idOf(m.row)))\n .map((m) => m.row);\n const patched = [...stay, ...here].map((r) => {\n const m = moved.get(idOf(r));\n return m ? { ...r, [opts.parent_field]: m.parent, [opts.order_field]: m.order } : r;\n });\n return sortSiblings(patched, opts.sibling_sort);\n}\n\nexport function TreeRenderer(props: RendererProps) {\n const { t } = useI18n();\n const opts = props.describe.view.tree_options;\n if (!opts) {\n return (\n <div className=\"udc:p-6 udc:text-sm udc:text-muted-foreground\" data-testid=\"tree-no-options\">\n {t(\"APP\", \"TREE_NO_OPTIONS\")}\n </div>\n );\n }\n return <Tree {...props} opts={opts} />;\n}\n\nconst SKELETON = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"];\n\nfunction Tree({\n collection,\n describe,\n filter,\n baseFilter,\n search,\n listSearch,\n filtered,\n onClearFilters,\n onCount,\n opts,\n}: RendererProps & { opts: TreeOptions }) {\n const { Button, Skeleton, useToast } = useUiKit();\n const { t } = useI18n();\n const { toast } = useToast();\n const client = useUdcClient();\n const qc = useQueryClient();\n const { capabilities, schema, view } = describe;\n const lazy = opts.lazy;\n const term = search.trim();\n // highlight_and_expand on a loaded tree searches in the browser; anything else asks the server.\n const clientSearch = !lazy && opts.on_search.mode === \"highlight_and_expand\";\n // A source that answers search gets the text, unless the tree searches what it loaded.\n const serverSearch = clientSearch ? undefined : listSearch;\n // A lazy tree lists the matches of a filter flat; a source search alone is such a filter too.\n const dataFilter: FilterNode | undefined = clientSearch\n ? baseFilter\n : (filter ?? (serverSearch === undefined ? undefined : { and: [] }));\n const highlight = opts.on_search.mode === \"highlight_and_expand\" ? term : \"\";\n\n // --- rows ----------------------------------------------------------------------\n const all = useUdcAllRows({\n collection,\n filter: dataFilter,\n sort: opts.sibling_sort,\n capabilities,\n enabled: !lazy,\n refetchInterval: describe.view.refresh_interval_ms,\n search: serverSearch,\n });\n const rootsQ = lazyRootsQuery(opts, dataFilter);\n const roots = useUdcCollection({\n collection,\n filter: rootsQ.filter,\n sort: rootsQ.sort ?? [],\n mode: \"pages\",\n pageLimit: rootsQ.limit,\n enabled: lazy,\n search: serverSearch,\n });\n const totalQ = useUdcCollection({\n collection,\n filter: dataFilter,\n mode: \"pages\",\n pageLimit: 1,\n enabled: lazy,\n search: serverSearch,\n });\n\n const [moved, setMoved] = useState<ReadonlyMap<string, Moved>>(new Map());\n const tree: BuiltTree = useMemo(\n () =>\n buildTree(\n all.rows.map((r) => {\n const m = moved.get(idOf(r));\n return m ? { ...r, [opts.parent_field]: m.parent, [opts.order_field]: m.order } : r;\n }),\n opts,\n ),\n [all.rows, moved, opts],\n );\n\n // A filtered lazy tree lists every match; those under a listed parent show when it opens.\n const lazyRoots = useMemo(() => {\n const ids = new Set(roots.rows.map(idOf));\n const top = roots.rows.filter((r) => {\n const p = parentOf(r, opts);\n return p === null || !ids.has(p);\n });\n return withMoves(top, null, moved, { opts });\n }, [roots.rows, moved, opts]);\n const lazyOrphans = useMemo(\n () => new Set(lazyRoots.filter((r) => parentOf(r, opts) !== null).map(idOf)),\n [lazyRoots, opts],\n );\n\n useEffect(() => {\n onCount(\n lazy\n ? totalQ.total === null\n ? null\n : { shown: lazyRoots.length, total: totalQ.total, unit: \"nodes\" }\n : all.total === null\n ? null\n : { shown: all.rows.length, total: all.rows.length, unit: \"nodes\" },\n );\n }, [onCount, lazy, lazyRoots.length, totalQ.total, all.rows.length, all.total]);\n useEffect(() => () => onCount(null), [onCount]);\n\n // --- expand state (with the search's own, while there is a term) ---------------------\n const expand: TreeExpand = useTreeExpand(opts, collection);\n const expansion = useMemo(\n () =>\n clientSearch && term\n ? searchExpansion(tree, term, view.search?.fields ?? [opts.label_field], opts)\n : null,\n [clientSearch, term, tree, view.search?.fields, opts],\n );\n const [searchToggles, setSearchToggles] = useState<ReadonlyMap<string, boolean>>(new Map());\n // biome-ignore lint/correctness/useExhaustiveDependencies: a new term starts from its own expansion\n useEffect(() => setSearchToggles(new Map()), [term]);\n // A filtered lazy tree lists matches at every depth: none is opened by default.\n const defaultsOn = !(lazy && dataFilter !== undefined);\n\n const isOpen = useCallback(\n (id: string, depth: number) => {\n if (expansion) {\n const toggled = searchToggles.get(id);\n if (toggled !== undefined) return toggled;\n if (expansion.open.has(id)) return true;\n return !opts.on_search.collapse_others && expand.isOpen(id, depth);\n }\n return expand.isOpen(id, defaultsOn ? depth : Number.POSITIVE_INFINITY);\n },\n [expansion, searchToggles, opts.on_search.collapse_others, expand, defaultsOn],\n );\n const setOpen = useCallback(\n (id: string, open: boolean) => {\n if (expansion) setSearchToggles((m) => new Map(m).set(id, open));\n else expand.set(id, open);\n },\n [expansion, expand],\n );\n\n // --- writes -------------------------------------------------------------------------\n const can = {\n rename: opts.interactive.rename && capabilities.mutate,\n reply: opts.interactive.reply && capabilities.mutate,\n reparent: opts.interactive.reparent && capabilities.mutate && capabilities.tree_reparent,\n };\n const mutate = useUdcMutate(collection);\n const fail = useCallback(\n (err: unknown, title: string) => {\n const busy = busyToast(err, t);\n if (busy) {\n toast(busy);\n } else if (isVersionConflict(err)) {\n toast({\n variant: \"warning\",\n title: t(\"APP\", \"TREE_CONFLICT_TITLE\"),\n description: t(\"APP\", \"TREE_CONFLICT_BODY\"),\n });\n } else {\n toast({ variant: \"danger\", title, description: (err as Error).message });\n }\n },\n [toast, t],\n );\n\n const onRename = async (row: Row, label: string) => {\n try {\n await mutate.mutateAsync({\n op: \"update\",\n id: idOf(row),\n row: { [opts.label_field]: label },\n expected_version: row.__meta.version,\n });\n } catch (err) {\n fail(err, t(\"APP\", \"TREE_RENAME_FAILED\"));\n }\n };\n\n const onReply = async (parent: Row, text: string) => {\n try {\n await mutate.mutateAsync({\n op: \"insert\",\n row: replyRow(\n opts,\n schema,\n parent,\n tree.children.get(idOf(parent)) ?? [],\n text,\n new Date(),\n ),\n });\n setOpen(idOf(parent), true);\n } catch (err) {\n fail(err, t(\"APP\", \"TREE_REPLY_FAILED\"));\n throw err;\n }\n };\n\n // --- drag and drop ---------------------------------------------------------------------\n const branches = useRef(new Map<string, Row[]>());\n const report = useCallback((parent: string, rows: Row[]) => {\n branches.current.set(parent, rows);\n }, []);\n const loadedRows = (): Map<string, Row> => {\n if (!lazy) return new Map(tree.byId);\n const map = new Map<string, Row>();\n for (const r of roots.rows) map.set(idOf(r), r);\n for (const rows of branches.current.values()) for (const r of rows) map.set(idOf(r), r);\n for (const m of moved.values()) {\n map.set(idOf(m.row), {\n ...m.row,\n [opts.parent_field]: m.parent,\n [opts.order_field]: m.order,\n });\n }\n return map;\n };\n const [drag, setDrag] = useState<TreeCtx[\"drag\"]>(null);\n const sensors = useSensors(\n useSensor(PointerSensor, { activationConstraint: { distance: 5 } }),\n useSensor(TouchSensor, { activationConstraint: { delay: 180, tolerance: 6 } }),\n );\n // The gap strip above a row wins over the row it overlaps.\n const collision: CollisionDetection = (args) =>\n pointerWithin(args).sort(\n (a, b) =>\n Number(String(b.id).startsWith(\"before:\")) - Number(String(a.id).startsWith(\"before:\")),\n );\n\n const onDragStart = (e: DragStartEvent) =>\n setDrag({ id: String(e.active.id), rowsById: loadedRows() });\n\n const siblingOrders = async (parent: string | null) => {\n const q = siblingsQuery(opts, parent);\n const res = await client.list({ collection, ...q, page: { limit: q.limit } });\n return res.rows.map((r) => ({ id: idOf(r), order: numberOf(r, opts.order_field), row: r }));\n };\n\n const move = async (dragId: string, target: DropTarget, rowsById: ReadonlyMap<string, Row>) => {\n const parent = dropParent(target, rowsById, opts);\n const row = rowsById.get(dragId);\n if (parent === undefined || !row) return;\n // Drawn at once: last under the new parent, or just above the target.\n const above = numberOf(rowsById.get(target.id), opts.order_field);\n const provisional =\n target.kind === \"before\" && above !== null ? above - 0.5 : Number.MAX_SAFE_INTEGER;\n setMoved((m) => new Map(m).set(dragId, { row, parent, order: provisional }));\n if (parent !== null) setOpen(parent, true);\n try {\n let siblings = await siblingOrders(parent);\n let plan = planDrop(dragId, target, parent, siblings);\n let version = row.__meta.version;\n if (plan.collision) {\n if (parent === null) throw new UdcError(\"internal\", t(\"APP\", \"TREE_NO_ROOM\"));\n await client.reindex({\n collection,\n scope: { [opts.parent_field]: parent },\n order_field: opts.order_field,\n });\n siblings = await siblingOrders(parent);\n plan = planDrop(dragId, target, parent, siblings);\n if (plan.collision) throw new UdcError(\"internal\", t(\"APP\", \"TREE_NO_ROOM\"));\n // A reindex of the node's own siblings bumped its version too.\n version = siblings.find((s) => s.id === dragId)?.row.__meta.version ?? version;\n }\n await client.treeReparent(reparentRequest(collection, opts, plan, version));\n } catch (err) {\n fail(err, t(\"APP\", \"TREE_MOVE_FAILED\"));\n } finally {\n await qc.invalidateQueries({ queryKey: udcKeys.lists(collection) });\n setMoved((m) => {\n const next = new Map(m);\n next.delete(dragId);\n return next;\n });\n }\n };\n\n const onDragEnd = (e: DragEndEvent) => {\n const current = drag;\n setDrag(null);\n const target = e.over ? parseDropId(String(e.over.id)) : null;\n if (!current || !target || !canDrop(current.id, target, current.rowsById, opts)) return;\n void move(current.id, target, current.rowsById);\n };\n\n // --- detail -------------------------------------------------------------------------------\n const [detail, setDetail] = useState<Row | null>(null);\n\n const ctx: TreeCtx = {\n collection,\n opts,\n describe,\n lazy,\n dataFilter,\n dataSearch: serverSearch,\n term: highlight,\n isOpen,\n setOpen,\n childrenOf: (id) => tree.children.get(id) ?? [],\n moved,\n orphans: lazy ? lazyOrphans : tree.orphans,\n can,\n drag,\n report,\n onOpenDetail: setDetail,\n onRename,\n onReply,\n };\n\n const topRows = lazy ? lazyRoots : tree.roots;\n const loading = lazy ? roots.isLoading : all.isLoading;\n const error = lazy ? roots.error : all.error;\n const allIds = () => [...tree.children.keys()];\n const dragRow = drag ? drag.rowsById.get(drag.id) : undefined;\n\n return (\n <Ctx.Provider value={ctx}>\n <div\n className=\"udc-tree udc:flex udc:min-h-0 udc:flex-1 udc:flex-col\"\n data-testid=\"tree\"\n data-lazy={lazy || undefined}\n data-searching={expansion ? true : undefined}\n >\n {lazy ? null : <AllRowsStatus result={all} />}\n <div className=\"udc:flex udc:items-center udc:gap-1 udc:border-b udc:border-border udc:bg-muted/30 udc:px-3 udc:py-1.5\">\n {lazy ? null : (\n <Button\n size=\"sm\"\n variant=\"ghost\"\n data-testid=\"tree-expand-all\"\n onClick={() => expand.expandAll(allIds())}\n >\n <ChevronsUpDown />\n {t(\"APP\", \"TREE_EXPAND_ALL\")}\n </Button>\n )}\n <Button\n size=\"sm\"\n variant=\"ghost\"\n data-testid=\"tree-collapse-all\"\n onClick={() => {\n setSearchToggles(new Map([...tree.children.keys()].map((id) => [id, false])));\n expand.collapseAll();\n }}\n >\n <ChevronsDownUp />\n {t(\"APP\", \"TREE_COLLAPSE_ALL\")}\n </Button>\n </div>\n <div className=\"udc-scroll-thin udc:min-h-0 udc:flex-1 udc:overflow-auto udc:py-1\">\n {error ? (\n <ErrorState\n error={error}\n onRetry={() => void (lazy ? roots.refetch() : all.refetch())}\n />\n ) : loading ? (\n <div className=\"udc:flex udc:flex-col udc:gap-2 udc:p-4\">\n {SKELETON.map((k, i) => (\n <Skeleton key={k} className=\"udc:h-6\" style={{ marginLeft: (i % 3) * 20 }} />\n ))}\n </div>\n ) : topRows.length === 0 ? (\n <EmptyState collection={collection} filtered={filtered} onClear={onClearFilters} />\n ) : (\n <DndContext\n sensors={sensors}\n collisionDetection={collision}\n onDragStart={onDragStart}\n onDragEnd={onDragEnd}\n onDragCancel={() => setDrag(null)}\n >\n <div role=\"tree\" aria-label={t(\"COLLECTIONS\", collection)} data-testid=\"tree-root\">\n <NodeList rows={topRows} depth={0} />\n </div>\n <DragOverlay dropAnimation={null}>\n {dragRow ? (\n <div className=\"udc:flex udc:max-w-md udc:items-center udc:gap-2 udc:rounded-md udc:border udc:border-border udc:bg-surface udc:px-3 udc:py-1.5 udc:text-[13px] udc:shadow-lg udc:shadow-black/15\">\n <ListTree className=\"udc:size-3.5 udc:text-muted-foreground\" />\n <TreeNodeLabel row={dragRow} />\n </div>\n ) : null}\n </DragOverlay>\n </DndContext>\n )}\n </div>\n </div>\n <CardDetailDialog\n row={detail ?? undefined}\n describe={describe}\n collection={collection}\n labels={{}}\n titleField={opts.label_field}\n bodyField={undefined}\n testId=\"tree-detail\"\n onClose={() => setDetail(null)}\n />\n </Ctx.Provider>\n );\n}\n\nexport function NodeList({ rows, depth }: { rows: readonly Row[]; depth: number }) {\n return (\n // biome-ignore lint/a11y/useSemanticElements: an ARIA tree group has no native element\n <div role=\"group\">\n {rows.map((row) => (\n <TreeNode key={idOf(row)} row={row} depth={depth} />\n ))}\n </div>\n );\n}\n\n/** One level of a lazy tree, read when its parent opens. */\nexport function LazyChildren({ parent, depth }: { parent: string; depth: number }) {\n const { Spinner } = useUiKit();\n const { t } = useI18n();\n const ctx = useTree();\n const { opts, collection, moved, report, dataFilter, dataSearch } = ctx;\n const q = lazyChildrenQuery(opts, parent, dataFilter);\n const res = useUdcCollection({\n collection,\n filter: q.filter,\n sort: q.sort ?? [],\n mode: \"pages\",\n pageLimit: q.limit,\n search: dataSearch,\n });\n useEffect(() => report(parent, res.rows), [report, parent, res.rows]);\n const rows = withMoves(res.rows, parent, moved, ctx);\n if (res.isLoading) {\n return (\n <div\n className=\"udc:flex udc:items-center udc:gap-2 udc:py-1 udc:text-xs udc:text-muted-foreground\"\n style={{ paddingLeft: 12 + (depth + 1) * 20 }}\n data-testid=\"tree-branch-loading\"\n >\n <Spinner className=\"udc:size-3.5\" />\n {t(\"APP\", \"TREE_LOADING\")}\n </div>\n );\n }\n return <NodeList rows={rows} depth={depth + 1} />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiGA,IAAM,MAAM,cAA8B,IAAI;AAE9C,SAAgB,UAAmB;CACjC,MAAM,MAAM,WAAW,GAAG;CAC1B,IAAI,CAAC,KAAK,MAAM,IAAI,MAAM,yCAAyC;CACnE,OAAO;AACT;;AAGA,SAAgB,UACd,MACA,QACA,OACA,KACO;CACP,MAAM,EAAE,SAAS;CACjB,MAAM,OAAO,KAAK,QAAQ,MAAM;EAC9B,MAAM,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC;EAC3B,OAAO,CAAC,KAAK,EAAE,WAAW;CAC5B,CAAC;CACD,MAAM,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,CAAC,CAC7B,QAAQ,MAAM,EAAE,WAAW,UAAU,CAAC,KAAK,MAAM,MAAM,KAAK,CAAC,MAAM,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAChF,KAAK,MAAM,EAAE,GAAG;CACnB,MAAM,UAAU,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC,CAAC,KAAK,MAAM;EAC5C,MAAM,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC;EAC3B,OAAO,IAAI;GAAE,GAAG;IAAI,KAAK,eAAe,EAAE;IAAS,KAAK,cAAc,EAAE;EAAM,IAAI;CACpF,CAAC;CACD,OAAO,aAAa,SAAS,KAAK,YAAY;AAChD;AAEA,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A+B;GAAY;EAAQ,GAApC,KAAK,GAAG,CAA4B,CACpD;CACE,CAAA;AAET;;AAGA,SAAgB,aAAa,EAAE,QAAQ,SAA4C;CACjF,MAAM,EAAE,YAAY,SAAS;CAC7B,MAAM,EAAE,MAAM,QAAQ;CACtB,MAAM,MAAM,QAAQ;CACpB,MAAM,EAAE,MAAM,YAAY,OAAO,QAAQ,YAAY,eAAe;CACpE,MAAM,IAAI,kBAAkB,MAAM,QAAQ,UAAU;CACpD,MAAM,MAAM,iBAAiB;EAC3B;EACA,QAAQ,EAAE;EACV,MAAM,EAAE,QAAQ,CAAC;EACjB,MAAM;EACN,WAAW,EAAE;EACb,QAAQ;CACV,CAAC;CACD,gBAAgB,OAAO,QAAQ,IAAI,IAAI,GAAG;EAAC;EAAQ;EAAQ,IAAI;CAAI,CAAC;CACpE,MAAM,OAAO,UAAU,IAAI,MAAM,QAAQ,OAAO,GAAG;CACnD,IAAI,IAAI,WACN,OACE,qBAAC,OAAD;EACE,WAAU;EACV,OAAO,EAAE,aAAa,MAAM,QAAQ,KAAK,GAAG;EAC5C,eAAY;EAHd,UAAA,CAKE,oBAAC,SAAD,EAAS,WAAU,eAAgB,CAAA,GAClC,EAAE,OAAO,cAAc,CACrB;;CAGT,OAAO,oBAAC,UAAD;EAAgB;EAAM,OAAO,QAAQ;CAAI,CAAA;AAClD"}
@@ -0,0 +1,9 @@
1
+ import type { ToastInput } from "../ui-kit/types.js";
2
+ /**
3
+ * The toast for a write the server refused with `busy` (@jsudc/core 0.7.0):
4
+ * another writer held the data's lock longer than the server waits — another
5
+ * process writing the same SQLite file, say. Nothing was written and the same
6
+ * write may simply be tried again, so it is a warning that says so, not a
7
+ * failure carrying the server's text. `null` for any other error.
8
+ */
9
+ export declare function busyToast(err: unknown, t: (section: string, term: string) => string): ToastInput | null;
@@ -0,0 +1,20 @@
1
+ import { isBusy } from "@jsudc/core";
2
+ // src/udc/busy.ts
3
+ /**
4
+ * The toast for a write the server refused with `busy` (@jsudc/core 0.7.0):
5
+ * another writer held the data's lock longer than the server waits — another
6
+ * process writing the same SQLite file, say. Nothing was written and the same
7
+ * write may simply be tried again, so it is a warning that says so, not a
8
+ * failure carrying the server's text. `null` for any other error.
9
+ */
10
+ function busyToast(err, t) {
11
+ if (!isBusy(err)) return null;
12
+ return {
13
+ variant: "warning",
14
+ title: t("APP", "BUSY_TITLE"),
15
+ description: t("APP", "BUSY_BODY")
16
+ };
17
+ }
18
+ export { busyToast };
19
+
20
+ //# sourceMappingURL=busy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"busy.js","names":[],"sources":["../../src/udc/busy.ts"],"sourcesContent":["import { isBusy } from \"@jsudc/core\";\nimport type { ToastInput } from \"../ui-kit/types.js\";\n\n/**\n * The toast for a write the server refused with `busy` (@jsudc/core 0.7.0):\n * another writer held the data's lock longer than the server waits — another\n * process writing the same SQLite file, say. Nothing was written and the same\n * write may simply be tried again, so it is a warning that says so, not a\n * failure carrying the server's text. `null` for any other error.\n */\nexport function busyToast(\n err: unknown,\n t: (section: string, term: string) => string,\n): ToastInput | null {\n if (!isBusy(err)) return null;\n return { variant: \"warning\", title: t(\"APP\", \"BUSY_TITLE\"), description: t(\"APP\", \"BUSY_BODY\") };\n}\n"],"mappings":";;;;;;;;;AAUA,SAAgB,UACd,KACA,GACmB;CACnB,IAAI,CAAC,OAAO,GAAG,GAAG,OAAO;CACzB,OAAO;EAAE,SAAS;EAAW,OAAO,EAAE,OAAO,YAAY;EAAG,aAAa,EAAE,OAAO,WAAW;CAAE;AACjG"}
@@ -6,7 +6,8 @@ export declare const UdcClientContext: import("react").Context<UdcClient | null>
6
6
  export declare function useUdcClient(): UdcClient;
7
7
  /**
8
8
  * A protocol error is the server's answer, not a hiccup: asking again gives
9
- * the same answer. Only transport failures are retried, twice.
9
+ * the same answer. Only transport failures and `busy` (another writer held the
10
+ * lock past the server's wait; @jsudc/core 0.7.0) are retried, twice.
10
11
  */
11
12
  export declare function shouldRetry(failureCount: number, error: unknown): boolean;
12
13
  export interface UdcQueryClientOptions {
@@ -1,5 +1,5 @@
1
1
  import { registerUnauthenticated } from "./unauthenticated.js";
2
- import { isUdcError, isUnauthenticated } from "@jsudc/core";
2
+ import { isBusy, isUdcError, isUnauthenticated } from "@jsudc/core";
3
3
  import { createContext, useContext } from "react";
4
4
  import { MutationCache, QueryCache, QueryClient } from "@tanstack/react-query";
5
5
  // src/udc/client.ts
@@ -12,10 +12,11 @@ function useUdcClient() {
12
12
  }
13
13
  /**
14
14
  * A protocol error is the server's answer, not a hiccup: asking again gives
15
- * the same answer. Only transport failures are retried, twice.
15
+ * the same answer. Only transport failures and `busy` (another writer held the
16
+ * lock past the server's wait; @jsudc/core 0.7.0) are retried, twice.
16
17
  */
17
18
  function shouldRetry(failureCount, error) {
18
- return !isUdcError(error) && failureCount < 2;
19
+ return (!isUdcError(error) || isBusy(error)) && failureCount < 2;
19
20
  }
20
21
  /**
21
22
  * Calls `fn` on the first unauthenticated error and swallows the rest until
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":[],"sources":["../../src/udc/client.ts"],"sourcesContent":["import { isUdcError, isUnauthenticated, type UdcError } from \"@jsudc/core\";\nimport type { UdcClient } from \"@jsudc/core/client\";\nimport { MutationCache, QueryCache, QueryClient } from \"@tanstack/react-query\";\nimport { createContext, useContext } from \"react\";\nimport { registerUnauthenticated } from \"./unauthenticated.js\";\n\n/** The client every hook talks to; `UdcProvider` sets it. */\nexport const UdcClientContext = createContext<UdcClient | null>(null);\n\nexport function useUdcClient(): UdcClient {\n const client = useContext(UdcClientContext);\n if (!client) throw new Error(\"useUdcClient needs a <UdcProvider client={...}> above it\");\n return client;\n}\n\n/**\n * A protocol error is the server's answer, not a hiccup: asking again gives\n * the same answer. Only transport failures are retried, twice.\n */\nexport function shouldRetry(failureCount: number, error: unknown): boolean {\n return !isUdcError(error) && failureCount < 2;\n}\n\nexport interface UdcQueryClientOptions {\n /**\n * Called when a query or a mutation fails because the user is not signed in\n * (`isUnauthenticated`: an HTTP 401 in front of `/udc`, or the server's\n * in-protocol refusal) — the place to send the user to the host's login.\n * Once per burst: the failures that arrive together (every query of a page,\n * say) make one call; it fires again only after `unauthenticatedQuietMs`\n * without such a failure.\n */\n onUnauthenticated?: (error: UdcError) => void;\n /** The quiet time, in ms, that ends a burst of unauthenticated failures. Default 2000. */\n unauthenticatedQuietMs?: number;\n}\n\n/**\n * Calls `fn` on the first unauthenticated error and swallows the rest until\n * `quietMs` pass without one (each further error restarts that wait).\n */\nfunction unauthenticatedNotifier(\n fn: (error: UdcError) => void,\n quietMs: number,\n): (error: unknown) => void {\n let lastAt: number | null = null;\n return (error) => {\n if (!isUnauthenticated(error)) return;\n const now = Date.now();\n const inBurst = lastAt !== null && now - lastAt < quietMs;\n lastAt = now;\n if (!inBurst) fn(error as UdcError);\n };\n}\n\nexport function createUdcQueryClient(options: UdcQueryClientOptions = {}): QueryClient {\n const notify = options.onUnauthenticated\n ? unauthenticatedNotifier(options.onUnauthenticated, options.unauthenticatedQuietMs ?? 2000)\n : undefined;\n const qc = new QueryClient({\n ...(notify\n ? {\n queryCache: new QueryCache({ onError: notify }),\n mutationCache: new MutationCache({ onError: notify }),\n }\n : {}),\n defaultOptions: {\n queries: { retry: shouldRetry, refetchOnWindowFocus: false },\n mutations: { retry: false },\n },\n });\n // The change feed's unauthenticated error takes the same path (and the same burst).\n if (notify) registerUnauthenticated(qc, notify);\n return qc;\n}\n"],"mappings":";;;;;;AAOA,IAAa,mBAAmB,cAAgC,IAAI;AAEpE,SAAgB,eAA0B;CACxC,MAAM,SAAS,WAAW,gBAAgB;CAC1C,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,0DAA0D;CACvF,OAAO;AACT;;;;;AAMA,SAAgB,YAAY,cAAsB,OAAyB;CACzE,OAAO,CAAC,WAAW,KAAK,KAAK,eAAe;AAC9C;;;;;AAoBA,SAAS,wBACP,IACA,SAC0B;CAC1B,IAAI,SAAwB;CAC5B,QAAQ,UAAU;EAChB,IAAI,CAAC,kBAAkB,KAAK,GAAG;EAC/B,MAAM,MAAM,KAAK,IAAI;EACrB,MAAM,UAAU,WAAW,QAAQ,MAAM,SAAS;EAClD,SAAS;EACT,IAAI,CAAC,SAAS,GAAG,KAAiB;CACpC;AACF;AAEA,SAAgB,qBAAqB,UAAiC,CAAC,GAAgB;CACrF,MAAM,SAAS,QAAQ,oBACnB,wBAAwB,QAAQ,mBAAmB,QAAQ,0BAA0B,GAAI,IACzF,KAAA;CACJ,MAAM,KAAK,IAAI,YAAY;EACzB,GAAI,SACA;GACE,YAAY,IAAI,WAAW,EAAE,SAAS,OAAO,CAAC;GAC9C,eAAe,IAAI,cAAc,EAAE,SAAS,OAAO,CAAC;EACtD,IACA,CAAC;EACL,gBAAgB;GACd,SAAS;IAAE,OAAO;IAAa,sBAAsB;GAAM;GAC3D,WAAW,EAAE,OAAO,MAAM;EAC5B;CACF,CAAC;CAED,IAAI,QAAQ,wBAAwB,IAAI,MAAM;CAC9C,OAAO;AACT"}
1
+ {"version":3,"file":"client.js","names":[],"sources":["../../src/udc/client.ts"],"sourcesContent":["import { isBusy, isUdcError, isUnauthenticated, type UdcError } from \"@jsudc/core\";\nimport type { UdcClient } from \"@jsudc/core/client\";\nimport { MutationCache, QueryCache, QueryClient } from \"@tanstack/react-query\";\nimport { createContext, useContext } from \"react\";\nimport { registerUnauthenticated } from \"./unauthenticated.js\";\n\n/** The client every hook talks to; `UdcProvider` sets it. */\nexport const UdcClientContext = createContext<UdcClient | null>(null);\n\nexport function useUdcClient(): UdcClient {\n const client = useContext(UdcClientContext);\n if (!client) throw new Error(\"useUdcClient needs a <UdcProvider client={...}> above it\");\n return client;\n}\n\n/**\n * A protocol error is the server's answer, not a hiccup: asking again gives\n * the same answer. Only transport failures and `busy` (another writer held the\n * lock past the server's wait; @jsudc/core 0.7.0) are retried, twice.\n */\nexport function shouldRetry(failureCount: number, error: unknown): boolean {\n return (!isUdcError(error) || isBusy(error)) && failureCount < 2;\n}\n\nexport interface UdcQueryClientOptions {\n /**\n * Called when a query or a mutation fails because the user is not signed in\n * (`isUnauthenticated`: an HTTP 401 in front of `/udc`, or the server's\n * in-protocol refusal) — the place to send the user to the host's login.\n * Once per burst: the failures that arrive together (every query of a page,\n * say) make one call; it fires again only after `unauthenticatedQuietMs`\n * without such a failure.\n */\n onUnauthenticated?: (error: UdcError) => void;\n /** The quiet time, in ms, that ends a burst of unauthenticated failures. Default 2000. */\n unauthenticatedQuietMs?: number;\n}\n\n/**\n * Calls `fn` on the first unauthenticated error and swallows the rest until\n * `quietMs` pass without one (each further error restarts that wait).\n */\nfunction unauthenticatedNotifier(\n fn: (error: UdcError) => void,\n quietMs: number,\n): (error: unknown) => void {\n let lastAt: number | null = null;\n return (error) => {\n if (!isUnauthenticated(error)) return;\n const now = Date.now();\n const inBurst = lastAt !== null && now - lastAt < quietMs;\n lastAt = now;\n if (!inBurst) fn(error as UdcError);\n };\n}\n\nexport function createUdcQueryClient(options: UdcQueryClientOptions = {}): QueryClient {\n const notify = options.onUnauthenticated\n ? unauthenticatedNotifier(options.onUnauthenticated, options.unauthenticatedQuietMs ?? 2000)\n : undefined;\n const qc = new QueryClient({\n ...(notify\n ? {\n queryCache: new QueryCache({ onError: notify }),\n mutationCache: new MutationCache({ onError: notify }),\n }\n : {}),\n defaultOptions: {\n queries: { retry: shouldRetry, refetchOnWindowFocus: false },\n mutations: { retry: false },\n },\n });\n // The change feed's unauthenticated error takes the same path (and the same burst).\n if (notify) registerUnauthenticated(qc, notify);\n return qc;\n}\n"],"mappings":";;;;;;AAOA,IAAa,mBAAmB,cAAgC,IAAI;AAEpE,SAAgB,eAA0B;CACxC,MAAM,SAAS,WAAW,gBAAgB;CAC1C,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,0DAA0D;CACvF,OAAO;AACT;;;;;;AAOA,SAAgB,YAAY,cAAsB,OAAyB;CACzE,QAAQ,CAAC,WAAW,KAAK,KAAK,OAAO,KAAK,MAAM,eAAe;AACjE;;;;;AAoBA,SAAS,wBACP,IACA,SAC0B;CAC1B,IAAI,SAAwB;CAC5B,QAAQ,UAAU;EAChB,IAAI,CAAC,kBAAkB,KAAK,GAAG;EAC/B,MAAM,MAAM,KAAK,IAAI;EACrB,MAAM,UAAU,WAAW,QAAQ,MAAM,SAAS;EAClD,SAAS;EACT,IAAI,CAAC,SAAS,GAAG,KAAiB;CACpC;AACF;AAEA,SAAgB,qBAAqB,UAAiC,CAAC,GAAgB;CACrF,MAAM,SAAS,QAAQ,oBACnB,wBAAwB,QAAQ,mBAAmB,QAAQ,0BAA0B,GAAI,IACzF,KAAA;CACJ,MAAM,KAAK,IAAI,YAAY;EACzB,GAAI,SACA;GACE,YAAY,IAAI,WAAW,EAAE,SAAS,OAAO,CAAC;GAC9C,eAAe,IAAI,cAAc,EAAE,SAAS,OAAO,CAAC;EACtD,IACA,CAAC;EACL,gBAAgB;GACd,SAAS;IAAE,OAAO;IAAa,sBAAsB;GAAM;GAC3D,WAAW,EAAE,OAAO,MAAM;EAC5B;CACF,CAAC;CAED,IAAI,QAAQ,wBAAwB,IAAI,MAAM;CAC9C,OAAO;AACT"}
@@ -25,7 +25,7 @@ export declare function useUdcCollections(): import("@tanstack/react-query").Use
25
25
  search?: "source" | undefined;
26
26
  changes?: boolean | undefined;
27
27
  };
28
- source_kind: "postgres_jsonb" | "memory" | "filesystem" | "http_api" | "yaml_menu" | "postgres_table";
28
+ source_kind: "postgres_jsonb" | "memory" | "filesystem" | "http_api" | "yaml_menu" | "postgres_table" | "sqlite_table";
29
29
  label?: string | undefined;
30
30
  group?: "database" | "files" | "internet" | undefined;
31
31
  }[];
@@ -50,7 +50,7 @@ export declare function useUdcDescribe(collection: string, opts?: {
50
50
  search?: "source" | undefined;
51
51
  changes?: boolean | undefined;
52
52
  };
53
- source_kind: "postgres_jsonb" | "memory" | "filesystem" | "http_api" | "yaml_menu" | "postgres_table";
53
+ source_kind: "postgres_jsonb" | "memory" | "filesystem" | "http_api" | "yaml_menu" | "postgres_table" | "sqlite_table";
54
54
  schema: {
55
55
  field_order: string[];
56
56
  version: string;
@@ -110,7 +110,9 @@ export declare function useUdcDescribe(collection: string, opts?: {
110
110
  [x: string]: unknown;
111
111
  fields: string[];
112
112
  case_insensitive: boolean;
113
- placeholder?: string | undefined;
113
+ placeholder
114
+ /** From `describe`: whether the source pages by cursor, and offers the change feed. */
115
+ ? /** From `describe`: whether the source pages by cursor, and offers the change feed. */: string | undefined;
114
116
  } | undefined;
115
117
  default_sort?: {
116
118
  field: string;
@@ -762,7 +764,7 @@ export declare function useUdcMutateMany(collection: string): UseMutationResult<
762
764
  updated: number;
763
765
  failed: {
764
766
  id: string;
765
- code: "not_found" | "validation_error" | "version_conflict" | "forbidden" | "unsupported_op" | "internal";
767
+ code: "not_found" | "validation_error" | "version_conflict" | "forbidden" | "unsupported_op" | "busy" | "internal";
766
768
  message?: string | undefined;
767
769
  }[];
768
770
  }, Error, UdcMutateManyVars, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsudc/react",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "React components for UDC collections: the data view, its table, cards, kanban, calendar, tree, map and chart renderers (one subpath each), the schema editor, headless hooks and models, i18n, theme and a compiled, udc:-prefixed stylesheet.",
@@ -120,7 +120,7 @@
120
120
  "@dnd-kit/core": "^6.3.1",
121
121
  "@dnd-kit/sortable": "^10.0.0",
122
122
  "@dnd-kit/utilities": "^3.2.2",
123
- "@jsudc/core": "^0.6.0",
123
+ "@jsudc/core": "^0.7.0",
124
124
  "@tanstack/react-query": "^5.104.4",
125
125
  "@tanstack/react-table": "^8.21.3",
126
126
  "leaflet": "^1.9.4",
@@ -159,7 +159,7 @@
159
159
  "@dnd-kit/core": "^6.3.1",
160
160
  "@dnd-kit/sortable": "^10.0.0",
161
161
  "@dnd-kit/utilities": "^3.2.2",
162
- "@jsudc/core": "^0.6.0",
162
+ "@jsudc/core": "^0.7.0",
163
163
  "@tailwindcss/cli": "^4.3.3",
164
164
  "@tanstack/react-query": "^5.104.4",
165
165
  "@tanstack/react-table": "^8.21.3",