@rerun-io/web-viewer-react 0.24.0-alpha.4 → 0.24.0-alpha.6

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 CHANGED
@@ -16,8 +16,8 @@ If you'd like to use a framework-agnostic package instead, see <https://www.npmj
16
16
 
17
17
  ## Install
18
18
 
19
- ```
20
- $ npm i @rerun-io/web-viewer-react
19
+ ```sh
20
+ npm i @rerun-io/web-viewer-react
21
21
  ```
22
22
 
23
23
  ℹ️ Note:
@@ -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.24.0-alpha.4/examples/dna.rrd>
38
+ - A hosted `.rrd` file, such as <https://app.rerun.io/version/0.24.0-alpha.6/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
@@ -1,5 +1,6 @@
1
1
  declare module '@rerun-io/web-viewer-react' {
2
2
  import type { default as React } from 'react';
3
+ import type { WebViewerEvents } from '@rerun-io/web-viewer';
3
4
  /**
4
5
  * Wrapper for `WebViewer` from the `@rerun-io/web-viewer`.
5
6
  *
@@ -40,7 +41,22 @@ declare module '@rerun-io/web-viewer-react' {
40
41
  */
41
42
  height?: string | undefined;
42
43
  };
43
- export type Props = (Omit<import("@rerun-io/web-viewer").WebViewerOptions, "allow_fullscreen" | "enable_history"> & BaseProps);
44
+ export type Props = (Omit<import("@rerun-io/web-viewer").WebViewerOptions, "allow_fullscreen" | "enable_history"> & BaseProps & ViewerEvents);
45
+ type PascalCase<S extends string> = S extends `${infer P1}_${infer P2}`
46
+ ? `${Capitalize<P1>}${PascalCase<P2>}`
47
+ : Capitalize<S>;
48
+
49
+ type WithValue = {
50
+ [K in keyof WebViewerEvents as WebViewerEvents[K] extends void ? never : `on${PascalCase<K>}`]?: (event: WebViewerEvents[K]) => void;
51
+
52
+ }
53
+
54
+ type WithoutValue = {
55
+ [K in keyof WebViewerEvents as WebViewerEvents[K] extends void ? `on${PascalCase<K>}` : never]?: () => void;
56
+
57
+ }
58
+
59
+ type ViewerEvents = WithValue & WithoutValue;
44
60
  }
45
61
 
46
62
  //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map CHANGED
@@ -1,8 +1,14 @@
1
1
  {
2
2
  "version": 3,
3
3
  "file": "index.d.ts",
4
- "names": [],
5
- "sources": [],
6
- "sourcesContent": [],
7
- "mappings": ""
4
+ "names": [
5
+ "ViewerEvents"
6
+ ],
7
+ "sources": [
8
+ "types.d.ts"
9
+ ],
10
+ "sourcesContent": [
11
+ null
12
+ ],
13
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiBYA,YAAYA"
8
14
  }
package/index.js CHANGED
@@ -15,6 +15,7 @@ import * as rerun from "@rerun-io/web-viewer";
15
15
  * @typedef {(
16
16
  * Omit<import("@rerun-io/web-viewer").WebViewerOptions, "allow_fullscreen" | "enable_history">
17
17
  * & BaseProps
18
+ * & import("./types.d.ts").ViewerEvents
18
19
  * )} Props
19
20
  */
20
21
 
@@ -43,7 +44,7 @@ export default class WebViewer extends React.Component {
43
44
  startViewer(
44
45
  this.#handle,
45
46
  /** @type {HTMLDivElement} */ (this.#parent.current),
46
- this.props,
47
+ () => this.props,
47
48
  );
48
49
  }
49
50
 
@@ -65,7 +66,7 @@ export default class WebViewer extends React.Component {
65
66
  startViewer(
66
67
  this.#handle,
67
68
  /** @type {HTMLDivElement} */ (this.#parent.current),
68
- this.props,
69
+ () => this.props,
69
70
  );
70
71
  } else {
71
72
  // We only need to diff the recordings.
@@ -92,12 +93,33 @@ export default class WebViewer extends React.Component {
92
93
  }
93
94
  }
94
95
 
96
+ /** @param {string} str */
97
+ function pascalToSnake(str) {
98
+ let out = "";
99
+ for (let i = 0; i < str.length; i++) {
100
+ const code = str.charCodeAt(i);
101
+
102
+ // A–Z ?
103
+ if (code >= 65 && code <= 90) {
104
+ // if not first char, prepend underscore
105
+ if (i > 0) out += "_";
106
+ // convert to lowercase by adding 32
107
+ out += String.fromCharCode(code + 32);
108
+ } else {
109
+ // everything else (a–z, 0–9, etc.) goes straight through
110
+ out += String.fromCharCode(code);
111
+ }
112
+ }
113
+ return out;
114
+ }
115
+
95
116
  /**
96
117
  * @param {rerun.WebViewer} handle
97
118
  * @param {HTMLElement} parent
98
- * @param {Props} props
119
+ * @param {() => Props} getProps
99
120
  */
100
- function startViewer(handle, parent, props) {
121
+ function startViewer(handle, parent, getProps) {
122
+ const props = getProps();
101
123
  handle.start(toArray(props.rrd), parent, {
102
124
  manifest_url: props.manifest_url,
103
125
  render_backend: props.render_backend,
@@ -108,6 +130,16 @@ function startViewer(handle, parent, props) {
108
130
  width: "100%",
109
131
  height: "100%",
110
132
  });
133
+
134
+ for (const key of Object.keys(props)) {
135
+ if (key.startsWith("on")) {
136
+ /** @type {any} */
137
+ const event = pascalToSnake(key.slice(2));
138
+ /** @type {any} */
139
+ const callback = /** @type {any} */ (getProps())[key];
140
+ handle.on(event, callback);
141
+ }
142
+ }
111
143
  }
112
144
 
113
145
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rerun-io/web-viewer-react",
3
- "version": "0.24.0-alpha.4",
3
+ "version": "0.24.0-alpha.6",
4
4
  "description": "Embed the Rerun web viewer in your React app",
5
5
  "licenses": [
6
6
  {
@@ -13,7 +13,8 @@
13
13
  "scripts": {
14
14
  "build:types": "tsc --noEmit && dts-buddy",
15
15
  "build": "npm run build:types",
16
- "pack": "yarn pack --filename web-viewer-react.tar.gz"
16
+ "pack": "yarn pack --filename web-viewer-react.tar.gz",
17
+ "docs": "typedoc"
17
18
  },
18
19
  "repository": {
19
20
  "type": "git",
@@ -36,16 +37,19 @@
36
37
  "index.d.ts",
37
38
  "index.d.ts.map",
38
39
  "index.js",
40
+ "types.d.ts",
39
41
  "package.json",
40
42
  "tsconfig.json"
41
43
  ],
42
44
  "dependencies": {
43
- "@rerun-io/web-viewer": "0.24.0-alpha.4",
45
+ "@rerun-io/web-viewer": "0.24.0-alpha.6",
44
46
  "@types/react": "^18.2.33",
45
47
  "react": "^18.2.0"
46
48
  },
47
49
  "devDependencies": {
48
50
  "dts-buddy": "^0.3.0",
51
+ "typedoc": "^0.28.6",
52
+ "typedoc-github-theme": "^0.3.0",
49
53
  "typescript": "^5.2.2"
50
54
  }
51
55
  }
package/types.d.ts ADDED
@@ -0,0 +1,21 @@
1
+
2
+ import type { WebViewerEvents } from "@rerun-io/web-viewer";
3
+
4
+ type PascalCase<S extends string> = S extends `${infer P1}_${infer P2}`
5
+ ? `${Capitalize<P1>}${PascalCase<P2>}`
6
+ : Capitalize<S>;
7
+
8
+ type WithValue = {
9
+ [K in keyof WebViewerEvents as WebViewerEvents[K] extends void ? never : `on${PascalCase<K>}`]?: (event: WebViewerEvents[K]) => void;
10
+
11
+ }
12
+
13
+ type WithoutValue = {
14
+ [K in keyof WebViewerEvents as WebViewerEvents[K] extends void ? `on${PascalCase<K>}` : never]?: () => void;
15
+
16
+ }
17
+
18
+ export type ViewerEvents = WithValue & WithoutValue;
19
+
20
+
21
+