@dxos/plugin-navtree 0.8.4-main.406dc2a → 0.8.4-main.4a85c3132b

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 (226) hide show
  1. package/dist/lib/browser/CommandsDialogContent-A27AKTHH.mjs +111 -0
  2. package/dist/lib/browser/CommandsDialogContent-A27AKTHH.mjs.map +7 -0
  3. package/dist/lib/browser/CommandsTrigger-HBZYQCGV.mjs +33 -0
  4. package/dist/lib/browser/CommandsTrigger-HBZYQCGV.mjs.map +7 -0
  5. package/dist/lib/browser/NavTreeContainer-B5K4FUJS.mjs +12 -0
  6. package/dist/lib/browser/NavTreeContainer-B5K4FUJS.mjs.map +7 -0
  7. package/dist/lib/browser/NavTreeDocumentTitle-GEE3URWH.mjs +26 -0
  8. package/dist/lib/browser/NavTreeDocumentTitle-GEE3URWH.mjs.map +7 -0
  9. package/dist/lib/browser/app-graph-builder-XGA4GPGL.mjs +44 -0
  10. package/dist/lib/browser/app-graph-builder-XGA4GPGL.mjs.map +7 -0
  11. package/dist/lib/browser/chunk-DQCYMXEU.mjs +1426 -0
  12. package/dist/lib/browser/chunk-DQCYMXEU.mjs.map +7 -0
  13. package/dist/lib/browser/chunk-H3OJ4WLF.mjs +14 -0
  14. package/dist/lib/browser/chunk-H3OJ4WLF.mjs.map +7 -0
  15. package/dist/lib/browser/chunk-X2HDG62A.mjs +23 -0
  16. package/dist/lib/browser/chunk-X2HDG62A.mjs.map +7 -0
  17. package/dist/lib/browser/chunk-YKTYPINZ.mjs +19 -0
  18. package/dist/lib/browser/chunk-YKTYPINZ.mjs.map +7 -0
  19. package/dist/lib/browser/index.mjs +86 -91
  20. package/dist/lib/browser/index.mjs.map +4 -4
  21. package/dist/lib/browser/{keyboard-AHSAWKXA.mjs → keyboard-OJZC54PK.mjs} +22 -19
  22. package/dist/lib/browser/keyboard-OJZC54PK.mjs.map +7 -0
  23. package/dist/lib/browser/meta.json +1 -1
  24. package/dist/lib/browser/operation-resolver-BNAMYOHF.mjs +53 -0
  25. package/dist/lib/browser/operation-resolver-BNAMYOHF.mjs.map +7 -0
  26. package/dist/lib/browser/react-surface-AYHOAJ4I.mjs +59 -0
  27. package/dist/lib/browser/react-surface-AYHOAJ4I.mjs.map +7 -0
  28. package/dist/lib/browser/state-AC3EETN7.mjs +131 -0
  29. package/dist/lib/browser/state-AC3EETN7.mjs.map +7 -0
  30. package/dist/types/src/NavTreePlugin.d.ts +2 -1
  31. package/dist/types/src/NavTreePlugin.d.ts.map +1 -1
  32. package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts +6 -0
  33. package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts.map +1 -0
  34. package/dist/types/src/capabilities/app-graph-builder/index.d.ts +3 -0
  35. package/dist/types/src/capabilities/app-graph-builder/index.d.ts.map +1 -0
  36. package/dist/types/src/capabilities/index.d.ts +5 -108
  37. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  38. package/dist/types/src/capabilities/keyboard/index.d.ts +3 -0
  39. package/dist/types/src/capabilities/keyboard/index.d.ts.map +1 -0
  40. package/dist/types/src/capabilities/keyboard/keyboard.d.ts +5 -0
  41. package/dist/types/src/capabilities/keyboard/keyboard.d.ts.map +1 -0
  42. package/dist/types/src/capabilities/operation-resolver/index.d.ts +3 -0
  43. package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +1 -0
  44. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +5 -0
  45. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -0
  46. package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
  47. package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
  48. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
  49. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
  50. package/dist/types/src/capabilities/state/index.d.ts +3 -0
  51. package/dist/types/src/capabilities/state/index.d.ts.map +1 -0
  52. package/dist/types/src/capabilities/state/state.d.ts +6 -0
  53. package/dist/types/src/capabilities/state/state.d.ts.map +1 -0
  54. package/dist/types/src/components/NavTree/NavTree.d.ts +11 -4
  55. package/dist/types/src/components/NavTree/NavTree.d.ts.map +1 -1
  56. package/dist/types/src/components/NavTree/NavTree.stories.d.ts +2 -2
  57. package/dist/types/src/components/NavTree/NavTree.stories.d.ts.map +1 -1
  58. package/dist/types/src/components/NavTreeItem/NavTreeItemAction.d.ts +6 -6
  59. package/dist/types/src/components/NavTreeItem/NavTreeItemAction.d.ts.map +1 -1
  60. package/dist/types/src/components/NavTreeItem/NavTreeItemAction.stories.d.ts +2 -1
  61. package/dist/types/src/components/NavTreeItem/NavTreeItemAction.stories.d.ts.map +1 -1
  62. package/dist/types/src/components/NavTreeItem/NavTreeItemColumns.d.ts.map +1 -1
  63. package/dist/types/src/components/Sidebar/L0Menu.d.ts +8 -5
  64. package/dist/types/src/components/Sidebar/L0Menu.d.ts.map +1 -1
  65. package/dist/types/src/components/Sidebar/L1Panel.d.ts +4 -7
  66. package/dist/types/src/components/Sidebar/L1Panel.d.ts.map +1 -1
  67. package/dist/types/src/components/Sidebar/L1Tabs.d.ts +5 -4
  68. package/dist/types/src/components/Sidebar/L1Tabs.d.ts.map +1 -1
  69. package/dist/types/src/components/UserAccountAvatar/UserAccountAvatar.stories.d.ts.map +1 -1
  70. package/dist/types/src/components/index.d.ts +0 -3
  71. package/dist/types/src/components/index.d.ts.map +1 -1
  72. package/dist/types/src/components/types.d.ts +8 -16
  73. package/dist/types/src/components/types.d.ts.map +1 -1
  74. package/dist/types/src/containers/CommandsDialogContent/CommandsDialogContent.d.ts +6 -0
  75. package/dist/types/src/containers/CommandsDialogContent/CommandsDialogContent.d.ts.map +1 -0
  76. package/dist/types/src/containers/CommandsDialogContent/index.d.ts +3 -0
  77. package/dist/types/src/containers/CommandsDialogContent/index.d.ts.map +1 -0
  78. package/dist/types/src/containers/CommandsTrigger/CommandsTrigger.d.ts.map +1 -0
  79. package/dist/types/src/containers/CommandsTrigger/index.d.ts +3 -0
  80. package/dist/types/src/containers/CommandsTrigger/index.d.ts.map +1 -0
  81. package/dist/types/src/containers/NavTreeContainer/NavTreeContainer.d.ts +9 -0
  82. package/dist/types/src/containers/NavTreeContainer/NavTreeContainer.d.ts.map +1 -0
  83. package/dist/types/src/containers/NavTreeContainer/index.d.ts +3 -0
  84. package/dist/types/src/containers/NavTreeContainer/index.d.ts.map +1 -0
  85. package/dist/types/src/{components → containers/NavTreeDocumentTitle}/NavTreeDocumentTitle.d.ts +1 -1
  86. package/dist/types/src/containers/NavTreeDocumentTitle/NavTreeDocumentTitle.d.ts.map +1 -0
  87. package/dist/types/src/containers/NavTreeDocumentTitle/index.d.ts +3 -0
  88. package/dist/types/src/containers/NavTreeDocumentTitle/index.d.ts.map +1 -0
  89. package/dist/types/src/containers/index.d.ts +7 -0
  90. package/dist/types/src/containers/index.d.ts.map +1 -0
  91. package/dist/types/src/experimental/Tree.stories.d.ts +15 -4
  92. package/dist/types/src/experimental/Tree.stories.d.ts.map +1 -1
  93. package/dist/types/src/hooks/index.d.ts +5 -0
  94. package/dist/types/src/hooks/index.d.ts.map +1 -0
  95. package/dist/types/src/hooks/useActions.d.ts +7 -0
  96. package/dist/types/src/hooks/useActions.d.ts.map +1 -0
  97. package/dist/types/src/hooks/useLoadDescendents.d.ts +6 -0
  98. package/dist/types/src/hooks/useLoadDescendents.d.ts.map +1 -0
  99. package/dist/types/src/hooks/useNavTreeModel.d.ts +7 -0
  100. package/dist/types/src/hooks/useNavTreeModel.d.ts.map +1 -0
  101. package/dist/types/src/hooks/useNavTreeState.d.ts +22 -0
  102. package/dist/types/src/hooks/useNavTreeState.d.ts.map +1 -0
  103. package/dist/types/src/index.d.ts +1 -2
  104. package/dist/types/src/index.d.ts.map +1 -1
  105. package/dist/types/src/meta.d.ts +2 -2
  106. package/dist/types/src/meta.d.ts.map +1 -1
  107. package/dist/types/src/testing/app-graph-builder.d.ts +2 -3
  108. package/dist/types/src/testing/app-graph-builder.d.ts.map +1 -1
  109. package/dist/types/src/testing/generator.d.ts +5 -6
  110. package/dist/types/src/testing/generator.d.ts.map +1 -1
  111. package/dist/types/src/testing/update-state.d.ts +2 -2
  112. package/dist/types/src/testing/update-state.d.ts.map +1 -1
  113. package/dist/types/src/types/capabilities.d.ts +16 -0
  114. package/dist/types/src/types/capabilities.d.ts.map +1 -0
  115. package/dist/types/src/types/events.d.ts +5 -0
  116. package/dist/types/src/types/events.d.ts.map +1 -0
  117. package/dist/types/src/types/index.d.ts +4 -0
  118. package/dist/types/src/types/index.d.ts.map +1 -0
  119. package/dist/types/src/{types.d.ts → types/schema.d.ts} +7 -7
  120. package/dist/types/src/types/schema.d.ts.map +1 -0
  121. package/dist/types/src/util.d.ts +11 -7
  122. package/dist/types/src/util.d.ts.map +1 -1
  123. package/dist/types/tsconfig.tsbuildinfo +1 -1
  124. package/package.json +55 -53
  125. package/src/NavTreePlugin.tsx +54 -73
  126. package/src/capabilities/app-graph-builder/app-graph-builder.ts +42 -0
  127. package/src/capabilities/app-graph-builder/index.ts +7 -0
  128. package/src/capabilities/index.ts +5 -9
  129. package/src/capabilities/keyboard/index.ts +7 -0
  130. package/src/capabilities/keyboard/keyboard.ts +66 -0
  131. package/src/capabilities/operation-resolver/index.ts +7 -0
  132. package/src/capabilities/operation-resolver/operation-resolver.ts +44 -0
  133. package/src/capabilities/react-surface/index.ts +7 -0
  134. package/src/capabilities/react-surface/react-surface.tsx +53 -0
  135. package/src/capabilities/state/index.ts +7 -0
  136. package/src/capabilities/state/state.ts +149 -0
  137. package/src/components/NavTree/NavTree.stories.tsx +44 -51
  138. package/src/components/NavTree/NavTree.tsx +63 -32
  139. package/src/components/NavTreeItem/NavTreeItemAction.stories.tsx +18 -8
  140. package/src/components/NavTreeItem/NavTreeItemAction.tsx +33 -28
  141. package/src/components/NavTreeItem/NavTreeItemColumns.tsx +39 -15
  142. package/src/components/Sidebar/L0Menu.tsx +145 -155
  143. package/src/components/Sidebar/L1Panel.tsx +231 -94
  144. package/src/components/Sidebar/L1Tabs.tsx +18 -33
  145. package/src/components/UserAccountAvatar/UserAccountAvatar.stories.tsx +2 -3
  146. package/src/components/UserAccountAvatar/UserAccountAvatar.tsx +1 -1
  147. package/src/components/index.ts +1 -3
  148. package/src/components/types.ts +14 -19
  149. package/src/containers/CommandsDialogContent/CommandsDialogContent.tsx +133 -0
  150. package/src/containers/CommandsDialogContent/index.ts +7 -0
  151. package/src/{components/CommandsDialog → containers/CommandsTrigger}/CommandsTrigger.tsx +5 -14
  152. package/src/containers/CommandsTrigger/index.ts +7 -0
  153. package/src/containers/NavTreeContainer/NavTreeContainer.tsx +270 -0
  154. package/src/containers/NavTreeContainer/index.ts +7 -0
  155. package/src/{components → containers/NavTreeDocumentTitle}/NavTreeDocumentTitle.tsx +4 -3
  156. package/src/containers/NavTreeDocumentTitle/index.ts +7 -0
  157. package/src/containers/index.ts +12 -0
  158. package/src/experimental/Tree.stories.tsx +54 -60
  159. package/src/experimental/Tree.tsx +3 -3
  160. package/src/hooks/index.ts +8 -0
  161. package/src/hooks/useActions.ts +38 -0
  162. package/src/hooks/useLoadDescendents.ts +23 -0
  163. package/src/hooks/useNavTreeModel.ts +112 -0
  164. package/src/hooks/useNavTreeState.ts +42 -0
  165. package/src/index.ts +1 -2
  166. package/src/meta.ts +7 -2
  167. package/src/testing/app-graph-builder.ts +159 -235
  168. package/src/testing/generator.ts +19 -17
  169. package/src/testing/update-state.ts +6 -6
  170. package/src/types/capabilities.ts +21 -0
  171. package/src/types/events.ts +12 -0
  172. package/src/types/index.ts +7 -0
  173. package/src/{types.ts → types/schema.ts} +6 -6
  174. package/src/util.ts +27 -16
  175. package/dist/lib/browser/app-graph-builder-YAPMENYT.mjs +0 -46
  176. package/dist/lib/browser/app-graph-builder-YAPMENYT.mjs.map +0 -7
  177. package/dist/lib/browser/chunk-IMFXKPSB.mjs +0 -1482
  178. package/dist/lib/browser/chunk-IMFXKPSB.mjs.map +0 -7
  179. package/dist/lib/browser/chunk-LPAREX6J.mjs +0 -15
  180. package/dist/lib/browser/chunk-LPAREX6J.mjs.map +0 -7
  181. package/dist/lib/browser/chunk-ZENLR72O.mjs +0 -14
  182. package/dist/lib/browser/chunk-ZENLR72O.mjs.map +0 -7
  183. package/dist/lib/browser/intent-resolver-TCQXGF6U.mjs +0 -47
  184. package/dist/lib/browser/intent-resolver-TCQXGF6U.mjs.map +0 -7
  185. package/dist/lib/browser/keyboard-AHSAWKXA.mjs.map +0 -7
  186. package/dist/lib/browser/react-surface-AH2TP73M.mjs +0 -51
  187. package/dist/lib/browser/react-surface-AH2TP73M.mjs.map +0 -7
  188. package/dist/lib/browser/state-2Q623V7U.mjs +0 -117
  189. package/dist/lib/browser/state-2Q623V7U.mjs.map +0 -7
  190. package/dist/types/src/capabilities/app-graph-builder.d.ts +0 -4
  191. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +0 -1
  192. package/dist/types/src/capabilities/capabilities.d.ts +0 -21
  193. package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
  194. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  195. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  196. package/dist/types/src/capabilities/keyboard.d.ts +0 -4
  197. package/dist/types/src/capabilities/keyboard.d.ts.map +0 -1
  198. package/dist/types/src/capabilities/react-surface.d.ts +0 -4
  199. package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
  200. package/dist/types/src/capabilities/state.d.ts +0 -20
  201. package/dist/types/src/capabilities/state.d.ts.map +0 -1
  202. package/dist/types/src/components/CommandsDialog/CommandsDialog.d.ts +0 -5
  203. package/dist/types/src/components/CommandsDialog/CommandsDialog.d.ts.map +0 -1
  204. package/dist/types/src/components/CommandsDialog/CommandsTrigger.d.ts.map +0 -1
  205. package/dist/types/src/components/CommandsDialog/index.d.ts +0 -3
  206. package/dist/types/src/components/CommandsDialog/index.d.ts.map +0 -1
  207. package/dist/types/src/components/NavTreeContainer.d.ts +0 -9
  208. package/dist/types/src/components/NavTreeContainer.d.ts.map +0 -1
  209. package/dist/types/src/components/NavTreeDocumentTitle.d.ts.map +0 -1
  210. package/dist/types/src/events.d.ts +0 -4
  211. package/dist/types/src/events.d.ts.map +0 -1
  212. package/dist/types/src/hooks.d.ts +0 -3
  213. package/dist/types/src/hooks.d.ts.map +0 -1
  214. package/dist/types/src/types.d.ts.map +0 -1
  215. package/src/capabilities/app-graph-builder.ts +0 -53
  216. package/src/capabilities/capabilities.ts +0 -20
  217. package/src/capabilities/intent-resolver.ts +0 -37
  218. package/src/capabilities/keyboard.ts +0 -59
  219. package/src/capabilities/react-surface.tsx +0 -45
  220. package/src/capabilities/state.ts +0 -105
  221. package/src/components/CommandsDialog/CommandsDialog.tsx +0 -118
  222. package/src/components/CommandsDialog/index.ts +0 -6
  223. package/src/components/NavTreeContainer.tsx +0 -346
  224. package/src/events.ts +0 -11
  225. package/src/hooks.ts +0 -21
  226. /package/dist/types/src/{components/CommandsDialog → containers/CommandsTrigger}/CommandsTrigger.d.ts +0 -0
