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
@@ -301,7 +301,11 @@
301
301
  CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
302
302
  return attributeName;
303
303
  }
304
- /** version: 2.7.3 */
304
+
305
+ const XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
306
+ const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
307
+ const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
308
+ /** version: 2.7.4 */
305
309
 
306
310
  /*
307
311
  * Copyright (c) 2018, salesforce.com, inc.
@@ -310,7 +314,6 @@
310
314
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
311
315
  */
312
316
 
313
-
314
317
  function detect(propName) {
315
318
  return Object.getOwnPropertyDescriptor(Element.prototype, propName) === undefined;
316
319
  }
@@ -471,7 +474,7 @@
471
474
 
472
475
  function setFeatureFlagForTest(name, value) {
473
476
  }
474
- /** version: 2.7.3 */
477
+ /** version: 2.7.4 */
475
478
 
476
479
  /* proxy-compat-disable */
477
480
 
@@ -931,6 +934,25 @@
931
934
  */
932
935
 
933
936
 
937
+ function addErrorComponentStack(vm, error) {
938
+ if (!isFrozen(error) && isUndefined$1(error.wcStack)) {
939
+ const wcStack = getErrorComponentStack(vm);
940
+ defineProperty(error, 'wcStack', {
941
+ get() {
942
+ return wcStack;
943
+ }
944
+
945
+ });
946
+ }
947
+ }
948
+ /*
949
+ * Copyright (c) 2018, salesforce.com, inc.
950
+ * All rights reserved.
951
+ * SPDX-License-Identifier: MIT
952
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
953
+ */
954
+
955
+
934
956
  function log(method, message, vm) {
935
957
  let msg = `[LWC ${method}]: ${message}`;
936
958
 
@@ -955,207 +977,12 @@
955
977
  * SPDX-License-Identifier: MIT
956
978
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
957
979
  */
980
+ // This is a temporary workaround to get the @lwc/engine-server to evaluate in node without having
981
+ // to inject at runtime.
958
982
 
959
983
 
960
- function isUndef(s) {
961
- return s === undefined;
962
- }
963
-
964
- function sameVnode(vnode1, vnode2) {
965
- return vnode1.key === vnode2.key && vnode1.sel === vnode2.sel;
966
- }
967
-
968
- function isVNode(vnode) {
969
- return vnode != null;
970
- }
971
-
972
- function createKeyToOldIdx(children, beginIdx, endIdx) {
973
- const map = {};
974
- let j, key, ch; // TODO [#1637]: simplify this by assuming that all vnodes has keys
975
-
976
- for (j = beginIdx; j <= endIdx; ++j) {
977
- ch = children[j];
978
-
979
- if (isVNode(ch)) {
980
- key = ch.key;
981
-
982
- if (key !== undefined) {
983
- map[key] = j;
984
- }
985
- }
986
- }
987
-
988
- return map;
989
- }
990
-
991
- function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
992
- for (; startIdx <= endIdx; ++startIdx) {
993
- const ch = vnodes[startIdx];
994
-
995
- if (isVNode(ch)) {
996
- ch.hook.create(ch);
997
- ch.hook.insert(ch, parentElm, before);
998
- }
999
- }
1000
- }
1001
-
1002
- function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
1003
- for (; startIdx <= endIdx; ++startIdx) {
1004
- const ch = vnodes[startIdx]; // text nodes do not have logic associated to them
1005
-
1006
- if (isVNode(ch)) {
1007
- ch.hook.remove(ch, parentElm);
1008
- }
1009
- }
1010
- }
1011
-
1012
- function updateDynamicChildren(parentElm, oldCh, newCh) {
1013
- let oldStartIdx = 0;
1014
- let newStartIdx = 0;
1015
- let oldEndIdx = oldCh.length - 1;
1016
- let oldStartVnode = oldCh[0];
1017
- let oldEndVnode = oldCh[oldEndIdx];
1018
- const newChEnd = newCh.length - 1;
1019
- let newEndIdx = newChEnd;
1020
- let newStartVnode = newCh[0];
1021
- let newEndVnode = newCh[newEndIdx];
1022
- let oldKeyToIdx;
1023
- let idxInOld;
1024
- let elmToMove;
1025
- let before;
1026
-
1027
- while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
1028
- if (!isVNode(oldStartVnode)) {
1029
- oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left
1030
- } else if (!isVNode(oldEndVnode)) {
1031
- oldEndVnode = oldCh[--oldEndIdx];
1032
- } else if (!isVNode(newStartVnode)) {
1033
- newStartVnode = newCh[++newStartIdx];
1034
- } else if (!isVNode(newEndVnode)) {
1035
- newEndVnode = newCh[--newEndIdx];
1036
- } else if (sameVnode(oldStartVnode, newStartVnode)) {
1037
- patchVnode(oldStartVnode, newStartVnode);
1038
- oldStartVnode = oldCh[++oldStartIdx];
1039
- newStartVnode = newCh[++newStartIdx];
1040
- } else if (sameVnode(oldEndVnode, newEndVnode)) {
1041
- patchVnode(oldEndVnode, newEndVnode);
1042
- oldEndVnode = oldCh[--oldEndIdx];
1043
- newEndVnode = newCh[--newEndIdx];
1044
- } else if (sameVnode(oldStartVnode, newEndVnode)) {
1045
- // Vnode moved right
1046
- patchVnode(oldStartVnode, newEndVnode);
1047
- newEndVnode.hook.move(oldStartVnode, parentElm, nextSibling$1(oldEndVnode.elm));
1048
- oldStartVnode = oldCh[++oldStartIdx];
1049
- newEndVnode = newCh[--newEndIdx];
1050
- } else if (sameVnode(oldEndVnode, newStartVnode)) {
1051
- // Vnode moved left
1052
- patchVnode(oldEndVnode, newStartVnode);
1053
- newStartVnode.hook.move(oldEndVnode, parentElm, oldStartVnode.elm);
1054
- oldEndVnode = oldCh[--oldEndIdx];
1055
- newStartVnode = newCh[++newStartIdx];
1056
- } else {
1057
- if (oldKeyToIdx === undefined) {
1058
- oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
1059
- }
1060
-
1061
- idxInOld = oldKeyToIdx[newStartVnode.key];
1062
-
1063
- if (isUndef(idxInOld)) {
1064
- // New element
1065
- newStartVnode.hook.create(newStartVnode);
1066
- newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm);
1067
- newStartVnode = newCh[++newStartIdx];
1068
- } else {
1069
- elmToMove = oldCh[idxInOld];
1070
-
1071
- if (isVNode(elmToMove)) {
1072
- if (elmToMove.sel !== newStartVnode.sel) {
1073
- // New element
1074
- newStartVnode.hook.create(newStartVnode);
1075
- newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm);
1076
- } else {
1077
- patchVnode(elmToMove, newStartVnode);
1078
- oldCh[idxInOld] = undefined;
1079
- newStartVnode.hook.move(elmToMove, parentElm, oldStartVnode.elm);
1080
- }
1081
- }
1082
-
1083
- newStartVnode = newCh[++newStartIdx];
1084
- }
1085
- }
1086
- }
1087
-
1088
- if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
1089
- if (oldStartIdx > oldEndIdx) {
1090
- // There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
1091
- // already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
1092
- let i = newEndIdx;
1093
- let n;
1094
-
1095
- do {
1096
- n = newCh[++i];
1097
- } while (!isVNode(n) && i < newChEnd);
1098
-
1099
- before = isVNode(n) ? n.elm : null;
1100
- addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
1101
- } else {
1102
- removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
1103
- }
1104
- }
1105
- }
1106
-
1107
- function updateStaticChildren(parentElm, oldCh, newCh) {
1108
- const oldChLength = oldCh.length;
1109
- const newChLength = newCh.length;
1110
-
1111
- if (oldChLength === 0) {
1112
- // the old list is empty, we can directly insert anything new
1113
- addVnodes(parentElm, null, newCh, 0, newChLength);
1114
- return;
1115
- }
1116
-
1117
- if (newChLength === 0) {
1118
- // the old list is nonempty and the new list is empty so we can directly remove all old nodes
1119
- // this is the case in which the dynamic children of an if-directive should be removed
1120
- removeVnodes(parentElm, oldCh, 0, oldChLength);
1121
- return;
1122
- } // if the old list is not empty, the new list MUST have the same
1123
- // amount of nodes, that's why we call this static children
1124
-
1125
-
1126
- let referenceElm = null;
1127
-
1128
- for (let i = newChLength - 1; i >= 0; i -= 1) {
1129
- const vnode = newCh[i];
1130
- const oldVNode = oldCh[i];
1131
-
1132
- if (vnode !== oldVNode) {
1133
- if (isVNode(oldVNode)) {
1134
- if (isVNode(vnode)) {
1135
- // both vnodes must be equivalent, and se just need to patch them
1136
- patchVnode(oldVNode, vnode);
1137
- referenceElm = vnode.elm;
1138
- } else {
1139
- // removing the old vnode since the new one is null
1140
- oldVNode.hook.remove(oldVNode, parentElm);
1141
- }
1142
- } else if (isVNode(vnode)) {
1143
- // this condition is unnecessary
1144
- vnode.hook.create(vnode); // insert the new node one since the old one is null
1145
-
1146
- vnode.hook.insert(vnode, parentElm, referenceElm);
1147
- referenceElm = vnode.elm;
1148
- }
1149
- }
1150
- }
1151
- }
1152
-
1153
- function patchVnode(oldVnode, vnode) {
1154
- if (oldVnode !== vnode) {
1155
- vnode.elm = oldVnode.elm;
1156
- vnode.hook.update(oldVnode, vnode);
1157
- }
1158
- }
984
+ const HTMLElementConstructor$1 = typeof HTMLElement !== 'undefined' ? HTMLElement : function () {};
985
+ const HTMLElementPrototype = HTMLElementConstructor$1.prototype;
1159
986
  /*
1160
987
  * Copyright (c) 2018, salesforce.com, inc.
1161
988
  * All rights reserved.
@@ -1163,7 +990,6 @@
1163
990
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1164
991
  */
