@dxos/plugin-navtree 0.7.4 → 0.7.5-labs.071a3e2
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-54MPRXMH.mjs +1109 -0
- package/dist/lib/browser/chunk-54MPRXMH.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-PSVCPL4T.mjs → chunk-KOXMEAOS.mjs} +5 -3
- package/dist/lib/browser/chunk-KOXMEAOS.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +107 -1218
- 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-LNRTNSM6.mjs +57 -0
- package/dist/lib/browser/react-surface-LNRTNSM6.mjs.map +7 -0
- package/dist/lib/browser/state-65TQKYX7.mjs +108 -0
- package/dist/lib/browser/state-65TQKYX7.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.map +1 -1
- package/dist/types/src/components/CommandsTrigger.d.ts.map +1 -1
- package/dist/types/src/components/L0Menu.d.ts +9 -0
- package/dist/types/src/components/L0Menu.d.ts.map +1 -0
- package/dist/types/src/components/L1Panels.d.ts +8 -0
- package/dist/types/src/components/L1Panels.d.ts.map +1 -0
- package/dist/types/src/components/NavTree.d.ts +3 -20
- 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 +4 -8
- package/dist/types/src/components/NavTreeItemAction.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeItemAction.stories.d.ts +0 -5
- 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.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 +25 -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/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 +2 -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 +4 -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 -0
- package/package.json +34 -39
- package/src/NavTreePlugin.tsx +68 -287
- 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 +4 -5
- package/src/components/CommandsTrigger.tsx +13 -8
- package/src/components/L0Menu.tsx +210 -0
- package/src/components/L1Panels.tsx +100 -0
- package/src/components/NavTree.stories.tsx +5 -5
- package/src/components/NavTree.tsx +26 -121
- package/src/components/NavTreeContainer.tsx +109 -69
- 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 +9 -8
- package/src/components/index.ts +3 -0
- package/src/components/types.ts +33 -0
- package/src/events.ts +11 -0
- package/src/hooks.ts +21 -0
- package/src/index.ts +3 -4
- package/src/meta.ts +3 -1
- package/src/stories/Graph.stories.tsx +5 -4
- package/src/stories/StorybookNavTree.tsx +63 -0
- package/src/translations.ts +0 -7
- package/src/types.ts +3 -2
- package/src/util.ts +54 -0
- package/dist/lib/browser/chunk-PSVCPL4T.mjs.map +0 -7
- package/dist/lib/browser/meta.mjs +0 -11
- 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 -158
|
@@ -2,135 +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
|
-
menuOpen={menuOpen}
|
|
33
|
-
setMenuOpen={setMenuOpen}
|
|
34
|
-
loadDescendents={loadDescendents}
|
|
35
|
-
renderItemEnd={renderItemEnd}
|
|
36
|
-
popoverAnchorId={popoverAnchorId}
|
|
37
|
-
/>
|
|
38
|
-
);
|
|
39
|
-
},
|
|
40
|
-
[renderItemEnd, popoverAnchorId, loadDescendents],
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
<Tree
|
|
45
|
-
{...props}
|
|
46
|
-
draggable
|
|
47
|
-
gridTemplateColumns='[tree-row-start] 1fr min-content min-content min-content [tree-row-end]'
|
|
48
|
-
renderColumns={renderColumns}
|
|
49
|
-
/>
|
|
18
|
+
export const NavTree = ({ id, root }: NavTreeProps) => {
|
|
19
|
+
const { getItems, tab } = useNavTreeContext();
|
|
20
|
+
const topLevelActions = getItems(root, 'item');
|
|
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],
|
|
50
27
|
);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
type NavTreeColumnsProps = {
|
|
54
|
-
path: string[];
|
|
55
|
-
node: Node;
|
|
56
|
-
getActions: (node: Node) => FlattenedActions;
|
|
57
|
-
menuOpen: boolean;
|
|
58
|
-
setMenuOpen: (open: boolean) => void;
|
|
59
|
-
loadDescendents?: (node: Node) => MaybePromise<void>;
|
|
60
|
-
renderItemEnd?: FC<{ node: Node }>;
|
|
61
|
-
popoverAnchorId?: string;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const NavTreeColumns = ({
|
|
65
|
-
path,
|
|
66
|
-
node,
|
|
67
|
-
getActions,
|
|
68
|
-
menuOpen,
|
|
69
|
-
setMenuOpen,
|
|
70
|
-
loadDescendents,
|
|
71
|
-
renderItemEnd: ItemEnd,
|
|
72
|
-
popoverAnchorId,
|
|
73
|
-
}: NavTreeColumnsProps) => {
|
|
74
|
-
const { t } = useTranslation(NAVTREE_PLUGIN);
|
|
75
|
-
|
|
76
|
-
const level = path.length - 2;
|
|
77
|
-
|
|
78
|
-
const { actions: _actions, groupedActions } = getActions(node);
|
|
79
|
-
const [primaryAction, ...secondaryActions] = _actions.toSorted((a, b) =>
|
|
80
|
-
a.properties?.disposition === 'toolbar' ? -1 : 1,
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
const actions = (primaryAction?.properties?.disposition === 'toolbar' ? secondaryActions : _actions)
|
|
84
|
-
.flatMap((action) => (isAction(action) ? [action] : []))
|
|
85
|
-
.filter((action) => !action.properties?.hidden);
|
|
86
|
-
|
|
87
|
-
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]);
|
|
88
30
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const frame = requestAnimationFrame(() => {
|
|
92
|
-
void loadDescendents?.(node);
|
|
93
|
-
if (primaryAction && !isAction(primaryAction)) {
|
|
94
|
-
void loadDescendents?.(primaryAction);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
return () => cancelAnimationFrame(frame);
|
|
98
|
-
}, [primaryAction]);
|
|
31
|
+
useLoadDescendents(root);
|
|
32
|
+
const path = useMemo(() => [id], [id]);
|
|
99
33
|
|
|
100
34
|
return (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
icon={primaryAction.properties?.icon ?? 'ph--placeholder--regular'}
|
|
107
|
-
parent={node}
|
|
108
|
-
monolithic={isAction(primaryAction)}
|
|
109
|
-
menuActions={isAction(primaryAction) ? [primaryAction] : groupedActions[primaryAction.id]}
|
|
110
|
-
menuType={primaryAction.properties?.menuType}
|
|
111
|
-
caller={NAV_TREE_ITEM}
|
|
112
|
-
/>
|
|
113
|
-
) : (
|
|
114
|
-
<Treegrid.Cell />
|
|
115
|
-
)}
|
|
116
|
-
<ActionRoot>
|
|
117
|
-
{actions.length > 0 ? (
|
|
118
|
-
<NavTreeItemAction
|
|
119
|
-
testId={`navtree.treeItem.actionsLevel${level}`}
|
|
120
|
-
label={t('tree item actions label')}
|
|
121
|
-
icon='ph--dots-three-vertical--regular'
|
|
122
|
-
parent={node}
|
|
123
|
-
menuActions={actions}
|
|
124
|
-
menuType='dropdown'
|
|
125
|
-
caller={NAV_TREE_ITEM}
|
|
126
|
-
menuOpen={menuOpen}
|
|
127
|
-
onChangeMenuOpen={setMenuOpen}
|
|
128
|
-
/>
|
|
129
|
-
) : (
|
|
130
|
-
<Treegrid.Cell />
|
|
131
|
-
)}
|
|
132
|
-
</ActionRoot>
|
|
133
|
-
{ItemEnd && <ItemEnd node={node} />}
|
|
134
|
-
</>
|
|
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} />
|
|
39
|
+
</Tabs.Root>
|
|
135
40
|
);
|
|
136
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 {
|
|
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,35 +35,41 @@ 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?
|
|
33
42
|
export const NODE_TYPE = 'dxos/app-graph/node';
|
|
34
43
|
|
|
35
|
-
const renderItemEnd = ({ node }: { node: Node }) => (
|
|
36
|
-
<Surface role='navtree-item-end' data={{
|
|
44
|
+
const renderItemEnd = ({ node, open }: { node: Node; open: boolean }) => (
|
|
45
|
+
<Surface role='navtree-item-end' data={{ id: node.id, subject: node.data, open }} limit={1} />
|
|
37
46
|
);
|
|
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
|
-
const dispatch = useIntentDispatcher();
|
|
47
|
-
const { graph } =
|
|
55
|
+
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
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
67
|
const action = isActionLike(node);
|
|
57
|
-
|
|
58
|
-
|
|
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) {
|
|
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,28 +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(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
});
|
|
168
|
+
void dispatch(
|
|
169
|
+
createIntent(LayoutAction.Open, {
|
|
170
|
+
part: 'main',
|
|
171
|
+
subject: [node.id],
|
|
172
|
+
options: { key: node.properties.key },
|
|
173
|
+
}),
|
|
174
|
+
);
|
|
135
175
|
} else if (option) {
|
|
136
|
-
void dispatch(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
activeParts: {
|
|
140
|
-
main: [node.id],
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
});
|
|
176
|
+
void dispatch(
|
|
177
|
+
createIntent(LayoutAction.Close, { part: 'main', subject: [node.id], options: { state: false } }),
|
|
178
|
+
);
|
|
144
179
|
} else {
|
|
145
|
-
void dispatch({
|
|
146
|
-
action: LayoutAction.SCROLL_INTO_VIEW,
|
|
147
|
-
data: { id: node.id },
|
|
148
|
-
});
|
|
180
|
+
void dispatch(createIntent(LayoutAction.ScrollIntoView, { part: 'current', subject: node.id }));
|
|
149
181
|
}
|
|
150
182
|
|
|
151
183
|
const defaultAction = graph.actions(node).find((action) => action.properties?.disposition === 'default');
|
|
@@ -154,10 +186,10 @@ export const NavTreeContainer = memo(({ isCurrent, popoverAnchorId, ...props }:
|
|
|
154
186
|
}
|
|
155
187
|
|
|
156
188
|
if (!isLg) {
|
|
157
|
-
|
|
189
|
+
void dispatch(createIntent(LayoutAction.UpdateSidebar, { part: 'sidebar', options: { state: 'closed' } }));
|
|
158
190
|
}
|
|
159
191
|
},
|
|
160
|
-
[graph, dispatch, isCurrent, isLg
|
|
192
|
+
[graph, dispatch, isCurrent, isLg],
|
|
161
193
|
);
|
|
162
194
|
|
|
163
195
|
// TODO(wittjosiah): Factor out hook.
|
|
@@ -219,36 +251,44 @@ export const NavTreeContainer = memo(({ isCurrent, popoverAnchorId, ...props }:
|
|
|
219
251
|
});
|
|
220
252
|
}, [graph]);
|
|
221
253
|
|
|
254
|
+
const navTreeContextValue = useMemo(
|
|
255
|
+
() => ({
|
|
256
|
+
tab,
|
|
257
|
+
onTabChange,
|
|
258
|
+
getActions,
|
|
259
|
+
loadDescendents,
|
|
260
|
+
renderItemEnd,
|
|
261
|
+
popoverAnchorId,
|
|
262
|
+
topbar,
|
|
263
|
+
getItems,
|
|
264
|
+
getProps,
|
|
265
|
+
isCurrent,
|
|
266
|
+
isOpen,
|
|
267
|
+
onOpenChange,
|
|
268
|
+
canDrop,
|
|
269
|
+
onSelect: handleSelect,
|
|
270
|
+
}),
|
|
271
|
+
[
|
|
272
|
+
tab,
|
|
273
|
+
onTabChange,
|
|
274
|
+
getActions,
|
|
275
|
+
loadDescendents,
|
|
276
|
+
renderItemEnd,
|
|
277
|
+
popoverAnchorId,
|
|
278
|
+
topbar,
|
|
279
|
+
getItems,
|
|
280
|
+
getProps,
|
|
281
|
+
isCurrent,
|
|
282
|
+
isOpen,
|
|
283
|
+
onOpenChange,
|
|
284
|
+
canDrop,
|
|
285
|
+
handleSelect,
|
|
286
|
+
],
|
|
287
|
+
);
|
|
288
|
+
|
|
222
289
|
return (
|
|
223
|
-
<
|
|
224
|
-
<
|
|
225
|
-
|
|
226
|
-
className='grid grid-cols-1 grid-rows-[var(--rail-size)_1fr_min-content] bs-full overflow-hidden'
|
|
227
|
-
>
|
|
228
|
-
{/* TODO(wittjosiah): Factor out surfaces to layout? */}
|
|
229
|
-
<div role='none' className='border-be border-separator'>
|
|
230
|
-
<Surface role='search-input' limit={1} />
|
|
231
|
-
</div>
|
|
232
|
-
|
|
233
|
-
{/* TODO(thure): What gives this an inline `overflow: initial`? */}
|
|
234
|
-
<div role='none' className='border-be border-separator !overflow-y-auto'>
|
|
235
|
-
<NavTree
|
|
236
|
-
id={graph.root.id}
|
|
237
|
-
getActions={getActions}
|
|
238
|
-
getItems={getItems}
|
|
239
|
-
getProps={getProps}
|
|
240
|
-
isCurrent={isCurrent}
|
|
241
|
-
loadDescendents={loadDescendents}
|
|
242
|
-
renderItemEnd={renderItemEnd}
|
|
243
|
-
popoverAnchorId={popoverAnchorId}
|
|
244
|
-
canDrop={canDrop}
|
|
245
|
-
onSelect={handleSelect}
|
|
246
|
-
{...props}
|
|
247
|
-
/>
|
|
248
|
-
</div>
|
|
249
|
-
|
|
250
|
-
<NavTreeFooter />
|
|
251
|
-
</div>
|
|
252
|
-
</ElevationProvider>
|
|
290
|
+
<NavTreeContext.Provider value={navTreeContextValue}>
|
|
291
|
+
<NavTree root={graph.root} id={graph.root.id} />
|
|
292
|
+
</NavTreeContext.Provider>
|
|
253
293
|
);
|
|
254
294
|
});
|
|
@@ -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'));
|