@jsudc/react 0.3.0 → 0.4.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.
Files changed (91) hide show
  1. package/README.md +561 -20
  2. package/dist/calendar/CalendarRenderer.js +1 -1
  3. package/dist/calendar/EventDetail.js +1 -1
  4. package/dist/calendar.js +1 -1
  5. package/dist/cards/CardRenderer.d.ts +2 -1
  6. package/dist/cards/CardRenderer.js +143 -109
  7. package/dist/cards/CardRenderer.js.map +1 -1
  8. package/dist/cells/registry.d.ts +60 -0
  9. package/dist/cells/registry.js +47 -0
  10. package/dist/cells/registry.js.map +1 -0
  11. package/dist/chart/ChartWindowControl.js +1 -1
  12. package/dist/components/ui/checkbox.js +1 -1
  13. package/dist/components/ui/dialog.js +4 -3
  14. package/dist/components/ui/dialog.js.map +1 -1
  15. package/dist/components/ui/dropdown-menu.js +2 -1
  16. package/dist/components/ui/dropdown-menu.js.map +1 -1
  17. package/dist/components/ui/popover.js +2 -1
  18. package/dist/components/ui/popover.js.map +1 -1
  19. package/dist/components/ui/select.js +2 -1
  20. package/dist/components/ui/select.js.map +1 -1
  21. package/dist/components/ui/toast.js +3 -2
  22. package/dist/components/ui/toast.js.map +1 -1
  23. package/dist/components/ui/tooltip.js +2 -1
  24. package/dist/components/ui/tooltip.js.map +1 -1
  25. package/dist/data-view/FilterBuilder.js +1 -1
  26. package/dist/data-view/FilterChips.js +1 -1
  27. package/dist/data-view/Freshness.js +1 -1
  28. package/dist/data-view/SearchBox.js +1 -1
  29. package/dist/data-view/UdcDataView.d.ts +83 -1
  30. package/dist/data-view/UdcDataView.js +171 -85
  31. package/dist/data-view/UdcDataView.js.map +1 -1
  32. package/dist/data-view/useDataViewState.d.ts +8 -0
  33. package/dist/data-view/useDataViewState.js +2 -1
  34. package/dist/data-view/useDataViewState.js.map +1 -1
  35. package/dist/headless.d.ts +3 -0
  36. package/dist/headless.js +5 -2
  37. package/dist/i18n/translations.js +8 -0
  38. package/dist/i18n/translations.js.map +1 -1
  39. package/dist/index.d.ts +6 -3
  40. package/dist/index.js +7 -3
  41. package/dist/kanban/KanbanColumn.js +1 -1
  42. package/dist/kanban/KanbanRenderer.js +1 -1
  43. package/dist/kanban/model.d.ts +7 -0
  44. package/dist/kanban/model.js +19 -1
  45. package/dist/kanban/model.js.map +1 -1
  46. package/dist/kanban/useKanbanBoard.d.ts +5 -1
  47. package/dist/kanban/useKanbanBoard.js +6 -2
  48. package/dist/kanban/useKanbanBoard.js.map +1 -1
  49. package/dist/lib/scope.d.ts +8 -0
  50. package/dist/lib/scope.js +12 -0
  51. package/dist/lib/scope.js.map +1 -0
  52. package/dist/lookup/LookupCombobox.js +2 -2
  53. package/dist/lookup/LookupCombobox.js.map +1 -1
  54. package/dist/map/MapRenderer.js +1 -1
  55. package/dist/renderers/types.d.ts +12 -0
  56. package/dist/renderers/types.js.map +1 -1
  57. package/dist/rows/useRowActivation.d.ts +74 -0
  58. package/dist/rows/useRowActivation.js +225 -0
  59. package/dist/rows/useRowActivation.js.map +1 -0
  60. package/dist/schema-editor/DeleteFieldDialog.js +1 -1
  61. package/dist/schema-editor/FieldFormDialog.js +1 -1
  62. package/dist/schema-editor/TagInput.js +1 -1
  63. package/dist/styles.css +1 -1
  64. package/dist/styles.scoped.css +2 -0
  65. package/dist/table/CellEditor.js +1 -0
  66. package/dist/table/CellEditor.js.map +1 -1
  67. package/dist/table/TableRenderer.d.ts +2 -1
  68. package/dist/table/TableRenderer.js +41 -8
  69. package/dist/table/TableRenderer.js.map +1 -1
  70. package/dist/table/cells.d.ts +13 -2
  71. package/dist/table/cells.js +14 -1
  72. package/dist/table/cells.js.map +1 -1
  73. package/dist/table/states.d.ts +6 -0
  74. package/dist/table/states.js +14 -1
  75. package/dist/table/states.js.map +1 -1
  76. package/dist/tree/TreeNode.js +1 -1
  77. package/dist/tree/TreeRenderer.js +1 -1
  78. package/dist/udc/client.d.ts +15 -1
  79. package/dist/udc/client.js +31 -10
  80. package/dist/udc/client.js.map +1 -1
  81. package/dist/udc/hooks.d.ts +8 -3
  82. package/dist/udc/provider.d.ts +5 -2
  83. package/dist/udc/provider.js +6 -1
  84. package/dist/udc/provider.js.map +1 -1
  85. package/dist/ui-kit/ui.d.ts +1 -0
  86. package/dist/ui.js +2 -1
  87. package/dist/url-state/adapters.d.ts +23 -0
  88. package/dist/url-state/adapters.js +57 -0
  89. package/dist/url-state/adapters.js.map +1 -0
  90. package/dist/url-state/index.d.ts +1 -0
  91. package/package.json +6 -4
package/README.md CHANGED
@@ -40,7 +40,7 @@ npm install @jsudc/react @jsudc/core \
40
40
  # then the peers of the renderers you register (see Renderers), all of them:
41
41
  npm install @tanstack/react-table leaflet recharts @dnd-kit/core @dnd-kit/sortable @dnd-kit/utilities
