@panneau/lists 5.0.0-alpha.1 → 5.0.0-alpha.10

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 (113) hide show
  1. package/README.md +3 -3
  2. package/dist/ItemDetails.css +34 -0
  3. package/dist/ItemDetails.d.ts +18 -0
  4. package/dist/ItemDetails.d.ts.map +1 -0
  5. package/dist/ItemDetails.js +104 -0
  6. package/dist/ItemDetails.js.map +1 -0
  7. package/dist/ItemDetails.module.js +16 -0
  8. package/dist/ItemDetails.module.js.map +1 -0
  9. package/dist/List.d.ts +2 -2
  10. package/dist/List.js +54 -12
  11. package/dist/List.js.map +1 -1
  12. package/dist/ListSkeleton.d.ts +17 -0
  13. package/dist/ListSkeleton.d.ts.map +1 -0
  14. package/dist/ListSkeleton.js +111 -0
  15. package/dist/ListSkeleton.js.map +1 -0
  16. package/dist/ListView.css +16 -16
  17. package/dist/ListView.d.ts +35 -6
  18. package/dist/ListView.d.ts.map +1 -1
  19. package/dist/ListView.js +544 -211
  20. package/dist/ListView.js.map +1 -1
  21. package/dist/ListView.module.js +10 -10
  22. package/dist/actions/ActionButton.d.ts +1 -1
  23. package/dist/actions/ActionButton.d.ts.map +1 -1
  24. package/dist/actions/ActionButton.js +90 -22
  25. package/dist/actions/ActionButton.js.map +1 -1
  26. package/dist/actions/Actions.css +9 -9
  27. package/dist/actions/Actions.module.js +6 -6
  28. package/dist/actions/ConfirmDialog.d.ts +15 -3
  29. package/dist/actions/ConfirmDialog.d.ts.map +1 -1
  30. package/dist/actions/ConfirmDialog.js +103 -89
  31. package/dist/actions/ConfirmDialog.js.map +1 -1
  32. package/dist/actions/RowActions.d.ts +6 -7
  33. package/dist/actions/RowActions.d.ts.map +1 -1
  34. package/dist/actions/RowActions.js +59 -53
  35. package/dist/actions/RowActions.js.map +1 -1
  36. package/dist/actions/actions.d.ts +5 -4
  37. package/dist/actions/actions.d.ts.map +1 -1
  38. package/dist/actions/actions.js +7 -14
  39. package/dist/actions/actions.js.map +1 -1
  40. package/dist/actions/icons.js.map +1 -1
  41. package/dist/cx.js.map +1 -1
  42. package/dist/displays/Displays.css +25 -13
  43. package/dist/displays/Displays.module.js +18 -14
  44. package/dist/displays/Displays.module.js.map +1 -1
  45. package/dist/displays/displays.d.ts +18 -3
  46. package/dist/displays/displays.d.ts.map +1 -1
  47. package/dist/displays/displays.js +355 -12
  48. package/dist/displays/displays.js.map +1 -1
  49. package/dist/filters/Filters.css +34 -20
  50. package/dist/filters/Filters.d.ts +1 -1
  51. package/dist/filters/Filters.js.map +1 -1
  52. package/dist/filters/Filters.module.js +13 -9
  53. package/dist/filters/Filters.module.js.map +1 -1
  54. package/dist/filters/controls.d.ts +1 -1
  55. package/dist/filters/controls.d.ts.map +1 -1
  56. package/dist/filters/controls.js +57 -35
  57. package/dist/filters/controls.js.map +1 -1
  58. package/dist/filters/format.d.ts +1 -1
  59. package/dist/filters/format.js.map +1 -1
  60. package/dist/index.d.ts +19 -18
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +4 -3
  63. package/dist/layouts/CardsLayout.css +22 -11
  64. package/dist/layouts/CardsLayout.d.ts +2 -2
  65. package/dist/layouts/CardsLayout.d.ts.map +1 -1
  66. package/dist/layouts/CardsLayout.js +39 -35
  67. package/dist/layouts/CardsLayout.js.map +1 -1
  68. package/dist/layouts/CardsLayout.module.js +8 -8
  69. package/dist/layouts/CardsLayout.module.js.map +1 -1
  70. package/dist/layouts/ItemTitle.d.ts +3 -1
  71. package/dist/layouts/ItemTitle.d.ts.map +1 -1
  72. package/dist/layouts/ItemTitle.js +12 -8
  73. package/dist/layouts/ItemTitle.js.map +1 -1
  74. package/dist/layouts/TableLayout.css +51 -35
  75. package/dist/layouts/TableLayout.d.ts +2 -2
  76. package/dist/layouts/TableLayout.d.ts.map +1 -1
  77. package/dist/layouts/TableLayout.js +38 -33
  78. package/dist/layouts/TableLayout.js.map +1 -1
  79. package/dist/layouts/TableLayout.module.js +14 -14
  80. package/dist/layouts/TableLayout.module.js.map +1 -1
  81. package/dist/layouts/builtIn.d.ts +1 -1
  82. package/dist/layouts/builtIn.js.map +1 -1
  83. package/dist/layouts/link.css +3 -3
  84. package/dist/layouts/link.module.js +1 -1
  85. package/dist/plugin.d.ts +1 -1
  86. package/dist/plugin.js.map +1 -1
  87. package/dist/query.d.ts +1 -1
  88. package/dist/query.js.map +1 -1
  89. package/dist/selection.d.ts +1 -1
  90. package/dist/selection.js.map +1 -1
  91. package/dist/toolbar/LayoutSwitch.js.map +1 -1
  92. package/dist/toolbar/Pagination.d.ts +33 -0
  93. package/dist/toolbar/Pagination.d.ts.map +1 -1
  94. package/dist/toolbar/Pagination.js +282 -42
  95. package/dist/toolbar/Pagination.js.map +1 -1
  96. package/dist/toolbar/SearchField.js.map +1 -1
  97. package/dist/toolbar/SortSelect.d.ts +1 -1
  98. package/dist/toolbar/SortSelect.js.map +1 -1
  99. package/dist/toolbar/Toolbar.css +12 -12
  100. package/dist/toolbar/Toolbar.module.js +7 -7
  101. package/dist/types.d.ts +16 -1
  102. package/dist/types.d.ts.map +1 -1
  103. package/dist/useDraft.js.map +1 -1
  104. package/dist/useListState.js.map +1 -1
  105. package/dist/useRenderValue.d.ts +8 -0
  106. package/dist/useRenderValue.d.ts.map +1 -0
  107. package/dist/useRenderValue.js +64 -0
  108. package/dist/useRenderValue.js.map +1 -0
  109. package/dist/values.d.ts +3 -1
  110. package/dist/values.d.ts.map +1 -1
  111. package/dist/values.js +6 -2
  112. package/dist/values.js.map +1 -1
  113. package/package.json +9 -9
