@dxos/plugin-simple-layout 0.8.4-main.bc674ce → 0.8.4-main.d05673bc65

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 (187) hide show
  1. package/dist/lib/browser/chunk-MDPEKLKR.mjs +1163 -0
  2. package/dist/lib/browser/chunk-MDPEKLKR.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-P77G4YTR.mjs → chunk-MRR7PXSM.mjs} +5 -5
  4. package/dist/lib/browser/chunk-MRR7PXSM.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +20 -19
  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-775UYAC2.mjs → operation-resolver-VTZ6HZ4B.mjs} +37 -46
  9. package/dist/lib/browser/operation-resolver-VTZ6HZ4B.mjs.map +7 -0
  10. package/dist/lib/browser/{react-root-KM55OMGJ.mjs → react-root-WVQYY2JA.mjs} +5 -5
  11. package/dist/lib/browser/react-root-WVQYY2JA.mjs.map +7 -0
  12. package/dist/lib/browser/{react-surface-BABGAWGY.mjs → react-surface-VLBR37ED.mjs} +18 -13
  13. package/dist/lib/browser/react-surface-VLBR37ED.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-OUFTC2KV.mjs → state-TXSMUWYI.mjs} +5 -4
  17. package/dist/lib/browser/state-TXSMUWYI.mjs.map +7 -0
  18. package/dist/lib/browser/url-handler-RBRONH7S.mjs +151 -0
  19. package/dist/lib/browser/url-handler-RBRONH7S.mjs.map +7 -0
  20. package/dist/lib/node-esm/chunk-DCKASLMP.mjs +1164 -0
  21. package/dist/lib/node-esm/chunk-DCKASLMP.mjs.map +7 -0
  22. package/dist/lib/node-esm/{chunk-F5TEKVJG.mjs → chunk-WMNTJ2MK.mjs} +5 -5
  23. package/dist/lib/node-esm/chunk-WMNTJ2MK.mjs.map +7 -0
  24. package/dist/lib/node-esm/index.mjs +20 -19
  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-LDNYS3DI.mjs → operation-resolver-R7CQ6ERU.mjs} +37 -46
  28. package/dist/lib/node-esm/operation-resolver-R7CQ6ERU.mjs.map +7 -0
  29. package/dist/lib/node-esm/{react-root-36UYFEEB.mjs → react-root-XBNDM7BE.mjs} +5 -5
  30. package/dist/lib/node-esm/react-root-XBNDM7BE.mjs.map +7 -0
  31. package/dist/lib/node-esm/{react-surface-CGHFVWU3.mjs → react-surface-U5NHA367.mjs} +18 -13
  32. package/dist/lib/node-esm/react-surface-U5NHA367.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-Q2ZA26W5.mjs → state-JMX6FAG4.mjs} +5 -4
  36. package/dist/lib/node-esm/state-JMX6FAG4.mjs.map +7 -0
  37. package/dist/lib/node-esm/url-handler-QSMCH3JB.mjs +152 -0
  38. package/dist/lib/node-esm/url-handler-QSMCH3JB.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 +1 -1
  43. package/dist/types/src/capabilities/react-root/react-root.d.ts.map +1 -1
  44. package/dist/types/src/capabilities/react-surface/index.d.ts +1 -1
  45. package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -1
  46. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +2 -2
  47. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -1
  48. package/dist/types/src/capabilities/spotlight-dismiss/index.d.ts +1 -1
  49. package/dist/types/src/capabilities/spotlight-dismiss/index.d.ts.map +1 -1
  50. package/dist/types/src/capabilities/spotlight-dismiss/spotlight-dismiss.d.ts +1 -1
  51. package/dist/types/src/capabilities/spotlight-dismiss/spotlight-dismiss.d.ts.map +1 -1
  52. package/dist/types/src/capabilities/state/index.d.ts +1 -1
  53. package/dist/types/src/capabilities/state/state.d.ts +1 -1
  54. package/dist/types/src/capabilities/state/state.d.ts.map +1 -1
  55. package/dist/types/src/capabilities/url-handler/url-handler.d.ts +5 -3
  56. package/dist/types/src/capabilities/url-handler/url-handler.d.ts.map +1 -1
  57. package/dist/types/src/components/ContentError.stories.d.ts +1 -3
  58. package/dist/types/src/components/ContentError.stories.d.ts.map +1 -1
  59. package/dist/types/src/components/ContentLoading/ContentLoading.d.ts.map +1 -0
  60. package/dist/types/src/components/ContentLoading/ContentLoading.stories.d.ts.map +1 -0
  61. package/dist/types/src/components/ContentLoading/index.d.ts +2 -0
  62. package/dist/types/src/components/ContentLoading/index.d.ts.map +1 -0
  63. package/dist/types/src/components/Home/Home.d.ts.map +1 -1
  64. package/dist/types/src/components/MobileLayout/MobileLayout.d.ts +35 -0
  65. package/dist/types/src/components/MobileLayout/MobileLayout.d.ts.map +1 -0
  66. package/dist/types/src/components/MobileLayout/MobileLayout.stories.d.ts +7 -0
  67. package/dist/types/src/components/MobileLayout/MobileLayout.stories.d.ts.map +1 -0
  68. package/dist/types/src/components/MobileLayout/index.d.ts +2 -0
  69. package/dist/types/src/components/MobileLayout/index.d.ts.map +1 -0
  70. package/dist/types/src/components/NavBranch/NavBranch.d.ts +11 -0
  71. package/dist/types/src/components/NavBranch/NavBranch.d.ts.map +1 -0
  72. package/dist/types/src/components/NavBranch/index.d.ts +2 -0
  73. package/dist/types/src/components/NavBranch/index.d.ts.map +1 -0
  74. package/dist/types/src/components/Popover/Popover.d.ts.map +1 -1
  75. package/dist/types/src/components/SimpleLayout/AppBar.d.ts +26 -0
  76. package/dist/types/src/components/SimpleLayout/AppBar.d.ts.map +1 -0
  77. package/dist/types/src/components/SimpleLayout/AppBar.stories.d.ts +47 -0
  78. package/dist/types/src/components/SimpleLayout/AppBar.stories.d.ts.map +1 -0
  79. package/dist/types/src/components/SimpleLayout/Drawer.d.ts +1 -1
  80. package/dist/types/src/components/SimpleLayout/Drawer.d.ts.map +1 -1
  81. package/dist/types/src/components/SimpleLayout/Main.d.ts.map +1 -1
  82. package/dist/types/src/components/SimpleLayout/NavBar.d.ts +10 -3
  83. package/dist/types/src/components/SimpleLayout/NavBar.d.ts.map +1 -1
  84. package/dist/types/src/components/SimpleLayout/NavBar.stories.d.ts +4 -4
  85. package/dist/types/src/components/SimpleLayout/NavBar.stories.d.ts.map +1 -1
  86. package/dist/types/src/components/SimpleLayout/SimpleLayout.d.ts.map +1 -1
  87. package/dist/types/src/components/SimpleLayout/SimpleLayout.stories.d.ts.map +1 -1
  88. package/dist/types/src/components/SimpleLayout/index.d.ts +3 -0
  89. package/dist/types/src/components/SimpleLayout/index.d.ts.map +1 -1
  90. package/dist/types/src/components/hooks.d.ts +4 -2
  91. package/dist/types/src/components/hooks.d.ts.map +1 -1
  92. package/dist/types/src/components/index.d.ts +2 -1
  93. package/dist/types/src/components/index.d.ts.map +1 -1
  94. package/dist/types/src/hooks/actions.d.ts +19 -0
  95. package/dist/types/src/hooks/actions.d.ts.map +1 -0
  96. package/dist/types/src/hooks/index.d.ts +4 -0
  97. package/dist/types/src/hooks/index.d.ts.map +1 -1
  98. package/dist/types/src/hooks/useAppBarProps.d.ts +7 -0
  99. package/dist/types/src/hooks/useAppBarProps.d.ts.map +1 -0
  100. package/dist/types/src/hooks/useCompanions.d.ts +5 -1
  101. package/dist/types/src/hooks/useCompanions.d.ts.map +1 -1
  102. package/dist/types/src/hooks/useDrawerActions.d.ts +13 -0
  103. package/dist/types/src/hooks/useDrawerActions.d.ts.map +1 -0
  104. package/dist/types/src/hooks/useNavbarActions.d.ts +14 -0
  105. package/dist/types/src/hooks/useNavbarActions.d.ts.map +1 -0
  106. package/dist/types/src/hooks/useSimpleLayoutState.d.ts +3 -3
  107. package/dist/types/src/hooks/useSimpleLayoutState.d.ts.map +1 -1
  108. package/dist/types/src/types/capabilities.d.ts +7 -6
  109. package/dist/types/src/types/capabilities.d.ts.map +1 -1
  110. package/dist/types/src/types/events.d.ts.map +1 -1
  111. package/dist/types/tsconfig.tsbuildinfo +1 -1
  112. package/package.json +36 -30
  113. package/src/SimpleLayoutPlugin.ts +10 -9
  114. package/src/capabilities/operation-resolver/operation-resolver.ts +33 -46
  115. package/src/capabilities/react-root/react-root.tsx +2 -2
  116. package/src/capabilities/react-surface/react-surface.tsx +14 -11
  117. package/src/capabilities/spotlight-dismiss/spotlight-dismiss.ts +2 -2
  118. package/src/capabilities/state/state.tsx +4 -3
  119. package/src/capabilities/url-handler/url-handler.ts +98 -45
  120. package/src/components/ContentError.stories.tsx +8 -7
  121. package/src/components/{ContentLoading.stories.tsx → ContentLoading/ContentLoading.stories.tsx} +2 -2
  122. package/src/components/{ContentLoading.tsx → ContentLoading/ContentLoading.tsx} +1 -1
  123. package/src/components/ContentLoading/index.ts +5 -0
  124. package/src/components/Dialog/Dialog.tsx +5 -5
  125. package/src/components/Home/Home.tsx +43 -35
  126. package/src/components/MobileLayout/MobileLayout.stories.tsx +129 -0
  127. package/src/components/MobileLayout/MobileLayout.tsx +305 -0
  128. package/src/components/MobileLayout/index.ts +5 -0
  129. package/src/components/NavBranch/NavBranch.tsx +130 -0
  130. package/src/components/{Workspace → NavBranch}/index.ts +1 -1
  131. package/src/components/Popover/Popover.tsx +17 -7
  132. package/src/components/SimpleLayout/AppBar.stories.tsx +144 -0
  133. package/src/components/SimpleLayout/AppBar.tsx +94 -0
  134. package/src/components/SimpleLayout/Drawer.tsx +25 -80
  135. package/src/components/SimpleLayout/Main.tsx +40 -30
  136. package/src/components/SimpleLayout/NavBar.stories.tsx +131 -23
  137. package/src/components/SimpleLayout/NavBar.tsx +15 -47
  138. package/src/components/SimpleLayout/SimpleLayout.stories.tsx +20 -11
  139. package/src/components/SimpleLayout/SimpleLayout.tsx +38 -19
  140. package/src/components/SimpleLayout/index.ts +3 -0
  141. package/src/components/hooks.ts +9 -9
  142. package/src/components/index.ts +2 -1
  143. package/src/hooks/actions.ts +83 -0
  144. package/src/hooks/index.ts +4 -0
  145. package/src/hooks/useAppBarProps.ts +115 -0
  146. package/src/hooks/useCompanions.ts +8 -5
  147. package/src/hooks/useDrawerActions.ts +100 -0
  148. package/src/hooks/useNavbarActions.ts +87 -0
  149. package/src/hooks/useSimpleLayoutState.ts +5 -5
  150. package/src/meta.ts +1 -1
  151. package/src/types/capabilities.ts +11 -7
  152. package/src/types/events.ts +3 -2
  153. package/dist/lib/browser/chunk-LR3EE3VB.mjs +0 -789
  154. package/dist/lib/browser/chunk-LR3EE3VB.mjs.map +0 -7
  155. package/dist/lib/browser/chunk-P77G4YTR.mjs.map +0 -7
  156. package/dist/lib/browser/operation-resolver-775UYAC2.mjs.map +0 -7
  157. package/dist/lib/browser/react-root-KM55OMGJ.mjs.map +0 -7
  158. package/dist/lib/browser/react-surface-BABGAWGY.mjs.map +0 -7
  159. package/dist/lib/browser/spotlight-dismiss-VSNOPETH.mjs.map +0 -7
  160. package/dist/lib/browser/state-OUFTC2KV.mjs.map +0 -7
  161. package/dist/lib/browser/url-handler-DOUFQIAC.mjs +0 -54
  162. package/dist/lib/browser/url-handler-DOUFQIAC.mjs.map +0 -7
  163. package/dist/lib/node-esm/chunk-F5TEKVJG.mjs.map +0 -7
  164. package/dist/lib/node-esm/chunk-HB2B3LLG.mjs +0 -790
  165. package/dist/lib/node-esm/chunk-HB2B3LLG.mjs.map +0 -7
  166. package/dist/lib/node-esm/operation-resolver-LDNYS3DI.mjs.map +0 -7
  167. package/dist/lib/node-esm/react-root-36UYFEEB.mjs.map +0 -7
  168. package/dist/lib/node-esm/react-surface-CGHFVWU3.mjs.map +0 -7
  169. package/dist/lib/node-esm/spotlight-dismiss-L5PCWIJG.mjs.map +0 -7
  170. package/dist/lib/node-esm/state-Q2ZA26W5.mjs.map +0 -7
  171. package/dist/lib/node-esm/url-handler-DVAZZEUO.mjs +0 -55
  172. package/dist/lib/node-esm/url-handler-DVAZZEUO.mjs.map +0 -7
  173. package/dist/types/src/components/ContentError.d.ts +0 -5
  174. package/dist/types/src/components/ContentError.d.ts.map +0 -1
  175. package/dist/types/src/components/ContentLoading.d.ts.map +0 -1
  176. package/dist/types/src/components/ContentLoading.stories.d.ts.map +0 -1
  177. package/dist/types/src/components/SimpleLayout/Banner.d.ts +0 -8
  178. package/dist/types/src/components/SimpleLayout/Banner.d.ts.map +0 -1
  179. package/dist/types/src/components/Workspace/Workspace.d.ts +0 -9
  180. package/dist/types/src/components/Workspace/Workspace.d.ts.map +0 -1
  181. package/dist/types/src/components/Workspace/index.d.ts +0 -2
  182. package/dist/types/src/components/Workspace/index.d.ts.map +0 -1
  183. package/src/components/ContentError.tsx +0 -23
  184. package/src/components/SimpleLayout/Banner.tsx +0 -113
  185. package/src/components/Workspace/Workspace.tsx +0 -115
  186. /package/dist/types/src/components/{ContentLoading.d.ts → ContentLoading/ContentLoading.d.ts} +0 -0
  187. /package/dist/types/src/components/{ContentLoading.stories.d.ts → ContentLoading/ContentLoading.stories.d.ts} +0 -0
