@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTableRowActionItem.d.ts","sourceRoot":"","sources":["../../src/table/DataTableRowActionItem.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvE,MAAM,WAAW,2BAA2B,CAAC,CAAC;IAC5C,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACrB,IAAI,EAAE,CAAC,CAAC;IACR,GAAG,EAAE,gBAAgB,CAAC;CACvB;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,CAAC,SAC/B,2BAA2B,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"DataTableRowActionItem.d.ts","sourceRoot":"","sources":["../../src/table/DataTableRowActionItem.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvE,MAAM,WAAW,2BAA2B,CAAC,CAAC;IAC5C,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACrB,IAAI,EAAE,CAAC,CAAC;IACR,GAAG,EAAE,gBAAgB,CAAC;CACvB;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,CAAC,SAC/B,2BAA2B,CAAC,CAAC,CAAC,gCAsCtC,CAAC"}
|
|
@@ -10,17 +10,30 @@ const DataTableRowActionItem = (props) => {
|
|
|
10
10
|
const { action, item, ctx } = props;
|
|
11
11
|
const Icon = action.icon;
|
|
12
12
|
const disabled = action.disabled?.(item);
|
|
13
|
+
const hint = action.hint?.(item);
|
|
14
|
+
const note = hint ? /* @__PURE__ */ jsx("span", {
|
|
15
|
+
className: "text-muted-foreground ms-auto ps-3 text-xs",
|
|
16
|
+
children: hint
|
|
17
|
+
}) : null;
|
|
13
18
|
if (action.checked) return /* @__PURE__ */ jsxs(DropdownMenuCheckboxItem, {
|
|
14
19
|
checked: action.checked(item),
|
|
15
20
|
disabled,
|
|
16
21
|
onClick: () => action.onClick(item, ctx),
|
|
17
|
-
children: [
|
|
22
|
+
children: [
|
|
23
|
+
Icon && /* @__PURE__ */ jsx(Icon, { className: "me-2 size-4" }),
|
|
24
|
+
action.label,
|
|
25
|
+
note
|
|
26
|
+
]
|
|
18
27
|
});
|
|
19
28
|
return /* @__PURE__ */ jsxs(DropdownMenuItem, {
|
|
20
29
|
disabled,
|
|
21
30
|
onClick: () => action.onClick(item, ctx),
|
|
22
31
|
variant: action.destructive ? "destructive" : void 0,
|
|
23
|
-
children: [
|
|
32
|
+
children: [
|
|
33
|
+
Icon && /* @__PURE__ */ jsx(Icon, { className: "me-2 size-4" }),
|
|
34
|
+
action.label,
|
|
35
|
+
note
|
|
36
|
+
]
|
|
24
37
|
});
|
|
25
38
|
};
|
|
26
39
|
export { DataTableRowActionItem };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTableRowActionItem.js","names":[],"sources":["../../src/table/DataTableRowActionItem.tsx"],"sourcesContent":["import {\n DropdownMenuCheckboxItem,\n DropdownMenuItem,\n} from \"../core/DropdownMenu.tsx\";\nimport type { RowAction, RowActionContext } from \"./dataTableTypes.ts\";\n\nexport interface DataTableRowActionItemProps<T> {\n action: RowAction<T>;\n item: T;\n ctx: RowActionContext;\n}\n\n/**\n * One menu entry, wherever it sits: at the top level of the row menu or\n * inside a group's submenu. Both render the same way, which is what keeps a\n * `checked` entry from behaving differently depending on where it was put.\n */\nexport const DataTableRowActionItem = <T,>(\n props: DataTableRowActionItemProps<T>,\n) => {\n const { action, item, ctx } = props;\n const Icon = action.icon;\n const disabled = action.disabled?.(item);\n if (action.checked) {\n return (\n <DropdownMenuCheckboxItem\n // Controlled with no `onCheckedChange`: the write is `onClick`, and\n // the state comes back from the row on the next render. Letting the\n // primitive toggle itself would show a check for a write that has\n // not landed, and would uncheck the current value when it is picked\n // again.\n checked={action.checked(item)}\n disabled={disabled}\n onClick={() => action.onClick(item, ctx)}\n >\n {Icon && <Icon className=\"me-2 size-4\" />}\n {action.label}\n </DropdownMenuCheckboxItem>\n );\n }\n return (\n <DropdownMenuItem\n disabled={disabled}\n onClick={() => action.onClick(item, ctx)}\n variant={action.destructive ? \"destructive\" : undefined}\n >\n {Icon && <Icon className=\"me-2 size-4\" />}\n {action.label}\n </DropdownMenuItem>\n );\n};\n"],"mappings":";;;;;;;;AAiBA,MAAa,0BACX,UACG;CACH,MAAM,EAAE,QAAQ,MAAM,QAAQ;CAC9B,MAAM,OAAO,OAAO;CACpB,MAAM,WAAW,OAAO,WAAW,IAAI;CACvC,IAAI,OAAO,SACT,OACE,qBAAC,0BAAD;EAME,SAAS,OAAO,QAAQ,IAAI;EAClB;EACV,eAAe,OAAO,QAAQ,MAAM,GAAG;EARzC,UAAA,
|
|
1
|
+
{"version":3,"file":"DataTableRowActionItem.js","names":[],"sources":["../../src/table/DataTableRowActionItem.tsx"],"sourcesContent":["import {\n DropdownMenuCheckboxItem,\n DropdownMenuItem,\n} from \"../core/DropdownMenu.tsx\";\nimport type { RowAction, RowActionContext } from \"./dataTableTypes.ts\";\n\nexport interface DataTableRowActionItemProps<T> {\n action: RowAction<T>;\n item: T;\n ctx: RowActionContext;\n}\n\n/**\n * One menu entry, wherever it sits: at the top level of the row menu or\n * inside a group's submenu. Both render the same way, which is what keeps a\n * `checked` entry from behaving differently depending on where it was put.\n */\nexport const DataTableRowActionItem = <T,>(\n props: DataTableRowActionItemProps<T>,\n) => {\n const { action, item, ctx } = props;\n const Icon = action.icon;\n const disabled = action.disabled?.(item);\n const hint = action.hint?.(item);\n const note = hint ? (\n <span className=\"text-muted-foreground ms-auto ps-3 text-xs\">{hint}</span>\n ) : null;\n if (action.checked) {\n return (\n <DropdownMenuCheckboxItem\n // Controlled with no `onCheckedChange`: the write is `onClick`, and\n // the state comes back from the row on the next render. Letting the\n // primitive toggle itself would show a check for a write that has\n // not landed, and would uncheck the current value when it is picked\n // again.\n checked={action.checked(item)}\n disabled={disabled}\n onClick={() => action.onClick(item, ctx)}\n >\n {Icon && <Icon className=\"me-2 size-4\" />}\n {action.label}\n {note}\n </DropdownMenuCheckboxItem>\n );\n }\n return (\n <DropdownMenuItem\n disabled={disabled}\n onClick={() => action.onClick(item, ctx)}\n variant={action.destructive ? \"destructive\" : undefined}\n >\n {Icon && <Icon className=\"me-2 size-4\" />}\n {action.label}\n {note}\n </DropdownMenuItem>\n );\n};\n"],"mappings":";;;;;;;;AAiBA,MAAa,0BACX,UACG;CACH,MAAM,EAAE,QAAQ,MAAM,QAAQ;CAC9B,MAAM,OAAO,OAAO;CACpB,MAAM,WAAW,OAAO,WAAW,IAAI;CACvC,MAAM,OAAO,OAAO,OAAO,IAAI;CAC/B,MAAM,OAAO,OACX,oBAAC,QAAD;EAAM,WAAU;EAA8C,UAAA;CAAW,CAAA,IACvE;CACJ,IAAI,OAAO,SACT,OACE,qBAAC,0BAAD;EAME,SAAS,OAAO,QAAQ,IAAI;EAClB;EACV,eAAe,OAAO,QAAQ,MAAM,GAAG;EARzC,UAAA;GAUG,QAAQ,oBAAC,MAAD,EAAM,WAAU,cAAe,CAAA;GACvC,OAAO;GACP;EACuB;;CAG9B,OACE,qBAAC,kBAAD;EACY;EACV,eAAe,OAAO,QAAQ,MAAM,GAAG;EACvC,SAAS,OAAO,cAAc,gBAAgB,KAAA;EAHhD,UAAA;GAKG,QAAQ,oBAAC,MAAD,EAAM,WAAU,cAAe,CAAA;GACvC,OAAO;GACP;EACe;;AAEtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTableRowActionsInline.d.ts","sourceRoot":"","sources":["../../src/table/DataTableRowActionsInline.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DataTableRowActionsInline.d.ts","sourceRoot":"","sources":["../../src/table/DataTableRowActionsInline.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAEV,gBAAgB,EAChB,cAAc,EAEf,MAAM,qBAAqB,CAAC;AAE7B,MAAM,WAAW,8BAA8B,CAAC,CAAC;IAC/C,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7B,IAAI,EAAE,CAAC,CAAC;IACR,GAAG,EAAE,gBAAgB,CAAC;CACvB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,GAAI,CAAC,SAClC,8BAA8B,CAAC,CAAC,CAAC,uCAiDzC,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Button } from "../core/Button.js";
|
|
2
2
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../core/Tooltip.js";
|
|
3
|
+
import { hasRowAction } from "./DataTableRowActionGroupItem.js";
|
|
3
4
|
import { DataTableRowActionsMenu } from "./DataTableRowActionsMenu.js";
|
|
4
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
6
|
// src/table/DataTableRowActionsInline.tsx
|
|
@@ -14,7 +15,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
14
15
|
*/
|
|
15
16
|
const DataTableRowActionsInline = (props) => {
|
|
16
17
|
const actions = props.actions.filter((entry) => !("children" in entry));
|
|
17
|
-
const groups = props.actions.filter((entry) => "children" in entry);
|
|
18
|
+
const groups = props.actions.filter((entry) => "children" in entry && hasRowAction(entry));
|
|
18
19
|
if (actions.length === 0 && groups.length === 0) return null;
|
|
19
20
|
return /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsxs("div", {
|
|
20
21
|
className: "flex items-center justify-end gap-1",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTableRowActionsInline.js","names":[],"sources":["../../src/table/DataTableRowActionsInline.tsx"],"sourcesContent":["import { Button } from \"../core/Button.tsx\";\nimport {\n Tooltip,\n TooltipContent,\n TooltipProvider,\n TooltipTrigger,\n} from \"../core/Tooltip.tsx\";\nimport { DataTableRowActionsMenu } from \"./DataTableRowActionsMenu.tsx\";\nimport type {\n RowAction,\n RowActionContext,\n RowActionEntry,\n RowActionGroup,\n} from \"./dataTableTypes.ts\";\n\nexport interface DataTableRowActionsInlineProps<T> {\n actions: RowActionEntry<T>[];\n item: T;\n ctx: RowActionContext;\n}\n\n/**\n * A row's actions as a line of icon buttons, for `rowActionsDisplay=\"inline\"`:\n * each one outlined, named by a tooltip from its `label`, red when it is\n * `destructive`.\n *\n * A group cannot be one button, so the groups keep a three-dots menu of\n * their own after the buttons. A `checked` entry is a toggle: its button\n * carries `aria-pressed`.\n */\nexport const DataTableRowActionsInline = <T,>(\n props: DataTableRowActionsInlineProps<T>,\n) => {\n const actions = props.actions.filter(\n (entry): entry is RowAction<T> => !(\"children\" in entry),\n );\n const groups = props.actions.filter(\n (entry): entry is RowActionGroup<T>
|
|
1
|
+
{"version":3,"file":"DataTableRowActionsInline.js","names":[],"sources":["../../src/table/DataTableRowActionsInline.tsx"],"sourcesContent":["import { Button } from \"../core/Button.tsx\";\nimport {\n Tooltip,\n TooltipContent,\n TooltipProvider,\n TooltipTrigger,\n} from \"../core/Tooltip.tsx\";\nimport { hasRowAction } from \"./DataTableRowActionGroupItem.tsx\";\nimport { DataTableRowActionsMenu } from \"./DataTableRowActionsMenu.tsx\";\nimport type {\n RowAction,\n RowActionContext,\n RowActionEntry,\n RowActionGroup,\n} from \"./dataTableTypes.ts\";\n\nexport interface DataTableRowActionsInlineProps<T> {\n actions: RowActionEntry<T>[];\n item: T;\n ctx: RowActionContext;\n}\n\n/**\n * A row's actions as a line of icon buttons, for `rowActionsDisplay=\"inline\"`:\n * each one outlined, named by a tooltip from its `label`, red when it is\n * `destructive`.\n *\n * A group cannot be one button, so the groups keep a three-dots menu of\n * their own after the buttons. A `checked` entry is a toggle: its button\n * carries `aria-pressed`.\n */\nexport const DataTableRowActionsInline = <T,>(\n props: DataTableRowActionsInlineProps<T>,\n) => {\n const actions = props.actions.filter(\n (entry): entry is RowAction<T> => !(\"children\" in entry),\n );\n const groups = props.actions.filter(\n (entry): entry is RowActionGroup<T> =>\n \"children\" in entry && hasRowAction(entry),\n );\n if (actions.length === 0 && groups.length === 0) return null;\n return (\n <TooltipProvider>\n <div className=\"flex items-center justify-end gap-1\">\n {actions.map((action) => {\n const Icon = action.icon;\n return (\n <Tooltip key={action.label}>\n <TooltipTrigger\n render={\n <Button\n type=\"button\"\n variant=\"outlined\"\n intent={action.destructive ? \"danger\" : undefined}\n size={Icon ? \"icon\" : \"sm\"}\n aria-label={action.label}\n aria-pressed={\n action.checked ? action.checked(props.item) : undefined\n }\n disabled={action.disabled?.(props.item)}\n onClick={() => action.onClick(props.item, props.ctx)}\n />\n }\n >\n {Icon ? <Icon className=\"size-4\" /> : action.label}\n </TooltipTrigger>\n <TooltipContent>{action.label}</TooltipContent>\n </Tooltip>\n );\n })}\n {groups.length > 0 ? (\n <DataTableRowActionsMenu\n actions={groups}\n item={props.item}\n ctx={props.ctx}\n />\n ) : null}\n </div>\n </TooltipProvider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;AA+BA,MAAa,6BACX,UACG;CACH,MAAM,UAAU,MAAM,QAAQ,QAC3B,UAAiC,EAAE,cAAc,MACpD;CACA,MAAM,SAAS,MAAM,QAAQ,QAC1B,UACC,cAAc,SAAS,aAAa,KAAK,CAC7C;CACA,IAAI,QAAQ,WAAW,KAAK,OAAO,WAAW,GAAG,OAAO;CACxD,OACE,oBAAC,iBAAD,EAAA,UACE,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACG,QAAQ,KAAK,WAAW;GACvB,MAAM,OAAO,OAAO;GACpB,OACE,qBAAC,SAAD,EAAA,UAAA,CACE,oBAAC,gBAAD;IACE,QACE,oBAAC,QAAD;KACE,MAAK;KACL,SAAQ;KACR,QAAQ,OAAO,cAAc,WAAW,KAAA;KACxC,MAAM,OAAO,SAAS;KACtB,cAAY,OAAO;KACnB,gBACE,OAAO,UAAU,OAAO,QAAQ,MAAM,IAAI,IAAI,KAAA;KAEhD,UAAU,OAAO,WAAW,MAAM,IAAI;KACtC,eAAe,OAAO,QAAQ,MAAM,MAAM,MAAM,GAAG;IACpD,CAAA;IAGF,UAAA,OAAO,oBAAC,MAAD,EAAM,WAAU,SAAU,CAAA,IAAI,OAAO;GAC/B,CAAA,GAChB,oBAAC,gBAAD,EAAA,UAAiB,OAAO,MAAsB,CAAA,CACvC,EAAA,GApBK,OAAO,KAoBZ;EAEb,CAAC,GACA,OAAO,SAAS,IACf,oBAAC,yBAAD;GACE,SAAS;GACT,MAAM,MAAM;GACZ,KAAK,MAAM;EACZ,CAAA,IACC,IACD;CACU,CAAA,EAAA,CAAA;AAErB"}
|
|
@@ -5,8 +5,9 @@ export interface DataTableRowActionsMenuProps<T> {
|
|
|
5
5
|
ctx: RowActionContext;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
-
* The three-dots menu at the end of a row,
|
|
9
|
-
*
|
|
8
|
+
* The three-dots menu at the end of a row, a group drawn as a submenu (and
|
|
9
|
+
* a group inside it as a submenu of that). Renders nothing when no entry
|
|
10
|
+
* survives.
|
|
10
11
|
*/
|
|
11
12
|
export declare const DataTableRowActionsMenu: <T>(props: DataTableRowActionsMenuProps<T>) => import("react").JSX.Element | null;
|
|
12
13
|
//# sourceMappingURL=DataTableRowActionsMenu.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTableRowActionsMenu.d.ts","sourceRoot":"","sources":["../../src/table/DataTableRowActionsMenu.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DataTableRowActionsMenu.d.ts","sourceRoot":"","sources":["../../src/table/DataTableRowActionsMenu.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE5E,MAAM,WAAW,4BAA4B,CAAC,CAAC;IAC7C,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7B,IAAI,EAAE,CAAC,CAAC;IACR,GAAG,EAAE,gBAAgB,CAAC;CACvB;AAED;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,GAAI,CAAC,SAChC,4BAA4B,CAAC,CAAC,CAAC,uCA4DvC,CAAC"}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { Button } from "../core/Button.js";
|
|
2
|
-
import { DropdownMenu, DropdownMenuContent, DropdownMenuSeparator,
|
|
2
|
+
import { DropdownMenu, DropdownMenuContent, DropdownMenuSeparator, DropdownMenuTrigger } from "../core/DropdownMenu.js";
|
|
3
|
+
import { DataTableRowActionGroupItem, hasRowAction, isRowActionGroup } from "./DataTableRowActionGroupItem.js";
|
|
3
4
|
import { DataTableRowActionItem } from "./DataTableRowActionItem.js";
|
|
4
5
|
import { useI18n } from "alepha/react/i18n";
|
|
5
6
|
import { MoreVertical } from "lucide-react";
|
|
6
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
8
|
// src/table/DataTableRowActionsMenu.tsx
|
|
8
9
|
/**
|
|
9
|
-
* The three-dots menu at the end of a row,
|
|
10
|
-
*
|
|
10
|
+
* The three-dots menu at the end of a row, a group drawn as a submenu (and
|
|
11
|
+
* a group inside it as a submenu of that). Renders nothing when no entry
|
|
12
|
+
* survives.
|
|
11
13
|
*/
|
|
12
14
|
const DataTableRowActionsMenu = (props) => {
|
|
13
15
|
const { tr } = useI18n();
|
|
14
|
-
const effective = props.actions.filter(
|
|
16
|
+
const effective = props.actions.filter(hasRowAction);
|
|
15
17
|
if (effective.length === 0) return null;
|
|
16
18
|
return /* @__PURE__ */ jsxs(DropdownMenu, { children: [/* @__PURE__ */ jsx(DropdownMenuTrigger, {
|
|
17
19
|
render: /* @__PURE__ */ jsx(Button, {
|
|
@@ -23,15 +25,14 @@ const DataTableRowActionsMenu = (props) => {
|
|
|
23
25
|
}), /* @__PURE__ */ jsx(DropdownMenuContent, {
|
|
24
26
|
align: "end",
|
|
25
27
|
children: effective.map((action, idx) => {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
const previous = effective[idx - 1];
|
|
29
|
+
const previousAction = previous && !isRowActionGroup(previous) ? previous : void 0;
|
|
30
|
+
const sep = idx > 0 && (!!previousAction?.separatorAfter || !isRowActionGroup(action) && !!action.destructive && !previousAction?.destructive);
|
|
31
|
+
return /* @__PURE__ */ jsxs("span", { children: [sep && /* @__PURE__ */ jsx(DropdownMenuSeparator, {}), isRowActionGroup(action) ? /* @__PURE__ */ jsx(DataTableRowActionGroupItem, {
|
|
32
|
+
group: action,
|
|
29
33
|
item: props.item,
|
|
30
34
|
ctx: props.ctx
|
|
31
|
-
}
|
|
32
|
-
const previous = effective[idx - 1];
|
|
33
|
-
const sep = idx > 0 && action.destructive && !(previous && !isRowActionGroup(previous) && previous.destructive);
|
|
34
|
-
return /* @__PURE__ */ jsxs("span", { children: [sep && /* @__PURE__ */ jsx(DropdownMenuSeparator, {}), /* @__PURE__ */ jsx(DataTableRowActionItem, {
|
|
35
|
+
}) : /* @__PURE__ */ jsx(DataTableRowActionItem, {
|
|
35
36
|
action,
|
|
36
37
|
item: props.item,
|
|
37
38
|
ctx: props.ctx
|
|
@@ -39,9 +40,6 @@ const DataTableRowActionsMenu = (props) => {
|
|
|
39
40
|
})
|
|
40
41
|
})] });
|
|
41
42
|
};
|
|
42
|
-
function isRowActionGroup(entry) {
|
|
43
|
-
return "children" in entry;
|
|
44
|
-
}
|
|
45
43
|
export { DataTableRowActionsMenu };
|
|
46
44
|
|
|
47
45
|
//# sourceMappingURL=DataTableRowActionsMenu.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTableRowActionsMenu.js","names":[],"sources":["../../src/table/DataTableRowActionsMenu.tsx"],"sourcesContent":["import { useI18n } from \"alepha/react/i18n\";\nimport { MoreVertical } from \"lucide-react\";\n\nimport { Button } from \"../core/Button.tsx\";\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuSeparator,\n
|
|
1
|
+
{"version":3,"file":"DataTableRowActionsMenu.js","names":[],"sources":["../../src/table/DataTableRowActionsMenu.tsx"],"sourcesContent":["import { useI18n } from \"alepha/react/i18n\";\nimport { MoreVertical } from \"lucide-react\";\n\nimport { Button } from \"../core/Button.tsx\";\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuSeparator,\n DropdownMenuTrigger,\n} from \"../core/DropdownMenu.tsx\";\nimport {\n DataTableRowActionGroupItem,\n hasRowAction,\n isRowActionGroup,\n} from \"./DataTableRowActionGroupItem.tsx\";\nimport { DataTableRowActionItem } from \"./DataTableRowActionItem.tsx\";\nimport type { RowActionContext, RowActionEntry } from \"./dataTableTypes.ts\";\n\nexport interface DataTableRowActionsMenuProps<T> {\n actions: RowActionEntry<T>[];\n item: T;\n ctx: RowActionContext;\n}\n\n/**\n * The three-dots menu at the end of a row, a group drawn as a submenu (and\n * a group inside it as a submenu of that). Renders nothing when no entry\n * survives.\n */\nexport const DataTableRowActionsMenu = <T,>(\n props: DataTableRowActionsMenuProps<T>,\n) => {\n const { tr } = useI18n();\n // ⚠️ Effective entries, not entries: a group is one entry however many\n // children it has, so a lone empty group would otherwise render the\n // three-dots trigger over an empty menu.\n const effective = props.actions.filter(hasRowAction);\n if (effective.length === 0) return null;\n return (\n <DropdownMenu>\n <DropdownMenuTrigger\n render={\n <Button\n variant=\"minimal\"\n size=\"icon\"\n aria-label={tr(\"dataTable.openRowActions\", {\n default: \"Open row actions\",\n })}\n />\n }\n >\n <MoreVertical className=\"size-4\" />\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"end\">\n {effective.map((action, idx) => {\n // A separator above an entry when the one before asked for it\n // (`separatorAfter`), or above the first of a run of destructive\n // entries. A group is never destructive, so the previous entry\n // being one reads as falsy here and the rule needs no case for it.\n const previous = effective[idx - 1];\n const previousAction =\n previous && !isRowActionGroup(previous) ? previous : undefined;\n const sep =\n idx > 0 &&\n (!!previousAction?.separatorAfter ||\n (!isRowActionGroup(action) &&\n !!action.destructive &&\n !previousAction?.destructive));\n return (\n <span key={action.label}>\n {sep && <DropdownMenuSeparator />}\n {isRowActionGroup(action) ? (\n <DataTableRowActionGroupItem\n group={action}\n item={props.item}\n ctx={props.ctx}\n />\n ) : (\n <DataTableRowActionItem\n action={action}\n item={props.item}\n ctx={props.ctx}\n />\n )}\n </span>\n );\n })}\n </DropdownMenuContent>\n </DropdownMenu>\n );\n};\n"],"mappings":";;;;;;;;;;;;;AA6BA,MAAa,2BACX,UACG;CACH,MAAM,EAAE,OAAO,QAAQ;CAIvB,MAAM,YAAY,MAAM,QAAQ,OAAO,YAAY;CACnD,IAAI,UAAU,WAAW,GAAG,OAAO;CACnC,OACE,qBAAC,cAAD,EAAA,UAAA,CACE,oBAAC,qBAAD;EACE,QACE,oBAAC,QAAD;GACE,SAAQ;GACR,MAAK;GACL,cAAY,GAAG,4BAA4B,EACzC,SAAS,mBACX,CAAC;EACF,CAAA;EAGH,UAAA,oBAAC,cAAD,EAAc,WAAU,SAAU,CAAA;CACf,CAAA,GACrB,oBAAC,qBAAD;EAAqB,OAAM;EACxB,UAAA,UAAU,KAAK,QAAQ,QAAQ;GAK9B,MAAM,WAAW,UAAU,MAAM;GACjC,MAAM,iBACJ,YAAY,CAAC,iBAAiB,QAAQ,IAAI,WAAW,KAAA;GACvD,MAAM,MACJ,MAAM,MACL,CAAC,CAAC,gBAAgB,kBAChB,CAAC,iBAAiB,MAAM,KACvB,CAAC,CAAC,OAAO,eACT,CAAC,gBAAgB;GACvB,OACE,qBAAC,QAAD,EAAA,UAAA,CACG,OAAO,oBAAC,uBAAD,CAAwB,CAAA,GAC/B,iBAAiB,MAAM,IACtB,oBAAC,6BAAD;IACE,OAAO;IACP,MAAM,MAAM;IACZ,KAAK,MAAM;GACZ,CAAA,IAED,oBAAC,wBAAD;IACU;IACR,MAAM,MAAM;IACZ,KAAK,MAAM;GACZ,CAAA,CAEC,EAAA,GAfK,OAAO,KAeZ;EAEV,CAAC;CACkB,CAAA,CACT,EAAA,CAAA;AAElB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
import type { DataTableCellPadding } from "./dataTableCellPadding.ts";
|
|
3
|
+
import type { DataTablePersistenceStorage } from "./dataTablePersistence.ts";
|
|
3
4
|
import type { DataTableSquareRight } from "./dataTableSquareRight.ts";
|
|
4
5
|
import type { DataTableEmptyState, DataTableFilterFields, DataTableFilters, DataTableNoFilterFields, DataTablePersistedFacets, DataTableGroupBy, DataTableSummary, BulkAction, BulkMenuAction, ColumnDef, RowActionEntry, SortState, TableAction } from "./dataTableTypes.ts";
|
|
5
6
|
/**
|
|
@@ -64,7 +65,8 @@ export interface DataTableBaseProps<T, F extends DataTableFilterFields = DataTab
|
|
|
64
65
|
* item. Each `onClick` receives `(item, { refresh, clearSelection })`.
|
|
65
66
|
*
|
|
66
67
|
* An entry may also be a {@link RowActionGroup}: a label, an icon and
|
|
67
|
-
* the actions it holds, rendered as a submenu
|
|
68
|
+
* the actions it holds, rendered as a submenu; a group inside a group is a
|
|
69
|
+
* submenu inside it.
|
|
68
70
|
*/
|
|
69
71
|
rowActions?: (item: T) => RowActionEntry<T>[];
|
|
70
72
|
/**
|
|
@@ -244,13 +246,25 @@ export interface DataTableBaseProps<T, F extends DataTableFilterFields = DataTab
|
|
|
244
246
|
filters?: DataTableFilters<F>;
|
|
245
247
|
/**
|
|
246
248
|
* When set, filter values, the filters on the bar, column visibility, and
|
|
247
|
-
* sort state are persisted
|
|
249
|
+
* sort state are persisted under this key, to `localStorage` unless
|
|
250
|
+
* {@link persistenceStorage} names another store. Pick a key that's
|
|
248
251
|
* unique per page and per scope (e.g. `"admin.users"`,
|
|
249
252
|
* `\`lor.board.${campaignId}\``).
|
|
250
253
|
*
|
|
251
254
|
* Narrow what it stores with {@link persist}.
|
|
252
255
|
*/
|
|
253
256
|
persistenceKey?: string;
|
|
257
|
+
/**
|
|
258
|
+
* Where {@link persistenceKey} is stored: `localStorage` when absent. Pass
|
|
259
|
+
* a {@link DataTablePersistenceStorage} to keep the table's state somewhere
|
|
260
|
+
* else, for instance in the user's preferences on the server so it follows
|
|
261
|
+
* them to another device.
|
|
262
|
+
*
|
|
263
|
+
* The storage answers synchronously, so a remote one is loaded before the
|
|
264
|
+
* table mounts. Keep its identity for the table's lifetime: it is read on
|
|
265
|
+
* mount and when the key changes.
|
|
266
|
+
*/
|
|
267
|
+
persistenceStorage?: DataTablePersistenceStorage;
|
|
254
268
|
/**
|
|
255
269
|
* Which facets {@link persistenceKey} stores. All three by default, so this
|
|
256
270
|
* is only ever worth passing to turn one OFF.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataTableBaseProps.d.ts","sourceRoot":"","sources":["../../src/table/dataTableBaseProps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,EACxB,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,SAAS,EACT,cAAc,EACd,SAAS,EACT,WAAW,EACZ,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAEH,MAAM,WAAW,kBAAkB,CACjC,CAAC,EACD,CAAC,SAAS,qBAAqB,GAAG,uBAAuB;IAEzD;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC
|
|
1
|
+
{"version":3,"file":"dataTableBaseProps.d.ts","sourceRoot":"","sources":["../../src/table/dataTableBaseProps.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,13 +1,54 @@
|
|
|
1
1
|
import { type ZObject } from "alepha";
|
|
2
2
|
import type { DataTableFilterMode, ColumnDef, SortState } from "./dataTableTypes.ts";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Where a table keeps what it persists: the filters, the filters on the bar,
|
|
5
|
+
* the columns and their order, the sort, the page size and the summary
|
|
6
|
+
* panel, each under its `persistenceKey` and a suffix naming the facet.
|
|
7
|
+
*
|
|
8
|
+
* Synchronous on both sides, and that is the contract: the table reads its
|
|
9
|
+
* state in `useState` initializers, so a store reached over the network has
|
|
10
|
+
* to be loaded before the table mounts and answer from memory after that.
|
|
11
|
+
* `write` with `undefined` deletes the value; `writePersisted` turns an empty
|
|
12
|
+
* object or array into `undefined` before it gets here.
|
|
13
|
+
*
|
|
14
|
+
* The default is {@link localStorageDataTableStorage}. Pass another one as a
|
|
15
|
+
* table's `persistenceStorage` to keep its state somewhere else, a user's
|
|
16
|
+
* preferences on the server for one. It should keep one identity for the
|
|
17
|
+
* table's lifetime: it is read when the table mounts and when its
|
|
18
|
+
* `persistenceKey` changes, not when the storage does.
|
|
19
|
+
*/
|
|
20
|
+
export interface DataTablePersistenceStorage {
|
|
21
|
+
/**
|
|
22
|
+
* The value stored for one facet of one key, or `undefined` when there is
|
|
23
|
+
* none. Never throws.
|
|
24
|
+
*/
|
|
25
|
+
read(key: string, suffix: string): unknown;
|
|
26
|
+
/**
|
|
27
|
+
* Store one facet of one key; `undefined` deletes it. Never throws.
|
|
28
|
+
*/
|
|
29
|
+
write(key: string, suffix: string, value: unknown): void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Every suffix a DataTable stores under its `persistenceKey`, one per facet.
|
|
33
|
+
* What a storage moving a table's state from one place to another (say, from
|
|
34
|
+
* `localStorage` to a server) has to carry over.
|
|
35
|
+
*/
|
|
36
|
+
export declare const DATA_TABLE_PERSISTED_SUFFIXES: readonly ["filters", "filterVisibility", "columns", "columnOrder", "sort", "size", "summaryOpen"];
|
|
37
|
+
/**
|
|
38
|
+
* The default storage: `localStorage`, under `<key>.<suffix>`, as JSON.
|
|
39
|
+
* Answers nothing on the server, and skips a write the browser refuses
|
|
40
|
+
* (private mode, quota).
|
|
41
|
+
*/
|
|
42
|
+
export declare const localStorageDataTableStorage: DataTablePersistenceStorage;
|
|
43
|
+
/**
|
|
44
|
+
* Synchronous read of `<key>.<suffix>` from `storage`, `localStorage` by
|
|
45
|
+
* default. Returns undefined on miss or error, and on the server.
|
|
5
46
|
*/
|
|
6
|
-
export declare const readPersisted: <V>(key: string, suffix: string) => V | undefined;
|
|
47
|
+
export declare const readPersisted: <V>(key: string, suffix: string, storage?: DataTablePersistenceStorage) => V | undefined;
|
|
7
48
|
/**
|
|
8
49
|
* Reshape persisted filter values that no longer match the schema.
|
|
9
50
|
*
|
|
10
|
-
* Filters are stored in localStorage
|
|
51
|
+
* Filters are stored per `persistenceKey` (in localStorage by default), so a filter whose
|
|
11
52
|
* shape changes meets values written by the previous shape - on the machine
|
|
12
53
|
* of anyone who has used the page, and only there, which is precisely the
|
|
13
54
|
* class of bug no test environment contains. The first case was the Quests
|
|
@@ -23,9 +64,10 @@ export declare const readPersisted: <V>(key: string, suffix: string) => V | unde
|
|
|
23
64
|
*/
|
|
24
65
|
export declare const reconcilePersistedFilters: (schema: ZObject | undefined, values: Record<string, any> | undefined) => Record<string, any> | undefined;
|
|
25
66
|
/**
|
|
26
|
-
* Synchronous
|
|
67
|
+
* Synchronous write of `<key>.<suffix>` to `storage`, `localStorage` by
|
|
68
|
+
* default. Empty objects, empty arrays and null delete the key.
|
|
27
69
|
*/
|
|
28
|
-
export declare const writePersisted: (key: string, suffix: string, value: unknown) => void;
|
|
70
|
+
export declare const writePersisted: (key: string, suffix: string, value: unknown, storage?: DataTablePersistenceStorage) => void;
|
|
29
71
|
/**
|
|
30
72
|
* The three persisted preferences, read for one `persistenceKey`.
|
|
31
73
|
*
|
|
@@ -35,16 +77,16 @@ export declare const writePersisted: (key: string, suffix: string, value: unknow
|
|
|
35
77
|
* scope-change path would come to disagree with the mount path about what a
|
|
36
78
|
* stored value means.
|
|
37
79
|
*/
|
|
38
|
-
export declare const persistedSort: (key: string | undefined, fallback: SortState | null | undefined) => SortState | null;
|
|
39
|
-
export declare const persistedSize: (key: string | undefined, fallback: number | undefined) => number;
|
|
80
|
+
export declare const persistedSort: (key: string | undefined, fallback: SortState | null | undefined, storage?: DataTablePersistenceStorage) => SortState | null;
|
|
81
|
+
export declare const persistedSize: (key: string | undefined, fallback: number | undefined, storage?: DataTablePersistenceStorage) => number;
|
|
40
82
|
/**
|
|
41
83
|
* Whether the summary panel is open: the reader's last choice, or open.
|
|
42
84
|
*
|
|
43
85
|
* Stored with the key whatever `persist` says, like the page size: it is how
|
|
44
86
|
* the reader arranged the page, not a question they asked it.
|
|
45
87
|
*/
|
|
46
|
-
export declare const persistedSummaryOpen: (key: string | undefined) => boolean;
|
|
47
|
-
export declare const persistedColumns: <T>(key: string | undefined, columns: Record<string, ColumnDef<T
|
|
88
|
+
export declare const persistedSummaryOpen: (key: string | undefined, storage?: DataTablePersistenceStorage) => boolean;
|
|
89
|
+
export declare const persistedColumns: <T>(key: string | undefined, columns: Record<string, ColumnDef<T>>, storage?: DataTablePersistenceStorage) => Set<string>;
|
|
48
90
|
/**
|
|
49
91
|
* The reader's column order, reconciled against what the table actually
|
|
50
92
|
* declares.
|
|
@@ -64,7 +106,7 @@ export declare const persistedColumns: <T>(key: string | undefined, columns: Rec
|
|
|
64
106
|
* the declared one any more) nor the reader's.
|
|
65
107
|
*/
|
|
66
108
|
export declare const reconcileOrder: (stored: string[] | undefined, declared: string[]) => string[];
|
|
67
|
-
export declare const persistedOrder: <T>(key: string | undefined, columns: Record<string, ColumnDef<T
|
|
109
|
+
export declare const persistedOrder: <T>(key: string | undefined, columns: Record<string, ColumnDef<T>>, storage?: DataTablePersistenceStorage) => string[];
|
|
68
110
|
/**
|
|
69
111
|
* Which filters a reader changed on the bar against the declaration: the
|
|
70
112
|
* optional ones they added, and the default ones they removed.
|
|
@@ -90,7 +132,7 @@ export declare const declaredShownFilters: (modes: Record<string, DataTableFilte
|
|
|
90
132
|
* optional and a removed key that is no longer default do nothing, and a
|
|
91
133
|
* locked key ignores both.
|
|
92
134
|
*/
|
|
93
|
-
export declare const persistedShownFilters: (key: string | undefined, modes: Record<string, DataTableFilterMode
|
|
135
|
+
export declare const persistedShownFilters: (key: string | undefined, modes: Record<string, DataTableFilterMode>, storage?: DataTablePersistenceStorage) => string[];
|
|
94
136
|
/**
|
|
95
137
|
* The change a set of shown filters makes against the declaration, or
|
|
96
138
|
* `undefined` when it makes none, which `writePersisted` turns into a delete.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataTablePersistence.d.ts","sourceRoot":"","sources":["../../src/table/dataTablePersistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAK,MAAM,QAAQ,CAAC;AAEzC,OAAO,KAAK,EACV,mBAAmB,EACnB,SAAS,EACT,SAAS,EACV,MAAM,qBAAqB,CAAC;AAE7B;;
|
|
1
|
+
{"version":3,"file":"dataTablePersistence.d.ts","sourceRoot":"","sources":["../../src/table/dataTablePersistence.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,13 +1,54 @@
|
|
|
1
1
|
import { z } from "alepha";
|
|
2
2
|
// src/table/dataTablePersistence.ts
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Every suffix a DataTable stores under its `persistenceKey`, one per facet.
|
|
5
|
+
* What a storage moving a table's state from one place to another (say, from
|
|
6
|
+
* `localStorage` to a server) has to carry over.
|
|
5
7
|
*/
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
+
const DATA_TABLE_PERSISTED_SUFFIXES = [
|
|
9
|
+
"filters",
|
|
10
|
+
"filterVisibility",
|
|
11
|
+
"columns",
|
|
12
|
+
"columnOrder",
|
|
13
|
+
"sort",
|
|
14
|
+
"size",
|
|
15
|
+
"summaryOpen"
|
|
16
|
+
];
|
|
17
|
+
/**
|
|
18
|
+
* The default storage: `localStorage`, under `<key>.<suffix>`, as JSON.
|
|
19
|
+
* Answers nothing on the server, and skips a write the browser refuses
|
|
20
|
+
* (private mode, quota).
|
|
21
|
+
*/
|
|
22
|
+
const localStorageDataTableStorage = {
|
|
23
|
+
read: (key, suffix) => {
|
|
24
|
+
if (typeof window === "undefined") return void 0;
|
|
25
|
+
try {
|
|
26
|
+
const raw = window.localStorage.getItem(`${key}.${suffix}`);
|
|
27
|
+
return raw == null ? void 0 : JSON.parse(raw);
|
|
28
|
+
} catch {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
write: (key, suffix, value) => {
|
|
33
|
+
if (typeof window === "undefined") return;
|
|
34
|
+
const fullKey = `${key}.${suffix}`;
|
|
35
|
+
try {
|
|
36
|
+
if (value === void 0) {
|
|
37
|
+
window.localStorage.removeItem(fullKey);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
window.localStorage.setItem(fullKey, JSON.stringify(value));
|
|
41
|
+
} catch {}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Synchronous read of `<key>.<suffix>` from `storage`, `localStorage` by
|
|
46
|
+
* default. Returns undefined on miss or error, and on the server.
|
|
47
|
+
*/
|
|
48
|
+
const readPersisted = (key, suffix, storage = localStorageDataTableStorage) => {
|
|
8
49
|
try {
|
|
9
|
-
const
|
|
10
|
-
return
|
|
50
|
+
const value = storage.read(key, suffix);
|
|
51
|
+
return value === void 0 || value === null ? void 0 : value;
|
|
11
52
|
} catch {
|
|
12
53
|
return;
|
|
13
54
|
}
|
|
@@ -15,7 +56,7 @@ const readPersisted = (key, suffix) => {
|
|
|
15
56
|
/**
|
|
16
57
|
* Reshape persisted filter values that no longer match the schema.
|
|
17
58
|
*
|
|
18
|
-
* Filters are stored in localStorage
|
|
59
|
+
* Filters are stored per `persistenceKey` (in localStorage by default), so a filter whose
|
|
19
60
|
* shape changes meets values written by the previous shape - on the machine
|
|
20
61
|
* of anyone who has used the page, and only there, which is precisely the
|
|
21
62
|
* class of bug no test environment contains. The first case was the Quests
|
|
@@ -45,19 +86,15 @@ const reconcilePersistedFilters = (schema, values) => {
|
|
|
45
86
|
return out;
|
|
46
87
|
};
|
|
47
88
|
/**
|
|
48
|
-
* Synchronous
|
|
89
|
+
* Synchronous write of `<key>.<suffix>` to `storage`, `localStorage` by
|
|
90
|
+
* default. Empty objects, empty arrays and null delete the key.
|
|
49
91
|
*/
|
|
50
|
-
const writePersisted = (key, suffix, value) => {
|
|
51
|
-
|
|
52
|
-
const
|
|
92
|
+
const writePersisted = (key, suffix, value, storage = localStorageDataTableStorage) => {
|
|
93
|
+
const isEmptyObject = value !== null && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0;
|
|
94
|
+
const isEmptyArray = Array.isArray(value) && value.length === 0;
|
|
95
|
+
const empty = value === void 0 || value === null || isEmptyObject || isEmptyArray;
|
|
53
96
|
try {
|
|
54
|
-
|
|
55
|
-
const isEmptyArray = Array.isArray(value) && value.length === 0;
|
|
56
|
-
if (value === void 0 || value === null || isEmptyObject || isEmptyArray) {
|
|
57
|
-
window.localStorage.removeItem(fullKey);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
window.localStorage.setItem(fullKey, JSON.stringify(value));
|
|
97
|
+
storage.write(key, suffix, empty ? void 0 : value);
|
|
61
98
|
} catch {}
|
|
62
99
|
};
|
|
63
100
|
/**
|
|
@@ -69,11 +106,11 @@ const writePersisted = (key, suffix, value) => {
|
|
|
69
106
|
* scope-change path would come to disagree with the mount path about what a
|
|
70
107
|
* stored value means.
|
|
71
108
|
*/
|
|
72
|
-
const persistedSort = (key, fallback) => {
|
|
73
|
-
return (key ? readPersisted(key, "sort") : void 0) ?? fallback ?? null;
|
|
109
|
+
const persistedSort = (key, fallback, storage) => {
|
|
110
|
+
return (key ? readPersisted(key, "sort", storage) : void 0) ?? fallback ?? null;
|
|
74
111
|
};
|
|
75
|
-
const persistedSize = (key, fallback) => {
|
|
76
|
-
return (key ? readPersisted(key, "size") : void 0) ?? fallback ?? 20;
|
|
112
|
+
const persistedSize = (key, fallback, storage) => {
|
|
113
|
+
return (key ? readPersisted(key, "size", storage) : void 0) ?? fallback ?? 20;
|
|
77
114
|
};
|
|
78
115
|
/**
|
|
79
116
|
* Whether the summary panel is open: the reader's last choice, or open.
|
|
@@ -81,13 +118,13 @@ const persistedSize = (key, fallback) => {
|
|
|
81
118
|
* Stored with the key whatever `persist` says, like the page size: it is how
|
|
82
119
|
* the reader arranged the page, not a question they asked it.
|
|
83
120
|
*/
|
|
84
|
-
const persistedSummaryOpen = (key) => {
|
|
85
|
-
const stored = key ? readPersisted(key, "summaryOpen") : void 0;
|
|
121
|
+
const persistedSummaryOpen = (key, storage) => {
|
|
122
|
+
const stored = key ? readPersisted(key, "summaryOpen", storage) : void 0;
|
|
86
123
|
return typeof stored === "boolean" ? stored : true;
|
|
87
124
|
};
|
|
88
|
-
const persistedColumns = (key, columns) => {
|
|
125
|
+
const persistedColumns = (key, columns, storage) => {
|
|
89
126
|
const declared = new Set(Object.keys(columns).filter((k) => !columns[k].defaultHidden));
|
|
90
|
-
const stored = key ? readPersisted(key, "columns") : void 0;
|
|
127
|
+
const stored = key ? readPersisted(key, "columns", storage) : void 0;
|
|
91
128
|
if (!Array.isArray(stored)) return declared;
|
|
92
129
|
const kept = new Set(stored.filter((k) => k in columns));
|
|
93
130
|
return kept.size > 0 ? kept : declared;
|
|
@@ -117,7 +154,7 @@ const reconcileOrder = (stored, declared) => {
|
|
|
117
154
|
const seen = new Set(kept);
|
|
118
155
|
return [...kept, ...declared.filter((key) => !seen.has(key))];
|
|
119
156
|
};
|
|
120
|
-
const persistedOrder = (key, columns) => reconcileOrder(key ? readPersisted(key, "columnOrder") : void 0, Object.keys(columns));
|
|
157
|
+
const persistedOrder = (key, columns, storage) => reconcileOrder(key ? readPersisted(key, "columnOrder", storage) : void 0, Object.keys(columns));
|
|
121
158
|
/**
|
|
122
159
|
* The filters a table puts on the bar from the start: every `default` field.
|
|
123
160
|
* A locked field is drawn regardless, and is not part of the set.
|
|
@@ -135,9 +172,9 @@ const declaredShownFilters = (modes) => Object.keys(modes).filter((key) => modes
|
|
|
135
172
|
* optional and a removed key that is no longer default do nothing, and a
|
|
136
173
|
* locked key ignores both.
|
|
137
174
|
*/
|
|
138
|
-
const persistedShownFilters = (key, modes) => {
|
|
175
|
+
const persistedShownFilters = (key, modes, storage) => {
|
|
139
176
|
const declared = declaredShownFilters(modes);
|
|
140
|
-
const stored = key ? readPersisted(key, "filterVisibility") : void 0;
|
|
177
|
+
const stored = key ? readPersisted(key, "filterVisibility", storage) : void 0;
|
|
141
178
|
if (!stored) return declared;
|
|
142
179
|
const listOf = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
143
180
|
const removed = new Set(listOf(stored.removed).filter((k) => modes[k] === "default"));
|
|
@@ -156,6 +193,6 @@ const filterVisibilityChange = (shown, modes) => {
|
|
|
156
193
|
removed
|
|
157
194
|
};
|
|
158
195
|
};
|
|
159
|
-
export { declaredShownFilters, filterVisibilityChange, persistedColumns, persistedOrder, persistedShownFilters, persistedSize, persistedSort, persistedSummaryOpen, readPersisted, reconcileOrder, reconcilePersistedFilters, writePersisted };
|
|
196
|
+
export { DATA_TABLE_PERSISTED_SUFFIXES, declaredShownFilters, filterVisibilityChange, localStorageDataTableStorage, persistedColumns, persistedOrder, persistedShownFilters, persistedSize, persistedSort, persistedSummaryOpen, readPersisted, reconcileOrder, reconcilePersistedFilters, writePersisted };
|
|
160
197
|
|
|
161
198
|
//# sourceMappingURL=dataTablePersistence.js.map
|