@dxos/plugin-navtree 0.7.5-main.499c70c → 0.7.5-main.5ae2ba8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/app-graph-builder-BL7LRXCM.mjs +44 -0
- package/dist/lib/browser/app-graph-builder-BL7LRXCM.mjs.map +7 -0
- package/dist/lib/browser/chunk-AOAGODQB.mjs +15 -0
- package/dist/lib/browser/chunk-AOAGODQB.mjs.map +7 -0
- package/dist/lib/browser/chunk-GXNOX2XZ.mjs +1262 -0
- package/dist/lib/browser/chunk-GXNOX2XZ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-VAXG4OAG.mjs → chunk-KOXMEAOS.mjs} +3 -3
- package/dist/lib/browser/{chunk-VAXG4OAG.mjs.map → chunk-KOXMEAOS.mjs.map} +3 -3
- package/dist/lib/browser/index.mjs +108 -1199
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/intent-resolver-U25VBFH3.mjs +47 -0
- package/dist/lib/browser/intent-resolver-U25VBFH3.mjs.map +7 -0
- package/dist/lib/browser/keyboard-MUBRTPI5.mjs +46 -0
- package/dist/lib/browser/keyboard-MUBRTPI5.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-surface-SG4QBA2U.mjs +57 -0
- package/dist/lib/browser/react-surface-SG4QBA2U.mjs.map +7 -0
- package/dist/lib/browser/state-IEFQTUPG.mjs +108 -0
- package/dist/lib/browser/state-IEFQTUPG.mjs.map +7 -0
- package/dist/types/src/NavTreePlugin.d.ts +1 -3
- package/dist/types/src/NavTreePlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts +181 -0
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -0
- package/dist/types/src/capabilities/capabilities.d.ts +18 -0
- package/dist/types/src/capabilities/capabilities.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +251 -0
- package/dist/types/src/capabilities/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/intent-resolver.d.ts +4 -0
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -0
- package/dist/types/src/capabilities/keyboard.d.ts +4 -0
- package/dist/types/src/capabilities/keyboard.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +4 -0
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
- package/dist/types/src/capabilities/state.d.ts +17 -0
- package/dist/types/src/capabilities/state.d.ts.map +1 -0
- package/dist/types/src/components/CommandsDialog.d.ts +1 -2
- package/dist/types/src/components/CommandsDialog.d.ts.map +1 -1
- package/dist/types/src/components/CommandsTrigger.d.ts +1 -2
- package/dist/types/src/components/CommandsTrigger.d.ts.map +1 -1
- package/dist/types/src/components/HaloButton.d.ts +1 -2
- package/dist/types/src/components/HaloButton.d.ts.map +1 -1
- package/dist/types/src/components/HaloButton.stories.d.ts +1 -2
- package/dist/types/src/components/HaloButton.stories.d.ts.map +1 -1
- package/dist/types/src/components/L0Menu.d.ts +8 -0
- package/dist/types/src/components/L0Menu.d.ts.map +1 -0
- package/dist/types/src/components/L1Panels.d.ts +13 -0
- package/dist/types/src/components/L1Panels.d.ts.map +1 -0
- package/dist/types/src/components/NavTree.d.ts +2 -22
- package/dist/types/src/components/NavTree.d.ts.map +1 -1
- package/dist/types/src/components/NavTree.stories.d.ts +2 -2
- package/dist/types/src/components/NavTree.stories.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeContainer.d.ts +4 -3
- package/dist/types/src/components/NavTreeContainer.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeContext.d.ts +4 -0
- package/dist/types/src/components/NavTreeContext.d.ts.map +1 -0
- package/dist/types/src/components/NavTreeItemAction.d.ts +6 -10
- package/dist/types/src/components/NavTreeItemAction.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeItemAction.stories.d.ts +2 -7
- package/dist/types/src/components/NavTreeItemAction.stories.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeItemColumns.d.ts +4 -0
- package/dist/types/src/components/NavTreeItemColumns.d.ts.map +1 -0
- package/dist/types/src/components/NotchStart.d.ts +1 -2
- package/dist/types/src/components/NotchStart.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +3 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/types.d.ts +26 -0
- package/dist/types/src/components/types.d.ts.map +1 -0
- package/dist/types/src/events.d.ts +4 -0
- package/dist/types/src/events.d.ts.map +1 -0
- package/dist/types/src/experimental/Tree.d.ts +8 -8
- package/dist/types/src/experimental/Tree.d.ts.map +1 -1
- package/dist/types/src/experimental/Tree.stories.d.ts +2 -3
- package/dist/types/src/experimental/Tree.stories.d.ts.map +1 -1
- package/dist/types/src/hooks.d.ts +3 -0
- package/dist/types/src/hooks.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +3 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +1 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/stories/Graph.stories.d.ts +2 -2
- package/dist/types/src/stories/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/stories/StorybookNavTree.d.ts +3 -0
- package/dist/types/src/stories/StorybookNavTree.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +0 -7
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +3 -2
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +9 -0
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +34 -39
- package/src/NavTreePlugin.tsx +67 -291
- package/src/capabilities/app-graph-builder.ts +42 -0
- package/src/capabilities/capabilities.ts +19 -0
- package/src/capabilities/index.ts +13 -0
- package/src/capabilities/intent-resolver.ts +36 -0
- package/src/capabilities/keyboard.ts +54 -0
- package/src/capabilities/react-surface.tsx +56 -0
- package/src/capabilities/state.ts +97 -0
- package/src/components/CommandsDialog.tsx +3 -4
- package/src/components/CommandsTrigger.tsx +7 -5
- package/src/components/L0Menu.tsx +332 -0
- package/src/components/L1Panels.tsx +119 -0
- package/src/components/NavTree.stories.tsx +6 -6
- package/src/components/NavTree.tsx +26 -124
- package/src/components/NavTreeContainer.tsx +114 -45
- package/src/components/NavTreeContext.tsx +13 -0
- package/src/components/NavTreeItemAction.stories.tsx +0 -2
- package/src/components/NavTreeItemAction.tsx +58 -316
- package/src/components/NavTreeItemColumns.tsx +71 -0
- package/src/components/NotchStart.tsx +6 -5
- package/src/components/index.ts +3 -0
- package/src/components/types.ts +35 -0
- package/src/events.ts +11 -0
- package/src/hooks.ts +21 -0
- package/src/index.ts +3 -4
- package/src/meta.ts +1 -1
- package/src/stories/Graph.stories.tsx +6 -5
- package/src/stories/StorybookNavTree.tsx +63 -0
- package/src/translations.ts +0 -7
- package/src/types.ts +3 -2
- package/src/util.ts +56 -2
- package/dist/lib/browser/meta.mjs +0 -13
- package/dist/lib/browser/meta.mjs.map +0 -7
- package/dist/types/src/components/NavTreeFooter.d.ts +0 -6
- package/dist/types/src/components/NavTreeFooter.d.ts.map +0 -1
- package/src/components/NavTreeFooter.tsx +0 -159
|
@@ -2,138 +2,40 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React, {
|
|
5
|
+
import React, { useMemo } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { Tree, type TreeProps } from '@dxos/react-ui-list';
|
|
10
|
-
import { type MaybePromise } from '@dxos/util';
|
|
7
|
+
import { Tabs } from '@dxos/react-ui-tabs';
|
|
8
|
+
import { byPosition } from '@dxos/util';
|
|
11
9
|
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
10
|
+
import { L0Menu } from './L0Menu';
|
|
11
|
+
import { L1Panels } from './L1Panels';
|
|
12
|
+
import { useNavTreeContext } from './NavTreeContext';
|
|
13
|
+
import { type NavTreeProps } from './types';
|
|
14
|
+
import { useLoadDescendents } from '../hooks';
|
|
15
15
|
|
|
16
16
|
export const NAV_TREE_ITEM = 'NavTreeItem';
|
|
17
17
|
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<NavTreeColumns
|
|
29
|
-
path={path}
|
|
30
|
-
node={item}
|
|
31
|
-
getActions={getActions}
|
|
32
|
-
open={open}
|
|
33
|
-
menuOpen={menuOpen}
|
|
34
|
-
setMenuOpen={setMenuOpen}
|
|
35
|
-
loadDescendents={loadDescendents}
|
|
36
|
-
renderItemEnd={renderItemEnd}
|
|
37
|
-
popoverAnchorId={popoverAnchorId}
|
|
38
|
-
/>
|
|
39
|
-
);
|
|
40
|
-
},
|
|
41
|
-
[renderItemEnd, popoverAnchorId, loadDescendents],
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<Tree
|
|
46
|
-
{...props}
|
|
47
|
-
draggable
|
|
48
|
-
gridTemplateColumns='[tree-row-start] 1fr min-content min-content min-content [tree-row-end]'
|
|
49
|
-
renderColumns={renderColumns}
|
|
50
|
-
/>
|
|
18
|
+
export const NavTree = ({ id, root }: NavTreeProps) => {
|
|
19
|
+
const { tab, getItems, onBack } = useNavTreeContext();
|
|
20
|
+
const topLevelActions = getItems(root, 'item').toSorted((a, b) => byPosition(a.properties, b.properties));
|
|
21
|
+
const topLevelCollections = getItems(root, 'collection');
|
|
22
|
+
const topLevelWorkspaces = getItems(root, 'workspace');
|
|
23
|
+
const topLevelNavigation = getItems(root, 'navigation');
|
|
24
|
+
const l0Items = useMemo(
|
|
25
|
+
() => [...topLevelActions, ...topLevelCollections, ...topLevelWorkspaces, ...topLevelNavigation],
|
|
26
|
+
[topLevelActions, topLevelCollections, topLevelWorkspaces, topLevelNavigation],
|
|
51
27
|
);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
type NavTreeColumnsProps = {
|
|
55
|
-
path: string[];
|
|
56
|
-
node: Node;
|
|
57
|
-
getActions: (node: Node) => FlattenedActions;
|
|
58
|
-
open: boolean;
|
|
59
|
-
menuOpen: boolean;
|
|
60
|
-
setMenuOpen: (open: boolean) => void;
|
|
61
|
-
loadDescendents?: (node: Node) => MaybePromise<void>;
|
|
62
|
-
renderItemEnd?: FC<{ node: Node; open: boolean }>;
|
|
63
|
-
popoverAnchorId?: string;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const NavTreeColumns = ({
|
|
67
|
-
path,
|
|
68
|
-
node,
|
|
69
|
-
getActions,
|
|
70
|
-
open,
|
|
71
|
-
menuOpen,
|
|
72
|
-
setMenuOpen,
|
|
73
|
-
loadDescendents,
|
|
74
|
-
renderItemEnd: ItemEnd,
|
|
75
|
-
popoverAnchorId,
|
|
76
|
-
}: NavTreeColumnsProps) => {
|
|
77
|
-
const { t } = useTranslation(NAVTREE_PLUGIN);
|
|
78
|
-
|
|
79
|
-
const level = path.length - 2;
|
|
80
|
-
|
|
81
|
-
const { actions: _actions, groupedActions } = getActions(node);
|
|
82
|
-
const [primaryAction, ...secondaryActions] = _actions.toSorted((a, b) =>
|
|
83
|
-
a.properties?.disposition === 'toolbar' ? -1 : 1,
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
const actions = (primaryAction?.properties?.disposition === 'toolbar' ? secondaryActions : _actions)
|
|
87
|
-
.flatMap((action) => (isAction(action) ? [action] : []))
|
|
88
|
-
.filter((action) => !action.properties?.hidden);
|
|
89
|
-
|
|
90
|
-
const ActionRoot = popoverAnchorId === `dxos.org/ui/${NAV_TREE_ITEM}/${node.id}` ? Popover.Anchor : Fragment;
|
|
28
|
+
const pinnedItems = getItems(root, 'pin-end').toSorted((a, b) => byPosition(a.properties, b.properties));
|
|
29
|
+
const topLevelItems = useMemo(() => [...l0Items, ...pinnedItems], [l0Items, pinnedItems]);
|
|
91
30
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const frame = requestAnimationFrame(() => {
|
|
95
|
-
void loadDescendents?.(node);
|
|
96
|
-
if (primaryAction && !isAction(primaryAction)) {
|
|
97
|
-
void loadDescendents?.(primaryAction);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
return () => cancelAnimationFrame(frame);
|
|
101
|
-
}, [primaryAction]);
|
|
31
|
+
useLoadDescendents(root);
|
|
32
|
+
const path = useMemo(() => [id], [id]);
|
|
102
33
|
|
|
103
34
|
return (
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
icon={primaryAction.properties?.icon ?? 'ph--placeholder--regular'}
|
|
110
|
-
parent={node}
|
|
111
|
-
monolithic={isAction(primaryAction)}
|
|
112
|
-
menuActions={isAction(primaryAction) ? [primaryAction] : groupedActions[primaryAction.id]}
|
|
113
|
-
menuType={primaryAction.properties?.menuType}
|
|
114
|
-
caller={NAV_TREE_ITEM}
|
|
115
|
-
/>
|
|
116
|
-
) : (
|
|
117
|
-
<Treegrid.Cell />
|
|
118
|
-
)}
|
|
119
|
-
<ActionRoot>
|
|
120
|
-
{actions.length > 0 ? (
|
|
121
|
-
<NavTreeItemAction
|
|
122
|
-
testId={`navtree.treeItem.actionsLevel${level}`}
|
|
123
|
-
label={t('tree item actions label')}
|
|
124
|
-
icon='ph--dots-three-vertical--regular'
|
|
125
|
-
parent={node}
|
|
126
|
-
menuActions={actions}
|
|
127
|
-
menuType='dropdown'
|
|
128
|
-
caller={NAV_TREE_ITEM}
|
|
129
|
-
menuOpen={menuOpen}
|
|
130
|
-
onChangeMenuOpen={setMenuOpen}
|
|
131
|
-
/>
|
|
132
|
-
) : (
|
|
133
|
-
<Treegrid.Cell />
|
|
134
|
-
)}
|
|
135
|
-
</ActionRoot>
|
|
136
|
-
{ItemEnd && <ItemEnd node={node} open={open} />}
|
|
137
|
-
</>
|
|
35
|
+
// NOTE(thure): 74px (rather than rem) is intentional in order to match the size of macOS windowing controls
|
|
36
|
+
<Tabs.Root value={tab} orientation='vertical' verticalVariant='stateless' classNames='relative'>
|
|
37
|
+
<L0Menu topLevelItems={l0Items} pinnedItems={pinnedItems} path={path} parent={root} />
|
|
38
|
+
<L1Panels topLevelItems={topLevelItems} path={path} currentItemId={tab} onBack={onBack} />
|
|
39
|
+
</Tabs.Root>
|
|
138
40
|
);
|
|
139
41
|
};
|
|
@@ -5,20 +5,28 @@
|
|
|
5
5
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
6
6
|
import { extractInstruction, type Instruction } from '@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item';
|
|
7
7
|
import { untracked } from '@preact/signals-core';
|
|
8
|
-
import React, { memo, useCallback, useEffect } from 'react';
|
|
8
|
+
import React, { memo, useCallback, useEffect, useMemo } from 'react';
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
createIntent,
|
|
12
|
+
LayoutAction,
|
|
13
|
+
Surface,
|
|
14
|
+
useAppGraph,
|
|
15
|
+
useCapability,
|
|
16
|
+
useIntentDispatcher,
|
|
17
|
+
useLayout,
|
|
18
|
+
} from '@dxos/app-framework';
|
|
11
19
|
import { isAction, isActionLike, type Node } from '@dxos/app-graph';
|
|
12
|
-
import { useGraph } from '@dxos/plugin-graph';
|
|
13
20
|
import { isEchoObject, isSpace } from '@dxos/react-client/echo';
|
|
14
|
-
import { useMediaQuery
|
|
21
|
+
import { useMediaQuery } from '@dxos/react-ui';
|
|
15
22
|
import { isTreeData, type TreeData, type PropsFromTreeItem } from '@dxos/react-ui-list';
|
|
16
23
|
import { mx } from '@dxos/react-ui-theme';
|
|
17
24
|
import { arrayMove } from '@dxos/util';
|
|
18
25
|
|
|
19
|
-
import { NAV_TREE_ITEM, NavTree
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
26
|
+
import { NAV_TREE_ITEM, NavTree } from './NavTree';
|
|
27
|
+
import { NavTreeContext } from './NavTreeContext';
|
|
28
|
+
import { type NavTreeContextValue } from './types';
|
|
29
|
+
import { NavTreeCapabilities } from '../capabilities';
|
|
22
30
|
import { type NavTreeItemGraphNode } from '../types';
|
|
23
31
|
import {
|
|
24
32
|
expandActions,
|
|
@@ -27,6 +35,7 @@ import {
|
|
|
27
35
|
getChildren,
|
|
28
36
|
getParent,
|
|
29
37
|
resolveMigrationOperation,
|
|
38
|
+
expandChildrenAndActions,
|
|
30
39
|
} from '../util';
|
|
31
40
|
|
|
32
41
|
// TODO(thure): Is NavTree truly authoritative in this regard?
|
|
@@ -38,24 +47,29 @@ const renderItemEnd = ({ node, open }: { node: Node; open: boolean }) => (
|
|
|
38
47
|
|
|
39
48
|
export type NavTreeContainerProps = {
|
|
40
49
|
popoverAnchorId?: string;
|
|
41
|
-
|
|
50
|
+
topbar?: boolean;
|
|
51
|
+
} & Pick<NavTreeContextValue, 'tab'>;
|
|
42
52
|
|
|
43
|
-
export const NavTreeContainer = memo(({
|
|
44
|
-
const { closeNavigationSidebar } = useSidebars(NAVTREE_PLUGIN);
|
|
53
|
+
export const NavTreeContainer = memo(({ tab, popoverAnchorId, topbar }: NavTreeContainerProps) => {
|
|
45
54
|
const [isLg] = useMediaQuery('lg', { ssr: false });
|
|
46
55
|
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
47
|
-
const { graph } =
|
|
56
|
+
const { graph } = useAppGraph();
|
|
57
|
+
const layout = useLayout();
|
|
58
|
+
const { isOpen, isCurrent, setItem } = useCapability(NavTreeCapabilities.State);
|
|
48
59
|
|
|
49
60
|
const getActions = useCallback((node: Node) => naturalGetActions(graph, node), [graph]);
|
|
50
61
|
|
|
51
62
|
const getItems = useCallback(
|
|
52
|
-
(node?: Node) => {
|
|
63
|
+
(node?: Node, disposition?: string) => {
|
|
53
64
|
return graph.nodes(node ?? graph.root, {
|
|
54
65
|
filter: (node): node is Node => {
|
|
55
66
|
return untracked(() => {
|
|
56
|
-
const action =
|
|
57
|
-
|
|
58
|
-
|
|
67
|
+
const action = isAction(node);
|
|
68
|
+
if (!disposition) {
|
|
69
|
+
return !action || node.properties.disposition === 'item';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return node.properties.disposition === disposition;
|
|
59
73
|
});
|
|
60
74
|
},
|
|
61
75
|
});
|
|
@@ -97,6 +111,33 @@ export const NavTreeContainer = memo(({ isCurrent, popoverAnchorId, ...props }:
|
|
|
97
111
|
[graph],
|
|
98
112
|
);
|
|
99
113
|
|
|
114
|
+
const onOpenChange = useCallback(
|
|
115
|
+
({ item: { id }, path, open }: { item: Node; path: string[]; open: boolean }) => {
|
|
116
|
+
// TODO(thure): This might become a localstorage leak; openItemIds that no longer exist should be removed from this map.
|
|
117
|
+
setItem(path, 'open', open);
|
|
118
|
+
|
|
119
|
+
if (graph) {
|
|
120
|
+
const node = graph.findNode(id);
|
|
121
|
+
return node && expandChildrenAndActions(graph, node as NavTreeItemGraphNode);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
[graph],
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const onTabChange = useCallback(
|
|
128
|
+
async (node: NavTreeItemGraphNode) => {
|
|
129
|
+
await dispatch(createIntent(LayoutAction.SwitchWorkspace, { part: 'workspace', subject: node.id }));
|
|
130
|
+
// Open the first item if the workspace is empty.
|
|
131
|
+
if (layout.active.length === 0) {
|
|
132
|
+
const [item] = getItems(node).filter((node) => !isActionLike(node));
|
|
133
|
+
if (item && item.data) {
|
|
134
|
+
await dispatch(createIntent(LayoutAction.Open, { part: 'main', subject: [item.id] }));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
[dispatch, layout],
|
|
139
|
+
);
|
|
140
|
+
|
|
100
141
|
const canDrop = useCallback((source: TreeData, target: TreeData) => {
|
|
101
142
|
const sourceNode = source.item as Node;
|
|
102
143
|
const targetNode = target.item as Node;
|
|
@@ -124,11 +165,19 @@ export const NavTreeContainer = memo(({ isCurrent, popoverAnchorId, ...props }:
|
|
|
124
165
|
|
|
125
166
|
const current = isCurrent(path, node);
|
|
126
167
|
if (!current) {
|
|
127
|
-
void dispatch(
|
|
168
|
+
void dispatch(
|
|
169
|
+
createIntent(LayoutAction.Open, {
|
|
170
|
+
part: 'main',
|
|
171
|
+
subject: [node.id],
|
|
172
|
+
options: { key: node.properties.key },
|
|
173
|
+
}),
|
|
174
|
+
);
|
|
128
175
|
} else if (option) {
|
|
129
|
-
void dispatch(
|
|
176
|
+
void dispatch(
|
|
177
|
+
createIntent(LayoutAction.Close, { part: 'main', subject: [node.id], options: { state: false } }),
|
|
178
|
+
);
|
|
130
179
|
} else {
|
|
131
|
-
void dispatch(createIntent(LayoutAction.ScrollIntoView, {
|
|
180
|
+
void dispatch(createIntent(LayoutAction.ScrollIntoView, { part: 'current', subject: node.id }));
|
|
132
181
|
}
|
|
133
182
|
|
|
134
183
|
const defaultAction = graph.actions(node).find((action) => action.properties?.disposition === 'default');
|
|
@@ -137,10 +186,15 @@ export const NavTreeContainer = memo(({ isCurrent, popoverAnchorId, ...props }:
|
|
|
137
186
|
}
|
|
138
187
|
|
|
139
188
|
if (!isLg) {
|
|
140
|
-
|
|
189
|
+
void dispatch(createIntent(LayoutAction.UpdateSidebar, { part: 'sidebar', options: { state: 'closed' } }));
|
|
141
190
|
}
|
|
142
191
|
},
|
|
143
|
-
[graph, dispatch, isCurrent, isLg
|
|
192
|
+
[graph, dispatch, isCurrent, isLg],
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
const onBack = useCallback(
|
|
196
|
+
() => dispatch(createIntent(LayoutAction.RevertWorkspace, { part: 'workspace', options: { revert: true } })),
|
|
197
|
+
[dispatch],
|
|
144
198
|
);
|
|
145
199
|
|
|
146
200
|
// TODO(wittjosiah): Factor out hook.
|
|
@@ -202,31 +256,46 @@ export const NavTreeContainer = memo(({ isCurrent, popoverAnchorId, ...props }:
|
|
|
202
256
|
});
|
|
203
257
|
}, [graph]);
|
|
204
258
|
|
|
259
|
+
const navTreeContextValue = useMemo(
|
|
260
|
+
() => ({
|
|
261
|
+
tab,
|
|
262
|
+
onTabChange,
|
|
263
|
+
onBack,
|
|
264
|
+
getActions,
|
|
265
|
+
loadDescendents,
|
|
266
|
+
renderItemEnd,
|
|
267
|
+
popoverAnchorId,
|
|
268
|
+
topbar,
|
|
269
|
+
getItems,
|
|
270
|
+
getProps,
|
|
271
|
+
isCurrent,
|
|
272
|
+
isOpen,
|
|
273
|
+
onOpenChange,
|
|
274
|
+
canDrop,
|
|
275
|
+
onSelect: handleSelect,
|
|
276
|
+
}),
|
|
277
|
+
[
|
|
278
|
+
tab,
|
|
279
|
+
onTabChange,
|
|
280
|
+
onBack,
|
|
281
|
+
getActions,
|
|
282
|
+
loadDescendents,
|
|
283
|
+
renderItemEnd,
|
|
284
|
+
popoverAnchorId,
|
|
285
|
+
topbar,
|
|
286
|
+
getItems,
|
|
287
|
+
getProps,
|
|
288
|
+
isCurrent,
|
|
289
|
+
isOpen,
|
|
290
|
+
onOpenChange,
|
|
291
|
+
canDrop,
|
|
292
|
+
handleSelect,
|
|
293
|
+
],
|
|
294
|
+
);
|
|
295
|
+
|
|
205
296
|
return (
|
|
206
|
-
<
|
|
207
|
-
{
|
|
208
|
-
|
|
209
|
-
<Surface role='search-input' limit={1} />
|
|
210
|
-
</div>
|
|
211
|
-
|
|
212
|
-
{/* TODO(thure): What gives this an inline `overflow: initial`? */}
|
|
213
|
-
<div role='none' className='border-be border-separator !overflow-y-auto'>
|
|
214
|
-
<NavTree
|
|
215
|
-
id={graph.root.id}
|
|
216
|
-
getActions={getActions}
|
|
217
|
-
getItems={getItems}
|
|
218
|
-
getProps={getProps}
|
|
219
|
-
isCurrent={isCurrent}
|
|
220
|
-
loadDescendents={loadDescendents}
|
|
221
|
-
renderItemEnd={renderItemEnd}
|
|
222
|
-
popoverAnchorId={popoverAnchorId}
|
|
223
|
-
canDrop={canDrop}
|
|
224
|
-
onSelect={handleSelect}
|
|
225
|
-
{...props}
|
|
226
|
-
/>
|
|
227
|
-
</div>
|
|
228
|
-
|
|
229
|
-
<NavTreeFooter />
|
|
230
|
-
</div>
|
|
297
|
+
<NavTreeContext.Provider value={navTreeContextValue}>
|
|
298
|
+
<NavTree root={graph.root} id={graph.root.id} />
|
|
299
|
+
</NavTreeContext.Provider>
|
|
231
300
|
);
|
|
232
301
|
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { createContext, useContext } from 'react';
|
|
6
|
+
|
|
7
|
+
import { raise } from '@dxos/debug';
|
|
8
|
+
|
|
9
|
+
import { type NavTreeContextValue } from './types';
|
|
10
|
+
|
|
11
|
+
export const NavTreeContext = createContext<NavTreeContextValue | null>(null);
|
|
12
|
+
|
|
13
|
+
export const useNavTreeContext = () => useContext(NavTreeContext) ?? raise(new Error('NavTreeContext not found'));
|