@@ -0,0 +1,1426 @@
1
+ import {
2
+ NavTreeCapabilities
3
+ } from "./chunk-X2HDG62A.mjs";
4
+ import {
5
+ meta
6
+ } from "./chunk-YKTYPINZ.mjs";
7
+
8
+ // src/util.ts
9
+ import { Graph, Node } from "@dxos/plugin-graph";
10
+ import { isNonNullable } from "@dxos/util";
11
+ var getParent = (graph, node, path) => {
12
+ const parentId = path[path.length - 2];
13
+ return Graph.getConnections(graph, node.id, Node.childRelation("inbound")).find((n) => n.id === parentId);
14
+ };
15
+ var getPersistenceParent = (graph, node, path, persistenceClass) => {
16
+ if (node.properties.acceptPersistenceClass?.has(persistenceClass)) {
17
+ return node;
18
+ } else {
19
+ const parent = getParent(graph, node, path);
20
+ return parent ? getPersistenceParent(graph, parent, path.slice(0, path.length - 1), persistenceClass) : null;
21
+ }
22
+ };
23
+ var resolveMigrationOperation = (graph, activeNode, destinationPath, destinationRelatedNode) => {
24
+ const activeClass = activeNode.properties.persistenceClass;
25
+ if (destinationRelatedNode && activeClass) {
26
+ const persistenceParent = getPersistenceParent(graph, destinationRelatedNode, destinationPath, activeClass);
27
+ if (persistenceParent) {
28
+ const activeKey = activeNode.properties.persistenceKey;
29
+ if (activeKey && persistenceParent?.properties.acceptPersistenceKey) {
30
+ return persistenceParent.properties.acceptPersistenceKey.has(activeKey) && persistenceParent.properties.onTransferStart ? "transfer" : persistenceParent.properties.onCopy ? "copy" : "reject";
31
+ } else {
32
+ return "reject";
33
+ }
34
+ } else {
35
+ return "reject";
36
+ }
37
+ } else {
38
+ return "reject";
39
+ }
40
+ };
41
+ var sortActions = (actions) => actions.sort((a, b) => {
42
+ if (a.properties.disposition === b.properties.disposition) {
43
+ return 0;
44
+ }
45
+ if (a.properties.disposition === "list-item-primary") {
46
+ return -1;
47
+ }
48
+ return 1;
49
+ });
50
+ var getChildren = (graph, node, path = []) => {
51
+ return Graph.getConnections(graph, node.id, "child").map((n) => {
52
+ const nextPath = [
53
+ ...path,
54
+ node.id
55
+ ];
56
+ return nextPath.includes(n.id) ? void 0 : n;
57
+ }).filter(isNonNullable);
58
+ };
59
+ var filterItems = (node, disposition) => {
60
+ if (!disposition && (node.properties.disposition === "hidden" || node.properties.disposition === "alternate-tree")) {
61
+ return false;
62
+ } else if (!disposition) {
63
+ const action = Node.isAction(node);
64
+ return !action || node.properties.disposition === "item";
65
+ } else {
66
+ return node.properties.disposition === disposition;
67
+ }
68
+ };
69
+ var l0ItemType = (item) => {
70
+ if (Node.isActionLike(item)) {
71
+ return "action";
72
+ } else {
73
+ return "tab";
74
+ }
75
+ };
76
+
77
+ // src/containers/NavTreeContainer/NavTreeContainer.tsx
78
+ import { monitorForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
79
+ import { extractInstruction } from "@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item";
80
+ import React8, { forwardRef as forwardRef3, memo as memo4, useCallback as useCallback3, useEffect as useEffect2, useMemo as useMemo8, useRef as useRef2 } from "react";
81
+ import { Surface, useOperationInvoker } from "@dxos/app-framework/ui";
82
+ import { LayoutOperation } from "@dxos/app-toolkit";
83
+ import { useAppGraph as useAppGraph6, useLayout } from "@dxos/app-toolkit/ui";
84
+ import { Graph as Graph5, Node as Node6, useActionRunner as useActionRunner4 } from "@dxos/plugin-graph";
85
+ import { useMediaQuery as useMediaQuery2, useSidebars } from "@dxos/react-ui";
86
+ import { isTreeData } from "@dxos/react-ui-list";
87
+ import { arrayMove as arrayMove2 } from "@dxos/util";
88
+
89
+ // src/components/NavTree/NavTree.tsx
90
+ import React7, { forwardRef as forwardRef2, useMemo as useMemo7 } from "react";
91
+ import { useAppGraph as useAppGraph5 } from "@dxos/app-toolkit/ui";
92
+ import { Node as Node5, useConnections as useConnections2, useActions as useGraphActions2 } from "@dxos/plugin-graph";
93
+ import { Tabs as Tabs3 } from "@dxos/react-ui-tabs";
94
+ import { byPosition } from "@dxos/util";
95
+
96
+ // src/hooks/useActions.ts
97
+ import { useMemo } from "react";
98
+ import { useAppGraph } from "@dxos/app-toolkit/ui";
99
+ import { Graph as Graph2, Node as Node2, useActions as useGraphActions } from "@dxos/plugin-graph";
100
+ var useActions = (node) => {
101
+ const { graph } = useAppGraph();
102
+ const actions = useGraphActions(graph, node.id);
103
+ return useMemo(() => actions.reduce((acc, arg) => {
104
+ if (arg.properties.disposition === "item") {
105
+ return acc;
106
+ }
107
+ acc.actions.push(arg);
108
+ if (!Node2.isAction(arg)) {
109
+ const actionGroup = Graph2.getActions(graph, arg.id);
110
+ acc.groupedActions[arg.id] = actionGroup;
111
+ }
112
+ return acc;
113
+ }, {
114
+ actions: [],
115
+ groupedActions: {}
116
+ }), [
117
+ actions
118
+ ]);
119
+ };
120
+
121
+ // src/hooks/useLoadDescendents.ts
122
+ import { useEffect } from "react";
123
+ import { useAppGraph as useAppGraph2 } from "@dxos/app-toolkit/ui";
124
+ import { Graph as Graph3 } from "@dxos/plugin-graph";
125
+ var useLoadDescendents = (root) => {
126
+ const { graph } = useAppGraph2();
127
+ useEffect(() => {
128
+ if (!root) {
129
+ return;
130
+ }
131
+ Graph3.expand(graph, root.id, "child");
132
+ }, [
133
+ graph,
134
+ root
135
+ ]);
136
+ };
137
+
138
+ // src/hooks/useNavTreeModel.ts
139
+ import { Atom } from "@effect-atom/atom-react";
140
+ import * as Option from "effect/Option";
141
+ import { useMemo as useMemo3 } from "react";
142
+ import { useAppGraph as useAppGraph3 } from "@dxos/app-toolkit/ui";
143
+ import { PLANK_COMPANION_TYPE } from "@dxos/plugin-deck/types";
144
+ import { Path } from "@dxos/react-ui-list";
145
+ import { mx } from "@dxos/ui-theme";
146
+
147
+ // src/hooks/useNavTreeState.ts
148
+ import { useAtomValue } from "@effect-atom/atom-react";
149
+ import { useMemo as useMemo2 } from "react";
150
+ import { useCapability } from "@dxos/app-framework/ui";
151
+ var useNavTreeState = () => {
152
+ return useCapability(NavTreeCapabilities.State);
153
+ };
154
+ var useNavTreeItemState = (path) => {
155
+ const { getItemAtom } = useCapability(NavTreeCapabilities.State);
156
+ const pathKey = useMemo2(() => path.join("~"), [
157
+ path
158
+ ]);
159
+ const atom = useMemo2(() => getItemAtom(path), [
160
+ getItemAtom,
161
+ pathKey
162
+ ]);
163
+ return useAtomValue(atom);
164
+ };
165
+ var useIsAlternateTree = (path, _item) => {
166
+ return useNavTreeItemState(path).alternateTree ?? false;
167
+ };
168
+
169
+ // src/hooks/useNavTreeModel.ts
170
+ var isVisibleChild = (node) => node.type !== PLANK_COMPANION_TYPE && node.properties.disposition !== "hidden";
171
+ var createItemPropsFamily = (graph) => Atom.family((pathKey) => {
172
+ const path = Path.parts(pathKey);
173
+ const id = Path.last(pathKey);
174
+ return Atom.make((get) => {
175
+ const nodeOpt = get(graph.node(id));
176
+ const node = Option.getOrElse(nodeOpt, () => void 0);
177
+ if (!node) {
178
+ return {
179
+ id,
180
+ label: id
181
+ };
182
+ }
183
+ const safeChildren = get(graph.connections(node.id, "child")).filter((child) => !path.includes(child.id));
184
+ const visibleChildren = safeChildren.filter(isVisibleChild);
185
+ const parentOf = visibleChildren.length > 0 ? visibleChildren.map((child) => child.id) : node.properties.role === "branch" ? [] : void 0;
186
+ return {
187
+ id: node.id,
188
+ parentOf,
189
+ disabled: node.properties.disabled,
190
+ label: node.properties.label ?? node.id,
191
+ className: mx(node.properties.className, node.properties.modified && "italic"),
192
+ headingClassName: node.properties.headingClassName,
193
+ icon: node.properties.icon,
194
+ iconHue: node.properties.iconHue,
195
+ testId: node.properties.testId
196
+ };
197
+ }).pipe(Atom.keepAlive);
198
+ });
199
+ var createChildIdsFamily = (graph) => Atom.family((id) => Atom.make((get) => get(graph.connections(id, "child")).map((child) => child.id)).pipe(Atom.keepAlive));
200
+ var createItemFamily = (graph) => Atom.family((id) => Atom.make((get) => {
201
+ const node = Option.getOrElse(get(graph.node(id)), () => void 0);
202
+ const passed = node ? filterItems(node) : false;
203
+ return node && passed ? node : void 0;
204
+ }).pipe(Atom.keepAlive));
205
+ var createItemOpenFamily = (getItemAtom) => Atom.family((pathKey) => {
206
+ const path = Path.parts(pathKey);
207
+ const stateAtom = getItemAtom(path);
208
+ return Atom.make((get) => get(stateAtom).open).pipe(Atom.keepAlive);
209
+ });
210
+ var createItemCurrentFamily = (getItemAtom) => Atom.family((pathKey) => {
211
+ const path = Path.parts(pathKey);
212
+ const stateAtom = getItemAtom(path);
213
+ return Atom.make((get) => get(stateAtom).current).pipe(Atom.keepAlive);
214
+ });
215
+ var useNavTreeModel = (rootId) => {
216
+ const { graph } = useAppGraph3();
217
+ const { getItemAtom } = useNavTreeState();
218
+ const itemPropsFamily = useMemo3(() => createItemPropsFamily(graph), [
219
+ graph
220
+ ]);
221
+ const childIdsFamily = useMemo3(() => createChildIdsFamily(graph), [
222
+ graph
223
+ ]);
224
+ const itemFamily = useMemo3(() => createItemFamily(graph), [
225
+ graph
226
+ ]);
227
+ const itemOpenFamily = useMemo3(() => createItemOpenFamily(getItemAtom), [
228
+ getItemAtom
229
+ ]);
230
+ const itemCurrentFamily = useMemo3(() => createItemCurrentFamily(getItemAtom), [
231
+ getItemAtom
232
+ ]);
233
+ return useMemo3(() => ({
234
+ item: (id) => itemFamily(id),
235
+ itemProps: (path) => itemPropsFamily(Path.create(...path)),
236
+ itemOpen: (path) => itemOpenFamily(Path.create(...path)),
237
+ itemCurrent: (path) => itemCurrentFamily(Path.create(...path)),
238
+ childIds: (parentId) => childIdsFamily(parentId ?? rootId)
239
+ }), [
240
+ itemFamily,
241
+ itemPropsFamily,
242
+ itemOpenFamily,
243
+ itemCurrentFamily,
244
+ childIdsFamily,
245
+ rootId
246
+ ]);
247
+ };
248
+
249
+ // src/components/NavTreeContext.tsx
250
+ import { createContext, useContext } from "react";
251
+ import { raise } from "@dxos/debug";
252
+ var NavTreeContext = /* @__PURE__ */ createContext(null);
253
+ var useNavTreeContext = () => useContext(NavTreeContext) ?? raise(new Error("Missing NavTreeContext"));
254
+
255
+ // src/components/Sidebar/L0Menu.tsx
256
+ import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
257
+ import { draggable, dropTargetForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
258
+ import { preserveOffsetOnSource } from "@atlaskit/pragmatic-drag-and-drop/element/preserve-offset-on-source";
259
+ import { scrollJustEnoughIntoView } from "@atlaskit/pragmatic-drag-and-drop/element/scroll-just-enough-into-view";
260
+ import { attachClosestEdge, extractClosestEdge } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
261
+ import { useAtomValue as useAtomValue2 } from "@effect-atom/atom-react";
262
+ import React2, { forwardRef, memo, useCallback, useLayoutEffect, useMemo as useMemo4, useRef, useState } from "react";
263
+ import { DxAvatar } from "@dxos/lit-ui/react";
264
+ import { useActionRunner } from "@dxos/plugin-graph";
265
+ import { Icon, ListItem, ScrollArea, Tooltip, toLocalizedString, useMediaQuery, useTranslation } from "@dxos/react-ui";
266
+ import { Menu } from "@dxos/react-ui-menu";
267
+ import { Tabs } from "@dxos/react-ui-tabs";
268
+ import { mx as mx2 } from "@dxos/ui-theme";
269
+ import { arrayMove } from "@dxos/util";
270
+
271
+ // src/components/UserAccountAvatar/UserAccountAvatar.tsx
272
+ import React from "react";
273
+ import { Avatar } from "@dxos/react-ui";
274
+ import { hexToFallback } from "@dxos/util";
275
+ var UserAccountAvatar = ({ size, userId, hue, emoji, status }) => {
276
+ const fallbackValue = hexToFallback(userId ?? "0");
277
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(L0ItemActiveTabIndicator, {
278
+ classNames: "inset-y-6"
279
+ }), /* @__PURE__ */ React.createElement("div", {
280
+ className: "grid place-items-center dx-focus-ring-group-indicator rounded-full",
281
+ "data-joyride": "welcome/account"
282
+ }, /* @__PURE__ */ React.createElement(Avatar.Root, null, /* @__PURE__ */ React.createElement(Avatar.Content, {
283
+ variant: "circle",
284
+ size: size ?? 12,
285
+ status: status ?? "active",
286
+ hue: hue || fallbackValue.hue,
287
+ fallback: emoji || fallbackValue.emoji,
288
+ "data-testid": "treeView.userAccount"
289
+ }))));
290
+ };
291
+
292
+ // src/components/Sidebar/L0Menu.tsx
293
+ var useL0ItemClick = ({ item, parent, path }, type) => {
294
+ const { onSelect, onTabChange } = useNavTreeContext();
295
+ const { getItem } = useNavTreeState();
296
+ const [isLg] = useMediaQuery("lg");
297
+ const runAction = useActionRunner();
298
+ return useCallback((event) => {
299
+ switch (type) {
300
+ case "action": {
301
+ const { properties: { caller } = {} } = item;
302
+ return void runAction(item, caller ? {
303
+ parent,
304
+ caller
305
+ } : {
306
+ parent
307
+ });
308
+ }
309
+ case "tab":
310
+ return onTabChange?.(item);
311
+ case "link":
312
+ return onSelect?.({
313
+ item,
314
+ path,
315
+ current: !getItem(path).current,
316
+ option: event.altKey
317
+ });
318
+ }
319
+ }, [
320
+ item,
321
+ parent,
322
+ type,
323
+ getItem,
324
+ onSelect,
325
+ onTabChange,
326
+ isLg,
327
+ runAction
328
+ ]);
329
+ };
330
+ var l0Breakpoints = {
331
+ lg: "hidden lg:grid"
332
+ };
333
+ var l0ItemRoot = 'group/l0item flex w-full justify-center items-center relative data[type!="collection"]:cursor-pointer dx-app-no-drag dx-focus-ring-group';
334
+ var l0ItemContent = "flex justify-center items-center dx-focus-ring-group-indicator transition-colors rounded-sm";
335
+ var L0ItemRoot = /* @__PURE__ */ memo(/* @__PURE__ */ forwardRef(({ item, parent, path, onMouseEnter, children }, forwardedRef) => {
336
+ const { model } = useNavTreeContext();
337
+ const itemPath = useMemo4(() => [
338
+ ...path,
339
+ item.id
340
+ ], [
341
+ item.id,
342
+ path
343
+ ]);
344
+ const { id, testId } = useAtomValue2(model.itemProps(itemPath));
345
+ const type = l0ItemType(item);
346
+ const { t } = useTranslation(meta.id);
347
+ const localizedString = toLocalizedString(item.properties.label, t);
348
+ const handleClick = useL0ItemClick({
349
+ item,
350
+ parent,
351
+ path: itemPath
352
+ }, type);
353
+ const rootProps = type === "tab" ? {
354
+ value: item.id,
355
+ tabIndex: 0,
356
+ onClick: handleClick,
357
+ "data-testid": testId,
358
+ "data-object-id": id
359
+ } : {
360
+ onClick: handleClick,
361
+ "data-testid": testId,
362
+ "data-object-id": id
363
+ };
364
+ return /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
365
+ asChild: true,
366
+ delayDuration: 0,
367
+ side: "right",
368
+ content: localizedString
369
+ }, /* @__PURE__ */ React2.createElement(Tabs.TabPrimitive, {
370
+ ...rootProps,
371
+ "data-type": type,
372
+ className: mx2(l0ItemRoot, l0Breakpoints[item.properties.l0Breakpoint]),
373
+ ref: forwardedRef,
374
+ onMouseEnter
375
+ }, children));
376
+ }));
377
+ var L0ItemActiveTabIndicator = ({ classNames }) => /* @__PURE__ */ React2.createElement("div", {
378
+ role: "none",
379
+ className: mx2("hidden group-aria-selected/l0item:block absolute start-0 inset-y-2 w-1 bg-accent-surface rounded-ie", classNames)
380
+ });
381
+ var L0Item = /* @__PURE__ */ memo(({ item, parent, path, pinned, onRearrange, onItemHover }) => {
382
+ const { t } = useTranslation(meta.id);
383
+ const itemElement = useRef(null);
384
+ const [closestEdge, setEdge] = useState(null);
385
+ const localizedString = toLocalizedString(item.properties.label, t);
386
+ const hue = item.properties.hue ?? null;
387
+ useLayoutEffect(() => {
388
+ if (!itemElement.current || !onRearrange) {
389
+ return;
390
+ }
391
+ return combine(draggable({
392
+ element: itemElement.current,
393
+ getInitialData: () => ({
394
+ id: item.id,
395
+ type: "l0Item"
396
+ }),
397
+ onGenerateDragPreview: ({ nativeSetDragImage, source, location }) => {
398
+ document.body.setAttribute("data-drag-preview", "true");
399
+ const element = source.element.querySelector("[data-frame]");
400
+ scrollJustEnoughIntoView({
401
+ element
402
+ });
403
+ const { x, y } = preserveOffsetOnSource({
404
+ element,
405
+ input: location.current.input
406
+ })({
407
+ container: element.offsetParent ?? document.body
408
+ });
409
+ nativeSetDragImage?.(element, x, y);
410
+ },
411
+ onDragStart: () => {
412
+ document.body.removeAttribute("data-drag-preview");
413
+ itemElement.current.closest("[data-drag-autoscroll]")?.setAttribute("data-drag-autoscroll", "active");
414
+ },
415
+ onDrop: () => {
416
+ itemElement.current.closest("[data-drag-autoscroll]")?.setAttribute("data-drag-autoscroll", "idle");
417
+ }
418
+ }), dropTargetForElements({
419
+ element: itemElement.current,
420
+ getData: ({ input, element }) => {
421
+ return attachClosestEdge({
422
+ id: item.id,
423
+ type: "l0Item"
424
+ }, {
425
+ input,
426
+ element,
427
+ allowedEdges: [
428
+ "top",
429
+ "bottom"
430
+ ]
431
+ });
432
+ },
433
+ onDragEnter: ({ self, source }) => {
434
+ if (source.data.type === self.data.type) {
435
+ setEdge(extractClosestEdge(self.data));
436
+ }
437
+ },
438
+ onDrag: ({ self, source }) => {
439
+ if (source.data.type === self.data.type) {
440
+ setEdge(extractClosestEdge(self.data));
441
+ }
442
+ },
443
+ onDragLeave: () => setEdge(null),
444
+ onDrop: ({ self, source }) => {
445
+ setEdge(null);
446
+ if (source.data.type === self.data.type) {
447
+ onRearrange(source.data, self.data, extractClosestEdge(self.data));
448
+ }
449
+ }
450
+ }));
451
+ }, [
452
+ item,
453
+ onRearrange
454
+ ]);
455
+ const handleMouseEnter = useCallback(() => onItemHover?.({
456
+ item
457
+ }), [
458
+ item,
459
+ onItemHover
460
+ ]);
461
+ return /* @__PURE__ */ React2.createElement(L0ItemRoot, {
462
+ ref: itemElement,
463
+ item,
464
+ parent,
465
+ path,
466
+ onMouseEnter: handleMouseEnter
467
+ }, /* @__PURE__ */ React2.createElement("div", {
468
+ role: "none",
469
+ "data-frame": true,
470
+ ...hue && {
471
+ style: {
472
+ background: `var(--color-${hue}-surface)`
473
+ }
474
+ },
475
+ className: mx2(l0ItemContent, pinned ? "p-2 group-hover/l0item:bg-active-surface" : "w-(--dx-l0-avatar-size) h-(--dx-l0-avatar-size) bg-active-surface")
476
+ }, /* @__PURE__ */ React2.createElement(ItemAvatar, {
477
+ item
478
+ })), /* @__PURE__ */ React2.createElement(L0ItemActiveTabIndicator, null), /* @__PURE__ */ React2.createElement("span", {
479
+ id: `${item.id}__label`,
480
+ className: "sr-only"
481
+ }, localizedString), closestEdge && /* @__PURE__ */ React2.createElement(ListItem.DropIndicator, {
482
+ edge: closestEdge
483
+ }));
484
+ });
485
+ var ItemAvatar = ({ item }) => {
486
+ const { t } = useTranslation(meta.id);
487
+ const type = l0ItemType(item);
488
+ if (item.properties.icon) {
489
+ const hue = item.properties.hue ?? null;
490
+ const hueFgStyle = hue && {
491
+ style: {
492
+ color: `var(--color-${hue}-surface-text)`
493
+ }
494
+ };
495
+ return /* @__PURE__ */ React2.createElement(Icon, {
496
+ icon: item.properties.icon,
497
+ size: 6,
498
+ ...hueFgStyle
499
+ });
500
+ }
501
+ if (type === "tab" && item.properties.disposition !== "pin-end") {
502
+ const hue = item.properties.hue ?? null;
503
+ const localizedString = toLocalizedString(item.properties.label, t);
504
+ return /* @__PURE__ */ React2.createElement(DxAvatar, {
505
+ hue,
506
+ hueVariant: "surface",
507
+ variant: "square",
508
+ size: 12,
509
+ fallback: localizedString
510
+ });
511
+ }
512
+ return null;
513
+ };
514
+ var L0Menu = ({ menuActions, topLevelItems, pinnedItems, userAccountItem, parent, path, onItemHover }) => {
515
+ const { t } = useTranslation(meta.id);
516
+ const runAction = useActionRunner();
517
+ const handleAction = useCallback((action, params) => {
518
+ void runAction(action, params);
519
+ }, [
520
+ runAction
521
+ ]);
522
+ const handleRearrange = useCallback((source, target, closestEdge) => {
523
+ const sourceItem = topLevelItems.find((i) => i.id === source.id);
524
+ if (!sourceItem?.properties.onRearrange) {
525
+ return;
526
+ }
527
+ const sourceIndex = topLevelItems.findIndex((i) => i.id === source.id);
528
+ const targetIndex = topLevelItems.findIndex((i) => i.id === target.id);
529
+ const insertIndex = source.id === target.id ? sourceIndex : targetIndex + (sourceIndex < targetIndex ? closestEdge === "top" ? -1 : 0 : closestEdge === "bottom" ? 1 : 0);
530
+ const nextOrder = arrayMove([
531
+ ...topLevelItems
532
+ ], sourceIndex, insertIndex);
533
+ return sourceItem.properties.onRearrange(nextOrder.map((item) => item.data));
534
+ }, [
535
+ topLevelItems
536
+ ]);
537
+ const hasRearrangeableItems = topLevelItems.some((item) => item.properties.onRearrange);
538
+ return /* @__PURE__ */ React2.createElement(Tabs.Tablist, {
539
+ classNames: [
540
+ "group/l0 absolute z-[1] inset-y-0 start-0 rounded-is",
541
+ "grid grid-cols-[var(--dx-l0-size)] grid-rows-[var(--dx-rail-size)_1fr_min-content_var(--dx-l0-size)] dx-contain-layout",
542
+ "!w-(--dx-l0-size) bg-toolbar-surface border-e border-subdued-separator dx-app-drag pb-[env(safe-area-inset-bottom)]"
543
+ ]
544
+ }, /* @__PURE__ */ React2.createElement(Menu.Root, {
545
+ onAction: handleAction
546
+ }, /* @__PURE__ */ React2.createElement(Menu.Trigger, {
547
+ asChild: true,
548
+ "data-testid": "spacePlugin.addSpace",
549
+ className: mx2(l0ItemRoot, "grid place-items-center dx-focus-ring-group", '[body[data-platform="macos"]_&]:mt-[30px]')
550
+ }, /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
551
+ content: t("app menu label"),
552
+ side: "right",
553
+ asChild: true
554
+ }, /* @__PURE__ */ React2.createElement(Tabs.TabPrimitive, {
555
+ value: "options",
556
+ asChild: true,
557
+ role: "button"
558
+ }, /* @__PURE__ */ React2.createElement("div", {
559
+ role: "none",
560
+ className: mx2(l0ItemContent, "h-(--dx-rail-action) w-(--dx-rail-action) group-hover/l0item:bg-hover-surface")
561
+ }, /* @__PURE__ */ React2.createElement(Icon, {
562
+ icon: "ph--list--regular",
563
+ size: 5
564
+ }))))), /* @__PURE__ */ React2.createElement(Menu.Content, {
565
+ group: parent,
566
+ items: menuActions
567
+ })), /* @__PURE__ */ React2.createElement(ScrollArea.Root, {
568
+ thin: true,
569
+ orientation: "vertical"
570
+ }, /* @__PURE__ */ React2.createElement(ScrollArea.Viewport, null, /* @__PURE__ */ React2.createElement("div", {
571
+ role: "none",
572
+ className: mx2([
573
+ "flex flex-col gap-1 pt-1",
574
+ '[body[data-platform="macos"]_&]:py-[30px]',
575
+ '[body[data-platform="ios"]_&]:py-[max(env(safe-area-inset-top),0.25rem)]'
576
+ ])
577
+ }, topLevelItems.map((item) => /* @__PURE__ */ React2.createElement(L0Item, {
578
+ key: item.id,
579
+ item,
580
+ parent,
581
+ path,
582
+ onItemHover,
583
+ ...hasRearrangeableItems && {
584
+ onRearrange: handleRearrange
585
+ }
586
+ }))))), /* @__PURE__ */ React2.createElement("div", {
587
+ role: "none",
588
+ className: "grid grid-cols-1 auto-rows-(--dx-rail-action) pt-2"
589
+ }, pinnedItems.map((item) => /* @__PURE__ */ React2.createElement(L0Item, {
590
+ key: item.id,
591
+ item,
592
+ parent,
593
+ path,
594
+ pinned: true
595
+ }))), userAccountItem && /* @__PURE__ */ React2.createElement("div", {
596
+ role: "none",
597
+ className: "grid dx-app-no-drag"
598
+ }, /* @__PURE__ */ React2.createElement(L0ItemRoot, {
599
+ key: userAccountItem.id,
600
+ item: userAccountItem,
601
+ parent,
602
+ path
603
+ }, /* @__PURE__ */ React2.createElement(UserAccountAvatar, {
604
+ userId: userAccountItem.properties.userId,
605
+ hue: userAccountItem.properties.hue,
606
+ emoji: userAccountItem.properties.emoji,
607
+ status: userAccountItem.properties.status,
608
+ size: 10
609
+ }))));
610
+ };
611
+
612
+ // src/components/Sidebar/L1Panel.tsx
613
+ import * as Effect from "effect/Effect";
614
+ import * as Option2 from "effect/Option";
615
+ import React5, { memo as memo3, useCallback as useCallback2, useMemo as useMemo6 } from "react";
616
+ import { Node as Node4 } from "@dxos/app-graph";
617
+ import { useAppGraph as useAppGraph4 } from "@dxos/app-toolkit/ui";
618
+ import { Graph as Graph4, useActionRunner as useActionRunner3, useConnections, useEdges } from "@dxos/plugin-graph";
619
+ import { DensityProvider, IconButton as IconButton2, ScrollArea as ScrollArea2, toLocalizedString as toLocalizedString4, useTranslation as useTranslation4 } from "@dxos/react-ui";
620
+ import { Tree } from "@dxos/react-ui-list";
621
+ import { Menu as Menu3 } from "@dxos/react-ui-menu";
622
+ import { Tabs as Tabs2 } from "@dxos/react-ui-tabs";
623
+ import { hoverableControlItem as hoverableControlItem2, hoverableOpenControlItem as hoverableOpenControlItem2 } from "@dxos/ui-theme";
624
+
625
+ // src/components/NavTreeItem/NavTreeItemAction.tsx
626
+ import React3 from "react";
627
+ import { useActionRunner as useActionRunner2 } from "@dxos/plugin-graph";
628
+ import { IconButton, toLocalizedString as toLocalizedString2, useDensityContext, useTranslation as useTranslation2 } from "@dxos/react-ui";
629
+ import { Menu as Menu2 } from "@dxos/react-ui-menu";
630
+ import { hoverableControlItem, hoverableOpenControlItem } from "@dxos/ui-theme";
631
+ var fallbackIcon = "ph--placeholder--regular";
632
+ var fineActionButtonProps = {
633
+ size: 4,
634
+ density: "fine"
635
+ };
636
+ var coarseActionButtonProps = {
637
+ size: 5,
638
+ density: "coarse"
639
+ };
640
+ var NavTreeItemActionDropdownMenu = ({ parent, label, icon, testId, menuActions, caller }) => {
641
+ const { t } = useTranslation2(meta.id);
642
+ const density = useDensityContext();
643
+ const runAction = useActionRunner2();
644
+ return /* @__PURE__ */ React3.createElement(Menu2.Root, {
645
+ caller,
646
+ onAction: runAction
647
+ }, /* @__PURE__ */ React3.createElement(Menu2.Trigger, {
648
+ asChild: true
649
+ }, /* @__PURE__ */ React3.createElement(IconButton, {
650
+ ...density === "coarse" ? coarseActionButtonProps : fineActionButtonProps,
651
+ classNames: [
652
+ "shrink-0 px-2 pointer-fine:px-1",
653
+ hoverableControlItem,
654
+ hoverableOpenControlItem
655
+ ],
656
+ variant: "ghost",
657
+ icon: icon ?? fallbackIcon,
658
+ iconOnly: true,
659
+ label: toLocalizedString2(label, t),
660
+ "data-testid": testId
661
+ })), /* @__PURE__ */ React3.createElement(Menu2.Content, {
662
+ group: parent,
663
+ items: menuActions
664
+ }));
665
+ };
666
+ var NavTreeItemMonolithicAction = (props) => {
667
+ const { parent, properties: { disabled, caller, testId, icon, variant = "ghost", iconOnly = true } = {
668
+ label: "never"
669
+ }, baseLabel } = props;
670
+ const density = useDensityContext();
671
+ const runAction = useActionRunner2();
672
+ return /* @__PURE__ */ React3.createElement(IconButton, {
673
+ ...density === "coarse" ? coarseActionButtonProps : fineActionButtonProps,
674
+ variant,
675
+ classNames: [
676
+ "shrink-0",
677
+ hoverableControlItem,
678
+ hoverableOpenControlItem,
679
+ iconOnly ? "px-2 pointer-fine:px-1" : "p-2 pointer-fine:p-2 me-1"
680
+ ],
681
+ icon: icon ?? fallbackIcon,
682
+ iconOnly,
683
+ label: baseLabel,
684
+ disabled,
685
+ onClick: (event) => {
686
+ event.stopPropagation();
687
+ if (disabled) {
688
+ return;
689
+ }
690
+ void runAction(props, caller ? {
691
+ parent,
692
+ caller
693
+ } : {
694
+ parent
695
+ });
696
+ },
697
+ "data-testid": testId
698
+ });
699
+ };
700
+ var NavTreeItemAction = ({ monolithic, menuActions, parent: node, ...props }) => {
701
+ const { t } = useTranslation2(meta.id);
702
+ const monolithicAction = menuActions?.length === 1 && menuActions[0];
703
+ const baseLabel = toLocalizedString2(monolithicAction ? monolithicAction.properties.label : props.label, t);
704
+ return monolithic && menuActions?.length === 1 ? /* @__PURE__ */ React3.createElement(NavTreeItemMonolithicAction, {
705
+ baseLabel,
706
+ parent: node,
707
+ ...menuActions[0]
708
+ }) : /* @__PURE__ */ React3.createElement(NavTreeItemActionDropdownMenu, {
709
+ ...props,
710
+ label: baseLabel,
711
+ parent: node,
712
+ menuActions
713
+ });
714
+ };
715
+
716
+ // src/components/NavTreeItem/NavTreeItemColumns.tsx
717
+ import React4, { Fragment, memo as memo2, useMemo as useMemo5 } from "react";
718
+ import { Node as Node3 } from "@dxos/app-graph";
719
+ import { Popover, Treegrid, toLocalizedString as toLocalizedString3, useTranslation as useTranslation3 } from "@dxos/react-ui";
720
+ var NavTreeItemColumns = /* @__PURE__ */ memo2(({ path, item, open }) => {
721
+ const { t } = useTranslation3(meta.id);
722
+ const { renderItemEnd: ItemEnd, popoverAnchorId } = useNavTreeContext();
723
+ const level = path.length - 2;
724
+ const { actions: actionsProp, groupedActions } = useActions(item);
725
+ const sortedActions = useMemo5(() => actionsProp.toSorted((actionA, actionB) => {
726
+ const primaryA = actionA.properties?.disposition === "list-item-primary";
727
+ const primaryB = actionB.properties?.disposition === "list-item-primary";
728
+ if (primaryA && !primaryB) {
729
+ return -1;
730
+ }
731
+ if (primaryB && !primaryA) {
732
+ return 1;
733
+ }
734
+ return 0;
735
+ }), [
736
+ actionsProp
737
+ ]);
738
+ const [primaryAction, ...secondaryActions] = sortedActions;
739
+ const actions = useMemo5(() => (primaryAction?.properties?.disposition === "list-item-primary" ? secondaryActions : sortedActions).flatMap((action) => Node3.isAction(action) ? [
740
+ action
741
+ ] : []).filter((a) => [
742
+ "list-item",
743
+ "list-item-primary"
744
+ ].includes(a.properties?.disposition)), [
745
+ sortedActions,
746
+ primaryAction
747
+ ]);
748
+ const primaryMenuActions = useMemo5(() => primaryAction ? Node3.isAction(primaryAction) ? [
749
+ primaryAction
750
+ ] : groupedActions[primaryAction?.id ?? ""] : void 0, [
751
+ primaryAction,
752
+ groupedActions
753
+ ]);
754
+ const ActionRoot = popoverAnchorId === `dxos.org/ui/${NAV_TREE_ITEM}/${item.id}` ? Popover.Anchor : Fragment;
755
+ return /* @__PURE__ */ React4.createElement("div", {
756
+ role: "none",
757
+ className: "contents dx-app-no-drag"
758
+ }, primaryAction?.properties?.disposition === "list-item-primary" && !primaryAction?.properties?.disabled ? /* @__PURE__ */ React4.createElement(Treegrid.Cell, {
759
+ classNames: "contents"
760
+ }, /* @__PURE__ */ React4.createElement(NavTreeItemAction, {
761
+ testId: primaryAction.properties?.testId,
762
+ label: toLocalizedString3(primaryAction.properties?.label, t),
763
+ icon: primaryAction.properties?.icon ?? "ph--placeholder--regular",
764
+ parent: item,
765
+ monolithic: Node3.isAction(primaryAction),
766
+ menuActions: primaryMenuActions,
767
+ menuType: primaryAction.properties?.menuType,
768
+ caller: NAV_TREE_ITEM
769
+ })) : /* @__PURE__ */ React4.createElement(Treegrid.Cell, {
770
+ role: "none"
771
+ }), /* @__PURE__ */ React4.createElement(ActionRoot, null, actions.length > 0 ? /* @__PURE__ */ React4.createElement(Treegrid.Cell, {
772
+ classNames: "contents"
773
+ }, /* @__PURE__ */ React4.createElement(NavTreeItemAction, {
774
+ testId: `navtree.treeItem.actionsLevel${level}`,
775
+ label: t("tree item actions label"),
776
+ icon: "ph--dots-three-vertical--regular",
777
+ parent: item,
778
+ menuActions: actions,
779
+ menuType: "dropdown",
780
+ caller: NAV_TREE_ITEM
781
+ })) : /* @__PURE__ */ React4.createElement(Treegrid.Cell, {
782
+ role: "none"
783
+ })), ItemEnd && /* @__PURE__ */ React4.createElement(Treegrid.Cell, {
784
+ classNames: "contents"
785
+ }, /* @__PURE__ */ React4.createElement(ItemEnd, {
786
+ node: item,
787
+ open
788
+ })));
789
+ });
790
+
791
+ // src/components/Sidebar/L1Panel.tsx
792
+ var L1Panel$ = ({ open, path, item, isCurrent, onBack }) => {
793
+ const { t } = useTranslation4(meta.id);
794
+ const title = toLocalizedString4(item.properties.label, t);
795
+ const isActivated = useIsActivatedWorkspace(item);
796
+ const shouldRenderContent = isCurrent || isActivated;
797
+ return /* @__PURE__ */ React5.createElement(Tabs2.Tabpanel, {
798
+ key: item.id,
799
+ value: item.id,
800
+ classNames: [
801
+ "absolute inset-y-0 end-0",
802
+ "w-[calc(100%-var(--dx-l0-size))] lg:w-(--dx-l1-size) grid-cols-1 grid-rows-[var(--dx-rail-size)_1fr]",
803
+ "py-[env(safe-area-inset-top)]",
804
+ isCurrent && "grid"
805
+ ],
806
+ tabIndex: -1,
807
+ "aria-label": title,
808
+ ...isCurrent && {
809
+ "data-testid": "navtree.workspace.visible"
810
+ },
811
+ ...!open && {
812
+ inert: true
813
+ }
814
+ }, shouldRenderContent && /* @__PURE__ */ React5.createElement(L1PanelContent, {
815
+ open,
816
+ path,
817
+ item,
818
+ onBack
819
+ }));
820
+ };
821
+ var useIsActivatedWorkspace = (item) => {
822
+ const { graph } = useAppGraph4();
823
+ const edges = useEdges(graph, item.id);
824
+ return useMemo6(() => {
825
+ const childIds = edges[Graph4.relationKey("child")] ?? [];
826
+ return childIds.some((childId) => {
827
+ const child = Graph4.getNode(graph, childId);
828
+ if (Option2.isNone(child)) {
829
+ return false;
830
+ }
831
+ return child.value.properties.disposition === void 0;
832
+ });
833
+ }, [
834
+ edges,
835
+ graph
836
+ ]);
837
+ };
838
+ var L1PanelContent = ({ path, item, onBack }) => {
839
+ const navTreeContext = useNavTreeContext();
840
+ const alternateTree = useAlternateTreeItem(item);
841
+ const alternatePath = useMemo6(() => [
842
+ ...path,
843
+ item.id
844
+ ], [
845
+ item.id,
846
+ path
847
+ ]);
848
+ const isAlternate = useIsAlternateTree(alternatePath, item);
849
+ return /* @__PURE__ */ React5.createElement(DensityProvider, {
850
+ density: "fine"
851
+ }, /* @__PURE__ */ React5.createElement(L1PanelHeader, {
852
+ path,
853
+ item,
854
+ onBack
855
+ }), /* @__PURE__ */ React5.createElement(ScrollArea2.Root, {
856
+ thin: true,
857
+ orientation: "vertical"
858
+ }, /* @__PURE__ */ React5.createElement(ScrollArea2.Viewport, null, isAlternate && alternateTree ? /* @__PURE__ */ React5.createElement(Tree, {
859
+ model: navTreeContext.model,
860
+ id: alternateTree.id,
861
+ rootId: alternateTree.id,
862
+ path: alternatePath,
863
+ levelOffset: 5,
864
+ gridTemplateColumns: "[tree-row-start] 1fr min-content min-content min-content [tree-row-end]",
865
+ renderColumns: NavTreeItemColumns,
866
+ blockInstruction: navTreeContext.blockInstruction,
867
+ canDrop: navTreeContext.canDrop,
868
+ canSelect: navTreeContext.canSelect,
869
+ onOpenChange: navTreeContext.onOpenChange,
870
+ onSelect: navTreeContext.onSelect,
871
+ onItemHover: navTreeContext.onItemHover
872
+ }) : /* @__PURE__ */ React5.createElement(Tree, {
873
+ model: navTreeContext.model,
874
+ id: item.id,
875
+ rootId: item.id,
876
+ path,
877
+ levelOffset: 5,
878
+ gridTemplateColumns: "[tree-row-start] 1fr min-content min-content min-content [tree-row-end]",
879
+ draggable: true,
880
+ renderColumns: NavTreeItemColumns,
881
+ blockInstruction: navTreeContext.blockInstruction,
882
+ canDrop: navTreeContext.canDrop,
883
+ canSelect: navTreeContext.canSelect,
884
+ onOpenChange: navTreeContext.onOpenChange,
885
+ onSelect: navTreeContext.onSelect,
886
+ onItemHover: navTreeContext.onItemHover
887
+ }))));
888
+ };
889
+ var L1PanelHeader = ({ item, path, onBack }) => {
890
+ const { t } = useTranslation4(meta.id);
891
+ const { renderItemEnd: ItemEnd } = useNavTreeContext();
892
+ const title = toLocalizedString4(item.properties.label, t);
893
+ const backCapableWorkspace = item.id.startsWith("!");
894
+ const { primaryAction, groupedActions, menuActions, onAction } = useL1MenuActions({
895
+ item,
896
+ path
897
+ });
898
+ useLoadDescendents(item);
899
+ return /* @__PURE__ */ React5.createElement("div", {
900
+ className: "flex w-full items-center border-b border-subdued-separator dx-app-drag dx-density-coarse pe-1"
901
+ }, backCapableWorkspace ? /* @__PURE__ */ React5.createElement(IconButton2, {
902
+ size: 5,
903
+ density: "coarse",
904
+ classNames: [
905
+ "shrink-0 px-2 pointer-fine:px-1",
906
+ hoverableControlItem2,
907
+ hoverableOpenControlItem2
908
+ ],
909
+ variant: "ghost",
910
+ icon: "ph--caret-left--regular",
911
+ iconOnly: true,
912
+ label: t("button back"),
913
+ "data-testid": "treeView.primaryTreeButton",
914
+ onClick: () => onBack?.()
915
+ }) : /* @__PURE__ */ React5.createElement("div", {
916
+ className: "w-6"
917
+ }), /* @__PURE__ */ React5.createElement("h2", {
918
+ className: "flex-1 truncate min-w-0"
919
+ }, title), /* @__PURE__ */ React5.createElement("div", {
920
+ role: "none",
921
+ className: "contents dx-app-no-drag"
922
+ }, primaryAction?.properties?.disposition === "list-item-primary" && !primaryAction?.properties?.disabled && /* @__PURE__ */ React5.createElement(NavTreeItemAction, {
923
+ testId: primaryAction.properties?.testId,
924
+ label: toLocalizedString4(primaryAction.properties?.label, t),
925
+ icon: primaryAction.properties?.icon ?? "ph--placeholder--regular",
926
+ parent: item,
927
+ monolithic: Node4.isAction(primaryAction),
928
+ menuActions: Node4.isAction(primaryAction) ? [
929
+ primaryAction
930
+ ] : groupedActions[primaryAction?.id ?? ""],
931
+ menuType: primaryAction.properties?.menuType,
932
+ caller: NAV_TREE_ITEM
933
+ }), menuActions.length === 1 && /* @__PURE__ */ React5.createElement(IconButton2, {
934
+ size: 5,
935
+ density: "coarse",
936
+ classNames: [
937
+ "shrink-0 px-2 pointer-fine:px-1",
938
+ hoverableControlItem2,
939
+ hoverableOpenControlItem2
940
+ ],
941
+ variant: "ghost",
942
+ icon: menuActions[0].properties?.icon ?? "ph--placeholder--regular",
943
+ iconOnly: true,
944
+ label: toLocalizedString4(menuActions[0].properties?.label, t),
945
+ "data-testid": menuActions[0].properties?.testId,
946
+ onClick: () => onAction(menuActions[0])
947
+ }), menuActions.length > 1 && /* @__PURE__ */ React5.createElement(Menu3.Root, {
948
+ caller: NAV_TREE_ITEM,
949
+ onAction
950
+ }, /* @__PURE__ */ React5.createElement(Menu3.Trigger, {
951
+ asChild: true
952
+ }, /* @__PURE__ */ React5.createElement(IconButton2, {
953
+ size: 5,
954
+ density: "coarse",
955
+ classNames: [
956
+ "shrink-0 px-2 pointer-fine:px-1",
957
+ hoverableControlItem2,
958
+ hoverableOpenControlItem2
959
+ ],
960
+ variant: "ghost",
961
+ icon: "ph--dots-three-vertical--regular",
962
+ iconOnly: true,
963
+ label: t("tree item actions label"),
964
+ "data-testid": "navtree.treeItem.actionsLevel0"
965
+ })), /* @__PURE__ */ React5.createElement(Menu3.Content, {
966
+ group: item,
967
+ items: menuActions
968
+ })), ItemEnd && /* @__PURE__ */ React5.createElement(ItemEnd, {
969
+ node: item,
970
+ open: true
971
+ })));
972
+ };
973
+ var useL1MenuActions = ({ item, path }) => {
974
+ const { t } = useTranslation4(meta.id);
975
+ const { setAlternateTree } = useNavTreeContext();
976
+ const { graph } = useAppGraph4();
977
+ const runAction = useActionRunner3();
978
+ const alternateTree = useAlternateTreeItem(item);
979
+ const alternatePath = useMemo6(() => [
980
+ ...path,
981
+ item.id
982
+ ], [
983
+ item.id,
984
+ path
985
+ ]);
986
+ const isAlternate = useIsAlternateTree(alternatePath, item);
987
+ const { actions: actionsProp, groupedActions } = useActions(item);
988
+ const [primaryAction, ...secondaryActions] = actionsProp.toSorted((a, _b) => a.properties?.disposition === "list-item-primary" ? -1 : 1);
989
+ const graphMenuActions = (primaryAction?.properties?.disposition === "list-item-primary" ? secondaryActions : actionsProp).flatMap((action) => Node4.isAction(action) ? [
990
+ action
991
+ ] : []).filter((a) => [
992
+ "list-item",
993
+ "list-item-primary"
994
+ ].includes(a.properties?.disposition));
995
+ const settingsActionId = `${item.id}~settings`;
996
+ const settingsAction = useMemo6(() => {
997
+ if (!alternateTree) {
998
+ return void 0;
999
+ }
1000
+ return {
1001
+ id: settingsActionId,
1002
+ type: Node4.ActionType,
1003
+ data: () => Effect.void,
1004
+ properties: {
1005
+ label: isAlternate ? [
1006
+ "button back",
1007
+ {
1008
+ ns: meta.id
1009
+ }
1010
+ ] : alternateTree.properties.label ?? alternateTree.id,
1011
+ icon: isAlternate ? "ph--arrow-u-down-left--regular" : alternateTree.properties.icon ?? "ph--placeholder--regular",
1012
+ disposition: "list-item",
1013
+ testId: isAlternate ? "navtree.backToSpace" : "navtree.spaceSettings"
1014
+ }
1015
+ };
1016
+ }, [
1017
+ alternateTree,
1018
+ isAlternate,
1019
+ settingsActionId,
1020
+ t
1021
+ ]);
1022
+ const menuActions = useMemo6(() => [
1023
+ ...graphMenuActions,
1024
+ ...settingsAction ? [
1025
+ settingsAction
1026
+ ] : []
1027
+ ], [
1028
+ graphMenuActions,
1029
+ settingsAction
1030
+ ]);
1031
+ const onAction = useCallback2((action, params) => {
1032
+ if (action.id === settingsActionId) {
1033
+ if (alternateTree && !isAlternate) {
1034
+ Graph4.expand(graph, alternateTree.id, "child");
1035
+ }
1036
+ setAlternateTree?.(alternatePath, !isAlternate);
1037
+ } else {
1038
+ void runAction(action, params);
1039
+ }
1040
+ }, [
1041
+ settingsActionId,
1042
+ setAlternateTree,
1043
+ alternatePath,
1044
+ isAlternate,
1045
+ runAction,
1046
+ graph,
1047
+ alternateTree
1048
+ ]);
1049
+ return {
1050
+ primaryAction,
1051
+ groupedActions,
1052
+ menuActions,
1053
+ onAction
1054
+ };
1055
+ };
1056
+ var useAlternateTreeItem = (item) => {
1057
+ const { graph } = useAppGraph4();
1058
+ const connections = useConnections(graph, item.id, "child");
1059
+ return connections.find((node) => node.properties.disposition === "alternate-tree");
1060
+ };
1061
+ var L1Panel = /* @__PURE__ */ memo3(L1Panel$);
1062
+
1063
+ // src/components/Sidebar/L1Tabs.tsx
1064
+ import React6 from "react";
1065
+ var L1Tabs = ({ topLevelItems, currentItemId, onBack, open, path }) => {
1066
+ return /* @__PURE__ */ React6.createElement(React6.Fragment, null, topLevelItems.map((item) => {
1067
+ const type = l0ItemType(item);
1068
+ if (type === "tab") {
1069
+ return /* @__PURE__ */ React6.createElement(L1Panel, {
1070
+ key: item.id,
1071
+ item,
1072
+ path,
1073
+ open,
1074
+ onBack,
1075
+ isCurrent: item.id === currentItemId
1076
+ });
1077
+ }
1078
+ return null;
1079
+ }));
1080
+ };
1081
+
1082
+ // src/components/NavTree/NavTree.tsx
1083
+ var NAV_TREE_ITEM = "NavTreeItem";
1084
+ var NavTree = /* @__PURE__ */ forwardRef2(({ id, root, tab, ...props }, forwardedRef) => {
1085
+ const { onBack, onItemHover } = useNavTreeContext();
1086
+ const { topLevelActions, l0Items, pinnedItems, userAccountItem, topLevelItems } = useTopLevelNavItems(root);
1087
+ useLoadDescendents(root);
1088
+ const path = useMemo7(() => [
1089
+ id
1090
+ ], [
1091
+ id
1092
+ ]);
1093
+ return (
1094
+ // TODO(thure): `Tabs.Root` forces all items that should be able to receive focus to use `Tabs.Tab(Primitive)` since
1095
+ // it uses RovingFocus and doesn't support moving focus to an item that is not a tab. Assess whether this situation
1096
+ // should change including whether it should motivate a change in the design/taxonomy, or if this means this should
1097
+ // not use `react-ui-tabs` at all.
1098
+ /* @__PURE__ */ React7.createElement(Tabs3.Root, {
1099
+ value: tab,
1100
+ orientation: "vertical",
1101
+ verticalVariant: "stateless",
1102
+ classNames: "relative",
1103
+ ref: forwardedRef
1104
+ }, /* @__PURE__ */ React7.createElement(L0Menu, {
1105
+ menuActions: topLevelActions,
1106
+ topLevelItems: l0Items,
1107
+ pinnedItems,
1108
+ userAccountItem,
1109
+ path,
1110
+ parent: root,
1111
+ onItemHover
1112
+ }), /* @__PURE__ */ React7.createElement(L1Tabs, {
1113
+ topLevelItems,
1114
+ path,
1115
+ currentItemId: tab,
1116
+ onBack,
1117
+ ...props
1118
+ }))
1119
+ );
1120
+ });
1121
+ var useTopLevelNavItems = (root) => {
1122
+ const { graph } = useAppGraph5();
1123
+ const rootId = root?.id ?? Node5.RootId;
1124
+ const rootOutboundItems = useConnections2(graph, rootId, "child");
1125
+ const rootActions = useGraphActions2(graph, rootId);
1126
+ const { topLevelActions, l0Items, pinnedItems, userAccountItem } = useMemo7(() => {
1127
+ const topLevelWorkspaces = [];
1128
+ const outboundPinnedItems = [];
1129
+ let userAccountItem2;
1130
+ for (const node of rootOutboundItems) {
1131
+ switch (node.properties.disposition) {
1132
+ case "workspace":
1133
+ topLevelWorkspaces.push(node);
1134
+ break;
1135
+ case "pin-end":
1136
+ outboundPinnedItems.push(node);
1137
+ break;
1138
+ case "user-account":
1139
+ userAccountItem2 ??= node;
1140
+ break;
1141
+ }
1142
+ }
1143
+ const topLevelActions2 = rootActions.filter((action) => action.properties.disposition === "menu").toSorted((a, b) => byPosition(a.properties, b.properties));
1144
+ const pinnedItems2 = [
1145
+ ...outboundPinnedItems,
1146
+ ...rootActions.filter((action) => action.properties.disposition === "pin-end")
1147
+ ].toSorted((a, b) => byPosition(a.properties, b.properties));
1148
+ return {
1149
+ topLevelActions: topLevelActions2,
1150
+ l0Items: topLevelWorkspaces,
1151
+ pinnedItems: pinnedItems2,
1152
+ userAccountItem: userAccountItem2
1153
+ };
1154
+ }, [
1155
+ rootActions,
1156
+ rootOutboundItems
1157
+ ]);
1158
+ const topLevelItems = useMemo7(() => [
1159
+ ...l0Items,
1160
+ ...pinnedItems,
1161
+ ...userAccountItem ? [
1162
+ userAccountItem
1163
+ ] : []
1164
+ ], [
1165
+ l0Items,
1166
+ pinnedItems,
1167
+ userAccountItem
1168
+ ]);
1169
+ return {
1170
+ topLevelActions,
1171
+ l0Items,
1172
+ pinnedItems,
1173
+ userAccountItem,
1174
+ topLevelItems
1175
+ };
1176
+ };
1177
+
1178
+ // src/containers/NavTreeContainer/NavTreeContainer.tsx
1179
+ var NODE_TYPE = "dxos/app-graph/node";
1180
+ var NavTreeItemEnd = ({ node, open }) => {
1181
+ const data = useMemo8(() => ({
1182
+ id: node.id,
1183
+ subject: node.data,
1184
+ open
1185
+ }), [
1186
+ node.id,
1187
+ node.data,
1188
+ open
1189
+ ]);
1190
+ return /* @__PURE__ */ React8.createElement(Surface.Surface, {
1191
+ role: "navtree-item-end",
1192
+ data,
1193
+ limit: 1
1194
+ });
1195
+ };
1196
+ var getItems = (graph, node, disposition) => {
1197
+ return Graph5.getConnections(graph, node?.id ?? Node6.RootId, "child").filter((node2) => filterItems(node2, disposition));
1198
+ };
1199
+ var NavTreeContainer$ = /* @__PURE__ */ forwardRef3(({ tab, popoverAnchorId }, forwardedRef) => {
1200
+ const [isLg] = useMediaQuery2("lg");
1201
+ const { invokeSync, invokePromise } = useOperationInvoker();
1202
+ const runAction = useActionRunner4();
1203
+ const { graph } = useAppGraph6();
1204
+ const { getItem, setItem } = useNavTreeState();
1205
+ const layout = useLayout();
1206
+ const model = useNavTreeModel(Node6.RootId);
1207
+ const { navigationSidebarState } = useSidebars(meta.id);
1208
+ const latestRef = useRef2({
1209
+ tab,
1210
+ activeItems: layout.active,
1211
+ navigationSidebarState,
1212
+ isLg
1213
+ });
1214
+ useEffect2(() => {
1215
+ latestRef.current = {
1216
+ tab,
1217
+ activeItems: layout.active,
1218
+ navigationSidebarState,
1219
+ isLg
1220
+ };
1221
+ }, [
1222
+ tab,
1223
+ layout.active,
1224
+ navigationSidebarState,
1225
+ isLg
1226
+ ]);
1227
+ const handleOpenChange = useCallback3(({ item: { id }, path, open }) => {
1228
+ setItem(path, "open", open);
1229
+ Graph5.expand(graph, id, "child");
1230
+ }, [
1231
+ graph,
1232
+ setItem
1233
+ ]);
1234
+ const handleTabChange = useCallback3((node) => {
1235
+ Graph5.expand(graph, node.id, "child");
1236
+ const { tab: activeTab, activeItems, navigationSidebarState: currentSidebarState, isLg: latestIsLg } = latestRef.current;
1237
+ invokeSync(LayoutOperation.UpdateSidebar, {
1238
+ state: node.id === activeTab ? currentSidebarState === "expanded" ? latestIsLg ? "collapsed" : "closed" : "expanded" : "expanded"
1239
+ });
1240
+ invokeSync(LayoutOperation.SwitchWorkspace, {
1241
+ subject: node.id
1242
+ });
1243
+ if (activeItems.length === 0) {
1244
+ const [item] = getItems(graph, node).filter((node2) => !Node6.isActionLike(node2));
1245
+ if (item && item.data) {
1246
+ invokeSync(LayoutOperation.Open, {
1247
+ subject: [
1248
+ item.id
1249
+ ]
1250
+ });
1251
+ }
1252
+ }
1253
+ }, [
1254
+ invokeSync,
1255
+ graph
1256
+ ]);
1257
+ const blockInstruction = useCallback3(({ instruction, source, target }) => {
1258
+ return target.item.properties.blockInstruction?.(source, instruction) ?? false;
1259
+ }, []);
1260
+ const canDrop = useCallback3(({ source, target }) => {
1261
+ return target.item.properties.canDrop?.(source) ?? false;
1262
+ }, []);
1263
+ const canSelect = useCallback3(({ item }) => {
1264
+ return item.properties.selectable ?? true;
1265
+ }, []);
1266
+ const handleSelect = useCallback3(({ item: node, path, option }) => {
1267
+ if (!node.data) {
1268
+ return;
1269
+ }
1270
+ if (Node6.isAction(node)) {
1271
+ const [parent] = Graph5.getConnections(graph, node.id, Node6.childRelation("inbound"));
1272
+ if (parent) {
1273
+ void runAction(node, {
1274
+ parent,
1275
+ caller: NAV_TREE_ITEM
1276
+ });
1277
+ }
1278
+ return;
1279
+ }
1280
+ const current = getItem(path).current;
1281
+ if (!current) {
1282
+ invokeSync(LayoutOperation.Open, {
1283
+ subject: [
1284
+ node.id
1285
+ ],
1286
+ key: node.properties.key
1287
+ });
1288
+ } else if (option) {
1289
+ invokeSync(LayoutOperation.Close, {
1290
+ subject: [
1291
+ node.id
1292
+ ]
1293
+ });
1294
+ } else {
1295
+ void invokePromise(LayoutOperation.ScrollIntoView, {
1296
+ subject: node.id
1297
+ });
1298
+ }
1299
+ const defaultAction = Graph5.getActions(graph, node.id).find((action) => action.properties?.disposition === "default");
1300
+ if (Node6.isAction(defaultAction)) {
1301
+ void runAction(defaultAction);
1302
+ }
1303
+ if (!isLg) {
1304
+ invokeSync(LayoutOperation.UpdateSidebar, {
1305
+ state: "closed"
1306
+ });
1307
+ }
1308
+ }, [
1309
+ graph,
1310
+ invokeSync,
1311
+ invokePromise,
1312
+ getItem,
1313
+ runAction,
1314
+ isLg
1315
+ ]);
1316
+ const handleBack = useCallback3(() => invokeSync(LayoutOperation.RevertWorkspace), [
1317
+ invokeSync
1318
+ ]);
1319
+ useEffect2(() => {
1320
+ return monitorForElements({
1321
+ canMonitor: ({ source }) => isTreeData(source.data),
1322
+ onDrop: ({ location, source }) => {
1323
+ if (!location.current.dropTargets.length) {
1324
+ return;
1325
+ }
1326
+ const target = location.current.dropTargets[0];
1327
+ const instruction = extractInstruction(target.data);
1328
+ if (instruction !== null && instruction.type !== "instruction-blocked") {
1329
+ const sourceNode = source.data.item;
1330
+ const targetNode = target.data.item;
1331
+ const sourcePath = source.data.path;
1332
+ const targetPath = target.data.path;
1333
+ const operation = sourcePath.slice(0, -1).join() === targetPath.slice(0, -1).join() && instruction.type !== "make-child" ? "rearrange" : resolveMigrationOperation(graph, sourceNode, targetPath, targetNode);
1334
+ const sourceParent = getParent(graph, sourceNode, sourcePath);
1335
+ const targetParent = getParent(graph, targetNode, targetPath);
1336
+ const sourceItems = getItems(graph, sourceParent);
1337
+ const targetItems = getItems(graph, targetParent);
1338
+ const sourceIndex = sourceItems.findIndex(({ id }) => id === sourceNode.id);
1339
+ const targetIndex = targetItems.findIndex(({ id }) => id === targetNode.id);
1340
+ const migrationIndex = instruction.type === "make-child" ? void 0 : instruction.type === "reorder-below" ? targetIndex + 1 : targetIndex;
1341
+ switch (operation) {
1342
+ case "rearrange": {
1343
+ const nextItems = sourceItems.map(({ data }) => data);
1344
+ arrayMove2(nextItems, sourceIndex, targetIndex);
1345
+ void sourceNode.properties.onRearrange?.(nextItems);
1346
+ break;
1347
+ }
1348
+ case "copy": {
1349
+ const target2 = instruction.type === "make-child" ? targetNode : targetParent;
1350
+ void target2?.properties.onCopy?.(sourceNode, migrationIndex);
1351
+ break;
1352
+ }
1353
+ case "transfer": {
1354
+ const target2 = instruction.type === "make-child" ? targetNode : targetParent;
1355
+ if (!target2?.properties.onTransferStart || !sourceParent?.properties.onTransferEnd) {
1356
+ break;
1357
+ }
1358
+ void target2?.properties.onTransferStart(sourceNode, migrationIndex);
1359
+ void sourceParent?.properties.onTransferEnd?.(sourceNode, target2);
1360
+ break;
1361
+ }
1362
+ }
1363
+ }
1364
+ }
1365
+ });
1366
+ }, [
1367
+ graph
1368
+ ]);
1369
+ const setAlternateTree = useCallback3((path, open) => {
1370
+ setItem(path, "alternateTree", open);
1371
+ }, [
1372
+ setItem
1373
+ ]);
1374
+ const onItemHover = useCallback3(({ item }) => Graph5.expand(graph, item.id, "child"), [
1375
+ graph
1376
+ ]);
1377
+ const navTreeContextValue = useMemo8(() => ({
1378
+ model,
1379
+ popoverAnchorId,
1380
+ renderItemEnd: NavTreeItemEnd,
1381
+ blockInstruction,
1382
+ canDrop,
1383
+ canSelect,
1384
+ setAlternateTree,
1385
+ onBack: handleBack,
1386
+ onOpenChange: handleOpenChange,
1387
+ onSelect: handleSelect,
1388
+ onTabChange: handleTabChange,
1389
+ onItemHover
1390
+ }), [
1391
+ model,
1392
+ popoverAnchorId,
1393
+ blockInstruction,
1394
+ canDrop,
1395
+ canSelect,
1396
+ setAlternateTree,
1397
+ handleBack,
1398
+ handleOpenChange,
1399
+ handleSelect,
1400
+ handleTabChange,
1401
+ onItemHover
1402
+ ]);
1403
+ return /* @__PURE__ */ React8.createElement(NavTreeContext.Provider, {
1404
+ value: navTreeContextValue
1405
+ }, /* @__PURE__ */ React8.createElement(NavTree, {
1406
+ id: Node6.RootId,
1407
+ root: Graph5.getRoot(graph),
1408
+ tab,
1409
+ open: layout.sidebarOpen,
1410
+ ref: forwardedRef
1411
+ }));
1412
+ });
1413
+ var NavTreeContainer = /* @__PURE__ */ memo4(NavTreeContainer$);
1414
+
1415
+ export {
1416
+ getParent,
1417
+ getPersistenceParent,
1418
+ resolveMigrationOperation,
1419
+ sortActions,
1420
+ getChildren,
1421
+ filterItems,
1422
+ l0ItemType,
1423
+ NODE_TYPE,
1424
+ NavTreeContainer
1425
+ };
1426
+ //# sourceMappingURL=chunk-DQCYMXEU.mjs.map