@sap-ux/fe-fpm-writer 0.38.1 → 0.38.3

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.
@@ -99,7 +99,7 @@ async function generateCustomAction(basePath, actionConfig, fs) {
99
99
  config.eventHandler = (0, event_handler_1.applyEventHandlerConfiguration)(fs, config, config.eventHandler, {
100
100
  controllerSuffix: false,
101
101
  typescript: config.typescript
102
- }, event_handler_1.contextParameter);
102
+ }, [event_handler_1.contextParameter, event_handler_1.selectedContextsParameter]);
103
103
  }
104
104
  // enhance manifest with action definition and controller reference
105
105
  const actions = enhanceManifestAndGetActionsElementReference(manifest, config.target);
@@ -9,23 +9,32 @@ interface EventHandlerConfigurationOptions {
9
9
  templatePath?: string;
10
10
  eventHandlerFnName?: string;
11
11
  }
12
+ type EventHandlerTypescriptParameters = EventHandlerTypescriptParameter[];
12
13
  /**
13
14
  * Interface to describe the input parameters for the generated event handler function.
14
15
  */
15
- export interface EventHandlerTypescriptParameters {
16
+ export interface EventHandlerTypescriptParameter {
17
+ /** Variable name in TypeScript style */
16
18
  name: string;
19
+ /** Variable name in JavaScript style (Hungarian notation) */
20
+ jsName: string;
17
21
  description: string;
18
22
  importType: string;
23
+ /**
24
+ * Optional. If not defined, the parameter type will be taken from `importType`.
25
+ */
26
+ paramType?: string;
19
27
  importSource: string;
20
28
  }
21
29
  /**
22
30
  * Default values for the input parameters of newly created event handlers.
23
31
  */
24
- export declare const defaultParameter: EventHandlerTypescriptParameters;
32
+ export declare const defaultParameter: EventHandlerTypescriptParameter;
25
33
  /**
26
34
  * Values for the input parameters of newly created event handlers that are added as manifest actions.
27
35
  */
28
- export declare const contextParameter: EventHandlerTypescriptParameters;
36
+ export declare const contextParameter: EventHandlerTypescriptParameter;
37
+ export declare const selectedContextsParameter: EventHandlerTypescriptParameter;
29
38
  /**
30
39
  * Method creates or updates handler js file and update 'settings.eventHandler' entry with namespace path entry to method.
31
40
  *
@@ -33,7 +42,7 @@ export declare const contextParameter: EventHandlerTypescriptParameters;
33
42
  * @param config - configuration
34
43
  * @param eventHandler - eventHandler for creation
35
44
  * @param eventHandlerOptions - eventHandler options
36
- * @param parameters - parameter configurations for the event handler
45
+ * @param parameters - parameters and its configurations for the event handler
37
46
  * @returns {string} full namespace path to method
38
47
  */
39
48
  export declare function applyEventHandlerConfiguration(fs: Editor, config: Partial<InternalCustomElement>, eventHandler: EventHandlerConfiguration | true | string, eventHandlerOptions: EventHandlerConfigurationOptions, parameters?: EventHandlerTypescriptParameters): string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.contextParameter = exports.defaultParameter = void 0;
3
+ exports.selectedContextsParameter = exports.contextParameter = exports.defaultParameter = void 0;
4
4
  exports.applyEventHandlerConfiguration = applyEventHandlerConfiguration;
5
5
  const path_1 = require("path");
6
6
  const templates_1 = require("../templates");
@@ -10,7 +10,8 @@ const utils_1 = require("../common/utils");
10
10
  */
11
11
  exports.defaultParameter = {
12
12
  name: 'event',
13
- description: 'the event object provided by the event provider',
13
+ jsName: 'oEvent',
14
+ description: 'the event object provided by the event provider.',
14
15
  importType: 'UI5Event',
15
16
  importSource: 'sap/ui/base/Event'
16
17
  };
@@ -18,9 +19,19 @@ exports.defaultParameter = {
18
19
  * Values for the input parameters of newly created event handlers that are added as manifest actions.
19
20
  */
20
21
  exports.contextParameter = {
21
- name: 'pageContext',
22
- description: 'the context of the page on which the event was fired',
22
+ name: 'context',
23
+ jsName: 'oContext',
24
+ description: 'the context of the page on which the event was fired. `undefined` for list report page.',
23
25
  importType: 'Context',
26
+ paramType: 'Context | undefined',
27
+ importSource: 'sap/ui/model/odata/v4/Context'
28
+ };
29
+ exports.selectedContextsParameter = {
30
+ name: 'selectedContexts',
31
+ jsName: 'aSelectedContexts',
32
+ description: 'the selected contexts of the table rows.',
33
+ importType: 'Context',
34
+ paramType: 'Context[]',
24
35
  importSource: 'sap/ui/model/odata/v4/Context'
25
36
  };
26
37
  /**
@@ -49,10 +60,10 @@ function getFileName(fileName, controllerPrefix) {
49
60
  * @param config - configuration
50
61
  * @param eventHandler - eventHandler for creation
51
62
  * @param eventHandlerOptions - eventHandler options
52
- * @param parameters - parameter configurations for the event handler
63
+ * @param parameters - parameters and its configurations for the event handler
53
64
  * @returns {string} full namespace path to method
54
65
  */
55
- function applyEventHandlerConfiguration(fs, config, eventHandler, eventHandlerOptions, parameters = exports.defaultParameter) {
66
+ function applyEventHandlerConfiguration(fs, config, eventHandler, eventHandlerOptions, parameters = [exports.defaultParameter]) {
56
67
  const { controllerSuffix, typescript, templatePath = 'common/EventHandler' } = eventHandlerOptions;
57
68
  let { eventHandlerFnName = 'onPress' } = eventHandlerOptions;
58
69
  if (typeof eventHandler === 'string') {
@@ -56,7 +56,7 @@ async function generateCustomFilter(basePath, filterConfig, fs) {
56
56
  controllerSuffix: false,
57
57
  typescript: config.typescript,
58
58
  templatePath: 'filter/Controller'
59
- }, event_handler_1.contextParameter);
59
+ }, [event_handler_1.contextParameter]);
60
60
  }
61
61
  // enhance manifest with the filter definition and controller reference
62
62
  const filters = enhanceManifestAndGetFiltersReference(manifest);
@@ -1,5 +1,6 @@
1
1
  import type { Editor } from 'mem-fs-editor';
2
2
  import type { CustomPage, InternalCustomPage } from './types';
3
+ import type { Logger } from '@sap-ux/logger';
3
4
  /**
4
5
  * Enhances the provided custom page configuration with default data.
5
6
  *
@@ -22,7 +23,8 @@ export declare function getTemplateRoot(ui5Version?: string): string;
22
23
  * @param {string} basePath - the base path
23
24
  * @param {CustomPage} data - the custom page configuration
24
25
  * @param {Editor} [fs] - the memfs editor instance
26
+ * @param {Logger} [log] - Logger instance
25
27
  * @returns {Promise<Editor>} the updated memfs editor instance
26
28
  */
27
- export declare function generate(basePath: string, data: CustomPage, fs?: Editor): Promise<Editor>;
29
+ export declare function generate(basePath: string, data: CustomPage, fs?: Editor, log?: Logger): Promise<Editor>;
28
30
  //# sourceMappingURL=custom.d.ts.map
@@ -18,6 +18,7 @@ const file_1 = require("../common/file");
18
18
  const building_block_1 = require("../building-block");
19
19
  const types_2 = require("../building-block/types");
20
20
  const xml_1 = require("../building-block/prompts/utils/xml");
21
+ const i18n_1 = require("../i18n");
21
22
  /**
22
23
  * Enhances the provided custom page configuration with default data.
23
24
  *
@@ -61,15 +62,46 @@ function getTemplateRoot(ui5Version) {
61
62
  return (0, templates_1.getTemplatePath)('/page/custom/1.84');
62
63
  }
63
64
  }
65
+ /**
66
+ * Handles the creation of a page building block for a custom page.
67
+ *
68
+ * @param {string} basePath - The base path of the UI5 application.
69
+ * @param {{ pageBuildingBlockTitle: string; minUI5Version?: string }} data - Object containing the building block title and optional minimum UI5 version.
70
+ * @param data.pageBuildingBlockTitle
71
+ * @param data.minUI5Version
72
+ * @param {string} viewPath - The path to the view XML file.
73
+ * @param {Editor} fs - The memfs editor instance.
74
+ * @param {Logger} [log] - Logger instance.
75
+ * @returns {Promise<void>} Resolves when the building block is handled or skipped due to version constraints.
76
+ */
77
+ async function handlePageBuildingBlock(basePath, data, viewPath, fs, log) {
78
+ const minVersion = (0, semver_1.coerce)(data.minUI5Version);
79
+ const t = (0, i18n_1.translate)(i18n_1.i18nNamespaces.buildingBlock, 'pageBuildingBlock.');
80
+ if (minVersion && (0, semver_1.lt)(minVersion.version, '1.136.0')) {
81
+ log?.warn(t('minUi5VersionRequirement', { minUI5Version: data.minUI5Version }));
82
+ return;
83
+ }
84
+ await (0, building_block_1.generateBuildingBlock)(basePath, {
85
+ viewOrFragmentPath: (0, path_1.relative)(basePath, viewPath),
86
+ aggregationPath: (0, xml_1.augmentXpathWithLocalNames)(`/mvc:View/Page`),
87
+ replace: true,
88
+ buildingBlockData: {
89
+ id: 'Page',
90
+ buildingBlockType: types_2.BuildingBlockType.Page,
91
+ title: data.pageBuildingBlockTitle
92
+ }
93
+ }, fs);
94
+ }
64
95
  /**
65
96
  * Add a custom page to an existing UI5 application.
66
97
  *
67
98
  * @param {string} basePath - the base path
68
99
  * @param {CustomPage} data - the custom page configuration
69
100
  * @param {Editor} [fs] - the memfs editor instance
101
+ * @param {Logger} [log] - Logger instance
70
102
  * @returns {Promise<Editor>} the updated memfs editor instance
71
103
  */
72
- async function generate(basePath, data, fs) {
104
+ async function generate(basePath, data, fs, log) {
73
105
  if (!fs) {
74
106
  fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
75
107
  }
@@ -104,16 +136,7 @@ async function generate(basePath, data, fs) {
104
136
  }
105
137
  }
106
138
  if (data.pageBuildingBlockTitle) {
107
- await (0, building_block_1.generateBuildingBlock)(basePath, {
108
- viewOrFragmentPath: (0, path_1.relative)(basePath, viewPath),
109
- aggregationPath: (0, xml_1.augmentXpathWithLocalNames)(`/mvc:View/Page`),
110
- replace: true,
111
- buildingBlockData: {
112
- id: 'Page',
113
- buildingBlockType: types_2.BuildingBlockType.Page,
114
- title: data.pageBuildingBlockTitle
115
- }
116
- }, fs);
139
+ await handlePageBuildingBlock(basePath, { pageBuildingBlockTitle: data.pageBuildingBlockTitle, minUI5Version: data.minUI5Version }, viewPath, fs, log);
117
140
  }
118
141
  const ext = data.typescript ? 'ts' : 'js';
119
142
  const controllerPath = (0, path_1.join)(config.path, `${config.name}.controller.${ext}`);
@@ -204,6 +204,9 @@ declare const ns1: {
204
204
  };
205
205
  };
206
206
  };
