@sap-ux/preview-middleware 0.23.48 → 0.23.50

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.
Files changed (36) hide show
  1. package/dist/client/adp/command-executor.js +99 -66
  2. package/dist/client/adp/controllers/AddCustomFragment.controller.js +120 -102
  3. package/dist/client/adp/controllers/AddFragment.controller.js +189 -163
  4. package/dist/client/adp/controllers/AddSubpage.controller.js +146 -137
  5. package/dist/client/adp/controllers/AddTableColumnFragments.controller.js +230 -188
  6. package/dist/client/adp/controllers/BaseDialog.controller.js +187 -164
  7. package/dist/client/adp/controllers/ControllerExtension.controller.js +329 -253
  8. package/dist/client/adp/controllers/ExtensionPoint.controller.js +158 -114
  9. package/dist/client/adp/extension-point.js +81 -60
  10. package/dist/client/adp/init.js +100 -99
  11. package/dist/client/adp/quick-actions/common/add-new-annotation-file.js +165 -147
  12. package/dist/client/adp/quick-actions/enablement-validator.js +0 -4
  13. package/dist/client/adp/quick-actions/fe-v2/create-table-custom-column.js +105 -100
  14. package/dist/client/adp/quick-actions/simple-quick-action-base.js +44 -40
  15. package/dist/client/adp/quick-actions/table-quick-action-base.js +309 -266
  16. package/dist/client/adp/sync-views-utils.js +119 -83
  17. package/dist/client/cpe/changes/flex-change.js +64 -48
  18. package/dist/client/cpe/changes/service.js +492 -367
  19. package/dist/client/cpe/communication-service.js +41 -29
  20. package/dist/client/cpe/connector-service.js +87 -64
  21. package/dist/client/cpe/context-menu-service.js +87 -74
  22. package/dist/client/cpe/control-data.js +353 -263
  23. package/dist/client/cpe/documentation.js +183 -126
  24. package/dist/client/cpe/init.js +69 -75
  25. package/dist/client/cpe/outline/service.js +60 -45
  26. package/dist/client/cpe/quick-actions/quick-action-definition.js +0 -4
  27. package/dist/client/cpe/quick-actions/quick-action-service.js +154 -129
  28. package/dist/client/cpe/rta-service.js +91 -69
  29. package/dist/client/cpe/selection.js +239 -187
  30. package/dist/client/cpe/types.js +0 -4
  31. package/dist/client/flp/init.js +403 -296
  32. package/dist/client/manifest.json +7 -4
  33. package/dist/client/thirdparty/@sap-ux-private/control-property-editor-common.js +444 -370
  34. package/dist/client/utils/info-center-message.js +59 -31
  35. package/dist/client/utils/version.js +128 -72
  36. package/package.json +4 -4
