@dxos/plugin-navtree 0.7.5-main.2567c87 → 0.7.5-main.5ae2ba8

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 (110) 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-GXNOX2XZ.mjs +1262 -0
  6. package/dist/lib/browser/chunk-GXNOX2XZ.mjs.map +7 -0
  7. package/dist/lib/browser/index.mjs +22 -27
  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-SG4QBA2U.mjs +57 -0
  13. package/dist/lib/browser/react-surface-SG4QBA2U.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 +110 -110
  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 +178 -122
  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 +1 -2
  28. package/dist/types/src/components/CommandsDialog.d.ts.map +1 -1
  29. package/dist/types/src/components/CommandsTrigger.d.ts +1 -2
  30. package/dist/types/src/components/CommandsTrigger.d.ts.map +1 -1
  31. package/dist/types/src/components/HaloButton.d.ts +1 -2
  32. package/dist/types/src/components/HaloButton.d.ts.map +1 -1
  33. package/dist/types/src/components/HaloButton.stories.d.ts +1 -2
  34. package/dist/types/src/components/HaloButton.stories.d.ts.map +1 -1
  35. package/dist/types/src/components/L0Menu.d.ts +8 -0
  36. package/dist/types/src/components/L0Menu.d.ts.map +1 -0
  37. package/dist/types/src/components/L1Panels.d.ts +13 -0
  38. package/dist/types/src/components/L1Panels.d.ts.map +1 -0
  39. package/dist/types/src/components/NavTree.d.ts +2 -20
  40. package/dist/types/src/components/NavTree.d.ts.map +1 -1
  41. package/dist/types/src/components/NavTree.stories.d.ts +2 -2
  42. package/dist/types/src/components/NavTree.stories.d.ts.map +1 -1
  43. package/dist/types/src/components/NavTreeContainer.d.ts +4 -3
  44. package/dist/types/src/components/NavTreeContainer.d.ts.map +1 -1
  45. package/dist/types/src/components/NavTreeContext.d.ts +4 -0
  46. package/dist/types/src/components/NavTreeContext.d.ts.map +1 -0
  47. package/dist/types/src/components/NavTreeItemAction.d.ts +5 -5
  48. package/dist/types/src/components/NavTreeItemAction.d.ts.map +1 -1
  49. package/dist/types/src/components/NavTreeItemAction.stories.d.ts +2 -2
  50. package/dist/types/src/components/NavTreeItemColumns.d.ts +4 -0
  51. package/dist/types/src/components/NavTreeItemColumns.d.ts.map +1 -0
  52. package/dist/types/src/components/NotchStart.d.ts +1 -2
  53. package/dist/types/src/components/NotchStart.d.ts.map +1 -1
  54. package/dist/types/src/components/index.d.ts +2 -0
  55. package/dist/types/src/components/index.d.ts.map +1 -1
  56. package/dist/types/src/components/types.d.ts +26 -0
  57. package/dist/types/src/components/types.d.ts.map +1 -0
  58. package/dist/types/src/experimental/Tree.d.ts +8 -8
  59. package/dist/types/src/experimental/Tree.d.ts.map +1 -1
  60. package/dist/types/src/experimental/Tree.stories.d.ts +2 -3
  61. package/dist/types/src/experimental/Tree.stories.d.ts.map +1 -1
  62. package/dist/types/src/hooks.d.ts +3 -0
  63. package/dist/types/src/hooks.d.ts.map +1 -0
  64. package/dist/types/src/stories/Graph.stories.d.ts +2 -2
  65. package/dist/types/src/stories/Graph.stories.d.ts.map +1 -1
  66. package/dist/types/src/stories/StorybookNavTree.d.ts +3 -0
  67. package/dist/types/src/stories/StorybookNavTree.d.ts.map +1 -0
  68. package/dist/types/src/translations.d.ts +0 -6
  69. package/dist/types/src/translations.d.ts.map +1 -1
  70. package/dist/types/src/types.d.ts +2 -1
  71. package/dist/types/src/types.d.ts.map +1 -1
  72. package/dist/types/src/util.d.ts +9 -0
  73. package/dist/types/src/util.d.ts.map +1 -1
  74. package/package.json +33 -31
  75. package/src/NavTreePlugin.tsx +9 -11
  76. package/src/capabilities/app-graph-builder.ts +6 -4
  77. package/src/capabilities/capabilities.ts +3 -2
  78. package/src/capabilities/intent-resolver.ts +22 -16
  79. package/src/capabilities/react-surface.tsx +15 -41
  80. package/src/capabilities/state.ts +6 -9
  81. package/src/components/CommandsDialog.tsx +3 -4
  82. package/src/components/CommandsTrigger.tsx +7 -5
  83. package/src/components/L0Menu.tsx +332 -0
  84. package/src/components/L1Panels.tsx +119 -0
  85. package/src/components/NavTree.stories.tsx +6 -6
  86. package/src/components/NavTree.tsx +26 -116
  87. package/src/components/NavTreeContainer.tsx +114 -33
  88. package/src/components/NavTreeContext.tsx +13 -0
  89. package/src/components/NavTreeItemAction.tsx +12 -4
  90. package/src/components/NavTreeItemColumns.tsx +71 -0
  91. package/src/components/NotchStart.tsx +2 -2
  92. package/src/components/index.ts +2 -0
  93. package/src/components/types.ts +35 -0
  94. package/src/hooks.ts +21 -0
  95. package/src/stories/Graph.stories.tsx +6 -5
  96. package/src/stories/StorybookNavTree.tsx +63 -0
  97. package/src/translations.ts +0 -6
  98. package/src/types.ts +2 -1
  99. package/src/util.ts +56 -2
  100. package/dist/lib/browser/chunk-IMGT2LAL.mjs +0 -658
  101. package/dist/lib/browser/chunk-IMGT2LAL.mjs.map +0 -7
  102. package/dist/lib/browser/chunk-OI7AAA6Q.mjs.map +0 -7
  103. package/dist/lib/browser/intent-resolver-74JPWYBP.mjs +0 -42
  104. package/dist/lib/browser/intent-resolver-74JPWYBP.mjs.map +0 -7
  105. package/dist/lib/browser/react-surface-6QWXI53A.mjs +0 -189
  106. package/dist/lib/browser/react-surface-6QWXI53A.mjs.map +0 -7
  107. package/dist/lib/browser/state-HT65TAYL.mjs.map +0 -7
  108. package/dist/types/src/components/NavTreeFooter.d.ts +0 -6
  109. package/dist/types/src/components/NavTreeFooter.d.ts.map +0 -1
  110. package/src/components/NavTreeFooter.tsx +0 -161
