@machinemetrics/mm-react-embeddable 1.4.0-0 → 1.4.0-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.
- package/dist/mm-react-embeddable.cjs.js +10 -10
- package/dist/mm-react-embeddable.es.js +323 -336
- package/dist/mm-react-embeddable.umd.js +10 -10
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),E=require("prop-types"),j=require("styled-components"),v=e.createContext(null),Z=e.createContext({pending:[],authorize:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{}}),ee=2e4,F=r=>{try{return new URL(r).origin}catch{return null}},W=r=>{if(!r||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(r)||r.includes(":"))return r;const u=r.split(".");return u.length<=2?r:u.slice(-2).join(".")},D=(r,u)=>{try{const s=new URL(r),d=new URL(u);return s.protocol!==d.protocol?!0:W(s.hostname)!==W(d.hostname)}catch{return!0}},H=(r,{onBlocked:u,onClosed:s})=>{const d=window.open(r.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!d)return u(),()=>{};const g=setInterval(()=>{d.closed&&(clearInterval(g),s())},1e3);return()=>clearInterval(g)},K=({children:r,launcher:u})=>{const s=e.useContext(v),[d,g]=e.useState({}),[R,p]=e.useState({}),[x,T]=e.useState({}),[I,w]=e.useState({}),y=e.useRef(x);y.current=x;const b=e.useRef(null),k=e.useRef({}),P=e.useRef({}),C=e.useCallback(t=>{const n=P.current[t];if(!n)return;const o=f=>f[t]?{...f,[t]:{...f[t],name:n}}:f;g(o),w(o)},[]),O=e.useCallback((t,n)=>{const o=F(t==null?void 0:t.authUrl);o&&(w(f=>f[o]?f:{...f,[o]:{origin:o,reason:n,name:null}}),C(o))},[C]),z=e.useCallback((t,{v2:n=!1}={})=>{const o=F(t==null?void 0:t.authUrl);o&&(n&&y.current[o]||(g(f=>f[o]?f:{...f,[o]:{origin:o,authUrl:t.authUrl,silentUrl:t.silentUrl||null,status:n&&t.silentUrl?"silent":"interactive",v2:n,name:null,popupBlocked:!1}}),C(o)))},[C]),S=e.useCallback(t=>{g(n=>{if(!n[t])return n;const o={...n};return delete o[t],o})},[]),i=e.useCallback(t=>{t&&(S(t),p(n=>({...n,[t]:(n[t]||0)+1})))},[S]),l=e.useCallback(t=>{g(n=>!n[t]||n[t].status==="interactive"?n:{...n,[t]:{...n[t],status:"interactive"}})},[]),c=e.useCallback(t=>{S(t.origin)},[S]),a=e.useCallback(t=>{const n=F(t==null?void 0:t.authUrl);if(n&&D(n,window.location.origin)){O(t,"cross-site-legacy");return}z(t)},[z,O]);e.useEffect(()=>{if(!s)return;const t=[s.addListener("*","init",n=>{n!=null&&n.origin&&n.name&&(P.current[n.origin]=n.name,C(n.origin))}),s.addListener("*","authorize",a),s.addListener("*","login",a),s.addListener("*","credential-request",n=>z(n,{v2:!0})),s.addListener("*","authorized",n=>{n!=null&&n.accessToken||i(F(n==null?void 0:n.authUrl))})];return()=>t.forEach(n=>n())},[s,a,z,i,C]),e.useEffect(()=>{const t=n=>{const o=n==null?void 0:n.data;if(!o||o.type!=="authorized"&&o.type!=="authorize-failed")return;const f=F(o.authUrl);if(!(!f||n.origin!==f)){if(o.type==="authorized"&&o.accessToken){T(M=>({...M,[f]:{accessToken:o.accessToken}})),S(f);return}o.type==="authorize-failed"&&l(f)}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[S,l]),e.useEffect(()=>{const t=k.current;Object.values(d).forEach(n=>{n.status==="silent"&&!t[n.origin]&&(t[n.origin]=setTimeout(()=>{delete t[n.origin],l(n.origin)},ee))}),Object.keys(t).forEach(n=>{(!d[n]||d[n].status!=="silent")&&(clearTimeout(t[n]),delete t[n])})},[d,l]),e.useEffect(()=>()=>{b.current&&b.current(),Object.values(k.current).forEach(clearTimeout)},[]);const h=e.useCallback(t=>{b.current&&(b.current(),b.current=null);const n=u||H;b.current=n(t,{onBlocked:()=>{g(o=>o[t.origin]?{...o,[t.origin]:{...o[t.origin],popupBlocked:!0}}:o)},onClosed:()=>{if(t.v2){g(o=>!o[t.origin]||!o[t.origin].silentUrl?o:{...o,[t.origin]:{...o[t.origin],status:"silent"}});return}i(t.origin)}})},[u,i]),m={pending:Object.values(d).filter(t=>t.status==="interactive"),authorize:h,dismiss:c,originEpochs:R,credentials:x,unsupported:I},U=Object.values(d).filter(t=>t.status==="silent"&&t.silentUrl);return e.createElement(Z.Provider,{value:m},r,U.map(t=>e.createElement("iframe",{key:`mm-silent-auth-${t.origin}`,src:t.silentUrl,title:`MachineMetrics silent authorization (${t.origin})`,"aria-hidden":"true",tabIndex:-1,style:{display:"none"}})))};K.propTypes={children:E.node,launcher:E.func};const V=()=>e.useContext(Z),G=r=>{const{originEpochs:u}=e.useContext(Z),s=F(r);return s&&u[s]||0},J=r=>{const{credentials:u}=e.useContext(Z),s=F(r);return s&&u[s]||null},Q=r=>{const{unsupported:u}=e.useContext(Z),s=F(r);return s&&u[s]||null},X=({children:r,authorizationLauncher:u})=>{const[s,d]=e.useState({}),[g,R]=e.useState({}),p=e.useRef({}),x=e.useRef({}),T=e.useRef({}),I=e.useCallback((i,l)=>{var c;return!!((c=T.current[i])!=null&&c.has(l))},[]),w=e.useCallback((i,l,c)=>{d(a=>({...a,[i]:{origin:l,frameRef:c}}))},[]),y=e.useCallback(i=>{d(l=>{const c={...l};return delete c[i],c}),R(l=>{const c={...l};return delete c[i],c}),delete T.current[i]},[]);e.useEffect(()=>{const i=(c=[],a)=>{c.forEach(h=>h(a))},l=c=>{var U,t,n,o,f;if(!((U=c==null?void 0:c.data)!=null&&U.instanceId))return;const{instanceId:a,type:h}=c.data,m=p.current;if(h==="response"){const{callbackId:M,response:$,error:A}=c.data,L=x.current[M];L&&(L($,A),delete x.current[M]);return}if(h==="mark-registered"){const{requestType:M}=c.data;T.current[a]||(T.current[a]=new Set),T.current[a].add(M);return}h==="ready"&&R(M=>({...M,[a]:!0})),i((t=m[a])==null?void 0:t[h],c.data),i((n=m["*"])==null?void 0:n[h],c.data),i((o=m[a])==null?void 0:o["*"],c.data),i((f=m["*"])==null?void 0:f["*"],c.data)};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[s]);const b=e.useCallback((i,l,c)=>{var h,m;const a=s[i];if(!a){console.warn(`Origin not set for id: ${i}. Unable to send message.`);return}(m=(h=a==null?void 0:a.frameRef)==null?void 0:h.current)!=null&&m.contentWindow&&a.frameRef.current.contentWindow.postMessage({type:l,...c,instanceId:i},a.origin)},[s]),k=e.useRef(0),P=e.useCallback(()=>`${Date.now()}-${++k.current}`,[]),C=e.useCallback(async(i,l,c={})=>new Promise((a,h)=>{const m=P(),U=(t,n)=>{delete x.current[m],n?h(n):a(t)};x.current[m]=U,b(i,"request",{callbackId:m,requestType:l,data:c})}),[b]),O=e.useCallback((i,l)=>{b(i,"load-options",l)},[b]),z=e.useCallback((i,l)=>{b(i,"validate",l)},[b]),S=e.useMemo(()=>({registerFrame:w,unregisterFrame:y,sendMessage:b,sendRequest:C,loadOptions:O,validate:z,hasHandler:I,readyFrames:g,addListener:(i,l,c)=>(p.current[i]||(p.current[i]={}),p.current[i][l]||(p.current[i][l]=[]),p.current[i][l].push(c),()=>{p.current[i][l]=p.current[i][l].filter(a=>a!==c)})}),[w,y,b,C,O,z,I,g]);return e.createElement(v.Provider,{value:S},e.createElement(K,{launcher:u},r))},q=(r,u,s)=>{const d=e.useContext(v);if(d===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const g=e.useRef(s);e.useEffect(()=>{g.current=s},[s]),e.useEffect(()=>{if(!(!r||!u)){if(u.startsWith("key:")){const R=u.substring(4);return d.readyFrames[r]&&d.sendMessage(r,"subscribe-key",{keyChord:R}),d.addListener(r,`key-pressed:${R}`,(...x)=>g.current(...x))}return d.addListener(r,u,(...R)=>g.current(...R))}},[d,r,u])};X.propTypes={children:E.node.isRequired,authorizationLauncher:E.func};const B=j.default||j,te=1e4,ne="credentials",_=(r,u)=>`${r}/mm-embedded-interop?id=${u}&origin=${window.location.origin}&caps=${ne}`,re=B.iframe`
|
|
2
2
|
width: 100%;
|
|
3
3
|
height: 100%;
|
|
4
4
|
border: none;
|
|
5
|
-
visibility: ${
|
|
6
|
-
`,
|
|
5
|
+
visibility: ${r=>r.$isReady?"visible":"hidden"};
|
|
6
|
+
`,se=B.div`
|
|
7
7
|
width: 100%;
|
|
8
8
|
height: 100%;
|
|
9
9
|
display: flex;
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
text-align: center;
|
|
17
17
|
color: #555;
|
|
18
18
|
font-size: 14px;
|
|
19
|
-
`,
|
|
19
|
+
`,Y=({entry:r})=>e.createElement(se,null,e.createElement("div",{style:{fontWeight:600}},r&&(r.name||r.origin)||"This app"," can’t be embedded here"),e.createElement("div",{style:{fontSize:12,color:"#888"}},"It needs an update to support embedding from a different domain."));Y.propTypes={entry:E.shape({origin:E.string,name:E.string,reason:E.string})};const oe=B.div`
|
|
20
20
|
height: 100%;
|
|
21
21
|
display: flex;
|
|
22
22
|
flex: 1;
|
|
23
23
|
align-items: center;
|
|
24
24
|
justify-content: center;
|
|
25
|
-
`,
|
|
25
|
+
`,ie=()=>e.createElement(oe,null,e.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),N=({id:r,src:u,path:s,onInit:d=()=>{},onTimeout:g,context:R={},params:p={},renderUnsupported:x,renderTimeout:T,...I})=>{if("isConfiguring"in I)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in R)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in R)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const w=e.useRef(),[y,b]=e.useState(),[k,P]=e.useState(0),[C,O]=e.useState(!1),[z,S]=e.useState(!1),i=G(u),l=J(u),c=Q(u);e.useEffect(()=>{i>0&&P(0)},[i]);const{registerFrame:a,unregisterFrame:h,sendMessage:m}=e.useContext(v),[U,t]=e.useState(),n=e.useRef(),o=e.useRef(g),f=e.useRef(d),M=e.useRef(!1);e.useEffect(()=>{o.current=g},[g]),e.useEffect(()=>{f.current=d},[d]),e.useEffect(()=>{k&&m(r,"set-context",{context:{...R,colorMode:p.colorMode,isFullScreen:p.isFullScreen}})},[R,p.colorMode,p.isFullScreen,r,k]),e.useEffect(()=>{k&&(m(r,"set-params",{params:p}),m(r,"set-configuring",{isConfiguring:p.isConfiguring}))},[p,r,k]),e.useEffect(()=>{s!==void 0&&t((s==null?void 0:s.indexOf("/"))===0?s:`/${s}`)},[s]),e.useEffect(()=>{U===void 0||!k||m(r,"navigate",{path:U})},[U,k,r,m]),e.useEffect(()=>{if(!u||!r||!w)return;const L=new URL(u);return a(r,L.origin,w),f.current(),b(_(L.origin,r)),()=>{h(r)}},[u,r,a,w]),e.useEffect(()=>{if(!(!y||M.current))return n.current=setTimeout(()=>{O(!0),o.current&&o.current()},te),()=>clearTimeout(n.current)},[y]);const $=e.useCallback(()=>{M.current=!0,clearTimeout(n.current),O(!1)},[]);q(r,"init",$),q(r,"authorize",$),q(r,"login",$),q(r,"credential-request",()=>{$(),S(!0)}),e.useEffect(()=>{!z||!l||m(r,"credential",{accessToken:l.accessToken})},[z,l,r,m]),q(r,"ready",()=>{$(),P(L=>L+1)});const A=e.useRef();return q(r,"heartbeat",()=>{A.current&&clearTimeout(A.current),A.current=setTimeout(()=>{if(w.current){const L=new URL(u);w.current.src=_(L.origin,r)}},6e3)}),e.useEffect(()=>()=>{A.current&&clearTimeout(A.current)},[]),c?x?x(c):e.createElement(Y,{entry:c}):C&&!k?T?T():e.createElement(ie,null):e.createElement(re,{key:`auth-epoch-${i}`,$isReady:k,ref:w,src:y,...I})};N.propTypes={id:E.string,src:E.string.isRequired,path:E.string,onInit:E.func,onTimeout:E.func,renderUnsupported:E.func,renderTimeout:E.func};const ue=j.div`
|
|
26
26
|
position: fixed;
|
|
27
27
|
inset: 0;
|
|
28
28
|
background: rgba(0, 0, 0, 0.45);
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
align-items: center;
|
|
31
31
|
justify-content: center;
|
|
32
32
|
z-index: 10000;
|
|
33
|
-
`,
|
|
33
|
+
`,ce=j.div`
|
|
34
34
|
background: #fff;
|
|
35
35
|
border-radius: 8px;
|
|
36
36
|
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
|
|
@@ -39,13 +39,13 @@
|
|
|
39
39
|
max-width: calc(100vw - 32px);
|
|
40
40
|
font-family: sans-serif;
|
|
41
41
|
color: #222;
|
|
42
|
-
`,
|
|
42
|
+
`,le=j.div`
|
|
43
43
|
display: flex;
|
|
44
44
|
align-items: center;
|
|
45
45
|
justify-content: space-between;
|
|
46
46
|
padding: 10px 0;
|
|
47
47
|
gap: 16px;
|
|
48
|
-
`,
|
|
48
|
+
`,ae=j.button`
|
|
49
49
|
background: #16a500;
|
|
50
50
|
color: #fff;
|
|
51
51
|
border: none;
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
font-size: 14px;
|
|
55
55
|
cursor: pointer;
|
|
56
56
|
white-space: nowrap;
|
|
57
|
-
`,
|
|
57
|
+
`,de=j.p`
|
|
58
58
|
color: #b3261e;
|
|
59
59
|
font-size: 13px;
|
|
60
60
|
margin: 4px 0 0;
|
|
61
|
-
`,
|
|
61
|
+
`,fe=()=>{const{pending:r,authorize:u}=V();return r.length===0?null:e.createElement(ue,null,e.createElement(ce,null,e.createElement("h3",{style:{margin:"0 0 8px"}},"Authorization Required"),e.createElement("p",{style:{margin:"0 0 12px",fontSize:14,color:"#555"}},"The following apps need you to sign in and authorize them before they can load."),r.map(s=>e.createElement("div",{key:s.origin},e.createElement(le,null,e.createElement("div",null,e.createElement("div",{style:{fontWeight:600}},s.name||s.origin),s.name&&e.createElement("div",{style:{fontSize:12,color:"#888"}},s.origin)),e.createElement(ae,{onClick:()=>u(s)},"Authorize")),s.popupBlocked&&e.createElement(de,null,"The sign-in window was blocked. Allow popups for this site, then try again.")))))};exports.EmbeddedAuthorizationContext=Z;exports.EmbeddedAuthorizationPrompt=fe;exports.MMEmbeddableZone=N;exports.MMEmbeddableZoneContext=v;exports.MMEmbeddableZoneProvider=X;exports.isCrossSite=D;exports.popupAuthorizationLauncher=H;exports.useEmbeddedAuthorizations=V;exports.useEmbeddedCredential=J;exports.useEmbeddedEffect=q;exports.useEmbeddedOriginEpoch=G;exports.useEmbeddedUnsupported=Q;
|
|
@@ -1,19 +1,7 @@
|
|
|
1
|
-
import f, { createContext as
|
|
2
|
-
import
|
|
1
|
+
import f, { createContext as J, useContext as Z, useState as L, useRef as R, useCallback as b, useEffect as h, useMemo as Y } from "react";
|
|
2
|
+
import x from "prop-types";
|
|
3
3
|
import W from "styled-components";
|
|
4
|
-
const
|
|
5
|
-
let o;
|
|
6
|
-
try {
|
|
7
|
-
if (o = new URL(t).origin, H[o] !== void 0)
|
|
8
|
-
return H[o];
|
|
9
|
-
const a = await (await fetch(`${o}/mm-app-manifest.json`)).json();
|
|
10
|
-
if (!a.version)
|
|
11
|
-
throw new Error("Invalid manifest");
|
|
12
|
-
return H[o] = a, a;
|
|
13
|
-
} catch {
|
|
14
|
-
}
|
|
15
|
-
return o && (H[o] = !1), !1;
|
|
16
|
-
}, ne = async (t) => !!await Y(t), D = X({
|
|
4
|
+
const H = J(null), D = J({
|
|
17
5
|
pending: [],
|
|
18
6
|
authorize: () => {
|
|
19
7
|
},
|
|
@@ -22,196 +10,202 @@ const K = X(null), H = {}, Y = async (t) => {
|
|
|
22
10
|
originEpochs: {},
|
|
23
11
|
credentials: {},
|
|
24
12
|
unsupported: {}
|
|
25
|
-
}),
|
|
13
|
+
}), N = 2e4, A = (n) => {
|
|
26
14
|
try {
|
|
27
|
-
return new URL(
|
|
15
|
+
return new URL(n).origin;
|
|
28
16
|
} catch {
|
|
29
17
|
return null;
|
|
30
18
|
}
|
|
31
|
-
},
|
|
32
|
-
if (!
|
|
33
|
-
return
|
|
34
|
-
const o =
|
|
35
|
-
return o.length <= 2 ?
|
|
36
|
-
},
|
|
19
|
+
}, V = (n) => {
|
|
20
|
+
if (!n || /^\d{1,3}(?:\.\d{1,3}){3}$/.test(n) || n.includes(":"))
|
|
21
|
+
return n;
|
|
22
|
+
const o = n.split(".");
|
|
23
|
+
return o.length <= 2 ? n : o.slice(-2).join(".");
|
|
24
|
+
}, ee = (n, o) => {
|
|
37
25
|
try {
|
|
38
|
-
const
|
|
39
|
-
return
|
|
26
|
+
const r = new URL(n), a = new URL(o);
|
|
27
|
+
return r.protocol !== a.protocol ? !0 : V(r.hostname) !== V(a.hostname);
|
|
40
28
|
} catch {
|
|
41
29
|
return !0;
|
|
42
30
|
}
|
|
43
|
-
},
|
|
31
|
+
}, te = (n, { onBlocked: o, onClosed: r }) => {
|
|
44
32
|
const a = window.open(
|
|
45
|
-
|
|
33
|
+
n.authUrl,
|
|
46
34
|
"mm-embed-auth",
|
|
47
35
|
"popup,width=600,height=700"
|
|
48
36
|
);
|
|
49
37
|
if (!a)
|
|
50
38
|
return o(), () => {
|
|
51
39
|
};
|
|
52
|
-
const
|
|
53
|
-
a.closed && (clearInterval(
|
|
40
|
+
const g = setInterval(() => {
|
|
41
|
+
a.closed && (clearInterval(g), r());
|
|
54
42
|
}, 1e3);
|
|
55
|
-
return () => clearInterval(
|
|
56
|
-
},
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
43
|
+
return () => clearInterval(g);
|
|
44
|
+
}, Q = ({ children: n, launcher: o }) => {
|
|
45
|
+
const r = Z(H), [a, g] = L({}), [T, p] = L({}), [M, C] = L({}), [j, z] = L({}), I = R(M);
|
|
46
|
+
I.current = M;
|
|
47
|
+
const E = R(null), k = R({}), q = R({}), U = b((e) => {
|
|
48
|
+
const t = q.current[e];
|
|
49
|
+
if (!t)
|
|
50
|
+
return;
|
|
51
|
+
const s = (d) => d[e] ? { ...d, [e]: { ...d[e], name: t } } : d;
|
|
52
|
+
g(s), z(s);
|
|
66
53
|
}, []), P = b(
|
|
67
|
-
(e,
|
|
68
|
-
const
|
|
69
|
-
|
|
54
|
+
(e, t) => {
|
|
55
|
+
const s = A(e == null ? void 0 : e.authUrl);
|
|
56
|
+
s && (z((d) => d[s] ? d : {
|
|
70
57
|
...d,
|
|
71
|
-
[
|
|
72
|
-
}),
|
|
58
|
+
[s]: { origin: s, reason: t, name: null }
|
|
59
|
+
}), U(s));
|
|
73
60
|
},
|
|
74
|
-
[
|
|
75
|
-
),
|
|
76
|
-
(e, { v2:
|
|
77
|
-
const
|
|
78
|
-
|
|
61
|
+
[U]
|
|
62
|
+
), O = b(
|
|
63
|
+
(e, { v2: t = !1 } = {}) => {
|
|
64
|
+
const s = A(e == null ? void 0 : e.authUrl);
|
|
65
|
+
s && (t && I.current[s] || (g((d) => d[s] ? d : {
|
|
79
66
|
...d,
|
|
80
|
-
[
|
|
81
|
-
origin:
|
|
67
|
+
[s]: {
|
|
68
|
+
origin: s,
|
|
82
69
|
authUrl: e.authUrl,
|
|
83
70
|
silentUrl: e.silentUrl || null,
|
|
84
71
|
// v2 entries try the invisible silent resolver first; legacy
|
|
85
72
|
// signals go straight to the host's interactive UI.
|
|
86
|
-
status:
|
|
87
|
-
v2:
|
|
73
|
+
status: t && e.silentUrl ? "silent" : "interactive",
|
|
74
|
+
v2: t,
|
|
88
75
|
name: null,
|
|
89
76
|
popupBlocked: !1
|
|
90
77
|
}
|
|
91
|
-
}),
|
|
78
|
+
}), U(s)));
|
|
92
79
|
},
|
|
93
|
-
[
|
|
94
|
-
),
|
|
95
|
-
|
|
96
|
-
if (!
|
|
97
|
-
return
|
|
98
|
-
const
|
|
99
|
-
return delete
|
|
80
|
+
[U]
|
|
81
|
+
), S = b((e) => {
|
|
82
|
+
g((t) => {
|
|
83
|
+
if (!t[e])
|
|
84
|
+
return t;
|
|
85
|
+
const s = { ...t };
|
|
86
|
+
return delete s[e], s;
|
|
100
87
|
});
|
|
101
|
-
}, []),
|
|
88
|
+
}, []), i = b(
|
|
102
89
|
(e) => {
|
|
103
|
-
e && (
|
|
104
|
-
...
|
|
105
|
-
[e]: (
|
|
90
|
+
e && (S(e), p((t) => ({
|
|
91
|
+
...t,
|
|
92
|
+
[e]: (t[e] || 0) + 1
|
|
106
93
|
})));
|
|
107
94
|
},
|
|
108
|
-
[
|
|
109
|
-
),
|
|
110
|
-
|
|
111
|
-
...
|
|
112
|
-
[e]: { ...
|
|
95
|
+
[S]
|
|
96
|
+
), u = b((e) => {
|
|
97
|
+
g((t) => !t[e] || t[e].status === "interactive" ? t : {
|
|
98
|
+
...t,
|
|
99
|
+
[e]: { ...t[e], status: "interactive" }
|
|
113
100
|
});
|
|
114
|
-
}, []),
|
|
101
|
+
}, []), c = b(
|
|
115
102
|
(e) => {
|
|
116
|
-
|
|
103
|
+
S(e.origin);
|
|
117
104
|
},
|
|
118
|
-
[
|
|
119
|
-
),
|
|
105
|
+
[S]
|
|
106
|
+
), l = b(
|
|
120
107
|
(e) => {
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
108
|
+
const t = A(e == null ? void 0 : e.authUrl);
|
|
109
|
+
if (t && ee(t, window.location.origin)) {
|
|
123
110
|
P(e, "cross-site-legacy");
|
|
124
111
|
return;
|
|
125
112
|
}
|
|
126
|
-
|
|
113
|
+
O(e);
|
|
127
114
|
},
|
|
128
|
-
[
|
|
115
|
+
[O, P]
|
|
129
116
|
);
|
|
130
117
|
h(() => {
|
|
131
|
-
if (!
|
|
118
|
+
if (!r)
|
|
132
119
|
return;
|
|
133
120
|
const e = [
|
|
134
|
-
s
|
|
135
|
-
|
|
136
|
-
|
|
121
|
+
// `init` carries the app's display name (v2 apps). Cache it by app origin
|
|
122
|
+
// and enrich any entry already showing for that origin. `init` is posted
|
|
123
|
+
// before the authorize/login/credential-request signals, so the name is
|
|
124
|
+
// usually cached by the time an entry is created.
|
|
125
|
+
r.addListener("*", "init", (t) => {
|
|
126
|
+
t != null && t.origin && t.name && (q.current[t.origin] = t.name, U(t.origin));
|
|
127
|
+
}),
|
|
128
|
+
r.addListener("*", "authorize", l),
|
|
129
|
+
r.addListener("*", "login", l),
|
|
130
|
+
r.addListener(
|
|
137
131
|
"*",
|
|
138
132
|
"credential-request",
|
|
139
|
-
(
|
|
133
|
+
(t) => O(t, { v2: !0 })
|
|
140
134
|
),
|
|
141
|
-
|
|
142
|
-
|
|
135
|
+
r.addListener("*", "authorized", (t) => {
|
|
136
|
+
t != null && t.accessToken || i(A(t == null ? void 0 : t.authUrl));
|
|
143
137
|
})
|
|
144
138
|
];
|
|
145
|
-
return () => e.forEach((
|
|
146
|
-
}, [
|
|
147
|
-
const e = (
|
|
148
|
-
const
|
|
149
|
-
if (!
|
|
139
|
+
return () => e.forEach((t) => t());
|
|
140
|
+
}, [r, l, O, i, U]), h(() => {
|
|
141
|
+
const e = (t) => {
|
|
142
|
+
const s = t == null ? void 0 : t.data;
|
|
143
|
+
if (!s || s.type !== "authorized" && s.type !== "authorize-failed")
|
|
150
144
|
return;
|
|
151
|
-
const d =
|
|
152
|
-
if (!(!d ||
|
|
153
|
-
if (
|
|
154
|
-
|
|
145
|
+
const d = A(s.authUrl);
|
|
146
|
+
if (!(!d || t.origin !== d)) {
|
|
147
|
+
if (s.type === "authorized" && s.accessToken) {
|
|
148
|
+
C((y) => ({
|
|
155
149
|
...y,
|
|
156
|
-
[d]: { accessToken:
|
|
157
|
-
})),
|
|
150
|
+
[d]: { accessToken: s.accessToken }
|
|
151
|
+
})), S(d);
|
|
158
152
|
return;
|
|
159
153
|
}
|
|
160
|
-
|
|
154
|
+
s.type === "authorize-failed" && u(d);
|
|
161
155
|
}
|
|
162
156
|
};
|
|
163
157
|
return window.addEventListener("message", e), () => window.removeEventListener("message", e);
|
|
164
|
-
}, [
|
|
158
|
+
}, [S, u]), h(() => {
|
|
165
159
|
const e = k.current;
|
|
166
|
-
Object.values(a).forEach((
|
|
167
|
-
|
|
168
|
-
delete e[
|
|
169
|
-
},
|
|
170
|
-
}), Object.keys(e).forEach((
|
|
171
|
-
(!a[
|
|
160
|
+
Object.values(a).forEach((t) => {
|
|
161
|
+
t.status === "silent" && !e[t.origin] && (e[t.origin] = setTimeout(() => {
|
|
162
|
+
delete e[t.origin], u(t.origin);
|
|
163
|
+
}, N));
|
|
164
|
+
}), Object.keys(e).forEach((t) => {
|
|
165
|
+
(!a[t] || a[t].status !== "silent") && (clearTimeout(e[t]), delete e[t]);
|
|
172
166
|
});
|
|
173
|
-
}, [a,
|
|
174
|
-
|
|
167
|
+
}, [a, u]), h(() => () => {
|
|
168
|
+
E.current && E.current(), Object.values(k.current).forEach(clearTimeout);
|
|
175
169
|
}, []);
|
|
176
|
-
const
|
|
170
|
+
const w = b(
|
|
177
171
|
(e) => {
|
|
178
|
-
|
|
179
|
-
const
|
|
180
|
-
|
|
172
|
+
E.current && (E.current(), E.current = null);
|
|
173
|
+
const t = o || te;
|
|
174
|
+
E.current = t(e, {
|
|
181
175
|
onBlocked: () => {
|
|
182
|
-
|
|
183
|
-
...
|
|
184
|
-
[e.origin]: { ...
|
|
185
|
-
} :
|
|
176
|
+
g((s) => s[e.origin] ? {
|
|
177
|
+
...s,
|
|
178
|
+
[e.origin]: { ...s[e.origin], popupBlocked: !0 }
|
|
179
|
+
} : s);
|
|
186
180
|
},
|
|
187
181
|
onClosed: () => {
|
|
188
182
|
if (e.v2) {
|
|
189
|
-
|
|
190
|
-
...
|
|
191
|
-
[e.origin]: { ...
|
|
183
|
+
g((s) => !s[e.origin] || !s[e.origin].silentUrl ? s : {
|
|
184
|
+
...s,
|
|
185
|
+
[e.origin]: { ...s[e.origin], status: "silent" }
|
|
192
186
|
});
|
|
193
187
|
return;
|
|
194
188
|
}
|
|
195
|
-
|
|
189
|
+
i(e.origin);
|
|
196
190
|
}
|
|
197
191
|
});
|
|
198
192
|
},
|
|
199
|
-
[o,
|
|
200
|
-
),
|
|
193
|
+
[o, i]
|
|
194
|
+
), m = {
|
|
201
195
|
// Hosts render UI for interactive entries only; silent resolution is
|
|
202
196
|
// invisible by design.
|
|
203
197
|
pending: Object.values(a).filter(
|
|
204
198
|
(e) => e.status === "interactive"
|
|
205
199
|
),
|
|
206
|
-
authorize:
|
|
207
|
-
dismiss:
|
|
208
|
-
originEpochs:
|
|
209
|
-
credentials:
|
|
210
|
-
unsupported:
|
|
211
|
-
},
|
|
200
|
+
authorize: w,
|
|
201
|
+
dismiss: c,
|
|
202
|
+
originEpochs: T,
|
|
203
|
+
credentials: M,
|
|
204
|
+
unsupported: j
|
|
205
|
+
}, F = Object.values(a).filter(
|
|
212
206
|
(e) => e.status === "silent" && e.silentUrl
|
|
213
207
|
);
|
|
214
|
-
return /* @__PURE__ */ f.createElement(D.Provider, { value:
|
|
208
|
+
return /* @__PURE__ */ f.createElement(D.Provider, { value: m }, n, F.map((e) => /* @__PURE__ */ f.createElement(
|
|
215
209
|
"iframe",
|
|
216
210
|
{
|
|
217
211
|
key: `mm-silent-auth-${e.origin}`,
|
|
@@ -223,159 +217,159 @@ const K = X(null), H = {}, Y = async (t) => {
|
|
|
223
217
|
}
|
|
224
218
|
)));
|
|
225
219
|
};
|
|
226
|
-
|
|
227
|
-
children:
|
|
228
|
-
launcher:
|
|
220
|
+
Q.propTypes = {
|
|
221
|
+
children: x.node,
|
|
222
|
+
launcher: x.func
|
|
229
223
|
};
|
|
230
|
-
const
|
|
231
|
-
const { originEpochs: o } = Z(D),
|
|
232
|
-
return
|
|
233
|
-
},
|
|
234
|
-
const { credentials: o } = Z(D),
|
|
235
|
-
return
|
|
236
|
-
},
|
|
237
|
-
const { unsupported: o } = Z(D),
|
|
238
|
-
return
|
|
239
|
-
},
|
|
240
|
-
const [
|
|
224
|
+
const ne = () => Z(D), re = (n) => {
|
|
225
|
+
const { originEpochs: o } = Z(D), r = A(n);
|
|
226
|
+
return r && o[r] || 0;
|
|
227
|
+
}, se = (n) => {
|
|
228
|
+
const { credentials: o } = Z(D), r = A(n);
|
|
229
|
+
return r && o[r] || null;
|
|
230
|
+
}, ie = (n) => {
|
|
231
|
+
const { unsupported: o } = Z(D), r = A(n);
|
|
232
|
+
return r && o[r] || null;
|
|
233
|
+
}, oe = ({ children: n, authorizationLauncher: o }) => {
|
|
234
|
+
const [r, a] = L({}), [g, T] = L({}), p = R({}), M = R({}), C = R({}), j = b((i, u) => {
|
|
241
235
|
var c;
|
|
242
|
-
return !!((c =
|
|
243
|
-
}, []),
|
|
244
|
-
a((
|
|
245
|
-
}, []),
|
|
246
|
-
a((
|
|
247
|
-
const c = { ...
|
|
236
|
+
return !!((c = C.current[i]) != null && c.has(u));
|
|
237
|
+
}, []), z = b((i, u, c) => {
|
|
238
|
+
a((l) => ({ ...l, [i]: { origin: u, frameRef: c } }));
|
|
239
|
+
}, []), I = b((i) => {
|
|
240
|
+
a((u) => {
|
|
241
|
+
const c = { ...u };
|
|
248
242
|
return delete c[i], c;
|
|
249
|
-
}),
|
|
250
|
-
const c = { ...
|
|
243
|
+
}), T((u) => {
|
|
244
|
+
const c = { ...u };
|
|
251
245
|
return delete c[i], c;
|
|
252
|
-
}), delete
|
|
246
|
+
}), delete C.current[i];
|
|
253
247
|
}, []);
|
|
254
248
|
h(() => {
|
|
255
|
-
const i = (c = [],
|
|
256
|
-
c.forEach((w) => w(
|
|
257
|
-
},
|
|
258
|
-
var e,
|
|
259
|
-
if (!((
|
|
249
|
+
const i = (c = [], l) => {
|
|
250
|
+
c.forEach((w) => w(l));
|
|
251
|
+
}, u = (c) => {
|
|
252
|
+
var F, e, t, s, d;
|
|
253
|
+
if (!((F = c == null ? void 0 : c.data) != null && F.instanceId))
|
|
260
254
|
return;
|
|
261
|
-
const { instanceId:
|
|
255
|
+
const { instanceId: l, type: w } = c.data, m = p.current;
|
|
262
256
|
if (w === "response") {
|
|
263
|
-
const { callbackId:
|
|
264
|
-
|
|
257
|
+
const { callbackId: y, response: B, error: v } = c.data, $ = M.current[y];
|
|
258
|
+
$ && ($(B, v), delete M.current[y]);
|
|
265
259
|
return;
|
|
266
260
|
}
|
|
267
261
|
if (w === "mark-registered") {
|
|
268
|
-
const { requestType:
|
|
269
|
-
|
|
262
|
+
const { requestType: y } = c.data;
|
|
263
|
+
C.current[l] || (C.current[l] = /* @__PURE__ */ new Set()), C.current[l].add(y);
|
|
270
264
|
return;
|
|
271
265
|
}
|
|
272
|
-
w === "ready" &&
|
|
266
|
+
w === "ready" && T((y) => ({ ...y, [l]: !0 })), i((e = m[l]) == null ? void 0 : e[w], c.data), i((t = m["*"]) == null ? void 0 : t[w], c.data), i((s = m[l]) == null ? void 0 : s["*"], c.data), i((d = m["*"]) == null ? void 0 : d["*"], c.data);
|
|
273
267
|
};
|
|
274
|
-
return window.addEventListener("message",
|
|
275
|
-
window.removeEventListener("message",
|
|
268
|
+
return window.addEventListener("message", u), () => {
|
|
269
|
+
window.removeEventListener("message", u);
|
|
276
270
|
};
|
|
277
|
-
}, [
|
|
278
|
-
const
|
|
279
|
-
(i,
|
|
280
|
-
var w,
|
|
281
|
-
const
|
|
282
|
-
if (!
|
|
271
|
+
}, [r]);
|
|
272
|
+
const E = b(
|
|
273
|
+
(i, u, c) => {
|
|
274
|
+
var w, m;
|
|
275
|
+
const l = r[i];
|
|
276
|
+
if (!l) {
|
|
283
277
|
console.warn(`Origin not set for id: ${i}. Unable to send message.`);
|
|
284
278
|
return;
|
|
285
279
|
}
|
|
286
|
-
(
|
|
287
|
-
{ type:
|
|
288
|
-
|
|
280
|
+
(m = (w = l == null ? void 0 : l.frameRef) == null ? void 0 : w.current) != null && m.contentWindow && l.frameRef.current.contentWindow.postMessage(
|
|
281
|
+
{ type: u, ...c, instanceId: i },
|
|
282
|
+
l.origin
|
|
289
283
|
);
|
|
290
284
|
},
|
|
291
|
-
[
|
|
292
|
-
), k =
|
|
293
|
-
async (i,
|
|
294
|
-
const
|
|
295
|
-
delete
|
|
285
|
+
[r]
|
|
286
|
+
), k = R(0), q = b(() => `${Date.now()}-${++k.current}`, []), U = b(
|
|
287
|
+
async (i, u, c = {}) => new Promise((l, w) => {
|
|
288
|
+
const m = q(), F = (e, t) => {
|
|
289
|
+
delete M.current[m], t ? w(t) : l(e);
|
|
296
290
|
};
|
|
297
|
-
|
|
291
|
+
M.current[m] = F, E(i, "request", { callbackId: m, requestType: u, data: c });
|
|
298
292
|
}),
|
|
299
|
-
[
|
|
300
|
-
),
|
|
301
|
-
(i,
|
|
302
|
-
|
|
293
|
+
[E]
|
|
294
|
+
), P = b(
|
|
295
|
+
(i, u) => {
|
|
296
|
+
E(i, "load-options", u);
|
|
303
297
|
},
|
|
304
|
-
[
|
|
305
|
-
),
|
|
306
|
-
(i,
|
|
307
|
-
|
|
298
|
+
[E]
|
|
299
|
+
), O = b(
|
|
300
|
+
(i, u) => {
|
|
301
|
+
E(i, "validate", u);
|
|
308
302
|
},
|
|
309
|
-
[
|
|
310
|
-
), S =
|
|
303
|
+
[E]
|
|
304
|
+
), S = Y(
|
|
311
305
|
() => ({
|
|
312
|
-
registerFrame:
|
|
313
|
-
unregisterFrame:
|
|
314
|
-
sendMessage:
|
|
315
|
-
sendRequest:
|
|
316
|
-
loadOptions:
|
|
317
|
-
validate:
|
|
318
|
-
hasHandler:
|
|
319
|
-
readyFrames:
|
|
320
|
-
addListener: (i,
|
|
321
|
-
|
|
306
|
+
registerFrame: z,
|
|
307
|
+
unregisterFrame: I,
|
|
308
|
+
sendMessage: E,
|
|
309
|
+
sendRequest: U,
|
|
310
|
+
loadOptions: P,
|
|
311
|
+
validate: O,
|
|
312
|
+
hasHandler: j,
|
|
313
|
+
readyFrames: g,
|
|
314
|
+
addListener: (i, u, c) => (p.current[i] || (p.current[i] = {}), p.current[i][u] || (p.current[i][u] = []), p.current[i][u].push(c), () => {
|
|
315
|
+
p.current[i][u] = p.current[i][u].filter((l) => l !== c);
|
|
322
316
|
})
|
|
323
317
|
}),
|
|
324
318
|
[
|
|
325
|
-
M,
|
|
326
|
-
$,
|
|
327
|
-
p,
|
|
328
|
-
P,
|
|
329
|
-
F,
|
|
330
319
|
z,
|
|
331
|
-
|
|
332
|
-
|
|
320
|
+
I,
|
|
321
|
+
E,
|
|
322
|
+
U,
|
|
323
|
+
P,
|
|
324
|
+
O,
|
|
325
|
+
j,
|
|
326
|
+
g
|
|
333
327
|
]
|
|
334
328
|
);
|
|
335
|
-
return /* @__PURE__ */ f.createElement(
|
|
336
|
-
}, _ = (
|
|
337
|
-
const a = Z(
|
|
329
|
+
return /* @__PURE__ */ f.createElement(H.Provider, { value: S }, /* @__PURE__ */ f.createElement(Q, { launcher: o }, n));
|
|
330
|
+
}, _ = (n, o, r) => {
|
|
331
|
+
const a = Z(H);
|
|
338
332
|
if (a === null)
|
|
339
333
|
throw new Error(
|
|
340
334
|
"useEmbeddedEffect must be used within a MMEmbeddableZoneProvider"
|
|
341
335
|
);
|
|
342
|
-
const
|
|
336
|
+
const g = R(r);
|
|
343
337
|
h(() => {
|
|
344
|
-
|
|
345
|
-
}, [
|
|
346
|
-
if (!(!
|
|
338
|
+
g.current = r;
|
|
339
|
+
}, [r]), h(() => {
|
|
340
|
+
if (!(!n || !o)) {
|
|
347
341
|
if (o.startsWith("key:")) {
|
|
348
|
-
const
|
|
349
|
-
return a.readyFrames[
|
|
350
|
-
|
|
351
|
-
`key-pressed:${
|
|
352
|
-
(...
|
|
342
|
+
const T = o.substring(4);
|
|
343
|
+
return a.readyFrames[n] && a.sendMessage(n, "subscribe-key", { keyChord: T }), a.addListener(
|
|
344
|
+
n,
|
|
345
|
+
`key-pressed:${T}`,
|
|
346
|
+
(...M) => g.current(...M)
|
|
353
347
|
);
|
|
354
348
|
}
|
|
355
349
|
return a.addListener(
|
|
356
|
-
|
|
350
|
+
n,
|
|
357
351
|
o,
|
|
358
|
-
(...
|
|
352
|
+
(...T) => g.current(...T)
|
|
359
353
|
);
|
|
360
354
|
}
|
|
361
|
-
}, [a,
|
|
355
|
+
}, [a, n, o]);
|
|
362
356
|
};
|
|
363
|
-
|
|
364
|
-
children:
|
|
357
|
+
oe.propTypes = {
|
|
358
|
+
children: x.node.isRequired,
|
|
365
359
|
/**
|
|
366
360
|
* Optional interactive-step launcher for embedded authorizations,
|
|
367
361
|
* `(entry, { onBlocked, onClosed }) => cleanup`. Defaults to a top-level
|
|
368
362
|
* popup. Hosts that cannot open windows (Android WebView shells) drive
|
|
369
363
|
* their own UI from useEmbeddedAuthorizations() instead.
|
|
370
364
|
*/
|
|
371
|
-
authorizationLauncher:
|
|
365
|
+
authorizationLauncher: x.func
|
|
372
366
|
};
|
|
373
|
-
const
|
|
367
|
+
const K = W.default || W, ce = 1e4, ue = "credentials", G = (n, o) => `${n}/mm-embedded-interop?id=${o}&origin=${window.location.origin}&caps=${ue}`, le = K.iframe`
|
|
374
368
|
width: 100%;
|
|
375
369
|
height: 100%;
|
|
376
370
|
border: none;
|
|
377
|
-
visibility: ${(
|
|
378
|
-
`,
|
|
371
|
+
visibility: ${(n) => n.$isReady ? "visible" : "hidden"};
|
|
372
|
+
`, ae = K.div`
|
|
379
373
|
width: 100%;
|
|
380
374
|
height: 100%;
|
|
381
375
|
display: flex;
|
|
@@ -388,140 +382,135 @@ const G = W.default || W, de = 1e4, fe = "credentials", V = (t, o) => `${t}/mm-e
|
|
|
388
382
|
text-align: center;
|
|
389
383
|
color: #555;
|
|
390
384
|
font-size: 14px;
|
|
391
|
-
`,
|
|
392
|
-
|
|
393
|
-
entry:
|
|
394
|
-
origin:
|
|
395
|
-
name:
|
|
396
|
-
reason:
|
|
385
|
+
`, X = ({ entry: n }) => /* @__PURE__ */ f.createElement(ae, null, /* @__PURE__ */ f.createElement("div", { style: { fontWeight: 600 } }, n && (n.name || n.origin) || "This app", " can’t be embedded here"), /* @__PURE__ */ f.createElement("div", { style: { fontSize: 12, color: "#888" } }, "It needs an update to support embedding from a different domain."));
|
|
386
|
+
X.propTypes = {
|
|
387
|
+
entry: x.shape({
|
|
388
|
+
origin: x.string,
|
|
389
|
+
name: x.string,
|
|
390
|
+
reason: x.string
|
|
397
391
|
})
|
|
398
392
|
};
|
|
399
|
-
const
|
|
393
|
+
const de = K.div`
|
|
400
394
|
height: 100%;
|
|
401
395
|
display: flex;
|
|
402
396
|
flex: 1;
|
|
403
397
|
align-items: center;
|
|
404
398
|
justify-content: center;
|
|
405
|
-
`,
|
|
406
|
-
id:
|
|
399
|
+
`, fe = () => /* @__PURE__ */ f.createElement(de, null, /* @__PURE__ */ f.createElement("div", { style: { textAlign: "center" } }, "This app couldn’t be loaded as an embeddable widget.")), me = ({
|
|
400
|
+
id: n,
|
|
407
401
|
src: o,
|
|
408
|
-
path:
|
|
402
|
+
path: r,
|
|
409
403
|
onInit: a = () => {
|
|
410
404
|
},
|
|
411
|
-
onTimeout:
|
|
412
|
-
context:
|
|
413
|
-
params:
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
...
|
|
405
|
+
onTimeout: g,
|
|
406
|
+
context: T = {},
|
|
407
|
+
params: p = {},
|
|
408
|
+
renderUnsupported: M,
|
|
409
|
+
renderTimeout: C,
|
|
410
|
+
...j
|
|
417
411
|
}) => {
|
|
418
|
-
if ("isConfiguring" in
|
|
412
|
+
if ("isConfiguring" in j)
|
|
419
413
|
return console.error(
|
|
420
414
|
"isConfiguring must be passed via the params prop to MMEmbeddableZone"
|
|
421
415
|
), null;
|
|
422
|
-
if ("colorMode" in
|
|
416
|
+
if ("colorMode" in T)
|
|
423
417
|
return console.error(
|
|
424
418
|
"colorMode must be passed via the params prop to MMEmbeddableZone"
|
|
425
419
|
), null;
|
|
426
|
-
if ("isFullScreen" in
|
|
420
|
+
if ("isFullScreen" in T)
|
|
427
421
|
return console.error(
|
|
428
422
|
"isFullScreen must be passed via the params prop to MMEmbeddableZone"
|
|
429
423
|
), null;
|
|
430
|
-
const
|
|
424
|
+
const z = R(), [I, E] = L(), [k, q] = L(0), [U, P] = L(!1), [O, S] = L(!1), i = re(o), u = se(o), c = ie(o);
|
|
431
425
|
h(() => {
|
|
432
|
-
|
|
433
|
-
}, [
|
|
434
|
-
const { registerFrame: l, unregisterFrame:
|
|
435
|
-
|
|
436
|
-
), [
|
|
426
|
+
i > 0 && q(0);
|
|
427
|
+
}, [i]);
|
|
428
|
+
const { registerFrame: l, unregisterFrame: w, sendMessage: m } = Z(
|
|
429
|
+
H
|
|
430
|
+
), [F, e] = L(), t = R(), s = R(g), d = R(a), y = R(!1);
|
|
437
431
|
h(() => {
|
|
438
|
-
|
|
439
|
-
}, [
|
|
440
|
-
|
|
432
|
+
s.current = g;
|
|
433
|
+
}, [g]), h(() => {
|
|
434
|
+
d.current = a;
|
|
441
435
|
}, [a]), h(() => {
|
|
442
|
-
k &&
|
|
436
|
+
k && m(n, "set-context", {
|
|
443
437
|
context: {
|
|
444
|
-
...
|
|
438
|
+
...T,
|
|
445
439
|
// TODO: Remove this once everything is migrated to params
|
|
446
|
-
colorMode:
|
|
447
|
-
isFullScreen:
|
|
440
|
+
colorMode: p.colorMode,
|
|
441
|
+
isFullScreen: p.isFullScreen
|
|
448
442
|
}
|
|
449
443
|
});
|
|
450
|
-
}, [
|
|
451
|
-
k && (
|
|
452
|
-
}, [
|
|
453
|
-
|
|
454
|
-
}, [
|
|
455
|
-
|
|
456
|
-
}, [
|
|
457
|
-
if (!
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
}, [o, t, l, M, E]), h(() => {
|
|
474
|
-
if (!(!E || !$ || A.current))
|
|
475
|
-
return r.current = setTimeout(() => {
|
|
476
|
-
d.current && d.current();
|
|
477
|
-
}, de), () => clearTimeout(r.current);
|
|
478
|
-
}, [$, E]);
|
|
479
|
-
const v = b(() => {
|
|
480
|
-
A.current = !0, clearTimeout(r.current);
|
|
444
|
+
}, [T, p.colorMode, p.isFullScreen, n, k]), h(() => {
|
|
445
|
+
k && (m(n, "set-params", { params: p }), m(n, "set-configuring", { isConfiguring: p.isConfiguring }));
|
|
446
|
+
}, [p, n, k]), h(() => {
|
|
447
|
+
r !== void 0 && e((r == null ? void 0 : r.indexOf("/")) === 0 ? r : `/${r}`);
|
|
448
|
+
}, [r]), h(() => {
|
|
449
|
+
F === void 0 || !k || m(n, "navigate", { path: F });
|
|
450
|
+
}, [F, k, n, m]), h(() => {
|
|
451
|
+
if (!o || !n || !z)
|
|
452
|
+
return;
|
|
453
|
+
const $ = new URL(o);
|
|
454
|
+
return l(n, $.origin, z), d.current(), E(G($.origin, n)), () => {
|
|
455
|
+
w(n);
|
|
456
|
+
};
|
|
457
|
+
}, [o, n, l, z]), h(() => {
|
|
458
|
+
if (!(!I || y.current))
|
|
459
|
+
return t.current = setTimeout(() => {
|
|
460
|
+
P(!0), s.current && s.current();
|
|
461
|
+
}, ce), () => clearTimeout(t.current);
|
|
462
|
+
}, [I]);
|
|
463
|
+
const B = b(() => {
|
|
464
|
+
y.current = !0, clearTimeout(t.current), P(!1);
|
|
481
465
|
}, []);
|
|
482
|
-
_(
|
|
483
|
-
|
|
466
|
+
_(n, "init", B), _(n, "authorize", B), _(n, "login", B), _(n, "credential-request", () => {
|
|
467
|
+
B(), S(!0);
|
|
484
468
|
}), h(() => {
|
|
485
|
-
!
|
|
486
|
-
}, [
|
|
487
|
-
|
|
469
|
+
!O || !u || m(n, "credential", { accessToken: u.accessToken });
|
|
470
|
+
}, [O, u, n, m]), _(n, "ready", () => {
|
|
471
|
+
B(), q(($) => $ + 1);
|
|
488
472
|
});
|
|
489
|
-
const
|
|
490
|
-
return _(
|
|
491
|
-
|
|
492
|
-
if (
|
|
493
|
-
const
|
|
494
|
-
|
|
473
|
+
const v = R();
|
|
474
|
+
return _(n, "heartbeat", () => {
|
|
475
|
+
v.current && clearTimeout(v.current), v.current = setTimeout(() => {
|
|
476
|
+
if (z.current) {
|
|
477
|
+
const $ = new URL(o);
|
|
478
|
+
z.current.src = G($.origin, n);
|
|
495
479
|
}
|
|
496
480
|
}, 6e3);
|
|
497
481
|
}), h(() => () => {
|
|
498
|
-
|
|
499
|
-
}, []),
|
|
500
|
-
|
|
482
|
+
v.current && clearTimeout(v.current);
|
|
483
|
+
}, []), c ? M ? M(c) : /* @__PURE__ */ f.createElement(X, { entry: c }) : U && !k ? C ? C() : /* @__PURE__ */ f.createElement(fe, null) : /* @__PURE__ */ f.createElement(
|
|
484
|
+
le,
|
|
501
485
|
{
|
|
502
|
-
key: `auth-epoch-${
|
|
486
|
+
key: `auth-epoch-${i}`,
|
|
503
487
|
$isReady: k,
|
|
504
|
-
ref:
|
|
505
|
-
src:
|
|
506
|
-
...
|
|
488
|
+
ref: z,
|
|
489
|
+
src: I,
|
|
490
|
+
...j
|
|
507
491
|
}
|
|
508
492
|
);
|
|
509
493
|
};
|
|
510
|
-
|
|
511
|
-
id:
|
|
512
|
-
src:
|
|
513
|
-
path:
|
|
514
|
-
onInit:
|
|
515
|
-
onTimeout:
|
|
516
|
-
skipManifestCheck: R.bool,
|
|
494
|
+
me.propTypes = {
|
|
495
|
+
id: x.string,
|
|
496
|
+
src: x.string.isRequired,
|
|
497
|
+
path: x.string,
|
|
498
|
+
onInit: x.func,
|
|
499
|
+
onTimeout: x.func,
|
|
517
500
|
/**
|
|
518
501
|
* Optional host-styled renderer for the structurally-unsupported embed
|
|
519
502
|
* state (legacy app on a cross-site origin), `(entry) => ReactNode`. Falls
|
|
520
503
|
* back to a minimal built-in placeholder.
|
|
521
504
|
*/
|
|
522
|
-
renderUnsupported:
|
|
505
|
+
renderUnsupported: x.func,
|
|
506
|
+
/**
|
|
507
|
+
* Optional host-styled renderer for the handshake-timeout failure state
|
|
508
|
+
* (the app is not embeddable / could not load), `() => ReactNode`. Falls
|
|
509
|
+
* back to a minimal centered message.
|
|
510
|
+
*/
|
|
511
|
+
renderTimeout: x.func
|
|
523
512
|
};
|
|
524
|
-
const
|
|
513
|
+
const ge = W.div`
|
|
525
514
|
position: fixed;
|
|
526
515
|
inset: 0;
|
|
527
516
|
background: rgba(0, 0, 0, 0.45);
|
|
@@ -529,7 +518,7 @@ const be = W.div`
|
|
|
529
518
|
align-items: center;
|
|
530
519
|
justify-content: center;
|
|
531
520
|
z-index: 10000;
|
|
532
|
-
`,
|
|
521
|
+
`, pe = W.div`
|
|
533
522
|
background: #fff;
|
|
534
523
|
border-radius: 8px;
|
|
535
524
|
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
|
|
@@ -538,13 +527,13 @@ const be = W.div`
|
|
|
538
527
|
max-width: calc(100vw - 32px);
|
|
539
528
|
font-family: sans-serif;
|
|
540
529
|
color: #222;
|
|
541
|
-
`,
|
|
530
|
+
`, he = W.div`
|
|
542
531
|
display: flex;
|
|
543
532
|
align-items: center;
|
|
544
533
|
justify-content: space-between;
|
|
545
534
|
padding: 10px 0;
|
|
546
535
|
gap: 16px;
|
|
547
|
-
`,
|
|
536
|
+
`, be = W.button`
|
|
548
537
|
background: #16a500;
|
|
549
538
|
color: #fff;
|
|
550
539
|
border: none;
|
|
@@ -553,27 +542,25 @@ const be = W.div`
|
|
|
553
542
|
font-size: 14px;
|
|
554
543
|
cursor: pointer;
|
|
555
544
|
white-space: nowrap;
|
|
556
|
-
`,
|
|
545
|
+
`, Ee = W.p`
|
|
557
546
|
color: #b3261e;
|
|
558
547
|
font-size: 13px;
|
|
559
548
|
margin: 4px 0 0;
|
|
560
|
-
`,
|
|
561
|
-
const { pending:
|
|
562
|
-
return
|
|
549
|
+
`, Te = () => {
|
|
550
|
+
const { pending: n, authorize: o } = ne();
|
|
551
|
+
return n.length === 0 ? null : /* @__PURE__ */ f.createElement(ge, null, /* @__PURE__ */ f.createElement(pe, null, /* @__PURE__ */ f.createElement("h3", { style: { margin: "0 0 8px" } }, "Authorization Required"), /* @__PURE__ */ f.createElement("p", { style: { margin: "0 0 12px", fontSize: 14, color: "#555" } }, "The following apps need you to sign in and authorize them before they can load."), n.map((r) => /* @__PURE__ */ f.createElement("div", { key: r.origin }, /* @__PURE__ */ f.createElement(he, null, /* @__PURE__ */ f.createElement("div", null, /* @__PURE__ */ f.createElement("div", { style: { fontWeight: 600 } }, r.name || r.origin), r.name && /* @__PURE__ */ f.createElement("div", { style: { fontSize: 12, color: "#888" } }, r.origin)), /* @__PURE__ */ f.createElement(be, { onClick: () => o(r) }, "Authorize")), r.popupBlocked && /* @__PURE__ */ f.createElement(Ee, null, "The sign-in window was blocked. Allow popups for this site, then try again.")))));
|
|
563
552
|
};
|
|
564
553
|
export {
|
|
565
554
|
D as EmbeddedAuthorizationContext,
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
ie as useEmbeddedAuthorizations,
|
|
575
|
-
ue as useEmbeddedCredential,
|
|
555
|
+
Te as EmbeddedAuthorizationPrompt,
|
|
556
|
+
me as MMEmbeddableZone,
|
|
557
|
+
H as MMEmbeddableZoneContext,
|
|
558
|
+
oe as MMEmbeddableZoneProvider,
|
|
559
|
+
ee as isCrossSite,
|
|
560
|
+
te as popupAuthorizationLauncher,
|
|
561
|
+
ne as useEmbeddedAuthorizations,
|
|
562
|
+
se as useEmbeddedCredential,
|
|
576
563
|
_ as useEmbeddedEffect,
|
|
577
|
-
|
|
578
|
-
|
|
564
|
+
re as useEmbeddedOriginEpoch,
|
|
565
|
+
ie as useEmbeddedUnsupported
|
|
579
566
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(g,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("react"),require("prop-types"),require("styled-components")):typeof define=="function"&&define.amd?define(["exports","react","prop-types","styled-components"],e):(g=typeof globalThis!="undefined"?globalThis:g||self,e(g["mm-react-embeddable"]={},g.React,g.PropTypes,g.styled))})(this,(function(g,e,k,j){"use strict";const _=e.createContext(null),W=e.createContext({pending:[],authorize:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{}}),ne=2e4,A=r=>{try{return new URL(r).origin}catch{return null}},H=r=>{if(!r||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(r)||r.includes(":"))return r;const u=r.split(".");return u.length<=2?r:u.slice(-2).join(".")},P=(r,u)=>{try{const s=new URL(r),f=new URL(u);return s.protocol!==f.protocol?!0:H(s.hostname)!==H(f.hostname)}catch{return!0}},K=(r,{onBlocked:u,onClosed:s})=>{const f=window.open(r.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!f)return u(),()=>{};const b=setInterval(()=>{f.closed&&(clearInterval(b),s())},1e3);return()=>clearInterval(b)},V=({children:r,launcher:u})=>{const s=e.useContext(_),[f,b]=e.useState({}),[w,h]=e.useState({}),[C,U]=e.useState({}),[Z,M]=e.useState({}),F=e.useRef(C);F.current=C;const E=e.useRef(null),x=e.useRef({}),$=e.useRef({}),z=e.useCallback(n=>{const t=$.current[n];if(!t)return;const i=a=>a[n]?{...a,[n]:{...a[n],name:t}}:a;b(i),M(i)},[]),y=e.useCallback((n,t)=>{const i=A(n==null?void 0:n.authUrl);i&&(M(a=>a[i]?a:{...a,[i]:{origin:i,reason:t,name:null}}),z(i))},[z]),T=e.useCallback((n,{v2:t=!1}={})=>{const i=A(n==null?void 0:n.authUrl);i&&(t&&F.current[i]||(b(a=>a[i]?a:{...a,[i]:{origin:i,authUrl:n.authUrl,silentUrl:n.silentUrl||null,status:t&&n.silentUrl?"silent":"interactive",v2:t,name:null,popupBlocked:!1}}),z(i)))},[z]),L=e.useCallback(n=>{b(t=>{if(!t[n])return t;const i={...t};return delete i[n],i})},[]),o=e.useCallback(n=>{n&&(L(n),h(t=>({...t,[n]:(t[n]||0)+1})))},[L]),l=e.useCallback(n=>{b(t=>!t[n]||t[n].status==="interactive"?t:{...t,[n]:{...t[n],status:"interactive"}})},[]),c=e.useCallback(n=>{L(n.origin)},[L]),d=e.useCallback(n=>{const t=A(n==null?void 0:n.authUrl);if(t&&P(t,window.location.origin)){y(n,"cross-site-legacy");return}T(n)},[T,y]);e.useEffect(()=>{if(!s)return;const n=[s.addListener("*","init",t=>{t!=null&&t.origin&&t.name&&($.current[t.origin]=t.name,z(t.origin))}),s.addListener("*","authorize",d),s.addListener("*","login",d),s.addListener("*","credential-request",t=>T(t,{v2:!0})),s.addListener("*","authorized",t=>{t!=null&&t.accessToken||o(A(t==null?void 0:t.authUrl))})];return()=>n.forEach(t=>t())},[s,d,T,o,z]),e.useEffect(()=>{const n=t=>{const i=t==null?void 0:t.data;if(!i||i.type!=="authorized"&&i.type!=="authorize-failed")return;const a=A(i.authUrl);if(!(!a||t.origin!==a)){if(i.type==="authorized"&&i.accessToken){U(S=>({...S,[a]:{accessToken:i.accessToken}})),L(a);return}i.type==="authorize-failed"&&l(a)}};return window.addEventListener("message",n),()=>window.removeEventListener("message",n)},[L,l]),e.useEffect(()=>{const n=x.current;Object.values(f).forEach(t=>{t.status==="silent"&&!n[t.origin]&&(n[t.origin]=setTimeout(()=>{delete n[t.origin],l(t.origin)},ne))}),Object.keys(n).forEach(t=>{(!f[t]||f[t].status!=="silent")&&(clearTimeout(n[t]),delete n[t])})},[f,l]),e.useEffect(()=>()=>{E.current&&E.current(),Object.values(x.current).forEach(clearTimeout)},[]);const p=e.useCallback(n=>{E.current&&(E.current(),E.current=null);const t=u||K;E.current=t(n,{onBlocked:()=>{b(i=>i[n.origin]?{...i,[n.origin]:{...i[n.origin],popupBlocked:!0}}:i)},onClosed:()=>{if(n.v2){b(i=>!i[n.origin]||!i[n.origin].silentUrl?i:{...i,[n.origin]:{...i[n.origin],status:"silent"}});return}o(n.origin)}})},[u,o]),m={pending:Object.values(f).filter(n=>n.status==="interactive"),authorize:p,dismiss:c,originEpochs:w,credentials:C,unsupported:Z},O=Object.values(f).filter(n=>n.status==="silent"&&n.silentUrl);return e.createElement(W.Provider,{value:m},r,O.map(n=>e.createElement("iframe",{key:`mm-silent-auth-${n.origin}`,src:n.silentUrl,title:`MachineMetrics silent authorization (${n.origin})`,"aria-hidden":"true",tabIndex:-1,style:{display:"none"}})))};V.propTypes={children:k.node,launcher:k.func};const G=()=>e.useContext(W),J=r=>{const{originEpochs:u}=e.useContext(W),s=A(r);return s&&u[s]||0},Q=r=>{const{credentials:u}=e.useContext(W),s=A(r);return s&&u[s]||null},X=r=>{const{unsupported:u}=e.useContext(W),s=A(r);return s&&u[s]||null},Y=({children:r,authorizationLauncher:u})=>{const[s,f]=e.useState({}),[b,w]=e.useState({}),h=e.useRef({}),C=e.useRef({}),U=e.useRef({}),Z=e.useCallback((o,l)=>{var c;return!!((c=U.current[o])!=null&&c.has(l))},[]),M=e.useCallback((o,l,c)=>{f(d=>({...d,[o]:{origin:l,frameRef:c}}))},[]),F=e.useCallback(o=>{f(l=>{const c={...l};return delete c[o],c}),w(l=>{const c={...l};return delete c[o],c}),delete U.current[o]},[]);e.useEffect(()=>{const o=(c=[],d)=>{c.forEach(p=>p(d))},l=c=>{var O,n,t,i,a;if(!((O=c==null?void 0:c.data)!=null&&O.instanceId))return;const{instanceId:d,type:p}=c.data,m=h.current;if(p==="response"){const{callbackId:S,response:v,error:B}=c.data,I=C.current[S];I&&(I(v,B),delete C.current[S]);return}if(p==="mark-registered"){const{requestType:S}=c.data;U.current[d]||(U.current[d]=new Set),U.current[d].add(S);return}p==="ready"&&w(S=>({...S,[d]:!0})),o((n=m[d])==null?void 0:n[p],c.data),o((t=m["*"])==null?void 0:t[p],c.data),o((i=m[d])==null?void 0:i["*"],c.data),o((a=m["*"])==null?void 0:a["*"],c.data)};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[s]);const E=e.useCallback((o,l,c)=>{var p,m;const d=s[o];if(!d){console.warn(`Origin not set for id: ${o}. Unable to send message.`);return}(m=(p=d==null?void 0:d.frameRef)==null?void 0:p.current)!=null&&m.contentWindow&&d.frameRef.current.contentWindow.postMessage({type:l,...c,instanceId:o},d.origin)},[s]),x=e.useRef(0),$=e.useCallback(()=>`${Date.now()}-${++x.current}`,[]),z=e.useCallback(async(o,l,c={})=>new Promise((d,p)=>{const m=$(),O=(n,t)=>{delete C.current[m],t?p(t):d(n)};C.current[m]=O,E(o,"request",{callbackId:m,requestType:l,data:c})}),[E]),y=e.useCallback((o,l)=>{E(o,"load-options",l)},[E]),T=e.useCallback((o,l)=>{E(o,"validate",l)},[E]),L=e.useMemo(()=>({registerFrame:M,unregisterFrame:F,sendMessage:E,sendRequest:z,loadOptions:y,validate:T,hasHandler:Z,readyFrames:b,addListener:(o,l,c)=>(h.current[o]||(h.current[o]={}),h.current[o][l]||(h.current[o][l]=[]),h.current[o][l].push(c),()=>{h.current[o][l]=h.current[o][l].filter(d=>d!==c)})}),[M,F,E,z,y,T,Z,b]);return e.createElement(_.Provider,{value:L},e.createElement(V,{launcher:u},r))},q=(r,u,s)=>{const f=e.useContext(_);if(f===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const b=e.useRef(s);e.useEffect(()=>{b.current=s},[s]),e.useEffect(()=>{if(!(!r||!u)){if(u.startsWith("key:")){const w=u.substring(4);return f.readyFrames[r]&&f.sendMessage(r,"subscribe-key",{keyChord:w}),f.addListener(r,`key-pressed:${w}`,(...C)=>b.current(...C))}return f.addListener(r,u,(...w)=>b.current(...w))}},[f,r,u])};Y.propTypes={children:k.node.isRequired,authorizationLauncher:k.func};const D=j.default||j,te=1e4,re="credentials",N=(r,u)=>`${r}/mm-embedded-interop?id=${u}&origin=${window.location.origin}&caps=${re}`,se=D.iframe`
|
|
2
2
|
width: 100%;
|
|
3
3
|
height: 100%;
|
|
4
4
|
border: none;
|
|
5
|
-
visibility: ${
|
|
6
|
-
`,
|
|
5
|
+
visibility: ${r=>r.$isReady?"visible":"hidden"};
|
|
6
|
+
`,ie=D.div`
|
|
7
7
|
width: 100%;
|
|
8
8
|
height: 100%;
|
|
9
9
|
display: flex;
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
text-align: center;
|
|
17
17
|
color: #555;
|
|
18
18
|
font-size: 14px;
|
|
19
|
-
`,
|
|
19
|
+
`,R=({entry:r})=>e.createElement(ie,null,e.createElement("div",{style:{fontWeight:600}},r&&(r.name||r.origin)||"This app"," can’t be embedded here"),e.createElement("div",{style:{fontSize:12,color:"#888"}},"It needs an update to support embedding from a different domain."));R.propTypes={entry:k.shape({origin:k.string,name:k.string,reason:k.string})};const oe=D.div`
|
|
20
20
|
height: 100%;
|
|
21
21
|
display: flex;
|
|
22
22
|
flex: 1;
|
|
23
23
|
align-items: center;
|
|
24
24
|
justify-content: center;
|
|
25
|
-
`,
|
|
25
|
+
`,ue=()=>e.createElement(oe,null,e.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),ee=({id:r,src:u,path:s,onInit:f=()=>{},onTimeout:b,context:w={},params:h={},renderUnsupported:C,renderTimeout:U,...Z})=>{if("isConfiguring"in Z)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in w)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in w)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const M=e.useRef(),[F,E]=e.useState(),[x,$]=e.useState(0),[z,y]=e.useState(!1),[T,L]=e.useState(!1),o=J(u),l=Q(u),c=X(u);e.useEffect(()=>{o>0&&$(0)},[o]);const{registerFrame:d,unregisterFrame:p,sendMessage:m}=e.useContext(_),[O,n]=e.useState(),t=e.useRef(),i=e.useRef(b),a=e.useRef(f),S=e.useRef(!1);e.useEffect(()=>{i.current=b},[b]),e.useEffect(()=>{a.current=f},[f]),e.useEffect(()=>{x&&m(r,"set-context",{context:{...w,colorMode:h.colorMode,isFullScreen:h.isFullScreen}})},[w,h.colorMode,h.isFullScreen,r,x]),e.useEffect(()=>{x&&(m(r,"set-params",{params:h}),m(r,"set-configuring",{isConfiguring:h.isConfiguring}))},[h,r,x]),e.useEffect(()=>{s!==void 0&&n((s==null?void 0:s.indexOf("/"))===0?s:`/${s}`)},[s]),e.useEffect(()=>{O===void 0||!x||m(r,"navigate",{path:O})},[O,x,r,m]),e.useEffect(()=>{if(!u||!r||!M)return;const I=new URL(u);return d(r,I.origin,M),a.current(),E(N(I.origin,r)),()=>{p(r)}},[u,r,d,M]),e.useEffect(()=>{if(!(!F||S.current))return t.current=setTimeout(()=>{y(!0),i.current&&i.current()},te),()=>clearTimeout(t.current)},[F]);const v=e.useCallback(()=>{S.current=!0,clearTimeout(t.current),y(!1)},[]);q(r,"init",v),q(r,"authorize",v),q(r,"login",v),q(r,"credential-request",()=>{v(),L(!0)}),e.useEffect(()=>{!T||!l||m(r,"credential",{accessToken:l.accessToken})},[T,l,r,m]),q(r,"ready",()=>{v(),$(I=>I+1)});const B=e.useRef();return q(r,"heartbeat",()=>{B.current&&clearTimeout(B.current),B.current=setTimeout(()=>{if(M.current){const I=new URL(u);M.current.src=N(I.origin,r)}},6e3)}),e.useEffect(()=>()=>{B.current&&clearTimeout(B.current)},[]),c?C?C(c):e.createElement(R,{entry:c}):z&&!x?U?U():e.createElement(ue,null):e.createElement(se,{key:`auth-epoch-${o}`,$isReady:x,ref:M,src:F,...Z})};ee.propTypes={id:k.string,src:k.string.isRequired,path:k.string,onInit:k.func,onTimeout:k.func,renderUnsupported:k.func,renderTimeout:k.func};const ce=j.div`
|
|
26
26
|
position: fixed;
|
|
27
27
|
inset: 0;
|
|
28
28
|
background: rgba(0, 0, 0, 0.45);
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
align-items: center;
|
|
31
31
|
justify-content: center;
|
|
32
32
|
z-index: 10000;
|
|
33
|
-
`,
|
|
33
|
+
`,le=j.div`
|
|
34
34
|
background: #fff;
|
|
35
35
|
border-radius: 8px;
|
|
36
36
|
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
|
|
@@ -39,13 +39,13 @@
|
|
|
39
39
|
max-width: calc(100vw - 32px);
|
|
40
40
|
font-family: sans-serif;
|
|
41
41
|
color: #222;
|
|
42
|
-
`,
|
|
42
|
+
`,de=j.div`
|
|
43
43
|
display: flex;
|
|
44
44
|
align-items: center;
|
|
45
45
|
justify-content: space-between;
|
|
46
46
|
padding: 10px 0;
|
|
47
47
|
gap: 16px;
|
|
48
|
-
`,
|
|
48
|
+
`,fe=j.button`
|
|
49
49
|
background: #16a500;
|
|
50
50
|
color: #fff;
|
|
51
51
|
border: none;
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
font-size: 14px;
|
|
55
55
|
cursor: pointer;
|
|
56
56
|
white-space: nowrap;
|
|
57
|
-
`,
|
|
57
|
+
`,ae=j.p`
|
|
58
58
|
color: #b3261e;
|
|
59
59
|
font-size: 13px;
|
|
60
60
|
margin: 4px 0 0;
|
|
61
|
-
`,
|
|
61
|
+
`,me=()=>{const{pending:r,authorize:u}=G();return r.length===0?null:e.createElement(ce,null,e.createElement(le,null,e.createElement("h3",{style:{margin:"0 0 8px"}},"Authorization Required"),e.createElement("p",{style:{margin:"0 0 12px",fontSize:14,color:"#555"}},"The following apps need you to sign in and authorize them before they can load."),r.map(s=>e.createElement("div",{key:s.origin},e.createElement(de,null,e.createElement("div",null,e.createElement("div",{style:{fontWeight:600}},s.name||s.origin),s.name&&e.createElement("div",{style:{fontSize:12,color:"#888"}},s.origin)),e.createElement(fe,{onClick:()=>u(s)},"Authorize")),s.popupBlocked&&e.createElement(ae,null,"The sign-in window was blocked. Allow popups for this site, then try again.")))))};g.EmbeddedAuthorizationContext=W,g.EmbeddedAuthorizationPrompt=me,g.MMEmbeddableZone=ee,g.MMEmbeddableZoneContext=_,g.MMEmbeddableZoneProvider=Y,g.isCrossSite=P,g.popupAuthorizationLauncher=K,g.useEmbeddedAuthorizations=G,g.useEmbeddedCredential=Q,g.useEmbeddedEffect=q,g.useEmbeddedOriginEpoch=J,g.useEmbeddedUnsupported=X,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
|