@ui5/webcomponents-base 0.34.0 → 1.0.1

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 (145) hide show
  1. package/.eslintignore +3 -1
  2. package/CHANGELOG.md +52 -0
  3. package/README.md +26 -2
  4. package/bundle.esm.js +6 -2
  5. package/dist/CSP.js +59 -0
  6. package/dist/Device.js +7 -0
  7. package/dist/EventProvider.js +19 -25
  8. package/dist/FontFace.js +7 -95
  9. package/dist/InitialConfiguration.js +31 -14
  10. package/dist/Keys.js +15 -0
  11. package/dist/ManagedStyles.js +83 -0
  12. package/dist/Render.js +3 -1
  13. package/dist/StaticAreaItem.js +11 -9
  14. package/dist/SystemCSSVars.js +4 -25
  15. package/dist/UI5Element.js +46 -60
  16. package/dist/UI5ElementMetadata.js +9 -1
  17. package/dist/asset-registries/Icons.js +29 -8
  18. package/dist/asset-registries/Illustrations.js +30 -0
  19. package/dist/asset-registries/LocaleData.js +11 -2
  20. package/dist/assets-meta/IconCollectionsAlias.js +18 -0
  21. package/dist/config/Theme.js +14 -0
  22. package/dist/css/FontFace.css +45 -0
  23. package/dist/css/OverrideFontFace.css +32 -0
  24. package/dist/css/SystemCSSVars.css +17 -0
  25. package/dist/delegate/ItemNavigation.js +66 -0
  26. package/dist/delegate/ScrollEnablement.js +7 -1
  27. package/dist/generated/AssetParameters.js +1 -1
  28. package/dist/generated/css/FontFace.css.js +5 -0
  29. package/dist/generated/css/OverrideFontFace.css.js +5 -0
  30. package/dist/generated/css/SystemCSSVars.css.js +5 -0
  31. package/dist/i18nBundle.js +33 -2
  32. package/dist/renderer/LitRenderer.js +24 -21
  33. package/dist/renderer/directives/style-map.js +72 -0
  34. package/dist/resources/bundle.esm.js +17 -101
  35. package/dist/resources/bundle.esm.js.map +1 -1
  36. package/dist/sap/base/Log.js +241 -0
  37. package/dist/sap/base/assert.js +8 -0
  38. package/dist/sap/base/security/URLListValidator.js +148 -0
  39. package/dist/sap/base/security/sanitizeHTML.js +16 -0
  40. package/dist/sap/base/util/now.js +7 -0
  41. package/dist/sap/ui/thirdparty/caja-html-sanitizer.js +3585 -0
  42. package/dist/test-resources/elements/WithStaticArea.js +2 -1
  43. package/dist/test-resources/pages/AllTestElements.html +3 -0
  44. package/dist/test-resources/pages/i18n.html +1 -3
  45. package/dist/test-resources/specs/ConfigurationChange.spec.js +9 -9
  46. package/dist/test-resources/specs/ConfigurationScript.spec.js +24 -24
  47. package/dist/test-resources/specs/ConfigurationURL.spec.js +64 -18
  48. package/dist/test-resources/specs/CustomTheme.spec.js +7 -7
  49. package/dist/test-resources/specs/EventProvider.spec.js +63 -0
  50. package/dist/test-resources/specs/StaticArea.spec.js +55 -13
  51. package/dist/test-resources/specs/Theming.spec.js +11 -11
  52. package/dist/test-resources/specs/UI5ElementInvalidation.js +29 -29
  53. package/dist/test-resources/specs/UI5ElementLifecycle.js +11 -11
  54. package/dist/test-resources/specs/UI5ElementListenForChildPropChanges.spec.js +11 -11
  55. package/dist/test-resources/specs/UI5ElementMetadataExt.js +8 -8
  56. package/dist/test-resources/specs/UI5ElementPropertyValidation.js +6 -6
  57. package/dist/test-resources/specs/UI5ElementPropsAndAttrs.spec.js +36 -36
  58. package/dist/test-resources/specs/UI5ElementShadowDOM.js +9 -9
  59. package/dist/test-resources/specs/UI5ElementSlots.js +9 -9
  60. package/dist/theming/CustomStyle.js +23 -3
  61. package/dist/theming/applyTheme.js +5 -8
  62. package/dist/theming/getEffectiveLinksHrefs.js +20 -0
  63. package/dist/theming/getStylesString.js +4 -2
  64. package/dist/theming/getThemeDesignerTheme.js +2 -1
  65. package/dist/theming/preloadLinks.js +23 -0
  66. package/dist/types/DataType.js +12 -0
  67. package/dist/types/Float.js +4 -0
  68. package/dist/types/Integer.js +4 -0
  69. package/dist/types/InvisibleMessageMode.js +30 -0
  70. package/dist/updateShadowRoot.js +8 -4
  71. package/dist/util/AriaLabelHelper.js +4 -4
  72. package/dist/util/FocusableElements.js +5 -1
  73. package/dist/util/HTMLSanitizer.js +7 -0
  74. package/dist/util/InvisibleMessage.js +58 -0
  75. package/dist/util/PopupUtils.js +1 -1
  76. package/dist/util/TabbableElements.js +1 -1
  77. package/dist/util/createLinkInHead.js +19 -0
  78. package/dist/util/encodeXML.js +35 -0
  79. package/dist/util/escapeRegex.js +10 -0
  80. package/dist/util/generateHighlightedMarkup.js +42 -0
  81. package/dist/util/getClassCopy.js +7 -2
  82. package/dist/util/isNodeTabbable.js +4 -4
  83. package/hash.txt +1 -1
  84. package/index.js +1 -1
  85. package/lib/generate-asset-parameters/index.js +0 -1
  86. package/lib/generate-styles/index.js +18 -0
  87. package/package-scripts.js +25 -3
  88. package/package.json +17 -9
  89. package/src/CSP.js +59 -0
  90. package/src/Device.js +7 -0
  91. package/src/EventProvider.js +19 -25
  92. package/src/FontFace.js +7 -95
  93. package/src/InitialConfiguration.js +31 -14
  94. package/src/Keys.js +15 -0
  95. package/src/ManagedStyles.js +83 -0
  96. package/src/Render.js +3 -1
  97. package/src/StaticAreaItem.js +11 -9
  98. package/src/SystemCSSVars.js +4 -25
  99. package/src/UI5Element.js +46 -60
  100. package/src/UI5ElementMetadata.js +9 -1
  101. package/src/asset-registries/Icons.js +29 -8
  102. package/src/asset-registries/Illustrations.js +30 -0
  103. package/src/asset-registries/LocaleData.js +11 -2
  104. package/src/assets-meta/IconCollectionsAlias.js +18 -0
  105. package/src/config/Theme.js +14 -0
  106. package/src/css/FontFace.css +45 -0
  107. package/src/css/OverrideFontFace.css +32 -0
  108. package/src/css/SystemCSSVars.css +17 -0
  109. package/src/delegate/ItemNavigation.js +66 -0
  110. package/src/delegate/ScrollEnablement.js +7 -1
  111. package/src/i18nBundle.js +33 -2
  112. package/src/renderer/LitRenderer.js +24 -21
  113. package/src/renderer/directives/style-map.js +72 -0
  114. package/src/theming/CustomStyle.js +23 -3
  115. package/src/theming/applyTheme.js +5 -8
  116. package/src/theming/getEffectiveLinksHrefs.js +20 -0
  117. package/src/theming/getStylesString.js +4 -2
  118. package/src/theming/getThemeDesignerTheme.js +2 -1
  119. package/src/theming/preloadLinks.js +23 -0
  120. package/src/types/DataType.js +12 -0
  121. package/src/types/Float.js +4 -0
  122. package/src/types/Integer.js +4 -0
  123. package/src/types/InvisibleMessageMode.js +30 -0
  124. package/src/updateShadowRoot.js +8 -4
  125. package/src/util/AriaLabelHelper.js +4 -4
  126. package/src/util/FocusableElements.js +5 -1
  127. package/src/util/HTMLSanitizer.js +7 -0
  128. package/src/util/InvisibleMessage.js +58 -0
  129. package/src/util/PopupUtils.js +1 -1
  130. package/src/util/TabbableElements.js +1 -1
  131. package/src/util/createLinkInHead.js +19 -0
  132. package/src/util/encodeXML.js +35 -0
  133. package/src/util/escapeRegex.js +10 -0
  134. package/src/util/generateHighlightedMarkup.js +42 -0
  135. package/src/util/getClassCopy.js +7 -2
  136. package/src/util/isNodeTabbable.js +4 -4
  137. package/used-modules.txt +7 -0
  138. package/dist/config/AssetsPath.js +0 -17
  139. package/dist/renderer/ifDefined.js +0 -21
  140. package/dist/renderer/scopeHTML.js +0 -32
  141. package/dist/theming/createThemePropertiesStyleTag.js +0 -20
  142. package/src/config/AssetsPath.js +0 -17
  143. package/src/renderer/ifDefined.js +0 -21
  144. package/src/renderer/scopeHTML.js +0 -32
  145. package/src/theming/createThemePropertiesStyleTag.js +0 -20
