@jsudc/react 0.4.0 → 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 (102) hide show
  1. package/README.md +589 -11
  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 +4 -3
  15. package/dist/calendar/CalendarRenderer.js.map +1 -1
  16. package/dist/cards/CardRenderer.d.ts +6 -0
  17. package/dist/cards/CardRenderer.js +42 -7
  18. package/dist/cards/CardRenderer.js.map +1 -1
  19. package/dist/chart/ChartRenderer.js +6 -4
  20. package/dist/chart/ChartRenderer.js.map +1 -1
  21. package/dist/chart/ChartWindowControl.js +1 -1
  22. package/dist/data-view/BulkBar.d.ts +36 -0
  23. package/dist/data-view/BulkBar.js +239 -0
  24. package/dist/data-view/BulkBar.js.map +1 -0
  25. package/dist/data-view/FilePreview.js +1 -1
  26. package/dist/data-view/FilterBuilder.js +1 -1
  27. package/dist/data-view/FilterChips.js +1 -1
  28. package/dist/data-view/LiveIndicator.d.ts +10 -0
  29. package/dist/data-view/LiveIndicator.js +33 -0
  30. package/dist/data-view/LiveIndicator.js.map +1 -0
  31. package/dist/data-view/UdcDataView.d.ts +28 -1
  32. package/dist/data-view/UdcDataView.js +69 -8
  33. package/dist/data-view/UdcDataView.js.map +1 -1
  34. package/dist/headless.d.ts +6 -0
  35. package/dist/headless.js +9 -2
  36. package/dist/i18n/translations.js +128 -0
  37. package/dist/i18n/translations.js.map +1 -1
  38. package/dist/index.d.ts +9 -1
  39. package/dist/index.js +13 -4
  40. package/dist/kanban/KanbanCard.js +1 -1
  41. package/dist/kanban/KanbanRenderer.js +5 -4
  42. package/dist/kanban/KanbanRenderer.js.map +1 -1
  43. package/dist/lookup/batch.js +1 -1
  44. package/dist/lookup/options.js +4 -1
  45. package/dist/lookup/options.js.map +1 -1
  46. package/dist/lookup/useUdcLookup.js +9 -3
  47. package/dist/lookup/useUdcLookup.js.map +1 -1
  48. package/dist/map/MapRenderer.js +3 -2
  49. package/dist/map/MapRenderer.js.map +1 -1
  50. package/dist/renderers/types.d.ts +32 -1
  51. package/dist/renderers/types.js.map +1 -1
  52. package/dist/rows/useRowActivation.d.ts +17 -0
  53. package/dist/rows/useRowActivation.js +37 -5
  54. package/dist/rows/useRowActivation.js.map +1 -1
  55. package/dist/rows/useRowSelection.d.ts +92 -0
  56. package/dist/rows/useRowSelection.js +156 -0
  57. package/dist/rows/useRowSelection.js.map +1 -0
  58. package/dist/schema-editor/DeleteFieldDialog.js +1 -1
  59. package/dist/schema-editor/FieldFormDialog.js +1 -1
  60. package/dist/styles.css +1 -1
  61. package/dist/styles.scoped.css +1 -1
  62. package/dist/table/CellEditor.js +1 -1
  63. package/dist/table/SelectCheckbox.d.ts +15 -0
  64. package/dist/table/SelectCheckbox.js +37 -0
  65. package/dist/table/SelectCheckbox.js.map +1 -0
  66. package/dist/table/TableRenderer.d.ts +13 -0
  67. package/dist/table/TableRenderer.js +281 -123
  68. package/dist/table/TableRenderer.js.map +1 -1
  69. package/dist/table/cells.js +1 -1
  70. package/dist/table/index.d.ts +1 -0
  71. package/dist/table/states.js +1 -1
  72. package/dist/table/useRowWindow.d.ts +82 -0
  73. package/dist/table/useRowWindow.js +182 -0
  74. package/dist/table/useRowWindow.js.map +1 -0
  75. package/dist/table.js.map +1 -1
  76. package/dist/tree/TreeRenderer.d.ts +2 -0
  77. package/dist/tree/TreeRenderer.js +15 -9
  78. package/dist/tree/TreeRenderer.js.map +1 -1
  79. package/dist/udc/changeFeed.d.ts +94 -0
  80. package/dist/udc/changeFeed.js +250 -0
  81. package/dist/udc/changeFeed.js.map +1 -0
  82. package/dist/udc/changes.d.ts +34 -0
  83. package/dist/udc/changes.js +79 -0
  84. package/dist/udc/changes.js.map +1 -0
  85. package/dist/udc/client.js +5 -2
  86. package/dist/udc/client.js.map +1 -1
  87. package/dist/udc/hooks.d.ts +93 -20
  88. package/dist/udc/hooks.js +113 -10
  89. package/dist/udc/hooks.js.map +1 -1
  90. package/dist/udc/keys.d.ts +2 -0
  91. package/dist/udc/keys.js.map +1 -1
  92. package/dist/udc/listCache.d.ts +11 -0
  93. package/dist/udc/listCache.js +38 -0
  94. package/dist/udc/listCache.js.map +1 -0
  95. package/dist/udc/provider.d.ts +17 -2
  96. package/dist/udc/provider.js +18 -2
  97. package/dist/udc/provider.js.map +1 -1
  98. package/dist/udc/unauthenticated.d.ts +4 -0
  99. package/dist/udc/unauthenticated.js +17 -0
  100. package/dist/udc/unauthenticated.js.map +1 -0
  101. package/dist/ui-kit/types.d.ts +14 -0
  102. package/package.json +3 -3
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.4.0 github:digital-cube/jsudc-react#v0.4.0
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
@@ -163,6 +164,7 @@ when this table drifts).
163
164
  | `unwindowedFilter` | `FilterNode \| undefined` (optional) | `filter` without the chart window: what "of M" counts |
