@osdk/widget.client 3.1.0-beta.2 → 3.1.0-beta.4
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 +18 -0
- package/build/browser/client.js +2 -65
- package/build/browser/client.js.map +1 -1
- package/build/cjs/index.cjs +2 -59
- package/build/cjs/index.cjs.map +1 -1
- package/build/esm/client.js +2 -65
- package/build/esm/client.js.map +1 -1
- package/build/types/client.d.ts.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @osdk/widget.client
|
|
2
2
|
|
|
3
|
+
## 3.1.0-beta.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [3744571]
|
|
8
|
+
- @osdk/widget.api@3.1.0-beta.4
|
|
9
|
+
|
|
10
|
+
## 3.1.0-beta.3
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- c09f545: Drop support for Sandbox v1 in widget client
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [c09f545]
|
|
19
|
+
- @osdk/widget.api@3.1.0-beta.3
|
|
20
|
+
|
|
3
21
|
## 3.1.0-beta.2
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/build/browser/client.js
CHANGED
|
@@ -15,17 +15,11 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { HostMessage, visitHostMessage } from "@osdk/widget.api";
|
|
18
|
-
import { META_TAG_HOST_ORIGIN } from "@osdk/widget.api";
|
|
19
18
|
import invariant from "tiny-invariant";
|
|
20
19
|
import { FoundryHostEventTarget } from "./host.js";
|
|
21
20
|
export function createFoundryWidgetClient() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
// todo: drop support for sandbox v1
|
|
26
|
-
return _createFoundryWidgetClientLegacy();
|
|
27
|
-
}
|
|
28
|
-
function _createFoundryWidgetClient(widgetApi) {
|
|
21
|
+
!("__PALANTIR_WIDGET_API__" in window) ? process.env.NODE_ENV !== "production" ? invariant(false, "[FoundryWidgetClient] Missing __PALANTIR_WIDGET_API__ in window") : invariant(false) : void 0;
|
|
22
|
+
const widgetApi = window.__PALANTIR_WIDGET_API__;
|
|
29
23
|
const hostEventTarget = new FoundryHostEventTarget();
|
|
30
24
|
const listenForHostMessages = event => {
|
|
31
25
|
visitHostMessage(event.detail, {
|
|
@@ -68,61 +62,4 @@ function _createFoundryWidgetClient(widgetApi) {
|
|
|
68
62
|
}
|
|
69
63
|
};
|
|
70
64
|
}
|
|
71
|
-
|
|
72
|
-
// todo: drop support for sandbox v1
|
|
73
|
-
function _createFoundryWidgetClientLegacy() {
|
|
74
|
-
!window.parent ? process.env.NODE_ENV !== "production" ? invariant(false, "[FoundryWidgetClient] Must be run in an iframe") : invariant(false) : void 0;
|
|
75
|
-
const parentWindow = window.parent;
|
|
76
|
-
const metaTag = document.querySelector(`meta[name="${META_TAG_HOST_ORIGIN}"]`);
|
|
77
|
-
!metaTag ? process.env.NODE_ENV !== "production" ? invariant(false, "[FoundryWidgetClient] Missing host origin meta tag " + META_TAG_HOST_ORIGIN) : invariant(false) : void 0;
|
|
78
|
-
const hostOrigin = metaTag.getAttribute("content");
|
|
79
|
-
!hostOrigin ? process.env.NODE_ENV !== "production" ? invariant(false, "[FoundryWidgetClient] Missing host origin meta tag content") : invariant(false) : void 0;
|
|
80
|
-
const hostEventTarget = new FoundryHostEventTarget();
|
|
81
|
-
const listenForHostMessages = event => {
|
|
82
|
-
visitHostMessage(event.data, {
|
|
83
|
-
"host.update-parameters": payload => {
|
|
84
|
-
hostEventTarget.dispatchEventMessage("host.update-parameters", payload);
|
|
85
|
-
},
|
|
86
|
-
_unknown: () => {
|
|
87
|
-
// Do nothing
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
const sendMessageToHost = message => {
|
|
92
|
-
parentWindow.postMessage(message, hostOrigin);
|
|
93
|
-
};
|
|
94
|
-
return {
|
|
95
|
-
hostEventTarget,
|
|
96
|
-
ready: () => {
|
|
97
|
-
sendMessageToHost({
|
|
98
|
-
type: "widget.ready",
|
|
99
|
-
payload: {
|
|
100
|
-
apiVersion: HostMessage.Version
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
},
|
|
104
|
-
emitEvent: (eventId, payload) => {
|
|
105
|
-
sendMessageToHost({
|
|
106
|
-
type: "widget.emit-event",
|
|
107
|
-
payload: {
|
|
108
|
-
eventId,
|
|
109
|
-
...payload
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
},
|
|
113
|
-
sendMessage: sendMessageToHost,
|
|
114
|
-
subscribe: () => {
|
|
115
|
-
window.addEventListener("message", event => {
|
|
116
|
-
if (event.origin !== hostOrigin) {
|
|
117
|
-
// Reject messages that aren't coming from the configured host
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
listenForHostMessages(event);
|
|
121
|
-
});
|
|
122
|
-
},
|
|
123
|
-
unsubscribe: () => {
|
|
124
|
-
window.removeEventListener("message", listenForHostMessages);
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
65
|
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":["HostMessage","visitHostMessage","META_TAG_HOST_ORIGIN","invariant","FoundryHostEventTarget","createFoundryWidgetClient","window","_createFoundryWidgetClient","__PALANTIR_WIDGET_API__","_createFoundryWidgetClientLegacy","widgetApi","hostEventTarget","listenForHostMessages","event","detail","payload","dispatchEventMessage","_unknown","sendMessageToHost","message","sendMessage","ready","type","apiVersion","Version","emitEvent","eventId","subscribe","addEventListener","unsubscribe","removeEventListener","parent","process","env","NODE_ENV","parentWindow","metaTag","document","querySelector","hostOrigin","getAttribute","data","postMessage","origin"],"sources":["client.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 HostMessage,\n visitHostMessage,\n type WidgetConfig,\n type WidgetMessage,\n} from \"@osdk/widget.api\";\nimport { META_TAG_HOST_ORIGIN } from \"@osdk/widget.api\";\nimport invariant from \"tiny-invariant\";\nimport { FoundryHostEventTarget } from \"./host.js\";\n\nexport interface FoundryWidgetClient<C extends WidgetConfig<C[\"parameters\"]>> {\n /**\n * Notifies the host that this client is ready to receive the first parameter values\n */\n ready: () => void;\n\n /**\n * Emits an event with the given ID and payload\n */\n emitEvent: <M extends WidgetMessage.EmitEvent<C>>(\n eventId: M[\"payload\"][\"eventId\"],\n payload: Omit<M[\"payload\"], \"eventId\">,\n ) => void;\n\n /**\n * Sends a message to the parent frame.\n * It is recommended to use the convenience methods for individual messages (e.g. ready or emitEvent) instead\n */\n sendMessage: <M extends WidgetMessage<C>>(message: M) => void;\n\n /**\n * Subscribes to events from the host, invoking the listener when a message is received\n */\n subscribe: () => void;\n\n /**\n * Unsubscribes a previously subscribed listener from host events, if one exists\n */\n unsubscribe: () => void;\n\n /**\n * Event targets on which you can subscribe to specific host messages\n */\n hostEventTarget: FoundryHostEventTarget<C>;\n}\n\nexport function createFoundryWidgetClient<\n C extends WidgetConfig<C[\"parameters\"]>,\n>(): FoundryWidgetClient<C> {\n if (\"__PALANTIR_WIDGET_API__\" in window) {\n return _createFoundryWidgetClient<C>(\n window.__PALANTIR_WIDGET_API__ as PalantirWidgetApi<C>,\n );\n }\n // todo: drop support for sandbox v1\n return _createFoundryWidgetClientLegacy<C>();\n}\n\ninterface PalantirWidgetApiEvents<C extends WidgetConfig<C[\"parameters\"]>> {\n message: CustomEvent<HostMessage<C>>;\n}\n\ninterface PalantirWidgetApi<C extends WidgetConfig<C[\"parameters\"]>> {\n sendMessage: <M extends WidgetMessage<C>>(message: M) => void;\n addEventListener<K extends keyof PalantirWidgetApiEvents<C>>(\n type: K,\n listener: (ev: PalantirWidgetApiEvents<C>[K]) => any,\n options?: boolean | AddEventListenerOptions,\n ): void;\n removeEventListener<K extends keyof PalantirWidgetApiEvents<C>>(\n type: K,\n listener: (ev: PalantirWidgetApiEvents<C>[K]) => any,\n options?: boolean | EventListenerOptions,\n ): void;\n}\n\nfunction _createFoundryWidgetClient<\n C extends WidgetConfig<C[\"parameters\"]>,\n>(\n widgetApi: PalantirWidgetApi<C>,\n): FoundryWidgetClient<C> {\n const hostEventTarget = new FoundryHostEventTarget<C>();\n\n const listenForHostMessages = (event: CustomEvent<HostMessage<C>>) => {\n visitHostMessage(event.detail, {\n \"host.update-parameters\": (payload) => {\n hostEventTarget.dispatchEventMessage(\"host.update-parameters\", payload);\n },\n _unknown: () => {\n // Do nothing\n },\n });\n };\n const sendMessageToHost = <M extends WidgetMessage<C>>(message: M) => {\n widgetApi.sendMessage(message);\n };\n\n return {\n hostEventTarget,\n ready: () => {\n sendMessageToHost({\n type: \"widget.ready\",\n payload: {\n apiVersion: HostMessage.Version,\n },\n });\n },\n emitEvent: (eventId, payload) => {\n sendMessageToHost({\n type: \"widget.emit-event\",\n payload: {\n eventId,\n ...payload,\n },\n });\n },\n sendMessage: sendMessageToHost,\n subscribe: () => {\n widgetApi.addEventListener(\"message\", listenForHostMessages);\n },\n unsubscribe: () => {\n widgetApi.removeEventListener(\"message\", listenForHostMessages);\n },\n };\n}\n\n// todo: drop support for sandbox v1\nfunction _createFoundryWidgetClientLegacy<\n C extends WidgetConfig<C[\"parameters\"]>,\n>(): FoundryWidgetClient<C> {\n invariant(window.parent, \"[FoundryWidgetClient] Must be run in an iframe\");\n const parentWindow = window.parent;\n const metaTag = document.querySelector(\n `meta[name=\"${META_TAG_HOST_ORIGIN}\"]`,\n );\n invariant(\n metaTag,\n \"[FoundryWidgetClient] Missing host origin meta tag \"\n + META_TAG_HOST_ORIGIN,\n );\n const hostOrigin = metaTag.getAttribute(\"content\");\n invariant(\n hostOrigin,\n \"[FoundryWidgetClient] Missing host origin meta tag content\",\n );\n const hostEventTarget = new FoundryHostEventTarget<C>();\n\n const listenForHostMessages = (event: MessageEvent<HostMessage<C>>) => {\n visitHostMessage(event.data, {\n \"host.update-parameters\": (payload) => {\n hostEventTarget.dispatchEventMessage(\"host.update-parameters\", payload);\n },\n _unknown: () => {\n // Do nothing\n },\n });\n };\n const sendMessageToHost = <M extends WidgetMessage<C>>(message: M) => {\n parentWindow.postMessage(message, hostOrigin);\n };\n\n return {\n hostEventTarget,\n ready: () => {\n sendMessageToHost({\n type: \"widget.ready\",\n payload: {\n apiVersion: HostMessage.Version,\n },\n });\n },\n emitEvent: (eventId, payload) => {\n sendMessageToHost({\n type: \"widget.emit-event\",\n payload: {\n eventId,\n ...payload,\n },\n });\n },\n sendMessage: sendMessageToHost,\n subscribe: () => {\n window.addEventListener(\"message\", (event) => {\n if (event.origin !== hostOrigin) {\n // Reject messages that aren't coming from the configured host\n return;\n }\n listenForHostMessages(event);\n });\n },\n unsubscribe: () => {\n window.removeEventListener(\"message\", listenForHostMessages);\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SACEA,WAAW,EACXC,gBAAgB,QAGX,kBAAkB;AACzB,SAASC,oBAAoB,QAAQ,kBAAkB;AACvD,OAAOC,SAAS,MAAM,gBAAgB;AACtC,SAASC,sBAAsB,QAAQ,WAAW;AAsClD,OAAO,SAASC,yBAAyBA,CAAA,EAEb;EAC1B,IAAI,yBAAyB,IAAIC,MAAM,EAAE;IACvC,OAAOC,0BAA0B,CAC/BD,MAAM,CAACE,uBACT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AAO,EAAE;UACPW,OAAO;UACP,GAAGX;QACL;MACF,CAAC,CAAC;IACJ,CAAC;IACDK,WAAW,EAAEF,iBAAiB;IAC9BS,SAAS,EAAEA,CAAA,KAAM;MACfrB,MAAM,CAACsB,gBAAgB,CAAC,SAAS,EAAGf,KAAK,IAAK;QAC5C,IAAIA,KAAK,CAAC8B,MAAM,KAAKJ,UAAU,EAAE;UAC/B;UACA;QACF;QACA3B,qBAAqB,CAACC,KAAK,CAAC;MAC9B,CAAC,CAAC;IACJ,CAAC;IACDgB,WAAW,EAAEA,CAAA,KAAM;MACjBvB,MAAM,CAACwB,mBAAmB,CAAC,SAAS,EAAElB,qBAAqB,CAAC;IAC9D;EACF,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"client.js","names":["HostMessage","visitHostMessage","invariant","FoundryHostEventTarget","createFoundryWidgetClient","window","process","env","NODE_ENV","widgetApi","__PALANTIR_WIDGET_API__","hostEventTarget","listenForHostMessages","event","detail","payload","dispatchEventMessage","_unknown","sendMessageToHost","message","sendMessage","ready","type","apiVersion","Version","emitEvent","eventId","subscribe","addEventListener","unsubscribe","removeEventListener"],"sources":["client.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 HostMessage,\n visitHostMessage,\n type WidgetConfig,\n type WidgetMessage,\n} from \"@osdk/widget.api\";\nimport invariant from \"tiny-invariant\";\nimport { FoundryHostEventTarget } from \"./host.js\";\n\nexport interface FoundryWidgetClient<C extends WidgetConfig<C[\"parameters\"]>> {\n /**\n * Notifies the host that this client is ready to receive the first parameter values\n */\n ready: () => void;\n\n /**\n * Emits an event with the given ID and payload\n */\n emitEvent: <M extends WidgetMessage.EmitEvent<C>>(\n eventId: M[\"payload\"][\"eventId\"],\n payload: Omit<M[\"payload\"], \"eventId\">,\n ) => void;\n\n /**\n * Sends a message to the parent frame.\n * It is recommended to use the convenience methods for individual messages (e.g. ready or emitEvent) instead\n */\n sendMessage: <M extends WidgetMessage<C>>(message: M) => void;\n\n /**\n * Subscribes to events from the host, invoking the listener when a message is received\n */\n subscribe: () => void;\n\n /**\n * Unsubscribes a previously subscribed listener from host events, if one exists\n */\n unsubscribe: () => void;\n\n /**\n * Event targets on which you can subscribe to specific host messages\n */\n hostEventTarget: FoundryHostEventTarget<C>;\n}\n\ninterface PalantirWidgetApiEvents<C extends WidgetConfig<C[\"parameters\"]>> {\n message: CustomEvent<HostMessage<C>>;\n}\n\ninterface PalantirWidgetApi<C extends WidgetConfig<C[\"parameters\"]>> {\n sendMessage: <M extends WidgetMessage<C>>(message: M) => void;\n addEventListener<K extends keyof PalantirWidgetApiEvents<C>>(\n type: K,\n listener: (ev: PalantirWidgetApiEvents<C>[K]) => any,\n options?: boolean | AddEventListenerOptions,\n ): void;\n removeEventListener<K extends keyof PalantirWidgetApiEvents<C>>(\n type: K,\n listener: (ev: PalantirWidgetApiEvents<C>[K]) => any,\n options?: boolean | EventListenerOptions,\n ): void;\n}\n\nexport function createFoundryWidgetClient<\n C extends WidgetConfig<C[\"parameters\"]>,\n>(): FoundryWidgetClient<C> {\n invariant(\n \"__PALANTIR_WIDGET_API__\" in window,\n \"[FoundryWidgetClient] Missing __PALANTIR_WIDGET_API__ in window\",\n );\n const widgetApi = window.__PALANTIR_WIDGET_API__ as PalantirWidgetApi<C>;\n const hostEventTarget = new FoundryHostEventTarget<C>();\n\n const listenForHostMessages = (event: CustomEvent<HostMessage<C>>) => {\n visitHostMessage(event.detail, {\n \"host.update-parameters\": (payload) => {\n hostEventTarget.dispatchEventMessage(\"host.update-parameters\", payload);\n },\n _unknown: () => {\n // Do nothing\n },\n });\n };\n const sendMessageToHost = <M extends WidgetMessage<C>>(message: M) => {\n widgetApi.sendMessage(message);\n };\n\n return {\n hostEventTarget,\n ready: () => {\n sendMessageToHost({\n type: \"widget.ready\",\n payload: {\n apiVersion: HostMessage.Version,\n },\n });\n },\n emitEvent: (eventId, payload) => {\n sendMessageToHost({\n type: \"widget.emit-event\",\n payload: {\n eventId,\n ...payload,\n },\n });\n },\n sendMessage: sendMessageToHost,\n subscribe: () => {\n widgetApi.addEventListener(\"message\", listenForHostMessages);\n },\n unsubscribe: () => {\n widgetApi.removeEventListener(\"message\", listenForHostMessages);\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SACEA,WAAW,EACXC,gBAAgB,QAGX,kBAAkB;AACzB,OAAOC,SAAS,MAAM,gBAAgB;AACtC,SAASC,sBAAsB,QAAQ,WAAW;AAwDlD,OAAO,SAASC,yBAAyBA,CAAA,EAEb;EAC1B,EACE,yBAAyB,IAAIC,MAAM,IAAAC,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBADrCN,SAAS,QAEP,iEAAiE,IAFnEA,SAAS;EAIT,MAAMO,SAAS,GAAGJ,MAAM,CAACK,uBAA+C;EACxE,MAAMC,eAAe,GAAG,IAAIR,sBAAsB,CAAI,CAAC;EAEvD,MAAMS,qBAAqB,GAAIC,KAAkC,IAAK;IACpEZ,gBAAgB,CAACY,KAAK,CAACC,MAAM,EAAE;MAC7B,wBAAwB,EAAGC,OAAO,IAAK;QACrCJ,eAAe,CAACK,oBAAoB,CAAC,wBAAwB,EAAED,OAAO,CAAC;MACzE,CAAC;MACDE,QAAQ,EAAEA,CAAA,KAAM;QACd;MAAA;IAEJ,CAAC,CAAC;EACJ,CAAC;EACD,MAAMC,iBAAiB,GAAgCC,OAAU,IAAK;IACpEV,SAAS,CAACW,WAAW,CAACD,OAAO,CAAC;EAChC,CAAC;EAED,OAAO;IACLR,eAAe;IACfU,KAAK,EAAEA,CAAA,KAAM;MACXH,iBAAiB,CAAC;QAChBI,IAAI,EAAE,cAAc;QACpBP,OAAO,EAAE;UACPQ,UAAU,EAAEvB,WAAW,CAACwB;QAC1B;MACF,CAAC,CAAC;IACJ,CAAC;IACDC,SAAS,EAAEA,CAACC,OAAO,EAAEX,OAAO,KAAK;MAC/BG,iBAAiB,CAAC;QAChBI,IAAI,EAAE,mBAAmB;QACzBP,OAAO,EAAE;UACPW,OAAO;UACP,GAAGX;QACL;MACF,CAAC,CAAC;IACJ,CAAC;IACDK,WAAW,EAAEF,iBAAiB;IAC9BS,SAAS,EAAEA,CAAA,KAAM;MACflB,SAAS,CAACmB,gBAAgB,CAAC,SAAS,EAAEhB,qBAAqB,CAAC;IAC9D,CAAC;IACDiB,WAAW,EAAEA,CAAA,KAAM;MACjBpB,SAAS,CAACqB,mBAAmB,CAAC,SAAS,EAAElB,qBAAqB,CAAC;IACjE;EACF,CAAC;AACH","ignoreList":[]}
|
package/build/cjs/index.cjs
CHANGED
|
@@ -26,12 +26,8 @@ var FoundryHostEventTarget = class extends EventTarget {
|
|
|
26
26
|
|
|
27
27
|
// src/client.ts
|
|
28
28
|
function createFoundryWidgetClient() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
return _createFoundryWidgetClientLegacy();
|
|
33
|
-
}
|
|
34
|
-
function _createFoundryWidgetClient(widgetApi) {
|
|
29
|
+
!("__PALANTIR_WIDGET_API__" in window) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, "[FoundryWidgetClient] Missing __PALANTIR_WIDGET_API__ in window") : invariant__default.default(false) : void 0;
|
|
30
|
+
const widgetApi = window.__PALANTIR_WIDGET_API__;
|
|
35
31
|
const hostEventTarget = new FoundryHostEventTarget();
|
|
36
32
|
const listenForHostMessages = (event) => {
|
|
37
33
|
widget_api.visitHostMessage(event.detail, {
|
|
@@ -73,59 +69,6 @@ function _createFoundryWidgetClient(widgetApi) {
|
|
|
73
69
|
}
|
|
74
70
|
};
|
|
75
71
|
}
|
|
76
|
-
function _createFoundryWidgetClientLegacy() {
|
|
77
|
-
!window.parent ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, "[FoundryWidgetClient] Must be run in an iframe") : invariant__default.default(false) : void 0;
|
|
78
|
-
const parentWindow = window.parent;
|
|
79
|
-
const metaTag = document.querySelector(`meta[name="${widget_api.META_TAG_HOST_ORIGIN}"]`);
|
|
80
|
-
!metaTag ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, "[FoundryWidgetClient] Missing host origin meta tag " + widget_api.META_TAG_HOST_ORIGIN) : invariant__default.default(false) : void 0;
|
|
81
|
-
const hostOrigin = metaTag.getAttribute("content");
|
|
82
|
-
!hostOrigin ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, "[FoundryWidgetClient] Missing host origin meta tag content") : invariant__default.default(false) : void 0;
|
|
83
|
-
const hostEventTarget = new FoundryHostEventTarget();
|
|
84
|
-
const listenForHostMessages = (event) => {
|
|
85
|
-
widget_api.visitHostMessage(event.data, {
|
|
86
|
-
"host.update-parameters": (payload) => {
|
|
87
|
-
hostEventTarget.dispatchEventMessage("host.update-parameters", payload);
|
|
88
|
-
},
|
|
89
|
-
_unknown: () => {
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
const sendMessageToHost = (message) => {
|
|
94
|
-
parentWindow.postMessage(message, hostOrigin);
|
|
95
|
-
};
|
|
96
|
-
return {
|
|
97
|
-
hostEventTarget,
|
|
98
|
-
ready: () => {
|
|
99
|
-
sendMessageToHost({
|
|
100
|
-
type: "widget.ready",
|
|
101
|
-
payload: {
|
|
102
|
-
apiVersion: widget_api.HostMessage.Version
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
},
|
|
106
|
-
emitEvent: (eventId, payload) => {
|
|
107
|
-
sendMessageToHost({
|
|
108
|
-
type: "widget.emit-event",
|
|
109
|
-
payload: {
|
|
110
|
-
eventId,
|
|
111
|
-
...payload
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
},
|
|
115
|
-
sendMessage: sendMessageToHost,
|
|
116
|
-
subscribe: () => {
|
|
117
|
-
window.addEventListener("message", (event) => {
|
|
118
|
-
if (event.origin !== hostOrigin) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
listenForHostMessages(event);
|
|
122
|
-
});
|
|
123
|
-
},
|
|
124
|
-
unsubscribe: () => {
|
|
125
|
-
window.removeEventListener("message", listenForHostMessages);
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
72
|
|
|
130
73
|
Object.defineProperty(exports, "HostMessage", {
|
|
131
74
|
enumerable: true,
|
package/build/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/host.ts","../../src/client.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["../../src/host.ts","../../src/client.ts"],"names":["invariant","visitHostMessage","HostMessage"],"mappings":";;;;;;;;;;;;AAgBa,IAAA,sBAAA,GAAN,cAAqC,WAAY,CAAA;AAAA,EACtD,gBAAA,CAAiB,IAAM,EAAA,QAAA,EAAU,OAAS,EAAA;AACxC,IAAM,KAAA,CAAA,gBAAA,CAAiB,IAAM,EAAA,QAAA,EAAU,OAAO,CAAA;AAAA;AAChD,EACA,mBAAA,CAAoB,IAAM,EAAA,QAAA,EAAU,OAAS,EAAA;AAC3C,IAAM,KAAA,CAAA,mBAAA,CAAoB,IAAM,EAAA,QAAA,EAAU,OAAO,CAAA;AAAA;AACnD,EACA,oBAAA,CAAqB,MAAM,OAAS,EAAA;AAClC,IAAK,IAAA,CAAA,aAAA,CAAc,IAAI,WAAA,CAAY,IAAM,EAAA;AAAA,MACvC,MAAQ,EAAA;AAAA,KACT,CAAC,CAAA;AAAA;AAEN;;;ACTO,SAAS,yBAA4B,GAAA;AAC1C,EAAA,EAAE,yBAA6B,IA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GACF;AACF","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\nexport class FoundryHostEventTarget extends EventTarget {\n addEventListener(type, callback, options) {\n super.addEventListener(type, callback, options);\n }\n removeEventListener(type, callback, options) {\n super.removeEventListener(type, callback, options);\n }\n dispatchEventMessage(type, payload) {\n this.dispatchEvent(new CustomEvent(type, {\n detail: payload\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 { HostMessage, visitHostMessage } from \"@osdk/widget.api\";\nimport invariant from \"tiny-invariant\";\nimport { FoundryHostEventTarget } from \"./host.js\";\nexport function createFoundryWidgetClient() {\n !(\"__PALANTIR_WIDGET_API__\" in window) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"[FoundryWidgetClient] Missing __PALANTIR_WIDGET_API__ in window\") : invariant(false) : void 0;\n const widgetApi = window.__PALANTIR_WIDGET_API__;\n const hostEventTarget = new FoundryHostEventTarget();\n const listenForHostMessages = event => {\n visitHostMessage(event.detail, {\n \"host.update-parameters\": payload => {\n hostEventTarget.dispatchEventMessage(\"host.update-parameters\", payload);\n },\n _unknown: () => {\n // Do nothing\n }\n });\n };\n const sendMessageToHost = message => {\n widgetApi.sendMessage(message);\n };\n return {\n hostEventTarget,\n ready: () => {\n sendMessageToHost({\n type: \"widget.ready\",\n payload: {\n apiVersion: HostMessage.Version\n }\n });\n },\n emitEvent: (eventId, payload) => {\n sendMessageToHost({\n type: \"widget.emit-event\",\n payload: {\n eventId,\n ...payload\n }\n });\n },\n sendMessage: sendMessageToHost,\n subscribe: () => {\n widgetApi.addEventListener(\"message\", listenForHostMessages);\n },\n unsubscribe: () => {\n widgetApi.removeEventListener(\"message\", listenForHostMessages);\n }\n };\n}"]}
|
package/build/esm/client.js
CHANGED
|
@@ -15,17 +15,11 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { HostMessage, visitHostMessage } from "@osdk/widget.api";
|
|
18
|
-
import { META_TAG_HOST_ORIGIN } from "@osdk/widget.api";
|
|
19
18
|
import invariant from "tiny-invariant";
|
|
20
19
|
import { FoundryHostEventTarget } from "./host.js";
|
|
21
20
|
export function createFoundryWidgetClient() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
// todo: drop support for sandbox v1
|
|
26
|
-
return _createFoundryWidgetClientLegacy();
|
|
27
|
-
}
|
|
28
|
-
function _createFoundryWidgetClient(widgetApi) {
|
|
21
|
+
!("__PALANTIR_WIDGET_API__" in window) ? process.env.NODE_ENV !== "production" ? invariant(false, "[FoundryWidgetClient] Missing __PALANTIR_WIDGET_API__ in window") : invariant(false) : void 0;
|
|
22
|
+
const widgetApi = window.__PALANTIR_WIDGET_API__;
|
|
29
23
|
const hostEventTarget = new FoundryHostEventTarget();
|
|
30
24
|
const listenForHostMessages = event => {
|
|
31
25
|
visitHostMessage(event.detail, {
|
|
@@ -68,61 +62,4 @@ function _createFoundryWidgetClient(widgetApi) {
|
|
|
68
62
|
}
|
|
69
63
|
};
|
|
70
64
|
}
|
|
71
|
-
|
|
72
|
-
// todo: drop support for sandbox v1
|
|
73
|
-
function _createFoundryWidgetClientLegacy() {
|
|
74
|
-
!window.parent ? process.env.NODE_ENV !== "production" ? invariant(false, "[FoundryWidgetClient] Must be run in an iframe") : invariant(false) : void 0;
|
|
75
|
-
const parentWindow = window.parent;
|
|
76
|
-
const metaTag = document.querySelector(`meta[name="${META_TAG_HOST_ORIGIN}"]`);
|
|
77
|
-
!metaTag ? process.env.NODE_ENV !== "production" ? invariant(false, "[FoundryWidgetClient] Missing host origin meta tag " + META_TAG_HOST_ORIGIN) : invariant(false) : void 0;
|
|
78
|
-
const hostOrigin = metaTag.getAttribute("content");
|
|
79
|
-
!hostOrigin ? process.env.NODE_ENV !== "production" ? invariant(false, "[FoundryWidgetClient] Missing host origin meta tag content") : invariant(false) : void 0;
|
|
80
|
-
const hostEventTarget = new FoundryHostEventTarget();
|
|
81
|
-
const listenForHostMessages = event => {
|
|
82
|
-
visitHostMessage(event.data, {
|
|
83
|
-
"host.update-parameters": payload => {
|
|
84
|
-
hostEventTarget.dispatchEventMessage("host.update-parameters", payload);
|
|
85
|
-
},
|
|
86
|
-
_unknown: () => {
|
|
87
|
-
// Do nothing
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
const sendMessageToHost = message => {
|
|
92
|
-
parentWindow.postMessage(message, hostOrigin);
|
|
93
|
-
};
|
|
94
|
-
return {
|
|
95
|
-
hostEventTarget,
|
|
96
|
-
ready: () => {
|
|
97
|
-
sendMessageToHost({
|
|
98
|
-
type: "widget.ready",
|
|
99
|
-
payload: {
|
|
100
|
-
apiVersion: HostMessage.Version
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
},
|
|
104
|
-
emitEvent: (eventId, payload) => {
|
|
105
|
-
sendMessageToHost({
|
|
106
|
-
type: "widget.emit-event",
|
|
107
|
-
payload: {
|
|
108
|
-
eventId,
|
|
109
|
-
...payload
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
},
|
|
113
|
-
sendMessage: sendMessageToHost,
|
|
114
|
-
subscribe: () => {
|
|
115
|
-
window.addEventListener("message", event => {
|
|
116
|
-
if (event.origin !== hostOrigin) {
|
|
117
|
-
// Reject messages that aren't coming from the configured host
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
listenForHostMessages(event);
|
|
121
|
-
});
|
|
122
|
-
},
|
|
123
|
-
unsubscribe: () => {
|
|
124
|
-
window.removeEventListener("message", listenForHostMessages);
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
65
|
//# sourceMappingURL=client.js.map
|
package/build/esm/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":["HostMessage","visitHostMessage","META_TAG_HOST_ORIGIN","invariant","FoundryHostEventTarget","createFoundryWidgetClient","window","_createFoundryWidgetClient","__PALANTIR_WIDGET_API__","_createFoundryWidgetClientLegacy","widgetApi","hostEventTarget","listenForHostMessages","event","detail","payload","dispatchEventMessage","_unknown","sendMessageToHost","message","sendMessage","ready","type","apiVersion","Version","emitEvent","eventId","subscribe","addEventListener","unsubscribe","removeEventListener","parent","process","env","NODE_ENV","parentWindow","metaTag","document","querySelector","hostOrigin","getAttribute","data","postMessage","origin"],"sources":["client.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 HostMessage,\n visitHostMessage,\n type WidgetConfig,\n type WidgetMessage,\n} from \"@osdk/widget.api\";\nimport { META_TAG_HOST_ORIGIN } from \"@osdk/widget.api\";\nimport invariant from \"tiny-invariant\";\nimport { FoundryHostEventTarget } from \"./host.js\";\n\nexport interface FoundryWidgetClient<C extends WidgetConfig<C[\"parameters\"]>> {\n /**\n * Notifies the host that this client is ready to receive the first parameter values\n */\n ready: () => void;\n\n /**\n * Emits an event with the given ID and payload\n */\n emitEvent: <M extends WidgetMessage.EmitEvent<C>>(\n eventId: M[\"payload\"][\"eventId\"],\n payload: Omit<M[\"payload\"], \"eventId\">,\n ) => void;\n\n /**\n * Sends a message to the parent frame.\n * It is recommended to use the convenience methods for individual messages (e.g. ready or emitEvent) instead\n */\n sendMessage: <M extends WidgetMessage<C>>(message: M) => void;\n\n /**\n * Subscribes to events from the host, invoking the listener when a message is received\n */\n subscribe: () => void;\n\n /**\n * Unsubscribes a previously subscribed listener from host events, if one exists\n */\n unsubscribe: () => void;\n\n /**\n * Event targets on which you can subscribe to specific host messages\n */\n hostEventTarget: FoundryHostEventTarget<C>;\n}\n\nexport function createFoundryWidgetClient<\n C extends WidgetConfig<C[\"parameters\"]>,\n>(): FoundryWidgetClient<C> {\n if (\"__PALANTIR_WIDGET_API__\" in window) {\n return _createFoundryWidgetClient<C>(\n window.__PALANTIR_WIDGET_API__ as PalantirWidgetApi<C>,\n );\n }\n // todo: drop support for sandbox v1\n return _createFoundryWidgetClientLegacy<C>();\n}\n\ninterface PalantirWidgetApiEvents<C extends WidgetConfig<C[\"parameters\"]>> {\n message: CustomEvent<HostMessage<C>>;\n}\n\ninterface PalantirWidgetApi<C extends WidgetConfig<C[\"parameters\"]>> {\n sendMessage: <M extends WidgetMessage<C>>(message: M) => void;\n addEventListener<K extends keyof PalantirWidgetApiEvents<C>>(\n type: K,\n listener: (ev: PalantirWidgetApiEvents<C>[K]) => any,\n options?: boolean | AddEventListenerOptions,\n ): void;\n removeEventListener<K extends keyof PalantirWidgetApiEvents<C>>(\n type: K,\n listener: (ev: PalantirWidgetApiEvents<C>[K]) => any,\n options?: boolean | EventListenerOptions,\n ): void;\n}\n\nfunction _createFoundryWidgetClient<\n C extends WidgetConfig<C[\"parameters\"]>,\n>(\n widgetApi: PalantirWidgetApi<C>,\n): FoundryWidgetClient<C> {\n const hostEventTarget = new FoundryHostEventTarget<C>();\n\n const listenForHostMessages = (event: CustomEvent<HostMessage<C>>) => {\n visitHostMessage(event.detail, {\n \"host.update-parameters\": (payload) => {\n hostEventTarget.dispatchEventMessage(\"host.update-parameters\", payload);\n },\n _unknown: () => {\n // Do nothing\n },\n });\n };\n const sendMessageToHost = <M extends WidgetMessage<C>>(message: M) => {\n widgetApi.sendMessage(message);\n };\n\n return {\n hostEventTarget,\n ready: () => {\n sendMessageToHost({\n type: \"widget.ready\",\n payload: {\n apiVersion: HostMessage.Version,\n },\n });\n },\n emitEvent: (eventId, payload) => {\n sendMessageToHost({\n type: \"widget.emit-event\",\n payload: {\n eventId,\n ...payload,\n },\n });\n },\n sendMessage: sendMessageToHost,\n subscribe: () => {\n widgetApi.addEventListener(\"message\", listenForHostMessages);\n },\n unsubscribe: () => {\n widgetApi.removeEventListener(\"message\", listenForHostMessages);\n },\n };\n}\n\n// todo: drop support for sandbox v1\nfunction _createFoundryWidgetClientLegacy<\n C extends WidgetConfig<C[\"parameters\"]>,\n>(): FoundryWidgetClient<C> {\n invariant(window.parent, \"[FoundryWidgetClient] Must be run in an iframe\");\n const parentWindow = window.parent;\n const metaTag = document.querySelector(\n `meta[name=\"${META_TAG_HOST_ORIGIN}\"]`,\n );\n invariant(\n metaTag,\n \"[FoundryWidgetClient] Missing host origin meta tag \"\n + META_TAG_HOST_ORIGIN,\n );\n const hostOrigin = metaTag.getAttribute(\"content\");\n invariant(\n hostOrigin,\n \"[FoundryWidgetClient] Missing host origin meta tag content\",\n );\n const hostEventTarget = new FoundryHostEventTarget<C>();\n\n const listenForHostMessages = (event: MessageEvent<HostMessage<C>>) => {\n visitHostMessage(event.data, {\n \"host.update-parameters\": (payload) => {\n hostEventTarget.dispatchEventMessage(\"host.update-parameters\", payload);\n },\n _unknown: () => {\n // Do nothing\n },\n });\n };\n const sendMessageToHost = <M extends WidgetMessage<C>>(message: M) => {\n parentWindow.postMessage(message, hostOrigin);\n };\n\n return {\n hostEventTarget,\n ready: () => {\n sendMessageToHost({\n type: \"widget.ready\",\n payload: {\n apiVersion: HostMessage.Version,\n },\n });\n },\n emitEvent: (eventId, payload) => {\n sendMessageToHost({\n type: \"widget.emit-event\",\n payload: {\n eventId,\n ...payload,\n },\n });\n },\n sendMessage: sendMessageToHost,\n subscribe: () => {\n window.addEventListener(\"message\", (event) => {\n if (event.origin !== hostOrigin) {\n // Reject messages that aren't coming from the configured host\n return;\n }\n listenForHostMessages(event);\n });\n },\n unsubscribe: () => {\n window.removeEventListener(\"message\", listenForHostMessages);\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SACEA,WAAW,EACXC,gBAAgB,QAGX,kBAAkB;AACzB,SAASC,oBAAoB,QAAQ,kBAAkB;AACvD,OAAOC,SAAS,MAAM,gBAAgB;AACtC,SAASC,sBAAsB,QAAQ,WAAW;AAsClD,OAAO,SAASC,yBAAyBA,CAAA,EAEb;EAC1B,IAAI,yBAAyB,IAAIC,MAAM,EAAE;IACvC,OAAOC,0BAA0B,CAC/BD,MAAM,CAACE,uBACT,CAAC;EACH;EACA;EACA,OAAOC,gCAAgC,CAAI,CAAC;AAC9C;AAoBA,SAASF,0BAA0BA,CAGjCG,SAA+B,EACP;EACxB,MAAMC,eAAe,GAAG,IAAIP,sBAAsB,CAAI,CAAC;EAEvD,MAAMQ,qBAAqB,GAAIC,KAAkC,IAAK;IACpEZ,gBAAgB,CAACY,KAAK,CAACC,MAAM,EAAE;MAC7B,wBAAwB,EAAGC,OAAO,IAAK;QACrCJ,eAAe,CAACK,oBAAoB,CAAC,wBAAwB,EAAED,OAAO,CAAC;MACzE,CAAC;MACDE,QAAQ,EAAEA,CAAA,KAAM;QACd;MAAA;IAEJ,CAAC,CAAC;EACJ,CAAC;EACD,MAAMC,iBAAiB,GAAgCC,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}
|
|
1
|
+
{"version":3,"file":"client.js","names":["HostMessage","visitHostMessage","invariant","FoundryHostEventTarget","createFoundryWidgetClient","window","process","env","NODE_ENV","widgetApi","__PALANTIR_WIDGET_API__","hostEventTarget","listenForHostMessages","event","detail","payload","dispatchEventMessage","_unknown","sendMessageToHost","message","sendMessage","ready","type","apiVersion","Version","emitEvent","eventId","subscribe","addEventListener","unsubscribe","removeEventListener"],"sources":["client.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 HostMessage,\n visitHostMessage,\n type WidgetConfig,\n type WidgetMessage,\n} from \"@osdk/widget.api\";\nimport invariant from \"tiny-invariant\";\nimport { FoundryHostEventTarget } from \"./host.js\";\n\nexport interface FoundryWidgetClient<C extends WidgetConfig<C[\"parameters\"]>> {\n /**\n * Notifies the host that this client is ready to receive the first parameter values\n */\n ready: () => void;\n\n /**\n * Emits an event with the given ID and payload\n */\n emitEvent: <M extends WidgetMessage.EmitEvent<C>>(\n eventId: M[\"payload\"][\"eventId\"],\n payload: Omit<M[\"payload\"], \"eventId\">,\n ) => void;\n\n /**\n * Sends a message to the parent frame.\n * It is recommended to use the convenience methods for individual messages (e.g. ready or emitEvent) instead\n */\n sendMessage: <M extends WidgetMessage<C>>(message: M) => void;\n\n /**\n * Subscribes to events from the host, invoking the listener when a message is received\n */\n subscribe: () => void;\n\n /**\n * Unsubscribes a previously subscribed listener from host events, if one exists\n */\n unsubscribe: () => void;\n\n /**\n * Event targets on which you can subscribe to specific host messages\n */\n hostEventTarget: FoundryHostEventTarget<C>;\n}\n\ninterface PalantirWidgetApiEvents<C extends WidgetConfig<C[\"parameters\"]>> {\n message: CustomEvent<HostMessage<C>>;\n}\n\ninterface PalantirWidgetApi<C extends WidgetConfig<C[\"parameters\"]>> {\n sendMessage: <M extends WidgetMessage<C>>(message: M) => void;\n addEventListener<K extends keyof PalantirWidgetApiEvents<C>>(\n type: K,\n listener: (ev: PalantirWidgetApiEvents<C>[K]) => any,\n options?: boolean | AddEventListenerOptions,\n ): void;\n removeEventListener<K extends keyof PalantirWidgetApiEvents<C>>(\n type: K,\n listener: (ev: PalantirWidgetApiEvents<C>[K]) => any,\n options?: boolean | EventListenerOptions,\n ): void;\n}\n\nexport function createFoundryWidgetClient<\n C extends WidgetConfig<C[\"parameters\"]>,\n>(): FoundryWidgetClient<C> {\n invariant(\n \"__PALANTIR_WIDGET_API__\" in window,\n \"[FoundryWidgetClient] Missing __PALANTIR_WIDGET_API__ in window\",\n );\n const widgetApi = window.__PALANTIR_WIDGET_API__ as PalantirWidgetApi<C>;\n const hostEventTarget = new FoundryHostEventTarget<C>();\n\n const listenForHostMessages = (event: CustomEvent<HostMessage<C>>) => {\n visitHostMessage(event.detail, {\n \"host.update-parameters\": (payload) => {\n hostEventTarget.dispatchEventMessage(\"host.update-parameters\", payload);\n },\n _unknown: () => {\n // Do nothing\n },\n });\n };\n const sendMessageToHost = <M extends WidgetMessage<C>>(message: M) => {\n widgetApi.sendMessage(message);\n };\n\n return {\n hostEventTarget,\n ready: () => {\n sendMessageToHost({\n type: \"widget.ready\",\n payload: {\n apiVersion: HostMessage.Version,\n },\n });\n },\n emitEvent: (eventId, payload) => {\n sendMessageToHost({\n type: \"widget.emit-event\",\n payload: {\n eventId,\n ...payload,\n },\n });\n },\n sendMessage: sendMessageToHost,\n subscribe: () => {\n widgetApi.addEventListener(\"message\", listenForHostMessages);\n },\n unsubscribe: () => {\n widgetApi.removeEventListener(\"message\", listenForHostMessages);\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA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B,SAAS,CAACmB,gBAAgB,CAAC,SAAS,EAAEhB,qBAAqB,CAAC;IAC9D,CAAC;IACDiB,WAAW,EAAEA,CAAA,KAAM;MACjBpB,SAAS,CAACqB,mBAAmB,CAAC,SAAS,EAAElB,qBAAqB,CAAC;IACjE;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,cAGO,mBACA,qBACA,kBAAmB;
|
|
1
|
+
{"mappings":"AAgBA,cAGO,mBACA,qBACA,kBAAmB;AAE1B,SAAS,8BAA8B,WAAY;AAEnD,iBAAiB,oBAAoB,UAAU,aAAa,EAAE,gBAAgB;;;;CAI5E;;;;CAKA,YAAY,UAAU,cAAc,UAAU,IAC5CA,SAAS,EAAE,WAAW,YACtBC,SAAS,KAAK,EAAE,YAAY;;;;;CAO9B,cAAc,UAAU,cAAc,IAAIC,SAAS;;;;CAKnD;;;;CAKA;;;;CAKA,iBAAiB,uBAAuB;AACzC;AAoBD,OAAO,iBAAS,0BACd,UAAU,aAAa,EAAE,mBACtB,oBAAoB","names":["eventId: M[\"payload\"][\"eventId\"]","payload: Omit<M[\"payload\"], \"eventId\">","message: M"],"sources":["../../src/client.ts"],"version":3,"file":"client.d.ts"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osdk/widget.client",
|
|
3
|
-
"version": "3.1.0-beta.
|
|
3
|
+
"version": "3.1.0-beta.4",
|
|
4
4
|
"description": "Client that sets up listeners for the custom widgets embedded into Foundry, adhering to the contract laid out in @osdk/widget.api",
|
|
5
5
|
"access": "public",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"tiny-invariant": "^1.3.1",
|
|
33
|
-
"@osdk/widget.api": "~3.1.0-beta.
|
|
33
|
+
"@osdk/widget.api": "~3.1.0-beta.4"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"ts-expect": "^1.3.0",
|
|
37
37
|
"typescript": "~5.5.4",
|
|
38
|
-
"@osdk/monorepo.
|
|
39
|
-
"@osdk/monorepo.
|
|
38
|
+
"@osdk/monorepo.api-extractor": "~0.3.0-beta.1",
|
|
39
|
+
"@osdk/monorepo.tsconfig": "~0.3.0-beta.1"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|