@jsudc/react 0.3.1 → 0.5.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 (144) hide show
  1. package/README.md +1137 -22
  2. package/dist/actions/RowActionsMenu.d.ts +45 -0
  3. package/dist/actions/RowActionsMenu.js +161 -0
  4. package/dist/actions/RowActionsMenu.js.map +1 -0
  5. package/dist/actions/bulk.d.ts +81 -0
  6. package/dist/actions/bulk.js +54 -0
  7. package/dist/actions/bulk.js.map +1 -0
  8. package/dist/actions/row.d.ts +50 -0
  9. package/dist/actions/row.js +34 -0
  10. package/dist/actions/row.js.map +1 -0
  11. package/dist/actions/useRowActionRunner.d.ts +26 -0
  12. package/dist/actions/useRowActionRunner.js +198 -0
  13. package/dist/actions/useRowActionRunner.js.map +1 -0
  14. package/dist/calendar/CalendarRenderer.js +5 -4
  15. package/dist/calendar/CalendarRenderer.js.map +1 -1
  16. package/dist/calendar/EventDetail.js +1 -1
  17. package/dist/calendar.js +1 -1
  18. package/dist/cards/CardRenderer.d.ts +8 -1
  19. package/dist/cards/CardRenderer.js +179 -110
  20. package/dist/cards/CardRenderer.js.map +1 -1
  21. package/dist/cells/registry.d.ts +60 -0
  22. package/dist/cells/registry.js +47 -0
  23. package/dist/cells/registry.js.map +1 -0
  24. package/dist/chart/ChartRenderer.js +6 -4
  25. package/dist/chart/ChartRenderer.js.map +1 -1
  26. package/dist/chart/ChartWindowControl.js +2 -2
  27. package/dist/components/ui/checkbox.js +1 -1
  28. package/dist/components/ui/dialog.js +4 -3
  29. package/dist/components/ui/dialog.js.map +1 -1
  30. package/dist/components/ui/dropdown-menu.js +2 -1
  31. package/dist/components/ui/dropdown-menu.js.map +1 -1
  32. package/dist/components/ui/popover.js +2 -1
  33. package/dist/components/ui/popover.js.map +1 -1
  34. package/dist/components/ui/select.js +2 -1
  35. package/dist/components/ui/select.js.map +1 -1
  36. package/dist/components/ui/toast.js +3 -2
  37. package/dist/components/ui/toast.js.map +1 -1
  38. package/dist/components/ui/tooltip.js +2 -1
  39. package/dist/components/ui/tooltip.js.map +1 -1
  40. package/dist/data-view/BulkBar.d.ts +36 -0
  41. package/dist/data-view/BulkBar.js +239 -0
  42. package/dist/data-view/BulkBar.js.map +1 -0
  43. package/dist/data-view/FilePreview.js +1 -1
  44. package/dist/data-view/FilterBuilder.js +2 -2
  45. package/dist/data-view/FilterChips.js +2 -2
  46. package/dist/data-view/Freshness.js +1 -1
  47. package/dist/data-view/LiveIndicator.d.ts +10 -0
  48. package/dist/data-view/LiveIndicator.js +33 -0
  49. package/dist/data-view/LiveIndicator.js.map +1 -0
  50. package/dist/data-view/SearchBox.js +1 -1
  51. package/dist/data-view/UdcDataView.d.ts +110 -1
  52. package/dist/data-view/UdcDataView.js +237 -90
  53. package/dist/data-view/UdcDataView.js.map +1 -1
  54. package/dist/data-view/useDataViewState.d.ts +8 -0
  55. package/dist/data-view/useDataViewState.js +2 -1
  56. package/dist/data-view/useDataViewState.js.map +1 -1
  57. package/dist/headless.d.ts +9 -0
  58. package/dist/headless.js +12 -2
  59. package/dist/i18n/translations.js +136 -0
  60. package/dist/i18n/translations.js.map +1 -1
  61. package/dist/index.d.ts +15 -4
  62. package/dist/index.js +17 -4
  63. package/dist/kanban/KanbanCard.js +1 -1
  64. package/dist/kanban/KanbanColumn.js +1 -1
  65. package/dist/kanban/KanbanRenderer.js +6 -5
  66. package/dist/kanban/KanbanRenderer.js.map +1 -1
  67. package/dist/lib/scope.d.ts +8 -0
  68. package/dist/lib/scope.js +12 -0
  69. package/dist/lib/scope.js.map +1 -0
  70. package/dist/lookup/LookupCombobox.js +1 -1
  71. package/dist/lookup/batch.js +1 -1
  72. package/dist/lookup/options.js +4 -1
  73. package/dist/lookup/options.js.map +1 -1
  74. package/dist/lookup/useUdcLookup.js +9 -3
  75. package/dist/lookup/useUdcLookup.js.map +1 -1
  76. package/dist/map/MapRenderer.js +4 -3
  77. package/dist/map/MapRenderer.js.map +1 -1
  78. package/dist/renderers/types.d.ts +44 -1
  79. package/dist/renderers/types.js.map +1 -1
  80. package/dist/rows/useRowActivation.d.ts +91 -0
  81. package/dist/rows/useRowActivation.js +257 -0
  82. package/dist/rows/useRowActivation.js.map +1 -0
  83. package/dist/rows/useRowSelection.d.ts +92 -0
  84. package/dist/rows/useRowSelection.js +156 -0
  85. package/dist/rows/useRowSelection.js.map +1 -0
  86. package/dist/schema-editor/DeleteFieldDialog.js +2 -2
  87. package/dist/schema-editor/FieldFormDialog.js +2 -2
  88. package/dist/schema-editor/TagInput.js +1 -1
  89. package/dist/styles.css +1 -1
  90. package/dist/styles.scoped.css +2 -0
  91. package/dist/table/CellEditor.js +2 -1
  92. package/dist/table/CellEditor.js.map +1 -1
  93. package/dist/table/SelectCheckbox.d.ts +15 -0
  94. package/dist/table/SelectCheckbox.js +37 -0
  95. package/dist/table/SelectCheckbox.js.map +1 -0
  96. package/dist/table/TableRenderer.d.ts +15 -1
  97. package/dist/table/TableRenderer.js +305 -114
  98. package/dist/table/TableRenderer.js.map +1 -1
  99. package/dist/table/cells.d.ts +13 -2
  100. package/dist/table/cells.js +15 -2
  101. package/dist/table/cells.js.map +1 -1
  102. package/dist/table/index.d.ts +1 -0
  103. package/dist/table/states.d.ts +6 -0
  104. package/dist/table/states.js +14 -1
  105. package/dist/table/states.js.map +1 -1
  106. package/dist/table/useRowWindow.d.ts +82 -0
  107. package/dist/table/useRowWindow.js +182 -0
  108. package/dist/table/useRowWindow.js.map +1 -0
  109. package/dist/table.js.map +1 -1
  110. package/dist/tree/TreeNode.js +1 -1
  111. package/dist/tree/TreeRenderer.d.ts +2 -0
  112. package/dist/tree/TreeRenderer.js +16 -10
  113. package/dist/tree/TreeRenderer.js.map +1 -1
  114. package/dist/udc/changeFeed.d.ts +94 -0
  115. package/dist/udc/changeFeed.js +250 -0
  116. package/dist/udc/changeFeed.js.map +1 -0
  117. package/dist/udc/changes.d.ts +34 -0
  118. package/dist/udc/changes.js +79 -0
  119. package/dist/udc/changes.js.map +1 -0
  120. package/dist/udc/client.d.ts +15 -1
  121. package/dist/udc/client.js +34 -10
  122. package/dist/udc/client.js.map +1 -1
  123. package/dist/udc/hooks.d.ts +94 -16
  124. package/dist/udc/hooks.js +113 -10
  125. package/dist/udc/hooks.js.map +1 -1
  126. package/dist/udc/keys.d.ts +2 -0
  127. package/dist/udc/keys.js.map +1 -1
  128. package/dist/udc/listCache.d.ts +11 -0
  129. package/dist/udc/listCache.js +38 -0
  130. package/dist/udc/listCache.js.map +1 -0
  131. package/dist/udc/provider.d.ts +21 -3
  132. package/dist/udc/provider.js +23 -2
  133. package/dist/udc/provider.js.map +1 -1
  134. package/dist/udc/unauthenticated.d.ts +4 -0
  135. package/dist/udc/unauthenticated.js +17 -0
  136. package/dist/udc/unauthenticated.js.map +1 -0
  137. package/dist/ui-kit/types.d.ts +14 -0
  138. package/dist/ui-kit/ui.d.ts +1 -0
  139. package/dist/ui.js +2 -1
  140. package/dist/url-state/adapters.d.ts +23 -0
  141. package/dist/url-state/adapters.js +57 -0
  142. package/dist/url-state/adapters.js.map +1 -0
  143. package/dist/url-state/index.d.ts +1 -0
  144. package/package.json +6 -4
