@dxos/plugin-simple-layout 0.8.4-main.21d9917 → 0.8.4-main.3eb6e50203

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/dist/lib/browser/{chunk-CLPGTNWJ.mjs → chunk-7VLT3S46.mjs} +3 -3
  2. package/dist/lib/browser/chunk-7VLT3S46.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-O3BQBYMW.mjs +1165 -0
  4. package/dist/lib/browser/chunk-O3BQBYMW.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +27 -20
  6. package/dist/lib/browser/index.mjs.map +3 -3
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/{operation-resolver-LTB63NKP.mjs → operation-resolver-BYRIQOQT.mjs} +66 -29
  9. package/dist/lib/browser/operation-resolver-BYRIQOQT.mjs.map +7 -0
  10. package/dist/lib/browser/{react-root-6ARAPH3O.mjs → react-root-GPTKI5H2.mjs} +5 -5
  11. package/dist/lib/browser/react-root-GPTKI5H2.mjs.map +7 -0
  12. package/dist/lib/browser/{react-surface-SO7B23GS.mjs → react-surface-LT5JJTPR.mjs} +10 -8
  13. package/dist/lib/browser/react-surface-LT5JJTPR.mjs.map +7 -0
  14. package/dist/lib/browser/{spotlight-dismiss-VSNOPETH.mjs → spotlight-dismiss-67PHYS5B.mjs} +3 -3
  15. package/dist/lib/browser/spotlight-dismiss-67PHYS5B.mjs.map +7 -0
  16. package/dist/lib/browser/{state-H4IGICBB.mjs → state-A3PGDWWZ.mjs} +8 -5
  17. package/dist/lib/browser/state-A3PGDWWZ.mjs.map +7 -0
  18. package/dist/lib/browser/url-handler-HTIUY6WL.mjs +152 -0
  19. package/dist/lib/browser/url-handler-HTIUY6WL.mjs.map +7 -0
  20. package/dist/lib/node-esm/chunk-UAWM4B2S.mjs +1166 -0
  21. package/dist/lib/node-esm/chunk-UAWM4B2S.mjs.map +7 -0
  22. package/dist/lib/node-esm/{chunk-MUVVYBUE.mjs → chunk-VIDE5UMB.mjs} +3 -3
  23. package/dist/lib/node-esm/chunk-VIDE5UMB.mjs.map +7 -0
  24. package/dist/lib/node-esm/index.mjs +27 -20
  25. package/dist/lib/node-esm/index.mjs.map +3 -3
  26. package/dist/lib/node-esm/meta.json +1 -1
  27. package/dist/lib/node-esm/{operation-resolver-7O6O7T4Q.mjs → operation-resolver-BDTFNCS2.mjs} +66 -29
  28. package/dist/lib/node-esm/operation-resolver-BDTFNCS2.mjs.map +7 -0
  29. package/dist/lib/node-esm/{react-root-2CPA2ZUS.mjs → react-root-GRG2OAI2.mjs} +5 -5
  30. package/dist/lib/node-esm/react-root-GRG2OAI2.mjs.map +7 -0
  31. package/dist/lib/node-esm/{react-surface-FKAV56MO.mjs → react-surface-TCUSDIN2.mjs} +10 -8
  32. package/dist/lib/node-esm/react-surface-TCUSDIN2.mjs.map +7 -0
  33. package/dist/lib/node-esm/{spotlight-dismiss-L5PCWIJG.mjs → spotlight-dismiss-RMLRZUVY.mjs} +3 -3
  34. package/dist/lib/node-esm/spotlight-dismiss-RMLRZUVY.mjs.map +7 -0
  35. package/dist/lib/node-esm/{state-QIU2LMLT.mjs → state-ZCFZTTPL.mjs} +8 -5
  36. package/dist/lib/node-esm/state-ZCFZTTPL.mjs.map +7 -0
  37. package/dist/lib/node-esm/url-handler-WBVVKVPC.mjs +153 -0
  38. package/dist/lib/node-esm/url-handler-WBVVKVPC.mjs.map +7 -0
  39. package/dist/types/src/SimpleLayoutPlugin.d.ts.map +1 -1
  40. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +2 -2
  41. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -1
  42. package/dist/types/src/capabilities/react-root/react-root.d.ts.map +1 -1
  43. package/dist/types/src/capabilities/react-surface/index.d.ts +1 -1
  44. package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -1
  45. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +2 -2
  46. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -1
  47. package/dist/types/src/capabilities/spotlight-dismiss/spotlight-dismiss.d.ts.map +1 -1
  48. package/dist/types/src/capabilities/state/state.d.ts.map +1 -1
  49. package/dist/types/src/capabilities/url-handler/url-handler.d.ts +2 -0
  50. package/dist/types/src/capabilities/url-handler/url-handler.d.ts.map +1 -1
  51. package/dist/types/src/components/ContentError.stories.d.ts +6 -0
  52. package/dist/types/src/components/ContentError.stories.d.ts.map +1 -1
  53. package/dist/types/src/components/Home/Home.d.ts.map +1 -1
  54. package/dist/types/src/components/MobileLayout/MobileLayout.d.ts +35 -0
  55. package/dist/types/src/components/MobileLayout/MobileLayout.d.ts.map +1 -0
  56. package/dist/types/src/components/MobileLayout/MobileLayout.stories.d.ts +7 -0
  57. package/dist/types/src/components/MobileLayout/MobileLayout.stories.d.ts.map +1 -0
  58. package/dist/types/src/components/MobileLayout/index.d.ts +2 -0
  59. package/dist/types/src/components/MobileLayout/index.d.ts.map +1 -0
  60. package/dist/types/src/components/SimpleLayout/AppBar.d.ts +26 -0
  61. package/dist/types/src/components/SimpleLayout/AppBar.d.ts.map +1 -0
  62. package/dist/types/src/components/SimpleLayout/AppBar.stories.d.ts +47 -0
  63. package/dist/types/src/components/SimpleLayout/AppBar.stories.d.ts.map +1 -0
  64. package/dist/types/src/components/SimpleLayout/Drawer.d.ts +9 -0
  65. package/dist/types/src/components/SimpleLayout/Drawer.d.ts.map +1 -0
  66. package/dist/types/src/components/SimpleLayout/Main.d.ts +1 -1
  67. package/dist/types/src/components/SimpleLayout/Main.d.ts.map +1 -1
  68. package/dist/types/src/components/SimpleLayout/NavBar.d.ts +13 -3
  69. package/dist/types/src/components/SimpleLayout/NavBar.d.ts.map +1 -1
  70. package/dist/types/src/components/SimpleLayout/NavBar.stories.d.ts +13 -9
  71. package/dist/types/src/components/SimpleLayout/NavBar.stories.d.ts.map +1 -1
  72. package/dist/types/src/components/SimpleLayout/SimpleLayout.d.ts.map +1 -1
  73. package/dist/types/src/components/SimpleLayout/SimpleLayout.stories.d.ts +10 -0
  74. package/dist/types/src/components/SimpleLayout/SimpleLayout.stories.d.ts.map +1 -1
  75. package/dist/types/src/components/SimpleLayout/index.d.ts +3 -0
  76. package/dist/types/src/components/SimpleLayout/index.d.ts.map +1 -1
  77. package/dist/types/src/components/Workspace/Workspace.d.ts +3 -1
  78. package/dist/types/src/components/Workspace/Workspace.d.ts.map +1 -1
  79. package/dist/types/src/components/hooks.d.ts.map +1 -1
  80. package/dist/types/src/components/index.d.ts +1 -0
  81. package/dist/types/src/components/index.d.ts.map +1 -1
  82. package/dist/types/src/hooks/actions.d.ts +20 -0
  83. package/dist/types/src/hooks/actions.d.ts.map +1 -0
  84. package/dist/types/src/hooks/index.d.ts +5 -0
  85. package/dist/types/src/hooks/index.d.ts.map +1 -1
  86. package/dist/types/src/hooks/useAppBarProps.d.ts +7 -0
  87. package/dist/types/src/hooks/useAppBarProps.d.ts.map +1 -0
  88. package/dist/types/src/hooks/useCompanions.d.ts +12 -0
  89. package/dist/types/src/hooks/useCompanions.d.ts.map +1 -0
  90. package/dist/types/src/hooks/useDrawerActions.d.ts +13 -0
  91. package/dist/types/src/hooks/useDrawerActions.d.ts.map +1 -0
  92. package/dist/types/src/hooks/useNavbarActions.d.ts +14 -0
  93. package/dist/types/src/hooks/useNavbarActions.d.ts.map +1 -0
  94. package/dist/types/src/hooks/useSimpleLayoutState.d.ts +3 -3
  95. package/dist/types/src/hooks/useSimpleLayoutState.d.ts.map +1 -1
  96. package/dist/types/src/translations.d.ts +6 -0
  97. package/dist/types/src/translations.d.ts.map +1 -1
  98. package/dist/types/src/types/capabilities.d.ts +8 -3
  99. package/dist/types/src/types/capabilities.d.ts.map +1 -1
  100. package/dist/types/src/types/events.d.ts.map +1 -1
  101. package/dist/types/tsconfig.tsbuildinfo +1 -1
  102. package/package.json +35 -30
  103. package/src/SimpleLayoutPlugin.ts +10 -9
  104. package/src/capabilities/operation-resolver/operation-resolver.ts +65 -26
  105. package/src/capabilities/react-root/react-root.tsx +2 -2
  106. package/src/capabilities/react-surface/react-surface.tsx +6 -5
  107. package/src/capabilities/spotlight-dismiss/spotlight-dismiss.ts +2 -2
  108. package/src/capabilities/state/state.tsx +6 -3
  109. package/src/capabilities/url-handler/url-handler.ts +111 -34
  110. package/src/components/ContentError.stories.tsx +1 -1
  111. package/src/components/ContentLoading.stories.tsx +1 -1
  112. package/src/components/Dialog/Dialog.tsx +4 -4
  113. package/src/components/Home/Home.tsx +21 -19
  114. package/src/components/MobileLayout/MobileLayout.stories.tsx +125 -0
  115. package/src/components/MobileLayout/MobileLayout.tsx +305 -0
  116. package/src/components/MobileLayout/index.ts +5 -0
  117. package/src/components/Popover/Popover.tsx +4 -4
  118. package/src/components/SimpleLayout/AppBar.stories.tsx +144 -0
  119. package/src/components/SimpleLayout/AppBar.tsx +101 -0
  120. package/src/components/SimpleLayout/Drawer.tsx +102 -0
  121. package/src/components/SimpleLayout/Main.tsx +44 -44
  122. package/src/components/SimpleLayout/NavBar.stories.tsx +129 -24
  123. package/src/components/SimpleLayout/NavBar.tsx +24 -58
  124. package/src/components/SimpleLayout/SimpleLayout.stories.tsx +22 -9
  125. package/src/components/SimpleLayout/SimpleLayout.tsx +45 -6
  126. package/src/components/SimpleLayout/index.ts +3 -0
  127. package/src/components/Workspace/Workspace.tsx +14 -10
  128. package/src/components/hooks.ts +9 -13
  129. package/src/components/index.ts +1 -0
  130. package/src/hooks/actions.ts +85 -0
  131. package/src/hooks/index.ts +5 -0
  132. package/src/hooks/useAppBarProps.ts +112 -0
  133. package/src/hooks/useCompanions.ts +22 -0
  134. package/src/hooks/useDrawerActions.ts +98 -0
  135. package/src/hooks/useNavbarActions.ts +86 -0
  136. package/src/hooks/useSimpleLayoutState.ts +5 -5
  137. package/src/translations.ts +6 -0
  138. package/src/types/capabilities.ts +12 -3
  139. package/src/types/events.ts +3 -2
  140. package/dist/lib/browser/chunk-CLPGTNWJ.mjs.map +0 -7
  141. package/dist/lib/browser/chunk-FK4M7GJV.mjs +0 -613
  142. package/dist/lib/browser/chunk-FK4M7GJV.mjs.map +0 -7
  143. package/dist/lib/browser/operation-resolver-LTB63NKP.mjs.map +0 -7
  144. package/dist/lib/browser/react-root-6ARAPH3O.mjs.map +0 -7
  145. package/dist/lib/browser/react-surface-SO7B23GS.mjs.map +0 -7
  146. package/dist/lib/browser/spotlight-dismiss-VSNOPETH.mjs.map +0 -7
  147. package/dist/lib/browser/state-H4IGICBB.mjs.map +0 -7
  148. package/dist/lib/browser/url-handler-7CFGTLNG.mjs +0 -54
  149. package/dist/lib/browser/url-handler-7CFGTLNG.mjs.map +0 -7
  150. package/dist/lib/node-esm/chunk-EGFZAVBD.mjs +0 -614
  151. package/dist/lib/node-esm/chunk-EGFZAVBD.mjs.map +0 -7
  152. package/dist/lib/node-esm/chunk-MUVVYBUE.mjs.map +0 -7
  153. package/dist/lib/node-esm/operation-resolver-7O6O7T4Q.mjs.map +0 -7
  154. package/dist/lib/node-esm/react-root-2CPA2ZUS.mjs.map +0 -7
  155. package/dist/lib/node-esm/react-surface-FKAV56MO.mjs.map +0 -7
  156. package/dist/lib/node-esm/spotlight-dismiss-L5PCWIJG.mjs.map +0 -7
  157. package/dist/lib/node-esm/state-QIU2LMLT.mjs.map +0 -7
  158. package/dist/lib/node-esm/url-handler-4LYP3JM7.mjs +0 -55
  159. package/dist/lib/node-esm/url-handler-4LYP3JM7.mjs.map +0 -7
  160. package/dist/types/src/components/SimpleLayout/Banner.d.ts +0 -8
  161. package/dist/types/src/components/SimpleLayout/Banner.d.ts.map +0 -1
  162. package/src/components/SimpleLayout/Banner.tsx +0 -82
