@dxos/plugin-simple-layout 0.8.4-main.21d9917 → 0.8.4-main.2244d791bb

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/dist/lib/browser/{chunk-CLPGTNWJ.mjs → chunk-7VLT3S46.mjs} +3 -3
  2. package/dist/lib/browser/chunk-7VLT3S46.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-U632CHRU.mjs +1167 -0
  4. package/dist/lib/browser/chunk-U632CHRU.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +27 -20
  6. package/dist/lib/browser/index.mjs.map +3 -3
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/{operation-resolver-LTB63NKP.mjs → operation-resolver-BYRIQOQT.mjs} +66 -29
  9. package/dist/lib/browser/operation-resolver-BYRIQOQT.mjs.map +7 -0
  10. package/dist/lib/browser/{react-root-6ARAPH3O.mjs → react-root-ZQTWLJYR.mjs} +5 -5
  11. package/dist/lib/browser/react-root-ZQTWLJYR.mjs.map +7 -0
  12. package/dist/lib/browser/{react-surface-SO7B23GS.mjs → react-surface-IOYDLMNR.mjs} +10 -8
  13. package/dist/lib/browser/react-surface-IOYDLMNR.mjs.map +7 -0
  14. package/dist/lib/browser/{spotlight-dismiss-VSNOPETH.mjs → spotlight-dismiss-67PHYS5B.mjs} +3 -3
  15. package/dist/lib/browser/spotlight-dismiss-67PHYS5B.mjs.map +7 -0
  16. package/dist/lib/browser/{state-H4IGICBB.mjs → state-A3PGDWWZ.mjs} +8 -5
  17. package/dist/lib/browser/state-A3PGDWWZ.mjs.map +7 -0
  18. package/dist/lib/browser/url-handler-HTIUY6WL.mjs +152 -0
  19. package/dist/lib/browser/url-handler-HTIUY6WL.mjs.map +7 -0
  20. package/dist/lib/node-esm/chunk-UXFYLQJA.mjs +1168 -0
  21. package/dist/lib/node-esm/chunk-UXFYLQJA.mjs.map +7 -0
  22. package/dist/lib/node-esm/{chunk-MUVVYBUE.mjs → chunk-VIDE5UMB.mjs} +3 -3
  23. package/dist/lib/node-esm/chunk-VIDE5UMB.mjs.map +7 -0
  24. package/dist/lib/node-esm/index.mjs +27 -20
  25. package/dist/lib/node-esm/index.mjs.map +3 -3
  26. package/dist/lib/node-esm/meta.json +1 -1
  27. package/dist/lib/node-esm/{operation-resolver-7O6O7T4Q.mjs → operation-resolver-BDTFNCS2.mjs} +66 -29
  28. package/dist/lib/node-esm/operation-resolver-BDTFNCS2.mjs.map +7 -0
  29. package/dist/lib/node-esm/{react-root-2CPA2ZUS.mjs → react-root-FMAUHDJI.mjs} +5 -5
  30. package/dist/lib/node-esm/react-root-FMAUHDJI.mjs.map +7 -0
  31. package/dist/lib/node-esm/{react-surface-FKAV56MO.mjs → react-surface-ZAZRIKZQ.mjs} +10 -8
  32. package/dist/lib/node-esm/react-surface-ZAZRIKZQ.mjs.map +7 -0
  33. package/dist/lib/node-esm/{spotlight-dismiss-L5PCWIJG.mjs → spotlight-dismiss-RMLRZUVY.mjs} +3 -3
  34. package/dist/lib/node-esm/spotlight-dismiss-RMLRZUVY.mjs.map +7 -0
  35. package/dist/lib/node-esm/{state-QIU2LMLT.mjs → state-ZCFZTTPL.mjs} +8 -5
  36. package/dist/lib/node-esm/state-ZCFZTTPL.mjs.map +7 -0
  37. package/dist/lib/node-esm/url-handler-WBVVKVPC.mjs +153 -0
  38. package/dist/lib/node-esm/url-handler-WBVVKVPC.mjs.map +7 -0
  39. package/dist/types/src/SimpleLayoutPlugin.d.ts.map +1 -1
  40. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +2 -2
  41. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -1
  42. package/dist/types/src/capabilities/react-root/react-root.d.ts.map +1 -1
  43. package/dist/types/src/capabilities/react-surface/index.d.ts +1 -1
  44. package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -1
  45. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +2 -2
  46. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -1
  47. package/dist/types/src/capabilities/spotlight-dismiss/spotlight-dismiss.d.ts.map +1 -1
  48. package/dist/types/src/capabilities/state/state.d.ts.map +1 -1
  49. package/dist/types/src/capabilities/url-handler/url-handler.d.ts +2 -0
  50. package/dist/types/src/capabilities/url-handler/url-handler.d.ts.map +1 -1
  51. package/dist/types/src/components/ContentError.stories.d.ts +6 -0
  52. package/dist/types/src/components/ContentError.stories.d.ts.map +1 -1
  53. package/dist/types/src/components/Home/Home.d.ts.map +1 -1
  54. package/dist/types/src/components/MobileLayout/MobileLayout.d.ts +35 -0
  55. package/dist/types/src/components/MobileLayout/MobileLayout.d.ts.map +1 -0
  56. package/dist/types/src/components/MobileLayout/MobileLayout.stories.d.ts +7 -0
  57. package/dist/types/src/components/MobileLayout/MobileLayout.stories.d.ts.map +1 -0
  58. package/dist/types/src/components/MobileLayout/index.d.ts +2 -0
  59. package/dist/types/src/components/MobileLayout/index.d.ts.map +1 -0
  60. package/dist/types/src/components/SimpleLayout/AppBar.d.ts +26 -0
  61. package/dist/types/src/components/SimpleLayout/AppBar.d.ts.map +1 -0
  62. package/dist/types/src/components/SimpleLayout/AppBar.stories.d.ts +47 -0
  63. package/dist/types/src/components/SimpleLayout/AppBar.stories.d.ts.map +1 -0
  64. package/dist/types/src/components/SimpleLayout/Drawer.d.ts +9 -0
  65. package/dist/types/src/components/SimpleLayout/Drawer.d.ts.map +1 -0
  66. package/dist/types/src/components/SimpleLayout/Main.d.ts +1 -1
  67. package/dist/types/src/components/SimpleLayout/Main.d.ts.map +1 -1
  68. package/dist/types/src/components/SimpleLayout/NavBar.d.ts +13 -3
  69. package/dist/types/src/components/SimpleLayout/NavBar.d.ts.map +1 -1
  70. package/dist/types/src/components/SimpleLayout/NavBar.stories.d.ts +13 -9
  71. package/dist/types/src/components/SimpleLayout/NavBar.stories.d.ts.map +1 -1
  72. package/dist/types/src/components/SimpleLayout/SimpleLayout.d.ts.map +1 -1
  73. package/dist/types/src/components/SimpleLayout/SimpleLayout.stories.d.ts +10 -0
  74. package/dist/types/src/components/SimpleLayout/SimpleLayout.stories.d.ts.map +1 -1
  75. package/dist/types/src/components/SimpleLayout/index.d.ts +3 -0
  76. package/dist/types/src/components/SimpleLayout/index.d.ts.map +1 -1
  77. package/dist/types/src/components/Workspace/Workspace.d.ts +3 -1
  78. package/dist/types/src/components/Workspace/Workspace.d.ts.map +1 -1
  79. package/dist/types/src/components/hooks.d.ts.map +1 -1
  80. package/dist/types/src/components/index.d.ts +1 -0
  81. package/dist/types/src/components/index.d.ts.map +1 -1
  82. package/dist/types/src/hooks/actions.d.ts +20 -0
  83. package/dist/types/src/hooks/actions.d.ts.map +1 -0
  84. package/dist/types/src/hooks/index.d.ts +5 -0
  85. package/dist/types/src/hooks/index.d.ts.map +1 -1
  86. package/dist/types/src/hooks/useAppBarProps.d.ts +7 -0
  87. package/dist/types/src/hooks/useAppBarProps.d.ts.map +1 -0
  88. package/dist/types/src/hooks/useCompanions.d.ts +12 -0
  89. package/dist/types/src/hooks/useCompanions.d.ts.map +1 -0
  90. package/dist/types/src/hooks/useDrawerActions.d.ts +13 -0
  91. package/dist/types/src/hooks/useDrawerActions.d.ts.map +1 -0
  92. package/dist/types/src/hooks/useNavbarActions.d.ts +14 -0
  93. package/dist/types/src/hooks/useNavbarActions.d.ts.map +1 -0
  94. package/dist/types/src/hooks/useSimpleLayoutState.d.ts +3 -3
  95. package/dist/types/src/hooks/useSimpleLayoutState.d.ts.map +1 -1
  96. package/dist/types/src/translations.d.ts +6 -0
  97. package/dist/types/src/translations.d.ts.map +1 -1
  98. package/dist/types/src/types/capabilities.d.ts +8 -3
  99. package/dist/types/src/types/capabilities.d.ts.map +1 -1
  100. package/dist/types/src/types/events.d.ts.map +1 -1
  101. package/dist/types/tsconfig.tsbuildinfo +1 -1
  102. package/package.json +35 -30
  103. package/src/SimpleLayoutPlugin.ts +10 -9
  104. package/src/capabilities/operation-resolver/operation-resolver.ts +65 -26
  105. package/src/capabilities/react-root/react-root.tsx +2 -2
  106. package/src/capabilities/react-surface/react-surface.tsx +6 -5
  107. package/src/capabilities/spotlight-dismiss/spotlight-dismiss.ts +2 -2
  108. package/src/capabilities/state/state.tsx +6 -3
  109. package/src/capabilities/url-handler/url-handler.ts +111 -34
  110. package/src/components/ContentError.stories.tsx +1 -1
  111. package/src/components/ContentLoading.stories.tsx +1 -1
  112. package/src/components/Dialog/Dialog.tsx +4 -4
  113. package/src/components/Home/Home.tsx +23 -20
  114. package/src/components/MobileLayout/MobileLayout.stories.tsx +125 -0
  115. package/src/components/MobileLayout/MobileLayout.tsx +305 -0
  116. package/src/components/MobileLayout/index.ts +5 -0
  117. package/src/components/Popover/Popover.tsx +4 -4
  118. package/src/components/SimpleLayout/AppBar.stories.tsx +144 -0
  119. package/src/components/SimpleLayout/AppBar.tsx +97 -0
  120. package/src/components/SimpleLayout/Drawer.tsx +102 -0
  121. package/src/components/SimpleLayout/Main.tsx +44 -44
  122. package/src/components/SimpleLayout/NavBar.stories.tsx +129 -24
  123. package/src/components/SimpleLayout/NavBar.tsx +24 -58
  124. package/src/components/SimpleLayout/SimpleLayout.stories.tsx +22 -9
  125. package/src/components/SimpleLayout/SimpleLayout.tsx +45 -6
  126. package/src/components/SimpleLayout/index.ts +3 -0
  127. package/src/components/Workspace/Workspace.tsx +16 -11
  128. package/src/components/hooks.ts +9 -13
  129. package/src/components/index.ts +1 -0
  130. package/src/hooks/actions.ts +85 -0
  131. package/src/hooks/index.ts +5 -0
  132. package/src/hooks/useAppBarProps.ts +112 -0
  133. package/src/hooks/useCompanions.ts +22 -0
  134. package/src/hooks/useDrawerActions.ts +98 -0
  135. package/src/hooks/useNavbarActions.ts +86 -0
  136. package/src/hooks/useSimpleLayoutState.ts +5 -5
  137. package/src/translations.ts +6 -0
  138. package/src/types/capabilities.ts +12 -3
  139. package/src/types/events.ts +3 -2
  140. package/dist/lib/browser/chunk-CLPGTNWJ.mjs.map +0 -7
  141. package/dist/lib/browser/chunk-FK4M7GJV.mjs +0 -613
  142. package/dist/lib/browser/chunk-FK4M7GJV.mjs.map +0 -7
  143. package/dist/lib/browser/operation-resolver-LTB63NKP.mjs.map +0 -7
  144. package/dist/lib/browser/react-root-6ARAPH3O.mjs.map +0 -7
  145. package/dist/lib/browser/react-surface-SO7B23GS.mjs.map +0 -7
  146. package/dist/lib/browser/spotlight-dismiss-VSNOPETH.mjs.map +0 -7
  147. package/dist/lib/browser/state-H4IGICBB.mjs.map +0 -7
  148. package/dist/lib/browser/url-handler-7CFGTLNG.mjs +0 -54
  149. package/dist/lib/browser/url-handler-7CFGTLNG.mjs.map +0 -7
  150. package/dist/lib/node-esm/chunk-EGFZAVBD.mjs +0 -614
  151. package/dist/lib/node-esm/chunk-EGFZAVBD.mjs.map +0 -7
  152. package/dist/lib/node-esm/chunk-MUVVYBUE.mjs.map +0 -7
  153. package/dist/lib/node-esm/operation-resolver-7O6O7T4Q.mjs.map +0 -7
  154. package/dist/lib/node-esm/react-root-2CPA2ZUS.mjs.map +0 -7
  155. package/dist/lib/node-esm/react-surface-FKAV56MO.mjs.map +0 -7
  156. package/dist/lib/node-esm/spotlight-dismiss-L5PCWIJG.mjs.map +0 -7
  157. package/dist/lib/node-esm/state-QIU2LMLT.mjs.map +0 -7
  158. package/dist/lib/node-esm/url-handler-4LYP3JM7.mjs +0 -55
  159. package/dist/lib/node-esm/url-handler-4LYP3JM7.mjs.map +0 -7
  160. package/dist/types/src/components/SimpleLayout/Banner.d.ts +0 -8
  161. package/dist/types/src/components/SimpleLayout/Banner.d.ts.map +0 -1
  162. package/src/components/SimpleLayout/Banner.tsx +0 -82
