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