@dxos/plugin-explorer 0.8.4-main.ae835ea → 0.8.4-main.bc674ce
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/ExplorerContainer-BFAWRIAJ.mjs +45 -0
- package/dist/lib/browser/ExplorerContainer-BFAWRIAJ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-CRN65FY3.mjs → chunk-AGZAGILW.mjs} +135 -148
- package/dist/lib/{node-esm/chunk-RSZFBKZM.mjs.map → browser/chunk-AGZAGILW.mjs.map} +3 -3
- package/dist/lib/browser/{chunk-2MKBRIUT.mjs → chunk-BZMTFAP3.mjs} +8 -5
- package/dist/lib/browser/chunk-BZMTFAP3.mjs.map +7 -0
- package/dist/lib/browser/chunk-HIFLWHXR.mjs +83 -0
- package/dist/lib/browser/chunk-HIFLWHXR.mjs.map +7 -0
- package/dist/lib/browser/chunk-MGBT2ZFU.mjs +177 -0
- package/dist/lib/browser/chunk-MGBT2ZFU.mjs.map +7 -0
- package/dist/lib/browser/{chunk-UBHZGWZQ.mjs → chunk-YNQF4CPY.mjs} +1 -1
- package/dist/lib/browser/chunk-YNQF4CPY.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +46 -65
- 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/react-surface-RWVHQL3J.mjs +35 -0
- package/dist/lib/browser/react-surface-RWVHQL3J.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +1 -2
- package/dist/lib/node-esm/ExplorerContainer-YQ2KKBVS.mjs +46 -0
- package/dist/lib/node-esm/ExplorerContainer-YQ2KKBVS.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-3OE6TBJI.mjs +84 -0
- package/dist/lib/node-esm/chunk-3OE6TBJI.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-UXZM5VJB.mjs → chunk-DK77RB6M.mjs} +1 -1
- package/dist/lib/node-esm/chunk-DK77RB6M.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-3ODK27PU.mjs → chunk-IPIGIQHX.mjs} +8 -5
- package/dist/lib/node-esm/chunk-IPIGIQHX.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-RSZFBKZM.mjs → chunk-QLMTN2XI.mjs} +135 -148
- package/dist/lib/{browser/chunk-CRN65FY3.mjs.map → node-esm/chunk-QLMTN2XI.mjs.map} +3 -3
- package/dist/lib/node-esm/chunk-YWJBDETV.mjs +179 -0
- package/dist/lib/node-esm/chunk-YWJBDETV.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +46 -65
- 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/react-surface-3REUS7KW.mjs +36 -0
- package/dist/lib/node-esm/react-surface-3REUS7KW.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +1 -2
- 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 +1 -2
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- 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/components/ExplorerContainer.d.ts +4 -6
- package/dist/types/src/components/ExplorerContainer.d.ts.map +1 -1
- package/dist/types/src/components/Graph/D3ForceGraph.d.ts.map +1 -1
- package/dist/types/src/components/Graph/D3ForceGraph.stories.d.ts.map +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 +17 -15
- 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 +2 -4
- package/dist/types/src/components/index.d.ts.map +1 -1
- 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 +17 -10
- 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 +21 -24
- package/dist/types/src/types/Graph.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +52 -47
- package/src/ExplorerPlugin.tsx +27 -52
- package/src/capabilities/index.ts +1 -4
- package/src/capabilities/react-surface/index.ts +7 -0
- package/src/capabilities/react-surface/react-surface.tsx +30 -0
- package/src/components/Chart/Chart.stories.tsx +2 -2
- package/src/components/ExplorerContainer.tsx +7 -9
- package/src/components/Globe/Globe.stories.tsx +2 -2
- package/src/components/Graph/D3ForceGraph.stories.tsx +19 -13
- package/src/components/Graph/D3ForceGraph.tsx +2 -2
- package/src/components/Graph/ForceGraph.stories.tsx +19 -13
- package/src/components/Graph/adapter.ts +14 -8
- package/src/components/Graph/testing.ts +11 -8
- package/src/components/Tree/Tree.stories.tsx +3 -2
- 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 -3
- package/src/components/Tree/types/tree.ts +39 -18
- package/src/components/Tree/types/types.ts +1 -1
- package/src/components/index.ts +3 -3
- package/src/hooks/useGraphModel.ts +6 -4
- package/src/meta.ts +2 -2
- package/src/translations.ts +3 -1
- package/src/types/ExplorerAction.ts +11 -19
- package/src/types/Graph.ts +38 -21
- package/dist/lib/browser/ExplorerContainer-L5RVUJRL.mjs +0 -50
- package/dist/lib/browser/ExplorerContainer-L5RVUJRL.mjs.map +0 -7
- 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-BGNRYZUN.mjs +0 -79
- package/dist/lib/browser/chunk-BGNRYZUN.mjs.map +0 -7
- package/dist/lib/browser/chunk-UBHZGWZQ.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-FX5H52QN.mjs +0 -31
- package/dist/lib/browser/intent-resolver-FX5H52QN.mjs.map +0 -7
- package/dist/lib/browser/react-surface-VS3ZFL2Y.mjs +0 -35
- package/dist/lib/browser/react-surface-VS3ZFL2Y.mjs.map +0 -7
- package/dist/lib/node-esm/ExplorerContainer-BBLPHH7K.mjs +0 -51
- package/dist/lib/node-esm/ExplorerContainer-BBLPHH7K.mjs.map +0 -7
- 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-TQESRBUJ.mjs +0 -80
- package/dist/lib/node-esm/chunk-TQESRBUJ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-UXZM5VJB.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-RGBBXXYM.mjs +0 -32
- package/dist/lib/node-esm/intent-resolver-RGBBXXYM.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-SXPT2T37.mjs +0 -36
- package/dist/lib/node-esm/react-surface-SXPT2T37.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/capabilities/react-surface.d.ts +0 -4
- package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
- package/src/capabilities/intent-resolver.ts +0 -21
- package/src/capabilities/react-surface.tsx +0 -27
|
@@ -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;
|
|
@@ -6,7 +6,7 @@ import { describe, test } from 'vitest';
|
|
|
6
6
|
|
|
7
7
|
import { Obj, Ref } from '@dxos/echo';
|
|
8
8
|
import { faker } from '@dxos/random';
|
|
9
|
-
import {
|
|
9
|
+
import { Task } from '@dxos/types';
|
|
10
10
|
|
|
11
11
|
import { createTree } from '../testing';
|
|
12
12
|
|
|
@@ -124,11 +124,13 @@ describe('tree', () => {
|
|
|
124
124
|
});
|
|
125
125
|
|
|
126
126
|
test('task', ({ expect }) => {
|
|
127
|
-
const task = Obj.make(
|
|
127
|
+
const task = Obj.make(Task.Task, { title: 'Test task.' });
|
|
128
128
|
expect(task.title).to.eq('Test task.');
|
|
129
129
|
|
|
130
130
|
const tree = createTree();
|
|
131
131
|
const node = tree.addNode(tree.root);
|
|
132
|
-
|
|
132
|
+
Obj.change(tree.tree, () => {
|
|
133
|
+
node.ref = Ref.make(task);
|
|
134
|
+
});
|
|
133
135
|
});
|
|
134
136
|
});
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
7
|
import { Key, Obj, 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(Type.Ref(
|
|
17
|
+
ref: Schema.optional(Type.Ref(TestSchema.Expando)),
|
|
17
18
|
}).pipe(Schema.mutable);
|
|
18
19
|
|
|
19
20
|
export interface TreeNodeType extends Schema.Schema.Type<typeof TreeNodeType> {}
|
|
@@ -22,7 +23,7 @@ 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
|
+
Type.object({
|
|
26
27
|
typename: 'dxos.org/type/Tree',
|
|
27
28
|
version: '0.1.0',
|
|
28
29
|
}),
|
|
@@ -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, (t) => {
|
|
189
|
+
t.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, (t) => {
|
|
206
|
+
t.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, (t) => {
|
|
222
|
+
delete t.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,11 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { lazy } from 'react';
|
|
6
|
-
|
|
7
|
-
export const ExplorerContainer = lazy(() => import('./ExplorerContainer'));
|
|
5
|
+
import { type ComponentType, lazy } from 'react';
|
|
8
6
|
|
|
9
7
|
export * from './Chart';
|
|
10
8
|
export * from './Globe';
|
|
11
9
|
export * from './Graph';
|
|
12
10
|
export * from './Tree';
|
|
11
|
+
|
|
12
|
+
export const ExplorerContainer: ComponentType<any> = lazy(() => import('./ExplorerContainer'));
|
|
@@ -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 { useContext, useEffect, useState } from 'react';
|
|
6
7
|
|
|
7
8
|
import { type Filter, type Queue, type Space } from '@dxos/client/echo';
|
|
8
9
|
import { SpaceGraphModel, type SpaceGraphModelOptions } from '@dxos/schema';
|
|
@@ -14,6 +15,7 @@ export const useGraphModel = (
|
|
|
14
15
|
options?: SpaceGraphModelOptions,
|
|
15
16
|
queue?: Queue,
|
|
16
17
|
): SpaceGraphModel | undefined => {
|
|
18
|
+
const registry = useContext(RegistryContext);
|
|
17
19
|
const [model, setModel] = useState<SpaceGraphModel | undefined>(undefined);
|
|
18
20
|
useEffect(() => {
|
|
19
21
|
if (!space) {
|
|
@@ -24,13 +26,13 @@ export const useGraphModel = (
|
|
|
24
26
|
|
|
25
27
|
// TODO(burdon): Does this need to be a dependency?
|
|
26
28
|
if (!model || model.queue !== queue) {
|
|
27
|
-
const model = new SpaceGraphModel().setFilter(filter).setOptions(options);
|
|
28
|
-
void model.open(space, queue);
|
|
29
|
+
const model = new SpaceGraphModel(registry).setFilter(filter).setOptions(options);
|
|
30
|
+
void model.open(space.db, queue);
|
|
29
31
|
setModel(model);
|
|
30
32
|
} else {
|
|
31
33
|
model.setFilter(filter).setOptions(options);
|
|
32
34
|
}
|
|
33
|
-
}, [space, filter, options, queue]);
|
|
35
|
+
}, [space, filter, options, queue, registry]);
|
|
34
36
|
|
|
35
37
|
return model;
|
|
36
38
|
};
|
package/src/meta.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
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:
|
|
8
|
+
export const meta: Plugin.Meta = {
|
|
9
9
|
id: 'dxos.org/plugin/explorer',
|
|
10
10
|
name: 'Explorer',
|
|
11
11
|
description: trim`
|
package/src/translations.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
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
|
|
|
@@ -11,7 +12,7 @@ import { Graph } from './types';
|
|
|
11
12
|
export const translations = [
|
|
12
13
|
{
|
|
13
14
|
'en-US': {
|
|
14
|
-
[Graph.Graph
|
|
15
|
+
[Type.getTypename(Graph.Graph)]: {
|
|
15
16
|
'typename label': 'Explorer',
|
|
16
17
|
'typename label_zero': 'Explorers',
|
|
17
18
|
'typename label_one': 'Explorer',
|
|
@@ -19,6 +20,7 @@ export const translations = [
|
|
|
19
20
|
'object name placeholder': 'New explorer',
|
|
20
21
|
'rename object label': 'Rename explorer',
|
|
21
22
|
'delete object label': 'Delete explorer',
|
|
23
|
+
'object deleted label': 'Explorer deleted',
|
|
22
24
|
},
|
|
23
25
|
[meta.id]: {
|
|
24
26
|
'plugin name': 'Explorer',
|
|
@@ -4,26 +4,18 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import { DataType, TypenameAnnotationId } 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
|
-
|
|
17
|
-
|
|
18
|
-
title: 'Select
|
|
19
|
-
|
|
11
|
+
// TODO(wittjosiah): This should be a query input instead.
|
|
12
|
+
typename: Schema.String.pipe(
|
|
13
|
+
Schema.annotations({ title: 'Select type' }),
|
|
14
|
+
TypeInputOptionsAnnotation.set({
|
|
15
|
+
location: ['database', 'runtime'],
|
|
16
|
+
kind: ['user'],
|
|
17
|
+
registered: ['registered'],
|
|
18
|
+
}),
|
|
19
|
+
Schema.optional,
|
|
20
|
+
),
|
|
20
21
|
});
|
|
21
|
-
|
|
22
|
-
export class CreateGraph extends Schema.TaggedClass<CreateGraph>()(`${EXPLORER_ACTION}/create-graph`, {
|
|
23
|
-
input: Schema.Struct({
|
|
24
|
-
space: SpaceSchema,
|
|
25
|
-
}).pipe(Schema.extend(GraphProps)),
|
|
26
|
-
output: Schema.Struct({
|
|
27
|
-
object: DataType.View,
|
|
28
|
-
}),
|
|
29
|
-
}) {}
|
package/src/types/Graph.ts
CHANGED
|
@@ -4,42 +4,59 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import { Filter, Obj, Query, QueryAST, Type } from '@dxos/echo';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
7
|
+
import { Filter, Obj, Query, QueryAST, Ref, Type } from '@dxos/echo';
|
|
8
|
+
import { FormInputAnnotation, LabelAnnotation } from '@dxos/echo/internal';
|
|
9
|
+
import { View, ViewAnnotation } from '@dxos/schema';
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
const GraphSchema = Schema.Struct({
|
|
12
12
|
name: Schema.optional(Schema.String),
|
|
13
|
+
|
|
14
|
+
view: Type.Ref(View.View).pipe(FormInputAnnotation.set(false)),
|
|
15
|
+
|
|
13
16
|
query: Schema.Struct({
|
|
14
17
|
raw: Schema.optional(Schema.String),
|
|
15
18
|
ast: QueryAST.Query,
|
|
16
|
-
}).pipe(
|
|
19
|
+
}).pipe(FormInputAnnotation.set(false)),
|
|
17
20
|
}).pipe(
|
|
18
|
-
Type.
|
|
21
|
+
Type.object({
|
|
19
22
|
typename: 'dxos.org/type/Graph',
|
|
20
|
-
version: '0.
|
|
23
|
+
version: '0.2.0',
|
|
21
24
|
}),
|
|
22
25
|
LabelAnnotation.set(['name']),
|
|
23
26
|
ViewAnnotation.set(true),
|
|
24
27
|
);
|
|
28
|
+
export interface Graph extends Schema.Schema.Type<typeof GraphSchema> {}
|
|
29
|
+
export const Graph: Type.Obj<Graph> = GraphSchema as any;
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Make a graph object.
|
|
30
|
-
*/
|
|
31
|
-
export const make = (
|
|
32
|
-
props: Obj.MakeProps<typeof Graph> = { query: { raw: '', ast: Query.select(Filter.nothing()).ast } },
|
|
33
|
-
) => Obj.make(Graph, props);
|
|
34
|
-
|
|
35
|
-
type MakeViewProps = Omit<CreateViewFromSpaceProps, 'presentation'> & {
|
|
36
|
-
presentation?: Omit<Obj.MakeProps<typeof Graph>, 'name'>;
|
|
31
|
+
type MakeProps = Omit<Partial<Obj.MakeProps<typeof Graph>>, 'view'> & {
|
|
32
|
+
view: View.View;
|
|
37
33
|
};
|
|
38
34
|
|
|
39
35
|
/**
|
|
40
36
|
* Make a graph as a view of a data set.
|
|
41
37
|
*/
|
|
42
|
-
export const
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
export const make = ({
|
|
39
|
+
name,
|
|
40
|
+
query = { raw: '', ast: Query.select(Filter.nothing()).ast },
|
|
41
|
+
view,
|
|
42
|
+
}: MakeProps): Graph => {
|
|
43
|
+
return Obj.make(Graph, { name, view: Ref.make(view), query });
|
|
45
44
|
};
|
|
45
|
+
|
|
46
|
+
//
|
|
47
|
+
// V1
|
|
48
|
+
//
|
|
49
|
+
|
|
50
|
+
export const GraphV1 = Schema.Struct({
|
|
51
|
+
name: Schema.optional(Schema.String),
|
|
52
|
+
query: Schema.Struct({
|
|
53
|
+
raw: Schema.optional(Schema.String),
|
|
54
|
+
ast: QueryAST.Query,
|
|
55
|
+
}),
|
|
56
|
+
}).pipe(
|
|
57
|
+
Type.object({
|
|
58
|
+
typename: 'dxos.org/type/Graph',
|
|
59
|
+
version: '0.1.0',
|
|
60
|
+
}),
|
|
61
|
+
LabelAnnotation.set(['name']),
|
|
62
|
+
);
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useGraphModel
|
|
3
|
-
} from "./chunk-2MKBRIUT.mjs";
|
|
4
|
-
import {
|
|
5
|
-
D3ForceGraph
|
|
6
|
-
} from "./chunk-6BVXZQPP.mjs";
|
|
7
|
-
import "./chunk-J5LGTIGS.mjs";
|
|
8
|
-
|
|
9
|
-
// src/components/ExplorerContainer.tsx
|
|
10
|
-
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
11
|
-
import React, { useCallback, useMemo, useState } from "react";
|
|
12
|
-
import { QueryBuilder } from "@dxos/echo-query";
|
|
13
|
-
import { useGlobalSearch } from "@dxos/plugin-search";
|
|
14
|
-
import { getSpace } from "@dxos/react-client/echo";
|
|
15
|
-
import { Toolbar } from "@dxos/react-ui";
|
|
16
|
-
import { QueryEditor } from "@dxos/react-ui-components";
|
|
17
|
-
import { StackItem } from "@dxos/react-ui-stack";
|
|
18
|
-
var ExplorerContainer = ({ role, view }) => {
|
|
19
|
-
var _effect = _useSignals();
|
|
20
|
-
try {
|
|
21
|
-
const space = getSpace(view);
|
|
22
|
-
const [filter, setFilter] = useState();
|
|
23
|
-
const model = useGraphModel(space, filter);
|
|
24
|
-
const { match } = useGlobalSearch();
|
|
25
|
-
const builder = useMemo(() => new QueryBuilder(), []);
|
|
26
|
-
const handleChange = useCallback((value) => {
|
|
27
|
-
setFilter(builder.build(value).filter);
|
|
28
|
-
}, []);
|
|
29
|
-
const showToolbar = role === "article";
|
|
30
|
-
if (!space || !model) {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
return /* @__PURE__ */ React.createElement(StackItem.Content, {
|
|
34
|
-
toolbar: showToolbar
|
|
35
|
-
}, showToolbar && /* @__PURE__ */ React.createElement(Toolbar.Root, null, /* @__PURE__ */ React.createElement(QueryEditor, {
|
|
36
|
-
db: space.db,
|
|
37
|
-
onChange: handleChange
|
|
38
|
-
})), /* @__PURE__ */ React.createElement(D3ForceGraph, {
|
|
39
|
-
model,
|
|
40
|
-
match
|
|
41
|
-
}));
|
|
42
|
-
} finally {
|
|
43
|
-
_effect.f();
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
var ExplorerContainer_default = ExplorerContainer;
|
|
47
|
-
export {
|
|
48
|
-
ExplorerContainer_default as default
|
|
49
|
-
};
|
|
50
|
-
//# sourceMappingURL=ExplorerContainer-L5RVUJRL.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/ExplorerContainer.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { useCallback, useMemo, useState } from 'react';\n\nimport { type Filter } from '@dxos/echo';\nimport { QueryBuilder } from '@dxos/echo-query';\nimport { useGlobalSearch } from '@dxos/plugin-search';\nimport { getSpace } from '@dxos/react-client/echo';\nimport { Toolbar } from '@dxos/react-ui';\nimport { QueryEditor, type QueryEditorProps } from '@dxos/react-ui-components';\nimport { StackItem } from '@dxos/react-ui-stack';\nimport { type DataType } from '@dxos/schema';\n\nimport { useGraphModel } from '../hooks';\n\nimport { D3ForceGraph } from './Graph';\n\ntype ExplorerContainerProps = {\n role: string;\n view: DataType.View;\n};\n\nconst ExplorerContainer = ({ role, view }: ExplorerContainerProps) => {\n const space = getSpace(view);\n const [filter, setFilter] = useState<Filter.Any>();\n const model = useGraphModel(space, filter);\n const { match } = useGlobalSearch();\n\n const builder = useMemo(() => new QueryBuilder(), []);\n const handleChange = useCallback<NonNullable<QueryEditorProps['onChange']>>((value) => {\n setFilter(builder.build(value).filter);\n }, []);\n\n const showToolbar = role === 'article';\n\n if (!space || !model) {\n return null;\n }\n\n return (\n <StackItem.Content toolbar={showToolbar}>\n {showToolbar && (\n <Toolbar.Root>\n <QueryEditor db={space.db} onChange={handleChange} />\n </Toolbar.Root>\n )}\n <D3ForceGraph model={model} match={match} />\n </StackItem.Content>\n );\n};\n\nexport default ExplorerContainer;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;AAIA,OAAOA,SAASC,aAAaC,SAASC,gBAAgB;AAGtD,SAASC,oBAAoB;AAC7B,SAASC,uBAAuB;AAChC,SAASC,gBAAgB;AACzB,SAASC,eAAe;AACxB,SAASC,mBAA0C;AACnD,SAASC,iBAAiB;AAY1B,IAAMC,oBAAoB,CAAC,EAAEC,MAAMC,KAAI,MAA0B;;;AAC/D,UAAMC,QAAQC,SAASF,IAAAA;AACvB,UAAM,CAACG,QAAQC,SAAAA,IAAaC,SAAAA;AAC5B,UAAMC,QAAQC,cAAcN,OAAOE,MAAAA;AACnC,UAAM,EAAEK,MAAK,IAAKC,gBAAAA;AAElB,UAAMC,UAAUC,QAAQ,MAAM,IAAIC,aAAAA,GAAgB,CAAA,CAAE;AACpD,UAAMC,eAAeC,YAAuD,CAACC,UAAAA;AAC3EX,gBAAUM,QAAQM,MAAMD,KAAAA,EAAOZ,MAAM;IACvC,GAAG,CAAA,CAAE;AAEL,UAAMc,cAAclB,SAAS;AAE7B,QAAI,CAACE,SAAS,CAACK,OAAO;AACpB,aAAO;IACT;AAEA,WACE,sBAAA,cAACY,UAAUC,SAAO;MAACC,SAASH;OACzBA,eACC,sBAAA,cAACI,QAAQC,MAAI,MACX,sBAAA,cAACC,aAAAA;MAAYC,IAAIvB,MAAMuB;MAAIC,UAAUZ;SAGzC,sBAAA,cAACa,cAAAA;MAAapB;MAAcE;;;;;AAGlC;AAEA,IAAA,4BAAeV;",
|
|
6
|
-
"names": ["React", "useCallback", "useMemo", "useState", "QueryBuilder", "useGlobalSearch", "getSpace", "Toolbar", "QueryEditor", "StackItem", "ExplorerContainer", "role", "view", "space", "getSpace", "filter", "setFilter", "useState", "model", "useGraphModel", "match", "useGlobalSearch", "builder", "useMemo", "QueryBuilder", "handleChange", "useCallback", "value", "build", "showToolbar", "StackItem", "Content", "toolbar", "Toolbar", "Root", "QueryEditor", "db", "onChange", "D3ForceGraph"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/useGraphModel.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type Filter, type Queue, type Space } from '@dxos/client/echo';\nimport { SpaceGraphModel, type SpaceGraphModelOptions } from '@dxos/schema';\n\n// TODO(burdon): Factor out.\nexport const useGraphModel = (\n space: Space | undefined,\n filter?: Filter.Any | undefined,\n options?: SpaceGraphModelOptions,\n queue?: Queue,\n): SpaceGraphModel | undefined => {\n const [model, setModel] = useState<SpaceGraphModel | undefined>(undefined);\n useEffect(() => {\n if (!space) {\n void model?.close();\n setModel(undefined);\n return;\n }\n\n // TODO(burdon): Does this need to be a dependency?\n if (!model || model.queue !== queue) {\n const model = new SpaceGraphModel().setFilter(filter).setOptions(options);\n void model.open(space, queue);\n setModel(model);\n } else {\n model.setFilter(filter).setOptions(options);\n }\n }, [space, filter, options, queue]);\n\n return model;\n};\n"],
|
|
5
|
-
"mappings": ";AAIA,SAASA,WAAWC,gBAAgB;AAGpC,SAASC,uBAAoD;AAGtD,IAAMC,gBAAgB,CAC3BC,OACAC,QACAC,SACAC,UAAAA;AAEA,QAAM,CAACC,OAAOC,QAAAA,IAAYC,SAAsCC,MAAAA;AAChEC,YAAU,MAAA;AACR,QAAI,CAACR,OAAO;AACV,WAAKI,OAAOK,MAAAA;AACZJ,eAASE,MAAAA;AACT;IACF;AAGA,QAAI,CAACH,SAASA,MAAMD,UAAUA,OAAO;AACnC,YAAMC,SAAQ,IAAIM,gBAAAA,EAAkBC,UAAUV,MAAAA,EAAQW,WAAWV,OAAAA;AACjE,WAAKE,OAAMS,KAAKb,OAAOG,KAAAA;AACvBE,eAASD,MAAAA;IACX,OAAO;AACLA,YAAMO,UAAUV,MAAAA,EAAQW,WAAWV,OAAAA;IACrC;EACF,GAAG;IAACF;IAAOC;IAAQC;IAASC;GAAM;AAElC,SAAOC;AACT;",
|
|
6
|
-
"names": ["useEffect", "useState", "SpaceGraphModel", "useGraphModel", "space", "filter", "options", "queue", "model", "setModel", "useState", "undefined", "useEffect", "close", "SpaceGraphModel", "setFilter", "setOptions", "open"]
|
|
7
|
-
}
|