@sap-ux/preview-middleware 0.18.20 → 0.18.23

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 (72) hide show
  1. package/dist/client/adp/api-handler.js +153 -153
  2. package/dist/client/adp/api-handler.ts +2 -2
  3. package/dist/client/adp/command-executor.js +75 -75
  4. package/dist/client/adp/control-utils.js +44 -44
  5. package/dist/client/adp/controllers/BaseDialog.controller.js +187 -187
  6. package/dist/client/adp/controllers/ControllerExtension.controller.js +209 -209
  7. package/dist/client/adp/controllers/ExtensionPoint.controller.js +138 -138
  8. package/dist/client/adp/controllers/FileExistsDialog.controller.js +66 -66
  9. package/dist/client/adp/dialog-factory.js +133 -133
  10. package/dist/client/adp/init-dialogs.js +107 -107
  11. package/dist/client/adp/quick-actions/common/add-controller-to-page.js +55 -55
  12. package/dist/client/adp/quick-actions/common/add-new-annotation-file.js +24 -7
  13. package/dist/client/adp/quick-actions/common/add-new-annotation-file.ts +25 -7
  14. package/dist/client/adp/quick-actions/common/add-new-subpage.js +134 -138
  15. package/dist/client/adp/quick-actions/common/add-new-subpage.ts +0 -5
  16. package/dist/client/adp/quick-actions/common/create-page-action.js +51 -51
  17. package/dist/client/adp/quick-actions/common/op-add-custom-section.js +36 -36
  18. package/dist/client/adp/quick-actions/common/op-add-header-field.js +61 -61
  19. package/dist/client/adp/quick-actions/common/utils.js +18 -18
  20. package/dist/client/adp/quick-actions/control-types.js +21 -21
  21. package/dist/client/adp/quick-actions/dialog-enablement-validator.js +24 -24
  22. package/dist/client/adp/quick-actions/enablement-validator.js +4 -4
  23. package/dist/client/adp/quick-actions/fe-v2/change-table-columns.js +101 -101
  24. package/dist/client/adp/quick-actions/fe-v2/create-table-action.js +104 -104
  25. package/dist/client/adp/quick-actions/fe-v2/create-table-custom-column.js +96 -96
  26. package/dist/client/adp/quick-actions/fe-v2/lr-enable-semantic-date-range-filter-bar.js +78 -78
  27. package/dist/client/adp/quick-actions/fe-v2/lr-enable-table-filtering.js +77 -77
  28. package/dist/client/adp/quick-actions/fe-v2/lr-enable-variant-management.js +69 -69
  29. package/dist/client/adp/quick-actions/fe-v2/lr-toggle-clear-filter-bar.js +59 -59
  30. package/dist/client/adp/quick-actions/fe-v2/op-enable-empty-row-mode.js +93 -93
  31. package/dist/client/adp/quick-actions/fe-v2/op-enable-variant-management.js +84 -84
  32. package/dist/client/adp/quick-actions/fe-v2/registry.js +76 -76
  33. package/dist/client/adp/quick-actions/fe-v2/utils.js +116 -116
  34. package/dist/client/adp/quick-actions/fe-v4/change-table-columns.js +73 -73
  35. package/dist/client/adp/quick-actions/fe-v4/create-table-action.js +50 -50
  36. package/dist/client/adp/quick-actions/fe-v4/create-table-custom-column.js +46 -46
  37. package/dist/client/adp/quick-actions/fe-v4/enable-variant-management.js +81 -81
  38. package/dist/client/adp/quick-actions/fe-v4/lr-enable-semantic-date-range-filter-bar.js +56 -56
  39. package/dist/client/adp/quick-actions/fe-v4/lr-enable-table-filtering.js +82 -82
  40. package/dist/client/adp/quick-actions/fe-v4/lr-toggle-clear-filter-bar.js +53 -53
  41. package/dist/client/adp/quick-actions/fe-v4/op-enable-empty-row-mode.js +89 -89
  42. package/dist/client/adp/quick-actions/fe-v4/registry.js +58 -58
  43. package/dist/client/adp/quick-actions/fe-v4/utils.js +47 -47
  44. package/dist/client/adp/quick-actions/load.js +44 -44
  45. package/dist/client/adp/quick-actions/quick-action-base.js +53 -53
  46. package/dist/client/adp/utils.js +160 -160
  47. package/dist/client/cpe/changes/index.js +10 -10
  48. package/dist/client/cpe/changes/validator.js +39 -39
  49. package/dist/client/cpe/documentation.js +164 -164
  50. package/dist/client/cpe/feature-service.js +36 -36
  51. package/dist/client/cpe/logger.js +30 -30
  52. package/dist/client/cpe/outline/editable.js +37 -37
  53. package/dist/client/cpe/outline/nodes.js +222 -222
  54. package/dist/client/cpe/quick-actions/quick-action-definition.js +4 -4
  55. package/dist/client/cpe/quick-actions/registry.js +143 -143
  56. package/dist/client/cpe/quick-actions/utils.js +92 -92
  57. package/dist/client/cpe/types.js +4 -4
  58. package/dist/client/cpe/ui5-utils.js +33 -33
  59. package/dist/client/cpe/utils.js +138 -138
  60. package/dist/client/flp/WorkspaceConnector.js +86 -86
  61. package/dist/client/flp/common.js +28 -28
  62. package/dist/client/flp/enableFakeConnector.js +83 -83
  63. package/dist/client/flp/initConnectors.js +28 -28
  64. package/dist/client/flp/initRta.js +178 -178
  65. package/dist/client/i18n.js +56 -56
  66. package/dist/client/utils/application.js +32 -32
  67. package/dist/client/utils/core.js +68 -68
  68. package/dist/client/utils/error.js +19 -19
  69. package/dist/client/utils/fe-v2.js +56 -56
  70. package/dist/client/utils/fe-v4.js +141 -141
  71. package/dist/client/utils/version.js +104 -104
  72. package/package.json +6 -6
