@dxos/plugin-navtree 0.8.4-main.406dc2a → 0.8.4-main.4a85c3132b
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/CommandsDialogContent-A27AKTHH.mjs +111 -0
- package/dist/lib/browser/CommandsDialogContent-A27AKTHH.mjs.map +7 -0
- package/dist/lib/browser/CommandsTrigger-HBZYQCGV.mjs +33 -0
- package/dist/lib/browser/CommandsTrigger-HBZYQCGV.mjs.map +7 -0
- package/dist/lib/browser/NavTreeContainer-B5K4FUJS.mjs +12 -0
- package/dist/lib/browser/NavTreeContainer-B5K4FUJS.mjs.map +7 -0
- package/dist/lib/browser/NavTreeDocumentTitle-GEE3URWH.mjs +26 -0
- package/dist/lib/browser/NavTreeDocumentTitle-GEE3URWH.mjs.map +7 -0
- package/dist/lib/browser/app-graph-builder-XGA4GPGL.mjs +44 -0
- package/dist/lib/browser/app-graph-builder-XGA4GPGL.mjs.map +7 -0
- package/dist/lib/browser/chunk-DQCYMXEU.mjs +1426 -0
- package/dist/lib/browser/chunk-DQCYMXEU.mjs.map +7 -0
- package/dist/lib/browser/chunk-H3OJ4WLF.mjs +14 -0
- package/dist/lib/browser/chunk-H3OJ4WLF.mjs.map +7 -0
- package/dist/lib/browser/chunk-X2HDG62A.mjs +23 -0
- package/dist/lib/browser/chunk-X2HDG62A.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 +86 -91
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/{keyboard-AHSAWKXA.mjs → keyboard-OJZC54PK.mjs} +22 -19
- package/dist/lib/browser/keyboard-OJZC54PK.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/operation-resolver-BNAMYOHF.mjs +53 -0
- package/dist/lib/browser/operation-resolver-BNAMYOHF.mjs.map +7 -0
- package/dist/lib/browser/react-surface-AYHOAJ4I.mjs +59 -0
- package/dist/lib/browser/react-surface-AYHOAJ4I.mjs.map +7 -0
- package/dist/lib/browser/state-AC3EETN7.mjs +131 -0
- package/dist/lib/browser/state-AC3EETN7.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 -108
- 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/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 +2 -2
- package/dist/types/src/components/NavTree/NavTree.stories.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 +2 -1
- 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.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 -16
- 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/index.d.ts +3 -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 +3 -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 +3 -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.stories.d.ts +15 -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 +7 -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 +22 -0
- package/dist/types/src/hooks/useNavTreeState.d.ts.map +1 -0
- 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 +2 -2
- 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} +7 -7
- package/dist/types/src/types/schema.d.ts.map +1 -0
- package/dist/types/src/util.d.ts +11 -7
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +55 -53
- package/src/NavTreePlugin.tsx +54 -73
- package/src/capabilities/app-graph-builder/app-graph-builder.ts +42 -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 +66 -0
- package/src/capabilities/operation-resolver/index.ts +7 -0
- package/src/capabilities/operation-resolver/operation-resolver.ts +44 -0
- package/src/capabilities/react-surface/index.ts +7 -0
- package/src/capabilities/react-surface/react-surface.tsx +53 -0
- package/src/capabilities/state/index.ts +7 -0
- package/src/capabilities/state/state.ts +149 -0
- package/src/components/NavTree/NavTree.stories.tsx +44 -51
- package/src/components/NavTree/NavTree.tsx +63 -32
- package/src/components/NavTreeItem/NavTreeItemAction.stories.tsx +18 -8
- package/src/components/NavTreeItem/NavTreeItemAction.tsx +33 -28
- package/src/components/NavTreeItem/NavTreeItemColumns.tsx +39 -15
- package/src/components/Sidebar/L0Menu.tsx +145 -155
- package/src/components/Sidebar/L1Panel.tsx +231 -94
- package/src/components/Sidebar/L1Tabs.tsx +18 -33
- 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 +14 -19
- package/src/containers/CommandsDialogContent/CommandsDialogContent.tsx +133 -0
- package/src/containers/CommandsDialogContent/index.ts +7 -0
- package/src/{components/CommandsDialog → containers/CommandsTrigger}/CommandsTrigger.tsx +5 -14
- package/src/containers/CommandsTrigger/index.ts +7 -0
- package/src/containers/NavTreeContainer/NavTreeContainer.tsx +270 -0
- package/src/containers/NavTreeContainer/index.ts +7 -0
- package/src/{components → containers/NavTreeDocumentTitle}/NavTreeDocumentTitle.tsx +4 -3
- package/src/containers/NavTreeDocumentTitle/index.ts +7 -0
- package/src/containers/index.ts +12 -0
- package/src/experimental/Tree.stories.tsx +54 -60
- package/src/experimental/Tree.tsx +3 -3
- package/src/hooks/index.ts +8 -0
- package/src/hooks/useActions.ts +38 -0
- package/src/hooks/useLoadDescendents.ts +23 -0
- package/src/hooks/useNavTreeModel.ts +112 -0
- package/src/hooks/useNavTreeState.ts +42 -0
- package/src/index.ts +1 -2
- package/src/meta.ts +7 -2
- package/src/testing/app-graph-builder.ts +159 -235
- package/src/testing/generator.ts +19 -17
- package/src/testing/update-state.ts +6 -6
- package/src/types/capabilities.ts +21 -0
- package/src/types/events.ts +12 -0
- package/src/types/index.ts +7 -0
- package/src/{types.ts → types/schema.ts} +6 -6
- package/src/util.ts +27 -16
- package/dist/lib/browser/app-graph-builder-YAPMENYT.mjs +0 -46
- package/dist/lib/browser/app-graph-builder-YAPMENYT.mjs.map +0 -7
- package/dist/lib/browser/chunk-IMFXKPSB.mjs +0 -1482
- package/dist/lib/browser/chunk-IMFXKPSB.mjs.map +0 -7
- package/dist/lib/browser/chunk-LPAREX6J.mjs +0 -15
- package/dist/lib/browser/chunk-LPAREX6J.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZENLR72O.mjs +0 -14
- package/dist/lib/browser/chunk-ZENLR72O.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-TCQXGF6U.mjs +0 -47
- package/dist/lib/browser/intent-resolver-TCQXGF6U.mjs.map +0 -7
- package/dist/lib/browser/keyboard-AHSAWKXA.mjs.map +0 -7
- package/dist/lib/browser/react-surface-AH2TP73M.mjs +0 -51
- package/dist/lib/browser/react-surface-AH2TP73M.mjs.map +0 -7
- package/dist/lib/browser/state-2Q623V7U.mjs +0 -117
- package/dist/lib/browser/state-2Q623V7U.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/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/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/app-graph-builder.ts +0 -53
- 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/components/CommandsDialog/CommandsDialog.tsx +0 -118
- package/src/components/CommandsDialog/index.ts +0 -6
- package/src/components/NavTreeContainer.tsx +0 -346
- 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
|
@@ -4,29 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { useOperationInvoker } from '@dxos/app-framework/ui';
|
|
8
|
+
import { LayoutOperation } from '@dxos/app-toolkit';
|
|
8
9
|
import { Button, Icon, useTranslation } from '@dxos/react-ui';
|
|
9
10
|
|
|
10
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 { invokeSync } = useOperationInvoker();
|
|
15
16
|
const { t } = useTranslation(meta.id);
|
|
16
17
|
return (
|
|
17
18
|
<Button
|
|
18
|
-
classNames='m-1
|
|
19
|
-
onClick={() =>
|
|
20
|
-
dispatch(
|
|
21
|
-
createIntent(LayoutAction.UpdateDialog, {
|
|
22
|
-
part: 'dialog',
|
|
23
|
-
subject: COMMANDS_DIALOG,
|
|
24
|
-
options: {
|
|
25
|
-
blockAlign: 'start',
|
|
26
|
-
},
|
|
27
|
-
}),
|
|
28
|
-
)
|
|
29
|
-
}
|
|
19
|
+
classNames='m-1 px-1 lg:px-2'
|
|
20
|
+
onClick={() => invokeSync(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} />
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
6
|
+
import { type Instruction, extractInstruction } from '@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item';
|
|
7
|
+
import React, { forwardRef, memo, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
8
|
+
|
|
9
|
+
import { Surface, useOperationInvoker } from '@dxos/app-framework/ui';
|
|
10
|
+
import { LayoutOperation } from '@dxos/app-toolkit';
|
|
11
|
+
import { useAppGraph, useLayout } from '@dxos/app-toolkit/ui';
|
|
12
|
+
import { Graph, Node, useActionRunner } from '@dxos/plugin-graph';
|
|
13
|
+
import { useMediaQuery, useSidebars } from '@dxos/react-ui';
|
|
14
|
+
import { type TreeData, isTreeData } from '@dxos/react-ui-list';
|
|
15
|
+
import { arrayMove } from '@dxos/util';
|
|
16
|
+
|
|
17
|
+
import { NAV_TREE_ITEM, NavTree, NavTreeContext } from '../../components';
|
|
18
|
+
import { useNavTreeModel, useNavTreeState } from '../../hooks';
|
|
19
|
+
import { meta } from '../../meta';
|
|
20
|
+
import { type NavTreeItemGraphNode } from '../../types';
|
|
21
|
+
import { filterItems, getParent, resolveMigrationOperation } from '../../util';
|
|
22
|
+
|
|
23
|
+
// TODO(thure): Is NavTree truly authoritative in this regard?
|
|
24
|
+
export const NODE_TYPE = 'dxos/app-graph/node';
|
|
25
|
+
|
|
26
|
+
// TODO(wittjosiah): Avoid using Surface within the navtree, prefer declarative data flow.
|
|
27
|
+
const NavTreeItemEnd = ({ node, open }: { node: Node.Node; open: boolean }) => {
|
|
28
|
+
const data = useMemo(() => ({ id: node.id, subject: node.data, open }), [node.id, node.data, open]);
|
|
29
|
+
return <Surface.Surface role='navtree-item-end' data={data} limit={1} />;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const getItems = (graph: Graph.ReadableGraph, node?: Node.Node, disposition?: string) => {
|
|
33
|
+
return Graph.getConnections(graph, node?.id ?? Node.RootId, 'child').filter((node) => filterItems(node, disposition));
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type NavTreeContainerProps = {
|
|
37
|
+
popoverAnchorId?: string;
|
|
38
|
+
tab: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const NavTreeContainer$ = forwardRef<HTMLDivElement, NavTreeContainerProps>(
|
|
42
|
+
({ tab, popoverAnchorId }, forwardedRef) => {
|
|
43
|
+
const [isLg] = useMediaQuery('lg');
|
|
44
|
+
const { invokeSync, invokePromise } = useOperationInvoker();
|
|
45
|
+
const runAction = useActionRunner();
|
|
46
|
+
const { graph } = useAppGraph();
|
|
47
|
+
const { getItem, setItem } = useNavTreeState();
|
|
48
|
+
const layout = useLayout();
|
|
49
|
+
const model = useNavTreeModel(Node.RootId);
|
|
50
|
+
const { navigationSidebarState } = useSidebars(meta.id);
|
|
51
|
+
const latestRef = useRef({
|
|
52
|
+
tab,
|
|
53
|
+
activeItems: layout.active,
|
|
54
|
+
navigationSidebarState,
|
|
55
|
+
isLg,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
latestRef.current = {
|
|
60
|
+
tab,
|
|
61
|
+
activeItems: layout.active,
|
|
62
|
+
navigationSidebarState,
|
|
63
|
+
isLg,
|
|
64
|
+
};
|
|
65
|
+
}, [tab, layout.active, navigationSidebarState, isLg]);
|
|
66
|
+
|
|
67
|
+
const handleOpenChange = useCallback(
|
|
68
|
+
({ item: { id }, path, open }: { item: Node.Node; path: string[]; open: boolean }) => {
|
|
69
|
+
// TODO(thure): This might become a localstorage leak; openItemIds that no longer exist should be removed from this map.
|
|
70
|
+
setItem(path, 'open', open);
|
|
71
|
+
Graph.expand(graph, id, 'child');
|
|
72
|
+
},
|
|
73
|
+
[graph, setItem],
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const handleTabChange = useCallback(
|
|
77
|
+
(node: NavTreeItemGraphNode) => {
|
|
78
|
+
Graph.expand(graph, node.id, 'child');
|
|
79
|
+
|
|
80
|
+
const {
|
|
81
|
+
tab: activeTab,
|
|
82
|
+
activeItems,
|
|
83
|
+
navigationSidebarState: currentSidebarState,
|
|
84
|
+
isLg: latestIsLg,
|
|
85
|
+
} = latestRef.current;
|
|
86
|
+
invokeSync(LayoutOperation.UpdateSidebar, {
|
|
87
|
+
state:
|
|
88
|
+
node.id === activeTab
|
|
89
|
+
? currentSidebarState === 'expanded'
|
|
90
|
+
? latestIsLg
|
|
91
|
+
? 'collapsed'
|
|
92
|
+
: 'closed'
|
|
93
|
+
: 'expanded'
|
|
94
|
+
: 'expanded',
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
invokeSync(LayoutOperation.SwitchWorkspace, { subject: node.id });
|
|
98
|
+
|
|
99
|
+
// Open the first item if the workspace is empty.
|
|
100
|
+
if (activeItems.length === 0) {
|
|
101
|
+
const [item] = getItems(graph, node).filter((node) => !Node.isActionLike(node));
|
|
102
|
+
if (item && item.data) {
|
|
103
|
+
invokeSync(LayoutOperation.Open, { subject: [item.id] });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
[invokeSync, graph],
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const blockInstruction = useCallback(
|
|
111
|
+
({ instruction, source, target }: { instruction: Instruction; source: TreeData; target: TreeData }) => {
|
|
112
|
+
return target.item.properties.blockInstruction?.(source, instruction) ?? false;
|
|
113
|
+
},
|
|
114
|
+
[],
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const canDrop = useCallback(({ source, target }: { source: TreeData; target: TreeData }) => {
|
|
118
|
+
return target.item.properties.canDrop?.(source) ?? false;
|
|
119
|
+
}, []);
|
|
120
|
+
|
|
121
|
+
const canSelect = useCallback(({ item }: { item: Node.Node }) => {
|
|
122
|
+
return item.properties.selectable ?? true;
|
|
123
|
+
}, []);
|
|
124
|
+
|
|
125
|
+
const handleSelect = useCallback(
|
|
126
|
+
({ item: node, path, option }: { item: Node.Node; path: string[]; option: boolean }) => {
|
|
127
|
+
if (!node.data) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (Node.isAction(node)) {
|
|
132
|
+
const [parent] = Graph.getConnections(graph, node.id, Node.childRelation('inbound'));
|
|
133
|
+
if (parent) {
|
|
134
|
+
void runAction(node, { parent, caller: NAV_TREE_ITEM });
|
|
135
|
+
}
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const current = getItem(path).current;
|
|
140
|
+
if (!current) {
|
|
141
|
+
invokeSync(LayoutOperation.Open, { subject: [node.id], key: node.properties.key });
|
|
142
|
+
} else if (option) {
|
|
143
|
+
invokeSync(LayoutOperation.Close, { subject: [node.id] });
|
|
144
|
+
} else {
|
|
145
|
+
void invokePromise(LayoutOperation.ScrollIntoView, { subject: node.id });
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const defaultAction = Graph.getActions(graph, node.id).find(
|
|
149
|
+
(action) => action.properties?.disposition === 'default',
|
|
150
|
+
);
|
|
151
|
+
if (Node.isAction(defaultAction)) {
|
|
152
|
+
void runAction(defaultAction);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (!isLg) {
|
|
156
|
+
invokeSync(LayoutOperation.UpdateSidebar, { state: 'closed' });
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
[graph, invokeSync, invokePromise, getItem, runAction, isLg],
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const handleBack = useCallback(() => invokeSync(LayoutOperation.RevertWorkspace), [invokeSync]);
|
|
163
|
+
|
|
164
|
+
// TODO(wittjosiah): Factor out hook.
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
return monitorForElements({
|
|
167
|
+
canMonitor: ({ source }) => isTreeData(source.data),
|
|
168
|
+
onDrop: ({ location, source }) => {
|
|
169
|
+
// Didn't drop on anything.
|
|
170
|
+
if (!location.current.dropTargets.length) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const target = location.current.dropTargets[0];
|
|
174
|
+
const instruction: Instruction | null = extractInstruction(target.data);
|
|
175
|
+
if (instruction !== null && instruction.type !== 'instruction-blocked') {
|
|
176
|
+
const sourceNode = source.data.item as NavTreeItemGraphNode;
|
|
177
|
+
const targetNode = target.data.item as NavTreeItemGraphNode;
|
|
178
|
+
const sourcePath = source.data.path as string[];
|
|
179
|
+
const targetPath = target.data.path as string[];
|
|
180
|
+
const operation =
|
|
181
|
+
sourcePath.slice(0, -1).join() === targetPath.slice(0, -1).join() && instruction.type !== 'make-child'
|
|
182
|
+
? 'rearrange'
|
|
183
|
+
: resolveMigrationOperation(graph, sourceNode, targetPath, targetNode);
|
|
184
|
+
const sourceParent = getParent(graph, sourceNode, sourcePath);
|
|
185
|
+
const targetParent = getParent(graph, targetNode, targetPath);
|
|
186
|
+
const sourceItems = getItems(graph, sourceParent);
|
|
187
|
+
const targetItems = getItems(graph, targetParent);
|
|
188
|
+
const sourceIndex = sourceItems.findIndex(({ id }) => id === sourceNode.id);
|
|
189
|
+
const targetIndex = targetItems.findIndex(({ id }) => id === targetNode.id);
|
|
190
|
+
const migrationIndex =
|
|
191
|
+
instruction.type === 'make-child'
|
|
192
|
+
? undefined
|
|
193
|
+
: instruction.type === 'reorder-below'
|
|
194
|
+
? targetIndex + 1
|
|
195
|
+
: targetIndex;
|
|
196
|
+
switch (operation) {
|
|
197
|
+
case 'rearrange': {
|
|
198
|
+
const nextItems = sourceItems.map(({ data }) => data);
|
|
199
|
+
arrayMove(nextItems, sourceIndex, targetIndex);
|
|
200
|
+
void sourceNode.properties.onRearrange?.(nextItems);
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
case 'copy': {
|
|
204
|
+
const target = instruction.type === 'make-child' ? targetNode : targetParent;
|
|
205
|
+
void target?.properties.onCopy?.(sourceNode, migrationIndex);
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
case 'transfer': {
|
|
209
|
+
const target = instruction.type === 'make-child' ? targetNode : targetParent;
|
|
210
|
+
if (!target?.properties.onTransferStart || !sourceParent?.properties.onTransferEnd) {
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
void target?.properties.onTransferStart(sourceNode, migrationIndex);
|
|
214
|
+
void sourceParent?.properties.onTransferEnd?.(sourceNode, target);
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
}, [graph]);
|
|
222
|
+
|
|
223
|
+
const setAlternateTree = useCallback(
|
|
224
|
+
(path: string[], open: boolean) => {
|
|
225
|
+
setItem(path, 'alternateTree', open);
|
|
226
|
+
},
|
|
227
|
+
[setItem],
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
const onItemHover = useCallback(({ item }: { item: Node.Node }) => Graph.expand(graph, item.id, 'child'), [graph]);
|
|
231
|
+
|
|
232
|
+
const navTreeContextValue = useMemo(
|
|
233
|
+
() => ({
|
|
234
|
+
model,
|
|
235
|
+
popoverAnchorId,
|
|
236
|
+
renderItemEnd: NavTreeItemEnd,
|
|
237
|
+
blockInstruction,
|
|
238
|
+
canDrop,
|
|
239
|
+
canSelect,
|
|
240
|
+
setAlternateTree,
|
|
241
|
+
onBack: handleBack,
|
|
242
|
+
onOpenChange: handleOpenChange,
|
|
243
|
+
onSelect: handleSelect,
|
|
244
|
+
onTabChange: handleTabChange,
|
|
245
|
+
onItemHover,
|
|
246
|
+
}),
|
|
247
|
+
[
|
|
248
|
+
model,
|
|
249
|
+
popoverAnchorId,
|
|
250
|
+
blockInstruction,
|
|
251
|
+
canDrop,
|
|
252
|
+
canSelect,
|
|
253
|
+
setAlternateTree,
|
|
254
|
+
handleBack,
|
|
255
|
+
handleOpenChange,
|
|
256
|
+
handleSelect,
|
|
257
|
+
handleTabChange,
|
|
258
|
+
onItemHover,
|
|
259
|
+
],
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
return (
|
|
263
|
+
<NavTreeContext.Provider value={navTreeContextValue}>
|
|
264
|
+
<NavTree id={Node.RootId} root={Graph.getRoot(graph)} tab={tab} open={layout.sidebarOpen} ref={forwardedRef} />
|
|
265
|
+
</NavTreeContext.Provider>
|
|
266
|
+
);
|
|
267
|
+
},
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
export const NavTreeContainer = memo(NavTreeContainer$);
|
|
@@ -5,13 +5,14 @@ import { useEffect } from 'react';
|
|
|
5
5
|
|
|
6
6
|
import { type Node } from '@dxos/app-graph';
|
|
7
7
|
import { toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
8
|
+
import { osTranslations } from '@dxos/ui-theme';
|
|
8
9
|
|
|
9
|
-
import { meta } from '
|
|
10
|
+
import { meta } from '../../meta';
|
|
10
11
|
|
|
11
|
-
export const NavTreeDocumentTitle = ({ node }: { node?: Node }) => {
|
|
12
|
+
export const NavTreeDocumentTitle = ({ node }: { node?: Node.Node }) => {
|
|
12
13
|
const { t } = useTranslation(meta.id);
|
|
13
14
|
useEffect(() => {
|
|
14
|
-
document.title = node ? toLocalizedString(node.properties.label, t) : t('current app name', { ns:
|
|
15
|
+
document.title = node ? toLocalizedString(node.properties.label, t) : t('current app name', { ns: osTranslations });
|
|
15
16
|
}, [node?.properties?.label]);
|
|
16
17
|
return null;
|
|
17
18
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type ComponentType, lazy } from 'react';
|
|
6
|
+
|
|
7
|
+
export { NODE_TYPE } from './NavTreeContainer/NavTreeContainer';
|
|
8
|
+
|
|
9
|
+
export const CommandsDialogContent: ComponentType<any> = lazy(() => import('./CommandsDialogContent'));
|
|
10
|
+
export const CommandsTrigger: ComponentType<any> = lazy(() => import('./CommandsTrigger'));
|
|
11
|
+
export const NavTreeContainer: ComponentType<any> = lazy(() => import('./NavTreeContainer'));
|
|
12
|
+
export const NavTreeDocumentTitle: ComponentType<any> = lazy(() => import('./NavTreeDocumentTitle'));
|
|
@@ -3,39 +3,17 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Meta } from '@storybook/react-vite';
|
|
6
|
-
import React, {
|
|
6
|
+
import React, { useEffect, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { faker } from '@dxos/random';
|
|
9
|
-
import { Icon, IconButton } from '@dxos/react-ui';
|
|
10
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
11
|
-
import { mx } from '@dxos/
|
|
9
|
+
import { Icon, IconButton, Panel, ScrollArea } from '@dxos/react-ui';
|
|
10
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
11
|
+
import { mx } from '@dxos/ui-theme';
|
|
12
12
|
|
|
13
13
|
import { type ItemMap, Tree, type TreeNodeData, type TreeProps, visitNodes, visitor } from './Tree';
|
|
14
14
|
|
|
15
15
|
faker.seed(1234);
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* Space:
|
|
19
|
-
* - Space panels are separated from each other to give them more weight than folders.
|
|
20
|
-
* - Private space isn't different (just first, different icon).
|
|
21
|
-
* - Edit titles in place.
|
|
22
|
-
*
|
|
23
|
-
* Navigation:
|
|
24
|
-
* - up/down across spaces/folder peers
|
|
25
|
-
* - right to enter space/folder children
|
|
26
|
-
* - left to parent
|
|
27
|
-
*/
|
|
28
|
-
const Container = ({ children, sidebar }: PropsWithChildren<{ sidebar: JSX.Element }>) => {
|
|
29
|
-
return (
|
|
30
|
-
<div className='flex'>
|
|
31
|
-
{/* TODO(burdon): Custom thin scrollbar. */}
|
|
32
|
-
{/* TODO(burdon): Horizontal scrolling within navtree? */}
|
|
33
|
-
<div className='flex flex-col overflow-y-auto w-[300px] bg-neutral-100 dark:bg-neutral-950'>{sidebar}</div>
|
|
34
|
-
<div className='flex flex-col grow overflow-hidden'>{children}</div>
|
|
35
|
-
</div>
|
|
36
|
-
);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
17
|
// TODO(burdon): Generate.
|
|
40
18
|
const data: TreeNodeData[] = [
|
|
41
19
|
{
|
|
@@ -134,7 +112,7 @@ const Sidebar = ({ mutate }: { mutate?: boolean }) => {
|
|
|
134
112
|
}
|
|
135
113
|
}, []);
|
|
136
114
|
|
|
137
|
-
const handleCreateItem: TreeProps['onMenuAction'] = (id
|
|
115
|
+
const handleCreateItem: TreeProps['onMenuAction'] = (id) => {
|
|
138
116
|
setItems((items) => {
|
|
139
117
|
let parent: TreeNodeData | undefined;
|
|
140
118
|
visitNodes(root, (node) => {
|
|
@@ -167,52 +145,68 @@ const Sidebar = ({ mutate }: { mutate?: boolean }) => {
|
|
|
167
145
|
};
|
|
168
146
|
|
|
169
147
|
return (
|
|
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
|
-
|
|
148
|
+
<Panel.Root>
|
|
149
|
+
<Panel.Content asChild>
|
|
150
|
+
<ScrollArea.Root orientation='vertical' thin>
|
|
151
|
+
<ScrollArea.Viewport>
|
|
152
|
+
<Tree
|
|
153
|
+
className='p-0.5 gap-1'
|
|
154
|
+
node={root}
|
|
155
|
+
open={openItems}
|
|
156
|
+
selected={selectedItems}
|
|
157
|
+
active={activeItems}
|
|
158
|
+
onChangeOpen={(id, open) => setOpenItems((items) => ({ ...items, [id]: open }))}
|
|
159
|
+
onChangeSelected={(id, open) => setSelectedItems((items) => ({ ...items, [id]: open }))}
|
|
160
|
+
onMenuAction={handleCreateItem}
|
|
161
|
+
getSlots={(node, open, depth) => {
|
|
162
|
+
if (depth === 1) {
|
|
163
|
+
return {
|
|
164
|
+
root: 'rounded-sm bg-white dark:bg-neutral-850',
|
|
165
|
+
header: mx('rounded-t bg-neutral-50 dark:bg-neutral-900', !open && 'rounded-b'),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}}
|
|
169
|
+
/>
|
|
170
|
+
</ScrollArea.Viewport>
|
|
171
|
+
</ScrollArea.Root>
|
|
172
|
+
</Panel.Content>
|
|
173
|
+
<Panel.Statusbar>
|
|
174
|
+
<div className='flex items-center my-2 px-2 gap-2'>
|
|
175
|
+
<IconButton icon='ph--plus-circle--regular' iconOnly label='Create space' onClick={handleCreateSpace} />
|
|
176
|
+
<span className='grow text-sm' onClick={handleCreateSpace}>
|
|
177
|
+
New space
|
|
178
|
+
</span>
|
|
179
|
+
<Icon icon='ph--list--regular' />
|
|
180
|
+
</div>
|
|
181
|
+
</Panel.Statusbar>
|
|
182
|
+
</Panel.Root>
|
|
200
183
|
);
|
|
201
184
|
};
|
|
202
185
|
|
|
203
186
|
const meta = {
|
|
204
187
|
title: 'plugins/plugin-navtree/experimental/Tree',
|
|
205
188
|
component: Tree,
|
|
206
|
-
decorators: [withTheme],
|
|
189
|
+
decorators: [withTheme(), withLayout({ layout: 'column', classNames: 'w-[20rem]' })],
|
|
207
190
|
parameters: {
|
|
208
|
-
layout: '
|
|
191
|
+
layout: 'fullscreen',
|
|
209
192
|
},
|
|
210
193
|
} satisfies Meta<typeof Tree>;
|
|
211
194
|
|
|
212
195
|
export default meta;
|
|
213
196
|
|
|
197
|
+
/**
|
|
198
|
+
* Space:
|
|
199
|
+
* - Space panels are separated from each other to give them more weight than folders.
|
|
200
|
+
* - Private space isn't different (just first, different icon).
|
|
201
|
+
* - Edit titles in place.
|
|
202
|
+
*
|
|
203
|
+
* Navigation:
|
|
204
|
+
* - up/down across spaces/folder peers
|
|
205
|
+
* - right to enter space/folder children
|
|
206
|
+
* - left to parent
|
|
207
|
+
*/
|
|
214
208
|
export const Default = () => {
|
|
215
|
-
return <
|
|
209
|
+
return <Sidebar mutate />;
|
|
216
210
|
};
|
|
217
211
|
|
|
218
212
|
export const Visitor = () => {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import React, { type HTMLAttributes, type PropsWithChildren } from 'react';
|
|
6
6
|
|
|
7
7
|
import { type ClassNameValue, Icon, type Size } from '@dxos/react-ui';
|
|
8
|
-
import { mx } from '@dxos/
|
|
8
|
+
import { mx } from '@dxos/ui-theme';
|
|
9
9
|
|
|
10
10
|
export const IconButton = ({
|
|
11
11
|
iconName,
|
|
@@ -193,9 +193,9 @@ export const TreeNodeRow = (props: TreeNodeProps & { className?: string }) => {
|
|
|
193
193
|
<Grid
|
|
194
194
|
style={{ paddingLeft: `${(depth - 1) * 24}px` }}
|
|
195
195
|
className={mx(
|
|
196
|
-
'group w-full items-center cursor-pointer bg-
|
|
196
|
+
'group w-full items-center cursor-pointer bg-hover-surface',
|
|
197
197
|
// TODO(burdon): Use data-active.
|
|
198
|
-
selected?.[id] && 'bg-
|
|
198
|
+
selected?.[id] && 'bg-active-surface',
|
|
199
199
|
className,
|
|
200
200
|
)}
|
|
201
201
|
onClick={() => selected && onChangeSelected?.(id, !selected[id])}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import { useAppGraph } from '@dxos/app-toolkit/ui';
|
|
8
|
+
import { Graph, Node, useActions as useGraphActions } from '@dxos/plugin-graph';
|
|
9
|
+
|
|
10
|
+
import { type FlattenedActions } from '../types';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns flattened actions and grouped sub-actions for a given graph node.
|
|
14
|
+
*/
|
|
15
|
+
export const useActions = (node: Node.Node): FlattenedActions => {
|
|
16
|
+
const { graph } = useAppGraph();
|
|
17
|
+
const actions = useGraphActions(graph, node.id);
|
|
18
|
+
|
|
19
|
+
return useMemo(
|
|
20
|
+
() =>
|
|
21
|
+
actions.reduce(
|
|
22
|
+
(acc: FlattenedActions, arg) => {
|
|
23
|
+
if (arg.properties.disposition === 'item') {
|
|
24
|
+
return acc;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
acc.actions.push(arg);
|
|
28
|
+
if (!Node.isAction(arg)) {
|
|
29
|
+
const actionGroup = Graph.getActions(graph, arg.id);
|
|
30
|
+
acc.groupedActions[arg.id] = actionGroup;
|
|
31
|
+
}
|
|
32
|
+
return acc;
|
|
33
|
+
},
|
|
34
|
+
{ actions: [], groupedActions: {} },
|
|
35
|
+
),
|
|
36
|
+
[actions],
|
|
37
|
+
);
|
|
38
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useEffect } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type Node } from '@dxos/app-graph';
|
|
8
|
+
import { useAppGraph } from '@dxos/app-toolkit/ui';
|
|
9
|
+
import { Graph } from '@dxos/plugin-graph';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Expands a root node in the app graph.
|
|
13
|
+
*/
|
|
14
|
+
export const useLoadDescendents = (root?: Node.Node) => {
|
|
15
|
+
const { graph } = useAppGraph();
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!root) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
Graph.expand(graph, root.id, 'child');
|
|
22
|
+
}, [graph, root]);
|
|
23
|
+
};
|