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