@transitive-sdk/utils-web 0.10.3 → 0.11.0

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/docs/client.md CHANGED
@@ -56,15 +56,52 @@ createWebComponent(Device, `${capabilityName}-device`, ['jwt']);
56
56
  A simple error boundary. Usage:
57
57
 
58
58
  ```jsx
59
- <ErrorBoundary message="Something went wrong">
60
- <SomeFlakyComponent />
61
- </ErrorBoundary>
59
+ <ErrorBoundary message="Something went wrong">
60
+ <SomeFlakyComponent />
61
+ </ErrorBoundary>
62
62
  ```
63
63
 
64
64
  #### Parameters
65
65
 
66
66
  * `props` &#x20;
67
67
 
68
+ ## CapabilityContextProvider
69
+
70
+ Context provider for capabilities. Use this to access the front-end API
71
+ provided by some capabilities. Example:
72
+
73
+ ```jsx
74
+ <CapabilityContextProvider jwt={jwt}>
75
+ <MyROSComponent />
76
+ </CapabilityContextProvider>
77
+ ```
78
+
79
+ where `jwt` is a JWT for a capability that exposes a front-end API. Then use
80
+ `useContext` in `MyROSComponent` to get the exposed data and functions, e.g.:
81
+
82
+ ```jsx
83
+ const MyROSComponent = () => {
84
+ const { ready, subscribe, data } = useContext(CapabilityContext);
85
+ // When ready, subscribe to the `/odom` topic in ROS1
86
+ useEffect(() => { ready && subscribe(1, '/odom'); }, [ready]);
87
+ return <pre>{JSON.stringify(data, true, 2)}</pre>;
88
+ }
89
+ ```
90
+
91
+ Where `ready`, `subscribe`, and `data` are reactive variables and functions
92
+ exposed by the capability of the provided JWT. In this example, the latest
93
+ message from the subscribed ROS topics will be available in the capabilities
94
+ namespace in `data`.
95
+
96
+ #### Parameters
97
+
98
+ * `props` **[object][1]**&#x20;
99
+
100
+ * `props.children` &#x20;
101
+ * `props.jwt` &#x20;
102
+ * `props.host` (optional, default `undefined`)
103
+ * `props.ssl` (optional, default `undefined`)
104
+
68
105
  ## Code
69
106
 
70
107
  Reusable component for showing code
@@ -125,12 +162,12 @@ and object properties, which get lost when using the custom element (Web
125
162
  Component) because HTML attributes are strings.
126
163
  Example:
127
164
 
128
- ```js
129
- <TransitiveCapability jwt={jwt}
130
- myconfig={{a: 1, b: 2}}
131
- onData={(data) => setData(data)}
132
- onclick={() => { console.log('custom click handler'); }}
133
- />
165
+ ```jsx
166
+ <TransitiveCapability jwt={jwt}
167
+ myconfig={{a: 1, b: 2}}
168
+ onData={(data) => setData(data)}
169
+ onclick={() => { console.log('custom click handler'); }}
170
+ />
134
171
  ```
135
172
 
136
173
  #### Parameters
@@ -149,12 +186,12 @@ this hook also returns any functions and objects the component exports in
149
186
  `loadedModule`. Example:
150
187
 
151
188
  ```js
152
- const {loaded, loadedModule} = useCapability({
153
- capability: '@transitive-robotics/terminal',
154
- name: 'mock-device',
155
- userId: 'user123',
156
- deviceId: 'd_mydevice123',
157
- });
189
+ const {loaded, loadedModule} = useCapability({
190
+ capability: '@transitive-robotics/terminal',
191
+ name: 'mock-device',
192
+ userId: 'user123',
193
+ deviceId: 'd_mydevice123',
194
+ });
158
195
  ```
159
196
 
160
197
  #### Parameters
@@ -167,6 +204,7 @@ deviceId: 'd_mydevice123',
167
204
  * `$0.deviceId` &#x20;
168
205
  * `$0.host` (optional, default `'transitiverobotics.com'`)
169
206
  * `$0.ssl` (optional, default `true`)
207
+ * `$0.appReact` &#x20;
170
208
 
171
209
  ## useMqttSync
172
210
 
@@ -179,6 +217,7 @@ Hook for using MqttSync in React.
179
217
  * `$0.jwt` &#x20;
180
218
  * `$0.id` &#x20;
181
219
  * `$0.mqttUrl` &#x20;
220
+ * `$0.appReact` &#x20;
182
221
 
183
222
  Returns **[object][1]** An object `{data, mqttSync, ready, StatusComponent, status}`
184
223
  where:
@@ -197,10 +236,10 @@ on the device of the JWT and get the data for that version.
197
236
  Example usage (with webrtc-video):
198
237
 
199
238
  ```js
200
- const { agentStatus, topicData } = useTopics({ jwt, topics: [
201
- '/options/videoSource',
202
- '/stats/+/log/'
203
- ]});
239
+ const { agentStatus, topicData } = useTopics({ jwt, topics: [
240
+ '/options/videoSource',
241
+ '/stats/+/log/'
242
+ ]});
204
243
  ```
205
244
 
206
245
  #### Parameters
@@ -213,6 +252,7 @@ const { agentStatus, topicData } = useTopics({ jwt, topics: [
213
252
  * `options.host` (optional, default `'transitiverobotics.com'`)
214
253
  * `options.ssl` (optional, default `true`)
215
254
  * `options.topics` (optional, default `[]`)
255
+ * `options.appReact` &#x20;
216
256
 
217
257
  Returns **[object][1]** An object `{data, mqttSync, ready, agentStatus, topicData}`
218
258
  where:
@@ -235,5 +275,6 @@ exposes reactive `data` state variable.
235
275
  * `$0.ssl` &#x20;
236
276
  * `$0.capability` &#x20;
237
277
  * `$0.versionNS` &#x20;
278
+ * `$0.appReact` &#x20;
238
279
 
239
280
  [1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
package/esbuild.js CHANGED
@@ -8,10 +8,10 @@ const config = {
8
8
  bundle: true,
9
9
  format: 'cjs',
10
10
  preserveSymlinks: true, // this allows us to use symlinks
11
- minify: !isDevelopment,
11
+ // Do *NOT* minify, it would remove "magic webpack comments" that are required
12
+ // by users that use webpack for bundling.
13
+ // minify: !isDevelopment,
12
14
  sourcemap: isDevelopment,
13
- // minify: true,
14
- // sourcemap: false,
15
15
  target: ['chrome110', 'firefox110', 'safari15', 'edge110'],
16
16
  // target: ['es2022'],
17
17
  packages: 'external',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transitive-sdk/utils-web",
3
- "version": "0.10.3",
3
+ "version": "0.11.0",
4
4
  "description": "Web utils for the Transitive framework",
5
5
  "homepage": "https://transitiverobotics.com",
6
6
  "repository": {