@ui5/webcomponents-base 0.0.0-e0658a650 → 0.0.0-e55c2cec6

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.
Files changed (146) hide show
  1. package/.eslintignore +1 -0
  2. package/dist/Device.d.ts +3 -2
  3. package/dist/Device.js +4 -2
  4. package/dist/Device.js.map +1 -1
  5. package/dist/Keys.js.map +1 -1
  6. package/dist/MarkedEvents.d.ts +9 -0
  7. package/dist/MarkedEvents.js +15 -0
  8. package/dist/MarkedEvents.js.map +1 -0
  9. package/dist/MediaRange.d.ts +3 -2
  10. package/dist/MediaRange.js +50 -48
  11. package/dist/MediaRange.js.map +1 -1
  12. package/dist/UI5Element.d.ts +7 -5
  13. package/dist/UI5Element.js +47 -25
  14. package/dist/UI5Element.js.map +1 -1
  15. package/dist/UI5ElementMetadata.d.ts +14 -11
  16. package/dist/UI5ElementMetadata.js +34 -17
  17. package/dist/UI5ElementMetadata.js.map +1 -1
  18. package/dist/api.json +1 -1
  19. package/dist/asset-registries/Icons.d.ts +1 -1
  20. package/dist/asset-registries/Illustrations.d.ts +4 -3
  21. package/dist/asset-registries/Illustrations.js +3 -3
  22. package/dist/asset-registries/Illustrations.js.map +1 -1
  23. package/dist/assets/bundle.esm.ffad994a.js +56 -0
  24. package/dist/decorators/customElement.d.ts +8 -0
  25. package/dist/decorators/customElement.js +16 -0
  26. package/dist/decorators/customElement.js.map +1 -0
  27. package/dist/decorators/event.d.ts +10 -0
  28. package/dist/decorators/event.js +24 -0
  29. package/dist/decorators/event.js.map +1 -0
  30. package/dist/decorators/fastNavigation.d.ts +7 -0
  31. package/dist/decorators/fastNavigation.js +13 -0
  32. package/dist/decorators/fastNavigation.js.map +1 -0
  33. package/dist/decorators/languageAware.d.ts +7 -0
  34. package/dist/decorators/languageAware.js +13 -0
  35. package/dist/decorators/languageAware.js.map +1 -0
  36. package/dist/decorators/property.d.ts +9 -0
  37. package/dist/decorators/property.js +24 -0
  38. package/dist/decorators/property.js.map +1 -0
  39. package/dist/decorators/slot.d.ts +9 -0
  40. package/dist/decorators/slot.js +37 -0
  41. package/dist/decorators/slot.js.map +1 -0
  42. package/dist/decorators/themeAware.d.ts +7 -0
  43. package/dist/decorators/themeAware.js +13 -0
  44. package/dist/decorators/themeAware.js.map +1 -0
  45. package/dist/delegate/ItemNavigation.d.ts +9 -9
  46. package/dist/delegate/ItemNavigation.js +2 -2
  47. package/dist/delegate/ItemNavigation.js.map +1 -1
  48. package/dist/delegate/ScrollEnablement.d.ts +6 -1
  49. package/dist/delegate/ScrollEnablement.js.map +1 -1
  50. package/dist/generated/VersionInfo.js +3 -3
  51. package/dist/locale/normalizeLocale.js +1 -1
  52. package/dist/sap/base/Log.js +28 -29
  53. package/dist/sap/base/assert.js +5 -6
  54. package/dist/sap/base/security/URLListValidator.js +13 -2
  55. package/dist/theming/getEffectiveLinksHrefs.js +2 -1
  56. package/dist/theming/getEffectiveLinksHrefs.js.map +1 -1
  57. package/dist/theming/getStylesString.d.ts +2 -2
  58. package/dist/theming/getStylesString.js +2 -1
  59. package/dist/theming/getStylesString.js.map +1 -1
  60. package/dist/types/AnimationMode.d.ts +1 -1
  61. package/dist/types/AnimationMode.js +1 -1
  62. package/dist/types/CSSColor.d.ts +2 -2
  63. package/dist/types/CSSColor.js +2 -2
  64. package/dist/types/CalendarType.d.ts +1 -1
  65. package/dist/types/CalendarType.js +1 -1
  66. package/dist/types/DOMReference.d.ts +2 -2
  67. package/dist/types/DOMReference.js +2 -2
  68. package/dist/types/DataType.d.ts +1 -1
  69. package/dist/types/DataType.js +1 -1
  70. package/dist/types/Float.d.ts +2 -2
  71. package/dist/types/Float.js +2 -2
  72. package/dist/types/Integer.d.ts +2 -2
  73. package/dist/types/Integer.js +2 -2
  74. package/dist/types/InvisibleMessageMode.d.ts +1 -1
  75. package/dist/types/InvisibleMessageMode.js +1 -1
  76. package/dist/types/ItemNavigationBehavior.d.ts +1 -1
  77. package/dist/types/ItemNavigationBehavior.js +1 -1
  78. package/dist/types/NavigationMode.d.ts +1 -1
  79. package/dist/types/NavigationMode.js +1 -1
  80. package/dist/types/ValueState.d.ts +1 -1
  81. package/dist/types/ValueState.js +1 -1
  82. package/dist/types.d.ts +9 -4
  83. package/dist/util/Caret.js.map +1 -1
  84. package/dist/util/ColorConversion.d.ts +2 -5
  85. package/dist/util/ColorConversion.js +2 -2
  86. package/dist/util/ColorConversion.js.map +1 -1
  87. package/dist/util/FocusableElements.d.ts +3 -2
  88. package/dist/util/FocusableElements.js.map +1 -1
  89. package/dist/util/PopupUtils.js +5 -5
  90. package/dist/util/PopupUtils.js.map +1 -1
  91. package/dist/util/TabbableElements.d.ts +15 -1
  92. package/dist/util/TabbableElements.js +14 -0
  93. package/dist/util/TabbableElements.js.map +1 -1
  94. package/dist/util/getClassCopy.d.ts +5 -3
  95. package/dist/util/isElementTabbable.d.ts +8 -1
  96. package/dist/util/isElementTabbable.js +8 -0
  97. package/dist/util/isElementTabbable.js.map +1 -1
  98. package/dist/util/willShowContent.d.ts +2 -0
  99. package/dist/util/willShowContent.js +7 -0
  100. package/dist/util/willShowContent.js.map +1 -0
  101. package/package-scripts.js +1 -1
  102. package/package.json +5 -6
  103. package/src/Device.ts +14 -11
  104. package/src/Keys.ts +60 -60
  105. package/src/MarkedEvents.ts +20 -0
  106. package/src/MediaRange.ts +52 -51
  107. package/src/UI5Element.ts +57 -27
  108. package/src/UI5ElementMetadata.ts +49 -24
  109. package/src/asset-registries/Icons.ts +1 -0
  110. package/src/asset-registries/Illustrations.ts +7 -5
  111. package/src/decorators/customElement.ts +17 -0
  112. package/src/decorators/event.ts +28 -0
  113. package/src/decorators/fastNavigation.ts +14 -0
  114. package/src/decorators/languageAware.ts +14 -0
  115. package/src/decorators/property.ts +30 -0
  116. package/src/decorators/slot.ts +49 -0
  117. package/src/decorators/themeAware.ts +14 -0
  118. package/src/delegate/ItemNavigation.ts +9 -9
  119. package/src/delegate/ScrollEnablement.ts +9 -3
  120. package/src/locale/normalizeLocale.ts +1 -1
  121. package/src/theming/getEffectiveLinksHrefs.ts +6 -4
  122. package/src/theming/getStylesString.ts +5 -3
  123. package/src/types/AnimationMode.ts +1 -1
  124. package/src/types/CSSColor.ts +2 -2
  125. package/src/types/CalendarType.ts +1 -1
  126. package/src/types/DOMReference.ts +2 -2
  127. package/src/types/DataType.ts +1 -1
  128. package/src/types/Float.ts +2 -2
  129. package/src/types/Integer.ts +2 -2
  130. package/src/types/InvisibleMessageMode.ts +1 -1
  131. package/src/types/ItemNavigationBehavior.ts +1 -1
  132. package/src/types/NavigationMode.ts +1 -1
  133. package/src/types/ValueState.ts +1 -1
  134. package/src/types.ts +13 -5
  135. package/src/util/Caret.ts +1 -1
  136. package/src/util/ColorConversion.ts +17 -12
  137. package/src/util/FocusableElements.ts +5 -3
  138. package/src/util/PopupUtils.ts +4 -4
  139. package/src/util/TabbableElements.ts +17 -3
  140. package/src/util/isElementTabbable.ts +10 -1
  141. package/src/util/willShowContent.ts +7 -0
  142. package/dist/assets/bundle.esm.72c1d211.js +0 -56
  143. package/dist/util/isDefaultSlotProvided.d.ts +0 -2
  144. package/dist/util/isDefaultSlotProvided.js +0 -10
  145. package/dist/util/isDefaultSlotProvided.js.map +0 -1
  146. package/src/util/isDefaultSlotProvided.ts +0 -11
