@lwc/engine-core 3.8.0 → 4.0.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.
@@ -1,13 +1,13 @@
1
1
  import { SlotSet } from './vm';
2
2
  import { LightningElementConstructor } from './base-lightning-element';
3
- import { VNode, VNodes, VElement, VText, VCustomElement, VComment, VElementData, VStatic, Key, VFragment, VScopedSlotFragment, VStaticPart, VStaticPartData } from './vnodes';
3
+ import { Key, VComment, VCustomElement, VElement, VElementData, VFragment, VNode, VNodes, VScopedSlotFragment, VStatic, VText, VStaticPart, VStaticPartData } from './vnodes';
4
4
  declare function sp(partId: number, data: VStaticPartData): VStaticPart;
5
5
  declare function ssf(slotName: unknown, factory: (value: any, key: any) => VFragment): VScopedSlotFragment;
6
6
  declare function st(fragment: Element, key: Key, parts?: VStaticPart[]): VStatic;
7
7
  declare function fr(key: Key, children: VNodes, stable: 0 | 1): VFragment;
8
8
  declare function h(sel: string, data: VElementData, children?: VNodes): VElement;
9
9
  declare function ti(value: any): number;
10
- declare function s(slotName: string, data: VElementData, children: VNodes, slotset: SlotSet | undefined): VElement | VNodes;
10
+ declare function s(slotName: string, data: VElementData, children: VNodes, slotset: SlotSet | undefined): VElement | VNodes | VFragment;
11
11
  declare function c(sel: string, Ctor: LightningElementConstructor, data: VElementData, children?: VNodes): VCustomElement;
12
12
  declare function i(iterable: Iterable<any>, factory: (value: any, index: number, first: boolean, last: boolean) => VNodes | VNode): VNodes;
13
13
  /**
@@ -1,3 +1,4 @@
1
+ import { APIVersion } from '@lwc/shared';
1
2
  import { HostNode, HostElement, RendererAPI } from './renderer';
2
3
  import { Template } from './template';
3
4
  import { ComponentDef } from './def';
@@ -141,6 +142,10 @@ export interface VM<N = HostNode, E = HostElement> {
141
142
  /**
142
143
  * Any stylesheets associated with the component */
143
144
  stylesheets: TemplateStylesheetFactories | null;
145
+ /**
146
+ * API version associated with this VM
147
+ */
148
+ apiVersion: APIVersion;
144
149
  }
145
150
  type VMAssociable = HostNode | LightningElement;
146
151
  export declare function rerenderVM(vm: VM): void;
package/dist/index.cjs.js CHANGED
@@ -6,7 +6,6 @@
6
6
  Object.defineProperty(exports, '__esModule', { value: true });
7
7
 
8
8
  var shared = require('@lwc/shared');
9
- var ariaReflection = require('@lwc/aria-reflection');
10
9
  var features = require('@lwc/features');
11
10
 
