@dxos/plugin-navtree 0.7.5-main.9d26e3a → 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 (127) hide show
  1. package/dist/lib/browser/app-graph-builder-BL7LRXCM.mjs +44 -0
  2. package/dist/lib/browser/app-graph-builder-BL7LRXCM.mjs.map +7 -0
  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-AOAGODQB.mjs +15 -0
  6. package/dist/lib/browser/chunk-AOAGODQB.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-VAXG4OAG.mjs → chunk-KOXMEAOS.mjs} +3 -3
  8. package/dist/lib/browser/{chunk-VAXG4OAG.mjs.map → chunk-KOXMEAOS.mjs.map} +3 -3
  9. package/dist/lib/browser/index.mjs +108 -1199
  10. package/dist/lib/browser/index.mjs.map +4 -4
  11. package/dist/lib/browser/intent-resolver-U25VBFH3.mjs +47 -0
  12. package/dist/lib/browser/intent-resolver-U25VBFH3.mjs.map +7 -0
  13. package/dist/lib/browser/keyboard-MUBRTPI5.mjs +46 -0
  14. package/dist/lib/browser/keyboard-MUBRTPI5.mjs.map +7 -0
  15. package/dist/lib/browser/meta.json +1 -1
  16. package/dist/lib/browser/react-surface-SIEGT4YS.mjs +57 -0
  17. package/dist/lib/browser/react-surface-SIEGT4YS.mjs.map +7 -0
  18. package/dist/lib/browser/state-IEFQTUPG.mjs +108 -0
  19. package/dist/lib/browser/state-IEFQTUPG.mjs.map +7 -0
  20. package/dist/types/src/NavTreePlugin.d.ts +1 -3
  21. package/dist/types/src/NavTreePlugin.d.ts.map +1 -1
  22. package/dist/types/src/capabilities/app-graph-builder.d.ts +181 -0
  23. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -0
  24. package/dist/types/src/capabilities/capabilities.d.ts +18 -0
  25. package/dist/types/src/capabilities/capabilities.d.ts.map +1 -0
  26. package/dist/types/src/capabilities/index.d.ts +251 -0
  27. package/dist/types/src/capabilities/index.d.ts.map +1 -0
  28. package/dist/types/src/capabilities/intent-resolver.d.ts +4 -0
  29. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -0
  30. package/dist/types/src/capabilities/keyboard.d.ts +4 -0
  31. package/dist/types/src/capabilities/keyboard.d.ts.map +1 -0
  32. package/dist/types/src/capabilities/react-surface.d.ts +4 -0
  33. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
  34. package/dist/types/src/capabilities/state.d.ts +17 -0
  35. package/dist/types/src/capabilities/state.d.ts.map +1 -0
  36. package/dist/types/src/components/CommandsDialog.d.ts +1 -2
  37. package/dist/types/src/components/CommandsDialog.d.ts.map +1 -1
  38. package/dist/types/src/components/CommandsTrigger.d.ts +1 -2
  39. package/dist/types/src/components/CommandsTrigger.d.ts.map +1 -1
  40. package/dist/types/src/components/HaloButton.d.ts +1 -2
  41. package/dist/types/src/components/HaloButton.d.ts.map +1 -1
  42. package/dist/types/src/components/HaloButton.stories.d.ts +1 -2
  43. package/dist/types/src/components/HaloButton.stories.d.ts.map +1 -1
  44. package/dist/types/src/components/L0Menu.d.ts +8 -0
  45. package/dist/types/src/components/L0Menu.d.ts.map +1 -0
  46. package/dist/types/src/components/L1Panels.d.ts +13 -0
  47. package/dist/types/src/components/L1Panels.d.ts.map +1 -0
  48. package/dist/types/src/components/NavTree.d.ts +2 -22
  49. package/dist/types/src/components/NavTree.d.ts.map +1 -1
  50. package/dist/types/src/components/NavTree.stories.d.ts +2 -2
  51. package/dist/types/src/components/NavTree.stories.d.ts.map +1 -1
  52. package/dist/types/src/components/NavTreeContainer.d.ts +4 -3
  53. package/dist/types/src/components/NavTreeContainer.d.ts.map +1 -1
  54. package/dist/types/src/components/NavTreeContext.d.ts +4 -0
  55. package/dist/types/src/components/NavTreeContext.d.ts.map +1 -0
  56. package/dist/types/src/components/NavTreeItemAction.d.ts +6 -10
  57. package/dist/types/src/components/NavTreeItemAction.d.ts.map +1 -1
  58. package/dist/types/src/components/NavTreeItemAction.stories.d.ts +2 -7
  59. package/dist/types/src/components/NavTreeItemAction.stories.d.ts.map +1 -1
  60. package/dist/types/src/components/NavTreeItemColumns.d.ts +4 -0
  61. package/dist/types/src/components/NavTreeItemColumns.d.ts.map +1 -0
  62. package/dist/types/src/components/NotchStart.d.ts +1 -2
  63. package/dist/types/src/components/NotchStart.d.ts.map +1 -1
  64. package/dist/types/src/components/index.d.ts +3 -0
  65. package/dist/types/src/components/index.d.ts.map +1 -1
  66. package/dist/types/src/components/types.d.ts +26 -0
  67. package/dist/types/src/components/types.d.ts.map +1 -0
  68. package/dist/types/src/events.d.ts +4 -0
  69. package/dist/types/src/events.d.ts.map +1 -0
  70. package/dist/types/src/experimental/Tree.d.ts +8 -8
  71. package/dist/types/src/experimental/Tree.d.ts.map +1 -1
  72. package/dist/types/src/experimental/Tree.stories.d.ts +2 -3
  73. package/dist/types/src/experimental/Tree.stories.d.ts.map +1 -1
  74. package/dist/types/src/hooks.d.ts +3 -0
  75. package/dist/types/src/hooks.d.ts.map +1 -0
  76. package/dist/types/src/index.d.ts +3 -2
  77. package/dist/types/src/index.d.ts.map +1 -1
  78. package/dist/types/src/meta.d.ts +1 -2
  79. package/dist/types/src/meta.d.ts.map +1 -1
  80. package/dist/types/src/stories/Graph.stories.d.ts +2 -2
  81. package/dist/types/src/stories/Graph.stories.d.ts.map +1 -1
  82. package/dist/types/src/stories/StorybookNavTree.d.ts +3 -0
  83. package/dist/types/src/stories/StorybookNavTree.d.ts.map +1 -0
  84. package/dist/types/src/translations.d.ts +0 -7
  85. package/dist/types/src/translations.d.ts.map +1 -1
  86. package/dist/types/src/types.d.ts +3 -2
  87. package/dist/types/src/types.d.ts.map +1 -1
  88. package/dist/types/src/util.d.ts +9 -0
  89. package/dist/types/src/util.d.ts.map +1 -1
  90. package/dist/types/tsconfig.tsbuildinfo +1 -1
  91. package/package.json +34 -39
  92. package/src/NavTreePlugin.tsx +67 -291
  93. package/src/capabilities/app-graph-builder.ts +42 -0
  94. package/src/capabilities/capabilities.ts +19 -0
  95. package/src/capabilities/index.ts +13 -0
  96. package/src/capabilities/intent-resolver.ts +36 -0
  97. package/src/capabilities/keyboard.ts +54 -0
  98. package/src/capabilities/react-surface.tsx +56 -0
  99. package/src/capabilities/state.ts +97 -0
  100. package/src/components/CommandsDialog.tsx +3 -4
  101. package/src/components/CommandsTrigger.tsx +7 -5
  102. package/src/components/L0Menu.tsx +238 -0
  103. package/src/components/L1Panels.tsx +119 -0
  104. package/src/components/NavTree.stories.tsx +6 -6
  105. package/src/components/NavTree.tsx +26 -124
  106. package/src/components/NavTreeContainer.tsx +114 -45
  107. package/src/components/NavTreeContext.tsx +13 -0
  108. package/src/components/NavTreeItemAction.stories.tsx +0 -2
  109. package/src/components/NavTreeItemAction.tsx +58 -316
  110. package/src/components/NavTreeItemColumns.tsx +71 -0
  111. package/src/components/NotchStart.tsx +6 -5
  112. package/src/components/index.ts +3 -0
  113. package/src/components/types.ts +35 -0
  114. package/src/events.ts +11 -0
  115. package/src/hooks.ts +21 -0
  116. package/src/index.ts +3 -4
  117. package/src/meta.ts +1 -1
  118. package/src/stories/Graph.stories.tsx +6 -5
  119. package/src/stories/StorybookNavTree.tsx +63 -0
  120. package/src/translations.ts +0 -7
  121. package/src/types.ts +3 -2
  122. package/src/util.ts +56 -2
  123. package/dist/lib/browser/meta.mjs +0 -13
  124. package/dist/lib/browser/meta.mjs.map +0 -7
  125. package/dist/types/src/components/NavTreeFooter.d.ts +0 -6
  126. package/dist/types/src/components/NavTreeFooter.d.ts.map +0 -1
  127. package/src/components/NavTreeFooter.tsx +0 -159
