@dxos/plugin-simple-layout 0.8.4-main.69d29f4 → 0.8.4-main.74a063c4e0

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 (247) hide show
  1. package/dist/lib/browser/index.mjs +44 -58
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +44 -57
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/SimpleLayoutPlugin.d.ts +1 -1
  8. package/dist/types/src/SimpleLayoutPlugin.d.ts.map +1 -1
  9. package/dist/types/src/capabilities/app-graph-builder.d.ts +6 -0
  10. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -0
  11. package/dist/types/src/capabilities/index.d.ts +21 -6
  12. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  13. package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
  14. package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
  15. package/dist/types/src/capabilities/{react-root/react-root.d.ts → react-root.d.ts} +1 -1
  16. package/dist/types/src/capabilities/react-root.d.ts.map +1 -0
  17. package/dist/types/src/capabilities/react-surface.d.ts +5 -0
  18. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
  19. package/dist/types/src/capabilities/{spotlight-dismiss/spotlight-dismiss.d.ts → spotlight-dismiss.d.ts} +1 -1
  20. package/dist/types/src/capabilities/spotlight-dismiss.d.ts.map +1 -0
  21. package/dist/types/src/capabilities/{state/state.d.ts → state.d.ts} +2 -2
  22. package/dist/types/src/capabilities/state.d.ts.map +1 -0
  23. package/dist/types/src/capabilities/url-handler.d.ts +12 -0
  24. package/dist/types/src/capabilities/url-handler.d.ts.map +1 -0
  25. package/dist/types/src/components/ContentError.stories.d.ts +26 -15
  26. package/dist/types/src/components/ContentError.stories.d.ts.map +1 -1
  27. package/dist/types/src/components/DebugOverlay/DebugOverlay.d.ts +19 -0
  28. package/dist/types/src/components/DebugOverlay/DebugOverlay.d.ts.map +1 -0
  29. package/dist/types/src/components/DebugOverlay/index.d.ts +2 -0
  30. package/dist/types/src/components/DebugOverlay/index.d.ts.map +1 -0
  31. package/dist/types/src/components/Home/Home.d.ts.map +1 -1
  32. package/dist/types/src/components/Loading/Loading.d.ts +3 -0
  33. package/dist/types/src/components/Loading/Loading.d.ts.map +1 -0
  34. package/dist/types/src/components/{ContentLoading.stories.d.ts → Loading/Loading.stories.d.ts} +1 -1
  35. package/dist/types/src/components/Loading/Loading.stories.d.ts.map +1 -0
  36. package/dist/types/src/components/Loading/index.d.ts +2 -0
  37. package/dist/types/src/components/Loading/index.d.ts.map +1 -0
  38. package/dist/types/src/components/MobileLayout/MobileLayout.d.ts +35 -0
  39. package/dist/types/src/components/MobileLayout/MobileLayout.d.ts.map +1 -0
  40. package/dist/types/src/components/MobileLayout/MobileLayout.stories.d.ts +7 -0
  41. package/dist/types/src/components/MobileLayout/MobileLayout.stories.d.ts.map +1 -0
  42. package/dist/types/src/components/MobileLayout/index.d.ts +2 -0
  43. package/dist/types/src/components/MobileLayout/index.d.ts.map +1 -0
  44. package/dist/types/src/components/NavBranch/NavBranch.d.ts +11 -0
  45. package/dist/types/src/components/NavBranch/NavBranch.d.ts.map +1 -0
  46. package/dist/types/src/components/NavBranch/index.d.ts +2 -0
  47. package/dist/types/src/components/NavBranch/index.d.ts.map +1 -0
  48. package/dist/types/src/components/Popover/Popover.d.ts.map +1 -1
  49. package/dist/types/src/components/SimpleLayout/AppBar.d.ts +28 -0
  50. package/dist/types/src/components/SimpleLayout/AppBar.d.ts.map +1 -0
  51. package/dist/types/src/components/SimpleLayout/AppBar.stories.d.ts +54 -0
  52. package/dist/types/src/components/SimpleLayout/AppBar.stories.d.ts.map +1 -0
  53. package/dist/types/src/components/SimpleLayout/Drawer.d.ts +9 -0
  54. package/dist/types/src/components/SimpleLayout/Drawer.d.ts.map +1 -0
  55. package/dist/types/src/components/SimpleLayout/Main.d.ts +1 -1
  56. package/dist/types/src/components/SimpleLayout/Main.d.ts.map +1 -1
  57. package/dist/types/src/components/SimpleLayout/NavBar.d.ts +18 -6
  58. package/dist/types/src/components/SimpleLayout/NavBar.d.ts.map +1 -1
  59. package/dist/types/src/components/SimpleLayout/NavBar.stories.d.ts +35 -21
  60. package/dist/types/src/components/SimpleLayout/NavBar.stories.d.ts.map +1 -1
  61. package/dist/types/src/components/SimpleLayout/SimpleLayout.d.ts.map +1 -1
  62. package/dist/types/src/components/SimpleLayout/SimpleLayout.stories.d.ts +26 -15
  63. package/dist/types/src/components/SimpleLayout/SimpleLayout.stories.d.ts.map +1 -1
  64. package/dist/types/src/components/SimpleLayout/index.d.ts +3 -0
  65. package/dist/types/src/components/SimpleLayout/index.d.ts.map +1 -1
  66. package/dist/types/src/components/hooks.d.ts +4 -2
  67. package/dist/types/src/components/hooks.d.ts.map +1 -1
  68. package/dist/types/src/components/index.d.ts +4 -2
  69. package/dist/types/src/components/index.d.ts.map +1 -1
  70. package/dist/types/src/hooks/actions.d.ts +19 -0
  71. package/dist/types/src/hooks/actions.d.ts.map +1 -0
  72. package/dist/types/src/hooks/index.d.ts +5 -0
  73. package/dist/types/src/hooks/index.d.ts.map +1 -1
  74. package/dist/types/src/hooks/useAppBarProps.d.ts +7 -0
  75. package/dist/types/src/hooks/useAppBarProps.d.ts.map +1 -0
  76. package/dist/types/src/hooks/useCompanions.d.ts +12 -0
  77. package/dist/types/src/hooks/useCompanions.d.ts.map +1 -0
  78. package/dist/types/src/hooks/useDrawerActions.d.ts +13 -0
  79. package/dist/types/src/hooks/useDrawerActions.d.ts.map +1 -0
  80. package/dist/types/src/hooks/useNavbarActions.d.ts +14 -0
  81. package/dist/types/src/hooks/useNavbarActions.d.ts.map +1 -0
  82. package/dist/types/src/hooks/useSimpleLayoutState.d.ts +3 -3
  83. package/dist/types/src/hooks/useSimpleLayoutState.d.ts.map +1 -1
  84. package/dist/types/src/operations/close.d.ts +5 -0
  85. package/dist/types/src/operations/close.d.ts.map +1 -0
  86. package/dist/types/src/operations/index.d.ts +3 -0
  87. package/dist/types/src/operations/index.d.ts.map +1 -0
  88. package/dist/types/src/operations/open.d.ts +5 -0
  89. package/dist/types/src/operations/open.d.ts.map +1 -0
  90. package/dist/types/src/operations/revert-workspace.d.ts +5 -0
  91. package/dist/types/src/operations/revert-workspace.d.ts.map +1 -0
  92. package/dist/types/src/operations/set-layout-mode.d.ts +5 -0
  93. package/dist/types/src/operations/set-layout-mode.d.ts.map +1 -0
  94. package/dist/types/src/operations/set.d.ts +5 -0
  95. package/dist/types/src/operations/set.d.ts.map +1 -0
  96. package/dist/types/src/operations/state-access.d.ts +8 -0
  97. package/dist/types/src/operations/state-access.d.ts.map +1 -0
  98. package/dist/types/src/operations/switch-workspace.d.ts +5 -0
  99. package/dist/types/src/operations/switch-workspace.d.ts.map +1 -0
  100. package/dist/types/src/operations/update-complementary.d.ts +5 -0
  101. package/dist/types/src/operations/update-complementary.d.ts.map +1 -0
  102. package/dist/types/src/operations/update-dialog.d.ts +5 -0
  103. package/dist/types/src/operations/update-dialog.d.ts.map +1 -0
  104. package/dist/types/src/operations/update-popover.d.ts +5 -0
  105. package/dist/types/src/operations/update-popover.d.ts.map +1 -0
  106. package/dist/types/src/operations/update-sidebar.d.ts +5 -0
  107. package/dist/types/src/operations/update-sidebar.d.ts.map +1 -0
  108. package/dist/types/src/translations.d.ts +26 -13
  109. package/dist/types/src/translations.d.ts.map +1 -1
  110. package/dist/types/src/types/capabilities.d.ts +18 -5
  111. package/dist/types/src/types/capabilities.d.ts.map +1 -1
  112. package/dist/types/src/types/events.d.ts.map +1 -1
  113. package/dist/types/tsconfig.tsbuildinfo +1 -1
  114. package/package.json +46 -30
  115. package/src/SimpleLayoutPlugin.ts +24 -13
  116. package/src/capabilities/app-graph-builder.ts +21 -0
  117. package/src/capabilities/index.ts +13 -6
  118. package/src/capabilities/operation-handler.ts +14 -0
  119. package/src/capabilities/{react-root/react-root.tsx → react-root.tsx} +4 -4
  120. package/src/capabilities/react-surface.tsx +50 -0
  121. package/src/capabilities/{spotlight-dismiss/spotlight-dismiss.ts → spotlight-dismiss.ts} +2 -2
  122. package/src/capabilities/{state/state.tsx → state.tsx} +8 -5
  123. package/src/capabilities/url-handler.ts +161 -0
  124. package/src/components/ContentError.stories.tsx +8 -7
  125. package/src/components/DebugOverlay/DebugOverlay.tsx +96 -0
  126. package/src/components/DebugOverlay/index.ts +5 -0
  127. package/src/components/Dialog/Dialog.tsx +6 -6
  128. package/src/components/Home/Home.tsx +51 -43
  129. package/src/components/{ContentLoading.stories.tsx → Loading/Loading.stories.tsx} +5 -5
  130. package/src/components/{ContentLoading.tsx → Loading/Loading.tsx} +2 -2
  131. package/src/components/Loading/index.ts +5 -0
  132. package/src/components/MobileLayout/MobileLayout.stories.tsx +133 -0
  133. package/src/components/MobileLayout/MobileLayout.tsx +374 -0
  134. package/src/components/MobileLayout/index.ts +5 -0
  135. package/src/components/NavBranch/NavBranch.tsx +128 -0
  136. package/src/components/{Workspace → NavBranch}/index.ts +1 -1
  137. package/src/components/Popover/Popover.tsx +10 -9
  138. package/src/components/SimpleLayout/AppBar.stories.tsx +143 -0
  139. package/src/components/SimpleLayout/AppBar.tsx +94 -0
  140. package/src/components/SimpleLayout/Drawer.tsx +98 -0
  141. package/src/components/SimpleLayout/Main.tsx +45 -48
  142. package/src/components/SimpleLayout/NavBar.stories.tsx +131 -27
  143. package/src/components/SimpleLayout/NavBar.tsx +21 -62
  144. package/src/components/SimpleLayout/SimpleLayout.stories.tsx +45 -55
  145. package/src/components/SimpleLayout/SimpleLayout.tsx +45 -7
  146. package/src/components/SimpleLayout/index.ts +3 -0
  147. package/src/components/hooks.ts +10 -14
  148. package/src/components/index.ts +4 -2
  149. package/src/hooks/actions.ts +84 -0
  150. package/src/hooks/index.ts +5 -0
  151. package/src/hooks/useAppBarProps.ts +115 -0
  152. package/src/hooks/useCompanions.ts +22 -0
  153. package/src/hooks/useDrawerActions.ts +100 -0
  154. package/src/hooks/useNavbarActions.ts +87 -0
  155. package/src/hooks/useSimpleLayoutState.ts +5 -5
  156. package/src/meta.ts +1 -1
  157. package/src/operations/close.ts +34 -0
  158. package/src/operations/index.ts +16 -0
  159. package/src/operations/open.ts +63 -0
  160. package/src/operations/revert-workspace.ts +22 -0
  161. package/src/operations/set-layout-mode.ts +12 -0
  162. package/src/operations/set.ts +23 -0
  163. package/src/operations/state-access.ts +19 -0
  164. package/src/operations/switch-workspace.ts +26 -0
  165. package/src/operations/update-complementary.ts +35 -0
  166. package/src/operations/update-dialog.ts +28 -0
  167. package/src/operations/update-popover.ts +35 -0
  168. package/src/operations/update-sidebar.ts +12 -0
  169. package/src/translations.ts +21 -13
  170. package/src/types/capabilities.ts +16 -7
  171. package/src/types/events.ts +3 -2
  172. package/dist/lib/browser/chunk-CLPGTNWJ.mjs +0 -29
  173. package/dist/lib/browser/chunk-CLPGTNWJ.mjs.map +0 -7
  174. package/dist/lib/browser/chunk-FK4M7GJV.mjs +0 -613
  175. package/dist/lib/browser/chunk-FK4M7GJV.mjs.map +0 -7
  176. package/dist/lib/browser/operation-resolver-LTB63NKP.mjs +0 -168
  177. package/dist/lib/browser/operation-resolver-LTB63NKP.mjs.map +0 -7
  178. package/dist/lib/browser/react-root-6ARAPH3O.mjs +0 -21
  179. package/dist/lib/browser/react-root-6ARAPH3O.mjs.map +0 -7
  180. package/dist/lib/browser/react-surface-SO7B23GS.mjs +0 -39
  181. package/dist/lib/browser/react-surface-SO7B23GS.mjs.map +0 -7
  182. package/dist/lib/browser/spotlight-dismiss-VSNOPETH.mjs +0 -66
  183. package/dist/lib/browser/spotlight-dismiss-VSNOPETH.mjs.map +0 -7
  184. package/dist/lib/browser/state-H4IGICBB.mjs +0 -45
  185. package/dist/lib/browser/state-H4IGICBB.mjs.map +0 -7
  186. package/dist/lib/browser/url-handler-7CFGTLNG.mjs +0 -54
  187. package/dist/lib/browser/url-handler-7CFGTLNG.mjs.map +0 -7
  188. package/dist/lib/node-esm/chunk-EGFZAVBD.mjs +0 -614
  189. package/dist/lib/node-esm/chunk-EGFZAVBD.mjs.map +0 -7
  190. package/dist/lib/node-esm/chunk-MUVVYBUE.mjs +0 -31
  191. package/dist/lib/node-esm/chunk-MUVVYBUE.mjs.map +0 -7
  192. package/dist/lib/node-esm/operation-resolver-7O6O7T4Q.mjs +0 -169
  193. package/dist/lib/node-esm/operation-resolver-7O6O7T4Q.mjs.map +0 -7
  194. package/dist/lib/node-esm/react-root-2CPA2ZUS.mjs +0 -22
  195. package/dist/lib/node-esm/react-root-2CPA2ZUS.mjs.map +0 -7
  196. package/dist/lib/node-esm/react-surface-FKAV56MO.mjs +0 -40
  197. package/dist/lib/node-esm/react-surface-FKAV56MO.mjs.map +0 -7
  198. package/dist/lib/node-esm/spotlight-dismiss-L5PCWIJG.mjs +0 -68
  199. package/dist/lib/node-esm/spotlight-dismiss-L5PCWIJG.mjs.map +0 -7
  200. package/dist/lib/node-esm/state-QIU2LMLT.mjs +0 -46
  201. package/dist/lib/node-esm/state-QIU2LMLT.mjs.map +0 -7
  202. package/dist/lib/node-esm/url-handler-4LYP3JM7.mjs +0 -55
  203. package/dist/lib/node-esm/url-handler-4LYP3JM7.mjs.map +0 -7
  204. package/dist/types/src/capabilities/operation-resolver/index.d.ts +0 -3
  205. package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +0 -1
  206. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +0 -5
  207. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +0 -1
  208. package/dist/types/src/capabilities/react-root/index.d.ts +0 -6
  209. package/dist/types/src/capabilities/react-root/index.d.ts.map +0 -1
  210. package/dist/types/src/capabilities/react-root/react-root.d.ts.map +0 -1
  211. package/dist/types/src/capabilities/react-surface/index.d.ts +0 -3
  212. package/dist/types/src/capabilities/react-surface/index.d.ts.map +0 -1
  213. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +0 -5
  214. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +0 -1
  215. package/dist/types/src/capabilities/spotlight-dismiss/index.d.ts +0 -3
  216. package/dist/types/src/capabilities/spotlight-dismiss/index.d.ts.map +0 -1
  217. package/dist/types/src/capabilities/spotlight-dismiss/spotlight-dismiss.d.ts.map +0 -1
  218. package/dist/types/src/capabilities/state/index.d.ts +0 -13
  219. package/dist/types/src/capabilities/state/index.d.ts.map +0 -1
  220. package/dist/types/src/capabilities/state/state.d.ts.map +0 -1
  221. package/dist/types/src/capabilities/url-handler/index.d.ts +0 -3
  222. package/dist/types/src/capabilities/url-handler/index.d.ts.map +0 -1
  223. package/dist/types/src/capabilities/url-handler/url-handler.d.ts +0 -10
  224. package/dist/types/src/capabilities/url-handler/url-handler.d.ts.map +0 -1
  225. package/dist/types/src/components/ContentError.d.ts +0 -5
  226. package/dist/types/src/components/ContentError.d.ts.map +0 -1
  227. package/dist/types/src/components/ContentLoading.d.ts +0 -3
  228. package/dist/types/src/components/ContentLoading.d.ts.map +0 -1
  229. package/dist/types/src/components/ContentLoading.stories.d.ts.map +0 -1
  230. package/dist/types/src/components/SimpleLayout/Banner.d.ts +0 -8
  231. package/dist/types/src/components/SimpleLayout/Banner.d.ts.map +0 -1
  232. package/dist/types/src/components/Workspace/Workspace.d.ts +0 -9
  233. package/dist/types/src/components/Workspace/Workspace.d.ts.map +0 -1
  234. package/dist/types/src/components/Workspace/index.d.ts +0 -2
  235. package/dist/types/src/components/Workspace/index.d.ts.map +0 -1
  236. package/src/capabilities/operation-resolver/index.ts +0 -10
  237. package/src/capabilities/operation-resolver/operation-resolver.ts +0 -178
  238. package/src/capabilities/react-root/index.ts +0 -7
  239. package/src/capabilities/react-surface/index.ts +0 -7
  240. package/src/capabilities/react-surface/react-surface.tsx +0 -40
  241. package/src/capabilities/spotlight-dismiss/index.ts +0 -7
  242. package/src/capabilities/state/index.ts +0 -9
  243. package/src/capabilities/url-handler/index.ts +0 -7
  244. package/src/capabilities/url-handler/url-handler.ts +0 -80
  245. package/src/components/ContentError.tsx +0 -23
  246. package/src/components/SimpleLayout/Banner.tsx +0 -82
  247. package/src/components/Workspace/Workspace.tsx +0 -115
