@jsudc/react 0.1.1 → 0.2.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.
Files changed (262) hide show
  1. package/README.md +409 -73
  2. package/dist/all.d.ts +9 -0
  3. package/dist/all.js +14 -0
  4. package/dist/all.js.map +1 -0
  5. package/dist/calendar/CalendarRenderer.d.ts +1 -3
  6. package/dist/calendar/CalendarRenderer.js +17 -46
  7. package/dist/calendar/CalendarRenderer.js.map +1 -1
  8. package/dist/calendar/EventBlock.d.ts +1 -1
  9. package/dist/calendar/EventBlock.js +6 -6
  10. package/dist/calendar/EventBlock.js.map +1 -1
  11. package/dist/calendar/EventDetail.d.ts +1 -1
  12. package/dist/calendar/EventDetail.js +19 -19
  13. package/dist/calendar/EventDetail.js.map +1 -1
  14. package/dist/calendar/MonthGrid.d.ts +2 -2
  15. package/dist/calendar/MonthGrid.js +15 -14
  16. package/dist/calendar/MonthGrid.js.map +1 -1
  17. package/dist/calendar/TimeGrid.d.ts +2 -2
  18. package/dist/calendar/TimeGrid.js +27 -26
  19. package/dist/calendar/TimeGrid.js.map +1 -1
  20. package/dist/calendar/index.d.ts +4 -0
  21. package/dist/calendar/model.d.ts +1 -1
  22. package/dist/calendar/model.js.map +1 -1
  23. package/dist/calendar/useCalendarUrl.d.ts +13 -0
  24. package/dist/calendar/useCalendarUrl.js +35 -0
  25. package/dist/calendar/useCalendarUrl.js.map +1 -0
  26. package/dist/calendar.d.ts +1 -0
  27. package/dist/calendar.js +22 -0
  28. package/dist/calendar.js.map +1 -0
  29. package/dist/cards/CardRenderer.d.ts +3 -3
  30. package/dist/cards/CardRenderer.js +59 -56
  31. package/dist/cards/CardRenderer.js.map +1 -1
  32. package/dist/cards/index.d.ts +4 -0
  33. package/dist/cards.d.ts +1 -0
  34. package/dist/cards.js +15 -0
  35. package/dist/cards.js.map +1 -0
  36. package/dist/chart/ChartRenderer.d.ts +1 -1
  37. package/dist/chart/ChartRenderer.js +33 -31
  38. package/dist/chart/ChartRenderer.js.map +1 -1
  39. package/dist/chart/ChartWindowControl.d.ts +2 -2
  40. package/dist/chart/ChartWindowControl.js +17 -13
  41. package/dist/chart/ChartWindowControl.js.map +1 -1
  42. package/dist/chart/index.d.ts +7 -0
  43. package/dist/chart/model.js +7 -2
  44. package/dist/chart/model.js.map +1 -1
  45. package/dist/chart/useChartWindow.d.ts +1 -1
  46. package/dist/chart/useChartWindow.js +2 -2
  47. package/dist/chart/useChartWindow.js.map +1 -1
  48. package/dist/chart/window.d.ts +1 -1
  49. package/dist/chart/window.js +4 -1
  50. package/dist/chart/window.js.map +1 -1
  51. package/dist/chart.d.ts +1 -0
  52. package/dist/chart.js +18 -0
  53. package/dist/chart.js.map +1 -0
  54. package/dist/components/ui/button.d.ts +9 -9
  55. package/dist/components/ui/button.js +11 -11
  56. package/dist/components/ui/button.js.map +1 -1
  57. package/dist/components/ui/checkbox.js +5 -5
  58. package/dist/components/ui/checkbox.js.map +1 -1
  59. package/dist/components/ui/dialog.d.ts +1 -1
  60. package/dist/components/ui/dialog.js +12 -12
  61. package/dist/components/ui/dialog.js.map +1 -1
  62. package/dist/components/ui/dropdown-menu.js +5 -5
  63. package/dist/components/ui/dropdown-menu.js.map +1 -1
  64. package/dist/components/ui/input.js +2 -2
  65. package/dist/components/ui/input.js.map +1 -1
  66. package/dist/components/ui/misc.js +3 -3
  67. package/dist/components/ui/misc.js.map +1 -1
  68. package/dist/components/ui/popover.js +2 -2
  69. package/dist/components/ui/popover.js.map +1 -1
  70. package/dist/components/ui/segmented.d.ts +2 -9
  71. package/dist/components/ui/segmented.js +4 -4
  72. package/dist/components/ui/segmented.js.map +1 -1
  73. package/dist/components/ui/select.d.ts +2 -4
  74. package/dist/components/ui/select.js +10 -10
  75. package/dist/components/ui/select.js.map +1 -1
  76. package/dist/components/ui/toast.d.ts +2 -6
  77. package/dist/components/ui/toast.js +14 -14
  78. package/dist/components/ui/toast.js.map +1 -1
  79. package/dist/components/ui/tooltip.js +2 -2
  80. package/dist/components/ui/tooltip.js.map +1 -1
  81. package/dist/data-view/DocTab.js +2 -2
  82. package/dist/data-view/DocTab.js.map +1 -1
  83. package/dist/data-view/FilePreview.js +9 -9
  84. package/dist/data-view/FilePreview.js.map +1 -1
  85. package/dist/data-view/FilterBuilder.js +30 -31
  86. package/dist/data-view/FilterBuilder.js.map +1 -1
  87. package/dist/data-view/FilterChips.d.ts +1 -1
  88. package/dist/data-view/FilterChips.js +30 -29
  89. package/dist/data-view/FilterChips.js.map +1 -1
  90. package/dist/data-view/FolderBar.js +8 -8
  91. package/dist/data-view/FolderBar.js.map +1 -1
  92. package/dist/data-view/FolderEntry.d.ts +1 -1
  93. package/dist/data-view/FolderEntry.js +4 -4
  94. package/dist/data-view/FolderEntry.js.map +1 -1
  95. package/dist/data-view/Freshness.js +9 -8
  96. package/dist/data-view/Freshness.js.map +1 -1
  97. package/dist/data-view/SearchBox.js +9 -9
  98. package/dist/data-view/SearchBox.js.map +1 -1
  99. package/dist/data-view/SourceTab.js +26 -25
  100. package/dist/data-view/SourceTab.js.map +1 -1
  101. package/dist/data-view/UdcDataView.d.ts +6 -2
  102. package/dist/data-view/UdcDataView.js +36 -37
  103. package/dist/data-view/UdcDataView.js.map +1 -1
  104. package/dist/data-view/compose.d.ts +1 -1
  105. package/dist/data-view/compose.js.map +1 -1
  106. package/dist/data-view/urlState.d.ts +1 -1
  107. package/dist/data-view/urlState.js.map +1 -1
  108. package/dist/data-view/useDataViewState.d.ts +5 -2
  109. package/dist/data-view/useDataViewState.js +15 -5
  110. package/dist/data-view/useDataViewState.js.map +1 -1
  111. package/dist/headless.d.ts +31 -0
  112. package/dist/headless.js +31 -0
  113. package/dist/i18n/i18n.d.ts +1 -1
  114. package/dist/i18n/i18n.js +1 -1
  115. package/dist/i18n/i18n.js.map +1 -1
  116. package/dist/i18n/translations.js +8 -0
  117. package/dist/i18n/translations.js.map +1 -1
  118. package/dist/icons/resolve.js.map +1 -1
  119. package/dist/index.d.ts +19 -27
  120. package/dist/index.js +11 -16
  121. package/dist/kanban/CardDetailDialog.js +8 -7
  122. package/dist/kanban/CardDetailDialog.js.map +1 -1
  123. package/dist/kanban/KanbanBoardSwitcher.js +4 -4
  124. package/dist/kanban/KanbanBoardSwitcher.js.map +1 -1
  125. package/dist/kanban/KanbanCard.js +46 -45
  126. package/dist/kanban/KanbanCard.js.map +1 -1
  127. package/dist/kanban/KanbanColumn.d.ts +1 -1
  128. package/dist/kanban/KanbanColumn.js +22 -21
  129. package/dist/kanban/KanbanColumn.js.map +1 -1
  130. package/dist/kanban/KanbanRenderer.d.ts +1 -1
  131. package/dist/kanban/KanbanRenderer.js +14 -14
  132. package/dist/kanban/KanbanRenderer.js.map +1 -1
  133. package/dist/kanban/index.d.ts +5 -0
  134. package/dist/kanban/persist.d.ts +2 -2
  135. package/dist/kanban/persist.js.map +1 -1
  136. package/dist/kanban/useKanbanBoard.js +2 -2
  137. package/dist/kanban/useKanbanBoard.js.map +1 -1
  138. package/dist/kanban.d.ts +1 -0
  139. package/dist/kanban.js +17 -0
  140. package/dist/kanban.js.map +1 -0
  141. package/dist/lib/storage.d.ts +7 -0
  142. package/dist/lib/storage.js +24 -0
  143. package/dist/lib/storage.js.map +1 -0
  144. package/dist/lib/theme.js +1 -1
  145. package/dist/lib/theme.js.map +1 -1
  146. package/dist/lib/utils.d.ts +2 -7
  147. package/dist/lib/utils.js +4 -21
  148. package/dist/lib/utils.js.map +1 -1
  149. package/dist/map/MapRenderer.d.ts +1 -1
  150. package/dist/map/MapRenderer.js +19 -19
  151. package/dist/map/MapRenderer.js.map +1 -1
  152. package/dist/map/index.d.ts +4 -0
  153. package/dist/map/model.js +4 -1
  154. package/dist/map/model.js.map +1 -1
  155. package/dist/map.d.ts +1 -0
  156. package/dist/map.js +15 -0
  157. package/dist/map.js.map +1 -0
  158. package/dist/react-router/UdcReactRouterUrlState.d.ts +10 -0
  159. package/dist/react-router/UdcReactRouterUrlState.js +35 -0
  160. package/dist/react-router/UdcReactRouterUrlState.js.map +1 -0
  161. package/dist/react-router/index.d.ts +1 -0
  162. package/dist/react-router.d.ts +1 -0
  163. package/dist/react-router.js +1 -0
  164. package/dist/renderers/AllRowsStatus.d.ts +1 -1
  165. package/dist/renderers/AllRowsStatus.js +5 -5
  166. package/dist/renderers/AllRowsStatus.js.map +1 -1
  167. package/dist/renderers/context.d.ts +11 -0
  168. package/dist/renderers/context.js +15 -0
  169. package/dist/renderers/context.js.map +1 -0
  170. package/dist/renderers/registry.d.ts +16 -12
  171. package/dist/renderers/registry.js +24 -87
  172. package/dist/renderers/registry.js.map +1 -1
  173. package/dist/renderers/types.d.ts +11 -4
  174. package/dist/renderers/types.js.map +1 -1
  175. package/dist/schema-editor/ColumnHeaderMenu.d.ts +1 -1
  176. package/dist/schema-editor/ColumnHeaderMenu.js +6 -5
  177. package/dist/schema-editor/ColumnHeaderMenu.js.map +1 -1
  178. package/dist/schema-editor/DeleteFieldDialog.js +13 -13
  179. package/dist/schema-editor/DeleteFieldDialog.js.map +1 -1
  180. package/dist/schema-editor/FieldFormDialog.js +32 -33
  181. package/dist/schema-editor/FieldFormDialog.js.map +1 -1
  182. package/dist/schema-editor/TagInput.js +6 -6
  183. package/dist/schema-editor/TagInput.js.map +1 -1
  184. package/dist/schema-editor/fieldForm.js +2 -1
  185. package/dist/schema-editor/fieldForm.js.map +1 -1
  186. package/dist/schema-editor/index.d.ts +6 -0
  187. package/dist/schema-editor/useSchemaEditor.d.ts +1 -1
  188. package/dist/schema-editor/useSchemaEditor.js +2 -2
  189. package/dist/schema-editor/useSchemaEditor.js.map +1 -1
  190. package/dist/schema-editor.d.ts +1 -0
  191. package/dist/schema-editor.js +7 -0
  192. package/dist/styles.css +1 -1
  193. package/dist/table/CellEditor.js +10 -9
  194. package/dist/table/CellEditor.js.map +1 -1
  195. package/dist/table/Pager.js +10 -10
  196. package/dist/table/Pager.js.map +1 -1
  197. package/dist/table/TableRenderer.d.ts +4 -4
  198. package/dist/table/TableRenderer.js +40 -40
  199. package/dist/table/TableRenderer.js.map +1 -1
  200. package/dist/table/cells.d.ts +2 -24
  201. package/dist/table/cells.js +20 -132
  202. package/dist/table/cells.js.map +1 -1
  203. package/dist/table/format.d.ts +24 -0
  204. package/dist/table/format.js +117 -0
  205. package/dist/table/format.js.map +1 -0
  206. package/dist/table/index.d.ts +6 -0
  207. package/dist/table/sparkline.js +6 -6
  208. package/dist/table/sparkline.js.map +1 -1
  209. package/dist/table/states.d.ts +7 -0
  210. package/dist/table/states.js +28 -13
  211. package/dist/table/states.js.map +1 -1
  212. package/dist/table/style.js +13 -13
  213. package/dist/table/style.js.map +1 -1
  214. package/dist/table/transforms.js.map +1 -1
  215. package/dist/table/useInfiniteSentinel.d.ts +1 -1
  216. package/dist/table/useInfiniteSentinel.js.map +1 -1
  217. package/dist/table.d.ts +1 -0
  218. package/dist/table.js +18 -0
  219. package/dist/table.js.map +1 -0
  220. package/dist/time/timezone.d.ts +1 -1
  221. package/dist/time/timezone.js +4 -8
  222. package/dist/time/timezone.js.map +1 -1
  223. package/dist/tokens.css +49 -27
  224. package/dist/tree/TreeNode.js +26 -25
  225. package/dist/tree/TreeNode.js.map +1 -1
  226. package/dist/tree/TreeRenderer.d.ts +1 -1
  227. package/dist/tree/TreeRenderer.js +16 -16
  228. package/dist/tree/TreeRenderer.js.map +1 -1
  229. package/dist/tree/expand.js +1 -1
  230. package/dist/tree/expand.js.map +1 -1
  231. package/dist/tree/index.d.ts +4 -0
  232. package/dist/tree.d.ts +1 -0
  233. package/dist/tree.js +15 -0
  234. package/dist/tree.js.map +1 -0
  235. package/dist/udc/client.d.ts +11 -0
  236. package/dist/udc/client.js +30 -0
  237. package/dist/udc/client.js.map +1 -0
  238. package/dist/udc/hooks.d.ts +3 -3
  239. package/dist/udc/hooks.js +1 -1
  240. package/dist/udc/hooks.js.map +1 -1
  241. package/dist/udc/provider.d.ts +15 -10
  242. package/dist/udc/provider.js +20 -27
  243. package/dist/udc/provider.js.map +1 -1
  244. package/dist/ui-kit/context.d.ts +11 -0
  245. package/dist/ui-kit/context.js +19 -0
  246. package/dist/ui-kit/context.js.map +1 -0
  247. package/dist/ui-kit/default.d.ts +3 -0
  248. package/dist/ui-kit/default.js +45 -0
  249. package/dist/ui-kit/default.js.map +1 -0
  250. package/dist/ui-kit/index.d.ts +2 -0
  251. package/dist/ui-kit/types.d.ts +227 -0
  252. package/dist/ui-kit/ui.d.ts +12 -0
  253. package/dist/ui.d.ts +1 -0
  254. package/dist/ui.js +13 -0
  255. package/dist/url-state/UrlState.d.ts +20 -0
  256. package/dist/url-state/UrlState.js +27 -0
  257. package/dist/url-state/UrlState.js.map +1 -0
  258. package/dist/url-state/adapter.d.ts +24 -0
  259. package/dist/url-state/adapter.js +33 -0
  260. package/dist/url-state/adapter.js.map +1 -0
  261. package/dist/url-state/index.d.ts +2 -0
  262. package/package.json +77 -5
