@vaadin/vaadin-themable-mixin 25.0.0-alpha6 → 25.0.0-alpha7
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/lumo-injection-mixin.js +6 -0
- package/package.json +4 -4
- package/src/css-utils.js +9 -15
- package/src/lumo-injector.js +18 -5
package/lumo-injection-mixin.js
CHANGED
|
@@ -61,6 +61,12 @@ export const LumoInjectionMixin = (superClass) =>
|
|
|
61
61
|
return `--${this.is}-lumo-inject`;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
static get lumoInjector() {
|
|
65
|
+
return {
|
|
66
|
+
includeBaseStyles: false,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
64
70
|
/** @protected */
|
|
65
71
|
connectedCallback() {
|
|
66
72
|
super.connectedCallback();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/vaadin-themable-mixin",
|
|
3
|
-
"version": "25.0.0-
|
|
3
|
+
"version": "25.0.0-alpha7",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@polymer/polymer": "^3.0.0",
|
|
40
|
-
"@vaadin/chai-plugins": "25.0.0-
|
|
41
|
-
"@vaadin/test-runner-commands": "25.0.0-
|
|
40
|
+
"@vaadin/chai-plugins": "25.0.0-alpha7",
|
|
41
|
+
"@vaadin/test-runner-commands": "25.0.0-alpha7",
|
|
42
42
|
"@vaadin/testing-helpers": "^2.0.0",
|
|
43
43
|
"sinon": "^18.0.0"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "87f72707ce6866892f8be5782fa0da008e87dcbc"
|
|
46
46
|
}
|
package/src/css-utils.js
CHANGED
|
@@ -15,16 +15,14 @@ import { adoptStyles } from 'lit';
|
|
|
15
15
|
* @return {CSSStyleSheet[]}
|
|
16
16
|
*/
|
|
17
17
|
function getEffectiveStyles(component) {
|
|
18
|
-
const
|
|
18
|
+
const { baseStyles, themeStyles, elementStyles, lumoInjector } = component.constructor;
|
|
19
|
+
const lumoStyleSheet = component.__lumoStyleSheet;
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return (componentClass.baseStyles ?? componentClass.themeStyles)
|
|
23
|
-
? [...componentClass.baseStyles, styleSheet, ...componentClass.themeStyles]
|
|
24
|
-
: [styleSheet, ...componentClass.elementStyles];
|
|
21
|
+
if (lumoStyleSheet && (baseStyles || themeStyles)) {
|
|
22
|
+
return [...(lumoInjector.includeBaseStyles ? baseStyles : []), lumoStyleSheet, ...themeStyles];
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
return
|
|
25
|
+
return [lumoStyleSheet, ...elementStyles].filter(Boolean);
|
|
28
26
|
}
|
|
29
27
|
|
|
30
28
|
/**
|
|
@@ -47,7 +45,7 @@ export function applyInstanceStyles(component) {
|
|
|
47
45
|
*/
|
|
48
46
|
export function injectLumoStyleSheet(component, styleSheet) {
|
|
49
47
|
// Store the new stylesheet so that it can be removed later.
|
|
50
|
-
component.
|
|
48
|
+
component.__lumoStyleSheet = styleSheet;
|
|
51
49
|
applyInstanceStyles(component);
|
|
52
50
|
}
|
|
53
51
|
|
|
@@ -57,11 +55,7 @@ export function injectLumoStyleSheet(component, styleSheet) {
|
|
|
57
55
|
*
|
|
58
56
|
* @param {HTMLElement} component
|
|
59
57
|
*/
|
|
60
|
-
export function
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
component.shadowRoot.adoptedStyleSheets = adoptedStyleSheets;
|
|
66
|
-
component.__lumoInjectorStyleSheet = undefined;
|
|
58
|
+
export function removeLumoStyleSheet(component) {
|
|
59
|
+
component.__lumoStyleSheet = undefined;
|
|
60
|
+
applyInstanceStyles(component);
|
|
67
61
|
}
|
package/src/lumo-injector.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { CSSPropertyObserver } from './css-property-observer.js';
|
|
7
|
-
import {
|
|
7
|
+
import { injectLumoStyleSheet, removeLumoStyleSheet } from './css-utils.js';
|
|
8
8
|
import { parseStyleSheets } from './lumo-modules.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -77,6 +77,9 @@ export class LumoInjector {
|
|
|
77
77
|
/** @type {Map<string, CSSStyleSheet>} */
|
|
78
78
|
#styleSheetsByTag = new Map();
|
|
79
79
|
|
|
80
|
+
/** @type {Map<string, Set<HTMLElement>>} */
|
|
81
|
+
#componentsByTag = new Map();
|
|
82
|
+
|
|
80
83
|
constructor(root = document) {
|
|
81
84
|
this.#root = root;
|
|
82
85
|
this.#cssPropertyObserver = new CSSPropertyObserver(this.#root, 'vaadin-lumo-injector', (propertyName) => {
|
|
@@ -97,9 +100,8 @@ export class LumoInjector {
|
|
|
97
100
|
componentConnected(component) {
|
|
98
101
|
const { is: tagName, lumoInjectPropName } = component.constructor;
|
|
99
102
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
this.#styleSheetsByTag.set(tagName, stylesheet);
|
|
103
|
+
this.#componentsByTag.set(tagName, this.#componentsByTag.get(tagName) ?? new Set());
|
|
104
|
+
this.#componentsByTag.get(tagName).add(component);
|
|
103
105
|
|
|
104
106
|
this.#updateComponentStyleSheet(tagName);
|
|
105
107
|
|
|
@@ -113,7 +115,10 @@ export class LumoInjector {
|
|
|
113
115
|
* @param {HTMLElement} component
|
|
114
116
|
*/
|
|
115
117
|
componentDisconnected(component) {
|
|
116
|
-
|
|
118
|
+
const { is: tagName } = component.constructor;
|
|
119
|
+
this.#componentsByTag.get(tagName)?.delete(component);
|
|
120
|
+
|
|
121
|
+
removeLumoStyleSheet(component);
|
|
117
122
|
}
|
|
118
123
|
|
|
119
124
|
#updateComponentStyleSheet(tagName) {
|
|
@@ -127,6 +132,14 @@ export class LumoInjector {
|
|
|
127
132
|
const stylesheet = this.#styleSheetsByTag.get(tagName) ?? new CSSStyleSheet();
|
|
128
133
|
stylesheet.replaceSync(cssText);
|
|
129
134
|
this.#styleSheetsByTag.set(tagName, stylesheet);
|
|
135
|
+
|
|
136
|
+
this.#componentsByTag.get(tagName)?.forEach((component) => {
|
|
137
|
+
if (cssText) {
|
|
138
|
+
injectLumoStyleSheet(component, stylesheet);
|
|
139
|
+
} else {
|
|
140
|
+
removeLumoStyleSheet(component);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
130
143
|
}
|
|
131
144
|
|
|
132
145
|
get #rootStyleSheets() {
|