@@ -0,0 +1,143 @@
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 { type ActionGraphProps, createMenuAction } from '@dxos/react-ui-menu';
11
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
12
+ import { withRegistry } from '@dxos/storybook-utils';
13
+
14
+ import { translations } from '../../translations';
15
+ import { MobileLayout } from '../MobileLayout';
16
+ import { AppBar, type AppBarProps } from './AppBar';
17
+
18
+ const buildEmptyActions = (): ActionGraphProps => ({ nodes: [], edges: [] });
19
+
20
+ const buildDefaultActions = (): ActionGraphProps => {
21
+ const result: ActionGraphProps = { nodes: [], edges: [] };
22
+ const actions = [
23
+ createMenuAction('action-edit.menu', () => console.log('Edit'), {
24
+ icon: 'ph--pencil--regular',
25
+ label: 'Edit',
26
+ }),
27
+ createMenuAction('action-share.menu', () => console.log('Share'), {
28
+ icon: 'ph--share--regular',
29
+ label: 'Share',
30
+ }),
31
+ createMenuAction('action-delete.menu', () => console.log('Delete'), {
32
+ icon: 'ph--trash--regular',
33
+ label: 'Delete',
34
+ }),
35
+ ];
36
+ result.nodes.push(...actions);
37
+ result.edges.push(...actions.map((a) => ({ source: 'root', target: a.id, relation: 'child' })));
38
+ return result;
39
+ };
40
+
41
+ type DefaultStoryProps = Omit<AppBarProps, 'actions'> & {
42
+ actions: ActionGraphProps;
43
+ };
44
+
45
+ const DefaultStory = ({ actions: actionsProp, ...props }: DefaultStoryProps) => {
46
+ const actions = useMemo(() => Atom.make(actionsProp).pipe(Atom.keepAlive), [actionsProp]);
47
+ return (
48
+ <MobileLayout.Root>
49
+ <AppBar {...props} actions={actions} />
50
+ </MobileLayout.Root>
51
+ );
52
+ };
53
+
54
+ const meta = {
55
+ title: 'plugins/plugin-simple-layout/components/AppBar',
56
+ render: DefaultStory,
57
+ decorators: [
58
+ withTheme(),
59
+ withLayout({
60
+ layout: 'column',
61
+ classNames: 'relative',
62
+ }),
63
+ withRegistry,
64
+ ],
65
+ parameters: {
66
+ layout: 'fullscreen',
67
+ translations,
68
+ },
69
+ } satisfies Meta<typeof DefaultStory>;
70
+
71
+ export default meta;
72
+
73
+ type Story = StoryObj<DefaultStoryProps>;
74
+
75
+ export const Default: Story = {
76
+ tags: ['test'],
77
+ args: {
78
+ actions: buildDefaultActions(),
79
+ title: 'Document Title',
80
+ showBackButton: true,
81
+ onAction: fn(),
82
+ onBack: fn(),
83
+ },
84
+ play: async ({ args, canvasElement }) => {
85
+ const canvas = within(canvasElement);
86
+
87
+ // Verify the banner renders with the correct title.
88
+ await expect(canvas.getByRole('banner')).toBeInTheDocument();
89
+ await expect(canvas.getByText('Document Title')).toBeInTheDocument();
90
+
91
+ // Test back button click.
92
+ const backButton = canvas.getByRole('button', { name: /back/i });
93
+ await expect(backButton).toBeInTheDocument();
94
+ await userEvent.click(backButton);
95
+ await expect(args.onBack).toHaveBeenCalledTimes(1);
96
+
97
+ // Test actions menu opens and action fires.
98
+ const menuTrigger = canvas.getByRole('button', { name: /actions/i });
99
+ await expect(menuTrigger).toBeInTheDocument();
100
+ await userEvent.click(menuTrigger);
101
+
102
+ // Wait for menu to open and click an action (menu items render in a portal).
103
+ const editAction = await screen.findByRole('menuitem', { name: /edit/i });
104
+ await userEvent.click(editAction);
105
+ await expect(args.onAction).toHaveBeenCalledTimes(1);
106
+ await expect((args.onAction as Mock).mock.calls[0][0]).toHaveProperty('id', 'action-edit.menu');
107
+ },
108
+ };
109
+
110
+ export const NoBackButton: Story = {
111
+ args: {
112
+ actions: buildDefaultActions(),
113
+ title: 'Home',
114
+ showBackButton: false,
115
+ onAction: (action) => console.log('Action:', action.id),
116
+ },
117
+ };
118
+
119
+ export const LongTitle: Story = {
120
+ args: {
121
+ actions: buildDefaultActions(),
122
+ title: 'This is a very long document title that should be truncated when it exceeds the available space',
123
+ showBackButton: true,
124
+ onBack: () => console.log('Back clicked'),
125
+ onAction: (action) => console.log('Action:', action.id),
126
+ },
127
+ };
128
+
129
+ export const NoActions: Story = {
130
+ args: {
131
+ actions: buildEmptyActions(),
132
+ title: 'Empty Document',
133
+ showBackButton: true,
134
+ onBack: () => console.log('Back clicked'),
135
+ onAction: (action) => console.log('Action:', action.id),
136
+ },
137
+ };
138
+
139
+ export const Empty: Story = {
140
+ args: {
141
+ actions: buildEmptyActions(),
142
+ },
143
+ };
@@ -0,0 +1,94 @@
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, Toolbar, useTranslation } from '@dxos/react-ui';
9
+ import { type ActionExecutor, type ActionGraphProps, Menu, useMenuActions } from '@dxos/react-ui-menu';
10
+ import { composable, composableProps, osTranslations } from '@dxos/ui-theme';
11
+
12
+ import { meta } from '#meta';
13
+
14
+ import { useMobileLayout } from '../MobileLayout';
15
+
16
+ const APP_BAR_NAME = 'SimpleLayout.AppBar';
17
+
18
+ export type AppBarProps = {
19
+ /** Title/label to display in the banner. */
20
+ title?: string;
21
+ /** Action graph atom for the dropdown menu. */
22
+ actions: Atom.Atom<ActionGraphProps>;
23
+ /** Whether to show the back button. */
24
+ showBackButton?: boolean;
25
+ /** Popover anchor ID for the dropdown trigger. */
26
+ popoverAnchorId?: string;
27
+ /** Action executor callback. */
28
+ onAction?: ActionExecutor;
29
+ /** Callback when back button is clicked. */
30
+ onBack?: () => void;
31
+ };
32
+
33
+ /**
34
+ * AppBar component that renders a title, optional back button, and actions dropdown.
35
+ */
36
+ export const AppBar = composable<HTMLDivElement, AppBarProps>(
37
+ ({ classNames, title, actions, showBackButton, popoverAnchorId, onAction, onBack, ...props }, forwardedRef) => {
38
+ const { t } = useTranslation(meta.id);
39
+ const menuActions = useMenuActions(actions);
40
+ const actionsValue = useAtomValue(actions);
41
+ const hasActions = actionsValue.nodes.length > 0;
42
+ const { keyboardOpen } = useMobileLayout(APP_BAR_NAME);
43
+
44
+ // Fall back to app name if no title provided.
45
+ const displayTitle = title ?? t('current-app.name', { ns: osTranslations });
46
+
47
+ // Wrap the menu trigger with Popover.Anchor when the popoverAnchorId is set.
48
+ const AnchorRoot = popoverAnchorId ? Popover.Anchor : Fragment;
49
+
50
+ return (
51
+ <Toolbar.Root
52
+ {...composableProps(props, {
53
+ role: 'banner',
54
+ classNames: 'grid grid-cols-[var(--dx-rail-size)_1fr_var(--dx-rail-size)] items-center dx-density-fine',
55
+ })}
56
+ ref={forwardedRef}
57
+ >
58
+ {keyboardOpen ? (
59
+ <IconButton variant='ghost' icon='ph--x--regular' iconOnly label={t('done.label')} />
60
+ ) : showBackButton ? (
61
+ <IconButton
62
+ variant='ghost'
63
+ icon='ph--caret-left--regular'
64
+ iconOnly
65
+ label={t('back.label')}
66
+ onClick={onBack}
67
+ />
68
+ ) : (
69
+ <div />
70
+ )}
71
+ <h1 className='text-center truncate font-thin uppercase'>{displayTitle}</h1>
72
+ {hasActions ? (
73
+ <AnchorRoot>
74
+ <Menu.Root {...menuActions} caller={meta.id} onAction={onAction}>
75
+ <Menu.Trigger asChild>
76
+ <IconButton
77
+ variant='ghost'
78
+ icon='ph--dots-three-vertical--regular'
79
+ iconOnly
80
+ label={t('actions-menu.label')}
81
+ />
82
+ </Menu.Trigger>
83
+ <Menu.Content />
84
+ </Menu.Root>
85
+ </AnchorRoot>
86
+ ) : (
87
+ <span />
88
+ )}
89
+ </Toolbar.Root>
90
+ );
91
+ },
92
+ );
93
+
94
+ AppBar.displayName = APP_BAR_NAME;
@@ -0,0 +1,98 @@
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 { type AppSurface, useAppGraph } from '@dxos/app-toolkit/ui';
9
+ import { type Node, useNode } from '@dxos/plugin-graph';
10
+ import { ErrorFallback, Panel } from '@dxos/react-ui';
11
+ import { getLinkedVariant } from '@dxos/react-ui-attention';
12
+ import { Menu, useMenuActions } from '@dxos/react-ui-menu';
13
+
14
+ import { useCompanions, useDrawerActions, useSimpleLayoutState } from '#hooks';
15
+
16
+ import { Loading } from '../Loading';
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(() => <Loading />, []);
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<AppSurface.ArticleData | undefined>(() => {
40
+ if (!node || !companionId) {
41
+ return undefined;
42
+ }
43
+ return {
44
+ attendableId: companionId,
45
+ subject: node.data,
46
+ companionTo: parentNode?.data,
47
+ properties: node.properties,
48
+ variant,
49
+ };
50
+ }, [companionId, node, parentNode, variant]);
51
+
52
+ // Get drawer actions (tabs + toolbar buttons).
53
+ const { actions, onAction } = useDrawerActions(DRAWER_NAME);
54
+ const menuActions = useMenuActions(actions);
55
+
56
+ return (
57
+ <Panel.Root>
58
+ <Panel.Toolbar>
59
+ <Menu.Root {...menuActions} alwaysActive onAction={onAction}>
60
+ <Menu.Toolbar />
61
+ </Menu.Root>
62
+ </Panel.Toolbar>
63
+ <Panel.Content>
64
+ <Surface.Surface role='article' data={data} limit={1} fallback={ErrorFallback} placeholder={placeholder} />
65
+ </Panel.Content>
66
+ </Panel.Root>
67
+ );
68
+ };
69
+
70
+ Drawer.displayName = DRAWER_NAME;
71
+
72
+ /**
73
+ * Resolves which companion to show based on variant preference.
74
+ * Falls back to first available if preferred variant not available.
75
+ */
76
+ const useSelectedCompanion = (companions: Node.Node[], preferredVariant?: string) => {
77
+ const selectedCompanion = useMemo(() => {
78
+ if (companions.length === 0) {
79
+ return undefined;
80
+ }
81
+
82
+ // Try to find companion matching the preferred variant.
83
+ if (preferredVariant) {
84
+ const preferred = companions.find((c) => getLinkedVariant(c.id) === preferredVariant);
85
+ if (preferred) {
86
+ return preferred;
87
+ }
88
+ }
89
+
90
+ // Fallback to first companion.
91
+ return companions[0];
92
+ }, [companions, preferredVariant]);
93
+
94
+ const companionId = selectedCompanion?.id;
95
+ const variant = companionId ? getLinkedVariant(companionId) : undefined;
96
+
97
+ return { selectedCompanion, companionId, variant };
98
+ };
@@ -2,80 +2,77 @@
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';
13
- import { mx } from '@dxos/ui-theme';
10
+ import { ErrorFallback, Panel } from '@dxos/react-ui';
11
+ import { useAttentionAttributes } from '@dxos/react-ui-attention';
14
12
 