42
42
  # or straight from a GitHub tag:
43
- npm install github:digital-cube/jsudc-core#v0.3.0 github:digital-cube/jsudc-react#v0.3.0
43
+ npm install github:digital-cube/jsudc-core#v0.4.0 github:digital-cube/jsudc-react#v0.4.0
44
44
  ```
45
45
 
46
46
  ## Quick start
@@ -85,17 +85,17 @@ collections, so each one starts from a fresh view.
85
85
 
86
86
  ### The providers a host wraps
87
87
 
88
- | Provider | Needed | Why |
89
- | ----------------------------------------------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
90
- | `UdcProvider client={new UdcClient(...)}` | yes | every hook reads the client from it; `renderers={…}` is what the data view draws its tabs with (none given: every tab says no renderer is registered) |
91
- | `QueryClientProvider client={createUdcQueryClient()}` | yes | the hooks are TanStack Query; `createUdcQueryClient` retries transport failures only, never a protocol error |
92
- | `UdcI18nProvider` | yes | every string goes through `useI18n()` |
93
- | `TooltipProvider` | yes | Radix tooltips on headers, chips and buttons; with your own kit, `kit.TooltipProvider` (see [Bring your own primitives](#bring-your-own-primitives)) |
94
- | `Toaster` | yes | save, conflict and schema-edit toasts (`useToast`); with your own kit, `kit.Toaster` |
95
- | `UdcUrlStateProvider` / `UdcReactRouterUrlState` | no | where search, filters, sort, paging and the tab live; without it `window.location` (see [URL state](#url-state)) |
96
- | `UdcLinksProvider` / `collectionPath` | no | where lookup links and `row_link`s go; without it `/c/<collection>` (see [Lookups and drill-down](#lookups-and-drill-down)) |
97
- | `TimezoneProvider` | no | without it instants are shown in the browser's zone; with it the user's pick, kept in `localStorage` (`udc-tz`) |
98
- | `ThemeProvider` | no | `useTheme()` toggles the `dark` class on `<html>` and keeps the choice (`udc-theme`); any other way of setting that class works too |
88
+ | Provider | Needed | Why |
89
+ | ----------------------------------------------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
90
+ | `UdcProvider client={new UdcClient(...)}` | yes | every hook reads the client from it; `renderers={…}` is what the data view draws its tabs with (none given: every tab says no renderer is registered) |
91
+ | `QueryClientProvider client={createUdcQueryClient()}` | yes | the hooks are TanStack Query; `createUdcQueryClient` retries transport failures only, never a protocol error; `onUnauthenticated` see [Sessions](#sessions) |
92
+ | `UdcI18nProvider` | yes | every string goes through `useI18n()` |
93
+ | `TooltipProvider` | yes | Radix tooltips on headers, chips and buttons; with your own kit, `kit.TooltipProvider` (see [Bring your own primitives](#bring-your-own-primitives)) |
94
+ | `Toaster` | yes | save, conflict and schema-edit toasts (`useToast`); with your own kit, `kit.Toaster` |
95
+ | `UdcUrlStateProvider` / `UdcReactRouterUrlState` | no | where search, filters, sort, paging and the tab live; without it `window.location` (see [URL state](#url-state)) |
96
+ | `UdcLinksProvider` / `collectionPath` | no | where lookup links and `row_link`s go; without it `/c/<collection>` (see [Lookups and drill-down](#lookups-and-drill-down)) |
97
+ | `TimezoneProvider` | no | without it instants are shown in the browser's zone; with it the user's pick, kept in `localStorage` (`udc-tz`) |
98
+ | `ThemeProvider` | no | `useTheme()` toggles the `dark` class on `<html>` and keeps the choice (`udc-theme`); any other way of setting that class works too |
99
99
 
100
100
  ## Renderers
101
101
 
@@ -143,6 +143,89 @@ peer is optional, builds and the import throws
143
143
  when the module loads. The root, `/table`, `/cards`, `/calendar` and
144
144
  `/headless` load without it.
145
145
 
146
+ ### Writing a renderer: the `RendererProps` contract
147
+
148
+ A host draws rows its own way (a message list, a timeline) by registering a
149
+ renderer of its own; `UdcDataView` hands its `component` the props below. They
150
+ are a **public contract**: from 0.4.0 none of them is renamed, removed or
151
+ retyped outside a major release, and a prop added later is optional, so a
152
+ renderer written today keeps compiling (the package's `npm run check:types`
153
+ compiles a host-written renderer against the published declarations and fails
154
+ when this table drifts).
155
+
156
+ | Prop | Type | What it is |
157
+ | ------------------------------------ | ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------- |
158
+ | `collection` | `string` | the collection's name |
159
+ | `describe` | `DescribeResponse` | its schema, view and capabilities, soft-deleted fields already gone |
160
+ | `data` | `UdcCollectionResult` | the view's paged list (`rows`, `total`, `isLoading`, `error`, `hasNextPage`, `fetchNextPage`, …); loaded only when `paging: true` |
161
+ | `filter` | `FilterNode \| undefined` | everything that filters the rows, composed: the host's `filter`, search, chips, the filter tree, the chart window |
162
+ | `baseFilter` | `FilterNode \| undefined` | `filter` without the search, for a renderer that searches what it loaded |
163
+ | `unwindowedFilter` | `FilterNode \| undefined` (optional) | `filter` without the chart window: what "of M" counts |
164
+ | `chartWindow` | `ChartWindowState \| undefined` (optional) | the chart window when one applies (already in `filter`) |
165
+ | `search` | `string` | the search box as typed (for highlighting) |
166
+ | `sort`, `onSort(field, multi)` | `SortKey[]`, function | the sort and the header click that cycles it |
167
+ | `mode`, `page`, `limit`, `onPage(n)` | `"pages" \| "infinite"`, numbers, function | the paging mode, the 1-based page, the page size, go to a page |
168
+ | `filtered`, `onClearFilters()` | `boolean`, function | did the user filter (the host's `filter` does not count), and "clear filters" for the empty state |
169
+ | `resetKey` | `string` | changes whenever the rows mean something else: scroll back to the top on it |
170
+ | `onCount(count \| null)` | function | a renderer with `paging: false` reports what the toolbar's "Showing N of M" says (`RendererCount`) |
171
+ | `onSchemaAction` | function (optional) | set when the schema may be edited and the renderer has `editMode` |
172
+ | `folder` | `FolderNav \| undefined` (optional) | set when the view has `folder_options` |
173
+ | `onRowActivate(row)` | function (optional) | Enter or a plain click on a row ([Row activation and keyboard](#row-activation-and-keyboard)); set only when the host passed one |
174
+ | `activeRowId` | `string \| null` (optional) | the row to draw as active; set whenever activation is on (the view keeps it when the host does not) |
175
+ | `onActiveRowChange(row \| null)` | function (optional) | report the active row moving (keys, a click on another row); set whenever activation is on |
176
+
177
+ The three activation props are absent unless the host turned activation on;
178
+ `useRowActivation` of `@jsudc/react/headless` does everything they describe
179
+ (see [Row activation and keyboard](#row-activation-and-keyboard)). How one
180
+ column's cells are drawn is not a renderer's business: see
181
+ [Custom cells](#custom-cells).
182
+
183
+ A renderer with `paging: true` draws `data` and needs nothing else; one with
184
+ `paging: false` loads its own rows with `filter` (the hooks of
185
+ `@jsudc/react/headless`, e.g. `useUdcAllRows`) and reports `onCount`. A message
186
+ list of a mail client:
187
+
188
+ ```tsx
189
+ import { createRendererRegistry, type RendererDefinition, type RendererProps } from "@jsudc/react";
190
+ import { tableRenderer } from "@jsudc/react/table";
191
+ import { Inbox } from "lucide-react";
192
+
193
+ function MessageList({ data, filtered, onClearFilters, mode, page, limit, onPage }: RendererProps) {
194
+ if (data.isLoading) return <p>Loading…</p>;
195
+ if (data.rows.length === 0) {
196
+ return filtered ? <button onClick={onClearFilters}>Clear filters</button> : <p>No messages</p>;
197
+ }
198
+ return (
199
+ <div>
200
+ <ul>
201
+ {data.rows.map((row) => (
202
+ <li key={row.__meta.id}>
203
+ <b>{String(row.subject)}</b> · {String(row.from)}
204
+ </li>
205
+ ))}
206
+ </ul>
207
+ {mode === "infinite" && data.hasNextPage ? (
208
+ <button onClick={data.fetchNextPage}>More</button>
209
+ ) : null}
210
+ {mode === "pages" && data.total !== null && page * limit < data.total ? (
211
+ <button onClick={() => onPage(page + 1)}>Next</button>
212
+ ) : null}
213
+ </div>
214
+ );
215
+ }
216
+
217
+ export const messageList: RendererDefinition = {
218
+ name: "messages", // the name a view lists in available_renderers
219
+ component: MessageList,
220
+ icon: Inbox,
221
+ labelKey: "TAB_MESSAGES", // APP.TAB_MESSAGES, through `messages` of UdcI18nProvider
222
+ paging: true, // reads `data`: the list loads, the paging toggle shows
223
+ editMode: false,
224
+ };
225
+
226
+ const renderers = createRendererRegistry(tableRenderer, messageList);
227
+ ```
228
+
146
229
  ## Headless
147
230
 
148
231
  `@jsudc/react/headless` is the data layer under the renderers, with no JSX, no
@@ -161,15 +244,22 @@ URL state.
161
244
  `TreeDropPlan`: the tree's names, prefixed), `useTreeExpand`;
162
245
  - `applyTransforms`, `displayText`, `renderKind` and the cell formatters;
163
246
  the zone helpers and `useTimezone`;
247
+ - `useRowActivation` (the active row and the keys, see
248
+ [Row activation and keyboard](#row-activation-and-keyboard)) and the cell
249
+ registry (`createCellRegistry`, `UdcCellsProvider`, `useCellRegistry`, see
250
+ [Custom cells](#custom-cells));
164
251
  - the registry functions (`createRendererRegistry`, `resolveTab`) and the URL
165
- state adapter, so its hooks behave exactly as inside `UdcDataView`.
252
+ state adapters (`windowLocationAdapter`, `prefixUrlStateAdapter`,
253
+ `createMemoryUrlStateAdapter`), so its hooks behave exactly as inside
254
+ `UdcDataView`.
166
255
 
167
256
  ## URL state
168
257
 
169
258
  The data view keeps what the user chose in the query string, so a link or a
170
259
  reload opens the same view: the tab (`?tab=`), the search (`?q=`), the chips
171
260
  and the filter tree, the sort, the paging mode and the page, the kanban board
172
- (`?board=`), the chart window (`?win=`, `?from=&to=`) and the calendar
261
+ (`?board=`; without it, the board an `eq` filter on the board field names, else
262
+ the first), the chart window (`?win=`, `?from=&to=`) and the calendar
173
263
  (`?preset=&date=`). Filters, sort and windows **replace** the current history
174
264
  entry; they are not a step the Back button walks through.
175
265
 
@@ -272,6 +362,336 @@ export function NextUrlState({ children }: { children: React.ReactNode }) {
272
362
  `[params, setParams]` pair the view uses, over whichever adapter is in effect;
273
363
  a function passed to `setParams` receives the query string as it is now.
274
364
 
365
+ Two views on one page, or a view inside a host route with parameters of its
366
+ own: give each a prefix (`urlPrefix`) or keep its state in memory
367
+ (`urlState="memory"`), see [Embedding a view](#embedding-a-view).
368
+
369
+ ## Embedding a view
370
+
371
+ `UdcDataView` can be one pane of a host's screen rather than a page: the
372
+ message list of a mail client between its folder list and its reading pane.
373
+ Every prop below is optional; without them the view is what it always was.
374
+
375
+ | Prop | What it does |
376
+ | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
377
+ | `filter` | a `FilterNode` of the host's (the open folder), ANDed into every list the view and its renderers load and counted in "of M"; not a chip or pill, not in the URL, not removed by "clear filters" |
378
+ | `chrome` | which parts of the frame are drawn: `"full"` (default), `"embedded"`, or flags |
379
+ | `pagingMode` | the paging mode to open in, instead of the view's `pagination` |
380
+ | `toolbarStart`, `toolbarEnd` | the host's own controls at the start (before the search) and at the end (after the count) of the toolbar |
381
+ | `urlPrefix` | a prefix for every parameter the view and its renderers read and write |
382
+ | `urlState` | `"url"` (default: the adapter in effect), `"memory"`, or any `UrlStateAdapter` |
383
+
384
+ **The host's filter** is what the host decides and the user does not: the
385
+ folder, the account, the project. The user still searches, picks chips and
386
+ builds filters on top of it; "Clear" and "Clear filters" remove theirs and
387
+ leave the host's; an empty folder shows "no rows", not "no rows match, clear
388
+ filters". It reaches every renderer through `filter` / `baseFilter` (see
389
+ [the contract](#writing-a-renderer-the-rendererprops-contract)), so the
390
+ kanban, the calendar, the tree, the map and the chart load the folder's rows
391
+ too. Change it and the view asks again; an equal object passed anew each
392
+ render asks nothing.
393
+
394
+ **Chrome.** `chrome` is a preset or flags, `true` drawing the part; a flag
395
+ left out takes the preset's value (`full`: all on, `embedded`: all off):
396
+
397
+ | Flag | The part |
398
+ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
399
+ | `header` | the title and the description |
400
+ | `tabs` | the renderer tabs (with Doc or Source still on, the renderer in use stays as the way back) |
401
+ | `pagingToggle` | the pages / infinite switch; without it the mode is `pagingMode`, else the view's `pagination`, never a choice stored by an earlier session or `?mode=` |
402
+ | `docTab` | the Doc pseudo-tab (the collection's README) |
403
+ | `sourceTab` | the Source pseudo-tab (the source file) |
404
+ | `frame` | the card around toolbar and rows: border, rounding, shadow and the outer margins |
405
+
406
+ `chrome="embedded"` leaves the toolbar and the rows only;
407
+ `chrome={{ preset: "embedded", tabs: true }}` adds the tabs back. The parts
408
+ keep their [stable classes](#stable-classes); `data-testid="data-view-frame"`
409
+ carries `data-framed`.
410
+
411
+ **URL state per view.** By default the view's parameters are the page's own
412
+ (`?q=`, `?sort=`, …), which is right for a view that is the page. A pane
413
+ shares the query string with its host and maybe with other views, so:
414
+
415
+ - `urlPrefix="inbox."` makes the view and its renderers use `inbox.q`,
416
+ `inbox.sort`, `inbox.p`, `inbox.board`, `inbox.win`, … and leave every
417
+ other parameter alone: a host route with a `?q=` of its own is neither read
418
+ nor removed, and two views with different prefixes keep separate search,
419
+ sort and page on one page. End the prefix with a separator: every key that
420
+ starts with it is the view's.
421
+ - `urlState="memory"` keeps the view's state in memory, its own store: the
422
+ address bar is never touched, and a reload starts afresh.
423
+ - `urlState={adapter}` uses any `UrlStateAdapter` (a host store, a router
424
+ adapter); `urlPrefix` applies on top of it.
425
+
426
+ Both are adapters, exported from the root and from `@jsudc/react/headless`
427
+ for a host's own components and headless renderers:
428
+ `prefixUrlStateAdapter(inner, prefix)` wraps any `UrlStateAdapter` (it reads
429
+ and writes only its own keys; `subscribe` is the inner one's), and
430
+ `createMemoryUrlStateAdapter(initial?)` is a store of its own (its `history`
431
+ lists what was written). Because the prefix applies at the adapter, every
432
+ parameter is covered, the kanban's, the chart's and the calendar's included:
433
+
434
+ ```tsx
435
+ import { prefixUrlStateAdapter, UdcUrlStateProvider, useUrlStateAdapter } from "@jsudc/react";
436
+ import { type ReactNode, useMemo } from "react";
437
+
438
+ /** The host's own controls of the pane share the view's `inbox.` parameters. */
439
+ function InboxPane({ children }: { children: ReactNode }) {
440
+ const inEffect = useUrlStateAdapter();
441
+ const adapter = useMemo(() => prefixUrlStateAdapter(inEffect, "inbox."), [inEffect]);
442
+ // Inside: useUrlSearchParams() sees `q` where the address bar has `inbox.q`.
443
+ return <UdcUrlStateProvider adapter={adapter}>{children}</UdcUrlStateProvider>;
444
+ }
445
+ ```
446
+
447
+ **A three-pane screen.** The folder list and the reading pane are the
448
+ host's; the message list is a data view with the folder as its filter, no
449
+ frame, the host's buttons in the toolbar and its state under `list.`:
450
+
451
+ ```tsx
452
+ import type { FilterNode } from "@jsudc/core";
453
+ import { UdcDataView } from "@jsudc/react";
454
+ import { useState } from "react";
455
+ import "@jsudc/react/styles.scoped.css";
456
+
457
+ const FOLDERS = ["inbox", "sent", "archive"] as const;
458
+
459
+ export function Mail() {
460
+ const [folder, setFolder] = useState<(typeof FOLDERS)[number]>("inbox");
461
+ const inFolder: FilterNode = { field: "folder", op: "eq", value: folder };
462
+
463
+ return (
464
+ <div style={{ display: "grid", gridTemplateColumns: "200px 1fr 1fr", height: "100vh" }}>
465
+ <nav>
466
+ {FOLDERS.map((f) => (
467
+ <button key={f} aria-current={f === folder} onClick={() => setFolder(f)}>
468
+ {f}
469
+ </button>
470
+ ))}
471
+ </nav>
472
+
473
+ <UdcDataView
474
+ collection="messages"
475
+ renderers={renderers} // createRendererRegistry(tableRenderer, messageList), see Renderers
476
+ filter={inFolder}
477
+ chrome={{ preset: "embedded", tabs: true }}
478
+ pagingMode="infinite"
479
+ urlPrefix="list."
480
+ toolbarStart={<button onClick={() => compose()}>Compose</button>}
481
+ toolbarEnd={<button onClick={() => syncMailbox()}>Sync</button>}
482
+ />
483
+
484
+ <article>{/* the host's reading pane */}</article>
485
+ </div>
486
+ );
487
+ }
488
+ ```
489
+
490
+ The address bar then reads `/mail?list.q=invoice&list.sort=date:desc`, and a
491
+ parameter the host keeps for itself (`?folder=`, `?q=`) stays untouched.
492
+ Opening a row in the reading pane is
493
+ [row activation](#row-activation-and-keyboard).
494
+
495
+ ## Row activation and keyboard
496
+
497
+ A row can do something of the host's: open the message in the reading pane.
498
+ `UdcDataView` takes three props, all optional; passing any of them turns
499
+ activation on, and without them the rows are what they were (no tab stop, no
500
+ keys, no active row, a `row_link` still followed on click):
501
+
502
+ | Prop | What it does |
503
+ | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
504
+ | `onRowActivate(row)` | called on Enter on a row and on a plain click of it (the main button, no modifier, not on a link, button or input in it) |
505
+ | `activeRowId` | the row drawn as active. Passed: controlled (`null` for none), the host moves it in `onActiveRowChange`. Left out: the view keeps it itself |
506
+ | `onActiveRowChange(row)` | the active row changed by the user: moved by the keys (no Enter needed), or a click on another row (just before `onRowActivate`). Preview on move here |
507
+
508
+ **Keys**, in the table and the cards, while the focus is on a row:
509
+ ArrowDown / `j` and ArrowUp / `k` move the active row (and the focus) by one,
510
+ Home / End jump to the first / last loaded row, Enter activates. They are
511
+ left alone while an input, the search box, a cell editor, a menu, a list box
512
+ or a dialog has the focus, and with Ctrl, Cmd, Alt or Shift held. Space is
513
+ not bound (it is the selection's, in 0.5.0). Double-click and Enter still
514
+ edit an editable cell when the focus is on the cell itself.
515
+
516
+ **One tab stop.** The rows are a roving-`tabindex` list: Tab reaches the
517
+ active row (else the one last focused, else the first) and leaves the list on
518
+ the next Tab. The table is `role="grid"`; the card grid too, each card a
519
+ `row`. The active row has `aria-selected="true"`, the attribute
520
+ `data-active="true"` (`.udc-row[data-active]`, `.udc-card[data-active]` for
521
+ your CSS) and the `--selected` background.
522
+
523
+ **Kept by id.** The active row and the focus follow the row's id across a
524
+ refetch, a sort and pages loading in infinite mode; ArrowDown on the last
525
+ loaded row in infinite mode loads the next page and moves onto its first
526
+ row; the active row is scrolled into view, also when the host sets
527
+ `activeRowId`. A row that left the list (deleted, filtered out) stops being
528
+ active without an error; when it comes back it is active again.
529
+
530
+ **`row_link`.** Without `onRowActivate` a click follows the view's
531
+ `row_link` as before. With it a plain click activates the row, and Cmd /
532
+ Ctrl-click and the middle button still open the link (in a new tab).
533
+
534
+ A list and a reading pane side by side, the pane following the keyboard: the
535
+ arrows preview, Enter or a click opens (marks the message read):
536
+
537
+ ```tsx
538
+ import type { Row } from "@jsudc/core";
539
+ import { UdcDataView } from "@jsudc/react";
540
+ import { useState } from "react";
541
+
542
+ export function Mailbox() {
543
+ const [open, setOpen] = useState<Row | null>(null);
544
+
545
+ return (
546
+ <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", height: "100vh" }}>
547
+ <UdcDataView
548
+ collection="messages"
549
+ chrome="embedded"
550
+ pagingMode="infinite"
551
+ // Controlled: the open message is the active row, so the pane and the list agree.
552
+ activeRowId={open?.__meta.id ?? null}
553
+ onActiveRowChange={setOpen} // ArrowDown / j: the pane previews the next message
554
+ onRowActivate={(row) => {
555
+ setOpen(row);
556
+ void markRead(row.__meta.id); // Enter or a click: the host's own action
557
+ }}
558
+ />
559
+ <article aria-live="polite">
560
+ {open ? (
561
+ <>
562
+ <h2>{String(open.subject)}</h2>
563
+ <p>{String(open.from)}</p>
564
+ </>
565
+ ) : (
566
+ <p>No message selected</p>
567
+ )}
568
+ </article>
569
+ </div>
570
+ );
571
+ }
572
+ ```
573
+
574
+ Leave `activeRowId` out and the view keeps the active row itself (across
575
+ tab switches too); pass only `onRowActivate` when moving should not open
576
+ anything.
577
+
578
+ **In a host renderer.** `UdcDataView` hands a renderer the same three props
579
+ (see [the contract](#writing-a-renderer-the-rendererprops-contract)), and
580
+ `useRowActivation` of `@jsudc/react/headless` (also on the root) gives it the
581
+ table's behaviour: spread `rowProps(row)` on each row's element (ref,
582
+ `tabIndex`, `aria-selected`, `data-active`, the key and focus handlers) and
583
+ call `handleClick(e, row)` from its `onClick`:
584
+
585
+ ```tsx
586
+ import type { RendererProps } from "@jsudc/react";
587
+ import { useRowActivation } from "@jsudc/react/headless";
588
+
589
+ function MessageList({ data, onRowActivate, activeRowId, onActiveRowChange }: RendererProps) {
590
+ const nav = useRowActivation({
591
+ rows: data.rows,
592
+ onRowActivate,
593
+ activeRowId,
594
+ onActiveRowChange,
595
+ // Infinite mode: moving past the last row loads the next page.
596
+ hasNextPage: data.hasNextPage,
597
+ isFetchingNextPage: data.isFetchingNextPage,
598
+ fetchNextPage: data.fetchNextPage,
599
+ });
600
+ return (
601
+ <ul role={nav.enabled ? "grid" : undefined}>
602
+ {data.rows.map((row) => (
603
+ <li
604
+ key={row.__meta.id}
605
+ role={nav.enabled ? "row" : undefined}
606
+ {...nav.rowProps(row)}
607
+ onClick={(e) => nav.handleClick(e, row)}
608
+ >
609
+ {String(row.subject)}
610
+ </li>
611
+ ))}
612
+ </ul>
613
+ );
614
+ }
615
+ ```
616
+
617
+ `nav.activeRowId` is the active row (when it is loaded), `nav.move("next")`
618
+ and `nav.activate(row)` drive it from the host's own buttons, and `ownsKeys`
619
+ says whether a key belongs to the element it was pressed on.
620
+
621
+ ## Custom cells
622
+
623
+ A column of the table can be drawn by a component of the host's. Register
624
+ cell components by name, the way renderers are registered, and name one in
625
+ the column's `render`:
626
+
627
+ ```yaml
628
+ view:
629
+ columns:
630
+ - field: from
631
+ render: sender # the host's component
632
+ render_options: { avatar: true }
633
+ - field: label
634
+ render: badge # built in, unless the host registered "badge"
635
+ ```
636
+
637
+ `render: "<name>"` resolves from the host's registry first, then from the
638
+ built-in kinds (`bool`, `badge`, `sparkline`, `heading_glyph`, `icon`,
639
+ `date`, `datetime`, `number_format`, `bytes`, `text`); a name nobody
640
+ registered behaves as before (the field type's kind). Registering a built-in
641
+ name replaces that kind for every column that names it in `render` (a
642
+ column that only inherits a kind from its field type keeps the built-in).
643
+ The cards draw their meta fields through the same registry; the other
644
+ renderers (the kanban's, the calendar's, the map's and the chart's details)
645
+ keep the built-in kinds.
646
+
647
+ A cell component receives `CellProps`, a public contract like
648
+ `RendererProps`:
649
+
650
+ | Prop | Type | What it is |
651
+ | ---------------------- | ----------------------- | ----------------------------------------------------------------------------------------- |
652
+ | `value` | `unknown` | `row[column.field]` as the server sent it; blank values too (draw your own empty) |
653
+ | `row` | `Row` | the whole row, `__meta` (id, version) included |
654
+ | `column` | `ColumnConfig` | the column from `view.columns[]` (or the card's meta field): `render_options`, `align`, … |
655
+ | `def` | `FieldDef \| undefined` | the field's definition in the schema |
656
+ | `collection` | `string` | the collection's name |
657
+ | `locale`, `intlLocale` | `string` | the UI's language and its `Intl` locale |
658
+ | `editable` | `boolean` | the cell edits on double-click (the inline editor draws over your component) |
659
+ | `surface` | `"table" \| "card"` | a table cell or a card's meta field |
660
+
661
+ ```tsx
662
+ import { type CellProps, createCellRegistry, UdcDataView, UdcProvider } from "@jsudc/react";
663
+
664
+ /** The sender as an avatar and a name, the unread ones bold. */
665
+ function SenderCell({ value, row, column }: CellProps) {
666
+ const name = String(value ?? "");
667
+ return (
668
+ <span style={{ display: "flex", gap: 6, fontWeight: row.unread ? 600 : 400 }}>
669
+ {column.render_options?.avatar ? (
670
+ <img src={`/avatars/${name}.png`} alt="" width={20} />
671
+ ) : null}
672
+ {name || "—"}
673
+ </span>
674
+ );
675
+ }
676
+
677
+ // A module constant, like the renderer registry.
678
+ const cells = createCellRegistry({ name: "sender", component: SenderCell });
679
+
680
+ <UdcProvider client={client} renderers={renderers} cells={cells}>
681
+ …
682
+ </UdcProvider>;
683
+
684
+ // Or for one view, added to the provider's (this view's names win):
685
+ <UdcDataView collection="messages" cells={cells} />;
686
+ ```
687
+
688
+ `createCellRegistry` takes `{ name, component }` definitions, a later one
689
+ replacing an earlier name; a plain `{ sender: SenderCell }` object is a
690
+ registry too. `UdcCellsProvider cells={…}` sets one anywhere in the tree
691
+ (nested providers add up, the inner names winning) and `useCellRegistry()`
692
+ reads the one in effect; `CellValue` of `@jsudc/react/table` draws with it
693
+ when passed `cells`, `row` and `collection`.
694
+
275
695
  ## Bring your own primitives
276
696
 
277
697
  The renderers never import a button, a dialog or a menu. They take every
@@ -355,7 +775,7 @@ peer while the default kit is the fallback.
355
775
  Everything the components import that a host is likely to have too is a peer,
356
776
  so there is one copy of it in the bundle:
357
777
 
358
- - `@jsudc/core` ^0.3.0 — one copy of the protocol, shared with the host's
778
+ - `@jsudc/core` ^0.4.0 — one copy of the protocol, shared with the host's
359
779
  own `UdcClient`;
360
780
  - `react`, `react-dom` ^19 — one React, or hooks break;
361
781
  - `@tanstack/react-query` ^5 — one `QueryClient` context, shared with the
@@ -398,10 +818,57 @@ The stylesheet also carries the library's base rules (`border-color` on `*`,
398
818
  `body` font and colours, pointer cursor on buttons) in `@layer base`; any
399
819
  unlayered CSS of the host wins over them.
400
820
 
821
+ ### The scoped sheet: a stylesheet that leaves the host alone
822
+
823
+ `styles.css` is made for a page that is the library's: its preflight resets
824
+ every `h1`, `button` and list of the page, its `body` rule sets the page's
825
+ font and colours, and its tokens sit on `:root`, where they overwrite a
826
+ host's own `--background` or `--primary`. A host that embeds a view in pages
827
+ of its own imports the scoped sheet instead (one of the two, not both):
828
+
829
+ ```ts
830
+ import "@jsudc/react/styles.scoped.css";
831
+ ```
832
+
833
+ It has the same utilities, tokens and resets, applied only inside the
834
+ library's roots: `.udc-data-view`, and `.udc-scope` (`UDC_SCOPE_CLASS`), which
835
+ the default UI kit puts on everything it portals out of the view (dialogs,
836
+ popovers, menus, selects, tooltips, toasts). There is no rule on `*`, `html`,
837
+ `body` or `:root`, no global preflight and no `@property` registration, so
838
+ the host's elements compute exactly the styles they computed before; the
839
+ build fails if a selector of the sheet could match an element outside a root
840
+ (`scripts/check-scoped-css.mjs`), and a test compares the computed styles of a
841
+ host's page with and without it in headless Chrome.
842
+
843
+ | Situation | Sheet |
844
+ | ------------------------------------------------------------------------ | ------------------- |
845
+ | the page is the library's (an admin, a back office), or a new app | `styles.css` |
846
+ | the view is a pane of the host's own pages, with the host's own base CSS | `styles.scoped.css` |
847
+ | the host's tokens share the generic names (`--background`, `--primary`) | `styles.scoped.css` |
848
+
849
+ What changes with it:
850
+
851
+ - **Theming:** the tokens are declared on the roots, at zero specificity
852
+ (`:where(.udc-data-view, .udc-scope)`), so the host restyles the library on
853
+ the roots, not on `:root`: `.udc-data-view, .udc-scope { --primary: …; }`.
854
+ `.dark` on any ancestor (or on the root itself) switches both themes as
855
+ before.
856
+ - **Components outside a view:** a `LookupCombobox` or a schema dialog
857
+ rendered by the host outside `<UdcDataView>` needs a root around it:
858
+ `<div className={UDC_SCOPE_CLASS}>…</div>`. A host-supplied UI kit that
859
+ portals its own content does the same if that content relies on the
860
+ library's sheet.
861
+ - **The background:** a root paints none; the view sits on the host's pane.
862
+ - **The cascade:** the resets are in `@layer base` and the utilities in
863
+ `@layer utilities`, as in `styles.css`, so an unlayered element rule of the
864
+ host (`button { background: … }`) still reaches inside the view. Put the
865
+ host's own base styles in a layer, or scope them, if they should not.
866
+
401
867
  ### Theming
402
868
 
403
869
  Every colour, radius and font comes from a CSS variable on `:root` and
404
- `.dark`. Restyling is redefining them after the stylesheet, no code:
870
+ `.dark` (with the scoped sheet: on the library's roots, see above).
871
+ Restyling is redefining them after the stylesheet, no code:
405
872
 
406
873
  ```css
