@akinon/app-client 0.3.0 → 0.3.2
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/README.md +68 -0
- package/dist/app-client-provider.d.ts +32 -3
- package/dist/app-client-provider.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +152 -127
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Akinon App Client Library
|
|
2
|
+
|
|
3
|
+
The `app-client` library provides a React context and hooks for integrating micro-frontend applications with the main application shell, enabling actions like navigation, displaying modals, and other inter-app communications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
To add the `app-client` library to your project, run:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm install @akinon/app-client
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
First, wrap your micro-frontend's root component with the `AppClientProvider`:
|
|
16
|
+
|
|
17
|
+
```jsx
|
|
18
|
+
import React from 'react';
|
|
19
|
+
import ReactDOM from 'react-dom';
|
|
20
|
+
import { AppClientProvider } from '@akinon/app-client';
|
|
21
|
+
import App from './App';
|
|
22
|
+
|
|
23
|
+
ReactDOM.render(
|
|
24
|
+
<AppClientProvider config={{ isDev: true }}>
|
|
25
|
+
<App />
|
|
26
|
+
</AppClientProvider>,
|
|
27
|
+
document.getElementById('root')
|
|
28
|
+
);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Then, use the `useAppClient` hook within your components to access client functionalities:
|
|
32
|
+
|
|
33
|
+
```jsx
|
|
34
|
+
import React from 'react';
|
|
35
|
+
import { useAppClient } from '@akinon/app-client';
|
|
36
|
+
|
|
37
|
+
const MyComponent = () => {
|
|
38
|
+
const { navigate } = useAppClient();
|
|
39
|
+
|
|
40
|
+
return <button onClick={() => navigate('/path')}>Go somewhere</button>;
|
|
41
|
+
};
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## API
|
|
45
|
+
|
|
46
|
+
### AppClientProvider
|
|
47
|
+
|
|
48
|
+
Props:
|
|
49
|
+
|
|
50
|
+
- `config`: Configuration for the client application, including isDev and forceRedirect.
|
|
51
|
+
|
|
52
|
+
### `useAppClient` Hook
|
|
53
|
+
|
|
54
|
+
Provides access to:
|
|
55
|
+
|
|
56
|
+
- `navigate(path: string)`: Function to navigate to a different route.
|
|
57
|
+
- `invokeAction(actionKey: string, ...args: any[])`: Invoke a custom action defined in the app shell.
|
|
58
|
+
- Helper functions for showing modals, toasts, and more.
|
|
59
|
+
- `data`: Data shared by host applications.
|
|
60
|
+
|
|
61
|
+
## Configuration
|
|
62
|
+
|
|
63
|
+
The `AppClientProvider` accepts the following configuration options:
|
|
64
|
+
|
|
65
|
+
- `isDev`: Enables development mode.
|
|
66
|
+
- `forceRedirect`: Forces the application to load in an iframe if not already.
|
|
67
|
+
|
|
68
|
+
For more information on configuration and usage, please refer to the detailed documentation.
|
|
@@ -1,17 +1,46 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApplicationData, FullpageApplicationConfig, PluginApplicationConfig, RegisteredApp, RegisteredAppType } from '@akinon/app-shared';
|
|
2
2
|
import React from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Defines the context state for the AppClient, including application data,
|
|
5
|
+
* loading status, and methods for invoking actions and navigating.
|
|
6
|
+
* @typedef {Object} AppClientContextState
|
|
7
|
+
* @property {ApplicationData} [data] - Optional application data shared across micro frontends.
|
|
8
|
+
* @property {boolean} isLoading - Indicates whether the application data is currently loading.
|
|
9
|
+
* @property {Function} invokeAction - Method to invoke an action defined in the AppShell.
|
|
10
|
+
* @property {Function} navigate - Method to navigate to a specified path within the application.
|
|
11
|
+
* Additional helper methods for invoking default actions like showing dialogs or toasts.
|
|
12
|
+
*/
|
|
3
13
|
interface AppClientContextState {
|
|
4
14
|
data?: ApplicationData;
|
|
5
15
|
isLoading: boolean;
|
|
6
16
|
invokeAction: <T = any>(actionKey: string, ...args: any[]) => Promise<T>;
|
|
7
17
|
navigate: (path: string) => void;
|
|
18
|
+
showModalDialog?: (title: string, content: string) => void;
|
|
19
|
+
showConfirmationDialog?: (title: string, content: string) => boolean;
|
|
20
|
+
showToast?: (content: string, type: 'success' | 'warning' | 'error' | 'loading' | 'destroy') => void;
|
|
21
|
+
showErrorMessage?: (title: string, content: string) => void;
|
|
8
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Props for the AppClientProvider component.
|
|
25
|
+
* @typedef {Object} AppClientProviderProps
|
|
26
|
+
* @property {React.ReactNode} children - Children components to be rendered within the provider.
|
|
27
|
+
* @property {ApplicationConfig} config - Configuration for the application, including settings like `isDev` and `forceRedirect`.
|
|
28
|
+
*/
|
|
9
29
|
interface AppClientProviderProps {
|
|
10
30
|
children: React.ReactNode;
|
|
11
|
-
config:
|
|
31
|
+
config: FullpageApplicationConfig | PluginApplicationConfig;
|
|
12
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Custom hook to access the AppClient context.
|
|
35
|
+
* @returns {AppClientContextState} The current context state.
|
|
36
|
+
*/
|
|
13
37
|
declare const useAppClient: () => AppClientContextState;
|
|
38
|
+
/**
|
|
39
|
+
* Component providing the context for AppClient. It initializes communication
|
|
40
|
+
* with the AppShell and provides methods for action invocation and navigation.
|
|
41
|
+
* @param {AppClientProviderProps} props - The props for the AppClientProvider component.
|
|
42
|
+
*/
|
|
14
43
|
declare const AppClientProvider: ({ children, config }: AppClientProviderProps) => React.JSX.Element;
|
|
15
44
|
export { AppClientProvider, useAppClient };
|
|
16
|
-
export type {
|
|
45
|
+
export type { FullpageApplicationConfig, PluginApplicationConfig, RegisteredApp, RegisteredAppType };
|
|
17
46
|
//# 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,
|
|
1
|
+
{"version":3,"file":"app-client-provider.d.ts","sourceRoot":"","sources":["../src/app-client-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAyD,MAAM,OAAO,CAAC;AAE9E;;;;;;;;;GASG;AACH,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;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;AA6ExD;;;;GAIG;AACH,QAAA,MAAM,iBAAiB,yBAA0B,sBAAsB,sBAmEtE,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAC;AAC3C,YAAY,EACV,yBAAyB,EACzB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EAClB,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("react/jsx-runtime"),M=require("react");var p=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function H(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var T={},h={},S;function K(){if(S)return h;S=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 v={},q;function Q(){if(q)return v;q=1,Object.defineProperty(v,"__esModule",{value:!0}),v.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 v.broadcastToChildWindows=o,v}var b={},C;function X(){if(C)return b;C=1,Object.defineProperty(b,"__esModule",{value:!0}),b.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 b.broadcast=o,b}var l={};Object.defineProperty(l,"__esModule",{value:!0});l.subscribers=l.childWindows=l.prefix=void 0;l.prefix="/*framebus*/";l.childWindows=[];l.subscribers={};var g={},R;function Y(){if(R)return g;R=1,Object.defineProperty(g,"__esModule",{value:!0}),g.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 g.dispatch=o,g}var O={};Object.defineProperty(O,"__esModule",{value:!0});O.hasOpener=void 0;function Z(r){return!(r.top!==r||r.opener==null||r.opener===r||r.opener.closed===!0)}O.hasOpener=Z;var F={};Object.defineProperty(F,"__esModule",{value:!0});F.isntString=void 0;function N(r){return typeof r!="string"}F.isntString=N;var y={},E;function ee(){if(E)return y;E=1,Object.defineProperty(y,"__esModule",{value:!0}),y.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 y.onMessage=o,y}var m={},k;function re(){if(k)return m;k=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 x={};Object.defineProperty(x,"__esModule",{value:!0});x.sendMessage=void 0;function te(r,o,n){try{r.postMessage(o,n)}catch{}}x.sendMessage=te;var _={},w={},B;function V(){if(B)return w;B=1,Object.defineProperty(w,"__esModule",{value:!0}),w.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 w.Framebus=n,w}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,I;function ae(){if(I)return _;I=1;var r=p&&p.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(_,"__esModule",{value:!0}),_.subscribeReplier=void 0;var o=V(),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 _.subscribeReplier=t,_}var P={},L;function se(){if(L)return P;L=1,Object.defineProperty(P,"__esModule",{value:!0}),P.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 P.subscriptionArgsInvalid=o,P}var U={};Object.defineProperty(U,"__esModule",{value:!0});var A={},W;function oe(){if(W)return A;W=1,Object.defineProperty(A,"__esModule",{value:!0}),A.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 A.unpackPayload=o,A}var $;function d(){return $||($=1,function(r){var o=p&&p.__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=p&&p.__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(K(),r),n(Q(),r),n(X(),r),n(l,r),n(Y(),r),n(O,r),n(F,r),n(ee(),r),n(re(),r),n(x,r),n(ae(),r),n(se(),r),n(U,r),n(oe(),r)}(T)),T}var ue=d(),ce=V();(0,ue.attach)();var fe=ce.Framebus;const j=H(fe),de={isLoading:!0,invokeAction:async()=>Promise.reject("Action functionality not initialized."),navigate:()=>{}},le=r=>{new j().emit("NAVIGATE",{path:r})},G=M.createContext(de),he=()=>M.useContext(G),pe=({children:r,config:o})=>{const[n,t]=M.useState(void 0),[e,i]=M.useState(!0),s=(u,...c)=>new Promise((f,J)=>{new j().emit("INVOKE_ACTION",{actionKey:u,args:c},D=>{D.success?f(D.result):J(new Error(D.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 j;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};return z.jsx(G.Provider,{value:a,children:r})};exports.AppClientProvider=pe;exports.useAppClient=he;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("react/jsx-runtime"),v=require("react");var b=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function H(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var j={},h={},S;function Q(){if(S)return h;S=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 y={},I;function X(){if(I)return y;I=1,Object.defineProperty(y,"__esModule",{value:!0}),y.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 y.broadcastToChildWindows=o,y}var m={},q;function Y(){if(q)return m;q=1,Object.defineProperty(m,"__esModule",{value:!0}),m.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 m.broadcast=o,m}var l={};Object.defineProperty(l,"__esModule",{value:!0});l.subscribers=l.childWindows=l.prefix=void 0;l.prefix="/*framebus*/";l.childWindows=[];l.subscribers={};var _={},R;function Z(){if(R)return _;R=1,Object.defineProperty(_,"__esModule",{value:!0}),_.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 _.dispatch=o,_}var D={};Object.defineProperty(D,"__esModule",{value:!0});D.hasOpener=void 0;function ee(r){return!(r.top!==r||r.opener==null||r.opener===r||r.opener.closed===!0)}D.hasOpener=ee;var F={};Object.defineProperty(F,"__esModule",{value:!0});F.isntString=void 0;function re(r){return typeof r!="string"}F.isntString=re;var w={},k;function te(){if(k)return w;k=1,Object.defineProperty(w,"__esModule",{value:!0}),w.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 w.onMessage=o,w}var P={},L;function ie(){if(L)return P;L=1,Object.defineProperty(P,"__esModule",{value:!0}),P.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 P.packagePayload=o,P}var x={};Object.defineProperty(x,"__esModule",{value:!0});x.sendMessage=void 0;function ne(r,o,n){try{r.postMessage(o,n)}catch{}}x.sendMessage=ne;var A={},O={},B;function U(){if(B)return O;B=1,Object.defineProperty(O,"__esModule",{value:!0}),O.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(f){(0,r.sendMessage)(f,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 f=s.emit(e,i,function(c){a(c)});f||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 f=[],c=0;c<arguments.length;c++)f[c]=arguments[c];s.passesVerifyDomainCheck(this&&this.origin)&&s.hasMatchingTargetFrame(this&&this.source)&&i.apply(void 0,f)}),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 f=this.origin;if((0,r.subscriptionArgsInvalid)(e,s,f))return!1;var c=r.subscribers[f]&&r.subscribers[f][e];if(!c)return!1;for(var a=0;a<c.length;a++)if(c[a]===s)return c.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 O.Framebus=n,O}function ae(){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 se=ae,W;function oe(){if(W)return A;W=1;var r=b&&b.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(A,"__esModule",{value:!0}),A.subscribeReplier=void 0;var o=U(),n=r(se);function t(e,i){var s=(0,n.default)();function a(u,f){e(u,f),o.Framebus.target({origin:i}).off(s,a)}return o.Framebus.target({origin:i}).on(s,a),s}return A.subscribeReplier=t,A}var M={},$;function ue(){if($)return M;$=1,Object.defineProperty(M,"__esModule",{value:!0}),M.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 M.subscriptionArgsInvalid=o,M}var N={};Object.defineProperty(N,"__esModule",{value:!0});var T={},K;function ce(){if(K)return T;K=1,Object.defineProperty(T,"__esModule",{value:!0}),T.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 f=(0,r.packagePayload)(s,e,u);f&&i.postMessage(f,e)}}}return t}return T.unpackPayload=o,T}var V;function d(){return V||(V=1,function(r){var o=b&&b.__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=b&&b.__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(Q(),r),n(X(),r),n(Y(),r),n(l,r),n(Z(),r),n(D,r),n(F,r),n(te(),r),n(ie(),r),n(x,r),n(oe(),r),n(ue(),r),n(N,r),n(ce(),r)}(j)),j}var fe=d(),de=U();(0,fe.attach)();var le=de.Framebus;const p=H(le),he={isLoading:!0,invokeAction:async()=>Promise.reject("Action functionality not initialized."),navigate:()=>{}},G=v.createContext(he),pe=()=>v.useContext(G),ve=r=>{new p().emit("NAVIGATE",{path:r})},be=(r,o)=>{new p().emit("INVOKE_DEFAULT_ACTION",{actionKey:"showModalDialog",args:[r,o]})},ge=(r,o)=>new p().emit("INVOKE_DEFAULT_ACTION",{actionKey:"showConfirmationDialog",args:[r,o]}),ye=(r,o)=>{new p().emit("INVOKE_DEFAULT_ACTION",{actionKey:"showToast",args:[r,o]})},me=(r,o)=>{new p().emit("INVOKE_DEFAULT_ACTION",{actionKey:"showErrorMessage",args:[r,o]})},_e=({children:r,config:o})=>{const[n,t]=v.useState(void 0),[e,i]=v.useState(void 0),[s,a]=v.useState(!0),u=(c,...g)=>new Promise((E,J)=>{new p().emit("INVOKE_ACTION",{actionKey:c,args:g},C=>{C.success?E(C.result):J(new Error(C.error))})});v.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 p;return c.emit("REQUEST_DATA",{config:o}),c.on("DATA_RESPONSE",g=>{i(g),a(!1)}),c.on("SET_APP_ID",g=>{const{appId:E}=g;t(E)}),()=>{c.teardown()}},[o]);const f={data:e,isLoading:s,invokeAction:u,navigate:ve,showModalDialog:be,showConfirmationDialog:ge,showToast:ye,showErrorMessage:me};return z.jsx(G.Provider,{value:f,children:r})};exports.AppClientProvider=_e;exports.useAppClient=pe;
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { jsx as z } from "react/jsx-runtime";
|
|
2
|
-
import { createContext as H, useContext as
|
|
3
|
-
var
|
|
4
|
-
function
|
|
2
|
+
import { createContext as H, useContext as Q, useState as C, useEffect as X } from "react";
|
|
3
|
+
var v = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
|
|
4
|
+
function Y(r) {
|
|
5
5
|
return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
|
|
6
6
|
}
|
|
7
|
-
var
|
|
8
|
-
function
|
|
9
|
-
if (
|
|
7
|
+
var I = {}, h = {}, j;
|
|
8
|
+
function Z() {
|
|
9
|
+
if (j)
|
|
10
10
|
return h;
|
|
11
|
-
|
|
11
|
+
j = 1, Object.defineProperty(h, "__esModule", { value: !0 }), h.detach = h.attach = void 0;
|
|
12
12
|
var r = d(), o = !1;
|
|
13
13
|
function n() {
|
|
14
14
|
o || typeof window > "u" || (o = !0, window.addEventListener("message", r.onMessage, !1));
|
|
@@ -19,11 +19,11 @@ function Y() {
|
|
|
19
19
|
}
|
|
20
20
|
return h.detach = t, h;
|
|
21
21
|
}
|
|
22
|
-
var
|
|
23
|
-
function
|
|
24
|
-
if (
|
|
25
|
-
return
|
|
26
|
-
|
|
22
|
+
var g = {}, S;
|
|
23
|
+
function ee() {
|
|
24
|
+
if (S)
|
|
25
|
+
return g;
|
|
26
|
+
S = 1, Object.defineProperty(g, "__esModule", { value: !0 }), g.broadcastToChildWindows = void 0;
|
|
27
27
|
var r = d();
|
|
28
28
|
function o(n, t, e) {
|
|
29
29
|
for (var i = r.childWindows.length - 1; i >= 0; i--) {
|
|
@@ -34,13 +34,13 @@ function Z() {
|
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
return
|
|
37
|
+
return g.broadcastToChildWindows = o, g;
|
|
38
38
|
}
|
|
39
|
-
var
|
|
40
|
-
function
|
|
41
|
-
if (
|
|
42
|
-
return
|
|
43
|
-
|
|
39
|
+
var y = {}, q;
|
|
40
|
+
function re() {
|
|
41
|
+
if (q)
|
|
42
|
+
return y;
|
|
43
|
+
q = 1, Object.defineProperty(y, "__esModule", { value: !0 }), y.broadcast = void 0;
|
|
44
44
|
var r = d();
|
|
45
45
|
function o(n, t) {
|
|
46
46
|
var e = 0, i, s = t.origin, a = t.frame;
|
|
@@ -56,7 +56,7 @@ function N() {
|
|
|
56
56
|
} catch {
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
return
|
|
59
|
+
return y.broadcast = o, y;
|
|
60
60
|
}
|
|
61
61
|
var l = {};
|
|
62
62
|
Object.defineProperty(l, "__esModule", { value: !0 });
|
|
@@ -64,11 +64,11 @@ l.subscribers = l.childWindows = l.prefix = void 0;
|
|
|
64
64
|
l.prefix = "/*framebus*/";
|
|
65
65
|
l.childWindows = [];
|
|
66
66
|
l.subscribers = {};
|
|
67
|
-
var
|
|
68
|
-
function
|
|
69
|
-
if (
|
|
70
|
-
return
|
|
71
|
-
|
|
67
|
+
var m = {}, R;
|
|
68
|
+
function te() {
|
|
69
|
+
if (R)
|
|
70
|
+
return m;
|
|
71
|
+
R = 1, Object.defineProperty(m, "__esModule", { value: !0 }), m.dispatch = void 0;
|
|
72
72
|
var r = d();
|
|
73
73
|
function o(n, t, e, i, s) {
|
|
74
74
|
if (r.subscribers[n] && r.subscribers[n][t]) {
|
|
@@ -78,27 +78,27 @@ function ee() {
|
|
|
78
78
|
r.subscribers[n][t][u].apply(s, a);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
return
|
|
81
|
+
return m.dispatch = o, m;
|
|
82
82
|
}
|
|
83
|
-
var
|
|
84
|
-
Object.defineProperty(
|
|
85
|
-
|
|
86
|
-
function
|
|
83
|
+
var T = {};
|
|
84
|
+
Object.defineProperty(T, "__esModule", { value: !0 });
|
|
85
|
+
T.hasOpener = void 0;
|
|
86
|
+
function ie(r) {
|
|
87
87
|
return !(r.top !== r || r.opener == null || r.opener === r || r.opener.closed === !0);
|
|
88
88
|
}
|
|
89
|
-
|
|
90
|
-
var
|
|
91
|
-
Object.defineProperty(
|
|
92
|
-
|
|
93
|
-
function
|
|
89
|
+
T.hasOpener = ie;
|
|
90
|
+
var D = {};
|
|
91
|
+
Object.defineProperty(D, "__esModule", { value: !0 });
|
|
92
|
+
D.isntString = void 0;
|
|
93
|
+
function ne(r) {
|
|
94
94
|
return typeof r != "string";
|
|
95
95
|
}
|
|
96
|
-
|
|
97
|
-
var
|
|
98
|
-
function
|
|
99
|
-
if (
|
|
100
|
-
return
|
|
101
|
-
|
|
96
|
+
D.isntString = ne;
|
|
97
|
+
var _ = {}, k;
|
|
98
|
+
function ae() {
|
|
99
|
+
if (k)
|
|
100
|
+
return _;
|
|
101
|
+
k = 1, Object.defineProperty(_, "__esModule", { value: !0 }), _.onMessage = void 0;
|
|
102
102
|
var r = d();
|
|
103
103
|
function o(n) {
|
|
104
104
|
if (!(0, r.isntString)(n.data)) {
|
|
@@ -109,13 +109,13 @@ function ie() {
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
return
|
|
112
|
+
return _.onMessage = o, _;
|
|
113
113
|
}
|
|
114
|
-
var
|
|
115
|
-
function
|
|
116
|
-
if (
|
|
117
|
-
return
|
|
118
|
-
|
|
114
|
+
var w = {}, L;
|
|
115
|
+
function se() {
|
|
116
|
+
if (L)
|
|
117
|
+
return w;
|
|
118
|
+
L = 1, Object.defineProperty(w, "__esModule", { value: !0 }), w.packagePayload = void 0;
|
|
119
119
|
var r = d();
|
|
120
120
|
function o(n, t, e, i) {
|
|
121
121
|
var s, a = {
|
|
@@ -130,23 +130,23 @@ function ne() {
|
|
|
130
130
|
}
|
|
131
131
|
return s;
|
|
132
132
|
}
|
|
133
|
-
return
|
|
133
|
+
return w.packagePayload = o, w;
|
|
134
134
|
}
|
|
135
135
|
var F = {};
|
|
136
136
|
Object.defineProperty(F, "__esModule", { value: !0 });
|
|
137
137
|
F.sendMessage = void 0;
|
|
138
|
-
function
|
|
138
|
+
function oe(r, o, n) {
|
|
139
139
|
try {
|
|
140
140
|
r.postMessage(o, n);
|
|
141
141
|
} catch {
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
F.sendMessage =
|
|
145
|
-
var
|
|
146
|
-
function
|
|
144
|
+
F.sendMessage = oe;
|
|
145
|
+
var P = {}, A = {}, B;
|
|
146
|
+
function U() {
|
|
147
147
|
if (B)
|
|
148
|
-
return
|
|
149
|
-
B = 1, Object.defineProperty(
|
|
148
|
+
return A;
|
|
149
|
+
B = 1, Object.defineProperty(A, "__esModule", { value: !0 }), A.Framebus = void 0;
|
|
150
150
|
var r = d(), o = typeof window < "u" && window.Promise, n = (
|
|
151
151
|
/** @class */
|
|
152
152
|
function() {
|
|
@@ -171,8 +171,8 @@ function V() {
|
|
|
171
171
|
return !1;
|
|
172
172
|
typeof i == "function" && (s = i, i = void 0);
|
|
173
173
|
var u = (0, r.packagePayload)(e, a, i, s);
|
|
174
|
-
return u ? (this.limitBroadcastToFramesArray ? this.targetFramesAsWindows().forEach(function(
|
|
175
|
-
(0, r.sendMessage)(
|
|
174
|
+
return u ? (this.limitBroadcastToFramesArray ? this.targetFramesAsWindows().forEach(function(f) {
|
|
175
|
+
(0, r.sendMessage)(f, u, a);
|
|
176
176
|
}) : (0, r.broadcast)(u, {
|
|
177
177
|
origin: a,
|
|
178
178
|
frame: window.top || window.self
|
|
@@ -180,19 +180,19 @@ function V() {
|
|
|
180
180
|
}, t.prototype.emitAsPromise = function(e, i) {
|
|
181
181
|
var s = this;
|
|
182
182
|
return new t.Promise(function(a, u) {
|
|
183
|
-
var
|
|
184
|
-
a(
|
|
183
|
+
var f = s.emit(e, i, function(c) {
|
|
184
|
+
a(c);
|
|
185
185
|
});
|
|
186
|
-
|
|
186
|
+
f || u(new Error('Listener not added for "'.concat(e, '"')));
|
|
187
187
|
});
|
|
188
188
|
}, t.prototype.on = function(e, i) {
|
|
189
189
|
if (this.isDestroyed)
|
|
190
190
|
return !1;
|
|
191
191
|
var s = this, a = this.origin, u = i;
|
|
192
192
|
return e = this.namespaceEvent(e), (0, r.subscriptionArgsInvalid)(e, u, a) ? !1 : (this.hasAdditionalChecksForOnListeners && (u = function() {
|
|
193
|
-
for (var
|
|
194
|
-
c
|
|
195
|
-
s.passesVerifyDomainCheck(this && this.origin) && s.hasMatchingTargetFrame(this && this.source) && i.apply(void 0,
|
|
193
|
+
for (var f = [], c = 0; c < arguments.length; c++)
|
|
194
|
+
f[c] = arguments[c];
|
|
195
|
+
s.passesVerifyDomainCheck(this && this.origin) && s.hasMatchingTargetFrame(this && this.source) && i.apply(void 0, f);
|
|
196
196
|
}), this.listeners.push({
|
|
197
197
|
eventName: e,
|
|
198
198
|
handler: u,
|
|
@@ -208,15 +208,15 @@ function V() {
|
|
|
208
208
|
u.originalHandler === i && (s = u.handler);
|
|
209
209
|
}
|
|
210
210
|
e = this.namespaceEvent(e);
|
|
211
|
-
var
|
|
212
|
-
if ((0, r.subscriptionArgsInvalid)(e, s,
|
|
211
|
+
var f = this.origin;
|
|
212
|
+
if ((0, r.subscriptionArgsInvalid)(e, s, f))
|
|
213
213
|
return !1;
|
|
214
|
-
var
|
|
215
|
-
if (!
|
|
214
|
+
var c = r.subscribers[f] && r.subscribers[f][e];
|
|
215
|
+
if (!c)
|
|
216
216
|
return !1;
|
|
217
|
-
for (var a = 0; a <
|
|
218
|
-
if (
|
|
219
|
-
return
|
|
217
|
+
for (var a = 0; a < c.length; a++)
|
|
218
|
+
if (c[a] === s)
|
|
219
|
+
return c.splice(a, 1), !0;
|
|
220
220
|
return !1;
|
|
221
221
|
}, t.prototype.teardown = function() {
|
|
222
222
|
if (!this.isDestroyed) {
|
|
@@ -252,28 +252,28 @@ function V() {
|
|
|
252
252
|
}, t.Promise = o, t;
|
|
253
253
|
}()
|
|
254
254
|
);
|
|
255
|
-
return
|
|
255
|
+
return A.Framebus = n, A;
|
|
256
256
|
}
|
|
257
|
-
function
|
|
257
|
+
function ue() {
|
|
258
258
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(r) {
|
|
259
259
|
var o = Math.random() * 16 | 0, n = r === "x" ? o : o & 3 | 8;
|
|
260
260
|
return n.toString(16);
|
|
261
261
|
});
|
|
262
262
|
}
|
|
263
|
-
var
|
|
264
|
-
function
|
|
265
|
-
if (
|
|
266
|
-
return
|
|
267
|
-
|
|
268
|
-
var r =
|
|
263
|
+
var ce = ue, W;
|
|
264
|
+
function fe() {
|
|
265
|
+
if (W)
|
|
266
|
+
return P;
|
|
267
|
+
W = 1;
|
|
268
|
+
var r = v && v.__importDefault || function(e) {
|
|
269
269
|
return e && e.__esModule ? e : { default: e };
|
|
270
270
|
};
|
|
271
|
-
Object.defineProperty(
|
|
272
|
-
var o =
|
|
271
|
+
Object.defineProperty(P, "__esModule", { value: !0 }), P.subscribeReplier = void 0;
|
|
272
|
+
var o = U(), n = r(ce);
|
|
273
273
|
function t(e, i) {
|
|
274
274
|
var s = (0, n.default)();
|
|
275
|
-
function a(u,
|
|
276
|
-
e(u,
|
|
275
|
+
function a(u, f) {
|
|
276
|
+
e(u, f), o.Framebus.target({
|
|
277
277
|
origin: i
|
|
278
278
|
}).off(s, a);
|
|
279
279
|
}
|
|
@@ -281,26 +281,26 @@ function ue() {
|
|
|
281
281
|
origin: i
|
|
282
282
|
}).on(s, a), s;
|
|
283
283
|
}
|
|
284
|
-
return
|
|
284
|
+
return P.subscribeReplier = t, P;
|
|
285
285
|
}
|
|
286
|
-
var
|
|
287
|
-
function
|
|
288
|
-
if (
|
|
289
|
-
return
|
|
290
|
-
|
|
286
|
+
var O = {}, $;
|
|
287
|
+
function de() {
|
|
288
|
+
if ($)
|
|
289
|
+
return O;
|
|
290
|
+
$ = 1, Object.defineProperty(O, "__esModule", { value: !0 }), O.subscriptionArgsInvalid = void 0;
|
|
291
291
|
var r = d();
|
|
292
292
|
function o(n, t, e) {
|
|
293
293
|
return (0, r.isntString)(n) || typeof t != "function" ? !0 : (0, r.isntString)(e);
|
|
294
294
|
}
|
|
295
|
-
return
|
|
295
|
+
return O.subscriptionArgsInvalid = o, O;
|
|
296
296
|
}
|
|
297
|
-
var
|
|
298
|
-
Object.defineProperty(
|
|
299
|
-
var
|
|
300
|
-
function
|
|
301
|
-
if (
|
|
302
|
-
return
|
|
303
|
-
|
|
297
|
+
var N = {};
|
|
298
|
+
Object.defineProperty(N, "__esModule", { value: !0 });
|
|
299
|
+
var M = {}, K;
|
|
300
|
+
function le() {
|
|
301
|
+
if (K)
|
|
302
|
+
return M;
|
|
303
|
+
K = 1, Object.defineProperty(M, "__esModule", { value: !0 }), M.unpackPayload = void 0;
|
|
304
304
|
var r = d();
|
|
305
305
|
function o(n) {
|
|
306
306
|
var t;
|
|
@@ -315,19 +315,19 @@ function fe() {
|
|
|
315
315
|
var e = n.origin, i = n.source, s = t.reply;
|
|
316
316
|
t.reply = function(u) {
|
|
317
317
|
if (i) {
|
|
318
|
-
var
|
|
319
|
-
|
|
318
|
+
var f = (0, r.packagePayload)(s, e, u);
|
|
319
|
+
f && i.postMessage(f, e);
|
|
320
320
|
}
|
|
321
321
|
};
|
|
322
322
|
}
|
|
323
323
|
return t;
|
|
324
324
|
}
|
|
325
|
-
return
|
|
325
|
+
return M.unpackPayload = o, M;
|
|
326
326
|
}
|
|
327
|
-
var
|
|
327
|
+
var V;
|
|
328
328
|
function d() {
|
|
329
|
-
return
|
|
330
|
-
var o =
|
|
329
|
+
return V || (V = 1, function(r) {
|
|
330
|
+
var o = v && v.__createBinding || (Object.create ? function(t, e, i, s) {
|
|
331
331
|
s === void 0 && (s = i);
|
|
332
332
|
var a = Object.getOwnPropertyDescriptor(e, i);
|
|
333
333
|
(!a || ("get" in a ? !e.__esModule : a.writable || a.configurable)) && (a = { enumerable: !0, get: function() {
|
|
@@ -335,52 +335,77 @@ function d() {
|
|
|
335
335
|
} }), Object.defineProperty(t, s, a);
|
|
336
336
|
} : function(t, e, i, s) {
|
|
337
337
|
s === void 0 && (s = i), t[s] = e[i];
|
|
338
|
-
}), n =
|
|
338
|
+
}), n = v && v.__exportStar || function(t, e) {
|
|
339
339
|
for (var i in t)
|
|
340
340
|
i !== "default" && !Object.prototype.hasOwnProperty.call(e, i) && o(e, t, i);
|
|
341
341
|
};
|
|
342
|
-
Object.defineProperty(r, "__esModule", { value: !0 }), n(
|
|
343
|
-
}(
|
|
342
|
+
Object.defineProperty(r, "__esModule", { value: !0 }), n(Z(), r), n(ee(), r), n(re(), r), n(l, r), n(te(), r), n(T, r), n(D, r), n(ae(), r), n(se(), r), n(F, r), n(fe(), r), n(de(), r), n(N, r), n(le(), r);
|
|
343
|
+
}(I)), I;
|
|
344
344
|
}
|
|
345
|
-
var
|
|
346
|
-
(0,
|
|
347
|
-
var
|
|
348
|
-
const
|
|
345
|
+
var he = d(), pe = U();
|
|
346
|
+
(0, he.attach)();
|
|
347
|
+
var ve = pe.Framebus;
|
|
348
|
+
const p = /* @__PURE__ */ Y(ve), be = {
|
|
349
349
|
isLoading: !0,
|
|
350
350
|
invokeAction: async () => Promise.reject("Action functionality not initialized."),
|
|
351
351
|
navigate: () => {
|
|
352
352
|
}
|
|
353
|
-
},
|
|
354
|
-
new
|
|
355
|
-
},
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
353
|
+
}, G = H(be), Me = () => Q(G), ge = (r) => {
|
|
354
|
+
new p().emit("NAVIGATE", { path: r });
|
|
355
|
+
}, ye = (r, o) => {
|
|
356
|
+
new p().emit("INVOKE_DEFAULT_ACTION", {
|
|
357
|
+
actionKey: "showModalDialog",
|
|
358
|
+
args: [r, o]
|
|
359
|
+
});
|
|
360
|
+
}, me = (r, o) => new p().emit("INVOKE_DEFAULT_ACTION", {
|
|
361
|
+
actionKey: "showConfirmationDialog",
|
|
362
|
+
args: [r, o]
|
|
363
|
+
}), _e = (r, o) => {
|
|
364
|
+
new p().emit("INVOKE_DEFAULT_ACTION", {
|
|
365
|
+
actionKey: "showToast",
|
|
366
|
+
args: [r, o]
|
|
367
|
+
});
|
|
368
|
+
}, we = (r, o) => {
|
|
369
|
+
new p().emit("INVOKE_DEFAULT_ACTION", {
|
|
370
|
+
actionKey: "showErrorMessage",
|
|
371
|
+
args: [r, o]
|
|
372
|
+
});
|
|
373
|
+
}, Te = ({ children: r, config: o }) => {
|
|
374
|
+
const [n, t] = C(void 0), [e, i] = C(void 0), [s, a] = C(!0), u = (c, ...b) => new Promise((x, J) => {
|
|
375
|
+
new p().emit("INVOKE_ACTION", { actionKey: c, args: b }, (E) => {
|
|
376
|
+
E.success ? x(E.result) : J(new Error(E.error));
|
|
359
377
|
});
|
|
360
378
|
});
|
|
361
|
-
|
|
379
|
+
X(() => {
|
|
362
380
|
if (o.forceRedirect && !o.isDev && window.self === window.top) {
|
|
363
381
|
console.error(
|
|
364
382
|
"This app must be run inside an iframe when forceRedirect is true."
|
|
365
383
|
);
|
|
366
384
|
return;
|
|
367
385
|
}
|
|
368
|
-
const
|
|
369
|
-
return
|
|
370
|
-
|
|
371
|
-
}),
|
|
372
|
-
|
|
386
|
+
const c = new p();
|
|
387
|
+
return c.emit("REQUEST_DATA", { config: o }), c.on("DATA_RESPONSE", (b) => {
|
|
388
|
+
i(b), a(!1);
|
|
389
|
+
}), c.on("SET_APP_ID", (b) => {
|
|
390
|
+
const { appId: x } = b;
|
|
391
|
+
t(x);
|
|
392
|
+
}), () => {
|
|
393
|
+
c.teardown();
|
|
373
394
|
};
|
|
374
395
|
}, [o]);
|
|
375
|
-
const
|
|
376
|
-
data:
|
|
377
|
-
isLoading:
|
|
378
|
-
invokeAction:
|
|
379
|
-
navigate:
|
|
396
|
+
const f = {
|
|
397
|
+
data: e,
|
|
398
|
+
isLoading: s,
|
|
399
|
+
invokeAction: u,
|
|
400
|
+
navigate: ge,
|
|
401
|
+
showModalDialog: ye,
|
|
402
|
+
showConfirmationDialog: me,
|
|
403
|
+
showToast: _e,
|
|
404
|
+
showErrorMessage: we
|
|
380
405
|
};
|
|
381
|
-
return /* @__PURE__ */ z(G.Provider, { value:
|
|
406
|
+
return /* @__PURE__ */ z(G.Provider, { value: f, children: r });
|
|
382
407
|
};
|
|
383
408
|
export {
|
|
384
|
-
|
|
385
|
-
|
|
409
|
+
Te as AppClientProvider,
|
|
410
|
+
Me as useAppClient
|
|
386
411
|
};
|
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.3.
|
|
4
|
+
"version": "0.3.2",
|
|
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.2.
|
|
16
|
+
"@akinon/app-shared": "^0.2.2"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/postmate": "^1.5.3",
|
|
20
20
|
"clean-package": "2.2.0",
|
|
21
|
+
"eslint-config-custom": "0.1.0",
|
|
21
22
|
"@akinon/vite-config": "^0.1.1",
|
|
22
|
-
"tsconfig": "0.0.0"
|
|
23
|
-
"eslint-config-custom": "0.1.0"
|
|
23
|
+
"tsconfig": "0.0.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"react": "18.x",
|