@ts-graphviz/react 0.9.1 → 0.10.0

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.
Files changed (62) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/LICENSE +1 -1
  3. package/README.md +25 -63
  4. package/example/example.tsx +14 -12
  5. package/lib/react.cjs +457 -0
  6. package/lib/react.d.ts +230 -0
  7. package/lib/react.js +457 -0
  8. package/package.json +55 -65
  9. package/src/components/Digraph.spec.tsx +18 -0
  10. package/src/components/Digraph.tsx +41 -0
  11. package/src/components/Edge.tsx +17 -0
  12. package/src/components/Graph.spec.tsx +18 -0
  13. package/src/components/Graph.tsx +36 -0
  14. package/src/components/GraphPortal.tsx +22 -0
  15. package/src/components/Node.spec.tsx +101 -0
  16. package/src/components/Node.tsx +21 -0
  17. package/src/components/Subgraph.tsx +30 -0
  18. package/src/contexts/CurrentGraph.ts +5 -0
  19. package/src/contexts/GraphContainer.ts +5 -0
  20. package/src/contexts/GraphMap.ts +5 -0
  21. package/src/contexts/GraphvizContext.ts +11 -0
  22. package/src/hooks/__tests__/wrapper.tsx +58 -0
  23. package/src/hooks/useCurrentGraph.spec.ts +56 -0
  24. package/src/hooks/useCurrentGraph.ts +18 -0
  25. package/src/hooks/useDigraph.spec.ts +15 -0
  26. package/src/hooks/useDigraph.ts +33 -0
  27. package/src/hooks/useEdge.spec.ts +46 -0
  28. package/src/hooks/useEdge.ts +35 -0
  29. package/src/hooks/useGraph.spec.ts +15 -0
  30. package/src/hooks/useGraph.ts +33 -0
  31. package/src/hooks/useGraphAttributes.ts +32 -0
  32. package/src/hooks/useGraphContainer.spec.ts +45 -0
  33. package/src/hooks/useGraphContainer.ts +10 -0
  34. package/src/hooks/useGraphMap.ts +7 -0
  35. package/src/hooks/useGraphvizContext.spec.ts +26 -0
  36. package/src/hooks/useGraphvizContext.ts +16 -0
  37. package/src/hooks/useHasAttributes.ts +16 -0
  38. package/src/hooks/useHasComment.ts +8 -0
  39. package/src/hooks/useNode.spec.ts +16 -0
  40. package/src/hooks/useNode.ts +29 -0
  41. package/src/hooks/useRenderedID.spec.tsx +28 -0
  42. package/src/hooks/useRenderedID.ts +6 -0
  43. package/src/hooks/useSubgraph.spec.ts +41 -0
  44. package/src/hooks/useSubgraph.ts +39 -0
  45. package/src/react.ts +16 -0
  46. package/src/reconciler.ts +272 -0
  47. package/src/render.test.tsx +71 -0
  48. package/src/render.ts +142 -0
  49. package/src/renderHTMLLike.ts +9 -0
  50. package/src/renderId.ts +9 -0
  51. package/src/types.ts +107 -0
  52. package/tsconfig.json +8 -0
  53. package/typedoc.json +5 -0
  54. package/vite.config.ts +31 -0
  55. package/.all-contributorsrc +0 -47
  56. package/.devcontainer/Dockerfile +0 -16
  57. package/.devcontainer/devcontainer.json +0 -35
  58. package/.eslintignore +0 -2
  59. package/lib/index.d.ts +0 -368
  60. package/lib/index.js +0 -1
  61. package/lib/index.mjs +0 -1
  62. package/rollup.config.js +0 -55