@@ -0,0 +1,49 @@
1
+ import type UI5Element from "../UI5Element.js";
2
+ import { Slot } from "../UI5ElementMetadata.js";
3
+
4
+ /**
5
+ * Returns a slot decorator.
6
+ *
7
+ * @param { Slot } slotData
8
+ * @returns { PropertyDecorator }
9
+ */
10
+ const slot = (slotData?: Slot): PropertyDecorator => {
11
+ return (target: any, slotKey: string | symbol) => {
12
+ const ctor = target.constructor as typeof UI5Element;
13
+
14
+ if (!Object.prototype.hasOwnProperty.call(ctor, "decoratorMetadata")) {
15
+ ctor.decoratorMetadata = {};
16
+ }
17
+
18
+ const decoratorMetadata = ctor.decoratorMetadata;
19
+ if (!decoratorMetadata.slots) {
20
+ decoratorMetadata.slots = {};
21
+ }
22
+
23
+ const slotMetadata = decoratorMetadata.slots;
24
+
25
+ if (slotData?.default && slotMetadata.default) {
26
+ throw new Error("Only one slot can be the default slot.");
27
+ }
28
+
29
+ const key = slotData?.default ? "default" : slotKey as string;
30
+ slotData = slotData || { type: HTMLElement };
31
+
32
+ if (!slotData.type) {
33
+ slotData.type = HTMLElement;
34
+ }
35
+
36
+ if (!slotMetadata[key]) {
37
+ slotMetadata[key] = slotData;
38
+ }
39
+
40
+ if (slotData.default) {
41
+ delete slotMetadata.default.default;
42
+ slotMetadata.default.propertyName = slotKey as string;
43
+ }
44
+
45
+ ctor.decoratorMetadata.managedSlots = true;
46
+ };
47
+ };
48
+
49
+ export default slot;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Class decorator, that sets the themeAware metadata.
3
+ * @param { any } target the decorated class
4
+ * @returns { void }
5
+ */
6
+ const themeAware = (target: any): void => {
7
+ if (!Object.prototype.hasOwnProperty.call(target, "decoratorMetadata")) {
8
+ target.decoratorMetadata = {};
9
+ }
10
+
11
+ target.decoratorMetadata.themeAware = true;
12
+ };
13
+
14
+ export default themeAware;
@@ -16,9 +16,9 @@ import ItemNavigationBehavior from "../types/ItemNavigationBehavior.js";
16
16
  import type UI5Element from "../UI5Element.js";
