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
@@ -294,7 +294,7 @@
294
294
  CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
295
295
  return attributeName;
296
296
  }
297
- /** version: 2.25.1 */
297
+ /** version: 2.26.1 */
298
298
 
299
299
  /**
300
300
  * Copyright (C) 2018 salesforce.com, inc.
@@ -376,7 +376,7 @@
376
376
  patch$1(propName);
377
377
  }
378
378
  }
379
- /** version: 2.25.1 */
379
+ /** version: 2.26.1 */
380
380
 
381
381
  /**
382
382
  * Copyright (C) 2018 salesforce.com, inc.
@@ -392,7 +392,6 @@
392
392
  DUMMY_TEST_FLAG: null,
393
393
  ENABLE_ELEMENT_PATCH: null,
394
394
  ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST: null,
395
- ENABLE_HMR: null,
396
395
  ENABLE_HTML_COLLECTIONS_PATCH: null,
397
396
  ENABLE_INNER_OUTER_TEXT_PATCH: null,
398
397
  ENABLE_MIXED_SHADOW_MODE: null,
@@ -403,6 +402,7 @@
403
402
  ENABLE_WIRE_SYNC_EMIT: null,
404
403
  ENABLE_LIGHT_GET_ROOT_NODE_PATCH: null,
405
404
  DISABLE_LIGHT_DOM_UNSCOPED_CSS: null,
405
+ ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
406
406
  };
407
407
  if (!_globalThis.lwcRuntimeFlags) {
408
408
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
@@ -1387,7 +1387,9 @@
1387
1387
  const LightningElement = function () {
1388
1388
  // This should be as performant as possible, while any initialization should be done lazily
1389
1389
  if (isNull(vmBeingConstructed)) {
1390
- throw new ReferenceError('Illegal constructor');
1390
+ // Thrown when doing something like `new LightningElement()` or
1391
+ // `class Foo extends LightningElement {}; new Foo()`
1392
+ throw new TypeError('Illegal constructor');
1391
1393
  }
1392
1394
  const vm = vmBeingConstructed;
1393
1395
  const { def, elm } = vm;
@@ -2167,34 +2169,19 @@
2167
2169
  freeze(BaseBridgeElement);
2168
2170
  seal(BaseBridgeElement.prototype);
2169
2171
  function setActiveVM(vm) {
2170
- {
2171
- // this method should never leak to prod
2172
- throw new ReferenceError();
2173
- }
2172
+ {
2173
+ // this method should never leak to prod
2174
+ throw new ReferenceError();
2175
+ }
2174
2176
  }
2175
2177
  function swapTemplate(oldTpl, newTpl) {
2176
-
2177
- if (!lwcRuntimeFlags.ENABLE_HMR) {
2178
- throw new Error('HMR is not enabled');
2179
- }
2180
-
2181
- return false;
2178
+ return false;
2182
2179
  }
2183
2180
  function swapComponent(oldComponent, newComponent) {
2184
-
2185
- if (!lwcRuntimeFlags.ENABLE_HMR) {
2186
- throw new Error('HMR is not enabled');
2187
- }
2188
-
2189
- return false;
2181
+ return false;
2190
2182
  }
2191
2183
  function swapStyle(oldStyle, newStyle) {
2192
-
2193
- if (!lwcRuntimeFlags.ENABLE_HMR) {
2194
- throw new Error('HMR is not enabled');
2195
- }
2196
-
2197
- return false;
2184
+ return false;
2198
2185
  }
2199
2186
 
2200
2187
  /*
@@ -2573,15 +2560,18 @@
2573
2560
  /**
2574
2561
  * This function returns the host style token for a custom element if it
2575
2562
  * exists. Otherwise it returns null.
2563
+ *
2564
+ * A host style token is applied to the component if scoped styles are used.
2576
2565
  */
2577
2566
 
2578
2567
  function getStylesheetTokenHost(vnode) {
2579
2568
  const {
2580
- template: {
2581
- stylesheetToken
2582
- }
2569
+ template
2583
2570
  } = getComponentInternalDef(vnode.ctor);
2584
- return !isUndefined$1(stylesheetToken) ? makeHostToken(stylesheetToken) : null;
2571
+ const {
2572
+ stylesheetToken
2573
+ } = template;
2574
+ return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template) ? makeHostToken(stylesheetToken) : null;
2585
2575
  }
2586
2576
 
2587
2577
  function getNearestNativeShadowComponent(vm) {
@@ -2635,69 +2625,6 @@
2635
2625
  return null;
2636
2626
  }
2637
2627
 
2638
- /*
2639
- * Copyright (c) 2020, salesforce.com, inc.
2640
- * All rights reserved.
2641
- * SPDX-License-Identifier: MIT
2642
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2643
- */
2644
-
2645
- function checkHasVM(elm) {
2646
- const hasVM = !isUndefined$1(getAssociatedVMIfPresent(elm));
2647
-
2648
- return hasVM;
2649
- }
2650
-
2651
- function getUpgradableConstructor(tagName, renderer) {
2652
- const {
2653
- getCustomElement,
2654
- HTMLElementExported: RendererHTMLElement,
2655
- defineCustomElement
2656
- } = renderer; // Should never get a tag with upper case letter at this point, the compiler should
2657
- // produce only tags with lowercase letters
2658
- // But, for backwards compatibility, we will lower case the tagName
2659
-
2660
- tagName = tagName.toLowerCase();
2661
- let CE = getCustomElement(tagName);
2662
-
2663
- if (!isUndefined$1(CE)) {
2664
- return CE;
2665
- }
2666
- /**
2667
- * LWC Upgradable Element reference to an element that was created
2668
- * via the scoped registry mechanism, and that is ready to be upgraded.
2669
- */
2670
-
2671
-
2672
- CE = class LWCUpgradableElement extends RendererHTMLElement {
2673
- constructor(upgradeCallback) {
2674
- super();
2675
-
2676
- if (isFunction$1(upgradeCallback)) {
2677
- upgradeCallback(this); // nothing to do with the result for now
2678
- }
2679
- }
2680
-
2681
- };
2682
-
2683
- if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
2684
- CE.prototype.connectedCallback = function () {
2685
- if (checkHasVM(this)) {
2686
- connectRootElement(this);
2687
- }
2688
- };
2689
-
2690
- CE.prototype.disconnectedCallback = function () {
2691
- if (checkHasVM(this)) {
2692
- disconnectRootElement(this);
2693
- }
2694
- };
2695
- }
2696
-
2697
- defineCustomElement(tagName, CE);
2698
- return CE;
2699
- }
2700
-
2701
2628
  /*
2702
2629
  * Copyright (c) 2018, salesforce.com, inc.
2703
2630
  * All rights reserved.
@@ -3185,7 +3112,9 @@
3185
3112
  sel,
3186
3113
  owner
3187
3114
  } = vnode;
3188
- const UpgradableConstructor = getUpgradableConstructor(sel, renderer);
3115
+ const {
3116
+ createCustomElement
3117
+ } = renderer;
3189
3118
  /**
3190
3119
  * Note: if the upgradable constructor does not expect, or throw when we new it
3191
3120
  * with a callback as the first argument, we could implement a more advanced
@@ -3194,10 +3123,30 @@
3194
3123
  */
