@webtides/element-js 1.0.0-alpha.8 → 1.0.0-alpha.9
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/package.json
CHANGED
package/src/BaseElement.js
CHANGED
|
@@ -10,6 +10,7 @@ export { toString } from './util/toString.js';
|
|
|
10
10
|
* @typedef {Object} BaseElementOptions
|
|
11
11
|
* @property {boolean} [autoUpdate] - When set to true the element will call the requestUpdate() method on the instance every time a property or attribute was changed. This will re-evaluate everything on the element and trigger a re-render (if a template is provided) and trigger the watchers for the affected properties/attributes. Default is `true`
|
|
12
12
|
* @property {boolean} [deferUpdate] - When set to true the element will not call the requestUpdate() method upon connecting and therefore will not render (if template was provided) initially. Default is `true`
|
|
13
|
+
* @property {boolean} [deferConnected] - When set to true the element will skip the initialization in connectedCallback() before connecting and therefore will not render (if template was provided) or hydrate initially. Default is `false`
|
|
13
14
|
* @property {MutationObserverOptions} [mutationObserverOptions]
|
|
14
15
|
* @property {PropertyOptions} [propertyOptions]
|
|
15
16
|
*/
|
|
@@ -69,13 +70,6 @@ class BaseElement extends HTMLElement {
|
|
|
69
70
|
propertyOptions: {},
|
|
70
71
|
...options,
|
|
71
72
|
};
|
|
72
|
-
|
|
73
|
-
if (this.hasAttribute('defer-update')) {
|
|
74
|
-
this._options.deferUpdate = true;
|
|
75
|
-
}
|
|
76
|
-
if (this.hasAttribute('defer-connected')) {
|
|
77
|
-
this._options.deferConnected = true;
|
|
78
|
-
}
|
|
79
73
|
}
|
|
80
74
|
|
|
81
75
|
/**
|
|
@@ -84,8 +78,13 @@ class BaseElement extends HTMLElement {
|
|
|
84
78
|
* register observers, refs and events.
|
|
85
79
|
*/
|
|
86
80
|
connectedCallback() {
|
|
87
|
-
if (this.
|
|
81
|
+
if (this.hasAttribute('defer-update')) {
|
|
82
|
+
this._options.deferUpdate = true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (this.hasAttribute('defer-connected') || this._options.deferConnected) {
|
|
88
86
|
this._options.deferConnected = false;
|
|
87
|
+
this.removeAttribute('defer-connected');
|
|
89
88
|
return;
|
|
90
89
|
}
|
|
91
90
|
|
|
@@ -111,7 +110,7 @@ class BaseElement extends HTMLElement {
|
|
|
111
110
|
// define everything that should be observed
|
|
112
111
|
this.defineObserver();
|
|
113
112
|
|
|
114
|
-
if (this.
|
|
113
|
+
if (this._options.deferUpdate) {
|
|
115
114
|
// don't update/render, but register refs and events
|
|
116
115
|
this.registerEventsAndRefs();
|
|
117
116
|
|
package/src/StyledElement.js
CHANGED
|
@@ -92,7 +92,9 @@ class StyledElement extends BaseElement {
|
|
|
92
92
|
const parentDocument = getShadowParentOrBody(this.getRoot());
|
|
93
93
|
|
|
94
94
|
const adoptGlobalStyleSheets =
|
|
95
|
-
this._options.shadowRender &&
|
|
95
|
+
this._options.shadowRender &&
|
|
96
|
+
this._options.adoptGlobalStyles !== false &&
|
|
97
|
+
parentDocument !== globalThis.document.body;
|
|
96
98
|
|
|
97
99
|
const appendableStyles = [
|
|
98
100
|
...(adoptGlobalStyleSheets ? globalStylesStore.getGlobalStyleSheets(this._options.adoptGlobalStyles) : []),
|
package/src/TemplateElement.js
CHANGED
|
@@ -24,8 +24,15 @@ class TemplateElement extends StyledElement {
|
|
|
24
24
|
...options,
|
|
25
25
|
});
|
|
26
26
|
this._template = this._options.template;
|
|
27
|
+
}
|
|
27
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Overrides the native `connectedCallback` of the HTMLElement to set up and initialize our element.
|
|
31
|
+
* This will attach a shadow DOM if the element is supposed to render in shadow DOM.
|
|
32
|
+
*/
|
|
33
|
+
connectedCallback() {
|
|
28
34
|
if (this._options.shadowRender) this.attachShadow({ mode: 'open' });
|
|
35
|
+
super.connectedCallback();
|
|
29
36
|
}
|
|
30
37
|
|
|
31
38
|
/**
|
|
@@ -50,15 +50,11 @@ class GlobalStylesStore extends Store {
|
|
|
50
50
|
let cssStyleSheet = this.globalStyleSheetsCache.get(styleSheet.ownerNode);
|
|
51
51
|
if (!cssStyleSheet) {
|
|
52
52
|
cssStyleSheet = new CSSStyleSheet();
|
|
53
|
-
let cssText = '';
|
|
54
53
|
if (styleSheet.ownerNode.tagName === 'STYLE') {
|
|
55
|
-
|
|
54
|
+
cssStyleSheet.replaceSync(styleSheet.ownerNode.textContent);
|
|
56
55
|
} else if (styleSheet.ownerNode.tagName === 'LINK') {
|
|
57
|
-
|
|
58
|
-
.map((rule) => rule.cssText)
|
|
59
|
-
.join('');
|
|
56
|
+
Array.from(styleSheet.cssRules).map((rule) => cssStyleSheet.insertRule(rule.cssText));
|
|
60
57
|
}
|
|
61
|
-
cssStyleSheet.replaceSync(cssText);
|
|
62
58
|
}
|
|
63
59
|
cssStyleSheets.push(cssStyleSheet);
|
|
64
60
|
});
|