@lwc/engine-core 3.1.3 → 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
  /**
@@ -41,7 +41,7 @@ export interface RendererAPI {
41
41
  isConnected: (node: N) => boolean;
42
42
  insertStylesheet: (content: string, target?: ShadowRoot) => void;
43
43
  assertInstanceOfHTMLElement: (elm: any, msg: string) => void;
44
- createCustomElement: (tagName: string, upgradeCallback: LifecycleCallback, connectedCallback?: LifecycleCallback, disconnectedCallback?: LifecycleCallback) => E;
44
+ createCustomElement: (tagName: string, upgradeCallback: LifecycleCallback, connectedCallback: LifecycleCallback, disconnectedCallback: LifecycleCallback) => E;
45
45
  ownerDocument(elm: E): Document;
46
46
  registerContextConsumer: (element: E, adapterContextToken: string, subscriptionPayload: WireContextSubscriptionPayload) => void;
47
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;
@@ -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);
@@ -6051,11 +6061,6 @@ const NON_STANDARD_ARIA_PROPS = [
6051
6061
  'ariaLabelledBy',
6052
6062
  'ariaOwns',
6053
6063
  ];
6054
- function isLightningElement(elm) {
6055
- // The former case is for `this.prop` (inside component) and the latter is for `element.prop` (outside component).
6056
- // In both cases, we apply the non-standard prop even when the global polyfill is disabled, so this is kosher.
6057
- return elm instanceof LightningElement || elm instanceof BaseBridgeElement;
6058
- }
6059
6064
  function findVM(elm) {
6060
6065
  // If it's a shadow DOM component, then it has a host
6061
6066
  const { host } = elm.getRootNode();
@@ -6066,7 +6071,8 @@ function findVM(elm) {
6066
6071
  // Else it might be a light DOM component. Walk up the tree trying to find the owner
6067
6072
  let parentElement = elm;
6068
6073
  while (!shared.isNull((parentElement = parentElement.parentElement))) {
6069
- if (isLightningElement(parentElement)) {
6074
+ if (parentElement instanceof BaseBridgeElement) {
6075
+ // parentElement is an LWC component
6070
6076
  const vm = getAssociatedVMIfPresent(parentElement);
6071
6077
  if (!shared.isUndefined(vm)) {
6072
6078
  return vm;
@@ -6076,28 +6082,26 @@ function findVM(elm) {
6076
6082
  // If we return undefined, it's because the element was rendered wholly outside a LightningElement
6077
6083
  }
6078
6084
  function checkAndReportViolation(elm, prop, isSetter, setValue) {
6079
- if (!isLightningElement(elm)) {
6080
- const vm = findVM(elm);
6081
- if (process.env.NODE_ENV !== 'production') {
6082
- logWarnOnce(`Element <${elm.tagName.toLowerCase()}> ` +
6083
- (shared.isUndefined(vm) ? '' : `owned by <${vm.elm.tagName.toLowerCase()}> `) +
6084
- `uses non-standard property "${prop}". This will be removed in a future version of LWC. ` +
6085
- `See https://sfdc.co/deprecated-aria`);
6086
- }
6087
- let setValueType;
6088
- if (isSetter) {
6089
- // `typeof null` is "object" which is not very useful for detecting null.
6090
- // We mostly want to know null vs undefined vs other types here, due to
6091
- // https://github.com/salesforce/lwc/issues/3284
6092
- setValueType = shared.isNull(setValue) ? 'null' : typeof setValue;
6093
- }
6094
- report("NonStandardAriaReflection" /* ReportingEventId.NonStandardAriaReflection */, {
6095
- tagName: vm === null || vm === void 0 ? void 0 : vm.tagName,
6096
- propertyName: prop,
6097
- isSetter,
6098
- setValueType,
6099
- });
6100
- }
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
+ });
6101
6105
  }
6102
6106
  function enableDetection() {
6103
6107
  const { prototype } = Element;
@@ -6132,7 +6136,7 @@ function enableDetection() {
6132
6136
  }
6133
6137
  // No point in running this code if we're not in a browser, or if the global polyfill is not loaded
6134
6138
  if (process.env.IS_BROWSER) {
6135
- if (!lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
6139
+ if (lwcRuntimeFlags.ENABLE_ARIA_REFLECTION_GLOBAL_POLYFILL) {
6136
6140
  // Always run detection in dev mode, so we can at least print to the console
6137
6141
  if (process.env.NODE_ENV !== 'production') {
6138
6142
  enableDetection();
@@ -6921,5 +6925,5 @@ exports.swapTemplate = swapTemplate;
6921
6925
  exports.track = track;
6922
6926
  exports.unwrap = unwrap;
6923
6927
  exports.wire = wire;
6924
- /** version: 3.1.3 */
6928
+ /** version: 4.0.0-alpha.0 */
6925
6929
  //# sourceMappingURL=index.cjs.js.map