lwc 2.25.1 → 2.26.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +890 -411
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +890 -411
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +736 -205
  5. package/dist/engine-dom/iife/es5/engine-dom.js +959 -311
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +888 -224
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +890 -411
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +736 -205
  11. package/dist/engine-dom/umd/es5/engine-dom.js +959 -311
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +888 -224
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +138 -227
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +138 -227
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +3 -3
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +3 -3
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +3 -3
  20. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +3 -3
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +3 -3
  22. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +3 -3
  23. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +3 -3
  24. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +3 -3
  25. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +3 -3
  26. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  27. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  28. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  29. package/dist/wire-service/iife/es5/wire-service.js +2 -2
  30. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  31. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/umd/es5/wire-service.js +2 -2
  34. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  35. package/package.json +8 -8
@@ -120,6 +120,7 @@ var LWC = (function (exports) {
120
120
  setPrototypeOf = Object.setPrototypeOf;
121
121
  var isArray$1 = Array.isArray;
122
122
  var _Array$prototype = Array.prototype,
123
+ ArrayFilter = _Array$prototype.filter,
123
124
  ArrayIndexOf = _Array$prototype.indexOf,
124
125
  ArrayJoin = _Array$prototype.join,
125
126
  ArrayMap = _Array$prototype.map,
@@ -346,7 +347,7 @@ var LWC = (function (exports) {
346
347
  CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
347
348
  return attributeName;
348
349
  }
349
- /** version: 2.25.1 */
350
+ /** version: 2.26.1 */
350
351
 
351
352
  /**
352
353
  * Copyright (C) 2018 salesforce.com, inc.
@@ -440,7 +441,7 @@ var LWC = (function (exports) {
440
441
  patch$1(propName);
441
442
  }
442
443
  }
443
- /** version: 2.25.1 */
444
+ /** version: 2.26.1 */
444
445
 
445
446
  /**
446
447
  * Copyright (C) 2018 salesforce.com, inc.
@@ -458,7 +459,6 @@ var LWC = (function (exports) {
458
459
  DUMMY_TEST_FLAG: null,
459
460
  ENABLE_ELEMENT_PATCH: null,
460
461
  ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST: null,
461
- ENABLE_HMR: null,
462
462
  ENABLE_HTML_COLLECTIONS_PATCH: null,
463
463
  ENABLE_INNER_OUTER_TEXT_PATCH: null,
464
464
  ENABLE_MIXED_SHADOW_MODE: null,
@@ -468,7 +468,8 @@ var LWC = (function (exports) {
468
468
  ENABLE_REACTIVE_SETTER: null,
469
469
  ENABLE_WIRE_SYNC_EMIT: null,
470
470
  ENABLE_LIGHT_GET_ROOT_NODE_PATCH: null,
471
- DISABLE_LIGHT_DOM_UNSCOPED_CSS: null
471
+ DISABLE_LIGHT_DOM_UNSCOPED_CSS: null,
472
+ ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null
472
473
  };
473
474
 
474
475
  if (!_globalThis.lwcRuntimeFlags) {
@@ -1794,7 +1795,9 @@ var LWC = (function (exports) {
1794
1795
  var LightningElement = function LightningElement() {
1795
1796
  // This should be as performant as possible, while any initialization should be done lazily
1796
1797
  if (isNull(vmBeingConstructed)) {
1797
- throw new ReferenceError('Illegal constructor');
1798
+ // Thrown when doing something like `new LightningElement()` or
1799
+ // `class Foo extends LightningElement {}; new Foo()`
1800
+ throw new TypeError('Illegal constructor');
1798
1801
  }
1799
1802
 
1800
1803
  var vm = vmBeingConstructed;
@@ -2766,33 +2769,21 @@ var LWC = (function (exports) {
2766
2769
  {
2767
2770
  // this method should never leak to prod
2768
2771
  throw new ReferenceError();
2769
- }
2772
+ } // tracking active component
2770
2773
  }
2771
2774
 
2772
2775
  function swapTemplate(oldTpl, newTpl) {
2773
2776
 
2774
- if (!lwcRuntimeFlags.ENABLE_HMR) {
2775
- throw new Error('HMR is not enabled');
2776
- }
2777
-
2778
2777
  return false;
2779
2778
  }
2780
2779
 
2781
2780
  function swapComponent(oldComponent, newComponent) {
2782
2781
 
2783
- if (!lwcRuntimeFlags.ENABLE_HMR) {
2784
- throw new Error('HMR is not enabled');
2785
- }
2786
-
2787
2782
  return false;
2788
2783
  }
2789
2784
 
2790
2785
  function swapStyle(oldStyle, newStyle) {
2791
2786
 
2792
- if (!lwcRuntimeFlags.ENABLE_HMR) {
2793
- throw new Error('HMR is not enabled');
2794
- }
2795
-
2796
2787
  return false;
2797
2788
  }
2798
2789
  /*
@@ -3218,14 +3209,17 @@ var LWC = (function (exports) {
3218
3209
  /**
3219
3210
  * This function returns the host style token for a custom element if it
3220
3211
  * exists. Otherwise it returns null.
3212
+ *
3213
+ * A host style token is applied to the component if scoped styles are used.
3221
3214
  */
3222
3215
 
3223
3216
 
3224
3217
  function getStylesheetTokenHost(vnode) {
3225
3218
  var _getComponentInternal = getComponentInternalDef(vnode.ctor),
3226
- stylesheetToken = _getComponentInternal.template.stylesheetToken;
3219
+ template = _getComponentInternal.template;
3227
3220
 
3228
- return !isUndefined$1(stylesheetToken) ? makeHostToken(stylesheetToken) : null;
3221
+ var stylesheetToken = template.stylesheetToken;
3222
+ return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template) ? makeHostToken(stylesheetToken) : null;
3229
3223
  }
3230
3224
 
3231
3225
  function getNearestNativeShadowComponent(vm) {
@@ -3274,78 +3268,6 @@ var LWC = (function (exports) {
3274
3268
 
3275
3269
  return null;
3276
3270
  }
3277
- /*
3278
- * Copyright (c) 2020, salesforce.com, inc.
3279
- * All rights reserved.
3280
- * SPDX-License-Identifier: MIT
3281
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3282
- */
3283
-
3284
-
3285
- function checkHasVM(elm) {
3286
- var hasVM = !isUndefined$1(getAssociatedVMIfPresent(elm));
3287
-
3288
- return hasVM;
3289
- }
3290
-
3291
- function getUpgradableConstructor(tagName, renderer) {
3292
- var getCustomElement = renderer.getCustomElement,
3293
- RendererHTMLElement = renderer.HTMLElementExported,
3294
- defineCustomElement = renderer.defineCustomElement; // Should never get a tag with upper case letter at this point, the compiler should
3295
- // produce only tags with lowercase letters
3296
- // But, for backwards compatibility, we will lower case the tagName
3297
-
3298
- tagName = tagName.toLowerCase();
3299
- var CE = getCustomElement(tagName);
3300
-
3301
- if (!isUndefined$1(CE)) {
3302
- return CE;
3303
- }
3304
- /**
3305
- * LWC Upgradable Element reference to an element that was created
3306
- * via the scoped registry mechanism, and that is ready to be upgraded.
3307
- */
3308
-
3309
-
3310
- CE = /*#__PURE__*/function (_RendererHTMLElement) {
3311
- _inherits(LWCUpgradableElement, _RendererHTMLElement);
3312
-
3313
- var _super5 = _createSuper(LWCUpgradableElement);
3314
-
3315
- function LWCUpgradableElement(upgradeCallback) {
3316
- var _this4;
3317
-
3318
- _classCallCheck(this, LWCUpgradableElement);
3319
-
3320
- _this4 = _super5.call(this);
3321
-
3322
- if (isFunction$1(upgradeCallback)) {
3323
- upgradeCallback(_assertThisInitialized(_this4)); // nothing to do with the result for now
3324
- }
3325
-
3326
- return _this4;
3327
- }
3328
-
3329
- return _createClass(LWCUpgradableElement);
3330
- }(RendererHTMLElement);
3331
-
3332
- if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3333
- CE.prototype.connectedCallback = function () {
3334
- if (checkHasVM(this)) {
3335
- connectRootElement(this);
3336
- }
3337
- };
3338
-
3339
- CE.prototype.disconnectedCallback = function () {
3340
- if (checkHasVM(this)) {
3341
- disconnectRootElement(this);
3342
- }
3343
- };
3344
- }
3345
-
3346
- defineCustomElement(tagName, CE);
3347
- return CE;
3348
- }
3349
3271
  /*
3350
3272
  * Copyright (c) 2018, salesforce.com, inc.
3351
3273
  * All rights reserved.
@@ -3878,7 +3800,7 @@ var LWC = (function (exports) {
3878
3800
  function mountCustomElement(vnode, parent, anchor, renderer) {
3879
3801
  var sel = vnode.sel,
3880
3802
  owner = vnode.owner;
3881
- var UpgradableConstructor = getUpgradableConstructor(sel, renderer);
3803
+ var createCustomElement = renderer.createCustomElement;
3882
3804
  /**
3883
3805
  * Note: if the upgradable constructor does not expect, or throw when we new it
3884
3806
  * with a callback as the first argument, we could implement a more advanced
@@ -3887,10 +3809,30 @@ var LWC = (function (exports) {
3887
3809
  */
3888
3810
 
3889
3811
  var vm;
3890
- var elm = new UpgradableConstructor(function (elm) {
3812
+
3813
+ var upgradeCallback = function upgradeCallback(elm) {
3891
3814
  // the custom element from the registry is expecting an upgrade callback
3892
3815
  vm = createViewModelHook(elm, vnode, renderer);
3893
- });
3816
+ };
3817
+
3818
+ var connectedCallback = function connectedCallback(elm) {
3819
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3820
+ connectRootElement(elm);
3821
+ }
3822
+ };
3823
+
3824
+ var disconnectedCallback = function disconnectedCallback(elm) {
3825
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3826
+ disconnectRootElement(elm);
3827
+ }
3828
+ }; // Should never get a tag with upper case letter at this point; the compiler
3829
+ // should produce only tags with lowercase letters. However, the Java
3830
+ // compiler may generate tagnames with uppercase letters so - for backwards
3831
+ // compatibility, we lower case the tagname here.
3832
+
3833
+
3834
+ var normalizedTagname = sel.toLowerCase();
3835
+ var elm = createCustomElement(normalizedTagname, upgradeCallback, connectedCallback, disconnectedCallback);
3894
3836
  vnode.elm = elm;
3895
3837
  vnode.vm = vm;
3896
3838
  linkNodeToShadow(elm, owner, renderer);
@@ -3898,8 +3840,6 @@ var LWC = (function (exports) {
3898
3840
 
3899
3841
  if (vm) {
3900
3842
  allocateChildren(vnode, vm);
3901
- } else if (vnode.ctor !== UpgradableConstructor) {
3902
- throw new TypeError("Incorrect Component Constructor");
3903
3843
  }
3904
3844
 
3905
3845
  patchElementPropsAndAttrs$1(null, vnode, renderer);
@@ -5874,21 +5814,21 @@ var LWC = (function (exports) {
5874
5814
  var WireContextRegistrationEvent = /*#__PURE__*/function (_CustomEvent) {
5875
5815
  _inherits(WireContextRegistrationEvent, _CustomEvent);
5876
5816
 
5877
- var _super6 = _createSuper(WireContextRegistrationEvent);
5817
+ var _super5 = _createSuper(WireContextRegistrationEvent);
5878
5818
 
5879
5819
  function WireContextRegistrationEvent(adapterToken, _ref3) {
5880
- var _this5;
5820
+ var _this4;
5881
5821
 
5882
5822
  var setNewContext = _ref3.setNewContext,
5883
5823
  setDisconnectedCallback = _ref3.setDisconnectedCallback;
5884
5824
 
5885
5825
  _classCallCheck(this, WireContextRegistrationEvent);
5886
5826
 
5887
- _this5 = _super6.call(this, adapterToken, {
5827
+ _this4 = _super5.call(this, adapterToken, {
5888
5828
  bubbles: true,
5889
5829
  composed: true
5890
5830
  });
5891
- defineProperties(_assertThisInitialized(_this5), {
5831
+ defineProperties(_assertThisInitialized(_this4), {
5892
5832
  setNewContext: {
5893
5833
  value: setNewContext
5894
5834
  },
@@ -5896,7 +5836,7 @@ var LWC = (function (exports) {
5896
5836
  value: setDisconnectedCallback
5897
5837
  }
5898
5838
  });
5899
- return _this5;
5839
+ return _this4;
5900
5840
  }
5901
5841
 
5902
5842
  return _createClass(WireContextRegistrationEvent);
@@ -6535,13 +6475,27 @@ var LWC = (function (exports) {
6535
6475
  // Consequently, hydration mismatches will occur if scoped CSS token classnames
6536
6476
  // are rendered during SSR. This needs to be accounted for when validating.
6537
6477
 
6538
- if (scopedToken) {
6478
+ if (!isNull(scopedToken) || !isNull(stylesheetTokenHost)) {
6539
6479
  if (!isUndefined$1(className)) {
6540
- className = isNull(stylesheetTokenHost) ? "".concat(scopedToken, " ").concat(className) : "".concat(scopedToken, " ").concat(className, " ").concat(stylesheetTokenHost);
6480
+ // The order of the className should be scopedToken className stylesheetTokenHost
6481
+ var classTokens = [scopedToken, className, stylesheetTokenHost];
6482
+ var classNames = ArrayFilter.call(classTokens, function (token) {
6483
+ return !isNull(token);
6484
+ });
6485
+ className = ArrayJoin.call(classNames, ' ');
6541
6486
  } else if (!isUndefined$1(classMap)) {
6542
- classMap = Object.assign(Object.assign(Object.assign({}, classMap), _defineProperty({}, scopedToken, true)), isNull(stylesheetTokenHost) ? {} : _defineProperty({}, stylesheetTokenHost, true));
6487
+ classMap = Object.assign(Object.assign(Object.assign({}, classMap), !isNull(scopedToken) ? _defineProperty({}, scopedToken, true) : {}), !isNull(stylesheetTokenHost) ? _defineProperty({}, stylesheetTokenHost, true) : {});
6543
6488
  } else {
6544
- className = isNull(stylesheetTokenHost) ? "".concat(scopedToken) : "".concat(scopedToken, " ").concat(stylesheetTokenHost);
6489
+ // The order of the className should be scopedToken stylesheetTokenHost
6490
+ var _classTokens = [scopedToken, stylesheetTokenHost];
6491
+
6492
+ var _classNames = ArrayFilter.call(_classTokens, function (token) {
6493
+ return !isNull(token);
6494
+ });
6495
+
6496
+ if (_classNames.length) {
6497
+ className = ArrayJoin.call(_classNames, ' ');
6498
+ }
6545
6499
  }
6546
6500
  }
6547
6501
 
@@ -6712,7 +6666,7 @@ var LWC = (function (exports) {
6712
6666
 
6713
6667
  return ctor;
6714
6668
  }
6715
- /* version: 2.25.1 */
6669
+ /* version: 2.26.1 */
6716
6670
 
6717
6671
  /*
6718
6672
  * Copyright (c) 2018, salesforce.com, inc.
@@ -6863,6 +6817,779 @@ var LWC = (function (exports) {
6863
6817
  insertLocalStylesheet(content, target);
6864
6818
  }
6865
6819
  }
6820
+ /*
6821
+ * Copyright (c) 2020, salesforce.com, inc.
6822
+ * All rights reserved.
6823
+ * SPDX-License-Identifier: MIT
6824
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6825
+ */
6826
+
6827
+
6828
+ function isCustomElementRegistryAvailable() {
6829
+ if (typeof customElements === 'undefined') {
6830
+ return false;
6831
+ }
6832
+
6833
+ try {
6834
+ // dereference HTMLElement global because babel wraps globals in compat mode with a
6835
+ // _wrapNativeSuper()
6836
+ // This is a problem because LWCUpgradableElement extends renderer.HTMLElement which does not
6837
+ // get wrapped by babel.
6838
+ var HTMLElementAlias = HTMLElement; // In case we use compat mode with a modern browser, the compat mode transformation
6839
+ // invokes the DOM api with an .apply() or .call() to initialize any DOM api sub-classing,
6840
+ // which are not equipped to be initialized that way.
6841
+
6842
+ var clazz = /*#__PURE__*/function (_HTMLElementAlias) {
6843
+ _inherits(clazz, _HTMLElementAlias);
6844
+
6845
+ var _super6 = _createSuper(clazz);
6846
+
6847
+ function clazz() {
6848
+ _classCallCheck(this, clazz);
6849
+
6850
+ return _super6.apply(this, arguments);
6851
+ }
6852
+
6853
+ return _createClass(clazz);
6854
+ }(HTMLElementAlias);
6855
+
6856
+ customElements.define('lwc-test-' + Math.floor(Math.random() * 1000000), clazz);
6857
+ new clazz();
6858
+ return true;
6859
+ } catch (_a) {
6860
+ return false;
6861
+ }
6862
+ }
6863
+
6864
+ var hasCustomElements = isCustomElementRegistryAvailable();
6865
+ /*
6866
+ * Copyright (c) 2018, salesforce.com, inc.
6867
+ * All rights reserved.
6868
+ * SPDX-License-Identifier: MIT
6869
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6870
+ */
6871
+ // Creates a custom element for compat (legacy) browser environments
6872
+
6873
+ var createCustomElementCompat = function createCustomElementCompat(tagName, upgradeCallback) {
6874
+ var elm = document.createElement(tagName);
6875
+ upgradeCallback(elm); // nothing to do with the result for now
6876
+
6877
+ return elm;
6878
+ };
6879
+ /*
6880
+ * Copyright (c) 2018, salesforce.com, inc.
6881
+ * All rights reserved.
6882
+ * SPDX-License-Identifier: MIT
6883
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6884
+ */
6885
+
6886
+
6887
+ var cachedConstructors = new Map();
6888
+ var elementsUpgradedOutsideLWC = new WeakSet();
6889
+ var elementBeingUpgradedByLWC = false; // Creates a constructor that is intended to be used as a vanilla custom element, except that the upgradeCallback is
6890
+ // passed in to the constructor so LWC can reuse the same custom element constructor for multiple components.
6891
+ // Another benefit is that only LWC can create components that actually do anything – if you do
6892
+ // `customElements.define('x-foo')`, then you don't have access to the upgradeCallback, so it's a dummy custom element.
6893
+ // This class should be created once per tag name.
6894
+
6895
+ var createUpgradableConstructor = function createUpgradableConstructor(_connectedCallback, _disconnectedCallback) {
6896
+ // TODO [#2972]: this class should expose observedAttributes as necessary
6897
+ return /*#__PURE__*/function (_HTMLElement) {
6898
+ _inherits(UpgradableConstructor, _HTMLElement);
6899
+
6900
+ var _super7 = _createSuper(UpgradableConstructor);
6901
+
6902
+ function UpgradableConstructor(upgradeCallback) {
6903
+ var _this5;
6904
+
6905
+ _classCallCheck(this, UpgradableConstructor);
6906
+
6907
+ _this5 = _super7.call(this); // If the element is not created using lwc.createElement(), e.g. `document.createElement('x-foo')`,
6908
+ // then elementBeingUpgraded will be false
6909
+
6910
+ if (elementBeingUpgradedByLWC) {
6911
+ upgradeCallback(_assertThisInitialized(_this5));
6912
+ } else {
6913
+ // keep track of elements that were not created by lwc.createElement,
6914
+ // so we can ignore their lifecycle hooks
6915
+ elementsUpgradedOutsideLWC.add(_assertThisInitialized(_this5)); // TODO [#2970]: LWC elements cannot be upgraded via new Ctor()
6916
+ // Do we want to support this? Throw an error? Currently for backwards compat it's a no-op.
6917
+ }
6918
+
6919
+ return _this5;
6920
+ }
6921
+
6922
+ _createClass(UpgradableConstructor, [{
6923
+ key: "connectedCallback",
6924
+ value: function connectedCallback() {
6925
+ if (!elementsUpgradedOutsideLWC.has(this)) {
6926
+ _connectedCallback(this);
6927
+ }
6928
+ }
6929
+ }, {
6930
+ key: "disconnectedCallback",
6931
+ value: function disconnectedCallback() {
6932
+ if (!elementsUpgradedOutsideLWC.has(this)) {
6933
+ _disconnectedCallback(this);
6934
+ }
6935
+ }
6936
+ }]);
6937
+
6938
+ return UpgradableConstructor;
6939
+ }( /*#__PURE__*/_wrapNativeSuper(HTMLElement));
6940
+ };
6941
+
6942
+ var createCustomElementVanilla = function createCustomElementVanilla(tagName, upgradeCallback, connectedCallback, disconnectedCallback) {
6943
+ // use global custom elements registry
6944
+ var UpgradableConstructor = cachedConstructors.get(tagName);
6945
+
6946
+ if (isUndefined$1(UpgradableConstructor)) {
6947
+ if (!isUndefined$1(customElements.get(tagName))) {
6948
+ throw new Error("Unexpected tag name \"".concat(tagName, "\". This name is a registered custom element, preventing LWC to upgrade the element."));
6949
+ }
6950
+
6951
+ UpgradableConstructor = createUpgradableConstructor(connectedCallback, disconnectedCallback);
6952
+ customElements.define(tagName, UpgradableConstructor);
6953
+ cachedConstructors.set(tagName, UpgradableConstructor);
6954
+ }
6955
+
6956
+ elementBeingUpgradedByLWC = true;
6957
+
6958
+ try {
6959
+ return new UpgradableConstructor(upgradeCallback);
6960
+ } finally {
6961
+ elementBeingUpgradedByLWC = false;
6962
+ }
6963
+ };
6964
+ /*
6965
+ * Copyright (c) 2020, salesforce.com, inc.
6966
+ * All rights reserved.
6967
+ * SPDX-License-Identifier: MIT
6968
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6969
+ */
6970
+
6971
+ /**
6972
+ * Create a scoped registry, i.e. a function that can create custom elements whose tag names
6973
+ * do not conflict with vanilla custom elements having the same tag name.
6974
+ */
6975
+
6976
+
6977
+ function createScopedRegistry() {
6978
+ if (!hasCustomElements) {
6979
+ // This code should never be reached, because we don't use the pivot registry if
6980
+ // custom elements are unavailable.
6981
+ throw new Error('Custom elements are not supported in this environment.');
6982
+ }
6983
+
6984
+ var _window = window,
6985
+ NativeHTMLElement = _window.HTMLElement;
6986
+ var _NativeHTMLElement$pr = NativeHTMLElement.prototype,
6987
+ nativeHasAttribute = _NativeHTMLElement$pr.hasAttribute,
6988
+ nativeSetAttribute = _NativeHTMLElement$pr.setAttribute,
6989
+ nativeRemoveAttribute = _NativeHTMLElement$pr.removeAttribute,
6990
+ nativeGetAttribute = _NativeHTMLElement$pr.getAttribute;
6991
+ var definitionForElement = new WeakMap();
6992
+ var pendingRegistryForElement = new WeakMap();
6993
+ var definitionForConstructor = new WeakMap();
6994
+ var registeredUserCtors = new WeakSet();
6995
+ var pivotCtorByTag = new Map();
6996
+ var globalDefinitionsByTag = new Map();
6997
+ var globalDefinitionsByClass = new Map();
6998
+ var awaitingUpgrade = new Map();
6999
+ var EMPTY_SET = new Set();
7000
+
7001
+ function createDefinitionRecord(constructor) {
7002
+ var _a;
7003
+
7004
+ var _constructor$prototyp = constructor.prototype,
7005
+ connectedCallback = _constructor$prototyp.connectedCallback,
7006
+ disconnectedCallback = _constructor$prototyp.disconnectedCallback,
7007
+ adoptedCallback = _constructor$prototyp.adoptedCallback,
7008
+ attributeChangedCallback = _constructor$prototyp.attributeChangedCallback;
7009
+ var observedAttributes = new Set((_a = constructor.observedAttributes) !== null && _a !== void 0 ? _a : []);
7010
+ return {
7011
+ UserCtor: constructor,
7012
+ PivotCtor: undefined,
7013
+ connectedCallback: connectedCallback,
7014
+ disconnectedCallback: disconnectedCallback,
7015
+ adoptedCallback: adoptedCallback,
7016
+ attributeChangedCallback: attributeChangedCallback,
7017
+ observedAttributes: observedAttributes
7018
+ };
7019
+ } // Helper to create stand-in element for each tagName registered that delegates out to the registry for the given
7020
+ // element. Note that the `registeredDefinition` represents the constructor that was used to register during
7021
+ // `customElements.define()`. Whereas the `pivotDefinition` represents the constructor that is passed when the pivot
7022
+ // constructor is invoked with another constructor.
7023
+
7024
+
7025
+ function createPivotingClass(tagName, registeredDefinition) {
7026
+ var PivotCtor = /*#__PURE__*/function (_NativeHTMLElement) {
7027
+ _inherits(PivotCtor, _NativeHTMLElement);
7028
+
7029
+ var _super8 = _createSuper(PivotCtor);
7030
+
7031
+ function PivotCtor(UserCtor) {
7032
+ var _this6;
7033
+
7034
+ _classCallCheck(this, PivotCtor);
7035
+
7036
+ // This constructor can only be invoked by:
7037
+ // a) the browser instantiating an element from parsing or via document.createElement.
7038
+ // b) LWC new PivotClass (This constructor is NOT observable/accessible in user-land).
7039
+ // b) new UserClass.
7040
+ // When LWC instantiates it, it will pass the upgrading definition as an argument
7041
+ // If the caller signals via UserCtor that this is in fact a controlled
7042
+ // definition, we use that one, otherwise fallback to the global
7043
+ // internal registry.
7044
+ _this6 = _super8.call(this);
7045
+ var userCtorIsDefined = !isUndefined$1(UserCtor);
7046
+
7047
+ if (userCtorIsDefined) {
7048
+ if (!isConstructor(UserCtor)) {
7049
+ throw new TypeError("Failed to create custom element: the provided constructor is not a constructor.");
7050
+ }
7051
+
7052
+ if (!registeredUserCtors.has(UserCtor)) {
7053
+ throw new Error("Failed to create custom element: the provided constructor is unregistered: ".concat(UserCtor.name, "."));
7054
+ }
7055
+ }
7056
+
7057
+ var definition = userCtorIsDefined ? getOrCreateDefinitionForConstructor(UserCtor) : globalDefinitionsByTag.get(tagName);
7058
+
7059
+ if (!isUndefined$1(definition)) {
7060
+ internalUpgrade(_assertThisInitialized(_this6), registeredDefinition, definition);
7061
+ } else {
7062
+ // This is the case in which there is no global definition, and
7063
+ // it is not handled by LWC (otherwise it will have a valid UserCtor)
7064
+ // so we need to add it to the pending queue just in case it eventually
7065
+ // gets defined in the global registry.
7066
+ pendingRegistryForElement.set(_assertThisInitialized(_this6), registeredDefinition);
7067
+ }
7068
+
7069
+ return _this6;
7070
+ }
7071
+
7072
+ _createClass(PivotCtor, [{
7073
+ key: "connectedCallback",
7074
+ value: function connectedCallback() {
7075
+ var _a;
7076
+
7077
+ var definition = definitionForElement.get(this);
7078
+
7079
+ if (!isUndefined$1(definition)) {
7080
+ // Delegate out to user callback
7081
+ (_a = definition.connectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
7082
+ } else {
7083
+ // Register for upgrade when defined (only when connected, so we don't leak)
7084
+ var awaiting = awaitingUpgrade.get(tagName);
7085
+
7086
+ if (isUndefined$1(awaiting)) {
7087
+ awaitingUpgrade.set(tagName, awaiting = new Set());
7088
+ }
7089
+
7090
+ awaiting.add(this);
7091
+ }
7092
+ }
7093
+ }, {
7094
+ key: "disconnectedCallback",
7095
+ value: function disconnectedCallback() {
7096
+ var _a;
7097
+
7098
+ var definition = definitionForElement.get(this);
7099
+
7100
+ if (!isUndefined$1(definition)) {
7101
+ // Delegate out to user callback
7102
+ (_a = definition.disconnectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
7103
+ } else {
7104
+ // Un-register for upgrade when defined (so we don't leak)
7105
+ var awaiting = awaitingUpgrade.get(tagName); // At this point, awaiting should never be undefined, because connectedCallback
7106
+ // must have been called before disconnectedCallback. But just to be safe, we check
7107
+
7108
+ if (!isUndefined$1(awaiting)) {
7109
+ awaiting.delete(this);
7110
+ }
7111
+ }
7112
+ }
7113
+ }, {
7114
+ key: "adoptedCallback",
7115
+ value: function adoptedCallback() {
7116
+ var _a;
7117
+
7118
+ var definition = definitionForElement.get(this);
7119
+ (_a = definition === null || definition === void 0 ? void 0 : definition.adoptedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
7120
+ }
7121
+ }, {
7122
+ key: "attributeChangedCallback",
7123
+ value: function attributeChangedCallback(name, oldValue, newValue) {
7124
+ var _a;
7125
+
7126
+ var definition = definitionForElement.get(this); // if both definitions are the same, then the observedAttributes is the same,
7127
+ // but if they are different, only if the runtime definition has the attribute
7128
+ // marked as observed, then it should invoke attributeChangedCallback.
7129
+
7130
+ if (registeredDefinition === definition || (definition === null || definition === void 0 ? void 0 : definition.observedAttributes.has(name))) {
7131
+ (_a = definition.attributeChangedCallback) === null || _a === void 0 ? void 0 : _a.apply(this, [name, oldValue, newValue]);
7132
+ }
7133
+ }
7134
+ }]);
7135
+
7136
+ return PivotCtor;
7137
+ }(NativeHTMLElement);
7138
+
7139
+ PivotCtor.observedAttributes = _toConsumableArray(registeredDefinition.observedAttributes);
7140
+ return PivotCtor;
7141
+ }
7142
+
7143
+ function getNewObservedAttributes(registeredDefinition, pivotDefinition) {
7144
+ var observedAttributes = pivotDefinition.observedAttributes,
7145
+ attributeChangedCallback = pivotDefinition.attributeChangedCallback;
7146
+
7147
+ if (observedAttributes.size === 0 || isUndefined$1(attributeChangedCallback)) {
7148
+ // This instance does not need to observe any attributes, no need to patch
7149
+ return EMPTY_SET;
7150
+ } // Natively, the attributes observed by the registered definition are going to be taken
7151
+ // care of by the browser, only the difference between the two sets has to be taken
7152
+ // care by the patched version.
7153
+
7154
+
7155
+ return new Set(_toConsumableArray(pivotDefinition.observedAttributes).filter(function (x) {
7156
+ return !registeredDefinition.observedAttributes.has(x);
7157
+ }));
7158
+ }
7159
+
7160
+ function throwAsyncError(error) {
7161
+ // Per native custom element behavior, errors thrown in attributeChangedCallback
7162
+ // become unhandled async errors. We use setTimeout() instead of Promise.resolve()
7163
+ // to make it an unhandled error rather than an unhandled rejection.
7164
+ setTimeout(function () {
7165
+ throw error;
7166
+ });
7167
+ } // Helper to patch `setAttribute`/`getAttribute` to implement `attributeChangedCallback`.
7168
+ // Why is this necessary? Well basically, you can't change the `observedAttributes` after
7169
+ // a custom element is defined. So with pivots, if two classes share the same tag name,
7170
+ // and the second class observes attributes that aren't observed by the first one,
7171
+ // then those attributes can never be observed by the native `observedAttributes` system.
7172
+ // So we have to simulate it by patching `getAttribute`/`removeAttribute`. Note that
7173
+ // we only do this when absolutely necessary, though; i.e. because we've determined
7174
+ // that we aren't observing the attributes we need to.
7175
+
7176
+
7177
+ function patchAttributes(instance, registeredDefinition, pivotDefinition) {
7178
+ var newObservedAttributes = getNewObservedAttributes(registeredDefinition, pivotDefinition);
7179
+
7180
+ if (newObservedAttributes.size === 0) {
7181
+ return;
7182
+ }
7183
+
7184
+ var attributeChangedCallback = pivotDefinition.attributeChangedCallback; // Patch the instance.
7185
+ // Note we use the native `getAttribute` rather than the super's `getAttribute` because
7186
+ // we don't actually want it to be observable that we're calling `getAttribute` from
7187
+ // `setAttribute` and `removeAttribute`.
7188
+ // TODO [#2994]: this should handle reflected properties such as `ariaLabel` and `role`.
7189
+
7190
+ defineProperties(instance, {
7191
+ setAttribute: {
7192
+ value: function setAttribute(name, value) {
7193
+ if (newObservedAttributes.has(name)) {
7194
+ var old = nativeGetAttribute.call(this, name);
7195
+ nativeSetAttribute.call(this, name, value);
7196
+
7197
+ try {
7198
+ attributeChangedCallback.call(this, name, old, value + '');
7199
+ } catch (error) {
7200
+ throwAsyncError(error);
7201
+ }
7202
+ } else {
7203
+ nativeSetAttribute.call(this, name, value);
7204
+ }
7205
+ },
7206
+ writable: true,
7207
+ enumerable: true,
7208
+ configurable: true
7209
+ },
7210
+ removeAttribute: {
7211
+ value: function removeAttribute(name) {
7212
+ if (newObservedAttributes.has(name)) {
7213
+ var old = nativeGetAttribute.call(this, name);
7214
+ nativeRemoveAttribute.call(this, name);
7215
+
7216
+ try {
7217
+ attributeChangedCallback.call(this, name, old, null);
7218
+ } catch (error) {
7219
+ throwAsyncError(error);
7220
+ }
7221
+ } else {
7222
+ nativeRemoveAttribute.call(this, name);
7223
+ }
7224
+ },
7225
+ writable: true,
7226
+ enumerable: true,
7227
+ configurable: true
7228
+ }
7229
+ });
7230
+ }
7231
+
7232
+ function patchAttributesDuringUpgrade(instance, registeredDefinition, pivotDefinition) {
7233
+ // The below case patches observed attributes for the case where the HTML element is upgraded
7234
+ // from a pre-existing one in the DOM.
7235
+ var newObservedAttributes = getNewObservedAttributes(registeredDefinition, pivotDefinition);
7236
+
7237
+ if (getNewObservedAttributes(registeredDefinition, pivotDefinition).size === 0) {
7238
+ return;
7239
+ }
7240
+
7241
+ var attributeChangedCallback = pivotDefinition.attributeChangedCallback; // Approximate observedAttributes from the user class, but only for the new observed attributes
7242
+
7243
+ newObservedAttributes.forEach(function (name) {
7244
+ if (nativeHasAttribute.call(instance, name)) {
7245
+ var newValue = nativeGetAttribute.call(instance, name);
7246
+ attributeChangedCallback.call(instance, name, null, newValue);
7247
+ }
7248
+ });
7249
+ } // User extends this HTMLElement, which returns the CE being upgraded
7250
+
7251
+
7252
+ var upgradingInstance; // Helper to upgrade an instance with a CE definition using "constructor call trick"
7253
+
7254
+ function internalUpgrade(instance, registeredDefinition, pivotDefinition) {
7255
+ setPrototypeOf(instance, pivotDefinition.UserCtor.prototype);
7256
+ definitionForElement.set(instance, pivotDefinition); // attributes patches when needed
7257
+
7258
+ if (pivotDefinition !== registeredDefinition) {
7259
+ patchAttributes(instance, registeredDefinition, pivotDefinition);
7260
+ } // Tricking the construction path to believe that a new instance is being created,
7261
+ // that way it will execute the super initialization mechanism but the HTMLElement
7262
+ // constructor will reuse the instance by returning the upgradingInstance.
7263
+ // This is by far the most important piece of the puzzle
7264
+
7265
+
7266
+ upgradingInstance = instance; // By `new`ing the UserCtor, we now jump to the constructor for the overridden global HTMLElement
7267
+ // The reason this happens is that the UserCtor extends HTMLElement, so it calls the `super()`.
7268
+ // Note that `upgradingInstance` is explicitly handled in the HTMLElement constructor.
7269
+
7270
+ new pivotDefinition.UserCtor();
7271
+ patchAttributesDuringUpgrade(instance, registeredDefinition, pivotDefinition);
7272
+ }
7273
+
7274
+ function isConstructor(constructor) {
7275
+ return isFunction$1(constructor) && isObject(constructor.prototype);
7276
+ }
7277
+
7278
+ function getOrCreateDefinitionForConstructor(constructor) {
7279
+ if (!isConstructor(constructor)) {
7280
+ throw new TypeError('The referenced constructor is not a constructor.');
7281
+ }
7282
+
7283
+ var definition = definitionForConstructor.get(constructor);
7284
+
7285
+ if (!isUndefined$1(definition)) {
7286
+ return definition;
7287
+ }
7288
+
7289
+ return createDefinitionRecord(constructor);
7290
+ }
7291
+
7292
+ var _window2 = window,
7293
+ nativeRegistry = _window2.customElements;
7294
+ var nativeDefine = nativeRegistry.define,
7295
+ nativeWhenDefined = nativeRegistry.whenDefined,
7296
+ nativeGet = nativeRegistry.get; // patch for the global registry define mechanism
7297
+
7298
+ CustomElementRegistry.prototype.define = function define(tagName, constructor, options) {
7299
+ if (options && options.extends) {
7300
+ // TODO [#2983]: should we support `extends`?
7301
+ throw new DOMException('NotSupportedError: "extends" key in customElements.define() options is not supported.');
7302
+ }
7303
+
7304
+ if (globalDefinitionsByTag.has(tagName)) {
7305
+ throw new DOMException("Failed to execute 'define' on 'CustomElementRegistry': the name \"".concat(tagName, "\" has already been used with this registry"));
7306
+ }
7307
+
7308
+ if (!isUndefined$1(globalDefinitionsByClass.get(constructor))) {
7309
+ throw new DOMException("Failed to execute 'define' on 'CustomElementRegistry': this constructor has already been used with this registry");
7310
+ }
7311
+
7312
+ var definition = getOrCreateDefinitionForConstructor(constructor);
7313
+ registeredUserCtors.add(constructor);
7314
+ var PivotCtor = pivotCtorByTag.get(tagName);
7315
+
7316
+ if (isUndefined$1(PivotCtor)) {
7317
+ PivotCtor = createPivotingClass(tagName, definition); // Register a pivoting class which will handle global registry initializations
7318
+
7319
+ nativeDefine.call(nativeRegistry, tagName, PivotCtor);
7320
+ } // Only cache after nativeDefine has been called, because if it throws an error
7321
+ // (e.g. for an invalid tag name), then we don't want to cache anything.
7322
+
7323
+
7324
+ definitionForConstructor.set(constructor, definition);
7325
+ pivotCtorByTag.set(tagName, PivotCtor);
7326
+ globalDefinitionsByTag.set(tagName, definition);
7327
+ globalDefinitionsByClass.set(constructor, definition); // For globally defined custom elements, the definition associated
7328
+ // to the UserCtor has a back-pointer to PivotCtor in case the user
7329
+ // new the UserCtor, so we know how to create the underlying element.
7330
+
7331
+ definition.PivotCtor = PivotCtor; // Upgrade any elements created in this scope before customElements.define
7332
+ // was called, which should be exhibited by the following steps:
7333
+ // 1) LWC registers a tagName for an LWC component.
7334
+ // 2) Element with same tagName is created with document.createElement()
7335
+ // and inserted into DOM.
7336
+ // 3) customElements.define() is called with tagName and non-LWC constructor.
7337
+ // This requires immediate upgrade when the new global tagName is defined.
7338
+
7339
+ var awaiting = awaitingUpgrade.get(tagName);
7340
+
7341
+ if (!isUndefined$1(awaiting)) {
7342
+ awaitingUpgrade.delete(tagName);
7343
+
7344
+ var _iterator6 = _createForOfIteratorHelper(awaiting),
7345
+ _step6;
7346
+
7347
+ try {
7348
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
7349
+ var element = _step6.value;
7350
+ var registeredDefinition = pendingRegistryForElement.get(element); // At this point, registeredDefinition should never be undefined because awaitingUpgrade
7351
+ // is only populated when we haven't run internalUpgrade yet, and we only populate
7352
+ // pendingRegistryForElement when internalUpgrade hasn't run yet.
7353
+ // But just to be safe, we check.
7354
+
7355
+ if (!isUndefined$1(registeredDefinition)) {
7356
+ pendingRegistryForElement.delete(element);
7357
+ internalUpgrade(element, registeredDefinition, definition);
7358
+ }
7359
+ }
7360
+ } catch (err) {
7361
+ _iterator6.e(err);
7362
+ } finally {
7363
+ _iterator6.f();
7364
+ }
7365
+ }
7366
+ };
7367
+
7368
+ CustomElementRegistry.prototype.get = function get(tagName) {
7369
+ var NativeCtor = nativeGet.call(nativeRegistry, tagName);
7370
+
7371
+ if (!isUndefined$1(NativeCtor)) {
7372
+ var definition = globalDefinitionsByTag.get(tagName);
7373
+
7374
+ if (!isUndefined$1(definition)) {
7375
+ return definition.UserCtor; // defined by the patched custom elements registry
7376
+ } // TODO [#3073]: return undefined rather than the pivot constructor (NativeCtor)
7377
+
7378
+
7379
+ return NativeCtor; // return the pivot constructor or constructor that existed before patching
7380
+ }
7381
+ };
7382
+
7383
+ CustomElementRegistry.prototype.whenDefined = function whenDefined(tagName) {
7384
+ return nativeWhenDefined.call(nativeRegistry, tagName).then(function (NativeCtor) {
7385
+ var definition = globalDefinitionsByTag.get(tagName);
7386
+
7387
+ if (!isUndefined$1(definition)) {
7388
+ return definition.UserCtor;
7389
+ } // TODO [#3073]: return undefined rather than the pivot constructor (NativeCtor)
7390
+ // In this case, the custom element must have been defined before the registry patches
7391
+ // were applied. So return the non-pivot constructor
7392
+
7393
+
7394
+ if (isUndefined$1(NativeCtor)) {
7395
+ // Chromium bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1335247
7396
+ // We can patch the correct behavior using customElements.get()
7397
+ return nativeGet.call(nativeRegistry, tagName);
7398
+ }
7399
+
7400
+ return NativeCtor;
7401
+ });
7402
+ }; // This constructor is invoked when we call `new pivotDefinition.UserCtor()`
7403
+ // @ts-ignore
7404
+
7405
+
7406
+ window.HTMLElement = function HTMLElement() {
7407
+ // Upgrading case: the pivoting class constructor was run by the browser's
7408
+ // native custom elements and we're in the process of running the
7409
+ // "constructor-call trick" on the natively constructed instance, so just
7410
+ // return that here.
7411
+ // This code path is also called when LWC `new`s a PivotCtor.
7412
+ var instance = upgradingInstance;
7413
+
7414
+ if (!isUndefined$1(instance)) {
7415
+ upgradingInstance = undefined;
7416
+ return instance;
7417
+ } // Construction case: we need to construct the pivoting instance and return it.
7418
+ // This is possible when the user register it via global registry and instantiate
7419
+ // it via `new Ctor()`.
7420
+
7421
+
7422
+ var constructor = this.constructor;
7423
+ var definition = globalDefinitionsByClass.get(constructor);
7424
+
7425
+ if (isUndefined$1(definition) || isUndefined$1(definition.PivotCtor)) {
7426
+ // This code path is hit if someone `new`s a class that extends `HTMLElement` without
7427
+ // doing `customElements.define()` first. This matches native browser behavior:
7428
+ // https://stackoverflow.com/a/61883392
7429
+ throw new TypeError('Illegal constructor');
7430
+ } // This constructor is ONLY invoked when it is the user instantiating
7431
+ // an element via new Ctor while Ctor is a registered global constructor.
7432
+
7433
+
7434
+ var PivotCtor = definition.PivotCtor,
7435
+ UserCtor = definition.UserCtor;
7436
+ return new PivotCtor(UserCtor);
7437
+ };
7438
+
7439
+ HTMLElement.prototype = NativeHTMLElement.prototype;
7440
+ /**
7441
+ * Create a new PivotConstructor for the given tagName, which is capable of being constructed
7442
+ * with a UserConstructor defining the behavior. Passing in the UserConstructor here
7443
+ * is a hint that can be used when registering a custom element with the global custom elements
7444
+ * registry for the first time, which provides certain optimizations. It also marks the UserConstructor
7445
+ * as "safe" to be used when passed in to a PivotConstructor.
7446
+ *
7447
+ * @param tagName - element tag name
7448
+ * @param UserCtor - userland custom element constructor
7449
+ * @returns a new custom element constructor
7450
+ */
7451
+
7452
+ return function createPivotConstructor(tagName, UserCtor) {
7453
+ tagName = StringToLowerCase.call(tagName);
7454
+ var PivotCtor = pivotCtorByTag.get(tagName);
7455
+
7456
+ if (isUndefined$1(PivotCtor)) {
7457
+ var definition = getOrCreateDefinitionForConstructor(UserCtor);
7458
+ PivotCtor = createPivotingClass(tagName, definition); // Register a pivoting class as a global custom element
7459
+
7460
+ nativeDefine.call(nativeRegistry, tagName, PivotCtor);
7461
+ definition.PivotCtor = PivotCtor; // Only cache after nativeDefine has been called, because if it throws an error
7462
+ // (e.g. for an invalid tag name), then we don't want to cache anything.
7463
+
7464
+ definitionForConstructor.set(UserCtor, definition);
7465
+ pivotCtorByTag.set(tagName, PivotCtor);
7466
+ } // Register a UserConstructor as "safe" to be used within a PivotConstructor
7467
+
7468
+
7469
+ registeredUserCtors.add(UserCtor);
7470
+ return PivotCtor;
7471
+ };
7472
+ }
7473
+ /*
7474
+ * Copyright (c) 2018, salesforce.com, inc.
7475
+ * All rights reserved.
7476
+ * SPDX-License-Identifier: MIT
7477
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7478
+ */
7479
+
7480
+
7481
+ var createScopedConstructor;
7482
+ var CachedHTMLElement; // We only call `createScopedRegistry()` if the browser supports custom elements and
7483
+ // ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is enabled, because we don't want to patch eagerly if the flag is disabled
7484
+ // or we're in a legacy browser.
7485
+
7486
+ if (lwcRuntimeFlags.ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY) {
7487
+ if (hasCustomElements) {
7488
+ // If ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is true, then we eagerly initialize the scoped registry.
7489
+ // It's assumed that ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is set *before* LWC loads, and never changes.
7490
+ //
7491
+ // Why not lazily patch in `createCustomElement`? Well, this could lead to subtle bugs, e.g.:
7492
+ //
7493
+ // 1. LWC loads
7494
+ // 2. `const Ctor = class extends HTMLElement {}`
7495
+ // 3. `lwc.createElement(...)` // here we lazily patch
7496
+ // 4. `customElements.define('x-foo', Ctor)` // throws error because class is bound to stale HTMLElement
7497
+ //
7498
+ // To reduce the risk of this, it's safer to patch the registry eagerly.
7499
+ createScopedConstructor = createScopedRegistry(); // It's important to cache window.HTMLElement here. Otherwise, someone else could overwrite window.HTMLElement (e.g.
7500
+ // another copy of the engine, or another scoping implementation) and we would get "Illegal constructor" errors
7501
+ // because the HTMLElement prototypes are mixed up.
7502
+ //
7503
+ // The reason this happens is that the scoping implementation overwrites window.HTMLElement and expects to work
7504
+ // with that version of HTMLElement. So if you load two copies of the scoping implementation in the same environment,
7505
+ // the second one may accidentally grab window.HTMLElement from the first (when doing `class extends HTMLElement`).
7506
+ // Caching avoids this problem.
7507
+
7508
+ CachedHTMLElement = window.HTMLElement;
7509
+ }
7510
+ } // Creates a constructor that is intended to be used as the UserConstructor in a scoped (pivots) registry.
7511
+ // In this case, the upgradeCallback only needs to be defined once because we create these on-demand,
7512
+ // multiple times per tag name.
7513
+
7514
+
7515
+ var createUserConstructor = function createUserConstructor(upgradeCallback, _connectedCallback2, _disconnectedCallback2, HTMLElementToExtend) {
7516
+ // TODO [#2972]: this class should expose observedAttributes as necessary
7517
+ return /*#__PURE__*/function (_HTMLElementToExtend) {
7518
+ _inherits(UserConstructor, _HTMLElementToExtend);
7519
+
7520
+ var _super9 = _createSuper(UserConstructor);
7521
+
7522
+ function UserConstructor() {
7523
+ var _this7;
7524
+
7525
+ _classCallCheck(this, UserConstructor);
7526
+
7527
+ _this7 = _super9.call(this);
7528
+ upgradeCallback(_assertThisInitialized(_this7));
7529
+ return _this7;
7530
+ }
7531
+
7532
+ _createClass(UserConstructor, [{
7533
+ key: "connectedCallback",
7534
+ value: function connectedCallback() {
7535
+ _connectedCallback2(this);
7536
+ }
7537
+ }, {
7538
+ key: "disconnectedCallback",
7539
+ value: function disconnectedCallback() {
7540
+ _disconnectedCallback2(this);
7541
+ }
7542
+ }]);
7543
+
7544
+ return UserConstructor;
7545
+ }(HTMLElementToExtend);
7546
+ };
7547
+
7548
+ function createCustomElementScoped(tagName, upgradeCallback, connectedCallback, disconnectedCallback) {
7549
+ if (isUndefined$1(createScopedConstructor) || isUndefined$1(CachedHTMLElement)) {
7550
+ // This error should be impossible to hit
7551
+ throw new Error('The flag ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY must be set to true to use this feature');
7552
+ }
7553
+
7554
+ var UserConstructor = createUserConstructor(upgradeCallback, connectedCallback, disconnectedCallback, CachedHTMLElement);
7555
+ var ScopedConstructor = createScopedConstructor(tagName, UserConstructor);
7556
+ return new ScopedConstructor(UserConstructor);
7557
+ }
7558
+ /*
7559
+ * Copyright (c) 2018, salesforce.com, inc.
7560
+ * All rights reserved.
7561
+ * SPDX-License-Identifier: MIT
7562
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7563
+ */
7564
+
7565
+ /**
7566
+ * We have three modes for creating custom elements:
7567
+ *
7568
+ * 1. Compat (legacy) browser support (e.g. IE11). Totally custom, doesn't rely on native browser APIs.
7569
+ * 2. "Vanilla" custom elements registry. This system actually still allows us to have two LWC components with the
7570
+ * same tag name, via a simple trick: every custom element constructor we define in the registry is basically
7571
+ * the same. It's essentially a dummy `class extends HTMLElement` that accepts an `upgradeCallback` in its
7572
+ * constructor, which allows us to have completely customized functionality for different components.
7573
+ * 3. "Scoped" (or "pivot") custom elements. This relies on a sophisticated system that emulates the "scoped custom
7574
+ * elements registry" proposal, with support for avoiding conflicts in tag names both between LWC components and
7575
+ * between LWC components and third-party elements. This uses a similar trick to #2, but is much more complex
7576
+ * because it must patch the global `customElements` and `HTMLElement` objects.
7577
+ */
7578
+
7579
+
7580
+ var createCustomElement;
7581
+
7582
+ if (hasCustomElements) {
7583
+ if (lwcRuntimeFlags.ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY) {
7584
+ createCustomElement = createCustomElementScoped;
7585
+ } else {
7586
+ // use global custom elements registry (vanilla)
7587
+ createCustomElement = createCustomElementVanilla;
7588
+ }
7589
+ } else {
7590
+ // no registry available here
7591
+ createCustomElement = createCustomElementCompat;
7592
+ }
6866
7593
  /*
6867
7594
  * Copyright (c) 2018, salesforce.com, inc.
6868
7595
  * All rights reserved.
@@ -6931,7 +7658,7 @@ var LWC = (function (exports) {
6931
7658
  function isNull(obj) {
6932
7659
  return obj === null;
6933
7660
  }
6934
- /** version: 2.25.1 */
7661
+ /** version: 2.26.1 */
6935
7662
 
6936
7663
  /*
6937
7664
  * Copyright (c) 2018, salesforce.com, inc.
@@ -6941,87 +7668,6 @@ var LWC = (function (exports) {
6941
7668
  */
6942
7669
 
6943
7670
 
6944
- exports.getCustomElement = void 0;
6945
- exports.defineCustomElement = void 0;
6946
- var HTMLElementConstructor;
6947
-
6948
- function isCustomElementRegistryAvailable() {
6949
- if (typeof customElements === 'undefined') {
6950
- return false;
6951
- }
6952
-
6953
- try {
6954
- // dereference HTMLElement global because babel wraps globals in compat mode with a
6955
- // _wrapNativeSuper()
6956
- // This is a problem because LWCUpgradableElement extends renderer.HTMLElementExported which does not
6957
- // get wrapped by babel.
6958
- var HTMLElementAlias = HTMLElement; // In case we use compat mode with a modern browser, the compat mode transformation
6959
- // invokes the DOM api with an .apply() or .call() to initialize any DOM api sub-classing,
6960
- // which are not equipped to be initialized that way.
6961
-
6962
- var clazz = /*#__PURE__*/function (_HTMLElementAlias) {
6963
- _inherits(clazz, _HTMLElementAlias);
6964
-
6965
- var _super7 = _createSuper(clazz);
6966
-
6967
- function clazz() {
6968
- _classCallCheck(this, clazz);
6969
-
6970
- return _super7.apply(this, arguments);
6971
- }
6972
-
6973
- return _createClass(clazz);
6974
- }(HTMLElementAlias);
6975
-
6976
- customElements.define('lwc-test-' + Math.floor(Math.random() * 1000000), clazz);
6977
- new clazz();
6978
- return true;
6979
- } catch (_a) {
6980
- return false;
6981
- }
6982
- }
6983
-
6984
- if (isCustomElementRegistryAvailable()) {
6985
- exports.getCustomElement = customElements.get.bind(customElements);
6986
- exports.defineCustomElement = customElements.define.bind(customElements);
6987
- HTMLElementConstructor = HTMLElement;
6988
- } else {
6989
- var registry = Object.create(null);
6990
- var reverseRegistry = new WeakMap();
6991
-
6992
- exports.defineCustomElement = function define(name, ctor) {
6993
- if (name !== String.prototype.toLowerCase.call(name) || registry[name]) {
6994
- throw new TypeError("Invalid Registration");
6995
- }
6996
-
6997
- registry[name] = ctor;
6998
- reverseRegistry.set(ctor, name);
6999
- };
7000
-
7001
- exports.getCustomElement = function get(name) {
7002
- return registry[name];
7003
- };
7004
-
7005
- HTMLElementConstructor = function HTMLElement() {
7006
- if (!(this instanceof HTMLElement)) {
7007
- throw new TypeError("Invalid Invocation");
7008
- }
7009
-
7010
- var constructor = this.constructor;
7011
- var name = reverseRegistry.get(constructor);
7012
-
7013
- if (!name) {
7014
- throw new TypeError("Invalid Construction");
7015
- }
7016
-
7017
- var elm = document.createElement(name);
7018
- Object.setPrototypeOf(elm, constructor.prototype);
7019
- return elm;
7020
- };
7021
-
7022
- HTMLElementConstructor.prototype = HTMLElement.prototype;
7023
- }
7024
-
7025
7671
  function cloneNode(node, deep) {
7026
7672
  return node.cloneNode(deep);
7027
7673
  }
@@ -7080,18 +7726,18 @@ var LWC = (function (exports) {
7080
7726
  var wrapperTags = topLevelWrappingMap[getTagName(html)];
7081
7727
 
7082
7728
  if (!isUndefined(wrapperTags)) {
7083
- var _iterator6 = _createForOfIteratorHelper(wrapperTags),
7084
- _step6;
7729
+ var _iterator7 = _createForOfIteratorHelper(wrapperTags),
7730
+ _step7;
7085
7731
 
7086
7732
  try {
7087
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
7088
- var wrapperTag = _step6.value;
7733
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
7734
+ var wrapperTag = _step7.value;
7089
7735
  html = "<".concat(wrapperTag, ">").concat(html, "</").concat(wrapperTag, ">");
7090
7736
  }
7091
7737
  } catch (err) {
7092
- _iterator6.e(err);
7738
+ _iterator7.e(err);
7093
7739
  } finally {
7094
- _iterator6.f();
7740
+ _iterator7.f();
7095
7741
  }
7096
7742
  } // For IE11, the document title must not be undefined, but it can be an empty string
7097
7743
  // https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createHTMLDocument#browser_compatibility
@@ -7237,8 +7883,6 @@ var LWC = (function (exports) {
7237
7883
  assert.invariant(elm instanceof HTMLElement, msg);
7238
7884
  }
7239
7885
 
7240
- var HTMLElementExported = HTMLElementConstructor;
7241
- exports.HTMLElementExported = HTMLElementExported;
7242
7886
  exports.addEventListener = addEventListener;
7243
7887
  exports.assertInstanceOfHTMLElement = assertInstanceOfHTMLElement;
7244
7888
  exports.attachShadow = attachShadow;
@@ -7297,6 +7941,8 @@ var LWC = (function (exports) {
7297
7941
  {
7298
7942
  // insertStyleSheet implementation shares a global cache of stylesheet data
7299
7943
  insertStylesheet: insertStylesheet,
7944
+ // relies on a shared global cache
7945
+ createCustomElement: createCustomElement,
7300
7946
  isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
7301
7947
  isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN)
7302
7948
  });
@@ -7413,35 +8059,39 @@ var LWC = (function (exports) {
7413
8059
  var hydratedCustomElements = new WeakSet();
7414
8060
 
7415
8061
  function buildCustomElementConstructor(Ctor) {
8062
+ var _a;
8063
+
7416
8064
  var HtmlPrototype = getComponentHtmlPrototype(Ctor);
7417
- return /*#__PURE__*/function (_HtmlPrototype) {
7418
- _inherits(_class, _HtmlPrototype);
8065
+ var observedAttributes = HtmlPrototype.observedAttributes;
8066
+ var _attributeChangedCallback = HtmlPrototype.prototype.attributeChangedCallback;
8067
+ return _a = /*#__PURE__*/function (_HTMLElement2) {
8068
+ _inherits(_a, _HTMLElement2);
7419
8069
 
7420
- var _super8 = _createSuper(_class);
8070
+ var _super10 = _createSuper(_a);
7421
8071
 
7422
- function _class() {
7423
- var _this6;
8072
+ function _a() {
8073
+ var _this8;
7424
8074
 
7425
- _classCallCheck(this, _class);
8075
+ _classCallCheck(this, _a);
7426
8076
 
7427
- _this6 = _super8.call(this);
8077
+ _this8 = _super10.call(this);
7428
8078
 
7429
- if (_this6.isConnected) {
8079
+ if (_this8.isConnected) {
7430
8080
  // this if block is hit when there's already an un-upgraded element in the DOM with the same tag name.
7431
- hydrateComponent(_assertThisInitialized(_this6), Ctor, {});
7432
- hydratedCustomElements.add(_assertThisInitialized(_this6));
8081
+ hydrateComponent(_assertThisInitialized(_this8), Ctor, {});
8082
+ hydratedCustomElements.add(_assertThisInitialized(_this8));
7433
8083
  } else {
7434
- createVM(_assertThisInitialized(_this6), Ctor, renderer, {
8084
+ createVM(_assertThisInitialized(_this8), Ctor, renderer, {
7435
8085
  mode: 'open',
7436
8086
  owner: null,
7437
- tagName: _this6.tagName
8087
+ tagName: _this8.tagName
7438
8088
  });
7439
8089
  }
7440
8090
 
7441
- return _this6;
8091
+ return _this8;
7442
8092
  }
7443
8093
 
7444
- _createClass(_class, [{
8094
+ _createClass(_a, [{
7445
8095
  key: "connectedCallback",
7446
8096
  value: function connectedCallback() {
7447
8097
  if (hydratedCustomElements.has(this)) {
@@ -7456,10 +8106,15 @@ var LWC = (function (exports) {
7456
8106
  value: function disconnectedCallback() {
7457
8107
  disconnectRootElement(this);
7458
8108
  }
8109
+ }, {
8110
+ key: "attributeChangedCallback",
8111
+ value: function attributeChangedCallback(name, oldValue, newValue) {
8112
+ _attributeChangedCallback.call(this, name, oldValue, newValue);
8113
+ }
7459
8114
  }]);
7460
8115
 
7461
- return _class;
7462
- }(HtmlPrototype);
8116
+ return _a;
8117
+ }( /*#__PURE__*/_wrapNativeSuper(HTMLElement)), _a.observedAttributes = observedAttributes, _a;
7463
8118
  }
7464
8119
  /*
7465
8120
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7542,8 +8197,11 @@ var LWC = (function (exports) {
7542
8197
  throw new TypeError("\"createElement\" function expects an \"is\" option with a valid component constructor.");
7543
8198
  }
7544
8199
 
7545
- var UpgradableConstructor = getUpgradableConstructor(sel, renderer);
7546
- var wasComponentUpgraded = false; // the custom element from the registry is expecting an upgrade callback
8200
+ var createCustomElement = renderer.createCustomElement; // tagName must be all lowercase, unfortunately, we have legacy code that is
8201
+ // passing `sel` as a camel-case, which makes them invalid custom elements name
8202
+ // the following line guarantees that this does not leaks beyond this point.
8203
+
8204
+ var tagName = StringToLowerCase.call(sel); // the custom element from the registry is expecting an upgrade callback
7547
8205
 
7548
8206
  /**
7549
8207
  * Note: if the upgradable constructor does not expect, or throw when we new it
@@ -7552,9 +8210,9 @@ var LWC = (function (exports) {
7552
8210
  * an upgradable custom element.
7553
8211
  */
7554
8212
 
7555
- var element = new UpgradableConstructor(function (elm) {
8213
+ var upgradeCallback = function upgradeCallback(elm) {
7556
8214
  createVM(elm, Ctor, renderer, {
7557
- tagName: sel,
8215
+ tagName: tagName,
7558
8216
  mode: options.mode !== 'closed' ? 'open' : 'closed',
7559
8217
  owner: null
7560
8218
  });
@@ -7563,15 +8221,21 @@ var LWC = (function (exports) {
7563
8221
  ConnectingSlot.set(elm, connectRootElement);
7564
8222
  DisconnectingSlot.set(elm, disconnectRootElement);
7565
8223
  }
8224
+ };
7566
8225
 
7567
- wasComponentUpgraded = true;
7568
- });
8226
+ var connectedCallback = function connectedCallback(elm) {
8227
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
8228
+ connectRootElement(elm);
8229
+ }
8230
+ };
7569
8231
 
7570
- if (!wasComponentUpgraded) {
7571
- /* eslint-disable-next-line no-console */
7572
- console.error("Unexpected tag name \"".concat(sel, "\". This name is a registered custom element, preventing LWC to upgrade the element."));
7573
- }
8232
+ var disconnectedCallback = function disconnectedCallback(elm) {
8233
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
8234
+ disconnectRootElement(elm);
8235
+ }
8236
+ };
7574
8237
 
8238
+ var element = createCustomElement(tagName, upgradeCallback, connectedCallback, disconnectedCallback);
7575
8239
  return element;
7576
8240
  }
7577
8241
  /*
@@ -7654,7 +8318,7 @@ var LWC = (function (exports) {
7654
8318
  });
7655
8319
  freeze(LightningElement);
7656
8320
  seal(LightningElement.prototype);
7657
- /* version: 2.25.1 */
8321
+ /* version: 2.26.1 */
7658
8322
 
7659
8323
  exports.LightningElement = LightningElement;
7660
8324
  exports.__unstable__ProfilerControl = profilerControl;