1165
992
 
1166
-
1167
993
  const defaultDefHTMLPropertyNames = ['accessKey', 'dir', 'draggable', 'hidden', 'id', 'lang', 'spellcheck', 'tabIndex', 'title'];
1168
994
 
1169
995
  function offsetPropertyErrorMessage(name) {
@@ -1275,18 +1101,6 @@
1275
1101
  controlledElement = elm;
1276
1102
  controlledAttributeName = key;
1277
1103
  }
1278
- /*
1279
- * Copyright (c) 2018, salesforce.com, inc.
1280
- * All rights reserved.
1281
- * SPDX-License-Identifier: MIT
1282
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1283
- */
1284
- // This is a temporary workaround to get the @lwc/engine-server to evaluate in node without having
1285
- // to inject at runtime.
1286
-
1287
-
1288
- const HTMLElementConstructor$1 = typeof HTMLElement !== 'undefined' ? HTMLElement : function () {};
1289
- const HTMLElementPrototype = HTMLElementConstructor$1.prototype;
1290
1104
  /*
1291
1105
  * Copyright (c) 2018, salesforce.com, inc.
1292
1106
  * All rights reserved.
@@ -1301,6 +1115,7 @@
1301
1115
  * Base Lightning Element should support.
1302
1116
  */
1303
1117
 
1118
+
1304
1119
  const HTMLElementOriginalDescriptors = create(null);
1305
1120
  forEach.call(keys(AriaPropNameToAttrNameMap), propName => {
1306
1121
  // Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because
@@ -1325,6 +1140,7 @@
1325
1140
  * Copyright (C) 2017 salesforce.com, inc.
1326
1141
  */
1327
1142
 
1143
+
1328
1144
  const {
1329
1145
  isArray
1330
1146
  } = Array;
@@ -2061,7 +1877,9 @@
2061
1877
  if (vm.renderMode === 1
2062
1878
  /* Shadow */
2063
1879
  ) {
2064
- doAttachShadow(vm);
1880
+ vm.renderRoot = doAttachShadow(vm);
1881
+ } else {
1882
+ vm.renderRoot = elm;
2065
1883
  } // Adding extra guard rails in DEV mode.
2066
1884
 
2067
1885
  return this;
@@ -2076,15 +1894,17 @@
2076
1894
  ctor
2077
1895
  }
2078
1896
  } = vm;
2079
- const cmpRoot = attachShadow$1(elm, {
1897
+ const shadowRoot = attachShadow$1(elm, {
2080
1898
  [KEY__SYNTHETIC_MODE]: shadowMode === 1
2081
1899
  /* Synthetic */
2082
1900
  ,
2083
1901
  delegatesFocus: Boolean(ctor.delegatesFocus),
2084
1902
  mode
2085
1903
  });
2086
- vm.cmpRoot = cmpRoot;
2087
- associateVM(cmpRoot, vm);
1904
+ vm.shadowRoot = shadowRoot;
1905
+ associateVM(shadowRoot, vm);
1906
+
1907
+ return shadowRoot;
2088
1908
  }
2089
1909
 
2090
1910
 
@@ -2213,7 +2033,7 @@
2213
2033
  get template() {
2214
2034
  const vm = getAssociatedVM(this);
2215
2035
 
2216
- return vm.cmpRoot;
2036
+ return vm.shadowRoot;
2217
2037
  },
2218
2038
 
2219
2039
  get shadowRoot() {
@@ -3152,6 +2972,11 @@
3152
2972
  return def;
3153
2973
  }
3154
2974
 
2975
+ function getComponentHtmlPrototype(Ctor) {
2976
+ const def = getComponentInternalDef(Ctor);
2977
+ return def.bridge;
2978
+ }
2979
+
3155
2980
  const lightingElementDef = {
3156
2981
  ctor: LightningElement,
3157
2982
  name: LightningElement.name,
@@ -3215,29 +3040,86 @@
3215
3040
  };
3216
3041
  }
3217
3042
  /*
3218
- * Copyright (c) 2018, salesforce.com, inc.
3043
+ * Copyright (c) 2020, salesforce.com, inc.
3219
3044
  * All rights reserved.
3220
3045
  * SPDX-License-Identifier: MIT
3221
3046
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3222
3047
  */
3223
3048
 
3224
3049
 
