@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.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (C) 2023 salesforce.com, inc.
3
3
  */
4
- import { noop, StringToLowerCase, isNull, ArrayPush as ArrayPush$1, ArrayJoin, isFrozen, isUndefined as isUndefined$1, defineProperty, ArrayIndexOf, ArraySplice, create, seal, isArray as isArray$1, isFunction as isFunction$1, keys, hasOwnProperty as hasOwnProperty$1, globalThis as globalThis$1, forEach, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, assign, isObject, freeze, KEY__SYNTHETIC_MODE, assert, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, isFalse, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, getOwnPropertyNames as getOwnPropertyNames$1, htmlPropertyToAttribute, ArraySlice, ArrayMap, KEY__SCOPED_CSS, kebabCaseToCamelCase, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, isString, StringSlice, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, ArrayPop, isNumber, StringReplace, ArrayUnshift, LOWEST_API_VERSION, KEY__NATIVE_GET_ELEMENT_BY_ID, KEY__NATIVE_QUERY_SELECTOR_ALL, ID_REFERENCING_ATTRIBUTES_SET, KEY__SHADOW_TOKEN, ArrayFilter, StringSplit, arrayEvery, ArrayIncludes, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse, ArrayShift } from '@lwc/shared';
4
+ import { noop, StringToLowerCase, isNull, ArrayPush as ArrayPush$1, ArrayJoin, isFrozen, isUndefined as isUndefined$1, defineProperty, ArrayIndexOf, ArraySplice, create, seal, isArray as isArray$1, isFunction as isFunction$1, keys, hasOwnProperty as hasOwnProperty$1, globalThis as globalThis$1, forEach, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, assign, isObject, freeze, KEY__SYNTHETIC_MODE, assert, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, isFalse, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, getOwnPropertyNames as getOwnPropertyNames$1, htmlPropertyToAttribute, ArraySlice, ArrayMap, KEY__SCOPED_CSS, kebabCaseToCamelCase, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, isString, StringSlice, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, ArrayPop, isAPIFeatureEnabled, isNumber, StringReplace, ArrayUnshift, LOWEST_API_VERSION, KEY__NATIVE_GET_ELEMENT_BY_ID, KEY__NATIVE_QUERY_SELECTOR_ALL, ID_REFERENCING_ATTRIBUTES_SET, KEY__SHADOW_TOKEN, ArrayFilter, StringSplit, arrayEvery, ArrayIncludes, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse, ArrayShift } from '@lwc/shared';
5
5
  import { applyAriaReflection } from '@lwc/aria-reflection';
6
6
  export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
7
7
 
@@ -1730,15 +1730,10 @@ for (const propName in HTMLElementOriginalDescriptors) {
1730
1730
  lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
1731
1731
  }
1732
1732
  defineProperties(LightningElement.prototype, lightningBasedDescriptors);
