@alepha/ui 0.39.0 → 0.40.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 +4 -2
- package/dist/admin/AdminJobExecutionSheet.d.ts.map +1 -1
- package/dist/admin/AdminJobExecutionSheet.js +7 -0
- package/dist/admin/AdminJobExecutionSheet.js.map +1 -1
- package/dist/admin/analytics/RequestDialog.js +1 -1
- package/dist/admin/analytics/RequestDialog.js.map +1 -1
- package/dist/ai/AiChat.d.ts +6 -3
- package/dist/ai/AiChat.d.ts.map +1 -1
- package/dist/ai/AiChat.js +34 -5
- package/dist/ai/AiChat.js.map +1 -1
- package/dist/ai/AiChatConfirmCard.d.ts.map +1 -1
- package/dist/ai/AiChatConfirmCard.js +5 -1
- package/dist/ai/AiChatConfirmCard.js.map +1 -1
- package/dist/ai/AiChatFloat.d.ts +14 -0
- package/dist/ai/AiChatFloat.d.ts.map +1 -0
- package/dist/ai/AiChatFloat.js +30 -0
- package/dist/ai/AiChatFloat.js.map +1 -0
- package/dist/ai/AiChatMessage.js +2 -2
- package/dist/ai/AiChatMessage.js.map +1 -1
- package/dist/ai/AiChatPanel.d.ts +19 -0
- package/dist/ai/AiChatPanel.d.ts.map +1 -1
- package/dist/ai/AiChatPanel.js +65 -19
- package/dist/ai/AiChatPanel.js.map +1 -1
- package/dist/ai/AiChatToolStepDetails.d.ts +14 -0
- package/dist/ai/AiChatToolStepDetails.d.ts.map +1 -0
- package/dist/ai/AiChatToolStepDetails.js +34 -0
- package/dist/ai/AiChatToolStepDetails.js.map +1 -0
- package/dist/ai/AiChatToolTrace.d.ts +50 -0
- package/dist/ai/AiChatToolTrace.d.ts.map +1 -0
- package/dist/ai/AiChatToolTrace.js +91 -0
- package/dist/ai/AiChatToolTrace.js.map +1 -0
- package/dist/ai/index.d.ts +4 -2
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +3 -1
- package/dist/core/Button.d.ts.map +1 -1
- package/dist/core/Button.js +17 -1
- package/dist/core/Button.js.map +1 -1
- package/dist/core/Dialog.d.ts.map +1 -1
- package/dist/core/Dialog.js +1 -1
- package/dist/core/Dialog.js.map +1 -1
- package/dist/core/TimeAgo.d.ts +3 -4
- package/dist/core/TimeAgo.d.ts.map +1 -1
- package/dist/core/TimeAgo.js +3 -4
- package/dist/core/TimeAgo.js.map +1 -1
- package/dist/i18n/en/index.d.ts +22 -0
- package/dist/i18n/en/index.d.ts.map +1 -0
- package/dist/i18n/en/index.js +1 -0
- package/dist/i18n/en/uiEn.d.ts +37 -0
- package/dist/i18n/en/uiEn.d.ts.map +1 -0
- package/dist/i18n/en/uiEn.js +1468 -0
- package/dist/i18n/en/uiEn.js.map +1 -0
- package/dist/i18n/fr/uiFr.d.ts +3 -2
- package/dist/i18n/fr/uiFr.d.ts.map +1 -1
- package/dist/i18n/fr/uiFr.js +7 -2
- package/dist/i18n/fr/uiFr.js.map +1 -1
- package/dist/markdown/MarkdownView.d.ts +14 -0
- package/dist/markdown/MarkdownView.d.ts.map +1 -1
- package/dist/markdown/MarkdownView.js +16 -3
- package/dist/markdown/MarkdownView.js.map +1 -1
- package/dist/markdown/highlightLines.d.ts +27 -0
- package/dist/markdown/highlightLines.d.ts.map +1 -0
- package/dist/markdown/highlightLines.js +91 -0
- package/dist/markdown/highlightLines.js.map +1 -0
- package/dist/markdown/index.d.ts +5 -2
- package/dist/markdown/index.d.ts.map +1 -1
- package/dist/markdown/index.js +2 -1
- package/dist/shell/ButtonInbox.d.ts +8 -0
- package/dist/shell/ButtonInbox.d.ts.map +1 -1
- package/dist/shell/ButtonInbox.js +3 -1
- package/dist/shell/ButtonInbox.js.map +1 -1
- package/dist/shell/PlateLayout.d.ts.map +1 -1
- package/dist/shell/PlateLayout.js +2 -2
- package/dist/shell/PlateLayout.js.map +1 -1
- package/dist/sortable/index.d.ts +17 -0
- package/dist/sortable/index.d.ts.map +1 -0
- package/dist/sortable/index.js +4 -0
- package/dist/sortable/useSortableItem.d.ts +32 -0
- package/dist/sortable/useSortableItem.d.ts.map +1 -0
- package/dist/sortable/useSortableItem.js +35 -0
- package/dist/sortable/useSortableItem.js.map +1 -0
- package/dist/sortable/useSortableList.d.ts +85 -0
- package/dist/sortable/useSortableList.d.ts.map +1 -0
- package/dist/sortable/useSortableList.js +125 -0
- package/dist/sortable/useSortableList.js.map +1 -0
- package/dist/table/DataTable.d.ts.map +1 -1
- package/dist/table/DataTable.js +9 -6
- package/dist/table/DataTable.js.map +1 -1
- package/dist/table/DataTableRowActionGroupItem.d.ts +23 -0
- package/dist/table/DataTableRowActionGroupItem.d.ts.map +1 -0
- package/dist/table/DataTableRowActionGroupItem.js +38 -0
- package/dist/table/DataTableRowActionGroupItem.js.map +1 -0
- package/dist/table/DataTableRowActionItem.d.ts.map +1 -1
- package/dist/table/DataTableRowActionItem.js +15 -2
- package/dist/table/DataTableRowActionItem.js.map +1 -1
- package/dist/table/DataTableRowActionsInline.d.ts.map +1 -1
- package/dist/table/DataTableRowActionsInline.js +2 -1
- package/dist/table/DataTableRowActionsInline.js.map +1 -1
- package/dist/table/DataTableRowActionsMenu.d.ts +3 -2
- package/dist/table/DataTableRowActionsMenu.d.ts.map +1 -1
- package/dist/table/DataTableRowActionsMenu.js +12 -14
- package/dist/table/DataTableRowActionsMenu.js.map +1 -1
- package/dist/table/dataTableBaseProps.d.ts +16 -2
- package/dist/table/dataTableBaseProps.d.ts.map +1 -1
- package/dist/table/dataTablePersistence.d.ts +53 -11
- package/dist/table/dataTablePersistence.d.ts.map +1 -1
- package/dist/table/dataTablePersistence.js +66 -29
- package/dist/table/dataTablePersistence.js.map +1 -1
- package/dist/table/dataTableTypes.d.ts +20 -3
- package/dist/table/dataTableTypes.d.ts.map +1 -1
- package/dist/table/index.d.ts +8 -1
- package/dist/table/index.d.ts.map +1 -1
- package/dist/table/index.js +2 -1
- package/dist/table/useDataTableColumns.d.ts.map +1 -1
- package/dist/table/useDataTableColumns.js +4 -4
- package/dist/table/useDataTableColumns.js.map +1 -1
- package/dist/table/useDataTableData.d.ts.map +1 -1
- package/dist/table/useDataTableData.js +3 -3
- package/dist/table/useDataTableData.js.map +1 -1
- package/dist/table/useDataTableFilterForm.d.ts.map +1 -1
- package/dist/table/useDataTableFilterForm.js +6 -2
- package/dist/table/useDataTableFilterForm.js.map +1 -1
- package/dist/table/useDataTableFilterVisibility.d.ts +5 -0
- package/dist/table/useDataTableFilterVisibility.d.ts.map +1 -1
- package/dist/table/useDataTableFilterVisibility.js +16 -8
- package/dist/table/useDataTableFilterVisibility.js.map +1 -1
- package/dist/table/useDataTableRefresh.d.ts.map +1 -1
- package/dist/table/useDataTableRefresh.js +3 -2
- package/dist/table/useDataTableRefresh.js.map +1 -1
- package/dist/table/useDataTableSummary.d.ts +5 -0
- package/dist/table/useDataTableSummary.d.ts.map +1 -1
- package/dist/table/useDataTableSummary.js +6 -6
- package/dist/table/useDataTableSummary.js.map +1 -1
- package/docs/packages-alepha-ui-ai.md +3 -3
- package/docs/packages-alepha-ui-i18n-en.md +35 -0
- package/docs/packages-alepha-ui-markdown.md +3 -1
- package/docs/packages-alepha-ui-overview.md +4 -2
- package/docs/packages-alepha-ui-sortable.md +34 -0
- package/docs/packages-alepha-ui-table.md +7 -1
- package/package.json +21 -3
- package/src/admin/AdminJobExecutionSheet.tsx +9 -0
- package/src/admin/analytics/RequestDialog.tsx +1 -1
- package/src/ai/AiChat.tsx +44 -6
- package/src/ai/AiChatConfirmCard.tsx +7 -1
- package/src/ai/AiChatFloat.tsx +46 -0
- package/src/ai/AiChatMessage.tsx +2 -2
- package/src/ai/AiChatPanel.tsx +154 -47
- package/src/ai/AiChatToolStepDetails.tsx +42 -0
- package/src/ai/AiChatToolTrace.tsx +167 -0
- package/src/ai/__tests__/AiChat.browser.spec.tsx +270 -2
- package/src/ai/index.ts +4 -2
- package/src/core/Button.tsx +26 -1
- package/src/core/Dialog.tsx +6 -2
- package/src/core/TimeAgo.tsx +3 -4
- package/src/core/__tests__/Button.browser.spec.tsx +57 -0
- package/src/i18n/en/__tests__/uiEn.spec.ts +110 -0
- package/src/i18n/en/index.ts +22 -0
- package/src/i18n/en/uiEn.ts +1647 -0
- package/src/i18n/fr/uiFr.ts +7 -2
- package/src/markdown/MarkdownView.tsx +30 -1
- package/src/markdown/__tests__/highlightLines.spec.ts +45 -0
- package/src/markdown/highlightLines.ts +120 -0
- package/src/markdown/index.ts +14 -2
- package/src/shell/ButtonInbox.tsx +11 -1
- package/src/shell/PlateLayout.tsx +18 -9
- package/src/shell/__tests__/ButtonInbox.browser.spec.tsx +40 -0
- package/src/shell/__tests__/PlateLayout.browser.spec.tsx +19 -2
- package/src/sortable/__tests__/useSortableList.browser.spec.tsx +157 -0
- package/src/sortable/index.ts +22 -0
- package/src/sortable/useSortableItem.ts +65 -0
- package/src/sortable/useSortableList.ts +231 -0
- package/src/table/DataTable.tsx +8 -5
- package/src/table/DataTableRowActionGroupItem.tsx +75 -0
- package/src/table/DataTableRowActionItem.tsx +6 -0
- package/src/table/DataTableRowActionsInline.tsx +3 -1
- package/src/table/DataTableRowActionsMenu.tsx +33 -49
- package/src/table/__tests__/DataTablePersistenceStorage.browser.spec.tsx +204 -0
- package/src/table/__tests__/DataTableRowActionGroup.browser.spec.tsx +118 -1
- package/src/table/dataTableBaseProps.ts +16 -2
- package/src/table/dataTablePersistence.ts +118 -32
- package/src/table/dataTableTypes.ts +20 -3
- package/src/table/index.ts +14 -1
- package/src/table/useDataTableColumns.ts +9 -4
- package/src/table/useDataTableData.ts +8 -3
- package/src/table/useDataTableFilterForm.ts +6 -2
- package/src/table/useDataTableFilterVisibility.ts +20 -7
- package/src/table/useDataTableRefresh.ts +4 -2
- package/src/table/useDataTableSummary.ts +25 -8
|
@@ -110,7 +110,7 @@ const useDataTableRefresh = (options) => {
|
|
|
110
110
|
useEffect(() => {
|
|
111
111
|
if (!filtersKey || !form || !props.filters) return;
|
|
112
112
|
const writeFilters = () => {
|
|
113
|
-
writePersisted(filtersKey, "filters", cleanFilterValues(form.currentValues ?? {}));
|
|
113
|
+
writePersisted(filtersKey, "filters", cleanFilterValues(form.currentValues ?? {}), props.persistenceStorage);
|
|
114
114
|
};
|
|
115
115
|
const unsubs = [alepha.events.on("form:changed", (event) => {
|
|
116
116
|
if (event.id !== form.id) return;
|
|
@@ -126,7 +126,8 @@ const useDataTableRefresh = (options) => {
|
|
|
126
126
|
alepha,
|
|
127
127
|
form,
|
|
128
128
|
props.filters,
|
|
129
|
-
filtersKey
|
|
129
|
+
filtersKey,
|
|
130
|
+
props.persistenceStorage
|
|
130
131
|
]);
|
|
131
132
|
useEffect(() => {
|
|
132
133
|
if (!props.pollMs) return;
|
|
@@ -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 /**\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":"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"}
|
|
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 on change, to `persistenceStorage` (localStorage\n // by default).\n useEffect(() => {\n if (!filtersKey || !form || !props.filters) return;\n const writeFilters = () => {\n writePersisted(\n filtersKey,\n \"filters\",\n cleanFilterValues(form.currentValues ?? {}),\n props.persistenceStorage,\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, props.persistenceStorage]);\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":"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"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Alepha, ZObject } from "alepha";
|
|
2
2
|
import type { FormModel } from "alepha/react/form";
|
|
3
|
+
import { type DataTablePersistenceStorage } from "./dataTablePersistence.ts";
|
|
3
4
|
import type { DataTableFilterFields, DataTableStatCard, DataTableSummary } from "./dataTableTypes.ts";
|
|
4
5
|
export interface UseDataTableSummaryOptions {
|
|
5
6
|
summary: DataTableSummary<DataTableFilterFields> | undefined;
|
|
@@ -8,6 +9,10 @@ export interface UseDataTableSummaryOptions {
|
|
|
8
9
|
* table stores nothing.
|
|
9
10
|
*/
|
|
10
11
|
persistenceKey: string | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Where `persistenceKey` is stored, `localStorage` when absent.
|
|
14
|
+
*/
|
|
15
|
+
persistenceStorage?: DataTablePersistenceStorage;
|
|
11
16
|
/**
|
|
12
17
|
* The table's reload counter. Every reload of the SET bumps it (a filter
|
|
13
18
|
* change, Refresh, `refreshSignal`, a poll, an action's `refresh()`), and a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDataTableSummary.d.ts","sourceRoot":"","sources":["../../src/table/useDataTableSummary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"useDataTableSummary.d.ts","sourceRoot":"","sources":["../../src/table/useDataTableSummary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAGnD,OAAO,EACL,KAAK,2BAA2B,EAGjC,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EACV,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,gBAAgB,CAAC,qBAAqB,CAAC,GAAG,SAAS,CAAC;IAC7D;;;OAGG;IACH,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC;;OAEG;IACH,kBAAkB,CAAC,EAAE,2BAA2B,CAAC;IACjD;;;;OAIG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,eAAO,MAAM,mBAAmB,YAAa,0BAA0B;;oBA4B5D,OAAO;sBAgBR,MAAM,GAAG,SAAS;;;CA0D3B,CAAC"}
|
|
@@ -7,8 +7,8 @@ import { useCallback, useEffect, useRef, useState } from "react";
|
|
|
7
7
|
* it shows, fetched with the table's filters when the caller gave a `fetch`.
|
|
8
8
|
*/
|
|
9
9
|
const useDataTableSummary = (options) => {
|
|
10
|
-
const { summary, persistenceKey, refreshKey, form, alepha } = options;
|
|
11
|
-
const [open, setOpenState] = useState(() => persistedSummaryOpen(persistenceKey));
|
|
10
|
+
const { summary, persistenceKey, persistenceStorage, refreshKey, form, alepha } = options;
|
|
11
|
+
const [open, setOpenState] = useState(() => persistedSummaryOpen(persistenceKey, persistenceStorage));
|
|
12
12
|
const [fetched, setFetched] = useState();
|
|
13
13
|
const [loading, setLoading] = useState(false);
|
|
14
14
|
const fetchRef = useRef(summary?.fetch);
|
|
@@ -18,8 +18,8 @@ const useDataTableSummary = (options) => {
|
|
|
18
18
|
const fetches = Boolean(summary?.fetch);
|
|
19
19
|
const setOpen = useCallback((next) => {
|
|
20
20
|
setOpenState(next);
|
|
21
|
-
if (persistenceKey) writePersisted(persistenceKey, "summaryOpen", next);
|
|
22
|
-
}, [persistenceKey]);
|
|
21
|
+
if (persistenceKey) writePersisted(persistenceKey, "summaryOpen", next, persistenceStorage);
|
|
22
|
+
}, [persistenceKey, persistenceStorage]);
|
|
23
23
|
/**
|
|
24
24
|
* Read the open state of another scope, and forget the cards of this one.
|
|
25
25
|
* Called by `DataTable` during the render where `persistenceKey` changes,
|
|
@@ -27,9 +27,9 @@ const useDataTableSummary = (options) => {
|
|
|
27
27
|
* must not sit under the name of the one just opened while it loads.
|
|
28
28
|
*/
|
|
29
29
|
const resetScope = useCallback((key) => {
|
|
30
|
-
setOpenState(persistedSummaryOpen(key));
|
|
30
|
+
setOpenState(persistedSummaryOpen(key, persistenceStorage));
|
|
31
31
|
setFetched(void 0);
|
|
32
|
-
}, []);
|
|
32
|
+
}, [persistenceStorage]);
|
|
33
33
|
useEffect(() => {
|
|
34
34
|
const fetcher = fetchRef.current;
|
|
35
35
|
if (!fetcher || !open) return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDataTableSummary.js","names":[],"sources":["../../src/table/useDataTableSummary.ts"],"sourcesContent":["import type { Alepha, ZObject } from \"alepha\";\nimport { ActionErrorPolicy } from \"alepha/react\";\nimport type { FormModel } from \"alepha/react/form\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\n\nimport {\n persistedSummaryOpen,\n writePersisted,\n} from \"./dataTablePersistence.ts\";\nimport type {\n DataTableFilterFields,\n DataTableStatCard,\n DataTableSummary,\n} from \"./dataTableTypes.ts\";\n\nexport interface UseDataTableSummaryOptions {\n summary: DataTableSummary<DataTableFilterFields> | undefined;\n /**\n * The key the panel's open state is stored under, or `undefined` when the\n * table stores nothing.\n */\n persistenceKey: string | undefined;\n /**\n * The table's reload counter. Every reload of the SET bumps it (a filter\n * change, Refresh, `refreshSignal`, a poll, an action's `refresh()`), and a\n * page or a sort does not, which is exactly when the figures change.\n */\n refreshKey: number;\n form: FormModel<ZObject> | undefined;\n alepha: Alepha;\n}\n\n/**\n * The state of `DataTable`'s summary panel: whether it is open, and the cards\n * it shows, fetched with the table's filters when the caller gave a `fetch`.\n */\nexport const useDataTableSummary = (options: UseDataTableSummaryOptions) => {\n const {
|
|
1
|
+
{"version":3,"file":"useDataTableSummary.js","names":[],"sources":["../../src/table/useDataTableSummary.ts"],"sourcesContent":["import type { Alepha, ZObject } from \"alepha\";\nimport { ActionErrorPolicy } from \"alepha/react\";\nimport type { FormModel } from \"alepha/react/form\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\n\nimport {\n type DataTablePersistenceStorage,\n persistedSummaryOpen,\n writePersisted,\n} from \"./dataTablePersistence.ts\";\nimport type {\n DataTableFilterFields,\n DataTableStatCard,\n DataTableSummary,\n} from \"./dataTableTypes.ts\";\n\nexport interface UseDataTableSummaryOptions {\n summary: DataTableSummary<DataTableFilterFields> | undefined;\n /**\n * The key the panel's open state is stored under, or `undefined` when the\n * table stores nothing.\n */\n persistenceKey: string | undefined;\n /**\n * Where `persistenceKey` is stored, `localStorage` when absent.\n */\n persistenceStorage?: DataTablePersistenceStorage;\n /**\n * The table's reload counter. Every reload of the SET bumps it (a filter\n * change, Refresh, `refreshSignal`, a poll, an action's `refresh()`), and a\n * page or a sort does not, which is exactly when the figures change.\n */\n refreshKey: number;\n form: FormModel<ZObject> | undefined;\n alepha: Alepha;\n}\n\n/**\n * The state of `DataTable`'s summary panel: whether it is open, and the cards\n * it shows, fetched with the table's filters when the caller gave a `fetch`.\n */\nexport const useDataTableSummary = (options: UseDataTableSummaryOptions) => {\n const {\n summary,\n persistenceKey,\n persistenceStorage,\n refreshKey,\n form,\n alepha,\n } = options;\n\n const [open, setOpenState] = useState(() =>\n persistedSummaryOpen(persistenceKey, persistenceStorage),\n );\n // `undefined` until the first fetch lands, which is what tells the panel\n // to draw its placeholder tiles rather than nothing.\n const [fetched, setFetched] = useState<DataTableStatCard[] | undefined>();\n const [loading, setLoading] = useState(false);\n\n // Held in a ref and out of the effect's dependencies, for the reason\n // `useDataTableData` gives for `fetch`: callers write it inline, so it is a\n // new function every render, and a dependency on it refetches forever.\n const fetchRef = useRef(summary?.fetch);\n fetchRef.current = summary?.fetch;\n const onErrorRef = useRef(summary?.onError);\n onErrorRef.current = summary?.onError;\n const fetches = Boolean(summary?.fetch);\n\n const setOpen = useCallback(\n (next: boolean) => {\n setOpenState(next);\n if (persistenceKey) {\n writePersisted(persistenceKey, \"summaryOpen\", next, persistenceStorage);\n }\n },\n [persistenceKey, persistenceStorage],\n );\n\n /**\n * Read the open state of another scope, and forget the cards of this one.\n * Called by `DataTable` during the render where `persistenceKey` changes,\n * like the rest of the scope's state: the figures of the project just left\n * must not sit under the name of the one just opened while it loads.\n */\n const resetScope = useCallback(\n (key: string | undefined) => {\n setOpenState(persistedSummaryOpen(key, persistenceStorage));\n setFetched(undefined);\n },\n [persistenceStorage],\n );\n\n useEffect(() => {\n const fetcher = fetchRef.current;\n // Collapsed, nothing is on screen to be right about: opening fetches.\n if (!fetcher || !open) return;\n const controller = new AbortController();\n setLoading(true);\n fetcher({\n // The values as the request leaves; the form moves on as the reader\n // types.\n filters: form ? { ...form.currentValues } : undefined,\n signal: controller.signal,\n })\n .then((cards) => {\n if (!controller.signal.aborted) setFetched(cards);\n })\n .catch((error: unknown) => {\n if (controller.signal.aborted) return;\n // The last cards stay up, like the table's rows. With none yet, the\n // placeholders go: tiles pulsing over a read that failed would say\n // it is still coming. No card is no panel, until a reload succeeds.\n setFetched((cards) => cards ?? []);\n // The table's own channel for a failed read, so a mounted\n // `ActionErrorToaster` reports it, unless the caller handles it: the\n // `onError` convention of `useQuery`, where the event still fires for\n // error reporting and the toaster skips it.\n const onError = onErrorRef.current;\n void alepha.events.emit(\"react:action:error\", {\n type: \"custom\",\n id: \"data-table:summary\",\n error: error as Error,\n handled: ActionErrorPolicy.isHandled(error, onError),\n });\n onError?.(error as Error);\n })\n .finally(() => {\n if (!controller.signal.aborted) setLoading(false);\n });\n // A newer load, a collapse or an unmount supersedes this one. Aborted\n // rather than ignored, so a fetcher that forwards the signal cancels the\n // request itself. `loading` is cleared here because the aborted load's\n // own `finally` leaves it alone, and a collapse starts no load to take\n // it over.\n return () => {\n controller.abort();\n setLoading(false);\n };\n }, [fetches, open, refreshKey, form, alepha]);\n\n const cards = summary?.fetch ? fetched : (summary?.cards ?? []);\n\n return { open, setOpen, resetScope, cards, loading };\n};\n"],"mappings":";;;;;;;;AAyCA,MAAa,uBAAuB,YAAwC;CAC1E,MAAM,EACJ,SACA,gBACA,oBACA,YACA,MACA,WACE;CAEJ,MAAM,CAAC,MAAM,gBAAgB,eAC3B,qBAAqB,gBAAgB,kBAAkB,CACzD;CAGA,MAAM,CAAC,SAAS,cAAc,SAA0C;CACxE,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAK5C,MAAM,WAAW,OAAO,SAAS,KAAK;CACtC,SAAS,UAAU,SAAS;CAC5B,MAAM,aAAa,OAAO,SAAS,OAAO;CAC1C,WAAW,UAAU,SAAS;CAC9B,MAAM,UAAU,QAAQ,SAAS,KAAK;CAEtC,MAAM,UAAU,aACb,SAAkB;EACjB,aAAa,IAAI;EACjB,IAAI,gBACF,eAAe,gBAAgB,eAAe,MAAM,kBAAkB;CAE1E,GACA,CAAC,gBAAgB,kBAAkB,CACrC;;;;;;;CAQA,MAAM,aAAa,aAChB,QAA4B;EAC3B,aAAa,qBAAqB,KAAK,kBAAkB,CAAC;EAC1D,WAAW,KAAA,CAAS;CACtB,GACA,CAAC,kBAAkB,CACrB;CAEA,gBAAgB;EACd,MAAM,UAAU,SAAS;EAEzB,IAAI,CAAC,WAAW,CAAC,MAAM;EACvB,MAAM,aAAa,IAAI,gBAAgB;EACvC,WAAW,IAAI;EACf,QAAQ;GAGN,SAAS,OAAO,EAAE,GAAG,KAAK,cAAc,IAAI,KAAA;GAC5C,QAAQ,WAAW;EACrB,CAAC,CAAC,CACC,MAAM,UAAU;GACf,IAAI,CAAC,WAAW,OAAO,SAAS,WAAW,KAAK;EAClD,CAAC,CAAC,CACD,OAAO,UAAmB;GACzB,IAAI,WAAW,OAAO,SAAS;GAI/B,YAAY,UAAU,SAAS,CAAC,CAAC;GAKjC,MAAM,UAAU,WAAW;GACtB,OAAO,OAAO,KAAK,sBAAsB;IAC5C,MAAM;IACN,IAAI;IACG;IACP,SAAS,kBAAkB,UAAU,OAAO,OAAO;GACrD,CAAC;GACD,UAAU,KAAc;EAC1B,CAAC,CAAC,CACD,cAAc;GACb,IAAI,CAAC,WAAW,OAAO,SAAS,WAAW,KAAK;EAClD,CAAC;EAMH,aAAa;GACX,WAAW,MAAM;GACjB,WAAW,KAAK;EAClB;CACF,GAAG;EAAC;EAAS;EAAM;EAAY;EAAM;CAAM,CAAC;CAI5C,OAAO;EAAE;EAAM;EAAS;EAAY,OAFtB,SAAS,QAAQ,UAAW,SAAS,SAAS,CAAC;EAElB;CAAQ;AACrD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
slug: "packages-alepha-ui-ai"
|
|
3
3
|
title: "@alepha/ui - Ai"
|
|
4
|
-
summary: "The in-app assistant on the client: a chat in a drawer
|
|
4
|
+
summary: "The in-app assistant on the client: a chat in a drawer, docked beside the page or floating over its corner, with streamed replies, history and a confirmation card per mutation, the headless `useAiC..."
|
|
5
5
|
package: "@alepha/ui"
|
|
6
6
|
section: "packages"
|
|
7
7
|
---
|
|
@@ -16,8 +16,8 @@ npm install @alepha/ui
|
|
|
16
16
|
|
|
17
17
|
## Overview
|
|
18
18
|
|
|
19
|
-
The in-app assistant on the client: a chat in a drawer
|
|
20
|
-
the page, with streamed replies, history and a confirmation card per
|
|
19
|
+
The in-app assistant on the client: a chat in a drawer, docked beside
|
|
20
|
+
the page or floating over its corner, with streamed replies, history and a confirmation card per
|
|
21
21
|
mutation, the headless `useAiChat`, and `useAiContext` for a page to
|
|
22
22
|
declare what it shows. Talks to `alepha/api/ai`.
|
|
23
23
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
slug: "packages-alepha-ui-i18n-en"
|
|
3
|
+
title: "@alepha/ui - I18n En"
|
|
4
|
+
summary: "The English catalogue for every key `@alepha/ui` asks for."
|
|
5
|
+
package: "@alepha/ui"
|
|
6
|
+
section: "packages"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# @alepha/ui - I18n En
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @alepha/ui
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Overview
|
|
18
|
+
|
|
19
|
+
The English catalogue for every key `@alepha/ui` asks for.
|
|
20
|
+
|
|
21
|
+
The components default to English already; this record is for an application
|
|
22
|
+
whose fallback language is not English, where a key missing from the `en`
|
|
23
|
+
catalogue would otherwise be read in the fallback language. A plain record
|
|
24
|
+
the application spreads into its own catalogue, and a subpath of its own so
|
|
25
|
+
that catalogue can load it lazily:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
en = $dictionary({
|
|
29
|
+
lazy: async () => {
|
|
30
|
+
const { uiEn } = await import("@alepha/ui/i18n/en");
|
|
31
|
+
return { default: { ...uiEn, "nav.home": "Home" } };
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
@@ -19,7 +19,9 @@ npm install @alepha/ui
|
|
|
19
19
|
Markdown rendered as prose, with diagrams.
|
|
20
20
|
|
|
21
21
|
`MarkdownView` renders GitHub-flavoured markdown with highlighted code, and
|
|
22
|
-
draws `flowchart` and `sequenceDiagram` fences as SVG. `
|
|
22
|
+
draws `flowchart` and `sequenceDiagram` fences as SVG. `highlightLines`
|
|
23
|
+
highlights a whole file line by line with the same grammars, for a code
|
|
24
|
+
view that numbers its lines. `diagramKind`,
|
|
23
25
|
`parseFlowchart` and `parseSequence` expose the parsers, so an editor can
|
|
24
26
|
validate a diagram before it is saved.
|
|
25
27
|
|
|
@@ -70,10 +70,12 @@ the module map and that `@alepha/ui` (the root) imports no other module.
|
|
|
70
70
|
| `@alepha/ui/calendar` | The react-day-picker wrapper (`Calendar`). Opt-in |
|
|
71
71
|
| `@alepha/ui/otp` | The input-otp wrapper (`InputOTP`). Opt-in |
|
|
72
72
|
| `@alepha/ui/resizable` | The react-resizable-panels wrapper. Opt-in |
|
|
73
|
+
| `@alepha/ui/sortable` | `useSortableList` and `useSortableItem`: a vertical list reordered by dragging or from the keyboard, on `@dnd-kit`. Opt-in |
|
|
74
|
+
| `@alepha/ui/i18n/en` | `uiEn`, the English catalogue, for an app whose fallback language is not English |
|
|
73
75
|
| `@alepha/ui/i18n/fr` | `uiFr`, the French catalogue for every key the package asks for |
|
|
74
76
|
|
|
75
|
-
The
|
|
76
|
-
react-day-picker, input-otp, react-resizable-panels) is loaded by the app
|
|
77
|
+
The six opt-in wrappers import only the root, so a heavy dependency (recharts,
|
|
78
|
+
react-day-picker, input-otp, react-resizable-panels, `@dnd-kit`) is loaded by the app
|
|
77
79
|
that imports its subpath and by nothing else.
|
|
78
80
|
|
|
79
81
|
> `useDialog()` throws without a `<DialogProvider>` above it, and toasts need a
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
slug: "packages-alepha-ui-sortable"
|
|
3
|
+
title: "@alepha/ui - Sortable"
|
|
4
|
+
summary: "Sortable lists, on `@dnd-kit`."
|
|
5
|
+
package: "@alepha/ui"
|
|
6
|
+
section: "packages"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# @alepha/ui - Sortable
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @alepha/ui
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Overview
|
|
18
|
+
|
|
19
|
+
Sortable lists, on `@dnd-kit`.
|
|
20
|
+
|
|
21
|
+
`useSortableList` holds a vertical list reordered by dragging (pointer or
|
|
22
|
+
touch) or from the keyboard: the order shown between a drop and the
|
|
23
|
+
server's answer, the drop index, a vertical-only modifier, and the keyboard
|
|
24
|
+
move (Space picks up, the arrows move, Space or Enter drops, Escape puts
|
|
25
|
+
back) with its screen-reader announcements. `useSortableItem` is one item
|
|
26
|
+
of it. The look and the save stay the app's. Opt-in: nothing else in
|
|
27
|
+
`@alepha/ui` imports it, so `@dnd-kit` loads only with it.
|
|
28
|
+
|
|
29
|
+
## API Reference
|
|
30
|
+
|
|
31
|
+
### React Hooks
|
|
32
|
+
|
|
33
|
+
- [`useSortableItem`](../../../alepha/docs/reference-react-hooks-usesortableitem.md) - One item of a `useSortableList`: the element both dragged and dropped
|
|
34
|
+
- [`useSortableList`](../../../alepha/docs/reference-react-hooks-usesortablelist.md) - A vertical list reordered by dragging or from the keyboard, on `@dnd-kit`
|
|
@@ -29,7 +29,13 @@ node beside them. A `help` node sits behind a `?` at the end of the
|
|
|
29
29
|
toolbar's icons. A page with views of one table is a `PlateLayout`, whose
|
|
30
30
|
folder tabs sit above it.
|
|
31
31
|
`DataTableFilterMenu`, `DataTableFilterDialog` and `DataTableBulkMenu`
|
|
32
|
-
are its parts, and `useTableSelection` its selection state.
|
|
32
|
+
are its parts, and `useTableSelection` its selection state.
|
|
33
|
+
`readPersisted` and `writePersisted` are where a table keeps what it
|
|
34
|
+
remembers under its `persistenceKey`, for a page control beside the table
|
|
35
|
+
(a grouping, a view) to be remembered the same way; they go to
|
|
36
|
+
`localStorage` unless a `DataTablePersistenceStorage` is passed, which is
|
|
37
|
+
what a table's `persistenceStorage` prop takes to keep its state elsewhere,
|
|
38
|
+
such as the user's preferences on a server. `PermissionMatrix` is the grid of
|
|
33
39
|
roles against permissions the admin and account kits draw.
|
|
34
40
|
|
|
35
41
|
## API Reference
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alepha/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.40.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,10 +95,18 @@
|
|
|
95
95
|
"types": "./dist/resizable/index.d.ts",
|
|
96
96
|
"default": "./dist/resizable/index.js"
|
|
97
97
|
},
|
|
98
|
+
"./sortable": {
|
|
99
|
+
"types": "./dist/sortable/index.d.ts",
|
|
100
|
+
"default": "./dist/sortable/index.js"
|
|
101
|
+
},
|
|
98
102
|
"./swagger": {
|
|
99
103
|
"types": "./dist/swagger/index.d.ts",
|
|
100
104
|
"default": "./dist/swagger/index.js"
|
|
101
105
|
},
|
|
106
|
+
"./i18n/en": {
|
|
107
|
+
"types": "./dist/i18n/en/index.d.ts",
|
|
108
|
+
"default": "./dist/i18n/en/index.js"
|
|
109
|
+
},
|
|
102
110
|
"./i18n/fr": {
|
|
103
111
|
"types": "./dist/i18n/fr/index.d.ts",
|
|
104
112
|
"default": "./dist/i18n/fr/index.js"
|
|
@@ -176,10 +184,18 @@
|
|
|
176
184
|
"types": "./dist/resizable/index.d.ts",
|
|
177
185
|
"default": "./dist/resizable/index.js"
|
|
178
186
|
},
|
|
187
|
+
"./sortable": {
|
|
188
|
+
"types": "./dist/sortable/index.d.ts",
|
|
189
|
+
"default": "./dist/sortable/index.js"
|
|
190
|
+
},
|
|
179
191
|
"./swagger": {
|
|
180
192
|
"types": "./dist/swagger/index.d.ts",
|
|
181
193
|
"default": "./dist/swagger/index.js"
|
|
182
194
|
},
|
|
195
|
+
"./i18n/en": {
|
|
196
|
+
"types": "./dist/i18n/en/index.d.ts",
|
|
197
|
+
"default": "./dist/i18n/en/index.js"
|
|
198
|
+
},
|
|
183
199
|
"./i18n/fr": {
|
|
184
200
|
"types": "./dist/i18n/fr/index.d.ts",
|
|
185
201
|
"default": "./dist/i18n/fr/index.js"
|
|
@@ -195,6 +211,8 @@
|
|
|
195
211
|
},
|
|
196
212
|
"dependencies": {
|
|
197
213
|
"@base-ui/react": "^1.9.0",
|
|
214
|
+
"@dnd-kit/core": "^6.3.1",
|
|
215
|
+
"@dnd-kit/utilities": "^3.2.2",
|
|
198
216
|
"@fontsource-variable/inter": "^5.3.0",
|
|
199
217
|
"@fontsource-variable/jetbrains-mono": "^5.3.0",
|
|
200
218
|
"class-variance-authority": "^0.7.1",
|
|
@@ -222,7 +240,7 @@
|
|
|
222
240
|
"@types/bun": "^1.4.4",
|
|
223
241
|
"@types/node": "^26.6.6",
|
|
224
242
|
"@types/react": "^19.3.0",
|
|
225
|
-
"alepha": "0.
|
|
243
|
+
"alepha": "0.40.0",
|
|
226
244
|
"react": "^19.3.1",
|
|
227
245
|
"react-dom": "^19.3.1",
|
|
228
246
|
"recharts": "^3.10.1",
|
|
@@ -230,7 +248,7 @@
|
|
|
230
248
|
"typescript": "^7.0.2"
|
|
231
249
|
},
|
|
232
250
|
"peerDependencies": {
|
|
233
|
-
"alepha": "^0.
|
|
251
|
+
"alepha": "^0.40.0",
|
|
234
252
|
"react": "^19.3.0",
|
|
235
253
|
"react-dom": "^19.3.0",
|
|
236
254
|
"recharts": "^3",
|
|
@@ -210,6 +210,15 @@ export const AdminJobExecutionSheet = (props: AdminJobExecutionSheetProps) => {
|
|
|
210
210
|
<AdminJobsPayloadBody payload={execution.payload} />
|
|
211
211
|
</section>
|
|
212
212
|
)}
|
|
213
|
+
|
|
214
|
+
{execution.result !== undefined && execution.result !== null && (
|
|
215
|
+
<section className="flex flex-col gap-2">
|
|
216
|
+
<h3 className="text-sm font-semibold">
|
|
217
|
+
{tr("admin.jobs.resultTitle", { default: "Result" })}
|
|
218
|
+
</h3>
|
|
219
|
+
<AdminJobsPayloadBody payload={execution.result} />
|
|
220
|
+
</section>
|
|
221
|
+
)}
|
|
213
222
|
</>
|
|
214
223
|
)}
|
|
215
224
|
</div>
|
|
@@ -48,7 +48,7 @@ export const RequestDialog = (props: RequestDialogProps) => {
|
|
|
48
48
|
if (!open) setCopied(false);
|
|
49
49
|
}}
|
|
50
50
|
>
|
|
51
|
-
<DialogContent className="flex max-h-[78vh] flex-col gap-3 sm:max-w-[560px]">
|
|
51
|
+
<DialogContent className="flex max-h-[78vh] flex-col gap-3 overflow-visible sm:max-w-[560px]">
|
|
52
52
|
<DialogHeader>
|
|
53
53
|
<DialogTitle>
|
|
54
54
|
{tr("admin.analytics.requestTitle", { default: "Request body" })}
|
package/src/ai/AiChat.tsx
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { useEffect, useState, useSyncExternalStore } from "react";
|
|
2
2
|
|
|
3
|
+
import { Dialog, DialogContent, DialogTitle } from "../core/Dialog.tsx";
|
|
3
4
|
import { Drawer, DrawerContent, DrawerTitle } from "../core/Drawer.tsx";
|
|
4
5
|
import { AiChatDock } from "./AiChatDock.tsx";
|
|
6
|
+
import { AiChatFloat } from "./AiChatFloat.tsx";
|
|
5
7
|
import { AiChatLauncher } from "./AiChatLauncher.tsx";
|
|
6
8
|
import { AiChatPanel, type AiChatViewProps } from "./AiChatPanel.tsx";
|
|
7
9
|
import { type UseAiChatOptions, useAiChat } from "./useAiChat.ts";
|
|
@@ -13,8 +15,10 @@ import { type UseAiChatOptions, useAiChat } from "./useAiChat.ts";
|
|
|
13
15
|
* (see `AiChatDock`), and folds into a pill.
|
|
14
16
|
* - `auto`: the dock from 1024px up, the drawer below, where a page has no
|
|
15
17
|
* width to give.
|
|
18
|
+
* - `floating`: a card over the page's bottom corner, the page under it
|
|
19
|
+
* still usable (see `AiChatFloat`), and folds into a pill.
|
|
16
20
|
*/
|
|
17
|
-
export type AiChatMode = "auto" | "dock" | "drawer";
|
|
21
|
+
export type AiChatMode = "auto" | "dock" | "drawer" | "floating";
|
|
18
22
|
|
|
19
23
|
export interface AiChatProps extends UseAiChatOptions, AiChatViewProps {
|
|
20
24
|
open: boolean;
|
|
@@ -45,12 +49,13 @@ const useWideScreen = () =>
|
|
|
45
49
|
);
|
|
46
50
|
|
|
47
51
|
/**
|
|
48
|
-
* The assistant: the conversation of `AiChatPanel`, in a drawer or a
|
|
52
|
+
* The assistant: the conversation of `AiChatPanel`, in a drawer, a dock or a
|
|
53
|
+
* floating card.
|
|
49
54
|
* It knows the page through `useAiContext()`, and runs `navigate` and
|
|
50
55
|
* `fillForm` for the model. The conversation lives here, so it survives a
|
|
51
56
|
* close, a minimize and a switch between drawer and dock.
|
|
52
57
|
*
|
|
53
|
-
* A docked chat minimizes into a pill (`AiChatLauncher`): it reports itself
|
|
58
|
+
* A docked or floating chat minimizes into a pill (`AiChatLauncher`): it reports itself
|
|
54
59
|
* closed through `onOpenChange(false)`, so the app's own button opens it
|
|
55
60
|
* again, and the pill does too.
|
|
56
61
|
*
|
|
@@ -85,15 +90,46 @@ export const AiChat = (props: AiChatProps) => {
|
|
|
85
90
|
}
|
|
86
91
|
}, [props.open]);
|
|
87
92
|
|
|
93
|
+
const [maximized, setMaximized] = useState(false);
|
|
94
|
+
|
|
88
95
|
const close = () => {
|
|
89
96
|
setMinimized(false);
|
|
97
|
+
setMaximized(false);
|
|
90
98
|
props.onOpenChange(false);
|
|
91
99
|
};
|
|
100
|
+
const toggleMaximized = () => setMaximized((value) => !value);
|
|
101
|
+
|
|
102
|
+
// Full screen, from the dock or the drawer: the panel in a dialog sized as
|
|
103
|
+
// an image lightbox maximizes (a 1rem gap from the screen's edges). Escape
|
|
104
|
+
// or the backdrop restores it, and the conversation stays where it was.
|
|
105
|
+
if (props.open && maximized) {
|
|
106
|
+
return (
|
|
107
|
+
<Dialog open onOpenChange={(open) => open || setMaximized(false)}>
|
|
108
|
+
<DialogContent
|
|
109
|
+
showCloseButton={false}
|
|
110
|
+
data-testid="ai-chat-fullscreen"
|
|
111
|
+
className="flex h-[calc(100dvh-2rem)] max-w-[calc(100vw-2rem)] flex-col gap-0 overflow-hidden p-0 sm:max-w-[calc(100vw-2rem)]"
|
|
112
|
+
>
|
|
113
|
+
<AiChatPanel
|
|
114
|
+
{...props}
|
|
115
|
+
chat={chat}
|
|
116
|
+
onClose={close}
|
|
117
|
+
onMaximize={toggleMaximized}
|
|
118
|
+
maximized
|
|
119
|
+
renderTitle={(title, className) => (
|
|
120
|
+
<DialogTitle className={className}>{title}</DialogTitle>
|
|
121
|
+
)}
|
|
122
|
+
/>
|
|
123
|
+
</DialogContent>
|
|
124
|
+
</Dialog>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
92
127
|
|
|
93
|
-
if (docked) {
|
|
128
|
+
if (docked || mode === "floating") {
|
|
129
|
+
const Container = docked ? AiChatDock : AiChatFloat;
|
|
94
130
|
if (props.open) {
|
|
95
131
|
return (
|
|
96
|
-
<
|
|
132
|
+
<Container>
|
|
97
133
|
<AiChatPanel
|
|
98
134
|
{...props}
|
|
99
135
|
chat={chat}
|
|
@@ -102,8 +138,9 @@ export const AiChat = (props: AiChatProps) => {
|
|
|
102
138
|
setMinimized(true);
|
|
103
139
|
props.onOpenChange(false);
|
|
104
140
|
}}
|
|
141
|
+
onMaximize={toggleMaximized}
|
|
105
142
|
/>
|
|
106
|
-
</
|
|
143
|
+
</Container>
|
|
107
144
|
);
|
|
108
145
|
}
|
|
109
146
|
return minimized ? (
|
|
@@ -130,6 +167,7 @@ export const AiChat = (props: AiChatProps) => {
|
|
|
130
167
|
{...props}
|
|
131
168
|
chat={chat}
|
|
132
169
|
onClose={close}
|
|
170
|
+
onMaximize={toggleMaximized}
|
|
133
171
|
renderTitle={(title, className) => (
|
|
134
172
|
<DrawerTitle className={className}>{title}</DrawerTitle>
|
|
135
173
|
)}
|
|
@@ -42,7 +42,13 @@ export const AiChatConfirmCard = (props: AiChatConfirmCardProps) => {
|
|
|
42
42
|
})}
|
|
43
43
|
</CardTitle>
|
|
44
44
|
</CardHeader>
|
|
45
|
-
|
|
45
|
+
{/* Capped and scrolling on its own: a long input drawn at full height
|
|
46
|
+
pushes the conversation away, and the buttons with it. The footer
|
|
47
|
+
sits outside, so Approve and Deny always show. */}
|
|
48
|
+
<CardContent
|
|
49
|
+
className="max-h-80 overflow-y-auto"
|
|
50
|
+
data-testid="ai-chat-confirm-body"
|
|
51
|
+
>
|
|
46
52
|
<AiChatConfirmFields input={props.pending.input} />
|
|
47
53
|
</CardContent>
|
|
48
54
|
<CardFooter className="gap-2">
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useI18n } from "alepha/react/i18n";
|
|
2
|
+
import { type ReactNode, useEffect, useState } from "react";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
|
|
5
|
+
import { cn } from "../core/utils.ts";
|
|
6
|
+
|
|
7
|
+
export interface AiChatFloatProps {
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The assistant as a card over the page's bottom corner, the way a support
|
|
14
|
+
* chat sits: rounded, shadowed, a fixed size that never outgrows the screen.
|
|
15
|
+
* No backdrop, no focus trap and nothing that closes it on a click
|
|
16
|
+
* elsewhere, so the page under it stays usable while the conversation goes
|
|
17
|
+
* on. Rendered into `document.body`, above the page's own layers.
|
|
18
|
+
*/
|
|
19
|
+
export const AiChatFloat = (props: AiChatFloatProps) => {
|
|
20
|
+
const { tr } = useI18n();
|
|
21
|
+
const [target, setTarget] = useState<Element>();
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
// After the commit: the server has no document.
|
|
25
|
+
// oxlint-disable-next-line react/set-state-in-effect -- the portal target only exists in the browser
|
|
26
|
+
setTarget(document.body);
|
|
27
|
+
}, []);
|
|
28
|
+
|
|
29
|
+
if (!target) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return createPortal(
|
|
34
|
+
<section
|
|
35
|
+
data-testid="ai-chat-float"
|
|
36
|
+
aria-label={tr("ai.chat.title", { default: "Assistant" })}
|
|
37
|
+
className={cn(
|
|
38
|
+
"bg-card text-card-foreground fixed end-4 bottom-4 z-40 flex h-[min(44rem,calc(100dvh-2rem))] w-[min(30rem,calc(100vw-2rem))] flex-col overflow-hidden rounded-2xl border text-sm shadow-2xl",
|
|
39
|
+
props.className,
|
|
40
|
+
)}
|
|
41
|
+
>
|
|
42
|
+
{props.children}
|
|
43
|
+
</section>,
|
|
44
|
+
target,
|
|
45
|
+
);
|
|
46
|
+
};
|
package/src/ai/AiChatMessage.tsx
CHANGED
|
@@ -78,7 +78,7 @@ export const AiChatMessage = (props: AiChatMessageProps) => {
|
|
|
78
78
|
return (
|
|
79
79
|
<div
|
|
80
80
|
data-testid="ai-chat-user"
|
|
81
|
-
className="bg-muted ms-10 self-end rounded-2xl rounded-ee-md px-3.5 py-2 text-sm leading-relaxed whitespace-pre-wrap"
|
|
81
|
+
className="bg-muted ms-10 max-w-[calc(100%-2.5rem)] min-w-0 self-end rounded-2xl rounded-ee-md px-3.5 py-2 text-sm leading-relaxed break-words whitespace-pre-wrap"
|
|
82
82
|
>
|
|
83
83
|
{item.content}
|
|
84
84
|
</div>
|
|
@@ -88,7 +88,7 @@ export const AiChatMessage = (props: AiChatMessageProps) => {
|
|
|
88
88
|
return (
|
|
89
89
|
<div
|
|
90
90
|
data-testid="ai-chat-assistant"
|
|
91
|
-
className="me-4 self-start text-sm leading-relaxed"
|
|
91
|
+
className="me-4 max-w-[calc(100%-1rem)] min-w-0 self-start text-sm leading-relaxed break-words"
|
|
92
92
|
>
|
|
93
93
|
{item.content ? (
|
|
94
94
|
<MarkdownView content={item.content} renderLink={props.renderLink} />
|