lwc 2.23.5 → 2.24.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.
Files changed (39) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +216 -69
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +216 -69
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +194 -67
  5. package/dist/engine-dom/iife/es5/engine-dom.js +494 -313
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +463 -299
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +216 -69
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +194 -67
  11. package/dist/engine-dom/umd/es5/engine-dom.js +494 -313
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +463 -299
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +124 -16
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +124 -16
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +205 -168
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +205 -168
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +2 -2
  20. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +195 -158
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +25 -11
  22. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js +2 -2
  23. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +25 -11
  24. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +205 -168
  25. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +2 -2
  26. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +195 -158
  27. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +25 -11
  28. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js +2 -2
  29. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +25 -11
  30. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  31. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/iife/es5/wire-service.js +2 -2
  34. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  35. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  36. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  37. package/dist/wire-service/umd/es5/wire-service.js +2 -2
  38. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  39. package/package.json +7 -7
@@ -432,9 +432,9 @@ function htmlEscape(str, attrMode = false) {
432
432
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
433
433
  */
434
434
  // Increment whenever the LWC template compiler changes
435
- const LWC_VERSION = "2.23.5";
435
+ const LWC_VERSION = "2.24.0";
436
436
  const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
437
- /** version: 2.23.5 */
437
+ /** version: 2.24.0 */
438
438
 
439
439
  /*
440
440
  * Copyright (c) 2020, salesforce.com, inc.
@@ -545,7 +545,7 @@ function setFeatureFlagForTest(name, value) {
545
545
  setFeatureFlag(name, value);
546
546
  }
547
547
  }
548
- /** version: 2.23.5 */
548
+ /** version: 2.24.0 */
549
549
 
550
550
  /* proxy-compat-disable */
551
551
 
@@ -596,6 +596,20 @@ function flattenStylesheets(stylesheets) {
596
596
  }
597
597
  return list;
598
598
  }
599
+ // Set a ref (lwc:ref) on a VM, from a template API
600
+ function setRefVNode(vm, ref, vnode) {
601
+ if (process.env.NODE_ENV !== 'production' && isUndefined$1(vm.refVNodes)) {
602
+ throw new Error('refVNodes must be defined when setting a ref');
603
+ }
604
+ // If this method is called, then vm.refVNodes is set as the template has refs.
605
+ // If not, then something went wrong and we threw an error above.
606
+ const refVNodes = vm.refVNodes;
607
+ // In cases of conflict (two elements with the same ref), prefer, the last one,
608
+ // in depth-first traversal order.
609
+ if (!(ref in refVNodes) || refVNodes[ref].key < vnode.key) {
610
+ refVNodes[ref] = vnode;
611
+ }
612
+ }
599
613
 