@@ -0,0 +1,115 @@
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) => ({
53
+ source: 'root',
54
+ target: action.id,
55
+ relation: 'child',
56
+ }));
57
+
58
+ // Add alternate-tree action (e.g. Settings) from the workspace node.
59
+ const workspaceConnections = state.workspace ? get(graph.connections(state.workspace, 'child')) : [];
60
+ const alternateTreeNode = workspaceConnections.find(
61
+ (node: Node.Node) => node.properties.disposition === 'alternate-tree',
62
+ );
63
+ if (alternateTreeNode && activeId !== alternateTreeNode.id) {
64
+ const settingsAction = {
65
+ id: `appbar-settings-${alternateTreeNode.id}`,
66
+ type: Node.ActionType,
67
+ data: () => Effect.sync(() => invokeSync(LayoutOperation.Open, { subject: [alternateTreeNode.id] })),
68
+ properties: {
69
+ label: alternateTreeNode.properties.label ?? alternateTreeNode.id,
70
+ icon: alternateTreeNode.properties.icon ?? 'ph--placeholder--regular',
71
+ },
72
+ };
73
+ nodes.push(settingsAction);
74
+ edges.push({ source: 'root', target: settingsAction.id, relation: 'child' });
75
+ }
76
+
77
+ return { nodes, edges };
78
+ }),
79
+ [graph, stateAtom],
80
+ );
81
+
82
+ // Back button logic.
83
+ const showBackButton = activeId !== undefined && activeId !== Node.RootId;
84
+
85
+ const onBack = useCallback(() => {
86
+ if (state.active) {
87
+ const isWorkspace = Graph.getNode(graph, state.active).pipe(
88
+ Option.map((node) => node.properties.disposition === 'workspace'),
89
+ Option.getOrElse(() => false),
90
+ );
91
+
92
+ // If history is empty and this is a workspace, go to home.
93
+ if (state.history.length === 0 && isWorkspace) {
94
+ invokeSync(LayoutOperation.SwitchWorkspace, { subject: Node.RootId });
95
+ } else {
96
+ // Otherwise, close (which will pop from history or clear active).
97
+ invokeSync(LayoutOperation.Close, { subject: [state.active] });
98
+ }
99
+ } else {
100
+ invokeSync(LayoutOperation.SwitchWorkspace, { subject: Node.RootId });
101
+ }
102
+ }, [graph, invokeSync, state.active, state.history.length]);
103
+
104
+ // Compute popover anchor ID.
105
+ const popoverAnchorId = node && state.popoverAnchorId === `${meta.id}:${node.id}` ? state.popoverAnchorId : undefined;
106
+
107
+ return {
108
+ title,
109
+ actions: actionsAtom,
110
+ showBackButton,
111
+ popoverAnchorId,
112
+ onBack: onBack,
113
+ onAction: runAction,
114
+ };
115
+ };
@@ -4,16 +4,19 @@
4
4
 
