@ts-graphviz/react 0.10.6 → 0.11.1
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/CHANGELOG.md +497 -0
- package/README.md +630 -67
- package/example/example.tsx +1 -1
- package/lib/react.d.ts +198 -96
- package/lib/react.js +558 -215
- package/package.json +15 -20
- package/tsconfig.test.json +11 -0
- package/lib/react.cjs +0 -457
- package/src/components/Digraph.spec.tsx +0 -18
- package/src/components/Digraph.tsx +0 -41
- package/src/components/Edge.tsx +0 -17
- package/src/components/Graph.spec.tsx +0 -18
- package/src/components/Graph.tsx +0 -36
- package/src/components/GraphPortal.tsx +0 -22
- package/src/components/Node.spec.tsx +0 -101
- package/src/components/Node.tsx +0 -21
- package/src/components/Subgraph.tsx +0 -30
- package/src/contexts/CurrentGraph.ts +0 -5
- package/src/contexts/GraphContainer.ts +0 -5
- package/src/contexts/GraphMap.ts +0 -5
- package/src/contexts/GraphvizContext.ts +0 -11
- package/src/hooks/__tests__/wrapper.tsx +0 -58
- package/src/hooks/useCurrentGraph.spec.ts +0 -56
- package/src/hooks/useCurrentGraph.ts +0 -18
- package/src/hooks/useDigraph.spec.ts +0 -15
- package/src/hooks/useDigraph.ts +0 -33
- package/src/hooks/useEdge.spec.ts +0 -46
- package/src/hooks/useEdge.ts +0 -35
- package/src/hooks/useGraph.spec.ts +0 -15
- package/src/hooks/useGraph.ts +0 -33
- package/src/hooks/useGraphAttributes.ts +0 -32
- package/src/hooks/useGraphContainer.spec.ts +0 -45
- package/src/hooks/useGraphContainer.ts +0 -10
- package/src/hooks/useGraphMap.ts +0 -7
- package/src/hooks/useGraphvizContext.spec.ts +0 -26
- package/src/hooks/useGraphvizContext.ts +0 -16
- package/src/hooks/useHasAttributes.ts +0 -16
- package/src/hooks/useHasComment.ts +0 -8
- package/src/hooks/useNode.spec.ts +0 -16
- package/src/hooks/useNode.ts +0 -29
- package/src/hooks/useRenderedID.spec.tsx +0 -28
- package/src/hooks/useRenderedID.ts +0 -6
- package/src/hooks/useSubgraph.spec.ts +0 -41
- package/src/hooks/useSubgraph.ts +0 -39
- package/src/react.ts +0 -16
- package/src/reconciler.ts +0 -272
- package/src/render.test.tsx +0 -71
- package/src/render.ts +0 -142
- package/src/renderHTMLLike.ts +0 -9
- package/src/renderId.ts +0 -9
- package/src/types.ts +0 -107
- package/tsconfig.json +0 -8
- package/typedoc.json +0 -5
- package/vite.config.ts +0 -31
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-graphviz/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "Graphviz-dot Renderer for React.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphviz",
|
|
@@ -32,33 +32,27 @@
|
|
|
32
32
|
"exports": {
|
|
33
33
|
".": {
|
|
34
34
|
"types": "./lib/react.d.ts",
|
|
35
|
-
"require": "./lib/react.cjs",
|
|
36
35
|
"default": "./lib/react.js"
|
|
37
36
|
},
|
|
38
37
|
"./package.json": "./package.json"
|
|
39
38
|
},
|
|
40
|
-
"main": "./lib/react.js",
|
|
41
|
-
"types": "./lib/react.d.ts",
|
|
42
39
|
"dependencies": {
|
|
43
|
-
"react-reconciler": "^0.
|
|
44
|
-
"@ts-graphviz/common": "^
|
|
45
|
-
"ts-graphviz": "^
|
|
40
|
+
"react-reconciler": "^0.32.0",
|
|
41
|
+
"@ts-graphviz/common": "^3.0.1",
|
|
42
|
+
"ts-graphviz": "^3.0.1"
|
|
46
43
|
},
|
|
47
44
|
"devDependencies": {
|
|
48
|
-
"@testing-library/react": "^
|
|
49
|
-
"@types/react": "^
|
|
50
|
-
"@types/react-
|
|
51
|
-
"
|
|
52
|
-
"react": "^
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"vite": "^5.4.8",
|
|
57
|
-
"vite-plugin-dts": "^4.2.1"
|
|
45
|
+
"@testing-library/react": "^16.3.0",
|
|
46
|
+
"@types/react": "^19.0.0",
|
|
47
|
+
"@types/react-reconciler": "^0.32.0",
|
|
48
|
+
"react": "^19.0.0",
|
|
49
|
+
"react-test-renderer": "^19.0.0",
|
|
50
|
+
"typescript": "^5.8.2",
|
|
51
|
+
"vite": "^7.0.2",
|
|
52
|
+
"vite-plugin-dts": "^4.5.3"
|
|
58
53
|
},
|
|
59
54
|
"peerDependencies": {
|
|
60
|
-
"react": ">=
|
|
61
|
-
"react-dom": ">=18"
|
|
55
|
+
"react": ">=19"
|
|
62
56
|
},
|
|
63
57
|
"publishConfig": {
|
|
64
58
|
"access": "public",
|
|
@@ -67,5 +61,6 @@
|
|
|
67
61
|
"scripts": {
|
|
68
62
|
"build": "vite build",
|
|
69
63
|
"example": "ts-node example/example"
|
|
70
|
-
}
|
|
64
|
+
},
|
|
65
|
+
"types": "./lib/react.d.ts"
|
|
71
66
|
}
|
package/lib/react.cjs
DELETED
|
@@ -1,457 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const react = require("react");
|
|
4
|
-
const tsGraphviz = require("ts-graphviz");
|
|
5
|
-
const jsxRuntime = require("react/jsx-runtime");
|
|
6
|
-
const server = require("react-dom/server");
|
|
7
|
-
const ReactReconciler = require("react-reconciler");
|
|
8
|
-
const GraphContainer = react.createContext(null);
|
|
9
|
-
GraphContainer.displayName = "GraphContainer";
|
|
10
|
-
function useGraphContainer() {
|
|
11
|
-
return react.useContext(GraphContainer);
|
|
12
|
-
}
|
|
13
|
-
const CurrentGraph = react.createContext(null);
|
|
14
|
-
CurrentGraph.displayName = "CurrentGraph";
|
|
15
|
-
function useCurrentGraph() {
|
|
16
|
-
const cluster = react.useContext(CurrentGraph);
|
|
17
|
-
if (cluster === null) {
|
|
18
|
-
throw Error(
|
|
19
|
-
"useCurrentGraph must be called within a cluster such as Digraph, Graph, Subgraph."
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
return cluster;
|
|
23
|
-
}
|
|
24
|
-
function useGraphAttributes(cluster, attributes, { edge, node, graph }) {
|
|
25
|
-
react.useEffect(() => {
|
|
26
|
-
cluster.clear();
|
|
27
|
-
cluster.apply(attributes);
|
|
28
|
-
}, [cluster, attributes]);
|
|
29
|
-
react.useEffect(() => {
|
|
30
|
-
cluster.attributes.node.clear();
|
|
31
|
-
cluster.attributes.node.apply(node ?? {});
|
|
32
|
-
}, [cluster, node]);
|
|
33
|
-
react.useEffect(() => {
|
|
34
|
-
cluster.attributes.edge.clear();
|
|
35
|
-
cluster.attributes.edge.apply(edge ?? {});
|
|
36
|
-
}, [cluster, edge]);
|
|
37
|
-
react.useEffect(() => {
|
|
38
|
-
cluster.attributes.graph.clear();
|
|
39
|
-
cluster.attributes.graph.apply(graph ?? {});
|
|
40
|
-
}, [cluster, graph]);
|
|
41
|
-
}
|
|
42
|
-
const GraphvizContext = react.createContext(
|
|
43
|
-
null
|
|
44
|
-
);
|
|
45
|
-
GraphvizContext.displayName = "GraphvizContext";
|
|
46
|
-
function useGraphvizContext() {
|
|
47
|
-
const context = react.useContext(
|
|
48
|
-
GraphvizContext
|
|
49
|
-
);
|
|
50
|
-
if (context === null) {
|
|
51
|
-
throw Error(
|
|
52
|
-
"Cannot call useGraphvizContext outside GraphvizContext.\nBasically, you need to use the render function provided by @ts-graphviz/react."
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
return context;
|
|
56
|
-
}
|
|
57
|
-
function useHasComment(target, comment) {
|
|
58
|
-
react.useEffect(() => {
|
|
59
|
-
target.comment = comment;
|
|
60
|
-
}, [target, comment]);
|
|
61
|
-
}
|
|
62
|
-
function useDigraph(options = {}) {
|
|
63
|
-
const { id, comment, edge, node, graph, ...attributes } = options;
|
|
64
|
-
const context = useGraphvizContext();
|
|
65
|
-
const digraph = react.useMemo(() => {
|
|
66
|
-
const g = new tsGraphviz.Digraph(id);
|
|
67
|
-
context.container = g;
|
|
68
|
-
g.comment = comment;
|
|
69
|
-
g.apply(attributes);
|
|
70
|
-
g.attributes.node.apply(node ?? {});
|
|
71
|
-
g.attributes.edge.apply(edge ?? {});
|
|
72
|
-
g.attributes.graph.apply(graph ?? {});
|
|
73
|
-
return g;
|
|
74
|
-
}, [context, id, comment, edge, node, graph, attributes]);
|
|
75
|
-
useHasComment(digraph, comment);
|
|
76
|
-
useGraphAttributes(digraph, attributes, { edge, node, graph });
|
|
77
|
-
react.useEffect(() => {
|
|
78
|
-
return () => {
|
|
79
|
-
context.container = void 0;
|
|
80
|
-
};
|
|
81
|
-
}, [context]);
|
|
82
|
-
return digraph;
|
|
83
|
-
}
|
|
84
|
-
function useGraph(options = {}) {
|
|
85
|
-
const { id, comment, edge, node, graph, ...attributes } = options;
|
|
86
|
-
const context = useGraphvizContext();
|
|
87
|
-
const memoGraph = react.useMemo(() => {
|
|
88
|
-
const g = new tsGraphviz.Graph(id);
|
|
89
|
-
context.container = g;
|
|
90
|
-
g.comment = comment;
|
|
91
|
-
g.apply(attributes);
|
|
92
|
-
g.attributes.node.apply(node ?? {});
|
|
93
|
-
g.attributes.edge.apply(edge ?? {});
|
|
94
|
-
g.attributes.graph.apply(graph ?? {});
|
|
95
|
-
return g;
|
|
96
|
-
}, [context, id, comment, edge, node, graph, attributes]);
|
|
97
|
-
useHasComment(memoGraph, comment);
|
|
98
|
-
useGraphAttributes(memoGraph, attributes, { edge, node, graph });
|
|
99
|
-
react.useEffect(() => {
|
|
100
|
-
return () => {
|
|
101
|
-
context.container = void 0;
|
|
102
|
-
};
|
|
103
|
-
}, [context]);
|
|
104
|
-
return memoGraph;
|
|
105
|
-
}
|
|
106
|
-
function useSubgraph(props = {}) {
|
|
107
|
-
const { id, comment, edge, node, graph, ...attributes } = props;
|
|
108
|
-
const context = useGraphvizContext();
|
|
109
|
-
const cluster = useCurrentGraph();
|
|
110
|
-
const subgraph = react.useMemo(() => {
|
|
111
|
-
const g = new tsGraphviz.Subgraph(id);
|
|
112
|
-
if (cluster !== null) {
|
|
113
|
-
cluster.addSubgraph(g);
|
|
114
|
-
} else if (!context.container) {
|
|
115
|
-
context.container = g;
|
|
116
|
-
}
|
|
117
|
-
g.comment = comment;
|
|
118
|
-
g.apply(attributes);
|
|
119
|
-
g.attributes.node.apply(node ?? {});
|
|
120
|
-
g.attributes.edge.apply(edge ?? {});
|
|
121
|
-
g.attributes.graph.apply(graph ?? {});
|
|
122
|
-
return g;
|
|
123
|
-
}, [context, cluster, id, comment, edge, node, graph, attributes]);
|
|
124
|
-
useHasComment(subgraph, comment);
|
|
125
|
-
useGraphAttributes(subgraph, attributes, { edge, node, graph });
|
|
126
|
-
react.useEffect(() => {
|
|
127
|
-
return () => {
|
|
128
|
-
cluster.removeSubgraph(subgraph);
|
|
129
|
-
};
|
|
130
|
-
}, [cluster, subgraph]);
|
|
131
|
-
return subgraph;
|
|
132
|
-
}
|
|
133
|
-
function useHasAttributes(target, attributes) {
|
|
134
|
-
react.useEffect(() => {
|
|
135
|
-
target.attributes.clear();
|
|
136
|
-
target.attributes.apply(attributes);
|
|
137
|
-
}, [target, attributes]);
|
|
138
|
-
}
|
|
139
|
-
function useEdge(targets, props = {}) {
|
|
140
|
-
const { comment, ...attributes } = props;
|
|
141
|
-
const cluster = useCurrentGraph();
|
|
142
|
-
if (targets.length < 2) {
|
|
143
|
-
throw Error("Edges must have at least 2 targets.");
|
|
144
|
-
}
|
|
145
|
-
const edge = react.useMemo(() => {
|
|
146
|
-
const e = cluster.createEdge(targets);
|
|
147
|
-
e.comment = comment;
|
|
148
|
-
e.attributes.apply(attributes);
|
|
149
|
-
return e;
|
|
150
|
-
}, [cluster, targets, comment, attributes]);
|
|
151
|
-
useHasComment(edge, comment);
|
|
152
|
-
useHasAttributes(edge, attributes);
|
|
153
|
-
react.useEffect(() => {
|
|
154
|
-
return () => {
|
|
155
|
-
cluster.removeEdge(edge);
|
|
156
|
-
};
|
|
157
|
-
}, [cluster, edge]);
|
|
158
|
-
return edge;
|
|
159
|
-
}
|
|
160
|
-
function useNode(id, options = {}) {
|
|
161
|
-
const { comment, ...attributes } = options;
|
|
162
|
-
const cluster = useCurrentGraph();
|
|
163
|
-
const node = react.useMemo(() => {
|
|
164
|
-
const n = cluster.createNode(id);
|
|
165
|
-
n.attributes.apply(attributes);
|
|
166
|
-
n.comment = comment;
|
|
167
|
-
return n;
|
|
168
|
-
}, [cluster, id, attributes, comment]);
|
|
169
|
-
useHasComment(node, comment);
|
|
170
|
-
useHasAttributes(node, attributes);
|
|
171
|
-
react.useEffect(() => {
|
|
172
|
-
return () => {
|
|
173
|
-
cluster.removeNode(node);
|
|
174
|
-
};
|
|
175
|
-
}, [cluster, node]);
|
|
176
|
-
return node;
|
|
177
|
-
}
|
|
178
|
-
const GraphMap = react.createContext(/* @__PURE__ */ new Map());
|
|
179
|
-
GraphMap.displayName = "GraphMap";
|
|
180
|
-
function useGraphMap() {
|
|
181
|
-
return react.useContext(GraphMap);
|
|
182
|
-
}
|
|
183
|
-
function renderHTMLLike(label) {
|
|
184
|
-
const htmlLike = server.renderToStaticMarkup(label).replace(/<dot:port>(.+?)<\/dot:port>/gi, "<$1>").replace(/<(\/?)dot:([a-z-]+)/gi, (_, $1, $2) => `<${$1}${$2}`);
|
|
185
|
-
return `<${htmlLike}>`;
|
|
186
|
-
}
|
|
187
|
-
function renderId(id) {
|
|
188
|
-
if (react.isValidElement(id)) {
|
|
189
|
-
return renderHTMLLike(id);
|
|
190
|
-
}
|
|
191
|
-
return id;
|
|
192
|
-
}
|
|
193
|
-
function useRenderedID(id) {
|
|
194
|
-
return react.useMemo(() => renderId(id), [id]);
|
|
195
|
-
}
|
|
196
|
-
const Graph = ({ children, label, ...options }) => {
|
|
197
|
-
const container = useGraphContainer();
|
|
198
|
-
if (container !== null) {
|
|
199
|
-
throw Error(
|
|
200
|
-
"RootCluster is duplicated.\nUse only one of Digraph and Graph."
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
const renderedLabel = useRenderedID(label);
|
|
204
|
-
if (renderedLabel !== void 0)
|
|
205
|
-
Object.assign(options, { label: renderedLabel });
|
|
206
|
-
const graph = useGraph(options);
|
|
207
|
-
const clusters = useGraphMap();
|
|
208
|
-
react.useEffect(() => {
|
|
209
|
-
if (graph.id !== void 0) {
|
|
210
|
-
clusters.set(graph.id, graph);
|
|
211
|
-
}
|
|
212
|
-
}, [clusters, graph]);
|
|
213
|
-
return /* @__PURE__ */ jsxRuntime.jsx(GraphContainer.Provider, { value: graph, children: /* @__PURE__ */ jsxRuntime.jsx(CurrentGraph.Provider, { value: graph, children }) });
|
|
214
|
-
};
|
|
215
|
-
Graph.displayName = "Graph";
|
|
216
|
-
const Digraph = ({
|
|
217
|
-
children,
|
|
218
|
-
label,
|
|
219
|
-
...options
|
|
220
|
-
}) => {
|
|
221
|
-
const container = useGraphContainer();
|
|
222
|
-
if (container !== null) {
|
|
223
|
-
throw Error(
|
|
224
|
-
"RootCluster is duplicated.\nUse only one of Digraph and Graph."
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
const renderedLabel = useRenderedID(label);
|
|
228
|
-
if (renderedLabel !== void 0)
|
|
229
|
-
Object.assign(options, { label: renderedLabel });
|
|
230
|
-
const digraph = useDigraph(options);
|
|
231
|
-
const clusters = useGraphMap();
|
|
232
|
-
react.useEffect(() => {
|
|
233
|
-
if (digraph.id !== void 0) {
|
|
234
|
-
clusters.set(digraph.id, digraph);
|
|
235
|
-
}
|
|
236
|
-
}, [clusters, digraph]);
|
|
237
|
-
return /* @__PURE__ */ jsxRuntime.jsx(GraphContainer.Provider, { value: digraph, children: /* @__PURE__ */ jsxRuntime.jsx(CurrentGraph.Provider, { value: digraph, children }) });
|
|
238
|
-
};
|
|
239
|
-
Digraph.displayName = "Digraph";
|
|
240
|
-
const Subgraph = ({
|
|
241
|
-
children,
|
|
242
|
-
label,
|
|
243
|
-
...options
|
|
244
|
-
}) => {
|
|
245
|
-
const renderedLabel = useRenderedID(label);
|
|
246
|
-
if (renderedLabel !== void 0)
|
|
247
|
-
Object.assign(options, { label: renderedLabel });
|
|
248
|
-
const subgraph = useSubgraph(options);
|
|
249
|
-
const clusters = useGraphMap();
|
|
250
|
-
react.useEffect(() => {
|
|
251
|
-
if (subgraph.id !== void 0) {
|
|
252
|
-
clusters.set(subgraph.id, subgraph);
|
|
253
|
-
}
|
|
254
|
-
}, [subgraph, clusters]);
|
|
255
|
-
return /* @__PURE__ */ jsxRuntime.jsx(CurrentGraph.Provider, { value: subgraph, children });
|
|
256
|
-
};
|
|
257
|
-
Subgraph.displayName = "Subgraph";
|
|
258
|
-
const Node = ({ id, label, xlabel, ...options }) => {
|
|
259
|
-
const renderedLabel = useRenderedID(label);
|
|
260
|
-
const renderedXlabel = useRenderedID(xlabel);
|
|
261
|
-
if (renderedLabel !== void 0)
|
|
262
|
-
Object.assign(options, { label: renderedLabel });
|
|
263
|
-
if (renderedXlabel !== void 0)
|
|
264
|
-
Object.assign(options, { xlabel: renderedXlabel });
|
|
265
|
-
useNode(id, options);
|
|
266
|
-
return null;
|
|
267
|
-
};
|
|
268
|
-
Node.displayName = "Node";
|
|
269
|
-
const Edge = ({ targets, label, ...options }) => {
|
|
270
|
-
const renderedLabel = useRenderedID(label);
|
|
271
|
-
if (renderedLabel !== void 0)
|
|
272
|
-
Object.assign(options, { label: renderedLabel });
|
|
273
|
-
useEdge(targets, options);
|
|
274
|
-
return null;
|
|
275
|
-
};
|
|
276
|
-
Edge.displayName = "Edge";
|
|
277
|
-
const GraphPortal = ({ children, id }) => {
|
|
278
|
-
const container = useGraphContainer();
|
|
279
|
-
const map = react.useContext(GraphMap);
|
|
280
|
-
const cluster = react.useMemo(
|
|
281
|
-
() => id ? map.get(id) ?? container : container,
|
|
282
|
-
[container, map, id]
|
|
283
|
-
);
|
|
284
|
-
return /* @__PURE__ */ jsxRuntime.jsx(CurrentGraph.Provider, { value: cluster, children });
|
|
285
|
-
};
|
|
286
|
-
GraphPortal.displayName = "GraphPortal";
|
|
287
|
-
class HostConfig {
|
|
288
|
-
preparePortalMount(containerInfo) {
|
|
289
|
-
}
|
|
290
|
-
scheduleTimeout(fn, delay) {
|
|
291
|
-
}
|
|
292
|
-
cancelTimeout(id) {
|
|
293
|
-
}
|
|
294
|
-
queueMicrotask(fn) {
|
|
295
|
-
}
|
|
296
|
-
cloneInstance;
|
|
297
|
-
cloneFundamentalInstance;
|
|
298
|
-
createContainerChildSet;
|
|
299
|
-
appendChildToContainerChildSet;
|
|
300
|
-
finalizeContainerChildren;
|
|
301
|
-
replaceContainerChildren;
|
|
302
|
-
cloneHiddenInstance;
|
|
303
|
-
cloneHiddenTextInstance;
|
|
304
|
-
now = Date.now;
|
|
305
|
-
setTimeout = setTimeout;
|
|
306
|
-
clearTimeout = clearTimeout;
|
|
307
|
-
noTimeout = -1;
|
|
308
|
-
// TODO
|
|
309
|
-
// Temporary workaround for scenario where multiple renderers concurrently
|
|
310
|
-
// render using the same context objects. E.g. React DOM and React ART on the
|
|
311
|
-
// same page. DOM is the primary renderer; ART is the secondary renderer.
|
|
312
|
-
isPrimaryRenderer = false;
|
|
313
|
-
supportsMutation = false;
|
|
314
|
-
supportsPersistence = false;
|
|
315
|
-
supportsHydration = false;
|
|
316
|
-
getPublicInstance(instance) {
|
|
317
|
-
return instance;
|
|
318
|
-
}
|
|
319
|
-
getRootHostContext(rootContainerInstance) {
|
|
320
|
-
return {};
|
|
321
|
-
}
|
|
322
|
-
getChildHostContext(parentHostContext, type, rootContainerInstance) {
|
|
323
|
-
return parentHostContext;
|
|
324
|
-
}
|
|
325
|
-
prepareForCommit(containerInfo) {
|
|
326
|
-
return null;
|
|
327
|
-
}
|
|
328
|
-
resetAfterCommit(containerInfo) {
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* Create component instance
|
|
332
|
-
*/
|
|
333
|
-
createInstance(type, props, rootContainerInstance, hostContext, internalInstanceHandle) {
|
|
334
|
-
return type(props);
|
|
335
|
-
}
|
|
336
|
-
appendInitialChild(parentInstance, child) {
|
|
337
|
-
parentInstance.appendChild(child);
|
|
338
|
-
}
|
|
339
|
-
finalizeInitialChildren(parentInstance, type, props, rootContainerInstance, hostContext) {
|
|
340
|
-
return false;
|
|
341
|
-
}
|
|
342
|
-
prepareUpdate(instance, type, oldProps, newProps, rootContainerInstance, hostContext) {
|
|
343
|
-
return {};
|
|
344
|
-
}
|
|
345
|
-
shouldSetTextContent(type, props) {
|
|
346
|
-
return false;
|
|
347
|
-
}
|
|
348
|
-
shouldDeprioritizeSubtree(type, props) {
|
|
349
|
-
return false;
|
|
350
|
-
}
|
|
351
|
-
createTextInstance(text, rootContainerInstance, hostContext, internalInstanceHandle) {
|
|
352
|
-
return text;
|
|
353
|
-
}
|
|
354
|
-
scheduleDeferredCallback(callback, options) {
|
|
355
|
-
}
|
|
356
|
-
cancelDeferredCallback(callbackID) {
|
|
357
|
-
}
|
|
358
|
-
// -------------------
|
|
359
|
-
// Mutation
|
|
360
|
-
// (optional)
|
|
361
|
-
// -------------------
|
|
362
|
-
appendChild(parentInstance, child) {
|
|
363
|
-
if (parentInstance.appendChild) {
|
|
364
|
-
parentInstance.appendChild(child);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
appendChildToContainer(container, child) {
|
|
368
|
-
}
|
|
369
|
-
commitTextUpdate(textInstance, oldText, newText) {
|
|
370
|
-
}
|
|
371
|
-
commitMount(instance, type, newProps, internalInstanceHandle) {
|
|
372
|
-
}
|
|
373
|
-
commitUpdate(instance, updatePayload, type, oldProps, newProps, internalInstanceHandle) {
|
|
374
|
-
}
|
|
375
|
-
insertBefore(parentInstance, child, beforeChild) {
|
|
376
|
-
}
|
|
377
|
-
insertInContainerBefore(container, child, beforeChild) {
|
|
378
|
-
}
|
|
379
|
-
removeChild(parentInstance, child) {
|
|
380
|
-
}
|
|
381
|
-
removeChildFromContainer(container, child) {
|
|
382
|
-
}
|
|
383
|
-
resetTextContent(instance) {
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
const reconciler = ReactReconciler(new HostConfig());
|
|
387
|
-
const noop = () => void 0;
|
|
388
|
-
function clusterMap(graph, map = /* @__PURE__ */ new Map()) {
|
|
389
|
-
if (graph) {
|
|
390
|
-
if (graph.id) {
|
|
391
|
-
map.set(graph.id, graph);
|
|
392
|
-
}
|
|
393
|
-
for (const s of graph.subgraphs) {
|
|
394
|
-
clusterMap(s, map);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
return map;
|
|
398
|
-
}
|
|
399
|
-
function render(element, container) {
|
|
400
|
-
const context = { container };
|
|
401
|
-
reconciler.updateContainer(
|
|
402
|
-
react.createElement(
|
|
403
|
-
GraphvizContext.Provider,
|
|
404
|
-
{ value: context },
|
|
405
|
-
react.createElement(
|
|
406
|
-
GraphMap.Provider,
|
|
407
|
-
{ value: clusterMap(container) },
|
|
408
|
-
react.createElement(
|
|
409
|
-
GraphContainer.Provider,
|
|
410
|
-
{ value: container ?? null },
|
|
411
|
-
container ? react.createElement(
|
|
412
|
-
CurrentGraph.Provider,
|
|
413
|
-
{ value: container },
|
|
414
|
-
element
|
|
415
|
-
) : element
|
|
416
|
-
)
|
|
417
|
-
)
|
|
418
|
-
),
|
|
419
|
-
reconciler.createContainer(
|
|
420
|
-
{},
|
|
421
|
-
0,
|
|
422
|
-
null,
|
|
423
|
-
true,
|
|
424
|
-
null,
|
|
425
|
-
"@ts-graphviz/react",
|
|
426
|
-
noop,
|
|
427
|
-
null
|
|
428
|
-
),
|
|
429
|
-
null,
|
|
430
|
-
noop
|
|
431
|
-
);
|
|
432
|
-
if (!context.container) {
|
|
433
|
-
throw Error(
|
|
434
|
-
"There are no clusters of container(Subgraph, Digraph, Graph)."
|
|
435
|
-
);
|
|
436
|
-
}
|
|
437
|
-
return context.container;
|
|
438
|
-
}
|
|
439
|
-
function renderToDot(element, container) {
|
|
440
|
-
return tsGraphviz.toDot(render(element, container));
|
|
441
|
-
}
|
|
442
|
-
exports.Digraph = Digraph;
|
|
443
|
-
exports.Edge = Edge;
|
|
444
|
-
exports.Graph = Graph;
|
|
445
|
-
exports.GraphPortal = GraphPortal;
|
|
446
|
-
exports.Node = Node;
|
|
447
|
-
exports.Subgraph = Subgraph;
|
|
448
|
-
exports.render = render;
|
|
449
|
-
exports.renderHTMLLike = renderHTMLLike;
|
|
450
|
-
exports.renderToDot = renderToDot;
|
|
451
|
-
exports.useCurrentGraph = useCurrentGraph;
|
|
452
|
-
exports.useDigraph = useDigraph;
|
|
453
|
-
exports.useEdge = useEdge;
|
|
454
|
-
exports.useGraph = useGraph;
|
|
455
|
-
exports.useGraphContainer = useGraphContainer;
|
|
456
|
-
exports.useNode = useNode;
|
|
457
|
-
exports.useSubgraph = useSubgraph;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
import { render } from '../render.js';
|
|
3
|
-
import { Digraph } from './Digraph.js';
|
|
4
|
-
|
|
5
|
-
describe('Digraph', () => {
|
|
6
|
-
test('An error occurs when duplicate <Digraph />', () => {
|
|
7
|
-
expect(() => {
|
|
8
|
-
render(
|
|
9
|
-
<Digraph>
|
|
10
|
-
<Digraph />
|
|
11
|
-
</Digraph>,
|
|
12
|
-
);
|
|
13
|
-
}).toThrowErrorMatchingInlineSnapshot(`
|
|
14
|
-
[Error: RootCluster is duplicated.
|
|
15
|
-
Use only one of Digraph and Graph.]
|
|
16
|
-
`);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { type FC, useEffect } from 'react';
|
|
2
|
-
import { CurrentGraph } from '../contexts/CurrentGraph.js';
|
|
3
|
-
import { GraphContainer } from '../contexts/GraphContainer.js';
|
|
4
|
-
import { useDigraph } from '../hooks/useDigraph.js';
|
|
5
|
-
import { useGraphContainer } from '../hooks/useGraphContainer.js';
|
|
6
|
-
import { useGraphMap } from '../hooks/useGraphMap.js';
|
|
7
|
-
import { useRenderedID } from '../hooks/useRenderedID.js';
|
|
8
|
-
import type { RootGraphProps } from '../types.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* `Digraph` component.
|
|
12
|
-
*/
|
|
13
|
-
export const Digraph: FC<RootGraphProps> = ({
|
|
14
|
-
children,
|
|
15
|
-
label,
|
|
16
|
-
...options
|
|
17
|
-
}) => {
|
|
18
|
-
const container = useGraphContainer();
|
|
19
|
-
if (container !== null) {
|
|
20
|
-
throw Error(
|
|
21
|
-
'RootCluster is duplicated.\nUse only one of Digraph and Graph.',
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
const renderedLabel = useRenderedID(label);
|
|
25
|
-
if (renderedLabel !== undefined)
|
|
26
|
-
Object.assign(options, { label: renderedLabel });
|
|
27
|
-
const digraph = useDigraph(options);
|
|
28
|
-
const clusters = useGraphMap();
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
if (digraph.id !== undefined) {
|
|
31
|
-
clusters.set(digraph.id, digraph);
|
|
32
|
-
}
|
|
33
|
-
}, [clusters, digraph]);
|
|
34
|
-
return (
|
|
35
|
-
<GraphContainer.Provider value={digraph}>
|
|
36
|
-
<CurrentGraph.Provider value={digraph}>{children}</CurrentGraph.Provider>
|
|
37
|
-
</GraphContainer.Provider>
|
|
38
|
-
);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
Digraph.displayName = 'Digraph';
|
package/src/components/Edge.tsx
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { FC } from 'react';
|
|
2
|
-
import { useEdge } from '../hooks/useEdge.js';
|
|
3
|
-
import { useRenderedID } from '../hooks/useRenderedID.js';
|
|
4
|
-
import type { EdgeProps } from '../types.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* `Edge` component.
|
|
8
|
-
*/
|
|
9
|
-
export const Edge: FC<EdgeProps> = ({ targets, label, ...options }) => {
|
|
10
|
-
const renderedLabel = useRenderedID(label);
|
|
11
|
-
if (renderedLabel !== undefined)
|
|
12
|
-
Object.assign(options, { label: renderedLabel });
|
|
13
|
-
useEdge(targets, options);
|
|
14
|
-
return null;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
Edge.displayName = 'Edge';
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
import { render } from '../render.js';
|
|
3
|
-
import { Graph } from './Graph.js';
|
|
4
|
-
|
|
5
|
-
describe('Graph', () => {
|
|
6
|
-
test('An error occurs when duplicate <Graph />', () => {
|
|
7
|
-
expect(() => {
|
|
8
|
-
render(
|
|
9
|
-
<Graph>
|
|
10
|
-
<Graph />
|
|
11
|
-
</Graph>,
|
|
12
|
-
);
|
|
13
|
-
}).toThrowErrorMatchingInlineSnapshot(`
|
|
14
|
-
[Error: RootCluster is duplicated.
|
|
15
|
-
Use only one of Digraph and Graph.]
|
|
16
|
-
`);
|
|
17
|
-
});
|
|
18
|
-
});
|
package/src/components/Graph.tsx
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { type FC, useEffect } from 'react';
|
|
2
|
-
import { CurrentGraph } from '../contexts/CurrentGraph.js';
|
|
3
|
-
import { GraphContainer } from '../contexts/GraphContainer.js';
|
|
4
|
-
import { useGraph } from '../hooks/useGraph.js';
|
|
5
|
-
import { useGraphContainer } from '../hooks/useGraphContainer.js';
|
|
6
|
-
import { useGraphMap } from '../hooks/useGraphMap.js';
|
|
7
|
-
import { useRenderedID } from '../hooks/useRenderedID.js';
|
|
8
|
-
import type { RootGraphProps } from '../types.js';
|
|
9
|
-
/**
|
|
10
|
-
* `Graph` component.
|
|
11
|
-
*/
|
|
12
|
-
export const Graph: FC<RootGraphProps> = ({ children, label, ...options }) => {
|
|
13
|
-
const container = useGraphContainer();
|
|
14
|
-
if (container !== null) {
|
|
15
|
-
throw Error(
|
|
16
|
-
'RootCluster is duplicated.\nUse only one of Digraph and Graph.',
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
const renderedLabel = useRenderedID(label);
|
|
20
|
-
if (renderedLabel !== undefined)
|
|
21
|
-
Object.assign(options, { label: renderedLabel });
|
|
22
|
-
const graph = useGraph(options);
|
|
23
|
-
const clusters = useGraphMap();
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
if (graph.id !== undefined) {
|
|
26
|
-
clusters.set(graph.id, graph);
|
|
27
|
-
}
|
|
28
|
-
}, [clusters, graph]);
|
|
29
|
-
return (
|
|
30
|
-
<GraphContainer.Provider value={graph}>
|
|
31
|
-
<CurrentGraph.Provider value={graph}>{children}</CurrentGraph.Provider>
|
|
32
|
-
</GraphContainer.Provider>
|
|
33
|
-
);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
Graph.displayName = 'Graph';
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { type FC, useContext, useMemo } from 'react';
|
|
2
|
-
import { CurrentGraph } from '../contexts/CurrentGraph.js';
|
|
3
|
-
import { GraphMap } from '../contexts/GraphMap.js';
|
|
4
|
-
import { useGraphContainer } from '../hooks/useGraphContainer.js';
|
|
5
|
-
import type { GraphPortalProps } from '../types.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* GraphPortal component.
|
|
9
|
-
*/
|
|
10
|
-
export const GraphPortal: FC<GraphPortalProps> = ({ children, id }) => {
|
|
11
|
-
const container = useGraphContainer();
|
|
12
|
-
const map = useContext(GraphMap);
|
|
13
|
-
const cluster = useMemo(
|
|
14
|
-
() => (id ? map.get(id) ?? container : container),
|
|
15
|
-
[container, map, id],
|
|
16
|
-
);
|
|
17
|
-
return (
|
|
18
|
-
<CurrentGraph.Provider value={cluster}>{children}</CurrentGraph.Provider>
|
|
19
|
-
);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
GraphPortal.displayName = 'GraphPortal';
|