Skip to content
This repository was archived by the owner on Mar 17, 2024. It is now read-only.

Commit 4d49bd7

Browse files
committed
update README and fix build settings
1 parent bfec287 commit 4d49bd7

File tree

5 files changed

+57
-22
lines changed

5 files changed

+57
-22
lines changed

.gitignore

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,7 @@ Temporary Items
131131
# End of https://www.gitignore.io/api/macos
132132

133133
# Output Modules
134-
lib
135-
lib.js
136-
lib.mjs
137-
web.js
138-
web.mjs
134+
core
135+
web
139136
docs
140137
*.d.ts

README.md

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,30 @@ $ npm install @ts-graphviz/react
1919

2020
- [React](https://github.com/facebook/react/)(>=16.8)
2121
- [ts-graphviz](https://github.com/ts-graphviz/ts-graphviz)
22+
- [@hpcc-js/wasm](https://www.npmjs.com/package/@hpcc-js/wasm) (Optional)
2223

2324
```bash
25+
# Peer Dependencies
2426
$ yarn add react ts-graphviz
27+
# Optional Peer Dependencies
28+
$ yarn add @hpcc-js/wasm
2529
```
2630

27-
## Usage
31+
## API
2832

29-
### Example
33+
### Core Module
34+
35+
The core is designed to be independent of the execution environment.
36+
37+
It is designed to work in both browsers and Node.js.
38+
39+
It provides core components and hooks of `@ts-graphviz/react` and render functions.
3040

3141
#### Script
3242

3343
```tsx
3444
import React, { FC } from 'react';
35-
import { Digraph, Node, Subgraph, renderToDot, Edge, DOT } from '@ts-graphviz/react';
45+
import { Digraph, Node, Subgraph, Edge, DOT, renderToDot } from '@ts-graphviz/react';
3646

3747
const Example: FC = () => (
3848
<Digraph
@@ -87,7 +97,6 @@ digraph {
8797
shape = "none",
8898
label = <<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"><TR><TD>left</TD><TD PORT="m">middle</TD><TD PORT="r">right</TD></TR></TABLE>>,
8999
];
90-
"nodeB";
91100
subgraph "cluster" {
92101
labeljust = "l";
93102
label = "Cluster";
@@ -104,6 +113,38 @@ digraph {
104113

105114
![dot](./example/example.svg)
106115

116+
### Web Module
117+
118+
The `Graphviz` component of `@ts-graphviz/react/web` can be rendered directly in the browser.
119+
120+
Since this component uses the function of `@hpcc-js/wasm` internally, it is necessary to host `@hpcc-js/wasm/dist/graphviz.wasm` and specify its directory with `wasmFolder`.
121+
122+
For development, I recommend using the one hosted by unpkg.
123+
124+
```tsx
125+
import React, { FC } from 'react';
126+
import ReactDOM from 'react-dom';
127+
import { Digraph, Node, Edge } from '@ts-graphviz/react';
128+
import { Graphviz } from '@ts-graphviz/react/web';
129+
import { wasmFolder } from '@hpcc-js/wasm';
130+
131+
wasmFolder('https://unpkg.com/@hpcc-js/wasm/dist/');
132+
133+
const App: FC = () => (
134+
<Graphviz>
135+
<Digraph>
136+
<Node id="n1" />
137+
<Node id="n2" />
138+
<Node id="n3" />
139+
<Edge targets={['n1', 'n2', 'n3']} />
140+
<Edge targets={['n1', 'n3']} />
141+
</Digraph>
142+
</Graphviz>
143+
);
144+
145+
ReactDOM.render(<App />, document.getElementById('root'));
146+
```
147+
107148
## See Also
108149

109150
Graphviz-dot Test and Integration

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
"publishConfig": {
2424
"access": "public"
2525
},
26-
"main": "lib.js",
27-
"module": "lib.mjs",
28-
"types": "lib/index.d.ts",
26+
"main": "core/index.js",
27+
"module": "core/index.mjs",
28+
"types": "core/index.d.ts",
2929
"scripts": {
3030
"example": "ts-node example/example",
3131
"build": "ts-node rollup.build",

rollup.build.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,21 @@ async function build({
4343
}
4444

4545
(async (): Promise<void> => {
46-
await Promise.all([remove('lib'), remove('lib.js'), remove('lib.mjs'), remove('web.js'), remove('web.mjs')]);
46+
await Promise.all([remove('core'), remove('web')]);
4747
await Promise.all([
4848
build({
4949
input: 'src/index.ts',
50-
output: 'lib',
50+
output: 'core',
5151
declaration: true,
5252
external: ['react', 'react-dom/server', 'ts-graphviz', 'prop-types', 'react-reconciler'],
5353
}),
5454
build({
5555
input: 'src/web/index.ts',
56-
output: 'lib/web',
56+
output: 'core/web',
5757
declaration: false,
5858
external: ['react', 'react-dom/server', 'ts-graphviz', 'react-reconciler', '@hpcc-js/wasm'],
5959
}),
6060
]);
6161

62-
await Promise.all([
63-
move('lib/index.js', 'lib.js'),
64-
move('lib/index.mjs', 'lib.mjs'),
65-
move('lib/web/index.js', 'web.js'),
66-
move('lib/web/index.mjs', 'web.mjs'),
67-
]);
62+
await move('core/web', 'web');
6863
})();

tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
"src/**/*.tsx"
2323
],
2424
"exclude": [
25+
"src/**/*.stories.tsx",
2526
"src/**/*.spec.ts",
2627
"src/**/*.spec.tsx",
2728
"src/**/*.test.ts",
28-
"src/**/*.test.tsx"
29+
"src/**/*.test.tsx",
30+
"src/**/__tests__/**/*.ts"
2931
]
3032
}

0 commit comments

Comments
 (0)