@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.
Files changed (187) hide show
  1. package/README.md +4 -2
  2. package/dist/admin/AdminJobExecutionSheet.d.ts.map +1 -1
  3. package/dist/admin/AdminJobExecutionSheet.js +7 -0
  4. package/dist/admin/AdminJobExecutionSheet.js.map +1 -1
  5. package/dist/admin/analytics/RequestDialog.js +1 -1
  6. package/dist/admin/analytics/RequestDialog.js.map +1 -1
  7. package/dist/ai/AiChat.d.ts +6 -3
  8. package/dist/ai/AiChat.d.ts.map +1 -1
  9. package/dist/ai/AiChat.js +34 -5
  10. package/dist/ai/AiChat.js.map +1 -1
  11. package/dist/ai/AiChatConfirmCard.d.ts.map +1 -1
  12. package/dist/ai/AiChatConfirmCard.js +5 -1
  13. package/dist/ai/AiChatConfirmCard.js.map +1 -1
  14. package/dist/ai/AiChatFloat.d.ts +14 -0
  15. package/dist/ai/AiChatFloat.d.ts.map +1 -0
  16. package/dist/ai/AiChatFloat.js +30 -0
  17. package/dist/ai/AiChatFloat.js.map +1 -0
  18. package/dist/ai/AiChatMessage.js +2 -2
  19. package/dist/ai/AiChatMessage.js.map +1 -1
  20. package/dist/ai/AiChatPanel.d.ts +19 -0
  21. package/dist/ai/AiChatPanel.d.ts.map +1 -1
  22. package/dist/ai/AiChatPanel.js +65 -19
  23. package/dist/ai/AiChatPanel.js.map +1 -1
  24. package/dist/ai/AiChatToolStepDetails.d.ts +14 -0
  25. package/dist/ai/AiChatToolStepDetails.d.ts.map +1 -0
  26. package/dist/ai/AiChatToolStepDetails.js +34 -0
  27. package/dist/ai/AiChatToolStepDetails.js.map +1 -0
  28. package/dist/ai/AiChatToolTrace.d.ts +50 -0
  29. package/dist/ai/AiChatToolTrace.d.ts.map +1 -0
  30. package/dist/ai/AiChatToolTrace.js +91 -0
  31. package/dist/ai/AiChatToolTrace.js.map +1 -0
  32. package/dist/ai/index.d.ts +4 -2
  33. package/dist/ai/index.d.ts.map +1 -1
  34. package/dist/ai/index.js +3 -1
  35. package/dist/core/Button.d.ts.map +1 -1
  36. package/dist/core/Button.js +17 -1
  37. package/dist/core/Button.js.map +1 -1
  38. package/dist/core/Dialog.d.ts.map +1 -1
  39. package/dist/core/Dialog.js +1 -1
  40. package/dist/core/Dialog.js.map +1 -1
  41. package/dist/core/TimeAgo.d.ts +3 -4
  42. package/dist/core/TimeAgo.d.ts.map +1 -1
  43. package/dist/core/TimeAgo.js +3 -4
  44. package/dist/core/TimeAgo.js.map +1 -1
  45. package/dist/i18n/en/index.d.ts +22 -0
  46. package/dist/i18n/en/index.d.ts.map +1 -0
  47. package/dist/i18n/en/index.js +1 -0
  48. package/dist/i18n/en/uiEn.d.ts +37 -0
  49. package/dist/i18n/en/uiEn.d.ts.map +1 -0
  50. package/dist/i18n/en/uiEn.js +1468 -0
  51. package/dist/i18n/en/uiEn.js.map +1 -0
  52. package/dist/i18n/fr/uiFr.d.ts +3 -2
  53. package/dist/i18n/fr/uiFr.d.ts.map +1 -1
  54. package/dist/i18n/fr/uiFr.js +7 -2
  55. package/dist/i18n/fr/uiFr.js.map +1 -1
  56. package/dist/markdown/MarkdownView.d.ts +14 -0
  57. package/dist/markdown/MarkdownView.d.ts.map +1 -1
  58. package/dist/markdown/MarkdownView.js +16 -3
  59. package/dist/markdown/MarkdownView.js.map +1 -1
  60. package/dist/markdown/highlightLines.d.ts +27 -0
  61. package/dist/markdown/highlightLines.d.ts.map +1 -0
  62. package/dist/markdown/highlightLines.js +91 -0
  63. package/dist/markdown/highlightLines.js.map +1 -0
  64. package/dist/markdown/index.d.ts +5 -2
  65. package/dist/markdown/index.d.ts.map +1 -1
  66. package/dist/markdown/index.js +2 -1
  67. package/dist/shell/ButtonInbox.d.ts +8 -0
  68. package/dist/shell/ButtonInbox.d.ts.map +1 -1
  69. package/dist/shell/ButtonInbox.js +3 -1
  70. package/dist/shell/ButtonInbox.js.map +1 -1
  71. package/dist/shell/PlateLayout.d.ts.map +1 -1
  72. package/dist/shell/PlateLayout.js +2 -2
  73. package/dist/shell/PlateLayout.js.map +1 -1
  74. package/dist/sortable/index.d.ts +17 -0
  75. package/dist/sortable/index.d.ts.map +1 -0
  76. package/dist/sortable/index.js +4 -0
  77. package/dist/sortable/useSortableItem.d.ts +32 -0
  78. package/dist/sortable/useSortableItem.d.ts.map +1 -0
  79. package/dist/sortable/useSortableItem.js +35 -0
  80. package/dist/sortable/useSortableItem.js.map +1 -0
  81. package/dist/sortable/useSortableList.d.ts +85 -0
  82. package/dist/sortable/useSortableList.d.ts.map +1 -0
  83. package/dist/sortable/useSortableList.js +125 -0
  84. package/dist/sortable/useSortableList.js.map +1 -0
  85. package/dist/table/DataTable.d.ts.map +1 -1
  86. package/dist/table/DataTable.js +9 -6
  87. package/dist/table/DataTable.js.map +1 -1
  88. package/dist/table/DataTableRowActionGroupItem.d.ts +23 -0
  89. package/dist/table/DataTableRowActionGroupItem.d.ts.map +1 -0
  90. package/dist/table/DataTableRowActionGroupItem.js +38 -0
  91. package/dist/table/DataTableRowActionGroupItem.js.map +1 -0
  92. package/dist/table/DataTableRowActionItem.d.ts.map +1 -1
  93. package/dist/table/DataTableRowActionItem.js +15 -2
  94. package/dist/table/DataTableRowActionItem.js.map +1 -1
  95. package/dist/table/DataTableRowActionsInline.d.ts.map +1 -1
  96. package/dist/table/DataTableRowActionsInline.js +2 -1
  97. package/dist/table/DataTableRowActionsInline.js.map +1 -1
  98. package/dist/table/DataTableRowActionsMenu.d.ts +3 -2
  99. package/dist/table/DataTableRowActionsMenu.d.ts.map +1 -1
  100. package/dist/table/DataTableRowActionsMenu.js +12 -14
  101. package/dist/table/DataTableRowActionsMenu.js.map +1 -1
  102. package/dist/table/dataTableBaseProps.d.ts +16 -2
  103. package/dist/table/dataTableBaseProps.d.ts.map +1 -1
  104. package/dist/table/dataTablePersistence.d.ts +53 -11
  105. package/dist/table/dataTablePersistence.d.ts.map +1 -1
  106. package/dist/table/dataTablePersistence.js +66 -29
  107. package/dist/table/dataTablePersistence.js.map +1 -1
  108. package/dist/table/dataTableTypes.d.ts +20 -3
  109. package/dist/table/dataTableTypes.d.ts.map +1 -1
  110. package/dist/table/index.d.ts +8 -1
  111. package/dist/table/index.d.ts.map +1 -1
  112. package/dist/table/index.js +2 -1
  113. package/dist/table/useDataTableColumns.d.ts.map +1 -1
  114. package/dist/table/useDataTableColumns.js +4 -4
  115. package/dist/table/useDataTableColumns.js.map +1 -1
  116. package/dist/table/useDataTableData.d.ts.map +1 -1
  117. package/dist/table/useDataTableData.js +3 -3
  118. package/dist/table/useDataTableData.js.map +1 -1
  119. package/dist/table/useDataTableFilterForm.d.ts.map +1 -1
  120. package/dist/table/useDataTableFilterForm.js +6 -2
  121. package/dist/table/useDataTableFilterForm.js.map +1 -1
  122. package/dist/table/useDataTableFilterVisibility.d.ts +5 -0
  123. package/dist/table/useDataTableFilterVisibility.d.ts.map +1 -1
  124. package/dist/table/useDataTableFilterVisibility.js +16 -8
  125. package/dist/table/useDataTableFilterVisibility.js.map +1 -1
  126. package/dist/table/useDataTableRefresh.d.ts.map +1 -1
  127. package/dist/table/useDataTableRefresh.js +3 -2
  128. package/dist/table/useDataTableRefresh.js.map +1 -1
  129. package/dist/table/useDataTableSummary.d.ts +5 -0
  130. package/dist/table/useDataTableSummary.d.ts.map +1 -1
  131. package/dist/table/useDataTableSummary.js +6 -6
  132. package/dist/table/useDataTableSummary.js.map +1 -1
  133. package/docs/packages-alepha-ui-ai.md +3 -3
  134. package/docs/packages-alepha-ui-i18n-en.md +35 -0
  135. package/docs/packages-alepha-ui-markdown.md +3 -1
  136. package/docs/packages-alepha-ui-overview.md +4 -2
  137. package/docs/packages-alepha-ui-sortable.md +34 -0
  138. package/docs/packages-alepha-ui-table.md +7 -1
  139. package/package.json +21 -3
  140. package/src/admin/AdminJobExecutionSheet.tsx +9 -0
  141. package/src/admin/analytics/RequestDialog.tsx +1 -1
  142. package/src/ai/AiChat.tsx +44 -6
  143. package/src/ai/AiChatConfirmCard.tsx +7 -1
  144. package/src/ai/AiChatFloat.tsx +46 -0
  145. package/src/ai/AiChatMessage.tsx +2 -2
  146. package/src/ai/AiChatPanel.tsx +154 -47
  147. package/src/ai/AiChatToolStepDetails.tsx +42 -0
  148. package/src/ai/AiChatToolTrace.tsx +167 -0
  149. package/src/ai/__tests__/AiChat.browser.spec.tsx +270 -2
  150. package/src/ai/index.ts +4 -2
  151. package/src/core/Button.tsx +26 -1
  152. package/src/core/Dialog.tsx +6 -2
  153. package/src/core/TimeAgo.tsx +3 -4
  154. package/src/core/__tests__/Button.browser.spec.tsx +57 -0
  155. package/src/i18n/en/__tests__/uiEn.spec.ts +110 -0
  156. package/src/i18n/en/index.ts +22 -0
  157. package/src/i18n/en/uiEn.ts +1647 -0
  158. package/src/i18n/fr/uiFr.ts +7 -2
  159. package/src/markdown/MarkdownView.tsx +30 -1
  160. package/src/markdown/__tests__/highlightLines.spec.ts +45 -0
  161. package/src/markdown/highlightLines.ts +120 -0
  162. package/src/markdown/index.ts +14 -2
  163. package/src/shell/ButtonInbox.tsx +11 -1
  164. package/src/shell/PlateLayout.tsx +18 -9
  165. package/src/shell/__tests__/ButtonInbox.browser.spec.tsx +40 -0
  166. package/src/shell/__tests__/PlateLayout.browser.spec.tsx +19 -2
  167. package/src/sortable/__tests__/useSortableList.browser.spec.tsx +157 -0
  168. package/src/sortable/index.ts +22 -0
  169. package/src/sortable/useSortableItem.ts +65 -0
  170. package/src/sortable/useSortableList.ts +231 -0
  171. package/src/table/DataTable.tsx +8 -5
  172. package/src/table/DataTableRowActionGroupItem.tsx +75 -0
  173. package/src/table/DataTableRowActionItem.tsx +6 -0
  174. package/src/table/DataTableRowActionsInline.tsx +3 -1
  175. package/src/table/DataTableRowActionsMenu.tsx +33 -49
  176. package/src/table/__tests__/DataTablePersistenceStorage.browser.spec.tsx +204 -0
  177. package/src/table/__tests__/DataTableRowActionGroup.browser.spec.tsx +118 -1
  178. package/src/table/dataTableBaseProps.ts +16 -2
  179. package/src/table/dataTablePersistence.ts +118 -32
  180. package/src/table/dataTableTypes.ts +20 -3
  181. package/src/table/index.ts +14 -1
  182. package/src/table/useDataTableColumns.ts +9 -4
  183. package/src/table/useDataTableData.ts +8 -3
  184. package/src/table/useDataTableFilterForm.ts +6 -2
  185. package/src/table/useDataTableFilterVisibility.ts +20 -7
  186. package/src/table/useDataTableRefresh.ts +4 -2
  187. package/src/table/useDataTableSummary.ts +25 -8
