@webtides/element-js 0.4.3 → 0.6.0
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/CHANGELOG.md +14 -0
- package/README.md +6 -3
- package/dist/index.js +50 -0
- package/dist/index.js.map +3 -3
- package/index.js +2 -1
- package/package.json +8 -3
- package/src/BaseElement.js +12 -0
- package/src/renderer/vanilla/util/directives.js +78 -0
- package/src/renderer/vanilla/util/html.js +3 -16
- package/src/renderer/vanilla/util/render.js +97 -217
- package/src/util/AttributeParser.js +26 -8
- package/src/util/Store.js +57 -0
package/CHANGELOG.md
CHANGED
|
@@ -14,6 +14,20 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
|
|
|
14
14
|
<!-- ### Changed -->
|
|
15
15
|
<!-- ### Removed -->
|
|
16
16
|
<!-- ### Fixed -->
|
|
17
|
+
## [0.6.0] - 2022-11-17
|
|
18
|
+
|
|
19
|
+
### ADDED
|
|
20
|
+
* StoreProperty for shared application state
|
|
21
|
+
* Directives for Vanilla Renderer
|
|
22
|
+
|
|
23
|
+
## [0.5.0] - 2022-09-13
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
* improved the performance of the vanilla-renderer
|
|
27
|
+
|
|
28
|
+
### Removed
|
|
29
|
+
* setting attributes as properties during dom diffing for the vanilla renderer. This is potentially a **breaking** change if you used attributes with the "." (dot) notation
|
|
30
|
+
|
|
17
31
|
## [0.4.3] - 2022-07-06
|
|
18
32
|
|
|
19
33
|
### ADDED
|
package/README.md
CHANGED
|
@@ -25,7 +25,9 @@ npm install --save @webtides/element-js
|
|
|
25
25
|
// import { BaseElement, defineElement } from 'https://unpkg.com/@webtides/element-js';
|
|
26
26
|
// import { BaseElement, defineElement } from 'https://cdn.skypack.dev/@webtides/element-js';
|
|
27
27
|
// or when installed via npm
|
|
28
|
-
import { BaseElement, defineElement } from '@webtides/element-js';
|
|
28
|
+
import { BaseElement, defineElement, Store } from '@webtides/element-js';
|
|
29
|
+
|
|
30
|
+
const sharedDate = new Store({date: Date.now()})
|
|
29
31
|
|
|
30
32
|
class ExampleElement extends BaseElement {
|
|
31
33
|
// normal public properties
|
|
@@ -40,7 +42,8 @@ class ExampleElement extends BaseElement {
|
|
|
40
42
|
// reactive attributes/properties
|
|
41
43
|
properties() {
|
|
42
44
|
return {
|
|
43
|
-
|
|
45
|
+
familyName: 'Doe',
|
|
46
|
+
sharedDate
|
|
44
47
|
};
|
|
45
48
|
}
|
|
46
49
|
|
|
@@ -55,7 +58,7 @@ class ExampleElement extends BaseElement {
|
|
|
55
58
|
|
|
56
59
|
// computed property
|
|
57
60
|
get computedMsg() {
|
|
58
|
-
return `${this.greeting} ${this.name} ${this.familyName}`;
|
|
61
|
+
return `${this.greeting} ${this.name} ${this.familyName} ${this.sharedDate.date}`;
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
// method
|
package/dist/index.js
CHANGED
|
@@ -73,6 +73,47 @@ function getShadowParentOrBody(element) {
|
|
|
73
73
|
var supportsAdoptingStyleSheets = () => "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype;
|
|
74
74
|
var supportsAppendingStyleSheets = !window.ShadyDOM;
|
|
75
75
|
|
|
76
|
+
// src/util/Store.js
|
|
77
|
+
var Store = class {
|
|
78
|
+
constructor(value) {
|
|
79
|
+
__publicField(this, "_observer", new Set());
|
|
80
|
+
__publicField(this, "_singlePropertyMode", false);
|
|
81
|
+
__publicField(this, "_state", {});
|
|
82
|
+
this._singlePropertyMode = !isObjectLike(value);
|
|
83
|
+
const specificValues = this._singlePropertyMode ? {value} : value;
|
|
84
|
+
this._state = {...!this._singlePropertyMode && this.properties(), ...specificValues};
|
|
85
|
+
Object.entries(this._state).map(([key, value2]) => {
|
|
86
|
+
Object.defineProperty(this, key, {
|
|
87
|
+
get: () => {
|
|
88
|
+
return this._state[key];
|
|
89
|
+
},
|
|
90
|
+
set: (newValue) => {
|
|
91
|
+
this._state[key] = newValue;
|
|
92
|
+
this.requestUpdate();
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
properties() {
|
|
98
|
+
return {};
|
|
99
|
+
}
|
|
100
|
+
valueOf() {
|
|
101
|
+
return this._singlePropertyMode ? this._state.value : this._state;
|
|
102
|
+
}
|
|
103
|
+
toString() {
|
|
104
|
+
return `${this._singlePropertyMode ? this._state.value : this._state}`;
|
|
105
|
+
}
|
|
106
|
+
subscribe(observer) {
|
|
107
|
+
this._observer.add(observer);
|
|
108
|
+
}
|
|
109
|
+
unsubscribe(observer) {
|
|
110
|
+
this._observer.delete(observer);
|
|
111
|
+
}
|
|
112
|
+
requestUpdate() {
|
|
113
|
+
this._observer.forEach((observer) => typeof observer.requestUpdate === "function" ? observer.requestUpdate() : observer());
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
76
117
|
// src/util/defineElement.js
|
|
77
118
|
function defineElement(name, constructor) {
|
|
78
119
|
try {
|
|
@@ -156,6 +197,11 @@ var BaseElement = class extends HTMLElement {
|
|
|
156
197
|
this.removeEvents();
|
|
157
198
|
if (this._mutationObserver)
|
|
158
199
|
this._mutationObserver.disconnect();
|
|
200
|
+
Object.values(this.properties()).forEach((property) => {
|
|
201
|
+
if (property instanceof Store) {
|
|
202
|
+
property.unsubscribe(this);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
159
205
|
this.triggerHook("disconnected");
|
|
160
206
|
}
|
|
161
207
|
requestUpdate(options = {notify: true}) {
|
|
@@ -210,6 +256,9 @@ var BaseElement = class extends HTMLElement {
|
|
|
210
256
|
}
|
|
211
257
|
defineProperty(property, value, reflectAttribute = false) {
|
|
212
258
|
var _a, _b;
|
|
259
|
+
if (value instanceof Store) {
|
|
260
|
+
value.subscribe(this);
|
|
261
|
+
}
|
|
213
262
|
if (this._state.hasOwnProperty(property)) {
|
|
214
263
|
return;
|
|
215
264
|
}
|
|
@@ -1494,6 +1543,7 @@ var TemplateElement = class extends StyledElement {
|
|
|
1494
1543
|
};
|
|
1495
1544
|
export {
|
|
1496
1545
|
BaseElement,
|
|
1546
|
+
Store,
|
|
1497
1547
|
StyledElement,
|
|
1498
1548
|
TemplateElement,
|
|
1499
1549
|
defineElement,
|