@dxos/plugin-navtree 0.8.4-main.1da679c → 0.8.4-main.21d9917
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-RSMA6I22.mjs +43 -0
- package/dist/lib/browser/app-graph-builder-RSMA6I22.mjs.map +7 -0
- package/dist/lib/browser/chunk-6YPQ625I.mjs +1293 -0
- package/dist/lib/browser/chunk-6YPQ625I.mjs.map +7 -0
- package/dist/lib/browser/chunk-AGQDZBPL.mjs +23 -0
- package/dist/lib/browser/chunk-AGQDZBPL.mjs.map +7 -0
- package/dist/lib/browser/chunk-YKTYPINZ.mjs +19 -0
- package/dist/lib/browser/chunk-YKTYPINZ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +82 -93
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/{keyboard-R2APW7UM.mjs → keyboard-32EH3N4K.mjs} +20 -19
- package/dist/lib/browser/keyboard-32EH3N4K.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/operation-resolver-IB75DC5O.mjs +52 -0
- package/dist/lib/browser/operation-resolver-IB75DC5O.mjs.map +7 -0
- package/dist/lib/browser/react-surface-F6CVMS3Y.mjs +58 -0
- package/dist/lib/browser/react-surface-F6CVMS3Y.mjs.map +7 -0
- package/dist/lib/browser/state-EVYQOUI3.mjs +120 -0
- package/dist/lib/browser/state-EVYQOUI3.mjs.map +7 -0
- package/dist/types/src/NavTreePlugin.d.ts +2 -1
- package/dist/types/src/NavTreePlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts +6 -0
- package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts.map +1 -0
- package/dist/types/src/capabilities/app-graph-builder/index.d.ts +3 -0
- package/dist/types/src/capabilities/app-graph-builder/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +5 -105
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/keyboard/index.d.ts +3 -0
- package/dist/types/src/capabilities/keyboard/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/keyboard/keyboard.d.ts +5 -0
- package/dist/types/src/capabilities/keyboard/keyboard.d.ts.map +1 -0
- package/dist/types/src/capabilities/operation-resolver/index.d.ts +3 -0
- package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +5 -0
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
- package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
- package/dist/types/src/capabilities/state/index.d.ts +3 -0
- package/dist/types/src/capabilities/state/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/state/state.d.ts +6 -0
- package/dist/types/src/capabilities/state/state.d.ts.map +1 -0
- package/dist/types/src/components/CommandsDialog/CommandsDialog.d.ts +3 -2
- package/dist/types/src/components/CommandsDialog/CommandsDialog.d.ts.map +1 -1
- package/dist/types/src/components/CommandsDialog/CommandsTrigger.d.ts.map +1 -1
- package/dist/types/src/components/NavTree/NavTree.d.ts +30 -1
- package/dist/types/src/components/NavTree/NavTree.d.ts.map +1 -1
- package/dist/types/src/components/NavTree/NavTree.stories.d.ts +5 -3
- package/dist/types/src/components/NavTree/NavTree.stories.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeContainer.d.ts +8 -1
- package/dist/types/src/components/NavTreeContainer.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeDocumentTitle.d.ts +1 -1
- package/dist/types/src/components/NavTreeDocumentTitle.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeItem/NavTreeItemAction.d.ts +6 -6
- package/dist/types/src/components/NavTreeItem/NavTreeItemAction.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeItem/NavTreeItemAction.stories.d.ts +3 -3
- package/dist/types/src/components/NavTreeItem/NavTreeItemAction.stories.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeItem/NavTreeItemColumns.d.ts +1 -1
- package/dist/types/src/components/NavTreeItem/NavTreeItemColumns.d.ts.map +1 -1
- package/dist/types/src/components/Sidebar/L0Menu.d.ts +6 -4
- package/dist/types/src/components/Sidebar/L0Menu.d.ts.map +1 -1
- package/dist/types/src/components/Sidebar/L1Panel.d.ts +1 -1
- package/dist/types/src/components/Sidebar/L1Panel.d.ts.map +1 -1
- package/dist/types/src/components/Sidebar/L1Tabs.d.ts +2 -2
- package/dist/types/src/components/Sidebar/L1Tabs.d.ts.map +1 -1
- package/dist/types/src/components/UserAccountAvatar/UserAccountAvatar.d.ts.map +1 -1
- package/dist/types/src/components/UserAccountAvatar/UserAccountAvatar.stories.d.ts +1 -2
- package/dist/types/src/components/UserAccountAvatar/UserAccountAvatar.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/types.d.ts +7 -7
- package/dist/types/src/components/types.d.ts.map +1 -1
- package/dist/types/src/experimental/Tree.d.ts +1 -2
- 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 +32 -1
- package/dist/types/src/hooks.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +3 -4
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/testing/app-graph-builder.d.ts +2 -3
- package/dist/types/src/testing/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/testing/generator.d.ts +5 -6
- package/dist/types/src/testing/generator.d.ts.map +1 -1
- package/dist/types/src/testing/update-state.d.ts +2 -2
- package/dist/types/src/testing/update-state.d.ts.map +1 -1
- package/dist/types/src/types/capabilities.d.ts +16 -0
- package/dist/types/src/types/capabilities.d.ts.map +1 -0
- package/dist/types/src/types/events.d.ts +5 -0
- package/dist/types/src/types/events.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +4 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/src/{types.d.ts → types/schema.d.ts} +10 -9
- package/dist/types/src/types/schema.d.ts.map +1 -0
- package/dist/types/src/util.d.ts +7 -7
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +54 -53
- package/src/NavTreePlugin.tsx +65 -83
- package/src/capabilities/app-graph-builder/app-graph-builder.ts +41 -0
- package/src/capabilities/app-graph-builder/index.ts +7 -0
- package/src/capabilities/index.ts +5 -9
- package/src/capabilities/keyboard/index.ts +7 -0
- package/src/capabilities/keyboard/keyboard.ts +65 -0
- package/src/capabilities/operation-resolver/index.ts +7 -0
- package/src/capabilities/operation-resolver/operation-resolver.ts +41 -0
- package/src/capabilities/react-surface/index.ts +7 -0
- package/src/capabilities/react-surface/react-surface.tsx +54 -0
- package/src/capabilities/state/index.ts +7 -0
- package/src/capabilities/state/state.ts +121 -0
- package/src/components/CommandsDialog/CommandsDialog.tsx +109 -98
- package/src/components/CommandsDialog/CommandsTrigger.tsx +6 -15
- package/src/components/NavTree/NavTree.stories.tsx +93 -88
- package/src/components/NavTree/NavTree.tsx +9 -15
- package/src/components/NavTreeContainer.tsx +254 -256
- package/src/components/NavTreeDocumentTitle.tsx +5 -4
- package/src/components/NavTreeItem/NavTreeItemAction.stories.tsx +18 -10
- package/src/components/NavTreeItem/NavTreeItemAction.tsx +23 -16
- package/src/components/NavTreeItem/NavTreeItemColumns.tsx +32 -26
- package/src/components/Sidebar/L0Menu.tsx +112 -137
- package/src/components/Sidebar/L1Panel.tsx +16 -17
- package/src/components/Sidebar/L1Tabs.tsx +6 -31
- package/src/components/UserAccountAvatar/UserAccountAvatar.stories.tsx +3 -4
- package/src/components/UserAccountAvatar/UserAccountAvatar.tsx +20 -12
- package/src/components/index.ts +1 -0
- package/src/components/types.ts +7 -7
- package/src/experimental/Tree.stories.tsx +26 -30
- package/src/experimental/Tree.tsx +7 -24
- package/src/hooks.ts +54 -2
- package/src/index.ts +1 -2
- package/src/meta.ts +11 -8
- package/src/testing/app-graph-builder.ts +159 -234
- package/src/testing/generator.ts +20 -18
- package/src/testing/update-state.ts +6 -6
- package/src/types/capabilities.ts +21 -0
- package/src/types/events.ts +11 -0
- package/src/types/index.ts +7 -0
- package/src/{types.ts → types/schema.ts} +9 -8
- package/src/util.ts +13 -16
- package/dist/lib/browser/app-graph-builder-DU57YHO5.mjs +0 -45
- package/dist/lib/browser/app-graph-builder-DU57YHO5.mjs.map +0 -7
- package/dist/lib/browser/chunk-EMIN6D7Q.mjs +0 -1469
- package/dist/lib/browser/chunk-EMIN6D7Q.mjs.map +0 -7
- package/dist/lib/browser/chunk-ERDGQTH5.mjs +0 -16
- package/dist/lib/browser/chunk-ERDGQTH5.mjs.map +0 -7
- package/dist/lib/browser/chunk-WCARAZ7J.mjs +0 -15
- package/dist/lib/browser/chunk-WCARAZ7J.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-RPZ5O7AJ.mjs +0 -47
- package/dist/lib/browser/intent-resolver-RPZ5O7AJ.mjs.map +0 -7
- package/dist/lib/browser/keyboard-R2APW7UM.mjs.map +0 -7
- package/dist/lib/browser/react-surface-DF7FNA34.mjs +0 -51
- package/dist/lib/browser/react-surface-DF7FNA34.mjs.map +0 -7
- package/dist/lib/browser/state-W5JDWIJL.mjs +0 -117
- package/dist/lib/browser/state-W5JDWIJL.mjs.map +0 -7
- package/dist/types/src/capabilities/app-graph-builder.d.ts +0 -4
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +0 -1
- package/dist/types/src/capabilities/capabilities.d.ts +0 -21
- package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
- package/dist/types/src/capabilities/keyboard.d.ts +0 -4
- package/dist/types/src/capabilities/keyboard.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface.d.ts +0 -4
- package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
- package/dist/types/src/capabilities/state.d.ts +0 -20
- package/dist/types/src/capabilities/state.d.ts.map +0 -1
- package/dist/types/src/events.d.ts +0 -4
- package/dist/types/src/events.d.ts.map +0 -1
- package/dist/types/src/types.d.ts.map +0 -1
- package/src/capabilities/app-graph-builder.ts +0 -52
- package/src/capabilities/capabilities.ts +0 -20
- package/src/capabilities/intent-resolver.ts +0 -37
- package/src/capabilities/keyboard.ts +0 -59
- package/src/capabilities/react-surface.tsx +0 -45
- package/src/capabilities/state.ts +0 -105
- package/src/events.ts +0 -11
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Atom } from '@effect-atom/atom-react';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
|
|
8
|
+
import { Capability, Common } from '@dxos/app-framework';
|
|
9
|
+
import { Path } from '@dxos/react-ui-list';
|
|
10
|
+
|
|
11
|
+
import { meta } from '../../meta';
|
|
12
|
+
import { type NavTreeCapabilities as NC, NavTreeCapabilities } from '../../types';
|
|
13
|
+
|
|
14
|
+
const KEY = `${meta.id}/state/v1`;
|
|
15
|
+
|
|
16
|
+
/** Default item state for new entries. */
|
|
17
|
+
const defaultItemState: NC.NavTreeItemState = { open: false, current: false, alternateTree: false };
|
|
18
|
+
|
|
19
|
+
/** Default state entries for initial tree structure. */
|
|
20
|
+
// TODO(thure): Initialize these dynamically.
|
|
21
|
+
const defaultStateEntries: [string, NC.NavTreeItemState][] = [
|
|
22
|
+
['root', { open: true, current: false }],
|
|
23
|
+
['root~dxos.org/plugin/space-spaces', { open: true, current: false }],
|
|
24
|
+
['root~dxos.org/plugin/files', { open: true, current: false }],
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const getInitialState = (): Map<string, NC.NavTreeItemState> => {
|
|
28
|
+
const stringified = localStorage.getItem(KEY);
|
|
29
|
+
if (!stringified) {
|
|
30
|
+
return new Map(defaultStateEntries);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
const cached: [string, { open: boolean; current: boolean }][] = JSON.parse(stringified);
|
|
35
|
+
return new Map(cached.map(([key, value]) => [key, { open: value.open, current: false }]));
|
|
36
|
+
} catch {
|
|
37
|
+
return new Map(defaultStateEntries);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export default Capability.makeModule(
|
|
42
|
+
Effect.fnUntraced(function* () {
|
|
43
|
+
const registry = yield* Capability.get(Common.Capability.AtomRegistry);
|
|
44
|
+
const layoutAtom = yield* Capability.get(Common.Capability.Layout);
|
|
45
|
+
|
|
46
|
+
// Backing state for persistence (not reactive).
|
|
47
|
+
const backingState = getInitialState();
|
|
48
|
+
|
|
49
|
+
// Per-path atom family for fine-grained reactivity.
|
|
50
|
+
// keepAlive prevents atoms from being garbage collected when components unmount,
|
|
51
|
+
// ensuring state is preserved across deletion/restoration cycles.
|
|
52
|
+
const itemAtomFamily = Atom.family((pathString: string) =>
|
|
53
|
+
Atom.make<NC.NavTreeItemState>(backingState.get(pathString) ?? { ...defaultItemState }).pipe(Atom.keepAlive),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const getItemAtom = (path: string[]): Atom.Atom<NC.NavTreeItemState> => {
|
|
57
|
+
const pathString = Path.create(...path);
|
|
58
|
+
return itemAtomFamily(pathString);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const getItem = (path: string[]): NC.NavTreeItemState => {
|
|
62
|
+
return registry.get(getItemAtom(path));
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const setItem = (path: string[], key: 'open' | 'current' | 'alternateTree', next: boolean) => {
|
|
66
|
+
const pathString = Path.create(...path);
|
|
67
|
+
const atom = itemAtomFamily(pathString);
|
|
68
|
+
const currentValue = registry.get(atom);
|
|
69
|
+
const newValue = { ...currentValue, [key]: next };
|
|
70
|
+
|
|
71
|
+
// Update the atom.
|
|
72
|
+
registry.set(atom, newValue);
|
|
73
|
+
|
|
74
|
+
// Update backing state and persist to localStorage.
|
|
75
|
+
backingState.set(pathString, newValue);
|
|
76
|
+
localStorage.setItem(KEY, JSON.stringify(Array.from(backingState.entries())));
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// Subscribe to layout changes to update current state.
|
|
80
|
+
let previous: string[] = [];
|
|
81
|
+
const unsubscribe = registry.subscribe(layoutAtom, (layout) => {
|
|
82
|
+
const removed = previous.filter((id) => !layout.active.includes(id));
|
|
83
|
+
previous = layout.active;
|
|
84
|
+
|
|
85
|
+
const handleUpdate = () => {
|
|
86
|
+
// Mark removed items as not current.
|
|
87
|
+
removed.forEach((id) => {
|
|
88
|
+
const keys = Array.from(backingState.keys()).filter((key) => Path.last(key) === id);
|
|
89
|
+
keys.forEach((key) => {
|
|
90
|
+
setItem(Path.parts(key), 'current', false);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Mark active items as current.
|
|
95
|
+
layout.active.forEach((id: string) => {
|
|
96
|
+
const keys = Array.from(new Set([...backingState.keys(), id])).filter((key) => Path.last(key) === id);
|
|
97
|
+
keys.forEach((key) => {
|
|
98
|
+
setItem(Path.parts(key), 'current', true);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// TODO(wittjosiah): This is setTimeout because there's a race between the keys being initialized.
|
|
104
|
+
// Keys are initialized on the first render of an item in the navtree.
|
|
105
|
+
// This could be avoided if the location was a path as well and not just an id.
|
|
106
|
+
const timeout = setTimeout(handleUpdate, 500);
|
|
107
|
+
handleUpdate();
|
|
108
|
+
return () => clearTimeout(timeout);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
return Capability.contributes(
|
|
112
|
+
NavTreeCapabilities.State,
|
|
113
|
+
{
|
|
114
|
+
getItem,
|
|
115
|
+
getItemAtom,
|
|
116
|
+
setItem,
|
|
117
|
+
},
|
|
118
|
+
() => Effect.sync(() => unsubscribe()),
|
|
119
|
+
);
|
|
120
|
+
}),
|
|
121
|
+
);
|
|
@@ -2,117 +2,128 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React, { useMemo, useState } from 'react';
|
|
5
|
+
import React, { forwardRef, useMemo, useState } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { Common } from '@dxos/app-framework';
|
|
8
|
+
import { useAppGraph, useOperationInvoker } from '@dxos/app-framework/react';
|
|
9
9
|
import { Keyboard, keySymbols } from '@dxos/keyboard';
|
|
10
|
+
import { Graph, Node, useActionRunner } from '@dxos/plugin-graph';
|
|
10
11
|
import { useActions } from '@dxos/plugin-graph';
|
|
11
|
-
import { Button, Dialog,
|
|
12
|
-
import { SearchList } from '@dxos/react-ui-searchlist';
|
|
13
|
-
import {
|
|
14
|
-
cardDialogContent,
|
|
15
|
-
cardDialogHeader,
|
|
16
|
-
cardDialogPaddedOverflow,
|
|
17
|
-
cardDialogSearchListRoot,
|
|
18
|
-
} from '@dxos/react-ui-stack';
|
|
19
|
-
import { descriptionText, mx } from '@dxos/react-ui-theme';
|
|
12
|
+
import { Button, Dialog, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
13
|
+
import { SearchList, useSearchListResults } from '@dxos/react-ui-searchlist';
|
|
14
|
+
import { osTranslations } from '@dxos/ui-theme';
|
|
20
15
|
import { getHostPlatform } from '@dxos/util';
|
|
21
16
|
|
|
22
|
-
import { KEY_BINDING,
|
|
17
|
+
import { KEY_BINDING, meta } from '../../meta';
|
|
18
|
+
|
|
19
|
+
export type CommandsDialogContentProps = {
|
|
20
|
+
selected?: string;
|
|
21
|
+
};
|
|
23
22
|
|
|
24
23
|
// TODO(wittjosiah): This probably deserves its own plugin but for now it lives here w/ other navigation UI.
|
|
25
|
-
export const CommandsDialogContent = (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
export const CommandsDialogContent = forwardRef<HTMLDivElement, CommandsDialogContentProps>(
|
|
25
|
+
({ selected: initial }, forwardedRef) => {
|
|
26
|
+
const { t } = useTranslation(meta.id);
|
|
27
|
+
const { invokeSync } = useOperationInvoker();
|
|
28
|
+
const runAction = useActionRunner();
|
|
29
|
+
const { graph } = useAppGraph();
|
|
30
|
+
const [selected, setSelected] = useState<string | undefined>(initial);
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
32
|
+
// Traverse graph.
|
|
33
|
+
// TODO(burdon): Factor out commonality with shortcut dialog.
|
|
34
|
+
const allActions = useMemo(() => {
|
|
35
|
+
// TODO(burdon): Get from navtree (not keyboard).
|
|
36
|
+
const current = Keyboard.singleton.getCurrentContext();
|
|
37
|
+
const actionMap = new Set<string>();
|
|
38
|
+
const actions: Node.ActionLike[] = [];
|
|
39
|
+
Graph.traverse(graph, {
|
|
40
|
+
visitor: (node, path) => {
|
|
41
|
+
if (
|
|
42
|
+
(Node.isAction(node) || Node.isActionGroup(node)) &&
|
|
43
|
+
!actionMap.has(node.id) &&
|
|
44
|
+
current.startsWith(path.slice(0, -1).join('/'))
|
|
45
|
+
) {
|
|
46
|
+
actionMap.add(node.id);
|
|
47
|
+
actions.push(node);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
});
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
actions.sort((a, b) => {
|
|
53
|
+
return toLocalizedString(a.properties.label, t)
|
|
54
|
+
?.toLowerCase()
|
|
55
|
+
.localeCompare(toLocalizedString(b.properties.label, t)?.toLowerCase());
|
|
56
|
+
});
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
return actions;
|
|
59
|
+
}, [graph]);
|
|
59
60
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
const group = allActions.find(({ id }) => id === selected);
|
|
62
|
+
const groupActions = useActions(graph, group?.id);
|
|
63
|
+
const actions = Node.isActionGroup(group) ? groupActions : allActions;
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
const { results, handleSearch } = useSearchListResults({
|
|
66
|
+
items: actions,
|
|
67
|
+
extract: (action) => toLocalizedString(action.properties.label, t),
|
|
68
|
+
});
|
|
67
69
|
|
|
68
|
-
|
|
69
|
-
<
|
|
70
|
-
<
|
|
71
|
-
<SearchList.
|
|
72
|
-
{
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
key={action.id}
|
|
82
|
-
onSelect={() => {
|
|
83
|
-
if (action.properties.disabled) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
70
|
+
return (
|
|
71
|
+
<Dialog.Content ref={forwardedRef}>
|
|
72
|
+
<Dialog.Title>{t('commands dialog title', { ns: meta.id })}</Dialog.Title>
|
|
73
|
+
<SearchList.Root onSearch={handleSearch}>
|
|
74
|
+
<div aria-label={t('command list input placeholder')} role='combobox' aria-expanded='true'>
|
|
75
|
+
<SearchList.Input placeholder={t('command list input placeholder')} />
|
|
76
|
+
<SearchList.Content>
|
|
77
|
+
<SearchList.Viewport>
|
|
78
|
+
{results.map((action) => {
|
|
79
|
+
const shortcut =
|
|
80
|
+
typeof action.properties.keyBinding === 'string'
|
|
81
|
+
? action.properties.keyBinding
|
|
82
|
+
: action.properties.keyBinding?.[getHostPlatform()];
|
|
86
83
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
84
|
+
return (
|
|
85
|
+
<SearchList.Item
|
|
86
|
+
value={action.id}
|
|
87
|
+
key={action.id}
|
|
88
|
+
label={toLocalizedString(action.properties.label, t)}
|
|
89
|
+
icon={action.properties.icon}
|
|
90
|
+
suffix={shortcut ? keySymbols(shortcut).join('') : undefined}
|
|
91
|
+
onSelect={() => {
|
|
92
|
+
if (action.properties.disabled) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
91
95
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
});
|
|
97
|
-
}}
|
|
98
|
-
classNames='flex items-center gap-2'
|
|
99
|
-
disabled={action.properties.disabled}
|
|
100
|
-
{...(action.properties?.testId && { 'data-testid': action.properties.testId })}
|
|
101
|
-
>
|
|
102
|
-
<Icon icon={action.properties.icon} size={4} />
|
|
103
|
-
<span className='grow truncate'>{label}</span>
|
|
104
|
-
{shortcut && <span className={mx('shrink-0', descriptionText)}>{keySymbols(shortcut).join('')}</span>}
|
|
105
|
-
</SearchList.Item>
|
|
106
|
-
);
|
|
107
|
-
})}
|
|
108
|
-
</SearchList.Content>
|
|
109
|
-
</SearchList.Root>
|
|
96
|
+
if (Node.isActionGroup(action)) {
|
|
97
|
+
setSelected(action.id);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
110
100
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
101
|
+
invokeSync(Common.LayoutOperation.UpdateDialog, { state: false });
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
const node = Graph.getConnections(graph, group?.id ?? action.id, 'inbound')[0];
|
|
104
|
+
if (node && Node.isAction(action)) {
|
|
105
|
+
void runAction(action, { parent: node, caller: KEY_BINDING });
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}}
|
|
109
|
+
classNames='flex items-center gap-2'
|
|
110
|
+
disabled={action.properties.disabled}
|
|
111
|
+
{...(action.properties?.testId && {
|
|
112
|
+
'data-testid': action.properties.testId,
|
|
113
|
+
})}
|
|
114
|
+
/>
|
|
115
|
+
);
|
|
116
|
+
})}
|
|
117
|
+
</SearchList.Viewport>
|
|
118
|
+
</SearchList.Content>
|
|
119
|
+
</div>
|
|
120
|
+
</SearchList.Root>
|
|
121
|
+
<div role='none' className='pli-cardSpacingInline pbe-cardSpacingBlock'>
|
|
122
|
+
<Dialog.Close asChild>
|
|
123
|
+
<Button classNames='is-full'>{t('close label', { ns: osTranslations })}</Button>
|
|
124
|
+
</Dialog.Close>
|
|
125
|
+
</div>
|
|
126
|
+
</Dialog.Content>
|
|
127
|
+
);
|
|
128
|
+
},
|
|
129
|
+
);
|
|
@@ -4,29 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { Common } from '@dxos/app-framework';
|
|
8
|
+
import { useOperationInvoker } from '@dxos/app-framework/react';
|
|
8
9
|
import { Button, Icon, useTranslation } from '@dxos/react-ui';
|
|
9
10
|
|
|
10
|
-
import { COMMANDS_DIALOG,
|
|
11
|
+
import { COMMANDS_DIALOG, meta } from '../../meta';
|
|
11
12
|
|
|
12
13
|
// TODO(thure): Refactor to be handled by a more appropriate plugin.
|
|
13
14
|
export const CommandsTrigger = () => {
|
|
14
|
-
const {
|
|
15
|
-
const { t } = useTranslation(
|
|
15
|
+
const { invokeSync } = useOperationInvoker();
|
|
16
|
+
const { t } = useTranslation(meta.id);
|
|
16
17
|
return (
|
|
17
18
|
<Button
|
|
18
19
|
classNames='m-1 pli-1 lg:pli-2'
|
|
19
|
-
onClick={() =>
|
|
20
|
-
dispatch(
|
|
21
|
-
createIntent(LayoutAction.UpdateDialog, {
|
|
22
|
-
part: 'dialog',
|
|
23
|
-
subject: COMMANDS_DIALOG,
|
|
24
|
-
options: {
|
|
25
|
-
blockAlign: 'start',
|
|
26
|
-
},
|
|
27
|
-
}),
|
|
28
|
-
)
|
|
29
|
-
}
|
|
20
|
+
onClick={() => invokeSync(Common.LayoutOperation.UpdateDialog, { subject: COMMANDS_DIALOG, blockAlign: 'start' })}
|
|
30
21
|
>
|
|
31
22
|
<span className='text-description font-normal grow text-start'>{t('command list input placeholder')}</span>
|
|
32
23
|
<Icon icon='ph--magnifying-glass--regular' size={5} />
|
|
@@ -2,36 +2,23 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
6
|
-
|
|
5
|
+
import { Atom, type Registry } from '@effect-atom/atom-react';
|
|
7
6
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
|
-
import
|
|
9
|
-
import React from 'react';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
LayoutAction,
|
|
15
|
-
SettingsPlugin,
|
|
16
|
-
contributes,
|
|
17
|
-
createResolver,
|
|
18
|
-
defineCapability,
|
|
19
|
-
useCapability,
|
|
20
|
-
} from '@dxos/app-framework';
|
|
7
|
+
import * as Effect from 'effect/Effect';
|
|
8
|
+
import React, { type KeyboardEvent, useCallback, useRef } from 'react';
|
|
9
|
+
import { expect, userEvent, within } from 'storybook/test';
|
|
10
|
+
|
|
11
|
+
import { Capability, Common } from '@dxos/app-framework';
|
|
12
|
+
import { useAtomCapability } from '@dxos/app-framework/react';
|
|
21
13
|
import { withPluginManager } from '@dxos/app-framework/testing';
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import { ClientPlugin } from '@dxos/plugin-client';
|
|
25
|
-
import { GraphPlugin } from '@dxos/plugin-graph';
|
|
26
|
-
import { SpacePlugin } from '@dxos/plugin-space';
|
|
27
|
-
import { StorybookLayoutPlugin } from '@dxos/plugin-storybook-layout';
|
|
28
|
-
import { ThemePlugin } from '@dxos/plugin-theme';
|
|
14
|
+
import { OperationResolver } from '@dxos/operation';
|
|
15
|
+
import { StorybookPlugin, corePlugins } from '@dxos/plugin-testing';
|
|
29
16
|
import { faker } from '@dxos/random';
|
|
30
17
|
import { IconButton, Input, Main, Toolbar } from '@dxos/react-ui';
|
|
18
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
31
19
|
import { useAttention, useAttentionAttributes } from '@dxos/react-ui-attention';
|
|
32
20
|
import { Stack, StackItem } from '@dxos/react-ui-stack';
|
|
33
|
-
import {
|
|
34
|
-
import { withLayout } from '@dxos/storybook-utils';
|
|
21
|
+
import { mx } from '@dxos/ui-theme';
|
|
35
22
|
|
|
36
23
|
import { NavTreePlugin } from '../../NavTreePlugin';
|
|
37
24
|
import { storybookGraphBuilders } from '../../testing';
|
|
@@ -40,7 +27,7 @@ import { NavTreeContainer } from '../NavTreeContainer';
|
|
|
40
27
|
|
|
41
28
|
faker.seed(1234);
|
|
42
29
|
|
|
43
|
-
const StoryState =
|
|
30
|
+
const StoryState = Capability.make<Atom.Atom<{ tab: string }>>('story-state');
|
|
44
31
|
|
|
45
32
|
// TODO(burdon): Fix outline (e.g., button in sidebar nav is clipped when focused).
|
|
46
33
|
// TODO(burdon): Consider similar containment of: Table, Sheet, Kanban Column, Form, etc.
|
|
@@ -52,7 +39,7 @@ const StoryPlankHeading = ({ attendableId }: { attendableId: string }) => {
|
|
|
52
39
|
const { hasAttention } = useAttention(attendableId);
|
|
53
40
|
console.log('hasAttention', hasAttention);
|
|
54
41
|
return (
|
|
55
|
-
<div className='flex p-1 items-center border-
|
|
42
|
+
<div className='flex p-1 items-center border-be border-separator'>
|
|
56
43
|
<IconButton
|
|
57
44
|
density='coarse'
|
|
58
45
|
icon='ph--atom--regular'
|
|
@@ -68,6 +55,15 @@ const StoryPlankHeading = ({ attendableId }: { attendableId: string }) => {
|
|
|
68
55
|
|
|
69
56
|
const StoryPlank = ({ attendableId }: { attendableId: string }) => {
|
|
70
57
|
const attentionAttrs = useAttentionAttributes(attendableId);
|
|
58
|
+
const rootElement = useRef<HTMLDivElement | null>(null);
|
|
59
|
+
|
|
60
|
+
// NOTE(thure): This is the same workaround as in Plank, but that component is out of scope for this story.
|
|
61
|
+
// TODO(thure): Tabster’s focus group should handle moving focus to Main, but something is blocking it.
|
|
62
|
+
const handleKeyDown = useCallback((event: KeyboardEvent) => {
|
|
63
|
+
if (event.target === event.currentTarget && event.key === 'Escape') {
|
|
64
|
+
rootElement.current?.closest('main')?.focus();
|
|
65
|
+
}
|
|
66
|
+
}, []);
|
|
71
67
|
|
|
72
68
|
return (
|
|
73
69
|
<StackItem.Root
|
|
@@ -75,10 +71,12 @@ const StoryPlank = ({ attendableId }: { attendableId: string }) => {
|
|
|
75
71
|
{...attentionAttrs}
|
|
76
72
|
classNames='bg-baseSurface border-ie border-separator'
|
|
77
73
|
size={30}
|
|
74
|
+
onKeyDown={handleKeyDown}
|
|
75
|
+
ref={rootElement}
|
|
78
76
|
>
|
|
79
77
|
<StoryPlankHeading attendableId={attendableId} />
|
|
80
78
|
<StackItem.Content toolbar>
|
|
81
|
-
<Toolbar.Root classNames='border-
|
|
79
|
+
<Toolbar.Root classNames='border-be border-subduedSeparator'>
|
|
82
80
|
<Toolbar.Button>Test</Toolbar.Button>
|
|
83
81
|
</Toolbar.Root>
|
|
84
82
|
|
|
@@ -99,7 +97,7 @@ const StoryPlank = ({ attendableId }: { attendableId: string }) => {
|
|
|
99
97
|
};
|
|
100
98
|
|
|
101
99
|
const DefaultStory = () => {
|
|
102
|
-
const state =
|
|
100
|
+
const state = useAtomCapability(StoryState);
|
|
103
101
|
|
|
104
102
|
return (
|
|
105
103
|
<Main.Root complementarySidebarState='closed'>
|
|
@@ -121,35 +119,37 @@ const meta = {
|
|
|
121
119
|
component: NavTreeContainer,
|
|
122
120
|
render: DefaultStory,
|
|
123
121
|
decorators: [
|
|
122
|
+
withTheme,
|
|
124
123
|
withPluginManager({
|
|
125
124
|
plugins: [
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
AttentionPlugin(),
|
|
125
|
+
...corePlugins(),
|
|
126
|
+
StorybookPlugin({
|
|
127
|
+
initialState: { sidebarState: 'expanded' },
|
|
128
|
+
}),
|
|
129
|
+
|
|
132
130
|
NavTreePlugin(),
|
|
133
131
|
],
|
|
134
|
-
capabilities: (
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
132
|
+
capabilities: () => {
|
|
133
|
+
const storyStateAtom = Atom.make({ tab: 'space-0' }).pipe(Atom.keepAlive);
|
|
134
|
+
return [
|
|
135
|
+
Capability.contributes(StoryState, storyStateAtom),
|
|
136
|
+
Capability.contributes(Common.Capability.AppGraphBuilder, storybookGraphBuilders()),
|
|
137
|
+
Capability.contributes(Common.Capability.OperationResolver, [
|
|
138
|
+
OperationResolver.make({
|
|
139
|
+
operation: Common.LayoutOperation.SwitchWorkspace,
|
|
140
|
+
handler: ({ subject }) =>
|
|
141
|
+
Effect.gen(function* () {
|
|
142
|
+
const registry: Registry.Registry = yield* Capability.get(Common.Capability.AtomRegistry);
|
|
143
|
+
registry.set(storyStateAtom, { tab: subject });
|
|
144
|
+
}),
|
|
145
|
+
}),
|
|
146
|
+
]),
|
|
147
|
+
];
|
|
148
|
+
},
|
|
149
149
|
}),
|
|
150
|
-
withLayout({ fullscreen: true }),
|
|
151
150
|
],
|
|
152
151
|
parameters: {
|
|
152
|
+
layout: 'fullscreen',
|
|
153
153
|
translations,
|
|
154
154
|
},
|
|
155
155
|
} satisfies Meta<typeof NavTreeContainer>;
|
|
@@ -158,43 +158,48 @@ export default meta;
|
|
|
158
158
|
|
|
159
159
|
type Story = StoryObj<typeof NavTreeContainer>;
|
|
160
160
|
|
|
161
|
-
export const Default: Story = {
|
|
161
|
+
export const Default: Story = {
|
|
162
|
+
play: async ({ canvasElement }) => {
|
|
163
|
+
const canvas = within(canvasElement);
|
|
162
164
|
|
|
163
|
-
//
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
165
|
+
// Find the element with treegrid role and click on its parent
|
|
166
|
+
const treegridElement = await canvas.findByRole('treegrid');
|
|
167
|
+
const treegridParent = treegridElement.parentElement;
|
|
168
|
+
if (treegridParent) {
|
|
169
|
+
await userEvent.click(treegridParent);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Press Escape
|
|
173
|
+
await userEvent.keyboard('{Escape}');
|
|
174
|
+
|
|
175
|
+
// Confirm that focus is on an element with attribute data-main-landmark="0"
|
|
176
|
+
await expect(document.activeElement).toHaveAttribute('data-main-landmark', '0');
|
|
177
|
+
|
|
178
|
+
// Press Tab
|
|
179
|
+
await userEvent.keyboard('{Tab}');
|
|
180
|
+
|
|
181
|
+
// Confirm that focus is now on an element with data-main-landmark="1"
|
|
182
|
+
await expect(document.activeElement).toHaveAttribute('data-main-landmark', '1');
|
|
183
|
+
|
|
184
|
+
// Press Tab
|
|
185
|
+
await userEvent.keyboard('{Tab}');
|
|
186
|
+
|
|
187
|
+
// Confirm that focus is now on an element with data-main-landmark="0"
|
|
188
|
+
await expect(document.activeElement).toHaveAttribute('data-main-landmark', '0');
|
|
189
|
+
|
|
190
|
+
// Press Shift-Tab
|
|
191
|
+
await userEvent.keyboard('{Shift>}{Tab}{/Shift}');
|
|
192
|
+
|
|
193
|
+
// Press Enter
|
|
194
|
+
await userEvent.keyboard('{Enter}');
|
|
195
|
+
|
|
196
|
+
// Confirm that focus is now on an element with data-attendable-id="space-0:object-0"
|
|
197
|
+
await expect(document.activeElement).toHaveAttribute('data-attendable-id', 'space-0:object-0');
|
|
198
|
+
|
|
199
|
+
// Press Escape
|
|
200
|
+
await userEvent.keyboard('{Escape}');
|
|
201
|
+
|
|
202
|
+
// Confirm that focus is now on an element with data-main-landmark="1"
|
|
203
|
+
await expect(document.activeElement).toHaveAttribute('data-main-landmark', '1');
|
|
204
|
+
},
|
|
200
205
|
};
|