1733
- function applyAriaReflectionToLightningElement() {
1734
- // If ARIA reflection is not applied globally to Element.prototype, or if we are running server-side,
1735
- // apply it to LightningElement.prototype.
1736
- // This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
1737
- applyAriaReflection(LightningElement.prototype);
1738
- }
1739
- if (!process.env.IS_BROWSER || lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
1740
- applyAriaReflectionToLightningElement();
1741
- }
1733
+ // Apply ARIA reflection to LightningElement.prototype, on both the browser and server.
1734
+ // This allows `this.aria*` property accessors to work from inside a component, and to reflect `aria-*` attrs.
1735
+ // Note this works regardless of whether the global ARIA reflection polyfill is applied or not.
1736
+ applyAriaReflection(LightningElement.prototype);
1742
1737
  defineProperty(LightningElement, 'CustomElementConstructor', {
1743
1738
  get() {
1744
1739
  // If required, a runtime-specific implementation must be defined.
@@ -2601,15 +2596,15 @@ if (process.env.IS_BROWSER) {
2601
2596
  // This ARIA reflection only really makes sense in the browser. On the server, there is no `renderedCallback()`,
2602
2597
  // so you cannot do e.g. `this.template.querySelector('x-child').ariaBusy = 'true'`. So we don't need to expose
2603
2598
  // ARIA props outside the LightningElement
2604
- if (lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
2605
- // If ARIA reflection is not applied globally to Element.prototype, apply it to HTMLBridgeElement.prototype.
2606
- // This allows `elm.aria*` property accessors to work from outside a component, and to reflect `aria-*` attrs.
2607
- // This is especially important because the template compiler compiles aria-* attrs on components to aria* props
2608
- //
2609
- // Also note that we apply this to BaseBridgeElement.prototype to avoid excessively redefining property
2610
- // accessors inside the HTMLBridgeElementFactory.
2611
- applyAriaReflection(BaseBridgeElement.prototype);
2612
- }
2599
+ //
2600
+ // Apply ARIA reflection to HTMLBridgeElement.prototype. This allows `elm.aria*` property accessors to work from
2601
+ // outside a component, and to reflect `aria-*` attrs. This is especially important because the template compiler
2602
+ // compiles aria-* attrs on components to aria* props.
2603
+ // Note this works regardless of whether the global ARIA reflection polyfill is applied or not.
2604
+ //
2605
+ // Also note that we apply this to BaseBridgeElement.prototype to avoid excessively redefining property
2606
+ // accessors inside the HTMLBridgeElementFactory.
2607
+ applyAriaReflection(BaseBridgeElement.prototype);
2613
2608
  }
2614
2609
  freeze(BaseBridgeElement);
2615
2610
  seal(BaseBridgeElement.prototype);
@@ -3725,16 +3720,16 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
3725
3720
  // the custom element from the registry is expecting an upgrade callback
3726
3721
  vm = createViewModelHook(elm, vnode, renderer);
3727
3722
  };
3728
- let connectedCallback;
3729
- let disconnectedCallback;
3730
- if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3731
- connectedCallback = (elm) => {
3723
+ const connectedCallback = (elm) => {
3724
+ if (shouldUseNativeCustomElementLifecycle(vm)) {
3732
3725
  connectRootElement(elm);
3733
- };
3734
- disconnectedCallback = (elm) => {
3726
+ }
3727
+ };
3728
+ const disconnectedCallback = (elm) => {
3729
+ if (shouldUseNativeCustomElementLifecycle(vm)) {
3735
3730
  disconnectRootElement(elm);
3736
- };
3737
- }
3731
+ }
3732
+ };
3738
3733
  // Should never get a tag with upper case letter at this point; the compiler
3739
3734
  // should produce only tags with lowercase letters. However, the Java
3740
3735
  // compiler may generate tagnames with uppercase letters so - for backwards
@@ -3752,7 +3747,7 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
3752
3747
  insertNode(elm, parent, anchor, renderer);
3753
3748
  if (vm) {
3754
3749
  if (process.env.IS_BROWSER) {
3755
- if (!lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3750
+ if (!shouldUseNativeCustomElementLifecycle(vm)) {
3756
3751
  if (process.env.NODE_ENV !== 'production') {
3757
3752
  // With synthetic lifecycle callbacks, it's possible for elements to be removed without the engine
3758
3753
  // noticing it (e.g. `appendChild` the same host element twice). This test ensures we don't regress.
@@ -4317,6 +4312,14 @@ function updateStaticChildren(c1, c2, parent, renderer) {
4317
4312
  }
4318
4313
  }
4319
4314
  }
4315
+ function shouldUseNativeCustomElementLifecycle(vm) {
4316
+ if (lwcRuntimeFlags.DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
4317
+ // temporary "kill switch"
4318
+ return false;
4319
+ }
4320
+ const apiVersion = getComponentAPIVersion(vm.component.constructor);
4321
+ return isAPIFeatureEnabled(5 /* APIFeature.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE */, apiVersion);
4322
+ }
4320
4323
 
4321
4324
  /*
4322
4325
  * Copyright (c) 2018, salesforce.com, inc.
@@ -4482,10 +4485,16 @@ function s(slotName, data, children, slotset) {
4482
4485
  children = newChildren;
4483
4486
  }
4484
4487
  const vmBeingRendered = getVMBeingRendered();
4485
- const { renderMode, shadowMode } = vmBeingRendered;
4488
+ const { renderMode, shadowMode, apiVersion } = vmBeingRendered;
4486
4489
  if (renderMode === 0 /* RenderMode.Light */) {
4487
- sc(children);
4488
- return children;
4490
+ // light DOM slots - backwards-compatible behavior uses flattening, new behavior uses fragments
4491
+ if (isAPIFeatureEnabled(2 /* APIFeature.USE_FRAGMENTS_FOR_LIGHT_DOM_SLOTS */, apiVersion)) {
4492
+ return fr(data.key, children, 0);
4493
+ }
4494
+ else {
4495
+ sc(children);
4496
+ return children;
4497
+ }
4489
4498
  }
4490
4499
  if (shadowMode === 1 /* ShadowMode.Synthetic */) {
4491
4500
  // TODO [#1276]: compiler should give us some sort of indicator when a vnodes collection is dynamic
@@ -5261,9 +5270,8 @@ function getComponentAPIVersion(Ctor) {
5261
5270
  const metadata = registeredComponentMap.get(Ctor);
5262
5271
  const apiVersion = metadata === null || metadata === void 0 ? void 0 : metadata.apiVersion;
5263
5272
  if (isUndefined$1(apiVersion)) {
5264
- // This should only occur in our Karma tests; in practice every component
5265
- // is registered, and so this code path should not get hit. But to be safe,
5266
- // return the lowest possible version.
5273
+ // This should only occur in two places: 1) our Karma tests, with unregistered components, and
5274
+ // 2) the ACT compiler. To be safe, return the lowest possible API version.
5267
5275
  return LOWEST_API_VERSION;
5268
5276
  }
5269
5277
  return apiVersion;
@@ -5350,7 +5358,7 @@ function invokeServiceHook(vm, cbs) {
5350
5358
  }
5351
5359
 
5352
5360
  /*
5353
- * Copyright (c) 2018, salesforce.com, inc.
5361
+ * Copyright (c) 2023, Salesforce.com, inc.
5354
5362
  * All rights reserved.
5355
5363
  * SPDX-License-Identifier: MIT
5356
5364
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
@@ -5421,6 +5429,7 @@ function getNearestShadowAncestor(vm) {
5421
5429
  function createVM(elm, ctor, renderer, options) {
5422
5430
  const { mode, owner, tagName, hydrated } = options;
5423
5431
  const def = getComponentInternalDef(ctor);
5432
+ const apiVersion = getComponentAPIVersion(ctor);
5424
5433
  const vm = {
5425
5434
  elm,
5426
5435
  def,
@@ -5463,6 +5472,7 @@ function createVM(elm, ctor, renderer, options) {
5463
5472
  setHook,
5464
5473
  getHook,
5465
5474
  renderer,
5475
+ apiVersion,
5466
5476
  };
5467
5477
  if (process.env.NODE_ENV !== 'production') {
5468
5478
  vm.debugInfo = create(null);
@@ -5541,7 +5551,7 @@ function warnOnStylesheetsMutation(ctor) {
5541
5551
  }
5542
5552
  function computeShadowMode(vm, renderer) {
5543
5553
  const { def } = vm;
5544
- const { isSyntheticShadowDefined, isNativeShadowDefined } = renderer;
5554
+ const { isSyntheticShadowDefined } = renderer;
5545
5555
  let shadowMode;
5546
5556
  if (isSyntheticShadowDefined) {
5547
5557
  if (def.renderMode === 0 /* RenderMode.Light */) {
@@ -5549,34 +5559,25 @@ function computeShadowMode(vm, renderer) {
5549
5559
  // everything defaults to native when the synthetic shadow polyfill is unavailable.
5550
5560
  shadowMode = 0 /* ShadowMode.Native */;
5551
5561
  }
5552
- else if (isNativeShadowDefined) {
5553
- // Not combined with above condition because @lwc/features only supports identifiers in
5554
- // the if-condition.
5555
- if (lwcRuntimeFlags.ENABLE_MIXED_SHADOW_MODE) {
5556
- if (def.shadowSupportMode === "any" /* ShadowSupportMode.Any */) {
5562
+ else if (lwcRuntimeFlags.ENABLE_MIXED_SHADOW_MODE) {
5563
+ if (def.shadowSupportMode === "any" /* ShadowSupportMode.Any */) {
5564
+ shadowMode = 0 /* ShadowMode.Native */;
5565
+ }
5566
+ else {
5567
+ const shadowAncestor = getNearestShadowAncestor(vm);
5568
+ if (!isNull(shadowAncestor) && shadowAncestor.shadowMode === 0 /* ShadowMode.Native */) {
5569
+ // Transitive support for native Shadow DOM. A component in native mode
5570
+ // transitively opts all of its descendants into native.
5557
5571
  shadowMode = 0 /* ShadowMode.Native */;
5558
5572
  }
5559
5573
  else {
5560
- const shadowAncestor = getNearestShadowAncestor(vm);
5561
- if (!isNull(shadowAncestor) &&
5562
- shadowAncestor.shadowMode === 0 /* ShadowMode.Native */) {
5563
- // Transitive support for native Shadow DOM. A component in native mode
5564
- // transitively opts all of its descendants into native.
5565
- shadowMode = 0 /* ShadowMode.Native */;
5566
- }
5567
- else {
5568
- // Synthetic if neither this component nor any of its ancestors are configured
5569
- // to be native.
5570
- shadowMode = 1 /* ShadowMode.Synthetic */;
5571
- }
5574
+ // Synthetic if neither this component nor any of its ancestors are configured
5575
+ // to be native.
5576
+ shadowMode = 1 /* ShadowMode.Synthetic */;
5572
5577
  }
5573
5578
  }
5574
- else {
5575
- shadowMode = 1 /* ShadowMode.Synthetic */;
5576
- }
5577
5579
  }
5578
5580
  else {
5579
- // Synthetic if there is no native Shadow DOM support.
5580
5581
  shadowMode = 1 /* ShadowMode.Synthetic */;
5581
5582
  }
5582
5583
  }
@@ -6056,11 +6057,6 @@ const NON_STANDARD_ARIA_PROPS = [
6056
6057
  'ariaLabelledBy',
6057
6058
  'ariaOwns',
6058
6059
  ];
6059
- function isLightningElement(elm) {
6060
- // The former case is for `this.prop` (inside component) and the latter is for `element.prop` (outside component).
6061
- // In both cases, we apply the non-standard prop even when the global polyfill is disabled, so this is kosher.
6062
- return elm instanceof LightningElement || elm instanceof BaseBridgeElement;
6063
- }
6064
6060
  function findVM(elm) {
6065
6061
  // If it's a shadow DOM component, then it has a host
6066
6062
  const { host } = elm.getRootNode();
@@ -6071,7 +6067,8 @@ function findVM(elm) {
6071
6067
  // Else it might be a light DOM component. Walk up the tree trying to find the owner
6072
6068
  let parentElement = elm;
6073
6069
  while (!isNull((parentElement = parentElement.parentElement))) {
6074
- if (isLightningElement(parentElement)) {
6070
+ if (parentElement instanceof BaseBridgeElement) {
6071
+ // parentElement is an LWC component
6075
6072
  const vm = getAssociatedVMIfPresent(parentElement);
6076
6073
  if (!isUndefined$1(vm)) {
6077
6074
  return vm;
@@ -6081,28 +6078,26 @@ function findVM(elm) {
6081
6078
  // If we return undefined, it's because the element was rendered wholly outside a LightningElement
6082
6079
  }
6083
6080
  function checkAndReportViolation(elm, prop, isSetter, setValue) {
6084
- if (!isLightningElement(elm)) {
6085
- const vm = findVM(elm);
6086
- if (process.env.NODE_ENV !== 'production') {
6087
- logWarnOnce(`Element <${elm.tagName.toLowerCase()}> ` +
6088
- (isUndefined$1(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 = 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
- });
6105
- }
6081
+ const vm = findVM(elm);
6082
+ if (process.env.NODE_ENV !== 'production') {
6083
+ logWarnOnce(`Element <${elm.tagName.toLowerCase()}> ` +
6084
+ (isUndefined$1(vm) ? '' : `owned by <${vm.elm.tagName.toLowerCase()}> `) +
6085
+ `uses non-standard property "${prop}". This will be removed in a future version of LWC. ` +
6086
+ `See https://sfdc.co/deprecated-aria`);
6087
+ }
6088
+ let setValueType;
6089
+ if (isSetter) {
6090
+ // `typeof null` is "object" which is not very useful for detecting null.
6091
+ // We mostly want to know null vs undefined vs other types here, due to
6092
+ // https://github.com/salesforce/lwc/issues/3284
6093
+ setValueType = isNull(setValue) ? 'null' : typeof setValue;
6094
+ }
6095
+ report("NonStandardAriaReflection" /* ReportingEventId.NonStandardAriaReflection */, {
6096
+ tagName: vm === null || vm === void 0 ? void 0 : vm.tagName,
6097
+ propertyName: prop,
6098
+ isSetter,
6099
+ setValueType,
6100
+ });
6106
6101
  }
6107
6102
  function enableDetection() {
6108
6103
  const { prototype } = Element;
@@ -6137,7 +6132,7 @@ function enableDetection() {
6137
6132
  }
6138
6133
  // No point in running this code if we're not in a browser, or if the global polyfill is not loaded
6139
6134
  if (process.env.IS_BROWSER) {
6140
- if (!lwcRuntimeFlags.DISABLE_ARIA_REFLECTION_POLYFILL) {
6135
+ if (lwcRuntimeFlags.ENABLE_ARIA_REFLECTION_GLOBAL_POLYFILL) {
6141
6136
  // Always run detection in dev mode, so we can at least print to the console
6142
6137
  if (process.env.NODE_ENV !== 'production') {
6143
6138
  enableDetection();
@@ -6888,5 +6883,5 @@ function readonly(obj) {
6888
6883
  }
6889
6884
 
6890
6885
  export { LightningElement, profilerControl as __unstable__ProfilerControl, reportingControl as __unstable__ReportingControl, api$1 as api, connectRootElement, createContextProviderWithRegister, createVM, disconnectRootElement, freezeTemplate, getAssociatedVMIfPresent, getComponentAPIVersion, getComponentConstructor, getComponentDef, getComponentHtmlPrototype, hydrateRoot, isComponentConstructor, parseFragment, parseSVGFragment, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setHooks, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
6891
- /** version: 3.1.2 */
6886
+ /** version: 4.0.0-alpha.0 */
6892
6887
  //# sourceMappingURL=index.js.map