@dxos/plugin-navtree 0.7.5-main.9d2a38b → 0.7.5-main.ff8607b

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 (97) hide show
  1. package/dist/lib/browser/{app-graph-builder-OF4MMBLH.mjs → app-graph-builder-BL7LRXCM.mjs} +7 -5
  2. package/dist/lib/browser/{app-graph-builder-OF4MMBLH.mjs.map → app-graph-builder-BL7LRXCM.mjs.map} +3 -3
  3. package/dist/lib/browser/{chunk-OI7AAA6Q.mjs → chunk-AOAGODQB.mjs} +1 -1
  4. package/dist/lib/browser/chunk-AOAGODQB.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-EO6JEADO.mjs +1113 -0
  6. package/dist/lib/browser/chunk-EO6JEADO.mjs.map +7 -0
  7. package/dist/lib/browser/index.mjs +21 -26
  8. package/dist/lib/browser/index.mjs.map +4 -4
  9. package/dist/lib/browser/intent-resolver-U25VBFH3.mjs +47 -0
  10. package/dist/lib/browser/intent-resolver-U25VBFH3.mjs.map +7 -0
  11. package/dist/lib/browser/meta.json +1 -1
  12. package/dist/lib/browser/react-surface-6ZP5XUTS.mjs +57 -0
  13. package/dist/lib/browser/react-surface-6ZP5XUTS.mjs.map +7 -0
  14. package/dist/lib/browser/{state-HT65TAYL.mjs → state-65TQKYX7.mjs} +6 -9
  15. package/dist/lib/browser/state-65TQKYX7.mjs.map +7 -0
  16. package/dist/types/src/NavTreePlugin.d.ts.map +1 -1
  17. package/dist/types/src/capabilities/app-graph-builder.d.ts +22 -22
  18. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
  19. package/dist/types/src/capabilities/capabilities.d.ts +3 -2
  20. package/dist/types/src/capabilities/capabilities.d.ts.map +1 -1
  21. package/dist/types/src/capabilities/index.d.ts +88 -32
  22. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  23. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  24. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  25. package/dist/types/src/capabilities/state.d.ts +3 -3
  26. package/dist/types/src/capabilities/state.d.ts.map +1 -1
  27. package/dist/types/src/components/CommandsDialog.d.ts.map +1 -1
  28. package/dist/types/src/components/CommandsTrigger.d.ts.map +1 -1
  29. package/dist/types/src/components/L0Menu.d.ts +9 -0
  30. package/dist/types/src/components/L0Menu.d.ts.map +1 -0
  31. package/dist/types/src/components/L1Panels.d.ts +8 -0
  32. package/dist/types/src/components/L1Panels.d.ts.map +1 -0
  33. package/dist/types/src/components/NavTree.d.ts +3 -20
  34. package/dist/types/src/components/NavTree.d.ts.map +1 -1
  35. package/dist/types/src/components/NavTree.stories.d.ts +2 -2
  36. package/dist/types/src/components/NavTree.stories.d.ts.map +1 -1
  37. package/dist/types/src/components/NavTreeContainer.d.ts +4 -3
  38. package/dist/types/src/components/NavTreeContainer.d.ts.map +1 -1
  39. package/dist/types/src/components/NavTreeContext.d.ts +4 -0
  40. package/dist/types/src/components/NavTreeContext.d.ts.map +1 -0
  41. package/dist/types/src/components/NavTreeItemAction.d.ts +1 -1
  42. package/dist/types/src/components/NavTreeItemAction.d.ts.map +1 -1
  43. package/dist/types/src/components/NavTreeItemColumns.d.ts +4 -0
  44. package/dist/types/src/components/NavTreeItemColumns.d.ts.map +1 -0
  45. package/dist/types/src/components/index.d.ts +2 -0
  46. package/dist/types/src/components/index.d.ts.map +1 -1
  47. package/dist/types/src/components/types.d.ts +25 -0
  48. package/dist/types/src/components/types.d.ts.map +1 -0
  49. package/dist/types/src/hooks.d.ts +3 -0
  50. package/dist/types/src/hooks.d.ts.map +1 -0
  51. package/dist/types/src/stories/Graph.stories.d.ts +2 -2
  52. package/dist/types/src/stories/Graph.stories.d.ts.map +1 -1
  53. package/dist/types/src/stories/StorybookNavTree.d.ts +4 -0
  54. package/dist/types/src/stories/StorybookNavTree.d.ts.map +1 -0
  55. package/dist/types/src/translations.d.ts +0 -6
  56. package/dist/types/src/translations.d.ts.map +1 -1
  57. package/dist/types/src/types.d.ts +2 -1
  58. package/dist/types/src/types.d.ts.map +1 -1
  59. package/dist/types/src/util.d.ts +9 -0
  60. package/dist/types/src/util.d.ts.map +1 -1
  61. package/package.json +33 -31
  62. package/src/NavTreePlugin.tsx +8 -10
  63. package/src/capabilities/app-graph-builder.ts +6 -4
  64. package/src/capabilities/capabilities.ts +3 -2
  65. package/src/capabilities/intent-resolver.ts +22 -16
  66. package/src/capabilities/react-surface.tsx +15 -41
  67. package/src/capabilities/state.ts +5 -8
  68. package/src/components/CommandsDialog.tsx +3 -4
  69. package/src/components/CommandsTrigger.tsx +7 -5
  70. package/src/components/L0Menu.tsx +208 -0
  71. package/src/components/L1Panels.tsx +100 -0
  72. package/src/components/NavTree.stories.tsx +5 -5
  73. package/src/components/NavTree.tsx +26 -116
  74. package/src/components/NavTreeContainer.tsx +106 -32
  75. package/src/components/NavTreeContext.tsx +13 -0
  76. package/src/components/NavTreeItemAction.tsx +12 -4
  77. package/src/components/NavTreeItemColumns.tsx +71 -0
  78. package/src/components/NotchStart.tsx +2 -2
  79. package/src/components/index.ts +2 -0
  80. package/src/components/types.ts +33 -0
  81. package/src/hooks.ts +21 -0
  82. package/src/stories/Graph.stories.tsx +5 -4
  83. package/src/stories/StorybookNavTree.tsx +63 -0
  84. package/src/translations.ts +0 -6
  85. package/src/types.ts +2 -1
  86. package/src/util.ts +54 -0
  87. package/dist/lib/browser/chunk-IMGT2LAL.mjs +0 -658
  88. package/dist/lib/browser/chunk-IMGT2LAL.mjs.map +0 -7
  89. package/dist/lib/browser/chunk-OI7AAA6Q.mjs.map +0 -7
  90. package/dist/lib/browser/intent-resolver-74JPWYBP.mjs +0 -42
  91. package/dist/lib/browser/intent-resolver-74JPWYBP.mjs.map +0 -7
  92. package/dist/lib/browser/react-surface-6QWXI53A.mjs +0 -189
  93. package/dist/lib/browser/react-surface-6QWXI53A.mjs.map +0 -7
  94. package/dist/lib/browser/state-HT65TAYL.mjs.map +0 -7
  95. package/dist/types/src/components/NavTreeFooter.d.ts +0 -6
  96. package/dist/types/src/components/NavTreeFooter.d.ts.map +0 -1
  97. package/src/components/NavTreeFooter.tsx +0 -161
