@dxos/react-ui-menu 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/index.mjs +592 -209
- package/dist/lib/index.mjs.map +1 -1
- package/dist/types/src/builder.d.ts +20 -1
- package/dist/types/src/builder.d.ts.map +1 -1
- package/dist/types/src/components/ActionMenu.d.ts.map +1 -1
- package/dist/types/src/components/ActionMenu.stories.d.ts +2 -0
- package/dist/types/src/components/ActionMenu.stories.d.ts.map +1 -1
- package/dist/types/src/components/ActionToolbar.d.ts +32 -8
- package/dist/types/src/components/ActionToolbar.d.ts.map +1 -1
- package/dist/types/src/components/ActionToolbar.stories.d.ts +32 -3
- package/dist/types/src/components/ActionToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +3 -2
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +26 -22
- package/src/builder.test.ts +28 -0
- package/src/builder.ts +71 -6
- package/src/components/ActionMenu.stories.tsx +38 -1
- package/src/components/ActionMenu.tsx +67 -7
- package/src/components/ActionToolbar.stories.tsx +533 -22
- package/src/components/ActionToolbar.tsx +440 -35
- package/src/hooks/useMenuActions.browser.test.tsx +6 -0
- package/src/index.ts +1 -1
package/dist/lib/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cloneElement, forwardRef, isValidElement, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
1
|
+
import { Fragment, cloneElement, forwardRef, isValidElement, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
2
2
|
import { keySymbols } from "@dxos/react-focus";
|
|
3
3
|
import * as Hooks from "@dxos/react-ui/Hooks";
|
|
4
4
|
import * as Icon from "@dxos/react-ui/Icon";
|
|
@@ -7,16 +7,17 @@ import * as Theme from "@dxos/react-ui/Theme";
|
|
|
7
7
|
import * as VirtualAnchor from "@dxos/react-ui/VirtualAnchor";
|
|
8
8
|
import { resolveKeyBinding } from "@dxos/util";
|
|
9
9
|
import { translationKey } from "#translations";
|
|
10
|
-
import
|
|
10
|
+
import { invariant } from "@dxos/invariant";
|
|
11
11
|
import * as AppGraphNode from "@dxos/app-graph/AppGraphNode";
|
|
12
|
+
import * as Effect from "effect/Effect";
|
|
13
|
+
import * as EffectEx from "@dxos/effect/EffectEx";
|
|
14
|
+
import * as Atom from "effect/reactivity/Atom";
|
|
12
15
|
import * as GraphNode from "@dxos/graph/GraphNode";
|
|
13
16
|
import { useAtomValue } from "@effect/atom-react/Hooks";
|
|
14
17
|
import { RegistryContext } from "@effect/atom-react/RegistryContext";
|
|
15
18
|
import * as AppGraph from "@dxos/app-graph/AppGraph";
|
|
16
19
|
import { log } from "@dxos/log";
|
|
17
|
-
import
|
|
18
|
-
import * as EffectEx from "@dxos/effect/EffectEx";
|
|
19
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
20
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
20
21
|
import { useAttention } from "@dxos/react-ui-attention";
|
|
21
22
|
import * as Button from "@dxos/react-ui/Button";
|
|
22
23
|
import * as Input from "@dxos/react-ui/Input";
|
|
@@ -24,8 +25,211 @@ import * as ToggleGroup from "@dxos/react-ui/ToggleGroup";
|
|
|
24
25
|
import * as Toolbar from "@dxos/react-ui/Toolbar";
|
|
25
26
|
import * as Tooltip from "@dxos/react-ui/Tooltip";
|
|
26
27
|
import * as Util from "@dxos/react-ui/Util";
|
|
28
|
+
import { TOOLBAR_HOLDS_ATTRIBUTE, TOOLBAR_OVERFLOW_TESTID } from "@dxos/ui-types";
|
|
27
29
|
import { mx } from "@dxos/ui-theme";
|
|
28
|
-
|
|
30
|
+
//#region src/types.ts
|
|
31
|
+
var MenuSeparatorType = "@dxos/react-ui-toolbar/separator";
|
|
32
|
+
var isSeparator = (node) => node.type === MenuSeparatorType;
|
|
33
|
+
var isMenuGroup = (node) => node.type === AppGraphNode.ActionGroupType;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/util.ts
|
|
36
|
+
/**
|
|
37
|
+
* Execute a menu action's Effect with its captured context.
|
|
38
|
+
* This provides the `_actionContext` layer if available.
|
|
39
|
+
*/
|
|
40
|
+
var executeMenuAction = async (action, params = {}) => {
|
|
41
|
+
let effect = action.data(params);
|
|
42
|
+
if (action._actionContext) effect = effect.pipe(Effect.provide(action._actionContext));
|
|
43
|
+
await EffectEx.runAndForwardErrors(effect);
|
|
44
|
+
};
|
|
45
|
+
var getShortcut = (action) => {
|
|
46
|
+
return resolveKeyBinding(action.properties?.keyBinding);
|
|
47
|
+
};
|
|
48
|
+
var fallbackIcon = "ph--circle-dashed--regular";
|
|
49
|
+
var createMenuAction = (id, invoke, properties) => ({
|
|
50
|
+
id,
|
|
51
|
+
type: AppGraphNode.ActionType,
|
|
52
|
+
properties,
|
|
53
|
+
data: (params) => Effect.sync(() => invoke(params))
|
|
54
|
+
});
|
|
55
|
+
var createMenuItemGroup = (id, properties) => ({
|
|
56
|
+
id,
|
|
57
|
+
type: AppGraphNode.ActionGroupType,
|
|
58
|
+
properties,
|
|
59
|
+
data: AppGraphNode.actionGroupSymbol
|
|
60
|
+
});
|
|
61
|
+
var createGapSeparator = (id = "gap", source = "root") => ({
|
|
62
|
+
nodes: [{
|
|
63
|
+
id,
|
|
64
|
+
type: "@dxos/react-ui-toolbar/separator",
|
|
65
|
+
properties: { variant: "gap" },
|
|
66
|
+
data: void 0
|
|
67
|
+
}],
|
|
68
|
+
edges: [{
|
|
69
|
+
source,
|
|
70
|
+
target: id,
|
|
71
|
+
relation: "child"
|
|
72
|
+
}]
|
|
73
|
+
});
|
|
74
|
+
var createLineSeparator = (id = "line", source = "root") => ({
|
|
75
|
+
nodes: [{
|
|
76
|
+
id,
|
|
77
|
+
type: "@dxos/react-ui-toolbar/separator",
|
|
78
|
+
properties: { variant: "line" },
|
|
79
|
+
data: void 0
|
|
80
|
+
}],
|
|
81
|
+
edges: [{
|
|
82
|
+
source,
|
|
83
|
+
target: id,
|
|
84
|
+
relation: "child"
|
|
85
|
+
}]
|
|
86
|
+
});
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/builder.ts
|
|
89
|
+
var __dxlog_file$1 = "/__w/dxos/dxos/packages/ui/react-ui-menu/src/builder.ts";
|
|
90
|
+
/** Default trigger for toolbar overflow (⋮) dropdown menus. */
|
|
91
|
+
var overflowMenuProperties = {
|
|
92
|
+
label: ["toolbar-overflow.menu", { ns: translationKey }],
|
|
93
|
+
icon: "ph--dots-three-vertical--regular",
|
|
94
|
+
iconOnly: true,
|
|
95
|
+
caretDown: false,
|
|
96
|
+
variant: "dropdownMenu"
|
|
97
|
+
};
|
|
98
|
+
var MenuBuilderImpl = class MenuBuilderImpl {
|
|
99
|
+
_data;
|
|
100
|
+
_rootId;
|
|
101
|
+
constructor(_data, _rootId) {
|
|
102
|
+
this._data = _data;
|
|
103
|
+
this._rootId = _rootId;
|
|
104
|
+
}
|
|
105
|
+
root(props) {
|
|
106
|
+
invariant(this._rootId === "root", "Root group can only be at the top level", {
|
|
107
|
+
"~LogMeta": "~LogMeta",
|
|
108
|
+
F: __dxlog_file$1,
|
|
109
|
+
L: 99,
|
|
110
|
+
S: this,
|
|
111
|
+
A: ["this._rootId === 'root'", "'Root group can only be at the top level'"]
|
|
112
|
+
});
|
|
113
|
+
invariant(this._data.nodes.find((node) => node.id === "root") === void 0, "Root group can only be created once", {
|
|
114
|
+
"~LogMeta": "~LogMeta",
|
|
115
|
+
F: __dxlog_file$1,
|
|
116
|
+
L: 100,
|
|
117
|
+
S: this,
|
|
118
|
+
A: ["this._data.nodes.find((node) => node.id === 'root') === undefined", "'Root group can only be created once'"]
|
|
119
|
+
});
|
|
120
|
+
this._data.nodes.push(createMenuItemGroup("root", props));
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
build() {
|
|
124
|
+
return this._data;
|
|
125
|
+
}
|
|
126
|
+
action(id, props, invoke) {
|
|
127
|
+
this._data.nodes.push(createMenuAction(id, invoke, props));
|
|
128
|
+
this._data.edges.push({
|
|
129
|
+
source: this._rootId,
|
|
130
|
+
target: id,
|
|
131
|
+
relation: "child"
|
|
132
|
+
});
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
switch(id, props, invoke) {
|
|
136
|
+
return this.action(id, {
|
|
137
|
+
...props,
|
|
138
|
+
variant: "switch"
|
|
139
|
+
}, invoke);
|
|
140
|
+
}
|
|
141
|
+
custom(id, props, render) {
|
|
142
|
+
return this.action(id, {
|
|
143
|
+
...props,
|
|
144
|
+
variant: "custom",
|
|
145
|
+
render
|
|
146
|
+
}, () => {});
|
|
147
|
+
}
|
|
148
|
+
text(id, props) {
|
|
149
|
+
return this.action(id, {
|
|
150
|
+
...props,
|
|
151
|
+
variant: "text"
|
|
152
|
+
}, () => {});
|
|
153
|
+
}
|
|
154
|
+
group(id, props, cb) {
|
|
155
|
+
this._data.nodes.push(createMenuItemGroup(id, props));
|
|
156
|
+
this._data.edges.push({
|
|
157
|
+
source: this._rootId,
|
|
158
|
+
target: id,
|
|
159
|
+
relation: "child"
|
|
160
|
+
});
|
|
161
|
+
cb(new MenuBuilderImpl(this._data, id));
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
menu(id, cb, testId) {
|
|
165
|
+
return this.group(id, testId === void 0 ? overflowMenuProperties : {
|
|
166
|
+
...overflowMenuProperties,
|
|
167
|
+
testId
|
|
168
|
+
}, cb);
|
|
169
|
+
}
|
|
170
|
+
subgraph(subgraphOrCb) {
|
|
171
|
+
if (!subgraphOrCb) return this;
|
|
172
|
+
if (typeof subgraphOrCb === "function") subgraphOrCb(new MenuBuilderImpl(this._data, this._rootId));
|
|
173
|
+
else {
|
|
174
|
+
const ids = /* @__PURE__ */ new Map();
|
|
175
|
+
for (const node of subgraphOrCb.nodes) if (node.type === "@dxos/react-ui-toolbar/separator") {
|
|
176
|
+
const id = this._nextSeparatorId();
|
|
177
|
+
ids.set(node.id, id);
|
|
178
|
+
this._data.nodes.push({
|
|
179
|
+
...node,
|
|
180
|
+
id
|
|
181
|
+
});
|
|
182
|
+
} else this._data.nodes.push(node);
|
|
183
|
+
this._data.edges.push(...subgraphOrCb.edges.map((edge) => ({
|
|
184
|
+
...edge,
|
|
185
|
+
source: ids.get(edge.source) ?? edge.source,
|
|
186
|
+
target: ids.get(edge.target) ?? edge.target
|
|
187
|
+
})));
|
|
188
|
+
}
|
|
189
|
+
return this;
|
|
190
|
+
}
|
|
191
|
+
separator(variant = "gap") {
|
|
192
|
+
const id = this._nextSeparatorId();
|
|
193
|
+
this._data.nodes.push({
|
|
194
|
+
id,
|
|
195
|
+
type: MenuSeparatorType,
|
|
196
|
+
properties: { variant },
|
|
197
|
+
data: void 0
|
|
198
|
+
});
|
|
199
|
+
this._data.edges.push({
|
|
200
|
+
source: this._rootId,
|
|
201
|
+
target: id,
|
|
202
|
+
relation: "child"
|
|
203
|
+
});
|
|
204
|
+
return this;
|
|
205
|
+
}
|
|
206
|
+
_nextSeparatorId() {
|
|
207
|
+
return `separator-${this._data.nodes.filter((node) => node.type === MenuSeparatorType).length + 1}`;
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
/** Id of the overflow menu (⋮) every toolbar ends with; contributors add to it with {@link MenuBuilder.extend}. */
|
|
211
|
+
var TOOLBAR_OVERFLOW_ID = "toolbar-overflow";
|
|
212
|
+
/** The overflow group a toolbar uses when its owner declares none, so contributors can still add to it. */
|
|
213
|
+
var defaultOverflowGroup = createMenuItemGroup(TOOLBAR_OVERFLOW_ID, overflowMenuProperties);
|
|
214
|
+
var MenuBuilder = Object.freeze({
|
|
215
|
+
make: () => new MenuBuilderImpl({
|
|
216
|
+
nodes: [],
|
|
217
|
+
edges: []
|
|
218
|
+
}, "root"),
|
|
219
|
+
/**
|
|
220
|
+
* Builds items into a named group another component declared, so a plugin extends a toolbar or menu it does not own.
|
|
221
|
+
* The result is merged into the owner's graph (e.g. with `subgraph`); its edges hang off `groupId`.
|
|
222
|
+
*/
|
|
223
|
+
extend: (groupId, cb) => {
|
|
224
|
+
const data = {
|
|
225
|
+
nodes: [],
|
|
226
|
+
edges: []
|
|
227
|
+
};
|
|
228
|
+
cb(new MenuBuilderImpl(data, groupId));
|
|
229
|
+
return data;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
//#endregion
|
|
29
233
|
//#region src/presentation.ts
|
|
30
234
|
/**
|
|
31
235
|
* Merges an action's `presentation[surface]` chrome override (if any) into its properties, letting a
|
|
@@ -45,7 +249,7 @@ var applyPresentation = (action, surface) => {
|
|
|
45
249
|
};
|
|
46
250
|
//#endregion
|
|
47
251
|
//#region src/hooks/useMenuActions.ts
|
|
48
|
-
var __dxlog_file
|
|
252
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-menu/src/hooks/useMenuActions.ts";
|
|
49
253
|
var DEFAULT_PRIORITY = 100;
|
|
50
254
|
var EMPTY_GRAPH = Atom.make({
|
|
51
255
|
nodes: [],
|
|
@@ -154,7 +358,7 @@ var resolveItems = (baseItems, group, entries) => {
|
|
|
154
358
|
using: replacements[0].id
|
|
155
359
|
}, {
|
|
156
360
|
"~LogMeta": "~LogMeta",
|
|
157
|
-
F: __dxlog_file
|
|
361
|
+
F: __dxlog_file,
|
|
158
362
|
L: 168,
|
|
159
363
|
S: void 0
|
|
160
364
|
});
|
|
@@ -241,64 +445,6 @@ var useGraphMenuActions = (graph, nodeId, options) => {
|
|
|
241
445
|
]), options);
|
|
242
446
|
};
|
|
243
447
|
//#endregion
|
|
244
|
-
//#region src/types.ts
|
|
245
|
-
var MenuSeparatorType = "@dxos/react-ui-toolbar/separator";
|
|
246
|
-
var isSeparator = (node) => node.type === MenuSeparatorType;
|
|
247
|
-
var isMenuGroup = (node) => node.type === AppGraphNode.ActionGroupType;
|
|
248
|
-
//#endregion
|
|
249
|
-
//#region src/util.ts
|
|
250
|
-
/**
|
|
251
|
-
* Execute a menu action's Effect with its captured context.
|
|
252
|
-
* This provides the `_actionContext` layer if available.
|
|
253
|
-
*/
|
|
254
|
-
var executeMenuAction = async (action, params = {}) => {
|
|
255
|
-
let effect = action.data(params);
|
|
256
|
-
if (action._actionContext) effect = effect.pipe(Effect.provide(action._actionContext));
|
|
257
|
-
await EffectEx.runAndForwardErrors(effect);
|
|
258
|
-
};
|
|
259
|
-
var getShortcut = (action) => {
|
|
260
|
-
return resolveKeyBinding(action.properties?.keyBinding);
|
|
261
|
-
};
|
|
262
|
-
var fallbackIcon = "ph--circle-dashed--regular";
|
|
263
|
-
var createMenuAction = (id, invoke, properties) => ({
|
|
264
|
-
id,
|
|
265
|
-
type: AppGraphNode.ActionType,
|
|
266
|
-
properties,
|
|
267
|
-
data: (params) => Effect.sync(() => invoke(params))
|
|
268
|
-
});
|
|
269
|
-
var createMenuItemGroup = (id, properties) => ({
|
|
270
|
-
id,
|
|
271
|
-
type: AppGraphNode.ActionGroupType,
|
|
272
|
-
properties,
|
|
273
|
-
data: AppGraphNode.actionGroupSymbol
|
|
274
|
-
});
|
|
275
|
-
var createGapSeparator = (id = "gap", source = "root") => ({
|
|
276
|
-
nodes: [{
|
|
277
|
-
id,
|
|
278
|
-
type: "@dxos/react-ui-toolbar/separator",
|
|
279
|
-
properties: { variant: "gap" },
|
|
280
|
-
data: void 0
|
|
281
|
-
}],
|
|
282
|
-
edges: [{
|
|
283
|
-
source,
|
|
284
|
-
target: id,
|
|
285
|
-
relation: "child"
|
|
286
|
-
}]
|
|
287
|
-
});
|
|
288
|
-
var createLineSeparator = (id = "line", source = "root") => ({
|
|
289
|
-
nodes: [{
|
|
290
|
-
id,
|
|
291
|
-
type: "@dxos/react-ui-toolbar/separator",
|
|
292
|
-
properties: { variant: "line" },
|
|
293
|
-
data: void 0
|
|
294
|
-
}],
|
|
295
|
-
edges: [{
|
|
296
|
-
source,
|
|
297
|
-
target: id,
|
|
298
|
-
relation: "child"
|
|
299
|
-
}]
|
|
300
|
-
});
|
|
301
|
-
//#endregion
|
|
302
448
|
//#region src/components/ActionMenu.tsx
|
|
303
449
|
var isMultiSelect = (group) => group?.properties?.selectCardinality === "multiple";
|
|
304
450
|
/** An action that declares `checked` is a select-group member (radio, or checkbox in a multi-select group). */
|
|
@@ -340,11 +486,14 @@ var ItemIcon = ({ menu, action }) => action.properties?.icon ? /* @__PURE__ */ j
|
|
|
340
486
|
size: menu.iconSize,
|
|
341
487
|
classNames: action.properties.iconClassNames
|
|
342
488
|
}) : null;
|
|
489
|
+
/** A row's indent within a menu listing a tree, added to the row's own inset. */
|
|
490
|
+
var indentStyle = ({ indent }) => indent ? { paddingInlineStart: `calc(var(--dx-gap-size) * 1.5 + ${indent}rem)` } : void 0;
|
|
343
491
|
var ActionMenuItem = ({ menu, action, group }) => {
|
|
344
492
|
const item = useItemData(action.id, action.properties);
|
|
345
493
|
const handleClick = useInvoke(menu, action, group);
|
|
346
494
|
return /* @__PURE__ */ jsxs(Menu.Item, {
|
|
347
495
|
item,
|
|
496
|
+
style: indentStyle(action.properties),
|
|
348
497
|
onClick: handleClick,
|
|
349
498
|
closeOnSelect: !isMultiSelect(group),
|
|
350
499
|
...action.properties?.testId && { "data-testid": action.properties.testId },
|
|
@@ -363,6 +512,7 @@ var ActionCheckboxItem = ({ menu, action, group }) => {
|
|
|
363
512
|
const handleClick = useInvoke(menu, action, group);
|
|
364
513
|
return /* @__PURE__ */ jsxs(Menu.CheckboxItem, {
|
|
365
514
|
item,
|
|
515
|
+
style: indentStyle(action.properties),
|
|
366
516
|
checked: !!action.properties.checked,
|
|
367
517
|
onClick: handleClick,
|
|
368
518
|
closeOnSelect: false,
|
|
@@ -382,6 +532,7 @@ var ActionRadioItem = ({ menu, action, group }) => {
|
|
|
382
532
|
const handleClick = useInvoke(menu, action, group);
|
|
383
533
|
return /* @__PURE__ */ jsxs(Menu.RadioItem, {
|
|
384
534
|
item,
|
|
535
|
+
style: indentStyle(action.properties),
|
|
385
536
|
onClick: handleClick,
|
|
386
537
|
...action.properties?.testId && { "data-testid": action.properties.testId },
|
|
387
538
|
children: [
|
|
@@ -414,13 +565,27 @@ var ActionSubMenu = ({ menu, group }) => {
|
|
|
414
565
|
group
|
|
415
566
|
}) })] });
|
|
416
567
|
};
|
|
568
|
+
/** A toolbar's named group may be declared for others to extend and left empty; a menu then omits it. */
|
|
569
|
+
var NamedGroupSubMenu = ({ menu, group }) => {
|
|
570
|
+
return useMenuItems(menu, group)?.some(isMenuRow) ? /* @__PURE__ */ jsx(ActionSubMenu, {
|
|
571
|
+
menu,
|
|
572
|
+
group
|
|
573
|
+
}) : null;
|
|
574
|
+
};
|
|
575
|
+
/**
|
|
576
|
+
* Whether an item renders as a menu row: a label belongs to a toolbar row (a menu has its own title), and a menu cannot
|
|
577
|
+
* host a control its contributor renders itself.
|
|
578
|
+
*/
|
|
579
|
+
var isMenuRow = (item) => isMenuGroup(item) || !isSeparator(item) && !item.properties?.hidden && item.properties?.variant !== "text" && item.properties?.variant !== "custom";
|
|
580
|
+
/** A toggle group is a set of options, which a menu lists in place, ruled off from its neighbours. */
|
|
581
|
+
var isOptionSet = (item) => isMenuGroup(item) && item.properties.variant === "toggleGroup";
|
|
417
582
|
/**
|
|
418
583
|
* Runs of checkable items in a single-select group become one radio group (Ark's radio items need one), whose value is
|
|
419
|
-
* the member marked `checked
|
|
584
|
+
* the member marked `checked`; a `toggle` is pressed on its own (a toolbar's, collapsed into ⋮), so it stays a checkbox.
|
|
420
585
|
*/
|
|
421
586
|
var segment = (items, multiple) => items.reduce((segments, item) => {
|
|
422
587
|
const last = segments.at(-1);
|
|
423
|
-
if (multiple || !isCheckable(item)) segments.push({
|
|
588
|
+
if (multiple || !isCheckable(item) || item.properties.variant === "toggle") segments.push({
|
|
424
589
|
kind: "item",
|
|
425
590
|
item
|
|
426
591
|
});
|
|
@@ -432,14 +597,28 @@ var segment = (items, multiple) => items.reduce((segments, item) => {
|
|
|
432
597
|
});
|
|
433
598
|
return segments;
|
|
434
599
|
}, []);
|
|
600
|
+
var isOptionSetSegment = (segment) => segment.kind === "item" && isOptionSet(segment.item);
|
|
435
601
|
var ActionMenuEntry = ({ menu, item, group }) => {
|
|
436
602
|
if (isSeparator(item)) return /* @__PURE__ */ jsx(Menu.Separator, {});
|
|
437
|
-
if (isMenuGroup(item))
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
603
|
+
if (isMenuGroup(item)) {
|
|
604
|
+
if (item.id === "toolbar-overflow") return /* @__PURE__ */ jsx(OverflowSection, {
|
|
605
|
+
menu,
|
|
606
|
+
group: item
|
|
607
|
+
});
|
|
608
|
+
if (isOptionSet(item)) return /* @__PURE__ */ jsx(ActionMenuItems, {
|
|
609
|
+
menu,
|
|
610
|
+
group: item
|
|
611
|
+
});
|
|
612
|
+
return item.properties.variant ? /* @__PURE__ */ jsx(ActionSubMenu, {
|
|
613
|
+
menu,
|
|
614
|
+
group: item
|
|
615
|
+
}) : /* @__PURE__ */ jsx(NamedGroupSubMenu, {
|
|
616
|
+
menu,
|
|
617
|
+
group: item
|
|
618
|
+
});
|
|
619
|
+
}
|
|
441
620
|
const action = item;
|
|
442
|
-
if (action
|
|
621
|
+
if (!isMenuRow(action)) return null;
|
|
443
622
|
return isCheckable(action) ? /* @__PURE__ */ jsx(ActionCheckboxItem, {
|
|
444
623
|
menu,
|
|
445
624
|
action,
|
|
@@ -450,21 +629,28 @@ var ActionMenuEntry = ({ menu, item, group }) => {
|
|
|
450
629
|
group
|
|
451
630
|
});
|
|
452
631
|
};
|
|
632
|
+
var OverflowSection = ({ menu, group }) => {
|
|
633
|
+
if (!useMenuItems(menu, group)?.some(isMenuRow)) return null;
|
|
634
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Menu.Separator, {}), /* @__PURE__ */ jsx(ActionMenuItems, {
|
|
635
|
+
menu,
|
|
636
|
+
group
|
|
637
|
+
})] });
|
|
638
|
+
};
|
|
453
639
|
var ActionMenuItems = ({ menu, group, actions }) => {
|
|
454
640
|
const items = useMenuItems(menu, group, actions);
|
|
455
641
|
const segments = useMemo(() => segment(items ?? [], isMultiSelect(group)), [items, group]);
|
|
456
|
-
return /* @__PURE__ */ jsx(Fragment, { children: segments.map((entry) => entry.kind === "radio" ? /* @__PURE__ */ jsx(Menu.RadioItemGroup, {
|
|
642
|
+
return /* @__PURE__ */ jsx(Fragment$1, { children: segments.map((entry, index) => entry.kind === "radio" ? /* @__PURE__ */ jsx(Menu.RadioItemGroup, {
|
|
457
643
|
value: entry.actions.find((action) => action.properties.checked)?.id ?? "",
|
|
458
644
|
children: entry.actions.filter((action) => !action.properties.hidden).map((action) => /* @__PURE__ */ jsx(ActionRadioItem, {
|
|
459
645
|
menu,
|
|
460
646
|
action,
|
|
461
647
|
group
|
|
462
648
|
}, action.id))
|
|
463
|
-
}, entry.id) : /* @__PURE__ */ jsx(ActionMenuEntry, {
|
|
649
|
+
}, entry.id) : /* @__PURE__ */ jsxs(Fragment, { children: [index > 0 && (isOptionSet(entry.item) || isOptionSetSegment(segments[index - 1])) && /* @__PURE__ */ jsx(Menu.Separator, {}), /* @__PURE__ */ jsx(ActionMenuEntry, {
|
|
464
650
|
menu,
|
|
465
651
|
item: entry.item,
|
|
466
652
|
group
|
|
467
|
-
}, entry.item.id)) });
|
|
653
|
+
})] }, entry.item.id)) });
|
|
468
654
|
};
|
|
469
655
|
/**
|
|
470
656
|
* A whole `Menu.Root` driven from a `MenuActions`: the child is the trigger (`asChild`), the items come from the
|
|
@@ -520,6 +706,7 @@ var ActionMenuRoot = ({ items, contributions, onAction, caller, iconSize, group,
|
|
|
520
706
|
children
|
|
521
707
|
}), /* @__PURE__ */ jsx(Menu.Content, {
|
|
522
708
|
container: containerRef,
|
|
709
|
+
arrow: virtualRef ? false : void 0,
|
|
523
710
|
children: /* @__PURE__ */ jsx(ActionMenuItems, {
|
|
524
711
|
menu,
|
|
525
712
|
group,
|
|
@@ -540,7 +727,7 @@ var actionLabel = (action, t) => {
|
|
|
540
727
|
var ActionLabel = ({ action }) => {
|
|
541
728
|
const { t } = Hooks.useTranslation(translationKey);
|
|
542
729
|
const shortcut = getShortcut(action);
|
|
543
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
730
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
|
|
544
731
|
className: "grow truncate",
|
|
545
732
|
children: Theme.toLocalizedString(action.properties.label, t)
|
|
546
733
|
}), shortcut && /* @__PURE__ */ jsx("span", {
|
|
@@ -554,7 +741,7 @@ var ActionLabel = ({ action }) => {
|
|
|
554
741
|
* An action as a Next Button: icon-only with its label (and shortcut) in a tooltip, or text with a trailing shortcut.
|
|
555
742
|
* Forwards its ref and remaining props, since a `Menu.Trigger asChild` merges the trigger's onto it.
|
|
556
743
|
*/
|
|
557
|
-
var ActionButton = forwardRef(({ action, classNames, testId, ...props }, forwardedRef) => {
|
|
744
|
+
var ActionButton = forwardRef(({ action, classNames, testId, compact, ...props }, forwardedRef) => {
|
|
558
745
|
const { t } = Hooks.useTranslation(translationKey);
|
|
559
746
|
const { icon, iconOnly = true, spin } = action.properties;
|
|
560
747
|
const common = {
|
|
@@ -564,7 +751,7 @@ var ActionButton = forwardRef(({ action, classNames, testId, ...props }, forward
|
|
|
564
751
|
...testId && { "data-testid": testId },
|
|
565
752
|
ref: forwardedRef
|
|
566
753
|
};
|
|
567
|
-
return icon && iconOnly ? /* @__PURE__ */ jsx(Button.Root, {
|
|
754
|
+
return icon && (iconOnly || compact) ? /* @__PURE__ */ jsx(Button.Root, {
|
|
568
755
|
...common,
|
|
569
756
|
icon,
|
|
570
757
|
label: actionLabel(action, t),
|
|
@@ -575,7 +762,7 @@ var ActionButton = forwardRef(({ action, classNames, testId, ...props }, forward
|
|
|
575
762
|
children: /* @__PURE__ */ jsx(ActionLabel, { action })
|
|
576
763
|
});
|
|
577
764
|
});
|
|
578
|
-
var ActionToolbarItem = ({ menu, action }) => {
|
|
765
|
+
var ActionToolbarItem = ({ menu, action, compact }) => {
|
|
579
766
|
const { onAction, caller, iconSize } = menu;
|
|
580
767
|
const [pending, setPending] = useState(false);
|
|
581
768
|
const pendingRef = useRef(false);
|
|
@@ -603,11 +790,12 @@ var ActionToolbarItem = ({ menu, action }) => {
|
|
|
603
790
|
iconSize,
|
|
604
791
|
classNames,
|
|
605
792
|
onClick: handleClick,
|
|
606
|
-
testId
|
|
793
|
+
testId,
|
|
794
|
+
compact
|
|
607
795
|
});
|
|
608
796
|
};
|
|
609
797
|
/** A `toggle` action is a pressed button whose state is the action's `checked`. */
|
|
610
|
-
var ToggleToolbarItem = ({ menu, action }) => {
|
|
798
|
+
var ToggleToolbarItem = ({ menu, action, compact }) => {
|
|
611
799
|
const { onAction, caller, iconSize } = menu;
|
|
612
800
|
const { t } = Hooks.useTranslation(translationKey);
|
|
613
801
|
const { icon, iconOnly = true, disabled, testId, hidden, checked, classNames, spin } = action.properties;
|
|
@@ -630,7 +818,7 @@ var ToggleToolbarItem = ({ menu, action }) => {
|
|
|
630
818
|
onPressedChange: handlePressedChange,
|
|
631
819
|
...testId && { "data-testid": testId }
|
|
632
820
|
};
|
|
633
|
-
return icon && iconOnly ? /* @__PURE__ */ jsx(Button.Toggle, {
|
|
821
|
+
return icon && (iconOnly || compact) ? /* @__PURE__ */ jsx(Button.Toggle, {
|
|
634
822
|
...common,
|
|
635
823
|
icon,
|
|
636
824
|
label: actionLabel(action, t),
|
|
@@ -667,7 +855,7 @@ var SwitchToolbarItem = ({ menu, action }) => {
|
|
|
667
855
|
children: control
|
|
668
856
|
}), /* @__PURE__ */ jsx(Tooltip.Content, { children: labelStr })] }) : control;
|
|
669
857
|
};
|
|
670
|
-
var DropdownToolbarItem = ({ menu, group }) => {
|
|
858
|
+
var DropdownToolbarItem = ({ menu, group, holds }) => {
|
|
671
859
|
const items = useMenuItems(menu, group);
|
|
672
860
|
const { disabled, testId, applyActive, caretDown = true } = group.properties;
|
|
673
861
|
const activeItem = items?.find((item) => !!item.properties.checked);
|
|
@@ -696,7 +884,8 @@ var DropdownToolbarItem = ({ menu, group }) => {
|
|
|
696
884
|
disabled,
|
|
697
885
|
iconSize: menu.iconSize,
|
|
698
886
|
caretDown: caretDown && !disabled,
|
|
699
|
-
testId
|
|
887
|
+
testId,
|
|
888
|
+
...holds && { [TOOLBAR_HOLDS_ATTRIBUTE]: holds }
|
|
700
889
|
});
|
|
701
890
|
if (disabled) return trigger;
|
|
702
891
|
return /* @__PURE__ */ jsx(ActionMenu, {
|
|
@@ -768,7 +957,21 @@ var ToggleGroupToolbarItem = ({ menu, group }) => {
|
|
|
768
957
|
children
|
|
769
958
|
});
|
|
770
959
|
};
|
|
771
|
-
var
|
|
960
|
+
var TextToolbarItem = ({ action }) => {
|
|
961
|
+
const { t } = Hooks.useTranslation(translationKey);
|
|
962
|
+
const { label, hidden, testId, classNames } = action.properties;
|
|
963
|
+
if (hidden) return null;
|
|
964
|
+
return /* @__PURE__ */ jsx(Toolbar.Text, {
|
|
965
|
+
classNames,
|
|
966
|
+
...testId && { "data-testid": testId },
|
|
967
|
+
children: Theme.toLocalizedString(label, t)
|
|
968
|
+
});
|
|
969
|
+
};
|
|
970
|
+
/**
|
|
971
|
+
* One menu item rendered as its toolbar control (button, toggle, switch, dropdown, toggle group or custom); `collapsed`
|
|
972
|
+
* renders its compact form.
|
|
973
|
+
*/
|
|
974
|
+
var MenuToolbarItem = ({ menu, item, collapsed = false }) => {
|
|
772
975
|
if (isSeparator(item)) return /* @__PURE__ */ jsx(Toolbar.Separator, { variant: item.properties.variant === "line" ? "line" : "gap" });
|
|
773
976
|
if (isMenuGroup(item)) return item.properties.variant === "dropdownMenu" ? /* @__PURE__ */ jsx(DropdownToolbarItem, {
|
|
774
977
|
menu,
|
|
@@ -785,31 +988,270 @@ var ToolbarItem = ({ menu, item }) => {
|
|
|
785
988
|
});
|
|
786
989
|
case "toggle": return /* @__PURE__ */ jsx(ToggleToolbarItem, {
|
|
787
990
|
menu,
|
|
788
|
-
action
|
|
991
|
+
action,
|
|
992
|
+
compact: collapsed
|
|
789
993
|
});
|
|
790
|
-
case "custom": return action.properties.render ? /* @__PURE__ */ jsx(Fragment, { children: action.properties.render() }) : null;
|
|
994
|
+
case "custom": return action.properties.render ? /* @__PURE__ */ jsx(Fragment$1, { children: action.properties.render({ collapsed }) }) : null;
|
|
995
|
+
case "text": return /* @__PURE__ */ jsx(TextToolbarItem, { action });
|
|
791
996
|
default: return /* @__PURE__ */ jsx(ActionToolbarItem, {
|
|
792
997
|
menu,
|
|
793
|
-
action
|
|
998
|
+
action,
|
|
999
|
+
compact: collapsed
|
|
794
1000
|
});
|
|
795
1001
|
}
|
|
796
1002
|
};
|
|
797
|
-
var
|
|
798
|
-
|
|
799
|
-
|
|
1003
|
+
var ZONES = ["start", "end"];
|
|
1004
|
+
var placementOf = (item) => isSeparator(item) ? {} : item.properties.placement ?? {};
|
|
1005
|
+
/** A named group without a render variant: inline in a toolbar, a submenu in a menu. */
|
|
1006
|
+
var isPlainGroup = (item) => isMenuGroup(item) && !item.properties.variant;
|
|
1007
|
+
/** Sorts by `placement.order`, an item without one keeping its insertion index. */
|
|
1008
|
+
var byOrder = (items) => items.map((item, index) => ({
|
|
1009
|
+
item,
|
|
1010
|
+
order: placementOf(item).order ?? index
|
|
1011
|
+
})).sort((a, b) => a.order - b.order).map(({ item }) => item);
|
|
1012
|
+
/**
|
|
1013
|
+
* Drops separators left leading, trailing or doubled once items are placed elsewhere: of a run between two items, a gap
|
|
1014
|
+
* stays if there is one, as it lays the row out, else the last.
|
|
1015
|
+
*/
|
|
1016
|
+
var trimSeparators = (items) => items.filter((item, index) => {
|
|
1017
|
+
if (!isSeparator(item)) return true;
|
|
1018
|
+
const before = items.findLastIndex((other, at) => at < index && !isSeparator(other));
|
|
1019
|
+
const after = items.findIndex((other, at) => at > index && !isSeparator(other));
|
|
1020
|
+
if (before < 0 || after < 0) return false;
|
|
1021
|
+
const run = items.slice(before + 1, after);
|
|
1022
|
+
const gap = run.findLastIndex((separator) => isSeparator(separator) && separator.properties.variant === "gap");
|
|
1023
|
+
return index === before + 1 + (gap >= 0 ? gap : run.length - 1);
|
|
1024
|
+
});
|
|
1025
|
+
/** A named group laid out inline, its own and contributed items in order; ruled off from what precedes it. */
|
|
1026
|
+
var InlineGroup = ({ menu, group, separated }) => {
|
|
1027
|
+
const items = useMenuItems(menu, group);
|
|
1028
|
+
const ordered = useMemo(() => byOrder(items ?? []), [items]);
|
|
1029
|
+
if (ordered.length === 0) return null;
|
|
1030
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [separated && /* @__PURE__ */ jsx(Toolbar.Separator, { variant: "line" }), ordered.map((item) => /* @__PURE__ */ jsx(MenuToolbarItem, {
|
|
800
1031
|
menu,
|
|
801
1032
|
item
|
|
802
|
-
}, item.id)) });
|
|
1033
|
+
}, item.id))] });
|
|
1034
|
+
};
|
|
1035
|
+
/** A rule in the ⋮ menu where the rows' items it lists change zone or row, or give way to its own. */
|
|
1036
|
+
var menuBreak = (id) => ({
|
|
1037
|
+
id: `toolbar-break-${id}`,
|
|
1038
|
+
type: MenuSeparatorType,
|
|
1039
|
+
properties: { variant: "gap" },
|
|
1040
|
+
data: void 0
|
|
1041
|
+
});
|
|
1042
|
+
/**
|
|
1043
|
+
* The ⋮ menu: what collapsed out of the rows, in the rows' order and ruled where they are (named groups as submenus),
|
|
1044
|
+
* then the overflow group's own and contributed items.
|
|
1045
|
+
*/
|
|
1046
|
+
var OverflowMenu = ({ menu, group, collapsed }) => {
|
|
1047
|
+
const items = useMenuItems(menu, group);
|
|
1048
|
+
const actions = useMemo(() => trimSeparators([
|
|
1049
|
+
...collapsed,
|
|
1050
|
+
menuBreak("overflow"),
|
|
1051
|
+
...byOrder(items ?? [])
|
|
1052
|
+
]), [collapsed, items]);
|
|
1053
|
+
return /* @__PURE__ */ jsx(OverflowMenuTrigger, {
|
|
1054
|
+
menu,
|
|
1055
|
+
actions,
|
|
1056
|
+
testId: group.properties.testId
|
|
1057
|
+
});
|
|
1058
|
+
};
|
|
1059
|
+
var OverflowMenuTrigger = ({ menu, actions, testId }) => {
|
|
1060
|
+
const { t } = Hooks.useTranslation(translationKey);
|
|
1061
|
+
if (actions.length === 0) return null;
|
|
1062
|
+
return /* @__PURE__ */ jsx(ActionMenu, {
|
|
1063
|
+
...menu,
|
|
1064
|
+
actions,
|
|
1065
|
+
children: /* @__PURE__ */ jsx(Button.Root, {
|
|
1066
|
+
"data-testid": testId ?? TOOLBAR_OVERFLOW_TESTID,
|
|
1067
|
+
icon: "ph--dots-three-vertical--regular",
|
|
1068
|
+
iconOnly: true,
|
|
1069
|
+
variant: "ghost",
|
|
1070
|
+
label: t("toolbar-overflow.menu")
|
|
1071
|
+
})
|
|
1072
|
+
});
|
|
1073
|
+
};
|
|
1074
|
+
/** The element a row lays out in: the `Toolbar.Root` scroll frame around it, else the row itself. */
|
|
1075
|
+
var frameOf = (row) => row.parentElement?.classList.contains("dx-toolbar-scroll") ? row.parentElement : row;
|
|
1076
|
+
/** A menu cannot show a control the contributor renders itself, or a label, so such items never leave the row. */
|
|
1077
|
+
var isMenuable = (item) => !isSeparator(item) && item.properties.variant !== "custom" && item.properties.variant !== "text";
|
|
1078
|
+
/**
|
|
1079
|
+
* A ranked item that has a compact form collapses in place to it: a `custom` item renders with `collapsed`, and an
|
|
1080
|
+
* action shown with its label and an icon shows the icon alone.
|
|
1081
|
+
*/
|
|
1082
|
+
var isCompactable = (item) => {
|
|
1083
|
+
if (isSeparator(item) || isMenuGroup(item) || placementOf(item).collapse === void 0) return false;
|
|
1084
|
+
const { variant, icon, iconOnly } = item.properties;
|
|
1085
|
+
return variant === "custom" || !!icon && iconOnly === false && variant !== "text" && variant !== "switch";
|
|
1086
|
+
};
|
|
1087
|
+
/**
|
|
1088
|
+
* Collapses items while any row is too narrow, so the toolbar fills its container without overflowing it. First each
|
|
1089
|
+
* ranked item with a compact form takes it (highest rank first); then groups marked `fold` fold; then ranked items move
|
|
1090
|
+
* into the overflow menu, then the rest, last first. Each step is undone once the toolbar is wider than when it was
|
|
1091
|
+
* taken, or tried again once an item's content changes, so hidden items are never measured.
|
|
1092
|
+
*/
|
|
1093
|
+
var useCollapse = (menu, units, rows, bounds) => {
|
|
1094
|
+
const registry = useContext(RegistryContext);
|
|
1095
|
+
const steps = useMemo(() => {
|
|
1096
|
+
const canCollapse = (item) => {
|
|
1097
|
+
if (!isMenuable(item)) return false;
|
|
1098
|
+
if (!isPlainGroup(item)) return true;
|
|
1099
|
+
const children = (registry.get(menu.items(item)) ?? []).filter((child) => !isSeparator(child));
|
|
1100
|
+
return children.length > 0 && children.every(isMenuable);
|
|
1101
|
+
};
|
|
1102
|
+
const ranked = units.map((item, index) => ({
|
|
1103
|
+
item,
|
|
1104
|
+
rank: placementOf(item).collapse,
|
|
1105
|
+
index
|
|
1106
|
+
})).filter(({ rank }) => rank !== void 0).sort((a, b) => (b.rank ?? 0) - (a.rank ?? 0) || b.index - a.index).map(({ item }) => item);
|
|
1107
|
+
const rest = units.filter((item) => placementOf(item).collapse === void 0 && canCollapse(item)).reverse();
|
|
1108
|
+
const order = [...ranked.filter(canCollapse), ...rest];
|
|
1109
|
+
return [
|
|
1110
|
+
...ranked.filter(isCompactable).map((item) => ({
|
|
1111
|
+
kind: "compact",
|
|
1112
|
+
item
|
|
1113
|
+
})),
|
|
1114
|
+
...order.filter((item) => isPlainGroup(item) && placementOf(item).fold).map((item) => ({
|
|
1115
|
+
kind: "fold",
|
|
1116
|
+
item
|
|
1117
|
+
})),
|
|
1118
|
+
...order.map((item) => ({
|
|
1119
|
+
kind: "move",
|
|
1120
|
+
item
|
|
1121
|
+
}))
|
|
1122
|
+
];
|
|
1123
|
+
}, [
|
|
1124
|
+
registry,
|
|
1125
|
+
menu,
|
|
1126
|
+
units
|
|
1127
|
+
]);
|
|
1128
|
+
const [count, setCount] = useState(0);
|
|
1129
|
+
const thresholds = useRef([]);
|
|
1130
|
+
const [width, setWidth] = useState(0);
|
|
1131
|
+
const [contentChanges, setContentChanges] = useState(0);
|
|
1132
|
+
const measuredChanges = useRef(contentChanges);
|
|
1133
|
+
const stepsKey = steps.map(({ kind, item }) => `${kind}:${item.id}`).join("\n");
|
|
1134
|
+
useLayoutEffect(() => {
|
|
1135
|
+
if (steps.length === 0 && count === 0) return;
|
|
1136
|
+
const elements = rows.current.filter((row) => !!row);
|
|
1137
|
+
if (elements.length === 0) return;
|
|
1138
|
+
const width = (bounds ?? frameOf(elements[0])).clientWidth;
|
|
1139
|
+
if (width === 0) return;
|
|
1140
|
+
if (measuredChanges.current !== contentChanges) {
|
|
1141
|
+
measuredChanges.current = contentChanges;
|
|
1142
|
+
thresholds.current.fill(0);
|
|
1143
|
+
}
|
|
1144
|
+
const overflowing = elements.some((row) => row.scrollWidth > row.clientWidth + 1);
|
|
1145
|
+
if (overflowing && count < steps.length) {
|
|
1146
|
+
thresholds.current[count] = width;
|
|
1147
|
+
setCount(count + 1);
|
|
1148
|
+
} else if (!overflowing && count > 0 && width > (thresholds.current[count - 1] ?? Infinity)) setCount(count - 1);
|
|
1149
|
+
}, [
|
|
1150
|
+
units,
|
|
1151
|
+
stepsKey,
|
|
1152
|
+
count,
|
|
1153
|
+
width,
|
|
1154
|
+
bounds,
|
|
1155
|
+
contentChanges
|
|
1156
|
+
]);
|
|
1157
|
+
const observed = steps.length > 0;
|
|
1158
|
+
useLayoutEffect(() => {
|
|
1159
|
+
const element = rows.current[0];
|
|
1160
|
+
if (!observed || !element) return;
|
|
1161
|
+
const observer = new ResizeObserver(([entry]) => setWidth(entry.contentRect.width));
|
|
1162
|
+
observer.observe(bounds ?? frameOf(element));
|
|
1163
|
+
return () => observer.disconnect();
|
|
1164
|
+
}, [
|
|
1165
|
+
observed,
|
|
1166
|
+
rows,
|
|
1167
|
+
bounds
|
|
1168
|
+
]);
|
|
1169
|
+
useLayoutEffect(() => {
|
|
1170
|
+
const elements = rows.current.filter((row) => !!row);
|
|
1171
|
+
if (!observed || elements.length === 0) return;
|
|
1172
|
+
const observer = new MutationObserver(() => setContentChanges((changes) => changes + 1));
|
|
1173
|
+
elements.forEach((row) => observer.observe(row, {
|
|
1174
|
+
childList: true,
|
|
1175
|
+
subtree: true,
|
|
1176
|
+
characterData: true
|
|
1177
|
+
}));
|
|
1178
|
+
return () => observer.disconnect();
|
|
1179
|
+
}, [
|
|
1180
|
+
observed,
|
|
1181
|
+
rows,
|
|
1182
|
+
units,
|
|
1183
|
+
count
|
|
1184
|
+
]);
|
|
1185
|
+
return useMemo(() => {
|
|
1186
|
+
const taken = steps.slice(0, count);
|
|
1187
|
+
return {
|
|
1188
|
+
moved: taken.filter(({ kind }) => kind === "move").map(({ item }) => item),
|
|
1189
|
+
folded: new Set(taken.filter(({ kind }) => kind === "fold").map(({ item }) => item.id)),
|
|
1190
|
+
compacted: new Set(taken.filter(({ kind }) => kind === "compact").map(({ item }) => item.id))
|
|
1191
|
+
};
|
|
1192
|
+
}, [steps, count]);
|
|
1193
|
+
};
|
|
1194
|
+
/** A folded group: its items in a dropdown, under the group's own label and icon. */
|
|
1195
|
+
var FoldedGroup = ({ menu, group }) => {
|
|
1196
|
+
const registry = useContext(RegistryContext);
|
|
1197
|
+
const dropdown = useMemo(() => {
|
|
1198
|
+
const { label, icon, ...properties } = group.properties;
|
|
1199
|
+
return {
|
|
1200
|
+
...group,
|
|
1201
|
+
properties: {
|
|
1202
|
+
...properties,
|
|
1203
|
+
label,
|
|
1204
|
+
icon,
|
|
1205
|
+
variant: "dropdownMenu"
|
|
1206
|
+
}
|
|
1207
|
+
};
|
|
1208
|
+
}, [group]);
|
|
1209
|
+
const holds = useMemo(() => heldTestIds(registry, menu, group).join(" "), [
|
|
1210
|
+
registry,
|
|
1211
|
+
menu,
|
|
1212
|
+
group
|
|
1213
|
+
]);
|
|
1214
|
+
return /* @__PURE__ */ jsx(DropdownToolbarItem, {
|
|
1215
|
+
menu,
|
|
1216
|
+
group: dropdown,
|
|
1217
|
+
holds
|
|
1218
|
+
});
|
|
1219
|
+
};
|
|
1220
|
+
/** The test ids of a group's items at any depth. */
|
|
1221
|
+
var heldTestIds = (registry, menu, group) => (registry.get(menu.items(group)) ?? []).flatMap((item) => isSeparator(item) ? [] : [...item.properties.testId ? [item.properties.testId] : [], ...isMenuGroup(item) ? heldTestIds(registry, menu, item) : []]);
|
|
1222
|
+
var setRef = (ref, value) => {
|
|
1223
|
+
if (typeof ref === "function") ref(value);
|
|
1224
|
+
else if (ref) ref.current = value;
|
|
1225
|
+
};
|
|
1226
|
+
/** Each group's items from `base`, then from `extra`, so a second graph extends the first group by group. */
|
|
1227
|
+
var mergeItems = (base, extra) => {
|
|
1228
|
+
const atoms = /* @__PURE__ */ new Map();
|
|
1229
|
+
return (group) => {
|
|
1230
|
+
const key = group?.id ?? "";
|
|
1231
|
+
let atom = atoms.get(key);
|
|
1232
|
+
if (!atom) {
|
|
1233
|
+
atom = Atom.make((get) => {
|
|
1234
|
+
const own = get(base(group));
|
|
1235
|
+
const added = get(extra(group));
|
|
1236
|
+
return own || added ? [...own ?? [], ...added ?? []] : null;
|
|
1237
|
+
});
|
|
1238
|
+
atoms.set(key, atom);
|
|
1239
|
+
}
|
|
1240
|
+
return atom;
|
|
1241
|
+
};
|
|
803
1242
|
};
|
|
804
1243
|
/**
|
|
805
|
-
* A
|
|
806
|
-
*
|
|
807
|
-
* `
|
|
1244
|
+
* A toolbar driven from a `MenuActions`. Each item's `placement` puts it in the start or end zone of a row; a
|
|
1245
|
+
* plain named group renders inline and others extend it (`MenuBuilder.extend`); the overflow menu (⋮,
|
|
1246
|
+
* `TOOLBAR_OVERFLOW_ID`) ends the first row and takes collapsible items while a row is too narrow. One row renders as a
|
|
1247
|
+
* single `Toolbar.Root` (which takes the props and ref); more stack one per row. Hand-written controls join the graph as
|
|
1248
|
+
* `custom` items (`MenuBuilder.custom`), labels as `text` items.
|
|
808
1249
|
*/
|
|
809
|
-
var ActionToolbar = Util.composable(({ items, contributions, onAction, caller, iconSize, attendableId, alwaysActive,
|
|
1250
|
+
var ActionToolbar = Util.composable(({ items, contributions, onAction, caller, iconSize, attendableId, alwaysActive, customActions, bounds, children: _, ...props }, forwardedRef) => {
|
|
810
1251
|
const standalone = useMenuActions();
|
|
1252
|
+
const custom = useMenuActions(customActions);
|
|
811
1253
|
const menu = useMemo(() => ({
|
|
812
|
-
items: items ?? standalone.items,
|
|
1254
|
+
items: customActions ? mergeItems(items ?? standalone.items, custom.items) : items ?? standalone.items,
|
|
813
1255
|
contributions: contributions ?? standalone.contributions,
|
|
814
1256
|
onAction,
|
|
815
1257
|
caller,
|
|
@@ -820,18 +1262,59 @@ var ActionToolbar = Util.composable(({ items, contributions, onAction, caller, i
|
|
|
820
1262
|
onAction,
|
|
821
1263
|
caller,
|
|
822
1264
|
iconSize,
|
|
823
|
-
standalone
|
|
1265
|
+
standalone,
|
|
1266
|
+
customActions,
|
|
1267
|
+
custom
|
|
824
1268
|
]);
|
|
825
1269
|
const { hasAttention } = useAttention(attendableId);
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
1270
|
+
const rootItems = useMenuItems(menu);
|
|
1271
|
+
const overflow = rootItems?.find((item) => isMenuGroup(item) && item.id === "toolbar-overflow") ?? defaultOverflowGroup;
|
|
1272
|
+
const units = useMemo(() => (rootItems ?? []).filter((item) => item.id !== TOOLBAR_OVERFLOW_ID), [rootItems]);
|
|
1273
|
+
const rows = useRef([]);
|
|
1274
|
+
const { moved: collapsed, folded, compacted } = useCollapse(menu, units, rows, bounds);
|
|
1275
|
+
const rowCount = Math.max(1, ...units.map((item) => (placementOf(item).row ?? 0) + 1));
|
|
1276
|
+
const inZone = (row, zone, keep) => byOrder(units.filter((item) => {
|
|
1277
|
+
const placement = placementOf(item);
|
|
1278
|
+
return (placement.row ?? 0) === row && (placement.zone ?? "start") === zone;
|
|
1279
|
+
})).filter(keep);
|
|
1280
|
+
const zone = (row, zone) => trimSeparators(inZone(row, zone, (item) => !collapsed.includes(item)));
|
|
1281
|
+
const moved = Array.from({ length: rowCount }, (_, row) => ZONES.flatMap((name) => [menuBreak(`${row}-${name}`), ...inZone(row, name, (item) => isSeparator(item) || collapsed.includes(item))])).flat();
|
|
1282
|
+
const renderRow = (row) => {
|
|
1283
|
+
const zones = ZONES.map((name) => ({
|
|
1284
|
+
name,
|
|
1285
|
+
items: zone(row, name)
|
|
1286
|
+
}));
|
|
1287
|
+
const first = row === 0;
|
|
1288
|
+
return /* @__PURE__ */ jsxs(Toolbar.Root, {
|
|
1289
|
+
...first ? Util.composableProps(props, { classNames: attendableId }) : { classNames: props.classNames },
|
|
1290
|
+
"data-row": rowCount > 1 ? row : void 0,
|
|
1291
|
+
inactive: !alwaysActive && !hasAttention,
|
|
1292
|
+
ref: (element) => {
|
|
1293
|
+
rows.current[row] = element;
|
|
1294
|
+
first && setRef(forwardedRef, element);
|
|
1295
|
+
},
|
|
1296
|
+
children: [zones.map(({ name, items }, index) => /* @__PURE__ */ jsxs(Fragment, { children: [index > 0 && items.length > 0 && /* @__PURE__ */ jsx(Toolbar.Separator, { variant: "gap" }), items.map((item, index) => isPlainGroup(item) && folded.has(item.id) ? /* @__PURE__ */ jsx(FoldedGroup, {
|
|
1297
|
+
menu,
|
|
1298
|
+
group: item
|
|
1299
|
+
}, item.id) : isPlainGroup(item) ? /* @__PURE__ */ jsx(InlineGroup, {
|
|
1300
|
+
menu,
|
|
1301
|
+
group: item,
|
|
1302
|
+
separated: index > 0 && !placementOf(item).fold
|
|
1303
|
+
}, item.id) : /* @__PURE__ */ jsx(MenuToolbarItem, {
|
|
1304
|
+
menu,
|
|
1305
|
+
item,
|
|
1306
|
+
collapsed: compacted.has(item.id)
|
|
1307
|
+
}, item.id))] }, name)), first && /* @__PURE__ */ jsx(OverflowMenu, {
|
|
1308
|
+
menu,
|
|
1309
|
+
group: overflow,
|
|
1310
|
+
collapsed: moved
|
|
1311
|
+
})]
|
|
1312
|
+
}, row);
|
|
1313
|
+
};
|
|
1314
|
+
return rowCount === 1 ? renderRow(0) : /* @__PURE__ */ jsx("div", {
|
|
1315
|
+
role: "none",
|
|
1316
|
+
className: "flex flex-col w-full min-w-0 min-h-fit",
|
|
1317
|
+
children: Array.from({ length: rowCount }, (_, row) => renderRow(row))
|
|
835
1318
|
});
|
|
836
1319
|
});
|
|
837
1320
|
ActionToolbar.displayName = "ActionToolbar";
|
|
@@ -936,106 +1419,6 @@ var GroupMenu = ({ fields, value, onChange, label, none, testId = "group" }) =>
|
|
|
936
1419
|
};
|
|
937
1420
|
GroupMenu.displayName = "GroupMenu";
|
|
938
1421
|
//#endregion
|
|
939
|
-
//#region src/builder.ts
|
|
940
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-menu/src/builder.ts";
|
|
941
|
-
/** Default trigger for toolbar overflow (⋮) dropdown menus. */
|
|
942
|
-
var overflowMenuProperties = {
|
|
943
|
-
label: ["toolbar-overflow.menu", { ns: translationKey }],
|
|
944
|
-
icon: "ph--dots-three-vertical--regular",
|
|
945
|
-
iconOnly: true,
|
|
946
|
-
caretDown: false,
|
|
947
|
-
variant: "dropdownMenu"
|
|
948
|
-
};
|
|
949
|
-
var MenuBuilderImpl = class MenuBuilderImpl {
|
|
950
|
-
_data;
|
|
951
|
-
_rootId;
|
|
952
|
-
_separatorCount = 0;
|
|
953
|
-
constructor(_data, _rootId) {
|
|
954
|
-
this._data = _data;
|
|
955
|
-
this._rootId = _rootId;
|
|
956
|
-
}
|
|
957
|
-
root(props) {
|
|
958
|
-
invariant(this._rootId === "root", "Root group can only be at the top level", {
|
|
959
|
-
"~LogMeta": "~LogMeta",
|
|
960
|
-
F: __dxlog_file,
|
|
961
|
-
L: 84,
|
|
962
|
-
S: this,
|
|
963
|
-
A: ["this._rootId === 'root'", "'Root group can only be at the top level'"]
|
|
964
|
-
});
|
|
965
|
-
invariant(this._data.nodes.find((node) => node.id === "root") === void 0, "Root group can only be created once", {
|
|
966
|
-
"~LogMeta": "~LogMeta",
|
|
967
|
-
F: __dxlog_file,
|
|
968
|
-
L: 85,
|
|
969
|
-
S: this,
|
|
970
|
-
A: ["this._data.nodes.find((node) => node.id === 'root') === undefined", "'Root group can only be created once'"]
|
|
971
|
-
});
|
|
972
|
-
this._data.nodes.push(createMenuItemGroup("root", props));
|
|
973
|
-
return this;
|
|
974
|
-
}
|
|
975
|
-
build() {
|
|
976
|
-
return this._data;
|
|
977
|
-
}
|
|
978
|
-
action(id, props, invoke) {
|
|
979
|
-
this._data.nodes.push(createMenuAction(id, invoke, props));
|
|
980
|
-
this._data.edges.push({
|
|
981
|
-
source: this._rootId,
|
|
982
|
-
target: id,
|
|
983
|
-
relation: "child"
|
|
984
|
-
});
|
|
985
|
-
return this;
|
|
986
|
-
}
|
|
987
|
-
switch(id, props, invoke) {
|
|
988
|
-
return this.action(id, {
|
|
989
|
-
...props,
|
|
990
|
-
variant: "switch"
|
|
991
|
-
}, invoke);
|
|
992
|
-
}
|
|
993
|
-
group(id, props, cb) {
|
|
994
|
-
this._data.nodes.push(createMenuItemGroup(id, props));
|
|
995
|
-
this._data.edges.push({
|
|
996
|
-
source: this._rootId,
|
|
997
|
-
target: id,
|
|
998
|
-
relation: "child"
|
|
999
|
-
});
|
|
1000
|
-
cb(new MenuBuilderImpl(this._data, id));
|
|
1001
|
-
return this;
|
|
1002
|
-
}
|
|
1003
|
-
menu(id, cb, testId) {
|
|
1004
|
-
return this.group(id, testId === void 0 ? overflowMenuProperties : {
|
|
1005
|
-
...overflowMenuProperties,
|
|
1006
|
-
testId
|
|
1007
|
-
}, cb);
|
|
1008
|
-
}
|
|
1009
|
-
subgraph(subgraphOrCb) {
|
|
1010
|
-
if (!subgraphOrCb) return this;
|
|
1011
|
-
if (typeof subgraphOrCb === "function") subgraphOrCb(new MenuBuilderImpl(this._data, this._rootId));
|
|
1012
|
-
else {
|
|
1013
|
-
this._data.nodes.push(...subgraphOrCb.nodes);
|
|
1014
|
-
this._data.edges.push(...subgraphOrCb.edges);
|
|
1015
|
-
}
|
|
1016
|
-
return this;
|
|
1017
|
-
}
|
|
1018
|
-
separator(variant = "gap") {
|
|
1019
|
-
const id = `separator-${++this._separatorCount}`;
|
|
1020
|
-
this._data.nodes.push({
|
|
1021
|
-
id,
|
|
1022
|
-
type: MenuSeparatorType,
|
|
1023
|
-
properties: { variant },
|
|
1024
|
-
data: void 0
|
|
1025
|
-
});
|
|
1026
|
-
this._data.edges.push({
|
|
1027
|
-
source: this._rootId,
|
|
1028
|
-
target: id,
|
|
1029
|
-
relation: "child"
|
|
1030
|
-
});
|
|
1031
|
-
return this;
|
|
1032
|
-
}
|
|
1033
|
-
};
|
|
1034
|
-
var MenuBuilder = Object.freeze({ make: () => new MenuBuilderImpl({
|
|
1035
|
-
nodes: [],
|
|
1036
|
-
edges: []
|
|
1037
|
-
}, "root") });
|
|
1038
|
-
//#endregion
|
|
1039
1422
|
//#region src/toolbar.ts
|
|
1040
1423
|
/** `disposition` value an action opts into to appear in an object toolbar (vs context-menu-only). */
|
|
1041
1424
|
var TOOLBAR_DISPOSITION = "toolbar";
|
|
@@ -1054,6 +1437,6 @@ var PROMPT_DISPOSITION = "prompt";
|
|
|
1054
1437
|
/** Filter for {@link graphActions}: keeps only actions a producer opted into a prompt row. */
|
|
1055
1438
|
var isPromptAction = (action) => AppGraphNode.hasDisposition(action, PROMPT_DISPOSITION);
|
|
1056
1439
|
//#endregion
|
|
1057
|
-
export { ActionMenu, ActionToolbar, GroupMenu, MenuBuilder, MenuSeparatorType, PROMPT_DISPOSITION, SortMenu, TOOLBAR_DISPOSITION, applyPresentation, buildGraphMenu, createGapSeparator, createLineSeparator, createMenuAction, createMenuItemGroup, executeMenuAction, fallbackIcon, graphActions, isMenuGroup, isPromptAction, isSeparator, isToolbarAction, makeMenuActions, resolveItems, useGraphMenuActions, useMenuActions, useMenuBuilder, useMenuContribution, useMenuGraph, useMenuItems };
|
|
1440
|
+
export { ActionMenu, ActionToolbar, GroupMenu, MenuBuilder, MenuSeparatorType, MenuToolbarItem, PROMPT_DISPOSITION, SortMenu, TOOLBAR_DISPOSITION, TOOLBAR_OVERFLOW_ID, applyPresentation, buildGraphMenu, createGapSeparator, createLineSeparator, createMenuAction, createMenuItemGroup, executeMenuAction, fallbackIcon, graphActions, isMenuGroup, isPromptAction, isSeparator, isToolbarAction, makeMenuActions, resolveItems, useGraphMenuActions, useMenuActions, useMenuBuilder, useMenuContribution, useMenuGraph, useMenuItems };
|
|
1058
1441
|
|
|
1059
1442
|
//# sourceMappingURL=index.mjs.map
|