@dxos/plugin-simple-layout 0.0.0 → 0.8.4-main.1068cf700f

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 (191) hide show
  1. package/dist/lib/browser/chunk-7VLT3S46.mjs +29 -0
  2. package/dist/lib/browser/chunk-7VLT3S46.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-O3BQBYMW.mjs +1165 -0
  4. package/dist/lib/browser/chunk-O3BQBYMW.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +101 -0
  6. package/dist/lib/browser/index.mjs.map +7 -0
  7. package/dist/lib/browser/meta.json +1 -0
  8. package/dist/lib/browser/operation-resolver-BYRIQOQT.mjs +205 -0
  9. package/dist/lib/browser/operation-resolver-BYRIQOQT.mjs.map +7 -0
  10. package/dist/lib/browser/react-root-GPTKI5H2.mjs +21 -0
  11. package/dist/lib/browser/react-root-GPTKI5H2.mjs.map +7 -0
  12. package/dist/lib/browser/react-surface-LT5JJTPR.mjs +41 -0
  13. package/dist/lib/browser/react-surface-LT5JJTPR.mjs.map +7 -0
  14. package/dist/lib/browser/spotlight-dismiss-67PHYS5B.mjs +66 -0
  15. package/dist/lib/browser/spotlight-dismiss-67PHYS5B.mjs.map +7 -0
  16. package/dist/lib/browser/state-A3PGDWWZ.mjs +48 -0
  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-UAWM4B2S.mjs +1166 -0
  21. package/dist/lib/node-esm/chunk-UAWM4B2S.mjs.map +7 -0
  22. package/dist/lib/node-esm/chunk-VIDE5UMB.mjs +31 -0
  23. package/dist/lib/node-esm/chunk-VIDE5UMB.mjs.map +7 -0
  24. package/dist/lib/node-esm/index.mjs +102 -0
  25. package/dist/lib/node-esm/index.mjs.map +7 -0
  26. package/dist/lib/node-esm/meta.json +1 -0
  27. package/dist/lib/node-esm/operation-resolver-BDTFNCS2.mjs +206 -0
  28. package/dist/lib/node-esm/operation-resolver-BDTFNCS2.mjs.map +7 -0
  29. package/dist/lib/node-esm/react-root-GRG2OAI2.mjs +22 -0
  30. package/dist/lib/node-esm/react-root-GRG2OAI2.mjs.map +7 -0
  31. package/dist/lib/node-esm/react-surface-TCUSDIN2.mjs +42 -0
  32. package/dist/lib/node-esm/react-surface-TCUSDIN2.mjs.map +7 -0
  33. package/dist/lib/node-esm/spotlight-dismiss-RMLRZUVY.mjs +68 -0
  34. package/dist/lib/node-esm/spotlight-dismiss-RMLRZUVY.mjs.map +7 -0
  35. package/dist/lib/node-esm/state-ZCFZTTPL.mjs +49 -0
  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 +7 -0
  40. package/dist/types/src/SimpleLayoutPlugin.d.ts.map +1 -0
  41. package/dist/types/src/capabilities/index.d.ts +7 -0
  42. package/dist/types/src/capabilities/index.d.ts.map +1 -0
  43. package/dist/types/src/capabilities/operation-resolver/index.d.ts +3 -0
  44. package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +1 -0
  45. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +5 -0
  46. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -0
  47. package/dist/types/src/capabilities/react-root/index.d.ts +6 -0
  48. package/dist/types/src/capabilities/react-root/index.d.ts.map +1 -0
  49. package/dist/types/src/capabilities/react-root/react-root.d.ts +9 -0
  50. package/dist/types/src/capabilities/react-root/react-root.d.ts.map +1 -0
  51. package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
  52. package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
  53. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
  54. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
  55. package/dist/types/src/capabilities/spotlight-dismiss/index.d.ts +3 -0
  56. package/dist/types/src/capabilities/spotlight-dismiss/index.d.ts.map +1 -0
  57. package/dist/types/src/capabilities/spotlight-dismiss/spotlight-dismiss.d.ts +14 -0
  58. package/dist/types/src/capabilities/spotlight-dismiss/spotlight-dismiss.d.ts.map +1 -0
  59. package/dist/types/src/capabilities/state/index.d.ts +13 -0
  60. package/dist/types/src/capabilities/state/index.d.ts.map +1 -0
  61. package/dist/types/src/capabilities/state/state.d.ts +19 -0
  62. package/dist/types/src/capabilities/state/state.d.ts.map +1 -0
  63. package/dist/types/src/capabilities/url-handler/index.d.ts +3 -0
  64. package/dist/types/src/capabilities/url-handler/index.d.ts.map +1 -0
  65. package/dist/types/src/capabilities/url-handler/url-handler.d.ts +12 -0
  66. package/dist/types/src/capabilities/url-handler/url-handler.d.ts.map +1 -0
  67. package/dist/types/src/components/ContentError.d.ts +5 -0
  68. package/dist/types/src/components/ContentError.d.ts.map +1 -0
  69. package/dist/types/src/components/ContentError.stories.d.ts +41 -0
  70. package/dist/types/src/components/ContentError.stories.d.ts.map +1 -0
  71. package/dist/types/src/components/ContentLoading.d.ts +3 -0
  72. package/dist/types/src/components/ContentLoading.d.ts.map +1 -0
  73. package/dist/types/src/components/ContentLoading.stories.d.ts +13 -0
  74. package/dist/types/src/components/ContentLoading.stories.d.ts.map +1 -0
  75. package/dist/types/src/components/Dialog/Dialog.d.ts +3 -0
  76. package/dist/types/src/components/Dialog/Dialog.d.ts.map +1 -0
  77. package/dist/types/src/components/Dialog/index.d.ts +2 -0
  78. package/dist/types/src/components/Dialog/index.d.ts.map +1 -0
  79. package/dist/types/src/components/Home/Home.d.ts +7 -0
  80. package/dist/types/src/components/Home/Home.d.ts.map +1 -0
  81. package/dist/types/src/components/Home/index.d.ts +2 -0
  82. package/dist/types/src/components/Home/index.d.ts.map +1 -0
  83. package/dist/types/src/components/MobileLayout/MobileLayout.d.ts +35 -0
  84. package/dist/types/src/components/MobileLayout/MobileLayout.d.ts.map +1 -0
  85. package/dist/types/src/components/MobileLayout/MobileLayout.stories.d.ts +7 -0
  86. package/dist/types/src/components/MobileLayout/MobileLayout.stories.d.ts.map +1 -0
  87. package/dist/types/src/components/MobileLayout/index.d.ts +2 -0
  88. package/dist/types/src/components/MobileLayout/index.d.ts.map +1 -0
  89. package/dist/types/src/components/Popover/Popover.d.ts +4 -0
  90. package/dist/types/src/components/Popover/Popover.d.ts.map +1 -0
  91. package/dist/types/src/components/Popover/index.d.ts +2 -0
  92. package/dist/types/src/components/Popover/index.d.ts.map +1 -0
  93. package/dist/types/src/components/SimpleLayout/AppBar.d.ts +26 -0
  94. package/dist/types/src/components/SimpleLayout/AppBar.d.ts.map +1 -0
  95. package/dist/types/src/components/SimpleLayout/AppBar.stories.d.ts +47 -0
  96. package/dist/types/src/components/SimpleLayout/AppBar.stories.d.ts.map +1 -0
  97. package/dist/types/src/components/SimpleLayout/Drawer.d.ts +9 -0
  98. package/dist/types/src/components/SimpleLayout/Drawer.d.ts.map +1 -0
  99. package/dist/types/src/components/SimpleLayout/Main.d.ts +9 -0
  100. package/dist/types/src/components/SimpleLayout/Main.d.ts.map +1 -0
  101. package/dist/types/src/components/SimpleLayout/NavBar.d.ts +18 -0
  102. package/dist/types/src/components/SimpleLayout/NavBar.d.ts.map +1 -0
  103. package/dist/types/src/components/SimpleLayout/NavBar.stories.d.ts +43 -0
  104. package/dist/types/src/components/SimpleLayout/NavBar.stories.d.ts.map +1 -0
  105. package/dist/types/src/components/SimpleLayout/SimpleLayout.d.ts +3 -0
  106. package/dist/types/src/components/SimpleLayout/SimpleLayout.d.ts.map +1 -0
  107. package/dist/types/src/components/SimpleLayout/SimpleLayout.stories.d.ts +47 -0
  108. package/dist/types/src/components/SimpleLayout/SimpleLayout.stories.d.ts.map +1 -0
  109. package/dist/types/src/components/SimpleLayout/index.d.ts +5 -0
  110. package/dist/types/src/components/SimpleLayout/index.d.ts.map +1 -0
  111. package/dist/types/src/components/Workspace/Workspace.d.ts +11 -0
  112. package/dist/types/src/components/Workspace/Workspace.d.ts.map +1 -0
  113. package/dist/types/src/components/Workspace/index.d.ts +2 -0
  114. package/dist/types/src/components/Workspace/index.d.ts.map +1 -0
  115. package/dist/types/src/components/hooks.d.ts +5 -0
  116. package/dist/types/src/components/hooks.d.ts.map +1 -0
  117. package/dist/types/src/components/index.d.ts +7 -0
  118. package/dist/types/src/components/index.d.ts.map +1 -0
  119. package/dist/types/src/hooks/actions.d.ts +20 -0
  120. package/dist/types/src/hooks/actions.d.ts.map +1 -0
  121. package/dist/types/src/hooks/index.d.ts +7 -0
  122. package/dist/types/src/hooks/index.d.ts.map +1 -0
  123. package/dist/types/src/hooks/useAppBarProps.d.ts +7 -0
  124. package/dist/types/src/hooks/useAppBarProps.d.ts.map +1 -0
  125. package/dist/types/src/hooks/useCompanions.d.ts +12 -0
  126. package/dist/types/src/hooks/useCompanions.d.ts.map +1 -0
  127. package/dist/types/src/hooks/useDrawerActions.d.ts +13 -0
  128. package/dist/types/src/hooks/useDrawerActions.d.ts.map +1 -0
  129. package/dist/types/src/hooks/useNavbarActions.d.ts +14 -0
  130. package/dist/types/src/hooks/useNavbarActions.d.ts.map +1 -0
  131. package/dist/types/src/hooks/useSimpleLayoutState.d.ts +7 -0
  132. package/dist/types/src/hooks/useSimpleLayoutState.d.ts.map +1 -0
  133. package/dist/types/src/index.d.ts +2 -0
  134. package/dist/types/src/index.d.ts.map +1 -0
  135. package/dist/types/src/meta.d.ts +3 -0
  136. package/dist/types/src/meta.d.ts.map +1 -0
  137. package/dist/types/src/translations.d.ts +26 -0
  138. package/dist/types/src/translations.d.ts.map +1 -0
  139. package/dist/types/src/types/capabilities.d.ts +36 -0
  140. package/dist/types/src/types/capabilities.d.ts.map +1 -0
  141. package/dist/types/src/types/events.d.ts +6 -0
  142. package/dist/types/src/types/events.d.ts.map +1 -0
  143. package/dist/types/src/types/index.d.ts +3 -0
  144. package/dist/types/src/types/index.d.ts.map +1 -0
  145. package/dist/types/tsconfig.tsbuildinfo +1 -0
  146. package/package.json +39 -29
  147. package/src/SimpleLayoutPlugin.ts +25 -8
  148. package/src/capabilities/index.ts +3 -0
  149. package/src/capabilities/operation-resolver/operation-resolver.ts +135 -53
  150. package/src/capabilities/react-root/react-root.tsx +2 -2
  151. package/src/capabilities/react-surface/index.ts +7 -0
  152. package/src/capabilities/react-surface/react-surface.tsx +41 -0
  153. package/src/capabilities/spotlight-dismiss/index.ts +7 -0
  154. package/src/{hooks/useSpotlightDismiss.ts → capabilities/spotlight-dismiss/spotlight-dismiss.ts} +31 -40
  155. package/src/capabilities/state/state.tsx +25 -33
  156. package/src/capabilities/url-handler/index.ts +7 -0
  157. package/src/capabilities/url-handler/url-handler.ts +157 -0
  158. package/src/components/ContentError.stories.tsx +1 -1
  159. package/src/components/ContentLoading.stories.tsx +1 -1
  160. package/src/components/Dialog/Dialog.tsx +14 -14
  161. package/src/components/Home/Home.tsx +64 -70
  162. package/src/components/MobileLayout/MobileLayout.stories.tsx +125 -0
  163. package/src/components/MobileLayout/MobileLayout.tsx +305 -0
  164. package/src/components/MobileLayout/index.ts +5 -0
  165. package/src/components/Popover/Popover.tsx +45 -27
  166. package/src/components/SimpleLayout/AppBar.stories.tsx +144 -0
  167. package/src/components/SimpleLayout/AppBar.tsx +101 -0
  168. package/src/components/SimpleLayout/Drawer.tsx +102 -0
  169. package/src/components/SimpleLayout/Main.tsx +53 -57
  170. package/src/components/SimpleLayout/NavBar.stories.tsx +164 -0
  171. package/src/components/SimpleLayout/NavBar.tsx +29 -86
  172. package/src/components/SimpleLayout/SimpleLayout.stories.tsx +24 -18
  173. package/src/components/SimpleLayout/SimpleLayout.tsx +45 -7
  174. package/src/components/SimpleLayout/index.ts +3 -0
  175. package/src/components/Workspace/Workspace.tsx +119 -0
  176. package/src/components/Workspace/index.ts +5 -0
  177. package/src/components/hooks.ts +26 -0
  178. package/src/components/index.ts +2 -0
  179. package/src/hooks/actions.ts +85 -0
  180. package/src/hooks/index.ts +6 -1
  181. package/src/hooks/useAppBarProps.ts +112 -0
  182. package/src/hooks/useCompanions.ts +22 -0
  183. package/src/hooks/useDrawerActions.ts +98 -0
  184. package/src/hooks/useNavbarActions.ts +86 -0
  185. package/src/hooks/useSimpleLayoutState.ts +30 -0
  186. package/src/translations.ts +6 -0
  187. package/src/types/capabilities.ts +20 -4
  188. package/src/types/events.ts +15 -0
  189. package/src/types/index.ts +1 -0
  190. package/src/components/SimpleLayout/Banner.tsx +0 -60
  191. package/src/components/SimpleLayout/NavBarstories.tsx +0 -59
