@dxos/react-ui-menu 0.7.5-main.937ce75 → 0.7.5-main.e9bb01b
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/browser/index.mjs +322 -115
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +320 -103
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +322 -115
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/DropdownMenu.d.ts +9 -8
- package/dist/types/src/components/DropdownMenu.d.ts.map +1 -1
- package/dist/types/src/components/MenuContext.d.ts +13 -0
- package/dist/types/src/components/MenuContext.d.ts.map +1 -0
- package/dist/types/src/components/ToolbarMenu.d.ts +20 -0
- package/dist/types/src/components/ToolbarMenu.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +2 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/defs.d.ts +34 -7
- package/dist/types/src/defs.d.ts.map +1 -1
- package/dist/types/src/hooks.d.ts +17 -0
- package/dist/types/src/hooks.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/testing/Menus.stories.d.ts +4 -1
- package/dist/types/src/testing/Menus.stories.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +6 -6
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +42 -1
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -12
- package/src/components/DropdownMenu.tsx +35 -27
- package/src/components/MenuContext.tsx +57 -0
- package/src/components/ToolbarMenu.tsx +185 -0
- package/src/components/index.ts +2 -1
- package/src/defs.ts +38 -7
- package/src/hooks.ts +72 -0
- package/src/index.ts +2 -0
- package/src/testing/Menus.stories.tsx +30 -18
- package/src/testing/index.ts +24 -5
- package/src/util.ts +58 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +0 -4
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/ToolbarDropdownMenu.d.ts +0 -4
- package/dist/types/src/components/Toolbar/ToolbarDropdownMenu.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/ToolbarToggleGroup.d.ts +0 -4
- package/dist/types/src/components/Toolbar/ToolbarToggleGroup.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/defs.d.ts +0 -30
- package/dist/types/src/components/Toolbar/defs.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/index.d.ts +0 -3
- package/dist/types/src/components/Toolbar/index.d.ts.map +0 -1
- package/src/components/Toolbar/Toolbar.tsx +0 -71
- package/src/components/Toolbar/ToolbarDropdownMenu.tsx +0 -36
- package/src/components/Toolbar/ToolbarToggleGroup.tsx +0 -39
- package/src/components/Toolbar/defs.ts +0 -36
- package/src/components/Toolbar/index.ts +0 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// packages/ui/react-ui-menu/src/components/DropdownMenu.tsx
|
|
2
2
|
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
3
|
-
import
|
|
3
|
+
import React3, { useCallback } from "react";
|
|
4
4
|
import { DropdownMenu as NaturalDropdownMenu, Icon } from "@dxos/react-ui";
|
|
5
5
|
|
|
6
6
|
// packages/ui/react-ui-menu/src/components/ActionLabel.tsx
|
|
@@ -20,10 +20,61 @@ var translations_default = [
|
|
|
20
20
|
];
|
|
21
21
|
|
|
22
22
|
// packages/ui/react-ui-menu/src/util.ts
|
|
23
|
+
import { ACTION_GROUP_TYPE, ACTION_TYPE, actionGroupSymbol } from "@dxos/app-graph";
|
|
23
24
|
import { getHostPlatform } from "@dxos/util";
|
|
24
25
|
var getShortcut = (action) => {
|
|
25
26
|
return typeof action.properties?.keyBinding === "string" ? action.properties.keyBinding : action.properties?.keyBinding?.[getHostPlatform()];
|
|
26
27
|
};
|
|
28
|
+
var noop = () => {
|
|
29
|
+
};
|
|
30
|
+
var createMenuAction = (id, properties) => ({
|
|
31
|
+
id,
|
|
32
|
+
type: ACTION_TYPE,
|
|
33
|
+
properties,
|
|
34
|
+
data: noop
|
|
35
|
+
});
|
|
36
|
+
var createMenuItemGroup = (id, properties) => ({
|
|
37
|
+
id,
|
|
38
|
+
type: ACTION_GROUP_TYPE,
|
|
39
|
+
properties,
|
|
40
|
+
data: actionGroupSymbol
|
|
41
|
+
});
|
|
42
|
+
var createGapSeparator = (id = "gap", source = "root") => ({
|
|
43
|
+
nodes: [
|
|
44
|
+
{
|
|
45
|
+
id,
|
|
46
|
+
type: "@dxos/react-ui-toolbar/separator",
|
|
47
|
+
properties: {
|
|
48
|
+
variant: "gap"
|
|
49
|
+
},
|
|
50
|
+
data: void 0
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
edges: [
|
|
54
|
+
{
|
|
55
|
+
source,
|
|
56
|
+
target: id
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
});
|
|
60
|
+
var createLineSeparator = (id = "line", source = "root") => ({
|
|
61
|
+
nodes: [
|
|
62
|
+
{
|
|
63
|
+
id,
|
|
64
|
+
type: "@dxos/react-ui-toolbar/separator",
|
|
65
|
+
properties: {
|
|
66
|
+
variant: "line"
|
|
67
|
+
},
|
|
68
|
+
data: void 0
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
edges: [
|
|
72
|
+
{
|
|
73
|
+
source,
|
|
74
|
+
target: id
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
});
|
|
27
78
|
|
|
28
79
|
// packages/ui/react-ui-menu/src/components/ActionLabel.tsx
|
|
29
80
|
var ActionLabel = ({ action }) => {
|
|
@@ -36,32 +87,67 @@ var ActionLabel = ({ action }) => {
|
|
|
36
87
|
}, keySymbols(shortcut).join("")));
|
|
37
88
|
};
|
|
38
89
|
|
|
90
|
+
// packages/ui/react-ui-menu/src/components/MenuContext.tsx
|
|
91
|
+
import { createContextScope } from "@radix-ui/react-context";
|
|
92
|
+
import React2, { useMemo } from "react";
|
|
93
|
+
var MENU_NAME = "GraphMenu";
|
|
94
|
+
var [createMenuContext, createMenuScope] = createContextScope(MENU_NAME, []);
|
|
95
|
+
var [MenuContextProvider, useMenu] = createMenuContext(MENU_NAME);
|
|
96
|
+
var menuContextDefaults = {
|
|
97
|
+
iconSize: 5,
|
|
98
|
+
onAction: () => {
|
|
99
|
+
},
|
|
100
|
+
resolveGroupItems: () => null
|
|
101
|
+
};
|
|
102
|
+
var useMenuScope = createMenuScope();
|
|
103
|
+
var MenuProvider = ({ children, resolveGroupItems = menuContextDefaults.resolveGroupItems, onAction = menuContextDefaults.onAction, iconSize = menuContextDefaults.iconSize, attendableId }) => {
|
|
104
|
+
const { scope } = useMenuScope(void 0);
|
|
105
|
+
return /* @__PURE__ */ React2.createElement(MenuContextProvider, {
|
|
106
|
+
resolveGroupItems,
|
|
107
|
+
onAction,
|
|
108
|
+
iconSize,
|
|
109
|
+
attendableId,
|
|
110
|
+
scope
|
|
111
|
+
}, children);
|
|
112
|
+
};
|
|
113
|
+
var useMenuItems = (group, propsItems, consumerName = "useMenuItemConsumer", __menuScope) => {
|
|
114
|
+
const { resolveGroupItems } = useMenu(consumerName, __menuScope);
|
|
115
|
+
return useMemo(() => propsItems ?? resolveGroupItems?.(group) ?? void 0, [
|
|
116
|
+
propsItems,
|
|
117
|
+
group,
|
|
118
|
+
resolveGroupItems
|
|
119
|
+
]);
|
|
120
|
+
};
|
|
121
|
+
|
|
39
122
|
// packages/ui/react-ui-menu/src/components/DropdownMenu.tsx
|
|
40
|
-
var DropdownMenuItem = ({
|
|
123
|
+
var DropdownMenuItem = ({ item, onClick, __menuScope }) => {
|
|
124
|
+
const action = item;
|
|
41
125
|
const handleClick = useCallback((event) => onClick(action, event), [
|
|
42
126
|
action,
|
|
43
127
|
onClick
|
|
44
128
|
]);
|
|
45
|
-
|
|
129
|
+
const { iconSize } = useMenu("DropdownMenuItem", __menuScope);
|
|
130
|
+
return /* @__PURE__ */ React3.createElement(NaturalDropdownMenu.Item, {
|
|
46
131
|
onClick: handleClick,
|
|
47
132
|
classNames: "gap-2",
|
|
48
133
|
disabled: action.properties?.disabled,
|
|
49
134
|
...action.properties?.testId && {
|
|
50
135
|
"data-testid": action.properties.testId
|
|
51
136
|
}
|
|
52
|
-
}, action.properties?.icon && /* @__PURE__ */
|
|
137
|
+
}, action.properties?.icon && /* @__PURE__ */ React3.createElement(Icon, {
|
|
53
138
|
icon: action.properties.icon,
|
|
54
|
-
size:
|
|
55
|
-
}), /* @__PURE__ */
|
|
139
|
+
size: iconSize
|
|
140
|
+
}), /* @__PURE__ */ React3.createElement(ActionLabel, {
|
|
56
141
|
action
|
|
57
142
|
}));
|
|
58
143
|
};
|
|
59
|
-
var DropdownMenuRoot = ({
|
|
144
|
+
var DropdownMenuRoot = ({ items: propsItems, group, open, defaultOpen, onOpenChange, suppressNextTooltip, children, __menuScope, ...naturalProps }) => {
|
|
60
145
|
const [optionsMenuOpen, setOptionsMenuOpen] = useControllableState({
|
|
61
|
-
prop:
|
|
62
|
-
defaultProp:
|
|
63
|
-
onChange:
|
|
146
|
+
prop: open,
|
|
147
|
+
defaultProp: defaultOpen,
|
|
148
|
+
onChange: onOpenChange
|
|
64
149
|
});
|
|
150
|
+
const { onAction } = useMenu("DropdownMenuRoot", __menuScope);
|
|
65
151
|
const handleActionClick = useCallback((action, event) => {
|
|
66
152
|
if (action.properties?.disabled) {
|
|
67
153
|
return;
|
|
@@ -75,19 +161,21 @@ var DropdownMenuRoot = ({ defaultMenuOpen, actions, menuOpen, suppressNextToolti
|
|
|
75
161
|
}, [
|
|
76
162
|
onAction
|
|
77
163
|
]);
|
|
78
|
-
|
|
164
|
+
const items = useMenuItems(group, propsItems);
|
|
165
|
+
return /* @__PURE__ */ React3.createElement(NaturalDropdownMenu.Root, {
|
|
79
166
|
open: optionsMenuOpen,
|
|
80
167
|
onOpenChange: (nextOpen) => {
|
|
81
168
|
if (!nextOpen && suppressNextTooltip) {
|
|
82
169
|
suppressNextTooltip.current = true;
|
|
83
170
|
}
|
|
84
171
|
return setOptionsMenuOpen(nextOpen);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
172
|
+
},
|
|
173
|
+
...naturalProps
|
|
174
|
+
}, children, /* @__PURE__ */ React3.createElement(NaturalDropdownMenu.Portal, null, /* @__PURE__ */ React3.createElement(NaturalDropdownMenu.Content, null, /* @__PURE__ */ React3.createElement(NaturalDropdownMenu.Viewport, null, items?.map((item) => /* @__PURE__ */ React3.createElement(DropdownMenuItem, {
|
|
175
|
+
key: item.id,
|
|
176
|
+
item,
|
|
89
177
|
onClick: handleActionClick
|
|
90
|
-
}))), /* @__PURE__ */
|
|
178
|
+
}))), /* @__PURE__ */ React3.createElement(NaturalDropdownMenu.Arrow, null))));
|
|
91
179
|
};
|
|
92
180
|
var DropdownMenu = {
|
|
93
181
|
Root: DropdownMenuRoot,
|
|
@@ -95,137 +183,256 @@ var DropdownMenu = {
|
|
|
95
183
|
VirtualTrigger: NaturalDropdownMenu.VirtualTrigger
|
|
96
184
|
};
|
|
97
185
|
|
|
98
|
-
// packages/ui/react-ui-menu/src/components/
|
|
99
|
-
import
|
|
100
|
-
import { Toolbar as
|
|
186
|
+
// packages/ui/react-ui-menu/src/components/ToolbarMenu.tsx
|
|
187
|
+
import React4, { useCallback as useCallback2, useRef } from "react";
|
|
188
|
+
import { Icon as Icon2, Toolbar as NaturalToolbar } from "@dxos/react-ui";
|
|
189
|
+
import { useAttention } from "@dxos/react-ui-attention";
|
|
101
190
|
|
|
102
|
-
// packages/ui/react-ui-menu/src/
|
|
103
|
-
import
|
|
104
|
-
|
|
105
|
-
var
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
191
|
+
// packages/ui/react-ui-menu/src/defs.ts
|
|
192
|
+
import { ACTION_GROUP_TYPE as ACTION_GROUP_TYPE2 } from "@dxos/app-graph";
|
|
193
|
+
var MenuSeparatorType = "@dxos/react-ui-toolbar/separator";
|
|
194
|
+
var isSeparator = (node) => node.type === MenuSeparatorType;
|
|
195
|
+
var isMenuGroup = (node) => node.type === ACTION_GROUP_TYPE2;
|
|
196
|
+
|
|
197
|
+
// packages/ui/react-ui-menu/src/components/ToolbarMenu.tsx
|
|
198
|
+
var ActionToolbarItem = ({ action, __menuScope }) => {
|
|
199
|
+
const { onAction, iconSize } = useMenu("ActionToolbarItem", __menuScope);
|
|
200
|
+
const handleClick = useCallback2(() => {
|
|
201
|
+
onAction?.(action);
|
|
202
|
+
}, [
|
|
203
|
+
action,
|
|
204
|
+
onAction
|
|
109
205
|
]);
|
|
110
|
-
const { icon, iconOnly = true, disabled, testId } =
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
suppressNextTooltip
|
|
116
|
-
}, /* @__PURE__ */ React3.createElement(DropdownMenu.Trigger, {
|
|
117
|
-
asChild: true
|
|
118
|
-
}, /* @__PURE__ */ React3.createElement(NaturalToolbar.IconButton, {
|
|
119
|
-
size: 5,
|
|
120
|
-
variant: "ghost",
|
|
206
|
+
const { icon, iconOnly = true, disabled, testId, hidden, classNames } = action.properties;
|
|
207
|
+
const Root = icon ? NaturalToolbar.IconButton : NaturalToolbar.Button;
|
|
208
|
+
const rootProps = icon ? {
|
|
209
|
+
icon,
|
|
210
|
+
size: iconSize,
|
|
121
211
|
iconOnly,
|
|
212
|
+
label: /* @__PURE__ */ React4.createElement(ActionLabel, {
|
|
213
|
+
action
|
|
214
|
+
})
|
|
215
|
+
} : {
|
|
216
|
+
children: /* @__PURE__ */ React4.createElement(ActionLabel, {
|
|
217
|
+
action
|
|
218
|
+
})
|
|
219
|
+
};
|
|
220
|
+
return hidden ? null : /* @__PURE__ */ React4.createElement(Root, {
|
|
221
|
+
key: action.id,
|
|
122
222
|
disabled,
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
action: actionGroup
|
|
126
|
-
}),
|
|
223
|
+
onClick: handleClick,
|
|
224
|
+
variant: "ghost",
|
|
127
225
|
...testId && {
|
|
128
226
|
"data-testid": testId
|
|
129
227
|
},
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
})
|
|
228
|
+
...rootProps,
|
|
229
|
+
classNames
|
|
230
|
+
});
|
|
133
231
|
};
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
232
|
+
var DropdownMenuToolbarItem = ({ group, items: propsItems, __menuScope }) => {
|
|
233
|
+
const { iconOnly, disabled, testId } = group.properties;
|
|
234
|
+
const suppressNextTooltip = useRef(false);
|
|
235
|
+
const { iconSize } = useMenu("DropdownMenuToolbarItem", __menuScope);
|
|
236
|
+
const items = useMenuItems(group, propsItems, "DropdownMenuToolbarItem", __menuScope);
|
|
237
|
+
const activeItem = items?.find((item) => !!item.properties.checked);
|
|
238
|
+
const icon = group.properties.applyActive && // TODO(thure): Handle other menu item types.
|
|
239
|
+
activeItem?.properties.icon || group.properties.icon;
|
|
240
|
+
const Root = icon ? NaturalToolbar.IconButton : NaturalToolbar.Button;
|
|
241
|
+
const label = /* @__PURE__ */ React4.createElement(ActionLabel, {
|
|
242
|
+
action: group.properties.applyActive && activeItem ? activeItem : group
|
|
243
|
+
});
|
|
244
|
+
const rootProps = icon ? {
|
|
143
245
|
icon,
|
|
246
|
+
size: iconSize,
|
|
144
247
|
iconOnly,
|
|
248
|
+
label,
|
|
249
|
+
caretDown: true,
|
|
250
|
+
suppressNextTooltip
|
|
251
|
+
} : {
|
|
252
|
+
children: /* @__PURE__ */ React4.createElement(React4.Fragment, null, label, /* @__PURE__ */ React4.createElement(Icon2, {
|
|
253
|
+
size: 3,
|
|
254
|
+
icon: "ph--caret-down--bold",
|
|
255
|
+
classNames: "mis-1"
|
|
256
|
+
}))
|
|
257
|
+
};
|
|
258
|
+
return /* @__PURE__ */ React4.createElement(DropdownMenu.Root, {
|
|
259
|
+
group,
|
|
260
|
+
items,
|
|
261
|
+
suppressNextTooltip
|
|
262
|
+
}, /* @__PURE__ */ React4.createElement(DropdownMenu.Trigger, {
|
|
263
|
+
asChild: true
|
|
264
|
+
}, /* @__PURE__ */ React4.createElement(Root, {
|
|
265
|
+
variant: "ghost",
|
|
145
266
|
disabled,
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
};
|
|
151
|
-
var ToolbarToggleGroup = ({ actionGroup, graph }) => {
|
|
152
|
-
const menuActions = useMemo2(() => graph ? graph.actions(actionGroup) : [], [
|
|
153
|
-
actionGroup,
|
|
154
|
-
graph
|
|
155
|
-
]);
|
|
156
|
-
const { selectCardinality, value } = actionGroup.properties;
|
|
157
|
-
return (
|
|
158
|
-
// TODO(thure): This is extremely difficult to manage, what do?
|
|
159
|
-
// @ts-ignore
|
|
160
|
-
/* @__PURE__ */ React4.createElement(NaturalToolbar2.ToggleGroup, {
|
|
161
|
-
type: selectCardinality,
|
|
162
|
-
value
|
|
163
|
-
}, menuActions.map((action) => /* @__PURE__ */ React4.createElement(ToolbarToggleGroupItem, {
|
|
164
|
-
key: action.id,
|
|
165
|
-
action
|
|
166
|
-
})))
|
|
167
|
-
);
|
|
267
|
+
...rootProps,
|
|
268
|
+
...testId && {
|
|
269
|
+
"data-testid": testId
|
|
270
|
+
}
|
|
271
|
+
})));
|
|
168
272
|
};
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
var ToolbarSeparatorType = "@dxos/react-ui-toolbar/separator";
|
|
173
|
-
var isSeparator = (node) => node.type === ToolbarSeparatorType;
|
|
174
|
-
var isMenu = (node) => node.type === ACTION_GROUP_TYPE;
|
|
175
|
-
|
|
176
|
-
// packages/ui/react-ui-menu/src/components/Toolbar/Toolbar.tsx
|
|
177
|
-
var ToolbarItem = ({ iconSize, action, onAction }) => {
|
|
273
|
+
var ToggleGroupItem = ({ action, __menuScope }) => {
|
|
274
|
+
const { iconSize, onAction } = useMenu("ToggleGroupItem", __menuScope);
|
|
275
|
+
const { icon, iconOnly = true, disabled, testId, hidden, classNames } = action.properties;
|
|
178
276
|
const handleClick = useCallback2(() => {
|
|
179
277
|
onAction?.(action);
|
|
180
278
|
}, [
|
|
181
279
|
action,
|
|
182
280
|
onAction
|
|
183
281
|
]);
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
key: action.id,
|
|
187
|
-
iconOnly,
|
|
188
|
-
variant: "ghost",
|
|
282
|
+
const Root = icon ? NaturalToolbar.ToggleGroupIconItem : NaturalToolbar.ToggleGroupItem;
|
|
283
|
+
const rootProps = icon ? {
|
|
189
284
|
icon,
|
|
190
285
|
size: iconSize,
|
|
191
|
-
|
|
286
|
+
iconOnly,
|
|
287
|
+
label: /* @__PURE__ */ React4.createElement(ActionLabel, {
|
|
192
288
|
action
|
|
193
|
-
})
|
|
289
|
+
})
|
|
290
|
+
} : {
|
|
291
|
+
children: /* @__PURE__ */ React4.createElement(ActionLabel, {
|
|
292
|
+
action
|
|
293
|
+
})
|
|
294
|
+
};
|
|
295
|
+
return hidden ? null : /* @__PURE__ */ React4.createElement(Root, {
|
|
296
|
+
key: action.id,
|
|
297
|
+
value: action.id,
|
|
194
298
|
disabled,
|
|
195
299
|
onClick: handleClick,
|
|
300
|
+
variant: "ghost",
|
|
196
301
|
...testId && {
|
|
197
302
|
"data-testid": testId
|
|
198
|
-
}
|
|
303
|
+
},
|
|
304
|
+
...rootProps,
|
|
305
|
+
classNames
|
|
199
306
|
});
|
|
200
307
|
};
|
|
201
|
-
var
|
|
202
|
-
|
|
308
|
+
var ToggleGroupToolbarItem = ({ group, items: propsItems, __menuScope }) => {
|
|
309
|
+
const items = useMenuItems(group, propsItems, "ToggleGroupToolbarItem", __menuScope);
|
|
310
|
+
const { selectCardinality, value } = group.properties;
|
|
311
|
+
return (
|
|
312
|
+
// TODO(thure): The type here is difficult to manage, what do?
|
|
313
|
+
// @ts-ignore
|
|
314
|
+
/* @__PURE__ */ React4.createElement(
|
|
315
|
+
NaturalToolbar.ToggleGroup,
|
|
316
|
+
{
|
|
317
|
+
type: selectCardinality,
|
|
318
|
+
value
|
|
319
|
+
},
|
|
320
|
+
// TODO(thure): Handle other menu item types.
|
|
321
|
+
items.map((action) => /* @__PURE__ */ React4.createElement(ToggleGroupItem, {
|
|
322
|
+
key: action.id,
|
|
323
|
+
action
|
|
324
|
+
}))
|
|
325
|
+
)
|
|
326
|
+
);
|
|
327
|
+
};
|
|
328
|
+
var ToolbarMenu = ({ __menuScope, classNames, ...props }) => {
|
|
329
|
+
const items = useMenuItems(void 0, void 0, "ToolbarMenu", __menuScope);
|
|
330
|
+
const { attendableId } = useMenu("ToolbarMenu", __menuScope);
|
|
331
|
+
const { hasAttention } = useAttention(attendableId);
|
|
332
|
+
return /* @__PURE__ */ React4.createElement(NaturalToolbar.Root, {
|
|
333
|
+
...props,
|
|
334
|
+
classNames: [
|
|
335
|
+
"p-0 pointer-fine:p-1 attention-surface",
|
|
336
|
+
!hasAttention && "opacity-20",
|
|
337
|
+
classNames
|
|
338
|
+
]
|
|
339
|
+
}, items?.map((item, i) => isSeparator(item) ? /* @__PURE__ */ React4.createElement(NaturalToolbar.Separator, {
|
|
203
340
|
key: i,
|
|
204
341
|
variant: item.properties.variant
|
|
205
|
-
}) :
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
342
|
+
}) : isMenuGroup(item) ? item.properties.variant === "dropdownMenu" ? (
|
|
343
|
+
// TODO(thure): Figure out type narrowing that doesn’t require so much use of `as`.
|
|
344
|
+
/* @__PURE__ */ React4.createElement(DropdownMenuToolbarItem, {
|
|
345
|
+
key: item.id,
|
|
346
|
+
group: item
|
|
347
|
+
})
|
|
348
|
+
) : (
|
|
349
|
+
// TODO(thure): Figure out type narrowing that doesn’t require so much use of `as`.
|
|
350
|
+
/* @__PURE__ */ React4.createElement(ToggleGroupToolbarItem, {
|
|
351
|
+
key: item.id,
|
|
352
|
+
group: item
|
|
353
|
+
})
|
|
354
|
+
) : (
|
|
355
|
+
// TODO(thure): Figure out type narrowing that doesn’t require so much use of `as`.
|
|
356
|
+
/* @__PURE__ */ React4.createElement(ActionToolbarItem, {
|
|
357
|
+
key: item.id,
|
|
358
|
+
action: item
|
|
359
|
+
})
|
|
360
|
+
)));
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
// packages/ui/react-ui-menu/src/hooks.ts
|
|
364
|
+
import { useSignalEffect } from "@preact/signals-react";
|
|
365
|
+
import { useCallback as useCallback3, useState } from "react";
|
|
366
|
+
import { Graph } from "@dxos/app-graph";
|
|
367
|
+
var edgesArrayToRecord = (edges) => {
|
|
368
|
+
return Object.fromEntries(Object.entries(edges.reduce((acc, { source, target }) => {
|
|
369
|
+
if (!acc[source]) {
|
|
370
|
+
acc[source] = {
|
|
371
|
+
inbound: [],
|
|
372
|
+
outbound: []
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
if (!acc[target]) {
|
|
376
|
+
acc[target] = {
|
|
377
|
+
inbound: [],
|
|
378
|
+
outbound: []
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
const sourceEdges = acc[source];
|
|
382
|
+
if (!sourceEdges.outbound.includes(target)) {
|
|
383
|
+
sourceEdges.outbound.push(target);
|
|
384
|
+
}
|
|
385
|
+
const targetEdges = acc[target];
|
|
386
|
+
if (!targetEdges.inbound.includes(source)) {
|
|
387
|
+
targetEdges.inbound.push(source);
|
|
388
|
+
}
|
|
389
|
+
return acc;
|
|
390
|
+
}, {})).map(([id, { outbound }]) => [
|
|
391
|
+
id,
|
|
392
|
+
outbound
|
|
393
|
+
]));
|
|
394
|
+
};
|
|
395
|
+
var useMenuActions = (actionCreator) => {
|
|
396
|
+
const initialMenuGraphProps = actionCreator();
|
|
397
|
+
const [graph] = useState(new Graph({
|
|
398
|
+
nodes: initialMenuGraphProps.nodes,
|
|
399
|
+
edges: edgesArrayToRecord(initialMenuGraphProps.edges)
|
|
400
|
+
}));
|
|
401
|
+
useSignalEffect(() => {
|
|
402
|
+
const menuGraphProps = actionCreator();
|
|
403
|
+
graph._addNodes(menuGraphProps.nodes);
|
|
404
|
+
graph._addEdges(menuGraphProps.edges);
|
|
405
|
+
});
|
|
406
|
+
const resolveGroupItems = useCallback3((sourceNode = graph.root) => {
|
|
407
|
+
if (graph) {
|
|
408
|
+
return graph.nodes(sourceNode, {
|
|
409
|
+
filter: (n) => true
|
|
410
|
+
}) || null;
|
|
411
|
+
} else {
|
|
412
|
+
return null;
|
|
413
|
+
}
|
|
414
|
+
}, [
|
|
216
415
|
graph
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
iconSize
|
|
222
|
-
})));
|
|
416
|
+
]);
|
|
417
|
+
return {
|
|
418
|
+
resolveGroupItems
|
|
419
|
+
};
|
|
223
420
|
};
|
|
224
421
|
export {
|
|
225
422
|
DropdownMenu,
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
423
|
+
MenuProvider,
|
|
424
|
+
MenuSeparatorType,
|
|
425
|
+
ToolbarMenu,
|
|
426
|
+
createGapSeparator,
|
|
427
|
+
createLineSeparator,
|
|
428
|
+
createMenuAction,
|
|
429
|
+
createMenuItemGroup,
|
|
430
|
+
createMenuScope,
|
|
431
|
+
isMenuGroup,
|
|
432
|
+
isSeparator,
|
|
433
|
+
menuContextDefaults,
|
|
434
|
+
useMenu,
|
|
435
|
+
useMenuActions,
|
|
436
|
+
useMenuItems
|
|
230
437
|
};
|
|
231
438
|
//# sourceMappingURL=index.mjs.map
|