@jsudc/react 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -4
- package/dist/calendar/EventDetail.js.map +1 -1
- package/dist/data-view/FilterBuilder.d.ts +4 -2
- package/dist/data-view/FilterBuilder.js +11 -2
- package/dist/data-view/FilterBuilder.js.map +1 -1
- package/dist/data-view/FilterChips.d.ts +10 -2
- package/dist/data-view/FilterChips.js +14 -2
- package/dist/data-view/FilterChips.js.map +1 -1
- package/dist/data-view/UdcDataView.js +4 -2
- package/dist/data-view/UdcDataView.js.map +1 -1
- package/dist/data-view/liveView.js +2 -2
- package/dist/data-view/liveView.js.map +1 -1
- package/dist/headless.d.ts +3 -0
- package/dist/headless.js +5 -2
- package/dist/i18n/translations.js +16 -0
- package/dist/i18n/translations.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +10 -2
- package/dist/kanban/KanbanCard.d.ts +1 -1
- package/dist/kanban/KanbanCard.js +5 -1
- package/dist/kanban/KanbanCard.js.map +1 -1
- package/dist/kanban/KanbanRenderer.js +72 -67
- package/dist/kanban/KanbanRenderer.js.map +1 -1
- package/dist/kanban/model.d.ts +11 -1
- package/dist/kanban/model.js +29 -3
- package/dist/kanban/model.js.map +1 -1
- package/dist/kanban/useKanbanBoard.d.ts +5 -1
- package/dist/kanban/useKanbanBoard.js +6 -2
- package/dist/kanban/useKanbanBoard.js.map +1 -1
- package/dist/lookup/LookupCombobox.d.ts +18 -0
- package/dist/lookup/LookupCombobox.js +146 -0
- package/dist/lookup/LookupCombobox.js.map +1 -0
- package/dist/lookup/LookupSelectChip.d.ts +17 -0
- package/dist/lookup/LookupSelectChip.js +96 -0
- package/dist/lookup/LookupSelectChip.js.map +1 -0
- package/dist/lookup/LookupValue.d.ts +27 -0
- package/dist/lookup/LookupValue.js +98 -0
- package/dist/lookup/LookupValue.js.map +1 -0
- package/dist/lookup/batch.d.ts +33 -0
- package/dist/lookup/batch.js +69 -0
- package/dist/lookup/batch.js.map +1 -0
- package/dist/lookup/label.d.ts +5 -0
- package/dist/lookup/label.js +16 -0
- package/dist/lookup/label.js.map +1 -0
- package/dist/lookup/links.d.ts +30 -0
- package/dist/lookup/links.js +49 -0
- package/dist/lookup/links.js.map +1 -0
- package/dist/lookup/options.d.ts +28 -0
- package/dist/lookup/options.js +66 -0
- package/dist/lookup/options.js.map +1 -0
- package/dist/lookup/useUdcLookup.d.ts +52 -0
- package/dist/lookup/useUdcLookup.js +96 -0
- package/dist/lookup/useUdcLookup.js.map +1 -0
- package/dist/react-router/UdcReactRouterUrlState.d.ts +6 -1
- package/dist/react-router/UdcReactRouterUrlState.js +16 -3
- package/dist/react-router/UdcReactRouterUrlState.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/table/CellEditor.d.ts +8 -4
- package/dist/table/CellEditor.js +15 -2
- package/dist/table/CellEditor.js.map +1 -1
- package/dist/table/TableRenderer.js +122 -97
- package/dist/table/TableRenderer.js.map +1 -1
- package/dist/table/cells.d.ts +4 -2
- package/dist/table/cells.js +9 -1
- package/dist/table/cells.js.map +1 -1
- package/dist/udc/hooks.d.ts +53 -2
- package/dist/udc/hooks.js +9 -1
- package/dist/udc/hooks.js.map +1 -1
- package/dist/udc/keys.d.ts +5 -0
- package/dist/udc/keys.js +26 -0
- package/dist/udc/keys.js.map +1 -1
- package/dist/udc/provider.d.ts +8 -1
- package/dist/udc/provider.js +6 -1
- package/dist/udc/provider.js.map +1 -1
- package/package.json +4 -4
package/dist/udc/hooks.d.ts
CHANGED
|
@@ -60,6 +60,13 @@ export declare function useUdcDescribe(collection: string, opts?: {
|
|
|
60
60
|
max?: number | undefined;
|
|
61
61
|
ref?: string | undefined;
|
|
62
62
|
label_field?: string | undefined;
|
|
63
|
+
lookup?: {
|
|
64
|
+
[x: string]: unknown;
|
|
65
|
+
collection: string;
|
|
66
|
+
label_field: string;
|
|
67
|
+
key_field?: string | undefined;
|
|
68
|
+
extra_fields?: string[] | undefined;
|
|
69
|
+
} | undefined;
|
|
63
70
|
}>;
|
|
64
71
|
};
|
|
65
72
|
view: {
|
|
@@ -345,6 +352,15 @@ export declare function useUdcDescribe(collection: string, opts?: {
|
|
|
345
352
|
}[];
|
|
346
353
|
apply?: boolean | undefined;
|
|
347
354
|
} | undefined;
|
|
355
|
+
row_link?: {
|
|
356
|
+
[x: string]: unknown;
|
|
357
|
+
collection: string;
|
|
358
|
+
filter: {
|
|
359
|
+
[x: string]: unknown;
|
|
360
|
+
field: string;
|
|
361
|
+
value_from: string;
|
|
362
|
+
};
|
|
363
|
+
} | undefined;
|
|
348
364
|
row_action_defs?: {
|
|
349
365
|
[x: string]: unknown;
|
|
350
366
|
kind: string;
|
|
@@ -557,6 +573,13 @@ export declare function useUdcSchema(collection: string): {
|
|
|
557
573
|
max?: number | undefined;
|
|
558
574
|
ref?: string | undefined;
|
|
559
575
|
label_field?: string | undefined;
|
|
576
|
+
lookup?: {
|
|
577
|
+
[x: string]: unknown;
|
|
578
|
+
collection: string;
|
|
579
|
+
label_field: string;
|
|
580
|
+
key_field?: string | undefined;
|
|
581
|
+
extra_fields?: string[] | undefined;
|
|
582
|
+
} | undefined;
|
|
560
583
|
}>;
|
|
561
584
|
};
|
|
562
585
|
}, Error, Omit<{
|
|
@@ -564,7 +587,7 @@ export declare function useUdcSchema(collection: string): {
|
|
|
564
587
|
name: string;
|
|
565
588
|
fielddef: {
|
|
566
589
|
[x: string]: unknown;
|
|
567
|
-
type: "string" | "
|
|
590
|
+
type: "string" | "date" | "enum" | "text" | "integer" | "year" | "decimal" | "bool" | "datetime" | "image" | "relation" | "string_array" | "rating" | "json" | "lookup" | "lookup_array";
|
|
568
591
|
length?: number | undefined;
|
|
569
592
|
index?: boolean | undefined;
|
|
570
593
|
required?: boolean | undefined;
|
|
@@ -575,6 +598,13 @@ export declare function useUdcSchema(collection: string): {
|
|
|
575
598
|
max?: number | undefined;
|
|
576
599
|
ref?: string | undefined;
|
|
577
600
|
label_field?: string | undefined;
|
|
601
|
+
lookup?: {
|
|
602
|
+
[x: string]: unknown;
|
|
603
|
+
collection: string;
|
|
604
|
+
label_field: string;
|
|
605
|
+
key_field?: string | undefined;
|
|
606
|
+
extra_fields?: string[] | undefined;
|
|
607
|
+
} | undefined;
|
|
578
608
|
};
|
|
579
609
|
position: {
|
|
580
610
|
where: "end" | "before" | "after";
|
|
@@ -599,6 +629,13 @@ export declare function useUdcSchema(collection: string): {
|
|
|
599
629
|
max?: number | undefined;
|
|
600
630
|
ref?: string | undefined;
|
|
601
631
|
label_field?: string | undefined;
|
|
632
|
+
lookup?: {
|
|
633
|
+
[x: string]: unknown;
|
|
634
|
+
collection: string;
|
|
635
|
+
label_field: string;
|
|
636
|
+
key_field?: string | undefined;
|
|
637
|
+
extra_fields?: string[] | undefined;
|
|
638
|
+
} | undefined;
|
|
602
639
|
}>;
|
|
603
640
|
};
|
|
604
641
|
}, Error, Omit<{
|
|
@@ -606,7 +643,7 @@ export declare function useUdcSchema(collection: string): {
|
|
|
606
643
|
name: string;
|
|
607
644
|
fielddef: {
|
|
608
645
|
[x: string]: unknown;
|
|
609
|
-
type: "string" | "
|
|
646
|
+
type: "string" | "date" | "enum" | "text" | "integer" | "year" | "decimal" | "bool" | "datetime" | "image" | "relation" | "string_array" | "rating" | "json" | "lookup" | "lookup_array";
|
|
610
647
|
length?: number | undefined;
|
|
611
648
|
index?: boolean | undefined;
|
|
612
649
|
required?: boolean | undefined;
|
|
@@ -617,6 +654,13 @@ export declare function useUdcSchema(collection: string): {
|
|
|
617
654
|
max?: number | undefined;
|
|
618
655
|
ref?: string | undefined;
|
|
619
656
|
label_field?: string | undefined;
|
|
657
|
+
lookup?: {
|
|
658
|
+
[x: string]: unknown;
|
|
659
|
+
collection: string;
|
|
660
|
+
label_field: string;
|
|
661
|
+
key_field?: string | undefined;
|
|
662
|
+
extra_fields?: string[] | undefined;
|
|
663
|
+
} | undefined;
|
|
620
664
|
};
|
|
621
665
|
}, "collection">, unknown>;
|
|
622
666
|
softDeleteField: import("@tanstack/react-query").UseMutationResult<{
|
|
@@ -637,6 +681,13 @@ export declare function useUdcSchema(collection: string): {
|
|
|
637
681
|
max?: number | undefined;
|
|
638
682
|
ref?: string | undefined;
|
|
639
683
|
label_field?: string | undefined;
|
|
684
|
+
lookup?: {
|
|
685
|
+
[x: string]: unknown;
|
|
686
|
+
collection: string;
|
|
687
|
+
label_field: string;
|
|
688
|
+
key_field?: string | undefined;
|
|
689
|
+
extra_fields?: string[] | undefined;
|
|
690
|
+
} | undefined;
|
|
640
691
|
}>;
|
|
641
692
|
};
|
|
642
693
|
}, Error, string, unknown>;
|
package/dist/udc/hooks.js
CHANGED
|
@@ -310,7 +310,15 @@ function useUdcMutate(collection) {
|
|
|
310
310
|
patchRowEverywhere(qc, collection, vars.id, () => fresh.row);
|
|
311
311
|
} catch {}
|
|
312
312
|
},
|
|
313
|
-
onSettled: () =>
|
|
313
|
+
onSettled: () => Promise.all([
|
|
314
|
+
qc.invalidateQueries({ queryKey: udcKeys.lists(collection) }),
|
|
315
|
+
qc.invalidateQueries({ queryKey: udcKeys.lookups(collection) }),
|
|
316
|
+
qc.invalidateQueries({ queryKey: [
|
|
317
|
+
"udc",
|
|
318
|
+
"lookup-options",
|
|
319
|
+
collection
|
|
320
|
+
] })
|
|
321
|
+
])
|
|
314
322
|
});
|
|
315
323
|
}
|
|
316
324
|
/**
|
package/dist/udc/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","names":[],"sources":["../../src/udc/hooks.ts"],"sourcesContent":["import {\n type ActionRequest,\n type Capabilities,\n type FilterNode,\n isVersionConflict,\n type ListResponse,\n type Row,\n type SortKey,\n} from \"@jsudc/core\";\nimport type { UdcClient } from \"@jsudc/core/client\";\nimport {\n type InfiniteData,\n keepPreviousData,\n type QueryClient,\n useInfiniteQuery,\n useMutation,\n useQuery,\n useQueryClient,\n} from \"@tanstack/react-query\";\nimport { useState } from \"react\";\nimport { useUdcClient } from \"./client.js\";\nimport { type ListKeyParams, type PagingMode, udcKeys } from \"./keys.js\";\n\nexport function useUdcCollections() {\n const client = useUdcClient();\n return useQuery({ queryKey: udcKeys.collections(), queryFn: () => client.collections() });\n}\n\nexport function useUdcDescribe(collection: string, opts: { enabled?: boolean } = {}) {\n const client = useUdcClient();\n return useQuery({\n queryKey: udcKeys.describe(collection),\n queryFn: () => client.describe(collection),\n staleTime: 5 * 60_000,\n enabled: (opts.enabled ?? true) && collection !== \"\",\n });\n}\n\n/** The file a `source_yaml` collection is read from (`source.read`); fetched again on every mount. */\nexport function useUdcSource(collection: string, opts: { enabled?: boolean } = {}) {\n const client = useUdcClient();\n return useQuery({\n queryKey: udcKeys.source(collection),\n queryFn: () => client.sourceRead(collection),\n staleTime: 0,\n enabled: (opts.enabled ?? true) && collection !== \"\",\n });\n}\n\nexport interface UseUdcCollectionArgs {\n collection: string;\n filter?: FilterNode | undefined;\n sort?: SortKey[];\n mode: PagingMode;\n pageLimit: number;\n /** 1-based; pages mode only. */\n page?: number;\n enabled?: boolean;\n /** From `describe`: a source without `cursor` paging is walked by offset in infinite mode too. */\n capabilities?: Pick<Capabilities, \"paging\"> | undefined;\n /** Poll: refetch the loaded rows this often (the view's `refresh_interval_ms`). */\n refetchInterval?: number | undefined;\n}\n\nexport interface UdcCollectionResult {\n rows: Row[];\n total: number | null;\n isLoading: boolean;\n isFetching: boolean;\n error: Error | null;\n refetch: () => void;\n /** Infinite mode only; always false in pages mode. */\n hasNextPage: boolean;\n isFetchingNextPage: boolean;\n fetchNextPage: () => void;\n /** A source serving a fetched copy: when it was fetched, and whether the last refresh failed. */\n fetchedAt: string | null;\n stale: boolean;\n}\n\n/** `refetchInterval` for TanStack: a positive number of ms, else off. */\nexport function pollInterval(ms: number | undefined): number | false {\n return typeof ms === \"number\" && ms > 0 ? ms : false;\n}\n\n/** The freshness of a list answer: `fetched_at` and `stale` when the source sent them. */\nexport function freshnessOf(res: Pick<ListResponse, \"fetched_at\" | \"stale\"> | undefined): {\n fetchedAt: string | null;\n stale: boolean;\n} {\n return { fetchedAt: res?.fetched_at ?? null, stale: res?.stale === true };\n}\n\n/** The `offset` a 1-based page asks for. */\nexport function pageOffset(page: number, limit: number): number {\n return Math.max(0, Math.floor(page) - 1) * limit;\n}\n\n/**\n * Rows of one collection. Infinite mode follows `next_cursor` page by page\n * (`useInfiniteQuery`), or the next `offset` while rows remain when the\n * source pages by offset only; pages mode asks for one `offset` page\n * (`useQuery`). Both hooks are always mounted and the inactive one is\n * disabled, so switching modes keeps each cache warm. `refetchInterval`\n * polls the active one.\n */\nexport function useUdcCollection(args: UseUdcCollectionArgs): UdcCollectionResult {\n const client = useUdcClient();\n const { collection, filter, mode, pageLimit: limit } = args;\n const sort = args.sort ?? [];\n const page = Math.max(1, args.page ?? 1);\n const enabled = args.enabled ?? true;\n const byCursor = args.capabilities?.paging?.includes(\"cursor\") ?? true;\n const refetchInterval = pollInterval(args.refetchInterval);\n\n const infiniteParams: ListKeyParams = { filter, sort, limit, mode: \"infinite\" };\n const infinite = useInfiniteQuery({\n queryKey: udcKeys.list(collection, infiniteParams),\n queryFn: ({ pageParam, signal }) =>\n client.list(\n {\n collection,\n ...(filter ? { filter } : {}),\n sort,\n page:\n typeof pageParam === \"number\"\n ? { limit, offset: pageParam }\n : pageParam\n ? { limit, cursor: pageParam }\n : { limit },\n },\n { signal },\n ),\n initialPageParam: null as string | number | null,\n getNextPageParam: (last, all) => {\n if (byCursor) return last.next_cursor ?? undefined;\n const loaded = all.reduce((n, p) => n + p.rows.length, 0);\n return last.rows.length > 0 && last.total !== null && loaded < last.total\n ? loaded\n : undefined;\n },\n placeholderData: keepPreviousData,\n enabled: enabled && mode === \"infinite\",\n refetchInterval,\n });\n\n const pagesParams: ListKeyParams = { filter, sort, limit, mode: \"pages\", page };\n const paged = useQuery({\n queryKey: udcKeys.list(collection, pagesParams),\n queryFn: ({ signal }) =>\n client.list(\n {\n collection,\n ...(filter ? { filter } : {}),\n sort,\n page: { limit, offset: pageOffset(page, limit) },\n },\n { signal },\n ),\n placeholderData: keepPreviousData,\n enabled: enabled && mode === \"pages\",\n refetchInterval,\n });\n\n if (mode === \"infinite\") {\n const pages = infinite.data?.pages ?? [];\n return {\n rows: pages.flatMap((p) => p.rows),\n total: pages[0]?.total ?? null,\n isLoading: infinite.isLoading,\n isFetching: infinite.isFetching,\n error: infinite.error,\n refetch: () => void infinite.refetch(),\n hasNextPage: infinite.hasNextPage,\n isFetchingNextPage: infinite.isFetchingNextPage,\n fetchNextPage: () => void infinite.fetchNextPage(),\n ...freshnessOf(pages[0]),\n };\n }\n return {\n rows: paged.data?.rows ?? [],\n total: paged.data?.total ?? null,\n isLoading: paged.isLoading,\n isFetching: paged.isFetching,\n error: paged.error,\n refetch: () => void paged.refetch(),\n hasNextPage: false,\n isFetchingNextPage: false,\n fetchNextPage: () => {},\n ...freshnessOf(paged.data),\n };\n}\n\nexport const ALL_ROWS_MAX = 2000;\nconst ALL_ROWS_PAGE = 500;\n\nexport interface FetchAllRowsArgs {\n collection: string;\n filter?: FilterNode | undefined;\n sort?: SortKey[];\n /** Stop after this many rows. */\n max: number;\n /** Rows per `list` call. */\n pageLimit?: number;\n /** Keyset paging unless the source pages by offset only. */\n cursor: boolean;\n signal?: AbortSignal;\n onProgress?: (loaded: number, total: number | null) => void;\n}\n\n/**\n * Every row of a filter, `list` page after page, until `total` or `max`.\n * Follows `next_cursor` when keyset paging is on; a source that answers no\n * cursor while rows remain is walked on by offset. Answers one list whose\n * `total` is the server's (so `rows.length < total` means capped), with the\n * first page's `fetched_at` and `stale`.\n */\nexport async function fetchAllRows(\n client: UdcClient,\n args: FetchAllRowsArgs,\n): Promise<ListResponse> {\n const { collection, filter, max } = args;\n const sort = args.sort ?? [];\n const pageLimit = args.pageLimit ?? ALL_ROWS_PAGE;\n const rows: Row[] = [];\n let total: number | null = null;\n let freshness: Pick<ListResponse, \"fetched_at\" | \"stale\"> = {};\n let cursor: string | null = null;\n let byCursor = args.cursor;\n while (rows.length < max) {\n const limit = Math.min(pageLimit, max - rows.length);\n const page = byCursor\n ? cursor\n ? { limit, cursor }\n : { limit }\n : { limit, offset: rows.length };\n const res = await client.list(\n { collection, ...(filter ? { filter } : {}), sort, page },\n args.signal ? { signal: args.signal } : undefined,\n );\n if (rows.length === 0) {\n freshness = {\n ...(res.fetched_at === undefined ? {} : { fetched_at: res.fetched_at }),\n ...(res.stale === undefined ? {} : { stale: res.stale }),\n };\n }\n rows.push(...res.rows);\n total = res.total;\n args.onProgress?.(rows.length, total);\n if (res.rows.length === 0 || (total !== null && rows.length >= total)) break;\n if (byCursor) {\n if (res.next_cursor) cursor = res.next_cursor;\n else if (total === null) break;\n else byCursor = false;\n } else if (total === null && res.rows.length < limit) {\n break;\n }\n }\n return { ...freshness, rows, next_cursor: null, total: total ?? rows.length };\n}\n\nexport interface UseUdcAllRowsArgs {\n collection: string;\n filter?: FilterNode | undefined;\n sort?: SortKey[];\n /** Default 2,000. */\n max?: number;\n /** From `describe`: whether the source pages by cursor. */\n capabilities?: Pick<Capabilities, \"paging\"> | undefined;\n enabled?: boolean;\n /** Poll: refetch every row this often (the view's `refresh_interval_ms`). */\n refetchInterval?: number | undefined;\n}\n\nexport interface UdcAllRowsResult {\n rows: Row[];\n total: number | null;\n isLoading: boolean;\n isFetching: boolean;\n error: Error | null;\n refetch: () => Promise<unknown>;\n /** More rows match than `max`: only the first `max` are here. */\n capped: boolean;\n /** Rows loaded so far by the fetch in flight, for a progress bar. */\n progress: { loaded: number; total: number | null } | null;\n fetchedAt: string | null;\n stale: boolean;\n}\n\n/**\n * All rows of the current filter in one cached list: what the kanban (and\n * the calendar, tree, map and charts after it) draw from. The cache entry\n * sits under `udcKeys.lists(collection)`, so `useUdcMutate`'s optimistic\n * patches and invalidations reach it like every other list.\n */\nexport function useUdcAllRows(args: UseUdcAllRowsArgs): UdcAllRowsResult {\n const client = useUdcClient();\n const { collection, filter } = args;\n const sort = args.sort ?? [];\n const max = args.max ?? ALL_ROWS_MAX;\n const cursor = args.capabilities?.paging?.includes(\"cursor\") ?? true;\n const [progress, setProgress] = useState<UdcAllRowsResult[\"progress\"]>(null);\n\n const key: ListKeyParams = { filter, sort, limit: max, mode: \"all\" };\n const query = useQuery({\n queryKey: udcKeys.list(collection, key),\n queryFn: async ({ signal }) => {\n setProgress({ loaded: 0, total: null });\n try {\n return await fetchAllRows(client, {\n collection,\n filter,\n sort,\n max,\n cursor,\n signal,\n onProgress: (loaded, total) => setProgress({ loaded, total }),\n });\n } finally {\n setProgress(null);\n }\n },\n placeholderData: keepPreviousData,\n enabled: args.enabled ?? true,\n refetchInterval: pollInterval(args.refetchInterval),\n });\n\n const rows = query.data?.rows ?? [];\n const total = query.data?.total ?? null;\n return {\n rows,\n total,\n isLoading: query.isLoading,\n isFetching: query.isFetching,\n error: query.error,\n refetch: () => query.refetch(),\n capped: total !== null && rows.length < total,\n progress,\n ...freshnessOf(query.data),\n };\n}\n\ntype ListCache = ListResponse | InfiniteData<ListResponse, unknown>;\n\nfunction isInfinite(data: ListCache): data is InfiniteData<ListResponse, unknown> {\n return \"pages\" in data;\n}\n\n/** `data` with every row whose id is `id` passed through `patch`. */\nexport function patchRowInList(\n data: ListCache | undefined,\n id: string,\n patch: (row: Row) => Row,\n): ListCache | undefined {\n if (!data) return data;\n const patchPage = (page: ListResponse): ListResponse =>\n page.rows.some((r) => r.__meta.id === id)\n ? { ...page, rows: page.rows.map((r) => (r.__meta.id === id ? patch(r) : r)) }\n : page;\n return isInfinite(data) ? { ...data, pages: data.pages.map(patchPage) } : patchPage(data);\n}\n\nfunction patchRowEverywhere(\n qc: QueryClient,\n collection: string,\n id: string,\n patch: (row: Row) => Row,\n) {\n qc.setQueriesData<ListCache>({ queryKey: udcKeys.lists(collection) }, (data) =>\n patchRowInList(data, id, patch),\n );\n}\n\nexport type UdcMutateVars = Omit<ActionRequest<\"mutate\">, \"collection\">;\n\n/**\n * Insert / update / delete one row. An update is applied optimistically to\n * the row in every cached list page and rolled back if the server says no.\n * A `version_conflict` additionally re-reads the row, so the cache holds the\n * value that won; the error still reaches the caller. Lists are invalidated\n * once the call settles.\n */\nexport function useUdcMutate(collection: string) {\n const client = useUdcClient();\n const qc = useQueryClient();\n\n return useMutation({\n mutationFn: (vars: UdcMutateVars) => client.mutate({ collection, ...vars }),\n onMutate: async (vars) => {\n await qc.cancelQueries({ queryKey: udcKeys.lists(collection) });\n const snapshot = qc.getQueriesData<ListCache>({ queryKey: udcKeys.lists(collection) });\n const { id, row } = vars;\n if (vars.op === \"update\" && id && row) {\n patchRowEverywhere(qc, collection, id, (r) => ({ ...r, ...row, __meta: r.__meta }));\n }\n return { snapshot };\n },\n onSuccess: (res) => {\n patchRowEverywhere(qc, collection, res.row.__meta.id, () => res.row);\n },\n onError: async (err, vars, ctx) => {\n for (const [key, data] of ctx?.snapshot ?? []) qc.setQueryData(key, data);\n if (isVersionConflict(err) && vars.id) {\n try {\n const fresh = await client.read(collection, vars.id);\n patchRowEverywhere(qc, collection, vars.id, () => fresh.row);\n } catch {\n // The invalidation below refetches the lists anyway.\n }\n }\n },\n onSettled: () => qc.invalidateQueries({ queryKey: udcKeys.lists(collection) }),\n });\n}\n\n/**\n * The three schema edits. Each answers the new schema; `describe` (which\n * derives the columns) and the lists are refetched afterwards.\n */\nexport function useUdcSchema(collection: string) {\n const client = useUdcClient();\n const qc = useQueryClient();\n const onSuccess = async () => {\n await qc.invalidateQueries({ queryKey: udcKeys.describe(collection) });\n await qc.invalidateQueries({ queryKey: udcKeys.lists(collection) });\n };\n\n const addField = useMutation({\n mutationFn: (req: Omit<ActionRequest<\"schema.add_field\">, \"collection\">) =>\n client.schemaAddField({ collection, ...req }),\n onSuccess,\n });\n const updateField = useMutation({\n mutationFn: (req: Omit<ActionRequest<\"schema.update_field\">, \"collection\">) =>\n client.schemaUpdateField({ collection, ...req }),\n onSuccess,\n });\n const softDeleteField = useMutation({\n mutationFn: (field: string) => client.schemaSoftDeleteField({ collection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pB;EACA,YAAY,QAAQ;GAClB,mBAAmB,IAAI,YAAY,IAAI,IAAI,OAAO,UAAU,IAAI,GAAG;EACrE;EACA,SAAS,OAAO,KAAK,MAAM,QAAQ;GACjC,KAAK,MAAM,CAAC,KAAK,SAAS,KAAK,YAAY,CAAC,GAAG,GAAG,aAAa,KAAK,IAAI;GACxE,IAAI,kBAAkB,GAAG,KAAK,KAAK,IACjC,IAAI;IACF,MAAM,QAAQ,MAAM,OAAO,KAAK,YAAY,KAAK,EAAE;IACnD,mBAAmB,IAAI,YAAY,KAAK,UAAU,MAAM,GAAG;GAC7D,QAAQ,CAER;EAEJ;EACA,iBAAiB,GAAG,kBAAkB,EAAE,UAAU,QAAQ,MAAM,UAAU,EAAE,CAAC;CAC/E,CAAC;AACH;;;;;AAMA,SAAgB,aAAa,YAAoB;CAC/C,MAAM,SAAS,aAAa;CAC5B,MAAM,KAAK,eAAe;CAC1B,MAAM,YAAY,YAAY;EAC5B,MAAM,GAAG,kBAAkB,EAAE,UAAU,QAAQ,SAAS,UAAU,EAAE,CAAC;EACrE,MAAM,GAAG,kBAAkB,EAAE,UAAU,QAAQ,MAAM,UAAU,EAAE,CAAC;CACpE;CAgBA,OAAO;EAAE,UAdQ,YAAY;GAC3B,aAAa,QACX,OAAO,eAAe;IAAE;IAAY,GAAG;GAAI,CAAC;GAC9C;EACF,CAUS;EAAU,aATC,YAAY;GAC9B,aAAa,QACX,OAAO,kBAAkB;IAAE;IAAY,GAAG;GAAI,CAAC;GACjD;EACF,CAKmB;EAAa,iBAJR,YAAY;GAClC,aAAa,UAAkB,OAAO,sBAAsB;IAAE;IAAY;GAAM,CAAC;GACjF;EACF,CACgC;CAAgB;AAClD"}
|
|
1
|
+
{"version":3,"file":"hooks.js","names":[],"sources":["../../src/udc/hooks.ts"],"sourcesContent":["import {\n type ActionRequest,\n type Capabilities,\n type FilterNode,\n isVersionConflict,\n type ListResponse,\n type Row,\n type SortKey,\n} from \"@jsudc/core\";\nimport type { UdcClient } from \"@jsudc/core/client\";\nimport {\n type InfiniteData,\n keepPreviousData,\n type QueryClient,\n useInfiniteQuery,\n useMutation,\n useQuery,\n useQueryClient,\n} from \"@tanstack/react-query\";\nimport { useState } from \"react\";\nimport { useUdcClient } from \"./client.js\";\nimport { type ListKeyParams, type PagingMode, udcKeys } from \"./keys.js\";\n\nexport function useUdcCollections() {\n const client = useUdcClient();\n return useQuery({ queryKey: udcKeys.collections(), queryFn: () => client.collections() });\n}\n\nexport function useUdcDescribe(collection: string, opts: { enabled?: boolean } = {}) {\n const client = useUdcClient();\n return useQuery({\n queryKey: udcKeys.describe(collection),\n queryFn: () => client.describe(collection),\n staleTime: 5 * 60_000,\n enabled: (opts.enabled ?? true) && collection !== \"\",\n });\n}\n\n/** The file a `source_yaml` collection is read from (`source.read`); fetched again on every mount. */\nexport function useUdcSource(collection: string, opts: { enabled?: boolean } = {}) {\n const client = useUdcClient();\n return useQuery({\n queryKey: udcKeys.source(collection),\n queryFn: () => client.sourceRead(collection),\n staleTime: 0,\n enabled: (opts.enabled ?? true) && collection !== \"\",\n });\n}\n\nexport interface UseUdcCollectionArgs {\n collection: string;\n filter?: FilterNode | undefined;\n sort?: SortKey[];\n mode: PagingMode;\n pageLimit: number;\n /** 1-based; pages mode only. */\n page?: number;\n enabled?: boolean;\n /** From `describe`: a source without `cursor` paging is walked by offset in infinite mode too. */\n capabilities?: Pick<Capabilities, \"paging\"> | undefined;\n /** Poll: refetch the loaded rows this often (the view's `refresh_interval_ms`). */\n refetchInterval?: number | undefined;\n}\n\nexport interface UdcCollectionResult {\n rows: Row[];\n total: number | null;\n isLoading: boolean;\n isFetching: boolean;\n error: Error | null;\n refetch: () => void;\n /** Infinite mode only; always false in pages mode. */\n hasNextPage: boolean;\n isFetchingNextPage: boolean;\n fetchNextPage: () => void;\n /** A source serving a fetched copy: when it was fetched, and whether the last refresh failed. */\n fetchedAt: string | null;\n stale: boolean;\n}\n\n/** `refetchInterval` for TanStack: a positive number of ms, else off. */\nexport function pollInterval(ms: number | undefined): number | false {\n return typeof ms === \"number\" && ms > 0 ? ms : false;\n}\n\n/** The freshness of a list answer: `fetched_at` and `stale` when the source sent them. */\nexport function freshnessOf(res: Pick<ListResponse, \"fetched_at\" | \"stale\"> | undefined): {\n fetchedAt: string | null;\n stale: boolean;\n} {\n return { fetchedAt: res?.fetched_at ?? null, stale: res?.stale === true };\n}\n\n/** The `offset` a 1-based page asks for. */\nexport function pageOffset(page: number, limit: number): number {\n return Math.max(0, Math.floor(page) - 1) * limit;\n}\n\n/**\n * Rows of one collection. Infinite mode follows `next_cursor` page by page\n * (`useInfiniteQuery`), or the next `offset` while rows remain when the\n * source pages by offset only; pages mode asks for one `offset` page\n * (`useQuery`). Both hooks are always mounted and the inactive one is\n * disabled, so switching modes keeps each cache warm. `refetchInterval`\n * polls the active one.\n */\nexport function useUdcCollection(args: UseUdcCollectionArgs): UdcCollectionResult {\n const client = useUdcClient();\n const { collection, filter, mode, pageLimit: limit } = args;\n const sort = args.sort ?? [];\n const page = Math.max(1, args.page ?? 1);\n const enabled = args.enabled ?? true;\n const byCursor = args.capabilities?.paging?.includes(\"cursor\") ?? true;\n const refetchInterval = pollInterval(args.refetchInterval);\n\n const infiniteParams: ListKeyParams = { filter, sort, limit, mode: \"infinite\" };\n const infinite = useInfiniteQuery({\n queryKey: udcKeys.list(collection, infiniteParams),\n queryFn: ({ pageParam, signal }) =>\n client.list(\n {\n collection,\n ...(filter ? { filter } : {}),\n sort,\n page:\n typeof pageParam === \"number\"\n ? { limit, offset: pageParam }\n : pageParam\n ? { limit, cursor: pageParam }\n : { limit },\n },\n { signal },\n ),\n initialPageParam: null as string | number | null,\n getNextPageParam: (last, all) => {\n if (byCursor) return last.next_cursor ?? undefined;\n const loaded = all.reduce((n, p) => n + p.rows.length, 0);\n return last.rows.length > 0 && last.total !== null && loaded < last.total\n ? loaded\n : undefined;\n },\n placeholderData: keepPreviousData,\n enabled: enabled && mode === \"infinite\",\n refetchInterval,\n });\n\n const pagesParams: ListKeyParams = { filter, sort, limit, mode: \"pages\", page };\n const paged = useQuery({\n queryKey: udcKeys.list(collection, pagesParams),\n queryFn: ({ signal }) =>\n client.list(\n {\n collection,\n ...(filter ? { filter } : {}),\n sort,\n page: { limit, offset: pageOffset(page, limit) },\n },\n { signal },\n ),\n placeholderData: keepPreviousData,\n enabled: enabled && mode === \"pages\",\n refetchInterval,\n });\n\n if (mode === \"infinite\") {\n const pages = infinite.data?.pages ?? [];\n return {\n rows: pages.flatMap((p) => p.rows),\n total: pages[0]?.total ?? null,\n isLoading: infinite.isLoading,\n isFetching: infinite.isFetching,\n error: infinite.error,\n refetch: () => void infinite.refetch(),\n hasNextPage: infinite.hasNextPage,\n isFetchingNextPage: infinite.isFetchingNextPage,\n fetchNextPage: () => void infinite.fetchNextPage(),\n ...freshnessOf(pages[0]),\n };\n }\n return {\n rows: paged.data?.rows ?? [],\n total: paged.data?.total ?? null,\n isLoading: paged.isLoading,\n isFetching: paged.isFetching,\n error: paged.error,\n refetch: () => void paged.refetch(),\n hasNextPage: false,\n isFetchingNextPage: false,\n fetchNextPage: () => {},\n ...freshnessOf(paged.data),\n };\n}\n\nexport const ALL_ROWS_MAX = 2000;\nconst ALL_ROWS_PAGE = 500;\n\nexport interface FetchAllRowsArgs {\n collection: string;\n filter?: FilterNode | undefined;\n sort?: SortKey[];\n /** Stop after this many rows. */\n max: number;\n /** Rows per `list` call. */\n pageLimit?: number;\n /** Keyset paging unless the source pages by offset only. */\n cursor: boolean;\n signal?: AbortSignal;\n onProgress?: (loaded: number, total: number | null) => void;\n}\n\n/**\n * Every row of a filter, `list` page after page, until `total` or `max`.\n * Follows `next_cursor` when keyset paging is on; a source that answers no\n * cursor while rows remain is walked on by offset. Answers one list whose\n * `total` is the server's (so `rows.length < total` means capped), with the\n * first page's `fetched_at` and `stale`.\n */\nexport async function fetchAllRows(\n client: UdcClient,\n args: FetchAllRowsArgs,\n): Promise<ListResponse> {\n const { collection, filter, max } = args;\n const sort = args.sort ?? [];\n const pageLimit = args.pageLimit ?? ALL_ROWS_PAGE;\n const rows: Row[] = [];\n let total: number | null = null;\n let freshness: Pick<ListResponse, \"fetched_at\" | \"stale\"> = {};\n let cursor: string | null = null;\n let byCursor = args.cursor;\n while (rows.length < max) {\n const limit = Math.min(pageLimit, max - rows.length);\n const page = byCursor\n ? cursor\n ? { limit, cursor }\n : { limit }\n : { limit, offset: rows.length };\n const res = await client.list(\n { collection, ...(filter ? { filter } : {}), sort, page },\n args.signal ? { signal: args.signal } : undefined,\n );\n if (rows.length === 0) {\n freshness = {\n ...(res.fetched_at === undefined ? {} : { fetched_at: res.fetched_at }),\n ...(res.stale === undefined ? {} : { stale: res.stale }),\n };\n }\n rows.push(...res.rows);\n total = res.total;\n args.onProgress?.(rows.length, total);\n if (res.rows.length === 0 || (total !== null && rows.length >= total)) break;\n if (byCursor) {\n if (res.next_cursor) cursor = res.next_cursor;\n else if (total === null) break;\n else byCursor = false;\n } else if (total === null && res.rows.length < limit) {\n break;\n }\n }\n return { ...freshness, rows, next_cursor: null, total: total ?? rows.length };\n}\n\nexport interface UseUdcAllRowsArgs {\n collection: string;\n filter?: FilterNode | undefined;\n sort?: SortKey[];\n /** Default 2,000. */\n max?: number;\n /** From `describe`: whether the source pages by cursor. */\n capabilities?: Pick<Capabilities, \"paging\"> | undefined;\n enabled?: boolean;\n /** Poll: refetch every row this often (the view's `refresh_interval_ms`). */\n refetchInterval?: number | undefined;\n}\n\nexport interface UdcAllRowsResult {\n rows: Row[];\n total: number | null;\n isLoading: boolean;\n isFetching: boolean;\n error: Error | null;\n refetch: () => Promise<unknown>;\n /** More rows match than `max`: only the first `max` are here. */\n capped: boolean;\n /** Rows loaded so far by the fetch in flight, for a progress bar. */\n progress: { loaded: number; total: number | null } | null;\n fetchedAt: string | null;\n stale: boolean;\n}\n\n/**\n * All rows of the current filter in one cached list: what the kanban (and\n * the calendar, tree, map and charts after it) draw from. The cache entry\n * sits under `udcKeys.lists(collection)`, so `useUdcMutate`'s optimistic\n * patches and invalidations reach it like every other list.\n */\nexport function useUdcAllRows(args: UseUdcAllRowsArgs): UdcAllRowsResult {\n const client = useUdcClient();\n const { collection, filter } = args;\n const sort = args.sort ?? [];\n const max = args.max ?? ALL_ROWS_MAX;\n const cursor = args.capabilities?.paging?.includes(\"cursor\") ?? true;\n const [progress, setProgress] = useState<UdcAllRowsResult[\"progress\"]>(null);\n\n const key: ListKeyParams = { filter, sort, limit: max, mode: \"all\" };\n const query = useQuery({\n queryKey: udcKeys.list(collection, key),\n queryFn: async ({ signal }) => {\n setProgress({ loaded: 0, total: null });\n try {\n return await fetchAllRows(client, {\n collection,\n filter,\n sort,\n max,\n cursor,\n signal,\n onProgress: (loaded, total) => setProgress({ loaded, total }),\n });\n } finally {\n setProgress(null);\n }\n },\n placeholderData: keepPreviousData,\n enabled: args.enabled ?? true,\n refetchInterval: pollInterval(args.refetchInterval),\n });\n\n const rows = query.data?.rows ?? [];\n const total = query.data?.total ?? null;\n return {\n rows,\n total,\n isLoading: query.isLoading,\n isFetching: query.isFetching,\n error: query.error,\n refetch: () => query.refetch(),\n capped: total !== null && rows.length < total,\n progress,\n ...freshnessOf(query.data),\n };\n}\n\ntype ListCache = ListResponse | InfiniteData<ListResponse, unknown>;\n\nfunction isInfinite(data: ListCache): data is InfiniteData<ListResponse, unknown> {\n return \"pages\" in data;\n}\n\n/** `data` with every row whose id is `id` passed through `patch`. */\nexport function patchRowInList(\n data: ListCache | undefined,\n id: string,\n patch: (row: Row) => Row,\n): ListCache | undefined {\n if (!data) return data;\n const patchPage = (page: ListResponse): ListResponse =>\n page.rows.some((r) => r.__meta.id === id)\n ? { ...page, rows: page.rows.map((r) => (r.__meta.id === id ? patch(r) : r)) }\n : page;\n return isInfinite(data) ? { ...data, pages: data.pages.map(patchPage) } : patchPage(data);\n}\n\nfunction patchRowEverywhere(\n qc: QueryClient,\n collection: string,\n id: string,\n patch: (row: Row) => Row,\n) {\n qc.setQueriesData<ListCache>({ queryKey: udcKeys.lists(collection) }, (data) =>\n patchRowInList(data, id, patch),\n );\n}\n\nexport type UdcMutateVars = Omit<ActionRequest<\"mutate\">, \"collection\">;\n\n/**\n * Insert / update / delete one row. An update is applied optimistically to\n * the row in every cached list page and rolled back if the server says no.\n * A `version_conflict` additionally re-reads the row, so the cache holds the\n * value that won; the error still reaches the caller. Lists are invalidated\n * once the call settles.\n */\nexport function useUdcMutate(collection: string) {\n const client = useUdcClient();\n const qc = useQueryClient();\n\n return useMutation({\n mutationFn: (vars: UdcMutateVars) => client.mutate({ collection, ...vars }),\n onMutate: async (vars) => {\n await qc.cancelQueries({ queryKey: udcKeys.lists(collection) });\n const snapshot = qc.getQueriesData<ListCache>({ queryKey: udcKeys.lists(collection) });\n const { id, row } = vars;\n if (vars.op === \"update\" && id && row) {\n patchRowEverywhere(qc, collection, id, (r) => ({ ...r, ...row, __meta: r.__meta }));\n }\n return { snapshot };\n },\n onSuccess: (res) => {\n patchRowEverywhere(qc, collection, res.row.__meta.id, () => res.row);\n },\n onError: async (err, vars, ctx) => {\n for (const [key, data] of ctx?.snapshot ?? []) qc.setQueryData(key, data);\n if (isVersionConflict(err) && vars.id) {\n try {\n const fresh = await client.read(collection, vars.id);\n patchRowEverywhere(qc, collection, vars.id, () => fresh.row);\n } catch {\n // The invalidation below refetches the lists anyway.\n }\n }\n },\n // A row of this collection may be another collection's lookup label: those batches go stale too.\n onSettled: () =>\n Promise.all([\n qc.invalidateQueries({ queryKey: udcKeys.lists(collection) }),\n qc.invalidateQueries({ queryKey: udcKeys.lookups(collection) }),\n qc.invalidateQueries({ queryKey: [\"udc\", \"lookup-options\", collection] }),\n ]),\n });\n}\n\n/**\n * The three schema edits. Each answers the new schema; `describe` (which\n * derives the columns) and the lists are refetched afterwards.\n */\nexport function useUdcSchema(collection: string) {\n const client = useUdcClient();\n const qc = useQueryClient();\n const onSuccess = async () => {\n await qc.invalidateQueries({ queryKey: udcKeys.describe(collection) });\n await qc.invalidateQueries({ queryKey: udcKeys.lists(collection) });\n };\n\n const addField = useMutation({\n mutationFn: (req: Omit<ActionRequest<\"schema.add_field\">, \"collection\">) =>\n client.schemaAddField({ collection, ...req }),\n onSuccess,\n });\n const updateField = useMutation({\n mutationFn: (req: Omit<ActionRequest<\"schema.update_field\">, \"collection\">) =>\n client.schemaUpdateField({ collection, ...req }),\n onSuccess,\n });\n const softDeleteField = useMutation({\n mutationFn: (field: string) => client.schemaSoftDeleteField({ collection, field }),\n onSuccess,\n });\n return { addField, updateField, softDeleteField };\n}\n"],"mappings":";;;;;;AAuBA,SAAgB,oBAAoB;CAClC,MAAM,SAAS,aAAa;CAC5B,OAAO,SAAS;EAAE,UAAU,QAAQ,YAAY;EAAG,eAAe,OAAO,YAAY;CAAE,CAAC;AAC1F;AAEA,SAAgB,eAAe,YAAoB,OAA8B,CAAC,GAAG;CACnF,MAAM,SAAS,aAAa;CAC5B,OAAO,SAAS;EACd,UAAU,QAAQ,SAAS,UAAU;EACrC,eAAe,OAAO,SAAS,UAAU;EACzC,WAAW;EACX,UAAU,KAAK,WAAW,SAAS,eAAe;CACpD,CAAC;AACH;;AAGA,SAAgB,aAAa,YAAoB,OAA8B,CAAC,GAAG;CACjF,MAAM,SAAS,aAAa;CAC5B,OAAO,SAAS;EACd,UAAU,QAAQ,OAAO,UAAU;EACnC,eAAe,OAAO,WAAW,UAAU;EAC3C,WAAW;EACX,UAAU,KAAK,WAAW,SAAS,eAAe;CACpD,CAAC;AACH;;AAkCA,SAAgB,aAAa,IAAwC;CACnE,OAAO,OAAO,OAAO,YAAY,KAAK,IAAI,KAAK;AACjD;;AAGA,SAAgB,YAAY,KAG1B;CACA,OAAO;EAAE,WAAW,KAAK,cAAc;EAAM,OAAO,KAAK,UAAU;CAAK;AAC1E;;AAGA,SAAgB,WAAW,MAAc,OAAuB;CAC9D,OAAO,KAAK,IAAI,GAAG,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI;AAC7C;;;;;;;;;AAUA,SAAgB,iBAAiB,MAAiD;CAChF,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e;IAAE;IAAY,GAAG;GAAI,CAAC;GAC9C;EACF,CAUS;EAAU,aATC,YAAY;GAC9B,aAAa,QACX,OAAO,kBAAkB;IAAE;IAAY,GAAG;GAAI,CAAC;GACjD;EACF,CAKmB;EAAa,iBAJR,YAAY;GAClC,aAAa,UAAkB,OAAO,sBAAsB;IAAE;IAAY;GAAM,CAAC;GACjF;EACF,CACgC;CAAgB;AAClD"}
|
package/dist/udc/keys.d.ts
CHANGED
|
@@ -16,4 +16,9 @@ export declare const udcKeys: {
|
|
|
16
16
|
source: (collection: string) => readonly ["udc", "source", string];
|
|
17
17
|
lists: (collection: string) => readonly ["udc", "list", string];
|
|
18
18
|
list: (collection: string, params: ListKeyParams) => readonly ["udc", "list", string, ListKeyParams];
|
|
19
|
+
lookups: (collection: string) => readonly ["udc", "lookup", string];
|
|
20
|
+
/** One lookup batch: the target collection, its sorted keys, and the key field when not `id`. */
|
|
21
|
+
lookup: (collection: string, sortedKeys: readonly string[], keyField?: string) => readonly ["udc", "lookup", string, readonly string[]] | readonly ["udc", "lookup", string, readonly string[], string];
|
|
22
|
+
/** The options of a lookup picker (a chip, the inline editor): target, label field, search. */
|
|
23
|
+
lookupOptions: (collection: string, labelField: string, search: string) => readonly ["udc", "lookup-options", string, string, string];
|
|
19
24
|
};
|
package/dist/udc/keys.js
CHANGED
|
@@ -23,6 +23,32 @@ var udcKeys = {
|
|
|
23
23
|
"list",
|
|
24
24
|
collection,
|
|
25
25
|
params
|
|
26
|
+
],
|
|
27
|
+
lookups: (collection) => [
|
|
28
|
+
"udc",
|
|
29
|
+
"lookup",
|
|
30
|
+
collection
|
|
31
|
+
],
|
|
32
|
+
/** One lookup batch: the target collection, its sorted keys, and the key field when not `id`. */
|
|
33
|
+
lookup: (collection, sortedKeys, keyField = "id") => keyField === "id" ? [
|
|
34
|
+
"udc",
|
|
35
|
+
"lookup",
|
|
36
|
+
collection,
|
|
37
|
+
sortedKeys
|
|
38
|
+
] : [
|
|
39
|
+
"udc",
|
|
40
|
+
"lookup",
|
|
41
|
+
collection,
|
|
42
|
+
sortedKeys,
|
|
43
|
+
keyField
|
|
44
|
+
],
|
|
45
|
+
/** The options of a lookup picker (a chip, the inline editor): target, label field, search. */
|
|
46
|
+
lookupOptions: (collection, labelField, search) => [
|
|
47
|
+
"udc",
|
|
48
|
+
"lookup-options",
|
|
49
|
+
collection,
|
|
50
|
+
labelField,
|
|
51
|
+
search
|
|
26
52
|
]
|
|
27
53
|
};
|
|
28
54
|
export { udcKeys };
|
package/dist/udc/keys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.js","names":[],"sources":["../../src/udc/keys.ts"],"sourcesContent":["import type { FilterNode, SortKey } from \"@jsudc/core\";\n\nexport type PagingMode = \"infinite\" | \"pages\";\n\nexport interface ListKeyParams {\n filter: FilterNode | undefined;\n sort: SortKey[];\n limit: number;\n /** `all`: every row up to `limit`, fetched page by page into one list (`useUdcAllRows`). */\n mode: PagingMode | \"all\";\n page?: number;\n}\n\n/** Every query this app makes sits under `[\"udc\", ...]`. */\nexport const udcKeys = {\n all: [\"udc\"] as const,\n collections: () => [\"udc\", \"collections\"] as const,\n describe: (collection: string) => [\"udc\", \"describe\", collection] as const,\n source: (collection: string) => [\"udc\", \"source\", collection] as const,\n lists: (collection: string) => [\"udc\", \"list\", collection] as const,\n list: (collection: string, params: ListKeyParams) => [\"udc\", \"list\", collection, params] as const,\n};\n"],"mappings":";;AAcA,IAAa,UAAU;CACrB,KAAK,CAAC,KAAK;CACX,mBAAmB,CAAC,OAAO,aAAa;CACxC,WAAW,eAAuB;EAAC;EAAO;EAAY;CAAU;CAChE,SAAS,eAAuB;EAAC;EAAO;EAAU;CAAU;CAC5D,QAAQ,eAAuB;EAAC;EAAO;EAAQ;CAAU;CACzD,OAAO,YAAoB,WAA0B;EAAC;EAAO;EAAQ;EAAY;CAAM;
|
|
1
|
+
{"version":3,"file":"keys.js","names":[],"sources":["../../src/udc/keys.ts"],"sourcesContent":["import type { FilterNode, SortKey } from \"@jsudc/core\";\n\nexport type PagingMode = \"infinite\" | \"pages\";\n\nexport interface ListKeyParams {\n filter: FilterNode | undefined;\n sort: SortKey[];\n limit: number;\n /** `all`: every row up to `limit`, fetched page by page into one list (`useUdcAllRows`). */\n mode: PagingMode | \"all\";\n page?: number;\n}\n\n/** Every query this app makes sits under `[\"udc\", ...]`. */\nexport const udcKeys = {\n all: [\"udc\"] as const,\n collections: () => [\"udc\", \"collections\"] as const,\n describe: (collection: string) => [\"udc\", \"describe\", collection] as const,\n source: (collection: string) => [\"udc\", \"source\", collection] as const,\n lists: (collection: string) => [\"udc\", \"list\", collection] as const,\n list: (collection: string, params: ListKeyParams) => [\"udc\", \"list\", collection, params] as const,\n lookups: (collection: string) => [\"udc\", \"lookup\", collection] as const,\n /** One lookup batch: the target collection, its sorted keys, and the key field when not `id`. */\n lookup: (collection: string, sortedKeys: readonly string[], keyField = \"id\") =>\n keyField === \"id\"\n ? ([\"udc\", \"lookup\", collection, sortedKeys] as const)\n : ([\"udc\", \"lookup\", collection, sortedKeys, keyField] as const),\n /** The options of a lookup picker (a chip, the inline editor): target, label field, search. */\n lookupOptions: (collection: string, labelField: string, search: string) =>\n [\"udc\", \"lookup-options\", collection, labelField, search] as const,\n};\n"],"mappings":";;AAcA,IAAa,UAAU;CACrB,KAAK,CAAC,KAAK;CACX,mBAAmB,CAAC,OAAO,aAAa;CACxC,WAAW,eAAuB;EAAC;EAAO;EAAY;CAAU;CAChE,SAAS,eAAuB;EAAC;EAAO;EAAU;CAAU;CAC5D,QAAQ,eAAuB;EAAC;EAAO;EAAQ;CAAU;CACzD,OAAO,YAAoB,WAA0B;EAAC;EAAO;EAAQ;EAAY;CAAM;CACvF,UAAU,eAAuB;EAAC;EAAO;EAAU;CAAU;;CAE7D,SAAS,YAAoB,YAA+B,WAAW,SACrE,aAAa,OACR;EAAC;EAAO;EAAU;EAAY;CAAU,IACxC;EAAC;EAAO;EAAU;EAAY;EAAY;CAAQ;;CAEzD,gBAAgB,YAAoB,YAAoB,WACtD;EAAC;EAAO;EAAkB;EAAY;EAAY;CAAM;AAC5D"}
|
package/dist/udc/provider.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { UdcClient } from "@jsudc/core/client";
|
|
2
2
|
import type { ReactNode } from "react";
|
|
3
|
+
import { type UdcLinks } from "../lookup/links.js";
|
|
3
4
|
import type { RendererRegistry } from "../renderers/types.js";
|
|
4
5
|
import type { UiKit } from "../ui-kit/types.js";
|
|
5
6
|
export { createUdcQueryClient, shouldRetry, useUdcClient } from "./client.js";
|
|
@@ -10,8 +11,14 @@ export { createUdcQueryClient, shouldRetry, useUdcClient } from "./client.js";
|
|
|
10
11
|
* `renderers` the outer `UdcRenderersProvider`'s registry is kept (else none:
|
|
11
12
|
* every tab says no renderer is registered).
|
|
12
13
|
*/
|
|
13
|
-
export declare function UdcProvider({ client, kit, renderers, children, }: {
|
|
14
|
+
export declare function UdcProvider({ client, kit, renderers, links, children, }: {
|
|
14
15
|
client: UdcClient;
|
|
16
|
+
/**
|
|
17
|
+
* Where a lookup link and a `row_link` go: the address of a collection's
|
|
18
|
+
* view, and how to navigate there. Default `defaultUdcLinks` (`/c/<name>`);
|
|
19
|
+
* `UdcReactRouterUrlState collectionPath` sets it for react-router.
|
|
20
|
+
*/
|
|
21
|
+
links?: UdcLinks;
|
|
15
22
|
kit?: UiKit;
|
|
16
23
|
/** `createRendererRegistry(tableRenderer, …)`, or `RENDERERS` from `@jsudc/react/all`. */
|
|
17
24
|
renderers?: RendererRegistry;
|
package/dist/udc/provider.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UdcLinksProvider } from "../lookup/links.js";
|
|
1
2
|
import { UdcRenderersProvider } from "../renderers/context.js";
|
|
2
3
|
import { UdcUiProvider } from "../ui-kit/context.js";
|
|
3
4
|
import { UdcClientContext, createUdcQueryClient, shouldRetry, useUdcClient } from "./client.js";
|
|
@@ -10,11 +11,15 @@ import { jsx } from "react/jsx-runtime";
|
|
|
10
11
|
* `renderers` the outer `UdcRenderersProvider`'s registry is kept (else none:
|
|
11
12
|
* every tab says no renderer is registered).
|
|
12
13
|
*/
|
|
13
|
-
function UdcProvider({ client, kit, renderers, children }) {
|
|
14
|
+
function UdcProvider({ client, kit, renderers, links, children }) {
|
|
14
15
|
let inner = /* @__PURE__ */ jsx(UdcClientContext.Provider, {
|
|
15
16
|
value: client,
|
|
16
17
|
children
|
|
17
18
|
});
|
|
19
|
+
if (links) inner = /* @__PURE__ */ jsx(UdcLinksProvider, {
|
|
20
|
+
links,
|
|
21
|
+
children: inner
|
|
22
|
+
});
|
|
18
23
|
if (renderers) inner = /* @__PURE__ */ jsx(UdcRenderersProvider, {
|
|
19
24
|
renderers,
|
|
20
25
|
children: inner
|
package/dist/udc/provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","names":[],"sources":["../../src/udc/provider.tsx"],"sourcesContent":["import type { UdcClient } from \"@jsudc/core/client\";\nimport type { ReactNode } from \"react\";\nimport { UdcRenderersProvider } from \"../renderers/context.js\";\nimport type { RendererRegistry } from \"../renderers/types.js\";\nimport { UdcUiProvider } from \"../ui-kit/context.js\";\nimport type { UiKit } from \"../ui-kit/types.js\";\nimport { UdcClientContext } from \"./client.js\";\n\nexport { createUdcQueryClient, shouldRetry, useUdcClient } from \"./client.js\";\n\n/**\n * The root provider: the client, the renderers `UdcDataView` draws its tabs\n * with, and optionally the UI kit they draw with. Without `kit` the kit in\n * effect is kept (an outer `UdcUiProvider`'s, else `defaultUiKit`); without\n * `renderers` the outer `UdcRenderersProvider`'s registry is kept (else none:\n * every tab says no renderer is registered).\n */\nexport function UdcProvider({\n client,\n kit,\n renderers,\n children,\n}: {\n client: UdcClient;\n kit?: UiKit;\n /** `createRendererRegistry(tableRenderer, …)`, or `RENDERERS` from `@jsudc/react/all`. */\n renderers?: RendererRegistry;\n children: ReactNode;\n}) {\n let inner = <UdcClientContext.Provider value={client}>{children}</UdcClientContext.Provider>;\n if (renderers) inner = <UdcRenderersProvider renderers={renderers}>{inner}</UdcRenderersProvider>;\n return kit ? <UdcUiProvider kit={kit}>{inner}</UdcUiProvider> : inner;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"provider.js","names":[],"sources":["../../src/udc/provider.tsx"],"sourcesContent":["import type { UdcClient } from \"@jsudc/core/client\";\nimport type { ReactNode } from \"react\";\nimport { type UdcLinks, UdcLinksProvider } from \"../lookup/links.js\";\nimport { UdcRenderersProvider } from \"../renderers/context.js\";\nimport type { RendererRegistry } from \"../renderers/types.js\";\nimport { UdcUiProvider } from \"../ui-kit/context.js\";\nimport type { UiKit } from \"../ui-kit/types.js\";\nimport { UdcClientContext } from \"./client.js\";\n\nexport { createUdcQueryClient, shouldRetry, useUdcClient } from \"./client.js\";\n\n/**\n * The root provider: the client, the renderers `UdcDataView` draws its tabs\n * with, and optionally the UI kit they draw with. Without `kit` the kit in\n * effect is kept (an outer `UdcUiProvider`'s, else `defaultUiKit`); without\n * `renderers` the outer `UdcRenderersProvider`'s registry is kept (else none:\n * every tab says no renderer is registered).\n */\nexport function UdcProvider({\n client,\n kit,\n renderers,\n links,\n children,\n}: {\n client: UdcClient;\n /**\n * Where a lookup link and a `row_link` go: the address of a collection's\n * view, and how to navigate there. Default `defaultUdcLinks` (`/c/<name>`);\n * `UdcReactRouterUrlState collectionPath` sets it for react-router.\n */\n links?: UdcLinks;\n kit?: UiKit;\n /** `createRendererRegistry(tableRenderer, …)`, or `RENDERERS` from `@jsudc/react/all`. */\n renderers?: RendererRegistry;\n children: ReactNode;\n}) {\n let inner = <UdcClientContext.Provider value={client}>{children}</UdcClientContext.Provider>;\n if (links) inner = <UdcLinksProvider links={links}>{inner}</UdcLinksProvider>;\n if (renderers) inner = <UdcRenderersProvider renderers={renderers}>{inner}</UdcRenderersProvider>;\n return kit ? <UdcUiProvider kit={kit}>{inner}</UdcUiProvider> : inner;\n}\n"],"mappings":";;;;;;;;;;;;;AAkBA,SAAgB,YAAY,EAC1B,QACA,KACA,WACA,OACA,YAaC;CACD,IAAI,QAAQ,oBAAC,iBAAiB,UAAlB;EAA2B,OAAO;EAAS;CAAoC,CAAA;CAC3F,IAAI,OAAO,QAAQ,oBAAC,kBAAD;EAAyB;EAAQ,UAAA;CAAwB,CAAA;CAC5E,IAAI,WAAW,QAAQ,oBAAC,sBAAD;EAAiC;EAAY,UAAA;CAA4B,CAAA;CAChG,OAAO,MAAM,oBAAC,eAAD;EAAoB;EAAM,UAAA;CAAqB,CAAA,IAAI;AAClE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsudc/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "React components for UDC collections: the data view, its table, cards, kanban, calendar, tree, map and chart renderers (one subpath each), the schema editor, headless hooks and models, i18n, theme and a compiled, udc:-prefixed stylesheet.",
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
},
|
|
103
103
|
"scripts": {
|
|
104
104
|
"build": "vite build && tsc -p tsconfig.build.json && npm run build:css",
|
|
105
|
-
"build:css": "tailwindcss -i src/styles.css -o dist/styles.css --minify && node -e \"require('node:fs').copyFileSync('src/tokens.css', 'dist/tokens.css')\" && node scripts/check-css.mjs",
|
|
105
|
+
"build:css": "tailwindcss -i src/styles.css -o dist/styles.css --minify && node -e \"require('node:fs').copyFileSync('src/tokens.css', 'dist/tokens.css')\" && node scripts/check-css.mjs && node scripts/check-classes.mjs",
|
|
106
106
|
"prepare": "npm run build",
|
|
107
107
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
108
108
|
"check:types": "tsc -p smoke/tsconfig.nodenext.json && tsc -p smoke/tsconfig.bundler.json",
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
"@dnd-kit/core": "^6.3.1",
|
|
120
120
|
"@dnd-kit/sortable": "^10.0.0",
|
|
121
121
|
"@dnd-kit/utilities": "^3.2.2",
|
|
122
|
-
"@jsudc/core": "^0.
|
|
122
|
+
"@jsudc/core": "^0.3.0",
|
|
123
123
|
"@tanstack/react-query": "^5.104.4",
|
|
124
124
|
"@tanstack/react-table": "^8.21.3",
|
|
125
125
|
"leaflet": "^1.9.4",
|
|
@@ -158,7 +158,7 @@
|
|
|
158
158
|
"@dnd-kit/core": "^6.3.1",
|
|
159
159
|
"@dnd-kit/sortable": "^10.0.0",
|
|
160
160
|
"@dnd-kit/utilities": "^3.2.2",
|
|
161
|
-
"@jsudc/core": "^0.
|
|
161
|
+
"@jsudc/core": "^0.3.0",
|
|
162
162
|
"@tailwindcss/cli": "^4.3.3",
|
|
163
163
|
"@tanstack/react-query": "^5.104.4",
|
|
164
164
|
"@tanstack/react-table": "^8.21.3",
|