@jsudc/react 0.7.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +113 -22
  2. package/dist/actions/RowActionsMenu.d.ts +14 -5
  3. package/dist/actions/RowActionsMenu.js +66 -17
  4. package/dist/actions/RowActionsMenu.js.map +1 -1
  5. package/dist/actions/row.d.ts +50 -5
  6. package/dist/actions/row.js +41 -3
  7. package/dist/actions/row.js.map +1 -1
  8. package/dist/actions/rowIcon.d.ts +4 -0
  9. package/dist/actions/rowIcon.js +13 -0
  10. package/dist/actions/rowIcon.js.map +1 -0
  11. package/dist/actions/useCanHover.d.ts +11 -0
  12. package/dist/actions/useCanHover.js +37 -0
  13. package/dist/actions/useCanHover.js.map +1 -0
  14. package/dist/actions/useRowActionRunner.d.ts +3 -1
  15. package/dist/actions/useRowActionRunner.js +9 -3
  16. package/dist/actions/useRowActionRunner.js.map +1 -1
  17. package/dist/data-view/BulkBar.js +1 -1
  18. package/dist/data-view/FilePreview.js +1 -1
  19. package/dist/data-view/UdcDataView.js +2 -1
  20. package/dist/data-view/UdcDataView.js.map +1 -1
  21. package/dist/headless.d.ts +1 -0
  22. package/dist/headless.js +6 -5
  23. package/dist/index.d.ts +3 -2
  24. package/dist/index.js +6 -5
  25. package/dist/kanban/KanbanRenderer.js +1 -1
  26. package/dist/lookup/LookupValue.d.ts +7 -1
  27. package/dist/lookup/LookupValue.js +59 -10
  28. package/dist/lookup/LookupValue.js.map +1 -1
  29. package/dist/lookup/label.d.ts +7 -0
  30. package/dist/lookup/label.js +14 -1
  31. package/dist/lookup/label.js.map +1 -1
  32. package/dist/lookup/links.d.ts +12 -4
  33. package/dist/lookup/links.js +4 -1
  34. package/dist/lookup/links.js.map +1 -1
  35. package/dist/react-router/UdcReactRouterUrlState.d.ts +3 -2
  36. package/dist/react-router/UdcReactRouterUrlState.js +3 -1
  37. package/dist/react-router/UdcReactRouterUrlState.js.map +1 -1
  38. package/dist/styles.css +1 -1
  39. package/dist/styles.scoped.css +1 -1
  40. package/dist/table/TableRenderer.js +37 -10
  41. package/dist/table/TableRenderer.js.map +1 -1
  42. package/dist/table/cells.js +2 -12
  43. package/dist/table/cells.js.map +1 -1
  44. package/dist/table/format.d.ts +4 -0
  45. package/dist/table/format.js +12 -1
  46. package/dist/table/format.js.map +1 -1
  47. package/dist/tree/TreeRenderer.js +1 -1
  48. package/dist/udc/hooks.d.ts +24 -6
  49. package/package.json +3 -3
package/README.md CHANGED
@@ -41,7 +41,7 @@ npm install @jsudc/react @jsudc/core \
41
41
  # then the peers of the renderers you register (see Renderers), all of them:
42
42
  npm install @tanstack/react-table leaflet recharts @dnd-kit/core @dnd-kit/sortable @dnd-kit/utilities
43
43
  # or straight from a GitHub tag:
44
- npm install github:digital-cube/jsudc-core#v0.7.0 github:digital-cube/jsudc-react#v0.7.0
44
+ npm install github:digital-cube/jsudc-core#v0.8.1 github:digital-cube/jsudc-react#v0.8.1
45
45
  ```
46
46
 
47
47
  ## Quick start
@@ -1122,14 +1122,46 @@ shows nothing.
1122
1122
  alternatives (only the widest), so it does not jump as rows change.
1123
1123
  - `menu`: one "more" button per row opening a dropdown, and the same menu on
1124
1124
  right-click anywhere on the row.
1125
+ - `hover` (0.8.1; the mail-list pattern): at rest the row shows no action
1126
+ column, so the last column sits at the right edge. While the pointer is over
1127
+ the row, while the focus is inside it, and while its menu is open or one of
1128
+ its actions runs, a compact bar of round icon buttons appears over the row's
1129
+ trailing cells, stuck to the pane's right edge when the table scrolls
1130
+ sideways and above right-pinned columns. It wears the row's background
1131
+ (hovered, selected, or its `row_color` tone) with a short fade at its left
1132
+ edge, so the text under it is covered; the row's height and the column
1133
+ layout are exactly those of the same view without row actions. Each button
1134
+ has a round highlight on hover and focus, its name in a tooltip and as its
1135
+ accessible name; `variant: destructive` and the kind `delete` keep the
1136
+ danger colours. A hidden bar takes no pointer but stays in the Tab order,
1137
+ and tabbing into it shows it. Right-click on the row and the menu key open
1138
+ the full menu (every eligible action).
1139
+
1140
+ Which actions are buttons: in declared order, each eligible action that has
1141
+ an icon (a known `icon`, or the kind `delete`) and is not `placement: menu`,
1142
+ up to `row_actions_max` (default 4). Every other eligible action (no icon,
1143
+ `placement: menu`, past the cap) goes to a round "more" (⋮) button at the
1144
+ end of the bar; with nothing left over there is no ⋮. While an action runs,
1145
+ its button (the ⋮ for one from the dropdown) shows a spinner and the others
1146
+ are disabled. `placement` and `row_actions_max` are read for `hover` only:
1147
+ `inline`, `menu` and the bulk bar ignore them.
1148
+
1149
+ On a device that cannot hover (`@media (hover: none)`, a touch screen),
1150
+ `hover` draws exactly as `menu`: the 40 px column with an always visible ⋮.
1151
+ **It needs `@jsudc/core` 0.8.1 on the server and in the client**: up to
1152
+ 0.8.0 `row_actions_display` is a strict `inline | menu` enum on both sides
1153
+ (the server reads `view.yaml` with it, the client parses the `describe`
1154
+ answer with it), so an older core refuses a view that says `hover` at load,
1155
+ with no fallback. `placement` and `row_actions_max` pass an older core
1156
+ untouched.
1125
1157
 
1126
1158
  The cards draw the same actions as a "more" menu on each card (right-click
1127
- opens it too), whatever the display. Kanban, tree, calendar, map and chart
1128
- draw no row actions.
1159
+ opens it too), whatever the display, `hover` included. Kanban, tree,
1160
+ calendar, map and chart draw no row actions.
1129
1161
 
1130
1162
  **The keyboard.** With row activation on, the focused row opens its menu from
1131
- the context-menu key, Shift+F10 or `.` (`isRowMenuKey`); in the inline
1132
- display the keys open the same actions as a menu. Arrow keys move in the
1163
+ the context-menu key, Shift+F10 or `.` (`isRowMenuKey`); in the inline and
1164
+ hover displays the keys open the same actions as a menu (all of them). Arrow keys move in the
1133
1165
  menu, Enter runs, Escape closes, and the focus goes back to the row. Opened
1134
1166
  from the "more" button, the focus goes back to that button.
1135
1167
 
@@ -1158,24 +1190,41 @@ is shown as a toast. A row action names its button with the term
1158
1190
  `ACTION_<KIND>` of the collection's section, else `ACTIONS.<kind>`, else the
1159
1191
  def's `label`, else the kind made readable.
1160
1192
 
1161
- A mailbox whose rows mark themselves read through a patch and archive through
1162
- the host's own endpoint, each hidden where it does not apply:
1193
+ A mailbox drawn the way a webmail draws it: the actions appear over the row
1194
+ under the pointer. Its rows mark themselves read or unread through a patch
1195
+ and archive through the host's own endpoint, each hidden where it does not
1196
+ apply:
1163
1197
 
1164
1198
  ```yaml
1165
1199
  # The view of `messages`
1166
1200
  view:
1167
- columns: [{ field: subject }, { field: from }, { field: received_at }]
1168
- row_actions_display: inline # or `menu`
1201
+ columns: [{ field: from }, { field: subject }, { field: received_at }]
1202
+ row_actions_display: hover # or `inline`, `menu`
1203
+ row_actions_max: 4 # the default
1169
1204
  row_action_defs:
1205
+ - kind: archive
1206
+ label: Archive
1207
+ icon: lucide:archive
1208
+ when: { field: folder, op: neq, value: archive }
1209
+ - kind: delete # the bin icon and the danger colours; asks first
1210
+ # A toggle is two defs with opposite `when`s: a row shows one of them.
1170
1211
  - kind: mark_read