407
874
  :root {
@@ -449,6 +916,7 @@ change with them, for plain-CSS overrides:
449
916
  | Class | Element |
450
917
  | -------------------- | ------------------------------------------------- |
451
918
  | `udc-data-view` | the whole view (header, toolbar, the renderer) |
919
+ | `udc-scope` | a portalled dialog, popover, menu, tooltip, toast |
452
920
  | `udc-toolbar` | the toolbar: search, chips, filter builder, count |
453
921
  | `udc-search` | the search box |
454
922
  | `udc-filter-chip` | one filter chip |
@@ -481,6 +949,9 @@ change with them, for plain-CSS overrides:
481
949
  }
482
950
  ```
483
951
 
952
+ With row activation on, the active row and card also carry
953
+ `data-active="true"` (`.udc-row[data-active] .udc-cell { … }`).
954
+
484
955
  A rule of the host's own (unlayered) CSS wins over the library's utilities,
485
956
  which sit in Tailwind's `@layer utilities`, without `!important`; only inline
486
957
  styles (row height, column widths, pinned offsets) need it.
@@ -523,6 +994,63 @@ const messages: Messages = {
523
994
  - `useI18n()` gives `t`, `tMaybe` (`null` when missing), `locale`,
524
995
  `intlLocale`, `locales` and `setLocale` to your own components too.
525
996
 
997
+ ## Sessions
998
+
999
+ A host with a cookie session and a CSRF token uses the client as it is: the
1000
+ `UdcClient` of `@jsudc/core` reads its `headers` per call when they are a
1001
+ function, sends cookies to another origin with `credentials: "include"`, and
1002
+ turns "not signed in" — an HTTP 401 in front of `/udc`, or the server's
1003
+ in-protocol refusal (`forbidden`, `details.reason: "unauthenticated"`) — into
1004
+ one error, `isUnauthenticated(err)`. That error is never retried. The library
1005
+ does two things with it:
1006
+
1007
+ - **`createUdcQueryClient({ onUnauthenticated })`** calls your callback when a
1008
+ query or a mutation fails that way: the one place to send the user to your
1009
+ login. It is called once per burst — the failures that arrive together (every
1010
+ query of a page) make one call — and again only after
1011
+ `unauthenticatedQuietMs` (default 2000) without such a failure.
1012
+ `createUdcQueryClient()` without arguments works as before.
1013
+ - **The error state** of every view says the user is signed out
1014
+ (`APP.SIGNED_OUT_TITLE`, `APP.SIGNED_OUT_BODY`, overridable like every other
1015
+ term) instead of the generic failure with Retry.
1016
+
1017
+ ```tsx
1018
+ import { UdcClient } from "@jsudc/core/client";
1019
+ import { createUdcQueryClient, UdcDataView, UdcProvider } from "@jsudc/react";
1020
+ import { RENDERERS } from "@jsudc/react/all";
1021
+ import { QueryClientProvider } from "@tanstack/react-query";
1022
+
1023
+ // Django-style: the session cookie travels by itself, the CSRF token is a cookie
1024
+ // the page reads and echoes in a header — read on every call, so a new session
1025
+ // (and a new token) needs no new client.
1026
+ const csrfToken = () => document.cookie.match(/(?:^|; )csrftoken=([^;]*)/)?.[1] ?? "";
1027
+
1028
+ const client = new UdcClient({
1029
+ httpUrl: "https://api.example.com",
1030
+ credentials: "include", // cookies to another origin; leave it out on the same origin
1031
+ headers: () => ({ "x-csrftoken": csrfToken() }),
1032
+ });
1033
+
1034
+ const queryClient = createUdcQueryClient({
1035
+ // once, however many queries of the page were refused together
1036
+ onUnauthenticated: () => {
1037
+ const next = encodeURIComponent(location.pathname + location.search);
1038
+ location.assign(`/login?next=${next}`);
1039
+ },
1040
+ });
1041
+
1042
+ <UdcProvider client={client} renderers={RENDERERS}>
1043
+ <QueryClientProvider client={queryClient}>
1044
+ {/* …the other providers of the quick start… */}
1045
+ <UdcDataView collection="messages" />
1046
+ </QueryClientProvider>
1047
+ </UdcProvider>;
1048
+ ```
1049
+
1050
+ An HTTP 403 is `forbidden` with `details.http_status: 403`: also not retried,
1051
+ shown as the generic failure, and not passed to `onUnauthenticated`. Login
1052
+ screens, token refresh and storing the session are the host's.
1053
+
526
1054
  ## Lookups and drill-down
527
1055
 
528
1056
  A `lookup` / `lookup_array` field (see `@jsudc/core`) holds the key of a row of
@@ -553,6 +1081,9 @@ only stores and filters keys.
553
1081
  by a value of the clicked row, on a row click; Cmd / Ctrl-click and the
554
1082
  middle button open a new tab. Rows show a pointer. A click in an editable
555
1083
  cell, on a link or a control stays where it is (double-click still edits).
1084
+ A drill-down onto a kanban collection lands on the linked board: without a
1085
+ `?board=`, the board select (kanban and calendar) follows an `eq` on
1086
+ `kanban_options.ticket_board_field` in the filter.
556
1087
 
557
1088
  ```ts
