@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
@@ -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;
@@ -0,0 +1,42 @@
1
+ import escapeRegex from "./escapeRegex.js";
2
+ import encodeXML from "./encodeXML.js";
3
+
4
+ // utility to replace all occurances of a string
5
+ function replaceAll(text, find, replace, caseInsensitive) {
6
+ return text.replace(new RegExp(escapeRegex(find), `${caseInsensitive ? "i" : ""}g`), replace);
7
+ }
8
+
9
+ /**
10
+ * Generate markup for a raw string where a particular text is wrapped with some tag, by default `<b>` (bold) tag.
11
+ * All inputs to this function are considered literal text, and special characters will always be escaped.
12
+ * @param {string} text The text to add highlighting to
13
+ * @param {string} textToHighlight The text which should be highlighted
14
+ * @return {string} the markup HTML which contains all occurrances of the input text surrounded with a `<b>` tag.
15
+ */
16
+ function generateHighlightedMarkup(text, textToHighlight) {
17
+ if (!text || !textToHighlight) {
18
+ return text;
19
+ }
20
+ // a token is some string that does not appear in either of the input strings
21
+ // repeat the token until it does not appear in the string
22
+ const makeToken = t => {
23
+ const [s, e] = t.split("");
24
+ while (text.indexOf(t) >= 0 || textToHighlight.indexOf(t) >= 0) {
25
+ t = `${s}${t}${e}`;
26
+ }
27
+ return t;
28
+ };
29
+ // It doesn't matter what characters are used as long as all 4 of them are unique
30
+ // And also that encodeXML will not change these characters
31
+ const openToken = makeToken("12");
32
+ const closeToken = makeToken("34");
33
+ // wrap every occurance of the textToHighlight using the open/close tokens (instead of markup at this point)
34
+ let result = encodeXML(replaceAll(text, textToHighlight, match => `${openToken}${match}${closeToken}`, true));
35
+ // now replace the open and close tokens with the markup that we expect
36
+ [[openToken, "<b>"], [closeToken, "</b>"]].forEach(([find, replace]) => {
37
+ result = replaceAll(result, find, replace);
38
+ });
39
+ return result;
40
+ }
41
+
42
+ export default generateHighlightedMarkup;
@@ -1,5 +1,10 @@
1
- const getClassCopy = klass => {
2
- return class classCopy extends klass {};
1
+ const getClassCopy = (klass, constructorCallback) => {
2
+ return class classCopy extends klass {
3
+ constructor() {
4
+ super();
5
+ constructorCallback && constructorCallback();
6
+ }
7
+ };
3
8
  };
4
9
 
5
10
  export default getClassCopy;
@@ -15,14 +15,14 @@ const isNodeTabbable = node => {
15
15
  return false;
16
16
  }
17
17
 
18
- if (nodeName === "a" || /input|select|textarea|button|object/.test(nodeName)) {
19
- return !node.disabled;
20
- }
21
-
22
18
  const tabIndex = node.getAttribute("tabindex");
23
19
  if (tabIndex !== null && tabIndex !== undefined) {
24
20
  return parseInt(tabIndex) >= 0;
25
21
  }
22
+
23
+ if (nodeName === "a" || /input|select|textarea|button|object/.test(nodeName)) {
24
+ return !node.disabled;
25
+ }
26
26
  };
27
27
 
28
28
  export default isNodeTabbable;
package/hash.txt CHANGED
@@ -1 +1 @@
1
- EpEv8ewlNPY90ULIm8etkaS9plo=
1
+ lG/1T57aPULqB5ErWOkk2B0Pejk=
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import UI5Element from "./src/UI5Element.js";
1
+ import UI5Element from "./dist/UI5Element.js";
2
2
 
3
3
  export default UI5Element;
4
4
  export { UI5Element };
@@ -1,5 +1,4 @@
1
1
  const fs = require('fs');
2
- const path = require('path');
3
2
  const mkdirp = require('mkdirp');
4
3
  const assets = require('@ui5/webcomponents-tools/assets-meta.js');
5
4
 
@@ -0,0 +1,18 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const mkdirp = require('mkdirp');
4
+ const CleanCSS = require('clean-css');
5
+
6
+ mkdirp.sync("dist/generated/css/");
7
+ fs.readdirSync("src/css/").filter(file => file.endsWith(".css")).forEach(file => {
8
+ let content = fs.readFileSync(path.join("src/css/", file));
9
+ const res = new CleanCSS().minify(`${content}`);
10
+ content = `export default {
11
+ packageName: "@ui5/webcomponents-base",
12
+ fileName: "${file}",
13
+ content: \`${res.styles}\`
14
+ };`;
15
+
16
+ fs.writeFileSync(path.join("dist/generated/css/", `${file}.js`), content);
17
+ });
18
+
@@ -1,30 +1,52 @@
1
1
  const resolve = require("resolve");
