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
@@ -336,7 +336,7 @@ var LWC = (function (exports) {
336
336
  CACHED_ATTRIBUTE_PROPERTY_MAPPING.set(attrName, propertyName);
337
337
  return propertyName;
338
338
  }
339
- /** version: 2.33.0 */
339
+ /** version: 2.34.0 */
340
340
 
341
341
  /**
342
342
  * Copyright (C) 2018 salesforce.com, inc.
@@ -359,6 +359,7 @@ var LWC = (function (exports) {
359
359
  ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
360
360
  ENABLE_FROZEN_TEMPLATE: null,
361
361
  DISABLE_ARIA_REFLECTION_POLYFILL: null,
362
+ ENABLE_PROGRAMMATIC_STYLESHEETS: null,
362
363
  };
363
364
  if (!_globalThis.lwcRuntimeFlags) {
364
365
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
@@ -402,7 +403,7 @@ var LWC = (function (exports) {
402
403
  */
403
404
  function setFeatureFlagForTest(name, value) {
404
405
  }
405
- /** version: 2.33.0 */
406
+ /** version: 2.34.0 */
406
407
 
407
408
  /**
408
409
  * Copyright (C) 2018 salesforce.com, inc.
@@ -466,7 +467,7 @@ var LWC = (function (exports) {
466
467
  }
467
468
  }
468
469
  }
469
- /** version: 2.33.0 */
470
+ /** version: 2.34.0 */
470
471
 
471
472
  /*
472
473
  * Copyright (c) 2018, salesforce.com, inc.
@@ -538,6 +539,18 @@ var LWC = (function (exports) {
538
539
  }
539
540
  return result;
540
541
  }
542
+ function flattenStylesheets(stylesheets) {
543
+ const list = [];
544
+ for (const stylesheet of stylesheets) {
545
+ if (!Array.isArray(stylesheet)) {
546
+ list.push(stylesheet);
547
+ }
548
+ else {
549
+ list.push(...flattenStylesheets(stylesheet));
550
+ }
551
+ }
552
+ return list;
553
+ }
541
554
  // Set a ref (lwc:ref) on a VM, from a template API
542
555
  function setRefVNode(vm, ref, vnode) {
543
556
  // If this method is called, then vm.refVNodes is set as the template has refs.
@@ -783,6 +796,9 @@ var LWC = (function (exports) {
783
796
  // Global HTML Attributes & Properties
784
797
  // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
785
798
  // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
799
+ //
800
+ // If you update this list, check for test files that recapitulate the same list. Searching the codebase
801
+ // for e.g. "dropzone" should suffice.
786
802
  assign(create(null), {
787
803
  accessKey: {
788
804
  attribute: 'accesskey',
@@ -2444,6 +2460,9 @@ var LWC = (function (exports) {
2444
2460
  stylesheets: newStylesheets,
2445
2461
  stylesheetToken: newStylesheetToken
2446
2462
  } = template;
2463
+ const {
2464
+ stylesheets: newVmStylesheets
2465
+ } = vm;
2447
2466
  const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
2448
2467
  const {
2449
2468
  hasScopedStyles
@@ -2467,7 +2486,9 @@ var LWC = (function (exports) {
2467
2486
  }
2468
2487
  // Apply the new template styling token to the host element, if the new template has any
2469
2488
  // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
2470
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
2489
+ const hasNewStylesheets = hasStyles(newStylesheets);
2490
+ const hasNewVmStylesheets = hasStyles(newVmStylesheets);
2491
+ if (hasNewStylesheets || hasNewVmStylesheets) {
2471
2492
  newToken = newStylesheetToken;
2472
2493
  }
2473
2494
  // Set the new styling token on the host element
@@ -2531,10 +2552,17 @@ var LWC = (function (exports) {
2531
2552
  stylesheets,
2532
2553
  stylesheetToken
2533
2554
  } = template;
2555
+ const {
2556
+ stylesheets: vmStylesheets
2557
+ } = vm;
2534
2558
  let content = [];
2535
- if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
2559
+ if (hasStyles(stylesheets)) {
2536
2560
  content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
2537
2561
  }
2562
+ // VM (component) stylesheets apply after template stylesheets
2563
+ if (hasStyles(vmStylesheets)) {
2564
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
2565
+ }
2538
2566
  return content;
2539
2567
  }
2540
2568
  // It might be worth caching this to avoid doing the lookup repeatedly, but
@@ -2572,10 +2600,13 @@ var LWC = (function (exports) {
2572
2600
  const {
2573
2601
  template
2574
2602
  } = getComponentInternalDef(vnode.ctor);
2603
+ const {
2604
+ vm
2605
+ } = vnode;
2575
2606
  const {
2576
2607
  stylesheetToken
2577
2608
  } = template;
2578
- return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template) ? makeHostToken(stylesheetToken) : null;
2609
+ return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template, vm) ? makeHostToken(stylesheetToken) : null;
2579
2610
  }
2580
2611
  function getNearestNativeShadowComponent(vm) {
2581
2612
  const owner = getNearestShadowComponent(vm);
@@ -3158,6 +3189,28 @@ var LWC = (function (exports) {
3158
3189
  // in fallback mode, the allocation will always set children to
3159
3190
  // empty and delegate the real allocation to the slot elements
3160
3191
  allocateChildren(n2, vm);
3192
+ // Solves an edge case with slotted VFragments in native shadow mode.
3193
+ //
3194
+ // During allocation, in native shadow, slotted VFragment nodes are flattened and their text delimiters are removed
3195
+ // to avoid interfering with native slot behavior. When this happens, if any of the fragments
3196
+ // were not stable, the children must go through the dynamic diffing algo.
3197
+ //
3198
+ // If the new children (n2.children) contain no VFragments, but the previous children (n1.children) were dynamic,
3199
+ // the new nodes must be marked dynamic so that all nodes are properly updated. The only indicator that the new
3200
+ // nodes need to be dynamic comes from the previous children, so we check that to determine whether we need to
3201
+ // mark the new children dynamic.
3202
+ //
3203
+ // Example:
3204
+ // n1.children: [div, VFragment('', div, null, ''), div] => [div, div, null, div]; // marked dynamic
3205
+ // n2.children: [div, null, div] => [div, null, div] // marked ???
3206
+ const {
3207
+ shadowMode,
3208
+ renderMode
3209
+ } = vm;
3210
+ if (shadowMode == 0 /* ShadowMode.Native */ && renderMode !== 0 /* RenderMode.Light */ && hasDynamicChildren(n1.children)) {
3211
+ // No-op if children has already been marked dynamic by 'allocateChildren()'.
3212
+ markAsDynamicChildren(n2.children);
3213
+ }
3161
3214
  }
