lwc 2.36.0 → 2.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +26 -576
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +26 -576
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +18 -568
  5. package/dist/engine-dom/iife/es5/engine-dom.js +38 -654
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +30 -646
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +26 -576
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +18 -568
  11. package/dist/engine-dom/umd/es5/engine-dom.js +38 -654
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +30 -646
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +38 -24
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +38 -25
  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 +7 -7
@@ -335,9 +335,9 @@
335
335
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
336
336
  */
337
337
  // Increment whenever the LWC template compiler changes
338
- const LWC_VERSION = "2.36.0";
338
+ const LWC_VERSION = "2.37.0";
339
339
  const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
340
- /** version: 2.36.0 */
340
+ /** version: 2.37.0 */
341
341
 
342
342
  /**
343
343
  * Copyright (C) 2018 salesforce.com, inc.
@@ -357,10 +357,8 @@
357
357
  ENABLE_WIRE_SYNC_EMIT: null,
358
358
  ENABLE_LIGHT_GET_ROOT_NODE_PATCH: null,
359
359
  DISABLE_LIGHT_DOM_UNSCOPED_CSS: null,
360
- ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
361
360
  ENABLE_FROZEN_TEMPLATE: null,
362
361
  DISABLE_ARIA_REFLECTION_POLYFILL: null,
363
- ENABLE_PROGRAMMATIC_STYLESHEETS: null,
364
362
  };
365
363
  if (!_globalThis.lwcRuntimeFlags) {
366
364
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
@@ -416,7 +414,7 @@
416
414
  setFeatureFlag(name, value);
417
415
  }
418
416
  }
419
- /** version: 2.36.0 */
417
+ /** version: 2.37.0 */
420
418
 
421
419
  /**
422
420
  * Copyright (C) 2018 salesforce.com, inc.
@@ -480,7 +478,7 @@
480
478
  }
481
479
  }
482
480
  }
483
- /** version: 2.36.0 */
481
+ /** version: 2.37.0 */
484
482
 
485
483
  /*
486
484
  * Copyright (c) 2018, salesforce.com, inc.
@@ -6245,18 +6243,16 @@
6245
6243
  }
6246
6244
  // Validate and flatten any stylesheets defined as `static stylesheets`
6247
6245
  function computeStylesheets(vm, ctor) {
6248
- if (lwcRuntimeFlags.ENABLE_PROGRAMMATIC_STYLESHEETS) {
6249
- warnOnStylesheetsMutation(ctor);
6250
- const {
6251
- stylesheets
6252
- } = ctor;
6253
- if (!isUndefined$1(stylesheets)) {
6254
- const valid = validateComponentStylesheets(vm, stylesheets);
6255
- if (valid) {
6256
- return flattenStylesheets(stylesheets);
6257
- } else if (process.env.NODE_ENV !== 'production') {
6258
- logError(`static stylesheets must be an array of CSS stylesheets. Found invalid stylesheets on <${vm.tagName}>`, vm);
6259
- }
6246
+ warnOnStylesheetsMutation(ctor);
6247
+ const {
6248
+ stylesheets
6249
+ } = ctor;
6250
+ if (!isUndefined$1(stylesheets)) {
6251
+ const valid = validateComponentStylesheets(vm, stylesheets);
6252
+ if (valid) {
6253
+ return flattenStylesheets(stylesheets);
6254
+ } else if (process.env.NODE_ENV !== 'production') {
6255
+ logError(`static stylesheets must be an array of CSS stylesheets. Found invalid stylesheets on <${vm.tagName}>`, vm);
6260
6256
  }
6261
6257
  }
6262
6258
  return null;
@@ -6650,7 +6646,7 @@
6650
6646
  // The goal of this code is to detect invalid cross-root ARIA references in synthetic shadow DOM.
6651
6647
  // These invalid references should be fixed before the offending components can be migrated to native shadow DOM.
6652
6648
  // When invalid usage is detected, we warn in dev mode and call the reporting API if enabled.
6653
- // See: https://lwc.dev/guide/accessibility#link-ids-and-aria-attributes-from-different-templates
6649
+ // See: https://sfdc.co/synthetic-aria
6654
6650
  //
6655
6651
  // Use the unpatched native getElementById/querySelectorAll rather than the synthetic one
6656
6652
  const getElementById = _globalThis[KEY__NATIVE_GET_ELEMENT_BY_ID];
@@ -6677,7 +6673,7 @@
6677
6673
  // Avoid excessively logging to the console in the case of duplicates.
6678
6674
  logWarnOnce(`Element <${source.tagName.toLowerCase()}> uses attribute "${attrName}" to reference element ` +
6679
6675
  `<${target.tagName.toLowerCase()}>, which is not in the same shadow root. This will break in native shadow DOM. ` +
6680
- `For details, see: https://lwc.dev/guide/accessibility#link-ids-and-aria-attributes-from-different-templates`, vm);
6676
+ `For details, see: https://sfdc.co/synthetic-aria`, vm);
6681
6677
  }
6682
6678
  }
6683
6679
  function parseIdRefAttributeValue(attrValue) {
@@ -6831,7 +6827,7 @@
6831
6827
  if (!isLightningElement(elm)) {
6832
6828
  const vm = findVM(elm);
6833
6829
  if (process.env.NODE_ENV !== 'production') {
6834
- logWarnOnce(`Element <${elm.tagName.toLowerCase()}> ` + (isUndefined$1(vm) ? '' : `owned by <${vm.elm.tagName.toLowerCase()}> `) + `uses non-standard property "${prop}". This will be removed in a future version of LWC. ` + `See https://lwc.dev/guide/accessibility#deprecated-aria-reflected-properties`);
6830
+ logWarnOnce(`Element <${elm.tagName.toLowerCase()}> ` + (isUndefined$1(vm) ? '' : `owned by <${vm.elm.tagName.toLowerCase()}> `) + `uses non-standard property "${prop}". This will be removed in a future version of LWC. ` + `See https://sfdc.co/deprecated-aria`);
6835
6831
  }
6836
6832
  report(2 /* ReportingEventId.NonStandardAriaReflection */, {
6837
6833
  tagName: vm === null || vm === void 0 ? void 0 : vm.tagName,
@@ -7401,7 +7397,7 @@
7401
7397
  }