17
17
  import { instanceOfUI5Element } from "../UI5Element.js";
18
18
 
19
- interface Tabbable {
20
- id?: string,
21
- _tabIndex?: string,
19
+ interface ITabbable {
20
+ id: string,
21
+ _tabIndex: string,
22
22
  }
23
23
 
24
24
  type ItemNavigationOptions = {
@@ -27,7 +27,7 @@ type ItemNavigationOptions = {
27
27
  rowSize?: number
28
28
  skipItemsSize?: number,
29
29
  behavior?: ItemNavigationBehavior,
30
- getItemsCallback: () => Array<Tabbable>,
30
+ getItemsCallback: () => Array<ITabbable>,
31
31
  affectedPropertiesNames?: Array<string>,
32
32
  };
33
33
 
@@ -67,7 +67,7 @@ type ItemNavigationOptions = {
67
67
  class ItemNavigation {
68
68
  rootWebComponent: UI5Element;
69
69
 
70
- _getItems: () => Array<Tabbable>;
70
+ _getItems: () => Array<ITabbable>;
71
71
 
72
72
  _currentIndex: number;
73
73
 
@@ -126,7 +126,7 @@ class ItemNavigation {
126
126
  * @public
127
127
  * @param current the new selected item
128
128
  */
129
- setCurrentItem(current: Tabbable) {
129
+ setCurrentItem(current: ITabbable) {
130
130
  const currentItemIndex = this._getItems().indexOf(current);
131
131
 
132
132
  if (currentItemIndex === -1) {
@@ -338,7 +338,7 @@ class ItemNavigation {
338
338
  _focusCurrentItem() {
339
339
  const currentItem = this._getCurrentItem();
340
340
  if (currentItem) {
341
- currentItem.focus();
341
+ currentItem.focus({ focusVisible: true } as FocusOptions);
342
342
  }
343
343
  }
344
344
 
@@ -353,7 +353,7 @@ class ItemNavigation {
353
353
  const items = this._getItems();
354
354
 
355
355
  if (!items.length) {
356
- return null;
356
+ return;
357
357
  }
358
358
 
359
359
  // normalize the index
@@ -389,5 +389,5 @@ class ItemNavigation {
389
389
  export default ItemNavigation;
390
390
 
391
391
  export {
392
- Tabbable,
392
+ ITabbable,
393
393
  };
@@ -6,7 +6,13 @@ import type UI5Element from "../UI5Element.js";
6
6
  const scrollEventName = "scroll";
7
7
  const touchEndEventName = supportsTouch() ? "touchend" : "mouseup";
8
8
 
9
- class ScrollEnablement<EventListenerParam, EventListenerReturn> extends EventProvider<EventListenerParam, EventListenerReturn> {
9
+ type EventListenerParam = {
10
+ isLeft: boolean;
11
+ isRight: boolean
12
+ }
13
+ type EventListenerReturn = void;
14
+
15
+ class ScrollEnablement extends EventProvider<EventListenerParam, EventListenerReturn> {
10
16
  containerComponent: UI5Element;
11
17
  mouseMove: (event: MouseEvent | TouchEvent) => void;
12
18
  mouseUp: (event: MouseEvent | TouchEvent) => void;
@@ -163,7 +169,7 @@ class ScrollEnablement<EventListenerParam, EventListenerReturn> extends EventPro
163
169
  this.fireEvent(scrollEventName, {
164
170
  isLeft: dragX! > this._prevDragX!,
165
171
  isRight: dragX! < this._prevDragX!,
166
- } as unknown as EventListenerParam);
172
+ });
167
173
 
168
174
  this.cachedValue.dragX = this._prevDragX!;
169
175
  this.cachedValue.dragY = this._prevDragY!;
@@ -200,7 +206,7 @@ class ScrollEnablement<EventListenerParam, EventListenerReturn> extends EventPro
200
206
  this.fireEvent(touchEndEventName, {
201
207
  isLeft: _dragX < this._prevDragX!,
202
208
  isRight: _dragX > this._prevDragX!,
203
- } as unknown as EventListenerParam);
209
+ });
204
210
 
205
211
  this._prevDragX = dragX;
206
212
  this._prevDragY = dragY;
@@ -7,7 +7,7 @@ const SAPSupportabilityLocales = /(?:^|-)(saptrc|sappsd)(?:-|$)/i;
7
7
  const M_ISO639_NEW_TO_OLD = {
8
8
  "he": "iw",
9
9
  "yi": "ji",
10
- "id": "in",
10
+ "nb": "no",
11
11
  "sr": "sh",
12
12
  };
13
13
 
@@ -2,23 +2,25 @@ import { getUrl } from "../CSP.js";
2
2
  import { getFeature } from "../FeaturesRegistry.js";
3
3
  import type UI5Element from "../UI5Element.js";
4
4
  import type OpenUI5Enablement from "../features/OpenUI5Enablement.js";
5
- import { StyleData, StyleDataCSP } from "../types.js";
5
+ import { ComponentStylesData, StyleDataCSP } from "../types.js";
6
+
7
+ const MAX_DEPTH_INHERITED_CLASSES = 10; // TypeScript complains about Infinity and big numbers
6
8
 
7
9
  const getEffectiveLinksHrefs = (ElementClass: typeof UI5Element, forStaticArea = false) => {
8
- const stylesData: StyleData | Array<StyleData> = ElementClass[forStaticArea ? "staticAreaStyles" : "styles"];
10
+ const stylesData: ComponentStylesData = ElementClass[forStaticArea ? "staticAreaStyles" : "styles"];
9
11
 
10
12
  if (!stylesData) {
11
13
  return;
12
14
  }
13
15
 
14
- const stylesDataArray: Array<StyleData> = Array.isArray(stylesData) ? stylesData : [stylesData];
16
+ const stylesDataArray: ComponentStylesData = Array.isArray(stylesData) ? stylesData : [stylesData];
15
17
 
16
18
  const openUI5Enablement = getFeature<typeof OpenUI5Enablement>("OpenUI5Enablement");
17
19
  if (openUI5Enablement) {
18
20
  stylesDataArray.push(openUI5Enablement.getBusyIndicatorStyles());
19
21
  }
20
22
 
21
- return stylesDataArray.flat().filter(data => !!data).map(data => getUrl((data as StyleDataCSP).packageName, (data as StyleDataCSP).fileName));
23
+ return stylesDataArray.flat(MAX_DEPTH_INHERITED_CLASSES).filter(data => !!data).map(data => getUrl((data as StyleDataCSP).packageName, (data as StyleDataCSP).fileName));
22
24
  };
23
25
 
24
26
  export default getEffectiveLinksHrefs;
@@ -1,8 +1,10 @@
1
- import { StyleData } from "../types.js";
1
+ import { ComponentStylesData, StyleData } from "../types.js";
2
2
 
3
- const getStylesString = (styles: Array<StyleData> | StyleData) => {
3
+ const MAX_DEPTH_INHERITED_CLASSES = 10; // TypeScript complains about Infinity and big numbers
4
+
5
+ const getStylesString = (styles: ComponentStylesData) => {
4
6
  if (Array.isArray(styles)) {
5
- return styles.filter(style => !!style).flat().map((style: StyleData) => {
7
+ return (styles.filter(style => !!style).flat(MAX_DEPTH_INHERITED_CLASSES) as Array<StyleData>).map((style: StyleData) => {
6
8
  return typeof style === "string" ? style : style.content;
7
9
  }).join(" ");
8
10
  }
@@ -5,7 +5,7 @@
5
5
  * @enum {string}
6
6
  * @public
7
7
  * @author SAP SE
8
- * @alias sap.ui.webcomponents.base.types.AnimationMode
8
+ * @alias sap.ui.webc.base.types.AnimationMode
9
9
  */
10
10
  enum AnimationMode {
11
11
  /**
@@ -4,10 +4,10 @@ import DataType from "./DataType.js";
4
4
  * @class
5
5
  * CSSColor data type.
6
6
  *
7
- * @extends sap.ui.webcomponents.base.types.DataType
7
+ * @extends sap.ui.webc.base.types.DataType
8
8
  * @constructor
9
9
  * @author SAP SE
10
- * @alias sap.ui.webcomponents.base.types.CSSColor
10
+ * @alias sap.ui.webc.base.types.CSSColor
11
11
  * @public
12
12
  * @enum {string}
13
13
  */
@@ -5,7 +5,7 @@
5
5
  * @enum {string}
6
6
  * @public
7
7
  * @author SAP SE
8
- * @alias sap.ui.webcomponents.base.types.CalendarType
8
+ * @alias sap.ui.webc.base.types.CalendarType
9
9
  */
10
10
  enum CalendarType {
11
11
  /**
@@ -6,9 +6,9 @@ import DataType from "./DataType.js";
6
6
  * <b>Note:</b> If an ID is passed, it is expected to be part of the same <code>document</code> element as the consuming component.
7
7
  *
8
8
  * @constructor
9
- * @extends sap.ui.webcomponents.base.types.DataType
9
+ * @extends sap.ui.webc.base.types.DataType
10
10
  * @author SAP SE
11
- * @alias sap.ui.webcomponents.base.types.DOMReference
11
+ * @alias sap.ui.webc.base.types.DOMReference
12
12
  * @public
13
13
  */
14
14
  class DOMReference extends DataType {
@@ -6,7 +6,7 @@ import { PropertyValue } from "../UI5ElementMetadata.js";
6
6
  * @class
7
7
  * @constructor
8
8
  * @author SAP SE
9
- * @alias sap.ui.webcomponents.base.types.DataType
9
+ * @alias sap.ui.webc.base.types.DataType
10
10
  * @public
11
11
  */
12
12
  class DataType {
@@ -6,9 +6,9 @@ import DataType from "./DataType.js";
6
6
  * Float data type.
7
7
  *
8
8
  * @constructor
9
- * @extends sap.ui.webcomponents.base.types.DataType
9
+ * @extends sap.ui.webc.base.types.DataType
10
10
  * @author SAP SE
11
- * @alias sap.ui.webcomponents.base.types.Float
11
+ * @alias sap.ui.webc.base.types.Float
12
12
  * @public
13
13
  * @enum {number}
14
14
  */
@@ -6,9 +6,9 @@ import DataType from "./DataType.js";
6
6
  * Integer data type.
7
7
  *
8
8
  * @constructor
9
- * @extends sap.ui.webcomponents.base.types.DataType
9
+ * @extends sap.ui.webc.base.types.DataType
10
10
  * @author SAP SE
11
- * @alias sap.ui.webcomponents.base.types.Integer
11
+ * @alias sap.ui.webc.base.types.Integer
12
12
  * @public
13
13
  * @enum {number}
14
14
  */
@@ -5,7 +5,7 @@
5
5
  * @enum {string}
6
6
  * @public
7
7
  * @author SAP SE
8
- * @alias sap.ui.webcomponents.base.types.InvisibleMessageMode
8
+ * @alias sap.ui.webc.base.types.InvisibleMessageMode
9
9
  */
10
10
  enum InvisibleMessageMode {
11
11
  /**
@@ -5,7 +5,7 @@
5
5
  * @enum {string}
6
6
  * @public
7
7
  * @author SAP SE
8
- * @alias sap.ui.webcomponents.base.types.ItemNavigationBehavior
8
+ * @alias sap.ui.webc.base.types.ItemNavigationBehavior
9
9
  */
10
10
  enum ItemNavigationBehavior {
11
11
  /**
@@ -5,7 +5,7 @@
5
5
  * @enum {string}
6
6
  * @public
7
7
  * @author SAP SE
8
- * @alias sap.ui.webcomponents.base.types.NavigationMode
8
+ * @alias sap.ui.webc.base.types.NavigationMode
9
9
  */
10
10
  enum NavigationMode {
11
11
  /**
@@ -5,7 +5,7 @@
5
5
  * @enum {string}
6
6
  * @public
7
7
  * @author SAP SE
8
- * @alias sap.ui.webcomponents.base.types.ValueState
8
+ * @alias sap.ui.webc.base.types.ValueState
9
9
  */
10
10
  enum ValueState {
11
11
  /**
package/src/types.ts CHANGED
@@ -1,22 +1,30 @@
1
1
  type PromiseResolve = (value: void | PromiseLike<void>) => void;
2
2
  type Timeout = ReturnType<typeof setTimeout>;
3
+ type Interval = ReturnType<typeof setInterval>;
3
4
 
4
5
  type StyleDataCSP = {
5
6
  content: string,
6
7
  packageName: string,
7
8
  fileName: string,
8
9
  };
10
+
9
11
  type StyleData = StyleDataCSP | string;
10
12
 
11
- type I18nDefaultText = {
12
- key: string,
13
- defaultText: string
14
- }
13
+ type ComponentStylesData = Array<ComponentStylesData> | Array<StyleData> | StyleData;
14
+
15
+ type ClassMapValue = Record<string, boolean>
16
+
17
+ type ClassMap = { [x: string] : ClassMapValue | ClassMap };
18
+
19
+ type PassiveEventListenerObject = EventListenerObject & { passive: boolean };
15
20
 
16
21
  export type {
17
22
  PromiseResolve,
18
23
  Timeout,
24
+ Interval,
19
25
  StyleData,
20
26
  StyleDataCSP,
21
- I18nDefaultText,
27
+ ComponentStylesData,
28
+ ClassMap,
29
+ PassiveEventListenerObject,
22
30
  };
package/src/util/Caret.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Returns the caret (cursor) position of the specified text field (field).
3
3
  * Return value range is 0-field.value.length.
4
4
  */
5
- const getCaretPosition = (field: HTMLInputElement) => {
5
+ const getCaretPosition = (field: HTMLInputElement): number | null => {
6
6
  // Initialize
7
7
  let caretPos: number | null = 0;
8
8
 
@@ -169,7 +169,7 @@ enum CSSColors {
169
169
  transparent = "00000000",
170
170
  }
171
171
 
172
- const getRGBColor = (color: string) => {
172
+ const getRGBColor = (color: string): ColorRGB => {
173
173
  if (color.startsWith("rgba")) {
174
174
  return RGBAToRGB(color);
175
175
  }
@@ -189,7 +189,7 @@ const getRGBColor = (color: string) => {
189
189
  }
190
190
 
191
191
  // Css Color
192
- if (Object.keys(CSSColors).includes(color)) {
192
+ if (color in CSSColors) {
193
193
  color = CSSColors[color as keyof typeof CSSColors];
194
194
  }
195
195
 
@@ -200,7 +200,7 @@ const getRGBColor = (color: string) => {
200
200
  * Return an object with the properties for each of the main colors(red, green, blue)
201
201
  * @param {String} color Receives a color in the following format: "rgba(0, 0, 0, 1)
202
202
  */
203
- const RGBAToRGB = (color: string) => {
203
+ const RGBAToRGB = (color: string): ColorRGB => {
204
204
  const openingBracketIndex = color.indexOf("("),
205
205
  commasIndexes = [];
206
206
 
@@ -221,7 +221,7 @@ const RGBAToRGB = (color: string) => {
221
221
  * Return an object with the properties for each of the main colors(red, green, blue)
222
222
  * @param {String} color Receives a color in the following format: "rgb(0, 0, 0)
223
223
  */
224
- const RGBStringToRGBObject = (color: string) => {
224
+ const RGBStringToRGBObject = (color: string): ColorRGB => {
225
225
  const openingBracketIndex = color.indexOf("("),
226
226
  closingBraketIndex = color.indexOf(")"),
227
227
  commasIndexes = [];
@@ -239,7 +239,7 @@ const RGBStringToRGBObject = (color: string) => {
239
239
  };
240
240
  };
241
241
 
242
- const HSLToRGB = (color: ColorHSL) => {
242
+ const HSLToRGB = (color: ColorHSL): ColorRGB => {
243
243
  // Formula taken from https://www.rapidtables.com/convert/color/hsl-to-rgb.html
244
244
  const C = (1 - Math.abs((2 * color.l) - 1)) * color.s,
245
245
  X = C * (1 - Math.abs(((color.h / 60) % 2) - 1)),
@@ -305,10 +305,10 @@ const HSLToRGB = (color: ColorHSL) => {
305
305
  r: Math.floor((tempColor.r + m) * 255),
306
306
  g: Math.floor((tempColor.g + m) * 255),
307
307
  b: Math.floor((tempColor.b + m) * 255),
308
- } as ColorRGB;
308
+ };
309
309
  };
310
310
 
311
- const HEXToRGB = (hex: string) => {
311
+ const HEXToRGB = (hex: string): ColorRGB => {
312
312
  // Please make sure you pass a valid 6 digit hex color
313
313
  // In the implementation of this method we assume that the hex argument is a 6 digit valid hex color
314
314
 
@@ -316,14 +316,14 @@ const HEXToRGB = (hex: string) => {
316
316
  r: parseInt(hex.substr(0, 2), 16),
317
317
  g: parseInt(hex.substr(2, 2), 16),
318
318
  b: parseInt(hex.substr(4, 2), 16),
319
- } as ColorRGB;
319
+ };
320
320
  };
321
321
 
322
322
  /**
323
323
  * Returns the hex value of the color as string
324
324
  * @param {Object} color Receives an object with the properties for each of the main colors(r, g, b)
325
325
  */
326
- const RGBtoHEX = (color: ColorRGB) => {
326
+ const RGBtoHEX = (color: ColorRGB): string => {
327
327
  const hexMap = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E"];
328
328
  let hexValue = "#";
329
329
 
@@ -345,7 +345,7 @@ const RGBtoHEX = (color: ColorRGB) => {
345
345
  return hexValue;
346
346
  };
347
347
 
348
- const RGBToHSL = (color: ColorRGB) => {
348
+ const RGBToHSL = (color: ColorRGB): ColorHSL => {
349
349
  const R = color.r / 255,
350
350
  G = color.g / 255,
351
351
  B = color.b / 255,
@@ -353,7 +353,7 @@ const RGBToHSL = (color: ColorRGB) => {
353
353
  min = Math.min(R, G, B),
354
354
  delta = max - min;
355
355
 
356
- let h,
356
+ let h = 0,
357
357
  s;
358
358
 
359
359
  // Hue calculation
@@ -381,7 +381,7 @@ const RGBToHSL = (color: ColorRGB) => {
381
381
  h,
382
382
  s,
383
383
  l,
384
- } as ColorHSL;
384
+ };
385
385
  };
386
386
 
387
387
  export {
@@ -392,3 +392,8 @@ export {
392
392
  RGBStringToRGBObject,
393
393
  RGBtoHEX,
394
394
  };
395
+
396
+ export type {
397
+ ColorHSL,
398
+ ColorRGB,
399
+ };
@@ -2,11 +2,13 @@ import isElementHidden from "./isElementHidden.js";
2
2
  import isElementClickable from "./isElementClickable.js";
3
3
  import { instanceOfUI5Element } from "../UI5Element.js";
4
4
 
5
+ type FocusableElementPromise = Promise<HTMLElement | null>;
6
+
5
7
  const isFocusTrap = (el: HTMLElement) => {
6
8
  return el.hasAttribute("data-ui5-focus-trap");
7
9
  };
8
10
 
9
- const getFirstFocusableElement = async (container: HTMLElement, startFromContainer: boolean): Promise<HTMLElement | null> => {
11
+ const getFirstFocusableElement = async (container: HTMLElement, startFromContainer?: boolean): FocusableElementPromise => {
10
12
  if (!container || isElementHidden(container)) {
11
13
  return null;
12
14
  }
@@ -14,7 +16,7 @@ const getFirstFocusableElement = async (container: HTMLElement, startFromContain
14
16
  return findFocusableElement(container, true, startFromContainer);
15
17
  };
16
18
 
17
- const getLastFocusableElement = async (container: HTMLElement, startFromContainer: boolean) => {
19
+ const getLastFocusableElement = async (container: HTMLElement, startFromContainer?: boolean): FocusableElementPromise => {
18
20
  if (!container || isElementHidden(container)) {
19
21
  return null;
20
22
  }
@@ -26,7 +28,7 @@ const isElemFocusable = (el: HTMLElement) => {
26
28
  return el.hasAttribute("data-ui5-focus-redirect") || !isElementHidden(el);
27
29
  };
28
30
 
29
- const findFocusableElement = async (container: HTMLElement, forward: boolean, startFromContainer?: boolean): Promise<HTMLElement | null> => {
31
+ const findFocusableElement = async (container: HTMLElement, forward: boolean, startFromContainer?: boolean): FocusableElementPromise => {
30
32
  let child: HTMLElement | undefined;
31
33
 
32
34
  if (container.shadowRoot) {
@@ -59,13 +59,13 @@ const isClickInRect = (event: MouseEvent | TouchEvent, rect: DOMRect) => {
59
59
  let x;
60
60
  let y;
61
61
 
62
- if (event instanceof TouchEvent) {
62
+ if (event instanceof MouseEvent) {
63
+ x = event.clientX;
64
+ y = event.clientY;
65
+ } else {
63
66
  const touch = event.touches[0];
64
67
  x = touch.clientX;
65
68
  y = touch.clientY;
66
- } else {
67
- x = event.clientX;
68
- y = event.clientY;
69
69
  }
70
70
 
71
71
  return isPointInRect(x, y, rect);
@@ -1,15 +1,29 @@
1
1
  import isElementTabbable from "./isElementTabbable.js";
2
2
 
3
- const getTabbableElements = (el: HTMLElement) => {
3
+ /**
4
+ * Returns the tabbable elements within the provided HTMLElement.
5
+ *
6
+ * @public
7
+ * @param { HTMLElement } el the component to operate on (component that slots or contains within its shadow root the items the user navigates among)
8
+ * @returns { Array<HTMLElement> } the tabbable elements
9
+ */
10
+ const getTabbableElements = (el: HTMLElement): Array<HTMLElement> => {
4
11
  return getTabbables([...el.children]);
5
12
  };
6
13
 
7
- const getLastTabbableElement = (el: HTMLElement) => {
14
+ /**
15
+ * Returns the last tabbable element within the provided HTMLElement.
16
+ *
17
+ * @public
18
+ * @param { HTMLElement } el the component to operate on (component that slots or contains within its shadow root the items the user navigates among)
19
+ * @returns { HTMLElement | null } the last tabbable element or "null" if not found
20
+ */
21
+ const getLastTabbableElement = (el: HTMLElement): HTMLElement | null => {
8
22
  const tabbables = getTabbables([...el.children]);
9
23
  return tabbables.length ? tabbables[tabbables.length - 1] : null;
10
24
  };
11
25
 
12
- const getTabbables = (nodes: Array<Node>, tabbables?: Array<HTMLElement>) => {
26
+ const getTabbables = (nodes: Array<Node>, tabbables?: Array<HTMLElement>): Array<HTMLElement> => {
13
27
  const tabbableElements = tabbables || [];
14
28
 
15
29
  if (!nodes) {
@@ -1,6 +1,13 @@
1
1
  import isElementHidden from "./isElementHidden.js";
2
2
 
3
- const isElementTabbable = (el: HTMLElement) => {
3
+ /**
4
+ * Returns if the HTMLElement is tabbable.
5
+ *
6
+ * @public
7
+ * @param { HTMLElement } el the component to operate on (component that slots or contains within its shadow root the items the user navigates among)
8
+ * @returns { boolean } true if the element is tabbable or false - if not
9
+ */
10
+ const isElementTabbable = (el: HTMLElement): boolean => {
4
11
  if (!el) {
5
12
  return false;
6
13
  }
@@ -23,6 +30,8 @@ const isElementTabbable = (el: HTMLElement) => {
23
30
  if (nodeName === "a" || /input|select|textarea|button|object/.test(nodeName)) {
24
31
  return !(el as HTMLLinkElement).disabled;
25
32
  }
33
+
34
+ return false;
26
35
  };
27
36
 
28
37
  export default isElementTabbable;
@@ -0,0 +1,7 @@
1
+ const willShowContent = (childNodes: Array<Node>) => {
2
+ return Array.from(childNodes).filter(node => {
3
+ return node.nodeType !== Node.COMMENT_NODE && (node.nodeType !== Node.TEXT_NODE || (node.nodeValue || "").trim().length !== 0);
4
+ }).length > 0;
5
+ };
6
+
7
+ export default willShowContent;