@dxos/plugin-navtree 0.8.4-main.ae835ea → 0.8.4-main.bc674ce

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