2
2
 
3
3
  const assetParametersScript = resolve.sync("@ui5/webcomponents-base/lib/generate-asset-parameters/index.js");
4
+ const stylesScript = resolve.sync("@ui5/webcomponents-base/lib/generate-styles/index.js");
4
5
  const serve = resolve.sync("@ui5/webcomponents-tools/lib/serve/index.js");
5
6
  const generateHash = resolve.sync("@ui5/webcomponents-tools/lib/hash/generate.js");
6
7
  const hashIsUpToDate = resolve.sync("@ui5/webcomponents-tools/lib/hash/upToDate.js");
8
+ const copyUsedModules = resolve.sync("@ui5/webcomponents-tools/lib/copy-list/index.js");
9
+ const replaceGlobalCore = resolve.sync("@ui5/webcomponents-tools/lib/replace-global-core/index.js");
10
+ const esmAbsToRel = resolve.sync("@ui5/webcomponents-tools/lib/esm-abs-to-rel/index.js");
7
11
  const UP_TO_DATE = `node "${hashIsUpToDate}" dist/ hash.txt && echo "Up to date."`;
8
12
 
9
13
  const scripts = {
10
14
  clean: "rimraf dist && rimraf .port",
11
15
  lint: "eslint . --config config/.eslintrc.js",
12
- prepare: "nps clean copy generateAssetParameters",
16
+ prepare: "nps clean integrate copy generateAssetParameters generateStyles",
17
+ integrate: {
18
+ default: "nps integrate.copy-used-modules integrate.copy-overlay integrate.replace-amd integrate.replace-export-true integrate.replace-export-false integrate.amd-to-es6 integrate.replace-global-core-usage integrate.esm-abs-to-rel integrate.third-party",
19
+ "copy-used-modules": `node "${copyUsedModules}" ./used-modules.txt dist/`,
20
+ "copy-overlay": `copy-and-watch "overlay/**/*.js" dist/`,
21
+ "replace-amd": "replace-in-file sap.ui.define define dist/**/*.js",
22
+ "replace-export-true": `replace-in-file ", /* bExport= */ true" "" dist/**/*.js`,
23
+ "replace-export-false": `replace-in-file ", /* bExport= */ false" "" dist/**/*.js`,
24
+ "amd-to-es6": "amdtoes6 --src=dist/ --replace --glob=**/*.js",
25
+ "replace-global-core-usage": `node "${replaceGlobalCore}" dist/`,
26
+ "esm-abs-to-rel": `node "${esmAbsToRel}" dist/ dist/`,
27
+ "third-party": {
28
+ default: "nps integrate.third-party.copy integrate.third-party.fix",
29
+ copy: "mkdirp dist/sap/ui/thirdparty/ && copy-and-watch ../../node_modules/@openui5/sap.ui.core/src/sap/ui/thirdparty/caja-html-sanitizer.js dist/sap/ui/thirdparty/",
30
+ fix: "replace-in-file 240 xA0 dist/sap/ui/thirdparty/caja-html-sanitizer.js"
31
+ },
32
+ },
13
33
  build: {
14
34
  default: `${UP_TO_DATE} || nps lint prepare build.bundle hash`,
15
35
  bundle: "rollup --config config/rollup.config.js",
16
36
  },
17
37
  copy: {
18
38
  default: "nps copy.src copy.test",
19
- src: `copy-and-watch "src/**/*.js" dist/`,
39
+ src: `copy-and-watch "src/**/*.{js,css}" dist/`,
20
40
  test: `copy-and-watch "test/**/*.*" dist/test-resources`,
21
41
  },
22
42
  generateAssetParameters: `node "${assetParametersScript}"`,
43
+ generateStyles: `node "${stylesScript}"`,
23
44
  watch: {
24
- default: 'concurrently "nps watch.test" "nps watch.src" "nps watch.bundle"',
45
+ default: 'concurrently "nps watch.test" "nps watch.src" "nps watch.bundle" "nps watch.styles"',
25
46
  src: 'nps "copy.src --watch --skip-initial-copy"',
26
47
  test: 'nps "copy.test --watch --skip-initial-copy"',
27
48
  bundle: "rollup --config config/rollup.config.js -w --environment DEV",
49
+ styles: 'chokidar "src/css/*.css" -c "nps generateStyles"'
28
50
  },
29
51
  dev: 'concurrently "nps serve" "nps watch"',
30
52
  start: "nps prepare dev",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui5/webcomponents-base",
3
- "version": "0.34.0",
3
+ "version": "1.0.1",
4
4
  "description": "UI5 Web Components: webcomponents.base",
5
5
  "author": "SAP SE (https://www.sap.com)",
6
6
  "license": "Apache-2.0",
@@ -15,6 +15,13 @@
15
15
  "url": "https://github.com/SAP/ui5-webcomponents.git",
16
16
  "directory": "packages/base"
17
17
  },
