@ui5/webcomponents-base 0.0.0-974b11d82 → 0.0.0-97db186fd

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 (390) hide show
  1. package/.eslintignore +4 -4
  2. package/.eslintrc.cjs +3 -0
  3. package/.npsrc.json +3 -0
  4. package/CHANGELOG.md +195 -0
  5. package/README.md +4 -0
  6. package/bundle.esm.js +5 -0
  7. package/config/wdio.conf.cjs +400 -0
  8. package/dist/AssetRegistry.js.map +1 -1
  9. package/dist/Boot.d.ts +4 -3
  10. package/dist/Boot.js +27 -4
  11. package/dist/Boot.js.map +1 -1
  12. package/dist/CSP.js.map +1 -1
  13. package/dist/CustomElementsRegistry.js.map +1 -1
  14. package/dist/CustomElementsScope.js.map +1 -1
  15. package/dist/CustomElementsScopeUtils.js.map +1 -1
  16. package/dist/DOMObserver.js.map +1 -1
  17. package/dist/Device.js.map +1 -1
  18. package/dist/EventProvider.js +1 -1
  19. package/dist/EventProvider.js.map +1 -1
  20. package/dist/FeaturesRegistry.js.map +1 -1
  21. package/dist/FontFace.js.map +1 -1
  22. package/dist/IgnoreCustomElements.d.ts +27 -0
  23. package/dist/IgnoreCustomElements.js +39 -0
  24. package/dist/IgnoreCustomElements.js.map +1 -0
  25. package/dist/InitialConfiguration.d.ts +6 -1
  26. package/dist/InitialConfiguration.js +10 -1
  27. package/dist/InitialConfiguration.js.map +1 -1
  28. package/dist/Keys.js.map +1 -1
  29. package/dist/ManagedStyles.js +9 -2
  30. package/dist/ManagedStyles.js.map +1 -1
  31. package/dist/MarkedEvents.js.map +1 -1
  32. package/dist/MediaRange.js.map +1 -1
  33. package/dist/PropertiesFileFormat.js.map +1 -1
  34. package/dist/Render.js.map +1 -1
  35. package/dist/RenderQueue.js.map +1 -1
  36. package/dist/Runtimes.js.map +1 -1
  37. package/dist/StaticArea.d.ts +3 -0
  38. package/dist/StaticArea.js +4 -3
  39. package/dist/StaticArea.js.map +1 -1
  40. package/dist/StaticAreaItem.js +3 -0
  41. package/dist/StaticAreaItem.js.map +1 -1
  42. package/dist/SystemCSSVars.js.map +1 -1
  43. package/dist/Theming.js.map +1 -1
  44. package/dist/UI5Element.d.ts +3 -7
  45. package/dist/UI5Element.js +24 -24
  46. package/dist/UI5Element.js.map +1 -1
  47. package/dist/UI5ElementMetadata.js.map +1 -1
  48. package/dist/animations/AnimationQueue.js.map +1 -1
  49. package/dist/animations/animate.js.map +1 -1
  50. package/dist/animations/scroll.js.map +1 -1
  51. package/dist/animations/slideDown.js.map +1 -1
  52. package/dist/animations/slideUp.js.map +1 -1
  53. package/dist/api.json +1 -1
  54. package/dist/asset-registries/Icons.d.ts +17 -9
  55. package/dist/asset-registries/Icons.js +23 -2
  56. package/dist/asset-registries/Icons.js.map +1 -1
  57. package/dist/asset-registries/Illustrations.js.map +1 -1
  58. package/dist/asset-registries/LocaleData.js.map +1 -1
  59. package/dist/asset-registries/Themes.js +2 -0
  60. package/dist/asset-registries/Themes.js.map +1 -1
  61. package/dist/asset-registries/i18n.js +9 -3
  62. package/dist/asset-registries/i18n.js.map +1 -1
  63. package/dist/assets/Boot.34b7cea0.css +1 -0
  64. package/dist/assets/Boot.7594c895.js +9 -0
  65. package/dist/assets/bundle.esm.37a629e7.js +50 -0
  66. package/dist/assets-meta/IconCollectionsAlias.js.map +1 -1
  67. package/dist/config/AnimationMode.d.ts +2 -2
  68. package/dist/config/AnimationMode.js +1 -1
  69. package/dist/config/AnimationMode.js.map +1 -1
  70. package/dist/config/CalendarType.js.map +1 -1
  71. package/dist/config/FormatSettings.js.map +1 -1
  72. package/dist/config/Icons.js +5 -5
  73. package/dist/config/Icons.js.map +1 -1
  74. package/dist/config/Language.d.ts +10 -1
  75. package/dist/config/Language.js +13 -1
  76. package/dist/config/Language.js.map +1 -1
  77. package/dist/config/NoConflict.js +1 -0
  78. package/dist/config/NoConflict.js.map +1 -1
  79. package/dist/config/RTL.js.map +1 -1
  80. package/dist/config/Theme.d.ts +15 -5
  81. package/dist/config/Theme.js +25 -6
  82. package/dist/config/Theme.js.map +1 -1
  83. package/dist/config/ThemeRoot.d.ts +29 -0
  84. package/dist/config/ThemeRoot.js +59 -0
  85. package/dist/config/ThemeRoot.js.map +1 -0
  86. package/dist/config/Timezone.d.ts +17 -0
  87. package/dist/config/Timezone.js +30 -0
  88. package/dist/config/Timezone.js.map +1 -0
  89. package/dist/decorators/customElement.js +14 -8
  90. package/dist/decorators/customElement.js.map +1 -1
  91. package/dist/decorators/event.js +6 -6
  92. package/dist/decorators/event.js.map +1 -1
  93. package/dist/decorators/property.js +6 -6
  94. package/dist/decorators/property.js.map +1 -1
  95. package/dist/decorators/slot.js +9 -9
  96. package/dist/decorators/slot.js.map +1 -1
  97. package/dist/delegate/ItemNavigation.js.map +1 -1
  98. package/dist/delegate/ResizeHandler.js +7 -5
  99. package/dist/delegate/ResizeHandler.js.map +1 -1
  100. package/dist/delegate/ScrollEnablement.js.map +1 -1
  101. package/dist/features/F6Navigation.js.map +1 -1
  102. package/dist/features/LegacyDateFormats.js.map +1 -1
  103. package/dist/features/OpenUI5Element.js.map +1 -1
  104. package/dist/features/OpenUI5Enablement.js.map +1 -1
  105. package/dist/features/OpenUI5Support.d.ts +1 -0
  106. package/dist/features/OpenUI5Support.js +1 -0
  107. package/dist/features/OpenUI5Support.js.map +1 -1
  108. package/dist/generated/AssetParameters.js +2 -0
  109. package/dist/generated/VersionInfo.js +3 -3
  110. package/dist/generated/css/BusyIndicator.css.js.map +1 -1
  111. package/dist/generated/css/FontFace.css.js.map +1 -1
  112. package/dist/generated/css/OverrideFontFace.css.js.map +1 -1
  113. package/dist/generated/css/SystemCSSVars.css.js.map +1 -1
  114. package/dist/generated/templates/elements/WithComplexTemplateTemplate.lit.d.ts +4 -0
  115. package/dist/generated/templates/elements/WithComplexTemplateTemplate.lit.js +8 -10
  116. package/dist/generated/templates/elements/WithComplexTemplateTemplate.lit.js.map +1 -0
  117. package/dist/getSharedResource.d.ts +1 -1
  118. package/dist/getSharedResource.js +8 -2
  119. package/dist/getSharedResource.js.map +1 -1
  120. package/dist/global.d.ts +2 -0
  121. package/dist/i18nBundle.js +2 -1
  122. package/dist/i18nBundle.js.map +1 -1
  123. package/dist/locale/Locale.js.map +1 -1
  124. package/dist/locale/RTLAwareRegistry.d.ts +1 -1
  125. package/dist/locale/RTLAwareRegistry.js.map +1 -1
  126. package/dist/locale/applyDirection.js.map +1 -1
  127. package/dist/locale/directionChange.js.map +1 -1
  128. package/dist/locale/getEffectiveDir.js.map +1 -1
  129. package/dist/locale/getLocale.js.map +1 -1
  130. package/dist/locale/languageChange.js.map +1 -1
  131. package/dist/locale/nextFallbackLocale.js.map +1 -1
  132. package/dist/locale/normalizeLocale.js.map +1 -1
  133. package/dist/renderer/LitRenderer.js.map +1 -1
  134. package/dist/renderer/executeTemplate.js +1 -1
  135. package/dist/renderer/executeTemplate.js.map +1 -1
  136. package/dist/sap/ui/thirdparty/caja-html-sanitizer.js +1 -1
  137. package/dist/theming/CustomStyle.js.map +1 -1
  138. package/dist/theming/ThemeLoaded.js.map +1 -1
  139. package/dist/theming/ThemeRegistered.d.ts +4 -0
  140. package/dist/theming/ThemeRegistered.js +11 -0
  141. package/dist/theming/ThemeRegistered.js.map +1 -0
  142. package/dist/theming/applyTheme.js +3 -2
  143. package/dist/theming/applyTheme.js.map +1 -1
  144. package/dist/theming/getConstructableStyle.js.map +1 -1
  145. package/dist/theming/getEffectiveLinksHrefs.js.map +1 -1
  146. package/dist/theming/getEffectiveStyle.js.map +1 -1
  147. package/dist/theming/getStylesString.js.map +1 -1
  148. package/dist/theming/getThemeDesignerTheme.js.map +1 -1
  149. package/dist/theming/preloadLinks.js.map +1 -1
  150. package/dist/thirdparty/_merge.js.map +1 -1
  151. package/dist/thirdparty/isPlainObject.js.map +1 -1
  152. package/dist/thirdparty/merge.js.map +1 -1
  153. package/dist/types/AnimationMode.d.ts +1 -1
  154. package/dist/types/AnimationMode.js +1 -1
  155. package/dist/types/AnimationMode.js.map +1 -1
  156. package/dist/types/CSSColor.d.ts +0 -1
  157. package/dist/types/CSSColor.js +0 -1
  158. package/dist/types/CSSColor.js.map +1 -1
  159. package/dist/types/CalendarType.d.ts +1 -1
  160. package/dist/types/CalendarType.js +1 -1
  161. package/dist/types/CalendarType.js.map +1 -1
  162. package/dist/types/DOMReference.js.map +1 -1
  163. package/dist/types/DataType.js.map +1 -1
  164. package/dist/types/Float.d.ts +0 -1
  165. package/dist/types/Float.js +0 -1
  166. package/dist/types/Float.js.map +1 -1
  167. package/dist/types/Integer.d.ts +0 -1
  168. package/dist/types/Integer.js +0 -1
  169. package/dist/types/Integer.js.map +1 -1
  170. package/dist/types/InvisibleMessageMode.d.ts +1 -1
  171. package/dist/types/InvisibleMessageMode.js +1 -1
  172. package/dist/types/InvisibleMessageMode.js.map +1 -1
  173. package/dist/types/ItemNavigationBehavior.d.ts +1 -1
  174. package/dist/types/ItemNavigationBehavior.js +1 -1
  175. package/dist/types/ItemNavigationBehavior.js.map +1 -1
  176. package/dist/types/NavigationMode.d.ts +1 -1
  177. package/dist/types/NavigationMode.js +1 -1
  178. package/dist/types/NavigationMode.js.map +1 -1
  179. package/dist/types/ValueState.d.ts +1 -1
  180. package/dist/types/ValueState.js +1 -1
  181. package/dist/types/ValueState.js.map +1 -1
  182. package/dist/types.d.ts +1 -1
  183. package/dist/types.js.map +1 -1
  184. package/dist/updateShadowRoot.js +7 -4
  185. package/dist/updateShadowRoot.js.map +1 -1
  186. package/dist/util/AriaLabelHelper.js.map +1 -1
  187. package/dist/util/Caret.js.map +1 -1
  188. package/dist/util/ColorConversion.js.map +1 -1
  189. package/dist/util/FetchHelper.js.map +1 -1
  190. package/dist/util/FocusableElements.js +4 -3
  191. package/dist/util/FocusableElements.js.map +1 -1
  192. package/dist/util/HTMLSanitizer.js.map +1 -1
  193. package/dist/util/InvisibleMessage.d.ts +1 -1
  194. package/dist/util/InvisibleMessage.js.map +1 -1
  195. package/dist/util/PopupUtils.js.map +1 -1
  196. package/dist/util/SlotsHelper.js.map +1 -1
  197. package/dist/util/StringHelper.js.map +1 -1
  198. package/dist/util/TabbableElements.js.map +1 -1
  199. package/dist/util/arraysAreEqual.js.map +1 -1
  200. package/dist/util/clamp.js.map +1 -1
  201. package/dist/util/createLinkInHead.js.map +1 -1
  202. package/dist/util/createStyleInHead.js.map +1 -1
  203. package/dist/util/debounce.js.map +1 -1
  204. package/dist/util/detectNavigatorLanguage.js.map +1 -1
  205. package/dist/util/escapeRegex.js.map +1 -1
  206. package/dist/util/formatMessage.js.map +1 -1
  207. package/dist/util/generateHighlightedMarkup.js.map +1 -1
  208. package/dist/util/getActiveElement.js.map +1 -1
  209. package/dist/util/getClassCopy.d.ts +2 -1
  210. package/dist/util/getClassCopy.js.map +1 -1
  211. package/dist/util/getDesigntimePropertyAsArray.js.map +1 -1
  212. package/dist/util/getEffectiveContentDensity.js.map +1 -1
  213. package/dist/util/getEffectiveScrollbarStyle.js.map +1 -1
  214. package/dist/util/getFastNavigationGroups.js.map +1 -1
  215. package/dist/util/getFileExtension.js.map +1 -1
  216. package/dist/util/getNormalizedTarget.js.map +1 -1
  217. package/dist/util/getSingletonElementInstance.d.ts +10 -1
  218. package/dist/util/getSingletonElementInstance.js +11 -2
  219. package/dist/util/getSingletonElementInstance.js.map +1 -1
  220. package/dist/util/isElementClickable.js.map +1 -1
  221. package/dist/util/isElementHidden.js.map +1 -1
  222. package/dist/util/isElementInView.js.map +1 -1
  223. package/dist/util/isElementTabbable.js.map +1 -1
  224. package/dist/util/isValidPropertyName.js.map +1 -1
  225. package/dist/util/whenDOMReady.js.map +1 -1
  226. package/dist/util/willShowContent.js.map +1 -1
  227. package/dist/validateThemeRoot.js +14 -13
  228. package/dist/validateThemeRoot.js.map +1 -1
  229. package/index.js +227 -1
  230. package/lib/generate-asset-parameters/index.js +4 -2
  231. package/lib/generate-styles/index.js +3 -3
  232. package/lib/generate-version-info/index.js +1 -1
  233. package/{package-scripts.js → package-scripts.cjs} +4 -4
  234. package/package.json +5 -4
  235. package/tsconfig.json +1 -0
  236. package/config/wdio.conf.js +0 -1
  237. package/dist/assets/bundle.esm.ea2cc5c5.js +0 -60
  238. package/dist/config/ThemeRoots.d.ts +0 -4
  239. package/dist/config/ThemeRoots.js +0 -28
  240. package/dist/config/ThemeRoots.js.map +0 -1
  241. package/dist/decorators/fastNavigation.d.ts +0 -7
  242. package/dist/decorators/fastNavigation.js +0 -13
  243. package/dist/decorators/fastNavigation.js.map +0 -1
  244. package/dist/decorators/languageAware.d.ts +0 -7
  245. package/dist/decorators/languageAware.js +0 -13
  246. package/dist/decorators/languageAware.js.map +0 -1
  247. package/dist/decorators/themeAware.d.ts +0 -7
  248. package/dist/decorators/themeAware.js +0 -13
  249. package/dist/decorators/themeAware.js.map +0 -1
  250. package/src/AssetRegistry.ts +0 -11
  251. package/src/Boot.ts +0 -65
  252. package/src/CSP.ts +0 -66
  253. package/src/CustomElementsRegistry.ts +0 -98
  254. package/src/CustomElementsScope.ts +0 -33
  255. package/src/CustomElementsScopeUtils.ts +0 -115
  256. package/src/DOMObserver.ts +0 -28
  257. package/src/Device.ts +0 -203
  258. package/src/EventProvider.ts +0 -87
  259. package/src/FeaturesRegistry.ts +0 -14
  260. package/src/FontFace.ts +0 -31
  261. package/src/InitialConfiguration.ts +0 -207
  262. package/src/Keys.ts +0 -295
  263. package/src/ManagedStyles.ts +0 -92
  264. package/src/MarkedEvents.ts +0 -20
  265. package/src/MediaRange.ts +0 -110
  266. package/src/PropertiesFileFormat.ts +0 -95
  267. package/src/Render.ts +0 -180
  268. package/src/RenderQueue.ts +0 -71
  269. package/src/Runtimes.ts +0 -114
  270. package/src/StaticArea.ts +0 -3
  271. package/src/StaticAreaItem.ts +0 -113
  272. package/src/SystemCSSVars.ts +0 -10
  273. package/src/Theming.ts +0 -4
  274. package/src/UI5Element.ts +0 -1175
  275. package/src/UI5ElementMetadata.ts +0 -389
  276. package/src/animations/AnimationQueue.ts +0 -43
  277. package/src/animations/animate.ts +0 -64
  278. package/src/animations/scroll.ts +0 -21
  279. package/src/animations/slideDown.ts +0 -72
  280. package/src/animations/slideUp.ts +0 -67
  281. package/src/asset-registries/Icons.ts +0 -161
  282. package/src/asset-registries/Illustrations.ts +0 -75
  283. package/src/asset-registries/LocaleData.ts +0 -172
  284. package/src/asset-registries/Themes.ts +0 -72
  285. package/src/asset-registries/i18n.ts +0 -118
  286. package/src/assets-meta/IconCollectionsAlias.ts +0 -41
  287. package/src/config/AnimationMode.ts +0 -33
  288. package/src/config/CalendarType.ts +0 -23
  289. package/src/config/FormatSettings.ts +0 -35
  290. package/src/config/Icons.ts +0 -126
  291. package/src/config/Language.ts +0 -72
  292. package/src/config/NoConflict.ts +0 -67
  293. package/src/config/RTL.ts +0 -45
  294. package/src/config/Theme.ts +0 -64
  295. package/src/config/ThemeRoots.ts +0 -41
  296. package/src/decorators/customElement.ts +0 -57
  297. package/src/decorators/event.ts +0 -28
  298. package/src/decorators/fastNavigation.ts +0 -14
  299. package/src/decorators/languageAware.ts +0 -14
  300. package/src/decorators/property.ts +0 -30
  301. package/src/decorators/slot.ts +0 -49
  302. package/src/decorators/themeAware.ts +0 -14
  303. package/src/delegate/ItemNavigation.ts +0 -393
  304. package/src/delegate/ResizeHandler.ts +0 -100
  305. package/src/delegate/ScrollEnablement.ts +0 -224
  306. package/src/features/F6Navigation.ts +0 -195
  307. package/src/features/LegacyDateFormats.ts +0 -40
  308. package/src/features/OpenUI5Element.ts +0 -11
  309. package/src/features/OpenUI5Enablement.ts +0 -117
  310. package/src/features/OpenUI5Support.ts +0 -153
  311. package/src/generated/css/BusyIndicator.css.ts +0 -9
  312. package/src/generated/css/FontFace.css.ts +0 -9
  313. package/src/generated/css/OverrideFontFace.css.ts +0 -9
  314. package/src/generated/css/SystemCSSVars.css.ts +0 -9
  315. package/src/getSharedResource.ts +0 -39
  316. package/src/global.d.ts +0 -38
  317. package/src/i18nBundle.ts +0 -108
  318. package/src/locale/Locale.ts +0 -101
  319. package/src/locale/RTLAwareRegistry.ts +0 -16
  320. package/src/locale/applyDirection.ts +0 -18
  321. package/src/locale/directionChange.ts +0 -34
  322. package/src/locale/getEffectiveDir.ts +0 -28
  323. package/src/locale/getLocale.ts +0 -46
  324. package/src/locale/languageChange.ts +0 -24
  325. package/src/locale/nextFallbackLocale.ts +0 -28
  326. package/src/locale/normalizeLocale.ts +0 -56
  327. package/src/renderer/LitRenderer.ts +0 -60
  328. package/src/renderer/executeTemplate.ts +0 -40
  329. package/src/theming/CustomStyle.ts +0 -64
  330. package/src/theming/ThemeLoaded.ts +0 -24
  331. package/src/theming/applyTheme.ts +0 -90
  332. package/src/theming/getConstructableStyle.ts +0 -31
  333. package/src/theming/getEffectiveLinksHrefs.ts +0 -26
  334. package/src/theming/getEffectiveStyle.ts +0 -41
  335. package/src/theming/getStylesString.ts +0 -15
  336. package/src/theming/getThemeDesignerTheme.ts +0 -101
  337. package/src/theming/preloadLinks.ts +0 -24
  338. package/src/thirdparty/_merge.ts +0 -32
  339. package/src/thirdparty/isPlainObject.ts +0 -18
  340. package/src/thirdparty/merge.ts +0 -5
  341. package/src/types/AnimationMode.ts +0 -33
  342. package/src/types/CSSColor.ts +0 -20
  343. package/src/types/CalendarType.ts +0 -38
  344. package/src/types/DOMReference.ts +0 -28
  345. package/src/types/DataType.ts +0 -51
  346. package/src/types/Float.ts +0 -25
  347. package/src/types/Integer.ts +0 -25
  348. package/src/types/InvisibleMessageMode.ts +0 -27
  349. package/src/types/ItemNavigationBehavior.ts +0 -26
  350. package/src/types/NavigationMode.ts +0 -33
  351. package/src/types/ValueState.ts +0 -47
  352. package/src/types.ts +0 -30
  353. package/src/updateShadowRoot.ts +0 -42
  354. package/src/util/AriaLabelHelper.ts +0 -218
  355. package/src/util/Caret.ts +0 -28
  356. package/src/util/ColorConversion.ts +0 -399
  357. package/src/util/FetchHelper.ts +0 -31
  358. package/src/util/FocusableElements.ts +0 -92
  359. package/src/util/HTMLSanitizer.ts +0 -9
  360. package/src/util/InvisibleMessage.ts +0 -69
  361. package/src/util/PopupUtils.ts +0 -112
  362. package/src/util/SlotsHelper.ts +0 -39
  363. package/src/util/StringHelper.ts +0 -26
  364. package/src/util/TabbableElements.ts +0 -70
  365. package/src/util/arraysAreEqual.ts +0 -15
  366. package/src/util/clamp.ts +0 -12
  367. package/src/util/createLinkInHead.ts +0 -25
  368. package/src/util/createStyleInHead.ts +0 -20
  369. package/src/util/debounce.ts +0 -18
  370. package/src/util/detectNavigatorLanguage.ts +0 -13
  371. package/src/util/escapeRegex.ts +0 -11
  372. package/src/util/formatMessage.ts +0 -24
  373. package/src/util/generateHighlightedMarkup.ts +0 -43
  374. package/src/util/getActiveElement.ts +0 -11
  375. package/src/util/getClassCopy.ts +0 -12
  376. package/src/util/getDesigntimePropertyAsArray.ts +0 -4
  377. package/src/util/getEffectiveContentDensity.ts +0 -5
  378. package/src/util/getEffectiveScrollbarStyle.ts +0 -5
  379. package/src/util/getFastNavigationGroups.ts +0 -63
  380. package/src/util/getFileExtension.ts +0 -21
  381. package/src/util/getNormalizedTarget.ts +0 -16
  382. package/src/util/getSingletonElementInstance.ts +0 -13
  383. package/src/util/isElementClickable.ts +0 -19
  384. package/src/util/isElementHidden.ts +0 -9
  385. package/src/util/isElementInView.ts +0 -15
  386. package/src/util/isElementTabbable.ts +0 -37
  387. package/src/util/isValidPropertyName.ts +0 -29
  388. package/src/util/whenDOMReady.ts +0 -13
  389. package/src/util/willShowContent.ts +0 -7
  390. package/src/validateThemeRoot.ts +0 -58