5
5
  import { useMemo } from 'react';
6
6
 
7
- import { useAppGraph } from '@dxos/app-framework/react';
7
+ import { useAppGraph } from '@dxos/app-toolkit/ui';
8
8
  import { useConnections } from '@dxos/plugin-graph';
9
9
  import { byPosition } from '@dxos/util';
10
10
 
11
- // TODO(wittjosiah): Factor out to shared location with plugin-deck.
12
- const PLANK_COMPANION_TYPE = 'dxos.org/plugin/deck/plank-companion';
11
+ import { PLANK_COMPANION_TYPE } from './actions';
13
12
 
14
- export const useCompanions = (id?: string) => {
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) => {
15
18
  const { graph } = useAppGraph();
16
- const nodes = useConnections(graph, id);
19
+ const nodes = useConnections(graph, nodeId, 'child');
17
20
  const companions = nodes.filter((node) => node.type === PLANK_COMPANION_TYPE);
18
21
  return useMemo(() => companions.toSorted((a, b) => byPosition(a.properties, b.properties)), [companions]);
19
22
  };
@@ -0,0 +1,100 @@
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 } 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 { updateState } = useSimpleLayoutState();
38
+ const { keyboardOpen } = useMobileLayout(consumerName);
39
+
40
+ // Create a computed atom that derives everything from graph connections and state.
41
+ const actionsAtom = useMemo(
42
+ () =>
43
+ Atom.make((get): ActionGraphProps => {
44
+ // Derive drawer state from state atom.
45
+ const state = get(stateAtom);
46
+
47
+ // Add companion tab actions.
48
+ const { nodes, edges } = createCompanionActions(graph, stateAtom, get, {
49
+ idPrefix: 'drawer',
50
+ selectedVariant: state.companionVariant,
51
+ updateState,
52
+ });
53
+
54
+ // Add gap separator before toolbar buttons.
55
+ const gapSeparator = createGapSeparator('drawer-gap');
56
+ nodes.push(...gapSeparator.nodes);
57
+ edges.push(...gapSeparator.edges);
58
+
59
+ // Add expand/collapse toggle button (hidden when keyboard is open).
60
+ if (!keyboardOpen) {
61
+ const isExpanded = state.drawerState === 'expanded';
62
+ const toggleExpandAction = {
63
+ id: 'drawer-toggle-expand',
64
+ type: Node.ActionType,
65
+ properties: {
66
+ icon: isExpanded ? 'ph--arrow-down--regular' : 'ph--arrow-up--regular',
67
+ label: isExpanded ? t('collapse drawer label') : t('expand drawer label'),
68
+ iconOnly: true,
69
+ },
70
+ data: () =>
71
+ Effect.sync(() => updateState((state) => ({ ...state, drawerState: isExpanded ? 'open' : 'expanded' }))),
72
+ };
73
+ nodes.push(toggleExpandAction);
74
+ edges.push({ source: 'root', target: toggleExpandAction.id, relation: 'child' });
75
+ }
76
+
77
+ // Add close button.
78
+ const closeAction = {
79
+ id: 'drawer-close',
80
+ type: Node.ActionType,
81
+ properties: {
82
+ icon: 'ph--x--regular',
83
+ label: t('close drawer label'),
84
+ iconOnly: true,
85
+ },
86
+ data: () =>
87
+ Effect.sync(() =>
88
+ updateState((state) => ({ ...state, drawerState: 'closed', companionVariant: undefined })),
89
+ ),
90
+ };
91
+ nodes.push(closeAction);
92
+ edges.push({ source: 'root', target: closeAction.id, relation: 'child' });
93
+
94
+ return { nodes, edges };
95
+ }),
96
+ [graph, stateAtom, updateState, keyboardOpen, t],
97
+ );
98
+
99
+ return { actions: actionsAtom, onAction: runAction };
100
+ };
@@ -0,0 +1,87 @@
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 } 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
+ import { useSimpleLayoutState } from './useSimpleLayoutState';
24
+
25
+ const MAIN_MENU_GROUP_ID = 'navbar-main-menu';
26
+
27
+ export type NavbarActions = {
28
+ /** Action graph atom for the navbar. */
29
+ actions: Atom.Atom<ActionGraphProps>;
30
+ /** Action executor callback. */
31
+ onAction: ActionExecutor;
32
+ };
33
+
34
+ /**
35
+ * Builds the navbar actions including companion icons, separator, and main menu dropdown.
36
+ * Derives everything from graph connection atoms for proper reactivity.
37
+ */
38
+ export const useNavbarActions = (): NavbarActions => {
39
+ const { t } = useTranslation(meta.id);
40
+ const { graph } = useAppGraph();
41
+ const runAction = useActionRunner();
42
+ const stateAtom = useCapability(SimpleLayoutState);
43
+ const { updateState } = useSimpleLayoutState();
44
+
45
+ // Create a computed atom that derives everything from graph connections and state.
46
+ const actionsAtom = useMemo(
47
+ () =>
48
+ Atom.make((get): ActionGraphProps => {
49
+ // Add companion actions.
50
+ const { nodes, edges } = createCompanionActions(graph, stateAtom, get, {
51
+ idPrefix: 'navbar',
52
+ updateState,
53
+ });
54
+
55
+ // Add gap separator.
56
+ const gapSeparator = createGapSeparator('navbar-gap');
57
+ nodes.push(...gapSeparator.nodes);
58
+ edges.push(...gapSeparator.edges);
59
+
60
+ // Add main menu dropdown group.
61
+ const mainMenuGroup = createMenuItemGroup(MAIN_MENU_GROUP_ID, {
62
+ variant: 'dropdownMenu',
63
+ icon: 'ph--list--regular',
64
+ iconOnly: true,
65
+ label: t('main menu label'),
66
+ testId: 'simpleLayoutPlugin.addSpace',
67
+ });
68
+ nodes.push(mainMenuGroup);
69
+ edges.push({ source: 'root', target: mainMenuGroup.id, relation: 'child' });
70
+
71
+ // Get menu actions from root actions (on 'action' edge relation).
72
+ const rootActions = get(graph.actions(Node.RootId));
73
+ const menuActions = rootActions.filter((node) => node.properties.disposition === 'menu');
74
+
75
+ // Add menu actions as children of the dropdown group.
76
+ menuActions.forEach((menuAction) => {
77
+ nodes.push(menuAction as ActionGraphProps['nodes'][number]);
78
+ edges.push({ source: MAIN_MENU_GROUP_ID, target: menuAction.id, relation: 'child' });
79
+ });
80
+
81
+ return { nodes, edges };
82
+ }),
83
+ [graph, stateAtom, updateState, t],
84
+ );
85
+
86
+ return { actions: actionsAtom, onAction: runAction };
87
+ };
@@ -5,18 +5,18 @@
5
5
  import { RegistryContext, useAtomValue } from '@effect-atom/atom-react';