package/dist/ListView.js CHANGED
@@ -2,23 +2,26 @@ import { getActionHref, groupListActions, hasScope, isAllowedOn } from "./action
2
2
  import { messages } from "./messages.js";
3
3
  import { ConfirmDialog, needsConfirmation } from "./actions/ConfirmDialog.js";
4
4
  import { getColumnValue, toText } from "./values.js";
5
- import { builtInDisplays } from "./displays/displays.js";
6
5
  import { cx } from "./cx.js";
7
6
  import { builtInLayouts } from "./layouts/builtIn.js";
7
+ import { useRenderValue } from "./useRenderValue.js";
8
+ import { ListSkeleton } from "./ListSkeleton.js";
8
9
  import ListView_module_default from "./ListView.module.js";
9
10
  import { ActionButton } from "./actions/ActionButton.js";
10
11
  import { RowActions } from "./actions/RowActions.js";
11
12
  import { FilterChips, FilterControls, useFilterLabels } from "./filters/Filters.js";
12
13
  import { countSelected, getPageSelection, isItemSelected } from "./selection.js";
13
14
  import { LayoutSwitch } from "./toolbar/LayoutSwitch.js";
14
- import { Pagination } from "./toolbar/Pagination.js";
15
+ import { CursorPagination, Pagination } from "./toolbar/Pagination.js";
15
16
  import { SearchField } from "./toolbar/SearchField.js";
16
17
  import { SortSelect } from "./toolbar/SortSelect.js";
17
18
  import { useListState } from "./useListState.js";
18
- import { usePlugins } from "@panneau/core";
19
- import { Alert, Button, Checkbox, Spinner, usePanneauIntl, useToast } from "@panneau/ui";
19
+ import { selectItemActions, usePlugins } from "@panneau/core";
20
+ import { c } from "react/compiler-runtime";
21
+ import { getActionLabel } from "@panneau/intl";
22
+ import { Alert, Button, Checkbox, usePanneauIntl, useToast } from "@panneau/ui";
20
23
  import { jsx, jsxs } from "react/jsx-runtime";
21
- import { useState } from "react";
24
+ import { useRef, useState } from "react";
22
25
  //#region src/ListView.tsx