@@ -1,315 +1,422 @@
1
- 'use strict';
2
- sap.ui.define([
3
- 'sap/base/Log',
4
- 'open/ux/preview/client/thirdparty/@sap-ux-private/control-property-editor-common',
5
- 'sap/ui/core/IconPool',
6
- 'sap/base/i18n/ResourceBundle',
7
- '../adp/api-handler',
8
- '../utils/error',
9
- './initCdm',
10
- './initConnectors',
11
- '../utils/version',
12
- '../utils/info-center-message'
13
- ], function (Log, ___sap_ux_private_control_property_editor_common, IconPool, ResourceBundle, ___adp_api_handler, ___utils_error, __initCdm, __initConnectors, ___utils_version, ___utils_info_center_message) {
14
- 'use strict';
15
- function _interopRequireDefault(obj) {
16
- return obj && obj.__esModule && typeof obj.default !== 'undefined' ? obj.default : obj;
17
- }
18
- function __ui5_require_async(path) {
19
- return new Promise(function (resolve, reject) {
20
- sap.ui.require([path], function (module) {
21
- if (!(module && module.__esModule)) {
22
- module = module === null || !(typeof module === 'object' && path.endsWith('/library')) ? { default: module } : module;
23
- Object.defineProperty(module, '__esModule', { value: true });
24
- }
25
- resolve(module);
26
- }, function (err) {
27
- reject(err);
28
- });
29
- });
30
- }
31
- const MessageBarType = ___sap_ux_private_control_property_editor_common['MessageBarType'];
32
- const SCENARIO = ___sap_ux_private_control_property_editor_common['SCENARIO'];
33
- const getManifestAppdescr = ___adp_api_handler['getManifestAppdescr'];
34
- const getError = ___utils_error['getError'];
35
- const initCdm = _interopRequireDefault(__initCdm);
36
- const initConnectors = _interopRequireDefault(__initConnectors);
37
- const getUi5Version = ___utils_version['getUi5Version'];
38
- const isLowerThanMinimalUi5Version = ___utils_version['isLowerThanMinimalUi5Version'];
39
- const sendInfoCenterMessage = ___utils_info_center_message['sendInfoCenterMessage'];
40
- const UI5_LIBS = [
41
- 'sap.apf',
42
- 'sap.base',
43
- 'sap.chart',
44
- 'sap.collaboration',
45
- 'sap.f',
46
- 'sap.fe',
47
- 'sap.fileviewer',
48
- 'sap.gantt',
49
- 'sap.landvisz',
50
- 'sap.m',
51
- 'sap.ndc',
52
- 'sap.ovp',
53
- 'sap.rules',
54
- 'sap.suite',
55
- 'sap.tnt',
56
- 'sap.ui',
57
- 'sap.uiext',
58
- 'sap.ushell',
59
- 'sap.uxap',
60
- 'sap.viz',
61
- 'sap.webanalytics',
62
- 'sap.zen'
63
- ];
64
- function addKeys(dependency, customLibs) {
65
- Object.keys(dependency).forEach(function (key) {
66
- if (!UI5_LIBS.some(function (substring) {
67
- return key === substring || key.startsWith(substring + '.');
68
- })) {
69
- customLibs[key] = true;
1
+ "use strict";
2
+
3
+ sap.ui.define(["sap/base/Log", "open/ux/preview/client/thirdparty/@sap-ux-private/control-property-editor-common", "sap/ui/core/IconPool", "sap/base/i18n/ResourceBundle", "../adp/api-handler", "../utils/error", "./initCdm", "./initConnectors", "../utils/version", "../utils/info-center-message"], function (Log, ___sap_ux_private_control_property_editor_common, IconPool, ResourceBundle, ___adp_api_handler, ___utils_error, __initCdm, __initConnectors, ___utils_version, ___utils_info_center_message) {
4
+ "use strict";
5
+
6
+ function _interopRequireDefault(obj) {
7
+ return obj && obj.__esModule && typeof obj.default !== "undefined" ? obj.default : obj;
8
+ }
9
+ function __ui5_require_async(path) {
10
+ return new Promise(function (resolve, reject) {
11
+ sap.ui.require([path], function (module) {
12
+ if (!(module && module.__esModule)) {
13
+ module = module === null || !(typeof module === "object" && path.endsWith("/library")) ? {
14
+ default: module
15
+ } : module;
16
+ Object.defineProperty(module, "__esModule", {
17
+ value: true
18
+ });
19
+ }
20
+ resolve(module);
21
+ }, function (err) {
22
+ reject(err);
23
+ });
24
+ });
25
+ }
26
+ const MessageBarType = ___sap_ux_private_control_property_editor_common["MessageBarType"];
27
+ const SCENARIO = ___sap_ux_private_control_property_editor_common["SCENARIO"];
28
+ const getManifestAppdescr = ___adp_api_handler["getManifestAppdescr"];
29
+ const getError = ___utils_error["getError"];
30
+ const initCdm = _interopRequireDefault(__initCdm);
31
+ const initConnectors = _interopRequireDefault(__initConnectors);
32
+ const getUi5Version = ___utils_version["getUi5Version"];
33
+ const isLowerThanMinimalUi5Version = ___utils_version["isLowerThanMinimalUi5Version"];
34
+ const sendInfoCenterMessage = ___utils_info_center_message["sendInfoCenterMessage"];
35
+ /**
36
+ * SAPUI5 delivered namespaces from https://ui5.sap.com/#/api/sap
37
+ */
38
+ const UI5_LIBS = ['sap.apf', 'sap.base', 'sap.chart', 'sap.collaboration', 'sap.f', 'sap.fe', 'sap.fileviewer', 'sap.gantt', 'sap.landvisz', 'sap.m', 'sap.ndc', 'sap.ovp', 'sap.rules', 'sap.suite', 'sap.tnt', 'sap.ui', 'sap.uiext', 'sap.ushell', 'sap.uxap', 'sap.viz', 'sap.webanalytics', 'sap.zen'];
39
+ /**
40
+ * Check whether a specific dependency is a custom library, and if yes, add it to the map.
41
+ *
42
+ * @param dependency dependency from the manifest
43
+ * @param customLibs map containing the required custom libraries
44
+ */
45
+ function addKeys(dependency, customLibs) {
46
+ Object.keys(dependency).forEach(function (key) {
47
+ // ignore libs or Components that start with SAPUI5 delivered namespaces
48
+ if (!UI5_LIBS.some(function (substring) {
49
+ return key === substring || key.startsWith(substring + '.');
50
+ })) {
51
+ customLibs[key] = true;
52
+ }
53
+ });
54
+ }
55
+
56
+ /**
57
+ * Check whether a specific ComponentUsage is a custom component, and if yes, add it to the map.
58
+ *
59
+ * @param compUsages ComponentUsage from the manifest
60
+ * @param customLibs map containing the required custom libraries
61
+ */
62
+ function getComponentUsageNames(compUsages, customLibs) {
63
+ const compNames = Object.keys(compUsages).map(function (compUsageKey) {
64
+ return compUsages[compUsageKey].name;
65
+ });
66
+ compNames.forEach(function (key) {
67
+ // ignore libs or Components that start with SAPUI5 delivered namespaces
68
+ if (!UI5_LIBS.some(function (substring) {
69
+ return key === substring || key.startsWith(substring + '.');
70
+ })) {
71
+ customLibs[key] = true;
72
+ }
73
+ });
74
+ }
75
+
76
+ /**
77
+ * Fetch the manifest for all the given application urls and generate a string containing all required custom library ids.
78
+ *
79
+ * @param appUrls urls pointing to included applications
80
+ * @returns Promise of a comma separated list of all required libraries.
81
+ */
82
+ async function getManifestLibs(appUrls) {
83
+ const result = {};
84
+ const promises = [];
85
+ for (const url of appUrls) {
86
+ promises.push(fetch(`${url}/manifest.json`).then(async resp => {
87
+ const manifest = await resp.json();
88
+ if (manifest) {
89
+ if (manifest['sap.ui5']?.dependencies) {
90
+ if (manifest['sap.ui5'].dependencies.libs) {
91
+ addKeys(manifest['sap.ui5'].dependencies.libs, result);
70
92
  }
71
- });
72
- }
73
- function getComponentUsageNames(compUsages, customLibs) {
74
- const compNames = Object.keys(compUsages).map(function (compUsageKey) {
75
- return compUsages[compUsageKey].name;
76
- });
77
- compNames.forEach(function (key) {
78
- if (!UI5_LIBS.some(function (substring) {
79
- return key === substring || key.startsWith(substring + '.');
80
- })) {
81
- customLibs[key] = true;
93
+ if (manifest['sap.ui5'].dependencies.components) {
94
+ addKeys(manifest['sap.ui5'].dependencies.components, result);
82
95
  }
83
- });
84
- }
85
- async function getManifestLibs(appUrls) {
86
- const result = {};
87
- const promises = [];
88
- for (const url of appUrls) {
89
- promises.push(fetch(`${ url }/manifest.json`).then(async resp => {
90
- const manifest = await resp.json();
91
- if (manifest) {
92
- if (manifest['sap.ui5']?.dependencies) {
93
- if (manifest['sap.ui5'].dependencies.libs) {
94
- addKeys(manifest['sap.ui5'].dependencies.libs, result);
95
- }
96
- if (manifest['sap.ui5'].dependencies.components) {
97
- addKeys(manifest['sap.ui5'].dependencies.components, result);
98
- }
99
- }
100
- if (manifest['sap.ui5']?.componentUsages) {
101
- getComponentUsageNames(manifest['sap.ui5'].componentUsages, result);
102
- }
103
- }
104
- }));
96
+ }
97
+ if (manifest['sap.ui5']?.componentUsages) {
98
+ getComponentUsageNames(manifest['sap.ui5'].componentUsages, result);
99
+ }
105
100
  }
106
- return Promise.all(promises).then(() => Object.keys(result).join(','));
101
+ }));
107
102
  }
108
- function registerModules(dataFromAppIndex) {
109
- Object.keys(dataFromAppIndex).forEach(function (moduleDefinitionKey) {
110
- const moduleDefinition = dataFromAppIndex[moduleDefinitionKey];
111
- if (moduleDefinition?.dependencies) {
112
- moduleDefinition.dependencies.forEach(function (dependency) {
113
- if (dependency.url && dependency.url.length > 0 && dependency.type === 'UI5LIB') {
114
- Log.info('Registering Library ' + dependency.componentId + ' from server ' + dependency.url);
115
- const compId = dependency.componentId.replace(/\./g, '/');
116
- const config = { paths: {} };
117
- config.paths[compId] = dependency.url;
118
- sap.ui.loader.config(config);
119
- }
120
- });
121
- }
103
+ return Promise.all(promises).then(() => Object.keys(result).join(','));
104
+ }
105
+
106
+ /**
107
+ * Register the custom libraries and their url with the UI5 loader.
108
+ *
109
+ * @param dataFromAppIndex data returned from the app index service
110
+ */
111
+ function registerModules(dataFromAppIndex) {
112
+ Object.keys(dataFromAppIndex).forEach(function (moduleDefinitionKey) {
113
+ const moduleDefinition = dataFromAppIndex[moduleDefinitionKey];
114
+ if (moduleDefinition?.dependencies) {
115
+ moduleDefinition.dependencies.forEach(function (dependency) {
116
+ if (dependency.url && dependency.url.length > 0 && dependency.type === 'UI5LIB') {
117
+ Log.info('Registering Library ' + dependency.componentId + ' from server ' + dependency.url);
118
+ const compId = dependency.componentId.replace(/\./g, '/');
119
+ const config = {
120
+ paths: {}
121
+ };
122
+ config.paths[compId] = dependency.url;
123
+ sap.ui.loader.config(config);
124
+ }
122
125
  });
126
+ }
127
+ });
128
+ }
129
+
130
+ /**
131
+ * Fetch the app state from the given application urls, then reset the app state.
132
+ *
133
+ * @param container the UShell container
134
+ */
135
+ async function resetAppState(container) {
136
+ const urlParams = new URLSearchParams(window.location.hash);
137
+ const appStateValue = urlParams.get('sap-iapp-state') ?? urlParams.get('/?sap-iapp-state');
138
+ if (appStateValue) {
139
+ const appStateService = await container.getServiceAsync('AppState');
140
+ appStateService.deleteAppState(appStateValue);
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Fetch the manifest from the given application urls, then parse them for custom libs, and finally request their urls.
146
+ *
147
+ * @param appUrls application urls
148
+ * @param urlParams URLSearchParams object
149
+ * @returns returns a promise when the registration is completed.
150
+ */
151
+ async function registerComponentDependencyPaths(appUrls, urlParams) {
152
+ const libs = await getManifestLibs(appUrls);
153
+ if (libs && libs.length > 0) {
154
+ let url = '/sap/bc/ui2/app_index/ui5_app_info?id=' + libs;
155
+ const sapClient = urlParams.get('sap-client');
156
+ if (sapClient && sapClient.length === 3) {
157
+ url = url + '&sap-client=' + sapClient;
158
+ }
159
+ const response = await fetch(url);
160
+ try {
161
+ registerModules(await response.json());
162
+ } catch (error) {
163
+ Log.error(`Registering of reuse libs failed. Error:${error}`);
164
+ }
123
165
  }
124
- async function resetAppState(container) {
125
- const urlParams = new URLSearchParams(window.location.hash);
126
- const appStateValue = urlParams.get('sap-iapp-state') ?? urlParams.get('/?sap-iapp-state');
127
- if (appStateValue) {
128
- const appStateService = await container.getServiceAsync('AppState');
129
- appStateService.deleteAppState(appStateValue);
166
+ }
167
+
168
+ /**
169
+ * Register SAP fonts that are also registered in a productive Fiori launchpad.
170
+ */
171
+ function registerSAPFonts() {
172
+ //Fiori Theme font family and URI
173
+ const fioriTheme = {
174
+ fontFamily: 'SAP-icons-TNT',
175
+ fontURI: sap.ui.require.toUrl('sap/tnt/themes/base/fonts/')
176
+ };
177
+ //Registering to the icon pool
178
+ IconPool.registerFont(fioriTheme);
179
+ //SAP Business Suite Theme font family and URI
180
+ const suiteTheme = {
181
+ fontFamily: 'BusinessSuiteInAppSymbols',
182
+ fontURI: sap.ui.require.toUrl('sap/ushell/themes/base/fonts/')
183
+ };
184
+ //Registering to the icon pool
185
+ IconPool.registerFont(suiteTheme);
186
+ }
187
+
188
+ /**
189
+ * Create Resource Bundle based on the scenario.
190
+ *
191
+ * @param scenario to be used for the resource bundle.
192
+ */
193
+ async function loadI18nResourceBundle(scenario) {
194
+ if (scenario === SCENARIO.AdaptationProject) {
195
+ const manifest = await getManifestAppdescr();
196
+ const enhanceWith = manifest.content.filter(content => content.texts?.i18n).map(content => ({
197
+ bundleUrl: `../${content.texts.i18n}`
198
+ }));
199
+ return ResourceBundle.create({
200
+ url: '../i18n/i18n.properties',
201
+ enhanceWith
202
+ });
203
+ }
204
+ return ResourceBundle.create({
205
+ url: 'i18n/i18n.properties'
206
+ });
207
+ }
208
+
209
+ /**
210
+ * Read the application title from the resource bundle and set it as document title.
211
+ *
212
+ * @param resourceBundle resource bundle to read the title from.
213
+ * @param i18nKey optional parameter to define the i18n key to be used for the title.
214
+ */
215
+ function setI18nTitle(resourceBundle) {
216
+ let i18nKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'appTitle';
217
+ if (resourceBundle.hasText(i18nKey)) {
218
+ document.title = resourceBundle.getText(i18nKey) ?? document.title;
219
+ }
220
+ }
221
+
222
+ /**
223
+ * This function dynamically adds a "Generate Card" action to the SAP Fiori Launchpad for the given component instance.
224
+ *
225
+ * @param componentInstance - The instance of the component for which the card generation action is being added.
226
+ * @param container - The SAP Fiori Launchpad container instance used to access services.
227
+ */
228
+ function addCardGenerationUserAction(componentInstance, container) {
229
+ sap.ui.require(['sap/cards/ap/generator/CardGenerator'], async CardGenerator => {
230
+ const extensionService = await container.getServiceAsync('Extension');
231
+ const controlProperties = {
232
+ icon: 'sap-icon://add',
233
+ id: 'generate_card',
234
+ text: 'Generate Card',
235
+ tooltip: 'Generate Card',
236
+ press: () => {
237
+ CardGenerator.initializeAsync(componentInstance);
130
238
  }
239
+ };
240
+ const parameters = {
241
+ controlType: 'sap.ushell.ui.launchpad.ActionItem'
242
+ };
243
+ const generateCardAction = await extensionService.createUserAction(controlProperties, parameters);
244
+ generateCardAction.showForCurrentApp();
245
+ });
246
+ }
247
+
248
+ /**
249
+ * Apply additional configuration and initialize sandbox.
250
+ *
251
+ * @param params init parameters read from the script tag
252
+ * @param params.appUrls JSON containing a string array of application urls
253
+ * @param params.flex JSON containing the flex configuration
254
+ * @param params.customInit path to the custom init module to be called
255
+ * @param params.enhancedHomePage boolean indicating if enhanced homepage is enabled
256
+ * @returns promise
257
+ */
258
+ async function init(_ref) {
259
+ let {
260
+ appUrls,
261
+ flex,
262
+ customInit,
263
+ enhancedHomePage,
264
+ enableCardGenerator
265
+ } = _ref;
266
+ // Set CDM configuration before importing ushell container
267
+ // to ensure proper configuration pickup during bootstrap
268
+ if (enhancedHomePage) {
269
+ initCdm();
131
270
  }
132
- async function registerComponentDependencyPaths(appUrls, urlParams) {
133
- const libs = await getManifestLibs(appUrls);
134
- if (libs && libs.length > 0) {
135
- let url = '/sap/bc/ui2/app_index/ui5_app_info?id=' + libs;
136
- const sapClient = urlParams.get('sap-client');
137
- if (sapClient && sapClient.length === 3) {
138
- url = url + '&sap-client=' + sapClient;
139
- }
140
- const response = await fetch(url);
271
+ const urlParams = new URLSearchParams(window.location.search);
272
+ const container = sap?.ushell?.Container ?? (await __ui5_require_async('sap/ushell/Container')).default;
273
+ let scenario = '';
274
+ const ui5VersionInfo = await getUi5Version();
275
+ // Register RTA if configured
276
+ if (flex) {
277
+ const flexSettings = JSON.parse(flex);
278
+ scenario = flexSettings.scenario;
279
+ container.attachRendererCreatedEvent(async function () {
280
+ const lifecycleService = await container.getServiceAsync('AppLifeCycle');
281
+ lifecycleService.attachAppLoaded(event => {
282
+ const view = event.getParameter('componentInstance');
283
+ const pluginScript = flexSettings.pluginScript ?? '';
284
+ let libs = [];
285
+ if (isLowerThanMinimalUi5Version(ui5VersionInfo, {
286
+ major: 1,
287
+ minor: 72
288
+ })) {
289
+ libs.push('open/ux/preview/client/flp/initRta');
290
+ } else {
291
+ libs.push('sap/ui/rta/api/startAdaptation');
292
+ }
293
+ if (flexSettings.pluginScript) {
294
+ libs.push(pluginScript);
295
+ delete flexSettings.pluginScript;
296
+ }
297
+ const options = {
298
+ rootControl: view,
299
+ validateAppVersion: false,
300
+ flexSettings
301
+ };
302
+ sap.ui.require(libs,
303
+ // eslint-disable-next-line no-shadow
304
+ async function (startAdaptation, pluginScript) {
141
305
  try {
142
- registerModules(await response.json());
306
+ await startAdaptation(options, pluginScript);
143
307
  } catch (error) {
144
- Log.error(`Registering of reuse libs failed. Error:${ error }`);
308
+ await sendInfoCenterMessage({
309
+ title: {
310
+ key: 'FLP_ADAPTATION_START_FAILED_TITLE'
311
+ },
312
+ description: getError(error).message,
313
+ type: MessageBarType.error
314
+ });
315
+ await handleHigherLayerChanges(error, ui5VersionInfo);
145
316
  }
146
- }
317
+ });
318
+ });
319
+ });
147
320
  }
148
- function registerSAPFonts() {
149
- const fioriTheme = {
150
- fontFamily: 'SAP-icons-TNT',
151
- fontURI: sap.ui.require.toUrl('sap/tnt/themes/base/fonts/')
152
- };
153
- IconPool.registerFont(fioriTheme);
154
- const suiteTheme = {
155
- fontFamily: 'BusinessSuiteInAppSymbols',
156
- fontURI: sap.ui.require.toUrl('sap/ushell/themes/base/fonts/')
157
- };
158
- IconPool.registerFont(suiteTheme);
321
+ if (enableCardGenerator && !isLowerThanMinimalUi5Version(ui5VersionInfo, {
322
+ major: 1,
323
+ minor: 121
324
+ })) {
325
+ container.attachRendererCreatedEvent(async function () {
326
+ const lifecycleService = await container.getServiceAsync('AppLifeCycle');
327
+ lifecycleService.attachAppLoaded(event => {
328
+ const componentInstance = event.getParameter('componentInstance');
329
+ addCardGenerationUserAction(componentInstance, container);
330
+ });
331
+ });
332
+ } else {
333
+ Log.warning('Card generator is not supported for the current UI5 version.');
159
334
  }
160
- async function loadI18nResourceBundle(scenario) {
161
- if (scenario === SCENARIO.AdaptationProject) {
162
- const manifest = await getManifestAppdescr();
163
- const enhanceWith = manifest.content.filter(content => content.texts?.i18n).map(content => ({ bundleUrl: `../${ content.texts.i18n }` }));
164
- return ResourceBundle.create({
165
- url: '../i18n/i18n.properties',
166
- enhanceWith
167
- });
168
- }
169
- return ResourceBundle.create({ url: 'i18n/i18n.properties' });
335
+
336
+ // reset app state if requested
337
+ if (urlParams.get('fiori-tools-iapp-state')?.toLocaleLowerCase() !== 'true') {
338
+ await resetAppState(container);
170
339
  }
171
- function setI18nTitle(resourceBundle) {
172
- let i18nKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'appTitle';
173
- if (resourceBundle.hasText(i18nKey)) {
174
- document.title = resourceBundle.getText(i18nKey) ?? document.title;
175
- }
340
+
341
+ // Load custom library paths if configured
342
+ if (appUrls) {
343
+ await registerComponentDependencyPaths(JSON.parse(appUrls) ?? [], urlParams);
176
344
  }
177
- function addCardGenerationUserAction(componentInstance, container) {
178
- sap.ui.require(['sap/cards/ap/generator/CardGenerator'], async CardGenerator => {
179
- const extensionService = await container.getServiceAsync('Extension');
180
- const controlProperties = {
181
- icon: 'sap-icon://add',
182
- id: 'generate_card',
183
- text: 'Generate Card',
184
- tooltip: 'Generate Card',
185
- press: () => {
186
- CardGenerator.initializeAsync(componentInstance);
187
- }
188
- };
189
- const parameters = { controlType: 'sap.ushell.ui.launchpad.ActionItem' };
190
- const generateCardAction = await extensionService.createUserAction(controlProperties, parameters);
191
- generateCardAction.showForCurrentApp();
192
- });
345
+
346
+ // Load rta connector
347
+ await initConnectors();
348
+
349
+ // Load custom initialization module
350
+ if (customInit) {
351
+ sap.ui.require([customInit]);
193
352
  }
194
- async function init(_ref) {
195
- let {appUrls, flex, customInit, enhancedHomePage, enableCardGenerator} = _ref;
196
- if (enhancedHomePage) {
197
- initCdm();
198
- }
199
- const urlParams = new URLSearchParams(window.location.search);
200
- const container = sap?.ushell?.Container ?? (await __ui5_require_async('sap/ushell/Container')).default;
201
- let scenario = '';
202
- const ui5VersionInfo = await getUi5Version();
203
- if (flex) {
204
- const flexSettings = JSON.parse(flex);
205
- scenario = flexSettings.scenario;
206
- container.attachRendererCreatedEvent(async function () {
207
- const lifecycleService = await container.getServiceAsync('AppLifeCycle');
208
- lifecycleService.attachAppLoaded(event => {
209
- const view = event.getParameter('componentInstance');
210
- const pluginScript = flexSettings.pluginScript ?? '';
211
- let libs = [];
212
- if (isLowerThanMinimalUi5Version(ui5VersionInfo, {
213
- major: 1,
214
- minor: 72
215
- })) {
216
- libs.push('open/ux/preview/client/flp/initRta');
217
- } else {
218
- libs.push('sap/ui/rta/api/startAdaptation');
219
- }
220
- if (flexSettings.pluginScript) {
221
- libs.push(pluginScript);
222
- delete flexSettings.pluginScript;
223
- }
224
- const options = {
225
- rootControl: view,
226
- validateAppVersion: false,
227
- flexSettings
228
- };
229
- sap.ui.require(libs, async function (startAdaptation, pluginScript) {
230
- try {
231
- await startAdaptation(options, pluginScript);
232
- } catch (error) {
233
- await sendInfoCenterMessage({
234
- title: { key: 'FLP_ADAPTATION_START_FAILED_TITLE' },
235
- description: getError(error).message,
236
- type: MessageBarType.error
237
- });
238
- await handleHigherLayerChanges(error, ui5VersionInfo);
239
- }
240
- });
241
- });
242
- });
243
- }
244
- if (enableCardGenerator && !isLowerThanMinimalUi5Version(ui5VersionInfo, {
245
- major: 1,
246
- minor: 121
247
- })) {
248
- container.attachRendererCreatedEvent(async function () {
249
- const lifecycleService = await container.getServiceAsync('AppLifeCycle');
250
- lifecycleService.attachAppLoaded(event => {
251
- const componentInstance = event.getParameter('componentInstance');
252
- addCardGenerationUserAction(componentInstance, container);
253
- });
254
- });
255
- } else {
256
- Log.warning('Card generator is not supported for the current UI5 version.');
257
- }
258
- if (urlParams.get('fiori-tools-iapp-state')?.toLocaleLowerCase() !== 'true') {
259
- await resetAppState(container);
260
- }
261
- if (appUrls) {
262
- await registerComponentDependencyPaths(JSON.parse(appUrls) ?? [], urlParams);
263
- }
264
- await initConnectors();
265
- if (customInit) {
266
- sap.ui.require([customInit]);
267
- }
268
- const resourceBundle = await loadI18nResourceBundle(scenario);
269
- setI18nTitle(resourceBundle);
270
- registerSAPFonts();
271
- if (enhancedHomePage) {
272
- await container.init('cdm');
273
- }
274
- const renderer = ui5VersionInfo.major < 2 && !ui5VersionInfo.label?.includes('legacy-free') ? await container.createRenderer(undefined, true) : await container.createRendererInternal(undefined, true);
275
- renderer.placeAt('content');
353
+
354
+ // init
355
+ const resourceBundle = await loadI18nResourceBundle(scenario);
356
+ setI18nTitle(resourceBundle);
357
+ registerSAPFonts();
358
+ if (enhancedHomePage) {
359
+ await container.init('cdm');
276
360
  }
277
- const bootstrapConfig = document.getElementById('sap-ui-bootstrap');
278
- if (bootstrapConfig) {
279
- init({
280
- appUrls: bootstrapConfig.getAttribute('data-open-ux-preview-libs-manifests'),
281
- flex: bootstrapConfig.getAttribute('data-open-ux-preview-flex-settings'),
282
- customInit: bootstrapConfig.getAttribute('data-open-ux-preview-customInit'),
283
- enhancedHomePage: !!bootstrapConfig.getAttribute('data-open-ux-preview-enhanced-homepage'),
284
- enableCardGenerator: !!bootstrapConfig.getAttribute('data-open-ux-preview-enable-card-generator')
285
- }).catch(e => {
286
- const error = getError(e);
287
- Log.error('Sandbox initialization failed: ' + error.message);
361
+ const renderer = ui5VersionInfo.major < 2 && !ui5VersionInfo.label?.includes('legacy-free') ? await container.createRenderer(undefined, true) : await container.createRendererInternal(undefined, true);
362
+ renderer.placeAt('content');
363
+ }
364
+
365
+ // eslint-disable-next-line fiori-custom/sap-no-dom-access,fiori-custom/sap-browser-api-warning
366
+ const bootstrapConfig = document.getElementById('sap-ui-bootstrap');
367
+ if (bootstrapConfig) {
368
+ init({
369
+ appUrls: bootstrapConfig.getAttribute('data-open-ux-preview-libs-manifests'),
370
+ flex: bootstrapConfig.getAttribute('data-open-ux-preview-flex-settings'),
371
+ customInit: bootstrapConfig.getAttribute('data-open-ux-preview-customInit'),
372
+ enhancedHomePage: !!bootstrapConfig.getAttribute('data-open-ux-preview-enhanced-homepage'),
373
+ enableCardGenerator: !!bootstrapConfig.getAttribute('data-open-ux-preview-enable-card-generator')
374
+ }).catch(e => {
375
+ const error = getError(e);
376
+ Log.error('Sandbox initialization failed: ' + error.message);
377
+ });
378
+ }
379
+
380
+ /**
381
+ * Handle higher layer changes when starting UI Adaptation.
382
+ * When RTA detects higher layer changes an error with Reload triggered text is thrown, the RTA instance is destroyed and the application is reloaded.
383
+ * For UI5 version lower than 1.84.0 RTA is showing a popup with notification text about the detection of higher layer changes.
384
+ *
385
+ * @param error the error thrown when there are higher layer changes when starting UI Adaptation.
386
+ * @param ui5VersionInfo ui5 version info
387
+ */
388
+ async function handleHigherLayerChanges(error, ui5VersionInfo) {
389
+ const err = getError(error);
390
+ if (err.message.includes('Reload triggered')) {
391
+ if (!isLowerThanMinimalUi5Version(ui5VersionInfo, {
392
+ major: 1,
393
+ minor: 84
394
+ })) {
395
+ await sendInfoCenterMessage({
396
+ title: {
397
+ key: 'HIGHER_LAYER_CHANGES_TITLE'
398
+ },
399
+ description: {
400
+ key: 'HIGHER_LAYER_CHANGES_INFO_MESSAGE'
401
+ },
402
+ type: MessageBarType.warning
288
403
  });
404
+ }
405
+
406
+ // eslint-disable-next-line fiori-custom/sap-no-location-reload
407
+ window.location.reload();
289
408
  }
290
- async function handleHigherLayerChanges(error, ui5VersionInfo) {
291
- const err = getError(error);
292
- if (err.message.includes('Reload triggered')) {
293
- if (!isLowerThanMinimalUi5Version(ui5VersionInfo, {
294
- major: 1,
295
- minor: 84
296
- })) {
297
- await sendInfoCenterMessage({
298
- title: { key: 'HIGHER_LAYER_CHANGES_TITLE' },
299
- description: { key: 'HIGHER_LAYER_CHANGES_INFO_MESSAGE' },
300
- type: MessageBarType.warning
301
- });
302
- }
303
- window.location.reload();
304
- }
305
- }
306
- var __exports = { __esModule: true };
307
- __exports.resetAppState = resetAppState;
308
- __exports.registerComponentDependencyPaths = registerComponentDependencyPaths;
309
- __exports.registerSAPFonts = registerSAPFonts;
310
- __exports.loadI18nResourceBundle = loadI18nResourceBundle;
311
- __exports.setI18nTitle = setI18nTitle;
312
- __exports.init = init;
313
- __exports.handleHigherLayerChanges = handleHigherLayerChanges;
314
- return __exports;
315
- });
409
+ }
410
+ var __exports = {
411
+ __esModule: true
412
+ };
413
+ __exports.resetAppState = resetAppState;
414
+ __exports.registerComponentDependencyPaths = registerComponentDependencyPaths;
415
+ __exports.registerSAPFonts = registerSAPFonts;
416
+ __exports.loadI18nResourceBundle = loadI18nResourceBundle;
417
+ __exports.setI18nTitle = setI18nTitle;
418
+ __exports.init = init;
419
+ __exports.handleHigherLayerChanges = handleHigherLayerChanges;
420
+ return __exports;
421
+ });
422
+ //# sourceMappingURL=init.js.map