@@ -2,20 +2,58 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import React from 'react';
5
+ import React, { useEffect, useRef, useState } from 'react';
6
6
 
7
+ import { Splitter, type SplitterMode } from '@dxos/react-ui';
8
+ import { Mosaic } from '@dxos/react-ui-mosaic';
9
+
10
+ import { useSimpleLayoutState } from '../../hooks';
7
11
  import { Dialog } from '../Dialog';
12
+ import { MobileLayout } from '../MobileLayout';
8
13
  import { PopoverContent, PopoverRoot } from '../Popover';
9
14
 
15
+ import { Drawer } from './Drawer';
10
16
  import { Main } from './Main';
11
17
 
12
- // TODO(wittjosiah): Support toast.
18
+ // TODO(burdon): Mobile/Desktop variance?
13
19
  export const SimpleLayout = () => {
20
+ const { state } = useSimpleLayoutState();
21
+ const [keyboardOpen, setKeyboardOpen] = useState(false);
22
+ const [splitterMode, setSplitterMode] = useState<SplitterMode>('upper');
23
+
24
+ const drawerRef = useRef<HTMLDivElement>(null);
25
+ useEffect(() => {
26
+ if (keyboardOpen) {
27
+ // Determine which panel has focus and expand that one.
28
+ const activeElement = document.activeElement;
29
+ const drawerHasFocus = drawerRef.current?.contains(activeElement);
30
+ setSplitterMode(drawerHasFocus ? 'lower' : 'upper');
31
+ } else {
32
+ setSplitterMode(state.drawerState === 'closed' ? 'upper' : state.drawerState === 'open' ? 'both' : 'lower');
33
+ }
34
+ }, [state.drawerState, keyboardOpen]);
35
+
14
36
  return (
15
- <PopoverRoot>
16
- <Main />
17
- <Dialog />
18
- <PopoverContent />
19
- </PopoverRoot>
37
+ <Mosaic.Root classNames='contents'>
38
+ <MobileLayout.Root
39
+ classNames='bg-toolbarSurface'
40
+ onKeyboardOpenChange={(keyboardOpen: boolean) => setKeyboardOpen(keyboardOpen)}
41
+ >
42
+ <MobileLayout.Panel safe={{ top: true, bottom: splitterMode === 'upper' }}>
43
+ <PopoverRoot>
44
+ <Splitter.Root mode={splitterMode} ratio={0.55}>
45
+ <Splitter.Panel position='upper'>
46
+ <Main />
47
+ </Splitter.Panel>
48
+ <Splitter.Panel position='lower' ref={drawerRef}>
49
+ <Drawer />
50
+ </Splitter.Panel>
51
+ </Splitter.Root>
52
+ <Dialog />
53
+ <PopoverContent />
54
+ </PopoverRoot>
55
+ </MobileLayout.Panel>
56
+ </MobileLayout.Root>
57
+ </Mosaic.Root>
20
58
  );
21
59
  };
