@lwc/engine-core 3.1.2 → 4.0.0-alpha.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,12 +1,12 @@
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, VStaticElementData } from './vnodes';
3
+ import { Key, VComment, VCustomElement, VElement, VElementData, VFragment, VNode, VNodes, VScopedSlotFragment, VStatic, VStaticElementData, VText } from './vnodes';
4
4
  declare function ssf(slotName: unknown, factory: (value: any, key: any) => VFragment): VScopedSlotFragment;
5
5
  declare function st(fragment: Element, key: Key, data?: VStaticElementData): VStatic;
6
6
  declare function fr(key: Key, children: VNodes, stable: 0 | 1): VFragment;
7
7
  declare function h(sel: string, data: VElementData, children?: VNodes): VElement;
8
8
  declare function ti(value: any): number;
9
- declare function s(slotName: string, data: VElementData, children: VNodes, slotset: SlotSet | undefined): VElement | VNodes;
9
+ declare function s(slotName: string, data: VElementData, children: VNodes, slotset: SlotSet | undefined): VElement | VNodes | VFragment;
10
10
  declare function c(sel: string, Ctor: LightningElementConstructor, data: VElementData, children?: VNodes): VCustomElement;
11
11
  declare function i(iterable: Iterable<any>, factory: (value: any, index: number, first: boolean, last: boolean) => VNodes | VNode): VNodes;
12
12
  /**
@@ -5,7 +5,6 @@ type N = HostNode;
5
5
  type E = HostElement;
6
6
  export type LifecycleCallback = (elm: E) => void;
7
7
  export interface RendererAPI {
8
- isNativeShadowDefined: boolean;
9
8
  isSyntheticShadowDefined: boolean;
10
9
  insert: (node: N, parent: E, anchor: N | null) => void;
11
10
  remove: (node: N, parent: E) => void;
@@ -42,7 +41,7 @@ export interface RendererAPI {
42
41
  isConnected: (node: N) => boolean;
43
42
  insertStylesheet: (content: string, target?: ShadowRoot) => void;
44
43
  assertInstanceOfHTMLElement: (elm: any, msg: string) => void;
45
- createCustomElement: (tagName: string, upgradeCallback: LifecycleCallback, connectedCallback?: LifecycleCallback, disconnectedCallback?: LifecycleCallback) => E;
44
+ createCustomElement: (tagName: string, upgradeCallback: LifecycleCallback, connectedCallback: LifecycleCallback, disconnectedCallback: LifecycleCallback) => E;
46
45
  ownerDocument(elm: E): Document;
47
46
  registerContextConsumer: (element: E, adapterContextToken: string, subscriptionPayload: WireContextSubscriptionPayload) => void;
48
47
  }
@@ -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';
@@ -134,6 +135,10 @@ export interface VM<N = HostNode, E = HostElement> {
134
135
  /**
135
136
  * Any stylesheets associated with the component */
136
137
  stylesheets: TemplateStylesheetFactories | null;
138
+ /**
139
+ * API version associated with this VM
140
+ */
141
+ apiVersion: APIVersion;
137
142
  }
138
143
  type VMAssociable = HostNode | LightningElement;
139
144
  export declare function rerenderVM(vm: VM): void;
package/dist/index.cjs.js CHANGED
@@ -1734,15 +1734,10 @@ for (const propName in HTMLElementOriginalDescriptors) {
1734
1734
  lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
1735
1735
  }
1736
1736
  shared.defineProperties(LightningElement.prototype, lightningBasedDescriptors);
