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