164
165
  | `chartWindow` | `ChartWindowState \| undefined` (optional) | the chart window when one applies (already in `filter`) |
165
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)) |
166
168
  | `sort`, `onSort(field, multi)` | `SortKey[]`, function | the sort and the header click that cycles it |
167
169
  | `mode`, `page`, `limit`, `onPage(n)` | `"pages" \| "infinite"`, numbers, function | the paging mode, the 1-based page, the page size, go to a page |
168
170
  | `filtered`, `onClearFilters()` | `boolean`, function | did the user filter (the host's `filter` does not count), and "clear filters" for the empty state |
@@ -173,6 +175,9 @@ when this table drifts).
173
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 |
174
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) |
175
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` |
176
181
 
177
182
  The three activation props are absent unless the host turned activation on;
178
183
  `useRowActivation` of `@jsudc/react/headless` does everything they describe
@@ -181,8 +186,9 @@ column's cells are drawn is not a renderer's business: see
181
186
  [Custom cells](#custom-cells).
182
187
 
183
188
  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
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
186
192
  list of a mail client:
187
193
 
188
194
  ```tsx
@@ -234,7 +240,8 @@ plain HTML builds its own renderer on it and gets the same queries, filters and
234
240
  URL state.
235
241
 
236
242
  - the client context and the hooks: `useUdcClient`, `useUdcDescribe`,
237
- `useUdcCollection`, `useUdcAllRows`, `useUdcMutate`, `useUdcSchema`, `udcKeys`;
243
+ `useUdcCollection`, `useUdcAllRows`, `useUdcMutate`, `useUdcSchema`, `udcKeys`,
244
+ and the change feed's `useUdcChanges` (see [Live updates](#live-updates));
238
245
  - the data view's state: `useDataViewState` (tab, search, chips, filter tree,
239
246
  sort, paging in the URL), `composeFilter`, the URL codecs of `urlState.ts`,