12
11
  /*
@@ -419,6 +418,45 @@ var _a, _b;
419
418
  const instrumentDef = (_a = shared.globalThis.__lwc_instrument_cmp_def) !== null && _a !== void 0 ? _a : shared.noop;
420
419
  const instrumentInstance = (_b = shared.globalThis.__lwc_instrument_cmp_instance) !== null && _b !== void 0 ? _b : shared.noop;
421
420
 
421
+ /*
422
+ * Copyright (c) 2023, salesforce.com, inc.
423
+ * All rights reserved.
424
+ * SPDX-License-Identifier: MIT
425
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
426
+ */
427
+ // Apply ARIA string reflection behavior to a prototype.
428
+ // This is deliberately kept separate from @lwc/aria-reflection. @lwc/aria-reflection is a global polyfill that is
429
+ // needed for backwards compatibility in LEX, whereas `applyAriaReflection` is designed to only apply to our own
430
+ // LightningElement/BaseBridgeElement prototypes.
431
+ function applyAriaReflection(prototype) {
432
+ for (const propName of shared.keys(shared.AriaPropNameToAttrNameMap)) {
433
+ const attrName = shared.AriaPropNameToAttrNameMap[propName];
434
+ if (shared.isUndefined(shared.getOwnPropertyDescriptor(prototype, propName))) {
435
+ // Note that we need to call this.{get,set,has,remove}Attribute rather than dereferencing
436
+ // from Element.prototype, because these methods are overridden in LightningElement.
437
+ shared.defineProperty(prototype, propName, {
438
+ get() {
439
+ return this.getAttribute(attrName);
440
+ },
441
+ set(newValue) {
442
+ // TODO [#3284]: there is disagreement between browsers and the spec on how to treat undefined
443
+ // Our historical behavior is to only treat null as removing the attribute
444
+ // See also https://github.com/w3c/aria/issues/1858
445
+ if (shared.isNull(newValue)) {
446
+ this.removeAttribute(attrName);
447
+ }
448
+ else {
449
+ this.setAttribute(attrName, newValue);
450
+ }
451
+ },
452
+ // configurable and enumerable to allow it to be overridden – this mimics Safari's/Chrome's behavior
453
+ configurable: true,
454
+ enumerable: true,
455
+ });
456
+ }
457
+ }
458
+ }
459
+
422
460
  /*
423
461
  * Copyright (c) 2018, salesforce.com, inc.
424
462
  * All rights reserved.
@@ -1803,15 +1841,10 @@ for (const propName in HTMLElementOriginalDescriptors) {
1803
1841
  lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
1804
1842
  }
1805
1843
  shared.defineProperties(LightningElement.prototype, lightningBasedDescriptors);
1806
- function applyAriaReflectionToLightningElement() {
1807
- // If ARIA reflection is not applied globally to Element.prototype, or if we are running server-side,
1808
- // apply it to LightningElement.prototype.
1809
- // This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
1810
- ariaReflection.applyAriaReflection(LightningElement.prototype);
1811
- }
1812
- if (!process.env.IS_BROWSER || lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
1813
- applyAriaReflectionToLightningElement();
1814
- }
1844
+ // Apply ARIA reflection to LightningElement.prototype, on both the browser and server.
1845
+ // This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
1846
+ // Note this works regardless of whether the global ARIA reflection polyfill is applied or not.
1847
+ applyAriaReflection(LightningElement.prototype);
1815
1848
  shared.defineProperty(LightningElement, 'CustomElementConstructor', {
1816
1849
  get() {
1817
1850
  // If required, a runtime-specific implementation must be defined.
@@ -2736,15 +2769,15 @@ if (process.env.IS_BROWSER) {
2736
2769
  // This ARIA reflection only really makes sense in the browser. On the server, there is no `renderedCallback()`,
2737
2770
  // so you cannot do e.g. `this.template.querySelector('x-child').ariaBusy = 'true'`. So we don't need to expose
2738
2771
  // ARIA props outside the LightningElement
2739
- if (lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
2740
- // If ARIA reflection is not applied globally to Element.prototype, apply it to HTMLBridgeElement.prototype.
2741
- // This allows `elm.aria*` property accessors to work from outside a component, and to reflect `aria-*` attrs.
2742
- // This is especially important because the template compiler compiles aria-* attrs on components to aria* props
2743
- //
2744
- // Also note that we apply this to BaseBridgeElement.prototype to avoid excessively redefining property
2745
- // accessors inside the HTMLBridgeElementFactory.
2746
- ariaReflection.applyAriaReflection(BaseBridgeElement.prototype);
2747
- }
2772
+ //
2773
+ // Apply ARIA reflection to HTMLBridgeElement.prototype. This allows `elm.aria*` property accessors to work from
2774
+ // outside a component, and to reflect `aria-*` attrs. This is especially important because the template compiler
2775
+ // compiles aria-* attrs on components to aria* props.
2776
+ // Note this works regardless of whether the global ARIA reflection polyfill is applied or not.
2777
+ //
2778
+ // Also note that we apply this to BaseBridgeElement.prototype to avoid excessively redefining property
2779
+ // accessors inside the HTMLBridgeElementFactory.
2780
+ applyAriaReflection(BaseBridgeElement.prototype);
2748
2781
  }
2749
2782
  shared.freeze(BaseBridgeElement);
2750
2783
  shared.seal(BaseBridgeElement.prototype);
@@ -4796,10 +4829,16 @@ function s(slotName, data, children, slotset) {
4796
4829
  children = newChildren;
4797
4830
  }
4798
4831
  const vmBeingRendered = getVMBeingRendered();
4799
- const { renderMode, shadowMode } = vmBeingRendered;
4832
+ const { renderMode, shadowMode, apiVersion } = vmBeingRendered;
4800
4833
  if (renderMode === 0 /* RenderMode.Light */) {
4801
- sc(children);
4802
- return children;
4834
+ // light DOM slots - backwards-compatible behavior uses flattening, new behavior uses fragments
4835
+ if (shared.isAPIFeatureEnabled(2 /* APIFeature.USE_FRAGMENTS_FOR_LIGHT_DOM_SLOTS */, apiVersion)) {
4836
+ return fr(data.key, children, 0);
4837
+ }
4838
+ else {
4839
+ sc(children);
4840
+ return children;
4841
+ }
4803
4842
  }
