@rerun-io/web-viewer-react 0.17.0 → 0.18.0-rc.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/README.md +1 -1
- package/index.d.ts +2 -5
- package/index.js +79 -22
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ export default function App() {
|
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
The `rrd` in the snippet above should be a URL pointing to either:
|
|
38
|
-
- A hosted `.rrd` file, such as <https://app.rerun.io/version/0.
|
|
38
|
+
- A hosted `.rrd` file, such as <https://app.rerun.io/version/0.18.0-rc.1/examples/dna.rrd>
|
|
39
39
|
- A WebSocket connection to the SDK opened via the [`serve`](https://www.rerun.io/docs/reference/sdk-operating-modes#serve) API
|
|
40
40
|
|
|
41
41
|
If `rrd` is not set, the Viewer will display the same welcome screen as <https://app.rerun.io>.
|
package/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ declare module '@rerun-io/web-viewer-react' {
|
|
|
24
24
|
}, HTMLDivElement>;
|
|
25
25
|
#private;
|
|
26
26
|
}
|
|
27
|
-
export type
|
|
27
|
+
export type BaseProps = {
|
|
28
28
|
/**
|
|
29
29
|
* URL(s) of the `.rrd` file(s) to load.
|
|
30
30
|
* Changing this prop will open any new unique URLs as recordings,
|
|
@@ -39,11 +39,8 @@ declare module '@rerun-io/web-viewer-react' {
|
|
|
39
39
|
* CSS height of the viewer's parent div
|
|
40
40
|
*/
|
|
41
41
|
height?: string | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* Whether to hide the welcome screen. Default is `false`.
|
|
44
|
-
*/
|
|
45
|
-
hide_welcome_screen?: boolean | undefined;
|
|
46
42
|
};
|
|
43
|
+
export type Props = (Omit<import("@rerun-io/web-viewer").WebViewerOptions, "allow_fullscreen" | "enable_history"> & BaseProps);
|
|
47
44
|
}
|
|
48
45
|
|
|
49
46
|
//# sourceMappingURL=index.d.ts.map
|
package/index.js
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import React, { createRef } from "react";
|
|
2
2
|
import * as rerun from "@rerun-io/web-viewer";
|
|
3
3
|
|
|
4
|
+
// NOTE: We're intentionally not exposing `allow_fullscreen` and `enable_history`.
|
|
5
|
+
// Those features are already pretty sensitive to the environment, especially
|
|
6
|
+
// so in React where all normal behavior of web APIs goes out of the window.
|
|
4
7
|
/**
|
|
5
|
-
* @typedef
|
|
8
|
+
* @typedef BaseProps
|
|
6
9
|
* @property {string | string[]} rrd URL(s) of the `.rrd` file(s) to load.
|
|
7
10
|
* Changing this prop will open any new unique URLs as recordings,
|
|
8
11
|
* and close any URLs which are not present.
|
|
9
12
|
* @property {string} [width] CSS width of the viewer's parent div
|
|
10
13
|
* @property {string} [height] CSS height of the viewer's parent div
|
|
11
|
-
*
|
|
14
|
+
*
|
|
15
|
+
* @typedef {(
|
|
16
|
+
* Omit<import("@rerun-io/web-viewer").WebViewerOptions, "allow_fullscreen" | "enable_history">
|
|
17
|
+
* & BaseProps
|
|
18
|
+
* )} Props
|
|
12
19
|
*/
|
|
13
20
|
|
|
14
21
|
/**
|
|
@@ -25,37 +32,50 @@ export default class WebViewer extends React.Component {
|
|
|
25
32
|
/** @type {rerun.WebViewer} */
|
|
26
33
|
#handle;
|
|
27
34
|
|
|
28
|
-
/** @type {string[]} */
|
|
29
|
-
#recordings = [];
|
|
30
|
-
|
|
31
|
-
/** @type {boolean} */
|
|
32
|
-
#hide_welcome_screen = false;
|
|
33
|
-
|
|
34
35
|
/** @param {Props} props */
|
|
35
36
|
constructor(props) {
|
|
36
37
|
super(props);
|
|
37
38
|
|
|
38
39
|
this.#handle = new rerun.WebViewer();
|
|
39
|
-
this.#recordings = toArray(props.rrd);
|
|
40
|
-
this.#hide_welcome_screen = props.hide_welcome_screen ?? false;
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
componentDidMount() {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
43
|
+
startViewer(
|
|
44
|
+
this.#handle,
|
|
45
|
+
/** @type {HTMLDivElement} */ (this.#parent.current),
|
|
46
|
+
this.props,
|
|
47
|
+
);
|
|
50
48
|
}
|
|
51
49
|
|
|
52
50
|
componentDidUpdate(/** @type {Props} */ prevProps) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
if (
|
|
52
|
+
keysChanged(prevProps, this.props, [
|
|
53
|
+
"hide_welcome_screen",
|
|
54
|
+
"manifest_url",
|
|
55
|
+
"render_backend",
|
|
56
|
+
])
|
|
57
|
+
) {
|
|
58
|
+
// We have to restart the viewer, because the above
|
|
59
|
+
// props are _startup_ options only, and we don't
|
|
60
|
+
// want to break that promise by setting them
|
|
61
|
+
// after the viewer has been started.
|
|
62
|
+
this.#handle.stop();
|
|
63
|
+
|
|
64
|
+
this.#handle = new rerun.WebViewer();
|
|
65
|
+
startViewer(
|
|
66
|
+
this.#handle,
|
|
67
|
+
/** @type {HTMLDivElement} */ (this.#parent.current),
|
|
68
|
+
this.props,
|
|
69
|
+
);
|
|
70
|
+
} else {
|
|
71
|
+
// We only need to diff the recordings.
|
|
72
|
+
|
|
73
|
+
const prev = toArray(prevProps.rrd);
|
|
74
|
+
const current = toArray(this.props.rrd);
|
|
75
|
+
const { added, removed } = diff(prev, current);
|
|
76
|
+
this.#handle.open(added);
|
|
77
|
+
this.#handle.close(removed);
|
|
78
|
+
}
|
|
59
79
|
}
|
|
60
80
|
|
|
61
81
|
componentWillUnmount() {
|
|
@@ -72,6 +92,24 @@ export default class WebViewer extends React.Component {
|
|
|
72
92
|
}
|
|
73
93
|
}
|
|
74
94
|
|
|
95
|
+
/**
|
|
96
|
+
* @param {rerun.WebViewer} handle
|
|
97
|
+
* @param {HTMLElement} parent
|
|
98
|
+
* @param {Props} props
|
|
99
|
+
*/
|
|
100
|
+
function startViewer(handle, parent, props) {
|
|
101
|
+
handle.start(toArray(props.rrd), parent, {
|
|
102
|
+
manifest_url: props.manifest_url,
|
|
103
|
+
render_backend: props.render_backend,
|
|
104
|
+
hide_welcome_screen: props.hide_welcome_screen,
|
|
105
|
+
|
|
106
|
+
// NOTE: `width`, `height` intentionally ignored, they will
|
|
107
|
+
// instead be used on the parent `div` element
|
|
108
|
+
width: "100%",
|
|
109
|
+
height: "100%",
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
75
113
|
/**
|
|
76
114
|
* Return the difference between the two arrays.
|
|
77
115
|
*
|
|
@@ -88,6 +126,25 @@ function diff(prev, current) {
|
|
|
88
126
|
};
|
|
89
127
|
}
|
|
90
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Returns `true` if any of the `keys` changed between `prev` and `curr`.
|
|
131
|
+
*
|
|
132
|
+
* The definition of "changed" is any of removed, added, value changed.
|
|
133
|
+
*
|
|
134
|
+
* @template {Record<string, any>} T
|
|
135
|
+
* @param {T} prev
|
|
136
|
+
* @param {T} curr
|
|
137
|
+
* @param {(keyof T)[]} keys
|
|
138
|
+
*/
|
|
139
|
+
function keysChanged(prev, curr, keys) {
|
|
140
|
+
for (const key of keys) {
|
|
141
|
+
if (prev[key] !== curr[key]) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
|
|
91
148
|
/**
|
|
92
149
|
* @template T
|
|
93
150
|
* @param {T | T[]} a
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rerun-io/web-viewer-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0-rc.1",
|
|
4
4
|
"description": "Embed the Rerun web viewer in your React app",
|
|
5
5
|
"licenses": [
|
|
6
6
|
{
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"tsconfig.json"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@rerun-io/web-viewer": "0.
|
|
42
|
+
"@rerun-io/web-viewer": "0.18.0-rc.1",
|
|
43
43
|
"@types/react": "^18.2.33",
|
|
44
44
|
"react": "^18.2.0"
|
|
45
45
|
},
|