lwc 2.22.0 → 2.23.2

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 (39) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +1222 -947
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +1222 -946
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +1129 -882
  5. package/dist/engine-dom/iife/es5/engine-dom.js +524 -499
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +475 -457
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +1222 -946
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +1129 -882
  11. package/dist/engine-dom/umd/es5/engine-dom.js +524 -499
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +475 -457
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +809 -626
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +809 -626
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +30 -27
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +30 -27
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +2 -2
  20. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +29 -26
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +32 -31
  22. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js +2 -2
  23. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +31 -30
  24. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +30 -27
  25. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +2 -2
  26. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +29 -26
  27. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +32 -31
  28. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js +2 -2
  29. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +31 -30
  30. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  31. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/iife/es5/wire-service.js +2 -2
  34. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  35. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  36. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  37. package/dist/wire-service/umd/es5/wire-service.js +2 -2
  38. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  39. package/package.json +7 -7
@@ -302,9 +302,13 @@ var LWC = (function (exports) {
302
302
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
303
303
  */
304
304
  // Increment whenever the LWC template compiler changes
305
- const LWC_VERSION = "2.22.0";
305
+ const LWC_VERSION = "2.23.2";
306
306
  const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
307
- /** version: 2.22.0 */
307
+ /** version: 2.23.2 */
308
+
309
+ /**
310
+ * Copyright (C) 2018 salesforce.com, inc.
311
+ */
308
312
 
309
313
  /*
310
314
  * Copyright (c) 2018, salesforce.com, inc.
@@ -313,7 +317,7 @@ var LWC = (function (exports) {
313
317
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
314
318
  */
315
319
  function detect(propName) {
316
- return Object.getOwnPropertyDescriptor(Element.prototype, propName) === undefined;
320
+ return getOwnPropertyDescriptor$1(Element.prototype, propName) === undefined;
317
321
  }
318
322
 
319
323
  /*
@@ -382,6 +386,7 @@ var LWC = (function (exports) {
382
386
  patch$1(propName);
383
387
  }
384
388
  }
389
+ /** version: 2.23.2 */
385
390
 
386
391
  /**
387
392
  * Copyright (C) 2018 salesforce.com, inc.
@@ -401,6 +406,7 @@ var LWC = (function (exports) {
401
406
  ENABLE_HTML_COLLECTIONS_PATCH: null,
402
407
  ENABLE_INNER_OUTER_TEXT_PATCH: null,
403
408
  ENABLE_MIXED_SHADOW_MODE: null,
409
+ ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE: null,
404
410
  ENABLE_NODE_LIST_PATCH: null,
405
411
  ENABLE_NODE_PATCH: null,
406
412
  ENABLE_REACTIVE_SETTER: null,
@@ -409,7 +415,7 @@ var LWC = (function (exports) {
409
415
  if (!_globalThis.lwcRuntimeFlags) {
410
416
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
411
417
  }
412
- const runtimeFlags = _globalThis.lwcRuntimeFlags;
418
+ const lwcRuntimeFlags = _globalThis.lwcRuntimeFlags;
413
419
  /**
414
420
  * Set the value at runtime of a given feature flag. This method only be invoked once per feature
415
421
  * flag. It is meant to be used during the app initialization.
@@ -436,17 +442,17 @@ var LWC = (function (exports) {
436
442
  }
437
443
  if (process.env.NODE_ENV !== 'production') {
438
444
  // Allow the same flag to be set more than once outside of production to enable testing
439
- runtimeFlags[name] = value;
445
+ lwcRuntimeFlags[name] = value;
440
446
  }
441
447
  else {
442
448
  // Disallow the same flag to be set more than once in production
443
- const runtimeValue = runtimeFlags[name];
449
+ const runtimeValue = lwcRuntimeFlags[name];
444
450
  if (!isUndefined$1(runtimeValue)) {
445
451
  // eslint-disable-next-line no-console
446
452
  console.error(`Failed to set the value "${value}" for the runtime feature flag "${name}". "${name}" has already been set with the value "${runtimeValue}".`);
447
453
  return;
448
454
  }
449
- defineProperty(runtimeFlags, name, { value });
455
+ defineProperty(lwcRuntimeFlags, name, { value });
450
456
  }
451
457
  }
452
458
  /**
@@ -458,7 +464,7 @@ var LWC = (function (exports) {
458
464
  setFeatureFlag(name, value);
459
465
  }
460
466
  }
461
- /** version: 2.22.0 */
467
+ /** version: 2.23.2 */
462
468
 
463
469
  /*
464
470
  * Copyright (c) 2018, salesforce.com, inc.
@@ -472,7 +478,7 @@ var LWC = (function (exports) {
472
478
  window.addEventListener('test-dummy-flag', () => {
473
479
  let hasFlag = false;
474
480
 
475
- if (runtimeFlags.DUMMY_TEST_FLAG) {
481
+ if (lwcRuntimeFlags.DUMMY_TEST_FLAG) {
476
482
  hasFlag = true;
477
483
  }
478
484
 
@@ -499,7 +505,7 @@ var LWC = (function (exports) {
499
505
  window.addEventListener('test-dummy-flag', () => {
500
506
  let hasFlag = false;
501
507
 
502
- if (runtimeFlags.DUMMY_TEST_FLAG) {
508
+ if (lwcRuntimeFlags.DUMMY_TEST_FLAG) {
503
509
  hasFlag = true;
504
510
  }
505
511
 
@@ -807,8 +813,8 @@ var LWC = (function (exports) {
807
813
  */
808
814
  // This is a temporary workaround to get the @lwc/engine-server to evaluate in node without having
809
815
  // to inject at runtime.
810
- const HTMLElementConstructor$1 = typeof HTMLElement !== 'undefined' ? HTMLElement : function () { };
811
- const HTMLElementPrototype = HTMLElementConstructor$1.prototype;
816
+ const HTMLElementConstructor = typeof HTMLElement !== 'undefined' ? HTMLElement : function () { };
817
+ const HTMLElementPrototype = HTMLElementConstructor.prototype;
812
818
 
813
819
  /*
814
820
  * Copyright (c) 2018, salesforce.com, inc.
@@ -1263,6 +1269,14 @@ var LWC = (function (exports) {
1263
1269
  defineProperties(proto, getLightningElementPrototypeRestrictionsDescriptors(proto));
1264
1270
  }
1265
1271
 
1272
+ function updateComponentValue(vm, key, newValue) {
1273
+ const { cmpFields } = vm;
1274
+ if (newValue !== cmpFields[key]) {
1275
+ cmpFields[key] = newValue;
1276
+ componentValueMutated(vm, key);
1277
+ }
1278
+ }
1279
+
1266
1280
  /**
1267
1281
  * Copyright (C) 2017 salesforce.com, inc.
1268
1282
  */
@@ -1895,10 +1909,7 @@ var LWC = (function (exports) {
1895
1909
  assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
1896
1910
  assert.invariant(!isObject(newValue) || isNull(newValue), `Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
1897
1911
  }
1898
- if (newValue !== vm.cmpProps[propName]) {
1899
- vm.cmpProps[propName] = newValue;
1900
- componentValueMutated(vm, propName);
1901
- }
1912
+ updateComponentValue(vm, propName, newValue);
1902
1913
  return set.call(vm.elm, newValue);
1903
1914
  },
1904
1915
  };
@@ -2193,10 +2204,7 @@ var LWC = (function (exports) {
2193
2204
  },
2194
2205
  set(newValue) {
2195
2206
  const vm = getAssociatedVM(this);
2196
- if (newValue !== vm.cmpFields[key]) {
2197
- vm.cmpFields[key] = newValue;
2198
- componentValueMutated(vm, key);
2199
- }
2207
+ updateComponentValue(vm, key, newValue);
2200
2208
  },
2201
2209
  enumerable: true,
2202
2210
  configurable: true,
@@ -2325,7 +2333,7 @@ var LWC = (function (exports) {
2325
2333
  }
2326
2334
 
2327
2335
  if (set) {
2328
- if (runtimeFlags.ENABLE_REACTIVE_SETTER) {
2336
+ if (lwcRuntimeFlags.ENABLE_REACTIVE_SETTER) {
2329
2337
  let ro = vm.oar[key];
2330
2338
 
2331
2339
  if (isUndefined$1(ro)) {
@@ -2383,10 +2391,7 @@ var LWC = (function (exports) {
2383
2391
  assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2384
2392
  }
2385
2393
  const reactiveOrAnyValue = getReactiveProxy(newValue);
2386
- if (reactiveOrAnyValue !== vm.cmpFields[key]) {
2387
- vm.cmpFields[key] = reactiveOrAnyValue;
2388
- componentValueMutated(vm, key);
2389
- }
2394
+ updateComponentValue(vm, key, reactiveOrAnyValue);
2390
2395
  },
2391
2396
  enumerable: true,
2392
2397
  configurable: true,
@@ -2425,10 +2430,7 @@ var LWC = (function (exports) {
2425
2430
  * letting the author to do the wrong thing, but it will keep our
2426
2431
  * system to be backward compatible.
2427
2432
  */
2428
- if (value !== vm.cmpFields[key]) {
2429
- vm.cmpFields[key] = value;
2430
- componentValueMutated(vm, key);
2431
- }
2433
+ updateComponentValue(vm, key, value);
2432
2434
  },
2433
2435
  enumerable: true,
2434
2436
  configurable: true,
@@ -2889,7 +2891,7 @@ var LWC = (function (exports) {
2889
2891
  defineProperties(HTMLBridgeElement.prototype, descriptors);
2890
2892
  return HTMLBridgeElement;
2891
2893
  }
2892
- const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor$1, getOwnPropertyNames$1(HTMLElementOriginalDescriptors), []);
2894
+ const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, getOwnPropertyNames$1(HTMLElementOriginalDescriptors), []);
2893
2895
  freeze(BaseBridgeElement);
2894
2896
  seal(BaseBridgeElement.prototype);
2895
2897
 
@@ -2983,7 +2985,7 @@ var LWC = (function (exports) {
2983
2985
  throw new ReferenceError();
2984
2986
  }
2985
2987
 
2986
- if (runtimeFlags.ENABLE_HMR) {
2988
+ if (lwcRuntimeFlags.ENABLE_HMR) {
2987
2989
  const visited = new Set();
2988
2990
 
2989
2991
  while (swappedTemplateMap.has(tpl) && !visited.has(tpl)) {
@@ -3000,7 +3002,7 @@ var LWC = (function (exports) {
3000
3002
  throw new ReferenceError();
3001
3003
  }
3002
3004
 
3003
- if (runtimeFlags.ENABLE_HMR) {
3005
+ if (lwcRuntimeFlags.ENABLE_HMR) {
3004
3006
  const visited = new Set();
3005
3007
 
3006
3008
  while (swappedComponentMap.has(Ctor) && !visited.has(Ctor)) {
@@ -3017,7 +3019,7 @@ var LWC = (function (exports) {
3017
3019
  throw new ReferenceError();
3018
3020
  }
3019
3021
 
3020
- if (runtimeFlags.ENABLE_HMR) {
3022
+ if (lwcRuntimeFlags.ENABLE_HMR) {
3021
3023
  const visited = new Set();
3022
3024
 
3023
3025
  while (swappedStyleMap.has(style) && !visited.has(style)) {
@@ -3034,7 +3036,7 @@ var LWC = (function (exports) {
3034
3036
  throw new ReferenceError();
3035
3037
  }
3036
3038
 
3037
- if (runtimeFlags.ENABLE_HMR) {
3039
+ if (lwcRuntimeFlags.ENABLE_HMR) {
3038
3040
  // tracking active component
3039
3041
  const Ctor = vm.def.ctor;
3040
3042
  let componentVMs = activeComponents.get(Ctor);
@@ -3091,7 +3093,7 @@ var LWC = (function (exports) {
3091
3093
  throw new ReferenceError();
3092
3094
  }
3093
3095
 
3094
- if (runtimeFlags.ENABLE_HMR) {
3096
+ if (lwcRuntimeFlags.ENABLE_HMR) {
3095
3097
  // tracking inactive component
3096
3098
  const Ctor = vm.def.ctor;
3097
3099
  let list = activeComponents.get(Ctor);
@@ -3138,7 +3140,7 @@ var LWC = (function (exports) {
3138
3140
  }
3139
3141
  }
3140
3142
 
3141
- if (!runtimeFlags.ENABLE_HMR) {
3143
+ if (!lwcRuntimeFlags.ENABLE_HMR) {
3142
3144
  throw new Error('HMR is not enabled');
3143
3145
  }
3144
3146
 
@@ -3154,7 +3156,7 @@ var LWC = (function (exports) {
3154
3156
  }
3155
3157
  }
3156
3158
 
3157
- if (!runtimeFlags.ENABLE_HMR) {
3159
+ if (!lwcRuntimeFlags.ENABLE_HMR) {
3158
3160
  throw new Error('HMR is not enabled');
3159
3161
  }
3160
3162
 
@@ -3168,7 +3170,7 @@ var LWC = (function (exports) {
3168
3170
  return rehydrateHotStyle(oldStyle);
3169
3171
  }
3170
3172
 
3171
- if (!runtimeFlags.ENABLE_HMR) {
3173
+ if (!lwcRuntimeFlags.ENABLE_HMR) {
3172
3174
  throw new Error('HMR is not enabled');
3173
3175
  }
3174
3176
 
@@ -3517,13 +3519,13 @@ var LWC = (function (exports) {
3517
3519
  return owner;
3518
3520
  }
3519
3521
  function createStylesheet(vm, stylesheets) {
3520
- const { renderMode, shadowMode, renderer: { ssr, insertStylesheet }, } = vm;
3522
+ const { renderMode, shadowMode, renderer: { insertStylesheet }, } = vm;
3521
3523
  if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
3522
3524
  for (let i = 0; i < stylesheets.length; i++) {
3523
3525
  insertStylesheet(stylesheets[i]);
3524
3526
  }
3525
3527
  }
3526
- else if (ssr || vm.hydrated) {
3528
+ else if (vm.hydrated) {
3527
3529
  // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
3528
3530
  // This works in the client, because the stylesheets are created, and cached in the VM
3529
3531
  // the first time the VM renders.
@@ -3548,30 +3550,67 @@ var LWC = (function (exports) {
3548
3550
  * SPDX-License-Identifier: MIT
3549
3551
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3550
3552
  */
3553
+
3554
+ function checkHasVM(elm) {
3555
+ const hasVM = !isUndefined$1(getAssociatedVMIfPresent(elm));
3556
+
3557
+ if (process.env.NODE_ENV !== 'production' && !hasVM) {
3558
+ // Occurs when an element is manually created with the same tag name as an existing LWC component. In that case,
3559
+ // we skip calling the LWC connectedCallback/disconnectedCallback logic and log an error.
3560
+ logError(`VM for tag name "${elm.tagName.toLowerCase()}" is undefined. ` + `This indicates that an element was created with this tag name, ` + `which is already reserved by an LWC component. Use lwc.createElement ` + `instead to create elements.`);
3561
+ }
3562
+
3563
+ return hasVM;
3564
+ }
3565
+
3551
3566
  function getUpgradableConstructor(tagName, renderer) {
3552
- const { getCustomElement, HTMLElementExported: RendererHTMLElement, defineCustomElement, } = renderer;
3553
- // Should never get a tag with upper case letter at this point, the compiler should
3554
- // produce only tags with lowercase letters
3555
- // But, for backwards compatibility, we will lower case the tagName
3556
- tagName = tagName.toLowerCase();
3557
- let CE = getCustomElement(tagName);
3558
- if (!isUndefined$1(CE)) {
3559
- return CE;
3567
+ const {
3568
+ getCustomElement,
3569
+ HTMLElementExported: RendererHTMLElement,
3570
+ defineCustomElement
3571
+ } = renderer; // Should never get a tag with upper case letter at this point, the compiler should
3572
+ // produce only tags with lowercase letters
3573
+ // But, for backwards compatibility, we will lower case the tagName
3574
+
3575
+ tagName = tagName.toLowerCase();
3576
+ let CE = getCustomElement(tagName);
3577
+
3578
+ if (!isUndefined$1(CE)) {
3579
+ return CE;
3580
+ }
3581
+ /**
3582
+ * LWC Upgradable Element reference to an element that was created
3583
+ * via the scoped registry mechanism, and that is ready to be upgraded.
3584
+ */
3585
+
3586
+
3587
+ CE = class LWCUpgradableElement extends RendererHTMLElement {
3588
+ constructor(upgradeCallback) {
3589
+ super();
3590
+
3591
+ if (isFunction$1(upgradeCallback)) {
3592
+ upgradeCallback(this); // nothing to do with the result for now
3593
+ }
3560
3594
  }
3561
- /**
3562
- * LWC Upgradable Element reference to an element that was created
3563
- * via the scoped registry mechanism, and that is ready to be upgraded.
3564
- */
3565
- CE = class LWCUpgradableElement extends RendererHTMLElement {
3566
- constructor(upgradeCallback) {
3567
- super();
3568
- if (isFunction$1(upgradeCallback)) {
3569
- upgradeCallback(this); // nothing to do with the result for now
3570
- }
3571
- }
3595
+
3596
+ };
3597
+
3598
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3599
+ CE.prototype.connectedCallback = function () {
3600
+ if (checkHasVM(this)) {
3601
+ connectRootElement(this);
3602
+ }
3572
3603
  };
3573
- defineCustomElement(tagName, CE);
3574
- return CE;
3604
+
3605
+ CE.prototype.disconnectedCallback = function () {
3606
+ if (checkHasVM(this)) {
3607
+ disconnectRootElement(this);
3608
+ }
3609
+ };
3610
+ }
3611
+
3612
+ defineCustomElement(tagName, CE);
3613
+ return CE;
3575
3614
  }
3576
3615
 
3577
3616
  /*
@@ -3659,6 +3698,14 @@ var LWC = (function (exports) {
3659
3698
  // different than the one previously set.
3660
3699
  if (isFirstPatch ||
3661
3700
  cur !== (isLiveBindingProp(sel, key) ? getProperty(elm, key) : oldProps[key])) {
3701
+ // Additional verification if properties are supported by the element
3702
+ // Validation relies on html properties and public properties being defined on the element,
3703
+ // SSR has its own custom validation.
3704
+ if (process.env.NODE_ENV !== 'production') {
3705
+ if (!(key in elm)) {
3706
+ logWarn(`Unknown public property "${key}" of element <${elm.tagName.toLowerCase()}>. This is either a typo on the corresponding attribute "${htmlPropertyToAttribute(key)}", or the attribute does not exist in this browser or DOM implementation.`);
3707
+ }
3708
+ }
3662
3709
  setProperty(elm, key, cur);
3663
3710
  }
3664
3711
  }
@@ -3817,569 +3864,798 @@ var LWC = (function (exports) {
3817
3864
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3818
3865
  */
3819
3866
  function patchChildren(c1, c2, parent, renderer) {
3820
- if (hasDynamicChildren(c2)) {
3821
- updateDynamicChildren(c1, c2, parent, renderer);
3822
- }
3823
- else {
3824
- updateStaticChildren(c1, c2, parent, renderer);
3825
- }
3867
+ if (hasDynamicChildren(c2)) {
3868
+ updateDynamicChildren(c1, c2, parent, renderer);
3869
+ } else {
3870
+ updateStaticChildren(c1, c2, parent, renderer);
3871
+ }
3826
3872
  }
3827
- function patch(n1, n2, renderer) {
3828
- var _a, _b;
3829
- if (n1 === n2) {
3830
- return;
3831
- }
3832
- if (process.env.NODE_ENV !== 'production') {
3833
- if (!isSameVnode(n1, n2)) {
3834
- throw new Error('Expected these VNodes to be the same: ' +
3835
- JSON.stringify({ sel: n1.sel, key: n1.key }) +
3836
- ', ' +
3837
- JSON.stringify({ sel: n2.sel, key: n2.key }));
3838
- }
3839
- }
3840
- switch (n2.type) {
3841
- case 0 /* VNodeType.Text */:
3842
- // VText has no special capability, fallback to the owner's renderer
3843
- patchText(n1, n2, renderer);
3844
- break;
3845
- case 1 /* VNodeType.Comment */:
3846
- // VComment has no special capability, fallback to the owner's renderer
3847
- patchComment(n1, n2, renderer);
3848
- break;
3849
- case 4 /* VNodeType.Static */:
3850
- n2.elm = n1.elm;
3851
- break;
3852
- case 2 /* VNodeType.Element */:
3853
- patchElement(n1, n2, (_a = n2.data.renderer) !== null && _a !== void 0 ? _a : renderer);
3854
- break;
3855
- case 3 /* VNodeType.CustomElement */:
3856
- patchCustomElement(n1, n2, (_b = n2.data.renderer) !== null && _b !== void 0 ? _b : renderer);
3857
- break;
3873
+
3874
+ function patch(n1, n2, parent, renderer) {
3875
+ var _a, _b;
3876
+
3877
+ if (n1 === n2) {
3878
+ return;
3879
+ }
3880
+
3881
+ if (process.env.NODE_ENV !== 'production') {
3882
+ if (!isSameVnode(n1, n2)) {
3883
+ throw new Error('Expected these VNodes to be the same: ' + JSON.stringify({
3884
+ sel: n1.sel,
3885
+ key: n1.key
3886
+ }) + ', ' + JSON.stringify({
3887
+ sel: n2.sel,
3888
+ key: n2.key
3889
+ }));
3858
3890
  }
3891
+ }
3892
+
3893
+ switch (n2.type) {
3894
+ case 0
3895
+ /* VNodeType.Text */
3896
+ :
3897
+ // VText has no special capability, fallback to the owner's renderer
3898
+ patchText(n1, n2, renderer);
3899
+ break;
3900
+
3901
+ case 1
3902
+ /* VNodeType.Comment */
3903
+ :
3904
+ // VComment has no special capability, fallback to the owner's renderer
3905
+ patchComment(n1, n2, renderer);
3906
+ break;
3907
+
3908
+ case 4
3909
+ /* VNodeType.Static */
3910
+ :
3911
+ n2.elm = n1.elm;
3912
+ break;
3913
+
3914
+ case 2
3915
+ /* VNodeType.Element */
3916
+ :
3917
+ patchElement(n1, n2, (_a = n2.data.renderer) !== null && _a !== void 0 ? _a : renderer);
3918
+ break;
3919
+
3920
+ case 3
3921
+ /* VNodeType.CustomElement */
3922
+ :
3923
+ patchCustomElement(n1, n2, parent, (_b = n2.data.renderer) !== null && _b !== void 0 ? _b : renderer);
3924
+ break;
3925
+ }
3859
3926
  }
3927
+
3860
3928
  function mount(node, parent, renderer, anchor) {
3861
- var _a, _b;
3862
- switch (node.type) {
3863
- case 0 /* VNodeType.Text */:
3864
- // VText has no special capability, fallback to the owner's renderer
3865
- mountText(node, parent, anchor, renderer);
3866
- break;
3867
- case 1 /* VNodeType.Comment */:
3868
- // VComment has no special capability, fallback to the owner's renderer
3869
- mountComment(node, parent, anchor, renderer);
3870
- break;
3871
- case 4 /* VNodeType.Static */:
3872
- // VStatic cannot have a custom renderer associated to them, using owner's renderer
3873
- mountStatic(node, parent, anchor, renderer);
3874
- break;
3875
- case 2 /* VNodeType.Element */:
3876
- // If the vnode data has a renderer override use it, else fallback to owner's renderer
3877
- mountElement(node, parent, anchor, (_a = node.data.renderer) !== null && _a !== void 0 ? _a : renderer);
3878
- break;
3879
- case 3 /* VNodeType.CustomElement */:
3880
- // If the vnode data has a renderer override use it, else fallback to owner's renderer
3881
- mountCustomElement(node, parent, anchor, (_b = node.data.renderer) !== null && _b !== void 0 ? _b : renderer);
3882
- break;
3883
- }
3929
+ var _a, _b;
3930
+
3931
+ switch (node.type) {
3932
+ case 0
3933
+ /* VNodeType.Text */
3934
+ :
3935
+ // VText has no special capability, fallback to the owner's renderer
3936
+ mountText(node, parent, anchor, renderer);
3937
+ break;
3938
+
3939
+ case 1
3940
+ /* VNodeType.Comment */
3941
+ :
3942
+ // VComment has no special capability, fallback to the owner's renderer
3943
+ mountComment(node, parent, anchor, renderer);
3944
+ break;
3945
+
3946
+ case 4
3947
+ /* VNodeType.Static */
3948
+ :
3949
+ // VStatic cannot have a custom renderer associated to them, using owner's renderer
3950
+ mountStatic(node, parent, anchor, renderer);
3951
+ break;
3952
+
3953
+ case 2
3954
+ /* VNodeType.Element */
3955
+ :
3956
+ // If the vnode data has a renderer override use it, else fallback to owner's renderer
3957
+ mountElement(node, parent, anchor, (_a = node.data.renderer) !== null && _a !== void 0 ? _a : renderer);
3958
+ break;
3959
+
3960
+ case 3
3961
+ /* VNodeType.CustomElement */
3962
+ :
3963
+ // If the vnode data has a renderer override use it, else fallback to owner's renderer
3964
+ mountCustomElement(node, parent, anchor, (_b = node.data.renderer) !== null && _b !== void 0 ? _b : renderer);
3965
+ break;
3966
+ }
3884
3967
  }
3968
+
3885
3969
  function patchText(n1, n2, renderer) {
3886
- n2.elm = n1.elm;
3887
- if (n2.text !== n1.text) {
3888
- updateTextContent(n2, renderer);
3889
- }
3970
+ n2.elm = n1.elm;
3971
+
3972
+ if (n2.text !== n1.text) {
3973
+ updateTextContent(n2, renderer);
3974
+ }
3890
3975
  }
3976
+
3891
3977
  function mountText(vnode, parent, anchor, renderer) {
3892
- const { owner } = vnode;
3893
- const { createText } = renderer;
3894
- const textNode = (vnode.elm = createText(vnode.text));
3895
- linkNodeToShadow(textNode, owner, renderer);
3896
- insertNode(textNode, parent, anchor, renderer);
3978
+ const {
3979
+ owner
3980
+ } = vnode;
3981
+ const {
3982
+ createText
3983
+ } = renderer;
3984
+ const textNode = vnode.elm = createText(vnode.text);
3985
+ linkNodeToShadow(textNode, owner, renderer);
3986
+ insertNode(textNode, parent, anchor, renderer);
3897
3987
  }
3988
+
3898
3989
  function patchComment(n1, n2, renderer) {
3899
- n2.elm = n1.elm;
3900
- // FIXME: Comment nodes should be static, we shouldn't need to diff them together. However
3901
- // it is the case today.
3902
- if (n2.text !== n1.text) {
3903
- updateTextContent(n2, renderer);
3904
- }
3990
+ n2.elm = n1.elm; // FIXME: Comment nodes should be static, we shouldn't need to diff them together. However
3991
+ // it is the case today.
3992
+
3993
+ if (n2.text !== n1.text) {
3994
+ updateTextContent(n2, renderer);
3995
+ }
3905
3996
  }
3997
+
3906
3998
  function mountComment(vnode, parent, anchor, renderer) {
3907
- const { owner } = vnode;
3908
- const { createComment } = renderer;
3909
- const commentNode = (vnode.elm = createComment(vnode.text));
3910
- linkNodeToShadow(commentNode, owner, renderer);
3911
- insertNode(commentNode, parent, anchor, renderer);
3999
+ const {
4000
+ owner
4001
+ } = vnode;
4002
+ const {
4003
+ createComment
4004
+ } = renderer;
4005
+ const commentNode = vnode.elm = createComment(vnode.text);
4006
+ linkNodeToShadow(commentNode, owner, renderer);
4007
+ insertNode(commentNode, parent, anchor, renderer);
3912
4008
  }
4009
+
3913
4010
  function mountElement(vnode, parent, anchor, renderer) {
3914
- const { sel, owner, data: { svg }, } = vnode;
3915
- const { createElement } = renderer;
3916
- const namespace = isTrue(svg) ? SVG_NAMESPACE : undefined;
3917
- const elm = (vnode.elm = createElement(sel, namespace));
3918
- linkNodeToShadow(elm, owner, renderer);
3919
- applyStyleScoping(elm, owner, renderer);
3920
- applyDomManual(elm, vnode);
3921
- applyElementRestrictions(elm, vnode);
3922
- patchElementPropsAndAttrs$1(null, vnode, renderer);
3923
- insertNode(elm, parent, anchor, renderer);
3924
- mountVNodes(vnode.children, elm, renderer, null);
4011
+ const {
4012
+ sel,
4013
+ owner,
4014
+ data: {
4015
+ svg
4016
+ }
4017
+ } = vnode;
4018
+ const {
4019
+ createElement
4020
+ } = renderer;
4021
+ const namespace = isTrue(svg) ? SVG_NAMESPACE : undefined;
4022
+ const elm = vnode.elm = createElement(sel, namespace);
4023
+ linkNodeToShadow(elm, owner, renderer);
4024
+ applyStyleScoping(elm, owner, renderer);
4025
+ applyDomManual(elm, vnode);
4026
+ applyElementRestrictions(elm, vnode);
4027
+ patchElementPropsAndAttrs$1(null, vnode, renderer);
4028
+ insertNode(elm, parent, anchor, renderer);
4029
+ mountVNodes(vnode.children, elm, renderer, null);
3925
4030
  }
4031
+
3926
4032
  function patchElement(n1, n2, renderer) {
3927
- const elm = (n2.elm = n1.elm);
3928
- patchElementPropsAndAttrs$1(n1, n2, renderer);
3929
- patchChildren(n1.children, n2.children, elm, renderer);
4033
+ const elm = n2.elm = n1.elm;
4034
+ patchElementPropsAndAttrs$1(n1, n2, renderer);
4035
+ patchChildren(n1.children, n2.children, elm, renderer);
3930
4036
  }
4037
+
3931
4038
  function mountStatic(vnode, parent, anchor, renderer) {
3932
- const { owner } = vnode;
3933
- const { cloneNode, isSyntheticShadowDefined } = renderer;
3934
- const elm = (vnode.elm = cloneNode(vnode.fragment, true));
3935
- linkNodeToShadow(elm, owner, renderer);
3936
- applyElementRestrictions(elm, vnode);
3937
- // Marks this node as Static to propagate the shadow resolver. must happen after elm is assigned to the proper shadow
3938
- const { renderMode, shadowMode } = owner;
3939
- if (isSyntheticShadowDefined) {
3940
- if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
3941
- elm[KEY__SHADOW_STATIC] = true;
3942
- }
4039
+ const {
4040
+ owner
4041
+ } = vnode;
4042
+ const {
4043
+ cloneNode,
4044
+ isSyntheticShadowDefined
4045
+ } = renderer;
4046
+ const elm = vnode.elm = cloneNode(vnode.fragment, true);
4047
+ linkNodeToShadow(elm, owner, renderer);
4048
+ applyElementRestrictions(elm, vnode); // Marks this node as Static to propagate the shadow resolver. must happen after elm is assigned to the proper shadow
4049
+
4050
+ const {
4051
+ renderMode,
4052
+ shadowMode
4053
+ } = owner;
4054
+
4055
+ if (isSyntheticShadowDefined) {
4056
+ if (shadowMode === 1
4057
+ /* ShadowMode.Synthetic */
4058
+ || renderMode === 0
4059
+ /* RenderMode.Light */
4060
+ ) {
4061
+ elm[KEY__SHADOW_STATIC] = true;
3943
4062
  }
3944
- insertNode(elm, parent, anchor, renderer);
4063
+ }
4064
+
4065
+ insertNode(elm, parent, anchor, renderer);
3945
4066
  }
4067
+
3946
4068
  function mountCustomElement(vnode, parent, anchor, renderer) {
3947
- const { sel, owner } = vnode;
3948
- const UpgradableConstructor = getUpgradableConstructor(sel, renderer);
3949
- /**
3950
- * Note: if the upgradable constructor does not expect, or throw when we new it
3951
- * with a callback as the first argument, we could implement a more advanced
3952
- * mechanism that only passes that argument if the constructor is known to be
3953
- * an upgradable custom element.
3954
- */
3955
- let vm;
3956
- const elm = new UpgradableConstructor((elm) => {
3957
- // the custom element from the registry is expecting an upgrade callback
3958
- vm = createViewModelHook(elm, vnode, renderer);
3959
- });
3960
- vnode.elm = elm;
3961
- vnode.vm = vm;
3962
- linkNodeToShadow(elm, owner, renderer);
3963
- applyStyleScoping(elm, owner, renderer);
3964
- if (vm) {
3965
- allocateChildren(vnode, vm);
3966
- }
3967
- else if (vnode.ctor !== UpgradableConstructor) {
3968
- throw new TypeError(`Incorrect Component Constructor`);
3969
- }
3970
- patchElementPropsAndAttrs$1(null, vnode, renderer);
3971
- insertNode(elm, parent, anchor, renderer);
3972
- if (vm) {
4069
+ const {
4070
+ sel,
4071
+ owner
4072
+ } = vnode;
4073
+ const UpgradableConstructor = getUpgradableConstructor(sel, renderer);
4074
+ /**
4075
+ * Note: if the upgradable constructor does not expect, or throw when we new it
4076
+ * with a callback as the first argument, we could implement a more advanced
4077
+ * mechanism that only passes that argument if the constructor is known to be
4078
+ * an upgradable custom element.
4079
+ */
4080
+
4081
+ let vm;
4082
+ const elm = new UpgradableConstructor(elm => {
4083
+ // the custom element from the registry is expecting an upgrade callback
4084
+ vm = createViewModelHook(elm, vnode, renderer);
4085
+ });
4086
+ vnode.elm = elm;
4087
+ vnode.vm = vm;
4088
+ linkNodeToShadow(elm, owner, renderer);
4089
+ applyStyleScoping(elm, owner, renderer);
4090
+
4091
+ if (vm) {
4092
+ allocateChildren(vnode, vm);
4093
+ } else if (vnode.ctor !== UpgradableConstructor) {
4094
+ throw new TypeError(`Incorrect Component Constructor`);
4095
+ }
4096
+
4097
+ patchElementPropsAndAttrs$1(null, vnode, renderer);
4098
+ insertNode(elm, parent, anchor, renderer);
4099
+
4100
+ if (vm) {
4101
+ {
4102
+ if (!lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3973
4103
  if (process.env.NODE_ENV !== 'production') {
3974
- assert.isTrue(vm.state === 0 /* VMState.created */, `${vm} cannot be recycled.`);
4104
+ // With synthetic lifecycle callbacks, it's possible for elements to be removed without the engine
4105
+ // noticing it (e.g. `appendChild` the same host element twice). This test ensures we don't regress.
4106
+ assert.isTrue(vm.state === 0
4107
+ /* VMState.created */
4108
+ , `${vm} cannot be recycled.`);
3975
4109
  }
4110
+
3976
4111
  runConnectedCallback(vm);
4112
+ }
3977
4113
  }
3978
- mountVNodes(vnode.children, elm, renderer, null);
3979
- if (vm) {
3980
- appendVM(vm);
3981
- }
4114
+ }
4115
+
4116
+ mountVNodes(vnode.children, elm, renderer, null);
4117
+
4118
+ if (vm) {
4119
+ appendVM(vm);
4120
+ }
3982
4121
  }
3983
- function patchCustomElement(n1, n2, renderer) {
3984
- const elm = (n2.elm = n1.elm);
3985
- const vm = (n2.vm = n1.vm);
4122
+
4123
+ function patchCustomElement(n1, n2, parent, renderer) {
4124
+ if (n1.ctor !== n2.ctor) {
4125
+ // If the constructor, unmount the current component and mount a new one using the new
4126
+ // constructor.
4127
+ const anchor = renderer.nextSibling(n1.elm);
4128
+ unmount(n1, parent, renderer, true);
4129
+ mountCustomElement(n2, parent, anchor, renderer);
4130
+ } else {
4131
+ // Otherwise patch the existing component with new props/attrs/etc.
4132
+ const elm = n2.elm = n1.elm;
4133
+ const vm = n2.vm = n1.vm;
3986
4134
  patchElementPropsAndAttrs$1(n1, n2, renderer);
4135
+
3987
4136
  if (!isUndefined$1(vm)) {
3988
- // in fallback mode, the allocation will always set children to
3989
- // empty and delegate the real allocation to the slot elements
3990
- allocateChildren(n2, vm);
3991
- }
3992
- // in fallback mode, the children will be always empty, so, nothing
4137
+ // in fallback mode, the allocation will always set children to
4138
+ // empty and delegate the real allocation to the slot elements
4139
+ allocateChildren(n2, vm);
4140
+ } // in fallback mode, the children will be always empty, so, nothing
3993
4141
  // will happen, but in native, it does allocate the light dom
4142
+
4143
+
3994
4144
  patchChildren(n1.children, n2.children, elm, renderer);
4145
+
3995
4146
  if (!isUndefined$1(vm)) {
3996
- // this will probably update the shadowRoot, but only if the vm is in a dirty state
3997
- // this is important to preserve the top to bottom synchronous rendering phase.
3998
- rerenderVM(vm);
4147
+ // this will probably update the shadowRoot, but only if the vm is in a dirty state
4148
+ // this is important to preserve the top to bottom synchronous rendering phase.
4149
+ rerenderVM(vm);
3999
4150
  }
4151
+ }
4000
4152
  }
4153
+
4001
4154
  function mountVNodes(vnodes, parent, renderer, anchor, start = 0, end = vnodes.length) {
4002
- for (; start < end; ++start) {
4003
- const vnode = vnodes[start];
4004
- if (isVNode(vnode)) {
4005
- mount(vnode, parent, renderer, anchor);
4006
- }
4155
+ for (; start < end; ++start) {
4156
+ const vnode = vnodes[start];
4157
+
4158
+ if (isVNode(vnode)) {
4159
+ mount(vnode, parent, renderer, anchor);
4007
4160
  }
4161
+ }
4008
4162
  }
4163
+
4009
4164
  function unmount(vnode, parent, renderer, doRemove = false) {
4010
- const { type, elm, sel } = vnode;
4011
- // When unmounting a VNode subtree not all the elements have to removed from the DOM. The
4012
- // subtree root, is the only element worth unmounting from the subtree.
4013
- if (doRemove) {
4014
- // The vnode might or might not have a data.renderer associated to it
4015
- // but the removal used here is from the owner instead.
4016
- removeNode(elm, parent, renderer);
4017
- }
4018
- switch (type) {
4019
- case 2 /* VNodeType.Element */: {
4020
- // Slot content is removed to trigger slotchange event when removing slot.
4021
- // Only required for synthetic shadow.
4022
- const shouldRemoveChildren = sel === 'slot' && vnode.owner.shadowMode === 1 /* ShadowMode.Synthetic */;
4023
- unmountVNodes(vnode.children, elm, renderer, shouldRemoveChildren);
4024
- break;
4025
- }
4026
- case 3 /* VNodeType.CustomElement */: {
4027
- const { vm } = vnode;
4028
- // No need to unmount the children here, `removeVM` will take care of removing the
4029
- // children.
4030
- if (!isUndefined$1(vm)) {
4031
- removeVM(vm);
4032
- }
4165
+ const {
4166
+ type,
4167
+ elm,
4168
+ sel
4169
+ } = vnode; // When unmounting a VNode subtree not all the elements have to removed from the DOM. The
4170
+ // subtree root, is the only element worth unmounting from the subtree.
4171
+
4172
+ if (doRemove) {
4173
+ // The vnode might or might not have a data.renderer associated to it
4174
+ // but the removal used here is from the owner instead.
4175
+ removeNode(elm, parent, renderer);
4176
+ }
4177
+
4178
+ switch (type) {
4179
+ case 2
4180
+ /* VNodeType.Element */
4181
+ :
4182
+ {
4183
+ // Slot content is removed to trigger slotchange event when removing slot.
4184
+ // Only required for synthetic shadow.
4185
+ const shouldRemoveChildren = sel === 'slot' && vnode.owner.shadowMode === 1
4186
+ /* ShadowMode.Synthetic */
4187
+ ;
4188
+ unmountVNodes(vnode.children, elm, renderer, shouldRemoveChildren);
4189
+ break;
4190
+ }
4191
+
4192
+ case 3
4193
+ /* VNodeType.CustomElement */
4194
+ :
4195
+ {
4196
+ const {
4197
+ vm
4198
+ } = vnode; // No need to unmount the children here, `removeVM` will take care of removing the
4199
+ // children.
4200
+
4201
+ if (!isUndefined$1(vm)) {
4202
+ removeVM(vm);
4033
4203
  }
4034
- }
4204
+ }
4205
+ }
4035
4206
  }
4207
+
4036
4208
  function unmountVNodes(vnodes, parent, renderer, doRemove = false, start = 0, end = vnodes.length) {
4037
- for (; start < end; ++start) {
4038
- const ch = vnodes[start];
4039
- if (isVNode(ch)) {
4040
- unmount(ch, parent, renderer, doRemove);
4041
- }
4209
+ for (; start < end; ++start) {
4210
+ const ch = vnodes[start];
4211
+
4212
+ if (isVNode(ch)) {
4213
+ unmount(ch, parent, renderer, doRemove);
4042
4214
  }
4215
+ }
4043
4216
  }
4217
+
4044
4218
  function isVNode(vnode) {
4045
- return vnode != null;
4219
+ return vnode != null;
4046
4220
  }
4221
+
4047
4222
  function linkNodeToShadow(elm, owner, renderer) {
4048
- const { renderRoot, renderMode, shadowMode } = owner;
4049
- const { isSyntheticShadowDefined } = renderer;
4050
- // TODO [#1164]: this should eventually be done by the polyfill directly
4051
- if (isSyntheticShadowDefined) {
4052
- if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
4053
- elm[KEY__SHADOW_RESOLVER] = renderRoot[KEY__SHADOW_RESOLVER];
4054
- }
4223
+ const {
4224
+ renderRoot,
4225
+ renderMode,
4226
+ shadowMode
4227
+ } = owner;
4228
+ const {
4229
+ isSyntheticShadowDefined
4230
+ } = renderer; // TODO [#1164]: this should eventually be done by the polyfill directly
4231
+
4232
+ if (isSyntheticShadowDefined) {
4233
+ if (shadowMode === 1
4234
+ /* ShadowMode.Synthetic */
4235
+ || renderMode === 0
4236
+ /* RenderMode.Light */
4237
+ ) {
4238
+ elm[KEY__SHADOW_RESOLVER] = renderRoot[KEY__SHADOW_RESOLVER];
4055
4239
  }
4240
+ }
4056
4241
  }
4242
+
4057
4243
  function updateTextContent(vnode, renderer) {
4058
- const { elm, text } = vnode;
4059
- const { setText } = renderer;
4060
- if (process.env.NODE_ENV !== 'production') {
4061
- unlockDomMutation();
4062
- }
4063
- setText(elm, text);
4064
- if (process.env.NODE_ENV !== 'production') {
4065
- lockDomMutation();
4066
- }
4244
+ const {
4245
+ elm,
4246
+ text
4247
+ } = vnode;
4248
+ const {
4249
+ setText
4250
+ } = renderer;
4251
+
4252
+ if (process.env.NODE_ENV !== 'production') {
4253
+ unlockDomMutation();
4254
+ }
4255
+
4256
+ setText(elm, text);
4257
+
4258
+ if (process.env.NODE_ENV !== 'production') {
4259
+ lockDomMutation();
4260
+ }
4067
4261
  }
4262
+
4068
4263
  function insertNode(node, parent, anchor, renderer) {
4069
- if (process.env.NODE_ENV !== 'production') {
4070
- unlockDomMutation();
4071
- }
4072
- renderer.insert(node, parent, anchor);
4073
- if (process.env.NODE_ENV !== 'production') {
4074
- lockDomMutation();
4075
- }
4264
+ if (process.env.NODE_ENV !== 'production') {
4265
+ unlockDomMutation();
4266
+ }
4267
+
4268
+ renderer.insert(node, parent, anchor);
4269
+
4270
+ if (process.env.NODE_ENV !== 'production') {
4271
+ lockDomMutation();
4272
+ }
4076
4273
  }
4274
+
4077
4275
  function removeNode(node, parent, renderer) {
4078
- if (process.env.NODE_ENV !== 'production') {
4079
- unlockDomMutation();
4080
- }
4081
- renderer.remove(node, parent);
4082
- if (process.env.NODE_ENV !== 'production') {
4083
- lockDomMutation();
4084
- }
4276
+ if (process.env.NODE_ENV !== 'production') {
4277
+ unlockDomMutation();
4278
+ }
4279
+
4280
+ renderer.remove(node, parent);
4281
+
4282
+ if (process.env.NODE_ENV !== 'production') {
4283
+ lockDomMutation();
4284
+ }
4085
4285
  }
4286
+
4086
4287
  function patchElementPropsAndAttrs$1(oldVnode, vnode, renderer) {
4087
- if (isNull(oldVnode)) {
4088
- applyEventListeners(vnode, renderer);
4089
- applyStaticClassAttribute(vnode, renderer);
4090
- applyStaticStyleAttribute(vnode, renderer);
4091
- }
4092
- // Attrs need to be applied to element before props IE11 will wipe out value on radio inputs if
4093
- // value is set before type=radio.
4094
- patchClassAttribute(oldVnode, vnode, renderer);
4095
- patchStyleAttribute(oldVnode, vnode, renderer);
4096
- patchAttributes(oldVnode, vnode, renderer);
4097
- patchProps(oldVnode, vnode, renderer);
4288
+ if (isNull(oldVnode)) {
4289
+ applyEventListeners(vnode, renderer);
4290
+ applyStaticClassAttribute(vnode, renderer);
4291
+ applyStaticStyleAttribute(vnode, renderer);
4292
+ } // Attrs need to be applied to element before props IE11 will wipe out value on radio inputs if
4293
+ // value is set before type=radio.
4294
+
4295
+
4296
+ patchClassAttribute(oldVnode, vnode, renderer);
4297
+ patchStyleAttribute(oldVnode, vnode, renderer);
4298
+ patchAttributes(oldVnode, vnode, renderer);
4299
+ patchProps(oldVnode, vnode, renderer);
4098
4300
  }
4301
+
4099
4302
  function applyStyleScoping(elm, owner, renderer) {
4100
- // Set the class name for `*.scoped.css` style scoping.
4101
- const scopeToken = getScopeTokenClass(owner);
4102
- if (!isNull(scopeToken)) {
4103
- const { getClassList } = renderer;
4104
- // TODO [#2762]: this dot notation with add is probably problematic
4105
- // probably we should have a renderer api for just the add operation
4106
- getClassList(elm).add(scopeToken);
4107
- }
4108
- // Set property element for synthetic shadow DOM style scoping.
4109
- const { stylesheetToken: syntheticToken } = owner.context;
4110
- if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && !isUndefined$1(syntheticToken)) {
4111
- elm.$shadowToken$ = syntheticToken;
4112
- }
4113
- }
4114
- function applyDomManual(elm, vnode) {
4115
- var _a;
4116
- const { owner, data: { context }, } = vnode;
4117
- if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && ((_a = context === null || context === void 0 ? void 0 : context.lwc) === null || _a === void 0 ? void 0 : _a.dom) === "manual" /* LwcDomMode.Manual */) {
4118
- elm.$domManual$ = true;
4119
- }
4120
- }
4121
- function applyElementRestrictions(elm, vnode) {
4122
- var _a, _b;
4123
- if (process.env.NODE_ENV !== 'production') {
4124
- const isPortal = vnode.type === 2 /* VNodeType.Element */ && ((_b = (_a = vnode.data.context) === null || _a === void 0 ? void 0 : _a.lwc) === null || _b === void 0 ? void 0 : _b.dom) === "manual" /* LwcDomMode.Manual */;
4125
- const isLight = vnode.owner.renderMode === 0 /* RenderMode.Light */;
4126
- patchElementWithRestrictions(elm, {
4127
- isPortal,
4128
- isLight,
4129
- });
4303
+ // Set the class name for `*.scoped.css` style scoping.
4304
+ const scopeToken = getScopeTokenClass(owner);
4305
+
4306
+ if (!isNull(scopeToken)) {
4307
+ const {
4308
+ getClassList
4309
+ } = renderer; // TODO [#2762]: this dot notation with add is probably problematic
4310
+ // probably we should have a renderer api for just the add operation
4311
+
4312
+ getClassList(elm).add(scopeToken);
4313
+ } // Set property element for synthetic shadow DOM style scoping.
4314
+
4315
+
4316
+ const {
4317
+ stylesheetToken: syntheticToken
4318
+ } = owner.context;
4319
+
4320
+ if (owner.shadowMode === 1
4321
+ /* ShadowMode.Synthetic */
4322
+ && !isUndefined$1(syntheticToken)) {
4323
+ elm.$shadowToken$ = syntheticToken;
4324
+ }
4325
+ }
4326
+
4327
+ function applyDomManual(elm, vnode) {
4328
+ var _a;
4329
+
4330
+ const {
4331
+ owner,
4332
+ data: {
4333
+ context
4130
4334
  }
4335
+ } = vnode;
4336
+
4337
+ if (owner.shadowMode === 1
4338
+ /* ShadowMode.Synthetic */
4339
+ && ((_a = context === null || context === void 0 ? void 0 : context.lwc) === null || _a === void 0 ? void 0 : _a.dom) === "manual"
4340
+ /* LwcDomMode.Manual */
4341
+ ) {
4342
+ elm.$domManual$ = true;
4343
+ }
4131
4344
  }
4345
+
4346
+ function applyElementRestrictions(elm, vnode) {
4347
+ var _a, _b;
4348
+
4349
+ if (process.env.NODE_ENV !== 'production') {
4350
+ const isPortal = vnode.type === 2
4351
+ /* VNodeType.Element */
4352
+ && ((_b = (_a = vnode.data.context) === null || _a === void 0 ? void 0 : _a.lwc) === null || _b === void 0 ? void 0 : _b.dom) === "manual"
4353
+ /* LwcDomMode.Manual */
4354
+ ;
4355
+ const isLight = vnode.owner.renderMode === 0
4356
+ /* RenderMode.Light */
4357
+ ;
4358
+ patchElementWithRestrictions(elm, {
4359
+ isPortal,
4360
+ isLight
4361
+ });
4362
+ }
4363
+ }
4364
+
4132
4365
  function allocateChildren(vnode, vm) {
4133
- // A component with slots will re-render because:
4134
- // 1- There is a change of the internal state.
4135
- // 2- There is a change on the external api (ex: slots)
4136
- //
4137
- // In case #1, the vnodes in the cmpSlots will be reused since they didn't changed. This routine emptied the
4138
- // slotted children when those VCustomElement were rendered and therefore in subsequent calls to allocate children
4139
- // in a reused VCustomElement, there won't be any slotted children.
4140
- // For those cases, we will use the reference for allocated children stored when rendering the fresh VCustomElement.
4141
- //
4142
- // In case #2, we will always get a fresh VCustomElement.
4143
- const children = vnode.aChildren || vnode.children;
4144
- vm.aChildren = children;
4145
- const { renderMode, shadowMode } = vm;
4146
- if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
4147
- // slow path
4148
- allocateInSlot(vm, children);
4149
- // save the allocated children in case this vnode is reused.
4150
- vnode.aChildren = children;
4151
- // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
4152
- vnode.children = EmptyArray;
4153
- }
4366
+ // A component with slots will re-render because:
4367
+ // 1- There is a change of the internal state.
4368
+ // 2- There is a change on the external api (ex: slots)
4369
+ //
4370
+ // In case #1, the vnodes in the cmpSlots will be reused since they didn't changed. This routine emptied the
4371
+ // slotted children when those VCustomElement were rendered and therefore in subsequent calls to allocate children
4372
+ // in a reused VCustomElement, there won't be any slotted children.
4373
+ // For those cases, we will use the reference for allocated children stored when rendering the fresh VCustomElement.
4374
+ //
4375
+ // In case #2, we will always get a fresh VCustomElement.
4376
+ const children = vnode.aChildren || vnode.children;
4377
+ vm.aChildren = children;
4378
+ const {
4379
+ renderMode,
4380
+ shadowMode
4381
+ } = vm;
4382
+
4383
+ if (shadowMode === 1
4384
+ /* ShadowMode.Synthetic */
4385
+ || renderMode === 0
4386
+ /* RenderMode.Light */
4387
+ ) {
4388
+ // slow path
4389
+ allocateInSlot(vm, children); // save the allocated children in case this vnode is reused.
4390
+
4391
+ vnode.aChildren = children; // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
4392
+
4393
+ vnode.children = EmptyArray;
4394
+ }
4154
4395
  }
4396
+
4155
4397
  function createViewModelHook(elm, vnode, renderer) {
4156
- let vm = getAssociatedVMIfPresent(elm);
4157
- // There is a possibility that a custom element is registered under tagName, in which case, the
4158
- // initialization is already carry on, and there is nothing else to do here since this hook is
4159
- // called right after invoking `document.createElement`.
4160
- if (!isUndefined$1(vm)) {
4161
- return vm;
4162
- }
4163
- const { sel, mode, ctor, owner } = vnode;
4164
- vm = createVM(elm, ctor, renderer, {
4165
- mode,
4166
- owner,
4167
- tagName: sel,
4168
- });
4169
- if (process.env.NODE_ENV !== 'production') {
4170
- assert.isTrue(isArray$1(vnode.children), `Invalid vnode for a custom element, it must have children defined.`);
4171
- }
4398
+ let vm = getAssociatedVMIfPresent(elm); // There is a possibility that a custom element is registered under tagName, in which case, the
4399
+ // initialization is already carry on, and there is nothing else to do here since this hook is
4400
+ // called right after invoking `document.createElement`.
4401
+
4402
+ if (!isUndefined$1(vm)) {
4172
4403
  return vm;
4404
+ }
4405
+
4406
+ const {
4407
+ sel,
4408
+ mode,
4409
+ ctor,
4410
+ owner
4411
+ } = vnode;
4412
+ vm = createVM(elm, ctor, renderer, {
4413
+ mode,
4414
+ owner,
4415
+ tagName: sel
4416
+ });
4417
+
4418
+ if (process.env.NODE_ENV !== 'production') {
4419
+ assert.isTrue(isArray$1(vnode.children), `Invalid vnode for a custom element, it must have children defined.`);
4420
+ }
4421
+
4422
+ return vm;
4173
4423
  }
4424
+
4174
4425
  function allocateInSlot(vm, children) {
4175
- var _a;
4176
- const { cmpSlots: oldSlots } = vm;
4177
- const cmpSlots = (vm.cmpSlots = create(null));
4178
- for (let i = 0, len = children.length; i < len; i += 1) {
4179
- const vnode = children[i];
4180
- if (isNull(vnode)) {
4181
- continue;
4182
- }
4183
- let slotName = '';
4184
- if (isVBaseElement(vnode)) {
4185
- slotName = ((_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) || '';
4186
- }
4187
- const vnodes = (cmpSlots[slotName] = cmpSlots[slotName] || []);
4188
- ArrayPush$1.call(vnodes, vnode);
4189
- }
4190
- if (isFalse(vm.isDirty)) {
4191
- // We need to determine if the old allocation is really different from the new one
4192
- // and mark the vm as dirty
4193
- const oldKeys = keys(oldSlots);
4194
- if (oldKeys.length !== keys(cmpSlots).length) {
4195
- markComponentAsDirty(vm);
4196
- return;
4197
- }
4198
- for (let i = 0, len = oldKeys.length; i < len; i += 1) {
4199
- const key = oldKeys[i];
4200
- if (isUndefined$1(cmpSlots[key]) || oldSlots[key].length !== cmpSlots[key].length) {
4201
- markComponentAsDirty(vm);
4202
- return;
4203
- }
4204
- const oldVNodes = oldSlots[key];
4205
- const vnodes = cmpSlots[key];
4206
- for (let j = 0, a = cmpSlots[key].length; j < a; j += 1) {
4207
- if (oldVNodes[j] !== vnodes[j]) {
4208
- markComponentAsDirty(vm);
4209
- return;
4210
- }
4211
- }
4426
+ var _a;
4427
+
4428
+ const {
4429
+ cmpSlots: oldSlots
4430
+ } = vm;
4431
+ const cmpSlots = vm.cmpSlots = create(null);
4432
+
4433
+ for (let i = 0, len = children.length; i < len; i += 1) {
4434
+ const vnode = children[i];
4435
+
4436
+ if (isNull(vnode)) {
4437
+ continue;
4438
+ }
4439
+
4440
+ let slotName = '';
4441
+
4442
+ if (isVBaseElement(vnode)) {
4443
+ slotName = ((_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) || '';
4444
+ }
4445
+
4446
+ const vnodes = cmpSlots[slotName] = cmpSlots[slotName] || [];
4447
+ ArrayPush$1.call(vnodes, vnode);
4448
+ }
4449
+
4450
+ if (isFalse(vm.isDirty)) {
4451
+ // We need to determine if the old allocation is really different from the new one
4452
+ // and mark the vm as dirty
4453
+ const oldKeys = keys(oldSlots);
4454
+
4455
+ if (oldKeys.length !== keys(cmpSlots).length) {
4456
+ markComponentAsDirty(vm);
4457
+ return;
4458
+ }
4459
+
4460
+ for (let i = 0, len = oldKeys.length; i < len; i += 1) {
4461
+ const key = oldKeys[i];
4462
+
4463
+ if (isUndefined$1(cmpSlots[key]) || oldSlots[key].length !== cmpSlots[key].length) {
4464
+ markComponentAsDirty(vm);
4465
+ return;
4466
+ }
4467
+
4468
+ const oldVNodes = oldSlots[key];
4469
+ const vnodes = cmpSlots[key];
4470
+
4471
+ for (let j = 0, a = cmpSlots[key].length; j < a; j += 1) {
4472
+ if (oldVNodes[j] !== vnodes[j]) {
4473
+ markComponentAsDirty(vm);
4474
+ return;
4212
4475
  }
4476
+ }
4213
4477
  }
4214
- }
4215
- // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
4216
- const FromIteration = new WeakMap();
4217
- // dynamic children means it was generated by an iteration
4478
+ }
4479
+ } // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
4480
+
4481
+
4482
+ const FromIteration = new WeakMap(); // dynamic children means it was generated by an iteration
4218
4483
  // in a template, and will require a more complex diffing algo.
4484
+
4219
4485
  function markAsDynamicChildren(children) {
4220
- FromIteration.set(children, 1);
4486
+ FromIteration.set(children, 1);
4221
4487
  }
4488
+
4222
4489
  function hasDynamicChildren(children) {
4223
- return FromIteration.has(children);
4490
+ return FromIteration.has(children);
4224
4491
  }
4492
+
4225
4493
  function createKeyToOldIdx(children, beginIdx, endIdx) {
4226
- const map = {};
4227
- // TODO [#1637]: simplify this by assuming that all vnodes has keys
4228
- for (let j = beginIdx; j <= endIdx; ++j) {
4229
- const ch = children[j];
4230
- if (isVNode(ch)) {
4231
- const { key } = ch;
4232
- if (key !== undefined) {
4233
- map[key] = j;
4234
- }
4235
- }
4494
+ const map = {}; // TODO [#1637]: simplify this by assuming that all vnodes has keys
4495
+
4496
+ for (let j = beginIdx; j <= endIdx; ++j) {
4497
+ const ch = children[j];
4498
+
4499
+ if (isVNode(ch)) {
4500
+ const {
4501
+ key
4502
+ } = ch;
4503
+
4504
+ if (key !== undefined) {
4505
+ map[key] = j;
4506
+ }
4236
4507
  }
4237
- return map;
4508
+ }
4509
+
4510
+ return map;
4238
4511
  }
4512
+
4239
4513
  function updateDynamicChildren(oldCh, newCh, parent, renderer) {
4240
- let oldStartIdx = 0;
4241
- let newStartIdx = 0;
4242
- let oldEndIdx = oldCh.length - 1;
4243
- let oldStartVnode = oldCh[0];
4244
- let oldEndVnode = oldCh[oldEndIdx];
4245
- const newChEnd = newCh.length - 1;
4246
- let newEndIdx = newChEnd;
4247
- let newStartVnode = newCh[0];
4248
- let newEndVnode = newCh[newEndIdx];
4249
- let oldKeyToIdx;
4250
- let idxInOld;
4251
- let elmToMove;
4252
- let before;
4253
- let clonedOldCh = false;
4254
- while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
4255
- if (!isVNode(oldStartVnode)) {
4256
- oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left
4257
- }
4258
- else if (!isVNode(oldEndVnode)) {
4259
- oldEndVnode = oldCh[--oldEndIdx];
4260
- }
4261
- else if (!isVNode(newStartVnode)) {
4262
- newStartVnode = newCh[++newStartIdx];
4263
- }
4264
- else if (!isVNode(newEndVnode)) {
4265
- newEndVnode = newCh[--newEndIdx];
4266
- }
4267
- else if (isSameVnode(oldStartVnode, newStartVnode)) {
4268
- patch(oldStartVnode, newStartVnode, renderer);
4269
- oldStartVnode = oldCh[++oldStartIdx];
4270
- newStartVnode = newCh[++newStartIdx];
4271
- }
4272
- else if (isSameVnode(oldEndVnode, newEndVnode)) {
4273
- patch(oldEndVnode, newEndVnode, renderer);
4274
- oldEndVnode = oldCh[--oldEndIdx];
4275
- newEndVnode = newCh[--newEndIdx];
4276
- }
4277
- else if (isSameVnode(oldStartVnode, newEndVnode)) {
4278
- // Vnode moved right
4279
- patch(oldStartVnode, newEndVnode, renderer);
4280
- insertNode(oldStartVnode.elm, parent, renderer.nextSibling(oldEndVnode.elm), renderer);
4281
- oldStartVnode = oldCh[++oldStartIdx];
4282
- newEndVnode = newCh[--newEndIdx];
4283
- }
4284
- else if (isSameVnode(oldEndVnode, newStartVnode)) {
4285
- // Vnode moved left
4286
- patch(oldEndVnode, newStartVnode, renderer);
4287
- insertNode(newStartVnode.elm, parent, oldStartVnode.elm, renderer);
4288
- oldEndVnode = oldCh[--oldEndIdx];
4289
- newStartVnode = newCh[++newStartIdx];
4290
- }
4291
- else {
4292
- if (oldKeyToIdx === undefined) {
4293
- oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
4294
- }
4295
- idxInOld = oldKeyToIdx[newStartVnode.key];
4296
- if (isUndefined$1(idxInOld)) {
4297
- // New element
4298
- mount(newStartVnode, parent, renderer, oldStartVnode.elm);
4299
- newStartVnode = newCh[++newStartIdx];
4300
- }
4301
- else {
4302
- elmToMove = oldCh[idxInOld];
4303
- if (isVNode(elmToMove)) {
4304
- if (elmToMove.sel !== newStartVnode.sel) {
4305
- // New element
4306
- mount(newStartVnode, parent, renderer, oldStartVnode.elm);
4307
- }
4308
- else {
4309
- patch(elmToMove, newStartVnode, renderer);
4310
- // Delete the old child, but copy the array since it is read-only.
4311
- // The `oldCh` will be GC'ed after `updateDynamicChildren` is complete,
4312
- // so we only care about the `oldCh` object inside this function.
4313
- // To avoid cloning over and over again, we check `clonedOldCh`
4314
- // and only clone once.
4315
- if (!clonedOldCh) {
4316
- clonedOldCh = true;
4317
- oldCh = [...oldCh];
4318
- }
4319
- // We've already cloned at least once, so it's no longer read-only
4320
- oldCh[idxInOld] = undefined;
4321
- insertNode(elmToMove.elm, parent, oldStartVnode.elm, renderer);
4322
- }
4323
- }
4324
- newStartVnode = newCh[++newStartIdx];
4325
- }
4514
+ let oldStartIdx = 0;
4515
+ let newStartIdx = 0;
4516
+ let oldEndIdx = oldCh.length - 1;
4517
+ let oldStartVnode = oldCh[0];
4518
+ let oldEndVnode = oldCh[oldEndIdx];
4519
+ const newChEnd = newCh.length - 1;
4520
+ let newEndIdx = newChEnd;
4521
+ let newStartVnode = newCh[0];
4522
+ let newEndVnode = newCh[newEndIdx];
4523
+ let oldKeyToIdx;
4524
+ let idxInOld;
4525
+ let elmToMove;
4526
+ let before;
4527
+ let clonedOldCh = false;
4528
+
4529
+ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
4530
+ if (!isVNode(oldStartVnode)) {
4531
+ oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left
4532
+ } else if (!isVNode(oldEndVnode)) {
4533
+ oldEndVnode = oldCh[--oldEndIdx];
4534
+ } else if (!isVNode(newStartVnode)) {
4535
+ newStartVnode = newCh[++newStartIdx];
4536
+ } else if (!isVNode(newEndVnode)) {
4537
+ newEndVnode = newCh[--newEndIdx];
4538
+ } else if (isSameVnode(oldStartVnode, newStartVnode)) {
4539
+ patch(oldStartVnode, newStartVnode, parent, renderer);
4540
+ oldStartVnode = oldCh[++oldStartIdx];
4541
+ newStartVnode = newCh[++newStartIdx];
4542
+ } else if (isSameVnode(oldEndVnode, newEndVnode)) {
4543
+ patch(oldEndVnode, newEndVnode, parent, renderer);
4544
+ oldEndVnode = oldCh[--oldEndIdx];
4545
+ newEndVnode = newCh[--newEndIdx];
4546
+ } else if (isSameVnode(oldStartVnode, newEndVnode)) {
4547
+ // Vnode moved right
4548
+ patch(oldStartVnode, newEndVnode, parent, renderer);
4549
+ insertNode(oldStartVnode.elm, parent, renderer.nextSibling(oldEndVnode.elm), renderer);
4550
+ oldStartVnode = oldCh[++oldStartIdx];
4551
+ newEndVnode = newCh[--newEndIdx];
4552
+ } else if (isSameVnode(oldEndVnode, newStartVnode)) {
4553
+ // Vnode moved left
4554
+ patch(oldEndVnode, newStartVnode, parent, renderer);
4555
+ insertNode(newStartVnode.elm, parent, oldStartVnode.elm, renderer);
4556
+ oldEndVnode = oldCh[--oldEndIdx];
4557
+ newStartVnode = newCh[++newStartIdx];
4558
+ } else {
4559
+ if (oldKeyToIdx === undefined) {
4560
+ oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
4561
+ }
4562
+
4563
+ idxInOld = oldKeyToIdx[newStartVnode.key];
4564
+
4565
+ if (isUndefined$1(idxInOld)) {
4566
+ // New element
4567
+ mount(newStartVnode, parent, renderer, oldStartVnode.elm);
4568
+ newStartVnode = newCh[++newStartIdx];
4569
+ } else {
4570
+ elmToMove = oldCh[idxInOld];
4571
+
4572
+ if (isVNode(elmToMove)) {
4573
+ if (elmToMove.sel !== newStartVnode.sel) {
4574
+ // New element
4575
+ mount(newStartVnode, parent, renderer, oldStartVnode.elm);
4576
+ } else {
4577
+ patch(elmToMove, newStartVnode, parent, renderer); // Delete the old child, but copy the array since it is read-only.
4578
+ // The `oldCh` will be GC'ed after `updateDynamicChildren` is complete,
4579
+ // so we only care about the `oldCh` object inside this function.
4580
+ // To avoid cloning over and over again, we check `clonedOldCh`
4581
+ // and only clone once.
4582
+
4583
+ if (!clonedOldCh) {
4584
+ clonedOldCh = true;
4585
+ oldCh = [...oldCh];
4586
+ } // We've already cloned at least once, so it's no longer read-only
4587
+
4588
+
4589
+ oldCh[idxInOld] = undefined;
4590
+ insertNode(elmToMove.elm, parent, oldStartVnode.elm, renderer);
4591
+ }
4326
4592
  }
4593
+
4594
+ newStartVnode = newCh[++newStartIdx];
4595
+ }
4327
4596
  }
4328
- if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
4329
- if (oldStartIdx > oldEndIdx) {
4330
- // There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
4331
- // already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
4332
- let i = newEndIdx;
4333
- let n;
4334
- do {
4335
- n = newCh[++i];
4336
- } while (!isVNode(n) && i < newChEnd);
4337
- before = isVNode(n) ? n.elm : null;
4338
- mountVNodes(newCh, parent, renderer, before, newStartIdx, newEndIdx + 1);
4339
- }
4340
- else {
4341
- unmountVNodes(oldCh, parent, renderer, true, oldStartIdx, oldEndIdx + 1);
4342
- }
4597
+ }
4598
+
4599
+ if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
4600
+ if (oldStartIdx > oldEndIdx) {
4601
+ // There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
4602
+ // already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
4603
+ let i = newEndIdx;
4604
+ let n;
4605
+
4606
+ do {
4607
+ n = newCh[++i];
4608
+ } while (!isVNode(n) && i < newChEnd);
4609
+
4610
+ before = isVNode(n) ? n.elm : null;
4611
+ mountVNodes(newCh, parent, renderer, before, newStartIdx, newEndIdx + 1);
4612
+ } else {
4613
+ unmountVNodes(oldCh, parent, renderer, true, oldStartIdx, oldEndIdx + 1);
4343
4614
  }
4615
+ }
4344
4616
  }
4617
+
4345
4618
  function updateStaticChildren(c1, c2, parent, renderer) {
4346
- const c1Length = c1.length;
4347
- const c2Length = c2.length;
4348
- if (c1Length === 0) {
4349
- // the old list is empty, we can directly insert anything new
4350
- mountVNodes(c2, parent, renderer, null);
4351
- return;
4352
- }
4353
- if (c2Length === 0) {
4354
- // the old list is nonempty and the new list is empty so we can directly remove all old nodes
4355
- // this is the case in which the dynamic children of an if-directive should be removed
4356
- unmountVNodes(c1, parent, renderer, true);
4357
- return;
4358
- }
4359
- // if the old list is not empty, the new list MUST have the same
4360
- // amount of nodes, that's why we call this static children
4361
- let anchor = null;
4362
- for (let i = c2Length - 1; i >= 0; i -= 1) {
4363
- const n1 = c1[i];
4364
- const n2 = c2[i];
4365
- if (n2 !== n1) {
4366
- if (isVNode(n1)) {
4367
- if (isVNode(n2)) {
4368
- // both vnodes are equivalent, and we just need to patch them
4369
- patch(n1, n2, renderer);
4370
- anchor = n2.elm;
4371
- }
4372
- else {
4373
- // removing the old vnode since the new one is null
4374
- unmount(n1, parent, renderer, true);
4375
- }
4376
- }
4377
- else if (isVNode(n2)) {
4378
- mount(n2, parent, renderer, anchor);
4379
- anchor = n2.elm;
4380
- }
4619
+ const c1Length = c1.length;
4620
+ const c2Length = c2.length;
4621
+
4622
+ if (c1Length === 0) {
4623
+ // the old list is empty, we can directly insert anything new
4624
+ mountVNodes(c2, parent, renderer, null);
4625
+ return;
4626
+ }
4627
+
4628
+ if (c2Length === 0) {
4629
+ // the old list is nonempty and the new list is empty so we can directly remove all old nodes
4630
+ // this is the case in which the dynamic children of an if-directive should be removed
4631
+ unmountVNodes(c1, parent, renderer, true);
4632
+ return;
4633
+ } // if the old list is not empty, the new list MUST have the same
4634
+ // amount of nodes, that's why we call this static children
4635
+
4636
+
4637
+ let anchor = null;
4638
+
4639
+ for (let i = c2Length - 1; i >= 0; i -= 1) {
4640
+ const n1 = c1[i];
4641
+ const n2 = c2[i];
4642
+
4643
+ if (n2 !== n1) {
4644
+ if (isVNode(n1)) {
4645
+ if (isVNode(n2)) {
4646
+ // both vnodes are equivalent, and we just need to patch them
4647
+ patch(n1, n2, parent, renderer);
4648
+ anchor = n2.elm;
4649
+ } else {
4650
+ // removing the old vnode since the new one is null
4651
+ unmount(n1, parent, renderer, true);
4381
4652
  }
4653
+ } else if (isVNode(n2)) {
4654
+ mount(n2, parent, renderer, anchor);
4655
+ anchor = n2.elm;
4656
+ }
4382
4657
  }
4658
+ }
4383
4659
  }
4384
4660
 
4385
4661
  /*
@@ -4700,13 +4976,6 @@ var LWC = (function (exports) {
4700
4976
  }
4701
4977
  return url;
4702
4978
  }
4703
- /**
4704
- * Map to store an index value assigned to any dynamic component reference ingested
4705
- * by dc() api. This allows us to generate a unique unique per template per dynamic
4706
- * component reference to avoid diffing algo mismatches.
4707
- */
4708
- const DynamicImportedComponentMap = new Map();
4709
- let dynamicImportedComponentCounter = 0;
4710
4979
  /**
4711
4980
  * create a dynamic component via `<x-foo lwc:dynamic={Ctor}>`
4712
4981
  */
@@ -4723,18 +4992,7 @@ var LWC = (function (exports) {
4723
4992
  if (!isComponentConstructor(Ctor)) {
4724
4993
  throw new Error(`Invalid LWC Constructor ${toString$1(Ctor)} for custom element <${sel}>.`);
4725
4994
  }
4726
- let idx = DynamicImportedComponentMap.get(Ctor);
4727
- if (isUndefined$1(idx)) {
4728
- idx = dynamicImportedComponentCounter++;
4729
- DynamicImportedComponentMap.set(Ctor, idx);
4730
- }
4731
- // the new vnode key is a mix of idx and compiler key, this is required by the diffing algo
4732
- // to identify different constructors as vnodes with different keys to avoid reusing the
4733
- // element used for previous constructors.
4734
- // Shallow clone is necessary here becuase VElementData may be shared across VNodes due to
4735
- // hoisting optimization.
4736
- const newData = Object.assign(Object.assign({}, data), { key: `dc:${idx}:${data.key}` });
4737
- return c(sel, Ctor, newData, children);
4995
+ return c(sel, Ctor, data, children);
4738
4996
  }
4739
4997
  /**
4740
4998
  * slow children collection marking mechanism. this API allows the compiler to signal
@@ -5460,7 +5718,7 @@ var LWC = (function (exports) {
5460
5718
  return `[object:vm ${def.name} (${vm.idx})]`;
5461
5719
  };
5462
5720
 
5463
- if (runtimeFlags.ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST) {
5721
+ if (lwcRuntimeFlags.ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST) {
5464
5722
  vm.shadowMode = 0
5465
5723
  /* ShadowMode.Native */
5466
5724
  ;
@@ -5499,7 +5757,7 @@ var LWC = (function (exports) {
5499
5757
  } else if (isNativeShadowDefined) {
5500
5758
  // Not combined with above condition because @lwc/features only supports identifiers in
5501
5759
  // the if-condition.
5502
- if (runtimeFlags.ENABLE_MIXED_SHADOW_MODE) {
5760
+ if (lwcRuntimeFlags.ENABLE_MIXED_SHADOW_MODE) {
5503
5761
  if (def.shadowSupportMode === "any"
5504
5762
  /* ShadowSupportMode.Any */
5505
5763
  ) {
@@ -5628,16 +5886,9 @@ var LWC = (function (exports) {
5628
5886
  const {
5629
5887
  def: {
5630
5888
  renderedCallback
5631
- },
5632
- renderer: {
5633
- ssr
5634
5889
  }
5635
5890
  } = vm;
5636
5891
 
5637
- if (isTrue(ssr)) {
5638
- return;
5639
- }
5640
-
5641
5892
  const {
5642
5893
  rendered
5643
5894
  } = Services;
@@ -5887,13 +6138,7 @@ var LWC = (function (exports) {
5887
6138
  vm.velements = EmptyArray;
5888
6139
  }
5889
6140
  function scheduleRehydration(vm) {
5890
- const {
5891
- renderer: {
5892
- ssr
5893
- }
5894
- } = vm;
5895
-
5896
- if (isTrue(ssr) || isTrue(vm.isScheduled)) {
6141
+ if (isTrue(vm.isScheduled)) {
5897
6142
  return;
5898
6143
  }
5899
6144
 
@@ -6000,15 +6245,8 @@ var LWC = (function (exports) {
6000
6245
  }
6001
6246
 
6002
6247
  function createFieldDataCallback(vm, name) {
6003
- const {
6004
- cmpFields
6005
- } = vm;
6006
6248
  return value => {
6007
- if (value !== vm.cmpFields[name]) {
6008
- // storing the value in the underlying storage
6009
- cmpFields[name] = value;
6010
- componentValueMutated(vm, name);
6011
- }
6249
+ updateComponentValue(vm, name, value);
6012
6250
  };
6013
6251
  }
6014
6252
 
@@ -6226,7 +6464,7 @@ var LWC = (function (exports) {
6226
6464
  ArrayPush$1.call(wiredConnecting, () => {
6227
6465
  connector.connect();
6228
6466
 
6229
- if (!runtimeFlags.ENABLE_WIRE_SYNC_EMIT) {
6467
+ if (!lwcRuntimeFlags.ENABLE_WIRE_SYNC_EMIT) {
6230
6468
  if (hasDynamicParams) {
6231
6469
  Promise.resolve().then(computeConfigAndUpdate);
6232
6470
  return;
@@ -6372,6 +6610,7 @@ var LWC = (function (exports) {
6372
6610
  }
6373
6611
  return renderer.nextSibling(hydratedNode);
6374
6612
  }
6613
+ const NODE_VALUE_PROP = 'nodeValue';
6375
6614
  function hydrateText(node, vnode, renderer) {
6376
6615
  var _a;
6377
6616
  if (!hasCorrectNodeType(vnode, node, 3 /* EnvNodeTypes.TEXT */, renderer)) {
@@ -6379,7 +6618,7 @@ var LWC = (function (exports) {
6379
6618
  }
6380
6619
  if (process.env.NODE_ENV !== 'production') {
6381
6620
  const { getProperty } = renderer;
6382
- const nodeValue = getProperty(node, 'nodeValue');
6621
+ const nodeValue = getProperty(node, NODE_VALUE_PROP);
6383
6622
  if (nodeValue !== vnode.text && !(nodeValue === '\u200D' && vnode.text === '')) {
6384
6623
  logWarn('Hydration mismatch: text values do not match, will recover from the difference', vnode.owner);
6385
6624
  }
@@ -6396,13 +6635,13 @@ var LWC = (function (exports) {
6396
6635
  }
6397
6636
  if (process.env.NODE_ENV !== 'production') {
6398
6637
  const { getProperty } = renderer;
6399
- const nodeValue = getProperty(node, 'nodeValue');
6638
+ const nodeValue = getProperty(node, NODE_VALUE_PROP);
6400
6639
  if (nodeValue !== vnode.text) {
6401
6640
  logWarn('Hydration mismatch: comment values do not match, will recover from the difference', vnode.owner);
6402
6641
  }
6403
6642
  }
6404
6643
  const { setProperty } = renderer;
6405
- setProperty(node, 'nodeValue', (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
6644
+ setProperty(node, NODE_VALUE_PROP, (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
6406
6645
  vnode.elm = node;
6407
6646
  return node;
6408
6647
  }
@@ -6670,13 +6909,13 @@ var LWC = (function (exports) {
6670
6909
  if (!hasCorrectNodeType(vnode, ssr, 3 /* EnvNodeTypes.TEXT */, renderer)) {
6671
6910
  return false;
6672
6911
  }
6673
- return getProperty(client, 'nodeValue') === getProperty(ssr, 'nodeValue');
6912
+ return getProperty(client, NODE_VALUE_PROP) === getProperty(ssr, NODE_VALUE_PROP);
6674
6913
  }
6675
6914
  if (getProperty(client, 'nodeType') === 8 /* EnvNodeTypes.COMMENT */) {
6676
6915
  if (!hasCorrectNodeType(vnode, ssr, 8 /* EnvNodeTypes.COMMENT */, renderer)) {
6677
6916
  return false;
6678
6917
  }
6679
- return getProperty(client, 'nodeValue') === getProperty(ssr, 'nodeValue');
6918
+ return getProperty(client, NODE_VALUE_PROP) === getProperty(ssr, NODE_VALUE_PROP);
6680
6919
  }
6681
6920
  if (!hasCorrectNodeType(vnode, ssr, 1 /* EnvNodeTypes.ELEMENT */, renderer)) {
6682
6921
  return false;
@@ -6832,7 +7071,7 @@ var LWC = (function (exports) {
6832
7071
  }
6833
7072
  return ctor;
6834
7073
  }
6835
- /* version: 2.22.0 */
7074
+ /* version: 2.23.2 */
6836
7075
 
6837
7076
  /*
6838
7077
  * Copyright (c) 2018, salesforce.com, inc.
@@ -6982,61 +7221,303 @@ var LWC = (function (exports) {
6982
7221
  * SPDX-License-Identifier: MIT
6983
7222
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6984
7223
  */
6985
- const SUPPORTS_TEMPLATE = typeof HTMLTemplateElement === 'function';
6986
- let createFragment;
6987
- if (SUPPORTS_TEMPLATE) {
6988
- // Parse the fragment HTML string into DOM
6989
- createFragment = function (html) {
6990
- const template = document.createElement('template');
6991
- template.innerHTML = html;
6992
- return template.content.firstChild;
6993
- };
6994
- }
6995
- else {
6996
- // In browsers that don't support <template> (e.g. IE11), we need to be careful to wrap elements like
6997
- // <td> in the proper container elements (e.g. <tbody>), because otherwise they will be parsed as null.
6998
- // Via https://github.com/webcomponents/polyfills/blob/ee1db33/packages/template/template.js#L273-L280
6999
- // With other elements added from:
7000
- // https://github.com/sindresorhus/html-tags/blob/95dcdd5/index.js
7001
- // Using the test:
7002
- // document.createRange().createContextualFragment(`<${tag}></${tag}>`).firstChild === null
7003
- // And omitting <html>, <head>, and <body> as these are not practical in an LWC component.
7004
- const topLevelWrappingMap = {
7005
- caption: ['table'],
7006
- col: ['colgroup', 'table'],
7007
- colgroup: ['table'],
7008
- option: ['select'],
7009
- tbody: ['table'],
7010
- td: ['tr', 'tbody', 'table'],
7011
- th: ['tr', 'tbody', 'table'],
7012
- thead: ['table'],
7013
- tfoot: ['table'],
7014
- tr: ['tbody', 'table'],
7015
- };
7016
- // Via https://github.com/webcomponents/polyfills/blob/ee1db33/packages/template/template.js#L282-L288
7017
- const getTagName = function (text) {
7018
- return (/<([a-z][^/\0>\x20\t\r\n\f]+)/i.exec(text) || ['', ''])[1].toLowerCase();
7019
- };
7020
- // Via https://github.com/webcomponents/polyfills/blob/ee1db33/packages/template/template.js#L295-L320
7021
- createFragment = function (html) {
7022
- const wrapperTags = topLevelWrappingMap[getTagName(html)];
7023
- if (!isUndefined$1(wrapperTags)) {
7024
- for (const wrapperTag of wrapperTags) {
7025
- html = `<${wrapperTag}>${html}</${wrapperTag}>`;
7224
+ /**
7225
+ * A factory function that produces a renderer.
7226
+ * Renderer encapsulates operations that are required to render an LWC component into the underlying
7227
+ * runtime environment. In the case of @lwc/enigne-dom, it is meant to be used in a DOM environment.
7228
+ * Example usage:
7229
+ * import { renderer, rendererFactory } from 'lwc';
7230
+ * const customRenderer = rendererFactory(renderer);
7231
+ *
7232
+ * @param baseRenderer Either null or the base renderer imported from 'lwc'.
7233
+ */
7234
+ function rendererFactory(baseRenderer) {
7235
+ // Util functions
7236
+ function assertInvariant(value, msg) {
7237
+ if (!value) {
7238
+ throw new Error(`Invariant Violation: ${msg}`);
7239
+ }
7240
+ }
7241
+ function isNull(obj) {
7242
+ return obj === null;
7243
+ }
7244
+ function isUndefined(obj) {
7245
+ return obj === undefined;
7246
+ }
7247
+ let getCustomElement;
7248
+ let defineCustomElement;
7249
+ let HTMLElementConstructor;
7250
+ function isCustomElementRegistryAvailable() {
7251
+ if (typeof customElements === 'undefined') {
7252
+ return false;
7253
+ }
7254
+ try {
7255
+ // dereference HTMLElement global because babel wraps globals in compat mode with a
7256
+ // _wrapNativeSuper()
7257
+ // This is a problem because LWCUpgradableElement extends renderer.HTMLElementExported which does not
7258
+ // get wrapped by babel.
7259
+ const HTMLElementAlias = HTMLElement;
7260
+ // In case we use compat mode with a modern browser, the compat mode transformation
7261
+ // invokes the DOM api with an .apply() or .call() to initialize any DOM api sub-classing,
7262
+ // which are not equipped to be initialized that way.
7263
+ class clazz extends HTMLElementAlias {
7026
7264
  }
7265
+ customElements.define('lwc-test-' + Math.floor(Math.random() * 1000000), clazz);
7266
+ new clazz();
7267
+ return true;
7268
+ }
7269
+ catch (_a) {
7270
+ return false;
7027
7271
  }
7028
- // For IE11, the document title must not be undefined, but it can be an empty string
7029
- // https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createHTMLDocument#browser_compatibility
7030
- const doc = document.implementation.createHTMLDocument('');
7031
- doc.body.innerHTML = html;
7032
- let content = doc.body;
7033
- if (!isUndefined$1(wrapperTags)) {
7034
- for (let i = 0; i < wrapperTags.length; i++) {
7035
- content = content.firstChild;
7272
+ }
7273
+ if (isCustomElementRegistryAvailable()) {
7274
+ getCustomElement = customElements.get.bind(customElements);
7275
+ defineCustomElement = customElements.define.bind(customElements);
7276
+ HTMLElementConstructor = HTMLElement;
7277
+ }
7278
+ else {
7279
+ const registry = Object.create(null);
7280
+ const reverseRegistry = new WeakMap();
7281
+ defineCustomElement = function define(name, ctor) {
7282
+ if (name !== String.prototype.toLowerCase.call(name) || registry[name]) {
7283
+ throw new TypeError(`Invalid Registration`);
7284
+ }
7285
+ registry[name] = ctor;
7286
+ reverseRegistry.set(ctor, name);
7287
+ };
7288
+ getCustomElement = function get(name) {
7289
+ return registry[name];
7290
+ };
7291
+ HTMLElementConstructor = function HTMLElement() {
7292
+ if (!(this instanceof HTMLElement)) {
7293
+ throw new TypeError(`Invalid Invocation`);
7294
+ }
7295
+ const { constructor } = this;
7296
+ const name = reverseRegistry.get(constructor);
7297
+ if (!name) {
7298
+ throw new TypeError(`Invalid Construction`);
7299
+ }
7300
+ const elm = document.createElement(name);
7301
+ Object.setPrototypeOf(elm, constructor.prototype);
7302
+ return elm;
7303
+ };
7304
+ HTMLElementConstructor.prototype = HTMLElement.prototype;
7305
+ }
7306
+ function cloneNode(node, deep) {
7307
+ return node.cloneNode(deep);
7308
+ }
7309
+ function createElement(tagName, namespace) {
7310
+ return isUndefined(namespace)
7311
+ ? document.createElement(tagName)
7312
+ : document.createElementNS(namespace, tagName);
7313
+ }
7314
+ function createText(content) {
7315
+ return document.createTextNode(content);
7316
+ }
7317
+ function createComment(content) {
7318
+ return document.createComment(content);
7319
+ }
7320
+ let createFragment;
7321
+ // IE11 lacks support for this feature
7322
+ const SUPPORTS_TEMPLATE = typeof HTMLTemplateElement === 'function';
7323
+ if (SUPPORTS_TEMPLATE) {
7324
+ // Parse the fragment HTML string into DOM
7325
+ createFragment = function (html) {
7326
+ const template = document.createElement('template');
7327
+ template.innerHTML = html;
7328
+ return template.content.firstChild;
7329
+ };
7330
+ }
7331
+ else {
7332
+ // In browsers that don't support <template> (e.g. IE11), we need to be careful to wrap elements like
7333
+ // <td> in the proper container elements (e.g. <tbody>), because otherwise they will be parsed as null.
7334
+ // Via https://github.com/webcomponents/polyfills/blob/ee1db33/packages/template/template.js#L273-L280
7335
+ // With other elements added from:
7336
+ // https://github.com/sindresorhus/html-tags/blob/95dcdd5/index.js
7337
+ // Using the test:
7338
+ // document.createRange().createContextualFragment(`<${tag}></${tag}>`).firstChild === null
7339
+ // And omitting <html>, <head>, and <body> as these are not practical in an LWC component.
7340
+ const topLevelWrappingMap = {
7341
+ caption: ['table'],
7342
+ col: ['colgroup', 'table'],
7343
+ colgroup: ['table'],
7344
+ option: ['select'],
7345
+ tbody: ['table'],
7346
+ td: ['tr', 'tbody', 'table'],
7347
+ th: ['tr', 'tbody', 'table'],
7348
+ thead: ['table'],
7349
+ tfoot: ['table'],
7350
+ tr: ['tbody', 'table'],
7351
+ };
7352
+ // Via https://github.com/webcomponents/polyfills/blob/ee1db33/packages/template/template.js#L282-L288
7353
+ const getTagName = function (text) {
7354
+ return (/<([a-z][^/\0>\x20\t\r\n\f]+)/i.exec(text) || ['', ''])[1].toLowerCase();
7355
+ };
7356
+ // Via https://github.com/webcomponents/polyfills/blob/ee1db33/packages/template/template.js#L295-L320
7357
+ createFragment = function (html) {
7358
+ const wrapperTags = topLevelWrappingMap[getTagName(html)];
7359
+ if (!isUndefined(wrapperTags)) {
7360
+ for (const wrapperTag of wrapperTags) {
7361
+ html = `<${wrapperTag}>${html}</${wrapperTag}>`;
7362
+ }
7036
7363
  }
7364
+ // For IE11, the document title must not be undefined, but it can be an empty string
7365
+ // https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createHTMLDocument#browser_compatibility
7366
+ const doc = document.implementation.createHTMLDocument('');
7367
+ doc.body.innerHTML = html;
7368
+ let content = doc.body;
7369
+ if (!isUndefined(wrapperTags)) {
7370
+ for (let i = 0; i < wrapperTags.length; i++) {
7371
+ content = content.firstChild;
7372
+ }
7373
+ }
7374
+ return content.firstChild;
7375
+ };
7376
+ }
7377
+ function insert(node, parent, anchor) {
7378
+ parent.insertBefore(node, anchor);
7379
+ }
7380
+ function remove(node, parent) {
7381
+ parent.removeChild(node);
7382
+ }
7383
+ function nextSibling(node) {
7384
+ return node.nextSibling;
7385
+ }
7386
+ function attachShadow(element, options) {
7387
+ // `shadowRoot` will be non-null in two cases:
7388
+ // 1. upon initial load with an SSR-generated DOM, while in Shadow render mode
7389
+ // 2. when a webapp author places <c-app> in their static HTML and mounts their
7390
+ // root component with customElement.define('c-app', Ctor)
7391
+ if (!isNull(element.shadowRoot)) {
7392
+ return element.shadowRoot;
7393
+ }
7394
+ return element.attachShadow(options);
7395
+ }
7396
+ function setText(node, content) {
7397
+ node.nodeValue = content;
7398
+ }
7399
+ function getProperty(node, key) {
7400
+ return node[key];
7401
+ }
7402
+ function setProperty(node, key, value) {
7403
+ node[key] = value;
7404
+ }
7405
+ function getAttribute(element, name, namespace) {
7406
+ return isUndefined(namespace)
7407
+ ? element.getAttribute(name)
7408
+ : element.getAttributeNS(namespace, name);
7409
+ }
7410
+ function setAttribute(element, name, value, namespace) {
7411
+ return isUndefined(namespace)
7412
+ ? element.setAttribute(name, value)
7413
+ : element.setAttributeNS(namespace, name, value);
7414
+ }
7415
+ function removeAttribute(element, name, namespace) {
7416
+ if (isUndefined(namespace)) {
7417
+ element.removeAttribute(name);
7037
7418
  }
7038
- return content.firstChild;
7419
+ else {
7420
+ element.removeAttributeNS(namespace, name);
7421
+ }
7422
+ }
7423
+ function addEventListener(target, type, callback, options) {
7424
+ target.addEventListener(type, callback, options);
7425
+ }
7426
+ function removeEventListener(target, type, callback, options) {
7427
+ target.removeEventListener(type, callback, options);
7428
+ }
7429
+ function dispatchEvent(target, event) {
7430
+ return target.dispatchEvent(event);
7431
+ }
7432
+ function getClassList(element) {
7433
+ return element.classList;
7434
+ }
7435
+ function setCSSStyleProperty(element, name, value, important) {
7436
+ // TODO [#0]: How to avoid this type casting? Shall we use a different type interface to
7437
+ // represent elements in the engine?
7438
+ element.style.setProperty(name, value, important ? 'important' : '');
7439
+ }
7440
+ function getBoundingClientRect(element) {
7441
+ return element.getBoundingClientRect();
7442
+ }
7443
+ function querySelector(element, selectors) {
7444
+ return element.querySelector(selectors);
7445
+ }
7446
+ function querySelectorAll(element, selectors) {
7447
+ return element.querySelectorAll(selectors);
7448
+ }
7449
+ function getElementsByTagName(element, tagNameOrWildCard) {
7450
+ return element.getElementsByTagName(tagNameOrWildCard);
7451
+ }
7452
+ function getElementsByClassName(element, names) {
7453
+ return element.getElementsByClassName(names);
7454
+ }
7455
+ function getChildren(element) {
7456
+ return element.children;
7457
+ }
7458
+ function getChildNodes(element) {
7459
+ return element.childNodes;
7460
+ }
7461
+ function getFirstChild(element) {
7462
+ return element.firstChild;
7463
+ }
7464
+ function getFirstElementChild(element) {
7465
+ return element.firstElementChild;
7466
+ }
7467
+ function getLastChild(element) {
7468
+ return element.lastChild;
7469
+ }
7470
+ function getLastElementChild(element) {
7471
+ return element.lastElementChild;
7472
+ }
7473
+ function isConnected(node) {
7474
+ return node.isConnected;
7475
+ }
7476
+ function assertInstanceOfHTMLElement(elm, msg) {
7477
+ assertInvariant(elm instanceof HTMLElement, msg);
7478
+ }
7479
+ const HTMLElementExported = HTMLElementConstructor;
7480
+ const renderer = {
7481
+ HTMLElementExported,
7482
+ insert,
7483
+ remove,
7484
+ cloneNode,
7485
+ createFragment,
7486
+ createElement,
7487
+ createText,
7488
+ createComment,
7489
+ nextSibling,
7490
+ attachShadow,
7491
+ getProperty,
7492
+ setProperty,
7493
+ setText,
7494
+ getAttribute,
7495
+ setAttribute,
7496
+ removeAttribute,
7497
+ addEventListener,
7498
+ removeEventListener,
7499
+ dispatchEvent,
7500
+ getClassList,
7501
+ setCSSStyleProperty,
7502
+ getBoundingClientRect,
7503
+ querySelector,
7504
+ querySelectorAll,
7505
+ getElementsByTagName,
7506
+ getElementsByClassName,
7507
+ getChildren,
7508
+ getChildNodes,
7509
+ getFirstChild,
7510
+ getFirstElementChild,
7511
+ getLastChild,
7512
+ getLastElementChild,
7513
+ isConnected,
7514
+ assertInstanceOfHTMLElement,
7515
+ defineCustomElement,
7516
+ getCustomElement,
7039
7517
  };
7518
+ // Meant to inherit any properties passed via the base renderer as the argument to the factory.
7519
+ Object.setPrototypeOf(renderer, baseRenderer);
7520
+ return renderer;
7040
7521
  }
7041
7522
 
7042
7523
  /*
@@ -7045,245 +7526,21 @@ var LWC = (function (exports) {
7045
7526
  * SPDX-License-Identifier: MIT
7046
7527
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7047
7528
  */
7048
- let getCustomElement;
7049
- let defineCustomElement;
7050
- let HTMLElementConstructor;
7051
- function isCustomElementRegistryAvailable() {
7052
- if (typeof customElements === 'undefined') {
7053
- return false;
7054
- }
7055
- try {
7056
- // dereference HTMLElement global because babel wraps globals in compat mode with a
7057
- // _wrapNativeSuper()
7058
- // This is a problem because LWCUpgradableElement extends renderer.HTMLElementExported which does not
7059
- // get wrapped by babel.
7060
- const HTMLElementAlias = HTMLElement;
7061
- // In case we use compat mode with a modern browser, the compat mode transformation
7062
- // invokes the DOM api with an .apply() or .call() to initialize any DOM api sub-classing,
7063
- // which are not equipped to be initialized that way.
7064
- class clazz extends HTMLElementAlias {
7065
- }
7066
- customElements.define('lwc-test-' + Math.floor(Math.random() * 1000000), clazz);
7067
- new clazz();
7068
- return true;
7069
- }
7070
- catch (_a) {
7071
- return false;
7072
- }
7073
- }
7074
- if (isCustomElementRegistryAvailable()) {
7075
- getCustomElement = customElements.get.bind(customElements);
7076
- defineCustomElement = customElements.define.bind(customElements);
7077
- HTMLElementConstructor = HTMLElement;
7078
- }
7079
- else {
7080
- const registry = create(null);
7081
- const reverseRegistry = new WeakMap();
7082
- defineCustomElement = function define(name, ctor) {
7083
- if (name !== StringToLowerCase.call(name) || registry[name]) {
7084
- throw new TypeError(`Invalid Registration`);
7085
- }
7086
- registry[name] = ctor;
7087
- reverseRegistry.set(ctor, name);
7088
- };
7089
- getCustomElement = function get(name) {
7090
- return registry[name];
7091
- };
7092
- HTMLElementConstructor = function HTMLElement() {
7093
- if (!(this instanceof HTMLElement)) {
7094
- throw new TypeError(`Invalid Invocation`);
7095
- }
7096
- const { constructor } = this;
7097
- const name = reverseRegistry.get(constructor);
7098
- if (!name) {
7099
- throw new TypeError(`Invalid Construction`);
7100
- }
7101
- const elm = document.createElement(name);
7102
- setPrototypeOf(elm, constructor.prototype);
7103
- return elm;
7104
- };
7105
- HTMLElementConstructor.prototype = HTMLElement.prototype;
7106
- }
7107
- let hydrating = false;
7108
- function setIsHydrating(value) {
7109
- hydrating = value;
7110
- }
7111
- const ssr = false;
7112
- function isHydrating() {
7113
- return hydrating;
7114
- }
7115
- const isNativeShadowDefined = _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED];
7116
- const isSyntheticShadowDefined = hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN);
7117
- function cloneNode(node, deep) {
7118
- return node.cloneNode(deep);
7119
- }
7120
- function createElement$1(tagName, namespace) {
7121
- return isUndefined$1(namespace)
7122
- ? document.createElement(tagName)
7123
- : document.createElementNS(namespace, tagName);
7124
- }
7125
- function createText(content) {
7126
- return document.createTextNode(content);
7127
- }
7128
- function createComment(content) {
7129
- return document.createComment(content);
7130
- }
7131
- function insert(node, parent, anchor) {
7132
- parent.insertBefore(node, anchor);
7133
- }
7134
- function remove(node, parent) {
7135
- parent.removeChild(node);
7136
- }
7137
- function nextSibling(node) {
7138
- return node.nextSibling;
7139
- }
7140
- function attachShadow(element, options) {
7141
- // `hydrating` will be true in two cases:
7142
- // 1. upon initial load with an SSR-generated DOM, while in Shadow render mode
7143
- // 2. when a webapp author places <c-app> in their static HTML and mounts their
7144
- // root component with customeElement.define('c-app', Ctor)
7145
- //
7146
- // The second case can be treated as a failed hydration with nominal impact
7147
- // to performance. However, because <c-app> won't have a <template shadowroot>
7148
- // declarative child, `element.shadowRoot` is `null`.
7149
- if (hydrating && element.shadowRoot) {
7150
- return element.shadowRoot;
7151
- }
7152
- return element.attachShadow(options);
7153
- }
7154
- function setText(node, content) {
7155
- node.nodeValue = content;
7156
- }
7157
- function getProperty(node, key) {
7158
- return node[key];
7159
- }
7160
- function setProperty(node, key, value) {
7161
- if (process.env.NODE_ENV !== 'production') {
7162
- if (node instanceof Element && !(key in node)) {
7163
- // TODO [#1297]: Move this validation to the compiler
7164
- assert.fail(`Unknown public property "${key}" of element <${node.tagName}>. This is likely a typo on the corresponding attribute "${htmlPropertyToAttribute(key)}".`);
7165
- }
7166
- }
7167
- node[key] = value;
7168
- }
7169
- function getAttribute(element, name, namespace) {
7170
- return isUndefined$1(namespace)
7171
- ? element.getAttribute(name)
7172
- : element.getAttributeNS(namespace, name);
7173
- }
7174
- function setAttribute(element, name, value, namespace) {
7175
- return isUndefined$1(namespace)
7176
- ? element.setAttribute(name, value)
7177
- : element.setAttributeNS(namespace, name, value);
7178
- }
7179
- function removeAttribute(element, name, namespace) {
7180
- if (isUndefined$1(namespace)) {
7181
- element.removeAttribute(name);
7182
- }
7183
- else {
7184
- element.removeAttributeNS(namespace, name);
7185
- }
7186
- }
7187
- function addEventListener(target, type, callback, options) {
7188
- target.addEventListener(type, callback, options);
7189
- }
7190
- function removeEventListener(target, type, callback, options) {
7191
- target.removeEventListener(type, callback, options);
7192
- }
7193
- function dispatchEvent(target, event) {
7194
- return target.dispatchEvent(event);
7195
- }
7196
- function getClassList(element) {
7197
- return element.classList;
7198
- }
7199
- function setCSSStyleProperty(element, name, value, important) {
7200
- // TODO [#0]: How to avoid this type casting? Shall we use a different type interface to
7201
- // represent elements in the engine?
7202
- element.style.setProperty(name, value, important ? 'important' : '');
7203
- }
7204
- function getBoundingClientRect(element) {
7205
- return element.getBoundingClientRect();
7206
- }
7207
- function querySelector(element, selectors) {
7208
- return element.querySelector(selectors);
7209
- }
7210
- function querySelectorAll(element, selectors) {
7211
- return element.querySelectorAll(selectors);
7212
- }
7213
- function getElementsByTagName(element, tagNameOrWildCard) {
7214
- return element.getElementsByTagName(tagNameOrWildCard);
7215
- }
7216
- function getElementsByClassName(element, names) {
7217
- return element.getElementsByClassName(names);
7218
- }
7219
- function getChildren(element) {
7220
- return element.children;
7221
- }
7222
- function getChildNodes(element) {
7223
- return element.childNodes;
7224
- }
7225
- function getFirstChild(element) {
7226
- return element.firstChild;
7227
- }
7228
- function getFirstElementChild(element) {
7229
- return element.firstElementChild;
7230
- }
7231
- function getLastChild(element) {
7232
- return element.lastChild;
7233
- }
7234
- function getLastElementChild(element) {
7235
- return element.lastElementChild;
7236
- }
7237
- function isConnected(node) {
7238
- return node.isConnected;
7239
- }
7240
- function assertInstanceOfHTMLElement(elm, msg) {
7241
- assert.invariant(elm instanceof HTMLElement, msg);
7242
- }
7243
- const HTMLElementExported = HTMLElementConstructor;
7244
- const renderer = {
7245
- ssr,
7246
- isNativeShadowDefined,
7247
- isSyntheticShadowDefined,
7248
- HTMLElementExported,
7249
- isHydrating,
7250
- insert,
7251
- remove,
7252
- cloneNode,
7253
- createFragment,
7254
- createElement: createElement$1,
7255
- createText,
7256
- createComment,
7257
- nextSibling,
7258
- attachShadow,
7259
- getProperty,
7260
- setProperty,
7261
- setText,
7262
- getAttribute,
7263
- setAttribute,
7264
- removeAttribute,
7265
- addEventListener,
7266
- removeEventListener,
7267
- dispatchEvent,
7268
- getClassList,
7269
- setCSSStyleProperty,
7270
- getBoundingClientRect,
7271
- querySelector,
7272
- querySelectorAll,
7273
- getElementsByTagName,
7274
- getElementsByClassName,
7275
- getChildren,
7276
- getChildNodes,
7277
- getFirstChild,
7278
- getFirstElementChild,
7279
- getLastChild,
7280
- getLastElementChild,
7281
- isConnected,
7529
+ /**
7530
+ * The base renderer that will be used by engine-core.
7531
+ * This will be used for DOM operations when lwc is running in a browser environment.
7532
+ */
7533
+ const renderer = assign(
7534
+ // The base renderer will invoke the factory with null and assign additional properties that are
7535
+ // shared across renderers
7536
+ rendererFactory(null),
7537
+ // Properties that are either not required to be sandboxed or rely on a globally shared information
7538
+ {
7539
+ // insertStyleSheet implementation shares a global cache of stylesheet data
7282
7540
  insertStylesheet,
7283
- assertInstanceOfHTMLElement,
7284
- defineCustomElement,
7285
- getCustomElement,
7286
- };
7541
+ isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
7542
+ isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
7543
+ });
7287
7544
 
7288
7545
  /*
7289
7546
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7332,13 +7589,8 @@ var LWC = (function (exports) {
7332
7589
  return;
7333
7590
  }
7334
7591
  try {
7335
- // Let the renderer know we are hydrating, so it does not replace the existing shadowRoot
7336
- // and uses the same algo to create the stylesheets as in SSR.
7337
- setIsHydrating(true);
7338
7592
  const vm = createVMWithProps(element, Ctor, props);
7339
7593
  hydrateRoot(vm);
7340
- // set it back since now we finished hydration.
7341
- setIsHydrating(false);
7342
7594
  }
7343
7595
  catch (e) {
7344
7596
  // Fallback: In case there's an error while hydrating, let's log the error, and replace the element content
@@ -7349,13 +7601,8 @@ var LWC = (function (exports) {
7349
7601
  resetShadowRootAndLightDom(element, Ctor);
7350
7602
  // we need to recreate the vm with the hydration flag on, so it re-uses the existing shadowRoot.
7351
7603
  createVMWithProps(element, Ctor, props);
7352
- setIsHydrating(false);
7353
7604
  connectRootElement(element);
7354
7605
  }
7355
- finally {
7356
- // in case there's an error during recovery
7357
- setIsHydrating(false);
7358
- }
7359
7606
  }
7360
7607
 
7361
7608
  /*
@@ -7429,44 +7676,60 @@ var LWC = (function (exports) {
7429
7676
  * SPDX-License-Identifier: MIT
7430
7677
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7431
7678
  */
7432
- // TODO [#2472]: Remove this workaround when appropriate.
7433
7679
  // eslint-disable-next-line @lwc/lwc-internal/no-global-node
7680
+
7434
7681
  const _Node$1 = Node;
7435
7682
  const ConnectingSlot = new WeakMap();
7436
7683
  const DisconnectingSlot = new WeakMap();
7684
+
7437
7685
  function callNodeSlot(node, slot) {
7438
- if (process.env.NODE_ENV !== 'production') {
7439
- assert.isTrue(node, `callNodeSlot() should not be called for a non-object`);
7440
- }
7441
- const fn = slot.get(node);
7442
- if (!isUndefined$1(fn)) {
7443
- fn(node);
7444
- }
7445
- return node; // for convenience
7686
+ if (process.env.NODE_ENV !== 'production') {
7687
+ assert.isTrue(node, `callNodeSlot() should not be called for a non-object`);
7688
+ }
7689
+
7690
+ const fn = slot.get(node);
7691
+
7692
+ if (!isUndefined$1(fn)) {
7693
+ fn(node);
7694
+ }
7695
+
7696
+ return node; // for convenience
7446
7697
  }
7447
- // Monkey patching Node methods to be able to detect the insertions and removal of root elements
7448
- // created via createElement.
7449
- const { appendChild, insertBefore, removeChild, replaceChild } = _Node$1.prototype;
7450
- assign(_Node$1.prototype, {
7698
+
7699
+ if (!lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
7700
+ // Monkey patching Node methods to be able to detect the insertions and removal of root elements
7701
+ // created via createElement.
7702
+ const {
7703
+ appendChild,
7704
+ insertBefore,
7705
+ removeChild,
7706
+ replaceChild
7707
+ } = _Node$1.prototype;
7708
+ assign(_Node$1.prototype, {
7451
7709
  appendChild(newChild) {
7452
- const appendedNode = appendChild.call(this, newChild);
7453
- return callNodeSlot(appendedNode, ConnectingSlot);
7710
+ const appendedNode = appendChild.call(this, newChild);
7711
+ return callNodeSlot(appendedNode, ConnectingSlot);
7454
7712
  },
7713
+
7455
7714
  insertBefore(newChild, referenceNode) {
7456
- const insertedNode = insertBefore.call(this, newChild, referenceNode);
7457
- return callNodeSlot(insertedNode, ConnectingSlot);
7715
+ const insertedNode = insertBefore.call(this, newChild, referenceNode);
7716
+ return callNodeSlot(insertedNode, ConnectingSlot);
7458
7717
  },
7718
+
7459
7719
  removeChild(oldChild) {
7460
- const removedNode = removeChild.call(this, oldChild);
7461
- return callNodeSlot(removedNode, DisconnectingSlot);
7720
+ const removedNode = removeChild.call(this, oldChild);
7721
+ return callNodeSlot(removedNode, DisconnectingSlot);
7462
7722
  },
7723
+
7463
7724
  replaceChild(newChild, oldChild) {
7464
- const replacedNode = replaceChild.call(this, newChild, oldChild);
7465
- callNodeSlot(replacedNode, DisconnectingSlot);
7466
- callNodeSlot(newChild, ConnectingSlot);
7467
- return replacedNode;
7468
- },
7469
- });
7725
+ const replacedNode = replaceChild.call(this, newChild, oldChild);
7726
+ callNodeSlot(replacedNode, DisconnectingSlot);
7727
+ callNodeSlot(newChild, ConnectingSlot);
7728
+ return replacedNode;
7729
+ }
7730
+
7731
+ });
7732
+ }
7470
7733
  /**
7471
7734
  * EXPERIMENTAL: This function is almost identical to document.createElement with the slightly
7472
7735
  * difference that in the options, you can pass the `is` property set to a Constructor instead of
@@ -7478,38 +7741,50 @@ var LWC = (function (exports) {
7478
7741
  * const el = createElement('x-foo', { is: FooCtor });
7479
7742
  * ```
7480
7743
  */
7744
+
7745
+
7481
7746
  function createElement(sel, options) {
7482
- if (!isObject(options) || isNull(options)) {
7483
- throw new TypeError(`"createElement" function expects an object as second parameter but received "${toString$1(options)}".`);
7484
- }
7485
- const Ctor = options.is;
7486
- if (!isFunction$1(Ctor)) {
7487
- throw new TypeError(`"createElement" function expects an "is" option with a valid component constructor.`);
7488
- }
7489
- const UpgradableConstructor = getUpgradableConstructor(sel, renderer);
7490
- let wasComponentUpgraded = false;
7491
- // the custom element from the registry is expecting an upgrade callback
7492
- /**
7493
- * Note: if the upgradable constructor does not expect, or throw when we new it
7494
- * with a callback as the first argument, we could implement a more advanced
7495
- * mechanism that only passes that argument if the constructor is known to be
7496
- * an upgradable custom element.
7497
- */
7498
- const element = new UpgradableConstructor((elm) => {
7499
- createVM(elm, Ctor, renderer, {
7500
- tagName: sel,
7501
- mode: options.mode !== 'closed' ? 'open' : 'closed',
7502
- owner: null,
7503
- });
7504
- ConnectingSlot.set(elm, connectRootElement);
7505
- DisconnectingSlot.set(elm, disconnectRootElement);
7506
- wasComponentUpgraded = true;
7747
+ if (!isObject(options) || isNull(options)) {
7748
+ throw new TypeError(`"createElement" function expects an object as second parameter but received "${toString$1(options)}".`);
7749
+ }
7750
+
7751
+ const Ctor = options.is;
7752
+
7753
+ if (!isFunction$1(Ctor)) {
7754
+ throw new TypeError(`"createElement" function expects an "is" option with a valid component constructor.`);
7755
+ }
7756
+
7757
+ const UpgradableConstructor = getUpgradableConstructor(sel, renderer);
7758
+ let wasComponentUpgraded = false; // the custom element from the registry is expecting an upgrade callback
7759
+
7760
+ /**
7761
+ * Note: if the upgradable constructor does not expect, or throw when we new it
7762
+ * with a callback as the first argument, we could implement a more advanced
7763
+ * mechanism that only passes that argument if the constructor is known to be
7764
+ * an upgradable custom element.
7765
+ */
7766
+
7767
+ const element = new UpgradableConstructor(elm => {
7768
+ createVM(elm, Ctor, renderer, {
7769
+ tagName: sel,
7770
+ mode: options.mode !== 'closed' ? 'open' : 'closed',
7771
+ owner: null
7507
7772
  });
7508
- if (!wasComponentUpgraded) {
7509
- /* eslint-disable-next-line no-console */
7510
- console.error(`Unexpected tag name "${sel}". This name is a registered custom element, preventing LWC to upgrade the element.`);
7773
+
7774
+ if (!lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
7775
+ ConnectingSlot.set(elm, connectRootElement);
7776
+ DisconnectingSlot.set(elm, disconnectRootElement);
7511
7777
  }
7512
- return element;
7778
+
7779
+ wasComponentUpgraded = true;
7780
+ });
7781
+
7782
+ if (!wasComponentUpgraded) {
7783
+ /* eslint-disable-next-line no-console */
7784
+ console.error(`Unexpected tag name "${sel}". This name is a registered custom element, preventing LWC to upgrade the element.`);
7785
+ }
7786
+
7787
+ return element;
7513
7788
  }
7514
7789
 
7515
7790
  /*
@@ -7543,7 +7818,7 @@ var LWC = (function (exports) {
7543
7818
  }
7544
7819
  // TODO [#1252]: Old behavior that is still used by some pieces of the platform. Manually
7545
7820
  // inserted nodes without the `lwc:dom=manual` directive will be considered as global elements.
7546
- return isSyntheticShadowDefined && !isUndefined$1(node[KEY__SHADOW_RESOLVER]);
7821
+ return renderer.isSyntheticShadowDefined && !isUndefined$1(node[KEY__SHADOW_RESOLVER]);
7547
7822
  }
7548
7823
 
7549
7824
  /*
@@ -7580,7 +7855,7 @@ var LWC = (function (exports) {
7580
7855
  });
7581
7856
  freeze(LightningElement);
7582
7857
  seal(LightningElement.prototype);
7583
- /* version: 2.22.0 */
7858
+ /* version: 2.23.2 */
7584
7859
 
7585
7860
  exports.LightningElement = LightningElement;
7586
7861
  exports.__unstable__ProfilerControl = profilerControl;
@@ -7602,6 +7877,7 @@ var LWC = (function (exports) {
7602
7877
  exports.registerDecorators = registerDecorators;
7603
7878
  exports.registerTemplate = registerTemplate;
7604
7879
  exports.renderer = renderer;
7880
+ exports.rendererFactory = rendererFactory;
7605
7881
  exports.sanitizeAttribute = sanitizeAttribute;
7606
7882
  exports.setFeatureFlag = setFeatureFlag;
7607
7883
  exports.setFeatureFlagForTest = setFeatureFlagForTest;