@@ -0,0 +1,45 @@
1
+ import type { Row } from "@jsudc/core";
2
+ import { type KeyboardEvent, type MouseEvent } from "react";
3
+ import { type RowActions } from "./row.js";
4
+ /** How a row's menu was opened: what decides where the focus goes when it closes. */
5
+ export type RowMenuVia = "trigger" | "key" | "context";
6
+ export interface RowMenuState {
7
+ /** The row whose menu is open, else `null`. */
8
+ openId: string | null;
9
+ /** Open (or close, `null`) the menu of the row with this id. */
10
+ openFor: (id: string | null, via?: RowMenuVia) => void;
11
+ /** How the menu last opened (read when it closes). */
12
+ lastVia: () => RowMenuVia;
13
+ }
14
+ /** Which row's actions menu is open: one per list. */
15
+ export declare function useRowMenu(): RowMenuState;
16
+ /**
17
+ * The row-level handlers that open a row's menu: the menu key on the focused
18
+ * row (`isRowMenuKey`), and a right-click when the view draws its actions
19
+ * in a menu. `keyDown` returns `true` when it took the key.
20
+ */
21
+ export declare function rowMenuHandlers(rowActions: RowActions | undefined, menu: RowMenuState, row: Row, opts: {
22
+ contextMenu: boolean;
23
+ }): {
24
+ keyDown: (e: KeyboardEvent<HTMLElement>) => boolean;
25
+ contextMenu: ((e: MouseEvent<HTMLElement>) => void) | undefined;
26
+ };
27
+ /**
28
+ * The trailing column's width, from every declared action (not one row's
29
+ * eligible subset, so the column does not jump as rows change). As in
30
+ * udc-js, actions with a `when` count as alternatives: only the widest.
31
+ */
32
+ export declare function rowActionsColumnWidth(rowActions: RowActions): number;
33
+ export interface RowActionsControlsProps {
34
+ row: Row;
35
+ rowActions: RowActions;
36
+ menu: RowMenuState;
37
+ /** `menu`: one "more" button whatever the view says (the cards). Default: `rowActions.display`. */
38
+ display?: "inline" | "menu";
39
+ className?: string;
40
+ }
41
+ /**
42
+ * One row's actions. A click, a key or a right-click inside never reaches the
43
+ * row: it neither activates it, nor follows its `row_link`, nor selects it.
44
+ */
45
+ export declare function RowActionsControls({ row, rowActions, menu, display, className, }: RowActionsControlsProps): import("react").JSX.Element | null;
@@ -0,0 +1,161 @@
1
+ import { actionIcon } from "../data-view/BulkBar.js";
2
+ import { useI18n } from "../i18n/i18n.js";
3
+ import { cn } from "../lib/utils.js";
4
+ import { ownsKeys } from "../rows/useRowActivation.js";
5
+ import { useUiKit } from "../ui-kit/context.js";
6
+ import { isRowMenuKey } from "./row.js";
7
+ import { useCallback, useRef, useState } from "react";
8
+ import { EllipsisVertical, Trash2 } from "lucide-react";
9
+ import { jsx, jsxs } from "react/jsx-runtime";
10
+ // src/actions/RowActionsMenu.tsx
11
+ /** Which row's actions menu is open: one per list. */
12
+ function useRowMenu() {
13
+ const [openId, setOpenId] = useState(null);
14
+ const via = useRef("trigger");
15
+ return {
16
+ openId,
17
+ openFor: useCallback((id, how = "trigger") => {
18
+ if (id !== null) via.current = how;
19
+ setOpenId(id);
20
+ }, []),
21
+ lastVia: useCallback(() => via.current, [])
22
+ };
23
+ }
24
+ /**
25
+ * The row-level handlers that open a row's menu: the menu key on the focused
26
+ * row (`isRowMenuKey`), and a right-click when the view draws its actions
27
+ * in a menu. `keyDown` returns `true` when it took the key.
28
+ */
29
+ function rowMenuHandlers(rowActions, menu, row, opts) {
30
+ const has = () => rowActions !== void 0 && rowActions.eligible(row).length > 0;
31
+ return {
32
+ keyDown: (e) => {
33
+ if (!rowActions || e.defaultPrevented || e.target !== e.currentTarget) return false;
34
+ if (!isRowMenuKey(e) || !has()) return false;
35
+ e.preventDefault();
36
+ menu.openFor(row.__meta.id, "key");
37
+ return true;
38
+ },
39
+ contextMenu: rowActions && opts.contextMenu ? (e) => {
40
+ if (e.defaultPrevented || ownsKeys(e.target) || !has()) return;
41
+ if (e.target?.closest?.("a,input,textarea,select")) return;
42
+ e.preventDefault();
43
+ menu.openFor(row.__meta.id, "context");
44
+ } : void 0
45
+ };
46
+ }
47
+ /** The width of an icon button of the inline strip, and of the "more" button. */
48
+ var ICON_BUTTON = 28;
49
+ var LABEL_CHAR = 7;
50
+ var LABEL_PADDING = 16;
51
+ var CELL_PADDING = 12;
52
+ var MENU_COLUMN = 40;
53
+ /**
54
+ * The trailing column's width, from every declared action (not one row's
55
+ * eligible subset, so the column does not jump as rows change). As in
56
+ * udc-js, actions with a `when` count as alternatives: only the widest.
57
+ */
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
+ const always = rowActions.defs.filter((d) => d.when === void 0);
62
+ const alternatives = rowActions.defs.filter((d) => d.when !== void 0);
63
+ const buttons = always.reduce((sum, d) => sum + widthOf(d) + 2, 0) + (alternatives.length > 0 ? Math.max(...alternatives.map(widthOf)) + 2 : 0);
64
+ return Math.max(MENU_COLUMN, buttons + CELL_PADDING);
65
+ }
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
+ }
72
+ var stop = (e) => e.stopPropagation();
73
+ /**
74
+ * One row's actions. A click, a key or a right-click inside never reaches the
75
+ * row: it neither activates it, nor follows its `row_link`, nor selects it.
76
+ */
77
+ function RowActionsControls({ row, rowActions, menu, display = rowActions.display, className }) {
78
+ const { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, Spinner, Tip } = useUiKit();
79
+ const { t } = useI18n();
80
+ const box = useRef(null);
81
+ const actions = rowActions.eligible(row);
82
+ if (actions.length === 0) return null;
83
+ const id = row.__meta.id;
84
+ const running = rowActions.runningOn(id);
85
+ const open = menu.openId === id;
86
+ const run = (def) => void rowActions.run(def, row);
87
+ const items = actions.map((def) => {
88
+ const Icon = iconOf(def);
89
+ return /* @__PURE__ */ jsxs(DropdownMenuItem, {
90
+ "data-testid": `row-action-item-${def.kind}`,
91
+ tone: def.variant === "destructive" || def.kind === "delete" ? "danger" : "default",
92
+ disabled: running !== null,
93
+ onSelect: () => run(def),
94
+ children: [Icon ? /* @__PURE__ */ jsx(Icon, {}) : null, rowActions.label(def)]
95
+ }, def.kind);
96
+ });
97
+ const dropdown = (trigger) => /* @__PURE__ */ jsxs(DropdownMenu, {
98
+ modal: false,
99
+ open,
100
+ onOpenChange: (next) => menu.openFor(next ? id : null, "trigger"),
101
+ children: [trigger === "button" ? /* @__PURE__ */ jsx(DropdownMenuTrigger, {
102
+ "data-testid": "row-actions-more",
103
+ "aria-label": t("APP", "ROW_ACTIONS_MORE"),
104
+ 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
+ children: running !== null ? /* @__PURE__ */ jsx(Spinner, {}) : /* @__PURE__ */ jsx(EllipsisVertical, { className: "udc:size-4" })
106
+ }) : /* @__PURE__ */ jsx(DropdownMenuTrigger, {
107
+ asChild: true,
108
+ children: /* @__PURE__ */ jsx("span", {
109
+ "aria-hidden": true,
110
+ tabIndex: -1,
111
+ className: "udc:block udc:size-0 udc:overflow-hidden"
112
+ })
113
+ }), /* @__PURE__ */ jsx(DropdownMenuContent, {
114
+ align: "end",
115
+ "data-testid": "row-actions-menu",
116
+ onCloseAutoFocus: (e) => {
117
+ if (menu.lastVia() === "trigger") return;
118
+ const rowEl = box.current?.closest("[data-row-id]");
119
+ if (rowEl?.hasAttribute("tabindex")) {
120
+ e.preventDefault();
121
+ rowEl.focus({ preventScroll: true });
122
+ }
123
+ },
124
+ children: items
125
+ })]
126
+ });
127
+ return /* @__PURE__ */ jsx("div", {
128
+ ref: box,
129
+ role: "toolbar",
130
+ "aria-label": t("APP", "ROW_ACTIONS"),
131
+ "data-testid": "row-actions",
132
+ "data-display": display,
133
+ onClick: stop,
134
+ onAuxClick: stop,
135
+ onDoubleClick: stop,
136
+ onKeyDown: stop,
137
+ onContextMenu: stop,
138
+ className: cn("udc:flex udc:items-center udc:justify-end udc:gap-0.5", className),
139
+ children: display === "menu" ? dropdown("button") : [...actions.map((def) => {
140
+ const Icon = iconOf(def);
141
+ const name = rowActions.label(def);
142
+ const busy = running === def.kind;
143
+ const button = /* @__PURE__ */ jsx("button", {
144
+ type: "button",
145
+ "data-testid": `row-action-${def.kind}`,
146
+ "aria-label": name,
147
+ disabled: running !== null,
148
+ 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"),
150
+ children: busy ? /* @__PURE__ */ jsx(Spinner, {}) : Icon ? /* @__PURE__ */ jsx(Icon, { className: "udc:size-4" }) : name
151
+ }, def.kind);
152
+ return Icon ? /* @__PURE__ */ jsx(Tip, {
153
+ label: name,
154
+ children: button
155
+ }, def.kind) : /* @__PURE__ */ jsx("span", { children: button }, def.kind);
156
+ }), /* @__PURE__ */ jsx("span", { children: dropdown("hidden") }, "__menu")]
157
+ });
158
+ }
159
+ export { RowActionsControls, rowActionsColumnWidth, rowMenuHandlers, useRowMenu };
160
+
161
+ //# sourceMappingURL=RowActionsMenu.js.map
@@ -0,0 +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":"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"}
@@ -0,0 +1,81 @@
1
+ import { type ActionDef, type FilterNode, type Row } from "@jsudc/core";
2
+ import { type ReactNode } from "react";
3
+ import type { RowSelection } from "../rows/useRowSelection.js";
4
+ /** The filter that matches every row: what "all that match" sends when the view has no filter. */
5
+ export declare const MATCH_ALL: FilterNode;
6
+ /**
7
+ * What a bulk action handler receives. In id mode `ids` names the selected
8
+ * rows; in "all that match" mode `filter` is the list's filter (search,
9
+ * chips, filter tree and the host's filter, composed; `{ and: [] }` for
10
+ * none) and `exceptIds` the rows taken out of it. Exactly one of `ids` and
11
+ * `filter` is set.
12
+ */
13
+ export interface BulkActionContext {
14
+ /** The action's `kind`, the key its handler is registered under. */
15
+ kind: string;
16
+ /** The `view.bulk_actions` entry. */
17
+ def: ActionDef;
18
+ collection: string;
19
+ /** Id mode: the selected ids. */
20
+ ids?: string[] | undefined;
21
+ /** "All that match" mode: the filter the selection stands for. */
22
+ filter?: FilterNode | undefined;
23
+ /** "All that match" mode: the ids taken out of it. */
24
+ exceptIds?: string[] | undefined;
25
+ /** The selected rows the view has loaded (in "all that match" mode, not every selected row). */
26
+ rows: Row[];
27
+ /** Select nothing: call it once the action is done (the view does not clear on its own). */
28
+ clearSelection: () => void;
29
+ /**
30
+ * A row action (0.5.0): the one row it was run on, also `ids[0]` and
31
+ * `rows[0]`. Absent when the bulk bar ran it on a selection.
32
+ */
33
+ row?: Row | undefined;
34
+ }
35
+ /** Runs one bulk action. A rejected promise (or a throw) shows its message as an error. */
36
+ export type BulkActionHandler = (ctx: BulkActionContext) => unknown;
37
+ /** `kind` → handler: what `UdcDataView actions` and `UdcProvider actions` take. */
38
+ export type BulkActionHandlers = Readonly<Record<string, BulkActionHandler>>;
39
+ export interface UdcActionsProviderProps {
40
+ /** The default handlers of every data view below; a view's own `actions` win by `kind`. Keep it stable. */
41
+ actions: BulkActionHandlers;
42
+ children: ReactNode;
43
+ }
44
+ /** Sets the bulk action handlers every `UdcDataView` below falls back to. */
45
+ export declare function UdcActionsProvider({ actions, children }: UdcActionsProviderProps): import("react").FunctionComponentElement<import("react").ProviderProps<Readonly<Record<string, BulkActionHandler>>>>;
46
+ /** The handlers in effect: the nearest provider's, else none. */
47
+ export declare function useBulkActionHandlers(): BulkActionHandlers;
48
+ /**
49
+ * How a bulk action runs, in this order: `host` a handler for its `kind` (the
50
+ * view's, else the provider's); `delete` the built-in delete (`mutate_many`
51
+ * `delete`, after a confirmation); `set` a `mutate_many` `update` with the
52
+ * def's `set`; `server` the server action named by the def's `action`
53
+ * (default its `kind`), a host action registered on the dispatcher.
54
+ */
55
+ export type BulkActionPlan = {
56
+ via: "host";
57
+ handler: BulkActionHandler;
58
+ } | {
59
+ via: "delete";
60
+ } | {
61
+ via: "set";
62
+ patch: Record<string, unknown>;
63
+ } | {
64
+ via: "server";
65
+ action: string;
66
+ };
67
+ export declare function planBulkAction(def: ActionDef, ...handlers: (BulkActionHandlers | undefined)[]): BulkActionPlan;
68
+ /**
69
+ * May the action run on the selection? Id mode: its `when` holds for every
70
+ * selected row (`isActionEligibleForAll`). "All that match" mode: rows not
71
+ * loaded cannot be checked in the browser, so it is offered unless `when` is
72
+ * `false` and the server decides.
73
+ */
74
+ export declare function bulkActionEligible(def: ActionDef, selection: Pick<RowSelection, "mode" | "rows">): boolean;
75
+ /** What a selection sends: `{ ids }`, or `{ filter, except_ids }` ("all that match"). */
76
+ export declare function selectionTarget(selection: Pick<RowSelection, "mode" | "ids" | "exceptIds">, filter: FilterNode | undefined): {
77
+ ids: string[];
78
+ } | {
79
+ filter: FilterNode;
80
+ except_ids?: string[];
81
+ };
@@ -0,0 +1,54 @@
1
+ import { actionServerName, isActionEligibleForAll } from "@jsudc/core";
2
+ import { createContext, createElement, useContext } from "react";
3
+ // src/actions/bulk.ts
4
+ /** The filter that matches every row: what "all that match" sends when the view has no filter. */
5
+ var MATCH_ALL = Object.freeze({ and: [] });
6
+ var NO_HANDLERS = Object.freeze({});
7
+ var ActionsContext = createContext(NO_HANDLERS);
8
+ /** Sets the bulk action handlers every `UdcDataView` below falls back to. */
9
+ function UdcActionsProvider({ actions, children }) {
10
+ return createElement(ActionsContext.Provider, { value: actions }, children);
11
+ }
12
+ /** The handlers in effect: the nearest provider's, else none. */
13
+ function useBulkActionHandlers() {
14
+ return useContext(ActionsContext);
15
+ }
16
+ function planBulkAction(def, ...handlers) {
17
+ for (const h of handlers) {
18
+ const handler = h && Object.hasOwn(h, def.kind) ? h[def.kind] : void 0;
19
+ if (handler) return {
20
+ via: "host",
21
+ handler
22
+ };
23
+ }
24
+ if (def.kind === "delete") return { via: "delete" };
25
+ if (def.set) return {
26
+ via: "set",
27
+ patch: def.set
28
+ };
29
+ return {
30
+ via: "server",
31
+ action: actionServerName(def)
32
+ };
33
+ }
34
+ /**
35
+ * May the action run on the selection? Id mode: its `when` holds for every
36
+ * selected row (`isActionEligibleForAll`). "All that match" mode: rows not
37
+ * loaded cannot be checked in the browser, so it is offered unless `when` is
38
+ * `false` and the server decides.
39
+ */
40
+ function bulkActionEligible(def, selection) {
41
+ if (selection.mode === "matching") return def.when !== false;
42
+ return isActionEligibleForAll(def, selection.rows);
43
+ }
44
+ /** What a selection sends: `{ ids }`, or `{ filter, except_ids }` ("all that match"). */
45
+ function selectionTarget(selection, filter) {
46
+ if (selection.mode === "ids") return { ids: [...selection.ids] };
47
+ return {
48
+ filter: filter ?? MATCH_ALL,
49
+ ...selection.exceptIds.length > 0 ? { except_ids: [...selection.exceptIds] } : {}
50
+ };
51
+ }
52
+ export { MATCH_ALL, UdcActionsProvider, bulkActionEligible, planBulkAction, selectionTarget, useBulkActionHandlers };
53
+
54
+ //# sourceMappingURL=bulk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bulk.js","names":[],"sources":["../../src/actions/bulk.ts"],"sourcesContent":["// Bulk actions (0.5.0): what runs a `view.bulk_actions` entry on a selection — a host's\n// handler by `kind`, else the server — and the provider that sets handlers for every data\n// view below it. No JSX (`@jsudc/react/headless` exports it).\nimport {\n type ActionDef,\n actionServerName,\n type FilterNode,\n isActionEligibleForAll,\n type Row,\n} from \"@jsudc/core\";\nimport { createContext, createElement, type ReactNode, useContext } from \"react\";\nimport type { RowSelection } from \"../rows/useRowSelection.js\";\n\n/** The filter that matches every row: what \"all that match\" sends when the view has no filter. */\nexport const MATCH_ALL: FilterNode = Object.freeze({ and: [] }) as FilterNode;\n\n/**\n * What a bulk action handler receives. In id mode `ids` names the selected\n * rows; in \"all that match\" mode `filter` is the list's filter (search,\n * chips, filter tree and the host's filter, composed; `{ and: [] }` for\n * none) and `exceptIds` the rows taken out of it. Exactly one of `ids` and\n * `filter` is set.\n */\nexport interface BulkActionContext {\n /** The action's `kind`, the key its handler is registered under. */\n kind: string;\n /** The `view.bulk_actions` entry. */\n def: ActionDef;\n collection: string;\n /** Id mode: the selected ids. */\n ids?: string[] | undefined;\n /** \"All that match\" mode: the filter the selection stands for. */\n filter?: FilterNode | undefined;\n /** \"All that match\" mode: the ids taken out of it. */\n exceptIds?: string[] | undefined;\n /** The selected rows the view has loaded (in \"all that match\" mode, not every selected row). */\n rows: Row[];\n /** Select nothing: call it once the action is done (the view does not clear on its own). */\n clearSelection: () => void;\n /**\n * A row action (0.5.0): the one row it was run on, also `ids[0]` and\n * `rows[0]`. Absent when the bulk bar ran it on a selection.\n */\n row?: Row | undefined;\n}\n\n/** Runs one bulk action. A rejected promise (or a throw) shows its message as an error. */\nexport type BulkActionHandler = (ctx: BulkActionContext) => unknown;\n\n/** `kind` → handler: what `UdcDataView actions` and `UdcProvider actions` take. */\nexport type BulkActionHandlers = Readonly<Record<string, BulkActionHandler>>;\n\nconst NO_HANDLERS: BulkActionHandlers = Object.freeze({});\nconst ActionsContext = createContext<BulkActionHandlers>(NO_HANDLERS);\n\nexport interface UdcActionsProviderProps {\n /** The default handlers of every data view below; a view's own `actions` win by `kind`. Keep it stable. */\n actions: BulkActionHandlers;\n children: ReactNode;\n}\n\n/** Sets the bulk action handlers every `UdcDataView` below falls back to. */\nexport function UdcActionsProvider({ actions, children }: UdcActionsProviderProps) {\n return createElement(ActionsContext.Provider, { value: actions }, children);\n}\n\n/** The handlers in effect: the nearest provider's, else none. */\nexport function useBulkActionHandlers(): BulkActionHandlers {\n return useContext(ActionsContext);\n}\n\n/**\n * How a bulk action runs, in this order: `host` a handler for its `kind` (the\n * view's, else the provider's); `delete` the built-in delete (`mutate_many`\n * `delete`, after a confirmation); `set` a `mutate_many` `update` with the\n * def's `set`; `server` the server action named by the def's `action`\n * (default its `kind`), a host action registered on the dispatcher.\n */\nexport type BulkActionPlan =\n | { via: \"host\"; handler: BulkActionHandler }\n | { via: \"delete\" }\n | { via: \"set\"; patch: Record<string, unknown> }\n | { via: \"server\"; action: string };\n\nexport function planBulkAction(\n def: ActionDef,\n ...handlers: (BulkActionHandlers | undefined)[]\n): BulkActionPlan {\n for (const h of handlers) {\n const handler = h && Object.hasOwn(h, def.kind) ? h[def.kind] : undefined;\n if (handler) return { via: \"host\", handler };\n }\n if (def.kind === \"delete\") return { via: \"delete\" };\n if (def.set) return { via: \"set\", patch: def.set };\n return { via: \"server\", action: actionServerName(def) };\n}\n\n/**\n * May the action run on the selection? Id mode: its `when` holds for every\n * selected row (`isActionEligibleForAll`). \"All that match\" mode: rows not\n * loaded cannot be checked in the browser, so it is offered unless `when` is\n * `false` and the server decides.\n */\nexport function bulkActionEligible(\n def: ActionDef,\n selection: Pick<RowSelection, \"mode\" | \"rows\">,\n): boolean {\n if (selection.mode === \"matching\") return def.when !== false;\n return isActionEligibleForAll(def, selection.rows);\n}\n\n/** What a selection sends: `{ ids }`, or `{ filter, except_ids }` (\"all that match\"). */\nexport function selectionTarget(\n selection: Pick<RowSelection, \"mode\" | \"ids\" | \"exceptIds\">,\n filter: FilterNode | undefined,\n): { ids: string[] } | { filter: FilterNode; except_ids?: string[] } {\n if (selection.mode === \"ids\") return { ids: [...selection.ids] };\n return {\n filter: filter ?? MATCH_ALL,\n ...(selection.exceptIds.length > 0 ? { except_ids: [...selection.exceptIds] } : {}),\n };\n}\n"],"mappings":";;;;AAcA,IAAa,YAAwB,OAAO,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC;AAsC9D,IAAM,cAAkC,OAAO,OAAO,CAAC,CAAC;AACxD,IAAM,iBAAiB,cAAkC,WAAW;;AASpE,SAAgB,mBAAmB,EAAE,SAAS,YAAqC;CACjF,OAAO,cAAc,eAAe,UAAU,EAAE,OAAO,QAAQ,GAAG,QAAQ;AAC5E;;AAGA,SAAgB,wBAA4C;CAC1D,OAAO,WAAW,cAAc;AAClC;AAeA,SAAgB,eACd,KACA,GAAG,UACa;CAChB,KAAK,MAAM,KAAK,UAAU;EACxB,MAAM,UAAU,KAAK,OAAO,OAAO,GAAG,IAAI,IAAI,IAAI,EAAE,IAAI,QAAQ,KAAA;EAChE,IAAI,SAAS,OAAO;GAAE,KAAK;GAAQ;EAAQ;CAC7C;CACA,IAAI,IAAI,SAAS,UAAU,OAAO,EAAE,KAAK,SAAS;CAClD,IAAI,IAAI,KAAK,OAAO;EAAE,KAAK;EAAO,OAAO,IAAI;CAAI;CACjD,OAAO;EAAE,KAAK;EAAU,QAAQ,iBAAiB,GAAG;CAAE;AACxD;;;;;;;AAQA,SAAgB,mBACd,KACA,WACS;CACT,IAAI,UAAU,SAAS,YAAY,OAAO,IAAI,SAAS;CACvD,OAAO,uBAAuB,KAAK,UAAU,IAAI;AACnD;;AAGA,SAAgB,gBACd,WACA,QACmE;CACnE,IAAI,UAAU,SAAS,OAAO,OAAO,EAAE,KAAK,CAAC,GAAG,UAAU,GAAG,EAAE;CAC/D,OAAO;EACL,QAAQ,UAAU;EAClB,GAAI,UAAU,UAAU,SAAS,IAAI,EAAE,YAAY,CAAC,GAAG,UAAU,SAAS,EAAE,IAAI,CAAC;CACnF;AACF"}
@@ -0,0 +1,50 @@
1
+ import { type ActionDef, type Row, type ViewConfig } from "@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";
4
+ /**
5
+ * The actions a view declares for one row, read as udc-js reads them: the
6
+ * typed `row_action_defs` when the view has any, else the kinds of the
7
+ * legacy `row_actions` lifted to `{ kind }`. Empty: the view has no row
8
+ * actions and draws nothing new.
9
+ */
10
+ 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;
13
+ /** The actions `row` offers: those of `defs` whose `when` holds for it (`isActionEligible`). */
14
+ export declare function eligibleRowActions(defs: readonly ActionDef[], row: Row): ActionDef[];
15
+ /** The keyboard modifiers and key a row menu key is read from. */
16
+ export interface RowMenuKeyEvent {
17
+ key: string;
18
+ shiftKey: boolean;
19
+ altKey: boolean;
20
+ ctrlKey: boolean;
21
+ metaKey: boolean;
22
+ }
23
+ /**
24
+ * Does this key open the menu of the focused row? The context-menu key,
25
+ * Shift+F10, or `.` (no modifier; unbound by the row keys of 0.4.0).
26
+ */
27
+ export declare function isRowMenuKey(e: RowMenuKeyEvent): boolean;
28
+ /**
29
+ * What `RendererProps.rowActions` hands a renderer: set when the view
30
+ * 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`.
32
+ */
33
+ export interface RowActions {
34
+ display: RowActionsDisplay;
35
+ /** Every action the view declares for a row, before `when` (what sizes a column). */
36
+ defs: readonly ActionDef[];
37
+ /** The actions `row` offers now: `defs` whose `when` holds for it. */
38
+ eligible: (row: Row) => ActionDef[];
39
+ /** The words for an action in the UI language: the collection's term, then the def's `label`. */
40
+ label: (def: ActionDef) => string;
41
+ /**
42
+ * Run `def` on `row`, as a bulk action runs on a selection of that one
43
+ * row: the host's handler for its `kind`, else `delete` (after a
44
+ * confirmation), a `set` patch (optimistic), or the server action the def
45
+ * names. Errors are shown as a toast; the promise does not reject.
46
+ */
47
+ run: (def: ActionDef, row: Row) => Promise<void>;
48
+ /** The `kind` running on the row with this id now, else `null`. */
49
+ runningOn: (rowId: string) => string | null;
50
+ }
@@ -0,0 +1,34 @@
1
+ import { isActionEligible } from "@jsudc/core";
2
+ // src/actions/row.ts
3
+ /**
4
+ * The actions a view declares for one row, read as udc-js reads them: the
5
+ * typed `row_action_defs` when the view has any, else the kinds of the
6
+ * legacy `row_actions` lifted to `{ kind }`. Empty: the view has no row
7
+ * actions and draws nothing new.
8
+ */
9
+ function rowActionDefs(view) {
10
+ const typed = view.row_action_defs ?? [];
11
+ if (typed.length > 0) return [...typed];
12
+ return (view.row_actions ?? []).map((kind) => ({ kind }));
13
+ }
14
+ /** `view.row_actions_display`; absent: `inline`, as in udc-js. */
15
+ function rowActionsDisplay(view) {
16
+ return view.row_actions_display === "menu" ? "menu" : "inline";
17
+ }
18
+ /** The actions `row` offers: those of `defs` whose `when` holds for it (`isActionEligible`). */
19
+ function eligibleRowActions(defs, row) {
20
+ return defs.filter((def) => isActionEligible(def, row));
21
+ }
22
+ /**
23
+ * Does this key open the menu of the focused row? The context-menu key,
24
+ * Shift+F10, or `.` (no modifier; unbound by the row keys of 0.4.0).
25
+ */
26
+ function isRowMenuKey(e) {
27
+ if (e.altKey || e.ctrlKey || e.metaKey) return false;
28
+ if (e.key === "ContextMenu") return true;
29
+ if (e.key === "F10") return e.shiftKey;
30
+ return e.key === "." && !e.shiftKey;
31
+ }
32
+ export { eligibleRowActions, isRowMenuKey, rowActionDefs, rowActionsDisplay };
33
+
34
+ //# sourceMappingURL=row.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"row.js","names":[],"sources":["../../src/actions/row.ts"],"sourcesContent":["// Row actions (0.5.0): the actions one row of a data view offers — `view.row_action_defs`, or\n// the kinds of `view.row_actions` — each where its `when` holds, shown inline or in a menu, and\n// run through the same plan as a bulk action (`planBulkAction`). No JSX (`@jsudc/react/headless`\n// exports it).\nimport { type ActionDef, isActionEligible, type Row, type ViewConfig } from \"@jsudc/core\";\n\n/** How a view draws its row actions: icon buttons in a trailing column, or one \"more\" menu. */\nexport type RowActionsDisplay = \"inline\" | \"menu\";\n\n/**\n * The actions a view declares for one row, read as udc-js reads them: the\n * typed `row_action_defs` when the view has any, else the kinds of the\n * legacy `row_actions` lifted to `{ kind }`. Empty: the view has no row\n * actions and draws nothing new.\n */\nexport function rowActionDefs(\n view: Pick<ViewConfig, \"row_actions\" | \"row_action_defs\">,\n): ActionDef[] {\n const typed = view.row_action_defs ?? [];\n if (typed.length > 0) return [...typed];\n return (view.row_actions ?? []).map((kind) => ({ kind }));\n}\n\n/** `view.row_actions_display`; absent: `inline`, as in udc-js. */\nexport function rowActionsDisplay(\n view: Pick<ViewConfig, \"row_actions_display\">,\n): RowActionsDisplay {\n return view.row_actions_display === \"menu\" ? \"menu\" : \"inline\";\n}\n\n/** The actions `row` offers: those of `defs` whose `when` holds for it (`isActionEligible`). */\nexport function eligibleRowActions(defs: readonly ActionDef[], row: Row): ActionDef[] {\n return defs.filter((def) => isActionEligible(def, row));\n}\n\n/** The keyboard modifiers and key a row menu key is read from. */\nexport interface RowMenuKeyEvent {\n key: string;\n shiftKey: boolean;\n altKey: boolean;\n ctrlKey: boolean;\n metaKey: boolean;\n}\n\n/**\n * Does this key open the menu of the focused row? The context-menu key,\n * Shift+F10, or `.` (no modifier; unbound by the row keys of 0.4.0).\n */\nexport function isRowMenuKey(e: RowMenuKeyEvent): boolean {\n if (e.altKey || e.ctrlKey || e.metaKey) return false;\n if (e.key === \"ContextMenu\") return true;\n if (e.key === \"F10\") return e.shiftKey;\n return e.key === \".\" && !e.shiftKey;\n}\n\n/**\n * What `RendererProps.rowActions` hands a renderer: set when the view\n * declares row actions, absent otherwise. Draw `eligible(row)` (inline as\n * `display` says, or in a menu), label each with `label`, run one with `run`.\n */\nexport interface RowActions {\n display: RowActionsDisplay;\n /** Every action the view declares for a row, before `when` (what sizes a column). */\n defs: readonly ActionDef[];\n /** The actions `row` offers now: `defs` whose `when` holds for it. */\n eligible: (row: Row) => ActionDef[];\n /** The words for an action in the UI language: the collection's term, then the def's `label`. */\n label: (def: ActionDef) => string;\n /**\n * Run `def` on `row`, as a bulk action runs on a selection of that one\n * row: the host's handler for its `kind`, else `delete` (after a\n * confirmation), a `set` patch (optimistic), or the server action the def\n * names. Errors are shown as a toast; the promise does not reject.\n */\n run: (def: ActionDef, row: Row) => Promise<void>;\n /** The `kind` running on the row with this id now, else `null`. */\n runningOn: (rowId: string) => string | null;\n}\n"],"mappings":";;;;;;;;AAeA,SAAgB,cACd,MACa;CACb,MAAM,QAAQ,KAAK,mBAAmB,CAAC;CACvC,IAAI,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,KAAK;CACtC,QAAQ,KAAK,eAAe,CAAC,EAAA,CAAG,KAAK,UAAU,EAAE,KAAK,EAAE;AAC1D;;AAGA,SAAgB,kBACd,MACmB;CACnB,OAAO,KAAK,wBAAwB,SAAS,SAAS;AACxD;;AAGA,SAAgB,mBAAmB,MAA4B,KAAuB;CACpF,OAAO,KAAK,QAAQ,QAAQ,iBAAiB,KAAK,GAAG,CAAC;AACxD;;;;;AAeA,SAAgB,aAAa,GAA6B;CACxD,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,OAAO;CAC/C,IAAI,EAAE,QAAQ,eAAe,OAAO;CACpC,IAAI,EAAE,QAAQ,OAAO,OAAO,EAAE;CAC9B,OAAO,EAAE,QAAQ,OAAO,CAAC,EAAE;AAC7B"}
@@ -0,0 +1,26 @@
1
+ import { type ActionDef, type Capabilities } from "@jsudc/core";
2
+ import { type ReactNode } from "react";
3
+ import type { RowSelection } from "../rows/useRowSelection.js";
4
+ import { type BulkActionHandlers } from "./bulk.js";
5
+ import { type RowActions, type RowActionsDisplay } from "./row.js";
6
+ export interface UseRowActionRunnerOptions {
7
+ collection: string;
8
+ /** The collection's i18n section (`TBL_<COLLECTION>`). */
9
+ section: string;
10
+ /** What the view declares (`rowActionDefs(view)`); empty: no row actions. */
11
+ defs: readonly ActionDef[];
12
+ display: RowActionsDisplay;
13
+ capabilities: Pick<Capabilities, "mutate" | "mutate_many"> | undefined;
14
+ /** The view's own handlers (`UdcDataView actions`), before the provider's. */
15
+ handlers?: BulkActionHandlers | undefined;
16
+ /** The view's selection, when it selects: a deleted row leaves it, a handler may clear it. */
17
+ selection?: RowSelection | undefined;
18
+ }
19
+ /**
20
+ * The `RowActions` a data view hands its renderer (`undefined` when the view
21
+ * declares none) and the confirmation dialog to mount beside it.
22
+ */
23
+ export declare function useRowActionRunner({ collection, section, defs, display, capabilities, handlers, selection, }: UseRowActionRunnerOptions): {
24
+ rowActions: RowActions | undefined;
25
+ dialog: ReactNode;
26
+ };