@dxos/react-ui-menu 0.8.4-main.c4373fc → 0.8.4-main.c85a9c8dae

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/lib/browser/index.mjs +547 -404
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +547 -404
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/builder.d.ts +7 -1
  8. package/dist/types/src/builder.d.ts.map +1 -1
  9. package/dist/types/src/components/ActionLabel.d.ts +3 -3
  10. package/dist/types/src/components/ActionLabel.d.ts.map +1 -1
  11. package/dist/types/src/components/DropdownMenu.d.ts +1 -1
  12. package/dist/types/src/components/DropdownMenu.d.ts.map +1 -1
  13. package/dist/types/src/components/Menu.d.ts +46 -0
  14. package/dist/types/src/components/Menu.d.ts.map +1 -0
  15. package/dist/types/src/components/Menu.test.d.ts +2 -0
  16. package/dist/types/src/components/Menu.test.d.ts.map +1 -0
  17. package/dist/types/src/components/MenuItems.stories.d.ts +21 -0
  18. package/dist/types/src/components/MenuItems.stories.d.ts.map +1 -0
  19. package/dist/types/src/components/ToolbarMenu.d.ts +4 -3
  20. package/dist/types/src/components/ToolbarMenu.d.ts.map +1 -1
  21. package/dist/types/src/components/ToolbarMenu.stories.d.ts +2 -2
  22. package/dist/types/src/components/ToolbarMenu.stories.d.ts.map +1 -1
  23. package/dist/types/src/components/index.d.ts +1 -3
  24. package/dist/types/src/components/index.d.ts.map +1 -1
  25. package/dist/types/src/hooks/useMenuActions.d.ts +8 -7
  26. package/dist/types/src/hooks/useMenuActions.d.ts.map +1 -1
  27. package/dist/types/src/index.d.ts +0 -1
  28. package/dist/types/src/index.d.ts.map +1 -1
  29. package/dist/types/src/testing/generator.d.ts +14 -12
  30. package/dist/types/src/testing/generator.d.ts.map +1 -1
  31. package/dist/types/src/translations.d.ts +2 -2
  32. package/dist/types/src/translations.d.ts.map +1 -1
  33. package/dist/types/src/types.d.ts +36 -26
  34. package/dist/types/src/types.d.ts.map +1 -1
  35. package/dist/types/src/util.d.ts +14 -5
  36. package/dist/types/src/util.d.ts.map +1 -1
  37. package/dist/types/tsconfig.tsbuildinfo +1 -1
  38. package/package.json +35 -29
  39. package/src/builder.ts +36 -9
  40. package/src/components/ActionLabel.tsx +5 -5
  41. package/src/components/DropdownMenu.tsx +12 -5
  42. package/src/components/Menu.test.tsx +448 -0
  43. package/src/components/Menu.tsx +349 -0
  44. package/src/components/MenuItems.stories.tsx +265 -0
  45. package/src/components/ToolbarMenu.stories.tsx +30 -23
  46. package/src/components/ToolbarMenu.tsx +41 -16
  47. package/src/components/index.ts +1 -3
  48. package/src/hooks/useMenuActions.ts +29 -54
  49. package/src/index.ts +0 -2
  50. package/src/testing/generator.ts +67 -62
  51. package/src/translations.ts +1 -1
  52. package/src/types.ts +38 -27
  53. package/src/util.ts +34 -15
  54. package/dist/types/src/components/MenuContext.d.ts +0 -13
  55. package/dist/types/src/components/MenuContext.d.ts.map +0 -1
  56. package/src/components/MenuContext.tsx +0 -50
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-menu",
3
- "version": "0.8.4-main.c4373fc",
3
+ "version": "0.8.4-main.c85a9c8dae",
4
4
  "description": "Components for facilitating reactive and consistent menus.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/dxos/dxos"
10
+ },
7
11
  "license": "MIT",
8
12
  "author": "DXOS.org",
9
- "sideEffects": true,
13
+ "sideEffects": false,
10
14
  "type": "module",
