@ui5/webcomponents-base 0.0.0-306572ffa → 0.0.0-35e2c9666

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 (328) hide show
  1. package/.eslintignore +3 -0
  2. package/CHANGELOG.md +242 -0
  3. package/README.md +26 -2
  4. package/bundle.esm.js +13 -11
  5. package/dist/AssetRegistry.js +8 -7
  6. package/dist/Boot.js +59 -0
  7. package/dist/CSP.js +59 -0
  8. package/dist/CustomElementsRegistry.js +60 -4
  9. package/dist/DOMObserver.js +65 -0
  10. package/dist/Device.js +69 -776
  11. package/dist/EventProvider.js +30 -26
  12. package/dist/FeaturesRegistry.js +4 -1
  13. package/dist/FontFace.js +19 -62
  14. package/dist/InitialConfiguration.js +43 -8
  15. package/dist/Keys.js +107 -0
  16. package/dist/ManagedStyles.js +83 -0
  17. package/dist/MediaRange.js +109 -0
  18. package/{src/util/parseProperties.js → dist/PropertiesFileFormat.js} +6 -0
  19. package/dist/Render.js +175 -0
  20. package/dist/RenderScheduler.js +16 -138
  21. package/dist/Runtimes.js +107 -0
  22. package/dist/StaticArea.js +1 -29
  23. package/dist/StaticAreaItem.js +58 -65
  24. package/dist/SystemCSSVars.js +4 -25
  25. package/dist/Theming.js +2 -1
  26. package/dist/UI5Element.js +310 -365
  27. package/dist/UI5ElementMetadata.js +131 -16
  28. package/dist/asset-registries/Icons.js +121 -13
  29. package/dist/asset-registries/Illustrations.js +30 -0
  30. package/dist/asset-registries/LocaleData.js +105 -66
  31. package/dist/asset-registries/Themes.js +23 -32
  32. package/dist/asset-registries/i18n.js +62 -48
  33. package/dist/assets-meta/IconCollectionsAlias.js +18 -0
  34. package/dist/config/Language.js +33 -6
  35. package/dist/config/Theme.js +25 -0
  36. package/dist/css/FontFace.css +45 -0
  37. package/dist/css/OverrideFontFace.css +32 -0
  38. package/dist/css/SystemCSSVars.css +17 -0
  39. package/dist/delegate/ItemNavigation.js +239 -170
  40. package/dist/delegate/ResizeHandler.js +78 -37
  41. package/dist/delegate/ScrollEnablement.js +49 -20
  42. package/dist/features/F6Navigation.js +108 -0
  43. package/dist/features/OpenUI5Support.js +41 -6
  44. package/dist/generated/AssetParameters.js +1 -1
  45. package/dist/generated/VersionInfo.js +10 -0
  46. package/dist/generated/css/FontFace.css.js +5 -0
  47. package/dist/generated/css/OverrideFontFace.css.js +5 -0
  48. package/dist/generated/css/SystemCSSVars.css.js +5 -0
  49. package/dist/i18nBundle.js +38 -4
  50. package/dist/isLegacyBrowser.js +3 -0
  51. package/dist/locale/applyDirection.js +6 -4
  52. package/dist/locale/directionChange.js +32 -0
  53. package/dist/locale/getEffectiveDir.js +28 -0
  54. package/dist/locale/getLocale.js +12 -2
  55. package/dist/locale/languageChange.js +1 -1
  56. package/dist/renderer/LitRenderer.js +24 -21
  57. package/dist/renderer/directives/style-map.js +72 -0
  58. package/dist/resources/bundle.esm.js +17 -109
  59. package/dist/resources/bundle.esm.js.map +1 -1
  60. package/dist/sap/base/Log.js +241 -0
  61. package/dist/sap/base/assert.js +8 -0
  62. package/dist/sap/base/security/URLListValidator.js +148 -0
  63. package/dist/sap/base/security/encodeCSS.js +14 -0
  64. package/dist/sap/base/security/encodeXML.js +23 -0
  65. package/dist/sap/base/security/sanitizeHTML.js +16 -0
  66. package/dist/sap/base/strings/toHex.js +8 -0
  67. package/dist/sap/base/util/now.js +7 -0
  68. package/dist/sap/ui/thirdparty/caja-html-sanitizer.js +3585 -0
  69. package/dist/test-resources/assets/Themes.js +8 -8
  70. package/dist/test-resources/elements/Parent.js +6 -2
  71. package/dist/test-resources/elements/WithStaticArea.js +2 -1
  72. package/dist/test-resources/pages/AllTestElements.html +3 -3
  73. package/dist/test-resources/pages/Configuration.html +0 -2
  74. package/dist/test-resources/pages/ConfigurationScript.html +0 -2
  75. package/dist/test-resources/pages/i18n.html +2 -9
  76. package/dist/test-resources/specs/ConfigurationChange.spec.js +10 -8
  77. package/dist/test-resources/specs/ConfigurationScript.spec.js +25 -23
  78. package/dist/test-resources/specs/ConfigurationURL.spec.js +65 -17
  79. package/dist/test-resources/specs/CustomTheme.spec.js +9 -7
  80. package/dist/test-resources/specs/EventProvider.spec.js +63 -0
  81. package/dist/test-resources/specs/StaticArea.spec.js +56 -12
  82. package/dist/test-resources/specs/Theming.spec.js +12 -10
  83. package/dist/test-resources/specs/UI5ElementInvalidation.js +54 -70
  84. package/dist/test-resources/specs/UI5ElementLifecycle.js +17 -15
  85. package/dist/test-resources/specs/UI5ElementListenForChildPropChanges.spec.js +25 -51
  86. package/dist/test-resources/specs/UI5ElementMetadataExt.js +9 -7
  87. package/dist/test-resources/specs/UI5ElementPropertyValidation.js +7 -5
  88. package/dist/test-resources/specs/UI5ElementPropsAndAttrs.spec.js +37 -35
  89. package/dist/test-resources/specs/UI5ElementShadowDOM.js +10 -8
  90. package/dist/test-resources/specs/UI5ElementSlots.js +10 -8
  91. package/dist/theming/CustomStyle.js +25 -5
  92. package/dist/theming/ThemeLoaded.js +22 -0
  93. package/dist/theming/applyTheme.js +13 -15
  94. package/dist/theming/getConstructableStyle.js +7 -6
  95. package/dist/theming/getEffectiveLinksHrefs.js +20 -0
  96. package/dist/theming/getEffectiveStyle.js +15 -8
  97. package/dist/theming/getStylesString.js +4 -2
  98. package/dist/theming/getThemeDesignerTheme.js +25 -5
  99. package/dist/theming/preloadLinks.js +23 -0
  100. package/dist/types/CSSColor.js +9 -0
  101. package/dist/types/CalendarType.js +1 -1
  102. package/dist/types/DataType.js +13 -1
  103. package/dist/types/Float.js +4 -0
  104. package/dist/types/Integer.js +4 -0
  105. package/dist/types/InvisibleMessageMode.js +30 -0
  106. package/dist/types/ItemNavigationBehavior.js +2 -7
  107. package/dist/types/PopupState.js +1 -1
  108. package/dist/types/ValueState.js +1 -1
  109. package/dist/updateShadowRoot.js +30 -0
  110. package/dist/util/AriaLabelHelper.js +41 -0
  111. package/dist/util/Caret.js +45 -0
  112. package/dist/util/ColorConversion.js +370 -0
  113. package/dist/util/FocusableElements.js +22 -9
  114. package/dist/util/HTMLSanitizer.js +7 -0
  115. package/dist/util/InvisibleMessage.js +60 -0
  116. package/dist/util/PopupUtils.js +93 -0
  117. package/dist/util/SlotsHelper.js +43 -0
  118. package/dist/util/TabbableElements.js +5 -1
  119. package/dist/util/arraysAreEqual.js +15 -0
  120. package/dist/util/clamp.js +12 -0
  121. package/dist/util/createLinkInHead.js +19 -0
  122. package/dist/util/debounce.js +17 -0
  123. package/dist/util/escapeRegex.js +10 -0
  124. package/dist/util/generateHighlightedMarkup.js +42 -0
  125. package/dist/util/getActiveElement.js +11 -0
  126. package/dist/util/getClassCopy.js +10 -0
  127. package/dist/util/getEffectiveContentDensity.js +5 -0
  128. package/dist/util/isElementInView.js +15 -0
  129. package/dist/util/isNodeHidden.js +1 -1
  130. package/dist/util/isNodeTabbable.js +4 -4
  131. package/dist/util/isValidPropertyName.js +4 -2
  132. package/hash.txt +1 -0
  133. package/index.js +1 -1
  134. package/lib/generate-asset-parameters/index.js +0 -1
  135. package/lib/generate-styles/index.js +18 -0
  136. package/lib/generate-version-info/index.js +27 -0
  137. package/package-scripts.js +34 -19
  138. package/package.json +19 -13
  139. package/src/AssetRegistry.js +8 -7
  140. package/src/Boot.js +59 -0
  141. package/src/CSP.js +59 -0
  142. package/src/CustomElementsRegistry.js +60 -4
  143. package/src/DOMObserver.js +65 -0
  144. package/src/Device.js +69 -776
  145. package/src/EventProvider.js +30 -26
  146. package/src/FeaturesRegistry.js +4 -1
  147. package/src/FontFace.js +19 -62
  148. package/src/InitialConfiguration.js +43 -8
  149. package/src/Keys.js +107 -0
  150. package/src/ManagedStyles.js +83 -0
  151. package/src/MediaRange.js +109 -0
  152. package/{dist/util/parseProperties.js → src/PropertiesFileFormat.js} +6 -0
  153. package/src/Render.js +175 -0
  154. package/src/RenderScheduler.js +16 -138
  155. package/src/Runtimes.js +107 -0
  156. package/src/StaticArea.js +1 -29
  157. package/src/StaticAreaItem.js +58 -65
  158. package/src/SystemCSSVars.js +4 -25
  159. package/src/Theming.js +2 -1
  160. package/src/UI5Element.js +310 -365
  161. package/src/UI5ElementMetadata.js +131 -16
  162. package/src/asset-registries/Icons.js +121 -13
  163. package/src/asset-registries/Illustrations.js +30 -0
  164. package/src/asset-registries/LocaleData.js +105 -66
  165. package/src/asset-registries/Themes.js +23 -32
  166. package/src/asset-registries/i18n.js +62 -48
  167. package/src/assets-meta/IconCollectionsAlias.js +18 -0
  168. package/src/config/Language.js +33 -6
  169. package/src/config/Theme.js +25 -0
  170. package/src/css/FontFace.css +45 -0
  171. package/src/css/OverrideFontFace.css +32 -0
  172. package/src/css/SystemCSSVars.css +17 -0
  173. package/src/delegate/ItemNavigation.js +239 -170
  174. package/src/delegate/ResizeHandler.js +78 -37
  175. package/src/delegate/ScrollEnablement.js +49 -20
  176. package/src/features/F6Navigation.js +108 -0
  177. package/src/features/OpenUI5Support.js +41 -6
  178. package/src/i18nBundle.js +38 -4
  179. package/src/isLegacyBrowser.js +3 -0
  180. package/src/locale/applyDirection.js +6 -4
  181. package/src/locale/directionChange.js +32 -0
  182. package/src/locale/getEffectiveDir.js +28 -0
  183. package/src/locale/getLocale.js +12 -2
  184. package/src/locale/languageChange.js +1 -1
  185. package/src/renderer/LitRenderer.js +24 -21
  186. package/src/renderer/directives/style-map.js +72 -0
  187. package/src/theming/CustomStyle.js +25 -5
  188. package/src/theming/ThemeLoaded.js +22 -0
  189. package/src/theming/applyTheme.js +13 -15
  190. package/src/theming/getConstructableStyle.js +7 -6
  191. package/src/theming/getEffectiveLinksHrefs.js +20 -0
  192. package/src/theming/getEffectiveStyle.js +15 -8
  193. package/src/theming/getStylesString.js +4 -2
  194. package/src/theming/getThemeDesignerTheme.js +25 -5
  195. package/src/theming/preloadLinks.js +23 -0
  196. package/src/types/CSSColor.js +9 -0
  197. package/src/types/CalendarType.js +1 -1
  198. package/src/types/DataType.js +13 -1
  199. package/src/types/Float.js +4 -0
  200. package/src/types/Integer.js +4 -0
  201. package/src/types/InvisibleMessageMode.js +30 -0
  202. package/src/types/ItemNavigationBehavior.js +2 -7
  203. package/src/types/PopupState.js +1 -1
  204. package/src/types/ValueState.js +1 -1
  205. package/src/updateShadowRoot.js +30 -0
  206. package/src/util/AriaLabelHelper.js +41 -0
  207. package/src/util/Caret.js +45 -0
  208. package/src/util/ColorConversion.js +370 -0
  209. package/src/util/FocusableElements.js +22 -9
  210. package/src/util/HTMLSanitizer.js +7 -0
  211. package/src/util/InvisibleMessage.js +60 -0
  212. package/src/util/PopupUtils.js +93 -0
  213. package/src/util/SlotsHelper.js +43 -0
  214. package/src/util/TabbableElements.js +5 -1
  215. package/src/util/arraysAreEqual.js +15 -0
  216. package/src/util/clamp.js +12 -0
  217. package/src/util/createLinkInHead.js +19 -0
  218. package/src/util/debounce.js +17 -0
  219. package/src/util/escapeRegex.js +10 -0
  220. package/src/util/generateHighlightedMarkup.js +42 -0
  221. package/src/util/getActiveElement.js +11 -0
  222. package/src/util/getClassCopy.js +10 -0
  223. package/src/util/getEffectiveContentDensity.js +5 -0
  224. package/src/util/isElementInView.js +15 -0
  225. package/src/util/isNodeHidden.js +1 -1
  226. package/src/util/isNodeTabbable.js +4 -4
  227. package/src/util/isValidPropertyName.js +4 -2
  228. package/used-modules.txt +10 -0
  229. package/bundle.es5.js +0 -28
  230. package/dist/SVGIconRegistry.js +0 -62
  231. package/dist/boot.js +0 -34
  232. package/dist/compatibility/DOMObserver.js +0 -62
  233. package/dist/compatibility/patchNodeValue.js +0 -24
  234. package/dist/compatibility/whenPolyfillLoaded.js +0 -26
  235. package/dist/delegate/CustomResize.js +0 -78
  236. package/dist/delegate/NativeResize.js +0 -44
  237. package/dist/features/PropertiesFormatSupport.js +0 -8
  238. package/dist/features/browsersupport/Edge.js +0 -6
  239. package/dist/features/browsersupport/IE11.js +0 -41
  240. package/dist/features/browsersupport/IE11WithWebComponentsPolyfill.js +0 -5
  241. package/dist/renderer/ifDefined.js +0 -21
  242. package/dist/renderer/scopeHTML.js +0 -32
  243. package/dist/resources/bundle.es5.js +0 -212
  244. package/dist/resources/bundle.es5.js.map +0 -1
  245. package/dist/theming/CSSVarsPonyfill.js +0 -24
  246. package/dist/theming/adaptCSSForIE.js +0 -95
  247. package/dist/theming/createComponentStyleTag.js +0 -55
  248. package/dist/theming/createThemePropertiesStyleTag.js +0 -20
  249. package/dist/thirdparty/Array.from.js +0 -16
  250. package/dist/thirdparty/Array.prototype.fill.js +0 -44
  251. package/dist/thirdparty/Array.prototype.find.js +0 -46
  252. package/dist/thirdparty/Array.prototype.includes.js +0 -51
  253. package/dist/thirdparty/Element.prototype.closest.js +0 -11
  254. package/dist/thirdparty/Element.prototype.matches.js +0 -6
  255. package/dist/thirdparty/Map.prototype.keys.js +0 -9
  256. package/dist/thirdparty/Number.isInteger.js +0 -5
  257. package/dist/thirdparty/Number.isNaN.js +0 -1
  258. package/dist/thirdparty/Number.parseInt.js +0 -1
  259. package/dist/thirdparty/Object.assign.js +0 -31
  260. package/dist/thirdparty/Object.entries.js +0 -11
  261. package/dist/thirdparty/Symbol.js +0 -2
  262. package/dist/thirdparty/WeakSet.js +0 -27
  263. package/dist/thirdparty/es6-string-methods.js +0 -182
  264. package/dist/thirdparty/events-polyfills.js +0 -89
  265. package/dist/thirdparty/fetch.js +0 -1
  266. package/dist/thirdparty/template.js +0 -600
  267. package/dist/thirdparty/webcomponents-sd-ce-pf.js +0 -318
  268. package/dist/util/getEffectiveAriaLabelText.js +0 -28
  269. package/dist/util/isSlot.js +0 -3
  270. package/dist/webcomponentsjs/LICENSE.md +0 -19
  271. package/dist/webcomponentsjs/README.md +0 -229
  272. package/dist/webcomponentsjs/bundles/webcomponents-ce.js +0 -63
  273. package/dist/webcomponentsjs/bundles/webcomponents-ce.js.map +0 -1
  274. package/dist/webcomponentsjs/bundles/webcomponents-sd-ce-pf.js +0 -297
  275. package/dist/webcomponentsjs/bundles/webcomponents-sd-ce-pf.js.map +0 -1
  276. package/dist/webcomponentsjs/bundles/webcomponents-sd-ce.js +0 -208
  277. package/dist/webcomponentsjs/bundles/webcomponents-sd-ce.js.map +0 -1
  278. package/dist/webcomponentsjs/bundles/webcomponents-sd.js +0 -166
  279. package/dist/webcomponentsjs/bundles/webcomponents-sd.js.map +0 -1
  280. package/dist/webcomponentsjs/custom-elements-es5-adapter.js +0 -15
  281. package/dist/webcomponentsjs/package.json +0 -46
  282. package/dist/webcomponentsjs/src/entrypoints/custom-elements-es5-adapter-index.js +0 -16
  283. package/dist/webcomponentsjs/src/entrypoints/webcomponents-bundle-index.js +0 -53
  284. package/dist/webcomponentsjs/src/entrypoints/webcomponents-ce-index.js +0 -17
  285. package/dist/webcomponentsjs/src/entrypoints/webcomponents-sd-ce-index.js +0 -19
  286. package/dist/webcomponentsjs/src/entrypoints/webcomponents-sd-ce-pf-index.js +0 -28
  287. package/dist/webcomponentsjs/src/entrypoints/webcomponents-sd-index.js +0 -18
  288. package/dist/webcomponentsjs/webcomponents-bundle.js +0 -298
  289. package/dist/webcomponentsjs/webcomponents-bundle.js.map +0 -1
  290. package/dist/webcomponentsjs/webcomponents-loader.js +0 -185
  291. package/src/SVGIconRegistry.js +0 -62
  292. package/src/boot.js +0 -34
  293. package/src/compatibility/DOMObserver.js +0 -62
  294. package/src/compatibility/patchNodeValue.js +0 -24
  295. package/src/compatibility/whenPolyfillLoaded.js +0 -26
  296. package/src/delegate/CustomResize.js +0 -78
  297. package/src/delegate/NativeResize.js +0 -44
  298. package/src/features/PropertiesFormatSupport.js +0 -8
  299. package/src/features/browsersupport/Edge.js +0 -6
  300. package/src/features/browsersupport/IE11.js +0 -41
  301. package/src/features/browsersupport/IE11WithWebComponentsPolyfill.js +0 -5
  302. package/src/renderer/ifDefined.js +0 -21
  303. package/src/renderer/scopeHTML.js +0 -32
  304. package/src/theming/CSSVarsPonyfill.js +0 -24
  305. package/src/theming/adaptCSSForIE.js +0 -95
  306. package/src/theming/createComponentStyleTag.js +0 -55
  307. package/src/theming/createThemePropertiesStyleTag.js +0 -20
  308. package/src/thirdparty/Array.from.js +0 -16
  309. package/src/thirdparty/Array.prototype.fill.js +0 -44
  310. package/src/thirdparty/Array.prototype.find.js +0 -46
  311. package/src/thirdparty/Array.prototype.includes.js +0 -51
  312. package/src/thirdparty/Element.prototype.closest.js +0 -11
  313. package/src/thirdparty/Element.prototype.matches.js +0 -6
  314. package/src/thirdparty/Map.prototype.keys.js +0 -9
  315. package/src/thirdparty/Number.isInteger.js +0 -5
  316. package/src/thirdparty/Number.isNaN.js +0 -1
  317. package/src/thirdparty/Number.parseInt.js +0 -1
  318. package/src/thirdparty/Object.assign.js +0 -31
  319. package/src/thirdparty/Object.entries.js +0 -11
  320. package/src/thirdparty/Symbol.js +0 -2
  321. package/src/thirdparty/WeakSet.js +0 -27
  322. package/src/thirdparty/es6-string-methods.js +0 -182
  323. package/src/thirdparty/events-polyfills.js +0 -89
  324. package/src/thirdparty/fetch.js +0 -1
  325. package/src/thirdparty/template.js +0 -600
  326. package/src/thirdparty/webcomponents-sd-ce-pf.js +0 -318
  327. package/src/util/getEffectiveAriaLabelText.js +0 -28
  328. package/src/util/isSlot.js +0 -3
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2018 Google LLC
4
+ * SPDX-License-Identifier: BSD-3-Clause
5
+ */
6
+
7
+ /**
8
+ * This is the original style-map.js directive from lit-html 2 with the only difference that "render" is not called even for the first rendering (update is used instead)
9
+ */
10
+
11
+ import { noChange } from 'lit-html';
12
+ import { directive, Directive, PartType, } from 'lit-html/directive.js';
13
+ class StyleMapDirective extends Directive {
14
+ constructor(partInfo) {
15
+ var _a;
16
+ super(partInfo);
17
+ if (partInfo.type !== PartType.ATTRIBUTE ||
18
+ partInfo.name !== 'style' ||
19
+ ((_a = partInfo.strings) === null || _a === void 0 ? void 0 : _a.length) > 2) {
20
+ throw new Error('The `styleMap` directive must be used in the `style` attribute ' +
21
+ 'and must be the only part in the attribute.');
22
+ }
23
+ }
24
+ render(styleInfo) {
25
+ return "";
26
+ }
27
+ update(part, [styleInfo]) {
28
+ const { style } = part.element;
29
+ if (this._previousStyleProperties === undefined) {
30
+ this._previousStyleProperties = new Set();
31
+ for (const name in styleInfo) {
32
+ this._previousStyleProperties.add(name);
33
+ }
34
+ // return this.render(styleInfo);
35
+ }
36
+ // Remove old properties that no longer exist in styleInfo
37
+ // We use forEach() instead of for-of so that re don't require down-level
38
+ // iteration.
39
+ this._previousStyleProperties.forEach((name) => {
40
+ // If the name isn't in styleInfo or it's null/undefined
41
+ if (styleInfo[name] == null) {
42
+ this._previousStyleProperties.delete(name);
43
+ if (name.includes('-')) {
44
+ style.removeProperty(name);
45
+ }
46
+ else {
47
+ // Note reset using empty string (vs null) as IE11 does not always
48
+ // reset via null (https://developer.mozilla.org/en-US/docs/Web/API/ElementCSSInlineStyle/style#setting_styles)
49
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
+ style[name] = '';
51
+ }
52
+ }
53
+ });
54
+ // Add or update properties
55
+ for (const name in styleInfo) {
56
+ const value = styleInfo[name];
57
+ if (value != null) {
58
+ this._previousStyleProperties.add(name);
59
+ if (name.includes('-')) {
60
+ style.setProperty(name, value);
61
+ }
62
+ else {
63
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
+ style[name] = value;
65
+ }
66
+ }
67
+ }
68
+ return noChange;
69
+ }
70
+ }
71
+
72
+ export const styleMap = directive(StyleMapDirective);
@@ -1,7 +1,8 @@
1
- import RenderScheduler from "../RenderScheduler.js";
1
+ import { reRenderAllUI5Elements } from "../Render.js";
2
+ import getSharedResource from "../getSharedResource.js";
2
3
  import EventProvider from "../EventProvider.js";
