@ui5/webcomponents-base 0.0.0-11d529e8a → 0.0.0-1e08ebdef
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.
- package/.eslintignore +2 -1
- package/CHANGELOG.md +42 -0
- package/README.md +2 -3
- package/bundle.esm.js +1 -2
- package/dist/CSP.js +59 -0
- package/dist/Device.js +11 -0
- package/dist/FontFace.js +7 -95
- package/dist/InitialConfiguration.js +11 -0
- package/dist/ManagedStyles.js +83 -0
- package/dist/Render.js +3 -1
- package/dist/StaticAreaItem.js +0 -9
- package/dist/SystemCSSVars.js +4 -25
- package/dist/UI5Element.js +14 -21
- package/dist/UI5ElementMetadata.js +8 -0
- package/dist/asset-registries/Icons.js +25 -14
- package/dist/asset-registries/LocaleData.js +11 -2
- package/dist/assets-meta/IconCollectionsAlias.js +18 -0
- package/dist/config/Theme.js +14 -0
- package/dist/css/FontFace.css +45 -0
- package/dist/css/OverrideFontFace.css +32 -0
- package/dist/css/SystemCSSVars.css +17 -0
- package/dist/generated/AssetParameters.js +1 -1
- package/dist/generated/css/FontFace.css.js +5 -0
- package/dist/generated/css/OverrideFontFace.css.js +5 -0
- package/dist/generated/css/SystemCSSVars.css.js +5 -0
- package/dist/i18nBundle.js +32 -2
- package/dist/renderer/LitRenderer.js +6 -4
- package/dist/renderer/directives/style-map.js +72 -0
- package/dist/resources/bundle.esm.js +8 -8
- package/dist/resources/bundle.esm.js.map +1 -1
- package/dist/sap/base/security/encodeCSS.js +14 -0
- package/dist/sap/base/security/encodeXML.js +23 -0
- package/dist/sap/base/strings/toHex.js +8 -0
- package/dist/test-resources/pages/i18n.html +1 -3
- package/dist/test-resources/specs/CustomTheme.spec.js +2 -2
- package/dist/test-resources/specs/Theming.spec.js +4 -4
- package/dist/theming/CustomStyle.js +23 -3
- package/dist/theming/applyTheme.js +11 -10
- package/dist/theming/getEffectiveLinksHrefs.js +20 -0
- package/dist/theming/getStylesString.js +4 -2
- package/dist/theming/getThemeDesignerTheme.js +25 -5
- package/dist/theming/preloadLinks.js +23 -0
- package/dist/updateShadowRoot.js +8 -4
- package/dist/util/createLinkInHead.js +19 -0
- package/dist/util/escapeRegex.js +10 -0
- package/dist/util/generateHighlightedMarkup.js +42 -0
- package/hash.txt +1 -1
- package/lib/generate-asset-parameters/index.js +0 -1
- package/lib/generate-styles/index.js +18 -0
- package/package-scripts.js +6 -3
- package/package.json +8 -9
- package/src/CSP.js +59 -0
- package/src/Device.js +11 -0
- package/src/FontFace.js +7 -95
- package/src/InitialConfiguration.js +11 -0
- package/src/ManagedStyles.js +83 -0
- package/src/Render.js +3 -1
- package/src/StaticAreaItem.js +0 -9
- package/src/SystemCSSVars.js +4 -25
- package/src/UI5Element.js +14 -21
- package/src/UI5ElementMetadata.js +8 -0
- package/src/asset-registries/Icons.js +25 -14
- package/src/asset-registries/LocaleData.js +11 -2
- package/src/assets-meta/IconCollectionsAlias.js +18 -0
- package/src/config/Theme.js +14 -0
- package/src/css/FontFace.css +45 -0
- package/src/css/OverrideFontFace.css +32 -0
- package/src/css/SystemCSSVars.css +17 -0
- package/src/i18nBundle.js +32 -2
- package/src/renderer/LitRenderer.js +6 -4
- package/src/renderer/directives/style-map.js +72 -0
- package/src/theming/CustomStyle.js +23 -3
- package/src/theming/applyTheme.js +11 -10
- package/src/theming/getEffectiveLinksHrefs.js +20 -0
- package/src/theming/getStylesString.js +4 -2
- package/src/theming/getThemeDesignerTheme.js +25 -5
- package/src/theming/preloadLinks.js +23 -0
- package/src/updateShadowRoot.js +8 -4
- package/src/util/createLinkInHead.js +19 -0
- package/src/util/escapeRegex.js +10 -0
- package/src/util/generateHighlightedMarkup.js +42 -0
- package/used-modules.txt +4 -1
- package/dist/theming/createThemePropertiesStyleTag.js +0 -20
- package/dist/util/encodeCSS.js +0 -24
- package/src/theming/createThemePropertiesStyleTag.js +0 -20
- package/src/util/encodeCSS.js +0 -24
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
|
|
@@ -39,7 +41,7 @@ class I18nBundle {
|
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
const
|
|
44
|
+
const getI18nBundleSync = packageName => {
|
|
43
45
|
if (I18nBundleInstances.has(packageName)) {
|
|
44
46
|
return I18nBundleInstances.get(packageName);
|
|
45
47
|
}
|
|
@@ -49,8 +51,36 @@ const getI18nBundle = packageName => {
|
|
|
49
51
|
return i18nBundle;
|
|
50
52
|
};
|
|
51
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
|
+
|
|
52
82
|
export {
|
|
53
83
|
registerI18nLoader,
|
|
54
|
-
fetchI18nBundle,
|
|
55
84
|
getI18nBundle,
|
|
85
|
+
registerCustomI18nBundleGetter,
|
|
56
86
|
};
|
|
@@ -5,9 +5,11 @@ import {
|
|
|
5
5
|
unsafeStatic,
|
|
6
6
|
} from "lit-html/static.js";
|
|
7
7
|
|
|
8
|
-
const litRender = (templateResult, domNode,
|
|
9
|
-
if (
|
|
10
|
-
templateResult = html`<style>${
|
|
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}`;
|
|
11
13
|
}
|
|
12
14
|
render(templateResult, domNode, { host });
|
|
13
15
|
};
|
|
@@ -25,7 +27,7 @@ export {
|
|
|
25
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 "
|
|
30
|
+
export { styleMap } from "./directives/style-map.js";
|
|
29
31
|
export { ifDefined } from "lit-html/directives/if-defined.js";
|
|
30
32
|
export { unsafeHTML } from "lit-html/directives/unsafe-html.js";
|
|
31
33
|
|
|
@@ -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
|
-
|
|
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
|
|
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-
|
|
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
|
|
20
|
-
|
|
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
|
-
|
|
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
|
|
38
|
-
|
|
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
|
|
|
@@ -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)).
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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;
|
package/src/updateShadowRoot.js
CHANGED
|
@@ -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
|
|
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 (
|
|
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
|
-
|
|
24
|
+
styleStrOrHrefsArr = getEffectiveStyle(element.constructor, forStaticArea);
|
|
21
25
|
}
|
|
22
26
|
|
|
23
|
-
element.constructor.render(renderResult, shadowRoot,
|
|
27
|
+
element.constructor.render(renderResult, shadowRoot, styleStrOrHrefsArr, { host: element });
|
|
24
28
|
};
|
|
25
29
|
|
|
26
30
|
export default updateShadowRoot;
|
|
@@ -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,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 "../sap/base/security/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;
|
package/used-modules.txt
CHANGED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import createStyleInHead from "../util/createStyleInHead.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Creates/updates a style element holding all CSS Custom Properties
|
|
5
|
-
* @param cssText
|
|
6
|
-
* @param packageName
|
|
7
|
-
*/
|
|
8
|
-
const createThemePropertiesStyleTag = (cssText, packageName) => {
|
|
9
|
-
const styleElement = document.head.querySelector(`style[data-ui5-theme-properties="${packageName}"]`);
|
|
10
|
-
if (styleElement) {
|
|
11
|
-
styleElement.textContent = cssText || ""; // in case of undefined
|
|
12
|
-
} else {
|
|
13
|
-
const attributes = {
|
|
14
|
-
"data-ui5-theme-properties": packageName,
|
|
15
|
-
};
|
|
16
|
-
createStyleInHead(cssText, attributes);
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export default createThemePropertiesStyleTag;
|
package/dist/util/encodeCSS.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const rCSS = /[\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xff\u2028\u2029][0-9A-Fa-f]?/g; // eslint-disable-line
|
|
2
|
-
|
|
3
|
-
const toHex = (iChar, iLength) => {
|
|
4
|
-
let sHex = iChar.toString(16);
|
|
5
|
-
if (iLength) {
|
|
6
|
-
sHex = sHex.padStart(iLength, "0");
|
|
7
|
-
}
|
|
8
|
-
return sHex;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const fnCSS = sChar => {
|
|
12
|
-
const iChar = sChar.charCodeAt(0);
|
|
13
|
-
if (sChar.length === 1) {
|
|
14
|
-
return `\\${toHex(iChar)}`;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return `\\${toHex(iChar)} ${sChar.substr(1)}`;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const encodeCSS = string => {
|
|
21
|
-
return string.replace(rCSS, fnCSS);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export default encodeCSS;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import createStyleInHead from "../util/createStyleInHead.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Creates/updates a style element holding all CSS Custom Properties
|
|
5
|
-
* @param cssText
|
|
6
|
-
* @param packageName
|
|
7
|
-
*/
|
|
8
|
-
const createThemePropertiesStyleTag = (cssText, packageName) => {
|
|
9
|
-
const styleElement = document.head.querySelector(`style[data-ui5-theme-properties="${packageName}"]`);
|
|
10
|
-
if (styleElement) {
|
|
11
|
-
styleElement.textContent = cssText || ""; // in case of undefined
|
|
12
|
-
} else {
|
|
13
|
-
const attributes = {
|
|
14
|
-
"data-ui5-theme-properties": packageName,
|
|
15
|
-
};
|
|
16
|
-
createStyleInHead(cssText, attributes);
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export default createThemePropertiesStyleTag;
|
package/src/util/encodeCSS.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const rCSS = /[\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xff\u2028\u2029][0-9A-Fa-f]?/g; // eslint-disable-line
|
|
2
|
-
|
|
3
|
-
const toHex = (iChar, iLength) => {
|
|
4
|
-
let sHex = iChar.toString(16);
|
|
5
|
-
if (iLength) {
|
|
6
|
-
sHex = sHex.padStart(iLength, "0");
|
|
7
|
-
}
|
|
8
|
-
return sHex;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const fnCSS = sChar => {
|
|
12
|
-
const iChar = sChar.charCodeAt(0);
|
|
13
|
-
if (sChar.length === 1) {
|
|
14
|
-
return `\\${toHex(iChar)}`;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return `\\${toHex(iChar)} ${sChar.substr(1)}`;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const encodeCSS = string => {
|
|
21
|
-
return string.replace(rCSS, fnCSS);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export default encodeCSS;
|