@machinemetrics/mm-react-embeddable 0.10.2-1 → 0.10.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,6 +1,6 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),M=require("prop-types"),x=require("styled-components"),R=t.createContext(null),P=({children:r})=>{const[a,c]=t.useState({}),o=t.useRef({}),l=t.useCallback((e,s,n)=>{c(i=>({...i,[e]:{origin:s,frameRef:n}}))},[]),f=t.useCallback(e=>{c(s=>{const n={...s};return delete n[e],n})},[]);t.useEffect(()=>{const e=(n=[],i)=>{n.forEach(d=>d(i))},s=n=>{var y,E,w,b,p;if(!((y=n==null?void 0:n.data)!=null&&y.instanceId))return;const{instanceId:i,type:d}=n.data,g=o.current;e((E=g[i])==null?void 0:E[d],n.data),e((w=g["*"])==null?void 0:w[d],n.data),e((b=g[i])==null?void 0:b["*"],n.data),e((p=g["*"])==null?void 0:p["*"],n.data)};return window.addEventListener("message",s),()=>{window.removeEventListener("message",s)}},[a]);const u=t.useCallback((e,s,n)=>{console.log("sendMessage",e,s,n);const i=a[e];if(!i){console.warn(`Origin not set for id: ${e}. Unable to send message.`);return}i.frameRef.current.contentWindow.postMessage({type:s,...n,instanceId:e},i.origin)},[a]),m=t.useCallback((e,s)=>{u(e,"load-options",s)},[u]),I=t.useCallback((e,s)=>{u(e,"validate",s)},[u]),C={registerFrame:l,unregisterFrame:f,sendMessage:u,loadOptions:m,validate:I,addListener:(e,s,n)=>(o.current[e]||(o.current[e]={}),o.current[e][s]||(o.current[e][s]=[]),o.current[e][s].push(n),()=>{o.current[e][s]=o.current[e][s].filter(i=>i!==n)})};return t.createElement(R.Provider,{value:C},r)},h={},$=async r=>{try{const a=new URL(r).origin;if(h[a]!==void 0)return h[a];const o=await(await fetch(`${a}/mm-app-manifest.json`)).json();if(!o.version)throw new Error("Invalid manifest");return h[a]=o,o}catch{}return h[origin]=!1,!1},L=async r=>!!await $(r),S=(r,a,c)=>{const o=t.useContext(R);if(o===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const l=t.useRef(c);return t.useEffect(()=>{l.current=c},[c]),t.useEffect(()=>{if(!(!r||!a))return o.addListener(r,a,(...f)=>l.current(...f))},[o,r,a]),t.useCallback((f,u)=>o.sendMessage(r,f,u),[o,r])};P.propTypes={children:M.node.isRequired};const v=x.default||x,F=v.iframe`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),y=require("prop-types"),x=require("styled-components"),R=t.createContext(null),P=({children:r})=>{const[o,d]=t.useState({}),a=t.useRef({}),f=t.useCallback((e,s,n)=>{d(i=>({...i,[e]:{origin:s,frameRef:n}}))},[]),m=t.useCallback(e=>{d(s=>{const n={...s};return delete n[e],n})},[]);t.useEffect(()=>{const e=(n=[],i)=>{n.forEach(c=>c(i))},s=n=>{var w,E,M,b,p;if(!((w=n==null?void 0:n.data)!=null&&w.instanceId))return;const{instanceId:i,type:c}=n.data,u=a.current;e((E=u[i])==null?void 0:E[c],n.data),e((M=u["*"])==null?void 0:M[c],n.data),e((b=u[i])==null?void 0:b["*"],n.data),e((p=u["*"])==null?void 0:p["*"],n.data)};return window.addEventListener("message",s),()=>{window.removeEventListener("message",s)}},[o]);const l=t.useCallback((e,s,n)=>{var c,u;const i=o[e];if(!i){console.warn(`Origin not set for id: ${e}. Unable to send message.`);return}(u=(c=i==null?void 0:i.frameRef)==null?void 0:c.current)!=null&&u.contentWindow&&i.frameRef.current.contentWindow.postMessage({type:s,...n,instanceId:e},i.origin)},[o]),g=t.useCallback((e,s)=>{l(e,"load-options",s)},[l]),I=t.useCallback((e,s)=>{l(e,"validate",s)},[l]),C={registerFrame:f,unregisterFrame:m,sendMessage:l,loadOptions:g,validate:I,addListener:(e,s,n)=>(a.current[e]||(a.current[e]={}),a.current[e][s]||(a.current[e][s]=[]),a.current[e][s].push(n),()=>{a.current[e][s]=a.current[e][s].filter(i=>i!==n)})};return t.createElement(R.Provider,{value:C},r)},h={},$=async r=>{try{const o=new URL(r).origin;if(h[o]!==void 0)return h[o];const a=await(await fetch(`${o}/mm-app-manifest.json`)).json();if(!a.version)throw new Error("Invalid manifest");return h[o]=a,a}catch{}return h[origin]=!1,!1},L=async r=>!!await $(r),S=(r,o,d)=>{const a=t.useContext(R);if(a===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const f=t.useRef(d);t.useEffect(()=>{f.current=d},[d]),t.useEffect(()=>{if(!(!r||!o))return a.addListener(r,o,(...m)=>f.current(...m))},[a,r,o])};P.propTypes={children:y.node.isRequired};const v=x.default||x,F=v.iframe`
2
2
  width: 100%;
3
3
  height: 100%;
4
4
  border: none;
5
5
  visibility: ${r=>r.$isReady?"visible":"hidden"};
6
- `,Z=({id:r,src:a,path:c,onInit:o=()=>{},context:l,isConfiguring:f,...u})=>{const m=t.useRef(),[I,C]=t.useState(),[e,s]=t.useState(0),{registerFrame:n,unregisterFrame:i,sendMessage:d}=t.useContext(R),[g,y]=t.useState(!0),[E,w]=t.useState();return t.useEffect(()=>{e&&d(r,"set-context",{context:l})},[l,r,e]),t.useEffect(()=>{c!==void 0&&w(c)},[c]),t.useEffect(()=>{E===void 0||!e||d(r,"navigate",{path:E})},[E,e,r,d]),t.useEffect(()=>{e&&d(r,"set-configuring",{isConfiguring:f})},[e,f]),t.useEffect(()=>{if(!(!a||!r||!m))return(async()=>{const b=await L(a);if(y(b),b){const p=new URL(a);n(r,p.origin,m),o(),C(`${p.origin}/mm-embedded-interop?id=${r}&origin=${window.location.origin}`);return}})(),()=>{i(r)}},[a,r,n,m]),S(r,"ready",()=>s(b=>b+1)),g?t.createElement(F,{$isReady:e,ref:m,src:I,...u}):t.createElement("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center"}},t.createElement("div",{style:{textAlign:"center"}},"Application must adhere to the MM App Manifest specification to be embedded."))};Z.propTypes={id:M.string,src:M.string.isRequired,path:M.string,onInit:M.func};exports.MMEmbeddableZone=Z;exports.MMEmbeddableZoneContext=R;exports.MMEmbeddableZoneProvider=P;exports.getAppInfo=$;exports.testIsEmbeddable=L;exports.useEmbeddedEffect=S;
6
+ `,Z=({id:r,src:o,path:d,onInit:a=()=>{},context:f,isConfiguring:m,...l})=>{const g=t.useRef(),[I,C]=t.useState(),[e,s]=t.useState(0),{registerFrame:n,unregisterFrame:i,sendMessage:c}=t.useContext(R),[u,w]=t.useState(!0),[E,M]=t.useState();return t.useEffect(()=>{e&&c(r,"set-context",{context:f})},[f,r,e]),t.useEffect(()=>{d!==void 0&&M(d)},[d]),t.useEffect(()=>{E===void 0||!e||c(r,"navigate",{path:E})},[E,e,r,c]),t.useEffect(()=>{e&&c(r,"set-configuring",{isConfiguring:m})},[e,m]),t.useEffect(()=>{if(!(!o||!r||!g))return(async()=>{const b=await L(o);if(w(b),b){const p=new URL(o);n(r,p.origin,g),a(),C(`${p.origin}/mm-embedded-interop?id=${r}&origin=${window.location.origin}`);return}})(),()=>{i(r)}},[o,r,n,g]),S(r,"ready",()=>s(b=>b+1)),u?t.createElement(F,{$isReady:e,ref:g,src:I,...l}):t.createElement("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center"}},t.createElement("div",{style:{textAlign:"center"}},"Application must adhere to the MM App Manifest specification to be embedded."))};Z.propTypes={id:y.string,src:y.string.isRequired,path:y.string,onInit:y.func};exports.MMEmbeddableZone=Z;exports.MMEmbeddableZoneContext=R;exports.MMEmbeddableZoneProvider=P;exports.getAppInfo=$;exports.testIsEmbeddable=L;exports.useEmbeddedEffect=S;
@@ -1,133 +1,130 @@
1
- import x, { createContext as C, useState as h, useRef as F, useCallback as E, useEffect as f, useContext as A } from "react";
2
- import y from "prop-types";
1
+ import x, { createContext as C, useState as y, useRef as F, useCallback as E, useEffect as u, useContext as A } from "react";
2
+ import h from "prop-types";
3
3
  import v from "styled-components";