@@ -0,0 +1,144 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Atom } from '@effect-atom/atom-react';
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';
9
+
10
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
11
+ import { type ActionGraphProps, createMenuAction } from '@dxos/react-ui-menu';
12
+ import { withRegistry } from '@dxos/storybook-utils';
13
+
14
+ import { translations } from '../../translations';
15
+ import { MobileLayout } from '../MobileLayout';
16
+
17
+ import { AppBar, type AppBarProps } from './AppBar';
18
+
19
+ const buildEmptyActions = (): ActionGraphProps => ({ nodes: [], edges: [] });
20
+
21
+ const buildDefaultActions = (): ActionGraphProps => {
22
+ const result: ActionGraphProps = { nodes: [], edges: [] };
23
+ const actions = [
24
+ createMenuAction('action-edit', () => console.log('Edit'), {
25
+ icon: 'ph--pencil--regular',
26
+ label: 'Edit',
27
+ }),
28
+ createMenuAction('action-share', () => console.log('Share'), {
29
+ icon: 'ph--share--regular',
30
+ label: 'Share',
31
+ }),
32
+ createMenuAction('action-delete', () => console.log('Delete'), {
33
+ icon: 'ph--trash--regular',
34
+ label: 'Delete',
35
+ }),
36
+ ];
37
+ result.nodes.push(...actions);
38
+ result.edges.push(...actions.map((a) => ({ source: 'root', target: a.id })));
39
+ return result;
40
+ };
41
+
42
+ type StoryProps = Omit<AppBarProps, 'actions'> & {
43
+ actions: ActionGraphProps;
44
+ };
45
+
46
+ const DefaultStory = ({ actions: actionsProp, ...props }: StoryProps) => {
47
+ const actions = useMemo(() => Atom.make(actionsProp).pipe(Atom.keepAlive), [actionsProp]);
48
+ return (
49
+ <MobileLayout.Root>
50
+ <AppBar {...props} actions={actions} />
51
+ </MobileLayout.Root>
52
+ );
53
+ };
54
+
55
+ const meta = {
56
+ title: 'plugins/plugin-simple-layout/AppBar',
57
+ render: DefaultStory,
58
+ decorators: [
59
+ withTheme(),
60
+ withLayout({
61
+ layout: 'column',
62
+ classNames: 'relative',
63
+ }),
64
+ withRegistry,
65
+ ],
66
+ parameters: {
67
+ layout: 'fullscreen',
68
+ translations,
69
+ },
70
+ } satisfies Meta<typeof DefaultStory>;
71
+
72
+ export default meta;
73
+
74
+ type Story = StoryObj<StoryProps>;
75
+
76
+ export const Default: Story = {
77
+ tags: ['test'],
78
+ args: {
79
+ actions: buildDefaultActions(),
80
+ title: 'Document Title',
81
+ showBackButton: true,
82
+ onAction: fn(),
83
+ onBack: fn(),
84
+ },
85
+ play: async ({ args, canvasElement }) => {
86
+ const canvas = within(canvasElement);
87
+
88
+ // Verify the banner renders with the correct title.
89
+ await expect(canvas.getByRole('banner')).toBeInTheDocument();
90
+ await expect(canvas.getByText('Document Title')).toBeInTheDocument();
91
+
92
+ // Test back button click.
93
+ const backButton = canvas.getByRole('button', { name: /back/i });
94
+ await expect(backButton).toBeInTheDocument();
95
+ await userEvent.click(backButton);
96
+ await expect(args.onBack).toHaveBeenCalledTimes(1);
97
+
98
+ // Test actions menu opens and action fires.
99
+ const menuTrigger = canvas.getByRole('button', { name: /actions/i });
100
+ await expect(menuTrigger).toBeInTheDocument();
101
+ await userEvent.click(menuTrigger);
102
+
103
+ // Wait for menu to open and click an action (menu items render in a portal).
104
+ const editAction = await screen.findByRole('menuitem', { name: /edit/i });
105
+ await userEvent.click(editAction);
106
+ await expect(args.onAction).toHaveBeenCalledTimes(1);
107
+ await expect((args.onAction as Mock).mock.calls[0][0]).toHaveProperty('id', 'action-edit');
108
+ },
109
+ };
110
+
111
+ export const NoBackButton: Story = {
112
+ args: {
113
+ actions: buildDefaultActions(),
114
+ title: 'Home',
115
+ showBackButton: false,
116
+ onAction: (action) => console.log('Action:', action.id),
117
+ },
118
+ };
119
+
120
+ export const LongTitle: Story = {
121
+ args: {
122
+ actions: buildDefaultActions(),
123
+ title: 'This is a very long document title that should be truncated when it exceeds the available space',
124
+ showBackButton: true,
125
+ onBack: () => console.log('Back clicked'),
126
+ onAction: (action) => console.log('Action:', action.id),
127
+ },
128
+ };
129
+
130
+ export const NoActions: Story = {
131
+ args: {
132
+ actions: buildEmptyActions(),
133
+ title: 'Empty Document',
134
+ showBackButton: true,
135
+ onBack: () => console.log('Back clicked'),
136
+ onAction: (action) => console.log('Action:', action.id),
137
+ },
138
+ };
139
+
140
+ export const Empty: Story = {
141
+ args: {
142
+ actions: buildEmptyActions(),
143
+ },
144
+ };
@@ -0,0 +1,97 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { type Atom, useAtomValue } from '@effect-atom/atom-react';
6
+ import React, { Fragment } from 'react';
7
+
8
+ import { IconButton, Popover, type ThemedClassName, Toolbar, useTranslation } from '@dxos/react-ui';
9
+ import {
10
+ type ActionExecutor,
11
+ type ActionGraphProps,
12
+ DropdownMenu,
13
+ MenuProvider,
14
+ useMenuActions,
15
+ } from '@dxos/react-ui-menu';
16
+ import { mx, osTranslations } from '@dxos/ui-theme';
17
+
18
+ import { meta } from '../../meta';
19
+ import { useMobileLayout } from '../MobileLayout';
20
+
21
+ const APP_BAR_NAME = 'SimpleLayout.AppBar';
22
+
23
+ export type AppBarProps = ThemedClassName<{
24
+ /** Title/label to display in the banner. */
25
+ title?: string;
26
+ /** Action graph atom for the dropdown menu. */
27
+ actions: Atom.Atom<ActionGraphProps>;
28
+ /** Whether to show the back button. */
29
+ showBackButton?: boolean;
30
+ /** Popover anchor ID for the dropdown trigger. */
31
+ popoverAnchorId?: string;
32
+ /** Action executor callback. */
33
+ onAction?: ActionExecutor;
34
+ /** Callback when back button is clicked. */
35
+ onBack?: () => void;
36
+ }>;
37
+
38
+ /**
39
+ * AppBar component that renders a title, optional back button, and actions dropdown.
40
+ */
41
+ export const AppBar = ({
42
+ classNames,
43
+ title,
44
+ actions,
45
+ showBackButton,
46
+ popoverAnchorId,
47
+ onAction,
48
+ onBack,
49
+ }: AppBarProps) => {
50
+ const { t } = useTranslation(meta.id);
51
+ const menu = useMenuActions(actions);
52
+ const actionsValue = useAtomValue(actions);
53
+ const hasActions = actionsValue.nodes.length > 0;
54
+ const { keyboardOpen } = useMobileLayout(APP_BAR_NAME);
55
+
56
+ // Fall back to app name if no title provided.
57
+ const displayTitle = title ?? t('current app name', { ns: osTranslations });
58
+
59
+ // Wrap the menu trigger with Popover.Anchor when the popoverAnchorId is set.
60
+ const AnchorRoot = popoverAnchorId ? Popover.Anchor : Fragment;
61
+
62
+ return (
63
+ <Toolbar.Root
64
+ role='banner'
65
+ classNames={mx('grid grid-cols-[var(--rail-size)_1fr_var(--rail-size)] items-center', 'density-fine', classNames)}
66
+ >
67
+ {keyboardOpen ? (
68
+ <IconButton variant='ghost' icon='ph--x--regular' iconOnly label={t('done label')} />
69
+ ) : showBackButton ? (
70
+ <IconButton variant='ghost' icon='ph--caret-left--regular' iconOnly label={t('back label')} onClick={onBack} />
71
+ ) : (
72
+ <div />
73
+ )}
74
+ <h1 className='text-center truncate font-thin uppercase'>{displayTitle}</h1>
75
+ {hasActions ? (
76
+ <AnchorRoot>
77
+ <MenuProvider {...menu} onAction={onAction}>
78
+ <DropdownMenu.Root caller={meta.id}>
79
+ <DropdownMenu.Trigger asChild>
80
+ <IconButton
81
+ variant='ghost'
82
+ icon='ph--dots-three-vertical--regular'
83
+ iconOnly
84
+ label={t('actions menu label')}
85
+ />
86
+ </DropdownMenu.Trigger>
87
+ </DropdownMenu.Root>
88
+ </MenuProvider>
89
+ </AnchorRoot>
90
+ ) : (
91
+ <span />
92
+ )}
93
+ </Toolbar.Root>
94
+ );
95
+ };
96
+
97
+ AppBar.displayName = APP_BAR_NAME;
@@ -0,0 +1,102 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import React, { useMemo } from 'react';
6
+
7
+ import { Surface } from '@dxos/app-framework/ui';
8
+ import { useAppGraph } from '@dxos/app-toolkit/ui';
9
+ import { type Node, useNode } from '@dxos/plugin-graph';
10
+ import { Layout } from '@dxos/react-ui';
11
+ import { ATTENDABLE_PATH_SEPARATOR } from '@dxos/react-ui-attention';
12
+ import { MenuProvider, ToolbarMenu, useMenuActions } from '@dxos/react-ui-menu';
13
+
14
+ import { useCompanions, useDrawerActions, useSimpleLayoutState } from '../../hooks';
15
+ import { ContentError } from '../ContentError';
16
+ import { ContentLoading } from '../ContentLoading';
17
+
18
+ const DRAWER_NAME = 'SimpleLayout.Drawer';
19
+
20
+ /**
21
+ * Companion drawer component.
22
+ */
23
+ export const Drawer = () => {
24
+ const { graph } = useAppGraph();
25
+ const { state: layoutState } = useSimpleLayoutState();
26
+
27
+ const placeholder = useMemo(() => <ContentLoading />, []);
28
+
29
+ // Get all companions for the current active (primary) item.
30
+ const activeId = layoutState.active ?? layoutState.workspace;
31
+ const companions = useCompanions(activeId);
32
+ const { companionId, variant } = useSelectedCompanion(companions, layoutState.companionVariant);
33
+
34
+ // Get node for the selected companion.
35
+ const node = useNode(graph, companionId);
36
+ const parentNode = useNode(graph, activeId);
37
+
38
+ // Build Surface data for the companion content.
39
+ const data = useMemo(() => {
40
+ return (
41
+ node && {
42
+ attendableId: companionId,
43
+ subject: node.data,
44
+ companionTo: parentNode?.data,
45
+ properties: node.properties,
46
+ variant,
47
+ }
48
+ );
49
+ }, [companionId, node, parentNode, variant]);
50
+
51
+ // Get drawer actions (tabs + toolbar buttons).
52
+ const { actions, onAction } = useDrawerActions(DRAWER_NAME);
53
+ const menu = useMenuActions(actions);
54
+
55
+ return (
56
+ <Layout.Main toolbar>
57
+ <MenuProvider {...menu} onAction={onAction} alwaysActive>
58
+ <ToolbarMenu density='coarse' />
59
+ </MenuProvider>
60
+ <Surface.Surface role='article' data={data} limit={1} fallback={ContentError} placeholder={placeholder} />
61
+ </Layout.Main>
62
+ );
63
+ };
64
+
65
+ Drawer.displayName = DRAWER_NAME;
66
+
67
+ /** Parse entry ID to extract primary ID and variant. */
68
+ const parseEntryId = (entryId: string) => {
69
+ const [id, variant] = entryId.split(ATTENDABLE_PATH_SEPARATOR);
70
+ return { id, variant };
71
+ };
72
+
73
+ /**
74
+ * Resolves which companion to show based on variant preference.
75
+ * Falls back to first available if preferred variant not available.
76
+ */
77
+ const useSelectedCompanion = (companions: Node.Node[], preferredVariant?: string) => {
78
+ const selectedCompanion = useMemo(() => {
79
+ if (companions.length === 0) {
80
+ return undefined;
81
+ }
82
+
83
+ // Try to find companion matching the preferred variant.
84
+ if (preferredVariant) {
85
+ const preferred = companions.find((c) => {
86
+ const { variant } = parseEntryId(c.id);
87
+ return variant === preferredVariant;
88
+ });
89
+ if (preferred) {
90
+ return preferred;
91
+ }
92
+ }
93
+
94
+ // Fallback to first companion.
95
+ return companions[0];
96
+ }, [companions, preferredVariant]);
97
+
98
+ const companionId = selectedCompanion?.id;
99
+ const { variant } = parseEntryId(companionId ?? '');
100
+
101
+ return { selectedCompanion, companionId, variant };
102
+ };
@@ -2,80 +2,80 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import React, { useCallback, useMemo } from 'react';
5
+ import React, { useMemo } from 'react';
6
6
 
