@osdk/widget.client-react 3.2.4 → 3.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @osdk/widget.client-react
2
2
 
3
+ ## 3.2.6
4
+
5
+ ### Patch Changes
6
+
7
+ - @osdk/widget.client@3.2.6
8
+
9
+ ## 3.2.5
10
+
11
+ ### Patch Changes
12
+
13
+ - 71f33ca: Add error boundary for custom widgets
14
+ - a2df5ba: Introduce widget resize message for automatic heights
15
+ - 71f33ca: Expand ErrorBoundary to catch all errors
16
+ - Updated dependencies [a2df5ba]
17
+ - @osdk/widget.client@3.2.5
18
+
3
19
  ## 3.2.4
4
20
 
5
21
  ### Patch Changes
@@ -0,0 +1,63 @@
1
+ /*
2
+ * Copyright 2025 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 * as React from "react";
18
+ /**
19
+ * Error boundary to catch and display errors in widget code.
20
+ */
21
+ export class ErrorBoundary extends React.Component {
22
+ state = {
23
+ error: null
24
+ };
25
+ static getDerivedStateFromError(error) {
26
+ return {
27
+ error
28
+ };
29
+ }
30
+ render() {
31
+ if (this.state.error) {
32
+ const errorDetails = this.state.error instanceof Error ? this.state.error.stack : "See browser console for more details.";
33
+ return /*#__PURE__*/React.createElement("section", {
34
+ style: {
35
+ padding: "16px"
36
+ }
37
+ }, /*#__PURE__*/React.createElement("h3", {
38
+ style: {
39
+ margin: "0 0 12px 0",
40
+ color: "#c00"
41
+ }
42
+ }, "An uncaught error occurred"), process.env.NODE_ENV !== "production" && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("p", {
43
+ style: {
44
+ margin: "0 0 8px 0"
45
+ }
46
+ }, "This error was caught by the widget framework's fallback error boundary."), /*#__PURE__*/React.createElement("ul", {
47
+ style: {
48
+ margin: "0 0 16px 0"
49
+ }
50
+ }, /*#__PURE__*/React.createElement("li", null, "Ensure errors are properly handled in your code with try-catch blocks and promise rejection handling."), /*#__PURE__*/React.createElement("li", null, "Add your own error boundary to replace this fallback with a custom error message or recovery options for your users."), /*#__PURE__*/React.createElement("li", null, "See:", " ", /*#__PURE__*/React.createElement("code", null, "https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary")))), /*#__PURE__*/React.createElement("pre", {
51
+ style: {
52
+ backgroundColor: "#f5f5f5",
53
+ padding: "12px",
54
+ overflow: "auto",
55
+ fontSize: "12px",
56
+ margin: 0
57
+ }
58
+ }, errorDetails));
59
+ }
60
+ return this.props.children;
61
+ }
62
+ }
63
+ //# sourceMappingURL=ErrorBoundary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorBoundary.js","names":["React","ErrorBoundary","Component","state","error","getDerivedStateFromError","render","errorDetails","Error","stack","createElement","style","padding","margin","color","process","env","NODE_ENV","Fragment","backgroundColor","overflow","fontSize","props","children"],"sources":["ErrorBoundary.tsx"],"sourcesContent":["/*\n * Copyright 2025 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 * as React from \"react\";\n\ninterface State {\n error: unknown;\n}\n\n/**\n * Error boundary to catch and display errors in widget code.\n */\nexport class ErrorBoundary extends React.Component<\n React.PropsWithChildren,\n State\n> {\n state: State = { error: null };\n\n static getDerivedStateFromError(error: unknown): Partial<State> {\n return { error };\n }\n\n render(): React.ReactNode {\n if (this.state.error) {\n const errorDetails = this.state.error instanceof Error\n ? this.state.error.stack\n : \"See browser console for more details.\";\n\n return (\n <section style={{ padding: \"16px\" }}>\n <h3 style={{ margin: \"0 0 12px 0\", color: \"#c00\" }}>\n An uncaught error occurred\n </h3>\n {process.env.NODE_ENV !== \"production\" && (\n <>\n <p style={{ margin: \"0 0 8px 0\" }}>\n This error was caught by the widget framework's fallback error\n boundary.\n </p>\n <ul style={{ margin: \"0 0 16px 0\" }}>\n <li>\n Ensure errors are properly handled in your code with try-catch\n blocks and promise rejection handling.\n </li>\n <li>\n Add your own error boundary to replace this fallback with a\n custom error message or recovery options for your users.\n </li>\n <li>\n See:{\" \"}\n <code>\n https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary\n </code>\n </li>\n </ul>\n </>\n )}\n <pre\n style={{\n backgroundColor: \"#f5f5f5\",\n padding: \"12px\",\n overflow: \"auto\",\n fontSize: \"12px\",\n margin: 0,\n }}\n >\n {errorDetails}\n </pre>\n </section>\n );\n }\n\n return this.props.children;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAM9B;AACA;AACA;AACA,OAAO,MAAMC,aAAa,SAASD,KAAK,CAACE,SAAS,CAGhD;EACAC,KAAK,GAAU;IAAEC,KAAK,EAAE;EAAK,CAAC;EAE9B,OAAOC,wBAAwBA,CAACD,KAAc,EAAkB;IAC9D,OAAO;MAAEA;IAAM,CAAC;EAClB;EAEAE,MAAMA,CAAA,EAAoB;IACxB,IAAI,IAAI,CAACH,KAAK,CAACC,KAAK,EAAE;MACpB,MAAMG,YAAY,GAAG,IAAI,CAACJ,KAAK,CAACC,KAAK,YAAYI,KAAK,GAClD,IAAI,CAACL,KAAK,CAACC,KAAK,CAACK,KAAK,GACtB,uCAAuC;MAE3C,oBACET,KAAA,CAAAU,aAAA;QAASC,KAAK,EAAE;UAAEC,OAAO,EAAE;QAAO;MAAE,gBAClCZ,KAAA,CAAAU,aAAA;QAAIC,KAAK,EAAE;UAAEE,MAAM,EAAE,YAAY;UAAEC,KAAK,EAAE;QAAO;MAAE,GAAC,4BAEhD,CAAC,EACJC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,iBACpCjB,KAAA,CAAAU,aAAA,CAAAV,KAAA,CAAAkB,QAAA,qBACElB,KAAA,CAAAU,aAAA;QAAGC,KAAK,EAAE;UAAEE,MAAM,EAAE;QAAY;MAAE,GAAC,0EAGhC,CAAC,eACJb,KAAA,CAAAU,aAAA;QAAIC,KAAK,EAAE;UAAEE,MAAM,EAAE;QAAa;MAAE,gBAClCb,KAAA,CAAAU,aAAA,aAAI,uGAGA,CAAC,eACLV,KAAA,CAAAU,aAAA,aAAI,sHAGA,CAAC,eACLV,KAAA,CAAAU,aAAA,aAAI,MACE,EAAC,GAAG,eACRV,KAAA,CAAAU,aAAA,eAAM,8FAEA,CACJ,CACF,CACJ,CACH,eACDV,KAAA,CAAAU,aAAA;QACEC,KAAK,EAAE;UACLQ,eAAe,EAAE,SAAS;UAC1BP,OAAO,EAAE,MAAM;UACfQ,QAAQ,EAAE,MAAM;UAChBC,QAAQ,EAAE,MAAM;UAChBR,MAAM,EAAE;QACV;MAAE,GAEDN,YACE,CACE,CAAC;IAEd;IAEA,OAAO,IAAI,CAACe,KAAK,CAACC,QAAQ;EAC5B;AACF","ignoreList":[]}
@@ -17,6 +17,7 @@
17
17
  import { createFoundryWidgetClient } from "@osdk/widget.client";
18
18
  import React, { useEffect, useMemo, useRef } from "react";
19
19
  import { FoundryWidgetContext } from "./context.js";
20
+ import { ErrorBoundary } from "./ErrorBoundary.js";
20
21
  import { extendParametersWithObjectSets } from "./utils/extendParametersWithObjectSets.js";
21
22
  import { initializeParameters } from "./utils/initializeParameters.js";
22
23
  /**
@@ -95,8 +96,33 @@ export const FoundryWidget = ({
95
96
  });
96
97
  });
97
98
  client.ready();
99
+ const resizeObserver = new ResizeObserver(entries => {
100
+ if (entries.length !== 1) {
101
+ // eslint-disable-next-line no-console
102
+ console.error("Expected exactly one resize observer entry but received:", entries);
103
+ return;
104
+ }
105
+ const entry = entries[0];
106
+ if (entry.borderBoxSize.length !== 1) {
107
+ // eslint-disable-next-line no-console
108
+ console.error("Expected exactly one border box size but received:", entry.borderBoxSize);
109
+ return;
110
+ }
111
+ const {
112
+ inlineSize: width,
113
+ blockSize: height
114
+ } = entry.borderBoxSize[0];
115
+ client.resize({
116
+ width,
117
+ height
118
+ });
119
+ });
120
+ resizeObserver.observe(document.body, {
121
+ box: "border-box"
122
+ });
98
123
  return () => {
99
124
  client.unsubscribe();
125
+ resizeObserver.disconnect();
100
126
  };
101
127
  }, []);
102
128
  return /*#__PURE__*/React.createElement(FoundryWidgetContext.Provider, {
@@ -110,6 +136,6 @@ export const FoundryWidget = ({
110
136
  }
111
137
  // Unfortunately the context is statically defined so we can't use the generic type, hence the cast
112
138
  }
113
- }, children);
139
+ }, /*#__PURE__*/React.createElement(ErrorBoundary, null, children));
114
140
  };