3195
3124
 
3196
3125
  let vm;
3197
- const elm = new UpgradableConstructor(elm => {
3126
+
3127
+ const upgradeCallback = elm => {
3198
3128
  // the custom element from the registry is expecting an upgrade callback
3199
3129
  vm = createViewModelHook(elm, vnode, renderer);
3200
- });
3130
+ };
3131
+
3132
+ const connectedCallback = elm => {
3133
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3134
+ connectRootElement(elm);
3135
+ }
3136
+ };
3137
+
3138
+ const disconnectedCallback = elm => {
3139
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3140
+ disconnectRootElement(elm);
3141
+ }
3142
+ }; // Should never get a tag with upper case letter at this point; the compiler
3143
+ // should produce only tags with lowercase letters. However, the Java
3144
+ // compiler may generate tagnames with uppercase letters so - for backwards
3145
+ // compatibility, we lower case the tagname here.
3146
+
3147
+
3148
+ const normalizedTagname = sel.toLowerCase();
3149
+ const elm = createCustomElement(normalizedTagname, upgradeCallback, connectedCallback, disconnectedCallback);
3201
3150
  vnode.elm = elm;
3202
3151
  vnode.vm = vm;
3203
3152
  linkNodeToShadow(elm, owner, renderer);
@@ -3205,8 +3154,6 @@
3205
3154
 
3206
3155
  if (vm) {
3207
3156
  allocateChildren(vnode, vm);
3208
- } else if (vnode.ctor !== UpgradableConstructor) {
3209
- throw new TypeError(`Incorrect Component Constructor`);
3210
3157
  }
3211
3158
 
3212
3159
  patchElementPropsAndAttrs$1(null, vnode, renderer);
@@ -5562,19 +5509,23 @@
5562
5509
  //
5563
5510
  // Consequently, hydration mismatches will occur if scoped CSS token classnames
5564
5511
  // are rendered during SSR. This needs to be accounted for when validating.
5565
- if (scopedToken) {
5512
+ if (!isNull(scopedToken) || !isNull(stylesheetTokenHost)) {
5566
5513
  if (!isUndefined$1(className)) {
5567
- className = isNull(stylesheetTokenHost)
5568
- ? `${scopedToken} ${className}`
5569
- : `${scopedToken} ${className} ${stylesheetTokenHost}`;
5514
+ // The order of the className should be scopedToken className stylesheetTokenHost
5515
+ const classTokens = [scopedToken, className, stylesheetTokenHost];
5516
+ const classNames = ArrayFilter.call(classTokens, (token) => !isNull(token));
5517
+ className = ArrayJoin.call(classNames, ' ');
5570
5518
  }
5571
5519
  else if (!isUndefined$1(classMap)) {
5572
- classMap = Object.assign(Object.assign(Object.assign({}, classMap), { [scopedToken]: true }), (isNull(stylesheetTokenHost) ? {} : { [stylesheetTokenHost]: true }));
5520
+ classMap = Object.assign(Object.assign(Object.assign({}, classMap), (!isNull(scopedToken) ? { [scopedToken]: true } : {})), (!isNull(stylesheetTokenHost) ? { [stylesheetTokenHost]: true } : {}));
5573
5521
  }
5574
5522
  else {
5575
- className = isNull(stylesheetTokenHost)
5576
- ? `${scopedToken}`
5577
- : `${scopedToken} ${stylesheetTokenHost}`;
5523
+ // The order of the className should be scopedToken stylesheetTokenHost
5524
+ const classTokens = [scopedToken, stylesheetTokenHost];
5525
+ const classNames = ArrayFilter.call(classTokens, (token) => !isNull(token));
5526
+ if (classNames.length) {
5527
+ className = ArrayJoin.call(classNames, ' ');
5528
+ }
5578
5529
  }
5579
5530
  }
5580
5531
  let nodesAreCompatible = true;
@@ -5703,7 +5654,7 @@
5703
5654
  }
5704
5655
  return ctor;
5705
5656
  }
5706
- /* version: 2.25.1 */
5657
+ /* version: 2.26.1 */
5707
5658
 
