@lwc/engine-core 3.6.0 → 3.7.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, getOwnPropertyDescriptors, 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, getOwnPropertyDescriptors, htmlPropertyToAttribute, ArraySlice, ArrayMap, KEY__SCOPED_CSS, kebabCaseToCamelCase, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, isString, StringSlice, ArrayShift, ArrayUnshift, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, ArrayPop, isNumber, StringReplace, 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 } from '@lwc/shared';
5
5
  import { applyAriaReflection } from '@lwc/aria-reflection';
6
6
  export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
7
7
 
@@ -388,20 +388,6 @@ function flattenStylesheets(stylesheets) {
388
388
  }
389
389
  return list;
390
390
  }
391
- // Set a ref (lwc:ref) on a VM, from a template API
392
- function setRefVNode(vm, ref, vnode) {
393
- if (process.env.NODE_ENV !== 'production' && isUndefined$1(vm.refVNodes)) {
394
- throw new Error('refVNodes must be defined when setting a ref');
395
- }
396
- // If this method is called, then vm.refVNodes is set as the template has refs.
397
- // If not, then something went wrong and we threw an error above.
398
- const refVNodes = vm.refVNodes;
399
- // In cases of conflict (two elements with the same ref), prefer, the last one,
400
- // in depth-first traversal order.
401
- if (!(ref in refVNodes) || refVNodes[ref].key < vnode.key) {
402
- refVNodes[ref] = vnode;
403
- }
404
- }
405
391
  // Throw an error if we're running in prod mode. Ensures code is truly removed from prod mode.
406
392
  function assertNotProd() {
407
393
  /* istanbul ignore if */
@@ -3698,6 +3684,106 @@ function applyStaticStyleAttribute(vnode, renderer) {
3698
3684
  }
3699
3685
  }
3700
3686
 
