@lwc/engine-core 3.1.2 → 3.2.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, isFalse, freeze, KEY__SYNTHETIC_MODE, assert, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, 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';
5
5
  import { applyAriaReflection } from '@lwc/aria-reflection';
6
6
  export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
7
7
 
@@ -1454,6 +1454,7 @@ function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
1454
1454
  logError(`this.${methodOrPropName} should not be called during the construction of the custom element for ${getComponentTag(vm)} because the element is not yet in the DOM or has no children yet.`);
1455
1455
  }
1456
1456
  }
1457
+ const supportsElementInternals = typeof ElementInternals !== 'undefined';
1457
1458
  // @ts-ignore
1458
1459
  LightningElement.prototype = {
1459
1460
  constructor: LightningElement,
@@ -1545,6 +1546,18 @@ LightningElement.prototype = {
1545
1546
  }
1546
1547
  return getBoundingClientRect(elm);
1547
1548
  },
1549
+ attachInternals() {
1550
+ const vm = getAssociatedVM(this);
1551
+ const { elm, renderer: { attachInternals }, } = vm;
1552
+ if (isFalse(supportsElementInternals)) {
1553
+ // Browsers that don't support attachInternals will need to be polyfilled before LWC is loaded.
1554
+ throw new Error('attachInternals API is not supported in this browser environment.');
1555
+ }
1556
+ if (vm.renderMode === 0 /* RenderMode.Light */ || vm.shadowMode === 1 /* ShadowMode.Synthetic */) {
1557
+ throw new Error('attachInternals API is not supported in light DOM or synthetic shadow.');
1558
+ }
1559
+ return attachInternals(elm);
1560
+ },
1548
1561
  get isConnected() {
1549
1562
  const vm = getAssociatedVM(this);
1550
1563
  const { elm, renderer: { isConnected }, } = vm;
@@ -2586,6 +2599,14 @@ function HTMLBridgeElementFactory(SuperClass, props, methods) {
2586
2599
  descriptors.attributeChangedCallback = {
2587
2600
  value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback),
2588
2601
  };
2602
+ // To avoid leaking private component details, accessing internals from outside a component is not allowed.
2603
+ descriptors.attachInternals = {
2604
+ get() {
2605
+ if (process.env.NODE_ENV !== 'production') {
2606
+ logError('attachInternals cannot be accessed outside of a component. Use this.attachInternals instead.');
2607
+ }
2608
+ },
2609
+ };
2589
2610
  // Specify attributes for which we want to reflect changes back to their corresponding
2590
2611
  // properties via attributeChangedCallback.
2591
2612
  defineProperty(HTMLBridgeElement, 'observedAttributes', {
@@ -5350,7 +5371,7 @@ function invokeServiceHook(vm, cbs) {
5350
5371
  }
5351
5372
 
5352
5373
  /*
5353
- * Copyright (c) 2018, salesforce.com, inc.
5374
+ * Copyright (c) 2023, Salesforce.com, inc.
5354
5375
  * All rights reserved.
5355
5376
  * SPDX-License-Identifier: MIT
5356
5377
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
@@ -5411,8 +5432,8 @@ function removeVM(vm) {
5411
5432
  }
5412
5433
  resetComponentStateWhenRemoved(vm);
5413
5434
  }
5414
- function getNearestShadowAncestor(vm) {
5415
- let ancestor = vm.owner;
5435
+ function getNearestShadowAncestor(owner) {
5436
+ let ancestor = owner;
5416
5437
  while (!isNull(ancestor) && ancestor.renderMode === 0 /* RenderMode.Light */) {
5417
5438
  ancestor = ancestor.owner;
5418
5439
  }
@@ -5468,15 +5489,12 @@ function createVM(elm, ctor, renderer, options) {
5468
5489
  vm.debugInfo = create(null);
5469
5490
  }
5470
5491
  vm.stylesheets = computeStylesheets(vm, def.ctor);
5471
- vm.shadowMode = computeShadowMode(vm, renderer);
5492
+ vm.shadowMode = computeShadowMode(def, vm.owner, renderer);
5472
5493
  vm.tro = getTemplateReactiveObserver(vm);
5473
5494
  if (process.env.NODE_ENV !== 'production') {
5474
5495
  vm.toString = () => {
5475
5496
  return `[object:vm ${def.name} (${vm.idx})]`;
5476
5497
  };
5477
- if (lwcRuntimeFlags.ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST) {
5478
- vm.shadowMode = 0 /* ShadowMode.Native */;
5479
- }
5480
5498
  }
5481
5499
  // Create component instance associated to the vm and the element.
5482
5500
  invokeComponentConstructor(vm, def.ctor);
@@ -5539,9 +5557,22 @@ function warnOnStylesheetsMutation(ctor) {
5539
5557
  });
5540
5558
  }