@@ -0,0 +1,65 @@
1
+ import {
2
+ type UniqueIdentifier,
3
+ useDraggable,
4
+ useDroppable,
5
+ } from "@dnd-kit/core";
6
+ import { CSS } from "@dnd-kit/utilities";
7
+ import type { CSSProperties, PointerEvent } from "react";
8
+
9
+ export interface SortableItem {
10
+ /**
11
+ * The item's element: what moves, and what another item is dropped on.
12
+ */
13
+ ref: (node: HTMLElement | null) => void;
14
+ /**
15
+ * Where the item is while dragged.
16
+ */
17
+ style: CSSProperties;
18
+ /**
19
+ * The drag's start, for the element a press begins on: the item itself,
20
+ * in the capture phase so a control inside it (a menu trigger) cannot
21
+ * swallow the press, or a grip of its own.
22
+ */
23
+ onPointerDown: ((event: PointerEvent<HTMLElement>) => void) | undefined;
24
+ isDragging: boolean;
25
+ /**
26
+ * Another item is held over this one: where a drop lands.
27
+ */
28
+ isOver: boolean;
29
+ }
30
+
31
+ /**
32
+ * One item of a {@link useSortableList}: the element both dragged and dropped
33
+ * on, and only the pointer listener of `@dnd-kit`. The keyboard move is the
34
+ * list's own (`onKeyDown`), on whichever element of the item takes focus.
35
+ */
36
+ export const useSortableItem = (
37
+ id: UniqueIdentifier,
38
+ options: { disabled?: boolean } = {},
39
+ ): SortableItem => {
40
+ const disabled = !!options.disabled;
41
+ const {
42
+ listeners,
43
+ setNodeRef: setDragRef,
44
+ transform,
45
+ isDragging,
46
+ } = useDraggable({ id, disabled });
47
+ const { setNodeRef: setDropRef, isOver } = useDroppable({ id, disabled });
48
+ return {
49
+ ref: (node) => {
50
+ setDragRef(node);
51
+ setDropRef(node);
52
+ },
53
+ style: {
54
+ transform: CSS.Translate.toString(transform),
55
+ zIndex: isDragging ? 10 : undefined,
56
+ },
57
+ onPointerDown: disabled
58
+ ? undefined
59
+ : (listeners?.onPointerDown as
60
+ | ((event: PointerEvent<HTMLElement>) => void)
61
+ | undefined),
62
+ isDragging,
63
+ isOver: isOver && !isDragging,
64
+ };
65
+ };
@@ -0,0 +1,231 @@
1
+ import {
2
+ type DndContextProps,
3
+ type DragEndEvent,
4
+ type Modifier,
5
+ PointerSensor,
6
+ TouchSensor,
7
+ type UniqueIdentifier,
8
+ useSensor,
9
+ useSensors,
10
+ } from "@dnd-kit/core";
11
+ import { type KeyboardEvent, useId, useState } from "react";
12
+
13
+ /**
14
+ * What a sortable list says to a screen reader as an item is moved from the
15
+ * keyboard. The words are the app's, in its own language.
16
+ */
17
+ export interface SortableListAnnouncements {
18
+ picked: (label: string) => string;
19
+ moved: (label: string, position: number, total: number) => string;
20
+ dropped: (label: string) => string;
21
+ cancelled: (label: string) => string;
22
+ }
23
+
24
+ export interface UseSortableListOptions<Id extends UniqueIdentifier> {
25
+ /**
26
+ * The order the app holds, as the server last answered it.
27
+ */
28
+ ids: readonly Id[];
29
+ /**
30
+ * A drop that changed the order: `next` is the whole list as now shown,
31
+ * `previous` the order it replaced, for a save that puts it back on a
32
+ * refusal. The list keeps showing `next` until `ids` changes.
33
+ */
34
+ onReorder: (next: Id[], previous: Id[]) => void;
35
+ /**
36
+ * The item's name, for the announcements.
37
+ */
38
+ labelOf: (id: Id) => string;
39
+ announcements: SortableListAnnouncements;
40
+ /**
41
+ * How far a pointer moves before a press becomes a drag, in pixels, so a
42
+ * plain click stays a click. Default 6.
43
+ */
44
+ activationDistance?: number;
45
+ /**
46
+ * Called as a pointer drag starts: a list of links swallows the click the
47
+ * drop ends with, for one.
48
+ */
49
+ onDragStart?: () => void;
50
+ }
51
+
52
+ export interface SortableList<Id extends UniqueIdentifier> {
53
+ /**
54
+ * The order to draw: the one held after a drop or a keyboard step, until
55
+ * `ids` catches up, else `ids`.
56
+ */
57
+ order: Id[];
58
+ /**
59
+ * Spread on the `DndContext` around the list.
60
+ */
61
+ contextProps: Pick<
62
+ DndContextProps,
63
+ | "id"
64
+ | "sensors"
65
+ | "modifiers"
66
+ | "autoScroll"
67
+ | "onDragStart"
68
+ | "onDragEnd"
69
+ | "onDragCancel"
70
+ >;
71
+ /**
72
+ * The keyboard move, for the item's focusable element: Space picks it up,
73
+ * the arrows move it, Space or Enter drops it and Escape (or Tab) puts it
74
+ * back.
75
+ */
76
+ onKeyDown: (id: Id) => (event: KeyboardEvent<HTMLElement>) => void;
77
+ /**
78
+ * The item held by the keyboard, if any.
79
+ */
80
+ picked: Id | undefined;
81
+ /**
82
+ * True while a pointer drag runs.
83
+ */
84
+ dragging: boolean;
85
+ /**
86
+ * The live region's text: render it in an `aria-live="assertive"` element.
87
+ */
88
+ announcement: string;
89
+ }
90
+
91
+ /**
92
+ * A vertical list reordered by dragging or from the keyboard, on `@dnd-kit`
93
+ * (pointer and touch sensors, and a keyboard move of its own).
94
+ *
95
+ * It holds what every such list needs and nothing of how it looks: the
96
+ * activation distance, a vertical-only modifier that keeps an item inside the
97
+ * list, the drop index, the order held between a drop and the server's
98
+ * answer, and the keyboard move with its screen-reader announcements. Each
99
+ * item uses {@link useSortableItem}; the list draws `order` inside a
100
+ * `DndContext` given `contextProps`.
101
+ *
102
+ * The keyboard move is the list's own rather than `@dnd-kit`'s
103
+ * `KeyboardSensor`: it moves by one place per arrow, inside a list that may
104
+ * scroll, and says where the item is at each step.
105
+ */
106
+ export const useSortableList = <Id extends UniqueIdentifier>(
107
+ options: UseSortableListOptions<Id>,
108
+ ): SortableList<Id> => {
109
+ const dndId = useId();
110
+ const key = options.ids.join("\u0000");
111
+ // The order shown before the app holds it, and the order the app held
112
+ // when it was set: once `ids` moves (the save read back, or the server
113
+ // said otherwise) it hands back to `ids`.
114
+ const [pending, setPending] = useState<
115
+ { order: Id[]; base: string } | undefined
116
+ >();
117
+ const [picked, setPicked] = useState<{ id: Id; before: Id[] } | undefined>();
118
+ const [dragging, setDragging] = useState(false);
119
+ const [announcement, setAnnouncement] = useState("");
120
+ const sensors = useSensors(
121
+ useSensor(PointerSensor, {
122
+ activationConstraint: { distance: options.activationDistance ?? 6 },
123
+ }),
124
+ useSensor(TouchSensor, {
125
+ activationConstraint: { delay: 200, tolerance: 6 },
126
+ }),
127
+ );
128
+
129
+ // Adjusted during render, React's "adjust state when a prop changes": the
130
+ // held order never outlives the answer, and no effect runs a second pass.
131
+ if (pending && !picked && pending.base !== key) {
132
+ setPending(undefined);
133
+ }
134
+ const order = pending ? pending.order : [...options.ids];
135
+
136
+ const move = (list: Id[], from: number, to: number): Id[] => {
137
+ const next = [...list];
138
+ next.splice(to, 0, ...next.splice(from, 1));
139
+ return next;
140
+ };
141
+
142
+ const save = (next: Id[], previous: Id[]) => {
143
+ setPending({ order: next, base: key });
144
+ options.onReorder(next, previous);
145
+ };
146
+
147
+ // One column: an item moves up and down it, never sideways, and never
148
+ // past its ends.
149
+ const vertical: Modifier = ({
150
+ transform,
151
+ draggingNodeRect,
152
+ containerNodeRect,
153
+ }) => {
154
+ let y = transform.y;
155
+ if (draggingNodeRect && containerNodeRect) {
156
+ y = Math.min(
157
+ Math.max(y, containerNodeRect.top - draggingNodeRect.top),
158
+ containerNodeRect.bottom - draggingNodeRect.bottom,
159
+ );
160
+ }
161
+ return { ...transform, x: 0, y };
162
+ };
163
+
164
+ const onDragEnd = (event: DragEndEvent) => {
165
+ setDragging(false);
166
+ const from = order.findIndex((id) => id === event.active.id);
167
+ const to = event.over ? order.findIndex((id) => id === event.over!.id) : -1;
168
+ if (from < 0 || to < 0 || from === to) return;
169
+ save(move(order, from, to), order);
170
+ };
171
+
172
+ const onKeyDown = (id: Id) => (event: KeyboardEvent<HTMLElement>) => {
173
+ const label = options.labelOf(id);
174
+ const held = picked?.id === id;
175
+ if (event.key === " " && !held) {
176
+ event.preventDefault();
177
+ setPicked({ id, before: order });
178
+ setAnnouncement(options.announcements.picked(label));
179
+ return;
180
+ }
181
+ if (!held) return;
182
+ if (event.key === "ArrowUp" || event.key === "ArrowDown") {
183
+ event.preventDefault();
184
+ const from = order.indexOf(id);
185
+ const to = from + (event.key === "ArrowUp" ? -1 : 1);
186
+ if (to < 0 || to >= order.length) return;
187
+ // Drawn now, saved on the drop.
188
+ setPending({ order: move(order, from, to), base: key });
189
+ setAnnouncement(options.announcements.moved(label, to + 1, order.length));
190
+ return;
191
+ }
192
+ if (event.key === " " || event.key === "Enter") {
193
+ event.preventDefault();
194
+ setPicked(undefined);
195
+ setAnnouncement(options.announcements.dropped(label));
196
+ if (order.join("\u0000") !== picked.before.join("\u0000")) {
197
+ save(order, picked.before);
198
+ } else {
199
+ setPending(undefined);
200
+ }
201
+ return;
202
+ }
203
+ if (event.key === "Escape" || event.key === "Tab") {
204
+ if (event.key === "Escape") event.preventDefault();
205
+ setPending(undefined);
206
+ setPicked(undefined);
207
+ setAnnouncement(options.announcements.cancelled(label));
208
+ }
209
+ };
210
+
211
+ return {
212
+ order,
213
+ contextProps: {
214
+ id: dndId,
215
+ sensors,
216
+ modifiers: [vertical],
217
+ // Vertical only: the column has nothing to scroll sideways.
218
+ autoScroll: { threshold: { x: 0, y: 0.2 } },
219
+ onDragStart: () => {
220
+ setDragging(true);
221
+ options.onDragStart?.();
222
+ },
223
+ onDragEnd,
224
+ onDragCancel: () => setDragging(false),
225
+ },
226
+ onKeyDown,
227
+ picked: picked?.id,
228
+ dragging,
229
+ announcement,
230
+ };
231
+ };
@@ -111,7 +111,7 @@ export const DataTable = <
111
111
  // reader had no way to see more rows than the call site had decided for
