@sap-ux/preview-middleware 0.23.54 → 0.23.55

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.
@@ -68,6 +68,38 @@ sap.ui.define(["sap/ui/core/Component", "sap/ui/core/Element"], function (Compon
68
68
  }
69
69
  return hasParent(parent, parentIdToFind);
70
70
  }
71
+
72
+ /**
73
+ * Utility function to safely call getParent on UI5 elements
74
+ * @param element UI5 element
75
+ * @returns parent element or null
76
+ */
77
+ function getElementParent(element) {
78
+ if (typeof element.getParent === 'function') {
79
+ return element.getParent();
80
+ }
81
+ return null;
82
+ }
83
+
84
+ /**
85
+ * Finds the view that contains the given control.
86
+ *
87
+ * @param control - Control instance
88
+ * @returns View instance if found, undefined otherwise
89
+ */
90
+ function findViewByControl(control) {
91
+ if (!control) {
92
+ return undefined;
93
+ }
94
+ if (isA('sap.ui.core.mvc.View', control)) {
95
+ return control;
96
+ }
97
+ const parent = getElementParent(control);
98
+ if (!parent) {
99
+ return undefined;
100
+ }
101
+ return findViewByControl(parent);
102
+ }
71
103
  function findNestedElements(ownerElement, candidates) {
72
104
  const ownerId = ownerElement.getId();
73
105
  return candidates.filter(item => hasParent(item, ownerId));
@@ -80,6 +112,7 @@ sap.ui.define(["sap/ui/core/Component", "sap/ui/core/Element"], function (Compon
80
112
  __exports.isManagedObject = isManagedObject;
81
113
  __exports.isA = isA;
82
114
  __exports.hasParent = hasParent;
115
+ __exports.findViewByControl = findViewByControl;
83
116
  __exports.findNestedElements = findNestedElements;
84
117
  return __exports;
85
118
  });
@@ -2,6 +2,7 @@ import Component from 'sap/ui/core/Component';
2
2
  import type { ID } from 'sap/ui/core/library';
3
3
  import type ManagedObject from 'sap/ui/base/ManagedObject';
4
4
  import Element from 'sap/ui/core/Element';
5
+ import View from 'sap/ui/core/mvc/View';
5
6
 
6
7
  /**
7
8
  * Gets Component by id.
@@ -71,6 +72,38 @@ export function hasParent(component: ManagedObject, parentIdToFind: string): boo
71
72
  return hasParent(parent, parentIdToFind);
72
73
  }
73
74
 
75
+ /**
76
+ * Utility function to safely call getParent on UI5 elements
77
+ * @param element UI5 element
78
+ * @returns parent element or null
79
+ */
80
+ function getElementParent(element: Element | ManagedObject): ManagedObject | null {
81
+ if (typeof element.getParent === 'function') {
82
+ return element.getParent();
83
+ }
84
+ return null;
85
+ }
86
+
87
+ /**
88
+ * Finds the view that contains the given control.
89
+ *
90
+ * @param control - Control instance
91
+ * @returns View instance if found, undefined otherwise
92
+ */
93
+ export function findViewByControl(control: Element | ManagedObject): View | undefined {
94
+ if (!control) {
95
+ return undefined;
96
+ }
97
+ if (isA<View>('sap.ui.core.mvc.View', control)) {
98
+ return control;
99
+ }
100
+ const parent = getElementParent(control);
101
+ if (!parent) {
102
+ return undefined;
103
+ }
104
+ return findViewByControl(parent);
105
+ }
106
+
74
107
  export function findNestedElements(
75
108
  ownerElement: Element,
76
109
  candidates: Element[]
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.23.54",
12
+ "version": "0.23.55",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -27,7 +27,7 @@
27
27
  "mem-fs-editor": "9.4.0",
28
28
  "qrcode": "1.5.4",
29
29
  "@sap/bas-sdk": "3.12.0",
30
- "@sap-ux/adp-tooling": "0.18.3",
30
+ "@sap-ux/adp-tooling": "0.18.4",
31
31
  "@sap-ux/btp-utils": "1.1.5",
32
32
  "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.7.2",
33
33
  "@sap-ux/feature-toggle": "0.3.4",
@@ -53,7 +53,7 @@
53
53
  "nock": "13.4.0",
54
54
  "npm-run-all2": "6.2.0",
55
55
  "supertest": "7.1.4",
56
- "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.17.4",
56
+ "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.18.1",
57
57
  "@sap-ux/axios-extension": "1.24.2",
58
58
  "@sap-ux/store": "1.3.3",
59
59
  "@sap-ux/ui5-info": "0.13.2"