@dxos/plugin-explorer 0.8.4-main.72ec0f3 → 0.8.4-main.74a063c4e0
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/{chunk-UBHZGWZQ.mjs → chunk-LSUP47BZ.mjs} +2 -2
- package/dist/lib/browser/chunk-LSUP47BZ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +11342 -87
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/meta.mjs +1 -1
- package/dist/lib/browser/types/index.mjs +64 -5
- package/dist/lib/browser/types/index.mjs.map +4 -4
- package/dist/lib/node-esm/{chunk-UXZM5VJB.mjs → chunk-EN3JZNEY.mjs} +2 -2
- package/dist/lib/node-esm/chunk-EN3JZNEY.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +11342 -87
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/meta.mjs +1 -1
- package/dist/lib/node-esm/types/index.mjs +64 -5
- package/dist/lib/node-esm/types/index.mjs.map +4 -4
- package/dist/types/src/ExplorerPlugin.d.ts +2 -1
- package/dist/types/src/ExplorerPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +2 -2
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts +3 -2
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/Chart/Chart.stories.d.ts.map +1 -1
- package/dist/types/src/components/Globe/Globe.stories.d.ts.map +1 -1
- package/dist/types/src/components/Graph/D3ForceGraph.d.ts +10 -5
- package/dist/types/src/components/Graph/D3ForceGraph.d.ts.map +1 -1
- package/dist/types/src/components/Graph/D3ForceGraph.stories.d.ts +8 -2
- package/dist/types/src/components/Graph/D3ForceGraph.stories.d.ts.map +1 -1
- package/dist/types/src/components/Graph/ForceGraph.stories.d.ts +1 -1
- package/dist/types/src/components/Graph/ForceGraph.stories.d.ts.map +1 -1
- package/dist/types/src/components/Graph/adapter.d.ts +1 -1
- package/dist/types/src/components/Graph/adapter.d.ts.map +1 -1
- package/dist/types/src/components/Graph/testing.d.ts.map +1 -1
- package/dist/types/src/components/Tree/Tree.d.ts.map +1 -1
- package/dist/types/src/components/Tree/Tree.stories.d.ts.map +1 -1
- package/dist/types/src/components/Tree/testing/generator.d.ts.map +1 -1
- package/dist/types/src/components/Tree/types/tree.d.ts +18 -16
- package/dist/types/src/components/Tree/types/tree.d.ts.map +1 -1
- package/dist/types/src/components/Tree/types/types.d.ts +1 -1
- package/dist/types/src/components/Tree/types/types.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +0 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/containers/ExplorerContainer/ExplorerContainer.d.ts +6 -0
- package/dist/types/src/containers/ExplorerContainer/ExplorerContainer.d.ts.map +1 -0
- package/dist/types/src/containers/ExplorerContainer/index.d.ts +2 -0
- package/dist/types/src/containers/ExplorerContainer/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +3 -0
- package/dist/types/src/containers/index.d.ts.map +1 -0
- package/dist/types/src/hooks/useGraphModel.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/translations.d.ts +31 -22
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/ExplorerAction.d.ts +1 -18
- package/dist/types/src/types/ExplorerAction.d.ts.map +1 -1
- package/dist/types/src/types/Graph.d.ts +14 -24
- package/dist/types/src/types/Graph.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +59 -46
- package/src/ExplorerPlugin.tsx +42 -54
- package/src/capabilities/index.ts +2 -3
- package/src/capabilities/react-surface.tsx +22 -19
- package/src/components/Chart/Chart.stories.tsx +3 -4
- package/src/components/Globe/Globe.stories.tsx +3 -4
- package/src/components/Graph/D3ForceGraph.stories.tsx +26 -21
- package/src/components/Graph/D3ForceGraph.tsx +82 -75
- package/src/components/Graph/ForceGraph.stories.tsx +26 -21
- package/src/components/Graph/adapter.ts +14 -8
- package/src/components/Graph/testing.ts +8 -5
- package/src/components/Tree/Tree.stories.tsx +9 -6
- package/src/components/Tree/Tree.tsx +8 -3
- package/src/components/Tree/testing/generator.ts +4 -2
- package/src/components/Tree/types/tree.test.ts +5 -4
- package/src/components/Tree/types/tree.ts +41 -20
- package/src/components/Tree/types/types.ts +1 -1
- package/src/components/index.ts +0 -4
- package/src/containers/ExplorerContainer/ExplorerContainer.tsx +53 -0
- package/src/containers/ExplorerContainer/index.ts +5 -0
- package/src/containers/index.ts +7 -0
- package/src/hooks/useGraphModel.ts +17 -10
- package/src/meta.ts +3 -3
- package/src/translations.ts +15 -12
- package/src/types/ExplorerAction.ts +9 -19
- package/src/types/Graph.ts +25 -22
- package/src/typings.d.ts +8 -0
- package/dist/lib/browser/ExplorerContainer-NOLLVUTE.mjs +0 -50
- package/dist/lib/browser/ExplorerContainer-NOLLVUTE.mjs.map +0 -7
- package/dist/lib/browser/chunk-2MKBRIUT.mjs +0 -31
- package/dist/lib/browser/chunk-2MKBRIUT.mjs.map +0 -7
- package/dist/lib/browser/chunk-6BVXZQPP.mjs +0 -188
- package/dist/lib/browser/chunk-6BVXZQPP.mjs.map +0 -7
- package/dist/lib/browser/chunk-ARBGXQFH.mjs +0 -11089
- package/dist/lib/browser/chunk-ARBGXQFH.mjs.map +0 -7
- package/dist/lib/browser/chunk-JDSUIUNR.mjs +0 -80
- package/dist/lib/browser/chunk-JDSUIUNR.mjs.map +0 -7
- package/dist/lib/browser/chunk-UBHZGWZQ.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-YS5LZC3A.mjs +0 -31
- package/dist/lib/browser/intent-resolver-YS5LZC3A.mjs.map +0 -7
- package/dist/lib/browser/react-surface-BVTCOVLK.mjs +0 -35
- package/dist/lib/browser/react-surface-BVTCOVLK.mjs.map +0 -7
- package/dist/lib/node-esm/ExplorerContainer-N3S5KSUX.mjs +0 -51
- package/dist/lib/node-esm/ExplorerContainer-N3S5KSUX.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-3ODK27PU.mjs +0 -33
- package/dist/lib/node-esm/chunk-3ODK27PU.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-CRSVAZNA.mjs +0 -190
- package/dist/lib/node-esm/chunk-CRSVAZNA.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-MS72BATS.mjs +0 -81
- package/dist/lib/node-esm/chunk-MS72BATS.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NPIP4VEH.mjs +0 -11091
- package/dist/lib/node-esm/chunk-NPIP4VEH.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-UXZM5VJB.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-VCEC67WX.mjs +0 -32
- package/dist/lib/node-esm/intent-resolver-VCEC67WX.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-4HFEX52O.mjs +0 -36
- package/dist/lib/node-esm/react-surface-4HFEX52O.mjs.map +0 -7
- package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
- package/dist/types/src/components/ExplorerContainer.d.ts +0 -9
- package/dist/types/src/components/ExplorerContainer.d.ts.map +0 -1
- package/src/capabilities/intent-resolver.ts +0 -21
- package/src/components/ExplorerContainer.tsx +0 -54
|
@@ -5,55 +5,60 @@
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
6
|
import React, { useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { Type } from '@dxos/echo';
|
|
9
|
+
import { View } from '@dxos/echo';
|
|
10
|
+
import { random } from '@dxos/random';
|
|
9
11
|
import { useClient } from '@dxos/react-client';
|
|
10
12
|
import { type Space } from '@dxos/react-client/echo';
|
|
11
13
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
12
14
|
import { useAsyncEffect } from '@dxos/react-ui';
|
|
13
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
14
|
-
import {
|
|
15
|
+
import { Loading, withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
16
|
+
import { ViewModel } from '@dxos/schema';
|
|
15
17
|
import { type ValueGenerator } from '@dxos/schema/testing';
|
|
16
|
-
import {
|
|
17
|
-
import { HasRelationship, Organization, Person,
|
|
18
|
+
import { withRegistry } from '@dxos/storybook-utils';
|
|
19
|
+
import { HasRelationship, Organization, Person, Pipeline } from '@dxos/types';
|
|
18
20
|
|
|
19
|
-
import { useGraphModel } from '
|
|
20
|
-
import { Graph } from '
|
|
21
|
+
import { useGraphModel } from '#hooks';
|
|
22
|
+
import { Graph } from '#types';
|
|
21
23
|
|
|
22
24
|
import { ForceGraph } from './ForceGraph';
|
|
23
25
|
import { generate } from './testing';
|
|
24
26
|
|
|
25
|
-
const generator =
|
|
27
|
+
const generator = random as any as ValueGenerator;
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
random.seed(1);
|
|
28
30
|
|
|
29
31
|
const DefaultStory = () => {
|
|
30
32
|
const client = useClient();
|
|
31
33
|
const [space, setSpace] = useState<Space>();
|
|
32
|
-
const [
|
|
34
|
+
const [graph, setGraph] = useState<Graph.Graph>();
|
|
33
35
|
|
|
34
36
|
useAsyncEffect(async () => {
|
|
35
|
-
const space = client.spaces.
|
|
37
|
+
const space = client.spaces.get()[0];
|
|
36
38
|
void generate(space, generator);
|
|
37
|
-
const { view } = await
|
|
38
|
-
|
|
39
|
+
const { view } = await ViewModel.makeFromDatabase({ db: space.db, typename: Type.getTypename(Graph.Graph) });
|
|
40
|
+
const graph = Graph.make({ name: 'Test', view });
|
|
41
|
+
space.db.add(graph);
|
|
39
42
|
setSpace(space);
|
|
40
|
-
|
|
41
|
-
}, []);
|
|
43
|
+
setGraph(graph);
|
|
44
|
+
}, [client]);
|
|
42
45
|
|
|
43
46
|
const model = useGraphModel(space);
|
|
44
|
-
if (!model || !space || !
|
|
45
|
-
return
|
|
47
|
+
if (!model || !space || !graph) {
|
|
48
|
+
return <Loading data={{ model: !!model, space: !!space, graph: !!graph }} />;
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
return <ForceGraph model={model} />;
|
|
49
52
|
};
|
|
50
53
|
|
|
51
54
|
const meta = {
|
|
52
|
-
title: 'plugins/plugin-explorer/ForceGraph',
|
|
55
|
+
title: 'plugins/plugin-explorer/components/ForceGraph',
|
|
53
56
|
component: ForceGraph,
|
|
54
|
-
render:
|
|
57
|
+
render: DefaultStory,
|
|
55
58
|
decorators: [
|
|
56
|
-
|
|
59
|
+
withRegistry,
|
|
60
|
+
withTheme(),
|
|
61
|
+
withLayout(),
|
|
57
62
|
withClientProvider({
|
|
58
63
|
createSpace: true,
|
|
59
64
|
types: [
|
|
@@ -61,7 +66,7 @@ const meta = {
|
|
|
61
66
|
View.View,
|
|
62
67
|
HasRelationship.HasRelationship,
|
|
63
68
|
Organization.Organization,
|
|
64
|
-
|
|
69
|
+
Pipeline.Pipeline,
|
|
65
70
|
Person.Person,
|
|
66
71
|
],
|
|
67
72
|
}),
|
|
@@ -25,19 +25,25 @@ export class GraphAdapter implements GraphData {
|
|
|
25
25
|
private readonly _nodes: GraphNode[] = [];
|
|
26
26
|
private readonly _links: GraphLink[] = [];
|
|
27
27
|
|
|
28
|
-
constructor(private readonly graph: Graph) {
|
|
29
|
-
this._nodes = graph.nodes.map((node) => ({
|
|
28
|
+
constructor(private readonly graph: Graph.Any) {
|
|
29
|
+
this._nodes = graph.nodes.map((node: Graph.Node.Any) => ({
|
|
30
30
|
id: node.id,
|
|
31
31
|
type: node.type,
|
|
32
32
|
data: node.data,
|
|
33
33
|
}));
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
// Build a set of node IDs for efficient lookup.
|
|
36
|
+
const nodeIds = new Set(this._nodes.map((node) => node.id));
|
|
37
|
+
|
|
38
|
+
// Filter out edges where source or target node doesn't exist.
|
|
39
|
+
this._links = graph.edges
|
|
40
|
+
.filter((edge: Graph.Edge.Any) => nodeIds.has(edge.source) && nodeIds.has(edge.target))
|
|
41
|
+
.map((edge: Graph.Edge.Any) => ({
|
|
42
|
+
type: edge.type,
|
|
43
|
+
source: edge.source,
|
|
44
|
+
target: edge.target,
|
|
45
|
+
data: edge.data,
|
|
46
|
+
}));
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
get nodes() {
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
import { type Space } from '@dxos/client/echo';
|
|
6
6
|
import { type Obj, Query, Relation } from '@dxos/echo';
|
|
7
7
|
import { type TypeSpec, type ValueGenerator, createObjectFactory } from '@dxos/schema/testing';
|
|
8
|
-
import { HasRelationship, Organization, Person,
|
|
8
|
+
import { HasRelationship, Organization, Person, Pipeline } from '@dxos/types';
|
|
9
9
|
import { range } from '@dxos/util';
|
|
10
10
|
|
|
11
|
-
const getObject = (objects: Obj.
|
|
11
|
+
const getObject = (objects: Obj.Unknown[]) => objects[Math.floor(Math.random() * objects.length)];
|
|
12
12
|
|
|
13
13
|
const defaultTypes: TypeSpec[] = [
|
|
14
14
|
{ type: Organization.Organization, count: 5 },
|
|
15
|
-
{ type:
|
|
15
|
+
{ type: Pipeline.Pipeline, count: 5 },
|
|
16
16
|
{ type: Person.Person, count: 10 },
|
|
17
17
|
];
|
|
18
18
|
|
|
@@ -24,7 +24,10 @@ export type GenerateOptions = {
|
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
const defaultRelations: GenerateOptions['relations'] = {
|
|
27
|
+
const defaultRelations: GenerateOptions['relations'] = {
|
|
28
|
+
kind: 'friend',
|
|
29
|
+
count: 10,
|
|
30
|
+
};
|
|
28
31
|
|
|
29
32
|
/**
|
|
30
33
|
* @deprecated Use @dxos/schema.
|
|
@@ -38,7 +41,7 @@ export const generate = async (
|
|
|
38
41
|
await createObjects(spec);
|
|
39
42
|
|
|
40
43
|
// Add relations between objects.
|
|
41
|
-
const
|
|
44
|
+
const contacts = await space.db.query(Query.type(Person.Person)).run();
|
|
42
45
|
for (const _ of range(relations.count)) {
|
|
43
46
|
const source = getObject(contacts);
|
|
44
47
|
const target = getObject(contacts);
|
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
6
|
import React, { useEffect, useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { invariant } from '@dxos/invariant';
|
|
9
|
+
import { random } from '@dxos/random';
|
|
9
10
|
import { useClient } from '@dxos/react-client';
|
|
10
11
|
import { type ClientRepeatedComponentProps, ClientRepeater } from '@dxos/react-client/testing';
|
|
11
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
12
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
13
|
+
import { withRegistry } from '@dxos/storybook-utils';
|
|
12
14
|
|
|
13
15
|
import { Tree, type TreeComponentProps } from './Tree';
|
|
14
16
|
import { Tree as TreeModel, TreeType } from './types';
|
|
@@ -16,13 +18,14 @@ import { Tree as TreeModel, TreeType } from './types';
|
|
|
16
18
|
// TODO(burdon): Storybook for Graph/Tree/Plot (generics); incl. GraphModel.
|
|
17
19
|
// TODO(burdon): Type for all Explorer components (Space, Object, Query, etc.) incl.
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
random.seed(1);
|
|
20
22
|
|
|
21
23
|
type ComponentProps = ClientRepeatedComponentProps & { type?: TreeComponentProps<any>['variant'] };
|
|
22
24
|
|
|
23
25
|
const Component = ({ type }: ComponentProps) => {
|
|
24
26
|
const client = useClient();
|
|
25
|
-
const space = client.spaces.
|
|
27
|
+
const space = client.spaces.get()[0];
|
|
28
|
+
invariant(space, 'Tree story requires at least one space');
|
|
26
29
|
const [object, setObject] = useState<TreeType>();
|
|
27
30
|
useEffect(() => {
|
|
28
31
|
setTimeout(() => {
|
|
@@ -43,10 +46,10 @@ const DefaultStory = () => {
|
|
|
43
46
|
};
|
|
44
47
|
|
|
45
48
|
const meta = {
|
|
46
|
-
title: 'plugins/plugin-explorer/Tree',
|
|
49
|
+
title: 'plugins/plugin-explorer/components/Tree',
|
|
47
50
|
component: Tree as any,
|
|
48
51
|
render: DefaultStory,
|
|
49
|
-
decorators: [withTheme],
|
|
52
|
+
decorators: [withRegistry, withTheme(), withLayout()],
|
|
50
53
|
parameters: {
|
|
51
54
|
layout: 'fullscreen',
|
|
52
55
|
},
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
6
|
+
import React, { useContext, useEffect, useRef, useState } from 'react';
|
|
6
7
|
|
|
7
8
|
import { type Space } from '@dxos/client/echo';
|
|
8
9
|
import { useAsyncState } from '@dxos/react-ui';
|
|
@@ -62,7 +63,11 @@ export type TreeComponentProps<N = unknown> = {
|
|
|
62
63
|
|
|
63
64
|
// TODO(burdon): Label accessor.
|
|
64
65
|
export const Tree = <N,>({ space, selected, variant = 'tidy', onNodeClick }: TreeComponentProps<N>) => {
|
|
65
|
-
const
|
|
66
|
+
const registry = useContext(RegistryContext);
|
|
67
|
+
const [model] = useAsyncState(
|
|
68
|
+
async () => (space ? new SpaceGraphModel(registry).open(space.db) : undefined),
|
|
69
|
+
[space, selected, registry],
|
|
70
|
+
);
|
|
66
71
|
|
|
67
72
|
const [tree, setTree] = useState<TreeNode>();
|
|
68
73
|
useEffect(() => {
|
|
@@ -100,7 +105,7 @@ export const Tree = <N,>({ space, selected, variant = 'tidy', onNodeClick }: Tre
|
|
|
100
105
|
}, [context.current, tree]);
|
|
101
106
|
|
|
102
107
|
return (
|
|
103
|
-
<div onClick={() => onNodeClick?.()}>
|
|
108
|
+
<div className='grow' onClick={() => onNodeClick?.()}>
|
|
104
109
|
<SVG.Root ref={context} />
|
|
105
110
|
</div>
|
|
106
111
|
);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Key } from '@dxos/echo';
|
|
5
|
+
import { Key, Obj } from '@dxos/echo';
|
|
6
6
|
import { range } from '@dxos/util';
|
|
7
7
|
|
|
8
8
|
import { Tree, type TreeNodeType } from '../types';
|
|
@@ -16,7 +16,9 @@ const random = (min: number, max: number) => Math.floor(Math.random() * (max - m
|
|
|
16
16
|
*/
|
|
17
17
|
export const createTree = (spec: NumberOrNumberArray[] = [], createText?: () => string): Tree => {
|
|
18
18
|
const tree = new Tree();
|
|
19
|
-
tree.
|
|
19
|
+
Obj.change(tree.tree, () => {
|
|
20
|
+
tree.root.data = { text: 'root' };
|
|
21
|
+
});
|
|
20
22
|
|
|
21
23
|
const createNodes = (parent: TreeNodeType, spec: NumberOrNumberArray = 0): TreeNodeType[] => {
|
|
22
24
|
const count = Array.isArray(spec) ? random(spec[0], spec[1]) : spec;
|
|
@@ -5,14 +5,13 @@
|
|
|
5
5
|
import { describe, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { Obj, Ref } from '@dxos/echo';
|
|
8
|
-
import {
|
|
8
|
+
import { random } from '@dxos/random';
|
|
9
9
|
import { Task } from '@dxos/types';
|
|
10
10
|
|
|
11
11
|
import { createTree } from '../testing';
|
|
12
|
-
|
|
13
12
|
import { type Tree } from './tree';
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
random.seed(0);
|
|
16
15
|
|
|
17
16
|
const print = (tree: Tree) => {
|
|
18
17
|
let count = 0;
|
|
@@ -129,6 +128,8 @@ describe('tree', () => {
|
|
|
129
128
|
|
|
130
129
|
const tree = createTree();
|
|
131
130
|
const node = tree.addNode(tree.root);
|
|
132
|
-
|
|
131
|
+
Obj.change(tree.tree, () => {
|
|
132
|
+
node.ref = Ref.make(task);
|
|
133
|
+
});
|
|
133
134
|
});
|
|
134
135
|
});
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import { Key, Obj, Type } from '@dxos/echo';
|
|
7
|
+
import { Key, Obj, Ref, Type } from '@dxos/echo';
|
|
8
|
+
import { TestSchema } from '@dxos/echo/testing';
|
|
8
9
|
import { invariant } from '@dxos/invariant';
|
|
9
10
|
|
|
10
11
|
// TODO(burdon): Reconcile with @dxos/graph (i.e., common types).
|
|
@@ -13,7 +14,7 @@ export const TreeNodeType = Schema.Struct({
|
|
|
13
14
|
id: Key.ObjectId,
|
|
14
15
|
children: Schema.mutable(Schema.Array(Key.ObjectId)),
|
|
15
16
|
data: Schema.mutable(Schema.Record({ key: Schema.String, value: Schema.Any })),
|
|
16
|
-
ref: Schema.optional(
|
|
17
|
+
ref: Schema.optional(Ref.Ref(TestSchema.Expando)),
|
|
17
18
|
}).pipe(Schema.mutable);
|
|
18
19
|
|
|
19
20
|
export interface TreeNodeType extends Schema.Schema.Type<typeof TreeNodeType> {}
|
|
@@ -22,8 +23,8 @@ export const TreeType = Schema.Struct({
|
|
|
22
23
|
root: Key.ObjectId,
|
|
23
24
|
nodes: Schema.mutable(Schema.Record({ key: Key.ObjectId, value: TreeNodeType })),
|
|
24
25
|
}).pipe(
|
|
25
|
-
Type.
|
|
26
|
-
typename: 'dxos.
|
|
26
|
+
Type.object({
|
|
27
|
+
typename: 'org.dxos.type.tree',
|
|
27
28
|
version: '0.1.0',
|
|
28
29
|
}),
|
|
29
30
|
);
|
|
@@ -184,9 +185,11 @@ export class Tree {
|
|
|
184
185
|
clear(): void {
|
|
185
186
|
const root = this._tree.nodes[this._tree.root];
|
|
186
187
|
root.children.length = 0;
|
|
187
|
-
this._tree
|
|
188
|
-
|
|
189
|
-
|
|
188
|
+
Obj.change(this._tree, (obj) => {
|
|
189
|
+
obj.nodes = {
|
|
190
|
+
[root.id]: root,
|
|
191
|
+
};
|
|
192
|
+
});
|
|
190
193
|
}
|
|
191
194
|
|
|
192
195
|
/**
|
|
@@ -198,8 +201,11 @@ export class Tree {
|
|
|
198
201
|
node = { id, children: [], data: { text: '' } }; // TODO(burdon): Generic.
|
|
199
202
|
}
|
|
200
203
|
|
|
201
|
-
|
|
202
|
-
|
|
204
|
+
const nodeToAdd = node;
|
|
205
|
+
Obj.change(this._tree, (obj) => {
|
|
206
|
+
obj.nodes[nodeToAdd.id] = nodeToAdd;
|
|
207
|
+
parent.children.splice(index ?? parent.children.length, 0, nodeToAdd.id);
|
|
208
|
+
});
|
|
203
209
|
return node;
|
|
204
210
|
}
|
|
205
211
|
|
|
@@ -212,10 +218,14 @@ export class Tree {
|
|
|
212
218
|
return undefined;
|
|
213
219
|
}
|
|
214
220
|
|
|
215
|
-
|
|
221
|
+
Obj.change(this._tree, (obj) => {
|
|
222
|
+
delete obj.nodes[node.id];
|
|
223
|
+
});
|
|
216
224
|
const idx = parent.children.findIndex((child) => child === id);
|
|
217
225
|
if (idx !== -1) {
|
|
218
|
-
|
|
226
|
+
Obj.change(this._tree, () => {
|
|
227
|
+
parent.children.splice(idx, 1);
|
|
228
|
+
});
|
|
219
229
|
}
|
|
220
230
|
|
|
221
231
|
return node;
|
|
@@ -232,8 +242,10 @@ export class Tree {
|
|
|
232
242
|
}
|
|
233
243
|
|
|
234
244
|
const child = node.children[from];
|
|
235
|
-
|
|
236
|
-
|
|
245
|
+
Obj.change(this._tree, () => {
|
|
246
|
+
node.children.splice(from, 1);
|
|
247
|
+
node.children.splice(to, 0, child);
|
|
248
|
+
});
|
|
237
249
|
return this.getNode(child);
|
|
238
250
|
}
|
|
239
251
|
|
|
@@ -252,8 +264,10 @@ export class Tree {
|
|
|
252
264
|
}
|
|
253
265
|
|
|
254
266
|
const previous = this.getNode(parent.children[idx - 1]);
|
|
255
|
-
|
|
256
|
-
|
|
267
|
+
Obj.change(this._tree, () => {
|
|
268
|
+
parent.children.splice(idx, 1);
|
|
269
|
+
previous.children.push(node.id);
|
|
270
|
+
});
|
|
257
271
|
}
|
|
258
272
|
|
|
259
273
|
/**
|
|
@@ -270,16 +284,23 @@ export class Tree {
|
|
|
270
284
|
return;
|
|
271
285
|
}
|
|
272
286
|
|
|
273
|
-
// Remove node from parent.
|
|
287
|
+
// Remove node from parent and get following siblings.
|
|
274
288
|
const nodeIdx = parent.children.findIndex((id) => id === node.id);
|
|
275
|
-
|
|
276
|
-
|
|
289
|
+
let rest: Key.ObjectId[] = [];
|
|
290
|
+
Obj.change(this._tree, () => {
|
|
291
|
+
const removed = parent.children.splice(nodeIdx, parent.children.length - nodeIdx);
|
|
292
|
+
rest = removed.slice(1); // Skip the node itself.
|
|
293
|
+
});
|
|
277
294
|
|
|
278
295
|
// Add to ancestor.
|
|
279
296
|
const parentIdx = this.getChildNodes(ancestor).findIndex((n) => n.id === parent.id);
|
|
280
|
-
|
|
297
|
+
Obj.change(this._tree, () => {
|
|
298
|
+
ancestor.children.splice(parentIdx + 1, 0, node.id);
|
|
299
|
+
});
|
|
281
300
|
|
|
282
301
|
// Transplant following siblings to current node.
|
|
283
|
-
|
|
302
|
+
Obj.change(this._tree, () => {
|
|
303
|
+
node.children.push(...rest);
|
|
304
|
+
});
|
|
284
305
|
}
|
|
285
306
|
}
|
|
@@ -10,7 +10,7 @@ export type TreeNode = {
|
|
|
10
10
|
children?: TreeNode[];
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export const mapGraphToTreeData = (model: GraphModel, maxDepth = 8): TreeNode | undefined => {
|
|
13
|
+
export const mapGraphToTreeData = (model: GraphModel.GraphModel, maxDepth = 8): TreeNode | undefined => {
|
|
14
14
|
// TODO(burdon): Convert to common/graph.
|
|
15
15
|
// const mapNode = (node: N, depth = 0): TreeNode => {
|
|
16
16
|
// const treeNode: TreeNode = {
|
package/src/components/index.ts
CHANGED
|
@@ -2,11 +2,7 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type ComponentType, lazy } from 'react';
|
|
6
|
-
|
|
7
5
|
export * from './Chart';
|
|
8
6
|
export * from './Globe';
|
|
9
7
|
export * from './Graph';
|
|
10
8
|
export * from './Tree';
|
|
11
|
-
|
|
12
|
-
export const ExplorerContainer: ComponentType<any> = lazy(() => import('./ExplorerContainer'));
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type AppSurface } from '@dxos/app-toolkit/ui';
|
|
8
|
+
import { type Filter } from '@dxos/echo';
|
|
9
|
+
import { type View } from '@dxos/echo';
|
|
10
|
+
import { QueryBuilder } from '@dxos/echo-query';
|
|
11
|
+
import { useGlobalSearch } from '@dxos/plugin-search';
|
|
12
|
+
import { getSpace, useObject } from '@dxos/react-client/echo';
|
|
13
|
+
import { Panel, Toolbar } from '@dxos/react-ui';
|
|
14
|
+
import { QueryEditor, type QueryEditorProps } from '@dxos/react-ui-components';
|
|
15
|
+
|
|
16
|
+
import { D3ForceGraph } from '#components';
|
|
17
|
+
import { useGraphModel } from '#hooks';
|
|
18
|
+
|
|
19
|
+
export type ExplorerContainerProps = AppSurface.ObjectArticleProps<View.View>;
|
|
20
|
+
|
|
21
|
+
export const ExplorerContainer = ({ role, subject: view, attendableId: _attendableId }: ExplorerContainerProps) => {
|
|
22
|
+
useObject(view);
|
|
23
|
+
const space = view && getSpace(view);
|
|
24
|
+
const [filter, setFilter] = useState<Filter.Any>();
|
|
25
|
+
const model = useGraphModel(space, filter);
|
|
26
|
+
const { match } = useGlobalSearch();
|
|
27
|
+
|
|
28
|
+
const builder = useMemo(() => new QueryBuilder(), []);
|
|
29
|
+
const handleChange = useCallback<NonNullable<QueryEditorProps['onChange']>>((value) => {
|
|
30
|
+
setFilter(builder.build(value).filter);
|
|
31
|
+
}, []);
|
|
32
|
+
|
|
33
|
+
const showToolbar = role === 'article';
|
|
34
|
+
|
|
35
|
+
if (!space || !model) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Panel.Root role={role}>
|
|
41
|
+
{showToolbar && (
|
|
42
|
+
<Panel.Toolbar asChild>
|
|
43
|
+
<Toolbar.Root>
|
|
44
|
+
<QueryEditor db={space.db} onChange={handleChange} />
|
|
45
|
+
</Toolbar.Root>
|
|
46
|
+
</Panel.Toolbar>
|
|
47
|
+
)}
|
|
48
|
+
<Panel.Content asChild>
|
|
49
|
+
<D3ForceGraph model={model} match={match} />
|
|
50
|
+
</Panel.Content>
|
|
51
|
+
</Panel.Root>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import { useEffect, useState } from 'react';
|
|
6
6
|
|
|
7
|
+
import { Capabilities } from '@dxos/app-framework';
|
|
8
|
+
import { useCapability } from '@dxos/app-framework/ui';
|
|
7
9
|
import { type Filter, type Queue, type Space } from '@dxos/client/echo';
|
|
8
10
|
import { SpaceGraphModel, type SpaceGraphModelOptions } from '@dxos/schema';
|
|
9
11
|
|
|
@@ -14,23 +16,28 @@ export const useGraphModel = (
|
|
|
14
16
|
options?: SpaceGraphModelOptions,
|
|
15
17
|
queue?: Queue,
|
|
16
18
|
): SpaceGraphModel | undefined => {
|
|
19
|
+
const registry = useCapability(Capabilities.AtomRegistry);
|
|
17
20
|
const [model, setModel] = useState<SpaceGraphModel | undefined>(undefined);
|
|
21
|
+
|
|
18
22
|
useEffect(() => {
|
|
19
23
|
if (!space) {
|
|
20
|
-
void model?.close();
|
|
21
24
|
setModel(undefined);
|
|
22
25
|
return;
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
}, [space,
|
|
28
|
+
const newModel = new SpaceGraphModel(registry);
|
|
29
|
+
void newModel.open(space.db, queue);
|
|
30
|
+
setModel(newModel);
|
|
31
|
+
|
|
32
|
+
return () => {
|
|
33
|
+
setModel(undefined);
|
|
34
|
+
void newModel.close();
|
|
35
|
+
};
|
|
36
|
+
}, [space, registry, queue]);
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
model?.setFilter(filter).setOptions(options);
|
|
40
|
+
}, [model, filter, options]);
|
|
34
41
|
|
|
35
42
|
return model;
|
|
36
43
|
};
|
package/src/meta.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type Plugin } from '@dxos/app-framework';
|
|
6
6
|
import { trim } from '@dxos/util';
|
|
7
7
|
|
|
8
|
-
export const meta:
|
|
9
|
-
id: 'dxos.
|
|
8
|
+
export const meta: Plugin.Meta = {
|
|
9
|
+
id: 'org.dxos.plugin.explorer',
|
|
10
10
|
name: 'Explorer',
|
|
11
11
|
description: trim`
|
|
12
12
|
Interactive hypergraph visualization that reveals relationships between objects in your workspace.
|
package/src/translations.ts
CHANGED
|
@@ -2,27 +2,30 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { Type } from '@dxos/echo';
|
|
5
6
|
import { type Resource } from '@dxos/react-ui';
|
|
6
7
|
import { translations as componentsTranslations } from '@dxos/react-ui-components';
|
|
7
8
|
|
|
8
|
-
import { meta } from '
|
|
9
|
-
import { Graph } from '
|
|
9
|
+
import { meta } from '#meta';
|
|
10
|
+
import { Graph } from '#types';
|
|
10
11
|
|
|
11
12
|
export const translations = [
|
|
12
13
|
{
|
|
13
14
|
'en-US': {
|
|
14
|
-
[Graph.Graph
|
|
15
|
-
'typename
|
|
16
|
-
'typename
|
|
17
|
-
'typename
|
|
18
|
-
'typename
|
|
19
|
-
'object
|
|
20
|
-
'
|
|
21
|
-
'
|
|
15
|
+
[Type.getTypename(Graph.Graph)]: {
|
|
16
|
+
'typename.label': 'Explorer',
|
|
17
|
+
'typename.label_zero': 'Explorers',
|
|
18
|
+
'typename.label_one': 'Explorer',
|
|
19
|
+
'typename.label_other': 'Explorers',
|
|
20
|
+
'object-name.placeholder': 'New explorer',
|
|
21
|
+
'add-object.label': 'Add explorer',
|
|
22
|
+
'rename-object.label': 'Rename explorer',
|
|
23
|
+
'delete-object.label': 'Delete explorer',
|
|
24
|
+
'object-deleted.label': 'Explorer deleted',
|
|
22
25
|
},
|
|
23
26
|
[meta.id]: {
|
|
24
|
-
'plugin
|
|
25
|
-
'object
|
|
27
|
+
'plugin.name': 'Explorer',
|
|
28
|
+
'object-title.label': 'Title',
|
|
26
29
|
},
|
|
27
30
|
},
|
|
28
31
|
},
|
|
@@ -4,27 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import { TypenameAnnotationId, View } from '@dxos/schema';
|
|
9
|
-
|
|
10
|
-
import { meta } from '../meta';
|
|
11
|
-
|
|
12
|
-
const EXPLORER_ACTION = `${meta.id}/action`;
|
|
7
|
+
import { TypeInputOptionsAnnotation } from '@dxos/plugin-space/types';
|
|
13
8
|
|
|
14
9
|
export const GraphProps = Schema.Struct({
|
|
15
10
|
name: Schema.optional(Schema.String),
|
|
16
11
|
// TODO(wittjosiah): This should be a query input instead.
|
|
17
|
-
typename: Schema.String.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
typename: Schema.String.pipe(
|
|
13
|
+
Schema.annotations({ title: 'Select type' }),
|
|
14
|
+
TypeInputOptionsAnnotation.set({
|
|
15
|
+
location: ['database', 'runtime'],
|
|
16
|
+
kind: ['user'],
|
|
17
|
+
}),
|
|
18
|
+
Schema.optional,
|
|
19
|
+
),
|
|
21
20
|
});
|
|
22
|
-
|
|
23
|
-
export class CreateGraph extends Schema.TaggedClass<CreateGraph>()(`${EXPLORER_ACTION}/create-graph`, {
|
|
24
|
-
input: Schema.Struct({
|
|
25
|
-
space: SpaceSchema,
|
|
26
|
-
}).pipe(Schema.extend(GraphProps)),
|
|
27
|
-
output: Schema.Struct({
|
|
28
|
-
object: View.View,
|
|
29
|
-
}),
|
|
30
|
-
}) {}
|