@dxos/react-ui-menu 0.8.4-main.c4373fc → 0.8.4-main.d05673bc65
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 +547 -404
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +547 -404
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/builder.d.ts +7 -1
- package/dist/types/src/builder.d.ts.map +1 -1
- package/dist/types/src/components/ActionLabel.d.ts +3 -3
- package/dist/types/src/components/ActionLabel.d.ts.map +1 -1
- package/dist/types/src/components/DropdownMenu.d.ts +1 -1
- package/dist/types/src/components/DropdownMenu.d.ts.map +1 -1
- package/dist/types/src/components/Menu.d.ts +46 -0
- package/dist/types/src/components/Menu.d.ts.map +1 -0
- package/dist/types/src/components/Menu.test.d.ts +2 -0
- package/dist/types/src/components/Menu.test.d.ts.map +1 -0
- package/dist/types/src/components/MenuItems.stories.d.ts +21 -0
- package/dist/types/src/components/MenuItems.stories.d.ts.map +1 -0
- package/dist/types/src/components/ToolbarMenu.d.ts +4 -3
- package/dist/types/src/components/ToolbarMenu.d.ts.map +1 -1
- package/dist/types/src/components/ToolbarMenu.stories.d.ts +2 -2
- package/dist/types/src/components/ToolbarMenu.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -3
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useMenuActions.d.ts +8 -7
- package/dist/types/src/hooks/useMenuActions.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/testing/generator.d.ts +15 -13
- package/dist/types/src/testing/generator.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +36 -26
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +14 -5
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +35 -29
- package/src/builder.ts +36 -9
- package/src/components/ActionLabel.tsx +5 -5
- package/src/components/DropdownMenu.tsx +12 -5
- package/src/components/Menu.test.tsx +448 -0
- package/src/components/Menu.tsx +349 -0
- package/src/components/MenuItems.stories.tsx +265 -0
- package/src/components/ToolbarMenu.stories.tsx +30 -23
- package/src/components/ToolbarMenu.tsx +43 -18
- package/src/components/index.ts +1 -3
- package/src/hooks/useMenuActions.ts +29 -54
- package/src/index.ts +0 -2
- package/src/testing/generator.ts +67 -62
- package/src/translations.ts +1 -1
- package/src/types.ts +38 -27
- package/src/util.ts +34 -15
- package/dist/types/src/components/MenuContext.d.ts +0 -13
- package/dist/types/src/components/MenuContext.d.ts.map +0 -1
- 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.
|
|
3
|
+
"version": "0.8.4-main.d05673bc65",
|
|
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":
|
|
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/
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/
|
|
36
|
-
"@dxos/
|
|
34
|
+
"@dxos/effect": "0.8.4-main.d05673bc65",
|
|
35
|
+
"@dxos/invariant": "0.8.4-main.d05673bc65",
|
|
36
|
+
"@dxos/keyboard": "0.8.4-main.d05673bc65",
|
|
37
|
+
"@dxos/log": "0.8.4-main.d05673bc65",
|
|
38
|
+
"@dxos/react-ui-attention": "0.8.4-main.d05673bc65",
|
|
39
|
+
"@dxos/ui-types": "0.8.4-main.d05673bc65",
|
|
40
|
+
"@dxos/util": "0.8.4-main.d05673bc65",
|
|
41
|
+
"@dxos/app-graph": "0.8.4-main.d05673bc65"
|
|
37
42
|
},
|
|
38
43
|
"devDependencies": {
|
|
39
|
-
"@effect-
|
|
40
|
-
"@effect/platform": "0.
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"
|
|
44
|
-
"react": "~19.2.
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"@dxos/random": "0.8.4-main.
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
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.d05673bc65",
|
|
55
|
+
"@dxos/storybook-utils": "0.8.4-main.d05673bc65",
|
|
56
|
+
"@dxos/ui-theme": "0.8.4-main.d05673bc65",
|
|
57
|
+
"@dxos/react-ui": "0.8.4-main.d05673bc65"
|
|
52
58
|
},
|
|
53
59
|
"peerDependencies": {
|
|
54
|
-
"@effect-
|
|
55
|
-
"@effect/platform": "
|
|
56
|
-
"effect": "
|
|
57
|
-
"react": "
|
|
58
|
-
"react-dom": "
|
|
59
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
60
|
-
"@dxos/
|
|
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.d05673bc65",
|
|
66
|
+
"@dxos/ui-theme": "0.8.4-main.d05673bc65"
|
|
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
|
|
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
|
-
|
|
60
|
-
|
|
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
|
|
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 {
|
|
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 =
|
|
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',
|
|
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,
|
|
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 } =
|
|
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
|
|
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
|
-
|
|
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);
|