15
- import { useSimpleLayoutState } from '../../hooks';
16
- import { ContentError } from '../ContentError';
17
- import { ContentLoading } from '../ContentLoading';
13
+ import { useAppBarProps, useNavbarActions, useSimpleLayoutState } from '#hooks';
18
14
 
19
- import { Banner } from './Banner';
15
+ import { useExpandPath } from '../hooks';
16
+ import { Loading } from '../Loading';
17
+ import { useMobileLayout } from '../MobileLayout';
18
+ import { AppBar } from './AppBar';
20
19
  import { NavBar } from './NavBar';
21
20
 
21
+ const MAIN_NAME = 'SimpleLayout.Main';
22
+
22
23
  /**
23
- * Main root component.
24
+ * Main content component.
24
25
  */
25
26
  export const Main = () => {
26
27
  const { state } = useSimpleLayoutState();
27
28
  const id = state.active ?? state.workspace;
28
- const showNavBar = !state.isPopover;
29
- const { graph } = useAppGraph();
30
- const node = useNode(graph, id);
29
+ const attentionAttrs = useAttentionAttributes(id);
30
+ const { keyboardOpen } = useMobileLayout(MAIN_NAME);
31
+ const { actions, onAction } = useNavbarActions();
32
+ const appBarProps = useAppBarProps();
31
33
 
32
- const placeholder = useMemo(() => <ContentLoading />, []);
34
+ const placeholder = useMemo(() => <Loading />, []);
33
35
 
36
+ const { graph } = useAppGraph();
37
+ const node = useNode(graph, id);
34
38
  const data = useMemo(() => {
35
- const { variant } = parseEntryId(id);
36
39
  return (
37
40
  node && {
38
41
  attendableId: id,
39
42
  subject: node.data,
40
43
  properties: node.properties,
41
44
  popoverAnchorId: state.popoverAnchorId,
42
- variant,
43
45
  }
44
46
  );
45
47
  }, [id, node, node?.data, node?.properties, state.popoverAnchorId]);
46
48
 
47
- const handleActiveIdChange = useCallback((nextActiveId: string | null) => {
48
- log.info('navigate', { nextActiveId });
49
- }, []);
49
+ useExpandPath(id);
50
+
51
+ // TODO(burdon): BUG: When showing ANY statusbar the size progressively shrinks when the keyboard opens/closes.
52
+ const showNavBar = !keyboardOpen && !state.isPopover && state.drawerState === 'closed';
50
53
 
51
54
  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>
55
+ <Panel.Root {...attentionAttrs} className='dx-document'>
56
+ <Panel.Toolbar asChild>
57
+ <AppBar {...appBarProps} />
58
+ </Panel.Toolbar>
59
+ <Panel.Content role='article' className='bg-base-surface'>
60
+ <Surface.Surface
61
+ key={id}
62
+ role='article'
63
+ data={data}
64
+ limit={1}
65
+ fallback={ErrorFallback}
66
+ placeholder={placeholder}
67
+ />
68
+ </Panel.Content>
69
+ {showNavBar && (
70
+ <Panel.Statusbar asChild>
71
+ <NavBar actions={actions} onAction={onAction} />
72
+ </Panel.Statusbar>
73
+ )}
74
+ </Panel.Root>
72
75
  );
