@akinon/app-client 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApplicationData, ApplicationNavigation, ApplicationParams, FullpageApplicationConfig, PluginApplicationConfig, RegisteredApp, RegisteredAppType } from '@akinon/app-shared';
|
|
1
|
+
import { ApplicationData, ApplicationNavigation, ApplicationParams, FullpageApplicationConfig, PluginApplicationConfig, RegisteredApp, RegisteredAppType, ShellNavigation, ShellNavigationPayload } from '@akinon/app-shared';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
/**
|
|
4
4
|
* Defines the context state for the AppClient, including application data,
|
|
@@ -16,7 +16,7 @@ interface AppClientContextState {
|
|
|
16
16
|
params?: ApplicationParams;
|
|
17
17
|
isLoading: boolean;
|
|
18
18
|
invokeAction: <T = any>(actionKey: string, ...args: any[]) => Promise<T>;
|
|
19
|
-
navigate: (
|
|
19
|
+
navigate: (payload: ShellNavigationPayload) => void;
|
|
20
20
|
showModalDialog?: (title: string, content: string) => void;
|
|
21
21
|
showConfirmationDialog?: (title: string, content: string) => boolean;
|
|
22
22
|
showToast?: (content: string, type: 'success' | 'warning' | 'error' | 'loading' | 'destroy') => void;
|
|
@@ -44,5 +44,5 @@ declare const useAppClient: () => AppClientContextState;
|
|
|
44
44
|
*/
|
|
45
45
|
declare const AppClientProvider: ({ children, config }: AppClientProviderProps) => React.JSX.Element;
|
|
46
46
|
export { AppClientProvider, useAppClient };
|
|
47
|
-
export type { ApplicationNavigation, FullpageApplicationConfig, PluginApplicationConfig, RegisteredApp, RegisteredAppType };
|
|
47
|
+
export type { ApplicationNavigation, FullpageApplicationConfig, PluginApplicationConfig, RegisteredApp, RegisteredAppType, ShellNavigation };
|
|
48
48
|
//# sourceMappingURL=app-client-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-client-provider.d.ts","sourceRoot":"","sources":["../src/app-client-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,yBAAyB,EACzB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,
|
|
1
|
+
{"version":3,"file":"app-client-provider.d.ts","sourceRoot":"","sources":["../src/app-client-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,yBAAyB,EACzB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAyD,MAAM,OAAO,CAAC;AAE9E;;;;;;;;;;GAUG;AACH,UAAU,qBAAqB;IAC7B,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,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,OAAO,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACpD,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;AAED;;;;;GAKG;AACH,UAAU,sBAAsB;IAC9B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,MAAM,EAAE,yBAAyB,GAAG,uBAAuB,CAAC;CAC7D;AAaD;;;GAGG;AACH,QAAA,MAAM,YAAY,6BAAqC,CAAC;AA4ExD;;;;GAIG;AACH,QAAA,MAAM,iBAAiB,yBAA0B,sBAAsB,sBAmGtE,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAC;AAC3C,YAAY,EACV,qBAAqB,EACrB,yBAAyB,EACzB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,eAAe,EAChB,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Y=require("react/jsx-runtime"),b=require("react");var m=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Z(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var R={},g={},q;function ee(){if(q)return g;q=1,Object.defineProperty(g,"__esModule",{value:!0}),g.detach=g.attach=void 0;var r=d(),o=!1;function n(){o||typeof window>"u"||(o=!0,window.addEventListener("message",r.onMessage,!1))}g.attach=n;function t(){o=!1,window.removeEventListener("message",r.onMessage,!1)}return g.detach=t,g}var w={},L;function re(){if(L)return w;L=1,Object.defineProperty(w,"__esModule",{value:!0}),w.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 w.broadcastToChildWindows=o,w}var P={},k;function te(){if(k)return P;k=1,Object.defineProperty(P,"__esModule",{value:!0}),P.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 P.broadcast=o,P}var p={};Object.defineProperty(p,"__esModule",{value:!0});p.subscribers=p.childWindows=p.prefix=void 0;p.prefix="/*framebus*/";p.childWindows=[];p.subscribers={};var A={},B;function ie(){if(B)return A;B=1,Object.defineProperty(A,"__esModule",{value:!0}),A.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 A.dispatch=o,A}var S={};Object.defineProperty(S,"__esModule",{value:!0});S.hasOpener=void 0;function ne(r){return!(r.top!==r||r.opener==null||r.opener===r||r.opener.closed===!0)}S.hasOpener=ne;var j={};Object.defineProperty(j,"__esModule",{value:!0});j.isntString=void 0;function ae(r){return typeof r!="string"}j.isntString=ae;var O={},W;function se(){if(W)return O;W=1,Object.defineProperty(O,"__esModule",{value:!0}),O.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 O.onMessage=o,O}var M={},$;function oe(){if($)return M;$=1,Object.defineProperty(M,"__esModule",{value:!0}),M.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 M.packagePayload=o,M}var I={};Object.defineProperty(I,"__esModule",{value:!0});I.sendMessage=void 0;function ue(r,o,n){try{r.postMessage(o,n)}catch{}}I.sendMessage=ue;var T={},D={},V;function H(){if(V)return D;V=1,Object.defineProperty(D,"__esModule",{value:!0}),D.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 D.Framebus=n,D}function ce(){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 fe=ce,K;function de(){if(K)return T;K=1;var r=m&&m.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(T,"__esModule",{value:!0}),T.subscribeReplier=void 0;var o=H(),n=r(fe);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 T.subscribeReplier=t,T}var F={},U;function le(){if(U)return F;U=1,Object.defineProperty(F,"__esModule",{value:!0}),F.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 F.subscriptionArgsInvalid=o,F}var J={};Object.defineProperty(J,"__esModule",{value:!0});var E={},N;function he(){if(N)return E;N=1,Object.defineProperty(E,"__esModule",{value:!0}),E.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 E.unpackPayload=o,E}var G;function d(){return G||(G=1,function(r){var o=m&&m.__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=m&&m.__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(ee(),r),n(re(),r),n(te(),r),n(p,r),n(ie(),r),n(S,r),n(j,r),n(se(),r),n(oe(),r),n(I,r),n(de(),r),n(le(),r),n(J,r),n(he(),r)}(R)),R}var pe=d(),ve=H();(0,pe.attach)();var ge=ve.Framebus;const v=Z(ge),be={isLoading:!0,invokeAction:async()=>Promise.reject("Action functionality not initialized."),navigate:()=>{}},z=b.createContext(be),ye=()=>b.useContext(z),me=r=>{new v().emit("NAVIGATE",{path:r})},_e=(r,o)=>{new v().emit("INVOKE_DEFAULT_ACTION",{actionKey:"showModalDialog",args:[r,o]})},we=(r,o)=>new v().emit("INVOKE_DEFAULT_ACTION",{actionKey:"showConfirmationDialog",args:[r,o]}),Pe=(r,o)=>{new v().emit("INVOKE_DEFAULT_ACTION",{actionKey:"showToast",args:[r,o]})},Ae=(r,o)=>{new v().emit("INVOKE_DEFAULT_ACTION",{actionKey:"showErrorMessage",args:[r,o]})},Oe=({children:r,config:o})=>{const[,n]=b.useState(void 0),[t,e]=b.useState(void 0),[i,s]=b.useState(void 0),[a,u]=b.useState(!0),c=(x,...C)=>new Promise((h,l)=>{new v().emit("INVOKE_ACTION",{actionKey:x,args:C},y=>{y.success?h(y.result):l(new Error(y.error))})}),f=()=>{const x=o;return Array.isArray(x.menu)};b.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 C=new URL(window.location.href).searchParams.get("c"),h=C?new v({channel:C}):new v;return h.emit("REQUEST_DATA",{config:o}),h.on("DATA_RESPONSE",l=>{e(l),u(!1)}),h.on("PARAMS_RESPONSE",l=>{s(l)}),h.on("SET_APP_ID",l=>{const{appId:_}=l;n(_)}),f()&&h.on("NAVIGATE_CHILD",l=>{const{path:_}=l,{navigation:y}=o;if(y){const{navigate:X}=y;X({path:_})}}),()=>{h.teardown()}},[o]);const Q={data:t,params:i,isLoading:a,invokeAction:c,navigate:me,showModalDialog:_e,showConfirmationDialog:we,showToast:Pe,showErrorMessage:Ae};return Y.jsx(z.Provider,{value:Q,children:r})};exports.AppClientProvider=Oe;exports.useAppClient=ye;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Y=require("react/jsx-runtime"),b=require("react");var m=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Z(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var R={},g={},q;function ee(){if(q)return g;q=1,Object.defineProperty(g,"__esModule",{value:!0}),g.detach=g.attach=void 0;var r=d(),o=!1;function n(){o||typeof window>"u"||(o=!0,window.addEventListener("message",r.onMessage,!1))}g.attach=n;function t(){o=!1,window.removeEventListener("message",r.onMessage,!1)}return g.detach=t,g}var w={},L;function re(){if(L)return w;L=1,Object.defineProperty(w,"__esModule",{value:!0}),w.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 w.broadcastToChildWindows=o,w}var P={},k;function te(){if(k)return P;k=1,Object.defineProperty(P,"__esModule",{value:!0}),P.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 P.broadcast=o,P}var p={};Object.defineProperty(p,"__esModule",{value:!0});p.subscribers=p.childWindows=p.prefix=void 0;p.prefix="/*framebus*/";p.childWindows=[];p.subscribers={};var A={},B;function ie(){if(B)return A;B=1,Object.defineProperty(A,"__esModule",{value:!0}),A.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 A.dispatch=o,A}var S={};Object.defineProperty(S,"__esModule",{value:!0});S.hasOpener=void 0;function ne(r){return!(r.top!==r||r.opener==null||r.opener===r||r.opener.closed===!0)}S.hasOpener=ne;var j={};Object.defineProperty(j,"__esModule",{value:!0});j.isntString=void 0;function ae(r){return typeof r!="string"}j.isntString=ae;var O={},W;function se(){if(W)return O;W=1,Object.defineProperty(O,"__esModule",{value:!0}),O.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 O.onMessage=o,O}var M={},$;function oe(){if($)return M;$=1,Object.defineProperty(M,"__esModule",{value:!0}),M.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 M.packagePayload=o,M}var I={};Object.defineProperty(I,"__esModule",{value:!0});I.sendMessage=void 0;function ue(r,o,n){try{r.postMessage(o,n)}catch{}}I.sendMessage=ue;var T={},D={},V;function H(){if(V)return D;V=1,Object.defineProperty(D,"__esModule",{value:!0}),D.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 D.Framebus=n,D}function ce(){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 fe=ce,K;function de(){if(K)return T;K=1;var r=m&&m.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(T,"__esModule",{value:!0}),T.subscribeReplier=void 0;var o=H(),n=r(fe);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 T.subscribeReplier=t,T}var F={},U;function le(){if(U)return F;U=1,Object.defineProperty(F,"__esModule",{value:!0}),F.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 F.subscriptionArgsInvalid=o,F}var J={};Object.defineProperty(J,"__esModule",{value:!0});var E={},N;function he(){if(N)return E;N=1,Object.defineProperty(E,"__esModule",{value:!0}),E.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 E.unpackPayload=o,E}var G;function d(){return G||(G=1,function(r){var o=m&&m.__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=m&&m.__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(ee(),r),n(re(),r),n(te(),r),n(p,r),n(ie(),r),n(S,r),n(j,r),n(se(),r),n(oe(),r),n(I,r),n(de(),r),n(le(),r),n(J,r),n(he(),r)}(R)),R}var pe=d(),ve=H();(0,pe.attach)();var ge=ve.Framebus;const v=Z(ge),be={isLoading:!0,invokeAction:async()=>Promise.reject("Action functionality not initialized."),navigate:()=>{}},z=b.createContext(be),ye=()=>b.useContext(z),me=r=>{new v().emit("NAVIGATE",{...r})},_e=(r,o)=>{new v().emit("INVOKE_DEFAULT_ACTION",{actionKey:"showModalDialog",args:[r,o]})},we=(r,o)=>new v().emit("INVOKE_DEFAULT_ACTION",{actionKey:"showConfirmationDialog",args:[r,o]}),Pe=(r,o)=>{new v().emit("INVOKE_DEFAULT_ACTION",{actionKey:"showToast",args:[r,o]})},Ae=(r,o)=>{new v().emit("INVOKE_DEFAULT_ACTION",{actionKey:"showErrorMessage",args:[r,o]})},Oe=({children:r,config:o})=>{const[,n]=b.useState(void 0),[t,e]=b.useState(void 0),[i,s]=b.useState(void 0),[a,u]=b.useState(!0),c=(x,...C)=>new Promise((h,l)=>{new v().emit("INVOKE_ACTION",{actionKey:x,args:C},y=>{y.success?h(y.result):l(new Error(y.error))})}),f=()=>{const x=o;return Array.isArray(x.menu)};b.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 C=new URL(window.location.href).searchParams.get("c"),h=C?new v({channel:C}):new v;return h.emit("REQUEST_DATA",{config:o}),h.on("DATA_RESPONSE",l=>{e(l),u(!1)}),h.on("PARAMS_RESPONSE",l=>{s(l)}),h.on("SET_APP_ID",l=>{const{appId:_}=l;n(_)}),f()&&h.on("NAVIGATE_CHILD",l=>{const{path:_}=l,{navigation:y}=o;if(y){const{navigate:X}=y;X({path:_})}}),()=>{h.teardown()}},[o]);const Q={data:t,params:i,isLoading:a,invokeAction:c,navigate:me,showModalDialog:_e,showConfirmationDialog:we,showToast:Pe,showErrorMessage:Ae};return Y.jsx(z.Provider,{value:Q,children:r})};exports.AppClientProvider=Oe;exports.useAppClient=ye;
|
package/dist/index.js
CHANGED
|
@@ -351,7 +351,7 @@ const v = /* @__PURE__ */ te(me), _e = {
|
|
|
351
351
|
navigate: () => {
|
|
352
352
|
}
|
|
353
353
|
}, z = Z(_e), Fe = () => ee(z), we = (r) => {
|
|
354
|
-
new v().emit("NAVIGATE", {
|
|
354
|
+
new v().emit("NAVIGATE", { ...r });
|
|
355
355
|
}, Pe = (r, o) => {
|
|
356
356
|
new v().emit("INVOKE_DEFAULT_ACTION", {
|
|
357
357
|
actionKey: "showModalDialog",
|
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.5.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.js",
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
"framebus": "^6.0.0",
|
|
14
14
|
"postmate": "^1.5.2",
|
|
15
15
|
"use-immer": "^0.9.0",
|
|
16
|
-
"@akinon/app-shared": "^0.
|
|
16
|
+
"@akinon/app-shared": "^0.4.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/postmate": "^1.5.3",
|
|
20
20
|
"clean-package": "2.2.0",
|
|
21
|
-
"
|
|
21
|
+
"@akinon/vite-config": "^0.1.1",
|
|
22
22
|
"tsconfig": "0.0.0",
|
|
23
|
-
"
|
|
23
|
+
"eslint-config-custom": "0.1.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"react": "18.x",
|