115
141
  //# sourceMappingURL=client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":["createFoundryWidgetClient","React","useEffect","useMemo","useRef","FoundryWidgetContext","extendParametersWithObjectSets","initializeParameters","FoundryWidget","children","config","initialValues","client","osdkClient","asyncParameterValues","setAsyncParameterValues","useState","allParameterValues","setAllParameterValues","type","objectSetCache","Map","subscribe","hostEventTarget","addEventListener","payload","processedParameters","detail","parameters","current","currentParameters","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 { Client, ObjectSet } from \"@osdk/client\";\nimport type { ObjectType } from \"@osdk/widget.api\";\nimport type {\n AsyncValue,\n ParameterConfig,\n WidgetConfig,\n} from \"@osdk/widget.client\";\nimport { createFoundryWidgetClient } from \"@osdk/widget.client\";\nimport React, { useEffect, useMemo, useRef } from \"react\";\nimport type {\n ExtendedAsyncParameterValueMap,\n ExtendedParameterValueMap,\n FoundryWidgetClientContext,\n} from \"./context.js\";\nimport { FoundryWidgetContext } from \"./context.js\";\nimport { extendParametersWithObjectSets } from \"./utils/extendParametersWithObjectSets.js\";\nimport { initializeParameters } from \"./utils/initializeParameters.js\";\n\ntype ExtractObjectTypes<C extends WidgetConfig<C[\"parameters\"]>> =\n C[\"parameters\"][keyof C[\"parameters\"]] extends infer Param\n ? Param extends { type: \"objectSet\"; objectType: infer OT }\n ? OT extends ObjectType ? OT : never\n : never\n : never;\n\ntype HasObjectSetParameters<C extends WidgetConfig<C[\"parameters\"]>> =\n ExtractObjectTypes<C> extends never ? false : true;\n\ntype ObjectSetProps<C extends WidgetConfig<C[\"parameters\"]>> = {\n /**\n * Used to hydrate object sets from their RIDs for object set parameters\n */\n client: Client;\n};\n\ntype FoundryWidgetProps<C extends WidgetConfig<C[\"parameters\"]>> =\n & {\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?: ExtendedAsyncParameterValueMap<C>;\n }\n & Partial<ObjectSetProps<C>>\n & (HasObjectSetParameters<C> extends true ? ObjectSetProps<C> : {});\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 client: osdkClient,\n}: FoundryWidgetProps<C>): React.ReactElement<FoundryWidgetProps<C>> => {\n const client = useMemo(() => createFoundryWidgetClient<C>(), []);\n const [asyncParameterValues, setAsyncParameterValues] = React.useState<\n ExtendedAsyncParameterValueMap<C>\n >(initialValues ?? initializeParameters(config, \"not-started\"));\n const [allParameterValues, setAllParameterValues] = React.useState<\n AsyncValue<ExtendedParameterValueMap<C>>\n >({\n type: \"not-started\",\n });\n\n const objectSetCache = useRef<\n Map<string, { objectSetRid: string; objectSet: ObjectSet }>\n >(new Map());\n\n useEffect(() => {\n client.subscribe();\n client.hostEventTarget.addEventListener(\n \"host.update-parameters\",\n (payload) => {\n const processedParameters = extendParametersWithObjectSets(\n osdkClient,\n config,\n payload.detail.parameters,\n objectSetCache.current,\n );\n setAsyncParameterValues((currentParameters) => ({\n ...currentParameters,\n ...processedParameters,\n }));\n setAllParameterValues((currentParameters) => {\n let aggregatedLoadedState: AsyncValue<any>[\"type\"] = \"loaded\";\n let firstError: Error | undefined;\n const newParameterValues: ExtendedParameterValueMap<\n WidgetConfig<ParameterConfig>\n > = {};\n for (const key in processedParameters) {\n const value = processedParameters[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 ExtendedParameterValueMap<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,EAAEC,MAAM,QAAQ,OAAO;AAMzD,SAASC,oBAAoB,QAAQ,cAAc;AACnD,SAASC,8BAA8B,QAAQ,2CAA2C;AAC1F,SAASC,oBAAoB,QAAQ,iCA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EY,qBAAqB;YAC3BI,KAAK,EAAEG;UACT,CAAC;QACL,CAAC,MAAM;UACL,OAAO;YAAEnB,IAAI,EAAEY;UAAsB,CAAC;QACxC;MACF,CAAC,CAAC;IACJ,CACF,CAAC;IACDnB,MAAM,CAAC4B,KAAK,CAAC,CAAC;IACd,OAAO,MAAM;MACX5B,MAAM,CAAC6B,WAAW,CAAC,CAAC;IACtB,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,oBACExC,KAAA,CAAAyC,aAAA,CAACrC,oBAAoB,CAACsC,QAAQ;IAC5BR,KAAK,EAAE;MACLS,SAAS,EAAEhC,MAAM,CAACgC,SAAS;MAC3BrB,eAAe,EAAEX,MAAM,CAACW,eAAe;MACvCT,oBAAoB;MACpBc,UAAU,EAAE;QACViB,MAAM,EAAE5B,kBAAkB,CAACkB,KAAK,IAAI,CAAC,CAAC;QACtCW,KAAK,EAAE7B,kBAAkB,CAACE;MAC5B;MACA;IACF;EAA+D,GAE9DV,QAC4B,CAAC;AAEpC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"client.js","names":["createFoundryWidgetClient","React","useEffect","useMemo","useRef","FoundryWidgetContext","ErrorBoundary","extendParametersWithObjectSets","initializeParameters","FoundryWidget","children","config","initialValues","client","osdkClient","asyncParameterValues","setAsyncParameterValues","useState","allParameterValues","setAllParameterValues","type","objectSetCache","Map","subscribe","hostEventTarget","addEventListener","payload","processedParameters","detail","parameters","current","currentParameters","aggregatedLoadedState","firstError","newParameterValues","key","value","error","currentParameterValue","updatedValue","Error","ready","resizeObserver","ResizeObserver","entries","length","console","entry","borderBoxSize","inlineSize","width","blockSize","height","resize","observe","document","body","box","unsubscribe","disconnect","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 { Client, ObjectSet } from \"@osdk/client\";\nimport type { ObjectType } from \"@osdk/widget.api\";\nimport type {\n AsyncValue,\n ParameterConfig,\n WidgetConfig,\n} from \"@osdk/widget.client\";\nimport { createFoundryWidgetClient } from \"@osdk/widget.client\";\nimport React, { useEffect, useMemo, useRef } from \"react\";\nimport type {\n ExtendedAsyncParameterValueMap,\n ExtendedParameterValueMap,\n FoundryWidgetClientContext,\n} from \"./context.js\";\nimport { FoundryWidgetContext } from \"./context.js\";\nimport { ErrorBoundary } from \"./ErrorBoundary.js\";\nimport { extendParametersWithObjectSets } from \"./utils/extendParametersWithObjectSets.js\";\nimport { initializeParameters } from \"./utils/initializeParameters.js\";\n\ntype ExtractObjectTypes<C extends WidgetConfig<C[\"parameters\"]>> =\n C[\"parameters\"][keyof C[\"parameters\"]] extends infer Param\n ? Param extends { type: \"objectSet\"; objectType: infer OT }\n ? OT extends ObjectType ? OT\n : never\n : never\n : never;\n\ntype HasObjectSetParameters<C extends WidgetConfig<C[\"parameters\"]>> =\n ExtractObjectTypes<C> extends never ? false : true;\n\ntype ObjectSetProps<C extends WidgetConfig<C[\"parameters\"]>> = {\n /**\n * Used to hydrate object sets from their RIDs for object set parameters\n */\n client: Client;\n};\n\ntype FoundryWidgetProps<C extends WidgetConfig<C[\"parameters\"]>> =\n & {\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?: ExtendedAsyncParameterValueMap<C>;\n }\n & Partial<ObjectSetProps<C>>\n & (HasObjectSetParameters<C> extends true ? ObjectSetProps<C> : {});\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 client: osdkClient,\n}: FoundryWidgetProps<C>): React.ReactElement<FoundryWidgetProps<C>> => {\n const client = useMemo(() => createFoundryWidgetClient<C>(), []);\n const [asyncParameterValues, setAsyncParameterValues] = React.useState<\n ExtendedAsyncParameterValueMap<C>\n >(initialValues ?? initializeParameters(config, \"not-started\"));\n const [allParameterValues, setAllParameterValues] = React.useState<\n AsyncValue<ExtendedParameterValueMap<C>>\n >({\n type: \"not-started\",\n });\n\n const objectSetCache = useRef<\n Map<string, { objectSetRid: string; objectSet: ObjectSet }>\n >(new Map());\n\n useEffect(() => {\n client.subscribe();\n client.hostEventTarget.addEventListener(\n \"host.update-parameters\",\n (payload) => {\n const processedParameters = extendParametersWithObjectSets(\n osdkClient,\n config,\n payload.detail.parameters,\n objectSetCache.current,\n );\n setAsyncParameterValues((currentParameters) => ({\n ...currentParameters,\n ...processedParameters,\n }));\n setAllParameterValues((currentParameters) => {\n let aggregatedLoadedState: AsyncValue<any>[\"type\"] = \"loaded\";\n let firstError: Error | undefined;\n const newParameterValues: ExtendedParameterValueMap<\n WidgetConfig<ParameterConfig>\n > = {};\n for (const key in processedParameters) {\n const value = processedParameters[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 ExtendedParameterValueMap<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\n const resizeObserver = new ResizeObserver((entries) => {\n if (entries.length !== 1) {\n // eslint-disable-next-line no-console\n console.error(\n \"Expected exactly one resize observer entry but received:\",\n entries,\n );\n return;\n }\n const entry = entries[0];\n if (entry.borderBoxSize.length !== 1) {\n // eslint-disable-next-line no-console\n console.error(\n \"Expected exactly one border box size but received:\",\n entry.borderBoxSize,\n );\n return;\n }\n const { inlineSize: width, blockSize: height } = entry.borderBoxSize[0];\n client.resize({ width, height });\n });\n resizeObserver.observe(document.body, { box: \"border-box\" });\n\n return () => {\n client.unsubscribe();\n resizeObserver.disconnect();\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 <ErrorBoundary>\n {children}\n </ErrorBoundary>\n </FoundryWidgetContext.Provider>\n );\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;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AACiB,UAAU,CAAC,CAAC;IAC7B,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,oBACE1D,KAAA,CAAA2D,aAAA,CAACvD,oBAAoB,CAACwD,QAAQ;IAC5BzB,KAAK,EAAE;MACL0B,SAAS,EAAEjD,MAAM,CAACiD,SAAS;MAC3BtC,eAAe,EAAEX,MAAM,CAACW,eAAe;MACvCT,oBAAoB;MACpBc,UAAU,EAAE;QACVkC,MAAM,EAAE7C,kBAAkB,CAACkB,KAAK,IAAI,CAAC,CAAC;QACtC4B,KAAK,EAAE9C,kBAAkB,CAACE;MAC5B;MACA;IACF;EAA+D,gBAE/DnB,KAAA,CAAA2D,aAAA,CAACtD,aAAa,QACXI,QACY,CACc,CAAC;AAEpC,CAAC","ignoreList":[]}
