@dxos/plugin-explorer 0.8.2-main.fbd8ed0 → 0.8.2-staging.4d6ad0f
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-BBZ54DJS.mjs +37 -0
- package/dist/lib/browser/ExplorerContainer-BBZ54DJS.mjs.map +7 -0
- package/dist/lib/browser/{chunk-JL7ZGOFE.mjs → chunk-73GQ46YO.mjs} +415 -155
- package/dist/lib/{node-esm/chunk-MUHCE377.mjs.map → browser/chunk-73GQ46YO.mjs.map} +4 -4
- package/dist/lib/browser/{chunk-HKQSZX7S.mjs → chunk-73YTQHOT.mjs} +3 -3
- package/dist/lib/browser/{chunk-HKQSZX7S.mjs.map → chunk-73YTQHOT.mjs.map} +1 -1
- package/dist/lib/browser/chunk-M2BGAY6H.mjs +177 -0
- package/dist/lib/browser/chunk-M2BGAY6H.mjs.map +7 -0
- package/dist/lib/browser/{chunk-Z2SDLMQM.mjs → chunk-OBAFAA5V.mjs} +3 -3
- package/dist/lib/browser/{chunk-Z2SDLMQM.mjs.map → chunk-OBAFAA5V.mjs.map} +1 -1
- package/dist/lib/browser/chunk-SLB2F5AO.mjs +30 -0
- package/dist/lib/browser/chunk-SLB2F5AO.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +15 -11
- package/dist/lib/browser/index.mjs.map +1 -1
- package/dist/lib/browser/{intent-resolver-7JF4DU2C.mjs → intent-resolver-FJDVBDE3.mjs} +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/meta.mjs +1 -1
- package/dist/lib/browser/{react-surface-JLE6GLG6.mjs → react-surface-H3YDMXAQ.mjs} +5 -5
- package/dist/lib/browser/types/index.mjs +2 -2
- package/dist/lib/node/{ExplorerContainer-4RMWCWRX.cjs → ExplorerContainer-MVP2AM7R.cjs} +24 -16
- package/dist/lib/node/ExplorerContainer-MVP2AM7R.cjs.map +7 -0
- package/dist/lib/node/chunk-4T4LCT5R.cjs +52 -0
- package/dist/lib/node/chunk-4T4LCT5R.cjs.map +7 -0
- package/dist/lib/node/{chunk-R4TOGRPE.cjs → chunk-72H5HBTK.cjs} +414 -153
- package/dist/lib/node/{chunk-R4TOGRPE.cjs.map → chunk-72H5HBTK.cjs.map} +4 -4
- package/dist/lib/node/{chunk-VB3QE6XY.cjs → chunk-BCDVG2CH.cjs} +6 -6
- package/dist/lib/node/{chunk-VB3QE6XY.cjs.map → chunk-BCDVG2CH.cjs.map} +1 -1
- package/dist/lib/node/{chunk-6R5P3UVS.cjs → chunk-MLRYW4WQ.cjs} +7 -7
- package/dist/lib/node/{chunk-6R5P3UVS.cjs.map → chunk-MLRYW4WQ.cjs.map} +1 -1
- package/dist/lib/node/chunk-NELWWGBU.cjs +204 -0
- package/dist/lib/node/chunk-NELWWGBU.cjs.map +7 -0
- package/dist/lib/node/index.cjs +34 -31
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/{intent-resolver-VDAHQEE7.cjs → intent-resolver-DRT67ZU4.cjs} +8 -8
- package/dist/lib/node/meta.cjs +3 -3
- package/dist/lib/node/meta.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/{react-surface-F66QYWDR.cjs → react-surface-6ESLSM33.cjs} +11 -11
- package/dist/lib/node/types/index.cjs +4 -4
- package/dist/lib/node/types/index.cjs.map +1 -1
- package/dist/lib/node-esm/ExplorerContainer-APGUQI4M.mjs +38 -0
- package/dist/lib/node-esm/ExplorerContainer-APGUQI4M.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-MUHCE377.mjs → chunk-34X2VFQN.mjs} +415 -154
- package/dist/lib/{browser/chunk-JL7ZGOFE.mjs.map → node-esm/chunk-34X2VFQN.mjs.map} +4 -4
- package/dist/lib/node-esm/{chunk-PUFSCMN4.mjs → chunk-3CMBLK6W.mjs} +3 -3
- package/dist/lib/node-esm/{chunk-PUFSCMN4.mjs.map → chunk-3CMBLK6W.mjs.map} +1 -1
- package/dist/lib/node-esm/{chunk-QOJSLABX.mjs → chunk-N6VEANUZ.mjs} +3 -3
- package/dist/lib/node-esm/{chunk-QOJSLABX.mjs.map → chunk-N6VEANUZ.mjs.map} +1 -1
- package/dist/lib/node-esm/chunk-PVII2K2B.mjs +179 -0
- package/dist/lib/node-esm/chunk-PVII2K2B.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-VSORIAHH.mjs +32 -0
- package/dist/lib/node-esm/chunk-VSORIAHH.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +15 -11
- package/dist/lib/node-esm/index.mjs.map +1 -1
- package/dist/lib/node-esm/{intent-resolver-XWRVHP6H.mjs → intent-resolver-4RBV644N.mjs} +3 -3
- 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-4ZT5BQP6.mjs → react-surface-ZEVL3FXG.mjs} +5 -5
- package/dist/lib/node-esm/types/index.mjs +2 -2
- package/dist/types/src/components/ExplorerContainer.d.ts +4 -3
- package/dist/types/src/components/ExplorerContainer.d.ts.map +1 -1
- package/dist/types/src/components/Graph/D3ForceGraph.d.ts +14 -0
- package/dist/types/src/components/Graph/D3ForceGraph.d.ts.map +1 -0
- package/dist/types/src/components/Graph/D3ForceGraph.stories.d.ts +6 -0
- package/dist/types/src/components/Graph/D3ForceGraph.stories.d.ts.map +1 -0
- package/dist/types/src/components/Graph/ForceGraph.d.ts +8 -0
- package/dist/types/src/components/Graph/ForceGraph.d.ts.map +1 -0
- package/dist/types/src/components/Graph/{Graph.stories.d.ts → ForceGraph.stories.d.ts} +1 -1
- package/dist/types/src/components/Graph/ForceGraph.stories.d.ts.map +1 -0
- package/dist/types/src/components/Graph/adapter.d.ts +21 -0
- package/dist/types/src/components/Graph/adapter.d.ts.map +1 -0
- package/dist/types/src/components/Graph/index.d.ts +2 -2
- package/dist/types/src/components/Graph/index.d.ts.map +1 -1
- package/dist/types/src/components/Graph/testing.d.ts +14 -0
- package/dist/types/src/components/Graph/testing.d.ts.map +1 -0
- package/dist/types/src/components/Tree/Tree.d.ts.map +1 -1
- package/dist/types/src/components/Tree/testing/generator.d.ts +8 -0
- package/dist/types/src/components/Tree/testing/generator.d.ts.map +1 -0
- package/dist/types/src/components/Tree/testing/index.d.ts +2 -0
- package/dist/types/src/components/Tree/testing/index.d.ts.map +1 -0
- package/dist/types/src/components/Tree/types/index.d.ts +3 -0
- package/dist/types/src/components/Tree/types/index.d.ts.map +1 -0
- package/dist/types/src/components/Tree/types/tree.d.ts +83 -0
- package/dist/types/src/components/Tree/types/tree.d.ts.map +1 -0
- package/dist/types/src/components/Tree/types/tree.test.d.ts +2 -0
- package/dist/types/src/components/Tree/types/tree.test.d.ts.map +1 -0
- package/dist/types/src/components/Tree/types/types.d.ts +8 -0
- package/dist/types/src/components/Tree/types/types.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +2 -2
- package/dist/types/src/hooks/index.d.ts +2 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/useGraphModel.d.ts +4 -0
- package/dist/types/src/hooks/useGraphModel.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/package.json +28 -28
- package/src/components/ExplorerContainer.tsx +11 -4
- package/src/components/Graph/D3ForceGraph.stories.tsx +64 -0
- package/src/components/Graph/D3ForceGraph.tsx +101 -0
- package/src/components/Graph/ForceGraph.stories.tsx +64 -0
- package/src/components/Graph/{Graph.tsx → ForceGraph.tsx} +19 -26
- package/src/components/Graph/adapter.ts +47 -0
- package/src/components/Graph/index.ts +2 -3
- package/src/components/Graph/testing.ts +57 -0
- package/src/components/Tree/Tree.stories.tsx +1 -1
- package/src/components/Tree/Tree.tsx +11 -18
- package/src/components/Tree/testing/generator.ts +46 -0
- package/src/components/Tree/testing/index.ts +5 -0
- package/src/components/Tree/types/index.ts +6 -0
- package/src/components/Tree/types/tree.test.ts +133 -0
- package/src/components/Tree/types/tree.ts +287 -0
- package/src/components/Tree/types/types.ts +41 -0
- package/src/hooks/index.ts +5 -0
- package/src/hooks/useGraphModel.ts +35 -0
- package/src/index.ts +2 -2
- package/src/meta.ts +2 -2
- package/dist/lib/browser/ExplorerContainer-6U4GS62Q.mjs +0 -27
- package/dist/lib/browser/ExplorerContainer-6U4GS62Q.mjs.map +0 -7
- package/dist/lib/browser/chunk-QRPUL5AH.mjs +0 -206
- package/dist/lib/browser/chunk-QRPUL5AH.mjs.map +0 -7
- package/dist/lib/node/ExplorerContainer-4RMWCWRX.cjs.map +0 -7
- package/dist/lib/node/chunk-4ZUNNUQD.cjs +0 -237
- package/dist/lib/node/chunk-4ZUNNUQD.cjs.map +0 -7
- package/dist/lib/node-esm/ExplorerContainer-3GOCCL7Q.mjs +0 -28
- package/dist/lib/node-esm/ExplorerContainer-3GOCCL7Q.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BJZBPCC3.mjs +0 -208
- package/dist/lib/node-esm/chunk-BJZBPCC3.mjs.map +0 -7
- package/dist/types/src/components/Graph/Graph.d.ts +0 -8
- package/dist/types/src/components/Graph/Graph.d.ts.map +0 -1
- package/dist/types/src/components/Graph/Graph.stories.d.ts.map +0 -1
- package/dist/types/src/components/Graph/graph-model.d.ts +0 -39
- package/dist/types/src/components/Graph/graph-model.d.ts.map +0 -1
- package/dist/types/src/components/Tree/types.d.ts +0 -8
- package/dist/types/src/components/Tree/types.d.ts.map +0 -1
- package/src/components/Graph/Graph.stories.tsx +0 -62
- package/src/components/Graph/graph-model.ts +0 -194
- package/src/components/Tree/types.ts +0 -40
- /package/dist/lib/browser/{intent-resolver-7JF4DU2C.mjs.map → intent-resolver-FJDVBDE3.mjs.map} +0 -0
- /package/dist/lib/browser/{react-surface-JLE6GLG6.mjs.map → react-surface-H3YDMXAQ.mjs.map} +0 -0
- /package/dist/lib/node/{intent-resolver-VDAHQEE7.cjs.map → intent-resolver-DRT67ZU4.cjs.map} +0 -0
- /package/dist/lib/node/{react-surface-F66QYWDR.cjs.map → react-surface-6ESLSM33.cjs.map} +0 -0
- /package/dist/lib/node-esm/{intent-resolver-XWRVHP6H.mjs.map → intent-resolver-4RBV644N.mjs.map} +0 -0
- /package/dist/lib/node-esm/{react-surface-4ZT5BQP6.mjs.map → react-surface-ZEVL3FXG.mjs.map} +0 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
|
+
|
|
7
|
+
import { Type } from '@dxos/echo';
|
|
8
|
+
import { ObjectId, Ref, Expando } from '@dxos/echo-schema';
|
|
9
|
+
import { invariant } from '@dxos/invariant';
|
|
10
|
+
import { live } from '@dxos/live-object';
|
|
11
|
+
|
|
12
|
+
// TODO(burdon): Reconcile with @dxos/graph (i.e., common types).
|
|
13
|
+
|
|
14
|
+
export const TreeNodeType = Schema.Struct({
|
|
15
|
+
id: ObjectId,
|
|
16
|
+
children: Schema.mutable(Schema.Array(ObjectId)),
|
|
17
|
+
data: Schema.mutable(Schema.Record({ key: Schema.String, value: Schema.Any })),
|
|
18
|
+
ref: Schema.optional(Ref(Expando)), // TODO(burdon): Generic type?
|
|
19
|
+
}).pipe(Schema.mutable);
|
|
20
|
+
|
|
21
|
+
export interface TreeNodeType extends Schema.Schema.Type<typeof TreeNodeType> {}
|
|
22
|
+
|
|
23
|
+
export const TreeType = Schema.Struct({
|
|
24
|
+
root: ObjectId,
|
|
25
|
+
nodes: Schema.mutable(Schema.Record({ key: ObjectId, value: TreeNodeType })),
|
|
26
|
+
}).pipe(
|
|
27
|
+
Type.Obj({
|
|
28
|
+
typename: 'dxos.org/type/Tree',
|
|
29
|
+
version: '0.1.0',
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
export interface TreeType extends Schema.Schema.Type<typeof TreeType> {}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Wrapper object for tree.
|
|
37
|
+
*/
|
|
38
|
+
export class Tree {
|
|
39
|
+
static create = (): TreeType => {
|
|
40
|
+
const id = ObjectId.random();
|
|
41
|
+
return live(TreeType, {
|
|
42
|
+
root: id,
|
|
43
|
+
nodes: {
|
|
44
|
+
[id]: {
|
|
45
|
+
id,
|
|
46
|
+
children: [],
|
|
47
|
+
data: { text: '' }, // TODO(burdon): Generic.
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
private _tree: TreeType;
|
|
54
|
+
|
|
55
|
+
constructor(tree?: TreeType) {
|
|
56
|
+
this._tree = tree ?? Tree.create();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
get tree() {
|
|
60
|
+
return this._tree;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// TODO(burdon): Make reactive.
|
|
64
|
+
get size() {
|
|
65
|
+
return Object.keys(this._tree.nodes).length;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get root() {
|
|
69
|
+
return this.getNode(this._tree.root);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//
|
|
73
|
+
// Traversal
|
|
74
|
+
//
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Recursively traverse the tree until the callback returns a value.
|
|
78
|
+
*/
|
|
79
|
+
tranverse<T>(
|
|
80
|
+
callback: (node: TreeNodeType, depth: number) => T | void,
|
|
81
|
+
root: ObjectId = this._tree.root,
|
|
82
|
+
depth = 0,
|
|
83
|
+
): T | void {
|
|
84
|
+
const node = this._tree.nodes[root];
|
|
85
|
+
const result = callback(node, depth);
|
|
86
|
+
if (result !== undefined) {
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
for (const childId of node.children) {
|
|
91
|
+
const result = this.tranverse(callback, childId, depth + 1);
|
|
92
|
+
if (result !== undefined) {
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
getNode(id: ObjectId): TreeNodeType {
|
|
99
|
+
const node = this._tree.nodes[id];
|
|
100
|
+
invariant(node);
|
|
101
|
+
return node;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Get the children of a node.
|
|
106
|
+
*/
|
|
107
|
+
getChildNodes(node: TreeNodeType): Array<TreeNodeType> {
|
|
108
|
+
return node.children.map((id) => this.getNode(id));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Get the parent of a node.
|
|
113
|
+
*/
|
|
114
|
+
getParent(node: TreeNodeType): TreeNodeType | null {
|
|
115
|
+
const parent = this.tranverse((n) => {
|
|
116
|
+
if (n.children.includes(node.id)) {
|
|
117
|
+
return n;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
return parent ?? null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Get the next node in the tree.
|
|
126
|
+
*/
|
|
127
|
+
getNext(node: TreeNodeType, hierarchical = true): TreeNodeType | undefined {
|
|
128
|
+
if (hierarchical && node.children.length) {
|
|
129
|
+
// First child.
|
|
130
|
+
return this.getChildNodes(node)[0];
|
|
131
|
+
} else {
|
|
132
|
+
const parent = this.getParent(node);
|
|
133
|
+
if (parent) {
|
|
134
|
+
const idx = this.getChildNodes(parent).findIndex(({ id }) => id === node.id);
|
|
135
|
+
if (idx < parent.children.length - 1) {
|
|
136
|
+
// Next sibling.
|
|
137
|
+
return this.getNode(parent.children[idx + 1]);
|
|
138
|
+
} else {
|
|
139
|
+
// Get parent's next sibling.
|
|
140
|
+
return this.getNext(parent, false);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Get the previous node in the tree.
|
|
148
|
+
*/
|
|
149
|
+
getPrevious(node: TreeNodeType, hierarchical = true): TreeNodeType | undefined {
|
|
150
|
+
const parent = this.getParent(node)!;
|
|
151
|
+
const idx = this.getChildNodes(parent).findIndex(({ id }) => id === node.id);
|
|
152
|
+
if (idx === 0) {
|
|
153
|
+
if (hierarchical) {
|
|
154
|
+
return parent;
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
const previous = this.getNode(parent.children[idx - 1]);
|
|
158
|
+
if (hierarchical && previous.children.length) {
|
|
159
|
+
return this.getLastDescendent(previous);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return previous;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Get the last descendent of a node.
|
|
168
|
+
*/
|
|
169
|
+
getLastDescendent(node: TreeNodeType): TreeNodeType | undefined {
|
|
170
|
+
const children = this.getChildNodes(node);
|
|
171
|
+
const last = children.length ? children[children.length - 1] : undefined;
|
|
172
|
+
if (last) {
|
|
173
|
+
return this.getLastDescendent(last);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return node;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
//
|
|
180
|
+
// Mutations
|
|
181
|
+
//
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Clear tree.
|
|
185
|
+
*/
|
|
186
|
+
clear(): void {
|
|
187
|
+
const root = this._tree.nodes[this._tree.root];
|
|
188
|
+
root.children.length = 0;
|
|
189
|
+
this._tree.nodes = {
|
|
190
|
+
[root.id]: root,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Add node.
|
|
196
|
+
*/
|
|
197
|
+
addNode(parent: TreeNodeType, node?: TreeNodeType, index?: number): TreeNodeType {
|
|
198
|
+
if (!node) {
|
|
199
|
+
const id = ObjectId.random();
|
|
200
|
+
node = { id, children: [], data: { text: '' } }; // TODO(burdon): Generic.
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
this._tree.nodes[node.id] = node;
|
|
204
|
+
parent.children.splice(index ?? parent.children.length, 0, node.id);
|
|
205
|
+
return node;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Delete node.
|
|
210
|
+
*/
|
|
211
|
+
deleteNode(parent: TreeNodeType, id: ObjectId): TreeNodeType | undefined {
|
|
212
|
+
const node = this._tree.nodes[id];
|
|
213
|
+
if (!node) {
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
delete this._tree.nodes[node.id];
|
|
218
|
+
const idx = parent.children.findIndex((child) => child === id);
|
|
219
|
+
if (idx !== -1) {
|
|
220
|
+
parent.children.splice(idx, 1);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return node;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Move child node.
|
|
228
|
+
*/
|
|
229
|
+
moveNode(node: TreeNodeType, from: number, to: number): TreeNodeType | null {
|
|
230
|
+
invariant(from >= 0 && from < node.children.length);
|
|
231
|
+
invariant(to >= 0 && to < node.children.length);
|
|
232
|
+
if (from === to) {
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const child = node.children[from];
|
|
237
|
+
node.children.splice(from, 1);
|
|
238
|
+
node.children.splice(to, 0, child);
|
|
239
|
+
return this.getNode(child);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Indent node.
|
|
244
|
+
*/
|
|
245
|
+
indentNode(node: TreeNodeType): void {
|
|
246
|
+
const parent = this.getParent(node);
|
|
247
|
+
if (!parent) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const idx = parent.children.findIndex((child) => child === node.id);
|
|
252
|
+
if (idx < 1 || idx >= parent.children.length) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const previous = this.getNode(parent.children[idx - 1]);
|
|
257
|
+
parent.children.splice(idx, 1);
|
|
258
|
+
previous.children.push(node.id);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Unindent node.
|
|
263
|
+
*/
|
|
264
|
+
unindentNode(node: TreeNodeType): void {
|
|
265
|
+
const parent = this.getParent(node);
|
|
266
|
+
if (!parent) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const ancestor = this.getParent(parent);
|
|
271
|
+
if (!ancestor) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Remove node from parent.
|
|
276
|
+
const nodeIdx = parent.children.findIndex((id) => id === node.id);
|
|
277
|
+
const [_, ...rest] = parent.children.splice(nodeIdx, parent.children.length - nodeIdx);
|
|
278
|
+
parent.children.splice(nodeIdx, parent.children.length - nodeIdx);
|
|
279
|
+
|
|
280
|
+
// Add to ancestor.
|
|
281
|
+
const parentIdx = this.getChildNodes(ancestor).findIndex((n) => n.id === parent.id);
|
|
282
|
+
ancestor.children.splice(parentIdx + 1, 0, node.id);
|
|
283
|
+
|
|
284
|
+
// Transplant following siblings to current node.
|
|
285
|
+
node.children.push(...rest);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type GraphModel } from '@dxos/graph';
|
|
6
|
+
|
|
7
|
+
export type TreeNode = {
|
|
8
|
+
id: string;
|
|
9
|
+
label?: string;
|
|
10
|
+
children?: TreeNode[];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const mapGraphToTreeData = (model: GraphModel, maxDepth = 8): TreeNode | undefined => {
|
|
14
|
+
// TODO(burdon): Convert to common/graph.
|
|
15
|
+
// const mapNode = (node: N, depth = 0): TreeNode => {
|
|
16
|
+
// const treeNode: TreeNode = {
|
|
17
|
+
// id: model.idAccessor(node),
|
|
18
|
+
// label: model.idAccessor(node).slice(0, 8),
|
|
19
|
+
// };
|
|
20
|
+
|
|
21
|
+
// const links = model.graph.links.filter((link) => link.source === treeNode.id);
|
|
22
|
+
// if (depth < maxDepth) {
|
|
23
|
+
// treeNode.children = links.map((link) =>
|
|
24
|
+
// mapNode(model.graph.nodes.find((node) => model.idAccessor(node) === link.target)!, depth + 1),
|
|
25
|
+
// );
|
|
26
|
+
// }
|
|
27
|
+
|
|
28
|
+
// return treeNode;
|
|
29
|
+
// };
|
|
30
|
+
|
|
31
|
+
let data: TreeNode | undefined;
|
|
32
|
+
// TODO(burdon): Selection model.
|
|
33
|
+
// if (model.selected) {
|
|
34
|
+
// const node = model.graph.nodes.find((node) => model.idAccessor(node) === model.selected);
|
|
35
|
+
// if (node) {
|
|
36
|
+
// data = mapNode(node);
|
|
37
|
+
// }
|
|
38
|
+
// }
|
|
39
|
+
|
|
40
|
+
return data;
|
|
41
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useEffect, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type Filter, type Space } from '@dxos/client/echo';
|
|
8
|
+
import { SpaceGraphModel, type SpaceGraphModelOptions } from '@dxos/schema';
|
|
9
|
+
|
|
10
|
+
// TODO(burdon): Factor out.
|
|
11
|
+
export const useGraphModel = (
|
|
12
|
+
space: Space | undefined,
|
|
13
|
+
filter?: Filter.Any | undefined,
|
|
14
|
+
options?: SpaceGraphModelOptions,
|
|
15
|
+
): SpaceGraphModel | undefined => {
|
|
16
|
+
const [model, setModel] = useState<SpaceGraphModel | undefined>(undefined);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (!space) {
|
|
19
|
+
void model?.close();
|
|
20
|
+
setModel(undefined);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// TODO(burdon): Does this need to be a dependency?
|
|
25
|
+
if (!model) {
|
|
26
|
+
const model = new SpaceGraphModel().setFilter(filter).setOptions(options);
|
|
27
|
+
void model.open(space);
|
|
28
|
+
setModel(model);
|
|
29
|
+
} else {
|
|
30
|
+
model.setFilter(filter).setOptions(options);
|
|
31
|
+
}
|
|
32
|
+
}, [space, filter, options]);
|
|
33
|
+
|
|
34
|
+
return model;
|
|
35
|
+
};
|
package/src/index.ts
CHANGED
package/src/meta.ts
CHANGED
|
@@ -11,7 +11,7 @@ export const meta: PluginMeta = {
|
|
|
11
11
|
name: 'Explorer',
|
|
12
12
|
description: 'Install this plugin to view a hypergraph of all objects inside of your Space.',
|
|
13
13
|
icon: 'ph--graph--regular',
|
|
14
|
-
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/
|
|
15
|
-
tags: ['
|
|
14
|
+
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-explorer',
|
|
15
|
+
tags: ['labs'],
|
|
16
16
|
screenshots: ['https://dxos.network/plugin-details-explorer-dark.png'],
|
|
17
17
|
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Graph
|
|
3
|
-
} from "./chunk-QRPUL5AH.mjs";
|
|
4
|
-
|
|
5
|
-
// packages/plugins/plugin-explorer/src/components/ExplorerContainer.tsx
|
|
6
|
-
import React from "react";
|
|
7
|
-
import { useGlobalSearch } from "@dxos/plugin-search";
|
|
8
|
-
import { getSpace } from "@dxos/react-client/echo";
|
|
9
|
-
import { StackItem } from "@dxos/react-ui-stack";
|
|
10
|
-
var ExplorerContainer = ({ view, role }) => {
|
|
11
|
-
const space = getSpace(view);
|
|
12
|
-
const { match } = useGlobalSearch();
|
|
13
|
-
if (!space) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
return /* @__PURE__ */ React.createElement(StackItem.Content, {
|
|
17
|
-
size: role === "section" ? "square" : "intrinsic"
|
|
18
|
-
}, /* @__PURE__ */ React.createElement(Graph, {
|
|
19
|
-
space,
|
|
20
|
-
match
|
|
21
|
-
}));
|
|
22
|
-
};
|
|
23
|
-
var ExplorerContainer_default = ExplorerContainer;
|
|
24
|
-
export {
|
|
25
|
-
ExplorerContainer_default as default
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=ExplorerContainer-6U4GS62Q.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 from 'react';\n\nimport { useGlobalSearch } from '@dxos/plugin-search';\nimport { getSpace } from '@dxos/react-client/echo';\nimport { StackItem } from '@dxos/react-ui-stack';\n\nimport { Graph } from './Graph';\nimport { type ViewType } from '../types';\n\nconst ExplorerContainer = ({ view, role }: { view: ViewType; role: string }) => {\n const space = getSpace(view);\n const { match } = useGlobalSearch();\n\n if (!space) {\n return null;\n }\n\n return (\n <StackItem.Content size={role === 'section' ? 'square' : 'intrinsic'}>\n <Graph space={space} match={match} />\n </StackItem.Content>\n );\n};\n\nexport default ExplorerContainer;\n"],
|
|
5
|
-
"mappings": ";;;;;AAIA,OAAOA,WAAW;AAElB,SAASC,uBAAuB;AAChC,SAASC,gBAAgB;AACzB,SAASC,iBAAiB;AAK1B,IAAMC,oBAAoB,CAAC,EAAEC,MAAMC,KAAI,MAAoC;AACzE,QAAMC,QAAQC,SAASH,IAAAA;AACvB,QAAM,EAAEI,MAAK,IAAKC,gBAAAA;AAElB,MAAI,CAACH,OAAO;AACV,WAAO;EACT;AAEA,SACE,sBAAA,cAACI,UAAUC,SAAO;IAACC,MAAMP,SAAS,YAAY,WAAW;KACvD,sBAAA,cAACQ,OAAAA;IAAMP;IAAcE;;AAG3B;AAEA,IAAA,4BAAeL;",
|
|
6
|
-
"names": ["React", "useGlobalSearch", "getSpace", "StackItem", "ExplorerContainer", "view", "role", "space", "getSpace", "match", "useGlobalSearch", "StackItem", "Content", "size", "Graph"]
|
|
7
|
-
}
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
// packages/plugins/plugin-explorer/src/components/Graph/graph-model.ts
|
|
2
|
-
import { SchemaAST } from "effect";
|
|
3
|
-
import { getSchema, getSchemaDXN, ReferenceAnnotationId, SchemaValidator, StoredSchema } from "@dxos/echo-schema";
|
|
4
|
-
import { GraphModel } from "@dxos/gem-spore";
|
|
5
|
-
import { log } from "@dxos/log";
|
|
6
|
-
import { CollectionType } from "@dxos/plugin-space/types";
|
|
7
|
-
import { Filter } from "@dxos/react-client/echo";
|
|
8
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-explorer/src/components/Graph/graph-model.ts";
|
|
9
|
-
var SpaceGraphModel = class extends GraphModel {
|
|
10
|
-
constructor(_options = {}) {
|
|
11
|
-
super();
|
|
12
|
-
this._options = _options;
|
|
13
|
-
this._graph = {
|
|
14
|
-
nodes: [],
|
|
15
|
-
links: []
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
get graph() {
|
|
19
|
-
return this._graph;
|
|
20
|
-
}
|
|
21
|
-
get objects() {
|
|
22
|
-
return this._objects ?? [];
|
|
23
|
-
}
|
|
24
|
-
// TODO(burdon): Alternative diagram types:
|
|
25
|
-
// - https://observablehq.com/@d3/radial-tree/2
|
|
26
|
-
// - https://observablehq.com/@d3/disjoint-force-directed-graph/2
|
|
27
|
-
// - https://observablehq.com/@mbostock/tadpoles
|
|
28
|
-
// - https://observablehq.com/@d3/psr-b1919-21
|
|
29
|
-
// - https://vasturiano.github.io/react-force-graph/example/basic (3D)
|
|
30
|
-
async open(space, objectId) {
|
|
31
|
-
if (!this._schemaSubscription) {
|
|
32
|
-
const schemaaQuery = space.db.schemaRegistry.query({});
|
|
33
|
-
const schemas = await schemaaQuery.run();
|
|
34
|
-
const onSchemaUpdate = ({ results }) => this._schema = results;
|
|
35
|
-
this._schemaSubscription = schemaaQuery.subscribe(onSchemaUpdate);
|
|
36
|
-
onSchemaUpdate({
|
|
37
|
-
results: schemas
|
|
38
|
-
});
|
|
39
|
-
this._objectsSubscription = space.db.query(Filter.not(Filter.or(Filter.type(StoredSchema), Filter.type(CollectionType)))).subscribe(({ objects }) => {
|
|
40
|
-
this._objects = objects;
|
|
41
|
-
const currentNodes = this._graph.nodes;
|
|
42
|
-
this._graph.nodes = [];
|
|
43
|
-
this._graph.links = [];
|
|
44
|
-
const addSchema = (typename) => {
|
|
45
|
-
const current = currentNodes.find((node) => node.id === typename);
|
|
46
|
-
if (typename) {
|
|
47
|
-
this._graph.nodes.push({
|
|
48
|
-
...current,
|
|
49
|
-
id: typename,
|
|
50
|
-
type: "schema",
|
|
51
|
-
data: {
|
|
52
|
-
typename
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
space.db.graph.schemaRegistry.schemas.forEach((schema) => {
|
|
58
|
-
const typename = getSchemaDXN(schema)?.typename;
|
|
59
|
-
if (typename) {
|
|
60
|
-
addSchema(typename);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
this._schema?.forEach((schema) => {
|
|
64
|
-
const typename = getSchemaDXN(schema)?.typename;
|
|
65
|
-
if (typename) {
|
|
66
|
-
addSchema(typename);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
this._objects.forEach((object) => {
|
|
70
|
-
const schema = getSchema(object);
|
|
71
|
-
if (schema) {
|
|
72
|
-
const typename = getSchemaDXN(schema)?.typename;
|
|
73
|
-
if (typename) {
|
|
74
|
-
const current = currentNodes.find((node) => node.id === object.id);
|
|
75
|
-
this._graph.nodes.push({
|
|
76
|
-
...current,
|
|
77
|
-
id: object.id,
|
|
78
|
-
type: "object",
|
|
79
|
-
data: {
|
|
80
|
-
typename,
|
|
81
|
-
object
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
const schemaNode = this._graph.nodes.find((node) => node.type === "schema" && node.data.typename === typename);
|
|
85
|
-
if (schemaNode) {
|
|
86
|
-
this._graph.links.push({
|
|
87
|
-
id: `${object.id}-${schemaNode.id}`,
|
|
88
|
-
source: object.id,
|
|
89
|
-
target: schemaNode.id
|
|
90
|
-
});
|
|
91
|
-
} else {
|
|
92
|
-
log.info("schema node not found", {
|
|
93
|
-
typename
|
|
94
|
-
}, {
|
|
95
|
-
F: __dxlog_file,
|
|
96
|
-
L: 148,
|
|
97
|
-
S: this,
|
|
98
|
-
C: (f, a) => f(...a)
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
SchemaAST.getPropertySignatures(schema.ast).forEach((prop) => {
|
|
102
|
-
if (!SchemaValidator.hasTypeAnnotation(schema, prop.name.toString(), ReferenceAnnotationId)) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const value = object[String(prop.name)];
|
|
106
|
-
if (value) {
|
|
107
|
-
const refs = Array.isArray(value) ? value : [
|
|
108
|
-
value
|
|
109
|
-
];
|
|
110
|
-
for (const ref of refs) {
|
|
111
|
-
if (objects.findIndex((obj) => obj.id === ref.id) !== -1) {
|
|
112
|
-
this._graph.links.push({
|
|
113
|
-
id: `${object.id}-${String(prop.name)}-${ref.id}`,
|
|
114
|
-
source: object.id,
|
|
115
|
-
target: ref.id
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
this.triggerUpdate();
|
|
125
|
-
}, {
|
|
126
|
-
fire: true
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
this.setSelected(objectId);
|
|
130
|
-
return this;
|
|
131
|
-
}
|
|
132
|
-
close() {
|
|
133
|
-
this._schemaSubscription?.();
|
|
134
|
-
this._schemaSubscription = void 0;
|
|
135
|
-
this._objectsSubscription?.();
|
|
136
|
-
this._objectsSubscription = void 0;
|
|
137
|
-
return this;
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
// packages/plugins/plugin-explorer/src/components/Graph/Graph.tsx
|
|
142
|
-
import { forceLink, forceManyBody } from "d3";
|
|
143
|
-
import ForceGraph from "force-graph";
|
|
144
|
-
import React, { useEffect, useRef } from "react";
|
|
145
|
-
import { useResizeDetector } from "react-resize-detector";
|
|
146
|
-
import { filterObjectsSync } from "@dxos/plugin-search";
|
|
147
|
-
import { useAsyncState } from "@dxos/react-ui";
|
|
148
|
-
var Graph = ({ space, match }) => {
|
|
149
|
-
const { ref, width, height } = useResizeDetector({
|
|
150
|
-
refreshRate: 200
|
|
151
|
-
});
|
|
152
|
-
const rootRef = useRef(null);
|
|
153
|
-
const forceGraph = useRef();
|
|
154
|
-
const [model] = useAsyncState(async () => space ? new SpaceGraphModel({
|
|
155
|
-
schema: true
|
|
156
|
-
}).open(space) : void 0, [
|
|
157
|
-
space
|
|
158
|
-
]);
|
|
159
|
-
const filteredRef = useRef();
|
|
160
|
-
filteredRef.current = filterObjectsSync(model?.objects ?? [], match);
|
|
161
|
-
useEffect(() => {
|
|
162
|
-
if (rootRef.current) {
|
|
163
|
-
forceGraph.current = new ForceGraph(rootRef.current).nodeRelSize(6).nodeLabel((node) => {
|
|
164
|
-
if (node.type === "schema") {
|
|
165
|
-
return node.data.typename;
|
|
166
|
-
}
|
|
167
|
-
return node.id;
|
|
168
|
-
}).nodeAutoColorBy((node) => node.type === "schema" ? "schema" : node.data.typename).linkColor(() => "rgba(255,255,255,0.25)");
|
|
169
|
-
}
|
|
170
|
-
return () => {
|
|
171
|
-
forceGraph.current?.pauseAnimation().graphData({
|
|
172
|
-
nodes: [],
|
|
173
|
-
links: []
|
|
174
|
-
});
|
|
175
|
-
forceGraph.current = void 0;
|
|
176
|
-
};
|
|
177
|
-
}, []);
|
|
178
|
-
useEffect(() => {
|
|
179
|
-
if (forceGraph.current && width && height && model) {
|
|
180
|
-
forceGraph.current.pauseAnimation().width(width).height(height).onEngineStop(() => {
|
|
181
|
-
handleZoomToFit();
|
|
182
|
-
}).d3Force("link", forceLink().distance(160).strength(0.5)).d3Force("charge", forceManyBody().strength(-30)).graphData(model.graph).warmupTicks(100).cooldownTime(1e3).resumeAnimation();
|
|
183
|
-
}
|
|
184
|
-
}, [
|
|
185
|
-
model,
|
|
186
|
-
width,
|
|
187
|
-
height
|
|
188
|
-
]);
|
|
189
|
-
const handleZoomToFit = () => {
|
|
190
|
-
forceGraph.current?.zoomToFit(400, 40);
|
|
191
|
-
};
|
|
192
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
193
|
-
ref,
|
|
194
|
-
className: "relative grow",
|
|
195
|
-
onClick: handleZoomToFit
|
|
196
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
197
|
-
ref: rootRef,
|
|
198
|
-
className: "absolute inset-0"
|
|
199
|
-
}));
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
export {
|
|
203
|
-
SpaceGraphModel,
|
|
204
|
-
Graph
|
|
205
|
-
};
|
|
206
|
-
//# sourceMappingURL=chunk-QRPUL5AH.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/Graph/graph-model.ts", "../../../src/components/Graph/Graph.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { SchemaAST } from 'effect';\n\nimport { type CleanupFn } from '@dxos/async';\nimport {\n getSchema,\n getSchemaDXN,\n type EchoSchema,\n ReferenceAnnotationId,\n SchemaValidator,\n StoredSchema,\n} from '@dxos/echo-schema';\nimport { type GraphData, GraphModel } from '@dxos/gem-spore';\nimport { log } from '@dxos/log';\nimport { CollectionType } from '@dxos/plugin-space/types';\nimport { Filter, type AnyLiveObject, type Space } from '@dxos/react-client/echo';\n\nexport type SpaceGraphModelOptions = {\n schema?: boolean;\n};\n\n// TODO(burdon): Convert to common/graph.\n\ntype SchemaGraphNode = {\n id: string;\n type: 'schema';\n data: { typename: string };\n};\n\ntype ObjectGraphNode = {\n id: string;\n type: 'object';\n data: { typename: string; object: AnyLiveObject<any> };\n};\n\nexport type EchoGraphNode = SchemaGraphNode | ObjectGraphNode;\n\n/**\n * Converts ECHO objects to a graph.\n */\nexport class SpaceGraphModel extends GraphModel<EchoGraphNode> {\n private readonly _graph: GraphData<EchoGraphNode> = {\n nodes: [],\n links: [],\n };\n\n private _schema?: EchoSchema[];\n private _schemaSubscription?: CleanupFn;\n private _objects?: AnyLiveObject<any>[];\n private _objectsSubscription?: CleanupFn;\n\n constructor(private readonly _options: SpaceGraphModelOptions = {}) {\n super();\n }\n\n override get graph(): GraphData<EchoGraphNode> {\n return this._graph;\n }\n\n get objects(): AnyLiveObject<any>[] {\n return this._objects ?? [];\n }\n\n // TODO(burdon): Alternative diagram types:\n // - https://observablehq.com/@d3/radial-tree/2\n // - https://observablehq.com/@d3/disjoint-force-directed-graph/2\n // - https://observablehq.com/@mbostock/tadpoles\n // - https://observablehq.com/@d3/psr-b1919-21\n // - https://vasturiano.github.io/react-force-graph/example/basic (3D)\n\n async open(space: Space, objectId?: string) {\n // TODO(burdon): Factor out graph builder to lib (use common/graph abstraction).\n if (!this._schemaSubscription) {\n // TODO(burdon): Normalize unsubscribe callbacks and merge handlers.\n // TODO(burdon): Trigger initial subscription update.\n // TODO(burdon): Normalize subscription cb for objects, schema, etc.\n\n const schemaaQuery = space.db.schemaRegistry.query({});\n const schemas = await schemaaQuery.run();\n const onSchemaUpdate = ({ results }: { results: EchoSchema[] }) => (this._schema = results);\n this._schemaSubscription = schemaaQuery.subscribe(onSchemaUpdate);\n onSchemaUpdate({ results: schemas });\n\n this._objectsSubscription = space.db\n // TODO(burdon): ERROR: Cannot mix type and or filters.\n .query(Filter.not(Filter.or(Filter.type(StoredSchema), Filter.type(CollectionType))))\n .subscribe(\n ({ objects }) => {\n this._objects = objects;\n\n // Merge with current nodes.\n const currentNodes = this._graph.nodes;\n\n this._graph.nodes = [];\n this._graph.links = [];\n\n const addSchema = (typename: string) => {\n const current = currentNodes.find((node) => node.id === typename);\n if (typename) {\n this._graph.nodes.push({\n ...current,\n id: typename,\n type: 'schema',\n data: { typename },\n });\n }\n };\n\n // Runtime schema.\n space.db.graph.schemaRegistry.schemas.forEach((schema) => {\n const typename = getSchemaDXN(schema)?.typename;\n if (typename) {\n addSchema(typename);\n }\n });\n\n // Database Schema.\n this._schema?.forEach((schema) => {\n const typename = getSchemaDXN(schema)?.typename;\n if (typename) {\n addSchema(typename);\n }\n });\n\n // Database Objects.\n this._objects.forEach((object) => {\n const schema = getSchema(object);\n if (schema) {\n const typename = getSchemaDXN(schema)?.typename;\n if (typename) {\n const current = currentNodes.find((node) => node.id === object.id);\n this._graph.nodes.push({ ...current, id: object.id, type: 'object', data: { typename, object } });\n\n // Link to schema.\n const schemaNode = this._graph.nodes.find(\n (node) => node.type === 'schema' && node.data.typename === typename,\n );\n if (schemaNode) {\n this._graph.links.push({\n id: `${object.id}-${schemaNode.id}`,\n source: object.id,\n target: schemaNode.id,\n });\n } else {\n log.info('schema node not found', { typename });\n }\n\n // Link ot refs.\n // TODO(burdon): This isn't working.\n SchemaAST.getPropertySignatures(schema.ast).forEach((prop) => {\n if (!SchemaValidator.hasTypeAnnotation(schema, prop.name.toString(), ReferenceAnnotationId)) {\n return;\n }\n\n const value = object[String(prop.name)];\n if (value) {\n const refs = Array.isArray(value) ? value : [value];\n for (const ref of refs) {\n if (objects.findIndex((obj) => obj.id === ref.id) !== -1) {\n this._graph.links.push({\n id: `${object.id}-${String(prop.name)}-${ref.id}`,\n source: object.id,\n target: ref.id,\n });\n }\n }\n }\n });\n }\n }\n });\n\n this.triggerUpdate();\n },\n { fire: true },\n );\n }\n\n this.setSelected(objectId);\n return this;\n }\n\n close() {\n this._schemaSubscription?.();\n this._schemaSubscription = undefined;\n this._objectsSubscription?.();\n this._objectsSubscription = undefined;\n\n return this;\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { forceLink, forceManyBody } from 'd3';\nimport ForceGraph from 'force-graph';\nimport React, { type FC, useEffect, useRef } from 'react';\nimport { useResizeDetector } from 'react-resize-detector';\n\nimport { type Space } from '@dxos/client/echo';\nimport { filterObjectsSync, type SearchResult } from '@dxos/plugin-search';\nimport { useAsyncState } from '@dxos/react-ui';\n\nimport { SpaceGraphModel } from './graph-model';\n\nexport type GraphProps = {\n space: Space;\n match?: RegExp;\n};\n\nexport const Graph: FC<GraphProps> = ({ space, match }) => {\n const { ref, width, height } = useResizeDetector({ refreshRate: 200 });\n const rootRef = useRef<HTMLDivElement>(null);\n const forceGraph = useRef<ForceGraph>();\n\n const [model] = useAsyncState(\n async () => (space ? new SpaceGraphModel({ schema: true }).open(space) : undefined),\n [space],\n );\n\n const filteredRef = useRef<SearchResult[]>();\n filteredRef.current = filterObjectsSync(model?.objects ?? [], match);\n\n useEffect(() => {\n if (rootRef.current) {\n // https://github.com/vasturiano/force-graph\n // https://github.com/vasturiano/3d-force-graph\n forceGraph.current = new ForceGraph(rootRef.current)\n .nodeRelSize(6)\n .nodeLabel((node: any) => {\n if (node.type === 'schema') {\n return node.data.typename;\n }\n\n return node.id;\n })\n .nodeAutoColorBy((node: any) => (node.type === 'schema' ? 'schema' : node.data.typename))\n .linkColor(() => 'rgba(255,255,255,0.25)');\n }\n\n return () => {\n forceGraph.current?.pauseAnimation().graphData({ nodes: [], links: [] });\n forceGraph.current = undefined;\n };\n }, []);\n\n useEffect(() => {\n if (forceGraph.current && width && height && model) {\n forceGraph.current\n .pauseAnimation()\n .width(width)\n .height(height)\n .onEngineStop(() => {\n handleZoomToFit();\n })\n\n // https://github.com/vasturiano/force-graph?tab=readme-ov-file#force-engine-d3-force-configuration\n // .d3Force('center', forceCenter().strength(0.9))\n .d3Force('link', forceLink().distance(160).strength(0.5))\n .d3Force('charge', forceManyBody().strength(-30))\n // .d3AlphaDecay(0.0228)\n // .d3VelocityDecay(0.4)\n\n .graphData(model.graph)\n .warmupTicks(100)\n .cooldownTime(1000)\n .resumeAnimation();\n }\n }, [model, width, height]);\n\n const handleZoomToFit = () => {\n forceGraph.current?.zoomToFit(400, 40);\n };\n\n return (\n <div ref={ref} className='relative grow' onClick={handleZoomToFit}>\n <div ref={rootRef} className='absolute inset-0' />\n </div>\n );\n};\n"],
|
|
5
|
-
"mappings": ";AAIA,SAASA,iBAAiB;AAG1B,SACEC,WACAC,cAEAC,uBACAC,iBACAC,oBACK;AACP,SAAyBC,kBAAkB;AAC3C,SAASC,WAAW;AACpB,SAASC,sBAAsB;AAC/B,SAASC,cAA8C;;AAyBhD,IAAMC,kBAAN,cAA8BJ,WAAAA;EAWnCK,YAA6BC,WAAmC,CAAC,GAAG;AAClE,UAAK;SADsBA,WAAAA;SAVZC,SAAmC;MAClDC,OAAO,CAAA;MACPC,OAAO,CAAA;IACT;EASA;EAEA,IAAaC,QAAkC;AAC7C,WAAO,KAAKH;EACd;EAEA,IAAII,UAAgC;AAClC,WAAO,KAAKC,YAAY,CAAA;EAC1B;;;;;;;EASA,MAAMC,KAAKC,OAAcC,UAAmB;AAE1C,QAAI,CAAC,KAAKC,qBAAqB;AAK7B,YAAMC,eAAeH,MAAMI,GAAGC,eAAeC,MAAM,CAAC,CAAA;AACpD,YAAMC,UAAU,MAAMJ,aAAaK,IAAG;AACtC,YAAMC,iBAAiB,CAAC,EAAEC,QAAO,MAAmC,KAAKC,UAAUD;AACnF,WAAKR,sBAAsBC,aAAaS,UAAUH,cAAAA;AAClDA,qBAAe;QAAEC,SAASH;MAAQ,CAAA;AAElC,WAAKM,uBAAuBb,MAAMI,GAE/BE,MAAMjB,OAAOyB,IAAIzB,OAAO0B,GAAG1B,OAAO2B,KAAK/B,YAAAA,GAAeI,OAAO2B,KAAK5B,cAAAA,CAAAA,CAAAA,CAAAA,EAClEwB,UACC,CAAC,EAAEf,QAAO,MAAE;AACV,aAAKC,WAAWD;AAGhB,cAAMoB,eAAe,KAAKxB,OAAOC;AAEjC,aAAKD,OAAOC,QAAQ,CAAA;AACpB,aAAKD,OAAOE,QAAQ,CAAA;AAEpB,cAAMuB,YAAY,CAACC,aAAAA;AACjB,gB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;GAAO;AAEzB,QAAMgC,kBAAkB,MAAA;AACtB3B,eAAWQ,SAAS6B,UAAU,KAAK,EAAA;EACrC;AAEA,SACE,sBAAA,cAACC,OAAAA;IAAI7C;IAAU8C,WAAU;IAAgBC,SAASb;KAChD,sBAAA,cAACW,OAAAA;IAAI7C,KAAKK;IAASyC,WAAU;;AAGnC;",
|
|
6
|
-
"names": ["SchemaAST", "getSchema", "getSchemaDXN", "ReferenceAnnotationId", "SchemaValidator", "StoredSchema", "GraphModel", "log", "CollectionType", "Filter", "SpaceGraphModel", "constructor", "_options", "_graph", "nodes", "links", "graph", "objects", "_objects", "open", "space", "objectId", "_schemaSubscription", "schemaaQuery", "db", "schemaRegistry", "query", "schemas", "run", "onSchemaUpdate", "results", "_schema", "subscribe", "_objectsSubscription", "not", "or", "type", "currentNodes", "addSchema", "typename", "current", "find", "node", "id", "push", "data", "forEach", "schema", "object", "schemaNode", "source", "target", "info", "getPropertySignatures", "ast", "prop", "hasTypeAnnotation", "name", "toString", "value", "String", "refs", "Array", "isArray", "ref", "findIndex", "obj", "triggerUpdate", "fire", "setSelected", "close", "undefined", "forceLink", "forceManyBody", "ForceGraph", "React", "useEffect", "useRef", "useResizeDetector", "filterObjectsSync", "useAsyncState", "Graph", "space", "match", "ref", "width", "height", "useResizeDetector", "refreshRate", "rootRef", "useRef", "forceGraph", "model", "useAsyncState", "SpaceGraphModel", "schema", "open", "undefined", "filteredRef", "current", "filterObjectsSync", "objects", "useEffect", "ForceGraph", "nodeRelSize", "nodeLabel", "node", "type", "data", "typename", "id", "nodeAutoColorBy", "linkColor", "pauseAnimation", "graphData", "nodes", "links", "onEngineStop", "handleZoomToFit", "d3Force", "forceLink", "distance", "strength", "forceManyBody", "graph", "warmupTicks", "cooldownTime", "resumeAnimation", "zoomToFit", "div", "className", "onClick"]
|
|
7
|
-
}
|