@dxos/plugin-navtree 0.7.5-labs.a279d8c → 0.7.5-labs.d453967

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 (98) 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-SKZPY4LJ.mjs +1120 -0
  6. package/dist/lib/browser/chunk-SKZPY4LJ.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-OZDS36WN.mjs +57 -0
  13. package/dist/lib/browser/react-surface-OZDS36WN.mjs.map +7 -0
  14. package/dist/lib/browser/{state-HT65TAYL.mjs → state-IEFQTUPG.mjs} +7 -10
  15. package/dist/lib/browser/state-IEFQTUPG.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/dist/types/tsconfig.tsbuildinfo +1 -1
  62. package/package.json +32 -31
  63. package/src/NavTreePlugin.tsx +8 -10
  64. package/src/capabilities/app-graph-builder.ts +6 -4
  65. package/src/capabilities/capabilities.ts +3 -2
  66. package/src/capabilities/intent-resolver.ts +22 -16
  67. package/src/capabilities/react-surface.tsx +15 -41
  68. package/src/capabilities/state.ts +6 -9
  69. package/src/components/CommandsDialog.tsx +3 -4
  70. package/src/components/CommandsTrigger.tsx +7 -5
  71. package/src/components/L0Menu.tsx +218 -0
  72. package/src/components/L1Panels.tsx +100 -0
  73. package/src/components/NavTree.stories.tsx +6 -6
  74. package/src/components/NavTree.tsx +26 -116
  75. package/src/components/NavTreeContainer.tsx +106 -32
  76. package/src/components/NavTreeContext.tsx +13 -0
  77. package/src/components/NavTreeItemAction.tsx +12 -4
  78. package/src/components/NavTreeItemColumns.tsx +71 -0
  79. package/src/components/NotchStart.tsx +2 -2
  80. package/src/components/index.ts +2 -0
  81. package/src/components/types.ts +33 -0
  82. package/src/hooks.ts +21 -0
  83. package/src/stories/Graph.stories.tsx +6 -5
  84. package/src/stories/StorybookNavTree.tsx +63 -0
  85. package/src/translations.ts +0 -6
  86. package/src/types.ts +2 -1
  87. package/src/util.ts +56 -2
  88. package/dist/lib/browser/chunk-IMGT2LAL.mjs +0 -658
  89. package/dist/lib/browser/chunk-IMGT2LAL.mjs.map +0 -7
  90. package/dist/lib/browser/chunk-OI7AAA6Q.mjs.map +0 -7
  91. package/dist/lib/browser/intent-resolver-74JPWYBP.mjs +0 -42
  92. package/dist/lib/browser/intent-resolver-74JPWYBP.mjs.map +0 -7
  93. package/dist/lib/browser/react-surface-6QWXI53A.mjs +0 -189
  94. package/dist/lib/browser/react-surface-6QWXI53A.mjs.map +0 -7
  95. package/dist/lib/browser/state-HT65TAYL.mjs.map +0 -7
  96. package/dist/types/src/components/NavTreeFooter.d.ts +0 -6
  97. package/dist/types/src/components/NavTreeFooter.d.ts.map +0 -1
  98. package/src/components/NavTreeFooter.tsx +0 -161