@@ -4,12 +4,28 @@ var widget_client = require('@osdk/widget.client');
4
4
  var React2 = require('react');
5
5
  var internal = require('@osdk/client/internal');
6
6
 
7
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
+ function _interopNamespace(e) {
8
+ if (e && e.__esModule) return e;
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
18
+ }
19
+ });
20
+ }
21
+ n.default = e;
22
+ return Object.freeze(n);
23
+ }
8
24
 
9
- var React2__default = /*#__PURE__*/_interopDefault(React2);
25
+ var React2__namespace = /*#__PURE__*/_interopNamespace(React2);
10
26
 
11
27
  // src/client.tsx
12
- var FoundryWidgetContext = /* @__PURE__ */ React2__default.default.createContext({
28
+ var FoundryWidgetContext = /* @__PURE__ */ React2__namespace.default.createContext({
13
29
  emitEvent: () => {
14
30
  },
15
31
  hostEventTarget: new widget_client.FoundryHostEventTarget(),
@@ -30,6 +46,48 @@ function useFoundryWidgetContext() {
30
46
  }
31
47
  _useFoundryWidgetContext.withTypes = withTypes;
32
48
  })(useFoundryWidgetContext || (useFoundryWidgetContext = {}));
49
+ var ErrorBoundary = class extends React2__namespace.Component {
50
+ state = {
51
+ error: null
52
+ };
53
+ static getDerivedStateFromError(error) {
54
+ return {
55
+ error
56
+ };
57
+ }
58
+ render() {
59
+ if (this.state.error) {
60
+ const errorDetails = this.state.error instanceof Error ? this.state.error.stack : "See browser console for more details.";
61
+ return /* @__PURE__ */ React2__namespace.createElement("section", {
62
+ style: {
63
+ padding: "16px"
64
+ }
65
+ }, /* @__PURE__ */ React2__namespace.createElement("h3", {
66
+ style: {
67
+ margin: "0 0 12px 0",
68
+ color: "#c00"
69
+ }
70
+ }, "An uncaught error occurred"), process.env.NODE_ENV !== "production" && /* @__PURE__ */ React2__namespace.createElement(React2__namespace.Fragment, null, /* @__PURE__ */ React2__namespace.createElement("p", {
71
+ style: {
72
+ margin: "0 0 8px 0"
73
+ }
74
+ }, "This error was caught by the widget framework's fallback error boundary."), /* @__PURE__ */ React2__namespace.createElement("ul", {
75
+ style: {
76
+ margin: "0 0 16px 0"
77
+ }
78
+ }, /* @__PURE__ */ React2__namespace.createElement("li", null, "Ensure errors are properly handled in your code with try-catch blocks and promise rejection handling."), /* @__PURE__ */ React2__namespace.createElement("li", null, "Add your own error boundary to replace this fallback with a custom error message or recovery options for your users."), /* @__PURE__ */ React2__namespace.createElement("li", null, "See:", " ", /* @__PURE__ */ React2__namespace.createElement("code", null, "https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary")))), /* @__PURE__ */ React2__namespace.createElement("pre", {
79
+ style: {
80
+ backgroundColor: "#f5f5f5",
81
+ padding: "12px",
82
+ overflow: "auto",
83
+ fontSize: "12px",
84
+ margin: 0
85
+ }
86
+ }, errorDetails));
87
+ }
88
+ return this.props.children;
89
+ }
90
+ };
33
91
  function extendParametersWithObjectSets(osdkClient, config, parameters, cache) {
34
92
  const extendedParameters = {
35
93
  ...parameters
@@ -87,8 +145,8 @@ var FoundryWidget = ({
87
145
  client: osdkClient
88
146
  }) => {
89
147
  const client = React2.useMemo(() => widget_client.createFoundryWidgetClient(), []);
90
- const [asyncParameterValues, setAsyncParameterValues] = React2__default.default.useState(initialValues ?? initializeParameters(config, "not-started"));
91
- const [allParameterValues, setAllParameterValues] = React2__default.default.useState({
148
+ const [asyncParameterValues, setAsyncParameterValues] = React2__namespace.default.useState(initialValues ?? initializeParameters(config, "not-started"));
149
+ const [allParameterValues, setAllParameterValues] = React2__namespace.default.useState({
92
150
  type: "not-started"
93
151
  });
94
152
  const objectSetCache = React2.useRef(/* @__PURE__ */ new Map());
@@ -150,11 +208,34 @@ var FoundryWidget = ({
150
208
  });
151
209
  });
152
210
  client.ready();
211
+ const resizeObserver = new ResizeObserver((entries) => {
212
+ if (entries.length !== 1) {
213
+ console.error("Expected exactly one resize observer entry but received:", entries);
214
+ return;
215
+ }
216
+ const entry = entries[0];
217
+ if (entry.borderBoxSize.length !== 1) {
218
+ console.error("Expected exactly one border box size but received:", entry.borderBoxSize);
219
+ return;
220
+ }
221
+ const {
222
+ inlineSize: width,
223
+ blockSize: height
224
+ } = entry.borderBoxSize[0];
225
+ client.resize({
226
+ width,
227
+ height
228
+ });
229
+ });
230
+ resizeObserver.observe(document.body, {
231
+ box: "border-box"
232
+ });
153
233
  return () => {
154
234
  client.unsubscribe();
235
+ resizeObserver.disconnect();
155
236
  };
156
237
  }, []);
157
- return /* @__PURE__ */ React2__default.default.createElement(FoundryWidgetContext.Provider, {
238
+ return /* @__PURE__ */ React2__namespace.default.createElement(FoundryWidgetContext.Provider, {
158
239
  value: {
159
240
  emitEvent: client.emitEvent,
160
241
  hostEventTarget: client.hostEventTarget,
@@ -165,7 +246,7 @@ var FoundryWidget = ({
165
246
  }
166
247
  // Unfortunately the context is statically defined so we can't use the generic type, hence the cast
167
248
  }
168
- }, children);
249
+ }, /* @__PURE__ */ React2__namespace.default.createElement(ErrorBoundary, null, children));
169
250
  };
170
251
 
171
252
  exports.FoundryWidget = FoundryWidget;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context.ts","../../src/utils/extendParametersWithObjectSets.ts","../../src/utils/initializeParameters.ts","../../src/client.tsx"],"names":["FoundryHostEventTarget","useContext","hydrateObjectSetFromRid","useMemo","createFoundryWidgetClient","React","useRef","useEffect"],"mappings":";;;;;;;;;;;AAkBO,IAAM,oBAAA,2CAA0C,aAAc,CAAA;AAAA,EACnE,WAAW,MAAM;AAAA,GAAC;AAAA,EAClB,eAAA,EAAiB,IAAIA,oCAAuB,EAAA;AAAA,EAC5C,sBAAsB,EAAC;AAAA,EACvB,UAAY,EAAA;AAAA,IACV,KAAO,EAAA,aAAA;AAAA,IACP,QAAQ;AAAC;AAEb,CAAC,CAAA;AAKM,SAAS,uBAA0B,GAAA;AACxC,EAAA,OAAOC,kBAAW,oBAAoB,CAAA;AACxC;AAAA,CACC,SAAU,wBAA0B,EAAA;AACnC,EAAA,SAAS,SAAY,GAAA;AACnB,IAAA,OAAO,MAAM;AACX,MAAA,OAAO,uBAAwB,EAAA;AAAA,KACjC;AAAA;AAEF,EAAA,wBAAA,CAAyB,SAAY,GAAA,SAAA;AACvC,CAAG,EAAA,uBAAA,KAA4B,uBAA0B,GAAA,EAAG,CAAA,CAAA;AClBrD,SAAS,8BAA+B,CAAA,UAAA,EAAY,MAAQ,EAAA,UAAA,EAAY,KAAO,EAAA;AACpF,EAAA,MAAM,kBAAqB,GAAA;AAAA,IACzB,GAAG;AAAA,GACL;AACA,EAAA,KAAA,MAAW,WAAe,IAAA,MAAA,CAAO,IAAK,CAAA,kBAAkB,CAAG,EAAA;AACzD,IAAM,MAAA,KAAA,GAAQ,MAAO,CAAA,UAAA,CAAW,WAAW,CAAA;AAC3C,IAAA,IAAI,MAAM,IAAS,KAAA,WAAA,IAAe,mBAAmB,WAAW,CAAA,CAAE,SAAS,WAAa,EAAA;AACtF,MAAA,MAAM,cAAiB,GAAA,kBAAA,CAAmB,WAAW,CAAA,CAAE,KAAM,CAAA,KAAA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,OAAO,0BAA0B,QAAW,GAAA;AAAA,YAC1C,IAAM,EAAA,qBAAA;AAAA,YACN,KAAO,EAAA,YAAA;AAAA,YACP,KAAO,EAAA,UAAA,IAAc,IAAI,KAAA,CAAM,2BAA2B;AAAA,WACxD,GAAA;AAAA,YACF,IAAM,EAAA,qBAAA;AAAA,YACN,KAAO,EAAA;AAAA,WACT;AAAA,SACK,MAAA;AACL,UAAO,OAAA;AAAA,YACL,IAAM,EAAA;AAAA,WACR;AAAA;AACF,OACD,CAAA;AAAA,KACF,CAAA;AACD,IAAA,MAAA,CAAO,KAAM,EAAA;AACb,IAAA,OAAO,MAAM;AACX,MAAA,MAAA,CAAO,WAAY,EAAA;AAAA,KACrB;AAAA,GACF,EAAG,EAAE,CAAA;AACL,EAAA,uBAAoBF,uBAAAA,CAAM,aAAc,CAAA,oBAAA,CAAqB,QAAU,EAAA;AAAA,IACrE,KAAO,EAAA;AAAA,MACL,WAAW,MAAO,CAAA,SAAA;AAAA,MAClB,iBAAiB,MAAO,CAAA,eAAA;AAAA,MACxB,oBAAA;AAAA,MACA,UAAY,EAAA;AAAA,QACV,MAAA,EAAQ,kBAAmB,CAAA,KAAA,IAAS,EAAC;AAAA,QACrC,OAAO,kBAAmB,CAAA;AAAA;AAC5B;AAAA;AAEF,KACC,QAAQ,CAAA;AACb","file":"index.cjs","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 { FoundryHostEventTarget } from \"@osdk/widget.client\";\nimport React, { useContext } from \"react\";\nexport const FoundryWidgetContext = /*#__PURE__*/React.createContext({\n emitEvent: () => {},\n hostEventTarget: new FoundryHostEventTarget(),\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 return useContext(FoundryWidgetContext);\n}\n(function (_useFoundryWidgetContext) {\n function withTypes() {\n return () => {\n return useFoundryWidgetContext();\n };\n }\n _useFoundryWidgetContext.withTypes = withTypes;\n})(useFoundryWidgetContext || (useFoundryWidgetContext = {}));","/*\n * Copyright 2025 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 { hydrateObjectSetFromRid } from \"@osdk/client/internal\";\n/**\n * Patches parameter values with hydrated object sets for object set parameters.\n *\n * The cache is used to avoid redundant hydration of the same object set RID, which\n * can cause unnecessary re-renders in React components consuming the parameters.\n */\nexport function extendParametersWithObjectSets(osdkClient, config, parameters, cache) {\n const extendedParameters = {\n ...parameters\n };\n for (const parameterId of Object.keys(extendedParameters)) {\n const param = config.parameters[parameterId];\n if (param.type === \"objectSet\" && extendedParameters[parameterId].type === \"objectSet\") {\n const parameterValue = extendedParameters[parameterId].value.value;\n if (parameterValue != null) {\n if (typeof parameterValue === \"object\" && \"objectSetRid\" in parameterValue && typeof parameterValue.objectSetRid === \"string\") {\n const objectSetRid = parameterValue.objectSetRid;\n const objectSet = getOrHydrateObjectSet(osdkClient, cache, parameterId, objectSetRid, param.objectType);\n parameterValue.objectSet = objectSet;\n } else {\n throw new Error(`Invalid object set parameter value for parameter \"${parameterId}\"`);\n }\n } else {\n cache.delete(parameterId);\n }\n }\n }\n return extendedParameters;\n}\nfunction getOrHydrateObjectSet(osdkClient, cache, paramKey, objectSetRid, definition) {\n if (osdkClient == null) {\n throw new Error(\"Not provided an OSDK client\");\n }\n const cached = cache.get(paramKey);\n if (cached?.objectSetRid === objectSetRid) {\n return cached.objectSet;\n }\n const objectSet = hydrateObjectSetFromRid(osdkClient, definition, objectSetRid);\n cache.set(paramKey, {\n objectSetRid,\n objectSet\n });\n return objectSet;\n}","/*\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\n/**\n * Utility function to initialize a map of parameter values to either a loading or not-started loading state\n */\nexport function initializeParameters(config, initialLoadingState) {\n return Object.fromEntries(Object.entries(config.parameters).map(([key, parameterConfig]) => [key, {\n type: parameterConfig.type,\n value: {\n type: initialLoadingState\n }\n }]));\n}","/*\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 { createFoundryWidgetClient } from \"@osdk/widget.client\";\nimport React, { useEffect, useMemo, useRef } from \"react\";\nimport { FoundryWidgetContext } from \"./context.js\";\nimport { extendParametersWithObjectSets } from \"./utils/extendParametersWithObjectSets.js\";\nimport { initializeParameters } from \"./utils/initializeParameters.js\";\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 = ({\n children,\n config,\n initialValues,\n client: osdkClient\n}) => {\n const client = useMemo(() => createFoundryWidgetClient(), []);\n const [asyncParameterValues, setAsyncParameterValues] = React.useState(initialValues ?? initializeParameters(config, \"not-started\"));\n const [allParameterValues, setAllParameterValues] = React.useState({\n type: \"not-started\"\n });\n const objectSetCache = useRef(new Map());\n useEffect(() => {\n client.subscribe();\n client.hostEventTarget.addEventListener(\"host.update-parameters\", payload => {\n const processedParameters = extendParametersWithObjectSets(osdkClient, config, payload.detail.parameters, objectSetCache.current);\n setAsyncParameterValues(currentParameters => ({\n ...currentParameters,\n ...processedParameters\n }));\n setAllParameterValues(currentParameters => {\n let aggregatedLoadedState = \"loaded\";\n let firstError;\n const newParameterValues = {};\n for (const key in processedParameters) {\n const value = processedParameters[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] = value.value;\n continue;\n }\n // If any is loading, consider all of it loading unless we have failed somewhere\n if (value.type === \"loading\" && aggregatedLoadedState !== \"failed\") {\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 (value.type === \"reloading\" && aggregatedLoadedState !== \"failed\" && aggregatedLoadedState !== \"loading\") {\n aggregatedLoadedState = \"reloading\";\n newParameterValues[key] = value.value;\n continue;\n }\n if (value.type === \"not-started\" && aggregatedLoadedState !== \"failed\" && aggregatedLoadedState !== \"loading\" && aggregatedLoadedState !== \"reloading\") {\n aggregatedLoadedState = \"not-started\";\n }\n if (value.type === \"loaded\") {\n newParameterValues[key] = value.value;\n }\n }\n const currentParameterValue = currentParameters.type !== \"not-started\" && currentParameters.type !== \"loading\" ? currentParameters.value : {};\n if (aggregatedLoadedState !== \"not-started\" && aggregatedLoadedState !== \"loading\") {\n const updatedValue = {\n ...currentParameterValue,\n ...newParameterValues\n };\n return aggregatedLoadedState === \"failed\" ? {\n type: aggregatedLoadedState,\n value: updatedValue,\n error: firstError ?? new Error(\"Failed to load parameters\")\n } : {\n type: aggregatedLoadedState,\n value: updatedValue\n };\n } else {\n return {\n type: aggregatedLoadedState\n };\n }\n });\n });\n client.ready();\n return () => {\n client.unsubscribe();\n };\n }, []);\n return /*#__PURE__*/React.createElement(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 }\n }, children);\n};"]}
1
+ {"version":3,"sources":["../../src/context.ts","../../src/ErrorBoundary.tsx","../../src/utils/extendParametersWithObjectSets.ts","../../src/utils/initializeParameters.ts","../../src/client.tsx"],"names":["FoundryHostEventTarget","useContext","React2","hydrateObjectSetFromRid","useMemo","createFoundryWidgetClient","React","useRef","useEffect"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBO,IAAM,oBAAA,6CAA0C,aAAc,CAAA;AAAA,EACnE,WAAW,MAAM;AAAA,GAAC;AAAA,EAClB,eAAA,EAAiB,IAAIA,oCAAuB,EAAA;AAAA,EAC5C,sBAAsB,EAAC;AAAA,EACvB,UAAY,EAAA;AAAA,IACV,KAAO,EAAA,aAAA;AAAA,IACP,QAAQ;AAAC;AAEb,CAAC,CAAA;AAKM,SAAS,uBAA0B,GAAA;AACxC,EAAA,OAAOC,kBAAW,oBAAoB,CAAA;AACxC;AAAA,CACC,SAAU,wBAA0B,EAAA;AACnC,EAAA,SAAS,SAAY,GAAA;AACnB,IAAA,OAAO,MAAM;AACX,MAAA,OAAO,uBAAwB,EAAA;AAAA,KACjC;AAAA;AAEF,EAAA,wBAAA,CAAyB,SAAY,GAAA,SAAA;AACvC,CAAG,EAAA,uBAAA,KAA4B,uBAA0B,GAAA,EAA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pE","file":"index.cjs","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 { FoundryHostEventTarget } from \"@osdk/widget.client\";\nimport React, { useContext } from \"react\";\nexport const FoundryWidgetContext = /*#__PURE__*/React.createContext({\n emitEvent: () => {},\n hostEventTarget: new FoundryHostEventTarget(),\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 return useContext(FoundryWidgetContext);\n}\n(function (_useFoundryWidgetContext) {\n function withTypes() {\n return () => {\n return useFoundryWidgetContext();\n };\n }\n _useFoundryWidgetContext.withTypes = withTypes;\n})(useFoundryWidgetContext || (useFoundryWidgetContext = {}));","/*\n * Copyright 2025 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 * as React from \"react\";\n/**\n * Error boundary to catch and display errors in widget code.\n */\nexport class ErrorBoundary extends React.Component {\n state = {\n error: null\n };\n static getDerivedStateFromError(error) {\n return {\n error\n };\n }\n render() {\n if (this.state.error) {\n const errorDetails = this.state.error instanceof Error ? this.state.error.stack : \"See browser console for more details.\";\n return /*#__PURE__*/React.createElement(\"section\", {\n style: {\n padding: \"16px\"\n }\n }, /*#__PURE__*/React.createElement(\"h3\", {\n style: {\n margin: \"0 0 12px 0\",\n color: \"#c00\"\n }\n }, \"An uncaught error occurred\"), process.env.NODE_ENV !== \"production\" && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(\"p\", {\n style: {\n margin: \"0 0 8px 0\"\n }\n }, \"This error was caught by the widget framework's fallback error boundary.\"), /*#__PURE__*/React.createElement(\"ul\", {\n style: {\n margin: \"0 0 16px 0\"\n }\n }, /*#__PURE__*/React.createElement(\"li\", null, \"Ensure errors are properly handled in your code with try-catch blocks and promise rejection handling.\"), /*#__PURE__*/React.createElement(\"li\", null, \"Add your own error boundary to replace this fallback with a custom error message or recovery options for your users.\"), /*#__PURE__*/React.createElement(\"li\", null, \"See:\", \" \", /*#__PURE__*/React.createElement(\"code\", null, \"https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary\")))), /*#__PURE__*/React.createElement(\"pre\", {\n style: {\n backgroundColor: \"#f5f5f5\",\n padding: \"12px\",\n overflow: \"auto\",\n fontSize: \"12px\",\n margin: 0\n }\n }, errorDetails));\n }\n return this.props.children;\n }\n}","/*\n * Copyright 2025 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 { hydrateObjectSetFromRid } from \"@osdk/client/internal\";\n/**\n * Patches parameter values with hydrated object sets for object set parameters.\n *\n * The cache is used to avoid redundant hydration of the same object set RID, which\n * can cause unnecessary re-renders in React components consuming the parameters.\n */\nexport function extendParametersWithObjectSets(osdkClient, config, parameters, cache) {\n const extendedParameters = {\n ...parameters\n };\n for (const parameterId of Object.keys(extendedParameters)) {\n const param = config.parameters[parameterId];\n if (param.type === \"objectSet\" && extendedParameters[parameterId].type === \"objectSet\") {\n const parameterValue = extendedParameters[parameterId].value.value;\n if (parameterValue != null) {\n if (typeof parameterValue === \"object\" && \"objectSetRid\" in parameterValue && typeof parameterValue.objectSetRid === \"string\") {\n const objectSetRid = parameterValue.objectSetRid;\n const objectSet = getOrHydrateObjectSet(osdkClient, cache, parameterId, objectSetRid, param.objectType);\n parameterValue.objectSet = objectSet;\n } else {\n throw new Error(`Invalid object set parameter value for parameter \"${parameterId}\"`);\n }\n } else {\n cache.delete(parameterId);\n }\n }\n }\n return extendedParameters;\n}\nfunction getOrHydrateObjectSet(osdkClient, cache, paramKey, objectSetRid, definition) {\n if (osdkClient == null) {\n throw new Error(\"Not provided an OSDK client\");\n }\n const cached = cache.get(paramKey);\n if (cached?.objectSetRid === objectSetRid) {\n return cached.objectSet;\n }\n const objectSet = hydrateObjectSetFromRid(osdkClient, definition, objectSetRid);\n cache.set(paramKey, {\n objectSetRid,\n objectSet\n });\n return objectSet;\n}","/*\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\n/**\n * Utility function to initialize a map of parameter values to either a loading or not-started loading state\n */\nexport function initializeParameters(config, initialLoadingState) {\n return Object.fromEntries(Object.entries(config.parameters).map(([key, parameterConfig]) => [key, {\n type: parameterConfig.type,\n value: {\n type: initialLoadingState\n }\n }]));\n}","/*\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 { createFoundryWidgetClient } from \"@osdk/widget.client\";\nimport React, { useEffect, useMemo, useRef } from \"react\";\nimport { FoundryWidgetContext } from \"./context.js\";\nimport { ErrorBoundary } from \"./ErrorBoundary.js\";\nimport { extendParametersWithObjectSets } from \"./utils/extendParametersWithObjectSets.js\";\nimport { initializeParameters } from \"./utils/initializeParameters.js\";\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 = ({\n children,\n config,\n initialValues,\n client: osdkClient\n}) => {\n const client = useMemo(() => createFoundryWidgetClient(), []);\n const [asyncParameterValues, setAsyncParameterValues] = React.useState(initialValues ?? initializeParameters(config, \"not-started\"));\n const [allParameterValues, setAllParameterValues] = React.useState({\n type: \"not-started\"\n });\n const objectSetCache = useRef(new Map());\n useEffect(() => {\n client.subscribe();\n client.hostEventTarget.addEventListener(\"host.update-parameters\", payload => {\n const processedParameters = extendParametersWithObjectSets(osdkClient, config, payload.detail.parameters, objectSetCache.current);\n setAsyncParameterValues(currentParameters => ({\n ...currentParameters,\n ...processedParameters\n }));\n setAllParameterValues(currentParameters => {\n let aggregatedLoadedState = \"loaded\";\n let firstError;\n const newParameterValues = {};\n for (const key in processedParameters) {\n const value = processedParameters[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] = value.value;\n continue;\n }\n // If any is loading, consider all of it loading unless we have failed somewhere\n if (value.type === \"loading\" && aggregatedLoadedState !== \"failed\") {\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 (value.type === \"reloading\" && aggregatedLoadedState !== \"failed\" && aggregatedLoadedState !== \"loading\") {\n aggregatedLoadedState = \"reloading\";\n newParameterValues[key] = value.value;\n continue;\n }\n if (value.type === \"not-started\" && aggregatedLoadedState !== \"failed\" && aggregatedLoadedState !== \"loading\" && aggregatedLoadedState !== \"reloading\") {\n aggregatedLoadedState = \"not-started\";\n }\n if (value.type === \"loaded\") {\n newParameterValues[key] = value.value;\n }\n }\n const currentParameterValue = currentParameters.type !== \"not-started\" && currentParameters.type !== \"loading\" ? currentParameters.value : {};\n if (aggregatedLoadedState !== \"not-started\" && aggregatedLoadedState !== \"loading\") {\n const updatedValue = {\n ...currentParameterValue,\n ...newParameterValues\n };\n return aggregatedLoadedState === \"failed\" ? {\n type: aggregatedLoadedState,\n value: updatedValue,\n error: firstError ?? new Error(\"Failed to load parameters\")\n } : {\n type: aggregatedLoadedState,\n value: updatedValue\n };\n } else {\n return {\n type: aggregatedLoadedState\n };\n }\n });\n });\n client.ready();\n const resizeObserver = new ResizeObserver(entries => {\n if (entries.length !== 1) {\n // eslint-disable-next-line no-console\n console.error(\"Expected exactly one resize observer entry but received:\", entries);\n return;\n }\n const entry = entries[0];\n if (entry.borderBoxSize.length !== 1) {\n // eslint-disable-next-line no-console\n console.error(\"Expected exactly one border box size but received:\", entry.borderBoxSize);\n return;\n }\n const {\n inlineSize: width,\n blockSize: height\n } = entry.borderBoxSize[0];\n client.resize({\n width,\n height\n });\n });\n resizeObserver.observe(document.body, {\n box: \"border-box\"\n });\n return () => {\n client.unsubscribe();\n resizeObserver.disconnect();\n };\n }, []);\n return /*#__PURE__*/React.createElement(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 }\n }, /*#__PURE__*/React.createElement(ErrorBoundary, null, children));\n};"]}
@@ -0,0 +1,63 @@
1
+ /*
2
+ * Copyright 2025 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 * as React from "react";
18
+ /**
19
+ * Error boundary to catch and display errors in widget code.
20
+ */
21
+ export class ErrorBoundary extends React.Component {
22
+ state = {
23
+ error: null
24
+ };
25
+ static getDerivedStateFromError(error) {
26
+ return {
27
+ error
28
+ };
29
+ }
30
+ render() {
31
+ if (this.state.error) {
32
+ const errorDetails = this.state.error instanceof Error ? this.state.error.stack : "See browser console for more details.";
33
+ return /*#__PURE__*/React.createElement("section", {
34
+ style: {
35
+ padding: "16px"
36
+ }
37
+ }, /*#__PURE__*/React.createElement("h3", {
38
+ style: {
39
+ margin: "0 0 12px 0",
40
+ color: "#c00"
41
+ }
42
+ }, "An uncaught error occurred"), process.env.NODE_ENV !== "production" && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("p", {
43
+ style: {
44
+ margin: "0 0 8px 0"
45
+ }
46
+ }, "This error was caught by the widget framework's fallback error boundary."), /*#__PURE__*/React.createElement("ul", {
47
+ style: {
48
+ margin: "0 0 16px 0"
49
+ }
50
+ }, /*#__PURE__*/React.createElement("li", null, "Ensure errors are properly handled in your code with try-catch blocks and promise rejection handling."), /*#__PURE__*/React.createElement("li", null, "Add your own error boundary to replace this fallback with a custom error message or recovery options for your users."), /*#__PURE__*/React.createElement("li", null, "See:", " ", /*#__PURE__*/React.createElement("code", null, "https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary")))), /*#__PURE__*/React.createElement("pre", {
51
+ style: {
52
+ backgroundColor: "#f5f5f5",
53
+ padding: "12px",
54
+ overflow: "auto",
55
+ fontSize: "12px",
56
+ margin: 0
57
+ }
58
+ }, errorDetails));
59
+ }
60
+ return this.props.children;
61
+ }
62
+ }
63
+ //# sourceMappingURL=ErrorBoundary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorBoundary.js","names":["React","ErrorBoundary","Component","state","error","getDerivedStateFromError","render","errorDetails","Error","stack","createElement","style","padding","margin","color","process","env","NODE_ENV","Fragment","backgroundColor","overflow","fontSize","props","children"],"sources":["ErrorBoundary.tsx"],"sourcesContent":["/*\n * Copyright 2025 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 * as React from \"react\";\n\ninterface State {\n error: unknown;\n}\n\n/**\n * Error boundary to catch and display errors in widget code.\n */\nexport class ErrorBoundary extends React.Component<\n React.PropsWithChildren,\n State\n> {\n state: State = { error: null };\n\n static getDerivedStateFromError(error: unknown): Partial<State> {\n return { error };\n }\n\n render(): React.ReactNode {\n if (this.state.error) {\n const errorDetails = this.state.error instanceof Error\n ? this.state.error.stack\n : \"See browser console for more details.\";\n\n return (\n <section style={{ padding: \"16px\" }}>\n <h3 style={{ margin: \"0 0 12px 0\", color: \"#c00\" }}>\n An uncaught error occurred\n </h3>\n {process.env.NODE_ENV !== \"production\" && (\n <>\n <p style={{ margin: \"0 0 8px 0\" }}>\n This error was caught by the widget framework's fallback error\n boundary.\n </p>\n <ul style={{ margin: \"0 0 16px 0\" }}>\n <li>\n Ensure errors are properly handled in your code with try-catch\n blocks and promise rejection handling.\n </li>\n <li>\n Add your own error boundary to replace this fallback with a\n custom error message or recovery options for your users.\n </li>\n <li>\n See:{\" \"}\n <code>\n https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary\n </code>\n </li>\n </ul>\n </>\n )}\n <pre\n style={{\n backgroundColor: \"#f5f5f5\",\n padding: \"12px\",\n overflow: \"auto\",\n fontSize: \"12px\",\n margin: 0,\n }}\n >\n {errorDetails}\n </pre>\n </section>\n );\n }\n\n return this.props.children;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAM9B;AACA;AACA;AACA,OAAO,MAAMC,aAAa,SAASD,KAAK,CAACE,SAAS,CAGhD;EACAC,KAAK,GAAU;IAAEC,KAAK,EAAE;EAAK,CAAC;EAE9B,OAAOC,wBAAwBA,CAACD,KAAc,EAAkB;IAC9D,OAAO;MAAEA;IAAM,CAAC;EAClB;EAEAE,MAAMA,CAAA,EAAoB;IACxB,IAAI,IAAI,CAACH,KAAK,CAACC,KAAK,EAAE;MACpB,MAAMG,YAAY,GAAG,IAAI,CAACJ,KAAK,CAACC,KAAK,YAAYI,KAAK,GAClD,IAAI,CAACL,KAAK,CAACC,KAAK,CAACK,KAAK,GACtB,uCAAuC;MAE3C,oBACET,KAAA,CAAAU,aAAA;QAASC,KAAK,EAAE;UAAEC,OAAO,EAAE;QAAO;MAAE,gBAClCZ,KAAA,CAAAU,aAAA;QAAIC,KAAK,EAAE;UAAEE,MAAM,EAAE,YAAY;UAAEC,KAAK,EAAE;QAAO;MAAE,GAAC,4BAEhD,CAAC,EACJC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,iBACpCjB,KAAA,CAAAU,aAAA,CAAAV,KAAA,CAAAkB,QAAA,qBACElB,KAAA,CAAAU,aAAA;QAAGC,KAAK,EAAE;UAAEE,MAAM,EAAE;QAAY;MAAE,GAAC,0EAGhC,CAAC,eACJb,KAAA,CAAAU,aAAA;QAAIC,KAAK,EAAE;UAAEE,MAAM,EAAE;QAAa;MAAE,gBAClCb,KAAA,CAAAU,aAAA,aAAI,uGAGA,CAAC,eACLV,KAAA,CAAAU,aAAA,aAAI,sHAGA,CAAC,eACLV,KAAA,CAAAU,aAAA,aAAI,MACE,EAAC,GAAG,eACRV,KAAA,CAAAU,aAAA,eAAM,8FAEA,CACJ,CACF,CACJ,CACH,eACDV,KAAA,CAAAU,aAAA;QACEC,KAAK,EAAE;UACLQ,eAAe,EAAE,SAAS;UAC1BP,OAAO,EAAE,MAAM;UACfQ,QAAQ,EAAE,MAAM;UAChBC,QAAQ,EAAE,MAAM;UAChBR,MAAM,EAAE;QACV;MAAE,GAEDN,YACE,CACE,CAAC;IAEd;IAEA,OAAO,IAAI,CAACe,KAAK,CAACC,QAAQ;EAC5B;AACF","ignoreList":[]}
@@ -17,6 +17,7 @@
17
17
  import { createFoundryWidgetClient } from "@osdk/widget.client";