package/src/i18nBundle.js CHANGED
@@ -3,6 +3,8 @@ import formatMessage from "./util/formatMessage.js";
3
3
 
4
4
  const I18nBundleInstances = new Map();
5
5
 
6
+ let customGetI18nBundle;
7
+
6
8
  /**
7
9
  * @class
8
10
  * @public
@@ -15,6 +17,7 @@ class I18nBundle {
15
17
  /**
16
18
  * Returns a text in the currently loaded language
17
19
  *
20
+ * @public
18
21
  * @param {Object|String} textObj key/defaultText pair or just the key
19
22
  * @param params Values for the placeholders
20
23
  * @returns {*}
@@ -38,7 +41,7 @@ class I18nBundle {
38
41
  }
39
42
  }
40
43
 
41
- const getI18nBundle = packageName => {
44
+ const getI18nBundleSync = packageName => {
42
45
  if (I18nBundleInstances.has(packageName)) {
43
46
  return I18nBundleInstances.get(packageName);
44
47
  }
@@ -48,8 +51,36 @@ const getI18nBundle = packageName => {
48
51
  return i18nBundle;
49
52
  };
50
53
 
54
+ /**
55
+ * Allows developers to provide a custom getI18nBundle implementation
56
+ * If this function is called, the custom implementation will be used for all components and will completely
57
+ * replace the default implementation.
58
+ *
59
+ * @public
60
+ * @param customGet the function to use instead of the standard getI18nBundle implementation
61
+ */
62
+ const registerCustomI18nBundleGetter = customGet => {
63
+ customGetI18nBundle = customGet;
64
+ };
65
+
66
+ /**
67
+ * Fetches and returns the I18nBundle instance for the given package
68
+ *
69
+ * @public
70
+ * @param packageName
71
+ * @returns {Promise<I18nBundle>}
72
+ */
73
+ const getI18nBundle = async packageName => {
74
+ if (customGetI18nBundle) {
75
+ return customGetI18nBundle(packageName);
76
+ }
77
+
78
+ await fetchI18nBundle(packageName);
79
+ return getI18nBundleSync(packageName);
80
+ };
81
+
51
82
  export {
52
83
  registerI18nLoader,
53
- fetchI18nBundle,
54
84
  getI18nBundle,
85
+ registerCustomI18nBundleGetter,
55
86
  };
