@panneau/lists 5.0.0-alpha.15 → 5.0.0-alpha.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ListView.d.ts +7 -1
- package/dist/ListView.d.ts.map +1 -1
- package/dist/ListView.js +302 -297
- package/dist/ListView.js.map +1 -1
- package/dist/actions/ActionButton.d.ts +7 -1
- package/dist/actions/ActionButton.d.ts.map +1 -1
- package/dist/actions/ActionButton.js +74 -72
- package/dist/actions/ActionButton.js.map +1 -1
- package/dist/actions/Actions.css +12 -0
- package/dist/actions/Actions.module.js +6 -2
- package/dist/actions/Actions.module.js.map +1 -1
- package/dist/actions/RowActions.d.ts +21 -4
- package/dist/actions/RowActions.d.ts.map +1 -1
- package/dist/actions/RowActions.js +149 -84
- package/dist/actions/RowActions.js.map +1 -1
- package/dist/actions/fit.d.ts +25 -0
- package/dist/actions/fit.d.ts.map +1 -0
- package/dist/actions/fit.js +197 -0
- package/dist/actions/fit.js.map +1 -0
- package/dist/actions/icons.d.ts +5 -0
- package/dist/actions/icons.d.ts.map +1 -1
- package/dist/actions/icons.js +15 -1
- package/dist/actions/icons.js.map +1 -1
- package/dist/displays/Displays.css +19 -1
- package/dist/displays/Displays.module.js +8 -2
- package/dist/displays/Displays.module.js.map +1 -1
- package/dist/displays/displays.d.ts +31 -8
- package/dist/displays/displays.d.ts.map +1 -1
- package/dist/displays/displays.js +615 -164
- package/dist/displays/displays.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/layouts/CalendarLayout.d.ts +4 -4
- package/dist/layouts/CalendarLayout.d.ts.map +1 -1
- package/dist/layouts/CalendarLayout.js +25 -20
- package/dist/layouts/CalendarLayout.js.map +1 -1
- package/dist/layouts/CardsLayout.d.ts.map +1 -1
- package/dist/layouts/CardsLayout.js +90 -93
- package/dist/layouts/CardsLayout.js.map +1 -1
- package/dist/layouts/GalleryLayout.css +7 -0
- package/dist/layouts/GalleryLayout.d.ts.map +1 -1
- package/dist/layouts/GalleryLayout.js +76 -53
- package/dist/layouts/GalleryLayout.js.map +1 -1
- package/dist/layouts/GalleryLayout.module.js.map +1 -1
- package/dist/layouts/TableLayout.d.ts.map +1 -1
- package/dist/layouts/TableLayout.js +120 -93
- package/dist/layouts/TableLayout.js.map +1 -1
- package/dist/layouts/calendarDays.d.ts +14 -0
- package/dist/layouts/calendarDays.d.ts.map +1 -0
- package/dist/layouts/calendarDays.js +44 -0
- package/dist/layouts/calendarDays.js.map +1 -0
- package/dist/query.d.ts +3 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +15 -4
- package/dist/query.js.map +1 -1
- package/dist/types.d.ts +9 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RowActions.d.ts","sourceRoot":"","sources":["../../src/actions/RowActions.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RowActions.d.ts","sourceRoot":"","sources":["../../src/actions/RowActions.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAOhD,OAAO,EAAE,KAAK,WAAW,EAAiB,MAAM,SAAS,CAAC;AAE1D,MAAM,WAAW,eAAe;IAC5B,sEAAsE;IACtE,SAAS,EAAE,MAAM,CAAC;IAClB,4FAA4F;IAC5F,OAAO,EAAE,SAAS,UAAU,EAAE,CAAC;IAC/B,uFAAuF;IACvF,IAAI,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5B,6DAA6D;IAC7D,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,8DAA8D;IAC9D,KAAK,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IAChC;;;OAGG;IACH,KAAK,CAAC,EAAE,SAAS,UAAU,EAAE,GAAG,SAAS,CAAC;IAC1C,mFAAmF;IACnF,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CACvC;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC3B,OAAO,EAAE,SAAS,UAAU,EAAE,EAC9B,IAAI,EAAE,SAAS,UAAU,EAAE,GAC5B,UAAU,EAAE,CASd;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,EACvB,SAAS,EACT,OAAO,EACP,IAAI,EACJ,OAAO,EACP,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAc,GACjB,EAAE,eAAe,+BA0FjB"}
|
|
@@ -1,105 +1,170 @@
|
|
|
1
1
|
import { messages } from "../messages.js";
|
|
2
2
|
import Actions_module_default from "./Actions.module.js";
|
|
3
3
|
import { getActionIcon } from "./icons.js";
|
|
4
|
+
import { RowActionsFit } from "./fit.js";
|
|
4
5
|
import { ActionButton } from "./ActionButton.js";
|
|
5
6
|
import { c } from "react/compiler-runtime";
|
|
6
7
|
import { getActionLabel } from "@panneau/intl";
|
|
7
8
|
import { IconButton, Menu, MenuItem, MenuTrigger, usePanneauIntl } from "@panneau/ui";
|
|
8
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
10
|
import { Ellipsis } from "lucide-react";
|
|
11
|
+
import { use } from "react";
|
|
10
12
|
//#region src/actions/RowActions.tsx
|
|
11
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* The actions of a row in their order: those placed in `row`, then those placed in `menu`, and
|
|
15
|
+
* those that destroy last. The last ones are the first to go in the menu.
|
|
16
|
+
*/
|
|
17
|
+
function orderRowActions(actions, menu) {
|
|
18
|
+
const all = [...actions, ...menu].filter((entry, index, list) => list.findIndex((other) => other.action.id === entry.action.id) === index);
|
|
19
|
+
return [...all.filter(({ action }) => action.destructive !== true), ...all.filter(({ action }) => action.destructive === true)];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The actions of a row (decision 0060): their icons, in their colors, with their labels as names
|
|
23
|
+
* and tooltips, but the main action, which keeps its label while the row has room; and when the
|
|
24
|
+
* icons don't fit, the last ones in an overflow menu, which never holds a single action. How they fit is the same for every row of the list (`RowActionsFit`), and a
|
|
25
|
+
* row keeps the place of the actions of other rows that it doesn't have, so they line up.
|
|
26
|
+
*/
|
|
12
27
|
function RowActions(t0) {
|
|
13
|
-
const $ = c(
|
|
14
|
-
const { itemLabel, actions, menu, pending, onRun, icons } = t0;
|
|
28
|
+
const $ = c(30);
|
|
29
|
+
const { itemLabel, actions, menu, pending, onRun, icons, slots, primary: t1 } = t0;
|
|
30
|
+
const primary = t1 === void 0 ? null : t1;
|
|
15
31
|
const intl = usePanneauIntl();
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
href,
|
|
26
|
-
isPending: pending === action.id,
|
|
27
|
-
isDisabled: pending !== null && pending !== action.id,
|
|
28
|
-
"aria-label": intl.formatMessage(messages.actionOnItem, {
|
|
29
|
-
action: getActionLabel(action, intl),
|
|
30
|
-
item: itemLabel
|
|
31
|
-
}),
|
|
32
|
-
onPress: () => onRun(action)
|
|
33
|
-
}, action.id);
|
|
32
|
+
const level = use(RowActionsFit);
|
|
33
|
+
let t2;
|
|
34
|
+
if ($[0] !== actions || $[1] !== icons || $[2] !== intl || $[3] !== itemLabel || $[4] !== level || $[5] !== menu || $[6] !== onRun || $[7] !== pending || $[8] !== primary || $[9] !== slots) {
|
|
35
|
+
const own = orderRowActions(actions, menu);
|
|
36
|
+
let t3;
|
|
37
|
+
if ($[11] !== slots) {
|
|
38
|
+
t3 = (t4) => {
|
|
39
|
+
const { action } = t4;
|
|
40
|
+
return slots?.some((slot) => slot.action.id === action.id) !== true;
|
|
34
41
|
};
|
|
35
|
-
$[
|
|
36
|
-
$[
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
$[11] = slots;
|
|
43
|
+
$[12] = t3;
|
|
44
|
+
} else t3 = $[12];
|
|
45
|
+
const all = [...slots ?? [], ...own.filter(t3)];
|
|
46
|
+
const find = (slot_0) => own.find((t4) => {
|
|
47
|
+
const { action: action_0 } = t4;
|
|
48
|
+
return action_0.id === slot_0.action.id;
|
|
49
|
+
});
|
|
50
|
+
const inMenu = level >= 2 && all.length >= 2 ? Math.min(level, all.length) : 0;
|
|
51
|
+
const shown = all.slice(0, all.length - inMenu);
|
|
52
|
+
const overflow = all.slice(all.length - inMenu).flatMap((slot_1) => find(slot_1) ?? []);
|
|
53
|
+
let t5;
|
|
54
|
+
if ($[13] !== intl || $[14] !== itemLabel) {
|
|
55
|
+
t5 = (action_1) => intl.formatMessage(messages.actionOnItem, {
|
|
56
|
+
action: getActionLabel(action_1, intl),
|
|
57
|
+
item: itemLabel
|
|
58
|
+
});
|
|
59
|
+
$[13] = intl;
|
|
60
|
+
$[14] = itemLabel;
|
|
61
|
+
$[15] = t5;
|
|
62
|
+
} else t5 = $[15];
|
|
63
|
+
const name = t5;
|
|
64
|
+
let t6;
|
|
65
|
+
if ($[16] !== icons || $[17] !== level || $[18] !== name || $[19] !== onRun || $[20] !== pending || $[21] !== primary) {
|
|
66
|
+
t6 = (entry) => /* @__PURE__ */ jsx(ActionButton, {
|
|
67
|
+
action: entry.action,
|
|
68
|
+
icons,
|
|
69
|
+
href: entry.href,
|
|
70
|
+
iconOnly: level >= 1 || entry.action.id !== primary,
|
|
71
|
+
isPending: pending === entry.action.id,
|
|
72
|
+
isDisabled: pending !== null && pending !== entry.action.id,
|
|
73
|
+
"aria-label": name(entry.action),
|
|
74
|
+
onPress: () => onRun(entry.action)
|
|
75
|
+
}, entry.action.id);
|
|
76
|
+
$[16] = icons;
|
|
77
|
+
$[17] = level;
|
|
78
|
+
$[18] = name;
|
|
79
|
+
$[19] = onRun;
|
|
80
|
+
$[20] = pending;
|
|
81
|
+
$[21] = primary;
|
|
82
|
+
$[22] = t6;
|
|
83
|
+
} else t6 = $[22];
|
|
84
|
+
const button = t6;
|
|
85
|
+
const placeholder = _temp;
|
|
86
|
+
let t7;
|
|
87
|
+
if ($[23] !== intl || $[24] !== itemLabel) {
|
|
88
|
+
t7 = intl.formatMessage(messages.itemActions, { item: itemLabel });
|
|
89
|
+
$[23] = intl;
|
|
90
|
+
$[24] = itemLabel;
|
|
91
|
+
$[25] = t7;
|
|
92
|
+
} else t7 = $[25];
|
|
93
|
+
const t8 = overflow.length >= 2;
|
|
94
|
+
const t9 = pending !== null && overflow.some((t10) => {
|
|
95
|
+
const { action: action_2 } = t10;
|
|
96
|
+
return action_2.id === pending;
|
|
97
|
+
});
|
|
98
|
+
let t11;
|
|
99
|
+
if ($[26] !== t7 || $[27] !== t8 || $[28] !== t9) {
|
|
100
|
+
t11 = /* @__PURE__ */ jsx(IconButton, {
|
|
101
|
+
icon: Ellipsis,
|
|
102
|
+
size: "sm",
|
|
103
|
+
appearance: "subtle",
|
|
104
|
+
label: t7,
|
|
105
|
+
showTooltip: t8,
|
|
106
|
+
isPending: t9
|
|
107
|
+
});
|
|
108
|
+
$[26] = t7;
|
|
109
|
+
$[27] = t8;
|
|
110
|
+
$[28] = t9;
|
|
111
|
+
$[29] = t11;
|
|
112
|
+
} else t11 = $[29];
|
|
113
|
+
const menuButton = t11;
|
|
114
|
+
t2 = /* @__PURE__ */ jsxs("div", {
|
|
115
|
+
className: Actions_module_default.row,
|
|
116
|
+
"data-row-actions": all.length,
|
|
117
|
+
children: [shown.map((slot_2) => {
|
|
118
|
+
const entry_0 = find(slot_2);
|
|
119
|
+
return entry_0 !== void 0 ? button(entry_0) : placeholder(slot_2.action.id, button({
|
|
120
|
+
...slot_2,
|
|
121
|
+
href: null
|
|
122
|
+
}));
|
|
123
|
+
}), overflow.length >= 2 ? /* @__PURE__ */ jsxs(MenuTrigger, { children: [menuButton, /* @__PURE__ */ jsx(Menu, {
|
|
124
|
+
placement: "bottom end",
|
|
125
|
+
onAction: (key_0) => {
|
|
126
|
+
const entry_1 = overflow.find((t12) => {
|
|
127
|
+
const { action: action_3 } = t12;
|
|
128
|
+
return action_3.id === key_0;
|
|
129
|
+
});
|
|
130
|
+
if (entry_1 !== void 0 && entry_1.href === null) onRun(entry_1.action);
|
|
131
|
+
},
|
|
132
|
+
children: overflow.map((t13) => {
|
|
133
|
+
const { action: action_4, href } = t13;
|
|
134
|
+
const icon = getActionIcon(action_4, icons);
|
|
135
|
+
return /* @__PURE__ */ jsx(MenuItem, {
|
|
136
|
+
id: action_4.id,
|
|
137
|
+
isDanger: action_4.destructive === true,
|
|
138
|
+
...icon !== void 0 ? { icon } : {},
|
|
139
|
+
...href !== null ? { href } : {},
|
|
140
|
+
children: getActionLabel(action_4, intl)
|
|
141
|
+
}, action_4.id);
|
|
142
|
+
})
|
|
143
|
+
})] }) : overflow.length === 1 && overflow[0] !== void 0 ? button(overflow[0]) : inMenu > 0 ? placeholder("menu", menuButton) : null]
|
|
144
|
+
});
|
|
43
145
|
$[0] = actions;
|
|
44
146
|
$[1] = icons;
|
|
45
147
|
$[2] = intl;
|
|
46
148
|
$[3] = itemLabel;
|
|
47
|
-
$[4] =
|
|
48
|
-
$[5] =
|
|
49
|
-
$[6] =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const entry = menu.find((t4) => {
|
|
65
|
-
const { action: action_1 } = t4;
|
|
66
|
-
return action_1.id === key;
|
|
67
|
-
});
|
|
68
|
-
if (entry !== void 0 && entry.href === null) onRun(entry.action);
|
|
69
|
-
},
|
|
70
|
-
children: menu.map((t5) => {
|
|
71
|
-
const { action: action_2, href: href_0 } = t5;
|
|
72
|
-
const icon = getActionIcon(action_2, icons);
|
|
73
|
-
return /* @__PURE__ */ jsx(MenuItem, {
|
|
74
|
-
id: action_2.id,
|
|
75
|
-
isDanger: action_2.destructive === true,
|
|
76
|
-
...icon !== void 0 ? { icon } : {},
|
|
77
|
-
...href_0 !== null ? { href: href_0 } : {},
|
|
78
|
-
children: getActionLabel(action_2, intl)
|
|
79
|
-
}, action_2.id);
|
|
80
|
-
})
|
|
81
|
-
})] }) : null;
|
|
82
|
-
$[13] = icons;
|
|
83
|
-
$[14] = intl;
|
|
84
|
-
$[15] = itemLabel;
|
|
85
|
-
$[16] = menu;
|
|
86
|
-
$[17] = onRun;
|
|
87
|
-
$[18] = pending;
|
|
88
|
-
$[19] = t2;
|
|
89
|
-
} else t2 = $[19];
|
|
90
|
-
let t3;
|
|
91
|
-
if ($[20] !== t1 || $[21] !== t2) {
|
|
92
|
-
t3 = /* @__PURE__ */ jsxs("div", {
|
|
93
|
-
className: Actions_module_default.row,
|
|
94
|
-
children: [t1, t2]
|
|
95
|
-
});
|
|
96
|
-
$[20] = t1;
|
|
97
|
-
$[21] = t2;
|
|
98
|
-
$[22] = t3;
|
|
99
|
-
} else t3 = $[22];
|
|
100
|
-
return t3;
|
|
149
|
+
$[4] = level;
|
|
150
|
+
$[5] = menu;
|
|
151
|
+
$[6] = onRun;
|
|
152
|
+
$[7] = pending;
|
|
153
|
+
$[8] = primary;
|
|
154
|
+
$[9] = slots;
|
|
155
|
+
$[10] = t2;
|
|
156
|
+
} else t2 = $[10];
|
|
157
|
+
return t2;
|
|
158
|
+
}
|
|
159
|
+
function _temp(key, content) {
|
|
160
|
+
return /* @__PURE__ */ jsx("span", {
|
|
161
|
+
className: Actions_module_default.placeholder,
|
|
162
|
+
"aria-hidden": "true",
|
|
163
|
+
inert: true,
|
|
164
|
+
children: content
|
|
165
|
+
}, key);
|
|
101
166
|
}
|
|
102
167
|
//#endregion
|
|
103
|
-
export { RowActions };
|
|
168
|
+
export { RowActions, orderRowActions };
|
|
104
169
|
|
|
105
170
|
//# sourceMappingURL=RowActions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RowActions.js","names":["Ellipsis","ItemAction","getActionLabel","Action","IconButton","Menu","MenuItem","MenuTrigger","usePanneauIntl","messages","ActionButton","styles","ActionIcons","getActionIcon","RowActionsProps","itemLabel","actions","menu","pending","onRun","action","icons","RowActions","t0","$","_c","intl","t1","t2","t3","href","id","formatMessage","actionOnItem","item","map","length","itemActions","some","action_0","key","entry","find","t4","action_1","undefined","t5","action_2","href_0","icon","destructive","row","_c","styles"],"sources":["../../src/actions/RowActions.tsx"],"sourcesContent":["import { Ellipsis } from 'lucide-react';\n\nimport type { ItemAction } from '@panneau/core';\nimport { getActionLabel } from '@panneau/intl';\nimport type { Action } from '@panneau/protocol';\nimport { IconButton, Menu, MenuItem, MenuTrigger, usePanneauIntl } from '@panneau/ui';\n\nimport { messages } from '../messages';\nimport { ActionButton } from './ActionButton';\nimport styles from './Actions.module.css';\nimport { type ActionIcons, getActionIcon } from './icons';\n\nexport interface RowActionsProps {\n /** The label of the item, for the accessible names of its actions. */\n itemLabel: string;\n /** Actions shown as buttons, with their links (`getItemActions()` of `@panneau/core`). */\n actions: readonly ItemAction[];\n /** Actions in the overflow menu. */\n menu: readonly ItemAction[];\n /** Id of the action that is running on this item, if any. */\n pending: string | null;\n onRun: (action: Action) => void;\n /** Icons of actions by id, over the icon the action names. */\n icons?: ActionIcons | undefined;\n}\n\n/** The actions of a row: buttons, then an overflow menu. */\nexport function RowActions({ itemLabel, actions, menu, pending, onRun, icons }: RowActionsProps) {\n const intl = usePanneauIntl();\n return (\n <div className={styles.row}>\n {actions.map(({ action, href }) => (\n <ActionButton\n key={action.id}\n action={action}\n icons={icons}\n href={href}\n isPending={pending === action.id}\n isDisabled={pending !== null && pending !== action.id}\n aria-label={intl.formatMessage(messages.actionOnItem, {\n action: getActionLabel(action, intl),\n item: itemLabel,\n })}\n onPress={() => onRun(action)}\n />\n ))}\n {menu.length > 0 ? (\n <MenuTrigger>\n <IconButton\n icon={Ellipsis}\n size=\"sm\"\n label={intl.formatMessage(messages.itemActions, { item: itemLabel })}\n isPending={\n pending !== null && menu.some(({ action }) => action.id === pending)\n }\n />\n <Menu\n placement=\"bottom end\"\n onAction={(key) => {\n const entry = menu.find(({ action }) => action.id === key);\n if (entry !== undefined && entry.href === null) {\n onRun(entry.action);\n }\n }}\n >\n {menu.map(({ action, href }) => {\n const icon = getActionIcon(action, icons);\n return (\n <MenuItem\n key={action.id}\n id={action.id}\n isDanger={action.destructive === true}\n {...(icon !== undefined ? { icon } : {})}\n {...(href !== null ? { href } : {})}\n >\n {getActionLabel(action, intl)}\n </MenuItem>\n );\n })}\n </Menu>\n </MenuTrigger>\n ) : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;AA2BA,SAAOsB,WAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAoB,MAAA,EAAAV,WAAAC,SAAAC,MAAAC,SAAAC,OAAAE,UAAAE;CACvB,MAAAG,OAAalB,eAAe;CAAE,IAAAmB;CAAA,IAAAH,EAAA,OAAAR,WAAAQ,EAAA,OAAAH,SAAAG,EAAA,OAAAE,QAAAF,EAAA,OAAAT,aAAAS,EAAA,OAAAL,SAAAK,EAAA,OAAAN,SAAA;EAAA,IAAAU;EAAA,IAAAJ,EAAA,OAAAH,SAAAG,EAAA,OAAAE,QAAAF,EAAA,OAAAT,aAAAS,EAAA,QAAAL,SAAAK,EAAA,QAAAN,SAAA;GAGTU,MAAAC,OAAA;IAAC,MAAA,EAAAT,QAAAU,SAAAD;IAAgB,OAC1B,oBAAC,cAAD;KAEYT;KACDC;KACDS;KACK,WAAAZ,YAAYE,OAAMW;KACjB,YAAAb,YAAY,QAAQA,YAAYE,OAAMW;KACtC,cAAAL,KAAIM,cAAevB,SAAQwB,cAAe;MAAAb,QAC1ClB,eAAekB,QAAQM,IAAI;MAACQ,MAC9BnB;KACV,CAAC;KACQ,eAAMI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O,UAAQC,KAAK;IAAE,OAEtC,oBAAC,UAAD;KAEQ,IAAAD,SAAMW;KACA,UAAAX,SAAM8B,gBAAiB;KAAI,GAChCD,SAASJ,KAAAA,IAAT,EAAAI,KAAiC,IAAjC,CAAiC;KAAC,GAClCnB,WAAS,OAAT,EAAAA,MAAkBA,OAAU,IAA5B,CAA4B;KAEhC5B,UAAAA,eAAekB,UAAQM,IAAI;IAPvB,GACAN,SAAMW,EADN;GAQE,CAElB;EAtBA,CAAA,CATG,EAAA,CAAA,IADf;EAmCOP,EAAA,MAAAH;EAAAG,EAAA,MAAAE;EAAAF,EAAA,MAAAT;EAAAS,EAAA,MAAAP;EAAAO,EAAA,MAAAL;EAAAK,EAAA,MAAAN;EAAAM,EAAA,MAAAI;CAAA,OAAAA,KAAAJ,EAAA;CAAA,IAAAK;CAAA,IAAAL,EAAA,QAAAG,MAAAH,EAAA,QAAAI,IAAA;EAnDZC,KAAA,qBAAA,OAAA;GAAgB,WAAAlB,uBAAMwC;GAAtB,UAAA,CACKxB,IAeAC,EAoCC;;EAAAJ,EAAA,MAAAG;EAAAH,EAAA,MAAAI;EAAAJ,EAAA,MAAAK;CAAA,OAAAA,KAAAL,EAAA;CAAA,OApDNK;AAoDM"}
|
|
1
|
+
{"version":3,"file":"RowActions.js","names":["Ellipsis","ReactNode","use","ItemAction","getActionLabel","Action","IconButton","Menu","MenuItem","MenuTrigger","usePanneauIntl","messages","ActionButton","styles","RowActionsFit","ActionIcons","getActionIcon","RowActionsProps","itemLabel","actions","menu","pending","onRun","action","icons","slots","primary","orderRowActions","all","filter","entry","index","list","findIndex","other","id","destructive","RowActions","t0","$","_c","t1","undefined","intl","level","t2","own","t3","t4","some","slot","find","slot_0","action_0","inMenu","length","Math","min","shown","slice","overflow","flatMap","slot_1","t5","action_1","formatMessage","actionOnItem","item","name","t6","href","button","placeholder","_temp","t7","itemActions","t8","t9","t10","action_2","t11","menuButton","row","map","slot_2","entry_0","key_0","entry_1","t12","action_3","key","t13","action_4","icon","content","_c","styles"],"sources":["../../src/actions/RowActions.tsx"],"sourcesContent":["import { Ellipsis } from 'lucide-react';\nimport { type ReactNode, use } from 'react';\n\nimport type { ItemAction } from '@panneau/core';\nimport { getActionLabel } from '@panneau/intl';\nimport type { Action } from '@panneau/protocol';\nimport { IconButton, Menu, MenuItem, MenuTrigger, usePanneauIntl } from '@panneau/ui';\n\nimport { messages } from '../messages';\nimport { ActionButton } from './ActionButton';\nimport styles from './Actions.module.css';\nimport { RowActionsFit } from './fit';\nimport { type ActionIcons, getActionIcon } from './icons';\n\nexport interface RowActionsProps {\n /** The label of the item, for the accessible names of its actions. */\n itemLabel: string;\n /** Actions placed in `row`, with their links (`selectItemActions()` of `@panneau/core`). */\n actions: readonly ItemAction[];\n /** Actions placed in `menu`: icons too while they fit, the first to go in the menu. */\n menu: readonly ItemAction[];\n /** Id of the action that is running on this item, if any. */\n pending: string | null;\n onRun: (action: Action) => void;\n /** Icons of actions by id, over the icon the action names. */\n icons?: ActionIcons | undefined;\n /**\n * The actions of every row of the list, in order (`orderRowActions()`): a row keeps the place\n * of those it doesn't have, so the actions of the rows line up. Without it, its own.\n */\n slots?: readonly ItemAction[] | undefined;\n /** The id of the main action of rows, which keeps its label (`show` or `edit`). */\n primary?: string | null | undefined;\n}\n\n/**\n * The actions of a row in their order: those placed in `row`, then those placed in `menu`, and\n * those that destroy last. The last ones are the first to go in the menu.\n */\nexport function orderRowActions(\n actions: readonly ItemAction[],\n menu: readonly ItemAction[],\n): ItemAction[] {\n const all = [...actions, ...menu].filter(\n (entry, index, list) =>\n list.findIndex((other) => other.action.id === entry.action.id) === index,\n );\n return [\n ...all.filter(({ action }) => action.destructive !== true),\n ...all.filter(({ action }) => action.destructive === true),\n ];\n}\n\n/**\n * The actions of a row (decision 0060): their icons, in their colors, with their labels as names\n * and tooltips, but the main action, which keeps its label while the row has room; and when the\n * icons don't fit, the last ones in an overflow menu, which never holds a single action. How they fit is the same for every row of the list (`RowActionsFit`), and a\n * row keeps the place of the actions of other rows that it doesn't have, so they line up.\n */\nexport function RowActions({\n itemLabel,\n actions,\n menu,\n pending,\n onRun,\n icons,\n slots,\n primary = null,\n}: RowActionsProps) {\n const intl = usePanneauIntl();\n const level = use(RowActionsFit);\n const own = orderRowActions(actions, menu);\n const all = [\n ...(slots ?? []),\n ...own.filter(({ action }) => slots?.some((slot) => slot.action.id === action.id) !== true),\n ];\n const find = (slot: ItemAction) => own.find(({ action }) => action.id === slot.action.id);\n const inMenu = level >= 2 && all.length >= 2 ? Math.min(level, all.length) : 0;\n const shown = all.slice(0, all.length - inMenu);\n const overflow = all.slice(all.length - inMenu).flatMap((slot) => find(slot) ?? []);\n const name = (action: Action) =>\n intl.formatMessage(messages.actionOnItem, {\n action: getActionLabel(action, intl),\n item: itemLabel,\n });\n const button = (entry: ItemAction) => (\n <ActionButton\n key={entry.action.id}\n action={entry.action}\n icons={icons}\n href={entry.href}\n iconOnly={level >= 1 || entry.action.id !== primary}\n isPending={pending === entry.action.id}\n isDisabled={pending !== null && pending !== entry.action.id}\n aria-label={name(entry.action)}\n onPress={() => onRun(entry.action)}\n />\n );\n // The place of an action of other rows: the same button, unseen and out of reach\n const placeholder = (key: string, content: ReactNode) => (\n <span key={key} className={styles.placeholder} aria-hidden=\"true\" inert>\n {content}\n </span>\n );\n const menuButton = (\n <IconButton\n icon={Ellipsis}\n size=\"sm\"\n appearance=\"subtle\"\n label={intl.formatMessage(messages.itemActions, { item: itemLabel })}\n showTooltip={overflow.length >= 2}\n isPending={pending !== null && overflow.some(({ action }) => action.id === pending)}\n />\n );\n return (\n <div className={styles.row} data-row-actions={all.length}>\n {shown.map((slot) => {\n const entry = find(slot);\n return entry !== undefined\n ? button(entry)\n : placeholder(slot.action.id, button({ ...slot, href: null }));\n })}\n {overflow.length >= 2 ? (\n <MenuTrigger>\n {menuButton}\n <Menu\n placement=\"bottom end\"\n onAction={(key) => {\n const entry = overflow.find(({ action }) => action.id === key);\n if (entry !== undefined && entry.href === null) {\n onRun(entry.action);\n }\n }}\n >\n {overflow.map(({ action, href }) => {\n const icon = getActionIcon(action, icons);\n return (\n <MenuItem\n key={action.id}\n id={action.id}\n isDanger={action.destructive === true}\n {...(icon !== undefined ? { icon } : {})}\n {...(href !== null ? { href } : {})}\n >\n {getActionLabel(action, intl)}\n </MenuItem>\n );\n })}\n </Menu>\n </MenuTrigger>\n ) : overflow.length === 1 && overflow[0] !== undefined ? (\n // A single action is no menu: its button, in the menu's place\n button(overflow[0])\n ) : inMenu > 0 ? (\n placeholder('menu', menuButton)\n ) : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAuCA,SAAgB2B,gBACZR,SACAC,MACY;CACZ,MAAMQ,MAAM,CAAC,GAAGT,SAAS,GAAGC,IAAI,CAAC,CAACS,QAC7BC,OAAOC,OAAOC,SACXA,KAAKC,WAAWC,UAAUA,MAAMX,OAAOY,OAAOL,MAAMP,OAAOY,EAAE,MAAMJ,KAC3E;CACA,OAAO,CACH,GAAGH,IAAIC,QAAQ,EAAEN,aAAaA,OAAOa,gBAAgB,IAAI,GACzD,GAAGR,IAAIC,QAAQ,EAAEN,aAAaA,OAAOa,gBAAgB,IAAI,CAAC;AAElE;;;;;;;AAQA,SAAOC,WAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAoB,MAAA,EAAAtB,WAAAC,SAAAC,MAAAC,SAAAC,OAAAE,OAAAC,OAAAC,SAAAe,OAAAH;CAQvB,MAAAZ,UAAAe,OAAAC,KAAAA,IAAA,OAAAD;CAEA,MAAAE,OAAajC,eAAe;CAC5B,MAAAkC,QAAc1C,IAAIY,aAAa;CAAE,IAAA+B;CAAA,IAAAN,EAAA,OAAApB,WAAAoB,EAAA,OAAAf,SAAAe,EAAA,OAAAI,QAAAJ,EAAA,OAAArB,aAAAqB,EAAA,OAAAK,SAAAL,EAAA,OAAAnB,QAAAmB,EAAA,OAAAjB,SAAAiB,EAAA,OAAAlB,WAAAkB,EAAA,OAAAb,WAA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AAA,IAEzC6B,OAAOX,SAAQ,EAGZ,IAFHN,SAAS,IACTkB,YAAY,QAAQS,UACjB,IAFH,IAGF;;EAAA1C,EAAA,KAAApB;EAAAoB,EAAA,KAAAf;EAAAe,EAAA,KAAAI;EAAAJ,EAAA,KAAArB;EAAAqB,EAAA,KAAAK;EAAAL,EAAA,KAAAnB;EAAAmB,EAAA,KAAAjB;EAAAiB,EAAA,KAAAlB;EAAAkB,EAAA,KAAAb;EAAAa,EAAA,KAAAd;EAAAc,EAAA,MAAAM;CAAA,OAAAA,KAAAN,EAAA;CAAA,OAzCNM;AAyCM;AAjGP,SAAA4B,MAAAiB,KAAAI,SAAA;CAAA,OAyCC,oBAAA,QAAA;EAA2B,WAAAjF,uBAAM2D;EAA0B,eAAA;EAAO,OAAA;EAC7DsB,UAAAA;CACE,GAFIJ,GAEJ;AAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the actions of rows fit (decision 0060), the same for every row of a list: `0`, every
|
|
3
|
+
* action as an icon but the main one, with its label; `1`, every action as an icon; `n` from 2,
|
|
4
|
+
* the last `n` actions of each row in its menu.
|
|
5
|
+
*/
|
|
6
|
+
export declare const RowActionsFit: import("react").Context<number>;
|
|
7
|
+
/** What the fit of a list depends on, besides its width: its items and its columns. */
|
|
8
|
+
export declare function fitContent(items: readonly {
|
|
9
|
+
id: string;
|
|
10
|
+
}[], columns: readonly {
|
|
11
|
+
id: string;
|
|
12
|
+
}[]): string;
|
|
13
|
+
/**
|
|
14
|
+
* Fits the actions of the rows of a list in the room they have (decision 0060). It draws each
|
|
15
|
+
* level in turn, from every action as an icon but the main one, labelled, then the main one as an
|
|
16
|
+
* icon too, then a menu of two actions, three…, while the next one may help, and keeps the best:
|
|
17
|
+
* where the actions crowd least (the list overflows, the actions of a row wrap or take more than
|
|
18
|
+
* 40% of it), then, on rows of five actions or more, where the rows are shortest (their content
|
|
19
|
+
* wraps or is cut less), then the fewest actions in the menu.
|
|
20
|
+
*
|
|
21
|
+
* @returns the level, and a callback ref for the element to measure: the list, which holds the
|
|
22
|
+
* actions.
|
|
23
|
+
*/
|
|
24
|
+
export declare function useRowActionsFit(content: string): [level: number, measure: (element: HTMLElement | null) => void];
|
|
25
|
+
//# sourceMappingURL=fit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fit.d.ts","sourceRoot":"","sources":["../../src/actions/fit.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,aAAa,iCAAmB,CAAC;AAE9C,uFAAuF;AACvF,wBAAgB,UAAU,CACtB,KAAK,EAAE,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,EAChC,OAAO,EAAE,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,GACnC,MAAM,CAER;AAgKD;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC5B,OAAO,EAAE,MAAM,GAChB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,KAAK,IAAI,CAAC,CA8BjE"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { c } from "react/compiler-runtime";
|
|
2
|
+
import { createContext, useEffect, useLayoutEffect, useState, useSyncExternalStore } from "react";
|
|
3
|
+
//#region src/actions/fit.ts
|
|
4
|
+
/**
|
|
5
|
+
* How the actions of rows fit (decision 0060), the same for every row of a list: `0`, every
|
|
6
|
+
* action as an icon but the main one, with its label; `1`, every action as an icon; `n` from 2,
|
|
7
|
+
* the last `n` actions of each row in its menu.
|
|
8
|
+
*/
|
|
9
|
+
var RowActionsFit = createContext(0);
|
|
10
|
+
/** What the fit of a list depends on, besides its width: its items and its columns. */
|
|
11
|
+
function fitContent(items, columns) {
|
|
12
|
+
return `${items.map((item) => item.id).join("\0")}\u0001${columns.map((column) => column.id).join("\0")}`;
|
|
13
|
+
}
|
|
14
|
+
/** Past that many actions in the menu, a row has nothing left to free. */
|
|
15
|
+
var MAX_LEVEL = 12;
|
|
16
|
+
/** The most of the width of its row that the actions of an item take before they crowd it. */
|
|
17
|
+
var SHARE = .4;
|
|
18
|
+
/**
|
|
19
|
+
* From that many actions on a row, they also go to the menu to give the content room, as long as
|
|
20
|
+
* `SHOWN` of them stay out of it.
|
|
21
|
+
*/
|
|
22
|
+
var MANY = 5;
|
|
23
|
+
var SHOWN = 4;
|
|
24
|
+
function measure(element) {
|
|
25
|
+
let crowding = Math.max(0, element.scrollWidth - element.clientWidth);
|
|
26
|
+
let count = 0;
|
|
27
|
+
for (const actions of element.querySelectorAll("[data-row-actions]")) {
|
|
28
|
+
count = Math.max(count, Number(actions.dataset.rowActions));
|
|
29
|
+
const box = actions.parentElement;
|
|
30
|
+
if (box !== null) crowding += Math.max(0, box.scrollWidth - box.clientWidth);
|
|
31
|
+
const first = actions.firstElementChild;
|
|
32
|
+
if (first instanceof HTMLElement) crowding += Math.max(0, actions.offsetHeight - first.offsetHeight);
|
|
33
|
+
const row = actions.closest("tr, li") ?? element;
|
|
34
|
+
crowding += Math.max(0, actions.offsetWidth - row.offsetWidth * SHARE);
|
|
35
|
+
}
|
|
36
|
+
let cut = 0;
|
|
37
|
+
for (const text of element.querySelectorAll("[data-clamp]")) cut += Math.max(0, text.scrollHeight - text.clientHeight);
|
|
38
|
+
return {
|
|
39
|
+
height: element.offsetHeight + cut,
|
|
40
|
+
crowding,
|
|
41
|
+
count
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Whether rows of `count` actions can give the content room with `level`: only when they have many
|
|
46
|
+
* actions, `SHOWN` of which stay out of the menu.
|
|
47
|
+
*/
|
|
48
|
+
function forContent(level, count) {
|
|
49
|
+
return count >= MANY && count - level >= SHOWN;
|
|
50
|
+
}
|
|
51
|
+
/** Whether the next level is worth a try, after `current`. */
|
|
52
|
+
function worthTrying(next, current) {
|
|
53
|
+
if (next === 1) return current.crowding > .5 || forContent(next, current.count);
|
|
54
|
+
return next <= Math.min(current.count, MAX_LEVEL) && current.count >= 2 && (current.crowding > .5 || forContent(next, current.count));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The best of the levels tried: the actions crowd least, then the rows are shortest (when the
|
|
58
|
+
* level may give the content room), then the fewest changes.
|
|
59
|
+
*/
|
|
60
|
+
function best(measures) {
|
|
61
|
+
let chosen = 0;
|
|
62
|
+
for (const [level, current] of measures) {
|
|
63
|
+
const kept = measures.get(chosen);
|
|
64
|
+
if (kept === void 0 || level === chosen) continue;
|
|
65
|
+
if (current.crowding < kept.crowding - .5) chosen = level;
|
|
66
|
+
else if (current.crowding <= kept.crowding + .5 && forContent(level, current.count) && current.height < kept.height - .5) chosen = level;
|
|
67
|
+
}
|
|
68
|
+
return chosen;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The level of a list, outside React: it changes while the list commits, and React draws each
|
|
72
|
+
* change at once (`useSyncExternalStore`), before the browser paints.
|
|
73
|
+
*/
|
|
74
|
+
var FitStore = class {
|
|
75
|
+
#level = 0;
|
|
76
|
+
#settled = false;
|
|
77
|
+
/** The measures of the levels tried. */
|
|
78
|
+
#measures = /* @__PURE__ */ new Map();
|
|
79
|
+
#content = null;
|
|
80
|
+
#listeners = /* @__PURE__ */ new Set();
|
|
81
|
+
subscribe = (listener) => {
|
|
82
|
+
this.#listeners.add(listener);
|
|
83
|
+
return () => this.#listeners.delete(listener);
|
|
84
|
+
};
|
|
85
|
+
getLevel = () => this.#level;
|
|
86
|
+
#set(level) {
|
|
87
|
+
if (level !== this.#level) {
|
|
88
|
+
this.#level = level;
|
|
89
|
+
for (const listener of this.#listeners) listener();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** Starts over from the labels: true when the list has to draw them first. */
|
|
93
|
+
restart() {
|
|
94
|
+
this.#settled = false;
|
|
95
|
+
this.#measures = /* @__PURE__ */ new Map();
|
|
96
|
+
const drawn = this.#level === 0;
|
|
97
|
+
this.#set(0);
|
|
98
|
+
return !drawn;
|
|
99
|
+
}
|
|
100
|
+
/** Starts over when the content changes. */
|
|
101
|
+
setContent(content) {
|
|
102
|
+
if (content === this.#content) return false;
|
|
103
|
+
this.#content = content;
|
|
104
|
+
return this.restart();
|
|
105
|
+
}
|
|
106
|
+
/** Measures the list drawn at `drawn`, then tries the next level, or settles on the best. */
|
|
107
|
+
step(element, drawn) {
|
|
108
|
+
if (this.#settled || drawn !== this.#level) return;
|
|
109
|
+
const current = measure(element);
|
|
110
|
+
this.#measures.set(drawn, current);
|
|
111
|
+
const next = drawn + 1;
|
|
112
|
+
if (worthTrying(next, current)) this.#set(next);
|
|
113
|
+
else {
|
|
114
|
+
this.#settled = true;
|
|
115
|
+
this.#set(best(this.#measures));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Fits the actions of the rows of a list in the room they have (decision 0060). It draws each
|
|
121
|
+
* level in turn, from every action as an icon but the main one, labelled, then the main one as an
|
|
122
|
+
* icon too, then a menu of two actions, three…, while the next one may help, and keeps the best:
|
|
123
|
+
* where the actions crowd least (the list overflows, the actions of a row wrap or take more than
|
|
124
|
+
* 40% of it), then, on rows of five actions or more, where the rows are shortest (their content
|
|
125
|
+
* wraps or is cut less), then the fewest actions in the menu.
|
|
126
|
+
*
|
|
127
|
+
* @returns the level, and a callback ref for the element to measure: the list, which holds the
|
|
128
|
+
* actions.
|
|
129
|
+
*/
|
|
130
|
+
function useRowActionsFit(content) {
|
|
131
|
+
const $ = c(12);
|
|
132
|
+
const [element, setElement] = useState(null);
|
|
133
|
+
const [store] = useState(_temp);
|
|
134
|
+
const level = useSyncExternalStore(store.subscribe, store.getLevel, store.getLevel);
|
|
135
|
+
let t0;
|
|
136
|
+
let t1;
|
|
137
|
+
if ($[0] !== content || $[1] !== element || $[2] !== level || $[3] !== store) {
|
|
138
|
+
t0 = () => {
|
|
139
|
+
if (element !== null && !store.setContent(content)) store.step(element, level);
|
|
140
|
+
};
|
|
141
|
+
t1 = [
|
|
142
|
+
store,
|
|
143
|
+
element,
|
|
144
|
+
content,
|
|
145
|
+
level
|
|
146
|
+
];
|
|
147
|
+
$[0] = content;
|
|
148
|
+
$[1] = element;
|
|
149
|
+
$[2] = level;
|
|
150
|
+
$[3] = store;
|
|
151
|
+
$[4] = t0;
|
|
152
|
+
$[5] = t1;
|
|
153
|
+
} else {
|
|
154
|
+
t0 = $[4];
|
|
155
|
+
t1 = $[5];
|
|
156
|
+
}
|
|
157
|
+
useLayoutEffect(t0, t1);
|
|
158
|
+
let t2;
|
|
159
|
+
let t3;
|
|
160
|
+
if ($[6] !== element || $[7] !== store) {
|
|
161
|
+
t2 = () => {
|
|
162
|
+
if (element === null || typeof ResizeObserver === "undefined") return;
|
|
163
|
+
let width = element.clientWidth;
|
|
164
|
+
const observer = new ResizeObserver(() => {
|
|
165
|
+
if (element.clientWidth !== width) {
|
|
166
|
+
width = element.clientWidth;
|
|
167
|
+
if (!store.restart()) store.step(element, 0);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
observer.observe(element);
|
|
171
|
+
return () => observer.disconnect();
|
|
172
|
+
};
|
|
173
|
+
t3 = [store, element];
|
|
174
|
+
$[6] = element;
|
|
175
|
+
$[7] = store;
|
|
176
|
+
$[8] = t2;
|
|
177
|
+
$[9] = t3;
|
|
178
|
+
} else {
|
|
179
|
+
t2 = $[8];
|
|
180
|
+
t3 = $[9];
|
|
181
|
+
}
|
|
182
|
+
useEffect(t2, t3);
|
|
183
|
+
let t4;
|
|
184
|
+
if ($[10] !== level) {
|
|
185
|
+
t4 = [level, setElement];
|
|
186
|
+
$[10] = level;
|
|
187
|
+
$[11] = t4;
|
|
188
|
+
} else t4 = $[11];
|
|
189
|
+
return t4;
|
|
190
|
+
}
|
|
191
|
+
function _temp() {
|
|
192
|
+
return new FitStore();
|
|
193
|
+
}
|
|
194
|
+
//#endregion
|
|
195
|
+
export { RowActionsFit, fitContent, useRowActionsFit };
|
|
196
|
+
|
|
197
|
+
//# sourceMappingURL=fit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fit.js","names":["createContext","useEffect","useLayoutEffect","useState","useSyncExternalStore","RowActionsFit","fitContent","items","id","columns","map","item","join","column","MAX_LEVEL","SHARE","MANY","SHOWN","Measure","height","crowding","count","measure","element","HTMLElement","Math","max","scrollWidth","clientWidth","actions","querySelectorAll","Number","dataset","rowActions","box","parentElement","first","firstElementChild","offsetHeight","row","closest","offsetWidth","cut","text","scrollHeight","clientHeight","forContent","level","worthTrying","next","current","min","best","measures","ReadonlyMap","chosen","kept","get","undefined","FitStore","settled","Map","content","listeners","Set","subscribe","listener","add","delete","getLevel","set","#set","restart","drawn","setContent","step","useRowActionsFit","$","_c","setElement","store","_temp","t0","t1","t2","t3","ResizeObserver","width","observer","observe","disconnect","t4","_c"],"sources":["../../src/actions/fit.ts"],"sourcesContent":["import { createContext, useEffect, useLayoutEffect, useState, useSyncExternalStore } from 'react';\n\n/**\n * How the actions of rows fit (decision 0060), the same for every row of a list: `0`, every\n * action as an icon but the main one, with its label; `1`, every action as an icon; `n` from 2,\n * the last `n` actions of each row in its menu.\n */\nexport const RowActionsFit = createContext(0);\n\n/** What the fit of a list depends on, besides its width: its items and its columns. */\nexport function fitContent(\n items: readonly { id: string }[],\n columns: readonly { id: string }[],\n): string {\n return `${items.map((item) => item.id).join('\\u0000')}\\u0001${columns.map((column) => column.id).join('\\u0000')}`;\n}\n\n/** Past that many actions in the menu, a row has nothing left to free. */\nconst MAX_LEVEL = 12;\n\n/** The most of the width of its row that the actions of an item take before they crowd it. */\nconst SHARE = 0.4;\n\n/**\n * From that many actions on a row, they also go to the menu to give the content room, as long as\n * `SHOWN` of them stay out of it.\n */\nconst MANY = 5;\nconst SHOWN = 4;\n\ninterface Measure {\n /**\n * The room the content lacks: the height of the list, since rows grow when their content\n * wraps, and what the displays that clamp their text (`data-clamp`) cut off.\n */\n height: number;\n /**\n * How much the actions don't fit, in pixels: what the list and the boxes of actions overflow,\n * the lines that actions wrap to, and what they take of their row past `SHARE`.\n */\n crowding: number;\n /** The most actions a row has, in the row and its menu. */\n count: number;\n}\n\nfunction measure(element: HTMLElement): Measure {\n let crowding = Math.max(0, element.scrollWidth - element.clientWidth);\n let count = 0;\n for (const actions of element.querySelectorAll<HTMLElement>('[data-row-actions]')) {\n count = Math.max(count, Number(actions.dataset.rowActions));\n const box = actions.parentElement;\n if (box !== null) {\n crowding += Math.max(0, box.scrollWidth - box.clientWidth);\n }\n const first = actions.firstElementChild;\n if (first instanceof HTMLElement) {\n crowding += Math.max(0, actions.offsetHeight - first.offsetHeight);\n }\n const row = actions.closest<HTMLElement>('tr, li') ?? element;\n crowding += Math.max(0, actions.offsetWidth - row.offsetWidth * SHARE);\n }\n let cut = 0;\n for (const text of element.querySelectorAll<HTMLElement>('[data-clamp]')) {\n cut += Math.max(0, text.scrollHeight - text.clientHeight);\n }\n return { height: element.offsetHeight + cut, crowding, count };\n}\n\n/**\n * Whether rows of `count` actions can give the content room with `level`: only when they have many\n * actions, `SHOWN` of which stay out of the menu.\n */\nfunction forContent(level: number, count: number): boolean {\n return count >= MANY && count - level >= SHOWN;\n}\n\n/** Whether the next level is worth a try, after `current`. */\nfunction worthTrying(next: number, current: Measure): boolean {\n if (next === 1) {\n return current.crowding > 0.5 || forContent(next, current.count);\n }\n return (\n next <= Math.min(current.count, MAX_LEVEL) &&\n current.count >= 2 &&\n (current.crowding > 0.5 || forContent(next, current.count))\n );\n}\n\n/**\n * The best of the levels tried: the actions crowd least, then the rows are shortest (when the\n * level may give the content room), then the fewest changes.\n */\nfunction best(measures: ReadonlyMap<number, Measure>): number {\n let chosen = 0;\n for (const [level, current] of measures) {\n const kept = measures.get(chosen);\n if (kept === undefined || level === chosen) {\n continue;\n }\n if (current.crowding < kept.crowding - 0.5) {\n chosen = level;\n } else if (\n current.crowding <= kept.crowding + 0.5 &&\n forContent(level, current.count) &&\n current.height < kept.height - 0.5\n ) {\n chosen = level;\n }\n }\n return chosen;\n}\n\n/**\n * The level of a list, outside React: it changes while the list commits, and React draws each\n * change at once (`useSyncExternalStore`), before the browser paints.\n */\nclass FitStore {\n #level = 0;\n #settled = false;\n /** The measures of the levels tried. */\n #measures = new Map<number, Measure>();\n #content: string | null = null;\n readonly #listeners = new Set<() => void>();\n\n readonly subscribe = (listener: () => void): (() => void) => {\n this.#listeners.add(listener);\n return () => this.#listeners.delete(listener);\n };\n\n readonly getLevel = (): number => this.#level;\n\n #set(level: number): void {\n if (level !== this.#level) {\n this.#level = level;\n for (const listener of this.#listeners) {\n listener();\n }\n }\n }\n\n /** Starts over from the labels: true when the list has to draw them first. */\n restart(): boolean {\n this.#settled = false;\n this.#measures = new Map();\n const drawn = this.#level === 0;\n this.#set(0);\n return !drawn;\n }\n\n /** Starts over when the content changes. */\n setContent(content: string): boolean {\n if (content === this.#content) {\n return false;\n }\n this.#content = content;\n return this.restart();\n }\n\n /** Measures the list drawn at `drawn`, then tries the next level, or settles on the best. */\n step(element: HTMLElement, drawn: number): void {\n if (this.#settled || drawn !== this.#level) {\n return;\n }\n const current = measure(element);\n this.#measures.set(drawn, current);\n const next = drawn + 1;\n if (worthTrying(next, current)) {\n this.#set(next);\n } else {\n this.#settled = true;\n this.#set(best(this.#measures));\n }\n }\n}\n\n/**\n * Fits the actions of the rows of a list in the room they have (decision 0060). It draws each\n * level in turn, from every action as an icon but the main one, labelled, then the main one as an\n * icon too, then a menu of two actions, three…, while the next one may help, and keeps the best:\n * where the actions crowd least (the list overflows, the actions of a row wrap or take more than\n * 40% of it), then, on rows of five actions or more, where the rows are shortest (their content\n * wraps or is cut less), then the fewest actions in the menu.\n *\n * @returns the level, and a callback ref for the element to measure: the list, which holds the\n * actions.\n */\nexport function useRowActionsFit(\n content: string,\n): [level: number, measure: (element: HTMLElement | null) => void] {\n const [element, setElement] = useState<HTMLElement | null>(null);\n const [store] = useState(() => new FitStore());\n const level = useSyncExternalStore(store.subscribe, store.getLevel, store.getLevel);\n\n useLayoutEffect(() => {\n if (element !== null && !store.setContent(content)) {\n store.step(element, level);\n }\n }, [store, element, content, level]);\n\n useEffect(() => {\n // Without ResizeObserver (jsdom), the list fits once, at its first width.\n if (element === null || typeof ResizeObserver === 'undefined') {\n return undefined;\n }\n let width = element.clientWidth;\n const observer = new ResizeObserver(() => {\n if (element.clientWidth !== width) {\n width = element.clientWidth;\n if (!store.restart()) {\n store.step(element, 0);\n }\n }\n });\n observer.observe(element);\n return () => observer.disconnect();\n }, [store, element]);\n\n return [level, setElement];\n}\n"],"mappings":";;;;;;;;AAOA,IAAaK,gBAAgBL,cAAc,CAAC;;AAG5C,SAAgBM,WACZC,OACAE,SACM;CACN,OAAO,GAAGF,MAAMG,KAAKC,SAASA,KAAKH,EAAE,CAAC,CAACI,KAAK,IAAQ,EAAC,QAASH,QAAQC,KAAKG,WAAWA,OAAOL,EAAE,CAAC,CAACI,KAAK,IAAQ;AAClH;;AAGA,IAAME,YAAY;;AAGlB,IAAMC,QAAQ;;;;;AAMd,IAAMC,OAAO;AACb,IAAMC,QAAQ;AAiBd,SAASK,QAAQC,SAA+B;CAC5C,IAAIH,WAAWK,KAAKC,IAAI,GAAGH,QAAQI,cAAcJ,QAAQK,WAAW;CACpE,IAAIP,QAAQ;CACZ,KAAK,MAAMQ,WAAWN,QAAQO,iBAA8B,oBAAoB,GAAG;EAC/ET,QAAQI,KAAKC,IAAIL,OAAOU,OAAOF,QAAQG,QAAQC,UAAU,CAAC;EAC1D,MAAMC,MAAML,QAAQM;EACpB,IAAID,QAAQ,MACRd,YAAYK,KAAKC,IAAI,GAAGQ,IAAIP,cAAcO,IAAIN,WAAW;EAE7D,MAAMQ,QAAQP,QAAQQ;EACtB,IAAID,iBAAiBZ,aACjBJ,YAAYK,KAAKC,IAAI,GAAGG,QAAQS,eAAeF,MAAME,YAAY;EAErE,MAAMC,MAAMV,QAAQW,QAAqB,QAAQ,KAAKjB;EACtDH,YAAYK,KAAKC,I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only<Record<string, IconComponent>>;
|
|
|
7
7
|
* names (`"send"`, loaded when it first renders), then the icon of a built-in action.
|
|
8
8
|
*/
|
|
9
9
|
export declare function getActionIcon(action: Action, icons?: ActionIcons): IconComponent | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* The tone of an action in rows (decision 0060): `danger` when it destroys, a color for `show`
|
|
12
|
+
* (`info`), `edit` (`accent`) and `restore` (`success`), and `neutral` for the others.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getActionTone(action: Action): 'neutral' | 'accent' | 'info' | 'success' | 'danger';
|
|
10
15
|
//# sourceMappingURL=icons.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icons.d.ts","sourceRoot":"","sources":["../../src/actions/icons.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,KAAK,aAAa,EAAgB,MAAM,aAAa,CAAC;AAE/D,2FAA2F;AAC3F,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;AAalE;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,aAAa,GAAG,SAAS,CAU5F"}
|
|
1
|
+
{"version":3,"file":"icons.d.ts","sourceRoot":"","sources":["../../src/actions/icons.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,KAAK,aAAa,EAAgB,MAAM,aAAa,CAAC;AAE/D,2FAA2F;AAC3F,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;AAalE;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,aAAa,GAAG,SAAS,CAU5F;AASD;;;GAGG;AACH,wBAAgB,aAAa,CACzB,MAAM,EAAE,MAAM,GACf,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,CAOtD"}
|
package/dist/actions/icons.js
CHANGED
|
@@ -21,7 +21,21 @@ function getActionIcon(action, icons) {
|
|
|
21
21
|
if (action.icon !== void 0 && action.icon !== "") return getNamedIcon(action.icon);
|
|
22
22
|
return Object.hasOwn(BUILT_IN_ICONS, action.id) ? BUILT_IN_ICONS[action.id] : void 0;
|
|
23
23
|
}
|
|
24
|
+
/** Colors of the built-in actions in rows, as Panneau 4 had them (decision 0060). */
|
|
25
|
+
var BUILT_IN_TONES = {
|
|
26
|
+
show: "info",
|
|
27
|
+
edit: "accent",
|
|
28
|
+
restore: "success"
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The tone of an action in rows (decision 0060): `danger` when it destroys, a color for `show`
|
|
32
|
+
* (`info`), `edit` (`accent`) and `restore` (`success`), and `neutral` for the others.
|
|
33
|
+
*/
|
|
34
|
+
function getActionTone(action) {
|
|
35
|
+
if (action.destructive === true) return "danger";
|
|
36
|
+
return Object.hasOwn(BUILT_IN_TONES, action.id) ? BUILT_IN_TONES[action.id] ?? "neutral" : "neutral";
|
|
37
|
+
}
|
|
24
38
|
//#endregion
|
|
25
|
-
export { getActionIcon };
|
|
39
|
+
export { getActionIcon, getActionTone };
|
|
26
40
|
|
|
27
41
|
//# sourceMappingURL=icons.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icons.js","names":["Copy","Download","Eye","LucideIcon","Pencil","RotateCcw","Trash2","Upload","Action","IconComponent","getNamedIcon","ActionIcons","Readonly","Record","BUILT_IN_ICONS","show","edit","duplicate","delete","restore","export","import","getActionIcon","action","icons","given","undefined","Object","hasOwn","id","icon"],"sources":["../../src/actions/icons.ts"],"sourcesContent":["import {\n Copy,\n Download,\n Eye,\n type LucideIcon,\n Pencil,\n RotateCcw,\n Trash2,\n Upload,\n} from 'lucide-react';\n\nimport type { Action } from '@panneau/protocol';\nimport { type IconComponent, getNamedIcon } from '@panneau/ui';\n\n/** Icons of actions by action id, for actions written in code (`{ archive: Archive }`). */\nexport type ActionIcons = Readonly<Record<string, IconComponent>>;\n\n/** Icons of the built-in actions, when they don't name one. */\nconst BUILT_IN_ICONS: Record<string, LucideIcon> = {\n show: Eye,\n edit: Pencil,\n duplicate: Copy,\n delete: Trash2,\n restore: RotateCcw,\n export: Download,\n import: Upload,\n};\n\n/**\n * The icon of an action: the one given for its id in `icons`, then the Lucide icon its `icon`\n * names (`\"send\"`, loaded when it first renders), then the icon of a built-in action.\n */\nexport function getActionIcon(action: Action, icons?: ActionIcons): IconComponent | undefined {\n const given =\n icons !== undefined && Object.hasOwn(icons, action.id) ? icons[action.id] : undefined;\n if (given !== undefined) {\n return given;\n }\n if (action.icon !== undefined && action.icon !== '') {\n return getNamedIcon(action.icon);\n }\n return Object.hasOwn(BUILT_IN_ICONS, action.id) ? BUILT_IN_ICONS[action.id] : undefined;\n}\n"],"mappings":";;;;AAkBA,IAAMc,iBAA6C;CAC/CC,MAAMb;CACNc,MAAMZ;CACNa,WAAWjB;CACXkB,QAAQZ;CACRa,SAASd;CACTe,QAAQnB;CACRoB,QAAQd;AACZ;;;;;AAMA,SAAgBe,cAAcC,QAAgBC,OAAgD;CAC1F,MAAMC,QACFD,UAAUE,KAAAA,KAAaC,OAAOC,OAAOJ,OAAOD,OAAOM,EAAE,IAAIL,MAAMD,OAAOM,MAAMH,KAAAA;CAChF,IAAID,UAAUC,KAAAA,GACV,OAAOD;CAEX,IAAIF,OAAOO,SAASJ,KAAAA,KAAaH,OAAOO,SAAS,IAC7C,OAAOpB,aAAaa,OAAOO,IAAI;CAEnC,OAAOH,OAAOC,OAAOd,gBAAgBS,OAAOM,EAAE,IAAIf,eAAeS,OAAOM,MAAMH,KAAAA;AAClF"}
|
|
1
|
+
{"version":3,"file":"icons.js","names":["Copy","Download","Eye","LucideIcon","Pencil","RotateCcw","Trash2","Upload","Action","IconComponent","getNamedIcon","ActionIcons","Readonly","Record","BUILT_IN_ICONS","show","edit","duplicate","delete","restore","export","import","getActionIcon","action","icons","given","undefined","Object","hasOwn","id","icon","BUILT_IN_TONES","getActionTone","destructive"],"sources":["../../src/actions/icons.ts"],"sourcesContent":["import {\n Copy,\n Download,\n Eye,\n type LucideIcon,\n Pencil,\n RotateCcw,\n Trash2,\n Upload,\n} from 'lucide-react';\n\nimport type { Action } from '@panneau/protocol';\nimport { type IconComponent, getNamedIcon } from '@panneau/ui';\n\n/** Icons of actions by action id, for actions written in code (`{ archive: Archive }`). */\nexport type ActionIcons = Readonly<Record<string, IconComponent>>;\n\n/** Icons of the built-in actions, when they don't name one. */\nconst BUILT_IN_ICONS: Record<string, LucideIcon> = {\n show: Eye,\n edit: Pencil,\n duplicate: Copy,\n delete: Trash2,\n restore: RotateCcw,\n export: Download,\n import: Upload,\n};\n\n/**\n * The icon of an action: the one given for its id in `icons`, then the Lucide icon its `icon`\n * names (`\"send\"`, loaded when it first renders), then the icon of a built-in action.\n */\nexport function getActionIcon(action: Action, icons?: ActionIcons): IconComponent | undefined {\n const given =\n icons !== undefined && Object.hasOwn(icons, action.id) ? icons[action.id] : undefined;\n if (given !== undefined) {\n return given;\n }\n if (action.icon !== undefined && action.icon !== '') {\n return getNamedIcon(action.icon);\n }\n return Object.hasOwn(BUILT_IN_ICONS, action.id) ? BUILT_IN_ICONS[action.id] : undefined;\n}\n\n/** Colors of the built-in actions in rows, as Panneau 4 had them (decision 0060). */\nconst BUILT_IN_TONES: Record<string, 'accent' | 'info' | 'success'> = {\n show: 'info',\n edit: 'accent',\n restore: 'success',\n};\n\n/**\n * The tone of an action in rows (decision 0060): `danger` when it destroys, a color for `show`\n * (`info`), `edit` (`accent`) and `restore` (`success`), and `neutral` for the others.\n */\nexport function getActionTone(\n action: Action,\n): 'neutral' | 'accent' | 'info' | 'success' | 'danger' {\n if (action.destructive === true) {\n return 'danger';\n }\n return Object.hasOwn(BUILT_IN_TONES, action.id)\n ? (BUILT_IN_TONES[action.id] ?? 'neutral')\n : 'neutral';\n}\n"],"mappings":";;;;AAkBA,IAAMc,iBAA6C;CAC/CC,MAAMb;CACNc,MAAMZ;CACNa,WAAWjB;CACXkB,QAAQZ;CACRa,SAASd;CACTe,QAAQnB;CACRoB,QAAQd;AACZ;;;;;AAMA,SAAgBe,cAAcC,QAAgBC,OAAgD;CAC1F,MAAMC,QACFD,UAAUE,KAAAA,KAAaC,OAAOC,OAAOJ,OAAOD,OAAOM,EAAE,IAAIL,MAAMD,OAAOM,MAAMH,KAAAA;CAChF,IAAID,UAAUC,KAAAA,GACV,OAAOD;CAEX,IAAIF,OAAOO,SAASJ,KAAAA,KAAaH,OAAOO,SAAS,IAC7C,OAAOpB,aAAaa,OAAOO,IAAI;CAEnC,OAAOH,OAAOC,OAAOd,gBAAgBS,OAAOM,EAAE,IAAIf,eAAeS,OAAOM,MAAMH,KAAAA;AAClF;;AAGA,IAAMK,iBAAgE;CAClEhB,MAAM;CACNC,MAAM;CACNG,SAAS;AACb;;;;;AAMA,SAAgBa,cACZT,QACoD;CACpD,IAAIA,OAAOU,gBAAgB,MACvB,OAAO;CAEX,OAAON,OAAOC,OAAOG,gBAAgBR,OAAOM,EAAE,IACvCE,eAAeR,OAAOM,OAAO,YAC9B;AACV"}
|