@dxos/plugin-navtree 0.8.2-main.fbd8ed0 → 0.8.2-staging.7ac8446
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/{app-graph-builder-P7AY3K72.mjs → app-graph-builder-26D3MUCA.mjs} +6 -7
- package/dist/lib/browser/app-graph-builder-26D3MUCA.mjs.map +7 -0
- package/dist/lib/browser/{chunk-TLQLMZXU.mjs → chunk-4RQJXI4D.mjs} +1 -1
- package/dist/lib/browser/chunk-4RQJXI4D.mjs.map +7 -0
- package/dist/lib/browser/{chunk-UM2C5XK3.mjs → chunk-DN43QXSX.mjs} +365 -444
- package/dist/lib/browser/chunk-DN43QXSX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +10 -5
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-resolver-PW7B76HO.mjs → intent-resolver-BZMUS24C.mjs} +7 -7
- package/dist/lib/browser/intent-resolver-BZMUS24C.mjs.map +7 -0
- package/dist/lib/browser/keyboard-IQXHKUWM.mjs +46 -0
- package/dist/lib/browser/keyboard-IQXHKUWM.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-M3CAS7ZP.mjs → react-surface-3HCM3SHJ.mjs} +3 -3
- package/dist/lib/browser/{state-3UBYOTQT.mjs → state-M5UJ3MHL.mjs} +12 -18
- package/dist/lib/browser/state-M5UJ3MHL.mjs.map +7 -0
- package/dist/types/src/capabilities/app-graph-builder.d.ts +179 -2
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/capabilities.d.ts +4 -7
- package/dist/types/src/capabilities/capabilities.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +183 -38
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts +2 -2
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
- package/dist/types/src/capabilities/keyboard.d.ts +2 -2
- package/dist/types/src/capabilities/keyboard.d.ts.map +1 -1
- package/dist/types/src/capabilities/state.d.ts +6 -9
- package/dist/types/src/capabilities/state.d.ts.map +1 -1
- package/dist/types/src/components/CommandsDialog.d.ts.map +1 -0
- package/dist/types/src/components/CommandsTrigger.d.ts.map +1 -0
- package/dist/types/src/components/L0Menu.d.ts +10 -0
- package/dist/types/src/components/L0Menu.d.ts.map +1 -0
- package/dist/types/src/components/L1Panels.d.ts +14 -0
- package/dist/types/src/components/L1Panels.d.ts.map +1 -0
- package/dist/types/src/components/NavTree.d.ts +5 -0
- package/dist/types/src/components/NavTree.d.ts.map +1 -0
- package/dist/types/src/components/NavTree.stories.d.ts +7 -0
- package/dist/types/src/components/NavTree.stories.d.ts.map +1 -0
- package/dist/types/src/components/NavTreeContainer.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeContext.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeDocumentTitle.d.ts.map +1 -1
- package/dist/types/src/components/{NavTreeItem/NavTreeItemAction.d.ts → NavTreeItemAction.d.ts} +3 -2
- package/dist/types/src/components/NavTreeItemAction.d.ts.map +1 -0
- package/dist/types/src/components/NavTreeItemAction.stories.d.ts +41 -0
- package/dist/types/src/components/NavTreeItemAction.stories.d.ts.map +1 -0
- package/dist/types/src/components/NavTreeItemColumns.d.ts +4 -0
- package/dist/types/src/components/NavTreeItemColumns.d.ts.map +1 -0
- package/dist/types/src/components/{UserAccountAvatar/UserAccountAvatar.d.ts → UserAccountAvatar.d.ts} +1 -1
- package/dist/types/src/components/UserAccountAvatar.d.ts.map +1 -0
- package/dist/types/src/components/{UserAccountAvatar/UserAccountAvatar.stories.d.ts → UserAccountAvatar.stories.d.ts} +2 -1
- package/dist/types/src/components/UserAccountAvatar.stories.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/types.d.ts +14 -20
- package/dist/types/src/components/types.d.ts.map +1 -1
- package/dist/types/src/experimental/Tree.d.ts.map +1 -1
- package/dist/types/src/hooks.d.ts.map +1 -1
- package/dist/types/src/stories/Graph.stories.d.ts +7 -0
- package/dist/types/src/stories/Graph.stories.d.ts.map +1 -0
- package/dist/types/src/stories/StorybookNavTree.d.ts +4 -0
- package/dist/types/src/stories/StorybookNavTree.d.ts.map +1 -0
- package/dist/types/src/testing/generator.d.ts +6 -7
- package/dist/types/src/testing/generator.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +0 -1
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/update-state.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +0 -1
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +10 -7
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +31 -40
- package/src/NavTreePlugin.tsx +2 -2
- package/src/capabilities/app-graph-builder.ts +28 -38
- package/src/capabilities/capabilities.ts +4 -5
- package/src/capabilities/intent-resolver.ts +7 -8
- package/src/capabilities/keyboard.ts +32 -37
- package/src/capabilities/state.ts +17 -23
- package/src/components/{CommandsDialog/CommandsDialog.tsx → CommandsDialog.tsx} +7 -8
- package/src/components/{CommandsDialog/CommandsTrigger.tsx → CommandsTrigger.tsx} +1 -1
- package/src/components/{Sidebar/L0Menu.tsx → L0Menu.tsx} +131 -188
- package/src/components/L1Panels.tsx +115 -0
- package/src/components/NavTree.stories.tsx +107 -0
- package/src/components/NavTree.tsx +51 -0
- package/src/components/NavTreeContainer.tsx +74 -94
- package/src/components/NavTreeContext.tsx +1 -1
- package/src/components/{NavTreeItem/NavTreeItemAction.stories.tsx → NavTreeItemAction.stories.tsx} +6 -12
- package/src/components/{NavTreeItem/NavTreeItemAction.tsx → NavTreeItemAction.tsx} +18 -23
- package/src/components/NavTreeItemColumns.tsx +71 -0
- package/src/components/{UserAccountAvatar/UserAccountAvatar.stories.tsx → UserAccountAvatar.stories.tsx} +5 -5
- package/src/components/{UserAccountAvatar/UserAccountAvatar.tsx → UserAccountAvatar.tsx} +7 -7
- package/src/components/index.ts +1 -0
- package/src/components/types.ts +15 -20
- package/src/hooks.ts +11 -12
- package/src/stories/Graph.stories.tsx +130 -0
- package/src/stories/StorybookNavTree.tsx +63 -0
- package/src/testing/generator.ts +12 -15
- package/src/testing/index.ts +0 -1
- package/src/translations.ts +0 -1
- package/src/util.ts +32 -10
- package/dist/lib/browser/app-graph-builder-P7AY3K72.mjs.map +0 -7
- package/dist/lib/browser/chunk-TLQLMZXU.mjs.map +0 -7
- package/dist/lib/browser/chunk-UM2C5XK3.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-PW7B76HO.mjs.map +0 -7
- package/dist/lib/browser/keyboard-DDFATRUG.mjs +0 -51
- package/dist/lib/browser/keyboard-DDFATRUG.mjs.map +0 -7
- package/dist/lib/browser/state-3UBYOTQT.mjs.map +0 -7
- 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/NavTree/NavTree.d.ts +0 -8
- package/dist/types/src/components/NavTree/NavTree.d.ts.map +0 -1
- package/dist/types/src/components/NavTree/NavTree.stories.d.ts +0 -8
- package/dist/types/src/components/NavTree/NavTree.stories.d.ts.map +0 -1
- package/dist/types/src/components/NavTree/index.d.ts +0 -2
- package/dist/types/src/components/NavTree/index.d.ts.map +0 -1
- package/dist/types/src/components/NavTreeItem/NavTreeItemAction.d.ts.map +0 -1
- package/dist/types/src/components/NavTreeItem/NavTreeItemAction.stories.d.ts +0 -8
- package/dist/types/src/components/NavTreeItem/NavTreeItemAction.stories.d.ts.map +0 -1
- package/dist/types/src/components/NavTreeItem/NavTreeItemColumns.d.ts +0 -4
- package/dist/types/src/components/NavTreeItem/NavTreeItemColumns.d.ts.map +0 -1
- package/dist/types/src/components/NavTreeItem/index.d.ts +0 -3
- package/dist/types/src/components/NavTreeItem/index.d.ts.map +0 -1
- package/dist/types/src/components/Sidebar/L0Menu.d.ts +0 -13
- package/dist/types/src/components/Sidebar/L0Menu.d.ts.map +0 -1
- package/dist/types/src/components/Sidebar/L1Panel.d.ts +0 -15
- package/dist/types/src/components/Sidebar/L1Panel.d.ts.map +0 -1
- package/dist/types/src/components/Sidebar/index.d.ts +0 -3
- package/dist/types/src/components/Sidebar/index.d.ts.map +0 -1
- package/dist/types/src/components/UserAccountAvatar/UserAccountAvatar.d.ts.map +0 -1
- package/dist/types/src/components/UserAccountAvatar/UserAccountAvatar.stories.d.ts.map +0 -1
- package/dist/types/src/components/UserAccountAvatar/index.d.ts +0 -2
- package/dist/types/src/components/UserAccountAvatar/index.d.ts.map +0 -1
- package/dist/types/src/testing/app-graph-builder.d.ts +0 -3
- package/dist/types/src/testing/app-graph-builder.d.ts.map +0 -1
- package/src/components/CommandsDialog/index.ts +0 -6
- package/src/components/NavTree/NavTree.stories.tsx +0 -159
- package/src/components/NavTree/NavTree.tsx +0 -62
- package/src/components/NavTree/index.ts +0 -5
- package/src/components/NavTreeItem/NavTreeItemColumns.tsx +0 -73
- package/src/components/NavTreeItem/index.ts +0 -6
- package/src/components/Sidebar/L1Panel.tsx +0 -175
- package/src/components/Sidebar/index.ts +0 -6
- package/src/components/UserAccountAvatar/index.ts +0 -5
- package/src/testing/app-graph-builder.ts +0 -224
- /package/dist/lib/browser/{react-surface-M3CAS7ZP.mjs.map → react-surface-3HCM3SHJ.mjs.map} +0 -0
- /package/dist/types/src/components/{CommandsDialog/CommandsDialog.d.ts → CommandsDialog.d.ts} +0 -0
- /package/dist/types/src/components/{CommandsDialog/CommandsTrigger.d.ts → CommandsTrigger.d.ts} +0 -0
package/src/hooks.ts
CHANGED
|
@@ -2,21 +2,20 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import { useEffect } from 'react';
|
|
6
6
|
|
|
7
7
|
import { type Node } from '@dxos/app-graph';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
import { useNavTreeContext } from './components';
|
|
10
10
|
|
|
11
11
|
export const useLoadDescendents = (root?: Node) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// }, [root]);
|
|
12
|
+
const { loadDescendents } = useNavTreeContext();
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const frame = requestAnimationFrame(() => {
|
|
15
|
+
if (root) {
|
|
16
|
+
void loadDescendents?.(root);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return () => cancelAnimationFrame(frame);
|
|
20
|
+
}, [root]);
|
|
22
21
|
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import '@dxos-theme';
|
|
6
|
+
|
|
7
|
+
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
8
|
+
import { extractInstruction, type Instruction } from '@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item';
|
|
9
|
+
import { batch } from '@preact/signals-core';
|
|
10
|
+
import { type Meta } from '@storybook/react';
|
|
11
|
+
import React, { useEffect } from 'react';
|
|
12
|
+
|
|
13
|
+
import { Graph, ROOT_ID, type Node } from '@dxos/app-graph';
|
|
14
|
+
import { registerSignalsRuntime } from '@dxos/echo-signals/react';
|
|
15
|
+
import { create, type ReactiveObject } from '@dxos/live-object';
|
|
16
|
+
import { faker } from '@dxos/random';
|
|
17
|
+
import { isTreeData, type PropsFromTreeItem } from '@dxos/react-ui-list';
|
|
18
|
+
import { Path } from '@dxos/react-ui-list';
|
|
19
|
+
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
20
|
+
|
|
21
|
+
import { StorybookNavTree } from './StorybookNavTree';
|
|
22
|
+
import { getActions, getChildren } from '../util';
|
|
23
|
+
|
|
24
|
+
faker.seed(3);
|
|
25
|
+
registerSignalsRuntime();
|
|
26
|
+
|
|
27
|
+
const createGraph = () => {
|
|
28
|
+
const graph = new Graph();
|
|
29
|
+
|
|
30
|
+
batch(() => {
|
|
31
|
+
(graph as any)._addNode({
|
|
32
|
+
id: ROOT_ID,
|
|
33
|
+
nodes: [...Array(2)].map((_, i) => ({
|
|
34
|
+
id: faker.string.hexadecimal({ length: 4 }).slice(2).toUpperCase(),
|
|
35
|
+
properties: { index: `a${i}`, label: faker.lorem.words(2), description: faker.lorem.sentence() },
|
|
36
|
+
nodes: [...Array(2)].map((_, j) => ({
|
|
37
|
+
id: faker.string.hexadecimal({ length: 4 }).slice(2).toUpperCase(),
|
|
38
|
+
properties: { index: `a${j}`, label: faker.lorem.words(2), description: faker.lorem.sentence() },
|
|
39
|
+
nodes: [...Array(2)].map((_, k) => ({
|
|
40
|
+
id: faker.string.hexadecimal({ length: 4 }).slice(2).toUpperCase(),
|
|
41
|
+
properties: { index: `a${k}`, label: faker.lorem.words(2), description: faker.lorem.sentence() },
|
|
42
|
+
})),
|
|
43
|
+
})),
|
|
44
|
+
})),
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return graph;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const graph = createGraph();
|
|
52
|
+
const state = new Map<string, ReactiveObject<{ open: boolean; current: boolean }>>();
|
|
53
|
+
|
|
54
|
+
export const Default = {};
|
|
55
|
+
|
|
56
|
+
const meta: Meta<typeof StorybookNavTree> = {
|
|
57
|
+
title: 'plugins/plugin-navtree/Graph',
|
|
58
|
+
component: StorybookNavTree,
|
|
59
|
+
decorators: [withTheme, withLayout({ tooltips: true })],
|
|
60
|
+
render: (args) => {
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
return monitorForElements({
|
|
63
|
+
canMonitor: ({ source }) => isTreeData(source.data),
|
|
64
|
+
onDrop: ({ location, source }) => {
|
|
65
|
+
// Didn't drop on anything.
|
|
66
|
+
if (!location.current.dropTargets.length) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const target = location.current.dropTargets[0];
|
|
71
|
+
|
|
72
|
+
const instruction: Instruction | null = extractInstruction(target.data);
|
|
73
|
+
if (instruction !== null) {
|
|
74
|
+
// TODO(wittjosiah): Implement drop logic.
|
|
75
|
+
console.log('update', instruction);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}, []);
|
|
80
|
+
|
|
81
|
+
return <StorybookNavTree {...args} />;
|
|
82
|
+
},
|
|
83
|
+
args: {
|
|
84
|
+
root: graph.root,
|
|
85
|
+
id: graph.root.id,
|
|
86
|
+
getActions: (node: Node) => getActions(graph, node),
|
|
87
|
+
getItems: (node?: Node) => graph.nodes(node ?? graph.root),
|
|
88
|
+
getProps: (node: Node, path: string[]) => {
|
|
89
|
+
const children = getChildren(graph, node, undefined, path);
|
|
90
|
+
const parentOf =
|
|
91
|
+
children.length > 0 ? children.map(({ id }) => id) : node.properties.role === 'branch' ? [] : undefined;
|
|
92
|
+
return {
|
|
93
|
+
id: node.id,
|
|
94
|
+
label: node.properties.label ?? node.id,
|
|
95
|
+
icon: node.properties.icon,
|
|
96
|
+
parentOf,
|
|
97
|
+
} satisfies PropsFromTreeItem;
|
|
98
|
+
},
|
|
99
|
+
isOpen: (_path: string[]) => {
|
|
100
|
+
const path = Path.create(..._path);
|
|
101
|
+
const value = state.get(path) ?? create({ open: false, current: false });
|
|
102
|
+
if (!state.has(path)) {
|
|
103
|
+
state.set(path, value);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return value.open;
|
|
107
|
+
},
|
|
108
|
+
isCurrent: (_path: string[]) => {
|
|
109
|
+
const path = Path.create(..._path);
|
|
110
|
+
const value = state.get(path) ?? create({ open: false, current: false });
|
|
111
|
+
if (!state.has(path)) {
|
|
112
|
+
state.set(path, value);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return value.current;
|
|
116
|
+
},
|
|
117
|
+
onOpenChange: ({ path: _path, open }) => {
|
|
118
|
+
const path = Path.create(..._path);
|
|
119
|
+
const object = state.get(path);
|
|
120
|
+
object!.open = open;
|
|
121
|
+
},
|
|
122
|
+
onSelect: ({ path: _path, current }) => {
|
|
123
|
+
const path = Path.create(..._path);
|
|
124
|
+
const object = state.get(path);
|
|
125
|
+
object!.current = current;
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export default meta;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { useMemo, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { NavTree, NavTreeContext, type NavTreeContextValue, type NavTreeProps } from '../components';
|
|
8
|
+
import { type NavTreeItemGraphNode } from '../types';
|
|
9
|
+
|
|
10
|
+
export const StorybookNavTree = ({
|
|
11
|
+
getActions,
|
|
12
|
+
loadDescendents,
|
|
13
|
+
renderItemEnd,
|
|
14
|
+
popoverAnchorId,
|
|
15
|
+
getItems,
|
|
16
|
+
getProps,
|
|
17
|
+
isCurrent,
|
|
18
|
+
canDrop,
|
|
19
|
+
onSelect,
|
|
20
|
+
isOpen,
|
|
21
|
+
onOpenChange,
|
|
22
|
+
...props
|
|
23
|
+
}: NavTreeProps & NavTreeContextValue) => {
|
|
24
|
+
const [tab, setTab] = useState('never');
|
|
25
|
+
|
|
26
|
+
const contextValue = useMemo(
|
|
27
|
+
() => ({
|
|
28
|
+
tab,
|
|
29
|
+
onTabChange: (node: NavTreeItemGraphNode) => setTab(node.id),
|
|
30
|
+
getActions,
|
|
31
|
+
loadDescendents,
|
|
32
|
+
renderItemEnd,
|
|
33
|
+
popoverAnchorId,
|
|
34
|
+
getItems,
|
|
35
|
+
getProps,
|
|
36
|
+
isCurrent,
|
|
37
|
+
isOpen,
|
|
38
|
+
onOpenChange,
|
|
39
|
+
canDrop,
|
|
40
|
+
onSelect,
|
|
41
|
+
}),
|
|
42
|
+
[
|
|
43
|
+
tab,
|
|
44
|
+
setTab,
|
|
45
|
+
getActions,
|
|
46
|
+
loadDescendents,
|
|
47
|
+
renderItemEnd,
|
|
48
|
+
popoverAnchorId,
|
|
49
|
+
getItems,
|
|
50
|
+
getProps,
|
|
51
|
+
isCurrent,
|
|
52
|
+
isOpen,
|
|
53
|
+
onOpenChange,
|
|
54
|
+
canDrop,
|
|
55
|
+
onSelect,
|
|
56
|
+
],
|
|
57
|
+
);
|
|
58
|
+
return (
|
|
59
|
+
<NavTreeContext.Provider value={contextValue}>
|
|
60
|
+
<NavTree {...props} />
|
|
61
|
+
</NavTreeContext.Provider>
|
|
62
|
+
);
|
|
63
|
+
};
|
package/src/testing/generator.ts
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema } from 'effect';
|
|
6
|
-
|
|
7
5
|
import { type NodeArg } from '@dxos/app-graph';
|
|
8
|
-
import { TypedObject } from '@dxos/echo-schema';
|
|
9
|
-
import {
|
|
6
|
+
import { S, TypedObject } from '@dxos/echo-schema';
|
|
7
|
+
import { create, type ReactiveObject } from '@dxos/live-object';
|
|
10
8
|
import { faker } from '@dxos/random';
|
|
11
9
|
import { range } from '@dxos/util';
|
|
12
10
|
|
|
@@ -17,12 +15,12 @@ import { range } from '@dxos/util';
|
|
|
17
15
|
export type TestItem = { id: string; type: string } & Record<string, any>;
|
|
18
16
|
|
|
19
17
|
type ObjectDataGenerator = {
|
|
20
|
-
createSchema?: () =>
|
|
18
|
+
createSchema?: () => S.Schema.AnyNoContext;
|
|
21
19
|
createData: () => any;
|
|
22
20
|
};
|
|
23
21
|
|
|
24
|
-
type ObjectFactory<T extends
|
|
25
|
-
schema?:
|
|
22
|
+
type ObjectFactory<T extends ReactiveObject<any>> = {
|
|
23
|
+
schema?: S.Schema.AnyNoContext; // TODO(burdon): Support both typed and expando schema.
|
|
26
24
|
createObject: () => T;
|
|
27
25
|
};
|
|
28
26
|
|
|
@@ -32,7 +30,7 @@ const createFactory = ({ createSchema, createData }: ObjectDataGenerator) => {
|
|
|
32
30
|
const schema = createSchema?.();
|
|
33
31
|
return {
|
|
34
32
|
schema,
|
|
35
|
-
createObject: () => (schema ?
|
|
33
|
+
createObject: () => (schema ? create(schema, createData()) : create(createData())),
|
|
36
34
|
};
|
|
37
35
|
};
|
|
38
36
|
|
|
@@ -59,10 +57,10 @@ export const defaultGenerators: { [type: string]: ObjectDataGenerator } = {
|
|
|
59
57
|
project: {
|
|
60
58
|
createSchema: () =>
|
|
61
59
|
class ProjectType extends TypedObject({ typename: 'example.com/type/Project', version: '0.1.0' })({
|
|
62
|
-
title:
|
|
63
|
-
repo:
|
|
64
|
-
status:
|
|
65
|
-
priority:
|
|
60
|
+
title: S.String,
|
|
61
|
+
repo: S.String,
|
|
62
|
+
status: S.String,
|
|
63
|
+
priority: S.Number,
|
|
66
64
|
}) {},
|
|
67
65
|
|
|
68
66
|
createData: () => ({
|
|
@@ -89,7 +87,7 @@ export class TestObjectGenerator {
|
|
|
89
87
|
}, {});
|
|
90
88
|
}
|
|
91
89
|
|
|
92
|
-
get schema():
|
|
90
|
+
get schema(): S.Schema.AnyNoContext[] {
|
|
93
91
|
return Object.values(this.factories).map((f) => f.schema!);
|
|
94
92
|
}
|
|
95
93
|
|
|
@@ -133,11 +131,10 @@ export const createTree = () => {
|
|
|
133
131
|
return {
|
|
134
132
|
id: faker.string.uuid(),
|
|
135
133
|
data: null,
|
|
136
|
-
type: '
|
|
134
|
+
type: 'collection',
|
|
137
135
|
properties: {
|
|
138
136
|
label: l0.title,
|
|
139
137
|
icon: 'ph--horse--regular',
|
|
140
|
-
disposition: 'collection',
|
|
141
138
|
},
|
|
142
139
|
nodes: [
|
|
143
140
|
...[...Array(4)].map(() => {
|
package/src/testing/index.ts
CHANGED
package/src/translations.ts
CHANGED
package/src/util.ts
CHANGED
|
@@ -2,22 +2,31 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
type Action,
|
|
7
|
+
type Node,
|
|
8
|
+
type NodeFilter,
|
|
9
|
+
type Graph,
|
|
10
|
+
ACTION_TYPE,
|
|
11
|
+
ACTION_GROUP_TYPE,
|
|
12
|
+
isAction,
|
|
13
|
+
isActionLike,
|
|
14
|
+
} from '@dxos/app-graph';
|
|
6
15
|
import { isNonNullable } from '@dxos/util';
|
|
7
16
|
|
|
8
17
|
import { type FlattenedActions, type NavTreeItemGraphNode } from './types';
|
|
9
18
|
|
|
10
19
|
export const getParent = (
|
|
11
|
-
graph:
|
|
20
|
+
graph: Graph,
|
|
12
21
|
node: NavTreeItemGraphNode,
|
|
13
22
|
path: string[],
|
|
14
23
|
): NavTreeItemGraphNode | undefined => {
|
|
15
24
|
const parentId = path[path.length - 2];
|
|
16
|
-
return graph.
|
|
25
|
+
return graph.nodes(node, { relation: 'inbound' }).find((n) => n.id === parentId) as NavTreeItemGraphNode | undefined;
|
|
17
26
|
};
|
|
18
27
|
|
|
19
28
|
export const getPersistenceParent = (
|
|
20
|
-
graph:
|
|
29
|
+
graph: Graph,
|
|
21
30
|
node: NavTreeItemGraphNode,
|
|
22
31
|
path: string[],
|
|
23
32
|
persistenceClass: string,
|
|
@@ -31,7 +40,7 @@ export const getPersistenceParent = (
|
|
|
31
40
|
};
|
|
32
41
|
|
|
33
42
|
export const resolveMigrationOperation = (
|
|
34
|
-
graph:
|
|
43
|
+
graph: Graph,
|
|
35
44
|
activeNode: NavTreeItemGraphNode,
|
|
36
45
|
destinationPath: string[],
|
|
37
46
|
destinationRelatedNode?: NavTreeItemGraphNode,
|
|
@@ -74,12 +83,13 @@ export const sortActions = (actions: Action[]): Action[] =>
|
|
|
74
83
|
});
|
|
75
84
|
|
|
76
85
|
export const getChildren = (
|
|
77
|
-
graph:
|
|
86
|
+
graph: Graph,
|
|
78
87
|
node: NavTreeItemGraphNode,
|
|
88
|
+
filter?: NodeFilter,
|
|
79
89
|
path: readonly string[] = [],
|
|
80
90
|
): NavTreeItemGraphNode[] => {
|
|
81
91
|
return graph
|
|
82
|
-
.
|
|
92
|
+
.nodes(node, { relation: 'outbound', filter })
|
|
83
93
|
.map((n) => {
|
|
84
94
|
// Break cycles.
|
|
85
95
|
const nextPath = [...path, node.id];
|
|
@@ -88,8 +98,8 @@ export const getChildren = (
|
|
|
88
98
|
.filter(isNonNullable) as NavTreeItemGraphNode[];
|
|
89
99
|
};
|
|
90
100
|
|
|
91
|
-
export const getActions = (graph:
|
|
92
|
-
return graph.
|
|
101
|
+
export const getActions = (graph: Graph, node: Node): FlattenedActions => {
|
|
102
|
+
return graph.actions(node).reduce(
|
|
93
103
|
(acc: FlattenedActions, arg) => {
|
|
94
104
|
if (arg.properties.disposition === 'item') {
|
|
95
105
|
return acc;
|
|
@@ -97,7 +107,7 @@ export const getActions = (graph: ReadableGraph, node: Node): FlattenedActions =
|
|
|
97
107
|
|
|
98
108
|
acc.actions.push(arg);
|
|
99
109
|
if (!isAction(arg)) {
|
|
100
|
-
const actionGroup = graph.
|
|
110
|
+
const actionGroup = graph.actions(arg);
|
|
101
111
|
acc.groupedActions[arg.id] = actionGroup;
|
|
102
112
|
}
|
|
103
113
|
return acc;
|
|
@@ -106,6 +116,18 @@ export const getActions = (graph: ReadableGraph, node: Node): FlattenedActions =
|
|
|
106
116
|
);
|
|
107
117
|
};
|
|
108
118
|
|
|
119
|
+
export const expandChildrenAndActions = (graph: Graph, node: Node) => {
|
|
120
|
+
return Promise.all([expandChildren(graph, node), expandActions(graph, node)]);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export const expandChildren = (graph: Graph, node: Node) => {
|
|
124
|
+
return graph.expand(node, 'outbound');
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const expandActions = (graph: Graph, node: Node) => {
|
|
128
|
+
return Promise.all([graph.expand(node, 'outbound', ACTION_TYPE), graph.expand(node, 'outbound', ACTION_GROUP_TYPE)]);
|
|
129
|
+
};
|
|
130
|
+
|
|
109
131
|
export const l0ItemType = (item: Node<any>) => {
|
|
110
132
|
if (item.properties.disposition === 'collection') {
|
|
111
133
|
return 'collection';
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/capabilities/app-graph-builder.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Rx } from '@effect-rx/rx-react';\nimport { Option, pipe } from 'effect';\n\nimport { Capabilities, contributes, type PluginContext, createIntent, LayoutAction } from '@dxos/app-framework';\nimport { createExtension, ROOT_ID } from '@dxos/plugin-graph';\n\nimport { COMMANDS_DIALOG, NAVTREE_PLUGIN } from '../meta';\n\nexport default (context: PluginContext) =>\n contributes(\n Capabilities.AppGraphBuilder,\n createExtension({\n id: NAVTREE_PLUGIN,\n actions: (node) =>\n Rx.make((get) =>\n pipe(\n get(node),\n Option.flatMap((node) => (node.id === ROOT_ID ? Option.some(node) : Option.none())),\n Option.map(() => [\n {\n id: COMMANDS_DIALOG,\n data: async () => {\n const { dispatchPromise: dispatch } = context.getCapability(Capabilities.IntentDispatcher);\n await dispatch(\n createIntent(LayoutAction.UpdateDialog, {\n part: 'dialog',\n subject: COMMANDS_DIALOG,\n options: {\n blockAlign: 'start',\n },\n }),\n );\n },\n properties: {\n label: ['open commands label', { ns: NAVTREE_PLUGIN }],\n icon: 'ph--magnifying-glass--regular',\n keyBinding: {\n macos: 'meta+k',\n windows: 'ctrl+k',\n },\n },\n },\n ]),\n Option.getOrElse(() => []),\n ),\n ),\n }),\n );\n"],
|
|
5
|
-
"mappings": ";;;;;;AAIA,SAASA,UAAU;AACnB,SAASC,QAAQC,YAAY;AAE7B,SAASC,cAAcC,aAAiCC,cAAcC,oBAAoB;AAC1F,SAASC,iBAAiBC,eAAe;AAIzC,IAAA,4BAAe,CAACC,YACdC,YACEC,aAAaC,iBACbC,gBAAgB;EACdC,IAAIC;EACJC,SAAS,CAACC,SACRC,GAAGC,KAAK,CAACC,QACPC,KACED,IAAIH,IAAAA,GACJK,OAAOC,QAAQ,CAACN,UAAUA,MAAKH,OAAOU,UAAUF,OAAOG,KAAKR,KAAAA,IAAQK,OAAOI,KAAI,CAAA,GAC/EJ,OAAOK,IAAI,MAAM;IACf;MACEb,IAAIc;MACJC,MAAM,YAAA;AACJ,cAAM,EAAEC,iBAAiBC,SAAQ,IAAKtB,QAAQuB,cAAcrB,aAAasB,gBAAgB;AACzF,cAAMF,SACJG,aAAaC,aAAaC,cAAc;UACtCC,MAAM;UACNC,SAASV;UACTW,SAAS;YACPC,YAAY;UACd;QACF,CAAA,CAAA;MAEJ;MACAC,YAAY;QACVC,OAAO;UAAC;UAAuB;YAAEC,IAAI5B;UAAe;;QACpD6B,MAAM;QACNC,YAAY;UACVC,OAAO;UACPC,SAAS;QACX;MACF;IACF;GACD,GACDzB,OAAO0B,UAAU,MAAM,CAAA,CAAE,CAAA,CAAA;AAGjC,CAAA,CAAA;",
|
|
6
|
-
"names": ["Rx", "Option", "pipe", "Capabilities", "contributes", "createIntent", "LayoutAction", "createExtension", "ROOT_ID", "context", "contributes", "Capabilities", "AppGraphBuilder", "createExtension", "id", "NAVTREE_PLUGIN", "actions", "node", "Rx", "make", "get", "pipe", "Option", "flatMap", "ROOT_ID", "some", "none", "map", "COMMANDS_DIALOG", "data", "dispatchPromise", "dispatch", "getCapability", "IntentDispatcher", "createIntent", "LayoutAction", "UpdateDialog", "part", "subject", "options", "blockAlign", "properties", "label", "ns", "icon", "keyBinding", "macos", "windows", "getOrElse"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/capabilities/capabilities.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { defineCapability } from '@dxos/app-framework';\nimport { type Live } from '@dxos/live-object';\n\nimport { NAVTREE_PLUGIN } from '../meta';\nimport { type NavTreeItemGraphNode } from '../types';\n\nexport namespace NavTreeCapabilities {\n export const State = defineCapability<{\n state: Map<string, Live<{ open: boolean; current: boolean; alternateTree?: boolean }>>;\n getItem: (path: string[]) => Live<{ open: boolean; current: boolean; alternateTree?: boolean }>;\n setItem: (path: string[], key: 'open' | 'current' | 'alternateTree', next: boolean) => void;\n isOpen: (path: string[], item: NavTreeItemGraphNode) => boolean;\n isCurrent: (path: string[], item: NavTreeItemGraphNode) => boolean;\n isAlternateTree: (path: string[], item: NavTreeItemGraphNode) => boolean;\n }>(`${NAVTREE_PLUGIN}/capability/state`);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;AAIA,SAASA,wBAAwB;;UAMhBC,sBAAAA;uBACFC,QAAQC,iBAOlB,GAAGC,cAAAA,mBAAiC;AACzC,GATiBH,wBAAAA,sBAAAA,CAAAA,EAAAA;",
|
|
6
|
-
"names": ["defineCapability", "NavTreeCapabilities", "State", "defineCapability", "NAVTREE_PLUGIN"]
|
|
7
|
-
}
|