@dxos/react-ui-menu 0.8.4-staging.60fe92afc8 → 0.9.1-main.c7dcc2e112
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 +107 -42
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/translations.mjs +3 -1
- package/dist/lib/browser/translations.mjs.map +2 -2
- package/dist/lib/node-esm/index.mjs +107 -42
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/translations.mjs +3 -1
- package/dist/lib/node-esm/translations.mjs.map +2 -2
- package/dist/types/src/builder.d.ts +11 -3
- package/dist/types/src/builder.d.ts.map +1 -1
- package/dist/types/src/components/ActionLabel.d.ts +2 -2
- package/dist/types/src/components/ActionLabel.d.ts.map +1 -1
- package/dist/types/src/components/Menu.d.ts +3 -3
- package/dist/types/src/components/Menu.d.ts.map +1 -1
- package/dist/types/src/components/Menu.stories.d.ts +3 -1
- package/dist/types/src/components/Menu.stories.d.ts.map +1 -1
- package/dist/types/src/components/ToolbarMenu.d.ts +14 -12
- package/dist/types/src/components/ToolbarMenu.d.ts.map +1 -1
- package/dist/types/src/components/ToolbarMenu.stories.d.ts +3 -1
- package/dist/types/src/components/ToolbarMenu.stories.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +1 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useGraphMenuActions.d.ts +31 -0
- package/dist/types/src/hooks/useGraphMenuActions.d.ts.map +1 -0
- package/dist/types/src/hooks/useGraphMenuActions.test.d.ts +2 -0
- package/dist/types/src/hooks/useGraphMenuActions.test.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +3 -1
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +7 -11
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +7 -3
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -15
- package/src/builder.test.ts +50 -11
- package/src/builder.ts +29 -5
- package/src/components/ActionLabel.tsx +2 -2
- package/src/components/Menu.tsx +5 -10
- package/src/components/ToolbarMenu.tsx +65 -65
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useGraphMenuActions.test.ts +93 -0
- package/src/hooks/useGraphMenuActions.ts +96 -0
- package/src/translations.ts +3 -1
- package/src/types.ts +9 -6
- package/src/util.ts +1 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/util.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/util.ts":{"bytes":7839,"imports":[{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"@dxos/app-graph","kind":"import-statement","external":true},{"path":"@dxos/effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/components/ActionLabel.tsx":{"bytes":3891,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/keyboard","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true},{"path":"#translations","kind":"import-statement","external":true},{"path":"src/util.ts","kind":"import-statement","original":"../util"}],"format":"esm"},"src/types.ts":{"bytes":4616,"imports":[{"path":"@dxos/app-graph","kind":"import-statement","external":true}],"format":"esm"},"src/components/DropdownMenu.tsx":{"bytes":10853,"imports":[{"path":"@radix-ui/react-use-controllable-state","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"src/util.ts","kind":"import-statement","original":"../util"},{"path":"src/components/ActionLabel.tsx","kind":"import-statement","original":"./ActionLabel"},{"path":"src/components/Menu.tsx","kind":"import-statement","original":"./Menu"}],"format":"esm"},"src/components/ToolbarMenu.tsx":{"bytes":26161,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-attention","kind":"import-statement","external":true},{"path":"#translations","kind":"import-statement","external":true},{"path":"src/types.ts","kind":"import-statement","original":"../types"},{"path":"src/util.ts","kind":"import-statement","original":"../util"},{"path":"src/components/ActionLabel.tsx","kind":"import-statement","original":"./ActionLabel"},{"path":"src/components/DropdownMenu.tsx","kind":"import-statement","original":"./DropdownMenu"},{"path":"src/components/Menu.tsx","kind":"import-statement","original":"./Menu"}],"format":"esm"},"src/components/Menu.tsx":{"bytes":31436,"imports":[{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-use-controllable-state","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"src/util.ts","kind":"import-statement","original":"../util"},{"path":"src/components/ActionLabel.tsx","kind":"import-statement","original":"./ActionLabel"},{"path":"src/components/ToolbarMenu.tsx","kind":"import-statement","original":"./ToolbarMenu"}],"format":"esm"},"src/components/index.ts":{"bytes":368,"imports":[{"path":"src/components/Menu.tsx","kind":"import-statement","original":"./Menu"}],"format":"esm"},"src/hooks/useMenuActions.ts":{"bytes":6912,"imports":[{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/app-graph","kind":"import-statement","external":true}],"format":"esm"},"src/hooks/useGraphMenuActions.ts":{"bytes":9917,"imports":[{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/app-graph","kind":"import-statement","external":true},{"path":"src/hooks/useMenuActions.ts","kind":"import-statement","original":"./useMenuActions"}],"format":"esm"},"src/hooks/index.ts":{"bytes":509,"imports":[{"path":"src/hooks/useGraphMenuActions.ts","kind":"import-statement","original":"./useGraphMenuActions"},{"path":"src/hooks/useMenuActions.ts","kind":"import-statement","original":"./useMenuActions"}],"format":"esm"},"src/builder.ts":{"bytes":12976,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"#translations","kind":"import-statement","external":true},{"path":"src/types.ts","kind":"import-statement","original":"./types"},{"path":"src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"},"src/index.ts":{"bytes":1214,"imports":[{"path":"src/components/index.ts","kind":"import-statement","original":"./components"},{"path":"src/hooks/index.ts","kind":"import-statement","original":"./hooks"},{"path":"src/types.ts","kind":"import-statement","original":"./types"},{"path":"src/util.ts","kind":"import-statement","original":"./util"},{"path":"src/builder.ts","kind":"import-statement","original":"./builder"}],"format":"esm"},"src/translations.ts":{"bytes":1117,"imports":[],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":59919},"dist/lib/browser/index.mjs":{"imports":[{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-use-controllable-state","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"@dxos/app-graph","kind":"import-statement","external":true},{"path":"@dxos/effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/keyboard","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true},{"path":"#translations","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-attention","kind":"import-statement","external":true},{"path":"#translations","kind":"import-statement","external":true},{"path":"@dxos/app-graph","kind":"import-statement","external":true},{"path":"@radix-ui/react-use-controllable-state","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/app-graph","kind":"import-statement","external":true},{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/app-graph","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"#translations","kind":"import-statement","external":true}],"exports":["Menu","MenuBuilder","MenuSeparatorType","buildGraphMenu","createGapSeparator","createLineSeparator","createMenuAction","createMenuItemGroup","graphActions","isMenuGroup","isSeparator","menuContextDefaults","useGraphMenuActions","useMenu","useMenuActions","useMenuBuilder","useMenuItems","useMenuScoped"],"entryPoint":"src/index.ts","inputs":{"src/components/Menu.tsx":{"bytesInOutput":6895},"src/util.ts":{"bytesInOutput":1473},"src/components/ActionLabel.tsx":{"bytesInOutput":890},"src/components/ToolbarMenu.tsx":{"bytesInOutput":6212},"src/types.ts":{"bytesInOutput":235},"src/components/DropdownMenu.tsx":{"bytesInOutput":2516},"src/index.ts":{"bytesInOutput":0},"src/hooks/useGraphMenuActions.ts":{"bytesInOutput":1454},"src/hooks/useMenuActions.ts":{"bytesInOutput":955},"src/builder.ts":{"bytesInOutput":2609}},"bytes":23961},"dist/lib/browser/translations.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":586},"dist/lib/browser/translations.mjs":{"imports":[],"exports":["translationKey","translations"],"entryPoint":"src/translations.ts","inputs":{"src/translations.ts":{"bytesInOutput":171}},"bytes":281}}}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/translations.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Resource } from '@dxos/react-ui';\n\nexport const translationKey = '@dxos/react-ui-menu';\n\nexport const translations = [\n {\n 'en-US': {\n [translationKey]: {},\n },\n },\n] as const satisfies Resource[];\n"],
|
|
5
|
-
"mappings": ";AAMO,IAAMA,iBAAiB;AAEvB,IAAMC,eAAe;EAC1B;IACE,SAAS;MACP,CAACD,cAAAA,GAAiB,
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Resource } from '@dxos/react-ui';\n\nexport const translationKey = '@dxos/react-ui-menu';\n\nexport const translations = [\n {\n 'en-US': {\n [translationKey]: {\n 'toolbar-overflow.menu': 'More',\n },\n },\n },\n] as const satisfies Resource[];\n"],
|
|
5
|
+
"mappings": ";AAMO,IAAMA,iBAAiB;AAEvB,IAAMC,eAAe;EAC1B;IACE,SAAS;MACP,CAACD,cAAAA,GAAiB;QAChB,yBAAyB;MAC3B;IACF;EACF;;",
|
|
6
6
|
"names": ["translationKey", "translations"]
|
|
7
7
|
}
|
|
@@ -6,7 +6,7 @@ import { createContextScope } from "@radix-ui/react-context";
|
|
|
6
6
|
import { useControllableState as useControllableState2 } from "@radix-ui/react-use-controllable-state";
|
|
7
7
|
import React4, { createContext, useCallback as useCallback3, useContext, useMemo } from "react";
|
|
8
8
|
import { log } from "@dxos/log";
|
|
9
|
-
import { Icon as
|
|
9
|
+
import { Icon as Icon2, DropdownMenu as NaturalDropdownMenu2 } from "@dxos/react-ui";
|
|
10
10
|
|
|
11
11
|
// src/util.ts
|
|
12
12
|
import * as Effect from "effect/Effect";
|
|
@@ -96,7 +96,7 @@ var actionLabel = (action, t) => {
|
|
|
96
96
|
|
|
97
97
|
// src/components/ToolbarMenu.tsx
|
|
98
98
|
import React3, { useCallback as useCallback2 } from "react";
|
|
99
|
-
import {
|
|
99
|
+
import { Toolbar as NaturalToolbar, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
100
100
|
import { composable, composableProps } from "@dxos/react-ui";
|
|
101
101
|
import { useAttention } from "@dxos/react-ui-attention";
|
|
102
102
|
import { translationKey as translationKey2 } from "#translations";
|
|
@@ -222,45 +222,42 @@ var ActionToolbarItem = ({ __menuScope, action }) => {
|
|
|
222
222
|
}));
|
|
223
223
|
};
|
|
224
224
|
var DropdownMenuToolbarItem = ({ __menuScope, group, items: propsItems }) => {
|
|
225
|
-
const { iconOnly, disabled, testId } = group.properties;
|
|
226
225
|
const { t } = useTranslation2(translationKey2);
|
|
227
226
|
const { iconSize } = useMenuScoped("DropdownMenuToolbarItem", __menuScope);
|
|
228
227
|
const items = useMenuItems(group, propsItems, "DropdownMenuToolbarItem", __menuScope);
|
|
228
|
+
const { iconOnly, disabled, testId, applyActive, caretDown = true, icon: groupIcon, iconClassNames: groupIconClassNames } = group.properties;
|
|
229
229
|
const activeItem = items?.find((item) => !!item.properties.checked);
|
|
230
|
-
const icon =
|
|
231
|
-
activeItem?.properties.icon ||
|
|
232
|
-
const iconClassNames =
|
|
233
|
-
const
|
|
234
|
-
const labelAction = group.properties.applyActive && activeItem ? activeItem : group;
|
|
235
|
-
const rootProps = icon ? {
|
|
236
|
-
icon,
|
|
237
|
-
size: iconSize,
|
|
238
|
-
iconOnly,
|
|
239
|
-
iconClassNames,
|
|
240
|
-
label: actionLabel(labelAction, t),
|
|
241
|
-
caretDown: true
|
|
242
|
-
} : {
|
|
243
|
-
children: /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(ActionLabel, {
|
|
244
|
-
action: labelAction
|
|
245
|
-
}), /* @__PURE__ */ React3.createElement(Icon2, {
|
|
246
|
-
size: 3,
|
|
247
|
-
icon: "ph--caret-down--bold",
|
|
248
|
-
classNames: "ms-1"
|
|
249
|
-
}))
|
|
250
|
-
};
|
|
230
|
+
const icon = applyActive && // TODO(thure): Handle other menu item types.
|
|
231
|
+
activeItem?.properties.icon || groupIcon;
|
|
232
|
+
const iconClassNames = applyActive && activeItem?.properties.iconClassNames || groupIconClassNames;
|
|
233
|
+
const labelAction = applyActive && activeItem ? activeItem : group;
|
|
251
234
|
return /* @__PURE__ */ React3.createElement(DropdownMenu.Root, {
|
|
252
235
|
group,
|
|
253
236
|
items
|
|
254
237
|
}, /* @__PURE__ */ React3.createElement(DropdownMenu.Trigger, {
|
|
255
238
|
asChild: true
|
|
256
|
-
}, /* @__PURE__ */ React3.createElement(
|
|
239
|
+
}, icon ? /* @__PURE__ */ React3.createElement(NaturalToolbar.IconButton, {
|
|
257
240
|
variant: "ghost",
|
|
258
241
|
disabled,
|
|
259
|
-
|
|
242
|
+
icon,
|
|
243
|
+
size: iconSize,
|
|
244
|
+
iconOnly,
|
|
245
|
+
iconClassNames,
|
|
246
|
+
label: actionLabel(labelAction, t),
|
|
247
|
+
caretDown,
|
|
260
248
|
...testId && {
|
|
261
249
|
"data-testid": testId
|
|
262
250
|
}
|
|
263
|
-
})
|
|
251
|
+
}) : /* @__PURE__ */ React3.createElement(NaturalToolbar.Button, {
|
|
252
|
+
variant: "ghost",
|
|
253
|
+
disabled,
|
|
254
|
+
caretDown,
|
|
255
|
+
...testId && {
|
|
256
|
+
"data-testid": testId
|
|
257
|
+
}
|
|
258
|
+
}, /* @__PURE__ */ React3.createElement(ActionLabel, {
|
|
259
|
+
action: labelAction
|
|
260
|
+
}))));
|
|
264
261
|
};
|
|
265
262
|
var ToggleGroupItem = ({ __menuScope, group, action }) => {
|
|
266
263
|
const { iconSize, onAction } = useMenuScoped("ToggleGroupItem", __menuScope);
|
|
@@ -350,12 +347,11 @@ var ToolbarMenuItem = ({ __menuScope, item }) => {
|
|
|
350
347
|
__menuScope,
|
|
351
348
|
group: item
|
|
352
349
|
});
|
|
353
|
-
} else {
|
|
354
|
-
return /* @__PURE__ */ React3.createElement(ToggleGroupToolbarItem, {
|
|
355
|
-
__menuScope,
|
|
356
|
-
group: item
|
|
357
|
-
});
|
|
358
350
|
}
|
|
351
|
+
return /* @__PURE__ */ React3.createElement(ToggleGroupToolbarItem, {
|
|
352
|
+
__menuScope,
|
|
353
|
+
group: item
|
|
354
|
+
});
|
|
359
355
|
}
|
|
360
356
|
return /* @__PURE__ */ React3.createElement(ActionToolbarItem, {
|
|
361
357
|
__menuScope,
|
|
@@ -388,12 +384,7 @@ var MenuDropdownContext = /* @__PURE__ */ createContext({
|
|
|
388
384
|
var DEFAULT_PRIORITY = 100;
|
|
389
385
|
var sortMenuItems = (items) => [
|
|
390
386
|
...items
|
|
391
|
-
].sort((a, b) =>
|
|
392
|
-
if (a.priority !== b.priority) {
|
|
393
|
-
return a.priority - b.priority;
|
|
394
|
-
}
|
|
395
|
-
return a.id.localeCompare(b.id);
|
|
396
|
-
});
|
|
387
|
+
].sort((a, b) => a.priority !== b.priority ? a.priority - b.priority : a.id.localeCompare(b.id));
|
|
397
388
|
var MenuProvider = ({ children, items = menuContextDefaults.items, iconSize = menuContextDefaults.iconSize, attendableId, alwaysActive, onAction }) => {
|
|
398
389
|
const { scope } = useMenuScope(void 0);
|
|
399
390
|
const registry = useContext(RegistryContext);
|
|
@@ -446,7 +437,7 @@ var resolveItems = (baseItems, group, entries) => {
|
|
|
446
437
|
log.warn("multiple replacement entries found", {
|
|
447
438
|
ids: replacements.map((r) => r.id).join(", "),
|
|
448
439
|
using: replacements[0].id
|
|
449
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L:
|
|
440
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 89, S: void 0 });
|
|
450
441
|
}
|
|
451
442
|
return replacements[0].items;
|
|
452
443
|
}
|
|
@@ -511,7 +502,7 @@ var MenuContentItem = ({ item, onClick, __menuScope }) => {
|
|
|
511
502
|
...action.properties?.testId && {
|
|
512
503
|
"data-testid": action.properties.testId
|
|
513
504
|
}
|
|
514
|
-
}, action.properties?.icon && /* @__PURE__ */ React4.createElement(
|
|
505
|
+
}, action.properties?.icon && /* @__PURE__ */ React4.createElement(Icon2, {
|
|
515
506
|
icon: action.properties.icon,
|
|
516
507
|
size: iconSize
|
|
517
508
|
}), /* @__PURE__ */ React4.createElement(ActionLabel, {
|
|
@@ -560,6 +551,11 @@ var Menu = {
|
|
|
560
551
|
Toolbar: ToolbarMenu
|
|
561
552
|
};
|
|
562
553
|
|
|
554
|
+
// src/hooks/useGraphMenuActions.ts
|
|
555
|
+
import { Atom as Atom3 } from "@effect-atom/atom-react";
|
|
556
|
+
import { useMemo as useMemo3 } from "react";
|
|
557
|
+
import { Node as Node4 } from "@dxos/app-graph";
|
|
558
|
+
|
|
563
559
|
// src/hooks/useMenuActions.ts
|
|
564
560
|
import { Atom as Atom2, RegistryContext as RegistryContext2, useAtomValue as useAtomValue2 } from "@effect-atom/atom-react";
|
|
565
561
|
import { useCallback as useCallback4, useContext as useContext2, useMemo as useMemo2 } from "react";
|
|
@@ -591,9 +587,72 @@ var useMenuBuilder = (build, deps) => {
|
|
|
591
587
|
return useMenuActions(atom);
|
|
592
588
|
};
|
|
593
589
|
|
|
590
|
+
// src/hooks/useGraphMenuActions.ts
|
|
591
|
+
var buildGraphMenu = (resolve, nodeId, options = {}) => {
|
|
592
|
+
const { rootId = Node4.RootId, filter } = options;
|
|
593
|
+
const nodes = [];
|
|
594
|
+
const edges = [];
|
|
595
|
+
const seen = /* @__PURE__ */ new Set();
|
|
596
|
+
const visit = (parentId, sourceId) => {
|
|
597
|
+
for (const action of resolve(sourceId)) {
|
|
598
|
+
if (filter && !filter(action)) {
|
|
599
|
+
continue;
|
|
600
|
+
}
|
|
601
|
+
edges.push({
|
|
602
|
+
source: parentId,
|
|
603
|
+
target: action.id,
|
|
604
|
+
relation: "child"
|
|
605
|
+
});
|
|
606
|
+
if (seen.has(action.id)) {
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
seen.add(action.id);
|
|
610
|
+
nodes.push(action);
|
|
611
|
+
if (Node4.isActionGroup(action)) {
|
|
612
|
+
visit(action.id, action.id);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
visit(rootId, nodeId);
|
|
617
|
+
return {
|
|
618
|
+
nodes,
|
|
619
|
+
edges
|
|
620
|
+
};
|
|
621
|
+
};
|
|
622
|
+
var graphActions = (graph, get, nodeId, options) => graph && nodeId ? buildGraphMenu((id) => get(graph.actions(id)), nodeId, options) : {
|
|
623
|
+
nodes: [],
|
|
624
|
+
edges: []
|
|
625
|
+
};
|
|
626
|
+
var useGraphMenuActions = (graph, nodeId, options) => {
|
|
627
|
+
const atom = useMemo3(
|
|
628
|
+
() => Atom3.make((get) => graphActions(graph, get, nodeId, options)),
|
|
629
|
+
// `options` is expected to be stable; `rootId` participates since it reshapes the graph.
|
|
630
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
631
|
+
[
|
|
632
|
+
graph,
|
|
633
|
+
nodeId,
|
|
634
|
+
options?.rootId
|
|
635
|
+
]
|
|
636
|
+
);
|
|
637
|
+
return useMenuActions(atom);
|
|
638
|
+
};
|
|
639
|
+
|
|
594
640
|
// src/builder.ts
|
|
595
641
|
import { invariant } from "@dxos/invariant";
|
|
642
|
+
import { translationKey as translationKey3 } from "#translations";
|
|
596
643
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-menu/src/builder.ts";
|
|
644
|
+
var overflowMenuProperties = {
|
|
645
|
+
label: [
|
|
646
|
+
"toolbar-overflow.menu",
|
|
647
|
+
{
|
|
648
|
+
ns: translationKey3
|
|
649
|
+
}
|
|
650
|
+
],
|
|
651
|
+
icon: "ph--dots-three-vertical--regular",
|
|
652
|
+
iconOnly: true,
|
|
653
|
+
caretDown: false,
|
|
654
|
+
variant: "dropdownMenu"
|
|
655
|
+
};
|
|
597
656
|
var MenuBuilderImpl = class _MenuBuilderImpl {
|
|
598
657
|
_data;
|
|
599
658
|
_rootId;
|
|
@@ -603,8 +662,8 @@ var MenuBuilderImpl = class _MenuBuilderImpl {
|
|
|
603
662
|
this._rootId = _rootId;
|
|
604
663
|
}
|
|
605
664
|
root(props) {
|
|
606
|
-
invariant(this._rootId === "root", "Root group can only be at the top level", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L:
|
|
607
|
-
invariant(this._data.nodes.find((node) => node.id === "root") === void 0, "Root group can only be created once", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L:
|
|
665
|
+
invariant(this._rootId === "root", "Root group can only be at the top level", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 29, S: this, A: ["this._rootId === 'root'", "'Root group can only be at the top level'"] });
|
|
666
|
+
invariant(this._data.nodes.find((node) => node.id === "root") === void 0, "Root group can only be created once", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 30, S: this, A: ["this._data.nodes.find((node)=>node.id === 'root') === undefined", "'Root group can only be created once'"] });
|
|
608
667
|
this._data.nodes.push(createMenuItemGroup("root", props));
|
|
609
668
|
return this;
|
|
610
669
|
}
|
|
@@ -630,6 +689,9 @@ var MenuBuilderImpl = class _MenuBuilderImpl {
|
|
|
630
689
|
cb(new _MenuBuilderImpl(this._data, id));
|
|
631
690
|
return this;
|
|
632
691
|
}
|
|
692
|
+
menu(id, cb) {
|
|
693
|
+
return this.group(id, overflowMenuProperties, cb);
|
|
694
|
+
}
|
|
633
695
|
subgraph(subgraphOrCb) {
|
|
634
696
|
if (!subgraphOrCb) {
|
|
635
697
|
return this;
|
|
@@ -670,13 +732,16 @@ export {
|
|
|
670
732
|
Menu,
|
|
671
733
|
MenuBuilder,
|
|
672
734
|
MenuSeparatorType,
|
|
735
|
+
buildGraphMenu,
|
|
673
736
|
createGapSeparator,
|
|
674
737
|
createLineSeparator,
|
|
675
738
|
createMenuAction,
|
|
676
739
|
createMenuItemGroup,
|
|
740
|
+
graphActions,
|
|
677
741
|
isMenuGroup,
|
|
678
742
|
isSeparator,
|
|
679
743
|
menuContextDefaults,
|
|
744
|
+
useGraphMenuActions,
|
|
680
745
|
useMenu,
|
|
681
746
|
useMenuActions,
|
|
682
747
|
useMenuBuilder,
|