@@ -1,31 +1,34 @@
1
- import { html, svg, render } from "lit-html/lit-html.js";
2
- import scopeHTML from "./scopeHTML.js";
1
+ import { render } from "lit-html";
2
+ import {
3
+ html,
4
+ svg,
5
+ unsafeStatic,
6
+ } from "lit-html/static.js";
3
7
 
4
- let tags;
5
- let suffix;
6
-
7
- const setTags = t => {
8
- tags = t;
9
- };
10
- const setSuffix = s => {
11
- suffix = s;
12
- };
13
-
14
- const litRender = (templateResult, domNode, styles, { eventContext } = {}) => {
15
- if (styles) {
16
- templateResult = html`<style>${styles}</style>${templateResult}`;
8
+ const litRender = (templateResult, domNode, styleStrOrHrefsArr, { host } = {}) => {
9
+ if (typeof styleStrOrHrefsArr === "string") {
10
+ templateResult = html`<style>${styleStrOrHrefsArr}</style>${templateResult}`;
11
+ } else if (Array.isArray(styleStrOrHrefsArr) && styleStrOrHrefsArr.length) {
12
+ templateResult = html`${styleStrOrHrefsArr.map(href => html`<link type="text/css" rel="stylesheet" href="${href}">`)}${templateResult}`;
17
13
  }
18
- render(templateResult, domNode, { eventContext });
14
+ render(templateResult, domNode, { host });
19
15
  };
20
16
 
21
- const scopedHtml = (strings, ...values) => html(scopeHTML(strings, tags, suffix), ...values);
22
- const scopedSvg = (strings, ...values) => svg(scopeHTML(strings, tags, suffix), ...values);
17
+ const scopeTag = (tag, tags, suffix) => {
18
+ const resultTag = suffix && (tags || []).includes(tag) ? `${tag}-${suffix}` : tag;
19
+ return unsafeStatic(resultTag);
20
+ };
23
21
 
24
- export { setTags, setSuffix };
25
- export { scopedHtml as html, scopedSvg as svg };
22
+ export {
23
+ html,
24
+ svg,
25
+ unsafeStatic,
26
+ };
27
+ export { scopeTag };
26
28
  export { repeat } from "lit-html/directives/repeat.js";
27
29
  export { classMap } from "lit-html/directives/class-map.js";
28
- export { styleMap } from "lit-html/directives/style-map.js";
30
+ export { styleMap } from "./directives/style-map.js";
31
+ export { ifDefined } from "lit-html/directives/if-defined.js";
29
32
  export { unsafeHTML } from "lit-html/directives/unsafe-html.js";
30
33
 
31
34
  export default litRender;
@@ -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
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,14 +17,33 @@ 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);
37
+
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
+ }
27
47
 