@@ -0,0 +1,1262 @@
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 useEffect3, 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 mx6 } from "@dxos/react-ui-theme";
323
+ import { arrayMove as arrayMove2 } 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 { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
332
+ import { draggable, dropTargetForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
333
+ import { preserveOffsetOnSource } from "@atlaskit/pragmatic-drag-and-drop/element/preserve-offset-on-source";
334
+ import { scrollJustEnoughIntoView } from "@atlaskit/pragmatic-drag-and-drop/element/scroll-just-enough-into-view";
335
+ import { attachClosestEdge, extractClosestEdge } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
336
+ import React5, { useCallback, useLayoutEffect, useMemo as useMemo2, useRef, useState as useState2 } from "react";
337
+ import { createIntent as createIntent4, LayoutAction as LayoutAction3, useIntentDispatcher as useIntentDispatcher4 } from "@dxos/app-framework";
338
+ import { invariant } from "@dxos/invariant";
339
+ import { Popover, ScrollArea, toLocalizedString as toLocalizedString3, Tooltip, useMediaQuery, useSidebars, useTranslation as useTranslation4, ListItem, Icon as Icon2 } from "@dxos/react-ui";
340
+ import { Tabs } from "@dxos/react-ui-tabs";
341
+ import { mx as mx3 } from "@dxos/react-ui-theme";
342
+ import { arrayMove } from "@dxos/util";
343
+
344
+ // packages/plugins/plugin-navtree/src/components/NavTreeContext.tsx
345
+ import { createContext, useContext } from "react";
346
+ import { raise } from "@dxos/debug";
347
+ var NavTreeContext = /* @__PURE__ */ createContext(null);
348
+ var useNavTreeContext = () => useContext(NavTreeContext) ?? raise(new Error("NavTreeContext not found"));
349
+
350
+ // packages/plugins/plugin-navtree/src/hooks.ts
351
+ import { useEffect as useEffect2 } from "react";
352
+
353
+ // packages/plugins/plugin-navtree/src/components/NavTreeDocumentTitle.tsx
354
+ import { useEffect } from "react";
355
+ import { toLocalizedString as toLocalizedString2, useTranslation as useTranslation3 } from "@dxos/react-ui";
356
+ var NavTreeDocumentTitle = ({ node }) => {
357
+ const { t } = useTranslation3(NAVTREE_PLUGIN);
358
+ useEffect(() => {
359
+ document.title = node ? toLocalizedString2(node.properties.label, t) : t("current app name", {
360
+ ns: "appkit"
361
+ });
362
+ }, [
363
+ node?.properties?.label
364
+ ]);
365
+ return null;
366
+ };
367
+
368
+ // packages/plugins/plugin-navtree/src/hooks.ts
369
+ var useLoadDescendents = (root) => {
370
+ const { loadDescendents } = useNavTreeContext();
371
+ useEffect2(() => {
372
+ const frame = requestAnimationFrame(() => {
373
+ if (root) {
374
+ void loadDescendents?.(root);
375
+ }
376
+ });
377
+ return () => cancelAnimationFrame(frame);
378
+ }, [
379
+ root
380
+ ]);
381
+ };
382
+
383
+ // packages/plugins/plugin-navtree/src/components/L0Menu.tsx
384
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-navtree/src/components/L0Menu.tsx";
385
+ var useL0ItemClick = ({ item, parent, path }, type) => {
386
+ const { tab, onTabChange, onSelect, isCurrent } = useNavTreeContext();
387
+ const { dispatchPromise: dispatch } = useIntentDispatcher4();
388
+ const { navigationSidebarState } = useSidebars(NAVTREE_PLUGIN);
389
+ const [isLg] = useMediaQuery("lg", {
390
+ ssr: false
391
+ });
392
+ return useCallback((event) => {
393
+ switch (type) {
394
+ case "tab":
395
+ void dispatch(createIntent4(LayoutAction3.UpdateSidebar, {
396
+ part: "sidebar",
397
+ options: {
398
+ state: item.id === tab ? navigationSidebarState === "expanded" ? isLg ? "collapsed" : "closed" : "expanded" : "expanded"
399
+ }
400
+ }));
401
+ return onTabChange?.(item);
402
+ case "link":
403
+ return onSelect?.({
404
+ item,
405
+ path,
406
+ current: !isCurrent(path, item),
407
+ option: event.altKey
408
+ });
409
+ case "action": {
410
+ const { data: invoke, properties: { caller } } = item;
411
+ return invoke?.(caller ? {
412
+ node: parent,
413
+ caller
414
+ } : {
415
+ node: parent
416
+ });
417
+ }
418
+ }
419
+ }, [
420
+ item,
421
+ type,
422
+ onSelect,
423
+ isCurrent,
424
+ parent,
425
+ tab,
426
+ navigationSidebarState,
427
+ isLg,
428
+ dispatch
429
+ ]);
430
+ };
431
+ var l0Breakpoints = {
432
+ lg: "hidden lg:grid"
433
+ };
434
+ var L0Item = ({ item, parent, path, pinned, onRearrange }) => {
435
+ const { t } = useTranslation4(NAVTREE_PLUGIN);
436
+ const itemElement = useRef(null);
437
+ const [closestEdge, setEdge] = useState2(null);
438
+ const type = l0ItemType(item);
439
+ const itemPath = useMemo2(() => [
440
+ ...path,
441
+ item.id
442
+ ], [
443
+ item.id,
444
+ path
445
+ ]);
446
+ const { getProps, popoverAnchorId } = useNavTreeContext();
447
+ const { id, testId } = getProps?.(item, path) ?? {};
448
+ const Root = type === "collection" ? "h2" : type === "tab" ? Tabs.TabPrimitive : "button";
449
+ const handleClick = useL0ItemClick({
450
+ item,
451
+ path: itemPath,
452
+ parent
453
+ }, type);
454
+ const rootProps = type === "tab" ? {
455
+ value: item.id,
456
+ tabIndex: 0,
457
+ onClick: handleClick,
458
+ "data-testid": testId,
459
+ "data-itemid": id
460
+ } : type !== "collection" ? {
461
+ onClick: handleClick,
462
+ "data-testid": testId,
463
+ "data-itemid": id
464
+ } : {
465
+ onClick: handleClick
466
+ };
467
+ const localizedString = toLocalizedString3(item.properties.label, t);
468
+ const hue = item.properties.hue ?? null;
469
+ const avatarValue = useMemo2(() => type === "tab" ? getFirstTwoRenderableChars(localizedString).join("").toUpperCase() : [], [
470
+ type,
471
+ item.properties.label,
472
+ t
473
+ ]);
474
+ const hueFgStyle = hue && {
475
+ style: {
476
+ color: `var(--dx-${hue}SurfaceText)`
477
+ }
478
+ };
479
+ useLayoutEffect(() => {
480
+ if (!itemElement.current || !onRearrange) {
481
+ return;
482
+ }
483
+ return combine(draggable({
484
+ element: itemElement.current,
485
+ getInitialData: () => ({
486
+ id: item.id,
487
+ type: "l0Item"
488
+ }),
489
+ onGenerateDragPreview: ({ nativeSetDragImage, source, location }) => {
490
+ document.body.setAttribute("data-drag-preview", "true");
491
+ const element = source.element.querySelector("[data-frame]");
492
+ scrollJustEnoughIntoView({
493
+ element
494
+ });
495
+ const { x, y } = preserveOffsetOnSource({
496
+ element,
497
+ input: location.current.input
498
+ })({
499
+ container: element.offsetParent ?? document.body
500
+ });
501
+ nativeSetDragImage?.(element, x, y);
502
+ },
503
+ onDragStart: () => {
504
+ document.body.removeAttribute("data-drag-preview");
505
+ itemElement.current.closest("[data-drag-autoscroll]")?.setAttribute("data-drag-autoscroll", "active");
506
+ },
507
+ onDrop: () => {
508
+ itemElement.current.closest("[data-drag-autoscroll]")?.setAttribute("data-drag-autoscroll", "idle");
509
+ }
510
+ }), dropTargetForElements({
511
+ element: itemElement.current,
512
+ getData: ({ input, element }) => {
513
+ return attachClosestEdge({
514
+ id: item.id,
515
+ type: "l0Item"
516
+ }, {
517
+ input,
518
+ element,
519
+ allowedEdges: [
520
+ "top",
521
+ "bottom"
522
+ ]
523
+ });
524
+ },
525
+ onDragEnter: ({ self, source }) => {
526
+ if (source.data.type === self.data.type) {
527
+ setEdge(extractClosestEdge(self.data));
528
+ }
529
+ },
530
+ onDrag: ({ self, source }) => {
531
+ if (source.data.type === self.data.type) {
532
+ setEdge(extractClosestEdge(self.data));
533
+ }
534
+ },
535
+ onDragLeave: () => setEdge(null),
536
+ onDrop: ({ self, source }) => {
537
+ setEdge(null);
538
+ if (source.data.type === self.data.type) {
539
+ onRearrange(source.data, self.data, extractClosestEdge(self.data));
540
+ }
541
+ }
542
+ }));
543
+ }, [
544
+ item,
545
+ onRearrange
546
+ ]);
547
+ const l0ItemTrigger = /* @__PURE__ */ React5.createElement(Root, {
548
+ ...rootProps,
549
+ "data-type": type,
550
+ className: mx3('group/l0i dx-focus-ring-group grid relative data[type!="collection"]:cursor-pointer app-no-drag', l0Breakpoints[item.properties.l0Breakpoint]),
551
+ ref: itemElement
552
+ }, /* @__PURE__ */ React5.createElement("div", {
553
+ role: "none",
554
+ "data-frame": true,
555
+ className: mx3("absolute grid 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"),
556
+ ...hue && {
557
+ style: {
558
+ background: `var(--dx-${hue}Surface)`
559
+ }
560
+ }
561
+ }, item.properties.icon && /* @__PURE__ */ React5.createElement(Icon2, {
562
+ icon: item.properties.icon,
563
+ size: pinned ? 5 : 7,
564
+ classNames: "place-self-center",
565
+ ...hueFgStyle
566
+ }) || (type === "tab" && item.properties.disposition !== "pin-end" ? /* @__PURE__ */ React5.createElement("span", {
567
+ role: "img",
568
+ className: "place-self-center text-3xl font-light",
569
+ ...hueFgStyle
570
+ }, avatarValue) : item.properties.icon && /* @__PURE__ */ React5.createElement(Icon2, {
571
+ icon: "ph--planet--regular",
572
+ size: pinned ? 5 : 7,
573
+ classNames: "place-self-center",
574
+ ...hueFgStyle
575
+ }))), /* @__PURE__ */ React5.createElement("div", {
576
+ role: "none",
577
+ className: "hidden group-aria-selected/l0i:block absolute inline-start-0 inset-block-4 is-1 bg-accentSurface rounded-ie"
578
+ }), /* @__PURE__ */ React5.createElement("span", {
579
+ id: `${item.id}__label`,
580
+ className: "sr-only"
581
+ }, localizedString), onRearrange && closestEdge && /* @__PURE__ */ React5.createElement(ListItem.DropIndicator, {
582
+ edge: closestEdge
583
+ }));
584
+ return popoverAnchorId === id ? /* @__PURE__ */ React5.createElement(Popover.Anchor, {
585
+ asChild: true
586
+ }, l0ItemTrigger) : /* @__PURE__ */ React5.createElement(Tooltip.Root, {
587
+ delayDuration: 0
588
+ }, /* @__PURE__ */ React5.createElement(Tooltip.Trigger, {
589
+ asChild: true
590
+ }, l0ItemTrigger), /* @__PURE__ */ React5.createElement(Tooltip.Portal, null, /* @__PURE__ */ React5.createElement(Tooltip.Content, {
591
+ side: "right"
592
+ }, localizedString, /* @__PURE__ */ React5.createElement(Tooltip.Arrow, null))));
593
+ };
594
+ var L0Collection = ({ item, path, parent }) => {
595
+ const navTreeContext = useNavTreeContext();
596
+ useLoadDescendents(item);
597
+ const collectionItems = navTreeContext.getItems(item);
598
+ const groupPath = useMemo2(() => [
599
+ ...path,
600
+ item.id
601
+ ], [
602
+ item.id,
603
+ path
604
+ ]);
605
+ const { id, testId } = navTreeContext.getProps?.(item, path) ?? {};
606
+ const handleRearrange = useCallback((source, target, closestEdge) => {
607
+ invariant(item.properties.onRearrangeChildren, void 0, {
608
+ F: __dxlog_file,
609
+ L: 246,
610
+ S: void 0,
611
+ A: [
612
+ "item.properties.onRearrangeChildren",
613
+ ""
614
+ ]
615
+ });
616
+ const sourceIndex = collectionItems.findIndex((i) => i.id === source.id);
617
+ const targetIndex = collectionItems.findIndex((i) => i.id === target.id);
618
+ const insertIndex = source.id === target.id ? sourceIndex : targetIndex + (sourceIndex < targetIndex ? closestEdge === "top" ? -1 : 0 : closestEdge === "bottom" ? 1 : 0);
619
+ const nextOrder = arrayMove([
620
+ ...collectionItems
621
+ ], sourceIndex, insertIndex);
622
+ return item.properties.onRearrangeChildren(nextOrder);
623
+ }, [
624
+ collectionItems,
625
+ item.properties.onRearrangeChildren
626
+ ]);
627
+ return /* @__PURE__ */ React5.createElement("div", {
628
+ role: "group",
629
+ className: "contents group/l0c",
630
+ "aria-labelledby": `${item.id}__label`,
631
+ "data-itemid": id,
632
+ "data-testid": testId
633
+ }, collectionItems.map((collectionItem) => /* @__PURE__ */ React5.createElement(L0Item, {
634
+ key: collectionItem.id,
635
+ item: collectionItem,
636
+ parent: item,
637
+ path: groupPath,
638
+ ...item.properties.onRearrangeChildren && {
639
+ onRearrange: handleRearrange
640
+ }
641
+ })));
642
+ };
643
+ var L0Menu = ({ topLevelItems, pinnedItems, parent, path }) => {
644
+ return /* @__PURE__ */ React5.createElement(Tabs.Tablist, {
645
+ 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 pbe-[env(safe-area-inset-bottom)]"
646
+ }, /* @__PURE__ */ React5.createElement(ScrollArea.Root, null, /* @__PURE__ */ React5.createElement(ScrollArea.Viewport, null, /* @__PURE__ */ React5.createElement("div", {
647
+ role: "none",
648
+ className: 'grid auto-rows-[calc(var(--l0-size)-.5rem)] plb-1 [body[data-platform="darwin"]_&]:pbs-[calc(30px+0.25rem)] [body[data-platform="ios"]_&]:pbs-[max(env(safe-area-inset-top),0.25rem)]'
649
+ }, topLevelItems.map((item) => {
650
+ if (l0ItemType(item) === "collection") {
651
+ return /* @__PURE__ */ React5.createElement(L0Collection, {
652
+ key: item.id,
653
+ item,
654
+ parent,
655
+ path
656
+ });
657
+ } else {
658
+ return /* @__PURE__ */ React5.createElement(L0Item, {
659
+ key: item.id,
660
+ item,
661
+ parent,
662
+ path
663
+ });
664
+ }
665
+ })), /* @__PURE__ */ React5.createElement(ScrollArea.Scrollbar, {
666
+ orientation: "vertical"
667
+ }, /* @__PURE__ */ React5.createElement(ScrollArea.Thumb, null)))), /* @__PURE__ */ React5.createElement("div", {
668
+ role: "none",
669
+ className: "grid grid-cols-1 auto-rows-[--rail-action] pbs-2"
670
+ }, pinnedItems.filter((item) => l0ItemType(item) !== "collection").map((item) => /* @__PURE__ */ React5.createElement(L0Item, {
671
+ key: item.id,
672
+ item,
673
+ parent,
674
+ path,
675
+ pinned: true
676
+ }))), /* @__PURE__ */ React5.createElement("div", {
677
+ role: "none",
678
+ className: "grid p-2 app-no-drag"
679
+ }, /* @__PURE__ */ React5.createElement(NotchStart, null)), /* @__PURE__ */ React5.createElement("div", {
680
+ role: "none",
681
+ className: 'hidden [body[data-platform="darwin"]_&]:block absolute block-start-0 is-[calc(var(--l0-size)-1px)] bs-[calc(40px+0.25rem)]',
682
+ style: {
683
+ background: "linear-gradient(to bottom, var(--dx-baseSurface) 0%, var(--dx-baseSurface) 70%, transparent 100%)"
684
+ }
685
+ }));
686
+ };
687
+
688
+ // packages/plugins/plugin-navtree/src/components/L1Panels.tsx
689
+ import React8, { useMemo as useMemo3 } from "react";
690
+ import { useLayout } from "@dxos/app-framework";
691
+ import { IconButton as IconButton2, toLocalizedString as toLocalizedString6, useTranslation as useTranslation7 } from "@dxos/react-ui";
692
+ import { Tree } from "@dxos/react-ui-list";
693
+ import { Tabs as Tabs2 } from "@dxos/react-ui-tabs";
694
+ import { hoverableControlItem as hoverableControlItem2, hoverableOpenControlItem as hoverableOpenControlItem2, mx as mx5 } from "@dxos/react-ui-theme";
695
+
696
+ // packages/plugins/plugin-navtree/src/components/NavTreeItemColumns.tsx
697
+ import React7, { Fragment, memo } from "react";
698
+ import { isAction as isAction3 } from "@dxos/app-graph";
699
+ import { Popover as Popover2, toLocalizedString as toLocalizedString5, Treegrid, useTranslation as useTranslation6 } from "@dxos/react-ui";
700
+
701
+ // packages/plugins/plugin-navtree/src/components/NavTreeItemAction.tsx
702
+ import React6, { useRef as useRef2 } from "react";
703
+ import { useTranslation as useTranslation5, toLocalizedString as toLocalizedString4, IconButton } from "@dxos/react-ui";
704
+ import { DropdownMenu, MenuProvider } from "@dxos/react-ui-menu";
705
+ import { hoverableControlItem, hoverableOpenControlItem, mx as mx4 } from "@dxos/react-ui-theme";
706
+ var fallbackIcon = "ph--placeholder--regular";
707
+ var actionButtonProps = {
708
+ size: 4,
709
+ density: "fine"
710
+ };
711
+ var NavTreeItemActionDropdownMenu = ({ label, icon, testId, menuActions, onAction }) => {
712
+ const { t } = useTranslation5(NAVTREE_PLUGIN);
713
+ const suppressNextTooltip = useRef2(false);
714
+ return /* @__PURE__ */ React6.createElement(MenuProvider, {
715
+ onAction
716
+ }, /* @__PURE__ */ React6.createElement(DropdownMenu.Root, {
717
+ items: menuActions,
718
+ suppressNextTooltip
719
+ }, /* @__PURE__ */ React6.createElement(DropdownMenu.Trigger, {
720
+ asChild: true
721
+ }, /* @__PURE__ */ React6.createElement(IconButton, {
722
+ ...actionButtonProps,
723
+ classNames: mx4("shrink-0 pli-2 pointer-fine:pli-1", hoverableControlItem, hoverableOpenControlItem),
724
+ variant: "ghost",
725
+ icon: icon ?? fallbackIcon,
726
+ iconOnly: true,
727
+ label: toLocalizedString4(label, t),
728
+ "data-testid": testId,
729
+ suppressNextTooltip
730
+ }))));
731
+ };
732
+ var NavTreeItemMonolithicAction = ({ parent, properties: { disabled, caller, testId, icon, variant = "ghost", iconOnly = true } = {
733
+ label: "never"
734
+ }, data: invoke, baseLabel }) => {
735
+ return /* @__PURE__ */ React6.createElement(IconButton, {
736
+ ...actionButtonProps,
737
+ variant,
738
+ classNames: mx4("shrink-0", hoverableControlItem, hoverableOpenControlItem, iconOnly ? "pli-2 pointer-fine:pli-1" : "p-2 pointer-fine:p-2 mie-1"),
739
+ icon: icon ?? fallbackIcon,
740
+ iconOnly,
741
+ label: baseLabel,
742
+ disabled,
743
+ onClick: (event) => {
744
+ if (disabled) {
745
+ return;
746
+ }
747
+ event.stopPropagation();
748
+ void invoke?.(caller ? {
749
+ node: parent,
750
+ caller
751
+ } : {
752
+ node: parent
753
+ });
754
+ },
755
+ "data-testid": testId
756
+ });
757
+ };
758
+ var NavTreeItemAction = ({ monolithic, menuActions, parent: node, ...props }) => {
759
+ const { t } = useTranslation5(NAVTREE_PLUGIN);
760
+ const monolithicAction = menuActions?.length === 1 && menuActions[0];
761
+ const baseLabel = toLocalizedString4(monolithicAction ? monolithicAction.properties.label : props.label, t);
762
+ return monolithic && menuActions?.length === 1 ? /* @__PURE__ */ React6.createElement(NavTreeItemMonolithicAction, {
763
+ baseLabel,
764
+ parent: node,
765
+ ...menuActions[0]
766
+ }) : /* @__PURE__ */ React6.createElement(NavTreeItemActionDropdownMenu, {
767
+ ...props,
768
+ label: baseLabel,
769
+ parent: node,
770
+ menuActions,
771
+ onAction: (action) => action.data?.(props.caller ? {
772
+ node,
773
+ caller: props.caller
774
+ } : {
775
+ node
776
+ })
777
+ });
778
+ };
779
+
780
+ // packages/plugins/plugin-navtree/src/components/NavTreeItemColumns.tsx
781
+ var NavTreeItemColumns = /* @__PURE__ */ memo(({ path, item, open }) => {
782
+ const { t } = useTranslation6(NAVTREE_PLUGIN);
783
+ const { getActions: getActions2, renderItemEnd: ItemEnd, popoverAnchorId } = useNavTreeContext();
784
+ const level = path.length - 2;
785
+ const { actions: _actions, groupedActions } = getActions2(item);
786
+ const [primaryAction, ...secondaryActions] = _actions.toSorted((a, b) => a.properties?.disposition === "toolbar" ? -1 : 1);
787
+ const actions = (primaryAction?.properties?.disposition === "toolbar" ? secondaryActions : _actions).flatMap((action) => isAction3(action) ? [
788
+ action
789
+ ] : []).filter((action) => !action.properties?.hidden);
790
+ const ActionRoot = popoverAnchorId === `dxos.org/ui/${NAV_TREE_ITEM}/${item.id}` ? Popover2.Anchor : Fragment;
791
+ useLoadDescendents(item);
792
+ useLoadDescendents(primaryAction && !isAction3(primaryAction) ? primaryAction : void 0);
793
+ return /* @__PURE__ */ React7.createElement("div", {
794
+ role: "none",
795
+ className: "contents app-no-drag"
796
+ }, primaryAction?.properties?.disposition === "toolbar" && !primaryAction?.properties?.disabled ? /* @__PURE__ */ React7.createElement(NavTreeItemAction, {
797
+ testId: primaryAction.properties?.testId,
798
+ label: toLocalizedString5(primaryAction.properties?.label, t),
799
+ icon: primaryAction.properties?.icon ?? "ph--placeholder--regular",
800
+ parent: item,
801
+ monolithic: isAction3(primaryAction),
802
+ menuActions: isAction3(primaryAction) ? [
803
+ primaryAction
804
+ ] : groupedActions[primaryAction.id],
805
+ menuType: primaryAction.properties?.menuType,
806
+ caller: NAV_TREE_ITEM
807
+ }) : /* @__PURE__ */ React7.createElement(Treegrid.Cell, null), /* @__PURE__ */ React7.createElement(ActionRoot, null, actions.length > 0 ? /* @__PURE__ */ React7.createElement(NavTreeItemAction, {
808
+ testId: `navtree.treeItem.actionsLevel${level}`,
809
+ label: t("tree item actions label"),
810
+ icon: "ph--dots-three-vertical--regular",
811
+ parent: item,
812
+ menuActions: actions,
813
+ menuType: "dropdown",
814
+ caller: NAV_TREE_ITEM
815
+ }) : /* @__PURE__ */ React7.createElement(Treegrid.Cell, null)), ItemEnd && /* @__PURE__ */ React7.createElement(ItemEnd, {
816
+ node: item,
817
+ open
818
+ }));
819
+ });
820
+
821
+ // packages/plugins/plugin-navtree/src/components/L1Panels.tsx
822
+ var L1Panel = ({ item, path, currentItemId, onBack }) => {
823
+ const layout = useLayout();
824
+ const navTreeContext = useNavTreeContext();
825
+ const { t } = useTranslation7(NAVTREE_PLUGIN);
826
+ return /* @__PURE__ */ React8.createElement(Tabs2.Tabpanel, {
827
+ key: item.id,
828
+ value: item.id,
829
+ classNames: [
830
+ "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] pbs-[env(safe-area-inset-top)]",
831
+ item.id === currentItemId && "grid"
832
+ ],
833
+ tabIndex: -1,
834
+ ...!layout.sidebarOpen && {
835
+ inert: "true"
836
+ }
837
+ }, item.id === currentItemId && /* @__PURE__ */ React8.createElement(React8.Fragment, null, /* @__PURE__ */ React8.createElement("h2", {
838
+ className: "flex items-center border-be border-separator pis-4 app-drag"
839
+ }, item.properties.disposition === "pin-end" && /* @__PURE__ */ React8.createElement(IconButton2, {
840
+ label: t("back label"),
841
+ iconOnly: true,
842
+ icon: "ph--caret-left--regular",
843
+ size: 5,
844
+ density: "fine",
845
+ variant: "ghost",
846
+ classNames: mx5("shrink-0 mie-2 !p-0", "pointer-fine:pli-1", hoverableControlItem2, hoverableOpenControlItem2),
847
+ onClick: onBack
848
+ }), /* @__PURE__ */ React8.createElement("span", {
849
+ className: "flex-1 truncate cursor-default"
850
+ }, toLocalizedString6(item.properties.label, t)), /* @__PURE__ */ React8.createElement(NavTreeItemColumns, {
851
+ path,
852
+ item,
853
+ open: true
854
+ })), /* @__PURE__ */ React8.createElement("div", {
855
+ role: "none",
856
+ className: "overflow-y-auto"
857
+ }, /* @__PURE__ */ React8.createElement(Tree, {
858
+ ...navTreeContext,
859
+ id: item.id,
860
+ root: item,
861
+ path,
862
+ levelOffset: 5,
863
+ draggable: true,
864
+ gridTemplateColumns: "[tree-row-start] 1fr min-content min-content min-content [tree-row-end]",
865
+ renderColumns: NavTreeItemColumns
866
+ }))));
867
+ };
868
+ var L1PanelCollection = ({ item, path, currentItemId }) => {
869
+ const { getItems } = useNavTreeContext();
870
+ useLoadDescendents(item);
871
+ const collectionItems = getItems(item);
872
+ const groupPath = useMemo3(() => [
873
+ ...path,
874
+ item.id
875
+ ], [
876
+ item.id,
877
+ path
878
+ ]);
879
+ return /* @__PURE__ */ React8.createElement(React8.Fragment, null, collectionItems.filter((item2) => l0ItemType(item2) === "tab").map((item2) => /* @__PURE__ */ React8.createElement(L1Panel, {
880
+ key: item2.id,
881
+ item: item2,
882
+ path: groupPath,
883
+ currentItemId
884
+ })));
885
+ };
886
+ var L1Panels = ({ topLevelItems, path, currentItemId, onBack }) => {
887
+ return /* @__PURE__ */ React8.createElement(React8.Fragment, null, topLevelItems.map((item) => {
888
+ const type = l0ItemType(item);
889
+ switch (type) {
890
+ case "collection":
891
+ return /* @__PURE__ */ React8.createElement(L1PanelCollection, {
892
+ key: item.id,
893
+ item,
894
+ path,
895
+ currentItemId
896
+ });
897
+ case "tab":
898
+ return /* @__PURE__ */ React8.createElement(L1Panel, {
899
+ key: item.id,
900
+ item,
901
+ path,
902
+ currentItemId,
903
+ onBack
904
+ });
905
+ default:
906
+ return null;
907
+ }
908
+ }));
909
+ };
910
+
911
+ // packages/plugins/plugin-navtree/src/components/NavTree.tsx
912
+ var NAV_TREE_ITEM = "NavTreeItem";
913
+ var NavTree = ({ id, root }) => {
914
+ const { tab, getItems, onBack } = useNavTreeContext();
915
+ const topLevelActions = getItems(root, "item").toSorted((a, b) => byPosition(a.properties, b.properties));
916
+ const topLevelCollections = getItems(root, "collection");
917
+ const topLevelWorkspaces = getItems(root, "workspace");
918
+ const topLevelNavigation = getItems(root, "navigation");
919
+ const l0Items = useMemo4(() => [
920
+ ...topLevelActions,
921
+ ...topLevelCollections,
922
+ ...topLevelWorkspaces,
923
+ ...topLevelNavigation
924
+ ], [
925
+ topLevelActions,
926
+ topLevelCollections,
927
+ topLevelWorkspaces,
928
+ topLevelNavigation
929
+ ]);
930
+ const pinnedItems = getItems(root, "pin-end").toSorted((a, b) => byPosition(a.properties, b.properties));
931
+ const topLevelItems = useMemo4(() => [
932
+ ...l0Items,
933
+ ...pinnedItems
934
+ ], [
935
+ l0Items,
936
+ pinnedItems
937
+ ]);
938
+ useLoadDescendents(root);
939
+ const path = useMemo4(() => [
940
+ id
941
+ ], [
942
+ id
943
+ ]);
944
+ return (
945
+ // NOTE(thure): 74px (rather than rem) is intentional in order to match the size of macOS windowing controls
946
+ /* @__PURE__ */ React9.createElement(Tabs3.Root, {
947
+ value: tab,
948
+ orientation: "vertical",
949
+ verticalVariant: "stateless",
950
+ classNames: "relative"
951
+ }, /* @__PURE__ */ React9.createElement(L0Menu, {
952
+ topLevelItems: l0Items,
953
+ pinnedItems,
954
+ path,
955
+ parent: root
956
+ }), /* @__PURE__ */ React9.createElement(L1Panels, {
957
+ topLevelItems,
958
+ path,
959
+ currentItemId: tab,
960
+ onBack
961
+ }))
962
+ );
963
+ };
964
+
965
+ // packages/plugins/plugin-navtree/src/capabilities/index.ts
966
+ import { lazy } from "@dxos/app-framework";
967
+ var AppGraphBuilder = lazy(() => import("./app-graph-builder-BL7LRXCM.mjs"));
968
+ var IntentResolver = lazy(() => import("./intent-resolver-U25VBFH3.mjs"));
969
+ var Keyboard2 = lazy(() => import("./keyboard-MUBRTPI5.mjs"));
970
+ var ReactSurface = lazy(() => import("./react-surface-SG4QBA2U.mjs"));
971
+ var State = lazy(() => import("./state-IEFQTUPG.mjs"));
972
+
973
+ // packages/plugins/plugin-navtree/src/components/NavTreeContainer.tsx
974
+ var NODE_TYPE = "dxos/app-graph/node";
975
+ var renderItemEnd = ({ node, open }) => /* @__PURE__ */ React10.createElement(Surface, {
976
+ role: "navtree-item-end",
977
+ data: {
978
+ id: node.id,
979
+ subject: node.data,
980
+ open
981
+ },
982
+ limit: 1
983
+ });
984
+ var NavTreeContainer = /* @__PURE__ */ memo2(({ tab, popoverAnchorId, topbar }) => {
985
+ const [isLg] = useMediaQuery2("lg", {
986
+ ssr: false
987
+ });
988
+ const { dispatchPromise: dispatch } = useIntentDispatcher5();
989
+ const { graph } = useAppGraph2();
990
+ const layout = useLayout2();
991
+ const { isOpen, isCurrent, setItem } = useCapability(NavTreeCapabilities.State);
992
+ const getActions2 = useCallback2((node) => getActions(graph, node), [
993
+ graph
994
+ ]);
995
+ const getItems = useCallback2((node, disposition) => {
996
+ return graph.nodes(node ?? graph.root, {
997
+ filter: (node2) => {
998
+ return untracked(() => {
999
+ const action = isAction4(node2);
1000
+ if (!disposition) {
1001
+ return !action || node2.properties.disposition === "item";
1002
+ }
1003
+ return node2.properties.disposition === disposition;
1004
+ });
1005
+ }
1006
+ });
1007
+ }, [
1008
+ graph
1009
+ ]);
1010
+ const getProps = useCallback2((node, path) => {
1011
+ const children = getChildren(graph, node, void 0, path);
1012
+ const parentOf = children.length > 0 ? children.map(({ id }) => id) : node.properties.role === "branch" ? [] : void 0;
1013
+ return {
1014
+ id: node.id,
1015
+ label: node.properties.label ?? node.id,
1016
+ parentOf,
1017
+ icon: node.properties.icon,
1018
+ disabled: node.properties.disabled,
1019
+ className: mx6(node.properties.modified && "italic", node.properties.className),
1020
+ headingClassName: node.properties.headingClassName,
1021
+ testId: node.properties.testId
1022
+ };
1023
+ }, [
1024
+ graph
1025
+ ]);
1026
+ const loadDescendents = useCallback2((node) => {
1027
+ void expandActions(graph, node);
1028
+ if (!isActionLike2(node)) {
1029
+ void expandChildren(graph, node).then(() => (
1030
+ // Load one level deeper, which resolves some juddering observed on open/close.
1031
+ Promise.all(getChildren(graph, node).flatMap((child) => [
1032
+ expandActions(graph, child),
1033
+ expandChildren(graph, child)
1034
+ ]))
1035
+ ));
1036
+ }
1037
+ }, [
1038
+ graph
1039
+ ]);
1040
+ const onOpenChange = useCallback2(({ item: { id }, path, open }) => {
1041
+ setItem(path, "open", open);
1042
+ if (graph) {
1043
+ const node = graph.findNode(id);
1044
+ return node && expandChildrenAndActions(graph, node);
1045
+ }
1046
+ }, [
1047
+ graph
1048
+ ]);
1049
+ const onTabChange = useCallback2(async (node) => {
1050
+ await dispatch(createIntent5(LayoutAction4.SwitchWorkspace, {
1051
+ part: "workspace",
1052
+ subject: node.id
1053
+ }));
1054
+ if (layout.active.length === 0) {
1055
+ const [item] = getItems(node).filter((node2) => !isActionLike2(node2));
1056
+ if (item && item.data) {
1057
+ await dispatch(createIntent5(LayoutAction4.Open, {
1058
+ part: "main",
1059
+ subject: [
1060
+ item.id
1061
+ ]
1062
+ }));
1063
+ }
1064
+ }
1065
+ }, [
1066
+ dispatch,
1067
+ layout
1068
+ ]);
1069
+ const canDrop = useCallback2((source, target) => {
1070
+ const sourceNode = source.item;
1071
+ const targetNode = target.item;
1072
+ if (isSpace(targetNode.data)) {
1073
+ return isEchoObject(sourceNode.data) || isSpace(sourceNode.data);
1074
+ } else if (isEchoObject(targetNode.data)) {
1075
+ return isEchoObject(sourceNode.data);
1076
+ } else {
1077
+ return false;
1078
+ }
1079
+ }, []);
1080
+ const handleSelect = useCallback2(({ item: node, path, option }) => {
1081
+ if (!node.data) {
1082
+ return;
1083
+ }
1084
+ if (isAction4(node)) {
1085
+ const [parent] = graph.nodes(node, {
1086
+ relation: "inbound"
1087
+ });
1088
+ void (parent && node.data({
1089
+ node: parent,
1090
+ caller: NAV_TREE_ITEM
1091
+ }));
1092
+ return;
1093
+ }
1094
+ const current = isCurrent(path, node);
1095
+ if (!current) {
1096
+ void dispatch(createIntent5(LayoutAction4.Open, {
1097
+ part: "main",
1098
+ subject: [
1099
+ node.id
1100
+ ],
1101
+ options: {
1102
+ key: node.properties.key
1103
+ }
1104
+ }));
1105
+ } else if (option) {
1106
+ void dispatch(createIntent5(LayoutAction4.Close, {
1107
+ part: "main",
1108
+ subject: [
1109
+ node.id
1110
+ ],
1111
+ options: {
1112
+ state: false
1113
+ }
1114
+ }));
1115
+ } else {
1116
+ void dispatch(createIntent5(LayoutAction4.ScrollIntoView, {
1117
+ part: "current",
1118
+ subject: node.id
1119
+ }));
1120
+ }
1121
+ const defaultAction = graph.actions(node).find((action) => action.properties?.disposition === "default");
1122
+ if (isAction4(defaultAction)) {
1123
+ void defaultAction.data();
1124
+ }
1125
+ if (!isLg) {
1126
+ void dispatch(createIntent5(LayoutAction4.UpdateSidebar, {
1127
+ part: "sidebar",
1128
+ options: {
1129
+ state: "closed"
1130
+ }
1131
+ }));
1132
+ }
1133
+ }, [
1134
+ graph,
1135
+ dispatch,
1136
+ isCurrent,
1137
+ isLg
1138
+ ]);
1139
+ const onBack = useCallback2(() => dispatch(createIntent5(LayoutAction4.RevertWorkspace, {
1140
+ part: "workspace",
1141
+ options: {
1142
+ revert: true
1143
+ }
1144
+ })), [
1145
+ dispatch
1146
+ ]);
1147
+ useEffect3(() => {
1148
+ return monitorForElements({
1149
+ canMonitor: ({ source }) => isTreeData(source.data),
1150
+ onDrop: ({ location, source }) => {
1151
+ if (!location.current.dropTargets.length) {
1152
+ return;
1153
+ }
1154
+ const target = location.current.dropTargets[0];
1155
+ const instruction = extractInstruction(target.data);
1156
+ if (instruction !== null && instruction.type !== "instruction-blocked") {
1157
+ const sourceNode = source.data.item;
1158
+ const targetNode = target.data.item;
1159
+ const sourcePath = source.data.path;
1160
+ const targetPath = target.data.path;
1161
+ const operation = sourcePath.slice(0, -1).join() === targetPath.slice(0, -1).join() && instruction.type !== "make-child" ? "rearrange" : resolveMigrationOperation(graph, sourceNode, targetPath, targetNode);
1162
+ const sourceParent = getParent(graph, sourceNode, sourcePath);
1163
+ const targetParent = getParent(graph, targetNode, targetPath);
1164
+ const sourceItems = getItems(sourceParent);
1165
+ const targetItems = getItems(targetParent);
1166
+ const sourceIndex = sourceItems.findIndex(({ id }) => id === sourceNode.id);
1167
+ const targetIndex = targetItems.findIndex(({ id }) => id === targetNode.id);
1168
+ const migrationIndex = instruction.type === "make-child" ? void 0 : instruction.type === "reorder-below" ? targetIndex + 1 : targetIndex;
1169
+ switch (operation) {
1170
+ case "rearrange": {
1171
+ const nextItems = sourceItems.map(({ data }) => data);
1172
+ arrayMove2(nextItems, sourceIndex, targetIndex);
1173
+ void sourceParent?.properties.onRearrangeChildren?.(nextItems);
1174
+ break;
1175
+ }
1176
+ case "copy": {
1177
+ const target2 = instruction.type === "make-child" ? targetNode : targetParent;
1178
+ void target2?.properties.onCopy?.(sourceNode, migrationIndex);
1179
+ break;
1180
+ }
1181
+ case "transfer": {
1182
+ const target2 = instruction.type === "make-child" ? targetNode : targetParent;
1183
+ if (!target2?.properties.onTransferStart || !sourceParent?.properties.onTransferEnd) {
1184
+ break;
1185
+ }
1186
+ void target2?.properties.onTransferStart(sourceNode, migrationIndex);
1187
+ void sourceParent?.properties.onTransferEnd?.(sourceNode, target2);
1188
+ break;
1189
+ }
1190
+ }
1191
+ }
1192
+ }
1193
+ });
1194
+ }, [
1195
+ graph
1196
+ ]);
1197
+ const navTreeContextValue = useMemo5(() => ({
1198
+ tab,
1199
+ onTabChange,
1200
+ onBack,
1201
+ getActions: getActions2,
1202
+ loadDescendents,
1203
+ renderItemEnd,
1204
+ popoverAnchorId,
1205
+ topbar,
1206
+ getItems,
1207
+ getProps,
1208
+ isCurrent,
1209
+ isOpen,
1210
+ onOpenChange,
1211
+ canDrop,
1212
+ onSelect: handleSelect
1213
+ }), [
1214
+ tab,
1215
+ onTabChange,
1216
+ onBack,
1217
+ getActions2,
1218
+ loadDescendents,
1219
+ renderItemEnd,
1220
+ popoverAnchorId,
1221
+ topbar,
1222
+ getItems,
1223
+ getProps,
1224
+ isCurrent,
1225
+ isOpen,
1226
+ onOpenChange,
1227
+ canDrop,
1228
+ handleSelect
1229
+ ]);
1230
+ return /* @__PURE__ */ React10.createElement(NavTreeContext.Provider, {
1231
+ value: navTreeContextValue
1232
+ }, /* @__PURE__ */ React10.createElement(NavTree, {
1233
+ root: graph.root,
1234
+ id: graph.root.id
1235
+ }));
1236
+ });
1237
+
1238
+ export {
1239
+ CommandsDialogContent,
1240
+ CommandsTrigger,
1241
+ NotchStart,
1242
+ getParent,
1243
+ getPersistenceParent,
1244
+ resolveMigrationOperation,
1245
+ sortActions,
1246
+ getChildren,
1247
+ getActions,
1248
+ expandChildrenAndActions,
1249
+ expandChildren,
1250
+ expandActions,
1251
+ l0ItemType,
1252
+ getFirstTwoRenderableChars,
1253
+ NODE_TYPE,
1254
+ NavTreeContainer,
1255
+ NavTreeDocumentTitle,
1256
+ AppGraphBuilder,
1257
+ IntentResolver,
1258
+ Keyboard2 as Keyboard,
1259
+ ReactSurface,
1260
+ State
1261
+ };
1262
+ //# sourceMappingURL=chunk-GXNOX2XZ.mjs.map