5708
5659
  /*
5709
5660
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5838,6 +5789,626 @@
5838
5789
  }
5839
5790
  }
5840
5791
 
5792
+ /*
5793
+ * Copyright (c) 2020, salesforce.com, inc.
5794
+ * All rights reserved.
5795
+ * SPDX-License-Identifier: MIT
5796
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5797
+ */
5798
+ function isCustomElementRegistryAvailable() {
5799
+ if (typeof customElements === 'undefined') {
5800
+ return false;
5801
+ }
5802
+ try {
5803
+ // dereference HTMLElement global because babel wraps globals in compat mode with a
5804
+ // _wrapNativeSuper()
5805
+ // This is a problem because LWCUpgradableElement extends renderer.HTMLElement which does not
5806
+ // get wrapped by babel.
5807
+ const HTMLElementAlias = HTMLElement;
5808
+ // In case we use compat mode with a modern browser, the compat mode transformation
5809
+ // invokes the DOM api with an .apply() or .call() to initialize any DOM api sub-classing,
5810
+ // which are not equipped to be initialized that way.
5811
+ class clazz extends HTMLElementAlias {
5812
+ }
5813
+ customElements.define('lwc-test-' + Math.floor(Math.random() * 1000000), clazz);
5814
+ new clazz();
5815
+ return true;
5816
+ }
5817
+ catch (_a) {
5818
+ return false;
5819
+ }
5820
+ }
5821
+ const hasCustomElements = isCustomElementRegistryAvailable();
5822
+
5823
+ /*
5824
+ * Copyright (c) 2018, salesforce.com, inc.
5825
+ * All rights reserved.
5826
+ * SPDX-License-Identifier: MIT
5827
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5828
+ */
5829
+ // Creates a custom element for compat (legacy) browser environments
5830
+ const createCustomElementCompat = (tagName, upgradeCallback) => {
5831
+ const elm = document.createElement(tagName);
5832
+ upgradeCallback(elm); // nothing to do with the result for now
5833
+ return elm;
5834
+ };
5835
+
5836
+ /*
5837
+ * Copyright (c) 2018, salesforce.com, inc.
5838
+ * All rights reserved.
5839
+ * SPDX-License-Identifier: MIT
5840
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5841
+ */
5842
+ const cachedConstructors = new Map();
5843
+ const elementsUpgradedOutsideLWC = new WeakSet();
5844
+ let elementBeingUpgradedByLWC = false;
5845
+ // Creates a constructor that is intended to be used as a vanilla custom element, except that the upgradeCallback is
5846
+ // passed in to the constructor so LWC can reuse the same custom element constructor for multiple components.
5847
+ // Another benefit is that only LWC can create components that actually do anything – if you do
5848
+ // `customElements.define('x-foo')`, then you don't have access to the upgradeCallback, so it's a dummy custom element.
5849
+ // This class should be created once per tag name.
5850
+ const createUpgradableConstructor = (connectedCallback, disconnectedCallback) => {
5851
+ // TODO [#2972]: this class should expose observedAttributes as necessary
5852
+ return class UpgradableConstructor extends HTMLElement {
5853
+ constructor(upgradeCallback) {
5854
+ super();
5855
+ // If the element is not created using lwc.createElement(), e.g. `document.createElement('x-foo')`,
5856
+ // then elementBeingUpgraded will be false
5857
+ if (elementBeingUpgradedByLWC) {
5858
+ upgradeCallback(this);
5859
+ }
5860
+ else {
5861
+ // keep track of elements that were not created by lwc.createElement,
5862
+ // so we can ignore their lifecycle hooks
5863
+ elementsUpgradedOutsideLWC.add(this);
5864
+ // TODO [#2970]: LWC elements cannot be upgraded via new Ctor()
5865
+ // Do we want to support this? Throw an error? Currently for backwards compat it's a no-op.
5866
+ }
5867
+ }
5868
+ connectedCallback() {
5869
+ if (!elementsUpgradedOutsideLWC.has(this)) {
5870
+ connectedCallback(this);
5871
+ }
5872
+ }
5873
+ disconnectedCallback() {
5874
+ if (!elementsUpgradedOutsideLWC.has(this)) {
5875
+ disconnectedCallback(this);
5876
+ }
5877
+ }
5878
+ };
5879
+ };
5880
+ const createCustomElementVanilla = (tagName, upgradeCallback, connectedCallback, disconnectedCallback) => {
5881
+ // use global custom elements registry
5882
+ let UpgradableConstructor = cachedConstructors.get(tagName);
5883
+ if (isUndefined$1(UpgradableConstructor)) {
5884
+ if (!isUndefined$1(customElements.get(tagName))) {
5885
+ throw new Error(`Unexpected tag name "${tagName}". This name is a registered custom element, preventing LWC to upgrade the element.`);
5886
+ }
5887
+ UpgradableConstructor = createUpgradableConstructor(connectedCallback, disconnectedCallback);
5888
+ customElements.define(tagName, UpgradableConstructor);
5889
+ cachedConstructors.set(tagName, UpgradableConstructor);
5890
+ }
5891
+ elementBeingUpgradedByLWC = true;
5892
+ try {
5893
+ return new UpgradableConstructor(upgradeCallback);
5894
+ }
5895
+ finally {
5896
+ elementBeingUpgradedByLWC = false;
5897
+ }
5898
+ };
5899
+
5900
+ /*
5901
+ * Copyright (c) 2020, salesforce.com, inc.
5902
+ * All rights reserved.
5903
+ * SPDX-License-Identifier: MIT
5904
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5905
+ */
5906
+ /**
5907
+ * Create a scoped registry, i.e. a function that can create custom elements whose tag names
5908
+ * do not conflict with vanilla custom elements having the same tag name.
5909
+ */
5910
+ function createScopedRegistry() {
5911
+ if (!hasCustomElements) {
5912
+ // This code should never be reached, because we don't use the pivot registry if
5913
+ // custom elements are unavailable.
5914
+ throw new Error('Custom elements are not supported in this environment.');
5915
+ }
5916
+ const { HTMLElement: NativeHTMLElement } = window;
5917
+ const { hasAttribute: nativeHasAttribute, setAttribute: nativeSetAttribute, removeAttribute: nativeRemoveAttribute, getAttribute: nativeGetAttribute, } = NativeHTMLElement.prototype;
5918
+ const definitionForElement = new WeakMap();
5919
+ const pendingRegistryForElement = new WeakMap();
5920
+ const definitionForConstructor = new WeakMap();
5921
+ const registeredUserCtors = new WeakSet();
5922
+ const pivotCtorByTag = new Map();
5923
+ const globalDefinitionsByTag = new Map();
5924
+ const globalDefinitionsByClass = new Map();
5925
+ const awaitingUpgrade = new Map();
5926
+ const EMPTY_SET = new Set();
5927
+ function createDefinitionRecord(constructor) {
5928
+ var _a;
5929
+ const { connectedCallback, disconnectedCallback, adoptedCallback, attributeChangedCallback, } = constructor.prototype;
5930
+ const observedAttributes = new Set((_a = constructor.observedAttributes) !== null && _a !== void 0 ? _a : []);
5931
+ return {
5932
+ UserCtor: constructor,
5933
+ PivotCtor: undefined,
5934
+ connectedCallback,
5935
+ disconnectedCallback,
5936
+ adoptedCallback,
5937
+ attributeChangedCallback,
5938
+ observedAttributes,
5939
+ };
5940
+ }
5941
+ // Helper to create stand-in element for each tagName registered that delegates out to the registry for the given
5942
+ // element. Note that the `registeredDefinition` represents the constructor that was used to register during
5943
+ // `customElements.define()`. Whereas the `pivotDefinition` represents the constructor that is passed when the pivot
5944
+ // constructor is invoked with another constructor.
5945
+ function createPivotingClass(tagName, registeredDefinition) {
5946
+ class PivotCtor extends NativeHTMLElement {
5947
+ constructor(UserCtor) {
5948
+ // This constructor can only be invoked by:
5949
+ // a) the browser instantiating an element from parsing or via document.createElement.
5950
+ // b) LWC new PivotClass (This constructor is NOT observable/accessible in user-land).
5951
+ // b) new UserClass.
5952
+ // When LWC instantiates it, it will pass the upgrading definition as an argument
5953
+ // If the caller signals via UserCtor that this is in fact a controlled
5954
+ // definition, we use that one, otherwise fallback to the global
5955
+ // internal registry.
5956
+ super();
5957
+ const userCtorIsDefined = !isUndefined$1(UserCtor);
5958
+ if (userCtorIsDefined) {
5959
+ if (!isConstructor(UserCtor)) {
5960
+ throw new TypeError(`Failed to create custom element: the provided constructor is not a constructor.`);
5961
+ }
5962
+ if (!registeredUserCtors.has(UserCtor)) {
5963
+ throw new Error(`Failed to create custom element: the provided constructor is unregistered: ${UserCtor.name}.`);
5964
+ }
5965
+ }
5966
+ const definition = userCtorIsDefined
5967
+ ? getOrCreateDefinitionForConstructor(UserCtor)
5968
+ : globalDefinitionsByTag.get(tagName);
5969
+ if (!isUndefined$1(definition)) {
5970
+ internalUpgrade(this, registeredDefinition, definition);
5971
+ }
5972
+ else {
5973
+ // This is the case in which there is no global definition, and
5974
+ // it is not handled by LWC (otherwise it will have a valid UserCtor)
5975
+ // so we need to add it to the pending queue just in case it eventually
5976
+ // gets defined in the global registry.
5977
+ pendingRegistryForElement.set(this, registeredDefinition);
5978
+ }
5979
+ }
5980
+ connectedCallback() {
5981
+ var _a;
5982
+ const definition = definitionForElement.get(this);
5983
+ if (!isUndefined$1(definition)) {
5984
+ // Delegate out to user callback
5985
+ (_a = definition.connectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
5986
+ }
5987
+ else {
5988
+ // Register for upgrade when defined (only when connected, so we don't leak)
5989
+ let awaiting = awaitingUpgrade.get(tagName);
5990
+ if (isUndefined$1(awaiting)) {
5991
+ awaitingUpgrade.set(tagName, (awaiting = new Set()));
5992
+ }
5993
+ awaiting.add(this);
5994
+ }
5995
+ }
5996
+ disconnectedCallback() {
5997
+ var _a;
5998
+ const definition = definitionForElement.get(this);
5999
+ if (!isUndefined$1(definition)) {
6000
+ // Delegate out to user callback
6001
+ (_a = definition.disconnectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
6002
+ }
6003
+ else {
6004
+ // Un-register for upgrade when defined (so we don't leak)
6005
+ const awaiting = awaitingUpgrade.get(tagName);
6006
+ // At this point, awaiting should never be undefined, because connectedCallback
6007
+ // must have been called before disconnectedCallback. But just to be safe, we check
6008
+ if (!isUndefined$1(awaiting)) {
6009
+ awaiting.delete(this);
6010
+ }
6011
+ }
6012
+ }
6013
+ adoptedCallback() {
6014
+ var _a;
6015
+ const definition = definitionForElement.get(this);
6016
+ (_a = definition === null || definition === void 0 ? void 0 : definition.adoptedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
6017
+ }
6018
+ attributeChangedCallback(name, oldValue, newValue) {
6019
+ var _a;
6020
+ const definition = definitionForElement.get(this);
6021
+ // if both definitions are the same, then the observedAttributes is the same,
6022
+ // but if they are different, only if the runtime definition has the attribute
6023
+ // marked as observed, then it should invoke attributeChangedCallback.
6024
+ if (registeredDefinition === definition ||
6025
+ (definition === null || definition === void 0 ? void 0 : definition.observedAttributes.has(name))) {
6026
+ (_a = definition.attributeChangedCallback) === null || _a === void 0 ? void 0 : _a.apply(this, [name, oldValue, newValue]);
6027
+ }
6028
+ }
6029
+ }
6030
+ PivotCtor.observedAttributes = [...registeredDefinition.observedAttributes];
6031
+ return PivotCtor;
6032
+ }
6033
+ function getNewObservedAttributes(registeredDefinition, pivotDefinition) {
6034
+ const { observedAttributes, attributeChangedCallback } = pivotDefinition;
6035
+ if (observedAttributes.size === 0 || isUndefined$1(attributeChangedCallback)) {
6036
+ // This instance does not need to observe any attributes, no need to patch
6037
+ return EMPTY_SET;
6038
+ }
6039
+ // Natively, the attributes observed by the registered definition are going to be taken
6040
+ // care of by the browser, only the difference between the two sets has to be taken
6041
+ // care by the patched version.
6042
+ return new Set([...pivotDefinition.observedAttributes].filter((x) => !registeredDefinition.observedAttributes.has(x)));
6043
+ }
6044
+ function throwAsyncError(error) {
6045
+ // Per native custom element behavior, errors thrown in attributeChangedCallback
6046
+ // become unhandled async errors. We use setTimeout() instead of Promise.resolve()
6047
+ // to make it an unhandled error rather than an unhandled rejection.
6048
+ setTimeout(() => {
6049
+ throw error;
6050
+ });
6051
+ }
6052
+ // Helper to patch `setAttribute`/`getAttribute` to implement `attributeChangedCallback`.
6053
+ // Why is this necessary? Well basically, you can't change the `observedAttributes` after
6054
+ // a custom element is defined. So with pivots, if two classes share the same tag name,
6055
+ // and the second class observes attributes that aren't observed by the first one,
6056
+ // then those attributes can never be observed by the native `observedAttributes` system.
6057
+ // So we have to simulate it by patching `getAttribute`/`removeAttribute`. Note that
6058
+ // we only do this when absolutely necessary, though; i.e. because we've determined
6059
+ // that we aren't observing the attributes we need to.
6060
+ function patchAttributes(instance, registeredDefinition, pivotDefinition) {
6061
+ const newObservedAttributes = getNewObservedAttributes(registeredDefinition, pivotDefinition);
6062
+ if (newObservedAttributes.size === 0) {
6063
+ return;
6064
+ }
6065
+ const { attributeChangedCallback } = pivotDefinition;
6066
+ // Patch the instance.
6067
+ // Note we use the native `getAttribute` rather than the super's `getAttribute` because
6068
+ // we don't actually want it to be observable that we're calling `getAttribute` from
6069
+ // `setAttribute` and `removeAttribute`.
6070
+ // TODO [#2994]: this should handle reflected properties such as `ariaLabel` and `role`.
6071
+ defineProperties(instance, {
6072
+ setAttribute: {
6073
+ value: function setAttribute(name, value) {
6074
+ if (newObservedAttributes.has(name)) {
6075
+ const old = nativeGetAttribute.call(this, name);
6076
+ nativeSetAttribute.call(this, name, value);
6077
+ try {
6078
+ attributeChangedCallback.call(this, name, old, value + '');
6079
+ }
6080
+ catch (error) {
6081
+ throwAsyncError(error);
6082
+ }
6083
+ }
6084
+ else {
6085
+ nativeSetAttribute.call(this, name, value);
6086
+ }
6087
+ },
6088
+ writable: true,
6089
+ enumerable: true,
6090
+ configurable: true,
6091
+ },
6092
+ removeAttribute: {
6093
+ value: function removeAttribute(name) {
6094
+ if (newObservedAttributes.has(name)) {
6095
+ const old = nativeGetAttribute.call(this, name);
6096
+ nativeRemoveAttribute.call(this, name);
6097
+ try {
6098
+ attributeChangedCallback.call(this, name, old, null);
6099
+ }
6100
+ catch (error) {
6101
+ throwAsyncError(error);
6102
+ }
6103
+ }
6104
+ else {
6105
+ nativeRemoveAttribute.call(this, name);
6106
+ }
6107
+ },
6108
+ writable: true,
6109
+ enumerable: true,
6110
+ configurable: true,
6111
+ },
6112
+ });
6113
+ }
6114
+ function patchAttributesDuringUpgrade(instance, registeredDefinition, pivotDefinition) {
6115
+ // The below case patches observed attributes for the case where the HTML element is upgraded
6116
+ // from a pre-existing one in the DOM.
6117
+ const newObservedAttributes = getNewObservedAttributes(registeredDefinition, pivotDefinition);
6118
+ if (getNewObservedAttributes(registeredDefinition, pivotDefinition).size === 0) {
6119
+ return;
6120
+ }
6121
+ const { attributeChangedCallback } = pivotDefinition;
6122
+ // Approximate observedAttributes from the user class, but only for the new observed attributes
6123
+ newObservedAttributes.forEach((name) => {
6124
+ if (nativeHasAttribute.call(instance, name)) {
6125
+ const newValue = nativeGetAttribute.call(instance, name);
6126
+ attributeChangedCallback.call(instance, name, null, newValue);
6127
+ }
6128
+ });
6129
+ }
6130
+ // User extends this HTMLElement, which returns the CE being upgraded
6131
+ let upgradingInstance;
6132
+ // Helper to upgrade an instance with a CE definition using "constructor call trick"
6133
+ function internalUpgrade(instance, registeredDefinition, pivotDefinition) {
6134
+ setPrototypeOf(instance, pivotDefinition.UserCtor.prototype);
6135
+ definitionForElement.set(instance, pivotDefinition);
6136
+ // attributes patches when needed
6137
+ if (pivotDefinition !== registeredDefinition) {
6138
+ patchAttributes(instance, registeredDefinition, pivotDefinition);
6139
+ }
6140
+ // Tricking the construction path to believe that a new instance is being created,
6141
+ // that way it will execute the super initialization mechanism but the HTMLElement
6142
+ // constructor will reuse the instance by returning the upgradingInstance.
6143
+ // This is by far the most important piece of the puzzle
6144
+ upgradingInstance = instance;
6145
+ // By `new`ing the UserCtor, we now jump to the constructor for the overridden global HTMLElement
6146
+ // The reason this happens is that the UserCtor extends HTMLElement, so it calls the `super()`.
6147
+ // Note that `upgradingInstance` is explicitly handled in the HTMLElement constructor.
6148
+ new pivotDefinition.UserCtor();
6149
+ patchAttributesDuringUpgrade(instance, registeredDefinition, pivotDefinition);
6150
+ }
6151
+ function isConstructor(constructor) {
6152
+ return isFunction$1(constructor) && isObject(constructor.prototype);
6153
+ }
6154
+ function getOrCreateDefinitionForConstructor(constructor) {
6155
+ if (!isConstructor(constructor)) {
6156
+ throw new TypeError('The referenced constructor is not a constructor.');
6157
+ }
6158
+ const definition = definitionForConstructor.get(constructor);
6159
+ if (!isUndefined$1(definition)) {
6160
+ return definition;
6161
+ }
6162
+ return createDefinitionRecord(constructor);
6163
+ }
6164
+ const { customElements: nativeRegistry } = window;
6165
+ const { define: nativeDefine, whenDefined: nativeWhenDefined, get: nativeGet } = nativeRegistry;
6166
+ // patch for the global registry define mechanism
6167
+ CustomElementRegistry.prototype.define = function define(tagName, constructor, options) {
6168
+ if (options && options.extends) {
6169
+ // TODO [#2983]: should we support `extends`?
6170
+ throw new DOMException('NotSupportedError: "extends" key in customElements.define() options is not supported.');
6171
+ }
6172
+ if (globalDefinitionsByTag.has(tagName)) {
6173
+ throw new DOMException(`Failed to execute 'define' on 'CustomElementRegistry': the name "${tagName}" has already been used with this registry`);
6174
+ }
6175
+ if (!isUndefined$1(globalDefinitionsByClass.get(constructor))) {
6176
+ throw new DOMException(`Failed to execute 'define' on 'CustomElementRegistry': this constructor has already been used with this registry`);
6177
+ }
6178
+ const definition = getOrCreateDefinitionForConstructor(constructor);
6179
+ registeredUserCtors.add(constructor);
6180
+ let PivotCtor = pivotCtorByTag.get(tagName);
6181
+ if (isUndefined$1(PivotCtor)) {
6182
+ PivotCtor = createPivotingClass(tagName, definition);
6183
+ // Register a pivoting class which will handle global registry initializations
6184
+ nativeDefine.call(nativeRegistry, tagName, PivotCtor);
6185
+ }
6186
+ // Only cache after nativeDefine has been called, because if it throws an error
6187
+ // (e.g. for an invalid tag name), then we don't want to cache anything.
6188
+ definitionForConstructor.set(constructor, definition);
6189
+ pivotCtorByTag.set(tagName, PivotCtor);
6190
+ globalDefinitionsByTag.set(tagName, definition);
6191
+ globalDefinitionsByClass.set(constructor, definition);
6192
+ // For globally defined custom elements, the definition associated
6193
+ // to the UserCtor has a back-pointer to PivotCtor in case the user
6194
+ // new the UserCtor, so we know how to create the underlying element.
6195
+ definition.PivotCtor = PivotCtor;
6196
+ // Upgrade any elements created in this scope before customElements.define
6197
+ // was called, which should be exhibited by the following steps:
6198
+ // 1) LWC registers a tagName for an LWC component.
6199
+ // 2) Element with same tagName is created with document.createElement()
6200
+ // and inserted into DOM.
6201
+ // 3) customElements.define() is called with tagName and non-LWC constructor.
6202
+ // This requires immediate upgrade when the new global tagName is defined.
6203
+ const awaiting = awaitingUpgrade.get(tagName);
6204
+ if (!isUndefined$1(awaiting)) {
6205
+ awaitingUpgrade.delete(tagName);
6206
+ for (const element of awaiting) {
6207
+ const registeredDefinition = pendingRegistryForElement.get(element);
6208
+ // At this point, registeredDefinition should never be undefined because awaitingUpgrade
6209
+ // is only populated when we haven't run internalUpgrade yet, and we only populate
6210
+ // pendingRegistryForElement when internalUpgrade hasn't run yet.
6211
+ // But just to be safe, we check.
6212
+ if (!isUndefined$1(registeredDefinition)) {
6213
+ pendingRegistryForElement.delete(element);
6214
+ internalUpgrade(element, registeredDefinition, definition);
6215
+ }
6216
+ }
6217
+ }
6218
+ };
6219
+ CustomElementRegistry.prototype.get = function get(tagName) {
6220
+ const NativeCtor = nativeGet.call(nativeRegistry, tagName);
6221
+ if (!isUndefined$1(NativeCtor)) {
6222
+ const definition = globalDefinitionsByTag.get(tagName);
6223
+ if (!isUndefined$1(definition)) {
6224
+ return definition.UserCtor; // defined by the patched custom elements registry
6225
+ }
6226
+ // TODO [#3073]: return undefined rather than the pivot constructor (NativeCtor)
6227
+ return NativeCtor; // return the pivot constructor or constructor that existed before patching
6228
+ }
6229
+ };
6230
+ CustomElementRegistry.prototype.whenDefined = function whenDefined(tagName) {
6231
+ return nativeWhenDefined.call(nativeRegistry, tagName).then((NativeCtor) => {
6232
+ const definition = globalDefinitionsByTag.get(tagName);
6233
+ if (!isUndefined$1(definition)) {
6234
+ return definition.UserCtor;
6235
+ }
6236
+ // TODO [#3073]: return undefined rather than the pivot constructor (NativeCtor)
6237
+ // In this case, the custom element must have been defined before the registry patches
6238
+ // were applied. So return the non-pivot constructor
6239
+ if (isUndefined$1(NativeCtor)) {
6240
+ // Chromium bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1335247
6241
+ // We can patch the correct behavior using customElements.get()
6242
+ return nativeGet.call(nativeRegistry, tagName);
6243
+ }
6244
+ return NativeCtor;
6245
+ });
6246
+ };
6247
+ // This constructor is invoked when we call `new pivotDefinition.UserCtor()`
6248
+ // @ts-ignore
6249
+ window.HTMLElement = function HTMLElement() {
6250
+ // Upgrading case: the pivoting class constructor was run by the browser's
6251
+ // native custom elements and we're in the process of running the
6252
+ // "constructor-call trick" on the natively constructed instance, so just
6253
+ // return that here.
6254
+ // This code path is also called when LWC `new`s a PivotCtor.
6255
+ const instance = upgradingInstance;
6256
+ if (!isUndefined$1(instance)) {
6257
+ upgradingInstance = undefined;
6258
+ return instance;
6259
+ }
6260
+ // Construction case: we need to construct the pivoting instance and return it.
6261
+ // This is possible when the user register it via global registry and instantiate
6262
+ // it via `new Ctor()`.
6263
+ const { constructor } = this;
6264
+ const definition = globalDefinitionsByClass.get(constructor);
6265
+ if (isUndefined$1(definition) || isUndefined$1(definition.PivotCtor)) {
6266
+ // This code path is hit if someone `new`s a class that extends `HTMLElement` without
6267
+ // doing `customElements.define()` first. This matches native browser behavior:
6268
+ // https://stackoverflow.com/a/61883392
6269
+ throw new TypeError('Illegal constructor');
6270
+ }
6271
+ // This constructor is ONLY invoked when it is the user instantiating
6272
+ // an element via new Ctor while Ctor is a registered global constructor.
6273
+ const { PivotCtor, UserCtor } = definition;
6274
+ return new PivotCtor(UserCtor);
6275
+ };
6276
+ HTMLElement.prototype = NativeHTMLElement.prototype;
6277
+ /**
6278
+ * Create a new PivotConstructor for the given tagName, which is capable of being constructed
6279
+ * with a UserConstructor defining the behavior. Passing in the UserConstructor here
6280
+ * is a hint that can be used when registering a custom element with the global custom elements
6281
+ * registry for the first time, which provides certain optimizations. It also marks the UserConstructor
6282
+ * as "safe" to be used when passed in to a PivotConstructor.
6283
+ *
6284
+ * @param tagName - element tag name
6285
+ * @param UserCtor - userland custom element constructor
6286
+ * @returns a new custom element constructor
6287
+ */
6288
+ return function createPivotConstructor(tagName, UserCtor) {
6289
+ tagName = StringToLowerCase.call(tagName);
6290
+ let PivotCtor = pivotCtorByTag.get(tagName);
6291
+ if (isUndefined$1(PivotCtor)) {
6292
+ const definition = getOrCreateDefinitionForConstructor(UserCtor);
6293
+ PivotCtor = createPivotingClass(tagName, definition);
6294
+ // Register a pivoting class as a global custom element
6295
+ nativeDefine.call(nativeRegistry, tagName, PivotCtor);
6296
+ definition.PivotCtor = PivotCtor;
6297
+ // Only cache after nativeDefine has been called, because if it throws an error
6298
+ // (e.g. for an invalid tag name), then we don't want to cache anything.
6299
+ definitionForConstructor.set(UserCtor, definition);
6300
+ pivotCtorByTag.set(tagName, PivotCtor);
6301
+ }
6302
+ // Register a UserConstructor as "safe" to be used within a PivotConstructor
6303
+ registeredUserCtors.add(UserCtor);
6304
+ return PivotCtor;
6305
+ };
6306
+ }
6307
+
6308
+ /*
6309
+ * Copyright (c) 2018, salesforce.com, inc.
6310
+ * All rights reserved.
6311
+ * SPDX-License-Identifier: MIT
6312
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6313
+ */
6314
+ let createScopedConstructor;
6315
+ let CachedHTMLElement; // We only call `createScopedRegistry()` if the browser supports custom elements and
6316
+ // ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is enabled, because we don't want to patch eagerly if the flag is disabled
6317
+ // or we're in a legacy browser.
6318
+
6319
+ if (lwcRuntimeFlags.ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY) {
6320
+ if (hasCustomElements) {
6321
+ // If ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is true, then we eagerly initialize the scoped registry.
6322
+ // It's assumed that ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is set *before* LWC loads, and never changes.
6323
+ //
6324
+ // Why not lazily patch in `createCustomElement`? Well, this could lead to subtle bugs, e.g.:
6325
+ //
6326
+ // 1. LWC loads
6327
+ // 2. `const Ctor = class extends HTMLElement {}`
6328
+ // 3. `lwc.createElement(...)` // here we lazily patch
6329
+ // 4. `customElements.define('x-foo', Ctor)` // throws error because class is bound to stale HTMLElement
6330
+ //
6331
+ // To reduce the risk of this, it's safer to patch the registry eagerly.
6332
+ createScopedConstructor = createScopedRegistry(); // It's important to cache window.HTMLElement here. Otherwise, someone else could overwrite window.HTMLElement (e.g.
6333
+ // another copy of the engine, or another scoping implementation) and we would get "Illegal constructor" errors
6334
+ // because the HTMLElement prototypes are mixed up.
6335
+ //
6336
+ // The reason this happens is that the scoping implementation overwrites window.HTMLElement and expects to work
6337
+ // with that version of HTMLElement. So if you load two copies of the scoping implementation in the same environment,
6338
+ // the second one may accidentally grab window.HTMLElement from the first (when doing `class extends HTMLElement`).
6339
+ // Caching avoids this problem.
6340
+
6341
+ CachedHTMLElement = window.HTMLElement;
6342
+ }
6343
+ } // Creates a constructor that is intended to be used as the UserConstructor in a scoped (pivots) registry.
6344
+ // In this case, the upgradeCallback only needs to be defined once because we create these on-demand,
6345
+ // multiple times per tag name.
6346
+
6347
+
6348
+ const createUserConstructor = (upgradeCallback, connectedCallback, disconnectedCallback, HTMLElementToExtend) => {
6349
+ // TODO [#2972]: this class should expose observedAttributes as necessary
6350
+ return class UserConstructor extends HTMLElementToExtend {
6351
+ constructor() {
6352
+ super();
6353
+ upgradeCallback(this);
6354
+ }
6355
+
6356
+ connectedCallback() {
6357
+ connectedCallback(this);
6358
+ }
6359
+
6360
+ disconnectedCallback() {
6361
+ disconnectedCallback(this);
6362
+ }
6363
+
6364
+ };
6365
+ };
6366
+
6367
+ function createCustomElementScoped(tagName, upgradeCallback, connectedCallback, disconnectedCallback) {
6368
+ if (isUndefined$1(createScopedConstructor) || isUndefined$1(CachedHTMLElement)) {
6369
+ // This error should be impossible to hit
6370
+ throw new Error('The flag ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY must be set to true to use this feature');
6371
+ }
6372
+
6373
+ const UserConstructor = createUserConstructor(upgradeCallback, connectedCallback, disconnectedCallback, CachedHTMLElement);
6374
+ const ScopedConstructor = createScopedConstructor(tagName, UserConstructor);
6375
+ return new ScopedConstructor(UserConstructor);
6376
+ }
6377
+
6378
+ /*
6379
+ * Copyright (c) 2018, salesforce.com, inc.
6380
+ * All rights reserved.
6381
+ * SPDX-License-Identifier: MIT
6382
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6383
+ */
6384
+ /**
6385
+ * We have three modes for creating custom elements:
6386
+ *
6387
+ * 1. Compat (legacy) browser support (e.g. IE11). Totally custom, doesn't rely on native browser APIs.
6388
+ * 2. "Vanilla" custom elements registry. This system actually still allows us to have two LWC components with the
6389
+ * same tag name, via a simple trick: every custom element constructor we define in the registry is basically
6390
+ * the same. It's essentially a dummy `class extends HTMLElement` that accepts an `upgradeCallback` in its
6391
+ * constructor, which allows us to have completely customized functionality for different components.
6392
+ * 3. "Scoped" (or "pivot") custom elements. This relies on a sophisticated system that emulates the "scoped custom
6393
+ * elements registry" proposal, with support for avoiding conflicts in tag names both between LWC components and
6394
+ * between LWC components and third-party elements. This uses a similar trick to #2, but is much more complex
6395
+ * because it must patch the global `customElements` and `HTMLElement` objects.
6396
+ */
6397
+
6398
+ let createCustomElement;
6399
+
6400
+ if (hasCustomElements) {
6401
+ if (lwcRuntimeFlags.ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY) {
6402
+ createCustomElement = createCustomElementScoped;
6403
+ } else {
6404
+ // use global custom elements registry (vanilla)
6405
+ createCustomElement = createCustomElementVanilla;
6406
+ }
6407
+ } else {
6408
+ // no registry available here
6409
+ createCustomElement = createCustomElementCompat;
6410
+ }
6411
+
5841
6412
  /*
5842
6413
  * Copyright (c) 2018, salesforce.com, inc.
5843
6414
  * All rights reserved.
@@ -5898,7 +6469,7 @@
5898
6469
  function isNull(obj) {
5899
6470
  return obj === null;
5900
6471
  }
5901
- /** version: 2.25.1 */
6472
+ /** version: 2.26.1 */
5902
6473
 
5903
6474
  /*
5904
6475
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5906,65 +6477,6 @@
5906
6477
  * SPDX-License-Identifier: MIT
5907
6478
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5908
6479
  */
5909
- exports.getCustomElement = void 0;
5910
- exports.defineCustomElement = void 0;
5911
- let HTMLElementConstructor;
5912
- function isCustomElementRegistryAvailable() {
5913
- if (typeof customElements === 'undefined') {
5914
- return false;
5915
- }
5916
- try {
5917
- // dereference HTMLElement global because babel wraps globals in compat mode with a
5918
- // _wrapNativeSuper()
5919
- // This is a problem because LWCUpgradableElement extends renderer.HTMLElementExported which does not
5920
- // get wrapped by babel.
5921
- const HTMLElementAlias = HTMLElement;
5922
- // In case we use compat mode with a modern browser, the compat mode transformation
5923
- // invokes the DOM api with an .apply() or .call() to initialize any DOM api sub-classing,
5924
- // which are not equipped to be initialized that way.
5925
- class clazz extends HTMLElementAlias {
5926
- }
5927
- customElements.define('lwc-test-' + Math.floor(Math.random() * 1000000), clazz);
5928
- new clazz();
5929
- return true;
5930
- }
5931
- catch (_a) {
5932
- return false;
5933
- }
5934
- }
5935
- if (isCustomElementRegistryAvailable()) {
5936
- exports.getCustomElement = customElements.get.bind(customElements);
5937
- exports.defineCustomElement = customElements.define.bind(customElements);
5938
- HTMLElementConstructor = HTMLElement;
5939
- }
5940
- else {
5941
- const registry = Object.create(null);
5942
- const reverseRegistry = new WeakMap();
5943
- exports.defineCustomElement = function define(name, ctor) {
5944
- if (name !== String.prototype.toLowerCase.call(name) || registry[name]) {
5945
- throw new TypeError(`Invalid Registration`);
5946
- }
5947
- registry[name] = ctor;
5948
- reverseRegistry.set(ctor, name);
5949
- };
5950
- exports.getCustomElement = function get(name) {
5951
- return registry[name];
5952
- };
5953
- HTMLElementConstructor = function HTMLElement() {
5954
- if (!(this instanceof HTMLElement)) {
5955
- throw new TypeError(`Invalid Invocation`);
5956
- }
5957
- const { constructor } = this;
5958
- const name = reverseRegistry.get(constructor);
5959
- if (!name) {
5960
- throw new TypeError(`Invalid Construction`);
5961
- }
5962
- const elm = document.createElement(name);
5963
- Object.setPrototypeOf(elm, constructor.prototype);
5964
- return elm;
5965
- };
5966
- HTMLElementConstructor.prototype = HTMLElement.prototype;
5967
- }
5968
6480
  function cloneNode(node, deep) {
5969
6481
  return node.cloneNode(deep);
5970
6482
  }
@@ -6138,9 +6650,7 @@
6138
6650
  function assertInstanceOfHTMLElement(elm, msg) {
6139
6651
  assert.invariant(elm instanceof HTMLElement, msg);
6140
6652
  }
6141
- const HTMLElementExported = HTMLElementConstructor;
6142
6653
 
6143
- exports.HTMLElementExported = HTMLElementExported;
6144
6654
  exports.addEventListener = addEventListener;
6145
6655
  exports.assertInstanceOfHTMLElement = assertInstanceOfHTMLElement;
6146
6656
  exports.attachShadow = attachShadow;
@@ -6200,6 +6710,8 @@
6200
6710
  {
6201
6711
  // insertStyleSheet implementation shares a global cache of stylesheet data
6202
6712
  insertStylesheet,
6713
+ // relies on a shared global cache
6714
+ createCustomElement,
6203
6715
  isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
6204
6716
  isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
6205
6717
  });
@@ -6295,36 +6807,44 @@
6295
6807
  // This WeakSet usage is valid because this functionality is not meant to run in IE11.
6296
6808
  const hydratedCustomElements = new WeakSet();
6297
6809
  function buildCustomElementConstructor(Ctor) {
6810
+ var _a;
6298
6811
  const HtmlPrototype = getComponentHtmlPrototype(Ctor);
6299
- return class extends HtmlPrototype {
6300
- constructor() {
6301
- super();
6302
- if (this.isConnected) {
6303
- // this if block is hit when there's already an un-upgraded element in the DOM with the same tag name.
6304
- hydrateComponent(this, Ctor, {});
6305
- hydratedCustomElements.add(this);
6812
+ const { observedAttributes } = HtmlPrototype;
6813
+ const { attributeChangedCallback } = HtmlPrototype.prototype;
6814
+ return _a = class extends HTMLElement {
6815
+ constructor() {
6816
+ super();
6817
+ if (this.isConnected) {
6818
+ // this if block is hit when there's already an un-upgraded element in the DOM with the same tag name.
6819
+ hydrateComponent(this, Ctor, {});
6820
+ hydratedCustomElements.add(this);
6821
+ }
6822
+ else {
6823
+ createVM(this, Ctor, renderer, {
6824
+ mode: 'open',
6825
+ owner: null,
6826
+ tagName: this.tagName,
6827
+ });
6828
+ }
6306
6829
  }
6307
- else {
6308
- createVM(this, Ctor, renderer, {
6309
- mode: 'open',
6310
- owner: null,
6311
- tagName: this.tagName,
6312
- });
6830
+ connectedCallback() {
6831
+ if (hydratedCustomElements.has(this)) {
6832
+ // This is an un-upgraded element that was hydrated in the constructor.
6833
+ hydratedCustomElements.delete(this);
6834
+ }
6835
+ else {
6836
+ connectRootElement(this);
6837
+ }
6313
6838
  }
6314
- }
6315
- connectedCallback() {
6316
- if (hydratedCustomElements.has(this)) {
6317
- // This is an un-upgraded element that was hydrated in the constructor.
6318
- hydratedCustomElements.delete(this);
6839
+ disconnectedCallback() {
6840
+ disconnectRootElement(this);
6319
6841
  }
6320
- else {
6321
- connectRootElement(this);
6842
+ attributeChangedCallback(name, oldValue, newValue) {
6843
+ attributeChangedCallback.call(this, name, oldValue, newValue);
6322
6844
  }
6323
- }
6324
- disconnectedCallback() {
6325
- disconnectRootElement(this);
6326
- }
6327
- };
6845
+ },
6846
+ _a.observedAttributes = observedAttributes,
6847
+ _a;
6328
6848
  }
6329
6849
 
6330
6850
  /*
@@ -6408,8 +6928,13 @@
6408
6928
  throw new TypeError(`"createElement" function expects an "is" option with a valid component constructor.`);
6409
6929
  }
6410
6930
 
6411
- const UpgradableConstructor = getUpgradableConstructor(sel, renderer);
6412
- let wasComponentUpgraded = false; // the custom element from the registry is expecting an upgrade callback
6931
+ const {
6932
+ createCustomElement
6933
+ } = renderer; // tagName must be all lowercase, unfortunately, we have legacy code that is
6934
+ // passing `sel` as a camel-case, which makes them invalid custom elements name
6935
+ // the following line guarantees that this does not leaks beyond this point.
6936
+
6937
+ const tagName = StringToLowerCase.call(sel); // the custom element from the registry is expecting an upgrade callback
6413
6938
 
6414
6939
  /**
6415
6940
  * Note: if the upgradable constructor does not expect, or throw when we new it
@@ -6418,9 +6943,9 @@
6418
6943
  * an upgradable custom element.
6419
6944
  */
6420
6945
 
6421
- const element = new UpgradableConstructor(elm => {
6946
+ const upgradeCallback = elm => {
6422
6947
  createVM(elm, Ctor, renderer, {
6423
- tagName: sel,
6948
+ tagName,
6424
6949
  mode: options.mode !== 'closed' ? 'open' : 'closed',
6425
6950
  owner: null
6426
6951
  });
@@ -6429,15 +6954,21 @@
6429
6954
  ConnectingSlot.set(elm, connectRootElement);
6430
6955
  DisconnectingSlot.set(elm, disconnectRootElement);
6431
6956
  }
6957
+ };
6432
6958
 
6433
- wasComponentUpgraded = true;
6434
- });
6959
+ const connectedCallback = elm => {
6960
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
6961
+ connectRootElement(elm);
6962
+ }
6963
+ };
6435
6964
 
6436
- if (!wasComponentUpgraded) {
6437
- /* eslint-disable-next-line no-console */
6438
- console.error(`Unexpected tag name "${sel}". This name is a registered custom element, preventing LWC to upgrade the element.`);
6439
- }
6965
+ const disconnectedCallback = elm => {
6966
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
6967
+ disconnectRootElement(elm);
6968
+ }
6969
+ };
6440
6970
 
6971
+ const element = createCustomElement(tagName, upgradeCallback, connectedCallback, disconnectedCallback);
6441
6972
  return element;
6442
6973
  }
6443
6974
 
@@ -6509,7 +7040,7 @@
6509
7040
  });
6510
7041
  freeze(LightningElement);
6511
7042
  seal(LightningElement.prototype);
6512
- /* version: 2.25.1 */
7043
+ /* version: 2.26.1 */
6513
7044
 
6514
7045
  exports.LightningElement = LightningElement;
6515
7046
  exports.__unstable__ProfilerControl = profilerControl;