@@ -0,0 +1,1165 @@
1
+ import {
2
+ SimpleLayoutState,
3
+ meta
4
+ } from "./chunk-7VLT3S46.mjs";
5
+
6
+ // src/components/Home/Home.tsx
7
+ import React, { useCallback, useEffect as useEffect2, useMemo, useRef } from "react";
8
+ import { useOperationInvoker } from "@dxos/app-framework/ui";
9
+ import { LayoutOperation } from "@dxos/app-toolkit";
10
+ import { useAppGraph as useAppGraph2 } from "@dxos/app-toolkit/ui";
11
+ import { Node, useConnections } from "@dxos/plugin-graph";
12
+ import { Avatar, Icon, Layout, ScrollArea, Toolbar, toLocalizedString, useTranslation } from "@dxos/react-ui";
13
+ import { Card, Mosaic } from "@dxos/react-ui-mosaic";
14
+ import { SearchList, useSearchListItem, useSearchListResults } from "@dxos/react-ui-searchlist";
15
+ import { mx } from "@dxos/ui-theme";
16
+ import { byPosition } from "@dxos/util";
17
+
18
+ // src/components/hooks.ts
19
+ import { useEffect } from "react";
20
+ import { useAppGraph } from "@dxos/app-toolkit/ui";
21
+ import { Graph } from "@dxos/plugin-graph";
22
+ var useLoadDescendents = (nodeId) => {
23
+ const { graph } = useAppGraph();
24
+ useEffect(() => {
25
+ if (nodeId) {
26
+ Graph.expand(graph, nodeId, "outbound");
27
+ Graph.getConnections(graph, nodeId, "outbound").forEach((child) => {
28
+ Graph.expand(graph, child.id, "outbound");
29
+ });
30
+ }
31
+ }, [
32
+ nodeId,
33
+ graph
34
+ ]);
35
+ };
36
+
37
+ // src/components/Home/Home.tsx
38
+ var Home = (_) => {
39
+ const { t } = useTranslation(meta.id);
40
+ const userAccountItem = useItemsByDisposition("user-account")[0];
41
+ const pinnedItems = useItemsByDisposition("pin-end", true);
42
+ const workspaceItems = useItemsByDisposition("workspace");
43
+ useLoadDescendents(Node.RootId);
44
+ const items = useMemo(() => [
45
+ ...userAccountItem ? [
46
+ userAccountItem
47
+ ] : [],
48
+ ...pinnedItems,
49
+ ...workspaceItems
50
+ ], [
51
+ userAccountItem,
52
+ pinnedItems,
53
+ workspaceItems
54
+ ]);
55
+ const { results, handleSearch } = useSearchListResults({
56
+ items,
57
+ extract: (node) => toLocalizedString(node.properties.label, t)
58
+ });
59
+ return /* @__PURE__ */ React.createElement(Layout.Main, {
60
+ toolbar: true
61
+ }, /* @__PURE__ */ React.createElement(SearchList.Root, {
62
+ onSearch: handleSearch
63
+ }, /* @__PURE__ */ React.createElement(Toolbar.Root, null, /* @__PURE__ */ React.createElement(SearchList.Input, {
64
+ placeholder: t("search placeholder"),
65
+ autoFocus: true
66
+ })), /* @__PURE__ */ React.createElement(SearchList.Content, null, /* @__PURE__ */ React.createElement(Mosaic.Container, {
67
+ asChild: true
68
+ }, /* @__PURE__ */ React.createElement(ScrollArea.Root, {
69
+ orientation: "vertical"
70
+ }, /* @__PURE__ */ React.createElement(ScrollArea.Viewport, {
71
+ classNames: "p-2"
72
+ }, /* @__PURE__ */ React.createElement(Mosaic.Stack, {
73
+ items: results,
74
+ getId: (node) => node.id,
75
+ Tile: WorkspaceTile
76
+ })))))));
77
+ };
78
+ var WorkspaceTile = ({ data }) => {
79
+ const { t } = useTranslation(meta.id);
80
+ const { invokePromise } = useOperationInvoker();
81
+ const { selectedValue, registerItem, unregisterItem } = useSearchListItem();
82
+ const name = toLocalizedString(data.properties.label, t);
83
+ const isSelected = selectedValue === data.id;
84
+ const cardRef = useRef(null);
85
+ useLoadDescendents(data.id);
86
+ const handleSelect = useCallback(() => invokePromise(LayoutOperation.SwitchWorkspace, {
87
+ subject: data.id
88
+ }), [
89
+ invokePromise,
90
+ data.id
91
+ ]);
92
+ useEffect2(() => {
93
+ if (cardRef.current) {
94
+ registerItem(data.id, cardRef.current, handleSelect);
95
+ }
96
+ return () => unregisterItem(data.id);
97
+ }, [
98
+ data.id,
99
+ handleSelect,
100
+ registerItem,
101
+ unregisterItem
102
+ ]);
103
+ useEffect2(() => {
104
+ if (isSelected && cardRef.current) {
105
+ cardRef.current.scrollIntoView({
106
+ block: "nearest",
107
+ behavior: "smooth"
108
+ });
109
+ }
110
+ }, [
111
+ isSelected
112
+ ]);
113
+ return /* @__PURE__ */ React.createElement(Card.Root, {
114
+ role: "button",
115
+ fullWidth: true,
116
+ tabIndex: -1,
117
+ "data-selected": isSelected,
118
+ classNames: mx("dx-focus-ring", isSelected && "bg-hoverOverlay"),
119
+ onClick: handleSelect,
120
+ ref: cardRef
121
+ }, /* @__PURE__ */ React.createElement(Card.Toolbar, {
122
+ density: "coarse"
123
+ }, /* @__PURE__ */ React.createElement(Avatar.Root, null, /* @__PURE__ */ React.createElement(Avatar.Content, {
124
+ icon: data.properties.icon,
125
+ hue: data.properties.hue,
126
+ hueVariant: "transparent",
127
+ variant: "square",
128
+ size: 12,
129
+ fallback: name
130
+ }), /* @__PURE__ */ React.createElement(Avatar.Label, null, name), /* @__PURE__ */ React.createElement(Icon, {
131
+ icon: "ph--caret-right--regular"
132
+ }))));
133
+ };
134
+ var filterItems = (node, disposition) => {
135
+ return node.properties.disposition === disposition;
136
+ };
137
+ var useItemsByDisposition = (disposition, sort = false) => {
138
+ const { graph } = useAppGraph2();
139
+ const connections = useConnections(graph, Node.RootId);
140
+ const filtered = connections.filter((node) => filterItems(node, disposition));
141
+ return sort ? filtered.toSorted((a, b) => byPosition(a.properties, b.properties)) : filtered;
142
+ };
143
+
144
+ // src/components/SimpleLayout/SimpleLayout.tsx
145
+ import React12, { useEffect as useEffect6, useRef as useRef4, useState as useState3 } from "react";
146
+ import { Splitter } from "@dxos/react-ui";
147
+ import { Mosaic as Mosaic3 } from "@dxos/react-ui-mosaic";
148
+
149
+ // src/hooks/useAppBarProps.ts
150
+ import { Atom, useAtomValue } from "@effect-atom/atom-react";
151
+ import * as Effect from "effect/Effect";
152
+ import * as Option from "effect/Option";
153
+ import { useCallback as useCallback2, useMemo as useMemo2 } from "react";
154
+ import { useCapability, useOperationInvoker as useOperationInvoker2 } from "@dxos/app-framework/ui";
155
+ import { LayoutOperation as LayoutOperation2 } from "@dxos/app-toolkit";
156
+ import { useAppGraph as useAppGraph3 } from "@dxos/app-toolkit/ui";
157
+ import { Graph as Graph2, Node as Node2, useActionRunner, useNode } from "@dxos/plugin-graph";
158
+ import { toLocalizedString as toLocalizedString2, useTranslation as useTranslation2 } from "@dxos/react-ui";
159
+ var useAppBarProps = () => {
160
+ const { t } = useTranslation2(meta.id);
161
+ const stateAtom = useCapability(SimpleLayoutState);
162
+ const state = useAtomValue(stateAtom);
163
+ const { graph } = useAppGraph3();
164
+ const { invokeSync } = useOperationInvoker2();
165
+ const runAction = useActionRunner();
166
+ const activeId = state.active ?? state.workspace;
167
+ const node = useNode(graph, activeId);
168
+ const title = node ? toLocalizedString2(node.properties.label, t) : void 0;
169
+ const actionsAtom = useMemo2(() => Atom.make((get) => {
170
+ const state2 = get(stateAtom);
171
+ const activeId2 = state2.active ?? state2.workspace;
172
+ const allActions = activeId2 ? get(graph.actions(activeId2)) : [];
173
+ const filtered = allActions.filter((action) => [
174
+ "list-item",
175
+ "list-item-primary",
176
+ "heading-list-item"
177
+ ].includes(action.properties.disposition));
178
+ const nodes = filtered;
179
+ const edges = filtered.map((action) => ({
180
+ source: "root",
181
+ target: action.id
182
+ }));
183
+ const workspaceConnections = state2.workspace ? get(graph.connections(state2.workspace)) : [];
184
+ const alternateTreeNode = workspaceConnections.find((node2) => node2.properties.disposition === "alternate-tree");
185
+ if (alternateTreeNode && activeId2 !== alternateTreeNode.id) {
186
+ const settingsAction = {
187
+ id: `appbar-settings-${alternateTreeNode.id}`,
188
+ type: Node2.ActionType,
189
+ data: () => Effect.sync(() => invokeSync(LayoutOperation2.Open, {
190
+ subject: [
191
+ alternateTreeNode.id
192
+ ]
193
+ })),
194
+ properties: {
195
+ label: alternateTreeNode.properties.label ?? alternateTreeNode.id,
196
+ icon: alternateTreeNode.properties.icon ?? "ph--placeholder--regular"
197
+ }
198
+ };
199
+ nodes.push(settingsAction);
200
+ edges.push({
201
+ source: "root",
202
+ target: settingsAction.id
203
+ });
204
+ }
205
+ return {
206
+ nodes,
207
+ edges
208
+ };
209
+ }), [
210
+ graph,
211
+ stateAtom
212
+ ]);
213
+ const showBackButton = activeId !== void 0 && activeId !== Node2.RootId;
214
+ const onBack = useCallback2(() => {
215
+ if (state.active) {
216
+ const isWorkspace = Graph2.getNode(graph, state.active).pipe(Option.map((node2) => node2.properties.disposition === "workspace"), Option.getOrElse(() => false));
217
+ if (state.history.length === 0 && isWorkspace) {
218
+ invokeSync(LayoutOperation2.SwitchWorkspace, {
219
+ subject: Node2.RootId
220
+ });
221
+ } else {
222
+ invokeSync(LayoutOperation2.Close, {
223
+ subject: [
224
+ state.active
225
+ ]
226
+ });
227
+ }
228
+ } else {
229
+ invokeSync(LayoutOperation2.SwitchWorkspace, {
230
+ subject: Node2.RootId
231
+ });
232
+ }
233
+ }, [
234
+ graph,
235
+ invokeSync,
236
+ state.active,
237
+ state.history.length
238
+ ]);
239
+ const popoverAnchorId = node && state.popoverAnchorId === `dxos.org/ui/${meta.id}/${node.id}` ? state.popoverAnchorId : void 0;
240
+ return {
241
+ title,
242
+ actions: actionsAtom,
243
+ showBackButton,
244
+ popoverAnchorId,
245
+ onBack,
246
+ onAction: runAction
247
+ };
248
+ };
249
+
250
+ // src/hooks/useCompanions.ts
251
+ import { useMemo as useMemo3 } from "react";
252
+ import { useAppGraph as useAppGraph4 } from "@dxos/app-toolkit/ui";
253
+ import { useConnections as useConnections2 } from "@dxos/plugin-graph";
254
+ import { byPosition as byPosition3 } from "@dxos/util";
255
+
256
+ // src/hooks/actions.ts
257
+ import * as Effect2 from "effect/Effect";
258
+ import { LayoutOperation as LayoutOperation3 } from "@dxos/app-toolkit";
259
+ import { Node as Node3 } from "@dxos/plugin-graph";
260
+ import { ATTENDABLE_PATH_SEPARATOR } from "@dxos/react-ui-attention";
261
+ import { byPosition as byPosition2 } from "@dxos/util";
262
+ var PLANK_COMPANION_TYPE = "dxos.org/plugin/deck/plank-companion";
263
+ var createCompanionActions = (graph, stateAtom, get, config) => {
264
+ const { idPrefix, selectedVariant, invokeSync } = config;
265
+ const state = get(stateAtom);
266
+ const activeId = state.active ?? state.workspace;
267
+ const activeConnections = activeId ? get(graph.connections(activeId)) : [];
268
+ const companions = activeConnections.filter((node) => node.type === PLANK_COMPANION_TYPE).toSorted((a, b) => byPosition2(a.properties, b.properties));
269
+ const nodes = [];
270
+ const edges = [];
271
+ companions.forEach((companion) => {
272
+ const [, companionVariant] = companion.id.split(ATTENDABLE_PATH_SEPARATOR);
273
+ const companionAction = {
274
+ id: `${idPrefix}-companion-${companion.id}`,
275
+ type: Node3.ActionType,
276
+ properties: {
277
+ icon: companion.properties.icon ?? "ph--placeholder--regular",
278
+ label: companion.properties.label,
279
+ iconOnly: true,
280
+ // Conditionally add variant highlighting.
281
+ ...selectedVariant !== void 0 && {
282
+ variant: selectedVariant === companionVariant ? "primary" : "ghost"
283
+ }
284
+ },
285
+ data: () => Effect2.sync(() => invokeSync(LayoutOperation3.Open, {
286
+ subject: [
287
+ companion.id
288
+ ]
289
+ }))
290
+ };
291
+ nodes.push(companionAction);
292
+ edges.push({
293
+ source: "root",
294
+ target: companionAction.id
295
+ });
296
+ });
297
+ return {
298
+ nodes,
299
+ edges
300
+ };
301
+ };
302
+
303
+ // src/hooks/useCompanions.ts
304
+ var useCompanions = (nodeId) => {
305
+ const { graph } = useAppGraph4();
306
+ const nodes = useConnections2(graph, nodeId);
307
+ const companions = nodes.filter((node) => node.type === PLANK_COMPANION_TYPE);
308
+ return useMemo3(() => companions.toSorted((a, b) => byPosition3(a.properties, b.properties)), [
309
+ companions
310
+ ]);
311
+ };
312
+
313
+ // src/hooks/useDrawerActions.ts
314
+ import { Atom as Atom2 } from "@effect-atom/atom-react";
315
+ import * as Effect3 from "effect/Effect";
316
+ import { useMemo as useMemo6 } from "react";
317
+ import { useCapability as useCapability3, useOperationInvoker as useOperationInvoker4 } from "@dxos/app-framework/ui";
318
+ import { useAppGraph as useAppGraph7 } from "@dxos/app-toolkit/ui";
319
+ import { Node as Node4, useActionRunner as useActionRunner2 } from "@dxos/plugin-graph";
320
+ import { useTranslation as useTranslation7 } from "@dxos/react-ui";
321
+ import { createGapSeparator } from "@dxos/react-ui-menu";
322
+
323
+ // src/components/ContentLoading.tsx
324
+ import React2 from "react";
325
+ var ContentLoading = () => {
326
+ return /* @__PURE__ */ React2.createElement("div", {
327
+ role: "none",
328
+ className: "grid place-items-center attention-surface"
329
+ });
330
+ };
331
+
332
+ // src/components/MobileLayout/MobileLayout.tsx
333
+ import { createContext } from "@radix-ui/react-context";
334
+ import React3, { forwardRef, useEffect as useEffect3, useState } from "react";
335
+ import { addEventListener, combine } from "@dxos/async";
336
+ import { log } from "@dxos/log";
337
+ import { mx as mx2 } from "@dxos/ui-theme";
338
+ var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-simple-layout/src/components/MobileLayout/MobileLayout.tsx";
339
+ var MOBILE_LAYOUT_NAME = "MobileLayout";
340
+ var MOBILE_LAYOUT_ROOT_NAME = "MobileLayout.Root";
341
+ var MOBILE_LAYOUT_PANEL_NAME = "MobileLayout.Panel";
342
+ var [MobileLayoutProvider, useMobileLayout] = createContext(MOBILE_LAYOUT_NAME);
343
+ var MobileLayoutRoot = /* @__PURE__ */ forwardRef(({ classNames, children, transition = 250, onKeyboardOpenChange, ...props }, forwardedRef) => {
344
+ const { open: keyboardOpen } = useIOSKeyboard();
345
+ useAutoScroll();
346
+ useEffect3(() => onKeyboardOpenChange?.(keyboardOpen), [
347
+ onKeyboardOpenChange,
348
+ keyboardOpen
349
+ ]);
350
+ useLockBodyScroll(keyboardOpen);
351
+ return /* @__PURE__ */ React3.createElement(MobileLayoutProvider, {
352
+ keyboardOpen
353
+ }, /* @__PURE__ */ React3.createElement("div", {
354
+ ...props,
355
+ role: "none",
356
+ style: {
357
+ transition: `block-size ${transition}ms ease-out`,
358
+ blockSize: "calc(100vh - var(--kb-height, 0px))"
359
+ },
360
+ className: mx2("absolute top-0 left-0 right-0 flex flex-col", classNames),
361
+ ref: forwardedRef
362
+ }, children));
363
+ });
364
+ MobileLayoutRoot.displayName = MOBILE_LAYOUT_ROOT_NAME;
365
+ var MobileLayoutPanel = /* @__PURE__ */ forwardRef(({ classNames, children, safe, ...props }, forwardedRef) => {
366
+ return /* @__PURE__ */ React3.createElement("div", {
367
+ ...props,
368
+ role: "none",
369
+ style: {
370
+ paddingTop: safe?.top ? "env(safe-area-inset-top)" : void 0,
371
+ paddingBottom: safe?.bottom ? `calc((1 - var(--kb-open, 0)) * env(safe-area-inset-bottom))` : void 0
372
+ },
373
+ className: mx2("relative bs-full flex flex-col overflow-hidden", classNames),
374
+ ref: forwardedRef
375
+ }, children);
376
+ });
377
+ MobileLayoutPanel.displayName = MOBILE_LAYOUT_PANEL_NAME;
378
+ var MobileLayout = {
379
+ Root: MobileLayoutRoot,
380
+ Panel: MobileLayoutPanel
381
+ };
382
+ var useAutoScroll = () => {
383
+ useEffect3(() => {
384
+ return addEventListener(
385
+ document,
386
+ "focus",
387
+ (event) => {
388
+ const target = event.target;
389
+ if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.tagName === "DIV" && target.isContentEditable) {
390
+ event.preventDefault();
391
+ target.focus({
392
+ preventScroll: true
393
+ });
394
+ const scrollX = window.scrollX;
395
+ const scrollY = window.scrollY;
396
+ requestAnimationFrame(() => {
397
+ window.scrollTo(scrollX, scrollY);
398
+ });
399
+ }
400
+ },
401
+ // Important: focus events don't bubble, so capture phase is required.
402
+ {
403
+ capture: true
404
+ }
405
+ );
406
+ }, []);
407
+ };
408
+ var useLockBodyScroll = (enabled) => {
409
+ useEffect3(() => {
410
+ if (!enabled) {
411
+ return;
412
+ }
413
+ const isScrollable = (el, axis) => {
414
+ while (el && el !== document.body) {
415
+ const style = getComputedStyle(el);
416
+ if (axis === "y") {
417
+ const overflow = style.overflowY;
418
+ if ((overflow === "auto" || overflow === "scroll") && el.scrollHeight > el.clientHeight) {
419
+ return true;
420
+ }
421
+ } else {
422
+ const overflow = style.overflowX;
423
+ if ((overflow === "auto" || overflow === "scroll") && el.scrollWidth > el.clientWidth) {
424
+ return true;
425
+ }
426
+ }
427
+ el = el.parentElement;
428
+ }
429
+ return false;
430
+ };
431
+ let touchStartX = 0;
432
+ let touchStartY = 0;
433
+ return combine(
434
+ // Record initial touch position.
435
+ addEventListener(document, "touchstart", (event) => {
436
+ const touch = event.touches[0];
437
+ touchStartX = touch.clientX;
438
+ touchStartY = touch.clientY;
439
+ }, {
440
+ passive: true
441
+ }),
442
+ // Prevent scrolling the viewport.
443
+ addEventListener(document, "touchmove", (event) => {
444
+ const touch = event.touches[0];
445
+ const dx = Math.abs(touch.clientX - touchStartX);
446
+ const dy = Math.abs(touch.clientY - touchStartY);
447
+ if (!isScrollable(event.target, dx > dy ? "x" : "y")) {
448
+ event.preventDefault();
449
+ }
450
+ }, {
451
+ passive: false
452
+ })
453
+ );
454
+ }, [
455
+ enabled
456
+ ]);
457
+ };
458
+ var useIOSKeyboard = () => {
459
+ const [open, setOpen] = useState(false);
460
+ const [height, setHeight] = useState(0);
461
+ useEffect3(() => {
462
+ const viewport = window.visualViewport;
463
+ if (!viewport) {
464
+ return;
465
+ }
466
+ const initialHeight = viewport.height ?? window.innerHeight;
467
+ const updateState = (keyboardHeight, keyboardOpen) => {
468
+ setOpen(keyboardOpen);
469
+ setHeight(keyboardHeight);
470
+ const vvh = initialHeight - keyboardHeight;
471
+ document.documentElement.style.setProperty("--vvh", `${vvh}px`);
472
+ document.documentElement.style.setProperty("--kb-height", `${keyboardHeight}px`);
473
+ document.documentElement.style.setProperty("--kb-open", keyboardOpen ? "1" : "0");
474
+ log.info("viewport size", {
475
+ initialHeight,
476
+ vvh,
477
+ keyboardHeight,
478
+ keyboardOpen
479
+ }, {
480
+ F: __dxlog_file,
481
+ L: 287,
482
+ S: void 0,
483
+ C: (f, a) => f(...a)
484
+ });
485
+ };
486
+ return combine(
487
+ // Handler for native iOS keyboard events (from KeyboardObserver.swift).
488
+ addEventListener(window, "keyboard", (event) => {
489
+ const { type, height: height2 } = event.detail;
490
+ log.info("keyboard event", {
491
+ type,
492
+ height: height2
493
+ }, {
494
+ F: __dxlog_file,
495
+ L: 297,
496
+ S: void 0,
497
+ C: (f, a) => f(...a)
498
+ });
499
+ updateState(height2, type === "show");
500
+ })
501
+ );
502
+ }, []);
503
+ return {
504
+ open,
505
+ height
506
+ };
507
+ };
508
+
509
+ // src/components/Popover/Popover.tsx
510
+ import { createContext as createContext2 } from "@radix-ui/react-context";
511
+ import React4, { useCallback as useCallback3, useEffect as useEffect4, useMemo as useMemo4, useRef as useRef2, useState as useState2 } from "react";
512
+ import { Surface } from "@dxos/app-framework/ui";
513
+ import { Popover, toLocalizedString as toLocalizedString3, useTranslation as useTranslation3 } from "@dxos/react-ui";
514
+ import { Card as Card2 } from "@dxos/react-ui-mosaic";
515
+ var DEBOUNCE_DELAY = 40;
516
+ var [LayoutPopoverProvider, useLayoutPopoverContext] = createContext2("LayoutPopover");
517
+ var PopoverRoot = ({ children }) => {
518
+ const { state } = useSimpleLayoutState();
519
+ const [open, setOpen] = useState2(false);
520
+ const virtualRef = useRef2(null);
521
+ const [virtualIter, setVirtualIter] = useState2(0);
522
+ const debounceRef = useRef2(null);
523
+ useEffect4(() => {
524
+ setOpen(false);
525
+ if (state.popoverOpen) {
526
+ if (debounceRef.current) {
527
+ clearTimeout(debounceRef.current);
528
+ }
529
+ if (state.popoverAnchor && virtualRef.current !== state.popoverAnchor) {
530
+ virtualRef.current = state.popoverAnchor ?? null;
531
+ setVirtualIter((iter) => iter + 1);
532
+ }
533
+ debounceRef.current = setTimeout(() => setOpen(true), DEBOUNCE_DELAY);
534
+ }
535
+ }, [
536
+ state.popoverOpen,
537
+ state.popoverAnchorId,
538
+ state.popoverAnchor,
539
+ state.popoverContent
540
+ ]);
541
+ return /* @__PURE__ */ React4.createElement(LayoutPopoverProvider, {
542
+ setOpen
543
+ }, /* @__PURE__ */ React4.createElement(Popover.Root, {
544
+ modal: false,
545
+ open
546
+ }, state.popoverAnchor && /* @__PURE__ */ React4.createElement(Popover.VirtualTrigger, {
547
+ key: virtualIter,
548
+ virtualRef
549
+ }), children));
550
+ };
551
+ var PopoverContent = () => {
552
+ const { t } = useTranslation3(meta.id);
553
+ const { state, updateState } = useSimpleLayoutState();
554
+ const { setOpen } = useLayoutPopoverContext("PopoverContent");
555
+ const handleClose = useCallback3(() => {
556
+ setOpen(false);
557
+ updateState((s) => ({
558
+ ...s,
559
+ popoverOpen: false,
560
+ popoverAnchor: void 0,
561
+ popoverAnchorId: void 0,
562
+ popoverSide: void 0
563
+ }));
564
+ }, [
565
+ setOpen,
566
+ updateState
567
+ ]);
568
+ const handleInteractOutside = useCallback3((event) => {
569
+ if (
570
+ // TODO(thure): CodeMirror should not focus itself when it updates.
571
+ event.type === "dismissableLayer.focusOutside" && event.currentTarget?.classList.contains("cm-content")
572
+ ) {
573
+ event.preventDefault();
574
+ } else {
575
+ handleClose();
576
+ }
577
+ }, [
578
+ handleClose
579
+ ]);
580
+ const collisionBoundaries = useMemo4(() => {
581
+ const closest = state.popoverAnchor?.closest("[data-popover-collision-boundary]");
582
+ return closest ? [
583
+ closest
584
+ ] : [];
585
+ }, [
586
+ state.popoverAnchor
587
+ ]);
588
+ return /* @__PURE__ */ React4.createElement(Popover.Portal, null, /* @__PURE__ */ React4.createElement(Popover.Content, {
589
+ side: state.popoverSide,
590
+ sticky: "always",
591
+ hideWhenDetached: true,
592
+ collisionBoundary: collisionBoundaries,
593
+ onInteractOutside: handleInteractOutside,
594
+ onEscapeKeyDown: handleInteractOutside
595
+ }, /* @__PURE__ */ React4.createElement(Popover.Viewport, null, state.popoverKind === "base" && /* @__PURE__ */ React4.createElement(Surface.Surface, {
596
+ role: "popover",
597
+ data: state.popoverContent,
598
+ limit: 1
599
+ }), state.popoverKind === "card" && /* @__PURE__ */ React4.createElement(Card2.Root, {
600
+ border: false,
601
+ classNames: "popover-card-max-width"
602
+ }, /* @__PURE__ */ React4.createElement(Card2.Toolbar, null, /* @__PURE__ */ React4.createElement("span", null), state.popoverTitle ? /* @__PURE__ */ React4.createElement(Card2.Title, null, toLocalizedString3(state.popoverTitle, t)) : /* @__PURE__ */ React4.createElement("span", null), /* @__PURE__ */ React4.createElement(Card2.Close, {
603
+ onClick: handleClose
604
+ })), /* @__PURE__ */ React4.createElement(Surface.Surface, {
605
+ role: "card--content",
606
+ data: state.popoverContent,
607
+ limit: 1
608
+ }))), /* @__PURE__ */ React4.createElement(Popover.Arrow, null)));
609
+ };
610
+
611
+ // src/components/SimpleLayout/AppBar.tsx
612
+ import { useAtomValue as useAtomValue2 } from "@effect-atom/atom-react";
613
+ import React5, { Fragment } from "react";
614
+ import { IconButton, Popover as Popover2, Toolbar as Toolbar2, useTranslation as useTranslation4 } from "@dxos/react-ui";
615
+ import { DropdownMenu, MenuProvider, useMenuActions } from "@dxos/react-ui-menu";
616
+ import { mx as mx3, osTranslations } from "@dxos/ui-theme";
617
+ var APP_BAR_NAME = "SimpleLayout.AppBar";
618
+ var AppBar = ({ classNames, title, actions, showBackButton, popoverAnchorId, onAction, onBack }) => {
619
+ const { t } = useTranslation4(meta.id);
620
+ const menu = useMenuActions(actions);
621
+ const actionsValue = useAtomValue2(actions);
622
+ const hasActions = actionsValue.nodes.length > 0;
623
+ const { keyboardOpen } = useMobileLayout(APP_BAR_NAME);
624
+ const displayTitle = title ?? t("current app name", {
625
+ ns: osTranslations
626
+ });
627
+ const AnchorRoot = popoverAnchorId ? Popover2.Anchor : Fragment;
628
+ return /* @__PURE__ */ React5.createElement(Toolbar2.Root, {
629
+ role: "banner",
630
+ classNames: mx3("grid grid-cols-[var(--rail-size)_1fr_var(--rail-size)] bs-[var(--rail-action)] items-center", "density-fine", classNames)
631
+ }, keyboardOpen ? /* @__PURE__ */ React5.createElement(IconButton, {
632
+ variant: "ghost",
633
+ icon: "ph--x--regular",
634
+ iconOnly: true,
635
+ label: t("done label")
636
+ }) : showBackButton ? /* @__PURE__ */ React5.createElement(IconButton, {
637
+ variant: "ghost",
638
+ icon: "ph--caret-left--regular",
639
+ iconOnly: true,
640
+ label: t("back label"),
641
+ onClick: onBack
642
+ }) : /* @__PURE__ */ React5.createElement("div", null), /* @__PURE__ */ React5.createElement("h1", {
643
+ className: "text-center truncate font-thin uppercase"
644
+ }, displayTitle), hasActions ? /* @__PURE__ */ React5.createElement(AnchorRoot, null, /* @__PURE__ */ React5.createElement(MenuProvider, {
645
+ ...menu,
646
+ onAction
647
+ }, /* @__PURE__ */ React5.createElement(DropdownMenu.Root, {
648
+ caller: meta.id
649
+ }, /* @__PURE__ */ React5.createElement(DropdownMenu.Trigger, {
650
+ asChild: true
651
+ }, /* @__PURE__ */ React5.createElement(IconButton, {
652
+ variant: "ghost",
653
+ icon: "ph--dots-three-vertical--regular",
654
+ iconOnly: true,
655
+ label: t("actions menu label")
656
+ }))))) : /* @__PURE__ */ React5.createElement("span", null));
657
+ };
658
+ AppBar.displayName = APP_BAR_NAME;
659
+
660
+ // src/components/SimpleLayout/Main.tsx
661
+ import React8, { useMemo as useMemo5 } from "react";
662
+ import { Surface as Surface2 } from "@dxos/app-framework/ui";
663
+ import { useAppGraph as useAppGraph5 } from "@dxos/app-toolkit/ui";
664
+ import { useNode as useNode2 } from "@dxos/plugin-graph";
665
+ import { useAttentionAttributes } from "@dxos/react-ui-attention";
666
+ import { mx as mx6 } from "@dxos/ui-theme";
667
+
668
+ // src/components/ContentError.tsx
669
+ import React6 from "react";
670
+ import { useTranslation as useTranslation5 } from "@dxos/react-ui";
671
+ import { descriptionMessage, mx as mx4 } from "@dxos/ui-theme";
672
+ var ContentError = ({ error }) => {
673
+ const { t } = useTranslation5(meta.id);
674
+ const errorString = error?.toString() ?? "";
675
+ return /* @__PURE__ */ React6.createElement("div", {
676
+ role: "none",
677
+ className: "grid place-items-center overflow-y-auto attention-surface"
678
+ }, /* @__PURE__ */ React6.createElement("p", {
679
+ role: "alert",
680
+ className: mx4(descriptionMessage, "p-2 break-all rounded-sm")
681
+ }, error ? errorString : t("error fallback message")));
682
+ };
683
+
684
+ // src/components/SimpleLayout/NavBar.tsx
685
+ import React7 from "react";
686
+ import { MenuProvider as MenuProvider2, ToolbarMenu, useMenuActions as useMenuActions2 } from "@dxos/react-ui-menu";
687
+ import { mx as mx5 } from "@dxos/ui-theme";
688
+ var NAVBAR_NAME = "SimpleLayout.NavBar";
689
+ var NavBar = ({ classNames, actions, onAction }) => {
690
+ const menu = useMenuActions2(actions);
691
+ return /* @__PURE__ */ React7.createElement(MenuProvider2, {
692
+ ...menu,
693
+ onAction,
694
+ alwaysActive: true
695
+ }, /* @__PURE__ */ React7.createElement(ToolbarMenu, {
696
+ density: "coarse",
697
+ classNames: mx5(classNames)
698
+ }));
699
+ };
700
+ NavBar.displayName = NAVBAR_NAME;
701
+
702
+ // src/components/SimpleLayout/Main.tsx
703
+ var MAIN_NAME = "SimpleLayout.Main";
704
+ var Main = () => {
705
+ const { state } = useSimpleLayoutState();
706
+ const id = state.active ?? state.workspace;
707
+ const attentionAttrs = useAttentionAttributes(id);
708
+ const { keyboardOpen } = useMobileLayout(MAIN_NAME);
709
+ const { actions, onAction } = useNavbarActions();
710
+ const appBarProps = useAppBarProps();
711
+ const placeholder = useMemo5(() => /* @__PURE__ */ React8.createElement(ContentLoading, null), []);
712
+ const { graph } = useAppGraph5();
713
+ const node = useNode2(graph, id);
714
+ const data = useMemo5(() => {
715
+ return node && {
716
+ attendableId: id,
717
+ subject: node.data,
718
+ properties: node.properties,
719
+ popoverAnchorId: state.popoverAnchorId
720
+ };
721
+ }, [
722
+ id,
723
+ node,
724
+ node?.data,
725
+ node?.properties,
726
+ state.popoverAnchorId
727
+ ]);
728
+ useLoadDescendents(id);
729
+ const showNavBar = !keyboardOpen && !state.isPopover && state.drawerState === "closed";
730
+ return /* @__PURE__ */ React8.createElement("div", {
731
+ role: "none",
732
+ className: mx6("bs-full grid overflow-hidden bg-toolbarSurface", showNavBar ? "grid-rows-[var(--rail-action)_1fr_var(--toolbar-size)]" : "grid-rows-[var(--rail-action)_1fr]"),
733
+ ...attentionAttrs
734
+ }, /* @__PURE__ */ React8.createElement(AppBar, appBarProps), /* @__PURE__ */ React8.createElement("article", {
735
+ className: "bs-full overflow-hidden bg-baseSurface"
736
+ }, /* @__PURE__ */ React8.createElement(Surface2.Surface, {
737
+ key: id,
738
+ role: "article",
739
+ data,
740
+ limit: 1,
741
+ fallback: ContentError,
742
+ placeholder
743
+ })), showNavBar && /* @__PURE__ */ React8.createElement(NavBar, {
744
+ classNames: "border-bs border-subduedSeparator",
745
+ actions,
746
+ onAction
747
+ }));
748
+ };
749
+ Main.displayName = MAIN_NAME;
750
+
751
+ // src/components/Workspace/Workspace.tsx
752
+ import React9, { useCallback as useCallback4, useEffect as useEffect5, useRef as useRef3 } from "react";
753
+ import { useOperationInvoker as useOperationInvoker3 } from "@dxos/app-framework/ui";
754
+ import { LayoutOperation as LayoutOperation4 } from "@dxos/app-toolkit";
755
+ import { useAppGraph as useAppGraph6 } from "@dxos/app-toolkit/ui";
756
+ import { useConnections as useConnections3 } from "@dxos/plugin-graph";
757
+ import { Avatar as Avatar2, Icon as Icon2, Layout as Layout2, ScrollArea as ScrollArea2, Toolbar as Toolbar3, toLocalizedString as toLocalizedString4, useTranslation as useTranslation6 } from "@dxos/react-ui";
758
+ import { Card as Card3, Mosaic as Mosaic2 } from "@dxos/react-ui-mosaic";
759
+ import { SearchList as SearchList2, useSearchListItem as useSearchListItem2, useSearchListResults as useSearchListResults2 } from "@dxos/react-ui-searchlist";
760
+ import { mx as mx7 } from "@dxos/ui-theme";
761
+ var Workspace = ({ id }) => {
762
+ const { t } = useTranslation6(meta.id);
763
+ const { graph } = useAppGraph6();
764
+ useLoadDescendents(id);
765
+ const children = useConnections3(graph, id, "outbound");
766
+ const { results, handleSearch } = useSearchListResults2({
767
+ items: children,
768
+ extract: (child) => toLocalizedString4(child.properties.label, t)
769
+ });
770
+ return /* @__PURE__ */ React9.createElement(Layout2.Main, {
771
+ toolbar: true
772
+ }, /* @__PURE__ */ React9.createElement(SearchList2.Root, {
773
+ onSearch: handleSearch
774
+ }, /* @__PURE__ */ React9.createElement(Toolbar3.Root, null, /* @__PURE__ */ React9.createElement(SearchList2.Input, {
775
+ placeholder: t("search placeholder"),
776
+ autoFocus: true
777
+ })), /* @__PURE__ */ React9.createElement(SearchList2.Content, null, /* @__PURE__ */ React9.createElement(Mosaic2.Container, {
778
+ asChild: true
779
+ }, /* @__PURE__ */ React9.createElement(ScrollArea2.Root, {
780
+ orientation: "vertical"
781
+ }, /* @__PURE__ */ React9.createElement(ScrollArea2.Viewport, {
782
+ classNames: "p-2"
783
+ }, /* @__PURE__ */ React9.createElement(Mosaic2.Stack, {
784
+ items: results,
785
+ getId: (child) => child.id,
786
+ Tile: WorkspaceChildTile
787
+ })))))));
788
+ };
789
+ var WorkspaceChildTile = ({ data }) => {
790
+ const { t } = useTranslation6(meta.id);
791
+ const { invokeSync } = useOperationInvoker3();
792
+ const ref = useRef3(null);
793
+ const { selectedValue, registerItem, unregisterItem } = useSearchListItem2();
794
+ const isSelected = selectedValue === data.id;
795
+ const name = toLocalizedString4(data.properties.label, t);
796
+ const handleSelect = useCallback4(() => invokeSync(LayoutOperation4.Open, {
797
+ subject: [
798
+ data.id
799
+ ]
800
+ }), [
801
+ invokeSync,
802
+ data.id
803
+ ]);
804
+ useEffect5(() => {
805
+ if (ref.current) {
806
+ registerItem(data.id, ref.current, handleSelect);
807
+ }
808
+ return () => unregisterItem(data.id);
809
+ }, [
810
+ data.id,
811
+ handleSelect,
812
+ registerItem,
813
+ unregisterItem
814
+ ]);
815
+ useEffect5(() => {
816
+ if (isSelected && ref.current) {
817
+ ref.current.scrollIntoView({
818
+ block: "nearest",
819
+ behavior: "smooth"
820
+ });
821
+ }
822
+ }, [
823
+ isSelected
824
+ ]);
825
+ return /* @__PURE__ */ React9.createElement(Card3.Root, {
826
+ ref,
827
+ role: "button",
828
+ fullWidth: true,
829
+ tabIndex: -1,
830
+ "data-selected": isSelected,
831
+ classNames: mx7("dx-focus-ring", isSelected && "bg-hoverOverlay"),
832
+ onClick: handleSelect
833
+ }, /* @__PURE__ */ React9.createElement(Card3.Toolbar, {
834
+ density: "coarse"
835
+ }, /* @__PURE__ */ React9.createElement(Avatar2.Root, null, /* @__PURE__ */ React9.createElement(Avatar2.Content, {
836
+ hue: data.properties.hue,
837
+ icon: data.properties.icon,
838
+ hueVariant: "transparent",
839
+ variant: "square",
840
+ size: 12,
841
+ fallback: name
842
+ }), /* @__PURE__ */ React9.createElement(Avatar2.Label, null, name), /* @__PURE__ */ React9.createElement(Icon2, {
843
+ icon: "ph--caret-right--regular"
844
+ }))));
845
+ };
846
+
847
+ // src/hooks/useSimpleLayoutState.ts
848
+ import { RegistryContext, useAtomValue as useAtomValue3 } from "@effect-atom/atom-react";
849
+ import { useCallback as useCallback5, useContext } from "react";
850
+ import { useCapability as useCapability2 } from "@dxos/app-framework/ui";
851
+ var useSimpleLayoutState = () => {
852
+ const registry = useContext(RegistryContext);
853
+ const stateAtom = useCapability2(SimpleLayoutState);
854
+ const state = useAtomValue3(stateAtom);
855
+ const updateState = useCallback5((fn) => {
856
+ registry.set(stateAtom, fn(registry.get(stateAtom)));
857
+ }, [
858
+ registry,
859
+ stateAtom
860
+ ]);
861
+ return {
862
+ state,
863
+ updateState
864
+ };
865
+ };
866
+
867
+ // src/hooks/useDrawerActions.ts
868
+ var useDrawerActions = (consumerName) => {
869
+ const { t } = useTranslation7(meta.id);
870
+ const stateAtom = useCapability3(SimpleLayoutState);
871
+ const { graph } = useAppGraph7();
872
+ const runAction = useActionRunner2();
873
+ const { invokeSync } = useOperationInvoker4();
874
+ const { updateState } = useSimpleLayoutState();
875
+ const { keyboardOpen } = useMobileLayout(consumerName);
876
+ const actionsAtom = useMemo6(() => Atom2.make((get) => {
877
+ const state = get(stateAtom);
878
+ const { nodes, edges } = createCompanionActions(graph, stateAtom, get, {
879
+ idPrefix: "drawer",
880
+ selectedVariant: state.companionVariant,
881
+ invokeSync
882
+ });
883
+ const gapSeparator = createGapSeparator("drawer-gap");
884
+ nodes.push(...gapSeparator.nodes);
885
+ edges.push(...gapSeparator.edges);
886
+ if (!keyboardOpen) {
887
+ const isExpanded = state.drawerState === "expanded";
888
+ const toggleExpandAction = {
889
+ id: "drawer-toggle-expand",
890
+ type: Node4.ActionType,
891
+ properties: {
892
+ icon: isExpanded ? "ph--arrow-down--regular" : "ph--arrow-up--regular",
893
+ label: isExpanded ? t("collapse drawer label") : t("expand drawer label"),
894
+ iconOnly: true
895
+ },
896
+ data: () => Effect3.sync(() => updateState((state2) => ({
897
+ ...state2,
898
+ drawerState: isExpanded ? "open" : "expanded"
899
+ })))
900
+ };
901
+ nodes.push(toggleExpandAction);
902
+ edges.push({
903
+ source: "root",
904
+ target: toggleExpandAction.id
905
+ });
906
+ }
907
+ const closeAction = {
908
+ id: "drawer-close",
909
+ type: Node4.ActionType,
910
+ properties: {
911
+ icon: "ph--x--regular",
912
+ label: t("close drawer label"),
913
+ iconOnly: true
914
+ },
915
+ data: () => Effect3.sync(() => updateState((state2) => ({
916
+ ...state2,
917
+ drawerState: "closed"
918
+ })))
919
+ };
920
+ nodes.push(closeAction);
921
+ edges.push({
922
+ source: "root",
923
+ target: closeAction.id
924
+ });
925
+ return {
926
+ nodes,
927
+ edges
928
+ };
929
+ }), [
930
+ graph,
931
+ stateAtom,
932
+ invokeSync,
933
+ updateState,
934
+ keyboardOpen,
935
+ t
936
+ ]);
937
+ return {
938
+ actions: actionsAtom,
939
+ onAction: runAction
940
+ };
941
+ };
942
+
943
+ // src/hooks/useNavbarActions.ts
944
+ import { Atom as Atom3 } from "@effect-atom/atom-react";
945
+ import { useMemo as useMemo7 } from "react";
946
+ import { useCapability as useCapability4, useOperationInvoker as useOperationInvoker5 } from "@dxos/app-framework/ui";
947
+ import { useAppGraph as useAppGraph8 } from "@dxos/app-toolkit/ui";
948
+ import { Node as Node5, useActionRunner as useActionRunner3 } from "@dxos/plugin-graph";
949
+ import { useTranslation as useTranslation8 } from "@dxos/react-ui";
950
+ import { createGapSeparator as createGapSeparator2, createMenuItemGroup } from "@dxos/react-ui-menu";
951
+ var MAIN_MENU_GROUP_ID = "navbar-main-menu";
952
+ var useNavbarActions = () => {
953
+ const { t } = useTranslation8(meta.id);
954
+ const { graph } = useAppGraph8();
955
+ const runAction = useActionRunner3();
956
+ const { invokeSync } = useOperationInvoker5();
957
+ const stateAtom = useCapability4(SimpleLayoutState);
958
+ const actionsAtom = useMemo7(() => Atom3.make((get) => {
959
+ const { nodes, edges } = createCompanionActions(graph, stateAtom, get, {
960
+ idPrefix: "navbar",
961
+ invokeSync
962
+ });
963
+ const gapSeparator = createGapSeparator2("navbar-gap");
964
+ nodes.push(...gapSeparator.nodes);
965
+ edges.push(...gapSeparator.edges);
966
+ const mainMenuGroup = createMenuItemGroup(MAIN_MENU_GROUP_ID, {
967
+ variant: "dropdownMenu",
968
+ icon: "ph--list--regular",
969
+ iconOnly: true,
970
+ label: t("main menu label"),
971
+ testId: "simpleLayoutPlugin.addSpace"
972
+ });
973
+ nodes.push(mainMenuGroup);
974
+ edges.push({
975
+ source: "root",
976
+ target: mainMenuGroup.id
977
+ });
978
+ const rootConnections = get(graph.connections(Node5.RootId));
979
+ const menuActions = rootConnections.filter((node) => node.properties.disposition === "menu");
980
+ menuActions.forEach((menuAction) => {
981
+ nodes.push(menuAction);
982
+ edges.push({
983
+ source: MAIN_MENU_GROUP_ID,
984
+ target: menuAction.id
985
+ });
986
+ });
987
+ return {
988
+ nodes,
989
+ edges
990
+ };
991
+ }), [
992
+ graph,
993
+ stateAtom,
994
+ invokeSync,
995
+ t
996
+ ]);
997
+ return {
998
+ actions: actionsAtom,
999
+ onAction: runAction
1000
+ };
1001
+ };
1002
+
1003
+ // src/components/Dialog/Dialog.tsx
1004
+ import React10 from "react";
1005
+ import { Surface as Surface3 } from "@dxos/app-framework/ui";
1006
+ import { AlertDialog, Dialog as NaturalDialog } from "@dxos/react-ui";
1007
+ var Dialog = () => {
1008
+ const { state, updateState } = useSimpleLayoutState();
1009
+ const DialogRoot = state.dialogType === "alert" ? AlertDialog.Root : NaturalDialog.Root;
1010
+ const DialogOverlay = state.dialogType === "alert" ? AlertDialog.Overlay : NaturalDialog.Overlay;
1011
+ return /* @__PURE__ */ React10.createElement(DialogRoot, {
1012
+ modal: state.dialogBlockAlign !== "end",
1013
+ open: state.dialogOpen,
1014
+ onOpenChange: (nextOpen) => updateState((state2) => ({
1015
+ ...state2,
1016
+ dialogOpen: nextOpen
1017
+ }))
1018
+ }, state.dialogBlockAlign === "end" ? /* @__PURE__ */ React10.createElement(Surface3.Surface, {
1019
+ role: "dialog",
1020
+ data: state.dialogContent,
1021
+ limit: 1,
1022
+ fallback: ContentError
1023
+ }) : /* @__PURE__ */ React10.createElement(DialogOverlay, {
1024
+ blockAlign: state.dialogBlockAlign,
1025
+ classNames: state.dialogOverlayClasses,
1026
+ style: state.dialogOverlayStyle
1027
+ }, /* @__PURE__ */ React10.createElement(Surface3.Surface, {
1028
+ role: "dialog",
1029
+ data: state.dialogContent,
1030
+ limit: 1,
1031
+ fallback: ContentError
1032
+ })));
1033
+ };
1034
+
1035
+ // src/components/SimpleLayout/Drawer.tsx
1036
+ import React11, { useMemo as useMemo8 } from "react";
1037
+ import { Surface as Surface4 } from "@dxos/app-framework/ui";
1038
+ import { useAppGraph as useAppGraph9 } from "@dxos/app-toolkit/ui";
1039
+ import { useNode as useNode3 } from "@dxos/plugin-graph";
1040
+ import { Layout as Layout3 } from "@dxos/react-ui";
1041
+ import { ATTENDABLE_PATH_SEPARATOR as ATTENDABLE_PATH_SEPARATOR2 } from "@dxos/react-ui-attention";
1042
+ import { MenuProvider as MenuProvider3, ToolbarMenu as ToolbarMenu2, useMenuActions as useMenuActions3 } from "@dxos/react-ui-menu";
1043
+ var DRAWER_NAME = "SimpleLayout.Drawer";
1044
+ var Drawer = () => {
1045
+ const { graph } = useAppGraph9();
1046
+ const { state: layoutState } = useSimpleLayoutState();
1047
+ const placeholder = useMemo8(() => /* @__PURE__ */ React11.createElement(ContentLoading, null), []);
1048
+ const activeId = layoutState.active ?? layoutState.workspace;
1049
+ const companions = useCompanions(activeId);
1050
+ const { companionId, variant } = useSelectedCompanion(companions, layoutState.companionVariant);
1051
+ const node = useNode3(graph, companionId);
1052
+ const parentNode = useNode3(graph, activeId);
1053
+ const data = useMemo8(() => {
1054
+ return node && {
1055
+ attendableId: companionId,
1056
+ subject: node.data,
1057
+ companionTo: parentNode?.data,
1058
+ properties: node.properties,
1059
+ variant
1060
+ };
1061
+ }, [
1062
+ companionId,
1063
+ node,
1064
+ parentNode,
1065
+ variant
1066
+ ]);
1067
+ const { actions, onAction } = useDrawerActions(DRAWER_NAME);
1068
+ const menu = useMenuActions3(actions);
1069
+ return /* @__PURE__ */ React11.createElement(Layout3.Main, {
1070
+ toolbar: true
1071
+ }, /* @__PURE__ */ React11.createElement(MenuProvider3, {
1072
+ ...menu,
1073
+ onAction,
1074
+ alwaysActive: true
1075
+ }, /* @__PURE__ */ React11.createElement(ToolbarMenu2, {
1076
+ density: "coarse"
1077
+ })), /* @__PURE__ */ React11.createElement(Surface4.Surface, {
1078
+ role: "article",
1079
+ data,
1080
+ limit: 1,
1081
+ fallback: ContentError,
1082
+ placeholder
1083
+ }));
1084
+ };
1085
+ Drawer.displayName = DRAWER_NAME;
1086
+ var parseEntryId = (entryId) => {
1087
+ const [id, variant] = entryId.split(ATTENDABLE_PATH_SEPARATOR2);
1088
+ return {
1089
+ id,
1090
+ variant
1091
+ };
1092
+ };
1093
+ var useSelectedCompanion = (companions, preferredVariant) => {
1094
+ const selectedCompanion = useMemo8(() => {
1095
+ if (companions.length === 0) {
1096
+ return void 0;
1097
+ }
1098
+ if (preferredVariant) {
1099
+ const preferred = companions.find((c) => {
1100
+ const { variant: variant2 } = parseEntryId(c.id);
1101
+ return variant2 === preferredVariant;
1102
+ });
1103
+ if (preferred) {
1104
+ return preferred;
1105
+ }
1106
+ }
1107
+ return companions[0];
1108
+ }, [
1109
+ companions,
1110
+ preferredVariant
1111
+ ]);
1112
+ const companionId = selectedCompanion?.id;
1113
+ const { variant } = parseEntryId(companionId ?? "");
1114
+ return {
1115
+ selectedCompanion,
1116
+ companionId,
1117
+ variant
1118
+ };
1119
+ };
1120
+
1121
+ // src/components/SimpleLayout/SimpleLayout.tsx
1122
+ var SimpleLayout = () => {
1123
+ const { state } = useSimpleLayoutState();
1124
+ const [keyboardOpen, setKeyboardOpen] = useState3(false);
1125
+ const [splitterMode, setSplitterMode] = useState3("upper");
1126
+ const drawerRef = useRef4(null);
1127
+ useEffect6(() => {
1128
+ if (keyboardOpen) {
1129
+ const activeElement = document.activeElement;
1130
+ const drawerHasFocus = drawerRef.current?.contains(activeElement);
1131
+ setSplitterMode(drawerHasFocus ? "lower" : "upper");
1132
+ } else {
1133
+ setSplitterMode(state.drawerState === "closed" ? "upper" : state.drawerState === "open" ? "both" : "lower");
1134
+ }
1135
+ }, [
1136
+ state.drawerState,
1137
+ keyboardOpen
1138
+ ]);
1139
+ return /* @__PURE__ */ React12.createElement(Mosaic3.Root, {
1140
+ classNames: "contents"
1141
+ }, /* @__PURE__ */ React12.createElement(MobileLayout.Root, {
1142
+ classNames: "bg-toolbarSurface",
1143
+ onKeyboardOpenChange: (keyboardOpen2) => setKeyboardOpen(keyboardOpen2)
1144
+ }, /* @__PURE__ */ React12.createElement(MobileLayout.Panel, {
1145
+ safe: {
1146
+ top: true,
1147
+ bottom: splitterMode === "upper"
1148
+ }
1149
+ }, /* @__PURE__ */ React12.createElement(PopoverRoot, null, /* @__PURE__ */ React12.createElement(Splitter.Root, {
1150
+ mode: splitterMode,
1151
+ ratio: 0.55
1152
+ }, /* @__PURE__ */ React12.createElement(Splitter.Panel, {
1153
+ position: "upper"
1154
+ }, /* @__PURE__ */ React12.createElement(Main, null)), /* @__PURE__ */ React12.createElement(Splitter.Panel, {
1155
+ position: "lower",
1156
+ ref: drawerRef
1157
+ }, /* @__PURE__ */ React12.createElement(Drawer, null))), /* @__PURE__ */ React12.createElement(Dialog, null), /* @__PURE__ */ React12.createElement(PopoverContent, null)))));
1158
+ };
1159
+
1160
+ export {
1161
+ Home,
1162
+ SimpleLayout,
1163
+ Workspace
1164
+ };
1165
+ //# sourceMappingURL=chunk-O3BQBYMW.mjs.map