lwc 2.33.0 → 2.34.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 (35) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +166 -42
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +166 -42
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +170 -39
  5. package/dist/engine-dom/iife/es5/engine-dom.js +204 -91
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +217 -88
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +166 -42
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +170 -39
  11. package/dist/engine-dom/umd/es5/engine-dom.js +204 -91
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +217 -88
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +158 -39
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +158 -39
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +3 -3
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +3 -3
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +3 -3
  20. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +3 -3
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +3 -3
  22. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +3 -3
  23. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +3 -3
  24. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +3 -3
  25. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +3 -3
  26. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  27. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  28. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  29. package/dist/wire-service/iife/es5/wire-service.js +2 -2
  30. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  31. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/umd/es5/wire-service.js +2 -2
  34. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  35. package/package.json +7 -7
@@ -347,9 +347,9 @@ var LWC = (function (exports) {
347
347
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
348
348
  */
349
349
  // Increment whenever the LWC template compiler changes
350
- const LWC_VERSION = "2.33.0";
350
+ const LWC_VERSION = "2.34.0";
351
351
  const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
352
- /** version: 2.33.0 */
352
+ /** version: 2.34.0 */
353
353
 
354
354
  /**
355
355
  * Copyright (C) 2018 salesforce.com, inc.
@@ -372,6 +372,7 @@ var LWC = (function (exports) {
372
372
  ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
373
373
  ENABLE_FROZEN_TEMPLATE: null,
374
374
  DISABLE_ARIA_REFLECTION_POLYFILL: null,
375
+ ENABLE_PROGRAMMATIC_STYLESHEETS: null,
375
376
  };
376
377
  if (!_globalThis.lwcRuntimeFlags) {
377
378
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
@@ -425,7 +426,7 @@ var LWC = (function (exports) {
425
426
  setFeatureFlag(name, value);
426
427
  }
427
428
  }
428
- /** version: 2.33.0 */
429
+ /** version: 2.34.0 */
429
430
 
430
431
  /**
431
432
  * Copyright (C) 2018 salesforce.com, inc.
@@ -489,7 +490,7 @@ var LWC = (function (exports) {
489
490
  }
490
491
  }
491
492
  }
492
- /** version: 2.33.0 */
493
+ /** version: 2.34.0 */
493
494
 
494
495
  /*
495
496
  * Copyright (c) 2018, salesforce.com, inc.
@@ -818,6 +819,7 @@ var LWC = (function (exports) {
818
819
  if (!isUndefined$1(vm)) {
819
820
  msg = `${msg}\n${getComponentStack(vm)}`;
820
821
  }
822
+ // In Jest tests, reduce the warning and error verbosity by not printing the callstack
821
823
  if (process.env.NODE_ENV === 'test') {
822
824
  /* eslint-disable-next-line no-console */
823
825
  console[method](msg);
@@ -887,6 +889,9 @@ var LWC = (function (exports) {
887
889
  // Global HTML Attributes & Properties
888
890
  // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
889
891
  // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
892
+ //
893
+ // If you update this list, check for test files that recapitulate the same list. Searching the codebase
894
+ // for e.g. "dropzone" should suffice.
890
895
  const globalHTMLProperties = assign(create(null), {
891
896
  accessKey: {
892
897
  attribute: 'accesskey',
@@ -3479,6 +3484,9 @@ var LWC = (function (exports) {
3479
3484
  stylesheets: newStylesheets,
3480
3485
  stylesheetToken: newStylesheetToken
3481
3486
  } = template;
3487
+ const {
3488
+ stylesheets: newVmStylesheets
3489
+ } = vm;
3482
3490
  const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
3483
3491
  const {
3484
3492
  hasScopedStyles
@@ -3502,7 +3510,9 @@ var LWC = (function (exports) {
3502
3510
  }
3503
3511
  // Apply the new template styling token to the host element, if the new template has any
3504
3512
  // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
3505
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
3513
+ const hasNewStylesheets = hasStyles(newStylesheets);
3514
+ const hasNewVmStylesheets = hasStyles(newVmStylesheets);
3515
+ if (hasNewStylesheets || hasNewVmStylesheets) {
3506
3516
  newToken = newStylesheetToken;
3507
3517
  }
3508
3518
  // Set the new styling token on the host element
@@ -3574,10 +3584,17 @@ var LWC = (function (exports) {
3574
3584
  stylesheets,
3575
3585
  stylesheetToken
3576
3586
  } = template;
3587
+ const {
3588
+ stylesheets: vmStylesheets
3589
+ } = vm;
3577
3590
  let content = [];
3578
- if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
3591
+ if (hasStyles(stylesheets)) {
3579
3592
  content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
3580
3593
  }
3594
+ // VM (component) stylesheets apply after template stylesheets
3595
+ if (hasStyles(vmStylesheets)) {
3596
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
3597
+ }
3581
3598
  return content;
3582
3599
  }
3583
3600
  // It might be worth caching this to avoid doing the lookup repeatedly, but
@@ -3615,10 +3632,13 @@ var LWC = (function (exports) {
3615
3632
  const {
3616
3633
  template
3617
3634
  } = getComponentInternalDef(vnode.ctor);
3635
+ const {
3636
+ vm
3637
+ } = vnode;
3618
3638
  const {
3619
3639
  stylesheetToken
3620
3640
  } = template;
3621
- return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template) ? makeHostToken(stylesheetToken) : null;
3641
+ return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template, vm) ? makeHostToken(stylesheetToken) : null;
3622
3642
  }
3623
3643
  function getNearestNativeShadowComponent(vm) {
3624
3644
  const owner = getNearestShadowComponent(vm);
@@ -4231,6 +4251,28 @@ var LWC = (function (exports) {
4231
4251
  // in fallback mode, the allocation will always set children to
4232
4252
  // empty and delegate the real allocation to the slot elements
4233
4253
  allocateChildren(n2, vm);
4254
+ // Solves an edge case with slotted VFragments in native shadow mode.
4255
+ //
4256
+ // During allocation, in native shadow, slotted VFragment nodes are flattened and their text delimiters are removed
4257
+ // to avoid interfering with native slot behavior. When this happens, if any of the fragments
4258
+ // were not stable, the children must go through the dynamic diffing algo.
4259
+ //
4260
+ // If the new children (n2.children) contain no VFragments, but the previous children (n1.children) were dynamic,
4261
+ // the new nodes must be marked dynamic so that all nodes are properly updated. The only indicator that the new
4262
+ // nodes need to be dynamic comes from the previous children, so we check that to determine whether we need to
4263
+ // mark the new children dynamic.
4264
+ //
4265
+ // Example:
4266
+ // n1.children: [div, VFragment('', div, null, ''), div] => [div, div, null, div]; // marked dynamic
4267
+ // n2.children: [div, null, div] => [div, null, div] // marked ???
4268
+ const {
4269
+ shadowMode,
4270
+ renderMode
4271
+ } = vm;
4272
+ if (shadowMode == 0 /* ShadowMode.Native */ && renderMode !== 0 /* RenderMode.Light */ && hasDynamicChildren(n1.children)) {
4273
+ // No-op if children has already been marked dynamic by 'allocateChildren()'.
4274
+ markAsDynamicChildren(n2.children);
4275
+ }
4234
4276
  }
4235
4277
  // in fallback mode, the children will be always empty, so, nothing
4236
4278
  // will happen, but in native, it does allocate the light dom
@@ -4423,7 +4465,6 @@ var LWC = (function (exports) {
4423
4465
  //
4424
4466
  // In case #2, we will always get a fresh VCustomElement.
4425
4467
  const children = vnode.aChildren || vnode.children;
4426
- vm.aChildren = children;
4427
4468
  const {
4428
4469
  renderMode,
4429
4470
  shadowMode
@@ -4436,15 +4477,61 @@ var LWC = (function (exports) {
4436
4477
  logError(`Invalid usage of 'lwc:slot-data' on ${getComponentTag(vm)} tag. Scoped slot content can only be passed to a light dom child.`);
4437
4478
  }
4438
4479
  }
4480
+ // If any of the children being allocated are VFragments, we remove the text delimiters and flatten all immediate
4481
+ // children VFragments to avoid them interfering with default slot behavior.
4482
+ const allocatedChildren = flattenFragmentsInChildren(children);
4483
+ vnode.children = allocatedChildren;
4484
+ vm.aChildren = allocatedChildren;
4439
4485
  if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
4440
4486
  // slow path
4441
- allocateInSlot(vm, children, vnode.owner);
4487
+ allocateInSlot(vm, allocatedChildren, vnode.owner);
4442
4488
  // save the allocated children in case this vnode is reused.
4443
- vnode.aChildren = children;
4489
+ vnode.aChildren = allocatedChildren;
4444
4490
  // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
4445
4491
  vnode.children = EmptyArray;
4446
4492
  }
4447
4493
  }
4494
+ /**
4495
+ * Flattens the contents of all VFragments in an array of VNodes, removes the text delimiters on those VFragments, and
4496
+ * marks the resulting children array as dynamic. Uses a stack (array) to iteratively traverse the nested VFragments
4497
+ * and avoid the perf overhead of creating/destroying throwaway arrays/objects in a recursive approach.
4498
+ *
4499
+ * With the delimiters removed, the contents are marked dynamic so they are diffed correctly.
4500
+ *
4501
+ * This function is used for slotted VFragments to avoid the text delimiters interfering with slotting functionality.
4502
+ */
4503
+ function flattenFragmentsInChildren(children) {
4504
+ const flattenedChildren = [];
4505
+ // Initialize our stack with the direct children of the custom component and check whether we have a VFragment.
4506
+ // If no VFragment is found in children, we don't need to traverse anything or mark the children dynamic and can return early.
4507
+ const nodeStack = [];
4508
+ let fragmentFound = false;
4509
+ for (let i = children.length - 1; i > -1; i -= 1) {
4510
+ const child = children[i];
4511
+ ArrayPush$1.call(nodeStack, child);
4512
+ fragmentFound = fragmentFound || !!(child && isVFragment(child));
4513
+ }
4514
+ if (!fragmentFound) {
4515
+ return children;
4516
+ }
4517
+ let currentNode;
4518
+ while (!isUndefined$1(currentNode = ArrayPop.call(nodeStack))) {
4519
+ if (!isNull(currentNode) && isVFragment(currentNode)) {
4520
+ const fChildren = currentNode.children;
4521
+ // Ignore the start and end text node delimiters
4522
+ for (let i = fChildren.length - 2; i > 0; i -= 1) {
4523
+ ArrayPush$1.call(nodeStack, fChildren[i]);
4524
+ }
4525
+ } else {
4526
+ ArrayPush$1.call(flattenedChildren, currentNode);
4527
+ }
4528
+ }
4529
+ // We always mark the children as dynamic because nothing generates stable VFragments yet.
4530
+ // If/when stable VFragments are generated by the compiler, this code should be updated to
4531
+ // not mark dynamic if all flattened VFragments were stable.
4532
+ markAsDynamicChildren(flattenedChildren);
4533
+ return flattenedChildren;
4534
+ }
4448
4535
  function createViewModelHook(elm, vnode, renderer) {
4449
4536
  let vm = getAssociatedVMIfPresent(elm);
4450
4537
  // There is a possibility that a custom element is registered under tagName, in which case, the
@@ -4469,22 +4556,20 @@ var LWC = (function (exports) {
4469
4556
  }
4470
4557
  return vm;
4471
4558
  }
4472
- /**
4473
- * Collects all slots into a SlotSet, traversing through VFragment Nodes
4474
- */
4475
- function collectSlots(vm, children, cmpSlotsMapping) {
4559
+ function allocateInSlot(vm, children, owner) {
4476
4560
  var _a, _b;
4561
+ const {
4562
+ cmpSlots: {
4563
+ slotAssignments: oldSlotsMapping
4564
+ }
4565
+ } = vm;
4566
+ const cmpSlotsMapping = create(null);
4567
+ // Collect all slots into cmpSlotsMapping
4477
4568
  for (let i = 0, len = children.length; i < len; i += 1) {
4478
4569
  const vnode = children[i];
4479
4570
  if (isNull(vnode)) {
4480
4571
  continue;
4481
4572
  }
4482
- // Dive further iff the content is wrapped in a VFragment
4483
- if (isVFragment(vnode)) {
4484
- // Remove the text delimiter nodes to avoid overriding default slot content
4485
- collectSlots(vm, vnode.children.slice(1, -1), cmpSlotsMapping);
4486
- continue;
4487
- }
4488
4573
  let slotName = '';
4489
4574
  if (isVBaseElement(vnode)) {
4490
4575
  slotName = (_b = (_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : '';
@@ -4494,15 +4579,6 @@ var LWC = (function (exports) {
4494
4579
  const vnodes = cmpSlotsMapping[slotName] = cmpSlotsMapping[slotName] || [];
4495
4580
  ArrayPush$1.call(vnodes, vnode);
4496
4581
  }
4497
- }
4498
- function allocateInSlot(vm, children, owner) {
4499
- const {
4500
- cmpSlots: {
4501
- slotAssignments: oldSlotsMapping
4502
- }
4503
- } = vm;
4504
- const cmpSlotsMapping = create(null);
4505
- collectSlots(vm, children, cmpSlotsMapping);
4506
4582
  vm.cmpSlots = {
4507
4583
  owner,
4508
4584
  slotAssignments: cmpSlotsMapping
@@ -4533,14 +4609,14 @@ var LWC = (function (exports) {
4533
4609
  }
4534
4610
  }
4535
4611
  // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
4536
- const FromIteration = new WeakMap();
4537
- // dynamic children means it was generated by an iteration
4538
- // in a template, and will require a more complex diffing algo.
4612
+ const DynamicChildren = new WeakMap();
4613
+ // dynamic children means it was either generated by an iteration in a template
4614
+ // or part of an unstable fragment, and will require a more complex diffing algo.
4539
4615
  function markAsDynamicChildren(children) {
4540
- FromIteration.set(children, 1);
4616
+ DynamicChildren.set(children, 1);
4541
4617
  }
4542
4618
  function hasDynamicChildren(children) {
4543
- return FromIteration.has(children);
4619
+ return DynamicChildren.has(children);
4544
4620
  }
4545
4621
  function createKeyToOldIdx(children, beginIdx, endIdx) {
4546
4622
  const map = {};
@@ -5406,7 +5482,7 @@ var LWC = (function (exports) {
5406
5482
  // Create a brand new template cache for the swapped templated.
5407
5483
  context.tplCache = create(null);
5408
5484
  // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
5409
- context.hasScopedStyles = computeHasScopedStyles(html);
5485
+ context.hasScopedStyles = computeHasScopedStyles(html, vm);
5410
5486
  // Update the scoping token on the host element.
5411
5487
  updateStylesheetToken(vm, html);
5412
5488
  // Evaluate, create stylesheet and cache the produced VNode for future
@@ -5449,9 +5525,8 @@ var LWC = (function (exports) {
5449
5525
  }
5450
5526
  return vnodes;
5451
5527
  }
5452
- function computeHasScopedStyles(template) {
5453
- const { stylesheets } = template;
5454
- if (!isUndefined$1(stylesheets)) {
5528
+ function computeHasScopedStylesInStylesheets(stylesheets) {
5529
+ if (hasStyles(stylesheets)) {
5455
5530
  for (let i = 0; i < stylesheets.length; i++) {
5456
5531
  if (isTrue(stylesheets[i][KEY__SCOPED_CSS])) {
5457
5532
  return true;
@@ -5460,6 +5535,15 @@ var LWC = (function (exports) {
5460
5535
  }
5461
5536
  return false;
5462
5537
  }
5538
+ function computeHasScopedStyles(template, vm) {
5539
+ const { stylesheets } = template;
5540
+ const vmStylesheets = !isUndefined$1(vm) ? vm.stylesheets : null;
5541
+ return (computeHasScopedStylesInStylesheets(stylesheets) ||
5542
+ computeHasScopedStylesInStylesheets(vmStylesheets));
5543
+ }
5544
+ function hasStyles(stylesheets) {
5545
+ return !isUndefined$1(stylesheets) && !isNull(stylesheets) && stylesheets.length > 0;
5546
+ }
5463
5547
 
5464
5548
  /*
5465
5549
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5775,6 +5859,7 @@ var LWC = (function (exports) {
5775
5859
  // Properties set right after VM creation.
5776
5860
  tro: null,
5777
5861
  shadowMode: null,
5862
+ stylesheets: null,
5778
5863
  // Properties set by the LightningElement constructor.
5779
5864
  component: null,
5780
5865
  shadowRoot: null,
@@ -5787,6 +5872,7 @@ var LWC = (function (exports) {
5787
5872
  if (process.env.NODE_ENV !== 'production') {
5788
5873
  vm.debugInfo = create(null);
5789
5874
  }
5875
+ vm.stylesheets = computeStylesheets(vm, def.ctor);
5790
5876
  vm.shadowMode = computeShadowMode(vm, renderer);
5791
5877
  vm.tro = getTemplateReactiveObserver(vm);
5792
5878
  if (process.env.NODE_ENV !== 'production') {
@@ -5805,6 +5891,42 @@ var LWC = (function (exports) {
5805
5891
  }
5806
5892
  return vm;
5807
5893
  }
5894
+ function validateComponentStylesheets(vm, stylesheets) {
5895
+ let valid = true;
5896
+ const validate = arrayOrStylesheet => {
5897
+ if (isArray$1(arrayOrStylesheet)) {
5898
+ for (let i = 0; i < arrayOrStylesheet.length; i++) {
5899
+ validate(arrayOrStylesheet[i]);
5900
+ }
5901
+ } else if (!isFunction$1(arrayOrStylesheet)) {
5902
+ // function assumed to be a stylesheet factory
5903
+ valid = false;
5904
+ }
5905
+ };
5906
+ if (!isArray$1(stylesheets)) {
5907
+ valid = false;
5908
+ } else {
5909
+ validate(stylesheets);
5910
+ }
5911
+ return valid;
5912
+ }
5913
+ // Validate and flatten any stylesheets defined as `static stylesheets`
5914
+ function computeStylesheets(vm, ctor) {
5915
+ if (lwcRuntimeFlags.ENABLE_PROGRAMMATIC_STYLESHEETS) {
5916
+ const {
5917
+ stylesheets
5918
+ } = ctor;
5919
+ if (!isUndefined$1(stylesheets)) {
5920
+ const valid = validateComponentStylesheets(vm, stylesheets);
5921
+ if (valid) {
5922
+ return flattenStylesheets(stylesheets);
5923
+ } else if (process.env.NODE_ENV !== 'production') {
5924
+ logError(`static stylesheets must be an array of CSS stylesheets. Found invalid stylesheets on <${vm.tagName}>`, vm);
5925
+ }
5926
+ }
5927
+ }
5928
+ return null;
5929
+ }
5808
5930
  function computeShadowMode(vm, renderer) {
5809
5931
  const {
5810
5932
  def
@@ -7123,7 +7245,7 @@ var LWC = (function (exports) {
7123
7245
  }
7124
7246
  return ctor;
7125
7247
  }
7126
- /* version: 2.33.0 */
7248
+ /* version: 2.34.0 */
7127
7249
 
7128
7250
  /*
7129
7251
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7230,7 +7352,9 @@ var LWC = (function (exports) {
7230
7352
  //
7231
7353
  // Test utilities
7232
7354
  //
7233
- if (process.env.NODE_ENV === 'development') {
7355
+ // Only used in LWC's Karma tests
7356
+ // @ts-ignore
7357
+ if (process.env.NODE_ENV !== 'production' && typeof __karma__ !== 'undefined') {
7234
7358
  // @ts-ignore
7235
7359
  window.__lwcResetGlobalStylesheets = () => {
7236
7360
  stylesheetCache.clear();
@@ -8096,7 +8220,7 @@ var LWC = (function (exports) {
8096
8220
  function isNull(obj) {
8097
8221
  return obj === null;
8098
8222
  }
8099
- /** version: 2.33.0 */
8223
+ /** version: 2.34.0 */
8100
8224
 
8101
8225
  /*
8102
8226
  * Copyright (c) 2018, salesforce.com, inc.
@@ -8657,7 +8781,7 @@ var LWC = (function (exports) {
8657
8781
  });
8658
8782
  freeze(LightningElement);
8659
8783
  seal(LightningElement.prototype);
8660
- /* version: 2.33.0 */
8784
+ /* version: 2.34.0 */
8661
8785
 
8662
8786
  exports.LightningElement = LightningElement;
8663
8787
  exports.__unstable__ProfilerControl = profilerControl;