3162
3215
  // in fallback mode, the children will be always empty, so, nothing
3163
3216
  // will happen, but in native, it does allocate the light dom
@@ -3319,20 +3372,65 @@ var LWC = (function (exports) {
3319
3372
  //
3320
3373
  // In case #2, we will always get a fresh VCustomElement.
3321
3374
  const children = vnode.aChildren || vnode.children;
3322
- vm.aChildren = children;
3323
3375
  const {
3324
3376
  renderMode,
3325
3377
  shadowMode
3326
3378
  } = vm;
3379
+ // If any of the children being allocated are VFragments, we remove the text delimiters and flatten all immediate
3380
+ // children VFragments to avoid them interfering with default slot behavior.
3381
+ const allocatedChildren = flattenFragmentsInChildren(children);
3382
+ vnode.children = allocatedChildren;
3383
+ vm.aChildren = allocatedChildren;
3327
3384
  if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
3328
3385
  // slow path
3329
- allocateInSlot(vm, children, vnode.owner);
3386
+ allocateInSlot(vm, allocatedChildren, vnode.owner);
3330
3387
  // save the allocated children in case this vnode is reused.
3331
- vnode.aChildren = children;
3388
+ vnode.aChildren = allocatedChildren;
3332
3389
  // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
3333
3390
  vnode.children = EmptyArray;
3334
3391
  }
3335
3392
  }
3393
+ /**
3394
+ * Flattens the contents of all VFragments in an array of VNodes, removes the text delimiters on those VFragments, and
3395
+ * marks the resulting children array as dynamic. Uses a stack (array) to iteratively traverse the nested VFragments
3396
+ * and avoid the perf overhead of creating/destroying throwaway arrays/objects in a recursive approach.
3397
+ *
3398
+ * With the delimiters removed, the contents are marked dynamic so they are diffed correctly.
3399
+ *
3400
+ * This function is used for slotted VFragments to avoid the text delimiters interfering with slotting functionality.
3401
+ */
3402
+ function flattenFragmentsInChildren(children) {
3403
+ const flattenedChildren = [];
3404
+ // Initialize our stack with the direct children of the custom component and check whether we have a VFragment.
3405
+ // If no VFragment is found in children, we don't need to traverse anything or mark the children dynamic and can return early.
3406
+ const nodeStack = [];
3407
+ let fragmentFound = false;
3408
+ for (let i = children.length - 1; i > -1; i -= 1) {
3409
+ const child = children[i];
3410
+ ArrayPush$1.call(nodeStack, child);
3411
+ fragmentFound = fragmentFound || !!(child && isVFragment(child));
3412
+ }
3413
+ if (!fragmentFound) {
3414
+ return children;
3415
+ }
3416
+ let currentNode;
3417
+ while (!isUndefined$1(currentNode = ArrayPop.call(nodeStack))) {
3418
+ if (!isNull(currentNode) && isVFragment(currentNode)) {
3419
+ const fChildren = currentNode.children;
3420
+ // Ignore the start and end text node delimiters
3421
+ for (let i = fChildren.length - 2; i > 0; i -= 1) {
3422
+ ArrayPush$1.call(nodeStack, fChildren[i]);
3423
+ }
3424
+ } else {
3425
+ ArrayPush$1.call(flattenedChildren, currentNode);
3426
+ }
3427
+ }
3428
+ // We always mark the children as dynamic because nothing generates stable VFragments yet.
3429
+ // If/when stable VFragments are generated by the compiler, this code should be updated to
3430
+ // not mark dynamic if all flattened VFragments were stable.
3431
+ markAsDynamicChildren(flattenedChildren);
3432
+ return flattenedChildren;
3433
+ }
3336
3434
  function createViewModelHook(elm, vnode, renderer) {
3337
3435
  let vm = getAssociatedVMIfPresent(elm);
3338
3436
  // There is a possibility that a custom element is registered under tagName, in which case, the
@@ -3354,22 +3452,20 @@ var LWC = (function (exports) {
3354
3452
  });
3355
3453
  return vm;
3356
3454
  }
