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

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