@dxos/plugin-navtree 0.8.4-main.fffef41 → 0.9.0
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/LICENSE +102 -5
- package/PLUGIN.mdl +376 -0
- package/README.md +1 -1
- package/dist/lib/neutral/CommandsDialogContent-UBGIQ5FI.mjs +112 -0
- package/dist/lib/neutral/CommandsDialogContent-UBGIQ5FI.mjs.map +7 -0
- package/dist/lib/neutral/CommandsTrigger-BH5WLMHK.mjs +27 -0
- package/dist/lib/neutral/CommandsTrigger-BH5WLMHK.mjs.map +7 -0
- package/dist/lib/neutral/NavTreeContainer-6AR4BFDD.mjs +12 -0
- package/dist/lib/neutral/NavTreeContainer-6AR4BFDD.mjs.map +7 -0
- package/dist/lib/neutral/NavTreeDocumentTitle-H3E6ZLYE.mjs +22 -0
- package/dist/lib/neutral/NavTreeDocumentTitle-H3E6ZLYE.mjs.map +7 -0
- package/dist/lib/neutral/NavTreePlugin.mjs +68 -0
- package/dist/lib/neutral/NavTreePlugin.mjs.map +7 -0
- package/dist/lib/neutral/NavTreePlugin.node.mjs +18 -0
- package/dist/lib/neutral/NavTreePlugin.node.mjs.map +7 -0
- package/dist/lib/neutral/NavTreePlugin.workerd.mjs +16 -0
- package/dist/lib/neutral/NavTreePlugin.workerd.mjs.map +7 -0
- package/dist/lib/neutral/app-graph-builder-Z347LKSF.mjs +42 -0
- package/dist/lib/neutral/app-graph-builder-Z347LKSF.mjs.map +7 -0
- package/dist/lib/neutral/capabilities/index.mjs +17 -0
- package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
- package/dist/lib/neutral/chunk-5OPDKH6B.mjs +273 -0
- package/dist/lib/neutral/chunk-5OPDKH6B.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/neutral/chunk-JOSNCOV4.mjs +79 -0
- package/dist/lib/neutral/chunk-JOSNCOV4.mjs.map +7 -0
- package/dist/lib/neutral/chunk-MDGKDQMZ.mjs +37 -0
- package/dist/lib/neutral/chunk-MDGKDQMZ.mjs.map +7 -0
- package/dist/lib/neutral/chunk-T7QS2EFI.mjs +8 -0
- package/dist/lib/neutral/chunk-T7QS2EFI.mjs.map +7 -0
- package/dist/lib/neutral/chunk-ZSWYB7JW.mjs +27 -0
- package/dist/lib/neutral/chunk-ZSWYB7JW.mjs.map +7 -0
- package/dist/lib/neutral/components/index.mjs +805 -0
- package/dist/lib/neutral/components/index.mjs.map +7 -0
- package/dist/lib/neutral/containers/index.mjs +20 -0
- package/dist/lib/neutral/containers/index.mjs.map +7 -0
- package/dist/lib/neutral/expose-26FV4W5D.mjs +38 -0
- package/dist/lib/neutral/expose-26FV4W5D.mjs.map +7 -0
- package/dist/lib/neutral/hooks/index.mjs +178 -0
- package/dist/lib/neutral/hooks/index.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +34 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/{browser/keyboard-YYTYJW4M.mjs → neutral/keyboard-EJ65BVTC.mjs} +25 -20
- package/dist/lib/neutral/keyboard-EJ65BVTC.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/meta.mjs +12 -0
- package/dist/lib/neutral/meta.mjs.map +7 -0
- package/dist/lib/neutral/operation-handler-ORDOJUL2.mjs +13 -0
- package/dist/lib/neutral/operation-handler-ORDOJUL2.mjs.map +7 -0
- package/dist/lib/neutral/operations/index.mjs +8 -0
- package/dist/lib/neutral/operations/index.mjs.map +7 -0
- package/dist/lib/neutral/plugin.mjs +16 -0
- package/dist/lib/neutral/plugin.mjs.map +7 -0
- package/dist/lib/neutral/react-surface-Q5XMAG7Z.mjs +50 -0
- package/dist/lib/neutral/react-surface-Q5XMAG7Z.mjs.map +7 -0
- package/dist/lib/neutral/state-VVJEWUHM.mjs +126 -0
- package/dist/lib/neutral/state-VVJEWUHM.mjs.map +7 -0
- package/dist/lib/neutral/testing/index.mjs +439 -0
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/lib/neutral/translations.mjs +23 -0
- package/dist/lib/neutral/translations.mjs.map +7 -0
- package/dist/lib/neutral/types/index.mjs +10 -0
- package/dist/lib/neutral/types/index.mjs.map +7 -0
- package/dist/types/src/NavTreePlugin.d.ts +3 -1
- package/dist/types/src/NavTreePlugin.d.ts.map +1 -1
- package/dist/types/src/NavTreePlugin.node.d.ts +4 -0
- package/dist/types/src/NavTreePlugin.node.d.ts.map +1 -0
- package/dist/types/src/NavTreePlugin.test.d.ts +2 -0
- package/dist/types/src/NavTreePlugin.test.d.ts.map +1 -0
- package/dist/types/src/NavTreePlugin.workerd.d.ts +4 -0
- package/dist/types/src/NavTreePlugin.workerd.d.ts.map +1 -0
- package/dist/types/src/capabilities/app-graph-builder.d.ts +4 -2
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +7 -108
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/keyboard.d.ts +3 -2
- package/dist/types/src/capabilities/keyboard.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
- package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +3 -2
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/capabilities/state.d.ts +4 -18
- package/dist/types/src/capabilities/state.d.ts.map +1 -1
- package/dist/types/src/components/NavTree/NavTree.d.ts +11 -4
- package/dist/types/src/components/NavTree/NavTree.d.ts.map +1 -1
- package/dist/types/src/components/NavTree/NavTree.stories.d.ts +10 -12
- package/dist/types/src/components/NavTree/NavTree.stories.d.ts.map +1 -1
- package/dist/types/src/components/{NavTreeContext.d.ts → NavTreeContext/NavTreeContext.d.ts} +1 -1
- package/dist/types/src/components/NavTreeContext/NavTreeContext.d.ts.map +1 -0
- package/dist/types/src/components/NavTreeContext/index.d.ts +2 -0
- package/dist/types/src/components/NavTreeContext/index.d.ts.map +1 -0
- package/dist/types/src/components/NavTreeItem/NavTreeItemAction.d.ts +13 -9
- package/dist/types/src/components/NavTreeItem/NavTreeItemAction.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeItem/NavTreeItemAction.stories.d.ts +3 -2
- package/dist/types/src/components/NavTreeItem/NavTreeItemAction.stories.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeItem/NavTreeItemColumns.d.ts.map +1 -1
- package/dist/types/src/components/Sidebar/L0Menu.d.ts +8 -5
- package/dist/types/src/components/Sidebar/L0Menu.d.ts.map +1 -1
- package/dist/types/src/components/Sidebar/L1Panel.d.ts +4 -7
- package/dist/types/src/components/Sidebar/L1Panel.d.ts.map +1 -1
- package/dist/types/src/components/Sidebar/L1Tabs.d.ts +5 -4
- 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.map +1 -1
- package/dist/types/src/components/index.d.ts +0 -3
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/types.d.ts +8 -17
- package/dist/types/src/components/types.d.ts.map +1 -1
- package/dist/types/src/containers/CommandsDialogContent/CommandsDialogContent.d.ts +6 -0
- package/dist/types/src/containers/CommandsDialogContent/CommandsDialogContent.d.ts.map +1 -0
- package/dist/types/src/containers/CommandsDialogContent/CommandsDialogContent.stories.d.ts +28 -0
- package/dist/types/src/containers/CommandsDialogContent/CommandsDialogContent.stories.d.ts.map +1 -0
- package/dist/types/src/containers/CommandsDialogContent/index.d.ts +2 -0
- package/dist/types/src/containers/CommandsDialogContent/index.d.ts.map +1 -0
- package/dist/types/src/containers/CommandsTrigger/CommandsTrigger.d.ts.map +1 -0
- package/dist/types/src/containers/CommandsTrigger/index.d.ts +2 -0
- package/dist/types/src/containers/CommandsTrigger/index.d.ts.map +1 -0
- package/dist/types/src/containers/NavTreeContainer/NavTreeContainer.d.ts +9 -0
- package/dist/types/src/containers/NavTreeContainer/NavTreeContainer.d.ts.map +1 -0
- package/dist/types/src/containers/NavTreeContainer/index.d.ts +3 -0
- package/dist/types/src/containers/NavTreeContainer/index.d.ts.map +1 -0
- package/dist/types/src/{components → containers/NavTreeDocumentTitle}/NavTreeDocumentTitle.d.ts +1 -1
- package/dist/types/src/containers/NavTreeDocumentTitle/NavTreeDocumentTitle.d.ts.map +1 -0
- package/dist/types/src/containers/NavTreeDocumentTitle/index.d.ts +2 -0
- package/dist/types/src/containers/NavTreeDocumentTitle/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +7 -0
- package/dist/types/src/containers/index.d.ts.map +1 -0
- package/dist/types/src/experimental/Tree.d.ts +2 -2
- package/dist/types/src/experimental/Tree.d.ts.map +1 -1
- package/dist/types/src/experimental/Tree.stories.d.ts +18 -4
- package/dist/types/src/experimental/Tree.stories.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +5 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/useActions.d.ts +11 -0
- package/dist/types/src/hooks/useActions.d.ts.map +1 -0
- package/dist/types/src/hooks/useLoadDescendents.d.ts +6 -0
- package/dist/types/src/hooks/useLoadDescendents.d.ts.map +1 -0
- package/dist/types/src/hooks/useNavTreeModel.d.ts +7 -0
- package/dist/types/src/hooks/useNavTreeModel.d.ts.map +1 -0
- package/dist/types/src/hooks/useNavTreeState.d.ts +18 -0
- package/dist/types/src/hooks/useNavTreeState.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +1 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +4 -3
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/operations/expose.d.ts +5 -0
- package/dist/types/src/operations/expose.d.ts.map +1 -0
- package/dist/types/src/operations/index.d.ts +3 -0
- package/dist/types/src/operations/index.d.ts.map +1 -0
- package/dist/types/src/plugin.d.ts +4 -0
- package/dist/types/src/plugin.d.ts.map +1 -0
- 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/translations.d.ts +8 -11
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/NavTreeCapabilities.d.ts +13 -0
- package/dist/types/src/types/NavTreeCapabilities.d.ts.map +1 -0
- package/dist/types/src/types/NavTreeEvents.d.ts +3 -0
- package/dist/types/src/types/NavTreeEvents.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 -6
- package/dist/types/src/types/schema.d.ts.map +1 -0
- package/dist/types/src/util.d.ts +12 -8
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +124 -62
- package/src/NavTreePlugin.node.ts +17 -0
- package/src/NavTreePlugin.test.ts +27 -0
- package/src/NavTreePlugin.tsx +46 -76
- package/src/NavTreePlugin.workerd.ts +16 -0
- package/src/capabilities/app-graph-builder.ts +34 -45
- package/src/capabilities/index.ts +10 -8
- package/src/capabilities/keyboard.ts +58 -51
- package/src/capabilities/operation-handler.ts +16 -0
- package/src/capabilities/react-surface.tsx +46 -38
- package/src/capabilities/state.ts +132 -84
- package/src/components/NavTree/NavTree.stories.tsx +55 -63
- package/src/components/NavTree/NavTree.tsx +65 -33
- package/src/components/{NavTreeContext.tsx → NavTreeContext/NavTreeContext.tsx} +1 -1
- package/src/components/NavTreeContext/index.ts +5 -0
- package/src/components/NavTreeItem/NavTreeItemAction.stories.tsx +23 -15
- package/src/components/NavTreeItem/NavTreeItemAction.tsx +75 -52
- package/src/components/NavTreeItem/NavTreeItemColumns.tsx +25 -42
- package/src/components/Sidebar/L0Menu.tsx +155 -184
- package/src/components/Sidebar/L1Panel.tsx +181 -101
- package/src/components/Sidebar/L1Tabs.tsx +18 -34
- package/src/components/UserAccountAvatar/UserAccountAvatar.stories.tsx +2 -3
- package/src/components/UserAccountAvatar/UserAccountAvatar.tsx +1 -1
- package/src/components/index.ts +1 -3
- package/src/components/types.ts +13 -19
- package/src/containers/CommandsDialogContent/CommandsDialogContent.stories.tsx +46 -0
- package/src/containers/CommandsDialogContent/CommandsDialogContent.tsx +127 -0
- package/src/containers/CommandsDialogContent/index.ts +5 -0
- package/src/containers/CommandsTrigger/CommandsTrigger.tsx +28 -0
- package/src/containers/CommandsTrigger/index.ts +5 -0
- package/src/containers/NavTreeContainer/NavTreeContainer.tsx +271 -0
- package/src/containers/NavTreeContainer/index.ts +6 -0
- package/src/{components → containers/NavTreeDocumentTitle}/NavTreeDocumentTitle.tsx +4 -3
- package/src/containers/NavTreeDocumentTitle/index.ts +5 -0
- package/src/containers/index.ts +12 -0
- package/src/experimental/Tree.stories.tsx +82 -85
- package/src/experimental/Tree.tsx +5 -5
- package/src/hooks/index.ts +8 -0
- package/src/hooks/useActions.ts +44 -0
- package/src/hooks/useLoadDescendents.ts +23 -0
- package/src/hooks/useNavTreeModel.ts +120 -0
- package/src/hooks/useNavTreeState.ts +35 -0
- package/src/index.ts +1 -3
- package/src/meta.ts +22 -7
- package/src/operations/expose.ts +42 -0
- package/src/operations/index.ts +7 -0
- package/src/plugin.ts +11 -0
- package/src/testing/app-graph-builder.ts +168 -238
- package/src/testing/generator.ts +35 -38
- package/src/testing/update-state.ts +6 -6
- package/src/translations.ts +8 -10
- package/src/types/NavTreeCapabilities.ts +21 -0
- package/src/types/NavTreeEvents.ts +12 -0
- package/src/types/index.ts +8 -0
- package/src/{types.ts → types/schema.ts} +9 -5
- package/src/util.ts +28 -17
- package/src/vite-env.d.ts +10 -0
- package/dist/lib/browser/app-graph-builder-OHSCN3GX.mjs +0 -46
- package/dist/lib/browser/app-graph-builder-OHSCN3GX.mjs.map +0 -7
- package/dist/lib/browser/chunk-5VLWX4PK.mjs +0 -15
- package/dist/lib/browser/chunk-5VLWX4PK.mjs.map +0 -7
- package/dist/lib/browser/chunk-7D2MPHXV.mjs +0 -1483
- package/dist/lib/browser/chunk-7D2MPHXV.mjs.map +0 -7
- package/dist/lib/browser/chunk-E6MZBCU5.mjs +0 -19
- package/dist/lib/browser/chunk-E6MZBCU5.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -146
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-YUVXVPHG.mjs +0 -47
- package/dist/lib/browser/intent-resolver-YUVXVPHG.mjs.map +0 -7
- package/dist/lib/browser/keyboard-YYTYJW4M.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/react-surface-J7MWWAGD.mjs +0 -51
- package/dist/lib/browser/react-surface-J7MWWAGD.mjs.map +0 -7
- package/dist/lib/browser/state-EUSVT6BI.mjs +0 -117
- package/dist/lib/browser/state-EUSVT6BI.mjs.map +0 -7
- 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/components/CommandsDialog/CommandsDialog.d.ts +0 -5
- package/dist/types/src/components/CommandsDialog/CommandsDialog.d.ts.map +0 -1
- package/dist/types/src/components/CommandsDialog/CommandsTrigger.d.ts.map +0 -1
- package/dist/types/src/components/CommandsDialog/index.d.ts +0 -3
- package/dist/types/src/components/CommandsDialog/index.d.ts.map +0 -1
- package/dist/types/src/components/NavTreeContainer.d.ts +0 -9
- package/dist/types/src/components/NavTreeContainer.d.ts.map +0 -1
- package/dist/types/src/components/NavTreeContext.d.ts.map +0 -1
- package/dist/types/src/components/NavTreeDocumentTitle.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/hooks.d.ts +0 -3
- package/dist/types/src/hooks.d.ts.map +0 -1
- package/dist/types/src/types.d.ts.map +0 -1
- package/src/capabilities/capabilities.ts +0 -20
- package/src/capabilities/intent-resolver.ts +0 -37
- package/src/components/CommandsDialog/CommandsDialog.tsx +0 -126
- package/src/components/CommandsDialog/CommandsTrigger.tsx +0 -36
- package/src/components/CommandsDialog/index.ts +0 -6
- package/src/components/NavTreeContainer.tsx +0 -369
- package/src/events.ts +0 -11
- package/src/hooks.ts +0 -21
- /package/dist/types/src/{components/CommandsDialog → containers/CommandsTrigger}/CommandsTrigger.d.ts +0 -0
|
@@ -2,148 +2,228 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Option from 'effect/Option';
|
|
6
|
+
import React, { memo, useCallback, useMemo } from 'react';
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
8
|
+
import { Node } from '@dxos/app-graph';
|
|
9
|
+
import { isPinnedWorkspace } from '@dxos/app-toolkit';
|
|
10
|
+
import { useAppGraph } from '@dxos/app-toolkit/ui';
|
|
11
|
+
import { Graph, useActionRunner, useEdges } from '@dxos/plugin-graph';
|
|
12
|
+
import { DensityProvider, IconButton, ScrollArea, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
9
13
|
import { Tree } from '@dxos/react-ui-list';
|
|
14
|
+
import { Menu, type MenuItem } from '@dxos/react-ui-menu';
|
|
10
15
|
import { Tabs } from '@dxos/react-ui-tabs';
|
|
11
|
-
import { hoverableControlItem, hoverableOpenControlItem } from '@dxos/
|
|
16
|
+
import { hoverableControlItem, hoverableOpenControlItem } from '@dxos/ui-theme';
|
|
12
17
|
|
|
13
|
-
import {
|
|
18
|
+
import { getListActions, useActions, useLoadDescendents } from '#hooks';
|
|
19
|
+
import { meta } from '#meta';
|
|
20
|
+
|
|
21
|
+
import { NAV_TREE_ITEM } from '../NavTree';
|
|
14
22
|
import { useNavTreeContext } from '../NavTreeContext';
|
|
15
|
-
import { NavTreeItemColumns } from '../NavTreeItem';
|
|
23
|
+
import { NavTreeItemColumns } from '../NavTreeItem/NavTreeItemColumns';
|
|
16
24
|
|
|
17
25
|
export type L1PanelProps = {
|
|
18
26
|
open?: boolean;
|
|
19
27
|
path: string[];
|
|
20
|
-
item: Node
|
|
21
|
-
|
|
28
|
+
item: Node.Node;
|
|
29
|
+
isCurrent: boolean;
|
|
22
30
|
onBack?: () => void;
|
|
23
31
|
};
|
|
24
32
|
|
|
25
33
|
/**
|
|
26
34
|
* Space or settings panel.
|
|
27
35
|
*/
|
|
28
|
-
|
|
36
|
+
const L1Panel$ = ({ open, path, item, isCurrent, onBack }: L1PanelProps) => {
|
|
29
37
|
const { t } = useTranslation(meta.id);
|
|
30
|
-
const { isAlternateTree, ...navTreeContext } = useNavTreeContext();
|
|
31
38
|
const title = toLocalizedString(item.properties.label, t);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const { useItems } = navTreeContext;
|
|
35
|
-
const alternateTree = useItems(item, { disposition: 'alternate-tree' })[0];
|
|
36
|
-
const alternatePath = useMemo(() => [...path, item.id], [item.id, path]);
|
|
37
|
-
const isAlternate = isAlternateTree?.(alternatePath, item) ?? false;
|
|
38
|
-
const useAlternateItems = useCallback(
|
|
39
|
-
(node?: Node, { disposition }: { disposition?: string } = {}) => {
|
|
40
|
-
// TODO(wittjosiah): Sorting is expensive, limit to necessary items for now.
|
|
41
|
-
return useItems(node, { disposition, sort: node?.id === alternateTree.id });
|
|
42
|
-
},
|
|
43
|
-
[alternateTree, useItems],
|
|
44
|
-
);
|
|
39
|
+
const isActivated = useIsActivatedWorkspace(item);
|
|
40
|
+
const shouldRenderContent = isCurrent || isActivated;
|
|
45
41
|
|
|
46
42
|
return (
|
|
47
|
-
<Tabs.
|
|
43
|
+
<Tabs.Panel
|
|
48
44
|
key={item.id}
|
|
49
45
|
value={item.id}
|
|
50
46
|
classNames={[
|
|
51
|
-
'absolute inset-
|
|
52
|
-
'
|
|
53
|
-
'
|
|
54
|
-
|
|
47
|
+
'absolute inset-y-0 end-0',
|
|
48
|
+
'w-[calc(100%-var(--dx-l0-size))] lg:w-(--dx-l1-size) grid-cols-1 grid-rows-[var(--dx-rail-size)_1fr]',
|
|
49
|
+
'py-[env(safe-area-inset-top)]',
|
|
50
|
+
isCurrent && 'grid',
|
|
55
51
|
]}
|
|
56
52
|
tabIndex={-1}
|
|
57
53
|
aria-label={title}
|
|
54
|
+
{...(isCurrent && { 'data-testid': 'navtree.workspace.visible' })}
|
|
58
55
|
{...(!open && { inert: true })}
|
|
59
56
|
>
|
|
60
|
-
{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
57
|
+
{shouldRenderContent && <L1PanelContent open={open} path={path} item={item} onBack={onBack} />}
|
|
58
|
+
</Tabs.Panel>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/** Determines whether a workspace tab has been populated with real child content (i.e. expanded at least once). */
|
|
63
|
+
const useIsActivatedWorkspace = (item: Node.Node): boolean => {
|
|
64
|
+
const { graph } = useAppGraph();
|
|
65
|
+
const edges = useEdges(graph, item.id);
|
|
66
|
+
|
|
67
|
+
return useMemo(() => {
|
|
68
|
+
const childIds = edges[Graph.relationKey('child')] ?? [];
|
|
69
|
+
return childIds.some((childId) => {
|
|
70
|
+
const child = Graph.getNode(graph, childId);
|
|
71
|
+
if (Option.isNone(child)) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return child.value.properties.disposition === undefined;
|
|
75
|
+
});
|
|
76
|
+
}, [edges, graph]);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Mounted panel content for active or previously-visited tabs.
|
|
81
|
+
*/
|
|
82
|
+
const L1PanelContent = ({ path, item, onBack }: Pick<L1PanelProps, 'open' | 'path' | 'item' | 'onBack'>) => {
|
|
83
|
+
const navTreeContext = useNavTreeContext();
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<DensityProvider density='md'>
|
|
87
|
+
<L1PanelHeader path={path} item={item} onBack={onBack} />
|
|
88
|
+
<ScrollArea.Root thin orientation='vertical'>
|
|
89
|
+
<ScrollArea.Viewport>
|
|
90
|
+
<Tree
|
|
91
|
+
classNames='pt-[2px]'
|
|
92
|
+
model={navTreeContext.model}
|
|
93
|
+
id={item.id}
|
|
94
|
+
rootId={item.id}
|
|
95
|
+
path={path}
|
|
96
|
+
levelOffset={5}
|
|
97
|
+
draggable
|
|
98
|
+
gridTemplateColumns='[tree-row-start] minmax(0, 1fr) min-content min-content [tree-row-end]'
|
|
99
|
+
renderColumns={NavTreeItemColumns}
|
|
100
|
+
blockInstruction={navTreeContext.blockInstruction}
|
|
101
|
+
canDrop={navTreeContext.canDrop}
|
|
102
|
+
canSelect={navTreeContext.canSelect}
|
|
103
|
+
onOpenChange={navTreeContext.onOpenChange}
|
|
104
|
+
onSelect={navTreeContext.onSelect}
|
|
105
|
+
onItemHover={navTreeContext.onItemHover}
|
|
106
|
+
/>
|
|
107
|
+
</ScrollArea.Viewport>
|
|
108
|
+
</ScrollArea.Root>
|
|
109
|
+
</DensityProvider>
|
|
91
110
|
);
|
|
92
111
|
};
|
|
93
112
|
|
|
94
113
|
/**
|
|
95
114
|
* Header row.
|
|
96
115
|
*/
|
|
97
|
-
const L1PanelHeader = ({ item, path, onBack }: L1PanelProps) => {
|
|
116
|
+
const L1PanelHeader = ({ item, path, onBack }: Pick<L1PanelProps, 'item' | 'path' | 'onBack'>) => {
|
|
98
117
|
const { t } = useTranslation(meta.id);
|
|
99
|
-
const {
|
|
118
|
+
const { renderItemEnd: ItemEnd } = useNavTreeContext();
|
|
100
119
|
const title = toLocalizedString(item.properties.label, t);
|
|
120
|
+
const backCapableWorkspace = isPinnedWorkspace(item.id);
|
|
121
|
+
|
|
122
|
+
const { menuActions, onAction } = useL1MenuActions({ item, path });
|
|
123
|
+
useLoadDescendents(item);
|
|
101
124
|
|
|
102
|
-
// TODO(wittjosiah): Support multiple alternate trees.
|
|
103
|
-
const alternateTree = navTreeContext.useItems(item, { disposition: 'alternate-tree' })[0];
|
|
104
|
-
const alternatePath = useMemo(() => [...path, item.id], [item.id, path]);
|
|
105
|
-
const isAlternate = isAlternateTree?.(alternatePath, item) ?? false;
|
|
106
|
-
const backCapable = item.id.startsWith('!') || isAlternate;
|
|
107
|
-
|
|
108
|
-
const handleOpen = useCallback(() => {
|
|
109
|
-
setAlternateTree?.(alternatePath, true);
|
|
110
|
-
}, [alternatePath, setAlternateTree]);
|
|
111
|
-
|
|
112
|
-
const handleBack = useCallback(() => {
|
|
113
|
-
if (isAlternate) {
|
|
114
|
-
setAlternateTree?.(alternatePath, false);
|
|
115
|
-
} else {
|
|
116
|
-
onBack?.();
|
|
117
|
-
}
|
|
118
|
-
}, [isAlternate, alternatePath, setAlternateTree, onBack]);
|
|
119
|
-
|
|
120
|
-
// TODO(burdon): Reuse same grid as tree?
|
|
121
125
|
return (
|
|
122
|
-
<div
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
+
<div
|
|
127
|
+
data-tauri-drag-region
|
|
128
|
+
className='grid grid-cols-[28px_1fr_min-content_min-content] w-full items-center dx-app-drag dx-density-lg'
|
|
129
|
+
>
|
|
130
|
+
{backCapableWorkspace ? (
|
|
126
131
|
<IconButton
|
|
132
|
+
classNames={[hoverableControlItem, hoverableOpenControlItem]}
|
|
127
133
|
variant='ghost'
|
|
128
|
-
icon='ph--
|
|
134
|
+
icon='ph--caret-left--regular'
|
|
129
135
|
iconOnly
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
136
|
+
size={4}
|
|
137
|
+
label={t('button-back.button')}
|
|
138
|
+
data-testid='treeView.primaryTreeButton'
|
|
139
|
+
onClick={() => onBack?.()}
|
|
133
140
|
/>
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
/>
|
|
145
|
-
))}
|
|
146
|
-
<NavTreeItemColumns open path={path} item={item} density='coarse' />
|
|
141
|
+
) : (
|
|
142
|
+
<div />
|
|
143
|
+
)}
|
|
144
|
+
<h2 data-tauri-drag-region className='flex-1 truncate min-w-0'>
|
|
145
|
+
{title}
|
|
146
|
+
</h2>
|
|
147
|
+
<div className='contents dx-app-no-drag'>
|
|
148
|
+
<MenuActions item={item} menuActions={menuActions} onAction={onAction} />
|
|
149
|
+
{ItemEnd && <ItemEnd node={item} open />}
|
|
150
|
+
</div>
|
|
147
151
|
</div>
|
|
148
152
|
);
|
|
149
153
|
};
|
|
154
|
+
|
|
155
|
+
type L1MenuActions = {
|
|
156
|
+
menuActions: Node.Action[];
|
|
157
|
+
onAction: (action: Node.Action, params?: Node.InvokeProps) => void;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Header menu actions for an L1 workspace tab. Renders nothing for an empty
|
|
162
|
+
* `menuActions`, a single inline icon button for one action, and a
|
|
163
|
+
* `…`-menu trigger for multiple.
|
|
164
|
+
*/
|
|
165
|
+
const MenuActions = ({
|
|
166
|
+
item,
|
|
167
|
+
menuActions,
|
|
168
|
+
onAction,
|
|
169
|
+
}: {
|
|
170
|
+
item: Node.Node;
|
|
171
|
+
} & Pick<L1MenuActions, 'menuActions' | 'onAction'>) => {
|
|
172
|
+
const { t } = useTranslation(meta.id);
|
|
173
|
+
|
|
174
|
+
if (menuActions.length === 0) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (menuActions.length === 1) {
|
|
179
|
+
return (
|
|
180
|
+
<IconButton
|
|
181
|
+
classNames={['shrink-0 px-2 pointer-fine:px-1', hoverableControlItem, hoverableOpenControlItem]}
|
|
182
|
+
variant='ghost'
|
|
183
|
+
icon={menuActions[0].properties?.icon ?? 'ph--circle-dashed--regular'}
|
|
184
|
+
iconOnly
|
|
185
|
+
size={4}
|
|
186
|
+
label={toLocalizedString(menuActions[0].properties?.label, t)}
|
|
187
|
+
data-testid={menuActions[0].properties?.testId}
|
|
188
|
+
onClick={() => onAction(menuActions[0] as Node.Action)}
|
|
189
|
+
/>
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return (
|
|
194
|
+
<Menu.Root caller={NAV_TREE_ITEM} onAction={onAction}>
|
|
195
|
+
<Menu.Trigger asChild>
|
|
196
|
+
<IconButton
|
|
197
|
+
classNames={['shrink-0 px-2 pointer-fine:px-1', hoverableControlItem, hoverableOpenControlItem]}
|
|
198
|
+
variant='ghost'
|
|
199
|
+
icon='ph--dots-three-vertical--regular'
|
|
200
|
+
iconOnly
|
|
201
|
+
size={4}
|
|
202
|
+
label={t('tree-item-actions.label')}
|
|
203
|
+
data-testid='navtree.treeItem.actionsLevel0'
|
|
204
|
+
/>
|
|
205
|
+
</Menu.Trigger>
|
|
206
|
+
<Menu.Content group={item} items={menuActions as MenuItem[]} />
|
|
207
|
+
</Menu.Root>
|
|
208
|
+
);
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Builds the menu actions for the L1 panel header.
|
|
213
|
+
*/
|
|
214
|
+
const useL1MenuActions = ({ item, path }: Pick<L1PanelProps, 'item' | 'path'>): L1MenuActions => {
|
|
215
|
+
const runAction = useActionRunner();
|
|
216
|
+
|
|
217
|
+
const menuActions = getListActions(useActions(item));
|
|
218
|
+
|
|
219
|
+
const onAction = useCallback(
|
|
220
|
+
(action: Node.Action, params?: Node.InvokeProps) => {
|
|
221
|
+
void runAction(action, { ...params, path });
|
|
222
|
+
},
|
|
223
|
+
[runAction, path],
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
return { menuActions, onAction };
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
export const L1Panel = memo(L1Panel$);
|
|
@@ -2,57 +2,41 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React
|
|
5
|
+
import React from 'react';
|
|
6
6
|
|
|
7
7
|
import { type Node } from '@dxos/app-graph';
|
|
8
8
|
|
|
9
|
-
import { useLoadDescendents } from '../../hooks';
|
|
10
9
|
import { l0ItemType } from '../../util';
|
|
11
|
-
import { useNavTreeContext } from '../NavTreeContext';
|
|
12
|
-
|
|
13
10
|
import { L1Panel, type L1PanelProps } from './L1Panel';
|
|
14
11
|
|
|
15
|
-
export type L1TabsProps = Pick<L1PanelProps, 'open' | '
|
|
12
|
+
export type L1TabsProps = Pick<L1PanelProps, 'open' | 'onBack'> & {
|
|
13
|
+
currentItemId: string;
|
|
16
14
|
path: string[];
|
|
17
|
-
topLevelItems: Node
|
|
15
|
+
topLevelItems: Node.Node[];
|
|
18
16
|
};
|
|
19
17
|
|
|
20
18
|
/**
|
|
21
|
-
* Each
|
|
19
|
+
* Each workspace is an L1 tab.
|
|
22
20
|
*/
|
|
23
|
-
export const L1Tabs = ({ topLevelItems, onBack,
|
|
21
|
+
export const L1Tabs = ({ topLevelItems, currentItemId, onBack, open, path }: L1TabsProps) => {
|
|
24
22
|
return (
|
|
25
23
|
<>
|
|
26
24
|
{topLevelItems.map((item) => {
|
|
27
25
|
const type = l0ItemType(item);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
if (type === 'tab') {
|
|
27
|
+
return (
|
|
28
|
+
<L1Panel
|
|
29
|
+
key={item.id}
|
|
30
|
+
item={item}
|
|
31
|
+
path={path}
|
|
32
|
+
open={open}
|
|
33
|
+
onBack={onBack}
|
|
34
|
+
isCurrent={item.id === currentItemId}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
35
37
|
}
|
|
38
|
+
return null;
|
|
36
39
|
})}
|
|
37
40
|
</>
|
|
38
41
|
);
|
|
39
42
|
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
*
|
|
43
|
-
*/
|
|
44
|
-
const L1PanelCollection = ({ item, path, ...props }: L1PanelProps) => {
|
|
45
|
-
const { useItems } = useNavTreeContext();
|
|
46
|
-
useLoadDescendents(item);
|
|
47
|
-
const collectionItems = useItems(item);
|
|
48
|
-
const groupPath = useMemo(() => [...path, item.id], [item.id, path]);
|
|
49
|
-
return (
|
|
50
|
-
<>
|
|
51
|
-
{collectionItems
|
|
52
|
-
.filter((item) => l0ItemType(item) === 'tab')
|
|
53
|
-
.map((item) => (
|
|
54
|
-
<L1Panel key={item.id} item={item} path={groupPath} {...props} />
|
|
55
|
-
))}
|
|
56
|
-
</>
|
|
57
|
-
);
|
|
58
|
-
};
|
|
@@ -9,9 +9,8 @@ import { withTheme } from '@dxos/react-ui/testing';
|
|
|
9
9
|
import { UserAccountAvatar } from './UserAccountAvatar';
|
|
10
10
|
|
|
11
11
|
const meta = {
|
|
12
|
-
title: 'plugins/plugin-navtree/UserAccountAvatar',
|
|
13
|
-
|
|
14
|
-
decorators: [withTheme],
|
|
12
|
+
title: 'plugins/plugin-navtree/components/UserAccountAvatar',
|
|
13
|
+
decorators: [withTheme()],
|
|
15
14
|
component: UserAccountAvatar,
|
|
16
15
|
} satisfies Meta<typeof UserAccountAvatar>;
|
|
17
16
|
|
|
@@ -22,7 +22,7 @@ export const UserAccountAvatar = ({ size, userId, hue, emoji, status }: UserAcco
|
|
|
22
22
|
|
|
23
23
|
return (
|
|
24
24
|
<>
|
|
25
|
-
<L0ItemActiveTabIndicator classNames='inset-
|
|
25
|
+
<L0ItemActiveTabIndicator classNames='inset-y-6' />
|
|
26
26
|
<div
|
|
27
27
|
className='grid place-items-center dx-focus-ring-group-indicator rounded-full'
|
|
28
28
|
data-joyride='welcome/account'
|
package/src/components/index.ts
CHANGED
package/src/components/types.ts
CHANGED
|
@@ -4,34 +4,28 @@
|
|
|
4
4
|
|
|
5
5
|
import type { FC } from 'react';
|
|
6
6
|
|
|
7
|
-
import type
|
|
7
|
+
import { type Node } from '@dxos/app-graph';
|
|
8
8
|
import type { Density } from '@dxos/react-ui';
|
|
9
|
-
import type { TreeProps } from '@dxos/react-ui-list';
|
|
10
|
-
import type { MaybePromise } from '@dxos/util';
|
|
9
|
+
import type { TreeModel, TreeProps } from '@dxos/react-ui-list';
|
|
11
10
|
|
|
12
|
-
import type {
|
|
11
|
+
import type { NavTreeItemGraphNode } from '#types';
|
|
13
12
|
|
|
14
13
|
import type { L1PanelProps } from './Sidebar';
|
|
15
14
|
|
|
16
|
-
export type NavTreeContextValue =
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
export type NavTreeContextValue = {
|
|
16
|
+
model: TreeModel<NavTreeItemGraphNode>;
|
|
17
|
+
popoverAnchorId?: string;
|
|
18
|
+
renderItemEnd?: FC<{ node: Node.Node; open: boolean }>;
|
|
19
|
+
onTabChange?: (node: NavTreeItemGraphNode) => void;
|
|
20
|
+
} & Pick<
|
|
21
|
+
TreeProps<NavTreeItemGraphNode>,
|
|
22
|
+
'blockInstruction' | 'canDrop' | 'canSelect' | 'onOpenChange' | 'onSelect' | 'onItemHover'
|
|
19
23
|
> &
|
|
20
|
-
Pick<L1PanelProps, 'onBack'
|
|
21
|
-
tab: string;
|
|
22
|
-
topbar?: boolean;
|
|
23
|
-
popoverAnchorId?: string;
|
|
24
|
-
renderItemEnd?: FC<{ node: Node; open: boolean }>;
|
|
25
|
-
useActions: (node: Node) => FlattenedActions;
|
|
26
|
-
loadDescendents?: (node: Node) => MaybePromise<void>;
|
|
27
|
-
isAlternateTree?: (path: string[], item: NavTreeItemGraphNode) => boolean;
|
|
28
|
-
setAlternateTree?: (path: string[], open: boolean) => void;
|
|
29
|
-
onTabChange?: (node: NavTreeItemGraphNode) => void;
|
|
30
|
-
};
|
|
24
|
+
Pick<L1PanelProps, 'onBack'>;
|
|
31
25
|
|
|
32
26
|
export type NavTreeItemColumnsProps = {
|
|
33
27
|
path: string[];
|
|
34
|
-
item: Node;
|
|
28
|
+
item: Node.Node;
|
|
35
29
|
open: boolean;
|
|
36
30
|
density?: Density;
|
|
37
31
|
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
import { withPluginManager } from '@dxos/app-framework/testing';
|
|
9
|
+
import { StorybookPlugin, corePlugins } from '@dxos/plugin-testing';
|
|
10
|
+
import { Dialog } from '@dxos/react-ui';
|
|
11
|
+
import { withLayout } from '@dxos/react-ui/testing';
|
|
12
|
+
|
|
13
|
+
import { translations } from '#translations';
|
|
14
|
+
|
|
15
|
+
import { NavTreePlugin } from '../../NavTreePlugin';
|
|
16
|
+
import { CommandsDialogContent } from './CommandsDialogContent';
|
|
17
|
+
|
|
18
|
+
const DefaultStory = () => (
|
|
19
|
+
<Dialog.Root defaultOpen>
|
|
20
|
+
<Dialog.Overlay>
|
|
21
|
+
<CommandsDialogContent />
|
|
22
|
+
</Dialog.Overlay>
|
|
23
|
+
</Dialog.Root>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const meta = {
|
|
27
|
+
title: 'plugins/plugin-navtree/containers/CommandsDialogContent',
|
|
28
|
+
component: CommandsDialogContent,
|
|
29
|
+
render: DefaultStory,
|
|
30
|
+
decorators: [
|
|
31
|
+
withLayout({ layout: 'fullscreen' }),
|
|
32
|
+
withPluginManager({
|
|
33
|
+
plugins: [...corePlugins(), StorybookPlugin({}), NavTreePlugin()],
|
|
34
|
+
}),
|
|
35
|
+
],
|
|
36
|
+
parameters: {
|
|
37
|
+
layout: 'fullscreen',
|
|
38
|
+
translations,
|
|
39
|
+
},
|
|
40
|
+
} satisfies Meta<typeof CommandsDialogContent>;
|
|
41
|
+
|
|
42
|
+
export default meta;
|
|
43
|
+
|
|
44
|
+
type Story = StoryObj<typeof meta>;
|
|
45
|
+
|
|
46
|
+
export const Default: Story = {};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { forwardRef, useMemo, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { useOperationInvoker } from '@dxos/app-framework/ui';
|
|
8
|
+
import { LayoutOperation } from '@dxos/app-toolkit';
|
|
9
|
+
import { useAppGraph } from '@dxos/app-toolkit/ui';
|
|
10
|
+
import { Keyboard, keySymbols } from '@dxos/keyboard';
|
|
11
|
+
import { Graph, Node, useActionRunner } from '@dxos/plugin-graph';
|
|
12
|
+
import { useActions } from '@dxos/plugin-graph';
|
|
13
|
+
import { Button, Dialog, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
14
|
+
import { SearchList, useSearchListResults } from '@dxos/react-ui-search';
|
|
15
|
+
import { osTranslations } from '@dxos/ui-theme';
|
|
16
|
+
import { getHostPlatform } from '@dxos/util';
|
|
17
|
+
|
|
18
|
+
import { KEY_BINDING, meta } from '#meta';
|
|
19
|
+
|
|
20
|
+
export type CommandsDialogContentProps = {
|
|
21
|
+
selected?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// TODO(wittjosiah): This probably deserves its own plugin but for now it lives here w/ other navigation UI.
|
|
25
|
+
export const CommandsDialogContent = forwardRef<HTMLDivElement, CommandsDialogContentProps>(
|
|
26
|
+
({ selected: initial }, forwardedRef) => {
|
|
27
|
+
const { t } = useTranslation(meta.id);
|
|
28
|
+
const { invokePromise } = useOperationInvoker();
|
|
29
|
+
const runAction = useActionRunner();
|
|
30
|
+
const { graph } = useAppGraph();
|
|
31
|
+
const [selected, setSelected] = useState<string | undefined>(initial);
|
|
32
|
+
|
|
33
|
+
// Traverse graph.
|
|
34
|
+
// TODO(burdon): Factor out commonality with shortcut dialog.
|
|
35
|
+
const allActions = useMemo(() => {
|
|
36
|
+
// TODO(burdon): Get from navtree (not keyboard).
|
|
37
|
+
const current = Keyboard.singleton.getCurrentContext();
|
|
38
|
+
const actionMap = new Set<string>();
|
|
39
|
+
const actions: Node.ActionLike[] = [];
|
|
40
|
+
Graph.traverse(graph, {
|
|
41
|
+
relation: ['child', 'action'],
|
|
42
|
+
visitor: (node, path) => {
|
|
43
|
+
const isActionLike = Node.isAction(node) || Node.isActionGroup(node);
|
|
44
|
+
const parentId = path.at(-2) ?? '';
|
|
45
|
+
const matches = current === parentId || current.startsWith(parentId + '/');
|
|
46
|
+
if (isActionLike && !actionMap.has(node.id) && matches) {
|
|
47
|
+
actionMap.add(node.id);
|
|
48
|
+
actions.push(node);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
actions.sort((a, b) => {
|
|
54
|
+
return toLocalizedString(a.properties.label, t)
|
|
55
|
+
?.toLowerCase()
|
|
56
|
+
.localeCompare(toLocalizedString(b.properties.label, t)?.toLowerCase());
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return actions;
|
|
60
|
+
}, [graph]);
|
|
61
|
+
|
|
62
|
+
const group = allActions.find(({ id }) => id === selected);
|
|
63
|
+
const groupActions = useActions(graph, group?.id);
|
|
64
|
+
const actions = Node.isActionGroup(group) ? groupActions : allActions;
|
|
65
|
+
|
|
66
|
+
const { results, handleSearch } = useSearchListResults({
|
|
67
|
+
items: actions,
|
|
68
|
+
extract: (action) => toLocalizedString(action.properties.label, t),
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<Dialog.Content ref={forwardedRef}>
|
|
73
|
+
<Dialog.Title srOnly>{t('commands-dialog.title', { ns: meta.id })}</Dialog.Title>
|
|
74
|
+
<SearchList.Root onSearch={handleSearch}>
|
|
75
|
+
<SearchList.Input placeholder={t('command-list-input.placeholder')} />
|
|
76
|
+
<SearchList.Viewport>
|
|
77
|
+
{results.map((action) => {
|
|
78
|
+
const shortcut =
|
|
79
|
+
typeof action.properties.keyBinding === 'string'
|
|
80
|
+
? action.properties.keyBinding
|
|
81
|
+
: action.properties.keyBinding?.[getHostPlatform()];
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<SearchList.Item
|
|
85
|
+
value={action.id}
|
|
86
|
+
key={action.id}
|
|
87
|
+
label={toLocalizedString(action.properties.label, t)}
|
|
88
|
+
icon={action.properties.icon}
|
|
89
|
+
suffix={shortcut ? keySymbols(shortcut).join('') : undefined}
|
|
90
|
+
onSelect={() => {
|
|
91
|
+
if (action.properties.disabled) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (Node.isActionGroup(action)) {
|
|
96
|
+
setSelected(action.id);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
void invokePromise(LayoutOperation.UpdateDialog, { state: false });
|
|
101
|
+
setTimeout(() => {
|
|
102
|
+
const lookupId = group?.id ?? action.id;
|
|
103
|
+
const node = Graph.getConnections(graph, lookupId, Node.actionRelation('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.Root>
|
|
119
|
+
<Dialog.ActionBar>
|
|
120
|
+
<Dialog.Close asChild>
|
|
121
|
+
<Button classNames='w-full'>{t('close.label', { ns: osTranslations })}</Button>
|
|
122
|
+
</Dialog.Close>
|
|
123
|
+
</Dialog.ActionBar>
|
|
124
|
+
</Dialog.Content>
|
|
125
|
+
);
|
|
126
|
+
},
|
|
127
|
+
);
|