207
+ pageBuildingBlock: {
208
+ minUi5VersionRequirement: string;
209
+ };
207
210
  };
208
211
  export default ns1;
209
212
  //# sourceMappingURL=i18n.d.ts.map
@@ -229,6 +229,9 @@ const ns1 = {
229
229
  'translationAnnotation': 'Description of the Page.'
230
230
  }
231
231
  }
232
+ },
233
+ 'pageBuildingBlock': {
234
+ 'minUi5VersionRequirement': 'The Page building block feature requires SAPUI5 1.136.0 or higher. The current version is {{ minUI5Version }}, so the Page building block will not be added.'
232
235
  }
233
236
  };
234
237
  exports.default = ns1;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sap-ux/fe-fpm-writer",
3
3
  "description": "SAP Fiori elements flexible programming model writer",
4
- "version": "0.38.1",
4
+ "version": "0.38.3",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -31,7 +31,8 @@
31
31
  "xml-formatter": "2.6.1",
32
32
  "xpath": "0.0.33",
33
33
  "@sap-ux/fiori-annotation-api": "0.6.17",
34
- "@sap-ux/project-access": "1.30.13"
34
+ "@sap-ux/project-access": "1.30.13",
35
+ "@sap-ux/logger": "0.7.0"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@types/inquirer": "8.2.6",
@@ -4,7 +4,21 @@ sap.ui.define([
4
4
  'use strict';
5
5
 
6
6
  return {
7
- <%- eventHandlerFnName %>: function(oEvent) {
7
+ <% if (typeof parameters !== "undefined" && parameters.length) { -%>
8
+ /**
9
+ * Generated event handler.
10
+ *
11
+ <% parameters.forEach(function(param) { -%>
12
+ * @param <%- param.jsName %> <%- param.description %>
13
+ <% }) -%>
14
+ */
15
+ <% } -%>
16
+ <%- eventHandlerFnName %>: function(<%=
17
+ (typeof parameters !== "undefined" ? parameters : [])
18
+ .map(function(param) {
19
+ return param.jsName;
20
+ }).join(", ")
21
+ -%>) {
8
22
  MessageToast.show("Custom handler invoked.");
9
23
  }
10
24
  };
@@ -1,13 +1,28 @@
1
1
  import ExtensionAPI from 'sap/fe/core/ExtensionAPI';
2
- import <%- parameters.importType %> from '<%- parameters.importSource %>';
2
+ <%
3
+ const importedTypes = new Set();
4
+ parameters.forEach(param => {
5
+ if (param.importType && !importedTypes.has(param.importType)) {
6
+ importedTypes.add(param.importType);
7
+ -%>
8
+ import <%- param.importType %> from '<%- param.importSource %>';
9
+ <%
10
+ }
11
+ }); -%>
3
12
  import MessageToast from 'sap/m/MessageToast';
4
13
 
5
14
  /**
6
15
  * Generated event handler.
7
16
  *
8
17
  * @param this reference to the 'this' that the event handler is bound to.
9
- * @param <%- parameters.name %> <%- parameters.description %>
18
+ <% parameters.forEach(function(param) { -%>
19
+ * @param <%- param.name %> <%- param.description %>
20
+ <% }) -%>
10
21
  */
11
- export function <%- eventHandlerFnName %>(this: ExtensionAPI, <%- parameters.name %>: <%- parameters.importType %>) {
22
+ export function <%- eventHandlerFnName %>(this: ExtensionAPI, <%=
23
+ parameters.map(function(param) {
24
+ return param.name + ": " + (param.paramType ?? param.importType);
25
+ }).join(", ")
26
+ %>) {
12
27
  MessageToast.show("Custom handler invoked.");
13
28
  }