@rerun-io/web-viewer-react 0.0.5
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/README.md +37 -0
- package/index.js +63 -0
- package/package.json +38 -0
- package/tsconfig.json +16 -0
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Rerun Web Viewer
|
|
2
|
+
|
|
3
|
+
Embed the Rerun web viewer within your React app.
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<img width="800" alt="Rerun Viewer" src="https://github.com/rerun-io/rerun/assets/2624717/c4900538-fc3a-43b8-841a-8d226e7b5a2e">
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
$ npm i @rerun-io/web-viewer-react
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```jsx
|
|
18
|
+
import WebViewer from "@rerun-io/web-viewer-react";
|
|
19
|
+
|
|
20
|
+
export default function App() {
|
|
21
|
+
return (
|
|
22
|
+
<div>
|
|
23
|
+
<WebViewer rrd="...">
|
|
24
|
+
</div>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
ℹ️ Note:
|
|
30
|
+
This package only targets recent versions of browsers.
|
|
31
|
+
If your target browser does not support Wasm imports, you may need to install additional plugins for your bundler.
|
|
32
|
+
|
|
33
|
+
## Development
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
$ npm run build
|
|
37
|
+
```
|
package/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from "react";
|
|
2
|
+
import * as rerun from "@rerun-io/web-viewer";
|
|
3
|
+
|
|
4
|
+
/** @typedef {import("react")} React */
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef Props
|
|
8
|
+
* @property {string} rrd URL of the `.rrd` file to load
|
|
9
|
+
* @property {string} [width] CSS width of the viewer's parent div
|
|
10
|
+
* @property {string} [height] CSS height of the viewer's parent div
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Wrapper for `WebViewer` from the `@rerun-io/web-viewer`.
|
|
15
|
+
*
|
|
16
|
+
* This component creates and manages the web viewer's `canvas` element.
|
|
17
|
+
*
|
|
18
|
+
* The web viewer is restarted each time `rrd` changes.
|
|
19
|
+
* Starting the web viewer is an expensive operation, so be careful with changing it too often!
|
|
20
|
+
*
|
|
21
|
+
* @param {Props} props
|
|
22
|
+
*/
|
|
23
|
+
export default function WebViewer(props) {
|
|
24
|
+
const { width = "100%", height = "640px", rrd } = props;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Parent DOM node
|
|
28
|
+
* @type {React.RefObject<HTMLDivElement>}
|
|
29
|
+
*/
|
|
30
|
+
const parent = useRef(null);
|
|
31
|
+
/**
|
|
32
|
+
* Web viewer instance
|
|
33
|
+
* @type {React.MutableRefObject<rerun.WebViewer | undefined>}
|
|
34
|
+
*/
|
|
35
|
+
const viewer = useRef();
|
|
36
|
+
|
|
37
|
+
useEffect(
|
|
38
|
+
() => {
|
|
39
|
+
if (parent.current) {
|
|
40
|
+
// Start the web viewer when the parent div is mounted to the DOM.
|
|
41
|
+
const w = new rerun.WebViewer();
|
|
42
|
+
w.start(rrd);
|
|
43
|
+
viewer.current = w;
|
|
44
|
+
return () => {
|
|
45
|
+
// Stop the web viewer when the component is unmounted.
|
|
46
|
+
w.stop();
|
|
47
|
+
viewer.current = undefined;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
// The web viewer will be restarted when:
|
|
52
|
+
// - `parent` is added/moved/removed in the DOM
|
|
53
|
+
// - `rrd` changes
|
|
54
|
+
[parent.current, rrd]
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
return React.createElement("div", {
|
|
58
|
+
className: "rerun-web-viewer",
|
|
59
|
+
style: { width, height, position: "relative" },
|
|
60
|
+
ref: parent,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rerun-io/web-viewer-react",
|
|
3
|
+
"version": "0.0.5",
|
|
4
|
+
"description": "Embed the Rerun web viewer in your React app",
|
|
5
|
+
"private": false,
|
|
6
|
+
"scripts": {},
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/rerun-io/rerun.git"
|
|
10
|
+
},
|
|
11
|
+
"author": "rerun-io",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/rerun-io/rerun/issues"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://rerun.io",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./index.d.ts",
|
|
20
|
+
"import": "./index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"index.d.ts",
|
|
25
|
+
"index.d.ts.map",
|
|
26
|
+
"index.js",
|
|
27
|
+
"package.json",
|
|
28
|
+
"tsconfig.json"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@rerun-io/web-viewer": "^0.0.5",
|
|
32
|
+
"@types/react": "^18.2.33",
|
|
33
|
+
"react": "^18.2.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"dts-buddy": "^0.3.0"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"checkJs": true,
|
|
5
|
+
"noEmit": true,
|
|
6
|
+
"strict": true,
|
|
7
|
+
"target": "ES2020",
|
|
8
|
+
"module": "ES2022",
|
|
9
|
+
"moduleResolution": "node",
|
|
10
|
+
"allowSyntheticDefaultImports": true,
|
|
11
|
+
},
|
|
12
|
+
"include": [
|
|
13
|
+
"index.js",
|
|
14
|
+
"re_viewer.js",
|
|
15
|
+
]
|
|
16
|
+
}
|