package/src/UI5Element.ts DELETED
@@ -1,1175 +0,0 @@
1
- import merge from "./thirdparty/merge.js";
2
- import { boot } from "./Boot.js";
3
- import UI5ElementMetadata, {
4
- Slot,
5
- SlotValue,
6
- State,
7
- PropertyValue,
8
- Metadata,
9
- } from "./UI5ElementMetadata.js";
10
- import EventProvider from "./EventProvider.js";
11
- import getSingletonElementInstance from "./util/getSingletonElementInstance.js";
12
- import StaticAreaItem from "./StaticAreaItem.js";
13
- import updateShadowRoot from "./updateShadowRoot.js";
14
- import { renderDeferred, renderImmediately, cancelRender } from "./Render.js";
15
- import { registerTag, isTagRegistered, recordTagRegistrationFailure } from "./CustomElementsRegistry.js";
16
- import { observeDOMNode, unobserveDOMNode } from "./DOMObserver.js";
17
- import { skipOriginalEvent } from "./config/NoConflict.js";
18
- import getEffectiveDir from "./locale/getEffectiveDir.js";
19
- import DataType from "./types/DataType.js";
20
- import { kebabToCamelCase, camelToKebabCase } from "./util/StringHelper.js";
21
- import isValidPropertyName from "./util/isValidPropertyName.js";
22
- import { getSlotName, getSlottedNodesList } from "./util/SlotsHelper.js";
23
- import arraysAreEqual from "./util/arraysAreEqual.js";
24
- import { markAsRtlAware } from "./locale/RTLAwareRegistry.js";
25
- import preloadLinks from "./theming/preloadLinks.js";
26
- import type { TemplateFunction, TemplateFunctionResult } from "./renderer/executeTemplate.js";
27
- import type { PromiseResolve, ComponentStylesData, ClassMap } from "./types.js";
28
-
29
- let autoId = 0;
30
-
31
- const elementTimeouts = new Map<string, Promise<void>>();
32
- const uniqueDependenciesCache = new Map<typeof UI5Element, Array<typeof UI5Element>>();
33
-
34
- type Renderer = (templateResult: TemplateFunctionResult, container: HTMLElement | DocumentFragment, styleStrOrHrefsArr: string | Array<string> | undefined, forStaticArea: boolean, options: RendererOptions) => void;
35
-
36
- type RendererOptions = {
37
- /**
38
- * An object to use as the `this` value for event listeners. It's often
39
- * useful to set this to the host component rendering a template.
40
- */
41
- host?: object,
42
- }
43
-
44
- type ChangeInfo = {
45
- type: "property" | "slot",
46
- name: string,
47
- reason?: string,
48
- child?: SlotValue,
49
- target?: UI5Element,
50
- newValue?: PropertyValue,
51
- oldValue?: PropertyValue,
52
- }
53
-
54
- type InvalidationInfo = ChangeInfo & { target: UI5Element };
55
-
56
- type ChildChangeListener = (param: InvalidationInfo) => void;
57
-
58
- type SlotChangeListener = (this: HTMLSlotElement, ev: Event) => void;
59
-
60
- /**
61
- * Triggers re-rendering of a UI5Element instance due to state change.
62
- * @param {ChangeInfo} changeInfo An object with information about the change that caused invalidation.
63
- * @private
64
- */
65
- function _invalidate(this: UI5Element, changeInfo: ChangeInfo) {
66
- // Invalidation should be suppressed: 1) before the component is rendered for the first time 2) and during the execution of onBeforeRendering
67
- // This is necessary not only as an optimization, but also to avoid infinite loops on invalidation between children and parents (when invalidateOnChildChange is used)
68
- if (this._suppressInvalidation) {
69
- return;
70
- }
71
-
72
- // Call the onInvalidation hook
73
- this.onInvalidation(changeInfo);
74
-
75
- this._changedState.push(changeInfo);
76
- renderDeferred(this);
77
- this._eventProvider.fireEvent("invalidate", { ...changeInfo, target: this });
78
- }
79
-
80
- let metadata = {} as Metadata;
81
-
82
- /**
83
- * Base class for all UI5 Web Components
84
- *
85
- * @class
86
- * @constructor
87
- * @author SAP SE
88
- * @alias sap.ui.webc.base.UI5Element
89
- * @extends HTMLElement
90
- * @public
91
- */
92
- abstract class UI5Element extends HTMLElement {
93
- __id?: string;
94
- _suppressInvalidation: boolean;
95
- _changedState: Array<ChangeInfo>;
96
- _eventProvider: EventProvider<InvalidationInfo, void>;
97
- _inDOM: boolean;
98
- _fullyConnected: boolean;
99
- _childChangeListeners: Map<string, ChildChangeListener>;
100
- _slotChangeListeners: Map<string, SlotChangeListener>;
101
- _domRefReadyPromise: Promise<void> & { _deferredResolve?: PromiseResolve };
102
- _doNotSyncAttributes: Set<string>;
103
- _state: State;
104
- _onComponentStateFinalized?: () => void;
105
- _getRealDomRef?: () => HTMLElement;
106
-
107
- staticAreaItem?: StaticAreaItem;
108
-
109
- static template?: TemplateFunction;
110
- static staticAreaTemplate?: TemplateFunction;
111
- static _metadata: UI5ElementMetadata;
112
-
113
- /**
114
- * @deprecated
115
- */
116
- static render: Renderer;
117
- static renderer?: Renderer;
118
-
119
- constructor() {
120
- super();
121
-
122
- const ctor = this.constructor as typeof UI5Element;
123
- this._changedState = []; // Filled on each invalidation, cleared on re-render (used for debugging)
124
- this._suppressInvalidation = true; // A flag telling whether all invalidations should be ignored. Initialized with "true" because a UI5Element can not be invalidated until it is rendered for the first time
125
- this._inDOM = false; // A flag telling whether the UI5Element is currently in the DOM tree of the document or not
126
- this._fullyConnected = false; // A flag telling whether the UI5Element's onEnterDOM hook was called (since it's possible to have the element removed from DOM before that)
127
- this._childChangeListeners = new Map(); // used to store lazy listeners per slot for the child change event of every child inside that slot
128
- this._slotChangeListeners = new Map(); // used to store lazy listeners per slot for the slotchange event of all slot children inside that slot
129
- this._eventProvider = new EventProvider(); // used by parent components for listening to changes to child components
130
- let deferredResolve;
131
- this._domRefReadyPromise = new Promise(resolve => {
132
- deferredResolve = resolve;
133
- });
134
- this._domRefReadyPromise._deferredResolve = deferredResolve;
135
- this._doNotSyncAttributes = new Set(); // attributes that are excluded from attributeChangedCallback synchronization
136
-
137
- this._state = { ...ctor.getMetadata().getInitialState() };
138
-
139
- this._upgradeAllProperties();
140
-
141
- if (ctor._needsShadowDOM()) {
142
- this.attachShadow({ mode: "open" });
143
- }
144
- }
145
-
146
- /**
147
- * Returns a unique ID for this UI5 Element
148
- *
149
- * @deprecated - This property is not guaranteed in future releases
150
- * @protected
151
- */
152
- get _id() {
153
- if (!this.__id) {
154
- this.__id = `ui5wc_${++autoId}`;
155
- }
156
-
157
- return this.__id;
158
- }
159
-
160
- /**
161
- * Do not call this method from derivatives of UI5Element, use "onEnterDOM" only
162
- * @private
163
- */
164
- async connectedCallback() {
165
- const ctor = this.constructor as typeof UI5Element;
166
-
167
- this.setAttribute(ctor.getMetadata().getPureTag(), "");
168
- if (ctor.getMetadata().supportsF6FastNavigation()) {
169
- this.setAttribute("data-sap-ui-fastnavgroup", "true");
170
- }
171
-
172
- const slotsAreManaged = ctor.getMetadata().slotsAreManaged();
173
-
174
- this._inDOM = true;
175
-
176
- if (slotsAreManaged) {
177
- // always register the observer before yielding control to the main thread (await)
178
- this._startObservingDOMChildren();
179
- await this._processChildren();
180
- }
181
-
182
- if (!this._inDOM) { // Component removed from DOM while _processChildren was running
183
- return;
184
- }
185
-
186
- renderImmediately(this);
187
- this._domRefReadyPromise._deferredResolve!();
188
- this._fullyConnected = true;
189
- this.onEnterDOM();
190
- }
191
-
192
- /**
193
- * Do not call this method from derivatives of UI5Element, use "onExitDOM" only
194
- * @private
195
- */
196
- disconnectedCallback() {
197
- const ctor = this.constructor as typeof UI5Element;
198
- const slotsAreManaged = ctor.getMetadata().slotsAreManaged();
199
-
200
- this._inDOM = false;
201
-
202
- if (slotsAreManaged) {
203
- this._stopObservingDOMChildren();
204
- }
205
-
206
- if (this._fullyConnected) {
207
- this.onExitDOM();
208
- this._fullyConnected = false;
209
- }
210
-
211
- if (this.staticAreaItem && this.staticAreaItem.parentElement) {
212
- this.staticAreaItem.parentElement.removeChild(this.staticAreaItem);
213
- }
214
-
215
- cancelRender(this);
216
- }
217
-
218
- /**
219
- * Called every time before the component renders.
220
- * @public
221
- */
222
- onBeforeRendering() {}
223
-
224
- /**
225
- * Called every time after the component renders.
226
- * @public
227
- */
228
- onAfterRendering() {}
229
-
230
- /**
231
- * Called on connectedCallback - added to the DOM.
232
- * @public
233
- */
234
- onEnterDOM() {}
235
-
236
- /**
237
- * Called on disconnectedCallback - removed from the DOM.
238
- * @public
239
- */
240
- onExitDOM() {}
241
-
242
- /**
243
- * @private
244
- */
245
- _startObservingDOMChildren() {
246
- const ctor = this.constructor as typeof UI5Element;
247
- const shouldObserveChildren = ctor.getMetadata().hasSlots();
248
- if (!shouldObserveChildren) {
249
- return;
250
- }
251
-
252
- const canSlotText = ctor.getMetadata().canSlotText();
253
- const mutationObserverOptions = {
254
- childList: true,
255
- subtree: canSlotText,
256
- characterData: canSlotText,
257
- };
258
- observeDOMNode(this, this._processChildren.bind(this) as MutationCallback, mutationObserverOptions);
259
- }
260
-
261
- /**
262
- * @private
263
- */
264
- _stopObservingDOMChildren() {
265
- unobserveDOMNode(this);
266
- }
267
-
268
- /**
269
- * Note: this method is also manually called by "compatibility/patchNodeValue.js"
270
- * @private
271
- */
272
- async _processChildren() {
273
- const hasSlots = (this.constructor as typeof UI5Element).getMetadata().hasSlots();
274
- if (hasSlots) {
275
- await this._updateSlots();
276
- }
277
- }
278
-
279
- /**
280
- * @private
281
- */
282
- async _updateSlots() {
283
- const ctor = this.constructor as typeof UI5Element;
284
- const slotsMap = ctor.getMetadata().getSlots();
285
- const canSlotText = ctor.getMetadata().canSlotText();
286
- const domChildren = Array.from(canSlotText ? this.childNodes : this.children) as Array<Node>;
287
-
288
- const slotsCachedContentMap = new Map<string, Array<SlotValue>>(); // Store here the content of each slot before the mutation occurred
289
- const propertyNameToSlotMap = new Map<string, string>(); // Used for reverse lookup to determine to which slot the property name corresponds
290
-
291
- // Init the _state object based on the supported slots and store the previous values
292
- for (const [slotName, slotData] of Object.entries(slotsMap)) { // eslint-disable-line
293
- const propertyName = slotData.propertyName || slotName;
294
- propertyNameToSlotMap.set(propertyName, slotName);
295
- slotsCachedContentMap.set(propertyName, [...(this._state[propertyName] as Array<SlotValue>)]);
296
- this._clearSlot(slotName, slotData);
297
- }
298
-
299
- const autoIncrementMap = new Map<string, number>();
300
- const slottedChildrenMap = new Map<string, Array<{child: Node, idx: number }>>();
301
-
302
- const allChildrenUpgraded = domChildren.map(async (child, idx) => {
303
- // Determine the type of the child (mainly by the slot attribute)
304
- const slotName = getSlotName(child);
305
- const slotData = slotsMap[slotName];
306
-
307
- // Check if the slotName is supported
308
- if (slotData === undefined) {
309
- if (slotName !== "default") {
310
- const validValues = Object.keys(slotsMap).join(", ");
311
- console.warn(`Unknown slotName: ${slotName}, ignoring`, child, `Valid values are: ${validValues}`); // eslint-disable-line
312
- }
313
-
314
- return;
315
- }
316
-
317
- // For children that need individual slots, calculate them
318
- if (slotData.individualSlots) {
319
- const nextIndex = (autoIncrementMap.get(slotName) || 0) + 1;
320
- autoIncrementMap.set(slotName, nextIndex);
321
- (child as Record<string, any>)._individualSlot = `${slotName}-${nextIndex}`;
322
- }
323
-
324
- // Await for not-yet-defined custom elements
325
- if (child instanceof HTMLElement) {
326
- const localName = child.localName;
327
- const isCustomElement = localName.includes("-");
328
- if (isCustomElement) {
329
- const isDefined = window.customElements.get(localName);
330
- if (!isDefined) {
331
- const whenDefinedPromise = window.customElements.whenDefined(localName); // Class registered, but instances not upgraded yet
332
- let timeoutPromise = elementTimeouts.get(localName);
333
- if (!timeoutPromise) {
334
- timeoutPromise = new Promise(resolve => setTimeout(resolve, 1000));
335
- elementTimeouts.set(localName, timeoutPromise);
336
- }
337
- await Promise.race([whenDefinedPromise, timeoutPromise]);
338
- }
339
- window.customElements.upgrade(child);
340
- }
341
- }
342
-
343
- child = (ctor.getMetadata().constructor as typeof UI5ElementMetadata).validateSlotValue(child, slotData);
344
-
345
- // Listen for any invalidation on the child if invalidateOnChildChange is true or an object (ignore when false or not set)
346
- if (instanceOfUI5Element(child) && slotData.invalidateOnChildChange) {
347
- const childChangeListener = this._getChildChangeListener(slotName);
348
-
349
- if (childChangeListener) {
350
- child.attachInvalidate.call(child, childChangeListener);
351
- }
352
- }
353
-
354
- // Listen for the slotchange event if the child is a slot itself
355
- if (child instanceof HTMLSlotElement) {
356
- this._attachSlotChange(child, slotName);
357
- }
358
-
359
- const propertyName = slotData.propertyName || slotName;
360
-
361
- if (slottedChildrenMap.has(propertyName)) {
362
- slottedChildrenMap.get(propertyName)!.push({ child, idx });
363
- } else {
364
- slottedChildrenMap.set(propertyName, [{ child, idx }]);
365
- }
366
- });
367
-
368
- await Promise.all(allChildrenUpgraded);
369
-
370
- // Distribute the child in the _state object, keeping the Light DOM order,
371
- // not the order elements are defined.
372
- slottedChildrenMap.forEach((children, propertyName) => {
373
- this._state[propertyName] = children.sort((a, b) => a.idx - b.idx).map(_ => _.child);
374
- });
375
-
376
- // Compare the content of each slot with the cached values and invalidate for the ones that changed
377
- let invalidated = false;
378
- for (const [slotName, slotData] of Object.entries(slotsMap)) { // eslint-disable-line
379
- const propertyName = slotData.propertyName || slotName;
380
- if (!arraysAreEqual(slotsCachedContentMap.get(propertyName)!, this._state[propertyName] as Array<SlotValue>)) {
381
- _invalidate.call(this, {
382
- type: "slot",
383
- name: propertyNameToSlotMap.get(propertyName)!,
384
- reason: "children",
385
- });
386
- invalidated = true;
387
- }
388
- }
389
-
390
- // If none of the slots had an invalidation due to changes to immediate children,
391
- // the change is considered to be text content of the default slot
392
- if (!invalidated) {
393
- _invalidate.call(this, {
394
- type: "slot",
395
- name: "default",
396
- reason: "textcontent",
397
- });
398
- }
399
- }
400
-
401
- /**
402
- * Removes all children from the slot and detaches listeners, if any
403
- * @private
404
- */
405
- _clearSlot(slotName: string, slotData: Slot) {
406
- const propertyName = slotData.propertyName || slotName;
407
- const children = this._state[propertyName] as Array<SlotValue>;
408
-
409
- children.forEach(child => {
410
- if (instanceOfUI5Element(child)) {
411
- const childChangeListener = this._getChildChangeListener(slotName);
412
-
413
- if (childChangeListener) {
414
- child.detachInvalidate.call(child, childChangeListener);
415
- }
416
- }
417
-
418
- if (child instanceof HTMLSlotElement) {
419
- this._detachSlotChange(child, slotName);
420
- }
421
- });
422
-
423
- this._state[propertyName] = [];
424
- }
425
-
426
- /**
427
- * Attach a callback that will be executed whenever the component is invalidated
428
- *
429
- * @param {InvalidationInfo} callback
430
- * @public
431
- */
432
- attachInvalidate(callback: (param: InvalidationInfo) => void) {
433
- this._eventProvider.attachEvent("invalidate", callback);
434
- }
435
-
436
- /**
437
- * Detach the callback that is executed whenever the component is invalidated
438
- *
439
- * @param {InvalidationInfo} callback
440
- * @public
441
- */
442
- detachInvalidate(callback: (param: InvalidationInfo) => void) {
443
- this._eventProvider.detachEvent("invalidate", callback);
444
- }
445
-
446
- /**
447
- * Callback that is executed whenever a monitored child changes its state
448
- *
449
- * @param {sting} slotName the slot in which a child was invalidated
450
- * @param { ChangeInfo } childChangeInfo the changeInfo object for the child in the given slot
451
- * @private
452
- */
453
- _onChildChange(slotName: string, childChangeInfo: ChangeInfo) {
454
- if (!(this.constructor as typeof UI5Element).getMetadata().shouldInvalidateOnChildChange(slotName, childChangeInfo.type, childChangeInfo.name)) {
455
- return;
456
- }
457
-
458
- // The component should be invalidated as this type of change on the child is listened for
459
- // However, no matter what changed on the child (property/slot), the invalidation is registered as "type=slot" for the component itself
460
- _invalidate.call(this, {
461
- type: "slot",
462
- name: slotName,
463
- reason: "childchange",
464
- child: childChangeInfo.target,
465
- });
466
- }
467
-
468
- /**
469
- * Do not override this method in derivatives of UI5Element
470
- * @private
471
- */
472
- attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {
473
- let newPropertyValue: PropertyValue;
474
- if (this._doNotSyncAttributes.has(name)) { // This attribute is mutated internally, not by the user
475
- return;
476
- }
477
-
478
- const properties = (this.constructor as typeof UI5Element).getMetadata().getProperties();
479
- const realName = name.replace(/^ui5-/, "");
480
- const nameInCamelCase = kebabToCamelCase(realName);
481
- if (properties.hasOwnProperty(nameInCamelCase)) { // eslint-disable-line
482
- const propData = properties[nameInCamelCase];
483
- const propertyType = propData.type;
484
- let propertyValidator = propData.validator as typeof DataType;
485
-
486
- if (propertyType && (propertyType as typeof DataType).isDataTypeClass) {
487
- propertyValidator = propertyType as typeof DataType;
488
- }
489
-
490
- if (propertyValidator) {
491
- newPropertyValue = propertyValidator.attributeToProperty(newValue);
492
- } else if (propertyType === Boolean) {
493
- newPropertyValue = newValue !== null;
494
- } else {
495
- newPropertyValue = newValue as string;
496
- }
497
-
498
- (this as Record<string, any>)[nameInCamelCase] = newPropertyValue;
499
- }
500
- }
501
-
502
- /**
503
- * @private
504
- */
505
- _updateAttribute(name: string, newValue: PropertyValue) {
506
- const ctor = this.constructor as typeof UI5Element;
507
-
508
- if (!ctor.getMetadata().hasAttribute(name)) {
509
- return;
510
- }
511
- const properties = ctor.getMetadata().getProperties();
512
- const propData = properties[name];
513
- const propertyType = propData.type;
514
- let propertyValidator = propData.validator as typeof DataType;
515
- const attrName = camelToKebabCase(name);
516
- const attrValue = this.getAttribute(attrName);
517
-
518
- if (propertyType && (propertyType as typeof DataType).isDataTypeClass) {
519
- propertyValidator = propertyType as typeof DataType;
520
- }
521
-
522
- if (propertyValidator) {
523
- const newAttrValue = propertyValidator.propertyToAttribute(newValue);
524
- if (newAttrValue === null) { // null means there must be no attribute for the current value of the property
525
- this._doNotSyncAttributes.add(attrName); // skip the attributeChangedCallback call for this attribute
526
- this.removeAttribute(attrName); // remove the attribute safely (will not trigger synchronization to the property value due to the above line)
527
- this._doNotSyncAttributes.delete(attrName); // enable synchronization again for this attribute
528
- } else {
529
- this.setAttribute(attrName, newAttrValue);
530
- }
531
- } else if (propertyType === Boolean) {
532
- if (newValue === true && attrValue === null) {
533
- this.setAttribute(attrName, "");
534
- } else if (newValue === false && attrValue !== null) {
535
- this.removeAttribute(attrName);
536
- }
537
- } else if (typeof newValue !== "object") {
538
- if (attrValue !== newValue) {
539
- this.setAttribute(attrName, newValue as string);
540
- }
541
- } // else { return; } // old object handling
542
- }
543
-
544
- /**
545
- * @private
546
- */
547
- _upgradeProperty(this: Record<string, any>, propertyName: string) {
548
- if (this.hasOwnProperty(propertyName)) { // eslint-disable-line
549
- const value = this[propertyName];
550
- delete this[propertyName];
551
- this[propertyName] = value;
552
- }
553
- }
554
-
555
- /**
556
- * @private
557
- */
558
- _upgradeAllProperties() {
559
- const allProps = (this.constructor as typeof UI5Element).getMetadata().getPropertiesList();
560
- allProps.forEach(this._upgradeProperty.bind(this));
561
- }
562
-
563
- /**
564
- * Returns a singleton event listener for the "change" event of a child in a given slot
565
- *
566
- * @param slotName the name of the slot, where the child is
567
- * @returns {ChildChangeListener}
568
- * @private
569
- */
570
- _getChildChangeListener(slotName: string) {
571
- if (!this._childChangeListeners.has(slotName)) {
572
- this._childChangeListeners.set(slotName, this._onChildChange.bind(this, slotName));
573
- }
574
- return this._childChangeListeners.get(slotName);
575
- }
576
-
577
- /**
578
- * Returns a singleton slotchange event listener that invalidates the component due to changes in the given slot
579
- *
580
- * @param slotName the name of the slot, where the slot element (whose slotchange event we're listening to) is
581
- * @returns {SlotChangeListener}
582
- * @private
583
- */
584
- _getSlotChangeListener(slotName: string) {
585
- if (!this._slotChangeListeners.has(slotName)) {
586
- this._slotChangeListeners.set(slotName, this._onSlotChange.bind(this, slotName));
587
- }
588
- return this._slotChangeListeners.get(slotName)!;
589
- }
590
-
591
- /**
592
- * @private
593
- */
594
- _attachSlotChange(child: HTMLSlotElement, slotName: string) {
595
- const slotChangeListener = this._getSlotChangeListener(slotName);
596
- if (slotChangeListener) {
597
- child.addEventListener("slotchange", slotChangeListener);
598
- }
599
- }
600
-
601
- /**
602
- * @private
603
- */
604
- _detachSlotChange(child: HTMLSlotElement, slotName: string) {
605
- child.removeEventListener("slotchange", this._getSlotChangeListener(slotName));
606
- }
607
-
608
- /**
609
- * Whenever a slot element is slotted inside a UI5 Web Component, its slotchange event invalidates the component
610
- *
611
- * @param slotName the name of the slot, where the slot element (whose slotchange event we're listening to) is
612
- * @private
613
- */
614
- _onSlotChange(slotName: string) {
615
- _invalidate.call(this, {
616
- type: "slot",
617
- name: slotName,
618
- reason: "slotchange",
619
- });
620
- }
621
-
622
- /**
623
- * A callback that is executed each time an already rendered component is invalidated (scheduled for re-rendering)
624
- *
625
- * @param changeInfo An object with information about the change that caused invalidation.
626
- * The object can have the following properties:
627
- * - type: (property|slot) tells what caused the invalidation
628
- * 1) property: a property value was changed either directly or as a result of changing the corresponding attribute
629
- * 2) slot: a slotted node(nodes) changed in one of several ways (see "reason")
630
- *
631
- * - name: the name of the property or slot that caused the invalidation
632
- *
633
- * - reason: (children|textcontent|childchange|slotchange) relevant only for type="slot" only and tells exactly what changed in the slot
634
- * 1) children: immediate children (HTML elements or text nodes) were added, removed or reordered in the slot
635
- * 2) textcontent: text nodes in the slot changed value (or nested text nodes were added or changed value). Can only trigger for slots of "type: Node"
636
- * 3) slotchange: a slot element, slotted inside that slot had its "slotchange" event listener called. This practically means that transitively slotted children changed.
637
- * Can only trigger if the child of a slot is a slot element itself.
638
- * 4) childchange: indicates that a UI5Element child in that slot was invalidated and in turn invalidated the component.
639
- * Can only trigger for slots with "invalidateOnChildChange" metadata descriptor
640
- *
641
- * - newValue: the new value of the property (for type="property" only)
642
- *
643
- * - oldValue: the old value of the property (for type="property" only)
644
- *
645
- * - child the child that was changed (for type="slot" and reason="childchange" only)
646
- *
647
- * @public
648
- */
649
- onInvalidation(changeInfo: ChangeInfo) {} // eslint-disable-line
650
-
651
- /**
652
- * Do not call this method directly, only intended to be called by js
653
- * @protected
654
- */
655
- _render() {
656
- const ctor = this.constructor as typeof UI5Element;
657
- const hasIndividualSlots = ctor.getMetadata().hasIndividualSlots();
658
-
659
- // suppress invalidation to prevent state changes scheduling another rendering
660
- this._suppressInvalidation = true;
661
-
662
- this.onBeforeRendering();
663
-
664
- // Intended for framework usage only. Currently ItemNavigation updates tab indexes after the component has updated its state but before the template is rendered
665
- if (this._onComponentStateFinalized) {
666
- this._onComponentStateFinalized();
667
- }
668
-
669
- // resume normal invalidation handling
670
- this._suppressInvalidation = false;
671
-
672
- // Update the shadow root with the render result
673
- /*
674
- if (this._changedState.length) {
675
- let element = this.localName;
676
- if (this.id) {
677
- element = `${element}#${this.id}`;
678
- }
679
- console.log("Re-rendering:", element, this._changedState.map(x => { // eslint-disable-line
680
- let res = `${x.type}`;
681
- if (x.reason) {
682
- res = `${res}(${x.reason})`;
683
- }
684
- res = `${res}: ${x.name}`;
685
- if (x.type === "property") {
686
- res = `${res} ${JSON.stringify(x.oldValue)} => ${JSON.stringify(x.newValue)}`;
687
- }
688
-
689
- return res;
690
- }));
691
- }
692
- */
693
- this._changedState = [];
694
-
695
- // Update shadow root and static area item
696
- if (ctor._needsShadowDOM()) {
697
- updateShadowRoot(this);
698
- }
699
- if (this.staticAreaItem) {
700
- this.staticAreaItem.update();
701
- }
702
-
703
- // Safari requires that children get the slot attribute only after the slot tags have been rendered in the shadow DOM
704
- if (hasIndividualSlots) {
705
- this._assignIndividualSlotsToChildren();
706
- }
707
-
708
- // Call the onAfterRendering hook
709
- this.onAfterRendering();
710
- }
711
-
712
- /**
713
- * @private
714
- */
715
- _assignIndividualSlotsToChildren() {
716
- const domChildren = Array.from(this.children);
717
-
718
- domChildren.forEach((child: Record<string, any>) => {
719
- if (child._individualSlot) {
720
- child.setAttribute("slot", child._individualSlot);
721
- }
722
- });
723
- }
724
-
725
- /**
726
- * @private
727
- */
728
- _waitForDomRef() {
729
- return this._domRefReadyPromise;
730
- }
731
-
732
- /**
733
- * Returns the DOM Element inside the Shadow Root that corresponds to the opening tag in the UI5 Web Component's template
734
- * *Note:* For logical (abstract) elements (items, options, etc...), returns the part of the parent's DOM that represents this option
735
- * Use this method instead of "this.shadowRoot" to read the Shadow DOM, if ever necessary
736
- *
737
- * @public
738
- */
739
- getDomRef() {
740
- // If a component set _getRealDomRef to its children, use the return value of this function
741
- if (typeof this._getRealDomRef === "function") {
742
- return this._getRealDomRef();
743
- }
744
-
745
- if (!this.shadowRoot || this.shadowRoot.children.length === 0) {
746
- return;
747
- }
748
-
749
- const children = [...this.shadowRoot.children].filter(child => !["link", "style"].includes(child.localName));
750
- if (children.length !== 1) {
751
- console.warn(`The shadow DOM for ${(this.constructor as typeof UI5Element).getMetadata().getTag()} does not have a top level element, the getDomRef() method might not work as expected`); // eslint-disable-line
752
- }
753
-
754
- return children[0] as HTMLElement;
755
- }
756
-
757
- /**
758
- * Returns the DOM Element marked with "data-sap-focus-ref" inside the template.
759
- * This is the element that will receive the focus by default.
760
- * @public
761
- */
762
- getFocusDomRef() {
763
- const domRef = this.getDomRef();
764
- if (domRef) {
765
- const focusRef = domRef.querySelector("[data-sap-focus-ref]") as HTMLElement;
766
- return focusRef || domRef;
767
- }
768
- }
769
-
770
- /**
771
- * Waits for dom ref and then returns the DOM Element marked with "data-sap-focus-ref" inside the template.
772
- * This is the element that will receive the focus by default.
773
- * @public
774
- */
775
- async getFocusDomRefAsync() {
776
- await this._waitForDomRef();
777
- return this.getFocusDomRef();
778
- }
779
-
780
- /**
781
- * Set the focus to the element, returned by "getFocusDomRef()" (marked by "data-sap-focus-ref")
782
- * @param {FocusOptions} focusOptions additional options for the focus
783
- * @public
784
- */
785
- async focus(focusOptions?: FocusOptions) {
786
- await this._waitForDomRef();
787
-
788
- const focusDomRef = this.getFocusDomRef();
789
-
790
- if (focusDomRef && typeof focusDomRef.focus === "function") {
791
- focusDomRef.focus(focusOptions);
792
- }
793
- }
794
-
795
- /**
796
- *
797
- * @public
798
- * @param name - name of the event
799
- * @param data - additional data for the event
800
- * @param cancelable - true, if the user can call preventDefault on the event object
801
- * @param bubbles - true, if the event bubbles
802
- * @returns {boolean} false, if the event was cancelled (preventDefault called), true otherwise
803
- */
804
- fireEvent<T>(name: string, data?: T, cancelable = false, bubbles = true) {
805
- const eventResult = this._fireEvent(name, data, cancelable, bubbles);
806
- const camelCaseEventName = kebabToCamelCase(name);
807
-
808
- if (camelCaseEventName !== name) {
809
- return eventResult && this._fireEvent(camelCaseEventName, data, cancelable);
810
- }
811
-
812
- return eventResult;
813
- }
814
-
815
- _fireEvent<T>(name: string, data?: T, cancelable = false, bubbles = true) {
816
- const noConflictEvent = new CustomEvent<T>(`ui5-${name}`, {
817
- detail: data,
818
- composed: false,
819
- bubbles,
820
- cancelable,
821
- });
822
-
823
- // This will be false if the no-conflict event is prevented
824
- const noConflictEventResult = this.dispatchEvent(noConflictEvent);
825
-
826
- if (skipOriginalEvent(name)) {
827
- return noConflictEventResult;
828
- }
829
-
830
- const normalEvent = new CustomEvent<T>(name, {
831
- detail: data,
832
- composed: false,
833
- bubbles,
834
- cancelable,
835
- });
836
-
837
- // This will be false if the normal event is prevented
838
- const normalEventResult = this.dispatchEvent(normalEvent);
839
-
840
- // Return false if any of the two events was prevented (its result was false).
841
- return normalEventResult && noConflictEventResult;
842
- }
843
-
844
- /**
845
- * Returns the actual children, associated with a slot.
846
- * Useful when there are transitive slots in nested component scenarios and you don't want to get a list of the slots, but rather of their content.
847
- * @public
848
- */
849
- getSlottedNodes<T = Node>(slotName: string) {
850
- return getSlottedNodesList((this as unknown as Record<string, Array<SlotValue>>)[slotName]) as Array<T>;
851
- }
852
-
853
- /**
854
- * Determines whether the component should be rendered in RTL mode or not.
855
- * Returns: "rtl", "ltr" or undefined
856
- *
857
- * @public
858
- * @returns {String|undefined}
859
- */
860
- get effectiveDir() {
861
- markAsRtlAware(this.constructor as typeof UI5Element); // if a UI5 Element calls this method, it's considered to be rtl-aware
862
- return getEffectiveDir(this);
863
- }
864
-
865
- /**
866
- * Used to duck-type UI5 elements without using instanceof
867
- * @returns {boolean}
868
- * @public
869
- */
870
- get isUI5Element() {
871
- return true;
872
- }
873
-
874
- get classes(): ClassMap {
875
- return {};
876
- }
877
-
878
- /**
879
- * Do not override this method in derivatives of UI5Element, use metadata properties instead
880
- * @private
881
- */
882
- static get observedAttributes() {
883
- return this.getMetadata().getAttributesList();
884
- }
885
-
886
- /**
887
- * @private
888
- */
889
- static _needsShadowDOM() {
890
- return !!this.template;
891
- }
892
-
893
- /**
894
- * @private
895
- */
896
- static _needsStaticArea() {
897
- return !!this.staticAreaTemplate;
898
- }
899
-
900
- /**
901
- * @public
902
- */
903
- getStaticAreaItemDomRef() {
904
- if (!(this.constructor as typeof UI5Element)._needsStaticArea()) {
905
- throw new Error("This component does not use the static area");
906
- }
907
-
908
- if (!this.staticAreaItem) {
909
- this.staticAreaItem = StaticAreaItem.createInstance();
910
- this.staticAreaItem.setOwnerElement(this);
911
- }
912
- if (!this.staticAreaItem.parentElement) {
913
- getSingletonElementInstance("ui5-static-area").appendChild(this.staticAreaItem);
914
- }
915
-
916
- return this.staticAreaItem.getDomRef();
917
- }
918
-
919
- /**
920
- * @private
921
- */
922
- static _generateAccessors() {
923
- const proto = this.prototype;
924
- const slotsAreManaged = this.getMetadata().slotsAreManaged();
925
-
926
- // Properties
927
- const properties = this.getMetadata().getProperties();
928
- for (const [prop, propData] of Object.entries(properties)) { // eslint-disable-line
929
- if (!isValidPropertyName(prop)) {
930
- console.warn(`"${prop}" is not a valid property name. Use a name that does not collide with DOM APIs`); /* eslint-disable-line */
931
- }
932
-
933
- if (propData.type === Boolean && propData.defaultValue) {
934
- throw new Error(`Cannot set a default value for property "${prop}". All booleans are false by default.`);
935
- }
936
-
937
- if (propData.type === Array) {
938
- throw new Error(`Wrong type for property "${prop}". Properties cannot be of type Array - use "multiple: true" and set "type" to the single value type, such as "String", "Object", etc...`);
939
- }
940
-
941
- if (propData.type === Object && propData.defaultValue) {
942
- throw new Error(`Cannot set a default value for property "${prop}". All properties of type "Object" are empty objects by default.`);
943
- }
944
-
945
- if (propData.multiple && propData.defaultValue) {
946
- throw new Error(`Cannot set a default value for property "${prop}". All multiple properties are empty arrays by default.`);
947
- }
948
-
949
- Object.defineProperty(proto, prop, {
950
- get(this: UI5Element) {
951
- if (this._state[prop] !== undefined) {
952
- return this._state[prop];
953
- }
954
-
955
- const propDefaultValue = propData.defaultValue;
956
-
957
- if (propData.type === Boolean) {
958
- return false;
959
- } else if (propData.type === String) { // eslint-disable-line
960
- return propDefaultValue;
961
- } else if (propData.multiple) { // eslint-disable-line
962
- return [];
963
- } else {
964
- return propDefaultValue;
965
- }
966
- },
967
-
968
- set(this: UI5Element, value: PropertyValue) {
969
- let isDifferent;
970
- const ctor = this.constructor as typeof UI5Element;
971
- const metadataCtor = ctor.getMetadata().constructor as typeof UI5ElementMetadata;
972
-
973
- value = metadataCtor.validatePropertyValue(value, propData);
974
- const propertyType = propData.type;
975
- let propertyValidator = propData.validator as typeof DataType;
976
- const oldState = this._state[prop];
977
-
978
- if (propertyType && (propertyType as typeof DataType).isDataTypeClass) {
979
- propertyValidator = propertyType as typeof DataType;
980
- }
981
-
982
- if (propertyValidator) {
983
- isDifferent = !propertyValidator.valuesAreEqual(oldState, value);
984
- } else if (Array.isArray(oldState) && Array.isArray(value) && propData.multiple && propData.compareValues) { // compareValues is added for IE, test if needed now
985
- isDifferent = !arraysAreEqual(oldState, value);
986
- } else {
987
- isDifferent = oldState !== value;
988
- }
989
-
990
- if (isDifferent) {
991
- this._state[prop] = value;
992
- _invalidate.call(this, {
993
- type: "property",
994
- name: prop,
995
- newValue: value,
996
- oldValue: oldState,
997
- });
998
- this._updateAttribute(prop, value);
999
- }
1000
- },
1001
- });
1002
- }
1003
-
1004
- // Slots
1005
- if (slotsAreManaged) {
1006
- const slots = this.getMetadata().getSlots();
1007
- for (const [slotName, slotData] of Object.entries(slots)) { // eslint-disable-line
1008
- if (!isValidPropertyName(slotName)) {
1009
- console.warn(`"${slotName}" is not a valid property name. Use a name that does not collide with DOM APIs`); /* eslint-disable-line */
1010
- }
1011
-
1012
- const propertyName = slotData.propertyName || slotName;
1013
- Object.defineProperty(proto, propertyName, {
1014
- get(this: UI5Element) {
1015
- if (this._state[propertyName] !== undefined) {
1016
- return this._state[propertyName];
1017
- }
1018
- return [];
1019
- },
1020
- set() {
1021
- throw new Error("Cannot set slot content directly, use the DOM APIs (appendChild, removeChild, etc...)");
1022
- },
1023
- });
1024
- }
1025
- }
1026
- }
1027
-
1028
- /**
1029
- * Returns the metadata object for this UI5 Web Component Class
1030
- * @protected
1031
- */
1032
- static get metadata() {
1033
- return metadata;
1034
- }
1035
-
1036
- /**
1037
- * Sets a new metadata object for this UI5 Web Component Class
1038
- * @protected
1039
- */
1040
- static set metadata(newMetadata) {
1041
- metadata = newMetadata;
1042
- }
1043
-
1044
- /**
1045
- * Returns the CSS for this UI5 Web Component Class
1046
- * @protected
1047
- */
1048
- static get styles(): ComponentStylesData {
1049
- return "";
1050
- }
1051
-
1052
- /**
1053
- * Returns the Static Area CSS for this UI5 Web Component Class
1054
- * @protected
1055
- */
1056
- static get staticAreaStyles(): ComponentStylesData {
1057
- return "";
1058
- }
1059
-
1060
- /**
1061
- * Returns an array with the dependencies for this UI5 Web Component, which could be:
1062
- * - composed components (used in its shadow root or static area item)
1063
- * - slotted components that the component may need to communicate with
1064
- *
1065
- * @protected
1066
- */
1067
- static get dependencies(): Array<typeof UI5Element> {
1068
- return [];
1069
- }
1070
-
1071
- /**
1072
- * Returns a list of the unique dependencies for this UI5 Web Component
1073
- *
1074
- * @public
1075
- */
1076
- static getUniqueDependencies(this: typeof UI5Element) {
1077
- if (!uniqueDependenciesCache.has(this)) {
1078
- const filtered = this.dependencies.filter((dep, index, deps) => deps.indexOf(dep) === index);
1079
- uniqueDependenciesCache.set(this, filtered);
1080
- }
1081
-
1082
- return uniqueDependenciesCache.get(this) || [];
1083
- }
1084
-
1085
- /**
1086
- * Returns a promise that resolves whenever all dependencies for this UI5 Web Component have resolved
1087
- *
1088
- * @returns {Promise}
1089
- */
1090
- static whenDependenciesDefined(): Promise<Array<typeof UI5Element>> {
1091
- return Promise.all(this.getUniqueDependencies().map(dep => dep.define()));
1092
- }
1093
-
1094
- /**
1095
- * Hook that will be called upon custom element definition
1096
- *
1097
- * @protected
1098
- * @returns {Promise<void>}
1099
- */
1100
- static async onDefine() {
1101
- return Promise.resolve();
1102
- }
1103
-
1104
- /**
1105
- * Registers a UI5 Web Component in the browser window object
1106
- * @public
1107
- * @returns {Promise<UI5Element>}
1108
- */
1109
- static async define() {
1110
- await boot();
1111
-
1112
- await Promise.all([
1113
- this.whenDependenciesDefined(),
1114
- this.onDefine(),
1115
- ]);
1116
-
1117
- const tag = this.getMetadata().getTag();
1118
-
1119
- const definedLocally = isTagRegistered(tag);
1120
- const definedGlobally = customElements.get(tag);
1121
-
1122
- if (definedGlobally && !definedLocally) {
1123
- recordTagRegistrationFailure(tag);
1124
- } else if (!definedGlobally) {
1125
- this._generateAccessors();
1126
- registerTag(tag);
1127
- window.customElements.define(tag, this as unknown as CustomElementConstructor);
1128
- preloadLinks(this);
1129
- }
1130
- return this;
1131
- }
1132
-
1133
- /**
1134
- * Returns an instance of UI5ElementMetadata.js representing this UI5 Web Component's full metadata (its and its parents')
1135
- * Note: not to be confused with the "get metadata()" method, which returns an object for this class's metadata only
1136
- * @public
1137
- * @returns {UI5ElementMetadata}
1138
- */
1139
- static getMetadata() {
1140
- if (this.hasOwnProperty("_metadata")) { // eslint-disable-line
1141
- return this._metadata;
1142
- }
1143
-
1144
- const effectiveMetadata = Object.keys(this.metadata).length ? this.metadata : this.decoratorMetadata;
1145
- const metadataObjects = [effectiveMetadata];
1146
- let klass = this; // eslint-disable-line
1147
- while (klass !== UI5Element) {
1148
- klass = Object.getPrototypeOf(klass);
1149
- const effectiveKlassMetadata = Object.keys(klass.metadata).length ? klass.metadata : klass.decoratorMetadata;
1150
- metadataObjects.unshift(effectiveKlassMetadata);
1151
- }
1152
- const mergedMetadata = merge({}, ...metadataObjects) as Metadata;
1153
-
1154
- this._metadata = new UI5ElementMetadata(mergedMetadata);
1155
- return this._metadata;
1156
- }
1157
-
1158
- static decoratorMetadata: Metadata = {};
1159
- }
1160
-
1161
- /**
1162
- * Always use duck-typing to cover all runtimes on the page.
1163
- * @returns {boolean}
1164
- */
1165
- const instanceOfUI5Element = (object: any): object is UI5Element => {
1166
- return "isUI5Element" in object;
1167
- };
1168
-
1169
- export default UI5Element;
1170
- export { instanceOfUI5Element };
1171
- export type {
1172
- ChangeInfo,
1173
- Renderer,
1174
- RendererOptions,
1175
- };