18
18
  import React, { useEffect, useMemo, useRef } from "react";
19
19
  import { FoundryWidgetContext } from "./context.js";
20
+ import { ErrorBoundary } from "./ErrorBoundary.js";
20
21
  import { extendParametersWithObjectSets } from "./utils/extendParametersWithObjectSets.js";
21
22
  import { initializeParameters } from "./utils/initializeParameters.js";
22
23
  /**
@@ -95,8 +96,33 @@ export const FoundryWidget = ({
95
96
  });
96
97
  });
97
98
  client.ready();
99
+ const resizeObserver = new ResizeObserver(entries => {
100
+ if (entries.length !== 1) {
101
+ // eslint-disable-next-line no-console
102
+ console.error("Expected exactly one resize observer entry but received:", entries);
103
+ return;
104
+ }
105
+ const entry = entries[0];
106
+ if (entry.borderBoxSize.length !== 1) {
107
+ // eslint-disable-next-line no-console
108
+ console.error("Expected exactly one border box size but received:", entry.borderBoxSize);
109
+ return;
110
+ }
111
+ const {
112
+ inlineSize: width,
113
+ blockSize: height
114
+ } = entry.borderBoxSize[0];
115
+ client.resize({
116
+ width,
117
+ height
118
+ });
119
+ });
120
+ resizeObserver.observe(document.body, {
121
+ box: "border-box"
122
+ });
98
123
  return () => {
99
124
  client.unsubscribe();
125
+ resizeObserver.disconnect();
100
126
  };
101
127
  }, []);
102
128
  return /*#__PURE__*/React.createElement(FoundryWidgetContext.Provider, {
@@ -110,6 +136,6 @@ export const FoundryWidget = ({
110
136
  }
111
137
  // Unfortunately the context is statically defined so we can't use the generic type, hence the cast
112
138
  }
113
- }, children);
139
+ }, /*#__PURE__*/React.createElement(ErrorBoundary, null, children));
114
140
  };
