@sap-ux/preview-middleware 0.11.0 → 0.11.2
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,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
sap.ui.define(["sap/ui/rta/command/CommandFactory"], function (CommandFactory) {
|
|
3
|
+
sap.ui.define(["sap/ui/rta/command/CommandFactory", "./validator"], function (CommandFactory, ___validator) {
|
|
4
4
|
"use strict";
|
|
5
5
|
|
|
6
|
+
const validateBindingModel = ___validator["validateBindingModel"];
|
|
6
7
|
/**
|
|
7
8
|
* Function to check a give value is a binding expression.
|
|
8
9
|
*
|
|
@@ -10,7 +11,7 @@ sap.ui.define(["sap/ui/rta/command/CommandFactory"], function (CommandFactory) {
|
|
|
10
11
|
* @returns boolean
|
|
11
12
|
*/
|
|
12
13
|
function isBindingExpression(value) {
|
|
13
|
-
return value.includes('{') && value.includes('}');
|
|
14
|
+
return value.includes('{') && value.includes('}') && value.indexOf('{') < value.indexOf('}');
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -26,9 +27,15 @@ sap.ui.define(["sap/ui/rta/command/CommandFactory"], function (CommandFactory) {
|
|
|
26
27
|
if (!modifiedControl) {
|
|
27
28
|
return;
|
|
28
29
|
}
|
|
30
|
+
const isBindingString = typeof change.value === 'string' && isBindingExpression(change.value);
|
|
31
|
+
const modifiedControlModifiedProperties = modifiedControl.getMetadata().getAllProperties()[change.propertyName];
|
|
32
|
+
const isBindingModel = isBindingString && modifiedControlModifiedProperties?.type === 'string';
|
|
29
33
|
const flexSettings = rta.getFlexSettings();
|
|
30
|
-
const changeType =
|
|
31
|
-
|
|
34
|
+
const changeType = isBindingString ? 'BindProperty' : 'Property';
|
|
35
|
+
if (isBindingModel) {
|
|
36
|
+
validateBindingModel(change.value);
|
|
37
|
+
}
|
|
38
|
+
const property = isBindingString ? 'newBinding' : 'newValue';
|
|
32
39
|
const modifiedValue = {
|
|
33
40
|
generator: flexSettings.generator,
|
|
34
41
|
propertyName: change.propertyName,
|
|
@@ -2,6 +2,7 @@ import type FlexCommand from 'sap/ui/rta/command/FlexCommand';
|
|
|
2
2
|
import CommandFactory from 'sap/ui/rta/command/CommandFactory';
|
|
3
3
|
import type { PropertyChange } from '@sap-ux-private/control-property-editor-common';
|
|
4
4
|
import type { UI5AdaptationOptions } from '../types';
|
|
5
|
+
import { validateBindingModel } from './validator';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Function to check a give value is a binding expression.
|
|
@@ -10,7 +11,7 @@ import type { UI5AdaptationOptions } from '../types';
|
|
|
10
11
|
* @returns boolean
|
|
11
12
|
*/
|
|
12
13
|
function isBindingExpression(value: string): boolean {
|
|
13
|
-
return value.includes('{') && value.includes('}');
|
|
14
|
+
return value.includes('{') && value.includes('}') && value.indexOf('{') < value.indexOf('}');
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -25,12 +26,17 @@ export async function applyChange(options: UI5AdaptationOptions, change: Propert
|
|
|
25
26
|
return;
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
const isBindingString = typeof change.value === 'string' && isBindingExpression(change.value);
|
|
30
|
+
const modifiedControlModifiedProperties = modifiedControl.getMetadata().getAllProperties()[change.propertyName];
|
|
31
|
+
const isBindingModel = isBindingString && modifiedControlModifiedProperties?.type === 'string';
|
|
28
32
|
const flexSettings = rta.getFlexSettings();
|
|
33
|
+
const changeType = isBindingString ? 'BindProperty' : 'Property';
|
|
29
34
|
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
if (isBindingModel) {
|
|
36
|
+
validateBindingModel(change.value as string);
|
|
37
|
+
}
|
|
32
38
|
|
|
33
|
-
const property =
|
|
39
|
+
const property = isBindingString ? 'newBinding' : 'newValue';
|
|
34
40
|
const modifiedValue = {
|
|
35
41
|
generator: flexSettings.generator,
|
|
36
42
|
propertyName: change.propertyName,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
sap.ui.define(["sap/base/i18n/ResourceBundle"], function (ResourceBundle) {
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Function to validate if a given value is a valid binding model.
|
|
8
|
+
*
|
|
9
|
+
* @param value value to be checked.
|
|
10
|
+
*/
|
|
11
|
+
function validateBindingModel(value) {
|
|
12
|
+
const bindingValue = value.replace(/[{}]/gi, '').trim();
|
|
13
|
+
const bindingParts = bindingValue.split('>').filter(el => el != '');
|
|
14
|
+
if (!bindingParts.length) {
|
|
15
|
+
throw new SyntaxError('Invalid binding string.');
|
|
16
|
+
}
|
|
17
|
+
if (bindingParts[0].trim() === 'i18n') {
|
|
18
|
+
if (bindingParts.length === 2) {
|
|
19
|
+
const resourceBundle = ResourceBundle.create({
|
|
20
|
+
url: '../i18n/i18n.properties'
|
|
21
|
+
});
|
|
22
|
+
const resourceKey = bindingParts[1].trim();
|
|
23
|
+
if (!resourceBundle.hasText(resourceKey)) {
|
|
24
|
+
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
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
throw new SyntaxError('Invalid binding string. Supported value pattern is {i18n>YOUR_KEY}');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
var __exports = {
|
|
32
|
+
__esModule: true
|
|
33
|
+
};
|
|
34
|
+
__exports.validateBindingModel = validateBindingModel;
|
|
35
|
+
return __exports;
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import ResourceBundle from 'sap/base/i18n/ResourceBundle';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Function to validate if a given value is a valid binding model.
|
|
5
|
+
*
|
|
6
|
+
* @param value value to be checked.
|
|
7
|
+
*/
|
|
8
|
+
export function validateBindingModel(value: string): void {
|
|
9
|
+
const bindingValue = value.replace(/[{}]/gi, '').trim();
|
|
10
|
+
const bindingParts = bindingValue.split('>').filter((el) => el != '');
|
|
11
|
+
|
|
12
|
+
if (!bindingParts.length) {
|
|
13
|
+
throw new SyntaxError('Invalid binding string.');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (bindingParts[0].trim() === 'i18n') {
|
|
17
|
+
if (bindingParts.length === 2) {
|
|
18
|
+
const resourceBundle = ResourceBundle.create({
|
|
19
|
+
url: '../i18n/i18n.properties'
|
|
20
|
+
}) as ResourceBundle;
|
|
21
|
+
const resourceKey = bindingParts[1].trim();
|
|
22
|
+
if (!resourceBundle.hasText(resourceKey)) {
|
|
23
|
+
throw new SyntaxError(
|
|
24
|
+
'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
|
+
);
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
throw new SyntaxError('Invalid binding string. Supported value pattern is {i18n>YOUR_KEY}');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
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.11.
|
|
12
|
+
"version": "0.11.2",
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"author": "@SAP/ux-tools-team",
|
|
15
15
|
"main": "dist/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"ejs": "3.1.9",
|
|
26
26
|
"@sap-ux/logger": "0.4.0",
|
|
27
|
-
"@sap-ux/adp-tooling": "0.
|
|
27
|
+
"@sap-ux/adp-tooling": "0.7.0",
|
|
28
28
|
"@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.4.2"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"npm-run-all": "4.1.5",
|
|
37
37
|
"nock": "13.2.1",
|
|
38
38
|
"supertest": "6.3.3",
|
|
39
|
-
"@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.8.
|
|
40
|
-
"@sap-ux/project-access": "1.15.
|
|
39
|
+
"@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.8.1",
|
|
40
|
+
"@sap-ux/project-access": "1.15.4",
|
|
41
41
|
"@sap-ux/store": "0.4.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|