@webtides/element-js 1.3.0 → 1.3.1

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.3.0",
3
+ "version": "1.3.1",
4
4
  "module": "index.js",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -71,13 +71,22 @@ const unsafeHTML = (string) => {
71
71
  * Renders multiple attributes as key="value" pairs from a map of attributes
72
72
  */
73
73
  export class SpreadAttributesDirective extends Directive {
74
+ /**
75
+ * An attribute with one of these values is left out, on the element and in the string.
76
+ * @param {any} value
77
+ * @returns {boolean}
78
+ */
79
+ isOmitted(value) {
80
+ return value === undefined || value === null || isNaN(value);
81
+ }
82
+
74
83
  /**
75
84
  * @param {Object.<string, any>} attributes
76
85
  */
77
86
  update(attributes) {
78
87
  for (const name of Object.keys(attributes)) {
79
88
  const value = attributes[name];
80
- if (value === undefined || value === null || isNaN(value)) {
89
+ if (this.isOmitted(value)) {
81
90
  this.node.removeAttribute(camelToDash(name));
82
91
  } else {
83
92
  this.node.setAttribute(
@@ -94,6 +103,7 @@ export class SpreadAttributesDirective extends Directive {
94
103
  */
95
104
  stringify(attributes) {
96
105
  return Object.keys(attributes)
106
+ .filter((name) => !this.isOmitted(attributes[name]))
97
107
  .map((name) => {
98
108
  let value = attributes[name];
99
109
  return `${camelToDash(name)}='${encodeAttribute(