@dxos/react-ui-menu 0.8.3 → 0.8.4-main.f9ba587
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 +75 -16
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +75 -16
- 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 +14 -0
- package/dist/types/src/builder.d.ts.map +1 -0
- package/dist/types/src/components/ActionLabel.d.ts.map +1 -1
- package/dist/types/src/components/Menus.stories.d.ts +2 -2
- package/dist/types/src/components/Menus.stories.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +3 -4
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -16
- package/src/builder.ts +62 -0
- package/src/components/ActionLabel.tsx +1 -2
- package/src/components/Menus.stories.tsx +6 -4
- package/src/components/ToolbarMenu.tsx +1 -1
- package/src/index.ts +1 -0
- package/src/translations.ts +5 -3
- package/dist/lib/node/index.cjs +0 -506
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-menu",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4-main.f9ba587",
|
|
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",
|
|
@@ -28,34 +28,35 @@
|
|
|
28
28
|
"@preact/signals-react": "^3.2.0",
|
|
29
29
|
"@radix-ui/react-context": "1.1.1",
|
|
30
30
|
"@radix-ui/react-use-controllable-state": "1.1.0",
|
|
31
|
-
"@dxos/app-graph": "0.8.
|
|
32
|
-
"@dxos/
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
31
|
+
"@dxos/app-graph": "0.8.4-main.f9ba587",
|
|
32
|
+
"@dxos/invariant": "0.8.4-main.f9ba587",
|
|
33
|
+
"@dxos/keyboard": "0.8.4-main.f9ba587",
|
|
34
|
+
"@dxos/react-ui-attention": "0.8.4-main.f9ba587",
|
|
35
|
+
"@dxos/util": "0.8.4-main.f9ba587"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"@effect-rx/rx-react": "
|
|
38
|
-
"@effect/platform": "0.
|
|
38
|
+
"@effect-rx/rx-react": "0.38.0",
|
|
39
|
+
"@effect/platform": "0.88.0",
|
|
39
40
|
"@types/react": "~18.2.0",
|
|
40
41
|
"@types/react-dom": "~18.2.0",
|
|
41
|
-
"effect": "3.
|
|
42
|
+
"effect": "3.16.13",
|
|
42
43
|
"react": "~18.2.0",
|
|
43
44
|
"react-dom": "~18.2.0",
|
|
44
45
|
"vite": "5.4.7",
|
|
45
|
-
"@dxos/live-object": "0.8.
|
|
46
|
-
"@dxos/random": "0.8.
|
|
47
|
-
"@dxos/react-ui": "0.8.
|
|
48
|
-
"@dxos/react-ui
|
|
49
|
-
"@dxos/storybook-utils": "0.8.
|
|
46
|
+
"@dxos/live-object": "0.8.4-main.f9ba587",
|
|
47
|
+
"@dxos/random": "0.8.4-main.f9ba587",
|
|
48
|
+
"@dxos/react-ui-theme": "0.8.4-main.f9ba587",
|
|
49
|
+
"@dxos/react-ui": "0.8.4-main.f9ba587",
|
|
50
|
+
"@dxos/storybook-utils": "0.8.4-main.f9ba587"
|
|
50
51
|
},
|
|
51
52
|
"peerDependencies": {
|
|
52
53
|
"@effect-rx/rx-react": "^0.34.1",
|
|
53
|
-
"@effect/platform": "0.80.12",
|
|
54
|
+
"@effect/platform": "^0.80.12",
|
|
54
55
|
"effect": "^3.13.3",
|
|
55
56
|
"react": "~18.2.0",
|
|
56
57
|
"react-dom": "~18.2.0",
|
|
57
|
-
"@dxos/react-ui": "0.8.
|
|
58
|
-
"@dxos/react-ui-theme": "0.8.
|
|
58
|
+
"@dxos/react-ui": "0.8.4-main.f9ba587",
|
|
59
|
+
"@dxos/react-ui-theme": "0.8.4-main.f9ba587"
|
|
59
60
|
},
|
|
60
61
|
"publishConfig": {
|
|
61
62
|
"access": "public"
|
package/src/builder.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { invariant } from '@dxos/invariant';
|
|
6
|
+
|
|
7
|
+
import type { ActionGraphProps } from './hooks';
|
|
8
|
+
import type { MenuActionProperties, MenuItemGroupProperties } from './types';
|
|
9
|
+
import { createMenuAction, createMenuItemGroup } from './util';
|
|
10
|
+
|
|
11
|
+
export interface ActionGroupBuilder {
|
|
12
|
+
action<P extends {} = {}>(id: string, invoke: () => void, properties: P & MenuActionProperties): this;
|
|
13
|
+
group<P extends {} = {}>(
|
|
14
|
+
id: string,
|
|
15
|
+
properties: P & MenuItemGroupProperties,
|
|
16
|
+
cb: (builder: ActionGroupBuilder) => void,
|
|
17
|
+
): this;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface MenuBuilder extends ActionGroupBuilder {
|
|
21
|
+
root(props: MenuItemGroupProperties): this;
|
|
22
|
+
build(): ActionGraphProps;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const MenuBuilder = Object.freeze({
|
|
26
|
+
make: (): MenuBuilder => new MenuBuilderImpl({ nodes: [], edges: [] }, 'root'),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
class MenuBuilderImpl implements MenuBuilder {
|
|
30
|
+
constructor(
|
|
31
|
+
private readonly _data: ActionGraphProps,
|
|
32
|
+
private readonly _rootId: string,
|
|
33
|
+
) {}
|
|
34
|
+
|
|
35
|
+
action<P extends {} = {}>(id: string, invoke: () => void, properties: P & MenuActionProperties): this {
|
|
36
|
+
this._data.nodes.push(createMenuAction(id, invoke, properties));
|
|
37
|
+
this._data.edges.push({ source: this._rootId, target: id });
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
root(props: MenuItemGroupProperties): this {
|
|
42
|
+
invariant(this._rootId === 'root', 'Root group can only be at the top level');
|
|
43
|
+
invariant(this._data.nodes.find((node) => node.id === 'root') === undefined, 'Root group can only be created once');
|
|
44
|
+
this._data.nodes.push(createMenuItemGroup('root', props));
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
group<P extends {} = {}>(
|
|
49
|
+
id: string,
|
|
50
|
+
properties: P & MenuItemGroupProperties,
|
|
51
|
+
cb: (builder: ActionGroupBuilder) => void,
|
|
52
|
+
): this {
|
|
53
|
+
this._data.nodes.push(createMenuItemGroup(id, properties));
|
|
54
|
+
this._data.edges.push({ source: this._rootId, target: id });
|
|
55
|
+
cb(new MenuBuilderImpl(this._data, id));
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
build(): ActionGraphProps {
|
|
60
|
+
return this._data;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -16,9 +16,8 @@ import { getShortcut } from '../util';
|
|
|
16
16
|
type Action = GraphAction<MenuActionProperties> | ActionGroup<Omit<MenuActionProperties, 'variant'>>;
|
|
17
17
|
|
|
18
18
|
export const ActionLabel = ({ action }: { action: Action }) => {
|
|
19
|
-
const shortcut = getShortcut(action);
|
|
20
19
|
const { t } = useTranslation(translationKey);
|
|
21
|
-
|
|
20
|
+
const shortcut = getShortcut(action);
|
|
22
21
|
return (
|
|
23
22
|
<>
|
|
24
23
|
<span className='grow truncate'>{toLocalizedString(action.properties!.label, t)}</span>
|
|
@@ -7,12 +7,12 @@ import React, { useCallback, useMemo } from 'react';
|
|
|
7
7
|
|
|
8
8
|
import { faker } from '@dxos/random';
|
|
9
9
|
import { IconButton } from '@dxos/react-ui';
|
|
10
|
-
import {
|
|
10
|
+
import { withTheme } from '@dxos/storybook-utils';
|
|
11
11
|
|
|
12
12
|
import { DropdownMenu as NaturalDropdownMenu, ToolbarMenu, MenuProvider } from '../components';
|
|
13
13
|
import { useMenuActions } from '../hooks';
|
|
14
14
|
import { createActions, createNestedActions, createNestedActionsResolver, useMutateActions } from '../testing';
|
|
15
|
-
import translations from '../translations';
|
|
15
|
+
import { translations } from '../translations';
|
|
16
16
|
import { type MenuAction } from '../types';
|
|
17
17
|
|
|
18
18
|
faker.seed(1234);
|
|
@@ -20,8 +20,10 @@ faker.seed(1234);
|
|
|
20
20
|
export default {
|
|
21
21
|
title: 'ui/react-ui-menu/Menus',
|
|
22
22
|
component: ToolbarMenu,
|
|
23
|
-
decorators: [withTheme
|
|
24
|
-
parameters: {
|
|
23
|
+
decorators: [withTheme],
|
|
24
|
+
parameters: {
|
|
25
|
+
translations,
|
|
26
|
+
},
|
|
25
27
|
};
|
|
26
28
|
|
|
27
29
|
export const DropdownMenu = {
|
|
@@ -163,7 +163,7 @@ export const ToolbarMenu = ({
|
|
|
163
163
|
const { attendableId } = useMenu('ToolbarMenu', __menuScope);
|
|
164
164
|
const { hasAttention } = useAttention(attendableId);
|
|
165
165
|
const InnerRoot = wrapContents ? 'div' : Fragment;
|
|
166
|
-
const innerRootProps = wrapContents ? { role: 'none', className: mx(textBlockWidth, toolbarLayout) } : {};
|
|
166
|
+
const innerRootProps = wrapContents ? { role: 'none', className: mx(textBlockWidth, toolbarLayout, 'bs-full') } : {};
|
|
167
167
|
return (
|
|
168
168
|
<NaturalToolbar.Root
|
|
169
169
|
{...props}
|
package/src/index.ts
CHANGED
package/src/translations.ts
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import { type Resource } from '@dxos/react-ui';
|
|
6
6
|
|
|
7
|
-
export
|
|
7
|
+
export const translationKey = 'react-ui-menu';
|
|
8
|
+
|
|
9
|
+
export const translations = [
|
|
8
10
|
{
|
|
9
11
|
'en-US': {
|
|
10
12
|
[translationKey]: {},
|
|
11
13
|
},
|
|
12
14
|
},
|
|
13
|
-
] as const;
|
|
15
|
+
] as const satisfies Resource[];
|