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