6
6
  import { useCallback, useContext } from 'react';
7
7
 
8
- import { useCapability } from '@dxos/app-framework/react';
8
+ import { useCapability } from '@dxos/app-framework/ui';
9
9
 
10
- import { type SimpleLayoutState, SimpleLayoutState as SimpleLayoutStateCapability } from '../types';
10
+ import { SimpleLayoutState } from '../types';
11
11
 
12
- export type SimpleLayoutStateHook = {
12
+ export type UseSimpleLayoutState = {
13
13
  state: SimpleLayoutState;
14
14
  updateState: (fn: (current: SimpleLayoutState) => SimpleLayoutState) => void;
15
15
  };
16
16
 
17
- export const useSimpleLayoutState = (): SimpleLayoutStateHook => {
17
+ export const useSimpleLayoutState = (): UseSimpleLayoutState => {
18
18
  const registry = useContext(RegistryContext);
19
- const stateAtom = useCapability(SimpleLayoutStateCapability);
19
+ const stateAtom = useCapability(SimpleLayoutState);
20
20
  const state = useAtomValue(stateAtom);
21
21
 
22
22
  const updateState = useCallback(
package/src/meta.ts CHANGED
@@ -6,7 +6,7 @@ import { type Plugin } from '@dxos/app-framework';
6
6
  import { trim } from '@dxos/util';
7
7
 
8
8
  export const meta: Plugin.Meta = {
9
- id: 'dxos.org/plugin/simple-layout',
9
+ id: 'org.dxos.plugin.simple-layout',
10
10
  name: 'Simple Layout',
11
11
  description: trim`
12
12
  Minimal layout plugin for simplified UI contexts like popover windows.
@@ -5,15 +5,21 @@
5
5
  import { type Atom } from '@effect-atom/atom-react';
6
6
 
7
7
  import { Capability } from '@dxos/app-framework';
8
- import { type DrawerState, type Label } from '@dxos/react-ui';
8
+ import { type Label } from '@dxos/react-ui';
9
9
 
10
10
  import { meta } from '../meta';
11
11
 
12
+ export type DrawerState = 'closed' | 'open' | 'expanded';
13
+
12
14
  // TODO(wittjosiah): Handle toasts.
13
15
  export type SimpleLayoutState = {
14
16
  /** Data to be passed to the main content Surface. */
15
17
  content?: any;
16
18
 
19
+ previousWorkspace: string;
20
+ workspace: string;
21
+ active?: string;
22
+
17
23
  dialogOpen: boolean;
18
24
  dialogType?: 'default' | 'alert';
19
25
  dialogBlockAlign?: 'start' | 'center' | 'end';
@@ -31,9 +37,9 @@ export type SimpleLayoutState = {
31
37
  popoverTitle?: Label;
32
38
  popoverContent?: any;
33
39
 
34
- workspace: string;
35
- previousWorkspace: string;
36
- active?: string;
40
+ /** Bottom drawer state. */
41
+ drawerState: DrawerState;
42
+
37
43
  /** Stack of previously active item IDs for back navigation. */
38
44
  history: string[];
39
45
 
@@ -42,8 +48,6 @@ export type SimpleLayoutState = {
42
48
 
43
49
  /** Variant of the companion to display in the drawer (e.g., "comments", "assistant-chat"). */
44
50
  companionVariant?: string;
45
- /** State of the companion drawer. */
46
- drawerState?: DrawerState;
47
51
  };
48
52
 
49
- export const SimpleLayoutState = Capability.make<Atom.Writable<SimpleLayoutState>>(`${meta.id}/state`);
53
+ export const SimpleLayoutState = Capability.make<Atom.Writable<SimpleLayoutState>>(`${meta.id}.state`);
@@ -2,13 +2,14 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { type ActivationEvent, Common } from '@dxos/app-framework';
5
+ import { type ActivationEvent } from '@dxos/app-framework';
6
+ import { AppActivationEvents } from '@dxos/app-toolkit';
6
7
 
7
8
  import { SimpleLayoutState } from './capabilities';
8
9
 
9
10
  export namespace SimpleLayoutEvents {
10
11
  /** Fired when SimpleLayoutState capability is ready. */
11
- export const StateReady: ActivationEvent.ActivationEvent = Common.ActivationEvent.createStateEvent(
12
+ export const StateReady: ActivationEvent.ActivationEvent = AppActivationEvents.createStateEvent(
12
13
  SimpleLayoutState.identifier,
13
14
  );
14
15
  }