@ts-graphviz/react 0.0.0-next-20240317150638

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 (55) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/LICENSE +22 -0
  3. package/README.md +104 -0
  4. package/example/example.svg +40 -0
  5. package/example/example.tsx +41 -0
  6. package/lib/react.cjs +457 -0
  7. package/lib/react.d.ts +230 -0
  8. package/lib/react.js +457 -0
  9. package/package.json +71 -0
  10. package/src/components/Digraph.spec.tsx +18 -0
  11. package/src/components/Digraph.tsx +41 -0
  12. package/src/components/Edge.tsx +17 -0
  13. package/src/components/Graph.spec.tsx +18 -0
  14. package/src/components/Graph.tsx +36 -0
  15. package/src/components/GraphPortal.tsx +22 -0
  16. package/src/components/Node.spec.tsx +101 -0
  17. package/src/components/Node.tsx +21 -0
  18. package/src/components/Subgraph.tsx +30 -0
  19. package/src/contexts/CurrentGraph.ts +5 -0
  20. package/src/contexts/GraphContainer.ts +5 -0
  21. package/src/contexts/GraphMap.ts +5 -0
  22. package/src/contexts/GraphvizContext.ts +11 -0
  23. package/src/hooks/__tests__/wrapper.tsx +58 -0
  24. package/src/hooks/useCurrentGraph.spec.ts +56 -0
  25. package/src/hooks/useCurrentGraph.ts +18 -0
  26. package/src/hooks/useDigraph.spec.ts +15 -0
  27. package/src/hooks/useDigraph.ts +33 -0
  28. package/src/hooks/useEdge.spec.ts +46 -0
  29. package/src/hooks/useEdge.ts +35 -0
  30. package/src/hooks/useGraph.spec.ts +15 -0
  31. package/src/hooks/useGraph.ts +33 -0
  32. package/src/hooks/useGraphAttributes.ts +32 -0
  33. package/src/hooks/useGraphContainer.spec.ts +45 -0
  34. package/src/hooks/useGraphContainer.ts +10 -0
  35. package/src/hooks/useGraphMap.ts +7 -0
  36. package/src/hooks/useGraphvizContext.spec.ts +26 -0
  37. package/src/hooks/useGraphvizContext.ts +16 -0
  38. package/src/hooks/useHasAttributes.ts +16 -0
  39. package/src/hooks/useHasComment.ts +8 -0
  40. package/src/hooks/useNode.spec.ts +16 -0
  41. package/src/hooks/useNode.ts +29 -0
  42. package/src/hooks/useRenderedID.spec.tsx +28 -0
  43. package/src/hooks/useRenderedID.ts +6 -0
  44. package/src/hooks/useSubgraph.spec.ts +41 -0
  45. package/src/hooks/useSubgraph.ts +39 -0
  46. package/src/react.ts +16 -0
  47. package/src/reconciler.ts +272 -0
  48. package/src/render.test.tsx +71 -0
  49. package/src/render.ts +142 -0
  50. package/src/renderHTMLLike.ts +9 -0
  51. package/src/renderId.ts +9 -0
  52. package/src/types.ts +107 -0
  53. package/tsconfig.json +8 -0
  54. package/typedoc.json +5 -0
  55. package/vite.config.ts +31 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,76 @@
