@akinon/app-client 0.2.0 → 0.3.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/app-client-provider.d.ts +6 -0
- package/dist/app-client-provider.d.ts.map +1 -1
- package/dist/index.cjs +1 -7
- package/dist/index.js +388 -186
- package/package.json +3 -2
|
@@ -3,6 +3,12 @@ import React from 'react';
|
|
|
3
3
|
interface AppClientContextState {
|
|
4
4
|
data?: ApplicationData;
|
|
5
5
|
isLoading: boolean;
|
|
6
|
+
invokeAction: <T = any>(actionKey: string, ...args: any[]) => Promise<T>;
|
|
7
|
+
navigate: (path: string) => void;
|
|
8
|
+
showModalDialog?: (title: string, content: string) => void;
|
|
9
|
+
showConfirmationDialog?: (title: string, content: string) => boolean;
|
|
10
|
+
showToast?: (content: string, type: 'success' | 'warning' | 'error' | 'loading' | 'destroy') => void;
|
|
11
|
+
showErrorMessage?: (title: string, content: string) => void;
|
|
6
12
|
}
|
|
7
13
|
interface AppClientProviderProps {
|
|
8
14
|
children: React.ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-client-provider.d.ts","sourceRoot":"","sources":["../src/app-client-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"app-client-provider.d.ts","sourceRoot":"","sources":["../src/app-client-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEtE,OAAO,KAAyD,MAAM,OAAO,CAAC;AAE9E,UAAU,qBAAqB;IAC7B,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,CAAC,CAAC,GAAG,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IACzE,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3D,sBAAsB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;IACrE,SAAS,CAAC,EAAE,CACV,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,KAC1D,IAAI,CAAC;IACV,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7D;AAkDD,UAAU,sBAAsB;IAC9B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,MAAM,EAAE,eAAe,CAAC;CACzB;AAKD,QAAA,MAAM,YAAY,6BAAqC,CAAC;AAExD,QAAA,MAAM,iBAAiB,yBAA0B,sBAAsB,sBA6DtE,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAC;AAC3C,YAAY,EAAE,eAAe,EAAE,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
postmate - A powerful, simple, promise-based postMessage library
|
|
3
|
-
@version v1.5.2
|
|
4
|
-
@link https://github.com/dollarshaveclub/postmate
|
|
5
|
-
@author Jacob Kelley <jakie8@gmail.com>
|
|
6
|
-
@license MIT
|
|
7
|
-
**/var h="application/x-postmate-v1+json",w=5,C=0,_=function(){return++C},l=function(){var r;return p.debug?(r=console).log.apply(r,arguments):null},k=function(r){var t=document.createElement("a");t.href=r;var n=t.protocol.length>4?t.protocol:window.location.protocol,e=t.host.length?t.port==="80"||t.port==="443"?t.hostname:t.host:window.location.host;return t.origin||n+"//"+e},D={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},g=function(r,t){return!(typeof t=="string"&&r.origin!==t||!r.data||typeof r.data=="object"&&!("postmate"in r.data)||r.data.type!==h||!D[r.data.postmate])},V=function(r,t){var n=typeof r[t]=="function"?r[t]():r[t];return p.Promise.resolve(n)},A=function(){function s(t){var n=this;this.parent=t.parent,this.frame=t.frame,this.child=t.child,this.childOrigin=t.childOrigin,this.events={},process.env.NODE_ENV!=="production"&&(l("Parent: Registering API"),l("Parent: Awaiting messages...")),this.listener=function(e){if(!g(e,n.childOrigin))return!1;var o=((e||{}).data||{}).value||{},i=o.data,d=o.name;e.data.postmate==="emit"&&(process.env.NODE_ENV!=="production"&&l("Parent: Received event emission: "+d),d in n.events&&n.events[d].call(n,i))},this.parent.addEventListener("message",this.listener,!1),process.env.NODE_ENV!=="production"&&l("Parent: Awaiting event emissions from Child")}var r=s.prototype;return r.get=function(n){var e=this;return new p.Promise(function(o){var i=_(),d=function a(c){c.data.uid===i&&c.data.postmate==="reply"&&(e.parent.removeEventListener("message",a,!1),o(c.data.value))};e.parent.addEventListener("message",d,!1),e.child.postMessage({postmate:"request",type:h,property:n,uid:i},e.childOrigin)})},r.call=function(n,e){this.child.postMessage({postmate:"call",type:h,property:n,data:e},this.childOrigin)},r.on=function(n,e){this.events[n]=e},r.destroy=function(){process.env.NODE_ENV!=="production"&&l("Parent: Destroying Postmate instance"),window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame)},s}(),L=function(){function s(t){var n=this;this.model=t.model,this.parent=t.parent,this.parentOrigin=t.parentOrigin,this.child=t.child,process.env.NODE_ENV!=="production"&&(l("Child: Registering API"),l("Child: Awaiting messages...")),this.child.addEventListener("message",function(e){if(g(e,n.parentOrigin)){process.env.NODE_ENV!=="production"&&l("Child: Received request",e.data);var o=e.data,i=o.property,d=o.uid,a=o.data;if(e.data.postmate==="call"){i in n.model&&typeof n.model[i]=="function"&&n.model[i](a);return}V(n.model,i).then(function(c){return e.source.postMessage({property:i,postmate:"reply",type:h,uid:d,value:c},e.origin)})}})}var r=s.prototype;return r.emit=function(n,e){process.env.NODE_ENV!=="production"&&l('Child: Emitting Event "'+n+'"',e),this.parent.postMessage({postmate:"emit",type:h,value:{name:n,data:e}},this.parentOrigin)},s}(),p=function(){function s(t){var n=t.container,e=n===void 0?typeof e<"u"?e:document.body:n,o=t.model,i=t.url,d=t.name,a=t.classListArray,c=a===void 0?[]:a;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=d||"",this.frame.classList.add.apply(this.frame.classList,c),e.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=o||{},this.sendHandshake(i)}var r=s.prototype;return r.sendHandshake=function(n){var e=this,o=k(n),i=0,d;return new s.Promise(function(a,c){var f=function v(m){return g(m,o)?m.data.postmate==="handshake-reply"?(clearInterval(d),process.env.NODE_ENV!=="production"&&l("Parent: Received handshake reply from Child"),e.parent.removeEventListener("message",v,!1),e.childOrigin=m.origin,process.env.NODE_ENV!=="production"&&l("Parent: Saving Child origin",e.childOrigin),a(new A(e))):(process.env.NODE_ENV!=="production"&&l("Parent: Invalid handshake reply"),c("Failed handshake")):!1};e.parent.addEventListener("message",f,!1);var E=function(){i++,process.env.NODE_ENV!=="production"&&l("Parent: Sending handshake attempt "+i,{childOrigin:o}),e.child.postMessage({postmate:"handshake",type:h,model:e.model},o),i===w&&clearInterval(d)},y=function(){E(),d=setInterval(E,500)};e.frame.attachEvent?e.frame.attachEvent("onload",y):e.frame.onload=y,process.env.NODE_ENV!=="production"&&l("Parent: Loading frame",{url:n}),e.frame.src=n})},s}();p.debug=!1;p.Promise=function(){try{return window?window.Promise:Promise}catch{return null}}();p.Model=function(){function s(t){return this.child=window,this.model=t,this.parent=this.child.parent,this.sendHandshakeReply()}var r=s.prototype;return r.sendHandshakeReply=function(){var n=this;return new p.Promise(function(e,o){var i=function d(a){if(a.data.postmate){if(a.data.postmate==="handshake"){process.env.NODE_ENV!=="production"&&l("Child: Received handshake from Parent"),n.child.removeEventListener("message",d,!1),process.env.NODE_ENV!=="production"&&l("Child: Sending handshake reply to Parent"),a.source.postMessage({postmate:"handshake-reply",type:h},a.origin),n.parentOrigin=a.origin;var c=a.data.model;return c&&(Object.keys(c).forEach(function(f){n.model[f]=c[f]}),process.env.NODE_ENV!=="production"&&l("Child: Inherited and extended model from Parent")),process.env.NODE_ENV!=="production"&&l("Child: Saving Parent origin",n.parentOrigin),e(new L(n))}return o("Handshake Reply Failed")}};n.child.addEventListener("message",i,!1)})},s}();const P={isLoading:!0},N=u.createContext(P),I=()=>u.useContext(N),R=({children:s,config:r})=>{const[t,n]=u.useState({}),[e,o]=u.useState(P);u.useEffect(()=>{if(r.forceRedirect&&!r.isDev&&window.self===window.top){console.error("This app must be run inside an iframe when forceRedirect is true.");return}const d=new p.Model({setData:a=>{console.log("AppClientProvider: setData",a),n(a)}});d.then(a=>{console.log("AppClientProvider: handshake success",a),a.emit("init",r)}),d.catch(a=>{console.error("AppClientProvider: handshake error",a)}),o({isLoading:!1})},[r]);const i={...e,data:t};return console.log("client context value",i),O.jsx(N.Provider,{value:i,children:s})};exports.AppClientProvider=R;exports.useAppClient=I;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const G=require("react/jsx-runtime"),M=require("react");var v=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function J(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var E={},h={},C;function z(){if(C)return h;C=1,Object.defineProperty(h,"__esModule",{value:!0}),h.detach=h.attach=void 0;var r=d(),o=!1;function n(){o||typeof window>"u"||(o=!0,window.addEventListener("message",r.onMessage,!1))}h.attach=n;function t(){o=!1,window.removeEventListener("message",r.onMessage,!1)}return h.detach=t,h}var b={},j;function H(){if(j)return b;j=1,Object.defineProperty(b,"__esModule",{value:!0}),b.broadcastToChildWindows=void 0;var r=d();function o(n,t,e){for(var i=r.childWindows.length-1;i>=0;i--){var s=r.childWindows[i];s.closed?r.childWindows.splice(i,1):e!==s&&(0,r.broadcast)(n,{origin:t,frame:s.top})}}return b.broadcastToChildWindows=o,b}var g={},S;function Q(){if(S)return g;S=1,Object.defineProperty(g,"__esModule",{value:!0}),g.broadcast=void 0;var r=d();function o(n,t){var e=0,i,s=t.origin,a=t.frame;try{for(a.postMessage(n,s),(0,r.hasOpener)(a)&&a.opener.top!==window.top&&o(n,{origin:s,frame:a.opener.top});i=a.frames[e];)o(n,{origin:s,frame:i}),e++}catch{}}return g.broadcast=o,g}var l={};Object.defineProperty(l,"__esModule",{value:!0});l.subscribers=l.childWindows=l.prefix=void 0;l.prefix="/*framebus*/";l.childWindows=[];l.subscribers={};var y={},q;function X(){if(q)return y;q=1,Object.defineProperty(y,"__esModule",{value:!0}),y.dispatch=void 0;var r=d();function o(n,t,e,i,s){if(r.subscribers[n]&&r.subscribers[n][t]){var a=[];e&&a.push(e),i&&a.push(i);for(var u=0;u<r.subscribers[n][t].length;u++)r.subscribers[n][t][u].apply(s,a)}}return y.dispatch=o,y}var T={};Object.defineProperty(T,"__esModule",{value:!0});T.hasOpener=void 0;function Y(r){return!(r.top!==r||r.opener==null||r.opener===r||r.opener.closed===!0)}T.hasOpener=Y;var D={};Object.defineProperty(D,"__esModule",{value:!0});D.isntString=void 0;function Z(r){return typeof r!="string"}D.isntString=Z;var m={},R;function ee(){if(R)return m;R=1,Object.defineProperty(m,"__esModule",{value:!0}),m.onMessage=void 0;var r=d();function o(n){if(!(0,r.isntString)(n.data)){var t=(0,r.unpackPayload)(n);if(t){var e=t.eventData,i=t.reply;(0,r.dispatch)("*",t.event,e,i,n),(0,r.dispatch)(n.origin,t.event,e,i,n),(0,r.broadcastToChildWindows)(n.data,t.origin,n.source)}}}return m.onMessage=o,m}var _={},I;function re(){if(I)return _;I=1,Object.defineProperty(_,"__esModule",{value:!0}),_.packagePayload=void 0;var r=d();function o(n,t,e,i){var s,a={event:n,origin:t};typeof i=="function"&&(a.reply=(0,r.subscribeReplier)(i,t)),a.eventData=e;try{s=r.prefix+JSON.stringify(a)}catch(u){throw new Error("Could not stringify event: ".concat(u.message))}return s}return _.packagePayload=o,_}var F={};Object.defineProperty(F,"__esModule",{value:!0});F.sendMessage=void 0;function te(r,o,n){try{r.postMessage(o,n)}catch{}}F.sendMessage=te;var w={},P={},k;function K(){if(k)return P;k=1,Object.defineProperty(P,"__esModule",{value:!0}),P.Framebus=void 0;var r=d(),o=typeof window<"u"&&window.Promise,n=function(){function t(e){e===void 0&&(e={}),this.origin=e.origin||"*",this.channel=e.channel||"",this.verifyDomain=e.verifyDomain,this.targetFrames=e.targetFrames||[],this.limitBroadcastToFramesArray=!!e.targetFrames,this.isDestroyed=!1,this.listeners=[],this.hasAdditionalChecksForOnListeners=!!(this.verifyDomain||this.limitBroadcastToFramesArray)}return t.setPromise=function(e){t.Promise=e},t.target=function(e){return new t(e)},t.prototype.addTargetFrame=function(e){this.limitBroadcastToFramesArray&&this.targetFrames.push(e)},t.prototype.include=function(e){return e==null||e.Window==null||e.constructor!==e.Window?!1:(r.childWindows.push(e),!0)},t.prototype.target=function(e){return t.target(e)},t.prototype.emit=function(e,i,s){if(this.isDestroyed)return!1;var a=this.origin;if(e=this.namespaceEvent(e),(0,r.isntString)(e)||(0,r.isntString)(a))return!1;typeof i=="function"&&(s=i,i=void 0);var u=(0,r.packagePayload)(e,a,i,s);return u?(this.limitBroadcastToFramesArray?this.targetFramesAsWindows().forEach(function(c){(0,r.sendMessage)(c,u,a)}):(0,r.broadcast)(u,{origin:a,frame:window.top||window.self}),!0):!1},t.prototype.emitAsPromise=function(e,i){var s=this;return new t.Promise(function(a,u){var c=s.emit(e,i,function(f){a(f)});c||u(new Error('Listener not added for "'.concat(e,'"')))})},t.prototype.on=function(e,i){if(this.isDestroyed)return!1;var s=this,a=this.origin,u=i;return e=this.namespaceEvent(e),(0,r.subscriptionArgsInvalid)(e,u,a)?!1:(this.hasAdditionalChecksForOnListeners&&(u=function(){for(var c=[],f=0;f<arguments.length;f++)c[f]=arguments[f];s.passesVerifyDomainCheck(this&&this.origin)&&s.hasMatchingTargetFrame(this&&this.source)&&i.apply(void 0,c)}),this.listeners.push({eventName:e,handler:u,originalHandler:i}),r.subscribers[a]=r.subscribers[a]||{},r.subscribers[a][e]=r.subscribers[a][e]||[],r.subscribers[a][e].push(u),!0)},t.prototype.off=function(e,i){var s=i;if(this.isDestroyed)return!1;if(this.verifyDomain)for(var a=0;a<this.listeners.length;a++){var u=this.listeners[a];u.originalHandler===i&&(s=u.handler)}e=this.namespaceEvent(e);var c=this.origin;if((0,r.subscriptionArgsInvalid)(e,s,c))return!1;var f=r.subscribers[c]&&r.subscribers[c][e];if(!f)return!1;for(var a=0;a<f.length;a++)if(f[a]===s)return f.splice(a,1),!0;return!1},t.prototype.teardown=function(){if(!this.isDestroyed){this.isDestroyed=!0;for(var e=0;e<this.listeners.length;e++){var i=this.listeners[e];this.off(i.eventName,i.handler)}this.listeners.length=0}},t.prototype.passesVerifyDomainCheck=function(e){return this.verifyDomain?this.checkOrigin(e):!0},t.prototype.targetFramesAsWindows=function(){return this.limitBroadcastToFramesArray?this.targetFrames.map(function(e){return e instanceof HTMLIFrameElement?e.contentWindow:e}).filter(function(e){return e}):[]},t.prototype.hasMatchingTargetFrame=function(e){if(!this.limitBroadcastToFramesArray)return!0;var i=this.targetFramesAsWindows().find(function(s){return s===e});return!!i},t.prototype.checkOrigin=function(e){var i,s=document.createElement("a");s.href=location.href,s.protocol==="https:"?i=s.host.replace(/:443$/,""):s.protocol==="http:"?i=s.host.replace(/:80$/,""):i=s.host;var a=s.protocol+"//"+i;return a===e?!0:this.verifyDomain?this.verifyDomain(e):!0},t.prototype.namespaceEvent=function(e){return this.channel?"".concat(this.channel,":").concat(e):e},t.Promise=o,t}();return P.Framebus=n,P}function ie(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(r){var o=Math.random()*16|0,n=r==="x"?o:o&3|8;return n.toString(16)})}var ne=ie,L;function ae(){if(L)return w;L=1;var r=v&&v.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(w,"__esModule",{value:!0}),w.subscribeReplier=void 0;var o=K(),n=r(ne);function t(e,i){var s=(0,n.default)();function a(u,c){e(u,c),o.Framebus.target({origin:i}).off(s,a)}return o.Framebus.target({origin:i}).on(s,a),s}return w.subscribeReplier=t,w}var A={},B;function se(){if(B)return A;B=1,Object.defineProperty(A,"__esModule",{value:!0}),A.subscriptionArgsInvalid=void 0;var r=d();function o(n,t,e){return(0,r.isntString)(n)||typeof t!="function"?!0:(0,r.isntString)(e)}return A.subscriptionArgsInvalid=o,A}var V={};Object.defineProperty(V,"__esModule",{value:!0});var O={},W;function oe(){if(W)return O;W=1,Object.defineProperty(O,"__esModule",{value:!0}),O.unpackPayload=void 0;var r=d();function o(n){var t;if(n.data.slice(0,r.prefix.length)!==r.prefix)return!1;try{t=JSON.parse(n.data.slice(r.prefix.length))}catch{return!1}if(t.reply){var e=n.origin,i=n.source,s=t.reply;t.reply=function(u){if(i){var c=(0,r.packagePayload)(s,e,u);c&&i.postMessage(c,e)}}}return t}return O.unpackPayload=o,O}var $;function d(){return $||($=1,function(r){var o=v&&v.__createBinding||(Object.create?function(t,e,i,s){s===void 0&&(s=i);var a=Object.getOwnPropertyDescriptor(e,i);(!a||("get"in a?!e.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,s,a)}:function(t,e,i,s){s===void 0&&(s=i),t[s]=e[i]}),n=v&&v.__exportStar||function(t,e){for(var i in t)i!=="default"&&!Object.prototype.hasOwnProperty.call(e,i)&&o(e,t,i)};Object.defineProperty(r,"__esModule",{value:!0}),n(z(),r),n(H(),r),n(Q(),r),n(l,r),n(X(),r),n(T,r),n(D,r),n(ee(),r),n(re(),r),n(F,r),n(ae(),r),n(se(),r),n(V,r),n(oe(),r)}(E)),E}var ue=d(),ce=K();(0,ue.attach)();var fe=ce.Framebus;const p=J(fe),de={isLoading:!0,invokeAction:async()=>Promise.reject("Action functionality not initialized."),navigate:()=>{}},le=r=>{new p().emit("NAVIGATE",{path:r})},he=(r,o)=>{new p().emit("INVOKE_DEFAULT_ACTION",{actionKey:"showModalDialog",args:[r,o]})},pe=(r,o)=>new p().emit("INVOKE_DEFAULT_ACTION",{actionKey:"showConfirmationDialog",args:[r,o]}),ve=(r,o)=>{new p().emit("INVOKE_DEFAULT_ACTION",{actionKey:"showToast",args:[r,o]})},be=(r,o)=>{new p().emit("INVOKE_DEFAULT_ACTION",{actionKey:"showErrorMessage",args:[r,o]})},U=M.createContext(de),ge=()=>M.useContext(U),ye=({children:r,config:o})=>{const[n,t]=M.useState(void 0),[e,i]=M.useState(!0),s=(u,...c)=>new Promise((f,N)=>{new p().emit("INVOKE_ACTION",{actionKey:u,args:c},x=>{x.success?f(x.result):N(new Error(x.error))})});M.useEffect(()=>{if(o.forceRedirect&&!o.isDev&&window.self===window.top){console.error("This app must be run inside an iframe when forceRedirect is true.");return}const u=new p;return u.on("DATA_RESPONSE",c=>{t(c),i(!1)}),u.emit("REQUEST_DATA"),()=>{u.teardown()}},[o]);const a={data:n,isLoading:e,invokeAction:s,navigate:le,showModalDialog:he,showConfirmationDialog:pe,showToast:ve,showErrorMessage:be};return G.jsx(U.Provider,{value:a,children:r})};exports.AppClientProvider=ye;exports.useAppClient=ge;
|
package/dist/index.js
CHANGED
|
@@ -1,206 +1,408 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}, A = function(r) {
|
|
16
|
-
var t = document.createElement("a");
|
|
17
|
-
t.href = r;
|
|
18
|
-
var n = t.protocol.length > 4 ? t.protocol : window.location.protocol, e = t.host.length ? t.port === "80" || t.port === "443" ? t.hostname : t.host : window.location.host;
|
|
19
|
-
return t.origin || n + "//" + e;
|
|
20
|
-
}, L = {
|
|
21
|
-
handshake: 1,
|
|
22
|
-
"handshake-reply": 1,
|
|
23
|
-
call: 1,
|
|
24
|
-
emit: 1,
|
|
25
|
-
reply: 1,
|
|
26
|
-
request: 1
|
|
27
|
-
/**
|
|
28
|
-
* Ensures that a message is safe to interpret
|
|
29
|
-
* @param {Object} message The postmate message being sent
|
|
30
|
-
* @param {String|Boolean} allowedOrigin The whitelisted origin or false to skip origin check
|
|
31
|
-
* @return {Boolean}
|
|
32
|
-
*/
|
|
33
|
-
}, m = function(r, t) {
|
|
34
|
-
return !(typeof t == "string" && r.origin !== t || !r.data || typeof r.data == "object" && !("postmate" in r.data) || r.data.type !== h || !L[r.data.postmate]);
|
|
35
|
-
}, I = function(r, t) {
|
|
36
|
-
var n = typeof r[t] == "function" ? r[t]() : r[t];
|
|
37
|
-
return p.Promise.resolve(n);
|
|
38
|
-
}, x = /* @__PURE__ */ function() {
|
|
39
|
-
function s(t) {
|
|
40
|
-
var n = this;
|
|
41
|
-
this.parent = t.parent, this.frame = t.frame, this.child = t.child, this.childOrigin = t.childOrigin, this.events = {}, process.env.NODE_ENV !== "production" && (l("Parent: Registering API"), l("Parent: Awaiting messages...")), this.listener = function(e) {
|
|
42
|
-
if (!m(e, n.childOrigin))
|
|
43
|
-
return !1;
|
|
44
|
-
var o = ((e || {}).data || {}).value || {}, i = o.data, d = o.name;
|
|
45
|
-
e.data.postmate === "emit" && (process.env.NODE_ENV !== "production" && l("Parent: Received event emission: " + d), d in n.events && n.events[d].call(n, i));
|
|
46
|
-
}, this.parent.addEventListener("message", this.listener, !1), process.env.NODE_ENV !== "production" && l("Parent: Awaiting event emissions from Child");
|
|
1
|
+
import { jsx as G } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as J, useContext as z, useState as E, useEffect as H } from "react";
|
|
3
|
+
var v = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
|
|
4
|
+
function Q(r) {
|
|
5
|
+
return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
|
|
6
|
+
}
|
|
7
|
+
var x = {}, h = {}, C;
|
|
8
|
+
function X() {
|
|
9
|
+
if (C)
|
|
10
|
+
return h;
|
|
11
|
+
C = 1, Object.defineProperty(h, "__esModule", { value: !0 }), h.detach = h.attach = void 0;
|
|
12
|
+
var r = d(), o = !1;
|
|
13
|
+
function n() {
|
|
14
|
+
o || typeof window > "u" || (o = !0, window.addEventListener("message", r.onMessage, !1));
|
|
47
15
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return new p.Promise(function(o) {
|
|
52
|
-
var i = V(), d = function a(c) {
|
|
53
|
-
c.data.uid === i && c.data.postmate === "reply" && (e.parent.removeEventListener("message", a, !1), o(c.data.value));
|
|
54
|
-
};
|
|
55
|
-
e.parent.addEventListener("message", d, !1), e.child.postMessage({
|
|
56
|
-
postmate: "request",
|
|
57
|
-
type: h,
|
|
58
|
-
property: n,
|
|
59
|
-
uid: i
|
|
60
|
-
}, e.childOrigin);
|
|
61
|
-
});
|
|
62
|
-
}, r.call = function(n, e) {
|
|
63
|
-
this.child.postMessage({
|
|
64
|
-
postmate: "call",
|
|
65
|
-
type: h,
|
|
66
|
-
property: n,
|
|
67
|
-
data: e
|
|
68
|
-
}, this.childOrigin);
|
|
69
|
-
}, r.on = function(n, e) {
|
|
70
|
-
this.events[n] = e;
|
|
71
|
-
}, r.destroy = function() {
|
|
72
|
-
process.env.NODE_ENV !== "production" && l("Parent: Destroying Postmate instance"), window.removeEventListener("message", this.listener, !1), this.frame.parentNode.removeChild(this.frame);
|
|
73
|
-
}, s;
|
|
74
|
-
}(), R = /* @__PURE__ */ function() {
|
|
75
|
-
function s(t) {
|
|
76
|
-
var n = this;
|
|
77
|
-
this.model = t.model, this.parent = t.parent, this.parentOrigin = t.parentOrigin, this.child = t.child, process.env.NODE_ENV !== "production" && (l("Child: Registering API"), l("Child: Awaiting messages...")), this.child.addEventListener("message", function(e) {
|
|
78
|
-
if (m(e, n.parentOrigin)) {
|
|
79
|
-
process.env.NODE_ENV !== "production" && l("Child: Received request", e.data);
|
|
80
|
-
var o = e.data, i = o.property, d = o.uid, a = o.data;
|
|
81
|
-
if (e.data.postmate === "call") {
|
|
82
|
-
i in n.model && typeof n.model[i] == "function" && n.model[i](a);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
I(n.model, i).then(function(c) {
|
|
86
|
-
return e.source.postMessage({
|
|
87
|
-
property: i,
|
|
88
|
-
postmate: "reply",
|
|
89
|
-
type: h,
|
|
90
|
-
uid: d,
|
|
91
|
-
value: c
|
|
92
|
-
}, e.origin);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
});
|
|
16
|
+
h.attach = n;
|
|
17
|
+
function t() {
|
|
18
|
+
o = !1, window.removeEventListener("message", r.onMessage, !1);
|
|
96
19
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
20
|
+
return h.detach = t, h;
|
|
21
|
+
}
|
|
22
|
+
var b = {}, j;
|
|
23
|
+
function Y() {
|
|
24
|
+
if (j)
|
|
25
|
+
return b;
|
|
26
|
+
j = 1, Object.defineProperty(b, "__esModule", { value: !0 }), b.broadcastToChildWindows = void 0;
|
|
27
|
+
var r = d();
|
|
28
|
+
function o(n, t, e) {
|
|
29
|
+
for (var i = r.childWindows.length - 1; i >= 0; i--) {
|
|
30
|
+
var s = r.childWindows[i];
|
|
31
|
+
s.closed ? r.childWindows.splice(i, 1) : e !== s && (0, r.broadcast)(n, {
|
|
32
|
+
origin: t,
|
|
33
|
+
frame: s.top
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return b.broadcastToChildWindows = o, b;
|
|
38
|
+
}
|
|
39
|
+
var g = {}, q;
|
|
40
|
+
function Z() {
|
|
41
|
+
if (q)
|
|
42
|
+
return g;
|
|
43
|
+
q = 1, Object.defineProperty(g, "__esModule", { value: !0 }), g.broadcast = void 0;
|
|
44
|
+
var r = d();
|
|
45
|
+
function o(n, t) {
|
|
46
|
+
var e = 0, i, s = t.origin, a = t.frame;
|
|
47
|
+
try {
|
|
48
|
+
for (a.postMessage(n, s), (0, r.hasOpener)(a) && a.opener.top !== window.top && o(n, {
|
|
49
|
+
origin: s,
|
|
50
|
+
frame: a.opener.top
|
|
51
|
+
}); i = a.frames[e]; )
|
|
52
|
+
o(n, {
|
|
53
|
+
origin: s,
|
|
54
|
+
frame: i
|
|
55
|
+
}), e++;
|
|
56
|
+
} catch {
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return g.broadcast = o, g;
|
|
60
|
+
}
|
|
61
|
+
var l = {};
|
|
62
|
+
Object.defineProperty(l, "__esModule", { value: !0 });
|
|
63
|
+
l.subscribers = l.childWindows = l.prefix = void 0;
|
|
64
|
+
l.prefix = "/*framebus*/";
|
|
65
|
+
l.childWindows = [];
|
|
66
|
+
l.subscribers = {};
|
|
67
|
+
var y = {}, R;
|
|
68
|
+
function ee() {
|
|
69
|
+
if (R)
|
|
70
|
+
return y;
|
|
71
|
+
R = 1, Object.defineProperty(y, "__esModule", { value: !0 }), y.dispatch = void 0;
|
|
72
|
+
var r = d();
|
|
73
|
+
function o(n, t, e, i, s) {
|
|
74
|
+
if (r.subscribers[n] && r.subscribers[n][t]) {
|
|
75
|
+
var a = [];
|
|
76
|
+
e && a.push(e), i && a.push(i);
|
|
77
|
+
for (var u = 0; u < r.subscribers[n][t].length; u++)
|
|
78
|
+
r.subscribers[n][t][u].apply(s, a);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return y.dispatch = o, y;
|
|
82
|
+
}
|
|
83
|
+
var M = {};
|
|
84
|
+
Object.defineProperty(M, "__esModule", { value: !0 });
|
|
85
|
+
M.hasOpener = void 0;
|
|
86
|
+
function re(r) {
|
|
87
|
+
return !(r.top !== r || r.opener == null || r.opener === r || r.opener.closed === !0);
|
|
88
|
+
}
|
|
89
|
+
M.hasOpener = re;
|
|
90
|
+
var T = {};
|
|
91
|
+
Object.defineProperty(T, "__esModule", { value: !0 });
|
|
92
|
+
T.isntString = void 0;
|
|
93
|
+
function te(r) {
|
|
94
|
+
return typeof r != "string";
|
|
95
|
+
}
|
|
96
|
+
T.isntString = te;
|
|
97
|
+
var m = {}, S;
|
|
98
|
+
function ie() {
|
|
99
|
+
if (S)
|
|
100
|
+
return m;
|
|
101
|
+
S = 1, Object.defineProperty(m, "__esModule", { value: !0 }), m.onMessage = void 0;
|
|
102
|
+
var r = d();
|
|
103
|
+
function o(n) {
|
|
104
|
+
if (!(0, r.isntString)(n.data)) {
|
|
105
|
+
var t = (0, r.unpackPayload)(n);
|
|
106
|
+
if (t) {
|
|
107
|
+
var e = t.eventData, i = t.reply;
|
|
108
|
+
(0, r.dispatch)("*", t.event, e, i, n), (0, r.dispatch)(n.origin, t.event, e, i, n), (0, r.broadcastToChildWindows)(n.data, t.origin, n.source);
|
|
105
109
|
}
|
|
106
|
-
}
|
|
107
|
-
}, s;
|
|
108
|
-
}(), p = /* @__PURE__ */ function() {
|
|
109
|
-
function s(t) {
|
|
110
|
-
var n = t.container, e = n === void 0 ? typeof e < "u" ? e : document.body : n, o = t.model, i = t.url, d = t.name, a = t.classListArray, c = a === void 0 ? [] : a;
|
|
111
|
-
return this.parent = window, this.frame = document.createElement("iframe"), this.frame.name = d || "", this.frame.classList.add.apply(this.frame.classList, c), e.appendChild(this.frame), this.child = this.frame.contentWindow || this.frame.contentDocument.parentWindow, this.model = o || {}, this.sendHandshake(i);
|
|
110
|
+
}
|
|
112
111
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
112
|
+
return m.onMessage = o, m;
|
|
113
|
+
}
|
|
114
|
+
var _ = {}, I;
|
|
115
|
+
function ne() {
|
|
116
|
+
if (I)
|
|
117
|
+
return _;
|
|
118
|
+
I = 1, Object.defineProperty(_, "__esModule", { value: !0 }), _.packagePayload = void 0;
|
|
119
|
+
var r = d();
|
|
120
|
+
function o(n, t, e, i) {
|
|
121
|
+
var s, a = {
|
|
122
|
+
event: n,
|
|
123
|
+
origin: t
|
|
124
|
+
};
|
|
125
|
+
typeof i == "function" && (a.reply = (0, r.subscribeReplier)(i, t)), a.eventData = e;
|
|
126
|
+
try {
|
|
127
|
+
s = r.prefix + JSON.stringify(a);
|
|
128
|
+
} catch (u) {
|
|
129
|
+
throw new Error("Could not stringify event: ".concat(u.message));
|
|
130
|
+
}
|
|
131
|
+
return s;
|
|
132
|
+
}
|
|
133
|
+
return _.packagePayload = o, _;
|
|
134
|
+
}
|
|
135
|
+
var D = {};
|
|
136
|
+
Object.defineProperty(D, "__esModule", { value: !0 });
|
|
137
|
+
D.sendMessage = void 0;
|
|
138
|
+
function ae(r, o, n) {
|
|
140
139
|
try {
|
|
141
|
-
|
|
140
|
+
r.postMessage(o, n);
|
|
142
141
|
} catch {
|
|
143
|
-
return null;
|
|
144
142
|
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
143
|
+
}
|
|
144
|
+
D.sendMessage = ae;
|
|
145
|
+
var w = {}, P = {}, k;
|
|
146
|
+
function K() {
|
|
147
|
+
if (k)
|
|
148
|
+
return P;
|
|
149
|
+
k = 1, Object.defineProperty(P, "__esModule", { value: !0 }), P.Framebus = void 0;
|
|
150
|
+
var r = d(), o = typeof window < "u" && window.Promise, n = (
|
|
151
|
+
/** @class */
|
|
152
|
+
function() {
|
|
153
|
+
function t(e) {
|
|
154
|
+
e === void 0 && (e = {}), this.origin = e.origin || "*", this.channel = e.channel || "", this.verifyDomain = e.verifyDomain, this.targetFrames = e.targetFrames || [], this.limitBroadcastToFramesArray = !!e.targetFrames, this.isDestroyed = !1, this.listeners = [], this.hasAdditionalChecksForOnListeners = !!(this.verifyDomain || this.limitBroadcastToFramesArray);
|
|
155
|
+
}
|
|
156
|
+
return t.setPromise = function(e) {
|
|
157
|
+
t.Promise = e;
|
|
158
|
+
}, t.target = function(e) {
|
|
159
|
+
return new t(e);
|
|
160
|
+
}, t.prototype.addTargetFrame = function(e) {
|
|
161
|
+
this.limitBroadcastToFramesArray && this.targetFrames.push(e);
|
|
162
|
+
}, t.prototype.include = function(e) {
|
|
163
|
+
return e == null || e.Window == null || e.constructor !== e.Window ? !1 : (r.childWindows.push(e), !0);
|
|
164
|
+
}, t.prototype.target = function(e) {
|
|
165
|
+
return t.target(e);
|
|
166
|
+
}, t.prototype.emit = function(e, i, s) {
|
|
167
|
+
if (this.isDestroyed)
|
|
168
|
+
return !1;
|
|
169
|
+
var a = this.origin;
|
|
170
|
+
if (e = this.namespaceEvent(e), (0, r.isntString)(e) || (0, r.isntString)(a))
|
|
171
|
+
return !1;
|
|
172
|
+
typeof i == "function" && (s = i, i = void 0);
|
|
173
|
+
var u = (0, r.packagePayload)(e, a, i, s);
|
|
174
|
+
return u ? (this.limitBroadcastToFramesArray ? this.targetFramesAsWindows().forEach(function(c) {
|
|
175
|
+
(0, r.sendMessage)(c, u, a);
|
|
176
|
+
}) : (0, r.broadcast)(u, {
|
|
177
|
+
origin: a,
|
|
178
|
+
frame: window.top || window.self
|
|
179
|
+
}), !0) : !1;
|
|
180
|
+
}, t.prototype.emitAsPromise = function(e, i) {
|
|
181
|
+
var s = this;
|
|
182
|
+
return new t.Promise(function(a, u) {
|
|
183
|
+
var c = s.emit(e, i, function(f) {
|
|
184
|
+
a(f);
|
|
185
|
+
});
|
|
186
|
+
c || u(new Error('Listener not added for "'.concat(e, '"')));
|
|
187
|
+
});
|
|
188
|
+
}, t.prototype.on = function(e, i) {
|
|
189
|
+
if (this.isDestroyed)
|
|
190
|
+
return !1;
|
|
191
|
+
var s = this, a = this.origin, u = i;
|
|
192
|
+
return e = this.namespaceEvent(e), (0, r.subscriptionArgsInvalid)(e, u, a) ? !1 : (this.hasAdditionalChecksForOnListeners && (u = function() {
|
|
193
|
+
for (var c = [], f = 0; f < arguments.length; f++)
|
|
194
|
+
c[f] = arguments[f];
|
|
195
|
+
s.passesVerifyDomainCheck(this && this.origin) && s.hasMatchingTargetFrame(this && this.source) && i.apply(void 0, c);
|
|
196
|
+
}), this.listeners.push({
|
|
197
|
+
eventName: e,
|
|
198
|
+
handler: u,
|
|
199
|
+
originalHandler: i
|
|
200
|
+
}), r.subscribers[a] = r.subscribers[a] || {}, r.subscribers[a][e] = r.subscribers[a][e] || [], r.subscribers[a][e].push(u), !0);
|
|
201
|
+
}, t.prototype.off = function(e, i) {
|
|
202
|
+
var s = i;
|
|
203
|
+
if (this.isDestroyed)
|
|
204
|
+
return !1;
|
|
205
|
+
if (this.verifyDomain)
|
|
206
|
+
for (var a = 0; a < this.listeners.length; a++) {
|
|
207
|
+
var u = this.listeners[a];
|
|
208
|
+
u.originalHandler === i && (s = u.handler);
|
|
209
|
+
}
|
|
210
|
+
e = this.namespaceEvent(e);
|
|
211
|
+
var c = this.origin;
|
|
212
|
+
if ((0, r.subscriptionArgsInvalid)(e, s, c))
|
|
213
|
+
return !1;
|
|
214
|
+
var f = r.subscribers[c] && r.subscribers[c][e];
|
|
215
|
+
if (!f)
|
|
216
|
+
return !1;
|
|
217
|
+
for (var a = 0; a < f.length; a++)
|
|
218
|
+
if (f[a] === s)
|
|
219
|
+
return f.splice(a, 1), !0;
|
|
220
|
+
return !1;
|
|
221
|
+
}, t.prototype.teardown = function() {
|
|
222
|
+
if (!this.isDestroyed) {
|
|
223
|
+
this.isDestroyed = !0;
|
|
224
|
+
for (var e = 0; e < this.listeners.length; e++) {
|
|
225
|
+
var i = this.listeners[e];
|
|
226
|
+
this.off(i.eventName, i.handler);
|
|
165
227
|
}
|
|
166
|
-
|
|
228
|
+
this.listeners.length = 0;
|
|
229
|
+
}
|
|
230
|
+
}, t.prototype.passesVerifyDomainCheck = function(e) {
|
|
231
|
+
return this.verifyDomain ? this.checkOrigin(e) : !0;
|
|
232
|
+
}, t.prototype.targetFramesAsWindows = function() {
|
|
233
|
+
return this.limitBroadcastToFramesArray ? this.targetFrames.map(function(e) {
|
|
234
|
+
return e instanceof HTMLIFrameElement ? e.contentWindow : e;
|
|
235
|
+
}).filter(function(e) {
|
|
236
|
+
return e;
|
|
237
|
+
}) : [];
|
|
238
|
+
}, t.prototype.hasMatchingTargetFrame = function(e) {
|
|
239
|
+
if (!this.limitBroadcastToFramesArray)
|
|
240
|
+
return !0;
|
|
241
|
+
var i = this.targetFramesAsWindows().find(function(s) {
|
|
242
|
+
return s === e;
|
|
243
|
+
});
|
|
244
|
+
return !!i;
|
|
245
|
+
}, t.prototype.checkOrigin = function(e) {
|
|
246
|
+
var i, s = document.createElement("a");
|
|
247
|
+
s.href = location.href, s.protocol === "https:" ? i = s.host.replace(/:443$/, "") : s.protocol === "http:" ? i = s.host.replace(/:80$/, "") : i = s.host;
|
|
248
|
+
var a = s.protocol + "//" + i;
|
|
249
|
+
return a === e ? !0 : this.verifyDomain ? this.verifyDomain(e) : !0;
|
|
250
|
+
}, t.prototype.namespaceEvent = function(e) {
|
|
251
|
+
return this.channel ? "".concat(this.channel, ":").concat(e) : e;
|
|
252
|
+
}, t.Promise = o, t;
|
|
253
|
+
}()
|
|
254
|
+
);
|
|
255
|
+
return P.Framebus = n, P;
|
|
256
|
+
}
|
|
257
|
+
function se() {
|
|
258
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(r) {
|
|
259
|
+
var o = Math.random() * 16 | 0, n = r === "x" ? o : o & 3 | 8;
|
|
260
|
+
return n.toString(16);
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
var oe = se, L;
|
|
264
|
+
function ue() {
|
|
265
|
+
if (L)
|
|
266
|
+
return w;
|
|
267
|
+
L = 1;
|
|
268
|
+
var r = v && v.__importDefault || function(e) {
|
|
269
|
+
return e && e.__esModule ? e : { default: e };
|
|
270
|
+
};
|
|
271
|
+
Object.defineProperty(w, "__esModule", { value: !0 }), w.subscribeReplier = void 0;
|
|
272
|
+
var o = K(), n = r(oe);
|
|
273
|
+
function t(e, i) {
|
|
274
|
+
var s = (0, n.default)();
|
|
275
|
+
function a(u, c) {
|
|
276
|
+
e(u, c), o.Framebus.target({
|
|
277
|
+
origin: i
|
|
278
|
+
}).off(s, a);
|
|
279
|
+
}
|
|
280
|
+
return o.Framebus.target({
|
|
281
|
+
origin: i
|
|
282
|
+
}).on(s, a), s;
|
|
283
|
+
}
|
|
284
|
+
return w.subscribeReplier = t, w;
|
|
285
|
+
}
|
|
286
|
+
var A = {}, B;
|
|
287
|
+
function ce() {
|
|
288
|
+
if (B)
|
|
289
|
+
return A;
|
|
290
|
+
B = 1, Object.defineProperty(A, "__esModule", { value: !0 }), A.subscriptionArgsInvalid = void 0;
|
|
291
|
+
var r = d();
|
|
292
|
+
function o(n, t, e) {
|
|
293
|
+
return (0, r.isntString)(n) || typeof t != "function" ? !0 : (0, r.isntString)(e);
|
|
294
|
+
}
|
|
295
|
+
return A.subscriptionArgsInvalid = o, A;
|
|
296
|
+
}
|
|
297
|
+
var V = {};
|
|
298
|
+
Object.defineProperty(V, "__esModule", { value: !0 });
|
|
299
|
+
var O = {}, W;
|
|
300
|
+
function fe() {
|
|
301
|
+
if (W)
|
|
302
|
+
return O;
|
|
303
|
+
W = 1, Object.defineProperty(O, "__esModule", { value: !0 }), O.unpackPayload = void 0;
|
|
304
|
+
var r = d();
|
|
305
|
+
function o(n) {
|
|
306
|
+
var t;
|
|
307
|
+
if (n.data.slice(0, r.prefix.length) !== r.prefix)
|
|
308
|
+
return !1;
|
|
309
|
+
try {
|
|
310
|
+
t = JSON.parse(n.data.slice(r.prefix.length));
|
|
311
|
+
} catch {
|
|
312
|
+
return !1;
|
|
313
|
+
}
|
|
314
|
+
if (t.reply) {
|
|
315
|
+
var e = n.origin, i = n.source, s = t.reply;
|
|
316
|
+
t.reply = function(u) {
|
|
317
|
+
if (i) {
|
|
318
|
+
var c = (0, r.packagePayload)(s, e, u);
|
|
319
|
+
c && i.postMessage(c, e);
|
|
167
320
|
}
|
|
168
321
|
};
|
|
169
|
-
|
|
322
|
+
}
|
|
323
|
+
return t;
|
|
324
|
+
}
|
|
325
|
+
return O.unpackPayload = o, O;
|
|
326
|
+
}
|
|
327
|
+
var $;
|
|
328
|
+
function d() {
|
|
329
|
+
return $ || ($ = 1, function(r) {
|
|
330
|
+
var o = v && v.__createBinding || (Object.create ? function(t, e, i, s) {
|
|
331
|
+
s === void 0 && (s = i);
|
|
332
|
+
var a = Object.getOwnPropertyDescriptor(e, i);
|
|
333
|
+
(!a || ("get" in a ? !e.__esModule : a.writable || a.configurable)) && (a = { enumerable: !0, get: function() {
|
|
334
|
+
return e[i];
|
|
335
|
+
} }), Object.defineProperty(t, s, a);
|
|
336
|
+
} : function(t, e, i, s) {
|
|
337
|
+
s === void 0 && (s = i), t[s] = e[i];
|
|
338
|
+
}), n = v && v.__exportStar || function(t, e) {
|
|
339
|
+
for (var i in t)
|
|
340
|
+
i !== "default" && !Object.prototype.hasOwnProperty.call(e, i) && o(e, t, i);
|
|
341
|
+
};
|
|
342
|
+
Object.defineProperty(r, "__esModule", { value: !0 }), n(X(), r), n(Y(), r), n(Z(), r), n(l, r), n(ee(), r), n(M, r), n(T, r), n(ie(), r), n(ne(), r), n(D, r), n(ue(), r), n(ce(), r), n(V, r), n(fe(), r);
|
|
343
|
+
}(x)), x;
|
|
344
|
+
}
|
|
345
|
+
var de = d(), le = K();
|
|
346
|
+
(0, de.attach)();
|
|
347
|
+
var he = le.Framebus;
|
|
348
|
+
const p = /* @__PURE__ */ Q(he), pe = {
|
|
349
|
+
isLoading: !0,
|
|
350
|
+
invokeAction: async () => Promise.reject("Action functionality not initialized."),
|
|
351
|
+
navigate: () => {
|
|
352
|
+
}
|
|
353
|
+
}, ve = (r) => {
|
|
354
|
+
new p().emit("NAVIGATE", { path: r });
|
|
355
|
+
}, be = (r, o) => {
|
|
356
|
+
new p().emit("INVOKE_DEFAULT_ACTION", {
|
|
357
|
+
actionKey: "showModalDialog",
|
|
358
|
+
args: [r, o]
|
|
359
|
+
});
|
|
360
|
+
}, ge = (r, o) => new p().emit("INVOKE_DEFAULT_ACTION", {
|
|
361
|
+
actionKey: "showConfirmationDialog",
|
|
362
|
+
args: [r, o]
|
|
363
|
+
}), ye = (r, o) => {
|
|
364
|
+
new p().emit("INVOKE_DEFAULT_ACTION", {
|
|
365
|
+
actionKey: "showToast",
|
|
366
|
+
args: [r, o]
|
|
367
|
+
});
|
|
368
|
+
}, me = (r, o) => {
|
|
369
|
+
new p().emit("INVOKE_DEFAULT_ACTION", {
|
|
370
|
+
actionKey: "showErrorMessage",
|
|
371
|
+
args: [r, o]
|
|
372
|
+
});
|
|
373
|
+
}, U = J(pe), Ae = () => z(U), Oe = ({ children: r, config: o }) => {
|
|
374
|
+
const [n, t] = E(void 0), [e, i] = E(!0), s = (u, ...c) => new Promise((f, N) => {
|
|
375
|
+
new p().emit("INVOKE_ACTION", { actionKey: u, args: c }, (F) => {
|
|
376
|
+
F.success ? f(F.result) : N(new Error(F.error));
|
|
170
377
|
});
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
isLoading: !0
|
|
175
|
-
}, N = w(P), S = () => C(N), b = ({ children: s, config: r }) => {
|
|
176
|
-
const [t, n] = y({}), [e, o] = y(P);
|
|
177
|
-
_(() => {
|
|
178
|
-
if (r.forceRedirect && !r.isDev && window.self === window.top) {
|
|
378
|
+
});
|
|
379
|
+
H(() => {
|
|
380
|
+
if (o.forceRedirect && !o.isDev && window.self === window.top) {
|
|
179
381
|
console.error(
|
|
180
382
|
"This app must be run inside an iframe when forceRedirect is true."
|
|
181
383
|
);
|
|
182
384
|
return;
|
|
183
385
|
}
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
386
|
+
const u = new p();
|
|
387
|
+
return u.on("DATA_RESPONSE", (c) => {
|
|
388
|
+
t(c), i(!1);
|
|
389
|
+
}), u.emit("REQUEST_DATA"), () => {
|
|
390
|
+
u.teardown();
|
|
391
|
+
};
|
|
392
|
+
}, [o]);
|
|
393
|
+
const a = {
|
|
394
|
+
data: n,
|
|
395
|
+
isLoading: e,
|
|
396
|
+
invokeAction: s,
|
|
397
|
+
navigate: ve,
|
|
398
|
+
showModalDialog: be,
|
|
399
|
+
showConfirmationDialog: ge,
|
|
400
|
+
showToast: ye,
|
|
401
|
+
showErrorMessage: me
|
|
200
402
|
};
|
|
201
|
-
return
|
|
403
|
+
return /* @__PURE__ */ G(U.Provider, { value: a, children: r });
|
|
202
404
|
};
|
|
203
405
|
export {
|
|
204
|
-
|
|
205
|
-
|
|
406
|
+
Oe as AppClientProvider,
|
|
407
|
+
Ae as useAppClient
|
|
206
408
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akinon/app-client",
|
|
3
3
|
"description": "Akinon UI App Client. This library is used to create a new plugin or an application which will reside in Akinon's applications.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.js",
|
|
@@ -10,9 +10,10 @@
|
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
+
"framebus": "^6.0.0",
|
|
13
14
|
"postmate": "^1.5.2",
|
|
14
15
|
"use-immer": "^0.9.0",
|
|
15
|
-
"@akinon/app-shared": "^0.1
|
|
16
|
+
"@akinon/app-shared": "^0.2.1"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
18
19
|
"@types/postmate": "^1.5.3",
|