@osdk/widget.client-react 2.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,490 @@
1
+ # @osdk/widget.client-react
2
+
3
+ ## 2.1.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 322c5bc: Simulated release
8
+ - 317b555: Release
9
+ - Updated dependencies [322c5bc]
10
+ - Updated dependencies [322c5bc]
11
+ - Updated dependencies [b61e9f5]
12
+ - Updated dependencies [7416ce4]
13
+ - Updated dependencies [1ba3871]
14
+ - Updated dependencies [12843cb]
15
+ - Updated dependencies [18ba34f]
16
+ - Updated dependencies [cdd3154]
17
+ - Updated dependencies [56aa502]
18
+ - Updated dependencies [abe4897]
19
+ - Updated dependencies [63b2e63]
20
+ - Updated dependencies [cddfbf9]
21
+ - Updated dependencies [5a12181]
22
+ - Updated dependencies [2ce3659]
23
+ - Updated dependencies [7416ce4]
24
+ - Updated dependencies [26c2d95]
25
+ - Updated dependencies [430dee3]
26
+ - Updated dependencies [397f906]
27
+ - Updated dependencies [488b51c]
28
+ - Updated dependencies [fccd9ac]
29
+ - Updated dependencies [5665b18]
30
+ - Updated dependencies [761e69d]
31
+ - Updated dependencies [889e84b]
32
+ - Updated dependencies [62e5965]
33
+ - Updated dependencies [ed69666]
34
+ - Updated dependencies [c92fe73]
35
+ - Updated dependencies [2517750]
36
+ - Updated dependencies [4183a55]
37
+ - Updated dependencies [1e16dcb]
38
+ - Updated dependencies [70b4464]
39
+ - Updated dependencies [2f6206c]
40
+ - Updated dependencies [81c0d8c]
41
+ - Updated dependencies [81c0d8c]
42
+ - Updated dependencies [791e655]
43
+ - Updated dependencies [317b555]
44
+ - Updated dependencies [879b6c3]
45
+ - Updated dependencies [63b2e63]
46
+ - Updated dependencies [2517750]
47
+ - Updated dependencies [1e16dcb]
48
+ - Updated dependencies [f4370e3]
49
+ - Updated dependencies [ea4e4b1]
50
+ - Updated dependencies [a146ce4]
51
+ - Updated dependencies [cc380b5]
52
+ - Updated dependencies [e873024]
53
+ - Updated dependencies [88591f7]
54
+ - Updated dependencies [751e5b3]
55
+ - Updated dependencies [805df40]
56
+ - Updated dependencies [fe0cc43]
57
+ - Updated dependencies [2517750]
58
+ - Updated dependencies [5467a0f]
59
+ - Updated dependencies [2517750]
60
+ - Updated dependencies [63b2e63]
61
+ - @osdk/client@2.2.0
62
+ - @osdk/widget.api.unstable@2.1.0
63
+
64
+ ## 2.1.0-beta.11
65
+
66
+ ### Minor Changes
67
+
68
+ - a1f5bdc: Adds react 19 as valid peer deps
69
+
70
+ ### Patch Changes
71
+
72
+ - Updated dependencies [4183a55]
73
+ - @osdk/client@2.2.0-beta.23
74
+ - @osdk/widget.client.unstable@2.1.0-beta.11
75
+
76
+ ## 2.1.0-beta.10
77
+
78
+ ### Minor Changes
79
+
80
+ - 317b555: Release
81
+
82
+ ### Patch Changes
83
+
84
+ - Updated dependencies [317b555]
85
+ - @osdk/widget.client.unstable@2.1.0-beta.10
86
+ - @osdk/client@2.2.0-beta.21
87
+
88
+ ## 2.1.0-beta.9
89
+
90
+ ### Patch Changes
91
+
92
+ - Updated dependencies [889e84b]
93
+ - @osdk/client@2.2.0-beta.20
94
+ - @osdk/widget.client.unstable@2.1.0-beta.9
95
+
96
+ ## 2.1.0-beta.8
97
+
98
+ ### Patch Changes
99
+
100
+ - Updated dependencies [b61e9f5]
101
+ - Updated dependencies [abe4897]
102
+ - Updated dependencies [5a12181]
103
+ - Updated dependencies [430dee3]
104
+ - Updated dependencies [70b4464]
105
+ - Updated dependencies [791e655]
106
+ - Updated dependencies [751e5b3]
107
+ - @osdk/client@2.2.0-beta.17
108
+ - @osdk/widget.client.unstable@2.1.0-beta.8
109
+
110
+ ## 2.1.0-beta.7
111
+
112
+ ### Patch Changes
113
+
114
+ - @osdk/client@2.2.0-beta.16
115
+ - @osdk/widget.client.unstable@2.1.0-beta.7
116
+
117
+ ## 2.1.0-beta.6
118
+
119
+ ### Patch Changes
120
+
121
+ - Updated dependencies [2ce3659]
122
+ - Updated dependencies [488b51c]
123
+ - Updated dependencies [e873024]
124
+ - Updated dependencies [88591f7]
125
+ - @osdk/client@2.2.0-beta.13
126
+ - @osdk/widget.client.unstable@2.1.0-beta.6
127
+
128
+ ## 2.1.0-beta.5
129
+
130
+ ### Patch Changes
131
+
132
+ - Updated dependencies [c92fe73]
133
+ - @osdk/client@2.2.0-beta.12
134
+ - @osdk/widget.client.unstable@2.1.0-beta.5
135
+
136
+ ## 2.1.0-beta.4
137
+
138
+ ### Patch Changes
139
+
140
+ - Updated dependencies [81c0d8c]
141
+ - Updated dependencies [81c0d8c]
142
+ - @osdk/client@2.2.0-beta.10
143
+ - @osdk/widget.client.unstable@2.1.0-beta.4
144
+
145
+ ## 2.1.0-beta.3
146
+
147
+ ### Patch Changes
148
+
149
+ - Updated dependencies [7416ce4]
150
+ - Updated dependencies [7416ce4]
151
+ - Updated dependencies [879b6c3]
152
+ - Updated dependencies [805df40]
153
+ - @osdk/client@2.2.0-beta.7
154
+ - @osdk/widget.client.unstable@2.1.0-beta.3
155
+
156
+ ## 2.1.0-beta.2
157
+
158
+ ### Patch Changes
159
+
160
+ - Updated dependencies [cddfbf9]
161
+ - Updated dependencies [ea4e4b1]
162
+ - @osdk/client@2.2.0-beta.6
163
+ - @osdk/widget.client.unstable@2.1.0-beta.2
164
+
165
+ ## 2.0.0
166
+
167
+ ### Major Changes
168
+
169
+ - 5a4ebd7: Bump unstable widget packages to v1 to avoid undesired v0.x version behavior
170
+
171
+ ### Minor Changes
172
+
173
+ - 009650f: Add initial views API
174
+ - 5f36612: Add support for events
175
+ - c691c8b: Package now has experimental support for commonjs
176
+ - 01c02e5: Add vite plugin to parse out parameter config into a generated config file
177
+ - 121475a: Release versions 1.1.0 of Custom Widget client libraries
178
+ - 7d1355e: Initial release of widget API
179
+
180
+ ### Patch Changes
181
+
182
+ - Updated dependencies [966d408]
183
+ - Updated dependencies [b773513]
184
+ - Updated dependencies [5a4ebd7]
185
+ - Updated dependencies [cddc196]
186
+ - Updated dependencies [d794c19]
187
+ - Updated dependencies [05febf4]
188
+ - Updated dependencies [55c05f2]
189
+ - Updated dependencies [a06ec35]
190
+ - Updated dependencies [0dc40b0]
191
+ - Updated dependencies [009650f]
192
+ - Updated dependencies [3703d81]
193
+ - Updated dependencies [6f50516]
194
+ - Updated dependencies [25fd9f0]
195
+ - Updated dependencies [11a05cc]
196
+ - Updated dependencies [7865cb6]
197
+ - Updated dependencies [e6fbd94]
198
+ - Updated dependencies [9c4efe6]
199
+ - Updated dependencies [0a7c747]
200
+ - Updated dependencies [3ea2e79]
201
+ - Updated dependencies [5f36612]
202
+ - Updated dependencies [1812118]
203
+ - Updated dependencies [d927a1d]
204
+ - Updated dependencies [bc1761c]
205
+ - Updated dependencies [656f975]
206
+ - Updated dependencies [f1145ff]
207
+ - Updated dependencies [1c59d93]
208
+ - Updated dependencies [f446d0c]
209
+ - Updated dependencies [c80ca45]
210
+ - Updated dependencies [bb8b219]
211
+ - Updated dependencies [44e62f6]
212
+ - Updated dependencies [03f95eb]
213
+ - Updated dependencies [91cfa3a]
214
+ - Updated dependencies [94463b6]
215
+ - Updated dependencies [14624f7]
216
+ - Updated dependencies [1a89f23]
217
+ - Updated dependencies [9d35a1f]
218
+ - Updated dependencies [c691c8b]
219
+ - Updated dependencies [314ae66]
220
+ - Updated dependencies [749cf69]
221
+ - Updated dependencies [f03e39f]
222
+ - Updated dependencies [d464009]
223
+ - Updated dependencies [21d2dd1]
224
+ - Updated dependencies [11088aa]
225
+ - Updated dependencies [720218d]
226
+ - Updated dependencies [01c02e5]
227
+ - Updated dependencies [9298f75]
228
+ - Updated dependencies [eb27b54]
229
+ - Updated dependencies [7a95618]
230
+ - Updated dependencies [f34b3d4]
231
+ - Updated dependencies [d88fdb9]
232
+ - Updated dependencies [8eb2378]
233
+ - Updated dependencies [acbfab9]
234
+ - Updated dependencies [c9da74c]
235
+ - Updated dependencies [27f0f77]
236
+ - Updated dependencies [015279b]
237
+ - Updated dependencies [62c1d63]
238
+ - Updated dependencies [3c9ac22]
239
+ - Updated dependencies [91cfa3a]
240
+ - Updated dependencies [e86e91d]
241
+ - Updated dependencies [abfe4b3]
242
+ - Updated dependencies [121475a]
243
+ - Updated dependencies [27866a8]
244
+ - Updated dependencies [0cd1603]
245
+ - Updated dependencies [a7a4aef]
246
+ - Updated dependencies [e5fe7c0]
247
+ - Updated dependencies [1b2e8c9]
248
+ - Updated dependencies [9f3807c]
249
+ - Updated dependencies [d12c92b]
250
+ - Updated dependencies [0c56d21]
251
+ - Updated dependencies [e548b9b]
252
+ - Updated dependencies [6671a39]
253
+ - Updated dependencies [83e7ea3]
254
+ - Updated dependencies [5e78575]
255
+ - Updated dependencies [ee6224b]
256
+ - Updated dependencies [1dc0228]
257
+ - Updated dependencies [fa02ebf]
258
+ - Updated dependencies [9af346e]
259
+ - Updated dependencies [d3b3f35]
260
+ - Updated dependencies [c682504]
261
+ - Updated dependencies [9018dc2]
262
+ - Updated dependencies [a6c320d]
263
+ - Updated dependencies [e4839b9]
264
+ - Updated dependencies [8026baf]
265
+ - Updated dependencies [6b6c8a1]
266
+ - Updated dependencies [c537e2d]
267
+ - Updated dependencies [3fc2ee6]
268
+ - Updated dependencies [0d8ac3b]
269
+ - Updated dependencies [73fa373]
270
+ - Updated dependencies [8e6a5f4]
271
+ - Updated dependencies [7d1355e]
272
+ - Updated dependencies [09eaf24]
273
+ - Updated dependencies [71dfb4c]
274
+ - Updated dependencies [2d5e648]
275
+ - Updated dependencies [c4f88a8]
276
+ - Updated dependencies [d665147]
277
+ - Updated dependencies [f19da8e]
278
+ - @osdk/client@2.1.0
279
+ - @osdk/widget.client.unstable@2.0.0
280
+
281
+ ## 2.0.0-beta.16
282
+
283
+ ### Patch Changes
284
+
285
+ - Updated dependencies [966d408]
286
+ - Updated dependencies [f03e39f]
287
+ - Updated dependencies [0d8ac3b]
288
+ - Updated dependencies [2d5e648]
289
+ - @osdk/client@2.1.0-beta.30
290
+ - @osdk/widget.client.unstable@2.0.0-beta.16
291
+
292
+ ## 2.0.0-beta.15
293
+
294
+ ### Patch Changes
295
+
296
+ - Updated dependencies [f1145ff]
297
+ - Updated dependencies [8026baf]
298
+ - @osdk/client@2.1.0-beta.29
299
+ - @osdk/widget.client.unstable@2.0.0-beta.15
300
+
301
+ ## 2.0.0-beta.14
302
+
303
+ ### Patch Changes
304
+
305
+ - @osdk/widget.client.unstable@2.0.0-beta.14
306
+
307
+ ## 2.0.0-beta.13
308
+
309
+ ### Minor Changes
310
+
311
+ - 121475a: Release versions 1.1.0 of Custom Widget client libraries
312
+
313
+ ### Patch Changes
314
+
315
+ - Updated dependencies [f446d0c]
316
+ - Updated dependencies [121475a]
317
+ - @osdk/client@2.1.0-beta.28
318
+ - @osdk/widget.client.unstable@2.0.0-beta.13
319
+
320
+ ## 2.0.0-beta.12
321
+
322
+ ### Patch Changes
323
+
324
+ - @osdk/client@2.1.0-beta.27
325
+ - @osdk/widget-client.unstable@2.0.0-beta.12
326
+
327
+ ## 2.0.0-beta.11
328
+
329
+ ### Patch Changes
330
+
331
+ - Updated dependencies [7865cb6]
332
+ - Updated dependencies [e6fbd94]
333
+ - Updated dependencies [9c4efe6]
334
+ - Updated dependencies [44e62f6]
335
+ - Updated dependencies [94463b6]
336
+ - Updated dependencies [f19da8e]
337
+ - @osdk/client@2.1.0-beta.26
338
+ - @osdk/widget.client.unstable@2.0.0-beta.11
339
+
340
+ ## 2.0.0-beta.10
341
+
342
+ ### Patch Changes
343
+
344
+ - Updated dependencies [c80ca45]
345
+ - @osdk/client@2.1.0-beta.25
346
+ - @osdk/widget.client.unstable@2.0.0-beta.10
347
+
348
+ ## 2.0.0-beta.9
349
+
350
+ ### Minor Changes
351
+
352
+ - c691c8b: Package now has experimental support for commonjs
353
+
354
+ ### Patch Changes
355
+
356
+ - Updated dependencies [03f95eb]
357
+ - Updated dependencies [c691c8b]
358
+ - Updated dependencies [3c9ac22]
359
+ - @osdk/client@2.1.0-beta.24
360
+ - @osdk/widget.client.unstable@2.0.0-beta.9
361
+
362
+ ## 2.0.0-beta.8
363
+
364
+ ### Patch Changes
365
+
366
+ - Updated dependencies [d794c19]
367
+ - Updated dependencies [7a95618]
368
+ - Updated dependencies [62c1d63]
369
+ - Updated dependencies [83e7ea3]
370
+ - Updated dependencies [3fc2ee6]
371
+ - Updated dependencies [d665147]
372
+ - @osdk/client@2.1.0-beta.23
373
+ - @osdk/widget.client.unstable@2.0.0-beta.8
374
+
375
+ ## 2.0.0-beta.7
376
+
377
+ ### Patch Changes
378
+
379
+ - Updated dependencies [c9da74c]
380
+ - Updated dependencies [73fa373]
381
+ - @osdk/client@2.1.0-beta.22
382
+ - @osdk/widget.client.unstable@2.0.0-beta.7
383
+
384
+ ## 2.0.0-beta.6
385
+
386
+ ### Patch Changes
387
+
388
+ - Updated dependencies [3ea2e79]
389
+ - Updated dependencies [656f975]
390
+ - Updated dependencies [314ae66]
391
+ - Updated dependencies [f34b3d4]
392
+ - Updated dependencies [e86e91d]
393
+ - @osdk/client@2.1.0-beta.21
394
+ - @osdk/widget.client.unstable@2.0.0-beta.6
395
+
396
+ ## 2.0.0-beta.5
397
+
398
+ ### Patch Changes
399
+
400
+ - Updated dependencies [b773513]
401
+ - Updated dependencies [9d35a1f]
402
+ - Updated dependencies [abfe4b3]
403
+ - Updated dependencies [c537e2d]
404
+ - @osdk/client@2.1.0-beta.20
405
+ - @osdk/widget.client.unstable@2.0.0-beta.5
406
+
407
+ ## 2.0.0-beta.4
408
+
409
+ ### Major Changes
410
+
411
+ - 5a4ebd7: Bump unstable widget packages to v1 to avoid undesired v0.x version behavior
412
+
413
+ ### Patch Changes
414
+
415
+ - Updated dependencies [5a4ebd7]
416
+ - Updated dependencies [cddc196]
417
+ - Updated dependencies [720218d]
418
+ - Updated dependencies [eb27b54]
419
+ - Updated dependencies [27f0f77]
420
+ - Updated dependencies [a7a4aef]
421
+ - Updated dependencies [6671a39]
422
+ - Updated dependencies [a6c320d]
423
+ - @osdk/widget.client.unstable@2.0.0-beta.4
424
+ - @osdk/client@2.1.0-beta.19
425
+
426
+ ## 0.3.0-beta.3
427
+
428
+ ### Patch Changes
429
+
430
+ - @osdk/client@2.1.0-beta.18
431
+ - @osdk/widget.client.unstable@0.3.0-beta.3
432
+
433
+ ## 0.3.0-beta.2
434
+
435
+ ### Patch Changes
436
+
437
+ - @osdk/client@2.1.0-beta.17
438
+ - @osdk/widget.client.unstable@0.3.0-beta.2
439
+
440
+ ## 0.3.0-beta.1
441
+
442
+ ### Patch Changes
443
+
444
+ - Updated dependencies [e5fe7c0]
445
+ - @osdk/client@2.1.0-beta.16
446
+ - @osdk/widget.client.unstable@0.3.0-beta.1
447
+
448
+ ## 0.2.0
449
+
450
+ ### Patch Changes
451
+
452
+ - Updated dependencies [1c59d93]
453
+ - Updated dependencies [e4839b9]
454
+ - @osdk/client@2.1.0-beta.15
455
+ - @osdk/widget.client.unstable@0.2.0-beta.0
456
+
457
+ ## 0.1.0
458
+
459
+ ### Patch Changes
460
+
461
+ - Updated dependencies [0a7c747]
462
+ - Updated dependencies [91cfa3a]
463
+ - Updated dependencies [015279b]
464
+ - Updated dependencies [91cfa3a]
465
+ - Updated dependencies [0c56d21]
466
+ - Updated dependencies [6b6c8a1]
467
+ - @osdk/client@2.1.0-beta.14
468
+ - @osdk/widget.client.unstable@0.1.0-beta.2
469
+
470
+ ## 0.1.0-beta.1
471
+
472
+ ### Patch Changes
473
+
474
+ - Updated dependencies [21d2dd1]
475
+ - Updated dependencies [c4f88a8]
476
+ - @osdk/widget.client.unstable@0.1.0-beta.1
477
+ - @osdk/client@2.1.0-beta.13
478
+
479
+ ## 0.1.0-beta.0
480
+
481
+ ### Minor Changes
482
+
483
+ - 01c02e5: Add vite plugin to parse out parameter config into a generated config file
484
+ - 7d1355e: Initial release of widget API
485
+
486
+ ### Patch Changes
487
+
488
+ - Updated dependencies [01c02e5]
489
+ - Updated dependencies [7d1355e]
490
+ - @osdk/widget.client.unstable@0.1.0-beta.0
@@ -0,0 +1,111 @@
1
+ /*
2
+ * Copyright 2024 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { createFoundryWidgetClient } from "@osdk/widget.client";
18
+ import React, { useEffect, useMemo } from "react";
19
+ import { FoundryWidgetContext } from "./context.js";
20
+ import { initializeParameters } from "./utils/initializeParameters.js";
21
+ /**
22
+ * Handles subscribing to messages from the host Foundry UI and updating the widget's parameter values accordingly via React context
23
+ */
24
+ export const FoundryWidget = ({
25
+ children,
26
+ config,
27
+ initialValues
28
+ }) => {
29
+ const client = useMemo(() => createFoundryWidgetClient(), []);
30
+ const [asyncParameterValues, setAsyncParameterValues] = React.useState(initialValues ?? initializeParameters(config, "not-started"));
31
+ const [allParameterValues, setAllParameterValues] = React.useState({
32
+ type: "not-started"
33
+ });
34
+ useEffect(() => {
35
+ client.subscribe();
36
+ client.hostEventTarget.addEventListener("host.update-parameters", payload => {
37
+ setAsyncParameterValues(currentParameters => ({
38
+ ...currentParameters,
39
+ ...payload.detail.parameters
40
+ }));
41
+ setAllParameterValues(currentParameters => {
42
+ let aggregatedLoadedState = "loaded";
43
+ let firstError;
44
+ const newParameterValues = {};
45
+ for (const key in payload.detail.parameters) {
46
+ const value = payload.detail.parameters[key].value;
47
+ // If any fails, consider the whole thing failed
48
+ if (value.type === "failed") {
49
+ aggregatedLoadedState = "failed";
50
+ firstError = firstError ?? value.error;
51
+ newParameterValues[key] = value.value;
52
+ continue;
53
+ }
54
+ // If any is loading, consider all of it loading unless we have failed somewhere
55
+ if (value.type === "loading" && aggregatedLoadedState !== "failed") {
56
+ aggregatedLoadedState = "loading";
57
+ continue;
58
+ }
59
+ // If any is reloading, consider it loading unless something is failed or loading for the first time
60
+ if (value.type === "reloading" && aggregatedLoadedState !== "failed" && aggregatedLoadedState !== "loading") {
61
+ aggregatedLoadedState = "reloading";
62
+ newParameterValues[key] = value.value;
63
+ continue;
64
+ }
65
+ if (value.type === "not-started" && aggregatedLoadedState !== "failed" && aggregatedLoadedState !== "loading" && aggregatedLoadedState !== "reloading") {
66
+ aggregatedLoadedState = "not-started";
67
+ }
68
+ if (value.type === "loaded") {
69
+ newParameterValues[key] = value.value;
70
+ }
71
+ }
72
+ const currentParameterValue = currentParameters.type !== "not-started" && currentParameters.type !== "loading" ? currentParameters.value : {};
73
+ if (aggregatedLoadedState !== "not-started" && aggregatedLoadedState !== "loading") {
74
+ const updatedValue = {
75
+ ...currentParameterValue,
76
+ ...newParameterValues
77
+ };
78
+ return aggregatedLoadedState === "failed" ? {
79
+ type: aggregatedLoadedState,
80
+ value: updatedValue,
81
+ error: firstError ?? new Error("Failed to load parameters")
82
+ } : {
83
+ type: aggregatedLoadedState,
84
+ value: updatedValue
85
+ };
86
+ } else {
87
+ return {
88
+ type: aggregatedLoadedState
89
+ };
90
+ }
91
+ });
92
+ });
93
+ client.ready();
94
+ return () => {
95
+ client.unsubscribe();
96
+ };
97
+ }, []);
98
+ return /*#__PURE__*/React.createElement(FoundryWidgetContext.Provider, {
99
+ value: {
100
+ emitEvent: client.emitEvent,
101
+ hostEventTarget: client.hostEventTarget,
102
+ asyncParameterValues,
103
+ parameters: {
104
+ values: allParameterValues.value ?? {},
105
+ state: allParameterValues.type
106
+ }
107
+ // Unfortunately the context is statically defined so we can't use the generic type, hence the cast
108
+ }
109
+ }, children);
110
+ };
111
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","names":["createFoundryWidgetClient","React","useEffect","useMemo","FoundryWidgetContext","initializeParameters","FoundryWidget","children","config","initialValues","client","asyncParameterValues","setAsyncParameterValues","useState","allParameterValues","setAllParameterValues","type","subscribe","hostEventTarget","addEventListener","payload","currentParameters","detail","parameters","aggregatedLoadedState","firstError","newParameterValues","key","value","error","currentParameterValue","updatedValue","Error","ready","unsubscribe","createElement","Provider","emitEvent","values","state"],"sources":["client.tsx"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n AsyncParameterValueMap,\n AsyncValue,\n ParameterConfig,\n ParameterValueMap,\n WidgetConfig,\n} from \"@osdk/widget.client\";\nimport { createFoundryWidgetClient } from \"@osdk/widget.client\";\nimport React, { useEffect, useMemo } from \"react\";\nimport type { FoundryWidgetClientContext } from \"./context.js\";\nimport { FoundryWidgetContext } from \"./context.js\";\nimport { initializeParameters } from \"./utils/initializeParameters.js\";\n\ninterface FoundryWidgetProps<C extends WidgetConfig<C[\"parameters\"]>> {\n children: React.ReactNode;\n\n /**\n * Parameter configuration for the widget\n */\n config: C;\n\n /**\n * Customize what the initial value of each parameter should be\n *\n * @default Sets all parameters to the \"not-started\" loading state\n */\n initialValues?: AsyncParameterValueMap<C>;\n}\n\n/**\n * Handles subscribing to messages from the host Foundry UI and updating the widget's parameter values accordingly via React context\n */\nexport const FoundryWidget = <C extends WidgetConfig<C[\"parameters\"]>>({\n children,\n config,\n initialValues,\n}: FoundryWidgetProps<C>): React.ReactElement<FoundryWidgetProps<C>> => {\n const client = useMemo(() => createFoundryWidgetClient<C>(), []);\n const [asyncParameterValues, setAsyncParameterValues] = React.useState<\n AsyncParameterValueMap<C>\n >(initialValues ?? initializeParameters(config, \"not-started\"));\n const [allParameterValues, setAllParameterValues] = React.useState<\n AsyncValue<ParameterValueMap<C>>\n >({\n type: \"not-started\",\n });\n\n useEffect(() => {\n client.subscribe();\n client.hostEventTarget.addEventListener(\n \"host.update-parameters\",\n (payload) => {\n setAsyncParameterValues((currentParameters) => ({\n ...currentParameters,\n ...payload.detail.parameters,\n }));\n setAllParameterValues((currentParameters) => {\n let aggregatedLoadedState: AsyncValue<any>[\"type\"] = \"loaded\";\n let firstError: Error | undefined;\n const newParameterValues: ParameterValueMap<\n WidgetConfig<ParameterConfig>\n > = {};\n for (const key in payload.detail.parameters) {\n const value = payload.detail.parameters[key].value;\n // If any fails, consider the whole thing failed\n if (value.type === \"failed\") {\n aggregatedLoadedState = \"failed\";\n firstError = firstError ?? value.error;\n newParameterValues[key as any] = value.value as any;\n continue;\n }\n // If any is loading, consider all of it loading unless we have failed somewhere\n if (\n value.type === \"loading\"\n && aggregatedLoadedState !== \"failed\"\n ) {\n aggregatedLoadedState = \"loading\";\n continue;\n }\n // If any is reloading, consider it loading unless something is failed or loading for the first time\n if (\n value.type === \"reloading\"\n && aggregatedLoadedState !== \"failed\"\n && aggregatedLoadedState !== \"loading\"\n ) {\n aggregatedLoadedState = \"reloading\";\n newParameterValues[key as any] = value.value as any;\n continue;\n }\n if (\n value.type === \"not-started\"\n && aggregatedLoadedState !== \"failed\"\n && aggregatedLoadedState !== \"loading\"\n && aggregatedLoadedState !== \"reloading\"\n ) {\n aggregatedLoadedState = \"not-started\";\n }\n\n if (value.type === \"loaded\") {\n newParameterValues[key as any] = value.value as any;\n }\n }\n const currentParameterValue = currentParameters.type !== \"not-started\"\n && currentParameters.type !== \"loading\"\n ? currentParameters.value\n : {};\n if (\n aggregatedLoadedState !== \"not-started\"\n && aggregatedLoadedState !== \"loading\"\n ) {\n const updatedValue = {\n ...currentParameterValue,\n ...newParameterValues,\n } as ParameterValueMap<C>;\n return aggregatedLoadedState === \"failed\"\n ? {\n type: aggregatedLoadedState,\n value: updatedValue,\n error: firstError ?? new Error(\"Failed to load parameters\"),\n }\n : {\n type: aggregatedLoadedState,\n value: updatedValue,\n };\n } else {\n return { type: aggregatedLoadedState };\n }\n });\n },\n );\n client.ready();\n return () => {\n client.unsubscribe();\n };\n }, []);\n\n return (\n <FoundryWidgetContext.Provider\n value={{\n emitEvent: client.emitEvent,\n hostEventTarget: client.hostEventTarget,\n asyncParameterValues,\n parameters: {\n values: allParameterValues.value ?? {},\n state: allParameterValues.type,\n },\n // Unfortunately the context is statically defined so we can't use the generic type, hence the cast\n } as FoundryWidgetClientContext<WidgetConfig<ParameterConfig>>}\n >\n {children}\n </FoundryWidgetContext.Provider>\n );\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,SAASA,yBAAyB,QAAQ,qBAAqB;AAC/D,OAAOC,KAAK,IAAIC,SAAS,EAAEC,OAAO,QAAQ,OAAO;AAEjD,SAASC,oBAAoB,QAAQ,cAAc;AACnD,SAASC,oBAAoB,QAAQ,iCAAiC;AAkBtE;AACA;AACA;AACA,OAAO,MAAMC,aAAa,GAAGA,CAA0C;EACrEC,QAAQ;EACRC,MAAM;EACNC;AACqB,CAAC,KAAgD;EACtE,MAAMC,MAAM,GAAGP,OAAO,CAAC,MAAMH,yBAAyB,CAAI,CAAC,EAAE,EAAE,CAAC;EAChE,MAAM,CAACW,oBAAoB,EAAEC,uBAAuB,CAAC,GAAGX,KAAK,CAACY,QAAQ,CAEpEJ,aAAa,IAAIJ,oBAAoB,CAACG,MAAM,EAAE,aAAa,CAAC,CAAC;EAC/D,MAAM,CAACM,kBAAkB,EAAEC,qBAAqB,CAAC,GAAGd,KAAK,CAACY,QAAQ,CAEhE;IACAG,IAAI,EAAE;EACR,CAAC,CAAC;EAEFd,SAAS,CAAC,MAAM;IACdQ,MAAM,CAACO,SAAS,C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@
1
+ /*
2
+ * Copyright 2024 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software=
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { FoundryHostEventTarget } from "@osdk/widget.client";
18
+ import React, { useContext } from "react";
19
+ export const FoundryWidgetContext = /*#__PURE__*/React.createContext({
20
+ emitEvent: () => {},
21
+ hostEventTarget: new FoundryHostEventTarget(),
22
+ asyncParameterValues: {},
23
+ parameters: {
24
+ state: "not-started",
25
+ values: {}
26
+ }
27
+ });
28
+
29
+ /**
30
+ * @returns The current FoundryWidgetClientContext, in the context of your specific parameter configuration
31
+ */
32
+ export function useFoundryWidgetContext() {
33
+ return useContext(FoundryWidgetContext);
34
+ }
35
+ (function (_useFoundryWidgetContext) {
36
+ _useFoundryWidgetContext.withTypes = function () {
37
+ return () => {
38
+ return useFoundryWidgetContext();
39
+ };
40
+ };
41
+ })(useFoundryWidgetContext || (useFoundryWidgetContext = {}));
42
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","names":["FoundryHostEventTarget","React","useContext","FoundryWidgetContext","createContext","emitEvent","hostEventTarget","asyncParameterValues","parameters","state","values","useFoundryWidgetContext","_useFoundryWidgetContext","withTypes"],"sources":["context.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software=\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n type AsyncParameterValueMap,\n type AsyncValue,\n FoundryHostEventTarget,\n type FoundryWidgetClient,\n type ParameterConfig,\n type ParameterValueMap,\n type WidgetConfig,\n} from \"@osdk/widget.client\";\nimport React, { useContext } from \"react\";\n\nexport interface FoundryWidgetClientContext<\n C extends WidgetConfig<C[\"parameters\"]>,\n> {\n emitEvent: FoundryWidgetClient<C>[\"emitEvent\"];\n hostEventTarget: FoundryHostEventTarget<C>;\n\n /**\n * Object where the individual parameters have their async state represented\n */\n asyncParameterValues: AsyncParameterValueMap<C>;\n\n /**\n * Convenience object that aggregates the value of all parameters, accounting for their loading states\n */\n parameters: {\n values: Partial<ParameterValueMap<C>>;\n state: AsyncValue<ParameterValueMap<C>>[\"type\"];\n };\n}\n\nexport const FoundryWidgetContext: React.Context<\n FoundryWidgetClientContext<WidgetConfig<ParameterConfig>>\n> = React.createContext<\n FoundryWidgetClientContext<WidgetConfig<ParameterConfig>>\n>({\n emitEvent: () => {},\n hostEventTarget: new FoundryHostEventTarget<WidgetConfig<ParameterConfig>>(),\n asyncParameterValues: {},\n parameters: {\n state: \"not-started\",\n values: {},\n },\n});\n\n/**\n * @returns The current FoundryWidgetClientContext, in the context of your specific parameter configuration\n */\nexport function useFoundryWidgetContext<\n C extends WidgetConfig<C[\"parameters\"]>,\n>() {\n return useContext(FoundryWidgetContext) as FoundryWidgetClientContext<C>;\n}\n\nexport namespace useFoundryWidgetContext {\n export function withTypes<\n C extends WidgetConfig<C[\"parameters\"]>,\n >(): () => FoundryWidgetClientContext<C> {\n return () => {\n return useFoundryWidgetContext<C>();\n };\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAGEA,sBAAsB,QAKjB,qBAAqB;AAC5B,OAAOC,KAAK,IAAIC,UAAU,QAAQ,OAAO;AAsBzC,OAAO,MAAMC,oBAEZ,gBAAGF,KAAK,CAACG,aAAa,CAErB;EACAC,SAAS,EAAEA,CAAA,KAAM,CAAC,CAAC;EACnBC,eAAe,EAAE,IAAIN,sBAAsB,CAAgC,CAAC;EAC5EO,oBAAoB,EAAE,CAAC,CAAC;EACxBC,UAAU,EAAE;IACVC,KAAK,EAAE,aAAa;IACpBC,MAAM,EAAE,CAAC;EACX;AACF,CAAC,CAAC;;AAEF;AACA;AACA;AACA,OAAO,SAASC,uBAAuBA,CAAA,EAEnC;EACF,OAAOT,UAAU,CAACC,oBAAoB,CAAC;AACzC;AAAC,WAAAS,wBAAA;EAAAA,wBAAA,CAAAC,SAAA,GAGQ,YAEkC;IACvC,OAAO,MAAM;MACX,OAAOF,uBAAuB,CAAI,CAAC;IACrC,CAAC;EACH,CAAC;AAAA,GAPcA,uBAAuB,KAAvBA,uBAAuB","ignoreList":[]}
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright 2024 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ export { FoundryWidget } from "./client.js";
18
+ export { useFoundryWidgetContext } from "./context.js";
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["FoundryWidget","useFoundryWidgetContext"],"sources":["index.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { FoundryWidget } from \"./client.js\";\nexport { useFoundryWidgetContext } from \"./context.js\";\nexport type { FoundryWidgetClientContext } from \"./context.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,aAAa,QAAQ,aAAa;AAC3C,SAASC,uBAAuB,QAAQ,cAAc","ignoreList":[]}