558
1089
  const { row, rows, isLoading } = useUdcLookup("boards", ["b1", "b2"]); // keys are ids
@@ -581,11 +1112,20 @@ registry and everything not tied to one renderer. Beyond the above:
581
1112
  `createRendererRegistry`, `rendererEntry`, `rendererTabs`, `resolveTab`,
582
1113
  `UdcRenderersProvider`, `useRendererRegistry` and the `RendererProps` /
583
1114
  `RendererEntry` / `RendererDefinition` / `RendererRegistry` types;
584
- `EmptyState` / `ErrorState` / `NoRendererState`; `mergeMessages`, `makeT`,
1115
+ `EmptyState` / `ErrorState` / `NoRendererState`; the `UdcQueryClientOptions` type;
1116
+ the row activation `useRowActivation`, `rowActivationEnabled`, `ownsKeys`
1117
+ and the `RowActivationProps` / `RowActivation` / `RowActivationRowProps` /
1118
+ `UseRowActivationOptions` types; the cells `createCellRegistry`,
1119
+ `cellComponent`, `mergeCellRegistries`, `UdcCellsProvider`, `useCellRegistry`
1120
+ and the `CellProps` / `CellComponent` / `CellDefinition` / `CellRegistry`
1121
+ types; `mergeMessages`, `makeT`,
585
1122
  `lookup`, `schemaLabelTerms`, `tableSection`, `TRANSLATIONS`, `LOCALES`;
