@sap-ux/fe-fpm-writer 0.24.9 → 0.24.10

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,4 +1,4 @@
1
- import type { CustomElement, InternalCustomElement, Manifest } from './types';
1
+ import type { CustomElement, FragmentContentData, InternalCustomElement, Manifest } from './types';
2
2
  export declare const FCL_ROUTER = "sap.f.routing.Router";
3
3
  /**
4
4
  * Sets the common default values for all custom elements.
@@ -9,6 +9,19 @@ export declare const FCL_ROUTER = "sap.f.routing.Router";
9
9
  * @returns enhanced configuration
10
10
  */
11
11
  export declare function setCommonDefaults<T extends CustomElement & Partial<InternalCustomElement>>(config: T, manifestPath: string, manifest: Manifest): InternalCustomElement & T;
12
+ /**
13
+ * Method to generate default content data for xml fragment.
14
+ *
15
+ * @param {string} text - text of button or label
16
+ * @param {string} [eventHandler] - event handler path
17
+ * if value is passed then "Button" control with 'press' event would be generated
18
+ * if value is not passed then "Text" control would be generated
19
+ * @param {boolean} isController - controls if `controller` should be added to handler path
20
+ * @param {boolean} prefferInput - controls if `input` element should be added to default fragment content
21
+ * @param {boolean} includeRequireInContent - controls if `core:require` attribute should be included to fragment content
22
+ * @returns default content for fragment
23
+ */
24
+ export declare function getDefaultFragmentContentData(text: string, eventHandler?: string, isController?: boolean, prefferInput?: boolean, includeRequireInContent?: boolean): FragmentContentData;
12
25
  /**
13
26
  * Method to generate default content for xml fragment.
14
27
  *
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDefaultFragmentContent = exports.setCommonDefaults = exports.FCL_ROUTER = void 0;
3
+ exports.getDefaultFragmentContent = exports.getDefaultFragmentContentData = exports.setCommonDefaults = exports.FCL_ROUTER = void 0;
4
4
  const path_1 = require("path");
5
5
  exports.FCL_ROUTER = 'sap.f.routing.Router';
6
6
  /**
@@ -21,7 +21,7 @@ function setCommonDefaults(config, manifestPath, manifest) {
21
21
  }
22
22
  exports.setCommonDefaults = setCommonDefaults;
23
23
  /**
24
- * Method to generate default content for xml fragment.
24
+ * Method to generate default content data for xml fragment.
25
25
  *
26
26
  * @param {string} text - text of button or label
27
27
  * @param {string} [eventHandler] - event handler path
@@ -29,20 +29,30 @@ exports.setCommonDefaults = setCommonDefaults;
29
29
  * if value is not passed then "Text" control would be generated
30
30
  * @param {boolean} isController - controls if `controller` should be added to handler path
31
31
  * @param {boolean} prefferInput - controls if `input` element should be added to default fragment content
32
+ * @param {boolean} includeRequireInContent - controls if `core:require` attribute should be included to fragment content
32
33
  * @returns default content for fragment
33
34
  */