600
614
  /*
601
615
  * Copyright (c) 2019, salesforce.com, inc.
@@ -1830,6 +1844,8 @@ function createBridgeToElementDescriptor(propName, descriptor) {
1830
1844
  },
1831
1845
  };
1832
1846
  }
1847
+ const EMPTY_REFS = freeze(create(null));
1848
+ const refsCache = new WeakMap();
1833
1849
  /**
1834
1850
  * This class is the base class for any LWC element.
1835
1851
  * Some elements directly extends this class, others implement it via inheritance.
@@ -2008,6 +2024,70 @@ LightningElement.prototype = {
2008
2024
  }
2009
2025
  return vm.shadowRoot;
2010
2026
  },
2027
+ get refs() {
2028
+ const vm = getAssociatedVM(this);
2029
+ if (isUpdatingTemplate) {
2030
+ if (process.env.NODE_ENV !== 'production') {
2031
+ logError(`this.refs should not be called while ${getComponentTag(vm)} is rendering. Use this.refs only when the DOM is stable, e.g. in renderedCallback().`);
2032
+ }
2033
+ // If the template is in the process of being updated, then we don't want to go through the normal
2034
+ // process of returning the refs and caching them, because the state of the refs is unstable.
2035
+ // This can happen if e.g. a template contains `<div class={foo}></div>` and `foo` is computed
2036
+ // based on `this.refs.bar`.
2037
+ return;
2038
+ }
2039
+ if (process.env.NODE_ENV !== 'production') {
2040
+ warnIfInvokedDuringConstruction(vm, 'refs');
2041
+ }
2042
+ const { refVNodes, hasRefVNodes, cmpTemplate } = vm;
2043
+ // If the `cmpTemplate` is null, that means that the template has not been rendered yet. Most likely this occurs
2044
+ // if `this.refs` is called during the `connectedCallback` phase. The DOM elements have not been rendered yet,
2045
+ // so log a warning. Note we also check `isBeingConstructed()` to avoid a double warning (due to
2046
+ // `warnIfInvokedDuringConstruction` above).
2047
+ if (process.env.NODE_ENV !== 'production' &&
2048
+ isNull(cmpTemplate) &&
2049
+ !isBeingConstructed(vm)) {
2050
+ logError(`this.refs is undefined for ${getComponentTag(vm)}. This is either because the attached template has no "lwc:ref" directive, or this.refs was ` +
2051
+ `invoked before renderedCallback(). Use this.refs only when the referenced HTML elements have ` +
2052
+ `been rendered to the DOM, such as within renderedCallback() or disconnectedCallback().`);
2053
+ }
2054
+ // For backwards compatibility with component written before template refs
2055
+ // were introduced, we return undefined if the template has no refs defined
2056
+ // anywhere. This fixes components that may want to add an expando called `refs`
2057
+ // and are checking if it exists with `if (this.refs)` before adding it.
2058
+ // Note it is not sufficient to just check if `refVNodes` is null or empty,
2059
+ // because a template may have `lwc:ref` defined within a falsy `if:true` block.
2060
+ if (!hasRefVNodes) {
2061
+ return;
2062
+ }
2063
+ // For templates that are using `lwc:ref`, if there are no refs currently available
2064
+ // (e.g. refs inside of a falsy `if:true` block), we return an empty object.
2065
+ if (isNull(refVNodes)) {
2066
+ return EMPTY_REFS;
2067
+ }
2068
+ // The refNodes can be cached based on the refVNodes, since the refVNodes
2069
+ // are recreated from scratch every time the template is rendered.
2070
+ // This happens with `vm.refVNodes = null` in `template.ts` in `@lwc/engine-core`.
2071
+ let refs = refsCache.get(refVNodes);
2072
+ if (isUndefined$1(refs)) {
2073
+ refs = create(null);
2074
+ for (const key of keys(refVNodes)) {
2075
+ refs[key] = refVNodes[key].elm;
2076
+ }
2077
+ freeze(refs);
2078
+ refsCache.set(refVNodes, refs);
2079
+ }
2080
+ return refs;
2081
+ },
2082
+ // For backwards compat, we allow component authors to set `refs` as an expando
2083
+ set refs(value) {
2084
+ defineProperty(this, 'refs', {
2085
+ configurable: true,
2086
+ enumerable: true,
2087
+ writable: true,
2088
+ value,
2089
+ });
2090
+ },
2011
2091
  get shadowRoot() {
2012
2092
  // From within the component instance, the shadowRoot is always reported as "closed".
2013
2093
  // Authors should rely on this.template instead.
@@ -3430,13 +3510,27 @@ function isLiveBindingProp(sel, key) {
3430
3510
  return sel === 'input' && (key === 'value' || key === 'checked');
3431
3511
  }
3432
3512
  function patchProps(oldVnode, vnode, renderer) {
3433
- const { props } = vnode.data;
3434
- if (isUndefined$1(props)) {
3513
+ let { props } = vnode.data;
3514
+ const { spread } = vnode.data;
3515
+ if (isUndefined$1(props) && isUndefined$1(spread)) {
3435
3516
  return;
3436
3517
  }
3437
- const oldProps = isNull(oldVnode) ? EmptyObject : oldVnode.data.props;
3438
- if (oldProps === props) {
3439
- return;
3518
+ let oldProps;
3519
+ if (!isNull(oldVnode)) {
3520
+ oldProps = oldVnode.data.props;
3521
+ const oldSpread = oldVnode.data.spread;
3522
+ if (oldProps === props && oldSpread === spread) {
3523
+ return;
3524
+ }
3525
+ if (isUndefined$1(oldProps)) {
3526
+ oldProps = EmptyObject;
3527
+ }
3528
+ if (!isUndefined$1(oldSpread)) {
3529
+ oldProps = assign({}, oldProps, oldSpread);
3530
+ }
3531
+ }
3532
+ if (!isUndefined$1(spread)) {
3533
+ props = assign({}, props, spread);
3440
3534
  }
3441
3535
  const isFirstPatch = isNull(oldVnode);
3442
3536
  const { elm, sel } = vnode;
@@ -3446,7 +3540,9 @@ function patchProps(oldVnode, vnode, renderer) {
3446
3540
  // Set the property if it's the first time is is patched or if the previous property is
3447
3541
  // different than the one previously set.
3448
3542
  if (isFirstPatch ||
3449
- cur !== (isLiveBindingProp(sel, key) ? getProperty(elm, key) : oldProps[key])) {
3543
+ cur !== (isLiveBindingProp(sel, key) ? getProperty(elm, key) : oldProps[key]) ||
3544
+ !(key in oldProps) // this is required because the above case will pass when `cur` is `undefined` and key is missing in `oldProps`
3545
+ ) {
3450
3546
  setProperty(elm, key, cur);
3451
3547
  }
3452
3548
  }
@@ -4490,17 +4586,20 @@ function h(sel, data, children = EmptyArray) {
4490
4586
  }
4491
4587
  });
4492
4588
  }
4493
- let elm;
4494
- const { key } = data;
4495
- return {
4589
+ const { key, ref } = data;
4590
+ const vnode = {
4496
4591
  type: 2 /* VNodeType.Element */,