586
1123
  `cn` (tailwind-merge set up for the `udc:` prefix), `storage`, `humanize`;
587
- `UdcUrlStateProvider`, `useUrlSearchParams`, `windowLocationAdapter` and the
588
- `UrlStateAdapter` type; `UdcUiProvider`, `useUiKit` and the `UiKit` type with
1124
+ `UdcUrlStateProvider`, `useUrlSearchParams`, `windowLocationAdapter`,
1125
+ `prefixUrlStateAdapter`, `createMemoryUrlStateAdapter` and the
1126
+ `UrlStateAdapter` / `MemoryUrlStateAdapter` types; the embedding types
1127
+ `UdcDataViewChrome` / `UdcDataViewChromePreset` with `resolveChrome`, and
1128
+ `UDC_SCOPE_CLASS` (also on `@jsudc/react/ui`); `UdcUiProvider`, `useUiKit` and the `UiKit` type with
589
1129
  its props types; `resolveIcon` with the `lucide:<name>` icons the package
590
1130
  bundles (`LUCIDE_ICONS`); and the zone helpers `allZones`, `offsetLabel`,
591
1131
  `zoneCity`; the lookups: `useUdcLookup`, `useUdcLookups`, `useLookupBatch`,
@@ -598,7 +1138,8 @@ The subpaths: one per renderer and `@jsudc/react/all` (see
598
1138
  [Renderers](#renderers)), `@jsudc/react/headless` (see [Headless](#headless)),
599
1139
  `@jsudc/react/ui` (`defaultUiKit` and its primitives: `Button`, `Dialog`,
600
1140
  `Toaster`, `TooltipProvider`, …), `@jsudc/react/react-router`
601
- (`UdcReactRouterUrlState`), `@jsudc/react/styles.css` and
1141
+ (`UdcReactRouterUrlState`), `@jsudc/react/styles.css`,
1142
+ `@jsudc/react/styles.scoped.css` (see [Styling](#styling)) and
602
1143
  `@jsudc/react/tokens.css`.
603
1144
 
604
1145
  The build is ESM only, one file per source module (tree-shakeable), one