@dxos/plugin-explorer 0.8.0 → 0.8.1-main.013e445
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-GJTCBEM4.mjs → ExplorerContainer-3FC557MG.mjs} +2 -2
- package/dist/lib/browser/{chunk-S3QNIEBS.mjs → chunk-4OFGICWF.mjs} +241 -2
- package/dist/lib/{node-esm/chunk-BRJI3QC2.mjs.map → browser/chunk-4OFGICWF.mjs.map} +4 -4
- package/dist/lib/browser/{chunk-PMHCTMKT.mjs → chunk-B3EX52V3.mjs} +2 -2
- package/dist/lib/browser/{chunk-QOKAZK4V.mjs → chunk-KYB47PZA.mjs} +1 -1
- package/dist/lib/browser/chunk-KYB47PZA.mjs.map +7 -0
- package/dist/lib/browser/chunk-X5CI43J6.mjs +205 -0
- package/dist/lib/browser/chunk-X5CI43J6.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +13 -20
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-resolver-UJNDAIDZ.mjs → intent-resolver-5UXBTZAM.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-3X2V3VPN.mjs → react-surface-7HHUAS3J.mjs} +7 -6
- package/dist/lib/browser/react-surface-7HHUAS3J.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +2 -2
- package/dist/lib/node/{ExplorerContainer-RJT54IOS.cjs → ExplorerContainer-2DQFUEG7.cjs} +6 -6
- package/dist/lib/node/{chunk-5MTMJYC4.cjs → chunk-6VLMSRD5.cjs} +4 -4
- package/dist/lib/node/chunk-6VLMSRD5.cjs.map +7 -0
- package/dist/lib/node/chunk-AABHIUUW.cjs +236 -0
- package/dist/lib/node/chunk-AABHIUUW.cjs.map +7 -0
- package/dist/lib/node/{chunk-YUY7P7R2.cjs → chunk-C4DXEIBU.cjs} +6 -6
- package/dist/lib/node/{chunk-VSACDC6F.cjs → chunk-ZJL53DLS.cjs} +234 -8
- package/dist/lib/node/chunk-ZJL53DLS.cjs.map +7 -0
- package/dist/lib/node/index.cjs +31 -38
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/{intent-resolver-XQV24IAA.cjs → intent-resolver-WDMZJTJ5.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-36YIY7NA.cjs → react-surface-UKU6NFBS.cjs} +12 -11
- package/dist/lib/node/react-surface-UKU6NFBS.cjs.map +7 -0
- 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-TM3VIXVK.mjs → ExplorerContainer-RBGUFI5X.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-BRJI3QC2.mjs → chunk-PIOV7IOO.mjs} +240 -2
- package/dist/lib/{browser/chunk-S3QNIEBS.mjs.map → node-esm/chunk-PIOV7IOO.mjs.map} +4 -4
- package/dist/lib/node-esm/{chunk-UHJZUVRI.mjs → chunk-RKQR2GVZ.mjs} +1 -1
- package/dist/lib/node-esm/chunk-RKQR2GVZ.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-TI3P4L2P.mjs +207 -0
- package/dist/lib/node-esm/chunk-TI3P4L2P.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-57K7ORAW.mjs → chunk-WJ6AML7W.mjs} +2 -2
- package/dist/lib/node-esm/index.mjs +13 -20
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/{intent-resolver-RZQ3EEOE.mjs → intent-resolver-KBRYGW6I.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-YDY7IBMY.mjs → react-surface-UZYRBRXP.mjs} +7 -6
- package/dist/lib/node-esm/react-surface-UZYRBRXP.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +2 -2
- package/dist/types/src/ExplorerPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/Chart/Chart.d.ts +2 -1
- package/dist/types/src/components/Chart/Chart.d.ts.map +1 -1
- package/dist/types/src/components/Chart/Chart.stories.d.ts +2 -1
- package/dist/types/src/components/Chart/Chart.stories.d.ts.map +1 -1
- package/dist/types/src/components/ExplorerContainer.d.ts +2 -1
- package/dist/types/src/components/ExplorerContainer.d.ts.map +1 -1
- package/dist/types/src/components/Globe/Globe.d.ts +2 -1
- package/dist/types/src/components/Globe/Globe.d.ts.map +1 -1
- package/dist/types/src/components/Globe/Globe.stories.d.ts +3 -2
- package/dist/types/src/components/Globe/Globe.stories.d.ts.map +1 -1
- package/dist/types/src/components/Graph/Graph.d.ts +0 -3
- package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
- package/dist/types/src/components/Graph/Graph.stories.d.ts +1 -1
- package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/components/Graph/graph-model.d.ts.map +1 -1
- package/dist/types/src/components/Tree/Tree.d.ts +2 -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/types.d.ts +1 -1
- package/dist/types/src/components/Tree/types.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -9
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -6
- package/dist/types/src/translations.d.ts.map +1 -1
- package/package.json +26 -26
- package/src/ExplorerPlugin.tsx +1 -2
- package/src/capabilities/react-surface.tsx +2 -1
- package/src/components/Graph/Graph.stories.tsx +2 -2
- package/src/components/Graph/Graph.tsx +16 -142
- package/src/components/Graph/graph-model.ts +2 -0
- package/src/components/Tree/Tree.stories.tsx +3 -36
- package/src/components/Tree/types.ts +2 -1
- package/src/meta.ts +2 -2
- package/src/translations.ts +1 -2
- package/dist/lib/browser/chunk-QOKAZK4V.mjs.map +0 -7
- package/dist/lib/browser/chunk-YQL7YE6N.mjs +0 -546
- package/dist/lib/browser/chunk-YQL7YE6N.mjs.map +0 -7
- package/dist/lib/browser/react-surface-3X2V3VPN.mjs.map +0 -7
- package/dist/lib/node/chunk-5MTMJYC4.cjs.map +0 -7
- package/dist/lib/node/chunk-VSACDC6F.cjs.map +0 -7
- package/dist/lib/node/chunk-YH4QYCZH.cjs +0 -567
- package/dist/lib/node/chunk-YH4QYCZH.cjs.map +0 -7
- package/dist/lib/node/react-surface-36YIY7NA.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-3KRWHGBM.mjs +0 -548
- package/dist/lib/node-esm/chunk-3KRWHGBM.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-UHJZUVRI.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-YDY7IBMY.mjs.map +0 -7
- /package/dist/lib/browser/{ExplorerContainer-GJTCBEM4.mjs.map → ExplorerContainer-3FC557MG.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-PMHCTMKT.mjs.map → chunk-B3EX52V3.mjs.map} +0 -0
- /package/dist/lib/browser/{intent-resolver-UJNDAIDZ.mjs.map → intent-resolver-5UXBTZAM.mjs.map} +0 -0
- /package/dist/lib/node/{ExplorerContainer-RJT54IOS.cjs.map → ExplorerContainer-2DQFUEG7.cjs.map} +0 -0
- /package/dist/lib/node/{chunk-YUY7P7R2.cjs.map → chunk-C4DXEIBU.cjs.map} +0 -0
- /package/dist/lib/node/{intent-resolver-XQV24IAA.cjs.map → intent-resolver-WDMZJTJ5.cjs.map} +0 -0
- /package/dist/lib/node-esm/{ExplorerContainer-TM3VIXVK.mjs.map → ExplorerContainer-RBGUFI5X.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-57K7ORAW.mjs.map → chunk-WJ6AML7W.mjs.map} +0 -0
- /package/dist/lib/node-esm/{intent-resolver-RZQ3EEOE.mjs.map → intent-resolver-KBRYGW6I.mjs.map} +0 -0
|
@@ -1,548 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
-
|
|
3
|
-
// packages/plugins/experimental/plugin-explorer/src/components/Graph/graph-model.ts
|
|
4
|
-
import { getSchema, getSchemaDXN, AST, ReferenceAnnotationId, SchemaValidator, StoredSchema } from "@dxos/echo-schema";
|
|
5
|
-
import { GraphModel } from "@dxos/gem-spore";
|
|
6
|
-
import { log } from "@dxos/log";
|
|
7
|
-
import { CollectionType } from "@dxos/plugin-space/types";
|
|
8
|
-
import { Filter } from "@dxos/react-client/echo";
|
|
9
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-explorer/src/components/Graph/graph-model.ts";
|
|
10
|
-
var SpaceGraphModel = class extends GraphModel {
|
|
11
|
-
constructor(_options = {}) {
|
|
12
|
-
super();
|
|
13
|
-
this._options = _options;
|
|
14
|
-
this._graph = {
|
|
15
|
-
nodes: [],
|
|
16
|
-
links: []
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
get graph() {
|
|
20
|
-
return this._graph;
|
|
21
|
-
}
|
|
22
|
-
get objects() {
|
|
23
|
-
return this._objects ?? [];
|
|
24
|
-
}
|
|
25
|
-
// TODO(burdon): Alternative diagram types:
|
|
26
|
-
// - https://observablehq.com/@d3/radial-tree/2
|
|
27
|
-
// - https://observablehq.com/@d3/disjoint-force-directed-graph/2
|
|
28
|
-
// - https://observablehq.com/@mbostock/tadpoles
|
|
29
|
-
// - https://observablehq.com/@d3/psr-b1919-21
|
|
30
|
-
// - https://vasturiano.github.io/react-force-graph/example/basic (3D)
|
|
31
|
-
async open(space, objectId) {
|
|
32
|
-
if (!this._schemaSubscription) {
|
|
33
|
-
const schemaaQuery = space.db.schemaRegistry.query({});
|
|
34
|
-
const schemas = await schemaaQuery.run();
|
|
35
|
-
const onSchemaUpdate = ({ results }) => this._schema = results;
|
|
36
|
-
this._schemaSubscription = schemaaQuery.subscribe(onSchemaUpdate);
|
|
37
|
-
onSchemaUpdate({
|
|
38
|
-
results: schemas
|
|
39
|
-
});
|
|
40
|
-
this._objectsSubscription = space.db.query(Filter.not(Filter.or(Filter.schema(StoredSchema), Filter.schema(CollectionType)))).subscribe(({ objects }) => {
|
|
41
|
-
this._objects = objects;
|
|
42
|
-
const currentNodes = this._graph.nodes;
|
|
43
|
-
this._graph.nodes = [];
|
|
44
|
-
this._graph.links = [];
|
|
45
|
-
const addSchema = (typename) => {
|
|
46
|
-
const current = currentNodes.find((node) => node.id === typename);
|
|
47
|
-
if (typename) {
|
|
48
|
-
this._graph.nodes.push({
|
|
49
|
-
...current,
|
|
50
|
-
id: typename,
|
|
51
|
-
type: "schema",
|
|
52
|
-
data: {
|
|
53
|
-
typename
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
space.db.graph.schemaRegistry.schemas.forEach((schema) => {
|
|
59
|
-
const typename = getSchemaDXN(schema)?.toTypename();
|
|
60
|
-
if (typename) {
|
|
61
|
-
addSchema(typename);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
this._schema?.forEach((schema) => {
|
|
65
|
-
const typename = getSchemaDXN(schema)?.toTypename();
|
|
66
|
-
if (typename) {
|
|
67
|
-
addSchema(typename);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
this._objects.forEach((object) => {
|
|
71
|
-
const schema = getSchema(object);
|
|
72
|
-
if (schema) {
|
|
73
|
-
const typename = getSchemaDXN(schema)?.toTypename();
|
|
74
|
-
if (typename) {
|
|
75
|
-
const current = currentNodes.find((node) => node.id === object.id);
|
|
76
|
-
this._graph.nodes.push({
|
|
77
|
-
...current,
|
|
78
|
-
id: object.id,
|
|
79
|
-
type: "object",
|
|
80
|
-
data: {
|
|
81
|
-
typename,
|
|
82
|
-
object
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
const schemaNode = this._graph.nodes.find((node) => node.type === "schema" && node.data.typename === typename);
|
|
86
|
-
if (schemaNode) {
|
|
87
|
-
this._graph.links.push({
|
|
88
|
-
id: `${object.id}-${schemaNode.id}`,
|
|
89
|
-
source: object.id,
|
|
90
|
-
target: schemaNode.id
|
|
91
|
-
});
|
|
92
|
-
} else {
|
|
93
|
-
log.info("schema node not found", {
|
|
94
|
-
typename
|
|
95
|
-
}, {
|
|
96
|
-
F: __dxlog_file,
|
|
97
|
-
L: 145,
|
|
98
|
-
S: this,
|
|
99
|
-
C: (f, a) => f(...a)
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
AST.getPropertySignatures(schema.ast).forEach((prop) => {
|
|
103
|
-
if (!SchemaValidator.hasTypeAnnotation(schema, prop.name.toString(), ReferenceAnnotationId)) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const value = object[String(prop.name)];
|
|
107
|
-
if (value) {
|
|
108
|
-
const refs = Array.isArray(value) ? value : [
|
|
109
|
-
value
|
|
110
|
-
];
|
|
111
|
-
for (const ref of refs) {
|
|
112
|
-
if (objects.findIndex((obj) => obj.id === ref.id) !== -1) {
|
|
113
|
-
this._graph.links.push({
|
|
114
|
-
id: `${object.id}-${String(prop.name)}-${ref.id}`,
|
|
115
|
-
source: object.id,
|
|
116
|
-
target: ref.id
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
this.triggerUpdate();
|
|
126
|
-
}, {
|
|
127
|
-
fire: true
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
this.setSelected(objectId);
|
|
131
|
-
return this;
|
|
132
|
-
}
|
|
133
|
-
close() {
|
|
134
|
-
this._schemaSubscription?.();
|
|
135
|
-
this._schemaSubscription = void 0;
|
|
136
|
-
this._objectsSubscription?.();
|
|
137
|
-
this._objectsSubscription = void 0;
|
|
138
|
-
return this;
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
// packages/plugins/experimental/plugin-explorer/src/components/Tree/Tree.tsx
|
|
143
|
-
import React2, { useEffect as useEffect2, useState as useState2 } from "react";
|
|
144
|
-
import { useResizeDetector as useResizeDetector2 } from "react-resize-detector";
|
|
145
|
-
import { createSvgContext as createSvgContext2, SVG as SVG2, SVGRoot as SVGRoot2 } from "@dxos/gem-core";
|
|
146
|
-
import { useAsyncState as useAsyncState2 } from "@dxos/react-ui";
|
|
147
|
-
|
|
148
|
-
// packages/plugins/experimental/plugin-explorer/src/components/Tree/layout/HierarchicalEdgeBundling.ts
|
|
149
|
-
import * as d3 from "d3";
|
|
150
|
-
var HierarchicalEdgeBundling = (s, data, options) => {
|
|
151
|
-
const svg = d3.select(s);
|
|
152
|
-
svg.selectAll("*").remove();
|
|
153
|
-
const { radius = 600, padding = 100, slots: slots2 } = options;
|
|
154
|
-
const root = d3.hierarchy(flatten(data));
|
|
155
|
-
const tree3 = d3.cluster().size([
|
|
156
|
-
2 * Math.PI,
|
|
157
|
-
radius - padding
|
|
158
|
-
]);
|
|
159
|
-
const layout = tree3(addLinks(root));
|
|
160
|
-
const node = svg.append("g").selectAll().data(layout.leaves()).join("g").attr("transform", (d) => `rotate(${d.x * (180 / Math.PI) - 90}) translate(${d.y},0)`).append("text").attr("class", slots2?.text ?? "").attr("dy", "0.31em").attr("x", (d) => d.x < Math.PI ? 6 : -6).attr("text-anchor", (d) => d.x < Math.PI ? "start" : "end").attr("transform", (d) => d.x >= Math.PI ? "rotate(180)" : null).call((text) => text.text((d) => d.data.id.slice(0, 8)));
|
|
161
|
-
const line = d3.lineRadial().curve(d3.curveBundle.beta(0.85)).radius((d) => d.y).angle((d) => d.x);
|
|
162
|
-
const links = svg.append("g").selectAll().data(layout.leaves().flatMap((leaf) => leaf.outgoing)).join("path").style("mix-blend-mode", "multiply").attr("class", slots2?.path ?? "").attr("d", ([i, o]) => {
|
|
163
|
-
return line(i.path(o));
|
|
164
|
-
}).each(function(d) {
|
|
165
|
-
d.path = this;
|
|
166
|
-
});
|
|
167
|
-
};
|
|
168
|
-
var addLinks = (root) => {
|
|
169
|
-
const nodes = new Map(root.descendants().map((d) => [
|
|
170
|
-
d.data.id,
|
|
171
|
-
d
|
|
172
|
-
]));
|
|
173
|
-
const parents = root.descendants().reduce((map, d) => {
|
|
174
|
-
if (d.children?.length) {
|
|
175
|
-
map.set(d.data.id, d);
|
|
176
|
-
}
|
|
177
|
-
return map;
|
|
178
|
-
}, /* @__PURE__ */ new Map());
|
|
179
|
-
for (const d of root.leaves()) {
|
|
180
|
-
const parent = parents.get(d.data.id);
|
|
181
|
-
if (parent) {
|
|
182
|
-
d.outgoing = parent.data.children?.slice(1).map((child) => {
|
|
183
|
-
return [
|
|
184
|
-
d,
|
|
185
|
-
nodes.get(child.id)
|
|
186
|
-
];
|
|
187
|
-
}) ?? [];
|
|
188
|
-
} else {
|
|
189
|
-
d.outgoing = [];
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return root;
|
|
193
|
-
};
|
|
194
|
-
var flatten = (node) => {
|
|
195
|
-
const clone = {
|
|
196
|
-
id: node.id
|
|
197
|
-
};
|
|
198
|
-
if (node.children?.length) {
|
|
199
|
-
const children = node.children.map((child) => flatten(child));
|
|
200
|
-
clone.children = [
|
|
201
|
-
{
|
|
202
|
-
id: node.id
|
|
203
|
-
},
|
|
204
|
-
...children
|
|
205
|
-
];
|
|
206
|
-
}
|
|
207
|
-
return clone;
|
|
208
|
-
};
|
|
209
|
-
var HierarchicalEdgeBundling_default = HierarchicalEdgeBundling;
|
|
210
|
-
|
|
211
|
-
// packages/plugins/experimental/plugin-explorer/src/components/Tree/layout/RadialTree.ts
|
|
212
|
-
import * as d32 from "d3";
|
|
213
|
-
var RadialTree = (s, data, options) => {
|
|
214
|
-
const svg = d32.select(s);
|
|
215
|
-
svg.selectAll("*").remove();
|
|
216
|
-
const { label, radius = 400, r = 4, slots: slots2 } = options;
|
|
217
|
-
const arc = 2 * Math.PI;
|
|
218
|
-
const root = d32.hierarchy(data);
|
|
219
|
-
const descendants = root.descendants();
|
|
220
|
-
const getLabel = label === null ? null : descendants.map((d) => label(d.data));
|
|
221
|
-
const layout = d32.tree().size([
|
|
222
|
-
arc,
|
|
223
|
-
radius
|
|
224
|
-
]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / a.depth);
|
|
225
|
-
layout(root);
|
|
226
|
-
svg.append("g").selectAll("path").data(root.links()).join("path").attr("class", slots2?.path ?? "").attr("d", d32.linkRadial().angle((d) => d.x + Math.PI / 2).radius((d) => d.y));
|
|
227
|
-
const node = svg.append("g").selectAll("a").data(root.descendants()).join("a").attr("transform", (d) => `rotate(${d.x * 180 / Math.PI}) translate(${d.y},0)`);
|
|
228
|
-
node.append("circle").attr("class", slots2?.node ?? "").attr("r", r);
|
|
229
|
-
if (getLabel) {
|
|
230
|
-
node.append("text").attr("transform", (d) => `rotate(${d.x >= Math.PI ? 180 : 0})`).attr("dy", "0.32em").attr("x", (d) => d.x < Math.PI === !d.children ? 6 : -6).attr("text-anchor", (d) => d.x < Math.PI === !d.children ? "start" : "end").attr("class", slots2?.text ?? "").text((d, i) => getLabel[i]);
|
|
231
|
-
}
|
|
232
|
-
return svg.node();
|
|
233
|
-
};
|
|
234
|
-
var RadialTree_default = RadialTree;
|
|
235
|
-
|
|
236
|
-
// packages/plugins/experimental/plugin-explorer/src/components/Tree/layout/TidyTree.ts
|
|
237
|
-
import * as d33 from "d3";
|
|
238
|
-
var TidyTree = (s, data, options) => {
|
|
239
|
-
const svg = d33.select(s);
|
|
240
|
-
svg.selectAll("*").remove();
|
|
241
|
-
const { label, width, height, r = 4, padding = 4, margin = 60, slots: slots2 } = options;
|
|
242
|
-
const root = d33.hierarchy(data);
|
|
243
|
-
const descendants = root.descendants();
|
|
244
|
-
const getLabel = label == null ? null : descendants.map((d) => label(d.data));
|
|
245
|
-
const dx = 16;
|
|
246
|
-
const dy = width / (root.height + padding);
|
|
247
|
-
const layout = d33.tree().nodeSize([
|
|
248
|
-
dx,
|
|
249
|
-
dy
|
|
250
|
-
]);
|
|
251
|
-
layout(root);
|
|
252
|
-
let x0 = Infinity;
|
|
253
|
-
let x1 = -x0;
|
|
254
|
-
let y0 = Infinity;
|
|
255
|
-
let y1 = -y0;
|
|
256
|
-
root.each((d) => {
|
|
257
|
-
if (d.x > x1) {
|
|
258
|
-
x1 = d.x;
|
|
259
|
-
}
|
|
260
|
-
if (d.x < x0) {
|
|
261
|
-
x0 = d.x;
|
|
262
|
-
}
|
|
263
|
-
if (d.y > y1) {
|
|
264
|
-
y1 = d.y;
|
|
265
|
-
}
|
|
266
|
-
if (d.y < y0) {
|
|
267
|
-
y0 = d.y;
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
const sx = Math.min(2, Math.max(1, (height - margin * 2) / (x1 - x0)));
|
|
271
|
-
const oy = -(width - (y1 - y0)) / 2;
|
|
272
|
-
svg.append("g").selectAll("path").data(root.links()).join("path").attr("class", slots2?.path ?? "").attr("d", d33.link(d33.curveBumpX).x((d) => d.y + oy).y((d) => d.x * sx));
|
|
273
|
-
const node = svg.append("g").selectAll("a").data(root.descendants()).join("a").attr("transform", (d) => `translate(${d.y + oy},${d.x * sx})`);
|
|
274
|
-
node.append("circle").attr("class", slots2?.node ?? "").attr("r", r);
|
|
275
|
-
if (getLabel) {
|
|
276
|
-
node.append("text").attr("dy", "0.32em").attr("x", (d) => d.children ? -6 : 6).attr("text-anchor", (d) => d.children ? "end" : "start").attr("class", slots2?.text ?? "").text((d, i) => getLabel[i]);
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
var TidyTree_default = TidyTree;
|
|
280
|
-
|
|
281
|
-
// packages/plugins/experimental/plugin-explorer/src/components/Tree/types.ts
|
|
282
|
-
var mapGraphToTreeData = (model, maxDepth = 8) => {
|
|
283
|
-
const mapNode = (node, depth = 0) => {
|
|
284
|
-
const treeNode = {
|
|
285
|
-
id: model.idAccessor(node),
|
|
286
|
-
label: model.idAccessor(node).slice(0, 8)
|
|
287
|
-
};
|
|
288
|
-
const links = model.graph.links.filter((link2) => link2.source === treeNode.id);
|
|
289
|
-
if (depth < maxDepth) {
|
|
290
|
-
treeNode.children = links.map((link2) => mapNode(model.graph.nodes.find((node2) => model.idAccessor(node2) === link2.target), depth + 1));
|
|
291
|
-
}
|
|
292
|
-
return treeNode;
|
|
293
|
-
};
|
|
294
|
-
let data;
|
|
295
|
-
if (model.selected) {
|
|
296
|
-
const node = model.graph.nodes.find((node2) => model.idAccessor(node2) === model.selected);
|
|
297
|
-
if (node) {
|
|
298
|
-
data = mapNode(node);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
return data;
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
// packages/plugins/experimental/plugin-explorer/src/components/Graph/Graph.tsx
|
|
305
|
-
import { forceLink, forceManyBody } from "d3";
|
|
306
|
-
import ForceGraph from "force-graph";
|
|
307
|
-
import React, { useEffect, useMemo, useRef, useState } from "react";
|
|
308
|
-
import { useResizeDetector } from "react-resize-detector";
|
|
309
|
-
import { getTypename } from "@dxos/client/echo";
|
|
310
|
-
import { createSvgContext, defaultGridStyles, Grid, SVG, SVGRoot, Zoom } from "@dxos/gem-core";
|
|
311
|
-
import { defaultStyles, Graph as GraphComponent, GraphForceProjector, Markers } from "@dxos/gem-spore";
|
|
312
|
-
import { filterObjectsSync } from "@dxos/plugin-search";
|
|
313
|
-
import { useAsyncState, useThemeContext } from "@dxos/react-ui";
|
|
314
|
-
import { mx } from "@dxos/react-ui-theme";
|
|
315
|
-
import "@dxos/gem-spore/styles";
|
|
316
|
-
var slots = {};
|
|
317
|
-
var colors = [
|
|
318
|
-
"[&>circle]:!fill-black-300 [&>circle]:!stroke-black-600",
|
|
319
|
-
"[&>circle]:!fill-slate-300 [&>circle]:!stroke-slate-600",
|
|
320
|
-
"[&>circle]:!fill-green-300 [&>circle]:!stroke-green-600",
|
|
321
|
-
"[&>circle]:!fill-sky-300 [&>circle]:!stroke-sky-600",
|
|
322
|
-
"[&>circle]:!fill-cyan-300 [&>circle]:!stroke-cyan-600",
|
|
323
|
-
"[&>circle]:!fill-rose-300 [&>circle]:!stroke-rose-600",
|
|
324
|
-
"[&>circle]:!fill-purple-300 [&>circle]:!stroke-purple-600",
|
|
325
|
-
"[&>circle]:!fill-orange-300 [&>circle]:!stroke-orange-600",
|
|
326
|
-
"[&>circle]:!fill-teal-300 [&>circle]:!stroke-teal-600",
|
|
327
|
-
"[&>circle]:!fill-indigo-300 [&>circle]:!stroke-indigo-600"
|
|
328
|
-
];
|
|
329
|
-
var Graph = ({ space, match, grid, svg }) => {
|
|
330
|
-
const { themeMode } = useThemeContext();
|
|
331
|
-
const [selected, setSelected] = useState();
|
|
332
|
-
const [model] = useAsyncState(async () => space ? new SpaceGraphModel({
|
|
333
|
-
schema: true
|
|
334
|
-
}).open(space) : void 0, [
|
|
335
|
-
space
|
|
336
|
-
]);
|
|
337
|
-
const context = createSvgContext();
|
|
338
|
-
const projector = useMemo(() => new GraphForceProjector(context, {
|
|
339
|
-
forces: {
|
|
340
|
-
manyBody: {
|
|
341
|
-
strength: -100
|
|
342
|
-
},
|
|
343
|
-
link: {
|
|
344
|
-
distance: 100
|
|
345
|
-
},
|
|
346
|
-
radial: {
|
|
347
|
-
radius: 150,
|
|
348
|
-
strength: 0.05
|
|
349
|
-
}
|
|
350
|
-
},
|
|
351
|
-
attributes: {
|
|
352
|
-
radius: (node) => node.data?.type === "schema" ? 12 : 8
|
|
353
|
-
}
|
|
354
|
-
}), []);
|
|
355
|
-
const filteredRef = useRef();
|
|
356
|
-
filteredRef.current = filterObjectsSync(model?.objects ?? [], match);
|
|
357
|
-
useEffect(() => {
|
|
358
|
-
void projector.start();
|
|
359
|
-
}, [
|
|
360
|
-
match
|
|
361
|
-
]);
|
|
362
|
-
const [colorMap] = useState(/* @__PURE__ */ new Map());
|
|
363
|
-
const { ref, width, height } = useResizeDetector();
|
|
364
|
-
const rootRef = useRef(null);
|
|
365
|
-
const forceGraph = useRef();
|
|
366
|
-
useEffect(() => {
|
|
367
|
-
if (rootRef.current) {
|
|
368
|
-
forceGraph.current = new ForceGraph(rootRef.current).nodeRelSize(6).nodeLabel((node) => {
|
|
369
|
-
if (node.type === "schema") {
|
|
370
|
-
return node.data.typename;
|
|
371
|
-
}
|
|
372
|
-
return node.id;
|
|
373
|
-
}).nodeAutoColorBy((node) => node.type === "schema" ? "schema" : node.data.typename).linkColor(() => "rgba(255,255,255,0.25)");
|
|
374
|
-
}
|
|
375
|
-
return () => {
|
|
376
|
-
forceGraph.current?.pauseAnimation().graphData({
|
|
377
|
-
nodes: [],
|
|
378
|
-
links: []
|
|
379
|
-
});
|
|
380
|
-
forceGraph.current = void 0;
|
|
381
|
-
};
|
|
382
|
-
}, []);
|
|
383
|
-
useEffect(() => {
|
|
384
|
-
if (forceGraph.current && width && height && model) {
|
|
385
|
-
forceGraph.current.pauseAnimation().width(width).height(height).onEngineStop(() => {
|
|
386
|
-
forceGraph.current?.zoomToFit(400, 40);
|
|
387
|
-
}).d3Force("link", forceLink().distance(160).strength(0.5)).d3Force("charge", forceManyBody().strength(-30)).warmupTicks(100).graphData(model.graph).resumeAnimation();
|
|
388
|
-
}
|
|
389
|
-
}, [
|
|
390
|
-
model,
|
|
391
|
-
width,
|
|
392
|
-
height
|
|
393
|
-
]);
|
|
394
|
-
const handleZoomToFit = () => {
|
|
395
|
-
forceGraph.current?.zoomToFit(400, 40);
|
|
396
|
-
};
|
|
397
|
-
if (!svg) {
|
|
398
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
399
|
-
ref,
|
|
400
|
-
className: "relative grow",
|
|
401
|
-
onClick: handleZoomToFit
|
|
402
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
403
|
-
ref: rootRef,
|
|
404
|
-
className: "absolute inset-0"
|
|
405
|
-
}));
|
|
406
|
-
}
|
|
407
|
-
if (selected) {
|
|
408
|
-
return /* @__PURE__ */ React.createElement(Tree, {
|
|
409
|
-
space,
|
|
410
|
-
selected,
|
|
411
|
-
variant: "tidy",
|
|
412
|
-
onNodeClick: () => setSelected(void 0)
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
|
-
return /* @__PURE__ */ React.createElement(SVGRoot, {
|
|
416
|
-
context
|
|
417
|
-
}, /* @__PURE__ */ React.createElement(SVG, {
|
|
418
|
-
className: mx(defaultStyles, slots?.root?.className)
|
|
419
|
-
}, /* @__PURE__ */ React.createElement(Markers, {
|
|
420
|
-
arrowSize: 6
|
|
421
|
-
}), grid && /* @__PURE__ */ React.createElement(Grid, {
|
|
422
|
-
className: slots?.grid?.className ?? defaultGridStyles(themeMode)
|
|
423
|
-
}), /* @__PURE__ */ React.createElement(Zoom, {
|
|
424
|
-
extent: [
|
|
425
|
-
1 / 2,
|
|
426
|
-
4
|
|
427
|
-
]
|
|
428
|
-
}, /* @__PURE__ */ React.createElement(GraphComponent, {
|
|
429
|
-
model,
|
|
430
|
-
projector,
|
|
431
|
-
drag: true,
|
|
432
|
-
arrows: true,
|
|
433
|
-
onSelect: (node) => setSelected(node?.data?.id),
|
|
434
|
-
labels: {
|
|
435
|
-
text: (node) => {
|
|
436
|
-
if (filteredRef.current?.length && !filteredRef.current.some((object) => object.id === node.data?.id)) {
|
|
437
|
-
return void 0;
|
|
438
|
-
}
|
|
439
|
-
return node.data?.label ?? node.data?.title ?? node.data?.name ?? node.data?.id.slice(0, 8);
|
|
440
|
-
}
|
|
441
|
-
},
|
|
442
|
-
attributes: {
|
|
443
|
-
node: (node) => {
|
|
444
|
-
let className;
|
|
445
|
-
if (node.data) {
|
|
446
|
-
const { object } = node.data;
|
|
447
|
-
if (object) {
|
|
448
|
-
const typename = getTypename(object);
|
|
449
|
-
if (typename) {
|
|
450
|
-
className = colorMap.get(typename);
|
|
451
|
-
if (!className) {
|
|
452
|
-
className = colors[colorMap.size % colors.length];
|
|
453
|
-
colorMap.set(typename, className);
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
const selected2 = filteredRef.current?.some((object) => object.id === node.data?.id);
|
|
459
|
-
const blur = !selected2 && !!filteredRef.current?.length;
|
|
460
|
-
return {
|
|
461
|
-
class: mx(className, blur && "opacity-70")
|
|
462
|
-
};
|
|
463
|
-
},
|
|
464
|
-
link: () => ({
|
|
465
|
-
class: "[&>path]:!stroke-neutral-300 dark:[&>path]:!stroke-neutral-700"
|
|
466
|
-
})
|
|
467
|
-
}
|
|
468
|
-
}))));
|
|
469
|
-
};
|
|
470
|
-
|
|
471
|
-
// packages/plugins/experimental/plugin-explorer/src/components/Tree/Tree.tsx
|
|
472
|
-
var defaultTreeLayoutSlots = {
|
|
473
|
-
node: "fill-blue-600",
|
|
474
|
-
path: "fill-none stroke-blue-400 stroke-[0.5px]",
|
|
475
|
-
text: "stroke-[0.5px] stroke-neutral-700 text-xs"
|
|
476
|
-
};
|
|
477
|
-
var renderers = /* @__PURE__ */ new Map([
|
|
478
|
-
[
|
|
479
|
-
"tidy",
|
|
480
|
-
TidyTree_default
|
|
481
|
-
],
|
|
482
|
-
[
|
|
483
|
-
"radial",
|
|
484
|
-
RadialTree_default
|
|
485
|
-
],
|
|
486
|
-
[
|
|
487
|
-
"edge",
|
|
488
|
-
HierarchicalEdgeBundling_default
|
|
489
|
-
]
|
|
490
|
-
]);
|
|
491
|
-
var Tree = ({ space, selected, variant = "tidy", onNodeClick }) => {
|
|
492
|
-
const [model] = useAsyncState2(async () => space ? new SpaceGraphModel().open(space, selected) : void 0, [
|
|
493
|
-
space,
|
|
494
|
-
selected
|
|
495
|
-
]);
|
|
496
|
-
const [tree3, setTree] = useState2();
|
|
497
|
-
useEffect2(() => {
|
|
498
|
-
return model?.subscribe(() => {
|
|
499
|
-
const tree4 = mapGraphToTreeData(model);
|
|
500
|
-
setTree(tree4);
|
|
501
|
-
}, true);
|
|
502
|
-
}, [
|
|
503
|
-
model
|
|
504
|
-
]);
|
|
505
|
-
const context = createSvgContext2();
|
|
506
|
-
const { ref, width = 0, height = 0 } = useResizeDetector2();
|
|
507
|
-
useEffect2(() => {
|
|
508
|
-
if (width && height) {
|
|
509
|
-
const size = Math.min(width, height);
|
|
510
|
-
const radius = size * 0.4;
|
|
511
|
-
const options = {
|
|
512
|
-
// TODO(burdon): Type.
|
|
513
|
-
label: (d) => d.label ?? d.id,
|
|
514
|
-
width,
|
|
515
|
-
height,
|
|
516
|
-
radius,
|
|
517
|
-
marginLeft: (width - radius * 2) / 2,
|
|
518
|
-
marginRight: (width - radius * 2) / 2,
|
|
519
|
-
marginTop: (height - radius * 2) / 2,
|
|
520
|
-
marginBottom: (height - radius * 2) / 2,
|
|
521
|
-
slots: defaultTreeLayoutSlots
|
|
522
|
-
};
|
|
523
|
-
if (tree3) {
|
|
524
|
-
const renderer = renderers.get(variant);
|
|
525
|
-
renderer?.(context.ref.current, tree3, options);
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
}, [
|
|
529
|
-
tree3,
|
|
530
|
-
width,
|
|
531
|
-
height
|
|
532
|
-
]);
|
|
533
|
-
return /* @__PURE__ */ React2.createElement("div", {
|
|
534
|
-
ref,
|
|
535
|
-
className: "flex grow overflow-hidden",
|
|
536
|
-
onClick: () => onNodeClick?.()
|
|
537
|
-
}, /* @__PURE__ */ React2.createElement(SVGRoot2, {
|
|
538
|
-
context
|
|
539
|
-
}, /* @__PURE__ */ React2.createElement(SVG2, null)));
|
|
540
|
-
};
|
|
541
|
-
|
|
542
|
-
export {
|
|
543
|
-
SpaceGraphModel,
|
|
544
|
-
defaultTreeLayoutSlots,
|
|
545
|
-
Tree,
|
|
546
|
-
Graph
|
|
547
|
-
};
|
|
548
|
-
//# sourceMappingURL=chunk-3KRWHGBM.mjs.map
|