18
+ "exports": {
19
+ ".": "./index.js",
20
+ "./dist/*": "./dist/*",
21
+ "./package.json": "./package.json",
22
+ "./bundle.esm.js": "./bundle.esm.js",
23
+ "./*": "./dist/*"
24
+ },
18
25
  "scripts": {
19
26
  "clean": "nps clean",
20
27
  "lint": "nps lint",
@@ -25,16 +32,17 @@
25
32
  "prepublishOnly": "npm run clean && npm run build"
26
33
  },
27
34
  "dependencies": {
28
- "lit-html": "^1.3.0"
35
+ "lit-html": "2.0.1"
29
36
  },
30
37
  "devDependencies": {
31
- "@ui5/webcomponents-tools": "1.0.0-rc.14",
32
- "array-uniq": "^2.0.0",
33
- "chromedriver": "89.0.0",
38
+ "@buxlabs/amd-to-es6": "0.16.1",
39
+ "@openui5/sap.ui.core": "1.94.0",
40
+ "@ui5/webcomponents-tools": "1.0.1",
41
+ "chromedriver": "95.0.0",
42
+ "clean-css": "^5.2.2",
34
43
  "copy-and-watch": "^0.1.5",
35
44
  "eslint": "^7.22.0",
36
- "eslint-config-airbnb-base": "^14.2.1",
37
- "npm-run-all": "^4.1.5",
38
- "path-exists-cli": "^1.0.0"
45
+ "mkdirp": "^1.0.4",
46
+ "resolve": "^1.20.0"
39
47
  }
40
- }
48
+ }
package/src/CSP.js ADDED
@@ -0,0 +1,59 @@
1
+ const roots = new Map();
2
+ let useLinks = false;
3
+ let preloadLinks = true;
4
+
5
+ /**
6
+ * Use this function to provide the path to the directory where the css resources for the given package will be served from
7
+ *
8
+ * @public
9
+ * @param packageName name of the package that is being configured
10
+ * @param root path, accessible by the server that will serve the css resources
11
+ */
12
+ const setPackageCSSRoot = (packageName, root) => {
13
+ roots.set(packageName, root);
14
+ };
15
+
16
+ const getUrl = (packageName, path) => {
17
+ return `${roots.get(packageName)}${path}`;
18
+ };
19
+
20
+ /**
21
+ * Call this function to enable or disable the usage of <link> tags instead of <style> tags to achieve CSP compliance
22
+ * Example: "setUseLinks(true)" will unconditionally use <link> tags for all browsers;
23
+ * Example: "setUseLinks(!document.adoptedStyleSheets) will only enable the usage of <link> tags for browsers that do not support constructable stylesheets.
24
+ *
25
+ * @public
26
+ * @param use whether links will be used
27
+ */
28
+ const setUseLinks = use => {
29
+ useLinks = use;
30
+ };
31
+
32
+ /**
33
+ * Call this function to enable or disable the preloading of <link> tags.
34
+ * Note: only taken into account when <link> tags are being used.
35
+ * Note: links are being preloaded by default, so call "setPreloadLinks(false)" to opt out of this.
36
+ *
37
+ * @public
38
+ * @param preload
39
+ */
40
+ const setPreloadLinks = preload => {
41
+ preloadLinks = preload;
42
+ };
43
+
44
+ const shouldUseLinks = () => {
45
+ return useLinks;
46
+ };
47
+
48
+ const shouldPreloadLinks = () => {
49
+ return preloadLinks;
50
+ };
51
+
52
+ export {
53
+ setPackageCSSRoot,
54
+ getUrl,
55
+ setUseLinks,
56
+ setPreloadLinks,
57
+ shouldUseLinks,
58
+ shouldPreloadLinks,
59
+ };