@lwc/engine-core 6.7.2 → 7.0.0-alpha.1

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) 2024 Salesforce, Inc.
3
3
  */
4
- import { noop, StringToLowerCase, isNull, ArrayPush as ArrayPush$1, ArrayJoin, isFrozen, isUndefined as isUndefined$1, defineProperty, ArrayIndexOf, ArrayPop, create, isFalse, isFunction as isFunction$1, isObject, seal, isAPIFeatureEnabled, isArray as isArray$1, keys, hasOwnProperty as hasOwnProperty$1, entries, AriaPropNameToAttrNameMap, getPropertyDescriptor, forEach, defineProperties, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, assign, freeze, KEY__SYNTHETIC_MODE, assert, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, getOwnPropertyNames as getOwnPropertyNames$1, getOwnPropertyDescriptors, htmlPropertyToAttribute, ArraySlice, ArrayMap, KEY__SCOPED_CSS, ArraySplice, kebabCaseToCamelCase, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, isString, StringSlice, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, isNumber, StringReplace, htmlEscape, StringCharAt, 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, ArrayPop, create, isFalse, isFunction as isFunction$1, isObject, seal, isAPIFeatureEnabled, isArray as isArray$1, keys, hasOwnProperty as hasOwnProperty$1, entries, AriaPropNameToAttrNameMap, getPropertyDescriptor, forEach, defineProperties, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, assign, assert, freeze, KEY__SYNTHETIC_MODE, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, getOwnPropertyNames as getOwnPropertyNames$1, getOwnPropertyDescriptors, htmlPropertyToAttribute, ArraySlice, ArrayMap, KEY__SCOPED_CSS, ArraySplice, kebabCaseToCamelCase, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, isString, StringSlice, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, isNumber, StringReplace, StringTrim, htmlEscape, StringCharAt, 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
  export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
6
6
 
7
7
  /*
@@ -1513,7 +1513,7 @@ function applyShadowMigrateMode(shadowRoot) {
1513
1513
  }
1514
1514
 
1515
1515
  /*
1516
- * Copyright (c) 2018, salesforce.com, inc.
1516
+ * Copyright (c) 2024, Salesforce, Inc.
1517
1517
  * All rights reserved.
1518
1518
  * SPDX-License-Identifier: MIT
1519
1519
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
@@ -1780,6 +1780,25 @@ LightningElement.prototype = {
1780
1780
  }
1781
1781
  return vm.shadowRoot;
1782
1782
  },
1783
+ get hostElement() {
1784
+ const vm = getAssociatedVM(this);
1785
+ if (!process.env.IS_BROWSER) {
1786
+ assert.fail('this.hostElement is not supported in this environment');
1787
+ }
1788
+ const apiVersion = getComponentAPIVersion(vm.def.ctor);
1789
+ if (!isAPIFeatureEnabled(9 /* APIFeature.ENABLE_THIS_DOT_HOST_ELEMENT */, apiVersion)) {
1790
+ if (process.env.NODE_ENV !== 'production') {
1791
+ logWarnOnce('The `this.hostElement` API within LightningElement is ' +
1792
+ 'only supported in API version 62 and above. Increase the API version to use it.');
1793
+ }
1794
+ // Simulate the old behavior for `this.hostElement` to avoid a breaking change
1795
+ return undefined;
1796
+ }
1797
+ if (process.env.NODE_ENV !== 'production') {
1798
+ assert.isTrue(vm.elm instanceof Element, `this.hostElement should be an Element, found: ${vm.elm}`);
1799
+ }
1800
+ return vm.elm;
1801
+ },
1783
1802
  get refs() {
1784
1803
  const vm = getAssociatedVM(this);
1785
1804
  if (isUpdatingTemplate) {
@@ -1906,6 +1925,19 @@ LightningElement.prototype = {
1906
1925
  const { elm, renderer } = getAssociatedVM(this);
1907
1926
  return renderer.getTagName(elm);
1908
1927
  },
1928
+ get style() {
1929
+ const { elm, renderer, def } = getAssociatedVM(this);
1930
+ const apiVersion = getComponentAPIVersion(def.ctor);
1931
+ if (!isAPIFeatureEnabled(10 /* APIFeature.ENABLE_THIS_DOT_STYLE */, apiVersion)) {
1932
+ if (process.env.NODE_ENV !== 'production') {
1933
+ logWarnOnce('The `this.style` API within LightningElement returning the CSSStyleDeclaration is ' +
1934
+ 'only supported in API version 62 and above. Increase the API version to use it.');
1935
+ }
1936
+ // Simulate the old behavior for `this.style` to avoid a breaking change
1937
+ return undefined;
1938
+ }
1939
+ return renderer.getStyle(elm);
1940
+ },
1909
1941
  render() {
1910
1942
  const vm = getAssociatedVM(this);
1911
1943
  return vm.def.template;
@@ -2258,12 +2290,21 @@ function disconnectWireAdapters(vm) {
2258
2290
  }
2259
2291
 
2260
2292
  /*
2261
- * Copyright (c) 2018, salesforce.com, inc.
2293
+ * Copyright (c) 2024, Salesforce, Inc.
2262
2294
  * All rights reserved.
2263
2295
  * SPDX-License-Identifier: MIT
2264
2296
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2265
2297
  */
2266
- function api$1() {
2298
+ /**
2299
+ * The `@api` decorator marks public fields and public methods in
2300
+ * LWC Components. This function implements the internals of this
2301
+ * decorator.
2302
+ */
2303
+ function api$1(
2304
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2305
+ value,
2306
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2307
+ context) {
2267
2308
  if (process.env.NODE_ENV !== 'production') {
2268
2309
  assert.fail(`@api decorator can only be used as a decorator function.`);
2269
2310
  }
@@ -2336,7 +2377,7 @@ function createPublicAccessorDescriptor(key, descriptor) {
2336
2377
  }
2337
2378
 
2338
2379
  /*
2339
- * Copyright (c) 2018, salesforce.com, inc.
2380
+ * Copyright (c) 2024, Salesforce, Inc.
2340
2381
  * All rights reserved.
2341
2382
  * SPDX-License-Identifier: MIT
2342
2383
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
@@ -2378,19 +2419,27 @@ function internalTrackDecorator(key) {
2378
2419
  }
2379
2420
 
2380
2421
  /*
2381
- * Copyright (c) 2018, salesforce.com, inc.
2422
+ * Copyright (c) 2024, Salesforce, Inc.
2382
2423
  * All rights reserved.
2383
2424
  * SPDX-License-Identifier: MIT
2384
2425
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2385
2426
  */
2386
2427
  /**
2387
- * The @wire decorator wires fields and methods to a wire adapter in
2388
- * LWC Components. This function implements the internals of this
2389
- * decorator.
2390
- * @param _adapter
2391
- * @param _config
2428
+ * Decorator factory to wire a property or method to a wire adapter data source.
2429
+ * @param adapter the adapter used to provision data
2430
+ * @param config configuration object for the adapter
2431
+ * @returns A decorator function
2432
+ * @example
2433
+ * export default class WireExample extends LightningElement {
2434
+ * \@api bookId;
2435
+ * \@wire(getBook, { id: '$bookId'}) book;
2436
+ * }
2392
2437
  */
2393
- function wire(_adapter, _config) {
2438
+ function wire(
2439
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2440
+ adapter,
2441
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2442
+ config) {
2394
2443
  if (process.env.NODE_ENV !== 'production') {
2395
2444
  assert.fail('@wire(adapter, config?) may only be used as a decorator.');
2396
2445
  }
@@ -2426,13 +2475,13 @@ function internalWireFieldDecorator(key) {
2426
2475
  */
2427
2476
  function getClassDescriptorType(descriptor) {
2428
2477
  if (isFunction$1(descriptor.value)) {
2429
- return "method" /* DescriptorType.Method */;
2478
+ return 'method';
2430
2479
  }
2431
2480
  else if (isFunction$1(descriptor.set) || isFunction$1(descriptor.get)) {
2432
- return "accessor" /* DescriptorType.Accessor */;
2481
+ return 'accessor';
2433
2482
  }
2434
2483
  else {
2435
- return "field" /* DescriptorType.Field */;
2484
+ return 'field';
2436
2485
  }
2437
2486
  }
2438
2487
  function validateObservedField(Ctor, fieldName, descriptor) {
@@ -2662,9 +2711,7 @@ function checkVersionMismatch(func, type) {
2662
2711
  const versionMatcher = func.toString().match(LWC_VERSION_COMMENT_REGEX);
2663
2712
  if (!isNull(versionMatcher) && !warned) {
2664
2713
  const version = versionMatcher[1];
2665
- const [major, minor] = version.split('.');
2666
- const [expectedMajor, expectedMinor] = LWC_VERSION.split('.');
2667
- if (major !== expectedMajor || minor !== expectedMinor) {
2714
+ if (version !== LWC_VERSION) {
2668
2715
  warned = true; // only warn once to avoid flooding the console
2669
2716
  // stylesheets and templates do not have user-meaningful names, but components do
2670
2717
  const friendlyName = type === 'component' ? `${type} ${func.name}` : type;
@@ -3297,7 +3344,7 @@ let swappedComponentMap =
3297
3344
  let swappedStyleMap = /*@__PURE__@*/ new WeakMap();
3298
3345
  // The important thing here is the weak values – VMs are transient (one per component instance) and should be GC'ed,
3299
3346
  // so we don't want to create strong references to them.
3300
- // The weak keys are kind of useless, because Templates, LightningElementConstructors, and StylesheetFactories are
3347
+ // The weak keys are kind of useless, because Templates, LightningElementConstructors, and Stylesheets are
3301
3348
  // never GC'ed. But maybe they will be someday, so we may as well use weak keys too.
3302
3349
  // The "pure" annotations are so that Rollup knows for sure it can remove these from prod mode
3303
3350
  let activeTemplates = /*@__PURE__@*/ new WeakMultiMap();
@@ -3530,13 +3577,13 @@ function createComponentDef(Ctor) {
3530
3577
  logError(`Missing ${ctorName}.constructor, ${ctorName} should have a "constructor" property.`);
3531
3578
  }
3532
3579
  if (!isUndefined$1(ctorShadowSupportMode) &&
3533
- ctorShadowSupportMode !== "any" /* ShadowSupportMode.Any */ &&
3534
- ctorShadowSupportMode !== "reset" /* ShadowSupportMode.Default */ &&
3535
- ctorShadowSupportMode !== "native" /* ShadowSupportMode.Native */) {
3580
+ ctorShadowSupportMode !== 'any' &&
3581
+ ctorShadowSupportMode !== 'reset' &&
3582
+ ctorShadowSupportMode !== 'native') {
3536
3583
  logError(`Invalid value for static property shadowSupportMode: '${ctorShadowSupportMode}'`);
3537
3584
  }
3538
3585
  // TODO [#3971]: Completely remove shadowSupportMode "any"
3539
- if (ctorShadowSupportMode === "any" /* ShadowSupportMode.Any */) {
3586
+ if (ctorShadowSupportMode === 'any') {
3540
3587
  logWarn(`Invalid value 'any' for static property shadowSupportMode. 'any' is deprecated and will be removed in a future release--use 'native' instead.`);
3541
3588
  }
3542
3589
  if (!isUndefined$1(ctorRenderMode) &&
@@ -3570,8 +3617,7 @@ function createComponentDef(Ctor) {
3570
3617
  if (!isUndefined$1(ctorShadowSupportMode)) {
3571
3618
  shadowSupportMode = ctorShadowSupportMode;
3572
3619
  if (isReportingEnabled() &&
3573
- (shadowSupportMode === "any" /* ShadowSupportMode.Any */ ||
3574
- shadowSupportMode === "native" /* ShadowSupportMode.Native */)) {
3620
+ (shadowSupportMode === 'any' || shadowSupportMode === 'native')) {
3575
3621
  report("ShadowSupportModeUsage" /* ReportingEventId.ShadowSupportModeUsage */, {
3576
3622
  tagName: Ctor.name,
3577
3623
  mode: shadowSupportMode,
@@ -3686,7 +3732,7 @@ const lightingElementDef = {
3686
3732
  propsConfig: EmptyObject,
3687
3733
  methods: EmptyObject,
3688
3734
  renderMode: 1 /* RenderMode.Shadow */,
3689
- shadowSupportMode: "reset" /* ShadowSupportMode.Default */,
3735
+ shadowSupportMode: 'reset',
3690
3736
  formAssociated: undefined,
3691
3737
  wire: EmptyObject,
3692
3738
  bridge: BaseBridgeElement,
@@ -3710,7 +3756,7 @@ function getComponentDef(Ctor) {
3710
3756
  // avoid leaking the reference to the public props descriptors
3711
3757
  publicProps[key] = {
3712
3758
  config: propsConfig[key] || 0, // a property by default
3713
- type: "any" /* PropDefType.any */, // no type inference for public services
3759
+ type: 'any', // no type inference for public services
3714
3760
  attr: htmlPropertyToAttribute(key),
3715
3761
  };
3716
3762
  }
@@ -4687,14 +4733,14 @@ function applyStyleScoping(elm, owner, renderer) {
4687
4733
  }
4688
4734
  function applyDomManual(elm, vnode) {
4689
4735
  const { owner, data: { context }, } = vnode;
4690
- if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && context?.lwc?.dom === "manual" /* LwcDomMode.Manual */) {
4736
+ if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && context?.lwc?.dom === 'manual') {
4691
4737
  elm.$domManual$ = true;
4692
4738
  }
4693
4739
  }
4694
4740
  function applyElementRestrictions(elm, vnode) {
4695
4741
  if (process.env.NODE_ENV !== 'production') {
4696
4742
  const isSynthetic = vnode.owner.shadowMode === 1 /* ShadowMode.Synthetic */;
4697
- const isPortal = vnode.type === 2 /* VNodeType.Element */ && vnode.data.context?.lwc?.dom === "manual" /* LwcDomMode.Manual */;
4743
+ const isPortal = vnode.type === 2 /* VNodeType.Element */ && vnode.data.context?.lwc?.dom === 'manual';
4698
4744
  const isLight = vnode.owner.renderMode === 0 /* RenderMode.Light */;
4699
4745
  patchElementWithRestrictions(elm, {
4700
4746
  isPortal,
@@ -5579,6 +5625,37 @@ function setSanitizeHtmlContentHook(newHookImpl) {
5579
5625
  function shc(content) {
5580
5626
  return sanitizeHtmlContentHook(content);
5581
5627
  }
5628
+ /**
5629
+ * [ncls] - Normalize class name attribute.
5630
+ *
5631
+ * Transforms the provided class property value from an object/string into a string the diffing algo
5632
+ * can operate on.
5633
+ *
5634
+ * This implementation is borrowed from Vue:
5635
+ * https://github.com/vuejs/core/blob/e790e1bdd7df7be39e14780529db86e4da47a3db/packages/shared/src/normalizeProp.ts#L63-L82
5636
+ */
5637
+ function ncls(value) {
5638
+ let res = '';
5639
+ if (isString(value)) {
5640
+ res = value;
5641
+ }
5642
+ else if (isArray$1(value)) {
5643
+ for (let i = 0; i < value.length; i++) {
5644
+ const normalized = ncls(value[i]);
5645
+ if (normalized) {
5646
+ res += normalized + ' ';
5647
+ }
5648
+ }
5649
+ }
5650
+ else if (isObject(value)) {
5651
+ for (const key in value) {
5652
+ if (value[key]) {
5653
+ res += key + ' ';
5654
+ }
5655
+ }
5656
+ }
5657
+ return StringTrim.call(res);
5658
+ }
5582
5659
  const api = freeze({
5583
5660
  s,
5584
5661
  h,
@@ -5600,6 +5677,7 @@ const api = freeze({
5600
5677
  ssf,
5601
5678
  ddc,
5602
5679
  sp,
5680
+ ncls,
5603
5681
  });
5604
5682
 
5605
5683
  /*
@@ -6481,7 +6559,7 @@ function computeShadowMode(def, owner, renderer, hydrated) {
6481
6559
  // everything defaults to native when the synthetic shadow polyfill is unavailable.
6482
6560
  shadowMode = 0 /* ShadowMode.Native */;
6483
6561
  }
6484
- else if (def.shadowSupportMode === "native" /* ShadowSupportMode.Native */) {
6562
+ else if (def.shadowSupportMode === 'native') {
6485
6563
  shadowMode = 0 /* ShadowMode.Native */;
6486
6564
  }
6487
6565
  else {
@@ -7276,7 +7354,7 @@ function hydrateElement(elm, vnode, renderer) {
7276
7354
  vnode.elm = elm;
7277
7355
  const { owner } = vnode;
7278
7356
  const { context } = vnode.data;
7279
- const isDomManual = Boolean(!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual" /* LwcDomMode.Manual */);
7357
+ const isDomManual = Boolean(!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === 'manual');
7280
7358
  if (isDomManual) {
7281
7359
  // it may be that this element has lwc:inner-html, we need to diff and in case are the same,
7282
7360
  // remove the innerHTML from props so it reuses the existing dom elements.
@@ -7951,5 +8029,5 @@ function readonly(obj) {
7951
8029
  }
7952
8030
 
7953
8031
  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, registerComponent, registerDecorators, registerTemplate, runFormAssociatedCallback, runFormDisabledCallback, runFormResetCallback, runFormStateRestoreCallback, sanitizeAttribute, setHooks, shouldBeFormAssociated, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
7954
- /** version: 6.7.2 */
8032
+ /** version: 7.0.0-alpha.0 */
7955
8033
  //# sourceMappingURL=index.js.map