@@ -1,85 +1,85 @@
1
- "use strict";
2
-
3
- sap.ui.define(["sap/ui/fl/LrepConnector", "sap/ui/fl/FakeLrepConnector", "./common"], function (LrepConnector, FakeLrepConnector, ___common) {
4
- "use strict";
5
-
6
- const CHANGES_API_PATH = ___common["CHANGES_API_PATH"];
7
- const getFlexSettings = ___common["getFlexSettings"];
8
- /**
9
- * Processes an array of FlexChange objects.
10
- * It updates each change object with settings and sends them to a API endpoint.
11
- *
12
- * @param {FlexChange | FlexChange[]} changes - Array of FlexChange objects to be processed.
13
- * @returns {Promise<void>} A promise that resolves when all changes are processed.
14
- */
15
- async function create(changes) {
16
- const settings = getFlexSettings();
17
- await Promise.all((Array.isArray(changes) ? changes : [changes]).map(change => {
18
- if (settings) {
19
- change.support ??= {};
20
- change.support.generator = settings.generator;
21
- }
22
- if (typeof FakeLrepConnector.fileChangeRequestNotifier === 'function' && change.fileName) {
23
- try {
24
- FakeLrepConnector.fileChangeRequestNotifier(change.fileName, 'create', change);
25
- } catch (e) {
26
- // exceptions in the listener call are ignored
27
- }
28
- }
29
- return fetch(CHANGES_API_PATH, {
30
- method: 'POST',
31
- body: JSON.stringify(change, null, 2),
32
- headers: {
33
- 'content-type': 'application/json'
34
- }
35
- });
36
- }));
37
- }
38
-
39
- /**
40
- * Loads changes from a given path and processes them using an LrepConnector instance.
41
- * The changes are then formatted and returned in a specified structure.
42
- *
43
- * @returns {Promise<LoadChangesResult>} A promise that resolves to an object of type LoadChangesResult.
44
- */
45
- async function loadChanges() {
46
- const lrep = new LrepConnector();
47
- const response = await fetch(CHANGES_API_PATH, {
48
- method: 'GET',
49
- headers: {
50
- 'content-type': 'application/json'
51
- }
52
- });
53
- const changes = await response.json();
54
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
55
- args[_key] = arguments[_key];
56
- }
57
- return LrepConnector.prototype.loadChanges.apply(lrep, args).then(res => {
58
- res.changes.changes = Object.values(changes);
59
- return res;
60
- });
61
- }
62
-
63
- /**
64
- * Configures and enables the FakeLrepConnector based on the SAP UI5 version.
65
- * If the minor version of the SAP UI5 is less than 72, this function extends
66
- * the FakeLrepConnector's prototype with specific methods and enables the fake connector.
67
- *
68
- * Assumes the existence of a global 'sap' object with a 'ui.version' property,
69
- * and global jQuery object with 'extend' method.
70
- *
71
- * @returns {void}
72
- */
73
- var __exports = function () {
74
- jQuery.extend(FakeLrepConnector.prototype, {
75
- create,
76
- loadChanges,
77
- loadSettings: () => Promise.resolve()
78
- });
79
- FakeLrepConnector.enableFakeConnector();
80
- };
81
- __exports.create = create;
82
- __exports.loadChanges = loadChanges;
83
- return __exports;
1
+ "use strict";
2
+
3
+ sap.ui.define(["sap/ui/fl/LrepConnector", "sap/ui/fl/FakeLrepConnector", "./common"], function (LrepConnector, FakeLrepConnector, ___common) {
4
+ "use strict";
5
+
6
+ const CHANGES_API_PATH = ___common["CHANGES_API_PATH"];
7
+ const getFlexSettings = ___common["getFlexSettings"];
8
+ /**
9
+ * Processes an array of FlexChange objects.
10
+ * It updates each change object with settings and sends them to a API endpoint.
11
+ *
12
+ * @param {FlexChange | FlexChange[]} changes - Array of FlexChange objects to be processed.
13
+ * @returns {Promise<void>} A promise that resolves when all changes are processed.
14
+ */
15
+ async function create(changes) {
16
+ const settings = getFlexSettings();
17
+ await Promise.all((Array.isArray(changes) ? changes : [changes]).map(change => {
18
+ if (settings) {
19
+ change.support ??= {};
20
+ change.support.generator = settings.generator;
21
+ }
22
+ if (typeof FakeLrepConnector.fileChangeRequestNotifier === 'function' && change.fileName) {
23
+ try {
24
+ FakeLrepConnector.fileChangeRequestNotifier(change.fileName, 'create', change);
25
+ } catch (e) {
26
+ // exceptions in the listener call are ignored
27
+ }
28
+ }
29
+ return fetch(CHANGES_API_PATH, {
30
+ method: 'POST',
31
+ body: JSON.stringify(change, null, 2),
32
+ headers: {
33
+ 'content-type': 'application/json'
34
+ }
35
+ });
36
+ }));
37
+ }
38
+
39
+ /**
40
+ * Loads changes from a given path and processes them using an LrepConnector instance.
41
+ * The changes are then formatted and returned in a specified structure.
42
+ *
43
+ * @returns {Promise<LoadChangesResult>} A promise that resolves to an object of type LoadChangesResult.
44
+ */
45
+ async function loadChanges() {
46
+ const lrep = new LrepConnector();
47
+ const response = await fetch(CHANGES_API_PATH, {
48
+ method: 'GET',
49
+ headers: {
50
+ 'content-type': 'application/json'
51
+ }
52
+ });
53
+ const changes = await response.json();
54
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
55
+ args[_key] = arguments[_key];
56
+ }
57
+ return LrepConnector.prototype.loadChanges.apply(lrep, args).then(res => {
58
+ res.changes.changes = Object.values(changes);
59
+ return res;
60
+ });
61
+ }
62
+
63
+ /**
64
+ * Configures and enables the FakeLrepConnector based on the SAP UI5 version.
65
+ * If the minor version of the SAP UI5 is less than 72, this function extends
66
+ * the FakeLrepConnector's prototype with specific methods and enables the fake connector.
67
+ *
68
+ * Assumes the existence of a global 'sap' object with a 'ui.version' property,
69
+ * and global jQuery object with 'extend' method.
70
+ *
71
+ * @returns {void}
72
+ */
73
+ var __exports = function () {
74
+ jQuery.extend(FakeLrepConnector.prototype, {
75
+ create,
76
+ loadChanges,
77
+ loadSettings: () => Promise.resolve()
78
+ });
79
+ FakeLrepConnector.enableFakeConnector();
80
+ };
81
+ __exports.create = create;
82
+ __exports.loadChanges = loadChanges;
83
+ return __exports;
84
84
  });
