@machinemetrics/mm-react-embeddable 1.0.11-0 → 1.0.12
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
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("react/jsx-runtime"),t=require("react"),w=require("prop-types"),Z=require("styled-components"),S=t.createContext(null),$=({children:n})=>{const[i,d]=t.useState({}),a=t.useRef({}),u=t.useRef({}),c=t.useRef({}),M=t.useCallback((e,r)=>!!c.current[e]?.has(r),[]),p=t.useCallback((e,r,s)=>{d(o=>({...o,[e]:{origin:r,frameRef:s}}))},[]),y=t.useCallback(e=>{d(r=>{const s={...r};return delete s[e],s}),delete c.current[e]},[]);t.useEffect(()=>{const e=(s=[],o)=>{s.forEach(l=>l(o))},r=s=>{if(!s?.data?.instanceId)return;const{instanceId:o,type:l}=s.data,m=a.current;if(l==="response"){const{callbackId:E,response:F,error:C}=s.data,q=u.current[E];q&&(q(F,C),delete u.current[E]);return}if(l==="mark-registered"){const{requestType:E}=s.data;c.current[o]||(c.current[o]=new Set),c.current[o].add(E);return}e(m[o]?.[l],s.data),e(m["*"]?.[l],s.data),e(m[o]?.["*"],s.data),e(m["*"]?.["*"],s.data)};return window.addEventListener("message",r),()=>{window.removeEventListener("message",r)}},[i]);const f=t.useCallback((e,r,s)=>{const o=i[e];if(!o){console.warn(`Origin not set for id: ${e}. Unable to send message.`);return}o?.frameRef?.current?.contentWindow&&o.frameRef.current.contentWindow.postMessage({type:r,...s,instanceId:e},o.origin)},[i]),b=t.useRef(0),k=t.useCallback(()=>`${Date.now()}-${++b.current}`,[]),h=t.useCallback(async(e,r,s={})=>new Promise((o,l)=>{const m=k(),E=(F,C)=>{delete u.current[m],C?l(C):o(F)};u.current[m]=E,f(e,"request",{callbackId:m,requestType:r,data:s})}),[f]),R=t.useCallback((e,r)=>{f(e,"load-options",r)},[f]),g=t.useCallback((e,r)=>{f(e,"validate",r)},[f]),v=t.useMemo(()=>({registerFrame:p,unregisterFrame:y,sendMessage:f,sendRequest:h,loadOptions:R,validate:g,hasHandler:M,addListener:(e,r,s)=>(a.current[e]||(a.current[e]={}),a.current[e][r]||(a.current[e][r]=[]),a.current[e][r].push(s),()=>{a.current[e][r]=a.current[e][r].filter(o=>o!==s)})}),[p,y,f,h,R,g,M]);return x.jsx(S.Provider,{value:v,children:n})},I={},j=async n=>{try{const i=new URL(n).origin;if(I[i]!==void 0)return I[i];const a=await(await fetch(`${i}/mm-app-manifest.json`)).json();if(!a.version)throw new Error("Invalid manifest");return I[i]=a,a}catch{}return I[origin]=!1,!1},P=async n=>!!await j(n),L=(n,i,d)=>{const a=t.useContext(S);if(a===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const u=t.useRef(d);t.useEffect(()=>{u.current=d},[d]),t.useEffect(()=>{if(!(!n||!i))return a.addListener(n,i,(...c)=>u.current(...c))},[a,n,i])};$.propTypes={children:w.node.isRequired};const T=Z.default||Z,U=T.iframe`
|
|
2
2
|
width: 100%;
|
|
3
3
|
height: 100%;
|
|
4
4
|
border: none;
|
|
5
|
-
visibility: ${
|
|
6
|
-
`,
|
|
5
|
+
visibility: ${n=>n.$isReady?"visible":"hidden"};
|
|
6
|
+
`,A=({id:n,src:i,path:d,onInit:a=()=>{},context:u={},params:c={},...M})=>{if("isConfiguring"in M)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in u)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in u)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const p=t.useRef(),[y,f]=t.useState(),[b,k]=t.useState(0),{registerFrame:h,unregisterFrame:R,sendMessage:g}=t.useContext(S),[v,e]=t.useState(!0),[r,s]=t.useState();return t.useEffect(()=>{b&&g(n,"set-context",{context:{...u,colorMode:c.colorMode,isFullScreen:c.isFullScreen}})},[u,c.colorMode,c.isFullScreen,n,b]),t.useEffect(()=>{b&&(g(n,"set-params",{params:c}),g(n,"set-configuring",{isConfiguring:c.isConfiguring}))},[c,n,b]),t.useEffect(()=>{d!==void 0&&s(d||"/")},[d]),t.useEffect(()=>{r===void 0||!b||g(n,"navigate",{path:r})},[r,b,n,g]),t.useEffect(()=>{if(!(!i||!n||!p))return(async()=>{const o=await P(i);if(e(o),o){const l=new URL(i);h(n,l.origin,p),a(),f(`${l.origin}/mm-embedded-interop?id=${n}&origin=${window.location.origin}`);return}})(),()=>{R(n)}},[i,n,h,p]),L(n,"ready",()=>k(o=>o+1)),v?x.jsx(U,{$isReady:b,ref:p,src:y,...M}):x.jsx("div",{style:{height:"100%",display:"flex",flex:1,alignItems:"center",justifyContent:"center"},children:x.jsx("div",{style:{textAlign:"center"},children:"Application must adhere to the MM App Manifest specification to be embedded."})})};A.propTypes={id:w.string,src:w.string.isRequired,path:w.string,onInit:w.func};exports.MMEmbeddableZone=A;exports.MMEmbeddableZoneContext=S;exports.MMEmbeddableZoneProvider=$;exports.getAppInfo=j;exports.testIsEmbeddable=P;exports.useEmbeddedEffect=L;
|
|
@@ -1,194 +1,187 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
const
|
|
6
|
-
const [o,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
u((n) => {
|
|
13
|
-
const r = { ...n };
|
|
14
|
-
return delete r[e], r;
|
|
1
|
+
import { jsx as x } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as j, useState as R, useRef as w, useCallback as b, useEffect as p, useMemo as A, useContext as U } from "react";
|
|
3
|
+
import I from "prop-types";
|
|
4
|
+
import k from "styled-components";
|
|
5
|
+
const Z = j(null), T = ({ children: n }) => {
|
|
6
|
+
const [o, d] = R({}), i = w({}), a = w({}), c = w({}), y = b((e, r) => !!c.current[e]?.has(r), []), h = b((e, r, t) => {
|
|
7
|
+
d((s) => ({ ...s, [e]: { origin: r, frameRef: t } }));
|
|
8
|
+
}, []), F = b((e) => {
|
|
9
|
+
d((r) => {
|
|
10
|
+
const t = { ...r };
|
|
11
|
+
return delete t[e], t;
|
|
15
12
|
}), delete c.current[e];
|
|
16
13
|
}, []);
|
|
17
|
-
|
|
18
|
-
const e = (
|
|
19
|
-
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
if (!(($ = r == null ? void 0 : r.data) != null && $.instanceId))
|
|
14
|
+
p(() => {
|
|
15
|
+
const e = (t = [], s) => {
|
|
16
|
+
t.forEach((u) => u(s));
|
|
17
|
+
}, r = (t) => {
|
|
18
|
+
if (!t?.data?.instanceId)
|
|
23
19
|
return;
|
|
24
|
-
const { instanceId: s, type:
|
|
25
|
-
if (
|
|
26
|
-
const { callbackId:
|
|
27
|
-
|
|
20
|
+
const { instanceId: s, type: u } = t.data, g = i.current;
|
|
21
|
+
if (u === "response") {
|
|
22
|
+
const { callbackId: M, response: S, error: $ } = t.data, q = a.current[M];
|
|
23
|
+
q && (q(S, $), delete a.current[M]);
|
|
28
24
|
return;
|
|
29
25
|
}
|
|
30
|
-
if (
|
|
31
|
-
const { requestType:
|
|
32
|
-
c.current[s] || (c.current[s] = /* @__PURE__ */ new Set()), c.current[s].add(
|
|
26
|
+
if (u === "mark-registered") {
|
|
27
|
+
const { requestType: M } = t.data;
|
|
28
|
+
c.current[s] || (c.current[s] = /* @__PURE__ */ new Set()), c.current[s].add(M);
|
|
33
29
|
return;
|
|
34
30
|
}
|
|
35
|
-
e(
|
|
31
|
+
e(g[s]?.[u], t.data), e(g["*"]?.[u], t.data), e(g[s]?.["*"], t.data), e(g["*"]?.["*"], t.data);
|
|
36
32
|
};
|
|
37
|
-
return window.addEventListener("message",
|
|
38
|
-
window.removeEventListener("message",
|
|
33
|
+
return window.addEventListener("message", r), () => {
|
|
34
|
+
window.removeEventListener("message", r);
|
|
39
35
|
};
|
|
40
36
|
}, [o]);
|
|
41
|
-
const
|
|
42
|
-
(e,
|
|
43
|
-
var a, l;
|
|
37
|
+
const l = b(
|
|
38
|
+
(e, r, t) => {
|
|
44
39
|
const s = o[e];
|
|
45
40
|
if (!s) {
|
|
46
41
|
console.warn(`Origin not set for id: ${e}. Unable to send message.`);
|
|
47
42
|
return;
|
|
48
43
|
}
|
|
49
|
-
|
|
50
|
-
{ type:
|
|
44
|
+
s?.frameRef?.current?.contentWindow && s.frameRef.current.contentWindow.postMessage(
|
|
45
|
+
{ type: r, ...t, instanceId: e },
|
|
51
46
|
s.origin
|
|
52
47
|
);
|
|
53
48
|
},
|
|
54
49
|
[o]
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const l = Z(), $ = (x, y) => {
|
|
60
|
-
delete d.current[l], y ? a(y) : s(x);
|
|
50
|
+
), f = w(0), L = b(() => `${Date.now()}-${++f.current}`, []), E = b(
|
|
51
|
+
async (e, r, t = {}) => new Promise((s, u) => {
|
|
52
|
+
const g = L(), M = (S, $) => {
|
|
53
|
+
delete a.current[g], $ ? u($) : s(S);
|
|
61
54
|
};
|
|
62
|
-
|
|
55
|
+
a.current[g] = M, l(e, "request", { callbackId: g, requestType: r, data: t });
|
|
63
56
|
}),
|
|
64
|
-
[
|
|
65
|
-
), C =
|
|
66
|
-
(e,
|
|
67
|
-
|
|
57
|
+
[l]
|
|
58
|
+
), C = b(
|
|
59
|
+
(e, r) => {
|
|
60
|
+
l(e, "load-options", r);
|
|
68
61
|
},
|
|
69
|
-
[
|
|
70
|
-
), m =
|
|
71
|
-
(e,
|
|
72
|
-
|
|
62
|
+
[l]
|
|
63
|
+
), m = b(
|
|
64
|
+
(e, r) => {
|
|
65
|
+
l(e, "validate", r);
|
|
73
66
|
},
|
|
74
|
-
[
|
|
75
|
-
),
|
|
67
|
+
[l]
|
|
68
|
+
), P = A(
|
|
76
69
|
() => ({
|
|
77
|
-
registerFrame:
|
|
70
|
+
registerFrame: h,
|
|
78
71
|
unregisterFrame: F,
|
|
79
|
-
sendMessage:
|
|
80
|
-
sendRequest:
|
|
72
|
+
sendMessage: l,
|
|
73
|
+
sendRequest: E,
|
|
81
74
|
loadOptions: C,
|
|
82
75
|
validate: m,
|
|
83
|
-
hasHandler:
|
|
84
|
-
addListener: (e,
|
|
85
|
-
i.current[e][
|
|
76
|
+
hasHandler: y,
|
|
77
|
+
addListener: (e, r, t) => (i.current[e] || (i.current[e] = {}), i.current[e][r] || (i.current[e][r] = []), i.current[e][r].push(t), () => {
|
|
78
|
+
i.current[e][r] = i.current[e][r].filter((s) => s !== t);
|
|
86
79
|
})
|
|
87
80
|
}),
|
|
88
81
|
[
|
|
89
|
-
|
|
82
|
+
h,
|
|
90
83
|
F,
|
|
91
|
-
|
|
92
|
-
|
|
84
|
+
l,
|
|
85
|
+
E,
|
|
93
86
|
C,
|
|
94
87
|
m,
|
|
95
|
-
|
|
88
|
+
y
|
|
96
89
|
]
|
|
97
90
|
);
|
|
98
|
-
return /* @__PURE__ */
|
|
99
|
-
},
|
|
91
|
+
return /* @__PURE__ */ x(Z.Provider, { value: P, children: n });
|
|
92
|
+
}, v = {}, O = async (n) => {
|
|
100
93
|
try {
|
|
101
|
-
const o = new URL(
|
|
102
|
-
if (
|
|
103
|
-
return
|
|
94
|
+
const o = new URL(n).origin;
|
|
95
|
+
if (v[o] !== void 0)
|
|
96
|
+
return v[o];
|
|
104
97
|
const i = await (await fetch(`${o}/mm-app-manifest.json`)).json();
|
|
105
98
|
if (!i.version)
|
|
106
99
|
throw new Error("Invalid manifest");
|
|
107
|
-
return
|
|
100
|
+
return v[o] = i, i;
|
|
108
101
|
} catch {
|
|
109
102
|
}
|
|
110
|
-
return
|
|
111
|
-
},
|
|
112
|
-
const i =
|
|
103
|
+
return v[origin] = !1, !1;
|
|
104
|
+
}, H = async (n) => !!await O(n), W = (n, o, d) => {
|
|
105
|
+
const i = U(Z);
|
|
113
106
|
if (i === null)
|
|
114
107
|
throw new Error(
|
|
115
108
|
"useEmbeddedEffect must be used within a MMEmbeddableZoneProvider"
|
|
116
109
|
);
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}, [
|
|
121
|
-
if (!(!
|
|
110
|
+
const a = w(d);
|
|
111
|
+
p(() => {
|
|
112
|
+
a.current = d;
|
|
113
|
+
}, [d]), p(() => {
|
|
114
|
+
if (!(!n || !o))
|
|
122
115
|
return i.addListener(
|
|
123
|
-
|
|
116
|
+
n,
|
|
124
117
|
o,
|
|
125
|
-
(...c) =>
|
|
118
|
+
(...c) => a.current(...c)
|
|
126
119
|
);
|
|
127
|
-
}, [i,
|
|
120
|
+
}, [i, n, o]);
|
|
128
121
|
};
|
|
129
|
-
|
|
130
|
-
children:
|
|
122
|
+
T.propTypes = {
|
|
123
|
+
children: I.node.isRequired
|
|
131
124
|
};
|
|
132
|
-
const
|
|
125
|
+
const B = k.default || k, D = B.iframe`
|
|
133
126
|
width: 100%;
|
|
134
127
|
height: 100%;
|
|
135
128
|
border: none;
|
|
136
|
-
visibility: ${(
|
|
137
|
-
`,
|
|
138
|
-
id:
|
|
129
|
+
visibility: ${(n) => n.$isReady ? "visible" : "hidden"};
|
|
130
|
+
`, _ = ({
|
|
131
|
+
id: n,
|
|
139
132
|
src: o,
|
|
140
|
-
path:
|
|
133
|
+
path: d,
|
|
141
134
|
onInit: i = () => {
|
|
142
135
|
},
|
|
143
|
-
context:
|
|
136
|
+
context: a = {},
|
|
144
137
|
params: c = {},
|
|
145
|
-
...
|
|
138
|
+
...y
|
|
146
139
|
}) => {
|
|
147
|
-
if ("isConfiguring" in
|
|
140
|
+
if ("isConfiguring" in y)
|
|
148
141
|
return console.error(
|
|
149
142
|
"isConfiguring must be passed via the params prop to MMEmbeddableZone"
|
|
150
143
|
), null;
|
|
151
|
-
if ("colorMode" in
|
|
144
|
+
if ("colorMode" in a)
|
|
152
145
|
return console.error(
|
|
153
146
|
"colorMode must be passed via the params prop to MMEmbeddableZone"
|
|
154
147
|
), null;
|
|
155
|
-
if ("isFullScreen" in
|
|
148
|
+
if ("isFullScreen" in a)
|
|
156
149
|
return console.error(
|
|
157
150
|
"isFullScreen must be passed via the params prop to MMEmbeddableZone"
|
|
158
151
|
), null;
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
), [
|
|
162
|
-
return
|
|
163
|
-
|
|
152
|
+
const h = w(), [F, l] = R(), [f, L] = R(0), { registerFrame: E, unregisterFrame: C, sendMessage: m } = U(
|
|
153
|
+
Z
|
|
154
|
+
), [P, e] = R(!0), [r, t] = R();
|
|
155
|
+
return p(() => {
|
|
156
|
+
f && m(n, "set-context", {
|
|
164
157
|
context: {
|
|
165
|
-
...
|
|
158
|
+
...a,
|
|
166
159
|
// TODO: Remove this once everything is migrated to params
|
|
167
160
|
colorMode: c.colorMode,
|
|
168
161
|
isFullScreen: c.isFullScreen
|
|
169
162
|
}
|
|
170
163
|
});
|
|
171
|
-
}, [
|
|
172
|
-
|
|
173
|
-
}, [c,
|
|
174
|
-
|
|
175
|
-
}, [
|
|
176
|
-
|
|
177
|
-
}, [
|
|
178
|
-
if (!(!o || !
|
|
164
|
+
}, [a, c.colorMode, c.isFullScreen, n, f]), p(() => {
|
|
165
|
+
f && (m(n, "set-params", { params: c }), m(n, "set-configuring", { isConfiguring: c.isConfiguring }));
|
|
166
|
+
}, [c, n, f]), p(() => {
|
|
167
|
+
d !== void 0 && t(d || "/");
|
|
168
|
+
}, [d]), p(() => {
|
|
169
|
+
r === void 0 || !f || m(n, "navigate", { path: r });
|
|
170
|
+
}, [r, f, n, m]), p(() => {
|
|
171
|
+
if (!(!o || !n || !h))
|
|
179
172
|
return (async () => {
|
|
180
|
-
const s = await
|
|
173
|
+
const s = await H(o);
|
|
181
174
|
if (e(s), s) {
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
`${
|
|
175
|
+
const u = new URL(o);
|
|
176
|
+
E(n, u.origin, h), i(), l(
|
|
177
|
+
`${u.origin}/mm-embedded-interop?id=${n}&origin=${window.location.origin}`
|
|
185
178
|
);
|
|
186
179
|
return;
|
|
187
180
|
}
|
|
188
181
|
})(), () => {
|
|
189
|
-
C(
|
|
182
|
+
C(n);
|
|
190
183
|
};
|
|
191
|
-
}, [o,
|
|
184
|
+
}, [o, n, E, h]), W(n, "ready", () => L((s) => s + 1)), P ? /* @__PURE__ */ x(D, { $isReady: f, ref: h, src: F, ...y }) : /* @__PURE__ */ x(
|
|
192
185
|
"div",
|
|
193
186
|
{
|
|
194
187
|
style: {
|
|
@@ -198,21 +191,21 @@ const J = A.default || A, K = J.iframe`
|
|
|
198
191
|
alignItems: "center",
|
|
199
192
|
justifyContent: "center"
|
|
200
193
|
},
|
|
201
|
-
children: /* @__PURE__ */
|
|
194
|
+
children: /* @__PURE__ */ x("div", { style: { textAlign: "center" }, children: "Application must adhere to the MM App Manifest specification to be embedded." })
|
|
202
195
|
}
|
|
203
196
|
);
|
|
204
197
|
};
|
|
205
|
-
|
|
206
|
-
id:
|
|
207
|
-
src:
|
|
208
|
-
path:
|
|
209
|
-
onInit:
|
|
198
|
+
_.propTypes = {
|
|
199
|
+
id: I.string,
|
|
200
|
+
src: I.string.isRequired,
|
|
201
|
+
path: I.string,
|
|
202
|
+
onInit: I.func
|
|
210
203
|
};
|
|
211
204
|
export {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
205
|
+
_ as MMEmbeddableZone,
|
|
206
|
+
Z as MMEmbeddableZoneContext,
|
|
207
|
+
T as MMEmbeddableZoneProvider,
|
|
208
|
+
O as getAppInfo,
|
|
209
|
+
H as testIsEmbeddable,
|
|
210
|
+
W as useEmbeddedEffect
|
|
218
211
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(d,
|
|
1
|
+
(function(d,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react/jsx-runtime"),require("react"),require("prop-types"),require("styled-components")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","prop-types","styled-components"],g):(d=typeof globalThis<"u"?globalThis:d||self,g(d["mm-react-embeddable"]={},d.React,d.React,d.PropTypes,d.styled))})(this,(function(d,g,e,y,$){"use strict";const C=e.createContext(null),x=({children:r})=>{const[i,l]=e.useState({}),u=e.useRef({}),a=e.useRef({}),c=e.useRef({}),w=e.useCallback((n,t)=>!!c.current[n]?.has(t),[]),M=e.useCallback((n,t,s)=>{l(o=>({...o,[n]:{origin:t,frameRef:s}}))},[]),S=e.useCallback(n=>{l(t=>{const s={...t};return delete s[n],s}),delete c.current[n]},[]);e.useEffect(()=>{const n=(s=[],o)=>{s.forEach(f=>f(o))},t=s=>{if(!s?.data?.instanceId)return;const{instanceId:o,type:f}=s.data,E=u.current;if(f==="response"){const{callbackId:h,response:Z,error:v}=s.data,U=a.current[h];U&&(U(Z,v),delete a.current[h]);return}if(f==="mark-registered"){const{requestType:h}=s.data;c.current[o]||(c.current[o]=new Set),c.current[o].add(h);return}n(E[o]?.[f],s.data),n(E["*"]?.[f],s.data),n(E[o]?.["*"],s.data),n(E["*"]?.["*"],s.data)};return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}},[i]);const b=e.useCallback((n,t,s)=>{const o=i[n];if(!o){console.warn(`Origin not set for id: ${n}. Unable to send message.`);return}o?.frameRef?.current?.contentWindow&&o.frameRef.current.contentWindow.postMessage({type:t,...s,instanceId:n},o.origin)},[i]),m=e.useRef(0),F=e.useCallback(()=>`${Date.now()}-${++m.current}`,[]),R=e.useCallback(async(n,t,s={})=>new Promise((o,f)=>{const E=F(),h=(Z,v)=>{delete a.current[E],v?f(v):o(Z)};a.current[E]=h,b(n,"request",{callbackId:E,requestType:t,data:s})}),[b]),k=e.useCallback((n,t)=>{b(n,"load-options",t)},[b]),p=e.useCallback((n,t)=>{b(n,"validate",t)},[b]),q=e.useMemo(()=>({registerFrame:M,unregisterFrame:S,sendMessage:b,sendRequest:R,loadOptions:k,validate:p,hasHandler:w,addListener:(n,t,s)=>(u.current[n]||(u.current[n]={}),u.current[n][t]||(u.current[n][t]=[]),u.current[n][t].push(s),()=>{u.current[n][t]=u.current[n][t].filter(o=>o!==s)})}),[M,S,b,R,k,p,w]);return g.jsx(C.Provider,{value:q,children:r})},I={},j=async r=>{try{const i=new URL(r).origin;if(I[i]!==void 0)return I[i];const u=await(await fetch(`${i}/mm-app-manifest.json`)).json();if(!u.version)throw new Error("Invalid manifest");return I[i]=u,u}catch{}return I[origin]=!1,!1},L=async r=>!!await j(r),A=(r,i,l)=>{const u=e.useContext(C);if(u===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const a=e.useRef(l);e.useEffect(()=>{a.current=l},[l]),e.useEffect(()=>{if(!(!r||!i))return u.addListener(r,i,(...c)=>a.current(...c))},[u,r,i])};x.propTypes={children:y.node.isRequired};const O=($.default||$).iframe`
|
|
2
2
|
width: 100%;
|
|
3
3
|
height: 100%;
|
|
4
4
|
border: none;
|
|
5
|
-
visibility: ${
|
|
6
|
-
`,
|
|
5
|
+
visibility: ${r=>r.$isReady?"visible":"hidden"};
|
|
6
|
+
`,P=({id:r,src:i,path:l,onInit:u=()=>{},context:a={},params:c={},...w})=>{if("isConfiguring"in w)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in a)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in a)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const M=e.useRef(),[S,b]=e.useState(),[m,F]=e.useState(0),{registerFrame:R,unregisterFrame:k,sendMessage:p}=e.useContext(C),[q,n]=e.useState(!0),[t,s]=e.useState();return e.useEffect(()=>{m&&p(r,"set-context",{context:{...a,colorMode:c.colorMode,isFullScreen:c.isFullScreen}})},[a,c.colorMode,c.isFullScreen,r,m]),e.useEffect(()=>{m&&(p(r,"set-params",{params:c}),p(r,"set-configuring",{isConfiguring:c.isConfiguring}))},[c,r,m]),e.useEffect(()=>{l!==void 0&&s(l||"/")},[l]),e.useEffect(()=>{t===void 0||!m||p(r,"navigate",{path:t})},[t,m,r,p]),e.useEffect(()=>{if(!(!i||!r||!M))return(async()=>{const o=await L(i);if(n(o),o){const f=new URL(i);R(r,f.origin,M),u(),b(`${f.origin}/mm-embedded-interop?id=${r}&origin=${window.location.origin}`);return}})(),()=>{k(r)}},[i,r,R,M]),A(r,"ready",()=>F(o=>o+1)),q?g.jsx(O,{$isReady:m,ref:M,src:S,...w}):g.jsx("div",{style:{height:"100%",display:"flex",flex:1,alignItems:"center",justifyContent:"center"},children:g.jsx("div",{style:{textAlign:"center"},children:"Application must adhere to the MM App Manifest specification to be embedded."})})};P.propTypes={id:y.string,src:y.string.isRequired,path:y.string,onInit:y.func},d.MMEmbeddableZone=P,d.MMEmbeddableZoneContext=C,d.MMEmbeddableZoneProvider=x,d.getAppInfo=j,d.testIsEmbeddable=L,d.useEmbeddedEffect=A,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": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"module": "dist/mm-react-embeddable.es.js",
|
|
6
6
|
"main": "dist/mm-react-embeddable.cjs.js",
|
|
@@ -26,8 +26,7 @@
|
|
|
26
26
|
"dist"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"prop-types": "^15.8.1"
|
|
30
|
-
"vite": "^5.4.8"
|
|
29
|
+
"prop-types": "^15.8.1"
|
|
31
30
|
},
|
|
32
31
|
"peerDependencies": {
|
|
33
32
|
"react": ">=16.0.0",
|
|
@@ -36,10 +35,11 @@
|
|
|
36
35
|
},
|
|
37
36
|
"devDependencies": {
|
|
38
37
|
"@testing-library/react": "^14.3.1",
|
|
39
|
-
"@vitejs/plugin-react": "^
|
|
40
|
-
"@vitest/coverage-v8": "^
|
|
38
|
+
"@vitejs/plugin-react": "^5.1.1",
|
|
39
|
+
"@vitest/coverage-v8": "^4.0.10",
|
|
41
40
|
"jsdom": "^24.1.3",
|
|
42
41
|
"prettier": "^3.3.3",
|
|
43
|
-
"
|
|
42
|
+
"vite": "^7.2.2",
|
|
43
|
+
"vitest": "^4.0.10"
|
|
44
44
|
}
|
|
45
45
|
}
|