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