85
85
  //# sourceMappingURL=enableFakeConnector.js.map
@@ -1,30 +1,30 @@
1
- "use strict";
2
-
3
- sap.ui.define(["../utils/version"], function (___utils_version) {
4
- "use strict";
5
-
6
- const getUi5Version = ___utils_version["getUi5Version"];
7
- const isLowerThanMinimalUi5Version = ___utils_version["isLowerThanMinimalUi5Version"];
8
- /**
9
- * Initializes UI5 connectors based on the current UI5 version.
10
- *
11
- * For UI5 versions below 1.72, this function dynamically requires and executes a FakeLrepConnector.
12
- * For UI5 versions 1.72 and above, it defines a local connector that reuses the WorkspaceConnector.
13
- * This setup allows for flexibility in using different connectors based on the UI5 version.
14
- *
15
- * @example
16
- * intiConnectors(); // Simply call the function without any arguments.
17
- */
18
- async function initConnectors() {
19
- if (isLowerThanMinimalUi5Version(await getUi5Version(), {
20
- major: 1,
21
- minor: 72
22
- })) {
23
- sap.ui.require(['open/ux/preview/client/flp/enableFakeConnector'], function (enableFakeConnector) {
24
- enableFakeConnector();
25
- });
26
- }
27
- }
28
- return initConnectors;
1
+ "use strict";
2
+
3
+ sap.ui.define(["../utils/version"], function (___utils_version) {
4
+ "use strict";
5
+
6
+ const getUi5Version = ___utils_version["getUi5Version"];
7
+ const isLowerThanMinimalUi5Version = ___utils_version["isLowerThanMinimalUi5Version"];
8
+ /**
9
+ * Initializes UI5 connectors based on the current UI5 version.
10
+ *
11
+ * For UI5 versions below 1.72, this function dynamically requires and executes a FakeLrepConnector.
12
+ * For UI5 versions 1.72 and above, it defines a local connector that reuses the WorkspaceConnector.
13
+ * This setup allows for flexibility in using different connectors based on the UI5 version.
14
+ *
15
+ * @example
16
+ * intiConnectors(); // Simply call the function without any arguments.
17
+ */
18
+ async function initConnectors() {
19
+ if (isLowerThanMinimalUi5Version(await getUi5Version(), {
20
+ major: 1,
21
+ minor: 72
22
+ })) {
23
+ sap.ui.require(['open/ux/preview/client/flp/enableFakeConnector'], function (enableFakeConnector) {
24
+ enableFakeConnector();
25
+ });
26
+ }
27
+ }
28
+ return initConnectors;
29
29
  });
30
30
  //# sourceMappingURL=initConnectors.js.map
@@ -1,180 +1,180 @@
1
- "use strict";
2
-
3
- sap.ui.define(["sap/base/util/merge", "sap/ui/core/Control", "sap/ui/core/UIComponent", "sap/ui/fl/Utils", "sap/ui/fl/write/api/FeaturesAPI", "sap/ui/rta/RuntimeAuthoring"], function (merge, Control, UIComponent, Utils, FeaturesAPI, RuntimeAuthoring) {
4
- "use strict";
5
-
6
- const defaultOptions = {
7
- flexSettings: {
8
- developerMode: false,
9
- layer: 'CUSTOMER'
10
- }
11
- };
12
- const layers = {
13
- BASE: 'BASE',
14
- CUSTOMER: 'CUSTOMER',
15
- CUSTOMER_BASE: 'CUSTOMER_BASE',
16
- PARTNER: 'PARTNER',
17
- PUBLIC: 'PUBLIC',
18
- USER: 'USER',
19
- VENDOR: 'VENDOR'
20
- };
21
-
22
- /**
23
- * Checks if the given layer is a valid layer.
24
- *
25
- * @param {string} layer - The layer name to be validated.
26
- * @returns {boolean} Returns true if the layer is valid, otherwise false.
27
- */
28
- function isValidLayer(layer) {
29
- return Object.keys(layers).some(existingLayer => existingLayer === layer);
30
- }
31
-
32
- /**
33
- * Validates a given layer and throws an error if it is invalid.
34
- *
35
- * @param {string} layer - The layer name to be checked.
36
- * @throws {Error} Throws an error if the layer is not valid.
37
- */
38
- function checkLayer(layer) {
39
- if (!isValidLayer(layer)) {
40
- throw new Error('An invalid layer is passed');
41
- }
42
- }
43
-
44
- /**
45
- * Checks if the given root control is an instance of Control or UIComponent.
46
- *
47
- * @param {Control | UIComponent} rootControl - The root control to be checked.
48
- * @throws {Error} Throws an error if the root control is not an instance of Control or UIComponent.
49
- */
50
- function checkRootControl(rootControl) {
51
- if (!(rootControl instanceof Control) && !(rootControl instanceof UIComponent)) {
52
- throw new Error('An invalid root control was passed');
53
- }
54
- }
55
-
56
- /**
57
- * Checks if key user adaptation is enabled for the specified component.
58
- * Fiori tools mode is considered a developer scenario where the `flexEnabled` flag should not be evaluated.
59
- *
60
- * @param {Control} component - The UI5 control component to check for flex (key user adaptation) enabled status.
61
- * @throws {Error} Throws an error if key user adaptation is explicitly disabled in the component's manifest.
62
- */
63
- function checkFlexEnabled(component) {
64
- // fiori tools is always a developer scenario where the flexEnabled flag should not be evaluated
65
- const fioriToolsMode = new URLSearchParams(window.location.search).get('fiori-tools-rta-mode');
66
- if (!fioriToolsMode || fioriToolsMode === 'false') {
67
- const manifest = component.getManifest() || {};
68
- const flexEnabled = manifest['sap.ui5']?.flexEnabled;
69
- if (flexEnabled === false) {
70
- throw new Error('This app is not enabled for key user adaptation');
71
- }
72
- }
73
- }
74
-
75
- /**
76
- * Checks if the current user is a key user for the given layer.
77
- * Specifically, it checks for key user rights if the layer is the CUSTOMER layer.
78
- * If the user is not a key user and the layer is CUSTOMER, an error is thrown.
79
- *
80
- * Note: The function assumes the presence of 'layers.CUSTOMER'. In case of non-CUSTOMER layers,
81
- * it simply resolves the promise without any additional checks.
82
- *
83
- * @param {string} layer - The layer for which to check key user rights.
84
- * @returns {Promise<void>} A promise that resolves if the user is a key user or the layer is not CUSTOMER.
85
- * Rejects with an error if the user is not a key user for the CUSTOMER layer.
86
- * @throws {Error} Throws an error with the message 'No key user rights found' if the user lacks key user rights.
87
- */
88
- async function checkKeyUser(layer) {
89
- if (layers.CUSTOMER === layer) {
90
- const isKeyUser = await FeaturesAPI.isKeyUser();
91
- if (!isKeyUser) {
92
- throw new Error('No key user rights found');
93
- }
94
- }
95
- }
96
-
97
- /**
98
- * Checks the validity of the specified layer and root control.
99
- * It ensures that the layer is valid and the root control is an instance of Control or UIComponent.
100
- * Additionally, it checks key user permissions for the specified layer.
101
- *
102
- * @param {Control} rootControl - The root control to be validated.
103
- * @param {string} layer - The layer name to be validated.
104
- * @returns {Promise<void>} A promise that resolves when all checks pass without errors.
105
- * @throws {Error} Throws an error if any of the checks fail.
106
- */
107
- async function checkLayerAndControl(rootControl, layer) {
108
- checkLayer(layer);
109
- checkRootControl(rootControl);
110
- await checkKeyUser(layer);
111
- }
112
-
113
- /**
114
- * Retrieves the first HTML element with the specified title attribute.
115
- *
116
- * @param {string} title - The title attribute value to search for in the HTML elements.
117
- * @param {Element | null} element - The target element that will be searched.
118
- * @returns {Element | null} The first HTML element that matches the given title attribute value, or null if no such element is found.
119
- */
120
- function getElementByTitle(title, element) {
121
- const selector = `[title="${title}"]`;
122
- return element ? element.querySelector(selector) : document.querySelector(selector);
123
- }
124
-
125
- /**
126
- * Hides a UI5 Button control with the specified ID.
127
- *
128
- * This function attempts to find a UI5 Button control by its ID and then sets its visibility to false.
129
- *
130
- * @param {string | undefined} buttonId - The ID of the Button control to hide. If undefined, no action is taken.
131
- * @returns {void}
132
- */
133
- function hideButtonById(buttonId) {
134
- const button = sap.ui.getCore().byId(buttonId);
135
- button?.setVisible(false);
136
- }
137
-
138
- /**
139
- * Hides specific buttons by ID from the RTA toolbar.
140
- * This function specifically targets buttons 'Reset' and 'Publish'.
141
- */
142
- function removeExtraBtnsFromToolbar() {
143
- const rtaToolbarEl = document.querySelector('.sapUiRtaToolbar');
144
- const resetEl = getElementByTitle('Reset', rtaToolbarEl);
145
- const publishEl = getElementByTitle('Publish', rtaToolbarEl);
146
- hideButtonById(resetEl?.id);
147
- hideButtonById(publishEl?.id);
148
- }
149
-
150
- /**
151
- * Initializes custom RuntimeAuthoring for UI5 Versions < 1.72 and start UI Adaptation.
152
- * Ensures that the passed options are valid.
153
- *
154
- * @param {RTAOptions} options - Options that are passed to RuntimeAuthoring upon initialization.
155
- * @param {RTAPlugin} loadPlugins - Script that needs to be executed after rta is initialized.
156
- * @returns {Promise<void>} A promise that resolves when all the checks have passed and RuntimeAuthoring is started.
157
- */
158
- var __exports = async function (options, loadPlugins) {
159
- options = merge(defaultOptions, options);
160
- const layer = options.flexSettings.layer;
161
- const rootControl = options.rootControl;
162
- await checkLayerAndControl(rootControl, layer);
163
- options.rootControl = Utils.getAppComponentForControl(rootControl);
164
- checkFlexEnabled(options.rootControl);
165
- const rta = new RuntimeAuthoring(options);
166
- rta.attachEvent('stop', () => rta.destroy());
167
- if (loadPlugins) {
168
- await loadPlugins(rta);
169
- }
170
- await rta.start();
171
- removeExtraBtnsFromToolbar();
172
- };
173
- __exports.isValidLayer = isValidLayer;
174
- __exports.checkLayer = checkLayer;
175
- __exports.checkRootControl = checkRootControl;
176
- __exports.checkFlexEnabled = checkFlexEnabled;
177
- __exports.checkKeyUser = checkKeyUser;
178
- return __exports;
1
+ "use strict";
2
+
3
+ sap.ui.define(["sap/base/util/merge", "sap/ui/core/Control", "sap/ui/core/UIComponent", "sap/ui/fl/Utils", "sap/ui/fl/write/api/FeaturesAPI", "sap/ui/rta/RuntimeAuthoring"], function (merge, Control, UIComponent, Utils, FeaturesAPI, RuntimeAuthoring) {
4
+ "use strict";
5
+
6
+ const defaultOptions = {
7
+ flexSettings: {
8
+ developerMode: false,
9
+ layer: 'CUSTOMER'
10
+ }
11
+ };
12
+ const layers = {
13
+ BASE: 'BASE',
14
+ CUSTOMER: 'CUSTOMER',
15
+ CUSTOMER_BASE: 'CUSTOMER_BASE',
16
+ PARTNER: 'PARTNER',
17
+ PUBLIC: 'PUBLIC',
18
+ USER: 'USER',
19
+ VENDOR: 'VENDOR'
20
+ };
21
+
22
+ /**
23
+ * Checks if the given layer is a valid layer.
24
+ *
25
+ * @param {string} layer - The layer name to be validated.
26
+ * @returns {boolean} Returns true if the layer is valid, otherwise false.
27
+ */
28
+ function isValidLayer(layer) {
29
+ return Object.keys(layers).some(existingLayer => existingLayer === layer);
30
+ }
31
+
32
+ /**
33
+ * Validates a given layer and throws an error if it is invalid.
34
+ *
35
+ * @param {string} layer - The layer name to be checked.
36
+ * @throws {Error} Throws an error if the layer is not valid.
37
+ */
38
+ function checkLayer(layer) {
39
+ if (!isValidLayer(layer)) {
40
+ throw new Error('An invalid layer is passed');
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Checks if the given root control is an instance of Control or UIComponent.
46
+ *
47
+ * @param {Control | UIComponent} rootControl - The root control to be checked.
48
+ * @throws {Error} Throws an error if the root control is not an instance of Control or UIComponent.
49
+ */
50
+ function checkRootControl(rootControl) {
51
+ if (!(rootControl instanceof Control) && !(rootControl instanceof UIComponent)) {
52
+ throw new Error('An invalid root control was passed');
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Checks if key user adaptation is enabled for the specified component.
58
+ * Fiori tools mode is considered a developer scenario where the `flexEnabled` flag should not be evaluated.
59
+ *
60
+ * @param {Control} component - The UI5 control component to check for flex (key user adaptation) enabled status.
61
+ * @throws {Error} Throws an error if key user adaptation is explicitly disabled in the component's manifest.
62
+ */
63
+ function checkFlexEnabled(component) {
64
+ // fiori tools is always a developer scenario where the flexEnabled flag should not be evaluated
65
+ const fioriToolsMode = new URLSearchParams(window.location.search).get('fiori-tools-rta-mode');
66
+ if (!fioriToolsMode || fioriToolsMode === 'false') {
67
+ const manifest = component.getManifest() || {};
68
+ const flexEnabled = manifest['sap.ui5']?.flexEnabled;
69
+ if (flexEnabled === false) {
70
+ throw new Error('This app is not enabled for key user adaptation');
71
+ }
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Checks if the current user is a key user for the given layer.
77
+ * Specifically, it checks for key user rights if the layer is the CUSTOMER layer.
78
+ * If the user is not a key user and the layer is CUSTOMER, an error is thrown.
79
+ *
80
+ * Note: The function assumes the presence of 'layers.CUSTOMER'. In case of non-CUSTOMER layers,
81
+ * it simply resolves the promise without any additional checks.
82
+ *
83
+ * @param {string} layer - The layer for which to check key user rights.
84
+ * @returns {Promise<void>} A promise that resolves if the user is a key user or the layer is not CUSTOMER.
85
+ * Rejects with an error if the user is not a key user for the CUSTOMER layer.
86
+ * @throws {Error} Throws an error with the message 'No key user rights found' if the user lacks key user rights.
87
+ */
88
+ async function checkKeyUser(layer) {
89
+ if (layers.CUSTOMER === layer) {
90
+ const isKeyUser = await FeaturesAPI.isKeyUser();
91
+ if (!isKeyUser) {
92
+ throw new Error('No key user rights found');
93
+ }
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Checks the validity of the specified layer and root control.
99
+ * It ensures that the layer is valid and the root control is an instance of Control or UIComponent.
100
+ * Additionally, it checks key user permissions for the specified layer.
101
+ *
102
+ * @param {Control} rootControl - The root control to be validated.
103
+ * @param {string} layer - The layer name to be validated.
104
+ * @returns {Promise<void>} A promise that resolves when all checks pass without errors.
105
+ * @throws {Error} Throws an error if any of the checks fail.
106
+ */
107
+ async function checkLayerAndControl(rootControl, layer) {
108
+ checkLayer(layer);
109
+ checkRootControl(rootControl);
110
+ await checkKeyUser(layer);
111
+ }
112
+
113
+ /**
114
+ * Retrieves the first HTML element with the specified title attribute.
115
+ *
116
+ * @param {string} title - The title attribute value to search for in the HTML elements.
117
+ * @param {Element | null} element - The target element that will be searched.
118
+ * @returns {Element | null} The first HTML element that matches the given title attribute value, or null if no such element is found.
119
+ */
120
+ function getElementByTitle(title, element) {
121
+ const selector = `[title="${title}"]`;
122
+ return element ? element.querySelector(selector) : document.querySelector(selector);
123
+ }
124
+
125
+ /**
126
+ * Hides a UI5 Button control with the specified ID.
127
+ *
128
+ * This function attempts to find a UI5 Button control by its ID and then sets its visibility to false.
129
+ *
130
+ * @param {string | undefined} buttonId - The ID of the Button control to hide. If undefined, no action is taken.
131
+ * @returns {void}
132
+ */
133
+ function hideButtonById(buttonId) {
134
+ const button = sap.ui.getCore().byId(buttonId);
135
+ button?.setVisible(false);
136
+ }
137
+
138
+ /**
139
+ * Hides specific buttons by ID from the RTA toolbar.
140
+ * This function specifically targets buttons 'Reset' and 'Publish'.
141
+ */
142
+ function removeExtraBtnsFromToolbar() {
143
+ const rtaToolbarEl = document.querySelector('.sapUiRtaToolbar');
144
+ const resetEl = getElementByTitle('Reset', rtaToolbarEl);
145
+ const publishEl = getElementByTitle('Publish', rtaToolbarEl);
146
+ hideButtonById(resetEl?.id);
147
+ hideButtonById(publishEl?.id);
148
+ }
149
+
150
+ /**
151
+ * Initializes custom RuntimeAuthoring for UI5 Versions < 1.72 and start UI Adaptation.
152
+ * Ensures that the passed options are valid.
153
+ *
154
+ * @param {RTAOptions} options - Options that are passed to RuntimeAuthoring upon initialization.
155
+ * @param {RTAPlugin} loadPlugins - Script that needs to be executed after rta is initialized.
156
+ * @returns {Promise<void>} A promise that resolves when all the checks have passed and RuntimeAuthoring is started.
157
+ */
158
+ var __exports = async function (options, loadPlugins) {
159
+ options = merge(defaultOptions, options);
160
+ const layer = options.flexSettings.layer;
161
+ const rootControl = options.rootControl;
162
+ await checkLayerAndControl(rootControl, layer);
163
+ options.rootControl = Utils.getAppComponentForControl(rootControl);
164
+ checkFlexEnabled(options.rootControl);
165
+ const rta = new RuntimeAuthoring(options);
166
+ rta.attachEvent('stop', () => rta.destroy());
167
+ if (loadPlugins) {
168
+ await loadPlugins(rta);
169
+ }
170
+ await rta.start();
171
+ removeExtraBtnsFromToolbar();
172
+ };
173
+ __exports.isValidLayer = isValidLayer;
174
+ __exports.checkLayer = checkLayer;
175
+ __exports.checkRootControl = checkRootControl;
176
+ __exports.checkFlexEnabled = checkFlexEnabled;
177
+ __exports.checkKeyUser = checkKeyUser;
178
+ return __exports;
179
179
  });
180
180
  //# sourceMappingURL=initRta.js.map