@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
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Atom } from '@effect-atom/atom-react';
|
|
6
|
+
import * as Option from 'effect/Option';
|
|
7
|
+
import { useMemo } from 'react';
|
|
8
|
+
|
|
9
|
+
import { useAppGraph } from '@dxos/app-toolkit/ui';
|
|
10
|
+
import { PLANK_COMPANION_TYPE } from '@dxos/plugin-deck/types';
|
|
11
|
+
import { type Node } from '@dxos/plugin-graph';
|
|
12
|
+
import { Path, type TreeModel } from '@dxos/react-ui-list';
|
|
13
|
+
import { mx } from '@dxos/ui-theme';
|
|
14
|
+
|
|
15
|
+
import { type NavTreeItemGraphNode } from '../types';
|
|
16
|
+
import { filterItems } from '../util';
|
|
17
|
+
|
|
18
|
+
import { useNavTreeState } from './useNavTreeState';
|
|
19
|
+
|
|
20
|
+
// TODO(wittjosiah): Move companion/hidden nodes to their own edge categories so this filter is unnecessary.
|
|
21
|
+
const isVisibleChild = (node: Node.Node): boolean =>
|
|
22
|
+
node.type !== PLANK_COMPANION_TYPE && node.properties.disposition !== 'hidden';
|
|
23
|
+
|
|
24
|
+
/** Create an atom family for item display props keyed by path. */
|
|
25
|
+
const createItemPropsFamily = (graph: ReturnType<typeof useAppGraph>['graph']) =>
|
|
26
|
+
Atom.family((pathKey: string) => {
|
|
27
|
+
const path = Path.parts(pathKey);
|
|
28
|
+
const id = Path.last(pathKey);
|
|
29
|
+
return Atom.make((get) => {
|
|
30
|
+
const nodeOpt = get(graph.node(id));
|
|
31
|
+
const node = Option.getOrElse(nodeOpt, () => undefined);
|
|
32
|
+
if (!node) {
|
|
33
|
+
return { id, label: id };
|
|
34
|
+
}
|
|
35
|
+
const safeChildren = get(graph.connections(node.id, 'child')).filter((child) => !path.includes(child.id));
|
|
36
|
+
const visibleChildren = safeChildren.filter(isVisibleChild);
|
|
37
|
+
const parentOf =
|
|
38
|
+
visibleChildren.length > 0
|
|
39
|
+
? visibleChildren.map((child) => child.id)
|
|
40
|
+
: node.properties.role === 'branch'
|
|
41
|
+
? []
|
|
42
|
+
: undefined;
|
|
43
|
+
return {
|
|
44
|
+
id: node.id,
|
|
45
|
+
parentOf,
|
|
46
|
+
disabled: node.properties.disabled,
|
|
47
|
+
label: node.properties.label ?? node.id,
|
|
48
|
+
className: mx(node.properties.className, node.properties.modified && 'italic'),
|
|
49
|
+
headingClassName: node.properties.headingClassName,
|
|
50
|
+
icon: node.properties.icon,
|
|
51
|
+
iconHue: node.properties.iconHue,
|
|
52
|
+
testId: node.properties.testId,
|
|
53
|
+
};
|
|
54
|
+
}).pipe(Atom.keepAlive);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/** Create an atom family for outbound child IDs keyed by parent ID (pre-sorted by position on write). */
|
|
58
|
+
const createChildIdsFamily = (graph: ReturnType<typeof useAppGraph>['graph']) =>
|
|
59
|
+
Atom.family((id: string) =>
|
|
60
|
+
Atom.make((get) => get(graph.connections(id, 'child')).map((child) => child.id)).pipe(Atom.keepAlive),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
/** Create an atom family for item resolution keyed by ID. */
|
|
64
|
+
const createItemFamily = (graph: ReturnType<typeof useAppGraph>['graph']) =>
|
|
65
|
+
Atom.family((id: string) =>
|
|
66
|
+
Atom.make((get) => {
|
|
67
|
+
const node = Option.getOrElse(get(graph.node(id)), () => undefined);
|
|
68
|
+
const passed = node ? filterItems(node) : false;
|
|
69
|
+
return node && passed ? node : undefined;
|
|
70
|
+
}).pipe(Atom.keepAlive),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
/** Create an atom family for open state keyed by path. */
|
|
74
|
+
const createItemOpenFamily = (getItemAtom: ReturnType<typeof useNavTreeState>['getItemAtom']) =>
|
|
75
|
+
Atom.family((pathKey: string) => {
|
|
76
|
+
const path = Path.parts(pathKey);
|
|
77
|
+
const stateAtom = getItemAtom(path);
|
|
78
|
+
return Atom.make((get) => get(stateAtom).open).pipe(Atom.keepAlive);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
/** Create an atom family for current (selected) state keyed by path. */
|
|
82
|
+
const createItemCurrentFamily = (getItemAtom: ReturnType<typeof useNavTreeState>['getItemAtom']) =>
|
|
83
|
+
Atom.family((pathKey: string) => {
|
|
84
|
+
const path = Path.parts(pathKey);
|
|
85
|
+
const stateAtom = getItemAtom(path);
|
|
86
|
+
return Atom.make((get) => get(stateAtom).current).pipe(Atom.keepAlive);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Creates a TreeModel backed by the app graph and navtree state.
|
|
91
|
+
*/
|
|
92
|
+
export const useNavTreeModel = (rootId: string): TreeModel<NavTreeItemGraphNode> => {
|
|
93
|
+
const { graph } = useAppGraph();
|
|
94
|
+
const { getItemAtom } = useNavTreeState();
|
|
95
|
+
|
|
96
|
+
const itemPropsFamily = useMemo(() => createItemPropsFamily(graph), [graph]);
|
|
97
|
+
const childIdsFamily = useMemo(() => createChildIdsFamily(graph), [graph]);
|
|
98
|
+
const itemFamily = useMemo(() => createItemFamily(graph), [graph]);
|
|
99
|
+
const itemOpenFamily = useMemo(() => createItemOpenFamily(getItemAtom), [getItemAtom]);
|
|
100
|
+
const itemCurrentFamily = useMemo(() => createItemCurrentFamily(getItemAtom), [getItemAtom]);
|
|
101
|
+
|
|
102
|
+
return useMemo(
|
|
103
|
+
() => ({
|
|
104
|
+
item: (id: string) => itemFamily(id),
|
|
105
|
+
itemProps: (path: string[]) => itemPropsFamily(Path.create(...path)),
|
|
106
|
+
itemOpen: (path: string[]) => itemOpenFamily(Path.create(...path)),
|
|
107
|
+
itemCurrent: (path: string[]) => itemCurrentFamily(Path.create(...path)),
|
|
108
|
+
childIds: (parentId?: string) => childIdsFamily(parentId ?? rootId),
|
|
109
|
+
}),
|
|
110
|
+
[itemFamily, itemPropsFamily, itemOpenFamily, itemCurrentFamily, childIdsFamily, rootId],
|
|
111
|
+
);
|
|
112
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Atom, useAtomValue } from '@effect-atom/atom-react';
|
|
6
|
+
import { useMemo } from 'react';
|
|
7
|
+
|
|
8
|
+
import { useCapability } from '@dxos/app-framework/ui';
|
|
9
|
+
|
|
10
|
+
import { NavTreeCapabilities } from '../types';
|
|
11
|
+
|
|
12
|
+
export type UseNavTreeStateResult = {
|
|
13
|
+
getItem: (path: string[]) => NavTreeCapabilities.NavTreeItemState;
|
|
14
|
+
getItemAtom: (path: string[]) => Atom.Atom<NavTreeCapabilities.NavTreeItemState>;
|
|
15
|
+
setItem: (path: string[], key: 'open' | 'current' | 'alternateTree', next: boolean) => void;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Hook that provides access to navtree state functions.
|
|
20
|
+
* For reactive subscriptions, use `useNavTreeItemState` or `useAtomValue(getItemAtom(path))`.
|
|
21
|
+
*/
|
|
22
|
+
export const useNavTreeState = (): UseNavTreeStateResult => {
|
|
23
|
+
return useCapability(NavTreeCapabilities.State);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Hook that subscribes to a single navtree item's state.
|
|
28
|
+
* Use this for fine-grained reactivity.
|
|
29
|
+
*/
|
|
30
|
+
export const useNavTreeItemState = (path: string[]): NavTreeCapabilities.NavTreeItemState => {
|
|
31
|
+
const { getItemAtom } = useCapability(NavTreeCapabilities.State);
|
|
32
|
+
const pathKey = useMemo(() => path.join('~'), [path]);
|
|
33
|
+
const atom = useMemo(() => getItemAtom(path), [getItemAtom, pathKey]);
|
|
34
|
+
return useAtomValue(atom);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Hook that subscribes to the alternateTree state for a tree item.
|
|
39
|
+
*/
|
|
40
|
+
export const useIsAlternateTree = (path: string[], _item?: any): boolean => {
|
|
41
|
+
return useNavTreeItemState(path).alternateTree ?? false;
|
|
42
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
export { NavTreeCapabilities } from './
|
|
6
|
-
export { NavTreeEvents } from './events';
|
|
5
|
+
export { NavTreeCapabilities, NavTreeEvents } from './types';
|
|
7
6
|
export * from './NavTreePlugin';
|
|
8
7
|
export * from './meta';
|
|
9
8
|
export * from './util';
|
package/src/meta.ts
CHANGED
|
@@ -2,11 +2,16 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type Plugin } from '@dxos/app-framework';
|
|
6
|
+
import { trim } from '@dxos/util';
|
|
6
7
|
|
|
7
|
-
export const meta:
|
|
8
|
+
export const meta: Plugin.Meta = {
|
|
8
9
|
id: 'dxos.org/plugin/navtree',
|
|
9
10
|
name: 'Navtree',
|
|
11
|
+
description: trim`
|
|
12
|
+
Hierarchical navigation tree for browsing spaces, folders, and objects.
|
|
13
|
+
Provides sidebar navigation with collapsible sections and quick access to workspace content.
|
|
14
|
+
`,
|
|
10
15
|
};
|
|
11
16
|
|
|
12
17
|
// TODO(wittjosiah): Factor out.
|
|
@@ -2,16 +2,15 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import * as
|
|
7
|
-
import * as Option from 'effect/Option';
|
|
5
|
+
import { Atom } from '@effect-atom/atom-react';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
8
7
|
|
|
9
|
-
import { type
|
|
8
|
+
import { type BuilderExtensions } from '@dxos/app-graph';
|
|
10
9
|
import { log } from '@dxos/log';
|
|
11
|
-
import {
|
|
10
|
+
import { GraphBuilder, NodeMatcher } from '@dxos/plugin-graph';
|
|
12
11
|
import { faker } from '@dxos/random';
|
|
13
12
|
|
|
14
|
-
export const storybookGraphBuilders = (
|
|
13
|
+
export const storybookGraphBuilders = (): BuilderExtensions => {
|
|
15
14
|
const propertiesCache = new Map<string, Record<string, unknown>>();
|
|
16
15
|
const getProperties = (id: string, defaults: Record<string, unknown>) => {
|
|
17
16
|
const cached = propertiesCache.get(id);
|
|
@@ -23,249 +22,174 @@ export const storybookGraphBuilders = (context: PluginContext): BuilderExtension
|
|
|
23
22
|
return defaults;
|
|
24
23
|
};
|
|
25
24
|
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
disposition: 'menu',
|
|
46
|
-
},
|
|
47
|
-
})),
|
|
48
|
-
];
|
|
49
|
-
}),
|
|
50
|
-
Option.getOrElse(() => []),
|
|
25
|
+
return Effect.runSync(
|
|
26
|
+
Effect.all([
|
|
27
|
+
// Create app menu actions.
|
|
28
|
+
GraphBuilder.createExtension({
|
|
29
|
+
id: 'app-menu',
|
|
30
|
+
match: NodeMatcher.whenRoot,
|
|
31
|
+
actions: () =>
|
|
32
|
+
Effect.succeed(
|
|
33
|
+
Array.from({ length: 5 }, (_, i) => ({
|
|
34
|
+
id: `app-menu/action-${i}`,
|
|
35
|
+
data: Effect.fnUntraced(function* () {
|
|
36
|
+
log.info('action', { id: 'app-menu', index: i });
|
|
37
|
+
}),
|
|
38
|
+
properties: {
|
|
39
|
+
label: `Action ${i}`,
|
|
40
|
+
icon: faker.properties.icon(),
|
|
41
|
+
disposition: 'menu',
|
|
42
|
+
},
|
|
43
|
+
})),
|
|
51
44
|
),
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
45
|
+
}),
|
|
46
|
+
// Create user account node.
|
|
47
|
+
GraphBuilder.createExtension({
|
|
48
|
+
id: 'user-account',
|
|
49
|
+
match: NodeMatcher.whenRoot,
|
|
50
|
+
connector: () =>
|
|
51
|
+
Effect.succeed([
|
|
52
|
+
{
|
|
53
|
+
id: 'user-account',
|
|
54
|
+
type: 'user-account',
|
|
55
|
+
properties: {
|
|
56
|
+
label: 'User profile',
|
|
57
|
+
icon: 'ph--user--regular',
|
|
58
|
+
disposition: 'user-account',
|
|
59
|
+
userId: '1234567890ABCDEF',
|
|
60
|
+
hue: faker.properties.hue(),
|
|
61
|
+
emoji: faker.properties.emoji(),
|
|
62
|
+
status: 'active',
|
|
63
|
+
},
|
|
64
|
+
nodes: [
|
|
64
65
|
{
|
|
65
|
-
id: '
|
|
66
|
-
type: '
|
|
66
|
+
id: 'profile',
|
|
67
|
+
type: 'profile',
|
|
67
68
|
properties: {
|
|
68
|
-
label: '
|
|
69
|
+
label: 'Profile',
|
|
69
70
|
icon: 'ph--user--regular',
|
|
70
|
-
disposition: 'user-account',
|
|
71
|
-
userId: '1234567890ABCDEF',
|
|
72
|
-
hue: faker.properties.hue(),
|
|
73
|
-
emoji: faker.properties.emoji(),
|
|
74
|
-
status: 'active',
|
|
75
71
|
},
|
|
76
|
-
nodes: [
|
|
77
|
-
{
|
|
78
|
-
id: 'profile',
|
|
79
|
-
type: 'profile',
|
|
80
|
-
properties: {
|
|
81
|
-
label: 'Profile',
|
|
82
|
-
icon: 'ph--user--regular',
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
id: 'devices',
|
|
87
|
-
type: 'devices',
|
|
88
|
-
properties: {
|
|
89
|
-
label: 'Devices',
|
|
90
|
-
icon: 'ph--devices--regular',
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
id: 'security',
|
|
95
|
-
type: 'security',
|
|
96
|
-
properties: {
|
|
97
|
-
label: 'Security',
|
|
98
|
-
icon: 'ph--key--regular',
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
],
|
|
102
72
|
},
|
|
103
|
-
];
|
|
104
|
-
}),
|
|
105
|
-
Option.getOrElse(() => []),
|
|
106
|
-
),
|
|
107
|
-
),
|
|
108
|
-
}),
|
|
109
|
-
// TODO(wittjosiah): This group node probably is unnecessary now with the flat L0 structure.
|
|
110
|
-
// Create spaces group node.
|
|
111
|
-
createExtension({
|
|
112
|
-
id: 'spaces-root',
|
|
113
|
-
position: 'hoist',
|
|
114
|
-
connector: (node) =>
|
|
115
|
-
Rx.make((get) =>
|
|
116
|
-
Function.pipe(
|
|
117
|
-
get(node),
|
|
118
|
-
Option.flatMap((node) => (node.id === ROOT_ID ? Option.some(node) : Option.none())),
|
|
119
|
-
Option.map(() => {
|
|
120
|
-
return [
|
|
121
73
|
{
|
|
122
|
-
id: '
|
|
123
|
-
type: '
|
|
74
|
+
id: 'devices',
|
|
75
|
+
type: 'devices',
|
|
124
76
|
properties: {
|
|
125
|
-
label: '
|
|
126
|
-
icon: 'ph--
|
|
127
|
-
role: 'branch',
|
|
128
|
-
disposition: 'collection',
|
|
77
|
+
label: 'Devices',
|
|
78
|
+
icon: 'ph--devices--regular',
|
|
129
79
|
},
|
|
130
80
|
},
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
81
|
+
{
|
|
82
|
+
id: 'security',
|
|
83
|
+
type: 'security',
|
|
84
|
+
properties: {
|
|
85
|
+
label: 'Security',
|
|
86
|
+
icon: 'ph--key--regular',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
]),
|
|
92
|
+
}),
|
|
93
|
+
// Create space (workspace) nodes directly under root.
|
|
94
|
+
GraphBuilder.createExtension({
|
|
95
|
+
id: 'spaces',
|
|
96
|
+
match: NodeMatcher.whenRoot,
|
|
97
|
+
connector: (_, get) =>
|
|
98
|
+
Effect.sync(() => {
|
|
99
|
+
const count = Atom.make((get) => {
|
|
100
|
+
let value = 3;
|
|
101
|
+
const interval = setInterval(() => {
|
|
102
|
+
if (value >= 10) {
|
|
103
|
+
clearInterval(interval);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
148
106
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
107
|
+
value++;
|
|
108
|
+
get.setSelf(value);
|
|
109
|
+
}, 5000);
|
|
110
|
+
get.addFinalizer(() => clearInterval(interval));
|
|
111
|
+
return value;
|
|
112
|
+
});
|
|
155
113
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
get(node),
|
|
185
|
-
Option.flatMap((node) => (node.type === 'space' ? Option.some(node) : Option.none())),
|
|
186
|
-
Option.map((node) => {
|
|
187
|
-
return [
|
|
188
|
-
...Array.from({ length: 5 }, (_, i) => ({
|
|
189
|
-
id: `${node.id}/action-${i}`,
|
|
190
|
-
data: () => {
|
|
191
|
-
log.info('action', { id: node.id, index: i });
|
|
192
|
-
},
|
|
193
|
-
properties: getProperties(`${node.id}/action-${i}`, {
|
|
194
|
-
label: `Action ${i}`,
|
|
195
|
-
icon: faker.properties.icon(),
|
|
196
|
-
}),
|
|
197
|
-
})),
|
|
198
|
-
];
|
|
199
|
-
}),
|
|
200
|
-
Option.getOrElse(() => []),
|
|
114
|
+
return Array.from({ length: get(count) }, (_, i) => ({
|
|
115
|
+
id: `space-${i}`,
|
|
116
|
+
type: 'space',
|
|
117
|
+
properties: getProperties(`space-${i}`, {
|
|
118
|
+
label: `Space ${i}`,
|
|
119
|
+
icon: faker.properties.icon(),
|
|
120
|
+
hue: faker.properties.hue(),
|
|
121
|
+
disposition: 'workspace',
|
|
122
|
+
}),
|
|
123
|
+
}));
|
|
124
|
+
}),
|
|
125
|
+
}),
|
|
126
|
+
// Create space actions.
|
|
127
|
+
GraphBuilder.createExtension({
|
|
128
|
+
id: 'space-actions',
|
|
129
|
+
match: NodeMatcher.whenNodeType('space'),
|
|
130
|
+
actions: () =>
|
|
131
|
+
Effect.succeed(
|
|
132
|
+
Array.from({ length: 5 }, (_, i) => ({
|
|
133
|
+
id: `space-actions/action-${i}`,
|
|
134
|
+
data: Effect.fnUntraced(function* () {
|
|
135
|
+
log.info('action', { id: 'space-actions', index: i });
|
|
136
|
+
}),
|
|
137
|
+
properties: getProperties(`space-actions/action-${i}`, {
|
|
138
|
+
label: `Action ${i}`,
|
|
139
|
+
icon: faker.properties.icon(),
|
|
140
|
+
}),
|
|
141
|
+
})),
|
|
201
142
|
),
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
143
|
+
}),
|
|
144
|
+
// Create object nodes.
|
|
145
|
+
GraphBuilder.createExtension({
|
|
146
|
+
id: 'objects',
|
|
147
|
+
match: NodeMatcher.whenNodeType('space'),
|
|
148
|
+
connector: (_, get) =>
|
|
149
|
+
Effect.sync(() => {
|
|
150
|
+
const count = Atom.make((get) => {
|
|
151
|
+
let value = 3;
|
|
152
|
+
const interval = setInterval(() => {
|
|
153
|
+
if (value >= 20) {
|
|
154
|
+
clearInterval(interval);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
215
157
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
158
|
+
value++;
|
|
159
|
+
get.setSelf(value);
|
|
160
|
+
}, 5000);
|
|
161
|
+
get.addFinalizer(() => clearInterval(interval));
|
|
162
|
+
return value;
|
|
163
|
+
});
|
|
222
164
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
Function.pipe(
|
|
250
|
-
get(node),
|
|
251
|
-
Option.flatMap((node) => (node.type === 'object' ? Option.some(node) : Option.none())),
|
|
252
|
-
Option.map((node) => {
|
|
253
|
-
return [
|
|
254
|
-
...Array.from({ length: 5 }, (_, i) => ({
|
|
255
|
-
id: `${node.id}/action-${i}`,
|
|
256
|
-
data: () => {
|
|
257
|
-
log.info('action', { id: node.id, index: i });
|
|
258
|
-
},
|
|
259
|
-
properties: getProperties(`${node.id}/action-${i}`, {
|
|
260
|
-
label: `Action ${i}`,
|
|
261
|
-
icon: faker.properties.icon(),
|
|
262
|
-
}),
|
|
263
|
-
})),
|
|
264
|
-
];
|
|
265
|
-
}),
|
|
266
|
-
Option.getOrElse(() => []),
|
|
165
|
+
return Array.from({ length: get(count) }, (_, i) => ({
|
|
166
|
+
id: `object-${i}`,
|
|
167
|
+
type: 'object',
|
|
168
|
+
properties: getProperties(`object-${i}`, {
|
|
169
|
+
label: `Object ${i}`,
|
|
170
|
+
icon: faker.properties.icon(),
|
|
171
|
+
}),
|
|
172
|
+
}));
|
|
173
|
+
}),
|
|
174
|
+
}),
|
|
175
|
+
// Create object actions.
|
|
176
|
+
GraphBuilder.createExtension({
|
|
177
|
+
id: 'object-actions',
|
|
178
|
+
match: NodeMatcher.whenNodeType('object'),
|
|
179
|
+
actions: () =>
|
|
180
|
+
Effect.succeed(
|
|
181
|
+
Array.from({ length: 5 }, (_, i) => ({
|
|
182
|
+
id: `object-actions/action-${i}`,
|
|
183
|
+
data: Effect.fnUntraced(function* () {
|
|
184
|
+
log.info('action', { id: 'object-actions', index: i });
|
|
185
|
+
}),
|
|
186
|
+
properties: getProperties(`object-actions/action-${i}`, {
|
|
187
|
+
label: `Action ${i}`,
|
|
188
|
+
icon: faker.properties.icon(),
|
|
189
|
+
}),
|
|
190
|
+
})),
|
|
267
191
|
),
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
192
|
+
}),
|
|
193
|
+
]),
|
|
194
|
+
);
|
|
271
195
|
};
|