@@ -0,0 +1,1113 @@
1
+ import {
2
+ NavTreeCapabilities
3
+ } from "./chunk-AOAGODQB.mjs";
4
+ import {
5
+ COMMANDS_DIALOG,
6
+ KEY_BINDING,
7
+ NAVTREE_PLUGIN
8
+ } from "./chunk-KOXMEAOS.mjs";
9
+
10
+ // packages/plugins/plugin-navtree/src/components/CommandsDialog.tsx
11
+ import React, { useMemo, useState } from "react";
12
+ import { createIntent, LayoutAction, useAppGraph, useIntentDispatcher } from "@dxos/app-framework";
13
+ import { isActionGroup, isAction } from "@dxos/app-graph";
14
+ import { Keyboard, keySymbols } from "@dxos/keyboard";
15
+ import { Button, Dialog, Icon, useTranslation, toLocalizedString } from "@dxos/react-ui";
16
+ import { SearchList } from "@dxos/react-ui-searchlist";
17
+ import { descriptionText, mx } from "@dxos/react-ui-theme";
18
+ import { getHostPlatform } from "@dxos/util";
19
+ var CommandsDialogContent = ({ selected: initial }) => {
20
+ const { t } = useTranslation(NAVTREE_PLUGIN);
21
+ const [selected, setSelected] = useState(initial);
22
+ const { dispatchPromise: dispatch } = useIntentDispatcher();
23
+ const { graph } = useAppGraph();
24
+ const allActions = useMemo(() => {
25
+ const current = Keyboard.singleton.getCurrentContext();
26
+ const actionMap = /* @__PURE__ */ new Set();
27
+ const actions2 = [];
28
+ graph?.traverse({
29
+ visitor: (node, path) => {
30
+ if ((isAction(node) || isActionGroup(node)) && !actionMap.has(node.id) && current.startsWith(path.slice(0, -1).join("/"))) {
31
+ actionMap.add(node.id);
32
+ actions2.push(node);
33
+ }
34
+ }
35
+ });
36
+ actions2.sort((a, b) => {
37
+ return toLocalizedString(a.properties.label, t)?.toLowerCase().localeCompare(toLocalizedString(b.properties.label, t)?.toLowerCase());
38
+ });
39
+ return actions2;
40
+ }, [
41
+ graph
42
+ ]);
43
+ const group = allActions.find(({ id }) => id === selected);
44
+ const actions = isActionGroup(group) ? graph.actions(group) : allActions;
45
+ return /* @__PURE__ */ React.createElement(Dialog.Content, {
46
+ classNames: [
47
+ "md:max-is-[30rem] overflow-hidden mbs-12"
48
+ ]
49
+ }, /* @__PURE__ */ React.createElement(Dialog.Title, null, t("commands dialog title", {
50
+ ns: NAVTREE_PLUGIN
51
+ })), /* @__PURE__ */ React.createElement(SearchList.Root, {
52
+ label: t("command list input placeholder"),
53
+ classNames: "flex flex-col grow overflow-hidden my-2"
54
+ }, /* @__PURE__ */ React.createElement(SearchList.Input, {
55
+ placeholder: t("command list input placeholder"),
56
+ classNames: "px-1 my-2"
57
+ }), /* @__PURE__ */ React.createElement(SearchList.Content, {
58
+ classNames: "max-bs-[24rem] overflow-auto"
59
+ }, actions?.map((action) => {
60
+ const label = toLocalizedString(action.properties.label, t);
61
+ const shortcut = typeof action.properties.keyBinding === "string" ? action.properties.keyBinding : action.properties.keyBinding?.[getHostPlatform()];
62
+ return /* @__PURE__ */ React.createElement(SearchList.Item, {
63
+ value: label,
64
+ key: action.id,
65
+ onSelect: () => {
66
+ if (action.properties.disabled) {
67
+ return;
68
+ }
69
+ if (isActionGroup(action)) {
70
+ setSelected(action.id);
71
+ return;
72
+ }
73
+ void dispatch(createIntent(LayoutAction.UpdateDialog, {
74
+ part: "dialog",
75
+ options: {
76
+ state: false
77
+ }
78
+ }));
79
+ setTimeout(() => {
80
+ const node = graph.nodes(group ?? action, {
81
+ relation: "inbound"
82
+ })[0];
83
+ void (node && isAction(action) && action.data({
84
+ node,
85
+ caller: KEY_BINDING
86
+ }));
87
+ });
88
+ },
89
+ classNames: "flex items-center gap-2",
90
+ disabled: action.properties.disabled,
91
+ ...action.properties?.testId && {
92
+ "data-testid": action.properties.testId
93
+ }
94
+ }, /* @__PURE__ */ React.createElement(Icon, {
95
+ icon: action.properties.icon,
96
+ size: 4
97
+ }), /* @__PURE__ */ React.createElement("span", {
98
+ className: "grow truncate"
99
+ }, label), shortcut && /* @__PURE__ */ React.createElement("span", {
100
+ className: mx("shrink-0", descriptionText)
101
+ }, keySymbols(shortcut).join("")));
102
+ }))), /* @__PURE__ */ React.createElement(Dialog.Close, {
103
+ asChild: true
104
+ }, /* @__PURE__ */ React.createElement(Button, {
105
+ variant: "primary",
106
+ classNames: "mbs-2"
107
+ }, t("close label", {
108
+ ns: "os"
109
+ }))));
110
+ };
111
+
112
+ // packages/plugins/plugin-navtree/src/components/CommandsTrigger.tsx
113
+ import { MagnifyingGlass } from "@phosphor-icons/react";
114
+ import React2 from "react";
115
+ import { createIntent as createIntent2, LayoutAction as LayoutAction2, useIntentDispatcher as useIntentDispatcher2 } from "@dxos/app-framework";
116
+ import { Button as Button2, useTranslation as useTranslation2 } from "@dxos/react-ui";
117
+ import { getSize } from "@dxos/react-ui-theme";
118
+ var CommandsTrigger = () => {
119
+ const { dispatchPromise: dispatch } = useIntentDispatcher2();
120
+ const { t } = useTranslation2(NAVTREE_PLUGIN);
121
+ return /* @__PURE__ */ React2.createElement(Button2, {
122
+ classNames: "m-1 pli-1 lg:pli-2",
123
+ onClick: () => dispatch(createIntent2(LayoutAction2.UpdateDialog, {
124
+ part: "dialog",
125
+ subject: COMMANDS_DIALOG,
126
+ options: {
127
+ blockAlign: "start"
128
+ }
129
+ }))
130
+ }, /* @__PURE__ */ React2.createElement("span", {
131
+ className: "text-description font-normal grow text-start"
132
+ }, t("command list input placeholder")), /* @__PURE__ */ React2.createElement(MagnifyingGlass, {
133
+ className: getSize(5)
134
+ }));
135
+ };
136
+
137
+ // packages/plugins/plugin-navtree/src/components/NotchStart.tsx
138
+ import React4 from "react";
139
+ import { createIntent as createIntent3, useCapabilities, useIntentDispatcher as useIntentDispatcher3 } from "@dxos/app-framework";
140
+ import { ClientAction } from "@dxos/plugin-client/types";
141
+ import { ObservabilityCapabilities } from "@dxos/plugin-observability";
142
+ import { useIdentity } from "@dxos/react-client/halo";
143
+
144
+ // packages/plugins/plugin-navtree/src/components/HaloButton.tsx
145
+ import React3 from "react";
146
+ import { ConnectionState, useNetworkStatus } from "@dxos/react-client/mesh";
147
+ import { Avatar } from "@dxos/react-ui";
148
+ import { focusRing, mx as mx2 } from "@dxos/react-ui-theme";
149
+ import { hexToFallback } from "@dxos/util";
150
+ var INTERNAL = "https://avatars.githubusercontent.com/u/57182821";
151
+ var HaloButton = (props) => {
152
+ const { onClick, identityKey, internal, size = 8 } = props;
153
+ const fallbackValue = hexToFallback(identityKey ?? "0");
154
+ const { swarm: connectionState } = useNetworkStatus();
155
+ return /* @__PURE__ */ React3.createElement("button", {
156
+ className: mx2(focusRing, "rounded grid place-items-center"),
157
+ onClick
158
+ }, /* @__PURE__ */ React3.createElement(Avatar.Root, {
159
+ size,
160
+ variant: "circle",
161
+ status: connectionState === ConnectionState.OFFLINE ? "error" : internal ? "internal" : "active",
162
+ hue: props.hue || fallbackValue.hue
163
+ }, /* @__PURE__ */ React3.createElement(Avatar.Frame, {
164
+ "data-testid": "treeView.haloButton",
165
+ "data-joyride": "welcome/halo"
166
+ }, internal ? /* @__PURE__ */ React3.createElement(Avatar.Image, {
167
+ href: INTERNAL
168
+ }) : /* @__PURE__ */ React3.createElement(Avatar.Fallback, {
169
+ text: props.emoji || fallbackValue.emoji
170
+ }))));
171
+ };
172
+
173
+ // packages/plugins/plugin-navtree/src/components/NotchStart.tsx
174
+ var NotchStart = () => {
175
+ const identity = useIdentity();
176
+ const [observability] = useCapabilities(ObservabilityCapabilities.Observability);
177
+ const { dispatchPromise: dispatch } = useIntentDispatcher3();
178
+ return /* @__PURE__ */ React4.createElement(HaloButton, {
179
+ size: 12,
180
+ identityKey: identity?.identityKey.toHex(),
181
+ hue: identity?.profile?.data?.hue,
182
+ emoji: identity?.profile?.data?.emoji,
183
+ internal: observability?.group === "dxos",
184
+ onClick: () => dispatch(createIntent3(ClientAction.ShareIdentity))
185
+ });
186
+ };
187
+
188
+ // packages/plugins/plugin-navtree/src/util.ts
189
+ import { ACTION_TYPE, ACTION_GROUP_TYPE, isAction as isAction2, isActionLike } from "@dxos/app-graph";
190
+ import { nonNullable } from "@dxos/util";
191
+ var getParent = (graph, node, path) => {
192
+ const parentId = path[path.length - 2];
193
+ return graph.nodes(node, {
194
+ relation: "inbound"
195
+ }).find((n) => n.id === parentId);
196
+ };
197
+ var getPersistenceParent = (graph, node, path, persistenceClass) => {
198
+ if (node.properties.acceptPersistenceClass?.has(persistenceClass)) {
199
+ return node;
200
+ } else {
201
+ const parent = getParent(graph, node, path);
202
+ return parent ? getPersistenceParent(graph, parent, path.slice(0, path.length - 1), persistenceClass) : null;
203
+ }
204
+ };
205
+ var resolveMigrationOperation = (graph, activeNode, destinationPath, destinationRelatedNode) => {
206
+ const activeClass = activeNode.properties.persistenceClass;
207
+ if (destinationRelatedNode && activeClass) {
208
+ const persistenceParent = getPersistenceParent(graph, destinationRelatedNode, destinationPath, activeClass);
209
+ if (persistenceParent) {
210
+ const activeKey = activeNode.properties.persistenceKey;
211
+ if (activeKey && persistenceParent?.properties.acceptPersistenceKey) {
212
+ return persistenceParent.properties.acceptPersistenceKey.has(activeKey) && persistenceParent.properties.onTransferStart ? "transfer" : persistenceParent.properties.onCopy ? "copy" : "reject";
213
+ } else {
214
+ return "reject";
215
+ }
216
+ } else {
217
+ return "reject";
218
+ }
219
+ } else {
220
+ return "reject";
221
+ }
222
+ };
223
+ var sortActions = (actions) => actions.sort((a, b) => {
224
+ if (a.properties.disposition === b.properties.disposition) {
225
+ return 0;
226
+ }
227
+ if (a.properties.disposition === "toolbar") {
228
+ return -1;
229
+ }
230
+ return 1;
231
+ });
232
+ var getChildren = (graph, node, filter, path = []) => {
233
+ return graph.nodes(node, {
234
+ relation: "outbound",
235
+ filter
236
+ }).map((n) => {
237
+ const nextPath = [
238
+ ...path,
239
+ node.id
240
+ ];
241
+ return nextPath.includes(n.id) ? void 0 : n;
242
+ }).filter(nonNullable);
243
+ };
244
+ var getActions = (graph, node) => {
245
+ return graph.actions(node).reduce((acc, arg) => {
246
+ if (arg.properties.disposition === "item") {
247
+ return acc;
248
+ }
249
+ acc.actions.push(arg);
250
+ if (!isAction2(arg)) {
251
+ const actionGroup = graph.actions(arg);
252
+ acc.groupedActions[arg.id] = actionGroup;
253
+ }
254
+ return acc;
255
+ }, {
256
+ actions: [],
257
+ groupedActions: {}
258
+ });
259
+ };
260
+ var expandChildrenAndActions = (graph, node) => {
261
+ return Promise.all([
262
+ expandChildren(graph, node),
263
+ expandActions(graph, node)
264
+ ]);
265
+ };
266
+ var expandChildren = (graph, node) => {
267
+ return graph.expand(node, "outbound");
268
+ };
269
+ var expandActions = (graph, node) => {
270
+ return Promise.all([
271
+ graph.expand(node, "outbound", ACTION_TYPE),
272
+ graph.expand(node, "outbound", ACTION_GROUP_TYPE)
273
+ ]);
274
+ };
275
+ var l0ItemType = (item) => {
276
+ if (item.properties.disposition === "collection") {
277
+ return "collection";
278
+ } else if (isActionLike(item)) {
279
+ return "action";
280
+ } else if (item.properties.disposition === "navigation") {
281
+ return "link";
282
+ } else {
283
+ return "tab";
284
+ }
285
+ };
286
+ var renderableCharRegex = /^(?![\p{Control}\p{Mark}\p{Separator}\p{Surrogate}\p{Unassigned}])[\p{L}\p{N}\p{P}\p{S}\p{Emoji}]$/u;
287
+ var getFirstTwoRenderableChars = (label) => {
288
+ const characters = Array.from(label);
289
+ const result = [
290
+ "",
291
+ ""
292
+ ];
293
+ let foundFirst = false;
294
+ for (let i = 0; i < characters.length; i++) {
295
+ const char = characters[i];
296
+ if (renderableCharRegex.test(char)) {
297
+ if (!foundFirst) {
298
+ result[0] = char;
299
+ foundFirst = true;
300
+ } else {
301
+ const textBetween = characters.slice(result[0].length, i).join("");
302
+ if (/[^\p{L}\p{N}_]/u.test(textBetween)) {
303
+ result[1] = char;
304
+ break;
305
+ }
306
+ }
307
+ }
308
+ }
309
+ return result;
310
+ };
311
+
312
+ // packages/plugins/plugin-navtree/src/components/NavTreeContainer.tsx
313
+ import { monitorForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
314
+ import { extractInstruction } from "@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item";
315
+ import { untracked } from "@preact/signals-core";
316
+ import React10, { memo as memo2, useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo5 } from "react";
317
+ import { createIntent as createIntent5, LayoutAction as LayoutAction4, Surface, useAppGraph as useAppGraph2, useCapability, useIntentDispatcher as useIntentDispatcher5, useLayout as useLayout2 } from "@dxos/app-framework";
318
+ import { isAction as isAction4, isActionLike as isActionLike2 } from "@dxos/app-graph";
319
+ import { isEchoObject, isSpace } from "@dxos/react-client/echo";
320
+ import { useMediaQuery as useMediaQuery2 } from "@dxos/react-ui";
321
+ import { isTreeData } from "@dxos/react-ui-list";
322
+ import { mx as mx5 } from "@dxos/react-ui-theme";
323
+ import { arrayMove } from "@dxos/util";
324
+
325
+ // packages/plugins/plugin-navtree/src/components/NavTree.tsx
326
+ import React9, { useMemo as useMemo4 } from "react";
327
+ import { Tabs as Tabs3 } from "@dxos/react-ui-tabs";
328
+ import { byPosition } from "@dxos/util";
329
+
330
+ // packages/plugins/plugin-navtree/src/components/L0Menu.tsx
331
+ import React5, { useCallback, useMemo as useMemo2 } from "react";
332
+ import { createIntent as createIntent4, LayoutAction as LayoutAction3, useIntentDispatcher as useIntentDispatcher4 } from "@dxos/app-framework";
333
+ import { Icon as Icon2, toLocalizedString as toLocalizedString2, Tooltip, useMediaQuery, useSidebars, useTranslation as useTranslation3 } from "@dxos/react-ui";
334
+ import { Tabs } from "@dxos/react-ui-tabs";
335
+ import { mx as mx3 } from "@dxos/react-ui-theme";
336
+
337
+ // packages/plugins/plugin-navtree/src/components/NavTreeContext.tsx
338
+ import { createContext, useContext } from "react";
339
+ import { raise } from "@dxos/debug";
340
+ var NavTreeContext = /* @__PURE__ */ createContext(null);
341
+ var useNavTreeContext = () => useContext(NavTreeContext) ?? raise(new Error("NavTreeContext not found"));
342
+
343
+ // packages/plugins/plugin-navtree/src/hooks.ts
344
+ import { useEffect } from "react";
345
+ var useLoadDescendents = (root) => {
346
+ const { loadDescendents } = useNavTreeContext();
347
+ useEffect(() => {
348
+ const frame = requestAnimationFrame(() => {
349
+ if (root) {
350
+ void loadDescendents?.(root);
351
+ }
352
+ });
353
+ return () => cancelAnimationFrame(frame);
354
+ }, [
355
+ root
356
+ ]);
357
+ };
358
+
359
+ // packages/plugins/plugin-navtree/src/components/L0Menu.tsx
360
+ var useL0ItemClick = ({ item, parent, path }, type) => {
361
+ const { tab, onTabChange, onSelect, isCurrent } = useNavTreeContext();
362
+ const { dispatchPromise: dispatch } = useIntentDispatcher4();
363
+ const { navigationSidebarState } = useSidebars(NAVTREE_PLUGIN);
364
+ const [isLg] = useMediaQuery("lg", {
365
+ ssr: false
366
+ });
367
+ return useCallback((event) => {
368
+ switch (type) {
369
+ case "tab":
370
+ void dispatch(createIntent4(LayoutAction3.UpdateSidebar, {
371
+ part: "sidebar",
372
+ options: {
373
+ state: item.id === tab ? navigationSidebarState === "expanded" ? isLg ? "collapsed" : "closed" : "expanded" : "expanded"
374
+ }
375
+ }));
376
+ return onTabChange?.(item);
377
+ case "link":
378
+ return onSelect?.({
379
+ item,
380
+ path,
381
+ current: !isCurrent(path, item),
382
+ option: event.altKey
383
+ });
384
+ case "action": {
385
+ const { data: invoke, properties: { caller } } = item;
386
+ return invoke?.(caller ? {
387
+ node: parent,
388
+ caller
389
+ } : {
390
+ node: parent
391
+ });
392
+ }
393
+ }
394
+ }, [
395
+ item,
396
+ type,
397
+ onSelect,
398
+ isCurrent,
399
+ parent,
400
+ tab,
401
+ navigationSidebarState,
402
+ isLg,
403
+ dispatch
404
+ ]);
405
+ };
406
+ var l0Breakpoints = {
407
+ lg: "hidden lg:grid"
408
+ };
409
+ var L0Item = ({ item, parent, path, pinned }) => {
410
+ const { t } = useTranslation3(NAVTREE_PLUGIN);
411
+ const type = l0ItemType(item);
412
+ const itemPath = useMemo2(() => [
413
+ ...path,
414
+ item.id
415
+ ], [
416
+ item.id,
417
+ path
418
+ ]);
419
+ const { getProps } = useNavTreeContext();
420
+ const { id, testId } = getProps?.(item, path) ?? {};
421
+ const Root = type === "collection" ? "h2" : type === "tab" ? Tabs.TabPrimitive : "button";
422
+ const handleClick = useL0ItemClick({
423
+ item,
424
+ path: itemPath,
425
+ parent
426
+ }, type);
427
+ const rootProps = type === "tab" ? {
428
+ value: item.id,
429
+ tabIndex: 0,
430
+ onClick: handleClick,
431
+ "data-testid": testId,
432
+ "data-itemid": id
433
+ } : type !== "collection" ? {
434
+ onClick: handleClick,
435
+ "data-testid": testId,
436
+ "data-itemid": id
437
+ } : {
438
+ onClick: handleClick
439
+ };
440
+ const localizedString = toLocalizedString2(item.properties.label, t);
441
+ const avatarValue = useMemo2(() => type === "tab" ? getFirstTwoRenderableChars(localizedString).join("") : [], [
442
+ type,
443
+ item.properties.label,
444
+ t
445
+ ]);
446
+ return /* @__PURE__ */ React5.createElement(Tooltip.Root, {
447
+ delayDuration: 0
448
+ }, /* @__PURE__ */ React5.createElement(Tooltip.Trigger, {
449
+ asChild: true
450
+ }, /* @__PURE__ */ React5.createElement(Root, {
451
+ ...rootProps,
452
+ "data-type": type,
453
+ className: mx3('group/l0i dx-focus-ring-group grid overflow-hidden relative data[type!="collection"]:cursor-pointer app-no-drag', l0Breakpoints[item.properties.l0Breakpoint])
454
+ }, type !== "collection" && /* @__PURE__ */ React5.createElement("div", {
455
+ role: "none",
456
+ className: mx3("absolute -z-[1] group-hover/l0i:bg-input dx-focus-ring-group-indicator transition-colors", type === "tab" || pinned ? "rounded" : "rounded-full", pinned ? "bg-transparent inset-inline-3 inset-block-0" : "bg-input inset-inline-3 inset-block-2")
457
+ }), /* @__PURE__ */ React5.createElement("div", {
458
+ role: "none",
459
+ className: "hidden group-aria-selected/l0i:block absolute inline-start-0 inset-block-4 is-1 bg-accentSurface rounded-ie"
460
+ }), type === "tab" && item.properties.disposition !== "pin-end" ? /* @__PURE__ */ React5.createElement("span", {
461
+ role: "img",
462
+ className: "place-self-center text-3xl font-light"
463
+ }, avatarValue) : item.properties.icon && /* @__PURE__ */ React5.createElement(Icon2, {
464
+ icon: item.properties.icon,
465
+ size: pinned ? 5 : 7,
466
+ classNames: "place-self-center"
467
+ }), /* @__PURE__ */ React5.createElement("span", {
468
+ id: `${item.id}__label`,
469
+ className: "sr-only"
470
+ }, localizedString))), /* @__PURE__ */ React5.createElement(Tooltip.Portal, null, /* @__PURE__ */ React5.createElement(Tooltip.Content, {
471
+ side: "right"
472
+ }, localizedString, /* @__PURE__ */ React5.createElement(Tooltip.Arrow, null))));
473
+ };
474
+ var L0Collection = ({ item, path, parent }) => {
475
+ const navTreeContext = useNavTreeContext();
476
+ useLoadDescendents(item);
477
+ const collectionItems = navTreeContext.getItems(item);
478
+ const groupPath = useMemo2(() => [
479
+ ...path,
480
+ item.id
481
+ ], [
482
+ item.id,
483
+ path
484
+ ]);
485
+ const { id, testId } = navTreeContext.getProps?.(item, path) ?? {};
486
+ return /* @__PURE__ */ React5.createElement("div", {
487
+ role: "group",
488
+ className: "contents group/l0c",
489
+ "aria-labelledby": `${item.id}__label`,
490
+ "data-itemid": id,
491
+ "data-testid": testId
492
+ }, /* @__PURE__ */ React5.createElement(L0Item, {
493
+ item,
494
+ parent,
495
+ path: groupPath
496
+ }), collectionItems.map((collectionItem) => /* @__PURE__ */ React5.createElement(L0Item, {
497
+ key: collectionItem.id,
498
+ item: collectionItem,
499
+ parent: item,
500
+ path: groupPath
501
+ })));
502
+ };
503
+ var L0Menu = ({ topLevelItems, pinnedItems, parent, path }) => {
504
+ return /* @__PURE__ */ React5.createElement(Tabs.Tablist, {
505
+ classNames: "group/l0 absolute z-[1] inset-block-0 inline-start-0 rounded-is-lg grid grid-cols-[var(--l0-size)] grid-rows-[1fr_min-content_var(--l0-size)] contain-layout !is-[--l0-size] bg-baseSurface border-ie border-separator app-drag"
506
+ }, /* @__PURE__ */ React5.createElement("div", {
507
+ role: "none",
508
+ className: 'grid auto-rows-[calc(var(--l0-size)-.5rem)] min-bs-0 !overflow-y-auto plb-1 [body[data-platform="darwin"]_&]:pbs-[calc(30px+0.25rem)]'
509
+ }, topLevelItems.map((item) => {
510
+ if (l0ItemType(item) === "collection") {
511
+ return /* @__PURE__ */ React5.createElement(L0Collection, {
512
+ key: item.id,
513
+ item,
514
+ parent,
515
+ path
516
+ });
517
+ } else {
518
+ return /* @__PURE__ */ React5.createElement(L0Item, {
519
+ key: item.id,
520
+ item,
521
+ parent,
522
+ path
523
+ });
524
+ }
525
+ })), /* @__PURE__ */ React5.createElement("div", {
526
+ role: "none",
527
+ className: "grid grid-cols-1 auto-rows-[--rail-action] pbs-2"
528
+ }, pinnedItems.filter((item) => l0ItemType(item) !== "collection").map((item) => /* @__PURE__ */ React5.createElement(L0Item, {
529
+ key: item.id,
530
+ item,
531
+ parent,
532
+ path,
533
+ pinned: true
534
+ }))), /* @__PURE__ */ React5.createElement("div", {
535
+ role: "none",
536
+ className: "grid p-2 app-no-drag"
537
+ }, /* @__PURE__ */ React5.createElement(NotchStart, null)), /* @__PURE__ */ React5.createElement("div", {
538
+ role: "none",
539
+ className: 'hidden [body[data-platform="darwin"]_&]:block absolute block-start-0 is-[calc(var(--l0-size)-1px)] bs-[calc(40px+0.25rem)]',
540
+ style: {
541
+ background: "linear-gradient(to bottom, var(--dx-baseSurface) 0%, var(--dx-baseSurface) 70%, transparent 100%)"
542
+ }
543
+ }));
544
+ };
545
+
546
+ // packages/plugins/plugin-navtree/src/components/L1Panels.tsx
547
+ import React8, { useMemo as useMemo3 } from "react";
548
+ import { useLayout } from "@dxos/app-framework";
549
+ import { toLocalizedString as toLocalizedString5, useTranslation as useTranslation6 } from "@dxos/react-ui";
550
+ import { Tree } from "@dxos/react-ui-list";
551
+ import { Tabs as Tabs2 } from "@dxos/react-ui-tabs";
552
+
553
+ // packages/plugins/plugin-navtree/src/components/NavTreeItemColumns.tsx
554
+ import React7, { Fragment, memo } from "react";
555
+ import { isAction as isAction3 } from "@dxos/app-graph";
556
+ import { Popover, toLocalizedString as toLocalizedString4, Treegrid, useTranslation as useTranslation5 } from "@dxos/react-ui";
557
+
558
+ // packages/plugins/plugin-navtree/src/components/NavTreeItemAction.tsx
559
+ import React6, { useRef } from "react";
560
+ import { useTranslation as useTranslation4, toLocalizedString as toLocalizedString3, IconButton } from "@dxos/react-ui";
561
+ import { DropdownMenu, MenuProvider } from "@dxos/react-ui-menu";
562
+ import { hoverableControlItem, hoverableOpenControlItem, mx as mx4 } from "@dxos/react-ui-theme";
563
+ var fallbackIcon = "ph--placeholder--regular";
564
+ var actionButtonProps = {
565
+ size: 4,
566
+ density: "fine"
567
+ };
568
+ var NavTreeItemActionDropdownMenu = ({ label, icon, testId, menuActions, onAction }) => {
569
+ const { t } = useTranslation4(NAVTREE_PLUGIN);
570
+ const suppressNextTooltip = useRef(false);
571
+ return /* @__PURE__ */ React6.createElement(MenuProvider, {
572
+ onAction
573
+ }, /* @__PURE__ */ React6.createElement(DropdownMenu.Root, {
574
+ items: menuActions,
575
+ suppressNextTooltip
576
+ }, /* @__PURE__ */ React6.createElement(DropdownMenu.Trigger, {
577
+ asChild: true
578
+ }, /* @__PURE__ */ React6.createElement(IconButton, {
579
+ ...actionButtonProps,
580
+ classNames: mx4("shrink-0 pli-2 pointer-fine:pli-1", hoverableControlItem, hoverableOpenControlItem),
581
+ variant: "ghost",
582
+ icon: icon ?? fallbackIcon,
583
+ iconOnly: true,
584
+ label: toLocalizedString3(label, t),
585
+ "data-testid": testId,
586
+ suppressNextTooltip
587
+ }))));
588
+ };
589
+ var NavTreeItemMonolithicAction = ({ parent, properties: { disabled, caller, testId, icon, variant = "ghost", iconOnly = true } = {
590
+ label: "never"
591
+ }, data: invoke, baseLabel }) => {
592
+ return /* @__PURE__ */ React6.createElement(IconButton, {
593
+ ...actionButtonProps,
594
+ variant,
595
+ classNames: mx4("shrink-0", hoverableControlItem, hoverableOpenControlItem, iconOnly ? "pli-2 pointer-fine:pli-1" : "p-2 pointer-fine:p-2 mie-1"),
596
+ icon: icon ?? fallbackIcon,
597
+ iconOnly,
598
+ label: baseLabel,
599
+ disabled,
600
+ onClick: (event) => {
601
+ if (disabled) {
602
+ return;
603
+ }
604
+ event.stopPropagation();
605
+ void invoke?.(caller ? {
606
+ node: parent,
607
+ caller
608
+ } : {
609
+ node: parent
610
+ });
611
+ },
612
+ "data-testid": testId
613
+ });
614
+ };
615
+ var NavTreeItemAction = ({ monolithic, menuActions, parent: node, ...props }) => {
616
+ const { t } = useTranslation4(NAVTREE_PLUGIN);
617
+ const monolithicAction = menuActions?.length === 1 && menuActions[0];
618
+ const baseLabel = toLocalizedString3(monolithicAction ? monolithicAction.properties.label : props.label, t);
619
+ return monolithic && menuActions?.length === 1 ? /* @__PURE__ */ React6.createElement(NavTreeItemMonolithicAction, {
620
+ baseLabel,
621
+ parent: node,
622
+ ...menuActions[0]
623
+ }) : /* @__PURE__ */ React6.createElement(NavTreeItemActionDropdownMenu, {
624
+ ...props,
625
+ label: baseLabel,
626
+ parent: node,
627
+ menuActions,
628
+ onAction: (action) => action.data?.(props.caller ? {
629
+ node,
630
+ caller: props.caller
631
+ } : {
632
+ node
633
+ })
634
+ });
635
+ };
636
+
637
+ // packages/plugins/plugin-navtree/src/components/NavTreeItemColumns.tsx
638
+ var NavTreeItemColumns = /* @__PURE__ */ memo(({ path, item, open }) => {
639
+ const { t } = useTranslation5(NAVTREE_PLUGIN);
640
+ const { getActions: getActions2, renderItemEnd: ItemEnd, popoverAnchorId } = useNavTreeContext();
641
+ const level = path.length - 2;
642
+ const { actions: _actions, groupedActions } = getActions2(item);
643
+ const [primaryAction, ...secondaryActions] = _actions.toSorted((a, b) => a.properties?.disposition === "toolbar" ? -1 : 1);
644
+ const actions = (primaryAction?.properties?.disposition === "toolbar" ? secondaryActions : _actions).flatMap((action) => isAction3(action) ? [
645
+ action
646
+ ] : []).filter((action) => !action.properties?.hidden);
647
+ const ActionRoot = popoverAnchorId === `dxos.org/ui/${NAV_TREE_ITEM}/${item.id}` ? Popover.Anchor : Fragment;
648
+ useLoadDescendents(item);
649
+ useLoadDescendents(primaryAction && !isAction3(primaryAction) ? primaryAction : void 0);
650
+ return /* @__PURE__ */ React7.createElement("div", {
651
+ role: "none",
652
+ className: "contents app-no-drag"
653
+ }, primaryAction?.properties?.disposition === "toolbar" && !primaryAction?.properties?.disabled ? /* @__PURE__ */ React7.createElement(NavTreeItemAction, {
654
+ testId: primaryAction.properties?.testId,
655
+ label: toLocalizedString4(primaryAction.properties?.label, t),
656
+ icon: primaryAction.properties?.icon ?? "ph--placeholder--regular",
657
+ parent: item,
658
+ monolithic: isAction3(primaryAction),
659
+ menuActions: isAction3(primaryAction) ? [
660
+ primaryAction
661
+ ] : groupedActions[primaryAction.id],
662
+ menuType: primaryAction.properties?.menuType,
663
+ caller: NAV_TREE_ITEM
664
+ }) : /* @__PURE__ */ React7.createElement(Treegrid.Cell, null), /* @__PURE__ */ React7.createElement(ActionRoot, null, actions.length > 0 ? /* @__PURE__ */ React7.createElement(NavTreeItemAction, {
665
+ testId: `navtree.treeItem.actionsLevel${level}`,
666
+ label: t("tree item actions label"),
667
+ icon: "ph--dots-three-vertical--regular",
668
+ parent: item,
669
+ menuActions: actions,
670
+ menuType: "dropdown",
671
+ caller: NAV_TREE_ITEM
672
+ }) : /* @__PURE__ */ React7.createElement(Treegrid.Cell, null)), ItemEnd && /* @__PURE__ */ React7.createElement(ItemEnd, {
673
+ node: item,
674
+ open
675
+ }));
676
+ });
677
+
678
+ // packages/plugins/plugin-navtree/src/components/L1Panels.tsx
679
+ var L1Panel = ({ item, path, currentItemId }) => {
680
+ const layout = useLayout();
681
+ const navTreeContext = useNavTreeContext();
682
+ const { t } = useTranslation6(NAVTREE_PLUGIN);
683
+ return /* @__PURE__ */ React8.createElement(Tabs2.Tabpanel, {
684
+ key: item.id,
685
+ value: item.id,
686
+ classNames: [
687
+ "absolute inset-block-0 inline-end-0 is-[calc(100%-var(--l0-size))] lg:is-[--l1-size] grid-cols-1 grid-rows-[var(--rail-size)_1fr]",
688
+ item.id === currentItemId && "grid"
689
+ ],
690
+ tabIndex: -1,
691
+ ...!layout.sidebarOpen && {
692
+ inert: "true"
693
+ }
694
+ }, item.id === currentItemId && /* @__PURE__ */ React8.createElement(React8.Fragment, null, /* @__PURE__ */ React8.createElement("h2", {
695
+ className: "flex items-center border-be border-separator pis-4 app-drag"
696
+ }, /* @__PURE__ */ React8.createElement("span", {
697
+ className: "flex-1 truncate cursor-default"
698
+ }, toLocalizedString5(item.properties.label, t)), /* @__PURE__ */ React8.createElement(NavTreeItemColumns, {
699
+ path,
700
+ item,
701
+ open: true
702
+ })), /* @__PURE__ */ React8.createElement("div", {
703
+ role: "none",
704
+ className: "overflow-y-auto"
705
+ }, /* @__PURE__ */ React8.createElement(Tree, {
706
+ ...navTreeContext,
707
+ id: item.id,
708
+ root: item,
709
+ path,
710
+ levelOffset: 5,
711
+ draggable: true,
712
+ gridTemplateColumns: "[tree-row-start] 1fr min-content min-content min-content [tree-row-end]",
713
+ renderColumns: NavTreeItemColumns
714
+ }))));
715
+ };
716
+ var L1PanelCollection = ({ item, path, currentItemId }) => {
717
+ const { getItems } = useNavTreeContext();
718
+ useLoadDescendents(item);
719
+ const collectionItems = getItems(item);
720
+ const groupPath = useMemo3(() => [
721
+ ...path,
722
+ item.id
723
+ ], [
724
+ item.id,
725
+ path
726
+ ]);
727
+ return /* @__PURE__ */ React8.createElement(React8.Fragment, null, collectionItems.filter((item2) => l0ItemType(item2) === "tab").map((item2) => /* @__PURE__ */ React8.createElement(L1Panel, {
728
+ key: item2.id,
729
+ item: item2,
730
+ path: groupPath,
731
+ currentItemId
732
+ })));
733
+ };
734
+ var L1Panels = ({ topLevelItems, path, currentItemId }) => {
735
+ return /* @__PURE__ */ React8.createElement(React8.Fragment, null, topLevelItems.map((item) => {
736
+ const type = l0ItemType(item);
737
+ switch (type) {
738
+ case "collection":
739
+ return /* @__PURE__ */ React8.createElement(L1PanelCollection, {
740
+ key: item.id,
741
+ item,
742
+ path,
743
+ currentItemId
744
+ });
745
+ case "tab":
746
+ return /* @__PURE__ */ React8.createElement(L1Panel, {
747
+ key: item.id,
748
+ item,
749
+ path,
750
+ currentItemId
751
+ });
752
+ default:
753
+ return null;
754
+ }
755
+ }));
756
+ };
757
+
758
+ // packages/plugins/plugin-navtree/src/components/NavTree.tsx
759
+ var NAV_TREE_ITEM = "NavTreeItem";
760
+ var NavTree = ({ id, root }) => {
761
+ const { getItems, tab } = useNavTreeContext();
762
+ const topLevelActions = getItems(root, "item");
763
+ const topLevelCollections = getItems(root, "collection");
764
+ const topLevelWorkspaces = getItems(root, "workspace");
765
+ const topLevelNavigation = getItems(root, "navigation");
766
+ const l0Items = useMemo4(() => [
767
+ ...topLevelActions,
768
+ ...topLevelCollections,
769
+ ...topLevelWorkspaces,
770
+ ...topLevelNavigation
771
+ ], [
772
+ topLevelActions,
773
+ topLevelCollections,
774
+ topLevelWorkspaces,
775
+ topLevelNavigation
776
+ ]);
777
+ const pinnedItems = getItems(root, "pin-end").toSorted((a, b) => byPosition(a.properties, b.properties));
778
+ const topLevelItems = useMemo4(() => [
779
+ ...l0Items,
780
+ ...pinnedItems
781
+ ], [
782
+ l0Items,
783
+ pinnedItems
784
+ ]);
785
+ useLoadDescendents(root);
786
+ const path = useMemo4(() => [
787
+ id
788
+ ], [
789
+ id
790
+ ]);
791
+ return (
792
+ // NOTE(thure): 74px (rather than rem) is intentional in order to match the size of macOS windowing controls
793
+ /* @__PURE__ */ React9.createElement(Tabs3.Root, {
794
+ value: tab,
795
+ orientation: "vertical",
796
+ verticalVariant: "stateless",
797
+ classNames: "relative"
798
+ }, /* @__PURE__ */ React9.createElement(L0Menu, {
799
+ topLevelItems: l0Items,
800
+ pinnedItems,
801
+ path,
802
+ parent: root
803
+ }), /* @__PURE__ */ React9.createElement(L1Panels, {
804
+ topLevelItems,
805
+ path,
806
+ currentItemId: tab
807
+ }))
808
+ );
809
+ };
810
+
811
+ // packages/plugins/plugin-navtree/src/capabilities/index.ts
812
+ import { lazy } from "@dxos/app-framework";
813
+ var AppGraphBuilder = lazy(() => import("./app-graph-builder-BL7LRXCM.mjs"));
814
+ var IntentResolver = lazy(() => import("./intent-resolver-U25VBFH3.mjs"));
815
+ var Keyboard2 = lazy(() => import("./keyboard-MUBRTPI5.mjs"));
816
+ var ReactSurface = lazy(() => import("./react-surface-6ZP5XUTS.mjs"));
817
+ var State = lazy(() => import("./state-65TQKYX7.mjs"));
818
+
819
+ // packages/plugins/plugin-navtree/src/components/NavTreeContainer.tsx
820
+ var NODE_TYPE = "dxos/app-graph/node";
821
+ var renderItemEnd = ({ node, open }) => /* @__PURE__ */ React10.createElement(Surface, {
822
+ role: "navtree-item-end",
823
+ data: {
824
+ id: node.id,
825
+ subject: node.data,
826
+ open
827
+ },
828
+ limit: 1
829
+ });
830
+ var NavTreeContainer = /* @__PURE__ */ memo2(({ tab, popoverAnchorId, topbar }) => {
831
+ const [isLg] = useMediaQuery2("lg", {
832
+ ssr: false
833
+ });
834
+ const { dispatchPromise: dispatch } = useIntentDispatcher5();
835
+ const { graph } = useAppGraph2();
836
+ const layout = useLayout2();
837
+ const { isOpen, isCurrent, setItem } = useCapability(NavTreeCapabilities.State);
838
+ const getActions2 = useCallback2((node) => getActions(graph, node), [
839
+ graph
840
+ ]);
841
+ const getItems = useCallback2((node, disposition) => {
842
+ return graph.nodes(node ?? graph.root, {
843
+ filter: (node2) => {
844
+ return untracked(() => {
845
+ const action = isActionLike2(node2);
846
+ if (!disposition) {
847
+ return !action || node2.properties.disposition === "item";
848
+ }
849
+ return node2.properties.disposition === disposition;
850
+ });
851
+ }
852
+ });
853
+ }, [
854
+ graph
855
+ ]);
856
+ const getProps = useCallback2((node, path) => {
857
+ const children = getChildren(graph, node, void 0, path);
858
+ const parentOf = children.length > 0 ? children.map(({ id }) => id) : node.properties.role === "branch" ? [] : void 0;
859
+ return {
860
+ id: node.id,
861
+ label: node.properties.label ?? node.id,
862
+ parentOf,
863
+ icon: node.properties.icon,
864
+ disabled: node.properties.disabled,
865
+ className: mx5(node.properties.modified && "italic", node.properties.className),
866
+ headingClassName: node.properties.headingClassName,
867
+ testId: node.properties.testId
868
+ };
869
+ }, [
870
+ graph
871
+ ]);
872
+ const loadDescendents = useCallback2((node) => {
873
+ void expandActions(graph, node);
874
+ if (!isActionLike2(node)) {
875
+ void expandChildren(graph, node).then(() => (
876
+ // Load one level deeper, which resolves some juddering observed on open/close.
877
+ Promise.all(getChildren(graph, node).flatMap((child) => [
878
+ expandActions(graph, child),
879
+ expandChildren(graph, child)
880
+ ]))
881
+ ));
882
+ }
883
+ }, [
884
+ graph
885
+ ]);
886
+ const onOpenChange = useCallback2(({ item: { id }, path, open }) => {
887
+ setItem(path, "open", open);
888
+ if (graph) {
889
+ const node = graph.findNode(id);
890
+ return node && expandChildrenAndActions(graph, node);
891
+ }
892
+ }, [
893
+ graph
894
+ ]);
895
+ const onTabChange = useCallback2(async (node) => {
896
+ await dispatch(createIntent5(LayoutAction4.SwitchWorkspace, {
897
+ part: "workspace",
898
+ subject: node.id
899
+ }));
900
+ if (layout.active.length === 0) {
901
+ const [item] = getItems(node).filter((node2) => !isActionLike2(node2));
902
+ if (item) {
903
+ await dispatch(createIntent5(LayoutAction4.Open, {
904
+ part: "main",
905
+ subject: [
906
+ item.id
907
+ ]
908
+ }));
909
+ }
910
+ }
911
+ }, [
912
+ dispatch,
913
+ layout
914
+ ]);
915
+ const canDrop = useCallback2((source, target) => {
916
+ const sourceNode = source.item;
917
+ const targetNode = target.item;
918
+ if (isSpace(targetNode.data)) {
919
+ return isEchoObject(sourceNode.data) || isSpace(sourceNode.data);
920
+ } else if (isEchoObject(targetNode.data)) {
921
+ return isEchoObject(sourceNode.data);
922
+ } else {
923
+ return false;
924
+ }
925
+ }, []);
926
+ const handleSelect = useCallback2(({ item: node, path, option }) => {
927
+ if (!node.data) {
928
+ return;
929
+ }
930
+ if (isAction4(node)) {
931
+ const [parent] = graph.nodes(node, {
932
+ relation: "inbound"
933
+ });
934
+ void (parent && node.data({
935
+ node: parent,
936
+ caller: NAV_TREE_ITEM
937
+ }));
938
+ return;
939
+ }
940
+ const current = isCurrent(path, node);
941
+ if (!current) {
942
+ void dispatch(createIntent5(LayoutAction4.Open, {
943
+ part: "main",
944
+ subject: [
945
+ node.id
946
+ ],
947
+ options: {
948
+ key: node.properties.key
949
+ }
950
+ }));
951
+ } else if (option) {
952
+ void dispatch(createIntent5(LayoutAction4.Close, {
953
+ part: "main",
954
+ subject: [
955
+ node.id
956
+ ],
957
+ options: {
958
+ state: false
959
+ }
960
+ }));
961
+ } else {
962
+ void dispatch(createIntent5(LayoutAction4.ScrollIntoView, {
963
+ part: "current",
964
+ subject: node.id
965
+ }));
966
+ }
967
+ const defaultAction = graph.actions(node).find((action) => action.properties?.disposition === "default");
968
+ if (isAction4(defaultAction)) {
969
+ void defaultAction.data();
970
+ }
971
+ if (!isLg) {
972
+ void dispatch(createIntent5(LayoutAction4.UpdateSidebar, {
973
+ part: "sidebar",
974
+ options: {
975
+ state: "closed"
976
+ }
977
+ }));
978
+ }
979
+ }, [
980
+ graph,
981
+ dispatch,
982
+ isCurrent,
983
+ isLg
984
+ ]);
985
+ useEffect2(() => {
986
+ return monitorForElements({
987
+ canMonitor: ({ source }) => isTreeData(source.data),
988
+ onDrop: ({ location, source }) => {
989
+ if (!location.current.dropTargets.length) {
990
+ return;
991
+ }
992
+ const target = location.current.dropTargets[0];
993
+ const instruction = extractInstruction(target.data);
994
+ if (instruction !== null && instruction.type !== "instruction-blocked") {
995
+ const sourceNode = source.data.item;
996
+ const targetNode = target.data.item;
997
+ const sourcePath = source.data.path;
998
+ const targetPath = target.data.path;
999
+ const operation = sourcePath.slice(0, -1).join() === targetPath.slice(0, -1).join() && instruction.type !== "make-child" ? "rearrange" : resolveMigrationOperation(graph, sourceNode, targetPath, targetNode);
1000
+ const sourceParent = getParent(graph, sourceNode, sourcePath);
1001
+ const targetParent = getParent(graph, targetNode, targetPath);
1002
+ const sourceItems = getItems(sourceParent);
1003
+ const targetItems = getItems(targetParent);
1004
+ const sourceIndex = sourceItems.findIndex(({ id }) => id === sourceNode.id);
1005
+ const targetIndex = targetItems.findIndex(({ id }) => id === targetNode.id);
1006
+ const migrationIndex = instruction.type === "make-child" ? void 0 : instruction.type === "reorder-below" ? targetIndex + 1 : targetIndex;
1007
+ switch (operation) {
1008
+ case "rearrange": {
1009
+ const nextItems = sourceItems.map(({ data }) => data);
1010
+ arrayMove(nextItems, sourceIndex, targetIndex);
1011
+ void sourceParent?.properties.onRearrangeChildren?.(nextItems);
1012
+ break;
1013
+ }
1014
+ case "copy": {
1015
+ const target2 = instruction.type === "make-child" ? targetNode : targetParent;
1016
+ void target2?.properties.onCopy?.(sourceNode, migrationIndex);
1017
+ break;
1018
+ }
1019
+ case "transfer": {
1020
+ const target2 = instruction.type === "make-child" ? targetNode : targetParent;
1021
+ if (!target2?.properties.onTransferStart || !sourceParent?.properties.onTransferEnd) {
1022
+ break;
1023
+ }
1024
+ void target2?.properties.onTransferStart(sourceNode, migrationIndex);
1025
+ void sourceParent?.properties.onTransferEnd?.(sourceNode, target2);
1026
+ break;
1027
+ }
1028
+ }
1029
+ }
1030
+ }
1031
+ });
1032
+ }, [
1033
+ graph
1034
+ ]);
1035
+ const navTreeContextValue = useMemo5(() => ({
1036
+ tab,
1037
+ onTabChange,
1038
+ getActions: getActions2,
1039
+ loadDescendents,
1040
+ renderItemEnd,
1041
+ popoverAnchorId,
1042
+ topbar,
1043
+ getItems,
1044
+ getProps,
1045
+ isCurrent,
1046
+ isOpen,
1047
+ onOpenChange,
1048
+ canDrop,
1049
+ onSelect: handleSelect
1050
+ }), [
1051
+ tab,
1052
+ onTabChange,
1053
+ getActions2,
1054
+ loadDescendents,
1055
+ renderItemEnd,
1056
+ popoverAnchorId,
1057
+ topbar,
1058
+ getItems,
1059
+ getProps,
1060
+ isCurrent,
1061
+ isOpen,
1062
+ onOpenChange,
1063
+ canDrop,
1064
+ handleSelect
1065
+ ]);
1066
+ return /* @__PURE__ */ React10.createElement(NavTreeContext.Provider, {
1067
+ value: navTreeContextValue
1068
+ }, /* @__PURE__ */ React10.createElement(NavTree, {
1069
+ root: graph.root,
1070
+ id: graph.root.id
1071
+ }));
1072
+ });
1073
+
1074
+ // packages/plugins/plugin-navtree/src/components/NavTreeDocumentTitle.tsx
1075
+ import { useEffect as useEffect3 } from "react";
1076
+ import { toLocalizedString as toLocalizedString6, useTranslation as useTranslation7 } from "@dxos/react-ui";
1077
+ var NavTreeDocumentTitle = ({ node }) => {
1078
+ const { t } = useTranslation7(NAVTREE_PLUGIN);
1079
+ useEffect3(() => {
1080
+ document.title = node ? toLocalizedString6(node.properties.label, t) : t("current app name", {
1081
+ ns: "appkit"
1082
+ });
1083
+ }, [
1084
+ node?.properties?.label
1085
+ ]);
1086
+ return null;
1087
+ };
1088
+
1089
+ export {
1090
+ CommandsDialogContent,
1091
+ CommandsTrigger,
1092
+ NotchStart,
1093
+ getParent,
1094
+ getPersistenceParent,
1095
+ resolveMigrationOperation,
1096
+ sortActions,
1097
+ getChildren,
1098
+ getActions,
1099
+ expandChildrenAndActions,
1100
+ expandChildren,
1101
+ expandActions,
1102
+ l0ItemType,
1103
+ getFirstTwoRenderableChars,
1104
+ NODE_TYPE,
1105
+ NavTreeContainer,
1106
+ NavTreeDocumentTitle,
1107
+ AppGraphBuilder,
1108
+ IntentResolver,
1109
+ Keyboard2 as Keyboard,
1110
+ ReactSurface,
1111
+ State
1112
+ };
1113
+ //# sourceMappingURL=chunk-EO6JEADO.mjs.map