3687
+ /*
3688
+ * Copyright (c) 2023, salesforce.com, inc.
3689
+ * All rights reserved.
3690
+ * SPDX-License-Identifier: MIT
3691
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3692
+ */
3693
+ // Set a ref (lwc:ref) on a VM, from a template API
3694
+ function applyRefs(vnode, owner) {
3695
+ const { data } = vnode;
3696
+ const { ref } = data;
3697
+ if (isUndefined$1(ref)) {
3698
+ return;
3699
+ }
3700
+ if (process.env.NODE_ENV !== 'production' && isUndefined$1(owner.refVNodes)) {
3701
+ throw new Error('refVNodes must be defined when setting a ref');
3702
+ }
3703
+ // If this method is called, then vm.refVNodes is set as the template has refs.
3704
+ // If not, then something went wrong and we threw an error above.
3705
+ const refVNodes = owner.refVNodes;
3706
+ // In cases of conflict (two elements with the same ref), prefer the last one,
3707
+ // in depth-first traversal order. This happens automatically due to how we render
3708
+ refVNodes[ref] = vnode;
3709
+ }
3710
+
3711
+ /*
3712
+ * Copyright (c) 2023, salesforce.com, inc.
3713
+ * All rights reserved.
3714
+ * SPDX-License-Identifier: MIT
3715
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3716
+ */
3717
+ function traverseAndSetElements(root, parts, renderer) {
3718
+ const numParts = parts.length;
3719
+ // Optimization given that, in most cases, there will be one part, and it's just the root
3720
+ if (numParts === 1) {
3721
+ const firstPart = parts[0];
3722
+ if (firstPart.partId === 0) {
3723
+ // 0 means the root node
3724
+ firstPart.elm = root;
3725
+ return;
3726
+ }
3727
+ }
3728
+ const partIdsToParts = new Map();
3729
+ for (const staticPart of parts) {
3730
+ partIdsToParts.set(staticPart.partId, staticPart);
3731
+ }
3732
+ let numFoundParts = 0;
3733
+ const { previousSibling, getLastChild } = renderer;
3734
+ const stack = [root];
3735
+ let partId = -1;
3736
+ // Depth-first traversal. We assign a partId to each element, which is an integer based on traversal order.
3737
+ while (stack.length > 0) {
3738
+ const elm = ArrayShift.call(stack);
3739
+ partId++;
3740
+ const part = partIdsToParts.get(partId);
3741
+ if (!isUndefined$1(part)) {
3742
+ part.elm = elm;
3743
+ if (++numFoundParts === numParts) {
3744
+ return; // perf optimization - stop traversing once we've found everything we need
3745
+ }
3746
+ }
3747
+ // For depth-first traversal, prepend to the stack in reverse order
3748
+ // Note that we traverse using `*Child`/`*Sibling` rather than `children` because the browser uses a linked
3749
+ // list under the hood to represent the DOM tree, so it's faster to do this than to create an underlying array
3750
+ // by calling `children`.
3751
+ let child = getLastChild(elm);
3752
+ while (!isNull(child)) {
3753
+ ArrayUnshift.call(stack, child);
3754
+ child = previousSibling(child);
3755
+ }
3756
+ }
3757
+ if (process.env.NODE_ENV !== 'production') {
3758
+ assert.isTrue(numFoundParts === numParts, `Should have found all parts by now. Found ${numFoundParts}, needed ${numParts}.`);
3759
+ }
3760
+ }
3761
+ /**
3762
+ * Given an array of static parts, do all the mounting required for these parts.
3763
+ *
3764
+ * @param root - the root element
3765
+ * @param vnode - the parent VStatic
3766
+ * @param renderer - the renderer to use
3767
+ */
3768
+ function applyStaticParts(root, vnode, renderer) {
3769
+ // On the server, we don't support ref (because it relies on renderedCallback), nor do we
3770
+ // support event listeners (no interactivity), so traversing parts makes no sense
3771
+ if (!process.env.IS_BROWSER) {
3772
+ return;
3773
+ }
3774
+ const { parts, owner } = vnode;
3775
+ if (isUndefined$1(parts)) {
3776
+ return;
3777
+ }
3778
+ traverseAndSetElements(root, parts, renderer); // this adds `part.elm` to each `part`
3779
+ for (const part of parts) {
3780
+ // Event listeners are only applied once when mounting, so they are allowed for static vnodes
3781
+ applyEventListeners(part, renderer);
3782
+ // Refs are allowed as well
3783
+ applyRefs(part, owner);
3784
+ }
3785
+ }
3786
+
3701
3787
  /*
3702
3788
  * Copyright (c) 2018, salesforce.com, inc.
3703
3789
  * All rights reserved.
@@ -3834,13 +3920,13 @@ function mountElement(vnode, parent, anchor, renderer) {
3834
3920
  applyStyleScoping(elm, owner, renderer);
3835
3921
  applyDomManual(elm, vnode);
3836
3922
  applyElementRestrictions(elm, vnode);
3837
- patchElementPropsAndAttrs$1(null, vnode, renderer);
3923
+ patchElementPropsAndAttrsAndRefs$1(null, vnode, renderer);
3838
3924
  insertNode(elm, parent, anchor, renderer);
3839
3925
  mountVNodes(vnode.children, elm, renderer, null);
3840
3926
  }
3841
3927
  function patchElement(n1, n2, renderer) {
3842
3928
  const elm = (n2.elm = n1.elm);
3843
- patchElementPropsAndAttrs$1(n1, n2, renderer);
3929
+ patchElementPropsAndAttrsAndRefs$1(n1, n2, renderer);
3844
3930
  patchChildren(n1.children, n2.children, elm, renderer);
3845
3931
  }
3846
3932
  function mountStatic(vnode, parent, anchor, renderer) {
@@ -3857,8 +3943,7 @@ function mountStatic(vnode, parent, anchor, renderer) {
3857
3943
  }
3858
3944
  }
3859
3945
  insertNode(elm, parent, anchor, renderer);
3860
- // Event listeners are only applied once when mounting, so they are allowed for static vnodes
3861
- applyEventListeners(vnode, renderer);
3946
+ applyStaticParts(elm, vnode, renderer);
3862
3947
  }
3863
3948
  function mountCustomElement(vnode, parent, anchor, renderer) {
3864
3949
  const { sel, owner } = vnode;
@@ -3913,7 +3998,7 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
3913
3998
  if (vm) {
3914
3999
  allocateChildren(vnode, vm);
3915
4000
  }
3916
- patchElementPropsAndAttrs$1(null, vnode, renderer);
4001
+ patchElementPropsAndAttrsAndRefs$1(null, vnode, renderer);
3917
4002
  insertNode(elm, parent, anchor, renderer);
3918
4003
  if (vm) {
3919
4004
  if (process.env.IS_BROWSER) {
@@ -3950,7 +4035,7 @@ function patchCustomElement(n1, n2, parent, renderer) {
3950
4035
  // Otherwise patch the existing component with new props/attrs/etc.
3951
4036
  const elm = (n2.elm = n1.elm);
3952
4037
  const vm = (n2.vm = n1.vm);
3953
- patchElementPropsAndAttrs$1(n1, n2, renderer);
4038
+ patchElementPropsAndAttrsAndRefs$1(n1, n2, renderer);
3954
4039
  if (!isUndefined$1(vm)) {
3955
4040
  // in fallback mode, the allocation will always set children to
3956
4041
  // empty and delegate the real allocation to the slot elements
@@ -4097,7 +4182,7 @@ function removeNode(node, parent, renderer) {
4097
4182
  lockDomMutation();
4098
4183
  }
4099
4184
  }
4100
- function patchElementPropsAndAttrs$1(oldVnode, vnode, renderer) {
4185
+ function patchElementPropsAndAttrsAndRefs$1(oldVnode, vnode, renderer) {
4101
4186
  if (isNull(oldVnode)) {
4102
4187
  applyEventListeners(vnode, renderer);
4103
4188
  applyStaticClassAttribute(vnode, renderer);
@@ -4109,6 +4194,8 @@ function patchElementPropsAndAttrs$1(oldVnode, vnode, renderer) {
4109
4194
  patchStyleAttribute(oldVnode, vnode, renderer);
4110
4195
  patchAttributes(oldVnode, vnode, renderer);
4111
4196
  patchProps(oldVnode, vnode, renderer);
4197
+ // The `refs` object is blown away in every re-render, so we always need to re-apply them
4198
+ applyRefs(vnode, vnode.owner);
4112
4199
  }
4113
4200
  function applyStyleScoping(elm, owner, renderer) {
4114
4201
  const { getClassList } = renderer;
@@ -4510,6 +4597,14 @@ const SymbolIterator = Symbol.iterator;
4510
4597
  function addVNodeToChildLWC(vnode) {
4511
4598
  ArrayPush$1.call(getVMBeingRendered().velements, vnode);
4512
4599
  }
4600
+ // [s]tatic [p]art
4601
+ function sp(partId, data) {
4602
+ return {
4603
+ partId,
4604
+ data,
4605
+ elm: undefined, // elm is defined later
4606
+ };
4607
+ }
4513
4608
  // [s]coped [s]lot [f]actory
4514
4609
  function ssf(slotName, factory) {
4515
4610
  return {
@@ -4523,7 +4618,7 @@ function ssf(slotName, factory) {
4523
4618
  };
4524
4619
  }
4525
4620
  // [st]atic node
4526
- function st(fragment, key, data) {
4621
+ function st(fragment, key, parts) {
4527
4622
  const owner = getVMBeingRendered();
4528
4623
  const vnode = {
4529
4624
  type: 4 /* VNodeType.Static */,
