@akinon/app-client 0.5.3 → 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.
@@ -1,9 +1,9 @@
1
- import { default as React } from 'react';
2
1
  import { ApplicationData, ApplicationNavigation, ApplicationParams, FullpageApplicationConfig, PluginApplicationConfig, RegisteredApp, RegisteredAppType, ShellNavigation, ShellNavigationPayload } from '@akinon/app-shared';
3
-
2
+ import React from 'react';
4
3
  /**
5
4
  * Defines the context state for the AppClient, including application data,
6
5
  * loading status, and methods for invoking actions and navigating.
6
+ *
7
7
  * @typedef {Object} AppClientContextState
8
8
  * @property {ApplicationData} [data] - Optional application data shared across micro frontends.
9
9
  * @property {ApplicationParams} [params] - Optional. Additional parameters to be passed to the application.
@@ -25,6 +25,7 @@ interface AppClientContextState {
25
25
  }
26
26
  /**
27
27
  * Props for the AppClientProvider component.
28
+ *
28
29
  * @typedef {Object} AppClientProviderProps
29
30
  * @property {React.ReactNode} children - Children components to be rendered within the provider.
30
31
  * @property {ApplicationConfig} config - Configuration for the application, including settings like `isDev` and `forceRedirect`.
@@ -35,12 +36,14 @@ interface AppClientProviderProps {
35
36
  }
36
37
  /**
37
38
  * Custom hook to access the AppClient context.
39
+ *
38
40
  * @returns {AppClientContextState} The current context state.
39
41
  */
40
42
  declare const useAppClient: () => AppClientContextState;
41
43
  /**
42
44
  * Component providing the context for AppClient. It initializes communication
43
45
  * with the AppShell and provides methods for action invocation and navigation.
46
+ *
44
47
  * @param {AppClientProviderProps} props - The props for the AppClientProvider component.
45
48
  */
46
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,2 @@
1
+ export * from './app-client-provider';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -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,11 +1,11 @@
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.5.3",
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
  ],
@@ -13,26 +13,33 @@
13
13
  "framebus": "^6.0.0",
14
14
  "react": "^18.2.0",
15
15
  "react-dom": "^18.2.0",
16
- "@akinon/app-shared": "^0.5.1"
16
+ "@akinon/app-shared": "0.6.0"
17
17
  },
18
18
  "devDependencies": {
19
19
  "clean-package": "2.2.0",
20
- "@akinon/vite-config": "^0.1.1",
21
- "eslint-config-custom": "0.1.0",
22
- "tsconfig": "0.0.0"
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"
23
26
  },
24
27
  "clean-package": "../../clean-package.config.json",
25
- "types": "dist/index.d.ts",
28
+ "types": "dist/esm/index.d.ts",
26
29
  "exports": {
27
30
  ".": {
28
- "types": "./dist/index.d.ts",
29
- "import": "./dist/index.js",
30
- "require": "./dist/index.cjs"
31
+ "types": "./dist/esm/index.d.ts",
32
+ "import": "./dist/esm/index.js",
33
+ "require": "./dist/cjs/index.js"
31
34
  },
32
35
  "./package.json": "./package.json"
33
36
  },