7
- import { Surface, useAppGraph } from '@dxos/app-framework/react';
8
- import { log } from '@dxos/log';
7
+ import { Surface } from '@dxos/app-framework/ui';
8
+ import { useAppGraph } from '@dxos/app-toolkit/ui';
9
9
  import { useNode } from '@dxos/plugin-graph';
10
- import { Main as NaturalMain } from '@dxos/react-ui';
11
- import { ATTENDABLE_PATH_SEPARATOR } from '@dxos/react-ui-attention';
12
- import { Mosaic } from '@dxos/react-ui-mosaic';
10
+ import { useAttentionAttributes } from '@dxos/react-ui-attention';
13
11
  import { mx } from '@dxos/ui-theme';
14
12
 
15
- import { useSimpleLayoutState } from '../../hooks';
13
+ import { useAppBarProps, useNavbarActions, useSimpleLayoutState } from '../../hooks';
16
14
  import { ContentError } from '../ContentError';
17
15
  import { ContentLoading } from '../ContentLoading';
16
+ import { useLoadDescendents } from '../hooks';
17
+ import { useMobileLayout } from '../MobileLayout/MobileLayout';
18
18
 
19
- import { Banner } from './Banner';
19
+ import { AppBar } from './AppBar';
20
20
  import { NavBar } from './NavBar';