4804
4843
  if (shadowMode === 1 /* ShadowMode.Synthetic */) {
4805
4844
  // TODO [#1276]: compiler should give us some sort of indicator when a vnodes collection is dynamic
@@ -5710,6 +5749,7 @@ function getNearestShadowAncestor(owner) {
5710
5749
  function createVM(elm, ctor, renderer, options) {
5711
5750
  const { mode, owner, tagName, hydrated } = options;
5712
5751
  const def = getComponentInternalDef(ctor);
5752
+ const apiVersion = getComponentAPIVersion(ctor);
5713
5753
  const vm = {
5714
5754
  elm,
5715
5755
  def,
@@ -5755,6 +5795,7 @@ function createVM(elm, ctor, renderer, options) {
5755
5795
  setHook,
5756
5796
  getHook,
5757
5797
  renderer,
5798
+ apiVersion,
5758
5799
  };
5759
5800
  if (process.env.NODE_ENV !== 'production') {
5760
5801
  vm.debugInfo = shared.create(null);
@@ -6390,10 +6431,11 @@ const NON_STANDARD_ARIA_PROPS = [
6390
6431
  'ariaLabelledBy',
6391
6432
  'ariaOwns',
6392
6433
  ];
6393
- function isLightningElement(elm) {
6394
- // The former case is for `this.prop` (inside component) and the latter is for `element.prop` (outside component).
6395
- // In both cases, we apply the non-standard prop even when the global polyfill is disabled, so this is kosher.
6396
- return elm instanceof LightningElement || elm instanceof BaseBridgeElement;
6434
+ function isGlobalAriaPolyfillLoaded() {
6435
+ // Sniff for the legacy polyfill being loaded. The reason this works is because ariaActiveDescendant is a
6436
+ // non-standard ARIA property reflection that is only supported in our legacy polyfill. See
6437
+ // @lwc/aria-reflection/README.md for details.
6438
+ return !shared.isUndefined(shared.getOwnPropertyDescriptor(Element.prototype, 'ariaActiveDescendant'));
6397
6439
  }
6398
6440
  function findVM(elm) {
6399
6441
  // If it's a shadow DOM component, then it has a host
@@ -6405,7 +6447,8 @@ function findVM(elm) {
6405
6447
  // Else it might be a light DOM component. Walk up the tree trying to find the owner
6406
6448
  let parentElement = elm;
6407
6449
  while (!shared.isNull((parentElement = parentElement.parentElement))) {
6408
- if (isLightningElement(parentElement)) {
6450
+ if (parentElement instanceof BaseBridgeElement) {
6451
+ // parentElement is an LWC component
6409
6452
  const vm = getAssociatedVMIfPresent(parentElement);
6410
6453
  if (!shared.isUndefined(vm)) {
6411
6454
  return vm;
@@ -6415,28 +6458,26 @@ function findVM(elm) {
6415
6458
  // If we return undefined, it's because the element was rendered wholly outside a LightningElement
6416
6459
  }
6417
6460
  function checkAndReportViolation(elm, prop, isSetter, setValue) {
6418
- if (!isLightningElement(elm)) {
6419
- const vm = findVM(elm);
6420
- if (process.env.NODE_ENV !== 'production') {
6421
- logWarnOnce(`Element <${elm.tagName.toLowerCase()}> ` +
6422
- (shared.isUndefined(vm) ? '' : `owned by <${vm.elm.tagName.toLowerCase()}> `) +
6423
- `uses non-standard property "${prop}". This will be removed in a future version of LWC. ` +
6424
- `See https://sfdc.co/deprecated-aria`);
6425
- }
6426
- let setValueType;
6427
- if (isSetter) {
6428
- // `typeof null` is "object" which is not very useful for detecting null.
6429
- // We mostly want to know null vs undefined vs other types here, due to
6430
- // https://github.com/salesforce/lwc/issues/3284
6431
- setValueType = shared.isNull(setValue) ? 'null' : typeof setValue;
6432
- }
6433
- report("NonStandardAriaReflection" /* ReportingEventId.NonStandardAriaReflection */, {
6434
- tagName: vm === null || vm === void 0 ? void 0 : vm.tagName,
6435
- propertyName: prop,
6436
- isSetter,
6437
- setValueType,
6438
- });
6439
- }
6461
+ const vm = findVM(elm);
6462
+ if (process.env.NODE_ENV !== 'production') {
6463
+ logWarnOnce(`Element <${elm.tagName.toLowerCase()}> ` +
6464
+ (shared.isUndefined(vm) ? '' : `owned by <${vm.elm.tagName.toLowerCase()}> `) +
6465
+ `uses non-standard property "${prop}". This will be removed in a future version of LWC. ` +
6466
+ `See https://sfdc.co/deprecated-aria`);
6467
+ }
6468
+ let setValueType;
6469
+ if (isSetter) {
6470
+ // `typeof null` is "object" which is not very useful for detecting null.
6471
+ // We mostly want to know null vs undefined vs other types here, due to
6472
+ // https://github.com/salesforce/lwc/issues/3284
6473
+ setValueType = shared.isNull(setValue) ? 'null' : typeof setValue;
6474
+ }
6475
+ report("NonStandardAriaReflection" /* ReportingEventId.NonStandardAriaReflection */, {
6476
+ tagName: vm === null || vm === void 0 ? void 0 : vm.tagName,
6477
+ propertyName: prop,
6478
+ isSetter,
6479
+ setValueType,
6480
+ });
6440
6481
  }
6441
6482
  function enableDetection() {
6442
6483
  const { prototype } = Element;
@@ -6455,6 +6496,9 @@ function enableDetection() {
6455
6496
  }
6456
6497
  // @ts-ignore
6457
6498
  const { get, set } = descriptor;
6499
+ // It's important for this defineProperty call to happen _after_ ARIA accessors are applied to the
6500
+ // BaseBridgeElement and LightningElement prototypes. Otherwise, we will log/report for access of non-standard
6501
+ // props on these prototypes, which we actually don't want. We only care about access on generic HTMLElements.
6458
6502
  shared.defineProperty(prototype, prop, {
6459
6503
  get() {
6460
6504
  checkAndReportViolation(this, prop, false, undefined);
@@ -6470,16 +6514,14 @@ function enableDetection() {
6470
6514
  }
6471
6515
  }
6472
6516
  // No point in running this code if we're not in a browser, or if the global polyfill is not loaded
6473
- if (process.env.IS_BROWSER) {
6474
- if (!lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
6475
- // Always run detection in dev mode, so we can at least print to the console
6476
- if (process.env.NODE_ENV !== 'production') {
6477
- enableDetection();
6478
- }
6479
- else {
6480
- // In prod mode, only enable detection if reporting is enabled
6481
- onReportingEnabled(enableDetection);
6482
- }
6517
+ if (process.env.IS_BROWSER && isGlobalAriaPolyfillLoaded()) {
6518
+ // Always run detection in dev mode, so we can at least print to the console
6519
+ if (process.env.NODE_ENV !== 'production') {
6520
+ enableDetection();
6521
+ }
6522
+ else {
6523
+ // In prod mode, only enable detection if reporting is enabled
6524
+ onReportingEnabled(enableDetection);
6483
6525
  }
6484
6526
  }
6485
6527
 
@@ -7271,5 +7313,5 @@ exports.swapTemplate = swapTemplate;
7271
7313
  exports.track = track;
7272
7314
  exports.unwrap = unwrap;
7273
7315
  exports.wire = wire;
7274
- /** version: 3.8.0 */
7316
+ /** version: 4.0.0 */
7275
7317
  //# sourceMappingURL=index.cjs.js.map