115
141
  //# sourceMappingURL=client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":["createFoundryWidgetClient","React","useEffect","useMemo","useRef","FoundryWidgetContext","extendParametersWithObjectSets","initializeParameters","FoundryWidget","children","config","initialValues","client","osdkClient","asyncParameterValues","setAsyncParameterValues","useState","allParameterValues","setAllParameterValues","type","objectSetCache","Map","subscribe","hostEventTarget","addEventListener","payload","processedParameters","detail","parameters","current","currentParameters","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 { Client, ObjectSet } from \"@osdk/client\";\nimport type { ObjectType } from \"@osdk/widget.api\";\nimport type {\n AsyncValue,\n ParameterConfig,\n WidgetConfig,\n} from \"@osdk/widget.client\";\nimport { createFoundryWidgetClient } from \"@osdk/widget.client\";\nimport React, { useEffect, useMemo, useRef } from \"react\";\nimport type {\n ExtendedAsyncParameterValueMap,\n ExtendedParameterValueMap,\n FoundryWidgetClientContext,\n} from \"./context.js\";\nimport { FoundryWidgetContext } from \"./context.js\";\nimport { extendParametersWithObjectSets } from \"./utils/extendParametersWithObjectSets.js\";\nimport { initializeParameters } from \"./utils/initializeParameters.js\";\n\ntype ExtractObjectTypes<C extends WidgetConfig<C[\"parameters\"]>> =\n C[\"parameters\"][keyof C[\"parameters\"]] extends infer Param\n ? Param extends { type: \"objectSet\"; objectType: infer OT }\n ? OT extends ObjectType ? OT : never\n : never\n : never;\n\ntype HasObjectSetParameters<C extends WidgetConfig<C[\"parameters\"]>> =\n ExtractObjectTypes<C> extends never ? false : true;\n\ntype ObjectSetProps<C extends WidgetConfig<C[\"parameters\"]>> = {\n /**\n * Used to hydrate object sets from their RIDs for object set parameters\n */\n client: Client;\n};\n\ntype FoundryWidgetProps<C extends WidgetConfig<C[\"parameters\"]>> =\n & {\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?: ExtendedAsyncParameterValueMap<C>;\n }\n & Partial<ObjectSetProps<C>>\n & (HasObjectSetParameters<C> extends true ? ObjectSetProps<C> : {});\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 client: osdkClient,\n}: FoundryWidgetProps<C>): React.ReactElement<FoundryWidgetProps<C>> => {\n const client = useMemo(() => createFoundryWidgetClient<C>(), []);\n const [asyncParameterValues, setAsyncParameterValues] = React.useState<\n ExtendedAsyncParameterValueMap<C>\n >(initialValues ?? initializeParameters(config, \"not-started\"));\n const [allParameterValues, setAllParameterValues] = React.useState<\n AsyncValue<ExtendedParameterValueMap<C>>\n >({\n type: \"not-started\",\n });\n\n const objectSetCache = useRef<\n Map<string, { objectSetRid: string; objectSet: ObjectSet }>\n >(new Map());\n\n useEffect(() => {\n client.subscribe();\n client.hostEventTarget.addEventListener(\n \"host.update-parameters\",\n (payload) => {\n const processedParameters = extendParametersWithObjectSets(\n osdkClient,\n config,\n payload.detail.parameters,\n objectSetCache.current,\n );\n setAsyncParameterValues((currentParameters) => ({\n ...currentParameters,\n ...processedParameters,\n }));\n setAllParameterValues((currentParameters) => {\n let aggregatedLoadedState: AsyncValue<any>[\"type\"] = \"loaded\";\n let firstError: Error | undefined;\n const newParameterValues: ExtendedParameterValueMap<\n WidgetConfig<ParameterConfig>\n > = {};\n for (const key in processedParameters) {\n const value = processedParameters[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 ExtendedParameterValueMap<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,EAAEC,MAAM,QAAQ,OAAO;AAMzD,SAASC,oBAAoB,QAAQ,cAAc;AACnD,SAASC,8BAA8B,QAAQ,2CAA2C;AAC1F,SAASC,oBAAoB,QAAQ,iCAAiC;AAsCtE;AACA;AACA;AACA,OAAO,MAAMC,aAAa,GAAGA,CAA0C;EACrEC,QAAQ;EACRC,MAAM;EACNC,aAAa;EACbC,MAAM,EAAEC;AACa,CAAC,KAAgD;EACtE,MAAMD,MAAM,GAAGT,OAAO,CAAC,MAAMH,yBAAyB,CAAI,CAAC,EAAE,EAAE,CAAC;EAChE,MAAM,CAACc,oBAAoB,EAAEC,uBAAuB,CAAC,GAAGd,KAAK,CAACe,QAAQ,CAEpEL,aAAa,IAAIJ,oBAAoB,CAACG,MAAM,EAAE,aAAa,CAAC,CAAC;EAC/D,MAAM,CAACO,kBAAkB,EAAEC,qBAAqB,CAAC,GAAGjB,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e,EAAEX,MAAM,CAACW,eAAe;MACvCT,oBAAoB;MACpBc,UAAU,EAAE;QACViB,MAAM,EAAE5B,kBAAkB,CAACkB,KAAK,IAAI,CAAC,CAAC;QACtCW,KAAK,EAAE7B,kBAAkB,CAACE;MAC5B;MACA;IACF;EAA+D,GAE9DV,QAC4B,CAAC;AAEpC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"client.js","names":["createFoundryWidgetClient","React","useEffect","useMemo","useRef","FoundryWidgetContext","ErrorBoundary","extendParametersWithObjectSets","initializeParameters","FoundryWidget","children","config","initialValues","client","osdkClient","asyncParameterValues","setAsyncParameterValues","useState","allParameterValues","setAllParameterValues","type","objectSetCache","Map","subscribe","hostEventTarget","addEventListener","payload","processedParameters","detail","parameters","current","currentParameters","aggregatedLoadedState","firstError","newParameterValues","key","value","error","currentParameterValue","updatedValue","Error","ready","resizeObserver","ResizeObserver","entries","length","console","entry","borderBoxSize","inlineSize","width","blockSize","height","resize","observe","document","body","box","unsubscribe","disconnect","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 { Client, ObjectSet } from \"@osdk/client\";\nimport type { ObjectType } from \"@osdk/widget.api\";\nimport type {\n AsyncValue,\n ParameterConfig,\n WidgetConfig,\n} from \"@osdk/widget.client\";\nimport { createFoundryWidgetClient } from \"@osdk/widget.client\";\nimport React, { useEffect, useMemo, useRef } from \"react\";\nimport type {\n ExtendedAsyncParameterValueMap,\n ExtendedParameterValueMap,\n FoundryWidgetClientContext,\n} from \"./context.js\";\nimport { FoundryWidgetContext } from \"./context.js\";\nimport { ErrorBoundary } from \"./ErrorBoundary.js\";\nimport { extendParametersWithObjectSets } from \"./utils/extendParametersWithObjectSets.js\";\nimport { initializeParameters } from \"./utils/initializeParameters.js\";\n\ntype ExtractObjectTypes<C extends WidgetConfig<C[\"parameters\"]>> =\n C[\"parameters\"][keyof C[\"parameters\"]] extends infer Param\n ? Param extends { type: \"objectSet\"; objectType: infer OT }\n ? OT extends ObjectType ? OT\n : never\n : never\n : never;\n\ntype HasObjectSetParameters<C extends WidgetConfig<C[\"parameters\"]>> =\n ExtractObjectTypes<C> extends never ? false : true;\n\ntype ObjectSetProps<C extends WidgetConfig<C[\"parameters\"]>> = {\n /**\n * Used to hydrate object sets from their RIDs for object set parameters\n */\n client: Client;\n};\n\ntype FoundryWidgetProps<C extends WidgetConfig<C[\"parameters\"]>> =\n & {\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?: ExtendedAsyncParameterValueMap<C>;\n }\n & Partial<ObjectSetProps<C>>\n & (HasObjectSetParameters<C> extends true ? ObjectSetProps<C> : {});\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 client: osdkClient,\n}: FoundryWidgetProps<C>): React.ReactElement<FoundryWidgetProps<C>> => {\n const client = useMemo(() => createFoundryWidgetClient<C>(), []);\n const [asyncParameterValues, setAsyncParameterValues] = React.useState<\n ExtendedAsyncParameterValueMap<C>\n >(initialValues ?? initializeParameters(config, \"not-started\"));\n const [allParameterValues, setAllParameterValues] = React.useState<\n AsyncValue<ExtendedParameterValueMap<C>>\n >({\n type: \"not-started\",\n });\n\n const objectSetCache = useRef<\n Map<string, { objectSetRid: string; objectSet: ObjectSet }>\n >(new Map());\n\n useEffect(() => {\n client.subscribe();\n client.hostEventTarget.addEventListener(\n \"host.update-parameters\",\n (payload) => {\n const processedParameters = extendParametersWithObjectSets(\n osdkClient,\n config,\n payload.detail.parameters,\n objectSetCache.current,\n );\n setAsyncParameterValues((currentParameters) => ({\n ...currentParameters,\n ...processedParameters,\n }));\n setAllParameterValues((currentParameters) => {\n let aggregatedLoadedState: AsyncValue<any>[\"type\"] = \"loaded\";\n let firstError: Error | undefined;\n const newParameterValues: ExtendedParameterValueMap<\n WidgetConfig<ParameterConfig>\n > = {};\n for (const key in processedParameters) {\n const value = processedParameters[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 ExtendedParameterValueMap<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\n const resizeObserver = new ResizeObserver((entries) => {\n if (entries.length !== 1) {\n // eslint-disable-next-line no-console\n console.error(\n \"Expected exactly one resize observer entry but received:\",\n entries,\n );\n return;\n }\n const entry = entries[0];\n if (entry.borderBoxSize.length !== 1) {\n // eslint-disable-next-line no-console\n console.error(\n \"Expected exactly one border box size but received:\",\n entry.borderBoxSize,\n );\n return;\n }\n const { inlineSize: width, blockSize: height } = entry.borderBoxSize[0];\n client.resize({ width, height });\n });\n resizeObserver.observe(document.body, { box: \"border-box\" });\n\n return () => {\n client.unsubscribe();\n resizeObserver.disconnect();\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 <ErrorBoundary>\n {children}\n </ErrorBoundary>\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,EAAEC,MAAM,QAAQ,OAAO;AAMzD,SAASC,oBAAoB,QAAQ,cAAc;AACnD,SAASC,aAAa,QAAQ,oBAAoB;AAClD,SAASC,8BAA8B,QAAQ,2CAA2C;AAC1F,SAASC,oBAAoB,QAAQ,iCAAiC;AAuCtE;AACA;AACA;AACA,OAAO,MAAMC,aAAa,GAAGA,CAA0C;EACrEC,QAAQ;EACRC,MAAM;EACNC,aAAa;EACbC,MAAM,EAAEC;AAC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A,CAACtD,aAAa,QACXI,QACY,CACc,CAAC;AAEpC,CAAC","ignoreList":[]}