@@ -2,4 +2,7 @@
2
2
  // Copyright 2026 DXOS.org
3
3
  //
4
4
 
5
+ export * from './AppBar';
6
+ export * from './Main';
7
+ export * from './NavBar';
5
8
  export * from './SimpleLayout';
@@ -0,0 +1,119 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import React, { useCallback, useEffect, useRef } from 'react';
6
+
7
+ import { useOperationInvoker } from '@dxos/app-framework/ui';
8
+ import { LayoutOperation } from '@dxos/app-toolkit';
9
+ import { useAppGraph } from '@dxos/app-toolkit/ui';
10
+ import { type Node, useConnections } from '@dxos/plugin-graph';
11
+ import { Avatar, Icon, Layout, ScrollArea, Toolbar, toLocalizedString, useTranslation } from '@dxos/react-ui';
12
+ import { Card, Mosaic, type StackTileComponent } from '@dxos/react-ui-mosaic';
13
+ import { SearchList, useSearchListItem, useSearchListResults } from '@dxos/react-ui-searchlist';
14
+ import { mx } from '@dxos/ui-theme';
15
+
16
+ import { meta } from '../../meta';
17
+ import { useLoadDescendents } from '../hooks';
18
+
19
+ export type WorkspaceProps = {
20
+ id: string;
21
+ };
22
+
23
+ /**
24
+ * Displays the contents of a workspace disposition graph node as a searchable list.
25
+ * Shows direct children of the workspace with icons and labels,
26
+ * allowing users to filter via search and navigate by selecting an item.
27
+ */
28
+ export const Workspace = ({ id }: WorkspaceProps) => {
29
+ const { t } = useTranslation(meta.id);
30
+ const { graph } = useAppGraph();
31
+
32
+ // Expand the workspace node to load its children.
33
+ useLoadDescendents(id);
34
+
35
+ // Get direct children of the workspace node.
36
+ const children = useConnections(graph, id, 'outbound');
37
+
38
+ const { results, handleSearch } = useSearchListResults({
39
+ items: children,
40
+ extract: (child) => toLocalizedString(child.properties.label, t),
41
+ });
42
+
43
+ return (
44
+ <Layout.Main toolbar>
45
+ <SearchList.Root onSearch={handleSearch}>
46
+ <Toolbar.Root>
47
+ <SearchList.Input placeholder={t('search placeholder')} autoFocus />
48
+ </Toolbar.Root>
49
+ <SearchList.Content>
50
+ <Mosaic.Container asChild>
51
+ <ScrollArea.Root orientation='vertical'>
52
+ <ScrollArea.Viewport classNames='p-2'>
53
+ <Mosaic.Stack items={results} getId={(child) => child.id} Tile={WorkspaceChildTile} />
54
+ </ScrollArea.Viewport>
55
+ </ScrollArea.Root>
56
+ </Mosaic.Container>
57
+ </SearchList.Content>
58
+ </SearchList.Root>
59
+ </Layout.Main>
60
+ );
61
+ };
62
+
63
+ const WorkspaceChildTile: StackTileComponent<Node.Node> = ({ data }) => {
64
+ const { t } = useTranslation(meta.id);
65
+ const { invokeSync } = useOperationInvoker();
66
+ const ref = useRef<HTMLDivElement>(null);
67
+ const { selectedValue, registerItem, unregisterItem } = useSearchListItem();
68
+ const isSelected = selectedValue === data.id;
69
+
70
+ const name = toLocalizedString(data.properties.label, t);
71
+
72
+ const handleSelect = useCallback(
73
+ () => invokeSync(LayoutOperation.Open, { subject: [data.id] }),
74
+ [invokeSync, data.id],
75
+ );
76
+
77
+ // Register this item with the search context.
78
+ useEffect(() => {
79
+ if (ref.current) {
80
+ registerItem(data.id, ref.current, handleSelect);
81
+ }
82
+
83
+ return () => unregisterItem(data.id);
84
+ }, [data.id, handleSelect, registerItem, unregisterItem]);
85
+
86
+ // Scroll into view when selected.
87
+ useEffect(() => {
88
+ if (isSelected && ref.current) {
89
+ ref.current.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
90
+ }
91
+ }, [isSelected]);
92
+
93
+ return (
94
+ <Card.Root
95
+ ref={ref}
96
+ role='button'
97
+ fullWidth
98
+ tabIndex={-1} // TODO(burdon): Use Mosaic.Focus.
99
+ data-selected={isSelected}
100
+ classNames={mx('dx-focus-ring', isSelected && 'bg-hoverOverlay')}
101
+ onClick={handleSelect}
102
+ >
103
+ <Card.Toolbar density='coarse'>
104
+ <Avatar.Root>
105
+ <Avatar.Content
106
+ hue={data.properties.hue}
107
+ icon={data.properties.icon}
108
+ hueVariant='transparent'
109
+ variant='square'
110
+ size={12}
111
+ fallback={name}
112
+ />
113
+ <Avatar.Label>{name}</Avatar.Label>
114
+ <Icon icon='ph--caret-right--regular' />
115
+ </Avatar.Root>
116
+ </Card.Toolbar>
117
+ </Card.Root>
118
+ );
119
+ };
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './Workspace';
@@ -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
+
10
+ /**
11
+ * Hook to expand graph nodes two levels deep when directly linked to.
12
+ */
13
+ export const useLoadDescendents = (nodeId?: string) => {
14
+ const { graph } = useAppGraph();
15
+
16
+ useEffect(() => {
17
+ if (nodeId) {
18
+ // First level: expand the node itself.
19
+ Graph.expand(graph, nodeId, 'outbound');
20
+ // Second level: expand each child.
21
+ Graph.getConnections(graph, nodeId, 'outbound').forEach((child) => {
22
+ Graph.expand(graph, child.id, 'outbound');
23
+ });
24
+ }
25
+ }, [nodeId, graph]);
26
+ };
@@ -4,5 +4,7 @@
4
4
 