73
76
  };
74
77
 
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';
78
+ Main.displayName = MAIN_NAME;
@@ -2,58 +2,162 @@
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
- import { withTheme } from '@dxos/react-ui/testing';
10
+ import { type ActionGraphProps, createGapSeparator, createMenuAction, createMenuItemGroup } from '@dxos/react-ui-menu';
11
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
12
+ import { withRegistry } from '@dxos/storybook-utils';
10
13
 
11
14
  import { translations } from '../../translations';
12
-
13
15
  import { NavBar } from './NavBar';
14
16
 
17
+ const MAIN_MENU_GROUP_ID = 'navbar-main-menu';
18
+
19
+ const buildEmptyActions = (): ActionGraphProps => ({ nodes: [], edges: [] });
20
+
21
+ const buildCompanionOnlyActions = (): ActionGraphProps => {
22
+ const result: ActionGraphProps = { nodes: [], edges: [] };
23
+ const companions = [
24
+ createMenuAction('companion-browse', () => console.log('Browse'), {
25
+ icon: 'ph--house--regular',
26
+ label: 'Browse',
27
+ iconOnly: true,
28
+ }),
29
+ createMenuAction('companion-notifications', () => console.log('Notifications'), {
30
+ icon: 'ph--bell--regular',
31
+ label: 'Notifications',
32
+ iconOnly: true,
33
+ }),
34
+ createMenuAction('companion-profile', () => console.log('Profile'), {
35
+ icon: 'ph--user--regular',
36
+ label: 'Profile',
37
+ iconOnly: true,
38
+ }),
39
+ ];
40
+ result.nodes.push(...companions);
41
+ result.edges.push(...companions.map((c) => ({ source: 'root', target: c.id, relation: 'child' })));
42
+ return result;
43
+ };
44
+
45
+ const buildDefaultActions = (): ActionGraphProps => {
46
+ const result: ActionGraphProps = { nodes: [], edges: [] };
47
+ const gapSeparator = createGapSeparator('navbar-gap');
48
+ const mainMenuGroup = createMenuItemGroup(MAIN_MENU_GROUP_ID, {
49
+ variant: 'dropdownMenu',
50
+ icon: 'ph--plus--regular',
51
+ iconOnly: true,
52
+ label: 'Main menu',
53
+ testId: 'simpleLayoutPlugin.addSpace',
54
+ });
55
+ const companions = [
56
+ createMenuAction('companion-browse', () => console.log('Browse'), {
57
+ icon: 'ph--house--regular',
58
+ label: 'Browse',
59
+ iconOnly: true,
60
+ }),
61
+ createMenuAction('companion-notifications', () => console.log('Notifications'), {
62
+ icon: 'ph--bell--regular',
63
+ label: 'Notifications',
64
+ iconOnly: true,
65
+ }),
66
+ ];
67
+ const menuActions = [
68
+ createMenuAction('action-create-space', () => console.log('Create space'), {
69
+ icon: 'ph--planet--regular',
70
+ label: 'Create space',
71
+ }),
72
+ createMenuAction('action-join-space', () => console.log('Join space'), {
73
+ icon: 'ph--sign-in--regular',
74
+ label: 'Join space',
75
+ }),
76
+ createMenuAction('action-settings', () => console.log('Settings'), {
77
+ icon: 'ph--gear--regular',
78
+ label: 'Settings',
79
+ }),
80
+ ];
81
+ result.nodes.push(...companions, ...gapSeparator.nodes, mainMenuGroup, ...menuActions);
82
+ result.edges.push(
83
+ ...companions.map((c) => ({ source: 'root', target: c.id, relation: 'child' })),
84
+ ...gapSeparator.edges,
85
+ { source: 'root', target: mainMenuGroup.id, relation: 'child' },
86
+ ...menuActions.map((action) => ({ source: MAIN_MENU_GROUP_ID, target: action.id, relation: 'child' })),
87
+ );
88
+ return result;
89
+ };
90
+
15
91
  const meta = {
16
- title: 'plugins/plugin-simple-layout/NavBar',
92
+ title: 'plugins/plugin-simple-layout/components/NavBar',
17
93
  component: NavBar,
18
- decorators: [
19
- withTheme,
20
- withPluginManager({
21
- plugins: [...corePlugins()],
22
- }),
23
- ],
94
+ decorators: [withTheme(), withLayout({ layout: 'fullscreen' }), withRegistry],
24
95
  parameters: {
25
96
  layout: 'fullscreen',
26
97
  translations,
27
98
  },
28
- argTypes: {
29
- onActiveIdChange: { action: 'activeIdChanged' },
30
- },
31
99
  } satisfies Meta<typeof NavBar>;