@@ -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 { type ListKeyParams, type PagingMode, udcKeys } from \"./keys\";\nimport { useUdcClient } from \"./provider\";\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, 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,WAA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,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 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, 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,S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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,14 +1,19 @@
1
1
  import type { UdcClient } from "@jsudc/core/client";
2
- import { QueryClient } from "@tanstack/react-query";
3
- import { type ReactNode } from "react";
4
- export declare function UdcProvider({ client, children }: {
2
+ import type { ReactNode } from "react";
3
+ import type { RendererRegistry } from "../renderers/types.js";
4
+ import type { UiKit } from "../ui-kit/types.js";
5
+ export { createUdcQueryClient, shouldRetry, useUdcClient } from "./client.js";
6
+ /**
7
+ * The root provider: the client, the renderers `UdcDataView` draws its tabs
8
+ * with, and optionally the UI kit they draw with. Without `kit` the kit in
9
+ * effect is kept (an outer `UdcUiProvider`'s, else `defaultUiKit`); without
10
+ * `renderers` the outer `UdcRenderersProvider`'s registry is kept (else none:
11
+ * every tab says no renderer is registered).
12
+ */
13
+ export declare function UdcProvider({ client, kit, renderers, children, }: {
5
14
  client: UdcClient;
15
+ kit?: UiKit;
16
+ /** `createRendererRegistry(tableRenderer, …)`, or `RENDERERS` from `@jsudc/react/all`. */
17
+ renderers?: RendererRegistry;
6
18
  children: ReactNode;
7
19
  }): import("react").JSX.Element;
8
- export declare function useUdcClient(): UdcClient;
9
- /**
10
- * A protocol error is the server's answer, not a hiccup: asking again gives
11
- * the same answer. Only transport failures are retried, twice.
12
- */
13
- export declare function shouldRetry(failureCount: number, error: unknown): boolean;
14
- export declare function createUdcQueryClient(): QueryClient;
@@ -1,35 +1,28 @@
1
- import { createContext, useContext } from "react";
1
+ import { UdcRenderersProvider } from "../renderers/context.js";
2
+ import { UdcUiProvider } from "../ui-kit/context.js";
3
+ import { UdcClientContext, createUdcQueryClient, shouldRetry, useUdcClient } from "./client.js";
2
4
  import { jsx } from "react/jsx-runtime";
3
- import { isUdcError } from "@jsudc/core";
4
- import { QueryClient } from "@tanstack/react-query";
5
5
  // src/udc/provider.tsx
6
- var UdcClientContext = createContext(null);
7
- function UdcProvider({ client, children }) {
8
- return /* @__PURE__ */ jsx(UdcClientContext.Provider, {
6
+ /**
7
+ * The root provider: the client, the renderers `UdcDataView` draws its tabs
8
+ * with, and optionally the UI kit they draw with. Without `kit` the kit in
9
+ * effect is kept (an outer `UdcUiProvider`'s, else `defaultUiKit`); without
10
+ * `renderers` the outer `UdcRenderersProvider`'s registry is kept (else none:
11
+ * every tab says no renderer is registered).
12
+ */
13
+ function UdcProvider({ client, kit, renderers, children }) {
14
+ let inner = /* @__PURE__ */ jsx(UdcClientContext.Provider, {
9
15
  value: client,
10
16
  children
11
17
  });
12
- }
13
- function useUdcClient() {
14
- const client = useContext(UdcClientContext);
15
- if (!client) throw new Error("useUdcClient needs a <UdcProvider client={...}> above it");
16
- return client;
17
- }
18
- /**
19
- * A protocol error is the server's answer, not a hiccup: asking again gives
20
- * the same answer. Only transport failures are retried, twice.
21
- */
22
- function shouldRetry(failureCount, error) {
23
- return !isUdcError(error) && failureCount < 2;
24
- }
25
- function createUdcQueryClient() {
26
- return new QueryClient({ defaultOptions: {
27
- queries: {
28
- retry: shouldRetry,
29
- refetchOnWindowFocus: false
30
- },
31
- mutations: { retry: false }
32
- } });
18
+ if (renderers) inner = /* @__PURE__ */ jsx(UdcRenderersProvider, {
19
+ renderers,
20
+ children: inner
21
+ });
22
+ return kit ? /* @__PURE__ */ jsx(UdcUiProvider, {
23
+ kit,
24
+ children: inner
25
+ }) : inner;
33
26
  }
34
27
  export { UdcProvider, createUdcQueryClient, shouldRetry, useUdcClient };
35
28
 
@@ -1 +1 @@
1
- {"version":3,"file":"provider.js","names":[],"sources":["../../src/udc/provider.tsx"],"sourcesContent":["import { isUdcError } from \"@jsudc/core\";\nimport type { UdcClient } from \"@jsudc/core/client\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport { createContext, type ReactNode, useContext } from \"react\";\n\nconst UdcClientContext = createContext<UdcClient | null>(null);\n\nexport function UdcProvider({ client, children }: { client: UdcClient; children: ReactNode }) {\n return <UdcClientContext.Provider value={client}>{children}</UdcClientContext.Provider>;\n}\n\nexport function useUdcClient(): UdcClient {\n const client = useContext(UdcClientContext);\n if (!client) throw new Error(\"useUdcClient needs a <UdcProvider client={...}> above it\");\n return client;\n}\n\n/**\n * A protocol error is the server's answer, not a hiccup: asking again gives\n * the same answer. Only transport failures are retried, twice.\n */\nexport function shouldRetry(failureCount: number, error: unknown): boolean {\n return !isUdcError(error) && failureCount < 2;\n}\n\nexport function createUdcQueryClient(): QueryClient {\n return new QueryClient({\n defaultOptions: {\n queries: { retry: shouldRetry, refetchOnWindowFocus: false },\n mutations: { retry: false },\n },\n });\n}\n"],"mappings":";;;;;AAKA,IAAM,mBAAmB,cAAgC,IAAI;AAE7D,SAAgB,YAAY,EAAE,QAAQ,YAAwD;CAC5F,OAAO,oBAAC,iBAAiB,UAAlB;EAA2B,OAAO;EAAS;CAAoC,CAAA;AACxF;AAEA,SAAgB,eAA0B;CACxC,MAAM,SAAS,WAAW,gBAAgB;CAC1C,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,0DAA0D;CACvF,OAAO;AACT;;;;;AAMA,SAAgB,YAAY,cAAsB,OAAyB;CACzE,OAAO,CAAC,WAAW,KAAK,KAAK,eAAe;AAC9C;AAEA,SAAgB,uBAAoC;CAClD,OAAO,IAAI,YAAY,EACrB,gBAAgB;EACd,SAAS;GAAE,OAAO;GAAa,sBAAsB;EAAM;EAC3D,WAAW,EAAE,OAAO,MAAM;CAC5B,EACF,CAAC;AACH"}
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":";;;;;;;;;;;;AAiBA,SAAgB,YAAY,EAC1B,QACA,KACA,WACA,YAOC;CACD,IAAI,QAAQ,oBAAC,iBAAiB,UAAlB;EAA2B,OAAO;EAAS;CAAoC,CAAA;CAC3F,IAAI,WAAW,QAAQ,oBAAC,sBAAD;EAAiC;EAAY,UAAA;CAA4B,CAAA;CAChG,OAAO,MAAM,oBAAC,eAAD;EAAoB;EAAM,UAAA;CAAqB,CAAA,IAAI;AAClE"}
@@ -0,0 +1,11 @@
1
+ import { type ReactNode } from "react";
2
+ import type { UiKit } from "./types.js";
3
+ export interface UdcUiProviderProps {
4
+ /** The primitives every renderer below draws with. Keep it stable (a module constant). */
5
+ kit: UiKit;
6
+ children: ReactNode;
7
+ }
8
+ /** Sets the UI kit for everything below it. */
9
+ export declare function UdcUiProvider({ kit, children }: UdcUiProviderProps): import("react").JSX.Element;
10
+ /** The kit in effect: the nearest `UdcUiProvider`'s, else `defaultUiKit`. */
11
+ export declare function useUiKit(): UiKit;
@@ -0,0 +1,19 @@
1
+ import { defaultUiKit } from "./default.js";
2
+ import { createContext, useContext } from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+ // src/ui-kit/context.tsx
5
+ var UiKitContext = createContext(defaultUiKit);
6
+ /** Sets the UI kit for everything below it. */
7
+ function UdcUiProvider({ kit, children }) {
8
+ return /* @__PURE__ */ jsx(UiKitContext.Provider, {
9
+ value: kit,
10
+ children
11
+ });
12
+ }
13
+ /** The kit in effect: the nearest `UdcUiProvider`'s, else `defaultUiKit`. */
14
+ function useUiKit() {
15
+ return useContext(UiKitContext);
16
+ }
17
+ export { UdcUiProvider, useUiKit };
18
+
19
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","names":[],"sources":["../../src/ui-kit/context.tsx"],"sourcesContent":["import { createContext, type ReactNode, useContext } from \"react\";\nimport { defaultUiKit } from \"./default.js\";\nimport type { UiKit } from \"./types.js\";\n\n// Without a provider the renderers draw with the default kit, so a renderer\n// mounted on its own (a test, a host page without `UdcProvider`) still works.\nconst UiKitContext = createContext<UiKit>(defaultUiKit);\n\nexport interface UdcUiProviderProps {\n /** The primitives every renderer below draws with. Keep it stable (a module constant). */\n kit: UiKit;\n children: ReactNode;\n}\n\n/** Sets the UI kit for everything below it. */\nexport function UdcUiProvider({ kit, children }: UdcUiProviderProps) {\n return <UiKitContext.Provider value={kit}>{children}</UiKitContext.Provider>;\n}\n\n/** The kit in effect: the nearest `UdcUiProvider`'s, else `defaultUiKit`. */\nexport function useUiKit(): UiKit {\n return useContext(UiKitContext);\n}\n"],"mappings":";;;;AAMA,IAAM,eAAe,cAAqB,YAAY;;AAStD,SAAgB,cAAc,EAAE,KAAK,YAAgC;CACnE,OAAO,oBAAC,aAAa,UAAd;EAAuB,OAAO;EAAM;CAAgC,CAAA;AAC7E;;AAGA,SAAgB,WAAkB;CAChC,OAAO,WAAW,YAAY;AAChC"}
@@ -0,0 +1,3 @@
1
+ import type { UiKit } from "./types.js";
2
+ /** The kit the package ships: Radix primitives styled with Tailwind (`components/ui`). */
3
+ export declare const defaultUiKit: UiKit;
@@ -0,0 +1,45 @@
1
+ import { Button } from "../components/ui/button.js";
2
+ import { Checkbox } from "../components/ui/checkbox.js";
3
+ import { Dialog, DialogBody, DialogContent, DialogFooter } from "../components/ui/dialog.js";
4
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "../components/ui/dropdown-menu.js";
5
+ import { Input, NativeSelect } from "../components/ui/input.js";
6
+ import { Kbd, Skeleton, Spinner } from "../components/ui/misc.js";
7
+ import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from "../components/ui/popover.js";
8
+ import { Segmented } from "../components/ui/segmented.js";
9
+ import { Select } from "../components/ui/select.js";
10
+ import { Toaster, useToast } from "../components/ui/toast.js";
11
+ import { Tip, TooltipProvider } from "../components/ui/tooltip.js";
12
+ // src/ui-kit/default.ts
13
+ /** The kit the package ships: Radix primitives styled with Tailwind (`components/ui`). */
14
+ var defaultUiKit = {
15
+ Button,
16
+ Input,
17
+ NativeSelect,
18
+ Checkbox,
19
+ Select,
20
+ Segmented,
21
+ Spinner,
22
+ Skeleton,
23
+ Kbd,
24
+ Dialog,
25
+ DialogContent,
26
+ DialogBody,
27
+ DialogFooter,
28
+ DropdownMenu,
29
+ DropdownMenuTrigger,
30
+ DropdownMenuContent,
31
+ DropdownMenuItem,
32
+ DropdownMenuLabel,
33
+ DropdownMenuSeparator,
34
+ Popover,
35
+ PopoverTrigger,
36
+ PopoverContent,
37
+ PopoverAnchor,
38
+ TooltipProvider,
39
+ Tip,
40
+ Toaster,
41
+ useToast
42
+ };
43
+ export { defaultUiKit };
44
+
45
+ //# sourceMappingURL=default.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default.js","names":[],"sources":["../../src/ui-kit/default.ts"],"sourcesContent":["import { Button } from \"../components/ui/button.js\";\nimport { Checkbox } from \"../components/ui/checkbox.js\";\nimport { Dialog, DialogBody, DialogContent, DialogFooter } from \"../components/ui/dialog.js\";\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuLabel,\n DropdownMenuSeparator,\n DropdownMenuTrigger,\n} from \"../components/ui/dropdown-menu.js\";\nimport { Input, NativeSelect } from \"../components/ui/input.js\";\nimport { Kbd, Skeleton, Spinner } from \"../components/ui/misc.js\";\nimport {\n Popover,\n PopoverAnchor,\n PopoverContent,\n PopoverTrigger,\n} from \"../components/ui/popover.js\";\nimport { Segmented } from \"../components/ui/segmented.js\";\nimport { Select } from \"../components/ui/select.js\";\nimport { Toaster, useToast } from \"../components/ui/toast.js\";\nimport { Tip, TooltipProvider } from \"../components/ui/tooltip.js\";\nimport type { UiKit } from \"./types.js\";\n\n/** The kit the package ships: Radix primitives styled with Tailwind (`components/ui`). */\nexport const defaultUiKit: UiKit = {\n Button,\n Input,\n NativeSelect,\n Checkbox,\n Select,\n Segmented,\n Spinner,\n Skeleton,\n Kbd,\n Dialog,\n DialogContent,\n DialogBody,\n DialogFooter,\n DropdownMenu,\n DropdownMenuTrigger,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuLabel,\n DropdownMenuSeparator,\n Popover,\n PopoverTrigger,\n PopoverContent,\n PopoverAnchor,\n TooltipProvider,\n Tip,\n Toaster,\n useToast,\n};\n"],"mappings":";;;;;;;;;;;;;AA0BA,IAAa,eAAsB;CACjC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
@@ -0,0 +1,2 @@
1
+ export { UdcUiProvider, type UdcUiProviderProps, useUiKit } from "./context.js";
2
+ export type * from "./types.js";
@@ -0,0 +1,227 @@
1
+ import type { ChangeEvent, ComponentType, CSSProperties, FocusEventHandler, HTMLInputTypeAttribute, KeyboardEventHandler, MouseEventHandler, PointerEventHandler, ReactNode, Ref, SelectHTMLAttributes } from "react";
2
+ /** What the renderers put on nearly every primitive. */
3
+ interface Base {
4
+ className?: string;
5
+ "data-testid"?: string;
6
+ }
7
+ /** A cancellable event: the renderers only ever call `preventDefault()` on it. */
8
+ export interface PreventableEvent {
9
+ preventDefault(): void;
10
+ }
11
+ export type ButtonVariant = "primary" | "outline" | "ghost" | "subtle" | "danger";
12
+ export type ButtonSize = "sm" | "md" | "icon" | "icon-sm";
13
+ export interface UiButtonProps extends Base {
14
+ /** Default `outline`. */
15
+ variant?: ButtonVariant;
16
+ /** Default `md`; `icon` and `icon-sm` are square. */
17
+ size?: ButtonSize;
18
+ type?: "button" | "submit";
19
+ disabled?: boolean;
20
+ onClick?: MouseEventHandler<HTMLButtonElement>;
21
+ onPointerDown?: PointerEventHandler<HTMLButtonElement>;
22
+ "aria-label"?: string;
23
+ children?: ReactNode;
24
+ }
25
+ export interface UiInputProps extends Base {
26
+ ref?: Ref<HTMLInputElement>;
27
+ id?: string;
28
+ type?: HTMLInputTypeAttribute;
29
+ value?: string | number;
30
+ defaultValue?: string | number;
31
+ placeholder?: string;
32
+ min?: string | number;
33
+ max?: string | number;
34
+ step?: string | number;
35
+ readOnly?: boolean;
36
+ autoFocus?: boolean;
37
+ autoComplete?: string;
38
+ spellCheck?: boolean;
39
+ inputMode?: "text" | "numeric" | "decimal" | "search";
40
+ "aria-label"?: string;
41
+ "aria-invalid"?: boolean;
42
+ onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
43
+ onKeyDown?: KeyboardEventHandler<HTMLInputElement>;
44
+ onBlur?: FocusEventHandler<HTMLInputElement>;
45
+ onPointerDown?: PointerEventHandler<HTMLInputElement>;
46
+ }
47
+ /** A native `<select>` with `<option>` children: keyboard and test friendly. */
48
+ export interface UiNativeSelectProps extends Base {
49
+ id?: string;
50
+ value?: SelectHTMLAttributes<HTMLSelectElement>["value"];
51
+ disabled?: boolean;
52
+ "aria-label"?: string;
53
+ onChange?: (e: ChangeEvent<HTMLSelectElement>) => void;
54
+ children?: ReactNode;
55
+ }
56
+ export interface UiCheckboxProps extends Base {
57
+ id?: string;
58
+ checked: boolean;
59
+ onCheckedChange: (checked: boolean | "indeterminate") => void;
60
+ }
61
+ export interface SelectOption {
62
+ value: string;
63
+ label: string;
64
+ }
65
+ /** A single choice from a list. `value` is never "" (Radix reserves it); `undefined` shows the placeholder. */
66
+ export interface UiSelectProps extends Base {
67
+ value: string | undefined;
68
+ onValueChange: (v: string) => void;
69
+ options: readonly SelectOption[];
70
+ placeholder?: string;
71
+ "aria-label"?: string;
72
+ }
73
+ export interface SegmentedOption<V extends string> {
74
+ value: V;
75
+ label: ReactNode;
76
+ testId?: string;
77
+ /** Shown, not choosable; `tooltip` says why. */
78
+ disabled?: boolean;
79
+ tooltip?: string;
80
+ }
81
+ /** A single-choice segmented control (pages | infinite, table | cards, en | sr). */
82
+ export interface UiSegmentedProps<V extends string> extends Base {
83
+ value: V;
84
+ onChange: (v: V) => void;
85
+ options: readonly SegmentedOption<V>[];
86
+ "aria-label": string;
87
+ }
88
+ export interface UiSkeletonProps extends Base {
89
+ style?: CSSProperties;
90
+ }
91
+ export interface UiKbdProps {
92
+ className?: string;
93
+ children?: ReactNode;
94
+ }
95
+ export interface UiSpinnerProps {
96
+ className?: string;
97
+ }
98
+ /** A controlled modal dialog. */
99
+ export interface UiDialogProps {
100
+ open: boolean;
101
+ onOpenChange: (open: boolean) => void;
102
+ children?: ReactNode;
103
+ }
104
+ /** The dialog panel: a title row with a close button, then `children` (`DialogBody`, `DialogFooter`). */
105
+ export interface UiDialogContentProps extends Base {
106
+ title: ReactNode;
107
+ description?: ReactNode;
108
+ role?: "dialog" | "alertdialog";
109
+ "data-mode"?: string;
110
+ /** `preventDefault()` keeps the dialog open (a save in flight). */
111
+ onEscapeKeyDown?: (e: PreventableEvent) => void;
112
+ onInteractOutside?: (e: PreventableEvent) => void;
113
+ children?: ReactNode;
114
+ }
115
+ export interface UiBlockProps {
116
+ className?: string;
117
+ children?: ReactNode;
118
+ }
119
+ /**
120
+ * A trigger renders its own button unless `asChild`: then it merges its
121
+ * behaviour into its single child element, which must forward a ref.
122
+ */
123
+ export interface UiTriggerProps extends Base {
124
+ asChild?: boolean;
125
+ "aria-label"?: string;
126
+ children?: ReactNode;
127
+ }
128
+ /** An uncontrolled menu that opens from its trigger. */
129
+ export interface UiDropdownMenuProps {
130
+ /** `false`: the page behind stays interactive while the menu is open. */
131
+ modal?: boolean;
132
+ children?: ReactNode;
133
+ }
134
+ export interface UiDropdownMenuContentProps extends Base {
135
+ align?: "start" | "center" | "end";
136
+ children?: ReactNode;
137
+ }
138
+ export interface UiDropdownMenuItemProps extends Base {
139
+ tone?: "default" | "danger";
140
+ disabled?: boolean;
141
+ /** Runs on click or Enter; the menu then closes. */
142
+ onSelect?: () => void;
143
+ children?: ReactNode;
144
+ }
145
+ /** Controlled when `open` is given, otherwise it toggles from its trigger. */
146
+ export interface UiPopoverProps {
147
+ open?: boolean;
148
+ onOpenChange?: (open: boolean) => void;
149
+ children?: ReactNode;
150
+ }
151
+ export interface UiPopoverContentProps extends Base {
152
+ side?: "top" | "right" | "bottom" | "left";
153
+ align?: "start" | "center" | "end";
154
+ collisionPadding?: number;
155
+ "data-event-id"?: string;
156
+ /** `preventDefault()` keeps the focus where it was. */
157
+ onOpenAutoFocus?: (e: PreventableEvent) => void;
158
+ children?: ReactNode;
159
+ }
160
+ /** Positions the popover at an element that is not its trigger (a calendar event). */
161
+ export interface UiPopoverAnchorProps {
162
+ virtualRef: {
163
+ current: {
164
+ getBoundingClientRect(): DOMRect;
165
+ };
166
+ };
167
+ }
168
+ /** A hover / focus label on its single child, which must forward a ref. */
169
+ export interface UiTipProps {
170
+ label: ReactNode;
171
+ children: ReactNode;
172
+ }
173
+ export type ToastVariant = "info" | "success" | "warning" | "danger";
174
+ export interface ToastInput {
175
+ title: string;
176
+ description?: string;
177
+ variant?: ToastVariant;
178
+ }
179
+ /**
180
+ * Every primitive the renderers draw. Hand one to `UdcUiProvider kit={…}` (or
181
+ * `UdcProvider kit={…}`); without a provider the renderers use `defaultUiKit`
182
+ * from `@jsudc/react/ui`. A kit is read once per render, so keep the object
183
+ * stable (a module constant), and `useToast` is called as a hook.
184
+ */
185
+ export interface UiKit {
186
+ Button: ComponentType<UiButtonProps>;
187
+ Input: ComponentType<UiInputProps>;
188
+ NativeSelect: ComponentType<UiNativeSelectProps>;
189
+ Checkbox: ComponentType<UiCheckboxProps>;
190
+ Select: ComponentType<UiSelectProps>;
191
+ Segmented: <V extends string>(props: UiSegmentedProps<V>) => ReactNode;
192
+ Spinner: ComponentType<UiSpinnerProps>;
193
+ Skeleton: ComponentType<UiSkeletonProps>;
194
+ Kbd: ComponentType<UiKbdProps>;
195
+ Dialog: ComponentType<UiDialogProps>;
196
+ DialogContent: ComponentType<UiDialogContentProps>;
197
+ /** The scrolling middle of a dialog. */
198
+ DialogBody: ComponentType<UiBlockProps>;
199
+ /** The button row at the bottom of a dialog. */
200
+ DialogFooter: ComponentType<UiBlockProps>;
201
+ DropdownMenu: ComponentType<UiDropdownMenuProps>;
202
+ DropdownMenuTrigger: ComponentType<UiTriggerProps>;
203
+ DropdownMenuContent: ComponentType<UiDropdownMenuContentProps>;
204
+ DropdownMenuItem: ComponentType<UiDropdownMenuItemProps>;
205
+ DropdownMenuLabel: ComponentType<UiBlockProps>;
206
+ DropdownMenuSeparator: ComponentType<{
207
+ className?: string;
208
+ }>;
209
+ Popover: ComponentType<UiPopoverProps>;
210
+ PopoverTrigger: ComponentType<UiTriggerProps>;
211
+ PopoverContent: ComponentType<UiPopoverContentProps>;
212
+ PopoverAnchor: ComponentType<UiPopoverAnchorProps>;
213
+ /** Mounted once by the host around the view; `Tip` may need it. */
214
+ TooltipProvider: ComponentType<{
215
+ children: ReactNode;
216
+ }>;
217
+ Tip: ComponentType<UiTipProps>;
218
+ /** Mounted once by the host around the view: the toast stack and its viewport. */
219
+ Toaster: ComponentType<{
220
+ children: ReactNode;
221
+ }>;
222
+ /** A hook: returns the function that shows a toast. */
223
+ useToast: () => {
224
+ toast: (t: ToastInput) => void;
225
+ };
226
+ }
227
+ export {};
@@ -0,0 +1,12 @@
1
+ export { Button, type ButtonProps } from "../components/ui/button.js";
2
+ export { Checkbox } from "../components/ui/checkbox.js";
3
+ export { Dialog, DialogBody, DialogClose, DialogContent, DialogFooter, DialogTrigger, } from "../components/ui/dialog.js";
4
+ export { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "../components/ui/dropdown-menu.js";
5
+ export { Input, inputClass, NativeSelect } from "../components/ui/input.js";
6
+ export { Kbd, Skeleton, Spinner } from "../components/ui/misc.js";
7
+ export { Popover, PopoverAnchor, PopoverClose, PopoverContent, PopoverTrigger, } from "../components/ui/popover.js";
8
+ export { Segmented, type SegmentedOption } from "../components/ui/segmented.js";
9
+ export { Select, type SelectOption } from "../components/ui/select.js";
10
+ export { Toaster, type ToastInput, type ToastVariant, useToast } from "../components/ui/toast.js";
11
+ export { Tip, TooltipProvider } from "../components/ui/tooltip.js";
12
+ export { defaultUiKit } from "./default.js";
package/dist/ui.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./ui-kit/ui.js";
package/dist/ui.js ADDED
@@ -0,0 +1,13 @@
1
+ import { Button } from "./components/ui/button.js";
2
+ import { Checkbox } from "./components/ui/checkbox.js";
3
+ import { Dialog, DialogBody, DialogClose, DialogContent, DialogFooter, DialogTrigger } from "./components/ui/dialog.js";
4
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "./components/ui/dropdown-menu.js";
5
+ import { Input, NativeSelect, inputClass } from "./components/ui/input.js";
6
+ import { Kbd, Skeleton, Spinner } from "./components/ui/misc.js";
7
+ import { Popover, PopoverAnchor, PopoverClose, PopoverContent, PopoverTrigger } from "./components/ui/popover.js";
8
+ import { Segmented } from "./components/ui/segmented.js";
9
+ import { Select } from "./components/ui/select.js";
10
+ import { Toaster, useToast } from "./components/ui/toast.js";
11
+ import { Tip, TooltipProvider } from "./components/ui/tooltip.js";
12
+ import { defaultUiKit } from "./ui-kit/default.js";
13
+ export { Button, Checkbox, Dialog, DialogBody, DialogClose, DialogContent, DialogFooter, DialogTrigger, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, Input, Kbd, NativeSelect, Popover, PopoverAnchor, PopoverClose, PopoverContent, PopoverTrigger, Segmented, Select, Skeleton, Spinner, Tip, Toaster, TooltipProvider, defaultUiKit, inputClass, useToast };
@@ -0,0 +1,20 @@
1
+ import { type ReactNode } from "react";
2
+ import { type UrlStateAdapter } from "./adapter.js";
3
+ export interface UdcUrlStateProviderProps {
4
+ adapter: UrlStateAdapter;
5
+ children?: ReactNode;
6
+ }
7
+ /** Route the data view's URL state through `adapter`; without it, `windowLocationAdapter`. */
8
+ export declare function UdcUrlStateProvider({ adapter, children }: UdcUrlStateProviderProps): import("react").FunctionComponentElement<import("react").ProviderProps<UrlStateAdapter>>;
9
+ /** The adapter in effect: the nearest provider's, else `windowLocationAdapter`. */
10
+ export declare function useUrlStateAdapter(): UrlStateAdapter;
11
+ export type SetUrlSearchParams = (next: URLSearchParams | ((prev: URLSearchParams) => URLSearchParams), opts?: {
12
+ replace?: boolean;
13
+ }) => void;
14
+ /**
15
+ * `[params, setParams]` over the adapter in effect, shaped like a router's
16
+ * `useSearchParams`. A function passed to `setParams` gets the query string as
17
+ * the adapter has it now, not as the last render saw it, so two quick updates
18
+ * do not both start from the same state.
19
+ */
20
+ export declare function useUrlSearchParams(): [URLSearchParams, SetUrlSearchParams];
@@ -0,0 +1,27 @@
1
+ import { windowLocationAdapter } from "./adapter.js";
2
+ import { createContext, createElement, useCallback, useContext, useMemo, useSyncExternalStore } from "react";
3
+ // src/url-state/UrlState.ts
4
+ var UrlStateContext = createContext(windowLocationAdapter);
5
+ /** Route the data view's URL state through `adapter`; without it, `windowLocationAdapter`. */
6
+ function UdcUrlStateProvider({ adapter, children }) {
7
+ return createElement(UrlStateContext.Provider, { value: adapter }, children);
8
+ }
9
+ /** The adapter in effect: the nearest provider's, else `windowLocationAdapter`. */
10
+ function useUrlStateAdapter() {
11
+ return useContext(UrlStateContext);
12
+ }
13
+ /**
14
+ * `[params, setParams]` over the adapter in effect, shaped like a router's
15
+ * `useSearchParams`. A function passed to `setParams` gets the query string as
16
+ * the adapter has it now, not as the last render saw it, so two quick updates
17
+ * do not both start from the same state.
18
+ */
19
+ function useUrlSearchParams() {
20
+ const adapter = useUrlStateAdapter();
21
+ const snapshot = () => adapter.get().toString();
22
+ const search = useSyncExternalStore(adapter.subscribe, snapshot, snapshot);
23
+ return [useMemo(() => new URLSearchParams(search), [search]), useCallback((next, opts) => adapter.set(typeof next === "function" ? next(adapter.get()) : next, opts), [adapter])];
24
+ }
25
+ export { UdcUrlStateProvider, useUrlSearchParams, useUrlStateAdapter };
26
+
27
+ //# sourceMappingURL=UrlState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UrlState.js","names":[],"sources":["../../src/url-state/UrlState.ts"],"sourcesContent":["import {\n createContext,\n createElement,\n type ReactNode,\n useCallback,\n useContext,\n useMemo,\n useSyncExternalStore,\n} from \"react\";\nimport { type UrlStateAdapter, windowLocationAdapter } from \"./adapter.js\";\n\nconst UrlStateContext = createContext<UrlStateAdapter>(windowLocationAdapter);\n\nexport interface UdcUrlStateProviderProps {\n adapter: UrlStateAdapter;\n children?: ReactNode;\n}\n\n/** Route the data view's URL state through `adapter`; without it, `windowLocationAdapter`. */\nexport function UdcUrlStateProvider({ adapter, children }: UdcUrlStateProviderProps) {\n return createElement(UrlStateContext.Provider, { value: adapter }, children);\n}\n\n/** The adapter in effect: the nearest provider's, else `windowLocationAdapter`. */\nexport function useUrlStateAdapter(): UrlStateAdapter {\n return useContext(UrlStateContext);\n}\n\nexport type SetUrlSearchParams = (\n next: URLSearchParams | ((prev: URLSearchParams) => URLSearchParams),\n opts?: { replace?: boolean },\n) => void;\n\n/**\n * `[params, setParams]` over the adapter in effect, shaped like a router's\n * `useSearchParams`. A function passed to `setParams` gets the query string as\n * the adapter has it now, not as the last render saw it, so two quick updates\n * do not both start from the same state.\n */\nexport function useUrlSearchParams(): [URLSearchParams, SetUrlSearchParams] {\n const adapter = useUrlStateAdapter();\n const snapshot = () => adapter.get().toString();\n // The snapshot is the string: equal strings are equal state, so no render loop.\n const search = useSyncExternalStore(adapter.subscribe, snapshot, snapshot);\n const params = useMemo(() => new URLSearchParams(search), [search]);\n const setParams = useCallback<SetUrlSearchParams>(\n (next, opts) => adapter.set(typeof next === \"function\" ? next(adapter.get()) : next, opts),\n [adapter],\n );\n return [params, setParams];\n}\n"],"mappings":";;;AAWA,IAAM,kBAAkB,cAA+B,qBAAqB;;AAQ5E,SAAgB,oBAAoB,EAAE,SAAS,YAAsC;CACnF,OAAO,cAAc,gBAAgB,UAAU,EAAE,OAAO,QAAQ,GAAG,QAAQ;AAC7E;;AAGA,SAAgB,qBAAsC;CACpD,OAAO,WAAW,eAAe;AACnC;;;;;;;AAaA,SAAgB,qBAA4D;CAC1E,MAAM,UAAU,mBAAmB;CACnC,MAAM,iBAAiB,QAAQ,IAAI,CAAC,CAAC,SAAS;CAE9C,MAAM,SAAS,qBAAqB,QAAQ,WAAW,UAAU,QAAQ;CAMzE,OAAO,CALQ,cAAc,IAAI,gBAAgB,MAAM,GAAG,CAAC,MAAM,CAKzD,GAJU,aACf,MAAM,SAAS,QAAQ,IAAI,OAAO,SAAS,aAAa,KAAK,QAAQ,IAAI,CAAC,IAAI,MAAM,IAAI,GACzF,CAAC,OAAO,CAEM,CAAS;AAC3B"}