@@ -0,0 +1,97 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { effect } from '@preact/signals-core';
6
+
7
+ import { Capabilities, contributes, type PluginsContext } from '@dxos/app-framework';
8
+ import { type ReactiveObject, create } from '@dxos/live-object';
9
+ import { Path } from '@dxos/react-ui-list';
10
+
11
+ import { NavTreeCapabilities } from './capabilities';
12
+ import { NAVTREE_PLUGIN } from '../meta';
13
+
14
+ const KEY = `${NAVTREE_PLUGIN}/state`;
15
+
16
+ const getInitialState = () => {
17
+ const stringified = localStorage.getItem(KEY);
18
+ if (!stringified) {
19
+ return;
20
+ }
21
+
22
+ try {
23
+ const cached: [string, { open: boolean; current: boolean }][] = JSON.parse(stringified);
24
+ return cached.map(
25
+ ([key, value]): [
26
+ string,
27
+ ReactiveObject<{
28
+ open: boolean;
29
+ current: boolean;
30
+ }>,
31
+ ] => [key, create({ open: value.open, current: false })],
32
+ );
33
+ } catch {}
34
+ };
35
+
36
+ export default (context: PluginsContext) => {
37
+ const layout = context.requestCapability(Capabilities.Layout);
38
+
39
+ // TODO(wittjosiah): This currently needs to be not a ReactiveObject at the root.
40
+ // If it is a ReactiveObject then React errors when initializing new paths because of state change during render.
41
+ // Ideally this could be a ReactiveObject but be able to access and update the root level without breaking render.
42
+ // Wrapping accesses and updates in `untracked` didn't seem to work in all cases.
43
+ const state = new Map<string, ReactiveObject<{ open: boolean; current: boolean }>>(
44
+ getInitialState() ?? [
45
+ // TODO(thure): Initialize these dynamically.
46
+ ['root', create({ open: true, current: false })],
47
+ ['root~dxos.org/plugin/space-spaces', create({ open: true, current: false })],
48
+ ['root~dxos.org/plugin/files', create({ open: true, current: false })],
49
+ ],
50
+ );
51
+
52
+ const getItem = (_path: string[]) => {
53
+ const path = Path.create(..._path);
54
+ const value = state.get(path) ?? create({ open: false, current: false });
55
+ if (!state.has(path)) {
56
+ state.set(path, value);
57
+ }
58
+
59
+ return value;
60
+ };
61
+
62
+ const setItem = (path: string[], key: 'open' | 'current', next: boolean) => {
63
+ const value = getItem(path);
64
+ value[key] = next;
65
+
66
+ localStorage.setItem(KEY, JSON.stringify(Array.from(state.entries())));
67
+ };
68
+
69
+ const isOpen = (path: string[]) => getItem(path).open;
70
+ const isCurrent = (path: string[]) => getItem(path).current;
71
+
72
+ let previous: string[] = [];
73
+ const unsubscribe = effect(() => {
74
+ const removed = previous.filter((id) => !layout.active.includes(id));
75
+ previous = layout.active;
76
+
77
+ // TODO(wittjosiah): This is setTimeout because there's a race between the keys be initialized.
78
+ // This could be avoided if the location was a path as well and not just an id.
79
+ setTimeout(() => {
80
+ removed.forEach((id) => {
81
+ const keys = Array.from(state.keys()).filter((key) => Path.last(key) === id);
82
+ keys.forEach((key) => {
83
+ setItem(Path.parts(key), 'current', false);
84
+ });
85
+ });
86
+
87
+ layout.active.forEach((id) => {
88
+ const keys = Array.from(new Set([...state.keys(), id])).filter((key) => Path.last(key) === id);
89
+ keys.forEach((key) => {
90
+ setItem(Path.parts(key), 'current', true);
91
+ });
92
+ });
93
+ });
94
+ });
95
+
96
+ return contributes(NavTreeCapabilities.State, { state, getItem, setItem, isOpen, isCurrent }, () => unsubscribe());
97
+ };
@@ -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='w-full h-full !rounded-none'
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>) => ({