@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
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { lazy } from '@dxos/app-framework';
|
|
6
|
+
|
|
7
|
+
export const AppGraphBuilder = lazy(() => import('./app-graph-builder'));
|
|
8
|
+
export const IntentResolver = lazy(() => import('./intent-resolver'));
|
|
9
|
+
export const Keyboard = lazy(() => import('./keyboard'));
|
|
10
|
+
export const ReactSurface = lazy(() => import('./react-surface'));
|
|
11
|
+
export const State = lazy(() => import('./state'));
|
|
12
|
+
|
|
13
|
+
export * from './capabilities';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { contributes, type PluginsContext, Capabilities, createResolver, LayoutAction } from '@dxos/app-framework';
|
|
6
|
+
import { S } from '@dxos/echo-schema';
|
|
7
|
+
import { log } from '@dxos/log';
|
|
8
|
+
|
|
9
|
+
import { NavTreeCapabilities } from './capabilities';
|
|
10
|
+
|
|
11
|
+
export default (context: PluginsContext) =>
|
|
12
|
+
contributes(
|
|
13
|
+
Capabilities.IntentResolver,
|
|
14
|
+
createResolver({
|
|
15
|
+
intent: LayoutAction.UpdateLayout,
|
|
16
|
+
filter: (data): data is S.Schema.Type<typeof LayoutAction.Expose.fields.input> =>
|
|
17
|
+
S.is(LayoutAction.Expose.fields.input)(data),
|
|
18
|
+
resolve: async ({ subject }) => {
|
|
19
|
+
const { graph } = context.requestCapability(Capabilities.AppGraph);
|
|
20
|
+
const { getItem, setItem } = context.requestCapability(NavTreeCapabilities.State);
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const path = await graph.waitForPath({ target: subject }, { timeout: 1_000 });
|
|
24
|
+
[...Array(path.length)].forEach((_, index) => {
|
|
25
|
+
const subpath = path.slice(0, index);
|
|
26
|
+
const value = getItem(subpath);
|
|
27
|
+
if (!value.open) {
|
|
28
|
+
setItem(subpath, 'open', true);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
} catch {
|
|
32
|
+
log('Path to node not found', { subject });
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Capabilities as AppCapabilities, contributes, type PluginsContext } from '@dxos/app-framework';
|
|
6
|
+
import { Keyboard } from '@dxos/keyboard';
|
|
7
|
+
import { isAction } from '@dxos/plugin-graph';
|
|
8
|
+
import { getHostPlatform } from '@dxos/util';
|
|
9
|
+
|
|
10
|
+
import { KEY_BINDING } from '../meta';
|
|
11
|
+
|
|
12
|
+
export default (context: PluginsContext) => {
|
|
13
|
+
const { graph } = context.requestCapability(AppCapabilities.AppGraph);
|
|
14
|
+
|
|
15
|
+
// TODO(wittjosiah): Factor out.
|
|
16
|
+
// TODO(wittjosiah): Handle removal of actions.
|
|
17
|
+
const unsubscribe = graph.subscribeTraverse({
|
|
18
|
+
visitor: (node, path) => {
|
|
19
|
+
let shortcut: string | undefined;
|
|
20
|
+
if (typeof node.properties.keyBinding === 'object') {
|
|
21
|
+
const availablePlatforms = Object.keys(node.properties.keyBinding);
|
|
22
|
+
const platform = getHostPlatform();
|
|
23
|
+
shortcut = availablePlatforms.includes(platform)
|
|
24
|
+
? node.properties.keyBinding[platform]
|
|
25
|
+
: platform === 'ios'
|
|
26
|
+
? node.properties.keyBinding.macos // Fallback to macos if ios-specific bindings not provided.
|
|
27
|
+
: platform === 'linux' || platform === 'unknown'
|
|
28
|
+
? node.properties.keyBinding.windows // Fallback to windows if platform-specific bindings not provided.
|
|
29
|
+
: undefined;
|
|
30
|
+
} else {
|
|
31
|
+
shortcut = node.properties.keyBinding;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (shortcut && isAction(node)) {
|
|
35
|
+
Keyboard.singleton.getContext(path.slice(0, -1).join('/')).bind({
|
|
36
|
+
shortcut,
|
|
37
|
+
handler: () => {
|
|
38
|
+
void node.data({ node, caller: KEY_BINDING });
|
|
39
|
+
},
|
|
40
|
+
data: node.properties.label,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// TODO(burdon): Create context and plugin.
|
|
47
|
+
Keyboard.singleton.initialize();
|
|
48
|
+
Keyboard.singleton.setCurrentContext(graph.root.id);
|
|
49
|
+
|
|
50
|
+
return contributes(AppCapabilities.Null, null, () => {
|
|
51
|
+
unsubscribe();
|
|
52
|
+
Keyboard.singleton.destroy();
|
|
53
|
+
});
|
|
54
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
import { Capabilities, contributes, createSurface } from '@dxos/app-framework';
|
|
8
|
+
import { isGraphNode } from '@dxos/plugin-graph';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
CommandsDialogContent,
|
|
12
|
+
CommandsTrigger,
|
|
13
|
+
NavTreeDocumentTitle,
|
|
14
|
+
NotchStart,
|
|
15
|
+
NavTreeContainer,
|
|
16
|
+
} from '../components';
|
|
17
|
+
import { COMMANDS_DIALOG, NAVTREE_PLUGIN } from '../meta';
|
|
18
|
+
|
|
19
|
+
export default () =>
|
|
20
|
+
contributes(Capabilities.ReactSurface, [
|
|
21
|
+
createSurface({
|
|
22
|
+
id: COMMANDS_DIALOG,
|
|
23
|
+
role: 'dialog',
|
|
24
|
+
filter: (data): data is { props: { selected?: string } } => data.component === COMMANDS_DIALOG,
|
|
25
|
+
component: ({ data }) => <CommandsDialogContent {...data.props} />,
|
|
26
|
+
}),
|
|
27
|
+
createSurface({
|
|
28
|
+
id: `${NAVTREE_PLUGIN}/navigation`,
|
|
29
|
+
role: 'navigation',
|
|
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
|
+
),
|
|
39
|
+
}),
|
|
40
|
+
createSurface({
|
|
41
|
+
id: `${NAVTREE_PLUGIN}/document-title`,
|
|
42
|
+
role: 'document-title',
|
|
43
|
+
component: ({ data }) => <NavTreeDocumentTitle node={isGraphNode(data.subject) ? data.subject : undefined} />,
|
|
44
|
+
}),
|
|
45
|
+
createSurface({
|
|
46
|
+
id: `${NAVTREE_PLUGIN}/notch-start`,
|
|
47
|
+
role: 'notch-start',
|
|
48
|
+
component: () => <NotchStart />,
|
|
49
|
+
}),
|
|
50
|
+
createSurface({
|
|
51
|
+
id: `${NAVTREE_PLUGIN}/search-input`,
|
|
52
|
+
role: 'search-input',
|
|
53
|
+
position: 'fallback',
|
|
54
|
+
component: () => <CommandsTrigger />,
|
|
55
|
+
}),
|
|
56
|
+
]);
|
|
@@ -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-mosaic';
|
|
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 {
|
|
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';
|
|
@@ -19,8 +18,8 @@ import { KEY_BINDING, NAVTREE_PLUGIN } from '../meta';
|
|
|
19
18
|
export const CommandsDialogContent = ({ selected: initial }: { selected?: string }) => {
|
|
20
19
|
const { t } = useTranslation(NAVTREE_PLUGIN);
|
|
21
20
|
const [selected, setSelected] = useState<string | undefined>(initial);
|
|
22
|
-
const dispatch = useIntentDispatcher();
|
|
23
|
-
const { graph } =
|
|
21
|
+
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
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(
|
|
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 }));
|
|
@@ -5,24 +5,29 @@
|
|
|
5
5
|
import { MagnifyingGlass } from '@phosphor-icons/react';
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
|
-
import { LayoutAction,
|
|
8
|
+
import { createIntent, LayoutAction, useIntentDispatcher } from '@dxos/app-framework';
|
|
9
9
|
import { Button, useTranslation } from '@dxos/react-ui';
|
|
10
10
|
import { getSize } from '@dxos/react-ui-theme';
|
|
11
11
|
|
|
12
|
-
import { NAVTREE_PLUGIN } from '../meta';
|
|
12
|
+
import { COMMANDS_DIALOG, NAVTREE_PLUGIN } from '../meta';
|
|
13
13
|
|
|
14
14
|
// TODO(thure): Refactor to be handled by a more appropriate plugin.
|
|
15
15
|
export const CommandsTrigger = () => {
|
|
16
|
-
const { dispatch } =
|
|
16
|
+
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
17
17
|
const { t } = useTranslation(NAVTREE_PLUGIN);
|
|
18
18
|
return (
|
|
19
19
|
<Button
|
|
20
|
-
classNames='
|
|
20
|
+
classNames='m-1 pli-1 lg:pli-2'
|
|
21
21
|
onClick={() =>
|
|
22
|
-
dispatch(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
dispatch(
|
|
23
|
+
createIntent(LayoutAction.UpdateDialog, {
|
|
24
|
+
part: 'dialog',
|
|
25
|
+
subject: COMMANDS_DIALOG,
|
|
26
|
+
options: {
|
|
27
|
+
blockAlign: 'start',
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
)
|
|
26
31
|
}
|
|
27
32
|
>
|
|
28
33
|
<span className='text-description font-normal grow text-start'>{t('command list input placeholder')}</span>
|
|
@@ -0,0 +1,210 @@
|
|
|
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 { Icon, toLocalizedString, Tooltip, useMediaQuery, useSidebars, useTranslation } from '@dxos/react-ui';
|
|
10
|
+
import { Tabs } from '@dxos/react-ui-tabs';
|
|
11
|
+
import { mx } from '@dxos/react-ui-theme';
|
|
12
|
+
|
|
13
|
+
import { useNavTreeContext } from './NavTreeContext';
|
|
14
|
+
import { NotchStart } from './NotchStart';
|
|
15
|
+
import { useLoadDescendents } from '../hooks';
|
|
16
|
+
import { NAVTREE_PLUGIN } from '../meta';
|
|
17
|
+
import { getFirstTwoRenderableChars, l0ItemType } from '../util';
|
|
18
|
+
|
|
19
|
+
type L0ItemProps = {
|
|
20
|
+
item: Node<any>;
|
|
21
|
+
parent?: Node<any>;
|
|
22
|
+
path: string[];
|
|
23
|
+
pinned?: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const useL0ItemClick = ({ item, parent, path }: L0ItemProps, type: string) => {
|
|
27
|
+
const { tab, onTabChange, onSelect, isCurrent } = useNavTreeContext();
|
|
28
|
+
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
29
|
+
const { navigationSidebarState } = useSidebars(NAVTREE_PLUGIN);
|
|
30
|
+
const [isLg] = useMediaQuery('lg', { ssr: false });
|
|
31
|
+
|
|
32
|
+
return useCallback(
|
|
33
|
+
(event: MouseEvent) => {
|
|
34
|
+
switch (type) {
|
|
35
|
+
case 'tab':
|
|
36
|
+
// TODO(thure): This dispatch should rightly be in `onTabChange`, but that callback wasn’t reacting to changes
|
|
37
|
+
// to its dependencies.
|
|
38
|
+
void dispatch(
|
|
39
|
+
createIntent(LayoutAction.UpdateSidebar, {
|
|
40
|
+
part: 'sidebar',
|
|
41
|
+
options: {
|
|
42
|
+
state:
|
|
43
|
+
item.id === tab
|
|
44
|
+
? navigationSidebarState === 'expanded'
|
|
45
|
+
? isLg
|
|
46
|
+
? 'collapsed'
|
|
47
|
+
: 'closed'
|
|
48
|
+
: 'expanded'
|
|
49
|
+
: 'expanded',
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
return onTabChange?.(item);
|
|
54
|
+
case 'link':
|
|
55
|
+
return onSelect?.({ item, path, current: !isCurrent(path, item), option: event.altKey });
|
|
56
|
+
case 'action': {
|
|
57
|
+
const {
|
|
58
|
+
data: invoke,
|
|
59
|
+
properties: { caller },
|
|
60
|
+
} = item;
|
|
61
|
+
return invoke?.(caller ? { node: parent, caller } : { node: parent });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
[item, type, onSelect, isCurrent, parent, tab, navigationSidebarState, isLg, dispatch],
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const l0Breakpoints: Record<string, string> = {
|
|
70
|
+
lg: 'hidden lg:grid',
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const L0Item = ({ item, parent, path, pinned }: L0ItemProps) => {
|
|
74
|
+
const { t } = useTranslation(NAVTREE_PLUGIN);
|
|
75
|
+
const type = l0ItemType(item);
|
|
76
|
+
const itemPath = useMemo(() => [...path, item.id], [item.id, path]);
|
|
77
|
+
const { getProps } = useNavTreeContext();
|
|
78
|
+
const { id, testId } = getProps?.(item, path) ?? {};
|
|
79
|
+
const Root = type === 'collection' ? 'h2' : type === 'tab' ? Tabs.TabPrimitive : 'button';
|
|
80
|
+
const handleClick = useL0ItemClick({ item, path: itemPath, parent }, type);
|
|
81
|
+
const rootProps =
|
|
82
|
+
type === 'tab'
|
|
83
|
+
? { value: item.id, tabIndex: 0, onClick: handleClick, 'data-testid': testId, 'data-itemid': id }
|
|
84
|
+
: type !== 'collection'
|
|
85
|
+
? { onClick: handleClick, 'data-testid': testId, 'data-itemid': id }
|
|
86
|
+
: { onClick: handleClick };
|
|
87
|
+
const localizedString = toLocalizedString(item.properties.label, t);
|
|
88
|
+
const avatarValue = useMemo(
|
|
89
|
+
() => (type === 'tab' ? getFirstTwoRenderableChars(localizedString).join('') : []),
|
|
90
|
+
[type, item.properties.label, t],
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<Tooltip.Root delayDuration={0}>
|
|
95
|
+
<Tooltip.Trigger asChild>
|
|
96
|
+
<Root
|
|
97
|
+
{...(rootProps as any)}
|
|
98
|
+
data-type={type}
|
|
99
|
+
className={mx(
|
|
100
|
+
'group/l0i dx-focus-ring-group grid overflow-hidden relative data[type!="collection"]:cursor-pointer app-no-drag',
|
|
101
|
+
l0Breakpoints[item.properties.l0Breakpoint],
|
|
102
|
+
)}
|
|
103
|
+
>
|
|
104
|
+
{type !== 'collection' && (
|
|
105
|
+
<div
|
|
106
|
+
role='none'
|
|
107
|
+
className={mx(
|
|
108
|
+
'absolute -z-[1] group-hover/l0i:bg-input dx-focus-ring-group-indicator transition-colors',
|
|
109
|
+
type === 'tab' || pinned ? 'rounded' : 'rounded-full',
|
|
110
|
+
pinned ? 'bg-transparent inset-inline-3 inset-block-0' : 'bg-input inset-inline-3 inset-block-2',
|
|
111
|
+
)}
|
|
112
|
+
/>
|
|
113
|
+
)}
|
|
114
|
+
<div
|
|
115
|
+
role='none'
|
|
116
|
+
className='hidden group-aria-selected/l0i:block absolute inline-start-0 inset-block-4 is-1 bg-accentSurface rounded-ie'
|
|
117
|
+
/>
|
|
118
|
+
{type === 'tab' && item.properties.disposition !== 'pin-end' ? (
|
|
119
|
+
<span role='img' className='place-self-center text-3xl font-light'>
|
|
120
|
+
{avatarValue}
|
|
121
|
+
</span>
|
|
122
|
+
) : (
|
|
123
|
+
item.properties.icon && (
|
|
124
|
+
<Icon icon={item.properties.icon} size={pinned ? 5 : 7} classNames='place-self-center' />
|
|
125
|
+
)
|
|
126
|
+
)}
|
|
127
|
+
<span id={`${item.id}__label`} className='sr-only'>
|
|
128
|
+
{localizedString}
|
|
129
|
+
</span>
|
|
130
|
+
</Root>
|
|
131
|
+
</Tooltip.Trigger>
|
|
132
|
+
<Tooltip.Portal>
|
|
133
|
+
<Tooltip.Content side='right'>
|
|
134
|
+
{localizedString}
|
|
135
|
+
<Tooltip.Arrow />
|
|
136
|
+
</Tooltip.Content>
|
|
137
|
+
</Tooltip.Portal>
|
|
138
|
+
</Tooltip.Root>
|
|
139
|
+
);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const L0Collection = ({ item, path, parent }: L0ItemProps) => {
|
|
143
|
+
const navTreeContext = useNavTreeContext();
|
|
144
|
+
useLoadDescendents(item);
|
|
145
|
+
const collectionItems = navTreeContext.getItems(item);
|
|
146
|
+
const groupPath = useMemo(() => [...path, item.id], [item.id, path]);
|
|
147
|
+
const { id, testId } = navTreeContext.getProps?.(item, path) ?? {};
|
|
148
|
+
return (
|
|
149
|
+
<div
|
|
150
|
+
role='group'
|
|
151
|
+
className='contents group/l0c'
|
|
152
|
+
aria-labelledby={`${item.id}__label`}
|
|
153
|
+
data-itemid={id}
|
|
154
|
+
data-testid={testId}
|
|
155
|
+
>
|
|
156
|
+
{/* TODO(burdon): Option. */}
|
|
157
|
+
{/* <L0Item item={item} parent={parent} path={groupPath} /> */}
|
|
158
|
+
{collectionItems.map((collectionItem) => (
|
|
159
|
+
<L0Item key={collectionItem.id} item={collectionItem} parent={item} path={groupPath} />
|
|
160
|
+
))}
|
|
161
|
+
</div>
|
|
162
|
+
);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export const L0Menu = ({
|
|
166
|
+
topLevelItems,
|
|
167
|
+
pinnedItems,
|
|
168
|
+
parent,
|
|
169
|
+
path,
|
|
170
|
+
}: {
|
|
171
|
+
topLevelItems: Node<any>[];
|
|
172
|
+
pinnedItems: Node<any>[];
|
|
173
|
+
parent?: Node<any>;
|
|
174
|
+
path: string[];
|
|
175
|
+
}) => {
|
|
176
|
+
return (
|
|
177
|
+
<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'>
|
|
178
|
+
<div
|
|
179
|
+
role='none'
|
|
180
|
+
className='grid auto-rows-[calc(var(--l0-size)-.5rem)] min-bs-0 !overflow-y-auto plb-1 [body[data-platform="darwin"]_&]:pbs-[calc(30px+0.25rem)]'
|
|
181
|
+
>
|
|
182
|
+
{topLevelItems.map((item) => {
|
|
183
|
+
if (l0ItemType(item) === 'collection') {
|
|
184
|
+
return <L0Collection key={item.id} item={item} parent={parent} path={path} />;
|
|
185
|
+
} else {
|
|
186
|
+
return <L0Item key={item.id} item={item} parent={parent} path={path} />;
|
|
187
|
+
}
|
|
188
|
+
})}
|
|
189
|
+
</div>
|
|
190
|
+
<div role='none' className='grid grid-cols-1 auto-rows-[--rail-action] pbs-2'>
|
|
191
|
+
{pinnedItems
|
|
192
|
+
.filter((item) => l0ItemType(item) !== 'collection')
|
|
193
|
+
.map((item) => (
|
|
194
|
+
<L0Item key={item.id} item={item} parent={parent} path={path} pinned />
|
|
195
|
+
))}
|
|
196
|
+
</div>
|
|
197
|
+
<div role='none' className='grid p-2 app-no-drag'>
|
|
198
|
+
<NotchStart />
|
|
199
|
+
</div>
|
|
200
|
+
<div
|
|
201
|
+
role='none'
|
|
202
|
+
className='hidden [body[data-platform="darwin"]_&]:block absolute block-start-0 is-[calc(var(--l0-size)-1px)] bs-[calc(40px+0.25rem)]'
|
|
203
|
+
style={{
|
|
204
|
+
background:
|
|
205
|
+
'linear-gradient(to bottom, var(--dx-baseSurface) 0%, var(--dx-baseSurface) 70%, transparent 100%)',
|
|
206
|
+
}}
|
|
207
|
+
/>
|
|
208
|
+
</Tabs.Tablist>
|
|
209
|
+
);
|
|
210
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
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 { toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
10
|
+
import { Tree } from '@dxos/react-ui-list';
|
|
11
|
+
import { Tabs } from '@dxos/react-ui-tabs';
|
|
12
|
+
|
|
13
|
+
import { useNavTreeContext } from './NavTreeContext';
|
|
14
|
+
import { NavTreeItemColumns } from './NavTreeItemColumns';
|
|
15
|
+
import { useLoadDescendents } from '../hooks';
|
|
16
|
+
import { NAVTREE_PLUGIN } from '../meta';
|
|
17
|
+
import { l0ItemType } from '../util';
|
|
18
|
+
|
|
19
|
+
type L1PanelProps = { item: Node<any>; path: string[]; currentItemId: string };
|
|
20
|
+
|
|
21
|
+
const L1Panel = ({ item, path, currentItemId }: L1PanelProps) => {
|
|
22
|
+
const layout = useLayout();
|
|
23
|
+
const navTreeContext = useNavTreeContext();
|
|
24
|
+
const { t } = useTranslation(NAVTREE_PLUGIN);
|
|
25
|
+
return (
|
|
26
|
+
<Tabs.Tabpanel
|
|
27
|
+
key={item.id}
|
|
28
|
+
value={item.id}
|
|
29
|
+
classNames={[
|
|
30
|
+
'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]',
|
|
31
|
+
item.id === currentItemId && 'grid',
|
|
32
|
+
]}
|
|
33
|
+
tabIndex={-1}
|
|
34
|
+
{...(!layout.sidebarOpen && { inert: 'true' })}
|
|
35
|
+
>
|
|
36
|
+
{item.id === currentItemId && (
|
|
37
|
+
<>
|
|
38
|
+
<h2 className='flex items-center border-be border-separator pis-4 app-drag'>
|
|
39
|
+
<span className='flex-1 truncate cursor-default'>{toLocalizedString(item.properties.label, t)}</span>
|
|
40
|
+
<NavTreeItemColumns path={path} item={item} open />
|
|
41
|
+
</h2>
|
|
42
|
+
<div role='none' className='overflow-y-auto'>
|
|
43
|
+
<Tree
|
|
44
|
+
{...navTreeContext}
|
|
45
|
+
id={item.id}
|
|
46
|
+
root={item}
|
|
47
|
+
path={path}
|
|
48
|
+
levelOffset={5}
|
|
49
|
+
draggable
|
|
50
|
+
gridTemplateColumns='[tree-row-start] 1fr min-content min-content min-content [tree-row-end]'
|
|
51
|
+
renderColumns={NavTreeItemColumns}
|
|
52
|
+
/>
|
|
53
|
+
</div>
|
|
54
|
+
</>
|
|
55
|
+
)}
|
|
56
|
+
</Tabs.Tabpanel>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const L1PanelCollection = ({ item, path, currentItemId }: L1PanelProps) => {
|
|
61
|
+
const { getItems } = useNavTreeContext();
|
|
62
|
+
useLoadDescendents(item);
|
|
63
|
+
const collectionItems = getItems(item);
|
|
64
|
+
const groupPath = useMemo(() => [...path, item.id], [item.id, path]);
|
|
65
|
+
return (
|
|
66
|
+
<>
|
|
67
|
+
{collectionItems
|
|
68
|
+
.filter((item) => l0ItemType(item) === 'tab')
|
|
69
|
+
.map((item) => (
|
|
70
|
+
<L1Panel key={item.id} item={item} path={groupPath} currentItemId={currentItemId} />
|
|
71
|
+
))}
|
|
72
|
+
</>
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const L1Panels = ({
|
|
77
|
+
topLevelItems,
|
|
78
|
+
path,
|
|
79
|
+
currentItemId,
|
|
80
|
+
}: {
|
|
81
|
+
topLevelItems: Node<any>[];
|
|
82
|
+
path: string[];
|
|
83
|
+
currentItemId: string;
|
|
84
|
+
}) => {
|
|
85
|
+
return (
|
|
86
|
+
<>
|
|
87
|
+
{topLevelItems.map((item) => {
|
|
88
|
+
const type = l0ItemType(item);
|
|
89
|
+
switch (type) {
|
|
90
|
+
case 'collection':
|
|
91
|
+
return <L1PanelCollection key={item.id} item={item} path={path} currentItemId={currentItemId} />;
|
|
92
|
+
case 'tab':
|
|
93
|
+
return <L1Panel key={item.id} item={item} path={path} currentItemId={currentItemId} />;
|
|
94
|
+
default:
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
})}
|
|
98
|
+
</>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
@@ -16,7 +16,7 @@ import { isTreeData, type TreeData } from '@dxos/react-ui-list';
|
|
|
16
16
|
import { Path } from '@dxos/react-ui-mosaic';
|
|
17
17
|
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
18
18
|
|
|
19
|
-
import {
|
|
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
|
|
27
|
+
const meta: Meta<typeof StorybookNavTree> = {
|
|
28
28
|
title: 'plugins/plugin-navtree/NavTree',
|
|
29
|
-
component:
|
|
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 <
|
|
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?:
|
|
63
|
+
getItems: (testItem?: any) => {
|
|
64
64
|
return testItem?.nodes ?? tree.nodes ?? [];
|
|
65
65
|
},
|
|
66
66
|
getProps: (testItem: NodeArg<any>) => ({
|