@jsudc/react 0.3.1 → 0.5.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 (144) hide show
  1. package/README.md +1137 -22
  2. package/dist/actions/RowActionsMenu.d.ts +45 -0
  3. package/dist/actions/RowActionsMenu.js +161 -0
  4. package/dist/actions/RowActionsMenu.js.map +1 -0
  5. package/dist/actions/bulk.d.ts +81 -0
  6. package/dist/actions/bulk.js +54 -0
  7. package/dist/actions/bulk.js.map +1 -0
  8. package/dist/actions/row.d.ts +50 -0
  9. package/dist/actions/row.js +34 -0
  10. package/dist/actions/row.js.map +1 -0
  11. package/dist/actions/useRowActionRunner.d.ts +26 -0
  12. package/dist/actions/useRowActionRunner.js +198 -0
  13. package/dist/actions/useRowActionRunner.js.map +1 -0
  14. package/dist/calendar/CalendarRenderer.js +5 -4
  15. package/dist/calendar/CalendarRenderer.js.map +1 -1
  16. package/dist/calendar/EventDetail.js +1 -1
  17. package/dist/calendar.js +1 -1
  18. package/dist/cards/CardRenderer.d.ts +8 -1
  19. package/dist/cards/CardRenderer.js +179 -110
  20. package/dist/cards/CardRenderer.js.map +1 -1
  21. package/dist/cells/registry.d.ts +60 -0
  22. package/dist/cells/registry.js +47 -0
  23. package/dist/cells/registry.js.map +1 -0
  24. package/dist/chart/ChartRenderer.js +6 -4
  25. package/dist/chart/ChartRenderer.js.map +1 -1
  26. package/dist/chart/ChartWindowControl.js +2 -2
  27. package/dist/components/ui/checkbox.js +1 -1
  28. package/dist/components/ui/dialog.js +4 -3
  29. package/dist/components/ui/dialog.js.map +1 -1
  30. package/dist/components/ui/dropdown-menu.js +2 -1
  31. package/dist/components/ui/dropdown-menu.js.map +1 -1
  32. package/dist/components/ui/popover.js +2 -1
  33. package/dist/components/ui/popover.js.map +1 -1
  34. package/dist/components/ui/select.js +2 -1
  35. package/dist/components/ui/select.js.map +1 -1
  36. package/dist/components/ui/toast.js +3 -2
  37. package/dist/components/ui/toast.js.map +1 -1
  38. package/dist/components/ui/tooltip.js +2 -1
  39. package/dist/components/ui/tooltip.js.map +1 -1
  40. package/dist/data-view/BulkBar.d.ts +36 -0
  41. package/dist/data-view/BulkBar.js +239 -0
  42. package/dist/data-view/BulkBar.js.map +1 -0
  43. package/dist/data-view/FilePreview.js +1 -1
  44. package/dist/data-view/FilterBuilder.js +2 -2
  45. package/dist/data-view/FilterChips.js +2 -2
  46. package/dist/data-view/Freshness.js +1 -1
  47. package/dist/data-view/LiveIndicator.d.ts +10 -0
  48. package/dist/data-view/LiveIndicator.js +33 -0
  49. package/dist/data-view/LiveIndicator.js.map +1 -0
  50. package/dist/data-view/SearchBox.js +1 -1
  51. package/dist/data-view/UdcDataView.d.ts +110 -1
  52. package/dist/data-view/UdcDataView.js +237 -90
  53. package/dist/data-view/UdcDataView.js.map +1 -1
  54. package/dist/data-view/useDataViewState.d.ts +8 -0
  55. package/dist/data-view/useDataViewState.js +2 -1
  56. package/dist/data-view/useDataViewState.js.map +1 -1
  57. package/dist/headless.d.ts +9 -0
  58. package/dist/headless.js +12 -2
  59. package/dist/i18n/translations.js +136 -0
  60. package/dist/i18n/translations.js.map +1 -1
  61. package/dist/index.d.ts +15 -4
  62. package/dist/index.js +17 -4
  63. package/dist/kanban/KanbanCard.js +1 -1
  64. package/dist/kanban/KanbanColumn.js +1 -1
  65. package/dist/kanban/KanbanRenderer.js +6 -5
  66. package/dist/kanban/KanbanRenderer.js.map +1 -1
  67. package/dist/lib/scope.d.ts +8 -0
  68. package/dist/lib/scope.js +12 -0
  69. package/dist/lib/scope.js.map +1 -0
  70. package/dist/lookup/LookupCombobox.js +1 -1
  71. package/dist/lookup/batch.js +1 -1
  72. package/dist/lookup/options.js +4 -1
  73. package/dist/lookup/options.js.map +1 -1
  74. package/dist/lookup/useUdcLookup.js +9 -3
  75. package/dist/lookup/useUdcLookup.js.map +1 -1
  76. package/dist/map/MapRenderer.js +4 -3
  77. package/dist/map/MapRenderer.js.map +1 -1
  78. package/dist/renderers/types.d.ts +44 -1
  79. package/dist/renderers/types.js.map +1 -1
  80. package/dist/rows/useRowActivation.d.ts +91 -0
  81. package/dist/rows/useRowActivation.js +257 -0
  82. package/dist/rows/useRowActivation.js.map +1 -0
  83. package/dist/rows/useRowSelection.d.ts +92 -0
  84. package/dist/rows/useRowSelection.js +156 -0
  85. package/dist/rows/useRowSelection.js.map +1 -0
  86. package/dist/schema-editor/DeleteFieldDialog.js +2 -2
  87. package/dist/schema-editor/FieldFormDialog.js +2 -2
  88. package/dist/schema-editor/TagInput.js +1 -1
  89. package/dist/styles.css +1 -1
  90. package/dist/styles.scoped.css +2 -0
  91. package/dist/table/CellEditor.js +2 -1
  92. package/dist/table/CellEditor.js.map +1 -1
  93. package/dist/table/SelectCheckbox.d.ts +15 -0
  94. package/dist/table/SelectCheckbox.js +37 -0
  95. package/dist/table/SelectCheckbox.js.map +1 -0
  96. package/dist/table/TableRenderer.d.ts +15 -1
  97. package/dist/table/TableRenderer.js +305 -114
  98. package/dist/table/TableRenderer.js.map +1 -1
  99. package/dist/table/cells.d.ts +13 -2
  100. package/dist/table/cells.js +15 -2
  101. package/dist/table/cells.js.map +1 -1
  102. package/dist/table/index.d.ts +1 -0
  103. package/dist/table/states.d.ts +6 -0
  104. package/dist/table/states.js +14 -1
  105. package/dist/table/states.js.map +1 -1
  106. package/dist/table/useRowWindow.d.ts +82 -0
  107. package/dist/table/useRowWindow.js +182 -0
  108. package/dist/table/useRowWindow.js.map +1 -0
  109. package/dist/table.js.map +1 -1
  110. package/dist/tree/TreeNode.js +1 -1
  111. package/dist/tree/TreeRenderer.d.ts +2 -0
  112. package/dist/tree/TreeRenderer.js +16 -10
  113. package/dist/tree/TreeRenderer.js.map +1 -1
  114. package/dist/udc/changeFeed.d.ts +94 -0
  115. package/dist/udc/changeFeed.js +250 -0
  116. package/dist/udc/changeFeed.js.map +1 -0
  117. package/dist/udc/changes.d.ts +34 -0
  118. package/dist/udc/changes.js +79 -0
  119. package/dist/udc/changes.js.map +1 -0
  120. package/dist/udc/client.d.ts +15 -1
  121. package/dist/udc/client.js +34 -10
  122. package/dist/udc/client.js.map +1 -1
  123. package/dist/udc/hooks.d.ts +94 -16
  124. package/dist/udc/hooks.js +113 -10
  125. package/dist/udc/hooks.js.map +1 -1
  126. package/dist/udc/keys.d.ts +2 -0
  127. package/dist/udc/keys.js.map +1 -1
  128. package/dist/udc/listCache.d.ts +11 -0
  129. package/dist/udc/listCache.js +38 -0
  130. package/dist/udc/listCache.js.map +1 -0
  131. package/dist/udc/provider.d.ts +21 -3
  132. package/dist/udc/provider.js +23 -2
  133. package/dist/udc/provider.js.map +1 -1
  134. package/dist/udc/unauthenticated.d.ts +4 -0
  135. package/dist/udc/unauthenticated.js +17 -0
  136. package/dist/udc/unauthenticated.js.map +1 -0
  137. package/dist/ui-kit/types.d.ts +14 -0
  138. package/dist/ui-kit/ui.d.ts +1 -0
  139. package/dist/ui.js +2 -1
  140. package/dist/url-state/adapters.d.ts +23 -0
  141. package/dist/url-state/adapters.js +57 -0
  142. package/dist/url-state/adapters.js.map +1 -0
  143. package/dist/url-state/index.d.ts +1 -0
  144. package/package.json +6 -4
package/README.md CHANGED
@@ -14,7 +14,8 @@ What is in the package:
14
14
  - **`UdcProvider`** and **`createUdcQueryClient`**, and TanStack Query hooks over
15
15
  the transport client of [`@jsudc/core`](https://github.com/digital-cube/jsudc-core)
16
16
  (`useUdcCollections`, `useUdcDescribe`, `useUdcCollection`, `useUdcAllRows`,
17
- `useUdcMutate`, `useUdcSchema`, `useUdcSource`);
17
+ `useUdcMutate`, `useUdcMutateMany`, `useUdcAction`, `useUdcSchema`,
18
+ `useUdcSource`);
18
19
  - **`UdcDataView`** and **`createRendererRegistry`**; each renderer is a
19
20
  subpath of its own (`@jsudc/react/table`, `/cards`, `/kanban`, `/calendar`,
20
21
  `/tree`, `/map`, `/chart`), so a page bundles, and a host installs the peers
@@ -40,7 +41,7 @@ npm install @jsudc/react @jsudc/core \
40
41
  # then the peers of the renderers you register (see Renderers), all of them:
41
42
  npm install @tanstack/react-table leaflet recharts @dnd-kit/core @dnd-kit/sortable @dnd-kit/utilities
42
43
  # or straight from a GitHub tag:
43
- npm install github:digital-cube/jsudc-core#v0.3.0 github:digital-cube/jsudc-react#v0.3.1
44
+ npm install github:digital-cube/jsudc-core#v0.5.0 github:digital-cube/jsudc-react#v0.5.0
44
45
  ```
45
46
 
46
47
  ## Quick start
@@ -85,17 +86,17 @@ collections, so each one starts from a fresh view.
85
86
 
86
87
  ### The providers a host wraps
87
88
 
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 |
89
+ | Provider | Needed | Why |
90
+ | ----------------------------------------------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
91
+ | `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) |
92
+ | `QueryClientProvider client={createUdcQueryClient()}` | yes | the hooks are TanStack Query; `createUdcQueryClient` retries transport failures only, never a protocol error; `onUnauthenticated` see [Sessions](#sessions) |
93
+ | `UdcI18nProvider` | yes | every string goes through `useI18n()` |
94
+ | `TooltipProvider` | yes | Radix tooltips on headers, chips and buttons; with your own kit, `kit.TooltipProvider` (see [Bring your own primitives](#bring-your-own-primitives)) |
95
+ | `Toaster` | yes | save, conflict and schema-edit toasts (`useToast`); with your own kit, `kit.Toaster` |
96
+ | `UdcUrlStateProvider` / `UdcReactRouterUrlState` | no | where search, filters, sort, paging and the tab live; without it `window.location` (see [URL state](#url-state)) |
97
+ | `UdcLinksProvider` / `collectionPath` | no | where lookup links and `row_link`s go; without it `/c/<collection>` (see [Lookups and drill-down](#lookups-and-drill-down)) |
98
+ | `TimezoneProvider` | no | without it instants are shown in the browser's zone; with it the user's pick, kept in `localStorage` (`udc-tz`) |
99
+ | `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
100
 
100
101
  ## Renderers
101
102
 
@@ -143,6 +144,94 @@ peer is optional, builds and the import throws
143
144
  when the module loads. The root, `/table`, `/cards`, `/calendar` and
144
145
  `/headless` load without it.
145
146
 
147
+ ### Writing a renderer: the `RendererProps` contract
148
+
149
+ A host draws rows its own way (a message list, a timeline) by registering a
150
+ renderer of its own; `UdcDataView` hands its `component` the props below. They
151
+ are a **public contract**: from 0.4.0 none of them is renamed, removed or
152
+ retyped outside a major release, and a prop added later is optional, so a
153
+ renderer written today keeps compiling (the package's `npm run check:types`
154
+ compiles a host-written renderer against the published declarations and fails
155
+ when this table drifts).
156
+
157
+ | Prop | Type | What it is |
158
+ | ------------------------------------ | ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------- |
159
+ | `collection` | `string` | the collection's name |
160
+ | `describe` | `DescribeResponse` | its schema, view and capabilities, soft-deleted fields already gone |
161
+ | `data` | `UdcCollectionResult` | the view's paged list (`rows`, `total`, `isLoading`, `error`, `hasNextPage`, `fetchNextPage`, …); loaded only when `paging: true` |
162
+ | `filter` | `FilterNode \| undefined` | everything that filters the rows, composed: the host's `filter`, search, chips, the filter tree, the chart window |
163
+ | `baseFilter` | `FilterNode \| undefined` | `filter` without the search, for a renderer that searches what it loaded |
164
+ | `unwindowedFilter` | `FilterNode \| undefined` (optional) | `filter` without the chart window: what "of M" counts |
165
+ | `chartWindow` | `ChartWindowState \| undefined` (optional) | the chart window when one applies (already in `filter`) |
166
+ | `search` | `string` | the search box as typed (for highlighting) |
167
+ | `listSearch` | `string \| undefined` (optional) | the text to send as `search` with every list, when the source answers search itself ([Search](#search-answered-by-the-source)) |
168
+ | `sort`, `onSort(field, multi)` | `SortKey[]`, function | the sort and the header click that cycles it |
169
+ | `mode`, `page`, `limit`, `onPage(n)` | `"pages" \| "infinite"`, numbers, function | the paging mode, the 1-based page, the page size, go to a page |
170
+ | `filtered`, `onClearFilters()` | `boolean`, function | did the user filter (the host's `filter` does not count), and "clear filters" for the empty state |
171
+ | `resetKey` | `string` | changes whenever the rows mean something else: scroll back to the top on it |
172
+ | `onCount(count \| null)` | function | a renderer with `paging: false` reports what the toolbar's "Showing N of M" says (`RendererCount`) |
173
+ | `onSchemaAction` | function (optional) | set when the schema may be edited and the renderer has `editMode` |
174
+ | `folder` | `FolderNav \| undefined` (optional) | set when the view has `folder_options` |
175
+ | `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 |
176
+ | `activeRowId` | `string \| null` (optional) | the row to draw as active; set whenever activation is on (the view keeps it when the host does not) |
177
+ | `onActiveRowChange(row \| null)` | function (optional) | report the active row moving (keys, a click on another row); set whenever activation is on |
178
+ | `selection` | `RowSelection` (optional) | the row selection ([Selection and bulk actions](#selection-and-bulk-actions)); set while the view selects and the renderer pages |
179
+ | `rowActions` | `RowActions` (optional) | the actions of each row ([Row actions](#row-actions)); set when the view declares `row_action_defs` or `row_actions` |
180
+ | `virtualize` | `TableVirtualizeProp` (optional) | the table's long-list windowing ([Long lists](#long-lists)); passed only when the host set `UdcDataView virtualize` |
181
+
182
+ The three activation props are absent unless the host turned activation on;
183
+ `useRowActivation` of `@jsudc/react/headless` does everything they describe
184
+ (see [Row activation and keyboard](#row-activation-and-keyboard)). How one
185
+ column's cells are drawn is not a renderer's business: see
186
+ [Custom cells](#custom-cells).
187
+
188
+ A renderer with `paging: true` draws `data` and needs nothing else; one with
189
+ `paging: false` loads its own rows with `filter` and `listSearch` (the hooks
190
+ of `@jsudc/react/headless`, e.g. `useUdcAllRows({ filter, search: listSearch })`)
191
+ and reports `onCount`. A message
192
+ list of a mail client:
193
+
194
+ ```tsx
195
+ import { createRendererRegistry, type RendererDefinition, type RendererProps } from "@jsudc/react";
196
+ import { tableRenderer } from "@jsudc/react/table";
197
+ import { Inbox } from "lucide-react";
198
+
199
+ function MessageList({ data, filtered, onClearFilters, mode, page, limit, onPage }: RendererProps) {
200
+ if (data.isLoading) return <p>Loading…</p>;
201
+ if (data.rows.length === 0) {
202
+ return filtered ? <button onClick={onClearFilters}>Clear filters</button> : <p>No messages</p>;
203
+ }
204
+ return (
205
+ <div>
206
+ <ul>
207
+ {data.rows.map((row) => (
208
+ <li key={row.__meta.id}>
209
+ <b>{String(row.subject)}</b> · {String(row.from)}
210
+ </li>
211
+ ))}
212
+ </ul>
213
+ {mode === "infinite" && data.hasNextPage ? (
214
+ <button onClick={data.fetchNextPage}>More</button>
215
+ ) : null}
216
+ {mode === "pages" && data.total !== null && page * limit < data.total ? (
217
+ <button onClick={() => onPage(page + 1)}>Next</button>
218
+ ) : null}
219
+ </div>
220
+ );
221
+ }
222
+
223
+ export const messageList: RendererDefinition = {
224
+ name: "messages", // the name a view lists in available_renderers
225
+ component: MessageList,
226
+ icon: Inbox,
227
+ labelKey: "TAB_MESSAGES", // APP.TAB_MESSAGES, through `messages` of UdcI18nProvider
228
+ paging: true, // reads `data`: the list loads, the paging toggle shows
229
+ editMode: false,
230
+ };
231
+
232
+ const renderers = createRendererRegistry(tableRenderer, messageList);
233
+ ```
234
+
146
235
  ## Headless
147
236
 
148
237
  `@jsudc/react/headless` is the data layer under the renderers, with no JSX, no
@@ -151,7 +240,8 @@ plain HTML builds its own renderer on it and gets the same queries, filters and
151
240
  URL state.
152
241
 
153
242
  - the client context and the hooks: `useUdcClient`, `useUdcDescribe`,
154
- `useUdcCollection`, `useUdcAllRows`, `useUdcMutate`, `useUdcSchema`, `udcKeys`;
243
+ `useUdcCollection`, `useUdcAllRows`, `useUdcMutate`, `useUdcSchema`, `udcKeys`,
244
+ and the change feed's `useUdcChanges` (see [Live updates](#live-updates));
155
245
  - the data view's state: `useDataViewState` (tab, search, chips, filter tree,
156
246
  sort, paging in the URL), `composeFilter`, the URL codecs of `urlState.ts`,
157
247
  `liveDescribe` / `liveSort`, the folder helpers;
@@ -161,8 +251,16 @@ URL state.
161
251
  `TreeDropPlan`: the tree's names, prefixed), `useTreeExpand`;
162
252
  - `applyTransforms`, `displayText`, `renderKind` and the cell formatters;
163
253
  the zone helpers and `useTimezone`;
254
+ - `useRowActivation` (the active row and the keys, see
255
+ [Row activation and keyboard](#row-activation-and-keyboard)), `useRowSelection`
256
+ and what runs a bulk action (`planBulkAction`, `bulkActionEligible`, see
257
+ [Selection and bulk actions](#selection-and-bulk-actions)) and the cell
258
+ registry (`createCellRegistry`, `UdcCellsProvider`, `useCellRegistry`, see
259
+ [Custom cells](#custom-cells));
164
260
  - the registry functions (`createRendererRegistry`, `resolveTab`) and the URL
165
- state adapter, so its hooks behave exactly as inside `UdcDataView`.
261
+ state adapters (`windowLocationAdapter`, `prefixUrlStateAdapter`,
262
+ `createMemoryUrlStateAdapter`), so its hooks behave exactly as inside
263
+ `UdcDataView`.
166
264
 
167
265
  ## URL state
168
266
 
@@ -273,6 +371,892 @@ export function NextUrlState({ children }: { children: React.ReactNode }) {
273
371
  `[params, setParams]` pair the view uses, over whichever adapter is in effect;
274
372
  a function passed to `setParams` receives the query string as it is now.
275
373
 
374
+ Two views on one page, or a view inside a host route with parameters of its
375
+ own: give each a prefix (`urlPrefix`) or keep its state in memory
376
+ (`urlState="memory"`), see [Embedding a view](#embedding-a-view).
377
+
378
+ ## Embedding a view
379
+
380
+ `UdcDataView` can be one pane of a host's screen rather than a page: the
381
+ message list of a mail client between its folder list and its reading pane.
382
+ Every prop below is optional; without them the view is what it always was.
383
+
384
+ | Prop | What it does |
385
+ | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
386
+ | `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" |
387
+ | `chrome` | which parts of the frame are drawn: `"full"` (default), `"embedded"`, or flags |
388
+ | `pagingMode` | the paging mode to open in, instead of the view's `pagination` |
389
+ | `toolbarStart`, `toolbarEnd` | the host's own controls at the start (before the search) and at the end (after the count) of the toolbar |
390
+ | `urlPrefix` | a prefix for every parameter the view and its renderers read and write |
391
+ | `urlState` | `"url"` (default: the adapter in effect), `"memory"`, or any `UrlStateAdapter` |
392
+
393
+ **The host's filter** is what the host decides and the user does not: the
394
+ folder, the account, the project. The user still searches, picks chips and
395
+ builds filters on top of it; "Clear" and "Clear filters" remove theirs and
396
+ leave the host's; an empty folder shows "no rows", not "no rows match, clear
397
+ filters". It reaches every renderer through `filter` / `baseFilter` (see
398
+ [the contract](#writing-a-renderer-the-rendererprops-contract)), so the
399
+ kanban, the calendar, the tree, the map and the chart load the folder's rows
400
+ too. Change it and the view asks again; an equal object passed anew each
401
+ render asks nothing.
402
+
403
+ **Chrome.** `chrome` is a preset or flags, `true` drawing the part; a flag
404
+ left out takes the preset's value (`full`: all on, `embedded`: all off):
405
+
406
+ | Flag | The part |
407
+ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
408
+ | `header` | the title and the description |
409
+ | `tabs` | the renderer tabs (with Doc or Source still on, the renderer in use stays as the way back) |
410
+ | `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=` |
411
+ | `docTab` | the Doc pseudo-tab (the collection's README) |
412
+ | `sourceTab` | the Source pseudo-tab (the source file) |
413
+ | `frame` | the card around toolbar and rows: border, rounding, shadow and the outer margins |
414
+
415
+ `chrome="embedded"` leaves the toolbar and the rows only;
416
+ `chrome={{ preset: "embedded", tabs: true }}` adds the tabs back. The parts
417
+ keep their [stable classes](#stable-classes); `data-testid="data-view-frame"`
418
+ carries `data-framed`.
419
+
420
+ **URL state per view.** By default the view's parameters are the page's own
421
+ (`?q=`, `?sort=`, …), which is right for a view that is the page. A pane
422
+ shares the query string with its host and maybe with other views, so:
423
+
424
+ - `urlPrefix="inbox."` makes the view and its renderers use `inbox.q`,
425
+ `inbox.sort`, `inbox.p`, `inbox.board`, `inbox.win`, … and leave every
426
+ other parameter alone: a host route with a `?q=` of its own is neither read
427
+ nor removed, and two views with different prefixes keep separate search,
428
+ sort and page on one page. End the prefix with a separator: every key that
429
+ starts with it is the view's.
430
+ - `urlState="memory"` keeps the view's state in memory, its own store: the
431
+ address bar is never touched, and a reload starts afresh.
432
+ - `urlState={adapter}` uses any `UrlStateAdapter` (a host store, a router
433
+ adapter); `urlPrefix` applies on top of it.
434
+
435
+ Both are adapters, exported from the root and from `@jsudc/react/headless`
436
+ for a host's own components and headless renderers:
437
+ `prefixUrlStateAdapter(inner, prefix)` wraps any `UrlStateAdapter` (it reads
438
+ and writes only its own keys; `subscribe` is the inner one's), and
439
+ `createMemoryUrlStateAdapter(initial?)` is a store of its own (its `history`
440
+ lists what was written). Because the prefix applies at the adapter, every
441
+ parameter is covered, the kanban's, the chart's and the calendar's included:
442
+
443
+ ```tsx
444
+ import { prefixUrlStateAdapter, UdcUrlStateProvider, useUrlStateAdapter } from "@jsudc/react";
445
+ import { type ReactNode, useMemo } from "react";
446
+
447
+ /** The host's own controls of the pane share the view's `inbox.` parameters. */
448
+ function InboxPane({ children }: { children: ReactNode }) {
449
+ const inEffect = useUrlStateAdapter();
450
+ const adapter = useMemo(() => prefixUrlStateAdapter(inEffect, "inbox."), [inEffect]);
451
+ // Inside: useUrlSearchParams() sees `q` where the address bar has `inbox.q`.
452
+ return <UdcUrlStateProvider adapter={adapter}>{children}</UdcUrlStateProvider>;
453
+ }
454
+ ```
455
+
456
+ **A three-pane screen.** The folder list and the reading pane are the
457
+ host's; the message list is a data view with the folder as its filter, no
458
+ frame, the host's buttons in the toolbar and its state under `list.`:
459
+
460
+ ```tsx
461
+ import type { FilterNode } from "@jsudc/core";
462
+ import { UdcDataView } from "@jsudc/react";
463
+ import { useState } from "react";
464
+ import "@jsudc/react/styles.scoped.css";
465
+
466
+ const FOLDERS = ["inbox", "sent", "archive"] as const;
467
+
468
+ export function Mail() {
469
+ const [folder, setFolder] = useState<(typeof FOLDERS)[number]>("inbox");
470
+ const inFolder: FilterNode = { field: "folder", op: "eq", value: folder };
471
+
472
+ return (
473
+ <div style={{ display: "grid", gridTemplateColumns: "200px 1fr 1fr", height: "100vh" }}>
474
+ <nav>
475
+ {FOLDERS.map((f) => (
476
+ <button key={f} aria-current={f === folder} onClick={() => setFolder(f)}>
477
+ {f}
478
+ </button>
479
+ ))}
480
+ </nav>
481
+
482
+ <UdcDataView
483
+ collection="messages"
484
+ renderers={renderers} // createRendererRegistry(tableRenderer, messageList), see Renderers
485
+ filter={inFolder}
486
+ chrome={{ preset: "embedded", tabs: true }}
487
+ pagingMode="infinite"
488
+ urlPrefix="list."
489
+ toolbarStart={<button onClick={() => compose()}>Compose</button>}
490
+ toolbarEnd={<button onClick={() => syncMailbox()}>Sync</button>}
491
+ />
492
+
493
+ <article>{/* the host's reading pane */}</article>
494
+ </div>
495
+ );
496
+ }
497
+ ```
498
+
499
+ The address bar then reads `/mail?list.q=invoice&list.sort=date:desc`, and a
500
+ parameter the host keeps for itself (`?folder=`, `?q=`) stays untouched.
501
+ Opening a row in the reading pane is
502
+ [row activation](#row-activation-and-keyboard).
503
+
504
+ ## Row activation and keyboard
505
+
506
+ A row can do something of the host's: open the message in the reading pane.
507
+ `UdcDataView` takes three props, all optional; passing any of them turns
508
+ activation on, and without them the rows are what they were (no tab stop, no
509
+ keys, no active row, a `row_link` still followed on click):
510
+
511
+ | Prop | What it does |
512
+ | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
513
+ | `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) |
514
+ | `activeRowId` | the row drawn as active. Passed: controlled (`null` for none), the host moves it in `onActiveRowChange`. Left out: the view keeps it itself |
515
+ | `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 |
516
+
517
+ **Keys**, in the table and the cards, while the focus is on a row:
518
+ ArrowDown / `j` and ArrowUp / `k` move the active row (and the focus) by one,
519
+ Home / End jump to the first / last loaded row, Enter activates. They are
520
+ left alone while an input, the search box, a cell editor, a menu, a list box
521
+ or a dialog has the focus, and with Ctrl, Cmd, Alt or Shift held. Space is
522
+ not bound unless the view selects; then it toggles the active row (0.5.0). Double-click and Enter still
523
+ edit an editable cell when the focus is on the cell itself.
524
+
525
+ **One tab stop.** The rows are a roving-`tabindex` list: Tab reaches the
526
+ active row (else the one last focused, else the first) and leaves the list on
527
+ the next Tab. The table is `role="grid"`; the card grid too, each card a
528
+ `row`. The active row has `aria-selected="true"` (while the view selects,
529
+ `aria-selected` is the selection and the active row has `aria-current`: see
530
+ [Selection and bulk actions](#selection-and-bulk-actions)), the attribute
531
+ `data-active="true"` (`.udc-row[data-active]`, `.udc-card[data-active]` for
532
+ your CSS) and the `--selected` background.
533
+
534
+ **Kept by id.** The active row and the focus follow the row's id across a
535
+ refetch, a sort and pages loading in infinite mode; ArrowDown on the last
536
+ loaded row in infinite mode loads the next page and moves onto its first
537
+ row; the active row is scrolled into view, also when the host sets
538
+ `activeRowId`. A row that left the list (deleted, filtered out) stops being
539
+ active without an error; when it comes back it is active again.
540
+
541
+ **`row_link`.** Without `onRowActivate` a click follows the view's
542
+ `row_link` as before. With it a plain click activates the row, and Cmd /
543
+ Ctrl-click and the middle button still open the link (in a new tab).
544
+
545
+ A list and a reading pane side by side, the pane following the keyboard: the
546
+ arrows preview, Enter or a click opens (marks the message read):
547
+
548
+ ```tsx
549
+ import type { Row } from "@jsudc/core";
550
+ import { UdcDataView } from "@jsudc/react";
551
+ import { useState } from "react";
552
+
553
+ export function Mailbox() {
554
+ const [open, setOpen] = useState<Row | null>(null);
555
+
556
+ return (
557
+ <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", height: "100vh" }}>
558
+ <UdcDataView
559
+ collection="messages"
560
+ chrome="embedded"
561
+ pagingMode="infinite"
562
+ // Controlled: the open message is the active row, so the pane and the list agree.
563
+ activeRowId={open?.__meta.id ?? null}
564
+ onActiveRowChange={setOpen} // ArrowDown / j: the pane previews the next message
565
+ onRowActivate={(row) => {
566
+ setOpen(row);
567
+ void markRead(row.__meta.id); // Enter or a click: the host's own action
568
+ }}
569
+ />
570
+ <article aria-live="polite">
571
+ {open ? (
572
+ <>
573
+ <h2>{String(open.subject)}</h2>
574
+ <p>{String(open.from)}</p>
575
+ </>
576
+ ) : (
577
+ <p>No message selected</p>
578
+ )}
579
+ </article>
580
+ </div>
581
+ );
582
+ }
583
+ ```
584
+
585
+ Leave `activeRowId` out and the view keeps the active row itself (across
586
+ tab switches too); pass only `onRowActivate` when moving should not open
587
+ anything.
588
+
589
+ **In a host renderer.** `UdcDataView` hands a renderer the same three props
590
+ (see [the contract](#writing-a-renderer-the-rendererprops-contract)), and
591
+ `useRowActivation` of `@jsudc/react/headless` (also on the root) gives it the
592
+ table's behaviour: spread `rowProps(row)` on each row's element (ref,
593
+ `tabIndex`, `aria-selected`, `data-active`, the key and focus handlers) and
594
+ call `handleClick(e, row)` from its `onClick`:
595
+
596
+ ```tsx
597
+ import type { RendererProps } from "@jsudc/react";
598
+ import { useRowActivation } from "@jsudc/react/headless";
599
+
600
+ function MessageList({ data, onRowActivate, activeRowId, onActiveRowChange }: RendererProps) {
601
+ const nav = useRowActivation({
602
+ rows: data.rows,
603
+ onRowActivate,
604
+ activeRowId,
605
+ onActiveRowChange,
606
+ // Infinite mode: moving past the last row loads the next page.
607
+ hasNextPage: data.hasNextPage,
608
+ isFetchingNextPage: data.isFetchingNextPage,
609
+ fetchNextPage: data.fetchNextPage,
610
+ });
611
+ return (
612
+ <ul role={nav.enabled ? "grid" : undefined}>
613
+ {data.rows.map((row) => (
614
+ <li
615
+ key={row.__meta.id}
616
+ role={nav.enabled ? "row" : undefined}
617
+ {...nav.rowProps(row)}
618
+ onClick={(e) => nav.handleClick(e, row)}
619
+ >
620
+ {String(row.subject)}
621
+ </li>
622
+ ))}
623
+ </ul>
624
+ );
625
+ }
626
+ ```
627
+
628
+ `nav.activeRowId` is the active row (when it is loaded), `nav.move("next")`
629
+ and `nav.activate(row)` drive it from the host's own buttons, and `ownsKeys`
630
+ says whether a key belongs to the element it was pressed on.
631
+
632
+ ## Search answered by the source
633
+
634
+ The search box filters in the browser's terms by default: its text becomes
635
+ `contains` over the view's `search.fields`, or-ed, and is ANDed with the chips
636
+ and the filter tree. When a collection's `describe` says
637
+ `capabilities.search: "source"` (a `postgres_table` with a `tsvector`, a
638
+ collection backed by OpenSearch; see `@jsudc/server`'s "Search answered by the
639
+ source"), the data view sends the text as `search` in `list` instead and
640
+ composes nothing for it:
641
+
642
+ - **The paged list** carries `search` next to the filter (the host's filter,
643
+ the chips, the tree), and so does its query key, so every text is its own
644
+ cache entry. A blank box sends no `search`.
645
+ - **Renderers that load their own rows** get the text as `listSearch` (and a
646
+ `filter` / `baseFilter` without it). Kanban, calendar, map, chart and tree
647
+ pass it on; a tree that highlights what it loaded
648
+ (`on_search: highlight_and_expand`) keeps searching in the browser. A renderer of your
649
+ own passes it as `search` to `useUdcAllRows` or `useUdcCollection`.
650
+ - **Relevance order.** With a search and no sort chosen, the request has no
651
+ sort and the source answers by relevance, so no column shows a sort
652
+ indicator. Clicking a header still sorts, and the sort is sent with the
653
+ search.
654
+ - **The selection** is cleared by a new search text, as by a new filter.
655
+ "Select all that match" is not offered while a source search is active:
656
+ `mutate_many` by filter cannot carry the search, so it could not name the
657
+ same rows. The bar says so instead ("Only the loaded rows can be selected
658
+ while searching"); the loaded rows can still be selected and acted on.
659
+ - The rest of the box is unchanged: the debounce, `?q=` in the URL, and the
660
+ clear button.
661
+
662
+ Nothing changes for a host: the capability comes from the server, and a
663
+ collection without it sends exactly the requests it sent before.
664
+
665
+ ```tsx
666
+ import { useUdcAllRows, type RendererProps } from "@jsudc/react";
667
+
668
+ // A renderer of your own that loads its rows: pass the source's search on.
669
+ function Timeline({ collection, describe, filter, listSearch }: RendererProps) {
670
+ const { rows } = useUdcAllRows({
671
+ collection,
672
+ filter, // no `contains` for the box under the capability
673
+ search: listSearch, // undefined without it, or with an empty box
674
+ capabilities: describe.capabilities,
675
+ });
676
+ return (
677
+ <ol>
678
+ {rows.map((r) => (
679
+ <li key={r.__meta.id}>{String(r.subject)}</li>
680
+ ))}
681
+ </ol>
682
+ );
683
+ }
684
+ ```
685
+
686
+ ## Live updates
687
+
688
+ By default a view refreshes on a timer: the view's `refresh_interval_ms`
689
+ becomes the list's polling interval, and nothing at all without it. A server
690
+ with the change feed (`@jsudc/server`'s "Change feed": `createChangeFeed()`
691
+ passed as `changes` to `createDispatcher`) says `capabilities.changes: true`
692
+ on its collections and serves one Server-Sent Events stream for a list of
693
+ collections (`UdcClient.changes` in `@jsudc/core`). Turn it on in the
694
+ provider and the views refetch when the server says their rows changed:
695
+
696
+ ```tsx
697
+ import { UdcClient } from "@jsudc/core/client";
698
+ import { QueryClientProvider } from "@tanstack/react-query";
699
+ import { createUdcQueryClient, UdcDataView, UdcProvider, useUdcChanges } from "@jsudc/react";
700
+ import { RENDERERS } from "@jsudc/react/all";
701
+ import { useState } from "react";
702
+
703
+ const client = new UdcClient({ httpUrl: "" });
704
+ const queryClient = createUdcQueryClient({ onUnauthenticated: () => location.assign("/login") });
705
+
706
+ export function App() {
707
+ return (
708
+ <QueryClientProvider client={queryClient}>
709
+ {/* `changes`: one stream for the collections on screen. Off by default. */}
710
+ <UdcProvider client={client} renderers={RENDERERS} changes>
711
+ <InboxBadge />
712
+ {/* Mark a message read in another tab: this list refetches within a moment. */}
713
+ <UdcDataView collection="messages" />
714
+ </UdcProvider>
715
+ </QueryClientProvider>
716
+ );
717
+ }
718
+
719
+ // A host's own counter: every insert the feed reports, as it arrives.
720
+ function InboxBadge() {
721
+ const [unseen, setUnseen] = useState(0);
722
+ const { status } = useUdcChanges("messages", (event) => {
723
+ if (event.op === "insert") setUnseen((n) => n + (event.ids?.length ?? 1));
724
+ });
725
+ return (
726
+ <button type="button" onClick={() => setUnseen(0)} title={status}>
727
+ Inbox {unseen > 0 ? `(${unseen})` : null}
728
+ </button>
729
+ );
730
+ }
731
+ ```
732
+
733
+ What happens:
734
+
735
+ - **One stream per provider.** A collection joins the stream when the first
736
+ view or hook that shows it mounts (the data view, `useUdcCollection`,
737
+ `useUdcAllRows`, `useUdcLookup` / `useUdcLookups` and `useLookupOptions`
738
+ for the collection a lookup points to, `useUdcChanges`) and leaves it when
739
+ the last one unmounts. A new list opens a new stream; the old one is closed
740
+ only once the new one is subscribed, so the collections that stay miss
741
+ nothing. Mounts close together (`batchMs`, 50 ms) make one reopen.
742
+ - **On an event** (`{ collection, op, ids? }`, no row data) the collection's
743
+ lists, the lookup batches into it (the labels other views show) and its
744
+ picker options are invalidated, so what is on screen refetches. A burst is
745
+ debounced into one refetch (`debounceMs`, 200 ms), held back while a
746
+ mutation of yours is in flight. A `delete` that names its `ids` takes those
747
+ rows out of the cached lists at once (`removeDeleted: false` turns that
748
+ off); nothing else is applied without the server's answer: a row is never
749
+ synthesised from an event.
750
+ - **On "reconnected"** (the stream dropped and is back) everything the stream
751
+ carries is refetched: changes made meanwhile were not sent. A collection
752
+ that joins the stream is refetched when its data was fetched before the
753
+ stream was asked for.
754
+ - **Polling is the fallback.** While the stream carries a collection its
755
+ `refresh_interval_ms` timer is suspended; it runs again while the stream
756
+ reconnects, when the server refused it, and always without a feed. An
757
+ unauthenticated stream goes to `createUdcQueryClient`'s
758
+ `onUnauthenticated` (in the same burst as failed queries) and is not
759
+ reopened until the set of collections changes.
760
+ - **What stays put** across such a refetch: the active row and the focus, the
761
+ selection, an open cell editor (and what was typed in it), the scroll
762
+ position of an infinite list. The rows are replaced under them, by id.
763
+ - **The indicator.** Beside the freshness pill the data view shows "live"
764
+ while the stream carries its collection and "reconnecting" while it is
765
+ being reopened (`FEED_LIVE`, `FEED_RECONNECTING` and their `_HINT`
766
+ tooltips, `en` and `sr`); `liveIndicator={false}` hides it, and
767
+ `LiveIndicator` draws it in a toolbar of your own.
768
+
769
+ `changes` also takes `UdcChangeFeedOptions`: `debounceMs`, `batchMs`,
770
+ `removeDeleted`, and `minDelayMs`, `maxDelayMs`, `idleTimeoutMs` passed to
771
+ `UdcClient.changes`. A `UdcProvider` without `changes` inside one with the
772
+ same client uses the outer feed; `changes={false}` turns it off below.
773
+
774
+ `useUdcChanges(collection, onEvent?, { capabilities?, enabled? })` answers
775
+ `{ status, live }`: `off` (no feed, or the collection does not offer it),
776
+ `connecting`, `live`, `reconnecting`, or `down` (refused). It reads the
777
+ capability from the collection's cached `describe` unless you pass
778
+ `capabilities`.
779
+
780
+ **Without the feed** nothing changes: a provider without `changes` opens no
781
+ connection and asks no `describe` for it, a collection whose `describe` does
782
+ not say `capabilities.changes: true` is never subscribed, and every view
783
+ polls on `refresh_interval_ms` (or not at all) exactly as before.
784
+
785
+ ## Selection and bulk actions
786
+
787
+ A user selects rows (one, a range, the page, or everything that matches the
788
+ filter) and runs the view's `bulk_actions` on them. Selection is on when the
789
+ view says `multiselect: true` or declares `bulk_actions`; `selectable` on
790
+ `UdcDataView` forces it on (`true`) or off (`false`). A view with neither
791
+ draws exactly what it drew before 0.5.0.
792
+
793
+ **What the user does.** The table gets a checkbox column pinned at the start
794
+ and a header checkbox for the page (checked, empty or indeterminate);
795
+ shift-click selects the range from the last row toggled; with row activation
796
+ on, Space toggles the active row and Shift+Space selects a range to it. The
797
+ cards get a checkbox each. Kanban, tree, calendar, map and chart do not
798
+ select. While anything is selected a bar over the list shows the count, a
799
+ button per `bulk_actions` entry and a clear button.
800
+
801
+ **All that match.** When the whole page is selected and more rows match than
802
+ are loaded, the bar offers "Select all 1,234 that match". Taking it switches
803
+ the selection to "every row the filter matches, except the ones you uncheck"
804
+ (the bar reads "All 1,234 are selected"), and an action then goes to the
805
+ server by filter, not by ids. When everything is loaded already the page is
806
+ everything, and nothing is offered.
807
+
808
+ **The selection is cleared** when the filter changes (the search, a chip,
809
+ the filter builder, the host's `filter`) or the collection does (under a
810
+ source search, see [Search answered by the source](#search-answered-by-the-source),
811
+ "all that match" is not offered); a sort, a
812
+ refetch and more pages loading keep it. In id mode the selected rows are
813
+ remembered, so a row a refetch drops still counts and still reaches a
814
+ handler.
815
+
816
+ **Without a total.** A source answering `capabilities.total_count: false`
817
+ lists with `total: null`. The offer then reads "Select all that match", with
818
+ no number, the bar "All matching rows are selected", with no number, and the
819
+ result message reports the count the server answers (`updated`).
820
+
821
+ ### Running an action
822
+
823
+ Each `bulk_actions` entry is an `ActionDef` of `@jsudc/core`: `kind`,
824
+ `label`, `icon` (`lucide:<name>`), `variant`, `when`, and 0.5.0's `set`,
825
+ `action` and `confirm`. Its button reads the term `ACTION_<KIND>` of the
826
+ collection's section (`TBL_<COLLECTION>`), else `ACTIONS.<kind>`, else the
827
+ def's `label`. It is disabled unless its `when` holds for every selected row
828
+ (`isActionEligibleForAll`); in "all that match" mode rows that are not loaded
829
+ cannot be checked in the browser, so it is offered unless `when` is `false`
830
+ and the server decides.
831
+
832
+ A click runs the first of these that applies:
833
+
834
+ 1. **A handler for its `kind`**: the view's `actions` prop, else
835
+ `UdcProvider actions`. It gets `{ kind, def, collection, ids }` in id mode
836
+ or `{ kind, def, collection, filter, exceptIds }` in "all that match" mode,
837
+ with `rows` (the selected rows that are loaded) and `clearSelection`. The
838
+ view does not clear the selection after a handler; call `clearSelection`
839
+ when you are done. A handler that throws shows its message.
840
+ 2. **`delete`**: a confirmation, then `mutate_many` `delete`.
841
+ 3. **A def with `set`**: `mutate_many` `update` with that patch.
842
+ 4. **Anything else**: the server action the def's `action` names (default its
843
+ `kind`) with `{ collection, ids }` or `{ collection, filter, except_ids }`
844
+ — a host action registered on the dispatcher (`@jsudc/server`'s
845
+ `Dispatcher.register`). An `unsupported_op` answer shows "The server does
846
+ not support …", naming the action.
847
+
848
+ The built-in paths ask first when `actionConfirms(def)` says so: `delete` by
849
+ default, any other def with `confirm: true` or a question of its own. They
850
+ change the loaded rows at once (`useUdcMutateMany`), put them back if the
851
+ call fails, refetch the collection's lists and lookups when it settles, and
852
+ report what the server answers: "12 rows deleted", "Mark read: 12 rows", and
853
+ "3 rows could not be changed" for the ids in `failed`, which stay selected.
854
+
855
+ A mailbox whose view archives through the host's own endpoint, marks read
856
+ with a patch, and deletes with the built-in delete:
857
+
858
+ ```yaml
859
+ # The view of `messages`
860
+ view:
861
+ columns: [{ field: subject }, { field: from }, { field: received_at }]
862
+ bulk_actions:
863
+ - kind: archive
864
+ label: Archive
865
+ icon: lucide:archive
866
+ - kind: mark_read
867
+ label: Mark read
868
+ icon: lucide:mail-open
869
+ set: { read: true }
870
+ when: { field: read, op: eq, value: false }
871
+ - kind: delete
872
+ variant: destructive
873
+ ```
874
+
875
+ ```tsx
876
+ import { UdcDataView } from "@jsudc/react";
877
+
878
+ export function Inbox() {
879
+ return (
880
+ <UdcDataView
881
+ collection="messages"
882
+ filter={{ field: "folder", op: "eq", value: "inbox" }}
883
+ actions={{
884
+ // Id mode: `ids`. "All that match": `filter` (the host's folder, the search, the chips)
885
+ // and `exceptIds`. `rows` are the selected rows the view has loaded.
886
+ archive: async ({ ids, filter, exceptIds, clearSelection }) => {
887
+ await fetch("/api/mail/archive", {
888
+ method: "POST",
889
+ headers: { "content-type": "application/json" },
890
+ body: JSON.stringify(ids ? { ids } : { filter, except_ids: exceptIds }),
891
+ });
892
+ clearSelection();
893
+ },
894
+ // mark_read has `set`: a mutate_many update, no handler needed.
895
+ // delete is built in: a confirmation, then a mutate_many delete.
896
+ }}
897
+ />
898
+ );
899
+ }
900
+ ```
901
+
902
+ **Accessibility.** With selection on and row activation off the table stays a
903
+ table: each row's checkbox is a native checkbox labelled "Select row", the
904
+ header's "Select all rows shown" (`aria-checked="mixed"` when some are). With
905
+ both on the list is ARIA's multi-select grid (`aria-multiselectable="true"`):
906
+ `aria-selected` on a row says whether it is **selected**, and the active row
907
+ is the one holding the focus (the roving tab stop), marked
908
+ `aria-current="true"` and `data-active="true"`. With selection off,
909
+ `aria-selected` marks the active row as in 0.4.0. A selected row carries
910
+ `data-selected="true"` (`.udc-row[data-selected]`, `.udc-card[data-selected]`)
911
+ and the `--selected` background; the bar is `role="toolbar"` and its count is
912
+ announced politely.
913
+
914
+ **In a host renderer.** `RendererProps.selection` (a `RowSelection`, set
915
+ while the view selects) carries `mode`, `ids`, `exceptIds`, `count`
916
+ (`null` in "all that match" mode without a total), `rows`, `pageState`,
917
+ `isSelected(id)`, `toggle(id, { range })`, `setPage(on)`,
918
+ `selectAllMatching()`, `setIds(ids)` and `clear()`; the view draws the bar.
919
+ `useRowSelection({ rows, total, resetKey })` of `@jsudc/react/headless` is
920
+ the same model for a list of your own, and its pure operations
921
+ (`toggleSelection`, `selectRange`, `setPageSelection`, `selectAllMatching`,
922
+ `selectionCount`, …) range over the rows as loaded, not over the DOM.
923
+ `useRowActivation` takes `isSelected` and `onToggleSelect(row, range)` for
924
+ Space and the ARIA above.
925
+
926
+ ### `useUdcMutateMany` and `useUdcAction`
927
+
928
+ `useUdcMutateMany(collection)` is `useUdcMutate` for many rows: `mutateAsync({
929
+ op: "update", ids, row })`, `{ op: "delete", ids }`, or by `filter` with
930
+ `except_ids`. The rows it touches are patched (or removed, the total counted
931
+ down) in every cached list at once, put back on an error, and the lists and
932
+ lookups are invalidated when it settles. It resolves to the server's `{
933
+ updated, failed }`: report `failed` yourself.
934
+
935
+ `useUdcAction(action)` is a mutation over the client's typed `call` for any
936
+ host action. Given the action's definition (`defineHostAction`, in a module
937
+ the server and the browser share), the payload and the answer are typed from
938
+ its schemas and the answer is checked; given a name, you type it
939
+ (`useUdcAction<Res, Req>("mail.flag")`). `invalidates` names the collections
940
+ whose lists to refetch afterwards; every other TanStack mutation option
941
+ passes through.
942
+
943
+ ```ts
944
+ // shared/actions.ts — imported by the server (Dispatcher.register) and by the browser
945
+ import { defineHostAction } from "@jsudc/core";
946
+ import { z } from "zod";
947
+
948
+ export const snooze = defineHostAction({
949
+ name: "mail.snooze",
950
+ request: z.object({ ids: z.array(z.string()), until: z.iso.datetime() }),
951
+ response: z.object({ snoozed: z.number().int() }),
952
+ });
953
+ ```
954
+
955
+ ```tsx
956
+ import { useUdcAction } from "@jsudc/react";
957
+ import { snooze } from "../shared/actions";
958
+
959
+ export function SnoozeButton({ ids }: { ids: string[] }) {
960
+ const run = useUdcAction(snooze, { invalidates: ["messages"] });
961
+ return (
962
+ <button
963
+ type="button"
964
+ disabled={run.isPending}
965
+ // The payload is typed { ids: string[]; until: string }; data is { snoozed: number }.
966
+ onClick={() => run.mutate({ ids, until: new Date(Date.now() + 3_600_000).toISOString() })}
967
+ >
968
+ {run.data ? `Snoozed ${run.data.snoozed}` : "Snooze an hour"}
969
+ </button>
970
+ );
971
+ }
972
+ ```
973
+
974
+ ## Row actions
975
+
976
+ Each row offers the actions its view declares for one row, as icon buttons at
977
+ the end of the row or in a "more" menu, each only where its `when` holds for
978
+ that row. They run exactly as a bulk action does on a selection of that one
979
+ row: the same handlers, the same server paths. A view that declares none
980
+ draws exactly what it drew before 0.5.0.
981
+
982
+ **What a row offers.** The three keys are udc's, read as udc-js reads them:
983
+ `row_action_defs` (a list of `ActionDef`, the shape of `bulk_actions`) when
984
+ the view has any, else the kinds of the legacy `row_actions: string[]`
985
+ lifted to `{ kind }`. Each is filtered by its `when` for that row
986
+ (`isActionEligible` of `@jsudc/core`: against `row.__meta.state` when the
987
+ source sends one, else the row's fields). A row none of whose actions apply
988
+ shows nothing.
989
+
990
+ **How they are drawn**, by `row_actions_display`:
991
+
992
+ - `inline` (the default, as in udc-js): the table gets a trailing column
993
+ pinned at the end (after any column pinned right) with one icon button per
994
+ action, labelled for screen readers and in a tooltip; an action whose
995
+ `icon` is not known draws its label as a small text button. The column is
996
+ sized from every declared action, with the `when`-gated ones counted as
997
+ alternatives (only the widest), so it does not jump as rows change.
998
+ - `menu`: one "more" button per row opening a dropdown, and the same menu on
999
+ right-click anywhere on the row.
1000
+
1001
+ The cards draw the same actions as a "more" menu on each card (right-click
1002
+ opens it too), whatever the display. Kanban, tree, calendar, map and chart
1003
+ draw no row actions.
1004
+
1005
+ **The keyboard.** With row activation on, the focused row opens its menu from
1006
+ the context-menu key, Shift+F10 or `.` (`isRowMenuKey`); in the inline
1007
+ display the keys open the same actions as a menu. Arrow keys move in the
1008
+ menu, Enter runs, Escape closes, and the focus goes back to the row. Opened
1009
+ from the "more" button, the focus goes back to that button.
1010
+
1011
+ **A click on an action is the action's**: it neither activates the row
1012
+ (`onRowActivate`), nor follows its `row_link`, nor toggles its selection; a
1013
+ click anywhere else on the row does what it did.
1014
+
1015
+ **Running one** goes through [Running an action](#running-an-action) with
1016
+ `ids: [id]` and `rows: [row]`:
1017
+
1018
+ 1. **A handler for its `kind`** (the view's `actions`, else `UdcProvider
1019
+ actions`): it gets the bulk context with `ids: [id]`, `rows: [row]` and
1020
+ `row`, the one row (absent when the bulk bar runs it). `clearSelection`
1021
+ clears the view's selection, if it selects.
1022
+ 2. **`delete`**: a confirmation ("Delete this row?"), then `mutate_many`
1023
+ `delete` when the source has `capabilities.mutate_many`, else `mutate`
1024
+ `delete`. The row leaves the list and the selection.
1025
+ 3. **A def with `set`**: an update with that patch (`mutate_many` or
1026
+ `mutate`), shown at once and put back if the call fails.
1027
+ 4. **Anything else**: the server action the def's `action` names (default its
1028
+ `kind`) with `{ collection, ids: [id] }`.
1029
+
1030
+ As for a bulk action, the built-in paths ask first per `confirm`, a handler
1031
+ asks its own questions, and an error (or the row named in a `failed` answer)
1032
+ is shown as a toast. A row action names its button with the term
1033
+ `ACTION_<KIND>` of the collection's section, else `ACTIONS.<kind>`, else the
1034
+ def's `label`, else the kind made readable.
1035
+
1036
+ A mailbox whose rows mark themselves read through a patch and archive through
1037
+ the host's own endpoint, each hidden where it does not apply:
1038
+
1039
+ ```yaml
1040
+ # The view of `messages`
1041
+ view:
1042
+ columns: [{ field: subject }, { field: from }, { field: received_at }]
1043
+ row_actions_display: inline # or `menu`
1044
+ row_action_defs:
1045
+ - kind: mark_read
1046
+ label: Mark read
1047
+ icon: lucide:mail-open
1048
+ set: { read: true } # no handler needed: an optimistic update
1049
+ when: { field: read, op: eq, value: false }
1050
+ - kind: archive
1051
+ label: Archive
1052
+ icon: lucide:archive
1053
+ when: { field: folder, op: neq, value: archive }
1054
+ ```
1055
+
1056
+ ```tsx
1057
+ import { UdcDataView } from "@jsudc/react";
1058
+
1059
+ export function Inbox() {
1060
+ return (
1061
+ <UdcDataView
1062
+ collection="messages"
1063
+ filter={{ field: "folder", op: "eq", value: "inbox" }}
1064
+ onRowActivate={(row) => openMessage(row.__meta.id)}
1065
+ actions={{
1066
+ // The same handler serves the bulk bar (`ids` of the selection, or `filter`) and the row
1067
+ // ("archive" on one row: `ids: [id]`, `rows: [row]`, `row`).
1068
+ archive: async ({ ids, filter, exceptIds, row, clearSelection }) => {
1069
+ await fetch("/api/mail/archive", {
1070
+ method: "POST",
1071
+ headers: { "content-type": "application/json" },
1072
+ body: JSON.stringify(ids ? { ids } : { filter, except_ids: exceptIds }),
1073
+ });
1074
+ if (!row) clearSelection();
1075
+ },
1076
+ }}
1077
+ />
1078
+ );
1079
+ }
1080
+ ```
1081
+
1082
+ An unread message in the inbox shows both; a read one only "Archive"; a read
1083
+ one already archived, none. Clicking "Mark read" shows the row read at once (and so
1084
+ "Mark read" goes from it); clicking the row itself still opens the message.
1085
+
1086
+ **In a host renderer.** `RendererProps.rowActions` (a `RowActions`, set when
1087
+ the view declares row actions) carries `display`, `defs` (every declared
1088
+ action, before `when`), `eligible(row)`, `label(def)`, `run(def, row)` (the
1089
+ path above; it shows its errors and does not reject) and `runningOn(id)`
1090
+ (the kind running on that row, else `null`). `RowActionsControls` with
1091
+ `useRowMenu()` draws the built-in buttons and menu; `rowMenuHandlers` gives a
1092
+ row element its menu key and right-click. The headless parts —
1093
+ `rowActionDefs(view)`, `rowActionsDisplay(view)`, `eligibleRowActions(defs,
1094
+ row)`, `isRowMenuKey(e)` — are in `@jsudc/react/headless`. A UI kit's
1095
+ `DropdownMenu` may take the optional `open` / `onOpenChange` and its content
1096
+ `onCloseAutoFocus` (the default kit does); a kit that ignores them still
1097
+ opens the menu from its trigger, but not from the keys or a right-click.
1098
+
1099
+ ## Long lists
1100
+
1101
+ In infinite mode the table mounts only the rows in and near its viewport,
1102
+ however many pages are loaded: a mailbox scrolled through for thousands of
1103
+ messages keeps a few dozen `<tr>` in the page, not thousands. The rows
1104
+ outside the window are stood in for by spacer rows of their height, so the
1105
+ scrollbar, the scroll position and the sticky header behave as if every row
1106
+ were there. Rows have one height (the view's `row_height`, default 40 px),
1107
+ so the window is arithmetic: no dependency, no measuring of each row.
1108
+
1109
+ **When it applies.** Only in infinite mode (pages mode is never windowed)
1110
+ and, by default, only once **more than 200 rows** are loaded: a list at or
1111
+ under that draws exactly the markup it drew before 0.5.0. The `virtualize`
1112
+ prop of `UdcDataView` (and of `TableRenderer`) changes that:
1113
+
1114
+ | `virtualize` | Infinite mode windows its rows… |
1115
+ | ---------------------------------- | -------------------------------------------------- |
1116
+ | left out, or `{ enabled: "auto" }` | once more than `threshold` (200) rows are loaded |
1117
+ | `true` / `{ enabled: true }` | always, however few |
1118
+ | `false` / `{ enabled: false }` | never: every loaded row is mounted, as before |
1119
+ | `{ threshold: 500 }` | once more than 500 are loaded |
1120
+ | `{ overscan: 20 }` | with 20 rows mounted beyond each edge (default 10) |
1121
+
1122
+ ```tsx
1123
+ import { UdcDataView } from "@jsudc/react";
1124
+
1125
+ // The mailbox: always infinite, always windowed (even a short folder), with a deeper overscan
1126
+ // for fast keyboard scrolling.
1127
+ export function Mailbox({ folder }: { folder: string }) {
1128
+ return (
1129
+ <UdcDataView
1130
+ collection="messages"
1131
+ filter={{ field: "folder", op: "eq", value: folder }}
1132
+ pagingMode="infinite"
1133
+ virtualize={{ enabled: true, overscan: 20 }}
1134
+ onRowActivate={(row) => openMessage(row.__meta.id)}
1135
+ />
1136
+ );
1137
+ }
1138
+ ```
1139
+
1140
+ With 5 000 messages loaded this mounts about 40 rows (the ~10 that show, 20
1141
+ above and 20 below); scrolling moves the window, and reaching the end of the
1142
+ loaded rows loads the next page as before.
1143
+
1144
+ **What keeps working across the window.**
1145
+
1146
+ - The sticky header, pinned columns and their shadows, column widths and
1147
+ horizontal scroll: the spacers span every column.
1148
+ - The infinite sentinel: it sits under the full height of the rows, so it
1149
+ comes into view at the end of the loaded rows and asks for the next page.
1150
+ - The keys of row activation: ArrowDown / ArrowUp / `j` / `k` onto a row
1151
+ outside the window scroll it in (to the nearest edge), mount it and focus
1152
+ it; Home and End go to the first and the last loaded row. A row is kept
1153
+ mounted, wherever it is, while it is the active row, holds the list's tab
1154
+ stop or has the focus, so it keeps the focus when it is scrolled away and
1155
+ back.
1156
+ - Selection: a shift-range and "select the page" are computed over the
1157
+ loaded rows, never the mounted ones, so a range spanning rows that were
1158
+ never drawn selects them all.
1159
+ - An open cell editor: its row stays mounted while the editor is open (the
1160
+ edit is neither committed nor cancelled by scrolling), and a row whose
1161
+ "more" menu is open stays mounted too.
1162
+ - Row actions, custom cells and lookups: a lookup column still makes one
1163
+ fetch for every loaded row, not one per window.
1164
+ - A refetch from the change feed keeps the scroll position: the window
1165
+ follows `scrollTop`, which a refetch of the same pages does not change.
1166
+ - `aria-rowcount` on the table is the loaded count and every mounted row
1167
+ carries its `aria-rowindex` (1-based, over the loaded rows), so a screen
1168
+ reader hears "row 2 501 of 5 000" for a row it could not otherwise place.
1169
+
1170
+ **Limits.** The browser's find-in-page (Ctrl / Cmd+F) sees only the mounted
1171
+ rows; search the list with the view's search box instead. Printing prints
1172
+ the window, not the list. Rows of variable height are not supported (a row
1173
+ taller than `row_height` is measured once and its height used for all), and
1174
+ the cards, kanban and tree renderers are not windowed.
1175
+
1176
+ **In a host renderer.** The arithmetic is in `@jsudc/react/headless`:
1177
+ `virtualizationApplies(virtualize, mode, count)`,
1178
+ `resolveVirtualization(virtualize)` (with `DEFAULT_VIRTUAL_THRESHOLD`,
1179
+ `DEFAULT_VIRTUAL_OVERSCAN`), `visibleRange`, `withOverscan`, `keepRange`,
1180
+ `bodySlices(count, range, pinned)` and the hook `useRowWindow`. A windowed
1181
+ list of your own passes `reveal(row, index)` to `useRowActivation`: the keys
1182
+ call it for a row that is not mounted, and the row takes the focus the
1183
+ moment its element attaches. `RendererProps.virtualize` carries the view's
1184
+ prop when the host set it.
1185
+
1186
+ ## Custom cells
1187
+
1188
+ A column of the table can be drawn by a component of the host's. Register
1189
+ cell components by name, the way renderers are registered, and name one in
1190
+ the column's `render`:
1191
+
1192
+ ```yaml
1193
+ view:
1194
+ columns:
1195
+ - field: from
1196
+ render: sender # the host's component
1197
+ render_options: { avatar: true }
1198
+ - field: label
1199
+ render: badge # built in, unless the host registered "badge"
1200
+ ```
1201
+
1202
+ `render: "<name>"` resolves from the host's registry first, then from the
1203
+ built-in kinds (`bool`, `badge`, `sparkline`, `heading_glyph`, `icon`,
1204
+ `date`, `datetime`, `number_format`, `bytes`, `text`); a name nobody
1205
+ registered behaves as before (the field type's kind). Registering a built-in
1206
+ name replaces that kind for every column that names it in `render` (a
1207
+ column that only inherits a kind from its field type keeps the built-in).
1208
+ The cards draw their meta fields through the same registry; the other
1209
+ renderers (the kanban's, the calendar's, the map's and the chart's details)
1210
+ keep the built-in kinds.
1211
+
1212
+ A cell component receives `CellProps`, a public contract like
1213
+ `RendererProps`:
1214
+
1215
+ | Prop | Type | What it is |
1216
+ | ---------------------- | ----------------------- | ----------------------------------------------------------------------------------------- |
1217
+ | `value` | `unknown` | `row[column.field]` as the server sent it; blank values too (draw your own empty) |
1218
+ | `row` | `Row` | the whole row, `__meta` (id, version) included |
1219
+ | `column` | `ColumnConfig` | the column from `view.columns[]` (or the card's meta field): `render_options`, `align`, … |
1220
+ | `def` | `FieldDef \| undefined` | the field's definition in the schema |
1221
+ | `collection` | `string` | the collection's name |
1222
+ | `locale`, `intlLocale` | `string` | the UI's language and its `Intl` locale |
1223
+ | `editable` | `boolean` | the cell edits on double-click (the inline editor draws over your component) |
1224
+ | `surface` | `"table" \| "card"` | a table cell or a card's meta field |
1225
+
1226
+ ```tsx
1227
+ import { type CellProps, createCellRegistry, UdcDataView, UdcProvider } from "@jsudc/react";
1228
+
1229
+ /** The sender as an avatar and a name, the unread ones bold. */
1230
+ function SenderCell({ value, row, column }: CellProps) {
1231
+ const name = String(value ?? "");
1232
+ return (
1233
+ <span style={{ display: "flex", gap: 6, fontWeight: row.unread ? 600 : 400 }}>
1234
+ {column.render_options?.avatar ? (
1235
+ <img src={`/avatars/${name}.png`} alt="" width={20} />
1236
+ ) : null}
1237
+ {name || "—"}
1238
+ </span>
1239
+ );
1240
+ }
1241
+
1242
+ // A module constant, like the renderer registry.
1243
+ const cells = createCellRegistry({ name: "sender", component: SenderCell });
1244
+
1245
+ <UdcProvider client={client} renderers={renderers} cells={cells}>
1246
+ …
1247
+ </UdcProvider>;
1248
+
1249
+ // Or for one view, added to the provider's (this view's names win):
1250
+ <UdcDataView collection="messages" cells={cells} />;
1251
+ ```
1252
+
1253
+ `createCellRegistry` takes `{ name, component }` definitions, a later one
1254
+ replacing an earlier name; a plain `{ sender: SenderCell }` object is a
1255
+ registry too. `UdcCellsProvider cells={…}` sets one anywhere in the tree
1256
+ (nested providers add up, the inner names winning) and `useCellRegistry()`
1257
+ reads the one in effect; `CellValue` of `@jsudc/react/table` draws with it
1258
+ when passed `cells`, `row` and `collection`.
1259
+
276
1260
  ## Bring your own primitives
277
1261
 
278
1262
  The renderers never import a button, a dialog or a menu. They take every
@@ -356,7 +1340,7 @@ peer while the default kit is the fallback.
356
1340
  Everything the components import that a host is likely to have too is a peer,
357
1341
  so there is one copy of it in the bundle:
358
1342
 
359
- - `@jsudc/core` ^0.3.0 — one copy of the protocol, shared with the host's
1343
+ - `@jsudc/core` ^0.5.0 — one copy of the protocol, shared with the host's
360
1344
  own `UdcClient`;
361
1345
  - `react`, `react-dom` ^19 — one React, or hooks break;
362
1346
  - `@tanstack/react-query` ^5 — one `QueryClient` context, shared with the
@@ -399,10 +1383,57 @@ The stylesheet also carries the library's base rules (`border-color` on `*`,
399
1383
  `body` font and colours, pointer cursor on buttons) in `@layer base`; any
400
1384
  unlayered CSS of the host wins over them.
401
1385
 
1386
+ ### The scoped sheet: a stylesheet that leaves the host alone
1387
+
1388
+ `styles.css` is made for a page that is the library's: its preflight resets
1389
+ every `h1`, `button` and list of the page, its `body` rule sets the page's
1390
+ font and colours, and its tokens sit on `:root`, where they overwrite a
1391
+ host's own `--background` or `--primary`. A host that embeds a view in pages
1392
+ of its own imports the scoped sheet instead (one of the two, not both):
1393
+
1394
+ ```ts
1395
+ import "@jsudc/react/styles.scoped.css";
1396
+ ```
1397
+
1398
+ It has the same utilities, tokens and resets, applied only inside the
1399
+ library's roots: `.udc-data-view`, and `.udc-scope` (`UDC_SCOPE_CLASS`), which
1400
+ the default UI kit puts on everything it portals out of the view (dialogs,
1401
+ popovers, menus, selects, tooltips, toasts). There is no rule on `*`, `html`,
1402
+ `body` or `:root`, no global preflight and no `@property` registration, so
1403
+ the host's elements compute exactly the styles they computed before; the
1404
+ build fails if a selector of the sheet could match an element outside a root
1405
+ (`scripts/check-scoped-css.mjs`), and a test compares the computed styles of a
1406
+ host's page with and without it in headless Chrome.
1407
+
1408
+ | Situation | Sheet |
1409
+ | ------------------------------------------------------------------------ | ------------------- |
1410
+ | the page is the library's (an admin, a back office), or a new app | `styles.css` |
1411
+ | the view is a pane of the host's own pages, with the host's own base CSS | `styles.scoped.css` |
1412
+ | the host's tokens share the generic names (`--background`, `--primary`) | `styles.scoped.css` |
1413
+
1414
+ What changes with it:
1415
+
1416
+ - **Theming:** the tokens are declared on the roots, at zero specificity
1417
+ (`:where(.udc-data-view, .udc-scope)`), so the host restyles the library on
1418
+ the roots, not on `:root`: `.udc-data-view, .udc-scope { --primary: …; }`.
1419
+ `.dark` on any ancestor (or on the root itself) switches both themes as
1420
+ before.
1421
+ - **Components outside a view:** a `LookupCombobox` or a schema dialog
1422
+ rendered by the host outside `<UdcDataView>` needs a root around it:
1423
+ `<div className={UDC_SCOPE_CLASS}>…</div>`. A host-supplied UI kit that
1424
+ portals its own content does the same if that content relies on the
1425
+ library's sheet.
1426
+ - **The background:** a root paints none; the view sits on the host's pane.
1427
+ - **The cascade:** the resets are in `@layer base` and the utilities in
1428
+ `@layer utilities`, as in `styles.css`, so an unlayered element rule of the
1429
+ host (`button { background: … }`) still reaches inside the view. Put the
1430
+ host's own base styles in a layer, or scope them, if they should not.
1431
+
402
1432
  ### Theming
403
1433
 
404
1434
  Every colour, radius and font comes from a CSS variable on `:root` and
405
- `.dark`. Restyling is redefining them after the stylesheet, no code:
1435
+ `.dark` (with the scoped sheet: on the library's roots, see above).
1436
+ Restyling is redefining them after the stylesheet, no code:
406
1437
 
407
1438
  ```css
408
1439
  :root {
@@ -450,6 +1481,7 @@ change with them, for plain-CSS overrides:
450
1481
  | Class | Element |
451
1482
  | -------------------- | ------------------------------------------------- |
452
1483
  | `udc-data-view` | the whole view (header, toolbar, the renderer) |
1484
+ | `udc-scope` | a portalled dialog, popover, menu, tooltip, toast |
453
1485
  | `udc-toolbar` | the toolbar: search, chips, filter builder, count |
454
1486
  | `udc-search` | the search box |
455
1487
  | `udc-filter-chip` | one filter chip |
@@ -482,6 +1514,9 @@ change with them, for plain-CSS overrides:
482
1514
  }
483
1515
  ```
484
1516
 
1517
+ With row activation on, the active row and card also carry
1518
+ `data-active="true"` (`.udc-row[data-active] .udc-cell { … }`).
1519
+
485
1520
  A rule of the host's own (unlayered) CSS wins over the library's utilities,
486
1521
  which sit in Tailwind's `@layer utilities`, without `!important`; only inline
487
1522
  styles (row height, column widths, pinned offsets) need it.
@@ -524,6 +1559,63 @@ const messages: Messages = {
524
1559
  - `useI18n()` gives `t`, `tMaybe` (`null` when missing), `locale`,
525
1560
  `intlLocale`, `locales` and `setLocale` to your own components too.
526
1561
 
1562
+ ## Sessions
1563
+
1564
+ A host with a cookie session and a CSRF token uses the client as it is: the
1565
+ `UdcClient` of `@jsudc/core` reads its `headers` per call when they are a
1566
+ function, sends cookies to another origin with `credentials: "include"`, and
1567
+ turns "not signed in" — an HTTP 401 in front of `/udc`, or the server's
1568
+ in-protocol refusal (`forbidden`, `details.reason: "unauthenticated"`) — into
1569
+ one error, `isUnauthenticated(err)`. That error is never retried. The library
1570
+ does two things with it:
1571
+
1572
+ - **`createUdcQueryClient({ onUnauthenticated })`** calls your callback when a
1573
+ query or a mutation fails that way: the one place to send the user to your
1574
+ login. It is called once per burst — the failures that arrive together (every
1575
+ query of a page) make one call — and again only after
1576
+ `unauthenticatedQuietMs` (default 2000) without such a failure.
1577
+ `createUdcQueryClient()` without arguments works as before.
1578
+ - **The error state** of every view says the user is signed out
1579
+ (`APP.SIGNED_OUT_TITLE`, `APP.SIGNED_OUT_BODY`, overridable like every other
1580
+ term) instead of the generic failure with Retry.
1581
+
1582
+ ```tsx
1583
+ import { UdcClient } from "@jsudc/core/client";
1584
+ import { createUdcQueryClient, UdcDataView, UdcProvider } from "@jsudc/react";
1585
+ import { RENDERERS } from "@jsudc/react/all";
1586
+ import { QueryClientProvider } from "@tanstack/react-query";
1587
+
1588
+ // Django-style: the session cookie travels by itself, the CSRF token is a cookie
1589
+ // the page reads and echoes in a header — read on every call, so a new session
1590
+ // (and a new token) needs no new client.
1591
+ const csrfToken = () => document.cookie.match(/(?:^|; )csrftoken=([^;]*)/)?.[1] ?? "";
1592
+
1593
+ const client = new UdcClient({
1594
+ httpUrl: "https://api.example.com",
1595
+ credentials: "include", // cookies to another origin; leave it out on the same origin
1596
+ headers: () => ({ "x-csrftoken": csrfToken() }),
1597
+ });
1598
+
1599
+ const queryClient = createUdcQueryClient({
1600
+ // once, however many queries of the page were refused together
1601
+ onUnauthenticated: () => {
1602
+ const next = encodeURIComponent(location.pathname + location.search);
1603
+ location.assign(`/login?next=${next}`);
1604
+ },
1605
+ });
1606
+
1607
+ <UdcProvider client={client} renderers={RENDERERS}>
1608
+ <QueryClientProvider client={queryClient}>
1609
+ {/* …the other providers of the quick start… */}
1610
+ <UdcDataView collection="messages" />
1611
+ </QueryClientProvider>
1612
+ </UdcProvider>;
1613
+ ```
1614
+
1615
+ An HTTP 403 is `forbidden` with `details.http_status: 403`: also not retried,
1616
+ shown as the generic failure, and not passed to `onUnauthenticated`. Login
1617
+ screens, token refresh and storing the session are the host's.
1618
+
527
1619
  ## Lookups and drill-down
528
1620
 
529
1621
  A `lookup` / `lookup_array` field (see `@jsudc/core`) holds the key of a row of
@@ -585,24 +1677,47 @@ registry and everything not tied to one renderer. Beyond the above:
585
1677
  `createRendererRegistry`, `rendererEntry`, `rendererTabs`, `resolveTab`,
586
1678
  `UdcRenderersProvider`, `useRendererRegistry` and the `RendererProps` /
587
1679
  `RendererEntry` / `RendererDefinition` / `RendererRegistry` types;
588
- `EmptyState` / `ErrorState` / `NoRendererState`; `mergeMessages`, `makeT`,
1680
+ `EmptyState` / `ErrorState` / `NoRendererState`; the `UdcQueryClientOptions` type;
1681
+ the row activation `useRowActivation`, `rowActivationEnabled`, `ownsKeys`
1682
+ and the `RowActivationProps` / `RowActivation` / `RowActivationRowProps` /
1683
+ `UseRowActivationOptions` types; the selection `useRowSelection` with its
1684
+ pure operations and the `RowSelection` / `RowSelectionState` types; the bulk
1685
+ actions `UdcActionsProvider`, `useBulkActionHandlers`, `planBulkAction`,
1686
+ `bulkActionEligible`, `selectionTarget`, `MATCH_ALL` and the
1687
+ `BulkActionContext` / `BulkActionHandler` / `BulkActionHandlers` /
1688
+ `BulkActionPlan` types; the row actions `rowActionDefs`, `rowActionsDisplay`,
1689
+ `eligibleRowActions`, `isRowMenuKey`, `RowActionsControls`, `useRowMenu`,
1690
+ `rowMenuHandlers`, `rowActionsColumnWidth` and the `RowActions` /
1691
+ `RowActionsDisplay` / `RowMenuState` / `RowMenuVia` /
1692
+ `RowActionsControlsProps` / `RowMenuKeyEvent` types; the hooks `useUdcMutateMany`, `useUdcAction` and the
1693
+ cache helpers `applyToListRows`, `mutateManyTouches`, `callAction`; the cells `createCellRegistry`,
1694
+ `cellComponent`, `mergeCellRegistries`, `UdcCellsProvider`, `useCellRegistry`
1695
+ and the `CellProps` / `CellComponent` / `CellDefinition` / `CellRegistry`
1696
+ types; `mergeMessages`, `makeT`,
589
1697
  `lookup`, `schemaLabelTerms`, `tableSection`, `TRANSLATIONS`, `LOCALES`;
590
1698
  `cn` (tailwind-merge set up for the `udc:` prefix), `storage`, `humanize`;
591
- `UdcUrlStateProvider`, `useUrlSearchParams`, `windowLocationAdapter` and the
592
- `UrlStateAdapter` type; `UdcUiProvider`, `useUiKit` and the `UiKit` type with
1699
+ `UdcUrlStateProvider`, `useUrlSearchParams`, `windowLocationAdapter`,
1700
+ `prefixUrlStateAdapter`, `createMemoryUrlStateAdapter` and the
1701
+ `UrlStateAdapter` / `MemoryUrlStateAdapter` types; the embedding types
1702
+ `UdcDataViewChrome` / `UdcDataViewChromePreset` with `resolveChrome`, and
1703
+ `UDC_SCOPE_CLASS` (also on `@jsudc/react/ui`); `UdcUiProvider`, `useUiKit` and the `UiKit` type with
593
1704
  its props types; `resolveIcon` with the `lucide:<name>` icons the package
594
1705
  bundles (`LUCIDE_ICONS`); and the zone helpers `allZones`, `offsetLabel`,
595
1706
  `zoneCity`; the lookups: `useUdcLookup`, `useUdcLookups`, `useLookupBatch`,
596
1707
  `UdcLookupBatch`, `LookupValue`, `useLookupLabels`, `useLookupOptions`,
597
1708
  `LookupSelectChip`, `LookupCombobox`, `UdcLinksProvider`, `useUdcLinks`,
598
1709
  `defaultUdcLinks`, `filterHref`, `followLink` (the hooks without markup are in
599
- `@jsudc/react/headless` too).
1710
+ `@jsudc/react/headless` too); the change feed: `useUdcChanges`,
1711
+ `useUdcChangeFeed`, `UdcChangeFeed`, `LiveIndicator` and the
1712
+ `UdcChangeFeedOptions` / `UdcChangeFeedStatus` / `UseUdcChangesOptions` /
1713
+ `UdcChangesResult` types (see [Live updates](#live-updates)).
600
1714
 
601
1715
  The subpaths: one per renderer and `@jsudc/react/all` (see
602
1716
  [Renderers](#renderers)), `@jsudc/react/headless` (see [Headless](#headless)),
603
1717
  `@jsudc/react/ui` (`defaultUiKit` and its primitives: `Button`, `Dialog`,
604
1718
  `Toaster`, `TooltipProvider`, …), `@jsudc/react/react-router`
605
- (`UdcReactRouterUrlState`), `@jsudc/react/styles.css` and
1719
+ (`UdcReactRouterUrlState`), `@jsudc/react/styles.css`,
1720
+ `@jsudc/react/styles.scoped.css` (see [Styling](#styling)) and
606
1721
  `@jsudc/react/tokens.css`.
607
1722
 
608
1723
  The build is ESM only, one file per source module (tree-shakeable), one