@dxos/plugin-simple-layout 0.8.4-main.69d29f4 → 0.8.4-main.6fa680abb7
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/chunk-MDPEKLKR.mjs +1163 -0
- package/dist/lib/browser/chunk-MDPEKLKR.mjs.map +7 -0
- package/dist/lib/browser/{chunk-CLPGTNWJ.mjs → chunk-MRR7PXSM.mjs} +5 -5
- package/dist/lib/browser/chunk-MRR7PXSM.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +27 -20
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{operation-resolver-LTB63NKP.mjs → operation-resolver-VTZ6HZ4B.mjs} +45 -19
- package/dist/lib/browser/operation-resolver-VTZ6HZ4B.mjs.map +7 -0
- package/dist/lib/browser/{react-root-6ARAPH3O.mjs → react-root-WVQYY2JA.mjs} +5 -5
- package/dist/lib/browser/react-root-WVQYY2JA.mjs.map +7 -0
- package/dist/lib/browser/{react-surface-SO7B23GS.mjs → react-surface-VLBR37ED.mjs} +18 -13
- package/dist/lib/browser/react-surface-VLBR37ED.mjs.map +7 -0
- package/dist/lib/browser/{spotlight-dismiss-VSNOPETH.mjs → spotlight-dismiss-67PHYS5B.mjs} +3 -3
- package/dist/lib/browser/spotlight-dismiss-67PHYS5B.mjs.map +7 -0
- package/dist/lib/browser/{state-H4IGICBB.mjs → state-TXSMUWYI.mjs} +8 -5
- package/dist/lib/browser/state-TXSMUWYI.mjs.map +7 -0
- package/dist/lib/browser/url-handler-RBRONH7S.mjs +151 -0
- package/dist/lib/browser/url-handler-RBRONH7S.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-DCKASLMP.mjs +1164 -0
- package/dist/lib/node-esm/chunk-DCKASLMP.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-MUVVYBUE.mjs → chunk-WMNTJ2MK.mjs} +5 -5
- package/dist/lib/node-esm/chunk-WMNTJ2MK.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +27 -20
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{operation-resolver-7O6O7T4Q.mjs → operation-resolver-R7CQ6ERU.mjs} +45 -19
- package/dist/lib/node-esm/operation-resolver-R7CQ6ERU.mjs.map +7 -0
- package/dist/lib/node-esm/{react-root-2CPA2ZUS.mjs → react-root-XBNDM7BE.mjs} +5 -5
- package/dist/lib/node-esm/react-root-XBNDM7BE.mjs.map +7 -0
- package/dist/lib/node-esm/{react-surface-FKAV56MO.mjs → react-surface-U5NHA367.mjs} +18 -13
- package/dist/lib/node-esm/react-surface-U5NHA367.mjs.map +7 -0
- package/dist/lib/node-esm/{spotlight-dismiss-L5PCWIJG.mjs → spotlight-dismiss-RMLRZUVY.mjs} +3 -3
- package/dist/lib/node-esm/spotlight-dismiss-RMLRZUVY.mjs.map +7 -0
- package/dist/lib/node-esm/{state-QIU2LMLT.mjs → state-JMX6FAG4.mjs} +8 -5
- package/dist/lib/node-esm/state-JMX6FAG4.mjs.map +7 -0
- package/dist/lib/node-esm/url-handler-QSMCH3JB.mjs +152 -0
- package/dist/lib/node-esm/url-handler-QSMCH3JB.mjs.map +7 -0
- package/dist/types/src/SimpleLayoutPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +2 -2
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-root/react-root.d.ts +1 -1
- package/dist/types/src/capabilities/react-root/react-root.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface/index.d.ts +1 -1
- package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts +2 -2
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -1
- package/dist/types/src/capabilities/spotlight-dismiss/index.d.ts +1 -1
- package/dist/types/src/capabilities/spotlight-dismiss/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/spotlight-dismiss/spotlight-dismiss.d.ts +1 -1
- package/dist/types/src/capabilities/spotlight-dismiss/spotlight-dismiss.d.ts.map +1 -1
- package/dist/types/src/capabilities/state/index.d.ts +1 -1
- package/dist/types/src/capabilities/state/state.d.ts +1 -1
- package/dist/types/src/capabilities/state/state.d.ts.map +1 -1
- package/dist/types/src/capabilities/url-handler/url-handler.d.ts +5 -3
- package/dist/types/src/capabilities/url-handler/url-handler.d.ts.map +1 -1
- package/dist/types/src/components/ContentError.stories.d.ts +7 -3
- package/dist/types/src/components/ContentError.stories.d.ts.map +1 -1
- package/dist/types/src/components/ContentLoading/ContentLoading.d.ts.map +1 -0
- package/dist/types/src/components/ContentLoading/ContentLoading.stories.d.ts.map +1 -0
- package/dist/types/src/components/ContentLoading/index.d.ts +2 -0
- package/dist/types/src/components/ContentLoading/index.d.ts.map +1 -0
- package/dist/types/src/components/Home/Home.d.ts.map +1 -1
- package/dist/types/src/components/MobileLayout/MobileLayout.d.ts +35 -0
- package/dist/types/src/components/MobileLayout/MobileLayout.d.ts.map +1 -0
- package/dist/types/src/components/MobileLayout/MobileLayout.stories.d.ts +7 -0
- package/dist/types/src/components/MobileLayout/MobileLayout.stories.d.ts.map +1 -0
- package/dist/types/src/components/MobileLayout/index.d.ts +2 -0
- package/dist/types/src/components/MobileLayout/index.d.ts.map +1 -0
- package/dist/types/src/components/NavBranch/NavBranch.d.ts +11 -0
- package/dist/types/src/components/NavBranch/NavBranch.d.ts.map +1 -0
- package/dist/types/src/components/NavBranch/index.d.ts +2 -0
- package/dist/types/src/components/NavBranch/index.d.ts.map +1 -0
- package/dist/types/src/components/Popover/Popover.d.ts.map +1 -1
- package/dist/types/src/components/SimpleLayout/AppBar.d.ts +26 -0
- package/dist/types/src/components/SimpleLayout/AppBar.d.ts.map +1 -0
- package/dist/types/src/components/SimpleLayout/AppBar.stories.d.ts +47 -0
- package/dist/types/src/components/SimpleLayout/AppBar.stories.d.ts.map +1 -0
- package/dist/types/src/components/SimpleLayout/Drawer.d.ts +9 -0
- package/dist/types/src/components/SimpleLayout/Drawer.d.ts.map +1 -0
- package/dist/types/src/components/SimpleLayout/Main.d.ts +1 -1
- package/dist/types/src/components/SimpleLayout/Main.d.ts.map +1 -1
- package/dist/types/src/components/SimpleLayout/NavBar.d.ts +13 -3
- package/dist/types/src/components/SimpleLayout/NavBar.d.ts.map +1 -1
- package/dist/types/src/components/SimpleLayout/NavBar.stories.d.ts +13 -9
- package/dist/types/src/components/SimpleLayout/NavBar.stories.d.ts.map +1 -1
- package/dist/types/src/components/SimpleLayout/SimpleLayout.d.ts.map +1 -1
- package/dist/types/src/components/SimpleLayout/SimpleLayout.stories.d.ts +10 -0
- package/dist/types/src/components/SimpleLayout/SimpleLayout.stories.d.ts.map +1 -1
- package/dist/types/src/components/SimpleLayout/index.d.ts +3 -0
- package/dist/types/src/components/SimpleLayout/index.d.ts.map +1 -1
- package/dist/types/src/components/hooks.d.ts +4 -2
- package/dist/types/src/components/hooks.d.ts.map +1 -1
- 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/hooks/actions.d.ts +19 -0
- package/dist/types/src/hooks/actions.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +5 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useAppBarProps.d.ts +7 -0
- package/dist/types/src/hooks/useAppBarProps.d.ts.map +1 -0
- package/dist/types/src/hooks/useCompanions.d.ts +12 -0
- package/dist/types/src/hooks/useCompanions.d.ts.map +1 -0
- package/dist/types/src/hooks/useDrawerActions.d.ts +13 -0
- package/dist/types/src/hooks/useDrawerActions.d.ts.map +1 -0
- package/dist/types/src/hooks/useNavbarActions.d.ts +14 -0
- package/dist/types/src/hooks/useNavbarActions.d.ts.map +1 -0
- package/dist/types/src/hooks/useSimpleLayoutState.d.ts +3 -3
- package/dist/types/src/hooks/useSimpleLayoutState.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +6 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/capabilities.d.ts +8 -3
- package/dist/types/src/types/capabilities.d.ts.map +1 -1
- package/dist/types/src/types/events.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +36 -30
- package/src/SimpleLayoutPlugin.ts +10 -9
- package/src/capabilities/operation-resolver/operation-resolver.ts +43 -19
- package/src/capabilities/react-root/react-root.tsx +2 -2
- package/src/capabilities/react-surface/react-surface.tsx +14 -11
- package/src/capabilities/spotlight-dismiss/spotlight-dismiss.ts +2 -2
- package/src/capabilities/state/state.tsx +6 -3
- package/src/capabilities/url-handler/url-handler.ts +98 -45
- package/src/components/ContentError.stories.tsx +8 -7
- package/src/components/{ContentLoading.stories.tsx → ContentLoading/ContentLoading.stories.tsx} +2 -2
- package/src/components/{ContentLoading.tsx → ContentLoading/ContentLoading.tsx} +1 -1
- package/src/components/ContentLoading/index.ts +5 -0
- package/src/components/Dialog/Dialog.tsx +5 -5
- package/src/components/Home/Home.tsx +43 -35
- package/src/components/MobileLayout/MobileLayout.stories.tsx +129 -0
- package/src/components/MobileLayout/MobileLayout.tsx +305 -0
- package/src/components/MobileLayout/index.ts +5 -0
- package/src/components/NavBranch/NavBranch.tsx +130 -0
- package/src/components/{Workspace → NavBranch}/index.ts +1 -1
- package/src/components/Popover/Popover.tsx +17 -7
- package/src/components/SimpleLayout/AppBar.stories.tsx +144 -0
- package/src/components/SimpleLayout/AppBar.tsx +94 -0
- package/src/components/SimpleLayout/Drawer.tsx +96 -0
- package/src/components/SimpleLayout/Main.tsx +46 -45
- package/src/components/SimpleLayout/NavBar.stories.tsx +131 -26
- package/src/components/SimpleLayout/NavBar.tsx +18 -58
- package/src/components/SimpleLayout/SimpleLayout.stories.tsx +24 -11
- package/src/components/SimpleLayout/SimpleLayout.tsx +45 -6
- package/src/components/SimpleLayout/index.ts +3 -0
- package/src/components/hooks.ts +10 -14
- package/src/components/index.ts +2 -1
- package/src/hooks/actions.ts +83 -0
- package/src/hooks/index.ts +5 -0
- package/src/hooks/useAppBarProps.ts +115 -0
- package/src/hooks/useCompanions.ts +22 -0
- package/src/hooks/useDrawerActions.ts +100 -0
- package/src/hooks/useNavbarActions.ts +87 -0
- package/src/hooks/useSimpleLayoutState.ts +5 -5
- package/src/meta.ts +1 -1
- package/src/translations.ts +6 -0
- package/src/types/capabilities.ts +13 -4
- package/src/types/events.ts +3 -2
- package/dist/lib/browser/chunk-CLPGTNWJ.mjs.map +0 -7
- package/dist/lib/browser/chunk-FK4M7GJV.mjs +0 -613
- package/dist/lib/browser/chunk-FK4M7GJV.mjs.map +0 -7
- package/dist/lib/browser/operation-resolver-LTB63NKP.mjs.map +0 -7
- package/dist/lib/browser/react-root-6ARAPH3O.mjs.map +0 -7
- package/dist/lib/browser/react-surface-SO7B23GS.mjs.map +0 -7
- package/dist/lib/browser/spotlight-dismiss-VSNOPETH.mjs.map +0 -7
- package/dist/lib/browser/state-H4IGICBB.mjs.map +0 -7
- package/dist/lib/browser/url-handler-7CFGTLNG.mjs +0 -54
- package/dist/lib/browser/url-handler-7CFGTLNG.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-EGFZAVBD.mjs +0 -614
- package/dist/lib/node-esm/chunk-EGFZAVBD.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-MUVVYBUE.mjs.map +0 -7
- package/dist/lib/node-esm/operation-resolver-7O6O7T4Q.mjs.map +0 -7
- package/dist/lib/node-esm/react-root-2CPA2ZUS.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-FKAV56MO.mjs.map +0 -7
- package/dist/lib/node-esm/spotlight-dismiss-L5PCWIJG.mjs.map +0 -7
- package/dist/lib/node-esm/state-QIU2LMLT.mjs.map +0 -7
- package/dist/lib/node-esm/url-handler-4LYP3JM7.mjs +0 -55
- package/dist/lib/node-esm/url-handler-4LYP3JM7.mjs.map +0 -7
- package/dist/types/src/components/ContentError.d.ts +0 -5
- package/dist/types/src/components/ContentError.d.ts.map +0 -1
- package/dist/types/src/components/ContentLoading.d.ts.map +0 -1
- package/dist/types/src/components/ContentLoading.stories.d.ts.map +0 -1
- package/dist/types/src/components/SimpleLayout/Banner.d.ts +0 -8
- package/dist/types/src/components/SimpleLayout/Banner.d.ts.map +0 -1
- package/dist/types/src/components/Workspace/Workspace.d.ts +0 -9
- package/dist/types/src/components/Workspace/Workspace.d.ts.map +0 -1
- package/dist/types/src/components/Workspace/index.d.ts +0 -2
- package/dist/types/src/components/Workspace/index.d.ts.map +0 -1
- package/src/components/ContentError.tsx +0 -23
- package/src/components/SimpleLayout/Banner.tsx +0 -82
- package/src/components/Workspace/Workspace.tsx +0 -115
- /package/dist/types/src/components/{ContentLoading.d.ts → ContentLoading/ContentLoading.d.ts} +0 -0
- /package/dist/types/src/components/{ContentLoading.stories.d.ts → ContentLoading/ContentLoading.stories.d.ts} +0 -0
|
@@ -2,58 +2,163 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { Atom } from '@effect-atom/atom-react';
|
|
5
6
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
7
|
+
import React, { useMemo } from 'react';
|
|
8
|
+
import { type Mock, expect, fn, screen, userEvent, within } from 'storybook/test';
|
|
6
9
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
11
|
+
import { type ActionGraphProps, createGapSeparator, createMenuAction, createMenuItemGroup } from '@dxos/react-ui-menu';
|
|
12
|
+
import { withRegistry } from '@dxos/storybook-utils';
|
|
10
13
|
|
|
11
14
|
import { translations } from '../../translations';
|
|
12
15
|
|
|
13
16
|
import { NavBar } from './NavBar';
|
|
14
17
|
|
|
18
|
+
const MAIN_MENU_GROUP_ID = 'navbar-main-menu';
|
|
19
|
+
|
|
20
|
+
const buildEmptyActions = (): ActionGraphProps => ({ nodes: [], edges: [] });
|
|
21
|
+
|
|
22
|
+
const buildCompanionOnlyActions = (): ActionGraphProps => {
|
|
23
|
+
const result: ActionGraphProps = { nodes: [], edges: [] };
|
|
24
|
+
const companions = [
|
|
25
|
+
createMenuAction('companion-browse', () => console.log('Browse'), {
|
|
26
|
+
icon: 'ph--house--regular',
|
|
27
|
+
label: 'Browse',
|
|
28
|
+
iconOnly: true,
|
|
29
|
+
}),
|
|
30
|
+
createMenuAction('companion-notifications', () => console.log('Notifications'), {
|
|
31
|
+
icon: 'ph--bell--regular',
|
|
32
|
+
label: 'Notifications',
|
|
33
|
+
iconOnly: true,
|
|
34
|
+
}),
|
|
35
|
+
createMenuAction('companion-profile', () => console.log('Profile'), {
|
|
36
|
+
icon: 'ph--user--regular',
|
|
37
|
+
label: 'Profile',
|
|
38
|
+
iconOnly: true,
|
|
39
|
+
}),
|
|
40
|
+
];
|
|
41
|
+
result.nodes.push(...companions);
|
|
42
|
+
result.edges.push(...companions.map((c) => ({ source: 'root', target: c.id, relation: 'child' })));
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const buildDefaultActions = (): ActionGraphProps => {
|
|
47
|
+
const result: ActionGraphProps = { nodes: [], edges: [] };
|
|
48
|
+
const gapSeparator = createGapSeparator('navbar-gap');
|
|
49
|
+
const mainMenuGroup = createMenuItemGroup(MAIN_MENU_GROUP_ID, {
|
|
50
|
+
variant: 'dropdownMenu',
|
|
51
|
+
icon: 'ph--plus--regular',
|
|
52
|
+
iconOnly: true,
|
|
53
|
+
label: 'Main menu',
|
|
54
|
+
testId: 'simpleLayoutPlugin.addSpace',
|
|
55
|
+
});
|
|
56
|
+
const companions = [
|
|
57
|
+
createMenuAction('companion-browse', () => console.log('Browse'), {
|
|
58
|
+
icon: 'ph--house--regular',
|
|
59
|
+
label: 'Browse',
|
|
60
|
+
iconOnly: true,
|
|
61
|
+
}),
|
|
62
|
+
createMenuAction('companion-notifications', () => console.log('Notifications'), {
|
|
63
|
+
icon: 'ph--bell--regular',
|
|
64
|
+
label: 'Notifications',
|
|
65
|
+
iconOnly: true,
|
|
66
|
+
}),
|
|
67
|
+
];
|
|
68
|
+
const menuActions = [
|
|
69
|
+
createMenuAction('action-create-space', () => console.log('Create space'), {
|
|
70
|
+
icon: 'ph--planet--regular',
|
|
71
|
+
label: 'Create space',
|
|
72
|
+
}),
|
|
73
|
+
createMenuAction('action-join-space', () => console.log('Join space'), {
|
|
74
|
+
icon: 'ph--sign-in--regular',
|
|
75
|
+
label: 'Join space',
|
|
76
|
+
}),
|
|
77
|
+
createMenuAction('action-settings', () => console.log('Settings'), {
|
|
78
|
+
icon: 'ph--gear--regular',
|
|
79
|
+
label: 'Settings',
|
|
80
|
+
}),
|
|
81
|
+
];
|
|
82
|
+
result.nodes.push(...companions, ...gapSeparator.nodes, mainMenuGroup, ...menuActions);
|
|
83
|
+
result.edges.push(
|
|
84
|
+
...companions.map((c) => ({ source: 'root', target: c.id, relation: 'child' })),
|
|
85
|
+
...gapSeparator.edges,
|
|
86
|
+
{ source: 'root', target: mainMenuGroup.id, relation: 'child' },
|
|
87
|
+
...menuActions.map((action) => ({ source: MAIN_MENU_GROUP_ID, target: action.id, relation: 'child' })),
|
|
88
|
+
);
|
|
89
|
+
return result;
|
|
90
|
+
};
|
|
91
|
+
|
|
15
92
|
const meta = {
|
|
16
|
-
title: 'plugins/plugin-simple-layout/NavBar',
|
|
93
|
+
title: 'plugins/plugin-simple-layout/components/NavBar',
|
|
17
94
|
component: NavBar,
|
|
18
|
-
decorators: [
|
|
19
|
-
withTheme,
|
|
20
|
-
withPluginManager({
|
|
21
|
-
plugins: [...corePlugins()],
|
|
22
|
-
}),
|
|
23
|
-
],
|
|
95
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' }), withRegistry],
|
|
24
96
|
parameters: {
|
|
25
97
|
layout: 'fullscreen',
|
|
26
98
|
translations,
|
|
27
99
|
},
|
|
28
|
-
argTypes: {
|
|
29
|
-
onActiveIdChange: { action: 'activeIdChanged' },
|
|
30
|
-
},
|
|
31
100
|
} satisfies Meta<typeof NavBar>;
|
|
32
101
|
|
|
33
102
|
export default meta;
|
|
34
103
|
|
|
35
104
|
type Story = StoryObj<typeof meta>;
|
|
36
105
|
|
|
106
|
+
const DefaultStory = ({ onAction }: { onAction: (action: { id: string }) => void }) => {
|
|
107
|
+
const actions = useMemo(() => Atom.make(buildDefaultActions()).pipe(Atom.keepAlive), []);
|
|
108
|
+
|
|
109
|
+
return <NavBar classNames='border-y border-separator' actions={actions} onAction={onAction} />;
|
|
110
|
+
};
|
|
111
|
+
|
|
37
112
|
export const Default: Story = {
|
|
113
|
+
tags: ['test'],
|
|
38
114
|
args: {
|
|
39
|
-
|
|
115
|
+
onAction: fn(),
|
|
116
|
+
} as any,
|
|
117
|
+
render: (args: any) => <DefaultStory onAction={args.onAction} />,
|
|
118
|
+
play: async ({ args, canvasElement }) => {
|
|
119
|
+
const canvas = within(canvasElement);
|
|
120
|
+
|
|
121
|
+
// Verify the navbar renders with the toolbar.
|
|
122
|
+
await expect(canvas.getByRole('toolbar')).toBeInTheDocument();
|
|
123
|
+
|
|
124
|
+
// Test companion action click (Browse button).
|
|
125
|
+
const browseButton = canvas.getByRole('button', { name: /browse/i });
|
|
126
|
+
await expect(browseButton).toBeInTheDocument();
|
|
127
|
+
await userEvent.click(browseButton);
|
|
128
|
+
await expect(args.onAction).toHaveBeenCalledTimes(1);
|
|
129
|
+
await expect((args.onAction as Mock).mock.calls[0][0]).toHaveProperty('id', 'companion-browse');
|
|
130
|
+
|
|
131
|
+
// Test dropdown menu opens and action fires.
|
|
132
|
+
const menuTrigger = canvas.getByRole('button', { name: /main menu/i });
|
|
133
|
+
await expect(menuTrigger).toBeInTheDocument();
|
|
134
|
+
await userEvent.click(menuTrigger);
|
|
135
|
+
|
|
136
|
+
// Wait for menu to open and click an action (menu items render in a portal).
|
|
137
|
+
const createSpaceAction = await screen.findByRole('menuitem', { name: /create space/i });
|
|
138
|
+
await userEvent.click(createSpaceAction);
|
|
139
|
+
await expect(args.onAction).toHaveBeenCalledTimes(2);
|
|
140
|
+
await expect((args.onAction as Mock).mock.calls[1][0]).toHaveProperty('id', 'action-create-space');
|
|
40
141
|
},
|
|
41
142
|
};
|
|
42
143
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
},
|
|
144
|
+
const CompanionsOnlyStory = () => {
|
|
145
|
+
const actions = useMemo(() => Atom.make(buildCompanionOnlyActions()).pipe(Atom.keepAlive), []);
|
|
146
|
+
|
|
147
|
+
return <NavBar actions={actions} onAction={(action) => console.log('Action:', action.id)} />;
|
|
47
148
|
};
|
|
48
149
|
|
|
49
|
-
export const
|
|
50
|
-
args: {
|
|
51
|
-
|
|
52
|
-
},
|
|
150
|
+
export const CompanionsOnly: Story = {
|
|
151
|
+
args: {} as any,
|
|
152
|
+
render: () => <CompanionsOnlyStory />,
|
|
53
153
|
};
|
|
54
154
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
},
|
|
155
|
+
const EmptyStory = () => {
|
|
156
|
+
const actions = useMemo(() => Atom.make(buildEmptyActions()).pipe(Atom.keepAlive), []);
|
|
157
|
+
|
|
158
|
+
return <NavBar actions={actions} onAction={(action) => console.log('Action:', action.id)} />;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export const Empty: Story = {
|
|
162
|
+
args: {} as any,
|
|
163
|
+
render: () => <EmptyStory />,
|
|
59
164
|
};
|
|
@@ -2,73 +2,33 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { type Atom } from '@effect-atom/atom-react';
|
|
5
6
|
import React from 'react';
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { IconButton, type ThemedClassName, Toolbar, Tooltip, useTranslation } from '@dxos/react-ui';
|
|
10
|
-
import { DropdownMenu, MenuProvider } from '@dxos/react-ui-menu';
|
|
8
|
+
import { type ThemedClassName } from '@dxos/react-ui';
|
|
9
|
+
import { type ActionExecutor, type ActionGraphProps, Menu, useMenuActions } from '@dxos/react-ui-menu';
|
|
11
10
|
import { mx } from '@dxos/ui-theme';
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
const NAVBAR_NAME = 'SimpleLayout.NavBar';
|
|
14
13
|
|
|
15
14
|
export type NavBarProps = ThemedClassName<{
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
/** Action graph atom for the toolbar. */
|
|
16
|
+
actions: Atom.Atom<ActionGraphProps>;
|
|
17
|
+
/** Action executor callback. */
|
|
18
|
+
onAction?: ActionExecutor;
|
|
18
19
|
}>;
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const connections = useConnections(graph, Node.RootId);
|
|
26
|
-
const menuActions = connections.filter((node) => node.properties.disposition === 'menu');
|
|
27
|
-
|
|
28
|
-
const isBrowseActive = activeId !== 'notifications' && activeId !== 'profile';
|
|
21
|
+
/**
|
|
22
|
+
* Presentational navbar component that renders a toolbar from an action graph.
|
|
23
|
+
*/
|
|
24
|
+
export const NavBar = ({ classNames, actions, onAction }: NavBarProps) => {
|
|
25
|
+
const menu = useMenuActions(actions);
|
|
29
26
|
|
|
30
27
|
return (
|
|
31
|
-
<
|
|
32
|
-
<
|
|
33
|
-
|
|
34
|
-
<Tooltip.Trigger asChild content={t('app menu label')}>
|
|
35
|
-
<DropdownMenu.Trigger asChild data-testid='spacePlugin.addSpace'>
|
|
36
|
-
<IconButton icon='ph--plus--regular' iconOnly label={t('main menu label')} />
|
|
37
|
-
</DropdownMenu.Trigger>
|
|
38
|
-
</Tooltip.Trigger>
|
|
39
|
-
</DropdownMenu.Root>
|
|
40
|
-
</MenuProvider>
|
|
41
|
-
{/*
|
|
42
|
-
<ButtonGroup>
|
|
43
|
-
<IconButton
|
|
44
|
-
{...buttonProps}
|
|
45
|
-
label={t('browse label')}
|
|
46
|
-
icon='ph--squares-four--regular'
|
|
47
|
-
onClick={() => onActiveIdChange?.(null)}
|
|
48
|
-
variant={isBrowseActive ? 'primary' : 'default'}
|
|
49
|
-
{...(isBrowseActive && { 'aria-current': 'location' })}
|
|
50
|
-
/>
|
|
51
|
-
<IconButton
|
|
52
|
-
{...buttonProps}
|
|
53
|
-
label={t('notifications label')}
|
|
54
|
-
icon='ph--bell-simple--regular'
|
|
55
|
-
onClick={() => onActiveIdChange?.('notifications')}
|
|
56
|
-
variant={activeId === 'notifications' ? 'primary' : 'default'}
|
|
57
|
-
{...(activeId === 'notifications' && { 'aria-current': 'location' })}
|
|
58
|
-
/>
|
|
59
|
-
<Button
|
|
60
|
-
variant={activeId === 'profile' ? 'primary' : 'default'}
|
|
61
|
-
onClick={() => onActiveIdChange?.('profile')}
|
|
62
|
-
classNames={buttonProps.classNames}
|
|
63
|
-
>
|
|
64
|
-
<span className='sr-only'>{t('profile label')}</span>
|
|
65
|
-
<Avatar.Root>
|
|
66
|
-
<Avatar.Label classNames='sr-only'>Profile display name</Avatar.Label>
|
|
67
|
-
<Avatar.Content size={8} status='active' hue='cyan' fallback='🗿' />
|
|
68
|
-
</Avatar.Root>
|
|
69
|
-
</Button>
|
|
70
|
-
</ButtonGroup>
|
|
71
|
-
*/}
|
|
72
|
-
</Toolbar.Root>
|
|
28
|
+
<Menu.Root {...menu} alwaysActive onAction={onAction}>
|
|
29
|
+
<Menu.Toolbar density='coarse' classNames={mx(classNames)} />
|
|
30
|
+
</Menu.Root>
|
|
73
31
|
);
|
|
74
32
|
};
|
|
33
|
+
|
|
34
|
+
NavBar.displayName = NAVBAR_NAME;
|
|
@@ -5,16 +5,17 @@
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
6
|
import * as Effect from 'effect/Effect';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { ActivationEvents, Capabilities, Capability, Plugin } from '@dxos/app-framework';
|
|
9
9
|
import { withPluginManager } from '@dxos/app-framework/testing';
|
|
10
|
+
import { AppActivationEvents, AppPlugin } from '@dxos/app-toolkit';
|
|
11
|
+
import { Collection } from '@dxos/echo';
|
|
10
12
|
import { ClientOperation, ClientPlugin } from '@dxos/plugin-client';
|
|
11
13
|
import { SearchPlugin } from '@dxos/plugin-search';
|
|
12
14
|
import { SpacePlugin } from '@dxos/plugin-space';
|
|
13
15
|
import { SpaceOperation } from '@dxos/plugin-space/types';
|
|
14
16
|
import { corePlugins } from '@dxos/plugin-testing';
|
|
15
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
17
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
16
18
|
import { translations as searchTranslation } from '@dxos/react-ui-searchlist';
|
|
17
|
-
import { Collection } from '@dxos/schema';
|
|
18
19
|
|
|
19
20
|
import { OperationResolver, type SimpleLayoutStateOptions, State } from '../../capabilities';
|
|
20
21
|
import { meta as pluginMeta } from '../../meta';
|
|
@@ -24,18 +25,18 @@ import { translations } from '../../translations';
|
|
|
24
25
|
import { SimpleLayout } from './SimpleLayout';
|
|
25
26
|
|
|
26
27
|
const TestPlugin = Plugin.define<SimpleLayoutPluginOptions>(pluginMeta).pipe(
|
|
28
|
+
AppPlugin.addOperationResolverModule({ activate: OperationResolver }),
|
|
27
29
|
Plugin.addModule(({ isPopover = false }) => ({
|
|
28
30
|
id: Capability.getModuleTag(State),
|
|
29
|
-
activatesOn:
|
|
30
|
-
activatesAfter: [
|
|
31
|
+
activatesOn: ActivationEvents.Startup,
|
|
32
|
+
activatesAfter: [AppActivationEvents.LayoutReady],
|
|
31
33
|
activate: () => State({ initialState: { isPopover } } satisfies SimpleLayoutStateOptions),
|
|
32
34
|
})),
|
|
33
|
-
Common.Plugin.addOperationResolverModule({ activate: OperationResolver }),
|
|
34
35
|
Plugin.addModule({
|
|
35
36
|
id: 'setup',
|
|
36
|
-
activatesOn:
|
|
37
|
+
activatesOn: ActivationEvents.OperationInvokerReady,
|
|
37
38
|
activate: Effect.fnUntraced(function* () {
|
|
38
|
-
const { invoke } = yield* Capability.get(
|
|
39
|
+
const { invoke } = yield* Capability.get(Capabilities.OperationInvoker);
|
|
39
40
|
yield* invoke(ClientOperation.CreateIdentity, {});
|
|
40
41
|
const { space: work } = yield* invoke(SpaceOperation.Create, { name: 'Work Space' });
|
|
41
42
|
const { space: sharedProject } = yield* invoke(SpaceOperation.Create, { name: 'Shared Project' });
|
|
@@ -79,7 +80,7 @@ const createPluginManager = ({ isPopover }: { isPopover: boolean }) => {
|
|
|
79
80
|
};
|
|
80
81
|
|
|
81
82
|
const meta = {
|
|
82
|
-
title: 'plugins/plugin-simple-layout/SimpleLayout',
|
|
83
|
+
title: 'plugins/plugin-simple-layout/components/SimpleLayout',
|
|
83
84
|
component: SimpleLayout,
|
|
84
85
|
parameters: {
|
|
85
86
|
layout: 'fullscreen',
|
|
@@ -91,10 +92,22 @@ export default meta;
|
|
|
91
92
|
|
|
92
93
|
type Story = StoryObj<typeof meta>;
|
|
93
94
|
|
|
95
|
+
/**
|
|
96
|
+
* NOTE: To expose to iphone on network:
|
|
97
|
+
* `moon run storybook-react:serve dev -H 0.0.0.0`
|
|
98
|
+
*/
|
|
94
99
|
export const Default: Story = {
|
|
95
|
-
decorators: [
|
|
100
|
+
decorators: [
|
|
101
|
+
withTheme(),
|
|
102
|
+
withLayout({ layout: 'column', classNames: 'relative' }),
|
|
103
|
+
createPluginManager({ isPopover: false }),
|
|
104
|
+
],
|
|
96
105
|
};
|
|
97
106
|
|
|
98
107
|
export const Popover: Story = {
|
|
99
|
-
decorators: [
|
|
108
|
+
decorators: [
|
|
109
|
+
withTheme(),
|
|
110
|
+
withLayout({ layout: 'column', classNames: 'relative' }),
|
|
111
|
+
createPluginManager({ isPopover: true }),
|
|
112
|
+
],
|
|
100
113
|
};
|
|
@@ -2,19 +2,58 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React from 'react';
|
|
5
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
6
6
|
|
|
7
|
+
import { Splitter, type SplitterMode } from '@dxos/react-ui';
|
|
8
|
+
import { Mosaic } from '@dxos/react-ui-mosaic';
|
|
9
|
+
|
|
10
|
+
import { useSimpleLayoutState } from '../../hooks';
|
|
7
11
|
import { Dialog } from '../Dialog';
|
|
12
|
+
import { MobileLayout } from '../MobileLayout';
|
|
8
13
|
import { PopoverContent, PopoverRoot } from '../Popover';
|
|
9
14
|
|
|
15
|
+
import { Drawer } from './Drawer';
|
|
10
16
|
import { Main } from './Main';
|
|
11
17
|
|
|
18
|
+
// TODO(burdon): Mobile/Desktop variance?
|
|
12
19
|
export const SimpleLayout = () => {
|
|
20
|
+
const { state } = useSimpleLayoutState();
|
|
21
|
+
const [keyboardOpen, setKeyboardOpen] = useState(false);
|
|
22
|
+
const [splitterMode, setSplitterMode] = useState<SplitterMode>('upper');
|
|
23
|
+
|
|
24
|
+
const drawerRef = useRef<HTMLDivElement>(null);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (keyboardOpen) {
|
|
27
|
+
// Determine which panel has focus and expand that one.
|
|
28
|
+
const activeElement = document.activeElement;
|
|
29
|
+
const drawerHasFocus = drawerRef.current?.contains(activeElement);
|
|
30
|
+
setSplitterMode(drawerHasFocus ? 'lower' : 'upper');
|
|
31
|
+
} else {
|
|
32
|
+
setSplitterMode(state.drawerState === 'closed' ? 'upper' : state.drawerState === 'open' ? 'both' : 'lower');
|
|
33
|
+
}
|
|
34
|
+
}, [state.drawerState, keyboardOpen]);
|
|
35
|
+
|
|
13
36
|
return (
|
|
14
|
-
<
|
|
15
|
-
<
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
37
|
+
<Mosaic.Root classNames='contents'>
|
|
38
|
+
<MobileLayout.Root
|
|
39
|
+
classNames='bg-toolbar-surface'
|
|
40
|
+
onKeyboardOpenChange={(keyboardOpen: boolean) => setKeyboardOpen(keyboardOpen)}
|
|
41
|
+
>
|
|
42
|
+
<MobileLayout.Panel safe={{ top: true, bottom: splitterMode === 'upper' }}>
|
|
43
|
+
<PopoverRoot>
|
|
44
|
+
<Splitter.Root mode={splitterMode} ratio={0.55}>
|
|
45
|
+
<Splitter.Panel position='upper'>
|
|
46
|
+
<Main />
|
|
47
|
+
</Splitter.Panel>
|
|
48
|
+
<Splitter.Panel position='lower' ref={drawerRef}>
|
|
49
|
+
<Drawer />
|
|
50
|
+
</Splitter.Panel>
|
|
51
|
+
</Splitter.Root>
|
|
52
|
+
<Dialog />
|
|
53
|
+
<PopoverContent />
|
|
54
|
+
</PopoverRoot>
|
|
55
|
+
</MobileLayout.Panel>
|
|
56
|
+
</MobileLayout.Root>
|
|
57
|
+
</Mosaic.Root>
|
|
19
58
|
);
|
|
20
59
|
};
|
package/src/components/hooks.ts
CHANGED
|
@@ -4,27 +4,23 @@
|
|
|
4
4
|
|
|
5
5
|
import { useEffect } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { expandAttendableId } from '@dxos/react-ui-attention';
|
|
8
|
+
import { useAppGraph } from '@dxos/app-toolkit/ui';
|
|
8
9
|
import { Graph } from '@dxos/plugin-graph';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
|
-
*
|
|
12
|
+
* Expand graph nodes along the full path from root to the given node ID.
|
|
13
|
+
* Walks each progressive prefix, ensuring ancestor nodes are materialized
|
|
14
|
+
* before attempting to access their children.
|
|
12
15
|
*/
|
|
13
|
-
export const
|
|
16
|
+
export const useExpandPath = (nodeId?: string) => {
|
|
14
17
|
const { graph } = useAppGraph();
|
|
15
18
|
|
|
16
19
|
useEffect(() => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Graph.expand(graph, nodeId, 'outbound');
|
|
21
|
-
// Second level: expand each child.
|
|
22
|
-
Graph.getConnections(graph, nodeId, 'outbound').forEach((child) => {
|
|
23
|
-
Graph.expand(graph, child.id, 'outbound');
|
|
24
|
-
});
|
|
20
|
+
if (nodeId) {
|
|
21
|
+
for (const prefix of expandAttendableId(nodeId)) {
|
|
22
|
+
Graph.expand(graph, prefix, 'child');
|
|
25
23
|
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return () => cancelAnimationFrame(frame);
|
|
24
|
+
}
|
|
29
25
|
}, [nodeId, graph]);
|
|
30
26
|
};
|
package/src/components/index.ts
CHANGED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Atom } from '@effect-atom/atom-react';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
|
|
8
|
+
import { type AppCapabilities, getCompanionVariant } from '@dxos/app-toolkit';
|
|
9
|
+
import { Node } from '@dxos/plugin-graph';
|
|
10
|
+
import { type ActionGraphProps } from '@dxos/react-ui-menu';
|
|
11
|
+
import { byPosition } from '@dxos/util';
|
|
12
|
+
|
|
13
|
+
import { type SimpleLayoutState } from '../types';
|
|
14
|
+
|
|
15
|
+
// TODO(wittjosiah): Factor out to shared location with plugin-deck.
|
|
16
|
+
export const PLANK_COMPANION_TYPE = 'org.dxos.plugin.deck.plank-companion';
|
|
17
|
+
|
|
18
|
+
export type CompanionActionsConfig = {
|
|
19
|
+
/** Prefix for companion action IDs (e.g. 'navbar' or 'drawer') */
|
|
20
|
+
idPrefix: string;
|
|
21
|
+
/** Optional: highlight companion with this variant */
|
|
22
|
+
selectedVariant?: string;
|
|
23
|
+
/** State updater for toggling the drawer. */
|
|
24
|
+
updateState: (fn: (state: SimpleLayoutState) => SimpleLayoutState) => void;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Creates action graph nodes and edges for companion actions.
|
|
29
|
+
* Shared logic between useNavbarActions and useDrawerActions.
|
|
30
|
+
*/
|
|
31
|
+
// TODO(burdon): Use builder pattern.
|
|
32
|
+
export const createCompanionActions = (
|
|
33
|
+
graph: AppCapabilities.AppGraph['graph'],
|
|
34
|
+
stateAtom: Atom.Atom<SimpleLayoutState>,
|
|
35
|
+
get: (atom: Atom.Atom<any>) => any,
|
|
36
|
+
config: CompanionActionsConfig,
|
|
37
|
+
): Pick<ActionGraphProps, 'nodes' | 'edges'> => {
|
|
38
|
+
const { idPrefix, selectedVariant, updateState } = config;
|
|
39
|
+
|
|
40
|
+
// Derive activeId from state atom.
|
|
41
|
+
const state = get(stateAtom);
|
|
42
|
+
const activeId = state.active ?? state.workspace;
|
|
43
|
+
|
|
44
|
+
// Get companions from graph connections for activeId.
|
|
45
|
+
const activeConnections = activeId ? get(graph.connections(activeId, 'child')) : [];
|
|
46
|
+
const companions = activeConnections
|
|
47
|
+
.filter((node: Node.Node) => node.type === PLANK_COMPANION_TYPE)
|
|
48
|
+
.toSorted((a: Node.Node, b: Node.Node) => byPosition(a.properties, b.properties));
|
|
49
|
+
|
|
50
|
+
const nodes: ActionGraphProps['nodes'] = [];
|
|
51
|
+
const edges: ActionGraphProps['edges'] = [];
|
|
52
|
+
|
|
53
|
+
companions.forEach((companion: Node.Node) => {
|
|
54
|
+
const companionVariant = getCompanionVariant(companion.id);
|
|
55
|
+
const companionAction = {
|
|
56
|
+
id: `${idPrefix}-companion-${companion.id}`,
|
|
57
|
+
type: Node.ActionType,
|
|
58
|
+
properties: {
|
|
59
|
+
icon: companion.properties.icon ?? 'ph--placeholder--regular',
|
|
60
|
+
label: companion.properties.label,
|
|
61
|
+
iconOnly: true,
|
|
62
|
+
...(selectedVariant !== undefined && {
|
|
63
|
+
variant: selectedVariant === companionVariant ? 'primary' : 'ghost',
|
|
64
|
+
}),
|
|
65
|
+
},
|
|
66
|
+
data: () =>
|
|
67
|
+
Effect.sync(() =>
|
|
68
|
+
updateState((current) => {
|
|
69
|
+
const closing = current.companionVariant === companionVariant && current.drawerState !== 'closed';
|
|
70
|
+
return {
|
|
71
|
+
...current,
|
|
72
|
+
companionVariant: closing ? undefined : companionVariant,
|
|
73
|
+
drawerState: closing ? 'closed' : 'open',
|
|
74
|
+
};
|
|
75
|
+
}),
|
|
76
|
+
),
|
|
77
|
+
};
|
|
78
|
+
nodes.push(companionAction);
|
|
79
|
+
edges.push({ source: 'root', target: companionAction.id, relation: 'child' });
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return { nodes, edges };
|
|
83
|
+
};
|
package/src/hooks/index.ts
CHANGED