@dxos/plugin-simple-layout 0.0.0 → 0.8.4-main.1c7ec43d41
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/SimpleLayoutPlugin-Q5BZE6KD.mjs +50 -0
- package/dist/lib/browser/SimpleLayoutPlugin-Q5BZE6KD.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +25 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/browser/translations.mjs +34 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/node-esm/SimpleLayoutPlugin-OD45TNPO.mjs +52 -0
- package/dist/lib/node-esm/SimpleLayoutPlugin-OD45TNPO.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +27 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/translations.mjs +36 -0
- package/dist/lib/node-esm/translations.mjs.map +7 -0
- package/dist/types/src/SimpleLayoutPlugin.d.ts +8 -0
- package/dist/types/src/SimpleLayoutPlugin.d.ts.map +1 -0
- package/dist/types/src/capabilities/app-graph-builder.d.ts +6 -0
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +22 -0
- package/dist/types/src/capabilities/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
- package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-root.d.ts +9 -0
- package/dist/types/src/capabilities/react-root.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +5 -0
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
- package/dist/types/src/capabilities/spotlight-dismiss.d.ts +14 -0
- package/dist/types/src/capabilities/spotlight-dismiss.d.ts.map +1 -0
- package/dist/types/src/capabilities/state.d.ts +19 -0
- package/dist/types/src/capabilities/state.d.ts.map +1 -0
- package/dist/types/src/capabilities/url-handler.d.ts +12 -0
- package/dist/types/src/capabilities/url-handler.d.ts.map +1 -0
- package/dist/types/src/components/ContentError.stories.d.ts +46 -0
- package/dist/types/src/components/ContentError.stories.d.ts.map +1 -0
- package/dist/types/src/components/DebugOverlay/DebugOverlay.d.ts +19 -0
- package/dist/types/src/components/DebugOverlay/DebugOverlay.d.ts.map +1 -0
- package/dist/types/src/components/DebugOverlay/index.d.ts +2 -0
- package/dist/types/src/components/DebugOverlay/index.d.ts.map +1 -0
- package/dist/types/src/components/Dialog/Dialog.d.ts +3 -0
- package/dist/types/src/components/Dialog/Dialog.d.ts.map +1 -0
- package/dist/types/src/components/Dialog/index.d.ts +2 -0
- package/dist/types/src/components/Dialog/index.d.ts.map +1 -0
- package/dist/types/src/components/Home/Home.d.ts +7 -0
- package/dist/types/src/components/Home/Home.d.ts.map +1 -0
- package/dist/types/src/components/Home/index.d.ts +2 -0
- package/dist/types/src/components/Home/index.d.ts.map +1 -0
- package/dist/types/src/components/Loading/Loading.d.ts +3 -0
- package/dist/types/src/components/Loading/Loading.d.ts.map +1 -0
- package/dist/types/src/components/Loading/Loading.stories.d.ts +13 -0
- package/dist/types/src/components/Loading/Loading.stories.d.ts.map +1 -0
- package/dist/types/src/components/Loading/index.d.ts +2 -0
- package/dist/types/src/components/Loading/index.d.ts.map +1 -0
- 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 +4 -0
- package/dist/types/src/components/Popover/Popover.d.ts.map +1 -0
- package/dist/types/src/components/Popover/index.d.ts +2 -0
- package/dist/types/src/components/Popover/index.d.ts.map +1 -0
- package/dist/types/src/components/SimpleLayout/AppBar.d.ts +24 -0
- package/dist/types/src/components/SimpleLayout/AppBar.d.ts.map +1 -0
- package/dist/types/src/components/SimpleLayout/AppBar.stories.d.ts +54 -0
- package/dist/types/src/components/SimpleLayout/AppBar.stories.d.ts.map +1 -0
- package/dist/types/src/components/SimpleLayout/Drawer.d.ts +6 -0
- package/dist/types/src/components/SimpleLayout/Drawer.d.ts.map +1 -0
- package/dist/types/src/components/SimpleLayout/Main.d.ts +6 -0
- package/dist/types/src/components/SimpleLayout/Main.d.ts.map +1 -0
- package/dist/types/src/components/SimpleLayout/NavBar.d.ts +16 -0
- package/dist/types/src/components/SimpleLayout/NavBar.d.ts.map +1 -0
- package/dist/types/src/components/SimpleLayout/NavBar.stories.d.ts +49 -0
- package/dist/types/src/components/SimpleLayout/NavBar.stories.d.ts.map +1 -0
- package/dist/types/src/components/SimpleLayout/SimpleLayout.d.ts +3 -0
- package/dist/types/src/components/SimpleLayout/SimpleLayout.d.ts.map +1 -0
- package/dist/types/src/components/SimpleLayout/SimpleLayout.stories.d.ts +48 -0
- package/dist/types/src/components/SimpleLayout/SimpleLayout.stories.d.ts.map +1 -0
- package/dist/types/src/components/SimpleLayout/index.d.ts +5 -0
- package/dist/types/src/components/SimpleLayout/index.d.ts.map +1 -0
- package/dist/types/src/components/hooks.d.ts +7 -0
- package/dist/types/src/components/hooks.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +8 -0
- package/dist/types/src/components/index.d.ts.map +1 -0
- 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 +7 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- 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 +7 -0
- package/dist/types/src/hooks/useSimpleLayoutState.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/meta.d.ts +3 -0
- package/dist/types/src/meta.d.ts.map +1 -0
- package/dist/types/src/operations/close.d.ts +5 -0
- package/dist/types/src/operations/close.d.ts.map +1 -0
- package/dist/types/src/operations/index.d.ts +3 -0
- package/dist/types/src/operations/index.d.ts.map +1 -0
- package/dist/types/src/operations/open.d.ts +5 -0
- package/dist/types/src/operations/open.d.ts.map +1 -0
- package/dist/types/src/operations/revert-workspace.d.ts +5 -0
- package/dist/types/src/operations/revert-workspace.d.ts.map +1 -0
- package/dist/types/src/operations/set-layout-mode.d.ts +5 -0
- package/dist/types/src/operations/set-layout-mode.d.ts.map +1 -0
- package/dist/types/src/operations/set.d.ts +5 -0
- package/dist/types/src/operations/set.d.ts.map +1 -0
- package/dist/types/src/operations/state-access.d.ts +8 -0
- package/dist/types/src/operations/state-access.d.ts.map +1 -0
- package/dist/types/src/operations/switch-workspace.d.ts +5 -0
- package/dist/types/src/operations/switch-workspace.d.ts.map +1 -0
- package/dist/types/src/operations/update-complementary.d.ts +5 -0
- package/dist/types/src/operations/update-complementary.d.ts.map +1 -0
- package/dist/types/src/operations/update-dialog.d.ts +5 -0
- package/dist/types/src/operations/update-dialog.d.ts.map +1 -0
- package/dist/types/src/operations/update-popover.d.ts +5 -0
- package/dist/types/src/operations/update-popover.d.ts.map +1 -0
- package/dist/types/src/operations/update-sidebar.d.ts +5 -0
- package/dist/types/src/operations/update-sidebar.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +32 -0
- package/dist/types/src/translations.d.ts.map +1 -0
- package/dist/types/src/types/capabilities.d.ts +44 -0
- package/dist/types/src/types/capabilities.d.ts.map +1 -0
- package/dist/types/src/types/events.d.ts +6 -0
- package/dist/types/src/types/events.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +3 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +58 -29
- package/src/SimpleLayoutPlugin.ts +39 -11
- package/src/capabilities/app-graph-builder.ts +21 -0
- package/src/capabilities/index.ts +13 -3
- package/src/capabilities/operation-handler.ts +14 -0
- package/src/capabilities/{react-root/react-root.tsx → react-root.tsx} +4 -4
- package/src/capabilities/react-surface.tsx +50 -0
- package/src/{hooks/useSpotlightDismiss.ts → capabilities/spotlight-dismiss.ts} +31 -40
- package/src/capabilities/state.tsx +52 -0
- package/src/capabilities/url-handler.ts +161 -0
- package/src/components/ContentError.stories.tsx +9 -8
- package/src/components/DebugOverlay/DebugOverlay.tsx +96 -0
- package/src/components/DebugOverlay/index.ts +5 -0
- package/src/components/Dialog/Dialog.tsx +26 -15
- package/src/components/Home/Home.tsx +80 -80
- package/src/components/{ContentLoading.stories.tsx → Loading/Loading.stories.tsx} +5 -5
- package/src/components/{ContentLoading.tsx → Loading/Loading.tsx} +2 -2
- package/src/components/Loading/index.ts +5 -0
- package/src/components/MobileLayout/MobileLayout.stories.tsx +133 -0
- package/src/components/MobileLayout/MobileLayout.tsx +374 -0
- package/src/components/MobileLayout/index.ts +5 -0
- package/src/components/NavBranch/NavBranch.tsx +124 -0
- package/src/components/NavBranch/index.ts +5 -0
- package/src/components/Popover/Popover.tsx +49 -27
- package/src/components/SimpleLayout/AppBar.stories.tsx +144 -0
- package/src/components/SimpleLayout/AppBar.tsx +94 -0
- package/src/components/SimpleLayout/Drawer.tsx +104 -0
- package/src/components/SimpleLayout/Main.tsx +54 -61
- package/src/components/SimpleLayout/NavBar.stories.tsx +164 -0
- package/src/components/SimpleLayout/NavBar.tsx +19 -83
- package/src/components/SimpleLayout/SimpleLayout.stories.tsx +44 -61
- package/src/components/SimpleLayout/SimpleLayout.tsx +45 -8
- package/src/components/SimpleLayout/index.ts +3 -0
- package/src/components/hooks.ts +26 -0
- package/src/components/index.ts +4 -1
- package/src/hooks/actions.ts +84 -0
- package/src/hooks/index.ts +6 -1
- package/src/hooks/useAppBarProps.ts +95 -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 +30 -0
- package/src/index.ts +7 -1
- package/src/meta.ts +2 -1
- package/src/operations/close.ts +34 -0
- package/src/operations/index.ts +16 -0
- package/src/operations/open.ts +63 -0
- package/src/operations/revert-workspace.ts +22 -0
- package/src/operations/set-layout-mode.ts +12 -0
- package/src/operations/set.ts +23 -0
- package/src/operations/state-access.ts +19 -0
- package/src/operations/switch-workspace.ts +26 -0
- package/src/operations/update-complementary.ts +35 -0
- package/src/operations/update-dialog.ts +28 -0
- package/src/operations/update-popover.ts +35 -0
- package/src/operations/update-sidebar.ts +12 -0
- package/src/translations.ts +21 -13
- package/src/types/capabilities.ts +23 -7
- package/src/types/events.ts +15 -0
- package/src/types/index.ts +1 -0
- package/src/capabilities/operation-resolver/index.ts +0 -10
- package/src/capabilities/operation-resolver/operation-resolver.ts +0 -135
- package/src/capabilities/react-root/index.ts +0 -7
- package/src/capabilities/state/index.ts +0 -9
- package/src/capabilities/state/state.tsx +0 -60
- package/src/components/ContentError.tsx +0 -23
- package/src/components/SimpleLayout/Banner.tsx +0 -60
- package/src/components/SimpleLayout/NavBarstories.tsx +0 -59
|
@@ -2,96 +2,32 @@
|
|
|
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 {
|
|
10
|
-
Avatar,
|
|
11
|
-
Button,
|
|
12
|
-
ButtonGroup,
|
|
13
|
-
DensityProvider,
|
|
14
|
-
IconButton,
|
|
15
|
-
type Size,
|
|
16
|
-
Tooltip,
|
|
17
|
-
useTranslation,
|
|
18
|
-
} from '@dxos/react-ui';
|
|
19
|
-
import { DropdownMenu, MenuProvider } from '@dxos/react-ui-menu';
|
|
20
|
-
import { mx, surfaceZIndex } from '@dxos/ui-theme';
|
|
8
|
+
import { type ActionExecutor, type ActionGraphProps, Menu, useMenuActions } from '@dxos/react-ui-menu';
|
|
9
|
+
import { composable, composableProps } from '@dxos/ui-theme';
|
|
21
10
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const buttonProps = {
|
|
25
|
-
iconOnly: true,
|
|
26
|
-
size: 6 as Size,
|
|
27
|
-
classNames: 'aspect-square',
|
|
28
|
-
};
|
|
11
|
+
const NAVBAR_NAME = 'SimpleLayout.NavBar';
|
|
29
12
|
|
|
30
13
|
export type NavBarProps = {
|
|
31
|
-
|
|
32
|
-
|
|
14
|
+
/** Action graph atom for the toolbar. */
|
|
15
|
+
actions: Atom.Atom<ActionGraphProps>;
|
|
16
|
+
/** Action executor callback. */
|
|
17
|
+
onAction?: ActionExecutor;
|
|
33
18
|
};
|
|
34
19
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const connections = useConnections(graph, Node.RootId);
|
|
41
|
-
const menuActions = connections.filter((node) => node.properties.disposition === 'menu');
|
|
42
|
-
|
|
43
|
-
const isBrowseActive = activeId !== 'notifications' && activeId !== 'profile';
|
|
20
|
+
/**
|
|
21
|
+
* Presentational navbar component that renders a toolbar from an action graph.
|
|
22
|
+
*/
|
|
23
|
+
export const NavBar = composable<HTMLDivElement, NavBarProps>(({ actions, onAction, ...props }, forwardedRef) => {
|
|
24
|
+
const menuActions = useMenuActions(actions);
|
|
44
25
|
|
|
45
26
|
return (
|
|
46
|
-
<
|
|
47
|
-
<
|
|
48
|
-
|
|
49
|
-
'fixed inset-inline-0',
|
|
50
|
-
'grid grid-cols-[min-content_min-content] gap-2 place-content-center',
|
|
51
|
-
'block-end-[--dx-mobile-bottombar-inset-bottom,0px] bs-[--dx-mobile-bottombar-content-height,64px]',
|
|
52
|
-
'bg-baseSurface border-bs border-separator',
|
|
53
|
-
surfaceZIndex({ level: 'menu' }),
|
|
54
|
-
)}
|
|
55
|
-
>
|
|
56
|
-
<ButtonGroup>
|
|
57
|
-
<IconButton
|
|
58
|
-
{...buttonProps}
|
|
59
|
-
label={t('browse label')}
|
|
60
|
-
icon='ph--squares-four--regular'
|
|
61
|
-
onClick={() => onActiveIdChange?.(null)}
|
|
62
|
-
variant={isBrowseActive ? 'primary' : 'default'}
|
|
63
|
-
{...(isBrowseActive && { 'aria-current': 'location' })}
|
|
64
|
-
/>
|
|
65
|
-
<IconButton
|
|
66
|
-
{...buttonProps}
|
|
67
|
-
label={t('notifications label')}
|
|
68
|
-
icon='ph--bell-simple--regular'
|
|
69
|
-
onClick={() => onActiveIdChange?.('notifications')}
|
|
70
|
-
variant={activeId === 'notifications' ? 'primary' : 'default'}
|
|
71
|
-
{...(activeId === 'notifications' && { 'aria-current': 'location' })}
|
|
72
|
-
/>
|
|
73
|
-
<Button
|
|
74
|
-
variant={activeId === 'profile' ? 'primary' : 'default'}
|
|
75
|
-
onClick={() => onActiveIdChange?.('profile')}
|
|
76
|
-
classNames={buttonProps.classNames}
|
|
77
|
-
>
|
|
78
|
-
<span className='sr-only'>{t('profile label')}</span>
|
|
79
|
-
<Avatar.Root>
|
|
80
|
-
<Avatar.Label classNames='sr-only'>Profile display name</Avatar.Label>
|
|
81
|
-
<Avatar.Content size={8} status='active' hue='cyan' fallback='🗿' />
|
|
82
|
-
</Avatar.Root>
|
|
83
|
-
</Button>
|
|
84
|
-
</ButtonGroup>
|
|
85
|
-
<MenuProvider onAction={runAction}>
|
|
86
|
-
<DropdownMenu.Root items={menuActions}>
|
|
87
|
-
<Tooltip.Trigger asChild content={t('app menu label')} side='right'>
|
|
88
|
-
<DropdownMenu.Trigger asChild data-testid='spacePlugin.addSpace'>
|
|
89
|
-
<IconButton {...buttonProps} icon='ph--plus--regular' label={t('main menu label')} />
|
|
90
|
-
</DropdownMenu.Trigger>
|
|
91
|
-
</Tooltip.Trigger>
|
|
92
|
-
</DropdownMenu.Root>
|
|
93
|
-
</MenuProvider>
|
|
94
|
-
</nav>
|
|
95
|
-
</DensityProvider>
|
|
27
|
+
<Menu.Root {...menuActions} alwaysActive onAction={onAction}>
|
|
28
|
+
<Menu.Toolbar {...composableProps(props)} ref={forwardedRef} />
|
|
29
|
+
</Menu.Root>
|
|
96
30
|
);
|
|
97
|
-
};
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
NavBar.displayName = NAVBAR_NAME;
|
|
@@ -5,88 +5,71 @@
|
|
|
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, Capability, Plugin } from '@dxos/app-framework';
|
|
9
9
|
import { withPluginManager } from '@dxos/app-framework/testing';
|
|
10
|
-
import {
|
|
10
|
+
import { AppActivationEvents } from '@dxos/app-toolkit/events';
|
|
11
|
+
import { Collection } from '@dxos/echo';
|
|
12
|
+
import { ClientPlugin } from '@dxos/plugin-client';
|
|
11
13
|
import { SearchPlugin } from '@dxos/plugin-search';
|
|
12
14
|
import { SpacePlugin } from '@dxos/plugin-space';
|
|
13
|
-
import { SpaceOperation } from '@dxos/plugin-space/types';
|
|
14
15
|
import { corePlugins } from '@dxos/plugin-testing';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { Collection } from '@dxos/schema';
|
|
16
|
+
import { translations as searchTranslation } from '@dxos/react-ui-search/translations';
|
|
17
|
+
import { withLayout } from '@dxos/react-ui/testing';
|
|
18
18
|
|
|
19
|
-
import {
|
|
20
|
-
import { meta as pluginMeta } from '
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
19
|
+
import { ReactRoot, ReactSurface, State } from '#capabilities';
|
|
20
|
+
import { meta as pluginMeta } from '#meta';
|
|
21
|
+
import { translations } from '#translations';
|
|
22
|
+
import { SimpleLayoutEvents } from '#types';
|
|
23
23
|
|
|
24
|
+
import { type SimpleLayoutPluginOptions } from '../../SimpleLayoutPlugin';
|
|
24
25
|
import { SimpleLayout } from './SimpleLayout';
|
|
25
26
|
|
|
26
|
-
const
|
|
27
|
-
Plugin.addModule(({ isPopover = false }) => ({
|
|
28
|
-
id: Capability.getModuleTag(State),
|
|
29
|
-
activatesOn: Common.ActivationEvent.Startup,
|
|
30
|
-
activatesAfter: [Common.ActivationEvent.LayoutReady],
|
|
31
|
-
activate: () => State({ initialState: { isPopover } } satisfies SimpleLayoutStateOptions),
|
|
32
|
-
})),
|
|
33
|
-
Common.Plugin.addOperationResolverModule({ activate: OperationResolver }),
|
|
34
|
-
Plugin.addModule({
|
|
35
|
-
id: 'setup',
|
|
36
|
-
activatesOn: Common.ActivationEvent.OperationInvokerReady,
|
|
37
|
-
activate: Effect.fnUntraced(function* () {
|
|
38
|
-
const { invoke } = yield* Capability.get(Common.Capability.OperationInvoker);
|
|
39
|
-
yield* invoke(ClientOperation.CreateIdentity, {});
|
|
40
|
-
const { space: work } = yield* invoke(SpaceOperation.Create, { name: 'Work Space' });
|
|
41
|
-
const { space: sharedProject } = yield* invoke(SpaceOperation.Create, { name: 'Shared Project' });
|
|
42
|
-
|
|
43
|
-
// Add collections to Work Space.
|
|
44
|
-
yield* invoke(SpaceOperation.AddObject, {
|
|
45
|
-
target: work.db,
|
|
46
|
-
object: Collection.make({ name: 'Projects', objects: [] }),
|
|
47
|
-
});
|
|
48
|
-
yield* invoke(SpaceOperation.AddObject, {
|
|
49
|
-
target: work.db,
|
|
50
|
-
object: Collection.make({ name: 'Documents', objects: [] }),
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// Add collections to Shared Project.
|
|
54
|
-
yield* invoke(SpaceOperation.AddObject, {
|
|
55
|
-
target: sharedProject.db,
|
|
56
|
-
object: Collection.make({ name: 'Tasks', objects: [] }),
|
|
57
|
-
});
|
|
58
|
-
yield* invoke(SpaceOperation.AddObject, {
|
|
59
|
-
target: sharedProject.db,
|
|
60
|
-
object: Collection.make({ name: 'Notes', objects: [] }),
|
|
61
|
-
});
|
|
62
|
-
}),
|
|
63
|
-
}),
|
|
64
|
-
Plugin.make,
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
const createPluginManager = ({ isPopover }: { isPopover: boolean }) => {
|
|
27
|
+
const createPluginManager = ({ isPopover }: { isPopover?: boolean }) => {
|
|
68
28
|
return withPluginManager({
|
|
29
|
+
setupEvents: [AppActivationEvents.SetupSettings],
|
|
69
30
|
plugins: [
|
|
70
31
|
...corePlugins(),
|
|
71
32
|
ClientPlugin({
|
|
33
|
+
types: [Collection.Collection],
|
|
72
34
|
onClientInitialized: ({ client }) =>
|
|
73
35
|
Effect.gen(function* () {
|
|
74
36
|
yield* Effect.promise(() => client.halo.createIdentity());
|
|
75
|
-
yield* Effect.promise(async () => {
|
|
76
|
-
await client.spaces.create({ name: 'Work Space' });
|
|
77
|
-
await client.spaces.create({ name: 'Shared Project' });
|
|
78
|
-
});
|
|
79
37
|
}),
|
|
80
38
|
}),
|
|
81
|
-
|
|
39
|
+
|
|
82
40
|
SearchPlugin(),
|
|
83
|
-
|
|
41
|
+
SpacePlugin({}),
|
|
42
|
+
|
|
43
|
+
// TODO(burdon): This should be factored ouf from SimpleLayoutPlugin.
|
|
44
|
+
Plugin.define<SimpleLayoutPluginOptions>(pluginMeta).pipe(
|
|
45
|
+
Plugin.addModule(({ isPopover = false }) => ({
|
|
46
|
+
id: Capability.getModuleTag(State),
|
|
47
|
+
activatesOn: ActivationEvents.Startup,
|
|
48
|
+
firesAfterActivation: [SimpleLayoutEvents.StateReady, AppActivationEvents.LayoutReady],
|
|
49
|
+
activate: () => State({ initialState: { isPopover } }),
|
|
50
|
+
})),
|
|
51
|
+
Plugin.addModule({
|
|
52
|
+
id: Capability.getModuleTag(ReactRoot),
|
|
53
|
+
activatesOn: ActivationEvents.Startup,
|
|
54
|
+
activate: ReactRoot,
|
|
55
|
+
}),
|
|
56
|
+
Plugin.addModule({
|
|
57
|
+
id: Capability.getModuleTag(ReactSurface),
|
|
58
|
+
activatesOn: ActivationEvents.Startup,
|
|
59
|
+
activate: ReactSurface,
|
|
60
|
+
}),
|
|
61
|
+
Plugin.make,
|
|
62
|
+
)({ isPopover }),
|
|
84
63
|
],
|
|
85
64
|
});
|
|
86
65
|
};
|
|
87
66
|
|
|
67
|
+
/**
|
|
68
|
+
* NOTE: To expose to iphone on network:
|
|
69
|
+
* `moon run storybook-react:serve dev -H 0.0.0.0`
|
|
70
|
+
*/
|
|
88
71
|
const meta = {
|
|
89
|
-
title: 'plugins/plugin-simple-layout/SimpleLayout',
|
|
72
|
+
title: 'plugins/plugin-simple-layout/components/SimpleLayout',
|
|
90
73
|
component: SimpleLayout,
|
|
91
74
|
parameters: {
|
|
92
75
|
layout: 'fullscreen',
|
|
@@ -99,9 +82,9 @@ export default meta;
|
|
|
99
82
|
type Story = StoryObj<typeof meta>;
|
|
100
83
|
|
|
101
84
|
export const Default: Story = {
|
|
102
|
-
decorators: [
|
|
85
|
+
decorators: [withLayout({ layout: 'column', classNames: 'relative' }), createPluginManager({})],
|
|
103
86
|
};
|
|
104
87
|
|
|
105
88
|
export const Popover: Story = {
|
|
106
|
-
decorators: [
|
|
89
|
+
decorators: [withLayout({ layout: 'column', classNames: 'relative' }), createPluginManager({ isPopover: true })],
|
|
107
90
|
};
|
|
@@ -2,20 +2,57 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React from 'react';
|
|
5
|
+
import React, { useLayoutEffect, 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';
|
|
11
|
+
|
|
12
|
+
import { DebugOverlay } from '../DebugOverlay';
|
|
7
13
|
import { Dialog } from '../Dialog';
|
|
14
|
+
import { MobileLayout } from '../MobileLayout';
|
|
8
15
|
import { PopoverContent, PopoverRoot } from '../Popover';
|
|
9
|
-
|
|
16
|
+
import { Drawer } from './Drawer';
|
|
10
17
|
import { Main } from './Main';
|
|
11
18
|
|
|
12
|
-
// TODO(wittjosiah): Support toast.
|
|
13
19
|
export const SimpleLayout = () => {
|
|
20
|
+
const { state } = useSimpleLayoutState();
|
|
21
|
+
const [keyboardOpen, setKeyboardOpen] = useState(false);
|
|
22
|
+
const [splitterMode, setSplitterMode] = useState<SplitterMode>('top');
|
|
23
|
+
|
|
24
|
+
const drawerRef = useRef<HTMLDivElement>(null);
|
|
25
|
+
|
|
26
|
+
// Restore Splitter mode when keyboard closes.
|
|
27
|
+
useLayoutEffect(() => {
|
|
28
|
+
if (!keyboardOpen) {
|
|
29
|
+
setSplitterMode(state.drawerState === 'closed' ? 'top' : state.drawerState === 'open' ? 'split' : 'bottom');
|
|
30
|
+
}
|
|
31
|
+
}, [state.drawerState, keyboardOpen]);
|
|
32
|
+
|
|
14
33
|
return (
|
|
15
|
-
<
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
34
|
+
<DebugOverlay.Root enabled={false}>
|
|
35
|
+
<PopoverRoot>
|
|
36
|
+
<Mosaic.Root>
|
|
37
|
+
<MobileLayout.Root
|
|
38
|
+
classNames='dx-container grid relative bg-toolbar-surface'
|
|
39
|
+
onKeyboardOpenChange={(nextKeyboardOpen) => setKeyboardOpen(nextKeyboardOpen)}
|
|
40
|
+
>
|
|
41
|
+
<MobileLayout.Panel safe={{ top: true, bottom: splitterMode === 'top' }}>
|
|
42
|
+
<Splitter.Root mode={splitterMode} ratio={0.55}>
|
|
43
|
+
<Splitter.Panel position='top'>
|
|
44
|
+
<Main />
|
|
45
|
+
</Splitter.Panel>
|
|
46
|
+
<Splitter.Panel position='bottom' ref={drawerRef}>
|
|
47
|
+
<Drawer />
|
|
48
|
+
</Splitter.Panel>
|
|
49
|
+
</Splitter.Root>
|
|
50
|
+
<Dialog />
|
|
51
|
+
<PopoverContent />
|
|
52
|
+
</MobileLayout.Panel>
|
|
53
|
+
</MobileLayout.Root>
|
|
54
|
+
</Mosaic.Root>
|
|
55
|
+
</PopoverRoot>
|
|
56
|
+
</DebugOverlay.Root>
|
|
20
57
|
);
|
|
21
58
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useEffect } from 'react';
|
|
6
|
+
|
|
7
|
+
import { useAppGraph } from '@dxos/app-toolkit/ui';
|
|
8
|
+
import { Graph } from '@dxos/plugin-graph';
|
|
9
|
+
import { expandAttendableId } from '@dxos/react-ui-attention';
|
|
10
|
+
|
|
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.
|
|
15
|
+
*/
|
|
16
|
+
export const useExpandPath = (nodeId?: string) => {
|
|
17
|
+
const { graph } = useAppGraph();
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (nodeId) {
|
|
21
|
+
for (const prefix of expandAttendableId(nodeId)) {
|
|
22
|
+
Graph.expand(graph, prefix, 'child');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}, [nodeId, graph]);
|
|
26
|
+
};
|
package/src/components/index.ts
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './DebugOverlay';
|
|
6
6
|
export * from './Home';
|
|
7
|
+
export * from './Loading';
|
|
8
|
+
export * from './MobileLayout';
|
|
7
9
|
export * from './Popover';
|
|
8
10
|
export * from './SimpleLayout';
|
|
11
|
+
export * from './NavBranch';
|
|
@@ -0,0 +1,84 @@
|
|
|
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 } from '@dxos/app-toolkit';
|
|
9
|
+
import { Node } from '@dxos/plugin-graph';
|
|
10
|
+
import { getLinkedVariant } from '@dxos/react-ui-attention';
|
|
11
|
+
import { type ActionGraphProps } from '@dxos/react-ui-menu';
|
|
12
|
+
import { byPosition } from '@dxos/util';
|
|
13
|
+
|
|
14
|
+
import { type SimpleLayoutState } from '#types';
|
|
15
|
+
|
|
16
|
+
// TODO(wittjosiah): Factor out to shared location with plugin-deck.
|
|
17
|
+
export const PLANK_COMPANION_TYPE = 'org.dxos.plugin.deck.plank-companion';
|
|
18
|
+
|
|
19
|
+
export type CompanionActionsConfig = {
|
|
20
|
+
/** Prefix for companion action IDs (e.g. 'navbar' or 'drawer') */
|
|
21
|
+
idPrefix: string;
|
|
22
|
+
/** Optional: highlight companion with this variant */
|
|
23
|
+
selectedVariant?: string;
|
|
24
|
+
/** State updater for toggling the drawer. */
|
|
25
|
+
updateState: (fn: (state: SimpleLayoutState) => SimpleLayoutState) => void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Creates action graph nodes and edges for companion actions.
|
|
30
|
+
* Shared logic between useNavbarActions and useDrawerActions.
|
|
31
|
+
*/
|
|
32
|
+
// TODO(burdon): Use builder pattern.
|
|
33
|
+
export const createCompanionActions = (
|
|
34
|
+
graph: AppCapabilities.AppGraph['graph'],
|
|
35
|
+
stateAtom: Atom.Atom<SimpleLayoutState>,
|
|
36
|
+
get: (atom: Atom.Atom<any>) => any,
|
|
37
|
+
config: CompanionActionsConfig,
|
|
38
|
+
): Pick<ActionGraphProps, 'nodes' | 'edges'> => {
|
|
39
|
+
const { idPrefix, selectedVariant, updateState } = config;
|
|
40
|
+
|
|
41
|
+
// Derive activeId from state atom.
|
|
42
|
+
const state = get(stateAtom);
|
|
43
|
+
const activeId = state.active ?? state.workspace;
|
|
44
|
+
|
|
45
|
+
// Get companions from graph connections for activeId.
|
|
46
|
+
const activeConnections = activeId ? get(graph.connections(activeId, 'child')) : [];
|
|
47
|
+
const companions = activeConnections
|
|
48
|
+
.filter((node: Node.Node) => node.type === PLANK_COMPANION_TYPE)
|
|
49
|
+
.toSorted((a: Node.Node, b: Node.Node) => byPosition(a.properties, b.properties));
|
|
50
|
+
|
|
51
|
+
const nodes: ActionGraphProps['nodes'] = [];
|
|
52
|
+
const edges: ActionGraphProps['edges'] = [];
|
|
53
|
+
|
|
54
|
+
companions.forEach((companion: Node.Node) => {
|
|
55
|
+
const companionVariant = getLinkedVariant(companion.id);
|
|
56
|
+
const companionAction = {
|
|
57
|
+
id: `${idPrefix}-companion-${companion.id}`,
|
|
58
|
+
type: Node.ActionType,
|
|
59
|
+
properties: {
|
|
60
|
+
icon: companion.properties.icon ?? 'ph--placeholder--regular',
|
|
61
|
+
label: companion.properties.label,
|
|
62
|
+
iconOnly: true,
|
|
63
|
+
...(selectedVariant !== undefined && {
|
|
64
|
+
variant: selectedVariant === companionVariant ? 'primary' : 'ghost',
|
|
65
|
+
}),
|
|
66
|
+
},
|
|
67
|
+
data: () =>
|
|
68
|
+
Effect.sync(() =>
|
|
69
|
+
updateState((current) => {
|
|
70
|
+
const closing = current.companionVariant === companionVariant && current.drawerState !== 'closed';
|
|
71
|
+
return {
|
|
72
|
+
...current,
|
|
73
|
+
companionVariant: closing ? undefined : companionVariant,
|
|
74
|
+
drawerState: closing ? 'closed' : 'open',
|
|
75
|
+
};
|
|
76
|
+
}),
|
|
77
|
+
),
|
|
78
|
+
};
|
|
79
|
+
nodes.push(companionAction);
|
|
80
|
+
edges.push({ source: 'root', target: companionAction.id, relation: 'child' });
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return { nodes, edges };
|
|
84
|
+
};
|
package/src/hooks/index.ts
CHANGED
|
@@ -2,4 +2,9 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './useAppBarProps';
|
|
6
|
+
export * from './useCompanions';
|
|
7
|
+
export * from './actions';
|
|
8
|
+
export * from './useDrawerActions';
|
|
9
|
+
export * from './useNavbarActions';
|
|
10
|
+
export * from './useSimpleLayoutState';
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Atom, useAtomValue } from '@effect-atom/atom-react';
|
|
6
|
+
import * as Option from 'effect/Option';
|
|
7
|
+
import { useCallback, useMemo } from 'react';
|
|
8
|
+
|
|
9
|
+
import { useCapability, useOperationInvoker } from '@dxos/app-framework/ui';
|
|
10
|
+
import { LayoutOperation } from '@dxos/app-toolkit';
|
|
11
|
+
import { useAppGraph } from '@dxos/app-toolkit/ui';
|
|
12
|
+
import { Graph, Node, useActionRunner, useNode } from '@dxos/plugin-graph';
|
|
13
|
+
import { toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
14
|
+
import { type ActionGraphProps } from '@dxos/react-ui-menu';
|
|
15
|
+
|
|
16
|
+
import { type AppBarProps } from '#components';
|
|
17
|
+
import { meta } from '#meta';
|
|
18
|
+
import { SimpleLayoutState as SimpleLayoutStateCapability } from '#types';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Hook that computes all AppBar props from the app graph.
|
|
22
|
+
* Derives activeId from state atom. Returns props ready to spread into the AppBar component.
|
|
23
|
+
*/
|
|
24
|
+
export const useAppBarProps = (): Omit<AppBarProps, 'classNames'> => {
|
|
25
|
+
const { t } = useTranslation(meta.id);
|
|
26
|
+
const stateAtom = useCapability(SimpleLayoutStateCapability);
|
|
27
|
+
const state = useAtomValue(stateAtom);
|
|
28
|
+
const { graph } = useAppGraph();
|
|
29
|
+
const { invokePromise } = useOperationInvoker();
|
|
30
|
+
const runAction = useActionRunner();
|
|
31
|
+
|
|
32
|
+
// Derive activeId from state.
|
|
33
|
+
const activeId = state.active ?? state.workspace;
|
|
34
|
+
const node = useNode(graph, activeId);
|
|
35
|
+
|
|
36
|
+
// Compute title from node label.
|
|
37
|
+
const title = node ? toLocalizedString(node.properties.label, t) : undefined;
|
|
38
|
+
|
|
39
|
+
// Build actions atom filtering by disposition.
|
|
40
|
+
// Derive activeId from state atom so we don't need to recreate this atom when it changes.
|
|
41
|
+
const actionsAtom = useMemo(
|
|
42
|
+
() =>
|
|
43
|
+
Atom.make((get): ActionGraphProps => {
|
|
44
|
+
const state = get(stateAtom);
|
|
45
|
+
const activeId = state.active ?? state.workspace;
|
|
46
|
+
const allActions = activeId ? get(graph.actions(activeId)) : [];
|
|
47
|
+
const filtered = allActions.filter((action) =>
|
|
48
|
+
['list-item', 'list-item-primary', 'heading-list-item'].includes(action.properties.disposition),
|
|
49
|
+
);
|
|
50
|
+
const nodes: ActionGraphProps['nodes'] = filtered as ActionGraphProps['nodes'];
|
|
51
|
+
const edges: ActionGraphProps['edges'] = filtered.map((action) => ({
|
|
52
|
+
source: 'root',
|
|
53
|
+
target: action.id,
|
|
54
|
+
relation: 'child',
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
return { nodes, edges };
|
|
58
|
+
}),
|
|
59
|
+
[graph, stateAtom],
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// Back button logic.
|
|
63
|
+
const showBackButton = activeId !== undefined && activeId !== Node.RootId;
|
|
64
|
+
|
|
65
|
+
const onBack = useCallback(() => {
|
|
66
|
+
if (state.active) {
|
|
67
|
+
const isWorkspace = Graph.getNode(graph, state.active).pipe(
|
|
68
|
+
Option.map((node) => node.properties.disposition === 'workspace'),
|
|
69
|
+
Option.getOrElse(() => false),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
// If history is empty and this is a workspace, go to home.
|
|
73
|
+
if (state.history.length === 0 && isWorkspace) {
|
|
74
|
+
void invokePromise(LayoutOperation.SwitchWorkspace, { subject: Node.RootId });
|
|
75
|
+
} else {
|
|
76
|
+
// Otherwise, close (which will pop from history or clear active).
|
|
77
|
+
void invokePromise(LayoutOperation.Close, { subject: [state.active] });
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
void invokePromise(LayoutOperation.SwitchWorkspace, { subject: Node.RootId });
|
|
81
|
+
}
|
|
82
|
+
}, [graph, invokePromise, state.active, state.history.length]);
|
|
83
|
+
|
|
84
|
+
// Compute popover anchor ID.
|
|
85
|
+
const popoverAnchorId = node && state.popoverAnchorId === `${meta.id}:${node.id}` ? state.popoverAnchorId : undefined;
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
title,
|
|
89
|
+
actions: actionsAtom,
|
|
90
|
+
showBackButton,
|
|
91
|
+
popoverAnchorId,
|
|
92
|
+
onBack: onBack,
|
|
93
|
+
onAction: runAction,
|
|
94
|
+
};
|
|
95
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import { useAppGraph } from '@dxos/app-toolkit/ui';
|
|
8
|
+
import { useConnections } from '@dxos/plugin-graph';
|
|
9
|
+
import { byPosition } from '@dxos/util';
|
|
10
|
+
|
|
11
|
+
import { PLANK_COMPANION_TYPE } from './actions';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Adopt the pattern from useNavbarActions (deriving from graph atoms)
|
|
15
|
+
* or merge the Drawer companion display into the NavBar component.
|
|
16
|
+
*/
|
|
17
|
+
export const useCompanions = (nodeId?: string) => {
|
|
18
|
+
const { graph } = useAppGraph();
|
|
19
|
+
const nodes = useConnections(graph, nodeId, 'child');
|
|
20
|
+
const companions = nodes.filter((node) => node.type === PLANK_COMPANION_TYPE);
|
|
21
|
+
return useMemo(() => companions.toSorted((a, b) => byPosition(a.properties, b.properties)), [companions]);
|
|
22
|
+
};
|