@webtides/element-js 1.2.4 → 1.2.6

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtides/element-js",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "module": "index.js",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -194,9 +194,6 @@ class BaseElement extends HTMLElement {
194
194
  // release dom references
195
195
  this.$refs = {};
196
196
 
197
- // clear state
198
- this._state = {};
199
-
200
197
  // cancel pending updates
201
198
  if (this._batchUpdate) {
202
199
  cancelAnimationFrame(this._batchUpdate);
@@ -298,7 +295,7 @@ class BaseElement extends HTMLElement {
298
295
  // registered or connected. To avoid such timing issues we check
299
296
  // if a value was set for that specific property on the
300
297
  // prototype before assigning a default value
301
- const value = this[prop] || this.properties()[prop];
298
+ const value = this[prop] ?? this.properties()[prop];
302
299
  this.defineProperty(prop, value);
303
300
  });
304
301
  }
@@ -312,11 +309,6 @@ class BaseElement extends HTMLElement {
312
309
  * @param {boolean} isAttribute
313
310
  */
314
311
  defineProperty(property, value, isAttribute = false) {
315
- if (this._state.hasOwnProperty(property)) {
316
- // property has already been defined as an attribute nothing to do here
317
- return;
318
- }
319
-
320
312
  // if property did not come from an attribute but has the option to reflect // enabled or custom fn
321
313
  if (!isAttribute && this._options.propertyOptions[property]?.reflect) {
322
314
  this.reflectProperty({ property: property, newValue: value });
@@ -337,8 +329,9 @@ class BaseElement extends HTMLElement {
337
329
  this._state[property].subscribe(this);
338
330
  }
339
331
 
340
- if (Object.getOwnPropertyDescriptor(this, property)) {
341
- // instance already has a defined property
332
+ const descriptor = Object.getOwnPropertyDescriptor(this, property);
333
+ if (descriptor && descriptor.set && descriptor.get) {
334
+ // instance already has a defined, reactive ejs property
342
335
  return;
343
336
  }
344
337
  Object.defineProperty(this, property, {
@@ -39,17 +39,6 @@ class StyledElement extends BaseElement {
39
39
  return cssStyleSheet;
40
40
  });
41
41
  }
42
-
43
- if (supportsAdoptingStyleSheets() && this._options.shadowRender) {
44
- // adopting does only make sense in shadow dom. Fall back to append for light elements
45
- this.adoptStyleSheets();
46
-
47
- if (this._options.adoptGlobalStyles !== false) {
48
- globalStylesStore.subscribe(() => {
49
- this.adoptStyleSheets();
50
- });
51
- }
52
- }
53
42
  }
54
43
 
55
44
  /**
@@ -73,6 +62,26 @@ class StyledElement extends BaseElement {
73
62
  super.update(options);
74
63
  }
75
64
 
65
+ /**
66
+ * Start the adoption of external stylesheets
67
+ * adopt global styles from document
68
+ * subscribe to globalStylesStore for updates
69
+ * @returns { void }
70
+ */
71
+
72
+ initStyleAdoption() {
73
+ if (this._options.shadowRender && supportsAdoptingStyleSheets()) {
74
+ // adopting does only make sense in shadow dom. Fall back to append for light elements
75
+ this.adoptStyleSheets();
76
+
77
+ if (this._options.adoptGlobalStyles !== false) {
78
+ globalStylesStore.subscribe(() => {
79
+ this.adoptStyleSheets();
80
+ });
81
+ }
82
+ }
83
+ }
84
+
76
85
  /**
77
86
  * Adopt stylesheets
78
87
  */
@@ -28,10 +28,8 @@ class TemplateElement extends StyledElement {
28
28
 
29
29
  /**
30
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
31
  */
33
32
  connectedCallback() {
34
- if (this._options.shadowRender && !this.shadowRoot) this.attachShadow({ mode: 'open' });
35
33
  super.connectedCallback();
36
34
  }
37
35
 
@@ -54,8 +52,16 @@ class TemplateElement extends StyledElement {
54
52
 
55
53
  /**
56
54
  * Render the template to the root
55
+ * This will attach a shadow DOM if the element is supposed to render in shadow DOM.
57
56
  */
58
57
  renderTemplate() {
58
+ const firstRender = this._options.shadowRender && !this.shadowRoot;
59
+ if (firstRender) {
60
+ this.attachShadow({ mode: 'open' });
61
+ // init external stylesheets
62
+ this.initStyleAdoption();
63
+ }
64
+
59
65
  const template = this._template || this.template();
60
66
  render(template, this.getRoot());
61
67
  }