@@ -4532,12 +4627,8 @@ function st(fragment, key, data) {
4532
4627
  elm: undefined,
4533
4628
  fragment,
4534
4629
  owner,
4535
- data,
4630
+ parts,
4536
4631
  };
4537
- const ref = data === null || data === void 0 ? void 0 : data.ref;
4538
- if (!isUndefined$1(ref)) {
4539
- setRefVNode(owner, ref, vnode);
4540
- }
4541
4632
  return vnode;
4542
4633
  }
4543
4634
  // [fr]agment node
@@ -4579,7 +4670,7 @@ function h(sel, data, children = EmptyArray) {
4579
4670
  }
4580
4671
  });
4581
4672
  }
4582
- const { key, ref } = data;
4673
+ const { key } = data;
4583
4674
  const vnode = {
4584
4675
  type: 2 /* VNodeType.Element */,
4585
4676
  sel,
@@ -4589,9 +4680,6 @@ function h(sel, data, children = EmptyArray) {
4589
4680
  key,
4590
4681
  owner: vmBeingRendered,
4591
4682
  };
4592
- if (!isUndefined$1(ref)) {
4593
- setRefVNode(vmBeingRendered, ref, vnode);
4594
- }
4595
4683
  return vnode;
4596
4684
  }
4597
4685
  // [t]ab[i]ndex function