112
112
  // them. Already in `load`'s dependency array, so changing it refetches.
113
113
  const [size, setSize] = useState<number>(() =>
114
- persistedSize(sizeKey, props.defaultSize),
114
+ persistedSize(sizeKey, props.defaultSize, props.persistenceStorage),
115
115
  );
116
116
  const alepha = useAlepha();
117
117
  const { tr } = useI18n();
@@ -159,6 +159,7 @@ export const DataTable = <
159
159
  const filterVisibility = useDataTableFilterVisibility({
160
160
  definition: filterDefinition,
161
161
  filtersKey,
162
+ persistenceStorage: props.persistenceStorage,
162
163
  });
163
164
 
164
165
  // The filters that sit in a column's header, by column: the first field
@@ -276,6 +277,7 @@ export const DataTable = <
276
277
  const summary = useDataTableSummary({
277
278
  summary: untyped.summary,
278
279
  persistenceKey: props.persistenceKey,
280
+ persistenceStorage: props.persistenceStorage,
279
281
  refreshKey,
280
282
  form,
281
283
  alepha,
@@ -441,13 +443,14 @@ export const DataTable = <
441
443
  if (scopeRef.current !== props.persistenceKey) {
442
444
  scopeRef.current = props.persistenceKey;
443
445
  setPage(0);
444
- setSize(persistedSize(sizeKey, props.defaultSize));
445
- setSort(persistedSort(sortKey, props.defaultSort));
446
- setVisibleColumns(persistedColumns(columnsKey, props.columns));
446
+ const storage = props.persistenceStorage;
447
+ setSize(persistedSize(sizeKey, props.defaultSize, storage));
448
+ setSort(persistedSort(sortKey, props.defaultSort, storage));
449
+ setVisibleColumns(persistedColumns(columnsKey, props.columns, storage));
447
450
  // Same render pass as the rest, and for the identical reason: the effects
448
451
  // keyed on `persistenceKey` fire in one flush, so an order left behind
449
452
  // here would be written back under the INCOMING key.
450
- setColumnOrder(persistedOrder(columnsKey, props.columns));
453
+ setColumnOrder(persistedOrder(columnsKey, props.columns, storage));
451
454
  // Which filters are on the bar is the scope's too, and read here for the
452
455
  // same reason: the project just opened must not show the bar of the one
453
456
  // just left.
@@ -0,0 +1,75 @@
1
+ import {
2
+ DropdownMenuSub,
3
+ DropdownMenuSubContent,
4
+ DropdownMenuSubTrigger,
5
+ } from "../core/DropdownMenu.tsx";
6
+ import { DataTableRowActionItem } from "./DataTableRowActionItem.tsx";
7
+ import type {
8
+ RowActionContext,
9
+ RowActionEntry,
10
+ RowActionGroup,
11
+ } from "./dataTableTypes.ts";
12
+
13
+ export interface DataTableRowActionGroupItemProps<T> {
14
+ group: RowActionGroup<T>;
15
+ item: T;
16
+ ctx: RowActionContext;
17
+ }
18
+
19
+ /**
20
+ * A row action group as a submenu: its trigger, then its children, each an
21
+ * action or a group of its own, drawn the same way one level further in.
22
+ * An empty child group is left out, as the row menu leaves out an empty
23
+ * group.
24
+ */
25
+ export const DataTableRowActionGroupItem = <T,>(
26
+ props: DataTableRowActionGroupItemProps<T>,
27
+ ) => {
28
+ const Icon = props.group.icon;
29
+ return (
30
+ <DropdownMenuSub>
31
+ <DropdownMenuSubTrigger>
32
+ {Icon && <Icon className="me-2 size-4" />}
33
+ {props.group.label}
34
+ </DropdownMenuSubTrigger>
35
+ <DropdownMenuSubContent>
36
+ {props.group.children
37
+ .filter(hasRowAction)
38
+ .map((child) =>
39
+ isRowActionGroup(child) ? (
40
+ <DataTableRowActionGroupItem
41
+ key={child.label}
42
+ group={child}
43
+ item={props.item}
44
+ ctx={props.ctx}
45
+ />
46
+ ) : (
47
+ <DataTableRowActionItem
48
+ key={child.label}
49
+ action={child}
50
+ item={props.item}
51
+ ctx={props.ctx}
52
+ />
53
+ ),
54
+ )}
55
+ </DropdownMenuSubContent>
56
+ </DropdownMenuSub>
57
+ );
58
+ };
59
+
60
+ /**
61
+ * Whether an entry is a group rather than an action: it has `children`.
62
+ */
63
+ export function isRowActionGroup<T>(
64
+ entry: RowActionEntry<T>,
65
+ ): entry is RowActionGroup<T> {
66
+ return "children" in entry;
67
+ }
68
+
69
+ /**
70
+ * Whether an entry holds anything to click: an action does, a group does
71
+ * when one of its children does, at any depth.
72
+ */
73
+ export function hasRowAction<T>(entry: RowActionEntry<T>): boolean {
74
+ return isRowActionGroup(entry) ? entry.children.some(hasRowAction) : true;
75
+ }
@@ -21,6 +21,10 @@ export const DataTableRowActionItem = <T,>(
21
21
  const { action, item, ctx } = props;
22
22
  const Icon = action.icon;
23
23
  const disabled = action.disabled?.(item);
24
+ const hint = action.hint?.(item);
25
+ const note = hint ? (
26
+ <span className="text-muted-foreground ms-auto ps-3 text-xs">{hint}</span>
27
+ ) : null;
24
28
  if (action.checked) {
25
29
  return (
26
30
  <DropdownMenuCheckboxItem
@@ -35,6 +39,7 @@ export const DataTableRowActionItem = <T,>(
35
39
  >
36
40
  {Icon && <Icon className="me-2 size-4" />}
37
41
  {action.label}
42
+ {note}
38
43
  </DropdownMenuCheckboxItem>
39
44
  );
40
45
  }
@@ -46,6 +51,7 @@ export const DataTableRowActionItem = <T,>(
46
51
  >
47
52
  {Icon && <Icon className="me-2 size-4" />}
48
53
  {action.label}
54
+ {note}
49
55
  </DropdownMenuItem>
50
56
  );
51
57
  };
@@ -5,6 +5,7 @@ import {
5
5
  TooltipProvider,
6
6
  TooltipTrigger,
7
7
  } from "../core/Tooltip.tsx";
8
+ import { hasRowAction } from "./DataTableRowActionGroupItem.tsx";
8
9
  import { DataTableRowActionsMenu } from "./DataTableRowActionsMenu.tsx";
9
10
  import type {
10
11
  RowAction,
@@ -35,7 +36,8 @@ export const DataTableRowActionsInline = <T,>(
35
36
  (entry): entry is RowAction<T> => !("children" in entry),
36
37
  );
37
38
  const groups = props.actions.filter(
38
- (entry): entry is RowActionGroup<T> => "children" in entry,
39
+ (entry): entry is RowActionGroup<T> =>
40
+ "children" in entry && hasRowAction(entry),
39
41
  );
40
42
  if (actions.length === 0 && groups.length === 0) return null;
41
43
  return (
@@ -6,17 +6,15 @@ import {
6
6
  DropdownMenu,
7
7
  DropdownMenuContent,
8
8
  DropdownMenuSeparator,
9
- DropdownMenuSub,
10
- DropdownMenuSubContent,
11
- DropdownMenuSubTrigger,
12
9
  DropdownMenuTrigger,
13
10
  } from "../core/DropdownMenu.tsx";
11
+ import {
12
+ DataTableRowActionGroupItem,
13
+ hasRowAction,
14
+ isRowActionGroup,
15
+ } from "./DataTableRowActionGroupItem.tsx";
14
16
  import { DataTableRowActionItem } from "./DataTableRowActionItem.tsx";
15
- import type {
16
- RowActionContext,
17
- RowActionEntry,
18
- RowActionGroup,
19
- } from "./dataTableTypes.ts";
17
+ import type { RowActionContext, RowActionEntry } from "./dataTableTypes.ts";
20
18
 
21
19
  export interface DataTableRowActionsMenuProps<T> {
22
20
  actions: RowActionEntry<T>[];
@@ -25,8 +23,9 @@ export interface DataTableRowActionsMenuProps<T> {
25
23
  }
26
24
 
27
25
  /**
28
- * The three-dots menu at the end of a row, with one level of submenus for
29
- * groups. Renders nothing when no entry survives.
26
+ * The three-dots menu at the end of a row, a group drawn as a submenu (and
27
+ * a group inside it as a submenu of that). Renders nothing when no entry
28
+ * survives.
30
29
  */
31
30
  export const DataTableRowActionsMenu = <T,>(
32
31
  props: DataTableRowActionsMenuProps<T>,
@@ -35,9 +34,7 @@ export const DataTableRowActionsMenu = <T,>(
35
34
  // ⚠️ Effective entries, not entries: a group is one entry however many
36
35
  // children it has, so a lone empty group would otherwise render the
37
36
  // three-dots trigger over an empty menu.
38
- const effective = props.actions.filter((action) =>
39
- isRowActionGroup(action) ? action.children.length > 0 : true,
40
- );
37
+ const effective = props.actions.filter(hasRowAction);
41
38
  if (effective.length === 0) return null;
42
39
  return (
43
40
  <DropdownMenu>
@@ -56,42 +53,35 @@ export const DataTableRowActionsMenu = <T,>(
56
53
  </DropdownMenuTrigger>
57
54
  <DropdownMenuContent align="end">
58
55
  {effective.map((action, idx) => {
59
- const Icon = action.icon;
60
- if (isRowActionGroup(action)) {
61
- return (
62
- <DropdownMenuSub key={action.label}>
63
- <DropdownMenuSubTrigger>
64
- {Icon && <Icon className="me-2 size-4" />}
65
- {action.label}
66
- </DropdownMenuSubTrigger>
67
- <DropdownMenuSubContent>
68
- {action.children.map((child) => (
69
- <DataTableRowActionItem
70
- key={child.label}
71
- action={child}
72
- item={props.item}
73
- ctx={props.ctx}
74
- />
75
- ))}
76
- </DropdownMenuSubContent>
77
- </DropdownMenuSub>
78
- );
79
- }
80
- // A group is never destructive, so the previous entry being one
81
- // reads as falsy here and the separator rule needs no case for it.
56
+ // A separator above an entry when the one before asked for it
57
+ // (`separatorAfter`), or above the first of a run of destructive
58
+ // entries. A group is never destructive, so the previous entry
59
+ // being one reads as falsy here and the rule needs no case for it.
82
60
  const previous = effective[idx - 1];
61
+ const previousAction =
62
+ previous && !isRowActionGroup(previous) ? previous : undefined;
83
63
  const sep =
84
64
  idx > 0 &&
85
- action.destructive &&
86
- !(previous && !isRowActionGroup(previous) && previous.destructive);
65
+ (!!previousAction?.separatorAfter ||
66
+ (!isRowActionGroup(action) &&
67
+ !!action.destructive &&
68
+ !previousAction?.destructive));
87
69
  return (
88
70
  <span key={action.label}>
89
71
  {sep && <DropdownMenuSeparator />}
90
- <DataTableRowActionItem
91
- action={action}
92
- item={props.item}
93
- ctx={props.ctx}
94
- />
72
+ {isRowActionGroup(action) ? (
73
+ <DataTableRowActionGroupItem
74
+ group={action}
75
+ item={props.item}
76
+ ctx={props.ctx}
77
+ />
78
+ ) : (
79
+ <DataTableRowActionItem
80
+ action={action}
81
+ item={props.item}
82
+ ctx={props.ctx}
83
+ />
84
+ )}
95
85
  </span>
96
86
  );
97
87
  })}
@@ -99,9 +89,3 @@ export const DataTableRowActionsMenu = <T,>(
99
89
  </DropdownMenu>
100
90
  );
101
91
  };
102
-
103
- function isRowActionGroup<T>(
104
- entry: RowActionEntry<T>,
105
- ): entry is RowActionGroup<T> {
106
- return "children" in entry;
107
- }