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