marko 5.32.10 → 5.32.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,28 +22,51 @@ var FLAG_SIMPLE_ATTRS = 1;
22
22
  var FLAG_CUSTOM_ELEMENT = 2;
23
23
  var FLAG_SPREAD_ATTRS = 4;
24
24
 
25
- var defineProperty = Object.defineProperty;
26
-
27
25
  var ATTR_HREF = "href";
28
- var EMPTY_OBJECT = Object.freeze({});
26
+ var EMPTY_OBJECT = Object.freeze(Object.create(null));
27
+ var specialElHandlers = {
28
+ option: {
29
+ selected: function (fromEl, value) {
30
+ fromEl.selected = value !== undefined;
31
+ }
32
+ },
33
+ input: {
34
+ value: function (fromEl, value) {
35
+ fromEl.value = value === undefined ? "" : value;
36
+ },
37
+ checked: function (fromEl, value) {
38
+ fromEl.checked = value !== undefined;
39
+ }
40
+ }
41
+ };
29
42
 
30
- function convertAttrValue(type, value) {
43
+ function normalizeValue(value) {
31
44
  if (value === true) {
32
45
  return "";
33
- } else if (type == "object") {
34
- switch (value.toString) {
35
- case Object.prototype.toString:
36
- case Array.prototype.toString:
37
- // eslint-disable-next-line no-constant-condition
46
+ }
38
47
 
48
+ if (value == null || value === false) {
49
+ return;
50
+ }
39
51
 
52
+ switch (typeof value) {
53
+ case "string":
54
+ return value;
55
+ case "object":
56
+ switch (value.toString) {
57
+ case Object.prototype.toString:
58
+ case Array.prototype.toString:
59
+ // eslint-disable-next-line no-constant-condition
40
60
 
41
61
 
42
62
 
43
- return JSON.stringify(value);
44
- case RegExp.prototype.toString:
45
- return value.source;
46
- }
63
+
64
+
65
+ return JSON.stringify(value);
66
+ case RegExp.prototype.toString:
67
+ return value.source;
68
+ }
69
+ break;
47
70
  }
48
71
 
49
72
  return value + "";
@@ -57,22 +80,6 @@ function assign(a, b) {
57
80
  }
58
81
  }
59
82
 
60
- function setAttribute(el, namespaceURI, name, value) {
61
- if (namespaceURI === null) {
62
- el.setAttribute(name, value);
63
- } else {
64
- el.setAttributeNS(namespaceURI, name, value);
65
- }
66
- }
67
-
68
- function removeAttribute(el, namespaceURI, name) {
69
- if (namespaceURI === null) {
70
- el.removeAttribute(name);
71
- } else {
72
- el.removeAttributeNS(namespaceURI, name);
73
- }
74
- }
75
-
76
83
  function VElementClone(other) {
77
84
  this.bW_ = other.bW_;
78
85
  this.bT_ = null;
@@ -177,19 +184,11 @@ VElement.prototype = {
177
184
  assign(el, attributes);
178
185
  } else {
179
186
  for (var attrName in attributes) {
180
- var attrValue = attributes[attrName];
181
-
182
- if (attrValue !== false && attrValue != null) {
183
- var type = typeof attrValue;
184
-
185
- if (type !== "string") {
186
- // Special attributes aren't copied to the real DOM. They are only
187
- // kept in the virtual attributes map
188
- attrValue = convertAttrValue(type, attrValue);
189
- }
187
+ var attrValue = normalizeValue(attributes[attrName]);
190
188
 
189
+ if (attrValue !== undefined) {
191
190
  if (attrName == ATTR_XLINK_HREF) {
192
- setAttribute(el, NS_XLINK, ATTR_HREF, attrValue);
191
+ el.setAttributeNS(NS_XLINK, ATTR_HREF, attrValue);
193
192
  } else {
194
193
  el.setAttribute(attrName, attrValue);
195
194
  }
@@ -197,7 +196,7 @@ VElement.prototype = {
197
196
  }
198
197
 
199
198
  if (tagName === "textarea") {
200
- el.defaultValue = el.value = this.e_;
199
+ el.defaultValue = this.bZ_;
201
200
  }
202
201
  }
203
202
 
@@ -217,39 +216,7 @@ VElement.prototype = {
217
216
 
218
217
  inherit(VElement, VNode);
219
218
 
220
- var proto = VElementClone.prototype = VElement.prototype;
221
-
222
- ["checked", "selected", "disabled"].forEach(function (name) {
223
- defineProperty(proto, name, {
224
- get: function () {
225
- var value = this.bX_[name];
226
- return value !== false && value != null;
227
- }
228
- });
229
- });
230
-
231
- defineProperty(proto, "e_", {
232
- get: function () {
233
- var value = this.bZ_;
234
- if (value == null) {
235
- value = this.bX_.value;
236
- }
237
- return value != null && value !== false ?
238
- value + "" :
239
- this.bX_.type === "checkbox" ||
240
- this.bX_.type === "radio" ?
241
- "on" :
242
- "";
243
- }
244
- });
245
-
246
- VElement.cc_ = function (attrs) {
247
- // By default this static method is a no-op, but if there are any
248
- // compiled components that have "no-update" attributes then
249
- // `preserve-attrs.js` will be imported and this method will be replaced
250
- // with a method that actually does something
251
- return attrs;
252
- };
219
+ VElementClone.prototype = VElement.prototype;
253
220
 
254
221
  function virtualizeElement(node, virtualizeChildNodes, ownerComponent) {
255
222
  var attributes = node.attributes;
@@ -300,23 +267,18 @@ function virtualizeElement(node, virtualizeChildNodes, ownerComponent) {
300
267
  return vdomEl;
301
268
  }
302
269
 
303
- VElement.cd_ = virtualizeElement;
304
-
305
- VElement.ce_ = function (fromEl, vFromEl, toEl) {
306
- var removePreservedAttributes = VElement.cc_;
270
+ VElement.cc_ = virtualizeElement;
307
271
 
272
+ VElement.cd_ = function (fromEl, vFromEl, toEl) {
308
273
  var fromFlags = vFromEl.t_;
309
274
  var toFlags = toEl.t_;
310
-
311
- vElementByDOMNode.set(fromEl, toEl);
312
-
313
275
  var attrs = toEl.bX_;
314
- var props = toEl._L_;
315
276
 
316
277
  if (toFlags & FLAG_CUSTOM_ELEMENT) {
317
278
  return assign(fromEl, attrs);
318
279
  }
319
280
 
281
+ var props = toEl._L_;
320
282
  var attrName;
321
283
 
322
284
  // We use expando properties to associate the previous HTML
@@ -329,16 +291,12 @@ VElement.ce_ = function (fromEl, vFromEl, toEl) {
329
291
 
330
292
  var oldAttrs = vFromEl.bX_;
331
293
 
332
- if (oldAttrs) {
333
- if (oldAttrs === attrs) {
334
- // For constant attributes the same object will be provided
335
- // every render and we can use that to our advantage to
336
- // not waste time diffing a constant, immutable attribute
337
- // map.
338
- return;
339
- } else {
340
- oldAttrs = removePreservedAttributes(oldAttrs, props);
341
- }
294
+ if (oldAttrs === attrs) {
295
+ // For constant attributes the same object will be provided
296
+ // every render and we can use that to our advantage to
297
+ // not waste time diffing a constant, immutable attribute
298
+ // map.
299
+ return;
342
300
  }
343
301
 
344
302
  var attrValue;
@@ -356,36 +314,32 @@ VElement.ce_ = function (fromEl, vFromEl, toEl) {
356
314
  return;
357
315
  }
358
316
 
359
- // In some cases we only want to set an attribute value for the first
360
- // render or we don't want certain attributes to be touched. To support
361
- // that use case we delete out all of the preserved attributes
362
- // so it's as if they never existed.
363
- attrs = removePreservedAttributes(attrs, props, true);
364
-
365
- var namespaceURI;
317
+ var preserve = props && props.pa || EMPTY_OBJECT;
318
+ var specialAttrs = specialElHandlers[toEl.bY_] || EMPTY_OBJECT;
319
+ var specialAttr;
366
320
 
367
321
  // Loop over all of the attributes in the attribute map and compare
368
322
  // them to the value in the old map. However, if the value is
369
323
  // null/undefined/false then we want to remove the attribute
370
324
  for (attrName in attrs) {
371
- attrValue = attrs[attrName];
372
- namespaceURI = null;
373
-
374
- if (attrName === ATTR_XLINK_HREF) {
375
- namespaceURI = NS_XLINK;
376
- attrName = ATTR_HREF;
377
- }
378
-
379
- if (attrValue == null || attrValue === false) {
380
- removeAttribute(fromEl, namespaceURI, attrName);
381
- } else if (oldAttrs[attrName] !== attrValue) {
382
- var type = typeof attrValue;
383
-
384
- if (type !== "string") {
385
- attrValue = convertAttrValue(type, attrValue);
325
+ if (
326
+ !preserve[attrName] &&
327
+ normalizeValue(oldAttrs[attrName]) !== (
328
+ attrValue = normalizeValue(attrs[attrName])))
329
+ {
330
+ if (specialAttr = specialAttrs[attrName]) {
331
+ specialAttr(fromEl, attrValue);
332
+ } else if (attrName === ATTR_XLINK_HREF) {
333
+ if (attrValue === undefined) {
334
+ fromEl.removeAttributeNS(NS_XLINK, ATTR_HREF);
335
+ } else {
336
+ fromEl.setAttributeNS(NS_XLINK, ATTR_HREF, attrValue);
337
+ }
338
+ } else if (attrValue === undefined) {
339
+ fromEl.removeAttribute(attrName);
340
+ } else {
341
+ fromEl.setAttribute(attrName, attrValue);
386
342
  }
387
-
388
- setAttribute(fromEl, namespaceURI, attrName, attrValue);
389
343
  }
390
344
  }
391
345
 
@@ -402,7 +356,9 @@ VElement.ce_ = function (fromEl, vFromEl, toEl) {
402
356
  if (toEl.bR_ === null || fromFlags & FLAG_SPREAD_ATTRS) {
403
357
  for (attrName in oldAttrs) {
404
358
  if (!(attrName in attrs)) {
405
- if (attrName === ATTR_XLINK_HREF) {
359
+ if (specialAttr = specialAttrs[attrName]) {
360
+ specialAttr(fromEl, undefined);
361
+ } else if (attrName === ATTR_XLINK_HREF) {
406
362
  fromEl.removeAttributeNS(ATTR_XLINK_HREF, ATTR_HREF);
407
363
  } else {
408
364
  fromEl.removeAttribute(attrName);
@@ -3,10 +3,10 @@ function VNode() {}
3
3
 
4
4
  VNode.prototype = {
5
5
  bQ_: function (finalChildCount, ownerComponent) {
6
- this.cf_ = finalChildCount;
7
- this.cg_ = 0;
6
+ this.ce_ = finalChildCount;
7
+ this.cf_ = 0;
8
8
  this.bW_ = null;
9
- this.ch_ = null;
9
+ this.cg_ = null;
10
10
  this.bT_ = null;
11
11
  this.bU_ = null;
12
12
  this._J_ = ownerComponent;
@@ -21,24 +21,24 @@ VNode.prototype = {
21
21
  // If the DocumentFragment node has a first child then we will return that.
22
22
  // Otherwise, the DocumentFragment node is not *really* the first child and
23
23
  // we need to skip to its next sibling
24
- return nestedFirstChild || firstChild.ci_;
24
+ return nestedFirstChild || firstChild.ch_;
25
25
  }
26
26
 
27
27
  return firstChild;
28
28
  },
29
29
 
30
- get ci_() {
30
+ get ch_() {
31
31
  var nextSibling = this.bU_;
32
32
 
33
33
  if (nextSibling) {
34
34
  if (nextSibling.bV_) {
35
35
  var firstChild = nextSibling.ay_;
36
- return firstChild || nextSibling.ci_;
36
+ return firstChild || nextSibling.ch_;
37
37
  }
38
38
  } else {
39
39
  var parentNode = this.bT_;
40
40
  if (parentNode && parentNode.bV_) {
41
- return parentNode.ci_;
41
+ return parentNode.ch_;
42
42
  }
43
43
  }
44
44
 
@@ -46,19 +46,17 @@ VNode.prototype = {
46
46
  },
47
47
 
48
48
  bI_: function (child) {
49
- this.cg_++;
49
+ this.cf_++;
50
50
 
51
51
  if (this.bY_ === "textarea") {
52
- if (child.cj_) {
53
- var childValue = child.ck_;
52
+ if (child.ci_) {
53
+ var childValue = child.cj_;
54
54
  this.bZ_ = (this.bZ_ || "") + childValue;
55
- } else if (child.aa_ || child.a__) {
56
- this.cl_ = true;
57
55
  } else {
58
56
  throw TypeError();
59
57
  }
60
58
  } else {
61
- var lastChild = this.ch_;
59
+ var lastChild = this.cg_;
62
60
 
63
61
  child.bT_ = this;
64
62
 
@@ -68,14 +66,14 @@ VNode.prototype = {
68
66
  this.bW_ = child;
69
67
  }
70
68
 
71
- this.ch_ = child;
69
+ this.cg_ = child;
72
70
  }
73
71
 
74
72
  return child;
75
73
  },
76
74
 
77
75
  ca_: function finishChild() {
78
- if (this.cg_ === this.cf_ && this.bT_) {
76
+ if (this.cf_ === this.ce_ && this.bT_) {
79
77
  return this.bT_.ca_();
80
78
  } else {
81
79
  return this;
@@ -3,20 +3,20 @@ var VNode = require("./VNode");
3
3
 
4
4
  function VText(value, ownerComponent) {
5
5
  this.bQ_(-1 /* no children */, ownerComponent);
6
- this.ck_ = value;
6
+ this.cj_ = value;
7
7
  }
8
8
 
9
9
  VText.prototype = {
10
- cj_: true,
10
+ ci_: true,
11
11
 
12
12
  bS_: 3,
13
13
 
14
14
  bP_: function (host) {
15
- return (host.ownerDocument || host).createTextNode(this.ck_);
15
+ return (host.ownerDocument || host).createTextNode(this.cj_);
16
16
  },
17
17
 
18
18
  bJ_: function () {
19
- return new VText(this.ck_);
19
+ return new VText(this.cj_);
20
20
  }
21
21
  };
22
22
 
@@ -44,7 +44,7 @@ exports.t = runtime.t = function (typeName) {
44
44
  instance.P_(input, out);
45
45
  };
46
46
 
47
- instance.cm_ = true;
47
+ instance.ck_ = true;
48
48
  instance.am_();
49
49
  instance._t_ = false;
50
50
 
@@ -78,7 +78,7 @@ registry._C_ = function (typeName, id) {
78
78
  if (instances) {
79
79
  instances.add(instance);
80
80
  instance.once("destroy", function () {
81
- if (!instance.cm_) {
81
+ if (!instance.ck_) {
82
82
  instances.delete(instance);
83
83
  }
84
84
  });
@@ -80,8 +80,8 @@ function createFragmentNode(startNode, nextNode, parentNode) {
80
80
 
81
81
  function beginFragmentNode(startNode, parentNode) {
82
82
  var fragment = createFragmentNode(startNode, null, parentNode);
83
- fragment.cn_ = function (nextNode) {
84
- fragment.cn_ = null;
83
+ fragment.cl_ = function (nextNode) {
84
+ fragment.cl_ = null;
85
85
  insertBefore(
86
86
  fragment.endNode,
87
87
  nextNode,
@@ -92,4 +92,4 @@ function beginFragmentNode(startNode, parentNode) {
92
92
  }
93
93
 
94
94
  exports._h_ = createFragmentNode;
95
- exports.co_ = beginFragmentNode;
95
+ exports.cm_ = beginFragmentNode;
@@ -37,6 +37,6 @@ function removeChild(node) {
37
37
 
38
38
  exports.bc_ = insertBefore;
39
39
  exports.bd_ = insertAfter;
40
- exports.ci_ = nextSibling;
40
+ exports.ch_ = nextSibling;
41
41
  exports.ay_ = firstChild;
42
42
  exports.be_ = removeChild;
@@ -11,9 +11,8 @@ var KeySequence = require("../../components/KeySequence");
11
11
  var VElement = require("../vdom").br_;
12
12
  var fragment = require("./fragment");
13
13
  var helpers = require("./helpers");
14
- var specialElHandlers = require("./specialElHandlers");
15
- var virtualizeElement = VElement.cd_;
16
- var morphAttrs = VElement.ce_;
14
+ var virtualizeElement = VElement.cc_;
15
+ var morphAttrs = VElement.cd_;
17
16
  var keysByDOMNode = domData._G_;
18
17
  var componentByDOMNode = domData._l_;
19
18
  var vElementByDOMNode = domData._H_;
@@ -21,11 +20,11 @@ var detachedByDOMNode = domData.aT_;
21
20
 
22
21
  var insertBefore = helpers.bc_;
23
22
  var insertAfter = helpers.bd_;
24
- var nextSibling = helpers.ci_;
23
+ var nextSibling = helpers.ch_;
25
24
  var firstChild = helpers.ay_;
26
25
  var removeChild = helpers.be_;
27
26
  var createFragmentNode = fragment._h_;
28
- var beginFragmentNode = fragment.co_;
27
+ var beginFragmentNode = fragment.cm_;
29
28
 
30
29
  var ELEMENT_NODE = 1;
31
30
  var TEXT_NODE = 3;
@@ -162,7 +161,7 @@ function morphdom(fromNode, toNode, host, componentsContext) {
162
161
  var fromComponent;
163
162
 
164
163
  outer: while (curToNodeChild) {
165
- toNextSibling = curToNodeChild.ci_;
164
+ toNextSibling = curToNodeChild.ch_;
166
165
  curToNodeType = curToNodeChild.bS_;
167
166
  curToNodeKey = curToNodeChild.bR_;
168
167
 
@@ -598,11 +597,11 @@ function morphdom(fromNode, toNode, host, componentsContext) {
598
597
  toNextSibling.bS_ === TEXT_NODE)
599
598
  {
600
599
  fromNextSibling = curFromNodeChild.splitText(
601
- curToNodeChild.ck_.length
600
+ curToNodeChild.cj_.length
602
601
  );
603
602
  }
604
- if (curFromNodeChild.nodeValue !== curToNodeChild.ck_) {
605
- curFromNodeChild.nodeValue = curToNodeChild.ck_;
603
+ if (curFromNodeChild.nodeValue !== curToNodeChild.cj_) {
604
+ curFromNodeChild.nodeValue = curToNodeChild.cj_;
606
605
  }
607
606
  }
608
607
  }
@@ -636,10 +635,10 @@ function morphdom(fromNode, toNode, host, componentsContext) {
636
635
  }
637
636
 
638
637
  // We have processed all of the "to nodes".
639
- if (fromNode.cn_) {
638
+ if (fromNode.cl_) {
640
639
  // If we are in an unfinished fragment, we have reached the end of the nodes
641
640
  // we were matching up and need to end the fragment
642
- fromNode.cn_(curFromNodeChild);
641
+ fromNode.cl_(curFromNodeChild);
643
642
  } else {
644
643
  // If curFromNodeChild is non-null then we still have some from nodes
645
644
  // left over that need to be removed
@@ -680,8 +679,9 @@ function morphdom(fromNode, toNode, host, componentsContext) {
680
679
 
681
680
  function morphEl(fromEl, vFromEl, toEl, parentComponent) {
682
681
  var nodeName = toEl.bY_;
683
-
684
682
  var constId = toEl.c__;
683
+ vElementByDOMNode.set(fromEl, toEl);
684
+
685
685
  if (constId !== undefined && vFromEl.c__ === constId) {
686
686
  return;
687
687
  }
@@ -692,14 +692,15 @@ function morphdom(fromNode, toNode, host, componentsContext) {
692
692
  return;
693
693
  }
694
694
 
695
- if (nodeName !== "textarea") {
695
+ if (nodeName === "textarea") {
696
+ var newValue = toEl.bZ_ || "";
697
+ var oldValue = vFromEl.bZ_ || "";
698
+ if (oldValue !== newValue) {
699
+ fromEl.value = newValue;
700
+ }
701
+ } else {
696
702
  morphChildren(fromEl, toEl, parentComponent);
697
703
  }
698
-
699
- var specialElHandler = specialElHandlers[nodeName];
700
- if (specialElHandler !== undefined) {
701
- specialElHandler(fromEl, toEl);
702
- }
703
704
  } // END: morphEl(...)
704
705
 
705
706
  // eslint-disable-next-line no-constant-condition
@@ -19,7 +19,7 @@ function virtualizeChildNodes(node, vdomParent, ownerComponent) {
19
19
  function virtualize(node, ownerComponent) {
20
20
  switch (node.nodeType) {
21
21
  case 1:
22
- return VElement.cd_(node, virtualizeChildNodes, ownerComponent);
22
+ return VElement.cc_(node, virtualizeChildNodes, ownerComponent);
23
23
  case 3:
24
24
  return new VText(node.nodeValue, ownerComponent);
25
25
  case 11:
@@ -78,5 +78,5 @@ exports.br_ = VElement;
78
78
  exports.bt_ = VText;
79
79
  exports.bu_ = VComponent;
80
80
  exports.bv_ = VFragment;
81
- exports.cd_ = virtualize;
81
+ exports.cc_ = virtualize;
82
82
  exports.bw_ = virtualizeHTML;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "5.32.10",
3
+ "version": "5.32.12",
4
4
  "description": "UI Components + streaming, async, high performance, HTML templating for Node.js and the browser.",
5
5
  "keywords": [
6
6
  "front-end",
@@ -65,7 +65,7 @@
65
65
  },
66
66
  "dependencies": {
67
67
  "@marko/compiler": "^5.34.7",
68
- "@marko/translator-default": "^5.31.15",
68
+ "@marko/translator-default": "^5.31.17",
69
69
  "app-module-path": "^2.2.0",
70
70
  "argly": "^1.2.0",
71
71
  "browser-refresh-client": "1.1.4",
@@ -22,28 +22,51 @@ var FLAG_SIMPLE_ATTRS = 1;
22
22
  var FLAG_CUSTOM_ELEMENT = 2;
23
23
  var FLAG_SPREAD_ATTRS = 4;
24
24
 
25
- var defineProperty = Object.defineProperty;
26
-
27
25
  var ATTR_HREF = "href";
28
- var EMPTY_OBJECT = Object.freeze({});
26
+ var EMPTY_OBJECT = Object.freeze(Object.create(null));
27
+ var specialElHandlers = {
28
+ option: {
29
+ selected: function (fromEl, value) {
30
+ fromEl.selected = value !== undefined;
31
+ },
32
+ },
33
+ input: {
34
+ value: function (fromEl, value) {
35
+ fromEl.value = value === undefined ? "" : value;
36
+ },
37
+ checked: function (fromEl, value) {
38
+ fromEl.checked = value !== undefined;
39
+ },
40
+ },
41
+ };
29
42
 
30
- function convertAttrValue(type, value) {
43
+ function normalizeValue(value) {
31
44
  if (value === true) {
32
45
  return "";
33
- } else if (type == "object") {
34
- switch (value.toString) {
35
- case Object.prototype.toString:
36
- case Array.prototype.toString:
37
- // eslint-disable-next-line no-constant-condition
38
- if ("MARKO_DEBUG") {
39
- complain(
40
- "Relying on JSON.stringify for attribute values is deprecated, in future versions of Marko these will be cast to strings instead.",
41
- );
42
- }
43
- return JSON.stringify(value);
44
- case RegExp.prototype.toString:
45
- return value.source;
46
- }
46
+ }
47
+
48
+ if (value == null || value === false) {
49
+ return;
50
+ }
51
+
52
+ switch (typeof value) {
53
+ case "string":
54
+ return value;
55
+ case "object":
56
+ switch (value.toString) {
57
+ case Object.prototype.toString:
58
+ case Array.prototype.toString:
59
+ // eslint-disable-next-line no-constant-condition
60
+ if ("MARKO_DEBUG") {
61
+ complain(
62
+ "Relying on JSON.stringify for attribute values is deprecated, in future versions of Marko these will be cast to strings instead.",
63
+ );
64
+ }
65
+ return JSON.stringify(value);
66
+ case RegExp.prototype.toString:
67
+ return value.source;
68
+ }
69
+ break;
47
70
  }
48
71
 
49
72
  return value + "";
@@ -57,22 +80,6 @@ function assign(a, b) {
57
80
  }
58
81
  }
59
82
 
60
- function setAttribute(el, namespaceURI, name, value) {
61
- if (namespaceURI === null) {
62
- el.setAttribute(name, value);
63
- } else {
64
- el.setAttributeNS(namespaceURI, name, value);
65
- }
66
- }
67
-
68
- function removeAttribute(el, namespaceURI, name) {
69
- if (namespaceURI === null) {
70
- el.removeAttribute(name);
71
- } else {
72
- el.removeAttributeNS(namespaceURI, name);
73
- }
74
- }
75
-
76
83
  function VElementClone(other) {
77
84
  this.___firstChildInternal = other.___firstChildInternal;
78
85
  this.___parentNode = null;
@@ -177,19 +184,11 @@ VElement.prototype = {
177
184
  assign(el, attributes);
178
185
  } else {
179
186
  for (var attrName in attributes) {
180
- var attrValue = attributes[attrName];
181
-
182
- if (attrValue !== false && attrValue != null) {
183
- var type = typeof attrValue;
184
-
185
- if (type !== "string") {
186
- // Special attributes aren't copied to the real DOM. They are only
187
- // kept in the virtual attributes map
188
- attrValue = convertAttrValue(type, attrValue);
189
- }
187
+ var attrValue = normalizeValue(attributes[attrName]);
190
188
 
189
+ if (attrValue !== undefined) {
191
190
  if (attrName == ATTR_XLINK_HREF) {
192
- setAttribute(el, NS_XLINK, ATTR_HREF, attrValue);
191
+ el.setAttributeNS(NS_XLINK, ATTR_HREF, attrValue);
193
192
  } else {
194
193
  el.setAttribute(attrName, attrValue);
195
194
  }
@@ -197,7 +196,7 @@ VElement.prototype = {
197
196
  }
198
197
 
199
198
  if (tagName === "textarea") {
200
- el.defaultValue = el.value = this.___value;
199
+ el.defaultValue = this.___valueInternal;
201
200
  }
202
201
  }
203
202
 
@@ -217,39 +216,7 @@ VElement.prototype = {
217
216
 
218
217
  inherit(VElement, VNode);
219
218
 
220
- var proto = (VElementClone.prototype = VElement.prototype);
221
-
222
- ["checked", "selected", "disabled"].forEach(function (name) {
223
- defineProperty(proto, name, {
224
- get: function () {
225
- var value = this.___attributes[name];
226
- return value !== false && value != null;
227
- },
228
- });
229
- });
230
-
231
- defineProperty(proto, "___value", {
232
- get: function () {
233
- var value = this.___valueInternal;
234
- if (value == null) {
235
- value = this.___attributes.value;
236
- }
237
- return value != null && value !== false
238
- ? value + ""
239
- : this.___attributes.type === "checkbox" ||
240
- this.___attributes.type === "radio"
241
- ? "on"
242
- : "";
243
- },
244
- });
245
-
246
- VElement.___removePreservedAttributes = function (attrs) {
247
- // By default this static method is a no-op, but if there are any
248
- // compiled components that have "no-update" attributes then
249
- // `preserve-attrs.js` will be imported and this method will be replaced
250
- // with a method that actually does something
251
- return attrs;
252
- };
219
+ VElementClone.prototype = VElement.prototype;
253
220
 
254
221
  function virtualizeElement(node, virtualizeChildNodes, ownerComponent) {
255
222
  var attributes = node.attributes;
@@ -303,20 +270,15 @@ function virtualizeElement(node, virtualizeChildNodes, ownerComponent) {
303
270
  VElement.___virtualize = virtualizeElement;
304
271
 
305
272
  VElement.___morphAttrs = function (fromEl, vFromEl, toEl) {
306
- var removePreservedAttributes = VElement.___removePreservedAttributes;
307
-
308
273
  var fromFlags = vFromEl.___flags;
309
274
  var toFlags = toEl.___flags;
310
-
311
- vElementByDOMNode.set(fromEl, toEl);
312
-
313
275
  var attrs = toEl.___attributes;
314
- var props = toEl.___properties;
315
276
 
316
277
  if (toFlags & FLAG_CUSTOM_ELEMENT) {
317
278
  return assign(fromEl, attrs);
318
279
  }
319
280
 
281
+ var props = toEl.___properties;
320
282
  var attrName;
321
283
 
322
284
  // We use expando properties to associate the previous HTML
@@ -329,16 +291,12 @@ VElement.___morphAttrs = function (fromEl, vFromEl, toEl) {
329
291
 
330
292
  var oldAttrs = vFromEl.___attributes;
331
293
 
332
- if (oldAttrs) {
333
- if (oldAttrs === attrs) {
334
- // For constant attributes the same object will be provided
335
- // every render and we can use that to our advantage to
336
- // not waste time diffing a constant, immutable attribute
337
- // map.
338
- return;
339
- } else {
340
- oldAttrs = removePreservedAttributes(oldAttrs, props);
341
- }
294
+ if (oldAttrs === attrs) {
295
+ // For constant attributes the same object will be provided
296
+ // every render and we can use that to our advantage to
297
+ // not waste time diffing a constant, immutable attribute
298
+ // map.
299
+ return;
342
300
  }
343
301
 
344
302
  var attrValue;
@@ -356,36 +314,32 @@ VElement.___morphAttrs = function (fromEl, vFromEl, toEl) {
356
314
  return;
357
315
  }
358
316
 
359
- // In some cases we only want to set an attribute value for the first
360
- // render or we don't want certain attributes to be touched. To support
361
- // that use case we delete out all of the preserved attributes
362
- // so it's as if they never existed.
363
- attrs = removePreservedAttributes(attrs, props, true);
364
-
365
- var namespaceURI;
317
+ var preserve = (props && props.pa) || EMPTY_OBJECT;
318
+ var specialAttrs = specialElHandlers[toEl.___nodeName] || EMPTY_OBJECT;
319
+ var specialAttr;
366
320
 
367
321
  // Loop over all of the attributes in the attribute map and compare
368
322
  // them to the value in the old map. However, if the value is
369
323
  // null/undefined/false then we want to remove the attribute
370
324
  for (attrName in attrs) {
371
- attrValue = attrs[attrName];
372
- namespaceURI = null;
373
-
374
- if (attrName === ATTR_XLINK_HREF) {
375
- namespaceURI = NS_XLINK;
376
- attrName = ATTR_HREF;
377
- }
378
-
379
- if (attrValue == null || attrValue === false) {
380
- removeAttribute(fromEl, namespaceURI, attrName);
381
- } else if (oldAttrs[attrName] !== attrValue) {
382
- var type = typeof attrValue;
383
-
384
- if (type !== "string") {
385
- attrValue = convertAttrValue(type, attrValue);
325
+ if (
326
+ !preserve[attrName] &&
327
+ normalizeValue(oldAttrs[attrName]) !==
328
+ (attrValue = normalizeValue(attrs[attrName]))
329
+ ) {
330
+ if ((specialAttr = specialAttrs[attrName])) {
331
+ specialAttr(fromEl, attrValue);
332
+ } else if (attrName === ATTR_XLINK_HREF) {
333
+ if (attrValue === undefined) {
334
+ fromEl.removeAttributeNS(NS_XLINK, ATTR_HREF);
335
+ } else {
336
+ fromEl.setAttributeNS(NS_XLINK, ATTR_HREF, attrValue);
337
+ }
338
+ } else if (attrValue === undefined) {
339
+ fromEl.removeAttribute(attrName);
340
+ } else {
341
+ fromEl.setAttribute(attrName, attrValue);
386
342
  }
387
-
388
- setAttribute(fromEl, namespaceURI, attrName, attrValue);
389
343
  }
390
344
  }
391
345
 
@@ -402,7 +356,9 @@ VElement.___morphAttrs = function (fromEl, vFromEl, toEl) {
402
356
  if (toEl.___key === null || fromFlags & FLAG_SPREAD_ATTRS) {
403
357
  for (attrName in oldAttrs) {
404
358
  if (!(attrName in attrs)) {
405
- if (attrName === ATTR_XLINK_HREF) {
359
+ if ((specialAttr = specialAttrs[attrName])) {
360
+ specialAttr(fromEl, undefined);
361
+ } else if (attrName === ATTR_XLINK_HREF) {
406
362
  fromEl.removeAttributeNS(ATTR_XLINK_HREF, ATTR_HREF);
407
363
  } else {
408
364
  fromEl.removeAttribute(attrName);
@@ -52,8 +52,6 @@ VNode.prototype = {
52
52
  if (child.___Text) {
53
53
  var childValue = child.___nodeValue;
54
54
  this.___valueInternal = (this.___valueInternal || "") + childValue;
55
- } else if (child.___preserve || child.___preserveBody) {
56
- this.___preserveTextAreaValue = true;
57
55
  } else {
58
56
  throw TypeError();
59
57
  }
@@ -11,7 +11,6 @@ var KeySequence = require("../../components/KeySequence");
11
11
  var VElement = require("../vdom").___VElement;
12
12
  var fragment = require("./fragment");
13
13
  var helpers = require("./helpers");
14
- var specialElHandlers = require("./specialElHandlers");
15
14
  var virtualizeElement = VElement.___virtualize;
16
15
  var morphAttrs = VElement.___morphAttrs;
17
16
  var keysByDOMNode = domData.___keyByDOMNode;
@@ -680,8 +679,9 @@ function morphdom(fromNode, toNode, host, componentsContext) {
680
679
 
681
680
  function morphEl(fromEl, vFromEl, toEl, parentComponent) {
682
681
  var nodeName = toEl.___nodeName;
683
-
684
682
  var constId = toEl.___constId;
683
+ vElementByDOMNode.set(fromEl, toEl);
684
+
685
685
  if (constId !== undefined && vFromEl.___constId === constId) {
686
686
  return;
687
687
  }
@@ -692,14 +692,15 @@ function morphdom(fromNode, toNode, host, componentsContext) {
692
692
  return;
693
693
  }
694
694
 
695
- if (nodeName !== "textarea") {
695
+ if (nodeName === "textarea") {
696
+ var newValue = toEl.___valueInternal || "";
697
+ var oldValue = vFromEl.___valueInternal || "";
698
+ if (oldValue !== newValue) {
699
+ fromEl.value = newValue;
700
+ }
701
+ } else {
696
702
  morphChildren(fromEl, toEl, parentComponent);
697
703
  }
698
-
699
- var specialElHandler = specialElHandlers[nodeName];
700
- if (specialElHandler !== undefined) {
701
- specialElHandler(fromEl, toEl);
702
- }
703
704
  } // END: morphEl(...)
704
705
 
705
706
  // eslint-disable-next-line no-constant-condition
@@ -1,106 +0,0 @@
1
- "use strict";function syncBooleanAttrProp(fromEl, toEl, name) {
2
- if (fromEl[name] !== toEl[name]) {
3
- fromEl[name] = toEl[name];
4
- if (fromEl[name]) {
5
- fromEl.setAttribute(name, "");
6
- } else {
7
- fromEl.removeAttribute(name, "");
8
- }
9
- }
10
- }
11
-
12
- function forEachOption(el, fn, i) {
13
- var curChild = el.ay_;
14
-
15
- while (curChild) {
16
- if (curChild.bY_ === "option") {
17
- fn(curChild, ++i);
18
- } else {
19
- i = forEachOption(curChild, fn, i);
20
- }
21
-
22
- curChild = curChild.ci_;
23
- }
24
-
25
- return i;
26
- }
27
-
28
- // We use a JavaScript class to benefit from fast property lookup
29
- function SpecialElHandlers() {}
30
- SpecialElHandlers.prototype = {
31
- /**
32
- * Needed for IE. Apparently IE doesn't think that "selected" is an
33
- * attribute when reading over the attributes using selectEl.attributes
34
- */
35
- option: function (fromEl, toEl) {
36
- syncBooleanAttrProp(fromEl, toEl, "selected");
37
- },
38
- button: function (fromEl, toEl) {
39
- syncBooleanAttrProp(fromEl, toEl, "disabled");
40
- },
41
- /**
42
- * The "value" attribute is special for the <input> element since it sets
43
- * the initial value. Changing the "value" attribute without changing the
44
- * "value" property will have no effect since it is only used to the set the
45
- * initial value. Similar for the "checked" attribute, and "disabled".
46
- */
47
- input: function (fromEl, toEl) {
48
- syncBooleanAttrProp(fromEl, toEl, "checked");
49
- syncBooleanAttrProp(fromEl, toEl, "disabled");
50
-
51
- if (fromEl.value != toEl.e_) {
52
- fromEl.value = toEl.e_;
53
- }
54
-
55
- if (fromEl.hasAttribute("value") && !toEl.cb_("value")) {
56
- fromEl.removeAttribute("value");
57
- }
58
- },
59
-
60
- textarea: function (fromEl, toEl) {
61
- if (toEl.cl_) {
62
- return;
63
- }
64
-
65
- var newValue = toEl.e_;
66
- if (fromEl.value != newValue) {
67
- fromEl.value = newValue;
68
- }
69
-
70
- var firstChild = fromEl.firstChild;
71
- if (firstChild) {
72
- // Needed for IE. Apparently IE sets the placeholder as the
73
- // node value and vise versa. This ignores an empty update.
74
- var oldValue = firstChild.nodeValue;
75
-
76
- if (
77
- oldValue == newValue ||
78
- !newValue && oldValue == fromEl.placeholder)
79
- {
80
- return;
81
- }
82
-
83
- firstChild.nodeValue = newValue;
84
- }
85
- },
86
- select: function (fromEl, toEl) {
87
- if (!toEl.cb_("multiple")) {
88
- var selected = 0;
89
- forEachOption(
90
- toEl,
91
- function (option, i) {
92
- if (option.cb_("selected")) {
93
- selected = i;
94
- }
95
- },
96
- -1
97
- );
98
-
99
- if (fromEl.selectedIndex !== selected) {
100
- fromEl.selectedIndex = selected;
101
- }
102
- }
103
- }
104
- };
105
-
106
- module.exports = new SpecialElHandlers();
@@ -1,15 +0,0 @@
1
- "use strict";var extend = require("raptor-util/extend");
2
-
3
- function removePreservedAttributes(attrs, props) {
4
- var preservedAttrs = props && props.pa;
5
- if (preservedAttrs) {
6
- attrs = extend({}, attrs);
7
- preservedAttrs.forEach(function (preservedAttrName) {
8
- delete attrs[preservedAttrName];
9
- });
10
- }
11
-
12
- return attrs;
13
- }
14
-
15
- require("./VElement").cc_ = removePreservedAttributes;
@@ -1,106 +0,0 @@
1
- function syncBooleanAttrProp(fromEl, toEl, name) {
2
- if (fromEl[name] !== toEl[name]) {
3
- fromEl[name] = toEl[name];
4
- if (fromEl[name]) {
5
- fromEl.setAttribute(name, "");
6
- } else {
7
- fromEl.removeAttribute(name, "");
8
- }
9
- }
10
- }
11
-
12
- function forEachOption(el, fn, i) {
13
- var curChild = el.___firstChild;
14
-
15
- while (curChild) {
16
- if (curChild.___nodeName === "option") {
17
- fn(curChild, ++i);
18
- } else {
19
- i = forEachOption(curChild, fn, i);
20
- }
21
-
22
- curChild = curChild.___nextSibling;
23
- }
24
-
25
- return i;
26
- }
27
-
28
- // We use a JavaScript class to benefit from fast property lookup
29
- function SpecialElHandlers() {}
30
- SpecialElHandlers.prototype = {
31
- /**
32
- * Needed for IE. Apparently IE doesn't think that "selected" is an
33
- * attribute when reading over the attributes using selectEl.attributes
34
- */
35
- option: function (fromEl, toEl) {
36
- syncBooleanAttrProp(fromEl, toEl, "selected");
37
- },
38
- button: function (fromEl, toEl) {
39
- syncBooleanAttrProp(fromEl, toEl, "disabled");
40
- },
41
- /**
42
- * The "value" attribute is special for the <input> element since it sets
43
- * the initial value. Changing the "value" attribute without changing the
44
- * "value" property will have no effect since it is only used to the set the
45
- * initial value. Similar for the "checked" attribute, and "disabled".
46
- */
47
- input: function (fromEl, toEl) {
48
- syncBooleanAttrProp(fromEl, toEl, "checked");
49
- syncBooleanAttrProp(fromEl, toEl, "disabled");
50
-
51
- if (fromEl.value != toEl.___value) {
52
- fromEl.value = toEl.___value;
53
- }
54
-
55
- if (fromEl.hasAttribute("value") && !toEl.___hasAttribute("value")) {
56
- fromEl.removeAttribute("value");
57
- }
58
- },
59
-
60
- textarea: function (fromEl, toEl) {
61
- if (toEl.___preserveTextAreaValue) {
62
- return;
63
- }
64
-
65
- var newValue = toEl.___value;
66
- if (fromEl.value != newValue) {
67
- fromEl.value = newValue;
68
- }
69
-
70
- var firstChild = fromEl.firstChild;
71
- if (firstChild) {
72
- // Needed for IE. Apparently IE sets the placeholder as the
73
- // node value and vise versa. This ignores an empty update.
74
- var oldValue = firstChild.nodeValue;
75
-
76
- if (
77
- oldValue == newValue ||
78
- (!newValue && oldValue == fromEl.placeholder)
79
- ) {
80
- return;
81
- }
82
-
83
- firstChild.nodeValue = newValue;
84
- }
85
- },
86
- select: function (fromEl, toEl) {
87
- if (!toEl.___hasAttribute("multiple")) {
88
- var selected = 0;
89
- forEachOption(
90
- toEl,
91
- function (option, i) {
92
- if (option.___hasAttribute("selected")) {
93
- selected = i;
94
- }
95
- },
96
- -1,
97
- );
98
-
99
- if (fromEl.selectedIndex !== selected) {
100
- fromEl.selectedIndex = selected;
101
- }
102
- }
103
- },
104
- };
105
-
106
- module.exports = new SpecialElHandlers();
@@ -1,15 +0,0 @@
1
- var extend = require("raptor-util/extend");
2
-
3
- function removePreservedAttributes(attrs, props) {
4
- var preservedAttrs = props && props.pa;
5
- if (preservedAttrs) {
6
- attrs = extend({}, attrs);
7
- preservedAttrs.forEach(function (preservedAttrName) {
8
- delete attrs[preservedAttrName];
9
- });
10
- }
11
-
12
- return attrs;
13
- }
14
-
15
- require("./VElement").___removePreservedAttributes = removePreservedAttributes;