@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.
@@ -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
  };
@@ -0,0 +1,4 @@
1
+ export type Event = {
2
+ metadata: Record<string, unknown>;
3
+ type: string;
4
+ };
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { ConnectWidget } from './ConnectWidget';
2
+ export type { Event } from './consts';
package/dist/index.js CHANGED
@@ -1,30 +1,41 @@
1
- const m = ({
2
- containerSelector: n,
3
- iframeProps: o,
4
- url: s
1
+ const g = ({
2
+ containerSelector: s,
3
+ iframeProps: i,
4
+ onEvent: a,
5
+ url: o
5
6
  }) => {
6
- const t = document.createElement("iframe"), { style: i, ...c } = o || {}, a = {
7
+ const t = document.createElement("iframe"), { style: c, ...d } = i || {}, m = {
7
8
  height: "100%",
8
9
  width: "100%",
9
- ...i ?? {}
10
+ ...c ?? {}
10
11
  };
11
- Object.assign(t.style, a);
12
- for (const [e, r] of Object.entries(c))
13
- e.startsWith("data-") ? t.setAttribute(e, String(r)) : Object.assign(t, { [e]: r });
14
- return t.src = s, {
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(n);
27
+ const e = document.querySelector(s);
17
28
  if (!e)
18
29
  throw new Error(
19
- `Container with selector "${n}" not found.`
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
- m as ConnectWidget
40
+ g as ConnectWidget
30
41
  };
@@ -1 +1 @@
1
- (function(e,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(e=typeof globalThis<"u"?globalThis:e||self,o(e.index={}))})(this,(function(e){"use strict";const o=({containerSelector:i,iframeProps:r,url:d})=>{const t=document.createElement("iframe"),{style:f,...c}=r||{},u={height:"100%",width:"100%",...f??{}};Object.assign(t.style,u);for(const[n,s]of Object.entries(c))n.startsWith("data-")?t.setAttribute(n,String(s)):Object.assign(t,{[n]:s});return t.src=d,{mount:()=>{const n=document.querySelector(i);if(!n)throw new Error(`Container with selector "${i}" not found.`);n.appendChild(t)},unmount:()=>{t.remove()}}};e.ConnectWidget=o,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
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"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mxenabled/web-connect-widget-sdk",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "MX Connect Web Widget SDK",
5
5
  "files": [
6
6
  "dist"