package/lib/index.d.ts DELETED
@@ -1,368 +0,0 @@
1
- /// <reference types="react" />
2
- import { ReactElement, FC, VFC } from 'react';
3
- import {
4
- EdgeAttributes,
5
- NodeAttributes,
6
- ClusterSubgraphAttributes,
7
- RootClusterAttributes,
8
- attribute,
9
- IHasComment,
10
- EdgeTargetLikeTuple,
11
- AttributesValue,
12
- ICluster,
13
- IRootCluster,
14
- ISubgraph,
15
- IEdge,
16
- INode,
17
- } from 'ts-graphviz';
18
-
19
- /** Common attribute values of objects under cluster */
20
- interface ClusterCommonAttributesProps {
21
- /** Attribute value for Edges */
22
- edge?: EdgeAttributes;
23
- /** Attribute value for Nodes */
24
- node?: NodeAttributes;
25
- /** Attribute value for Graphs */
26
- graph?: ClusterSubgraphAttributes;
27
- }
28
- /** Options for RootCluster */
29
- interface RootClusterOptions
30
- extends Omit<RootClusterAttributes, typeof attribute.comment>,
31
- ClusterCommonAttributesProps,
32
- IHasComment {
33
- /** Cluster id */
34
- id?: string;
35
- }
36
- /** Options for Subgraph */
37
- interface SubgraphOptions
38
- extends Omit<ClusterSubgraphAttributes, typeof attribute.comment>,
39
- ClusterCommonAttributesProps,
40
- IHasComment {
41
- /** Cluster id */
42
- id?: string;
43
- }
44
- /** Options for Edge */
45
- interface EdgeOptions extends Omit<EdgeAttributes, typeof attribute.comment>, IHasComment {}
46
- /** Options for Node */
47
- interface NodeOptions extends Omit<NodeAttributes, typeof attribute.comment>, IHasComment {}
48
- /** Props for RootCluster component */
49
- interface RootClusterProps extends Omit<RootClusterOptions, typeof attribute.label> {
50
- label?: ReactElement | string;
51
- }
52
- /** Props for Edge component */
53
- interface EdgeProps extends Omit<EdgeOptions, typeof attribute.label> {
54
- /** Edge targets */
55
- targets: EdgeTargetLikeTuple;
56
- /** Edge label */
57
- label?: ReactElement | string;
58
- }
59
- /** Props for Node component */
60
- interface NodeProps extends Omit<NodeOptions, typeof attribute.label | typeof attribute.xlabel> {
61
- /** Node id */
62
- id: string;
63
- /** Node label */
64
- label?: ReactElement | string;
65
- /** Node xlabel */
66
- xlabel?: ReactElement | string;
67
- }
68
- /** Props for Subgraph component */
69
- interface SubgraphProps extends Omit<SubgraphOptions, typeof attribute.label> {
70
- /** Subgraph label */
71
- label?: ReactElement | string;
72
- }
73
- /** Props for ClusterPortal component */
74
- interface ClusterPortalProps {
75
- /**
76
- * id of the cluster you want to target for the portal.
77
- * If not specified, target the cluster that is the container to the portal.
78
- */
79
- id?: string;
80
- }
81
-
82
- declare type ValueOf<T> = T[keyof T];
83
- declare namespace labels {
84
- export type TableProps = {
85
- ALIGN?: 'CENTER' | 'LEFT' | 'RIGHT';
86
- BGCOLOR?: AttributesValue;
87
- BORDER?: AttributesValue;
88
- CELLBORDER?: AttributesValue;
89
- CELLPADDING?: AttributesValue;
90
- CELLSPACING?: AttributesValue;
91
- COLOR?: AttributesValue;
92
- COLUMNS?: AttributesValue;
93
- FIXEDSIZE?: true;
94
- GRADIENTANGLE?: AttributesValue;
95
- HEIGHT?: AttributesValue;
96
- HREF?: AttributesValue;
97
- ID?: AttributesValue;
98
- PORT?: AttributesValue;
99
- ROWS?: AttributesValue;
100
- SIDES?: AttributesValue;
101
- STYLE?: AttributesValue;
102
- TARGET?: AttributesValue;
103
- TITLE?: AttributesValue;
104
- TOOLTIP?: AttributesValue;
105
- VALIGN?: 'MIDDLE' | 'BOTTOM' | 'TOP';
106
- WIDTH?: AttributesValue;
107
- };
108
- type NoAttributes = Record<string, unknown>;
109
- export type TrProps = NoAttributes;
110
- export type TdProps = {
111
- ALIGN?: 'CENTER' | 'LEFT' | 'RIGHT' | 'TEXT';
112
- BALIGN?: 'CENTER' | 'LEFT' | 'RIGHT';
113
- BGCOLOR?: AttributesValue;
114
- BORDER?: AttributesValue;
115
- CELLPADDING?: AttributesValue;
116
- CELLSPACING?: AttributesValue;
117
- COLOR?: AttributesValue;
118
- COLSPAN?: AttributesValue;
119
- FIXEDSIZE?: boolean;
120
- GRADIENTANGLE?: AttributesValue;
121
- HEIGHT?: AttributesValue;
122
- HREF?: AttributesValue;
123
- ID?: AttributesValue;
124
- PORT?: AttributesValue;
125
- ROWSPAN?: AttributesValue;
126
- SIDES?: AttributesValue;
127
- STYLE?: AttributesValue;
128
- TARGET?: AttributesValue;
129
- TITLE?: AttributesValue;
130
- TOOLTIP?: AttributesValue;
131
- VALIGN?: 'MIDDLE' | 'BOTTOM' | 'TOP';
132
- WIDTH?: AttributesValue;
133
- };
134
- export type FontProps = {
135
- COLOR?: AttributesValue;
136
- FACE?: AttributesValue;
137
- 'POINT-SIZE'?: AttributesValue;
138
- };
139
- export type BrProps = {
140
- ALIGN?: 'CENTER' | 'LEFT' | 'RIGHT';
141
- };
142
- export type ImgProps = {
143
- SCALE?: boolean | 'WIDTH' | 'HEIGHT' | 'BOTH';
144
- SRC?: AttributesValue;
145
- };
146
- export type IProps = NoAttributes;
147
- export type BProps = NoAttributes;
148
- export type UProps = NoAttributes;
149
- export type OProps = NoAttributes;
150
- export type SubProps = NoAttributes;
151
- export type SupProps = NoAttributes;
152
- export type SProps = NoAttributes;
153
- export type HrProps = NoAttributes;
154
- export type VrProps = NoAttributes;
155
- export {};
156
- }
157
- declare const DOT: Readonly<{
158
- readonly PORT: 'dot-port';
159
- readonly TABLE: 'dot-table';
160
- readonly TR: 'dot-tr';
161
- readonly TD: 'dot-td';
162
- readonly FONT: 'dot-font';
163
- readonly BR: 'dot-br';
164
- readonly IMG: 'dot-img';
165
- readonly I: 'dot-i';
166
- readonly B: 'dot-b';
167
- readonly U: 'dot-u';
168
- readonly O: 'dot-o';
169
- readonly SUB: 'dot-sub';
170
- readonly SUP: 'dot-sup';
171
- readonly S: 'dot-s';
172
- readonly HR: 'dot-hr';
173
- readonly VR: 'dot-vr';
174
- }>;
175
- declare type DOT = ValueOf<typeof DOT>;
176
- declare global {
177
- namespace JSX {
178
- interface IntrinsicElements {
179
- [DOT.PORT]: {
180
- children: string;
181
- };
182
- [DOT.TABLE]: React.PropsWithChildren<labels.TableProps>;
183
- [DOT.TR]: React.PropsWithChildren<labels.TrProps>;
184
- [DOT.TD]: React.PropsWithChildren<labels.TdProps>;
185
- [DOT.FONT]: React.PropsWithChildren<labels.FontProps>;
186
- [DOT.BR]: labels.BrProps;
187
- [DOT.IMG]: labels.ImgProps;
188
- [DOT.I]: React.PropsWithChildren<labels.IProps>;
189
- [DOT.B]: React.PropsWithChildren<labels.BProps>;
190
- [DOT.U]: React.PropsWithChildren<labels.UProps>;
191
- [DOT.O]: React.PropsWithChildren<labels.OProps>;
192
- [DOT.SUB]: React.PropsWithChildren<labels.SubProps>;
193
- [DOT.SUP]: React.PropsWithChildren<labels.SupProps>;
194
- [DOT.S]: React.PropsWithChildren<labels.SProps>;
195
- [DOT.HR]: labels.HrProps;
196
- [DOT.VR]: labels.VrProps;
197
- }
198
- }
199
- }
200
-
201
- /**
202
- * Return the cluster of container.
203
- */
204
- declare function useContainerCluster(): ICluster | null;
205
-
206
- /**
207
- * Hook to get the current cluster(Digraph, Graph or Subgraph).
208
- *
209
- * @throws If it is out of the context of Cluster, it throws an exception.
210
- */
211
- declare function useCurrentCluster(): ICluster;
212
-
213
- /**
214
- * `useDigraph` is a hook that creates an instance of Digraph
215
- * according to the object given by props.
216
- */
217
- declare function useDigraph(options?: RootClusterOptions): IRootCluster;
218
-
219
- /**
220
- * `useGraph` is a hook that creates an instance of Graph
221
- * according to the object given by props.
222
- */
223
- declare function useGraph(options?: RootClusterOptions): IRootCluster;
224
-
225
- /**
226
- * `useSubgraph` is a hook that creates an instance of Subgraph
227
- * according to the object given by props.
228
- */
229
- declare function useSubgraph(props?: SubgraphOptions): ISubgraph;
230
-
231
- /**
232
- * `useEdge` is a hook that creates an instance of Edge
233
- * according to the object given by props.
234
- */
235
- declare function useEdge(targets: EdgeTargetLikeTuple, props?: EdgeOptions): IEdge;
236
-
237
- /**
238
- * `useNode` is a hook that creates an instance of Node
239
- * according to the object given by props.
240
- */
241
- declare function useNode(id: string, options?: NodeOptions): INode;
242
-
243
- /**
244
- * `Graph` component.
245
- */
246
- declare const Graph: FC<RootClusterProps>;
247
-
248
- /**
249
- * `Digraph` component.
250
- */
251
- declare const Digraph: FC<RootClusterProps>;
252
-
253
- /**
254
- * `Subgraph` component.
255
- */
256
- declare const Subgraph: FC<SubgraphProps>;
257
-
258
- /**
259
- * `Node` component.
260
- */
261
- declare const Node: VFC<NodeProps>;
262
-
263
- /**
264
- * `Edge` component.
265
- */
266
- declare const Edge: VFC<EdgeProps>;
267
-
268
- /**
269
- * ClusterPortal component.
270
- */
271
- declare const ClusterPortal: FC<ClusterPortalProps>;
272
-
273
- /**
274
- * Convert the given element to Graphviz model.
275
- *
276
- * @example Example of giving a cluster as a container with the second argument.
277
- *
278
- * ```tsx
279
- * import React, { FC } from 'react';
280
- * import { digraph, toDot } from 'ts-graphviz';
281
- * import { Node, Subgraph, render, Edge } from '@ts-graphviz/react';
282
- *
283
- * const Example: FC = () => (
284
- * <>
285
- * <Node id="a" />
286
- *
287
- * <Subgraph id="my_cluster">
288
- * <Node id="b" />
289
- * </Subgraph>
290
- * <Edge targets={['b', 'a']} />
291
- * </>
292
- * );
293
- *
294
- * const G = digraph((g) => render(<Example />, g));
295
- * console.log(toDot(G));
296
- * // digraph {
297
- * // "a";
298
- * // subgraph "my_cluster" {
299
- * // "b";
300
- * // }
301
- * // "b" -> "a";
302
- * // }
303
- * ```
304
- */
305
- declare function render(element: ReactElement, container?: ICluster): ICluster;
306
- /**
307
- * Converts the given element to DOT language and returns it.
308
- *
309
- * @example
310
- *
311
- * ```tsx
312
- * import React, { FC } from 'react';
313
- * import { Digraph, Node, Subgraph, renderToDot, Edge } from '@ts-graphviz/react';
314
- *
315
- * const Example: FC = () => (
316
- * <Digraph>
317
- * <Node id="a" />
318
- * <Subgraph id="my_cluster">
319
- * <Node id="b" />
320
- * </Subgraph>
321
- * <Edge targets={['b', 'a']} />
322
- * </Digraph>
323
- * );
324
- *
325
- * const dot = renderToDot(<Example />);
326
- * console.log(dot);
327
- * // digraph {
328
- * // "a";
329
- * // subgraph "my_cluster" {
330
- * // "b";
331
- * // }
332
- * // "b" -> "a";
333
- * // }
334
- * ```
335
- *
336
- * @returns Rendered dot string
337
- */
338
- declare function renderToDot(element: ReactElement, container?: ICluster): string;
339
-
340
- export {
341
- ClusterCommonAttributesProps,
342
- ClusterPortal,
343
- ClusterPortalProps,
344
- DOT,
345
- Digraph,
346
- Edge,
347
- EdgeOptions,
348
- EdgeProps,
349
- Graph,
350
- Node,
351
- NodeOptions,
352
- NodeProps,
353
- RootClusterOptions,
354
- RootClusterProps,
355
- Subgraph,
356
- SubgraphOptions,
357
- SubgraphProps,
358
- labels,
359
- render,
360
- renderToDot,
361
- useContainerCluster,
362
- useCurrentCluster,
363
- useDigraph,
364
- useEdge,
365
- useGraph,
366
- useNode,
367
- useSubgraph,
368
- };
package/lib/index.js DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("ts-graphviz"),r=require("prop-types"),n=require("react-dom/server.js"),o=require("react-reconciler");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=a(e),i=a(r),l=a(o),p=Object.freeze({PORT:"dot-port",TABLE:"dot-table",TR:"dot-tr",TD:"dot-td",FONT:"dot-font",BR:"dot-br",IMG:"dot-img",I:"dot-i",B:"dot-b",U:"dot-u",O:"dot-o",SUB:"dot-sub",SUP:"dot-sup",S:"dot-s",HR:"dot-hr",VR:"dot-vr"}),d=u.default.createContext(null);function c(){return e.useContext(d)}d.displayName="ContainerCluster";var s=u.default.createContext(null);s.displayName="CurrentCluster";function f(){var t=e.useContext(s);if(null===t)throw Error("useCluster must be called within a cluster such as Digraph, Graph, Subgraph.");return t}function m(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}var v=u.default.createContext(null);function g(){var t=e.useContext(v);if(null===t)throw Error("Cannot call useGraphvizContext outside GraphvizContext.\nBasically, you need to use the render function provided by @ts-graphviz/react.");return t}function h(t,r,n){var o=n.edge,a=n.node,u=n.graph;e.useEffect((function(){t.clear(),t.apply(r)}),[t,r]),e.useEffect((function(){t.attributes.node.clear(),t.attributes.node.apply(null!=a?a:{})}),[t,a]),e.useEffect((function(){t.attributes.edge.clear(),t.attributes.edge.apply(null!=o?o:{})}),[t,o]),e.useEffect((function(){t.attributes.graph.clear(),t.attributes.graph.apply(null!=u?u:{})}),[t,u])}function y(t,r){e.useEffect((function(){t.comment=r}),[t,r])}function b(r){void 0===r&&(r={});var n=r.id,o=r.comment,a=r.edge,u=r.node,i=r.graph,l=m(r,["id","comment","edge","node","graph"]),p=g(),d=e.useMemo((function(){var e=new t.Digraph(n);return p.container=e,e.comment=o,e.apply(l),e.attributes.node.apply(null!=u?u:{}),e.attributes.edge.apply(null!=a?a:{}),e.attributes.graph.apply(null!=i?i:{}),e}),[p,n,o,a,u,i,l]);return y(d,o),h(d,l,{edge:a,node:u,graph:i}),e.useEffect((function(){return function(){p.container=void 0}}),[p]),d}function C(r){void 0===r&&(r={});var n=r.id,o=r.comment,a=r.edge,u=r.node,i=r.graph,l=m(r,["id","comment","edge","node","graph"]),p=g(),d=e.useMemo((function(){var e=new t.Graph(n);return p.container=e,e.comment=o,e.apply(l),e.attributes.node.apply(null!=u?u:{}),e.attributes.edge.apply(null!=a?a:{}),e.attributes.graph.apply(null!=i?i:{}),e}),[p,n,o,a,u,i,l]);return y(d,o),h(d,l,{edge:a,node:u,graph:i}),e.useEffect((function(){return function(){p.container=void 0}}),[p]),d}function x(r){void 0===r&&(r={});var n=r.id,o=r.comment,a=r.edge,u=r.node,i=r.graph,l=m(r,["id","comment","edge","node","graph"]),p=g(),d=f(),c=e.useMemo((function(){var e=new t.Subgraph(n);return null!==d?d.addSubgraph(e):p.container||(p.container=e),e.comment=o,e.apply(l),e.attributes.node.apply(null!=u?u:{}),e.attributes.edge.apply(null!=a?a:{}),e.attributes.graph.apply(null!=i?i:{}),e}),[p,d,n,o,a,u,i,l]);return y(c,o),h(c,l,{edge:a,node:u,graph:i}),e.useEffect((function(){return function(){d.removeSubgraph(c)}}),[d,c]),c}function E(t,r){e.useEffect((function(){t.attributes.clear(),t.attributes.apply(r)}),[t,r])}function T(t,r){void 0===r&&(r={});var n=r.comment,o=m(r,["comment"]),a=f();if(t.length<2)throw Error("Edges must have at least 2 targets.");var u=e.useMemo((function(){var e=a.createEdge(t);return e.comment=n,e.attributes.apply(o),e}),[a,t,n,o]);return y(u,n),E(u,o),e.useEffect((function(){return function(){a.removeEdge(u)}}),[a,u]),u}function P(t,r){void 0===r&&(r={});var n=r.comment,o=m(r,["comment"]),a=f(),u=e.useMemo((function(){var e=a.createNode(t);return e.attributes.apply(o),e.comment=n,e}),[a,t,o,n]);return y(u,n),E(u,o),e.useEffect((function(){return function(){a.removeNode(u)}}),[a,u]),u}function O(t){return e.useMemo((function(){return function(t){return e.isValidElement(t)?"<"+n.renderToStaticMarkup(t).replace(/<dot-port>(.+?)<\/dot-port>/gi,"<$1>").replace(/<(\/?)dot-([a-z-]+)/gi,(function(e,t,r){return"<"+t+r.toUpperCase()}))+">":t}(t)}),[t])}v.displayName="GraphvizContext";var w=u.default.createContext(new Map);function M(){return e.useContext(w)}w.displayName="ClusterMap";var D=function(t){var r=t.children,n=t.label,o=m(t,["children","label"]);if(null!==c())throw Error("RootCluster is duplicated.\nUse only one of Digraph and Graph.");var a=O(n);void 0!==a&&Object.assign(o,{label:a});var i=C(o),l=M();return e.useEffect((function(){void 0!==i.id&&l.set(i.id,i)}),[l,i]),u.default.createElement(d.Provider,{value:i},u.default.createElement(s.Provider,{value:i},r))};D.displayName="Graph",D.defaultProps={id:void 0,comment:void 0,label:void 0},D.propTypes={id:i.default.string,comment:i.default.string,label:i.default.oneOfType([i.default.element,i.default.string])};var N=function(t){var r=t.children,n=t.label,o=m(t,["children","label"]);if(null!==c())throw Error("RootCluster is duplicated.\nUse only one of Digraph and Graph.");var a=O(n);void 0!==a&&Object.assign(o,{label:a});var i=b(o),l=M();return e.useEffect((function(){void 0!==i.id&&l.set(i.id,i)}),[l,i]),u.default.createElement(d.Provider,{value:i},u.default.createElement(s.Provider,{value:i},r))};N.displayName="Digraph",N.defaultProps={id:void 0,comment:void 0,label:void 0},N.propTypes={id:i.default.string,comment:i.default.string,label:i.default.oneOfType([i.default.element,i.default.string])};var S=function(t){var r=t.children,n=t.label,o=m(t,["children","label"]),a=O(n);void 0!==a&&Object.assign(o,{label:a});var i=x(o),l=M();return e.useEffect((function(){void 0!==i.id&&l.set(i.id,i)}),[i,l]),u.default.createElement(s.Provider,{value:i},r)};S.displayName="Subgraph",S.propTypes={id:i.default.string,comment:i.default.string,label:i.default.oneOfType([i.default.element,i.default.string])},S.defaultProps={id:void 0,comment:void 0,label:void 0};var j=function(e){var t=e.id,r=e.label,n=e.xlabel,o=m(e,["id","label","xlabel"]),a=O(r),u=O(n);return void 0!==a&&Object.assign(o,{label:a}),void 0!==u&&Object.assign(o,{xlabel:u}),P(t,o),null};j.displayName="Node",j.propTypes={id:i.default.string.isRequired,comment:i.default.string,label:i.default.oneOfType([i.default.element,i.default.string]),xlabel:i.default.oneOfType([i.default.element,i.default.string])},j.defaultProps={comment:void 0,label:void 0,xlabel:void 0};var G=function(e){var t=e.targets,r=e.label,n=m(e,["targets","label"]),o=O(r);return void 0!==o&&Object.assign(n,{label:o}),T(t,n),null};G.displayName="Edge",G.propTypes={targets:i.default.array.isRequired,comment:i.default.string,label:i.default.oneOfType([i.default.element,i.default.string])},G.defaultProps={comment:void 0,label:void 0};var R=function(t){var r=t.children,n=t.id,o=c(),a=e.useContext(w),i=e.useMemo((function(){var e;return n&&null!==(e=a.get(n))&&void 0!==e?e:o}),[o,a,n]);return u.default.createElement(s.Provider,{value:i},r)};R.displayName="ClusterPortal",R.defaultProps={id:void 0},R.propTypes={id:i.default.string};var z=function(){function e(){this.now=Date.now,this.setTimeout=setTimeout,this.clearTimeout=clearTimeout,this.noTimeout=-1,this.isPrimaryRenderer=!1,this.supportsMutation=!1,this.supportsPersistence=!1,this.supportsHydration=!1}return e.prototype.preparePortalMount=function(e){},e.prototype.scheduleTimeout=function(e,t){},e.prototype.cancelTimeout=function(e){},e.prototype.queueMicrotask=function(e){},e.prototype.getPublicInstance=function(e){return e},e.prototype.getRootHostContext=function(e){return{}},e.prototype.getChildHostContext=function(e,t,r){return e},e.prototype.prepareForCommit=function(e){return null},e.prototype.resetAfterCommit=function(e){},e.prototype.createInstance=function(e,t,r,n,o){return e(t)},e.prototype.appendInitialChild=function(e,t){e.appendChild(t)},e.prototype.finalizeInitialChildren=function(e,t,r,n,o){return!1},e.prototype.prepareUpdate=function(e,t,r,n,o,a){return{}},e.prototype.shouldSetTextContent=function(e,t){return!1},e.prototype.shouldDeprioritizeSubtree=function(e,t){return!1},e.prototype.createTextInstance=function(e,t,r,n){return e},e.prototype.scheduleDeferredCallback=function(e,t){},e.prototype.cancelDeferredCallback=function(e){},e.prototype.appendChild=function(e,t){e.appendChild&&e.appendChild(t)},e.prototype.appendChildToContainer=function(e,t){},e.prototype.commitTextUpdate=function(e,t,r){},e.prototype.commitMount=function(e,t,r,n){},e.prototype.commitUpdate=function(e,t,r,n,o,a){},e.prototype.insertBefore=function(e,t,r){},e.prototype.insertInContainerBefore=function(e,t,r){},e.prototype.removeChild=function(e,t){},e.prototype.removeChildFromContainer=function(e,t){},e.prototype.resetTextContent=function(e){},e}(),I=l.default(new z),U=function(){};function q(e,t){return void 0===t&&(t=new Map),e&&(e.id&&t.set(e.id,e),e.subgraphs.forEach((function(e){return q(e,t)}))),t}function B(t,r){var n={container:r};if(I.updateContainer(e.createElement(v.Provider,{value:n},e.createElement(w.Provider,{value:q(r)},e.createElement(d.Provider,{value:null!=r?r:null},r?e.createElement(s.Provider,{value:r},t):t))),I.createContainer({},0,!1,null),null,U),!n.container)throw Error("There are no clusters of container(Subgraph, Digraph, Graph).");return n.container}exports.ClusterPortal=R,exports.DOT=p,exports.Digraph=N,exports.Edge=G,exports.Graph=D,exports.Node=j,exports.Subgraph=S,exports.render=B,exports.renderToDot=function(e,r){return t.toDot(B(e,r))},exports.useContainerCluster=c,exports.useCurrentCluster=f,exports.useDigraph=b,exports.useEdge=T,exports.useGraph=C,exports.useNode=P,exports.useSubgraph=x;
package/lib/index.mjs DELETED
@@ -1 +0,0 @@
1
- import e,{useContext as t,useEffect as r,useMemo as n,isValidElement as o,createElement as i}from"react";import{Digraph as a,Graph as u,Subgraph as l,toDot as p}from"ts-graphviz";import c from"prop-types";import{renderToStaticMarkup as d}from"react-dom/server.js";import s from"react-reconciler";var f=Object.freeze({PORT:"dot-port",TABLE:"dot-table",TR:"dot-tr",TD:"dot-td",FONT:"dot-font",BR:"dot-br",IMG:"dot-img",I:"dot-i",B:"dot-b",U:"dot-u",O:"dot-o",SUB:"dot-sub",SUP:"dot-sup",S:"dot-s",HR:"dot-hr",VR:"dot-vr"}),m=e.createContext(null);function v(){return t(m)}m.displayName="ContainerCluster";var y=e.createContext(null);y.displayName="CurrentCluster";function g(){var e=t(y);if(null===e)throw Error("useCluster must be called within a cluster such as Digraph, Graph, Subgraph.");return e}function h(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}var b=e.createContext(null);function C(){var e=t(b);if(null===e)throw Error("Cannot call useGraphvizContext outside GraphvizContext.\nBasically, you need to use the render function provided by @ts-graphviz/react.");return e}function T(e,t,n){var o=n.edge,i=n.node,a=n.graph;r((function(){e.clear(),e.apply(t)}),[e,t]),r((function(){e.attributes.node.clear(),e.attributes.node.apply(null!=i?i:{})}),[e,i]),r((function(){e.attributes.edge.clear(),e.attributes.edge.apply(null!=o?o:{})}),[e,o]),r((function(){e.attributes.graph.clear(),e.attributes.graph.apply(null!=a?a:{})}),[e,a])}function P(e,t){r((function(){e.comment=t}),[e,t])}function O(e){void 0===e&&(e={});var t=e.id,o=e.comment,i=e.edge,u=e.node,l=e.graph,p=h(e,["id","comment","edge","node","graph"]),c=C(),d=n((function(){var e=new a(t);return c.container=e,e.comment=o,e.apply(p),e.attributes.node.apply(null!=u?u:{}),e.attributes.edge.apply(null!=i?i:{}),e.attributes.graph.apply(null!=l?l:{}),e}),[c,t,o,i,u,l,p]);return P(d,o),T(d,p,{edge:i,node:u,graph:l}),r((function(){return function(){c.container=void 0}}),[c]),d}function x(e){void 0===e&&(e={});var t=e.id,o=e.comment,i=e.edge,a=e.node,l=e.graph,p=h(e,["id","comment","edge","node","graph"]),c=C(),d=n((function(){var e=new u(t);return c.container=e,e.comment=o,e.apply(p),e.attributes.node.apply(null!=a?a:{}),e.attributes.edge.apply(null!=i?i:{}),e.attributes.graph.apply(null!=l?l:{}),e}),[c,t,o,i,a,l,p]);return P(d,o),T(d,p,{edge:i,node:a,graph:l}),r((function(){return function(){c.container=void 0}}),[c]),d}function E(e){void 0===e&&(e={});var t=e.id,o=e.comment,i=e.edge,a=e.node,u=e.graph,p=h(e,["id","comment","edge","node","graph"]),c=C(),d=g(),s=n((function(){var e=new l(t);return null!==d?d.addSubgraph(e):c.container||(c.container=e),e.comment=o,e.apply(p),e.attributes.node.apply(null!=a?a:{}),e.attributes.edge.apply(null!=i?i:{}),e.attributes.graph.apply(null!=u?u:{}),e}),[c,d,t,o,i,a,u,p]);return P(s,o),T(s,p,{edge:i,node:a,graph:u}),r((function(){return function(){d.removeSubgraph(s)}}),[d,s]),s}function w(e,t){r((function(){e.attributes.clear(),e.attributes.apply(t)}),[e,t])}function N(e,t){void 0===t&&(t={});var o=t.comment,i=h(t,["comment"]),a=g();if(e.length<2)throw Error("Edges must have at least 2 targets.");var u=n((function(){var t=a.createEdge(e);return t.comment=o,t.attributes.apply(i),t}),[a,e,o,i]);return P(u,o),w(u,i),r((function(){return function(){a.removeEdge(u)}}),[a,u]),u}function S(e,t){void 0===t&&(t={});var o=t.comment,i=h(t,["comment"]),a=g(),u=n((function(){var t=a.createNode(e);return t.attributes.apply(i),t.comment=o,t}),[a,e,i,o]);return P(u,o),w(u,i),r((function(){return function(){a.removeNode(u)}}),[a,u]),u}function j(e){return n((function(){return function(e){return o(e)?"<"+d(e).replace(/<dot-port>(.+?)<\/dot-port>/gi,"<$1>").replace(/<(\/?)dot-([a-z-]+)/gi,(function(e,t,r){return"<"+t+r.toUpperCase()}))+">":e}(e)}),[e])}b.displayName="GraphvizContext";var D=e.createContext(new Map);function R(){return t(D)}D.displayName="ClusterMap";var G=function(t){var n=t.children,o=t.label,i=h(t,["children","label"]);if(null!==v())throw Error("RootCluster is duplicated.\nUse only one of Digraph and Graph.");var a=j(o);void 0!==a&&Object.assign(i,{label:a});var u=x(i),l=R();return r((function(){void 0!==u.id&&l.set(u.id,u)}),[l,u]),e.createElement(m.Provider,{value:u},e.createElement(y.Provider,{value:u},n))};G.displayName="Graph",G.defaultProps={id:void 0,comment:void 0,label:void 0},G.propTypes={id:c.string,comment:c.string,label:c.oneOfType([c.element,c.string])};var z=function(t){var n=t.children,o=t.label,i=h(t,["children","label"]);if(null!==v())throw Error("RootCluster is duplicated.\nUse only one of Digraph and Graph.");var a=j(o);void 0!==a&&Object.assign(i,{label:a});var u=O(i),l=R();return r((function(){void 0!==u.id&&l.set(u.id,u)}),[l,u]),e.createElement(m.Provider,{value:u},e.createElement(y.Provider,{value:u},n))};z.displayName="Digraph",z.defaultProps={id:void 0,comment:void 0,label:void 0},z.propTypes={id:c.string,comment:c.string,label:c.oneOfType([c.element,c.string])};var I=function(t){var n=t.children,o=t.label,i=h(t,["children","label"]),a=j(o);void 0!==a&&Object.assign(i,{label:a});var u=E(i),l=R();return r((function(){void 0!==u.id&&l.set(u.id,u)}),[u,l]),e.createElement(y.Provider,{value:u},n)};I.displayName="Subgraph",I.propTypes={id:c.string,comment:c.string,label:c.oneOfType([c.element,c.string])},I.defaultProps={id:void 0,comment:void 0,label:void 0};var U=function(e){var t=e.id,r=e.label,n=e.xlabel,o=h(e,["id","label","xlabel"]),i=j(r),a=j(n);return void 0!==i&&Object.assign(o,{label:i}),void 0!==a&&Object.assign(o,{xlabel:a}),S(t,o),null};U.displayName="Node",U.propTypes={id:c.string.isRequired,comment:c.string,label:c.oneOfType([c.element,c.string]),xlabel:c.oneOfType([c.element,c.string])},U.defaultProps={comment:void 0,label:void 0,xlabel:void 0};var M=function(e){var t=e.targets,r=e.label,n=h(e,["targets","label"]),o=j(r);return void 0!==o&&Object.assign(n,{label:o}),N(t,n),null};M.displayName="Edge",M.propTypes={targets:c.array.isRequired,comment:c.string,label:c.oneOfType([c.element,c.string])},M.defaultProps={comment:void 0,label:void 0};var B=function(r){var o=r.children,i=r.id,a=v(),u=t(D),l=n((function(){var e;return i&&null!==(e=u.get(i))&&void 0!==e?e:a}),[a,u,i]);return e.createElement(y.Provider,{value:l},o)};B.displayName="ClusterPortal",B.defaultProps={id:void 0},B.propTypes={id:c.string};var H=s(new(function(){function e(){this.now=Date.now,this.setTimeout=setTimeout,this.clearTimeout=clearTimeout,this.noTimeout=-1,this.isPrimaryRenderer=!1,this.supportsMutation=!1,this.supportsPersistence=!1,this.supportsHydration=!1}return e.prototype.preparePortalMount=function(e){},e.prototype.scheduleTimeout=function(e,t){},e.prototype.cancelTimeout=function(e){},e.prototype.queueMicrotask=function(e){},e.prototype.getPublicInstance=function(e){return e},e.prototype.getRootHostContext=function(e){return{}},e.prototype.getChildHostContext=function(e,t,r){return e},e.prototype.prepareForCommit=function(e){return null},e.prototype.resetAfterCommit=function(e){},e.prototype.createInstance=function(e,t,r,n,o){return e(t)},e.prototype.appendInitialChild=function(e,t){e.appendChild(t)},e.prototype.finalizeInitialChildren=function(e,t,r,n,o){return!1},e.prototype.prepareUpdate=function(e,t,r,n,o,i){return{}},e.prototype.shouldSetTextContent=function(e,t){return!1},e.prototype.shouldDeprioritizeSubtree=function(e,t){return!1},e.prototype.createTextInstance=function(e,t,r,n){return e},e.prototype.scheduleDeferredCallback=function(e,t){},e.prototype.cancelDeferredCallback=function(e){},e.prototype.appendChild=function(e,t){e.appendChild&&e.appendChild(t)},e.prototype.appendChildToContainer=function(e,t){},e.prototype.commitTextUpdate=function(e,t,r){},e.prototype.commitMount=function(e,t,r,n){},e.prototype.commitUpdate=function(e,t,r,n,o,i){},e.prototype.insertBefore=function(e,t,r){},e.prototype.insertInContainerBefore=function(e,t,r){},e.prototype.removeChild=function(e,t){},e.prototype.removeChildFromContainer=function(e,t){},e.prototype.resetTextContent=function(e){},e}())),k=function(){};function q(e,t){return void 0===t&&(t=new Map),e&&(e.id&&t.set(e.id,e),e.subgraphs.forEach((function(e){return q(e,t)}))),t}function F(e,t){var r={container:t};if(H.updateContainer(i(b.Provider,{value:r},i(D.Provider,{value:q(t)},i(m.Provider,{value:null!=t?t:null},t?i(y.Provider,{value:t},e):e))),H.createContainer({},0,!1,null),null,k),!r.container)throw Error("There are no clusters of container(Subgraph, Digraph, Graph).");return r.container}function A(e,t){return p(F(e,t))}export{B as ClusterPortal,f as DOT,z as Digraph,M as Edge,G as Graph,U as Node,I as Subgraph,F as render,A as renderToDot,v as useContainerCluster,g as useCurrentCluster,O as useDigraph,N as useEdge,x as useGraph,S as useNode,E as useSubgraph};
package/rollup.config.js DELETED
@@ -1,55 +0,0 @@
1
- import typescript from 'rollup-plugin-typescript2';
2
- import del from 'rollup-plugin-delete';
3
- import dts from 'rollup-plugin-dts';
4
- import { terser } from 'rollup-plugin-terser';
5
-
6
- /** @type {import('rollup').RollupOptions[]} */
7
- const options = [
8
- {
9
- input: './src/index.ts',
10
- plugins: [
11
- typescript({
12
- tsconfigOverride: {
13
- compilerOptions: {
14
- module: 'ESNext',
15
- declaration: true,
16
- },
17
- },
18
- }),
19
- terser({
20
- format: {
21
- comments: false,
22
- },
23
- }),
24
- ],
25
- external: ['react', 'react-dom/server.js', 'ts-graphviz', 'prop-types', 'react-reconciler'],
26
- output: [
27
- {
28
- format: 'cjs',
29
- file: './lib/index.js',
30
- },
31
- {
32
- format: 'esm',
33
- file: './lib/index.mjs',
34
- },
35
- ],
36
- },
37
- {
38
- input: './lib/index.d.ts',
39
- plugins: [
40
- del({
41
- targets: ['lib/**/*.d.ts', '!lib/index.d.ts'],
42
- hook: 'buildEnd',
43
- }),
44
- dts(),
45
- ],
46
- output: [
47
- {
48
- format: 'esm',
49
- file: './lib/index.d.ts',
50
- },
51
- ],
52
- },
53
- ];
54
-
55
- export default options;