21
21
 
22
+ const MAIN_NAME = 'SimpleLayout.Main';
23
+
22
24
  /**
23
- * Main root component.
25
+ * Main content component.
24
26
  */
25
27
  export const Main = () => {
26
28
  const { state } = useSimpleLayoutState();
27
29
  const id = state.active ?? state.workspace;
28
- const showNavBar = !state.isPopover;
29
- const { graph } = useAppGraph();
30
- const node = useNode(graph, id);
30
+ const attentionAttrs = useAttentionAttributes(id);
31
+ const { keyboardOpen } = useMobileLayout(MAIN_NAME);
32
+ const { actions, onAction } = useNavbarActions();
33
+ const appBarProps = useAppBarProps();
31
34
 
32
35
  const placeholder = useMemo(() => <ContentLoading />, []);
33
36
 
37
+ const { graph } = useAppGraph();
38
+ const node = useNode(graph, id);
34
39
  const data = useMemo(() => {
35
- const { variant } = parseEntryId(id);
36
40
  return (
37
41
  node && {
38
42
  attendableId: id,
39
43
  subject: node.data,
40
44
  properties: node.properties,
41
45
  popoverAnchorId: state.popoverAnchorId,
42
- variant,
43
46
  }
44
47
  );
45
48
  }, [id, node, node?.data, node?.properties, state.popoverAnchorId]);
46
49
 
47
- const handleActiveIdChange = useCallback((nextActiveId: string | null) => {
48
- log.info('navigate', { nextActiveId });
49
- }, []);
50
+ // Ensures that children are loaded so that they are available to navigate to.
51
+ useLoadDescendents(id);
52
+
53
+ // TODO(burdon): BUG: When showing ANY statusbar the size progressively shrinks when the keyboard opens/closes.
54
+ const showNavBar = !keyboardOpen && !state.isPopover && state.drawerState === 'closed';
50
55
 
51
56
  return (
52
- <Mosaic.Root>
53
- <NaturalMain.Root complementarySidebarState='closed' navigationSidebarState='closed'>
54
- <NaturalMain.Content
55
- bounce
56
- classNames={mx(
57
- 'dx-mobile-main dx-mobile-main-scroll-area--flush',
58
- 'grid bs-full overflow-hidden',
59
- showNavBar ? 'grid-rows-[min-content_1fr_min-content]' : 'grid-rows-[min-content_1fr]',
60
- )}
61
- >
62
- <Banner classNames='border-be border-separator' node={node} />
63
- <article className='contents'>
64
- <Surface key={id} role='article' data={data} limit={1} fallback={ContentError} placeholder={placeholder} />
65
- </article>
66
- {showNavBar && (
67
- <NavBar classNames='border-bs border-separator' activeId={id} onActiveIdChange={handleActiveIdChange} />
68
- )}
69
- </NaturalMain.Content>
70
- </NaturalMain.Root>
71
- </Mosaic.Root>
57
+ <div
58
+ role='none'
59
+ className={mx(
60
+ 'bs-full grid overflow-hidden bg-toolbarSurface',
61
+ showNavBar ? 'grid-rows-[var(--rail-action)_1fr_var(--toolbar-size)]' : 'grid-rows-[var(--rail-action)_1fr]',
62
+ )}
63
+ {...attentionAttrs}
64
+ >
65
+ <AppBar {...appBarProps} />
66
+ <article className='bs-full overflow-hidden bg-baseSurface'>
67
+ <Surface.Surface
68
+ key={id}
69
+ role='article'
70
+ data={data}
71
+ limit={1}
72
+ fallback={ContentError}
73
+ placeholder={placeholder}
74
+ />
75
+ </article>
76
+ {showNavBar && <NavBar classNames='border-bs border-subduedSeparator' actions={actions} onAction={onAction} />}
77
+ </div>
72
78
  );
73
79
  };