28
48
  return reRenderAllUI5Elements({ tag });
29
49
  };
@@ -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
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();
@@ -17,14 +17,11 @@ const loadThemeBase = async theme => {
17
17
  }
18
18
 
19
19
  const cssText = await getThemeProperties(BASE_THEME_PACKAGE, theme);
20
- createThemePropertiesStyleTag(cssText, BASE_THEME_PACKAGE);
20
+ createOrUpdateStyle(cssText, "data-ui5-theme-properties", BASE_THEME_PACKAGE);
21
21
  };
22
22
 
23
23
  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
- }
24
+ removeStyle("data-ui5-theme-properties", BASE_THEME_PACKAGE);
28
25
  };
29
26
 
30
27
  const loadComponentPackages = async theme => {
@@ -35,7 +32,7 @@ const loadComponentPackages = async theme => {
35
32
  }
36
33
 
37
34
  const cssText = await getThemeProperties(packageName, theme);
38
- createThemePropertiesStyleTag(cssText, packageName);
35
+ createOrUpdateStyle(cssText, "data-ui5-theme-properties", packageName);
39
36
  });
40
37
  };
41
38
 
@@ -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;
@@ -1,9 +1,11 @@
1
1
  const getStylesString = styles => {
2
2
  if (Array.isArray(styles)) {
3
- return flatten(styles.filter(style => !!style)).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,6 +1,6 @@
1
1
  const getThemeMetadata = () => {
2
2
  // 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");
3
+ let el = document.querySelector(".sapThemeMetaData-Base-baseLib") || document.querySelector(".sapThemeMetaData-UI5-sap-ui-core");
4
4
  if (el) {
5
5
  return getComputedStyle(el).backgroundImage;
6
6
  }
@@ -8,6 +8,7 @@ const getThemeMetadata = () => {
8
8
  el = document.createElement("span");
9
9
  el.style.display = "none";
10
10
  el.classList.add("sapThemeMetaData-Base-baseLib");
11
+ el.classList.add("sapThemeMetaData-UI5-sap-ui-core");
11
12
  document.body.appendChild(el);
12
13
  const metadata = getComputedStyle(el).backgroundImage;
13
14
  document.body.removeChild(el);
@@ -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;
@@ -11,6 +11,18 @@ class DataType {
11
11
  static isValid(value) {
12
12
  }
13
13
 
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
+
14
26
  static generateTypeAccessors(types) {
15
27
  Object.keys(types).forEach(type => {
16
28
  Object.defineProperty(this, type, {
@@ -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;
@@ -1,7 +1,9 @@
1
1
  import executeTemplate from "./renderer/executeTemplate.js";
2
2
  import getConstructableStyle from "./theming/getConstructableStyle.js";
3
3
  import getEffectiveStyle from "./theming/getEffectiveStyle.js";
4
+ import getEffectiveLinksHrefs from "./theming/getEffectiveLinksHrefs.js";
4
5
  import isLegacyBrowser from "./isLegacyBrowser.js";
6
+ import { shouldUseLinks } from "./CSP.js";
5
7
 
6
8
  /**
7
9
  * Updates the shadow root of a UI5Element or its static area item
@@ -9,18 +11,20 @@ import isLegacyBrowser from "./isLegacyBrowser.js";
9
11
  * @param forStaticArea
10
12
  */
11
13
  const updateShadowRoot = (element, forStaticArea = false) => {
12
- let styleToPrepend;
14
+ let styleStrOrHrefsArr;
13
15
  const template = forStaticArea ? "staticAreaTemplate" : "template";
14
16
  const shadowRoot = forStaticArea ? element.staticAreaItem.shadowRoot : element.shadowRoot;
15
17
  const renderResult = executeTemplate(element.constructor[template], element);
16
18
 
17
- if (document.adoptedStyleSheets) { // Chrome
19
+ if (shouldUseLinks()) {
20
+ styleStrOrHrefsArr = getEffectiveLinksHrefs(element.constructor, forStaticArea);
21
+ } else if (document.adoptedStyleSheets) { // Chrome
18
22
  shadowRoot.adoptedStyleSheets = getConstructableStyle(element.constructor, forStaticArea);
19
23
  } else if (!isLegacyBrowser()) { // FF, Safari
20
- styleToPrepend = getEffectiveStyle(element.constructor, forStaticArea);
24
+ styleStrOrHrefsArr = getEffectiveStyle(element.constructor, forStaticArea);
21
25
  }
22
26
 
23
- element.constructor.render(renderResult, shadowRoot, styleToPrepend, { eventContext: element });
27
+ element.constructor.render(renderResult, shadowRoot, styleStrOrHrefsArr, { host: element });
24
28
  };
25
29
 
26
30
  export default updateShadowRoot;
@@ -1,9 +1,9 @@
1
1
  import findNodeOwner from "./findNodeOwner.js";
2
2
 
3
3
  const getEffectiveAriaLabelText = el => {
4
- if (!el.ariaLabelledby) {
5
- if (el.ariaLabel) {
6
- return el.ariaLabel;
4
+ if (!el.accessibleNameRef) {
5
+ if (el.accessibleName) {
6
+ return el.accessibleName;
7
7
  }
8
8
 
9
9
  return undefined;
@@ -19,7 +19,7 @@ const getEffectiveAriaLabelText = el => {
19
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
20
  */
21
21
  const getAriaLabelledByTexts = (el, ownerDocument, readyIds = "") => {
22
- const ids = (readyIds && readyIds.split(" ")) || el.ariaLabelledby.split(" ");
22
+ const ids = (readyIds && readyIds.split(" ")) || el.accessibleNameRef.split(" ");
23
23
  const owner = ownerDocument || findNodeOwner(el);
24
24
  let result = "";
25
25
 
@@ -21,6 +21,10 @@ const getLastFocusableElement = async container => {
21
21
  return findFocusableElement(container, false);
22
22
  };
23
23
 
24
+ const isElemFocusable = el => {
25
+ return el.hasAttribute("data-ui5-focus-redirect") || !isNodeHidden(el);
26
+ };
27
+
24
28
  const findFocusableElement = async (container, forward) => {
25
29
  let child;
26
30
 
@@ -48,7 +52,7 @@ const findFocusableElement = async (container, forward) => {
48
52
  return null;
49
53
  }
50
54
 
51
- if (child.nodeType === 1 && !isNodeHidden(child) && !isFocusTrap(child)) {
55
+ if (child.nodeType === 1 && isElemFocusable(child) && !isFocusTrap(child)) {
52
56
  if (isNodeClickable(child)) {
53
57
  return (child && typeof child.focus === "function") ? child : null;
54
58
  }
@@ -0,0 +1,7 @@
1
+ import sanitizeHTML from "../sap/base/security/sanitizeHTML.js";
2
+ import URLListValidator from "../sap/base/security/URLListValidator.js";
3
+
4
+ export {
5
+ URLListValidator,
6
+ sanitizeHTML,
7
+ };
@@ -0,0 +1,58 @@
1
+ import InvisibleMessageMode from "../types/InvisibleMessageMode.js";
2
+ import getSingletonElementInstance from "./getSingletonElementInstance.js";
3
+ import { attachBoot } from "../Boot.js";
4
+
5
+ let politeSpan;
6
+ let assertiveSpan;
7
+
8
+ attachBoot(() => {
9
+ if (politeSpan && assertiveSpan) {
10
+ return;
11
+ }
12
+
13
+ const styles = `position: absolute;
14
+ clip: rect(1px,1px,1px,1px);
15
+ user-select: none;
16
+ left: -1000px;
17
+ top: -1000px;
18
+ pointer-events: none;`;
19
+
20
+ politeSpan = document.createElement("span");
21
+ assertiveSpan = document.createElement("span");
22
+
23
+ politeSpan.classList.add("ui5-invisiblemessage-polite");
24
+ assertiveSpan.classList.add("ui5-invisiblemessage-assertive");
25
+
26
+ politeSpan.setAttribute("aria-live", "polite");
27
+ assertiveSpan.setAttribute("aria-live", "assertive");
28
+
29
+ politeSpan.setAttribute("role", "alert");
30
+ assertiveSpan.setAttribute("role", "alert");
31
+
32
+ politeSpan.style.cssText = styles;
33
+ assertiveSpan.style.cssText = styles;
34
+
35
+ getSingletonElementInstance("ui5-static-area").appendChild(politeSpan);
36
+ getSingletonElementInstance("ui5-static-area").appendChild(assertiveSpan);
37
+ });
38
+
39
+ /**
40
+ * Inserts the string into the respective span, depending on the mode provided.
41
+ *
42
+ * @param {string} message String to be announced by the screen reader.
43
+ * @param {sap.ui.core.InvisibleMessageMode} mode The mode to be inserted in the aria-live attribute.
44
+ */
45
+ const announce = (message, mode) => {
46
+ // If no type is presented, fallback to polite announcement.
47
+ const span = mode === InvisibleMessageMode.Assertive ? assertiveSpan : politeSpan;
48
+
49
+ // Set textContent to empty string in order to trigger screen reader's announcement.
50
+ span.textContent = "";
51
+ span.textContent = message;
52
+
53
+ if (mode !== InvisibleMessageMode.Assertive && mode !== InvisibleMessageMode.Polite) {
54
+ console.warn(`You have entered an invalid mode. Valid values are: "Polite" and "Assertive". The framework will automatically set the mode to "Polite".`); // eslint-disable-line
55
+ }
56
+ };
57
+
58
+ export default announce;
@@ -62,7 +62,7 @@ const isClickInRect = (event, rect) => {
62
62
  const getClosedPopupParent = el => {
63
63
  const parent = el.parentElement || (el.getRootNode && el.getRootNode().host);
64
64
 
65
- if (parent && ((parent.openBy && parent.isUI5Element) || (parent.open && parent.isUI5Element) || parent === document.documentElement)) {
65
+ if (parent && ((parent.showAt && parent.isUI5Element) || (parent.open && parent.isUI5Element) || parent === document.documentElement)) {
66
66
  return parent;
67
67
  }
68
68
 
@@ -17,7 +17,7 @@ const getTabbables = (nodes, tabbables) => {
17
17
  }
18
18
 
19
19
  Array.from(nodes).forEach(currentNode => {
20
- if (currentNode.nodeType === Node.TEXT_NODE || currentNode.nodeType === Node.COMMENT_NODE) {
20
+ if (currentNode.nodeType === Node.TEXT_NODE || currentNode.nodeType === Node.COMMENT_NODE || currentNode.hasAttribute("data-sap-no-tab-ref")) {
21
21
  return;
22
22
  }
23
23
 
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Creates a <link> tag in the <head> tag
3
+ * @param href - the CSS
4
+ * @param attributes - optional attributes to add to the tag
5
+ * @returns {HTMLElement}
6
+ */
7
+ const createLinkInHead = (href, attributes = {}) => {
8
+ const link = document.createElement("link");
9
+ link.type = "text/css";
10
+ link.rel = "stylesheet";
11
+
12
+ Object.entries(attributes).forEach(pair => link.setAttribute(...pair));
13
+
14
+ link.href = href;
15
+ document.head.appendChild(link);
16
+ return link;
17
+ };
18
+
19
+ export default createLinkInHead;
@@ -0,0 +1,35 @@
1
+ const fnToHex = (iChar, iLength) => {
2
+ let sHex = iChar.toString(16);
3
+ if (iLength) {
4
+ sHex = sHex.padStart(iLength, "0");
5
+ }
6
+ return sHex;
7
+ };
8
+
9
+ const rHtml = /[\x00-\x2b\x2f\x3a-\x40\x5b-\x5e\x60\x7b-\xff\u2028\u2029]/g, // eslint-disable-line no-control-regex
10
+ rHtmlReplace = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f]/, // eslint-disable-line no-control-regex
11
+ mHtmlLookup = {
12
+ "<": "&lt;",
13
+ ">": "&gt;",
14
+ "&": "&amp;",
15
+ "\"": "&quot;",
16
+ };
17
+
18
+ const fnHtml = sChar => {
19
+ let sEncoded = mHtmlLookup[sChar];
20
+ if (!sEncoded) {
21
+ if (rHtmlReplace.test(sChar)) {
22
+ sEncoded = "&#xfffd;";
23
+ } else {
24
+ sEncoded = `&#x${fnToHex(sChar.charCodeAt(0))};`;
25
+ }
26
+ mHtmlLookup[sChar] = sEncoded;
27
+ }
28
+ return sEncoded;
29
+ };
30
+
31
+ const fnEncodeXML = sString => {
32
+ return sString.replace(rHtml, fnHtml);
33
+ };
34
+
35
+ export default fnEncodeXML;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Escape a regular expression text so that it can be used in a regular expression.
3
+ * @param {string} text The string to be interpreted literally
4
+ * @returns Regular expression string to pass to regex
5
+ */
6
+ function escapeRegex(text) {
7
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
8
+ }
9
+
10
+ export default escapeRegex;