1171
1212
  label: Mark read
1172
1213
  icon: lucide:mail-open
1173
1214
  set: { read: true } # no handler needed: an optimistic update
1174
1215
  when: { field: read, op: eq, value: false }
1175
- - kind: archive
1176
- label: Archive
1177
- icon: lucide:archive
1178
- when: { field: folder, op: neq, value: archive }
1216
+ - kind: mark_unread
1217
+ label: Mark unread
1218
+ icon: lucide:mail
1219
+ set: { read: false }
1220
+ when: { field: read, op: eq, value: true }
1221
+ - kind: snooze # no icon: in the ⋮ dropdown
1222
+ label: Snooze
1223
+ action: mail.snooze
1224
+ - kind: move
1225
+ label: Move to…
1226
+ icon: lucide:folder-input
1227
+ placement: menu # always in the ⋮ dropdown
1179
1228
  ```
1180
1229
 
1181
1230
  ```tsx
@@ -1204,19 +1253,26 @@ export function Inbox() {
1204
1253
  }
1205
1254
  ```
1206
1255
 
1207
- An unread message in the inbox shows both; a read one only "Archive"; a read
1208
- one already archived, none. Clicking "Mark read" shows the row read at once (and so
1209
- "Mark read" goes from it); clicking the row itself still opens the message.
1256
+ Hovering an unread message in the inbox shows Archive, Delete and Mark read
1257
+ as buttons and a ⋮ with Snooze and Move to…; a read one shows Mark unread in
1258
+ place of Mark read; an archived one, Delete and the toggle. Clicking "Mark
1259
+ read" shows the row read at once, and the button under the pointer becomes
1260
+ "Mark unread"; clicking the row itself still opens the message.
1210
1261
 
1211
1262
  **In a host renderer.** `RendererProps.rowActions` (a `RowActions`, set when
1212
1263
  the view declares row actions) carries `display`, `defs` (every declared
1213
- action, before `when`), `eligible(row)`, `label(def)`, `run(def, row)` (the
1264
+ action, before `when`), `eligible(row)`, `split(row)` (for `hover`: `{ bar,
1265
+ overflow }`, the bar's buttons and the ⋮ dropdown's rest), `label(def)`, `run(def, row)` (the
1214
1266
  path above; it shows its errors and does not reject) and `runningOn(id)`
1215
1267
  (the kind running on that row, else `null`). `RowActionsControls` with
1216
- `useRowMenu()` draws the built-in buttons and menu; `rowMenuHandlers` gives a
1268
+ `useRowMenu()` draws the built-in buttons and menu (its `display` takes
1269
+ `hover` too: the bar, shown while an ancestor marked `udc:group/row` is
1270
+ hovered or holds the focus, positioned by your `className`); `rowMenuHandlers` gives a
1217
1271
  row element its menu key and right-click. The headless parts —
1218
- `rowActionDefs(view)`, `rowActionsDisplay(view)`, `eligibleRowActions(defs,
1219
- row)`, `isRowMenuKey(e)` — are in `@jsudc/react/headless`. A UI kit's
1272
+ `rowActionDefs(view)`, `rowActionsDisplay(view)`, `rowActionsMax(view)`,
1273
+ `eligibleRowActions(defs, row)`, `splitRowActions(eligible, { hasIcon, max })`,
1274
+ `isRowMenuKey(e)`, and `useCanHover()` with `effectiveRowActionsDisplay`
1275
+ (`hover` becomes `menu` on touch) — are in `@jsudc/react/headless`. A UI kit's
1220
1276
  `DropdownMenu` may take the optional `open` / `onOpenChange` and its content
1221
1277
  `onCloseAutoFocus` (the default kit does); a kit that ignores them still
1222
1278
  opens the menu from its trigger, but not from the keys or a right-click.
@@ -1465,7 +1521,7 @@ peer while the default kit is the fallback.
1465
1521
  Everything the components import that a host is likely to have too is a peer,
1466
1522
  so there is one copy of it in the bundle:
1467
1523
 
1468
- - `@jsudc/core` ^0.7.0 — one copy of the protocol, shared with the host's
1524
+ - `@jsudc/core` ^0.8.1 — one copy of the protocol, shared with the host's
1469
1525
  own `UdcClient`;
1470
1526
  - `react`, `react-dom` ^19 — one React, or hooks break;
1471
1527
  - `@tanstack/react-query` ^5 — one `QueryClient` context, shared with the
@@ -1767,6 +1823,39 @@ only stores and filters keys.
1767
1823
  is a `lookup_array`. In an `editable` cell a plain click on a label stays in
1768
1824
  the cell (double-click edits) and Cmd / Ctrl-click opens the target. A filter
1769
1825
  pill on a lookup field shows the labels too.
1826
+ - **Coloured chips.** With `lookup.color_field` (`@jsudc/core` 0.8.0) each
1827
+ chip of a `lookup_array` takes the colour of its target row: the value of that
1828
+ field, a named palette value, is the chip's `data-color`. A tone of the
1829
+ palette (`accent`, `success`, `warning`, `danger`, `info`, `muted`,
1830
+ `default`) draws as that tone's badge, in both themes. Any other name is the
1831
+ host's to map, through two variables on the chip (class `udc-lookup-chip`):
1832
+
1833
+ ```css
1834
+ .udc-lookup-chip[data-color="red"] { --udc-chip-bg: oklch(0.95 0.04 25); --udc-chip-fg: oklch(0.5 0.19 25); }
1835
+ .dark .udc-lookup-chip[data-color="red"] { --udc-chip-bg: oklch(0.32 0.08 25); --udc-chip-fg: oklch(0.85 0.09 25); }
1836
+ ```
1837
+
1838
+ A name the host does not map, and a row with no value there, draw the
1839
+ default chip. A single `lookup` stays a plain link.
1840
+ - **Chip size.** A long chip ends in "…" inside its rounded box. The chip is
1841
+ at most `--udc-chip-max-width` wide (default `12em`); when the chips do not
1842
+ fit in the cell, the first keep their width and the last visible one
1843
+ shrinks, down to `--udc-chip-min-width` (default `2.5rem`). The text is
1844
+ `--udc-chip-font-weight` (default `500`) at `--udc-chip-font-size` (default
1845
+ `11px`):
1846
+
1847
+ ```css
1848
+ .udc-lookup-chip { --udc-chip-max-width: 10em; --udc-chip-font-weight: 600; --udc-chip-font-size: 11.5px; }
1849
+ ```
1850
+ - **Chips that are not links.** A host with no view of the target collection
1851
+ (one embedded table, no `/c/<target>`) returns `null` from `UdcLinks.href`
1852
+ (or `collectionPath`) for it: the chips and labels of that lookup are then
1853
+ plain text, and a click on one is the row's (`onRowActivate`, `row_link`).
1854
+ A `row_link` to such a collection does nothing.
1855
+
1856
+ ```tsx
1857
+ <UdcProvider client={client} links={{ href: () => null, navigate: () => {} }}>…</UdcProvider>
1858
+ ```
1770
1859
  - **One call per lookup field**, not per cell: the table (and the kanban
1771
1860
  board) resolve the keys of the rows on screen with `useLookupBatch` and hand
1772
1861
  them down through `<UdcLookupBatch>`. A `LookupValue` outside a batch
@@ -1804,7 +1893,9 @@ where a collection's view is mounted. Under react-router:
1804
1893
 
1805
1894
  Otherwise pass `links={{ href, navigate }}` to `UdcProvider` (`UdcLinks`).
1806
1895
  Without either, links go to `/c/<collection>` and are followed with
1807
- `history.pushState` and a `popstate` event (`defaultUdcLinks`).
1896
+ `history.pushState` and a `popstate` event (`defaultUdcLinks`). An `href` (or
1897
+ `collectionPath`) that returns `null` says the app has no view of that
1898
+ collection: its lookups are plain text and a `row_link` to it does nothing.
1808
1899
 
1809
1900
  ## API
1810
1901
 
@@ -1,6 +1,6 @@
1
1
  import type { Row } from "@jsudc/core";
2
2
  import { type KeyboardEvent, type MouseEvent } from "react";
3
- import { type RowActions } from "./row.js";
3
+ import { type RowActions, type RowActionsDisplay } from "./row.js";
4
4
  /** How a row's menu was opened: what decides where the focus goes when it closes. */
5
5
  export type RowMenuVia = "trigger" | "key" | "context";
6
6
  export interface RowMenuState {
@@ -28,18 +28,27 @@ export declare function rowMenuHandlers(rowActions: RowActions | undefined, menu
28
28
  * The trailing column's width, from every declared action (not one row's
29
29
  * eligible subset, so the column does not jump as rows change). As in
30
30
  * udc-js, actions with a `when` count as alternatives: only the widest.
31
+ * `hover` takes no width (its bar lies over the row's trailing cells);
32
+ * `display` is what the renderer draws, the view's display by default.
31
33
  */
32
- export declare function rowActionsColumnWidth(rowActions: RowActions): number;
34
+ export declare function rowActionsColumnWidth(rowActions: RowActions, display?: RowActionsDisplay): number;
33
35
  export interface RowActionsControlsProps {
34
36
  row: Row;
35
37
  rowActions: RowActions;
36
38
  menu: RowMenuState;
37
- /** `menu`: one "more" button whatever the view says (the cards). Default: `rowActions.display`. */
38
- display?: "inline" | "menu";
39
+ /**
40
+ * `menu`: one "more" button whatever the view says (the cards). Default:
41
+ * `rowActions.display`. `hover` (0.8.1) draws the bar: shown while an
42
+ * ancestor marked `udc:group/row` is hovered, while the focus is inside
43
+ * and while the menu is open or an action runs; on a device that cannot
44
+ * hover it draws as `menu`. Position it with `className` (the table lays
45
+ * it over the row's trailing cells).
46
+ */
47
+ display?: RowActionsDisplay;
39
48
  className?: string;
40
49
  }
41
50
  /**
42
51
  * One row's actions. A click, a key or a right-click inside never reaches the
43
52
  * row: it neither activates it, nor follows its `row_link`, nor selects it.
44
53
  */
45
- export declare function RowActionsControls({ row, rowActions, menu, display, className, }: RowActionsControlsProps): import("react").JSX.Element | null;
54
+ export declare function RowActionsControls({ row, rowActions, menu, display: asked, className, }: RowActionsControlsProps): import("react").JSX.Element | null;
@@ -1,11 +1,12 @@
1
- import { actionIcon } from "../data-view/BulkBar.js";
2
1
  import { useI18n } from "../i18n/i18n.js";
3
2
  import { cn } from "../lib/utils.js";
4
3
  import { ownsKeys } from "../rows/useRowActivation.js";
5
4
  import { useUiKit } from "../ui-kit/context.js";
6
5
  import { isRowMenuKey } from "./row.js";
6
+ import { rowActionHasIcon, rowActionIcon } from "./rowIcon.js";
7
+ import { effectiveRowActionsDisplay, useCanHover } from "./useCanHover.js";
7
8
  import { useCallback, useRef, useState } from "react";
8
- import { EllipsisVertical, Trash2 } from "lucide-react";
9
+ import { EllipsisVertical } from "lucide-react";
9
10
  import { jsx, jsxs } from "react/jsx-runtime";
10
11
  // src/actions/RowActionsMenu.tsx
11
12
  /** Which row's actions menu is open: one per list. */
@@ -54,41 +55,46 @@ var MENU_COLUMN = 40;
54
55
  * The trailing column's width, from every declared action (not one row's
55
56
  * eligible subset, so the column does not jump as rows change). As in
56
57
  * udc-js, actions with a `when` count as alternatives: only the widest.
58
+ * `hover` takes no width (its bar lies over the row's trailing cells);
59
+ * `display` is what the renderer draws, the view's display by default.
57
60
  */
58
- function rowActionsColumnWidth(rowActions) {
59
- if (rowActions.display === "menu") return MENU_COLUMN;
60
- const widthOf = (def) => hasIcon(def) ? ICON_BUTTON : Math.ceil(rowActions.label(def).length * LABEL_CHAR) + LABEL_PADDING;
61
+ function rowActionsColumnWidth(rowActions, display = rowActions.display) {
62
+ if (display === "hover") return 0;
63
+ if (display === "menu") return MENU_COLUMN;
64
+ const widthOf = (def) => rowActionHasIcon(def) ? ICON_BUTTON : Math.ceil(rowActions.label(def).length * LABEL_CHAR) + LABEL_PADDING;
61
65
  const always = rowActions.defs.filter((d) => d.when === void 0);
62
66
  const alternatives = rowActions.defs.filter((d) => d.when !== void 0);
63
67
  const buttons = always.reduce((sum, d) => sum + widthOf(d) + 2, 0) + (alternatives.length > 0 ? Math.max(...alternatives.map(widthOf)) + 2 : 0);
64
68
  return Math.max(MENU_COLUMN, buttons + CELL_PADDING);
65
69
  }
66
- function iconOf(def) {
67
- return actionIcon(def.icon) ?? (def.kind === "delete" ? Trash2 : null);
68
- }
69
- function hasIcon(def) {
70
- return iconOf(def) !== null;
71
- }
70
+ var danger = (def) => def.variant === "destructive" || def.kind === "delete";
71
+ /** A round icon button of the `hover` bar, and its "more" button. */
72
+ var ROUND_BUTTON = cn("udc:grid udc:size-8 udc:shrink-0 udc:place-items-center udc:rounded-full udc:outline-none udc:transition-colors udc:disabled:opacity-50", "udc:focus-visible:ring-2 udc:focus-visible:ring-ring");
73
+ var ROUND_TONE = cn("udc:text-muted-foreground udc:hover:bg-border/70 udc:hover:text-foreground udc:focus-visible:bg-border/70 udc:focus-visible:text-foreground udc:active:bg-border", "udc:data-[state=open]:bg-border/70 udc:data-[state=open]:text-foreground");
74
+ var ROUND_DANGER = "udc:text-sem-danger udc:hover:bg-sem-danger-bg udc:focus-visible:bg-sem-danger-bg udc:active:bg-sem-danger/20";
72
75
  var stop = (e) => e.stopPropagation();
73
76
  /**
74
77
  * One row's actions. A click, a key or a right-click inside never reaches the
75
78
  * row: it neither activates it, nor follows its `row_link`, nor selects it.
76
79
  */
77
- function RowActionsControls({ row, rowActions, menu, display = rowActions.display, className }) {
80
+ function RowActionsControls({ row, rowActions, menu, display: asked = rowActions.display, className }) {
78
81
  const { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, Spinner, Tip } = useUiKit();
79
82
  const { t } = useI18n();
80
83
  const box = useRef(null);
84
+ const display = effectiveRowActionsDisplay(asked, useCanHover());
81
85
  const actions = rowActions.eligible(row);
82
86
  if (actions.length === 0) return null;
83
87
  const id = row.__meta.id;
84
88
  const running = rowActions.runningOn(id);
85
89
  const open = menu.openId === id;
90
+ const split = display === "hover" ? rowActions.split(row) : null;
91
+ const menuDefs = split && menu.lastVia() === "trigger" ? split.overflow : actions;
86
92
  const run = (def) => void rowActions.run(def, row);
87
- const items = actions.map((def) => {
88
- const Icon = iconOf(def);
93
+ const items = menuDefs.map((def) => {
94
+ const Icon = rowActionIcon(def);
89
95
  return /* @__PURE__ */ jsxs(DropdownMenuItem, {
90
96
  "data-testid": `row-action-item-${def.kind}`,
91
- tone: def.variant === "destructive" || def.kind === "delete" ? "danger" : "default",
97
+ tone: danger(def) ? "danger" : "default",
92
98
  disabled: running !== null,
93
99
  onSelect: () => run(def),
94
100
  children: [Icon ? /* @__PURE__ */ jsx(Icon, {}) : null, rowActions.label(def)]
@@ -103,6 +109,16 @@ function RowActionsControls({ row, rowActions, menu, display = rowActions.displa
103
109
  "aria-label": t("APP", "ROW_ACTIONS_MORE"),
104
110
  className: cn("udc:grid udc:size-7 udc:shrink-0 udc:place-items-center udc:rounded-md udc:text-muted-foreground udc:outline-none udc:transition-colors", "udc:hover:bg-border/70 udc:hover:text-foreground udc:focus-visible:ring-2 udc:focus-visible:ring-ring udc:data-[state=open]:bg-border/70 udc:data-[state=open]:text-foreground"),
105
111
  children: running !== null ? /* @__PURE__ */ jsx(Spinner, {}) : /* @__PURE__ */ jsx(EllipsisVertical, { className: "udc:size-4" })
112
+ }) : trigger === "round" ? /* @__PURE__ */ jsx(DropdownMenuTrigger, {
113
+ asChild: true,
114
+ children: /* @__PURE__ */ jsx("button", {
115
+ type: "button",
116
+ "data-testid": "row-actions-more",
117
+ "aria-label": t("APP", "ROW_ACTIONS_MORE"),
118
+ disabled: running !== null,
119
+ className: cn(ROUND_BUTTON, ROUND_TONE),
120
+ children: running !== null && !split?.bar.some((d) => d.kind === running) ? /* @__PURE__ */ jsx(Spinner, {}) : /* @__PURE__ */ jsx(EllipsisVertical, { className: "udc:size-[18px]" })
121
+ })
106
122
  }) : /* @__PURE__ */ jsx(DropdownMenuTrigger, {
107
123
  asChild: true,
108
124
  children: /* @__PURE__ */ jsx("span", {
@@ -124,6 +140,39 @@ function RowActionsControls({ row, rowActions, menu, display = rowActions.displa
124
140
  children: items
125
141
  })]
126
142
  });
143
+ if (split) {
144
+ const pinned = open || running !== null;
145
+ return /* @__PURE__ */ jsxs("div", {
146
+ ref: box,
147
+ role: "toolbar",
148
+ "aria-label": t("APP", "ROW_ACTIONS"),
149
+ "data-testid": "row-actions",
150
+ "data-display": "hover",
151
+ "data-shown": pinned || void 0,
152
+ onClick: stop,
153
+ onAuxClick: stop,
154
+ onDoubleClick: stop,
155
+ onKeyDown: stop,
156
+ onContextMenu: stop,
157
+ className: cn("udc:flex udc:items-center udc:justify-end udc:gap-0.5 udc:pr-1.5 udc:pl-6 udc:transition-opacity udc:duration-100", "udc:[mask-image:linear-gradient(to_right,transparent,black_24px)]", pinned ? "udc:opacity-100" : "udc:pointer-events-none udc:opacity-0 udc:focus-within:pointer-events-auto udc:focus-within:opacity-100 udc:group-hover/row:pointer-events-auto udc:group-hover/row:opacity-100", className),
158
+ children: [split.bar.map((def) => {
159
+ const Icon = rowActionIcon(def);
160
+ const name = rowActions.label(def);
161
+ return /* @__PURE__ */ jsx(Tip, {
162
+ label: name,
163
+ children: /* @__PURE__ */ jsx("button", {
164
+ type: "button",
165
+ "data-testid": `row-action-${def.kind}`,
166
+ "aria-label": name,
167
+ disabled: running !== null,
168
+ onClick: () => run(def),
169
+ className: cn(ROUND_BUTTON, danger(def) ? ROUND_DANGER : ROUND_TONE),
170
+ children: running === def.kind ? /* @__PURE__ */ jsx(Spinner, {}) : Icon ? /* @__PURE__ */ jsx(Icon, { className: "udc:size-[18px]" }) : null
171
+ })
172
+ }, def.kind);
173
+ }), dropdown(split.overflow.length > 0 ? "round" : "hidden")]
174
+ });
175
+ }
127
176
  return /* @__PURE__ */ jsx("div", {
128
177
  ref: box,
129
178
  role: "toolbar",
@@ -137,7 +186,7 @@ function RowActionsControls({ row, rowActions, menu, display = rowActions.displa
137
186
  onContextMenu: stop,
138
187
  className: cn("udc:flex udc:items-center udc:justify-end udc:gap-0.5", className),
139
188
  children: display === "menu" ? dropdown("button") : [...actions.map((def) => {
140
- const Icon = iconOf(def);
189
+ const Icon = rowActionIcon(def);
141
190
  const name = rowActions.label(def);
142
191
  const busy = running === def.kind;
143
192
  const button = /* @__PURE__ */ jsx("button", {
@@ -146,7 +195,7 @@ function RowActionsControls({ row, rowActions, menu, display = rowActions.displa
146
195
  "aria-label": name,
147
196
  disabled: running !== null,
148
197
  onClick: () => run(def),
149
- className: cn("udc:inline-flex udc:h-7 udc:shrink-0 udc:items-center udc:justify-center udc:rounded-md udc:outline-none udc:transition-colors udc:disabled:opacity-50", "udc:focus-visible:ring-2 udc:focus-visible:ring-ring", Icon ? "udc:w-7" : "udc:px-2 udc:text-xs udc:font-medium", def.variant === "destructive" || def.kind === "delete" ? "udc:text-sem-danger udc:hover:bg-sem-danger-bg" : "udc:text-muted-foreground udc:hover:bg-border/70 udc:hover:text-foreground"),
198
+ className: cn("udc:inline-flex udc:h-7 udc:shrink-0 udc:items-center udc:justify-center udc:rounded-md udc:outline-none udc:transition-colors udc:disabled:opacity-50", "udc:focus-visible:ring-2 udc:focus-visible:ring-ring", Icon ? "udc:w-7" : "udc:px-2 udc:text-xs udc:font-medium", danger(def) ? "udc:text-sem-danger udc:hover:bg-sem-danger-bg" : "udc:text-muted-foreground udc:hover:bg-border/70 udc:hover:text-foreground"),
150
199
  children: busy ? /* @__PURE__ */ jsx(Spinner, {}) : Icon ? /* @__PURE__ */ jsx(Icon, { className: "udc:size-4" }) : name
151
200
  }, def.kind);
152
201
  return Icon ? /* @__PURE__ */ jsx(Tip, {
@@ -1 +1 @@
1
- {"version":3,"file":"RowActionsMenu.js","names":[],"sources":["../../src/actions/RowActionsMenu.tsx"],"sourcesContent":["// The row actions of one row as the table and the cards draw them (0.5.0): icon buttons, or a\n// \"more\" button opening a dropdown; the same dropdown opens from the keyboard and on right-click.\nimport type { ActionDef, Row } from \"@jsudc/core\";\nimport { EllipsisVertical, Trash2 } from \"lucide-react\";\nimport {\n type KeyboardEvent,\n type MouseEvent,\n type SyntheticEvent,\n useCallback,\n useRef,\n useState,\n} from \"react\";\nimport { actionIcon } from \"../data-view/BulkBar.js\";\nimport { useI18n } from \"../i18n/i18n.js\";\nimport { cn } from \"../lib/utils.js\";\nimport { ownsKeys } from \"../rows/useRowActivation.js\";\nimport { useUiKit } from \"../ui-kit/context.js\";\nimport { isRowMenuKey, type RowActions } from \"./row.js\";\n\n/** How a row's menu was opened: what decides where the focus goes when it closes. */\nexport type RowMenuVia = \"trigger\" | \"key\" | \"context\";\n\nexport interface RowMenuState {\n /** The row whose menu is open, else `null`. */\n openId: string | null;\n /** Open (or close, `null`) the menu of the row with this id. */\n openFor: (id: string | null, via?: RowMenuVia) => void;\n /** How the menu last opened (read when it closes). */\n lastVia: () => RowMenuVia;\n}\n\n/** Which row's actions menu is open: one per list. */\nexport function useRowMenu(): RowMenuState {\n const [openId, setOpenId] = useState<string | null>(null);\n const via = useRef<RowMenuVia>(\"trigger\");\n const openFor = useCallback((id: string | null, how: RowMenuVia = \"trigger\") => {\n if (id !== null) via.current = how;\n setOpenId(id);\n }, []);\n const lastVia = useCallback(() => via.current, []);\n return { openId, openFor, lastVia };\n}\n\n/**\n * The row-level handlers that open a row's menu: the menu key on the focused\n * row (`isRowMenuKey`), and a right-click when the view draws its actions\n * in a menu. `keyDown` returns `true` when it took the key.\n */\nexport function rowMenuHandlers(\n rowActions: RowActions | undefined,\n menu: RowMenuState,\n row: Row,\n opts: { contextMenu: boolean },\n) {\n const has = () => rowActions !== undefined && rowActions.eligible(row).length > 0;\n return {\n keyDown: (e: KeyboardEvent<HTMLElement>): boolean => {\n if (!rowActions || e.defaultPrevented || e.target !== e.currentTarget) return false;\n if (!isRowMenuKey(e) || !has()) return false;\n e.preventDefault();\n menu.openFor(row.__meta.id, \"key\");\n return true;\n },\n contextMenu:\n rowActions && opts.contextMenu\n ? (e: MouseEvent<HTMLElement>) => {\n if (e.defaultPrevented || ownsKeys(e.target) || !has()) return;\n const own = (e.target as Element | null)?.closest?.(\"a,input,textarea,select\");\n if (own) return;\n e.preventDefault();\n menu.openFor(row.__meta.id, \"context\");\n }\n : undefined,\n };\n}\n\n/** The width of an icon button of the inline strip, and of the \"more\" button. */\nconst ICON_BUTTON = 28;\nconst LABEL_CHAR = 7;\nconst LABEL_PADDING = 16;\nconst CELL_PADDING = 12;\nconst MENU_COLUMN = 40;\n\n/**\n * The trailing column's width, from every declared action (not one row's\n * eligible subset, so the column does not jump as rows change). As in\n * udc-js, actions with a `when` count as alternatives: only the widest.\n */\nexport function rowActionsColumnWidth(rowActions: RowActions): number {\n if (rowActions.display === \"menu\") return MENU_COLUMN;\n const widthOf = (def: ActionDef) =>\n hasIcon(def)\n ? ICON_BUTTON\n : Math.ceil(rowActions.label(def).length * LABEL_CHAR) + LABEL_PADDING;\n const always = rowActions.defs.filter((d) => d.when === undefined);\n const alternatives = rowActions.defs.filter((d) => d.when !== undefined);\n const buttons =\n always.reduce((sum, d) => sum + widthOf(d) + 2, 0) +\n (alternatives.length > 0 ? Math.max(...alternatives.map(widthOf)) + 2 : 0);\n return Math.max(MENU_COLUMN, buttons + CELL_PADDING);\n}\n\nfunction iconOf(def: ActionDef) {\n return actionIcon(def.icon) ?? (def.kind === \"delete\" ? Trash2 : null);\n}\n\nfunction hasIcon(def: ActionDef): boolean {\n return iconOf(def) !== null;\n}\n\nconst stop = (e: SyntheticEvent) => e.stopPropagation();\n\nexport interface RowActionsControlsProps {\n row: Row;\n rowActions: RowActions;\n menu: RowMenuState;\n /** `menu`: one \"more\" button whatever the view says (the cards). Default: `rowActions.display`. */\n display?: \"inline\" | \"menu\";\n className?: string;\n}\n\n/**\n * One row's actions. A click, a key or a right-click inside never reaches the\n * row: it neither activates it, nor follows its `row_link`, nor selects it.\n */\nexport function RowActionsControls({\n row,\n rowActions,\n menu,\n display = rowActions.display,\n className,\n}: RowActionsControlsProps) {\n const { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, Spinner, Tip } =\n useUiKit();\n const { t } = useI18n();\n const box = useRef<HTMLDivElement>(null);\n const actions = rowActions.eligible(row);\n if (actions.length === 0) return null;\n const id = row.__meta.id;\n const running = rowActions.runningOn(id);\n const open = menu.openId === id;\n\n const run = (def: ActionDef) => void rowActions.run(def, row);\n const items = actions.map((def) => {\n const Icon = iconOf(def);\n return (\n <DropdownMenuItem\n key={def.kind}\n data-testid={`row-action-item-${def.kind}`}\n tone={def.variant === \"destructive\" || def.kind === \"delete\" ? \"danger\" : \"default\"}\n disabled={running !== null}\n onSelect={() => run(def)}\n >\n {Icon ? <Icon /> : null}\n {rowActions.label(def)}\n </DropdownMenuItem>\n );\n });\n\n const dropdown = (trigger: \"button\" | \"hidden\") => (\n <DropdownMenu\n modal={false}\n open={open}\n onOpenChange={(next) => menu.openFor(next ? id : null, \"trigger\")}\n >\n {trigger === \"button\" ? (\n <DropdownMenuTrigger\n data-testid=\"row-actions-more\"\n aria-label={t(\"APP\", \"ROW_ACTIONS_MORE\")}\n className={cn(\n \"udc:grid udc:size-7 udc:shrink-0 udc:place-items-center udc:rounded-md udc:text-muted-foreground udc:outline-none udc:transition-colors\",\n \"udc:hover:bg-border/70 udc:hover:text-foreground udc:focus-visible:ring-2 udc:focus-visible:ring-ring udc:data-[state=open]:bg-border/70 udc:data-[state=open]:text-foreground\",\n )}\n >\n {running !== null ? <Spinner /> : <EllipsisVertical className=\"udc:size-4\" />}\n </DropdownMenuTrigger>\n ) : (\n <DropdownMenuTrigger asChild>\n <span aria-hidden tabIndex={-1} className=\"udc:block udc:size-0 udc:overflow-hidden\" />\n </DropdownMenuTrigger>\n )}\n <DropdownMenuContent\n align=\"end\"\n data-testid=\"row-actions-menu\"\n onCloseAutoFocus={(e) => {\n if (menu.lastVia() === \"trigger\") return;\n // Opened from the row (a key, a right-click): the focus goes back to the row.\n const rowEl = box.current?.closest<HTMLElement>(\"[data-row-id]\");\n if (rowEl?.hasAttribute(\"tabindex\")) {\n e.preventDefault();\n rowEl.focus({ preventScroll: true });\n }\n }}\n >\n {items}\n </DropdownMenuContent>\n </DropdownMenu>\n );\n\n return (\n <div\n ref={box}\n role=\"toolbar\"\n aria-label={t(\"APP\", \"ROW_ACTIONS\")}\n data-testid=\"row-actions\"\n data-display={display}\n onClick={stop}\n onAuxClick={stop}\n onDoubleClick={stop}\n onKeyDown={stop}\n onContextMenu={stop}\n className={cn(\"udc:flex udc:items-center udc:justify-end udc:gap-0.5\", className)}\n >\n {display === \"menu\"\n ? dropdown(\"button\")\n : [\n ...actions.map((def) => {\n const Icon = iconOf(def);\n const name = rowActions.label(def);\n const busy = running === def.kind;\n const button = (\n <button\n key={def.kind}\n type=\"button\"\n data-testid={`row-action-${def.kind}`}\n aria-label={name}\n disabled={running !== null}\n onClick={() => run(def)}\n className={cn(\n \"udc:inline-flex udc:h-7 udc:shrink-0 udc:items-center udc:justify-center udc:rounded-md udc:outline-none udc:transition-colors udc:disabled:opacity-50\",\n \"udc:focus-visible:ring-2 udc:focus-visible:ring-ring\",\n Icon ? \"udc:w-7\" : \"udc:px-2 udc:text-xs udc:font-medium\",\n def.variant === \"destructive\" || def.kind === \"delete\"\n ? \"udc:text-sem-danger udc:hover:bg-sem-danger-bg\"\n : \"udc:text-muted-foreground udc:hover:bg-border/70 udc:hover:text-foreground\",\n )}\n >\n {busy ? <Spinner /> : Icon ? <Icon className=\"udc:size-4\" /> : name}\n </button>\n );\n return Icon ? (\n <Tip key={def.kind} label={name}>\n {button}\n </Tip>\n ) : (\n <span key={def.kind}>{button}</span>\n );\n }),\n <span key=\"__menu\">{dropdown(\"hidden\")}</span>,\n ]}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;AAgCA,SAAgB,aAA2B;CACzC,MAAM,CAAC,QAAQ,aAAa,SAAwB,IAAI;CACxD,MAAM,MAAM,OAAmB,SAAS;CAMxC,OAAO;EAAE;EAAQ,SALD,aAAa,IAAmB,MAAkB,cAAc;GAC9E,IAAI,OAAO,MAAM,IAAI,UAAU;GAC/B,UAAU,EAAE;EACd,GAAG,CAAC,CAEa;EAAS,SADV,kBAAkB,IAAI,SAAS,CAAC,CACtB;CAAQ;AACpC;;;;;;AAOA,SAAgB,gBACd,YACA,MACA,KACA,MACA;CACA,MAAM,YAAY,eAAe,KAAA,KAAa,WAAW,SAAS,GAAG,CAAC,CAAC,SAAS;CAChF,OAAO;EACL,UAAU,MAA2C;GACnD,IAAI,CAAC,cAAc,EAAE,oBAAoB,EAAE,WAAW,EAAE,eAAe,OAAO;GAC9E,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,GAAG,OAAO;GACvC,EAAE,eAAe;GACjB,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK;GACjC,OAAO;EACT;EACA,aACE,cAAc,KAAK,eACd,MAA+B;GAC9B,IAAI,EAAE,oBAAoB,SAAS,EAAE,MAAM,KAAK,CAAC,IAAI,GAAG;GAExD,IADa,EAAE,QAA2B,UAAU,yBAAyB,GACpE;GACT,EAAE,eAAe;GACjB,KAAK,QAAQ,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,gBAAc;EACd,SAAS;EACT,YAAY;EACZ,eAAe;EACf,WAAW;EACX,eAAe;EACf,WAAW,GAAG,yDAAyD,SAAS;EAE/E,UAAA,YAAY,SACT,SAAS,QAAQ,IACjB,CACE,GAAG,QAAQ,KAAK,QAAQ;GACtB,MAAM,OAAO,OAAO,GAAG;GACvB,MAAM,OAAO,WAAW,MAAM,GAAG;GACjC,MAAM,OAAO,YAAY,IAAI;GAC7B,MAAM,SACJ,oBAAC,UAAD;IAEE,MAAK;IACL,eAAa,cAAc,IAAI;IAC/B,cAAY;IACZ,UAAU,YAAY;IACtB,eAAe,IAAI,GAAG;IACtB,WAAW,GACT,0JACA,wDACA,OAAO,YAAY,wCACnB,IAAI,YAAY,iBAAiB,IAAI,SAAS,WAC1C,mDACA,4EACN;IAEC,UAAA,OAAO,oBAAC,SAAD,CAAU,CAAA,IAAI,OAAO,oBAAC,MAAD,EAAM,WAAU,aAAc,CAAA,IAAI;GACzD,GAhBD,IAAI,IAgBH;GAEV,OAAO,OACL,oBAAC,KAAD;IAAoB,OAAO;IACxB,UAAA;GACE,GAFK,IAAI,IAET,IAEL,oBAAC,QAAD,EAAA,UAAsB,OAAa,GAAxB,IAAI,IAAoB;EAEvC,CAAC,GACD,oBAAC,QAAD,EAAA,UAAoB,SAAS,QAAQ,EAAQ,GAAnC,QAAmC,CAC/C;CACD,CAAA;AAET"}
1
+ {"version":3,"file":"RowActionsMenu.js","names":["hasIcon","iconOf"],"sources":["../../src/actions/RowActionsMenu.tsx"],"sourcesContent":["// The row actions of one row as the table and the cards draw them (0.5.0): icon buttons, or a\n// \"more\" button opening a dropdown; the same dropdown opens from the keyboard and on right-click.\n// `hover` (0.8.1): a bar of round icon buttons shown over the row while it is hovered or focused,\n// ending in a \"more\" button for the rest.\nimport type { ActionDef, Row } from \"@jsudc/core\";\nimport { EllipsisVertical } from \"lucide-react\";\nimport {\n type KeyboardEvent,\n type MouseEvent,\n type SyntheticEvent,\n useCallback,\n useRef,\n useState,\n} from \"react\";\nimport { useI18n } from \"../i18n/i18n.js\";\nimport { cn } from \"../lib/utils.js\";\nimport { ownsKeys } from \"../rows/useRowActivation.js\";\nimport { useUiKit } from \"../ui-kit/context.js\";\nimport { isRowMenuKey, type RowActions, type RowActionsDisplay } from \"./row.js\";\nimport { rowActionHasIcon as hasIcon, rowActionIcon as iconOf } from \"./rowIcon.js\";\nimport { effectiveRowActionsDisplay, useCanHover } from \"./useCanHover.js\";\n\n/** How a row's menu was opened: what decides where the focus goes when it closes. */\nexport type RowMenuVia = \"trigger\" | \"key\" | \"context\";\n\nexport interface RowMenuState {\n /** The row whose menu is open, else `null`. */\n openId: string | null;\n /** Open (or close, `null`) the menu of the row with this id. */\n openFor: (id: string | null, via?: RowMenuVia) => void;\n /** How the menu last opened (read when it closes). */\n lastVia: () => RowMenuVia;\n}\n\n/** Which row's actions menu is open: one per list. */\nexport function useRowMenu(): RowMenuState {\n const [openId, setOpenId] = useState<string | null>(null);\n const via = useRef<RowMenuVia>(\"trigger\");\n const openFor = useCallback((id: string | null, how: RowMenuVia = \"trigger\") => {\n if (id !== null) via.current = how;\n setOpenId(id);\n }, []);\n const lastVia = useCallback(() => via.current, []);\n return { openId, openFor, lastVia };\n}\n\n/**\n * The row-level handlers that open a row's menu: the menu key on the focused\n * row (`isRowMenuKey`), and a right-click when the view draws its actions\n * in a menu. `keyDown` returns `true` when it took the key.\n */\nexport function rowMenuHandlers(\n rowActions: RowActions | undefined,\n menu: RowMenuState,\n row: Row,\n opts: { contextMenu: boolean },\n) {\n const has = () => rowActions !== undefined && rowActions.eligible(row).length > 0;\n return {\n keyDown: (e: KeyboardEvent<HTMLElement>): boolean => {\n if (!rowActions || e.defaultPrevented || e.target !== e.currentTarget) return false;\n if (!isRowMenuKey(e) || !has()) return false;\n e.preventDefault();\n menu.openFor(row.__meta.id, \"key\");\n return true;\n },\n contextMenu:\n rowActions && opts.contextMenu\n ? (e: MouseEvent<HTMLElement>) => {\n if (e.defaultPrevented || ownsKeys(e.target) || !has()) return;\n const own = (e.target as Element | null)?.closest?.(\"a,input,textarea,select\");\n if (own) return;\n e.preventDefault();\n menu.openFor(row.__meta.id, \"context\");\n }\n : undefined,\n };\n}\n\n/** The width of an icon button of the inline strip, and of the \"more\" button. */\nconst ICON_BUTTON = 28;\nconst LABEL_CHAR = 7;\nconst LABEL_PADDING = 16;\nconst CELL_PADDING = 12;\nconst MENU_COLUMN = 40;\n\n/**\n * The trailing column's width, from every declared action (not one row's\n * eligible subset, so the column does not jump as rows change). As in\n * udc-js, actions with a `when` count as alternatives: only the widest.\n * `hover` takes no width (its bar lies over the row's trailing cells);\n * `display` is what the renderer draws, the view's display by default.\n */\nexport function rowActionsColumnWidth(\n rowActions: RowActions,\n display: RowActionsDisplay = rowActions.display,\n): number {\n if (display === \"hover\") return 0;\n if (display === \"menu\") return MENU_COLUMN;\n const widthOf = (def: ActionDef) =>\n hasIcon(def)\n ? ICON_BUTTON\n : Math.ceil(rowActions.label(def).length * LABEL_CHAR) + LABEL_PADDING;\n const always = rowActions.defs.filter((d) => d.when === undefined);\n const alternatives = rowActions.defs.filter((d) => d.when !== undefined);\n const buttons =\n always.reduce((sum, d) => sum + widthOf(d) + 2, 0) +\n (alternatives.length > 0 ? Math.max(...alternatives.map(widthOf)) + 2 : 0);\n return Math.max(MENU_COLUMN, buttons + CELL_PADDING);\n}\n\nconst danger = (def: ActionDef) => def.variant === \"destructive\" || def.kind === \"delete\";\n\n/** A round icon button of the `hover` bar, and its \"more\" button. */\nconst ROUND_BUTTON = cn(\n \"udc:grid udc:size-8 udc:shrink-0 udc:place-items-center udc:rounded-full udc:outline-none udc:transition-colors udc:disabled:opacity-50\",\n \"udc:focus-visible:ring-2 udc:focus-visible:ring-ring\",\n);\nconst ROUND_TONE = cn(\n \"udc:text-muted-foreground udc:hover:bg-border/70 udc:hover:text-foreground udc:focus-visible:bg-border/70 udc:focus-visible:text-foreground udc:active:bg-border\",\n \"udc:data-[state=open]:bg-border/70 udc:data-[state=open]:text-foreground\",\n);\nconst ROUND_DANGER =\n \"udc:text-sem-danger udc:hover:bg-sem-danger-bg udc:focus-visible:bg-sem-danger-bg udc:active:bg-sem-danger/20\";\n\nconst stop = (e: SyntheticEvent) => e.stopPropagation();\n\nexport interface RowActionsControlsProps {\n row: Row;\n rowActions: RowActions;\n menu: RowMenuState;\n /**\n * `menu`: one \"more\" button whatever the view says (the cards). Default:\n * `rowActions.display`. `hover` (0.8.1) draws the bar: shown while an\n * ancestor marked `udc:group/row` is hovered, while the focus is inside\n * and while the menu is open or an action runs; on a device that cannot\n * hover it draws as `menu`. Position it with `className` (the table lays\n * it over the row's trailing cells).\n */\n display?: RowActionsDisplay;\n className?: string;\n}\n\n/**\n * One row's actions. A click, a key or a right-click inside never reaches the\n * row: it neither activates it, nor follows its `row_link`, nor selects it.\n */\nexport function RowActionsControls({\n row,\n rowActions,\n menu,\n display: asked = rowActions.display,\n className,\n}: RowActionsControlsProps) {\n const { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, Spinner, Tip } =\n useUiKit();\n const { t } = useI18n();\n const box = useRef<HTMLDivElement>(null);\n const display = effectiveRowActionsDisplay(asked, useCanHover());\n const actions = rowActions.eligible(row);\n if (actions.length === 0) return null;\n const id = row.__meta.id;\n const running = rowActions.runningOn(id);\n const open = menu.openId === id;\n // `hover`: the bar's buttons and the \"more\" dropdown's rest. Opened from the row (a\n // right-click, the menu key) the dropdown holds every eligible action, as in `menu`.\n const split = display === \"hover\" ? rowActions.split(row) : null;\n const menuDefs = split && menu.lastVia() === \"trigger\" ? split.overflow : actions;\n\n const run = (def: ActionDef) => void rowActions.run(def, row);\n const items = menuDefs.map((def) => {\n const Icon = iconOf(def);\n return (\n <DropdownMenuItem\n key={def.kind}\n data-testid={`row-action-item-${def.kind}`}\n tone={danger(def) ? \"danger\" : \"default\"}\n disabled={running !== null}\n onSelect={() => run(def)}\n >\n {Icon ? <Icon /> : null}\n {rowActions.label(def)}\n </DropdownMenuItem>\n );\n });\n\n const dropdown = (trigger: \"button\" | \"round\" | \"hidden\") => (\n <DropdownMenu\n modal={false}\n open={open}\n onOpenChange={(next) => menu.openFor(next ? id : null, \"trigger\")}\n >\n {trigger === \"button\" ? (\n <DropdownMenuTrigger\n data-testid=\"row-actions-more\"\n aria-label={t(\"APP\", \"ROW_ACTIONS_MORE\")}\n className={cn(\n \"udc:grid udc:size-7 udc:shrink-0 udc:place-items-center udc:rounded-md udc:text-muted-foreground udc:outline-none udc:transition-colors\",\n \"udc:hover:bg-border/70 udc:hover:text-foreground udc:focus-visible:ring-2 udc:focus-visible:ring-ring udc:data-[state=open]:bg-border/70 udc:data-[state=open]:text-foreground\",\n )}\n >\n {running !== null ? <Spinner /> : <EllipsisVertical className=\"udc:size-4\" />}\n </DropdownMenuTrigger>\n ) : trigger === \"round\" ? (\n <DropdownMenuTrigger asChild>\n <button\n type=\"button\"\n data-testid=\"row-actions-more\"\n aria-label={t(\"APP\", \"ROW_ACTIONS_MORE\")}\n disabled={running !== null}\n className={cn(ROUND_BUTTON, ROUND_TONE)}\n >\n {running !== null && !split?.bar.some((d) => d.kind === running) ? (\n <Spinner />\n ) : (\n <EllipsisVertical className=\"udc:size-[18px]\" />\n )}\n </button>\n </DropdownMenuTrigger>\n ) : (\n <DropdownMenuTrigger asChild>\n <span aria-hidden tabIndex={-1} className=\"udc:block udc:size-0 udc:overflow-hidden\" />\n </DropdownMenuTrigger>\n )}\n <DropdownMenuContent\n align=\"end\"\n data-testid=\"row-actions-menu\"\n onCloseAutoFocus={(e) => {\n if (menu.lastVia() === \"trigger\") return;\n // Opened from the row (a key, a right-click): the focus goes back to the row.\n const rowEl = box.current?.closest<HTMLElement>(\"[data-row-id]\");\n if (rowEl?.hasAttribute(\"tabindex\")) {\n e.preventDefault();\n rowEl.focus({ preventScroll: true });\n }\n }}\n >\n {items}\n </DropdownMenuContent>\n </DropdownMenu>\n );\n\n if (split) {\n // Kept visible while its menu is open or one of its actions runs; hidden otherwise until\n // the row is hovered or the focus enters (a hidden bar still takes Tab, which shows it).\n const pinned = open || running !== null;\n return (\n <div\n ref={box}\n role=\"toolbar\"\n aria-label={t(\"APP\", \"ROW_ACTIONS\")}\n data-testid=\"row-actions\"\n data-display=\"hover\"\n data-shown={pinned || undefined}\n onClick={stop}\n onAuxClick={stop}\n onDoubleClick={stop}\n onKeyDown={stop}\n onContextMenu={stop}\n className={cn(\n \"udc:flex udc:items-center udc:justify-end udc:gap-0.5 udc:pr-1.5 udc:pl-6 udc:transition-opacity udc:duration-100\",\n // The left edge fades into the row over 24 px, the bar's own padding.\n \"udc:[mask-image:linear-gradient(to_right,transparent,black_24px)]\",\n pinned\n ? \"udc:opacity-100\"\n : \"udc:pointer-events-none udc:opacity-0 udc:focus-within:pointer-events-auto udc:focus-within:opacity-100 udc:group-hover/row:pointer-events-auto udc:group-hover/row:opacity-100\",\n className,\n )}\n >\n {split.bar.map((def) => {\n const Icon = iconOf(def);\n const name = rowActions.label(def);\n return (\n <Tip key={def.kind} label={name}>\n <button\n type=\"button\"\n data-testid={`row-action-${def.kind}`}\n aria-label={name}\n disabled={running !== null}\n onClick={() => run(def)}\n className={cn(ROUND_BUTTON, danger(def) ? ROUND_DANGER : ROUND_TONE)}\n >\n {running === def.kind ? (\n <Spinner />\n ) : Icon ? (\n <Icon className=\"udc:size-[18px]\" />\n ) : null}\n </button>\n </Tip>\n );\n })}\n {dropdown(split.overflow.length > 0 ? \"round\" : \"hidden\")}\n </div>\n );\n }\n\n return (\n <div\n ref={box}\n role=\"toolbar\"\n aria-label={t(\"APP\", \"ROW_ACTIONS\")}\n data-testid=\"row-actions\"\n data-display={display}\n onClick={stop}\n onAuxClick={stop}\n onDoubleClick={stop}\n onKeyDown={stop}\n onContextMenu={stop}\n className={cn(\"udc:flex udc:items-center udc:justify-end udc:gap-0.5\", className)}\n >\n {display === \"menu\"\n ? dropdown(\"button\")\n : [\n ...actions.map((def) => {\n const Icon = iconOf(def);\n const name = rowActions.label(def);\n const busy = running === def.kind;\n const button = (\n <button\n key={def.kind}\n type=\"button\"\n data-testid={`row-action-${def.kind}`}\n aria-label={name}\n disabled={running !== null}\n onClick={() => run(def)}\n className={cn(\n \"udc:inline-flex udc:h-7 udc:shrink-0 udc:items-center udc:justify-center udc:rounded-md udc:outline-none udc:transition-colors udc:disabled:opacity-50\",\n \"udc:focus-visible:ring-2 udc:focus-visible:ring-ring\",\n Icon ? \"udc:w-7\" : \"udc:px-2 udc:text-xs udc:font-medium\",\n danger(def)\n ? \"udc:text-sem-danger udc:hover:bg-sem-danger-bg\"\n : \"udc:text-muted-foreground udc:hover:bg-border/70 udc:hover:text-foreground\",\n )}\n >\n {busy ? <Spinner /> : Icon ? <Icon className=\"udc:size-4\" /> : name}\n </button>\n );\n return Icon ? (\n <Tip key={def.kind} label={name}>\n {button}\n </Tip>\n ) : (\n <span key={def.kind}>{button}</span>\n );\n }),\n <span key=\"__menu\">{dropdown(\"hidden\")}</span>,\n ]}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAmCA,SAAgB,aAA2B;CACzC,MAAM,CAAC,QAAQ,aAAa,SAAwB,IAAI;CACxD,MAAM,MAAM,OAAmB,SAAS;CAMxC,OAAO;EAAE;EAAQ,SALD,aAAa,IAAmB,MAAkB,cAAc;GAC9E,IAAI,OAAO,MAAM,IAAI,UAAU;GAC/B,UAAU,EAAE;EACd,GAAG,CAAC,CAEa;EAAS,SADV,kBAAkB,IAAI,SAAS,CAAC,CACtB;CAAQ;AACpC;;;;;;AAOA,SAAgB,gBACd,YACA,MACA,KACA,MACA;CACA,MAAM,YAAY,eAAe,KAAA,KAAa,WAAW,SAAS,GAAG,CAAC,CAAC,SAAS;CAChF,OAAO;EACL,UAAU,MAA2C;GACnD,IAAI,CAAC,cAAc,EAAE,oBAAoB,EAAE,WAAW,EAAE,eAAe,OAAO;GAC9E,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,GAAG,OAAO;GACvC,EAAE,eAAe;GACjB,KAAK,QAAQ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@jsudc/core";
2
- /** How a view draws its row actions: icon buttons in a trailing column, or one "more" menu. */
3
- export type RowActionsDisplay = "inline" | "menu";
2
+ /**
3
+ * How a view draws its row actions: icon buttons in a trailing column
4
+ * (`inline`), one "more" menu in a trailing column (`menu`), or a bar of icon
5
+ * buttons over the row's trailing cells while the row is hovered or focused,
6
+ * with no column of its own (`hover`, 0.8.1).
7
+ */
8
+ export type RowActionsDisplay = "inline" | "menu" | "hover";
9
+ /** How many buttons the `hover` bar shows when the view sets no `row_actions_max`. */
10
+ export declare const DEFAULT_ROW_ACTIONS_MAX = 4;
4
11
  /**
5
12
  * The actions a view declares for one row, read as udc-js reads them: the
6
13
  * typed `row_action_defs` when the view has any, else the kinds of the
@@ -8,8 +15,40 @@ export type RowActionsDisplay = "inline" | "menu";
8
15
  * actions and draws nothing new.
9
16
  */
10
17
  export declare function rowActionDefs(view: Pick<ViewConfig, "row_actions" | "row_action_defs">): ActionDef[];
11
- /** `view.row_actions_display`; absent: `inline`, as in udc-js. */
12
- export declare function rowActionsDisplay(view: Pick<ViewConfig, "row_actions_display">): RowActionsDisplay;
18
+ /**
19
+ * `view.row_actions_display`; absent (or a value this version does not know):
20
+ * `inline`, as in udc-js. Read loosely, so a view typed by an older
21
+ * `@jsudc/core` (whose enum has no `hover`) passes too.
22
+ */
23
+ export declare function rowActionsDisplay(view: {
24
+ row_actions_display?: unknown;
25
+ }): RowActionsDisplay;
26
+ /**
27
+ * `view.row_actions_max`: the most buttons the `hover` bar shows. Absent, or
28
+ * not a positive integer: `DEFAULT_ROW_ACTIONS_MAX` (4). Read loosely, like
29
+ * `rowActionsDisplay`.
30
+ */
31
+ export declare function rowActionsMax(view: object): number;
32
+ /** Where a row action goes in the `hover` display: `def.placement`, `bar` when absent. */
33
+ export declare function rowActionPlacement(def: ActionDef): "bar" | "menu";
34
+ /** One row's eligible actions as the `hover` display draws them. */
35
+ export interface RowActionSplit {
36
+ /** The icon buttons of the bar, in declared order. */
37
+ bar: ActionDef[];
38
+ /** The rest, in declared order: the dropdown of the ⋮ button at the bar's end. */
39
+ overflow: ActionDef[];
40
+ }
41
+ /**
42
+ * Split one row's eligible actions (`eligibleRowActions`) for the `hover`
43
+ * bar: `bar` takes, in declared order, each one that has an icon (`hasIcon`)
44
+ * and is not `placement: menu`, up to `max` (default 4); every other one goes
45
+ * to `overflow`, in declared order. Pure: `hasIcon` is the renderer's answer
46
+ * (the styled renderer's is a known `icon`, or the kind `delete`).
47
+ */
48
+ export declare function splitRowActions(eligible: readonly ActionDef[], opts: {
49
+ hasIcon: (def: ActionDef) => boolean;
50
+ max?: number | undefined;
51
+ }): RowActionSplit;
13
52
  /** The actions `row` offers: those of `defs` whose `when` holds for it (`isActionEligible`). */
14
53
  export declare function eligibleRowActions(defs: readonly ActionDef[], row: Row): ActionDef[];
15
54
  /** The keyboard modifiers and key a row menu key is read from. */
@@ -28,7 +67,8 @@ export declare function isRowMenuKey(e: RowMenuKeyEvent): boolean;
28
67
  /**
29
68
  * What `RendererProps.rowActions` hands a renderer: set when the view
30
69
  * declares row actions, absent otherwise. Draw `eligible(row)` (inline as
31
- * `display` says, or in a menu), label each with `label`, run one with `run`.
70
+ * `display` says, or in a menu; for `hover`, `split(row)`), label each with
71
+ * `label`, run one with `run`.
32
72
  */
33
73
  export interface RowActions {
34
74
  display: RowActionsDisplay;
@@ -36,6 +76,11 @@ export interface RowActions {
36
76
  defs: readonly ActionDef[];
37
77
  /** The actions `row` offers now: `defs` whose `when` holds for it. */
38
78
  eligible: (row: Row) => ActionDef[];
79
+ /**
80
+ * `eligible(row)` split for the `hover` bar (`splitRowActions` with the
81
+ * view's `row_actions_max`): the bar's icon buttons and the ⋮ dropdown's rest.
82
+ */
83
+ split: (row: Row) => RowActionSplit;
39
84
  /** The words for an action in the UI language: the collection's term, then the def's `label`. */
40
85
  label: (def: ActionDef) => string;
41
86
  /**
@@ -1,5 +1,7 @@
1
1
  import { isActionEligible } from "@jsudc/core";
2
2
  // src/actions/row.ts
3
+ /** How many buttons the `hover` bar shows when the view sets no `row_actions_max`. */
4
+ var DEFAULT_ROW_ACTIONS_MAX = 4;
3
5
  /**
4
6
  * The actions a view declares for one row, read as udc-js reads them: the
5
7
  * typed `row_action_defs` when the view has any, else the kinds of the
@@ -11,9 +13,45 @@ function rowActionDefs(view) {
11
13
  if (typed.length > 0) return [...typed];
12
14
  return (view.row_actions ?? []).map((kind) => ({ kind }));
13
15
  }
14
- /** `view.row_actions_display`; absent: `inline`, as in udc-js. */
16
+ /**
17
+ * `view.row_actions_display`; absent (or a value this version does not know):
18
+ * `inline`, as in udc-js. Read loosely, so a view typed by an older
19
+ * `@jsudc/core` (whose enum has no `hover`) passes too.
20
+ */
15
21
  function rowActionsDisplay(view) {
16
- return view.row_actions_display === "menu" ? "menu" : "inline";
22
+ const display = view.row_actions_display;
23
+ return display === "menu" || display === "hover" ? display : "inline";
24
+ }
25
+ /**
26
+ * `view.row_actions_max`: the most buttons the `hover` bar shows. Absent, or
27
+ * not a positive integer: `DEFAULT_ROW_ACTIONS_MAX` (4). Read loosely, like
28
+ * `rowActionsDisplay`.
29
+ */
30
+ function rowActionsMax(view) {
31
+ const max = view.row_actions_max;
32
+ return typeof max === "number" && Number.isInteger(max) && max > 0 ? max : 4;
33
+ }
34
+ /** Where a row action goes in the `hover` display: `def.placement`, `bar` when absent. */
35
+ function rowActionPlacement(def) {
36
+ return def.placement === "menu" ? "menu" : "bar";
37
+ }
38
+ /**
39
+ * Split one row's eligible actions (`eligibleRowActions`) for the `hover`
40
+ * bar: `bar` takes, in declared order, each one that has an icon (`hasIcon`)
41
+ * and is not `placement: menu`, up to `max` (default 4); every other one goes
42
+ * to `overflow`, in declared order. Pure: `hasIcon` is the renderer's answer
43
+ * (the styled renderer's is a known `icon`, or the kind `delete`).
44
+ */
45
+ function splitRowActions(eligible, opts) {
46
+ const max = opts.max ?? 4;
47
+ const bar = [];
48
+ const overflow = [];
49
+ for (const def of eligible) if (bar.length < max && rowActionPlacement(def) === "bar" && opts.hasIcon(def)) bar.push(def);
50
+ else overflow.push(def);
51
+ return {
52
+ bar,
53
+ overflow
54
+ };
17
55
  }
18
56
  /** The actions `row` offers: those of `defs` whose `when` holds for it (`isActionEligible`). */
19
57
  function eligibleRowActions(defs, row) {
@@ -29,6 +67,6 @@ function isRowMenuKey(e) {
29
67
  if (e.key === "F10") return e.shiftKey;
30
68
  return e.key === "." && !e.shiftKey;
31
69
  }
32
- export { eligibleRowActions, isRowMenuKey, rowActionDefs, rowActionsDisplay };
70
+ export { DEFAULT_ROW_ACTIONS_MAX, eligibleRowActions, isRowMenuKey, rowActionDefs, rowActionPlacement, rowActionsDisplay, rowActionsMax, splitRowActions };
33
71
 
34
72
  //# sourceMappingURL=row.js.map