@akinon/app-client 0.10.0 → 0.11.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/cjs/app-client-provider.d.ts +95 -19
- package/dist/cjs/app-client-provider.d.ts.map +1 -1
- package/dist/cjs/app-client-provider.js +82 -33
- package/dist/esm/app-client-provider.d.ts +95 -19
- package/dist/esm/app-client-provider.d.ts.map +1 -1
- package/dist/esm/app-client-provider.js +82 -33
- package/package.json +3 -10
|
@@ -1,40 +1,116 @@
|
|
|
1
|
-
import { ApplicationData, ApplicationNavigation, ApplicationParams, FullpageApplicationConfig, PluginApplicationConfig, RegisteredApp, RegisteredAppType, ShellNavigation, ShellNavigationPayload } from '@akinon/app-shared';
|
|
1
|
+
import type { ApplicationData, ApplicationModalSize, ApplicationNavigation, ApplicationParams, ApplicationToastType, FullpageApplicationConfig, PluginApplicationConfig, RegisteredApp, RegisteredAppType, ShellNavigation, ShellNavigationPayload } from '@akinon/app-shared';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
/**
|
|
4
4
|
* Defines the context state for the AppClient, including application data,
|
|
5
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.
|
|
6
|
+
* Additional helper methods include showing dialogs, toasts, and error messages.
|
|
14
7
|
*/
|
|
15
8
|
interface AppClientContextState {
|
|
9
|
+
/**
|
|
10
|
+
* Shared application data across micro frontends.
|
|
11
|
+
*/
|
|
16
12
|
data?: ApplicationData;
|
|
13
|
+
/**
|
|
14
|
+
* Additional parameters to be passed to the application.
|
|
15
|
+
*/
|
|
17
16
|
params?: ApplicationParams;
|
|
17
|
+
/**
|
|
18
|
+
* Indicates whether the application data is currently loading.
|
|
19
|
+
*/
|
|
18
20
|
isLoading: boolean;
|
|
19
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Method to invoke an action defined in the AppShell.
|
|
23
|
+
*/
|
|
24
|
+
invokeAction: (actionKey: string, ...args: Array<unknown>) => Promise<unknown>;
|
|
25
|
+
/**
|
|
26
|
+
* Method to navigate to a specified path within the application.
|
|
27
|
+
* @param {ShellNavigationPayload} payload - The payload containing the navigation details.
|
|
28
|
+
*/
|
|
20
29
|
navigate: (payload: ShellNavigationPayload) => void;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Shows a modal dialog with the specified options.
|
|
32
|
+
* This method communicates with the AppShell to display the modal dialog.
|
|
33
|
+
*
|
|
34
|
+
* @param {Object} options - The options for the modal dialog.
|
|
35
|
+
* @param {string} options.title - The title of the modal dialog.
|
|
36
|
+
* @param {string} options.content - The content of the modal dialog.
|
|
37
|
+
* @param {Function} options.onConfirm - Callback function to be executed when the dialog is confirmed.
|
|
38
|
+
* @param {Function} options.onCancel - Callback function to be executed when the dialog is canceled.
|
|
39
|
+
* @returns {boolean} - Indicates if the dialog was successfully shown.
|
|
40
|
+
*/
|
|
41
|
+
showModalDialog?: (options: {
|
|
42
|
+
title: string;
|
|
43
|
+
content: string;
|
|
44
|
+
onConfirm?: () => void;
|
|
45
|
+
onCancel?: () => void;
|
|
46
|
+
}) => boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Shows a confirmation dialog with the specified options.
|
|
49
|
+
* This method communicates with the AppShell to display the confirmation dialog.
|
|
50
|
+
*
|
|
51
|
+
* @param {Object} options - The options for the confirmation dialog.
|
|
52
|
+
* @param {string} options.title - The title of the confirmation dialog.
|
|
53
|
+
* @param {string} options.content - The content of the confirmation dialog.
|
|
54
|
+
* @param {Function} options.onConfirm - Callback function to be executed when the dialog is confirmed.
|
|
55
|
+
* @param {Function} options.onCancel - Callback function to be executed when the dialog is canceled.
|
|
56
|
+
* @returns {boolean} - Indicates if the dialog was successfully shown.
|
|
57
|
+
*/
|
|
58
|
+
showConfirmationDialog?: (options: {
|
|
59
|
+
title: string;
|
|
60
|
+
content: string;
|
|
61
|
+
onConfirm?: (data: unknown) => void;
|
|
62
|
+
onCancel?: () => void;
|
|
63
|
+
}) => boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Shows a toast message with the specified content and type.
|
|
66
|
+
* This method communicates with the AppShell to display the toast message.
|
|
67
|
+
*
|
|
68
|
+
* @param {string} content - The content of the toast message.
|
|
69
|
+
* @param {ApplicationToastType} type - The type of the toast message.
|
|
70
|
+
*/
|
|
71
|
+
showToast?: (content: string, type: ApplicationToastType) => boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Shows an error message dialog with the specified title and content.
|
|
74
|
+
* This method communicates with the AppShell to display the error message.
|
|
75
|
+
*
|
|
76
|
+
* @param {string} title - The title of the error message dialog.
|
|
77
|
+
* @param {string} content - The content of the error message dialog.
|
|
78
|
+
*/
|
|
79
|
+
showErrorMessage?: (title: string, content: string) => boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Displays a rich-contentful modal with the specified path and context.
|
|
82
|
+
* This method communicates with the AppShell to display the rich-contentful modal.
|
|
83
|
+
*
|
|
84
|
+
* @param {string} path - The path of displayed iframe.
|
|
85
|
+
* @param {unknown} context - Optional context. Its type must follow the rules: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
|
|
86
|
+
* @param {Object} size - Optional size of the modal.
|
|
87
|
+
* @param {number | string} size.maxWidth - The maximum width of the modal. If falsish, the modal will be max 540px wide.
|
|
88
|
+
* @param {number | string} size.maxHeight - The maximum height of the modal. If falsish, the modal will be max 360px high.
|
|
89
|
+
* @param {string} closeIconColor - Optional color of the close icon.
|
|
90
|
+
*/
|
|
91
|
+
showRichModal?: (path: string, context?: unknown, size?: ApplicationModalSize, closeIconColor?: string) => boolean;
|
|
92
|
+
/**
|
|
93
|
+
* The current locale of the application.
|
|
94
|
+
*/
|
|
26
95
|
locale: string;
|
|
96
|
+
/**
|
|
97
|
+
* Method to handle locale changes.
|
|
98
|
+
* @param {Function} callback - Callback function to be executed when the locale changes.
|
|
99
|
+
* @returns {Function} - Function to remove the callback.
|
|
100
|
+
*/
|
|
27
101
|
onLocaleChange: (callback: (newLocale: string) => void) => void;
|
|
28
102
|
}
|
|
29
103
|
/**
|
|
30
104
|
* Props for the AppClientProvider component.
|
|
31
|
-
*
|
|
32
|
-
* @typedef {Object} AppClientProviderProps
|
|
33
|
-
* @property {React.ReactNode} children - Children components to be rendered within the provider.
|
|
34
|
-
* @property {ApplicationConfig} config - Configuration for the application, including settings like `isDev` and `forceRedirect`.
|
|
35
105
|
*/
|
|
36
106
|
interface AppClientProviderProps {
|
|
107
|
+
/**
|
|
108
|
+
* Children components to be rendered within the provider.
|
|
109
|
+
*/
|
|
37
110
|
children: React.ReactNode;
|
|
111
|
+
/**
|
|
112
|
+
* Configuration for the application, including settings like `isDev` and `forceRedirect`.
|
|
113
|
+
*/
|
|
38
114
|
config: FullpageApplicationConfig | PluginApplicationConfig;
|
|
39
115
|
}
|
|
40
116
|
/**
|
|
@@ -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,KAAK,EACV,eAAe,EACf,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,EACpB,yBAAyB,EACzB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAON,MAAM,OAAO,CAAC;AAEf;;;;GAIG;AACH,UAAU,qBAAqB;IAC7B;;OAEG;IACH,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB;;OAEG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B;;OAEG;IACH,SAAS,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,YAAY,EAAE,CACZ,SAAS,EAAE,MAAM,EACjB,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,KACpB,OAAO,CAAC,OAAO,CAAC,CAAC;IACtB;;;OAGG;IACH,QAAQ,EAAE,CAAC,OAAO,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACpD;;;;;;;;;;OAUG;IACH,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE;QAC1B,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;QACvB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;KACvB,KAAK,OAAO,CAAC;IACd;;;;;;;;;;OAUG;IACH,sBAAsB,CAAC,EAAE,CAAC,OAAO,EAAE;QACjC,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;QACpC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;KACvB,KAAK,OAAO,CAAC;IACd;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,KAAK,OAAO,CAAC;IACrE;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;IAC/D;;;;;;;;;;OAUG;IACH,aAAa,CAAC,EAAE,CACd,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,OAAO,EACjB,IAAI,CAAC,EAAE,oBAAoB,EAC3B,cAAc,CAAC,EAAE,MAAM,KACpB,OAAO,CAAC;IACb;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,cAAc,EAAE,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,KAAK,IAAI,CAAC;CACjE;AAED;;GAEG;AACH,UAAU,sBAAsB;IAC9B;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;OAEG;IACH,MAAM,EAAE,yBAAyB,GAAG,uBAAuB,CAAC;CAC7D;AAyBD;;;;GAIG;AACH,QAAA,MAAM,YAAY,QAAO,qBAAqD,CAAC;AAwL/E;;;;;GAKG;AACH,QAAA,MAAM,iBAAiB,yBAA0B,sBAAsB,sBAiJtE,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"}
|
|
@@ -13,15 +13,25 @@ exports.useAppClient = exports.AppClientProvider = void 0;
|
|
|
13
13
|
const app_shared_1 = require("@akinon/app-shared");
|
|
14
14
|
const framebus_1 = require("framebus");
|
|
15
15
|
const react_1 = require("react");
|
|
16
|
+
/**
|
|
17
|
+
* Default context state for the AppClient.
|
|
18
|
+
*/
|
|
16
19
|
const defaultContextState = {
|
|
17
20
|
isLoading: true,
|
|
18
21
|
invokeAction: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
22
|
return Promise.reject('Action functionality not initialized.');
|
|
20
23
|
}),
|
|
21
|
-
navigate: () => {
|
|
24
|
+
navigate: () => {
|
|
25
|
+
return;
|
|
26
|
+
},
|
|
22
27
|
locale: 'en',
|
|
23
|
-
onLocaleChange: () => {
|
|
28
|
+
onLocaleChange: () => {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
24
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Context for the AppClient, providing access to application state and methods.
|
|
34
|
+
*/
|
|
25
35
|
const AppClientContext = (0, react_1.createContext)(defaultContextState);
|
|
26
36
|
/**
|
|
27
37
|
* Custom hook to access the AppClient context.
|
|
@@ -31,68 +41,97 @@ const AppClientContext = (0, react_1.createContext)(defaultContextState);
|
|
|
31
41
|
const useAppClient = () => (0, react_1.useContext)(AppClientContext);
|
|
32
42
|
exports.useAppClient = useAppClient;
|
|
33
43
|
/**
|
|
34
|
-
*
|
|
35
|
-
* the
|
|
36
|
-
*
|
|
37
|
-
* @param {string} path - The path to navigate to.
|
|
44
|
+
* Navigates to the specified path within the application.
|
|
45
|
+
* This method communicates with the AppShell to perform the navigation.
|
|
38
46
|
*/
|
|
39
|
-
const navigate = (
|
|
47
|
+
const navigate = ({ id, path, external }) => {
|
|
40
48
|
const bus = new framebus_1.default();
|
|
41
|
-
bus.emit(app_shared_1.EVENTS.NAVIGATE,
|
|
49
|
+
bus.emit(app_shared_1.EVENTS.NAVIGATE, { id, path, external });
|
|
42
50
|
};
|
|
43
51
|
/**
|
|
44
|
-
* Shows a modal dialog with the specified title and content.
|
|
45
|
-
* with the AppShell to display the modal dialog.
|
|
52
|
+
* Shows a modal dialog with the specified title and content.
|
|
53
|
+
* This method communicates with the AppShell to display the modal dialog.
|
|
46
54
|
*
|
|
47
|
-
* @
|
|
48
|
-
* @param {string} content - The content of the modal dialog.
|
|
55
|
+
* @returns {boolean} - Indicates if the dialog was successfully shown.
|
|
49
56
|
*/
|
|
50
|
-
const showModalDialog = (title, content) => {
|
|
57
|
+
const showModalDialog = ({ title, content, onConfirm, onCancel }) => {
|
|
51
58
|
const bus = new framebus_1.default();
|
|
52
|
-
|
|
59
|
+
function handleActionConfirmed() {
|
|
60
|
+
bus.off(app_shared_1.EVENTS.ACTION_CONFIRMED, handleActionConfirmed);
|
|
61
|
+
bus.off(app_shared_1.EVENTS.ACTION_CANCELED, handleActionCanceled);
|
|
62
|
+
onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm();
|
|
63
|
+
}
|
|
64
|
+
function handleActionCanceled() {
|
|
65
|
+
bus.off(app_shared_1.EVENTS.ACTION_CANCELED, handleActionCanceled);
|
|
66
|
+
bus.off(app_shared_1.EVENTS.ACTION_CONFIRMED, handleActionConfirmed);
|
|
67
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
68
|
+
}
|
|
69
|
+
if (onConfirm) {
|
|
70
|
+
bus.on(app_shared_1.EVENTS.ACTION_CONFIRMED, handleActionConfirmed);
|
|
71
|
+
}
|
|
72
|
+
if (onCancel) {
|
|
73
|
+
bus.on(app_shared_1.EVENTS.ACTION_CANCELED, handleActionCanceled);
|
|
74
|
+
}
|
|
75
|
+
return bus.emit(app_shared_1.EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
53
76
|
actionKey: app_shared_1.DEFAULT_ACTION_KEYS.showModalDialog,
|
|
54
77
|
args: [title, content]
|
|
55
78
|
});
|
|
56
79
|
};
|
|
57
80
|
/**
|
|
58
|
-
* Shows a confirmation dialog with the specified title and content
|
|
59
|
-
* with the AppShell to display the confirmation dialog
|
|
81
|
+
* Shows a confirmation dialog with the specified title and content and can handle the user's input.
|
|
82
|
+
* This method communicates with the AppShell to display the confirmation dialog.
|
|
60
83
|
*
|
|
61
|
-
* @
|
|
62
|
-
* @param {string} content - The content of the confirmation dialog.
|
|
63
|
-
* @returns The result of the confirmation dialog action.
|
|
84
|
+
* @returns {boolean} - Indicates if the dialog was successfully shown.
|
|
64
85
|
*/
|
|
65
|
-
const showConfirmationDialog = (title, content) => {
|
|
86
|
+
const showConfirmationDialog = ({ title, content, onConfirm, onCancel }) => {
|
|
66
87
|
const bus = new framebus_1.default();
|
|
88
|
+
function handleActionConfirmed(data) {
|
|
89
|
+
bus.off(app_shared_1.EVENTS.ACTION_CONFIRMED, handleActionConfirmed);
|
|
90
|
+
bus.off(app_shared_1.EVENTS.ACTION_CANCELED, handleActionCanceled);
|
|
91
|
+
onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm(data);
|
|
92
|
+
}
|
|
93
|
+
function handleActionCanceled() {
|
|
94
|
+
bus.off(app_shared_1.EVENTS.ACTION_CANCELED, handleActionCanceled);
|
|
95
|
+
bus.off(app_shared_1.EVENTS.ACTION_CONFIRMED, handleActionConfirmed);
|
|
96
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
97
|
+
}
|
|
98
|
+
if (onConfirm) {
|
|
99
|
+
bus.on(app_shared_1.EVENTS.ACTION_CONFIRMED, handleActionConfirmed);
|
|
100
|
+
}
|
|
101
|
+
if (onCancel) {
|
|
102
|
+
bus.on(app_shared_1.EVENTS.ACTION_CANCELED, handleActionCanceled);
|
|
103
|
+
}
|
|
67
104
|
return bus.emit(app_shared_1.EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
68
105
|
actionKey: app_shared_1.DEFAULT_ACTION_KEYS.showConfirmationDialog,
|
|
69
106
|
args: [title, content]
|
|
70
107
|
});
|
|
71
108
|
};
|
|
72
109
|
/**
|
|
73
|
-
* Displays a toast message with the specified content and type.
|
|
74
|
-
* with the AppShell to display the toast message.
|
|
110
|
+
* Displays a toast message with the specified content and type.
|
|
111
|
+
* This method communicates with the AppShell to display the toast message.
|
|
75
112
|
*
|
|
76
113
|
* @param {string} content - The content of the toast message.
|
|
77
|
-
* @param {
|
|
114
|
+
* @param {ApplicationToastType} type - The type of the toast message.
|
|
115
|
+
* @returns {boolean} - Indicates if the event was emitted successfully.
|
|
78
116
|
*/
|
|
79
117
|
const showToast = (content, type) => {
|
|
80
118
|
const bus = new framebus_1.default();
|
|
81
|
-
bus.emit(app_shared_1.EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
119
|
+
return bus.emit(app_shared_1.EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
82
120
|
actionKey: app_shared_1.DEFAULT_ACTION_KEYS.showToast,
|
|
83
121
|
args: [content, type]
|
|
84
122
|
});
|
|
85
123
|
};
|
|
86
124
|
/**
|
|
87
125
|
* Displays an error message dialog with the specified title and content.
|
|
88
|
-
* This method
|
|
126
|
+
* This method communicates with the AppShell to display the error message.
|
|
89
127
|
*
|
|
90
128
|
* @param {string} title - The title of the error message dialog.
|
|
91
129
|
* @param {string} content - The content of the error message dialog.
|
|
130
|
+
* @returns {boolean} - Indicates if the event was emitted successfully.
|
|
92
131
|
*/
|
|
93
132
|
const showErrorMessage = (title, content) => {
|
|
94
133
|
const bus = new framebus_1.default();
|
|
95
|
-
bus.emit(app_shared_1.EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
134
|
+
return bus.emit(app_shared_1.EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
96
135
|
actionKey: app_shared_1.DEFAULT_ACTION_KEYS.showErrorMessage,
|
|
97
136
|
args: [title, content]
|
|
98
137
|
});
|
|
@@ -103,12 +142,16 @@ const showErrorMessage = (title, content) => {
|
|
|
103
142
|
*
|
|
104
143
|
* @param {string} path - The path of displayed iframe.
|
|
105
144
|
* @param {unknown} context - Optional context. Its type must follow the rules: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
|
|
145
|
+
* @param {Object} size - Optional size of the modal.
|
|
146
|
+
* @param {number | string} size.maxWidth - The maximum width of the modal. If falsish, the modal will be max 540px wide.
|
|
147
|
+
* @param {number | string} size.maxHeight - The maximum height of the modal. If falsish, the modal will be max 360px high.
|
|
148
|
+
* @param {string} closeIconColor - Optional color of the close icon.
|
|
106
149
|
*/
|
|
107
|
-
const showRichModal = (path, context) => {
|
|
150
|
+
const showRichModal = (path, context, size, closeIconColor) => {
|
|
108
151
|
const bus = new framebus_1.default();
|
|
109
|
-
bus.emit(app_shared_1.EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
152
|
+
return bus.emit(app_shared_1.EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
110
153
|
actionKey: app_shared_1.DEFAULT_ACTION_KEYS.showRichModal,
|
|
111
|
-
args: [path, context]
|
|
154
|
+
args: [path, context, size, closeIconColor]
|
|
112
155
|
});
|
|
113
156
|
};
|
|
114
157
|
/**
|
|
@@ -129,11 +172,17 @@ const AppClientProvider = ({ children, config }) => {
|
|
|
129
172
|
return new Promise((resolve, reject) => {
|
|
130
173
|
const bus = new framebus_1.default();
|
|
131
174
|
bus.emit(app_shared_1.EVENTS.INVOKE_ACTION, { actionKey, args }, (response) => {
|
|
132
|
-
if (response
|
|
133
|
-
|
|
175
|
+
if (typeof response === 'object' && response !== null) {
|
|
176
|
+
const typedResponse = response;
|
|
177
|
+
if (typedResponse.success) {
|
|
178
|
+
resolve(typedResponse.result);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
reject(new Error(typedResponse.error || 'Unknown error'));
|
|
182
|
+
}
|
|
134
183
|
}
|
|
135
184
|
else {
|
|
136
|
-
reject(new Error(response
|
|
185
|
+
reject(new Error('Invalid response format'));
|
|
137
186
|
}
|
|
138
187
|
});
|
|
139
188
|
});
|
|
@@ -156,7 +205,7 @@ const AppClientProvider = ({ children, config }) => {
|
|
|
156
205
|
// Pass apps config data.
|
|
157
206
|
bus.emit(app_shared_1.EVENTS.SET_CONFIG, { config });
|
|
158
207
|
bus.on(app_shared_1.EVENTS.SET_DATA, (receivedData) => {
|
|
159
|
-
setData(receivedData);
|
|
208
|
+
setData(prevState => (Object.assign(Object.assign({}, prevState), receivedData)));
|
|
160
209
|
setIsLoading(false);
|
|
161
210
|
});
|
|
162
211
|
bus.on(app_shared_1.EVENTS.SET_PARAMS, message => {
|
|
@@ -1,40 +1,116 @@
|
|
|
1
|
-
import { ApplicationData, ApplicationNavigation, ApplicationParams, FullpageApplicationConfig, PluginApplicationConfig, RegisteredApp, RegisteredAppType, ShellNavigation, ShellNavigationPayload } from '@akinon/app-shared';
|
|
1
|
+
import type { ApplicationData, ApplicationModalSize, ApplicationNavigation, ApplicationParams, ApplicationToastType, FullpageApplicationConfig, PluginApplicationConfig, RegisteredApp, RegisteredAppType, ShellNavigation, ShellNavigationPayload } from '@akinon/app-shared';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
/**
|
|
4
4
|
* Defines the context state for the AppClient, including application data,
|
|
5
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.
|
|
6
|
+
* Additional helper methods include showing dialogs, toasts, and error messages.
|
|
14
7
|
*/
|
|
15
8
|
interface AppClientContextState {
|
|
9
|
+
/**
|
|
10
|
+
* Shared application data across micro frontends.
|
|
11
|
+
*/
|
|
16
12
|
data?: ApplicationData;
|
|
13
|
+
/**
|
|
14
|
+
* Additional parameters to be passed to the application.
|
|
15
|
+
*/
|
|
17
16
|
params?: ApplicationParams;
|
|
17
|
+
/**
|
|
18
|
+
* Indicates whether the application data is currently loading.
|
|
19
|
+
*/
|
|
18
20
|
isLoading: boolean;
|
|
19
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Method to invoke an action defined in the AppShell.
|
|
23
|
+
*/
|
|
24
|
+
invokeAction: (actionKey: string, ...args: Array<unknown>) => Promise<unknown>;
|
|
25
|
+
/**
|
|
26
|
+
* Method to navigate to a specified path within the application.
|
|
27
|
+
* @param {ShellNavigationPayload} payload - The payload containing the navigation details.
|
|
28
|
+
*/
|
|
20
29
|
navigate: (payload: ShellNavigationPayload) => void;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Shows a modal dialog with the specified options.
|
|
32
|
+
* This method communicates with the AppShell to display the modal dialog.
|
|
33
|
+
*
|
|
34
|
+
* @param {Object} options - The options for the modal dialog.
|
|
35
|
+
* @param {string} options.title - The title of the modal dialog.
|
|
36
|
+
* @param {string} options.content - The content of the modal dialog.
|
|
37
|
+
* @param {Function} options.onConfirm - Callback function to be executed when the dialog is confirmed.
|
|
38
|
+
* @param {Function} options.onCancel - Callback function to be executed when the dialog is canceled.
|
|
39
|
+
* @returns {boolean} - Indicates if the dialog was successfully shown.
|
|
40
|
+
*/
|
|
41
|
+
showModalDialog?: (options: {
|
|
42
|
+
title: string;
|
|
43
|
+
content: string;
|
|
44
|
+
onConfirm?: () => void;
|
|
45
|
+
onCancel?: () => void;
|
|
46
|
+
}) => boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Shows a confirmation dialog with the specified options.
|
|
49
|
+
* This method communicates with the AppShell to display the confirmation dialog.
|
|
50
|
+
*
|
|
51
|
+
* @param {Object} options - The options for the confirmation dialog.
|
|
52
|
+
* @param {string} options.title - The title of the confirmation dialog.
|
|
53
|
+
* @param {string} options.content - The content of the confirmation dialog.
|
|
54
|
+
* @param {Function} options.onConfirm - Callback function to be executed when the dialog is confirmed.
|
|
55
|
+
* @param {Function} options.onCancel - Callback function to be executed when the dialog is canceled.
|
|
56
|
+
* @returns {boolean} - Indicates if the dialog was successfully shown.
|
|
57
|
+
*/
|
|
58
|
+
showConfirmationDialog?: (options: {
|
|
59
|
+
title: string;
|
|
60
|
+
content: string;
|
|
61
|
+
onConfirm?: (data: unknown) => void;
|
|
62
|
+
onCancel?: () => void;
|
|
63
|
+
}) => boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Shows a toast message with the specified content and type.
|
|
66
|
+
* This method communicates with the AppShell to display the toast message.
|
|
67
|
+
*
|
|
68
|
+
* @param {string} content - The content of the toast message.
|
|
69
|
+
* @param {ApplicationToastType} type - The type of the toast message.
|
|
70
|
+
*/
|
|
71
|
+
showToast?: (content: string, type: ApplicationToastType) => boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Shows an error message dialog with the specified title and content.
|
|
74
|
+
* This method communicates with the AppShell to display the error message.
|
|
75
|
+
*
|
|
76
|
+
* @param {string} title - The title of the error message dialog.
|
|
77
|
+
* @param {string} content - The content of the error message dialog.
|
|
78
|
+
*/
|
|
79
|
+
showErrorMessage?: (title: string, content: string) => boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Displays a rich-contentful modal with the specified path and context.
|
|
82
|
+
* This method communicates with the AppShell to display the rich-contentful modal.
|
|
83
|
+
*
|
|
84
|
+
* @param {string} path - The path of displayed iframe.
|
|
85
|
+
* @param {unknown} context - Optional context. Its type must follow the rules: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
|
|
86
|
+
* @param {Object} size - Optional size of the modal.
|
|
87
|
+
* @param {number | string} size.maxWidth - The maximum width of the modal. If falsish, the modal will be max 540px wide.
|
|
88
|
+
* @param {number | string} size.maxHeight - The maximum height of the modal. If falsish, the modal will be max 360px high.
|
|
89
|
+
* @param {string} closeIconColor - Optional color of the close icon.
|
|
90
|
+
*/
|
|
91
|
+
showRichModal?: (path: string, context?: unknown, size?: ApplicationModalSize, closeIconColor?: string) => boolean;
|
|
92
|
+
/**
|
|
93
|
+
* The current locale of the application.
|
|
94
|
+
*/
|
|
26
95
|
locale: string;
|
|
96
|
+
/**
|
|
97
|
+
* Method to handle locale changes.
|
|
98
|
+
* @param {Function} callback - Callback function to be executed when the locale changes.
|
|
99
|
+
* @returns {Function} - Function to remove the callback.
|
|
100
|
+
*/
|
|
27
101
|
onLocaleChange: (callback: (newLocale: string) => void) => void;
|
|
28
102
|
}
|
|
29
103
|
/**
|
|
30
104
|
* Props for the AppClientProvider component.
|
|
31
|
-
*
|
|
32
|
-
* @typedef {Object} AppClientProviderProps
|
|
33
|
-
* @property {React.ReactNode} children - Children components to be rendered within the provider.
|
|
34
|
-
* @property {ApplicationConfig} config - Configuration for the application, including settings like `isDev` and `forceRedirect`.
|
|
35
105
|
*/
|
|
36
106
|
interface AppClientProviderProps {
|
|
107
|
+
/**
|
|
108
|
+
* Children components to be rendered within the provider.
|
|
109
|
+
*/
|
|
37
110
|
children: React.ReactNode;
|
|
111
|
+
/**
|
|
112
|
+
* Configuration for the application, including settings like `isDev` and `forceRedirect`.
|
|
113
|
+
*/
|
|
38
114
|
config: FullpageApplicationConfig | PluginApplicationConfig;
|
|
39
115
|
}
|
|
40
116
|
/**
|
|
@@ -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,KAAK,EACV,eAAe,EACf,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,EACpB,yBAAyB,EACzB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAON,MAAM,OAAO,CAAC;AAEf;;;;GAIG;AACH,UAAU,qBAAqB;IAC7B;;OAEG;IACH,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB;;OAEG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B;;OAEG;IACH,SAAS,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,YAAY,EAAE,CACZ,SAAS,EAAE,MAAM,EACjB,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,KACpB,OAAO,CAAC,OAAO,CAAC,CAAC;IACtB;;;OAGG;IACH,QAAQ,EAAE,CAAC,OAAO,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACpD;;;;;;;;;;OAUG;IACH,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE;QAC1B,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;QACvB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;KACvB,KAAK,OAAO,CAAC;IACd;;;;;;;;;;OAUG;IACH,sBAAsB,CAAC,EAAE,CAAC,OAAO,EAAE;QACjC,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;QACpC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;KACvB,KAAK,OAAO,CAAC;IACd;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,KAAK,OAAO,CAAC;IACrE;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;IAC/D;;;;;;;;;;OAUG;IACH,aAAa,CAAC,EAAE,CACd,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,OAAO,EACjB,IAAI,CAAC,EAAE,oBAAoB,EAC3B,cAAc,CAAC,EAAE,MAAM,KACpB,OAAO,CAAC;IACb;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,cAAc,EAAE,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,KAAK,IAAI,CAAC;CACjE;AAED;;GAEG;AACH,UAAU,sBAAsB;IAC9B;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;OAEG;IACH,MAAM,EAAE,yBAAyB,GAAG,uBAAuB,CAAC;CAC7D;AAyBD;;;;GAIG;AACH,QAAA,MAAM,YAAY,QAAO,qBAAqD,CAAC;AAwL/E;;;;;GAKG;AACH,QAAA,MAAM,iBAAiB,yBAA0B,sBAAsB,sBAiJtE,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"}
|
|
@@ -10,15 +10,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { DEFAULT_ACTION_KEYS, EVENTS } from '@akinon/app-shared';
|
|
11
11
|
import Framebus from 'framebus';
|
|
12
12
|
import React, { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
13
|
+
/**
|
|
14
|
+
* Default context state for the AppClient.
|
|
15
|
+
*/
|
|
13
16
|
const defaultContextState = {
|
|
14
17
|
isLoading: true,
|
|
15
18
|
invokeAction: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
19
|
return Promise.reject('Action functionality not initialized.');
|
|
17
20
|
}),
|
|
18
|
-
navigate: () => {
|
|
21
|
+
navigate: () => {
|
|
22
|
+
return;
|
|
23
|
+
},
|
|
19
24
|
locale: 'en',
|
|
20
|
-
onLocaleChange: () => {
|
|
25
|
+
onLocaleChange: () => {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
21
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* Context for the AppClient, providing access to application state and methods.
|
|
31
|
+
*/
|
|
22
32
|
const AppClientContext = createContext(defaultContextState);
|
|
23
33
|
/**
|
|
24
34
|
* Custom hook to access the AppClient context.
|
|
@@ -27,68 +37,97 @@ const AppClientContext = createContext(defaultContextState);
|
|
|
27
37
|
*/
|
|
28
38
|
const useAppClient = () => useContext(AppClientContext);
|
|
29
39
|
/**
|
|
30
|
-
*
|
|
31
|
-
* the
|
|
32
|
-
*
|
|
33
|
-
* @param {string} path - The path to navigate to.
|
|
40
|
+
* Navigates to the specified path within the application.
|
|
41
|
+
* This method communicates with the AppShell to perform the navigation.
|
|
34
42
|
*/
|
|
35
|
-
const navigate = (
|
|
43
|
+
const navigate = ({ id, path, external }) => {
|
|
36
44
|
const bus = new Framebus();
|
|
37
|
-
bus.emit(EVENTS.NAVIGATE,
|
|
45
|
+
bus.emit(EVENTS.NAVIGATE, { id, path, external });
|
|
38
46
|
};
|
|
39
47
|
/**
|
|
40
|
-
* Shows a modal dialog with the specified title and content.
|
|
41
|
-
* with the AppShell to display the modal dialog.
|
|
48
|
+
* Shows a modal dialog with the specified title and content.
|
|
49
|
+
* This method communicates with the AppShell to display the modal dialog.
|
|
42
50
|
*
|
|
43
|
-
* @
|
|
44
|
-
* @param {string} content - The content of the modal dialog.
|
|
51
|
+
* @returns {boolean} - Indicates if the dialog was successfully shown.
|
|
45
52
|
*/
|
|
46
|
-
const showModalDialog = (title, content) => {
|
|
53
|
+
const showModalDialog = ({ title, content, onConfirm, onCancel }) => {
|
|
47
54
|
const bus = new Framebus();
|
|
48
|
-
|
|
55
|
+
function handleActionConfirmed() {
|
|
56
|
+
bus.off(EVENTS.ACTION_CONFIRMED, handleActionConfirmed);
|
|
57
|
+
bus.off(EVENTS.ACTION_CANCELED, handleActionCanceled);
|
|
58
|
+
onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm();
|
|
59
|
+
}
|
|
60
|
+
function handleActionCanceled() {
|
|
61
|
+
bus.off(EVENTS.ACTION_CANCELED, handleActionCanceled);
|
|
62
|
+
bus.off(EVENTS.ACTION_CONFIRMED, handleActionConfirmed);
|
|
63
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
64
|
+
}
|
|
65
|
+
if (onConfirm) {
|
|
66
|
+
bus.on(EVENTS.ACTION_CONFIRMED, handleActionConfirmed);
|
|
67
|
+
}
|
|
68
|
+
if (onCancel) {
|
|
69
|
+
bus.on(EVENTS.ACTION_CANCELED, handleActionCanceled);
|
|
70
|
+
}
|
|
71
|
+
return bus.emit(EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
49
72
|
actionKey: DEFAULT_ACTION_KEYS.showModalDialog,
|
|
50
73
|
args: [title, content]
|
|
51
74
|
});
|
|
52
75
|
};
|
|
53
76
|
/**
|
|
54
|
-
* Shows a confirmation dialog with the specified title and content
|
|
55
|
-
* with the AppShell to display the confirmation dialog
|
|
77
|
+
* Shows a confirmation dialog with the specified title and content and can handle the user's input.
|
|
78
|
+
* This method communicates with the AppShell to display the confirmation dialog.
|
|
56
79
|
*
|
|
57
|
-
* @
|
|
58
|
-
* @param {string} content - The content of the confirmation dialog.
|
|
59
|
-
* @returns The result of the confirmation dialog action.
|
|
80
|
+
* @returns {boolean} - Indicates if the dialog was successfully shown.
|
|
60
81
|
*/
|
|
61
|
-
const showConfirmationDialog = (title, content) => {
|
|
82
|
+
const showConfirmationDialog = ({ title, content, onConfirm, onCancel }) => {
|
|
62
83
|
const bus = new Framebus();
|
|
84
|
+
function handleActionConfirmed(data) {
|
|
85
|
+
bus.off(EVENTS.ACTION_CONFIRMED, handleActionConfirmed);
|
|
86
|
+
bus.off(EVENTS.ACTION_CANCELED, handleActionCanceled);
|
|
87
|
+
onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm(data);
|
|
88
|
+
}
|
|
89
|
+
function handleActionCanceled() {
|
|
90
|
+
bus.off(EVENTS.ACTION_CANCELED, handleActionCanceled);
|
|
91
|
+
bus.off(EVENTS.ACTION_CONFIRMED, handleActionConfirmed);
|
|
92
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
93
|
+
}
|
|
94
|
+
if (onConfirm) {
|
|
95
|
+
bus.on(EVENTS.ACTION_CONFIRMED, handleActionConfirmed);
|
|
96
|
+
}
|
|
97
|
+
if (onCancel) {
|
|
98
|
+
bus.on(EVENTS.ACTION_CANCELED, handleActionCanceled);
|
|
99
|
+
}
|
|
63
100
|
return bus.emit(EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
64
101
|
actionKey: DEFAULT_ACTION_KEYS.showConfirmationDialog,
|
|
65
102
|
args: [title, content]
|
|
66
103
|
});
|
|
67
104
|
};
|
|
68
105
|
/**
|
|
69
|
-
* Displays a toast message with the specified content and type.
|
|
70
|
-
* with the AppShell to display the toast message.
|
|
106
|
+
* Displays a toast message with the specified content and type.
|
|
107
|
+
* This method communicates with the AppShell to display the toast message.
|
|
71
108
|
*
|
|
72
109
|
* @param {string} content - The content of the toast message.
|
|
73
|
-
* @param {
|
|
110
|
+
* @param {ApplicationToastType} type - The type of the toast message.
|
|
111
|
+
* @returns {boolean} - Indicates if the event was emitted successfully.
|
|
74
112
|
*/
|
|
75
113
|
const showToast = (content, type) => {
|
|
76
114
|
const bus = new Framebus();
|
|
77
|
-
bus.emit(EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
115
|
+
return bus.emit(EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
78
116
|
actionKey: DEFAULT_ACTION_KEYS.showToast,
|
|
79
117
|
args: [content, type]
|
|
80
118
|
});
|
|
81
119
|
};
|
|
82
120
|
/**
|
|
83
121
|
* Displays an error message dialog with the specified title and content.
|
|
84
|
-
* This method
|
|
122
|
+
* This method communicates with the AppShell to display the error message.
|
|
85
123
|
*
|
|
86
124
|
* @param {string} title - The title of the error message dialog.
|
|
87
125
|
* @param {string} content - The content of the error message dialog.
|
|
126
|
+
* @returns {boolean} - Indicates if the event was emitted successfully.
|
|
88
127
|
*/
|
|
89
128
|
const showErrorMessage = (title, content) => {
|
|
90
129
|
const bus = new Framebus();
|
|
91
|
-
bus.emit(EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
130
|
+
return bus.emit(EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
92
131
|
actionKey: DEFAULT_ACTION_KEYS.showErrorMessage,
|
|
93
132
|
args: [title, content]
|
|
94
133
|
});
|
|
@@ -99,12 +138,16 @@ const showErrorMessage = (title, content) => {
|
|
|
99
138
|
*
|
|
100
139
|
* @param {string} path - The path of displayed iframe.
|
|
101
140
|
* @param {unknown} context - Optional context. Its type must follow the rules: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
|
|
141
|
+
* @param {Object} size - Optional size of the modal.
|
|
142
|
+
* @param {number | string} size.maxWidth - The maximum width of the modal. If falsish, the modal will be max 540px wide.
|
|
143
|
+
* @param {number | string} size.maxHeight - The maximum height of the modal. If falsish, the modal will be max 360px high.
|
|
144
|
+
* @param {string} closeIconColor - Optional color of the close icon.
|
|
102
145
|
*/
|
|
103
|
-
const showRichModal = (path, context) => {
|
|
146
|
+
const showRichModal = (path, context, size, closeIconColor) => {
|
|
104
147
|
const bus = new Framebus();
|
|
105
|
-
bus.emit(EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
148
|
+
return bus.emit(EVENTS.INVOKE_DEFAULT_ACTION, {
|
|
106
149
|
actionKey: DEFAULT_ACTION_KEYS.showRichModal,
|
|
107
|
-
args: [path, context]
|
|
150
|
+
args: [path, context, size, closeIconColor]
|
|
108
151
|
});
|
|
109
152
|
};
|
|
110
153
|
/**
|
|
@@ -125,11 +168,17 @@ const AppClientProvider = ({ children, config }) => {
|
|
|
125
168
|
return new Promise((resolve, reject) => {
|
|
126
169
|
const bus = new Framebus();
|
|
127
170
|
bus.emit(EVENTS.INVOKE_ACTION, { actionKey, args }, (response) => {
|
|
128
|
-
if (response
|
|
129
|
-
|
|
171
|
+
if (typeof response === 'object' && response !== null) {
|
|
172
|
+
const typedResponse = response;
|
|
173
|
+
if (typedResponse.success) {
|
|
174
|
+
resolve(typedResponse.result);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
reject(new Error(typedResponse.error || 'Unknown error'));
|
|
178
|
+
}
|
|
130
179
|
}
|
|
131
180
|
else {
|
|
132
|
-
reject(new Error(response
|
|
181
|
+
reject(new Error('Invalid response format'));
|
|
133
182
|
}
|
|
134
183
|
});
|
|
135
184
|
});
|
|
@@ -152,7 +201,7 @@ const AppClientProvider = ({ children, config }) => {
|
|
|
152
201
|
// Pass apps config data.
|
|
153
202
|
bus.emit(EVENTS.SET_CONFIG, { config });
|
|
154
203
|
bus.on(EVENTS.SET_DATA, (receivedData) => {
|
|
155
|
-
setData(receivedData);
|
|
204
|
+
setData(prevState => (Object.assign(Object.assign({}, prevState), receivedData)));
|
|
156
205
|
setIsLoading(false);
|
|
157
206
|
});
|
|
158
207
|
bus.on(EVENTS.SET_PARAMS, message => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akinon/app-client",
|
|
3
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.
|
|
4
|
+
"version": "0.11.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/esm/index.js",
|
|
@@ -10,16 +10,14 @@
|
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"framebus": "^6.0.
|
|
14
|
-
"@akinon/app-shared": "0.
|
|
13
|
+
"framebus": "^6.0.1",
|
|
14
|
+
"@akinon/app-shared": "0.12.0"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"clean-package": "2.2.0",
|
|
18
18
|
"copyfiles": "^2.4.1",
|
|
19
19
|
"rimraf": "^5.0.5",
|
|
20
20
|
"typescript": "^5.2.2",
|
|
21
|
-
"@akinon/vite-config": "0.4.0",
|
|
22
|
-
"@akinon/eslint-config": "0.1.0",
|
|
23
21
|
"@akinon/typescript-config": "0.2.0"
|
|
24
22
|
},
|
|
25
23
|
"peerDependencies": {
|
|
@@ -42,11 +40,6 @@
|
|
|
42
40
|
"build:commonjs": "tsc --module commonjs --outDir dist/cjs",
|
|
43
41
|
"copy:files": "copyfiles -u 1 src/**/*.css dist/esm && copyfiles -u 1 src/**/*.css dist/cjs",
|
|
44
42
|
"clean": "rimraf dist/",
|
|
45
|
-
"lint": "eslint *.ts*",
|
|
46
|
-
"test": "vitest run",
|
|
47
|
-
"test:coverage": "vitest run --coverage",
|
|
48
|
-
"test:ui": "vitest --ui",
|
|
49
|
-
"test:watch": "vitest watch",
|
|
50
43
|
"typecheck": "tsc --noEmit"
|
|
51
44
|
}
|
|
52
45
|
}
|