@sap-ux/preview-middleware 0.15.7 → 0.15.8

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.
@@ -33,7 +33,7 @@ sap.ui.define(["sap/ui/rta/command/CommandFactory", "./validator"], function (Co
33
33
  const flexSettings = rta.getFlexSettings();
34
34
  const changeType = isBindingString ? 'BindProperty' : 'Property';
35
35
  if (isBindingModel) {
36
- validateBindingModel(change.value);
36
+ validateBindingModel(modifiedControl, change.value);
37
37
  }
38
38
  const property = isBindingString ? 'newBinding' : 'newValue';
39
39
  const modifiedValue = {
@@ -33,7 +33,7 @@ export async function applyChange(options: UI5AdaptationOptions, change: Propert
33
33
  const changeType = isBindingString ? 'BindProperty' : 'Property';
34
34
 
35
35
  if (isBindingModel) {
36
- validateBindingModel(change.value as string);
36
+ validateBindingModel(modifiedControl, change.value as string);
37
37
  }
38
38
 
39
39
  const property = isBindingString ? 'newBinding' : 'newValue';
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
 
3
- sap.ui.define(["sap/base/i18n/ResourceBundle"], function (ResourceBundle) {
3
+ sap.ui.define([], function () {
4
4
  "use strict";
5
5
 
6
6
  /**
7
7
  * Function to validate if a given value is a valid binding model.
8
8
  *
9
+ * @param modifiedControl control to be modified.
9
10
  * @param value value to be checked.
10
11
  */
11
- function validateBindingModel(value) {
12
+ function validateBindingModel(modifiedControl, value) {
12
13
  const bindingValue = value.replace(/[{}]/gi, '').trim();
13
14
  const bindingParts = bindingValue.split('>').filter(el => el !== '');
14
15
  if (!bindingParts.length) {
@@ -16,11 +17,9 @@ sap.ui.define(["sap/base/i18n/ResourceBundle"], function (ResourceBundle) {
16
17
  }
17
18
  if (bindingParts[0].trim() === 'i18n') {
18
19
  if (bindingParts.length === 2) {
19
- const resourceBundle = ResourceBundle.create({
20
- url: '../i18n/i18n.properties'
21
- });
22
20
  const resourceKey = bindingParts[1].trim();
23
- if (!resourceBundle.hasText(resourceKey)) {
21
+ const resourceBundle = modifiedControl.getModel('i18n').getResourceBundle();
22
+ if (!resourceBundle.getText(resourceKey, undefined, true)) {
24
23
  throw new SyntaxError('Invalid key in the binding string. Supported value pattern is {i18n>YOUR_KEY}. Check if the key already exists in i18n.properties.' + 'If not, add the key in the i18n.properties file and reload the editor for the new key to take effect.');
25
24
  }
26
25
  } else {
@@ -1,11 +1,14 @@
1
1
  import ResourceBundle from 'sap/base/i18n/ResourceBundle';
2
+ import ResourceModel from 'sap/ui/model/resource/ResourceModel';
3
+ import type UI5Element from 'sap/ui/core/Element';
2
4
 
3
5
  /**
4
6
  * Function to validate if a given value is a valid binding model.
5
7
  *
8
+ * @param modifiedControl control to be modified.
6
9
  * @param value value to be checked.
7
10
  */
8
- export function validateBindingModel(value: string): void {
11
+ export function validateBindingModel(modifiedControl: UI5Element, value: string): void {
9
12
  const bindingValue = value.replace(/[{}]/gi, '').trim();
10
13
  const bindingParts = bindingValue.split('>').filter((el) => el !== '');
11
14
 
@@ -15,11 +18,9 @@ export function validateBindingModel(value: string): void {
15
18
 
16
19
  if (bindingParts[0].trim() === 'i18n') {
17
20
  if (bindingParts.length === 2) {
18
- const resourceBundle = ResourceBundle.create({
19
- url: '../i18n/i18n.properties'
20
- }) as ResourceBundle;
21
21
  const resourceKey = bindingParts[1].trim();
22
- if (!resourceBundle.hasText(resourceKey)) {
22
+ const resourceBundle = (modifiedControl.getModel('i18n') as ResourceModel).getResourceBundle() as ResourceBundle;
23
+ if (!resourceBundle.getText(resourceKey, undefined, true)) {
23
24
  throw new SyntaxError(
24
25
  'Invalid key in the binding string. Supported value pattern is {i18n>YOUR_KEY}. Check if the key already exists in i18n.properties.' +
25
26
  'If not, add the key in the i18n.properties file and reload the editor for the new key to take effect.'
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
 
3
- sap.ui.define(["sap/base/Log", "sap/ui/core/IconPool", "sap/base/i18n/ResourceBundle"], function (Log, IconPool, ResourceBundle) {
3
+ sap.ui.define(["sap/base/Log", "sap/ui/fl/Scenario", "sap/ui/core/IconPool", "sap/base/i18n/ResourceBundle", "../adp/api-handler"], function (Log, scenarios, IconPool, ResourceBundle, ___adp_api_handler) {
4
4
  "use strict";
5
5
 
6
+ const getManifestAppdescr = ___adp_api_handler["getManifestAppdescr"];
6
7
  /**
7
8
  * SAPUI5 delivered namespaces from https://ui5.sap.com/#/api/sap
8
9
  */
@@ -136,19 +137,35 @@ sap.ui.define(["sap/base/Log", "sap/ui/core/IconPool", "sap/base/i18n/ResourceBu
136
137
  IconPool.registerFont(suiteTheme);
137
138
  }
138
139
 
140
+ /**
141
+ * Create Resource Bundle based on the scenario.
142
+ *
143
+ * @param scenario to be used for the resource bundle.
144
+ */
145
+ async function loadI18nResourceBundle(scenario) {
146
+ if (scenario === scenarios.AdaptationProject) {
147
+ const manifest = await getManifestAppdescr();
148
+ const enhanceWith = manifest.content.filter(content => content.texts?.i18n).map(content => ({
149
+ bundleUrl: `../${content.texts.i18n}`
150
+ }));
151
+ return ResourceBundle.create({
152
+ url: '../i18n/i18n.properties',
153
+ enhanceWith
154
+ });
155
+ }
156
+ return ResourceBundle.create({
157
+ url: 'i18n/i18n.properties'
158
+ });
159
+ }
160
+
139
161
  /**
140
162
  * Read the application title from the resource bundle and set it as document title.
141
163
  *
164
+ * @param resourceBundle resource bundle to read the title from.
142
165
  * @param i18nKey optional parameter to define the i18n key to be used for the title.
143
166
  */
144
- function setI18nTitle() {
145
- let i18nKey = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'appTitle';
146
- const localization = sap.ui.require('sap/base/i18n/Localization') ?? sap.ui.getCore().getConfiguration();
147
- const locale = localization.getLanguage();
148
- const resourceBundle = ResourceBundle.create({
149
- url: 'i18n/i18n.properties',
150
- locale
151
- });
167
+ function setI18nTitle(resourceBundle) {
168
+ let i18nKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'appTitle';
152
169
  if (resourceBundle.hasText(i18nKey)) {
153
170
  document.title = resourceBundle.getText(i18nKey) ?? document.title;
154
171
  }
@@ -171,8 +188,11 @@ sap.ui.define(["sap/base/Log", "sap/ui/core/IconPool", "sap/base/i18n/ResourceBu
171
188
  } = _ref;
172
189
  const urlParams = new URLSearchParams(window.location.search);
173
190
  const container = sap?.ushell?.Container ?? sap.ui.require('sap/ushell/Container');
191
+ let scenario = '';
174
192
  // Register RTA if configured
175
193
  if (flex) {
194
+ const flexSettings = JSON.parse(flex);
195
+ scenario = flexSettings.scenario;
176
196
  container.attachRendererCreatedEvent(async function () {
177
197
  const lifecycleService = await container.getServiceAsync('AppLifeCycle');
178
198
  lifecycleService.attachAppLoaded(event => {
@@ -219,7 +239,8 @@ sap.ui.define(["sap/base/Log", "sap/ui/core/IconPool", "sap/base/i18n/ResourceBu
219
239
  }
220
240
 
221
241
  // init
222
- setI18nTitle();
242
+ const resourceBundle = await loadI18nResourceBundle(scenario);
243
+ setI18nTitle(resourceBundle);
223
244
  registerSAPFonts();
224
245
  const renderer = await container.createRenderer(undefined, true);
225
246
  renderer.placeAt('content');
@@ -238,6 +259,7 @@ sap.ui.define(["sap/base/Log", "sap/ui/core/IconPool", "sap/base/i18n/ResourceBu
238
259
  __exports.resetAppState = resetAppState;
239
260
  __exports.registerComponentDependencyPaths = registerComponentDependencyPaths;
240
261
  __exports.registerSAPFonts = registerSAPFonts;
262
+ __exports.loadI18nResourceBundle = loadI18nResourceBundle;
241
263
  __exports.setI18nTitle = setI18nTitle;
242
264
  __exports.init = init;
243
265
  return __exports;
@@ -1,11 +1,13 @@
1
1
  import Log from 'sap/base/Log';
2
2
  import type AppLifeCycle from 'sap/ushell/services/AppLifeCycle';
3
3
  import type { InitRtaScript, RTAPlugin, StartAdaptation } from 'sap/ui/rta/api/startAdaptation';
4
+ import scenarios, { type Scenario } from 'sap/ui/fl/Scenario';
4
5
  import type { FlexSettings, RTAOptions } from 'sap/ui/rta/RuntimeAuthoring';
5
6
  import IconPool from 'sap/ui/core/IconPool';
6
7
  import ResourceBundle from 'sap/base/i18n/ResourceBundle';
7
8
  import AppState from 'sap/ushell/services/AppState';
8
- import type Localization from 'sap/base/i18n/Localization';
9
+ import { getManifestAppdescr } from '../adp/api-handler';
10
+
9
11
  /**
10
12
  * SAPUI5 delivered namespaces from https://ui5.sap.com/#/api/sap
11
13
  */
@@ -188,19 +190,34 @@ export function registerSAPFonts() {
188
190
  IconPool.registerFont(suiteTheme);
189
191
  }
190
192
 
193
+ /**
194
+ * Create Resource Bundle based on the scenario.
195
+ *
196
+ * @param scenario to be used for the resource bundle.
197
+ */
198
+ export async function loadI18nResourceBundle(scenario: Scenario): Promise<ResourceBundle> {
199
+ if (scenario === scenarios.AdaptationProject) {
200
+ const manifest = await getManifestAppdescr();
201
+ const enhanceWith = (manifest.content as { texts: { i18n: string } }[])
202
+ .filter((content) => content.texts?.i18n)
203
+ .map((content) => ({ bundleUrl: `../${content.texts.i18n}` }));
204
+ return ResourceBundle.create({
205
+ url: '../i18n/i18n.properties',
206
+ enhanceWith
207
+ });
208
+ }
209
+ return ResourceBundle.create({
210
+ url: 'i18n/i18n.properties'
211
+ });
212
+ }
213
+
191
214
  /**
192
215
  * Read the application title from the resource bundle and set it as document title.
193
216
  *
217
+ * @param resourceBundle resource bundle to read the title from.
194
218
  * @param i18nKey optional parameter to define the i18n key to be used for the title.
195
219
  */
196
- export function setI18nTitle(i18nKey = 'appTitle') {
197
- const localization =
198
- (sap.ui.require('sap/base/i18n/Localization') as Localization) ?? sap.ui.getCore().getConfiguration();
199
- const locale = localization.getLanguage();
200
- const resourceBundle = ResourceBundle.create({
201
- url: 'i18n/i18n.properties',
202
- locale
203
- }) as ResourceBundle;
220
+ export function setI18nTitle(resourceBundle: ResourceBundle, i18nKey = 'appTitle') {
204
221
  if (resourceBundle.hasText(i18nKey)) {
205
222
  document.title = resourceBundle.getText(i18nKey) ?? document.title;
206
223
  }
@@ -226,8 +243,11 @@ export async function init({
226
243
  }): Promise<void> {
227
244
  const urlParams = new URLSearchParams(window.location.search);
228
245
  const container = sap?.ushell?.Container ?? (sap.ui.require('sap/ushell/Container') as typeof sap.ushell.Container);
246
+ let scenario: string = '';
229
247
  // Register RTA if configured
230
248
  if (flex) {
249
+ const flexSettings = JSON.parse(flex) as FlexSettings;
250
+ scenario = flexSettings.scenario;
231
251
  container.attachRendererCreatedEvent(async function () {
232
252
  const lifecycleService = await container.getServiceAsync<AppLifeCycle>('AppLifeCycle');
233
253
  lifecycleService.attachAppLoaded((event) => {
@@ -281,7 +301,8 @@ export async function init({
281
301
  }
282
302
 
283
303
  // init
284
- setI18nTitle();
304
+ const resourceBundle = await loadI18nResourceBundle(scenario as Scenario);
305
+ setI18nTitle(resourceBundle);
285
306
  registerSAPFonts();
286
307
  const renderer = await container.createRenderer(undefined, true);
287
308
  renderer.placeAt('content');
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "bugs": {
10
10
  "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Apreview-middleware"
11
11
  },
12
- "version": "0.15.7",
12
+ "version": "0.15.8",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -28,8 +28,8 @@
28
28
  "@sap-ux/logger": "0.5.1",
29
29
  "@sap-ux/btp-utils": "0.14.4",
30
30
  "@sap-ux/adp-tooling": "0.11.13",
31
- "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.4.23",
32
- "@sap-ux/project-access": "1.22.4"
31
+ "@sap-ux/project-access": "1.22.4",
32
+ "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.4.23"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/ejs": "3.1.2",
@@ -45,11 +45,11 @@
45
45
  "supertest": "6.3.3",
46
46
  "@sap-ux-private/playwright": "0.0.3",
47
47
  "dotenv": "16.3.1",
48
- "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.9.17",
48
+ "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.9.18",
49
49
  "@sap-ux/axios-extension": "1.14.4",
50
+ "@sap-ux/i18n": "0.0.7",
50
51
  "@sap-ux/store": "0.6.0",
51
- "@sap-ux/ui5-info": "0.5.0",
52
- "@sap-ux/i18n": "0.0.7"
52
+ "@sap-ux/ui5-info": "0.5.0"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "express": "4"