@sap-ux/preview-middleware 0.13.36 → 0.13.37

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.
@@ -27,6 +27,7 @@ sap.ui.define(["sap/ui/core/Fragment", "sap/ui/fl/Utils", "./controllers/AddFrag
27
27
  id: 'ADD_FRAGMENT',
28
28
  text: 'Add: Fragment',
29
29
  handler: async overlays => await handler(overlays[0], rta, DialogNames.ADD_FRAGMENT),
30
+ enabled: isFragmentCommandEnabled,
30
31
  icon: 'sap-icon://attachment-html'
31
32
  });
32
33
  contextMenu.addMenuItem({
@@ -44,13 +45,26 @@ sap.ui.define(["sap/ui/core/Fragment", "sap/ui/fl/Utils", "./controllers/AddFrag
44
45
  * @param overlays Control overlays
45
46
  * @param syncViewsIds Runtime Authoring
46
47
  *
47
- * @returns boolean
48
+ * @returns boolean
48
49
  */
49
50
  const isControllerExtensionEnabled = (overlays, syncViewsIds) => {
50
51
  const clickedControlId = FlUtils.getViewForControl(overlays[0].getElement()).getId();
51
52
  return overlays.length <= 1 && !syncViewsIds.includes(clickedControlId);
52
53
  };
53
54
 
55
+ /**
56
+ * Determines whether the fragment command should be enabled based on the provided overlays.
57
+ *
58
+ * @param {ElementOverlay[]} overlays - An array of ElementOverlay objects representing the UI overlays.
59
+ * @returns {boolean} True if the fragment command is enabled, false otherwise.
60
+ */
61
+ const isFragmentCommandEnabled = overlays => {
62
+ if (overlays.length === 0) return false;
63
+ const control = overlays[0].getElement();
64
+ const hasStableId = FlUtils.checkControlId(control);
65
+ return hasStableId && overlays.length <= 1;
66
+ };
67
+
54
68
  /**
55
69
  * Handler for new context menu entry
56
70
  *
@@ -86,6 +100,7 @@ sap.ui.define(["sap/ui/core/Fragment", "sap/ui/fl/Utils", "./controllers/AddFrag
86
100
  __exports.DialogNames = DialogNames;
87
101
  __exports.initDialogs = initDialogs;
88
102
  __exports.isControllerExtensionEnabled = isControllerExtensionEnabled;
103
+ __exports.isFragmentCommandEnabled = isFragmentCommandEnabled;
89
104
  __exports.handler = handler;
90
105
  return __exports;
91
106
  });
@@ -11,7 +11,8 @@ import type RuntimeAuthoring from 'sap/ui/rta/RuntimeAuthoring';
11
11
  /** sap.ui.fl */
12
12
  import FlUtils from 'sap/ui/fl/Utils';
13
13
 
14
- import ElementOverlay from 'sap/ui/dt/ElementOverlay';
14
+ /** sap.ui.dt */
15
+ import type ElementOverlay from 'sap/ui/dt/ElementOverlay';
15
16
 
16
17
  import AddFragment from './controllers/AddFragment.controller';
17
18
  import ControllerExtension from './controllers/ControllerExtension.controller';
@@ -39,6 +40,7 @@ export const initDialogs = (rta: RuntimeAuthoring, syncViewsIds: string[]): void
39
40
  id: 'ADD_FRAGMENT',
40
41
  text: 'Add: Fragment',
41
42
  handler: async (overlays: UI5Element[]) => await handler(overlays[0], rta, DialogNames.ADD_FRAGMENT),
43
+ enabled: isFragmentCommandEnabled,
42
44
  icon: 'sap-icon://attachment-html'
43
45
  });
44
46
 
@@ -57,7 +59,7 @@ export const initDialogs = (rta: RuntimeAuthoring, syncViewsIds: string[]): void
57
59
  * @param overlays Control overlays
58
60
  * @param syncViewsIds Runtime Authoring
59
61
  *
60
- * @returns boolean
62
+ * @returns boolean
61
63
  */
62
64
  export const isControllerExtensionEnabled = (overlays: ElementOverlay[], syncViewsIds: string[]): boolean => {
63
65
  const clickedControlId = FlUtils.getViewForControl(overlays[0].getElement()).getId();
@@ -65,6 +67,21 @@ export const isControllerExtensionEnabled = (overlays: ElementOverlay[], syncVie
65
67
  return overlays.length <= 1 && !syncViewsIds.includes(clickedControlId);
66
68
  };
67
69
 
70
+ /**
71
+ * Determines whether the fragment command should be enabled based on the provided overlays.
72
+ *
73
+ * @param {ElementOverlay[]} overlays - An array of ElementOverlay objects representing the UI overlays.
74
+ * @returns {boolean} True if the fragment command is enabled, false otherwise.
75
+ */
76
+ export const isFragmentCommandEnabled = (overlays: ElementOverlay[]): boolean => {
77
+ if (overlays.length === 0) return false;
78
+
79
+ const control = overlays[0].getElement();
80
+ const hasStableId = FlUtils.checkControlId(control);
81
+
82
+ return hasStableId && overlays.length <= 1;
83
+ };
84
+
68
85
  /**
69
86
  * Handler for new context menu entry
70
87
  *
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.13.36",
12
+ "version": "0.13.37",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -25,9 +25,9 @@
25
25
  "ejs": "3.1.10",
26
26
  "mem-fs": "2.1.0",
27
27
  "mem-fs-editor": "9.4.0",
28
- "@sap-ux/logger": "0.5.1",
29
28
  "@sap-ux/btp-utils": "0.14.4",
30
29
  "@sap-ux/adp-tooling": "0.10.5",
30
+ "@sap-ux/logger": "0.5.1",
31
31
  "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.4.20",
32
32
  "@sap-ux/project-access": "1.20.0"
33
33
  },
@@ -45,10 +45,10 @@
45
45
  "supertest": "6.3.3",
46
46
  "@sap-ux-private/playwright": "0.0.3",
47
47
  "dotenv": "16.3.1",
48
- "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.9.9",
48
+ "@sap-ux/i18n": "0.0.6",
49
+ "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.9.10",
49
50
  "@sap-ux/axios-extension": "1.12.3",
50
- "@sap-ux/store": "0.5.0",
51
- "@sap-ux/i18n": "0.0.6"
51
+ "@sap-ux/store": "0.5.0"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "express": "4"