@jsudc/react 0.4.0 → 0.5.1
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.
- package/README.md +615 -11
- package/dist/actions/RowActionsMenu.d.ts +45 -0
- package/dist/actions/RowActionsMenu.js +161 -0
- package/dist/actions/RowActionsMenu.js.map +1 -0
- package/dist/actions/bulk.d.ts +81 -0
- package/dist/actions/bulk.js +54 -0
- package/dist/actions/bulk.js.map +1 -0
- package/dist/actions/row.d.ts +50 -0
- package/dist/actions/row.js +34 -0
- package/dist/actions/row.js.map +1 -0
- package/dist/actions/useRowActionRunner.d.ts +26 -0
- package/dist/actions/useRowActionRunner.js +198 -0
- package/dist/actions/useRowActionRunner.js.map +1 -0
- package/dist/calendar/CalendarRenderer.js +4 -3
- package/dist/calendar/CalendarRenderer.js.map +1 -1
- package/dist/cards/CardRenderer.d.ts +6 -0
- package/dist/cards/CardRenderer.js +45 -9
- package/dist/cards/CardRenderer.js.map +1 -1
- package/dist/chart/ChartRenderer.js +6 -4
- package/dist/chart/ChartRenderer.js.map +1 -1
- package/dist/chart/ChartWindowControl.js +1 -1
- package/dist/data-view/BulkBar.d.ts +36 -0
- package/dist/data-view/BulkBar.js +239 -0
- package/dist/data-view/BulkBar.js.map +1 -0
- package/dist/data-view/FilePreview.js +1 -1
- package/dist/data-view/FilterBuilder.js +1 -1
- package/dist/data-view/FilterChips.js +1 -1
- package/dist/data-view/LiveIndicator.d.ts +10 -0
- package/dist/data-view/LiveIndicator.js +33 -0
- package/dist/data-view/LiveIndicator.js.map +1 -0
- package/dist/data-view/UdcDataView.d.ts +28 -1
- package/dist/data-view/UdcDataView.js +76 -9
- package/dist/data-view/UdcDataView.js.map +1 -1
- package/dist/headless.d.ts +6 -0
- package/dist/headless.js +9 -2
- package/dist/i18n/translations.js +144 -0
- package/dist/i18n/translations.js.map +1 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.js +13 -4
- package/dist/kanban/KanbanCard.js +1 -1
- package/dist/kanban/KanbanRenderer.js +5 -4
- package/dist/kanban/KanbanRenderer.js.map +1 -1
- package/dist/lookup/batch.js +1 -1
- package/dist/lookup/options.js +4 -1
- package/dist/lookup/options.js.map +1 -1
- package/dist/lookup/useUdcLookup.js +9 -3
- package/dist/lookup/useUdcLookup.js.map +1 -1
- package/dist/map/MapRenderer.js +3 -2
- package/dist/map/MapRenderer.js.map +1 -1
- package/dist/renderers/types.d.ts +32 -1
- package/dist/renderers/types.js.map +1 -1
- package/dist/rows/useRowActivation.d.ts +17 -0
- package/dist/rows/useRowActivation.js +37 -5
- package/dist/rows/useRowActivation.js.map +1 -1
- package/dist/rows/useRowSelection.d.ts +92 -0
- package/dist/rows/useRowSelection.js +156 -0
- package/dist/rows/useRowSelection.js.map +1 -0
- package/dist/schema-editor/DeleteFieldDialog.js +1 -1
- package/dist/schema-editor/FieldFormDialog.js +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.scoped.css +1 -1
- package/dist/table/CellEditor.js +1 -1
- package/dist/table/Pager.d.ts +10 -2
- package/dist/table/Pager.js +26 -20
- package/dist/table/Pager.js.map +1 -1
- package/dist/table/SelectCheckbox.d.ts +15 -0
- package/dist/table/SelectCheckbox.js +37 -0
- package/dist/table/SelectCheckbox.js.map +1 -0
- package/dist/table/TableRenderer.d.ts +13 -0
- package/dist/table/TableRenderer.js +284 -125
- package/dist/table/TableRenderer.js.map +1 -1
- package/dist/table/cells.js +1 -1
- package/dist/table/index.d.ts +1 -0
- package/dist/table/states.js +1 -1
- package/dist/table/useRowWindow.d.ts +82 -0
- package/dist/table/useRowWindow.js +182 -0
- package/dist/table/useRowWindow.js.map +1 -0
- package/dist/table.js.map +1 -1
- package/dist/tree/TreeRenderer.d.ts +2 -0
- package/dist/tree/TreeRenderer.js +15 -9
- package/dist/tree/TreeRenderer.js.map +1 -1
- package/dist/udc/changeFeed.d.ts +107 -0
- package/dist/udc/changeFeed.js +281 -0
- package/dist/udc/changeFeed.js.map +1 -0
- package/dist/udc/changes.d.ts +40 -0
- package/dist/udc/changes.js +85 -0
- package/dist/udc/changes.js.map +1 -0
- package/dist/udc/client.js +5 -2
- package/dist/udc/client.js.map +1 -1
- package/dist/udc/hooks.d.ts +93 -20
- package/dist/udc/hooks.js +115 -11
- package/dist/udc/hooks.js.map +1 -1
- package/dist/udc/keys.d.ts +2 -0
- package/dist/udc/keys.js.map +1 -1
- package/dist/udc/listCache.d.ts +11 -0
- package/dist/udc/listCache.js +38 -0
- package/dist/udc/listCache.js.map +1 -0
- package/dist/udc/provider.d.ts +34 -2
- package/dist/udc/provider.js +28 -2
- package/dist/udc/provider.js.map +1 -1
- package/dist/udc/unauthenticated.d.ts +4 -0
- package/dist/udc/unauthenticated.js +17 -0
- package/dist/udc/unauthenticated.js.map +1 -0
- package/dist/ui-kit/types.d.ts +14 -0
- 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`, `
|
|
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.
|
|
44
|
+
npm install github:digital-cube/jsudc-core#v0.5.0 github:digital-cube/jsudc-react#v0.5.1
|
|
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
|
|
185
|
-
`@jsudc/react/headless`, e.g. `useUdcAllRows
|
|
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))
|
|
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
|
|
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"
|
|
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,586 @@ 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
|
+
**When the user behind the client changes** (0.5.1). The server runs the plugin's
|
|
775
|
+
`context` once, when a stream opens, and keeps that scope for the life of the
|
|
776
|
+
stream. With `headers` as a function (`new UdcClient({ headers: () => ({
|
|
777
|
+
"x-user": current }) })`: a demo user switcher, an account switcher,
|
|
778
|
+
impersonation) a switch leaves the collections on screen as they were, so
|
|
779
|
+
nothing would reopen the stream: the new user would hear the old user's
|
|
780
|
+
events and miss their own. Tell the provider who the stream is for:
|
|
781
|
+
|
|
782
|
+
```tsx
|
|
783
|
+
<UdcProvider client={client} changes={{ identity: user }}>
|
|
784
|
+
<Routes />
|
|
785
|
+
</UdcProvider>;
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
When `identity` changes (compared with `Object.is`: pass an id, not a new
|
|
789
|
+
object per render) the provider calls `reconnect()` on its feed: the stream
|
|
790
|
+
is closed at once and reopened for the same collections, `headers` read
|
|
791
|
+
again; meanwhile the views say `reconnecting` and poll, and once it is open
|
|
792
|
+
what was fetched before the switch is refetched. Nothing below the provider
|
|
793
|
+
remounts, so component state survives (no `key={user}` needed). The same is
|
|
794
|
+
`useUdcChangeFeed()?.reconnect()` from your own code, which also asks again
|
|
795
|
+
for a stream the server refused (after signing in again). For full control,
|
|
796
|
+
provide a feed of your own through `UdcChangeFeedContext` (`new
|
|
797
|
+
UdcChangeFeed(client, options)`, one per user, `close()` it when replaced);
|
|
798
|
+
a `UdcProvider` below it with the same client and without `changes` uses it.
|
|
799
|
+
|
|
800
|
+
`useUdcChanges(collection, onEvent?, { capabilities?, enabled? })` answers
|
|
801
|
+
`{ status, live }`: `off` (no feed, or the collection does not offer it),
|
|
802
|
+
`connecting`, `live`, `reconnecting`, or `down` (refused). It reads the
|
|
803
|
+
capability from the collection's cached `describe` unless you pass
|
|
804
|
+
`capabilities`.
|
|
805
|
+
|
|
806
|
+
**Without the feed** nothing changes: a provider without `changes` opens no
|
|
807
|
+
connection and asks no `describe` for it, a collection whose `describe` does
|
|
808
|
+
not say `capabilities.changes: true` is never subscribed, and every view
|
|
809
|
+
polls on `refresh_interval_ms` (or not at all) exactly as before.
|
|
810
|
+
|
|
811
|
+
## Selection and bulk actions
|
|
812
|
+
|
|
813
|
+
A user selects rows (one, a range, the page, or everything that matches the
|
|
814
|
+
filter) and runs the view's `bulk_actions` on them. Selection is on when the
|
|
815
|
+
view says `multiselect: true` or declares `bulk_actions`; `selectable` on
|
|
816
|
+
`UdcDataView` forces it on (`true`) or off (`false`). A view with neither
|
|
817
|
+
draws exactly what it drew before 0.5.0.
|
|
818
|
+
|
|
819
|
+
**What the user does.** The table gets a checkbox column pinned at the start
|
|
820
|
+
and a header checkbox for the page (checked, empty or indeterminate);
|
|
821
|
+
shift-click selects the range from the last row toggled; with row activation
|
|
822
|
+
on, Space toggles the active row and Shift+Space selects a range to it. The
|
|
823
|
+
cards get a checkbox each. Kanban, tree, calendar, map and chart do not
|
|
824
|
+
select. While anything is selected a bar over the list shows the count, a
|
|
825
|
+
button per `bulk_actions` entry and a clear button.
|
|
826
|
+
|
|
827
|
+
**All that match.** When the whole page is selected and more rows match than
|
|
828
|
+
are loaded, the bar offers "Select all 1,234 that match". Taking it switches
|
|
829
|
+
the selection to "every row the filter matches, except the ones you uncheck"
|
|
830
|
+
(the bar reads "All 1,234 are selected"), and an action then goes to the
|
|
831
|
+
server by filter, not by ids. When everything is loaded already the page is
|
|
832
|
+
everything, and nothing is offered.
|
|
833
|
+
|
|
834
|
+
**The selection is cleared** when the filter changes (the search, a chip,
|
|
835
|
+
the filter builder, the host's `filter`) or the collection does (under a
|
|
836
|
+
source search, see [Search answered by the source](#search-answered-by-the-source),
|
|
837
|
+
"all that match" is not offered); a sort, a
|
|
838
|
+
refetch and more pages loading keep it. In id mode the selected rows are
|
|
839
|
+
remembered, so a row a refetch drops still counts and still reaches a
|
|
840
|
+
handler.
|
|
841
|
+
|
|
842
|
+
**Without a total.** A source answering `capabilities.total_count: false`
|
|
843
|
+
lists with `total: null`. The offer then reads "Select all that match", with
|
|
844
|
+
no number, the bar "All matching rows are selected", with no number, and the
|
|
845
|
+
result message reports the count the server answers (`updated`).
|
|
846
|
+
|
|
847
|
+
### Running an action
|
|
848
|
+
|
|
849
|
+
Each `bulk_actions` entry is an `ActionDef` of `@jsudc/core`: `kind`,
|
|
850
|
+
`label`, `icon` (`lucide:<name>`), `variant`, `when`, and 0.5.0's `set`,
|
|
851
|
+
`action` and `confirm`. Its button reads the term `ACTION_<KIND>` of the
|
|
852
|
+
collection's section (`TBL_<COLLECTION>`), else `ACTIONS.<kind>`, else the
|
|
853
|
+
def's `label`. It is disabled unless its `when` holds for every selected row
|
|
854
|
+
(`isActionEligibleForAll`); in "all that match" mode rows that are not loaded
|
|
855
|
+
cannot be checked in the browser, so it is offered unless `when` is `false`
|
|
856
|
+
and the server decides.
|
|
857
|
+
|
|
858
|
+
A click runs the first of these that applies:
|
|
859
|
+
|
|
860
|
+
1. **A handler for its `kind`**: the view's `actions` prop, else
|
|
861
|
+
`UdcProvider actions`. It gets `{ kind, def, collection, ids }` in id mode
|
|
862
|
+
or `{ kind, def, collection, filter, exceptIds }` in "all that match" mode,
|
|
863
|
+
with `rows` (the selected rows that are loaded) and `clearSelection`. The
|
|
864
|
+
view does not clear the selection after a handler; call `clearSelection`
|
|
865
|
+
when you are done. A handler that throws shows its message.
|
|
866
|
+
2. **`delete`**: a confirmation, then `mutate_many` `delete`.
|
|
867
|
+
3. **A def with `set`**: `mutate_many` `update` with that patch.
|
|
868
|
+
4. **Anything else**: the server action the def's `action` names (default its
|
|
869
|
+
`kind`) with `{ collection, ids }` or `{ collection, filter, except_ids }`
|
|
870
|
+
— a host action registered on the dispatcher (`@jsudc/server`'s
|
|
871
|
+
`Dispatcher.register`). An `unsupported_op` answer shows "The server does
|
|
872
|
+
not support …", naming the action.
|
|
873
|
+
|
|
874
|
+
The built-in paths ask first when `actionConfirms(def)` says so: `delete` by
|
|
875
|
+
default, any other def with `confirm: true` or a question of its own. They
|
|
876
|
+
change the loaded rows at once (`useUdcMutateMany`), put them back if the
|
|
877
|
+
call fails, refetch the collection's lists and lookups when it settles, and
|
|
878
|
+
report what the server answers: "12 rows deleted", "Mark read: 12 rows", and
|
|
879
|
+
"3 rows could not be changed" for the ids in `failed`, which stay selected.
|
|
880
|
+
|
|
881
|
+
A mailbox whose view archives through the host's own endpoint, marks read
|
|
882
|
+
with a patch, and deletes with the built-in delete:
|
|
883
|
+
|
|
884
|
+
```yaml
|
|
885
|
+
# The view of `messages`
|
|
886
|
+
view:
|
|
887
|
+
columns: [{ field: subject }, { field: from }, { field: received_at }]
|
|
888
|
+
bulk_actions:
|
|
889
|
+
- kind: archive
|
|
890
|
+
label: Archive
|
|
891
|
+
icon: lucide:archive
|
|
892
|
+
- kind: mark_read
|
|
893
|
+
label: Mark read
|
|
894
|
+
icon: lucide:mail-open
|
|
895
|
+
set: { read: true }
|
|
896
|
+
when: { field: read, op: eq, value: false }
|
|
897
|
+
- kind: delete
|
|
898
|
+
variant: destructive
|
|
899
|
+
```
|
|
900
|
+
|
|
901
|
+
```tsx
|
|
902
|
+
import { UdcDataView } from "@jsudc/react";
|
|
903
|
+
|
|
904
|
+
export function Inbox() {
|
|
905
|
+
return (
|
|
906
|
+
<UdcDataView
|
|
907
|
+
collection="messages"
|
|
908
|
+
filter={{ field: "folder", op: "eq", value: "inbox" }}
|
|
909
|
+
actions={{
|
|
910
|
+
// Id mode: `ids`. "All that match": `filter` (the host's folder, the search, the chips)
|
|
911
|
+
// and `exceptIds`. `rows` are the selected rows the view has loaded.
|
|
912
|
+
archive: async ({ ids, filter, exceptIds, clearSelection }) => {
|
|
913
|
+
await fetch("/api/mail/archive", {
|
|
914
|
+
method: "POST",
|
|
915
|
+
headers: { "content-type": "application/json" },
|
|
916
|
+
body: JSON.stringify(ids ? { ids } : { filter, except_ids: exceptIds }),
|
|
917
|
+
});
|
|
918
|
+
clearSelection();
|
|
919
|
+
},
|
|
920
|
+
// mark_read has `set`: a mutate_many update, no handler needed.
|
|
921
|
+
// delete is built in: a confirmation, then a mutate_many delete.
|
|
922
|
+
}}
|
|
923
|
+
/>
|
|
924
|
+
);
|
|
925
|
+
}
|
|
926
|
+
```
|
|
927
|
+
|
|
928
|
+
**Accessibility.** With selection on and row activation off the table stays a
|
|
929
|
+
table: each row's checkbox is a native checkbox labelled "Select row", the
|
|
930
|
+
header's "Select all rows shown" (`aria-checked="mixed"` when some are). With
|
|
931
|
+
both on the list is ARIA's multi-select grid (`aria-multiselectable="true"`):
|
|
932
|
+
`aria-selected` on a row says whether it is **selected**, and the active row
|
|
933
|
+
is the one holding the focus (the roving tab stop), marked
|
|
934
|
+
`aria-current="true"` and `data-active="true"`. With selection off,
|
|
935
|
+
`aria-selected` marks the active row as in 0.4.0. A selected row carries
|
|
936
|
+
`data-selected="true"` (`.udc-row[data-selected]`, `.udc-card[data-selected]`)
|
|
937
|
+
and the `--selected` background; the bar is `role="toolbar"` and its count is
|
|
938
|
+
announced politely.
|
|
939
|
+
|
|
940
|
+
**In a host renderer.** `RendererProps.selection` (a `RowSelection`, set
|
|
941
|
+
while the view selects) carries `mode`, `ids`, `exceptIds`, `count`
|
|
942
|
+
(`null` in "all that match" mode without a total), `rows`, `pageState`,
|
|
943
|
+
`isSelected(id)`, `toggle(id, { range })`, `setPage(on)`,
|
|
944
|
+
`selectAllMatching()`, `setIds(ids)` and `clear()`; the view draws the bar.
|
|
945
|
+
`useRowSelection({ rows, total, resetKey })` of `@jsudc/react/headless` is
|
|
946
|
+
the same model for a list of your own, and its pure operations
|
|
947
|
+
(`toggleSelection`, `selectRange`, `setPageSelection`, `selectAllMatching`,
|
|
948
|
+
`selectionCount`, …) range over the rows as loaded, not over the DOM.
|
|
949
|
+
`useRowActivation` takes `isSelected` and `onToggleSelect(row, range)` for
|
|
950
|
+
Space and the ARIA above.
|
|
951
|
+
|
|
952
|
+
### `useUdcMutateMany` and `useUdcAction`
|
|
953
|
+
|
|
954
|
+
`useUdcMutateMany(collection)` is `useUdcMutate` for many rows: `mutateAsync({
|
|
955
|
+
op: "update", ids, row })`, `{ op: "delete", ids }`, or by `filter` with
|
|
956
|
+
`except_ids`. The rows it touches are patched (or removed, the total counted
|
|
957
|
+
down) in every cached list at once, put back on an error, and the lists and
|
|
958
|
+
lookups are invalidated when it settles. It resolves to the server's `{
|
|
959
|
+
updated, failed }`: report `failed` yourself.
|
|
960
|
+
|
|
961
|
+
`useUdcAction(action)` is a mutation over the client's typed `call` for any
|
|
962
|
+
host action. Given the action's definition (`defineHostAction`, in a module
|
|
963
|
+
the server and the browser share), the payload and the answer are typed from
|
|
964
|
+
its schemas and the answer is checked; given a name, you type it
|
|
965
|
+
(`useUdcAction<Res, Req>("mail.flag")`). `invalidates` names the collections
|
|
966
|
+
whose lists to refetch afterwards; every other TanStack mutation option
|
|
967
|
+
passes through.
|
|
968
|
+
|
|
969
|
+
```ts
|
|
970
|
+
// shared/actions.ts — imported by the server (Dispatcher.register) and by the browser
|
|
971
|
+
import { defineHostAction } from "@jsudc/core";
|
|
972
|
+
import { z } from "zod";
|
|
973
|
+
|
|
974
|
+
export const snooze = defineHostAction({
|
|
975
|
+
name: "mail.snooze",
|
|
976
|
+
request: z.object({ ids: z.array(z.string()), until: z.iso.datetime() }),
|
|
977
|
+
response: z.object({ snoozed: z.number().int() }),
|
|
978
|
+
});
|
|
979
|
+
```
|
|
980
|
+
|
|
981
|
+
```tsx
|
|
982
|
+
import { useUdcAction } from "@jsudc/react";
|
|
983
|
+
import { snooze } from "../shared/actions";
|
|
984
|
+
|
|
985
|
+
export function SnoozeButton({ ids }: { ids: string[] }) {
|
|
986
|
+
const run = useUdcAction(snooze, { invalidates: ["messages"] });
|
|
987
|
+
return (
|
|
988
|
+
<button
|
|
989
|
+
type="button"
|
|
990
|
+
disabled={run.isPending}
|
|
991
|
+
// The payload is typed { ids: string[]; until: string }; data is { snoozed: number }.
|
|
992
|
+
onClick={() => run.mutate({ ids, until: new Date(Date.now() + 3_600_000).toISOString() })}
|
|
993
|
+
>
|
|
994
|
+
{run.data ? `Snoozed ${run.data.snoozed}` : "Snooze an hour"}
|
|
995
|
+
</button>
|
|
996
|
+
);
|
|
997
|
+
}
|
|
998
|
+
```
|
|
999
|
+
|
|
1000
|
+
## Row actions
|
|
1001
|
+
|
|
1002
|
+
Each row offers the actions its view declares for one row, as icon buttons at
|
|
1003
|
+
the end of the row or in a "more" menu, each only where its `when` holds for
|
|
1004
|
+
that row. They run exactly as a bulk action does on a selection of that one
|
|
1005
|
+
row: the same handlers, the same server paths. A view that declares none
|
|
1006
|
+
draws exactly what it drew before 0.5.0.
|
|
1007
|
+
|
|
1008
|
+
**What a row offers.** The three keys are udc's, read as udc-js reads them:
|
|
1009
|
+
`row_action_defs` (a list of `ActionDef`, the shape of `bulk_actions`) when
|
|
1010
|
+
the view has any, else the kinds of the legacy `row_actions: string[]`
|
|
1011
|
+
lifted to `{ kind }`. Each is filtered by its `when` for that row
|
|
1012
|
+
(`isActionEligible` of `@jsudc/core`: against `row.__meta.state` when the
|
|
1013
|
+
source sends one, else the row's fields). A row none of whose actions apply
|
|
1014
|
+
shows nothing.
|
|
1015
|
+
|
|
1016
|
+
**How they are drawn**, by `row_actions_display`:
|
|
1017
|
+
|
|
1018
|
+
- `inline` (the default, as in udc-js): the table gets a trailing column
|
|
1019
|
+
pinned at the end (after any column pinned right) with one icon button per
|
|
1020
|
+
action, labelled for screen readers and in a tooltip; an action whose
|
|
1021
|
+
`icon` is not known draws its label as a small text button. The column is
|
|
1022
|
+
sized from every declared action, with the `when`-gated ones counted as
|
|
1023
|
+
alternatives (only the widest), so it does not jump as rows change.
|
|
1024
|
+
- `menu`: one "more" button per row opening a dropdown, and the same menu on
|
|
1025
|
+
right-click anywhere on the row.
|
|
1026
|
+
|
|
1027
|
+
The cards draw the same actions as a "more" menu on each card (right-click
|
|
1028
|
+
opens it too), whatever the display. Kanban, tree, calendar, map and chart
|
|
1029
|
+
draw no row actions.
|
|
1030
|
+
|
|
1031
|
+
**The keyboard.** With row activation on, the focused row opens its menu from
|
|
1032
|
+
the context-menu key, Shift+F10 or `.` (`isRowMenuKey`); in the inline
|
|
1033
|
+
display the keys open the same actions as a menu. Arrow keys move in the
|
|
1034
|
+
menu, Enter runs, Escape closes, and the focus goes back to the row. Opened
|
|
1035
|
+
from the "more" button, the focus goes back to that button.
|
|
1036
|
+
|
|
1037
|
+
**A click on an action is the action's**: it neither activates the row
|
|
1038
|
+
(`onRowActivate`), nor follows its `row_link`, nor toggles its selection; a
|
|
1039
|
+
click anywhere else on the row does what it did.
|
|
1040
|
+
|
|
1041
|
+
**Running one** goes through [Running an action](#running-an-action) with
|
|
1042
|
+
`ids: [id]` and `rows: [row]`:
|
|
1043
|
+
|
|
1044
|
+
1. **A handler for its `kind`** (the view's `actions`, else `UdcProvider
|
|
1045
|
+
actions`): it gets the bulk context with `ids: [id]`, `rows: [row]` and
|
|
1046
|
+
`row`, the one row (absent when the bulk bar runs it). `clearSelection`
|
|
1047
|
+
clears the view's selection, if it selects.
|
|
1048
|
+
2. **`delete`**: a confirmation ("Delete this row?"), then `mutate_many`
|
|
1049
|
+
`delete` when the source has `capabilities.mutate_many`, else `mutate`
|
|
1050
|
+
`delete`. The row leaves the list and the selection.
|
|
1051
|
+
3. **A def with `set`**: an update with that patch (`mutate_many` or
|
|
1052
|
+
`mutate`), shown at once and put back if the call fails.
|
|
1053
|
+
4. **Anything else**: the server action the def's `action` names (default its
|
|
1054
|
+
`kind`) with `{ collection, ids: [id] }`.
|
|
1055
|
+
|
|
1056
|
+
As for a bulk action, the built-in paths ask first per `confirm`, a handler
|
|
1057
|
+
asks its own questions, and an error (or the row named in a `failed` answer)
|
|
1058
|
+
is shown as a toast. A row action names its button with the term
|
|
1059
|
+
`ACTION_<KIND>` of the collection's section, else `ACTIONS.<kind>`, else the
|
|
1060
|
+
def's `label`, else the kind made readable.
|
|
1061
|
+
|
|
1062
|
+
A mailbox whose rows mark themselves read through a patch and archive through
|
|
1063
|
+
the host's own endpoint, each hidden where it does not apply:
|
|
1064
|
+
|
|
1065
|
+
```yaml
|
|
1066
|
+
# The view of `messages`
|
|
1067
|
+
view:
|
|
1068
|
+
columns: [{ field: subject }, { field: from }, { field: received_at }]
|
|
1069
|
+
row_actions_display: inline # or `menu`
|
|
1070
|
+
row_action_defs:
|
|
1071
|
+
- kind: mark_read
|
|
1072
|
+
label: Mark read
|
|
1073
|
+
icon: lucide:mail-open
|
|
1074
|
+
set: { read: true } # no handler needed: an optimistic update
|
|
1075
|
+
when: { field: read, op: eq, value: false }
|
|
1076
|
+
- kind: archive
|
|
1077
|
+
label: Archive
|
|
1078
|
+
icon: lucide:archive
|
|
1079
|
+
when: { field: folder, op: neq, value: archive }
|
|
1080
|
+
```
|
|
1081
|
+
|
|
1082
|
+
```tsx
|
|
1083
|
+
import { UdcDataView } from "@jsudc/react";
|
|
1084
|
+
|
|
1085
|
+
export function Inbox() {
|
|
1086
|
+
return (
|
|
1087
|
+
<UdcDataView
|
|
1088
|
+
collection="messages"
|
|
1089
|
+
filter={{ field: "folder", op: "eq", value: "inbox" }}
|
|
1090
|
+
onRowActivate={(row) => openMessage(row.__meta.id)}
|
|
1091
|
+
actions={{
|
|
1092
|
+
// The same handler serves the bulk bar (`ids` of the selection, or `filter`) and the row
|
|
1093
|
+
// ("archive" on one row: `ids: [id]`, `rows: [row]`, `row`).
|
|
1094
|
+
archive: async ({ ids, filter, exceptIds, row, clearSelection }) => {
|
|
1095
|
+
await fetch("/api/mail/archive", {
|
|
1096
|
+
method: "POST",
|
|
1097
|
+
headers: { "content-type": "application/json" },
|
|
1098
|
+
body: JSON.stringify(ids ? { ids } : { filter, except_ids: exceptIds }),
|
|
1099
|
+
});
|
|
1100
|
+
if (!row) clearSelection();
|
|
1101
|
+
},
|
|
1102
|
+
}}
|
|
1103
|
+
/>
|
|
1104
|
+
);
|
|
1105
|
+
}
|
|
1106
|
+
```
|
|
1107
|
+
|
|
1108
|
+
An unread message in the inbox shows both; a read one only "Archive"; a read
|
|
1109
|
+
one already archived, none. Clicking "Mark read" shows the row read at once (and so
|
|
1110
|
+
"Mark read" goes from it); clicking the row itself still opens the message.
|
|
1111
|
+
|
|
1112
|
+
**In a host renderer.** `RendererProps.rowActions` (a `RowActions`, set when
|
|
1113
|
+
the view declares row actions) carries `display`, `defs` (every declared
|
|
1114
|
+
action, before `when`), `eligible(row)`, `label(def)`, `run(def, row)` (the
|
|
1115
|
+
path above; it shows its errors and does not reject) and `runningOn(id)`
|
|
1116
|
+
(the kind running on that row, else `null`). `RowActionsControls` with
|
|
1117
|
+
`useRowMenu()` draws the built-in buttons and menu; `rowMenuHandlers` gives a
|
|
1118
|
+
row element its menu key and right-click. The headless parts —
|
|
1119
|
+
`rowActionDefs(view)`, `rowActionsDisplay(view)`, `eligibleRowActions(defs,
|
|
1120
|
+
row)`, `isRowMenuKey(e)` — are in `@jsudc/react/headless`. A UI kit's
|
|
1121
|
+
`DropdownMenu` may take the optional `open` / `onOpenChange` and its content
|
|
1122
|
+
`onCloseAutoFocus` (the default kit does); a kit that ignores them still
|
|
1123
|
+
opens the menu from its trigger, but not from the keys or a right-click.
|
|
1124
|
+
|
|
1125
|
+
## Long lists
|
|
1126
|
+
|
|
1127
|
+
In infinite mode the table mounts only the rows in and near its viewport,
|
|
1128
|
+
however many pages are loaded: a mailbox scrolled through for thousands of
|
|
1129
|
+
messages keeps a few dozen `<tr>` in the page, not thousands. The rows
|
|
1130
|
+
outside the window are stood in for by spacer rows of their height, so the
|
|
1131
|
+
scrollbar, the scroll position and the sticky header behave as if every row
|
|
1132
|
+
were there. Rows have one height (the view's `row_height`, default 40 px),
|
|
1133
|
+
so the window is arithmetic: no dependency, no measuring of each row.
|
|
1134
|
+
|
|
1135
|
+
**When it applies.** Only in infinite mode (pages mode is never windowed)
|
|
1136
|
+
and, by default, only once **more than 200 rows** are loaded: a list at or
|
|
1137
|
+
under that draws exactly the markup it drew before 0.5.0. The `virtualize`
|
|
1138
|
+
prop of `UdcDataView` (and of `TableRenderer`) changes that:
|
|
1139
|
+
|
|
1140
|
+
| `virtualize` | Infinite mode windows its rows… |
|
|
1141
|
+
| ---------------------------------- | -------------------------------------------------- |
|
|
1142
|
+
| left out, or `{ enabled: "auto" }` | once more than `threshold` (200) rows are loaded |
|
|
1143
|
+
| `true` / `{ enabled: true }` | always, however few |
|
|
1144
|
+
| `false` / `{ enabled: false }` | never: every loaded row is mounted, as before |
|
|
1145
|
+
| `{ threshold: 500 }` | once more than 500 are loaded |
|
|
1146
|
+
| `{ overscan: 20 }` | with 20 rows mounted beyond each edge (default 10) |
|
|
1147
|
+
|
|
1148
|
+
```tsx
|
|
1149
|
+
import { UdcDataView } from "@jsudc/react";
|
|
1150
|
+
|
|
1151
|
+
// The mailbox: always infinite, always windowed (even a short folder), with a deeper overscan
|
|
1152
|
+
// for fast keyboard scrolling.
|
|
1153
|
+
export function Mailbox({ folder }: { folder: string }) {
|
|
1154
|
+
return (
|
|
1155
|
+
<UdcDataView
|
|
1156
|
+
collection="messages"
|
|
1157
|
+
filter={{ field: "folder", op: "eq", value: folder }}
|
|
1158
|
+
pagingMode="infinite"
|
|
1159
|
+
virtualize={{ enabled: true, overscan: 20 }}
|
|
1160
|
+
onRowActivate={(row) => openMessage(row.__meta.id)}
|
|
1161
|
+
/>
|
|
1162
|
+
);
|
|
1163
|
+
}
|
|
1164
|
+
```
|
|
1165
|
+
|
|
1166
|
+
With 5 000 messages loaded this mounts about 40 rows (the ~10 that show, 20
|
|
1167
|
+
above and 20 below); scrolling moves the window, and reaching the end of the
|
|
1168
|
+
loaded rows loads the next page as before.
|
|
1169
|
+
|
|
1170
|
+
**What keeps working across the window.**
|
|
1171
|
+
|
|
1172
|
+
- The sticky header, pinned columns and their shadows, column widths and
|
|
1173
|
+
horizontal scroll: the spacers span every column.
|
|
1174
|
+
- The infinite sentinel: it sits under the full height of the rows, so it
|
|
1175
|
+
comes into view at the end of the loaded rows and asks for the next page.
|
|
1176
|
+
- The keys of row activation: ArrowDown / ArrowUp / `j` / `k` onto a row
|
|
1177
|
+
outside the window scroll it in (to the nearest edge), mount it and focus
|
|
1178
|
+
it; Home and End go to the first and the last loaded row. A row is kept
|
|
1179
|
+
mounted, wherever it is, while it is the active row, holds the list's tab
|
|
1180
|
+
stop or has the focus, so it keeps the focus when it is scrolled away and
|
|
1181
|
+
back.
|
|
1182
|
+
- Selection: a shift-range and "select the page" are computed over the
|
|
1183
|
+
loaded rows, never the mounted ones, so a range spanning rows that were
|
|
1184
|
+
never drawn selects them all.
|
|
1185
|
+
- An open cell editor: its row stays mounted while the editor is open (the
|
|
1186
|
+
edit is neither committed nor cancelled by scrolling), and a row whose
|
|
1187
|
+
"more" menu is open stays mounted too.
|
|
1188
|
+
- Row actions, custom cells and lookups: a lookup column still makes one
|
|
1189
|
+
fetch for every loaded row, not one per window.
|
|
1190
|
+
- A refetch from the change feed keeps the scroll position: the window
|
|
1191
|
+
follows `scrollTop`, which a refetch of the same pages does not change.
|
|
1192
|
+
- `aria-rowcount` on the table is the loaded count and every mounted row
|
|
1193
|
+
carries its `aria-rowindex` (1-based, over the loaded rows), so a screen
|
|
1194
|
+
reader hears "row 2 501 of 5 000" for a row it could not otherwise place.
|
|
1195
|
+
|
|
1196
|
+
**Limits.** The browser's find-in-page (Ctrl / Cmd+F) sees only the mounted
|
|
1197
|
+
rows; search the list with the view's search box instead. Printing prints
|
|
1198
|
+
the window, not the list. Rows of variable height are not supported (a row
|
|
1199
|
+
taller than `row_height` is measured once and its height used for all), and
|
|
1200
|
+
the cards, kanban and tree renderers are not windowed.
|
|
1201
|
+
|
|
1202
|
+
**In a host renderer.** The arithmetic is in `@jsudc/react/headless`:
|
|
1203
|
+
`virtualizationApplies(virtualize, mode, count)`,
|
|
1204
|
+
`resolveVirtualization(virtualize)` (with `DEFAULT_VIRTUAL_THRESHOLD`,
|
|
1205
|
+
`DEFAULT_VIRTUAL_OVERSCAN`), `visibleRange`, `withOverscan`, `keepRange`,
|
|
1206
|
+
`bodySlices(count, range, pinned)` and the hook `useRowWindow`. A windowed
|
|
1207
|
+
list of your own passes `reveal(row, index)` to `useRowActivation`: the keys
|
|
1208
|
+
call it for a row that is not mounted, and the row takes the focus the
|
|
1209
|
+
moment its element attaches. `RendererProps.virtualize` carries the view's
|
|
1210
|
+
prop when the host set it.
|
|
1211
|
+
|
|
621
1212
|
## Custom cells
|
|
622
1213
|
|
|
623
1214
|
A column of the table can be drawn by a component of the host's. Register
|
|
@@ -775,7 +1366,7 @@ peer while the default kit is the fallback.
|
|
|
775
1366
|
Everything the components import that a host is likely to have too is a peer,
|
|
776
1367
|
so there is one copy of it in the bundle:
|
|
777
1368
|
|
|
778
|
-
- `@jsudc/core` ^0.
|
|
1369
|
+
- `@jsudc/core` ^0.5.0 — one copy of the protocol, shared with the host's
|
|
779
1370
|
own `UdcClient`;
|
|
780
1371
|
- `react`, `react-dom` ^19 — one React, or hooks break;
|
|
781
1372
|
- `@tanstack/react-query` ^5 — one `QueryClient` context, shared with the
|
|
@@ -1115,7 +1706,17 @@ registry and everything not tied to one renderer. Beyond the above:
|
|
|
1115
1706
|
`EmptyState` / `ErrorState` / `NoRendererState`; the `UdcQueryClientOptions` type;
|
|
1116
1707
|
the row activation `useRowActivation`, `rowActivationEnabled`, `ownsKeys`
|
|
1117
1708
|
and the `RowActivationProps` / `RowActivation` / `RowActivationRowProps` /
|
|
1118
|
-
`UseRowActivationOptions` types; the
|
|
1709
|
+
`UseRowActivationOptions` types; the selection `useRowSelection` with its
|
|
1710
|
+
pure operations and the `RowSelection` / `RowSelectionState` types; the bulk
|
|
1711
|
+
actions `UdcActionsProvider`, `useBulkActionHandlers`, `planBulkAction`,
|
|
1712
|
+
`bulkActionEligible`, `selectionTarget`, `MATCH_ALL` and the
|
|
1713
|
+
`BulkActionContext` / `BulkActionHandler` / `BulkActionHandlers` /
|
|
1714
|
+
`BulkActionPlan` types; the row actions `rowActionDefs`, `rowActionsDisplay`,
|
|
1715
|
+
`eligibleRowActions`, `isRowMenuKey`, `RowActionsControls`, `useRowMenu`,
|
|
1716
|
+
`rowMenuHandlers`, `rowActionsColumnWidth` and the `RowActions` /
|
|
1717
|
+
`RowActionsDisplay` / `RowMenuState` / `RowMenuVia` /
|
|
1718
|
+
`RowActionsControlsProps` / `RowMenuKeyEvent` types; the hooks `useUdcMutateMany`, `useUdcAction` and the
|
|
1719
|
+
cache helpers `applyToListRows`, `mutateManyTouches`, `callAction`; the cells `createCellRegistry`,
|
|
1119
1720
|
`cellComponent`, `mergeCellRegistries`, `UdcCellsProvider`, `useCellRegistry`
|
|
1120
1721
|
and the `CellProps` / `CellComponent` / `CellDefinition` / `CellRegistry`
|
|
1121
1722
|
types; `mergeMessages`, `makeT`,
|
|
@@ -1132,7 +1733,10 @@ bundles (`LUCIDE_ICONS`); and the zone helpers `allZones`, `offsetLabel`,
|
|
|
1132
1733
|
`UdcLookupBatch`, `LookupValue`, `useLookupLabels`, `useLookupOptions`,
|
|
1133
1734
|
`LookupSelectChip`, `LookupCombobox`, `UdcLinksProvider`, `useUdcLinks`,
|
|
1134
1735
|
`defaultUdcLinks`, `filterHref`, `followLink` (the hooks without markup are in
|
|
1135
|
-
`@jsudc/react/headless` too)
|
|
1736
|
+
`@jsudc/react/headless` too); the change feed: `useUdcChanges`,
|
|
1737
|
+
`useUdcChangeFeed`, `UdcChangeFeed`, `LiveIndicator` and the
|
|
1738
|
+
`UdcChangeFeedOptions` / `UdcChangeFeedStatus` / `UseUdcChangesOptions` /
|
|
1739
|
+
`UdcChangesResult` types (see [Live updates](#live-updates)).
|
|
1136
1740
|
|
|
1137
1741
|
The subpaths: one per renderer and `@jsudc/react/all` (see
|
|
1138
1742
|
[Renderers](#renderers)), `@jsudc/react/headless` (see [Headless](#headless)),
|