23
26
  function keyOf(action, item) {
24
27
  return item !== void 0 ? `${action.id}\u0000${item.id}` : action.id;
@@ -28,7 +31,34 @@ function keyOf(action, item) {
28
31
  * cards), with sorting, search, filters and their chips, pagination, selection and actions. It
29
32
  * fetches nothing: the caller gives the items of the list's query and their total.
30
33
  */
31
- function ListView({ list, items, columns, total, isLoading = false, error = null, onRetry, filters = [], fields = [], search = false, layouts: layoutsProp = ["table"], layout: controlledLayout, onLayoutChange, perPageOptions, selectable: selectableProp, actions: actionsProp, onAction, actionIcons, itemTitle, getItemLabel: getItemLabelProp, getItemHref, displays, layoutComponents, filterControls, toolbar, emptyMessage, "aria-label": ariaLabel, className }) {
34
+ function ListView(t0) {
35
+ const $ = c(120);
36
+ const { list, items, columns, total, cursors, isLoading: t1, error: t2, onRetry, filters: t3, fields: t4, search: t5, layouts: t6, layout: controlledLayout, onLayoutChange, perPageOptions, selectable: selectableProp, actions: actionsProp, onAction, previewAction, actionIcons, itemTitle, getItemLabel: getItemLabelProp, getItemHref, getLinkHref, currentItemId: t7, displays, layoutComponents, filterControls, toolbar, emptyMessage, "aria-label": ariaLabel, className } = t0;
37
+ const isLoading = t1 === void 0 ? false : t1;
38
+ const error = t2 === void 0 ? null : t2;
39
+ let t8;
40
+ if ($[0] !== t3) {
41
+ t8 = t3 === void 0 ? [] : t3;
42
+ $[0] = t3;
43
+ $[1] = t8;
44
+ } else t8 = $[1];
45
+ const filters = t8;
46
+ let t9;
47
+ if ($[2] !== t4) {
48
+ t9 = t4 === void 0 ? [] : t4;
49
+ $[2] = t4;
50
+ $[3] = t9;
51
+ } else t9 = $[3];
52
+ const fields = t9;
53
+ const search = t5 === void 0 ? false : t5;
54
+ let t10;
55
+ if ($[4] !== t6) {
56
+ t10 = t6 === void 0 ? ["table"] : t6;
57
+ $[4] = t6;
58
+ $[5] = t10;
59
+ } else t10 = $[5];
60
+ const layoutsProp = t10;
61
+ const currentItemId = t7 === void 0 ? null : t7;
32
62
  const intl = usePanneauIntl();
33
63
  const toasts = useToast();
34
64
  const plugins = usePlugins();
@@ -36,288 +66,591 @@ function ListView({ list, items, columns, total, isLoading = false, error = null
36
66
  const filterLabels = useFilterLabels();
37
67
  const [uncontrolledLayout, setLayout] = useState(null);
38
68
  const [confirming, setConfirming] = useState(null);
69
+ const [preview, setPreview] = useState(null);
70
+ const confirmation = useRef(0);
39
71
  const [pending, setPending] = useState(null);
40
- const label = ariaLabel ?? intl.formatMessage(messages.list);
72
+ let t11;
73
+ if ($[6] !== ariaLabel || $[7] !== intl) {
74
+ t11 = ariaLabel ?? intl.formatMessage(messages.list);
75
+ $[6] = ariaLabel;
76
+ $[7] = intl;
77
+ $[8] = t11;
78
+ } else t11 = $[8];
79
+ const label = t11;
41
80
  const pageItems = items ?? [];
42
81
  const count = total ?? pageItems.length;
43
- const sort = query.sort ?? [];
44
- const filterValues = query.filter ?? {};
45
- const hasQuery = Object.keys(filterValues).length > 0 || (query.q ?? "") !== "";
46
- const allDisplays = {
47
- ...builtInDisplays,
48
- ...Object.fromEntries(plugins.displays),
49
- ...displays
50
- };
51
- const allLayouts = {
52
- ...builtInLayouts,
53
- ...Object.fromEntries(plugins.listLayouts),
54
- ...layoutComponents
55
- };
56
- const available = layoutsProp.filter((id) => allLayouts[id] !== void 0);
57
- const layouts = available.length > 0 ? available : ["table"];
82
+ let t12;
83
+ if ($[9] !== query.sort) {
84
+ t12 = query.sort ?? [];
85
+ $[9] = query.sort;
86
+ $[10] = t12;
87
+ } else t12 = $[10];
88
+ const sort = t12;
89
+ let t13;
90
+ if ($[11] !== query.filter) {
91
+ t13 = query.filter ?? {};
92
+ $[11] = query.filter;
93
+ $[12] = t13;
94
+ } else t13 = $[12];
95
+ const filterValues = t13;
96
+ let t14;
97
+ if ($[13] !== filterValues || $[14] !== query.q) {
98
+ t14 = Object.keys(filterValues).length > 0 || (query.q ?? "") !== "";
99
+ $[13] = filterValues;
100
+ $[14] = query.q;
101
+ $[15] = t14;
102
+ } else t14 = $[15];
103
+ const hasQuery = t14;
104
+ let t15;
105
+ if ($[16] !== plugins.listLayouts) {
106
+ t15 = Object.fromEntries(plugins.listLayouts);
107
+ $[16] = plugins.listLayouts;
108
+ $[17] = t15;
109
+ } else t15 = $[17];
110
+ const t16 = t15;
111
+ let t17;
112
+ if ($[18] !== layoutComponents || $[19] !== t16) {
113
+ t17 = {
114
+ ...builtInLayouts,
115
+ ...t16,
116
+ ...layoutComponents
117
+ };
118
+ $[18] = layoutComponents;
119
+ $[19] = t16;
120
+ $[20] = t17;
121
+ } else t17 = $[20];
122
+ const allLayouts = t17;
123
+ let t18;
124
+ if ($[21] !== allLayouts || $[22] !== layoutsProp) {
125
+ let t19;
126
+ if ($[24] !== allLayouts) {
127
+ t19 = (id) => allLayouts[id] !== void 0;
128
+ $[24] = allLayouts;
129
+ $[25] = t19;
130
+ } else t19 = $[25];
131
+ t18 = layoutsProp.filter(t19);
132
+ $[21] = allLayouts;
133
+ $[22] = layoutsProp;
134
+ $[23] = t18;
135
+ } else t18 = $[23];
136
+ const available = t18;
137
+ let t19;
138
+ if ($[26] !== available) {
139
+ t19 = available.length > 0 ? available : ["table"];
140
+ $[26] = available;
141
+ $[27] = t19;
142
+ } else t19 = $[27];
143
+ const layouts = t19;
58
144
  const layout = controlledLayout ?? uncontrolledLayout ?? layouts[0] ?? "table";
59
145
  const Layout = allLayouts[layout] ?? builtInLayouts.table;
60
146
  const grouped = groupListActions(actionsProp);
61
- const rowActions = grouped.row.filter((action) => hasScope(action, "item"));
62
- const rowMenu = grouped.menu.filter((action_0) => hasScope(action_0, "item"));
63
- const toolbarActions = [...grouped.toolbar, ...grouped.menu].filter((action_1, index, all) => (hasScope(action_1, "selection") || hasScope(action_1, "resource")) && all.findIndex((candidate) => candidate.id === action_1.id) === index);
64
- const selectionActions = toolbarActions.filter((action_2) => hasScope(action_2, "selection"));
65
- const resourceActions = toolbarActions.filter((action_3) => hasScope(action_3, "resource"));
147
+ const toolbarActions = [...grouped.toolbar, ...grouped.menu].filter(_temp);
148
+ const selectionActions = toolbarActions.filter(_temp2);
149
+ const resourceActions = toolbarActions.filter(_temp3);
66
150
  const selectable = selectableProp ?? selectionActions.length > 0;
67
151
  const selectedCount = selectable ? countSelected(selection, count) : 0;
68
- const selectedItems = pageItems.filter((item) => isItemSelected(selection, item.id));
152
+ let t20;
153
+ if ($[28] !== selection) {
154
+ t20 = (item) => isItemSelected(selection, item.id);
155
+ $[28] = selection;
156
+ $[29] = t20;
157
+ } else t20 = $[29];
158
+ const selectedItems = pageItems.filter(t20);
69
159
  const pageSelection = getPageSelection(selection, pageItems);
70
- const getItemLabel = (item_0) => {
71
- if (getItemLabelProp !== void 0) return getItemLabelProp(item_0);
72
- const titleColumn = columns.find((column) => column.id === itemTitle) ?? (itemTitle === void 0 ? columns[0] : void 0);
73
- const title = titleColumn !== void 0 ? toText(getColumnValue(item_0, titleColumn, intl.locale), intl.locale) : itemTitle !== void 0 ? toText(item_0[itemTitle], intl.locale) : "";
74
- return title !== "" ? title : item_0.id;
75
- };
76
- const renderValue = (item_1, column_0) => {
77
- if (column_0.render !== void 0) return column_0.render(item_1);
78
- const Display = (column_0.display !== void 0 && column_0.display !== null ? allDisplays[column_0.display] : void 0) ?? builtInDisplays.text;
79
- if (Display === void 0) return null;
80
- return /* @__PURE__ */ jsx(Display, {
81
- value: getColumnValue(item_1, column_0, intl.locale),
82
- item: item_1,
83
- column: column_0,
84
- field: column_0.field ?? null
85
- });
160
+ let t21;
161
+ if ($[30] !== columns || $[31] !== getItemLabelProp || $[32] !== intl.locale || $[33] !== itemTitle) {
162
+ t21 = (item_0) => {
163
+ if (getItemLabelProp !== void 0) return getItemLabelProp(item_0);
164
+ const titleColumn = columns.find((column) => column.id === itemTitle) ?? (itemTitle === void 0 ? columns[0] : void 0);
165
+ const title = titleColumn !== void 0 ? toText(getColumnValue(item_0, titleColumn, intl.locale), intl.locale) : itemTitle !== void 0 ? toText(item_0[itemTitle], intl.locale) : "";
166
+ return title !== "" ? title : item_0.id;
167
+ };
168
+ $[30] = columns;
169
+ $[31] = getItemLabelProp;
170
+ $[32] = intl.locale;
171
+ $[33] = itemTitle;
172
+ $[34] = t21;
173
+ } else t21 = $[34];
174
+ const getItemLabel = t21;
175
+ const renderValue = useRenderValue(displays);
176
+ const closeConfirmation = () => {
177
+ confirmation.current = confirmation.current + 1;
178
+ setConfirming(null);
179
+ setPreview(null);
86
180
  };
87
181
  const execute = async (event) => {
88
- setConfirming(null);
182
+ closeConfirmation();
89
183
  setPending(keyOf(event.action, event.item));
90
- try {
91
- const outcome = await onAction?.(event);
184
+ await Promise.resolve().then(() => onAction?.(event)).then((outcome) => {
92
185
  if (event.scope === "selection" && outcome !== false) list.clearSelection();
93
- } catch (caught) {
186
+ }).catch((caught) => {
94
187
  toasts.show({
95
- title: intl.formatMessage(messages.actionFailed, { action: event.action.label }),
188
+ title: intl.formatMessage(messages.actionFailed, { action: getActionLabel(event.action, intl) }),
96
189
  ...caught instanceof Error && caught.message !== "" ? { description: caught.message } : {},
97
190
  tone: "danger"
98
191
  });
99
- } finally {
100
- setPending(null);
101
- }
192
+ });
193
+ setPending(null);
102
194
  };
103
195
  const run = (event_0) => {
196
+ const { action: action_2, selection: selection_0 } = event_0;
197
+ if (previewAction !== void 0 && action_2.dryRun === true && selection_0 !== void 0 && "query" in selection_0) {
198
+ const current = confirmation.current = confirmation.current + 1;
199
+ const asks = action_2.confirm !== void 0 && action_2.confirm !== false;
200
+ setConfirming(event_0);
201
+ setPreview({ status: "loading" });
202
+ previewAction(event_0).then((result) => {
203
+ if (confirmation.current !== current) return;
204
+ if ((result?.skipped ?? event_0.skipped.length) === 0 && !asks) execute(event_0);
205
+ else setPreview(result !== null ? {
206
+ status: "done",
207
+ ...result
208
+ } : null);
209
+ }, () => {
210
+ if (confirmation.current !== current) return;
211
+ if (needsConfirmation(event_0)) setPreview(null);
212
+ else execute(event_0);
213
+ });
214
+ return;
215
+ }
104
216
  if (needsConfirmation(event_0)) setConfirming(event_0);
105
217
  else execute(event_0);
106
218
  };
107
- const runOnItem = (action_4, item_2) => run({
108
- action: action_4,
219
+ const runOnItem = (action_3, item_1) => run({
220
+ action: action_3,
109
221
  scope: "item",
110
- item: item_2,
222
+ item: item_1,
111
223
  count: 1,
112
224
  skipped: []
113
225
  });
114
- const runOnSelection = (action_5) => {
226
+ const runOnSelection = (action_4) => {
115
227
  const selected = list.getSelection();
116
228
  if (selected === null) return;
117
229
  run({
118
- action: action_5,
230
+ action: action_4,
119
231
  scope: "selection",
120
232
  selection: selected,
121
233
  count: selectedCount,
122
- skipped: selectedItems.filter((item_3) => !isAllowedOn(action_5, item_3))
234
+ skipped: selectedItems.filter((item_2) => !isAllowedOn(action_4, item_2))
123
235
  });
124
236
  };
125
- const runOnResource = (action_6) => run({
126
- action: action_6,
237
+ const runOnResource = (action_5) => run({
238
+ action: action_5,
127
239
  scope: "resource",
128
240
  count,
129
241
  skipped: []
130
242
  });
131
- const renderActions = (item_4) => {
132
- const allowed = rowActions.filter((action_7) => isAllowedOn(action_7, item_4));
133
- const menu = rowMenu.filter((action_8) => isAllowedOn(action_8, item_4));
243
+ const renderActions = (item_3) => {
244
+ const allowed = selectItemActions(grouped.row, item_3, "row", { getLinkHref });
245
+ const menu = selectItemActions(grouped.menu, item_3, "menu", { getLinkHref });
134
246
  if (allowed.length === 0 && menu.length === 0) return null;
135
- const running = pending?.endsWith(`\u0000${item_4.id}`) === true ? pending.split("\0")[0] : null;
247
+ const running = pending?.endsWith(`\u0000${item_3.id}`) === true ? pending.split("\0")[0] : null;
136
248
  return /* @__PURE__ */ jsx(RowActions, {
137
- item: item_4,
138
- itemLabel: getItemLabel(item_4),
249
+ itemLabel: getItemLabel(item_3),
139
250
  actions: allowed,
140
251
  menu,
141
252
  pending: running ?? null,
142
- onRun: (action_9) => runOnItem(action_9, item_4),
253
+ onRun: (action_6) => runOnItem(action_6, item_3),
143
254
  icons: actionIcons
144
255
  });
145
256
  };
257
+ let t22;
258
+ if ($[35] !== intl) {
259
+ t22 = intl.formatMessage(messages.selectPage);
260
+ $[35] = intl;
261
+ $[36] = t22;
262
+ } else t22 = $[36];
146
263
  const pageCheckbox = /* @__PURE__ */ jsx(Checkbox, {
147
- "aria-label": intl.formatMessage(messages.selectPage),
264
+ "aria-label": t22,
148
265
  isSelected: pageSelection === "all",
149
266
  isIndeterminate: pageSelection === "some",
150
267
  isDisabled: pageItems.length === 0,
151
268
  onChange: () => {
152
- const ids = pageItems.map((item_5) => item_5.id);
269
+ const ids = pageItems.map(_temp4);
153
270
  if (pageSelection === "all") list.deselect(ids);
154
271
  else list.select(ids);
155
272
  }
156
273
  });
157
- const sortable = columns.some((column_1) => column_1.sortable === true);
274
+ const sortable = columns.some(_temp5);
158
275
  const showToolbar = search || filters.length > 0 || sortable || layouts.length > 1 || resourceActions.length > 0 || toolbar !== void 0;
159
- const body = (() => {
160
- if (error !== null) return /* @__PURE__ */ jsx(Alert, {
161
- tone: "danger",
162
- title: intl.formatMessage(messages.loadFailed),
163
- actions: onRetry !== void 0 ? /* @__PURE__ */ jsx(Button, {
164
- size: "sm",
165
- onPress: onRetry,
166
- children: intl.formatMessage(messages.retry)
167
- }) : void 0,
168
- children: error.message
169
- });
170
- if (items === void 0) return /* @__PURE__ */ jsx("div", {
171
- className: ListView_module_default.state,
172
- children: /* @__PURE__ */ jsx(Spinner, { showLabel: true })
173
- });
174
- if (pageItems.length === 0) return /* @__PURE__ */ jsxs("div", {
175
- className: ListView_module_default.state,
176
- children: [/* @__PURE__ */ jsx("p", { children: hasQuery ? intl.formatMessage(messages.noResults) : emptyMessage ?? intl.formatMessage(messages.empty) }), hasQuery ? /* @__PURE__ */ jsx(Button, {
177
- size: "sm",
178
- onPress: () => clearFilters(),
179
- children: intl.formatMessage(messages.clearFilters)
180
- }) : null]
181
- });
182
- return /* @__PURE__ */ jsx(Layout, {
276
+ let t23;
277
+ if ($[37] !== filterValues || $[38] !== list || $[39] !== query.q) {
278
+ t23 = function clearFilters() {
279
+ Object.keys(filterValues).forEach((id_0) => list.setFilter(id_0, void 0));
280
+ if ((query.q ?? "") !== "") list.setSearch("");
281
+ };
282
+ $[37] = filterValues;
283
+ $[38] = list;
284
+ $[39] = query.q;
285
+ $[40] = t23;
286
+ } else t23 = $[40];
287
+ const clearFilters = t23;
288
+ let t24;
289
+ bb0: {
290
+ if (error !== null) {
291
+ let t25;
292
+ if ($[41] !== intl) {
293
+ t25 = intl.formatMessage(messages.loadFailed);
294
+ $[41] = intl;
295
+ $[42] = t25;
296
+ } else t25 = $[42];
297
+ let t26;
298
+ if ($[43] !== intl || $[44] !== onRetry) {
299
+ t26 = onRetry !== void 0 ? /* @__PURE__ */ jsx(Button, {
300
+ size: "sm",
301
+ onPress: onRetry,
302
+ children: intl.formatMessage(messages.retry)
303
+ }) : void 0;
304
+ $[43] = intl;
305
+ $[44] = onRetry;
306
+ $[45] = t26;
307
+ } else t26 = $[45];
308
+ let t27;
309
+ if ($[46] !== error.message || $[47] !== t25 || $[48] !== t26) {
310
+ t27 = /* @__PURE__ */ jsx(Alert, {
311
+ tone: "danger",
312
+ title: t25,
313
+ actions: t26,
314
+ children: error.message
315
+ });
316
+ $[46] = error.message;
317
+ $[47] = t25;
318
+ $[48] = t26;
319
+ $[49] = t27;
320
+ } else t27 = $[49];
321
+ t24 = t27;
322
+ break bb0;
323
+ }
324
+ if (items === void 0) {
325
+ let t25;
326
+ if ($[50] !== Layout || $[51] !== columns || $[52] !== label || $[53] !== query.perPage || $[54] !== sort) {
327
+ t25 = /* @__PURE__ */ jsx(ListSkeleton, {
328
+ Layout,
329
+ columns,
330
+ perPage: query.perPage,
331
+ sort,
332
+ label
333
+ });
334
+ $[50] = Layout;
335
+ $[51] = columns;
336
+ $[52] = label;
337
+ $[53] = query.perPage;
338
+ $[54] = sort;
339
+ $[55] = t25;
340
+ } else t25 = $[55];
341
+ t24 = t25;
342
+ break bb0;
343
+ }
344
+ if (pageItems.length === 0) {
345
+ let t25;
346
+ if ($[56] !== emptyMessage || $[57] !== hasQuery || $[58] !== intl) {
347
+ t25 = hasQuery ? intl.formatMessage(messages.noResults) : emptyMessage ?? intl.formatMessage(messages.empty);
348
+ $[56] = emptyMessage;
349
+ $[57] = hasQuery;
350
+ $[58] = intl;
351
+ $[59] = t25;
352
+ } else t25 = $[59];
353
+ let t26;
354
+ if ($[60] !== t25) {
355
+ t26 = /* @__PURE__ */ jsx("p", { children: t25 });
356
+ $[60] = t25;
357
+ $[61] = t26;
358
+ } else t26 = $[61];
359
+ let t27;
360
+ if ($[62] !== clearFilters || $[63] !== hasQuery || $[64] !== intl) {
361
+ t27 = hasQuery ? /* @__PURE__ */ jsx(Button, {
362
+ size: "sm",
363
+ onPress: () => clearFilters(),
364
+ children: intl.formatMessage(messages.clearFilters)
365
+ }) : null;
366
+ $[62] = clearFilters;
367
+ $[63] = hasQuery;
368
+ $[64] = intl;
369
+ $[65] = t27;
370
+ } else t27 = $[65];
371
+ let t28;
372
+ if ($[66] !== t26 || $[67] !== t27) {
373
+ t28 = /* @__PURE__ */ jsxs("div", {
374
+ className: ListView_module_default.state,
375
+ children: [t26, t27]
376
+ });
377
+ $[66] = t26;
378
+ $[67] = t27;
379
+ $[68] = t28;
380
+ } else t28 = $[68];
381
+ t24 = t28;
382
+ break bb0;
383
+ }
384
+ let t25;
385
+ if ($[69] !== currentItemId) {
386
+ t25 = (item_5) => item_5.id === currentItemId;
387
+ $[69] = currentItemId;
388
+ $[70] = t25;
389
+ } else t25 = $[70];
390
+ let t26;
391
+ if ($[71] !== selection) {
392
+ t26 = (item_6) => isItemSelected(selection, item_6.id);
393
+ $[71] = selection;
394
+ $[72] = t26;
395
+ } else t26 = $[72];
396
+ let t27;
397
+ if ($[73] !== list) {
398
+ t27 = (item_7) => list.toggle(item_7.id);
399
+ $[73] = list;
400
+ $[74] = t27;
401
+ } else t27 = $[74];
402
+ let t28;
403
+ if ($[75] !== list) {
404
+ t28 = (column_1) => list.toggleSort(column_1.id);
405
+ $[75] = list;
406
+ $[76] = t28;
407
+ } else t28 = $[76];
408
+ t24 = /* @__PURE__ */ jsx(Layout, {
183
409
  items: pageItems,
184
410
  columns,
185
411
  renderValue,
186
412
  getItemLabel,
187
413
  getItemHref,
414
+ isCurrent: t25,
188
415
  selectable,
189
- isSelected: (item_6) => isItemSelected(selection, item_6.id),
190
- onToggle: (item_7) => list.toggle(item_7.id),
416
+ isSelected: t26,
417
+ onToggle: t27,
191
418
  renderActions,
192
419
  sort,
193
- onSort: (column_2) => list.toggleSort(column_2.id),
420
+ onSort: t28,
194
421
  label,
195
422
  pageSelection: pageCheckbox
196
423
  });
197
- })();
198
- function clearFilters() {
199
- Object.keys(filterValues).forEach((id_0) => list.setFilter(id_0, void 0));
200
- if ((query.q ?? "") !== "") list.setSearch("");
201
424
  }
202
- return /* @__PURE__ */ jsxs("div", {
203
- className: cx(ListView_module_default.list, className),
204
- children: [
205
- showToolbar ? /* @__PURE__ */ jsxs("div", {
206
- className: ListView_module_default.toolbar,
207
- children: [/* @__PURE__ */ jsxs("div", {
208
- className: ListView_module_default.toolbarStart,
209
- children: [search ? /* @__PURE__ */ jsx(SearchField, {
210
- value: query.q ?? "",
211
- onChange: (q) => list.setSearch(q)
212
- }) : null, filters.length > 0 ? /* @__PURE__ */ jsx(FilterControls, {
213
- filters,
214
- values: filterValues,
215
- onChange: (id_1, value) => list.setFilter(id_1, value),
216
- onLabel: filterLabels.remember,
217
- controls: filterControls,
218
- columns,
219
- fields,
220
- labels: filterLabels.labels
221
- }) : null]
222
- }), /* @__PURE__ */ jsxs("div", {
223
- className: ListView_module_default.toolbarEnd,
224
- children: [
225
- sortable ? /* @__PURE__ */ jsx("div", {
226
- className: layout === "table" ? ListView_module_default.tableSort : void 0,
227
- children: /* @__PURE__ */ jsx(SortSelect, {
228
- columns,
229
- sort,
230
- onChange: (next) => list.setSort(next)
231
- })
232
- }) : null,
233
- layouts.length > 1 ? /* @__PURE__ */ jsx(LayoutSwitch, {
234
- layouts,
235
- value: layout,
236
- onChange: (next_0) => {
237
- setLayout(next_0);
238
- onLayoutChange?.(next_0);
239
- }
240
- }) : null,
241
- resourceActions.filter((action_10) => selectedCount === 0 || !hasScope(action_10, "selection")).map((action_11) => /* @__PURE__ */ jsx(ActionButton, {
242
- action: action_11,
243
- icons: actionIcons,
244
- size: "md",
245
- href: getActionHref(action_11),
246
- isPending: pending === keyOf(action_11),
247
- onPress: () => runOnResource(action_11)
248
- }, action_11.id)),
249
- toolbar
250
- ]
251
- })]
252
- }) : null,
253
- /* @__PURE__ */ jsx(FilterChips, {
425
+ const body = t24;
426
+ let t25;
427
+ if ($[77] !== className) {
428
+ t25 = cx(ListView_module_default.list, className);
429
+ $[77] = className;
430
+ $[78] = t25;
431
+ } else t25 = $[78];
432
+ const t26 = showToolbar ? /* @__PURE__ */ jsxs("div", {
433
+ className: ListView_module_default.toolbar,
434
+ children: [/* @__PURE__ */ jsxs("div", {
435
+ className: ListView_module_default.toolbarStart,
436
+ children: [search ? /* @__PURE__ */ jsx(SearchField, {
437
+ value: query.q ?? "",
438
+ onChange: (q) => list.setSearch(q)
439
+ }) : null, filters.length > 0 ? /* @__PURE__ */ jsx(FilterControls, {
254
440
  filters,
255
441
  values: filterValues,
256
- q: query.q,
257
- onRemove: (id_2) => list.setFilter(id_2, void 0),
258
- onClearSearch: () => list.setSearch(""),
259
- onClear: clearFilters,
442
+ onChange: (id_1, value) => list.setFilter(id_1, value),
443
+ onLabel: filterLabels.remember,
444
+ controls: filterControls,
260
445
  columns,
261
446
  fields,
262
447
  labels: filterLabels.labels
448
+ }) : null]
449
+ }), /* @__PURE__ */ jsxs("div", {
450
+ className: ListView_module_default.toolbarEnd,
451
+ children: [
452
+ sortable ? /* @__PURE__ */ jsx("div", {
453
+ className: layout === "table" ? ListView_module_default.tableSort : void 0,
454
+ children: /* @__PURE__ */ jsx(SortSelect, {
455
+ columns,
456
+ sort,
457
+ onChange: (next) => list.setSort(next)
458
+ })
459
+ }) : null,
460
+ layouts.length > 1 ? /* @__PURE__ */ jsx(LayoutSwitch, {
461
+ layouts,
462
+ value: layout,
463
+ onChange: (next_0) => {
464
+ setLayout(next_0);
465
+ onLayoutChange?.(next_0);
466
+ }
467
+ }) : null,
468
+ resourceActions.filter((action_7) => selectedCount === 0 || !hasScope(action_7, "selection")).map((action_8) => /* @__PURE__ */ jsx(ActionButton, {
469
+ action: action_8,
470
+ icons: actionIcons,
471
+ size: "md",
472
+ href: getActionHref(action_8),
473
+ isPending: pending === keyOf(action_8),
474
+ onPress: () => runOnResource(action_8)
475
+ }, action_8.id)),
476
+ toolbar
477
+ ]
478
+ })]
479
+ }) : null;
480
+ let t27;
481
+ let t28;
482
+ if ($[79] !== list) {
483
+ t27 = (id_2) => list.setFilter(id_2, void 0);
484
+ t28 = () => list.setSearch("");
485
+ $[79] = list;
486
+ $[80] = t27;
487
+ $[81] = t28;
488
+ } else {
489
+ t27 = $[80];
490
+ t28 = $[81];
491
+ }
492
+ let t29;
493
+ if ($[82] !== clearFilters || $[83] !== columns || $[84] !== fields || $[85] !== filterLabels.labels || $[86] !== filterValues || $[87] !== filters || $[88] !== query.q || $[89] !== t27 || $[90] !== t28) {
494
+ t29 = /* @__PURE__ */ jsx(FilterChips, {
495
+ filters,
496
+ values: filterValues,
497
+ q: query.q,
498
+ onRemove: t27,
499
+ onClearSearch: t28,
500
+ onClear: clearFilters,
501
+ columns,
502
+ fields,
503
+ labels: filterLabels.labels
504
+ });
505
+ $[82] = clearFilters;
506
+ $[83] = columns;
507
+ $[84] = fields;
508
+ $[85] = filterLabels.labels;
509
+ $[86] = filterValues;
510
+ $[87] = filters;
511
+ $[88] = query.q;
512
+ $[89] = t27;
513
+ $[90] = t28;
514
+ $[91] = t29;
515
+ } else t29 = $[91];
516
+ const t30 = selectedCount > 0 ? /* @__PURE__ */ jsxs("div", {
517
+ className: ListView_module_default.selection,
518
+ children: [
519
+ /* @__PURE__ */ jsx("span", {
520
+ className: ListView_module_default.selectionCount,
521
+ role: "status",
522
+ children: selection.mode === "all" ? intl.formatMessage(messages.allMatchingSelected, { total: selectedCount }) : intl.formatMessage(messages.selectedCount, { count: selectedCount })
263
523
  }),
264
- selectedCount > 0 ? /* @__PURE__ */ jsxs("div", {
265
- className: ListView_module_default.selection,
266
- children: [
267
- /* @__PURE__ */ jsx("span", {
268
- className: ListView_module_default.selectionCount,
269
- role: "status",
270
- children: selection.mode === "all" ? intl.formatMessage(messages.allMatchingSelected, { total: selectedCount }) : intl.formatMessage(messages.selectedCount, { count: selectedCount })
271
- }),
272
- selection.mode === "ids" && pageSelection === "all" && count > pageItems.length ? /* @__PURE__ */ jsx(Button, {
273
- size: "sm",
274
- variant: "ghost",
275
- onPress: () => list.selectAllMatching(),
276
- children: intl.formatMessage(messages.selectAllMatching, { total: count })
277
- }) : null,
278
- /* @__PURE__ */ jsx(Button, {
279
- size: "sm",
280
- variant: "ghost",
281
- onPress: () => list.clearSelection(),
282
- children: intl.formatMessage(messages.clearSelection)
283
- }),
284
- selectionActions.length > 0 ? /* @__PURE__ */ jsx("div", {
285
- className: ListView_module_default.selectionActions,
286
- children: selectionActions.map((action_12) => {
287
- const skipped = selectedItems.filter((item_8) => !isAllowedOn(action_12, item_8)).length;
288
- return /* @__PURE__ */ jsx(ActionButton, {
289
- action: action_12,
290
- icons: actionIcons,
291
- size: "md",
292
- href: null,
293
- isPending: pending === keyOf(action_12),
294
- isDisabled: pending !== null && pending !== keyOf(action_12) || skipped >= selectedCount,
295
- onPress: () => runOnSelection(action_12)
296
- }, action_12.id);
297
- })
298
- }) : null
299
- ]
524
+ selection.mode === "ids" && pageSelection === "all" && count > pageItems.length ? /* @__PURE__ */ jsx(Button, {
525
+ size: "sm",
526
+ variant: "ghost",
527
+ onPress: () => list.selectAllMatching(),
528
+ children: intl.formatMessage(messages.selectAllMatching, { total: count })
300
529
  }) : null,
301
- /* @__PURE__ */ jsx("div", {
302
- className: ListView_module_default.body,
303
- "aria-busy": isLoading && items !== void 0,
304
- children: body
530
+ /* @__PURE__ */ jsx(Button, {
531
+ size: "sm",
532
+ variant: "ghost",
533
+ onPress: () => list.clearSelection(),
534
+ children: intl.formatMessage(messages.clearSelection)
305
535
  }),
306
- total !== void 0 && error === null && total > 0 ? /* @__PURE__ */ jsx(Pagination, {
307
- page: query.page ?? 1,
308
- perPage: query.perPage ?? pageItems.length,
309
- total,
310
- onPageChange: (page) => list.setPage(page),
311
- perPageOptions,
312
- onPerPageChange: (perPage) => list.setPerPage(perPage)
313
- }) : null,
314
- /* @__PURE__ */ jsx(ConfirmDialog, {
315
- event: confirming,
316
- onConfirm: (event_1) => void execute(event_1),
317
- onCancel: () => setConfirming(null)
318
- })
536
+ selectionActions.length > 0 ? /* @__PURE__ */ jsx("div", {
537
+ className: ListView_module_default.selectionActions,
538
+ children: selectionActions.map((action_9) => {
539
+ const skipped_0 = selectedItems.filter((item_8) => !isAllowedOn(action_9, item_8)).length;
540
+ return /* @__PURE__ */ jsx(ActionButton, {
541
+ action: action_9,
542
+ icons: actionIcons,
543
+ size: "md",
544
+ href: null,
545
+ isPending: pending === keyOf(action_9),
546
+ isDisabled: pending !== null && pending !== keyOf(action_9) || skipped_0 >= selectedCount,
547
+ onPress: () => runOnSelection(action_9)
548
+ }, action_9.id);
549
+ })
550
+ }) : null
319
551
  ]
320
- });
552
+ }) : null;
553
+ const t31 = isLoading && items !== void 0;
554
+ let t32;
555
+ if ($[92] !== body || $[93] !== t31) {
556
+ t32 = /* @__PURE__ */ jsx("div", {
557
+ className: ListView_module_default.body,
558
+ "aria-busy": t31,
559
+ children: body
560
+ });
561
+ $[92] = body;
562
+ $[93] = t31;
563
+ $[94] = t32;
564
+ } else t32 = $[94];
565
+ let t33;
566
+ if ($[95] !== cursors || $[96] !== error || $[97] !== list || $[98] !== pageItems || $[99] !== perPageOptions || $[100] !== query.cursor || $[101] !== query.page || $[102] !== query.perPage || $[103] !== total) {
567
+ t33 = cursors !== void 0 && error === null ? /* @__PURE__ */ jsx(CursorPagination, {
568
+ perPage: query.perPage ?? pageItems.length,
569
+ hasPrevious: query.cursor !== void 0,
570
+ hasNext: cursors.next !== null,
571
+ onPrevious: () => list.previousPage(cursors.previous),
572
+ onNext: () => {
573
+ if (cursors.next !== null) list.nextPage(cursors.next);
574
+ },
575
+ perPageOptions,
576
+ onPerPageChange: (perPage) => list.setPerPage(perPage)
577
+ }) : total !== void 0 && error === null && total > 0 ? /* @__PURE__ */ jsx(Pagination, {
578
+ page: query.page ?? 1,
579
+ perPage: query.perPage ?? pageItems.length,
580
+ total,
581
+ onPageChange: (page) => list.setPage(page),
582
+ perPageOptions,
583
+ onPerPageChange: (perPage_0) => list.setPerPage(perPage_0)
584
+ }) : null;
585
+ $[95] = cursors;
586
+ $[96] = error;
587
+ $[97] = list;
588
+ $[98] = pageItems;
589
+ $[99] = perPageOptions;
590
+ $[100] = query.cursor;
591
+ $[101] = query.page;
592
+ $[102] = query.perPage;
593
+ $[103] = total;
594
+ $[104] = t33;
595
+ } else t33 = $[104];
596
+ let t34;
597
+ if ($[105] !== execute) {
598
+ t34 = (event_1) => void execute(event_1);
599
+ $[105] = execute;
600
+ $[106] = t34;
601
+ } else t34 = $[106];
602
+ let t35;
603
+ if ($[107] !== closeConfirmation || $[108] !== confirming || $[109] !== preview || $[110] !== t34) {
604
+ t35 = /* @__PURE__ */ jsx(ConfirmDialog, {
605
+ event: confirming,
606
+ preview,
607
+ onConfirm: t34,
608
+ onCancel: closeConfirmation
609
+ });
610
+ $[107] = closeConfirmation;
611
+ $[108] = confirming;
612
+ $[109] = preview;
613
+ $[110] = t34;
614
+ $[111] = t35;
615
+ } else t35 = $[111];
616
+ let t36;
617
+ if ($[112] !== t25 || $[113] !== t26 || $[114] !== t29 || $[115] !== t30 || $[116] !== t32 || $[117] !== t33 || $[118] !== t35) {
618
+ t36 = /* @__PURE__ */ jsxs("div", {
619
+ className: t25,
620
+ children: [
621
+ t26,
622
+ t29,
623
+ t30,
624
+ t32,
625
+ t33,
626
+ t35
627
+ ]
628
+ });
629
+ $[112] = t25;
630
+ $[113] = t26;
631
+ $[114] = t29;
632
+ $[115] = t30;
633
+ $[116] = t32;
634
+ $[117] = t33;
635
+ $[118] = t35;
636
+ $[119] = t36;
637
+ } else t36 = $[119];
638
+ return t36;
639
+ }
640
+ function _temp5(column_0) {
641
+ return column_0.sortable === true;
642
+ }
643
+ function _temp4(item_4) {
644
+ return item_4.id;
645
+ }
646
+ function _temp3(action_1) {
647
+ return hasScope(action_1, "resource");
648
+ }
649
+ function _temp2(action_0) {
650
+ return hasScope(action_0, "selection");
651
+ }
652
+ function _temp(action, index, all) {
653
+ return (hasScope(action, "selection") || hasScope(action, "resource")) && all.findIndex((candidate) => candidate.id === action.id) === index;
321
654
  }
322
655
  //#endregion
323
656
  export { ListView };