34
37
  "scripts": {
35
- "build": "vite 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/",
36
43
  "lint": "eslint *.ts*",
37
44
  "test": "vitest run",
38
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,EAGvB,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 ee=require("react/jsx-runtime"),y=require("react"),l={SET_APP_ID:"SET_APP_ID",SET_CONFIG:"SET_CONFIG",SET_DATA:"SET_DATA",SET_HEIGHT:"SET_HEIGHT",SET_PARAMS:"SET_PARAMS",INVOKE_ACTION:"INVOKE_ACTION",INVOKE_DEFAULT_ACTION:"INVOKE_DEFAULT_ACTION",NAVIGATE:"NAVIGATE",NAVIGATE_CHILD:"NAVIGATE_CHILD"},x={showConfirmationDialog:"showConfirmationDialog",showModalDialog:"showModalDialog",showToast:"showToast",showErrorMessage:"showErrorMessage"};var m=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function re(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var L={},b={},N;function te(){if(N)return b;N=1,Object.defineProperty(b,"__esModule",{value:!0}),b.detach=b.attach=void 0;var r=h(),o=!1;function n(){o||typeof window>"u"||(o=!0,window.addEventListener("message",r.onMessage,!1))}b.attach=n;function t(){o=!1,window.removeEventListener("message",r.onMessage,!1)}return b.detach=t,b}var A={},V;function ie(){if(V)return A;V=1,Object.defineProperty(A,"__esModule",{value:!0}),A.broadcastToChildWindows=void 0;var r=h();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 A.broadcastToChildWindows=o,A}var T={},k;function ne(){if(k)return T;k=1,Object.defineProperty(T,"__esModule",{value:!0}),T.broadcast=void 0;var r=h();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 T.broadcast=o,T}var v={};Object.defineProperty(v,"__esModule",{value:!0});v.subscribers=v.childWindows=v.prefix=void 0;v.prefix="/*framebus*/";v.childWindows=[];v.subscribers={};var P={},B;function ae(){if(B)return P;B=1,Object.defineProperty(P,"__esModule",{value:!0}),P.dispatch=void 0;var r=h();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 P.dispatch=o,P}var j={};Object.defineProperty(j,"__esModule",{value:!0});j.hasOpener=void 0;function se(r){return!(r.top!==r||r.opener==null||r.opener===r||r.opener.closed===!0)}j.hasOpener=se;var R={};Object.defineProperty(R,"__esModule",{value:!0});R.isntString=void 0;function oe(r){return typeof r!="string"}R.isntString=oe;var E={},G;function ue(){if(G)return E;G=1,Object.defineProperty(E,"__esModule",{value:!0}),E.onMessage=void 0;var r=h();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 E.onMessage=o,E}var O={},K;function ce(){if(K)return O;K=1,Object.defineProperty(O,"__esModule",{value:!0}),O.packagePayload=void 0;var r=h();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 O.packagePayload=o,O}var q={};Object.defineProperty(q,"__esModule",{value:!0});q.sendMessage=void 0;function fe(r,o,n){try{r.postMessage(o,n)}catch{}}q.sendMessage=fe;var D={},M={},W;function z(){if(W)return M;W=1,Object.defineProperty(M,"__esModule",{value:!0}),M.Framebus=void 0;var r=h(),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 M.Framebus=n,M}function de(){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 le=de,$;function he(){if($)return D;$=1;var r=m&&m.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(D,"__esModule",{value:!0}),D.subscribeReplier=void 0;var o=z(),n=r(le);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 D.subscribeReplier=t,D}var I={},H;function pe(){if(H)return I;H=1,Object.defineProperty(I,"__esModule",{value:!0}),I.subscriptionArgsInvalid=void 0;var r=h();function o(n,t,e){return(0,r.isntString)(n)||typeof t!="function"?!0:(0,r.isntString)(e)}return I.subscriptionArgsInvalid=o,I}var Q={};Object.defineProperty(Q,"__esModule",{value:!0});var C={},U;function ve(){if(U)return C;U=1,Object.defineProperty(C,"__esModule",{value:!0}),C.unpackPayload=void 0;var r=h();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 C.unpackPayload=o,C}var J;function h(){return J||(J=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(te(),r),n(ie(),r),n(ne(),r),n(v,r),n(ae(),r),n(j,r),n(R,r),n(ue(),r),n(ce(),r),n(q,r),n(he(),r),n(pe(),r),n(Q,r),n(ve(),r)}(L)),L}var ge=h(),be=z();(0,ge.attach)();var ye=be.Framebus;const g=re(ye),_e={isLoading:!0,invokeAction:async()=>Promise.reject("Action functionality not initialized."),navigate:()=>{}},X=y.createContext(_e),me=()=>y.useContext(X),we=r=>{new g().emit(l.NAVIGATE,{...r})},Ae=(r,o)=>{new g().emit(l.INVOKE_DEFAULT_ACTION,{actionKey:x.showModalDialog,args:[r,o]})},Te=(r,o)=>new g().emit(l.INVOKE_DEFAULT_ACTION,{actionKey:x.showConfirmationDialog,args:[r,o]}),Pe=(r,o)=>{new g().emit(l.INVOKE_DEFAULT_ACTION,{actionKey:x.showToast,args:[r,o]})},Ee=(r,o)=>{new g().emit(l.INVOKE_DEFAULT_ACTION,{actionKey:x.showErrorMessage,args:[r,o]})},Oe=({children:r,config:o})=>{const[,n]=y.useState(void 0),[t,e]=y.useState(void 0),[i,s]=y.useState(void 0),[a,u]=y.useState(!0),c=(F,...S)=>new Promise((p,d)=>{new g().emit(l.INVOKE_ACTION,{actionKey:F,args:S},_=>{_.success?p(_.result):d(new Error(_.error))})}),f=()=>{const F=o;return Array.isArray(F.menu)};y.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 S=new URL(window.location.href).searchParams.get("c"),p=S?new g({channel:S}):new g;if(p.emit(l.SET_CONFIG,{config:o}),p.on(l.SET_DATA,d=>{e(d),u(!1)}),p.on(l.SET_PARAMS,d=>{s(d)}),p.on(l.SET_APP_ID,d=>{const{appId:w}=d;n(w)}),!f()){const d=document.getElementsByTagName("html")[0].offsetHeight;d>0&&window.name&&p.emit(l.SET_HEIGHT,{height:d,id:window.name})}return f()&&p.on(l.NAVIGATE_CHILD,d=>{const{path:w}=d,{navigation:_}=o;if(_){const{navigate:Z}=_;Z({path:w})}}),()=>{p.teardown()}},[o]);const Y={data:t,params:i,isLoading:a,invokeAction:c,navigate:we,showModalDialog:Ae,showConfirmationDialog:Te,showToast:Pe,showErrorMessage:Ee};return ee.jsx(X.Provider,{value:Y,children:r})};exports.AppClientProvider=Oe;exports.useAppClient=me;
@@ -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,499 +0,0 @@
1
- import { jsx as ee } from "react/jsx-runtime";
2
- import { createContext as re, useContext as te, useState as S, useEffect as ie } from "react";
3
- const l = {
4
- /**
5
- * The event that is emitted when the AppShell sends
6
- * the application ID to the client application.
7
- *
8
- * AppShell → AppClient
9
- */
10
- SET_APP_ID: "SET_APP_ID",
11
- /**
12
- * The event that is emitted when client applications
13
- * sends their configuration to the AppShell.
14
- *
15
- * AppClient → AppShell
16
- */
17
- SET_CONFIG: "SET_CONFIG",
18
- /**
19
- * The event that is emitted when the AppShell sends
20
- * data to the client application.
21
- *
22
- * AppShell → AppClient
23
- */
24
- SET_DATA: "SET_DATA",
25
- /**
26
- * The event that is emitted when client applications
27
- * loads and sends their css height information to the AppShell.
28
- *
29
- * AppClient → AppShell
30
- */
31
- SET_HEIGHT: "SET_HEIGHT",
32
- /**
33
- * The event that is emitted to client applications when params property
34
- * passed to the PluginRenderer component is received or changed.
35
- *
36
- * AppShell → AppClient
37
- */
38
- SET_PARAMS: "SET_PARAMS",
39
- /**
40
- * The event that is emitted when client applications trigger
41
- * custom actions defined on the AppShell.
42
- *
43
- * AppClient → AppShell
44
- */
45
- INVOKE_ACTION: "INVOKE_ACTION",
46
- /**
47
- * The event that is emitted when client applications trigger
48
- * default actions defined on the AppShell.
49
- *
50
- * AppClient → AppShell
51
- */
52
- INVOKE_DEFAULT_ACTION: "INVOKE_DEFAULT_ACTION",
53
- /**
54
- * The event that is emitted when client applications trigger
55
- * navigation for their shell application.
56
- *
57
- * AppClient → AppShell
58
- */
59
- NAVIGATE: "NAVIGATE",
60
- /**
61
- * The event that is emitted when shell applications trigger
62
- * navigation for their child applications.
63
- *
64
- * AppShell → AppClient
65
- */
66
- NAVIGATE_CHILD: "NAVIGATE_CHILD"
67
- }, x = {
68
- showConfirmationDialog: "showConfirmationDialog",
69
- showModalDialog: "showModalDialog",
70
- showToast: "showToast",
71
- showErrorMessage: "showErrorMessage"
72
- };
73
- var m = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
74
- function ne(r) {
75
- return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
76
- }
77
- var q = {}, b = {}, N;
78
- function ae() {
79
- if (N)
80
- return b;
81
- N = 1, Object.defineProperty(b, "__esModule", { value: !0 }), b.detach = b.attach = void 0;
82
- var r = h(), o = !1;
83
- function n() {
84
- o || typeof window > "u" || (o = !0, window.addEventListener("message", r.onMessage, !1));
85
- }
86
- b.attach = n;
87
- function t() {
88
- o = !1, window.removeEventListener("message", r.onMessage, !1);
89
- }
90
- return b.detach = t, b;
91
- }
92
- var w = {}, V;
93
- function se() {
94
- if (V)
95
- return w;
96
- V = 1, Object.defineProperty(w, "__esModule", { value: !0 }), w.broadcastToChildWindows = void 0;
97
- var r = h();
98
- function o(n, t, e) {
99
- for (var i = r.childWindows.length - 1; i >= 0; i--) {
100
- var s = r.childWindows[i];
101
- s.closed ? r.childWindows.splice(i, 1) : e !== s && (0, r.broadcast)(n, {
102
- origin: t,
103
- frame: s.top
104
- });
105
- }
106
- }
107
- return w.broadcastToChildWindows = o, w;
108
- }
109
- var A = {}, k;
110
- function oe() {
111
- if (k)
112
- return A;
113
- k = 1, Object.defineProperty(A, "__esModule", { value: !0 }), A.broadcast = void 0;
114
- var r = h();
115
- function o(n, t) {
116
- var e = 0, i, s = t.origin, a = t.frame;
117
- try {
118
- for (a.postMessage(n, s), (0, r.hasOpener)(a) && a.opener.top !== window.top && o(n, {
119
- origin: s,
120
- frame: a.opener.top
121
- }); i = a.frames[e]; )
122
- o(n, {
123
- origin: s,
124
- frame: i
125
- }), e++;
126
- } catch {
127
- }
128
- }
129
- return A.broadcast = o, A;
130
- }
131
- var v = {};
132
- Object.defineProperty(v, "__esModule", { value: !0 });
133
- v.subscribers = v.childWindows = v.prefix = void 0;
134
- v.prefix = "/*framebus*/";
135
- v.childWindows = [];
136
- v.subscribers = {};
137
- var T = {}, B;
138
- function ue() {
139
- if (B)
140
- return T;
141
- B = 1, Object.defineProperty(T, "__esModule", { value: !0 }), T.dispatch = void 0;
142
- var r = h();
143
- function o(n, t, e, i, s) {
144
- if (r.subscribers[n] && r.subscribers[n][t]) {
145
- var a = [];
146
- e && a.push(e), i && a.push(i);
147
- for (var u = 0; u < r.subscribers[n][t].length; u++)
148
- r.subscribers[n][t][u].apply(s, a);
149
- }
150
- }
151
- return T.dispatch = o, T;
152
- }
153
- var j = {};
154
- Object.defineProperty(j, "__esModule", { value: !0 });
155
- j.hasOpener = void 0;
156
- function ce(r) {
157
- return !(r.top !== r || r.opener == null || r.opener === r || r.opener.closed === !0);
158
- }
159
- j.hasOpener = ce;
160
- var R = {};
161
- Object.defineProperty(R, "__esModule", { value: !0 });
162
- R.isntString = void 0;
163
- function fe(r) {
164
- return typeof r != "string";
165
- }
166
- R.isntString = fe;
167
- var P = {}, G;
168
- function de() {
169
- if (G)
170
- return P;
171
- G = 1, Object.defineProperty(P, "__esModule", { value: !0 }), P.onMessage = void 0;
172
- var r = h();
173
- function o(n) {
174
- if (!(0, r.isntString)(n.data)) {
175
- var t = (0, r.unpackPayload)(n);
176
- if (t) {
177
- var e = t.eventData, i = t.reply;
178
- (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);
179
- }
180
- }
181
- }
182
- return P.onMessage = o, P;
183
- }
184
- var E = {}, K;
185
- function le() {
186
- if (K)
187
- return E;
188
- K = 1, Object.defineProperty(E, "__esModule", { value: !0 }), E.packagePayload = void 0;
189
- var r = h();
190
- function o(n, t, e, i) {
191
- var s, a = {
192
- event: n,
193
- origin: t
194
- };
195
- typeof i == "function" && (a.reply = (0, r.subscribeReplier)(i, t)), a.eventData = e;
196
- try {
197
- s = r.prefix + JSON.stringify(a);
198
- } catch (u) {
199
- throw new Error("Could not stringify event: ".concat(u.message));
200
- }
201
- return s;
202
- }
203
- return E.packagePayload = o, E;
204
- }
205
- var L = {};
206
- Object.defineProperty(L, "__esModule", { value: !0 });
207
- L.sendMessage = void 0;
208
- function he(r, o, n) {
209
- try {
210
- r.postMessage(o, n);
211
- } catch {
212
- }
213
- }
214
- L.sendMessage = he;
215
- var O = {}, D = {}, W;
216
- function z() {
217
- if (W)
218
- return D;
219
- W = 1, Object.defineProperty(D, "__esModule", { value: !0 }), D.Framebus = void 0;
220
- var r = h(), o = typeof window < "u" && window.Promise, n = (
221
- /** @class */
222
- function() {
223
- function t(e) {
224
- 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);
225
- }
226
- return t.setPromise = function(e) {
227
- t.Promise = e;
228
- }, t.target = function(e) {
229
- return new t(e);
230
- }, t.prototype.addTargetFrame = function(e) {
231
- this.limitBroadcastToFramesArray && this.targetFrames.push(e);
232
- }, t.prototype.include = function(e) {
233
- return e == null || e.Window == null || e.constructor !== e.Window ? !1 : (r.childWindows.push(e), !0);
234
- }, t.prototype.target = function(e) {
235
- return t.target(e);
236
- }, t.prototype.emit = function(e, i, s) {
237
- if (this.isDestroyed)
238
- return !1;
239
- var a = this.origin;
240
- if (e = this.namespaceEvent(e), (0, r.isntString)(e) || (0, r.isntString)(a))
241
- return !1;
242
- typeof i == "function" && (s = i, i = void 0);
243
- var u = (0, r.packagePayload)(e, a, i, s);
244
- return u ? (this.limitBroadcastToFramesArray ? this.targetFramesAsWindows().forEach(function(c) {
245
- (0, r.sendMessage)(c, u, a);
246
- }) : (0, r.broadcast)(u, {
247
- origin: a,
248
- frame: window.top || window.self
249
- }), !0) : !1;
250
- }, t.prototype.emitAsPromise = function(e, i) {
251
- var s = this;
252
- return new t.Promise(function(a, u) {
253
- var c = s.emit(e, i, function(f) {
254
- a(f);
255
- });
256
- c || u(new Error('Listener not added for "'.concat(e, '"')));
257
- });
258
- }, t.prototype.on = function(e, i) {
259
- if (this.isDestroyed)
260
- return !1;
261
- var s = this, a = this.origin, u = i;
262
- return e = this.namespaceEvent(e), (0, r.subscriptionArgsInvalid)(e, u, a) ? !1 : (this.hasAdditionalChecksForOnListeners && (u = function() {
263
- for (var c = [], f = 0; f < arguments.length; f++)
264
- c[f] = arguments[f];
265
- s.passesVerifyDomainCheck(this && this.origin) && s.hasMatchingTargetFrame(this && this.source) && i.apply(void 0, c);
266
- }), this.listeners.push({
267
- eventName: e,
268
- handler: u,
269
- originalHandler: i
270
- }), r.subscribers[a] = r.subscribers[a] || {}, r.subscribers[a][e] = r.subscribers[a][e] || [], r.subscribers[a][e].push(u), !0);
271
- }, t.prototype.off = function(e, i) {
272
- var s = i;
273
- if (this.isDestroyed)
274
- return !1;
275
- if (this.verifyDomain)
276
- for (var a = 0; a < this.listeners.length; a++) {
277
- var u = this.listeners[a];
278
- u.originalHandler === i && (s = u.handler);
279
- }
280
- e = this.namespaceEvent(e);
281
- var c = this.origin;
282
- if ((0, r.subscriptionArgsInvalid)(e, s, c))
283
- return !1;
284
- var f = r.subscribers[c] && r.subscribers[c][e];
285
- if (!f)
286
- return !1;
287
- for (var a = 0; a < f.length; a++)
288
- if (f[a] === s)
289
- return f.splice(a, 1), !0;
290
- return !1;
291
- }, t.prototype.teardown = function() {
292
- if (!this.isDestroyed) {
293
- this.isDestroyed = !0;
294
- for (var e = 0; e < this.listeners.length; e++) {
295
- var i = this.listeners[e];
296
- this.off(i.eventName, i.handler);
297
- }
298
- this.listeners.length = 0;
299
- }
300
- }, t.prototype.passesVerifyDomainCheck = function(e) {
301
- return this.verifyDomain ? this.checkOrigin(e) : !0;
302
- }, t.prototype.targetFramesAsWindows = function() {
303
- return this.limitBroadcastToFramesArray ? this.targetFrames.map(function(e) {
304
- return e instanceof HTMLIFrameElement ? e.contentWindow : e;
305
- }).filter(function(e) {
306
- return e;
307
- }) : [];
308
- }, t.prototype.hasMatchingTargetFrame = function(e) {
309
- if (!this.limitBroadcastToFramesArray)
310
- return !0;
311
- var i = this.targetFramesAsWindows().find(function(s) {
312
- return s === e;
313
- });
314
- return !!i;
315
- }, t.prototype.checkOrigin = function(e) {
316
- var i, s = document.createElement("a");
317
- s.href = location.href, s.protocol === "https:" ? i = s.host.replace(/:443$/, "") : s.protocol === "http:" ? i = s.host.replace(/:80$/, "") : i = s.host;
318
- var a = s.protocol + "//" + i;
319
- return a === e ? !0 : this.verifyDomain ? this.verifyDomain(e) : !0;
320
- }, t.prototype.namespaceEvent = function(e) {
321
- return this.channel ? "".concat(this.channel, ":").concat(e) : e;
322
- }, t.Promise = o, t;
323
- }()
324
- );
325
- return D.Framebus = n, D;
326
- }
327
- function pe() {
328
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(r) {
329
- var o = Math.random() * 16 | 0, n = r === "x" ? o : o & 3 | 8;
330
- return n.toString(16);
331
- });
332
- }
333
- var ve = pe, $;
334
- function ge() {
335
- if ($)
336
- return O;
337
- $ = 1;
338
- var r = m && m.__importDefault || function(e) {
339
- return e && e.__esModule ? e : { default: e };
340
- };
341
- Object.defineProperty(O, "__esModule", { value: !0 }), O.subscribeReplier = void 0;
342
- var o = z(), n = r(ve);
343
- function t(e, i) {
344
- var s = (0, n.default)();
345
- function a(u, c) {
346
- e(u, c), o.Framebus.target({
347
- origin: i
348
- }).off(s, a);
349
- }
350
- return o.Framebus.target({
351
- origin: i
352
- }).on(s, a), s;
353
- }
354
- return O.subscribeReplier = t, O;
355
- }
356
- var I = {}, H;
357
- function be() {
358
- if (H)
359
- return I;
360
- H = 1, Object.defineProperty(I, "__esModule", { value: !0 }), I.subscriptionArgsInvalid = void 0;
361
- var r = h();
362
- function o(n, t, e) {
363
- return (0, r.isntString)(n) || typeof t != "function" ? !0 : (0, r.isntString)(e);
364
- }
365
- return I.subscriptionArgsInvalid = o, I;
366
- }
367
- var Q = {};
368
- Object.defineProperty(Q, "__esModule", { value: !0 });
369
- var M = {}, U;
370
- function ye() {
371
- if (U)
372
- return M;
373
- U = 1, Object.defineProperty(M, "__esModule", { value: !0 }), M.unpackPayload = void 0;
374
- var r = h();
375
- function o(n) {
376
- var t;
377
- if (n.data.slice(0, r.prefix.length) !== r.prefix)
378
- return !1;
379
- try {
380
- t = JSON.parse(n.data.slice(r.prefix.length));
381
- } catch {
382
- return !1;
383
- }
384
- if (t.reply) {
385
- var e = n.origin, i = n.source, s = t.reply;
386
- t.reply = function(u) {
387
- if (i) {
388
- var c = (0, r.packagePayload)(s, e, u);
389
- c && i.postMessage(c, e);
390
- }
391
- };
392
- }
393
- return t;
394
- }
395
- return M.unpackPayload = o, M;
396
- }
397
- var J;
398
- function h() {
399
- return J || (J = 1, function(r) {
400
- var o = m && m.__createBinding || (Object.create ? function(t, e, i, s) {
401
- s === void 0 && (s = i);
402
- var a = Object.getOwnPropertyDescriptor(e, i);
403
- (!a || ("get" in a ? !e.__esModule : a.writable || a.configurable)) && (a = { enumerable: !0, get: function() {
404
- return e[i];
405
- } }), Object.defineProperty(t, s, a);
406
- } : function(t, e, i, s) {
407
- s === void 0 && (s = i), t[s] = e[i];
408
- }), n = m && m.__exportStar || function(t, e) {
409
- for (var i in t)
410
- i !== "default" && !Object.prototype.hasOwnProperty.call(e, i) && o(e, t, i);
411
- };
412
- Object.defineProperty(r, "__esModule", { value: !0 }), n(ae(), r), n(se(), r), n(oe(), r), n(v, r), n(ue(), r), n(j, r), n(R, r), n(de(), r), n(le(), r), n(L, r), n(ge(), r), n(be(), r), n(Q, r), n(ye(), r);
413
- }(q)), q;
414
- }
415
- var me = h(), _e = z();
416
- (0, me.attach)();
417
- var we = _e.Framebus;
418
- const g = /* @__PURE__ */ ne(we), Ae = {
419
- isLoading: !0,
420
- invokeAction: async () => Promise.reject("Action functionality not initialized."),
421
- navigate: () => {
422
- }
423
- }, X = re(Ae), Fe = () => te(X), Te = (r) => {
424
- new g().emit(l.NAVIGATE, { ...r });
425
- }, Pe = (r, o) => {
426
- new g().emit(l.INVOKE_DEFAULT_ACTION, {
427
- actionKey: x.showModalDialog,
428
- args: [r, o]
429
- });
430
- }, Ee = (r, o) => new g().emit(l.INVOKE_DEFAULT_ACTION, {
431
- actionKey: x.showConfirmationDialog,
432
- args: [r, o]
433
- }), Oe = (r, o) => {
434
- new g().emit(l.INVOKE_DEFAULT_ACTION, {
435
- actionKey: x.showToast,
436
- args: [r, o]
437
- });
438
- }, De = (r, o) => {
439
- new g().emit(l.INVOKE_DEFAULT_ACTION, {
440
- actionKey: x.showErrorMessage,
441
- args: [r, o]
442
- });
443
- }, Ce = ({ children: r, config: o }) => {
444
- const [, n] = S(void 0), [t, e] = S(void 0), [i, s] = S(
445
- void 0
446
- ), [a, u] = S(!0), c = (F, ...C) => new Promise((p, d) => {
447
- new g().emit(l.INVOKE_ACTION, { actionKey: F, args: C }, (y) => {
448
- y.success ? p(y.result) : d(new Error(y.error));
449
- });
450
- }), f = () => {
451
- const F = o;
452
- return Array.isArray(F.menu);
453
- };
454
- ie(() => {
455
- if (o.forceRedirect && !o.isDev && window.self === window.top) {
456
- console.error(
457
- "This app must be run inside an iframe when forceRedirect is true."
458
- );
459
- return;
460
- }
461
- const C = new URL(window.location.href).searchParams.get("c"), p = C ? new g({ channel: C }) : new g();
462
- if (p.emit(l.SET_CONFIG, { config: o }), p.on(l.SET_DATA, (d) => {
463
- e(d), u(!1);
464
- }), p.on(l.SET_PARAMS, (d) => {
465
- s(d);
466
- }), p.on(l.SET_APP_ID, (d) => {
467
- const { appId: _ } = d;
468
- n(_);
469
- }), !f()) {
470
- const d = document.getElementsByTagName("html")[0].offsetHeight;
471
- d > 0 && window.name && p.emit(l.SET_HEIGHT, { height: d, id: window.name });
472
- }
473
- return f() && p.on(l.NAVIGATE_CHILD, (d) => {
474
- const { path: _ } = d, { navigation: y } = o;
475
- if (y) {
476
- const { navigate: Z } = y;
477
- Z({ path: _ });
478
- }
479
- }), () => {
480
- p.teardown();
481
- };
482
- }, [o]);
483
- const Y = {
484
- data: t,
485
- params: i,
486
- isLoading: a,
487
- invokeAction: c,
488
- navigate: Te,
489
- showModalDialog: Pe,
490
- showConfirmationDialog: Ee,
491
- showToast: Oe,
492
- showErrorMessage: De
493
- };
494
- return /* @__PURE__ */ ee(X.Provider, { value: Y, children: r });
495
- };
496
- export {
497
- Ce as AppClientProvider,
498
- Fe as useAppClient
499
- };
File without changes