@sap-ux/preview-middleware 0.16.4 → 0.16.6
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.
- package/README.md +7 -6
- package/dist/client/adp/api-handler.js +142 -142
- package/dist/client/adp/command-executor.js +58 -58
- package/dist/client/adp/control-utils.js +44 -44
- package/dist/client/adp/controllers/AddFragment.controller.js +219 -219
- package/dist/client/adp/controllers/BaseDialog.controller.js +105 -105
- package/dist/client/adp/controllers/ControllerExtension.controller.js +228 -228
- package/dist/client/adp/controllers/ExtensionPoint.controller.js +138 -138
- package/dist/client/adp/init-dialogs.js +121 -121
- package/dist/client/adp/ui5-version-utils.js +63 -63
- package/dist/client/adp/utils.js +61 -61
- package/dist/client/cpe/changes/flex-change.js +51 -51
- package/dist/client/cpe/changes/index.js +10 -10
- package/dist/client/cpe/changes/validator.js +34 -34
- package/dist/client/cpe/documentation.js +164 -164
- package/dist/client/cpe/error-utils.js +19 -19
- package/dist/client/cpe/logger.js +30 -30
- package/dist/client/cpe/outline/nodes.js +151 -151
- package/dist/client/cpe/outline/utils.js +37 -37
- package/dist/client/cpe/types.js +4 -4
- package/dist/client/cpe/ui5-utils.js +49 -49
- package/dist/client/cpe/utils.js +48 -48
- package/dist/client/flp/WorkspaceConnector.js +84 -84
- package/dist/client/flp/common.js +28 -28
- package/dist/client/flp/enableFakeConnector.js +84 -84
- package/dist/client/flp/initConnectors.js +33 -33
- package/dist/client/flp/initRta.js +178 -178
- package/package.json +4 -4
package/dist/client/adp/utils.js
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
sap.ui.define(["sap/m/MessageToast"], function (MessageToast) {
|
|
4
|
-
"use strict";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Defers the resolution of the promise, stores resolve/reject functions so that they can be accessed at a later stage.
|
|
8
|
-
*
|
|
9
|
-
* @description A Deferred object contains an unresolved promise along with the functions to resolve or reject that promise.
|
|
10
|
-
*
|
|
11
|
-
* @returns {Deferred} Deferred object
|
|
12
|
-
*/
|
|
13
|
-
function createDeferred() {
|
|
14
|
-
let resolve = null;
|
|
15
|
-
let reject = null;
|
|
16
|
-
const promise = new Promise((res, rej) => {
|
|
17
|
-
resolve = res;
|
|
18
|
-
reject = rej;
|
|
19
|
-
});
|
|
20
|
-
if (resolve === null || reject === null) {
|
|
21
|
-
throw new Error('Failed to initialize resolve and reject functions.');
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
promise,
|
|
25
|
-
resolve,
|
|
26
|
-
reject
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Checks if the fragment name associated with a command matches the specified fragment name.
|
|
32
|
-
*
|
|
33
|
-
* @param {FlexCommand} command - The command object containing the prepared change to be examined.
|
|
34
|
-
* @param {string} fragmentName - The name of the fragment to match against the command's change.
|
|
35
|
-
* @returns {boolean} Returns true if the command's change contains a fragment path that matches
|
|
36
|
-
* the specified fragment name; otherwise, returns false.
|
|
37
|
-
*/
|
|
38
|
-
function matchesFragmentName(command, fragmentName) {
|
|
39
|
-
const change = command.getPreparedChange().getDefinition();
|
|
40
|
-
return change.content?.fragmentPath?.includes(`${fragmentName}.fragment.xml`) || false;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Displays a message to the user indicating that an XML fragment will be created upon saving a change.
|
|
45
|
-
*
|
|
46
|
-
* @param {string} message - The message to be shown in the message toast.
|
|
47
|
-
* @param {number} duration - The duration during which message toast will be active.
|
|
48
|
-
*/
|
|
49
|
-
function notifyUser(message) {
|
|
50
|
-
let duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5000;
|
|
51
|
-
MessageToast.show(message, {
|
|
52
|
-
duration
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
var __exports = {
|
|
56
|
-
__esModule: true
|
|
57
|
-
};
|
|
58
|
-
__exports.createDeferred = createDeferred;
|
|
59
|
-
__exports.matchesFragmentName = matchesFragmentName;
|
|
60
|
-
__exports.notifyUser = notifyUser;
|
|
61
|
-
return __exports;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
sap.ui.define(["sap/m/MessageToast"], function (MessageToast) {
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Defers the resolution of the promise, stores resolve/reject functions so that they can be accessed at a later stage.
|
|
8
|
+
*
|
|
9
|
+
* @description A Deferred object contains an unresolved promise along with the functions to resolve or reject that promise.
|
|
10
|
+
*
|
|
11
|
+
* @returns {Deferred} Deferred object
|
|
12
|
+
*/
|
|
13
|
+
function createDeferred() {
|
|
14
|
+
let resolve = null;
|
|
15
|
+
let reject = null;
|
|
16
|
+
const promise = new Promise((res, rej) => {
|
|
17
|
+
resolve = res;
|
|
18
|
+
reject = rej;
|
|
19
|
+
});
|
|
20
|
+
if (resolve === null || reject === null) {
|
|
21
|
+
throw new Error('Failed to initialize resolve and reject functions.');
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
promise,
|
|
25
|
+
resolve,
|
|
26
|
+
reject
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Checks if the fragment name associated with a command matches the specified fragment name.
|
|
32
|
+
*
|
|
33
|
+
* @param {FlexCommand} command - The command object containing the prepared change to be examined.
|
|
34
|
+
* @param {string} fragmentName - The name of the fragment to match against the command's change.
|
|
35
|
+
* @returns {boolean} Returns true if the command's change contains a fragment path that matches
|
|
36
|
+
* the specified fragment name; otherwise, returns false.
|
|
37
|
+
*/
|
|
38
|
+
function matchesFragmentName(command, fragmentName) {
|
|
39
|
+
const change = command.getPreparedChange().getDefinition();
|
|
40
|
+
return change.content?.fragmentPath?.includes(`${fragmentName}.fragment.xml`) || false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Displays a message to the user indicating that an XML fragment will be created upon saving a change.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} message - The message to be shown in the message toast.
|
|
47
|
+
* @param {number} duration - The duration during which message toast will be active.
|
|
48
|
+
*/
|
|
49
|
+
function notifyUser(message) {
|
|
50
|
+
let duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5000;
|
|
51
|
+
MessageToast.show(message, {
|
|
52
|
+
duration
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
var __exports = {
|
|
56
|
+
__esModule: true
|
|
57
|
+
};
|
|
58
|
+
__exports.createDeferred = createDeferred;
|
|
59
|
+
__exports.matchesFragmentName = matchesFragmentName;
|
|
60
|
+
__exports.notifyUser = notifyUser;
|
|
61
|
+
return __exports;
|
|
62
62
|
});
|
|
63
63
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
sap.ui.define(["sap/ui/rta/command/CommandFactory", "./validator"], function (CommandFactory, ___validator) {
|
|
4
|
-
"use strict";
|
|
5
|
-
|
|
6
|
-
const validateBindingModel = ___validator["validateBindingModel"];
|
|
7
|
-
/**
|
|
8
|
-
* Function to check a give value is a binding expression.
|
|
9
|
-
*
|
|
10
|
-
* @param value value to be checked.
|
|
11
|
-
* @returns boolean
|
|
12
|
-
*/
|
|
13
|
-
function isBindingExpression(value) {
|
|
14
|
-
return value.includes('{') && value.includes('}') && value.indexOf('{') < value.indexOf('}');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
*
|
|
19
|
-
* @param options UI5 adaptation options
|
|
20
|
-
* @param change changed property of a control
|
|
21
|
-
*/
|
|
22
|
-
async function applyChange(options, change) {
|
|
23
|
-
const {
|
|
24
|
-
rta
|
|
25
|
-
} = options;
|
|
26
|
-
const modifiedControl = sap.ui.getCore().byId(change.controlId);
|
|
27
|
-
if (!modifiedControl) {
|
|
28
|
-
return;
|
|
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';
|
|
33
|
-
const flexSettings = rta.getFlexSettings();
|
|
34
|
-
const changeType = isBindingString ? 'BindProperty' : 'Property';
|
|
35
|
-
if (isBindingModel) {
|
|
36
|
-
validateBindingModel(modifiedControl, change.value);
|
|
37
|
-
}
|
|
38
|
-
const property = isBindingString ? 'newBinding' : 'newValue';
|
|
39
|
-
const modifiedValue = {
|
|
40
|
-
generator: flexSettings.generator,
|
|
41
|
-
propertyName: change.propertyName,
|
|
42
|
-
[property]: change.value
|
|
43
|
-
};
|
|
44
|
-
const command = await CommandFactory.getCommandFor(modifiedControl, changeType, modifiedValue, null, flexSettings);
|
|
45
|
-
await rta.getCommandStack().pushAndExecute(command);
|
|
46
|
-
}
|
|
47
|
-
var __exports = {
|
|
48
|
-
__esModule: true
|
|
49
|
-
};
|
|
50
|
-
__exports.applyChange = applyChange;
|
|
51
|
-
return __exports;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
sap.ui.define(["sap/ui/rta/command/CommandFactory", "./validator"], function (CommandFactory, ___validator) {
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
const validateBindingModel = ___validator["validateBindingModel"];
|
|
7
|
+
/**
|
|
8
|
+
* Function to check a give value is a binding expression.
|
|
9
|
+
*
|
|
10
|
+
* @param value value to be checked.
|
|
11
|
+
* @returns boolean
|
|
12
|
+
*/
|
|
13
|
+
function isBindingExpression(value) {
|
|
14
|
+
return value.includes('{') && value.includes('}') && value.indexOf('{') < value.indexOf('}');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param options UI5 adaptation options
|
|
20
|
+
* @param change changed property of a control
|
|
21
|
+
*/
|
|
22
|
+
async function applyChange(options, change) {
|
|
23
|
+
const {
|
|
24
|
+
rta
|
|
25
|
+
} = options;
|
|
26
|
+
const modifiedControl = sap.ui.getCore().byId(change.controlId);
|
|
27
|
+
if (!modifiedControl) {
|
|
28
|
+
return;
|
|
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';
|
|
33
|
+
const flexSettings = rta.getFlexSettings();
|
|
34
|
+
const changeType = isBindingString ? 'BindProperty' : 'Property';
|
|
35
|
+
if (isBindingModel) {
|
|
36
|
+
validateBindingModel(modifiedControl, change.value);
|
|
37
|
+
}
|
|
38
|
+
const property = isBindingString ? 'newBinding' : 'newValue';
|
|
39
|
+
const modifiedValue = {
|
|
40
|
+
generator: flexSettings.generator,
|
|
41
|
+
propertyName: change.propertyName,
|
|
42
|
+
[property]: change.value
|
|
43
|
+
};
|
|
44
|
+
const command = await CommandFactory.getCommandFor(modifiedControl, changeType, modifiedValue, null, flexSettings);
|
|
45
|
+
await rta.getCommandStack().pushAndExecute(command);
|
|
46
|
+
}
|
|
47
|
+
var __exports = {
|
|
48
|
+
__esModule: true
|
|
49
|
+
};
|
|
50
|
+
__exports.applyChange = applyChange;
|
|
51
|
+
return __exports;
|
|
52
52
|
});
|
|
53
53
|
//# sourceMappingURL=flex-change.js.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
sap.ui.define(["./service"], function (___service) {
|
|
4
|
-
"use strict";
|
|
5
|
-
|
|
6
|
-
var __exports = {
|
|
7
|
-
__esModule: true
|
|
8
|
-
};
|
|
9
|
-
__exports.ChangeService = ___service.ChangeService;
|
|
10
|
-
return __exports;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
sap.ui.define(["./service"], function (___service) {
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
var __exports = {
|
|
7
|
+
__esModule: true
|
|
8
|
+
};
|
|
9
|
+
__exports.ChangeService = ___service.ChangeService;
|
|
10
|
+
return __exports;
|
|
11
11
|
});
|
|
12
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
sap.ui.define([], function () {
|
|
4
|
-
"use strict";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Function to validate if a given value is a valid binding model.
|
|
8
|
-
*
|
|
9
|
-
* @param modifiedControl control to be modified.
|
|
10
|
-
* @param value value to be checked.
|
|
11
|
-
*/
|
|
12
|
-
function validateBindingModel(modifiedControl, value) {
|
|
13
|
-
const bindingValue = value.replace(/[{}]/gi, '').trim();
|
|
14
|
-
const bindingParts = bindingValue.split('>').filter(el => el !== '');
|
|
15
|
-
if (!bindingParts.length) {
|
|
16
|
-
throw new SyntaxError('Invalid binding string.');
|
|
17
|
-
}
|
|
18
|
-
if (bindingParts[0].trim() === 'i18n') {
|
|
19
|
-
if (bindingParts.length === 2) {
|
|
20
|
-
const resourceKey = bindingParts[1].trim();
|
|
21
|
-
const resourceBundle = modifiedControl.getModel('i18n').getResourceBundle();
|
|
22
|
-
if (!resourceBundle.getText(resourceKey, undefined, true)) {
|
|
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.');
|
|
24
|
-
}
|
|
25
|
-
} else {
|
|
26
|
-
throw new SyntaxError('Invalid binding string. Supported value pattern is {i18n>YOUR_KEY}');
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
var __exports = {
|
|
31
|
-
__esModule: true
|
|
32
|
-
};
|
|
33
|
-
__exports.validateBindingModel = validateBindingModel;
|
|
34
|
-
return __exports;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
sap.ui.define([], function () {
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Function to validate if a given value is a valid binding model.
|
|
8
|
+
*
|
|
9
|
+
* @param modifiedControl control to be modified.
|
|
10
|
+
* @param value value to be checked.
|
|
11
|
+
*/
|
|
12
|
+
function validateBindingModel(modifiedControl, value) {
|
|
13
|
+
const bindingValue = value.replace(/[{}]/gi, '').trim();
|
|
14
|
+
const bindingParts = bindingValue.split('>').filter(el => el !== '');
|
|
15
|
+
if (!bindingParts.length) {
|
|
16
|
+
throw new SyntaxError('Invalid binding string.');
|
|
17
|
+
}
|
|
18
|
+
if (bindingParts[0].trim() === 'i18n') {
|
|
19
|
+
if (bindingParts.length === 2) {
|
|
20
|
+
const resourceKey = bindingParts[1].trim();
|
|
21
|
+
const resourceBundle = modifiedControl.getModel('i18n').getResourceBundle();
|
|
22
|
+
if (!resourceBundle.getText(resourceKey, undefined, true)) {
|
|
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.');
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
throw new SyntaxError('Invalid binding string. Supported value pattern is {i18n>YOUR_KEY}');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
var __exports = {
|
|
31
|
+
__esModule: true
|
|
32
|
+
};
|
|
33
|
+
__exports.validateBindingModel = validateBindingModel;
|
|
34
|
+
return __exports;
|
|
35
35
|
});
|
|
36
36
|
//# sourceMappingURL=validator.js.map
|
|
@@ -1,166 +1,166 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
sap.ui.define(["./utils", "sap/base/Log"], function (___utils, Log) {
|
|
4
|
-
"use strict";
|
|
5
|
-
|
|
6
|
-
const getLibrary = ___utils["getLibrary"];
|
|
7
|
-
/**
|
|
8
|
-
* Get ui5 metadata of given library name.
|
|
9
|
-
*
|
|
10
|
-
* @param libName library name for eg: sap.m
|
|
11
|
-
* @returns Promise<SchemaForApiJsonFiles>
|
|
12
|
-
*/
|
|
13
|
-
async function getUi5ApiDtMetadata(libName) {
|
|
14
|
-
const libUrl = '/test-resources/' + libName.split('.').join('/') + '/designtime/api.json';
|
|
15
|
-
return fetch(libUrl).then(res => res.json());
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* load ui5 controls design time metadata api.json for following libraries
|
|
20
|
-
* sap.m, sap.ui.comp, sap.f, sap.ui.core
|
|
21
|
-
* loading libraries(more in file size) in parallel during initialization.
|
|
22
|
-
* Others (less in file size) are loaded dynamically in getControlMetadata method
|
|
23
|
-
*/
|
|
24
|
-
const ui5ApiDtMetadata = new Map();
|
|
25
|
-
function loadDefaultLibraries() {
|
|
26
|
-
const allData = Promise.all([getUi5ApiDtMetadata('sap.m'), getUi5ApiDtMetadata('sap.ui.comp'), getUi5ApiDtMetadata('sap.ui.core'), getUi5ApiDtMetadata('sap.f')]);
|
|
27
|
-
allData.then(res => {
|
|
28
|
-
res.forEach(api => {
|
|
29
|
-
if (api.library) {
|
|
30
|
-
ui5ApiDtMetadata.set(api.library, api);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}).catch(reason => Log.error('Loading Library Failed: ' + reason));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Format html text.
|
|
38
|
-
*
|
|
39
|
-
* @param sHtml - html string
|
|
40
|
-
* @returns string
|
|
41
|
-
*/
|
|
42
|
-
function formatHtmlText(sHtml) {
|
|
43
|
-
// replaced "sHtml.replace(new RegExp('<[^>]*>', 'g')" due to regex runtime vulnerability
|
|
44
|
-
const parts = (sHtml || '').split('<');
|
|
45
|
-
let result = '';
|
|
46
|
-
for (const part of parts) {
|
|
47
|
-
if (!result) {
|
|
48
|
-
result = part;
|
|
49
|
-
} else {
|
|
50
|
-
const indexClosingBracket = part.indexOf('>');
|
|
51
|
-
result += indexClosingBracket >= 0 ? part.substring(indexClosingBracket + 1) : `<${part}`;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Method to parse ui5 control metadata.
|
|
59
|
-
*
|
|
60
|
-
* @param controlLibMetadata control library metadata
|
|
61
|
-
* @param controlName name of the control
|
|
62
|
-
* @returns ControlMetadata
|
|
63
|
-
*/
|
|
64
|
-
function parseControlMetaModel(controlLibMetadata, controlName) {
|
|
65
|
-
const controlInfo = {
|
|
66
|
-
baseType: '',
|
|
67
|
-
doc: '',
|
|
68
|
-
properties: {}
|
|
69
|
-
};
|
|
70
|
-
const selectedControlMetadata = (controlLibMetadata.symbols ?? []).find(control => control.name === controlName);
|
|
71
|
-
if (selectedControlMetadata) {
|
|
72
|
-
// base type info of control is available on property 'extends'
|
|
73
|
-
controlInfo.baseType = selectedControlMetadata.extends;
|
|
74
|
-
controlInfo.doc = selectedControlMetadata.description ?? '';
|
|
75
|
-
const properties = selectedControlMetadata['ui5-metadata'].properties;
|
|
76
|
-
if (properties) {
|
|
77
|
-
properties.forEach(prop => {
|
|
78
|
-
prop.description = formatHtmlText(prop.description || '');
|
|
79
|
-
prop.propertyName = prop.name;
|
|
80
|
-
prop.propertyType = prop.type;
|
|
81
|
-
if (prop.defaultValue === null || prop.defaultValue === '') {
|
|
82
|
-
prop.defaultValue = '-';
|
|
83
|
-
}
|
|
84
|
-
controlInfo.properties[prop.name] = {
|
|
85
|
-
...prop
|
|
86
|
-
};
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return controlInfo;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Get control metadata for a given control.
|
|
95
|
-
*
|
|
96
|
-
* @param controlName name of the control
|
|
97
|
-
* @param contLibName library name of the control
|
|
98
|
-
* @returns Promise<ControlMetadata | undefined>
|
|
99
|
-
*/
|
|
100
|
-
async function getControlMetadata(controlName, contLibName) {
|
|
101
|
-
let result;
|
|
102
|
-
let controlLibMetadata = ui5ApiDtMetadata.get(contLibName);
|
|
103
|
-
if (controlLibMetadata) {
|
|
104
|
-
result = parseControlMetaModel(controlLibMetadata, controlName);
|
|
105
|
-
} else {
|
|
106
|
-
controlLibMetadata = await getUi5ApiDtMetadata(contLibName);
|
|
107
|
-
ui5ApiDtMetadata.set(contLibName, controlLibMetadata);
|
|
108
|
-
result = parseControlMetaModel(controlLibMetadata, controlName);
|
|
109
|
-
}
|
|
110
|
-
return result;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Get Control Property Documentation for a give control name and control library.
|
|
115
|
-
*
|
|
116
|
-
* @param controlName name of the control
|
|
117
|
-
* @param contLibName library name of the control
|
|
118
|
-
* @returns Promise<Properties | undefined>
|
|
119
|
-
*/
|
|
120
|
-
async function getControlPropertyDocumentation(controlName, contLibName) {
|
|
121
|
-
const doc = await getControlMetadata(controlName, contLibName);
|
|
122
|
-
if (doc) {
|
|
123
|
-
const baseControlType = doc.baseType;
|
|
124
|
-
if (baseControlType) {
|
|
125
|
-
const baseContLibName = await getLibrary(baseControlType);
|
|
126
|
-
if (baseContLibName) {
|
|
127
|
-
const baseControlProps = await getControlPropertyDocumentation(baseControlType, baseContLibName);
|
|
128
|
-
return {
|
|
129
|
-
...baseControlProps,
|
|
130
|
-
...doc.properties
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
...doc.properties
|
|
136
|
-
};
|
|
137
|
-
} else {
|
|
138
|
-
return undefined;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Get documentation of a given control of a ui5 library.
|
|
144
|
-
*
|
|
145
|
-
* @param controlName name of the control.
|
|
146
|
-
* @param contLibName library name of the control
|
|
147
|
-
* @returns Promise<Properties | undefined>
|
|
148
|
-
*/
|
|
149
|
-
async function getDocumentation(controlName, contLibName) {
|
|
150
|
-
let doc;
|
|
151
|
-
try {
|
|
152
|
-
doc = await getControlPropertyDocumentation(controlName, contLibName);
|
|
153
|
-
} catch (err) {
|
|
154
|
-
Log.error(`Error in getting documentation for ${contLibName}`);
|
|
155
|
-
}
|
|
156
|
-
return doc;
|
|
157
|
-
}
|
|
158
|
-
var __exports = {
|
|
159
|
-
__esModule: true
|
|
160
|
-
};
|
|
161
|
-
__exports.getUi5ApiDtMetadata = getUi5ApiDtMetadata;
|
|
162
|
-
__exports.loadDefaultLibraries = loadDefaultLibraries;
|
|
163
|
-
__exports.getDocumentation = getDocumentation;
|
|
164
|
-
return __exports;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
sap.ui.define(["./utils", "sap/base/Log"], function (___utils, Log) {
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
const getLibrary = ___utils["getLibrary"];
|
|
7
|
+
/**
|
|
8
|
+
* Get ui5 metadata of given library name.
|
|
9
|
+
*
|
|
10
|
+
* @param libName library name for eg: sap.m
|
|
11
|
+
* @returns Promise<SchemaForApiJsonFiles>
|
|
12
|
+
*/
|
|
13
|
+
async function getUi5ApiDtMetadata(libName) {
|
|
14
|
+
const libUrl = '/test-resources/' + libName.split('.').join('/') + '/designtime/api.json';
|
|
15
|
+
return fetch(libUrl).then(res => res.json());
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* load ui5 controls design time metadata api.json for following libraries
|
|
20
|
+
* sap.m, sap.ui.comp, sap.f, sap.ui.core
|
|
21
|
+
* loading libraries(more in file size) in parallel during initialization.
|
|
22
|
+
* Others (less in file size) are loaded dynamically in getControlMetadata method
|
|
23
|
+
*/
|
|
24
|
+
const ui5ApiDtMetadata = new Map();
|
|
25
|
+
function loadDefaultLibraries() {
|
|
26
|
+
const allData = Promise.all([getUi5ApiDtMetadata('sap.m'), getUi5ApiDtMetadata('sap.ui.comp'), getUi5ApiDtMetadata('sap.ui.core'), getUi5ApiDtMetadata('sap.f')]);
|
|
27
|
+
allData.then(res => {
|
|
28
|
+
res.forEach(api => {
|
|
29
|
+
if (api.library) {
|
|
30
|
+
ui5ApiDtMetadata.set(api.library, api);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}).catch(reason => Log.error('Loading Library Failed: ' + reason));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Format html text.
|
|
38
|
+
*
|
|
39
|
+
* @param sHtml - html string
|
|
40
|
+
* @returns string
|
|
41
|
+
*/
|
|
42
|
+
function formatHtmlText(sHtml) {
|
|
43
|
+
// replaced "sHtml.replace(new RegExp('<[^>]*>', 'g')" due to regex runtime vulnerability
|
|
44
|
+
const parts = (sHtml || '').split('<');
|
|
45
|
+
let result = '';
|
|
46
|
+
for (const part of parts) {
|
|
47
|
+
if (!result) {
|
|
48
|
+
result = part;
|
|
49
|
+
} else {
|
|
50
|
+
const indexClosingBracket = part.indexOf('>');
|
|
51
|
+
result += indexClosingBracket >= 0 ? part.substring(indexClosingBracket + 1) : `<${part}`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Method to parse ui5 control metadata.
|
|
59
|
+
*
|
|
60
|
+
* @param controlLibMetadata control library metadata
|
|
61
|
+
* @param controlName name of the control
|
|
62
|
+
* @returns ControlMetadata
|
|
63
|
+
*/
|
|
64
|
+
function parseControlMetaModel(controlLibMetadata, controlName) {
|
|
65
|
+
const controlInfo = {
|
|
66
|
+
baseType: '',
|
|
67
|
+
doc: '',
|
|
68
|
+
properties: {}
|
|
69
|
+
};
|
|
70
|
+
const selectedControlMetadata = (controlLibMetadata.symbols ?? []).find(control => control.name === controlName);
|
|
71
|
+
if (selectedControlMetadata) {
|
|
72
|
+
// base type info of control is available on property 'extends'
|
|
73
|
+
controlInfo.baseType = selectedControlMetadata.extends;
|
|
74
|
+
controlInfo.doc = selectedControlMetadata.description ?? '';
|
|
75
|
+
const properties = selectedControlMetadata['ui5-metadata'].properties;
|
|
76
|
+
if (properties) {
|
|
77
|
+
properties.forEach(prop => {
|
|
78
|
+
prop.description = formatHtmlText(prop.description || '');
|
|
79
|
+
prop.propertyName = prop.name;
|
|
80
|
+
prop.propertyType = prop.type;
|
|
81
|
+
if (prop.defaultValue === null || prop.defaultValue === '') {
|
|
82
|
+
prop.defaultValue = '-';
|
|
83
|
+
}
|
|
84
|
+
controlInfo.properties[prop.name] = {
|
|
85
|
+
...prop
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return controlInfo;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Get control metadata for a given control.
|
|
95
|
+
*
|
|
96
|
+
* @param controlName name of the control
|
|
97
|
+
* @param contLibName library name of the control
|
|
98
|
+
* @returns Promise<ControlMetadata | undefined>
|
|
99
|
+
*/
|
|
100
|
+
async function getControlMetadata(controlName, contLibName) {
|
|
101
|
+
let result;
|
|
102
|
+
let controlLibMetadata = ui5ApiDtMetadata.get(contLibName);
|
|
103
|
+
if (controlLibMetadata) {
|
|
104
|
+
result = parseControlMetaModel(controlLibMetadata, controlName);
|
|
105
|
+
} else {
|
|
106
|
+
controlLibMetadata = await getUi5ApiDtMetadata(contLibName);
|
|
107
|
+
ui5ApiDtMetadata.set(contLibName, controlLibMetadata);
|
|
108
|
+
result = parseControlMetaModel(controlLibMetadata, controlName);
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Get Control Property Documentation for a give control name and control library.
|
|
115
|
+
*
|
|
116
|
+
* @param controlName name of the control
|
|
117
|
+
* @param contLibName library name of the control
|
|
118
|
+
* @returns Promise<Properties | undefined>
|
|
119
|
+
*/
|
|
120
|
+
async function getControlPropertyDocumentation(controlName, contLibName) {
|
|
121
|
+
const doc = await getControlMetadata(controlName, contLibName);
|
|
122
|
+
if (doc) {
|
|
123
|
+
const baseControlType = doc.baseType;
|
|
124
|
+
if (baseControlType) {
|
|
125
|
+
const baseContLibName = await getLibrary(baseControlType);
|
|
126
|
+
if (baseContLibName) {
|
|
127
|
+
const baseControlProps = await getControlPropertyDocumentation(baseControlType, baseContLibName);
|
|
128
|
+
return {
|
|
129
|
+
...baseControlProps,
|
|
130
|
+
...doc.properties
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
...doc.properties
|
|
136
|
+
};
|
|
137
|
+
} else {
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Get documentation of a given control of a ui5 library.
|
|
144
|
+
*
|
|
145
|
+
* @param controlName name of the control.
|
|
146
|
+
* @param contLibName library name of the control
|
|
147
|
+
* @returns Promise<Properties | undefined>
|
|
148
|
+
*/
|
|
149
|
+
async function getDocumentation(controlName, contLibName) {
|
|
150
|
+
let doc;
|
|
151
|
+
try {
|
|
152
|
+
doc = await getControlPropertyDocumentation(controlName, contLibName);
|
|
153
|
+
} catch (err) {
|
|
154
|
+
Log.error(`Error in getting documentation for ${contLibName}`);
|
|
155
|
+
}
|
|
156
|
+
return doc;
|
|
157
|
+
}
|
|
158
|
+
var __exports = {
|
|
159
|
+
__esModule: true
|
|
160
|
+
};
|
|
161
|
+
__exports.getUi5ApiDtMetadata = getUi5ApiDtMetadata;
|
|
162
|
+
__exports.loadDefaultLibraries = loadDefaultLibraries;
|
|
163
|
+
__exports.getDocumentation = getDocumentation;
|
|
164
|
+
return __exports;
|
|
165
165
|
});
|
|
166
166
|
//# sourceMappingURL=documentation.js.map
|