@lwc/engine-core 2.7.3 → 2.7.4
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/dist/engine-core.cjs.js +857 -784
- package/dist/engine-core.js +855 -782
- package/package.json +4 -4
- package/types/framework/api.d.ts +1 -1
- package/types/framework/component.d.ts +1 -1
- package/types/framework/def.d.ts +1 -0
- package/types/framework/hydration.d.ts +3 -0
- package/types/framework/invoker.d.ts +1 -1
- package/types/framework/main.d.ts +1 -1
- package/types/framework/modules/attrs.d.ts +2 -2
- package/types/framework/modules/computed-class-attr.d.ts +2 -2
- package/types/framework/modules/computed-style-attr.d.ts +2 -2
- package/types/framework/modules/events.d.ts +2 -2
- package/types/framework/modules/props.d.ts +2 -2
- package/types/framework/modules/static-class-attr.d.ts +2 -2
- package/types/framework/modules/static-style-attr.d.ts +2 -2
- package/types/framework/rendering.d.ts +9 -0
- package/types/framework/services.d.ts +1 -1
- package/types/framework/stylesheet.d.ts +1 -1
- package/types/framework/template.d.ts +1 -1
- package/types/framework/vm.d.ts +10 -5
- package/types/{3rdparty/snabbdom/types.d.ts → framework/vnodes.d.ts} +32 -32
- package/types/3rdparty/snabbdom/snabbdom.d.ts +0 -11
- package/types/framework/hooks.d.ts +0 -18
package/dist/engine-core.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* proxy-compat-disable */
|
|
2
|
-
import { seal, create, isFunction as isFunction$1, ArrayPush as ArrayPush$1, isUndefined as isUndefined$1, ArrayIndexOf, ArraySplice, StringToLowerCase, ArrayJoin, isNull,
|
|
2
|
+
import { seal, create, isFunction as isFunction$1, ArrayPush as ArrayPush$1, isUndefined as isUndefined$1, ArrayIndexOf, ArraySplice, StringToLowerCase, ArrayJoin, isNull, isFrozen, defineProperty, assign, forEach, keys, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getOwnPropertyNames as getOwnPropertyNames$1, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, isObject, assert, KEY__SYNTHETIC_MODE, toString as toString$1, isFalse, isTrue, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, freeze, htmlPropertyToAttribute, ArraySlice, hasOwnProperty as hasOwnProperty$1, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, isString, StringSlice, SVG_NAMESPACE, KEY__SHADOW_RESOLVER, isArray as isArray$1, isNumber, StringReplace, KEY__SCOPED_CSS, noop, ArrayUnshift, ArrayFilter } from '@lwc/shared';
|
|
3
3
|
import { runtimeFlags } from '@lwc/features';
|
|
4
4
|
export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
|
|
5
5
|
|
|
@@ -397,6 +397,24 @@ function getErrorComponentStack(vm) {
|
|
|
397
397
|
return wcStack.reverse().join('\n\t');
|
|
398
398
|
}
|
|
399
399
|
|
|
400
|
+
/*
|
|
401
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
402
|
+
* All rights reserved.
|
|
403
|
+
* SPDX-License-Identifier: MIT
|
|
404
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
405
|
+
*/
|
|
406
|
+
function addErrorComponentStack(vm, error) {
|
|
407
|
+
if (!isFrozen(error) && isUndefined$1(error.wcStack)) {
|
|
408
|
+
const wcStack = getErrorComponentStack(vm);
|
|
409
|
+
defineProperty(error, 'wcStack', {
|
|
410
|
+
get() {
|
|
411
|
+
return wcStack;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
400
418
|
/*
|
|
401
419
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
402
420
|
* All rights reserved.
|
|
@@ -438,205 +456,10 @@ function logWarn(message, vm) {
|
|
|
438
456
|
* SPDX-License-Identifier: MIT
|
|
439
457
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
440
458
|
*/
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
function sameVnode(vnode1, vnode2) {
|
|
447
|
-
return vnode1.key === vnode2.key && vnode1.sel === vnode2.sel;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
function isVNode(vnode) {
|
|
451
|
-
return vnode != null;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
function createKeyToOldIdx(children, beginIdx, endIdx) {
|
|
455
|
-
const map = {};
|
|
456
|
-
let j, key, ch; // TODO [#1637]: simplify this by assuming that all vnodes has keys
|
|
457
|
-
|
|
458
|
-
for (j = beginIdx; j <= endIdx; ++j) {
|
|
459
|
-
ch = children[j];
|
|
460
|
-
|
|
461
|
-
if (isVNode(ch)) {
|
|
462
|
-
key = ch.key;
|
|
463
|
-
|
|
464
|
-
if (key !== undefined) {
|
|
465
|
-
map[key] = j;
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
return map;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
|
|
474
|
-
for (; startIdx <= endIdx; ++startIdx) {
|
|
475
|
-
const ch = vnodes[startIdx];
|
|
476
|
-
|
|
477
|
-
if (isVNode(ch)) {
|
|
478
|
-
ch.hook.create(ch);
|
|
479
|
-
ch.hook.insert(ch, parentElm, before);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
|
|
485
|
-
for (; startIdx <= endIdx; ++startIdx) {
|
|
486
|
-
const ch = vnodes[startIdx]; // text nodes do not have logic associated to them
|
|
487
|
-
|
|
488
|
-
if (isVNode(ch)) {
|
|
489
|
-
ch.hook.remove(ch, parentElm);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
function updateDynamicChildren(parentElm, oldCh, newCh) {
|
|
495
|
-
let oldStartIdx = 0;
|
|
496
|
-
let newStartIdx = 0;
|
|
497
|
-
let oldEndIdx = oldCh.length - 1;
|
|
498
|
-
let oldStartVnode = oldCh[0];
|
|
499
|
-
let oldEndVnode = oldCh[oldEndIdx];
|
|
500
|
-
const newChEnd = newCh.length - 1;
|
|
501
|
-
let newEndIdx = newChEnd;
|
|
502
|
-
let newStartVnode = newCh[0];
|
|
503
|
-
let newEndVnode = newCh[newEndIdx];
|
|
504
|
-
let oldKeyToIdx;
|
|
505
|
-
let idxInOld;
|
|
506
|
-
let elmToMove;
|
|
507
|
-
let before;
|
|
508
|
-
|
|
509
|
-
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
|
|
510
|
-
if (!isVNode(oldStartVnode)) {
|
|
511
|
-
oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left
|
|
512
|
-
} else if (!isVNode(oldEndVnode)) {
|
|
513
|
-
oldEndVnode = oldCh[--oldEndIdx];
|
|
514
|
-
} else if (!isVNode(newStartVnode)) {
|
|
515
|
-
newStartVnode = newCh[++newStartIdx];
|
|
516
|
-
} else if (!isVNode(newEndVnode)) {
|
|
517
|
-
newEndVnode = newCh[--newEndIdx];
|
|
518
|
-
} else if (sameVnode(oldStartVnode, newStartVnode)) {
|
|
519
|
-
patchVnode(oldStartVnode, newStartVnode);
|
|
520
|
-
oldStartVnode = oldCh[++oldStartIdx];
|
|
521
|
-
newStartVnode = newCh[++newStartIdx];
|
|
522
|
-
} else if (sameVnode(oldEndVnode, newEndVnode)) {
|
|
523
|
-
patchVnode(oldEndVnode, newEndVnode);
|
|
524
|
-
oldEndVnode = oldCh[--oldEndIdx];
|
|
525
|
-
newEndVnode = newCh[--newEndIdx];
|
|
526
|
-
} else if (sameVnode(oldStartVnode, newEndVnode)) {
|
|
527
|
-
// Vnode moved right
|
|
528
|
-
patchVnode(oldStartVnode, newEndVnode);
|
|
529
|
-
newEndVnode.hook.move(oldStartVnode, parentElm, nextSibling(oldEndVnode.elm));
|
|
530
|
-
oldStartVnode = oldCh[++oldStartIdx];
|
|
531
|
-
newEndVnode = newCh[--newEndIdx];
|
|
532
|
-
} else if (sameVnode(oldEndVnode, newStartVnode)) {
|
|
533
|
-
// Vnode moved left
|
|
534
|
-
patchVnode(oldEndVnode, newStartVnode);
|
|
535
|
-
newStartVnode.hook.move(oldEndVnode, parentElm, oldStartVnode.elm);
|
|
536
|
-
oldEndVnode = oldCh[--oldEndIdx];
|
|
537
|
-
newStartVnode = newCh[++newStartIdx];
|
|
538
|
-
} else {
|
|
539
|
-
if (oldKeyToIdx === undefined) {
|
|
540
|
-
oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
idxInOld = oldKeyToIdx[newStartVnode.key];
|
|
544
|
-
|
|
545
|
-
if (isUndef(idxInOld)) {
|
|
546
|
-
// New element
|
|
547
|
-
newStartVnode.hook.create(newStartVnode);
|
|
548
|
-
newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm);
|
|
549
|
-
newStartVnode = newCh[++newStartIdx];
|
|
550
|
-
} else {
|
|
551
|
-
elmToMove = oldCh[idxInOld];
|
|
552
|
-
|
|
553
|
-
if (isVNode(elmToMove)) {
|
|
554
|
-
if (elmToMove.sel !== newStartVnode.sel) {
|
|
555
|
-
// New element
|
|
556
|
-
newStartVnode.hook.create(newStartVnode);
|
|
557
|
-
newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm);
|
|
558
|
-
} else {
|
|
559
|
-
patchVnode(elmToMove, newStartVnode);
|
|
560
|
-
oldCh[idxInOld] = undefined;
|
|
561
|
-
newStartVnode.hook.move(elmToMove, parentElm, oldStartVnode.elm);
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
newStartVnode = newCh[++newStartIdx];
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
|
|
571
|
-
if (oldStartIdx > oldEndIdx) {
|
|
572
|
-
// There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
|
|
573
|
-
// already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
|
|
574
|
-
let i = newEndIdx;
|
|
575
|
-
let n;
|
|
576
|
-
|
|
577
|
-
do {
|
|
578
|
-
n = newCh[++i];
|
|
579
|
-
} while (!isVNode(n) && i < newChEnd);
|
|
580
|
-
|
|
581
|
-
before = isVNode(n) ? n.elm : null;
|
|
582
|
-
addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
|
|
583
|
-
} else {
|
|
584
|
-
removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
function updateStaticChildren(parentElm, oldCh, newCh) {
|
|
589
|
-
const oldChLength = oldCh.length;
|
|
590
|
-
const newChLength = newCh.length;
|
|
591
|
-
|
|
592
|
-
if (oldChLength === 0) {
|
|
593
|
-
// the old list is empty, we can directly insert anything new
|
|
594
|
-
addVnodes(parentElm, null, newCh, 0, newChLength);
|
|
595
|
-
return;
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
if (newChLength === 0) {
|
|
599
|
-
// the old list is nonempty and the new list is empty so we can directly remove all old nodes
|
|
600
|
-
// this is the case in which the dynamic children of an if-directive should be removed
|
|
601
|
-
removeVnodes(parentElm, oldCh, 0, oldChLength);
|
|
602
|
-
return;
|
|
603
|
-
} // if the old list is not empty, the new list MUST have the same
|
|
604
|
-
// amount of nodes, that's why we call this static children
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
let referenceElm = null;
|
|
608
|
-
|
|
609
|
-
for (let i = newChLength - 1; i >= 0; i -= 1) {
|
|
610
|
-
const vnode = newCh[i];
|
|
611
|
-
const oldVNode = oldCh[i];
|
|
612
|
-
|
|
613
|
-
if (vnode !== oldVNode) {
|
|
614
|
-
if (isVNode(oldVNode)) {
|
|
615
|
-
if (isVNode(vnode)) {
|
|
616
|
-
// both vnodes must be equivalent, and se just need to patch them
|
|
617
|
-
patchVnode(oldVNode, vnode);
|
|
618
|
-
referenceElm = vnode.elm;
|
|
619
|
-
} else {
|
|
620
|
-
// removing the old vnode since the new one is null
|
|
621
|
-
oldVNode.hook.remove(oldVNode, parentElm);
|
|
622
|
-
}
|
|
623
|
-
} else if (isVNode(vnode)) {
|
|
624
|
-
// this condition is unnecessary
|
|
625
|
-
vnode.hook.create(vnode); // insert the new node one since the old one is null
|
|
626
|
-
|
|
627
|
-
vnode.hook.insert(vnode, parentElm, referenceElm);
|
|
628
|
-
referenceElm = vnode.elm;
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
function patchVnode(oldVnode, vnode) {
|
|
635
|
-
if (oldVnode !== vnode) {
|
|
636
|
-
vnode.elm = oldVnode.elm;
|
|
637
|
-
vnode.hook.update(oldVnode, vnode);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
459
|
+
// This is a temporary workaround to get the @lwc/engine-server to evaluate in node without having
|
|
460
|
+
// to inject at runtime.
|
|
461
|
+
const HTMLElementConstructor = typeof HTMLElement !== 'undefined' ? HTMLElement : function () {};
|
|
462
|
+
const HTMLElementPrototype = HTMLElementConstructor.prototype;
|
|
640
463
|
|
|
641
464
|
/*
|
|
642
465
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
@@ -754,6 +577,40 @@ function unlockAttribute(elm, key) {
|
|
|
754
577
|
controlledAttributeName = key;
|
|
755
578
|
}
|
|
756
579
|
|
|
580
|
+
/*
|
|
581
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
582
|
+
* All rights reserved.
|
|
583
|
+
* SPDX-License-Identifier: MIT
|
|
584
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
585
|
+
*/
|
|
586
|
+
/**
|
|
587
|
+
* This is a descriptor map that contains
|
|
588
|
+
* all standard properties that a Custom Element can support (including AOM properties), which
|
|
589
|
+
* determines what kind of capabilities the Base HTML Element and
|
|
590
|
+
* Base Lightning Element should support.
|
|
591
|
+
*/
|
|
592
|
+
|
|
593
|
+
const HTMLElementOriginalDescriptors = create(null);
|
|
594
|
+
forEach.call(keys(AriaPropNameToAttrNameMap), propName => {
|
|
595
|
+
// Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because
|
|
596
|
+
// in IE11, some properties are on Element.prototype instead of HTMLElement, just to be sure.
|
|
597
|
+
const descriptor = getPropertyDescriptor(HTMLElementPrototype, propName);
|
|
598
|
+
|
|
599
|
+
if (!isUndefined$1(descriptor)) {
|
|
600
|
+
HTMLElementOriginalDescriptors[propName] = descriptor;
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
forEach.call(defaultDefHTMLPropertyNames, propName => {
|
|
604
|
+
// Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because
|
|
605
|
+
// in IE11, id property is on Element.prototype instead of HTMLElement, and we suspect that more will fall into
|
|
606
|
+
// this category, so, better to be sure.
|
|
607
|
+
const descriptor = getPropertyDescriptor(HTMLElementPrototype, propName);
|
|
608
|
+
|
|
609
|
+
if (!isUndefined$1(descriptor)) {
|
|
610
|
+
HTMLElementOriginalDescriptors[propName] = descriptor;
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
|
|
757
614
|
/*
|
|
758
615
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
759
616
|
* All rights reserved.
|
|
@@ -1118,53 +975,8 @@ function patchLightningElementPrototypeWithRestrictions(proto) {
|
|
|
1118
975
|
defineProperties(proto, getLightningElementPrototypeRestrictionsDescriptors(proto));
|
|
1119
976
|
}
|
|
1120
977
|
|
|
1121
|
-
|
|
1122
|
-
* Copyright (
|
|
1123
|
-
* All rights reserved.
|
|
1124
|
-
* SPDX-License-Identifier: MIT
|
|
1125
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
1126
|
-
*/
|
|
1127
|
-
// This is a temporary workaround to get the @lwc/engine-server to evaluate in node without having
|
|
1128
|
-
// to inject at runtime.
|
|
1129
|
-
const HTMLElementConstructor = typeof HTMLElement !== 'undefined' ? HTMLElement : function () {};
|
|
1130
|
-
const HTMLElementPrototype = HTMLElementConstructor.prototype;
|
|
1131
|
-
|
|
1132
|
-
/*
|
|
1133
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
1134
|
-
* All rights reserved.
|
|
1135
|
-
* SPDX-License-Identifier: MIT
|
|
1136
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
1137
|
-
*/
|
|
1138
|
-
/**
|
|
1139
|
-
* This is a descriptor map that contains
|
|
1140
|
-
* all standard properties that a Custom Element can support (including AOM properties), which
|
|
1141
|
-
* determines what kind of capabilities the Base HTML Element and
|
|
1142
|
-
* Base Lightning Element should support.
|
|
1143
|
-
*/
|
|
1144
|
-
|
|
1145
|
-
const HTMLElementOriginalDescriptors = create(null);
|
|
1146
|
-
forEach.call(keys(AriaPropNameToAttrNameMap), propName => {
|
|
1147
|
-
// Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because
|
|
1148
|
-
// in IE11, some properties are on Element.prototype instead of HTMLElement, just to be sure.
|
|
1149
|
-
const descriptor = getPropertyDescriptor(HTMLElementPrototype, propName);
|
|
1150
|
-
|
|
1151
|
-
if (!isUndefined$1(descriptor)) {
|
|
1152
|
-
HTMLElementOriginalDescriptors[propName] = descriptor;
|
|
1153
|
-
}
|
|
1154
|
-
});
|
|
1155
|
-
forEach.call(defaultDefHTMLPropertyNames, propName => {
|
|
1156
|
-
// Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because
|
|
1157
|
-
// in IE11, id property is on Element.prototype instead of HTMLElement, and we suspect that more will fall into
|
|
1158
|
-
// this category, so, better to be sure.
|
|
1159
|
-
const descriptor = getPropertyDescriptor(HTMLElementPrototype, propName);
|
|
1160
|
-
|
|
1161
|
-
if (!isUndefined$1(descriptor)) {
|
|
1162
|
-
HTMLElementOriginalDescriptors[propName] = descriptor;
|
|
1163
|
-
}
|
|
1164
|
-
});
|
|
1165
|
-
|
|
1166
|
-
/**
|
|
1167
|
-
* Copyright (C) 2017 salesforce.com, inc.
|
|
978
|
+
/**
|
|
979
|
+
* Copyright (C) 2017 salesforce.com, inc.
|
|
1168
980
|
*/
|
|
1169
981
|
const {
|
|
1170
982
|
isArray
|
|
@@ -2079,7 +1891,9 @@ const LightningElement = function () {
|
|
|
2079
1891
|
if (vm.renderMode === 1
|
|
2080
1892
|
/* Shadow */
|
|
2081
1893
|
) {
|
|
2082
|
-
doAttachShadow(vm);
|
|
1894
|
+
vm.renderRoot = doAttachShadow(vm);
|
|
1895
|
+
} else {
|
|
1896
|
+
vm.renderRoot = elm;
|
|
2083
1897
|
} // Adding extra guard rails in DEV mode.
|
|
2084
1898
|
|
|
2085
1899
|
|
|
@@ -2100,19 +1914,21 @@ function doAttachShadow(vm) {
|
|
|
2100
1914
|
ctor
|
|
2101
1915
|
}
|
|
2102
1916
|
} = vm;
|
|
2103
|
-
const
|
|
1917
|
+
const shadowRoot = attachShadow(elm, {
|
|
2104
1918
|
[KEY__SYNTHETIC_MODE]: shadowMode === 1
|
|
2105
1919
|
/* Synthetic */
|
|
2106
1920
|
,
|
|
2107
1921
|
delegatesFocus: Boolean(ctor.delegatesFocus),
|
|
2108
1922
|
mode
|
|
2109
1923
|
});
|
|
2110
|
-
vm.
|
|
2111
|
-
associateVM(
|
|
1924
|
+
vm.shadowRoot = shadowRoot;
|
|
1925
|
+
associateVM(shadowRoot, vm);
|
|
2112
1926
|
|
|
2113
1927
|
if (process.env.NODE_ENV !== 'production') {
|
|
2114
|
-
patchShadowRootWithRestrictions(
|
|
1928
|
+
patchShadowRootWithRestrictions(shadowRoot);
|
|
2115
1929
|
}
|
|
1930
|
+
|
|
1931
|
+
return shadowRoot;
|
|
2116
1932
|
}
|
|
2117
1933
|
|
|
2118
1934
|
function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
|
|
@@ -2280,7 +2096,7 @@ LightningElement.prototype = {
|
|
|
2280
2096
|
}
|
|
2281
2097
|
}
|
|
2282
2098
|
|
|
2283
|
-
return vm.
|
|
2099
|
+
return vm.shadowRoot;
|
|
2284
2100
|
},
|
|
2285
2101
|
|
|
2286
2102
|
get shadowRoot() {
|
|
@@ -3664,6 +3480,10 @@ function getComponentInternalDef(Ctor) {
|
|
|
3664
3480
|
|
|
3665
3481
|
return def;
|
|
3666
3482
|
}
|
|
3483
|
+
function getComponentHtmlPrototype(Ctor) {
|
|
3484
|
+
const def = getComponentInternalDef(Ctor);
|
|
3485
|
+
return def.bridge;
|
|
3486
|
+
}
|
|
3667
3487
|
const lightingElementDef = {
|
|
3668
3488
|
ctor: LightningElement,
|
|
3669
3489
|
name: LightningElement.name,
|
|
@@ -3727,14 +3547,68 @@ function getComponentDef(Ctor) {
|
|
|
3727
3547
|
};
|
|
3728
3548
|
}
|
|
3729
3549
|
|
|
3550
|
+
/*
|
|
3551
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
|
3552
|
+
* All rights reserved.
|
|
3553
|
+
* SPDX-License-Identifier: MIT
|
|
3554
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3555
|
+
*/
|
|
3556
|
+
function getUpgradableConstructor(tagName) {
|
|
3557
|
+
// Should never get a tag with upper case letter at this point, the compiler should
|
|
3558
|
+
// produce only tags with lowercase letters
|
|
3559
|
+
// But, for backwards compatibility, we will lower case the tagName
|
|
3560
|
+
tagName = tagName.toLowerCase();
|
|
3561
|
+
let CE = getCustomElement(tagName);
|
|
3562
|
+
|
|
3563
|
+
if (!isUndefined$1(CE)) {
|
|
3564
|
+
return CE;
|
|
3565
|
+
}
|
|
3566
|
+
/**
|
|
3567
|
+
* LWC Upgradable Element reference to an element that was created
|
|
3568
|
+
* via the scoped registry mechanism, and that is ready to be upgraded.
|
|
3569
|
+
*/
|
|
3570
|
+
|
|
3571
|
+
|
|
3572
|
+
CE = class LWCUpgradableElement extends HTMLElementExported {
|
|
3573
|
+
constructor(upgradeCallback) {
|
|
3574
|
+
super();
|
|
3575
|
+
|
|
3576
|
+
if (isFunction$1(upgradeCallback)) {
|
|
3577
|
+
upgradeCallback(this); // nothing to do with the result for now
|
|
3578
|
+
}
|
|
3579
|
+
}
|
|
3580
|
+
|
|
3581
|
+
};
|
|
3582
|
+
defineCustomElement(tagName, CE);
|
|
3583
|
+
return CE;
|
|
3584
|
+
}
|
|
3585
|
+
|
|
3586
|
+
/*
|
|
3587
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
3588
|
+
* All rights reserved.
|
|
3589
|
+
* SPDX-License-Identifier: MIT
|
|
3590
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3591
|
+
*/
|
|
3592
|
+
function isVBaseElement(vnode) {
|
|
3593
|
+
const {
|
|
3594
|
+
type
|
|
3595
|
+
} = vnode;
|
|
3596
|
+
return type === 2
|
|
3597
|
+
/* Element */
|
|
3598
|
+
|| type === 3
|
|
3599
|
+
/* CustomElement */
|
|
3600
|
+
;
|
|
3601
|
+
}
|
|
3602
|
+
function isSameVnode(vnode1, vnode2) {
|
|
3603
|
+
return vnode1.key === vnode2.key && vnode1.sel === vnode2.sel;
|
|
3604
|
+
}
|
|
3605
|
+
|
|
3730
3606
|
/*
|
|
3731
3607
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
3732
3608
|
* All rights reserved.
|
|
3733
3609
|
* SPDX-License-Identifier: MIT
|
|
3734
3610
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3735
3611
|
*/
|
|
3736
|
-
const xlinkNS = 'http://www.w3.org/1999/xlink';
|
|
3737
|
-
const xmlNS = 'http://www.w3.org/XML/1998/namespace';
|
|
3738
3612
|
const ColonCharCode = 58;
|
|
3739
3613
|
function patchAttributes(oldVnode, vnode) {
|
|
3740
3614
|
const {
|
|
@@ -3764,10 +3638,10 @@ function patchAttributes(oldVnode, vnode) {
|
|
|
3764
3638
|
|
|
3765
3639
|
if (StringCharCodeAt.call(key, 3) === ColonCharCode) {
|
|
3766
3640
|
// Assume xml namespace
|
|
3767
|
-
setAttribute(elm, key, cur,
|
|
3641
|
+
setAttribute(elm, key, cur, XML_NAMESPACE);
|
|
3768
3642
|
} else if (StringCharCodeAt.call(key, 5) === ColonCharCode) {
|
|
3769
3643
|
// Assume xlink namespace
|
|
3770
|
-
setAttribute(elm, key, cur,
|
|
3644
|
+
setAttribute(elm, key, cur, XLINK_NAMESPACE);
|
|
3771
3645
|
} else if (isNull(cur) || isUndefined$1(cur)) {
|
|
3772
3646
|
removeAttribute(elm, key);
|
|
3773
3647
|
} else {
|
|
@@ -4018,6 +3892,160 @@ function applyStaticStyleAttribute(vnode) {
|
|
|
4018
3892
|
* SPDX-License-Identifier: MIT
|
|
4019
3893
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
4020
3894
|
*/
|
|
3895
|
+
const TextHook = {
|
|
3896
|
+
create: vnode => {
|
|
3897
|
+
const {
|
|
3898
|
+
owner
|
|
3899
|
+
} = vnode;
|
|
3900
|
+
const elm = createText(vnode.text);
|
|
3901
|
+
linkNodeToShadow(elm, owner);
|
|
3902
|
+
vnode.elm = elm;
|
|
3903
|
+
},
|
|
3904
|
+
update: updateNodeHook,
|
|
3905
|
+
insert: insertNode,
|
|
3906
|
+
move: insertNode,
|
|
3907
|
+
remove: removeNode
|
|
3908
|
+
};
|
|
3909
|
+
const CommentHook = {
|
|
3910
|
+
create: vnode => {
|
|
3911
|
+
const {
|
|
3912
|
+
owner,
|
|
3913
|
+
text
|
|
3914
|
+
} = vnode;
|
|
3915
|
+
const elm = createComment(text);
|
|
3916
|
+
linkNodeToShadow(elm, owner);
|
|
3917
|
+
vnode.elm = elm;
|
|
3918
|
+
},
|
|
3919
|
+
update: updateNodeHook,
|
|
3920
|
+
insert: insertNode,
|
|
3921
|
+
move: insertNode,
|
|
3922
|
+
remove: removeNode
|
|
3923
|
+
}; // insert is called after update, which is used somewhere else (via a module)
|
|
3924
|
+
// to mark the vm as inserted, that means we cannot use update as the main channel
|
|
3925
|
+
// to rehydrate when dirty, because sometimes the element is not inserted just yet,
|
|
3926
|
+
// which breaks some invariants. For that reason, we have the following for any
|
|
3927
|
+
// Custom Element that is inserted via a template.
|
|
3928
|
+
|
|
3929
|
+
const ElementHook = {
|
|
3930
|
+
create: vnode => {
|
|
3931
|
+
const {
|
|
3932
|
+
sel,
|
|
3933
|
+
owner,
|
|
3934
|
+
data: {
|
|
3935
|
+
svg
|
|
3936
|
+
}
|
|
3937
|
+
} = vnode;
|
|
3938
|
+
const namespace = isTrue(svg) ? SVG_NAMESPACE : undefined;
|
|
3939
|
+
const elm = createElement(sel, namespace);
|
|
3940
|
+
linkNodeToShadow(elm, owner);
|
|
3941
|
+
fallbackElmHook(elm, vnode);
|
|
3942
|
+
vnode.elm = elm;
|
|
3943
|
+
patchElementPropsAndAttrs$1(null, vnode);
|
|
3944
|
+
},
|
|
3945
|
+
update: (oldVnode, vnode) => {
|
|
3946
|
+
patchElementPropsAndAttrs$1(oldVnode, vnode);
|
|
3947
|
+
patchChildren(vnode.elm, oldVnode.children, vnode.children);
|
|
3948
|
+
},
|
|
3949
|
+
insert: (vnode, parentNode, referenceNode) => {
|
|
3950
|
+
insertNode(vnode, parentNode, referenceNode);
|
|
3951
|
+
createChildrenHook(vnode);
|
|
3952
|
+
},
|
|
3953
|
+
move: insertNode,
|
|
3954
|
+
remove: (vnode, parentNode) => {
|
|
3955
|
+
removeNode(vnode, parentNode);
|
|
3956
|
+
removeChildren(vnode);
|
|
3957
|
+
}
|
|
3958
|
+
};
|
|
3959
|
+
const CustomElementHook = {
|
|
3960
|
+
create: vnode => {
|
|
3961
|
+
const {
|
|
3962
|
+
sel,
|
|
3963
|
+
owner
|
|
3964
|
+
} = vnode;
|
|
3965
|
+
const UpgradableConstructor = getUpgradableConstructor(sel);
|
|
3966
|
+
/**
|
|
3967
|
+
* Note: if the upgradable constructor does not expect, or throw when we new it
|
|
3968
|
+
* with a callback as the first argument, we could implement a more advanced
|
|
3969
|
+
* mechanism that only passes that argument if the constructor is known to be
|
|
3970
|
+
* an upgradable custom element.
|
|
3971
|
+
*/
|
|
3972
|
+
|
|
3973
|
+
let vm;
|
|
3974
|
+
const elm = new UpgradableConstructor(elm => {
|
|
3975
|
+
// the custom element from the registry is expecting an upgrade callback
|
|
3976
|
+
vm = createViewModelHook(elm, vnode);
|
|
3977
|
+
});
|
|
3978
|
+
linkNodeToShadow(elm, owner);
|
|
3979
|
+
vnode.elm = elm;
|
|
3980
|
+
|
|
3981
|
+
if (vm) {
|
|
3982
|
+
allocateChildren(vnode, vm);
|
|
3983
|
+
} else if (vnode.ctor !== UpgradableConstructor) {
|
|
3984
|
+
throw new TypeError(`Incorrect Component Constructor`);
|
|
3985
|
+
}
|
|
3986
|
+
|
|
3987
|
+
patchElementPropsAndAttrs$1(null, vnode);
|
|
3988
|
+
},
|
|
3989
|
+
update: (oldVnode, vnode) => {
|
|
3990
|
+
patchElementPropsAndAttrs$1(oldVnode, vnode);
|
|
3991
|
+
const vm = getAssociatedVMIfPresent(vnode.elm);
|
|
3992
|
+
|
|
3993
|
+
if (vm) {
|
|
3994
|
+
// in fallback mode, the allocation will always set children to
|
|
3995
|
+
// empty and delegate the real allocation to the slot elements
|
|
3996
|
+
allocateChildren(vnode, vm);
|
|
3997
|
+
} // in fallback mode, the children will be always empty, so, nothing
|
|
3998
|
+
// will happen, but in native, it does allocate the light dom
|
|
3999
|
+
|
|
4000
|
+
|
|
4001
|
+
patchChildren(vnode.elm, oldVnode.children, vnode.children);
|
|
4002
|
+
|
|
4003
|
+
if (vm) {
|
|
4004
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
4005
|
+
assert.isTrue(isArray$1(vnode.children), `Invalid vnode for a custom element, it must have children defined.`);
|
|
4006
|
+
} // this will probably update the shadowRoot, but only if the vm is in a dirty state
|
|
4007
|
+
// this is important to preserve the top to bottom synchronous rendering phase.
|
|
4008
|
+
|
|
4009
|
+
|
|
4010
|
+
rerenderVM(vm);
|
|
4011
|
+
}
|
|
4012
|
+
},
|
|
4013
|
+
insert: (vnode, parentNode, referenceNode) => {
|
|
4014
|
+
insertNode(vnode, parentNode, referenceNode);
|
|
4015
|
+
const vm = getAssociatedVMIfPresent(vnode.elm);
|
|
4016
|
+
|
|
4017
|
+
if (vm) {
|
|
4018
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
4019
|
+
assert.isTrue(vm.state === 0
|
|
4020
|
+
/* created */
|
|
4021
|
+
, `${vm} cannot be recycled.`);
|
|
4022
|
+
}
|
|
4023
|
+
|
|
4024
|
+
runConnectedCallback(vm);
|
|
4025
|
+
}
|
|
4026
|
+
|
|
4027
|
+
createChildrenHook(vnode);
|
|
4028
|
+
|
|
4029
|
+
if (vm) {
|
|
4030
|
+
appendVM(vm);
|
|
4031
|
+
}
|
|
4032
|
+
},
|
|
4033
|
+
move: insertNode,
|
|
4034
|
+
remove: (vnode, parentNode) => {
|
|
4035
|
+
removeNode(vnode, parentNode);
|
|
4036
|
+
const vm = getAssociatedVMIfPresent(vnode.elm);
|
|
4037
|
+
|
|
4038
|
+
if (vm) {
|
|
4039
|
+
// for custom elements we don't have to go recursively because the removeVM routine
|
|
4040
|
+
// will take care of disconnecting any child VM attached to its shadow as well.
|
|
4041
|
+
removeVM(vm);
|
|
4042
|
+
}
|
|
4043
|
+
}
|
|
4044
|
+
};
|
|
4045
|
+
|
|
4046
|
+
function isVNode(vnode) {
|
|
4047
|
+
return vnode != null;
|
|
4048
|
+
}
|
|
4021
4049
|
|
|
4022
4050
|
function observeElementChildNodes(elm) {
|
|
4023
4051
|
elm.$domManual$ = true;
|
|
@@ -4040,6 +4068,24 @@ function setScopeTokenClassIfNecessary(elm, owner) {
|
|
|
4040
4068
|
}
|
|
4041
4069
|
}
|
|
4042
4070
|
|
|
4071
|
+
function linkNodeToShadow(elm, owner) {
|
|
4072
|
+
const {
|
|
4073
|
+
renderRoot,
|
|
4074
|
+
renderMode,
|
|
4075
|
+
shadowMode
|
|
4076
|
+
} = owner; // TODO [#1164]: this should eventually be done by the polyfill directly
|
|
4077
|
+
|
|
4078
|
+
if (isSyntheticShadowDefined) {
|
|
4079
|
+
if (shadowMode === 1
|
|
4080
|
+
/* Synthetic */
|
|
4081
|
+
|| renderMode === 0
|
|
4082
|
+
/* Light */
|
|
4083
|
+
) {
|
|
4084
|
+
elm[KEY__SHADOW_RESOLVER] = renderRoot[KEY__SHADOW_RESOLVER];
|
|
4085
|
+
}
|
|
4086
|
+
}
|
|
4087
|
+
}
|
|
4088
|
+
|
|
4043
4089
|
function updateNodeHook(oldVnode, vnode) {
|
|
4044
4090
|
const {
|
|
4045
4091
|
elm,
|
|
@@ -4058,7 +4104,8 @@ function updateNodeHook(oldVnode, vnode) {
|
|
|
4058
4104
|
}
|
|
4059
4105
|
}
|
|
4060
4106
|
}
|
|
4061
|
-
|
|
4107
|
+
|
|
4108
|
+
function insertNode(vnode, parentNode, referenceNode) {
|
|
4062
4109
|
if (process.env.NODE_ENV !== 'production') {
|
|
4063
4110
|
unlockDomMutation();
|
|
4064
4111
|
}
|
|
@@ -4069,7 +4116,8 @@ function insertNodeHook(vnode, parentNode, referenceNode) {
|
|
|
4069
4116
|
lockDomMutation();
|
|
4070
4117
|
}
|
|
4071
4118
|
}
|
|
4072
|
-
|
|
4119
|
+
|
|
4120
|
+
function removeNode(vnode, parentNode) {
|
|
4073
4121
|
if (process.env.NODE_ENV !== 'production') {
|
|
4074
4122
|
unlockDomMutation();
|
|
4075
4123
|
}
|
|
@@ -4080,7 +4128,8 @@ function removeNodeHook(vnode, parentNode) {
|
|
|
4080
4128
|
lockDomMutation();
|
|
4081
4129
|
}
|
|
4082
4130
|
}
|
|
4083
|
-
|
|
4131
|
+
|
|
4132
|
+
function patchElementPropsAndAttrs$1(oldVnode, vnode) {
|
|
4084
4133
|
if (isNull(oldVnode)) {
|
|
4085
4134
|
applyEventListeners(vnode);
|
|
4086
4135
|
applyStaticClassAttribute(vnode);
|
|
@@ -4094,10 +4143,7 @@ function patchElementPropsAndAttrs(oldVnode, vnode) {
|
|
|
4094
4143
|
patchAttributes(oldVnode, vnode);
|
|
4095
4144
|
patchProps(oldVnode, vnode);
|
|
4096
4145
|
}
|
|
4097
|
-
|
|
4098
|
-
applyEventListeners(vnode);
|
|
4099
|
-
patchProps(null, vnode);
|
|
4100
|
-
}
|
|
4146
|
+
|
|
4101
4147
|
function fallbackElmHook(elm, vnode) {
|
|
4102
4148
|
const {
|
|
4103
4149
|
owner
|
|
@@ -4117,7 +4163,7 @@ function fallbackElmHook(elm, vnode) {
|
|
|
4117
4163
|
} = owner.context;
|
|
4118
4164
|
|
|
4119
4165
|
if (!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
|
|
4120
|
-
/*
|
|
4166
|
+
/* Manual */
|
|
4121
4167
|
) {
|
|
4122
4168
|
// this element will now accept any manual content inserted into it
|
|
4123
4169
|
observeElementChildNodes(elm);
|
|
@@ -4135,7 +4181,7 @@ function fallbackElmHook(elm, vnode) {
|
|
|
4135
4181
|
}
|
|
4136
4182
|
} = vnode;
|
|
4137
4183
|
const isPortal = !isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
|
|
4138
|
-
/*
|
|
4184
|
+
/* Manual */
|
|
4139
4185
|
;
|
|
4140
4186
|
const isLight = owner.renderMode === 0
|
|
4141
4187
|
/* Light */
|
|
@@ -4146,6 +4192,7 @@ function fallbackElmHook(elm, vnode) {
|
|
|
4146
4192
|
});
|
|
4147
4193
|
}
|
|
4148
4194
|
}
|
|
4195
|
+
|
|
4149
4196
|
function patchChildren(parent, oldCh, newCh) {
|
|
4150
4197
|
if (hasDynamicChildren(newCh)) {
|
|
4151
4198
|
updateDynamicChildren(parent, oldCh, newCh);
|
|
@@ -4153,7 +4200,7 @@ function patchChildren(parent, oldCh, newCh) {
|
|
|
4153
4200
|
updateStaticChildren(parent, oldCh, newCh);
|
|
4154
4201
|
}
|
|
4155
4202
|
}
|
|
4156
|
-
function
|
|
4203
|
+
function allocateChildren(vnode, vm) {
|
|
4157
4204
|
// A component with slots will re-render because:
|
|
4158
4205
|
// 1- There is a change of the internal state.
|
|
4159
4206
|
// 2- There is a change on the external api (ex: slots)
|
|
@@ -4184,12 +4231,14 @@ function allocateChildrenHook(vnode, vm) {
|
|
|
4184
4231
|
vnode.children = EmptyArray;
|
|
4185
4232
|
}
|
|
4186
4233
|
}
|
|
4234
|
+
|
|
4187
4235
|
function createViewModelHook(elm, vnode) {
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4236
|
+
let vm = getAssociatedVMIfPresent(elm); // There is a possibility that a custom element is registered under tagName, in which case, the
|
|
4237
|
+
// initialization is already carry on, and there is nothing else to do here since this hook is
|
|
4238
|
+
// called right after invoking `document.createElement`.
|
|
4239
|
+
|
|
4240
|
+
if (!isUndefined$1(vm)) {
|
|
4241
|
+
return vm;
|
|
4193
4242
|
}
|
|
4194
4243
|
|
|
4195
4244
|
const {
|
|
@@ -4211,8 +4260,7 @@ function createViewModelHook(elm, vnode) {
|
|
|
4211
4260
|
setElementShadowToken(elm, stylesheetToken);
|
|
4212
4261
|
}
|
|
4213
4262
|
|
|
4214
|
-
|
|
4215
|
-
createVM(elm, def, {
|
|
4263
|
+
vm = createVM(elm, ctor, {
|
|
4216
4264
|
mode,
|
|
4217
4265
|
owner,
|
|
4218
4266
|
tagName: sel
|
|
@@ -4221,7 +4269,10 @@ function createViewModelHook(elm, vnode) {
|
|
|
4221
4269
|
if (process.env.NODE_ENV !== 'production') {
|
|
4222
4270
|
assert.isTrue(isArray$1(vnode.children), `Invalid vnode for a custom element, it must have children defined.`);
|
|
4223
4271
|
}
|
|
4272
|
+
|
|
4273
|
+
return vm;
|
|
4224
4274
|
}
|
|
4275
|
+
|
|
4225
4276
|
function createChildrenHook(vnode) {
|
|
4226
4277
|
const {
|
|
4227
4278
|
elm,
|
|
@@ -4238,170 +4289,7 @@ function createChildrenHook(vnode) {
|
|
|
4238
4289
|
}
|
|
4239
4290
|
}
|
|
4240
4291
|
|
|
4241
|
-
function
|
|
4242
|
-
// eslint-disable-next-line lwc-internal/no-global-node
|
|
4243
|
-
return node.nodeType === Node.ELEMENT_NODE;
|
|
4244
|
-
}
|
|
4245
|
-
|
|
4246
|
-
function vnodesAndElementHaveCompatibleAttrs(vnode, elm) {
|
|
4247
|
-
const {
|
|
4248
|
-
data: {
|
|
4249
|
-
attrs = {}
|
|
4250
|
-
}
|
|
4251
|
-
} = vnode;
|
|
4252
|
-
let nodesAreCompatible = true; // Validate attributes, though we could always recovery from those by running the update mods.
|
|
4253
|
-
// Note: intentionally ONLY matching vnodes.attrs to elm.attrs, in case SSR is adding extra attributes.
|
|
4254
|
-
|
|
4255
|
-
for (const [attrName, attrValue] of Object.entries(attrs)) {
|
|
4256
|
-
const elmAttrValue = getAttribute(elm, attrName);
|
|
4257
|
-
|
|
4258
|
-
if (String(attrValue) !== elmAttrValue) {
|
|
4259
|
-
logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "${attrName}" has different values, expected "${attrValue}" but found "${elmAttrValue}"`, vnode.owner);
|
|
4260
|
-
nodesAreCompatible = false;
|
|
4261
|
-
}
|
|
4262
|
-
}
|
|
4263
|
-
|
|
4264
|
-
return nodesAreCompatible;
|
|
4265
|
-
}
|
|
4266
|
-
|
|
4267
|
-
function vnodesAndElementHaveCompatibleClass(vnode, elm) {
|
|
4268
|
-
const {
|
|
4269
|
-
data: {
|
|
4270
|
-
className,
|
|
4271
|
-
classMap
|
|
4272
|
-
}
|
|
4273
|
-
} = vnode;
|
|
4274
|
-
let nodesAreCompatible = true;
|
|
4275
|
-
let vnodeClassName;
|
|
4276
|
-
|
|
4277
|
-
if (!isUndefined$1(className) && String(className) !== elm.className) {
|
|
4278
|
-
// className is used when class is bound to an expr.
|
|
4279
|
-
nodesAreCompatible = false;
|
|
4280
|
-
vnodeClassName = className;
|
|
4281
|
-
} else if (!isUndefined$1(classMap)) {
|
|
4282
|
-
// classMap is used when class is set to static value.
|
|
4283
|
-
const classList = getClassList(elm);
|
|
4284
|
-
let computedClassName = ''; // all classes from the vnode should be in the element.classList
|
|
4285
|
-
|
|
4286
|
-
for (const name in classMap) {
|
|
4287
|
-
computedClassName += ' ' + name;
|
|
4288
|
-
|
|
4289
|
-
if (!classList.contains(name)) {
|
|
4290
|
-
nodesAreCompatible = false;
|
|
4291
|
-
}
|
|
4292
|
-
}
|
|
4293
|
-
|
|
4294
|
-
vnodeClassName = computedClassName.trim();
|
|
4295
|
-
|
|
4296
|
-
if (classList.length > keys(classMap).length) {
|
|
4297
|
-
nodesAreCompatible = false;
|
|
4298
|
-
}
|
|
4299
|
-
}
|
|
4300
|
-
|
|
4301
|
-
if (!nodesAreCompatible) {
|
|
4302
|
-
logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "class" has different values, expected "${vnodeClassName}" but found "${elm.className}"`, vnode.owner);
|
|
4303
|
-
}
|
|
4304
|
-
|
|
4305
|
-
return nodesAreCompatible;
|
|
4306
|
-
}
|
|
4307
|
-
|
|
4308
|
-
function vnodesAndElementHaveCompatibleStyle(vnode, elm) {
|
|
4309
|
-
const {
|
|
4310
|
-
data: {
|
|
4311
|
-
style,
|
|
4312
|
-
styleDecls
|
|
4313
|
-
}
|
|
4314
|
-
} = vnode;
|
|
4315
|
-
const elmStyle = getAttribute(elm, 'style') || '';
|
|
4316
|
-
let vnodeStyle;
|
|
4317
|
-
let nodesAreCompatible = true;
|
|
4318
|
-
|
|
4319
|
-
if (!isUndefined$1(style) && style !== elmStyle) {
|
|
4320
|
-
nodesAreCompatible = false;
|
|
4321
|
-
vnodeStyle = style;
|
|
4322
|
-
} else if (!isUndefined$1(styleDecls)) {
|
|
4323
|
-
const parsedVnodeStyle = parseStyleText(elmStyle);
|
|
4324
|
-
const expectedStyle = []; // styleMap is used when style is set to static value.
|
|
4325
|
-
|
|
4326
|
-
for (let i = 0, n = styleDecls.length; i < n; i++) {
|
|
4327
|
-
const [prop, value, important] = styleDecls[i];
|
|
4328
|
-
expectedStyle.push(`${prop}: ${value + (important ? ' important!' : '')}`);
|
|
4329
|
-
const parsedPropValue = parsedVnodeStyle[prop];
|
|
4330
|
-
|
|
4331
|
-
if (isUndefined$1(parsedPropValue)) {
|
|
4332
|
-
nodesAreCompatible = false;
|
|
4333
|
-
} else if (!parsedPropValue.startsWith(value)) {
|
|
4334
|
-
nodesAreCompatible = false;
|
|
4335
|
-
} else if (important && !parsedPropValue.endsWith('!important')) {
|
|
4336
|
-
nodesAreCompatible = false;
|
|
4337
|
-
}
|
|
4338
|
-
}
|
|
4339
|
-
|
|
4340
|
-
if (keys(parsedVnodeStyle).length > styleDecls.length) {
|
|
4341
|
-
nodesAreCompatible = false;
|
|
4342
|
-
}
|
|
4343
|
-
|
|
4344
|
-
vnodeStyle = ArrayJoin.call(expectedStyle, ';');
|
|
4345
|
-
}
|
|
4346
|
-
|
|
4347
|
-
if (!nodesAreCompatible) {
|
|
4348
|
-
// style is used when class is bound to an expr.
|
|
4349
|
-
logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "style" has different values, expected "${vnodeStyle}" but found "${elmStyle}".`, vnode.owner);
|
|
4350
|
-
}
|
|
4351
|
-
|
|
4352
|
-
return nodesAreCompatible;
|
|
4353
|
-
}
|
|
4354
|
-
|
|
4355
|
-
function throwHydrationError() {
|
|
4356
|
-
assert.fail('Server rendered elements do not match client side generated elements');
|
|
4357
|
-
}
|
|
4358
|
-
|
|
4359
|
-
function hydrateChildrenHook(elmChildren, children, vm) {
|
|
4360
|
-
var _a, _b;
|
|
4361
|
-
|
|
4362
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
4363
|
-
const filteredVNodes = ArrayFilter.call(children, vnode => !!vnode);
|
|
4364
|
-
|
|
4365
|
-
if (elmChildren.length !== filteredVNodes.length) {
|
|
4366
|
-
logError(`Hydration mismatch: incorrect number of rendered nodes, expected ${filteredVNodes.length} but found ${elmChildren.length}.`, vm);
|
|
4367
|
-
throwHydrationError();
|
|
4368
|
-
}
|
|
4369
|
-
}
|
|
4370
|
-
|
|
4371
|
-
let elmCurrentChildIdx = 0;
|
|
4372
|
-
|
|
4373
|
-
for (let j = 0, n = children.length; j < n; j++) {
|
|
4374
|
-
const ch = children[j];
|
|
4375
|
-
|
|
4376
|
-
if (ch != null) {
|
|
4377
|
-
const childNode = elmChildren[elmCurrentChildIdx];
|
|
4378
|
-
|
|
4379
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
4380
|
-
// VComments and VTexts validation is handled in their hooks
|
|
4381
|
-
if (isElementNode(childNode)) {
|
|
4382
|
-
if (((_a = ch.sel) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== childNode.tagName.toLowerCase()) {
|
|
4383
|
-
logError(`Hydration mismatch: expecting element with tag "${(_b = ch.sel) === null || _b === void 0 ? void 0 : _b.toLowerCase()}" but found "${childNode.tagName.toLowerCase()}".`, vm);
|
|
4384
|
-
throwHydrationError();
|
|
4385
|
-
} // Note: props are not yet set
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
const hasIncompatibleAttrs = vnodesAndElementHaveCompatibleAttrs(ch, childNode);
|
|
4389
|
-
const hasIncompatibleClass = vnodesAndElementHaveCompatibleClass(ch, childNode);
|
|
4390
|
-
const hasIncompatibleStyle = vnodesAndElementHaveCompatibleStyle(ch, childNode);
|
|
4391
|
-
const isVNodeAndElementCompatible = hasIncompatibleAttrs && hasIncompatibleClass && hasIncompatibleStyle;
|
|
4392
|
-
|
|
4393
|
-
if (!isVNodeAndElementCompatible) {
|
|
4394
|
-
throwHydrationError();
|
|
4395
|
-
}
|
|
4396
|
-
}
|
|
4397
|
-
}
|
|
4398
|
-
|
|
4399
|
-
ch.hook.hydrate(ch, childNode);
|
|
4400
|
-
elmCurrentChildIdx++;
|
|
4401
|
-
}
|
|
4402
|
-
}
|
|
4403
|
-
}
|
|
4404
|
-
function removeElmHook(vnode) {
|
|
4292
|
+
function removeChildren(vnode) {
|
|
4405
4293
|
// this method only needs to search on child vnodes from template
|
|
4406
4294
|
// to trigger the remove hook just in case some of those children
|
|
4407
4295
|
// are custom elements.
|
|
@@ -4420,6 +4308,8 @@ function removeElmHook(vnode) {
|
|
|
4420
4308
|
}
|
|
4421
4309
|
|
|
4422
4310
|
function allocateInSlot(vm, children) {
|
|
4311
|
+
var _a;
|
|
4312
|
+
|
|
4423
4313
|
const {
|
|
4424
4314
|
cmpSlots: oldSlots
|
|
4425
4315
|
} = vm;
|
|
@@ -4432,10 +4322,12 @@ function allocateInSlot(vm, children) {
|
|
|
4432
4322
|
continue;
|
|
4433
4323
|
}
|
|
4434
4324
|
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4325
|
+
let slotName = '';
|
|
4326
|
+
|
|
4327
|
+
if (isVBaseElement(vnode)) {
|
|
4328
|
+
slotName = ((_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) || '';
|
|
4329
|
+
}
|
|
4330
|
+
|
|
4439
4331
|
const vnodes = cmpSlots[slotName] = cmpSlots[slotName] || []; // re-keying the vnodes is necessary to avoid conflicts with default content for the slot
|
|
4440
4332
|
// which might have similar keys. Each vnode will always have a key that
|
|
4441
4333
|
// starts with a numeric character from compiler. In this case, we add a unique
|
|
@@ -4491,329 +4383,203 @@ function hasDynamicChildren(children) {
|
|
|
4491
4383
|
return FromIteration.has(children);
|
|
4492
4384
|
}
|
|
4493
4385
|
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
* All rights reserved.
|
|
4497
|
-
* SPDX-License-Identifier: MIT
|
|
4498
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
4499
|
-
*/
|
|
4500
|
-
function getUpgradableConstructor(tagName) {
|
|
4501
|
-
// Should never get a tag with upper case letter at this point, the compiler should
|
|
4502
|
-
// produce only tags with lowercase letters
|
|
4503
|
-
// But, for backwards compatibility, we will lower case the tagName
|
|
4504
|
-
tagName = tagName.toLowerCase();
|
|
4505
|
-
let CE = getCustomElement(tagName);
|
|
4506
|
-
|
|
4507
|
-
if (!isUndefined$1(CE)) {
|
|
4508
|
-
return CE;
|
|
4509
|
-
}
|
|
4510
|
-
/**
|
|
4511
|
-
* LWC Upgradable Element reference to an element that was created
|
|
4512
|
-
* via the scoped registry mechanism, and that is ready to be upgraded.
|
|
4513
|
-
*/
|
|
4386
|
+
function createKeyToOldIdx(children, beginIdx, endIdx) {
|
|
4387
|
+
const map = {}; // TODO [#1637]: simplify this by assuming that all vnodes has keys
|
|
4514
4388
|
|
|
4389
|
+
for (let j = beginIdx; j <= endIdx; ++j) {
|
|
4390
|
+
const ch = children[j];
|
|
4515
4391
|
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4392
|
+
if (isVNode(ch)) {
|
|
4393
|
+
const {
|
|
4394
|
+
key
|
|
4395
|
+
} = ch;
|
|
4519
4396
|
|
|
4520
|
-
if (
|
|
4521
|
-
|
|
4397
|
+
if (key !== undefined) {
|
|
4398
|
+
map[key] = j;
|
|
4522
4399
|
}
|
|
4523
4400
|
}
|
|
4401
|
+
}
|
|
4524
4402
|
|
|
4525
|
-
|
|
4526
|
-
defineCustomElement(tagName, CE);
|
|
4527
|
-
return CE;
|
|
4403
|
+
return map;
|
|
4528
4404
|
}
|
|
4529
4405
|
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
* SPDX-License-Identifier: MIT
|
|
4534
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
4535
|
-
*/
|
|
4536
|
-
const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
|
|
4537
|
-
const SymbolIterator = Symbol.iterator;
|
|
4538
|
-
const TextHook = {
|
|
4539
|
-
create: vnode => {
|
|
4540
|
-
const {
|
|
4541
|
-
owner
|
|
4542
|
-
} = vnode;
|
|
4543
|
-
const elm = createText(vnode.text);
|
|
4544
|
-
linkNodeToShadow(elm, owner);
|
|
4545
|
-
vnode.elm = elm;
|
|
4546
|
-
},
|
|
4547
|
-
update: updateNodeHook,
|
|
4548
|
-
insert: insertNodeHook,
|
|
4549
|
-
move: insertNodeHook,
|
|
4550
|
-
remove: removeNodeHook,
|
|
4551
|
-
hydrate: (vNode, node) => {
|
|
4552
|
-
var _a;
|
|
4553
|
-
|
|
4554
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
4555
|
-
// eslint-disable-next-line lwc-internal/no-global-node
|
|
4556
|
-
if (node.nodeType !== Node.TEXT_NODE) {
|
|
4557
|
-
logError('Hydration mismatch: incorrect node type received', vNode.owner);
|
|
4558
|
-
assert.fail('Hydration mismatch: incorrect node type received.');
|
|
4559
|
-
}
|
|
4406
|
+
function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
|
|
4407
|
+
for (; startIdx <= endIdx; ++startIdx) {
|
|
4408
|
+
const ch = vnodes[startIdx];
|
|
4560
4409
|
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
}
|
|
4410
|
+
if (isVNode(ch)) {
|
|
4411
|
+
ch.hook.create(ch);
|
|
4412
|
+
ch.hook.insert(ch, parentElm, before);
|
|
4413
|
+
}
|
|
4414
|
+
}
|
|
4415
|
+
}
|
|
4565
4416
|
|
|
4417
|
+
function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
|
|
4418
|
+
for (; startIdx <= endIdx; ++startIdx) {
|
|
4419
|
+
const ch = vnodes[startIdx]; // text nodes do not have logic associated to them
|
|
4566
4420
|
|
|
4567
|
-
|
|
4568
|
-
|
|
4421
|
+
if (isVNode(ch)) {
|
|
4422
|
+
ch.hook.remove(ch, parentElm);
|
|
4423
|
+
}
|
|
4569
4424
|
}
|
|
4570
|
-
}
|
|
4571
|
-
const CommentHook = {
|
|
4572
|
-
create: vnode => {
|
|
4573
|
-
const {
|
|
4574
|
-
owner,
|
|
4575
|
-
text
|
|
4576
|
-
} = vnode;
|
|
4577
|
-
const elm = createComment(text);
|
|
4578
|
-
linkNodeToShadow(elm, owner);
|
|
4579
|
-
vnode.elm = elm;
|
|
4580
|
-
},
|
|
4581
|
-
update: updateNodeHook,
|
|
4582
|
-
insert: insertNodeHook,
|
|
4583
|
-
move: insertNodeHook,
|
|
4584
|
-
remove: removeNodeHook,
|
|
4585
|
-
hydrate: (vNode, node) => {
|
|
4586
|
-
var _a;
|
|
4425
|
+
}
|
|
4587
4426
|
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4427
|
+
function updateDynamicChildren(parentElm, oldCh, newCh) {
|
|
4428
|
+
let oldStartIdx = 0;
|
|
4429
|
+
let newStartIdx = 0;
|
|
4430
|
+
let oldEndIdx = oldCh.length - 1;
|
|
4431
|
+
let oldStartVnode = oldCh[0];
|
|
4432
|
+
let oldEndVnode = oldCh[oldEndIdx];
|
|
4433
|
+
const newChEnd = newCh.length - 1;
|
|
4434
|
+
let newEndIdx = newChEnd;
|
|
4435
|
+
let newStartVnode = newCh[0];
|
|
4436
|
+
let newEndVnode = newCh[newEndIdx];
|
|
4437
|
+
let oldKeyToIdx;
|
|
4438
|
+
let idxInOld;
|
|
4439
|
+
let elmToMove;
|
|
4440
|
+
let before;
|
|
4594
4441
|
|
|
4595
|
-
|
|
4596
|
-
|
|
4442
|
+
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
|
|
4443
|
+
if (!isVNode(oldStartVnode)) {
|
|
4444
|
+
oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left
|
|
4445
|
+
} else if (!isVNode(oldEndVnode)) {
|
|
4446
|
+
oldEndVnode = oldCh[--oldEndIdx];
|
|
4447
|
+
} else if (!isVNode(newStartVnode)) {
|
|
4448
|
+
newStartVnode = newCh[++newStartIdx];
|
|
4449
|
+
} else if (!isVNode(newEndVnode)) {
|
|
4450
|
+
newEndVnode = newCh[--newEndIdx];
|
|
4451
|
+
} else if (isSameVnode(oldStartVnode, newStartVnode)) {
|
|
4452
|
+
patchVnode(oldStartVnode, newStartVnode);
|
|
4453
|
+
oldStartVnode = oldCh[++oldStartIdx];
|
|
4454
|
+
newStartVnode = newCh[++newStartIdx];
|
|
4455
|
+
} else if (isSameVnode(oldEndVnode, newEndVnode)) {
|
|
4456
|
+
patchVnode(oldEndVnode, newEndVnode);
|
|
4457
|
+
oldEndVnode = oldCh[--oldEndIdx];
|
|
4458
|
+
newEndVnode = newCh[--newEndIdx];
|
|
4459
|
+
} else if (isSameVnode(oldStartVnode, newEndVnode)) {
|
|
4460
|
+
// Vnode moved right
|
|
4461
|
+
patchVnode(oldStartVnode, newEndVnode);
|
|
4462
|
+
newEndVnode.hook.move(oldStartVnode, parentElm, nextSibling(oldEndVnode.elm));
|
|
4463
|
+
oldStartVnode = oldCh[++oldStartIdx];
|
|
4464
|
+
newEndVnode = newCh[--newEndIdx];
|
|
4465
|
+
} else if (isSameVnode(oldEndVnode, newStartVnode)) {
|
|
4466
|
+
// Vnode moved left
|
|
4467
|
+
patchVnode(oldEndVnode, newStartVnode);
|
|
4468
|
+
newStartVnode.hook.move(oldEndVnode, parentElm, oldStartVnode.elm);
|
|
4469
|
+
oldEndVnode = oldCh[--oldEndIdx];
|
|
4470
|
+
newStartVnode = newCh[++newStartIdx];
|
|
4471
|
+
} else {
|
|
4472
|
+
if (oldKeyToIdx === undefined) {
|
|
4473
|
+
oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
|
|
4597
4474
|
}
|
|
4598
|
-
} // always set the text value to the one from the vnode.
|
|
4599
|
-
|
|
4600
4475
|
|
|
4601
|
-
|
|
4602
|
-
vNode.elm = node;
|
|
4603
|
-
}
|
|
4604
|
-
}; // insert is called after update, which is used somewhere else (via a module)
|
|
4605
|
-
// to mark the vm as inserted, that means we cannot use update as the main channel
|
|
4606
|
-
// to rehydrate when dirty, because sometimes the element is not inserted just yet,
|
|
4607
|
-
// which breaks some invariants. For that reason, we have the following for any
|
|
4608
|
-
// Custom Element that is inserted via a template.
|
|
4609
|
-
|
|
4610
|
-
const ElementHook = {
|
|
4611
|
-
create: vnode => {
|
|
4612
|
-
const {
|
|
4613
|
-
sel,
|
|
4614
|
-
owner,
|
|
4615
|
-
data: {
|
|
4616
|
-
svg
|
|
4617
|
-
}
|
|
4618
|
-
} = vnode;
|
|
4619
|
-
const namespace = isTrue(svg) ? SVG_NAMESPACE : undefined;
|
|
4620
|
-
const elm = createElement(sel, namespace);
|
|
4621
|
-
linkNodeToShadow(elm, owner);
|
|
4622
|
-
fallbackElmHook(elm, vnode);
|
|
4623
|
-
vnode.elm = elm;
|
|
4624
|
-
patchElementPropsAndAttrs(null, vnode);
|
|
4625
|
-
},
|
|
4626
|
-
update: (oldVnode, vnode) => {
|
|
4627
|
-
patchElementPropsAndAttrs(oldVnode, vnode);
|
|
4628
|
-
patchChildren(vnode.elm, oldVnode.children, vnode.children);
|
|
4629
|
-
},
|
|
4630
|
-
insert: (vnode, parentNode, referenceNode) => {
|
|
4631
|
-
insertNodeHook(vnode, parentNode, referenceNode);
|
|
4632
|
-
createChildrenHook(vnode);
|
|
4633
|
-
},
|
|
4634
|
-
move: (vnode, parentNode, referenceNode) => {
|
|
4635
|
-
insertNodeHook(vnode, parentNode, referenceNode);
|
|
4636
|
-
},
|
|
4637
|
-
remove: (vnode, parentNode) => {
|
|
4638
|
-
removeNodeHook(vnode, parentNode);
|
|
4639
|
-
removeElmHook(vnode);
|
|
4640
|
-
},
|
|
4641
|
-
hydrate: (vnode, node) => {
|
|
4642
|
-
const elm = node;
|
|
4643
|
-
vnode.elm = elm;
|
|
4644
|
-
const {
|
|
4645
|
-
context
|
|
4646
|
-
} = vnode.data;
|
|
4647
|
-
const isDomManual = Boolean(!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
|
|
4648
|
-
/* manual */
|
|
4649
|
-
);
|
|
4476
|
+
idxInOld = oldKeyToIdx[newStartVnode.key];
|
|
4650
4477
|
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
}
|
|
4478
|
+
if (isUndefined$1(idxInOld)) {
|
|
4479
|
+
// New element
|
|
4480
|
+
newStartVnode.hook.create(newStartVnode);
|
|
4481
|
+
newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm);
|
|
4482
|
+
newStartVnode = newCh[++newStartIdx];
|
|
4483
|
+
} else {
|
|
4484
|
+
elmToMove = oldCh[idxInOld];
|
|
4657
4485
|
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4486
|
+
if (isVNode(elmToMove)) {
|
|
4487
|
+
if (elmToMove.sel !== newStartVnode.sel) {
|
|
4488
|
+
// New element
|
|
4489
|
+
newStartVnode.hook.create(newStartVnode);
|
|
4490
|
+
newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm);
|
|
4491
|
+
} else {
|
|
4492
|
+
patchVnode(elmToMove, newStartVnode);
|
|
4493
|
+
oldCh[idxInOld] = undefined;
|
|
4494
|
+
newStartVnode.hook.move(elmToMove, parentElm, oldStartVnode.elm);
|
|
4495
|
+
}
|
|
4663
4496
|
}
|
|
4664
|
-
}
|
|
4665
|
-
}
|
|
4666
4497
|
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
if (!isDomManual) {
|
|
4670
|
-
hydrateChildrenHook(vnode.elm.childNodes, vnode.children, vnode.owner);
|
|
4498
|
+
newStartVnode = newCh[++newStartIdx];
|
|
4499
|
+
}
|
|
4671
4500
|
}
|
|
4672
4501
|
}
|
|
4673
|
-
};
|
|
4674
|
-
const CustomElementHook = {
|
|
4675
|
-
create: vnode => {
|
|
4676
|
-
const {
|
|
4677
|
-
sel,
|
|
4678
|
-
owner
|
|
4679
|
-
} = vnode;
|
|
4680
|
-
const UpgradableConstructor = getUpgradableConstructor(sel);
|
|
4681
|
-
/**
|
|
4682
|
-
* Note: if the upgradable constructor does not expect, or throw when we new it
|
|
4683
|
-
* with a callback as the first argument, we could implement a more advanced
|
|
4684
|
-
* mechanism that only passes that argument if the constructor is known to be
|
|
4685
|
-
* an upgradable custom element.
|
|
4686
|
-
*/
|
|
4687
|
-
|
|
4688
|
-
const elm = new UpgradableConstructor(elm => {
|
|
4689
|
-
// the custom element from the registry is expecting an upgrade callback
|
|
4690
|
-
createViewModelHook(elm, vnode);
|
|
4691
|
-
});
|
|
4692
|
-
linkNodeToShadow(elm, owner);
|
|
4693
|
-
vnode.elm = elm;
|
|
4694
|
-
const vm = getAssociatedVMIfPresent(elm);
|
|
4695
|
-
|
|
4696
|
-
if (vm) {
|
|
4697
|
-
allocateChildrenHook(vnode, vm);
|
|
4698
|
-
} else if (vnode.ctor !== UpgradableConstructor) {
|
|
4699
|
-
throw new TypeError(`Incorrect Component Constructor`);
|
|
4700
|
-
}
|
|
4701
|
-
|
|
4702
|
-
patchElementPropsAndAttrs(null, vnode);
|
|
4703
|
-
},
|
|
4704
|
-
update: (oldVnode, vnode) => {
|
|
4705
|
-
patchElementPropsAndAttrs(oldVnode, vnode);
|
|
4706
|
-
const vm = getAssociatedVMIfPresent(vnode.elm);
|
|
4707
|
-
|
|
4708
|
-
if (vm) {
|
|
4709
|
-
// in fallback mode, the allocation will always set children to
|
|
4710
|
-
// empty and delegate the real allocation to the slot elements
|
|
4711
|
-
allocateChildrenHook(vnode, vm);
|
|
4712
|
-
} // in fallback mode, the children will be always empty, so, nothing
|
|
4713
|
-
// will happen, but in native, it does allocate the light dom
|
|
4714
|
-
|
|
4715
4502
|
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
// this is important to preserve the top to bottom synchronous rendering phase.
|
|
4503
|
+
if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
|
|
4504
|
+
if (oldStartIdx > oldEndIdx) {
|
|
4505
|
+
// There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
|
|
4506
|
+
// already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
|
|
4507
|
+
let i = newEndIdx;
|
|
4508
|
+
let n;
|
|
4723
4509
|
|
|
4510
|
+
do {
|
|
4511
|
+
n = newCh[++i];
|
|
4512
|
+
} while (!isVNode(n) && i < newChEnd);
|
|
4724
4513
|
|
|
4725
|
-
|
|
4514
|
+
before = isVNode(n) ? n.elm : null;
|
|
4515
|
+
addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
|
|
4516
|
+
} else {
|
|
4517
|
+
removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
|
|
4726
4518
|
}
|
|
4727
|
-
}
|
|
4728
|
-
|
|
4729
|
-
insertNodeHook(vnode, parentNode, referenceNode);
|
|
4730
|
-
const vm = getAssociatedVMIfPresent(vnode.elm);
|
|
4519
|
+
}
|
|
4520
|
+
}
|
|
4731
4521
|
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
/* created */
|
|
4736
|
-
, `${vm} cannot be recycled.`);
|
|
4737
|
-
}
|
|
4522
|
+
function updateStaticChildren(parentElm, oldCh, newCh) {
|
|
4523
|
+
const oldChLength = oldCh.length;
|
|
4524
|
+
const newChLength = newCh.length;
|
|
4738
4525
|
|
|
4739
|
-
|
|
4740
|
-
|
|
4526
|
+
if (oldChLength === 0) {
|
|
4527
|
+
// the old list is empty, we can directly insert anything new
|
|
4528
|
+
addVnodes(parentElm, null, newCh, 0, newChLength);
|
|
4529
|
+
return;
|
|
4530
|
+
}
|
|
4741
4531
|
|
|
4742
|
-
|
|
4532
|
+
if (newChLength === 0) {
|
|
4533
|
+
// the old list is nonempty and the new list is empty so we can directly remove all old nodes
|
|
4534
|
+
// this is the case in which the dynamic children of an if-directive should be removed
|
|
4535
|
+
removeVnodes(parentElm, oldCh, 0, oldChLength);
|
|
4536
|
+
return;
|
|
4537
|
+
} // if the old list is not empty, the new list MUST have the same
|
|
4538
|
+
// amount of nodes, that's why we call this static children
|
|
4743
4539
|
|
|
4744
|
-
if (vm) {
|
|
4745
|
-
appendVM(vm);
|
|
4746
|
-
}
|
|
4747
|
-
},
|
|
4748
|
-
move: (vnode, parentNode, referenceNode) => {
|
|
4749
|
-
insertNodeHook(vnode, parentNode, referenceNode);
|
|
4750
|
-
},
|
|
4751
|
-
remove: (vnode, parentNode) => {
|
|
4752
|
-
removeNodeHook(vnode, parentNode);
|
|
4753
|
-
const vm = getAssociatedVMIfPresent(vnode.elm);
|
|
4754
4540
|
|
|
4755
|
-
|
|
4756
|
-
// for custom elements we don't have to go recursively because the removeVM routine
|
|
4757
|
-
// will take care of disconnecting any child VM attached to its shadow as well.
|
|
4758
|
-
removeVM(vm);
|
|
4759
|
-
}
|
|
4760
|
-
},
|
|
4761
|
-
hydrate: (vnode, elm) => {
|
|
4762
|
-
// the element is created, but the vm is not
|
|
4763
|
-
const {
|
|
4764
|
-
sel,
|
|
4765
|
-
mode,
|
|
4766
|
-
ctor,
|
|
4767
|
-
owner
|
|
4768
|
-
} = vnode;
|
|
4769
|
-
const def = getComponentInternalDef(ctor);
|
|
4770
|
-
createVM(elm, def, {
|
|
4771
|
-
mode,
|
|
4772
|
-
owner,
|
|
4773
|
-
tagName: sel
|
|
4774
|
-
});
|
|
4775
|
-
vnode.elm = elm;
|
|
4776
|
-
const vm = getAssociatedVM(elm);
|
|
4777
|
-
allocateChildrenHook(vnode, vm);
|
|
4778
|
-
hydrateElmHook(vnode); // Insert hook section:
|
|
4541
|
+
let referenceElm = null;
|
|
4779
4542
|
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
, `${vm} cannot be recycled.`);
|
|
4784
|
-
}
|
|
4543
|
+
for (let i = newChLength - 1; i >= 0; i -= 1) {
|
|
4544
|
+
const vnode = newCh[i];
|
|
4545
|
+
const oldVNode = oldCh[i];
|
|
4785
4546
|
|
|
4786
|
-
|
|
4547
|
+
if (vnode !== oldVNode) {
|
|
4548
|
+
if (isVNode(oldVNode)) {
|
|
4549
|
+
if (isVNode(vnode)) {
|
|
4550
|
+
// both vnodes must be equivalent, and se just need to patch them
|
|
4551
|
+
patchVnode(oldVNode, vnode);
|
|
4552
|
+
referenceElm = vnode.elm;
|
|
4553
|
+
} else {
|
|
4554
|
+
// removing the old vnode since the new one is null
|
|
4555
|
+
oldVNode.hook.remove(oldVNode, parentElm);
|
|
4556
|
+
}
|
|
4557
|
+
} else if (isVNode(vnode)) {
|
|
4558
|
+
// this condition is unnecessary
|
|
4559
|
+
vnode.hook.create(vnode); // insert the new node one since the old one is null
|
|
4787
4560
|
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
// VM is not rendering in Light DOM, we can proceed and hydrate the slotted content.
|
|
4792
|
-
// Note: for Light DOM, this is handled while hydrating the VM
|
|
4793
|
-
hydrateChildrenHook(vnode.elm.childNodes, vnode.children, vm);
|
|
4561
|
+
vnode.hook.insert(vnode, parentElm, referenceElm);
|
|
4562
|
+
referenceElm = vnode.elm;
|
|
4563
|
+
}
|
|
4794
4564
|
}
|
|
4795
|
-
|
|
4796
|
-
hydrateVM(vm);
|
|
4797
4565
|
}
|
|
4798
|
-
}
|
|
4799
|
-
|
|
4800
|
-
function linkNodeToShadow(elm, owner) {
|
|
4801
|
-
const {
|
|
4802
|
-
renderMode,
|
|
4803
|
-
shadowMode
|
|
4804
|
-
} = owner; // TODO [#1164]: this should eventually be done by the polyfill directly
|
|
4566
|
+
}
|
|
4805
4567
|
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
/* Light */
|
|
4811
|
-
) {
|
|
4812
|
-
elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
|
|
4813
|
-
}
|
|
4568
|
+
function patchVnode(oldVnode, vnode) {
|
|
4569
|
+
if (oldVnode !== vnode) {
|
|
4570
|
+
vnode.elm = oldVnode.elm;
|
|
4571
|
+
vnode.hook.update(oldVnode, vnode);
|
|
4814
4572
|
}
|
|
4815
4573
|
}
|
|
4816
4574
|
|
|
4575
|
+
/*
|
|
4576
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
4577
|
+
* All rights reserved.
|
|
4578
|
+
* SPDX-License-Identifier: MIT
|
|
4579
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
4580
|
+
*/
|
|
4581
|
+
const SymbolIterator = Symbol.iterator;
|
|
4582
|
+
|
|
4817
4583
|
function addVNodeToChildLWC(vnode) {
|
|
4818
4584
|
ArrayPush$1.call(getVMBeingRendered().velements, vnode);
|
|
4819
4585
|
} // [h]tml node
|
|
@@ -4837,20 +4603,22 @@ function h(sel, data, children) {
|
|
|
4837
4603
|
|
|
4838
4604
|
forEach.call(children, childVnode => {
|
|
4839
4605
|
if (childVnode != null) {
|
|
4840
|
-
assert.isTrue(
|
|
4606
|
+
assert.isTrue('type' in childVnode && 'sel' in childVnode && 'elm' in childVnode && 'key' in childVnode, `${childVnode} is not a vnode.`);
|
|
4841
4607
|
}
|
|
4842
4608
|
});
|
|
4843
4609
|
}
|
|
4844
4610
|
|
|
4845
|
-
let
|
|
4611
|
+
let elm;
|
|
4846
4612
|
const {
|
|
4847
4613
|
key
|
|
4848
4614
|
} = data;
|
|
4849
4615
|
return {
|
|
4616
|
+
type: 2
|
|
4617
|
+
/* Element */
|
|
4618
|
+
,
|
|
4850
4619
|
sel,
|
|
4851
4620
|
data,
|
|
4852
4621
|
children,
|
|
4853
|
-
text,
|
|
4854
4622
|
elm,
|
|
4855
4623
|
key,
|
|
4856
4624
|
hook: ElementHook,
|
|
@@ -4931,7 +4699,7 @@ function c(sel, Ctor, data, children = EmptyArray) {
|
|
|
4931
4699
|
if (arguments.length === 4) {
|
|
4932
4700
|
forEach.call(children, childVnode => {
|
|
4933
4701
|
if (childVnode != null) {
|
|
4934
|
-
assert.isTrue(
|
|
4702
|
+
assert.isTrue('type' in childVnode && 'sel' in childVnode && 'elm' in childVnode && 'key' in childVnode, `${childVnode} is not a vnode.`);
|
|
4935
4703
|
}
|
|
4936
4704
|
});
|
|
4937
4705
|
}
|
|
@@ -4940,12 +4708,14 @@ function c(sel, Ctor, data, children = EmptyArray) {
|
|
|
4940
4708
|
const {
|
|
4941
4709
|
key
|
|
4942
4710
|
} = data;
|
|
4943
|
-
let
|
|
4711
|
+
let elm;
|
|
4944
4712
|
const vnode = {
|
|
4713
|
+
type: 3
|
|
4714
|
+
/* CustomElement */
|
|
4715
|
+
,
|
|
4945
4716
|
sel,
|
|
4946
4717
|
data,
|
|
4947
4718
|
children,
|
|
4948
|
-
text,
|
|
4949
4719
|
elm,
|
|
4950
4720
|
key,
|
|
4951
4721
|
hook: CustomElementHook,
|
|
@@ -5073,12 +4843,12 @@ function f(items) {
|
|
|
5073
4843
|
|
|
5074
4844
|
|
|
5075
4845
|
function t(text) {
|
|
5076
|
-
|
|
5077
|
-
let sel, children, key, elm;
|
|
4846
|
+
let sel, key, elm;
|
|
5078
4847
|
return {
|
|
4848
|
+
type: 0
|
|
4849
|
+
/* Text */
|
|
4850
|
+
,
|
|
5079
4851
|
sel,
|
|
5080
|
-
data,
|
|
5081
|
-
children,
|
|
5082
4852
|
text,
|
|
5083
4853
|
elm,
|
|
5084
4854
|
key,
|
|
@@ -5089,12 +4859,12 @@ function t(text) {
|
|
|
5089
4859
|
|
|
5090
4860
|
|
|
5091
4861
|
function co(text) {
|
|
5092
|
-
|
|
5093
|
-
let sel, children, key, elm;
|
|
4862
|
+
let sel, key, elm;
|
|
5094
4863
|
return {
|
|
4864
|
+
type: 1
|
|
4865
|
+
/* Comment */
|
|
4866
|
+
,
|
|
5095
4867
|
sel,
|
|
5096
|
-
data,
|
|
5097
|
-
children,
|
|
5098
4868
|
text,
|
|
5099
4869
|
elm,
|
|
5100
4870
|
key,
|
|
@@ -5531,7 +5301,7 @@ function createStylesheet(vm, stylesheets) {
|
|
|
5531
5301
|
insertGlobalStylesheet(stylesheets[i]);
|
|
5532
5302
|
} else {
|
|
5533
5303
|
// local level
|
|
5534
|
-
insertStylesheet(stylesheets[i], root.
|
|
5304
|
+
insertStylesheet(stylesheets[i], root.shadowRoot);
|
|
5535
5305
|
}
|
|
5536
5306
|
}
|
|
5537
5307
|
}
|
|
@@ -5823,24 +5593,6 @@ function computeHasScopedStyles(template) {
|
|
|
5823
5593
|
return false;
|
|
5824
5594
|
}
|
|
5825
5595
|
|
|
5826
|
-
/*
|
|
5827
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
5828
|
-
* All rights reserved.
|
|
5829
|
-
* SPDX-License-Identifier: MIT
|
|
5830
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
5831
|
-
*/
|
|
5832
|
-
function addErrorComponentStack(vm, error) {
|
|
5833
|
-
if (!isFrozen(error) && isUndefined$1(error.wcStack)) {
|
|
5834
|
-
const wcStack = getErrorComponentStack(vm);
|
|
5835
|
-
defineProperty(error, 'wcStack', {
|
|
5836
|
-
get() {
|
|
5837
|
-
return wcStack;
|
|
5838
|
-
}
|
|
5839
|
-
|
|
5840
|
-
});
|
|
5841
|
-
}
|
|
5842
|
-
}
|
|
5843
|
-
|
|
5844
5596
|
/*
|
|
5845
5597
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
5846
5598
|
* All rights reserved.
|
|
@@ -6070,6 +5822,320 @@ function invokeServiceHook(vm, cbs) {
|
|
|
6070
5822
|
}
|
|
6071
5823
|
}
|
|
6072
5824
|
|
|
5825
|
+
/*
|
|
5826
|
+
* Copyright (c) 2022, salesforce.com, inc.
|
|
5827
|
+
* All rights reserved.
|
|
5828
|
+
* SPDX-License-Identifier: MIT
|
|
5829
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
5830
|
+
*/
|
|
5831
|
+
|
|
5832
|
+
function hydrate$1(vnode, node) {
|
|
5833
|
+
switch (vnode.type) {
|
|
5834
|
+
case 0
|
|
5835
|
+
/* Text */
|
|
5836
|
+
:
|
|
5837
|
+
hydrateText(vnode, node);
|
|
5838
|
+
break;
|
|
5839
|
+
|
|
5840
|
+
case 1
|
|
5841
|
+
/* Comment */
|
|
5842
|
+
:
|
|
5843
|
+
hydrateComment(vnode, node);
|
|
5844
|
+
break;
|
|
5845
|
+
|
|
5846
|
+
case 2
|
|
5847
|
+
/* Element */
|
|
5848
|
+
:
|
|
5849
|
+
hydrateElement(vnode, node);
|
|
5850
|
+
break;
|
|
5851
|
+
|
|
5852
|
+
case 3
|
|
5853
|
+
/* CustomElement */
|
|
5854
|
+
:
|
|
5855
|
+
hydrateCustomElement(vnode, node);
|
|
5856
|
+
break;
|
|
5857
|
+
}
|
|
5858
|
+
}
|
|
5859
|
+
|
|
5860
|
+
function hydrateText(vnode, node) {
|
|
5861
|
+
var _a;
|
|
5862
|
+
|
|
5863
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
5864
|
+
// eslint-disable-next-line lwc-internal/no-global-node
|
|
5865
|
+
validateNodeType(vnode, node, Node.TEXT_NODE);
|
|
5866
|
+
|
|
5867
|
+
if (node.nodeValue !== vnode.text && !(node.nodeValue === '\u200D' && vnode.text === '')) {
|
|
5868
|
+
logWarn('Hydration mismatch: text values do not match, will recover from the difference', vnode.owner);
|
|
5869
|
+
}
|
|
5870
|
+
} // always set the text value to the one from the vnode.
|
|
5871
|
+
|
|
5872
|
+
|
|
5873
|
+
node.nodeValue = (_a = vnode.text) !== null && _a !== void 0 ? _a : null;
|
|
5874
|
+
vnode.elm = node;
|
|
5875
|
+
}
|
|
5876
|
+
|
|
5877
|
+
function hydrateComment(vnode, node) {
|
|
5878
|
+
var _a;
|
|
5879
|
+
|
|
5880
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
5881
|
+
// eslint-disable-next-line lwc-internal/no-global-node
|
|
5882
|
+
validateNodeType(vnode, node, Node.COMMENT_NODE);
|
|
5883
|
+
|
|
5884
|
+
if (node.nodeValue !== vnode.text) {
|
|
5885
|
+
logWarn('Hydration mismatch: comment values do not match, will recover from the difference', vnode.owner);
|
|
5886
|
+
}
|
|
5887
|
+
} // always set the text value to the one from the vnode.
|
|
5888
|
+
|
|
5889
|
+
|
|
5890
|
+
node.nodeValue = (_a = vnode.text) !== null && _a !== void 0 ? _a : null;
|
|
5891
|
+
vnode.elm = node;
|
|
5892
|
+
}
|
|
5893
|
+
|
|
5894
|
+
function hydrateElement(vnode, node) {
|
|
5895
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
5896
|
+
// eslint-disable-next-line lwc-internal/no-global-node
|
|
5897
|
+
validateNodeType(vnode, node, Node.ELEMENT_NODE);
|
|
5898
|
+
validateElement(vnode, node);
|
|
5899
|
+
}
|
|
5900
|
+
|
|
5901
|
+
const elm = node;
|
|
5902
|
+
vnode.elm = elm;
|
|
5903
|
+
const {
|
|
5904
|
+
context
|
|
5905
|
+
} = vnode.data;
|
|
5906
|
+
const isDomManual = Boolean(!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
|
|
5907
|
+
/* Manual */
|
|
5908
|
+
);
|
|
5909
|
+
|
|
5910
|
+
if (isDomManual) {
|
|
5911
|
+
// it may be that this element has lwc:inner-html, we need to diff and in case are the same,
|
|
5912
|
+
// remove the innerHTML from props so it reuses the existing dom elements.
|
|
5913
|
+
const {
|
|
5914
|
+
props
|
|
5915
|
+
} = vnode.data;
|
|
5916
|
+
|
|
5917
|
+
if (!isUndefined$1(props) && !isUndefined$1(props.innerHTML)) {
|
|
5918
|
+
if (elm.innerHTML === props.innerHTML) {
|
|
5919
|
+
delete props.innerHTML;
|
|
5920
|
+
} else {
|
|
5921
|
+
logWarn(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: innerHTML values do not match for element, will recover from the difference`, vnode.owner);
|
|
5922
|
+
}
|
|
5923
|
+
}
|
|
5924
|
+
}
|
|
5925
|
+
|
|
5926
|
+
patchElementPropsAndAttrs(vnode);
|
|
5927
|
+
|
|
5928
|
+
if (!isDomManual) {
|
|
5929
|
+
hydrateChildren(vnode.elm.childNodes, vnode.children, vnode.owner);
|
|
5930
|
+
}
|
|
5931
|
+
}
|
|
5932
|
+
|
|
5933
|
+
function hydrateCustomElement(vnode, node) {
|
|
5934
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
5935
|
+
// eslint-disable-next-line lwc-internal/no-global-node
|
|
5936
|
+
validateNodeType(vnode, node, Node.ELEMENT_NODE);
|
|
5937
|
+
validateElement(vnode, node);
|
|
5938
|
+
}
|
|
5939
|
+
|
|
5940
|
+
const elm = node;
|
|
5941
|
+
vnode.elm = elm;
|
|
5942
|
+
const {
|
|
5943
|
+
sel,
|
|
5944
|
+
mode,
|
|
5945
|
+
ctor,
|
|
5946
|
+
owner
|
|
5947
|
+
} = vnode;
|
|
5948
|
+
const vm = createVM(elm, ctor, {
|
|
5949
|
+
mode,
|
|
5950
|
+
owner,
|
|
5951
|
+
tagName: sel
|
|
5952
|
+
});
|
|
5953
|
+
allocateChildren(vnode, vm);
|
|
5954
|
+
patchElementPropsAndAttrs(vnode); // Insert hook section:
|
|
5955
|
+
|
|
5956
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
5957
|
+
assert.isTrue(vm.state === 0
|
|
5958
|
+
/* created */
|
|
5959
|
+
, `${vm} cannot be recycled.`);
|
|
5960
|
+
}
|
|
5961
|
+
|
|
5962
|
+
runConnectedCallback(vm);
|
|
5963
|
+
|
|
5964
|
+
if (vm.renderMode !== 0
|
|
5965
|
+
/* Light */
|
|
5966
|
+
) {
|
|
5967
|
+
// VM is not rendering in Light DOM, we can proceed and hydrate the slotted content.
|
|
5968
|
+
// Note: for Light DOM, this is handled while hydrating the VM
|
|
5969
|
+
hydrateChildren(vnode.elm.childNodes, vnode.children, vm);
|
|
5970
|
+
}
|
|
5971
|
+
|
|
5972
|
+
hydrateVM(vm);
|
|
5973
|
+
}
|
|
5974
|
+
|
|
5975
|
+
function hydrateChildren(elmChildren, children, vm) {
|
|
5976
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
5977
|
+
const filteredVNodes = ArrayFilter.call(children, vnode => !!vnode);
|
|
5978
|
+
|
|
5979
|
+
if (elmChildren.length !== filteredVNodes.length) {
|
|
5980
|
+
logError(`Hydration mismatch: incorrect number of rendered nodes, expected ${filteredVNodes.length} but found ${elmChildren.length}.`, vm);
|
|
5981
|
+
throwHydrationError();
|
|
5982
|
+
}
|
|
5983
|
+
}
|
|
5984
|
+
|
|
5985
|
+
let childNodeIndex = 0;
|
|
5986
|
+
|
|
5987
|
+
for (let i = 0; i < children.length; i++) {
|
|
5988
|
+
const childVnode = children[i];
|
|
5989
|
+
|
|
5990
|
+
if (!isNull(childVnode)) {
|
|
5991
|
+
const childNode = elmChildren[childNodeIndex];
|
|
5992
|
+
hydrate$1(childVnode, childNode);
|
|
5993
|
+
childNodeIndex++;
|
|
5994
|
+
}
|
|
5995
|
+
}
|
|
5996
|
+
}
|
|
5997
|
+
|
|
5998
|
+
function patchElementPropsAndAttrs(vnode) {
|
|
5999
|
+
applyEventListeners(vnode);
|
|
6000
|
+
patchProps(null, vnode);
|
|
6001
|
+
}
|
|
6002
|
+
|
|
6003
|
+
function throwHydrationError() {
|
|
6004
|
+
assert.fail('Server rendered elements do not match client side generated elements');
|
|
6005
|
+
}
|
|
6006
|
+
|
|
6007
|
+
function validateNodeType(vnode, node, nodeType) {
|
|
6008
|
+
if (node.nodeType !== nodeType) {
|
|
6009
|
+
logError('Hydration mismatch: incorrect node type received', vnode.owner);
|
|
6010
|
+
assert.fail('Hydration mismatch: incorrect node type received.');
|
|
6011
|
+
}
|
|
6012
|
+
}
|
|
6013
|
+
|
|
6014
|
+
function validateElement(vnode, elm) {
|
|
6015
|
+
if (vnode.sel.toLowerCase() !== elm.tagName.toLowerCase()) {
|
|
6016
|
+
logError(`Hydration mismatch: expecting element with tag "${vnode.sel.toLowerCase()}" but found "${elm.tagName.toLowerCase()}".`, vnode.owner);
|
|
6017
|
+
throwHydrationError();
|
|
6018
|
+
}
|
|
6019
|
+
|
|
6020
|
+
const hasIncompatibleAttrs = validateAttrs(vnode, elm);
|
|
6021
|
+
const hasIncompatibleClass = validateClassAttr(vnode, elm);
|
|
6022
|
+
const hasIncompatibleStyle = validateStyleAttr(vnode, elm);
|
|
6023
|
+
const isVNodeAndElementCompatible = hasIncompatibleAttrs && hasIncompatibleClass && hasIncompatibleStyle;
|
|
6024
|
+
|
|
6025
|
+
if (!isVNodeAndElementCompatible) {
|
|
6026
|
+
throwHydrationError();
|
|
6027
|
+
}
|
|
6028
|
+
}
|
|
6029
|
+
|
|
6030
|
+
function validateAttrs(vnode, elm) {
|
|
6031
|
+
const {
|
|
6032
|
+
data: {
|
|
6033
|
+
attrs = {}
|
|
6034
|
+
}
|
|
6035
|
+
} = vnode;
|
|
6036
|
+
let nodesAreCompatible = true; // Validate attributes, though we could always recovery from those by running the update mods.
|
|
6037
|
+
// Note: intentionally ONLY matching vnodes.attrs to elm.attrs, in case SSR is adding extra attributes.
|
|
6038
|
+
|
|
6039
|
+
for (const [attrName, attrValue] of Object.entries(attrs)) {
|
|
6040
|
+
const elmAttrValue = getAttribute(elm, attrName);
|
|
6041
|
+
|
|
6042
|
+
if (String(attrValue) !== elmAttrValue) {
|
|
6043
|
+
logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "${attrName}" has different values, expected "${attrValue}" but found "${elmAttrValue}"`, vnode.owner);
|
|
6044
|
+
nodesAreCompatible = false;
|
|
6045
|
+
}
|
|
6046
|
+
}
|
|
6047
|
+
|
|
6048
|
+
return nodesAreCompatible;
|
|
6049
|
+
}
|
|
6050
|
+
|
|
6051
|
+
function validateClassAttr(vnode, elm) {
|
|
6052
|
+
const {
|
|
6053
|
+
data: {
|
|
6054
|
+
className,
|
|
6055
|
+
classMap
|
|
6056
|
+
}
|
|
6057
|
+
} = vnode;
|
|
6058
|
+
let nodesAreCompatible = true;
|
|
6059
|
+
let vnodeClassName;
|
|
6060
|
+
|
|
6061
|
+
if (!isUndefined$1(className) && String(className) !== elm.className) {
|
|
6062
|
+
// className is used when class is bound to an expr.
|
|
6063
|
+
nodesAreCompatible = false;
|
|
6064
|
+
vnodeClassName = className;
|
|
6065
|
+
} else if (!isUndefined$1(classMap)) {
|
|
6066
|
+
// classMap is used when class is set to static value.
|
|
6067
|
+
const classList = getClassList(elm);
|
|
6068
|
+
let computedClassName = ''; // all classes from the vnode should be in the element.classList
|
|
6069
|
+
|
|
6070
|
+
for (const name in classMap) {
|
|
6071
|
+
computedClassName += ' ' + name;
|
|
6072
|
+
|
|
6073
|
+
if (!classList.contains(name)) {
|
|
6074
|
+
nodesAreCompatible = false;
|
|
6075
|
+
}
|
|
6076
|
+
}
|
|
6077
|
+
|
|
6078
|
+
vnodeClassName = computedClassName.trim();
|
|
6079
|
+
|
|
6080
|
+
if (classList.length > keys(classMap).length) {
|
|
6081
|
+
nodesAreCompatible = false;
|
|
6082
|
+
}
|
|
6083
|
+
}
|
|
6084
|
+
|
|
6085
|
+
if (!nodesAreCompatible) {
|
|
6086
|
+
logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "class" has different values, expected "${vnodeClassName}" but found "${elm.className}"`, vnode.owner);
|
|
6087
|
+
}
|
|
6088
|
+
|
|
6089
|
+
return nodesAreCompatible;
|
|
6090
|
+
}
|
|
6091
|
+
|
|
6092
|
+
function validateStyleAttr(vnode, elm) {
|
|
6093
|
+
const {
|
|
6094
|
+
data: {
|
|
6095
|
+
style,
|
|
6096
|
+
styleDecls
|
|
6097
|
+
}
|
|
6098
|
+
} = vnode;
|
|
6099
|
+
const elmStyle = getAttribute(elm, 'style') || '';
|
|
6100
|
+
let vnodeStyle;
|
|
6101
|
+
let nodesAreCompatible = true;
|
|
6102
|
+
|
|
6103
|
+
if (!isUndefined$1(style) && style !== elmStyle) {
|
|
6104
|
+
nodesAreCompatible = false;
|
|
6105
|
+
vnodeStyle = style;
|
|
6106
|
+
} else if (!isUndefined$1(styleDecls)) {
|
|
6107
|
+
const parsedVnodeStyle = parseStyleText(elmStyle);
|
|
6108
|
+
const expectedStyle = []; // styleMap is used when style is set to static value.
|
|
6109
|
+
|
|
6110
|
+
for (let i = 0, n = styleDecls.length; i < n; i++) {
|
|
6111
|
+
const [prop, value, important] = styleDecls[i];
|
|
6112
|
+
expectedStyle.push(`${prop}: ${value + (important ? ' important!' : '')}`);
|
|
6113
|
+
const parsedPropValue = parsedVnodeStyle[prop];
|
|
6114
|
+
|
|
6115
|
+
if (isUndefined$1(parsedPropValue)) {
|
|
6116
|
+
nodesAreCompatible = false;
|
|
6117
|
+
} else if (!parsedPropValue.startsWith(value)) {
|
|
6118
|
+
nodesAreCompatible = false;
|
|
6119
|
+
} else if (important && !parsedPropValue.endsWith('!important')) {
|
|
6120
|
+
nodesAreCompatible = false;
|
|
6121
|
+
}
|
|
6122
|
+
}
|
|
6123
|
+
|
|
6124
|
+
if (keys(parsedVnodeStyle).length > styleDecls.length) {
|
|
6125
|
+
nodesAreCompatible = false;
|
|
6126
|
+
}
|
|
6127
|
+
|
|
6128
|
+
vnodeStyle = ArrayJoin.call(expectedStyle, ';');
|
|
6129
|
+
}
|
|
6130
|
+
|
|
6131
|
+
if (!nodesAreCompatible) {
|
|
6132
|
+
// style is used when class is bound to an expr.
|
|
6133
|
+
logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "style" has different values, expected "${vnodeStyle}" but found "${elmStyle}".`, vnode.owner);
|
|
6134
|
+
}
|
|
6135
|
+
|
|
6136
|
+
return nodesAreCompatible;
|
|
6137
|
+
}
|
|
6138
|
+
|
|
6073
6139
|
/*
|
|
6074
6140
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
6075
6141
|
* All rights reserved.
|
|
@@ -6188,12 +6254,13 @@ function getNearestShadowAncestor(vm) {
|
|
|
6188
6254
|
return ancestor;
|
|
6189
6255
|
}
|
|
6190
6256
|
|
|
6191
|
-
function createVM(elm,
|
|
6257
|
+
function createVM(elm, ctor, options) {
|
|
6192
6258
|
const {
|
|
6193
6259
|
mode,
|
|
6194
6260
|
owner,
|
|
6195
6261
|
tagName
|
|
6196
6262
|
} = options;
|
|
6263
|
+
const def = getComponentInternalDef(ctor);
|
|
6197
6264
|
const vm = {
|
|
6198
6265
|
elm,
|
|
6199
6266
|
def,
|
|
@@ -6215,7 +6282,6 @@ function createVM(elm, def, options) {
|
|
|
6215
6282
|
oar: create(null),
|
|
6216
6283
|
cmpTemplate: null,
|
|
6217
6284
|
renderMode: def.renderMode,
|
|
6218
|
-
shadowMode: null,
|
|
6219
6285
|
context: {
|
|
6220
6286
|
stylesheetToken: undefined,
|
|
6221
6287
|
hasTokenInClass: undefined,
|
|
@@ -6226,9 +6292,13 @@ function createVM(elm, def, options) {
|
|
|
6226
6292
|
wiredConnecting: EmptyArray,
|
|
6227
6293
|
wiredDisconnecting: EmptyArray
|
|
6228
6294
|
},
|
|
6295
|
+
// Properties set right after VM creation.
|
|
6229
6296
|
tro: null,
|
|
6297
|
+
shadowMode: null,
|
|
6298
|
+
// Properties set by the LightningElement constructor.
|
|
6230
6299
|
component: null,
|
|
6231
|
-
|
|
6300
|
+
shadowRoot: null,
|
|
6301
|
+
renderRoot: null,
|
|
6232
6302
|
callHook,
|
|
6233
6303
|
setHook,
|
|
6234
6304
|
getHook
|
|
@@ -6316,7 +6386,7 @@ function computeShadowMode(vm) {
|
|
|
6316
6386
|
}
|
|
6317
6387
|
|
|
6318
6388
|
function assertIsVM(obj) {
|
|
6319
|
-
if (isNull(obj) || !isObject(obj) || !('
|
|
6389
|
+
if (isNull(obj) || !isObject(obj) || !('renderRoot' in obj)) {
|
|
6320
6390
|
throw new TypeError(`${obj} is not a VM.`);
|
|
6321
6391
|
}
|
|
6322
6392
|
}
|
|
@@ -6363,13 +6433,14 @@ function hydrate(vm) {
|
|
|
6363
6433
|
const vmChildren = vm.renderMode === 0
|
|
6364
6434
|
/* Light */
|
|
6365
6435
|
? vm.elm.childNodes : vm.elm.shadowRoot.childNodes;
|
|
6366
|
-
|
|
6436
|
+
hydrateChildren(vmChildren, children, vm);
|
|
6367
6437
|
runRenderedCallback(vm);
|
|
6368
6438
|
}
|
|
6369
6439
|
}
|
|
6370
6440
|
|
|
6371
6441
|
function patchShadowRoot(vm, newCh) {
|
|
6372
6442
|
const {
|
|
6443
|
+
renderRoot,
|
|
6373
6444
|
children: oldCh
|
|
6374
6445
|
} = vm; // caching the new children collection
|
|
6375
6446
|
|
|
@@ -6386,7 +6457,6 @@ function patchShadowRoot(vm, newCh) {
|
|
|
6386
6457
|
, vm);
|
|
6387
6458
|
}, () => {
|
|
6388
6459
|
// job
|
|
6389
|
-
const renderRoot = getRenderRoot(vm);
|
|
6390
6460
|
patchChildren(renderRoot, oldCh, newCh);
|
|
6391
6461
|
}, () => {
|
|
6392
6462
|
// post
|
|
@@ -6622,14 +6692,22 @@ function recursivelyDisconnectChildren(vnodes) {
|
|
|
6622
6692
|
for (let i = 0, len = vnodes.length; i < len; i += 1) {
|
|
6623
6693
|
const vnode = vnodes[i];
|
|
6624
6694
|
|
|
6625
|
-
if (!isNull(vnode) &&
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
6632
|
-
|
|
6695
|
+
if (!isNull(vnode) && !isUndefined$1(vnode.elm)) {
|
|
6696
|
+
switch (vnode.type) {
|
|
6697
|
+
case 2
|
|
6698
|
+
/* Element */
|
|
6699
|
+
:
|
|
6700
|
+
recursivelyDisconnectChildren(vnode.children);
|
|
6701
|
+
break;
|
|
6702
|
+
|
|
6703
|
+
case 3
|
|
6704
|
+
/* CustomElement */
|
|
6705
|
+
:
|
|
6706
|
+
{
|
|
6707
|
+
const vm = getAssociatedVM(vnode.elm);
|
|
6708
|
+
resetComponentStateWhenRemoved(vm);
|
|
6709
|
+
break;
|
|
6710
|
+
}
|
|
6633
6711
|
}
|
|
6634
6712
|
}
|
|
6635
6713
|
}
|
|
@@ -6641,15 +6719,15 @@ function recursivelyDisconnectChildren(vnodes) {
|
|
|
6641
6719
|
|
|
6642
6720
|
function resetComponentRoot(vm) {
|
|
6643
6721
|
const {
|
|
6644
|
-
children
|
|
6722
|
+
children,
|
|
6723
|
+
renderRoot
|
|
6645
6724
|
} = vm;
|
|
6646
|
-
const rootNode = getRenderRoot(vm);
|
|
6647
6725
|
|
|
6648
6726
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
6649
6727
|
const child = children[i];
|
|
6650
6728
|
|
|
6651
6729
|
if (!isNull(child) && !isUndefined$1(child.elm)) {
|
|
6652
|
-
remove(child.elm,
|
|
6730
|
+
remove(child.elm, renderRoot);
|
|
6653
6731
|
}
|
|
6654
6732
|
}
|
|
6655
6733
|
|
|
@@ -6733,11 +6811,6 @@ function forceRehydration(vm) {
|
|
|
6733
6811
|
scheduleRehydration(vm);
|
|
6734
6812
|
}
|
|
6735
6813
|
}
|
|
6736
|
-
function getRenderRoot(vm) {
|
|
6737
|
-
return vm.renderMode === 1
|
|
6738
|
-
/* Shadow */
|
|
6739
|
-
? vm.cmpRoot : vm.elm;
|
|
6740
|
-
}
|
|
6741
6814
|
|
|
6742
6815
|
/*
|
|
6743
6816
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
@@ -7118,5 +7191,5 @@ function setHooks(hooks) {
|
|
|
7118
7191
|
setSanitizeHtmlContentHook(hooks.sanitizeHtmlContent);
|
|
7119
7192
|
}
|
|
7120
7193
|
|
|
7121
|
-
export { LightningElement, profilerControl as __unstable__ProfilerControl, api$1 as api, connectRootElement, createContextProvider, createVM, disconnectRootElement, getAssociatedVMIfPresent, getComponentDef,
|
|
7122
|
-
/* version: 2.7.
|
|
7194
|
+
export { LightningElement, profilerControl as __unstable__ProfilerControl, api$1 as api, connectRootElement, createContextProvider, createVM, disconnectRootElement, getAssociatedVMIfPresent, getComponentDef, getComponentHtmlPrototype, getUpgradableConstructor, hydrateRootElement, isComponentConstructor, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setAddEventListener, setAssertInstanceOfHTMLElement, setAttachShadow, setCreateComment, setCreateElement, setCreateText, setDefineCustomElement, setDispatchEvent, setGetAttribute, setGetBoundingClientRect, setGetChildNodes, setGetChildren, setGetClassList, setGetCustomElement, setGetElementsByClassName, setGetElementsByTagName, setGetFirstChild, setGetFirstElementChild, setGetLastChild, setGetLastElementChild, setGetProperty, setHTMLElement, setHooks, setInsert, setInsertGlobalStylesheet, setInsertStylesheet, setIsConnected, setIsHydrating, setIsNativeShadowDefined, setIsSyntheticShadowDefined, setNextSibling, setQuerySelector, setQuerySelectorAll, setRemove, setRemoveAttribute, setRemoveEventListener, setSetAttribute, setSetCSSStyleProperty, setSetProperty, setSetText, setSsr, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
|
|
7195
|
+
/* version: 2.7.4 */
|