@sap-ux/fe-fpm-writer 1.3.11 → 1.3.13

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.
@@ -96,7 +96,7 @@ export async function getChartBuildingBlockPrompts(context) {
96
96
  getAggregationPathPrompt(context, {
97
97
  message: t('aggregation'),
98
98
  guiOptions: { groupId: groupIds.commonChartBuildingBlockProperties, mandatory: true }
99
- }),
99
+ }, { defaultTarget: 'items' }),
100
100
  getFilterBarIdPrompt(context, {
101
101
  message: t('filterBar.message'),
102
102
  type: 'list',
@@ -73,7 +73,7 @@ export async function getFilterBarBuildingBlockPrompts(context) {
73
73
  getAggregationPathPrompt(context, {
74
74
  message: t('aggregation'),
75
75
  guiOptions: { groupId: groupIds.commonFilterBarBuildingBlockProperties, mandatory: true }
76
- }),
76
+ }, { defaultTarget: 'items' }),
77
77
  getEntityPrompt(context, {
78
78
  message: t('entity'),
79
79
  guiOptions: {
@@ -89,7 +89,7 @@ export async function getFormBuildingBlockPrompts(context) {
89
89
  groupId: groupIds.commonFormBuildingBlockProperties,
90
90
  mandatory: true
91
91
  }
92
- }),
92
+ }, { defaultTarget: 'items' }),
93
93
  {
94
94
  type: 'input',
95
95
  name: 'buildingBlockData.title',
@@ -108,7 +108,7 @@ export async function getTableBuildingBlockPrompts(context) {
108
108
  groupId: groupIds.commonTableBuildingBlockProperties,
109
109
  mandatory: true
110
110
  }
111
- }),
111
+ }, { defaultTarget: 'items' }),
112
112
  getFilterBarIdPrompt(context, {
113
113
  message: t('filterBar.message'),
114
114
  type: 'list',
@@ -63,9 +63,13 @@ export declare function getCAPServiceChoices(project: Project, appId: string): P
63
63
  *
64
64
  * @param context - prompt context including data about project
65
65
  * @param properties - object with additional properties of question
66
+ * @param options - additional options
67
+ * @param options.defaultTarget - preferred aggregation to pre-select by default: `'page'` (default) or `'items'`
66
68
  * @returns prompt for choosing aggregation path of selected xml file.
67
69
  */
68
- export declare function getAggregationPathPrompt(context: PromptContext, properties?: Partial<ListPromptQuestion>): ListPromptQuestion;
70
+ export declare function getAggregationPathPrompt(context: PromptContext, properties?: Partial<ListPromptQuestion>, options?: {
71
+ defaultTarget?: 'page' | 'items';
72
+ }): ListPromptQuestion;
69
73
  /**
70
74
  * Method converts choices to "PromptListChoices" type.
71
75
  *
@@ -212,16 +212,59 @@ export async function getCAPServiceChoices(project, appId) {
212
212
  }
213
213
  return transformChoices(servicesMap);
214
214
  }
215
+ /**
216
+ * Resolves the default (pre-selected) aggregation-path choice key.
217
+ *
218
+ * By default the pre-selected choice is the page macro node itself (`macros:Page`), matching the historic
219
+ * behavior. When `defaultTarget` is `'items'`, the default is the `macros:items` slot under the page macro,
220
+ * or the first tab's content (`IconTabFilter`) directly inside that slot when one exists.
221
+ *
222
+ * The lookup is anchored to the `macros:items` slot under the page macro, so this only applies to a Custom Page
223
+ * building block layout. For views without a `macros:Page` (e.g. object-page sections or plain FPM views) no key
224
+ * matches, so it falls through to the historic fallback and the default is unchanged.
225
+ *
226
+ * @param inputChoices - map of available aggregation XPath choices
227
+ * @param pageMacroDefinition - the page macro node name (e.g. `macros:Page`)
228
+ * @param defaultTarget - preferred default target: `'page'` (default) or `'items'`
229
+ * @returns the choice key to mark as checked, or undefined when none applies
230
+ */
231
+ function resolveDefaultKey(inputChoices, pageMacroDefinition, defaultTarget) {
232
+ const keys = Object.keys(inputChoices);
233
+ if (defaultTarget === 'items' && pageMacroDefinition) {
234
+ // Use local-name matching throughout to handle non-default namespace prefixes (e.g. xmlns:m="sap.m").
235
+ const localName = (path) => path.split('/').pop()?.split(':').pop();
236
+ // Find the items slot as the direct child of the page macro node with local-name 'items'.
237
+ const pageKey = keys.find((k) => k.endsWith(`/${pageMacroDefinition}`));
238
+ const itemsKey = pageKey
239
+ ? keys.find((k) => k.startsWith(`${pageKey}/`) &&
240
+ k.slice(pageKey.length + 1).split('/').length === 1 &&
241
+ localName(k) === 'items')
242
+ : undefined;
243
+ if (itemsKey) {
244
+ // Prefer the first tab's content (IconTabFilter) directly under the items slot.
245
+ // Depth check: exactly 3 segments after itemsKey (e.g. IconTabBar/items/IconTabFilter).
246
+ const tabKey = keys.find((k) => k.startsWith(`${itemsKey}/`) &&
247
+ localName(k) === 'IconTabFilter' &&
248
+ k.slice(itemsKey.length + 1).split('/').length === 3);
249
+ return tabKey ?? itemsKey;
250
+ }
251
+ }
252
+ // Default / fallback: the page macro node itself (undefined when no page macro node exists).
253
+ return keys.find((k) => k.endsWith(`/${pageMacroDefinition}`));
254
+ }
215
255
  /**
216
256
  * Return a Prompt for choosing the aggregation path.
217
257
  *
218
258
  * @param context - prompt context including data about project
219
259
  * @param properties - object with additional properties of question
260
+ * @param options - additional options
261
+ * @param options.defaultTarget - preferred aggregation to pre-select by default: `'page'` (default) or `'items'`
220
262
  * @returns prompt for choosing aggregation path of selected xml file.
221
263
  */
222
- export function getAggregationPathPrompt(context, properties = {}) {
264
+ export function getAggregationPathPrompt(context, properties = {}, options = {}) {
223
265
  const { fs, project, appPath } = context;
224
266
  const { guiOptions } = properties;
267
+ const { defaultTarget = 'page' } = options;
225
268
  return {
226
269
  ...properties,
227
270
  type: 'list',
@@ -231,7 +274,7 @@ export function getAggregationPathPrompt(context, properties = {}) {
231
274
  const { viewOrFragmentPath } = answers;
232
275
  if (viewOrFragmentPath) {
233
276
  const { inputChoices, pageMacroDefinition } = getXPathStringsForXmlFile(join(appPath, viewOrFragmentPath), fs);
234
- const key = Object.keys(inputChoices).find((k) => k.endsWith(`/${pageMacroDefinition}`));
277
+ const key = resolveDefaultKey(inputChoices, pageMacroDefinition, defaultTarget);
235
278
  const choices = transformChoices(inputChoices, false, key);
236
279
  if (!choices.length) {
237
280
  throw new Error('Failed while fetching the aggregation path.');
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": "1.3.11",
4
+ "version": "1.3.13",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -31,7 +31,7 @@
31
31
  "semver": "7.8.5",
32
32
  "xml-formatter": "3.7.0",
33
33
  "xpath": "0.0.34",
34
- "@sap-ux/fiori-annotation-api": "1.0.22",
34
+ "@sap-ux/fiori-annotation-api": "1.0.23",
35
35
  "@sap-ux/i18n": "1.0.2",
36
36
  "@sap-ux/project-access": "2.1.10",
37
37
  "@sap-ux/logger": "1.0.3"