@@ -4700,7 +4788,7 @@ function c(sel, Ctor, data, children = EmptyArray) {
4700
4788
  });
4701
4789
  }
4702
4790
  }
4703
- const { key, ref } = data;
4791
+ const { key } = data;
4704
4792
  let elm, aChildren, vm;
4705
4793
  const vnode = {
4706
4794
  type: 3 /* VNodeType.CustomElement */,
@@ -4716,9 +4804,6 @@ function c(sel, Ctor, data, children = EmptyArray) {
4716
4804
  vm,
4717
4805
  };
4718
4806
  addVNodeToChildLWC(vnode);
4719
- if (!isUndefined$1(ref)) {
4720
- setRefVNode(vmBeingRendered, ref, vnode);
4721
- }
4722
4807
  return vnode;
4723
4808
  }
4724
4809
  // [i]terable node
@@ -5009,6 +5094,7 @@ const api = freeze({
5009
5094
  shc,
5010
5095
  ssf,
5011
5096
  ddc,
5097
+ sp,
5012
5098
  });
5013
5099
 
5014
5100
  /*
@@ -6471,7 +6557,7 @@ function hydrateStaticElement(elm, vnode, renderer) {
6471
6557
  return handleMismatch(elm, vnode, renderer);
6472
6558
  }
6473
6559
  vnode.elm = elm;
6474
- applyEventListeners(vnode, renderer);
6560
+ applyStaticParts(elm, vnode, renderer);
6475
6561
  return elm;
6476
6562
  }
6477
6563
  function hydrateFragment(elm, vnode, renderer) {
@@ -6505,7 +6591,7 @@ function hydrateElement(elm, vnode, renderer) {
6505
6591
  }
6506
6592
  }
6507
6593
  }
6508
- patchElementPropsAndAttrs(vnode, renderer);
6594
+ patchElementPropsAndAttrsAndRefs(vnode, renderer);
6509
6595
  if (!isDomManual) {
6510
6596
  const { getFirstChild } = renderer;
6511
6597
  hydrateChildren(getFirstChild(elm), vnode.children, elm, owner);
@@ -6538,7 +6624,7 @@ function hydrateCustomElement(elm, vnode, renderer) {
6538
6624
  vnode.elm = elm;
6539
6625
  vnode.vm = vm;
6540
6626
  allocateChildren(vnode, vm);
6541
- patchElementPropsAndAttrs(vnode, renderer);
6627
+ patchElementPropsAndAttrsAndRefs(vnode, renderer);
6542
6628
  // Insert hook section:
6543
6629
  if (process.env.NODE_ENV !== 'production') {
6544
6630
  assert.isTrue(vm.state === 0 /* VMState.created */, `${vm} cannot be recycled.`);
@@ -6603,9 +6689,11 @@ function handleMismatch(node, vnode, renderer) {
6603
6689
  removeNode(node, parentNode, renderer);
6604
6690
  return vnode.elm;
6605
6691
  }
6606
- function patchElementPropsAndAttrs(vnode, renderer) {
6692
+ function patchElementPropsAndAttrsAndRefs(vnode, renderer) {
6607
6693
  applyEventListeners(vnode, renderer);
6608
6694
  patchProps(null, vnode, renderer);
6695
+ // The `refs` object is blown away in every re-render, so we always need to re-apply them
6696
+ applyRefs(vnode, vnode.owner);
6609
6697
  }
6610
6698
  function hasCorrectNodeType(vnode, node, nodeType, renderer) {
6611
6699
  const { getProperty } = renderer;
@@ -7084,5 +7172,5 @@ function readonly(obj) {
7084
7172
  }
7085
7173
 
7086
7174
  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, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
7087
- /** version: 3.6.0 */
7175
+ /** version: 3.7.0 */
7088
7176
  //# sourceMappingURL=index.js.map