1737
- function applyAriaReflectionToLightningElement() {
1738
- // If ARIA reflection is not applied globally to Element.prototype, or if we are running server-side,
1739
- // apply it to LightningElement.prototype.
1740
- // This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
1741
- ariaReflection.applyAriaReflection(LightningElement.prototype);
1742
- }
1743
- if (!process.env.IS_BROWSER || lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
1744
- applyAriaReflectionToLightningElement();
1745
- }
1737
+ // Apply ARIA reflection to LightningElement.prototype, on both the browser and server.
1738
+ // This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
1739
+ // Note this works regardless of whether the global ARIA reflection polyfill is applied or not.
1740
+ ariaReflection.applyAriaReflection(LightningElement.prototype);
1746
1741
  shared.defineProperty(LightningElement, 'CustomElementConstructor', {
1747
1742
  get() {
1748
1743
  // If required, a runtime-specific implementation must be defined.
@@ -2605,15 +2600,15 @@ if (process.env.IS_BROWSER) {
2605
2600
  // This ARIA reflection only really makes sense in the browser. On the server, there is no `renderedCallback()`,
2606
2601
  // so you cannot do e.g. `this.template.querySelector('x-child').ariaBusy = 'true'`. So we don't need to expose
2607
2602
  // ARIA props outside the LightningElement
2608
- if (lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
2609
- // If ARIA reflection is not applied globally to Element.prototype, apply it to HTMLBridgeElement.prototype.
2610
- // This allows `elm.aria*` property accessors to work from outside a component, and to reflect `aria-*` attrs.
2611
- // This is especially important because the template compiler compiles aria-* attrs on components to aria* props
2612
- //
2613
- // Also note that we apply this to BaseBridgeElement.prototype to avoid excessively redefining property
2614
- // accessors inside the HTMLBridgeElementFactory.
2615
- ariaReflection.applyAriaReflection(BaseBridgeElement.prototype);
2616
- }
2603
+ //
2604
+ // Apply ARIA reflection to HTMLBridgeElement.prototype. This allows `elm.aria*` property accessors to work from
2605
+ // outside a component, and to reflect `aria-*` attrs. This is especially important because the template compiler
2606
+ // compiles aria-* attrs on components to aria* props.
2607
+ // Note this works regardless of whether the global ARIA reflection polyfill is applied or not.
2608
+ //
2609
+ // Also note that we apply this to BaseBridgeElement.prototype to avoid excessively redefining property
2610
+ // accessors inside the HTMLBridgeElementFactory.
2611
+ ariaReflection.applyAriaReflection(BaseBridgeElement.prototype);
2617
2612
  }
2618
2613
  shared.freeze(BaseBridgeElement);
2619
2614
  shared.seal(BaseBridgeElement.prototype);
@@ -3729,16 +3724,16 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
3729
3724
  // the custom element from the registry is expecting an upgrade callback
3730
3725
  vm = createViewModelHook(elm, vnode, renderer);
3731
3726
  };
3732
- let connectedCallback;
3733
- let disconnectedCallback;
3734
- if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3735
- connectedCallback = (elm) => {
3727
+ const connectedCallback = (elm) => {
3728
+ if (shouldUseNativeCustomElementLifecycle(vm)) {
3736
3729
  connectRootElement(elm);
3737
- };
3738
- disconnectedCallback = (elm) => {
3730
+ }
3731
+ };
3732
+ const disconnectedCallback = (elm) => {
3733
+ if (shouldUseNativeCustomElementLifecycle(vm)) {
3739
3734
  disconnectRootElement(elm);
3740
- };
3741
- }
3735
+ }
3736
+ };
3742
3737
  // Should never get a tag with upper case letter at this point; the compiler
3743
3738
  // should produce only tags with lowercase letters. However, the Java
3744
3739
  // compiler may generate tagnames with uppercase letters so - for backwards
@@ -3756,7 +3751,7 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
3756
3751
  insertNode(elm, parent, anchor, renderer);
3757
3752
  if (vm) {
3758
3753
  if (process.env.IS_BROWSER) {
3759
- if (!lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3754
+ if (!shouldUseNativeCustomElementLifecycle(vm)) {
3760
3755
  if (process.env.NODE_ENV !== 'production') {
3761
3756
  // With synthetic lifecycle callbacks, it's possible for elements to be removed without the engine
3762
3757
  // noticing it (e.g. `appendChild` the same host element twice). This test ensures we don't regress.
@@ -4321,6 +4316,14 @@ function updateStaticChildren(c1, c2, parent, renderer) {
4321
4316
  }
4322
4317
  }
4323
4318
  }
4319
+ function shouldUseNativeCustomElementLifecycle(vm) {
4320
+ if (lwcRuntimeFlags.DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
4321
+ // temporary "kill switch"
4322
+ return false;
4323
+ }
4324
+ const apiVersion = getComponentAPIVersion(vm.component.constructor);
4325
+ return shared.isAPIFeatureEnabled(5 /* APIFeature.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE */, apiVersion);
4326
+ }
4324
4327
 
4325
4328
  /*
4326
4329
  * Copyright (c) 2018, salesforce.com, inc.
@@ -4486,10 +4489,16 @@ function s(slotName, data, children, slotset) {
4486
4489
  children = newChildren;
4487
4490
  }
4488
4491
  const vmBeingRendered = getVMBeingRendered();
4489
- const { renderMode, shadowMode } = vmBeingRendered;
4492
+ const { renderMode, shadowMode, apiVersion } = vmBeingRendered;
4490
4493
  if (renderMode === 0 /* RenderMode.Light */) {
4491
- sc(children);
4492
- return children;
4494
+ // light DOM slots - backwards-compatible behavior uses flattening, new behavior uses fragments
4495
+ if (shared.isAPIFeatureEnabled(2 /* APIFeature.USE_FRAGMENTS_FOR_LIGHT_DOM_SLOTS */, apiVersion)) {
4496
+ return fr(data.key, children, 0);
4497
+ }
4498
+ else {
4499
+ sc(children);
4500
+ return children;
4501
+ }
4493
4502
  }
4494
4503
  if (shadowMode === 1 /* ShadowMode.Synthetic */) {
4495
4504
  // TODO [#1276]: compiler should give us some sort of indicator when a vnodes collection is dynamic
@@ -5265,9 +5274,8 @@ function getComponentAPIVersion(Ctor) {
5265
5274
  const metadata = registeredComponentMap.get(Ctor);
5266
5275
  const apiVersion = metadata === null || metadata === void 0 ? void 0 : metadata.apiVersion;
5267
5276
  if (shared.isUndefined(apiVersion)) {
5268
- // This should only occur in our Karma tests; in practice every component
5269
- // is registered, and so this code path should not get hit. But to be safe,
5270
- // return the lowest possible version.
5277
+ // This should only occur in two places: 1) our Karma tests, with unregistered components, and
5278
+ // 2) the ACT compiler. To be safe, return the lowest possible API version.
5271
5279
  return shared.LOWEST_API_VERSION;
5272
5280
  }
5273
5281
  return apiVersion;
@@ -5354,7 +5362,7 @@ function invokeServiceHook(vm, cbs) {
5354
5362
  }
5355
5363
 
5356
5364
  /*
5357
- * Copyright (c) 2018, salesforce.com, inc.
5365
+ * Copyright (c) 2023, Salesforce.com, inc.
5358
5366
  * All rights reserved.
5359
5367
  * SPDX-License-Identifier: MIT
5360
5368
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
@@ -5425,6 +5433,7 @@ function getNearestShadowAncestor(vm) {
5425
5433
  function createVM(elm, ctor, renderer, options) {
5426
5434
  const { mode, owner, tagName, hydrated } = options;
5427
5435
  const def = getComponentInternalDef(ctor);
5436
+ const apiVersion = getComponentAPIVersion(ctor);
5428
5437
  const vm = {
5429
5438
  elm,
5430
5439
  def,
@@ -5467,6 +5476,7 @@ function createVM(elm, ctor, renderer, options) {
5467
5476
  setHook,
5468
5477
  getHook,
5469
5478
  renderer,
5479
+ apiVersion,
5470
5480
  };
5471
5481
  if (process.env.NODE_ENV !== 'production') {
5472
5482
  vm.debugInfo = shared.create(null);
@@ -5545,7 +5555,7 @@ function warnOnStylesheetsMutation(ctor) {
5545
5555
  }
5546
5556
  function computeShadowMode(vm, renderer) {
5547
5557
  const { def } = vm;
5548
- const { isSyntheticShadowDefined, isNativeShadowDefined } = renderer;
5558
+ const { isSyntheticShadowDefined } = renderer;
5549
5559
  let shadowMode;
5550
5560
  if (isSyntheticShadowDefined) {
5551
5561
  if (def.renderMode === 0 /* RenderMode.Light */) {
@@ -5553,34 +5563,25 @@ function computeShadowMode(vm, renderer) {
5553
5563
  // everything defaults to native when the synthetic shadow polyfill is unavailable.
5554
5564
  shadowMode = 0 /* ShadowMode.Native */;
5555
5565
  }
5556
- else if (isNativeShadowDefined) {
5557
- // Not combined with above condition because @lwc/features only supports identifiers in
5558
- // the if-condition.
5559
- if (lwcRuntimeFlags.ENABLE_MIXED_SHADOW_MODE) {
5560
- if (def.shadowSupportMode === "any" /* ShadowSupportMode.Any */) {
5566
+ else if (lwcRuntimeFlags.ENABLE_MIXED_SHADOW_MODE) {
5567
+ if (def.shadowSupportMode === "any" /* ShadowSupportMode.Any */) {
5568
+ shadowMode = 0 /* ShadowMode.Native */;
5569
+ }
5570
+ else {
5571
+ const shadowAncestor = getNearestShadowAncestor(vm);
5572
+ if (!shared.isNull(shadowAncestor) && shadowAncestor.shadowMode === 0 /* ShadowMode.Native */) {
5573
+ // Transitive support for native Shadow DOM. A component in native mode
5574
+ // transitively opts all of its descendants into native.
5561
5575
  shadowMode = 0 /* ShadowMode.Native */;
5562
5576
  }
5563
5577
  else {
5564
- const shadowAncestor = getNearestShadowAncestor(vm);
5565
- if (!shared.isNull(shadowAncestor) &&
5566
- shadowAncestor.shadowMode === 0 /* ShadowMode.Native */) {
5567
- // Transitive support for native Shadow DOM. A component in native mode
5568
- // transitively opts all of its descendants into native.
5569
- shadowMode = 0 /* ShadowMode.Native */;
5570
- }
5571
- else {
5572
- // Synthetic if neither this component nor any of its ancestors are configured
5573
- // to be native.
5574
- shadowMode = 1 /* ShadowMode.Synthetic */;
5575
- }
5578
+ // Synthetic if neither this component nor any of its ancestors are configured
5579
+ // to be native.
5580
+ shadowMode = 1 /* ShadowMode.Synthetic */;
5576
5581
  }
5577
5582
  }
5578
- else {
5579
- shadowMode = 1 /* ShadowMode.Synthetic */;
5580
- }
5581
5583
  }
5582
5584
  else {
5583
- // Synthetic if there is no native Shadow DOM support.
5584
5585
  shadowMode = 1 /* ShadowMode.Synthetic */;
5585
5586
  }
5586
5587
  }
@@ -6060,11 +6061,6 @@ const NON_STANDARD_ARIA_PROPS = [
6060
6061
  'ariaLabelledBy',
6061
6062
  'ariaOwns',
6062
6063
  ];
6063
- function isLightningElement(elm) {
6064
- // The former case is for `this.prop` (inside component) and the latter is for `element.prop` (outside component).
6065
- // In both cases, we apply the non-standard prop even when the global polyfill is disabled, so this is kosher.
6066
- return elm instanceof LightningElement || elm instanceof BaseBridgeElement;
6067
- }
6068
6064
  function findVM(elm) {
6069
6065
  // If it's a shadow DOM component, then it has a host
6070
6066
  const { host } = elm.getRootNode();
@@ -6075,7 +6071,8 @@ function findVM(elm) {
6075
6071
  // Else it might be a light DOM component. Walk up the tree trying to find the owner
6076
6072
  let parentElement = elm;
6077
6073
  while (!shared.isNull((parentElement = parentElement.parentElement))) {
6078
- if (isLightningElement(parentElement)) {
6074
+ if (parentElement instanceof BaseBridgeElement) {
6075
+ // parentElement is an LWC component
6079
6076
  const vm = getAssociatedVMIfPresent(parentElement);
6080
6077
  if (!shared.isUndefined(vm)) {
6081
6078
  return vm;
@@ -6085,28 +6082,26 @@ function findVM(elm) {
6085
6082
  // If we return undefined, it's because the element was rendered wholly outside a LightningElement
6086
6083
  }
6087
6084
  function checkAndReportViolation(elm, prop, isSetter, setValue) {
6088
- if (!isLightningElement(elm)) {
6089
- const vm = findVM(elm);
6090
- if (process.env.NODE_ENV !== 'production') {
6091
- logWarnOnce(`Element <${elm.tagName.toLowerCase()}> ` +
6092
- (shared.isUndefined(vm) ? '' : `owned by <${vm.elm.tagName.toLowerCase()}> `) +
6093
- `uses non-standard property "${prop}". This will be removed in a future version of LWC. ` +
6094
- `See https://sfdc.co/deprecated-aria`);
6095
- }
6096
- let setValueType;
6097
- if (isSetter) {
6098
- // `typeof null` is "object" which is not very useful for detecting null.
6099
- // We mostly want to know null vs undefined vs other types here, due to
6100
- // https://github.com/salesforce/lwc/issues/3284
6101
- setValueType = shared.isNull(setValue) ? 'null' : typeof setValue;
6102
- }
6103
- report("NonStandardAriaReflection" /* ReportingEventId.NonStandardAriaReflection */, {
6104
- tagName: vm === null || vm === void 0 ? void 0 : vm.tagName,
6105
- propertyName: prop,
6106
- isSetter,
6107
- setValueType,
6108
- });
6109
- }
6085
+ const vm = findVM(elm);
6086
+ if (process.env.NODE_ENV !== 'production') {
6087
+ logWarnOnce(`Element <${elm.tagName.toLowerCase()}> ` +
6088
+ (shared.isUndefined(vm) ? '' : `owned by <${vm.elm.tagName.toLowerCase()}> `) +
6089
+ `uses non-standard property "${prop}". This will be removed in a future version of LWC. ` +
6090
+ `See https://sfdc.co/deprecated-aria`);
6091
+ }
6092
+ let setValueType;
6093
+ if (isSetter) {
6094
+ // `typeof null` is "object" which is not very useful for detecting null.
6095
+ // We mostly want to know null vs undefined vs other types here, due to
6096
+ // https://github.com/salesforce/lwc/issues/3284
6097
+ setValueType = shared.isNull(setValue) ? 'null' : typeof setValue;
6098
+ }
6099
+ report("NonStandardAriaReflection" /* ReportingEventId.NonStandardAriaReflection */, {
6100
+ tagName: vm === null || vm === void 0 ? void 0 : vm.tagName,
6101
+ propertyName: prop,
6102
+ isSetter,
6103
+ setValueType,
6104
+ });
6110
6105
  }
6111
6106
  function enableDetection() {
6112
6107
  const { prototype } = Element;
@@ -6141,7 +6136,7 @@ function enableDetection() {
6141
6136
  }
6142
6137
  // No point in running this code if we're not in a browser, or if the global polyfill is not loaded
6143
6138
  if (process.env.IS_BROWSER) {
6144
- if (!lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
6139
+ if (lwcRuntimeFlags.ENABLE_ARIA_REFLECTION_GLOBAL_POLYFILL) {
6145
6140
  // Always run detection in dev mode, so we can at least print to the console
6146
6141
  if (process.env.NODE_ENV !== 'production') {
6147
6142
  enableDetection();
@@ -6930,5 +6925,5 @@ exports.swapTemplate = swapTemplate;
6930
6925
  exports.track = track;
6931
6926
  exports.unwrap = unwrap;
6932
6927
  exports.wire = wire;
6933
- /** version: 3.1.2 */
6928
+ /** version: 4.0.0-alpha.0 */
6934
6929
  //# sourceMappingURL=index.cjs.js.map