74
80
 
75
- // TODO(wittjosiah): Factor out. Copied from deck plugin.
76
- const parseEntryId = (entryId: string) => {
77
- const [id, variant] = entryId.split(ATTENDABLE_PATH_SEPARATOR);
78
- return { id, variant };
79
- };
80
-
81
- Main.displayName = 'SimpleLayout.Main';
81
+ Main.displayName = MAIN_NAME;
@@ -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 { withPluginManager } from '@dxos/app-framework/testing';
8
- import { corePlugins } from '@dxos/plugin-testing';
9
10
  import { 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 })));
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 })),
85
+ ...gapSeparator.edges,
86
+ { source: 'root', target: mainMenuGroup.id },
87
+ ...menuActions.map((action) => ({ source: MAIN_MENU_GROUP_ID, target: action.id })),
88
+ );
89
+ return result;
90
+ };
91
+
15
92
  const meta = {
16
93
  title: 'plugins/plugin-simple-layout/NavBar',
17
94
  component: NavBar,
18
- decorators: [
19
- withTheme,
20
- withPluginManager({
21
- plugins: [...corePlugins()],
22
- }),
23
- ],
95
+ decorators: [withTheme(), 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-bs border-separator' actions={actions} onAction={onAction} />;
110
+ };
111
+
37
112
  export const Default: Story = {
113
+ tags: ['test'],
38
114
  args: {
39
- activeId: undefined,
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
- export const BrowseActive: Story = {
44
- args: {
45
- activeId: 'some-document',
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 NotificationsActive: Story = {
50
- args: {
51
- activeId: 'notifications',
52
- },
150
+ export const CompanionsOnly: Story = {
151
+ args: {} as any,
152
+ render: () => <CompanionsOnlyStory />,
53
153
  };
54
154
 
55
- export const ProfileActive: Story = {
56
- args: {
57
- activeId: 'profile',
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
  };