@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.
@@ -0,0 +1,28 @@
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
+ /**
18
+ * Utility function to initialize a map of parameter values to either a loading or not-started loading state
19
+ */
20
+ export function initializeParameters(config, initialLoadingState) {
21
+ return Object.fromEntries(Object.entries(config.parameters).map(([key, parameterConfig]) => [key, {
22
+ type: parameterConfig.type,
23
+ value: {
24
+ type: initialLoadingState
25
+ }
26
+ }]));
27
+ }
28
+ //# sourceMappingURL=initializeParameters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initializeParameters.js","names":["initializeParameters","config","initialLoadingState","Object","fromEntries","entries","parameters","map","key","parameterConfig","type","value"],"sources":["initializeParameters.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 type { AsyncParameterValueMap, WidgetConfig } from \"@osdk/widget.client\";\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<C extends WidgetConfig<C[\"parameters\"]>>(\n config: C,\n initialLoadingState: \"loading\" | \"not-started\",\n): AsyncParameterValueMap<C> {\n return Object.fromEntries(\n Object.entries(config.parameters).map(([key, parameterConfig]) => [\n key,\n { type: parameterConfig.type, value: { type: initialLoadingState } },\n ]),\n ) as AsyncParameterValueMap<C>;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA;AACA;AACA;AACA,OAAO,SAASA,oBAAoBA,CAClCC,MAAS,EACTC,mBAA8C,EACnB;EAC3B,OAAOC,MAAM,CAACC,WAAW,CACvBD,MAAM,CAACE,OAAO,CAACJ,MAAM,CAACK,UAAU,CAAC,CAACC,GAAG,CAAC,CAAC,CAACC,GAAG,EAAEC,eAAe,CAAC,KAAK,CAChED,GAAG,EACH;IAAEE,IAAI,EAAED,eAAe,CAACC,IAAI;IAAEC,KAAK,EAAE;MAAED,IAAI,EAAER;IAAoB;EAAE,CAAC,CACrE,CACH,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,132 @@
1
+ 'use strict';
2
+
3
+ var widget_client = require('@osdk/widget.client');
4
+ var React2 = require('react');
5
+
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
+
8
+ var React2__default = /*#__PURE__*/_interopDefault(React2);
9
+
10
+ // src/client.tsx
11
+ var FoundryWidgetContext = /* @__PURE__ */ React2__default.default.createContext({
12
+ emitEvent: () => {
13
+ },
14
+ hostEventTarget: new widget_client.FoundryHostEventTarget(),
15
+ asyncParameterValues: {},
16
+ parameters: {
17
+ state: "not-started",
18
+ values: {}
19
+ }
20
+ });
21
+ function useFoundryWidgetContext() {
22
+ return React2.useContext(FoundryWidgetContext);
23
+ }
24
+ (function(_useFoundryWidgetContext) {
25
+ function withTypes() {
26
+ return () => {
27
+ return useFoundryWidgetContext();
28
+ };
29
+ }
30
+ _useFoundryWidgetContext.withTypes = withTypes;
31
+ })(useFoundryWidgetContext || (useFoundryWidgetContext = {}));
32
+
33
+ // src/utils/initializeParameters.ts
34
+ function initializeParameters(config, initialLoadingState) {
35
+ return Object.fromEntries(Object.entries(config.parameters).map(([key, parameterConfig]) => [key, {
36
+ type: parameterConfig.type,
37
+ value: {
38
+ type: initialLoadingState
39
+ }
40
+ }]));
41
+ }
42
+
43
+ // src/client.tsx
44
+ var FoundryWidget = ({
45
+ children,
46
+ config,
47
+ initialValues
48
+ }) => {
49
+ const client = React2.useMemo(() => widget_client.createFoundryWidgetClient(), []);
50
+ const [asyncParameterValues, setAsyncParameterValues] = React2__default.default.useState(initialValues ?? initializeParameters(config, "not-started"));
51
+ const [allParameterValues, setAllParameterValues] = React2__default.default.useState({
52
+ type: "not-started"
53
+ });
54
+ React2.useEffect(() => {
55
+ client.subscribe();
56
+ client.hostEventTarget.addEventListener("host.update-parameters", (payload) => {
57
+ setAsyncParameterValues((currentParameters) => ({
58
+ ...currentParameters,
59
+ ...payload.detail.parameters
60
+ }));
61
+ setAllParameterValues((currentParameters) => {
62
+ let aggregatedLoadedState = "loaded";
63
+ let firstError;
64
+ const newParameterValues = {};
65
+ for (const key in payload.detail.parameters) {
66
+ const value = payload.detail.parameters[key].value;
67
+ if (value.type === "failed") {
68
+ aggregatedLoadedState = "failed";
69
+ firstError = firstError ?? value.error;
70
+ newParameterValues[key] = value.value;
71
+ continue;
72
+ }
73
+ if (value.type === "loading" && aggregatedLoadedState !== "failed") {
74
+ aggregatedLoadedState = "loading";
75
+ continue;
76
+ }
77
+ if (value.type === "reloading" && aggregatedLoadedState !== "failed" && aggregatedLoadedState !== "loading") {
78
+ aggregatedLoadedState = "reloading";
79
+ newParameterValues[key] = value.value;
80
+ continue;
81
+ }
82
+ if (value.type === "not-started" && aggregatedLoadedState !== "failed" && aggregatedLoadedState !== "loading" && aggregatedLoadedState !== "reloading") {
83
+ aggregatedLoadedState = "not-started";
84
+ }
85
+ if (value.type === "loaded") {
86
+ newParameterValues[key] = value.value;
87
+ }
88
+ }
89
+ const currentParameterValue = currentParameters.type !== "not-started" && currentParameters.type !== "loading" ? currentParameters.value : {};
90
+ if (aggregatedLoadedState !== "not-started" && aggregatedLoadedState !== "loading") {
91
+ const updatedValue = {
92
+ ...currentParameterValue,
93
+ ...newParameterValues
94
+ };
95
+ return aggregatedLoadedState === "failed" ? {
96
+ type: aggregatedLoadedState,
97
+ value: updatedValue,
98
+ error: firstError ?? new Error("Failed to load parameters")
99
+ } : {
100
+ type: aggregatedLoadedState,
101
+ value: updatedValue
102
+ };
103
+ } else {
104
+ return {
105
+ type: aggregatedLoadedState
106
+ };
107
+ }
108
+ });
109
+ });
110
+ client.ready();
111
+ return () => {
112
+ client.unsubscribe();
113
+ };
114
+ }, []);
115
+ return /* @__PURE__ */ React2__default.default.createElement(FoundryWidgetContext.Provider, {
116
+ value: {
117
+ emitEvent: client.emitEvent,
118
+ hostEventTarget: client.hostEventTarget,
119
+ asyncParameterValues,
120
+ parameters: {
121
+ values: allParameterValues.value ?? {},
122
+ state: allParameterValues.type
123
+ }
124
+ // Unfortunately the context is statically defined so we can't use the generic type, hence the cast
125
+ }
126
+ }, children);
127
+ };
128
+
129
+ exports.FoundryWidget = FoundryWidget;
130
+ exports.useFoundryWidgetContext = useFoundryWidgetContext;
131
+ //# sourceMappingURL=index.cjs.map
132
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/context.ts","../../src/utils/initializeParameters.ts","../../src/client.tsx"],"names":["FoundryHostEventTarget","useContext","useMemo","createFoundryWidgetClient","React","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;A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 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 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 } from \"react\";\nimport { FoundryWidgetContext } from \"./context.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}) => {\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 useEffect(() => {\n client.subscribe();\n client.hostEventTarget.addEventListener(\"host.update-parameters\", payload => {\n setAsyncParameterValues(currentParameters => ({\n ...currentParameters,\n ...payload.detail.parameters\n }));\n setAllParameterValues(currentParameters => {\n let aggregatedLoadedState = \"loaded\";\n let firstError;\n const newParameterValues = {};\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] = 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};"]}
@@ -0,0 +1,45 @@
1
+ import { WidgetConfig, AsyncParameterValueMap, FoundryWidgetClient, FoundryHostEventTarget, ParameterValueMap, AsyncValue } from '@osdk/widget.client';
2
+ import React from 'react';
3
+
4
+ interface FoundryWidgetProps<C extends WidgetConfig<C["parameters"]>> {
5
+ children: React.ReactNode;
6
+ /**
7
+ * Parameter configuration for the widget
8
+ */
9
+ config: C;
10
+ /**
11
+ * Customize what the initial value of each parameter should be
12
+ *
13
+ * @default Sets all parameters to the "not-started" loading state
14
+ */
15
+ initialValues?: AsyncParameterValueMap<C>;
16
+ }
17
+ /**
18
+ * Handles subscribing to messages from the host Foundry UI and updating the widget's parameter values accordingly via React context
19
+ */
20
+ declare const FoundryWidget: <C extends WidgetConfig<C["parameters"]>>({ children, config, initialValues, }: FoundryWidgetProps<C>) => React.ReactElement<FoundryWidgetProps<C>>;
21
+
22
+ interface FoundryWidgetClientContext<C extends WidgetConfig<C["parameters"]>> {
23
+ emitEvent: FoundryWidgetClient<C>["emitEvent"];
24
+ hostEventTarget: FoundryHostEventTarget<C>;
25
+ /**
26
+ * Object where the individual parameters have their async state represented
27
+ */
28
+ asyncParameterValues: AsyncParameterValueMap<C>;
29
+ /**
30
+ * Convenience object that aggregates the value of all parameters, accounting for their loading states
31
+ */
32
+ parameters: {
33
+ values: Partial<ParameterValueMap<C>>;
34
+ state: AsyncValue<ParameterValueMap<C>>["type"];
35
+ };
36
+ }
37
+ /**
38
+ * @returns The current FoundryWidgetClientContext, in the context of your specific parameter configuration
39
+ */
40
+ declare function useFoundryWidgetContext<C extends WidgetConfig<C["parameters"]>>(): FoundryWidgetClientContext<C>;
41
+ declare namespace useFoundryWidgetContext {
42
+ function withTypes<C extends WidgetConfig<C["parameters"]>>(): () => FoundryWidgetClientContext<C>;
43
+ }
44
+
45
+ export { FoundryWidget, type FoundryWidgetClientContext, useFoundryWidgetContext };
@@ -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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,KAAK,EAAEG;UACT,CAAC;QACL,CAAC,MAAM;UACL,OAAO;YAAEf,IAAI,EAAEQ;UAAsB,CAAC;QACxC;MACF,CAAC,CAAC;IACJ,CACF,CAAC;IACDd,MAAM,CAACuB,KAAK,CAAC,CAAC;IACd,OAAO,MAAM;MACXvB,MAAM,CAACwB,WAAW,CAAC,CAAC;IACtB,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,oBACEjC,KAAA,CAAAkC,aAAA,CAAC/B,oBAAoB,CAACgC,QAAQ;IAC5BR,KAAK,EAAE;MACLS,SAAS,EAAE3B,MAAM,CAAC2B,SAAS;MAC3BnB,eAAe,EAAER,MAAM,CAACQ,eAAe;MACvCP,oBAAoB;MACpBY,UAAU,EAAE;QACVe,MAAM,EAAExB,kBAAkB,CAACc,KAAK,IAAI,CAAC,CAAC;QACtCW,KAAK,EAAEzB,kBAAkB,CAACE;MAC5B;MACA;IACF;EAA+D,GAE9DT,QAC4B,CAAC;AAEpC,CAAC","ignoreList":[]}
@@ -0,0 +1,42 @@
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":[]}
@@ -0,0 +1,28 @@
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
+ /**
18
+ * Utility function to initialize a map of parameter values to either a loading or not-started loading state
19
+ */
20
+ export function initializeParameters(config, initialLoadingState) {
21
+ return Object.fromEntries(Object.entries(config.parameters).map(([key, parameterConfig]) => [key, {
22
+ type: parameterConfig.type,
23
+ value: {
24
+ type: initialLoadingState
25
+ }
26
+ }]));
27
+ }
28
+ //# sourceMappingURL=initializeParameters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initializeParameters.js","names":["initializeParameters","config","initialLoadingState","Object","fromEntries","entries","parameters","map","key","parameterConfig","type","value"],"sources":["initializeParameters.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 type { AsyncParameterValueMap, WidgetConfig } from \"@osdk/widget.client\";\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<C extends WidgetConfig<C[\"parameters\"]>>(\n config: C,\n initialLoadingState: \"loading\" | \"not-started\",\n): AsyncParameterValueMap<C> {\n return Object.fromEntries(\n Object.entries(config.parameters).map(([key, parameterConfig]) => [\n key,\n { type: parameterConfig.type, value: { type: initialLoadingState } },\n ]),\n ) as AsyncParameterValueMap<C>;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA;AACA;AACA;AACA,OAAO,SAASA,oBAAoBA,CAClCC,MAAS,EACTC,mBAA8C,EACnB;EAC3B,OAAOC,MAAM,CAACC,WAAW,CACvBD,MAAM,CAACE,OAAO,CAACJ,MAAM,CAACK,UAAU,CAAC,CAACC,GAAG,CAAC,CAAC,CAACC,GAAG,EAAEC,eAAe,CAAC,KAAK,CAChED,GAAG,EACH;IAAEE,IAAI,EAAED,eAAe,CAACC,IAAI;IAAEC,KAAK,EAAE;MAAED,IAAI,EAAER;IAAoB;EAAE,CAAC,CACrE,CACH,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,20 @@
1
+ import type { AsyncParameterValueMap, WidgetConfig } from "@osdk/widget.client";
2
+ import React from "react";
3
+ interface FoundryWidgetProps<C extends WidgetConfig<C["parameters"]>> {
4
+ children: React.ReactNode;
5
+ /**
6
+ * Parameter configuration for the widget
7
+ */
8
+ config: C;
9
+ /**
10
+ * Customize what the initial value of each parameter should be
11
+ *
12
+ * @default Sets all parameters to the "not-started" loading state
13
+ */
14
+ initialValues?: AsyncParameterValueMap<C>;
15
+ }
16
+ /**
17
+ * Handles subscribing to messages from the host Foundry UI and updating the widget's parameter values accordingly via React context
18
+ */
19
+ export declare const FoundryWidget: <C extends WidgetConfig<C["parameters"]>>({ children, config, initialValues }: FoundryWidgetProps<C>) => React.ReactElement<FoundryWidgetProps<C>>;
20
+ export {};
@@ -0,0 +1 @@
1
+ {"mappings":"AAgBA,cACE,wBAIA,oBACK,qBAAsB;AAE7B,OAAO,WAAmC,OAAQ;UAKxC,mBAAmB,UAAU,aAAa,EAAE,gBAAgB;CACpE,UAAU,MAAM;;;;CAKhB,QAAQ;;;;;;CAOR,gBAAgB,uBAAuB;AACxC;;;;AAKD,OAAO,cAAM,gBAAiB,UAAU,aAAa,EAAE,gBAAgB,EACrE,UACA,QACA,eACsB,EAArB,mBAAmB,OAAK,MAAM,aAAa,mBAAmB","names":[],"sources":["../../src/client.tsx"],"version":3,"file":"client.d.ts"}
@@ -0,0 +1,25 @@
1
+ import { type AsyncParameterValueMap, type AsyncValue, FoundryHostEventTarget, type FoundryWidgetClient, type ParameterConfig, type ParameterValueMap, type WidgetConfig } from "@osdk/widget.client";
2
+ import React from "react";
3
+ export interface FoundryWidgetClientContext<C extends WidgetConfig<C["parameters"]>> {
4
+ emitEvent: FoundryWidgetClient<C>["emitEvent"];
5
+ hostEventTarget: FoundryHostEventTarget<C>;
6
+ /**
7
+ * Object where the individual parameters have their async state represented
8
+ */
9
+ asyncParameterValues: AsyncParameterValueMap<C>;
10
+ /**
11
+ * Convenience object that aggregates the value of all parameters, accounting for their loading states
12
+ */
13
+ parameters: {
14
+ values: Partial<ParameterValueMap<C>>
15
+ state: AsyncValue<ParameterValueMap<C>>["type"]
16
+ };
17
+ }
18
+ export declare const FoundryWidgetContext: React.Context<FoundryWidgetClientContext<WidgetConfig<ParameterConfig>>>;
19
+ /**
20
+ * @returns The current FoundryWidgetClientContext, in the context of your specific parameter configuration
21
+ */
22
+ export declare function useFoundryWidgetContext<C extends WidgetConfig<C["parameters"]>>(): FoundryWidgetClientContext<C>;
23
+ export declare namespace useFoundryWidgetContext {
24
+ function withTypes<C extends WidgetConfig<C["parameters"]>>(): () => FoundryWidgetClientContext<C>;
25
+ }
@@ -0,0 +1 @@
1
+ {"mappings":"AAgBA,cACO,6BACA,YACL,6BACK,0BACA,sBACA,wBACA,oBACA,qBAAsB;AAC7B,OAAO,WAA2B,OAAQ;AAE1C,iBAAiB,2BACf,UAAU,aAAa,EAAE,gBACzB;CACA,WAAW,oBAAoB,GAAG;CAClC,iBAAiB,uBAAuB;;;;CAKxC,sBAAsB,uBAAuB;;;;CAK7C,YAAY;EACV,QAAQ,QAAQ,kBAAkB;EAClC,OAAO,WAAW,kBAAkB,IAAI;CACzC;AACF;AAED,OAAO,cAAMA,sBAAsB,MAAM,QACvC,2BAA2B,aAAa;;;;AAgB1C,OAAO,iBAAS,wBACd,UAAU,aAAa,EAAE,mBAEkB,2BAA2B;AAGxE,yBAAiB;CACR,SAAS,UACd,UAAU,aAAa,EAAE,yBAChB,2BAA2B","names":["FoundryWidgetContext: React.Context<\n FoundryWidgetClientContext<WidgetConfig<ParameterConfig>>\n>"],"sources":["../../src/context.ts"],"version":3,"file":"context.d.ts"}
@@ -0,0 +1,3 @@
1
+ export { FoundryWidget } from "./client.js";
2
+ export { useFoundryWidgetContext } from "./context.js";
3
+ export type { FoundryWidgetClientContext } from "./context.js";
@@ -0,0 +1 @@
1
+ {"mappings":"AAgBA,SAAS,qBAAqB;AAC9B,SAAS,+BAA+B;AACxC,cAAc,kCAAkC","names":[],"sources":["../../src/index.ts"],"version":3,"file":"index.d.ts"}
@@ -0,0 +1,5 @@
1
+ import type { AsyncParameterValueMap, WidgetConfig } from "@osdk/widget.client";
2
+ /**
3
+ * Utility function to initialize a map of parameter values to either a loading or not-started loading state
4
+ */
5
+ export declare function initializeParameters<C extends WidgetConfig<C["parameters"]>>(config: C, initialLoadingState: "loading" | "not-started"): AsyncParameterValueMap<C>;
@@ -0,0 +1 @@
1
+ {"mappings":"AAgBA,cAAc,wBAAwB,oBAAoB,qBAAsB;;;;AAKhF,OAAO,iBAAS,qBAAqB,UAAU,aAAa,EAAE,gBAC5DA,QAAQ,GACRC,qBAAqB,YAAY,gBAChC,uBAAuB","names":["config: C","initialLoadingState: \"loading\" | \"not-started\""],"sources":["../../../src/utils/initializeParameters.ts"],"version":3,"file":"initializeParameters.d.ts"}