3
4
 
4
- const eventProvider = new EventProvider();
5
+ const eventProvider = getSharedResource("CustomStyle.eventProvider", new EventProvider());
5
6
  const CUSTOM_CSS_CHANGE = "CustomCSSChange";
6
7
 
7
8
  const attachCustomCSSChange = listener => {
@@ -16,16 +17,35 @@ const fireCustomCSSChange = tag => {
16
17
  return eventProvider.fireEvent(CUSTOM_CSS_CHANGE, tag);
17
18
  };
18
19
 
19
- const customCSSFor = {};
20
+ const customCSSFor = getSharedResource("CustomStyle.customCSSFor", {});
21
+
22
+ // Listen to the eventProvider, in case other copies of this CustomStyle module fire this
23
+ // event, and this copy would therefore need to reRender the ui5 webcomponents; but
24
+ // don't reRender if it was this copy that fired the event to begin with.
25
+ let skipRerender;
26
+ attachCustomCSSChange(tag => {
27
+ if (!skipRerender) {
28
+ reRenderAllUI5Elements({ tag });
29
+ }
30
+ });
20
31
 
21
32
  const addCustomCSS = (tag, css) => {
22
33
  if (!customCSSFor[tag]) {
23
34
  customCSSFor[tag] = [];
24
35
  }
25
36
  customCSSFor[tag].push(css);
26
- fireCustomCSSChange(tag);
27
37
 
28
- RenderScheduler.reRenderAllUI5Elements({ tag });
38
+ skipRerender = true;
39
+ try {
40
+ // The event is fired and the attached event listeners are all called synchronously
41
+ // The skipRerender flag will be used to avoid calling reRenderAllUI5Elements twice when it is this copy
42
+ // of CustomStyle.js which is firing the `CustomCSSChange` event.
43
+ fireCustomCSSChange(tag);
44
+ } finally {
45
+ skipRerender = false;
46
+ }
47
+
48
+ return reRenderAllUI5Elements({ tag });
29
49
  };
30
50
 
31
51
  const getCustomCSS = tag => {
@@ -0,0 +1,22 @@
1
+ import EventProvider from "../EventProvider.js";
2
+
3
+ const eventProvider = new EventProvider();
4
+ const THEME_LOADED = "themeLoaded";
5
+
6
+ const attachThemeLoaded = listener => {
7
+ eventProvider.attachEvent(THEME_LOADED, listener);
8
+ };
9
+
10
+ const detachThemeLoaded = listener => {
11
+ eventProvider.detachEvent(THEME_LOADED, listener);
12
+ };
13
+
14
+ const fireThemeLoaded = theme => {
15
+ return eventProvider.fireEvent(THEME_LOADED, theme);
16
+ };
17
+
18
+ export {
19
+ attachThemeLoaded,
20
+ detachThemeLoaded,
21
+ fireThemeLoaded,
22
+ };
@@ -1,10 +1,10 @@
1
1
  import { getThemeProperties, getRegisteredPackages, isThemeRegistered } from "../asset-registries/Themes.js";
2
- import createThemePropertiesStyleTag from "./createThemePropertiesStyleTag.js";
2
+ import { removeStyle, createOrUpdateStyle } from "../ManagedStyles.js";
3
3
  import getThemeDesignerTheme from "./getThemeDesignerTheme.js";
4
- import { ponyfillNeeded, runPonyfill } from "./CSSVarsPonyfill.js";
4
+ import { fireThemeLoaded } from "./ThemeLoaded.js";
5
5
  import { getFeature } from "../FeaturesRegistry.js";
6
6
 
7
- const BASE_THEME_PACKAGE = "@ui5/webcomponents-theme-base";
7
+ const BASE_THEME_PACKAGE = "@ui5/webcomponents-theming";
8
8
 
9
9
  const isThemeBaseRegistered = () => {
10
10
  const registeredPackages = getRegisteredPackages();
@@ -16,15 +16,14 @@ const loadThemeBase = async theme => {
16
16
  return;
17
17
  }
18
18
 
19
- const cssText = await getThemeProperties(BASE_THEME_PACKAGE, theme);
20
- createThemePropertiesStyleTag(cssText, BASE_THEME_PACKAGE);
19
+ const cssData = await getThemeProperties(BASE_THEME_PACKAGE, theme);
20
+ if (cssData) {
21
+ createOrUpdateStyle(cssData, "data-ui5-theme-properties", BASE_THEME_PACKAGE);
22
+ }
21
23
  };
22
24
 
23
25
  const deleteThemeBase = () => {
24
- const styleElement = document.head.querySelector(`style[data-ui5-theme-properties="${BASE_THEME_PACKAGE}"]`);
25
- if (styleElement) {
26
- styleElement.parentElement.removeChild(styleElement);
27
- }
26
+ removeStyle("data-ui5-theme-properties", BASE_THEME_PACKAGE);
28
27
  };
29
28
 
30
29
  const loadComponentPackages = async theme => {
@@ -34,8 +33,10 @@ const loadComponentPackages = async theme => {
34
33
  return;
35
34
  }
36
35
 
37
- const cssText = await getThemeProperties(packageName, theme);
38
- createThemePropertiesStyleTag(cssText, packageName);
36
+ const cssData = await getThemeProperties(packageName, theme);
37
+ if (cssData) {
38
+ createOrUpdateStyle(cssData, "data-ui5-theme-properties", packageName);
39
+ }
39
40
  });
40
41
  };
