@akinon/app-client 0.5.1 → 0.6.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.
- package/dist/{app-client-provider.d.ts → cjs/app-client-provider.d.ts} +4 -0
- package/dist/cjs/app-client-provider.d.ts.map +1 -0
- package/dist/cjs/app-client-provider.js +189 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +17 -0
- package/dist/esm/app-client-provider.d.ts +52 -0
- package/dist/esm/app-client-provider.d.ts.map +1 -0
- package/dist/esm/app-client-provider.js +185 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +1 -0
- package/package.json +22 -20
- package/dist/app-client-provider.d.ts.map +0 -1
- package/dist/index.cjs +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -429
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
|
@@ -3,6 +3,7 @@ import React from 'react';
|
|
|
3
3
|
/**
|
|
4
4
|
* Defines the context state for the AppClient, including application data,
|
|
5
5
|
* loading status, and methods for invoking actions and navigating.
|
|
6
|
+
*
|
|
6
7
|
* @typedef {Object} AppClientContextState
|
|
7
8
|
* @property {ApplicationData} [data] - Optional application data shared across micro frontends.
|
|
8
9
|
* @property {ApplicationParams} [params] - Optional. Additional parameters to be passed to the application.
|
|
@@ -24,6 +25,7 @@ interface AppClientContextState {
|
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
26
27
|
* Props for the AppClientProvider component.
|
|
28
|
+
*
|
|
27
29
|
* @typedef {Object} AppClientProviderProps
|
|
28
30
|
* @property {React.ReactNode} children - Children components to be rendered within the provider.
|
|
29
31
|
* @property {ApplicationConfig} config - Configuration for the application, including settings like `isDev` and `forceRedirect`.
|
|
@@ -34,12 +36,14 @@ interface AppClientProviderProps {
|
|
|
34
36
|
}
|
|
35
37
|
/**
|
|
36
38
|
* Custom hook to access the AppClient context.
|
|
39
|
+
*
|
|
37
40
|
* @returns {AppClientContextState} The current context state.
|
|
38
41
|
*/
|
|
39
42
|
declare const useAppClient: () => AppClientContextState;
|
|
40
43
|
/**
|
|
41
44
|
* Component providing the context for AppClient. It initializes communication
|
|
42
45
|
* with the AppShell and provides methods for action invocation and navigation.
|
|
46
|
+
*
|
|
43
47
|
* @param {AppClientProviderProps} props - The props for the AppClientProvider component.
|
|
44
48
|
*/
|
|
45
49
|
declare const AppClientProvider: ({ children, config }: AppClientProviderProps) => React.JSX.Element;
|
|
@@ -0,0 +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,EAGjB,yBAAyB,EACzB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAyD,MAAM,OAAO,CAAC;AAE9E;;;;;;;;;;;GAWG;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;;;;;;GAMG;AACH,UAAU,sBAAsB;IAC9B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,MAAM,EAAE,yBAAyB,GAAG,uBAAuB,CAAC;CAC7D;AAaD;;;;GAIG;AACH,QAAA,MAAM,YAAY,6BAAqC,CAAC;AA6ExD;;;;;GAKG;AACH,QAAA,MAAM,iBAAiB,yBAA0B,sBAAsB,sBA4GtE,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"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.useAppClient = exports.AppClientProvider = void 0;
|
|
13
|
+
const app_shared_1 = require("@akinon/app-shared");
|
|
14
|
+
const framebus_1 = require("framebus");
|
|
15
|
+
const react_1 = require("react");
|
|
16
|
+
const defaultContextState = {
|
|
17
|
+
isLoading: true,
|
|
18
|
+
invokeAction: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
return Promise.reject('Action functionality not initialized.');
|
|
20
|
+
}),
|
|
21
|
+
navigate: () => { }
|
|
22
|
+
};
|
|
23
|
+
const AppClientContext = (0, react_1.createContext)(defaultContextState);
|
|
24
|
+
/**
|
|
25
|
+
* Custom hook to access the AppClient context.
|
|
26
|
+
*
|
|
27
|
+
* @returns {AppClientContextState} The current context state.
|
|
28
|
+
*/
|
|
29
|
+
const useAppClient = () => (0, react_1.useContext)(AppClientContext);
|
|
30
|
+
exports.useAppClient = useAppClient;
|
|
31
|
+
/**
|
|
32
|
+
* This method communicates with the AppShell to perform
|
|
33
|
+
* the navigation on the shell.
|
|
34
|
+
*
|
|
35
|
+
* @param {string} path - The path to navigate to.
|
|
36
|
+
*/
|
|
37
|
+
const navigate = (payload) => {
|
|
38
|
+
const bus = new framebus_1.default();
|
|
39
|
+
bus.emit(app_shared_1.EVENTS.NAVIGATE, Object.assign({}, payload));
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Shows a modal dialog with the specified title and content. This method communicates
|
|
43
|
+
* with the AppShell to display the modal dialog.
|
|
44
|
+
*
|
|
45
|
+
* @param {string} title - The title of the modal dialog.
|
|
46
|
+
* @param {string} content - The content of the modal dialog.
|
|
47
|
+
*/
|
|
48
|
+
const showModalDialog = (title, content) => {
|
|
49
|
+
const bus = new framebus_1.default();
|
|
50
|
+
bus.emit(app_shared_1.EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
51
|
+
actionKey: app_shared_1.DEFAULT_ACTION_KEYS.showModalDialog,
|
|
52
|
+
args: [title, content]
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Shows a confirmation dialog with the specified title and content. This method communicates
|
|
57
|
+
* with the AppShell to display the confirmation dialog and waits for user input.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} title - The title of the confirmation dialog.
|
|
60
|
+
* @param {string} content - The content of the confirmation dialog.
|
|
61
|
+
* @returns The result of the confirmation dialog action.
|
|
62
|
+
*/
|
|
63
|
+
const showConfirmationDialog = (title, content) => {
|
|
64
|
+
const bus = new framebus_1.default();
|
|
65
|
+
return bus.emit(app_shared_1.EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
66
|
+
actionKey: app_shared_1.DEFAULT_ACTION_KEYS.showConfirmationDialog,
|
|
67
|
+
args: [title, content]
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Displays a toast message with the specified content and type. This method communicates
|
|
72
|
+
* with the AppShell to display the toast message.
|
|
73
|
+
*
|
|
74
|
+
* @param {string} content - The content of the toast message.
|
|
75
|
+
* @param {'success' | 'warning' | 'error' | 'loading' | 'destroy'} type - The type of the toast message.
|
|
76
|
+
*/
|
|
77
|
+
const showToast = (content, type) => {
|
|
78
|
+
const bus = new framebus_1.default();
|
|
79
|
+
bus.emit(app_shared_1.EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
80
|
+
actionKey: app_shared_1.DEFAULT_ACTION_KEYS.showToast,
|
|
81
|
+
args: [content, type]
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Displays an error message dialog with the specified title and content.
|
|
86
|
+
* This method communicateswith the AppShell to display the error message.
|
|
87
|
+
*
|
|
88
|
+
* @param {string} title - The title of the error message dialog.
|
|
89
|
+
* @param {string} content - The content of the error message dialog.
|
|
90
|
+
*/
|
|
91
|
+
const showErrorMessage = (title, content) => {
|
|
92
|
+
const bus = new framebus_1.default();
|
|
93
|
+
bus.emit(app_shared_1.EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
94
|
+
actionKey: app_shared_1.DEFAULT_ACTION_KEYS.showErrorMessage,
|
|
95
|
+
args: [title, content]
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Component providing the context for AppClient. It initializes communication
|
|
100
|
+
* with the AppShell and provides methods for action invocation and navigation.
|
|
101
|
+
*
|
|
102
|
+
* @param {AppClientProviderProps} props - The props for the AppClientProvider component.
|
|
103
|
+
*/
|
|
104
|
+
const AppClientProvider = ({ children, config }) => {
|
|
105
|
+
const [, setAppId] = (0, react_1.useState)(undefined);
|
|
106
|
+
const [data, setData] = (0, react_1.useState)(undefined);
|
|
107
|
+
const [params, setParams] = (0, react_1.useState)(undefined);
|
|
108
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
109
|
+
// Function to invoke an action in the AppShell
|
|
110
|
+
const invokeAction = (actionKey, ...args) => {
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
const bus = new framebus_1.default();
|
|
113
|
+
bus.emit(app_shared_1.EVENTS.INVOKE_ACTION, { actionKey, args }, (response) => {
|
|
114
|
+
if (response.success) {
|
|
115
|
+
resolve(response.result);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
reject(new Error(response.error));
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
const isFullPageApplication = () => {
|
|
124
|
+
const castedConfig = config;
|
|
125
|
+
return Array.isArray(castedConfig.menu);
|
|
126
|
+
};
|
|
127
|
+
(0, react_1.useEffect)(() => {
|
|
128
|
+
// In production, enforce running in an iframe if forceRedirect is true
|
|
129
|
+
if (config.forceRedirect && !config.isDev && window.self === window.top) {
|
|
130
|
+
console.error('This app must be run inside an iframe when forceRedirect is true.');
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
// Get c from the url of the iframe containing the application.
|
|
134
|
+
const url = new URL(window.location.href);
|
|
135
|
+
const channel = url.searchParams.get('c');
|
|
136
|
+
const bus = channel ? new framebus_1.default({ channel }) : new framebus_1.default();
|
|
137
|
+
// Send data from the AppShell upon initialization.
|
|
138
|
+
// Pass apps config data.
|
|
139
|
+
bus.emit(app_shared_1.EVENTS.SET_CONFIG, { config });
|
|
140
|
+
bus.on(app_shared_1.EVENTS.SET_DATA, (receivedData) => {
|
|
141
|
+
setData(receivedData);
|
|
142
|
+
setIsLoading(false);
|
|
143
|
+
});
|
|
144
|
+
bus.on(app_shared_1.EVENTS.SET_PARAMS, message => {
|
|
145
|
+
const passedParams = message;
|
|
146
|
+
setParams(passedParams);
|
|
147
|
+
});
|
|
148
|
+
bus.on(app_shared_1.EVENTS.SET_APP_ID, data => {
|
|
149
|
+
const { appId } = data;
|
|
150
|
+
setAppId(appId);
|
|
151
|
+
});
|
|
152
|
+
if (!isFullPageApplication()) {
|
|
153
|
+
// Get computed height of iframe element.
|
|
154
|
+
const height = document.getElementsByTagName('html')[0].offsetHeight;
|
|
155
|
+
if (height > 0 && window.name) {
|
|
156
|
+
bus.emit(app_shared_1.EVENTS.SET_HEIGHT, { height, id: window.name });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// Only listen to navigation events if application type is
|
|
160
|
+
// fullpage. plugin type apps should not have the ability to navigate.
|
|
161
|
+
if (isFullPageApplication()) {
|
|
162
|
+
// Listen for navigation events.
|
|
163
|
+
bus.on(app_shared_1.EVENTS.NAVIGATE_CHILD, message => {
|
|
164
|
+
const { path } = message;
|
|
165
|
+
const { navigation } = config;
|
|
166
|
+
if (navigation) {
|
|
167
|
+
const { navigate } = navigation;
|
|
168
|
+
navigate({ path });
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return () => {
|
|
173
|
+
bus.teardown();
|
|
174
|
+
};
|
|
175
|
+
}, [config]);
|
|
176
|
+
const contextValue = {
|
|
177
|
+
data,
|
|
178
|
+
params,
|
|
179
|
+
isLoading,
|
|
180
|
+
invokeAction,
|
|
181
|
+
navigate,
|
|
182
|
+
showModalDialog,
|
|
183
|
+
showConfirmationDialog,
|
|
184
|
+
showToast,
|
|
185
|
+
showErrorMessage
|
|
186
|
+
};
|
|
187
|
+
return (react_1.default.createElement(AppClientContext.Provider, { value: contextValue }, children));
|
|
188
|
+
};
|
|
189
|
+
exports.AppClientProvider = AppClientProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./app-client-provider"), exports);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ApplicationData, ApplicationNavigation, ApplicationParams, FullpageApplicationConfig, PluginApplicationConfig, RegisteredApp, RegisteredAppType, ShellNavigation, ShellNavigationPayload } from '@akinon/app-shared';
|
|
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
|
+
*
|
|
7
|
+
* @typedef {Object} AppClientContextState
|
|
8
|
+
* @property {ApplicationData} [data] - Optional application data shared across micro frontends.
|
|
9
|
+
* @property {ApplicationParams} [params] - Optional. Additional parameters to be passed to the application.
|
|
10
|
+
* @property {boolean} isLoading - Indicates whether the application data is currently loading.
|
|
11
|
+
* @property {Function} invokeAction - Method to invoke an action defined in the AppShell.
|
|
12
|
+
* @property {Function} navigate - Method to navigate to a specified path within the application.
|
|
13
|
+
* Additional helper methods for invoking default actions like showing dialogs or toasts.
|
|
14
|
+
*/
|
|
15
|
+
interface AppClientContextState {
|
|
16
|
+
data?: ApplicationData;
|
|
17
|
+
params?: ApplicationParams;
|
|
18
|
+
isLoading: boolean;
|
|
19
|
+
invokeAction: <T = any>(actionKey: string, ...args: any[]) => Promise<T>;
|
|
20
|
+
navigate: (payload: ShellNavigationPayload) => void;
|
|
21
|
+
showModalDialog?: (title: string, content: string) => void;
|
|
22
|
+
showConfirmationDialog?: (title: string, content: string) => boolean;
|
|
23
|
+
showToast?: (content: string, type: 'success' | 'warning' | 'error' | 'loading' | 'destroy') => void;
|
|
24
|
+
showErrorMessage?: (title: string, content: string) => void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Props for the AppClientProvider component.
|
|
28
|
+
*
|
|
29
|
+
* @typedef {Object} AppClientProviderProps
|
|
30
|
+
* @property {React.ReactNode} children - Children components to be rendered within the provider.
|
|
31
|
+
* @property {ApplicationConfig} config - Configuration for the application, including settings like `isDev` and `forceRedirect`.
|
|
32
|
+
*/
|
|
33
|
+
interface AppClientProviderProps {
|
|
34
|
+
children: React.ReactNode;
|
|
35
|
+
config: FullpageApplicationConfig | PluginApplicationConfig;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Custom hook to access the AppClient context.
|
|
39
|
+
*
|
|
40
|
+
* @returns {AppClientContextState} The current context state.
|
|
41
|
+
*/
|
|
42
|
+
declare const useAppClient: () => AppClientContextState;
|
|
43
|
+
/**
|
|
44
|
+
* Component providing the context for AppClient. It initializes communication
|
|
45
|
+
* with the AppShell and provides methods for action invocation and navigation.
|
|
46
|
+
*
|
|
47
|
+
* @param {AppClientProviderProps} props - The props for the AppClientProvider component.
|
|
48
|
+
*/
|
|
49
|
+
declare const AppClientProvider: ({ children, config }: AppClientProviderProps) => React.JSX.Element;
|
|
50
|
+
export { AppClientProvider, useAppClient };
|
|
51
|
+
export type { ApplicationNavigation, FullpageApplicationConfig, PluginApplicationConfig, RegisteredApp, RegisteredAppType, ShellNavigation };
|
|
52
|
+
//# sourceMappingURL=app-client-provider.d.ts.map
|
|
@@ -0,0 +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,EAGjB,yBAAyB,EACzB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAyD,MAAM,OAAO,CAAC;AAE9E;;;;;;;;;;;GAWG;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;;;;;;GAMG;AACH,UAAU,sBAAsB;IAC9B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,MAAM,EAAE,yBAAyB,GAAG,uBAAuB,CAAC;CAC7D;AAaD;;;;GAIG;AACH,QAAA,MAAM,YAAY,6BAAqC,CAAC;AA6ExD;;;;;GAKG;AACH,QAAA,MAAM,iBAAiB,yBAA0B,sBAAsB,sBA4GtE,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"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { DEFAULT_ACTION_KEYS, EVENTS } from '@akinon/app-shared';
|
|
11
|
+
import Framebus from 'framebus';
|
|
12
|
+
import React, { createContext, useContext, useEffect, useState } from 'react';
|
|
13
|
+
const defaultContextState = {
|
|
14
|
+
isLoading: true,
|
|
15
|
+
invokeAction: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
return Promise.reject('Action functionality not initialized.');
|
|
17
|
+
}),
|
|
18
|
+
navigate: () => { }
|
|
19
|
+
};
|
|
20
|
+
const AppClientContext = createContext(defaultContextState);
|
|
21
|
+
/**
|
|
22
|
+
* Custom hook to access the AppClient context.
|
|
23
|
+
*
|
|
24
|
+
* @returns {AppClientContextState} The current context state.
|
|
25
|
+
*/
|
|
26
|
+
const useAppClient = () => useContext(AppClientContext);
|
|
27
|
+
/**
|
|
28
|
+
* This method communicates with the AppShell to perform
|
|
29
|
+
* the navigation on the shell.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} path - The path to navigate to.
|
|
32
|
+
*/
|
|
33
|
+
const navigate = (payload) => {
|
|
34
|
+
const bus = new Framebus();
|
|
35
|
+
bus.emit(EVENTS.NAVIGATE, Object.assign({}, payload));
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Shows a modal dialog with the specified title and content. This method communicates
|
|
39
|
+
* with the AppShell to display the modal dialog.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} title - The title of the modal dialog.
|
|
42
|
+
* @param {string} content - The content of the modal dialog.
|
|
43
|
+
*/
|
|
44
|
+
const showModalDialog = (title, content) => {
|
|
45
|
+
const bus = new Framebus();
|
|
46
|
+
bus.emit(EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
47
|
+
actionKey: DEFAULT_ACTION_KEYS.showModalDialog,
|
|
48
|
+
args: [title, content]
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Shows a confirmation dialog with the specified title and content. This method communicates
|
|
53
|
+
* with the AppShell to display the confirmation dialog and waits for user input.
|
|
54
|
+
*
|
|
55
|
+
* @param {string} title - The title of the confirmation dialog.
|
|
56
|
+
* @param {string} content - The content of the confirmation dialog.
|
|
57
|
+
* @returns The result of the confirmation dialog action.
|
|
58
|
+
*/
|
|
59
|
+
const showConfirmationDialog = (title, content) => {
|
|
60
|
+
const bus = new Framebus();
|
|
61
|
+
return bus.emit(EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
62
|
+
actionKey: DEFAULT_ACTION_KEYS.showConfirmationDialog,
|
|
63
|
+
args: [title, content]
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Displays a toast message with the specified content and type. This method communicates
|
|
68
|
+
* with the AppShell to display the toast message.
|
|
69
|
+
*
|
|
70
|
+
* @param {string} content - The content of the toast message.
|
|
71
|
+
* @param {'success' | 'warning' | 'error' | 'loading' | 'destroy'} type - The type of the toast message.
|
|
72
|
+
*/
|
|
73
|
+
const showToast = (content, type) => {
|
|
74
|
+
const bus = new Framebus();
|
|
75
|
+
bus.emit(EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
76
|
+
actionKey: DEFAULT_ACTION_KEYS.showToast,
|
|
77
|
+
args: [content, type]
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Displays an error message dialog with the specified title and content.
|
|
82
|
+
* This method communicateswith the AppShell to display the error message.
|
|
83
|
+
*
|
|
84
|
+
* @param {string} title - The title of the error message dialog.
|
|
85
|
+
* @param {string} content - The content of the error message dialog.
|
|
86
|
+
*/
|
|
87
|
+
const showErrorMessage = (title, content) => {
|
|
88
|
+
const bus = new Framebus();
|
|
89
|
+
bus.emit(EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
90
|
+
actionKey: DEFAULT_ACTION_KEYS.showErrorMessage,
|
|
91
|
+
args: [title, content]
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Component providing the context for AppClient. It initializes communication
|
|
96
|
+
* with the AppShell and provides methods for action invocation and navigation.
|
|
97
|
+
*
|
|
98
|
+
* @param {AppClientProviderProps} props - The props for the AppClientProvider component.
|
|
99
|
+
*/
|
|
100
|
+
const AppClientProvider = ({ children, config }) => {
|
|
101
|
+
const [, setAppId] = useState(undefined);
|
|
102
|
+
const [data, setData] = useState(undefined);
|
|
103
|
+
const [params, setParams] = useState(undefined);
|
|
104
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
105
|
+
// Function to invoke an action in the AppShell
|
|
106
|
+
const invokeAction = (actionKey, ...args) => {
|
|
107
|
+
return new Promise((resolve, reject) => {
|
|
108
|
+
const bus = new Framebus();
|
|
109
|
+
bus.emit(EVENTS.INVOKE_ACTION, { actionKey, args }, (response) => {
|
|
110
|
+
if (response.success) {
|
|
111
|
+
resolve(response.result);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
reject(new Error(response.error));
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
const isFullPageApplication = () => {
|
|
120
|
+
const castedConfig = config;
|
|
121
|
+
return Array.isArray(castedConfig.menu);
|
|
122
|
+
};
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
// In production, enforce running in an iframe if forceRedirect is true
|
|
125
|
+
if (config.forceRedirect && !config.isDev && window.self === window.top) {
|
|
126
|
+
console.error('This app must be run inside an iframe when forceRedirect is true.');
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
// Get c from the url of the iframe containing the application.
|
|
130
|
+
const url = new URL(window.location.href);
|
|
131
|
+
const channel = url.searchParams.get('c');
|
|
132
|
+
const bus = channel ? new Framebus({ channel }) : new Framebus();
|
|
133
|
+
// Send data from the AppShell upon initialization.
|
|
134
|
+
// Pass apps config data.
|
|
135
|
+
bus.emit(EVENTS.SET_CONFIG, { config });
|
|
136
|
+
bus.on(EVENTS.SET_DATA, (receivedData) => {
|
|
137
|
+
setData(receivedData);
|
|
138
|
+
setIsLoading(false);
|
|
139
|
+
});
|
|
140
|
+
bus.on(EVENTS.SET_PARAMS, message => {
|
|
141
|
+
const passedParams = message;
|
|
142
|
+
setParams(passedParams);
|
|
143
|
+
});
|
|
144
|
+
bus.on(EVENTS.SET_APP_ID, data => {
|
|
145
|
+
const { appId } = data;
|
|
146
|
+
setAppId(appId);
|
|
147
|
+
});
|
|
148
|
+
if (!isFullPageApplication()) {
|
|
149
|
+
// Get computed height of iframe element.
|
|
150
|
+
const height = document.getElementsByTagName('html')[0].offsetHeight;
|
|
151
|
+
if (height > 0 && window.name) {
|
|
152
|
+
bus.emit(EVENTS.SET_HEIGHT, { height, id: window.name });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// Only listen to navigation events if application type is
|
|
156
|
+
// fullpage. plugin type apps should not have the ability to navigate.
|
|
157
|
+
if (isFullPageApplication()) {
|
|
158
|
+
// Listen for navigation events.
|
|
159
|
+
bus.on(EVENTS.NAVIGATE_CHILD, message => {
|
|
160
|
+
const { path } = message;
|
|
161
|
+
const { navigation } = config;
|
|
162
|
+
if (navigation) {
|
|
163
|
+
const { navigate } = navigation;
|
|
164
|
+
navigate({ path });
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return () => {
|
|
169
|
+
bus.teardown();
|
|
170
|
+
};
|
|
171
|
+
}, [config]);
|
|
172
|
+
const contextValue = {
|
|
173
|
+
data,
|
|
174
|
+
params,
|
|
175
|
+
isLoading,
|
|
176
|
+
invokeAction,
|
|
177
|
+
navigate,
|
|
178
|
+
showModalDialog,
|
|
179
|
+
showConfirmationDialog,
|
|
180
|
+
showToast,
|
|
181
|
+
showErrorMessage
|
|
182
|
+
};
|
|
183
|
+
return (React.createElement(AppClientContext.Provider, { value: contextValue }, children));
|
|
184
|
+
};
|
|
185
|
+
export { AppClientProvider, useAppClient };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './app-client-provider';
|
package/package.json
CHANGED
|
@@ -1,43 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akinon/app-client",
|
|
3
|
-
"description": "Akinon
|
|
4
|
-
"version": "0.
|
|
3
|
+
"description": "Akinon AppClient library. This library is used to create a new plugin or an application which will reside in Akinon's applications.",
|
|
4
|
+
"version": "0.6.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
|
-
"main": "dist/index.js",
|
|
8
|
-
"module": "dist/index.js",
|
|
7
|
+
"main": "dist/esm/index.js",
|
|
8
|
+
"module": "dist/esm/index.js",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"framebus": "^6.0.0",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"@akinon/app-shared": "
|
|
14
|
+
"react": "^18.2.0",
|
|
15
|
+
"react-dom": "^18.2.0",
|
|
16
|
+
"@akinon/app-shared": "0.6.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@types/postmate": "^1.5.3",
|
|
20
19
|
"clean-package": "2.2.0",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
"react-dom": "18.x"
|
|
20
|
+
"copyfiles": "^2.4.1",
|
|
21
|
+
"rimraf": "^5.0.5",
|
|
22
|
+
"typescript": "^5.2.2",
|
|
23
|
+
"@akinon/vite-config": "0.2.0",
|
|
24
|
+
"@akinon/eslint-config": "0.1.0",
|
|
25
|
+
"@akinon/typescript-config": "0.0.0"
|
|
28
26
|
},
|
|
29
27
|
"clean-package": "../../clean-package.config.json",
|
|
30
|
-
"types": "dist/index.d.ts",
|
|
28
|
+
"types": "dist/esm/index.d.ts",
|
|
31
29
|
"exports": {
|
|
32
30
|
".": {
|
|
33
|
-
"types": "./dist/index.d.ts",
|
|
34
|
-
"import": "./dist/index.js",
|
|
35
|
-
"require": "./dist/index.
|
|
31
|
+
"types": "./dist/esm/index.d.ts",
|
|
32
|
+
"import": "./dist/esm/index.js",
|
|
33
|
+
"require": "./dist/cjs/index.js"
|
|
36
34
|
},
|
|
37
35
|
"./package.json": "./package.json"
|
|
38
36
|
},
|
|
39
37
|
"scripts": {
|
|
40
|
-
"build": "
|
|
38
|
+
"build": "pnpm run build:esm && pnpm run build:commonjs && pnpm run copy:files",
|
|
39
|
+
"build:esm": "tsc --outDir dist/esm",
|
|
40
|
+
"build:commonjs": "tsc --module commonjs --outDir dist/cjs",
|
|
41
|
+
"copy:files": "copyfiles -u 1 src/**/*.css dist/esm && copyfiles -u 1 src/**/*.css dist/cjs",
|
|
42
|
+
"clean": "rimraf dist/",
|
|
41
43
|
"lint": "eslint *.ts*",
|
|
42
44
|
"test": "vitest run",
|
|
43
45
|
"test:ui": "vitest --ui",
|
|
@@ -1 +0,0 @@
|
|
|
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,sBA4GtE,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
DELETED
|
@@ -1 +0,0 @@
|
|
|
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=l(),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=l();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=l();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=l();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 C={};Object.defineProperty(C,"__esModule",{value:!0});C.hasOpener=void 0;function ne(r){return!(r.top!==r||r.opener==null||r.opener===r||r.opener.closed===!0)}C.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=l();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=l();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 G(){if(V)return D;V=1,Object.defineProperty(D,"__esModule",{value:!0}),D.Framebus=void 0;var r=l(),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=G(),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 E={},U;function le(){if(U)return E;U=1,Object.defineProperty(E,"__esModule",{value:!0}),E.subscriptionArgsInvalid=void 0;var r=l();function o(n,t,e){return(0,r.isntString)(n)||typeof t!="function"?!0:(0,r.isntString)(e)}return E.subscriptionArgsInvalid=o,E}var J={};Object.defineProperty(J,"__esModule",{value:!0});var F={},N;function he(){if(N)return F;N=1,Object.defineProperty(F,"__esModule",{value:!0}),F.unpackPayload=void 0;var r=l();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 F.unpackPayload=o,F}var H;function l(){return H||(H=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(C,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=l(),ve=G();(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=(S,...x)=>new Promise((h,d)=>{new v().emit("INVOKE_ACTION",{actionKey:S,args:x},y=>{y.success?h(y.result):d(new Error(y.error))})}),f=()=>{const S=o;return Array.isArray(S.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 x=new URL(window.location.href).searchParams.get("c"),h=x?new v({channel:x}):new v;if(h.emit("REQUEST_DATA",{config:o}),h.on("DATA_RESPONSE",d=>{e(d),u(!1)}),h.on("PARAMS_RESPONSE",d=>{s(d)}),h.on("SET_APP_ID",d=>{const{appId:_}=d;n(_)}),!f()){const d=document.getElementsByTagName("html")[0].offsetHeight;d>0&&window.name&&h.emit("SET_HEIGHT",{height:d,id:window.name})}return f()&&h.on("NAVIGATE_CHILD",d=>{const{path:_}=d,{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.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
|
package/dist/index.js
DELETED
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
import { jsx as Y } from "react/jsx-runtime";
|
|
2
|
-
import { createContext as Z, useContext as ee, useState as C, useEffect as re } from "react";
|
|
3
|
-
var y = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
|
|
4
|
-
function te(r) {
|
|
5
|
-
return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
|
|
6
|
-
}
|
|
7
|
-
var R = {}, g = {}, q;
|
|
8
|
-
function ie() {
|
|
9
|
-
if (q)
|
|
10
|
-
return g;
|
|
11
|
-
q = 1, Object.defineProperty(g, "__esModule", { value: !0 }), g.detach = g.attach = void 0;
|
|
12
|
-
var r = l(), o = !1;
|
|
13
|
-
function n() {
|
|
14
|
-
o || typeof window > "u" || (o = !0, window.addEventListener("message", r.onMessage, !1));
|
|
15
|
-
}
|
|
16
|
-
g.attach = n;
|
|
17
|
-
function t() {
|
|
18
|
-
o = !1, window.removeEventListener("message", r.onMessage, !1);
|
|
19
|
-
}
|
|
20
|
-
return g.detach = t, g;
|
|
21
|
-
}
|
|
22
|
-
var _ = {}, L;
|
|
23
|
-
function ne() {
|
|
24
|
-
if (L)
|
|
25
|
-
return _;
|
|
26
|
-
L = 1, Object.defineProperty(_, "__esModule", { value: !0 }), _.broadcastToChildWindows = void 0;
|
|
27
|
-
var r = l();
|
|
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 _.broadcastToChildWindows = o, _;
|
|
38
|
-
}
|
|
39
|
-
var w = {}, k;
|
|
40
|
-
function ae() {
|
|
41
|
-
if (k)
|
|
42
|
-
return w;
|
|
43
|
-
k = 1, Object.defineProperty(w, "__esModule", { value: !0 }), w.broadcast = void 0;
|
|
44
|
-
var r = l();
|
|
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 w.broadcast = o, w;
|
|
60
|
-
}
|
|
61
|
-
var p = {};
|
|
62
|
-
Object.defineProperty(p, "__esModule", { value: !0 });
|
|
63
|
-
p.subscribers = p.childWindows = p.prefix = void 0;
|
|
64
|
-
p.prefix = "/*framebus*/";
|
|
65
|
-
p.childWindows = [];
|
|
66
|
-
p.subscribers = {};
|
|
67
|
-
var P = {}, B;
|
|
68
|
-
function se() {
|
|
69
|
-
if (B)
|
|
70
|
-
return P;
|
|
71
|
-
B = 1, Object.defineProperty(P, "__esModule", { value: !0 }), P.dispatch = void 0;
|
|
72
|
-
var r = l();
|
|
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 P.dispatch = o, P;
|
|
82
|
-
}
|
|
83
|
-
var I = {};
|
|
84
|
-
Object.defineProperty(I, "__esModule", { value: !0 });
|
|
85
|
-
I.hasOpener = void 0;
|
|
86
|
-
function oe(r) {
|
|
87
|
-
return !(r.top !== r || r.opener == null || r.opener === r || r.opener.closed === !0);
|
|
88
|
-
}
|
|
89
|
-
I.hasOpener = oe;
|
|
90
|
-
var S = {};
|
|
91
|
-
Object.defineProperty(S, "__esModule", { value: !0 });
|
|
92
|
-
S.isntString = void 0;
|
|
93
|
-
function ue(r) {
|
|
94
|
-
return typeof r != "string";
|
|
95
|
-
}
|
|
96
|
-
S.isntString = ue;
|
|
97
|
-
var A = {}, W;
|
|
98
|
-
function ce() {
|
|
99
|
-
if (W)
|
|
100
|
-
return A;
|
|
101
|
-
W = 1, Object.defineProperty(A, "__esModule", { value: !0 }), A.onMessage = void 0;
|
|
102
|
-
var r = l();
|
|
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);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return A.onMessage = o, A;
|
|
113
|
-
}
|
|
114
|
-
var O = {}, $;
|
|
115
|
-
function fe() {
|
|
116
|
-
if ($)
|
|
117
|
-
return O;
|
|
118
|
-
$ = 1, Object.defineProperty(O, "__esModule", { value: !0 }), O.packagePayload = void 0;
|
|
119
|
-
var r = l();
|
|
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 O.packagePayload = o, O;
|
|
134
|
-
}
|
|
135
|
-
var j = {};
|
|
136
|
-
Object.defineProperty(j, "__esModule", { value: !0 });
|
|
137
|
-
j.sendMessage = void 0;
|
|
138
|
-
function de(r, o, n) {
|
|
139
|
-
try {
|
|
140
|
-
r.postMessage(o, n);
|
|
141
|
-
} catch {
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
j.sendMessage = de;
|
|
145
|
-
var M = {}, T = {}, V;
|
|
146
|
-
function G() {
|
|
147
|
-
if (V)
|
|
148
|
-
return T;
|
|
149
|
-
V = 1, Object.defineProperty(T, "__esModule", { value: !0 }), T.Framebus = void 0;
|
|
150
|
-
var r = l(), 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);
|
|
227
|
-
}
|
|
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 T.Framebus = n, T;
|
|
256
|
-
}
|
|
257
|
-
function le() {
|
|
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 he = le, K;
|
|
264
|
-
function pe() {
|
|
265
|
-
if (K)
|
|
266
|
-
return M;
|
|
267
|
-
K = 1;
|
|
268
|
-
var r = y && y.__importDefault || function(e) {
|
|
269
|
-
return e && e.__esModule ? e : { default: e };
|
|
270
|
-
};
|
|
271
|
-
Object.defineProperty(M, "__esModule", { value: !0 }), M.subscribeReplier = void 0;
|
|
272
|
-
var o = G(), n = r(he);
|
|
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 M.subscribeReplier = t, M;
|
|
285
|
-
}
|
|
286
|
-
var D = {}, U;
|
|
287
|
-
function ve() {
|
|
288
|
-
if (U)
|
|
289
|
-
return D;
|
|
290
|
-
U = 1, Object.defineProperty(D, "__esModule", { value: !0 }), D.subscriptionArgsInvalid = void 0;
|
|
291
|
-
var r = l();
|
|
292
|
-
function o(n, t, e) {
|
|
293
|
-
return (0, r.isntString)(n) || typeof t != "function" ? !0 : (0, r.isntString)(e);
|
|
294
|
-
}
|
|
295
|
-
return D.subscriptionArgsInvalid = o, D;
|
|
296
|
-
}
|
|
297
|
-
var J = {};
|
|
298
|
-
Object.defineProperty(J, "__esModule", { value: !0 });
|
|
299
|
-
var E = {}, N;
|
|
300
|
-
function ge() {
|
|
301
|
-
if (N)
|
|
302
|
-
return E;
|
|
303
|
-
N = 1, Object.defineProperty(E, "__esModule", { value: !0 }), E.unpackPayload = void 0;
|
|
304
|
-
var r = l();
|
|
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);
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
return t;
|
|
324
|
-
}
|
|
325
|
-
return E.unpackPayload = o, E;
|
|
326
|
-
}
|
|
327
|
-
var H;
|
|
328
|
-
function l() {
|
|
329
|
-
return H || (H = 1, function(r) {
|
|
330
|
-
var o = y && y.__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 = y && y.__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(ie(), r), n(ne(), r), n(ae(), r), n(p, r), n(se(), r), n(I, r), n(S, r), n(ce(), r), n(fe(), r), n(j, r), n(pe(), r), n(ve(), r), n(J, r), n(ge(), r);
|
|
343
|
-
}(R)), R;
|
|
344
|
-
}
|
|
345
|
-
var be = l(), ye = G();
|
|
346
|
-
(0, be.attach)();
|
|
347
|
-
var me = ye.Framebus;
|
|
348
|
-
const v = /* @__PURE__ */ te(me), _e = {
|
|
349
|
-
isLoading: !0,
|
|
350
|
-
invokeAction: async () => Promise.reject("Action functionality not initialized."),
|
|
351
|
-
navigate: () => {
|
|
352
|
-
}
|
|
353
|
-
}, z = Z(_e), Ee = () => ee(z), we = (r) => {
|
|
354
|
-
new v().emit("NAVIGATE", { ...r });
|
|
355
|
-
}, Pe = (r, o) => {
|
|
356
|
-
new v().emit("INVOKE_DEFAULT_ACTION", {
|
|
357
|
-
actionKey: "showModalDialog",
|
|
358
|
-
args: [r, o]
|
|
359
|
-
});
|
|
360
|
-
}, Ae = (r, o) => new v().emit("INVOKE_DEFAULT_ACTION", {
|
|
361
|
-
actionKey: "showConfirmationDialog",
|
|
362
|
-
args: [r, o]
|
|
363
|
-
}), Oe = (r, o) => {
|
|
364
|
-
new v().emit("INVOKE_DEFAULT_ACTION", {
|
|
365
|
-
actionKey: "showToast",
|
|
366
|
-
args: [r, o]
|
|
367
|
-
});
|
|
368
|
-
}, Me = (r, o) => {
|
|
369
|
-
new v().emit("INVOKE_DEFAULT_ACTION", {
|
|
370
|
-
actionKey: "showErrorMessage",
|
|
371
|
-
args: [r, o]
|
|
372
|
-
});
|
|
373
|
-
}, Fe = ({ children: r, config: o }) => {
|
|
374
|
-
const [, n] = C(void 0), [t, e] = C(void 0), [i, s] = C(
|
|
375
|
-
void 0
|
|
376
|
-
), [a, u] = C(!0), c = (F, ...x) => new Promise((h, d) => {
|
|
377
|
-
new v().emit("INVOKE_ACTION", { actionKey: F, args: x }, (b) => {
|
|
378
|
-
b.success ? h(b.result) : d(new Error(b.error));
|
|
379
|
-
});
|
|
380
|
-
}), f = () => {
|
|
381
|
-
const F = o;
|
|
382
|
-
return Array.isArray(F.menu);
|
|
383
|
-
};
|
|
384
|
-
re(() => {
|
|
385
|
-
if (o.forceRedirect && !o.isDev && window.self === window.top) {
|
|
386
|
-
console.error(
|
|
387
|
-
"This app must be run inside an iframe when forceRedirect is true."
|
|
388
|
-
);
|
|
389
|
-
return;
|
|
390
|
-
}
|
|
391
|
-
const x = new URL(window.location.href).searchParams.get("c"), h = x ? new v({ channel: x }) : new v();
|
|
392
|
-
if (h.emit("REQUEST_DATA", { config: o }), h.on("DATA_RESPONSE", (d) => {
|
|
393
|
-
e(d), u(!1);
|
|
394
|
-
}), h.on("PARAMS_RESPONSE", (d) => {
|
|
395
|
-
s(d);
|
|
396
|
-
}), h.on("SET_APP_ID", (d) => {
|
|
397
|
-
const { appId: m } = d;
|
|
398
|
-
n(m);
|
|
399
|
-
}), !f()) {
|
|
400
|
-
const d = document.getElementsByTagName("html")[0].offsetHeight;
|
|
401
|
-
d > 0 && window.name && h.emit("SET_HEIGHT", { height: d, id: window.name });
|
|
402
|
-
}
|
|
403
|
-
return f() && h.on("NAVIGATE_CHILD", (d) => {
|
|
404
|
-
const { path: m } = d, { navigation: b } = o;
|
|
405
|
-
if (b) {
|
|
406
|
-
const { navigate: X } = b;
|
|
407
|
-
X({ path: m });
|
|
408
|
-
}
|
|
409
|
-
}), () => {
|
|
410
|
-
h.teardown();
|
|
411
|
-
};
|
|
412
|
-
}, [o]);
|
|
413
|
-
const Q = {
|
|
414
|
-
data: t,
|
|
415
|
-
params: i,
|
|
416
|
-
isLoading: a,
|
|
417
|
-
invokeAction: c,
|
|
418
|
-
navigate: we,
|
|
419
|
-
showModalDialog: Pe,
|
|
420
|
-
showConfirmationDialog: Ae,
|
|
421
|
-
showToast: Oe,
|
|
422
|
-
showErrorMessage: Me
|
|
423
|
-
};
|
|
424
|
-
return /* @__PURE__ */ Y(z.Provider, { value: Q, children: r });
|
|
425
|
-
};
|
|
426
|
-
export {
|
|
427
|
-
Fe as AppClientProvider,
|
|
428
|
-
Ee as useAppClient
|
|
429
|
-
};
|
|
File without changes
|