7402
7398
  function reportViolation(type, eventId, prop) {
7403
7399
  if (process.env.NODE_ENV !== 'production') {
7404
- logWarnOnce(`Mutating the "${prop}" property on a ${type} ` + `is deprecated and will be removed in a future version of LWC. ` + `See: https://lwc.dev/guide/css#deprecated-template-mutation`);
7400
+ logWarnOnce(`Mutating the "${prop}" property on a ${type} ` + `is deprecated and will be removed in a future version of LWC. ` + `See: https://sfdc.co/template-mutation`);
7405
7401
  }
7406
7402
  report(eventId, {
7407
7403
  propertyName: prop
@@ -7581,7 +7577,7 @@
7581
7577
  }
7582
7578
  return ctor;
7583
7579
  }
7584
- /* version: 2.36.0 */
7580
+ /* version: 2.37.0 */
7585
7581
 
7586
7582
  /*
7587
7583
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7924,545 +7920,6 @@
7924
7920
  }
7925
7921
  };
7926
7922
 
7927
- /*
7928
- * Copyright (c) 2020, salesforce.com, inc.
7929
- * All rights reserved.
7930
- * SPDX-License-Identifier: MIT
7931
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7932
- */
7933
- /**
7934
- * Create a scoped registry, i.e. a function that can create custom elements whose tag names
7935
- * do not conflict with third-party custom elements having the same tag name.
7936
- */
7937
- function createScopedRegistry() {
7938
- if (!hasCustomElements) {
7939
- // This code should never be reached, because we don't use the pivot registry if
7940
- // custom elements are unavailable.
7941
- throw new Error('Custom elements are not supported in this environment.');
7942
- }
7943
- const { HTMLElement: NativeHTMLElement } = window;
7944
- const { hasAttribute: nativeHasAttribute, setAttribute: nativeSetAttribute, removeAttribute: nativeRemoveAttribute, getAttribute: nativeGetAttribute, } = NativeHTMLElement.prototype;
7945
- const definitionForElement = new WeakMap();
7946
- const pendingRegistryForElement = new WeakMap();
7947
- const definitionForConstructor = new WeakMap();
7948
- const registeredUserCtors = new WeakSet();
7949
- const registeredPivotCtors = new WeakSet();
7950
- const pivotCtorByTag = new Map();
7951
- const globalDefinitionsByTag = new Map();
7952
- const globalDefinitionsByClass = new Map();
7953
- const awaitingUpgrade = new Map();
7954
- const pendingWhenDefinedCallbacks = new Map();
7955
- const EMPTY_SET = new Set();
7956
- function createDefinitionRecord(constructor) {
7957
- var _a;
7958
- const { connectedCallback, disconnectedCallback, formAssociatedCallback, formDisabledCallback, formResetCallback, formStateRestoreCallback, adoptedCallback, attributeChangedCallback, } = constructor.prototype;
7959
- const formAssociated = Boolean(constructor.formAssociated);
7960
- const observedAttributes = new Set((_a = constructor.observedAttributes) !== null && _a !== void 0 ? _a : []);
7961
- return {
7962
- UserCtor: constructor,
7963
- PivotCtor: undefined,
7964
- connectedCallback,
7965
- disconnectedCallback,
7966
- formAssociatedCallback,
7967
- formDisabledCallback,
7968
- formResetCallback,
7969
- formStateRestoreCallback,
7970
- adoptedCallback,
7971
- attributeChangedCallback,
7972
- observedAttributes,
7973
- formAssociated,
7974
- };
7975
- }
7976
- // Helper to create stand-in element for each tagName registered that delegates out to the registry for the given
7977
- // element. Note that the `registeredDefinition` represents the constructor that was used to register during
7978
- // `customElements.define()`. Whereas the `pivotDefinition` represents the constructor that is passed when the pivot
7979
- // constructor is invoked with another constructor.
7980
- function createPivotingClass(tagName, registeredDefinition) {
7981
- class PivotCtor extends NativeHTMLElement {
7982
- constructor(UserCtor) {
7983
- // This constructor can only be invoked by:
7984
- // a) the browser instantiating an element from parsing or via document.createElement.
7985
- // b) LWC new PivotClass (This constructor is NOT observable/accessible in user-land).
7986
- // b) new UserClass.
7987
- // When LWC instantiates it, it will pass the upgrading definition as an argument
7988
- // If the caller signals via UserCtor that this is in fact a controlled
7989
- // definition, we use that one, otherwise fallback to the global
7990
- // internal registry.
7991
- super();
7992
- const userCtorIsDefined = !isUndefined$1(UserCtor);
7993
- if (userCtorIsDefined) {
7994
- if (!isConstructor(UserCtor)) {
7995
- throw new TypeError(`Failed to create custom element: the provided constructor is not a constructor.`);
7996
- }
7997
- if (!registeredUserCtors.has(UserCtor)) {
7998
- throw new Error(`Failed to create custom element: the provided constructor is unregistered: ${UserCtor.name}.`);
7999
- }
8000
- }
8001
- const definition = userCtorIsDefined
8002
- ? getOrCreateDefinitionForConstructor(UserCtor)
8003
- : globalDefinitionsByTag.get(tagName);
8004
- if (!isUndefined$1(definition)) {
8005
- internalUpgrade(this, registeredDefinition, definition);
8006
- }
8007
- else {
8008
- // This is the case in which there is no global definition, and
8009
- // it is not handled by LWC (otherwise it will have a valid UserCtor)
8010
- // so we need to add it to the pending queue just in case it eventually
8011
- // gets defined in the global registry.
8012
- pendingRegistryForElement.set(this, registeredDefinition);
8013
- }
8014
- }
8015
- connectedCallback() {
8016
- var _a;
8017
- const definition = definitionForElement.get(this);
8018
- if (!isUndefined$1(definition)) {
8019
- // Delegate out to user callback
8020
- (_a = definition.connectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
8021
- }
8022
- else {
8023
- // Register for upgrade when defined (only when connected, so we don't leak)
8024
- let awaiting = awaitingUpgrade.get(tagName);
8025
- if (isUndefined$1(awaiting)) {
8026
- awaitingUpgrade.set(tagName, (awaiting = new Set()));
8027
- }
8028
- awaiting.add(this);
8029
- }
8030
- }
8031
- disconnectedCallback() {
8032
- var _a;
8033
- const definition = definitionForElement.get(this);
8034
- if (!isUndefined$1(definition)) {
8035
- // Delegate out to user callback
8036
- (_a = definition.disconnectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
8037
- }
8038
- else {
8039
- // Un-register for upgrade when defined (so we don't leak)
8040
- const awaiting = awaitingUpgrade.get(tagName);
8041
- // At this point, awaiting should never be undefined, because connectedCallback
8042
- // must have been called before disconnectedCallback. But just to be safe, we check
8043
- if (!isUndefined$1(awaiting)) {
8044
- awaiting.delete(this);
8045
- }
8046
- }
8047
- }
8048
- formAssociatedCallback(form) {
8049
- var _a;
8050
- const definition = definitionForElement.get(this);
8051
- (_a = definition === null || definition === void 0 ? void 0 : definition.formAssociatedCallback) === null || _a === void 0 ? void 0 : _a.call(this, form);
8052
- }
8053
- formDisabledCallback(disabled) {
8054
- var _a;
8055
- const definition = definitionForElement.get(this);
8056
- (_a = definition === null || definition === void 0 ? void 0 : definition.formDisabledCallback) === null || _a === void 0 ? void 0 : _a.call(this, disabled);
8057
- }
8058
- formResetCallback() {
8059
- var _a;
8060
- const definition = definitionForElement.get(this);
8061
- (_a = definition === null || definition === void 0 ? void 0 : definition.formResetCallback) === null || _a === void 0 ? void 0 : _a.call(this);
8062
- }
8063
- formStateRestoreCallback(state, mode) {
8064
- var _a;
8065
- const definition = definitionForElement.get(this);
8066
- (_a = definition === null || definition === void 0 ? void 0 : definition.formStateRestoreCallback) === null || _a === void 0 ? void 0 : _a.call(this, state, mode);
8067
- }
8068
- adoptedCallback() {
8069
- var _a;
8070
- const definition = definitionForElement.get(this);
8071
- (_a = definition === null || definition === void 0 ? void 0 : definition.adoptedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
8072
- }
8073
- attributeChangedCallback(name, oldValue, newValue) {
8074
- var _a;
8075
- const definition = definitionForElement.get(this);
8076
- // if both definitions are the same, then the observedAttributes is the same,
8077
- // but if they are different, only if the runtime definition has the attribute
8078
- // marked as observed, then it should invoke attributeChangedCallback.
8079
- if (registeredDefinition === definition ||
8080
- (definition === null || definition === void 0 ? void 0 : definition.observedAttributes.has(name))) {
8081
- (_a = definition.attributeChangedCallback) === null || _a === void 0 ? void 0 : _a.apply(this, [name, oldValue, newValue]);
8082
- }
8083
- }
8084
- }
8085
- PivotCtor.observedAttributes = [...registeredDefinition.observedAttributes];
8086
- // TODO [#3000]: support case where registeredDefinition is not form-associated, but later definition is.
8087
- PivotCtor.formAssociated = registeredDefinition.formAssociated;
8088
- registeredPivotCtors.add(PivotCtor);
8089
- return PivotCtor;
8090
- }
8091
- function getNewObservedAttributes(registeredDefinition, pivotDefinition) {
8092
- const { observedAttributes, attributeChangedCallback } = pivotDefinition;
8093
- if (observedAttributes.size === 0 || isUndefined$1(attributeChangedCallback)) {
8094
- // This instance does not need to observe any attributes, no need to patch
8095
- return EMPTY_SET;
8096
- }
8097
- // Natively, the attributes observed by the registered definition are going to be taken
8098
- // care of by the browser, only the difference between the two sets has to be taken
8099
- // care by the patched version.
8100
- return new Set([...pivotDefinition.observedAttributes].filter((x) => !registeredDefinition.observedAttributes.has(x)));
8101
- }
8102
- function throwAsyncError(error) {
8103
- // Per native custom element behavior, errors thrown in attributeChangedCallback
8104
- // become unhandled async errors. We use setTimeout() instead of Promise.resolve()
8105
- // to make it an unhandled error rather than an unhandled rejection.
8106
- setTimeout(() => {
8107
- throw error;
8108
- });
8109
- }
8110
- // Helper to patch `setAttribute`/`getAttribute` to implement `attributeChangedCallback`.
8111
- // Why is this necessary? Well basically, you can't change the `observedAttributes` after
8112
- // a custom element is defined. So with pivots, if two classes share the same tag name,
8113
- // and the second class observes attributes that aren't observed by the first one,
8114
- // then those attributes can never be observed by the native `observedAttributes` system.
8115
- // So we have to simulate it by patching `getAttribute`/`removeAttribute`. Note that
8116
- // we only do this when absolutely necessary, though; i.e. because we've determined
8117
- // that we aren't observing the attributes we need to.
8118
- function patchAttributes(instance, registeredDefinition, pivotDefinition) {
8119
- const newObservedAttributes = getNewObservedAttributes(registeredDefinition, pivotDefinition);
8120
- if (newObservedAttributes.size === 0) {
8121
- return;
8122
- }
8123
- const { attributeChangedCallback } = pivotDefinition;
8124
- // Patch the instance.
8125
- // Note we use the native `getAttribute` rather than the super's `getAttribute` because
8126
- // we don't actually want it to be observable that we're calling `getAttribute` from
8127
- // `setAttribute` and `removeAttribute`.
8128
- // TODO [#2994]: this should handle reflected properties such as `ariaLabel` and `role`.
8129
- defineProperties(instance, {
8130
- setAttribute: {
8131
- value: function setAttribute(name, value) {
8132
- if (newObservedAttributes.has(name)) {
8133
- const old = nativeGetAttribute.call(this, name);
8134
- nativeSetAttribute.call(this, name, value);
8135
- try {
8136
- attributeChangedCallback.call(this, name, old, value + '');
8137
- }
8138
- catch (error) {
8139
- throwAsyncError(error);
8140
- }
8141
- }
8142
- else {
8143
- nativeSetAttribute.call(this, name, value);
8144
- }
8145
- },
8146
- writable: true,
8147
- enumerable: true,
8148
- configurable: true,
8149
- },
8150
- removeAttribute: {
8151
- value: function removeAttribute(name) {
8152
- if (newObservedAttributes.has(name)) {
8153
- const old = nativeGetAttribute.call(this, name);
8154
- nativeRemoveAttribute.call(this, name);
8155
- try {
8156
- attributeChangedCallback.call(this, name, old, null);
8157
- }
8158
- catch (error) {
8159
- throwAsyncError(error);
8160
- }
8161
- }
8162
- else {
8163
- nativeRemoveAttribute.call(this, name);
8164
- }
8165
- },
8166
- writable: true,
8167
- enumerable: true,
8168
- configurable: true,
8169
- },
8170
- });
8171
- }
8172
- function patchAttributesDuringUpgrade(instance, registeredDefinition, pivotDefinition) {
8173
- // The below case patches observed attributes for the case where the HTML element is upgraded
8174
- // from a pre-existing one in the DOM.
8175
- const newObservedAttributes = getNewObservedAttributes(registeredDefinition, pivotDefinition);
8176
- if (getNewObservedAttributes(registeredDefinition, pivotDefinition).size === 0) {
8177
- return;
8178
- }
8179
- const { attributeChangedCallback } = pivotDefinition;
8180
- // Approximate observedAttributes from the user class, but only for the new observed attributes
8181
- newObservedAttributes.forEach((name) => {
8182
- if (nativeHasAttribute.call(instance, name)) {
8183
- const newValue = nativeGetAttribute.call(instance, name);
8184
- attributeChangedCallback.call(instance, name, null, newValue);
8185
- }
8186
- });
8187
- }
8188
- // User extends this HTMLElement, which returns the CE being upgraded
8189
- let upgradingInstance;
8190
- // Helper to upgrade an instance with a CE definition using "constructor call trick"
8191
- function internalUpgrade(instance, registeredDefinition, pivotDefinition) {
8192
- setPrototypeOf(instance, pivotDefinition.UserCtor.prototype);
8193
- definitionForElement.set(instance, pivotDefinition);
8194
- // attributes patches when needed
8195
- if (pivotDefinition !== registeredDefinition) {
8196
- patchAttributes(instance, registeredDefinition, pivotDefinition);
8197
- }
8198
- // Tricking the construction path to believe that a new instance is being created,
8199
- // that way it will execute the super initialization mechanism but the HTMLElement
8200
- // constructor will reuse the instance by returning the upgradingInstance.
8201
- // This is by far the most important piece of the puzzle
8202
- upgradingInstance = instance;
8203
- // By `new`ing the UserCtor, we now jump to the constructor for the overridden global HTMLElement
8204
- // The reason this happens is that the UserCtor extends HTMLElement, so it calls the `super()`.
8205
- // Note that `upgradingInstance` is explicitly handled in the HTMLElement constructor.
8206
- new pivotDefinition.UserCtor();
8207
- patchAttributesDuringUpgrade(instance, registeredDefinition, pivotDefinition);
8208
- }
8209
- function isConstructor(constructor) {
8210
- return isFunction$1(constructor) && isObject(constructor.prototype);
8211
- }
8212
- function getOrCreateDefinitionForConstructor(constructor) {
8213
- if (!isConstructor(constructor)) {
8214
- throw new TypeError('The referenced constructor is not a constructor.');
8215
- }
8216
- const definition = definitionForConstructor.get(constructor);
8217
- if (!isUndefined$1(definition)) {
8218
- return definition;
8219
- }
8220
- return createDefinitionRecord(constructor);
8221
- }
8222
- // Defer a `whenDefined()` callback until an externally-visible custom element is defined
8223
- function createPendingWhenDefinedCallback(tagName) {
8224
- return new Promise((resolve) => {
8225
- let resolvers = pendingWhenDefinedCallbacks.get(tagName);
8226
- if (isUndefined$1(resolvers)) {
8227
- resolvers = [];
8228
- pendingWhenDefinedCallbacks.set(tagName, resolvers);
8229
- }
8230
- resolvers.push(resolve);
8231
- });
8232
- }
8233
- // Call any pending `whenDefined()` callbacks
8234
- function flushPendingWhenDefinedCallbacks(tagName, ctor) {
8235
- const resolvers = pendingWhenDefinedCallbacks.get(tagName);
8236
- if (!isUndefined$1(resolvers)) {
8237
- for (const resolver of resolvers) {
8238
- resolver(ctor);
8239
- }
8240
- }
8241
- pendingWhenDefinedCallbacks.delete(tagName);
8242
- }
8243
- const { customElements: nativeRegistry } = window;
8244
- const { define: nativeDefine, whenDefined: nativeWhenDefined, get: nativeGet } = nativeRegistry;
8245
- // patch for the global registry define mechanism
8246
- CustomElementRegistry.prototype.define = function define(tagName, constructor, options) {
8247
- if (options && options.extends) {
8248
- // TODO [#2983]: should we support `extends`?
8249
- throw new DOMException('NotSupportedError: "extends" key in customElements.define() options is not supported.');
8250
- }
8251
- if (globalDefinitionsByTag.has(tagName)) {
8252
- throw new DOMException(`Failed to execute 'define' on 'CustomElementRegistry': the name "${tagName}" has already been used with this registry`);
8253
- }
8254
- if (!isUndefined$1(globalDefinitionsByClass.get(constructor))) {
8255
- throw new DOMException(`Failed to execute 'define' on 'CustomElementRegistry': this constructor has already been used with this registry`);
8256
- }
8257
- const definition = getOrCreateDefinitionForConstructor(constructor);
8258
- registeredUserCtors.add(constructor);
8259
- let PivotCtor = pivotCtorByTag.get(tagName);
8260
- if (isUndefined$1(PivotCtor)) {
8261
- PivotCtor = createPivotingClass(tagName, definition);
8262
- // Register a pivoting class which will handle global registry initializations
8263
- nativeDefine.call(nativeRegistry, tagName, PivotCtor);
8264
- }
8265
- // Only cache after nativeDefine has been called, because if it throws an error
8266
- // (e.g. for an invalid tag name), then we don't want to cache anything.
8267
- definitionForConstructor.set(constructor, definition);
8268
- pivotCtorByTag.set(tagName, PivotCtor);
8269
- globalDefinitionsByTag.set(tagName, definition);
8270
- globalDefinitionsByClass.set(constructor, definition);
8271
- // For globally defined custom elements, the definition associated
8272
- // to the UserCtor has a back-pointer to PivotCtor in case the user
8273
- // new the UserCtor, so we know how to create the underlying element.
8274
- definition.PivotCtor = PivotCtor;
8275
- // Upgrade any elements created in this scope before customElements.define
8276
- // was called, which should be exhibited by the following steps:
8277
- // 1) LWC registers a tagName for an LWC component.
8278
- // 2) Element with same tagName is created with document.createElement()
8279
- // and inserted into DOM.
8280
- // 3) customElements.define() is called with tagName and non-LWC constructor.
8281
- // This requires immediate upgrade when the new global tagName is defined.
8282
- const awaiting = awaitingUpgrade.get(tagName);
8283
- if (!isUndefined$1(awaiting)) {
8284
- awaitingUpgrade.delete(tagName);
8285
- for (const element of awaiting) {
8286
- const registeredDefinition = pendingRegistryForElement.get(element);
8287
- // At this point, registeredDefinition should never be undefined because awaitingUpgrade
8288
- // is only populated when we haven't run internalUpgrade yet, and we only populate
8289
- // pendingRegistryForElement when internalUpgrade hasn't run yet.
8290
- // But just to be safe, we check.
8291
- if (!isUndefined$1(registeredDefinition)) {
8292
- pendingRegistryForElement.delete(element);
8293
- internalUpgrade(element, registeredDefinition, definition);
8294
- }
8295
- }
8296
- }
8297
- // If anyone called customElements.whenDefined() and is still waiting for a promise resolution, resolve now
8298
- flushPendingWhenDefinedCallbacks(tagName, constructor);
8299
- };
8300
- CustomElementRegistry.prototype.get = function get(tagName) {
8301
- const NativeCtor = nativeGet.call(nativeRegistry, tagName);
8302
- if (!isUndefined$1(NativeCtor)) {
8303
- const definition = globalDefinitionsByTag.get(tagName);
8304
- if (!isUndefined$1(definition)) {
8305
- return definition.UserCtor; // defined by the patched custom elements registry
8306
- }
8307
- if (registeredPivotCtors.has(NativeCtor)) {
8308
- return undefined; // pivot constructors should not be observable, return undefined
8309
- }
8310
- return NativeCtor; // constructor that existed before patching
8311
- }
8312
- };
8313
- CustomElementRegistry.prototype.whenDefined = function whenDefined(tagName) {
8314
- return nativeWhenDefined.call(nativeRegistry, tagName).then((NativeCtor) => {
8315
- const definition = globalDefinitionsByTag.get(tagName);
8316
- if (!isUndefined$1(definition)) {
8317
- return definition.UserCtor;
8318
- }
8319
- // In this case, the custom element must have been defined before the registry patches
8320
- // were applied. So return the non-pivot constructor
8321
- if (isUndefined$1(NativeCtor)) {
8322
- // Chromium bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1335247
8323
- // We can patch the correct behavior using customElements.get()
8324
- NativeCtor = nativeGet.call(nativeRegistry, tagName);
8325
- }
8326
- if (registeredPivotCtors.has(NativeCtor)) {
8327
- // Pivot constructors should not be observable. Wait to resolve the promise
8328
- // if a constructor is ever defined in userland
8329
- return createPendingWhenDefinedCallback(tagName);
8330
- }
8331
- return NativeCtor;
8332
- });
8333
- };
8334
- // This constructor is invoked when we call `new pivotDefinition.UserCtor()`
8335
- // @ts-ignore
8336
- window.HTMLElement = function HTMLElement() {
8337
- // Upgrading case: the pivoting class constructor was run by the browser's
8338
- // native custom elements and we're in the process of running the
8339
- // "constructor-call trick" on the natively constructed instance, so just
8340
- // return that here.
8341
- // This code path is also called when LWC `new`s a PivotCtor.
8342
- const instance = upgradingInstance;
8343
- if (!isUndefined$1(instance)) {
8344
- upgradingInstance = undefined;
8345
- return instance;
8346
- }
8347
- // Construction case: we need to construct the pivoting instance and return it.
8348
- // This is possible when the user register it via global registry and instantiate
8349
- // it via `new Ctor()`.
8350
- const { constructor } = this;
8351
- const definition = globalDefinitionsByClass.get(constructor);
8352
- if (isUndefined$1(definition) || isUndefined$1(definition.PivotCtor)) {
8353
- // This code path is hit if someone `new`s a class that extends `HTMLElement` without
8354
- // doing `customElements.define()` first. This matches native browser behavior:
8355
- // https://stackoverflow.com/a/61883392
8356
- throw new TypeError('Illegal constructor');
8357
- }
8358
- // This constructor is ONLY invoked when it is the user instantiating
8359
- // an element via new Ctor while Ctor is a registered global constructor.
8360
- const { PivotCtor, UserCtor } = definition;
8361
- return new PivotCtor(UserCtor);
8362
- };
8363
- HTMLElement.prototype = NativeHTMLElement.prototype;
8364
- /**
8365
- * Create a new PivotConstructor for the given tagName, which is capable of being constructed
8366
- * with a UserConstructor defining the behavior. Passing in the UserConstructor here
8367
- * is a hint that can be used when registering a custom element with the global custom elements
8368
- * registry for the first time, which provides certain optimizations. It also marks the UserConstructor
8369
- * as "safe" to be used when passed in to a PivotConstructor.
8370
- *
8371
- * @param tagName - element tag name
8372
- * @param UserCtor - userland custom element constructor
8373
- * @returns a new custom element constructor
8374
- */
8375
- return function createPivotConstructor(tagName, UserCtor) {
8376
- tagName = StringToLowerCase.call(tagName);
8377
- let PivotCtor = pivotCtorByTag.get(tagName);
8378
- if (isUndefined$1(PivotCtor)) {
8379
- const definition = getOrCreateDefinitionForConstructor(UserCtor);
8380
- PivotCtor = createPivotingClass(tagName, definition);
8381
- // Register a pivoting class as a global custom element
8382
- nativeDefine.call(nativeRegistry, tagName, PivotCtor);
8383
- definition.PivotCtor = PivotCtor;
8384
- // Only cache after nativeDefine has been called, because if it throws an error
8385
- // (e.g. for an invalid tag name), then we don't want to cache anything.
8386
- definitionForConstructor.set(UserCtor, definition);
8387
- pivotCtorByTag.set(tagName, PivotCtor);
8388
- }
8389
- // Register a UserConstructor as "safe" to be used within a PivotConstructor
8390
- registeredUserCtors.add(UserCtor);
8391
- return PivotCtor;
8392
- };
8393
- }
8394
-
8395
- /*
8396
- * Copyright (c) 2018, salesforce.com, inc.
8397
- * All rights reserved.
8398
- * SPDX-License-Identifier: MIT
8399
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
8400
- */
8401
- let createScopedConstructor;
8402
- let CachedHTMLElement;
8403
- // We only call `createScopedRegistry()` if the browser supports custom elements and
8404
- // ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is enabled, because we don't want to patch eagerly if the flag is disabled
8405
- // or we're in a legacy browser.
8406
- if (lwcRuntimeFlags.ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY) {
8407
- if (hasCustomElements) {
8408
- // If ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is true, then we eagerly initialize the scoped registry.
8409
- // It's assumed that ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY is set *before* LWC loads, and never changes.
8410
- //
8411
- // Why not lazily patch in `createCustomElement`? Well, this could lead to subtle bugs, e.g.:
8412
- //
8413
- // 1. LWC loads
8414
- // 2. `const Ctor = class extends HTMLElement {}`
8415
- // 3. `lwc.createElement(...)` // here we lazily patch
8416
- // 4. `customElements.define('x-foo', Ctor)` // throws error because class is bound to stale HTMLElement
8417
- //
8418
- // To reduce the risk of this, it's safer to patch the registry eagerly.
8419
- createScopedConstructor = createScopedRegistry();
8420
- // It's important to cache window.HTMLElement here. Otherwise, someone else could overwrite window.HTMLElement (e.g.
8421
- // another copy of the engine, or another scoping implementation) and we would get "Illegal constructor" errors
8422
- // because the HTMLElement prototypes are mixed up.
8423
- //
8424
- // The reason this happens is that the scoping implementation overwrites window.HTMLElement and expects to work
8425
- // with that version of HTMLElement. So if you load two copies of the scoping implementation in the same environment,
8426
- // the second one may accidentally grab window.HTMLElement from the first (when doing `class extends HTMLElement`).
8427
- // Caching avoids this problem.
8428
- CachedHTMLElement = window.HTMLElement;
8429
- }
8430
- }
8431
- // Creates a constructor that is intended to be used as the UserConstructor in a scoped (pivots) registry.
8432
- // In this case, the upgradeCallback only needs to be defined once because we create these on-demand,
8433
- // multiple times per tag name.
8434
- const createUserConstructor = (HTMLElementToExtend, upgradeCallback, connectedCallback, disconnectedCallback) => {
8435
- // TODO [#2972]: this class should expose observedAttributes as necessary
8436
- return class UserConstructor extends HTMLElementToExtend {
8437
- constructor() {
8438
- super();
8439
- upgradeCallback(this);
8440
- }
8441
- // Note that there is no need to do the "avoid defining connectedCallback/disconnectedCallback" optimization
8442
- // here, because in create-scoped-registry.ts, the registered class will always have these callbacks anyway.
8443
- // See: https://github.com/salesforce/lwc/pull/3162#issuecomment-1311851174
8444
- connectedCallback() {
8445
- if (!isUndefined$1(connectedCallback)) {
8446
- connectedCallback(this);
8447
- }
8448
- }
8449
- disconnectedCallback() {
8450
- if (!isUndefined$1(disconnectedCallback)) {
8451
- disconnectedCallback(this);
8452
- }
8453
- }
8454
- };
8455
- };
8456
- function createCustomElementScoped(tagName, upgradeCallback, connectedCallback, disconnectedCallback) {
8457
- if (isUndefined$1(createScopedConstructor) || isUndefined$1(CachedHTMLElement)) {
8458
- // This error should be impossible to hit
8459
- throw new Error('The flag ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY must be set to true to use this feature');
8460
- }
8461
- const UserConstructor = createUserConstructor(CachedHTMLElement, upgradeCallback, connectedCallback, disconnectedCallback);
8462
- const ScopedConstructor = createScopedConstructor(tagName, UserConstructor);
8463
- return new ScopedConstructor(UserConstructor);
8464
- }
8465
-
8466
7923
  /*
8467
7924
  * Copyright (c) 2018, salesforce.com, inc.
8468
7925
  * All rights reserved.
@@ -8470,29 +7927,22 @@
8470
7927
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
8471
7928
  */
8472
7929
  /**
8473
- * We have three modes for creating custom elements:
7930
+ * We have two modes for creating custom elements:
8474
7931
  *
8475
7932
  * 1. Compat (legacy) browser support (e.g. IE11). Totally custom, doesn't rely on native browser APIs.
8476
7933
  * 2. "Upgradable constructor" custom element. This allows us to have two LWC components with the same tag name,
8477
7934
  * via a trick: every custom element constructor we define in the registry is basically the same. It's essentially
8478
7935
  * a dummy `class extends HTMLElement` that accepts an `upgradeCallback` in its constructor ("upgradable
8479
7936
  * constructor"), which allows us to have completely customized functionality for different components.
8480
- * 3. "Scoped" (or "pivot") custom elements. This relies on a sophisticated system that emulates the "scoped custom
8481
- * elements registry" proposal, with support for avoiding conflicts in tag names both between LWC components and
8482
- * between LWC components and third-party elements. This uses a similar trick to #2, but is much more complex
8483
- * because it must patch the global `customElements` and `HTMLElement` objects.
8484
7937
  */
8485
7938
  let createCustomElement;
8486
7939
  if (hasCustomElements) {
8487
- if (lwcRuntimeFlags.ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY) {
8488
- createCustomElement = createCustomElementScoped;
8489
- } else {
8490
7940
  // use the global registry, with an upgradable constructor for the defined custom element
8491
7941
  createCustomElement = createCustomElementUsingUpgradableConstructor;
8492
- }
8493
- } else {
8494
- // no registry available here
8495
- createCustomElement = createCustomElementCompat;
7942
+ }
7943
+ else {
7944
+ // no registry available here
7945
+ createCustomElement = createCustomElementCompat;
8496
7946
  }
8497
7947
 
8498
7948
  /*
@@ -8555,7 +8005,7 @@
8555
8005
  function isNull(obj) {
8556
8006
  return obj === null;
8557
8007
  }
8558
- /** version: 2.36.0 */
8008
+ /** version: 2.37.0 */
8559
8009
 
8560
8010
  /*
8561
8011
  * Copyright (c) 2018, salesforce.com, inc.
@@ -9116,7 +8566,7 @@
9116
8566
  });
9117
8567
  freeze(LightningElement);
9118
8568
  seal(LightningElement.prototype);
9119
- /* version: 2.36.0 */
8569
+ /* version: 2.37.0 */
9120
8570
 
9121
8571
  exports.LightningElement = LightningElement;
9122
8572
  exports.__unstable__ProfilerControl = profilerControl;