3225
- const xlinkNS = 'http://www.w3.org/1999/xlink';
3226
- const xmlNS = 'http://www.w3.org/XML/1998/namespace';
3227
- const ColonCharCode = 58;
3228
-
3229
- function patchAttributes(oldVnode, vnode) {
3230
- const {
3231
- attrs
3232
- } = vnode.data;
3050
+ function getUpgradableConstructor(tagName) {
3051
+ // Should never get a tag with upper case letter at this point, the compiler should
3052
+ // produce only tags with lowercase letters
3053
+ // But, for backwards compatibility, we will lower case the tagName
3054
+ tagName = tagName.toLowerCase();
3055
+ let CE = getCustomElement$1(tagName);
3233
3056
 
3234
- if (isUndefined$1(attrs)) {
3235
- return;
3057
+ if (!isUndefined$1(CE)) {
3058
+ return CE;
3236
3059
  }
3060
+ /**
3061
+ * LWC Upgradable Element reference to an element that was created
3062
+ * via the scoped registry mechanism, and that is ready to be upgraded.
3063
+ */
3237
3064
 
3238
- const oldAttrs = isNull(oldVnode) ? EmptyObject : oldVnode.data.attrs;
3239
3065
 
3240
- if (oldAttrs === attrs) {
3066
+ CE = class LWCUpgradableElement extends HTMLElementExported$1 {
3067
+ constructor(upgradeCallback) {
3068
+ super();
3069
+
3070
+ if (isFunction$1(upgradeCallback)) {
3071
+ upgradeCallback(this); // nothing to do with the result for now
3072
+ }
3073
+ }
3074
+
3075
+ };
3076
+ defineCustomElement$1(tagName, CE);
3077
+ return CE;
3078
+ }
3079
+ /*
3080
+ * Copyright (c) 2018, salesforce.com, inc.
3081
+ * All rights reserved.
3082
+ * SPDX-License-Identifier: MIT
3083
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3084
+ */
3085
+
3086
+
3087
+ function isVBaseElement(vnode) {
3088
+ const {
3089
+ type
3090
+ } = vnode;
3091
+ return type === 2
3092
+ /* Element */
3093
+ || type === 3
3094
+ /* CustomElement */
3095
+ ;
3096
+ }
3097
+
3098
+ function isSameVnode(vnode1, vnode2) {
3099
+ return vnode1.key === vnode2.key && vnode1.sel === vnode2.sel;
3100
+ }
3101
+ /*
3102
+ * Copyright (c) 2018, salesforce.com, inc.
3103
+ * All rights reserved.
3104
+ * SPDX-License-Identifier: MIT
3105
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3106
+ */
3107
+
3108
+
3109
+ const ColonCharCode = 58;
3110
+
3111
+ function patchAttributes(oldVnode, vnode) {
3112
+ const {
3113
+ attrs
3114
+ } = vnode.data;
3115
+
3116
+ if (isUndefined$1(attrs)) {
3117
+ return;
3118
+ }
3119
+
3120
+ const oldAttrs = isNull(oldVnode) ? EmptyObject : oldVnode.data.attrs;
3121
+
3122
+ if (oldAttrs === attrs) {
3241
3123
  return;
3242
3124
  }
3243
3125
 
@@ -3254,10 +3136,10 @@
3254
3136
 
3255
3137
  if (StringCharCodeAt.call(key, 3) === ColonCharCode) {
3256
3138
  // Assume xml namespace
3257
- setAttribute$1(elm, key, cur, xmlNS);
3139
+ setAttribute$1(elm, key, cur, XML_NAMESPACE);
3258
3140
  } else if (StringCharCodeAt.call(key, 5) === ColonCharCode) {
3259
3141
  // Assume xlink namespace
3260
- setAttribute$1(elm, key, cur, xlinkNS);
3142
+ setAttribute$1(elm, key, cur, XLINK_NAMESPACE);
3261
3143
  } else if (isNull(cur) || isUndefined$1(cur)) {
3262
3144
  removeAttribute$1(elm, key);
3263
3145
  } else {
@@ -3506,6 +3388,153 @@
3506
3388
  */
3507
3389
 
3508
3390
 
3391
+ const TextHook = {
3392
+ create: vnode => {
3393
+ const {
3394
+ owner
3395
+ } = vnode;
3396
+ const elm = createText$1(vnode.text);
3397
+ linkNodeToShadow(elm, owner);
3398
+ vnode.elm = elm;
3399
+ },
3400
+ update: updateNodeHook,
3401
+ insert: insertNode,
3402
+ move: insertNode,
3403
+ remove: removeNode
3404
+ };
3405
+ const CommentHook = {
3406
+ create: vnode => {
3407
+ const {
3408
+ owner,
3409
+ text
3410
+ } = vnode;
3411
+ const elm = createComment$1(text);
3412
+ linkNodeToShadow(elm, owner);
3413
+ vnode.elm = elm;
3414
+ },
3415
+ update: updateNodeHook,
3416
+ insert: insertNode,
3417
+ move: insertNode,
3418
+ remove: removeNode
3419
+ }; // insert is called after update, which is used somewhere else (via a module)
3420
+ // to mark the vm as inserted, that means we cannot use update as the main channel
3421
+ // to rehydrate when dirty, because sometimes the element is not inserted just yet,
3422
+ // which breaks some invariants. For that reason, we have the following for any
3423
+ // Custom Element that is inserted via a template.
3424
+
3425
+ const ElementHook = {
3426
+ create: vnode => {
3427
+ const {
3428
+ sel,
3429
+ owner,
3430
+ data: {
3431
+ svg
3432
+ }
3433
+ } = vnode;
3434
+ const namespace = isTrue(svg) ? SVG_NAMESPACE : undefined;
3435
+ const elm = createElement$2(sel, namespace);
3436
+ linkNodeToShadow(elm, owner);
3437
+ fallbackElmHook(elm, vnode);
3438
+ vnode.elm = elm;
3439
+ patchElementPropsAndAttrs$1(null, vnode);
3440
+ },
3441
+ update: (oldVnode, vnode) => {
3442
+ patchElementPropsAndAttrs$1(oldVnode, vnode);
3443
+ patchChildren(vnode.elm, oldVnode.children, vnode.children);
3444
+ },
3445
+ insert: (vnode, parentNode, referenceNode) => {
3446
+ insertNode(vnode, parentNode, referenceNode);
3447
+ createChildrenHook(vnode);
3448
+ },
3449
+ move: insertNode,
3450
+ remove: (vnode, parentNode) => {
3451
+ removeNode(vnode, parentNode);
3452
+ removeChildren(vnode);
3453
+ }
3454
+ };
3455
+ const CustomElementHook = {
3456
+ create: vnode => {
3457
+ const {
3458
+ sel,
3459
+ owner
3460
+ } = vnode;
3461
+ const UpgradableConstructor = getUpgradableConstructor(sel);
3462
+ /**
3463
+ * Note: if the upgradable constructor does not expect, or throw when we new it
3464
+ * with a callback as the first argument, we could implement a more advanced
3465
+ * mechanism that only passes that argument if the constructor is known to be
3466
+ * an upgradable custom element.
3467
+ */
3468
+
3469
+ let vm;
3470
+ const elm = new UpgradableConstructor(elm => {
3471
+ // the custom element from the registry is expecting an upgrade callback
3472
+ vm = createViewModelHook(elm, vnode);
3473
+ });
3474
+ linkNodeToShadow(elm, owner);
3475
+ vnode.elm = elm;
3476
+
3477
+ if (vm) {
3478
+ allocateChildren(vnode, vm);
3479
+ } else if (vnode.ctor !== UpgradableConstructor) {
3480
+ throw new TypeError(`Incorrect Component Constructor`);
3481
+ }
3482
+
3483
+ patchElementPropsAndAttrs$1(null, vnode);
3484
+ },
3485
+ update: (oldVnode, vnode) => {
3486
+ patchElementPropsAndAttrs$1(oldVnode, vnode);
3487
+ const vm = getAssociatedVMIfPresent(vnode.elm);
3488
+
3489
+ if (vm) {
3490
+ // in fallback mode, the allocation will always set children to
3491
+ // empty and delegate the real allocation to the slot elements
3492
+ allocateChildren(vnode, vm);
3493
+ } // in fallback mode, the children will be always empty, so, nothing
3494
+ // will happen, but in native, it does allocate the light dom
3495
+
3496
+
3497
+ patchChildren(vnode.elm, oldVnode.children, vnode.children);
3498
+
3499
+ if (vm) {
3500
+ // this is important to preserve the top to bottom synchronous rendering phase.
3501
+
3502
+
3503
+ rerenderVM(vm);
3504
+ }
3505
+ },
3506
+ insert: (vnode, parentNode, referenceNode) => {
3507
+ insertNode(vnode, parentNode, referenceNode);
3508
+ const vm = getAssociatedVMIfPresent(vnode.elm);
3509
+
3510
+ if (vm) {
3511
+
3512
+ runConnectedCallback(vm);
3513
+ }
3514
+
3515
+ createChildrenHook(vnode);
3516
+
3517
+ if (vm) {
3518
+ appendVM(vm);
3519
+ }
3520
+ },
3521
+ move: insertNode,
3522
+ remove: (vnode, parentNode) => {
3523
+ removeNode(vnode, parentNode);
3524
+ const vm = getAssociatedVMIfPresent(vnode.elm);
3525
+
3526
+ if (vm) {
3527
+ // for custom elements we don't have to go recursively because the removeVM routine
3528
+ // will take care of disconnecting any child VM attached to its shadow as well.
3529
+ removeVM(vm);
3530
+ }
3531
+ }
3532
+ };
3533
+
3534
+ function isVNode(vnode) {
3535
+ return vnode != null;
3536
+ }
3537
+
3509
3538
  function observeElementChildNodes(elm) {
3510
3539
  elm.$domManual$ = true;
3511
3540
  }
@@ -3527,6 +3556,24 @@
3527
3556
  }
3528
3557
  }
3529
3558
 
3559
+ function linkNodeToShadow(elm, owner) {
3560
+ const {
3561
+ renderRoot,
3562
+ renderMode,
3563
+ shadowMode
3564
+ } = owner; // TODO [#1164]: this should eventually be done by the polyfill directly
3565
+
3566
+ if (isSyntheticShadowDefined$1) {
3567
+ if (shadowMode === 1
3568
+ /* Synthetic */
3569
+ || renderMode === 0
3570
+ /* Light */
3571
+ ) {
3572
+ elm[KEY__SHADOW_RESOLVER] = renderRoot[KEY__SHADOW_RESOLVER];
3573
+ }
3574
+ }
3575
+ }
3576
+
3530
3577
  function updateNodeHook(oldVnode, vnode) {
3531
3578
  const {
3532
3579
  elm,
@@ -3539,17 +3586,17 @@
3539
3586
  }
3540
3587
  }
3541
3588
 
3542
- function insertNodeHook(vnode, parentNode, referenceNode) {
3589
+ function insertNode(vnode, parentNode, referenceNode) {
3543
3590
 
3544
3591
  insert$1(vnode.elm, parentNode, referenceNode);
3545
3592
  }
3546
3593
 
3547
- function removeNodeHook(vnode, parentNode) {
3594
+ function removeNode(vnode, parentNode) {
3548
3595
 
3549
3596
  remove$1(vnode.elm, parentNode);
3550
3597
  }
3551
3598
 
3552
- function patchElementPropsAndAttrs(oldVnode, vnode) {
3599
+ function patchElementPropsAndAttrs$1(oldVnode, vnode) {
3553
3600
  if (isNull(oldVnode)) {
3554
3601
  applyEventListeners(vnode);
3555
3602
  applyStaticClassAttribute(vnode);
@@ -3564,11 +3611,6 @@
3564
3611
  patchProps(oldVnode, vnode);
3565
3612
  }
3566
3613
 
3567
- function hydrateElmHook(vnode) {
3568
- applyEventListeners(vnode);
3569
- patchProps(null, vnode);
3570
- }
3571
-
3572
3614
  function fallbackElmHook(elm, vnode) {
3573
3615
  const {
3574
3616
  owner
@@ -3588,7 +3630,7 @@
3588
3630
  } = owner.context;
3589
3631
 
3590
3632
  if (!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
3591
- /* manual */
3633
+ /* Manual */
3592
3634
  ) {
3593
3635
  // this element will now accept any manual content inserted into it
3594
3636
  observeElementChildNodes(elm);
@@ -3608,7 +3650,7 @@
3608
3650
  }
3609
3651
  }
3610
3652
 
3611
- function allocateChildrenHook(vnode, vm) {
3653
+ function allocateChildren(vnode, vm) {
3612
3654
  // A component with slots will re-render because:
3613
3655
  // 1- There is a change of the internal state.
3614
3656
  // 2- There is a change on the external api (ex: slots)
@@ -3641,11 +3683,12 @@
3641
3683
  }
3642
3684
 
3643
3685
  function createViewModelHook(elm, vnode) {
3644
- if (!isUndefined$1(getAssociatedVMIfPresent(elm))) {
3645
- // There is a possibility that a custom element is registered under tagName,
3646
- // in which case, the initialization is already carry on, and there is nothing else
3647
- // to do here since this hook is called right after invoking `document.createElement`.
3648
- return;
3686
+ let vm = getAssociatedVMIfPresent(elm); // There is a possibility that a custom element is registered under tagName, in which case, the
3687
+ // initialization is already carry on, and there is nothing else to do here since this hook is
3688
+ // called right after invoking `document.createElement`.
3689
+
3690
+ if (!isUndefined$1(vm)) {
3691
+ return vm;
3649
3692
  }
3650
3693
 
3651
3694
  const {
@@ -3667,12 +3710,13 @@
3667
3710
  setElementShadowToken(elm, stylesheetToken);
3668
3711
  }
3669
3712
 
3670
- const def = getComponentInternalDef(ctor);
3671
- createVM(elm, def, {
3713
+ vm = createVM(elm, ctor, {
3672
3714
  mode,
3673
3715
  owner,
3674
3716
  tagName: sel
3675
3717
  });
3718
+
3719
+ return vm;
3676
3720
  }
3677
3721
 
3678
3722
  function createChildrenHook(vnode) {
@@ -3691,23 +3735,7 @@
3691
3735
  }
3692
3736
  }
3693
3737
 
3694
- function hydrateChildrenHook(elmChildren, children, vm) {
3695
-
3696
- let elmCurrentChildIdx = 0;
3697
-
3698
- for (let j = 0, n = children.length; j < n; j++) {
3699
- const ch = children[j];
3700
-
3701
- if (ch != null) {
3702
- const childNode = elmChildren[elmCurrentChildIdx];
3703
-
3704
- ch.hook.hydrate(ch, childNode);
3705
- elmCurrentChildIdx++;
3706
- }
3707
- }
3708
- }
3709
-
3710
- function removeElmHook(vnode) {
3738
+ function removeChildren(vnode) {
3711
3739
  // this method only needs to search on child vnodes from template
3712
3740
  // to trigger the remove hook just in case some of those children
3713
3741
  // are custom elements.
@@ -3726,6 +3754,8 @@
3726
3754
  }
3727
3755
 
3728
3756
  function allocateInSlot(vm, children) {
3757
+ var _a;
3758
+
3729
3759
  const {
3730
3760
  cmpSlots: oldSlots
3731
3761
  } = vm;
@@ -3738,10 +3768,12 @@
3738
3768
  continue;
3739
3769
  }
3740
3770
 
3741
- const {
3742
- data
3743
- } = vnode;
3744
- const slotName = data.attrs && data.attrs.slot || '';
3771
+ let slotName = '';
3772
+
3773
+ if (isVBaseElement(vnode)) {
3774
+ slotName = ((_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) || '';
3775
+ }
3776
+
3745
3777
  const vnodes = cmpSlots[slotName] = cmpSlots[slotName] || []; // re-keying the vnodes is necessary to avoid conflicts with default content for the slot
3746
3778
  // which might have similar keys. Each vnode will always have a key that
3747
3779
  // starts with a numeric character from compiler. In this case, we add a unique
@@ -3796,293 +3828,204 @@
3796
3828
  function hasDynamicChildren(children) {
3797
3829
  return FromIteration.has(children);
3798
3830
  }
3799
- /*
3800
- * Copyright (c) 2020, salesforce.com, inc.
3801
- * All rights reserved.
3802
- * SPDX-License-Identifier: MIT
3803
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3804
- */
3805
-
3806
-
3807
- function getUpgradableConstructor(tagName) {
3808
- // Should never get a tag with upper case letter at this point, the compiler should
3809
- // produce only tags with lowercase letters
3810
- // But, for backwards compatibility, we will lower case the tagName
3811
- tagName = tagName.toLowerCase();
3812
- let CE = getCustomElement$1(tagName);
3813
3831
 
3814
- if (!isUndefined$1(CE)) {
3815
- return CE;
3816
- }
3817
- /**
3818
- * LWC Upgradable Element reference to an element that was created
3819
- * via the scoped registry mechanism, and that is ready to be upgraded.
3820
- */
3832
+ function createKeyToOldIdx(children, beginIdx, endIdx) {
3833
+ const map = {}; // TODO [#1637]: simplify this by assuming that all vnodes has keys
3821
3834
 
3835
+ for (let j = beginIdx; j <= endIdx; ++j) {
3836
+ const ch = children[j];
3822
3837
 
3823
- CE = class LWCUpgradableElement extends HTMLElementExported$1 {
3824
- constructor(upgradeCallback) {
3825
- super();
3838
+ if (isVNode(ch)) {
3839
+ const {
3840
+ key
3841
+ } = ch;
3826
3842
 
3827
- if (isFunction$1(upgradeCallback)) {
3828
- upgradeCallback(this); // nothing to do with the result for now
3843
+ if (key !== undefined) {
3844
+ map[key] = j;
3829
3845
  }
3830
3846
  }
3831
-
3832
- };
3833
- defineCustomElement$1(tagName, CE);
3834
- return CE;
3835
- }
3836
- /*
3837
- * Copyright (c) 2018, salesforce.com, inc.
3838
- * All rights reserved.
3839
- * SPDX-License-Identifier: MIT
3840
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3841
- */
3842
-
3843
-
3844
- const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
3845
- const SymbolIterator = Symbol.iterator;
3846
- const TextHook = {
3847
- create: vnode => {
3848
- const {
3849
- owner
3850
- } = vnode;
3851
- const elm = createText$1(vnode.text);
3852
- linkNodeToShadow(elm, owner);
3853
- vnode.elm = elm;
3854
- },
3855
- update: updateNodeHook,
3856
- insert: insertNodeHook,
3857
- move: insertNodeHook,
3858
- remove: removeNodeHook,
3859
- hydrate: (vNode, node) => {
3860
- var _a;
3861
-
3862
-
3863
- node.nodeValue = (_a = vNode.text) !== null && _a !== void 0 ? _a : null;
3864
- vNode.elm = node;
3865
3847
  }
3866
- };
3867
- const CommentHook = {
3868
- create: vnode => {
3869
- const {
3870
- owner,
3871
- text
3872
- } = vnode;
3873
- const elm = createComment$1(text);
3874
- linkNodeToShadow(elm, owner);
3875
- vnode.elm = elm;
3876
- },
3877
- update: updateNodeHook,
3878
- insert: insertNodeHook,
3879
- move: insertNodeHook,
3880
- remove: removeNodeHook,
3881
- hydrate: (vNode, node) => {
3882
- var _a;
3883
-
3884
3848
 
3885
- node.nodeValue = (_a = vNode.text) !== null && _a !== void 0 ? _a : null;
3886
- vNode.elm = node;
3887
- }
3888
- }; // insert is called after update, which is used somewhere else (via a module)
3889
- // to mark the vm as inserted, that means we cannot use update as the main channel
3890
- // to rehydrate when dirty, because sometimes the element is not inserted just yet,
3891
- // which breaks some invariants. For that reason, we have the following for any
3892
- // Custom Element that is inserted via a template.
3893
-
3894
- const ElementHook = {
3895
- create: vnode => {
3896
- const {
3897
- sel,
3898
- owner,
3899
- data: {
3900
- svg
3901
- }
3902
- } = vnode;
3903
- const namespace = isTrue(svg) ? SVG_NAMESPACE : undefined;
3904
- const elm = createElement$2(sel, namespace);
3905
- linkNodeToShadow(elm, owner);
3906
- fallbackElmHook(elm, vnode);
3907
- vnode.elm = elm;
3908
- patchElementPropsAndAttrs(null, vnode);
3909
- },
3910
- update: (oldVnode, vnode) => {
3911
- patchElementPropsAndAttrs(oldVnode, vnode);
3912
- patchChildren(vnode.elm, oldVnode.children, vnode.children);
3913
- },
3914
- insert: (vnode, parentNode, referenceNode) => {
3915
- insertNodeHook(vnode, parentNode, referenceNode);
3916
- createChildrenHook(vnode);
3917
- },
3918
- move: (vnode, parentNode, referenceNode) => {
3919
- insertNodeHook(vnode, parentNode, referenceNode);
3920
- },
3921
- remove: (vnode, parentNode) => {
3922
- removeNodeHook(vnode, parentNode);
3923
- removeElmHook(vnode);
3924
- },
3925
- hydrate: (vnode, node) => {
3926
- const elm = node;
3927
- vnode.elm = elm;
3928
- const {
3929
- context
3930
- } = vnode.data;
3931
- const isDomManual = Boolean(!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
3932
- /* manual */
3933
- );
3849
+ return map;
3850
+ }
3934
3851
 
3935
- if (isDomManual) {
3936
- // it may be that this element has lwc:inner-html, we need to diff and in case are the same,
3937
- // remove the innerHTML from props so it reuses the existing dom elements.
3938
- const {
3939
- props
3940
- } = vnode.data;
3852
+ function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
3853
+ for (; startIdx <= endIdx; ++startIdx) {
3854
+ const ch = vnodes[startIdx];
3941
3855
 
3942
- if (!isUndefined$1(props) && !isUndefined$1(props.innerHTML)) {
3943
- if (elm.innerHTML === props.innerHTML) {
3944
- delete props.innerHTML;
3945
- } else {
3946
- logWarn(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: innerHTML values do not match for element, will recover from the difference`, vnode.owner);
3947
- }
3948
- }
3856
+ if (isVNode(ch)) {
3857
+ ch.hook.create(ch);
3858
+ ch.hook.insert(ch, parentElm, before);
3949
3859
  }
3860
+ }
3861
+ }
3950
3862
 
3951
- hydrateElmHook(vnode);
3863
+ function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
3864
+ for (; startIdx <= endIdx; ++startIdx) {
3865
+ const ch = vnodes[startIdx]; // text nodes do not have logic associated to them
3952
3866
 
3953
- if (!isDomManual) {
3954
- hydrateChildrenHook(vnode.elm.childNodes, vnode.children, vnode.owner);
3867
+ if (isVNode(ch)) {
3868
+ ch.hook.remove(ch, parentElm);
3955
3869
  }
3956
3870
  }
3957
- };
3958
- const CustomElementHook = {
3959
- create: vnode => {
3960
- const {
3961
- sel,
3962
- owner
3963
- } = vnode;
3964
- const UpgradableConstructor = getUpgradableConstructor(sel);
3965
- /**
3966
- * Note: if the upgradable constructor does not expect, or throw when we new it
3967
- * with a callback as the first argument, we could implement a more advanced
3968
- * mechanism that only passes that argument if the constructor is known to be
3969
- * an upgradable custom element.
3970
- */
3871
+ }
3971
3872
 
3972
- const elm = new UpgradableConstructor(elm => {
3973
- // the custom element from the registry is expecting an upgrade callback
3974
- createViewModelHook(elm, vnode);
3975
- });
3976
- linkNodeToShadow(elm, owner);
3977
- vnode.elm = elm;
3978
- const vm = getAssociatedVMIfPresent(elm);
3873
+ function updateDynamicChildren(parentElm, oldCh, newCh) {
3874
+ let oldStartIdx = 0;
3875
+ let newStartIdx = 0;
3876
+ let oldEndIdx = oldCh.length - 1;
3877
+ let oldStartVnode = oldCh[0];
3878
+ let oldEndVnode = oldCh[oldEndIdx];
3879
+ const newChEnd = newCh.length - 1;
3880
+ let newEndIdx = newChEnd;
3881
+ let newStartVnode = newCh[0];
3882
+ let newEndVnode = newCh[newEndIdx];
3883
+ let oldKeyToIdx;
3884
+ let idxInOld;
3885
+ let elmToMove;
3886
+ let before;
3979
3887
 
3980
- if (vm) {
3981
- allocateChildrenHook(vnode, vm);
3982
- } else if (vnode.ctor !== UpgradableConstructor) {
3983
- throw new TypeError(`Incorrect Component Constructor`);
3984
- }
3888
+ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
3889
+ if (!isVNode(oldStartVnode)) {
3890
+ oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left
3891
+ } else if (!isVNode(oldEndVnode)) {
3892
+ oldEndVnode = oldCh[--oldEndIdx];
3893
+ } else if (!isVNode(newStartVnode)) {
3894
+ newStartVnode = newCh[++newStartIdx];
3895
+ } else if (!isVNode(newEndVnode)) {
3896
+ newEndVnode = newCh[--newEndIdx];
3897
+ } else if (isSameVnode(oldStartVnode, newStartVnode)) {
3898
+ patchVnode(oldStartVnode, newStartVnode);
3899
+ oldStartVnode = oldCh[++oldStartIdx];
3900
+ newStartVnode = newCh[++newStartIdx];
3901
+ } else if (isSameVnode(oldEndVnode, newEndVnode)) {
3902
+ patchVnode(oldEndVnode, newEndVnode);
3903
+ oldEndVnode = oldCh[--oldEndIdx];
3904
+ newEndVnode = newCh[--newEndIdx];
3905
+ } else if (isSameVnode(oldStartVnode, newEndVnode)) {
3906
+ // Vnode moved right
3907
+ patchVnode(oldStartVnode, newEndVnode);
3908
+ newEndVnode.hook.move(oldStartVnode, parentElm, nextSibling$1(oldEndVnode.elm));
3909
+ oldStartVnode = oldCh[++oldStartIdx];
3910
+ newEndVnode = newCh[--newEndIdx];
3911
+ } else if (isSameVnode(oldEndVnode, newStartVnode)) {
3912
+ // Vnode moved left
3913
+ patchVnode(oldEndVnode, newStartVnode);
3914
+ newStartVnode.hook.move(oldEndVnode, parentElm, oldStartVnode.elm);
3915
+ oldEndVnode = oldCh[--oldEndIdx];
3916
+ newStartVnode = newCh[++newStartIdx];
3917
+ } else {
3918
+ if (oldKeyToIdx === undefined) {
3919
+ oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
3920
+ }
3985
3921
 
3986
- patchElementPropsAndAttrs(null, vnode);
3987
- },
3988
- update: (oldVnode, vnode) => {
3989
- patchElementPropsAndAttrs(oldVnode, vnode);
3990
- const vm = getAssociatedVMIfPresent(vnode.elm);
3922
+ idxInOld = oldKeyToIdx[newStartVnode.key];
3991
3923
 
3992
- if (vm) {
3993
- // in fallback mode, the allocation will always set children to
3994
- // empty and delegate the real allocation to the slot elements
3995
- allocateChildrenHook(vnode, vm);
3996
- } // in fallback mode, the children will be always empty, so, nothing
3997
- // will happen, but in native, it does allocate the light dom
3924
+ if (isUndefined$1(idxInOld)) {
3925
+ // New element
3926
+ newStartVnode.hook.create(newStartVnode);
3927
+ newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm);
3928
+ newStartVnode = newCh[++newStartIdx];
3929
+ } else {
3930
+ elmToMove = oldCh[idxInOld];
3998
3931
 
3932
+ if (isVNode(elmToMove)) {
3933
+ if (elmToMove.sel !== newStartVnode.sel) {
3934
+ // New element
3935
+ newStartVnode.hook.create(newStartVnode);
3936
+ newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm);
3937
+ } else {
3938
+ patchVnode(elmToMove, newStartVnode);
3939
+ oldCh[idxInOld] = undefined;
3940
+ newStartVnode.hook.move(elmToMove, parentElm, oldStartVnode.elm);
3941
+ }
3942
+ }
3999
3943
 
4000
- patchChildren(vnode.elm, oldVnode.children, vnode.children);
3944
+ newStartVnode = newCh[++newStartIdx];
3945
+ }
3946
+ }
3947
+ }
4001
3948
 
4002
- if (vm) {
4003
- // this is important to preserve the top to bottom synchronous rendering phase.
3949
+ if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
3950
+ if (oldStartIdx > oldEndIdx) {
3951
+ // There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
3952
+ // already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
3953
+ let i = newEndIdx;
3954
+ let n;
4004
3955
 
3956
+ do {
3957
+ n = newCh[++i];
3958
+ } while (!isVNode(n) && i < newChEnd);
4005
3959
 
4006
- rerenderVM(vm);
3960
+ before = isVNode(n) ? n.elm : null;
3961
+ addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
3962
+ } else {
3963
+ removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
4007
3964
  }
4008
- },
4009
- insert: (vnode, parentNode, referenceNode) => {
4010
- insertNodeHook(vnode, parentNode, referenceNode);
4011
- const vm = getAssociatedVMIfPresent(vnode.elm);
3965
+ }
3966
+ }
4012
3967
 
4013
- if (vm) {
3968
+ function updateStaticChildren(parentElm, oldCh, newCh) {
3969
+ const oldChLength = oldCh.length;
3970
+ const newChLength = newCh.length;
4014
3971
 
4015
- runConnectedCallback(vm);
4016
- }
3972
+ if (oldChLength === 0) {
3973
+ // the old list is empty, we can directly insert anything new
3974
+ addVnodes(parentElm, null, newCh, 0, newChLength);
3975
+ return;
3976
+ }
4017
3977
 
4018
- createChildrenHook(vnode);
3978
+ if (newChLength === 0) {
3979
+ // the old list is nonempty and the new list is empty so we can directly remove all old nodes
3980
+ // this is the case in which the dynamic children of an if-directive should be removed
3981
+ removeVnodes(parentElm, oldCh, 0, oldChLength);
3982
+ return;
3983
+ } // if the old list is not empty, the new list MUST have the same
3984
+ // amount of nodes, that's why we call this static children
4019
3985
 
4020
- if (vm) {
4021
- appendVM(vm);
4022
- }
4023
- },
4024
- move: (vnode, parentNode, referenceNode) => {
4025
- insertNodeHook(vnode, parentNode, referenceNode);
4026
- },
4027
- remove: (vnode, parentNode) => {
4028
- removeNodeHook(vnode, parentNode);
4029
- const vm = getAssociatedVMIfPresent(vnode.elm);
4030
3986
 
4031
- if (vm) {
4032
- // for custom elements we don't have to go recursively because the removeVM routine
4033
- // will take care of disconnecting any child VM attached to its shadow as well.
4034
- removeVM(vm);
4035
- }
4036
- },
4037
- hydrate: (vnode, elm) => {
4038
- // the element is created, but the vm is not
4039
- const {
4040
- sel,
4041
- mode,
4042
- ctor,
4043
- owner
4044
- } = vnode;
4045
- const def = getComponentInternalDef(ctor);
4046
- createVM(elm, def, {
4047
- mode,
4048
- owner,
4049
- tagName: sel
4050
- });
4051
- vnode.elm = elm;
4052
- const vm = getAssociatedVM(elm);
4053
- allocateChildrenHook(vnode, vm);
4054
- hydrateElmHook(vnode); // Insert hook section:
3987
+ let referenceElm = null;
3988
+
3989
+ for (let i = newChLength - 1; i >= 0; i -= 1) {
3990
+ const vnode = newCh[i];
3991
+ const oldVNode = oldCh[i];
4055
3992
 
4056
- runConnectedCallback(vm);
3993
+ if (vnode !== oldVNode) {
3994
+ if (isVNode(oldVNode)) {
3995
+ if (isVNode(vnode)) {
3996
+ // both vnodes must be equivalent, and se just need to patch them
3997
+ patchVnode(oldVNode, vnode);
3998
+ referenceElm = vnode.elm;
3999
+ } else {
4000
+ // removing the old vnode since the new one is null
4001
+ oldVNode.hook.remove(oldVNode, parentElm);
4002
+ }
4003
+ } else if (isVNode(vnode)) {
4004
+ // this condition is unnecessary
4005
+ vnode.hook.create(vnode); // insert the new node one since the old one is null
4057
4006
 
4058
- if (vm.renderMode !== 0
4059
- /* Light */
4060
- ) {
4061
- // VM is not rendering in Light DOM, we can proceed and hydrate the slotted content.
4062
- // Note: for Light DOM, this is handled while hydrating the VM
4063
- hydrateChildrenHook(vnode.elm.childNodes, vnode.children);
4007
+ vnode.hook.insert(vnode, parentElm, referenceElm);
4008
+ referenceElm = vnode.elm;
4009
+ }
4064
4010
  }
4065
-
4066
- hydrateVM(vm);
4067
4011
  }
4068
- };
4069
-
4070
- function linkNodeToShadow(elm, owner) {
4071
- const {
4072
- renderMode,
4073
- shadowMode
4074
- } = owner; // TODO [#1164]: this should eventually be done by the polyfill directly
4012
+ }
4075
4013
 
4076
- if (isSyntheticShadowDefined$1) {
4077
- if (shadowMode === 1
4078
- /* Synthetic */
4079
- || renderMode === 0
4080
- /* Light */
4081
- ) {
4082
- elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
4083
- }
4014
+ function patchVnode(oldVnode, vnode) {
4015
+ if (oldVnode !== vnode) {
4016
+ vnode.elm = oldVnode.elm;
4017
+ vnode.hook.update(oldVnode, vnode);
4084
4018
  }
4085
4019
  }
4020
+ /*
4021
+ * Copyright (c) 2018, salesforce.com, inc.
4022
+ * All rights reserved.
4023
+ * SPDX-License-Identifier: MIT
4024
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4025
+ */
4026
+
4027
+
4028
+ const SymbolIterator = Symbol.iterator;
4086
4029
 
4087
4030
  function addVNodeToChildLWC(vnode) {
4088
4031
  ArrayPush$1.call(getVMBeingRendered().velements, vnode);
@@ -4092,15 +4035,17 @@
4092
4035
  function h(sel, data, children) {
4093
4036
  const vmBeingRendered = getVMBeingRendered();
4094
4037
 
4095
- let text, elm;
4038
+ let elm;
4096
4039
  const {
4097
4040
  key
4098
4041
  } = data;
4099
4042
  return {
4043
+ type: 2
4044
+ /* Element */
4045
+ ,
4100
4046
  sel,
4101
4047
  data,
4102
4048
  children,
4103
- text,
4104
4049
  elm,
4105
4050
  key,
4106
4051
  hook: ElementHook,
@@ -4155,12 +4100,14 @@
4155
4100
  const {
4156
4101
  key
4157
4102
  } = data;
4158
- let text, elm;
4103
+ let elm;
4159
4104
  const vnode = {
4105
+ type: 3
4106
+ /* CustomElement */
4107
+ ,
4160
4108
  sel,
4161
4109
  data,
4162
4110
  children,
4163
- text,
4164
4111
  elm,
4165
4112
  key,
4166
4113
  hook: CustomElementHook,
@@ -4240,12 +4187,12 @@
4240
4187
 
4241
4188
 
4242
4189
  function t(text) {
4243
- const data = EmptyObject;
4244
- let sel, children, key, elm;
4190
+ let sel, key, elm;
4245
4191
  return {
4192
+ type: 0
4193
+ /* Text */
4194
+ ,
4246
4195
  sel,
4247
- data,
4248
- children,
4249
4196
  text,
4250
4197
  elm,
4251
4198
  key,
@@ -4256,12 +4203,12 @@
4256
4203
 
4257
4204
 
4258
4205
  function co(text) {
4259
- const data = EmptyObject;
4260
- let sel, children, key, elm;
4206
+ let sel, key, elm;
4261
4207
  return {
4208
+ type: 1
4209
+ /* Comment */
4210
+ ,
4262
4211
  sel,
4263
- data,
4264
- children,
4265
4212
  text,
4266
4213
  elm,
4267
4214
  key,
@@ -4672,7 +4619,7 @@
4672
4619
  insertGlobalStylesheet$1(stylesheets[i]);
4673
4620
  } else {
4674
4621
  // local level
4675
- insertStylesheet$1(stylesheets[i], root.cmpRoot);
4622
+ insertStylesheet$1(stylesheets[i], root.shadowRoot);
4676
4623
  }
4677
4624
  }
4678
4625
  }
@@ -4876,25 +4823,6 @@
4876
4823
 
4877
4824
  return false;
4878
4825
  }
4879
- /*
4880
- * Copyright (c) 2018, salesforce.com, inc.
4881
- * All rights reserved.
4882
- * SPDX-License-Identifier: MIT
4883
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4884
- */
4885
-
4886
-
4887
- function addErrorComponentStack(vm, error) {
4888
- if (!isFrozen(error) && isUndefined$1(error.wcStack)) {
4889
- const wcStack = getErrorComponentStack(vm);
4890
- defineProperty(error, 'wcStack', {
4891
- get() {
4892
- return wcStack;
4893
- }
4894
-
4895
- });
4896
- }
4897
- }
4898
4826
  let vmBeingConstructed = null;
4899
4827
 
4900
4828
  function isBeingConstructed(vm) {
@@ -5108,6 +5036,142 @@
5108
5036
  cbs[i].call(undefined, component, {}, def, context);
5109
5037
  }
5110
5038
  }
5039
+ /*
5040
+ * Copyright (c) 2022, salesforce.com, inc.
5041
+ * All rights reserved.
5042
+ * SPDX-License-Identifier: MIT
5043
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5044
+ */
5045
+
5046
+
5047
+ function hydrate$1(vnode, node) {
5048
+ switch (vnode.type) {
5049
+ case 0
5050
+ /* Text */
5051
+ :
5052
+ hydrateText(vnode, node);
5053
+ break;
5054
+
5055
+ case 1
5056
+ /* Comment */
5057
+ :
5058
+ hydrateComment(vnode, node);
5059
+ break;
5060
+
5061
+ case 2
5062
+ /* Element */
5063
+ :
5064
+ hydrateElement(vnode, node);
5065
+ break;
5066
+
5067
+ case 3
5068
+ /* CustomElement */
5069
+ :
5070
+ hydrateCustomElement(vnode, node);
5071
+ break;
5072
+ }
5073
+ }
5074
+
5075
+ function hydrateText(vnode, node) {
5076
+ var _a;
5077
+
5078
+
5079
+ node.nodeValue = (_a = vnode.text) !== null && _a !== void 0 ? _a : null;
5080
+ vnode.elm = node;
5081
+ }
5082
+
5083
+ function hydrateComment(vnode, node) {
5084
+ var _a;
5085
+
5086
+
5087
+ node.nodeValue = (_a = vnode.text) !== null && _a !== void 0 ? _a : null;
5088
+ vnode.elm = node;
5089
+ }
5090
+
5091
+ function hydrateElement(vnode, node) {
5092
+
5093
+ const elm = node;
5094
+ vnode.elm = elm;
5095
+ const {
5096
+ context
5097
+ } = vnode.data;
5098
+ const isDomManual = Boolean(!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
5099
+ /* Manual */
5100
+ );
5101
+
5102
+ if (isDomManual) {
5103
+ // it may be that this element has lwc:inner-html, we need to diff and in case are the same,
5104
+ // remove the innerHTML from props so it reuses the existing dom elements.
5105
+ const {
5106
+ props
5107
+ } = vnode.data;
5108
+
5109
+ if (!isUndefined$1(props) && !isUndefined$1(props.innerHTML)) {
5110
+ if (elm.innerHTML === props.innerHTML) {
5111
+ delete props.innerHTML;
5112
+ } else {
5113
+ logWarn(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: innerHTML values do not match for element, will recover from the difference`, vnode.owner);
5114
+ }
5115
+ }
5116
+ }
5117
+
5118
+ patchElementPropsAndAttrs(vnode);
5119
+
5120
+ if (!isDomManual) {
5121
+ hydrateChildren(vnode.elm.childNodes, vnode.children, vnode.owner);
5122
+ }
5123
+ }
5124
+
5125
+ function hydrateCustomElement(vnode, node) {
5126
+
5127
+ const elm = node;
5128
+ vnode.elm = elm;
5129
+ const {
5130
+ sel,
5131
+ mode,
5132
+ ctor,
5133
+ owner
5134
+ } = vnode;
5135
+ const vm = createVM(elm, ctor, {
5136
+ mode,
5137
+ owner,
5138
+ tagName: sel
5139
+ });
5140
+ allocateChildren(vnode, vm);
5141
+ patchElementPropsAndAttrs(vnode); // Insert hook section:
5142
+
5143
+ runConnectedCallback(vm);
5144
+
5145
+ if (vm.renderMode !== 0
5146
+ /* Light */
5147
+ ) {
5148
+ // VM is not rendering in Light DOM, we can proceed and hydrate the slotted content.
5149
+ // Note: for Light DOM, this is handled while hydrating the VM
5150
+ hydrateChildren(vnode.elm.childNodes, vnode.children);
5151
+ }
5152
+
5153
+ hydrateVM(vm);
5154
+ }
5155
+
5156
+ function hydrateChildren(elmChildren, children, vm) {
5157
+
5158
+ let childNodeIndex = 0;
5159
+
5160
+ for (let i = 0; i < children.length; i++) {
5161
+ const childVnode = children[i];
5162
+
5163
+ if (!isNull(childVnode)) {
5164
+ const childNode = elmChildren[childNodeIndex];
5165
+ hydrate$1(childVnode, childNode);
5166
+ childNodeIndex++;
5167
+ }
5168
+ }
5169
+ }
5170
+
5171
+ function patchElementPropsAndAttrs(vnode) {
5172
+ applyEventListeners(vnode);
5173
+ patchProps(null, vnode);
5174
+ }
5111
5175
  /*
5112
5176
  * Copyright (c) 2018, salesforce.com, inc.
5113
5177
  * All rights reserved.
@@ -5223,12 +5287,13 @@
5223
5287
  return ancestor;
5224
5288
  }
5225
5289
 
5226
- function createVM(elm, def, options) {
5290
+ function createVM(elm, ctor, options) {
5227
5291
  const {
5228
5292
  mode,
5229
5293
  owner,
5230
5294
  tagName
5231
5295
  } = options;
5296
+ const def = getComponentInternalDef(ctor);
5232
5297
  const vm = {
5233
5298
  elm,
5234
5299
  def,
@@ -5250,7 +5315,6 @@
5250
5315
  oar: create(null),
5251
5316
  cmpTemplate: null,
5252
5317
  renderMode: def.renderMode,
5253
- shadowMode: null,
5254
5318
  context: {
5255
5319
  stylesheetToken: undefined,
5256
5320
  hasTokenInClass: undefined,
@@ -5261,9 +5325,13 @@
5261
5325
  wiredConnecting: EmptyArray,
5262
5326
  wiredDisconnecting: EmptyArray
5263
5327
  },
5328
+ // Properties set right after VM creation.
5264
5329
  tro: null,
5330
+ shadowMode: null,
5331
+ // Properties set by the LightningElement constructor.
5265
5332
  component: null,
5266
- cmpRoot: null,
5333
+ shadowRoot: null,
5334
+ renderRoot: null,
5267
5335
  callHook,
5268
5336
  setHook,
5269
5337
  getHook
@@ -5372,13 +5440,14 @@
5372
5440
  const vmChildren = vm.renderMode === 0
5373
5441
  /* Light */
5374
5442
  ? vm.elm.childNodes : vm.elm.shadowRoot.childNodes;
5375
- hydrateChildrenHook(vmChildren, children);
5443
+ hydrateChildren(vmChildren, children);
5376
5444
  runRenderedCallback(vm);
5377
5445
  }
5378
5446
  }
5379
5447
 
5380
5448
  function patchShadowRoot(vm, newCh) {
5381
5449
  const {
5450
+ renderRoot,
5382
5451
  children: oldCh
5383
5452
  } = vm; // caching the new children collection
5384
5453
 
@@ -5395,7 +5464,6 @@
5395
5464
  , vm);
5396
5465
  }, () => {
5397
5466
  // job
5398
- const renderRoot = getRenderRoot(vm);
5399
5467
  patchChildren(renderRoot, oldCh, newCh);
5400
5468
  }, () => {
5401
5469
  // post
@@ -5622,14 +5690,22 @@
5622
5690
  for (let i = 0, len = vnodes.length; i < len; i += 1) {
5623
5691
  const vnode = vnodes[i];
5624
5692
 
5625
- if (!isNull(vnode) && isArray$1(vnode.children) && !isUndefined$1(vnode.elm)) {
5626
- // vnode is a VElement with children
5627
- if (isUndefined$1(vnode.ctor)) {
5628
- // it is a VElement, just keep looking (recursively)
5629
- recursivelyDisconnectChildren(vnode.children);
5630
- } else {
5631
- // it is a VCustomElement, disconnect it and ignore its children
5632
- resetComponentStateWhenRemoved(getAssociatedVM(vnode.elm));
5693
+ if (!isNull(vnode) && !isUndefined$1(vnode.elm)) {
5694
+ switch (vnode.type) {
5695
+ case 2
5696
+ /* Element */
5697
+ :
5698
+ recursivelyDisconnectChildren(vnode.children);
5699
+ break;
5700
+
5701
+ case 3
5702
+ /* CustomElement */
5703
+ :
5704
+ {
5705
+ const vm = getAssociatedVM(vnode.elm);
5706
+ resetComponentStateWhenRemoved(vm);
5707
+ break;
5708
+ }
5633
5709
  }
5634
5710
  }
5635
5711
  }
@@ -5641,15 +5717,15 @@
5641
5717
 
5642
5718
  function resetComponentRoot(vm) {
5643
5719
  const {
5644
- children
5720
+ children,
5721
+ renderRoot
5645
5722
  } = vm;
5646
- const rootNode = getRenderRoot(vm);
5647
5723
 
5648
5724
  for (let i = 0, len = children.length; i < len; i++) {
5649
5725
  const child = children[i];
5650
5726
 
5651
5727
  if (!isNull(child) && !isUndefined$1(child.elm)) {
5652
- remove$1(child.elm, rootNode);
5728
+ remove$1(child.elm, renderRoot);
5653
5729
  }
5654
5730
  }
5655
5731
 
@@ -5717,12 +5793,6 @@
5717
5793
  }
5718
5794
  }
5719
5795
  }
5720
-
5721
- function getRenderRoot(vm) {
5722
- return vm.renderMode === 1
5723
- /* Shadow */
5724
- ? vm.cmpRoot : vm.elm;
5725
- }
5726
5796
  /*
5727
5797
  * Copyright (c) 2018, salesforce.com, inc.
5728
5798
  * All rights reserved.
@@ -6104,7 +6174,7 @@
6104
6174
  hooksAreSet = true;
6105
6175
  setSanitizeHtmlContentHook(hooks.sanitizeHtmlContent);
6106
6176
  }
6107
- /* version: 2.7.3 */
6177
+ /* version: 2.7.4 */
6108
6178
 
6109
6179
  /*
6110
6180
  * Copyright (c) 2018, salesforce.com, inc.
@@ -6538,8 +6608,7 @@
6538
6608
  */
6539
6609
 
6540
6610
  const element = new UpgradableConstructor(elm => {
6541
- const def = getComponentInternalDef(Ctor);
6542
- createVM(elm, def, {
6611
+ createVM(elm, Ctor, {
6543
6612
  tagName: sel,
6544
6613
  mode: options.mode !== 'closed' ? 'open' : 'closed',
6545
6614
  owner: null
@@ -6577,13 +6646,11 @@
6577
6646
  throw new TypeError(`"hydrateComponent" expects an object as the third parameter but instead received ${props}.`);
6578
6647
  }
6579
6648
 
6580
- const def = getComponentInternalDef(Ctor);
6581
-
6582
6649
  try {
6583
6650
  // Let the renderer know we are hydrating, so it does not replace the existing shadowRoot
6584
6651
  // and uses the same algo to create the stylesheets as in SSR.
6585
6652
  setIsHydrating(true);
6586
- createVM(element, def, {
6653
+ createVM(element, Ctor, {
6587
6654
  mode: 'open',
6588
6655
  owner: null,
6589
6656
  tagName: element.tagName.toLowerCase()
@@ -6645,11 +6712,11 @@
6645
6712
  }
6646
6713
 
6647
6714
  function buildCustomElementConstructor(Ctor) {
6648
- const def = getComponentInternalDef(Ctor);
6649
- return class extends def.bridge {
6715
+ const HtmlPrototype = getComponentHtmlPrototype(Ctor);
6716
+ return class extends HtmlPrototype {
6650
6717
  constructor() {
6651
6718
  super();
6652
- createVM(this, def, {
6719
+ createVM(this, Ctor, {
6653
6720
  mode: 'open',
6654
6721
  owner: null,
6655
6722
  tagName: this.tagName
@@ -6772,7 +6839,7 @@
6772
6839
  });
6773
6840
  freeze(LightningElement);
6774
6841
  seal(LightningElement.prototype);
6775
- /* version: 2.7.3 */
6842
+ /* version: 2.7.4 */
6776
6843
 
6777
6844
  exports.LightningElement = LightningElement;
6778
6845
  exports.__unstable__ProfilerControl = profilerControl;