32
100
 
33
101
  export default meta;
34
102
 
35
103
  type Story = StoryObj<typeof meta>;
36
104
 
105
+ const DefaultStory = ({ onAction }: { onAction: (action: { id: string }) => void }) => {
106
+ const actions = useMemo(() => Atom.make(buildDefaultActions()).pipe(Atom.keepAlive), []);
107
+
108
+ return <NavBar classNames='border-y border-separator' actions={actions} onAction={onAction} />;
109
+ };
110
+
37
111
  export const Default: Story = {
112
+ tags: ['test'],
38
113
  args: {
39
- activeId: undefined,
114
+ onAction: fn(),
115
+ } as any,
116
+ render: (args: any) => <DefaultStory onAction={args.onAction} />,
117
+ play: async ({ args, canvasElement }) => {
118
+ const canvas = within(canvasElement);
119
+
120
+ // Verify the navbar renders with the toolbar.
121
+ await expect(canvas.getByRole('toolbar')).toBeInTheDocument();
122
+
123
+ // Test companion action click (Browse button).
124
+ const browseButton = canvas.getByRole('button', { name: /browse/i });
125
+ await expect(browseButton).toBeInTheDocument();
126
+ await userEvent.click(browseButton);
127
+ await expect(args.onAction).toHaveBeenCalledTimes(1);
128
+ await expect((args.onAction as Mock).mock.calls[0][0]).toHaveProperty('id', 'companion-browse');
129
+
130
+ // Test dropdown menu opens and action fires.
131
+ const menuTrigger = canvas.getByRole('button', { name: /main menu/i });
132
+ await expect(menuTrigger).toBeInTheDocument();
133
+ await userEvent.click(menuTrigger);
134
+
135
+ // Wait for menu to open and click an action (menu items render in a portal).
136
+ const createSpaceAction = await screen.findByRole('menuitem', { name: /create space/i });
137
+ await userEvent.click(createSpaceAction);
138
+ await expect(args.onAction).toHaveBeenCalledTimes(2);
139
+ await expect((args.onAction as Mock).mock.calls[1][0]).toHaveProperty('id', 'action-create-space');
40
140
  },
41
141
  };
42
142
 
43
- export const BrowseActive: Story = {
44
- args: {
45
- activeId: 'some-document',
46
- },
143
+ const CompanionsOnlyStory = () => {
144
+ const actions = useMemo(() => Atom.make(buildCompanionOnlyActions()).pipe(Atom.keepAlive), []);
145
+
146
+ return <NavBar actions={actions} onAction={(action) => console.log('Action:', action.id)} />;
47
147
  };
48
148
 
49
- export const NotificationsActive: Story = {
50
- args: {
51
- activeId: 'notifications',
52
- },
149
+ export const CompanionsOnly: Story = {
150
+ args: {} as any,
151
+ render: () => <CompanionsOnlyStory />,
53
152
  };
54
153
 
55
- export const ProfileActive: Story = {
56
- args: {
57
- activeId: 'profile',
58
- },
154
+ const EmptyStory = () => {
155
+ const actions = useMemo(() => Atom.make(buildEmptyActions()).pipe(Atom.keepAlive), []);
156
+
157
+ return <NavBar actions={actions} onAction={(action) => console.log('Action:', action.id)} />;
158
+ };
159
+
160
+ export const Empty: Story = {
161
+ args: {} as any,
162
+ render: () => <EmptyStory />,
59
163
  };