5
5
  export * from './ContentLoading';
6
6
  export * from './Home';
7
+ export * from './MobileLayout';
7
8
  export * from './Popover';
8
9
  export * from './SimpleLayout';
10
+ export * from './Workspace';
@@ -0,0 +1,85 @@
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 Capabilities } from '@dxos/app-framework';
9
+ import { type AppCapabilities, LayoutOperation } from '@dxos/app-toolkit';
10
+ import { Node } from '@dxos/plugin-graph';
11
+ import { ATTENDABLE_PATH_SEPARATOR } from '@dxos/react-ui-attention';
12
+ import { type ActionGraphProps } from '@dxos/react-ui-menu';
13
+ import { byPosition } from '@dxos/util';
14
+
15
+ import { type SimpleLayoutState } from '../types';
16
+
17
+ // TODO(wittjosiah): Factor out to shared location with plugin-deck.
18
+ export const PLANK_COMPANION_TYPE = 'dxos.org/plugin/deck/plank-companion';
19
+
20
+ export type CompanionActionsConfig = {
21
+ /** Prefix for companion action IDs (e.g. 'navbar' or 'drawer') */
22
+ idPrefix: string;
23
+ /** Optional: highlight companion with this variant */
24
+ selectedVariant?: string;
25
+ /** invokeSync function for dispatching operations */
26
+ invokeSync: Capabilities.OperationInvoker['invokeSync'];
27
+ };
28
+
29
+ /**
30
+ * Creates action graph nodes and edges for companion actions.
31
+ * Shared logic between useNavbarActions and useDrawerActions.
32
+ */
33
+ // TODO(burdon): Use builder pattern.
34
+ export const createCompanionActions = (
35
+ graph: AppCapabilities.AppGraph['graph'],
36
+ stateAtom: Atom.Atom<SimpleLayoutState>,
37
+ get: (atom: Atom.Atom<any>) => any,
38
+ config: CompanionActionsConfig,
39
+ ): Pick<ActionGraphProps, 'nodes' | 'edges'> => {
40
+ const { idPrefix, selectedVariant, invokeSync } = config;
41
+
42
+ // Derive activeId from state atom.
43
+ const state = get(stateAtom);
44
+ const activeId = state.active ?? state.workspace;
45
+
46
+ // Get companions from graph connections for activeId.
47
+ const activeConnections = activeId ? get(graph.connections(activeId)) : [];
48
+ const companions = activeConnections
49
+ .filter((node: Node.Node) => node.type === PLANK_COMPANION_TYPE)
50
+ .toSorted((a: Node.Node, b: Node.Node) => byPosition(a.properties, b.properties));
51
+
52
+ const nodes: ActionGraphProps['nodes'] = [];
53
+ const edges: ActionGraphProps['edges'] = [];
54
+
55
+ // Add companion actions.
56
+ // TODO(burdon): Cap at 6 items.
57
+ companions.forEach((companion: Node.Node) => {
58
+ // Extract variant for highlighting if needed.
59
+ const [, companionVariant] = companion.id.split(ATTENDABLE_PATH_SEPARATOR);
60
+
61
+ const companionAction = {
62
+ id: `${idPrefix}-companion-${companion.id}`,
63
+ type: Node.ActionType,
64
+ properties: {
65
+ icon: companion.properties.icon ?? 'ph--placeholder--regular',
66
+ label: companion.properties.label,
67
+ iconOnly: true,
68
+ // Conditionally add variant highlighting.
69
+ ...(selectedVariant !== undefined && {
70
+ variant: selectedVariant === companionVariant ? 'primary' : 'ghost',
71
+ }),
72
+ },
73
+ data: () =>
74
+ Effect.sync(() =>
75
+ invokeSync(LayoutOperation.Open, {
76
+ subject: [companion.id],
77
+ }),
78
+ ),
79
+ };
80
+ nodes.push(companionAction);
81
+ edges.push({ source: 'root', target: companionAction.id });
82
+ });
83
+
84
+ return { nodes, edges };
85
+ };
@@ -2,4 +2,9 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- export * from './useSpotlightDismiss';
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,112 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Atom, useAtomValue } from '@effect-atom/atom-react';
6
+ import * as Effect from 'effect/Effect';
7
+ import * as Option from 'effect/Option';
8
+ import { useCallback, useMemo } from 'react';
9
+
10
+ import { useCapability, useOperationInvoker } from '@dxos/app-framework/ui';
11
+ import { LayoutOperation } from '@dxos/app-toolkit';
12
+ import { useAppGraph } from '@dxos/app-toolkit/ui';
13
+ import { Graph, Node, useActionRunner, useNode } from '@dxos/plugin-graph';
14
+ import { toLocalizedString, useTranslation } from '@dxos/react-ui';
15
+ import { type ActionGraphProps } from '@dxos/react-ui-menu';
16
+
17
+ import { type AppBarProps } from '../components';
18
+ import { meta } from '../meta';
19
+ import { SimpleLayoutState as SimpleLayoutStateCapability } from '../types';
20
+
21
+ /**
22
+ * Hook that computes all AppBar props from the app graph.
23
+ * Derives activeId from state atom. Returns props ready to spread into the AppBar component.
24
+ */
25
+ export const useAppBarProps = (): Omit<AppBarProps, 'classNames'> => {
26
+ const { t } = useTranslation(meta.id);
27
+ const stateAtom = useCapability(SimpleLayoutStateCapability);
28
+ const state = useAtomValue(stateAtom);
29
+ const { graph } = useAppGraph();
30
+ const { invokeSync } = useOperationInvoker();
31
+ const runAction = useActionRunner();
32
+
33
+ // Derive activeId from state.
34
+ const activeId = state.active ?? state.workspace;
35
+ const node = useNode(graph, activeId);
36
+
37
+ // Compute title from node label.
38
+ const title = node ? toLocalizedString(node.properties.label, t) : undefined;
39
+
40
+ // Build actions atom filtering by disposition.
41
+ // Derive activeId from state atom so we don't need to recreate this atom when it changes.
42
+ const actionsAtom = useMemo(
43
+ () =>
44
+ Atom.make((get): ActionGraphProps => {
45
+ const state = get(stateAtom);
46
+ const activeId = state.active ?? state.workspace;
47
+ const allActions = activeId ? get(graph.actions(activeId)) : [];
48
+ const filtered = allActions.filter((action) =>
49
+ ['list-item', 'list-item-primary', 'heading-list-item'].includes(action.properties.disposition),
50
+ );
51
+ const nodes: ActionGraphProps['nodes'] = filtered as ActionGraphProps['nodes'];
52
+ const edges: ActionGraphProps['edges'] = filtered.map((action) => ({ source: 'root', target: action.id }));
53
+
54
+ // Add alternate-tree action (e.g. Settings) from the workspace node.
55
+ const workspaceConnections = state.workspace ? get(graph.connections(state.workspace)) : [];
56
+ const alternateTreeNode = workspaceConnections.find(
57
+ (node: Node.Node) => node.properties.disposition === 'alternate-tree',
58
+ );
59
+ if (alternateTreeNode && activeId !== alternateTreeNode.id) {
60
+ const settingsAction = {
61
+ id: `appbar-settings-${alternateTreeNode.id}`,
62
+ type: Node.ActionType,
63
+ data: () => Effect.sync(() => invokeSync(LayoutOperation.Open, { subject: [alternateTreeNode.id] })),
64
+ properties: {
65
+ label: alternateTreeNode.properties.label ?? alternateTreeNode.id,
66
+ icon: alternateTreeNode.properties.icon ?? 'ph--placeholder--regular',
67
+ },
68
+ };
69
+ nodes.push(settingsAction);
70
+ edges.push({ source: 'root', target: settingsAction.id });
71
+ }
72
+
73
+ return { nodes, edges };
74
+ }),
75
+ [graph, stateAtom],
76
+ );
77
+
78
+ // Back button logic.
79
+ const showBackButton = activeId !== undefined && activeId !== Node.RootId;
80
+
81
+ const onBack = useCallback(() => {
82
+ if (state.active) {
83
+ const isWorkspace = Graph.getNode(graph, state.active).pipe(
84
+ Option.map((node) => node.properties.disposition === 'workspace'),
85
+ Option.getOrElse(() => false),
86
+ );
87
+
88
+ // If history is empty and this is a workspace, go to home.
89
+ if (state.history.length === 0 && isWorkspace) {
90
+ invokeSync(LayoutOperation.SwitchWorkspace, { subject: Node.RootId });
91
+ } else {
92
+ // Otherwise, close (which will pop from history or clear active).
93
+ invokeSync(LayoutOperation.Close, { subject: [state.active] });
94
+ }
95
+ } else {
96
+ invokeSync(LayoutOperation.SwitchWorkspace, { subject: Node.RootId });
97
+ }
98
+ }, [graph, invokeSync, state.active, state.history.length]);
99
+
100
+ // Compute popover anchor ID.
101
+ const popoverAnchorId =
102
+ node && state.popoverAnchorId === `dxos.org/ui/${meta.id}/${node.id}` ? state.popoverAnchorId : undefined;
103
+
104
+ return {
105
+ title,
106
+ actions: actionsAtom,
107
+ showBackButton,
108
+ popoverAnchorId,
109
+ onBack: onBack,
110
+ onAction: runAction,
111
+ };
112
+ };
@@ -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);
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
+ };
@@ -0,0 +1,98 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Atom } from '@effect-atom/atom-react';
6
+ import * as Effect from 'effect/Effect';
7
+ import { useMemo } from 'react';
8
+
9
+ import { useCapability, useOperationInvoker } from '@dxos/app-framework/ui';
10
+ import { useAppGraph } from '@dxos/app-toolkit/ui';
11
+ import { Node, useActionRunner } from '@dxos/plugin-graph';
12
+ import { useTranslation } from '@dxos/react-ui';
13
+ import { type ActionExecutor, type ActionGraphProps, createGapSeparator } from '@dxos/react-ui-menu';
14
+
15
+ import { useMobileLayout } from '../components';
16
+ import { meta } from '../meta';
17
+ import { SimpleLayoutState as SimpleLayoutStateCapability } from '../types';
18
+
19
+ import { createCompanionActions } from './actions';
20
+ import { useSimpleLayoutState } from './useSimpleLayoutState';
21
+
22
+ export type DrawerActions = {
23
+ /** Action graph atom for the drawer. */
24
+ actions: Atom.Atom<ActionGraphProps>;
25
+ /** Action executor callback. */
26
+ onAction: ActionExecutor;
27
+ };
28
+
29
+ /**
30
+ * Builds the drawer actions including companion tabs and toolbar buttons.
31
+ */
32
+ export const useDrawerActions = (consumerName: string): DrawerActions => {
33
+ const { t } = useTranslation(meta.id);
34
+ const stateAtom = useCapability(SimpleLayoutStateCapability);
35
+ const { graph } = useAppGraph();
36
+ const runAction = useActionRunner();
37
+ const { invokeSync } = useOperationInvoker();
38
+ const { updateState } = useSimpleLayoutState();
39
+ const { keyboardOpen } = useMobileLayout(consumerName);
40
+
41
+ // Create a computed atom that derives everything from graph connections and state.
42
+ const actionsAtom = useMemo(
43
+ () =>
44
+ Atom.make((get): ActionGraphProps => {
45
+ // Derive drawer state from state atom.
46
+ const state = get(stateAtom);
47
+
48
+ // Add companion tab actions.
49
+ const { nodes, edges } = createCompanionActions(graph, stateAtom, get, {
50
+ idPrefix: 'drawer',
51
+ selectedVariant: state.companionVariant,
52
+ invokeSync,
53
+ });
54
+
55
+ // Add gap separator before toolbar buttons.
56
+ const gapSeparator = createGapSeparator('drawer-gap');
57
+ nodes.push(...gapSeparator.nodes);
58
+ edges.push(...gapSeparator.edges);
59
+
60
+ // Add expand/collapse toggle button (hidden when keyboard is open).
61
+ if (!keyboardOpen) {
62
+ const isExpanded = state.drawerState === 'expanded';
63
+ const toggleExpandAction = {
64
+ id: 'drawer-toggle-expand',
65
+ type: Node.ActionType,
66
+ properties: {
67
+ icon: isExpanded ? 'ph--arrow-down--regular' : 'ph--arrow-up--regular',
68
+ label: isExpanded ? t('collapse drawer label') : t('expand drawer label'),
69
+ iconOnly: true,
70
+ },
71
+ data: () =>
72
+ Effect.sync(() => updateState((state) => ({ ...state, drawerState: isExpanded ? 'open' : 'expanded' }))),
73
+ };
74
+ nodes.push(toggleExpandAction);
75
+ edges.push({ source: 'root', target: toggleExpandAction.id });
76
+ }
77
+
78
+ // Add close button.
79
+ const closeAction = {
80
+ id: 'drawer-close',
81
+ type: Node.ActionType,
82
+ properties: {
83
+ icon: 'ph--x--regular',
84
+ label: t('close drawer label'),
85
+ iconOnly: true,
86
+ },
87
+ data: () => Effect.sync(() => updateState((state) => ({ ...state, drawerState: 'closed' }))),
88
+ };
89
+ nodes.push(closeAction);
90
+ edges.push({ source: 'root', target: closeAction.id });
91
+
92
+ return { nodes, edges };
93
+ }),
94
+ [graph, stateAtom, invokeSync, updateState, keyboardOpen, t],
95
+ );
96
+
97
+ return { actions: actionsAtom, onAction: runAction };
98
+ };
@@ -0,0 +1,86 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Atom } from '@effect-atom/atom-react';
6
+ import { useMemo } from 'react';
7
+
8
+ import { useCapability, useOperationInvoker } from '@dxos/app-framework/ui';
9
+ import { useAppGraph } from '@dxos/app-toolkit/ui';
10
+ import { Node, useActionRunner } from '@dxos/plugin-graph';
11
+ import { useTranslation } from '@dxos/react-ui';
12
+ import {
13
+ type ActionExecutor,
14
+ type ActionGraphProps,
15
+ createGapSeparator,
16
+ createMenuItemGroup,
17
+ } from '@dxos/react-ui-menu';
18
+
19
+ import { meta } from '../meta';
20
+ import { SimpleLayoutState } from '../types';
21
+
22
+ import { createCompanionActions } from './actions';
23
+
24
+ const MAIN_MENU_GROUP_ID = 'navbar-main-menu';
25
+
26
+ export type NavbarActions = {
27
+ /** Action graph atom for the navbar. */
28
+ actions: Atom.Atom<ActionGraphProps>;
29
+ /** Action executor callback. */
30
+ onAction: ActionExecutor;
31
+ };
32
+
33
+ /**
34
+ * Builds the navbar actions including companion icons, separator, and main menu dropdown.
35
+ * Derives everything from graph connection atoms for proper reactivity.
36
+ */
37
+ export const useNavbarActions = (): NavbarActions => {
38
+ const { t } = useTranslation(meta.id);
39
+ const { graph } = useAppGraph();
40
+ const runAction = useActionRunner();
41
+ const { invokeSync } = useOperationInvoker();
42
+ const stateAtom = useCapability(SimpleLayoutState);
43
+
44
+ // Create a computed atom that derives everything from graph connections and state.
45
+ const actionsAtom = useMemo(
46
+ () =>
47
+ Atom.make((get): ActionGraphProps => {
48
+ // Add companion actions.
49
+ const { nodes, edges } = createCompanionActions(graph, stateAtom, get, {
50
+ idPrefix: 'navbar',
51
+ invokeSync,
52
+ });
53
+
54
+ // Add gap separator.
55
+ const gapSeparator = createGapSeparator('navbar-gap');
56
+ nodes.push(...gapSeparator.nodes);
57
+ edges.push(...gapSeparator.edges);
58
+
59
+ // Add main menu dropdown group.
60
+ const mainMenuGroup = createMenuItemGroup(MAIN_MENU_GROUP_ID, {
61
+ variant: 'dropdownMenu',
62
+ icon: 'ph--list--regular',
63
+ iconOnly: true,
64
+ label: t('main menu label'),
65
+ testId: 'simpleLayoutPlugin.addSpace',
66
+ });
67
+ nodes.push(mainMenuGroup);
68
+ edges.push({ source: 'root', target: mainMenuGroup.id });
69
+
70
+ // Get menu actions from root connections.
71
+ const rootConnections = get(graph.connections(Node.RootId));
72
+ const menuActions = rootConnections.filter((node) => node.properties.disposition === 'menu');
73
+
74
+ // Add menu actions as children of the dropdown group.
75
+ menuActions.forEach((menuAction) => {
76
+ nodes.push(menuAction as ActionGraphProps['nodes'][number]);
77
+ edges.push({ source: MAIN_MENU_GROUP_ID, target: menuAction.id });
78
+ });
79
+
80
+ return { nodes, edges };
81
+ }),
82
+ [graph, stateAtom, invokeSync, t],
83
+ );
84
+
85
+ return { actions: actionsAtom, onAction: runAction };
86
+ };