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

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-7OKF4GP3.mjs +1156 -0
  4. package/dist/lib/browser/chunk-7OKF4GP3.mjs.map +7 -0
  5. package/dist/lib/browser/{chunk-OI7AAA6Q.mjs → chunk-AOAGODQB.mjs} +1 -1
  6. package/dist/lib/browser/chunk-AOAGODQB.mjs.map +7 -0
  7. package/dist/lib/browser/index.mjs +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-SIEGT4YS.mjs +57 -0
  13. package/dist/lib/browser/react-surface-SIEGT4YS.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 +238 -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,238 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import React, { type MouseEvent, useCallback, useMemo } from 'react';
6
+
7
+ import { createIntent, LayoutAction, useIntentDispatcher } from '@dxos/app-framework';
8
+ import { type Node } from '@dxos/app-graph';
9
+ import {
10
+ Icon,
11
+ Popover,
12
+ ScrollArea,
13
+ toLocalizedString,
14
+ Tooltip,
15
+ useMediaQuery,
16
+ useSidebars,
17
+ useTranslation,
18
+ } from '@dxos/react-ui';
19
+ import { Tabs } from '@dxos/react-ui-tabs';
20
+ import { mx } from '@dxos/react-ui-theme';
21
+
22
+ import { useNavTreeContext } from './NavTreeContext';
23
+ import { NotchStart } from './NotchStart';
24
+ import { useLoadDescendents } from '../hooks';
25
+ import { NAVTREE_PLUGIN } from '../meta';
26
+ import { getFirstTwoRenderableChars, l0ItemType } from '../util';
27
+
28
+ type L0ItemProps = {
29
+ item: Node<any>;
30
+ parent?: Node<any>;
31
+ path: string[];
32
+ pinned?: boolean;
33
+ };
34
+
35
+ const useL0ItemClick = ({ item, parent, path }: L0ItemProps, type: string) => {
36
+ const { tab, onTabChange, onSelect, isCurrent } = useNavTreeContext();
37
+ const { dispatchPromise: dispatch } = useIntentDispatcher();
38
+ const { navigationSidebarState } = useSidebars(NAVTREE_PLUGIN);
39
+ const [isLg] = useMediaQuery('lg', { ssr: false });
40
+
41
+ return useCallback(
42
+ (event: MouseEvent) => {
43
+ switch (type) {
44
+ case 'tab':
45
+ // TODO(thure): This dispatch should rightly be in `onTabChange`, but that callback wasn’t reacting to changes
46
+ // to its dependencies.
47
+ void dispatch(
48
+ createIntent(LayoutAction.UpdateSidebar, {
49
+ part: 'sidebar',
50
+ options: {
51
+ state:
52
+ item.id === tab
53
+ ? navigationSidebarState === 'expanded'
54
+ ? isLg
55
+ ? 'collapsed'
56
+ : 'closed'
57
+ : 'expanded'
58
+ : 'expanded',
59
+ },
60
+ }),
61
+ );
62
+ return onTabChange?.(item);
63
+ case 'link':
64
+ return onSelect?.({ item, path, current: !isCurrent(path, item), option: event.altKey });
65
+ case 'action': {
66
+ const {
67
+ data: invoke,
68
+ properties: { caller },
69
+ } = item;
70
+ return invoke?.(caller ? { node: parent, caller } : { node: parent });
71
+ }
72
+ }
73
+ },
74
+ [item, type, onSelect, isCurrent, parent, tab, navigationSidebarState, isLg, dispatch],
75
+ );
76
+ };
77
+
78
+ const l0Breakpoints: Record<string, string> = {
79
+ lg: 'hidden lg:grid',
80
+ };
81
+
82
+ const L0Item = ({ item, parent, path, pinned }: L0ItemProps) => {
83
+ const { t } = useTranslation(NAVTREE_PLUGIN);
84
+ const type = l0ItemType(item);
85
+ const itemPath = useMemo(() => [...path, item.id], [item.id, path]);
86
+ const { getProps, popoverAnchorId } = useNavTreeContext();
87
+ const { id, testId } = getProps?.(item, path) ?? {};
88
+ const Root = type === 'collection' ? 'h2' : type === 'tab' ? Tabs.TabPrimitive : 'button';
89
+ const handleClick = useL0ItemClick({ item, path: itemPath, parent }, type);
90
+ const rootProps =
91
+ type === 'tab'
92
+ ? { value: item.id, tabIndex: 0, onClick: handleClick, 'data-testid': testId, 'data-itemid': id }
93
+ : type !== 'collection'
94
+ ? { onClick: handleClick, 'data-testid': testId, 'data-itemid': id }
95
+ : { onClick: handleClick };
96
+ const localizedString = toLocalizedString(item.properties.label, t);
97
+ const hue = item.properties.hue ?? null;
98
+ const avatarValue = useMemo(
99
+ () => (type === 'tab' ? getFirstTwoRenderableChars(localizedString).join('').toUpperCase() : []),
100
+ [type, item.properties.label, t],
101
+ );
102
+ const hueFgStyle = hue && { style: { color: `var(--dx-${hue}SurfaceText)` } };
103
+
104
+ const l0ItemTrigger = (
105
+ <Root
106
+ {...(rootProps as any)}
107
+ data-type={type}
108
+ className={mx(
109
+ 'group/l0i dx-focus-ring-group grid overflow-hidden relative data[type!="collection"]:cursor-pointer app-no-drag',
110
+ l0Breakpoints[item.properties.l0Breakpoint],
111
+ )}
112
+ >
113
+ {type !== 'collection' && (
114
+ <div
115
+ role='none'
116
+ className={mx(
117
+ 'absolute -z-[1] dx-focus-ring-group-indicator transition-colors',
118
+ type === 'tab' || pinned ? 'rounded' : 'rounded-full',
119
+ pinned
120
+ ? 'bg-transparent group-hover/l0i:bg-groupSurface inset-inline-3 inset-block-0.5'
121
+ : 'bg-groupSurface inset-inline-3 inset-block-2',
122
+ )}
123
+ {...(hue && { style: { background: `var(--dx-${hue}Surface)` } })}
124
+ />
125
+ )}
126
+ <div
127
+ role='none'
128
+ className='hidden group-aria-selected/l0i:block absolute inline-start-0 inset-block-4 is-1 bg-accentSurface rounded-ie'
129
+ />
130
+ {(item.properties.icon && (
131
+ <Icon icon={item.properties.icon} size={pinned ? 5 : 7} classNames='place-self-center' {...hueFgStyle} />
132
+ )) ||
133
+ (type === 'tab' && item.properties.disposition !== 'pin-end' ? (
134
+ <span role='img' className='place-self-center text-3xl font-light' {...hueFgStyle}>
135
+ {avatarValue}
136
+ </span>
137
+ ) : (
138
+ item.properties.icon && (
139
+ <Icon icon='ph--planet--regular' size={pinned ? 5 : 7} classNames='place-self-center' {...hueFgStyle} />
140
+ )
141
+ ))}
142
+ <span id={`${item.id}__label`} className='sr-only'>
143
+ {localizedString}
144
+ </span>
145
+ </Root>
146
+ );
147
+
148
+ return popoverAnchorId === id ? (
149
+ <Popover.Anchor asChild>{l0ItemTrigger}</Popover.Anchor>
150
+ ) : (
151
+ <Tooltip.Root delayDuration={0}>
152
+ <Tooltip.Trigger asChild>{l0ItemTrigger}</Tooltip.Trigger>
153
+ <Tooltip.Portal>
154
+ <Tooltip.Content side='right'>
155
+ {localizedString}
156
+ <Tooltip.Arrow />
157
+ </Tooltip.Content>
158
+ </Tooltip.Portal>
159
+ </Tooltip.Root>
160
+ );
161
+ };
162
+
163
+ const L0Collection = ({ item, path, parent }: L0ItemProps) => {
164
+ const navTreeContext = useNavTreeContext();
165
+ useLoadDescendents(item);
166
+ const collectionItems = navTreeContext.getItems(item);
167
+ const groupPath = useMemo(() => [...path, item.id], [item.id, path]);
168
+ const { id, testId } = navTreeContext.getProps?.(item, path) ?? {};
169
+ return (
170
+ <div
171
+ role='group'
172
+ className='contents group/l0c'
173
+ aria-labelledby={`${item.id}__label`}
174
+ data-itemid={id}
175
+ data-testid={testId}
176
+ >
177
+ {/* TODO(burdon): Option. */}
178
+ {/* <L0Item item={item} parent={parent} path={groupPath} /> */}
179
+ {collectionItems.map((collectionItem) => (
180
+ <L0Item key={collectionItem.id} item={collectionItem} parent={item} path={groupPath} />
181
+ ))}
182
+ </div>
183
+ );
184
+ };
185
+
186
+ export const L0Menu = ({
187
+ topLevelItems,
188
+ pinnedItems,
189
+ parent,
190
+ path,
191
+ }: {
192
+ topLevelItems: Node<any>[];
193
+ pinnedItems: Node<any>[];
194
+ parent?: Node<any>;
195
+ path: string[];
196
+ }) => {
197
+ return (
198
+ <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)]'>
199
+ <ScrollArea.Root>
200
+ <ScrollArea.Viewport>
201
+ <div
202
+ role='none'
203
+ 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)]'
204
+ >
205
+ {topLevelItems.map((item) => {
206
+ if (l0ItemType(item) === 'collection') {
207
+ return <L0Collection key={item.id} item={item} parent={parent} path={path} />;
208
+ } else {
209
+ return <L0Item key={item.id} item={item} parent={parent} path={path} />;
210
+ }
211
+ })}
212
+ </div>
213
+ <ScrollArea.Scrollbar orientation='vertical'>
214
+ <ScrollArea.Thumb />
215
+ </ScrollArea.Scrollbar>
216
+ </ScrollArea.Viewport>
217
+ </ScrollArea.Root>
218
+ <div role='none' className='grid grid-cols-1 auto-rows-[--rail-action] pbs-2'>
219
+ {pinnedItems
220
+ .filter((item) => l0ItemType(item) !== 'collection')
221
+ .map((item) => (
222
+ <L0Item key={item.id} item={item} parent={parent} path={path} pinned />
223
+ ))}
224
+ </div>
225
+ <div role='none' className='grid p-2 app-no-drag'>
226
+ <NotchStart />
227
+ </div>
228
+ <div
229
+ role='none'
230
+ className='hidden [body[data-platform="darwin"]_&]:block absolute block-start-0 is-[calc(var(--l0-size)-1px)] bs-[calc(40px+0.25rem)]'
231
+ style={{
232
+ background:
233
+ 'linear-gradient(to bottom, var(--dx-baseSurface) 0%, var(--dx-baseSurface) 70%, transparent 100%)',
234
+ }}
235
+ />
236
+ </Tabs.Tablist>
237
+ );
238
+ };
@@ -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',
50
+ 'pli-2 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>) => ({