lwc 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.
Files changed (35) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +866 -800
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +866 -800
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +654 -587
  5. package/dist/engine-dom/iife/es5/engine-dom.js +912 -848
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +698 -633
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +866 -800
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +654 -587
  11. package/dist/engine-dom/umd/es5/engine-dom.js +912 -848
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +698 -633
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +606 -903
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +606 -903
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +3 -3
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +3 -3
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +3 -3
  20. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +3 -3
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +3 -3
  22. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +3 -3
  23. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +3 -3
  24. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +3 -3
  25. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +3 -3
  26. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  27. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  28. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  29. package/dist/wire-service/iife/es5/wire-service.js +2 -2
  30. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  31. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/umd/es5/wire-service.js +2 -2
  34. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  35. package/package.json +8 -8
@@ -302,7 +302,11 @@ var LWC = (function (exports) {
302
302
  CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
303
303
  return attributeName;
304
304
  }
305
- /** version: 2.7.3 */
305
+
306
+ const XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
307
+ const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
308
+ const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
309
+ /** version: 2.7.4 */
306
310
 
307
311
  /*
308
312
  * Copyright (c) 2018, salesforce.com, inc.
@@ -311,7 +315,6 @@ var LWC = (function (exports) {
311
315
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
312
316
  */
313
317
 
314
-
315
318
  function detect(propName) {
316
319
  return Object.getOwnPropertyDescriptor(Element.prototype, propName) === undefined;
317
320
  }
@@ -480,7 +483,7 @@ var LWC = (function (exports) {
480
483
  setFeatureFlag(name, value);
481
484
  }
482
485
  }
483
- /** version: 2.7.3 */
486
+ /** version: 2.7.4 */
484
487
 
485
488
  /* proxy-compat-disable */
486
489
 
@@ -978,6 +981,25 @@ var LWC = (function (exports) {
978
981
  */
979
982
 
980
983
 
984
+ function addErrorComponentStack(vm, error) {
985
+ if (!isFrozen(error) && isUndefined$1(error.wcStack)) {
986
+ const wcStack = getErrorComponentStack(vm);
987
+ defineProperty(error, 'wcStack', {
988
+ get() {
989
+ return wcStack;
990
+ }
991
+
992
+ });
993
+ }
994
+ }
995
+ /*
996
+ * Copyright (c) 2018, salesforce.com, inc.
997
+ * All rights reserved.
998
+ * SPDX-License-Identifier: MIT
999
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1000
+ */
1001
+
1002
+
981
1003
  function log(method, message, vm) {
982
1004
  let msg = `[LWC ${method}]: ${message}`;
983
1005
 
@@ -1012,207 +1034,12 @@ var LWC = (function (exports) {
1012
1034
  * SPDX-License-Identifier: MIT
1013
1035
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1014
1036
  */
1037
+ // This is a temporary workaround to get the @lwc/engine-server to evaluate in node without having
1038
+ // to inject at runtime.
1015
1039
 
1016
1040
 
1017
- function isUndef(s) {
1018
- return s === undefined;
1019
- }
1020
-
1021
- function sameVnode(vnode1, vnode2) {
1022
- return vnode1.key === vnode2.key && vnode1.sel === vnode2.sel;
1023
- }
1024
-
1025
- function isVNode(vnode) {
1026
- return vnode != null;
1027
- }
1028
-
1029
- function createKeyToOldIdx(children, beginIdx, endIdx) {
1030
- const map = {};
1031
- let j, key, ch; // TODO [#1637]: simplify this by assuming that all vnodes has keys
1032
-
1033
- for (j = beginIdx; j <= endIdx; ++j) {
1034
- ch = children[j];
1035
-
1036
- if (isVNode(ch)) {
1037
- key = ch.key;
1038
-
1039
- if (key !== undefined) {
1040
- map[key] = j;
1041
- }
1042
- }
1043
- }
1044
-
1045
- return map;
1046
- }
1047
-
1048
- function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
1049
- for (; startIdx <= endIdx; ++startIdx) {
1050
- const ch = vnodes[startIdx];
1051
-
1052
- if (isVNode(ch)) {
1053
- ch.hook.create(ch);
1054
- ch.hook.insert(ch, parentElm, before);
1055
- }
1056
- }
1057
- }
1058
-
1059
- function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
1060
- for (; startIdx <= endIdx; ++startIdx) {
1061
- const ch = vnodes[startIdx]; // text nodes do not have logic associated to them
1062
-
1063
- if (isVNode(ch)) {
1064
- ch.hook.remove(ch, parentElm);
1065
- }
1066
- }
1067
- }
1068
-
1069
- function updateDynamicChildren(parentElm, oldCh, newCh) {
1070
- let oldStartIdx = 0;
1071
- let newStartIdx = 0;
1072
- let oldEndIdx = oldCh.length - 1;
1073
- let oldStartVnode = oldCh[0];
1074
- let oldEndVnode = oldCh[oldEndIdx];
1075
- const newChEnd = newCh.length - 1;
1076
- let newEndIdx = newChEnd;
1077
- let newStartVnode = newCh[0];
1078
- let newEndVnode = newCh[newEndIdx];
1079
- let oldKeyToIdx;
1080
- let idxInOld;
1081
- let elmToMove;
1082
- let before;
1083
-
1084
- while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
1085
- if (!isVNode(oldStartVnode)) {
1086
- oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left
1087
- } else if (!isVNode(oldEndVnode)) {
1088
- oldEndVnode = oldCh[--oldEndIdx];
1089
- } else if (!isVNode(newStartVnode)) {
1090
- newStartVnode = newCh[++newStartIdx];
1091
- } else if (!isVNode(newEndVnode)) {
1092
- newEndVnode = newCh[--newEndIdx];
1093
- } else if (sameVnode(oldStartVnode, newStartVnode)) {
1094
- patchVnode(oldStartVnode, newStartVnode);
1095
- oldStartVnode = oldCh[++oldStartIdx];
1096
- newStartVnode = newCh[++newStartIdx];
1097
- } else if (sameVnode(oldEndVnode, newEndVnode)) {
1098
- patchVnode(oldEndVnode, newEndVnode);
1099
- oldEndVnode = oldCh[--oldEndIdx];
1100
- newEndVnode = newCh[--newEndIdx];
1101
- } else if (sameVnode(oldStartVnode, newEndVnode)) {
1102
- // Vnode moved right
1103
- patchVnode(oldStartVnode, newEndVnode);
1104
- newEndVnode.hook.move(oldStartVnode, parentElm, nextSibling$1(oldEndVnode.elm));
1105
- oldStartVnode = oldCh[++oldStartIdx];
1106
- newEndVnode = newCh[--newEndIdx];
1107
- } else if (sameVnode(oldEndVnode, newStartVnode)) {
1108
- // Vnode moved left
1109
- patchVnode(oldEndVnode, newStartVnode);
1110
- newStartVnode.hook.move(oldEndVnode, parentElm, oldStartVnode.elm);
1111
- oldEndVnode = oldCh[--oldEndIdx];
1112
- newStartVnode = newCh[++newStartIdx];
1113
- } else {
1114
- if (oldKeyToIdx === undefined) {
1115
- oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
1116
- }
1117
-
1118
- idxInOld = oldKeyToIdx[newStartVnode.key];
1119
-
1120
- if (isUndef(idxInOld)) {
1121
- // New element
1122
- newStartVnode.hook.create(newStartVnode);
1123
- newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm);
1124
- newStartVnode = newCh[++newStartIdx];
1125
- } else {
1126
- elmToMove = oldCh[idxInOld];
1127
-
1128
- if (isVNode(elmToMove)) {
1129
- if (elmToMove.sel !== newStartVnode.sel) {
1130
- // New element
1131
- newStartVnode.hook.create(newStartVnode);
1132
- newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm);
1133
- } else {
1134
- patchVnode(elmToMove, newStartVnode);
1135
- oldCh[idxInOld] = undefined;
1136
- newStartVnode.hook.move(elmToMove, parentElm, oldStartVnode.elm);
1137
- }
1138
- }
1139
-
1140
- newStartVnode = newCh[++newStartIdx];
1141
- }
1142
- }
1143
- }
1144
-
1145
- if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
1146
- if (oldStartIdx > oldEndIdx) {
1147
- // There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
1148
- // already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
1149
- let i = newEndIdx;
1150
- let n;
1151
-
1152
- do {
1153
- n = newCh[++i];
1154
- } while (!isVNode(n) && i < newChEnd);
1155
-
1156
- before = isVNode(n) ? n.elm : null;
1157
- addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
1158
- } else {
1159
- removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
1160
- }
1161
- }
1162
- }
1163
-
1164
- function updateStaticChildren(parentElm, oldCh, newCh) {
1165
- const oldChLength = oldCh.length;
1166
- const newChLength = newCh.length;
1167
-
1168
- if (oldChLength === 0) {
1169
- // the old list is empty, we can directly insert anything new
1170
- addVnodes(parentElm, null, newCh, 0, newChLength);
1171
- return;
1172
- }
1173
-
1174
- if (newChLength === 0) {
1175
- // the old list is nonempty and the new list is empty so we can directly remove all old nodes
1176
- // this is the case in which the dynamic children of an if-directive should be removed
1177
- removeVnodes(parentElm, oldCh, 0, oldChLength);
1178
- return;
1179
- } // if the old list is not empty, the new list MUST have the same
1180
- // amount of nodes, that's why we call this static children
1181
-
1182
-
1183
- let referenceElm = null;
1184
-
1185
- for (let i = newChLength - 1; i >= 0; i -= 1) {
1186
- const vnode = newCh[i];
1187
- const oldVNode = oldCh[i];
1188
-
1189
- if (vnode !== oldVNode) {
1190
- if (isVNode(oldVNode)) {
1191
- if (isVNode(vnode)) {
1192
- // both vnodes must be equivalent, and se just need to patch them
1193
- patchVnode(oldVNode, vnode);
1194
- referenceElm = vnode.elm;
1195
- } else {
1196
- // removing the old vnode since the new one is null
1197
- oldVNode.hook.remove(oldVNode, parentElm);
1198
- }
1199
- } else if (isVNode(vnode)) {
1200
- // this condition is unnecessary
1201
- vnode.hook.create(vnode); // insert the new node one since the old one is null
1202
-
1203
- vnode.hook.insert(vnode, parentElm, referenceElm);
1204
- referenceElm = vnode.elm;
1205
- }
1206
- }
1207
- }
1208
- }
1209
-
1210
- function patchVnode(oldVnode, vnode) {
1211
- if (oldVnode !== vnode) {
1212
- vnode.elm = oldVnode.elm;
1213
- vnode.hook.update(oldVnode, vnode);
1214
- }
1215
- }
1041
+ const HTMLElementConstructor$1 = typeof HTMLElement !== 'undefined' ? HTMLElement : function () {};
1042
+ const HTMLElementPrototype = HTMLElementConstructor$1.prototype;
1216
1043
  /*
1217
1044
  * Copyright (c) 2018, salesforce.com, inc.
1218
1045
  * All rights reserved.
@@ -1220,7 +1047,6 @@ var LWC = (function (exports) {
1220
1047
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1221
1048
  */
