@webtides/element-js 0.4.1 → 0.5.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 CHANGED
@@ -14,11 +14,29 @@ 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.5.0] - 2022-09-13
18
+
19
+ ### Changed
20
+ * improved the performance of the vanilla-renderer
21
+
22
+ ### Removed
23
+ * 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
24
+
25
+ ## [0.4.3] - 2022-07-06
26
+
27
+ ### ADDED
28
+ * parse option to propertyOptions that can be either a boolean OR a function for custom parsing
29
+ * enhance reflect option in propertyOptions that it can also be a function for custom reflection
30
+
31
+ ## [0.4.2] - 2022-02-03
32
+
33
+ ### Fixed
34
+ * vanilla-renderer: fixes attribute comparsion
17
35
 
18
36
  ## [0.4.1] - 2022-02-01
19
37
 
20
38
  ### Fixed
21
- * vanilla-renderer: fixes attribute comparsion
39
+ * refs="id[]" indexing keys not nodes *rolleyes*
22
40
 
23
41
  ### Added
24
42
  * refs="id[]" aka possibbility to refrence a list of nodes to the $refs map.
package/dist/index.js CHANGED
@@ -33,10 +33,13 @@ function isNumber(value) {
33
33
  function isNaN(value) {
34
34
  return Number.isNaN(value);
35
35
  }
36
- function parseAttribute(value) {
37
- if (!isString(value)) {
36
+ function parseAttribute(value, options = {}) {
37
+ if (options.parse === false || !isString(value)) {
38
38
  return value;
39
39
  }
40
+ if (typeof options.parse === "function") {
41
+ return options.parse(value);
42
+ }
40
43
  let parsedValue = value;
41
44
  if (isJSON(value))
42
45
  parsedValue = JSON.parse(value);
@@ -132,7 +135,7 @@ var BaseElement = class extends HTMLElement {
132
135
  this._mutationObserver = new MutationObserver((mutations) => {
133
136
  mutations.forEach((mutation) => {
134
137
  if (mutation.type === "attributes" && mutation.target === this && this._state.hasOwnProperty(dashToCamel(mutation.attributeName))) {
135
- this[dashToCamel(mutation.attributeName)] = parseAttribute(this.getAttribute(mutation.attributeName));
138
+ this[dashToCamel(mutation.attributeName)] = parseAttribute(this.getAttribute(mutation.attributeName), this._options.propertyOptions[dashToCamel(mutation.attributeName)]);
136
139
  }
137
140
  if (mutation.type === "attributes" && mutation.target !== this) {
138
141
  this.requestUpdate();
@@ -191,7 +194,9 @@ var BaseElement = class extends HTMLElement {
191
194
  Array.from(this.attributes).filter((attribute) => {
192
195
  return !ignoreAttributes.includes(attribute.name);
193
196
  }).forEach((attribute) => {
194
- this.defineProperty(dashToCamel(attribute.name), parseAttribute(attribute.value), true);
197
+ const name = dashToCamel(attribute.name);
198
+ const parseOptions = this._options.propertyOptions[name];
199
+ this.defineProperty(name, parseAttribute(attribute.value, parseOptions), true);
195
200
  });
196
201
  }
197
202
  properties() {
@@ -208,7 +213,7 @@ var BaseElement = class extends HTMLElement {
208
213
  if (this._state.hasOwnProperty(property)) {
209
214
  return;
210
215
  }
211
- if (!reflectAttribute && ((_a = this._options.propertyOptions[property]) == null ? void 0 : _a.reflect) === true) {
216
+ if (!reflectAttribute && ((_a = this._options.propertyOptions[property]) == null ? void 0 : _a.reflect)) {
212
217
  this.reflectProperty({property, newValue: value});
213
218
  }
214
219
  if (((_b = this._options.propertyOptions[property]) == null ? void 0 : _b.reflect) === false) {
@@ -225,7 +230,7 @@ var BaseElement = class extends HTMLElement {
225
230
  const newValueString = JSON.stringify(newValue);
226
231
  if (JSON.stringify(oldValue) !== newValueString) {
227
232
  this._state[property] = newValue;
228
- if (reflectAttribute || ((_a2 = this._options.propertyOptions[property]) == null ? void 0 : _a2.reflect) === true) {
233
+ if (reflectAttribute || ((_a2 = this._options.propertyOptions[property]) == null ? void 0 : _a2.reflect)) {
229
234
  this.reflectProperty({property, newValue, newValueString});
230
235
  }
231
236
  const informWatchedPropertiesAndDispatchChangeEvent = () => {
@@ -255,12 +260,16 @@ var BaseElement = class extends HTMLElement {
255
260
  });
256
261
  }
257
262
  reflectProperty(options) {
263
+ var _a;
258
264
  const {property, newValue} = options;
259
265
  const newValueString = options.newValueString || JSON.stringify(newValue);
260
266
  if (newValue === void 0 || newValue === null || isNaN(newValue)) {
261
267
  this.setAttribute(camelToDash(property), "");
262
268
  } else {
263
- const attributeValue = isObjectLike(newValue) ? newValueString : newValue;
269
+ let attributeValue = isObjectLike(newValue) ? newValueString : newValue;
270
+ if (typeof ((_a = this._options.propertyOptions[property]) == null ? void 0 : _a.reflect) === "function") {
271
+ attributeValue = this._options.propertyOptions[property].reflect(newValue);
272
+ }
264
273
  this.setAttribute(camelToDash(property), attributeValue);
265
274
  }
266
275
  }
@@ -350,7 +359,7 @@ var BaseElement = class extends HTMLElement {
350
359
  if (!refsMap[cleanKey] || !hasListRef) {
351
360
  refsMap[cleanKey] = [];
352
361
  }
353
- refsMap[cleanKey].push(cleanKey);
362
+ refsMap[cleanKey].push(refNode);
354
363
  } else if (!hasListRef) {
355
364
  refsMap[refKey] = refNode;
356
365
  } else {