4497
4592
  sel,
4498
4593
  data,
4499
4594
  children,
4500
- elm,
4595
+ elm: undefined,
4501
4596
  key,
4502
4597
  owner: vmBeingRendered,
4503
4598
  };
4599
+ if (!isUndefined$1(ref)) {
4600
+ setRefVNode(vmBeingRendered, ref, vnode);
4601
+ }
4602
+ return vnode;
4504
4603
  }
4505
4604
  // [t]ab[i]ndex function
4506
4605
  function ti(value) {
@@ -4565,7 +4664,7 @@ function c(sel, Ctor, data, children = EmptyArray) {
4565
4664
  });
4566
4665
  }
4567
4666
  }
4568
- const { key } = data;
4667
+ const { key, ref } = data;
4569
4668
  let elm, aChildren, vm;
4570
4669
  const vnode = {
4571
4670
  type: 3 /* VNodeType.CustomElement */,
@@ -4581,6 +4680,9 @@ function c(sel, Ctor, data, children = EmptyArray) {
4581
4680
  vm,
4582
4681
  };
4583
4682
  addVNodeToChildLWC(vnode);
4683
+ if (!isUndefined$1(ref)) {
4684
+ setRefVNode(vmBeingRendered, ref, vnode);
4685
+ }
4584
4686
  return vnode;
4585
4687
  }
4586
4688
  // [i]terable node
@@ -5070,6 +5172,10 @@ function evaluateTemplate(vm, html) {
5070
5172
  // add the VM to the list of host VMs that can be re-rendered if html is swapped
5071
5173
  setActiveVM(vm);
5072
5174
  }
5175
+ // reset the refs; they will be set during the tmpl() instantiation
5176
+ const hasRefVNodes = Boolean(html.hasRefs);
5177
+ vm.hasRefVNodes = hasRefVNodes;
5178
+ vm.refVNodes = hasRefVNodes ? create(null) : null;
5073
5179
  // right before producing the vnodes, we clear up all internal references
5074
5180
  // to custom elements from the template.
5075
5181
  vm.velements = [];
@@ -5422,6 +5528,8 @@ function createVM(elm, ctor, renderer, options) {
5422
5528
  tagName,
5423
5529
  mode,
5424
5530
  owner,
5531
+ refVNodes: null,
5532
+ hasRefVNodes: false,
5425
5533
  children: EmptyArray,
5426
5534
  aChildren: EmptyArray,
5427
5535
  velements: EmptyArray,
@@ -6299,7 +6407,7 @@ function freezeTemplate(tmpl) {
6299
6407
  });
6300
6408
  }
6301
6409
  }
6302
- /* version: 2.23.5 */
6410
+ /* version: 2.24.0 */
6303
6411
 
6304
6412
  /*
6305
6413
  * Copyright (c) 2020, salesforce.com, inc.
@@ -6769,6 +6877,6 @@ function renderComponent(tagName, Ctor, props = {}) {
6769
6877
  */
6770
6878
  freeze(LightningElement);
6771
6879
  seal(LightningElement.prototype);
6772
- /* version: 2.23.5 */
6880
+ /* version: 2.24.0 */
6773
6881
 
6774
6882
  export { LightningElement, api$1 as api, createContextProvider, freezeTemplate, getComponentDef, isComponentConstructor, parseFragment, parseFragment as parseSVGFragment, readonly, register, registerComponent, registerDecorators, registerTemplate, renderComponent, renderer, sanitizeAttribute, setFeatureFlag, setFeatureFlagForTest, setHooks, track, unwrap, wire };