@@ -0,0 +1,13 @@
1
+ import * as React from "react";
2
+ interface State {
3
+ error: unknown;
4
+ }
5
+ /**
6
+ * Error boundary to catch and display errors in widget code.
7
+ */
8
+ export declare class ErrorBoundary extends React.Component<React.PropsWithChildren, State> {
9
+ state: State;
10
+ static getDerivedStateFromError(error: unknown): Partial<State>;
11
+ render(): React.ReactNode;
12
+ }
13
+ export {};
@@ -0,0 +1 @@
1
+ {"mappings":"AAgBA,YAAY,WAAW,OAAQ;UAErB,MAAM;CACd;AACD;;;;AAKD,OAAO,cAAM,sBAAsB,MAAM,UACvC,MAAM,mBACN,OACA;CACA,OAAO;CAEP,OAAO,yBAAyBA,iBAAiB,QAAQ;CAIzD,UAAU,MAAM;AAoDjB","names":["error: unknown"],"sources":["../../src/ErrorBoundary.tsx"],"version":3,"file":"ErrorBoundary.d.ts"}
@@ -1 +1 @@
1
- {"mappings":"AAgBA,cAAc,cAAyB,cAAe;AACtD,cAAc,kBAAkB,kBAAmB;AACnD,cAGE,oBACK,qBAAsB;AAE7B,OAAO,WAA2C,OAAQ;AAC1D,cACE,sCAGK,cAAe;KAKjB,mBAAmB,UAAU,aAAa,EAAE,kBAC/C,EAAE,oBAAoB,EAAE,6BAA6B,QACjD,cAAc;CAAE,MAAM;CAAa,kBAAkB;AAAI,IACvD,WAAW,aAAa;KAI3B,uBAAuB,UAAU,aAAa,EAAE,kBACnD,mBAAmB,mBAAmB,QAAQ;KAE3C,eAAe,UAAU,aAAa,EAAE,kBAAkB;;;;CAI7D,QAAQ;AACT;KAEI,mBAAmB,UAAU,aAAa,EAAE,kBAC7C;CACA,UAAU,MAAM;;;;CAKhB,QAAQ;;;;;;CAOR,gBAAgB,+BAA+B;AAChD,IACC,QAAQ,eAAe,OACtB,uBAAuB,WAAW,OAAO,eAAe,KAAK,CAAE;;;;AAKpE,OAAO,cAAM,gBAAiB,UAAU,aAAa,EAAE,gBAAgB,EACrE,UACA,QACA,eACA,QAAQ,YACc,EAArB,mBAAmB,OAAK,MAAM,aAAa,mBAAmB","names":[],"sources":["../../src/client.tsx"],"version":3,"file":"client.d.ts"}
1
+ {"mappings":"AAgBA,cAAc,cAAyB,cAAe;AACtD,cAAc,kBAAkB,kBAAmB;AACnD,cAGE,oBACK,qBAAsB;AAE7B,OAAO,WAA2C,OAAQ;AAC1D,cACE,sCAGK,cAAe;KAMjB,mBAAmB,UAAU,aAAa,EAAE,kBAC/C,EAAE,oBAAoB,EAAE,6BAA6B,QACjD,cAAc;CAAE,MAAM;CAAa,kBAAkB;AAAI,IACvD,WAAW,aAAa;KAK3B,uBAAuB,UAAU,aAAa,EAAE,kBACnD,mBAAmB,mBAAmB,QAAQ;KAE3C,eAAe,UAAU,aAAa,EAAE,kBAAkB;;;;CAI7D,QAAQ;AACT;KAEI,mBAAmB,UAAU,aAAa,EAAE,kBAC7C;CACA,UAAU,MAAM;;;;CAKhB,QAAQ;;;;;;CAOR,gBAAgB,+BAA+B;AAChD,IACC,QAAQ,eAAe,OACtB,uBAAuB,WAAW,OAAO,eAAe,KAAK,CAAE;;;;AAKpE,OAAO,cAAM,gBAAiB,UAAU,aAAa,EAAE,gBAAgB,EACrE,UACA,QACA,eACA,QAAQ,YACc,EAArB,mBAAmB,OAAK,MAAM,aAAa,mBAAmB","names":[],"sources":["../../src/client.tsx"],"version":3,"file":"client.d.ts"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osdk/widget.client-react",
3
- "version": "3.2.4",
3
+ "version": "3.2.6",
4
4
  "description": "Wrapper around @osdk/widget.client",
5
5
  "access": "public",
6
6
  "license": "Apache-2.0",
@@ -34,7 +34,7 @@
34
34
  "@types/react-dom": "^18 || ^19",
35
35
  "react": "^18 || ^19",
36
36
  "react-dom": "^18 || ^19",
37
- "@osdk/widget.client": "~3.2.4"
37
+ "@osdk/widget.client": "~3.2.6"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/react": "^18.3.24",
@@ -43,11 +43,11 @@
43
43
  "react-dom": "18.3.1",
44
44
  "ts-expect": "^1.3.0",
45
45
  "typescript": "~5.5.4",
46
+ "@osdk/monorepo.api-extractor": "~0.4.0",
47
+ "@osdk/client": "~2.5.3",
48
+ "@osdk/widget.api": "~3.2.6",
46
49
  "@osdk/monorepo.tsconfig": "~0.4.0",
47
- "@osdk/widget.api": "~3.2.4",
48
- "@osdk/client": "~2.5.2",
49
- "@osdk/widget.client": "~3.2.4",
50
- "@osdk/monorepo.api-extractor": "~0.4.0"
50
+ "@osdk/widget.client": "~3.2.6"
51
51
  },
52
52
  "publishConfig": {
53
53
  "access": "public"