lwc 2.25.1 → 2.27.0

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 (37) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +953 -431
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +953 -431
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +797 -223
  5. package/dist/engine-dom/iife/es5/engine-dom.js +1025 -330
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +952 -241
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +953 -431
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +797 -223
  11. package/dist/engine-dom/umd/es5/engine-dom.js +1025 -330
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +952 -241
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +201 -247
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +201 -247
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +4 -4
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +4 -4
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +2 -2
  20. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +4 -4
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +3 -3
  22. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +3 -3
  23. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +4 -4
  24. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +2 -2
  25. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +4 -4
  26. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +3 -3
  27. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +3 -3
  28. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  29. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  30. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  31. package/dist/wire-service/iife/es5/wire-service.js +2 -2
  32. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  33. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  34. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  35. package/dist/wire-service/umd/es5/wire-service.js +2 -2
  36. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  37. package/package.json +7 -7
@@ -46,7 +46,7 @@ var LWC = (function (exports) {
46
46
  */
47
47
  const { assign, create, defineProperties, defineProperty, freeze, getOwnPropertyDescriptor: getOwnPropertyDescriptor$1, getOwnPropertyNames: getOwnPropertyNames$1, getPrototypeOf: getPrototypeOf$1, hasOwnProperty: hasOwnProperty$1, isFrozen, keys, seal, setPrototypeOf, } = Object;
48
48
  const { isArray: isArray$1 } = Array;
49
- const { copyWithin: ArrayCopyWithin, fill: ArrayFill, filter: ArrayFilter, find: ArrayFind, indexOf: ArrayIndexOf, join: ArrayJoin, map: ArrayMap, pop: ArrayPop, push: ArrayPush$1, reduce: ArrayReduce, reverse: ArrayReverse, shift: ArrayShift, slice: ArraySlice, sort: ArraySort, splice: ArraySplice, unshift: ArrayUnshift, forEach, } = Array.prototype;
49
+ const { concat: ArrayConcat$1, copyWithin: ArrayCopyWithin, fill: ArrayFill, filter: ArrayFilter, find: ArrayFind, indexOf: ArrayIndexOf, join: ArrayJoin, map: ArrayMap, pop: ArrayPop, push: ArrayPush$1, reduce: ArrayReduce, reverse: ArrayReverse, shift: ArrayShift, slice: ArraySlice, sort: ArraySort, splice: ArraySplice, unshift: ArrayUnshift, forEach, } = Array.prototype;
50
50
  const { fromCharCode: StringFromCharCode } = String;
51
51
  const { charCodeAt: StringCharCodeAt, replace: StringReplace, slice: StringSlice, toLowerCase: StringToLowerCase, } = String.prototype;
52
52
  function isUndefined$1(obj) {
@@ -291,7 +291,7 @@ var LWC = (function (exports) {
291
291
  CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
292
292
  return attributeName;
293
293
  }
294
- /** version: 2.25.1 */
294
+ /** version: 2.27.0 */
295
295
 
296
296
  /**
297
297
  * Copyright (C) 2018 salesforce.com, inc.
@@ -373,7 +373,7 @@ var LWC = (function (exports) {
373
373
  patch$1(propName);
374
374
  }
375
375
  }
376
- /** version: 2.25.1 */
376
+ /** version: 2.27.0 */
377
377
 
378
378
  /**
379
379
  * Copyright (C) 2018 salesforce.com, inc.
@@ -389,7 +389,6 @@ var LWC = (function (exports) {
389
389
  DUMMY_TEST_FLAG: null,
390
390
  ENABLE_ELEMENT_PATCH: null,
391
391
  ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST: null,
392
- ENABLE_HMR: null,
393
392
  ENABLE_HTML_COLLECTIONS_PATCH: null,
394
393
  ENABLE_INNER_OUTER_TEXT_PATCH: null,
395
394
  ENABLE_MIXED_SHADOW_MODE: null,
@@ -400,6 +399,7 @@ var LWC = (function (exports) {
400
399
  ENABLE_WIRE_SYNC_EMIT: null,
401
400
  ENABLE_LIGHT_GET_ROOT_NODE_PATCH: null,
402
401
  DISABLE_LIGHT_DOM_UNSCOPED_CSS: null,
402
+ ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
403
403
  };
404
404
  if (!_globalThis.lwcRuntimeFlags) {
405
405
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
@@ -1384,7 +1384,9 @@ var LWC = (function (exports) {
1384
1384
  const LightningElement = function () {
1385
1385
  // This should be as performant as possible, while any initialization should be done lazily
1386
1386
  if (isNull(vmBeingConstructed)) {
1387
- throw new ReferenceError('Illegal constructor');
1387
+ // Thrown when doing something like `new LightningElement()` or
1388
+ // `class Foo extends LightningElement {}; new Foo()`
1389
+ throw new TypeError('Illegal constructor');
1388
1390
  }
1389
1391
  const vm = vmBeingConstructed;
1390
1392
  const { def, elm } = vm;
@@ -2164,34 +2166,19 @@ var LWC = (function (exports) {
2164
2166
  freeze(BaseBridgeElement);
2165
2167
  seal(BaseBridgeElement.prototype);
2166
2168
  function setActiveVM(vm) {
2167
- {
2168
- // this method should never leak to prod
2169
- throw new ReferenceError();
2170
- }
2169
+ {
2170
+ // this method should never leak to prod
2171
+ throw new ReferenceError();
2172
+ }
2171
2173
  }
2172
2174
  function swapTemplate(oldTpl, newTpl) {
2173
-
2174
- if (!lwcRuntimeFlags.ENABLE_HMR) {
2175
- throw new Error('HMR is not enabled');
2176
- }
2177
-
2178
- return false;
2175
+ return false;
2179
2176
  }
2180
2177
  function swapComponent(oldComponent, newComponent) {
2181
-
2182
- if (!lwcRuntimeFlags.ENABLE_HMR) {
2183
- throw new Error('HMR is not enabled');
2184
- }
2185
-
2186
- return false;
2178
+ return false;
2187
2179
  }
2188
2180
  function swapStyle(oldStyle, newStyle) {
2189
-
2190
- if (!lwcRuntimeFlags.ENABLE_HMR) {
2191
- throw new Error('HMR is not enabled');
2192
- }
2193
-
2194
- return false;
2181
+ return false;
2195
2182
  }
2196
2183
 
2197
2184
  /*
@@ -2570,15 +2557,18 @@ var LWC = (function (exports) {
2570
2557
  /**
2571
2558
  * This function returns the host style token for a custom element if it
2572
2559
  * exists. Otherwise it returns null.
2560
+ *
2561
+ * A host style token is applied to the component if scoped styles are used.
2573
2562
  */
2574
2563
 
2575
2564
  function getStylesheetTokenHost(vnode) {
2576
2565
  const {
2577
- template: {
2578
- stylesheetToken
2579
- }
2566
+ template
2580
2567
  } = getComponentInternalDef(vnode.ctor);
2581
- return !isUndefined$1(stylesheetToken) ? makeHostToken(stylesheetToken) : null;
2568
+ const {
2569
+ stylesheetToken
2570
+ } = template;
2571
+ return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template) ? makeHostToken(stylesheetToken) : null;
2582
2572
  }
2583
2573
 
2584
2574
  function getNearestNativeShadowComponent(vm) {
@@ -2632,69 +2622,6 @@ var LWC = (function (exports) {
2632
2622
  return null;
2633
2623
  }
2634
2624
 
2635
- /*
2636
- * Copyright (c) 2020, salesforce.com, inc.
2637
- * All rights reserved.
2638
- * SPDX-License-Identifier: MIT
2639
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2640
- */
2641
-
2642
- function checkHasVM(elm) {
2643
- const hasVM = !isUndefined$1(getAssociatedVMIfPresent(elm));
2644
-
2645
- return hasVM;
2646
- }
2647
-
2648
- function getUpgradableConstructor(tagName, renderer) {
2649
- const {
2650
- getCustomElement,
2651
- HTMLElementExported: RendererHTMLElement,
2652
- defineCustomElement
2653
- } = renderer; // Should never get a tag with upper case letter at this point, the compiler should
2654
- // produce only tags with lowercase letters
2655
- // But, for backwards compatibility, we will lower case the tagName
2656
-
2657
- tagName = tagName.toLowerCase();
2658
- let CE = getCustomElement(tagName);
2659
-
2660
- if (!isUndefined$1(CE)) {
2661
- return CE;
2662
- }
2663
- /**
2664
- * LWC Upgradable Element reference to an element that was created
2665
- * via the scoped registry mechanism, and that is ready to be upgraded.
2666
- */
2667
-
2668
-
2669
- CE = class LWCUpgradableElement extends RendererHTMLElement {
2670
- constructor(upgradeCallback) {
2671
- super();
2672
-
2673
- if (isFunction$1(upgradeCallback)) {
2674
- upgradeCallback(this); // nothing to do with the result for now
2675
- }
2676
- }
2677
-
2678
- };
2679
-
2680
- if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
2681
- CE.prototype.connectedCallback = function () {
2682
- if (checkHasVM(this)) {
2683
- connectRootElement(this);
2684
- }
2685
- };
2686
-
2687
- CE.prototype.disconnectedCallback = function () {
2688
- if (checkHasVM(this)) {
2689
- disconnectRootElement(this);
2690
- }
2691
- };
2692
- }
2693
-
2694
- defineCustomElement(tagName, CE);
2695
- return CE;
2696
- }
2697
-
2698
2625
  /*
2699
2626
  * Copyright (c) 2018, salesforce.com, inc.
2700
2627
  * All rights reserved.
@@ -2711,6 +2638,9 @@ var LWC = (function (exports) {
2711
2638
  function isVCustomElement(vnode) {
2712
2639
  return vnode.type === 3 /* VNodeType.CustomElement */;
2713
2640
  }
2641
+ function isVScopedSlotFragment(vnode) {
2642
+ return vnode.type === 6 /* VNodeType.ScopedSlotFragment */;
2643
+ }
2714
2644
 
2715
2645
  /*
2716
2646
  * Copyright (c) 2018, salesforce.com, inc.
@@ -3182,7 +3112,9 @@ var LWC = (function (exports) {
3182
3112
  sel,
3183
3113
  owner
3184
3114
  } = vnode;
3185
- const UpgradableConstructor = getUpgradableConstructor(sel, renderer);
3115
+ const {
3116
+ createCustomElement
3117
+ } = renderer;
3186
3118
  /**
3187
3119
  * Note: if the upgradable constructor does not expect, or throw when we new it
3188
3120
  * with a callback as the first argument, we could implement a more advanced
@@ -3191,10 +3123,25 @@ var LWC = (function (exports) {
3191
3123
  */
3192
3124
 
3193
3125
  let vm;
3194
- const elm = new UpgradableConstructor(elm => {
3126
+
3127
+ const upgradeCallback = elm => {
3195
3128
  // the custom element from the registry is expecting an upgrade callback
3196
3129
  vm = createViewModelHook(elm, vnode, renderer);
3197
- });
3130
+ };
3131
+
3132
+ const connectedCallback = elm => {
3133
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3134
+ connectRootElement(elm);
3135
+ }
3136
+ };
3137
+
3138
+ const disconnectedCallback = elm => {
3139
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3140
+ disconnectRootElement(elm);
3141
+ }
3142
+ };
3143
+
3144
+ const elm = createCustomElement(sel, upgradeCallback, connectedCallback, disconnectedCallback);
3198
3145
  vnode.elm = elm;
3199
3146
  vnode.vm = vm;
3200
3147
  linkNodeToShadow(elm, owner, renderer);
@@ -3202,8 +3149,6 @@ var LWC = (function (exports) {
3202
3149
 
3203
3150
  if (vm) {
3204
3151
  allocateChildren(vnode, vm);
3205
- } else if (vnode.ctor !== UpgradableConstructor) {
3206
- throw new TypeError(`Incorrect Component Constructor`);
3207
3152
  }
3208
3153
 
3209
3154
  patchElementPropsAndAttrs$1(null, vnode, renderer);
@@ -3456,7 +3401,7 @@ var LWC = (function (exports) {
3456
3401
  /* RenderMode.Light */
3457
3402
  ) {
3458
3403
  // slow path
3459
- allocateInSlot(vm, children); // save the allocated children in case this vnode is reused.
3404
+ allocateInSlot(vm, children, vnode.owner); // save the allocated children in case this vnode is reused.
3460
3405
 
3461
3406
  vnode.aChildren = children; // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
3462
3407
 
@@ -3488,13 +3433,19 @@ var LWC = (function (exports) {
3488
3433
  return vm;
3489
3434
  }
3490
3435
 
3491
- function allocateInSlot(vm, children) {
3492
- var _a;
3436
+ function allocateInSlot(vm, children, owner) {
3437
+ var _a, _b;
3493
3438
 
3494
3439
  const {
3495
- cmpSlots: oldSlots
3440
+ cmpSlots: {
3441
+ slotAssignments: oldSlotsMapping
3442
+ }
3496
3443
  } = vm;
3497
- const cmpSlots = vm.cmpSlots = create(null);
3444
+ const cmpSlotsMapping = create(null);
3445
+ vm.cmpSlots = {
3446
+ owner,
3447
+ slotAssignments: cmpSlotsMapping
3448
+ };
3498
3449
 
3499
3450
  for (let i = 0, len = children.length; i < len; i += 1) {
3500
3451
  const vnode = children[i];
@@ -3506,19 +3457,21 @@ var LWC = (function (exports) {
3506
3457
  let slotName = '';
3507
3458
 
3508
3459
  if (isVBaseElement(vnode)) {
3509
- slotName = ((_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) || '';
3460
+ slotName = (_b = (_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : '';
3461
+ } else if (isVScopedSlotFragment(vnode)) {
3462
+ slotName = vnode.slotName;
3510
3463
  }
3511
3464
 
3512
- const vnodes = cmpSlots[slotName] = cmpSlots[slotName] || [];
3465
+ const vnodes = cmpSlotsMapping[slotName] = cmpSlotsMapping[slotName] || [];
3513
3466
  ArrayPush$1.call(vnodes, vnode);
3514
3467
  }
3515
3468
 
3516
3469
  if (isFalse(vm.isDirty)) {
3517
3470
  // We need to determine if the old allocation is really different from the new one
3518
3471
  // and mark the vm as dirty
3519
- const oldKeys = keys(oldSlots);
3472
+ const oldKeys = keys(oldSlotsMapping);
3520
3473
 
3521
- if (oldKeys.length !== keys(cmpSlots).length) {
3474
+ if (oldKeys.length !== keys(cmpSlotsMapping).length) {
3522
3475
  markComponentAsDirty(vm);
3523
3476
  return;
3524
3477
  }
@@ -3526,15 +3479,15 @@ var LWC = (function (exports) {
3526
3479
  for (let i = 0, len = oldKeys.length; i < len; i += 1) {
3527
3480
  const key = oldKeys[i];
3528
3481
 
3529
- if (isUndefined$1(cmpSlots[key]) || oldSlots[key].length !== cmpSlots[key].length) {
3482
+ if (isUndefined$1(cmpSlotsMapping[key]) || oldSlotsMapping[key].length !== cmpSlotsMapping[key].length) {
3530
3483
  markComponentAsDirty(vm);
3531
3484
  return;
3532
3485
  }
3533
3486
 
3534
- const oldVNodes = oldSlots[key];
3535
- const vnodes = cmpSlots[key];
3487
+ const oldVNodes = oldSlotsMapping[key];
3488
+ const vnodes = cmpSlotsMapping[key];
3536
3489
 
3537
- for (let j = 0, a = cmpSlots[key].length; j < a; j += 1) {
3490
+ for (let j = 0, a = cmpSlotsMapping[key].length; j < a; j += 1) {
3538
3491
  if (oldVNodes[j] !== vnodes[j]) {
3539
3492
  markComponentAsDirty(vm);
3540
3493
  return;
@@ -3734,6 +3687,18 @@ var LWC = (function (exports) {
3734
3687
  function addVNodeToChildLWC(vnode) {
3735
3688
  ArrayPush$1.call(getVMBeingRendered().velements, vnode);
3736
3689
  }
3690
+ // [s]coped [s]lot [f]actory
3691
+ function ssf(slotName, factory) {
3692
+ return {
3693
+ type: 6 /* VNodeType.ScopedSlotFragment */,
3694
+ factory,
3695
+ owner: getVMBeingRendered(),
3696
+ elm: undefined,
3697
+ sel: undefined,
3698
+ key: undefined,
3699
+ slotName,
3700
+ };
3701
+ }
3737
3702
  // [st]atic node
3738
3703
  function st(fragment, key) {
3739
3704
  return {
@@ -3786,9 +3751,31 @@ var LWC = (function (exports) {
3786
3751
  // [s]lot element node
3787
3752
  function s(slotName, data, children, slotset) {
3788
3753
  if (!isUndefined$1(slotset) &&
3789
- !isUndefined$1(slotset[slotName]) &&
3790
- slotset[slotName].length !== 0) {
3791
- children = slotset[slotName];
3754
+ !isUndefined$1(slotset.slotAssignments) &&
3755
+ !isUndefined$1(slotset.slotAssignments[slotName]) &&
3756
+ slotset.slotAssignments[slotName].length !== 0) {
3757
+ children = slotset.slotAssignments[slotName].reduce((acc, vnode) => {
3758
+ // If the passed slot content is factory, evaluate it and use the produced vnodes
3759
+ if (vnode && isVScopedSlotFragment(vnode)) {
3760
+ const vmBeingRenderedInception = getVMBeingRendered();
3761
+ let children = [];
3762
+ // Evaluate in the scope of the slot content's owner
3763
+ // if a slotset is provided, there will always be an owner. The only case where owner is
3764
+ // undefined is for root components, but root components cannot accept slotted content
3765
+ setVMBeingRendered(slotset.owner);
3766
+ try {
3767
+ children = vnode.factory(data.slotData);
3768
+ }
3769
+ finally {
3770
+ setVMBeingRendered(vmBeingRenderedInception);
3771
+ }
3772
+ return ArrayConcat$1.call(acc, children);
3773
+ }
3774
+ else {
3775
+ // If the slot content is a static list of child nodes provided by the parent, nothing to do
3776
+ return ArrayConcat$1.call(acc, vnode);
3777
+ }
3778
+ }, []);
3792
3779
  }
3793
3780
  const vmBeingRendered = getVMBeingRendered();
3794
3781
  const { renderMode, shadowMode } = vmBeingRendered;
@@ -4026,6 +4013,7 @@ var LWC = (function (exports) {
4026
4013
  gid,
4027
4014
  fid,
4028
4015
  shc,
4016
+ ssf,
4029
4017
  });
4030
4018
  /** Indicates if operations should be logged by the profiler. */
4031
4019
  let isProfilerEnabled = false;
@@ -4518,7 +4506,9 @@ var LWC = (function (exports) {
4518
4506
  velements: EmptyArray,
4519
4507
  cmpProps: create(null),
4520
4508
  cmpFields: create(null),
4521
- cmpSlots: create(null),
4509
+ cmpSlots: {
4510
+ slotAssignments: create(null)
4511
+ },
4522
4512
  oar: create(null),
4523
4513
  cmpTemplate: null,
4524
4514
  hydrated: Boolean(hydrated),
@@ -5559,19 +5549,23 @@ var LWC = (function (exports) {
5559
5549
  //
5560
5550
  // Consequently, hydration mismatches will occur if scoped CSS token classnames
5561
5551
  // are rendered during SSR. This needs to be accounted for when validating.
5562
- if (scopedToken) {
5552
+ if (!isNull(scopedToken) || !isNull(stylesheetTokenHost)) {
5563
5553
  if (!isUndefined$1(className)) {
5564
- className = isNull(stylesheetTokenHost)
5565
- ? `${scopedToken} ${className}`
5566
- : `${scopedToken} ${className} ${stylesheetTokenHost}`;
5554
+ // The order of the className should be scopedToken className stylesheetTokenHost
5555
+ const classTokens = [scopedToken, className, stylesheetTokenHost];
5556
+ const classNames = ArrayFilter.call(classTokens, (token) => !isNull(token));
5557
+ className = ArrayJoin.call(classNames, ' ');
5567
5558
  }
5568
5559
  else if (!isUndefined$1(classMap)) {
5569
- classMap = Object.assign(Object.assign(Object.assign({}, classMap), { [scopedToken]: true }), (isNull(stylesheetTokenHost) ? {} : { [stylesheetTokenHost]: true }));
5560
+ classMap = Object.assign(Object.assign(Object.assign({}, classMap), (!isNull(scopedToken) ? { [scopedToken]: true } : {})), (!isNull(stylesheetTokenHost) ? { [stylesheetTokenHost]: true } : {}));
5570
5561
  }
5571
5562
  else {
5572
- className = isNull(stylesheetTokenHost)
5573
- ? `${scopedToken}`
5574
- : `${scopedToken} ${stylesheetTokenHost}`;
5563
+ // The order of the className should be scopedToken stylesheetTokenHost
5564
+ const classTokens = [scopedToken, stylesheetTokenHost];
5565
+ const classNames = ArrayFilter.call(classTokens, (token) => !isNull(token));
5566
+ if (classNames.length) {
5567
+ className = ArrayJoin.call(classNames, ' ');
5568
+ }
5575
5569
  }
5576
5570
  }
5577
5571
  let nodesAreCompatible = true;
@@ -5700,7 +5694,7 @@ var LWC = (function (exports) {
5700
5694
  }
5701
5695
  return ctor;
5702
5696
  }
5703
- /* version: 2.25.1 */
5697
+ /* version: 2.27.0 */
5704
5698
 
5705
5699
  /*
5706
5700
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5835,6 +5829,626 @@ var LWC = (function (exports) {
5835
5829
  }
5836
5830
  }
5837
5831
 
5832
+ /*
5833
+ * Copyright (c) 2020, salesforce.com, inc.
5834
+ * All rights reserved.
5835
+ * SPDX-License-Identifier: MIT
5836
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5837
+ */
5838
+ function isCustomElementRegistryAvailable() {
5839
+ if (typeof customElements === 'undefined') {
5840
+ return false;
5841
+ }
5842
+ try {
5843
+ // dereference HTMLElement global because babel wraps globals in compat mode with a
5844
+ // _wrapNativeSuper()
5845
+ // This is a problem because LWCUpgradableElement extends renderer.HTMLElement which does not
5846
+ // get wrapped by babel.
5847
+ const HTMLElementAlias = HTMLElement;
5848
+ // In case we use compat mode with a modern browser, the compat mode transformation
5849
+ // invokes the DOM api with an .apply() or .call() to initialize any DOM api sub-classing,
5850
+ // which are not equipped to be initialized that way.
5851
+ class clazz extends HTMLElementAlias {
5852
+ }
5853
+ customElements.define('lwc-test-' + Math.floor(Math.random() * 1000000), clazz);
5854
+ new clazz();
5855
+ return true;
5856
+ }
5857
+ catch (_a) {
5858
+ return false;
5859
+ }
5860
+ }
5861
+ const hasCustomElements = isCustomElementRegistryAvailable();
5862
+
5863
+ /*
5864
+ * Copyright (c) 2018, salesforce.com, inc.
5865
+ * All rights reserved.
5866
+ * SPDX-License-Identifier: MIT
5867
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5868
+ */
5869
+ // Creates a custom element for compat (legacy) browser environments
5870
+ const createCustomElementCompat = (tagName, upgradeCallback) => {
5871
+ const elm = document.createElement(tagName);
5872
+ upgradeCallback(elm); // nothing to do with the result for now
5873
+ return elm;
5874
+ };
5875
+
5876
+ /*
5877
+ * Copyright (c) 2018, salesforce.com, inc.
5878
+ * All rights reserved.
5879
+ * SPDX-License-Identifier: MIT
5880
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5881
+ */
5882
+ const cachedConstructors = new Map();
5883
+ const elementsUpgradedOutsideLWC = new WeakSet();
5884
+ let elementBeingUpgradedByLWC = false;
5885
+ // Creates a constructor that is intended to be used as a vanilla custom element, except that the upgradeCallback is
5886
+ // passed in to the constructor so LWC can reuse the same custom element constructor for multiple components.
5887
+ // Another benefit is that only LWC can create components that actually do anything – if you do
5888
+ // `customElements.define('x-foo')`, then you don't have access to the upgradeCallback, so it's a dummy custom element.
5889
+ // This class should be created once per tag name.
5890
+ const createUpgradableConstructor = (connectedCallback, disconnectedCallback) => {
5891
+ // TODO [#2972]: this class should expose observedAttributes as necessary
5892
+ return class UpgradableConstructor extends HTMLElement {
5893
+ constructor(upgradeCallback) {
5894
+ super();
5895
+ // If the element is not created using lwc.createElement(), e.g. `document.createElement('x-foo')`,
5896
+ // then elementBeingUpgraded will be false
5897
+ if (elementBeingUpgradedByLWC) {
5898
+ upgradeCallback(this);
5899
+ }
5900
+ else {
5901
+ // keep track of elements that were not created by lwc.createElement,
5902
+ // so we can ignore their lifecycle hooks
5903
+ elementsUpgradedOutsideLWC.add(this);
5904
+ // TODO [#2970]: LWC elements cannot be upgraded via new Ctor()
5905
+ // Do we want to support this? Throw an error? Currently for backwards compat it's a no-op.
5906
+ }
5907
+ }
5908
+ connectedCallback() {
5909
+ if (!elementsUpgradedOutsideLWC.has(this)) {
5910
+ connectedCallback(this);
5911
+ }
5912
+ }
5913
+ disconnectedCallback() {
5914
+ if (!elementsUpgradedOutsideLWC.has(this)) {
5915
+ disconnectedCallback(this);
5916
+ }
5917
+ }
5918
+ };
5919
+ };
5920
+ const createCustomElementVanilla = (tagName, upgradeCallback, connectedCallback, disconnectedCallback) => {
5921
+ // use global custom elements registry
5922
+ let UpgradableConstructor = cachedConstructors.get(tagName);
5923
+ if (isUndefined$1(UpgradableConstructor)) {
5924
+ if (!isUndefined$1(customElements.get(tagName))) {
5925
+ throw new Error(`Unexpected tag name "${tagName}". This name is a registered custom element, preventing LWC to upgrade the element.`);
5926
+ }
5927
+ UpgradableConstructor = createUpgradableConstructor(connectedCallback, disconnectedCallback);
5928
+ customElements.define(tagName, UpgradableConstructor);
5929
+ cachedConstructors.set(tagName, UpgradableConstructor);
5930
+ }
5931
+ elementBeingUpgradedByLWC = true;
5932
+ try {
5933
+ return new UpgradableConstructor(upgradeCallback);
5934
+ }
5935
+ finally {
5936
+ elementBeingUpgradedByLWC = false;
5937
+ }
5938
+ };
5939
+
5940
+ /*
5941
+ * Copyright (c) 2020, salesforce.com, inc.
5942
+ * All rights reserved.
5943
+ * SPDX-License-Identifier: MIT
5944
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5945
+ */
5946
+ /**
5947
+ * Create a scoped registry, i.e. a function that can create custom elements whose tag names
5948
+ * do not conflict with vanilla custom elements having the same tag name.
5949
+ */
5950
+ function createScopedRegistry() {
5951
+ if (!hasCustomElements) {
5952
+ // This code should never be reached, because we don't use the pivot registry if
5953
+ // custom elements are unavailable.
5954
+ throw new Error('Custom elements are not supported in this environment.');
5955
+ }
5956
+ const { HTMLElement: NativeHTMLElement } = window;
5957
+ const { hasAttribute: nativeHasAttribute, setAttribute: nativeSetAttribute, removeAttribute: nativeRemoveAttribute, getAttribute: nativeGetAttribute, } = NativeHTMLElement.prototype;
5958
+ const definitionForElement = new WeakMap();
5959
+ const pendingRegistryForElement = new WeakMap();
5960
+ const definitionForConstructor = new WeakMap();
5961
+ const registeredUserCtors = new WeakSet();
5962
+ const pivotCtorByTag = new Map();
5963
+ const globalDefinitionsByTag = new Map();
5964
+ const globalDefinitionsByClass = new Map();
5965
+ const awaitingUpgrade = new Map();
5966
+ const EMPTY_SET = new Set();
5967
+ function createDefinitionRecord(constructor) {
5968
+ var _a;
5969
+ const { connectedCallback, disconnectedCallback, adoptedCallback, attributeChangedCallback, } = constructor.prototype;
5970
+ const observedAttributes = new Set((_a = constructor.observedAttributes) !== null && _a !== void 0 ? _a : []);
5971
+ return {
5972
+ UserCtor: constructor,
5973
+ PivotCtor: undefined,
5974
+ connectedCallback,
5975
+ disconnectedCallback,
5976
+ adoptedCallback,
5977
+ attributeChangedCallback,
5978
+ observedAttributes,
5979
+ };
5980
+ }
5981
+ // Helper to create stand-in element for each tagName registered that delegates out to the registry for the given
5982
+ // element. Note that the `registeredDefinition` represents the constructor that was used to register during
5983
+ // `customElements.define()`. Whereas the `pivotDefinition` represents the constructor that is passed when the pivot
5984
+ // constructor is invoked with another constructor.
5985
+ function createPivotingClass(tagName, registeredDefinition) {
5986
+ class PivotCtor extends NativeHTMLElement {
5987
+ constructor(UserCtor) {
5988
+ // This constructor can only be invoked by:
5989
+ // a) the browser instantiating an element from parsing or via document.createElement.
5990
+ // b) LWC new PivotClass (This constructor is NOT observable/accessible in user-land).
5991
+ // b) new UserClass.
5992
+ // When LWC instantiates it, it will pass the upgrading definition as an argument
5993
+ // If the caller signals via UserCtor that this is in fact a controlled
5994
+ // definition, we use that one, otherwise fallback to the global
5995
+ // internal registry.
5996
+ super();
5997
+ const userCtorIsDefined = !isUndefined$1(UserCtor);
5998
+ if (userCtorIsDefined) {
5999
+ if (!isConstructor(UserCtor)) {
6000
+ throw new TypeError(`Failed to create custom element: the provided constructor is not a constructor.`);
6001
+ }
6002
+ if (!registeredUserCtors.has(UserCtor)) {
6003
+ throw new Error(`Failed to create custom element: the provided constructor is unregistered: ${UserCtor.name}.`);
6004
+ }
6005
+ }
6006
+ const definition = userCtorIsDefined
6007
+ ? getOrCreateDefinitionForConstructor(UserCtor)
6008
+ : globalDefinitionsByTag.get(tagName);
6009
+ if (!isUndefined$1(definition)) {
6010
+ internalUpgrade(this, registeredDefinition, definition);
6011
+ }
6012
+ else {
6013
+ // This is the case in which there is no global definition, and
6014
+ // it is not handled by LWC (otherwise it will have a valid UserCtor)
6015
+ // so we need to add it to the pending queue just in case it eventually
6016
+ // gets defined in the global registry.
6017
+ pendingRegistryForElement.set(this, registeredDefinition);
6018
+ }
6019
+ }
6020
+ connectedCallback() {
6021
+ var _a;
6022
+ const definition = definitionForElement.get(this);
6023
+ if (!isUndefined$1(definition)) {
6024
+ // Delegate out to user callback
6025
+ (_a = definition.connectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
6026
+ }
6027
+ else {
6028
+ // Register for upgrade when defined (only when connected, so we don't leak)
6029
+ let awaiting = awaitingUpgrade.get(tagName);
6030
+ if (isUndefined$1(awaiting)) {
6031
+ awaitingUpgrade.set(tagName, (awaiting = new Set()));
6032
+ }
6033
+ awaiting.add(this);
6034
+ }
6035
+ }
6036
+ disconnectedCallback() {
6037
+ var _a;
6038
+ const definition = definitionForElement.get(this);
6039
+ if (!isUndefined$1(definition)) {
6040
+ // Delegate out to user callback
6041
+ (_a = definition.disconnectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
6042
+ }
6043
+ else {
6044
+ // Un-register for upgrade when defined (so we don't leak)
6045
+ const awaiting = awaitingUpgrade.get(tagName);
6046
+ // At this point, awaiting should never be undefined, because connectedCallback
6047
+ // must have been called before disconnectedCallback. But just to be safe, we check
6048
+ if (!isUndefined$1(awaiting)) {
6049
+ awaiting.delete(this);
6050
+ }
6051
+ }
6052
+ }
6053
+ adoptedCallback() {
6054
+ var _a;
6055
+ const definition = definitionForElement.get(this);
6056
+ (_a = definition === null || definition === void 0 ? void 0 : definition.adoptedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
6057
+ }
6058
+ attributeChangedCallback(name, oldValue, newValue) {
6059
+ var _a;
6060
+ const definition = definitionForElement.get(this);
6061
+ // if both definitions are the same, then the observedAttributes is the same,
6062
+ // but if they are different, only if the runtime definition has the attribute
6063
+ // marked as observed, then it should invoke attributeChangedCallback.
6064
+ if (registeredDefinition === definition ||
6065
+ (definition === null || definition === void 0 ? void 0 : definition.observedAttributes.has(name))) {
6066
+ (_a = definition.attributeChangedCallback) === null || _a === void 0 ? void 0 : _a.apply(this, [name, oldValue, newValue]);
6067
+ }
6068
+ }
6069
+ }
6070
+ PivotCtor.observedAttributes = [...registeredDefinition.observedAttributes];
6071
+ return PivotCtor;
6072
+ }
6073
+ function getNewObservedAttributes(registeredDefinition, pivotDefinition) {
6074
+ const { observedAttributes, attributeChangedCallback } = pivotDefinition;
6075
+ if (observedAttributes.size === 0 || isUndefined$1(attributeChangedCallback)) {
6076
+ // This instance does not need to observe any attributes, no need to patch
6077
+ return EMPTY_SET;
6078
+ }
6079
+ // Natively, the attributes observed by the registered definition are going to be taken
6080
+ // care of by the browser, only the difference between the two sets has to be taken
6081
+ // care by the patched version.
6082
+ return new Set([...pivotDefinition.observedAttributes].filter((x) => !registeredDefinition.observedAttributes.has(x)));
6083
+ }
6084
+ function throwAsyncError(error) {
6085
+ // Per native custom element behavior, errors thrown in attributeChangedCallback
6086
+ // become unhandled async errors. We use setTimeout() instead of Promise.resolve()
6087
+ // to make it an unhandled error rather than an unhandled rejection.
6088
+ setTimeout(() => {
6089
+ throw error;
6090
+ });
6091
+ }
6092
+ // Helper to patch `setAttribute`/`getAttribute` to implement `attributeChangedCallback`.
6093
+ // Why is this necessary? Well basically, you can't change the `observedAttributes` after
6094
+ // a custom element is defined. So with pivots, if two classes share the same tag name,
6095
+ // and the second class observes attributes that aren't observed by the first one,
6096
+ // then those attributes can never be observed by the native `observedAttributes` system.
6097
+ // So we have to simulate it by patching `getAttribute`/`removeAttribute`. Note that
6098
+ // we only do this when absolutely necessary, though; i.e. because we've determined
6099
+ // that we aren't observing the attributes we need to.
6100
+ function patchAttributes(instance, registeredDefinition, pivotDefinition) {
6101
+ const newObservedAttributes = getNewObservedAttributes(registeredDefinition, pivotDefinition);
6102
+ if (newObservedAttributes.size === 0) {
6103
+ return;
6104
+ }
6105
+ const { attributeChangedCallback } = pivotDefinition;
6106
+ // Patch the instance.
6107
+ // Note we use the native `getAttribute` rather than the super's `getAttribute` because
6108
+ // we don't actually want it to be observable that we're calling `getAttribute` from
6109
+ // `setAttribute` and `removeAttribute`.
6110
+ // TODO [#2994]: this should handle reflected properties such as `ariaLabel` and `role`.
6111
+ defineProperties(instance, {
6112
+ setAttribute: {
6113
+ value: function setAttribute(name, value) {
6114
+ if (newObservedAttributes.has(name)) {
6115
+ const old = nativeGetAttribute.call(this, name);
6116
+ nativeSetAttribute.call(this, name, value);
6117
+ try {
6118
+ attributeChangedCallback.call(this, name, old, value + '');
6119
+ }
6120
+ catch (error) {
6121
+ throwAsyncError(error);
6122
+ }
6123
+ }
6124
+ else {
6125
+ nativeSetAttribute.call(this, name, value);
6126
+ }
6127
+ },
6128
+ writable: true,
6129
+ enumerable: true,
6130
+ configurable: true,
6131
+ },
6132
+ removeAttribute: {
6133
+ value: function removeAttribute(name) {
6134
+ if (newObservedAttributes.has(name)) {
6135
+ const old = nativeGetAttribute.call(this, name);
6136
+ nativeRemoveAttribute.call(this, name);
6137
+ try {
6138
+ attributeChangedCallback.call(this, name, old, null);
6139
+ }
6140
+ catch (error) {
6141
+ throwAsyncError(error);
6142
+ }
6143
+ }
6144
+ else {
6145
+ nativeRemoveAttribute.call(this, name);
6146
+ }
6147
+ },
6148
+ writable: true,
6149
+ enumerable: true,
6150
+ configurable: true,
6151
+ },
6152
+ });
6153
+ }
6154
+ function patchAttributesDuringUpgrade(instance, registeredDefinition, pivotDefinition) {
6155
+ // The below case patches observed attributes for the case where the HTML element is upgraded
6156
+ // from a pre-existing one in the DOM.
6157
+ const newObservedAttributes = getNewObservedAttributes(registeredDefinition, pivotDefinition);
6158
+ if (getNewObservedAttributes(registeredDefinition, pivotDefinition).size === 0) {
6159
+ return;
6160
+ }
6161
+ const { attributeChangedCallback } = pivotDefinition;
6162
+ // Approximate observedAttributes from the user class, but only for the new observed attributes
6163
+ newObservedAttributes.forEach((name) => {
6164
+ if (nativeHasAttribute.call(instance, name)) {
6165
+ const newValue = nativeGetAttribute.call(instance, name);
6166
+ attributeChangedCallback.call(instance, name, null, newValue);
6167
+ }
6168
+ });
6169
+ }
6170
+ // User extends this HTMLElement, which returns the CE being upgraded
6171
+ let upgradingInstance;
6172
+ // Helper to upgrade an instance with a CE definition using "constructor call trick"
6173
+ function internalUpgrade(instance, registeredDefinition, pivotDefinition) {
6174
+ setPrototypeOf(instance, pivotDefinition.UserCtor.prototype);
6175
+ definitionForElement.set(instance, pivotDefinition);
6176
+ // attributes patches when needed
6177
+ if (pivotDefinition !== registeredDefinition) {
6178
+ patchAttributes(instance, registeredDefinition, pivotDefinition);
6179
+ }
6180
+ // Tricking the construction path to believe that a new instance is being created,
6181
+ // that way it will execute the super initialization mechanism but the HTMLElement
6182
+ // constructor will reuse the instance by returning the upgradingInstance.
6183
+ // This is by far the most important piece of the puzzle
6184
+ upgradingInstance = instance;
6185
+ // By `new`ing the UserCtor, we now jump to the constructor for the overridden global HTMLElement
6186
+ // The reason this happens is that the UserCtor extends HTMLElement, so it calls the `super()`.
6187
+ // Note that `upgradingInstance` is explicitly handled in the HTMLElement constructor.
6188
+ new pivotDefinition.UserCtor();
6189
+ patchAttributesDuringUpgrade(instance, registeredDefinition, pivotDefinition);
6190
+ }
6191
+ function isConstructor(constructor) {
6192
+ return isFunction$1(constructor) && isObject(constructor.prototype);
6193
+ }
6194
+ function getOrCreateDefinitionForConstructor(constructor) {
6195
+ if (!isConstructor(constructor)) {
6196
+ throw new TypeError('The referenced constructor is not a constructor.');
6197
+ }
6198
+ const definition = definitionForConstructor.get(constructor);
6199
+ if (!isUndefined$1(definition)) {
6200
+ return definition;
6201
+ }
6202
+ return createDefinitionRecord(constructor);
6203
+ }
6204
+ const { customElements: nativeRegistry } = window;
6205
+ const { define: nativeDefine, whenDefined: nativeWhenDefined, get: nativeGet } = nativeRegistry;
6206
+ // patch for the global registry define mechanism
6207
+ CustomElementRegistry.prototype.define = function define(tagName, constructor, options) {
6208
+ if (options && options.extends) {
6209
+ // TODO [#2983]: should we support `extends`?
6210
+ throw new DOMException('NotSupportedError: "extends" key in customElements.define() options is not supported.');
6211
+ }
6212
+ if (globalDefinitionsByTag.has(tagName)) {
6213
+ throw new DOMException(`Failed to execute 'define' on 'CustomElementRegistry': the name "${tagName}" has already been used with this registry`);
6214
+ }
6215
+ if (!isUndefined$1(globalDefinitionsByClass.get(constructor))) {
6216
+ throw new DOMException(`Failed to execute 'define' on 'CustomElementRegistry': this constructor has already been used with this registry`);
6217
+ }
6218
+ const definition = getOrCreateDefinitionForConstructor(constructor);
6219
+ registeredUserCtors.add(constructor);
6220
+ let PivotCtor = pivotCtorByTag.get(tagName);
6221
+ if (isUndefined$1(PivotCtor)) {
6222
+ PivotCtor = createPivotingClass(tagName, definition);
6223
+ // Register a pivoting class which will handle global registry initializations
6224
+ nativeDefine.call(nativeRegistry, tagName, PivotCtor);
6225
+ }
6226
+ // Only cache after nativeDefine has been called, because if it throws an error
6227
+ // (e.g. for an invalid tag name), then we don't want to cache anything.
6228
+ definitionForConstructor.set(constructor, definition);
6229
+ pivotCtorByTag.set(tagName, PivotCtor);
6230
+ globalDefinitionsByTag.set(tagName, definition);
6231
+ globalDefinitionsByClass.set(constructor, definition);
6232
+ // For globally defined custom elements, the definition associated
6233
+ // to the UserCtor has a back-pointer to PivotCtor in case the user
6234
+ // new the UserCtor, so we know how to create the underlying element.
6235
+ definition.PivotCtor = PivotCtor;
6236
+ // Upgrade any elements created in this scope before customElements.define
6237
+ // was called, which should be exhibited by the following steps:
6238
+ // 1) LWC registers a tagName for an LWC component.
6239
+ // 2) Element with same tagName is created with document.createElement()
6240
+ // and inserted into DOM.
6241
+ // 3) customElements.define() is called with tagName and non-LWC constructor.
6242
+ // This requires immediate upgrade when the new global tagName is defined.
6243
+ const awaiting = awaitingUpgrade.get(tagName);
6244
+ if (!isUndefined$1(awaiting)) {
6245
+ awaitingUpgrade.delete(tagName);
6246
+ for (const element of awaiting) {
6247
+ const registeredDefinition = pendingRegistryForElement.get(element);
6248
+ // At this point, registeredDefinition should never be undefined because awaitingUpgrade
6249
+ // is only populated when we haven't run internalUpgrade yet, and we only populate
6250
+ // pendingRegistryForElement when internalUpgrade hasn't run yet.
6251
+ // But just to be safe, we check.
6252
+ if (!isUndefined$1(registeredDefinition)) {
6253
+ pendingRegistryForElement.delete(element);
6254
+ internalUpgrade(element, registeredDefinition, definition);
6255
+ }
6256
+ }
6257
+ }
6258
+ };
6259
+ CustomElementRegistry.prototype.get = function get(tagName) {
6260
+ const NativeCtor = nativeGet.call(nativeRegistry, tagName);
6261
+ if (!isUndefined$1(NativeCtor)) {
6262
+ const definition = globalDefinitionsByTag.get(tagName);
6263
+ if (!isUndefined$1(definition)) {
6264
+ return definition.UserCtor; // defined by the patched custom elements registry
6265
+ }
6266
+ // TODO [#3073]: return undefined rather than the pivot constructor (NativeCtor)
6267
+ return NativeCtor; // return the pivot constructor or constructor that existed before patching
6268
+ }
6269
+ };
6270
+ CustomElementRegistry.prototype.whenDefined = function whenDefined(tagName) {
6271
+ return nativeWhenDefined.call(nativeRegistry, tagName).then((NativeCtor) => {
6272
+ const definition = globalDefinitionsByTag.get(tagName);
6273
+ if (!isUndefined$1(definition)) {
6274
+ return definition.UserCtor;
6275
+ }
6276
+ // TODO [#3073]: return undefined rather than the pivot constructor (NativeCtor)
6277
+ // In this case, the custom element must have been defined before the registry patches
6278
+ // were applied. So return the non-pivot constructor
6279
+ if (isUndefined$1(NativeCtor)) {
6280
+ // Chromium bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1335247
6281
+ // We can patch the correct behavior using customElements.get()
6282
+ return nativeGet.call(nativeRegistry, tagName);
6283
+ }
6284
+ return NativeCtor;
6285
+ });
6286
+ };
6287
+ // This constructor is invoked when we call `new pivotDefinition.UserCtor()`
6288
+ // @ts-ignore
6289
+ window.HTMLElement = function HTMLElement() {
6290
+ // Upgrading case: the pivoting class constructor was run by the browser's
6291
+ // native custom elements and we're in the process of running the
6292
+ // "constructor-call trick" on the natively constructed instance, so just
6293
+ // return that here.
6294
+ // This code path is also called when LWC `new`s a PivotCtor.
6295
+ const instance = upgradingInstance;
6296
+ if (!isUndefined$1(instance)) {
6297
+ upgradingInstance = undefined;
6298
+ return instance;
6299
+ }
6300
+ // Construction case: we need to construct the pivoting instance and return it.
6301
+ // This is possible when the user register it via global registry and instantiate
6302
+ // it via `new Ctor()`.
6303
+ const { constructor } = this;
6304
+ const definition = globalDefinitionsByClass.get(constructor);
6305
+ if (isUndefined$1(definition) || isUndefined$1(definition.PivotCtor)) {
6306
+ // This code path is hit if someone `new`s a class that extends `HTMLElement` without
6307
+ // doing `customElements.define()` first. This matches native browser behavior:
6308
+ // https://stackoverflow.com/a/61883392
6309
+ throw new TypeError('Illegal constructor');
6310
+ }
6311
+ // This constructor is ONLY invoked when it is the user instantiating
6312
+ // an element via new Ctor while Ctor is a registered global constructor.
6313
+ const { PivotCtor, UserCtor } = definition;
6314
+ return new PivotCtor(UserCtor);
6315
+ };
6316
+ HTMLElement.prototype = NativeHTMLElement.prototype;
6317
+ /**
6318
+ * Create a new PivotConstructor for the given tagName, which is capable of being constructed
6319
+ * with a UserConstructor defining the behavior. Passing in the UserConstructor here
6320
+ * is a hint that can be used when registering a custom element with the global custom elements
6321
+ * registry for the first time, which provides certain optimizations. It also marks the UserConstructor
6322
+ * as "safe" to be used when passed in to a PivotConstructor.
6323
+ *
6324
+ * @param tagName - element tag name
6325
+ * @param UserCtor - userland custom element constructor
6326
+ * @returns a new custom element constructor
6327
+ */
6328
+ return function createPivotConstructor(tagName, UserCtor) {
6329
+ tagName = StringToLowerCase.call(tagName);
6330
+ let PivotCtor = pivotCtorByTag.get(tagName);
6331
+ if (isUndefined$1(PivotCtor)) {
6332
+ const definition = getOrCreateDefinitionForConstructor(UserCtor);
6333
+ PivotCtor = createPivotingClass(tagName, definition);
6334
+ // Register a pivoting class as a global custom element
6335
+ nativeDefine.call(nativeRegistry, tagName, PivotCtor);
6336
+ definition.PivotCtor = PivotCtor;
6337
+ // Only cache after nativeDefine has been called, because if it throws an error
6338
+ // (e.g. for an invalid tag name), then we don't want to cache anything.
6339
+ definitionForConstructor.set(UserCtor, definition);
6340
+ pivotCtorByTag.set(tagName, PivotCtor);
6341
+ }
6342
+ // Register a UserConstructor as "safe" to be used within a PivotConstructor
6343
+ registeredUserCtors.add(UserCtor);
6344
+ return PivotCtor;
6345
+ };
6346
+ }
6347
+
6348
+ /*
6349
+ * Copyright (c) 2018, salesforce.com, inc.
6350
+ * All rights reserved.
6351
+ * SPDX-License-Identifier: MIT
6352
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6353
+ */
6354
+ let createScopedConstructor;
6355
+ let CachedHTMLElement; // We only call `createScopedRegistry()` if the browser supports custom elements and
6356
+ // ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is enabled, because we don't want to patch eagerly if the flag is disabled
6357
+ // or we're in a legacy browser.
6358
+
6359
+ if (lwcRuntimeFlags.ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY) {
6360
+ if (hasCustomElements) {
6361
+ // If ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is true, then we eagerly initialize the scoped registry.
6362
+ // It's assumed that ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is set *before* LWC loads, and never changes.
6363
+ //
6364
+ // Why not lazily patch in `createCustomElement`? Well, this could lead to subtle bugs, e.g.:
6365
+ //
6366
+ // 1. LWC loads
6367
+ // 2. `const Ctor = class extends HTMLElement {}`
6368
+ // 3. `lwc.createElement(...)` // here we lazily patch
6369
+ // 4. `customElements.define('x-foo', Ctor)` // throws error because class is bound to stale HTMLElement
6370
+ //
6371
+ // To reduce the risk of this, it's safer to patch the registry eagerly.
6372
+ createScopedConstructor = createScopedRegistry(); // It's important to cache window.HTMLElement here. Otherwise, someone else could overwrite window.HTMLElement (e.g.
6373
+ // another copy of the engine, or another scoping implementation) and we would get "Illegal constructor" errors
6374
+ // because the HTMLElement prototypes are mixed up.
6375
+ //
6376
+ // The reason this happens is that the scoping implementation overwrites window.HTMLElement and expects to work
6377
+ // with that version of HTMLElement. So if you load two copies of the scoping implementation in the same environment,
6378
+ // the second one may accidentally grab window.HTMLElement from the first (when doing `class extends HTMLElement`).
6379
+ // Caching avoids this problem.
6380
+
6381
+ CachedHTMLElement = window.HTMLElement;
6382
+ }
6383
+ } // Creates a constructor that is intended to be used as the UserConstructor in a scoped (pivots) registry.
6384
+ // In this case, the upgradeCallback only needs to be defined once because we create these on-demand,
6385
+ // multiple times per tag name.
6386
+
6387
+
6388
+ const createUserConstructor = (upgradeCallback, connectedCallback, disconnectedCallback, HTMLElementToExtend) => {
6389
+ // TODO [#2972]: this class should expose observedAttributes as necessary
6390
+ return class UserConstructor extends HTMLElementToExtend {
6391
+ constructor() {
6392
+ super();
6393
+ upgradeCallback(this);
6394
+ }
6395
+
6396
+ connectedCallback() {
6397
+ connectedCallback(this);
6398
+ }
6399
+
6400
+ disconnectedCallback() {
6401
+ disconnectedCallback(this);
6402
+ }
6403
+
6404
+ };
6405
+ };
6406
+
6407
+ function createCustomElementScoped(tagName, upgradeCallback, connectedCallback, disconnectedCallback) {
6408
+ if (isUndefined$1(createScopedConstructor) || isUndefined$1(CachedHTMLElement)) {
6409
+ // This error should be impossible to hit
6410
+ throw new Error('The flag ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY must be set to true to use this feature');
6411
+ }
6412
+
6413
+ const UserConstructor = createUserConstructor(upgradeCallback, connectedCallback, disconnectedCallback, CachedHTMLElement);
6414
+ const ScopedConstructor = createScopedConstructor(tagName, UserConstructor);
6415
+ return new ScopedConstructor(UserConstructor);
6416
+ }
6417
+
6418
+ /*
6419
+ * Copyright (c) 2018, salesforce.com, inc.
6420
+ * All rights reserved.
6421
+ * SPDX-License-Identifier: MIT
6422
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6423
+ */
6424
+ /**
6425
+ * We have three modes for creating custom elements:
6426
+ *
6427
+ * 1. Compat (legacy) browser support (e.g. IE11). Totally custom, doesn't rely on native browser APIs.
6428
+ * 2. "Vanilla" custom elements registry. This system actually still allows us to have two LWC components with the
6429
+ * same tag name, via a simple trick: every custom element constructor we define in the registry is basically
6430
+ * the same. It's essentially a dummy `class extends HTMLElement` that accepts an `upgradeCallback` in its
6431
+ * constructor, which allows us to have completely customized functionality for different components.
6432
+ * 3. "Scoped" (or "pivot") custom elements. This relies on a sophisticated system that emulates the "scoped custom
6433
+ * elements registry" proposal, with support for avoiding conflicts in tag names both between LWC components and
6434
+ * between LWC components and third-party elements. This uses a similar trick to #2, but is much more complex
6435
+ * because it must patch the global `customElements` and `HTMLElement` objects.
6436
+ */
6437
+
6438
+ let createCustomElement;
6439
+
6440
+ if (hasCustomElements) {
6441
+ if (lwcRuntimeFlags.ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY) {
6442
+ createCustomElement = createCustomElementScoped;
6443
+ } else {
6444
+ // use global custom elements registry (vanilla)
6445
+ createCustomElement = createCustomElementVanilla;
6446
+ }
6447
+ } else {
6448
+ // no registry available here
6449
+ createCustomElement = createCustomElementCompat;
6450
+ }
6451
+
5838
6452
  /*
5839
6453
  * Copyright (c) 2018, salesforce.com, inc.
5840
6454
  * All rights reserved.
@@ -5895,7 +6509,7 @@ var LWC = (function (exports) {
5895
6509
  function isNull(obj) {
5896
6510
  return obj === null;
5897
6511
  }
5898
- /** version: 2.25.1 */
6512
+ /** version: 2.27.0 */
5899
6513
 
5900
6514
  /*
5901
6515
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5903,65 +6517,6 @@ var LWC = (function (exports) {
5903
6517
  * SPDX-License-Identifier: MIT
5904
6518
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5905
6519
  */
5906
- exports.getCustomElement = void 0;
5907
- exports.defineCustomElement = void 0;
5908
- let HTMLElementConstructor;
5909
- function isCustomElementRegistryAvailable() {
5910
- if (typeof customElements === 'undefined') {
5911
- return false;
5912
- }
5913
- try {
5914
- // dereference HTMLElement global because babel wraps globals in compat mode with a
5915
- // _wrapNativeSuper()
5916
- // This is a problem because LWCUpgradableElement extends renderer.HTMLElementExported which does not
5917
- // get wrapped by babel.
5918
- const HTMLElementAlias = HTMLElement;
5919
- // In case we use compat mode with a modern browser, the compat mode transformation
5920
- // invokes the DOM api with an .apply() or .call() to initialize any DOM api sub-classing,
5921
- // which are not equipped to be initialized that way.
5922
- class clazz extends HTMLElementAlias {
5923
- }
5924
- customElements.define('lwc-test-' + Math.floor(Math.random() * 1000000), clazz);
5925
- new clazz();
5926
- return true;
5927
- }
5928
- catch (_a) {
5929
- return false;
5930
- }
5931
- }
5932
- if (isCustomElementRegistryAvailable()) {
5933
- exports.getCustomElement = customElements.get.bind(customElements);
5934
- exports.defineCustomElement = customElements.define.bind(customElements);
5935
- HTMLElementConstructor = HTMLElement;
5936
- }
5937
- else {
5938
- const registry = Object.create(null);
5939
- const reverseRegistry = new WeakMap();
5940
- exports.defineCustomElement = function define(name, ctor) {
5941
- if (name !== String.prototype.toLowerCase.call(name) || registry[name]) {
5942
- throw new TypeError(`Invalid Registration`);
5943
- }
5944
- registry[name] = ctor;
5945
- reverseRegistry.set(ctor, name);
5946
- };
5947
- exports.getCustomElement = function get(name) {
5948
- return registry[name];
5949
- };
5950
- HTMLElementConstructor = function HTMLElement() {
5951
- if (!(this instanceof HTMLElement)) {
5952
- throw new TypeError(`Invalid Invocation`);
5953
- }
5954
- const { constructor } = this;
5955
- const name = reverseRegistry.get(constructor);
5956
- if (!name) {
5957
- throw new TypeError(`Invalid Construction`);
5958
- }
5959
- const elm = document.createElement(name);
5960
- Object.setPrototypeOf(elm, constructor.prototype);
5961
- return elm;
5962
- };
5963
- HTMLElementConstructor.prototype = HTMLElement.prototype;
5964
- }
5965
6520
  function cloneNode(node, deep) {
5966
6521
  return node.cloneNode(deep);
5967
6522
  }
@@ -6135,9 +6690,7 @@ var LWC = (function (exports) {
6135
6690
  function assertInstanceOfHTMLElement(elm, msg) {
6136
6691
  assert.invariant(elm instanceof HTMLElement, msg);
6137
6692
  }
6138
- const HTMLElementExported = HTMLElementConstructor;
6139
6693
 
6140
- exports.HTMLElementExported = HTMLElementExported;
6141
6694
  exports.addEventListener = addEventListener;
6142
6695
  exports.assertInstanceOfHTMLElement = assertInstanceOfHTMLElement;
6143
6696
  exports.attachShadow = attachShadow;
@@ -6197,6 +6750,8 @@ var LWC = (function (exports) {
6197
6750
  {
6198
6751
  // insertStyleSheet implementation shares a global cache of stylesheet data
6199
6752
  insertStylesheet,
6753
+ // relies on a shared global cache
6754
+ createCustomElement,
6200
6755
  isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
6201
6756
  isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
6202
6757
  });
@@ -6292,36 +6847,44 @@ var LWC = (function (exports) {
6292
6847
  // This WeakSet usage is valid because this functionality is not meant to run in IE11.
6293
6848
  const hydratedCustomElements = new WeakSet();
6294
6849
  function buildCustomElementConstructor(Ctor) {
6850
+ var _a;
6295
6851
  const HtmlPrototype = getComponentHtmlPrototype(Ctor);
6296
- return class extends HtmlPrototype {
6297
- constructor() {
6298
- super();
6299
- if (this.isConnected) {
6300
- // this if block is hit when there's already an un-upgraded element in the DOM with the same tag name.
6301
- hydrateComponent(this, Ctor, {});
6302
- hydratedCustomElements.add(this);
6852
+ const { observedAttributes } = HtmlPrototype;
6853
+ const { attributeChangedCallback } = HtmlPrototype.prototype;
6854
+ return _a = class extends HTMLElement {
6855
+ constructor() {
6856
+ super();
6857
+ if (this.isConnected) {
6858
+ // this if block is hit when there's already an un-upgraded element in the DOM with the same tag name.
6859
+ hydrateComponent(this, Ctor, {});
6860
+ hydratedCustomElements.add(this);
6861
+ }
6862
+ else {
6863
+ createVM(this, Ctor, renderer, {
6864
+ mode: 'open',
6865
+ owner: null,
6866
+ tagName: this.tagName,
6867
+ });
6868
+ }
6303
6869
  }
6304
- else {
6305
- createVM(this, Ctor, renderer, {
6306
- mode: 'open',
6307
- owner: null,
6308
- tagName: this.tagName,
6309
- });
6870
+ connectedCallback() {
6871
+ if (hydratedCustomElements.has(this)) {
6872
+ // This is an un-upgraded element that was hydrated in the constructor.
6873
+ hydratedCustomElements.delete(this);
6874
+ }
6875
+ else {
6876
+ connectRootElement(this);
6877
+ }
6310
6878
  }
6311
- }
6312
- connectedCallback() {
6313
- if (hydratedCustomElements.has(this)) {
6314
- // This is an un-upgraded element that was hydrated in the constructor.
6315
- hydratedCustomElements.delete(this);
6879
+ disconnectedCallback() {
6880
+ disconnectRootElement(this);
6316
6881
  }
6317
- else {
6318
- connectRootElement(this);
6882
+ attributeChangedCallback(name, oldValue, newValue) {
6883
+ attributeChangedCallback.call(this, name, oldValue, newValue);
6319
6884
  }
6320
- }
6321
- disconnectedCallback() {
6322
- disconnectRootElement(this);
6323
- }
6324
- };
6885
+ },
6886
+ _a.observedAttributes = observedAttributes,
6887
+ _a;
6325
6888
  }
6326
6889
 
6327
6890
  /*
@@ -6405,8 +6968,13 @@ var LWC = (function (exports) {
6405
6968
  throw new TypeError(`"createElement" function expects an "is" option with a valid component constructor.`);
6406
6969
  }
6407
6970
 
6408
- const UpgradableConstructor = getUpgradableConstructor(sel, renderer);
6409
- let wasComponentUpgraded = false; // the custom element from the registry is expecting an upgrade callback
6971
+ const {
6972
+ createCustomElement
6973
+ } = renderer; // tagName must be all lowercase, unfortunately, we have legacy code that is
6974
+ // passing `sel` as a camel-case, which makes them invalid custom elements name
6975
+ // the following line guarantees that this does not leaks beyond this point.
6976
+
6977
+ const tagName = StringToLowerCase.call(sel); // the custom element from the registry is expecting an upgrade callback
6410
6978
 
6411
6979
  /**
6412
6980
  * Note: if the upgradable constructor does not expect, or throw when we new it
@@ -6415,9 +6983,9 @@ var LWC = (function (exports) {
6415
6983
  * an upgradable custom element.
6416
6984
  */
6417
6985
 
6418
- const element = new UpgradableConstructor(elm => {
6986
+ const upgradeCallback = elm => {
6419
6987
  createVM(elm, Ctor, renderer, {
6420
- tagName: sel,
6988
+ tagName,
6421
6989
  mode: options.mode !== 'closed' ? 'open' : 'closed',
6422
6990
  owner: null
6423
6991
  });
@@ -6426,15 +6994,21 @@ var LWC = (function (exports) {
6426
6994
  ConnectingSlot.set(elm, connectRootElement);
6427
6995
  DisconnectingSlot.set(elm, disconnectRootElement);
6428
6996
  }
6997
+ };
6429
6998
 
6430
- wasComponentUpgraded = true;
6431
- });
6999
+ const connectedCallback = elm => {
7000
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
7001
+ connectRootElement(elm);
7002
+ }
7003
+ };
6432
7004
 
6433
- if (!wasComponentUpgraded) {
6434
- /* eslint-disable-next-line no-console */
6435
- console.error(`Unexpected tag name "${sel}". This name is a registered custom element, preventing LWC to upgrade the element.`);
6436
- }
7005
+ const disconnectedCallback = elm => {
7006
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
7007
+ disconnectRootElement(elm);
7008
+ }
7009
+ };
6437
7010
 
7011
+ const element = createCustomElement(tagName, upgradeCallback, connectedCallback, disconnectedCallback);
6438
7012
  return element;
6439
7013
  }
6440
7014
 
@@ -6506,7 +7080,7 @@ var LWC = (function (exports) {
6506
7080
  });
6507
7081
  freeze(LightningElement);
6508
7082
  seal(LightningElement.prototype);
6509
- /* version: 2.25.1 */
7083
+ /* version: 2.27.0 */
6510
7084
 
6511
7085
  exports.LightningElement = LightningElement;
6512
7086
  exports.__unstable__ProfilerControl = profilerControl;