@lwc/engine-core 5.0.2 → 5.0.4

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.
@@ -1,10 +1,12 @@
1
+ import { ShadowMode } from './vm';
1
2
  export declare const enum ReportingEventId {
2
3
  CrossRootAriaInSyntheticShadow = "CrossRootAriaInSyntheticShadow",
3
4
  CompilerRuntimeVersionMismatch = "CompilerRuntimeVersionMismatch",
4
5
  NonStandardAriaReflection = "NonStandardAriaReflection",
5
6
  TemplateMutation = "TemplateMutation",
6
7
  StylesheetMutation = "StylesheetMutation",
7
- ConnectedCallbackWhileDisconnected = "ConnectedCallbackWhileDisconnected"
8
+ ConnectedCallbackWhileDisconnected = "ConnectedCallbackWhileDisconnected",
9
+ ShadowModeUsage = "ShadowModeUsage"
8
10
  }
9
11
  export interface BasePayload {
10
12
  tagName?: string;
@@ -29,6 +31,9 @@ export interface StylesheetMutationPayload extends BasePayload {
29
31
  }
30
32
  export interface ConnectedCallbackWhileDisconnectedPayload extends BasePayload {
31
33
  }
34
+ export interface ShadowModeUsagePayload extends BasePayload {
35
+ mode: ShadowMode;
36
+ }
32
37
  export type ReportingPayloadMapping = {
33
38
  [ReportingEventId.CrossRootAriaInSyntheticShadow]: CrossRootAriaInSyntheticShadowPayload;
34
39
  [ReportingEventId.CompilerRuntimeVersionMismatch]: CompilerRuntimeVersionMismatchPayload;
@@ -36,6 +41,7 @@ export type ReportingPayloadMapping = {
36
41
  [ReportingEventId.TemplateMutation]: TemplateMutationPayload;
37
42
  [ReportingEventId.StylesheetMutation]: StylesheetMutationPayload;
38
43
  [ReportingEventId.ConnectedCallbackWhileDisconnected]: ConnectedCallbackWhileDisconnectedPayload;
44
+ [ReportingEventId.ShadowModeUsage]: ShadowModeUsagePayload;
39
45
  };
40
46
  export type ReportingDispatcher<T extends ReportingEventId = ReportingEventId> = (reportingEventId: T, payload: ReportingPayloadMapping[T]) => void;
41
47
  /** Callbacks to invoke when reporting is enabled **/
package/dist/index.cjs.js CHANGED
@@ -425,54 +425,53 @@ const instrumentDef = (_a = shared.globalThis.__lwc_instrument_cmp_def) !== null
425
425
  const instrumentInstance = (_b = shared.globalThis.__lwc_instrument_cmp_instance) !== null && _b !== void 0 ? _b : shared.noop;
426
426
 
427
427
  /*
428
- * Copyright (c) 2023, salesforce.com, inc.
428
+ * Copyright (c) 2018, salesforce.com, inc.
429
429
  * All rights reserved.
430
430
  * SPDX-License-Identifier: MIT
431
431
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
432
432
  */
433
- // Apply ARIA string reflection behavior to a prototype.
434
- // This is deliberately kept separate from @lwc/aria-reflection. @lwc/aria-reflection is a global polyfill that is
435
- // needed for backwards compatibility in LEX, whereas `applyAriaReflection` is designed to only apply to our own
436
- // LightningElement/BaseBridgeElement prototypes.
437
- function applyAriaReflection(prototype) {
438
- for (const propName of shared.keys(shared.AriaPropNameToAttrNameMap)) {
439
- const attrName = shared.AriaPropNameToAttrNameMap[propName];
440
- if (shared.isUndefined(shared.getOwnPropertyDescriptor(prototype, propName))) {
441
- // Note that we need to call this.{get,set,has,remove}Attribute rather than dereferencing
442
- // from Element.prototype, because these methods are overridden in LightningElement.
443
- shared.defineProperty(prototype, propName, {
444
- get() {
445
- return this.getAttribute(attrName);
446
- },
447
- set(newValue) {
448
- // TODO [#3284]: there is disagreement between browsers and the spec on how to treat undefined
449
- // Our historical behavior is to only treat null as removing the attribute
450
- // See also https://github.com/w3c/aria/issues/1858
451
- if (shared.isNull(newValue)) {
452
- this.removeAttribute(attrName);
453
- }
454
- else {
455
- this.setAttribute(attrName, newValue);
456
- }
457
- },
458
- // configurable and enumerable to allow it to be overridden – this mimics Safari's/Chrome's behavior
459
- configurable: true,
460
- enumerable: true,
461
- });
462
- }
463
- }
464
- }
433
+ // This is a temporary workaround to get the @lwc/engine-server to evaluate in node without having
434
+ // to inject at runtime.
435
+ const HTMLElementConstructor = typeof HTMLElement !== 'undefined' ? HTMLElement : function () { };
436
+ const HTMLElementPrototype = HTMLElementConstructor.prototype;
465
437
 
466
438
  /*
467
- * Copyright (c) 2018, salesforce.com, inc.
439
+ * Copyright (c) 2023, salesforce.com, inc.
468
440
  * All rights reserved.
469
441
  * SPDX-License-Identifier: MIT
470
442
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
471
443
  */
472
- // This is a temporary workaround to get the @lwc/engine-server to evaluate in node without having
473
- // to inject at runtime.
474
- const HTMLElementConstructor = typeof HTMLElement !== 'undefined' ? HTMLElement : function () { };
475
- const HTMLElementPrototype = HTMLElementConstructor.prototype;
444
+ // Apply ARIA string reflection behavior to a prototype.
445
+ // This is deliberately kept separate from @lwc/aria-reflection. @lwc/aria-reflection is a global polyfill that is
446
+ // needed for backwards compatibility in LEX, whereas this is designed to only apply to our own
447
+ // LightningElement/BaseBridgeElement prototypes.
448
+ // Note we only need to handle ARIA reflections that aren't already in Element.prototype
449
+ const ariaReflectionPolyfillDescriptors = shared.create(null);
450
+ for (const [propName, attrName] of shared.entries(shared.AriaPropNameToAttrNameMap)) {
451
+ if (shared.isUndefined(shared.getPropertyDescriptor(HTMLElementPrototype, propName))) {
452
+ // Note that we need to call this.{get,set,has,remove}Attribute rather than dereferencing
453
+ // from Element.prototype, because these methods are overridden in LightningElement.
454
+ ariaReflectionPolyfillDescriptors[propName] = {
455
+ get() {
456
+ return this.getAttribute(attrName);
457
+ },
458
+ set(newValue) {
459
+ // TODO [#3284]: there is disagreement between browsers and the spec on how to treat undefined
460
+ // Our historical behavior is to only treat null as removing the attribute
461
+ // See also https://github.com/w3c/aria/issues/1858
462
+ if (shared.isNull(newValue)) {
463
+ this.removeAttribute(attrName);
464
+ }
465
+ else {
466
+ this.setAttribute(attrName, newValue);
467
+ }
468
+ },
469
+ // configurable and enumerable to allow it to be overridden – this mimics Safari's/Chrome's behavior
470
+ configurable: true,
471
+ enumerable: true,
472
+ };
473
+ }
474
+ }
476
475
 
477
476
  /*
478
477
  * Copyright (c) 2018, salesforce.com, inc.
@@ -1846,11 +1845,22 @@ const lightningBasedDescriptors = shared.create(null);
1846
1845
  for (const propName in HTMLElementOriginalDescriptors) {
1847
1846
  lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
1848
1847
  }
1849
- shared.defineProperties(LightningElement.prototype, lightningBasedDescriptors);
1850
1848
  // Apply ARIA reflection to LightningElement.prototype, on both the browser and server.
1851
1849
  // This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
1852
1850
  // Note this works regardless of whether the global ARIA reflection polyfill is applied or not.
1853
- applyAriaReflection(LightningElement.prototype);
1851
+ if (process.env.IS_BROWSER) {
1852
+ // In the browser, we use createBridgeToElementDescriptor, so we can get the normal reactivity lifecycle for
1853
+ // aria* properties
1854
+ for (const [propName, descriptor] of shared.entries(ariaReflectionPolyfillDescriptors)) {
1855
+ lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, descriptor);
1856
+ }
1857
+ }
1858
+ else {
1859
+ // On the server, we cannot use createBridgeToElementDescriptor because getAttribute/setAttribute are
1860
+ // not supported on HTMLElement. So apply the polyfill directly on top of LightningElement
1861
+ shared.defineProperties(LightningElement.prototype, ariaReflectionPolyfillDescriptors);
1862
+ }
1863
+ shared.defineProperties(LightningElement.prototype, lightningBasedDescriptors);
1854
1864
  shared.defineProperty(LightningElement, 'CustomElementConstructor', {
1855
1865
  get() {
1856
1866
  // If required, a runtime-specific implementation must be defined.
@@ -2700,7 +2710,8 @@ function HTMLBridgeElementFactory(SuperClass, publicProperties, methods, observe
2700
2710
  // and can break tooling that expects it to be iterable or defined, e.g. Jest:
2701
2711
  // https://github.com/jestjs/jest/blob/b4c9587/packages/pretty-format/src/plugins/DOMElement.ts#L95
2702
2712
  // It also doesn't make sense to override e.g. "constructor".
2703
- .filter((propName) => !(propName in HTMLElementPrototype)));
2713
+ .filter((propName) => !(propName in HTMLElementPrototype) &&
2714
+ !(propName in ariaReflectionPolyfillDescriptors)));
2704
2715
  for (const propName of nonPublicPropertiesToWarnOn) {
2705
2716
  if (shared.ArrayIndexOf.call(publicProperties, propName) === -1) {
2706
2717
  descriptors[propName] = createAccessorThatWarns(propName);
@@ -2770,21 +2781,22 @@ function HTMLBridgeElementFactory(SuperClass, publicProperties, methods, observe
2770
2781
  shared.defineProperties(HTMLBridgeElement.prototype, descriptors);
2771
2782
  return HTMLBridgeElement;
2772
2783
  }
2773
- const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, shared.getOwnPropertyNames(HTMLElementOriginalDescriptors), [], [], null, false);
2774
- if (process.env.IS_BROWSER) {
2775
- // This ARIA reflection only really makes sense in the browser. On the server, there is no `renderedCallback()`,
2776
- // so you cannot do e.g. `this.template.querySelector('x-child').ariaBusy = 'true'`. So we don't need to expose
2777
- // ARIA props outside the LightningElement
2778
- //
2779
- // Apply ARIA reflection to HTMLBridgeElement.prototype. This allows `elm.aria*` property accessors to work from
2780
- // outside a component, and to reflect `aria-*` attrs. This is especially important because the template compiler
2781
- // compiles aria-* attrs on components to aria* props.
2782
- // Note this works regardless of whether the global ARIA reflection polyfill is applied or not.
2783
- //
2784
- // Also note that we apply this to BaseBridgeElement.prototype to avoid excessively redefining property
2785
- // accessors inside the HTMLBridgeElementFactory.
2786
- applyAriaReflection(BaseBridgeElement.prototype);
2787
- }
2784
+ // We do some special handling of non-standard ARIA props like ariaLabelledBy as well as props without (as of this
2785
+ // writing) broad cross-browser support like ariaBrailleLabel. This is so the reflection works correctly and preserves
2786
+ // backwards compatibility with the previous global polyfill approach.
2787
+ //
2788
+ // The goal here is to expose `elm.aria*` property accessors to work from outside a component, and to reflect `aria-*`
2789
+ // attrs. This is especially important because the template compiler compiles aria-* attrs on components to aria* props.
2790
+ // Note this works regardless of whether the global ARIA reflection polyfill is applied or not.
2791
+ //
2792
+ // Also note this ARIA reflection only really makes sense in the browser. On the server, there is no
2793
+ // `renderedCallback()`, so you cannot do e.g. `this.template.querySelector('x-child').ariaBusy = 'true'`. So we don't
2794
+ // need to expose ARIA props outside the LightningElement
2795
+ const basePublicProperties = [
2796
+ ...shared.getOwnPropertyNames(HTMLElementOriginalDescriptors),
2797
+ ...(process.env.IS_BROWSER ? shared.getOwnPropertyNames(ariaReflectionPolyfillDescriptors) : []),
2798
+ ];
2799
+ const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, basePublicProperties, [], [], null, false);
2788
2800
  shared.freeze(BaseBridgeElement);
2789
2801
  shared.seal(BaseBridgeElement.prototype);
2790
2802
 
@@ -5810,6 +5822,13 @@ function createVM(elm, ctor, renderer, options) {
5810
5822
  vm.stylesheets = computeStylesheets(vm, def.ctor);
5811
5823
  vm.shadowMode = computeShadowMode(def, vm.owner, renderer);
5812
5824
  vm.tro = getTemplateReactiveObserver(vm);
5825
+ // We don't need to report the shadow mode if we're rendering in light DOM
5826
+ if (isReportingEnabled() && vm.renderMode === 1 /* RenderMode.Shadow */) {
5827
+ report("ShadowModeUsage" /* ReportingEventId.ShadowModeUsage */, {
5828
+ tagName: vm.tagName,
5829
+ mode: vm.shadowMode,
5830
+ });
5831
+ }
5813
5832
  if (process.env.NODE_ENV !== 'production') {
5814
5833
  vm.toString = () => {
5815
5834
  return `[object:vm ${def.name} (${vm.idx})]`;
@@ -7352,5 +7371,5 @@ exports.swapTemplate = swapTemplate;
7352
7371
  exports.track = track;
7353
7372
  exports.unwrap = unwrap;
7354
7373
  exports.wire = wire;
7355
- /** version: 5.0.2 */
7374
+ /** version: 5.0.4 */
7356
7375
  //# sourceMappingURL=index.cjs.js.map