@mxenabled/web-connect-widget-sdk 0.0.2 → 0.0.3
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/dist/ConnectWidget.d.ts +3 -1
- package/dist/consts.d.ts +4 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +26 -15
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/ConnectWidget.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { Event } from './consts';
|
|
1
2
|
interface ConnectWidgetProps {
|
|
2
3
|
containerSelector: string;
|
|
3
4
|
iframeProps?: Record<string, unknown>;
|
|
5
|
+
onEvent?: (event: Event) => void;
|
|
4
6
|
url: string;
|
|
5
7
|
}
|
|
6
|
-
export declare const ConnectWidget: ({ containerSelector, iframeProps, url, }: ConnectWidgetProps) => {
|
|
8
|
+
export declare const ConnectWidget: ({ containerSelector, iframeProps, onEvent, url, }: ConnectWidgetProps) => {
|
|
7
9
|
mount: () => void;
|
|
8
10
|
unmount: () => void;
|
|
9
11
|
};
|
package/dist/consts.d.ts
ADDED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,30 +1,41 @@
|
|
|
1
|
-
const
|
|
2
|
-
containerSelector:
|
|
3
|
-
iframeProps:
|
|
4
|
-
|
|
1
|
+
const g = ({
|
|
2
|
+
containerSelector: s,
|
|
3
|
+
iframeProps: i,
|
|
4
|
+
onEvent: a,
|
|
5
|
+
url: o
|
|
5
6
|
}) => {
|
|
6
|
-
const t = document.createElement("iframe"), { style:
|
|
7
|
+
const t = document.createElement("iframe"), { style: c, ...d } = i || {}, m = {
|
|
7
8
|
height: "100%",
|
|
8
9
|
width: "100%",
|
|
9
|
-
...
|
|
10
|
+
...c ?? {}
|
|
10
11
|
};
|
|
11
|
-
Object.assign(t.style,
|
|
12
|
-
for (const [e,
|
|
13
|
-
e.startsWith("data-") ? t.setAttribute(e, String(
|
|
14
|
-
|
|
12
|
+
Object.assign(t.style, m);
|
|
13
|
+
for (const [e, n] of Object.entries(d))
|
|
14
|
+
e.startsWith("data-") ? t.setAttribute(e, String(n)) : Object.assign(t, { [e]: n });
|
|
15
|
+
t.src = o;
|
|
16
|
+
const r = (e) => {
|
|
17
|
+
if (e.origin !== new URL(o).origin)
|
|
18
|
+
return;
|
|
19
|
+
const { data: n } = e, { metadata: f, type: u } = n;
|
|
20
|
+
a?.({
|
|
21
|
+
metadata: f,
|
|
22
|
+
type: u
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
15
26
|
mount: () => {
|
|
16
|
-
const e = document.querySelector(
|
|
27
|
+
const e = document.querySelector(s);
|
|
17
28
|
if (!e)
|
|
18
29
|
throw new Error(
|
|
19
|
-
`Container with selector "${
|
|
30
|
+
`Container with selector "${s}" not found.`
|
|
20
31
|
);
|
|
21
|
-
e.appendChild(t);
|
|
32
|
+
e.appendChild(t), window.addEventListener("message", r);
|
|
22
33
|
},
|
|
23
34
|
unmount: () => {
|
|
24
|
-
t.remove();
|
|
35
|
+
t.remove(), window.removeEventListener("message", r);
|
|
25
36
|
}
|
|
26
37
|
};
|
|
27
38
|
};
|
|
28
39
|
export {
|
|
29
|
-
|
|
40
|
+
g as ConnectWidget
|
|
30
41
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(t,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(t=typeof globalThis<"u"?globalThis:t||self,o(t.index={}))})(this,(function(t){"use strict";const o=({containerSelector:s,iframeProps:a,onEvent:c,url:r})=>{const n=document.createElement("iframe"),{style:f,...u}=a||{},m={height:"100%",width:"100%",...f??{}};Object.assign(n.style,m);for(const[e,i]of Object.entries(u))e.startsWith("data-")?n.setAttribute(e,String(i)):Object.assign(n,{[e]:i});n.src=r;const d=e=>{if(e.origin!==new URL(r).origin)return;const{data:i}=e,{metadata:l,type:g}=i;c?.({metadata:l,type:g})};return{mount:()=>{const e=document.querySelector(s);if(!e)throw new Error(`Container with selector "${s}" not found.`);e.appendChild(n),window.addEventListener("message",d)},unmount:()=>{n.remove(),window.removeEventListener("message",d)}}};t.ConnectWidget=o,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
|