@machinemetrics/mm-react-embeddable 0.10.1-0 → 0.10.1

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