@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.
- package/README.md +589 -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 +42 -7
- 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 +69 -8
- 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 +128 -0
- package/dist/i18n/translations.js.map +1 -1
- package/dist/index.d.ts +9 -1
- 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/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 +281 -123
- 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 +94 -0
- package/dist/udc/changeFeed.js +250 -0
- package/dist/udc/changeFeed.js.map +1 -0
- package/dist/udc/changes.d.ts +34 -0
- package/dist/udc/changes.js +79 -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 +113 -10
- 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 +17 -2
- package/dist/udc/provider.js +18 -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/dist/lookup/options.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useUdcChangesMany } from "../udc/changes.js";
|
|
1
2
|
import { useUdcClient } from "../udc/client.js";
|
|
2
3
|
import { udcKeys } from "../udc/keys.js";
|
|
3
4
|
import { lookupLabel } from "./label.js";
|
|
@@ -30,6 +31,8 @@ function useLookupOptions(lookup, search, opts = {}) {
|
|
|
30
31
|
label_field: ""
|
|
31
32
|
};
|
|
32
33
|
const filter = optionsFilter(target, search);
|
|
34
|
+
const enabled = (opts.enabled ?? true) && lookup !== void 0;
|
|
35
|
+
useUdcChangesMany([target.collection], { enabled });
|
|
33
36
|
const q = useQuery({
|
|
34
37
|
queryKey: udcKeys.lookupOptions(target.collection, target.label_field, search.trim()),
|
|
35
38
|
queryFn: ({ signal }) => client.list({
|
|
@@ -41,7 +44,7 @@ function useLookupOptions(lookup, search, opts = {}) {
|
|
|
41
44
|
}],
|
|
42
45
|
page: { limit: 50 }
|
|
43
46
|
}, { signal }),
|
|
44
|
-
enabled
|
|
47
|
+
enabled,
|
|
45
48
|
staleTime: 6e4,
|
|
46
49
|
placeholderData: keepPreviousData
|
|
47
50
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","names":[],"sources":["../../src/lookup/options.ts"],"sourcesContent":["import { type FilterNode, type LookupDef, lookupKeyOf, type Row } from \"@jsudc/core\";\nimport { keepPreviousData, useQuery } from \"@tanstack/react-query\";\nimport { useUdcClient } from \"../udc/client.js\";\nimport { udcKeys } from \"../udc/keys.js\";\nimport { lookupLabel } from \"./label.js\";\nimport { keyString } from \"./useUdcLookup.js\";\n\n/** How many target rows a picker lists; above this it searches by `label_field` instead. */\nexport const LOOKUP_OPTIONS_LIMIT = 50;\n\nexport interface LookupOption {\n key: string;\n /** The stored key as the target row has it (a number stays a number). */\n raw: unknown;\n label: string;\n row: Row;\n}\n\nexport interface LookupOptionsResult {\n options: LookupOption[];\n /** The target's row count for this search; more than `LOOKUP_OPTIONS_LIMIT` means \"type to narrow\". */\n total: number | null;\n isLoading: boolean;\n error: Error | null;\n}\n\n/** The search condition of a picker: `label_field contains <search>`, case-insensitive. */\nexport function optionsFilter(lookup: LookupDef, search: string): FilterNode | undefined {\n const s = search.trim();\n return s\n ? { field: lookup.label_field, op: \"contains\", value: s, case_insensitive: true }\n : undefined;\n}\n\n/**\n * The first `LOOKUP_OPTIONS_LIMIT` rows of a lookup's target, by\n * `label_field`, narrowed by `search` (`contains` on `label_field`). A\n * picker shows its search box once `total` (of the empty search) is larger\n * than the limit.\n */\nexport function useLookupOptions(\n lookup: LookupDef | undefined,\n search: string,\n opts: { enabled?: boolean } = {},\n): LookupOptionsResult {\n const client = useUdcClient();\n const target = lookup ?? { collection: \"\", label_field: \"\" };\n const filter = optionsFilter(target, search);\n const q = useQuery({\n queryKey: udcKeys.lookupOptions(target.collection, target.label_field, search.trim()),\n queryFn: ({ signal }) =>\n client.list(\n {\n collection: target.collection,\n ...(filter ? { filter } : {}),\n sort: [{ field: target.label_field, dir: \"asc\" }],\n page: { limit: LOOKUP_OPTIONS_LIMIT },\n },\n { signal },\n ),\n enabled
|
|
1
|
+
{"version":3,"file":"options.js","names":[],"sources":["../../src/lookup/options.ts"],"sourcesContent":["import { type FilterNode, type LookupDef, lookupKeyOf, type Row } from \"@jsudc/core\";\nimport { keepPreviousData, useQuery } from \"@tanstack/react-query\";\nimport { useUdcChangesMany } from \"../udc/changes.js\";\nimport { useUdcClient } from \"../udc/client.js\";\nimport { udcKeys } from \"../udc/keys.js\";\nimport { lookupLabel } from \"./label.js\";\nimport { keyString } from \"./useUdcLookup.js\";\n\n/** How many target rows a picker lists; above this it searches by `label_field` instead. */\nexport const LOOKUP_OPTIONS_LIMIT = 50;\n\nexport interface LookupOption {\n key: string;\n /** The stored key as the target row has it (a number stays a number). */\n raw: unknown;\n label: string;\n row: Row;\n}\n\nexport interface LookupOptionsResult {\n options: LookupOption[];\n /** The target's row count for this search; more than `LOOKUP_OPTIONS_LIMIT` means \"type to narrow\". */\n total: number | null;\n isLoading: boolean;\n error: Error | null;\n}\n\n/** The search condition of a picker: `label_field contains <search>`, case-insensitive. */\nexport function optionsFilter(lookup: LookupDef, search: string): FilterNode | undefined {\n const s = search.trim();\n return s\n ? { field: lookup.label_field, op: \"contains\", value: s, case_insensitive: true }\n : undefined;\n}\n\n/**\n * The first `LOOKUP_OPTIONS_LIMIT` rows of a lookup's target, by\n * `label_field`, narrowed by `search` (`contains` on `label_field`). A\n * picker shows its search box once `total` (of the empty search) is larger\n * than the limit.\n */\nexport function useLookupOptions(\n lookup: LookupDef | undefined,\n search: string,\n opts: { enabled?: boolean } = {},\n): LookupOptionsResult {\n const client = useUdcClient();\n const target = lookup ?? { collection: \"\", label_field: \"\" };\n const filter = optionsFilter(target, search);\n const enabled = (opts.enabled ?? true) && lookup !== undefined;\n useUdcChangesMany([target.collection], { enabled });\n const q = useQuery({\n queryKey: udcKeys.lookupOptions(target.collection, target.label_field, search.trim()),\n queryFn: ({ signal }) =>\n client.list(\n {\n collection: target.collection,\n ...(filter ? { filter } : {}),\n sort: [{ field: target.label_field, dir: \"asc\" }],\n page: { limit: LOOKUP_OPTIONS_LIMIT },\n },\n { signal },\n ),\n enabled,\n staleTime: 60_000,\n placeholderData: keepPreviousData,\n });\n const options = (q.data?.rows ?? []).map((row) => {\n const raw = lookupKeyOf(row, target);\n const key = keyString(raw);\n return { key, raw, label: lookupLabel(row, target) ?? key, row };\n });\n return { options, total: q.data?.total ?? null, isLoading: q.isLoading, error: q.error };\n}\n"],"mappings":";;;;;;;;;AASA,IAAa,uBAAuB;;AAmBpC,SAAgB,cAAc,QAAmB,QAAwC;CACvF,MAAM,IAAI,OAAO,KAAK;CACtB,OAAO,IACH;EAAE,OAAO,OAAO;EAAa,IAAI;EAAY,OAAO;EAAG,kBAAkB;CAAK,IAC9E,KAAA;AACN;;;;;;;AAQA,SAAgB,iBACd,QACA,QACA,OAA8B,CAAC,GACV;CACrB,MAAM,SAAS,aAAa;CAC5B,MAAM,SAAS,UAAU;EAAE,YAAY;EAAI,aAAa;CAAG;CAC3D,MAAM,SAAS,cAAc,QAAQ,MAAM;CAC3C,MAAM,WAAW,KAAK,WAAW,SAAS,WAAW,KAAA;CACrD,kBAAkB,CAAC,OAAO,UAAU,GAAG,EAAE,QAAQ,CAAC;CAClD,MAAM,IAAI,SAAS;EACjB,UAAU,QAAQ,cAAc,OAAO,YAAY,OAAO,aAAa,OAAO,KAAK,CAAC;EACpF,UAAU,EAAE,aACV,OAAO,KACL;GACE,YAAY,OAAO;GACnB,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;GAC3B,MAAM,CAAC;IAAE,OAAO,OAAO;IAAa,KAAK;GAAM,CAAC;GAChD,MAAM,EAAE,OAAA,GAA4B;EACtC,GACA,EAAE,OAAO,CACX;EACF;EACA,WAAW;EACX,iBAAiB;CACnB,CAAC;CAMD,OAAO;EAAE,UALQ,EAAE,MAAM,QAAQ,CAAC,EAAA,CAAG,KAAK,QAAQ;GAChD,MAAM,MAAM,YAAY,KAAK,MAAM;GACnC,MAAM,MAAM,UAAU,GAAG;GACzB,OAAO;IAAE;IAAK;IAAK,OAAO,YAAY,KAAK,MAAM,KAAK;IAAK;GAAI;EACjE,CACS;EAAS,OAAO,EAAE,MAAM,SAAS;EAAM,WAAW,EAAE;EAAW,OAAO,EAAE;CAAM;AACzF"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { useUdcChangesMany } from "../udc/changes.js";
|
|
1
2
|
import { useUdcClient } from "../udc/client.js";
|
|
2
3
|
import { udcKeys } from "../udc/keys.js";
|
|
3
|
-
import { useMemo } from "react";
|
|
4
4
|
import { MAX_PAGE_LIMIT, lookupKeyField, lookupKeyOf, lookupKeysFilter } from "@jsudc/core";
|
|
5
|
+
import { useMemo } from "react";
|
|
5
6
|
import { keepPreviousData, useQueries, useQuery } from "@tanstack/react-query";
|
|
6
7
|
// src/lookup/useUdcLookup.ts
|
|
7
8
|
/** A key as the maps below hold it: `7` and `"7"` are one key, as on the server. */
|
|
@@ -70,10 +71,14 @@ function result(data, isLoading, error) {
|
|
|
70
71
|
* name (keys are ids) or a field's `lookup` block.
|
|
71
72
|
*/
|
|
72
73
|
function useUdcLookup(target, keys, opts = {}) {
|
|
73
|
-
const
|
|
74
|
+
const client = useUdcClient();
|
|
75
|
+
const lookup = asLookup(target);
|
|
76
|
+
const q = lookupQuery(client, lookup, useMemo(() => lookupKeys(keys), [keys]));
|
|
77
|
+
const enabled = q.enabled && (opts.enabled ?? true);
|
|
78
|
+
useUdcChangesMany([lookup.collection], { enabled });
|
|
74
79
|
const res = useQuery({
|
|
75
80
|
...q,
|
|
76
|
-
enabled
|
|
81
|
+
enabled
|
|
77
82
|
});
|
|
78
83
|
return result(res.data, res.isLoading, res.error);
|
|
79
84
|
}
|
|
@@ -82,6 +87,7 @@ function useUdcLookups(requests) {
|
|
|
82
87
|
const client = useUdcClient();
|
|
83
88
|
const queries = useMemo(() => requests.map((r) => lookupQuery(client, r.lookup, lookupKeys(r.keys))), [client, requests]);
|
|
84
89
|
const results = useQueries({ queries });
|
|
90
|
+
useUdcChangesMany(requests.filter((_, i) => queries[i]?.enabled).map((r) => r.lookup.collection));
|
|
85
91
|
return useMemo(() => {
|
|
86
92
|
const out = /* @__PURE__ */ new Map();
|
|
87
93
|
requests.forEach((r, i) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUdcLookup.js","names":[],"sources":["../../src/lookup/useUdcLookup.ts"],"sourcesContent":["import {\n type FilterNode,\n type LookupDef,\n lookupKeyField,\n lookupKeyOf,\n lookupKeysFilter,\n MAX_PAGE_LIMIT,\n type Row,\n} from \"@jsudc/core\";\nimport type { UdcClient } from \"@jsudc/core/client\";\nimport { keepPreviousData, useQueries, useQuery } from \"@tanstack/react-query\";\nimport { useMemo } from \"react\";\nimport { useUdcClient } from \"../udc/client.js\";\nimport { udcKeys } from \"../udc/keys.js\";\n\n/** A key as the maps below hold it: `7` and `\"7\"` are one key, as on the server. */\nexport const keyString = (key: unknown): string =>\n typeof key === \"string\" ? key : typeof key === \"number\" ? String(key) : JSON.stringify(key);\n\nconst isKey = (v: unknown): v is string | number =>\n (typeof v === \"string\" && v !== \"\") || (typeof v === \"number\" && Number.isFinite(v));\n\n/** The distinct keys of some lookup values (each one key or a list), as strings, in order of appearance. */\nexport function valueKeys(values: readonly unknown[]): string[] {\n const out = new Set<string>();\n for (const v of values) {\n for (const k of Array.isArray(v) ? v : [v]) if (isKey(k)) out.add(keyString(k));\n }\n return [...out];\n}\n\n/** `valueKeys`, sorted: what a lookup query is keyed and asked by. */\nexport function lookupKeys(values: readonly unknown[]): string[] {\n return valueKeys(values).sort();\n}\n\n/** `string` (a collection, keyed by id) or a lookup block, as a lookup block. */\nexport function asLookup(target: string | LookupDef): LookupDef {\n return typeof target === \"string\" ? { collection: target, label_field: \"\" } : target;\n}\n\n/** The target rows of a lookup, keyed by `keyString` of their key. */\nexport type LookupRows = ReadonlyMap<string, Row>;\n\n/** `list` the target rows of `keys`, one call per 1000 keys (the page limit). */\nexport async function fetchLookupRows(\n client: UdcClient,\n lookup: LookupDef,\n keys: readonly string[],\n signal?: AbortSignal,\n): Promise<Map<string, Row>> {\n const out = new Map<string, Row>();\n for (let i = 0; i < keys.length; i += MAX_PAGE_LIMIT) {\n const chunk = keys.slice(i, i + MAX_PAGE_LIMIT);\n const filter: FilterNode = lookupKeysFilter(lookup, chunk);\n const res = await client.list(\n { collection: lookup.collection, filter, page: { limit: chunk.length } },\n signal ? { signal } : undefined,\n );\n for (const row of res.rows) out.set(keyString(lookupKeyOf(row, lookup)), row);\n }\n return out;\n}\n\n/**\n * The query of one lookup: `[\"udc\", \"lookup\", collection, sortedKeys]` (and\n * the key field when it is not the id), one batch `list` with an `in` filter.\n */\nexport function lookupQuery(client: UdcClient, lookup: LookupDef, keys: readonly string[]) {\n const field = lookupKeyField(lookup);\n return {\n queryKey: udcKeys.lookup(lookup.collection, keys, field),\n queryFn: ({ signal }: { signal?: AbortSignal }) =>\n fetchLookupRows(client, lookup, keys, signal),\n enabled: keys.length > 0 && lookup.collection !== \"\",\n staleTime: 60_000,\n // While the next set of keys loads (a new page arrived), keep showing the labels already known.\n placeholderData: keepPreviousData,\n };\n}\n\nexport interface UdcLookupResult {\n rows: LookupRows;\n /** The target row of `key`, once loaded. */\n row: (key: unknown) => Row | undefined;\n isLoading: boolean;\n error: Error | null;\n}\n\nconst EMPTY: LookupRows = new Map();\n\nfunction result(data: LookupRows | undefined, isLoading: boolean, error: Error | null) {\n const rows = data ?? EMPTY;\n return { rows, row: (key: unknown) => rows.get(keyString(key)), isLoading, error };\n}\n\n/**\n * The rows of `target` whose key is in `keys`: one `list` with an `in`\n * filter over the key field (the row id without a `key_field`), cached in\n * TanStack Query by collection and sorted keys. `target` is a collection\n * name (keys are ids) or a field's `lookup` block.\n */\nexport function useUdcLookup(\n target: string | LookupDef,\n keys: readonly unknown[],\n opts: { enabled?: boolean } = {},\n): UdcLookupResult {\n const client = useUdcClient();\n const lookup = asLookup(target);\n const sorted = useMemo(() => lookupKeys(keys), [keys]);\n const q = lookupQuery(client, lookup, sorted);\n const
|
|
1
|
+
{"version":3,"file":"useUdcLookup.js","names":[],"sources":["../../src/lookup/useUdcLookup.ts"],"sourcesContent":["import {\n type FilterNode,\n type LookupDef,\n lookupKeyField,\n lookupKeyOf,\n lookupKeysFilter,\n MAX_PAGE_LIMIT,\n type Row,\n} from \"@jsudc/core\";\nimport type { UdcClient } from \"@jsudc/core/client\";\nimport { keepPreviousData, useQueries, useQuery } from \"@tanstack/react-query\";\nimport { useMemo } from \"react\";\nimport { useUdcChangesMany } from \"../udc/changes.js\";\nimport { useUdcClient } from \"../udc/client.js\";\nimport { udcKeys } from \"../udc/keys.js\";\n\n/** A key as the maps below hold it: `7` and `\"7\"` are one key, as on the server. */\nexport const keyString = (key: unknown): string =>\n typeof key === \"string\" ? key : typeof key === \"number\" ? String(key) : JSON.stringify(key);\n\nconst isKey = (v: unknown): v is string | number =>\n (typeof v === \"string\" && v !== \"\") || (typeof v === \"number\" && Number.isFinite(v));\n\n/** The distinct keys of some lookup values (each one key or a list), as strings, in order of appearance. */\nexport function valueKeys(values: readonly unknown[]): string[] {\n const out = new Set<string>();\n for (const v of values) {\n for (const k of Array.isArray(v) ? v : [v]) if (isKey(k)) out.add(keyString(k));\n }\n return [...out];\n}\n\n/** `valueKeys`, sorted: what a lookup query is keyed and asked by. */\nexport function lookupKeys(values: readonly unknown[]): string[] {\n return valueKeys(values).sort();\n}\n\n/** `string` (a collection, keyed by id) or a lookup block, as a lookup block. */\nexport function asLookup(target: string | LookupDef): LookupDef {\n return typeof target === \"string\" ? { collection: target, label_field: \"\" } : target;\n}\n\n/** The target rows of a lookup, keyed by `keyString` of their key. */\nexport type LookupRows = ReadonlyMap<string, Row>;\n\n/** `list` the target rows of `keys`, one call per 1000 keys (the page limit). */\nexport async function fetchLookupRows(\n client: UdcClient,\n lookup: LookupDef,\n keys: readonly string[],\n signal?: AbortSignal,\n): Promise<Map<string, Row>> {\n const out = new Map<string, Row>();\n for (let i = 0; i < keys.length; i += MAX_PAGE_LIMIT) {\n const chunk = keys.slice(i, i + MAX_PAGE_LIMIT);\n const filter: FilterNode = lookupKeysFilter(lookup, chunk);\n const res = await client.list(\n { collection: lookup.collection, filter, page: { limit: chunk.length } },\n signal ? { signal } : undefined,\n );\n for (const row of res.rows) out.set(keyString(lookupKeyOf(row, lookup)), row);\n }\n return out;\n}\n\n/**\n * The query of one lookup: `[\"udc\", \"lookup\", collection, sortedKeys]` (and\n * the key field when it is not the id), one batch `list` with an `in` filter.\n */\nexport function lookupQuery(client: UdcClient, lookup: LookupDef, keys: readonly string[]) {\n const field = lookupKeyField(lookup);\n return {\n queryKey: udcKeys.lookup(lookup.collection, keys, field),\n queryFn: ({ signal }: { signal?: AbortSignal }) =>\n fetchLookupRows(client, lookup, keys, signal),\n enabled: keys.length > 0 && lookup.collection !== \"\",\n staleTime: 60_000,\n // While the next set of keys loads (a new page arrived), keep showing the labels already known.\n placeholderData: keepPreviousData,\n };\n}\n\nexport interface UdcLookupResult {\n rows: LookupRows;\n /** The target row of `key`, once loaded. */\n row: (key: unknown) => Row | undefined;\n isLoading: boolean;\n error: Error | null;\n}\n\nconst EMPTY: LookupRows = new Map();\n\nfunction result(data: LookupRows | undefined, isLoading: boolean, error: Error | null) {\n const rows = data ?? EMPTY;\n return { rows, row: (key: unknown) => rows.get(keyString(key)), isLoading, error };\n}\n\n/**\n * The rows of `target` whose key is in `keys`: one `list` with an `in`\n * filter over the key field (the row id without a `key_field`), cached in\n * TanStack Query by collection and sorted keys. `target` is a collection\n * name (keys are ids) or a field's `lookup` block.\n */\nexport function useUdcLookup(\n target: string | LookupDef,\n keys: readonly unknown[],\n opts: { enabled?: boolean } = {},\n): UdcLookupResult {\n const client = useUdcClient();\n const lookup = asLookup(target);\n const sorted = useMemo(() => lookupKeys(keys), [keys]);\n const q = lookupQuery(client, lookup, sorted);\n const enabled = q.enabled && (opts.enabled ?? true);\n // A change of the target collection may change the labels shown (the provider's change feed).\n useUdcChangesMany([lookup.collection], { enabled });\n const res = useQuery({ ...q, enabled });\n return result(res.data, res.isLoading, res.error);\n}\n\nexport interface LookupRequest {\n /** What the result is filed under (the field name). */\n id: string;\n lookup: LookupDef;\n keys: readonly unknown[];\n}\n\n/** `useUdcLookup` for several lookups at once (one query each), keyed by request id. */\nexport function useUdcLookups(requests: readonly LookupRequest[]): Map<string, UdcLookupResult> {\n const client = useUdcClient();\n const queries = useMemo(\n () => requests.map((r) => lookupQuery(client, r.lookup, lookupKeys(r.keys))),\n [client, requests],\n );\n const results = useQueries({ queries });\n useUdcChangesMany(requests.filter((_, i) => queries[i]?.enabled).map((r) => r.lookup.collection));\n return useMemo(() => {\n const out = new Map<string, UdcLookupResult>();\n requests.forEach((r, i) => {\n const res = results[i];\n out.set(r.id, result(res?.data, res?.isLoading ?? false, res?.error ?? null));\n });\n return out;\n }, [requests, results]);\n}\n"],"mappings":";;;;;;;;AAiBA,IAAa,aAAa,QACxB,OAAO,QAAQ,WAAW,MAAM,OAAO,QAAQ,WAAW,OAAO,GAAG,IAAI,KAAK,UAAU,GAAG;AAE5F,IAAM,SAAS,MACZ,OAAO,MAAM,YAAY,MAAM,MAAQ,OAAO,MAAM,YAAY,OAAO,SAAS,CAAC;;AAGpF,SAAgB,UAAU,QAAsC;CAC9D,MAAM,sBAAM,IAAI,IAAY;CAC5B,KAAK,MAAM,KAAK,QACd,KAAK,MAAM,KAAK,MAAM,QAAQ,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,MAAM,CAAC,GAAG,IAAI,IAAI,UAAU,CAAC,CAAC;CAEhF,OAAO,CAAC,GAAG,GAAG;AAChB;;AAGA,SAAgB,WAAW,QAAsC;CAC/D,OAAO,UAAU,MAAM,CAAC,CAAC,KAAK;AAChC;;AAGA,SAAgB,SAAS,QAAuC;CAC9D,OAAO,OAAO,WAAW,WAAW;EAAE,YAAY;EAAQ,aAAa;CAAG,IAAI;AAChF;;AAMA,eAAsB,gBACpB,QACA,QACA,MACA,QAC2B;CAC3B,MAAM,sBAAM,IAAI,IAAiB;CACjC,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK,g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AAUA,SAAgB,cAAc,UAAkE;CAC9F,MAAM,SAAS,aAAa;CAC5B,MAAM,UAAU,cACR,SAAS,KAAK,MAAM,YAAY,QAAQ,EAAE,QAAQ,WAAW,EAAE,IAAI,CAAC,CAAC,GAC3E,CAAC,QAAQ,QAAQ,CACnB;CACA,MAAM,UAAU,WAAW,EAAE,QAAQ,CAAC;CACtC,kBAAkB,SAAS,QAAQ,GAAG,MAAM,QAAQ,EAAE,EAAE,OAAO,CAAC,CAAC,KAAK,MAAM,EAAE,OAAO,UAAU,CAAC;CAChG,OAAO,cAAc;EACnB,MAAM,sBAAM,IAAI,IAA6B;EAC7C,SAAS,SAAS,GAAG,MAAM;GACzB,MAAM,MAAM,QAAQ;GACpB,IAAI,IAAI,EAAE,IAAI,OAAO,KAAK,MAAM,KAAK,aAAa,OAAO,KAAK,SAAS,IAAI,CAAC;EAC9E,CAAC;EACD,OAAO;CACT,GAAG,CAAC,UAAU,OAAO,CAAC;AACxB"}
|
package/dist/map/MapRenderer.js
CHANGED
|
@@ -61,7 +61,7 @@ function MapRenderer(props) {
|
|
|
61
61
|
opts
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
|
-
function MapView({ collection, describe, filter, sort, filtered, onClearFilters, onCount, opts }) {
|
|
64
|
+
function MapView({ collection, describe, filter, listSearch, sort, filtered, onClearFilters, onCount, opts }) {
|
|
65
65
|
const { Skeleton } = useUiKit();
|
|
66
66
|
const { t } = useI18n();
|
|
67
67
|
const q = useUdcAllRows({
|
|
@@ -70,7 +70,8 @@ function MapView({ collection, describe, filter, sort, filtered, onClearFilters,
|
|
|
70
70
|
sort,
|
|
71
71
|
capabilities: describe.capabilities,
|
|
72
72
|
max: opts.max_rows,
|
|
73
|
-
refetchInterval: describe.view.refresh_interval_ms
|
|
73
|
+
refetchInterval: describe.view.refresh_interval_ms,
|
|
74
|
+
search: listSearch
|
|
74
75
|
});
|
|
75
76
|
const rowColor = describe.view.row_color;
|
|
76
77
|
const markers = useMemo(() => toMarkers(q.rows, opts, rowColor), [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapRenderer.js","names":[],"sources":["../../src/map/MapRenderer.tsx"],"sourcesContent":["import \"leaflet/dist/leaflet.css\";\nimport type { DescribeResponse, MapOptions, Row } from \"@jsudc/core\";\nimport L from \"leaflet\";\nimport { Maximize } from \"lucide-react\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { tableSection, useI18n } from \"../i18n/i18n.js\";\nimport { AllRowsStatus } from \"../renderers/AllRowsStatus.js\";\nimport type { RendererProps } from \"../renderers/types.js\";\nimport { CellValue } from \"../table/cells.js\";\nimport { EmptyState, ErrorState } from \"../table/states.js\";\nimport { useUdcAllRows } from \"../udc/hooks.js\";\nimport { useUiKit } from \"../ui-kit/context.js\";\nimport {\n airplaneHtml,\n boundsOf,\n initialView,\n type MapMarker,\n regionAt,\n regionById,\n toMarkers,\n trailMarkers,\n} from \"./model.js\";\n\nconst OSM_TILES = \"https://tile.openstreetmap.org/{z}/{x}/{y}.png\";\nconst OSM_ATTRIBUTION =\n '© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors';\nconst FIT_PADDING: L.PointExpression = [32, 32];\n/** Fitting a single marker (or a tight cluster) should not zoom to a street. */\nconst FIT_MAX_ZOOM = 12;\n\n/** Frame every marker (no-op without one). */\nfunction fitMarkers(map: L.Map | null, list: readonly MapMarker[], animate: boolean) {\n const bounds = boundsOf(list);\n if (bounds && map)\n map.fitBounds(bounds, { padding: FIT_PADDING, maxZoom: FIT_MAX_ZOOM, animate });\n}\n\n/** A marker on the map: a circle, or an aeroplane (a divIcon) turned along its track. */\ntype MarkerLayer = L.CircleMarker | L.Marker;\n\nconst isPlane = (layer: MarkerLayer): layer is L.Marker => layer instanceof L.Marker;\n\n/** The element a test and the selection styles read: the circle's path, the plane's icon. */\nconst markerElement = (layer: MarkerLayer): Element | undefined =>\n isPlane(layer) ? layer.getElement() : layer.getElement();\n\nfunction planeIcon(m: MapMarker, size: number): L.DivIcon {\n return L.divIcon({\n html: airplaneHtml(m.rotation ?? 0, size),\n // No leaflet-div-icon: its white box and border would frame the plane.\n className: `udc-map-plane tone-${m.tone}`,\n iconSize: [size, size],\n iconAnchor: [size / 2, size / 2],\n });\n}\n\n/** Turn and recolour a plane in place: its element (and a hover on it) stays. */\nfunction updatePlane(layer: L.Marker, m: MapMarker) {\n const el = layer.getElement();\n if (!el) return;\n for (const c of [...el.classList]) if (c.startsWith(\"tone-\")) el.classList.remove(c);\n el.classList.add(`tone-${m.tone}`);\n el.setAttribute(\"data-rotation\", String(m.rotation ?? 0));\n const glyph = el.querySelector<HTMLElement>(\".udc-map-plane-glyph\");\n if (glyph) glyph.style.transform = `rotate(${m.rotation ?? 0}deg)`;\n}\n\n/** The `map` tab: every row with a position as a circle (or an aeroplane), over OpenStreetMap tiles. */\nexport function MapRenderer(props: RendererProps) {\n const opts = props.describe.view.map_options;\n const { t } = useI18n();\n if (!opts) {\n return (\n <div\n className=\"udc:p-8 udc:text-center udc:text-sm udc:text-muted-foreground\"\n data-testid=\"map-missing\"\n >\n {t(\"APP\", \"MAP_NO_OPTIONS\")}\n </div>\n );\n }\n return <MapView {...props} opts={opts} />;\n}\n\n/** The view a toolbar and a test read: centre to 4 decimals and zoom. */\ninterface ViewState {\n center: [number, number];\n zoom: number;\n}\n\nfunction MapView({\n collection,\n describe,\n filter,\n sort,\n filtered,\n onClearFilters,\n onCount,\n opts,\n}: RendererProps & { opts: MapOptions }) {\n const { Skeleton } = useUiKit();\n const { t } = useI18n();\n const q = useUdcAllRows({\n collection,\n filter,\n sort,\n capabilities: describe.capabilities,\n max: opts.max_rows,\n refetchInterval: describe.view.refresh_interval_ms,\n });\n const rowColor = describe.view.row_color;\n const markers = useMemo(() => toMarkers(q.rows, opts, rowColor), [q.rows, opts, rowColor]);\n\n useEffect(() => {\n onCount(\n q.total === null\n ? null\n : {\n shown: markers.length,\n total: q.total,\n unit: \"map\",\n fetchedAt: q.fetchedAt,\n stale: q.stale,\n },\n );\n }, [onCount, markers.length, q.total, q.fetchedAt, q.stale]);\n useEffect(() => () => onCount(null), [onCount]);\n\n // --- the Leaflet map: one per mount -----------------------------------------------\n const containerRef = useRef<HTMLElement>(null);\n const mapRef = useRef<L.Map | null>(null);\n const layerRef = useRef<L.LayerGroup | null>(null);\n const trailLayerRef = useRef<L.LayerGroup | null>(null);\n const trailRendererRef = useRef<L.Renderer | null>(null);\n const popupRef = useRef<L.Popup | null>(null);\n const byId = useRef(new Map<string, MarkerLayer>());\n const optsRef = useRef(opts);\n optsRef.current = opts;\n const [popupEl] = useState(() => document.createElement(\"div\"));\n const [view, setView] = useState<ViewState>(() => initialView(opts));\n const [selected, setSelected] = useState<string | null>(null);\n const [hovered, setHovered] = useState<string | null>(null);\n\n useEffect(() => {\n const el = containerRef.current;\n if (!el) return;\n const start = initialView(optsRef.current);\n const map = L.map(el, { center: start.center, zoom: start.zoom, worldCopyJump: true });\n L.tileLayer(OSM_TILES, { attribution: OSM_ATTRIBUTION, maxZoom: 19 }).addTo(map);\n // Trails under every marker (circles are in the overlay pane, z 400; planes above it).\n map.createPane(\"udc-trails\").style.zIndex = \"350\";\n trailRendererRef.current = L.svg({ pane: \"udc-trails\" });\n trailLayerRef.current = L.layerGroup().addTo(map);\n layerRef.current = L.layerGroup().addTo(map);\n popupRef.current = L.popup({ className: \"udc-map-popup\", maxWidth: 320, minWidth: 200 });\n popupRef.current.setContent(popupEl);\n map.on(\"moveend\", () => {\n const c = map.getCenter();\n const round = (x: number) => Math.round(x * 1e4) / 1e4;\n setView({ center: [round(c.lat), round(c.lng)], zoom: map.getZoom() });\n });\n // Closed by its button, Escape or a click on the map: nothing is selected any more.\n map.on(\"popupclose\", (e) => {\n if (e.popup === popupRef.current) setSelected(null);\n });\n mapRef.current = map;\n const resize = new ResizeObserver(() => map.invalidateSize());\n resize.observe(el);\n return () => {\n resize.disconnect();\n map.remove();\n mapRef.current = null;\n layerRef.current = null;\n trailLayerRef.current = null;\n trailRendererRef.current = null;\n popupRef.current = null;\n byId.current.clear();\n };\n }, [popupEl]);\n\n // --- markers, kept by id: a poll moves them in place ---------------------------------\n const fitted = useRef(false);\n useEffect(() => {\n const layer = layerRef.current;\n if (!layer) return;\n const size = optsRef.current.icon_size;\n const seen = new Set<string>();\n for (const m of markers) {\n seen.add(m.id);\n const plane = m.rotation !== null;\n let marker = byId.current.get(m.id);\n // A row that gained or lost its track changes kind: drawn anew.\n if (marker && isPlane(marker) !== plane) {\n layer.removeLayer(marker);\n marker = undefined;\n }\n if (marker) {\n marker.setLatLng([m.lat, m.lng]);\n if (isPlane(marker)) updatePlane(marker, m);\n else {\n marker.setRadius(m.radius);\n const path = marker.getElement();\n path?.setAttribute(\"class\", `leaflet-interactive udc-map-marker tone-${m.tone}`);\n }\n continue;\n }\n const id = m.id;\n marker = plane\n ? L.marker([m.lat, m.lng], {\n icon: planeIcon(m, size),\n keyboard: false,\n bubblingMouseEvents: false,\n })\n : L.circleMarker([m.lat, m.lng], {\n radius: m.radius,\n weight: 1.5,\n fillOpacity: 0.4,\n // The colour comes from the theme's tokens in index.css, by tone.\n className: `udc-map-marker tone-${m.tone}`,\n bubblingMouseEvents: false,\n });\n marker.on(\"click\", () => setSelected(id));\n marker.on(\"mouseover\", () => setHovered(id));\n marker.on(\"mouseout\", () => setHovered((h) => (h === id ? null : h)));\n marker.addTo(layer);\n const el = markerElement(marker);\n el?.setAttribute(\"data-testid\", \"map-marker\");\n el?.setAttribute(\"data-id\", m.id);\n if (plane) {\n el?.setAttribute(\"data-icon\", \"airplane\");\n el?.setAttribute(\"data-rotation\", String(m.rotation ?? 0));\n }\n byId.current.set(m.id, marker);\n }\n for (const [id, marker] of byId.current) {\n if (seen.has(id)) continue;\n layer.removeLayer(marker);\n byId.current.delete(id);\n }\n // Fit once, when the first rows arrive; later filters leave the view where the user put it.\n if (optsRef.current.fit_bounds && !fitted.current && markers.length > 0) {\n fitted.current = true;\n fitMarkers(mapRef.current, markers, false);\n }\n }, [markers]);\n\n // --- trails: every one up to TRAILS_FOR_ALL_MAX markers, else the hovered and the selected\n useEffect(() => {\n const layer = trailLayerRef.current;\n const renderer = trailRendererRef.current;\n if (!layer || !renderer) return;\n layer.clearLayers();\n for (const m of trailMarkers(markers, hovered, selected)) {\n const active = m.id === hovered || m.id === selected;\n const line = L.polyline(m.trail, {\n renderer,\n interactive: false,\n weight: active ? 2.5 : 1.5,\n className: `udc-map-trail tone-${m.tone}${active ? \" is-active\" : \"\"}`,\n }).addTo(layer);\n const path = line.getElement();\n path?.setAttribute(\"data-testid\", \"map-trail\");\n path?.setAttribute(\"data-id\", m.id);\n path?.setAttribute(\"data-points\", String(m.trail.length));\n if (active) path?.setAttribute(\"data-active\", \"true\");\n }\n }, [markers, hovered, selected]);\n\n // --- the selected marker: highlighted, on top, its popup open ------------------------\n const selectedMarker = selected ? markers.find((m) => m.id === selected) : undefined;\n useEffect(() => {\n const map = mapRef.current;\n const popup = popupRef.current;\n if (!map || !popup) return;\n const marker = selectedMarker ? byId.current.get(selectedMarker.id) : undefined;\n if (!selectedMarker || !marker) {\n if (map.hasLayer(popup)) map.closePopup(popup);\n return;\n }\n const el = markerElement(marker);\n el?.classList.add(\"is-selected\");\n if (isPlane(marker)) marker.setZIndexOffset(1000);\n else marker.bringToFront();\n // Opened by a click, it pans the map to fit; moved by a poll (setLatLng and update pan\n // too), it follows its marker and the viewport stays where the user put it.\n const open = map.hasLayer(popup);\n popup.options.autoPan = !open;\n popup.options.offset = isPlane(marker) ? [0, -opts.icon_size / 2] : [0, 7];\n popup.setLatLng(marker.getLatLng());\n if (!open) popup.openOn(map);\n else popup.update();\n return () => {\n el?.classList.remove(\"is-selected\");\n if (isPlane(marker)) marker.setZIndexOffset(0);\n };\n }, [selectedMarker, opts.icon_size]);\n\n // A selection the filter took away goes with it.\n useEffect(() => {\n if (selected && !selectedMarker && !q.isFetching) setSelected(null);\n }, [selected, selectedMarker, q.isFetching]);\n\n const flyTo = (id: string) => {\n const r = regionById(opts, id);\n if (r) mapRef.current?.flyTo(r.center, r.zoom, { duration: 0.6 });\n };\n\n const region = regionAt(opts, view.center, view.zoom);\n const firstLoad = q.isLoading && q.rows.length === 0;\n const error = q.error && q.rows.length === 0 ? q.error : null;\n const empty = !firstLoad && !error && !q.isFetching && q.rows.length === 0;\n\n return (\n <div\n className=\"udc:flex udc:min-h-0 udc:flex-1 udc:flex-col\"\n data-testid=\"map\"\n data-zoom={view.zoom}\n data-center={view.center.join(\",\")}\n data-region={region ?? undefined}\n >\n <AllRowsStatus result={q} />\n <MapToolbar\n opts={opts}\n region={region}\n onRegion={flyTo}\n onFitAll={() => fitMarkers(mapRef.current, markers, true)}\n canFit={markers.length > 0}\n />\n <div className=\"udc:relative udc:min-h-0 udc:flex-1\">\n <section\n ref={containerRef}\n className=\"udc-map udc:absolute udc:inset-0\"\n aria-label={t(\"APP\", \"TAB_MAP\")}\n />\n {firstLoad ? (\n <div className=\"udc:absolute udc:inset-0 udc:z-[1000] udc:p-3\" data-testid=\"map-skeleton\">\n <Skeleton className=\"udc:size-full udc:rounded-lg\" />\n </div>\n ) : null}\n {error || empty ? (\n <div className=\"udc:absolute udc:inset-0 udc:z-[1000] udc:grid udc:place-items-center udc:bg-background/70 udc:backdrop-blur-[1px]\">\n <div className=\"udc:rounded-xl udc:border udc:border-border udc:bg-surface udc:shadow-lg\">\n {error ? (\n <ErrorState error={error} onRetry={() => void q.refetch()} />\n ) : (\n <EmptyState filtered={filtered} onClear={onClearFilters} />\n )}\n </div>\n </div>\n ) : null}\n </div>\n {selectedMarker\n ? createPortal(\n <MapPopup\n row={selectedMarker.row}\n collection={collection}\n describe={describe}\n opts={opts}\n />,\n popupEl,\n )\n : null}\n </div>\n );\n}\n\n/** Region buttons and \"fit all\", above the map; the count is the data view's. */\nexport function MapToolbar({\n opts,\n region,\n onRegion,\n onFitAll,\n canFit,\n}: {\n opts: MapOptions;\n region: string | null;\n onRegion: (id: string) => void;\n onFitAll: () => void;\n canFit: boolean;\n}) {\n const { Button, Segmented } = useUiKit();\n const { t } = useI18n();\n const regions = opts.regions ?? [];\n return (\n <div\n className=\"udc:flex udc:flex-wrap udc:items-center udc:gap-2 udc:border-b udc:border-border udc:bg-muted/30 udc:px-3 udc:py-1.5\"\n data-testid=\"map-toolbar\"\n >\n {regions.length > 0 ? (\n <Segmented<string>\n aria-label={t(\"APP\", \"MAP_REGIONS\")}\n data-testid=\"map-regions\"\n value={region ?? \"\"}\n onChange={onRegion}\n options={regions.map((r) => ({\n value: r.id,\n label: r.label,\n testId: `map-region-${r.id}`,\n }))}\n />\n ) : null}\n <Button\n size=\"sm\"\n variant=\"ghost\"\n data-testid=\"map-fit-all\"\n disabled={!canFit}\n onClick={onFitAll}\n >\n <Maximize />\n {t(\"APP\", \"MAP_FIT_ALL\")}\n </Button>\n </div>\n );\n}\n\n/** The popup of a marker: `popup_fields` (else the first columns), as the table formats them. */\nfunction MapPopup({\n row,\n collection,\n describe,\n opts,\n}: {\n row: Row;\n collection: string;\n describe: DescribeResponse;\n opts: MapOptions;\n}) {\n const { t, locale, intlLocale } = useI18n();\n const { view, schema } = describe;\n const section = tableSection(collection);\n const fields = (opts.popup_fields ?? view.columns.slice(0, 4).map((c) => c.field)).filter(\n (f) => schema.fields[f],\n );\n const column = (field: string) => view.columns.find((c) => c.field === field) ?? { field };\n const [head, ...rest] = fields;\n return (\n <div\n data-testid=\"map-popup\"\n data-id={row.__meta.id}\n className=\"udc:flex udc:flex-col udc:gap-1.5\"\n >\n {head ? (\n <div\n className=\"udc:text-sm udc:leading-snug udc:font-semibold udc:text-foreground\"\n data-testid={`map-popup-${head}`}\n >\n <CellValue\n value={row[head]}\n column={column(head)}\n def={schema.fields[head]}\n locale={locale}\n intlLocale={intlLocale}\n />\n </div>\n ) : null}\n {rest.length > 0 ? (\n <dl className=\"udc:flex udc:flex-col\">\n {rest.map((field) => (\n <div\n key={field}\n data-testid={`map-popup-${field}`}\n className=\"udc:flex udc:min-h-6 udc:items-center udc:justify-between udc:gap-4 udc:border-t udc:border-dashed udc:border-border/80 udc:py-0.5\"\n >\n <dt className=\"udc:shrink-0 udc:text-xs udc:text-muted-foreground\">\n {t(section, field)}\n </dt>\n <dd className=\"udc:flex udc:min-w-0 udc:items-center udc:justify-end udc:text-right udc:text-[13px] udc:font-medium udc:text-foreground\">\n <CellValue\n value={row[field]}\n column={column(field)}\n def={schema.fields[field]}\n locale={locale}\n intlLocale={intlLocale}\n />\n </dd>\n </div>\n ))}\n </dl>\n ) : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAwBA,IAAM,YAAY;AAClB,IAAM,kBACJ;AACF,IAAM,cAAiC,CAAC,IAAI,EAAE;;AAE9C,IAAM,eAAe;;AAGrB,SAAS,WAAW,KAAmB,MAA4B,SAAkB;CACnF,MAAM,SAAS,SAAS,IAAI;CAC5B,IAAI,UAAU,KACZ,IAAI,UAAU,QAAQ;EAAE,SAAS;EAAa,SAAS;EAAc;CAAQ,CAAC;AAClF;AAKA,IAAM,WAAW,UAA0C,iBAAiB,EAAE;;AAG9E,IAAM,iBAAiB,UACrB,QAAQ,KAAK,IAAI,MAAM,WAAW,IAAI,MAAM,WAAW;AAEzD,SAAS,UAAU,GAAc,MAAyB;CACxD,OAAO,EAAE,QAAQ;EACf,MAAM,aAAa,EAAE,YAAY,GAAG,IAAI;EAExC,WAAW,sBAAsB,EAAE;EACnC,UAAU,CAAC,MAAM,IAAI;EACrB,YAAY,CAAC,OAAO,GAAG,OAAO,CAAC;CACjC,CAAC;AACH;;AAGA,SAAS,YAAY,OAAiB,GAAc;CAClD,MAAM,KAAK,MAAM,WAAW;CAC5B,IAAI,CAAC,IAAI;CACT,KAAK,MAAM,KAAK,CAAC,GAAG,GAAG,SAAS,GAAG,IAAI,EAAE,WAAW,OAAO,GAAG,GAAG,UAAU,OAAO,CAAC;CACnF,GAAG,UAAU,IAAI,QAAQ,EAAE,MAAM;CACjC,GAAG,aAAa,iBA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I;IACnB,KAAK,OAAO,OAAO;IACX;IACI;GACb,CAAA;EACE,CAAA,IACH,MACH,KAAK,SAAS,IACb,oBAAC,MAAD;GAAI,WAAU;GACX,UAAA,KAAK,KAAK,UACT,qBAAC,OAAD;IAEE,eAAa,aAAa;IAC1B,WAAU;IAHZ,UAAA,CAKE,oBAAC,MAAD;KAAI,WAAU;KACX,UAAA,EAAE,SAAS,KAAK;IACf,CAAA,GACJ,oBAAC,MAAD;KAAI,WAAU;KACZ,UAAA,oBAAC,WAAD;MACE,OAAO,IAAI;MACX,QAAQ,OAAO,KAAK;MACpB,KAAK,OAAO,OAAO;MACX;MACI;KACb,CAAA;IACC,CAAA,CACD;GAhBE,GAAA,KAgBF,CACN;EACC,CAAA,IACF,IACD;;AAET"}
|
|
1
|
+
{"version":3,"file":"MapRenderer.js","names":[],"sources":["../../src/map/MapRenderer.tsx"],"sourcesContent":["import \"leaflet/dist/leaflet.css\";\nimport type { DescribeResponse, MapOptions, Row } from \"@jsudc/core\";\nimport L from \"leaflet\";\nimport { Maximize } from \"lucide-react\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { tableSection, useI18n } from \"../i18n/i18n.js\";\nimport { AllRowsStatus } from \"../renderers/AllRowsStatus.js\";\nimport type { RendererProps } from \"../renderers/types.js\";\nimport { CellValue } from \"../table/cells.js\";\nimport { EmptyState, ErrorState } from \"../table/states.js\";\nimport { useUdcAllRows } from \"../udc/hooks.js\";\nimport { useUiKit } from \"../ui-kit/context.js\";\nimport {\n airplaneHtml,\n boundsOf,\n initialView,\n type MapMarker,\n regionAt,\n regionById,\n toMarkers,\n trailMarkers,\n} from \"./model.js\";\n\nconst OSM_TILES = \"https://tile.openstreetmap.org/{z}/{x}/{y}.png\";\nconst OSM_ATTRIBUTION =\n '© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors';\nconst FIT_PADDING: L.PointExpression = [32, 32];\n/** Fitting a single marker (or a tight cluster) should not zoom to a street. */\nconst FIT_MAX_ZOOM = 12;\n\n/** Frame every marker (no-op without one). */\nfunction fitMarkers(map: L.Map | null, list: readonly MapMarker[], animate: boolean) {\n const bounds = boundsOf(list);\n if (bounds && map)\n map.fitBounds(bounds, { padding: FIT_PADDING, maxZoom: FIT_MAX_ZOOM, animate });\n}\n\n/** A marker on the map: a circle, or an aeroplane (a divIcon) turned along its track. */\ntype MarkerLayer = L.CircleMarker | L.Marker;\n\nconst isPlane = (layer: MarkerLayer): layer is L.Marker => layer instanceof L.Marker;\n\n/** The element a test and the selection styles read: the circle's path, the plane's icon. */\nconst markerElement = (layer: MarkerLayer): Element | undefined =>\n isPlane(layer) ? layer.getElement() : layer.getElement();\n\nfunction planeIcon(m: MapMarker, size: number): L.DivIcon {\n return L.divIcon({\n html: airplaneHtml(m.rotation ?? 0, size),\n // No leaflet-div-icon: its white box and border would frame the plane.\n className: `udc-map-plane tone-${m.tone}`,\n iconSize: [size, size],\n iconAnchor: [size / 2, size / 2],\n });\n}\n\n/** Turn and recolour a plane in place: its element (and a hover on it) stays. */\nfunction updatePlane(layer: L.Marker, m: MapMarker) {\n const el = layer.getElement();\n if (!el) return;\n for (const c of [...el.classList]) if (c.startsWith(\"tone-\")) el.classList.remove(c);\n el.classList.add(`tone-${m.tone}`);\n el.setAttribute(\"data-rotation\", String(m.rotation ?? 0));\n const glyph = el.querySelector<HTMLElement>(\".udc-map-plane-glyph\");\n if (glyph) glyph.style.transform = `rotate(${m.rotation ?? 0}deg)`;\n}\n\n/** The `map` tab: every row with a position as a circle (or an aeroplane), over OpenStreetMap tiles. */\nexport function MapRenderer(props: RendererProps) {\n const opts = props.describe.view.map_options;\n const { t } = useI18n();\n if (!opts) {\n return (\n <div\n className=\"udc:p-8 udc:text-center udc:text-sm udc:text-muted-foreground\"\n data-testid=\"map-missing\"\n >\n {t(\"APP\", \"MAP_NO_OPTIONS\")}\n </div>\n );\n }\n return <MapView {...props} opts={opts} />;\n}\n\n/** The view a toolbar and a test read: centre to 4 decimals and zoom. */\ninterface ViewState {\n center: [number, number];\n zoom: number;\n}\n\nfunction MapView({\n collection,\n describe,\n filter,\n listSearch,\n sort,\n filtered,\n onClearFilters,\n onCount,\n opts,\n}: RendererProps & { opts: MapOptions }) {\n const { Skeleton } = useUiKit();\n const { t } = useI18n();\n const q = useUdcAllRows({\n collection,\n filter,\n sort,\n capabilities: describe.capabilities,\n max: opts.max_rows,\n refetchInterval: describe.view.refresh_interval_ms,\n search: listSearch,\n });\n const rowColor = describe.view.row_color;\n const markers = useMemo(() => toMarkers(q.rows, opts, rowColor), [q.rows, opts, rowColor]);\n\n useEffect(() => {\n onCount(\n q.total === null\n ? null\n : {\n shown: markers.length,\n total: q.total,\n unit: \"map\",\n fetchedAt: q.fetchedAt,\n stale: q.stale,\n },\n );\n }, [onCount, markers.length, q.total, q.fetchedAt, q.stale]);\n useEffect(() => () => onCount(null), [onCount]);\n\n // --- the Leaflet map: one per mount -----------------------------------------------\n const containerRef = useRef<HTMLElement>(null);\n const mapRef = useRef<L.Map | null>(null);\n const layerRef = useRef<L.LayerGroup | null>(null);\n const trailLayerRef = useRef<L.LayerGroup | null>(null);\n const trailRendererRef = useRef<L.Renderer | null>(null);\n const popupRef = useRef<L.Popup | null>(null);\n const byId = useRef(new Map<string, MarkerLayer>());\n const optsRef = useRef(opts);\n optsRef.current = opts;\n const [popupEl] = useState(() => document.createElement(\"div\"));\n const [view, setView] = useState<ViewState>(() => initialView(opts));\n const [selected, setSelected] = useState<string | null>(null);\n const [hovered, setHovered] = useState<string | null>(null);\n\n useEffect(() => {\n const el = containerRef.current;\n if (!el) return;\n const start = initialView(optsRef.current);\n const map = L.map(el, { center: start.center, zoom: start.zoom, worldCopyJump: true });\n L.tileLayer(OSM_TILES, { attribution: OSM_ATTRIBUTION, maxZoom: 19 }).addTo(map);\n // Trails under every marker (circles are in the overlay pane, z 400; planes above it).\n map.createPane(\"udc-trails\").style.zIndex = \"350\";\n trailRendererRef.current = L.svg({ pane: \"udc-trails\" });\n trailLayerRef.current = L.layerGroup().addTo(map);\n layerRef.current = L.layerGroup().addTo(map);\n popupRef.current = L.popup({ className: \"udc-map-popup\", maxWidth: 320, minWidth: 200 });\n popupRef.current.setContent(popupEl);\n map.on(\"moveend\", () => {\n const c = map.getCenter();\n const round = (x: number) => Math.round(x * 1e4) / 1e4;\n setView({ center: [round(c.lat), round(c.lng)], zoom: map.getZoom() });\n });\n // Closed by its button, Escape or a click on the map: nothing is selected any more.\n map.on(\"popupclose\", (e) => {\n if (e.popup === popupRef.current) setSelected(null);\n });\n mapRef.current = map;\n const resize = new ResizeObserver(() => map.invalidateSize());\n resize.observe(el);\n return () => {\n resize.disconnect();\n map.remove();\n mapRef.current = null;\n layerRef.current = null;\n trailLayerRef.current = null;\n trailRendererRef.current = null;\n popupRef.current = null;\n byId.current.clear();\n };\n }, [popupEl]);\n\n // --- markers, kept by id: a poll moves them in place ---------------------------------\n const fitted = useRef(false);\n useEffect(() => {\n const layer = layerRef.current;\n if (!layer) return;\n const size = optsRef.current.icon_size;\n const seen = new Set<string>();\n for (const m of markers) {\n seen.add(m.id);\n const plane = m.rotation !== null;\n let marker = byId.current.get(m.id);\n // A row that gained or lost its track changes kind: drawn anew.\n if (marker && isPlane(marker) !== plane) {\n layer.removeLayer(marker);\n marker = undefined;\n }\n if (marker) {\n marker.setLatLng([m.lat, m.lng]);\n if (isPlane(marker)) updatePlane(marker, m);\n else {\n marker.setRadius(m.radius);\n const path = marker.getElement();\n path?.setAttribute(\"class\", `leaflet-interactive udc-map-marker tone-${m.tone}`);\n }\n continue;\n }\n const id = m.id;\n marker = plane\n ? L.marker([m.lat, m.lng], {\n icon: planeIcon(m, size),\n keyboard: false,\n bubblingMouseEvents: false,\n })\n : L.circleMarker([m.lat, m.lng], {\n radius: m.radius,\n weight: 1.5,\n fillOpacity: 0.4,\n // The colour comes from the theme's tokens in index.css, by tone.\n className: `udc-map-marker tone-${m.tone}`,\n bubblingMouseEvents: false,\n });\n marker.on(\"click\", () => setSelected(id));\n marker.on(\"mouseover\", () => setHovered(id));\n marker.on(\"mouseout\", () => setHovered((h) => (h === id ? null : h)));\n marker.addTo(layer);\n const el = markerElement(marker);\n el?.setAttribute(\"data-testid\", \"map-marker\");\n el?.setAttribute(\"data-id\", m.id);\n if (plane) {\n el?.setAttribute(\"data-icon\", \"airplane\");\n el?.setAttribute(\"data-rotation\", String(m.rotation ?? 0));\n }\n byId.current.set(m.id, marker);\n }\n for (const [id, marker] of byId.current) {\n if (seen.has(id)) continue;\n layer.removeLayer(marker);\n byId.current.delete(id);\n }\n // Fit once, when the first rows arrive; later filters leave the view where the user put it.\n if (optsRef.current.fit_bounds && !fitted.current && markers.length > 0) {\n fitted.current = true;\n fitMarkers(mapRef.current, markers, false);\n }\n }, [markers]);\n\n // --- trails: every one up to TRAILS_FOR_ALL_MAX markers, else the hovered and the selected\n useEffect(() => {\n const layer = trailLayerRef.current;\n const renderer = trailRendererRef.current;\n if (!layer || !renderer) return;\n layer.clearLayers();\n for (const m of trailMarkers(markers, hovered, selected)) {\n const active = m.id === hovered || m.id === selected;\n const line = L.polyline(m.trail, {\n renderer,\n interactive: false,\n weight: active ? 2.5 : 1.5,\n className: `udc-map-trail tone-${m.tone}${active ? \" is-active\" : \"\"}`,\n }).addTo(layer);\n const path = line.getElement();\n path?.setAttribute(\"data-testid\", \"map-trail\");\n path?.setAttribute(\"data-id\", m.id);\n path?.setAttribute(\"data-points\", String(m.trail.length));\n if (active) path?.setAttribute(\"data-active\", \"true\");\n }\n }, [markers, hovered, selected]);\n\n // --- the selected marker: highlighted, on top, its popup open ------------------------\n const selectedMarker = selected ? markers.find((m) => m.id === selected) : undefined;\n useEffect(() => {\n const map = mapRef.current;\n const popup = popupRef.current;\n if (!map || !popup) return;\n const marker = selectedMarker ? byId.current.get(selectedMarker.id) : undefined;\n if (!selectedMarker || !marker) {\n if (map.hasLayer(popup)) map.closePopup(popup);\n return;\n }\n const el = markerElement(marker);\n el?.classList.add(\"is-selected\");\n if (isPlane(marker)) marker.setZIndexOffset(1000);\n else marker.bringToFront();\n // Opened by a click, it pans the map to fit; moved by a poll (setLatLng and update pan\n // too), it follows its marker and the viewport stays where the user put it.\n const open = map.hasLayer(popup);\n popup.options.autoPan = !open;\n popup.options.offset = isPlane(marker) ? [0, -opts.icon_size / 2] : [0, 7];\n popup.setLatLng(marker.getLatLng());\n if (!open) popup.openOn(map);\n else popup.update();\n return () => {\n el?.classList.remove(\"is-selected\");\n if (isPlane(marker)) marker.setZIndexOffset(0);\n };\n }, [selectedMarker, opts.icon_size]);\n\n // A selection the filter took away goes with it.\n useEffect(() => {\n if (selected && !selectedMarker && !q.isFetching) setSelected(null);\n }, [selected, selectedMarker, q.isFetching]);\n\n const flyTo = (id: string) => {\n const r = regionById(opts, id);\n if (r) mapRef.current?.flyTo(r.center, r.zoom, { duration: 0.6 });\n };\n\n const region = regionAt(opts, view.center, view.zoom);\n const firstLoad = q.isLoading && q.rows.length === 0;\n const error = q.error && q.rows.length === 0 ? q.error : null;\n const empty = !firstLoad && !error && !q.isFetching && q.rows.length === 0;\n\n return (\n <div\n className=\"udc:flex udc:min-h-0 udc:flex-1 udc:flex-col\"\n data-testid=\"map\"\n data-zoom={view.zoom}\n data-center={view.center.join(\",\")}\n data-region={region ?? undefined}\n >\n <AllRowsStatus result={q} />\n <MapToolbar\n opts={opts}\n region={region}\n onRegion={flyTo}\n onFitAll={() => fitMarkers(mapRef.current, markers, true)}\n canFit={markers.length > 0}\n />\n <div className=\"udc:relative udc:min-h-0 udc:flex-1\">\n <section\n ref={containerRef}\n className=\"udc-map udc:absolute udc:inset-0\"\n aria-label={t(\"APP\", \"TAB_MAP\")}\n />\n {firstLoad ? (\n <div className=\"udc:absolute udc:inset-0 udc:z-[1000] udc:p-3\" data-testid=\"map-skeleton\">\n <Skeleton className=\"udc:size-full udc:rounded-lg\" />\n </div>\n ) : null}\n {error || empty ? (\n <div className=\"udc:absolute udc:inset-0 udc:z-[1000] udc:grid udc:place-items-center udc:bg-background/70 udc:backdrop-blur-[1px]\">\n <div className=\"udc:rounded-xl udc:border udc:border-border udc:bg-surface udc:shadow-lg\">\n {error ? (\n <ErrorState error={error} onRetry={() => void q.refetch()} />\n ) : (\n <EmptyState filtered={filtered} onClear={onClearFilters} />\n )}\n </div>\n </div>\n ) : null}\n </div>\n {selectedMarker\n ? createPortal(\n <MapPopup\n row={selectedMarker.row}\n collection={collection}\n describe={describe}\n opts={opts}\n />,\n popupEl,\n )\n : null}\n </div>\n );\n}\n\n/** Region buttons and \"fit all\", above the map; the count is the data view's. */\nexport function MapToolbar({\n opts,\n region,\n onRegion,\n onFitAll,\n canFit,\n}: {\n opts: MapOptions;\n region: string | null;\n onRegion: (id: string) => void;\n onFitAll: () => void;\n canFit: boolean;\n}) {\n const { Button, Segmented } = useUiKit();\n const { t } = useI18n();\n const regions = opts.regions ?? [];\n return (\n <div\n className=\"udc:flex udc:flex-wrap udc:items-center udc:gap-2 udc:border-b udc:border-border udc:bg-muted/30 udc:px-3 udc:py-1.5\"\n data-testid=\"map-toolbar\"\n >\n {regions.length > 0 ? (\n <Segmented<string>\n aria-label={t(\"APP\", \"MAP_REGIONS\")}\n data-testid=\"map-regions\"\n value={region ?? \"\"}\n onChange={onRegion}\n options={regions.map((r) => ({\n value: r.id,\n label: r.label,\n testId: `map-region-${r.id}`,\n }))}\n />\n ) : null}\n <Button\n size=\"sm\"\n variant=\"ghost\"\n data-testid=\"map-fit-all\"\n disabled={!canFit}\n onClick={onFitAll}\n >\n <Maximize />\n {t(\"APP\", \"MAP_FIT_ALL\")}\n </Button>\n </div>\n );\n}\n\n/** The popup of a marker: `popup_fields` (else the first columns), as the table formats them. */\nfunction MapPopup({\n row,\n collection,\n describe,\n opts,\n}: {\n row: Row;\n collection: string;\n describe: DescribeResponse;\n opts: MapOptions;\n}) {\n const { t, locale, intlLocale } = useI18n();\n const { view, schema } = describe;\n const section = tableSection(collection);\n const fields = (opts.popup_fields ?? view.columns.slice(0, 4).map((c) => c.field)).filter(\n (f) => schema.fields[f],\n );\n const column = (field: string) => view.columns.find((c) => c.field === field) ?? { field };\n const [head, ...rest] = fields;\n return (\n <div\n data-testid=\"map-popup\"\n data-id={row.__meta.id}\n className=\"udc:flex udc:flex-col udc:gap-1.5\"\n >\n {head ? (\n <div\n className=\"udc:text-sm udc:leading-snug udc:font-semibold udc:text-foreground\"\n data-testid={`map-popup-${head}`}\n >\n <CellValue\n value={row[head]}\n column={column(head)}\n def={schema.fields[head]}\n locale={locale}\n intlLocale={intlLocale}\n />\n </div>\n ) : null}\n {rest.length > 0 ? (\n <dl className=\"udc:flex udc:flex-col\">\n {rest.map((field) => (\n <div\n key={field}\n data-testid={`map-popup-${field}`}\n className=\"udc:flex udc:min-h-6 udc:items-center udc:justify-between udc:gap-4 udc:border-t udc:border-dashed udc:border-border/80 udc:py-0.5\"\n >\n <dt className=\"udc:shrink-0 udc:text-xs udc:text-muted-foreground\">\n {t(section, field)}\n </dt>\n <dd className=\"udc:flex udc:min-w-0 udc:items-center udc:justify-end udc:text-right udc:text-[13px] udc:font-medium udc:text-foreground\">\n <CellValue\n value={row[field]}\n column={column(field)}\n def={schema.fields[field]}\n locale={locale}\n intlLocale={intlLocale}\n />\n </dd>\n </div>\n ))}\n </dl>\n ) : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAwBA,IAAM,YAAY;AAClB,IAAM,kBACJ;AACF,IAAM,cAAiC,CAAC,IAAI,EAAE;;AAE9C,IAAM,eAAe;;AAGrB,SAAS,WAAW,KAAmB,MAA4B,SAAkB;CACnF,MAAM,SAAS,SAAS,IAAI;CAC5B,IAAI,UAAU,KACZ,IAAI,UAAU,QAAQ;EAAE,SAAS;EAAa,SAAS;EAAc;CAAQ,CAAC;AAClF;AAKA,IAAM,WAAW,UAA0C,iBAAiB,EAAE;;AAG9E,IAAM,iBAAiB,UACrB,QAAQ,KAAK,IAAI,MAAM,WAAW,IAAI,MAAM,WAAW;AAEzD,SAAS,UAAU,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,UAAU;CACvC,MAAM,UAAU,KAAK,gBAAgB,KAAK,QAAQ,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,KAAK,EAAA,CAAG,QAChF,MAAM,OAAO,OAAO,EACvB;CACA,MAAM,UAAU,UAAkB,KAAK,QAAQ,MAAM,MAAM,EAAE,UAAU,KAAK,KAAK,EAAE,MAAM;CACzF,MAAM,CAAC,MAAM,GAAG,QAAQ;CACxB,OACE,qBAAC,OAAD;EACE,eAAY;EACZ,WAAS,IAAI,OAAO;EACpB,WAAU;EAHZ,UAAA,CAKG,OACC,oBAAC,OAAD;GACE,WAAU;GACV,eAAa,aAAa;GAE1B,UAAA,oBAAC,WAAD;IACE,OAAO,IAAI;IACX,QAAQ,OAAO,IAAI;IACnB,KAAK,OAAO,OAAO;IACX;IACI;GACb,CAAA;EACE,CAAA,IACH,MACH,KAAK,SAAS,IACb,oBAAC,MAAD;GAAI,WAAU;GACX,UAAA,KAAK,KAAK,UACT,qBAAC,OAAD;IAEE,eAAa,aAAa;IAC1B,WAAU;IAHZ,UAAA,CAKE,oBAAC,MAAD;KAAI,WAAU;KACX,UAAA,EAAE,SAAS,KAAK;IACf,CAAA,GACJ,oBAAC,MAAD;KAAI,WAAU;KACZ,UAAA,oBAAC,WAAD;MACE,OAAO,IAAI;MACX,QAAQ,OAAO,KAAK;MACpB,KAAK,OAAO,OAAO;MACX;MACI;KACb,CAAA;IACC,CAAA,CACD;GAhBE,GAAA,KAgBF,CACN;EACC,CAAA,IACF,IACD;;AAET"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { DescribeResponse, FilterNode, FolderOptions, Row, SortKey } from "@jsudc/core";
|
|
2
2
|
import type { LucideIcon } from "lucide-react";
|
|
3
3
|
import type { ComponentType } from "react";
|
|
4
|
+
import type { RowActions } from "../actions/row.js";
|
|
4
5
|
import type { ChartWindowState } from "../chart/useChartWindow.js";
|
|
6
|
+
import type { RowSelection } from "../rows/useRowSelection.js";
|
|
5
7
|
import type { SchemaAction } from "../schema-editor/fieldForm.js";
|
|
8
|
+
import type { TableVirtualizeProp } from "../table/useRowWindow.js";
|
|
6
9
|
import type { UdcCollectionResult } from "../udc/hooks.js";
|
|
7
10
|
import type { PagingMode } from "../udc/keys.js";
|
|
8
11
|
/** The row count a renderer that loads its own rows reports to the toolbar. */
|
|
@@ -36,7 +39,7 @@ export interface RendererProps {
|
|
|
36
39
|
describe: DescribeResponse;
|
|
37
40
|
/** The data view's paged list; loaded only for a renderer with `paging`. */
|
|
38
41
|
data: UdcCollectionResult;
|
|
39
|
-
/** Search, chips and filter tree, composed. */
|
|
42
|
+
/** Search, chips and filter tree, composed (the search left out under `listSearch`). */
|
|
40
43
|
filter: FilterNode | undefined;
|
|
41
44
|
/** Chips and filter tree without the search: for a renderer that searches what it loaded. */
|
|
42
45
|
baseFilter: FilterNode | undefined;
|
|
@@ -50,6 +53,14 @@ export interface RendererProps {
|
|
|
50
53
|
unwindowedFilter?: FilterNode | undefined;
|
|
51
54
|
/** The search box, as typed. */
|
|
52
55
|
search: string;
|
|
56
|
+
/**
|
|
57
|
+
* The text to send as `ListRequest.search` with every list the renderer
|
|
58
|
+
* makes, set only when the collection's source answers search itself
|
|
59
|
+
* (`describe.capabilities.search === "source"`) and the box is not blank.
|
|
60
|
+
* `filter` and `baseFilter` then hold no `contains` for it. Pass it as
|
|
61
|
+
* `search` to `useUdcAllRows` / `useUdcCollection` (0.5.0).
|
|
62
|
+
*/
|
|
63
|
+
listSearch?: string | undefined;
|
|
53
64
|
sort: SortKey[];
|
|
54
65
|
onSort: (field: string, multi: boolean) => void;
|
|
55
66
|
mode: PagingMode;
|
|
@@ -77,6 +88,26 @@ export interface RendererProps {
|
|
|
77
88
|
activeRowId?: string | null | undefined;
|
|
78
89
|
/** Report the active row moving (keys, a click on another row); set whenever activation is on. */
|
|
79
90
|
onActiveRowChange?: ((row: Row | null) => void) | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Row selection (0.5.0; `useRowSelection` of `@jsudc/react/headless`): set
|
|
93
|
+
* when the view selects (`view.multiselect`, `view.bulk_actions`, or the
|
|
94
|
+
* `selectable` prop) and the renderer reads the paged list; absent
|
|
95
|
+
* otherwise. Draw a checkbox from `isSelected`, drive it with `toggle`,
|
|
96
|
+
* `setPage`, `selectAllMatching` and `clear`; the view draws the bulk bar.
|
|
97
|
+
*/
|
|
98
|
+
selection?: RowSelection | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Row actions (0.5.0; `RowActions` of `@jsudc/react/headless`): set when the
|
|
101
|
+
* view declares `row_action_defs` or `row_actions`, absent otherwise. Draw
|
|
102
|
+
* `eligible(row)` as `display` says, label each with `label`, run one with
|
|
103
|
+
* `run(def, row)` (the host's handler, else the server, as the bulk bar).
|
|
104
|
+
*/
|
|
105
|
+
rowActions?: RowActions | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* Long lists (0.5.0): `UdcDataView`'s `virtualize`, passed only when the host set it. The
|
|
108
|
+
* table windows its rows in infinite mode by it; other renderers ignore it.
|
|
109
|
+
*/
|
|
110
|
+
virtualize?: TableVirtualizeProp | undefined;
|
|
80
111
|
}
|
|
81
112
|
export interface RendererEntry {
|
|
82
113
|
component: ComponentType<RendererProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../src/renderers/types.ts"],"sourcesContent":["import type { DescribeResponse, FilterNode, FolderOptions, Row, SortKey } from \"@jsudc/core\";\nimport type { LucideIcon } from \"lucide-react\";\nimport type { ComponentType } from \"react\";\nimport type { ChartWindowState } from \"../chart/useChartWindow.js\";\nimport type { SchemaAction } from \"../schema-editor/fieldForm.js\";\nimport type { UdcCollectionResult } from \"../udc/hooks.js\";\nimport type { PagingMode } from \"../udc/keys.js\";\n\n/** The row count a renderer that loads its own rows reports to the toolbar. */\nexport interface RendererCount {\n shown: number;\n total: number | null;\n /**\n * `nodes`: the toolbar reads \"N nodes\" (the tree), `map`: \"N on map of M\"\n * (rows without a position are not drawn), `chart`: \"N points in window of\n * M\" (M counts the filter without the window), instead of \"Showing N of M\".\n */\n unit?: \"nodes\" | \"map\" | \"chart\";\n /** A source serving a fetched copy (http_api): when it was fetched, and whether it is stale. */\n fetchedAt?: string | null;\n stale?: boolean;\n}\n\n/** A folder-shaped collection (`folder_options`): what a folder row or a file row does on click. */\nexport interface FolderNav {\n options: FolderOptions;\n /** Open a folder by its path (`\"\"`: the root). */\n open: (path: string) => void;\n /** Preview a file row; absent when the view has no preview. */\n openFile?: ((row: Row) => void) | undefined;\n}\n\n/** Is `row` a folder of `nav`'s listing (the `..` row included)? */\nexport function isFolderRow(row: Row, nav: FolderNav): boolean {\n return row[nav.options.kind_field] === nav.options.dir_value;\n}\n\n/** What `<UdcDataView>` hands every renderer; each takes the parts it uses. */\nexport interface RendererProps {\n collection: string;\n /** `describe` with soft-deleted fields already gone. */\n describe: DescribeResponse;\n /** The data view's paged list; loaded only for a renderer with `paging`. */\n data: UdcCollectionResult;\n /** Search, chips and filter tree, composed. */\n filter: FilterNode | undefined;\n /** Chips and filter tree without the search: for a renderer that searches what it loaded. */\n baseFilter: FilterNode | undefined;\n /**\n * The chart window, when the view has one and it applies (on the chart tab,\n * or on any tab once the URL picked it): already ANDed into `filter` and\n * `baseFilter`.\n */\n chartWindow?: ChartWindowState | undefined;\n /** `filter` without the chart window: what \"of M\" counts. */\n unwindowedFilter?: FilterNode | undefined;\n /** The search box, as typed. */\n search: string;\n sort: SortKey[];\n onSort: (field: string, multi: boolean) => void;\n mode: PagingMode;\n page: number;\n limit: number;\n onPage: (page: number) => void;\n filtered: boolean;\n onClearFilters: () => void;\n resetKey: string;\n /** Set when the schema may be edited and the renderer has `editMode`. */\n onSchemaAction?: ((a: SchemaAction) => void) | undefined;\n /** For a renderer without `paging`: the count the toolbar shows. */\n onCount: (count: RendererCount | null) => void;\n /** Set when the view has `folder_options`. */\n folder?: FolderNav | undefined;\n /**\n * Row activation (0.4.0; `useRowActivation` of `@jsudc/react/headless` does\n * all of it): Enter or a plain click on a row. Absent unless the host asked.\n */\n onRowActivate?: ((row: Row) => void) | undefined;\n /**\n * The row to draw as active; `null` for none. Set (kept by the view when the\n * host does not control it) whenever activation is on, else absent.\n */\n activeRowId?: string | null | undefined;\n /** Report the active row moving (keys, a click on another row); set whenever activation is on. */\n onActiveRowChange?: ((row: Row | null) => void) | undefined;\n}\n\nexport interface RendererEntry {\n component: ComponentType<RendererProps>;\n icon: LucideIcon;\n /** `APP.<labelKey>` is the tab label. */\n labelKey: string;\n /** Reads the data view's paged list: the paging toggle shows, the list loads. */\n paging: boolean;\n /** Offers the schema editor (column menus, add column). */\n editMode: boolean;\n /** Extra controls in the toolbar while this tab is open. */\n toolbar?: ComponentType<{ collection: string; describe: DescribeResponse }>;\n}\n\n/** One renderer as its subpath exports it (`tableRenderer` from `@jsudc/react/table`). */\nexport interface RendererDefinition extends RendererEntry {\n /** The name a view lists in `available_renderers`. */\n name: string;\n}\n\n/** Renderer name → entry: what `UdcDataView` draws its tabs with. `createRendererRegistry` builds one. */\nexport type RendererRegistry = Readonly<Record<string, RendererEntry>>;\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/renderers/types.ts"],"sourcesContent":["import type { DescribeResponse, FilterNode, FolderOptions, Row, SortKey } from \"@jsudc/core\";\nimport type { LucideIcon } from \"lucide-react\";\nimport type { ComponentType } from \"react\";\nimport type { RowActions } from \"../actions/row.js\";\nimport type { ChartWindowState } from \"../chart/useChartWindow.js\";\nimport type { RowSelection } from \"../rows/useRowSelection.js\";\nimport type { SchemaAction } from \"../schema-editor/fieldForm.js\";\nimport type { TableVirtualizeProp } from \"../table/useRowWindow.js\";\nimport type { UdcCollectionResult } from \"../udc/hooks.js\";\nimport type { PagingMode } from \"../udc/keys.js\";\n\n/** The row count a renderer that loads its own rows reports to the toolbar. */\nexport interface RendererCount {\n shown: number;\n total: number | null;\n /**\n * `nodes`: the toolbar reads \"N nodes\" (the tree), `map`: \"N on map of M\"\n * (rows without a position are not drawn), `chart`: \"N points in window of\n * M\" (M counts the filter without the window), instead of \"Showing N of M\".\n */\n unit?: \"nodes\" | \"map\" | \"chart\";\n /** A source serving a fetched copy (http_api): when it was fetched, and whether it is stale. */\n fetchedAt?: string | null;\n stale?: boolean;\n}\n\n/** A folder-shaped collection (`folder_options`): what a folder row or a file row does on click. */\nexport interface FolderNav {\n options: FolderOptions;\n /** Open a folder by its path (`\"\"`: the root). */\n open: (path: string) => void;\n /** Preview a file row; absent when the view has no preview. */\n openFile?: ((row: Row) => void) | undefined;\n}\n\n/** Is `row` a folder of `nav`'s listing (the `..` row included)? */\nexport function isFolderRow(row: Row, nav: FolderNav): boolean {\n return row[nav.options.kind_field] === nav.options.dir_value;\n}\n\n/** What `<UdcDataView>` hands every renderer; each takes the parts it uses. */\nexport interface RendererProps {\n collection: string;\n /** `describe` with soft-deleted fields already gone. */\n describe: DescribeResponse;\n /** The data view's paged list; loaded only for a renderer with `paging`. */\n data: UdcCollectionResult;\n /** Search, chips and filter tree, composed (the search left out under `listSearch`). */\n filter: FilterNode | undefined;\n /** Chips and filter tree without the search: for a renderer that searches what it loaded. */\n baseFilter: FilterNode | undefined;\n /**\n * The chart window, when the view has one and it applies (on the chart tab,\n * or on any tab once the URL picked it): already ANDed into `filter` and\n * `baseFilter`.\n */\n chartWindow?: ChartWindowState | undefined;\n /** `filter` without the chart window: what \"of M\" counts. */\n unwindowedFilter?: FilterNode | undefined;\n /** The search box, as typed. */\n search: string;\n /**\n * The text to send as `ListRequest.search` with every list the renderer\n * makes, set only when the collection's source answers search itself\n * (`describe.capabilities.search === \"source\"`) and the box is not blank.\n * `filter` and `baseFilter` then hold no `contains` for it. Pass it as\n * `search` to `useUdcAllRows` / `useUdcCollection` (0.5.0).\n */\n listSearch?: string | undefined;\n sort: SortKey[];\n onSort: (field: string, multi: boolean) => void;\n mode: PagingMode;\n page: number;\n limit: number;\n onPage: (page: number) => void;\n filtered: boolean;\n onClearFilters: () => void;\n resetKey: string;\n /** Set when the schema may be edited and the renderer has `editMode`. */\n onSchemaAction?: ((a: SchemaAction) => void) | undefined;\n /** For a renderer without `paging`: the count the toolbar shows. */\n onCount: (count: RendererCount | null) => void;\n /** Set when the view has `folder_options`. */\n folder?: FolderNav | undefined;\n /**\n * Row activation (0.4.0; `useRowActivation` of `@jsudc/react/headless` does\n * all of it): Enter or a plain click on a row. Absent unless the host asked.\n */\n onRowActivate?: ((row: Row) => void) | undefined;\n /**\n * The row to draw as active; `null` for none. Set (kept by the view when the\n * host does not control it) whenever activation is on, else absent.\n */\n activeRowId?: string | null | undefined;\n /** Report the active row moving (keys, a click on another row); set whenever activation is on. */\n onActiveRowChange?: ((row: Row | null) => void) | undefined;\n /**\n * Row selection (0.5.0; `useRowSelection` of `@jsudc/react/headless`): set\n * when the view selects (`view.multiselect`, `view.bulk_actions`, or the\n * `selectable` prop) and the renderer reads the paged list; absent\n * otherwise. Draw a checkbox from `isSelected`, drive it with `toggle`,\n * `setPage`, `selectAllMatching` and `clear`; the view draws the bulk bar.\n */\n selection?: RowSelection | undefined;\n /**\n * Row actions (0.5.0; `RowActions` of `@jsudc/react/headless`): set when the\n * view declares `row_action_defs` or `row_actions`, absent otherwise. Draw\n * `eligible(row)` as `display` says, label each with `label`, run one with\n * `run(def, row)` (the host's handler, else the server, as the bulk bar).\n */\n rowActions?: RowActions | undefined;\n /**\n * Long lists (0.5.0): `UdcDataView`'s `virtualize`, passed only when the host set it. The\n * table windows its rows in infinite mode by it; other renderers ignore it.\n */\n virtualize?: TableVirtualizeProp | undefined;\n}\n\nexport interface RendererEntry {\n component: ComponentType<RendererProps>;\n icon: LucideIcon;\n /** `APP.<labelKey>` is the tab label. */\n labelKey: string;\n /** Reads the data view's paged list: the paging toggle shows, the list loads. */\n paging: boolean;\n /** Offers the schema editor (column menus, add column). */\n editMode: boolean;\n /** Extra controls in the toolbar while this tab is open. */\n toolbar?: ComponentType<{ collection: string; describe: DescribeResponse }>;\n}\n\n/** One renderer as its subpath exports it (`tableRenderer` from `@jsudc/react/table`). */\nexport interface RendererDefinition extends RendererEntry {\n /** The name a view lists in `available_renderers`. */\n name: string;\n}\n\n/** Renderer name → entry: what `UdcDataView` draws its tabs with. `createRendererRegistry` builds one. */\nexport type RendererRegistry = Readonly<Record<string, RendererEntry>>;\n"],"mappings":";;AAoCA,SAAgB,YAAY,KAAU,KAAyB;CAC7D,OAAO,IAAI,IAAI,QAAQ,gBAAgB,IAAI,QAAQ;AACrD"}
|
|
@@ -31,6 +31,21 @@ export interface UseRowActivationOptions extends RowActivationProps {
|
|
|
31
31
|
fetchNextPage?: (() => unknown) | undefined;
|
|
32
32
|
/** Override the default, `rowActivationEnabled(options)`. */
|
|
33
33
|
enabled?: boolean | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Multiselect is on (0.5.0): `aria-selected` then says whether the row is
|
|
36
|
+
* selected (ARIA's multi-select grid), and the active row is the one holding
|
|
37
|
+
* the focus, marked `aria-current="true"` and `data-active`. Absent: as in
|
|
38
|
+
* 0.4.0, `aria-selected` marks the active row.
|
|
39
|
+
*/
|
|
40
|
+
isSelected?: ((id: string) => boolean) | undefined;
|
|
41
|
+
/** Space on a row toggles its selection (Shift+Space: a range from the last toggled row). */
|
|
42
|
+
onToggleSelect?: ((row: Row, range: boolean) => void) | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* A windowed list (0.5.0; the table's long lists) mounts only some rows: when the keys move
|
|
45
|
+
* to a row whose element is not mounted, this is called to scroll it in and mount it, and
|
|
46
|
+
* the row takes the focus the moment its element attaches. Absent: every row is mounted.
|
|
47
|
+
*/
|
|
48
|
+
reveal?: ((row: Row, index: number) => void) | undefined;
|
|
34
49
|
}
|
|
35
50
|
/** What to spread on the element of one row (a `<tr>`, a card, an `<li>`). */
|
|
36
51
|
export interface RowActivationRowProps {
|
|
@@ -38,6 +53,8 @@ export interface RowActivationRowProps {
|
|
|
38
53
|
/** One tab stop for the list: the active row, else the last focused one, else the first. */
|
|
39
54
|
tabIndex: 0 | -1;
|
|
40
55
|
"aria-selected": boolean;
|
|
56
|
+
/** With `isSelected` (multiselect): `"true"` on the active row, whose `aria-selected` is its selection. */
|
|
57
|
+
"aria-current"?: "true" | undefined;
|
|
41
58
|
/** `"true"` on the active row: a stable hook for CSS (`.udc-row[data-active]`). */
|
|
42
59
|
"data-active": "true" | undefined;
|
|
43
60
|
onKeyDown: (e: KeyboardEvent<HTMLElement>) => void;
|
|
@@ -54,14 +54,21 @@ function useRowActivation(options) {
|
|
|
54
54
|
};
|
|
55
55
|
const paging = useRef(options);
|
|
56
56
|
paging.current = options;
|
|
57
|
+
/** A windowed list: the row the keys moved to before it was mounted; focused when it attaches. */
|
|
58
|
+
const revealRef = useRef(null);
|
|
57
59
|
const elements = useRef(/* @__PURE__ */ new Map());
|
|
58
60
|
const refs = useRef(/* @__PURE__ */ new Map());
|
|
59
61
|
const refFor = (id) => {
|
|
60
62
|
let cb = refs.current.get(id);
|
|
61
63
|
if (!cb) {
|
|
62
64
|
cb = (el) => {
|
|
63
|
-
if (el)
|
|
64
|
-
|
|
65
|
+
if (el) {
|
|
66
|
+
elements.current.set(id, el);
|
|
67
|
+
if (revealRef.current === id) {
|
|
68
|
+
revealRef.current = null;
|
|
69
|
+
el.focus({ preventScroll: true });
|
|
70
|
+
}
|
|
71
|
+
} else elements.current.delete(id);
|
|
65
72
|
};
|
|
66
73
|
refs.current.set(id, cb);
|
|
67
74
|
}
|
|
@@ -73,7 +80,17 @@ function useRowActivation(options) {
|
|
|
73
80
|
const pendingRef = useRef(null);
|
|
74
81
|
const focusRow = useCallback((id) => {
|
|
75
82
|
const el = elements.current.get(id);
|
|
76
|
-
if (!el)
|
|
83
|
+
if (!el) {
|
|
84
|
+
const reveal = paging.current.reveal;
|
|
85
|
+
const list = latest.current.rows;
|
|
86
|
+
const i = list.findIndex((r) => idOf(r) === id);
|
|
87
|
+
if (reveal && i >= 0) {
|
|
88
|
+
revealRef.current = id;
|
|
89
|
+
reveal(list[i], i);
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
revealRef.current = null;
|
|
77
94
|
el.focus({ preventScroll: true });
|
|
78
95
|
if (typeof el.scrollIntoView === "function") el.scrollIntoView({ block: "nearest" });
|
|
79
96
|
}, []);
|
|
@@ -146,11 +163,24 @@ function useRowActivation(options) {
|
|
|
146
163
|
if (activeRowId === null) return;
|
|
147
164
|
const el = elements.current.get(activeRowId);
|
|
148
165
|
if (el && typeof el.scrollIntoView === "function") el.scrollIntoView({ block: "nearest" });
|
|
166
|
+
else if (!el && paging.current.reveal) {
|
|
167
|
+
const list = latest.current.rows;
|
|
168
|
+
const i = list.findIndex((r) => idOf(r) === activeRowId);
|
|
169
|
+
if (i >= 0) paging.current.reveal(list[i], i);
|
|
170
|
+
}
|
|
149
171
|
}, [activeRowId]);
|
|
150
172
|
const onKeyDown = (e, row) => {
|
|
151
|
-
if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey
|
|
173
|
+
if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey) return;
|
|
152
174
|
if (!within(e.currentTarget, e.target)) return;
|
|
153
175
|
if (ownsKeys(e.target)) return;
|
|
176
|
+
const toggleSelect = paging.current.onToggleSelect;
|
|
177
|
+
if (e.key === " " && toggleSelect) {
|
|
178
|
+
if (closestOf(e.target, "a,button") !== null && e.target !== e.currentTarget) return;
|
|
179
|
+
e.preventDefault();
|
|
180
|
+
toggleSelect(row, e.shiftKey);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (e.shiftKey) return;
|
|
154
184
|
const id = idOf(row);
|
|
155
185
|
switch (e.key) {
|
|
156
186
|
case "ArrowDown":
|
|
@@ -193,10 +223,12 @@ function useRowActivation(options) {
|
|
|
193
223
|
const rowProps = (row) => {
|
|
194
224
|
if (!enabled) return {};
|
|
195
225
|
const id = idOf(row);
|
|
226
|
+
const isSelected = paging.current.isSelected;
|
|
196
227
|
return {
|
|
197
228
|
ref: refFor(id),
|
|
198
229
|
tabIndex: id === tabStopId ? 0 : -1,
|
|
199
|
-
"aria-selected": id === activeRowId,
|
|
230
|
+
"aria-selected": isSelected ? isSelected(id) : id === activeRowId,
|
|
231
|
+
...isSelected ? { "aria-current": id === activeRowId ? "true" : void 0 } : {},
|
|
200
232
|
"data-active": id === activeRowId ? "true" : void 0,
|
|
201
233
|
onKeyDown: (e) => onKeyDown(e, row),
|
|
202
234
|
onFocus: (e) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRowActivation.js","names":[],"sources":["../../src/rows/useRowActivation.ts"],"sourcesContent":["// Row activation and keyboard movement over a list of rows: the active row, a roving tab\n// stop, ArrowUp / ArrowDown / j / k / Home / End / Enter, and a click that activates. The\n// table and the cards use it; a host renderer gets the same behaviour from\n// `@jsudc/react/headless`. No JSX.\nimport type { Row } from \"@jsudc/core\";\nimport {\n type FocusEvent,\n type KeyboardEvent,\n type MouseEvent,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\n\n/**\n * The activation props of `UdcDataView` and of `RendererProps`. All optional;\n * with none of them a list behaves as before 0.4.0 (no tab stop on the rows,\n * no keys, no active row).\n */\nexport interface RowActivationProps {\n /** A row was activated: Enter on it, or a plain click (no modifier, the main button). */\n onRowActivate?: ((row: Row) => void) | undefined;\n /**\n * The row drawn as active (`aria-selected=\"true\"`, `data-active`, the\n * `--selected` background). Passed: controlled, the host moves it in\n * `onActiveRowChange`; `null` is \"none\". Left out: the list keeps it itself.\n */\n activeRowId?: string | null | undefined;\n /**\n * The active row changed by the user: moved by the keys (without Enter) or a\n * click on another row (before `onRowActivate`). Preview on move here.\n */\n onActiveRowChange?: ((row: Row | null) => void) | undefined;\n}\n\n/** Is activation on: any of the three props passed? */\nexport function rowActivationEnabled(p: RowActivationProps): boolean {\n return (\n p.onRowActivate !== undefined ||\n p.activeRowId !== undefined ||\n p.onActiveRowChange !== undefined\n );\n}\n\nexport interface UseRowActivationOptions extends RowActivationProps {\n /** The loaded rows, in the order they are drawn. */\n rows: readonly Row[];\n /** Infinite mode: moving past the last loaded row asks for the next page. */\n hasNextPage?: boolean | undefined;\n isFetchingNextPage?: boolean | undefined;\n fetchNextPage?: (() => unknown) | undefined;\n /** Override the default, `rowActivationEnabled(options)`. */\n enabled?: boolean | undefined;\n}\n\n/** What to spread on the element of one row (a `<tr>`, a card, an `<li>`). */\nexport interface RowActivationRowProps {\n ref: (el: HTMLElement | null) => void;\n /** One tab stop for the list: the active row, else the last focused one, else the first. */\n tabIndex: 0 | -1;\n \"aria-selected\": boolean;\n /** `\"true\"` on the active row: a stable hook for CSS (`.udc-row[data-active]`). */\n \"data-active\": \"true\" | undefined;\n onKeyDown: (e: KeyboardEvent<HTMLElement>) => void;\n onFocus: (e: FocusEvent<HTMLElement>) => void;\n onBlur: (e: FocusEvent<HTMLElement>) => void;\n}\n\nexport interface RowActivation {\n /** Off: `rowProps` is `{}` and the handlers do nothing. */\n enabled: boolean;\n /** The active row's id when it is among `rows`, else `null`. */\n activeRowId: string | null;\n /** The row holding the list's tab stop. */\n tabStopId: string | null;\n /** The props of one row's element (`{}` when off). */\n rowProps: (row: Row) => RowActivationRowProps | Record<string, never>;\n /**\n * A click on the row: a plain click activates it (and focuses it, unless the\n * click went to a focusable cell). A modified or non-main-button click, or one\n * on a link, button, input or menu, is left alone. `true` when it activated.\n */\n handleClick: (e: MouseEvent<HTMLElement>, row: Row) => boolean;\n /** Activate `row` as Enter does: make it active, then `onRowActivate`. */\n activate: (row: Row) => void;\n /** Move the active row, as the keys do, and focus it. */\n move: (to: \"next\" | \"previous\" | \"first\" | \"last\") => void;\n}\n\n/** Elements whose keys belong to them: an input, a cell editor, a menu, a dialog, a list box. */\nconst OWNS_KEYS =\n 'input,textarea,select,[contenteditable=\"\"],[contenteditable=\"true\"],[role=\"menu\"],[role=\"menubar\"],[role=\"dialog\"],[role=\"alertdialog\"],[role=\"listbox\"],[role=\"combobox\"],[role=\"textbox\"],[data-cell-editor]';\n/** Where a click is the control's, not the row's. */\nconst OWNS_CLICK = `a,button,label,${OWNS_KEYS}`;\n\n// Duck-typed, so an element of another realm (an iframe) counts too.\nfunction closestOf(target: EventTarget | null, selector: string): Element | null {\n const el = target as Element | null;\n return el && typeof el.closest === \"function\" ? el.closest(selector) : null;\n}\n\n/** Is `target` inside `container` (a key or click from a portal bubbles through React too)? */\nfunction within(container: HTMLElement, target: EventTarget | null): boolean {\n const node = target as Node | null;\n return !!node && typeof node.nodeType === \"number\" && container.contains(node);\n}\n\n/** Does a key pressed on `target` belong to it rather than to the list? */\nexport function ownsKeys(target: EventTarget | null): boolean {\n if ((target as HTMLElement | null)?.isContentEditable === true) return true;\n return closestOf(target, OWNS_KEYS) !== null;\n}\n\nconst idOf = (r: Row) => r.__meta.id;\n\n/**\n * The active row of a list and the keys that move it. Spread `rowProps(row)`\n * on each row's element, call `handleClick` from its `onClick`, and give the\n * list `role=\"grid\"` (rows `role=\"row\"`) while `enabled`.\n */\nexport function useRowActivation(options: UseRowActivationOptions): RowActivation {\n const { rows, activeRowId: controlledId, onRowActivate, onActiveRowChange } = options;\n const enabled = options.enabled ?? rowActivationEnabled(options);\n const controlled = controlledId !== undefined;\n const [ownId, setOwnId] = useState<string | null>(null);\n const [focusId, setFocusId] = useState<string | null>(null);\n const rawId = controlled ? controlledId : ownId;\n const has = (id: string | null): id is string => id !== null && rows.some((r) => idOf(r) === id);\n const activeRowId = enabled && has(rawId) ? rawId : null;\n const tabStopId = !enabled\n ? null\n : (activeRowId ?? (has(focusId) ? focusId : null) ?? (rows[0] ? idOf(rows[0]) : null));\n\n // The latest values, for handlers that outlive a render.\n const latest = useRef({ rows, activeRowId, onRowActivate, onActiveRowChange, controlled });\n latest.current = { rows, activeRowId, onRowActivate, onActiveRowChange, controlled };\n const paging = useRef(options);\n paging.current = options;\n\n // One stable ref callback per row id, so React does not detach and reattach each render.\n const elements = useRef(new Map<string, HTMLElement>());\n const refs = useRef(new Map<string, (el: HTMLElement | null) => void>());\n const refFor = (id: string) => {\n let cb = refs.current.get(id);\n if (!cb) {\n cb = (el) => {\n if (el) elements.current.set(id, el);\n else elements.current.delete(id);\n };\n refs.current.set(id, cb);\n }\n return cb;\n };\n\n /** The row id that had focus while the list had it; kept across a refetch that unmounts rows. */\n const focusedRef = useRef<string | null>(null);\n /** Infinite mode: the last row when ArrowDown asked for the next page; moves past it on arrival. */\n const pendingRef = useRef<string | null>(null);\n\n const focusRow = useCallback((id: string) => {\n const el = elements.current.get(id);\n if (!el) return;\n el.focus({ preventScroll: true });\n if (typeof el.scrollIntoView === \"function\") el.scrollIntoView({ block: \"nearest\" });\n }, []);\n\n const changeActive = useCallback((row: Row) => {\n const now = latest.current;\n if (now.activeRowId === idOf(row)) return;\n if (!now.controlled) setOwnId(idOf(row));\n now.onActiveRowChange?.(row);\n }, []);\n\n const go = useCallback(\n (row: Row) => {\n setFocusId(idOf(row));\n focusedRef.current = idOf(row);\n changeActive(row);\n focusRow(idOf(row));\n },\n [changeActive, focusRow],\n );\n\n const activate = useCallback(\n (row: Row) => {\n changeActive(row);\n latest.current.onRowActivate?.(row);\n },\n [changeActive],\n );\n\n const step = useCallback(\n (from: string | null, to: \"next\" | \"previous\" | \"first\" | \"last\") => {\n const list = latest.current.rows;\n if (list.length === 0) return;\n if (to === \"first\") return go(list[0] as Row);\n const last = list.length - 1;\n if (to === \"last\") return go(list[last] as Row);\n const i = from === null ? -1 : list.findIndex((r) => idOf(r) === from);\n if (i < 0) return go(list[0] as Row);\n const next = to === \"next\" ? i + 1 : i - 1;\n if (next < 0) return;\n if (next > last) {\n const { hasNextPage, isFetchingNextPage, fetchNextPage } = paging.current;\n if (hasNextPage && fetchNextPage) {\n pendingRef.current = idOf(list[last] as Row);\n if (!isFetchingNextPage) fetchNextPage();\n }\n return;\n }\n go(list[next] as Row);\n },\n [go],\n );\n\n const move = useCallback(\n (to: \"next\" | \"previous\" | \"first\" | \"last\") => {\n const now = latest.current;\n step(now.activeRowId ?? focusedRef.current, to);\n },\n [step],\n );\n\n // A page arrived after ArrowDown on the last row: continue onto its first row.\n useEffect(() => {\n const pending = pendingRef.current;\n if (!enabled || pending === null) return;\n const i = rows.findIndex((r) => idOf(r) === pending);\n const next = i >= 0 ? rows[i + 1] : undefined;\n if (next) {\n pendingRef.current = null;\n go(next);\n } else if (i < 0 || (!options.isFetchingNextPage && !options.hasNextPage)) {\n pendingRef.current = null;\n }\n }, [enabled, rows, go, options.isFetchingNextPage, options.hasNextPage]);\n\n // Rows unmounted under the focus (a refetch drawing skeletons, a sort): give it back by id.\n // biome-ignore lint/correctness/useExhaustiveDependencies: `rows` is the trigger, not an input\n useLayoutEffect(() => {\n const id = focusedRef.current;\n if (!enabled || id === null) return;\n const el = elements.current.get(id);\n if (!el) return;\n const active = typeof document === \"undefined\" ? null : document.activeElement;\n if (active === el) return;\n if (active === null || active === document.body) el.focus({ preventScroll: true });\n }, [enabled, rows]);\n\n // The active row set from outside (the host opened a message) is scrolled into view.\n useEffect(() => {\n if (activeRowId === null) return;\n const el = elements.current.get(activeRowId);\n if (el && typeof el.scrollIntoView === \"function\") el.scrollIntoView({ block: \"nearest\" });\n }, [activeRowId]);\n\n const onKeyDown = (e: KeyboardEvent<HTMLElement>, row: Row) => {\n if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return;\n // A key from a portalled menu or dialog bubbles through React to here: not the list's.\n if (!within(e.currentTarget, e.target)) return;\n if (ownsKeys(e.target)) return;\n const id = idOf(row);\n switch (e.key) {\n case \"ArrowDown\":\n case \"j\":\n step(id, \"next\");\n break;\n case \"ArrowUp\":\n case \"k\":\n step(id, \"previous\");\n break;\n case \"Home\":\n step(id, \"first\");\n break;\n case \"End\":\n step(id, \"last\");\n break;\n case \"Enter\":\n // Enter on a link or a button in the row is that control's.\n if (closestOf(e.target, \"a,button\") !== null && e.target !== e.currentTarget) return;\n activate(row);\n break;\n default:\n return;\n }\n e.preventDefault();\n };\n\n const handleClick = (e: MouseEvent<HTMLElement>, row: Row): boolean => {\n if (!enabled || e.defaultPrevented) return false;\n if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return false;\n if (!within(e.currentTarget, e.target)) return false;\n if (closestOf(e.target, OWNS_CLICK)) return false;\n const id = idOf(row);\n setFocusId(id);\n // A click in a focusable cell (an editable one) keeps the focus there.\n const focusable = closestOf(e.target, \"[tabindex]\");\n if (!focusable || focusable === e.currentTarget) {\n focusedRef.current = id;\n elements.current.get(id)?.focus({ preventScroll: true });\n }\n activate(row);\n return true;\n };\n\n const rowProps = (row: Row): RowActivationRowProps | Record<string, never> => {\n if (!enabled) return {};\n const id = idOf(row);\n return {\n ref: refFor(id),\n tabIndex: id === tabStopId ? 0 : -1,\n \"aria-selected\": id === activeRowId,\n \"data-active\": id === activeRowId ? \"true\" : undefined,\n onKeyDown: (e) => onKeyDown(e, row),\n onFocus: (e) => {\n if (e.target !== e.currentTarget) return;\n focusedRef.current = id;\n setFocusId(id);\n },\n onBlur: (e) => {\n // Focus left the list (not to another row or a cell of it): forget it.\n const list = e.currentTarget.parentElement;\n if (!list || !within(list, e.relatedTarget)) focusedRef.current = null;\n },\n };\n };\n\n return { enabled, activeRowId, tabStopId, rowProps, handleClick, activate, move };\n}\n"],"mappings":";;;AAsCA,SAAgB,qBAAqB,GAAgC;CACnE,OACE,EAAE,kBAAkB,KAAA,KACpB,EAAE,gBAAgB,KAAA,KAClB,EAAE,sBAAsB,KAAA;AAE5B;;AAgDA,IAAM,YACJ;;AAEF,IAAM,aAAa,kBAAkB;AAGrC,SAAS,UAAU,QAA4B,UAAkC;CAC/E,MAAM,KAAK;CACX,OAAO,MAAM,OAAO,GAAG,YAAY,aAAa,GAAG,QAAQ,QAAQ,IAAI;AACzE;;AAGA,SAAS,OAAO,WAAwB,QAAqC;CAC3E,MAAM,OAAO;CACb,OAAO,CAAC,CAAC,QAAQ,OAAO,KAAK,aAAa,YAAY,UAAU,SAAS,IAAI;AAC/E;;AAGA,SAA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OAAO,EAAE;GACd,UAAU,OAAO,YAAY,IAAI;GACjC,iBAAiB,OAAO;GACxB,eAAe,OAAO,cAAc,SAAS,KAAA;GAC7C,YAAY,MAAM,UAAU,GAAG,GAAG;GAClC,UAAU,MAAM;IACd,IAAI,EAAE,WAAW,EAAE,eAAe;IAClC,WAAW,UAAU;IACrB,WAAW,EAAE;GACf;GACA,SAAS,MAAM;IAEb,MAAM,OAAO,EAAE,cAAc;IAC7B,IAAI,CAAC,QAAQ,CAAC,OAAO,MAAM,EAAE,aAAa,GAAG,WAAW,UAAU;GACpE;EACF;CACF;CAEA,OAAO;EAAE;EAAS;EAAa;EAAW;EAAU;EAAa;EAAU;CAAK;AAClF"}
|
|
1
|
+
{"version":3,"file":"useRowActivation.js","names":[],"sources":["../../src/rows/useRowActivation.ts"],"sourcesContent":["// Row activation and keyboard movement over a list of rows: the active row, a roving tab\n// stop, ArrowUp / ArrowDown / j / k / Home / End / Enter, and a click that activates. The\n// table and the cards use it; a host renderer gets the same behaviour from\n// `@jsudc/react/headless`. No JSX.\nimport type { Row } from \"@jsudc/core\";\nimport {\n type FocusEvent,\n type KeyboardEvent,\n type MouseEvent,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\n\n/**\n * The activation props of `UdcDataView` and of `RendererProps`. All optional;\n * with none of them a list behaves as before 0.4.0 (no tab stop on the rows,\n * no keys, no active row).\n */\nexport interface RowActivationProps {\n /** A row was activated: Enter on it, or a plain click (no modifier, the main button). */\n onRowActivate?: ((row: Row) => void) | undefined;\n /**\n * The row drawn as active (`aria-selected=\"true\"`, `data-active`, the\n * `--selected` background). Passed: controlled, the host moves it in\n * `onActiveRowChange`; `null` is \"none\". Left out: the list keeps it itself.\n */\n activeRowId?: string | null | undefined;\n /**\n * The active row changed by the user: moved by the keys (without Enter) or a\n * click on another row (before `onRowActivate`). Preview on move here.\n */\n onActiveRowChange?: ((row: Row | null) => void) | undefined;\n}\n\n/** Is activation on: any of the three props passed? */\nexport function rowActivationEnabled(p: RowActivationProps): boolean {\n return (\n p.onRowActivate !== undefined ||\n p.activeRowId !== undefined ||\n p.onActiveRowChange !== undefined\n );\n}\n\nexport interface UseRowActivationOptions extends RowActivationProps {\n /** The loaded rows, in the order they are drawn. */\n rows: readonly Row[];\n /** Infinite mode: moving past the last loaded row asks for the next page. */\n hasNextPage?: boolean | undefined;\n isFetchingNextPage?: boolean | undefined;\n fetchNextPage?: (() => unknown) | undefined;\n /** Override the default, `rowActivationEnabled(options)`. */\n enabled?: boolean | undefined;\n /**\n * Multiselect is on (0.5.0): `aria-selected` then says whether the row is\n * selected (ARIA's multi-select grid), and the active row is the one holding\n * the focus, marked `aria-current=\"true\"` and `data-active`. Absent: as in\n * 0.4.0, `aria-selected` marks the active row.\n */\n isSelected?: ((id: string) => boolean) | undefined;\n /** Space on a row toggles its selection (Shift+Space: a range from the last toggled row). */\n onToggleSelect?: ((row: Row, range: boolean) => void) | undefined;\n /**\n * A windowed list (0.5.0; the table's long lists) mounts only some rows: when the keys move\n * to a row whose element is not mounted, this is called to scroll it in and mount it, and\n * the row takes the focus the moment its element attaches. Absent: every row is mounted.\n */\n reveal?: ((row: Row, index: number) => void) | undefined;\n}\n\n/** What to spread on the element of one row (a `<tr>`, a card, an `<li>`). */\nexport interface RowActivationRowProps {\n ref: (el: HTMLElement | null) => void;\n /** One tab stop for the list: the active row, else the last focused one, else the first. */\n tabIndex: 0 | -1;\n \"aria-selected\": boolean;\n /** With `isSelected` (multiselect): `\"true\"` on the active row, whose `aria-selected` is its selection. */\n \"aria-current\"?: \"true\" | undefined;\n /** `\"true\"` on the active row: a stable hook for CSS (`.udc-row[data-active]`). */\n \"data-active\": \"true\" | undefined;\n onKeyDown: (e: KeyboardEvent<HTMLElement>) => void;\n onFocus: (e: FocusEvent<HTMLElement>) => void;\n onBlur: (e: FocusEvent<HTMLElement>) => void;\n}\n\nexport interface RowActivation {\n /** Off: `rowProps` is `{}` and the handlers do nothing. */\n enabled: boolean;\n /** The active row's id when it is among `rows`, else `null`. */\n activeRowId: string | null;\n /** The row holding the list's tab stop. */\n tabStopId: string | null;\n /** The props of one row's element (`{}` when off). */\n rowProps: (row: Row) => RowActivationRowProps | Record<string, never>;\n /**\n * A click on the row: a plain click activates it (and focuses it, unless the\n * click went to a focusable cell). A modified or non-main-button click, or one\n * on a link, button, input or menu, is left alone. `true` when it activated.\n */\n handleClick: (e: MouseEvent<HTMLElement>, row: Row) => boolean;\n /** Activate `row` as Enter does: make it active, then `onRowActivate`. */\n activate: (row: Row) => void;\n /** Move the active row, as the keys do, and focus it. */\n move: (to: \"next\" | \"previous\" | \"first\" | \"last\") => void;\n}\n\n/** Elements whose keys belong to them: an input, a cell editor, a menu, a dialog, a list box. */\nconst OWNS_KEYS =\n 'input,textarea,select,[contenteditable=\"\"],[contenteditable=\"true\"],[role=\"menu\"],[role=\"menubar\"],[role=\"dialog\"],[role=\"alertdialog\"],[role=\"listbox\"],[role=\"combobox\"],[role=\"textbox\"],[data-cell-editor]';\n/** Where a click is the control's, not the row's. */\nconst OWNS_CLICK = `a,button,label,${OWNS_KEYS}`;\n\n// Duck-typed, so an element of another realm (an iframe) counts too.\nfunction closestOf(target: EventTarget | null, selector: string): Element | null {\n const el = target as Element | null;\n return el && typeof el.closest === \"function\" ? el.closest(selector) : null;\n}\n\n/** Is `target` inside `container` (a key or click from a portal bubbles through React too)? */\nfunction within(container: HTMLElement, target: EventTarget | null): boolean {\n const node = target as Node | null;\n return !!node && typeof node.nodeType === \"number\" && container.contains(node);\n}\n\n/** Does a key pressed on `target` belong to it rather than to the list? */\nexport function ownsKeys(target: EventTarget | null): boolean {\n if ((target as HTMLElement | null)?.isContentEditable === true) return true;\n return closestOf(target, OWNS_KEYS) !== null;\n}\n\nconst idOf = (r: Row) => r.__meta.id;\n\n/**\n * The active row of a list and the keys that move it. Spread `rowProps(row)`\n * on each row's element, call `handleClick` from its `onClick`, and give the\n * list `role=\"grid\"` (rows `role=\"row\"`) while `enabled`.\n */\nexport function useRowActivation(options: UseRowActivationOptions): RowActivation {\n const { rows, activeRowId: controlledId, onRowActivate, onActiveRowChange } = options;\n const enabled = options.enabled ?? rowActivationEnabled(options);\n const controlled = controlledId !== undefined;\n const [ownId, setOwnId] = useState<string | null>(null);\n const [focusId, setFocusId] = useState<string | null>(null);\n const rawId = controlled ? controlledId : ownId;\n const has = (id: string | null): id is string => id !== null && rows.some((r) => idOf(r) === id);\n const activeRowId = enabled && has(rawId) ? rawId : null;\n const tabStopId = !enabled\n ? null\n : (activeRowId ?? (has(focusId) ? focusId : null) ?? (rows[0] ? idOf(rows[0]) : null));\n\n // The latest values, for handlers that outlive a render.\n const latest = useRef({ rows, activeRowId, onRowActivate, onActiveRowChange, controlled });\n latest.current = { rows, activeRowId, onRowActivate, onActiveRowChange, controlled };\n const paging = useRef(options);\n paging.current = options;\n\n /** A windowed list: the row the keys moved to before it was mounted; focused when it attaches. */\n const revealRef = useRef<string | null>(null);\n // One stable ref callback per row id, so React does not detach and reattach each render.\n const elements = useRef(new Map<string, HTMLElement>());\n const refs = useRef(new Map<string, (el: HTMLElement | null) => void>());\n const refFor = (id: string) => {\n let cb = refs.current.get(id);\n if (!cb) {\n cb = (el) => {\n if (el) {\n elements.current.set(id, el);\n // A windowed list mounted the row the keys moved to: it takes the focus now.\n if (revealRef.current === id) {\n revealRef.current = null;\n el.focus({ preventScroll: true });\n }\n } else elements.current.delete(id);\n };\n refs.current.set(id, cb);\n }\n return cb;\n };\n\n /** The row id that had focus while the list had it; kept across a refetch that unmounts rows. */\n const focusedRef = useRef<string | null>(null);\n /** Infinite mode: the last row when ArrowDown asked for the next page; moves past it on arrival. */\n const pendingRef = useRef<string | null>(null);\n\n const focusRow = useCallback((id: string) => {\n const el = elements.current.get(id);\n if (!el) {\n const reveal = paging.current.reveal;\n const list = latest.current.rows;\n const i = list.findIndex((r) => idOf(r) === id);\n if (reveal && i >= 0) {\n revealRef.current = id;\n reveal(list[i] as Row, i);\n }\n return;\n }\n revealRef.current = null;\n el.focus({ preventScroll: true });\n if (typeof el.scrollIntoView === \"function\") el.scrollIntoView({ block: \"nearest\" });\n }, []);\n\n const changeActive = useCallback((row: Row) => {\n const now = latest.current;\n if (now.activeRowId === idOf(row)) return;\n if (!now.controlled) setOwnId(idOf(row));\n now.onActiveRowChange?.(row);\n }, []);\n\n const go = useCallback(\n (row: Row) => {\n setFocusId(idOf(row));\n focusedRef.current = idOf(row);\n changeActive(row);\n focusRow(idOf(row));\n },\n [changeActive, focusRow],\n );\n\n const activate = useCallback(\n (row: Row) => {\n changeActive(row);\n latest.current.onRowActivate?.(row);\n },\n [changeActive],\n );\n\n const step = useCallback(\n (from: string | null, to: \"next\" | \"previous\" | \"first\" | \"last\") => {\n const list = latest.current.rows;\n if (list.length === 0) return;\n if (to === \"first\") return go(list[0] as Row);\n const last = list.length - 1;\n if (to === \"last\") return go(list[last] as Row);\n const i = from === null ? -1 : list.findIndex((r) => idOf(r) === from);\n if (i < 0) return go(list[0] as Row);\n const next = to === \"next\" ? i + 1 : i - 1;\n if (next < 0) return;\n if (next > last) {\n const { hasNextPage, isFetchingNextPage, fetchNextPage } = paging.current;\n if (hasNextPage && fetchNextPage) {\n pendingRef.current = idOf(list[last] as Row);\n if (!isFetchingNextPage) fetchNextPage();\n }\n return;\n }\n go(list[next] as Row);\n },\n [go],\n );\n\n const move = useCallback(\n (to: \"next\" | \"previous\" | \"first\" | \"last\") => {\n const now = latest.current;\n step(now.activeRowId ?? focusedRef.current, to);\n },\n [step],\n );\n\n // A page arrived after ArrowDown on the last row: continue onto its first row.\n useEffect(() => {\n const pending = pendingRef.current;\n if (!enabled || pending === null) return;\n const i = rows.findIndex((r) => idOf(r) === pending);\n const next = i >= 0 ? rows[i + 1] : undefined;\n if (next) {\n pendingRef.current = null;\n go(next);\n } else if (i < 0 || (!options.isFetchingNextPage && !options.hasNextPage)) {\n pendingRef.current = null;\n }\n }, [enabled, rows, go, options.isFetchingNextPage, options.hasNextPage]);\n\n // Rows unmounted under the focus (a refetch drawing skeletons, a sort): give it back by id.\n // biome-ignore lint/correctness/useExhaustiveDependencies: `rows` is the trigger, not an input\n useLayoutEffect(() => {\n const id = focusedRef.current;\n if (!enabled || id === null) return;\n const el = elements.current.get(id);\n if (!el) return;\n const active = typeof document === \"undefined\" ? null : document.activeElement;\n if (active === el) return;\n if (active === null || active === document.body) el.focus({ preventScroll: true });\n }, [enabled, rows]);\n\n // The active row set from outside (the host opened a message) is scrolled into view.\n useEffect(() => {\n if (activeRowId === null) return;\n const el = elements.current.get(activeRowId);\n if (el && typeof el.scrollIntoView === \"function\") el.scrollIntoView({ block: \"nearest\" });\n else if (!el && paging.current.reveal) {\n // A windowed list whose active row is not mounted: scroll it in (the focus stays put).\n const list = latest.current.rows;\n const i = list.findIndex((r) => idOf(r) === activeRowId);\n if (i >= 0) paging.current.reveal(list[i] as Row, i);\n }\n }, [activeRowId]);\n\n const onKeyDown = (e: KeyboardEvent<HTMLElement>, row: Row) => {\n if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey) return;\n // A key from a portalled menu or dialog bubbles through React to here: not the list's.\n if (!within(e.currentTarget, e.target)) return;\n if (ownsKeys(e.target)) return;\n // Space toggles the row's selection when the list selects (0.5.0); unbound otherwise.\n const toggleSelect = paging.current.onToggleSelect;\n if (e.key === \" \" && toggleSelect) {\n if (closestOf(e.target, \"a,button\") !== null && e.target !== e.currentTarget) return;\n e.preventDefault();\n toggleSelect(row, e.shiftKey);\n return;\n }\n if (e.shiftKey) return;\n const id = idOf(row);\n switch (e.key) {\n case \"ArrowDown\":\n case \"j\":\n step(id, \"next\");\n break;\n case \"ArrowUp\":\n case \"k\":\n step(id, \"previous\");\n break;\n case \"Home\":\n step(id, \"first\");\n break;\n case \"End\":\n step(id, \"last\");\n break;\n case \"Enter\":\n // Enter on a link or a button in the row is that control's.\n if (closestOf(e.target, \"a,button\") !== null && e.target !== e.currentTarget) return;\n activate(row);\n break;\n default:\n return;\n }\n e.preventDefault();\n };\n\n const handleClick = (e: MouseEvent<HTMLElement>, row: Row): boolean => {\n if (!enabled || e.defaultPrevented) return false;\n if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return false;\n if (!within(e.currentTarget, e.target)) return false;\n if (closestOf(e.target, OWNS_CLICK)) return false;\n const id = idOf(row);\n setFocusId(id);\n // A click in a focusable cell (an editable one) keeps the focus there.\n const focusable = closestOf(e.target, \"[tabindex]\");\n if (!focusable || focusable === e.currentTarget) {\n focusedRef.current = id;\n elements.current.get(id)?.focus({ preventScroll: true });\n }\n activate(row);\n return true;\n };\n\n const rowProps = (row: Row): RowActivationRowProps | Record<string, never> => {\n if (!enabled) return {};\n const id = idOf(row);\n const isSelected = paging.current.isSelected;\n return {\n ref: refFor(id),\n tabIndex: id === tabStopId ? 0 : -1,\n \"aria-selected\": isSelected ? isSelected(id) : id === activeRowId,\n ...(isSelected ? { \"aria-current\": id === activeRowId ? \"true\" : undefined } : {}),\n \"data-active\": id === activeRowId ? \"true\" : undefined,\n onKeyDown: (e) => onKeyDown(e, row),\n onFocus: (e) => {\n if (e.target !== e.currentTarget) return;\n focusedRef.current = id;\n setFocusId(id);\n },\n onBlur: (e) => {\n // Focus left the list (not to another row or a cell of it): forget it.\n const list = e.currentTarget.parentElement;\n if (!list || !within(list, e.relatedTarget)) focusedRef.current = null;\n },\n };\n };\n\n return { enabled, activeRowId, tabStopId, rowProps, handleClick, activate, move };\n}\n"],"mappings":";;;AAsCA,SAAgB,qBAAqB,GAAgC;CACnE,OACE,EAAE,kBAAkB,KAAA,KACpB,EAAE,gBAAgB,KAAA,KAClB,EAAE,sBAAsB,KAAA;AAE5B;;AAiEA,IAAM,YACJ;;AAEF,IAAM,aAAa,kBAAkB;AAGrC,SAAS,UAAU,QAA4B,UAAkC;CAC/E,MAAM,KAAK;CACX,OAAO,MAAM,OAAO,GAAG,YAAY,aAAa,GAAG,QAAQ,QAAQ,IAAI;AACzE;;AAGA,SAAS,OAAO,WAAwB,QAAqC;C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