5541
5559
  }
5542
- function computeShadowMode(vm, renderer) {
5543
- const { def } = vm;
5544
- const { isSyntheticShadowDefined, isNativeShadowDefined } = renderer;
5560
+ // Compute the shadowMode/renderMode without creating a VM. This is used in some scenarios like hydration.
5561
+ function computeShadowAndRenderMode(Ctor, renderer) {
5562
+ const def = getComponentInternalDef(Ctor);
5563
+ const { renderMode } = def;
5564
+ // Assume null `owner` - this is what happens in hydration cases anyway
5565
+ const shadowMode = computeShadowMode(def, /* owner */ null, renderer);
5566
+ return { renderMode, shadowMode };
5567
+ }
5568
+ function computeShadowMode(def, owner, renderer) {
5569
+ // Force the shadow mode to always be native. Used for running tests with synthetic shadow patches
5570
+ // on, but components running in actual native shadow mode
5571
+ if (process.env.NODE_ENV !== 'production' &&
5572
+ lwcRuntimeFlags.ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST) {
5573
+ return 0 /* ShadowMode.Native */;
5574
+ }
5575
+ const { isSyntheticShadowDefined } = renderer;
5545
5576
  let shadowMode;
5546
5577
  if (isSyntheticShadowDefined) {
5547
5578
  if (def.renderMode === 0 /* RenderMode.Light */) {
@@ -5549,34 +5580,25 @@ function computeShadowMode(vm, renderer) {
5549
5580
  // everything defaults to native when the synthetic shadow polyfill is unavailable.
5550
5581
  shadowMode = 0 /* ShadowMode.Native */;
5551
5582
  }
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 */) {
5583
+ else if (lwcRuntimeFlags.ENABLE_MIXED_SHADOW_MODE) {
5584
+ if (def.shadowSupportMode === "any" /* ShadowSupportMode.Any */) {
5585
+ shadowMode = 0 /* ShadowMode.Native */;
5586
+ }
5587
+ else {
5588
+ const shadowAncestor = getNearestShadowAncestor(owner);
5589
+ if (!isNull(shadowAncestor) && shadowAncestor.shadowMode === 0 /* ShadowMode.Native */) {
5590
+ // Transitive support for native Shadow DOM. A component in native mode
5591
+ // transitively opts all of its descendants into native.
5557
5592
  shadowMode = 0 /* ShadowMode.Native */;
5558
5593
  }
5559
5594
  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
- }
5595
+ // Synthetic if neither this component nor any of its ancestors are configured
5596
+ // to be native.
5597
+ shadowMode = 1 /* ShadowMode.Synthetic */;
5572
5598
  }
5573
5599
  }
5574
- else {
5575
- shadowMode = 1 /* ShadowMode.Synthetic */;
5576
- }
5577
5600
  }
5578
5601
  else {
5579
- // Synthetic if there is no native Shadow DOM support.
5580
5602
  shadowMode = 1 /* ShadowMode.Synthetic */;
5581
5603
  }
5582
5604
  }
@@ -6887,6 +6909,6 @@ function readonly(obj) {
6887
6909
  return getReadOnlyProxy(obj);
6888
6910
  }
6889
6911
 
6890
- 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 */
6912
+ export { LightningElement, profilerControl as __unstable__ProfilerControl, reportingControl as __unstable__ReportingControl, api$1 as api, computeShadowAndRenderMode, 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 };
6913
+ /** version: 3.2.0 */
6892
6914
  //# sourceMappingURL=index.js.map