11
15
  "exports": {
12
16
  ".": {
@@ -25,39 +29,41 @@
25
29
  "src"
26
30
  ],
27
31
  "dependencies": {
28
- "@preact-signals/safe-react": "^0.9.0",
29
- "@preact/signals-react": "^3.3.0",
30
32
  "@radix-ui/react-context": "1.1.1",
31
33
  "@radix-ui/react-use-controllable-state": "1.1.0",
32
- "@dxos/app-graph": "0.8.4-main.c4373fc",
33
- "@dxos/keyboard": "0.8.4-main.c4373fc",
34
- "@dxos/invariant": "0.8.4-main.c4373fc",
35
- "@dxos/react-ui-attention": "0.8.4-main.c4373fc",
36
- "@dxos/util": "0.8.4-main.c4373fc"
34
+ "@dxos/app-graph": "0.8.4-main.c85a9c8dae",
35
+ "@dxos/invariant": "0.8.4-main.c85a9c8dae",
36
+ "@dxos/effect": "0.8.4-main.c85a9c8dae",
37
+ "@dxos/log": "0.8.4-main.c85a9c8dae",
38
+ "@dxos/react-ui-attention": "0.8.4-main.c85a9c8dae",
39
+ "@dxos/ui-types": "0.8.4-main.c85a9c8dae",
40
+ "@dxos/keyboard": "0.8.4-main.c85a9c8dae",
41
+ "@dxos/util": "0.8.4-main.c85a9c8dae"
37
42
  },
38
43
  "devDependencies": {
39
- "@effect-rx/rx-react": "0.42.4",
40
- "@effect/platform": "0.92.1",
41
- "@types/react": "~19.2.2",
42
- "@types/react-dom": "~19.2.1",
43
- "effect": "3.18.3",
44
- "react": "~19.2.0",
45
- "react-dom": "~19.2.0",
46
- "vite": "7.1.9",
47
- "@dxos/live-object": "0.8.4-main.c4373fc",
48
- "@dxos/react-ui": "0.8.4-main.c4373fc",
49
- "@dxos/random": "0.8.4-main.c4373fc",
50
- "@dxos/react-ui-theme": "0.8.4-main.c4373fc",
51
- "@dxos/storybook-utils": "0.8.4-main.c4373fc"
44
+ "@effect-atom/atom-react": "^0.5.0",
45
+ "@effect/platform": "0.94.4",
46
+ "@testing-library/jest-dom": "^6.9.1",
47
+ "@testing-library/react": "^16.3.0",
48
+ "@types/react": "~19.2.7",
49
+ "@types/react-dom": "~19.2.3",
50
+ "effect": "3.19.16",
51
+ "react": "~19.2.3",
52
+ "react-dom": "~19.2.3",
53
+ "vite": "^7.1.11",
54
+ "@dxos/random": "0.8.4-main.c85a9c8dae",
55
+ "@dxos/react-ui": "0.8.4-main.c85a9c8dae",
56
+ "@dxos/ui-theme": "0.8.4-main.c85a9c8dae",
57
+ "@dxos/storybook-utils": "0.8.4-main.c85a9c8dae"
52
58
  },
53
59
  "peerDependencies": {
54
- "@effect-rx/rx-react": "^0.34.1",
55
- "@effect/platform": "^0.80.12",
56
- "effect": "^3.13.3",
57
- "react": "^19.0.0",
58
- "react-dom": "^19.0.0",
59
- "@dxos/react-ui": "0.8.4-main.c4373fc",
60
- "@dxos/react-ui-theme": "0.8.4-main.c4373fc"
60
+ "@effect-atom/atom-react": "^0.5.0",
61
+ "@effect/platform": "0.94.4",
62
+ "effect": "3.19.16",
63
+ "react": "~19.2.3",
64
+ "react-dom": "~19.2.3",
65
+ "@dxos/react-ui": "0.8.4-main.c85a9c8dae",
66
+ "@dxos/ui-theme": "0.8.4-main.c85a9c8dae"
61
67
  },
62
68
  "publishConfig": {
63
69
  "access": "public"
package/src/builder.ts CHANGED
@@ -3,18 +3,25 @@
3
3
  //
4
4
 
5
5
  import { invariant } from '@dxos/invariant';
6
+ import type { MenuActionProperties, MenuItemGroupProperties } from '@dxos/ui-types';
6
7
 
7
8
  import type { ActionGraphProps } from './hooks';
8
- import type { MenuActionProperties, MenuItemGroupProperties } from './types';
9
+ import { MenuSeparatorType } from './types';
9
10
  import { createMenuAction, createMenuItemGroup } from './util';
10
11
 
11
12
  export interface ActionGroupBuilder {
13
+ /** Add an action node as a child of the current group. */
12
14
  action<P extends {} = {}>(id: string, props: P & MenuActionProperties, invoke: () => void): this;
15
+ /** Add a nested action group. */
13
16
  group<P extends {} = {}>(
14
17
  id: string,
15
18
  props: P & MenuItemGroupProperties,
16
19
  cb: (builder: ActionGroupBuilder) => void,
17
20
  ): this;
21
+ /** Merge pre-built nodes and edges into this builder. */
22
+ subgraph(subgraph: ActionGraphProps): this;
23
+ /** Add a separator. */
24
+ separator(id?: string, variant?: 'gap' | 'line'): this;
18
25
  }
19
26
 
20
27
  export interface MenuBuilder extends ActionGroupBuilder {
@@ -22,11 +29,9 @@ export interface MenuBuilder extends ActionGroupBuilder {
22
29
  build(): ActionGraphProps;
23
30
  }
24
31
 
25
- export const MenuBuilder = Object.freeze({
26
- make: (): MenuBuilder => new MenuBuilderImpl({ nodes: [], edges: [] }, 'root'),
27
- });
28
-
29
32
  class MenuBuilderImpl implements MenuBuilder {
33
+ private _separatorCount = 0;
34
+
30
35
  constructor(
31
36
  private readonly _data: ActionGraphProps,
32
37
  private readonly _rootId: string,
@@ -39,9 +44,13 @@ class MenuBuilderImpl implements MenuBuilder {
39
44
  return this;
40
45
  }
41
46
 
47
+ build(): ActionGraphProps {
48
+ return this._data;
49
+ }
50
+
42
51
  action<P extends {} = {}>(id: string, props: P & MenuActionProperties, invoke: () => void): this {
43
52
  this._data.nodes.push(createMenuAction(id, invoke, props));
44
- this._data.edges.push({ source: this._rootId, target: id });
53
+ this._data.edges.push({ source: this._rootId, target: id, relation: 'child' });
45
54
  return this;
46
55
  }
47
56
 
@@ -51,12 +60,30 @@ class MenuBuilderImpl implements MenuBuilder {
51
60
  cb: (builder: ActionGroupBuilder) => void,
52
61
  ): this {
53
62
  this._data.nodes.push(createMenuItemGroup(id, props));
54
- this._data.edges.push({ source: this._rootId, target: id });
63
+ this._data.edges.push({ source: this._rootId, target: id, relation: 'child' });
55
64
  cb(new MenuBuilderImpl(this._data, id));
56
65
  return this;
57
66
  }
58
67
 
59
- build(): ActionGraphProps {
60
- return this._data;
68
+ subgraph(subgraph: ActionGraphProps): this {
69
+ this._data.nodes.push(...subgraph.nodes);
70
+ this._data.edges.push(...subgraph.edges);
71
+ return this;
72
+ }
73
+
74
+ separator(id?: string, variant: 'gap' | 'line' = 'gap'): this {
75
+ id ??= `separator-${++this._separatorCount}`;
76
+ this._data.nodes.push({
77
+ id,
78
+ type: MenuSeparatorType,
79
+ properties: { variant },
80
+ data: undefined as never,
81
+ });
82
+ this._data.edges.push({ source: this._rootId, target: id, relation: 'child' });
83
+ return this;
61
84
  }
62
85
  }
86
+
87
+ export const MenuBuilder = Object.freeze({
88
+ make: (): MenuBuilder => new MenuBuilderImpl({ nodes: [], edges: [] }, 'root'),
89
+ });
@@ -4,16 +4,16 @@
4
4
 
5
5
  import React from 'react';
6
6
 
7
- import { type ActionGroup, type Action as GraphAction } from '@dxos/app-graph';
7
+ import { type Node } from '@dxos/app-graph';
8
8
  import { keySymbols } from '@dxos/keyboard';
9
9
  import { type TFunction, toLocalizedString, useTranslation } from '@dxos/react-ui';
10
- import { descriptionText, mx } from '@dxos/react-ui-theme';
10
+ import { mx } from '@dxos/ui-theme';
11
+ import { type MenuActionProperties } from '@dxos/ui-types';
11
12
 
12
13
  import { translationKey } from '../translations';
13
- import { type MenuActionProperties } from '../types';
14
14
  import { getShortcut } from '../util';
15
15
 
16
- type Action = GraphAction<MenuActionProperties> | ActionGroup<Omit<MenuActionProperties, 'variant'>>;
16
+ type Action = Node.Action<MenuActionProperties> | Node.ActionGroup<Omit<MenuActionProperties, 'variant'>>;
17
17
 
18
18
  export const ActionLabel = ({ action }: { action: Action }) => {
19
19
  const { t } = useTranslation(translationKey);
@@ -21,7 +21,7 @@ export const ActionLabel = ({ action }: { action: Action }) => {
21
21
  return (
22
22
  <>
23
23
  <span className='grow truncate'>{toLocalizedString(action.properties!.label, t)}</span>
24
- {shortcut && <span className={mx('shrink-0', descriptionText)}>{keySymbols(shortcut).join('')}</span>}
24
+ {shortcut && <span className={mx('shrink-0', 'text-description')}>{keySymbols(shortcut).join('')}</span>}
25
25
  </>
26
26
  );
27
27
  };
@@ -8,9 +8,10 @@ import React, { type MouseEvent, useCallback } from 'react';
8
8
  import { type DropdownMenuRootProps, Icon, DropdownMenu as NaturalDropdownMenu } from '@dxos/react-ui';
9
9
 
10
10
  import { type MenuAction, type MenuItem, type MenuItemGroup } from '../types';
11
+ import { executeMenuAction } from '../util';
11
12
 
12
13
  import { ActionLabel } from './ActionLabel';
13
- import { type MenuScopedProps, useMenu, useMenuItems } from './MenuContext';
14
+ import { type MenuScopedProps, useMenuItems, useMenuScoped } from './Menu';
14
15
 
15
16
  export type DropdownMenuProps = DropdownMenuRootProps & {
16
17
  group?: MenuItemGroup;
@@ -29,7 +30,7 @@ const DropdownMenuItem = ({
29
30
  // TODO(thure): handle other items.
30
31
  const action = item as MenuAction;
31
32
  const handleClick = useCallback((event: MouseEvent) => onClick(action, event), [action, onClick]);
32
- const { iconSize } = useMenu('DropdownMenuItem', __menuScope);
33
+ const { iconSize } = useMenuScoped('DropdownMenuItem', __menuScope);
33
34
  return (
34
35
  <NaturalDropdownMenu.Item
35
36
  onClick={handleClick}
@@ -60,17 +61,23 @@ const DropdownMenuRoot = ({
60
61
  onChange: onOpenChange,
61
62
  });
62
63
 
64
+ const { onAction } = useMenuScoped('DropdownMenuRoot', __menuScope);
65
+
63
66
  const handleActionClick = useCallback(
64
67
  (action: MenuAction, event: MouseEvent) => {
65
68
  if (action.properties?.disabled) {
66
69
  return;
67
70
  }
68
71
  event.stopPropagation();
69
- // TODO(thure): Why does Dialog’s modal-ness cause issues if we don’t explicitly close the menu here?
72
+ // TODO(thure): Why does Dialog's modal-ness cause issues if we don't explicitly close the menu here?
70
73
  setOptionsMenuOpen(false);
71
- void action.data?.({ parent: group, caller });
74
+ if (onAction) {
75
+ onAction(action, { parent: group, caller });
76
+ } else {
77
+ void executeMenuAction(action, { parent: group, caller });
78
+ }
72
79
  },
73
- [group, caller],
80
+ [group, caller, onAction],
74
81
  );
75
82
 
76
83
  const items = useMenuItems(group, propsItems);