@dxos/plugin-navtree 0.8.2-main.f11618f → 0.8.2-staging.42af850

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