4
4
  const P = C(null), U = ({ children: t }) => {
5
- const [o, a] = h({}), s = F({}), l = E((e, n, r) => {
6
- a((i) => ({ ...i, [e]: { origin: n, frameRef: r } }));
7
- }, []), u = E((e) => {
8
- a((n) => {
5
+ const [s, c] = y({}), o = F({}), f = E((e, n, r) => {
6
+ c((i) => ({ ...i, [e]: { origin: n, frameRef: r } }));
7
+ }, []), g = E((e) => {
8
+ c((n) => {
9
9
  const r = { ...n };
10
10
  return delete r[e], r;
11
11
  });
12
12
  }, []);
13
- f(() => {
13
+ u(() => {
14
14
  const e = (r = [], i) => {
15
- r.forEach((d) => d(i));
15
+ r.forEach((a) => a(i));
16
16
  }, n = (r) => {
17
- var M, p, R, m, w;
18
- if (!((M = r == null ? void 0 : r.data) != null && M.instanceId))
17
+ var R, b, M, m, w;
18
+ if (!((R = r == null ? void 0 : r.data) != null && R.instanceId))
19
19
  return;
20
- const { instanceId: i, type: d } = r.data, b = s.current;
21
- e((p = b[i]) == null ? void 0 : p[d], r.data), e((R = b["*"]) == null ? void 0 : R[d], r.data), e((m = b[i]) == null ? void 0 : m["*"], r.data), e((w = b["*"]) == null ? void 0 : w["*"], r.data);
20
+ const { instanceId: i, type: a } = r.data, d = o.current;
21
+ e((b = d[i]) == null ? void 0 : b[a], r.data), e((M = d["*"]) == null ? void 0 : M[a], r.data), e((m = d[i]) == null ? void 0 : m["*"], r.data), e((w = d["*"]) == null ? void 0 : w["*"], r.data);
22
22
  };
23
23
  return window.addEventListener("message", n), () => {
24
24
  window.removeEventListener("message", n);
25
25
  };
26
- }, [o]);
27
- const c = E(
26
+ }, [s]);
27
+ const l = E(
28
28
  (e, n, r) => {
29
- console.log("sendMessage", e, n, r);
30
- const i = o[e];
29
+ var a, d;
30
+ const i = s[e];
31
31
  if (!i) {
32
32
  console.warn(`Origin not set for id: ${e}. Unable to send message.`);
33
33
  return;
34
34
  }
35
- i.frameRef.current.contentWindow.postMessage(
35
+ (d = (a = i == null ? void 0 : i.frameRef) == null ? void 0 : a.current) != null && d.contentWindow && i.frameRef.current.contentWindow.postMessage(
36
36
  { type: n, ...r, instanceId: e },
37
37
  i.origin
38
38
  );
39
39
  },
40
- [o]
41
- ), g = E(
40
+ [s]
41
+ ), p = E(
42
42
  (e, n) => {
43
- c(e, "load-options", n);
43
+ l(e, "load-options", n);
44
44
  },
45
- [c]
45
+ [l]
46
46
  ), $ = E(
47
47
  (e, n) => {
48
- c(e, "validate", n);
48
+ l(e, "validate", n);
49
49
  },
50
- [c]
50
+ [l]
51
51
  ), L = {
52
- registerFrame: l,
53
- unregisterFrame: u,
54
- sendMessage: c,
55
- loadOptions: g,
52
+ registerFrame: f,
53
+ unregisterFrame: g,
54
+ sendMessage: l,
55
+ loadOptions: p,
56
56
  validate: $,
57
- addListener: (e, n, r) => (s.current[e] || (s.current[e] = {}), s.current[e][n] || (s.current[e][n] = []), s.current[e][n].push(r), () => {
58
- s.current[e][n] = s.current[e][n].filter((i) => i !== r);
57
+ addListener: (e, n, r) => (o.current[e] || (o.current[e] = {}), o.current[e][n] || (o.current[e][n] = []), o.current[e][n].push(r), () => {
58
+ o.current[e][n] = o.current[e][n].filter((i) => i !== r);
59
59
  })
60
60
  };
61
61
  return /* @__PURE__ */ x.createElement(P.Provider, { value: L }, t);
62
62
  }, I = {}, Z = async (t) => {
63
63
  try {
64
- const o = new URL(t).origin;
65
- if (I[o] !== void 0)
66
- return I[o];
67
- const s = await (await fetch(`${o}/mm-app-manifest.json`)).json();
68
- if (!s.version)
64
+ const s = new URL(t).origin;
65
+ if (I[s] !== void 0)
66
+ return I[s];
67
+ const o = await (await fetch(`${s}/mm-app-manifest.json`)).json();
68
+ if (!o.version)
69
69
  throw new Error("Invalid manifest");
70
- return I[o] = s, s;
70
+ return I[s] = o, o;
71
71
  } catch {
72
72
  }
73
73
  return I[origin] = !1, !1;
74
- }, j = async (t) => !!await Z(t), O = (t, o, a) => {
75
- const s = A(P);
76
- if (s === null)
74
+ }, j = async (t) => !!await Z(t), O = (t, s, c) => {
75
+ const o = A(P);
76
+ if (o === null)
77
77
  throw new Error(
78
78
  "useEmbeddedEffect must be used within a MMEmbeddableZoneProvider"
79
79
  );
80
- const l = F(a);
81
- return f(() => {
82
- l.current = a;
83
- }, [a]), f(() => {
84
- if (!(!t || !o))
85
- return s.addListener(
80
+ const f = F(c);
81
+ u(() => {
82
+ f.current = c;
83
+ }, [c]), u(() => {
84
+ if (!(!t || !s))
85
+ return o.addListener(
86
86
  t,
87
- o,
88
- (...u) => l.current(...u)
87
+ s,
88
+ (...g) => f.current(...g)
89
89
  );
90
- }, [s, t, o]), E(
91
- (u, c) => s.sendMessage(t, u, c),
92
- [s, t]
93
- );
90
+ }, [o, t, s]);
94
91
  };
95
92
  U.propTypes = {
96
- children: y.node.isRequired
93
+ children: h.node.isRequired
97
94
  };
98
95
  const T = v.default || v, q = T.iframe`
99
96
  width: 100%;
100
97
  height: 100%;
101
98
  border: none;
102
99
  visibility: ${(t) => t.$isReady ? "visible" : "hidden"};
103
- `, S = ({
100
+ `, W = ({
104
101
  id: t,
105
- src: o,
106
- path: a,
107
- onInit: s = () => {
102
+ src: s,
103
+ path: c,
104
+ onInit: o = () => {
108
105
  },
109
- context: l,
110
- isConfiguring: u,
111
- ...c
106
+ context: f,
107
+ isConfiguring: g,
108
+ ...l
112
109
  }) => {
113
- const g = F(), [$, L] = h(), [e, n] = h(0), { registerFrame: r, unregisterFrame: i, sendMessage: d } = A(
110
+ const p = F(), [$, L] = y(), [e, n] = y(0), { registerFrame: r, unregisterFrame: i, sendMessage: a } = A(
114
111
  P
115
- ), [b, M] = h(!0), [p, R] = h();
116
- return f(() => {
117
- e && d(t, "set-context", { context: l });
118
- }, [l, t, e]), f(() => {
119
- a !== void 0 && R(a);
120
- }, [a]), f(() => {
121
- p === void 0 || !e || d(t, "navigate", { path: p });
122
- }, [p, e, t, d]), f(() => {
123
- e && d(t, "set-configuring", { isConfiguring: u });
124
- }, [e, u]), f(() => {
125
- if (!(!o || !t || !g))
112
+ ), [d, R] = y(!0), [b, M] = y();
113
+ return u(() => {
114
+ e && a(t, "set-context", { context: f });
115
+ }, [f, t, e]), u(() => {
116
+ c !== void 0 && M(c);
117
+ }, [c]), u(() => {
118
+ b === void 0 || !e || a(t, "navigate", { path: b });
119
+ }, [b, e, t, a]), u(() => {
120
+ e && a(t, "set-configuring", { isConfiguring: g });
121
+ }, [e, g]), u(() => {
122
+ if (!(!s || !t || !p))
126
123
  return (async () => {
127
- const m = await j(o);
128
- if (M(m), m) {
129
- const w = new URL(o);
130
- r(t, w.origin, g), s(), L(
124
+ const m = await j(s);
125
+ if (R(m), m) {
126
+ const w = new URL(s);
127
+ r(t, w.origin, p), o(), L(
131
128
  `${w.origin}/mm-embedded-interop?id=${t}&origin=${window.location.origin}`
132
129
  );
133
130
  return;
@@ -135,7 +132,7 @@ const T = v.default || v, q = T.iframe`
135
132
  })(), () => {
136
133
  i(t);
137
134
  };
138
- }, [o, t, r, g]), O(t, "ready", () => n((m) => m + 1)), b ? /* @__PURE__ */ x.createElement(q, { $isReady: e, ref: g, src: $, ...c }) : /* @__PURE__ */ x.createElement(
135
+ }, [s, t, r, p]), O(t, "ready", () => n((m) => m + 1)), d ? /* @__PURE__ */ x.createElement(q, { $isReady: e, ref: p, src: $, ...l }) : /* @__PURE__ */ x.createElement(
139
136
  "div",
140
137
  {
141
138
  style: {
@@ -148,14 +145,14 @@ const T = v.default || v, q = T.iframe`
148
145
  /* @__PURE__ */ x.createElement("div", { style: { textAlign: "center" } }, "Application must adhere to the MM App Manifest specification to be embedded.")
149
146
  );
150
147
  };
151
- S.propTypes = {
152
- id: y.string,
153
- src: y.string.isRequired,
154
- path: y.string,
155
- onInit: y.func
148
+ W.propTypes = {
149
+ id: h.string,
150
+ src: h.string.isRequired,
151
+ path: h.string,
152
+ onInit: h.func
156
153
  };
157
154
  export {
158
- S as MMEmbeddableZone,
155
+ W as MMEmbeddableZone,
159
156
  P as MMEmbeddableZoneContext,
160
157
  U as MMEmbeddableZoneProvider,
161
158
  Z as getAppInfo,
@@ -1,6 +1,6 @@
1
- (function(d,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react"),require("prop-types"),require("styled-components")):typeof define=="function"&&define.amd?define(["exports","react","prop-types","styled-components"],e):(d=typeof globalThis<"u"?globalThis:d||self,e(d["mm-react-embeddable"]={},d.React,d.PropTypes,d.styled))})(this,function(d,e,y,S){"use strict";const h=e.createContext(null),Z=({children:n})=>{const[i,a]=e.useState({}),o=e.useRef({}),m=e.useCallback((t,s,r)=>{a(u=>({...u,[t]:{origin:s,frameRef:r}}))},[]),l=e.useCallback(t=>{a(s=>{const r={...s};return delete r[t],r})},[]);e.useEffect(()=>{const t=(r=[],u)=>{r.forEach(c=>c(u))},s=r=>{var I,p,C,b,M;if(!((I=r==null?void 0:r.data)!=null&&I.instanceId))return;const{instanceId:u,type:c}=r.data,E=o.current;t((p=E[u])==null?void 0:p[c],r.data),t((C=E["*"])==null?void 0:C[c],r.data),t((b=E[u])==null?void 0:b["*"],r.data),t((M=E["*"])==null?void 0:M["*"],r.data)};return window.addEventListener("message",s),()=>{window.removeEventListener("message",s)}},[i]);const f=e.useCallback((t,s,r)=>{console.log("sendMessage",t,s,r);const u=i[t];if(!u){console.warn(`Origin not set for id: ${t}. Unable to send message.`);return}u.frameRef.current.contentWindow.postMessage({type:s,...r,instanceId:t},u.origin)},[i]),g=e.useCallback((t,s)=>{f(t,"load-options",s)},[f]),$=e.useCallback((t,s)=>{f(t,"validate",s)},[f]),L={registerFrame:m,unregisterFrame:l,sendMessage:f,loadOptions:g,validate:$,addListener:(t,s,r)=>(o.current[t]||(o.current[t]={}),o.current[t][s]||(o.current[t][s]=[]),o.current[t][s].push(r),()=>{o.current[t][s]=o.current[t][s].filter(u=>u!==r)})};return e.createElement(h.Provider,{value:L},n)},w={},v=async n=>{try{const i=new URL(n).origin;if(w[i]!==void 0)return w[i];const o=await(await fetch(`${i}/mm-app-manifest.json`)).json();if(!o.version)throw new Error("Invalid manifest");return w[i]=o,o}catch{}return w[origin]=!1,!1},x=async n=>!!await v(n),F=(n,i,a)=>{const o=e.useContext(h);if(o===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const m=e.useRef(a);return e.useEffect(()=>{m.current=a},[a]),e.useEffect(()=>{if(!(!n||!i))return o.addListener(n,i,(...l)=>m.current(...l))},[o,n,i]),e.useCallback((l,f)=>o.sendMessage(n,l,f),[o,n])};Z.propTypes={children:y.node.isRequired};const q=(S.default||S).iframe`
1
+ (function(u,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react"),require("prop-types"),require("styled-components")):typeof define=="function"&&define.amd?define(["exports","react","prop-types","styled-components"],e):(u=typeof globalThis<"u"?globalThis:u||self,e(u["mm-react-embeddable"]={},u.React,u.PropTypes,u.styled))})(this,function(u,e,y,S){"use strict";const w=e.createContext(null),Z=({children:n})=>{const[i,f]=e.useState({}),o=e.useRef({}),l=e.useCallback((t,s,r)=>{f(d=>({...d,[t]:{origin:s,frameRef:r}}))},[]),E=e.useCallback(t=>{f(s=>{const r={...s};return delete r[t],r})},[]);e.useEffect(()=>{const t=(r=[],d)=>{r.forEach(a=>a(d))},s=r=>{var I,p,C,b,h;if(!((I=r==null?void 0:r.data)!=null&&I.instanceId))return;const{instanceId:d,type:a}=r.data,c=o.current;t((p=c[d])==null?void 0:p[a],r.data),t((C=c["*"])==null?void 0:C[a],r.data),t((b=c[d])==null?void 0:b["*"],r.data),t((h=c["*"])==null?void 0:h["*"],r.data)};return window.addEventListener("message",s),()=>{window.removeEventListener("message",s)}},[i]);const m=e.useCallback((t,s,r)=>{var a,c;const d=i[t];if(!d){console.warn(`Origin not set for id: ${t}. Unable to send message.`);return}(c=(a=d==null?void 0:d.frameRef)==null?void 0:a.current)!=null&&c.contentWindow&&d.frameRef.current.contentWindow.postMessage({type:s,...r,instanceId:t},d.origin)},[i]),g=e.useCallback((t,s)=>{m(t,"load-options",s)},[m]),$=e.useCallback((t,s)=>{m(t,"validate",s)},[m]),L={registerFrame:l,unregisterFrame:E,sendMessage:m,loadOptions:g,validate:$,addListener:(t,s,r)=>(o.current[t]||(o.current[t]={}),o.current[t][s]||(o.current[t][s]=[]),o.current[t][s].push(r),()=>{o.current[t][s]=o.current[t][s].filter(d=>d!==r)})};return e.createElement(w.Provider,{value:L},n)},M={},v=async n=>{try{const i=new URL(n).origin;if(M[i]!==void 0)return M[i];const o=await(await fetch(`${i}/mm-app-manifest.json`)).json();if(!o.version)throw new Error("Invalid manifest");return M[i]=o,o}catch{}return M[origin]=!1,!1},x=async n=>!!await v(n),F=(n,i,f)=>{const o=e.useContext(w);if(o===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const l=e.useRef(f);e.useEffect(()=>{l.current=f},[f]),e.useEffect(()=>{if(!(!n||!i))return o.addListener(n,i,(...E)=>l.current(...E))},[o,n,i])};Z.propTypes={children:y.node.isRequired};const q=(S.default||S).iframe`
2
2
  width: 100%;
3
3
  height: 100%;
4
4
  border: none;
5
5
  visibility: ${n=>n.$isReady?"visible":"hidden"};
6
- `,j=({id:n,src:i,path:a,onInit:o=()=>{},context:m,isConfiguring:l,...f})=>{const g=e.useRef(),[$,L]=e.useState(),[t,s]=e.useState(0),{registerFrame:r,unregisterFrame:u,sendMessage:c}=e.useContext(h),[E,I]=e.useState(!0),[p,C]=e.useState();return e.useEffect(()=>{t&&c(n,"set-context",{context:m})},[m,n,t]),e.useEffect(()=>{a!==void 0&&C(a)},[a]),e.useEffect(()=>{p===void 0||!t||c(n,"navigate",{path:p})},[p,t,n,c]),e.useEffect(()=>{t&&c(n,"set-configuring",{isConfiguring:l})},[t,l]),e.useEffect(()=>{if(!(!i||!n||!g))return(async()=>{const b=await x(i);if(I(b),b){const M=new URL(i);r(n,M.origin,g),o(),L(`${M.origin}/mm-embedded-interop?id=${n}&origin=${window.location.origin}`);return}})(),()=>{u(n)}},[i,n,r,g]),F(n,"ready",()=>s(b=>b+1)),E?e.createElement(q,{$isReady:t,ref:g,src:$,...f}):e.createElement("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center"}},e.createElement("div",{style:{textAlign:"center"}},"Application must adhere to the MM App Manifest specification to be embedded."))};j.propTypes={id:y.string,src:y.string.isRequired,path:y.string,onInit:y.func},d.MMEmbeddableZone=j,d.MMEmbeddableZoneContext=h,d.MMEmbeddableZoneProvider=Z,d.getAppInfo=v,d.testIsEmbeddable=x,d.useEmbeddedEffect=F,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
6
+ `,j=({id:n,src:i,path:f,onInit:o=()=>{},context:l,isConfiguring:E,...m})=>{const g=e.useRef(),[$,L]=e.useState(),[t,s]=e.useState(0),{registerFrame:r,unregisterFrame:d,sendMessage:a}=e.useContext(w),[c,I]=e.useState(!0),[p,C]=e.useState();return e.useEffect(()=>{t&&a(n,"set-context",{context:l})},[l,n,t]),e.useEffect(()=>{f!==void 0&&C(f)},[f]),e.useEffect(()=>{p===void 0||!t||a(n,"navigate",{path:p})},[p,t,n,a]),e.useEffect(()=>{t&&a(n,"set-configuring",{isConfiguring:E})},[t,E]),e.useEffect(()=>{if(!(!i||!n||!g))return(async()=>{const b=await x(i);if(I(b),b){const h=new URL(i);r(n,h.origin,g),o(),L(`${h.origin}/mm-embedded-interop?id=${n}&origin=${window.location.origin}`);return}})(),()=>{d(n)}},[i,n,r,g]),F(n,"ready",()=>s(b=>b+1)),c?e.createElement(q,{$isReady:t,ref:g,src:$,...m}):e.createElement("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center"}},e.createElement("div",{style:{textAlign:"center"}},"Application must adhere to the MM App Manifest specification to be embedded."))};j.propTypes={id:y.string,src:y.string.isRequired,path:y.string,onInit:y.func},u.MMEmbeddableZone=j,u.MMEmbeddableZoneContext=w,u.MMEmbeddableZoneProvider=Z,u.getAppInfo=v,u.testIsEmbeddable=x,u.useEmbeddedEffect=F,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machinemetrics/mm-react-embeddable",
3
- "version": "0.10.2-1",
3
+ "version": "0.10.3",
4
4
  "license": "MIT",
5
5
  "module": "dist/mm-react-embeddable.es.js",
6
6
  "main": "dist/mm-react-embeddable.cjs.js",