34
- function getDefaultFragmentContent(text, eventHandler, isController = false, prefferInput = false) {
35
+ function getDefaultFragmentContentData(text, eventHandler, isController = false, prefferInput = false, includeRequireInContent = true) {
35
36
  let content;
37
+ let requireAttribute;
36
38
  if (eventHandler) {
37
39
  const parts = eventHandler.split('.');
38
40
  const method = parts.pop();
39
41
  const handler = `${parts.join('/')}${isController ? '.controller' : ''}`;
40
- const requireAttr = `core:require="{ handler: '${handler}'}"`;
42
+ requireAttribute = `core:require="{ handler: '${handler}'}"`;
43
+ const attributes = [];
44
+ if (includeRequireInContent) {
45
+ attributes.push(requireAttribute);
46
+ }
41
47
  if (prefferInput) {
42
- content = `<Input ${requireAttr} value="${text}" change="handler.${method}" />`;
48
+ attributes.push(`value="${text}"`);
49
+ attributes.push(`change="handler.${method}"`);
50
+ content = `<Input ${attributes.join(' ')} />`;
43
51
  }
44
52
  else {
45
- content = `<Button ${requireAttr} text="${text}" press="handler.${method}" />`;
53
+ attributes.push(`text="${text}"`);
54
+ attributes.push(`press="handler.${method}"`);
55
+ content = `<Button ${attributes.join(' ')} />`;
46
56
  }
47
57
  }
48
58
  else if (prefferInput) {
@@ -51,7 +61,26 @@ function getDefaultFragmentContent(text, eventHandler, isController = false, pre
51
61
  else {
52
62
  content = `<Text text="${text}" />`;
53
63
  }
54
- return content;
64
+ return {
65
+ content,
66
+ requireAttribute
67
+ };
68
+ }
69
+ exports.getDefaultFragmentContentData = getDefaultFragmentContentData;
70
+ /**
71
+ * Method to generate default content for xml fragment.
72
+ *
73
+ * @param {string} text - text of button or label
74
+ * @param {string} [eventHandler] - event handler path
75
+ * if value is passed then "Button" control with 'press' event would be generated
76
+ * if value is not passed then "Text" control would be generated
77
+ * @param {boolean} isController - controls if `controller` should be added to handler path
78
+ * @param {boolean} prefferInput - controls if `input` element should be added to default fragment content
79
+ * @returns default content for fragment
80
+ */
81
+ function getDefaultFragmentContent(text, eventHandler, isController = false, prefferInput = false) {
82
+ const contentData = getDefaultFragmentContentData(text, eventHandler, isController, prefferInput);
83
+ return contentData.content;
55
84
  }
56
85
  exports.getDefaultFragmentContent = getDefaultFragmentContent;
57
86
  //# sourceMappingURL=defaults.js.map
@@ -170,4 +170,11 @@ export interface CustomFragment {
170
170
  */
171
171
  fragmentFile?: string;
172
172
  }
173
+ /**
174
+ * Interface represents content data of generated fragment.
175
+ */
176
+ export interface FragmentContentData {
177
+ content: string;
178
+ requireAttribute?: string;
179
+ }
173
180
  //# sourceMappingURL=types.d.ts.map
@@ -58,7 +58,12 @@ function enhanceConfig(fs, data, manifestPath, manifest) {
58
58
  });
59
59
  }
60
60
  // generate section content
61
- config.content = config.control || (0, defaults_1.getDefaultFragmentContent)(config.name, config.eventHandler);
61
+ if (config.control) {
62
+ config.content = config.control;
63
+ }
64
+ else {
65
+ Object.assign(config, (0, defaults_1.getDefaultFragmentContentData)(config.name, config.eventHandler, undefined, undefined, false));
66
+ }
62
67
  // Additional dependencies to include into 'Fragment.xml'
63
68
  config.dependencies = getAdditionalDependencies(config.minUI5Version);
64
69
  return config;
@@ -106,7 +111,6 @@ function generate(basePath, customSection, manifestTemplateRoot, fs) {
106
111
  * @returns {Promise<Editor>} the updated mem-fs editor instance
107
112
  */
108
113
  function generateCustomHeaderSection(basePath, customHeaderSection, fs) {
109
- var _a;
110
114
  if (!fs) {
111
115
  fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
112
116
  }
@@ -134,8 +138,12 @@ function generateCustomHeaderSection(basePath, customHeaderSection, fs) {
134
138
  });
135
139
  }
136
140
  // Generate edit fragment content
137
- editSection.content =
138
- (_a = editSection.control) !== null && _a !== void 0 ? _a : (0, defaults_1.getDefaultFragmentContent)(editSection.name, editSection.eventHandler, false, true);
141
+ if (editSection.control) {
142
+ editSection.content = editSection.control;
143
+ }
144
+ else {
145
+ Object.assign(editSection, (0, defaults_1.getDefaultFragmentContentData)(editSection.name, editSection.eventHandler, false, true, false));
146
+ }
139
147
  if (editSection.path) {
140
148
  const viewPath = (0, path_1.join)(editSection.path, `${editSection.name}.fragment.xml`);
141
149
  if (!editor.exists(viewPath)) {
@@ -1,4 +1,4 @@
1
- import type { CustomElement, InternalCustomElement, Position, EventHandler, CustomFragment } from '../common/types';
1
+ import type { CustomElement, InternalCustomElement, Position, EventHandler, CustomFragment, FragmentContentData } from '../common/types';
2
2
  export interface CustomSection extends CustomElement, EventHandler, CustomFragment {
3
3
  /**
4
4
  * Name of the routing target
@@ -17,8 +17,7 @@ export interface CustomSection extends CustomElement, EventHandler, CustomFragme
17
17
  */
18
18
  control?: string;
19
19
  }
20
- export interface InternalCustomSection extends CustomHeaderSection, CustomSection, CustomSubSection, InternalCustomElement {
21
- content: string;
20
+ export interface InternalCustomSection extends CustomHeaderSection, CustomSection, CustomSubSection, InternalCustomElement, FragmentContentData {
22
21
  dependencies?: string;
23
22
  }
24
23
  export type HeaderSectionEditProperty = Pick<CustomElement, 'name' | 'folder'> & EventHandler;
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.24.9",
4
+ "version": "0.24.10",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -33,7 +33,7 @@
33
33
  "@types/mem-fs": "1.1.2",
34
34
  "@types/mem-fs-editor": "7.0.1",
35
35
  "@types/semver": "7.5.2",
36
- "@sap-ux/project-access": "1.17.5"
36
+ "@sap-ux/project-access": "1.19.12"
37
37
  },
38
38
  "engines": {
39
39
  "node": ">=18.x"
@@ -1,5 +1,5 @@
1
1
  <core:FragmentDefinition xmlns:core="sap.ui.core" xmlns="sap.m" xmlns:f="sap.ui.layout.form"<%- typeof dependencies !== 'undefined' ? ` ${dependencies}` : '' %>>
2
- <f:FormElement>
2
+ <f:FormElement<%- typeof requireAttribute !== 'undefined' ? ` ${requireAttribute}` : '' %>>
3
3
  <f:fields>
4
4
  <%- content %>
5
5
  </f:fields>
@@ -1,5 +1,5 @@
1
1
  <core:FragmentDefinition xmlns:core="sap.ui.core" xmlns="sap.m"<%- typeof dependencies !== 'undefined' ? ` ${dependencies}` : '' %>>
2
- <VBox>
2
+ <VBox<%- typeof requireAttribute !== 'undefined' ? ` ${requireAttribute}` : '' %>>
3
3
  <%- content %>
4
4
  </VBox>
5
5
  </core:FragmentDefinition>