@sap-ux/preview-middleware 0.13.36 → 0.13.38

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
  *
@@ -1,13 +1,12 @@
1
1
  'use strict';
2
2
  sap.ui.define([
3
3
  'sap/base/Log',
4
- 'sap/ui/core/ElementRegistry',
5
4
  '../cpe/init',
6
5
  './init-dialogs',
7
6
  'open/ux/preview/client/thirdparty/@sap-ux-private/control-property-editor-common',
8
7
  'sap/ui/VersionInfo',
9
8
  './ui5-version-utils'
10
- ], function (log, UI5ElementRegistry, __init, ___init_dialogs, ___sap_ux_private_control_property_editor_common, VersionInfo, ___ui5_version_utils) {
9
+ ], function (log, __init, ___init_dialogs, ___sap_ux_private_control_property_editor_common, VersionInfo, ___ui5_version_utils) {
11
10
  'use strict';
12
11
  function _interopRequireDefault(obj) {
13
12
  return obj && obj.__esModule && typeof obj.default !== 'undefined' ? obj.default : obj;
@@ -52,7 +51,7 @@ sap.ui.define([
52
51
  }
53
52
  }
54
53
  });
55
- const syncViewsIds = getAllSyncViewsIds();
54
+ const syncViewsIds = await getAllSyncViewsIds(minor);
56
55
  initDialogs(rta, syncViewsIds);
57
56
  if (minor > 77) {
58
57
  const ExtensionPointService = (await __ui5_require_async('open/ux/preview/client/adp/extension-point')).default;
@@ -76,16 +75,34 @@ sap.ui.define([
76
75
  }
77
76
  log.debug('ADP init executed.');
78
77
  };
79
- function getAllSyncViewsIds() {
80
- const elements = UI5ElementRegistry.all();
78
+ async function getAllSyncViewsIds(minor) {
81
79
  const syncViewIds = [];
82
- Object.entries(elements).forEach(_ref => {
83
- let [key, ui5Element] = _ref;
84
- if (ui5Element?.getMetadata()?.getName()?.includes('XMLView') && ui5Element?.oAsyncState === undefined) {
85
- syncViewIds.push(key);
80
+ try {
81
+ if (minor < 120) {
82
+ const Element = (await __ui5_require_async('sap/ui/core/Element')).default;
83
+ const elements = Element.registry.filter(() => true);
84
+ elements.forEach(ui5Element => {
85
+ if (isSyncView(ui5Element)) {
86
+ syncViewIds.push(ui5Element.getId());
87
+ }
88
+ });
89
+ } else {
90
+ const ElementRegistry = (await __ui5_require_async('sap/ui/core/ElementRegistry')).default;
91
+ const elements = ElementRegistry.all();
92
+ Object.entries(elements).forEach(_ref => {
93
+ let [key, ui5Element] = _ref;
94
+ if (isSyncView(ui5Element)) {
95
+ syncViewIds.push(key);
96
+ }
97
+ });
86
98
  }
87
- });
99
+ } catch (error) {
100
+ log.error('Could not get application sync views', error);
101
+ }
88
102
  return syncViewIds;
89
103
  }
104
+ const isSyncView = element => {
105
+ return element?.getMetadata()?.getName()?.includes('XMLView') && element?.oAsyncState === undefined;
106
+ };
90
107
  return __exports;
91
108
  });
@@ -1,7 +1,5 @@
1
1
  import log from 'sap/base/Log';
2
2
  import type RuntimeAuthoring from 'sap/ui/rta/RuntimeAuthoring';
3
- import UI5ElementRegistry from 'sap/ui/core/ElementRegistry';
4
-
5
3
  import init from '../cpe/init';
6
4
  import { initDialogs } from './init-dialogs';
7
5
  import {
@@ -46,7 +44,7 @@ export default async function (rta: RuntimeAuthoring) {
46
44
  }
47
45
  );
48
46
 
49
- const syncViewsIds = getAllSyncViewsIds();
47
+ const syncViewsIds = await getAllSyncViewsIds(minor);
50
48
  initDialogs(rta, syncViewsIds);
51
49
 
52
50
  if (minor > 77) {
@@ -77,19 +75,45 @@ export default async function (rta: RuntimeAuthoring) {
77
75
  }
78
76
 
79
77
  /**
80
- *
81
78
  * Get Ids for all sync views
79
+ *
80
+ * @param minor UI5 Version
82
81
  *
83
82
  * @returns array of Ids for application sync views
84
83
  */
85
- function getAllSyncViewsIds(): string[] {
86
- const elements = UI5ElementRegistry.all() as Record<string, UI5Element>;
84
+ async function getAllSyncViewsIds(minor: number): Promise<string[]> {
87
85
  const syncViewIds: string[] = [];
88
- Object.entries(elements).forEach(([key, ui5Element]) => {
89
- if (ui5Element?.getMetadata()?.getName()?.includes('XMLView') && ui5Element?.oAsyncState === undefined) {
90
- syncViewIds.push(key);
86
+ try {
87
+ if (minor < 120) {
88
+ const Element = (await import('sap/ui/core/Element')).default;
89
+ const elements = Element.registry.filter(() => true) as UI5Element[];
90
+ elements.forEach((ui5Element) => {
91
+ if (isSyncView(ui5Element)) {
92
+ syncViewIds.push(ui5Element.getId());
93
+ }
94
+ });
95
+ } else {
96
+ const ElementRegistry = (await import('sap/ui/core/ElementRegistry')).default;
97
+ const elements = ElementRegistry.all() as Record<string, UI5Element>;
98
+ Object.entries(elements).forEach(([key, ui5Element]) => {
99
+ if (isSyncView(ui5Element)) {
100
+ syncViewIds.push(key);
101
+ }
102
+ });
91
103
  }
92
- });
104
+ } catch (error) {
105
+ log.error('Could not get application sync views', error);
106
+ }
93
107
 
94
108
  return syncViewIds;
95
109
  }
110
+
111
+ /**
112
+ * Check if element is sync view
113
+ *
114
+ * @param element UI5Element
115
+ * @returns boolean if element is sync view or not
116
+ */
117
+ const isSyncView = (element: UI5Element): boolean => {
118
+ return element?.getMetadata()?.getName()?.includes('XMLView') && element?.oAsyncState === undefined;
119
+ };
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.38",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -26,10 +26,10 @@
26
26
  "mem-fs": "2.1.0",
27
27
  "mem-fs-editor": "9.4.0",
28
28
  "@sap-ux/logger": "0.5.1",
29
- "@sap-ux/btp-utils": "0.14.4",
30
29
  "@sap-ux/adp-tooling": "0.10.5",
31
30
  "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.4.20",
32
- "@sap-ux/project-access": "1.20.0"
31
+ "@sap-ux/project-access": "1.20.0",
32
+ "@sap-ux/btp-utils": "0.14.4"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/ejs": "3.1.2",
@@ -45,7 +45,7 @@
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
+ "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.9.11",
49
49
  "@sap-ux/axios-extension": "1.12.3",
50
50
  "@sap-ux/store": "0.5.0",
51
51
  "@sap-ux/i18n": "0.0.6"