3357
- /**
3358
- * Collects all slots into a SlotSet, traversing through VFragment Nodes
3359
- */
3360
- function collectSlots(vm, children, cmpSlotsMapping) {
3455
+ function allocateInSlot(vm, children, owner) {
3361
3456
  var _a, _b;
3457
+ const {
3458
+ cmpSlots: {
3459
+ slotAssignments: oldSlotsMapping
3460
+ }
3461
+ } = vm;
3462
+ const cmpSlotsMapping = create(null);
3463
+ // Collect all slots into cmpSlotsMapping
3362
3464
  for (let i = 0, len = children.length; i < len; i += 1) {
3363
3465
  const vnode = children[i];
3364
3466
  if (isNull(vnode)) {
3365
3467
  continue;
3366
3468
  }
3367
- // Dive further iff the content is wrapped in a VFragment
3368
- if (isVFragment(vnode)) {
3369
- // Remove the text delimiter nodes to avoid overriding default slot content
3370
- collectSlots(vm, vnode.children.slice(1, -1), cmpSlotsMapping);
3371
- continue;
3372
- }
3373
3469
  let slotName = '';
3374
3470
  if (isVBaseElement(vnode)) {
3375
3471
  slotName = (_b = (_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : '';
@@ -3379,15 +3475,6 @@ var LWC = (function (exports) {
3379
3475
  const vnodes = cmpSlotsMapping[slotName] = cmpSlotsMapping[slotName] || [];
3380
3476
  ArrayPush$1.call(vnodes, vnode);
3381
3477
  }
3382
- }
3383
- function allocateInSlot(vm, children, owner) {
3384
- const {
3385
- cmpSlots: {
3386
- slotAssignments: oldSlotsMapping
3387
- }
3388
- } = vm;
3389
- const cmpSlotsMapping = create(null);
3390
- collectSlots(vm, children, cmpSlotsMapping);
3391
3478
  vm.cmpSlots = {
3392
3479
  owner,
3393
3480
  slotAssignments: cmpSlotsMapping
@@ -3418,14 +3505,14 @@ var LWC = (function (exports) {
3418
3505
  }
3419
3506
  }
3420
3507
  // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
3421
- const FromIteration = new WeakMap();
3422
- // dynamic children means it was generated by an iteration
3423
- // in a template, and will require a more complex diffing algo.
3508
+ const DynamicChildren = new WeakMap();
3509
+ // dynamic children means it was either generated by an iteration in a template
3510
+ // or part of an unstable fragment, and will require a more complex diffing algo.
3424
3511
  function markAsDynamicChildren(children) {
3425
- FromIteration.set(children, 1);
3512
+ DynamicChildren.set(children, 1);
3426
3513
  }
3427
3514
  function hasDynamicChildren(children) {
3428
- return FromIteration.has(children);
3515
+ return DynamicChildren.has(children);
3429
3516
  }
3430
3517
  function createKeyToOldIdx(children, beginIdx, endIdx) {
3431
3518
  const map = {};
@@ -4084,7 +4171,7 @@ var LWC = (function (exports) {
4084
4171
  // Create a brand new template cache for the swapped templated.
4085
4172
  context.tplCache = create(null);
4086
4173
  // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
4087
- context.hasScopedStyles = computeHasScopedStyles(html);
4174
+ context.hasScopedStyles = computeHasScopedStyles(html, vm);
4088
4175
  // Update the scoping token on the host element.
4089
4176
  updateStylesheetToken(vm, html);
4090
4177
  // Evaluate, create stylesheet and cache the produced VNode for future
@@ -4119,9 +4206,8 @@ var LWC = (function (exports) {
4119
4206
  });
4120
4207
  return vnodes;
4121
4208
  }
4122
- function computeHasScopedStyles(template) {
4123
- const { stylesheets } = template;
4124
- if (!isUndefined$1(stylesheets)) {
4209
+ function computeHasScopedStylesInStylesheets(stylesheets) {
4210
+ if (hasStyles(stylesheets)) {
4125
4211
  for (let i = 0; i < stylesheets.length; i++) {
4126
4212
  if (isTrue(stylesheets[i][KEY__SCOPED_CSS])) {
4127
4213
  return true;
@@ -4130,6 +4216,15 @@ var LWC = (function (exports) {
4130
4216
  }
4131
4217
  return false;
4132
4218
  }
4219
+ function computeHasScopedStyles(template, vm) {
4220
+ const { stylesheets } = template;
4221
+ const vmStylesheets = !isUndefined$1(vm) ? vm.stylesheets : null;
4222
+ return (computeHasScopedStylesInStylesheets(stylesheets) ||
4223
+ computeHasScopedStylesInStylesheets(vmStylesheets));
4224
+ }
4225
+ function hasStyles(stylesheets) {
4226
+ return !isUndefined$1(stylesheets) && !isNull(stylesheets) && stylesheets.length > 0;
4227
+ }
4133
4228
  let vmBeingConstructed = null;
4134
4229
  function isBeingConstructed(vm) {
4135
4230
  return vmBeingConstructed === vm;
@@ -4406,6 +4501,7 @@ var LWC = (function (exports) {
4406
4501
  // Properties set right after VM creation.
4407
4502
  tro: null,
4408
4503
  shadowMode: null,
4504
+ stylesheets: null,
4409
4505
  // Properties set by the LightningElement constructor.
4410
4506
  component: null,
4411
4507
  shadowRoot: null,
@@ -4415,6 +4511,7 @@ var LWC = (function (exports) {
4415
4511
  getHook,
4416
4512
  renderer
4417
4513
  };
4514
+ vm.stylesheets = computeStylesheets(vm, def.ctor);
4418
4515
  vm.shadowMode = computeShadowMode(vm, renderer);
4419
4516
  vm.tro = getTemplateReactiveObserver(vm);
4420
4517
  // Create component instance associated to the vm and the element.
@@ -4425,6 +4522,40 @@ var LWC = (function (exports) {
4425
4522
  }
4426
4523
  return vm;
4427
4524
  }
4525
+ function validateComponentStylesheets(vm, stylesheets) {
4526
+ let valid = true;
4527
+ const validate = arrayOrStylesheet => {
4528
+ if (isArray$1(arrayOrStylesheet)) {
4529
+ for (let i = 0; i < arrayOrStylesheet.length; i++) {
4530
+ validate(arrayOrStylesheet[i]);
4531
+ }
4532
+ } else if (!isFunction$1(arrayOrStylesheet)) {
4533
+ // function assumed to be a stylesheet factory
4534
+ valid = false;
4535
+ }
4536
+ };
4537
+ if (!isArray$1(stylesheets)) {
4538
+ valid = false;
4539
+ } else {
4540
+ validate(stylesheets);
4541
+ }
4542
+ return valid;
4543
+ }
4544
+ // Validate and flatten any stylesheets defined as `static stylesheets`
4545
+ function computeStylesheets(vm, ctor) {
4546
+ if (lwcRuntimeFlags.ENABLE_PROGRAMMATIC_STYLESHEETS) {
4547
+ const {
4548
+ stylesheets
4549
+ } = ctor;
4550
+ if (!isUndefined$1(stylesheets)) {
4551
+ const valid = validateComponentStylesheets(vm, stylesheets);
4552
+ if (valid) {
4553
+ return flattenStylesheets(stylesheets);
4554
+ }
4555
+ }
4556
+ }
4557
+ return null;
4558
+ }
4428
4559
  function computeShadowMode(vm, renderer) {
4429
4560
  const {
4430
4561
  def
@@ -6380,7 +6511,7 @@ var LWC = (function (exports) {
6380
6511
  function isNull(obj) {
6381
6512
  return obj === null;
6382
6513
  }
6383
- /** version: 2.33.0 */
6514
+ /** version: 2.34.0 */
6384
6515
 
6385
6516
  /*
6386
6517
  * Copyright (c) 2018, salesforce.com, inc.
@@ -6933,7 +7064,7 @@ var LWC = (function (exports) {
6933
7064
  });
6934
7065
  freeze(LightningElement);
6935
7066
  seal(LightningElement.prototype);
6936
- /* version: 2.33.0 */
7067
+ /* version: 2.34.0 */
6937
7068
 
6938
7069
  exports.LightningElement = LightningElement;
6939
7070
  exports.__unstable__ProfilerControl = profilerControl;