@rerun-io/web-viewer-react 0.31.3 → 0.31.4
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 +5 -0
- package/index.d.ts.map +1 -1
- package/index.js +102 -16
- 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.31.
|
|
38
|
+
- A hosted `.rrd` file, such as <https://app.rerun.io/version/0.31.4/examples/dna.rrd>
|
|
39
39
|
- A gRPC 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
|
@@ -32,6 +32,11 @@ declare module '@rerun-io/web-viewer-react' {
|
|
|
32
32
|
* and close any URLs which are not present.
|
|
33
33
|
*/
|
|
34
34
|
rrd: string | string[];
|
|
35
|
+
/**
|
|
36
|
+
* Whether to open HTTP `.rrd` sources in following mode.
|
|
37
|
+
* Defaults to `false`. Ignored for non-HTTP sources.
|
|
38
|
+
*/
|
|
39
|
+
follow_if_http?: boolean | undefined;
|
|
35
40
|
/**
|
|
36
41
|
* CSS width of the viewer's parent div
|
|
37
42
|
*/
|
package/index.d.ts.map
CHANGED
package/index.js
CHANGED
|
@@ -9,6 +9,8 @@ import * as rerun from "@rerun-io/web-viewer";
|
|
|
9
9
|
* @property {string | string[]} rrd URL(s) of the `.rrd` file(s) to load.
|
|
10
10
|
* Changing this prop will open any new unique URLs as recordings,
|
|
11
11
|
* and close any URLs which are not present.
|
|
12
|
+
* @property {boolean} [follow_if_http] Whether to open HTTP `.rrd` sources in following mode.
|
|
13
|
+
* Defaults to `false`. Ignored for non-HTTP sources.
|
|
12
14
|
* @property {string} [width] CSS width of the viewer's parent div
|
|
13
15
|
* @property {string} [height] CSS height of the viewer's parent div
|
|
14
16
|
*
|
|
@@ -71,11 +73,17 @@ export default class WebViewer extends React.Component {
|
|
|
71
73
|
} else {
|
|
72
74
|
// We only need to diff the recordings.
|
|
73
75
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
if (!this.#handle.ready) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
syncRecordings(
|
|
81
|
+
this.#handle,
|
|
82
|
+
toArray(prevProps.rrd),
|
|
83
|
+
toArray(this.props.rrd),
|
|
84
|
+
prevProps.follow_if_http,
|
|
85
|
+
this.props.follow_if_http,
|
|
86
|
+
);
|
|
79
87
|
}
|
|
80
88
|
}
|
|
81
89
|
|
|
@@ -120,17 +128,42 @@ function pascalToSnake(str) {
|
|
|
120
128
|
*/
|
|
121
129
|
function startViewer(handle, parent, getProps) {
|
|
122
130
|
const props = getProps();
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
const initial = toArray(props.rrd);
|
|
132
|
+
const initialFollowIfHttp = props.follow_if_http;
|
|
133
|
+
handle
|
|
134
|
+
.start(
|
|
135
|
+
initial,
|
|
136
|
+
parent,
|
|
137
|
+
{
|
|
138
|
+
manifest_url: props.manifest_url,
|
|
139
|
+
render_backend: props.render_backend,
|
|
140
|
+
hide_welcome_screen: props.hide_welcome_screen,
|
|
141
|
+
theme: props.theme,
|
|
142
|
+
|
|
143
|
+
// NOTE: `width`, `height` intentionally ignored, they will
|
|
144
|
+
// instead be used on the parent `div` element
|
|
145
|
+
width: "100%",
|
|
146
|
+
height: "100%",
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
follow_if_http: initialFollowIfHttp,
|
|
150
|
+
},
|
|
151
|
+
)
|
|
152
|
+
.then(() => {
|
|
153
|
+
if (!handle.ready) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const { rrd, follow_if_http } = getProps();
|
|
158
|
+
syncRecordings(
|
|
159
|
+
handle,
|
|
160
|
+
initial,
|
|
161
|
+
toArray(rrd),
|
|
162
|
+
initialFollowIfHttp,
|
|
163
|
+
follow_if_http,
|
|
164
|
+
);
|
|
165
|
+
})
|
|
166
|
+
.catch(() => {});
|
|
134
167
|
|
|
135
168
|
for (const key of Object.keys(props)) {
|
|
136
169
|
if (key.startsWith("on")) {
|
|
@@ -159,6 +192,59 @@ function diff(prev, current) {
|
|
|
159
192
|
};
|
|
160
193
|
}
|
|
161
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Reconcile the currently open recordings with the latest props.
|
|
197
|
+
*
|
|
198
|
+
* @param {rerun.WebViewer} handle
|
|
199
|
+
* @param {string[]} prev
|
|
200
|
+
* @param {string[]} current
|
|
201
|
+
* @param {boolean | undefined} prevFollowIfHttp
|
|
202
|
+
* @param {boolean | undefined} followIfHttp
|
|
203
|
+
*/
|
|
204
|
+
function syncRecordings(handle, prev, current, prevFollowIfHttp, followIfHttp) {
|
|
205
|
+
const { added, removed } = diff(prev, current);
|
|
206
|
+
const reopened =
|
|
207
|
+
prevFollowIfHttp !== followIfHttp
|
|
208
|
+
? intersection(prev, current).filter(isHttpSource)
|
|
209
|
+
: [];
|
|
210
|
+
|
|
211
|
+
if (removed.length > 0 || reopened.length > 0) {
|
|
212
|
+
handle.close([...removed, ...reopened]);
|
|
213
|
+
}
|
|
214
|
+
if (added.length > 0) {
|
|
215
|
+
handle.open(added, { follow_if_http: followIfHttp });
|
|
216
|
+
}
|
|
217
|
+
if (reopened.length > 0) {
|
|
218
|
+
handle.open(reopened, { follow_if_http: followIfHttp });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Return the values present in both arrays.
|
|
224
|
+
*
|
|
225
|
+
* @param {string[]} prev
|
|
226
|
+
* @param {string[]} current
|
|
227
|
+
* @returns {string[]}
|
|
228
|
+
*/
|
|
229
|
+
function intersection(prev, current) {
|
|
230
|
+
const prevSet = new Set(prev);
|
|
231
|
+
return current.filter((v) => prevSet.has(v));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Returns `true` if the recording source is affected by `follow_if_http`.
|
|
236
|
+
*
|
|
237
|
+
* @param {string} url
|
|
238
|
+
*/
|
|
239
|
+
function isHttpSource(url) {
|
|
240
|
+
try {
|
|
241
|
+
const protocol = new URL(url, document.baseURI).protocol;
|
|
242
|
+
return protocol === "http:" || protocol === "https:";
|
|
243
|
+
} catch {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
162
248
|
/**
|
|
163
249
|
* Returns `true` if any of the `keys` changed between `prev` and `curr`.
|
|
164
250
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rerun-io/web-viewer-react",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.4",
|
|
4
4
|
"description": "Embed the Rerun web viewer in your React app",
|
|
5
5
|
"licenses": [
|
|
6
6
|
{
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"tsconfig.json"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@rerun-io/web-viewer": "0.31.
|
|
46
|
+
"@rerun-io/web-viewer": "0.31.4"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@types/react": "^18.2.33 || ^19.0.0",
|