@alepha/ui 0.35.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -1
- package/dist/account/AccountBrand.d.ts +10 -3
- package/dist/account/AccountBrand.d.ts.map +1 -1
- package/dist/account/AccountBrand.js +12 -6
- package/dist/account/AccountBrand.js.map +1 -1
- package/dist/account/AccountLayout.d.ts.map +1 -1
- package/dist/account/AccountLayout.js +1 -1
- package/dist/account/AccountLayout.js.map +1 -1
- package/dist/admin/AdminUserDetail.d.ts +3 -3
- package/dist/admin/AdminUserDetail.js +3 -3
- package/dist/admin/AdminUserDetail.js.map +1 -1
- package/dist/ai/AiChat.d.ts +36 -6
- package/dist/ai/AiChat.d.ts.map +1 -1
- package/dist/ai/AiChat.js +101 -63
- package/dist/ai/AiChat.js.map +1 -1
- package/dist/ai/AiChatComposer.d.ts +22 -0
- package/dist/ai/AiChatComposer.d.ts.map +1 -0
- package/dist/ai/AiChatComposer.js +75 -0
- package/dist/ai/AiChatComposer.js.map +1 -0
- package/dist/ai/AiChatConfirmCard.d.ts +5 -2
- package/dist/ai/AiChatConfirmCard.d.ts.map +1 -1
- package/dist/ai/AiChatConfirmCard.js +7 -6
- package/dist/ai/AiChatConfirmCard.js.map +1 -1
- package/dist/ai/AiChatConfirmFields.d.ts +9 -0
- package/dist/ai/AiChatConfirmFields.d.ts.map +1 -0
- package/dist/ai/AiChatConfirmFields.js +45 -0
- package/dist/ai/AiChatConfirmFields.js.map +1 -0
- package/dist/ai/AiChatEmpty.d.ts +26 -0
- package/dist/ai/AiChatEmpty.d.ts.map +1 -0
- package/dist/ai/AiChatEmpty.js +47 -0
- package/dist/ai/AiChatEmpty.js.map +1 -0
- package/dist/ai/AiChatHistory.d.ts +3 -2
- package/dist/ai/AiChatHistory.d.ts.map +1 -1
- package/dist/ai/AiChatHistory.js +51 -22
- package/dist/ai/AiChatHistory.js.map +1 -1
- package/dist/ai/AiChatMessage.d.ts +14 -0
- package/dist/ai/AiChatMessage.d.ts.map +1 -1
- package/dist/ai/AiChatMessage.js +20 -12
- package/dist/ai/AiChatMessage.js.map +1 -1
- package/dist/ai/index.d.ts +3 -0
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +4 -1
- package/dist/ai/useAiChat.d.ts +4 -0
- package/dist/ai/useAiChat.d.ts.map +1 -1
- package/dist/ai/useAiChat.js +15 -1
- package/dist/ai/useAiChat.js.map +1 -1
- package/dist/core/Sidebar.js +2 -2
- package/dist/core/Sidebar.js.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -1
- package/dist/core/useToast.d.ts +22 -1
- package/dist/core/useToast.d.ts.map +1 -1
- package/dist/core/useToast.js +4 -1
- package/dist/core/useToast.js.map +1 -1
- package/dist/core/useUndoable.d.ts +93 -0
- package/dist/core/useUndoable.d.ts.map +1 -0
- package/dist/core/useUndoable.js +172 -0
- package/dist/core/useUndoable.js.map +1 -0
- package/dist/i18n/fr/uiFr.d.ts.map +1 -1
- package/dist/i18n/fr/uiFr.js +50 -1
- package/dist/i18n/fr/uiFr.js.map +1 -1
- package/dist/markdown/MarkdownView.d.ts +15 -0
- package/dist/markdown/MarkdownView.d.ts.map +1 -1
- package/dist/markdown/MarkdownView.js +4 -1
- package/dist/markdown/MarkdownView.js.map +1 -1
- package/dist/organizations/useInviteOrganizationMember.d.ts +2 -2
- package/dist/organizations/useInviteOrganizationMember.js.map +1 -1
- package/dist/shell/AppShellSidebarNavItem.d.ts.map +1 -1
- package/dist/shell/AppShellSidebarNavItem.js +25 -2
- package/dist/shell/AppShellSidebarNavItem.js.map +1 -1
- package/dist/shell/PlateTabBar.d.ts.map +1 -1
- package/dist/shell/PlateTabBar.js +2 -2
- package/dist/shell/PlateTabBar.js.map +1 -1
- package/dist/shell/SidebarBackHeader.d.ts +35 -0
- package/dist/shell/SidebarBackHeader.d.ts.map +1 -0
- package/dist/shell/SidebarBackHeader.js +34 -0
- package/dist/shell/SidebarBackHeader.js.map +1 -0
- package/dist/shell/appShellNav.d.ts +30 -0
- package/dist/shell/appShellNav.d.ts.map +1 -1
- package/dist/shell/appShellNav.js.map +1 -1
- package/dist/shell/index.d.ts +2 -1
- package/dist/shell/index.d.ts.map +1 -1
- package/dist/shell/index.js +2 -1
- package/dist/swagger/$uiSwagger.d.ts +75 -0
- package/dist/swagger/$uiSwagger.d.ts.map +1 -0
- package/dist/swagger/$uiSwagger.js +51 -0
- package/dist/swagger/$uiSwagger.js.map +1 -0
- package/dist/swagger/OpenApiSpec.d.ts +113 -0
- package/dist/swagger/OpenApiSpec.d.ts.map +1 -0
- package/dist/swagger/OpenApiSpec.js +186 -0
- package/dist/swagger/OpenApiSpec.js.map +1 -0
- package/dist/swagger/SwaggerAccessBadge.d.ts +16 -0
- package/dist/swagger/SwaggerAccessBadge.d.ts.map +1 -0
- package/dist/swagger/SwaggerAccessBadge.js +40 -0
- package/dist/swagger/SwaggerAccessBadge.js.map +1 -0
- package/dist/swagger/SwaggerAlephaMeta.d.ts +11 -0
- package/dist/swagger/SwaggerAlephaMeta.d.ts.map +1 -0
- package/dist/swagger/SwaggerAlephaMeta.js +103 -0
- package/dist/swagger/SwaggerAlephaMeta.js.map +1 -0
- package/dist/swagger/SwaggerCredentials.d.ts +11 -0
- package/dist/swagger/SwaggerCredentials.d.ts.map +1 -0
- package/dist/swagger/SwaggerCredentials.js +35 -0
- package/dist/swagger/SwaggerCredentials.js.map +1 -0
- package/dist/swagger/SwaggerExplorer.d.ts +31 -0
- package/dist/swagger/SwaggerExplorer.d.ts.map +1 -0
- package/dist/swagger/SwaggerExplorer.js +156 -0
- package/dist/swagger/SwaggerExplorer.js.map +1 -0
- package/dist/swagger/SwaggerMethodBadge.d.ts +10 -0
- package/dist/swagger/SwaggerMethodBadge.d.ts.map +1 -0
- package/dist/swagger/SwaggerMethodBadge.js +27 -0
- package/dist/swagger/SwaggerMethodBadge.js.map +1 -0
- package/dist/swagger/SwaggerNav.d.ts +16 -0
- package/dist/swagger/SwaggerNav.d.ts.map +1 -0
- package/dist/swagger/SwaggerNav.js +63 -0
- package/dist/swagger/SwaggerNav.js.map +1 -0
- package/dist/swagger/SwaggerOperationView.d.ts +22 -0
- package/dist/swagger/SwaggerOperationView.d.ts.map +1 -0
- package/dist/swagger/SwaggerOperationView.js +89 -0
- package/dist/swagger/SwaggerOperationView.js.map +1 -0
- package/dist/swagger/SwaggerParameters.d.ts +11 -0
- package/dist/swagger/SwaggerParameters.d.ts.map +1 -0
- package/dist/swagger/SwaggerParameters.js +80 -0
- package/dist/swagger/SwaggerParameters.js.map +1 -0
- package/dist/swagger/SwaggerRequestBuilder.d.ts +83 -0
- package/dist/swagger/SwaggerRequestBuilder.d.ts.map +1 -0
- package/dist/swagger/SwaggerRequestBuilder.js +231 -0
- package/dist/swagger/SwaggerRequestBuilder.js.map +1 -0
- package/dist/swagger/SwaggerResponseView.d.ts +25 -0
- package/dist/swagger/SwaggerResponseView.d.ts.map +1 -0
- package/dist/swagger/SwaggerResponseView.js +94 -0
- package/dist/swagger/SwaggerResponseView.js.map +1 -0
- package/dist/swagger/SwaggerResponses.d.ts +12 -0
- package/dist/swagger/SwaggerResponses.d.ts.map +1 -0
- package/dist/swagger/SwaggerResponses.js +75 -0
- package/dist/swagger/SwaggerResponses.js.map +1 -0
- package/dist/swagger/SwaggerSchemaView.d.ts +19 -0
- package/dist/swagger/SwaggerSchemaView.d.ts.map +1 -0
- package/dist/swagger/SwaggerSchemaView.js +98 -0
- package/dist/swagger/SwaggerSchemaView.js.map +1 -0
- package/dist/swagger/SwaggerSection.d.ts +14 -0
- package/dist/swagger/SwaggerSection.d.ts.map +1 -0
- package/dist/swagger/SwaggerSection.js +23 -0
- package/dist/swagger/SwaggerSection.js.map +1 -0
- package/dist/swagger/SwaggerTryIt.d.ts +31 -0
- package/dist/swagger/SwaggerTryIt.d.ts.map +1 -0
- package/dist/swagger/SwaggerTryIt.js +68 -0
- package/dist/swagger/SwaggerTryIt.js.map +1 -0
- package/dist/swagger/SwaggerTryItForm.d.ts +20 -0
- package/dist/swagger/SwaggerTryItForm.d.ts.map +1 -0
- package/dist/swagger/SwaggerTryItForm.js +52 -0
- package/dist/swagger/SwaggerTryItForm.js.map +1 -0
- package/dist/swagger/index.d.ts +29 -0
- package/dist/swagger/index.d.ts.map +1 -0
- package/dist/swagger/index.js +18 -0
- package/dist/swagger/useSwaggerAccess.d.ts +24 -0
- package/dist/swagger/useSwaggerAccess.d.ts.map +1 -0
- package/dist/swagger/useSwaggerAccess.js +33 -0
- package/dist/swagger/useSwaggerAccess.js.map +1 -0
- package/dist/table/DataTable.d.ts.map +1 -1
- package/dist/table/DataTable.js +50 -13
- package/dist/table/DataTable.js.map +1 -1
- package/dist/table/DataTableBody.d.ts +18 -1
- package/dist/table/DataTableBody.d.ts.map +1 -1
- package/dist/table/DataTableBody.js +83 -58
- package/dist/table/DataTableBody.js.map +1 -1
- package/dist/table/DataTableRowActionsInline.d.ts +17 -0
- package/dist/table/DataTableRowActionsInline.d.ts.map +1 -0
- package/dist/table/DataTableRowActionsInline.js +45 -0
- package/dist/table/DataTableRowActionsInline.js.map +1 -0
- package/dist/table/PermissionMatrix.d.ts +4 -4
- package/dist/table/PermissionMatrix.js +2 -2
- package/dist/table/PermissionMatrix.js.map +1 -1
- package/dist/table/dataTableBaseProps.d.ts +31 -0
- package/dist/table/dataTableBaseProps.d.ts.map +1 -1
- package/dist/table/dataTableTypes.d.ts +16 -2
- package/dist/table/dataTableTypes.d.ts.map +1 -1
- package/dist/table/useDataTableData.d.ts +3 -0
- package/dist/table/useDataTableData.d.ts.map +1 -1
- package/dist/table/useDataTableData.js +9 -2
- package/dist/table/useDataTableData.js.map +1 -1
- package/dist/table/useDataTableRefresh.d.ts +1 -0
- package/dist/table/useDataTableRefresh.d.ts.map +1 -1
- package/dist/table/useDataTableRefresh.js +13 -1
- package/dist/table/useDataTableRefresh.js.map +1 -1
- package/dist/table/useOptimisticRows.d.ts +64 -0
- package/dist/table/useOptimisticRows.d.ts.map +1 -0
- package/dist/table/useOptimisticRows.js +185 -0
- package/dist/table/useOptimisticRows.js.map +1 -0
- package/dist/table/useRowMotion.d.ts +27 -0
- package/dist/table/useRowMotion.d.ts.map +1 -0
- package/dist/table/useRowMotion.js +112 -0
- package/dist/table/useRowMotion.js.map +1 -0
- package/docs/packages-alepha-ui-core.md +1 -0
- package/docs/packages-alepha-ui-overview.md +53 -1
- package/docs/packages-alepha-ui-swagger.md +35 -0
- package/package.json +11 -3
- package/src/account/AccountBrand.tsx +25 -6
- package/src/account/AccountLayout.tsx +5 -1
- package/src/admin/AdminUserDetail.tsx +3 -3
- package/src/admin/__tests__/AdminUserDetail.spec.ts +2 -2
- package/src/ai/AiChat.tsx +160 -82
- package/src/ai/AiChatComposer.tsx +117 -0
- package/src/ai/AiChatConfirmCard.tsx +7 -5
- package/src/ai/AiChatConfirmFields.tsx +65 -0
- package/src/ai/AiChatEmpty.tsx +73 -0
- package/src/ai/AiChatHistory.tsx +64 -28
- package/src/ai/AiChatMessage.tsx +41 -14
- package/src/ai/__tests__/AiChat.browser.spec.tsx +146 -5
- package/src/ai/index.ts +3 -0
- package/src/ai/useAiChat.ts +18 -0
- package/src/core/Sidebar.tsx +2 -2
- package/src/core/__tests__/useUndoable.browser.spec.tsx +201 -0
- package/src/core/index.ts +7 -0
- package/src/core/useToast.tsx +30 -2
- package/src/core/useUndoable.tsx +285 -0
- package/src/form/__tests__/ControlChoices.browser.spec.tsx +2 -1
- package/src/i18n/fr/uiFr.ts +52 -0
- package/src/markdown/MarkdownView.tsx +27 -9
- package/src/organizations/useInviteOrganizationMember.ts +2 -2
- package/src/shell/AppShellSidebarNavItem.tsx +51 -1
- package/src/shell/PlateTabBar.tsx +8 -2
- package/src/shell/SidebarBackHeader.tsx +58 -0
- package/src/shell/appShellNav.tsx +31 -0
- package/src/shell/index.ts +5 -1
- package/src/swagger/$uiSwagger.tsx +95 -0
- package/src/swagger/OpenApiSpec.ts +300 -0
- package/src/swagger/SwaggerAccessBadge.tsx +64 -0
- package/src/swagger/SwaggerAlephaMeta.tsx +141 -0
- package/src/swagger/SwaggerCredentials.tsx +44 -0
- package/src/swagger/SwaggerExplorer.tsx +208 -0
- package/src/swagger/SwaggerMethodBadge.tsx +32 -0
- package/src/swagger/SwaggerNav.tsx +92 -0
- package/src/swagger/SwaggerOperationView.tsx +102 -0
- package/src/swagger/SwaggerParameters.tsx +74 -0
- package/src/swagger/SwaggerRequestBuilder.ts +331 -0
- package/src/swagger/SwaggerResponseView.tsx +107 -0
- package/src/swagger/SwaggerResponses.tsx +83 -0
- package/src/swagger/SwaggerSchemaView.tsx +134 -0
- package/src/swagger/SwaggerSection.tsx +29 -0
- package/src/swagger/SwaggerTryIt.tsx +95 -0
- package/src/swagger/SwaggerTryItForm.tsx +87 -0
- package/src/swagger/__tests__/$uiSwagger.spec.ts +52 -0
- package/src/swagger/__tests__/OpenApiSpec.spec.ts +139 -0
- package/src/swagger/__tests__/SwaggerAccess.browser.spec.tsx +124 -0
- package/src/swagger/__tests__/SwaggerOperationView.browser.spec.tsx +194 -0
- package/src/swagger/__tests__/SwaggerRequestBuilder.spec.ts +250 -0
- package/src/swagger/index.ts +75 -0
- package/src/swagger/useSwaggerAccess.ts +59 -0
- package/src/table/DataTable.tsx +85 -34
- package/src/table/DataTableBody.tsx +51 -7
- package/src/table/DataTableRowActionsInline.tsx +80 -0
- package/src/table/PermissionMatrix.tsx +4 -4
- package/src/table/__tests__/DataTableEmptyState.browser.spec.tsx +1 -1
- package/src/table/__tests__/DataTableListMode.browser.spec.tsx +174 -0
- package/src/table/__tests__/DataTableOptimistic.browser.spec.tsx +173 -0
- package/src/table/__tests__/PermissionMatrix.browser.spec.tsx +2 -2
- package/src/table/__tests__/queryFilters.spec.ts +10 -12
- package/src/table/dataTableBaseProps.ts +31 -0
- package/src/table/dataTableTypes.ts +16 -2
- package/src/table/useDataTableData.ts +18 -2
- package/src/table/useDataTableRefresh.ts +26 -2
- package/src/table/useOptimisticRows.ts +265 -0
- package/src/table/useRowMotion.ts +152 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDataTableRefresh.js","names":[],"sources":["../../src/table/useDataTableRefresh.ts"],"sourcesContent":["import type { Alepha, ZObject } from \"alepha\";\nimport type { FormModel } from \"alepha/react/form\";\nimport type { I18nProvider } from \"alepha/react/i18n\";\nimport {\n type Dispatch,\n type SetStateAction,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\n\nimport type { Toast } from \"../core/useToast.tsx\";\nimport type { DataTableBaseProps } from \"./dataTableBaseProps.ts\";\nimport { writePersisted } from \"./dataTablePersistence.ts\";\nimport type {\n DataTableFilterFields,\n DataTableSource,\n} from \"./dataTableTypes.ts\";\nimport { cleanFilterValues, shareFiltersUrl } from \"./queryFilters.ts\";\n\nexport interface UseDataTableRefreshOptions<T> {\n props: DataTableBaseProps<T, DataTableFilterFields> &\n DataTableSource<T, DataTableFilterFields>;\n form: FormModel<ZObject> | undefined;\n /**\n * Every filter key, operator keys included, as read at mount. Reset clears\n * each of them and Share rewrites each of them.\n */\n filterKeys: readonly string[];\n /**\n * Put the bar back to its declaration. Reset filters is one act: the\n * values empty and the bar returns to what the table declares, together.\n */\n resetShownFilters: () => void;\n /**\n * The key the filter values are persisted under, or `undefined` when the\n * table does not store them.\n */\n filtersKey: string | undefined;\n alepha: Alepha;\n toast: Toast;\n tr: I18nProvider<any, any>[\"tr\"];\n setPage: Dispatch<SetStateAction<number>>;\n setRefreshKey: Dispatch<SetStateAction<number>>;\n setIsRefreshing: Dispatch<SetStateAction<boolean>>;\n}\n\n/**\n * What makes `DataTable` fetch again, and the filter actions that sit\n * beside it: the refresh button and `refreshSignal`, filter reset and share,\n * the filter form's submit and change events (with the filter persistence\n * they drive), and polling.\n *\n * It owns no row state. The page and the refresh key it writes belong to\n * `useDataTableData`.\n */\nexport const useDataTableRefresh = <T>(\n options: UseDataTableRefreshOptions<T>,\n) => {\n const {\n props,\n form,\n filterKeys,\n resetShownFilters,\n filtersKey,\n alepha,\n toast,\n tr,\n setPage,\n setRefreshKey,\n setIsRefreshing,\n } = options;\n\n // -- Refresh + reset wiring -----------------------------------------------\n\n const refresh = useCallback(() => {\n setPage(0);\n setRefreshKey((k) => k + 1);\n }, []);\n\n const handleRefreshClick = useCallback(() => {\n setIsRefreshing(true);\n refresh();\n setTimeout(() => setIsRefreshing(false), 1000);\n }, [refresh]);\n\n // React to the external `refreshSignal` prop. The first render seeds the\n // ref without refetching (the mount effect already loads); every later\n // change triggers a refresh. Kept separate from `load`'s deps so an inline\n // `fetch` closure can't self-trigger a loop (see `fetchRef` above).\n const refreshSignalRef = useRef(props.refreshSignal);\n useEffect(() => {\n if (refreshSignalRef.current === props.refreshSignal) return;\n refreshSignalRef.current = props.refreshSignal;\n refresh();\n }, [props.refreshSignal, refresh]);\n\n const resetFilters = useCallback(() => {\n if (!form || !props.filters) return;\n // Per-field `.set(undefined)` is necessary: `setInitialValues({})`\n // doesn't emit `form:changed` for deleted keys, so inputs stay\n // visually populated and subscribers don't refetch. Explicit set\n // keeps everyone in sync.\n for (const key of filterKeys) {\n const input = (form.input as Record<string, { set?: (v: any) => void }>)[\n key\n ];\n input?.set?.(undefined);\n }\n resetShownFilters();\n }, [form, props.filters, filterKeys, resetShownFilters]);\n\n /**\n * Copy a link that opens this table with these filters.\n *\n * The write half of `fromQuery`, and the only one: nothing puts the\n * filters in the address bar as the reader types, so a link out of a\n * filtered table has to be asked for. Built on the page's own URL, so the\n * params the page owns travel with it.\n */\n /**\n * Whether a link out of this table would do anything on arrival.\n *\n * A table that does not read the query back would copy a URL whose params\n * are inert, which is worse than no Share at all: it looks like it worked.\n */\n const canShare = Boolean(props.filters?.fromQuery);\n\n const shareFilters = useCallback(async () => {\n if (!props.filters || !form) return;\n const url = shareFiltersUrl(\n window.location.href,\n filterKeys,\n cleanFilterValues(form.currentValues ?? {}),\n );\n try {\n await navigator.clipboard.writeText(url);\n toast.success(\n tr(\"dataTable.shareFiltersCopied\", { default: \"Link copied\" }),\n );\n } catch {\n // A denied clipboard permission, or an insecure origin. Nothing here\n // is worth an error toast the reader cannot act on.\n }\n }, [form, props.filters, filterKeys, toast, tr]);\n\n // -- Form event subscriptions ---------------------------------------------\n\n // Refetch on explicit submit (manual Apply, programmatic submit, etc.).\n useEffect(() => {\n if (!form) return;\n return alepha.events.on(\"form:submit:success\", (event) => {\n if (event.id !== form.id) return;\n setPage(0);\n setRefreshKey((k) => k + 1);\n });\n }, [alepha, form]);\n\n // Refetch on change (debounced) when autoApplyFilters is on. Default\n // is on whenever DataTable owns the form (`filters` prop).\n const autoApply = props.autoApplyFilters ?? Boolean(props.filters);\n useEffect(() => {\n if (!form || !autoApply) return;\n let timeout: ReturnType<typeof setTimeout> | undefined;\n const unsub = alepha.events.on(\"form:changed\", (event) => {\n if (event.id !== form.id) return;\n if (timeout) clearTimeout(timeout);\n timeout = setTimeout(() => {\n setPage(0);\n setRefreshKey((k) => k + 1);\n }, 250);\n });\n return () => {\n if (timeout) clearTimeout(timeout);\n unsub();\n };\n }, [alepha, form, autoApply]);\n\n // Persist filter values to localStorage on change.\n useEffect(() => {\n if (!filtersKey || !form || !props.filters) return;\n const writeFilters = () => {\n writePersisted(\n filtersKey,\n \"filters\",\n cleanFilterValues(form.currentValues ?? {}),\n );\n };\n const unsubs = [\n alepha.events.on(\"form:changed\", (event) => {\n if (event.id !== form.id) return;\n writeFilters();\n }),\n alepha.events.on(\"form:submit:success\", (event) => {\n if (event.id !== form.id) return;\n writeFilters();\n }),\n ];\n return () => {\n for (const u of unsubs) u();\n };\n }, [alepha, form, props.filters, filtersKey]);\n\n // -- Polling ---------------------------------------------------------------\n\n useEffect(() => {\n if (!props.pollMs) return;\n const id = setInterval(() => {\n if (document.visibilityState === \"visible\") setRefreshKey((k) => k + 1);\n }, props.pollMs);\n return () => clearInterval(id);\n }, [props.pollMs]);\n\n return { refresh, handleRefreshClick, resetFilters, canShare, sh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AAa,cAAc,EAAE;CAC/B,GAAG,CAAC,MAAM,MAAM,CAAC;CAEjB,OAAO;EAAE;EAAS;EAAoB;EAAc;EAAU;CAAa;AAC7E"}
|
|
1
|
+
{"version":3,"file":"useDataTableRefresh.js","names":[],"sources":["../../src/table/useDataTableRefresh.ts"],"sourcesContent":["import type { Alepha, ZObject } from \"alepha\";\nimport type { FormModel } from \"alepha/react/form\";\nimport type { I18nProvider } from \"alepha/react/i18n\";\nimport {\n type Dispatch,\n type SetStateAction,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\n\nimport type { Toast } from \"../core/useToast.tsx\";\nimport type { DataTableBaseProps } from \"./dataTableBaseProps.ts\";\nimport { writePersisted } from \"./dataTablePersistence.ts\";\nimport type {\n DataTableFilterFields,\n DataTableSource,\n} from \"./dataTableTypes.ts\";\nimport { cleanFilterValues, shareFiltersUrl } from \"./queryFilters.ts\";\n\nexport interface UseDataTableRefreshOptions<T> {\n props: DataTableBaseProps<T, DataTableFilterFields> &\n DataTableSource<T, DataTableFilterFields>;\n form: FormModel<ZObject> | undefined;\n /**\n * Every filter key, operator keys included, as read at mount. Reset clears\n * each of them and Share rewrites each of them.\n */\n filterKeys: readonly string[];\n /**\n * Put the bar back to its declaration. Reset filters is one act: the\n * values empty and the bar returns to what the table declares, together.\n */\n resetShownFilters: () => void;\n /**\n * The key the filter values are persisted under, or `undefined` when the\n * table does not store them.\n */\n filtersKey: string | undefined;\n alepha: Alepha;\n toast: Toast;\n tr: I18nProvider<any, any>[\"tr\"];\n setPage: Dispatch<SetStateAction<number>>;\n setRefreshKey: Dispatch<SetStateAction<number>>;\n setIsRefreshing: Dispatch<SetStateAction<boolean>>;\n}\n\n/**\n * What makes `DataTable` fetch again, and the filter actions that sit\n * beside it: the refresh button and `refreshSignal`, filter reset and share,\n * the filter form's submit and change events (with the filter persistence\n * they drive), and polling.\n *\n * It owns no row state. The page and the refresh key it writes belong to\n * `useDataTableData`.\n */\nexport const useDataTableRefresh = <T>(\n options: UseDataTableRefreshOptions<T>,\n) => {\n const {\n props,\n form,\n filterKeys,\n resetShownFilters,\n filtersKey,\n alepha,\n toast,\n tr,\n setPage,\n setRefreshKey,\n setIsRefreshing,\n } = options;\n\n // -- Refresh + reset wiring -----------------------------------------------\n\n const refresh = useCallback(() => {\n setPage(0);\n setRefreshKey((k) => k + 1);\n }, []);\n\n /**\n * Fetch the page again where the reader is: no jump to page one, no\n * skeleton (the rows stay until the new ones land). What a row action\n * wants after a write, where `refresh` is what a filter change wants.\n */\n const reload = useCallback(() => {\n setRefreshKey((k) => k + 1);\n }, []);\n\n // The spinner's one-second timer, cleared on unmount: a table that is gone\n // must not take a state update (in a jsdom spec, it lands after teardown).\n const spinTimer = useRef<ReturnType<typeof setTimeout> | undefined>(\n undefined,\n );\n useEffect(() => () => clearTimeout(spinTimer.current), []);\n\n const handleRefreshClick = useCallback(() => {\n setIsRefreshing(true);\n refresh();\n clearTimeout(spinTimer.current);\n spinTimer.current = setTimeout(() => setIsRefreshing(false), 1000);\n }, [refresh]);\n\n // React to the external `refreshSignal` prop. The first render seeds the\n // ref without refetching (the mount effect already loads); every later\n // change triggers a refresh. Kept separate from `load`'s deps so an inline\n // `fetch` closure can't self-trigger a loop (see `fetchRef` above).\n const refreshSignalRef = useRef(props.refreshSignal);\n useEffect(() => {\n if (refreshSignalRef.current === props.refreshSignal) return;\n refreshSignalRef.current = props.refreshSignal;\n refresh();\n }, [props.refreshSignal, refresh]);\n\n const resetFilters = useCallback(() => {\n if (!form || !props.filters) return;\n // Per-field `.set(undefined)` is necessary: `setInitialValues({})`\n // doesn't emit `form:changed` for deleted keys, so inputs stay\n // visually populated and subscribers don't refetch. Explicit set\n // keeps everyone in sync.\n for (const key of filterKeys) {\n const input = (form.input as Record<string, { set?: (v: any) => void }>)[\n key\n ];\n input?.set?.(undefined);\n }\n resetShownFilters();\n }, [form, props.filters, filterKeys, resetShownFilters]);\n\n /**\n * Copy a link that opens this table with these filters.\n *\n * The write half of `fromQuery`, and the only one: nothing puts the\n * filters in the address bar as the reader types, so a link out of a\n * filtered table has to be asked for. Built on the page's own URL, so the\n * params the page owns travel with it.\n */\n /**\n * Whether a link out of this table would do anything on arrival.\n *\n * A table that does not read the query back would copy a URL whose params\n * are inert, which is worse than no Share at all: it looks like it worked.\n */\n const canShare = Boolean(props.filters?.fromQuery);\n\n const shareFilters = useCallback(async () => {\n if (!props.filters || !form) return;\n const url = shareFiltersUrl(\n window.location.href,\n filterKeys,\n cleanFilterValues(form.currentValues ?? {}),\n );\n try {\n await navigator.clipboard.writeText(url);\n toast.success(\n tr(\"dataTable.shareFiltersCopied\", { default: \"Link copied\" }),\n );\n } catch {\n // A denied clipboard permission, or an insecure origin. Nothing here\n // is worth an error toast the reader cannot act on.\n }\n }, [form, props.filters, filterKeys, toast, tr]);\n\n // -- Form event subscriptions ---------------------------------------------\n\n // Refetch on explicit submit (manual Apply, programmatic submit, etc.).\n useEffect(() => {\n if (!form) return;\n return alepha.events.on(\"form:submit:success\", (event) => {\n if (event.id !== form.id) return;\n setPage(0);\n setRefreshKey((k) => k + 1);\n });\n }, [alepha, form]);\n\n // Refetch on change (debounced) when autoApplyFilters is on. Default\n // is on whenever DataTable owns the form (`filters` prop).\n const autoApply = props.autoApplyFilters ?? Boolean(props.filters);\n useEffect(() => {\n if (!form || !autoApply) return;\n let timeout: ReturnType<typeof setTimeout> | undefined;\n const unsub = alepha.events.on(\"form:changed\", (event) => {\n if (event.id !== form.id) return;\n if (timeout) clearTimeout(timeout);\n timeout = setTimeout(() => {\n setPage(0);\n setRefreshKey((k) => k + 1);\n }, 250);\n });\n return () => {\n if (timeout) clearTimeout(timeout);\n unsub();\n };\n }, [alepha, form, autoApply]);\n\n // Persist filter values to localStorage on change.\n useEffect(() => {\n if (!filtersKey || !form || !props.filters) return;\n const writeFilters = () => {\n writePersisted(\n filtersKey,\n \"filters\",\n cleanFilterValues(form.currentValues ?? {}),\n );\n };\n const unsubs = [\n alepha.events.on(\"form:changed\", (event) => {\n if (event.id !== form.id) return;\n writeFilters();\n }),\n alepha.events.on(\"form:submit:success\", (event) => {\n if (event.id !== form.id) return;\n writeFilters();\n }),\n ];\n return () => {\n for (const u of unsubs) u();\n };\n }, [alepha, form, props.filters, filtersKey]);\n\n // -- Polling ---------------------------------------------------------------\n\n useEffect(() => {\n if (!props.pollMs) return;\n const id = setInterval(() => {\n if (document.visibilityState === \"visible\") setRefreshKey((k) => k + 1);\n }, props.pollMs);\n return () => clearInterval(id);\n }, [props.pollMs]);\n\n return {\n refresh,\n reload,\n handleRefreshClick,\n resetFilters,\n canShare,\n shareFilters,\n };\n};\n"],"mappings":";;;;;;;;;;;;;AAwDA,MAAa,uBACX,YACG;CACH,MAAM,EACJ,OACA,MACA,YACA,mBACA,YACA,QACA,OACA,IACA,SACA,eACA,oBACE;CAIJ,MAAM,UAAU,kBAAkB;EAChC,QAAQ,CAAC;EACT,eAAe,MAAM,IAAI,CAAC;CAC5B,GAAG,CAAC,CAAC;;;;;;CAOL,MAAM,SAAS,kBAAkB;EAC/B,eAAe,MAAM,IAAI,CAAC;CAC5B,GAAG,CAAC,CAAC;CAIL,MAAM,YAAY,OAChB,KAAA,CACF;CACA,sBAAsB,aAAa,UAAU,OAAO,GAAG,CAAC,CAAC;CAEzD,MAAM,qBAAqB,kBAAkB;EAC3C,gBAAgB,IAAI;EACpB,QAAQ;EACR,aAAa,UAAU,OAAO;EAC9B,UAAU,UAAU,iBAAiB,gBAAgB,KAAK,GAAG,GAAI;CACnE,GAAG,CAAC,OAAO,CAAC;CAMZ,MAAM,mBAAmB,OAAO,MAAM,aAAa;CACnD,gBAAgB;EACd,IAAI,iBAAiB,YAAY,MAAM,eAAe;EACtD,iBAAiB,UAAU,MAAM;EACjC,QAAQ;CACV,GAAG,CAAC,MAAM,eAAe,OAAO,CAAC;CAEjC,MAAM,eAAe,kBAAkB;EACrC,IAAI,CAAC,QAAQ,CAAC,MAAM,SAAS;EAK7B,KAAK,MAAM,OAAO,YAIhB,KAHoB,M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AAS;EAC5C,MAAM,qBAAqB;GACzB,eACE,YACA,WACA,kBAAkB,KAAK,iBAAiB,CAAC,CAAC,CAC5C;EACF;EACA,MAAM,SAAS,CACb,OAAO,OAAO,GAAG,iBAAiB,UAAU;GAC1C,IAAI,MAAM,OAAO,KAAK,IAAI;GAC1B,aAAa;EACf,CAAC,GACD,OAAO,OAAO,GAAG,wBAAwB,UAAU;GACjD,IAAI,MAAM,OAAO,KAAK,IAAI;GAC1B,aAAa;EACf,CAAC,CACH;EACA,aAAa;GACX,KAAK,MAAM,KAAK,QAAQ,EAAE;EAC5B;CACF,GAAG;EAAC;EAAQ;EAAM,MAAM;EAAS;CAAU,CAAC;CAI5C,gBAAgB;EACd,IAAI,CAAC,MAAM,QAAQ;EACnB,MAAM,KAAK,kBAAkB;GAC3B,IAAI,SAAS,oBAAoB,WAAW,eAAe,MAAM,IAAI,CAAC;EACxE,GAAG,MAAM,MAAM;EACf,aAAa,cAAc,EAAE;CAC/B,GAAG,CAAC,MAAM,MAAM,CAAC;CAEjB,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a row action gets back from `ctx.optimistic`: how to put the row back,
|
|
3
|
+
* and how to say the server agreed. `useUndoable`'s `apply` accepts it as is.
|
|
4
|
+
*/
|
|
5
|
+
export interface OptimisticHandle {
|
|
6
|
+
/**
|
|
7
|
+
* The write failed or was undone: the row comes back as it was.
|
|
8
|
+
*/
|
|
9
|
+
rollback: () => void;
|
|
10
|
+
/**
|
|
11
|
+
* The server accepted the write. The table reloads the page in place and
|
|
12
|
+
* lets go of the overlay once that reload has answered, so the row never
|
|
13
|
+
* flickers back between the two.
|
|
14
|
+
*/
|
|
15
|
+
settle: () => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The optimistic verbs a row or bulk action receives on its context.
|
|
19
|
+
*/
|
|
20
|
+
export interface OptimisticRows<T> {
|
|
21
|
+
/**
|
|
22
|
+
* Take rows off the page now: they play their exit, the rows below close
|
|
23
|
+
* the gap.
|
|
24
|
+
*/
|
|
25
|
+
remove: (items: T | T[]) => OptimisticHandle;
|
|
26
|
+
/**
|
|
27
|
+
* Draw a row as `next` now (a new status chip, a new assignee). The row
|
|
28
|
+
* flashes so the eye finds what changed.
|
|
29
|
+
*/
|
|
30
|
+
patch: (item: T, next: T) => OptimisticHandle;
|
|
31
|
+
}
|
|
32
|
+
export interface UseOptimisticRowsOptions<T> {
|
|
33
|
+
data: T[];
|
|
34
|
+
rowKeys: string[];
|
|
35
|
+
rowKey: (item: T) => string;
|
|
36
|
+
/**
|
|
37
|
+
* The id of the request whose rows are on screen.
|
|
38
|
+
*/
|
|
39
|
+
loadedRequestId: number;
|
|
40
|
+
/**
|
|
41
|
+
* The id of the newest request sent.
|
|
42
|
+
*/
|
|
43
|
+
lastRequestId: () => number;
|
|
44
|
+
reload: () => void;
|
|
45
|
+
/**
|
|
46
|
+
* Static mode: the caller owns the rows, so a settled overlay goes at once.
|
|
47
|
+
*/
|
|
48
|
+
isStatic: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The layer between the rows the server sent and the rows on screen.
|
|
52
|
+
*
|
|
53
|
+
* An entry hides or redraws one row by key until it is rolled back or
|
|
54
|
+
* settled. A settled entry waits for a request that left AFTER the settle,
|
|
55
|
+
* because one that left before still carries the old row.
|
|
56
|
+
*/
|
|
57
|
+
export declare const useOptimisticRows: <T>(options: UseOptimisticRowsOptions<T>) => {
|
|
58
|
+
data: T[];
|
|
59
|
+
rowKeys: string[];
|
|
60
|
+
leaving: ReadonlySet<string>;
|
|
61
|
+
flash: Set<string>;
|
|
62
|
+
optimistic: OptimisticRows<T>;
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=useOptimisticRows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOptimisticRows.d.ts","sourceRoot":"","sources":["../../src/table/useOptimisticRows.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB;;;;OAIG;IACH,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B;;;OAGG;IACH,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,gBAAgB,CAAC;IAC7C;;;OAGG;IACH,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,gBAAgB,CAAC;CAC/C;AAYD,MAAM,WAAW,wBAAwB,CAAC,CAAC;IACzC,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,CAAC;IAC5B;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,aAAa,EAAE,MAAM,MAAM,CAAC;IAC5B,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,WAAW,wBAAwB,CAAC,CAAC,CAAC;;;;;;CA+KxE,CAAC"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
// src/table/useOptimisticRows.ts
|
|
3
|
+
/**
|
|
4
|
+
* How long a removed row plays its exit before it leaves the DOM. Matches
|
|
5
|
+
* `useRowMotion`'s exit animation.
|
|
6
|
+
*/
|
|
7
|
+
const LEAVE_MS = 200;
|
|
8
|
+
/**
|
|
9
|
+
* The layer between the rows the server sent and the rows on screen.
|
|
10
|
+
*
|
|
11
|
+
* An entry hides or redraws one row by key until it is rolled back or
|
|
12
|
+
* settled. A settled entry waits for a request that left AFTER the settle,
|
|
13
|
+
* because one that left before still carries the old row.
|
|
14
|
+
*/
|
|
15
|
+
const useOptimisticRows = (options) => {
|
|
16
|
+
const { data, rowKeys, loadedRequestId, lastRequestId, reload, isStatic } = options;
|
|
17
|
+
const [allEntries, setEntries] = useState(() => /* @__PURE__ */ new Map());
|
|
18
|
+
const flashRef = useRef(/* @__PURE__ */ new Set());
|
|
19
|
+
const loadedRef = useRef(loadedRequestId);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
loadedRef.current = loadedRequestId;
|
|
22
|
+
}, [loadedRequestId]);
|
|
23
|
+
const timers = useRef(/* @__PURE__ */ new Set());
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
const pending = timers.current;
|
|
26
|
+
return () => {
|
|
27
|
+
for (const timer of pending) clearTimeout(timer);
|
|
28
|
+
pending.clear();
|
|
29
|
+
};
|
|
30
|
+
}, []);
|
|
31
|
+
/**
|
|
32
|
+
* Every write starts by dropping the dead entries, so a rollback sees a
|
|
33
|
+
* settled row as gone and puts it back by hand.
|
|
34
|
+
*/
|
|
35
|
+
const update = useCallback((fn) => setEntries((prev) => {
|
|
36
|
+
const next = new Map(prev);
|
|
37
|
+
for (const [key, entry] of next) if (!isLive(entry, loadedRef.current)) next.delete(key);
|
|
38
|
+
fn(next);
|
|
39
|
+
return next;
|
|
40
|
+
}), []);
|
|
41
|
+
const handleFor = useCallback((keys, originals) => ({
|
|
42
|
+
rollback: () => update((next) => {
|
|
43
|
+
for (const key of keys) {
|
|
44
|
+
const entry = next.get(key);
|
|
45
|
+
const original = originals?.get(key);
|
|
46
|
+
if (!entry && original) next.set(key, {
|
|
47
|
+
kind: "restore",
|
|
48
|
+
value: original.item,
|
|
49
|
+
index: original.index
|
|
50
|
+
});
|
|
51
|
+
else next.delete(key);
|
|
52
|
+
}
|
|
53
|
+
}),
|
|
54
|
+
settle: () => {
|
|
55
|
+
if (isStatic) {
|
|
56
|
+
update((next) => {
|
|
57
|
+
for (const key of keys) next.delete(key);
|
|
58
|
+
});
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const after = lastRequestId();
|
|
62
|
+
update((next) => {
|
|
63
|
+
for (const key of keys) {
|
|
64
|
+
const entry = next.get(key);
|
|
65
|
+
if (entry) next.set(key, {
|
|
66
|
+
...entry,
|
|
67
|
+
settledAfter: after
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
reload();
|
|
72
|
+
}
|
|
73
|
+
}), [
|
|
74
|
+
update,
|
|
75
|
+
isStatic,
|
|
76
|
+
lastRequestId,
|
|
77
|
+
reload
|
|
78
|
+
]);
|
|
79
|
+
const remove = useCallback((items) => {
|
|
80
|
+
const list = Array.isArray(items) ? items : [items];
|
|
81
|
+
const keys = list.map(options.rowKey);
|
|
82
|
+
const originals = /* @__PURE__ */ new Map();
|
|
83
|
+
list.forEach((item, i) => originals.set(keys[i], {
|
|
84
|
+
item,
|
|
85
|
+
index: rowKeys.indexOf(keys[i])
|
|
86
|
+
}));
|
|
87
|
+
update((next) => {
|
|
88
|
+
for (const key of keys) next.set(key, {
|
|
89
|
+
kind: "remove",
|
|
90
|
+
leaving: true
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
const timer = setTimeout(() => {
|
|
94
|
+
timers.current.delete(timer);
|
|
95
|
+
update((next) => {
|
|
96
|
+
for (const key of keys) {
|
|
97
|
+
const entry = next.get(key);
|
|
98
|
+
if (entry?.kind === "remove") next.set(key, {
|
|
99
|
+
...entry,
|
|
100
|
+
leaving: false
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}, LEAVE_MS);
|
|
105
|
+
timers.current.add(timer);
|
|
106
|
+
return handleFor(keys, originals);
|
|
107
|
+
}, [
|
|
108
|
+
update,
|
|
109
|
+
handleFor,
|
|
110
|
+
options.rowKey,
|
|
111
|
+
rowKeys
|
|
112
|
+
]);
|
|
113
|
+
const patch = useCallback((item, value) => {
|
|
114
|
+
const key = options.rowKey(item);
|
|
115
|
+
flashRef.current.add(key);
|
|
116
|
+
update((next) => {
|
|
117
|
+
next.set(key, {
|
|
118
|
+
kind: "patch",
|
|
119
|
+
value
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
return handleFor([key]);
|
|
123
|
+
}, [
|
|
124
|
+
update,
|
|
125
|
+
handleFor,
|
|
126
|
+
options.rowKey
|
|
127
|
+
]);
|
|
128
|
+
const view = useMemo(() => {
|
|
129
|
+
const entries = new Map([...allEntries].filter(([, entry]) => isLive(entry, loadedRequestId)));
|
|
130
|
+
if (entries.size === 0) return {
|
|
131
|
+
data,
|
|
132
|
+
rowKeys,
|
|
133
|
+
leaving: EMPTY
|
|
134
|
+
};
|
|
135
|
+
const outData = [];
|
|
136
|
+
const outKeys = [];
|
|
137
|
+
const leaving = /* @__PURE__ */ new Set();
|
|
138
|
+
data.forEach((item, index) => {
|
|
139
|
+
const key = rowKeys[index];
|
|
140
|
+
const entry = entries.get(key);
|
|
141
|
+
if (entry?.kind === "remove") {
|
|
142
|
+
if (!entry.leaving) return;
|
|
143
|
+
leaving.add(key);
|
|
144
|
+
}
|
|
145
|
+
outData.push(entry?.kind === "patch" ? entry.value : item);
|
|
146
|
+
outKeys.push(key);
|
|
147
|
+
});
|
|
148
|
+
const present = new Set(rowKeys);
|
|
149
|
+
const restores = [...entries].filter(([key, e]) => e.kind === "restore" && !present.has(key)).sort(([, a], [, b]) => a.kind === "restore" && b.kind === "restore" ? a.index - b.index : 0);
|
|
150
|
+
for (const [key, entry] of restores) {
|
|
151
|
+
if (entry.kind !== "restore") continue;
|
|
152
|
+
const at = Math.max(0, Math.min(entry.index, outData.length));
|
|
153
|
+
outData.splice(at, 0, entry.value);
|
|
154
|
+
outKeys.splice(at, 0, key);
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
data: outData,
|
|
158
|
+
rowKeys: outKeys,
|
|
159
|
+
leaving
|
|
160
|
+
};
|
|
161
|
+
}, [
|
|
162
|
+
data,
|
|
163
|
+
rowKeys,
|
|
164
|
+
allEntries,
|
|
165
|
+
loadedRequestId
|
|
166
|
+
]);
|
|
167
|
+
const optimistic = useMemo(() => ({
|
|
168
|
+
remove,
|
|
169
|
+
patch
|
|
170
|
+
}), [remove, patch]);
|
|
171
|
+
return {
|
|
172
|
+
...view,
|
|
173
|
+
flash: flashRef.current,
|
|
174
|
+
optimistic
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
const EMPTY = /* @__PURE__ */ new Set();
|
|
178
|
+
/**
|
|
179
|
+
* Whether an entry still overrides the server's row: never settled, or
|
|
180
|
+
* settled and still waiting for a request sent after it to answer.
|
|
181
|
+
*/
|
|
182
|
+
const isLive = (entry, loadedRequestId) => entry.settledAfter === void 0 || loadedRequestId <= entry.settledAfter;
|
|
183
|
+
export { useOptimisticRows };
|
|
184
|
+
|
|
185
|
+
//# sourceMappingURL=useOptimisticRows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOptimisticRows.js","names":[],"sources":["../../src/table/useOptimisticRows.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\n\n/**\n * How long a removed row plays its exit before it leaves the DOM. Matches\n * `useRowMotion`'s exit animation.\n */\nconst LEAVE_MS = 200;\n\n/**\n * What a row action gets back from `ctx.optimistic`: how to put the row back,\n * and how to say the server agreed. `useUndoable`'s `apply` accepts it as is.\n */\nexport interface OptimisticHandle {\n /**\n * The write failed or was undone: the row comes back as it was.\n */\n rollback: () => void;\n /**\n * The server accepted the write. The table reloads the page in place and\n * lets go of the overlay once that reload has answered, so the row never\n * flickers back between the two.\n */\n settle: () => void;\n}\n\n/**\n * The optimistic verbs a row or bulk action receives on its context.\n */\nexport interface OptimisticRows<T> {\n /**\n * Take rows off the page now: they play their exit, the rows below close\n * the gap.\n */\n remove: (items: T | T[]) => OptimisticHandle;\n /**\n * Draw a row as `next` now (a new status chip, a new assignee). The row\n * flashes so the eye finds what changed.\n */\n patch: (item: T, next: T) => OptimisticHandle;\n}\n\ntype Entry<T> =\n | { kind: \"remove\"; leaving: boolean; settledAfter?: number }\n | { kind: \"patch\"; value: T; settledAfter?: number }\n /**\n * A removed row put back after the server already dropped it from the\n * page (an Undo after the settle): drawn at its old index until a reload\n * says where it really goes.\n */\n | { kind: \"restore\"; value: T; index: number; settledAfter?: number };\n\nexport interface UseOptimisticRowsOptions<T> {\n data: T[];\n rowKeys: string[];\n rowKey: (item: T) => string;\n /**\n * The id of the request whose rows are on screen.\n */\n loadedRequestId: number;\n /**\n * The id of the newest request sent.\n */\n lastRequestId: () => number;\n reload: () => void;\n /**\n * Static mode: the caller owns the rows, so a settled overlay goes at once.\n */\n isStatic: boolean;\n}\n\n/**\n * The layer between the rows the server sent and the rows on screen.\n *\n * An entry hides or redraws one row by key until it is rolled back or\n * settled. A settled entry waits for a request that left AFTER the settle,\n * because one that left before still carries the old row.\n */\nexport const useOptimisticRows = <T>(options: UseOptimisticRowsOptions<T>) => {\n const { data, rowKeys, loadedRequestId, lastRequestId, reload, isStatic } =\n options;\n const [allEntries, setEntries] = useState<ReadonlyMap<string, Entry<T>>>(\n () => new Map(),\n );\n // Rows flashed by a patch, cleared by `useRowMotion` once played.\n const flashRef = useRef(new Set<string>());\n\n // The newest answered request, for the writers below: an entry settled\n // before it is dead. Kept in a ref, written after render, because the\n // writers run from clicks long after the render that created them.\n const loadedRef = useRef(loadedRequestId);\n useEffect(() => {\n loadedRef.current = loadedRequestId;\n }, [loadedRequestId]);\n\n // The pending end-of-exit timers. Cleared on unmount: a table that is gone\n // must not take a state update from a row that was leaving it.\n const timers = useRef(new Set<ReturnType<typeof setTimeout>>());\n useEffect(() => {\n const pending = timers.current;\n return () => {\n for (const timer of pending) clearTimeout(timer);\n pending.clear();\n };\n }, []);\n\n /**\n * Every write starts by dropping the dead entries, so a rollback sees a\n * settled row as gone and puts it back by hand.\n */\n const update = useCallback(\n (fn: (next: Map<string, Entry<T>>) => void) =>\n setEntries((prev) => {\n const next = new Map(prev);\n for (const [key, entry] of next) {\n if (!isLive(entry, loadedRef.current)) next.delete(key);\n }\n fn(next);\n return next;\n }),\n [],\n );\n\n const handleFor = useCallback(\n (\n keys: string[],\n originals?: Map<string, { item: T; index: number }>,\n ): OptimisticHandle => ({\n rollback: () =>\n update((next) => {\n for (const key of keys) {\n const entry = next.get(key);\n const original = originals?.get(key);\n // Still hidden by this overlay: lifting it is enough. Gone (the\n // settle already let go, the server page no longer has it): put\n // it back by hand, so Undo is as instant as the click was.\n if (!entry && original) {\n next.set(key, {\n kind: \"restore\",\n value: original.item,\n index: original.index,\n });\n } else {\n next.delete(key);\n }\n }\n }),\n settle: () => {\n if (isStatic) {\n update((next) => {\n for (const key of keys) next.delete(key);\n });\n return;\n }\n const after = lastRequestId();\n update((next) => {\n for (const key of keys) {\n const entry = next.get(key);\n if (entry) next.set(key, { ...entry, settledAfter: after });\n }\n });\n reload();\n },\n }),\n [update, isStatic, lastRequestId, reload],\n );\n\n const remove = useCallback(\n (items: T | T[]): OptimisticHandle => {\n const list = Array.isArray(items) ? items : [items];\n const keys = list.map(options.rowKey);\n const originals = new Map<string, { item: T; index: number }>();\n list.forEach((item, i) =>\n originals.set(keys[i], { item, index: rowKeys.indexOf(keys[i]) }),\n );\n update((next) => {\n for (const key of keys)\n next.set(key, { kind: \"remove\", leaving: true });\n });\n const timer = setTimeout(() => {\n timers.current.delete(timer);\n update((next) => {\n for (const key of keys) {\n const entry = next.get(key);\n if (entry?.kind === \"remove\") {\n next.set(key, { ...entry, leaving: false });\n }\n }\n });\n }, LEAVE_MS);\n timers.current.add(timer);\n return handleFor(keys, originals);\n },\n [update, handleFor, options.rowKey, rowKeys],\n );\n\n const patch = useCallback(\n (item: T, value: T): OptimisticHandle => {\n const key = options.rowKey(item);\n flashRef.current.add(key);\n update((next) => {\n next.set(key, { kind: \"patch\", value });\n });\n return handleFor([key]);\n },\n [update, handleFor, options.rowKey],\n );\n\n // A settled entry lets go once a request sent after the settle has\n // answered: the server's rows are the truth again. Derived here rather\n // than deleted by an effect, so no render shows the stale overlay.\n const view = useMemo(() => {\n const entries = new Map(\n [...allEntries].filter(([, entry]) => isLive(entry, loadedRequestId)),\n );\n if (entries.size === 0) {\n return { data, rowKeys, leaving: EMPTY };\n }\n const outData: T[] = [];\n const outKeys: string[] = [];\n const leaving = new Set<string>();\n data.forEach((item, index) => {\n const key = rowKeys[index];\n const entry = entries.get(key);\n if (entry?.kind === \"remove\") {\n if (!entry.leaving) return;\n leaving.add(key);\n }\n outData.push(entry?.kind === \"patch\" ? entry.value : item);\n outKeys.push(key);\n });\n // Restored rows the server page does not hold (yet), at their old index.\n const present = new Set(rowKeys);\n const restores = [...entries]\n .filter(([key, e]) => e.kind === \"restore\" && !present.has(key))\n .sort(([, a], [, b]) =>\n a.kind === \"restore\" && b.kind === \"restore\" ? a.index - b.index : 0,\n );\n for (const [key, entry] of restores) {\n if (entry.kind !== \"restore\") continue;\n const at = Math.max(0, Math.min(entry.index, outData.length));\n outData.splice(at, 0, entry.value);\n outKeys.splice(at, 0, key);\n }\n return { data: outData, rowKeys: outKeys, leaving };\n }, [data, rowKeys, allEntries, loadedRequestId]);\n\n const optimistic: OptimisticRows<T> = useMemo(\n () => ({ remove, patch }),\n [remove, patch],\n );\n\n return { ...view, flash: flashRef.current, optimistic };\n};\n\nconst EMPTY: ReadonlySet<string> = new Set();\n\n/**\n * Whether an entry still overrides the server's row: never settled, or\n * settled and still waiting for a request sent after it to answer.\n */\nconst isLive = (\n entry: { settledAfter?: number },\n loadedRequestId: number,\n): boolean =>\n entry.settledAfter === undefined || loadedRequestId <= entry.settledAfter;\n"],"mappings":";;;;;;AAMA,MAAM,WAAW;;;;;;;;AAuEjB,MAAa,qBAAwB,YAAyC;CAC5E,MAAM,EAAE,MAAM,SAAS,iBAAiB,eAAe,QAAQ,aAC7D;CACF,MAAM,CAAC,YAAY,cAAc,+BACzB,IAAI,IAAI,CAChB;CAEA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iBAAiB,KAAA,KAAa,mBAAmB,MAAM"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
export interface UseRowMotionOptions {
|
|
3
|
+
body: RefObject<HTMLTableSectionElement | null>;
|
|
4
|
+
rowKeys: string[];
|
|
5
|
+
/**
|
|
6
|
+
* Rows playing their exit, still in the DOM.
|
|
7
|
+
*/
|
|
8
|
+
leaving: ReadonlySet<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Rows redrawn by an optimistic patch, flashed once and then forgotten.
|
|
11
|
+
*/
|
|
12
|
+
flash: Set<string>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Rows that move, arrive and leave like objects rather than redrawing.
|
|
16
|
+
*
|
|
17
|
+
* FLIP on the Web Animations API, no library: after each commit, every row
|
|
18
|
+
* that kept its key but changed its `offsetTop` is played from where it was
|
|
19
|
+
* to where it is; a new key fades and slides in with a tint; a leaving one
|
|
20
|
+
* fades out sideways; a patched one flashes.
|
|
21
|
+
*
|
|
22
|
+
* ⚠️ It stands still when most of the page changed at once (a new page, a
|
|
23
|
+
* filter, a sort): thirty rows sliding at the same moment is noise, not
|
|
24
|
+
* information. And it stands still under `prefers-reduced-motion`.
|
|
25
|
+
*/
|
|
26
|
+
export declare const useRowMotion: (options: UseRowMotionOptions) => void;
|
|
27
|
+
//# sourceMappingURL=useRowMotion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRowMotion.d.ts","sourceRoot":"","sources":["../../src/table/useRowMotion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAA2B,MAAM,OAAO,CAAC;AAEhE,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,SAAS,CAAC,uBAAuB,GAAG,IAAI,CAAC,CAAC;IAChD,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB;;OAEG;IACH,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7B;;OAEG;IACH,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACpB;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,YAAa,mBAAmB,SAiHxD,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef } from "react";
|
|
2
|
+
// src/table/useRowMotion.ts
|
|
3
|
+
/**
|
|
4
|
+
* Rows that move, arrive and leave like objects rather than redrawing.
|
|
5
|
+
*
|
|
6
|
+
* FLIP on the Web Animations API, no library: after each commit, every row
|
|
7
|
+
* that kept its key but changed its `offsetTop` is played from where it was
|
|
8
|
+
* to where it is; a new key fades and slides in with a tint; a leaving one
|
|
9
|
+
* fades out sideways; a patched one flashes.
|
|
10
|
+
*
|
|
11
|
+
* ⚠️ It stands still when most of the page changed at once (a new page, a
|
|
12
|
+
* filter, a sort): thirty rows sliding at the same moment is noise, not
|
|
13
|
+
* information. And it stands still under `prefers-reduced-motion`.
|
|
14
|
+
*/
|
|
15
|
+
const useRowMotion = (options) => {
|
|
16
|
+
const previous = useRef(void 0);
|
|
17
|
+
const exits = useRef(/* @__PURE__ */ new Map());
|
|
18
|
+
useLayoutEffect(() => {
|
|
19
|
+
const body = options.body.current;
|
|
20
|
+
if (!body) return;
|
|
21
|
+
const rows = /* @__PURE__ */ new Map();
|
|
22
|
+
for (const el of body.querySelectorAll(":scope > tr[data-row-key]")) rows.set(el.dataset.rowKey, el);
|
|
23
|
+
const now = /* @__PURE__ */ new Map();
|
|
24
|
+
for (const [key, el] of rows) now.set(key, el.offsetTop);
|
|
25
|
+
const before = previous.current;
|
|
26
|
+
previous.current = now;
|
|
27
|
+
if (!before) return;
|
|
28
|
+
if (typeof window === "undefined" || typeof body.animate !== "function" || window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) return;
|
|
29
|
+
let kept = 0;
|
|
30
|
+
for (const key of now.keys()) if (before.has(key)) kept++;
|
|
31
|
+
if (now.size > 0 && kept / Math.max(now.size, before.size) < .5) {
|
|
32
|
+
exits.current.clear();
|
|
33
|
+
options.flash.clear();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
for (const key of exits.current.keys()) if (!rows.has(key)) exits.current.delete(key);
|
|
37
|
+
const tint = tintColor(body);
|
|
38
|
+
for (const [key, el] of rows) {
|
|
39
|
+
if (options.leaving.has(key)) {
|
|
40
|
+
if (exits.current.has(key)) continue;
|
|
41
|
+
const exit = el.animate([{
|
|
42
|
+
opacity: 1,
|
|
43
|
+
transform: "translateX(0)"
|
|
44
|
+
}, {
|
|
45
|
+
opacity: 0,
|
|
46
|
+
transform: "translateX(-16px)"
|
|
47
|
+
}], {
|
|
48
|
+
duration: 180,
|
|
49
|
+
easing: "cubic-bezier(.4,0,1,1)",
|
|
50
|
+
fill: "forwards"
|
|
51
|
+
});
|
|
52
|
+
exits.current.set(key, exit);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const exit = exits.current.get(key);
|
|
56
|
+
if (exit) {
|
|
57
|
+
exits.current.delete(key);
|
|
58
|
+
exit.reverse();
|
|
59
|
+
exit.onfinish = () => exit.cancel();
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const from = before.get(key);
|
|
63
|
+
if (from === void 0) {
|
|
64
|
+
el.animate([
|
|
65
|
+
{
|
|
66
|
+
opacity: 0,
|
|
67
|
+
transform: "translateY(-6px)",
|
|
68
|
+
backgroundColor: tint
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
opacity: 1,
|
|
72
|
+
transform: "translateY(0)",
|
|
73
|
+
backgroundColor: tint,
|
|
74
|
+
offset: .4
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
opacity: 1,
|
|
78
|
+
transform: "translateY(0)",
|
|
79
|
+
backgroundColor: "transparent"
|
|
80
|
+
}
|
|
81
|
+
], {
|
|
82
|
+
duration: 900,
|
|
83
|
+
easing: "ease-out"
|
|
84
|
+
});
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const dy = from - now.get(key);
|
|
88
|
+
if (dy !== 0) el.animate([{ transform: `translateY(${dy}px)` }, { transform: "translateY(0)" }], {
|
|
89
|
+
duration: 260,
|
|
90
|
+
easing: "cubic-bezier(.2,.8,.2,1)"
|
|
91
|
+
});
|
|
92
|
+
if (options.flash.has(key)) {
|
|
93
|
+
options.flash.delete(key);
|
|
94
|
+
el.animate([{ backgroundColor: tint }, { backgroundColor: "transparent" }], {
|
|
95
|
+
duration: 900,
|
|
96
|
+
easing: "ease-out"
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* The theme's primary at low strength, read once per commit so it follows a
|
|
104
|
+
* light/dark switch. A keyframe cannot take `var()` everywhere yet.
|
|
105
|
+
*/
|
|
106
|
+
const tintColor = (el) => {
|
|
107
|
+
const primary = getComputedStyle(el).getPropertyValue("--primary").trim();
|
|
108
|
+
return primary ? `color-mix(in oklab, ${primary} 14%, transparent)` : "rgba(127,127,127,.12)";
|
|
109
|
+
};
|
|
110
|
+
export { useRowMotion };
|
|
111
|
+
|
|
112
|
+
//# sourceMappingURL=useRowMotion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRowMotion.js","names":[],"sources":["../../src/table/useRowMotion.ts"],"sourcesContent":["import { type RefObject, useLayoutEffect, useRef } from \"react\";\n\nexport interface UseRowMotionOptions {\n body: RefObject<HTMLTableSectionElement | null>;\n rowKeys: string[];\n /**\n * Rows playing their exit, still in the DOM.\n */\n leaving: ReadonlySet<string>;\n /**\n * Rows redrawn by an optimistic patch, flashed once and then forgotten.\n */\n flash: Set<string>;\n}\n\n/**\n * Rows that move, arrive and leave like objects rather than redrawing.\n *\n * FLIP on the Web Animations API, no library: after each commit, every row\n * that kept its key but changed its `offsetTop` is played from where it was\n * to where it is; a new key fades and slides in with a tint; a leaving one\n * fades out sideways; a patched one flashes.\n *\n * ⚠️ It stands still when most of the page changed at once (a new page, a\n * filter, a sort): thirty rows sliding at the same moment is noise, not\n * information. And it stands still under `prefers-reduced-motion`.\n */\nexport const useRowMotion = (options: UseRowMotionOptions) => {\n const previous = useRef<Map<string, number> | undefined>(undefined);\n // The exit each leaving row is playing, so a rollback can take it back.\n const exits = useRef(new Map<string, Animation>());\n\n useLayoutEffect(() => {\n const body = options.body.current;\n if (!body) return;\n const rows = new Map<string, HTMLElement>();\n for (const el of body.querySelectorAll<HTMLElement>(\n \":scope > tr[data-row-key]\",\n )) {\n rows.set(el.dataset.rowKey!, el);\n }\n const now = new Map<string, number>();\n for (const [key, el] of rows) now.set(key, el.offsetTop);\n\n const before = previous.current;\n previous.current = now;\n if (!before) return;\n if (\n typeof window === \"undefined\" ||\n // jsdom, and anything else without the Web Animations API.\n typeof body.animate !== \"function\" ||\n window.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches\n ) {\n return;\n }\n\n let kept = 0;\n for (const key of now.keys()) if (before.has(key)) kept++;\n // Most of the page is new: a page change, not an edit.\n if (now.size > 0 && kept / Math.max(now.size, before.size) < 0.5) {\n exits.current.clear();\n options.flash.clear();\n return;\n }\n\n for (const key of exits.current.keys()) {\n if (!rows.has(key)) exits.current.delete(key);\n }\n\n const tint = tintColor(body);\n for (const [key, el] of rows) {\n if (options.leaving.has(key)) {\n if (exits.current.has(key)) continue;\n const exit = el.animate(\n [\n { opacity: 1, transform: \"translateX(0)\" },\n { opacity: 0, transform: \"translateX(-16px)\" },\n ],\n { duration: 180, easing: \"cubic-bezier(.4,0,1,1)\", fill: \"forwards\" },\n );\n exits.current.set(key, exit);\n continue;\n }\n\n // Rolled back while leaving (the write failed, or Undo was quicker\n // than the exit): the held exit frame would keep it invisible.\n const exit = exits.current.get(key);\n if (exit) {\n exits.current.delete(key);\n exit.reverse();\n // Then let go of the held frame, which would otherwise pin the row's\n // opacity and transform under every later animation.\n exit.onfinish = () => exit.cancel();\n continue;\n }\n\n const from = before.get(key);\n if (from === undefined) {\n el.animate(\n [\n {\n opacity: 0,\n transform: \"translateY(-6px)\",\n backgroundColor: tint,\n },\n {\n opacity: 1,\n transform: \"translateY(0)\",\n backgroundColor: tint,\n offset: 0.4,\n },\n {\n opacity: 1,\n transform: \"translateY(0)\",\n backgroundColor: \"transparent\",\n },\n ],\n { duration: 900, easing: \"ease-out\" },\n );\n continue;\n }\n const dy = from - now.get(key)!;\n if (dy !== 0) {\n el.animate(\n [\n { transform: `translateY(${dy}px)` },\n { transform: \"translateY(0)\" },\n ],\n { duration: 260, easing: \"cubic-bezier(.2,.8,.2,1)\" },\n );\n }\n if (options.flash.has(key)) {\n options.flash.delete(key);\n el.animate(\n [{ backgroundColor: tint }, { backgroundColor: \"transparent\" }],\n { duration: 900, easing: \"ease-out\" },\n );\n }\n }\n });\n};\n\n/**\n * The theme's primary at low strength, read once per commit so it follows a\n * light/dark switch. A keyframe cannot take `var()` everywhere yet.\n */\nconst tintColor = (el: HTMLElement): string => {\n const primary = getComputedStyle(el).getPropertyValue(\"--primary\").trim();\n return primary\n ? `color-mix(in oklab, ${primary} 14%, transparent)`\n : \"rgba(127,127,127,.12)\";\n};\n"],"mappings":";;;;;;;;;;;;;;AA2BA,MAAa,gBAAgB,YAAiC;CAC5D,MAAM,WAAW,OAAwC,KAAA,CAAS;CAElE,MAAM,QAAQ,uBAAO,IAAI,IAAuB,CAAC;CAEjD,sBAAsB;EACpB,MAAM,OAAO,QAAQ,KAAK;EAC1B,IAAI,CAAC,MAAM;EACX,MAAM,uBAAO,IAAI,IAAyB;EAC1C,KAAK,MAAM,MAAM,KAAK,iBACpB,2BACF,GACE,KAAK,IAAI,GAAG,QAAQ,QAAS,EAAE;EAEjC,MAAM,sBAAM,IAAI,IAAoB;EACpC,KAAK,MAAM,CAAC,KAAK,OAAO,MAAM,IAAI,IAAI,KAAK,GAAG,SAAS;EAEvD,MAAM,SAAS,SAAS;EACxB,SAAS,UAAU;EACnB,IAAI,CAAC,QAAQ;EACb,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;IAAW,CACtC;IACA;GACF;GACA,MAAM,KAAK,OAAO,IAAI,IAAI,GAAG;GAC7B,IAAI,OAAO,GACT,GAAG,QACD,CACE,EAAE,WAAW,cAAc,GAAG,KAAK,GACnC,EAAE,WAAW,gBAAgB,CAC/B,GACA;IAAE,UAAU;IAAK,QAAQ;GAA2B,CACtD;GAEF,IAAI,QAAQ,MAAM,IAAI,GAAG,GAAG;IAC1B,QAAQ,MAAM,OAAO,GAAG;IACxB,GAAG,QACD,CAAC,EAAE,iBAAiB,KAAK,GAAG,EAAE,iBAAiB,cAAc,CAAC,GAC9D;KAAE,UAAU;KAAK,QAAQ;IAAW,CACtC;GACF;EACF;CACF,CAAC;AACH;;;;;AAMA,MAAM,aAAa,OAA4B;CAC7C,MAAM,UAAU,iBAAiB,EAAE,CAAC,CAAC,iBAAiB,WAAW,CAAC,CAAC,KAAK;CACxE,OAAO,UACH,uBAAuB,QAAQ,sBAC/B;AACN"}
|
|
@@ -38,3 +38,4 @@ shell. Load the stylesheet once, at the app's entry: `@alepha/ui/styles.css`.
|
|
|
38
38
|
|
|
39
39
|
- [`useDialog`](../../../alepha/docs/reference-react-hooks-usedialog.md) - Imperative dialog API. Returns an object with:
|
|
40
40
|
- [`useIsMobile`](../../../alepha/docs/reference-react-hooks-useismobile.md) - The shadcn version this started from seeds `undefined` and fills it in from
|
|
41
|
+
- [`useUndoable`](../../../alepha/docs/reference-react-hooks-useundoable.md) - Optimistic writes with an Undo toast.
|
|
@@ -28,7 +28,7 @@ bugfixes arrive through normal dependency updates.
|
|
|
28
28
|
|
|
29
29
|
## Import paths
|
|
30
30
|
|
|
31
|
-
The package is
|
|
31
|
+
The package is nineteen modules, one subpath each. The primitives are the package
|
|
32
32
|
root; everything heavier is a subpath of its own, so an app loads only what it
|
|
33
33
|
renders:
|
|
34
34
|
|
|
@@ -64,6 +64,7 @@ the module map and that `@alepha/ui` (the root) imports no other module.
|
|
|
64
64
|
| `@alepha/ui/auth` | `AuthRouter` and its pages, `TurnstileWidget` |
|
|
65
65
|
| `@alepha/ui/account` | `AccountRouter`, `$pageAccount`, and the account pages |
|
|
66
66
|
| `@alepha/ui/admin` | `AdminRouter`, `$pageAdmin`, the admin pages and `AdminAnalytics` |
|
|
67
|
+
| `@alepha/ui/swagger` | `$uiSwagger`, the API explorer page over the app's OpenAPI document, and its parts. See the section below |
|
|
67
68
|
| `@alepha/ui/chart` | The recharts wrapper (`ChartContainer` and its parts). Opt-in |
|
|
68
69
|
| `@alepha/ui/command` | The command palette on Base UI's `Autocomplete` (`Command`, `CommandDialog`), ranked by cmdk's scorer. Opt-in |
|
|
69
70
|
| `@alepha/ui/calendar` | The react-day-picker wrapper (`Calendar`). Opt-in |
|
|
@@ -264,6 +265,57 @@ place anything, and node width comes from a generated per-character width table
|
|
|
264
265
|
measured against Inter at one size; inheriting the surrounding face would make
|
|
265
266
|
text and box disagree, differently on every surface.
|
|
266
267
|
|
|
268
|
+
## API explorer
|
|
269
|
+
|
|
270
|
+
`alepha/server/swagger` serves the OpenAPI document and nothing else
|
|
271
|
+
(`$swagger`, at `/docs/json`). `@alepha/ui/swagger` is the viewer:
|
|
272
|
+
|
|
273
|
+
```ts
|
|
274
|
+
import { $uiSwagger } from "@alepha/ui/swagger";
|
|
275
|
+
import { $swagger } from "alepha/server/swagger";
|
|
276
|
+
|
|
277
|
+
class App {
|
|
278
|
+
openapi = $swagger({ info: { title: "Shop API", version: "1.0.0" } });
|
|
279
|
+
docs = $uiSwagger();
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
`$uiSwagger()` mounts a page at `/docs` reading `/docs/json` (`path`, `spec`,
|
|
284
|
+
`title`, `name`, `signIn` and `use` change that). The page is its own lazy
|
|
285
|
+
chunk, so an app pays for it only when someone opens it. It shows:
|
|
286
|
+
|
|
287
|
+
- the operations by tag, with a search over method, path, summary and action
|
|
288
|
+
name, an operation linkable by its hash (`/docs#createOrder`);
|
|
289
|
+
- each operation in full: parameters, request body, responses and a tree of
|
|
290
|
+
their schemas, plus what Alepha declared about it from the `x-alepha-*`
|
|
291
|
+
extensions (the action, the roles and permissions it requires, its
|
|
292
|
+
middlewares, declared errors, timeout);
|
|
293
|
+
- a **Try it** form built from the schemas with the `Control` components: a
|
|
294
|
+
field per parameter, the body field by field or as raw JSON, a file input
|
|
295
|
+
per binary part of a multipart body. The response shows its status, time,
|
|
296
|
+
size, headers and body, and a streamed body (server-sent events, a chunked
|
|
297
|
+
download) as it arrives;
|
|
298
|
+
- whether the viewer may call each gated operation: sign in first, allowed,
|
|
299
|
+
or not allowed, read from the signed-in user's action registry (the answer
|
|
300
|
+
`useAuth().has()` gives).
|
|
301
|
+
|
|
302
|
+
Requests go out as the viewer: same-origin, the browser sends the session
|
|
303
|
+
cookie and the server turns it into the `Authorization` it checks, with no
|
|
304
|
+
token to paste. The **Credentials** panel takes a bearer token or API key to
|
|
305
|
+
send instead, for an app without sign-in or to call as another principal; it
|
|
306
|
+
is kept in memory until the page reloads.
|
|
307
|
+
|
|
308
|
+
The document is read in the browser, never by a page loader: on a Worker, a
|
|
309
|
+
server render fetching its own origin is a self-subrequest, which fails. On
|
|
310
|
+
Cloudflare with `run_worker_first`, list `/docs/json` so the request reaches
|
|
311
|
+
the worker.
|
|
312
|
+
|
|
313
|
+
Guard the page with `use: [$secure({ roles: ["admin"] })]` when only the
|
|
314
|
+
team should see it, and remember that the document is a route of its own:
|
|
315
|
+
`$swagger` does not hide it. The components (`SwaggerExplorer`,
|
|
316
|
+
`SwaggerOperationView`, `SwaggerTryIt`, `OpenApiSpec`, ...) are exported for
|
|
317
|
+
an app that lays the explorer out itself.
|
|
318
|
+
|
|
267
319
|
## Command palette
|
|
268
320
|
|
|
269
321
|
`@alepha/ui/command` is Base UI's `Autocomplete`, rendered inline: a search
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
slug: "packages-alepha-ui-swagger"
|
|
3
|
+
title: "@alepha/ui - Swagger"
|
|
4
|
+
summary: "The API explorer."
|
|
5
|
+
package: "@alepha/ui"
|
|
6
|
+
section: "packages"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# @alepha/ui - Swagger
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @alepha/ui
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Overview
|
|
18
|
+
|
|
19
|
+
The API explorer.
|
|
20
|
+
|
|
21
|
+
`$uiSwagger` mounts a page that reads the app's OpenAPI document (served by
|
|
22
|
+
`$swagger` from `alepha/server/swagger`) and renders it with `@alepha/ui`:
|
|
23
|
+
operations by tag with a search, each in full with its schemas and the
|
|
24
|
+
`x-alepha-*` metadata Alepha adds. The components are exported too, for an
|
|
25
|
+
app that lays the explorer out itself.
|
|
26
|
+
|
|
27
|
+
## API Reference
|
|
28
|
+
|
|
29
|
+
### Primitives
|
|
30
|
+
|
|
31
|
+
- [`$uiSwagger`](../../../alepha/docs/reference-primitives-$uiswagger.md) - An API explorer page, reading the app's OpenAPI document.
|
|
32
|
+
|
|
33
|
+
### React Hooks
|
|
34
|
+
|
|
35
|
+
- [`useSwaggerAccess`](../../../alepha/docs/reference-react-hooks-useswaggeraccess.md) - Answers `SwaggerAccess` for each operation, against the current user.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alepha/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.0",
|
|
4
4
|
"description": "Shared Base UI and Tailwind components for Alepha apps. Edited directly; bugfixes propagate via normal dep updates.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"alepha",
|
|
@@ -95,6 +95,10 @@
|
|
|
95
95
|
"types": "./dist/resizable/index.d.ts",
|
|
96
96
|
"default": "./dist/resizable/index.js"
|
|
97
97
|
},
|
|
98
|
+
"./swagger": {
|
|
99
|
+
"types": "./dist/swagger/index.d.ts",
|
|
100
|
+
"default": "./dist/swagger/index.js"
|
|
101
|
+
},
|
|
98
102
|
"./i18n/fr": {
|
|
99
103
|
"types": "./dist/i18n/fr/index.d.ts",
|
|
100
104
|
"default": "./dist/i18n/fr/index.js"
|
|
@@ -172,6 +176,10 @@
|
|
|
172
176
|
"types": "./dist/resizable/index.d.ts",
|
|
173
177
|
"default": "./dist/resizable/index.js"
|
|
174
178
|
},
|
|
179
|
+
"./swagger": {
|
|
180
|
+
"types": "./dist/swagger/index.d.ts",
|
|
181
|
+
"default": "./dist/swagger/index.js"
|
|
182
|
+
},
|
|
175
183
|
"./i18n/fr": {
|
|
176
184
|
"types": "./dist/i18n/fr/index.d.ts",
|
|
177
185
|
"default": "./dist/i18n/fr/index.js"
|
|
@@ -214,7 +222,7 @@
|
|
|
214
222
|
"@types/bun": "^1.4.4",
|
|
215
223
|
"@types/node": "^26.6.6",
|
|
216
224
|
"@types/react": "^19.3.0",
|
|
217
|
-
"alepha": "0.
|
|
225
|
+
"alepha": "0.36.0",
|
|
218
226
|
"react": "^19.3.1",
|
|
219
227
|
"react-dom": "^19.3.1",
|
|
220
228
|
"recharts": "^3.10.1",
|
|
@@ -222,7 +230,7 @@
|
|
|
222
230
|
"typescript": "^7.0.2"
|
|
223
231
|
},
|
|
224
232
|
"peerDependencies": {
|
|
225
|
-
"alepha": "^0.
|
|
233
|
+
"alepha": "^0.36.0",
|
|
226
234
|
"react": "^19.3.0",
|
|
227
235
|
"react-dom": "^19.3.0",
|
|
228
236
|
"recharts": "^3",
|