1222
1049
 
1223
-
1224
1050
  const defaultDefHTMLPropertyNames = ['accessKey', 'dir', 'draggable', 'hidden', 'id', 'lang', 'spellcheck', 'tabIndex', 'title'];
1225
1051
 
1226
1052
  function offsetPropertyErrorMessage(name) {
@@ -1339,6 +1165,40 @@ var LWC = (function (exports) {
1339
1165
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1340
1166
  */
1341
1167
 
1168
+ /**
1169
+ * This is a descriptor map that contains
1170
+ * all standard properties that a Custom Element can support (including AOM properties), which
1171
+ * determines what kind of capabilities the Base HTML Element and
1172
+ * Base Lightning Element should support.
1173
+ */
1174
+
1175
+
1176
+ const HTMLElementOriginalDescriptors = create(null);
1177
+ forEach.call(keys(AriaPropNameToAttrNameMap), propName => {
1178
+ // Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because
1179
+ // in IE11, some properties are on Element.prototype instead of HTMLElement, just to be sure.
1180
+ const descriptor = getPropertyDescriptor(HTMLElementPrototype, propName);
1181
+
1182
+ if (!isUndefined$1(descriptor)) {
1183
+ HTMLElementOriginalDescriptors[propName] = descriptor;
1184
+ }
1185
+ });
1186
+ forEach.call(defaultDefHTMLPropertyNames, propName => {
1187
+ // Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because
1188
+ // in IE11, id property is on Element.prototype instead of HTMLElement, and we suspect that more will fall into
1189
+ // this category, so, better to be sure.
1190
+ const descriptor = getPropertyDescriptor(HTMLElementPrototype, propName);
1191
+
1192
+ if (!isUndefined$1(descriptor)) {
1193
+ HTMLElementOriginalDescriptors[propName] = descriptor;
1194
+ }
1195
+ });
1196
+ /*
1197
+ * Copyright (c) 2018, salesforce.com, inc.
1198
+ * All rights reserved.
1199
+ * SPDX-License-Identifier: MIT
1200
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1201
+ */
1342
1202
 
1343
1203
  function generateDataDescriptor(options) {
1344
1204
  return assign({
@@ -1701,56 +1561,11 @@ var LWC = (function (exports) {
1701
1561
  function patchLightningElementPrototypeWithRestrictions(proto) {
1702
1562
  defineProperties(proto, getLightningElementPrototypeRestrictionsDescriptors(proto));
1703
1563
  }
1704
- /*
1705
- * Copyright (c) 2018, salesforce.com, inc.
1706
- * All rights reserved.
1707
- * SPDX-License-Identifier: MIT
1708
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1564
+ /**
1565
+ * Copyright (C) 2017 salesforce.com, inc.
1709
1566
  */
1710
- // This is a temporary workaround to get the @lwc/engine-server to evaluate in node without having
1711
- // to inject at runtime.
1712
1567
 
1713
1568
 
1714
- const HTMLElementConstructor$1 = typeof HTMLElement !== 'undefined' ? HTMLElement : function () {};
1715
- const HTMLElementPrototype = HTMLElementConstructor$1.prototype;
1716
- /*
1717
- * Copyright (c) 2018, salesforce.com, inc.
1718
- * All rights reserved.
1719
- * SPDX-License-Identifier: MIT
1720
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1721
- */
1722
-
1723
- /**
1724
- * This is a descriptor map that contains
1725
- * all standard properties that a Custom Element can support (including AOM properties), which
1726
- * determines what kind of capabilities the Base HTML Element and
1727
- * Base Lightning Element should support.
1728
- */
1729
-
1730
- const HTMLElementOriginalDescriptors = create(null);
1731
- forEach.call(keys(AriaPropNameToAttrNameMap), propName => {
1732
- // Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because
1733
- // in IE11, some properties are on Element.prototype instead of HTMLElement, just to be sure.
1734
- const descriptor = getPropertyDescriptor(HTMLElementPrototype, propName);
1735
-
1736
- if (!isUndefined$1(descriptor)) {
1737
- HTMLElementOriginalDescriptors[propName] = descriptor;
1738
- }
1739
- });
1740
- forEach.call(defaultDefHTMLPropertyNames, propName => {
1741
- // Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because
1742
- // in IE11, id property is on Element.prototype instead of HTMLElement, and we suspect that more will fall into
1743
- // this category, so, better to be sure.
1744
- const descriptor = getPropertyDescriptor(HTMLElementPrototype, propName);
1745
-
1746
- if (!isUndefined$1(descriptor)) {
1747
- HTMLElementOriginalDescriptors[propName] = descriptor;
1748
- }
1749
- });
1750
- /**
1751
- * Copyright (C) 2017 salesforce.com, inc.
1752
- */
1753
-
1754
1569
  const {
1755
1570
  isArray
1756
1571
  } = Array;
@@ -2667,7 +2482,9 @@ var LWC = (function (exports) {
2667
2482
  if (vm.renderMode === 1
2668
2483
  /* Shadow */
2669
2484
  ) {
2670
- doAttachShadow(vm);
2485
+ vm.renderRoot = doAttachShadow(vm);
2486
+ } else {
2487
+ vm.renderRoot = elm;
2671
2488
  } // Adding extra guard rails in DEV mode.
2672
2489
 
2673
2490
 
@@ -2688,19 +2505,21 @@ var LWC = (function (exports) {
2688
2505
  ctor
2689
2506
  }
2690
2507
  } = vm;
2691
- const cmpRoot = attachShadow$1(elm, {
2508
+ const shadowRoot = attachShadow$1(elm, {
2692
2509
  [KEY__SYNTHETIC_MODE]: shadowMode === 1
2693
2510
  /* Synthetic */
2694
2511
  ,
2695
2512
  delegatesFocus: Boolean(ctor.delegatesFocus),
2696
2513
  mode
2697
2514
  });
2698
- vm.cmpRoot = cmpRoot;
2699
- associateVM(cmpRoot, vm);
2515
+ vm.shadowRoot = shadowRoot;
2516
+ associateVM(shadowRoot, vm);
2700
2517
 
2701
2518
  if (process.env.NODE_ENV !== 'production') {
2702
- patchShadowRootWithRestrictions(cmpRoot);
2519
+ patchShadowRootWithRestrictions(shadowRoot);
2703
2520
  }
2521
+
2522
+ return shadowRoot;
2704
2523
  }
2705
2524
 
2706
2525
  function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
@@ -2868,7 +2687,7 @@ var LWC = (function (exports) {
2868
2687
  }
2869
2688
  }
2870
2689
 
2871
- return vm.cmpRoot;
2690
+ return vm.shadowRoot;
2872
2691
  },
2873
2692
 
2874
2693
  get shadowRoot() {
@@ -4280,6 +4099,11 @@ var LWC = (function (exports) {
4280
4099
  return def;
4281
4100
  }
4282
4101
 
4102
+ function getComponentHtmlPrototype(Ctor) {
4103
+ const def = getComponentInternalDef(Ctor);
4104
+ return def.bridge;
4105
+ }
4106
+
4283
4107
  const lightingElementDef = {
4284
4108
  ctor: LightningElement,
4285
4109
  name: LightningElement.name,
@@ -4342,6 +4166,65 @@ var LWC = (function (exports) {
4342
4166
  methods: publicMethods
4343
4167
  };
4344
4168
  }
4169
+ /*
4170
+ * Copyright (c) 2020, salesforce.com, inc.
4171
+ * All rights reserved.
4172
+ * SPDX-License-Identifier: MIT
4173
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4174
+ */
4175
+
4176
+
4177
+ function getUpgradableConstructor(tagName) {
4178
+ // Should never get a tag with upper case letter at this point, the compiler should
4179
+ // produce only tags with lowercase letters
4180
+ // But, for backwards compatibility, we will lower case the tagName
4181
+ tagName = tagName.toLowerCase();
4182
+ let CE = getCustomElement$1(tagName);
4183
+
4184
+ if (!isUndefined$1(CE)) {
4185
+ return CE;
4186
+ }
4187
+ /**
4188
+ * LWC Upgradable Element reference to an element that was created
4189
+ * via the scoped registry mechanism, and that is ready to be upgraded.
4190
+ */
4191
+
4192
+
4193
+ CE = class LWCUpgradableElement extends HTMLElementExported$1 {
4194
+ constructor(upgradeCallback) {
4195
+ super();
4196
+
4197
+ if (isFunction$1(upgradeCallback)) {
4198
+ upgradeCallback(this); // nothing to do with the result for now
4199
+ }
4200
+ }
4201
+
4202
+ };
4203
+ defineCustomElement$1(tagName, CE);
4204
+ return CE;
4205
+ }
4206
+ /*
4207
+ * Copyright (c) 2018, salesforce.com, inc.
4208
+ * All rights reserved.
4209
+ * SPDX-License-Identifier: MIT
4210
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4211
+ */
4212
+
4213
+
4214
+ function isVBaseElement(vnode) {
4215
+ const {
4216
+ type
4217
+ } = vnode;
4218
+ return type === 2
4219
+ /* Element */
4220
+ || type === 3
4221
+ /* CustomElement */
4222
+ ;
4223
+ }
4224
+
4225
+ function isSameVnode(vnode1, vnode2) {
4226
+ return vnode1.key === vnode2.key && vnode1.sel === vnode2.sel;
4227
+ }
4345
4228
  /*
4346
4229
  * Copyright (c) 2018, salesforce.com, inc.
4347
4230
  * All rights reserved.
@@ -4350,8 +4233,6 @@ var LWC = (function (exports) {
4350
4233
  */
4351
4234
 
4352
4235
 
4353
- const xlinkNS = 'http://www.w3.org/1999/xlink';
4354
- const xmlNS = 'http://www.w3.org/XML/1998/namespace';
4355
4236
  const ColonCharCode = 58;
4356
4237
 
4357
4238
  function patchAttributes(oldVnode, vnode) {
@@ -4382,10 +4263,10 @@ var LWC = (function (exports) {
4382
4263
 
4383
4264
  if (StringCharCodeAt.call(key, 3) === ColonCharCode) {
4384
4265
  // Assume xml namespace
4385
- setAttribute$1(elm, key, cur, xmlNS);
4266
+ setAttribute$1(elm, key, cur, XML_NAMESPACE);
4386
4267
  } else if (StringCharCodeAt.call(key, 5) === ColonCharCode) {
4387
4268
  // Assume xlink namespace
4388
- setAttribute$1(elm, key, cur, xlinkNS);
4269
+ setAttribute$1(elm, key, cur, XLINK_NAMESPACE);
4389
4270
  } else if (isNull(cur) || isUndefined$1(cur)) {
4390
4271
  removeAttribute$1(elm, key);
4391
4272
  } else {
@@ -4639,6 +4520,161 @@ var LWC = (function (exports) {
4639
4520
  */
4640
4521
 
4641
4522
 
4523
+ const TextHook = {
4524
+ create: vnode => {
4525
+ const {
4526
+ owner
4527
+ } = vnode;
4528
+ const elm = createText$1(vnode.text);
4529
+ linkNodeToShadow(elm, owner);
4530
+ vnode.elm = elm;
4531
+ },
4532
+ update: updateNodeHook,
4533
+ insert: insertNode,
4534
+ move: insertNode,
4535
+ remove: removeNode
4536
+ };
4537
+ const CommentHook = {
4538
+ create: vnode => {
4539
+ const {
4540
+ owner,
4541
+ text
4542
+ } = vnode;
4543
+ const elm = createComment$1(text);
4544
+ linkNodeToShadow(elm, owner);
4545
+ vnode.elm = elm;
4546
+ },
4547
+ update: updateNodeHook,
4548
+ insert: insertNode,
4549
+ move: insertNode,
4550
+ remove: removeNode
4551
+ }; // insert is called after update, which is used somewhere else (via a module)
4552
+ // to mark the vm as inserted, that means we cannot use update as the main channel
4553
+ // to rehydrate when dirty, because sometimes the element is not inserted just yet,
4554
+ // which breaks some invariants. For that reason, we have the following for any
4555
+ // Custom Element that is inserted via a template.
4556
+
4557
+ const ElementHook = {
4558
+ create: vnode => {
4559
+ const {
4560
+ sel,
4561
+ owner,
4562
+ data: {
4563
+ svg
4564
+ }
4565
+ } = vnode;
4566
+ const namespace = isTrue(svg) ? SVG_NAMESPACE : undefined;
4567
+ const elm = createElement$2(sel, namespace);
4568
+ linkNodeToShadow(elm, owner);
4569
+ fallbackElmHook(elm, vnode);
4570
+ vnode.elm = elm;
4571
+ patchElementPropsAndAttrs$1(null, vnode);
4572
+ },
4573
+ update: (oldVnode, vnode) => {
4574
+ patchElementPropsAndAttrs$1(oldVnode, vnode);
4575
+ patchChildren(vnode.elm, oldVnode.children, vnode.children);
4576
+ },
4577
+ insert: (vnode, parentNode, referenceNode) => {
4578
+ insertNode(vnode, parentNode, referenceNode);
4579
+ createChildrenHook(vnode);
4580
+ },
4581
+ move: insertNode,
4582
+ remove: (vnode, parentNode) => {
4583
+ removeNode(vnode, parentNode);
4584
+ removeChildren(vnode);
4585
+ }
4586
+ };
4587
+ const CustomElementHook = {
4588
+ create: vnode => {
4589
+ const {
4590
+ sel,
4591
+ owner
4592
+ } = vnode;
4593
+ const UpgradableConstructor = getUpgradableConstructor(sel);
4594
+ /**
4595
+ * Note: if the upgradable constructor does not expect, or throw when we new it
4596
+ * with a callback as the first argument, we could implement a more advanced
4597
+ * mechanism that only passes that argument if the constructor is known to be
4598
+ * an upgradable custom element.
4599
+ */
4600
+
4601
+ let vm;
4602
+ const elm = new UpgradableConstructor(elm => {
4603
+ // the custom element from the registry is expecting an upgrade callback
4604
+ vm = createViewModelHook(elm, vnode);
4605
+ });
4606
+ linkNodeToShadow(elm, owner);
4607
+ vnode.elm = elm;
4608
+
4609
+ if (vm) {
4610
+ allocateChildren(vnode, vm);
4611
+ } else if (vnode.ctor !== UpgradableConstructor) {
4612
+ throw new TypeError(`Incorrect Component Constructor`);
4613
+ }
4614
+
4615
+ patchElementPropsAndAttrs$1(null, vnode);
4616
+ },
4617
+ update: (oldVnode, vnode) => {
4618
+ patchElementPropsAndAttrs$1(oldVnode, vnode);
4619
+ const vm = getAssociatedVMIfPresent(vnode.elm);
4620
+
4621
+ if (vm) {
4622
+ // in fallback mode, the allocation will always set children to
4623
+ // empty and delegate the real allocation to the slot elements
4624
+ allocateChildren(vnode, vm);
4625
+ } // in fallback mode, the children will be always empty, so, nothing
4626
+ // will happen, but in native, it does allocate the light dom
4627
+
4628
+
4629
+ patchChildren(vnode.elm, oldVnode.children, vnode.children);
4630
+
4631
+ if (vm) {
4632
+ if (process.env.NODE_ENV !== 'production') {
4633
+ assert.isTrue(isArray$1(vnode.children), `Invalid vnode for a custom element, it must have children defined.`);
4634
+ } // this will probably update the shadowRoot, but only if the vm is in a dirty state
4635
+ // this is important to preserve the top to bottom synchronous rendering phase.
4636
+
4637
+
4638
+ rerenderVM(vm);
4639
+ }
4640
+ },
4641
+ insert: (vnode, parentNode, referenceNode) => {
4642
+ insertNode(vnode, parentNode, referenceNode);
4643
+ const vm = getAssociatedVMIfPresent(vnode.elm);
4644
+
4645
+ if (vm) {
4646
+ if (process.env.NODE_ENV !== 'production') {
4647
+ assert.isTrue(vm.state === 0
4648
+ /* created */
4649
+ , `${vm} cannot be recycled.`);
4650
+ }
4651
+
4652
+ runConnectedCallback(vm);
4653
+ }
4654
+
4655
+ createChildrenHook(vnode);
4656
+
4657
+ if (vm) {
4658
+ appendVM(vm);
4659
+ }
4660
+ },
4661
+ move: insertNode,
4662
+ remove: (vnode, parentNode) => {
4663
+ removeNode(vnode, parentNode);
4664
+ const vm = getAssociatedVMIfPresent(vnode.elm);
4665
+
4666
+ if (vm) {
4667
+ // for custom elements we don't have to go recursively because the removeVM routine
4668
+ // will take care of disconnecting any child VM attached to its shadow as well.
4669
+ removeVM(vm);
4670
+ }
4671
+ }
4672
+ };
4673
+
4674
+ function isVNode(vnode) {
4675
+ return vnode != null;
4676
+ }
4677
+
4642
4678
  function observeElementChildNodes(elm) {
4643
4679
  elm.$domManual$ = true;
4644
4680
  }
@@ -4660,6 +4696,24 @@ var LWC = (function (exports) {
4660
4696
  }
4661
4697
  }
4662
4698
 
4699
+ function linkNodeToShadow(elm, owner) {
4700
+ const {
4701
+ renderRoot,
4702
+ renderMode,
4703
+ shadowMode
4704
+ } = owner; // TODO [#1164]: this should eventually be done by the polyfill directly
4705
+
4706
+ if (isSyntheticShadowDefined$1) {
4707
+ if (shadowMode === 1
4708
+ /* Synthetic */
4709
+ || renderMode === 0
4710
+ /* Light */
4711
+ ) {
4712
+ elm[KEY__SHADOW_RESOLVER] = renderRoot[KEY__SHADOW_RESOLVER];
4713
+ }
4714
+ }
4715
+ }
4716
+
4663
4717
  function updateNodeHook(oldVnode, vnode) {
4664
4718
  const {
4665
4719
  elm,
@@ -4679,7 +4733,7 @@ var LWC = (function (exports) {
4679
4733
  }
4680
4734
  }
4681
4735
 
4682
- function insertNodeHook(vnode, parentNode, referenceNode) {
4736
+ function insertNode(vnode, parentNode, referenceNode) {
4683
4737
  if (process.env.NODE_ENV !== 'production') {
4684
4738
  unlockDomMutation();
4685
4739
  }
@@ -4691,7 +4745,7 @@ var LWC = (function (exports) {
4691
4745
  }
4692
4746
  }
4693
4747
 
4694
- function removeNodeHook(vnode, parentNode) {
4748
+ function removeNode(vnode, parentNode) {
4695
4749
  if (process.env.NODE_ENV !== 'production') {
4696
4750
  unlockDomMutation();
4697
4751
  }
@@ -4703,7 +4757,7 @@ var LWC = (function (exports) {
4703
4757
  }
4704
4758
  }
4705
4759
 
4706
- function patchElementPropsAndAttrs(oldVnode, vnode) {
4760
+ function patchElementPropsAndAttrs$1(oldVnode, vnode) {
4707
4761
  if (isNull(oldVnode)) {
4708
4762
  applyEventListeners(vnode);
4709
4763
  applyStaticClassAttribute(vnode);
@@ -4718,11 +4772,6 @@ var LWC = (function (exports) {
4718
4772
  patchProps(oldVnode, vnode);
4719
4773
  }
4720
4774
 
4721
- function hydrateElmHook(vnode) {
4722
- applyEventListeners(vnode);
4723
- patchProps(null, vnode);
4724
- }
4725
-
4726
4775
  function fallbackElmHook(elm, vnode) {
4727
4776
  const {
4728
4777
  owner
@@ -4742,7 +4791,7 @@ var LWC = (function (exports) {
4742
4791
  } = owner.context;
4743
4792
 
4744
4793
  if (!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
4745
- /* manual */
4794
+ /* Manual */
4746
4795
  ) {
4747
4796
  // this element will now accept any manual content inserted into it
4748
4797
  observeElementChildNodes(elm);
@@ -4760,7 +4809,7 @@ var LWC = (function (exports) {
4760
4809
  }
4761
4810
  } = vnode;
4762
4811
  const isPortal = !isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
4763
- /* manual */
4812
+ /* Manual */
4764
4813
  ;
4765
4814
  const isLight = owner.renderMode === 0
4766
4815
  /* Light */
@@ -4780,7 +4829,7 @@ var LWC = (function (exports) {
4780
4829
  }
4781
4830
  }
4782
4831
 
4783
- function allocateChildrenHook(vnode, vm) {
4832
+ function allocateChildren(vnode, vm) {
4784
4833
  // A component with slots will re-render because:
4785
4834
  // 1- There is a change of the internal state.
4786
4835
  // 2- There is a change on the external api (ex: slots)
@@ -4813,11 +4862,12 @@ var LWC = (function (exports) {
4813
4862
  }
4814
4863
 
4815
4864
  function createViewModelHook(elm, vnode) {
4816
- if (!isUndefined$1(getAssociatedVMIfPresent(elm))) {
4817
- // There is a possibility that a custom element is registered under tagName,
4818
- // in which case, the initialization is already carry on, and there is nothing else
4819
- // to do here since this hook is called right after invoking `document.createElement`.
4820
- return;
4865
+ let vm = getAssociatedVMIfPresent(elm); // There is a possibility that a custom element is registered under tagName, in which case, the
4866
+ // initialization is already carry on, and there is nothing else to do here since this hook is
4867
+ // called right after invoking `document.createElement`.
4868
+
4869
+ if (!isUndefined$1(vm)) {
4870
+ return vm;
4821
4871
  }
4822
4872
 
4823
4873
  const {
@@ -4839,8 +4889,7 @@ var LWC = (function (exports) {
4839
4889
  setElementShadowToken(elm, stylesheetToken);
4840
4890
  }
4841
4891
 
4842
- const def = getComponentInternalDef(ctor);
4843
- createVM(elm, def, {
4892
+ vm = createVM(elm, ctor, {
4844
4893
  mode,
4845
4894
  owner,
4846
4895
  tagName: sel
@@ -4849,7 +4898,9 @@ var LWC = (function (exports) {
4849
4898
  if (process.env.NODE_ENV !== 'production') {
4850
4899
  assert.isTrue(isArray$1(vnode.children), `Invalid vnode for a custom element, it must have children defined.`);
4851
4900
  }
4852
- }
4901
+
4902
+ return vm;
4903
+ }
4853
4904
 
4854
4905
  function createChildrenHook(vnode) {
4855
4906
  const {
@@ -4867,171 +4918,7 @@ var LWC = (function (exports) {
4867
4918
  }
4868
4919
  }
4869
4920
 
4870
- function isElementNode(node) {
4871
- // eslint-disable-next-line lwc-internal/no-global-node
4872
- return node.nodeType === Node.ELEMENT_NODE;
4873
- }
4874
-
4875
- function vnodesAndElementHaveCompatibleAttrs(vnode, elm) {
4876
- const {
4877
- data: {
4878
- attrs = {}
4879
- }
4880
- } = vnode;
4881
- let nodesAreCompatible = true; // Validate attributes, though we could always recovery from those by running the update mods.
4882
- // Note: intentionally ONLY matching vnodes.attrs to elm.attrs, in case SSR is adding extra attributes.
4883
-
4884
- for (const [attrName, attrValue] of Object.entries(attrs)) {
4885
- const elmAttrValue = getAttribute$1(elm, attrName);
4886
-
4887
- if (String(attrValue) !== elmAttrValue) {
4888
- logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "${attrName}" has different values, expected "${attrValue}" but found "${elmAttrValue}"`, vnode.owner);
4889
- nodesAreCompatible = false;
4890
- }
4891
- }
4892
-
4893
- return nodesAreCompatible;
4894
- }
4895
-
4896
- function vnodesAndElementHaveCompatibleClass(vnode, elm) {
4897
- const {
4898
- data: {
4899
- className,
4900
- classMap
4901
- }
4902
- } = vnode;
4903
- let nodesAreCompatible = true;
4904
- let vnodeClassName;
4905
-
4906
- if (!isUndefined$1(className) && String(className) !== elm.className) {
4907
- // className is used when class is bound to an expr.
4908
- nodesAreCompatible = false;
4909
- vnodeClassName = className;
4910
- } else if (!isUndefined$1(classMap)) {
4911
- // classMap is used when class is set to static value.
4912
- const classList = getClassList$1(elm);
4913
- let computedClassName = ''; // all classes from the vnode should be in the element.classList
4914
-
4915
- for (const name in classMap) {
4916
- computedClassName += ' ' + name;
4917
-
4918
- if (!classList.contains(name)) {
4919
- nodesAreCompatible = false;
4920
- }
4921
- }
4922
-
4923
- vnodeClassName = computedClassName.trim();
4924
-
4925
- if (classList.length > keys(classMap).length) {
4926
- nodesAreCompatible = false;
4927
- }
4928
- }
4929
-
4930
- if (!nodesAreCompatible) {
4931
- logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "class" has different values, expected "${vnodeClassName}" but found "${elm.className}"`, vnode.owner);
4932
- }
4933
-
4934
- return nodesAreCompatible;
4935
- }
4936
-
4937
- function vnodesAndElementHaveCompatibleStyle(vnode, elm) {
4938
- const {
4939
- data: {
4940
- style,
4941
- styleDecls
4942
- }
4943
- } = vnode;
4944
- const elmStyle = getAttribute$1(elm, 'style') || '';
4945
- let vnodeStyle;
4946
- let nodesAreCompatible = true;
4947
-
4948
- if (!isUndefined$1(style) && style !== elmStyle) {
4949
- nodesAreCompatible = false;
4950
- vnodeStyle = style;
4951
- } else if (!isUndefined$1(styleDecls)) {
4952
- const parsedVnodeStyle = parseStyleText(elmStyle);
4953
- const expectedStyle = []; // styleMap is used when style is set to static value.
4954
-
4955
- for (let i = 0, n = styleDecls.length; i < n; i++) {
4956
- const [prop, value, important] = styleDecls[i];
4957
- expectedStyle.push(`${prop}: ${value + (important ? ' important!' : '')}`);
4958
- const parsedPropValue = parsedVnodeStyle[prop];
4959
-
4960
- if (isUndefined$1(parsedPropValue)) {
4961
- nodesAreCompatible = false;
4962
- } else if (!parsedPropValue.startsWith(value)) {
4963
- nodesAreCompatible = false;
4964
- } else if (important && !parsedPropValue.endsWith('!important')) {
4965
- nodesAreCompatible = false;
4966
- }
4967
- }
4968
-
4969
- if (keys(parsedVnodeStyle).length > styleDecls.length) {
4970
- nodesAreCompatible = false;
4971
- }
4972
-
4973
- vnodeStyle = ArrayJoin.call(expectedStyle, ';');
4974
- }
4975
-
4976
- if (!nodesAreCompatible) {
4977
- // style is used when class is bound to an expr.
4978
- logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "style" has different values, expected "${vnodeStyle}" but found "${elmStyle}".`, vnode.owner);
4979
- }
4980
-
4981
- return nodesAreCompatible;
4982
- }
4983
-
4984
- function throwHydrationError() {
4985
- assert.fail('Server rendered elements do not match client side generated elements');
4986
- }
4987
-
4988
- function hydrateChildrenHook(elmChildren, children, vm) {
4989
- var _a, _b;
4990
-
4991
- if (process.env.NODE_ENV !== 'production') {
4992
- const filteredVNodes = ArrayFilter.call(children, vnode => !!vnode);
4993
-
4994
- if (elmChildren.length !== filteredVNodes.length) {
4995
- logError(`Hydration mismatch: incorrect number of rendered nodes, expected ${filteredVNodes.length} but found ${elmChildren.length}.`, vm);
4996
- throwHydrationError();
4997
- }
4998
- }
4999
-
5000
- let elmCurrentChildIdx = 0;
5001
-
5002
- for (let j = 0, n = children.length; j < n; j++) {
5003
- const ch = children[j];
5004
-
5005
- if (ch != null) {
5006
- const childNode = elmChildren[elmCurrentChildIdx];
5007
-
5008
- if (process.env.NODE_ENV !== 'production') {
5009
- // VComments and VTexts validation is handled in their hooks
5010
- if (isElementNode(childNode)) {
5011
- if (((_a = ch.sel) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== childNode.tagName.toLowerCase()) {
5012
- logError(`Hydration mismatch: expecting element with tag "${(_b = ch.sel) === null || _b === void 0 ? void 0 : _b.toLowerCase()}" but found "${childNode.tagName.toLowerCase()}".`, vm);
5013
- throwHydrationError();
5014
- } // Note: props are not yet set
5015
-
5016
-
5017
- const hasIncompatibleAttrs = vnodesAndElementHaveCompatibleAttrs(ch, childNode);
5018
- const hasIncompatibleClass = vnodesAndElementHaveCompatibleClass(ch, childNode);
5019
- const hasIncompatibleStyle = vnodesAndElementHaveCompatibleStyle(ch, childNode);
5020
- const isVNodeAndElementCompatible = hasIncompatibleAttrs && hasIncompatibleClass && hasIncompatibleStyle;
5021
-
5022
- if (!isVNodeAndElementCompatible) {
5023
- throwHydrationError();
5024
- }
5025
- }
5026
- }
5027
-
5028
- ch.hook.hydrate(ch, childNode);
5029
- elmCurrentChildIdx++;
5030
- }
5031
- }
5032
- }
5033
-
5034
- function removeElmHook(vnode) {
4921
+ function removeChildren(vnode) {
5035
4922
  // this method only needs to search on child vnodes from template
5036
4923
  // to trigger the remove hook just in case some of those children
5037
4924
  // are custom elements.
@@ -5050,6 +4937,8 @@ var LWC = (function (exports) {
5050
4937
  }
5051
4938
 
5052
4939
  function allocateInSlot(vm, children) {
4940
+ var _a;
4941
+
5053
4942
  const {
5054
4943
  cmpSlots: oldSlots
5055
4944
  } = vm;
@@ -5062,10 +4951,12 @@ var LWC = (function (exports) {
5062
4951
  continue;
5063
4952
  }
5064
4953
 
5065
- const {
5066
- data
5067
- } = vnode;
5068
- const slotName = data.attrs && data.attrs.slot || '';
4954
+ let slotName = '';
4955
+
4956
+ if (isVBaseElement(vnode)) {
4957
+ slotName = ((_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) || '';
4958
+ }
4959
+
5069
4960
  const vnodes = cmpSlots[slotName] = cmpSlots[slotName] || []; // re-keying the vnodes is necessary to avoid conflicts with default content for the slot
5070
4961
  // which might have similar keys. Each vnode will always have a key that
5071
4962
  // starts with a numeric character from compiler. In this case, we add a unique
@@ -5120,331 +5011,204 @@ var LWC = (function (exports) {
5120
5011
  function hasDynamicChildren(children) {
5121
5012
  return FromIteration.has(children);
5122
5013
  }
5123
- /*
5124
- * Copyright (c) 2020, salesforce.com, inc.
5125
- * All rights reserved.
5126
- * SPDX-License-Identifier: MIT
5127
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5128
- */
5129
-
5130
-
5131
- function getUpgradableConstructor(tagName) {
5132
- // Should never get a tag with upper case letter at this point, the compiler should
5133
- // produce only tags with lowercase letters
5134
- // But, for backwards compatibility, we will lower case the tagName
5135
- tagName = tagName.toLowerCase();
5136
- let CE = getCustomElement$1(tagName);
5137
5014
 
5138
- if (!isUndefined$1(CE)) {
5139
- return CE;
5140
- }
5141
- /**
5142
- * LWC Upgradable Element reference to an element that was created
5143
- * via the scoped registry mechanism, and that is ready to be upgraded.
5144
- */
5015
+ function createKeyToOldIdx(children, beginIdx, endIdx) {
5016
+ const map = {}; // TODO [#1637]: simplify this by assuming that all vnodes has keys
5145
5017
 
5018
+ for (let j = beginIdx; j <= endIdx; ++j) {
5019
+ const ch = children[j];
5146
5020
 
5147
- CE = class LWCUpgradableElement extends HTMLElementExported$1 {
5148
- constructor(upgradeCallback) {
5149
- super();
5021
+ if (isVNode(ch)) {
5022
+ const {
5023
+ key
5024
+ } = ch;
5150
5025
 
5151
- if (isFunction$1(upgradeCallback)) {
5152
- upgradeCallback(this); // nothing to do with the result for now
5026
+ if (key !== undefined) {
5027
+ map[key] = j;
5153
5028
  }
5154
5029
  }
5030
+ }
5155
5031
 
5156
- };
5157
- defineCustomElement$1(tagName, CE);
5158
- return CE;
5032
+ return map;
5159
5033
  }
5160
- /*
5161
- * Copyright (c) 2018, salesforce.com, inc.
5162
- * All rights reserved.
5163
- * SPDX-License-Identifier: MIT
5164
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5165
- */
5166
5034
 
5035
+ function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
5036
+ for (; startIdx <= endIdx; ++startIdx) {
5037
+ const ch = vnodes[startIdx];
5167
5038
 
5168
- const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
5169
- const SymbolIterator = Symbol.iterator;
5170
- const TextHook = {
5171
- create: vnode => {
5172
- const {
5173
- owner
5174
- } = vnode;
5175
- const elm = createText$1(vnode.text);
5176
- linkNodeToShadow(elm, owner);
5177
- vnode.elm = elm;
5178
- },
5179
- update: updateNodeHook,
5180
- insert: insertNodeHook,
5181
- move: insertNodeHook,
5182
- remove: removeNodeHook,
5183
- hydrate: (vNode, node) => {
5184
- var _a;
5185
-
5186
- if (process.env.NODE_ENV !== 'production') {
5187
- // eslint-disable-next-line lwc-internal/no-global-node
5188
- if (node.nodeType !== Node.TEXT_NODE) {
5189
- logError('Hydration mismatch: incorrect node type received', vNode.owner);
5190
- assert.fail('Hydration mismatch: incorrect node type received.');
5191
- }
5192
-
5193
- if (node.nodeValue !== vNode.text) {
5194
- logWarn('Hydration mismatch: text values do not match, will recover from the difference', vNode.owner);
5195
- }
5196
- } // always set the text value to the one from the vnode.
5039
+ if (isVNode(ch)) {
5040
+ ch.hook.create(ch);
5041
+ ch.hook.insert(ch, parentElm, before);
5042
+ }
5043
+ }
5044
+ }
5197
5045
 
5046
+ function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
5047
+ for (; startIdx <= endIdx; ++startIdx) {
5048
+ const ch = vnodes[startIdx]; // text nodes do not have logic associated to them
5198
5049
 
5199
- node.nodeValue = (_a = vNode.text) !== null && _a !== void 0 ? _a : null;
5200
- vNode.elm = node;
5050
+ if (isVNode(ch)) {
5051
+ ch.hook.remove(ch, parentElm);
5052
+ }
5201
5053
  }
5202
- };
5203
- const CommentHook = {
5204
- create: vnode => {
5205
- const {
5206
- owner,
5207
- text
5208
- } = vnode;
5209
- const elm = createComment$1(text);
5210
- linkNodeToShadow(elm, owner);
5211
- vnode.elm = elm;
5212
- },
5213
- update: updateNodeHook,
5214
- insert: insertNodeHook,
5215
- move: insertNodeHook,
5216
- remove: removeNodeHook,
5217
- hydrate: (vNode, node) => {
5218
- var _a;
5054
+ }
5219
5055
 
5220
- if (process.env.NODE_ENV !== 'production') {
5221
- // eslint-disable-next-line lwc-internal/no-global-node
5222
- if (node.nodeType !== Node.COMMENT_NODE) {
5223
- logError('Hydration mismatch: incorrect node type received', vNode.owner);
5224
- assert.fail('Hydration mismatch: incorrect node type received.');
5225
- }
5056
+ function updateDynamicChildren(parentElm, oldCh, newCh) {
5057
+ let oldStartIdx = 0;
5058
+ let newStartIdx = 0;
5059
+ let oldEndIdx = oldCh.length - 1;
5060
+ let oldStartVnode = oldCh[0];
5061
+ let oldEndVnode = oldCh[oldEndIdx];
5062
+ const newChEnd = newCh.length - 1;
5063
+ let newEndIdx = newChEnd;
5064
+ let newStartVnode = newCh[0];
5065
+ let newEndVnode = newCh[newEndIdx];
5066
+ let oldKeyToIdx;
5067
+ let idxInOld;
5068
+ let elmToMove;
5069
+ let before;
5226
5070
 
5227
- if (node.nodeValue !== vNode.text) {
5228
- logWarn('Hydration mismatch: comment values do not match, will recover from the difference', vNode.owner);
5071
+ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
5072
+ if (!isVNode(oldStartVnode)) {
5073
+ oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left
5074
+ } else if (!isVNode(oldEndVnode)) {
5075
+ oldEndVnode = oldCh[--oldEndIdx];
5076
+ } else if (!isVNode(newStartVnode)) {
5077
+ newStartVnode = newCh[++newStartIdx];
5078
+ } else if (!isVNode(newEndVnode)) {
5079
+ newEndVnode = newCh[--newEndIdx];
5080
+ } else if (isSameVnode(oldStartVnode, newStartVnode)) {
5081
+ patchVnode(oldStartVnode, newStartVnode);
5082
+ oldStartVnode = oldCh[++oldStartIdx];
5083
+ newStartVnode = newCh[++newStartIdx];
5084
+ } else if (isSameVnode(oldEndVnode, newEndVnode)) {
5085
+ patchVnode(oldEndVnode, newEndVnode);
5086
+ oldEndVnode = oldCh[--oldEndIdx];
5087
+ newEndVnode = newCh[--newEndIdx];
5088
+ } else if (isSameVnode(oldStartVnode, newEndVnode)) {
5089
+ // Vnode moved right
5090
+ patchVnode(oldStartVnode, newEndVnode);
5091
+ newEndVnode.hook.move(oldStartVnode, parentElm, nextSibling$1(oldEndVnode.elm));
5092
+ oldStartVnode = oldCh[++oldStartIdx];
5093
+ newEndVnode = newCh[--newEndIdx];
5094
+ } else if (isSameVnode(oldEndVnode, newStartVnode)) {
5095
+ // Vnode moved left
5096
+ patchVnode(oldEndVnode, newStartVnode);
5097
+ newStartVnode.hook.move(oldEndVnode, parentElm, oldStartVnode.elm);
5098
+ oldEndVnode = oldCh[--oldEndIdx];
5099
+ newStartVnode = newCh[++newStartIdx];
5100
+ } else {
5101
+ if (oldKeyToIdx === undefined) {
5102
+ oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
5229
5103
  }
5230
- } // always set the text value to the one from the vnode.
5231
-
5232
5104
 
5233
- node.nodeValue = (_a = vNode.text) !== null && _a !== void 0 ? _a : null;
5234
- vNode.elm = node;
5235
- }
5236
- }; // insert is called after update, which is used somewhere else (via a module)
5237
- // to mark the vm as inserted, that means we cannot use update as the main channel
5238
- // to rehydrate when dirty, because sometimes the element is not inserted just yet,
5239
- // which breaks some invariants. For that reason, we have the following for any
5240
- // Custom Element that is inserted via a template.
5241
-
5242
- const ElementHook = {
5243
- create: vnode => {
5244
- const {
5245
- sel,
5246
- owner,
5247
- data: {
5248
- svg
5249
- }
5250
- } = vnode;
5251
- const namespace = isTrue(svg) ? SVG_NAMESPACE : undefined;
5252
- const elm = createElement$2(sel, namespace);
5253
- linkNodeToShadow(elm, owner);
5254
- fallbackElmHook(elm, vnode);
5255
- vnode.elm = elm;
5256
- patchElementPropsAndAttrs(null, vnode);
5257
- },
5258
- update: (oldVnode, vnode) => {
5259
- patchElementPropsAndAttrs(oldVnode, vnode);
5260
- patchChildren(vnode.elm, oldVnode.children, vnode.children);
5261
- },
5262
- insert: (vnode, parentNode, referenceNode) => {
5263
- insertNodeHook(vnode, parentNode, referenceNode);
5264
- createChildrenHook(vnode);
5265
- },
5266
- move: (vnode, parentNode, referenceNode) => {
5267
- insertNodeHook(vnode, parentNode, referenceNode);
5268
- },
5269
- remove: (vnode, parentNode) => {
5270
- removeNodeHook(vnode, parentNode);
5271
- removeElmHook(vnode);
5272
- },
5273
- hydrate: (vnode, node) => {
5274
- const elm = node;
5275
- vnode.elm = elm;
5276
- const {
5277
- context
5278
- } = vnode.data;
5279
- const isDomManual = Boolean(!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
5280
- /* manual */
5281
- );
5105
+ idxInOld = oldKeyToIdx[newStartVnode.key];
5282
5106
 
5283
- if (isDomManual) {
5284
- // it may be that this element has lwc:inner-html, we need to diff and in case are the same,
5285
- // remove the innerHTML from props so it reuses the existing dom elements.
5286
- const {
5287
- props
5288
- } = vnode.data;
5107
+ if (isUndefined$1(idxInOld)) {
5108
+ // New element
5109
+ newStartVnode.hook.create(newStartVnode);
5110
+ newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm);
5111
+ newStartVnode = newCh[++newStartIdx];
5112
+ } else {
5113
+ elmToMove = oldCh[idxInOld];
5289
5114
 
5290
- if (!isUndefined$1(props) && !isUndefined$1(props.innerHTML)) {
5291
- if (elm.innerHTML === props.innerHTML) {
5292
- delete props.innerHTML;
5293
- } else {
5294
- logWarn(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: innerHTML values do not match for element, will recover from the difference`, vnode.owner);
5115
+ if (isVNode(elmToMove)) {
5116
+ if (elmToMove.sel !== newStartVnode.sel) {
5117
+ // New element
5118
+ newStartVnode.hook.create(newStartVnode);
5119
+ newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm);
5120
+ } else {
5121
+ patchVnode(elmToMove, newStartVnode);
5122
+ oldCh[idxInOld] = undefined;
5123
+ newStartVnode.hook.move(elmToMove, parentElm, oldStartVnode.elm);
5124
+ }
5295
5125
  }
5296
- }
5297
- }
5298
5126
 
5299
- hydrateElmHook(vnode);
5300
-
5301
- if (!isDomManual) {
5302
- hydrateChildrenHook(vnode.elm.childNodes, vnode.children, vnode.owner);
5127
+ newStartVnode = newCh[++newStartIdx];
5128
+ }
5303
5129
  }
5304
5130
  }
5305
- };
5306
- const CustomElementHook = {
5307
- create: vnode => {
5308
- const {
5309
- sel,
5310
- owner
5311
- } = vnode;
5312
- const UpgradableConstructor = getUpgradableConstructor(sel);
5313
- /**
5314
- * Note: if the upgradable constructor does not expect, or throw when we new it
5315
- * with a callback as the first argument, we could implement a more advanced
5316
- * mechanism that only passes that argument if the constructor is known to be
5317
- * an upgradable custom element.
5318
- */
5319
5131
 
5320
- const elm = new UpgradableConstructor(elm => {
5321
- // the custom element from the registry is expecting an upgrade callback
5322
- createViewModelHook(elm, vnode);
5323
- });
5324
- linkNodeToShadow(elm, owner);
5325
- vnode.elm = elm;
5326
- const vm = getAssociatedVMIfPresent(elm);
5327
-
5328
- if (vm) {
5329
- allocateChildrenHook(vnode, vm);
5330
- } else if (vnode.ctor !== UpgradableConstructor) {
5331
- throw new TypeError(`Incorrect Component Constructor`);
5332
- }
5333
-
5334
- patchElementPropsAndAttrs(null, vnode);
5335
- },
5336
- update: (oldVnode, vnode) => {
5337
- patchElementPropsAndAttrs(oldVnode, vnode);
5338
- const vm = getAssociatedVMIfPresent(vnode.elm);
5339
-
5340
- if (vm) {
5341
- // in fallback mode, the allocation will always set children to
5342
- // empty and delegate the real allocation to the slot elements
5343
- allocateChildrenHook(vnode, vm);
5344
- } // in fallback mode, the children will be always empty, so, nothing
5345
- // will happen, but in native, it does allocate the light dom
5346
-
5347
-
5348
- patchChildren(vnode.elm, oldVnode.children, vnode.children);
5349
-
5350
- if (vm) {
5351
- if (process.env.NODE_ENV !== 'production') {
5352
- assert.isTrue(isArray$1(vnode.children), `Invalid vnode for a custom element, it must have children defined.`);
5353
- } // this will probably update the shadowRoot, but only if the vm is in a dirty state
5354
- // this is important to preserve the top to bottom synchronous rendering phase.
5132
+ if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
5133
+ if (oldStartIdx > oldEndIdx) {
5134
+ // There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
5135
+ // already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
5136
+ let i = newEndIdx;
5137
+ let n;
5355
5138
 
5139
+ do {
5140
+ n = newCh[++i];
5141
+ } while (!isVNode(n) && i < newChEnd);
5356
5142
 
5357
- rerenderVM(vm);
5143
+ before = isVNode(n) ? n.elm : null;
5144
+ addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
5145
+ } else {
5146
+ removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
5358
5147
  }
5359
- },
5360
- insert: (vnode, parentNode, referenceNode) => {
5361
- insertNodeHook(vnode, parentNode, referenceNode);
5362
- const vm = getAssociatedVMIfPresent(vnode.elm);
5148
+ }
5149
+ }
5363
5150
 
5364
- if (vm) {
5365
- if (process.env.NODE_ENV !== 'production') {
5366
- assert.isTrue(vm.state === 0
5367
- /* created */
5368
- , `${vm} cannot be recycled.`);
5369
- }
5151
+ function updateStaticChildren(parentElm, oldCh, newCh) {
5152
+ const oldChLength = oldCh.length;
5153
+ const newChLength = newCh.length;
5370
5154
 
5371
- runConnectedCallback(vm);
5372
- }
5155
+ if (oldChLength === 0) {
5156
+ // the old list is empty, we can directly insert anything new
5157
+ addVnodes(parentElm, null, newCh, 0, newChLength);
5158
+ return;
5159
+ }
5373
5160
 
5374
- createChildrenHook(vnode);
5161
+ if (newChLength === 0) {
5162
+ // the old list is nonempty and the new list is empty so we can directly remove all old nodes
5163
+ // this is the case in which the dynamic children of an if-directive should be removed
5164
+ removeVnodes(parentElm, oldCh, 0, oldChLength);
5165
+ return;
5166
+ } // if the old list is not empty, the new list MUST have the same
5167
+ // amount of nodes, that's why we call this static children
5375
5168
 
5376
- if (vm) {
5377
- appendVM(vm);
5378
- }
5379
- },
5380
- move: (vnode, parentNode, referenceNode) => {
5381
- insertNodeHook(vnode, parentNode, referenceNode);
5382
- },
5383
- remove: (vnode, parentNode) => {
5384
- removeNodeHook(vnode, parentNode);
5385
- const vm = getAssociatedVMIfPresent(vnode.elm);
5386
5169
 
5387
- if (vm) {
5388
- // for custom elements we don't have to go recursively because the removeVM routine
5389
- // will take care of disconnecting any child VM attached to its shadow as well.
5390
- removeVM(vm);
5391
- }
5392
- },
5393
- hydrate: (vnode, elm) => {
5394
- // the element is created, but the vm is not
5395
- const {
5396
- sel,
5397
- mode,
5398
- ctor,
5399
- owner
5400
- } = vnode;
5401
- const def = getComponentInternalDef(ctor);
5402
- createVM(elm, def, {
5403
- mode,
5404
- owner,
5405
- tagName: sel
5406
- });
5407
- vnode.elm = elm;
5408
- const vm = getAssociatedVM(elm);
5409
- allocateChildrenHook(vnode, vm);
5410
- hydrateElmHook(vnode); // Insert hook section:
5170
+ let referenceElm = null;
5411
5171
 
5412
- if (process.env.NODE_ENV !== 'production') {
5413
- assert.isTrue(vm.state === 0
5414
- /* created */
5415
- , `${vm} cannot be recycled.`);
5416
- }
5172
+ for (let i = newChLength - 1; i >= 0; i -= 1) {
5173
+ const vnode = newCh[i];
5174
+ const oldVNode = oldCh[i];
5417
5175
 
5418
- runConnectedCallback(vm);
5176
+ if (vnode !== oldVNode) {
5177
+ if (isVNode(oldVNode)) {
5178
+ if (isVNode(vnode)) {
5179
+ // both vnodes must be equivalent, and se just need to patch them
5180
+ patchVnode(oldVNode, vnode);
5181
+ referenceElm = vnode.elm;
5182
+ } else {
5183
+ // removing the old vnode since the new one is null
5184
+ oldVNode.hook.remove(oldVNode, parentElm);
5185
+ }
5186
+ } else if (isVNode(vnode)) {
5187
+ // this condition is unnecessary
5188
+ vnode.hook.create(vnode); // insert the new node one since the old one is null
5419
5189
 
5420
- if (vm.renderMode !== 0
5421
- /* Light */
5422
- ) {
5423
- // VM is not rendering in Light DOM, we can proceed and hydrate the slotted content.
5424
- // Note: for Light DOM, this is handled while hydrating the VM
5425
- hydrateChildrenHook(vnode.elm.childNodes, vnode.children, vm);
5190
+ vnode.hook.insert(vnode, parentElm, referenceElm);
5191
+ referenceElm = vnode.elm;
5192
+ }
5426
5193
  }
5427
-
5428
- hydrateVM(vm);
5429
5194
  }
5430
- };
5431
-
5432
- function linkNodeToShadow(elm, owner) {
5433
- const {
5434
- renderMode,
5435
- shadowMode
5436
- } = owner; // TODO [#1164]: this should eventually be done by the polyfill directly
5195
+ }
5437
5196
 
5438
- if (isSyntheticShadowDefined$1) {
5439
- if (shadowMode === 1
5440
- /* Synthetic */
5441
- || renderMode === 0
5442
- /* Light */
5443
- ) {
5444
- elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
5445
- }
5197
+ function patchVnode(oldVnode, vnode) {
5198
+ if (oldVnode !== vnode) {
5199
+ vnode.elm = oldVnode.elm;
5200
+ vnode.hook.update(oldVnode, vnode);
5446
5201
  }
5447
5202
  }
5203
+ /*
5204
+ * Copyright (c) 2018, salesforce.com, inc.
5205
+ * All rights reserved.
5206
+ * SPDX-License-Identifier: MIT
5207
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5208
+ */
5209
+
5210
+
5211
+ const SymbolIterator = Symbol.iterator;
5448
5212
 
5449
5213
  function addVNodeToChildLWC(vnode) {
5450
5214
  ArrayPush$1.call(getVMBeingRendered().velements, vnode);
@@ -5469,20 +5233,22 @@ var LWC = (function (exports) {
5469
5233
 
5470
5234
  forEach.call(children, childVnode => {
5471
5235
  if (childVnode != null) {
5472
- assert.isTrue(childVnode && 'sel' in childVnode && 'data' in childVnode && 'children' in childVnode && 'text' in childVnode && 'elm' in childVnode && 'key' in childVnode, `${childVnode} is not a vnode.`);
5236
+ assert.isTrue('type' in childVnode && 'sel' in childVnode && 'elm' in childVnode && 'key' in childVnode, `${childVnode} is not a vnode.`);
5473
5237
  }
5474
5238
  });
5475
5239
  }
5476
5240
 
5477
- let text, elm;
5241
+ let elm;
5478
5242
  const {
5479
5243
  key
5480
5244
  } = data;
5481
5245
  return {
5246
+ type: 2
5247
+ /* Element */
5248
+ ,
5482
5249
  sel,
5483
5250
  data,
5484
5251
  children,
5485
- text,
5486
5252
  elm,
5487
5253
  key,
5488
5254
  hook: ElementHook,
@@ -5563,7 +5329,7 @@ var LWC = (function (exports) {
5563
5329
  if (arguments.length === 4) {
5564
5330
  forEach.call(children, childVnode => {
5565
5331
  if (childVnode != null) {
5566
- assert.isTrue(childVnode && 'sel' in childVnode && 'data' in childVnode && 'children' in childVnode && 'text' in childVnode && 'elm' in childVnode && 'key' in childVnode, `${childVnode} is not a vnode.`);
5332
+ assert.isTrue('type' in childVnode && 'sel' in childVnode && 'elm' in childVnode && 'key' in childVnode, `${childVnode} is not a vnode.`);
5567
5333
  }
5568
5334
  });
5569
5335
  }
@@ -5572,12 +5338,14 @@ var LWC = (function (exports) {
5572
5338
  const {
5573
5339
  key
5574
5340
  } = data;
5575
- let text, elm;
5341
+ let elm;
5576
5342
  const vnode = {
5343
+ type: 3
5344
+ /* CustomElement */
5345
+ ,
5577
5346
  sel,
5578
5347
  data,
5579
5348
  children,
5580
- text,
5581
5349
  elm,
5582
5350
  key,
5583
5351
  hook: CustomElementHook,
@@ -5705,12 +5473,12 @@ var LWC = (function (exports) {
5705
5473
 
5706
5474
 
5707
5475
  function t(text) {
5708
- const data = EmptyObject;
5709
- let sel, children, key, elm;
5476
+ let sel, key, elm;
5710
5477
  return {
5478
+ type: 0
5479
+ /* Text */
5480
+ ,
5711
5481
  sel,
5712
- data,
5713
- children,
5714
5482
  text,
5715
5483
  elm,
5716
5484
  key,
@@ -5721,12 +5489,12 @@ var LWC = (function (exports) {
5721
5489
 
5722
5490
 
5723
5491
  function co(text) {
5724
- const data = EmptyObject;
5725
- let sel, children, key, elm;
5492
+ let sel, key, elm;
5726
5493
  return {
5494
+ type: 1
5495
+ /* Comment */
5496
+ ,
5727
5497
  sel,
5728
- data,
5729
- children,
5730
5498
  text,
5731
5499
  elm,
5732
5500
  key,
@@ -6164,7 +5932,7 @@ var LWC = (function (exports) {
6164
5932
  insertGlobalStylesheet$1(stylesheets[i]);
6165
5933
  } else {
6166
5934
  // local level
6167
- insertStylesheet$1(stylesheets[i], root.cmpRoot);
5935
+ insertStylesheet$1(stylesheets[i], root.shadowRoot);
6168
5936
  }
6169
5937
  }
6170
5938
  }
@@ -6471,25 +6239,6 @@ var LWC = (function (exports) {
6471
6239
  */
6472
6240
 
6473
6241
 
6474
- function addErrorComponentStack(vm, error) {
6475
- if (!isFrozen(error) && isUndefined$1(error.wcStack)) {
6476
- const wcStack = getErrorComponentStack(vm);
6477
- defineProperty(error, 'wcStack', {
6478
- get() {
6479
- return wcStack;
6480
- }
6481
-
6482
- });
6483
- }
6484
- }
6485
- /*
6486
- * Copyright (c) 2018, salesforce.com, inc.
6487
- * All rights reserved.
6488
- * SPDX-License-Identifier: MIT
6489
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6490
- */
6491
-
6492
-
6493
6242
  let isInvokingRender = false;
6494
6243
  let vmBeingConstructed = null;
6495
6244
 
@@ -6726,6 +6475,320 @@ var LWC = (function (exports) {
6726
6475
  cbs[i].call(undefined, component, {}, def, context);
6727
6476
  }
6728
6477
  }
6478
+ /*
6479
+ * Copyright (c) 2022, salesforce.com, inc.
6480
+ * All rights reserved.
6481
+ * SPDX-License-Identifier: MIT
6482
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6483
+ */
6484
+
6485
+
6486
+ function hydrate$1(vnode, node) {
6487
+ switch (vnode.type) {
6488
+ case 0
6489
+ /* Text */
6490
+ :
6491
+ hydrateText(vnode, node);
6492
+ break;
6493
+
6494
+ case 1
6495
+ /* Comment */
6496
+ :
6497
+ hydrateComment(vnode, node);
6498
+ break;
6499
+
6500
+ case 2
6501
+ /* Element */
6502
+ :
6503
+ hydrateElement(vnode, node);
6504
+ break;
6505
+
6506
+ case 3
6507
+ /* CustomElement */
6508
+ :
6509
+ hydrateCustomElement(vnode, node);
6510
+ break;
6511
+ }
6512
+ }
6513
+
6514
+ function hydrateText(vnode, node) {
6515
+ var _a;
6516
+
6517
+ if (process.env.NODE_ENV !== 'production') {
6518
+ // eslint-disable-next-line lwc-internal/no-global-node
6519
+ validateNodeType(vnode, node, Node.TEXT_NODE);
6520
+
6521
+ if (node.nodeValue !== vnode.text && !(node.nodeValue === '\u200D' && vnode.text === '')) {
6522
+ logWarn('Hydration mismatch: text values do not match, will recover from the difference', vnode.owner);
6523
+ }
6524
+ } // always set the text value to the one from the vnode.
6525
+
6526
+
6527
+ node.nodeValue = (_a = vnode.text) !== null && _a !== void 0 ? _a : null;
6528
+ vnode.elm = node;
6529
+ }
6530
+
6531
+ function hydrateComment(vnode, node) {
6532
+ var _a;
6533
+
6534
+ if (process.env.NODE_ENV !== 'production') {
6535
+ // eslint-disable-next-line lwc-internal/no-global-node
6536
+ validateNodeType(vnode, node, Node.COMMENT_NODE);
6537
+
6538
+ if (node.nodeValue !== vnode.text) {
6539
+ logWarn('Hydration mismatch: comment values do not match, will recover from the difference', vnode.owner);
6540
+ }
6541
+ } // always set the text value to the one from the vnode.
6542
+
6543
+
6544
+ node.nodeValue = (_a = vnode.text) !== null && _a !== void 0 ? _a : null;
6545
+ vnode.elm = node;
6546
+ }
6547
+
6548
+ function hydrateElement(vnode, node) {
6549
+ if (process.env.NODE_ENV !== 'production') {
6550
+ // eslint-disable-next-line lwc-internal/no-global-node
6551
+ validateNodeType(vnode, node, Node.ELEMENT_NODE);
6552
+ validateElement(vnode, node);
6553
+ }
6554
+
6555
+ const elm = node;
6556
+ vnode.elm = elm;
6557
+ const {
6558
+ context
6559
+ } = vnode.data;
6560
+ const isDomManual = Boolean(!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
6561
+ /* Manual */
6562
+ );
6563
+
6564
+ if (isDomManual) {
6565
+ // it may be that this element has lwc:inner-html, we need to diff and in case are the same,
6566
+ // remove the innerHTML from props so it reuses the existing dom elements.
6567
+ const {
6568
+ props
6569
+ } = vnode.data;
6570
+
6571
+ if (!isUndefined$1(props) && !isUndefined$1(props.innerHTML)) {
6572
+ if (elm.innerHTML === props.innerHTML) {
6573
+ delete props.innerHTML;
6574
+ } else {
6575
+ logWarn(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: innerHTML values do not match for element, will recover from the difference`, vnode.owner);
6576
+ }
6577
+ }
6578
+ }
6579
+
6580
+ patchElementPropsAndAttrs(vnode);
6581
+
6582
+ if (!isDomManual) {
6583
+ hydrateChildren(vnode.elm.childNodes, vnode.children, vnode.owner);
6584
+ }
6585
+ }
6586
+
6587
+ function hydrateCustomElement(vnode, node) {
6588
+ if (process.env.NODE_ENV !== 'production') {
6589
+ // eslint-disable-next-line lwc-internal/no-global-node
6590
+ validateNodeType(vnode, node, Node.ELEMENT_NODE);
6591
+ validateElement(vnode, node);
6592
+ }
6593
+
6594
+ const elm = node;
6595
+ vnode.elm = elm;
6596
+ const {
6597
+ sel,
6598
+ mode,
6599
+ ctor,
6600
+ owner
6601
+ } = vnode;
6602
+ const vm = createVM(elm, ctor, {
6603
+ mode,
6604
+ owner,
6605
+ tagName: sel
6606
+ });
6607
+ allocateChildren(vnode, vm);
6608
+ patchElementPropsAndAttrs(vnode); // Insert hook section:
6609
+
6610
+ if (process.env.NODE_ENV !== 'production') {
6611
+ assert.isTrue(vm.state === 0
6612
+ /* created */
6613
+ , `${vm} cannot be recycled.`);
6614
+ }
6615
+
6616
+ runConnectedCallback(vm);
6617
+
6618
+ if (vm.renderMode !== 0
6619
+ /* Light */
6620
+ ) {
6621
+ // VM is not rendering in Light DOM, we can proceed and hydrate the slotted content.
6622
+ // Note: for Light DOM, this is handled while hydrating the VM
6623
+ hydrateChildren(vnode.elm.childNodes, vnode.children, vm);
6624
+ }
6625
+
6626
+ hydrateVM(vm);
6627
+ }
6628
+
6629
+ function hydrateChildren(elmChildren, children, vm) {
6630
+ if (process.env.NODE_ENV !== 'production') {
6631
+ const filteredVNodes = ArrayFilter.call(children, vnode => !!vnode);
6632
+
6633
+ if (elmChildren.length !== filteredVNodes.length) {
6634
+ logError(`Hydration mismatch: incorrect number of rendered nodes, expected ${filteredVNodes.length} but found ${elmChildren.length}.`, vm);
6635
+ throwHydrationError();
6636
+ }
6637
+ }
6638
+
6639
+ let childNodeIndex = 0;
6640
+
6641
+ for (let i = 0; i < children.length; i++) {
6642
+ const childVnode = children[i];
6643
+
6644
+ if (!isNull(childVnode)) {
6645
+ const childNode = elmChildren[childNodeIndex];
6646
+ hydrate$1(childVnode, childNode);
6647
+ childNodeIndex++;
6648
+ }
6649
+ }
6650
+ }
6651
+
6652
+ function patchElementPropsAndAttrs(vnode) {
6653
+ applyEventListeners(vnode);
6654
+ patchProps(null, vnode);
6655
+ }
6656
+
6657
+ function throwHydrationError() {
6658
+ assert.fail('Server rendered elements do not match client side generated elements');
6659
+ }
6660
+
6661
+ function validateNodeType(vnode, node, nodeType) {
6662
+ if (node.nodeType !== nodeType) {
6663
+ logError('Hydration mismatch: incorrect node type received', vnode.owner);
6664
+ assert.fail('Hydration mismatch: incorrect node type received.');
6665
+ }
6666
+ }
6667
+
6668
+ function validateElement(vnode, elm) {
6669
+ if (vnode.sel.toLowerCase() !== elm.tagName.toLowerCase()) {
6670
+ logError(`Hydration mismatch: expecting element with tag "${vnode.sel.toLowerCase()}" but found "${elm.tagName.toLowerCase()}".`, vnode.owner);
6671
+ throwHydrationError();
6672
+ }
6673
+
6674
+ const hasIncompatibleAttrs = validateAttrs(vnode, elm);
6675
+ const hasIncompatibleClass = validateClassAttr(vnode, elm);
6676
+ const hasIncompatibleStyle = validateStyleAttr(vnode, elm);
6677
+ const isVNodeAndElementCompatible = hasIncompatibleAttrs && hasIncompatibleClass && hasIncompatibleStyle;
6678
+
6679
+ if (!isVNodeAndElementCompatible) {
6680
+ throwHydrationError();
6681
+ }
6682
+ }
6683
+
6684
+ function validateAttrs(vnode, elm) {
6685
+ const {
6686
+ data: {
6687
+ attrs = {}
6688
+ }
6689
+ } = vnode;
6690
+ let nodesAreCompatible = true; // Validate attributes, though we could always recovery from those by running the update mods.
6691
+ // Note: intentionally ONLY matching vnodes.attrs to elm.attrs, in case SSR is adding extra attributes.
6692
+
6693
+ for (const [attrName, attrValue] of Object.entries(attrs)) {
6694
+ const elmAttrValue = getAttribute$1(elm, attrName);
6695
+
6696
+ if (String(attrValue) !== elmAttrValue) {
6697
+ logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "${attrName}" has different values, expected "${attrValue}" but found "${elmAttrValue}"`, vnode.owner);
6698
+ nodesAreCompatible = false;
6699
+ }
6700
+ }
6701
+
6702
+ return nodesAreCompatible;
6703
+ }
6704
+
6705
+ function validateClassAttr(vnode, elm) {
6706
+ const {
6707
+ data: {
6708
+ className,
6709
+ classMap
6710
+ }
6711
+ } = vnode;
6712
+ let nodesAreCompatible = true;
6713
+ let vnodeClassName;
6714
+
6715
+ if (!isUndefined$1(className) && String(className) !== elm.className) {
6716
+ // className is used when class is bound to an expr.
6717
+ nodesAreCompatible = false;
6718
+ vnodeClassName = className;
6719
+ } else if (!isUndefined$1(classMap)) {
6720
+ // classMap is used when class is set to static value.
6721
+ const classList = getClassList$1(elm);
6722
+ let computedClassName = ''; // all classes from the vnode should be in the element.classList
6723
+
6724
+ for (const name in classMap) {
6725
+ computedClassName += ' ' + name;
6726
+
6727
+ if (!classList.contains(name)) {
6728
+ nodesAreCompatible = false;
6729
+ }
6730
+ }
6731
+
6732
+ vnodeClassName = computedClassName.trim();
6733
+
6734
+ if (classList.length > keys(classMap).length) {
6735
+ nodesAreCompatible = false;
6736
+ }
6737
+ }
6738
+
6739
+ if (!nodesAreCompatible) {
6740
+ logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "class" has different values, expected "${vnodeClassName}" but found "${elm.className}"`, vnode.owner);
6741
+ }
6742
+
6743
+ return nodesAreCompatible;
6744
+ }
6745
+
6746
+ function validateStyleAttr(vnode, elm) {
6747
+ const {
6748
+ data: {
6749
+ style,
6750
+ styleDecls
6751
+ }
6752
+ } = vnode;
6753
+ const elmStyle = getAttribute$1(elm, 'style') || '';
6754
+ let vnodeStyle;
6755
+ let nodesAreCompatible = true;
6756
+
6757
+ if (!isUndefined$1(style) && style !== elmStyle) {
6758
+ nodesAreCompatible = false;
6759
+ vnodeStyle = style;
6760
+ } else if (!isUndefined$1(styleDecls)) {
6761
+ const parsedVnodeStyle = parseStyleText(elmStyle);
6762
+ const expectedStyle = []; // styleMap is used when style is set to static value.
6763
+
6764
+ for (let i = 0, n = styleDecls.length; i < n; i++) {
6765
+ const [prop, value, important] = styleDecls[i];
6766
+ expectedStyle.push(`${prop}: ${value + (important ? ' important!' : '')}`);
6767
+ const parsedPropValue = parsedVnodeStyle[prop];
6768
+
6769
+ if (isUndefined$1(parsedPropValue)) {
6770
+ nodesAreCompatible = false;
6771
+ } else if (!parsedPropValue.startsWith(value)) {
6772
+ nodesAreCompatible = false;
6773
+ } else if (important && !parsedPropValue.endsWith('!important')) {
6774
+ nodesAreCompatible = false;
6775
+ }
6776
+ }
6777
+
6778
+ if (keys(parsedVnodeStyle).length > styleDecls.length) {
6779
+ nodesAreCompatible = false;
6780
+ }
6781
+
6782
+ vnodeStyle = ArrayJoin.call(expectedStyle, ';');
6783
+ }
6784
+
6785
+ if (!nodesAreCompatible) {
6786
+ // style is used when class is bound to an expr.
6787
+ logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "style" has different values, expected "${vnodeStyle}" but found "${elmStyle}".`, vnode.owner);
6788
+ }
6789
+
6790
+ return nodesAreCompatible;
6791
+ }
6729
6792
  /*
6730
6793
  * Copyright (c) 2018, salesforce.com, inc.
6731
6794
  * All rights reserved.
@@ -6852,12 +6915,13 @@ var LWC = (function (exports) {
6852
6915
  return ancestor;
6853
6916
  }
6854
6917
 
6855
- function createVM(elm, def, options) {
6918
+ function createVM(elm, ctor, options) {
6856
6919
  const {
6857
6920
  mode,
6858
6921
  owner,
6859
6922
  tagName
6860
6923
  } = options;
6924
+ const def = getComponentInternalDef(ctor);
6861
6925
  const vm = {
6862
6926
  elm,
6863
6927
  def,
@@ -6879,7 +6943,6 @@ var LWC = (function (exports) {
6879
6943
  oar: create(null),
6880
6944
  cmpTemplate: null,
6881
6945
  renderMode: def.renderMode,
6882
- shadowMode: null,
6883
6946
  context: {
6884
6947
  stylesheetToken: undefined,
6885
6948
  hasTokenInClass: undefined,
@@ -6890,9 +6953,13 @@ var LWC = (function (exports) {
6890
6953
  wiredConnecting: EmptyArray,
6891
6954
  wiredDisconnecting: EmptyArray
6892
6955
  },
6956
+ // Properties set right after VM creation.
6893
6957
  tro: null,
6958
+ shadowMode: null,
6959
+ // Properties set by the LightningElement constructor.
6894
6960
  component: null,
6895
- cmpRoot: null,
6961
+ shadowRoot: null,
6962
+ renderRoot: null,
6896
6963
  callHook,
6897
6964
  setHook,
6898
6965
  getHook
@@ -6980,7 +7047,7 @@ var LWC = (function (exports) {
6980
7047
  }
6981
7048
 
6982
7049
  function assertIsVM(obj) {
6983
- if (isNull(obj) || !isObject(obj) || !('cmpRoot' in obj)) {
7050
+ if (isNull(obj) || !isObject(obj) || !('renderRoot' in obj)) {
6984
7051
  throw new TypeError(`${obj} is not a VM.`);
6985
7052
  }
6986
7053
  }
@@ -7029,13 +7096,14 @@ var LWC = (function (exports) {
7029
7096
  const vmChildren = vm.renderMode === 0
7030
7097
  /* Light */
7031
7098
  ? vm.elm.childNodes : vm.elm.shadowRoot.childNodes;
7032
- hydrateChildrenHook(vmChildren, children, vm);
7099
+ hydrateChildren(vmChildren, children, vm);
7033
7100
  runRenderedCallback(vm);
7034
7101
  }
7035
7102
  }
7036
7103
 
7037
7104
  function patchShadowRoot(vm, newCh) {
7038
7105
  const {
7106
+ renderRoot,
7039
7107
  children: oldCh
7040
7108
  } = vm; // caching the new children collection
7041
7109
 
@@ -7052,7 +7120,6 @@ var LWC = (function (exports) {
7052
7120
  , vm);
7053
7121
  }, () => {
7054
7122
  // job
7055
- const renderRoot = getRenderRoot(vm);
7056
7123
  patchChildren(renderRoot, oldCh, newCh);
7057
7124
  }, () => {
7058
7125
  // post
@@ -7288,14 +7355,22 @@ var LWC = (function (exports) {
7288
7355
  for (let i = 0, len = vnodes.length; i < len; i += 1) {
7289
7356
  const vnode = vnodes[i];
7290
7357
 
7291
- if (!isNull(vnode) && isArray$1(vnode.children) && !isUndefined$1(vnode.elm)) {
7292
- // vnode is a VElement with children
7293
- if (isUndefined$1(vnode.ctor)) {
7294
- // it is a VElement, just keep looking (recursively)
7295
- recursivelyDisconnectChildren(vnode.children);
7296
- } else {
7297
- // it is a VCustomElement, disconnect it and ignore its children
7298
- resetComponentStateWhenRemoved(getAssociatedVM(vnode.elm));
7358
+ if (!isNull(vnode) && !isUndefined$1(vnode.elm)) {
7359
+ switch (vnode.type) {
7360
+ case 2
7361
+ /* Element */
7362
+ :
7363
+ recursivelyDisconnectChildren(vnode.children);
7364
+ break;
7365
+
7366
+ case 3
7367
+ /* CustomElement */
7368
+ :
7369
+ {
7370
+ const vm = getAssociatedVM(vnode.elm);
7371
+ resetComponentStateWhenRemoved(vm);
7372
+ break;
7373
+ }
7299
7374
  }
7300
7375
  }
7301
7376
  }
@@ -7307,15 +7382,15 @@ var LWC = (function (exports) {
7307
7382
 
7308
7383
  function resetComponentRoot(vm) {
7309
7384
  const {
7310
- children
7385
+ children,
7386
+ renderRoot
7311
7387
  } = vm;
7312
- const rootNode = getRenderRoot(vm);
7313
7388
 
7314
7389
  for (let i = 0, len = children.length; i < len; i++) {
7315
7390
  const child = children[i];
7316
7391
 
7317
7392
  if (!isNull(child) && !isUndefined$1(child.elm)) {
7318
- remove$1(child.elm, rootNode);
7393
+ remove$1(child.elm, renderRoot);
7319
7394
  }
7320
7395
  }
7321
7396
 
@@ -7401,12 +7476,6 @@ var LWC = (function (exports) {
7401
7476
  scheduleRehydration(vm);
7402
7477
  }
7403
7478
  }
7404
-
7405
- function getRenderRoot(vm) {
7406
- return vm.renderMode === 1
7407
- /* Shadow */
7408
- ? vm.cmpRoot : vm.elm;
7409
- }
7410
7479
  /*
7411
7480
  * Copyright (c) 2018, salesforce.com, inc.
7412
7481
  * All rights reserved.
@@ -7798,7 +7867,7 @@ var LWC = (function (exports) {
7798
7867
  hooksAreSet = true;
7799
7868
  setSanitizeHtmlContentHook(hooks.sanitizeHtmlContent);
7800
7869
  }
7801
- /* version: 2.7.3 */
7870
+ /* version: 2.7.4 */
7802
7871
 
7803
7872
  /*
7804
7873
  * Copyright (c) 2018, salesforce.com, inc.
@@ -8262,8 +8331,7 @@ var LWC = (function (exports) {
8262
8331
  */
8263
8332
 
8264
8333
  const element = new UpgradableConstructor(elm => {
8265
- const def = getComponentInternalDef(Ctor);
8266
- createVM(elm, def, {
8334
+ createVM(elm, Ctor, {
8267
8335
  tagName: sel,
8268
8336
  mode: options.mode !== 'closed' ? 'open' : 'closed',
8269
8337
  owner: null
@@ -8301,13 +8369,11 @@ var LWC = (function (exports) {
8301
8369
  throw new TypeError(`"hydrateComponent" expects an object as the third parameter but instead received ${props}.`);
8302
8370
  }
8303
8371
 
8304
- const def = getComponentInternalDef(Ctor);
8305
-
8306
8372
  try {
8307
8373
  // Let the renderer know we are hydrating, so it does not replace the existing shadowRoot
8308
8374
  // and uses the same algo to create the stylesheets as in SSR.
8309
8375
  setIsHydrating(true);
8310
- createVM(element, def, {
8376
+ createVM(element, Ctor, {
8311
8377
  mode: 'open',
8312
8378
  owner: null,
8313
8379
  tagName: element.tagName.toLowerCase()
@@ -8373,11 +8439,11 @@ var LWC = (function (exports) {
8373
8439
  }
8374
8440
 
8375
8441
  function buildCustomElementConstructor(Ctor) {
8376
- const def = getComponentInternalDef(Ctor);
8377
- return class extends def.bridge {
8442
+ const HtmlPrototype = getComponentHtmlPrototype(Ctor);
8443
+ return class extends HtmlPrototype {
8378
8444
  constructor() {
8379
8445
  super();
8380
- createVM(this, def, {
8446
+ createVM(this, Ctor, {
8381
8447
  mode: 'open',
8382
8448
  owner: null,
8383
8449
  tagName: this.tagName
@@ -8500,7 +8566,7 @@ var LWC = (function (exports) {
8500
8566
  });
8501
8567
  freeze(LightningElement);
8502
8568
  seal(LightningElement.prototype);
8503
- /* version: 2.7.3 */
8569
+ /* version: 2.7.4 */
8504
8570
 
8505
8571
  exports.LightningElement = LightningElement;
8506
8572
  exports.__unstable__ProfilerControl = profilerControl;