@@ -0,0 +1,1120 @@
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 { isNonNullable } 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(isNonNullable);
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 hue = item.properties.hue ?? null;
442
+ const avatarValue = useMemo2(() => type === "tab" ? getFirstTwoRenderableChars(localizedString).join("") : [], [
443
+ type,
444
+ item.properties.label,
445
+ t
446
+ ]);
447
+ return /* @__PURE__ */ React5.createElement(Tooltip.Root, {
448
+ delayDuration: 0
449
+ }, /* @__PURE__ */ React5.createElement(Tooltip.Trigger, {
450
+ asChild: true
451
+ }, /* @__PURE__ */ React5.createElement(Root, {
452
+ ...rootProps,
453
+ "data-type": type,
454
+ className: mx3('group/l0i dx-focus-ring-group grid overflow-hidden relative data[type!="collection"]:cursor-pointer app-no-drag', l0Breakpoints[item.properties.l0Breakpoint])
455
+ }, type !== "collection" && /* @__PURE__ */ React5.createElement("div", {
456
+ role: "none",
457
+ className: mx3("absolute -z-[1] dx-focus-ring-group-indicator transition-colors", type === "tab" || pinned ? "rounded" : "rounded-full", pinned ? "bg-transparent group-hover/l0i:bg-groupSurface inset-inline-3 inset-block-0.5" : "bg-groupSurface inset-inline-3 inset-block-2"),
458
+ ...hue && {
459
+ style: {
460
+ background: `var(--dx-${hue}Surface)`
461
+ }
462
+ }
463
+ }), /* @__PURE__ */ React5.createElement("div", {
464
+ role: "none",
465
+ className: "hidden group-aria-selected/l0i:block absolute inline-start-0 inset-block-4 is-1 bg-accentSurface rounded-ie"
466
+ }), type === "tab" && item.properties.disposition !== "pin-end" ? /* @__PURE__ */ React5.createElement("span", {
467
+ role: "img",
468
+ className: "place-self-center text-3xl font-light",
469
+ ...hue && {
470
+ style: {
471
+ color: `var(--dx-${hue}SurfaceText)`
472
+ }
473
+ }
474
+ }, avatarValue) : item.properties.icon && /* @__PURE__ */ React5.createElement(Icon2, {
475
+ icon: item.properties.icon,
476
+ size: pinned ? 5 : 7,
477
+ classNames: "place-self-center"
478
+ }), /* @__PURE__ */ React5.createElement("span", {
479
+ id: `${item.id}__label`,
480
+ className: "sr-only"
481
+ }, localizedString))), /* @__PURE__ */ React5.createElement(Tooltip.Portal, null, /* @__PURE__ */ React5.createElement(Tooltip.Content, {
482
+ side: "right"
483
+ }, localizedString, /* @__PURE__ */ React5.createElement(Tooltip.Arrow, null))));
484
+ };
485
+ var L0Collection = ({ item, path, parent }) => {
486
+ const navTreeContext = useNavTreeContext();
487
+ useLoadDescendents(item);
488
+ const collectionItems = navTreeContext.getItems(item);
489
+ const groupPath = useMemo2(() => [
490
+ ...path,
491
+ item.id
492
+ ], [
493
+ item.id,
494
+ path
495
+ ]);
496
+ const { id, testId } = navTreeContext.getProps?.(item, path) ?? {};
497
+ return /* @__PURE__ */ React5.createElement("div", {
498
+ role: "group",
499
+ className: "contents group/l0c",
500
+ "aria-labelledby": `${item.id}__label`,
501
+ "data-itemid": id,
502
+ "data-testid": testId
503
+ }, collectionItems.map((collectionItem) => /* @__PURE__ */ React5.createElement(L0Item, {
504
+ key: collectionItem.id,
505
+ item: collectionItem,
506
+ parent: item,
507
+ path: groupPath
508
+ })));
509
+ };
510
+ var L0Menu = ({ topLevelItems, pinnedItems, parent, path }) => {
511
+ return /* @__PURE__ */ React5.createElement(Tabs.Tablist, {
512
+ 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"
513
+ }, /* @__PURE__ */ React5.createElement("div", {
514
+ role: "none",
515
+ 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)]'
516
+ }, topLevelItems.map((item) => {
517
+ if (l0ItemType(item) === "collection") {
518
+ return /* @__PURE__ */ React5.createElement(L0Collection, {
519
+ key: item.id,
520
+ item,
521
+ parent,
522
+ path
523
+ });
524
+ } else {
525
+ return /* @__PURE__ */ React5.createElement(L0Item, {
526
+ key: item.id,
527
+ item,
528
+ parent,
529
+ path
530
+ });
531
+ }
532
+ })), /* @__PURE__ */ React5.createElement("div", {
533
+ role: "none",
534
+ className: "grid grid-cols-1 auto-rows-[--rail-action] pbs-2"
535
+ }, pinnedItems.filter((item) => l0ItemType(item) !== "collection").map((item) => /* @__PURE__ */ React5.createElement(L0Item, {
536
+ key: item.id,
537
+ item,
538
+ parent,
539
+ path,
540
+ pinned: true
541
+ }))), /* @__PURE__ */ React5.createElement("div", {
542
+ role: "none",
543
+ className: "grid p-2 app-no-drag"
544
+ }, /* @__PURE__ */ React5.createElement(NotchStart, null)), /* @__PURE__ */ React5.createElement("div", {
545
+ role: "none",
546
+ className: 'hidden [body[data-platform="darwin"]_&]:block absolute block-start-0 is-[calc(var(--l0-size)-1px)] bs-[calc(40px+0.25rem)]',
547
+ style: {
548
+ background: "linear-gradient(to bottom, var(--dx-baseSurface) 0%, var(--dx-baseSurface) 70%, transparent 100%)"
549
+ }
550
+ }));
551
+ };
552
+
553
+ // packages/plugins/plugin-navtree/src/components/L1Panels.tsx
554
+ import React8, { useMemo as useMemo3 } from "react";
555
+ import { useLayout } from "@dxos/app-framework";
556
+ import { toLocalizedString as toLocalizedString5, useTranslation as useTranslation6 } from "@dxos/react-ui";
557
+ import { Tree } from "@dxos/react-ui-list";
558
+ import { Tabs as Tabs2 } from "@dxos/react-ui-tabs";
559
+
560
+ // packages/plugins/plugin-navtree/src/components/NavTreeItemColumns.tsx
561
+ import React7, { Fragment, memo } from "react";
562
+ import { isAction as isAction3 } from "@dxos/app-graph";
563
+ import { Popover, toLocalizedString as toLocalizedString4, Treegrid, useTranslation as useTranslation5 } from "@dxos/react-ui";
564
+
565
+ // packages/plugins/plugin-navtree/src/components/NavTreeItemAction.tsx
566
+ import React6, { useRef } from "react";
567
+ import { useTranslation as useTranslation4, toLocalizedString as toLocalizedString3, IconButton } from "@dxos/react-ui";
568
+ import { DropdownMenu, MenuProvider } from "@dxos/react-ui-menu";
569
+ import { hoverableControlItem, hoverableOpenControlItem, mx as mx4 } from "@dxos/react-ui-theme";
570
+ var fallbackIcon = "ph--placeholder--regular";
571
+ var actionButtonProps = {
572
+ size: 4,
573
+ density: "fine"
574
+ };
575
+ var NavTreeItemActionDropdownMenu = ({ label, icon, testId, menuActions, onAction }) => {
576
+ const { t } = useTranslation4(NAVTREE_PLUGIN);
577
+ const suppressNextTooltip = useRef(false);
578
+ return /* @__PURE__ */ React6.createElement(MenuProvider, {
579
+ onAction
580
+ }, /* @__PURE__ */ React6.createElement(DropdownMenu.Root, {
581
+ items: menuActions,
582
+ suppressNextTooltip
583
+ }, /* @__PURE__ */ React6.createElement(DropdownMenu.Trigger, {
584
+ asChild: true
585
+ }, /* @__PURE__ */ React6.createElement(IconButton, {
586
+ ...actionButtonProps,
587
+ classNames: mx4("shrink-0 pli-2 pointer-fine:pli-1", hoverableControlItem, hoverableOpenControlItem),
588
+ variant: "ghost",
589
+ icon: icon ?? fallbackIcon,
590
+ iconOnly: true,
591
+ label: toLocalizedString3(label, t),
592
+ "data-testid": testId,
593
+ suppressNextTooltip
594
+ }))));
595
+ };
596
+ var NavTreeItemMonolithicAction = ({ parent, properties: { disabled, caller, testId, icon, variant = "ghost", iconOnly = true } = {
597
+ label: "never"
598
+ }, data: invoke, baseLabel }) => {
599
+ return /* @__PURE__ */ React6.createElement(IconButton, {
600
+ ...actionButtonProps,
601
+ variant,
602
+ classNames: mx4("shrink-0", hoverableControlItem, hoverableOpenControlItem, iconOnly ? "pli-2 pointer-fine:pli-1" : "p-2 pointer-fine:p-2 mie-1"),
603
+ icon: icon ?? fallbackIcon,
604
+ iconOnly,
605
+ label: baseLabel,
606
+ disabled,
607
+ onClick: (event) => {
608
+ if (disabled) {
609
+ return;
610
+ }
611
+ event.stopPropagation();
612
+ void invoke?.(caller ? {
613
+ node: parent,
614
+ caller
615
+ } : {
616
+ node: parent
617
+ });
618
+ },
619
+ "data-testid": testId
620
+ });
621
+ };
622
+ var NavTreeItemAction = ({ monolithic, menuActions, parent: node, ...props }) => {
623
+ const { t } = useTranslation4(NAVTREE_PLUGIN);
624
+ const monolithicAction = menuActions?.length === 1 && menuActions[0];
625
+ const baseLabel = toLocalizedString3(monolithicAction ? monolithicAction.properties.label : props.label, t);
626
+ return monolithic && menuActions?.length === 1 ? /* @__PURE__ */ React6.createElement(NavTreeItemMonolithicAction, {
627
+ baseLabel,
628
+ parent: node,
629
+ ...menuActions[0]
630
+ }) : /* @__PURE__ */ React6.createElement(NavTreeItemActionDropdownMenu, {
631
+ ...props,
632
+ label: baseLabel,
633
+ parent: node,
634
+ menuActions,
635
+ onAction: (action) => action.data?.(props.caller ? {
636
+ node,
637
+ caller: props.caller
638
+ } : {
639
+ node
640
+ })
641
+ });
642
+ };
643
+
644
+ // packages/plugins/plugin-navtree/src/components/NavTreeItemColumns.tsx
645
+ var NavTreeItemColumns = /* @__PURE__ */ memo(({ path, item, open }) => {
646
+ const { t } = useTranslation5(NAVTREE_PLUGIN);
647
+ const { getActions: getActions2, renderItemEnd: ItemEnd, popoverAnchorId } = useNavTreeContext();
648
+ const level = path.length - 2;
649
+ const { actions: _actions, groupedActions } = getActions2(item);
650
+ const [primaryAction, ...secondaryActions] = _actions.toSorted((a, b) => a.properties?.disposition === "toolbar" ? -1 : 1);
651
+ const actions = (primaryAction?.properties?.disposition === "toolbar" ? secondaryActions : _actions).flatMap((action) => isAction3(action) ? [
652
+ action
653
+ ] : []).filter((action) => !action.properties?.hidden);
654
+ const ActionRoot = popoverAnchorId === `dxos.org/ui/${NAV_TREE_ITEM}/${item.id}` ? Popover.Anchor : Fragment;
655
+ useLoadDescendents(item);
656
+ useLoadDescendents(primaryAction && !isAction3(primaryAction) ? primaryAction : void 0);
657
+ return /* @__PURE__ */ React7.createElement("div", {
658
+ role: "none",
659
+ className: "contents app-no-drag"
660
+ }, primaryAction?.properties?.disposition === "toolbar" && !primaryAction?.properties?.disabled ? /* @__PURE__ */ React7.createElement(NavTreeItemAction, {
661
+ testId: primaryAction.properties?.testId,
662
+ label: toLocalizedString4(primaryAction.properties?.label, t),
663
+ icon: primaryAction.properties?.icon ?? "ph--placeholder--regular",
664
+ parent: item,
665
+ monolithic: isAction3(primaryAction),
666
+ menuActions: isAction3(primaryAction) ? [
667
+ primaryAction
668
+ ] : groupedActions[primaryAction.id],
669
+ menuType: primaryAction.properties?.menuType,
670
+ caller: NAV_TREE_ITEM
671
+ }) : /* @__PURE__ */ React7.createElement(Treegrid.Cell, null), /* @__PURE__ */ React7.createElement(ActionRoot, null, actions.length > 0 ? /* @__PURE__ */ React7.createElement(NavTreeItemAction, {
672
+ testId: `navtree.treeItem.actionsLevel${level}`,
673
+ label: t("tree item actions label"),
674
+ icon: "ph--dots-three-vertical--regular",
675
+ parent: item,
676
+ menuActions: actions,
677
+ menuType: "dropdown",
678
+ caller: NAV_TREE_ITEM
679
+ }) : /* @__PURE__ */ React7.createElement(Treegrid.Cell, null)), ItemEnd && /* @__PURE__ */ React7.createElement(ItemEnd, {
680
+ node: item,
681
+ open
682
+ }));
683
+ });
684
+
685
+ // packages/plugins/plugin-navtree/src/components/L1Panels.tsx
686
+ var L1Panel = ({ item, path, currentItemId }) => {
687
+ const layout = useLayout();
688
+ const navTreeContext = useNavTreeContext();
689
+ const { t } = useTranslation6(NAVTREE_PLUGIN);
690
+ return /* @__PURE__ */ React8.createElement(Tabs2.Tabpanel, {
691
+ key: item.id,
692
+ value: item.id,
693
+ classNames: [
694
+ "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]",
695
+ item.id === currentItemId && "grid"
696
+ ],
697
+ tabIndex: -1,
698
+ ...!layout.sidebarOpen && {
699
+ inert: "true"
700
+ }
701
+ }, item.id === currentItemId && /* @__PURE__ */ React8.createElement(React8.Fragment, null, /* @__PURE__ */ React8.createElement("h2", {
702
+ className: "flex items-center border-be border-separator pis-4 app-drag"
703
+ }, /* @__PURE__ */ React8.createElement("span", {
704
+ className: "flex-1 truncate cursor-default"
705
+ }, toLocalizedString5(item.properties.label, t)), /* @__PURE__ */ React8.createElement(NavTreeItemColumns, {
706
+ path,
707
+ item,
708
+ open: true
709
+ })), /* @__PURE__ */ React8.createElement("div", {
710
+ role: "none",
711
+ className: "overflow-y-auto"
712
+ }, /* @__PURE__ */ React8.createElement(Tree, {
713
+ ...navTreeContext,
714
+ id: item.id,
715
+ root: item,
716
+ path,
717
+ levelOffset: 5,
718
+ draggable: true,
719
+ gridTemplateColumns: "[tree-row-start] 1fr min-content min-content min-content [tree-row-end]",
720
+ renderColumns: NavTreeItemColumns
721
+ }))));
722
+ };
723
+ var L1PanelCollection = ({ item, path, currentItemId }) => {
724
+ const { getItems } = useNavTreeContext();
725
+ useLoadDescendents(item);
726
+ const collectionItems = getItems(item);
727
+ const groupPath = useMemo3(() => [
728
+ ...path,
729
+ item.id
730
+ ], [
731
+ item.id,
732
+ path
733
+ ]);
734
+ return /* @__PURE__ */ React8.createElement(React8.Fragment, null, collectionItems.filter((item2) => l0ItemType(item2) === "tab").map((item2) => /* @__PURE__ */ React8.createElement(L1Panel, {
735
+ key: item2.id,
736
+ item: item2,
737
+ path: groupPath,
738
+ currentItemId
739
+ })));
740
+ };
741
+ var L1Panels = ({ topLevelItems, path, currentItemId }) => {
742
+ return /* @__PURE__ */ React8.createElement(React8.Fragment, null, topLevelItems.map((item) => {
743
+ const type = l0ItemType(item);
744
+ switch (type) {
745
+ case "collection":
746
+ return /* @__PURE__ */ React8.createElement(L1PanelCollection, {
747
+ key: item.id,
748
+ item,
749
+ path,
750
+ currentItemId
751
+ });
752
+ case "tab":
753
+ return /* @__PURE__ */ React8.createElement(L1Panel, {
754
+ key: item.id,
755
+ item,
756
+ path,
757
+ currentItemId
758
+ });
759
+ default:
760
+ return null;
761
+ }
762
+ }));
763
+ };
764
+
765
+ // packages/plugins/plugin-navtree/src/components/NavTree.tsx
766
+ var NAV_TREE_ITEM = "NavTreeItem";
767
+ var NavTree = ({ id, root }) => {
768
+ const { getItems, tab } = useNavTreeContext();
769
+ const topLevelActions = getItems(root, "item");
770
+ const topLevelCollections = getItems(root, "collection");
771
+ const topLevelWorkspaces = getItems(root, "workspace");
772
+ const topLevelNavigation = getItems(root, "navigation");
773
+ const l0Items = useMemo4(() => [
774
+ ...topLevelActions,
775
+ ...topLevelCollections,
776
+ ...topLevelWorkspaces,
777
+ ...topLevelNavigation
778
+ ], [
779
+ topLevelActions,
780
+ topLevelCollections,
781
+ topLevelWorkspaces,
782
+ topLevelNavigation
783
+ ]);
784
+ const pinnedItems = getItems(root, "pin-end").toSorted((a, b) => byPosition(a.properties, b.properties));
785
+ const topLevelItems = useMemo4(() => [
786
+ ...l0Items,
787
+ ...pinnedItems
788
+ ], [
789
+ l0Items,
790
+ pinnedItems
791
+ ]);
792
+ useLoadDescendents(root);
793
+ const path = useMemo4(() => [
794
+ id
795
+ ], [
796
+ id
797
+ ]);
798
+ return (
799
+ // NOTE(thure): 74px (rather than rem) is intentional in order to match the size of macOS windowing controls
800
+ /* @__PURE__ */ React9.createElement(Tabs3.Root, {
801
+ value: tab,
802
+ orientation: "vertical",
803
+ verticalVariant: "stateless",
804
+ classNames: "relative"
805
+ }, /* @__PURE__ */ React9.createElement(L0Menu, {
806
+ topLevelItems: l0Items,
807
+ pinnedItems,
808
+ path,
809
+ parent: root
810
+ }), /* @__PURE__ */ React9.createElement(L1Panels, {
811
+ topLevelItems,
812
+ path,
813
+ currentItemId: tab
814
+ }))
815
+ );
816
+ };
817
+
818
+ // packages/plugins/plugin-navtree/src/capabilities/index.ts
819
+ import { lazy } from "@dxos/app-framework";
820
+ var AppGraphBuilder = lazy(() => import("./app-graph-builder-BL7LRXCM.mjs"));
821
+ var IntentResolver = lazy(() => import("./intent-resolver-U25VBFH3.mjs"));
822
+ var Keyboard2 = lazy(() => import("./keyboard-MUBRTPI5.mjs"));
823
+ var ReactSurface = lazy(() => import("./react-surface-OZDS36WN.mjs"));
824
+ var State = lazy(() => import("./state-IEFQTUPG.mjs"));
825
+
826
+ // packages/plugins/plugin-navtree/src/components/NavTreeContainer.tsx
827
+ var NODE_TYPE = "dxos/app-graph/node";
828
+ var renderItemEnd = ({ node, open }) => /* @__PURE__ */ React10.createElement(Surface, {
829
+ role: "navtree-item-end",
830
+ data: {
831
+ id: node.id,
832
+ subject: node.data,
833
+ open
834
+ },
835
+ limit: 1
836
+ });
837
+ var NavTreeContainer = /* @__PURE__ */ memo2(({ tab, popoverAnchorId, topbar }) => {
838
+ const [isLg] = useMediaQuery2("lg", {
839
+ ssr: false
840
+ });
841
+ const { dispatchPromise: dispatch } = useIntentDispatcher5();
842
+ const { graph } = useAppGraph2();
843
+ const layout = useLayout2();
844
+ const { isOpen, isCurrent, setItem } = useCapability(NavTreeCapabilities.State);
845
+ const getActions2 = useCallback2((node) => getActions(graph, node), [
846
+ graph
847
+ ]);
848
+ const getItems = useCallback2((node, disposition) => {
849
+ return graph.nodes(node ?? graph.root, {
850
+ filter: (node2) => {
851
+ return untracked(() => {
852
+ const action = isActionLike2(node2);
853
+ if (!disposition) {
854
+ return !action || node2.properties.disposition === "item";
855
+ }
856
+ return node2.properties.disposition === disposition;
857
+ });
858
+ }
859
+ });
860
+ }, [
861
+ graph
862
+ ]);
863
+ const getProps = useCallback2((node, path) => {
864
+ const children = getChildren(graph, node, void 0, path);
865
+ const parentOf = children.length > 0 ? children.map(({ id }) => id) : node.properties.role === "branch" ? [] : void 0;
866
+ return {
867
+ id: node.id,
868
+ label: node.properties.label ?? node.id,
869
+ parentOf,
870
+ icon: node.properties.icon,
871
+ disabled: node.properties.disabled,
872
+ className: mx5(node.properties.modified && "italic", node.properties.className),
873
+ headingClassName: node.properties.headingClassName,
874
+ testId: node.properties.testId
875
+ };
876
+ }, [
877
+ graph
878
+ ]);
879
+ const loadDescendents = useCallback2((node) => {
880
+ void expandActions(graph, node);
881
+ if (!isActionLike2(node)) {
882
+ void expandChildren(graph, node).then(() => (
883
+ // Load one level deeper, which resolves some juddering observed on open/close.
884
+ Promise.all(getChildren(graph, node).flatMap((child) => [
885
+ expandActions(graph, child),
886
+ expandChildren(graph, child)
887
+ ]))
888
+ ));
889
+ }
890
+ }, [
891
+ graph
892
+ ]);
893
+ const onOpenChange = useCallback2(({ item: { id }, path, open }) => {
894
+ setItem(path, "open", open);
895
+ if (graph) {
896
+ const node = graph.findNode(id);
897
+ return node && expandChildrenAndActions(graph, node);
898
+ }
899
+ }, [
900
+ graph
901
+ ]);
902
+ const onTabChange = useCallback2(async (node) => {
903
+ await dispatch(createIntent5(LayoutAction4.SwitchWorkspace, {
904
+ part: "workspace",
905
+ subject: node.id
906
+ }));
907
+ if (layout.active.length === 0) {
908
+ const [item] = getItems(node).filter((node2) => !isActionLike2(node2));
909
+ if (item) {
910
+ await dispatch(createIntent5(LayoutAction4.Open, {
911
+ part: "main",
912
+ subject: [
913
+ item.id
914
+ ]
915
+ }));
916
+ }
917
+ }
918
+ }, [
919
+ dispatch,
920
+ layout
921
+ ]);
922
+ const canDrop = useCallback2((source, target) => {
923
+ const sourceNode = source.item;
924
+ const targetNode = target.item;
925
+ if (isSpace(targetNode.data)) {
926
+ return isEchoObject(sourceNode.data) || isSpace(sourceNode.data);
927
+ } else if (isEchoObject(targetNode.data)) {
928
+ return isEchoObject(sourceNode.data);
929
+ } else {
930
+ return false;
931
+ }
932
+ }, []);
933
+ const handleSelect = useCallback2(({ item: node, path, option }) => {
934
+ if (!node.data) {
935
+ return;
936
+ }
937
+ if (isAction4(node)) {
938
+ const [parent] = graph.nodes(node, {
939
+ relation: "inbound"
940
+ });
941
+ void (parent && node.data({
942
+ node: parent,
943
+ caller: NAV_TREE_ITEM
944
+ }));
945
+ return;
946
+ }
947
+ const current = isCurrent(path, node);
948
+ if (!current) {
949
+ void dispatch(createIntent5(LayoutAction4.Open, {
950
+ part: "main",
951
+ subject: [
952
+ node.id
953
+ ],
954
+ options: {
955
+ key: node.properties.key
956
+ }
957
+ }));
958
+ } else if (option) {
959
+ void dispatch(createIntent5(LayoutAction4.Close, {
960
+ part: "main",
961
+ subject: [
962
+ node.id
963
+ ],
964
+ options: {
965
+ state: false
966
+ }
967
+ }));
968
+ } else {
969
+ void dispatch(createIntent5(LayoutAction4.ScrollIntoView, {
970
+ part: "current",
971
+ subject: node.id
972
+ }));
973
+ }
974
+ const defaultAction = graph.actions(node).find((action) => action.properties?.disposition === "default");
975
+ if (isAction4(defaultAction)) {
976
+ void defaultAction.data();
977
+ }
978
+ if (!isLg) {
979
+ void dispatch(createIntent5(LayoutAction4.UpdateSidebar, {
980
+ part: "sidebar",
981
+ options: {
982
+ state: "closed"
983
+ }
984
+ }));
985
+ }
986
+ }, [
987
+ graph,
988
+ dispatch,
989
+ isCurrent,
990
+ isLg
991
+ ]);
992
+ useEffect2(() => {
993
+ return monitorForElements({
994
+ canMonitor: ({ source }) => isTreeData(source.data),
995
+ onDrop: ({ location, source }) => {
996
+ if (!location.current.dropTargets.length) {
997
+ return;
998
+ }
999
+ const target = location.current.dropTargets[0];
1000
+ const instruction = extractInstruction(target.data);
1001
+ if (instruction !== null && instruction.type !== "instruction-blocked") {
1002
+ const sourceNode = source.data.item;
1003
+ const targetNode = target.data.item;
1004
+ const sourcePath = source.data.path;
1005
+ const targetPath = target.data.path;
1006
+ const operation = sourcePath.slice(0, -1).join() === targetPath.slice(0, -1).join() && instruction.type !== "make-child" ? "rearrange" : resolveMigrationOperation(graph, sourceNode, targetPath, targetNode);
1007
+ const sourceParent = getParent(graph, sourceNode, sourcePath);
1008
+ const targetParent = getParent(graph, targetNode, targetPath);
1009
+ const sourceItems = getItems(sourceParent);
1010
+ const targetItems = getItems(targetParent);
1011
+ const sourceIndex = sourceItems.findIndex(({ id }) => id === sourceNode.id);
1012
+ const targetIndex = targetItems.findIndex(({ id }) => id === targetNode.id);
1013
+ const migrationIndex = instruction.type === "make-child" ? void 0 : instruction.type === "reorder-below" ? targetIndex + 1 : targetIndex;
1014
+ switch (operation) {
1015
+ case "rearrange": {
1016
+ const nextItems = sourceItems.map(({ data }) => data);
1017
+ arrayMove(nextItems, sourceIndex, targetIndex);
1018
+ void sourceParent?.properties.onRearrangeChildren?.(nextItems);
1019
+ break;
1020
+ }
1021
+ case "copy": {
1022
+ const target2 = instruction.type === "make-child" ? targetNode : targetParent;
1023
+ void target2?.properties.onCopy?.(sourceNode, migrationIndex);
1024
+ break;
1025
+ }
1026
+ case "transfer": {
1027
+ const target2 = instruction.type === "make-child" ? targetNode : targetParent;
1028
+ if (!target2?.properties.onTransferStart || !sourceParent?.properties.onTransferEnd) {
1029
+ break;
1030
+ }
1031
+ void target2?.properties.onTransferStart(sourceNode, migrationIndex);
1032
+ void sourceParent?.properties.onTransferEnd?.(sourceNode, target2);
1033
+ break;
1034
+ }
1035
+ }
1036
+ }
1037
+ }
1038
+ });
1039
+ }, [
1040
+ graph
1041
+ ]);
1042
+ const navTreeContextValue = useMemo5(() => ({
1043
+ tab,
1044
+ onTabChange,
1045
+ getActions: getActions2,
1046
+ loadDescendents,
1047
+ renderItemEnd,
1048
+ popoverAnchorId,
1049
+ topbar,
1050
+ getItems,
1051
+ getProps,
1052
+ isCurrent,
1053
+ isOpen,
1054
+ onOpenChange,
1055
+ canDrop,
1056
+ onSelect: handleSelect
1057
+ }), [
1058
+ tab,
1059
+ onTabChange,
1060
+ getActions2,
1061
+ loadDescendents,
1062
+ renderItemEnd,
1063
+ popoverAnchorId,
1064
+ topbar,
1065
+ getItems,
1066
+ getProps,
1067
+ isCurrent,
1068
+ isOpen,
1069
+ onOpenChange,
1070
+ canDrop,
1071
+ handleSelect
1072
+ ]);
1073
+ return /* @__PURE__ */ React10.createElement(NavTreeContext.Provider, {
1074
+ value: navTreeContextValue
1075
+ }, /* @__PURE__ */ React10.createElement(NavTree, {
1076
+ root: graph.root,
1077
+ id: graph.root.id
1078
+ }));
1079
+ });
1080
+
1081
+ // packages/plugins/plugin-navtree/src/components/NavTreeDocumentTitle.tsx
1082
+ import { useEffect as useEffect3 } from "react";
1083
+ import { toLocalizedString as toLocalizedString6, useTranslation as useTranslation7 } from "@dxos/react-ui";
1084
+ var NavTreeDocumentTitle = ({ node }) => {
1085
+ const { t } = useTranslation7(NAVTREE_PLUGIN);
1086
+ useEffect3(() => {
1087
+ document.title = node ? toLocalizedString6(node.properties.label, t) : t("current app name", {
1088
+ ns: "appkit"
1089
+ });
1090
+ }, [
1091
+ node?.properties?.label
1092
+ ]);
1093
+ return null;
1094
+ };
1095
+
1096
+ export {
1097
+ CommandsDialogContent,
1098
+ CommandsTrigger,
1099
+ NotchStart,
1100
+ getParent,
1101
+ getPersistenceParent,
1102
+ resolveMigrationOperation,
1103
+ sortActions,
1104
+ getChildren,
1105
+ getActions,
1106
+ expandChildrenAndActions,
1107
+ expandChildren,
1108
+ expandActions,
1109
+ l0ItemType,
1110
+ getFirstTwoRenderableChars,
1111
+ NODE_TYPE,
1112
+ NavTreeContainer,
1113
+ NavTreeDocumentTitle,
1114
+ AppGraphBuilder,
1115
+ IntentResolver,
1116
+ Keyboard2 as Keyboard,
1117
+ ReactSurface,
1118
+ State
1119
+ };
1120
+ //# sourceMappingURL=chunk-SKZPY4LJ.mjs.map