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