41
42
 
@@ -72,10 +73,7 @@ const applyTheme = async theme => {
72
73
  const packagesTheme = isThemeRegistered(theme) ? theme : extTheme && extTheme.baseThemeName;
73
74
  await loadComponentPackages(packagesTheme);
74
75
 
75
- // When changing the theme, run the ponyfill immediately
76
- if (ponyfillNeeded()) {
77
- runPonyfill();
78
- }
76
+ fireThemeLoaded(theme);
79
77
  };
80
78
 
81
79
  export default applyTheme;
@@ -4,7 +4,7 @@ import { attachCustomCSSChange } from "./CustomStyle.js";
4
4
  const constructableStyleMap = new Map();
5
5
 
6
6
  attachCustomCSSChange(tag => {
7
- constructableStyleMap.delete(tag);
7
+ constructableStyleMap.delete(`${tag}_normal`); // there is custom CSS only for the component itself, not for its static area part
8
8
  });
9
9
 
10
10
  /**
@@ -13,17 +13,18 @@ attachCustomCSSChange(tag => {
13
13
  * @param ElementClass
14
14
  * @returns {*}
15
15
  */
16
- const getConstructableStyle = ElementClass => {
16
+ const getConstructableStyle = (ElementClass, forStaticArea = false) => {
17
17
  const tag = ElementClass.getMetadata().getTag();
18
+ const key = `${tag}_${forStaticArea ? "static" : "normal"}`;
18
19
 
19
- if (!constructableStyleMap.has(tag)) {
20
- const styleContent = getEffectiveStyle(ElementClass);
20
+ if (!constructableStyleMap.has(key)) {
21
+ const styleContent = getEffectiveStyle(ElementClass, forStaticArea);
21
22
  const style = new CSSStyleSheet();
22
23
  style.replaceSync(styleContent);
23
- constructableStyleMap.set(tag, [style]);
24
+ constructableStyleMap.set(key, [style]);
24
25
  }
25
26
 
26
- return constructableStyleMap.get(tag);
27
+ return constructableStyleMap.get(key);
27
28
  };
28
29
 
29
30
  export default getConstructableStyle;
@@ -0,0 +1,20 @@
1
+ import { getUrl } from "../CSP.js";
2
+
3
+ const flatten = arr => {
4
+ return arr.reduce((acc, val) => acc.concat(Array.isArray(val) ? flatten(val) : val), []);
5
+ };
6
+
7
+ const getEffectiveLinksHrefs = (ElementClass, forStaticArea = false) => {
8
+ let stylesData = ElementClass[forStaticArea ? "staticAreaStyles" : "styles"];
9
+ if (!stylesData) {
10
+ return;
11
+ }
12
+
13
+ if (!Array.isArray(stylesData)) {
14
+ stylesData = [stylesData];
15
+ }
16
+
17
+ return flatten(stylesData).filter(data => !!data).map(data => getUrl(data.packageName, data.fileName));
18
+ };
19
+
20
+ export default getEffectiveLinksHrefs;
@@ -4,20 +4,27 @@ import getStylesString from "./getStylesString.js";
4
4
  const effectiveStyleMap = new Map();
5
5
 
6
6
  attachCustomCSSChange(tag => {
7
- effectiveStyleMap.delete(tag);
7
+ effectiveStyleMap.delete(`${tag}_normal`); // there is custom CSS only for the component itself, not for its static area part
8
8
  });
9
9
 
10
- const getEffectiveStyle = ElementClass => {
10
+ const getEffectiveStyle = (ElementClass, forStaticArea = false) => {
11
11
  const tag = ElementClass.getMetadata().getTag();
12
+ const key = `${tag}_${forStaticArea ? "static" : "normal"}`;
12
13
 
13
- if (!effectiveStyleMap.has(tag)) {
14
- const customStyle = getCustomCSS(tag) || "";
15
- const builtInStyles = getStylesString(ElementClass.styles);
16
- const effectiveStyle = `${builtInStyles} ${customStyle}`;
17
- effectiveStyleMap.set(tag, effectiveStyle);
14
+ if (!effectiveStyleMap.has(key)) {
15
+ let effectiveStyle;
16
+
17
+ if (forStaticArea) {
18
+ effectiveStyle = getStylesString(ElementClass.staticAreaStyles);
19
+ } else {
20
+ const customStyle = getCustomCSS(tag) || "";
21
+ const builtInStyles = getStylesString(ElementClass.styles);
22
+ effectiveStyle = `${builtInStyles} ${customStyle}`;
23
+ }
24
+ effectiveStyleMap.set(key, effectiveStyle);
18
25
  }
19
26
 
20
- return effectiveStyleMap.get(tag);
27
+ return effectiveStyleMap.get(key);
21
28
  };
22
29
 
23
30
  export default getEffectiveStyle;
@@ -1,9 +1,11 @@
1
1
  const getStylesString = styles => {
2
2
  if (Array.isArray(styles)) {
3
- return flatten(styles).join(" ");
3
+ return flatten(styles.filter(style => !!style)).map(style => {
4
+ return typeof style === "string" ? style : style.content;
5
+ }).join(" ");
4
6
  }
5
7
 
6
- return styles;
8
+ return typeof styles === "string" ? styles : styles.content;
7
9
  };
8
10
 
9
11
  const flatten = arr => {
@@ -1,15 +1,26 @@
1
+ const warnings = new Set();
2
+
1
3
  const getThemeMetadata = () => {
2
4
  // Check if the class was already applied, most commonly to the link/style tag with the CSS Variables
3
- let el = document.querySelector(".sapThemeMetaData-Base-baseLib");
5
+ let el = document.querySelector(".sapThemeMetaData-Base-baseLib") || document.querySelector(".sapThemeMetaData-UI5-sap-ui-core");
4
6
  if (el) {
5
7
  return getComputedStyle(el).backgroundImage;
6
8
  }
7
9
 
8
10
  el = document.createElement("span");
9
11
  el.style.display = "none";
12
+
13
+ // Try with sapThemeMetaData-Base-baseLib first
10
14
  el.classList.add("sapThemeMetaData-Base-baseLib");
11
15
  document.body.appendChild(el);
12
- const metadata = getComputedStyle(el).backgroundImage;
16
+ let metadata = getComputedStyle(el).backgroundImage;
17
+
18
+ // Try with sapThemeMetaData-UI5-sap-ui-core only if the previous selector was not found
19
+ if (metadata === "none") {
20
+ el.classList.add("sapThemeMetaData-UI5-sap-ui-core");
21
+ metadata = getComputedStyle(el).backgroundImage;
22
+ }
23
+
13
24
  document.body.removeChild(el);
14
25
 
15
26
  return metadata;
@@ -24,14 +35,20 @@ const parseThemeMetadata = metadataString => {
24
35
  try {
25
36
  paramsString = decodeURIComponent(paramsString);
26
37
  } catch (ex) {
27
- console.warn("Malformed theme metadata string, unable to decodeURIComponent"); // eslint-disable-line
38
+ if (!warnings.has("decode")) {
39
+ console.warn("Malformed theme metadata string, unable to decodeURIComponent"); // eslint-disable-line
40
+ warnings.add("decode");
41
+ }
28
42
  return;
29
43
  }
30
44
  }
31
45
  try {
32
46
  return JSON.parse(paramsString);
33
47
  } catch (ex) {
34
- console.warn("Malformed theme metadata string, unable to parse JSON"); // eslint-disable-line
48
+ if (!warnings.has("parse")) {
49
+ console.warn("Malformed theme metadata string, unable to parse JSON"); // eslint-disable-line
50
+ warnings.add("parse");
51
+ }
35
52
  }
36
53
  }
37
54
  };
@@ -44,7 +61,10 @@ const processThemeMetadata = metadata => {
44
61
  themeName = metadata.Path.match(/\.([^.]+)\.css_variables$/)[1];
45
62
  baseThemeName = metadata.Extends[0];
46
63
  } catch (ex) {
47
- console.warn("Malformed theme metadata Object", metadata); // eslint-disable-line
64
+ if (!warnings.has("object")) {
65
+ console.warn("Malformed theme metadata Object", metadata); // eslint-disable-line
66
+ warnings.add("object");
67
+ }
48
68
  return;
49
69
  }
50
70
 
@@ -0,0 +1,23 @@
1
+ import getEffectiveLinksHrefs from "./getEffectiveLinksHrefs.js";
2
+ import createLinkInHead from "../util/createLinkInHead.js";
3
+ import { shouldUseLinks, shouldPreloadLinks } from "../CSP.js";
4
+
5
+ const preloaded = new Set();
6
+
7
+ const preloadLinks = ElementClass => {
8
+ if (!shouldUseLinks() || !shouldPreloadLinks()) {
9
+ return;
10
+ }
11
+
12
+ const linksHrefs = getEffectiveLinksHrefs(ElementClass, false) || [];
13
+ const staticAreaLinksHrefs = getEffectiveLinksHrefs(ElementClass, true) || [];
14
+
15
+ [...linksHrefs, ...staticAreaLinksHrefs].forEach(href => {
16
+ if (!preloaded.has(href)) {
17
+ createLinkInHead(href, { rel: "preload", as: "style" });
18
+ preloaded.add(href);
19
+ }
20
+ });
21
+ };
22
+
23
+ export default preloadLinks;
@@ -0,0 +1,9 @@
1
+ import DataType from "./DataType.js";
2
+
3
+ class CSSColor extends DataType {
4
+ static isValid(value) {
5
+ return /^(#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})|rgb\(\s*((1?[0-9]?[0-9]|2([0-4][0-9]|5[0-5]))|([0-9]?[0-9](\.[0-9]+)?|100(\.0+)?)%)\s*(,\s*((1?[0-9]?[0-9]|2([0-4][0-9]|5[0-5]))|([0-9]?[0-9](\.[0-9]+)?|100(\.0+)?)%)\s*){2}\)|rgba\((\s*((1?[0-9]?[0-9]|2([0-4][0-9]|5[0-5]))|([0-9]?[0-9](\.[0-9]+)?|100(\.0+)?)%)\s*,){3}\s*(0(\.[0-9]+)?|1(\.0+)?)\s*\)|hsl\(\s*([0-2]?[0-9]?[0-9]|3([0-5][0-9]|60))\s*(,\s*(([0-9]?[0-9](\.[0-9]+)?|100(\.0+)?)%)\s*){2}\)|hsla\(\s*([0-2]?[0-9]?[0-9]|3([0-5][0-9]|60))\s*,(\s*(([0-9]?[0-9](\.[0-9]+)?|100(\.0+)?)%)\s*,){2}\s*(0(\.[0-9]+)?|1(\.0+)?)\s*\)|aliceblue|antiquewhite|aqua|aquamarine|azure|beige|bisque|black|blanchedalmond|blue|blueviolet|brown|burlywood|cadetblue|chartreuse|chocolate|coral|cornflowerblue|cornsilk|crimson|cyan|darkblue|darkcyan|darkgoldenrod|darkgray|darkgrey|darkgreen|darkkhaki|darkmagenta|darkolivegreen|darkorange|darkorchid|darkred|darksalmon|darkseagreen|darkslateblue|darkslategray|darkslategrey|darkturquoise|darkviolet|deeppink|deepskyblue|dimgray|dimgrey|dodgerblue|firebrick|floralwhite|forestgreen|fuchsia|gainsboro|ghostwhite|gold|goldenrod|gray|grey|green|greenyellow|honeydew|hotpink|indianred|indigo|ivory|khaki|lavender|lavenderblush|lawngreen|lemonchiffon|lightblue|lightcoral|lightcyan|lightgoldenrodyellow|lightgray|lightgrey|lightgreen|lightpink|lightsalmon|lightseagreen|lightskyblue|lightslategray|lightslategrey|lightsteelblue|lightyellow|lime|limegreen|linen|magenta|maroon|mediumaquamarine|mediumblue|mediumorchid|mediumpurple|mediumseagreen|mediumslateblue|mediumspringgreen|mediumturquoise|mediumvioletred|midnightblue|mintcream|mistyrose|moccasin|navajowhite|navy|oldlace|olive|olivedrab|orange|orangered|orchid|palegoldenrod|palegreen|paleturquoise|palevioletred|papayawhip|peachpuff|peru|pink|plum|powderblue|purple|red|rosybrown|royalblue|saddlebrown|salmon|sandybrown|seagreen|seashell|sienna|silverskyblue|slateblue|slategray|slategrey|snow|springgreen|steelblue|tan|teal|thistle|tomato|turquoise|violet|wheat|white|whitesmoke|yellow|yellowgreen|transparent|inherit|)$/.test(value ); // eslint-disable-line
6
+ }
7
+ }
8
+
9
+ export default CSSColor;
@@ -17,6 +17,6 @@ class CalendarType extends DataType {
17
17
  }
18
18
  }
19
19
 
20
- CalendarType.generataTypeAcessors(CalendarTypes);
20
+ CalendarType.generateTypeAccessors(CalendarTypes);
21
21
 
22
22
  export default CalendarType;
@@ -11,7 +11,19 @@ class DataType {
11
11
  static isValid(value) {
12
12
  }
13
13
 
14
- static generataTypeAcessors(types) {
14
+ static attributeToProperty(attributeValue) {
15
+ return attributeValue;
16
+ }
17
+
18
+ static propertyToAttribute(propertyValue) {
19
+ return `${propertyValue}`;
20
+ }
21
+
22
+ static valuesAreEqual(value1, value2) {
23
+ return value1 === value2;
24
+ }
25
+
26
+ static generateTypeAccessors(types) {
15
27
  Object.keys(types).forEach(type => {
16
28
  Object.defineProperty(this, type, {
17
29
  get() {
@@ -5,6 +5,10 @@ class Float extends DataType {
5
5
  // Assuming that integers are floats as well!
6
6
  return Number(value) === value;
7
7
  }
8
+
9
+ static attributeToProperty(attributeValue) {
10
+ return parseFloat(attributeValue);
11
+ }
8
12
  }
9
13
 
10
14
  export default Float;
@@ -4,6 +4,10 @@ class Integer extends DataType {
4
4
  static isValid(value) {
5
5
  return Number.isInteger(value);
6
6
  }
7
+
8
+ static attributeToProperty(attributeValue) {
9
+ return parseInt(attributeValue);
10
+ }
7
11
  }
8
12
 
9
13
  export default Integer;
@@ -0,0 +1,30 @@
1
+ import DataType from "./DataType.js";
2
+
3
+ /**
4
+ * Enumeration for different mode behaviors of the <code>InvisibleMessage</code>.
5
+ * @private
6
+ */
7
+ const InvisibleMessageModes = {
8
+
9
+ /**
10
+ * Indicates that updates to the region should be presented at the next graceful opportunity,
11
+ * such as at the end of reading the current sentence, or when the user pauses typing.
12
+ */
13
+ Polite: "Polite",
14
+
15
+ /**
16
+ * Indicates that updates to the region have the highest priority and should be presented to the user immediately.
17
+ */
18
+ Assertive: "Assertive",
19
+
20
+ };
21
+
22
+ class InvisibleMessageMode extends DataType {
23
+ static isValid(value) {
24
+ return !!InvisibleMessageModes[value];
25
+ }
26
+ }
27
+
28
+ InvisibleMessageMode.generateTypeAccessors(InvisibleMessageModes);
29
+
30
+ export default InvisibleMessageModes;
@@ -4,18 +4,13 @@
4
4
  */
5
5
  const ItemNavigationBehavior = {
6
6
  /**
7
- * Static behavior: when border of the items is reached, you can't go out of the cage.
7
+ * Static behavior: navigations stops at the first or last item.
8
8
  */
9
9
  Static: "Static",
10
10
 
11
11
  /**
12
- * Cycling behavior: when border of the items is reached, you can cycle through the items.
12
+ * Cycling behavior: navigating past the last item continues with the first and vice versa.
13
13
  */
14
14
  Cyclic: "Cyclic",
15
-
16
- /**
17
- * Paging behavior: when border of the items is reached, tou can go up/down based on the rowsize(e.g. DayPicker)
18
- */
19
- Paging: "Paging",
20
15
  };
21
16
  export default ItemNavigationBehavior;
@@ -32,6 +32,6 @@ class PopupState extends DataType {
32
32
  }
33
33
  }
34
34
 
35
- PopupState.generataTypeAcessors(PopupStates);
35
+ PopupState.generateTypeAccessors(PopupStates);
36
36
 
37
37
  export default PopupState;
@@ -17,6 +17,6 @@ class ValueState extends DataType {
17
17
  }
18
18
  }
19
19
 
20
- ValueState.generataTypeAcessors(ValueStates);
20
+ ValueState.generateTypeAccessors(ValueStates);
21
21
 
22
22
  export default ValueState;
@@ -0,0 +1,30 @@
1
+ import executeTemplate from "./renderer/executeTemplate.js";
2
+ import getConstructableStyle from "./theming/getConstructableStyle.js";
3
+ import getEffectiveStyle from "./theming/getEffectiveStyle.js";
4
+ import getEffectiveLinksHrefs from "./theming/getEffectiveLinksHrefs.js";
5
+ import isLegacyBrowser from "./isLegacyBrowser.js";
6
+ import { shouldUseLinks } from "./CSP.js";
7
+
8
+ /**
9
+ * Updates the shadow root of a UI5Element or its static area item
10
+ * @param element
11
+ * @param forStaticArea
12
+ */
13
+ const updateShadowRoot = (element, forStaticArea = false) => {
14
+ let styleStrOrHrefsArr;
15
+ const template = forStaticArea ? "staticAreaTemplate" : "template";
16
+ const shadowRoot = forStaticArea ? element.staticAreaItem.shadowRoot : element.shadowRoot;
17
+ const renderResult = executeTemplate(element.constructor[template], element);
18
+
19
+ if (shouldUseLinks()) {
20
+ styleStrOrHrefsArr = getEffectiveLinksHrefs(element.constructor, forStaticArea);
21
+ } else if (document.adoptedStyleSheets) { // Chrome
22
+ shadowRoot.adoptedStyleSheets = getConstructableStyle(element.constructor, forStaticArea);
23
+ } else if (!isLegacyBrowser()) { // FF, Safari
24
+ styleStrOrHrefsArr = getEffectiveStyle(element.constructor, forStaticArea);
25
+ }
26
+
27
+ element.constructor.render(renderResult, shadowRoot, styleStrOrHrefsArr, { host: element });
28
+ };
29
+
30
+ export default updateShadowRoot;
@@ -0,0 +1,41 @@
1
+ import findNodeOwner from "./findNodeOwner.js";
2
+
3
+ const getEffectiveAriaLabelText = el => {
4
+ if (!el.accessibleNameRef) {
5
+ if (el.accessibleName) {
6
+ return el.accessibleName;
7
+ }
8
+
9
+ return undefined;
10
+ }
11
+
12
+ return getAriaLabelledByTexts(el);
13
+ };
14
+
15
+ /**
16
+ *
17
+ * @param {HTMLElement} el Defines the HTMLElement, for which you need to get all related texts
18
+ * @param {HTMLElement} ownerDocument (Optional) Defines the HTMLElement(might document or custom element) where the you want to search for the texts.
19
+ * @param {String} readyIds (Optional) Defines a string of elements ids. The text of these elements will be returned. If used you should provide either el or ownerDocument
20
+ */
21
+ const getAriaLabelledByTexts = (el, ownerDocument, readyIds = "") => {
22
+ const ids = (readyIds && readyIds.split(" ")) || el.accessibleNameRef.split(" ");
23
+ const owner = ownerDocument || findNodeOwner(el);
24
+ let result = "";
25
+
26
+ ids.forEach((elementId, index) => {
27
+ const element = owner.querySelector(`[id='${elementId}']`);
28
+ result += `${element ? element.textContent : ""}`;
29
+
30
+ if (index < ids.length - 1) {
31
+ result += " ";
32
+ }
33
+ });
34
+
35
+ return result;
36
+ };
37
+
38
+ export {
39
+ getEffectiveAriaLabelText,
40
+ getAriaLabelledByTexts,
41
+ };
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Returns the caret (cursor) position of the specified text field (field).
3
+ * Return value range is 0-field.value.length.
4
+ */
5
+ const getCaretPosition = field => {
6
+ // Initialize
7
+ let caretPos = 0;
8
+
9
+ // IE Support
10
+ if (document.selection) {
11
+ // Set focus on the element
12
+ field.focus();
13
+
14
+ // To get cursor position, get empty selection range
15
+ const selection = document.selection.createRange();
16
+
17
+ // Move selection start to 0 position
18
+ selection.moveStart("character", -field.value.length);
19
+
20
+ // The caret position is selection length
21
+ caretPos = selection.text.length;
22
+ } else if (field.selectionStart || field.selectionStart === "0") { // Firefox support
23
+ caretPos = field.selectionDirection === "backward" ? field.selectionStart : field.selectionEnd;
24
+ }
25
+
26
+ return caretPos;
27
+ };
28
+
29
+ const setCaretPosition = (field, caretPos) => {
30
+ if (field.createTextRange) {
31
+ const range = field.createTextRange();
32
+ range.move("character", caretPos);
33
+ range.select();
34
+ } else if (field.selectionStart) {
35
+ field.focus();
36
+ field.setSelectionRange(caretPos, caretPos);
37
+ } else {
38
+ field.focus();
39
+ }
40
+ };
41
+
42
+ export {
43
+ getCaretPosition,
44
+ setCaretPosition,
45
+ };