240
247
  `liveDescribe` / `liveSort`, the folder helpers;
@@ -245,7 +252,9 @@ URL state.
245
252
  - `applyTransforms`, `displayText`, `renderKind` and the cell formatters;
246
253
  the zone helpers and `useTimezone`;
247
254
  - `useRowActivation` (the active row and the keys, see
248
- [Row activation and keyboard](#row-activation-and-keyboard)) and the cell
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
249
258
  registry (`createCellRegistry`, `UdcCellsProvider`, `useCellRegistry`, see
250
259
  [Custom cells](#custom-cells));
251
260
  - the registry functions (`createRendererRegistry`, `resolveTab`) and the URL
@@ -510,13 +519,15 @@ ArrowDown / `j` and ArrowUp / `k` move the active row (and the focus) by one,
510
519
  Home / End jump to the first / last loaded row, Enter activates. They are
511
520
  left alone while an input, the search box, a cell editor, a menu, a list box
512
521
  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
522
+ not bound unless the view selects; then it toggles the active row (0.5.0). Double-click and Enter still
514
523
  edit an editable cell when the focus is on the cell itself.
515
524
 
516
525
  **One tab stop.** The rows are a roving-`tabindex` list: Tab reaches the
517
526
  active row (else the one last focused, else the first) and leaves the list on
518
527
  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
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
520
531
  `data-active="true"` (`.udc-row[data-active]`, `.udc-card[data-active]` for
521
532
  your CSS) and the `--selected` background.
522
533
 
@@ -618,6 +629,560 @@ function MessageList({ data, onRowActivate, activeRowId, onActiveRowChange }: Re
618
629
  and `nav.activate(row)` drive it from the host's own buttons, and `ownsKeys`
619
630
  says whether a key belongs to the element it was pressed on.
620
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
+
621
1186
  ## Custom cells
622
1187
 
623
1188
  A column of the table can be drawn by a component of the host's. Register
@@ -775,7 +1340,7 @@ peer while the default kit is the fallback.
775
1340
  Everything the components import that a host is likely to have too is a peer,
776
1341
  so there is one copy of it in the bundle:
777
1342
 
778
- - `@jsudc/core` ^0.4.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
779
1344
  own `UdcClient`;
780
1345
  - `react`, `react-dom` ^19 — one React, or hooks break;
781
1346
  - `@tanstack/react-query` ^5 — one `QueryClient` context, shared with the
@@ -1115,7 +1680,17 @@ registry and everything not tied to one renderer. Beyond the above:
1115
1680
  `EmptyState` / `ErrorState` / `NoRendererState`; the `UdcQueryClientOptions` type;
1116
1681
  the row activation `useRowActivation`, `rowActivationEnabled`, `ownsKeys`
1117
1682
  and the `RowActivationProps` / `RowActivation` / `RowActivationRowProps` /
1118
- `UseRowActivationOptions` types; the cells `createCellRegistry`,
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`,
1119
1694
  `cellComponent`, `mergeCellRegistries`, `UdcCellsProvider`, `useCellRegistry`
1120
1695
  and the `CellProps` / `CellComponent` / `CellDefinition` / `CellRegistry`
1121
1696
  types; `mergeMessages`, `makeT`,
@@ -1132,7 +1707,10 @@ bundles (`LUCIDE_ICONS`); and the zone helpers `allZones`, `offsetLabel`,
1132
1707
  `UdcLookupBatch`, `LookupValue`, `useLookupLabels`, `useLookupOptions`,
1133
1708
  `LookupSelectChip`, `LookupCombobox`, `UdcLinksProvider`, `useUdcLinks`,
1134
1709
  `defaultUdcLinks`, `filterHref`, `followLink` (the hooks without markup are in
1135
- `@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)).
1136
1714
 
1137
1715
  The subpaths: one per renderer and `@jsudc/react/all` (see
1138
1716
  [Renderers](#renderers)), `@jsudc/react/headless` (see [Headless](#headless)),