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

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
@@ -2,12 +2,11 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import React, { useCallback } from 'react';
5
+ import React from 'react';
6
6
 
7
- import { createSurface, Capabilities, contributes, useCapability } from '@dxos/app-framework';
8
- import { isGraphNode, type Node } from '@dxos/plugin-graph';
7
+ import { Capabilities, contributes, createSurface } from '@dxos/app-framework';
8
+ import { isGraphNode } from '@dxos/plugin-graph';
9
9
 
10
- import { NavTreeCapabilities } from './capabilities';
11
10
  import {
12
11
  CommandsDialogContent,
13
12
  CommandsTrigger,
@@ -15,48 +14,28 @@ import {
15
14
  NotchStart,
16
15
  NavTreeContainer,
17
16
  } from '../components';
18
- import { NavTreeFooter } from '../components/NavTreeFooter';
19
17
  import { COMMANDS_DIALOG, NAVTREE_PLUGIN } from '../meta';
20
- import { type NavTreeItemGraphNode } from '../types';
21
- import { expandChildrenAndActions } from '../util';
22
18
 
23
19
  export default () =>
24
20
  contributes(Capabilities.ReactSurface, [
25
21
  createSurface({
26
22
  id: COMMANDS_DIALOG,
27
23
  role: 'dialog',
28
- filter: (data): data is { subject?: string } => data.component === COMMANDS_DIALOG,
29
- component: ({ data }) => <CommandsDialogContent selected={data.subject} />,
24
+ filter: (data): data is { props: { selected?: string } } => data.component === COMMANDS_DIALOG,
25
+ component: ({ data }) => <CommandsDialogContent {...data.props} />,
30
26
  }),
31
27
  createSurface({
32
28
  id: `${NAVTREE_PLUGIN}/navigation`,
33
29
  role: 'navigation',
34
- component: ({ data }) => {
35
- const { graph } = useCapability(Capabilities.AppGraph);
36
- const { isOpen, isCurrent, setItem } = useCapability(NavTreeCapabilities.State);
37
-
38
- const handleOpenChange = useCallback(
39
- ({ item: { id }, path, open }: { item: Node; path: string[]; open: boolean }) => {
40
- // TODO(thure): This might become a localstorage leak; openItemIds that no longer exist should be removed from this map.
41
- setItem(path, 'open', open);
42
-
43
- if (graph) {
44
- const node = graph.findNode(id);
45
- return node && expandChildrenAndActions(graph, node as NavTreeItemGraphNode);
46
- }
47
- },
48
- [graph],
49
- );
50
-
51
- return (
52
- <NavTreeContainer
53
- isOpen={isOpen}
54
- isCurrent={isCurrent}
55
- onOpenChange={handleOpenChange}
56
- popoverAnchorId={data.popoverAnchorId as string | undefined}
57
- />
58
- );
59
- },
30
+ filter: (data): data is { popoverAnchorId?: string; topbar: boolean; current: string } =>
31
+ typeof data.current === 'string',
32
+ component: ({ data }) => (
33
+ <NavTreeContainer
34
+ tab={data.current}
35
+ popoverAnchorId={data.popoverAnchorId as string | undefined}
36
+ topbar={data.topbar as boolean}
37
+ />
38
+ ),
60
39
  }),
61
40
  createSurface({
62
41
  id: `${NAVTREE_PLUGIN}/document-title`,
@@ -68,15 +47,10 @@ export default () =>
68
47
  role: 'notch-start',
69
48
  component: () => <NotchStart />,
70
49
  }),
71
- createSurface({
72
- id: `${NAVTREE_PLUGIN}/header-end`,
73
- role: 'header-end',
74
- component: () => <NavTreeFooter />,
75
- }),
76
50
  createSurface({
77
51
  id: `${NAVTREE_PLUGIN}/search-input`,
78
52
  role: 'search-input',
79
- disposition: 'fallback',
53
+ position: 'fallback',
80
54
  component: () => <CommandsTrigger />,
81
55
  }),
82
56
  ]);
@@ -6,7 +6,7 @@ import { effect } from '@preact/signals-core';
6
6
 
7
7
  import { Capabilities, contributes, type PluginsContext } from '@dxos/app-framework';
8
8
  import { type ReactiveObject, create } from '@dxos/live-object';
9
- import { Path } from '@dxos/react-ui-mosaic';
9
+ import { Path } from '@dxos/react-ui-list';
10
10
 
11
11
  import { NavTreeCapabilities } from './capabilities';
12
12
  import { NAVTREE_PLUGIN } from '../meta';
@@ -34,6 +34,8 @@ const getInitialState = () => {
34
34
  };
35
35
 
36
36
  export default (context: PluginsContext) => {
37
+ const layout = context.requestCapability(Capabilities.Layout);
38
+
37
39
  // TODO(wittjosiah): This currently needs to be not a ReactiveObject at the root.
38
40
  // If it is a ReactiveObject then React errors when initializing new paths because of state change during render.
39
41
  // Ideally this could be a ReactiveObject but be able to access and update the root level without breaking render.
@@ -67,15 +69,10 @@ export default (context: PluginsContext) => {
67
69
  const isOpen = (path: string[]) => getItem(path).open;
68
70
  const isCurrent = (path: string[]) => getItem(path).current;
69
71
 
70
- const location = context.requestCapability(Capabilities.Location);
71
- const layout = context.requestCapability(Capabilities.Layout);
72
-
73
72
  let previous: string[] = [];
74
73
  const unsubscribe = effect(() => {
75
- const part = layout.layoutMode === 'solo' ? 'solo' : 'main';
76
- const current = location.active[part]?.map(({ id }) => id) ?? [];
77
- const removed = previous.filter((id) => !current.includes(id));
78
- previous = current;
74
+ const removed = previous.filter((id) => !layout.active.includes(id));
75
+ previous = layout.active;
79
76
 
80
77
  // TODO(wittjosiah): This is setTimeout because there's a race between the keys be initialized.
81
78
  // This could be avoided if the location was a path as well and not just an id.
@@ -87,7 +84,7 @@ export default (context: PluginsContext) => {
87
84
  });
88
85
  });
89
86
 
90
- current.forEach((id) => {
87
+ layout.active.forEach((id) => {
91
88
  const keys = Array.from(new Set([...state.keys(), id])).filter((key) => Path.last(key) === id);
92
89
  keys.forEach((key) => {
93
90
  setItem(Path.parts(key), 'current', true);
@@ -4,10 +4,9 @@
4
4
 
5
5
  import React, { useMemo, useState } from 'react';
6
6
 
7
- import { useIntentDispatcher, LayoutAction, createIntent } from '@dxos/app-framework';
7
+ import { createIntent, LayoutAction, useAppGraph, useIntentDispatcher } from '@dxos/app-framework';
8
8
  import { type ActionLike, isActionGroup, isAction } from '@dxos/app-graph';
9
9
  import { Keyboard, keySymbols } from '@dxos/keyboard';
10
- import { useGraph } from '@dxos/plugin-graph';
11
10
  import { Button, Dialog, Icon, useTranslation, toLocalizedString } from '@dxos/react-ui';
12
11
  import { SearchList } from '@dxos/react-ui-searchlist';
13
12
  import { descriptionText, mx } from '@dxos/react-ui-theme';
@@ -20,7 +19,7 @@ export const CommandsDialogContent = ({ selected: initial }: { selected?: string
20
19
  const { t } = useTranslation(NAVTREE_PLUGIN);
21
20
  const [selected, setSelected] = useState<string | undefined>(initial);
22
21
  const { dispatchPromise: dispatch } = useIntentDispatcher();
23
- const { graph } = useGraph();
22
+ const { graph } = useAppGraph();
24
23
 
25
24
  // Traverse graph.
26
25
  // TODO(burdon): Factor out commonality with shortcut dialog.
@@ -83,7 +82,7 @@ export const CommandsDialogContent = ({ selected: initial }: { selected?: string
83
82
  return;
84
83
  }
85
84
 
86
- void dispatch(createIntent(LayoutAction.SetLayout, { element: 'dialog', state: false }));
85
+ void dispatch(createIntent(LayoutAction.UpdateDialog, { part: 'dialog', options: { state: false } }));
87
86
  setTimeout(() => {
88
87
  const node = graph.nodes(group ?? action, { relation: 'inbound' })[0];
89
88
  void (node && isAction(action) && action.data({ node, caller: KEY_BINDING }));
@@ -17,13 +17,15 @@ export const CommandsTrigger = () => {
17
17
  const { t } = useTranslation(NAVTREE_PLUGIN);
18
18
  return (
19
19
  <Button
20
- classNames='m-1 !pli-1 lg:!pli-2'
20
+ classNames='m-1 pli-1 lg:pli-2'
21
21
  onClick={() =>
22
22
  dispatch(
23
- createIntent(LayoutAction.SetLayout, {
24
- element: 'dialog',
25
- component: COMMANDS_DIALOG,
26
- dialogBlockAlign: 'start',
23
+ createIntent(LayoutAction.UpdateDialog, {
24
+ part: 'dialog',
25
+ subject: COMMANDS_DIALOG,
26
+ options: {
27
+ blockAlign: 'start',
28
+ },
27
29
  }),
28
30
  )
29
31
  }
@@ -0,0 +1,332 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
6
+ import { draggable, dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
7
+ import { preserveOffsetOnSource } from '@atlaskit/pragmatic-drag-and-drop/element/preserve-offset-on-source';
8
+ import { scrollJustEnoughIntoView } from '@atlaskit/pragmatic-drag-and-drop/element/scroll-just-enough-into-view';
9
+ import {
10
+ attachClosestEdge,
11
+ type Edge,
12
+ extractClosestEdge,
13
+ } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
14
+ import React, { type MouseEvent, useCallback, useLayoutEffect, useMemo, useRef, useState } from 'react';
15
+
16
+ import { createIntent, LayoutAction, useIntentDispatcher } from '@dxos/app-framework';
17
+ import { type Node } from '@dxos/app-graph';
18
+ import { invariant } from '@dxos/invariant';
19
+ import {
20
+ Popover,
21
+ ScrollArea,
22
+ toLocalizedString,
23
+ Tooltip,
24
+ useMediaQuery,
25
+ useSidebars,
26
+ useTranslation,
27
+ ListItem,
28
+ Icon,
29
+ } from '@dxos/react-ui';
30
+ import type { StackItemRearrangeHandler } from '@dxos/react-ui-stack';
31
+ import { Tabs } from '@dxos/react-ui-tabs';
32
+ import { mx } from '@dxos/react-ui-theme';
33
+ import { arrayMove } from '@dxos/util';
34
+
35
+ import { useNavTreeContext } from './NavTreeContext';
36
+ import { NotchStart } from './NotchStart';
37
+ import { useLoadDescendents } from '../hooks';
38
+ import { NAVTREE_PLUGIN } from '../meta';
39
+ import { getFirstTwoRenderableChars, l0ItemType } from '../util';
40
+
41
+ type L0ItemData = { id: L0ItemProps['item']['id']; type: 'l0Item' };
42
+
43
+ type L0ItemProps = {
44
+ item: Node<any>;
45
+ parent?: Node<any>;
46
+ path: string[];
47
+ pinned?: boolean;
48
+ onRearrange?: StackItemRearrangeHandler<L0ItemData>;
49
+ };
50
+
51
+ const useL0ItemClick = ({ item, parent, path }: L0ItemProps, type: string) => {
52
+ const { tab, onTabChange, onSelect, isCurrent } = useNavTreeContext();
53
+ const { dispatchPromise: dispatch } = useIntentDispatcher();
54
+ const { navigationSidebarState } = useSidebars(NAVTREE_PLUGIN);
55
+ const [isLg] = useMediaQuery('lg', { ssr: false });
56
+
57
+ return useCallback(
58
+ (event: MouseEvent) => {
59
+ switch (type) {
60
+ case 'tab':
61
+ // TODO(thure): This dispatch should rightly be in `onTabChange`, but that callback wasn’t reacting to changes
62
+ // to its dependencies.
63
+ void dispatch(
64
+ createIntent(LayoutAction.UpdateSidebar, {
65
+ part: 'sidebar',
66
+ options: {
67
+ state:
68
+ item.id === tab
69
+ ? navigationSidebarState === 'expanded'
70
+ ? isLg
71
+ ? 'collapsed'
72
+ : 'closed'
73
+ : 'expanded'
74
+ : 'expanded',
75
+ },
76
+ }),
77
+ );
78
+ return onTabChange?.(item);
79
+ case 'link':
80
+ return onSelect?.({ item, path, current: !isCurrent(path, item), option: event.altKey });
81
+ case 'action': {
82
+ const {
83
+ data: invoke,
84
+ properties: { caller },
85
+ } = item;
86
+ return invoke?.(caller ? { node: parent, caller } : { node: parent });
87
+ }
88
+ }
89
+ },
90
+ [item, type, onSelect, isCurrent, parent, tab, navigationSidebarState, isLg, dispatch],
91
+ );
92
+ };
93
+
94
+ const l0Breakpoints: Record<string, string> = {
95
+ lg: 'hidden lg:grid',
96
+ };
97
+
98
+ const L0Item = ({ item, parent, path, pinned, onRearrange }: L0ItemProps) => {
99
+ const { t } = useTranslation(NAVTREE_PLUGIN);
100
+ const itemElement = useRef<HTMLElement | null>(null);
101
+ const [closestEdge, setEdge] = useState<Edge | null>(null);
102
+ const type = l0ItemType(item);
103
+ const itemPath = useMemo(() => [...path, item.id], [item.id, path]);
104
+ const { getProps, popoverAnchorId } = useNavTreeContext();
105
+ const { id, testId } = getProps?.(item, path) ?? {};
106
+ const Root = type === 'collection' ? 'h2' : type === 'tab' ? Tabs.TabPrimitive : 'button';
107
+ const handleClick = useL0ItemClick({ item, path: itemPath, parent }, type);
108
+ const rootProps =
109
+ type === 'tab'
110
+ ? { value: item.id, tabIndex: 0, onClick: handleClick, 'data-testid': testId, 'data-itemid': id }
111
+ : type !== 'collection'
112
+ ? { onClick: handleClick, 'data-testid': testId, 'data-itemid': id }
113
+ : { onClick: handleClick };
114
+ const localizedString = toLocalizedString(item.properties.label, t);
115
+ const hue = item.properties.hue ?? null;
116
+ const avatarValue = useMemo(
117
+ () => (type === 'tab' ? getFirstTwoRenderableChars(localizedString).join('').toUpperCase() : []),
118
+ [type, item.properties.label, t],
119
+ );
120
+ const hueFgStyle = hue && { style: { color: `var(--dx-${hue}SurfaceText)` } };
121
+
122
+ useLayoutEffect(() => {
123
+ // NOTE(thure): This is copied from StackItem, perhaps this should be DRYed out.
124
+ if (!itemElement.current || !onRearrange) {
125
+ return;
126
+ }
127
+ return combine(
128
+ draggable({
129
+ element: itemElement.current,
130
+ getInitialData: () => ({ id: item.id, type: 'l0Item' }) satisfies L0ItemData,
131
+ onGenerateDragPreview: ({ nativeSetDragImage, source, location }) => {
132
+ document.body.setAttribute('data-drag-preview', 'true');
133
+ const element = source.element.querySelector('[data-frame]') as HTMLElement;
134
+ scrollJustEnoughIntoView({ element });
135
+ const { x, y } = preserveOffsetOnSource({ element, input: location.current.input })({
136
+ container: (element.offsetParent ?? document.body) as HTMLElement,
137
+ });
138
+ nativeSetDragImage?.(element, x, y);
139
+ },
140
+ onDragStart: () => {
141
+ document.body.removeAttribute('data-drag-preview');
142
+ itemElement.current!.closest('[data-drag-autoscroll]')?.setAttribute('data-drag-autoscroll', 'active');
143
+ },
144
+ onDrop: () => {
145
+ itemElement.current!.closest('[data-drag-autoscroll]')?.setAttribute('data-drag-autoscroll', 'idle');
146
+ },
147
+ }),
148
+ dropTargetForElements({
149
+ element: itemElement.current,
150
+ getData: ({ input, element }) => {
151
+ return attachClosestEdge(
152
+ { id: item.id, type: 'l0Item' },
153
+ { input, element, allowedEdges: ['top', 'bottom'] },
154
+ );
155
+ },
156
+ onDragEnter: ({ self, source }) => {
157
+ if (source.data.type === self.data.type) {
158
+ setEdge(extractClosestEdge(self.data));
159
+ }
160
+ },
161
+ onDrag: ({ self, source }) => {
162
+ if (source.data.type === self.data.type) {
163
+ setEdge(extractClosestEdge(self.data));
164
+ }
165
+ },
166
+ onDragLeave: () => setEdge(null),
167
+ onDrop: ({ self, source }) => {
168
+ setEdge(null);
169
+ if (source.data.type === self.data.type) {
170
+ onRearrange(source.data as L0ItemData, self.data as L0ItemData, extractClosestEdge(self.data));
171
+ }
172
+ },
173
+ }),
174
+ );
175
+ }, [item, onRearrange]);
176
+
177
+ const l0ItemTrigger = (
178
+ <Root
179
+ {...(rootProps as any)}
180
+ data-type={type}
181
+ className={mx(
182
+ 'group/l0i dx-focus-ring-group grid relative data[type!="collection"]:cursor-pointer app-no-drag',
183
+ l0Breakpoints[item.properties.l0Breakpoint],
184
+ )}
185
+ ref={itemElement}
186
+ >
187
+ <div
188
+ role='none'
189
+ data-frame={true}
190
+ className={mx(
191
+ 'absolute grid dx-focus-ring-group-indicator transition-colors',
192
+ type === 'tab' || pinned ? 'rounded' : 'rounded-full',
193
+ pinned
194
+ ? 'bg-transparent group-hover/l0i:bg-groupSurface inset-inline-3 inset-block-0.5'
195
+ : 'bg-groupSurface inset-inline-3 inset-block-2',
196
+ )}
197
+ {...(hue && { style: { background: `var(--dx-${hue}Surface)` } })}
198
+ >
199
+ {(item.properties.icon && (
200
+ <Icon icon={item.properties.icon} size={pinned ? 5 : 7} classNames='place-self-center' {...hueFgStyle} />
201
+ )) ||
202
+ (type === 'tab' && item.properties.disposition !== 'pin-end' ? (
203
+ <span role='img' className='place-self-center text-3xl font-light' {...hueFgStyle}>
204
+ {avatarValue}
205
+ </span>
206
+ ) : (
207
+ item.properties.icon && (
208
+ <Icon icon='ph--planet--regular' size={pinned ? 5 : 7} classNames='place-self-center' {...hueFgStyle} />
209
+ )
210
+ ))}
211
+ </div>
212
+ <div
213
+ role='none'
214
+ className='hidden group-aria-selected/l0i:block absolute inline-start-0 inset-block-4 is-1 bg-accentSurface rounded-ie'
215
+ />
216
+ <span id={`${item.id}__label`} className='sr-only'>
217
+ {localizedString}
218
+ </span>
219
+ {onRearrange && closestEdge && <ListItem.DropIndicator edge={closestEdge} />}
220
+ </Root>
221
+ );
222
+
223
+ return popoverAnchorId === id ? (
224
+ <Popover.Anchor asChild>{l0ItemTrigger}</Popover.Anchor>
225
+ ) : (
226
+ <Tooltip.Root delayDuration={0}>
227
+ <Tooltip.Trigger asChild>{l0ItemTrigger}</Tooltip.Trigger>
228
+ <Tooltip.Portal>
229
+ <Tooltip.Content side='right'>
230
+ {localizedString}
231
+ <Tooltip.Arrow />
232
+ </Tooltip.Content>
233
+ </Tooltip.Portal>
234
+ </Tooltip.Root>
235
+ );
236
+ };
237
+
238
+ const L0Collection = ({ item, path, parent }: L0ItemProps) => {
239
+ const navTreeContext = useNavTreeContext();
240
+ useLoadDescendents(item);
241
+ const collectionItems = navTreeContext.getItems(item);
242
+ const groupPath = useMemo(() => [...path, item.id], [item.id, path]);
243
+ const { id, testId } = navTreeContext.getProps?.(item, path) ?? {};
244
+ const handleRearrange = useCallback<StackItemRearrangeHandler<L0ItemData>>(
245
+ (source, target, closestEdge) => {
246
+ invariant(item.properties.onRearrangeChildren);
247
+ const sourceIndex = collectionItems.findIndex((i) => i.id === source.id);
248
+ const targetIndex = collectionItems.findIndex((i) => i.id === target.id);
249
+ const insertIndex =
250
+ source.id === target.id
251
+ ? sourceIndex
252
+ : targetIndex +
253
+ (sourceIndex < targetIndex ? (closestEdge === 'top' ? -1 : 0) : closestEdge === 'bottom' ? 1 : 0);
254
+ const nextOrder = arrayMove([...collectionItems], sourceIndex, insertIndex);
255
+ return item.properties.onRearrangeChildren(nextOrder);
256
+ },
257
+ [collectionItems, item.properties.onRearrangeChildren],
258
+ );
259
+ return (
260
+ <div
261
+ role='group'
262
+ className='contents group/l0c'
263
+ aria-labelledby={`${item.id}__label`}
264
+ data-itemid={id}
265
+ data-testid={testId}
266
+ >
267
+ {collectionItems.map((collectionItem) => (
268
+ <L0Item
269
+ key={collectionItem.id}
270
+ item={collectionItem}
271
+ parent={item}
272
+ path={groupPath}
273
+ {...(item.properties.onRearrangeChildren && { onRearrange: handleRearrange })}
274
+ />
275
+ ))}
276
+ </div>
277
+ );
278
+ };
279
+
280
+ export const L0Menu = ({
281
+ topLevelItems,
282
+ pinnedItems,
283
+ parent,
284
+ path,
285
+ }: {
286
+ topLevelItems: Node<any>[];
287
+ pinnedItems: Node<any>[];
288
+ parent?: Node<any>;
289
+ path: string[];
290
+ }) => {
291
+ return (
292
+ <Tabs.Tablist 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)]'>
293
+ <ScrollArea.Root>
294
+ <ScrollArea.Viewport>
295
+ <div
296
+ role='none'
297
+ 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)]'
298
+ >
299
+ {topLevelItems.map((item) => {
300
+ if (l0ItemType(item) === 'collection') {
301
+ return <L0Collection key={item.id} item={item} parent={parent} path={path} />;
302
+ } else {
303
+ return <L0Item key={item.id} item={item} parent={parent} path={path} />;
304
+ }
305
+ })}
306
+ </div>
307
+ <ScrollArea.Scrollbar orientation='vertical'>
308
+ <ScrollArea.Thumb />
309
+ </ScrollArea.Scrollbar>
310
+ </ScrollArea.Viewport>
311
+ </ScrollArea.Root>
312
+ <div role='none' className='grid grid-cols-1 auto-rows-[--rail-action] pbs-2'>
313
+ {pinnedItems
314
+ .filter((item) => l0ItemType(item) !== 'collection')
315
+ .map((item) => (
316
+ <L0Item key={item.id} item={item} parent={parent} path={path} pinned />
317
+ ))}
318
+ </div>
319
+ <div role='none' className='grid p-2 app-no-drag'>
320
+ <NotchStart />
321
+ </div>
322
+ <div
323
+ role='none'
324
+ className='hidden [body[data-platform="darwin"]_&]:block absolute block-start-0 is-[calc(var(--l0-size)-1px)] bs-[calc(40px+0.25rem)]'
325
+ style={{
326
+ background:
327
+ 'linear-gradient(to bottom, var(--dx-baseSurface) 0%, var(--dx-baseSurface) 70%, transparent 100%)',
328
+ }}
329
+ />
330
+ </Tabs.Tablist>
331
+ );
332
+ };
@@ -0,0 +1,119 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import React, { useMemo } from 'react';
6
+
7
+ import { useLayout } from '@dxos/app-framework';
8
+ import { type Node } from '@dxos/app-graph';
9
+ import { IconButton, toLocalizedString, useTranslation } from '@dxos/react-ui';
10
+ import { Tree } from '@dxos/react-ui-list';
11
+ import { Tabs } from '@dxos/react-ui-tabs';
12
+ import { hoverableControlItem, hoverableOpenControlItem, mx } from '@dxos/react-ui-theme';
13
+
14
+ import { useNavTreeContext } from './NavTreeContext';
15
+ import { NavTreeItemColumns } from './NavTreeItemColumns';
16
+ import { useLoadDescendents } from '../hooks';
17
+ import { NAVTREE_PLUGIN } from '../meta';
18
+ import { l0ItemType } from '../util';
19
+
20
+ export type L1PanelProps = { item: Node<any>; path: string[]; currentItemId: string; onBack?: () => void };
21
+
22
+ const L1Panel = ({ item, path, currentItemId, onBack }: L1PanelProps) => {
23
+ const layout = useLayout();
24
+ const navTreeContext = useNavTreeContext();
25
+ const { t } = useTranslation(NAVTREE_PLUGIN);
26
+ return (
27
+ <Tabs.Tabpanel
28
+ key={item.id}
29
+ value={item.id}
30
+ classNames={[
31
+ '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)]',
32
+ item.id === currentItemId && 'grid',
33
+ ]}
34
+ tabIndex={-1}
35
+ {...(!layout.sidebarOpen && { inert: 'true' })}
36
+ >
37
+ {item.id === currentItemId && (
38
+ <>
39
+ <h2 className='flex items-center border-be border-separator pis-4 app-drag'>
40
+ {item.properties.disposition === 'pin-end' && (
41
+ <IconButton
42
+ label={t('back label')}
43
+ iconOnly
44
+ icon='ph--caret-left--regular'
45
+ size={5}
46
+ density='fine'
47
+ variant='ghost'
48
+ classNames={mx(
49
+ 'shrink-0 mie-2 !p-0',
50
+ 'pointer-fine:pli-1',
51
+ hoverableControlItem,
52
+ hoverableOpenControlItem,
53
+ )}
54
+ onClick={onBack}
55
+ />
56
+ )}
57
+ <span className='flex-1 truncate cursor-default'>{toLocalizedString(item.properties.label, t)}</span>
58
+ <NavTreeItemColumns path={path} item={item} open />
59
+ </h2>
60
+ <div role='none' className='overflow-y-auto'>
61
+ <Tree
62
+ {...navTreeContext}
63
+ id={item.id}
64
+ root={item}
65
+ path={path}
66
+ levelOffset={5}
67
+ draggable
68
+ gridTemplateColumns='[tree-row-start] 1fr min-content min-content min-content [tree-row-end]'
69
+ renderColumns={NavTreeItemColumns}
70
+ />
71
+ </div>
72
+ </>
73
+ )}
74
+ </Tabs.Tabpanel>
75
+ );
76
+ };
77
+
78
+ const L1PanelCollection = ({ item, path, currentItemId }: L1PanelProps) => {
79
+ const { getItems } = useNavTreeContext();
80
+ useLoadDescendents(item);
81
+ const collectionItems = getItems(item);
82
+ const groupPath = useMemo(() => [...path, item.id], [item.id, path]);
83
+ return (
84
+ <>
85
+ {collectionItems
86
+ .filter((item) => l0ItemType(item) === 'tab')
87
+ .map((item) => (
88
+ <L1Panel key={item.id} item={item} path={groupPath} currentItemId={currentItemId} />
89
+ ))}
90
+ </>
91
+ );
92
+ };
93
+
94
+ export const L1Panels = ({
95
+ topLevelItems,
96
+ path,
97
+ currentItemId,
98
+ onBack,
99
+ }: Pick<L1PanelProps, 'onBack'> & {
100
+ topLevelItems: Node<any>[];
101
+ path: string[];
102
+ currentItemId: string;
103
+ }) => {
104
+ return (
105
+ <>
106
+ {topLevelItems.map((item) => {
107
+ const type = l0ItemType(item);
108
+ switch (type) {
109
+ case 'collection':
110
+ return <L1PanelCollection key={item.id} item={item} path={path} currentItemId={currentItemId} />;
111
+ case 'tab':
112
+ return <L1Panel key={item.id} item={item} path={path} currentItemId={currentItemId} onBack={onBack} />;
113
+ default:
114
+ return null;
115
+ }
116
+ })}
117
+ </>
118
+ );
119
+ };
@@ -13,10 +13,10 @@ import { isActionLike, type NodeArg } from '@dxos/app-graph';
13
13
  import { create, type ReactiveObject } from '@dxos/live-object';
14
14
  import { faker } from '@dxos/random';
15
15
  import { isTreeData, type TreeData } from '@dxos/react-ui-list';
16
- import { Path } from '@dxos/react-ui-mosaic';
16
+ import { Path } from '@dxos/react-ui-list';
17
17
  import { withLayout, withTheme } from '@dxos/storybook-utils';
18
18
 
19
- import { NavTree } from './NavTree';
19
+ import { StorybookNavTree } from '../stories/StorybookNavTree';
20
20
  import { createTree, updateState } from '../testing';
21
21
 
22
22
  faker.seed(1234);
@@ -24,9 +24,9 @@ faker.seed(1234);
24
24
  const tree = create<NodeArg<any>>(createTree());
25
25
  const state = new Map<string, ReactiveObject<{ open: boolean; current: boolean }>>();
26
26
 
27
- const meta: Meta<typeof NavTree> = {
27
+ const meta: Meta<typeof StorybookNavTree> = {
28
28
  title: 'plugins/plugin-navtree/NavTree',
29
- component: NavTree,
29
+ component: StorybookNavTree,
30
30
  decorators: [withTheme, withLayout({ tooltips: true })],
31
31
  render: (args) => {
32
32
  useEffect(() => {
@@ -52,7 +52,7 @@ const meta: Meta<typeof NavTree> = {
52
52
  });
53
53
  }, []);
54
54
 
55
- return <NavTree {...args} />;
55
+ return <StorybookNavTree {...args} />;
56
56
  },
57
57
  args: {
58
58
  id: tree.id,
@@ -60,7 +60,7 @@ const meta: Meta<typeof NavTree> = {
60
60
  actions: arg.nodes?.filter((node) => isActionLike(node)) ?? [],
61
61
  groupedActions: {},
62
62
  }),
63
- getItems: (testItem?: NodeArg<any>) => {
63
+ getItems: (testItem?: any) => {
64
64
  return testItem?.nodes ?? tree.nodes ?? [];
65
65
  },
66
66
  getProps: (testItem: NodeArg<any>) => ({