1
+ # @ts-graphviz/react
2
+
3
+ ## 0.0.0-next-20240317150638
4
+
5
+ ### Minor Changes
6
+
7
+ - [#992](https://github.com/ts-graphviz/ts-graphviz/pull/992) [`391e98e`](https://github.com/ts-graphviz/ts-graphviz/commit/391e98edf70bb43c1feb4a00f832fa9d96dd9d39) Thanks [@kamiazya](https://github.com/kamiazya)! - ## `@ts-graphviz/react` integrate with ts-graphviz monorepo
8
+
9
+ ### Overview
10
+
11
+ - Imported source code from `@ts-graphviz/react` repository and integrated it into the monorepo.
12
+ - Emphasized code quality through component tests and updated function signatures.
13
+ - Renamed functions and types for readability and consistency throughout the ts-graphviz project.
14
+
15
+ ### Dependencies
16
+
17
+ - Support React 18 and remove `prop-types` as a dependency.
18
+ - `prop-types` is removed because TypeScript can cover the same functionality.
19
+ - Moved `react-dom` to `peerDependencies` for streamlined dependency management.
20
+ - Improved file naming conventions for better codebase organization.
21
+
22
+ ### New Features
23
+
24
+ #### New HTMLLike label syntax
25
+
26
+ ```tsx
27
+ import { Digraph, Node, Edge, render } from "@ts-graphviz/react";
28
+
29
+ const dot = render(
30
+ <Digraph>
31
+ <Node
32
+ id="A"
33
+ label={
34
+ <dot:table>
35
+ <dot:tr>
36
+ <dot:td>left</dot:td>
37
+ <dot:td>right</dot:td>
38
+ </dot:tr>
39
+ </dot:table>
40
+ }
41
+ />
42
+ </Digraph>
43
+ );
44
+ ```
45
+
46
+ #### `renderHTMLLike` function
47
+
48
+ The `renderHTMLLike` function is introduced for rendering HTML-like labels.
49
+
50
+ ```tsx
51
+ import { renderHTMLLike } from "@ts-graphviz/react";
52
+
53
+ const htmlLike = renderHTMLLike(
54
+ <dot:table>
55
+ <dot:tr>
56
+ <dot:td>left</dot:td>
57
+ <dot:td>right</dot:td>
58
+ </dot:tr>
59
+ </dot:table>
60
+ );
61
+ ```
62
+
63
+ ### Other Changes
64
+
65
+ - Added the `provenance` flag in `package.json` for enhanced publishing traceability.
66
+ - Enhanced TypeScript support and type definitions, including moving types to `@ts-graphviz/common`.
67
+
68
+ - Move HTMLLike type to `@ts-graphviz/common`.
69
+
70
+ - Refactor JSX syntax for better compatibility and custom JSX-like syntax for HTMLLike.
71
+
72
+ ### Patch Changes
73
+
74
+ - Updated dependencies [[`cb5517a`](https://github.com/ts-graphviz/ts-graphviz/commit/cb5517a0236ce33527d200df9770390f4eb40064), [`0589b4f`](https://github.com/ts-graphviz/ts-graphviz/commit/0589b4f8849290d2c4a39beceb9b633f059f2e3f), [`5ce6b59`](https://github.com/ts-graphviz/ts-graphviz/commit/5ce6b59fa395bc344de2bfb15061b158a9ea5586), [`122336b`](https://github.com/ts-graphviz/ts-graphviz/commit/122336bede1033f73a2a94c82d499fda238f6b2e), [`b5f36fa`](https://github.com/ts-graphviz/ts-graphviz/commit/b5f36faf9cf70dfc263130c4480dc21770475c5a), [`c55f2d0`](https://github.com/ts-graphviz/ts-graphviz/commit/c55f2d0dfa851d318cc16a36499c69c0a34f1588), [`81a50ff`](https://github.com/ts-graphviz/ts-graphviz/commit/81a50ff94b461f44256f2eea5b86af5eb26afd94), [`a16f047`](https://github.com/ts-graphviz/ts-graphviz/commit/a16f047dfdd5db73f3e25847cf3fb2f8075aaf11), [`391e98e`](https://github.com/ts-graphviz/ts-graphviz/commit/391e98edf70bb43c1feb4a00f832fa9d96dd9d39), [`a16f047`](https://github.com/ts-graphviz/ts-graphviz/commit/a16f047dfdd5db73f3e25847cf3fb2f8075aaf11), [`a16f047`](https://github.com/ts-graphviz/ts-graphviz/commit/a16f047dfdd5db73f3e25847cf3fb2f8075aaf11)]:
75
+ - ts-graphviz@0.0.0-next-20240317150638
76
+ - @ts-graphviz/common@0.0.0-next-20240317150638
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2019-2024 Yuki Yamazaki
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # @ts-graphviz/react
2
+
3
+ > It is part of the ts-graphviz library, which is split into modular packages to improve maintainability, flexibility, and ease of use.
4
+
5
+ Graphviz-dot Renderer using React.
6
+
7
+ ## Installation
8
+
9
+ The module can then be installed using [npm](https://www.npmjs.com/):
10
+
11
+ [![NPM](https://nodei.co/npm/@ts-graphviz/react.png)](https://nodei.co/npm/@ts-graphviz/react/)
12
+
13
+ ```bash
14
+ # yarn
15
+ $ yarn add @ts-graphviz/react react react-dom
16
+ # or npm
17
+ $ npm install -S @ts-graphviz/react react react-dom
18
+ ```
19
+
20
+ > Install [React and React DOM](https://github.com/facebook/react/) as peerDependencies at the same time.
21
+
22
+ ## Example
23
+
24
+ ```jsx
25
+ import { Digraph, Node, Subgraph, Edge, renderToDot } from '@ts-graphviz/react';
26
+
27
+ const Example = () => (
28
+ <Digraph
29
+ rankdir="TB"
30
+ edge={{
31
+ color: 'blue',
32
+ fontcolor: 'blue',
33
+ }}
34
+ node={{
35
+ shape: 'none',
36
+ }}
37
+ >
38
+ <Node
39
+ id="nodeA"
40
+ shape="none"
41
+ label={
42
+ <dot:table border="0" cellborder="1" cellspacing="0">
43
+ <dot:tr>
44
+ <dot:td>left</dot:td>
45
+ <dot:td port="m">middle</dot:td>
46
+ <dot:td port="r">right</dot:td>
47
+ </dot:tr>
48
+ </dot:table>
49
+ }
50
+ />
51
+
52
+ <Subgraph id="cluster" label="Cluster" labeljust="l">
53
+ <Node id="nodeB" label="This is label for nodeB." />
54
+ </Subgraph>
55
+ <Edge targets={['nodeB', 'nodeA:m']} comment="Edge from node A to B" label={<dot:b>A to B</dot:b>} />
56
+ </Digraph>
57
+ );
58
+
59
+ const dot = renderToDot(<Example />);
60
+
61
+ console.log(dot);
62
+ ```
63
+
64
+ ### Output dot
65
+
66
+ ```dot
67
+ digraph {
68
+ rankdir = "TB";
69
+ edge [
70
+ color = "blue";
71
+ fontcolor = "blue";
72
+ ];
73
+ node [
74
+ shape = "none";
75
+ ];
76
+ "nodeA" [
77
+ shape = "none";
78
+ label = <<table border="0" cellborder="1" cellSpacing="0"><tr><td>left</td><td port="m">middle</td><td port="r">right</td></tr></table>>;
79
+ ];
80
+ subgraph "cluster" {
81
+ labeljust = "l";
82
+ label = "Cluster";
83
+ "nodeB" [
84
+ label = "This is label for nodeB.";
85
+ ];
86
+ }
87
+ // Edge from node A to B
88
+ "nodeB" -> "nodeA":"m" [
89
+ label = <<b>A to B</b>>;
90
+ ];
91
+ }
92
+ ```
93
+
94
+ ![dot](./example/example.svg)
95
+
96
+ ## Contributing
97
+
98
+ Contributions to the ts-graphviz project are welcome.
99
+
100
+ Please refer to the main ts-graphviz repository for guidelines on how to contribute.
101
+
102
+ ## License
103
+
104
+ This software is released under the MIT License.
@@ -0,0 +1,40 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
3
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
+ <!-- Generated by graphviz version 2.42.3 (20191010.1750)
5
+ -->
6
+ <!-- Title: %3 Pages: 1 -->
7
+ <svg width="188pt" height="168pt"
8
+ viewBox="0.00 0.00 188.00 168.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
9
+ <g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 164)">
10
+ <title>%3</title>
11
+ <polygon fill="white" stroke="transparent" points="-4,4 -4,-164 184,-164 184,4 -4,4"/>
12
+ <g id="clust1" class="cluster">
13
+ <title>cluster</title>
14
+ <polygon fill="none" stroke="black" points="8,-78 8,-152 172,-152 172,-78 8,-78"/>
15
+ <text text-anchor="middle" x="36.22" y="-136.8" font-family="Times,serif" font-size="14.00">Cluster</text>
16
+ </g>
17
+ <!-- nodeA -->
18
+ <g id="node1" class="node">
19
+ <title>nodeA</title>
20
+ <polygon fill="none" stroke="black" points="44,-8 44,-28 68,-28 68,-8 44,-8"/>
21
+ <text text-anchor="start" x="46.67" y="-13.8" font-family="Times,serif" font-size="14.00">left</text>
22
+ <polygon fill="none" stroke="black" points="68,-8 68,-28 112,-28 112,-8 68,-8"/>
23
+ <text text-anchor="start" x="70.56" y="-13.8" font-family="Times,serif" font-size="14.00">middle</text>
24
+ <polygon fill="none" stroke="black" points="112,-8 112,-28 144,-28 144,-8 112,-8"/>
25
+ <text text-anchor="start" x="114.78" y="-13.8" font-family="Times,serif" font-size="14.00">right</text>
26
+ </g>
27
+ <!-- nodeB -->
28
+ <g id="node2" class="node">
29
+ <title>nodeB</title>
30
+ <text text-anchor="middle" x="90" y="-99.8" font-family="Times,serif" font-size="14.00">This is label for nodeB.</text>
31
+ </g>
32
+ <!-- nodeB&#45;&gt;nodeA -->
33
+ <g id="edge1" class="edge">
34
+ <title>nodeB&#45;&gt;nodeA:m</title>
35
+ <path fill="none" stroke="blue" d="M90,-85.95C90,-73.53 90,-56.02 90,-39.27"/>
36
+ <polygon fill="blue" stroke="blue" points="93.5,-39 90,-29 86.5,-39 93.5,-39"/>
37
+ <text text-anchor="start" x="90" y="-57.8" font-family="Times,serif" font-weight="bold" font-size="14.00" fill="blue">A to B</text>
38
+ </g>
39
+ </g>
40
+ </svg>
@@ -0,0 +1,41 @@
1
+ import { Digraph, Edge, Node, Subgraph, renderToDot } from '@ts-graphviz/react';
2
+
3
+ const Example = () => (
4
+ <Digraph
5
+ rankdir="TB"
6
+ edge={{
7
+ color: 'blue',
8
+ fontcolor: 'blue',
9
+ }}
10
+ node={{
11
+ shape: 'none',
12
+ }}
13
+ >
14
+ <Node
15
+ id="nodeA"
16
+ shape="none"
17
+ label={
18
+ <dot:table border={0} cellborder={1} cellSpacing={0}>
19
+ <dot:tr>
20
+ <dot:td>left</dot:td>
21
+ <dot:td port="m">middle</dot:td>
22
+ <dot:td port="r">right</dot:td>
23
+ </dot:tr>
24
+ </dot:table>
25
+ }
26
+ />
27
+
28
+ <Subgraph id="cluster" label="Cluster" labeljust="l">
29
+ <Node id="nodeB" label="This is label for nodeB." />
30
+ </Subgraph>
31
+ <Edge
32
+ targets={['nodeB', 'nodeA:m']}
33
+ comment="Edge from node A to B"
34
+ label={<dot:b>A to B</dot:b>}
35
+ />
36
+ </Digraph>
37
+ );
38
+
39
+ const dot = renderToDot(<Example />);
40
+
41
+ console.log(dot);