lwc 2.13.1 → 2.13.4

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 (43) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +376 -170
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +376 -169
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -2
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +222 -164
  5. package/dist/engine-dom/iife/es5/engine-dom.js +7562 -5758
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +5947 -4586
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +376 -169
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -2
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +222 -164
  11. package/dist/engine-dom/umd/es5/engine-dom.js +7562 -5758
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +5947 -4586
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +190 -72
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +190 -73
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +29 -4
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +29 -4
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +10 -13
  20. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +4 -4
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +4601 -3603
  22. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js +10 -1
  23. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +4424 -3481
  24. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +29 -4
  25. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +10 -13
  26. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +4 -4
  27. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +4601 -3603
  28. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js +10 -1
  29. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +4424 -3481
  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.min.js +1 -1
  33. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  34. package/dist/wire-service/iife/es5/wire-service.js +243 -258
  35. package/dist/wire-service/iife/es5/wire-service.min.js +1 -1
  36. package/dist/wire-service/iife/es5/wire-service_debug.js +243 -258
  37. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  38. package/dist/wire-service/umd/es2017/wire-service.min.js +1 -1
  39. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  40. package/dist/wire-service/umd/es5/wire-service.js +243 -258
  41. package/dist/wire-service/umd/es5/wire-service.min.js +1 -1
  42. package/dist/wire-service/umd/es5/wire-service_debug.js +243 -258
  43. package/package.json +7 -7
@@ -46,7 +46,7 @@ var LWC = (function (exports) {
46
46
  */
47
47
  const { assign, create, defineProperties, defineProperty, freeze, getOwnPropertyDescriptor: getOwnPropertyDescriptor$1, getOwnPropertyNames: getOwnPropertyNames$1, getPrototypeOf: getPrototypeOf$1, hasOwnProperty: hasOwnProperty$1, isFrozen, keys, seal, setPrototypeOf, } = Object;
48
48
  const { isArray: isArray$1 } = Array;
49
- const { filter: ArrayFilter, find: ArrayFind, indexOf: ArrayIndexOf, join: ArrayJoin, map: ArrayMap, push: ArrayPush$1, reduce: ArrayReduce, reverse: ArrayReverse, slice: ArraySlice, splice: ArraySplice, unshift: ArrayUnshift, forEach, } = Array.prototype;
49
+ const { copyWithin: ArrayCopyWithin, fill: ArrayFill, filter: ArrayFilter, find: ArrayFind, indexOf: ArrayIndexOf, join: ArrayJoin, map: ArrayMap, pop: ArrayPop, push: ArrayPush$1, reduce: ArrayReduce, reverse: ArrayReverse, shift: ArrayShift, slice: ArraySlice, sort: ArraySort, splice: ArraySplice, unshift: ArrayUnshift, forEach, } = Array.prototype;
50
50
  const { fromCharCode: StringFromCharCode } = String;
51
51
  const { charCodeAt: StringCharCodeAt, replace: StringReplace, slice: StringSlice, toLowerCase: StringToLowerCase, } = String.prototype;
52
52
  function isUndefined$1(obj) {
@@ -301,9 +301,9 @@ var LWC = (function (exports) {
301
301
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
302
302
  */
303
303
  // Increment whenever the LWC template compiler changes
304
- const LWC_VERSION = "2.13.1";
304
+ const LWC_VERSION = "2.13.4";
305
305
  const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
306
- /** version: 2.13.1 */
306
+ /** version: 2.13.4 */
307
307
 
308
308
  /*
309
309
  * Copyright (c) 2018, salesforce.com, inc.
@@ -393,6 +393,7 @@ var LWC = (function (exports) {
393
393
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
394
394
  */
395
395
  const features = {
396
+ DUMMY_TEST_FLAG: null,
396
397
  ENABLE_ELEMENT_PATCH: null,
397
398
  ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST: null,
398
399
  ENABLE_HMR: null,
@@ -456,10 +457,35 @@ var LWC = (function (exports) {
456
457
  setFeatureFlag(name, value);
457
458
  }
458
459
  }
459
- /** version: 2.13.1 */
460
+ /** version: 2.13.4 */
460
461
 
461
462
  /* proxy-compat-disable */
462
463
 
464
+ /*
465
+ * Copyright (c) 2018, salesforce.com, inc.
466
+ * All rights reserved.
467
+ * SPDX-License-Identifier: MIT
468
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
469
+ */
470
+ // @ts-ignore
471
+
472
+ if (process.env.NODE_ENV !== 'production' && typeof __karma__ !== 'undefined') {
473
+ window.addEventListener('test-dummy-flag', () => {
474
+ let hasFlag = false;
475
+
476
+ if (runtimeFlags.DUMMY_TEST_FLAG) {
477
+ hasFlag = true;
478
+ }
479
+
480
+ window.dispatchEvent(new CustomEvent('has-dummy-flag', {
481
+ detail: {
482
+ package: '@lwc/engine-core',
483
+ hasFlag
484
+ }
485
+ }));
486
+ });
487
+ }
488
+
463
489
  /*
464
490
  * Copyright (c) 2018, salesforce.com, inc.
465
491
  * All rights reserved.
@@ -560,10 +586,6 @@ var LWC = (function (exports) {
560
586
  function setHTMLElement(HTMLElementImpl) {
561
587
  HTMLElementExported$1 = HTMLElementImpl;
562
588
  }
563
- let isHydrating$1;
564
- function setIsHydrating$1(isHydratingImpl) {
565
- isHydrating$1 = isHydratingImpl;
566
- }
567
589
  let insert$1;
568
590
  function setInsert(insertImpl) {
569
591
  insert$1 = insertImpl;
@@ -684,10 +706,6 @@ var LWC = (function (exports) {
684
706
  function setIsConnected(isConnectedImpl) {
685
707
  isConnected$1 = isConnectedImpl;
686
708
  }
687
- let insertGlobalStylesheet$1;
688
- function setInsertGlobalStylesheet(insertGlobalStylesheetImpl) {
689
- insertGlobalStylesheet$1 = insertGlobalStylesheetImpl;
690
- }
691
709
  let insertStylesheet$1;
692
710
  function setInsertStylesheet(insertStylesheetImpl) {
693
711
  insertStylesheet$1 = insertStylesheetImpl;
@@ -2775,6 +2793,12 @@ var LWC = (function (exports) {
2775
2793
  }
2776
2794
  }
2777
2795
 
2796
+ /*
2797
+ * Copyright (c) 2018, salesforce.com, inc.
2798
+ * All rights reserved.
2799
+ * SPDX-License-Identifier: MIT
2800
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2801
+ */
2778
2802
  const signedTemplateSet = new Set();
2779
2803
  function defaultEmptyTemplate() {
2780
2804
  return [];
@@ -2792,6 +2816,32 @@ var LWC = (function (exports) {
2792
2816
  checkVersionMismatch(tpl, 'template');
2793
2817
  }
2794
2818
  signedTemplateSet.add(tpl);
2819
+ // FIXME[@W-10950976]: the template object should be frozen, and it should not be possible to set
2820
+ // the stylesheets or stylesheetToken(s). For backwards compat, though, we shim stylesheetTokens
2821
+ // on top of stylesheetToken for anyone who is accessing the old internal API.
2822
+ // Details: https://salesforce.quip.com/v1rmAFu2cKAr
2823
+ defineProperty(tpl, 'stylesheetTokens', {
2824
+ enumerable: true,
2825
+ configurable: true,
2826
+ get() {
2827
+ const { stylesheetToken } = this;
2828
+ if (isUndefined$1(stylesheetToken)) {
2829
+ return stylesheetToken;
2830
+ }
2831
+ // Shim for the old `stylesheetTokens` property
2832
+ // See https://github.com/salesforce/lwc/pull/2332/files#diff-7901555acef29969adaa6583185b3e9bce475cdc6f23e799a54e0018cb18abaa
2833
+ return {
2834
+ hostAttribute: `${stylesheetToken}-host`,
2835
+ shadowAttribute: stylesheetToken,
2836
+ };
2837
+ },
2838
+ set(value) {
2839
+ // If the value is null or some other exotic object, you would be broken anyway in the past
2840
+ // because the engine would try to access hostAttribute/shadowAttribute, which would throw an error.
2841
+ // However it may be undefined in newer versions of LWC, so we need to guard against that case.
2842
+ this.stylesheetToken = isUndefined$1(value) ? undefined : value.shadowAttribute;
2843
+ },
2844
+ });
2795
2845
  // chaining this method as a way to wrap existing
2796
2846
  // assignment of templates easily, without too much transformation
2797
2847
  return tpl;
@@ -3856,15 +3906,16 @@ var LWC = (function (exports) {
3856
3906
  }
3857
3907
  }
3858
3908
  function unmount(vnode, parent, doRemove = false) {
3859
- const { type, elm } = vnode;
3909
+ const { type, elm, sel } = vnode;
3860
3910
  // When unmounting a VNode subtree not all the elements have to removed from the DOM. The
3861
3911
  // subtree root, is the only element worth unmounting from the subtree.
3862
3912
  if (doRemove) {
3863
3913
  removeNode(elm, parent);
3864
3914
  }
3915
+ const removeChildren = sel === 'slot'; // slot content is removed to trigger slotchange event when removing slot
3865
3916
  switch (type) {
3866
3917
  case 2 /* Element */:
3867
- unmountVNodes(vnode.children, elm);
3918
+ unmountVNodes(vnode.children, elm, removeChildren);
3868
3919
  break;
3869
3920
  case 3 /* CustomElement */: {
3870
3921
  const { vm } = vnode;
@@ -4782,10 +4833,10 @@ var LWC = (function (exports) {
4782
4833
  const { renderMode, shadowMode } = vm;
4783
4834
  if (renderMode === 1 /* Shadow */ && shadowMode === 1 /* Synthetic */) {
4784
4835
  for (let i = 0; i < stylesheets.length; i++) {
4785
- insertGlobalStylesheet$1(stylesheets[i]);
4836
+ insertStylesheet$1(stylesheets[i]);
4786
4837
  }
4787
4838
  }
4788
- else if (ssr$1 || isHydrating$1()) {
4839
+ else if (ssr$1 || vm.hydrated) {
4789
4840
  // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
4790
4841
  // This works in the client, because the stylesheets are created, and cached in the VM
4791
4842
  // the first time the VM renders.
@@ -4796,15 +4847,10 @@ var LWC = (function (exports) {
4796
4847
  else {
4797
4848
  // native shadow or light DOM, DOM renderer
4798
4849
  const root = getNearestNativeShadowComponent(vm);
4799
- const isGlobal = isNull(root);
4850
+ // null root means a global style
4851
+ const target = isNull(root) ? undefined : root.shadowRoot;
4800
4852
  for (let i = 0; i < stylesheets.length; i++) {
4801
- if (isGlobal) {
4802
- insertGlobalStylesheet$1(stylesheets[i]);
4803
- }
4804
- else {
4805
- // local level
4806
- insertStylesheet$1(stylesheets[i], root.shadowRoot);
4807
- }
4853
+ insertStylesheet$1(stylesheets[i], target);
4808
4854
  }
4809
4855
  }
4810
4856
  return null;
@@ -5346,24 +5392,14 @@ var LWC = (function (exports) {
5346
5392
 
5347
5393
  resetComponentStateWhenRemoved(vm);
5348
5394
  }
5349
-
5350
- function getNearestShadowAncestor(vm) {
5351
- let ancestor = vm.owner;
5352
-
5353
- while (!isNull(ancestor) && ancestor.renderMode === 0
5354
- /* Light */
5355
- ) {
5356
- ancestor = ancestor.owner;
5357
- }
5358
-
5359
- return ancestor;
5360
- }
5361
-
5362
5395
  function createVM(elm, ctor, options) {
5396
+ var _a;
5397
+
5363
5398
  const {
5364
5399
  mode,
5365
5400
  owner,
5366
- tagName
5401
+ tagName,
5402
+ hydrated
5367
5403
  } = options;
5368
5404
  const def = getComponentInternalDef(ctor);
5369
5405
  const vm = {
@@ -5386,7 +5422,10 @@ var LWC = (function (exports) {
5386
5422
  cmpSlots: create(null),
5387
5423
  oar: create(null),
5388
5424
  cmpTemplate: null,
5425
+ hydrated: Boolean(hydrated),
5389
5426
  renderMode: def.renderMode,
5427
+ shadowMode: computeShadowMode(def, owner),
5428
+ nearestShadowMode: (owner === null || owner === void 0 ? void 0 : owner.shadowRoot) ? owner.shadowMode : (_a = owner === null || owner === void 0 ? void 0 : owner.nearestShadowMode) !== null && _a !== void 0 ? _a : null,
5390
5429
  context: {
5391
5430
  stylesheetToken: undefined,
5392
5431
  hasTokenInClass: undefined,
@@ -5399,7 +5438,6 @@ var LWC = (function (exports) {
5399
5438
  },
5400
5439
  // Properties set right after VM creation.
5401
5440
  tro: null,
5402
- shadowMode: null,
5403
5441
  // Properties set by the LightningElement constructor.
5404
5442
  component: null,
5405
5443
  shadowRoot: null,
@@ -5408,7 +5446,6 @@ var LWC = (function (exports) {
5408
5446
  setHook,
5409
5447
  getHook
5410
5448
  };
5411
- vm.shadowMode = computeShadowMode(vm);
5412
5449
  vm.tro = getTemplateReactiveObserver(vm);
5413
5450
 
5414
5451
  if (process.env.NODE_ENV !== 'production') {
@@ -5433,10 +5470,9 @@ var LWC = (function (exports) {
5433
5470
  return vm;
5434
5471
  }
5435
5472
 
5436
- function computeShadowMode(vm) {
5437
- const {
5438
- def
5439
- } = vm;
5473
+ function computeShadowMode(def, owner) {
5474
+ var _a;
5475
+
5440
5476
  let shadowMode;
5441
5477
 
5442
5478
  if (isSyntheticShadowDefined$1) {
@@ -5459,23 +5495,13 @@ var LWC = (function (exports) {
5459
5495
  /* Native */
5460
5496
  ;
5461
5497
  } else {
5462
- const shadowAncestor = getNearestShadowAncestor(vm);
5463
-
5464
- if (!isNull(shadowAncestor) && shadowAncestor.shadowMode === 0
5465
- /* Native */
5466
- ) {
5467
- // Transitive support for native Shadow DOM. A component in native mode
5468
- // transitively opts all of its descendants into native.
5469
- shadowMode = 0
5470
- /* Native */
5471
- ;
5472
- } else {
5473
- // Synthetic if neither this component nor any of its ancestors are configured
5474
- // to be native.
5475
- shadowMode = 1
5476
- /* Synthetic */
5477
- ;
5478
- }
5498
+ // Transitive support for native Shadow DOM. A component in native mode
5499
+ // transitively opts all of its descendants into native.
5500
+ // Synthetic if neither this component nor any of its ancestors are configured
5501
+ // to be native.
5502
+ shadowMode = (_a = owner === null || owner === void 0 ? void 0 : owner.nearestShadowMode) !== null && _a !== void 0 ? _a : 1
5503
+ /* Synthetic */
5504
+ ;
5479
5505
  }
5480
5506
  } else {
5481
5507
  shadowMode = 1
@@ -6371,6 +6397,7 @@ var LWC = (function (exports) {
6371
6397
  mode,
6372
6398
  owner,
6373
6399
  tagName: sel,
6400
+ hydrated: true,
6374
6401
  });
6375
6402
  vnode.elm = elm;
6376
6403
  vnode.vm = vm;
@@ -6564,7 +6591,6 @@ var LWC = (function (exports) {
6564
6591
  hooksAreSet = true;
6565
6592
  setSanitizeHtmlContentHook(hooks.sanitizeHtmlContent);
6566
6593
  }
6567
- /* version: 2.13.1 */
6568
6594
 
6569
6595
  /*
6570
6596
  * Copyright (c) 2018, salesforce.com, inc.
@@ -6572,25 +6598,270 @@ var LWC = (function (exports) {
6572
6598
  * SPDX-License-Identifier: MIT
6573
6599
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6574
6600
  */
6575
- const globalStylesheets = create(null);
6576
- if (process.env.NODE_ENV === 'development') {
6577
- // @ts-ignore
6578
- window.__lwcResetGlobalStylesheets = () => {
6579
- for (const key of Object.keys(globalStylesheets)) {
6580
- delete globalStylesheets[key];
6601
+ // See @lwc/engine-core/src/framework/template.ts
6602
+ const TEMPLATE_PROPS = ['slots', 'stylesheetToken', 'stylesheets', 'renderMode'];
6603
+ // Via https://www.npmjs.com/package/object-observer
6604
+ const ARRAY_MUTATION_METHODS = [
6605
+ 'pop',
6606
+ 'push',
6607
+ 'shift',
6608
+ 'unshift',
6609
+ 'reverse',
6610
+ 'sort',
6611
+ 'fill',
6612
+ 'splice',
6613
+ 'copyWithin',
6614
+ ];
6615
+ function getOriginalArrayMethod(prop) {
6616
+ switch (prop) {
6617
+ case 'pop':
6618
+ return ArrayPop;
6619
+ case 'push':
6620
+ return ArrayPush$1;
6621
+ case 'shift':
6622
+ return ArrayShift;
6623
+ case 'unshift':
6624
+ return ArrayUnshift;
6625
+ case 'reverse':
6626
+ return ArrayReverse;
6627
+ case 'sort':
6628
+ return ArraySort;
6629
+ case 'fill':
6630
+ return ArrayFill;
6631
+ case 'splice':
6632
+ return ArraySplice;
6633
+ case 'copyWithin':
6634
+ return ArrayCopyWithin;
6635
+ }
6636
+ }
6637
+ let mutationWarningsSilenced = false;
6638
+ // Warn if the user tries to mutate tmpl.stylesheets, e.g.:
6639
+ // `tmpl.stylesheets.push(someStylesheetFunction)`
6640
+ function warnOnArrayMutation(stylesheets) {
6641
+ // We can't handle users calling Array.prototype.slice.call(tmpl.stylesheets), but
6642
+ // we can at least warn when they use the most common mutation methods.
6643
+ for (const prop of ARRAY_MUTATION_METHODS) {
6644
+ const originalArrayMethod = getOriginalArrayMethod(prop);
6645
+ stylesheets[prop] = function arrayMutationWarningWrapper() {
6646
+ logError(`Mutating the "stylesheets" array on a template function ` +
6647
+ `is deprecated and may be removed in a future version of LWC.`);
6648
+ // @ts-ignore
6649
+ return originalArrayMethod.apply(this, arguments);
6650
+ };
6651
+ }
6652
+ }
6653
+ // TODO [#2782]: eventually freezeTemplate() will _actually_ freeze the tmpl object. Today it
6654
+ // just warns on mutation.
6655
+ function freezeTemplate(tmpl) {
6656
+ if (process.env.NODE_ENV !== 'production') {
6657
+ if (!isUndefined$1(tmpl.stylesheets)) {
6658
+ warnOnArrayMutation(tmpl.stylesheets);
6659
+ }
6660
+ for (const prop of TEMPLATE_PROPS) {
6661
+ let value = tmpl[prop];
6662
+ defineProperty(tmpl, prop, {
6663
+ enumerable: true,
6664
+ configurable: true,
6665
+ get() {
6666
+ return value;
6667
+ },
6668
+ set(newValue) {
6669
+ if (!mutationWarningsSilenced) {
6670
+ logError(`Dynamically setting the "${prop}" property on a template function ` +
6671
+ `is deprecated and may be removed in a future version of LWC.`);
6672
+ }
6673
+ value = newValue;
6674
+ },
6675
+ });
6581
6676
  }
6582
- };
6677
+ const originalDescriptor = getOwnPropertyDescriptor$1(tmpl, 'stylesheetTokens');
6678
+ defineProperty(tmpl, 'stylesheetTokens', {
6679
+ enumerable: true,
6680
+ configurable: true,
6681
+ get: originalDescriptor.get,
6682
+ set(value) {
6683
+ logError(`Dynamically setting the "stylesheetTokens" property on a template function ` +
6684
+ `is deprecated and may be removed in a future version of LWC.`);
6685
+ // Avoid logging twice (for both stylesheetToken and stylesheetTokens)
6686
+ mutationWarningsSilenced = true;
6687
+ originalDescriptor.set.call(this, value);
6688
+ mutationWarningsSilenced = false;
6689
+ },
6690
+ });
6691
+ }
6583
6692
  }
6584
- const globalStylesheetsParentElement = document.head || document.body || document;
6585
- // This check for constructable stylesheets is similar to Fast's:
6693
+
6694
+ /*
6695
+ * Copyright (c) 2018, salesforce.com, inc.
6696
+ * All rights reserved.
6697
+ * SPDX-License-Identifier: MIT
6698
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6699
+ */
6700
+ /**
6701
+ * EXPERIMENTAL: This function provides access to the component constructor, given an HTMLElement.
6702
+ * This API is subject to change or being removed.
6703
+ */
6704
+ function getComponentConstructor(elm) {
6705
+ let ctor = null;
6706
+ // intentionally checking for undefined due to some funky libraries patching weakmap.get
6707
+ // to throw when undefined.
6708
+ if (!isUndefined$1(elm)) {
6709
+ const vm = getAssociatedVMIfPresent(elm);
6710
+ if (!isUndefined$1(vm)) {
6711
+ ctor = vm.def.ctor;
6712
+ }
6713
+ }
6714
+ return ctor;
6715
+ }
6716
+ /* version: 2.13.4 */
6717
+
6718
+ /*
6719
+ * Copyright (c) 2018, salesforce.com, inc.
6720
+ * All rights reserved.
6721
+ * SPDX-License-Identifier: MIT
6722
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6723
+ */
6724
+ //
6725
+ // Feature detection
6726
+ //
6727
+ // This check for constructable style sheets is similar to Fast's:
6586
6728
  // https://github.com/microsoft/fast/blob/d49d1ec/packages/web-components/fast-element/src/dom.ts#L51-L53
6587
6729
  // See also: https://github.com/whatwg/webidl/issues/1027#issuecomment-934510070
6588
- const supportsConstructableStyleSheets = isFunction$1(CSSStyleSheet.prototype.replaceSync) && isArray$1(document.adoptedStyleSheets);
6589
- const supportsMutableAdoptedStyleSheets = supportsConstructableStyleSheets &&
6730
+ const supportsConstructableStylesheets = isFunction$1(CSSStyleSheet.prototype.replaceSync) && isArray$1(document.adoptedStyleSheets);
6731
+ // The original adoptedStylesheet proposal used a frozen array. A follow-up proposal made the array mutable.
6732
+ // Chromium 99+ and Firefox 101+ support mutable arrays. We check if the array is mutable, to ensure backward compat.
6733
+ // (If the length is writable, then the array is mutable.) See: https://chromestatus.com/feature/5638996492288000
6734
+ // TODO [#2828]: Re-evaluate this in the future once we drop support for older browser versions.
6735
+ const supportsMutableAdoptedStyleSheets = supportsConstructableStylesheets &&
6590
6736
  getOwnPropertyDescriptor$1(document.adoptedStyleSheets, 'length').writable;
6591
- const styleElements = create(null);
6592
- const styleSheets = create(null);
6593
- const shadowRootsToStyleSheets = new WeakMap();
6737
+ // Detect IE, via https://stackoverflow.com/a/9851769
6738
+ const isIE11 = !isUndefined$1(document.documentMode);
6739
+ const stylesheetCache = new Map();
6740
+ //
6741
+ // Test utilities
6742
+ //
6743
+ if (process.env.NODE_ENV === 'development') {
6744
+ // @ts-ignore
6745
+ window.__lwcResetGlobalStylesheets = () => {
6746
+ stylesheetCache.clear();
6747
+ };
6748
+ }
6749
+ function isDocument(target) {
6750
+ return !isUndefined$1(target.head);
6751
+ }
6752
+ function createFreshStyleElement(content) {
6753
+ const elm = document.createElement('style');
6754
+ elm.type = 'text/css';
6755
+ elm.textContent = content;
6756
+ return elm;
6757
+ }
6758
+ function createStyleElement(content, cacheData) {
6759
+ const { stylesheet, used } = cacheData;
6760
+ // If the <style> was already used, then we should clone it. We cannot insert
6761
+ // the same <style> in two places in the DOM.
6762
+ if (used) {
6763
+ // For a mysterious reason, IE11 doesn't like the way we clone <style> nodes
6764
+ // and will render the incorrect styles if we do things that way. It's just
6765
+ // a perf optimization, so we can skip it for IE11.
6766
+ if (isIE11) {
6767
+ return createFreshStyleElement(content);
6768
+ }
6769
+ // This `<style>` may be repeated multiple times in the DOM, so cache it. It's a bit
6770
+ // faster to call `cloneNode()` on an existing node than to recreate it every time.
6771
+ return stylesheet.cloneNode(true);
6772
+ }
6773
+ // We don't clone every time, because that would be a perf tax on the first time
6774
+ cacheData.used = true;
6775
+ return stylesheet;
6776
+ }
6777
+ function createConstructableStylesheet(content) {
6778
+ const stylesheet = new CSSStyleSheet();
6779
+ stylesheet.replaceSync(content);
6780
+ return stylesheet;
6781
+ }
6782
+ function insertConstructableStylesheet(content, target, cacheData) {
6783
+ const { adoptedStyleSheets } = target;
6784
+ const { stylesheet } = cacheData;
6785
+ // Mutable adopted stylesheets are only supported in certain browsers.
6786
+ // The reason we use it is for perf: https://github.com/salesforce/lwc/pull/2683
6787
+ if (supportsMutableAdoptedStyleSheets) {
6788
+ adoptedStyleSheets.push(stylesheet);
6789
+ }
6790
+ else {
6791
+ target.adoptedStyleSheets = [...adoptedStyleSheets, stylesheet];
6792
+ }
6793
+ }
6794
+ function insertStyleElement(content, target, cacheData) {
6795
+ const elm = createStyleElement(content, cacheData);
6796
+ const targetAnchorPoint = isDocument(target) ? target.head : target;
6797
+ targetAnchorPoint.appendChild(elm);
6798
+ }
6799
+ function doInsertStylesheet(content, target, cacheData) {
6800
+ // Constructable stylesheets are only supported in certain browsers:
6801
+ // https://caniuse.com/mdn-api_document_adoptedstylesheets
6802
+ // The reason we use it is for perf: https://github.com/salesforce/lwc/pull/2460
6803
+ if (supportsConstructableStylesheets) {
6804
+ insertConstructableStylesheet(content, target, cacheData);
6805
+ }
6806
+ else {
6807
+ // Fall back to <style> element
6808
+ insertStyleElement(content, target, cacheData);
6809
+ }
6810
+ }
6811
+ function getCacheData(content) {
6812
+ let cacheData = stylesheetCache.get(content);
6813
+ if (isUndefined$1(cacheData)) {
6814
+ cacheData = {
6815
+ stylesheet: supportsConstructableStylesheets
6816
+ ? createConstructableStylesheet(content)
6817
+ : createFreshStyleElement(content),
6818
+ roots: undefined,
6819
+ global: false,
6820
+ used: false,
6821
+ };
6822
+ stylesheetCache.set(content, cacheData);
6823
+ }
6824
+ return cacheData;
6825
+ }
6826
+ function insertGlobalStylesheet(content) {
6827
+ const cacheData = getCacheData(content);
6828
+ if (cacheData.global) {
6829
+ // already inserted
6830
+ return;
6831
+ }
6832
+ cacheData.global = true; // mark inserted
6833
+ doInsertStylesheet(content, document, cacheData);
6834
+ }
6835
+ function insertLocalStylesheet(content, target) {
6836
+ const cacheData = getCacheData(content);
6837
+ let { roots } = cacheData;
6838
+ if (isUndefined$1(roots)) {
6839
+ roots = cacheData.roots = new WeakSet(); // lazily initialize (not needed for global styles)
6840
+ }
6841
+ else if (roots.has(target)) {
6842
+ // already inserted
6843
+ return;
6844
+ }
6845
+ roots.add(target); // mark inserted
6846
+ doInsertStylesheet(content, target, cacheData);
6847
+ }
6848
+ function insertStylesheet(content, target) {
6849
+ if (isUndefined$1(target)) {
6850
+ // global
6851
+ insertGlobalStylesheet(content);
6852
+ }
6853
+ else {
6854
+ // local
6855
+ insertLocalStylesheet(content, target);
6856
+ }
6857
+ }
6858
+
6859
+ /*
6860
+ * Copyright (c) 2018, salesforce.com, inc.
6861
+ * All rights reserved.
6862
+ * SPDX-License-Identifier: MIT
6863
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6864
+ */
6594
6865
  let getCustomElement;
6595
6866
  let defineCustomElement;
6596
6867
  let HTMLElementConstructor;
@@ -6617,52 +6888,6 @@ var LWC = (function (exports) {
6617
6888
  return false;
6618
6889
  }
6619
6890
  }
6620
- function insertConstructableStyleSheet(content, target) {
6621
- // It's important for CSSStyleSheets to be unique based on their content, so that
6622
- // `shadowRoot.adoptedStyleSheets.includes(sheet)` works.
6623
- let styleSheet = styleSheets[content];
6624
- if (isUndefined$1(styleSheet)) {
6625
- styleSheet = new CSSStyleSheet();
6626
- styleSheet.replaceSync(content);
6627
- styleSheets[content] = styleSheet;
6628
- }
6629
- const { adoptedStyleSheets } = target;
6630
- if (!adoptedStyleSheets.includes(styleSheet)) {
6631
- if (supportsMutableAdoptedStyleSheets) {
6632
- // This is only supported in later versions of Chromium:
6633
- // https://chromestatus.com/feature/5638996492288000
6634
- adoptedStyleSheets.push(styleSheet);
6635
- }
6636
- else {
6637
- target.adoptedStyleSheets = [...adoptedStyleSheets, styleSheet];
6638
- }
6639
- }
6640
- }
6641
- function insertStyleElement(content, target) {
6642
- // Avoid inserting duplicate `<style>`s
6643
- let sheets = shadowRootsToStyleSheets.get(target);
6644
- if (isUndefined$1(sheets)) {
6645
- sheets = create(null);
6646
- shadowRootsToStyleSheets.set(target, sheets);
6647
- }
6648
- if (sheets[content]) {
6649
- return;
6650
- }
6651
- sheets[content] = true;
6652
- // This `<style>` may be repeated multiple times in the DOM, so cache it. It's a bit
6653
- // faster to call `cloneNode()` on an existing node than to recreate it every time.
6654
- let elm = styleElements[content];
6655
- if (isUndefined$1(elm)) {
6656
- elm = document.createElement('style');
6657
- elm.type = 'text/css';
6658
- elm.textContent = content;
6659
- styleElements[content] = elm;
6660
- }
6661
- else {
6662
- elm = elm.cloneNode(true);
6663
- }
6664
- target.appendChild(elm);
6665
- }
6666
6891
  if (isCustomElementRegistryAvailable()) {
6667
6892
  getCustomElement = customElements.get.bind(customElements);
6668
6893
  defineCustomElement = customElements.define.bind(customElements);
@@ -6701,9 +6926,6 @@ var LWC = (function (exports) {
6701
6926
  hydrating = value;
6702
6927
  }
6703
6928
  const ssr = false;
6704
- function isHydrating() {
6705
- return hydrating;
6706
- }
6707
6929
  const isNativeShadowDefined = _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED];
6708
6930
  const isSyntheticShadowDefined = hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN);
6709
6931
  function createElement$1(tagName, namespace) {
@@ -6818,25 +7040,6 @@ var LWC = (function (exports) {
6818
7040
  function isConnected(node) {
6819
7041
  return node.isConnected;
6820
7042
  }
6821
- function insertGlobalStylesheet(content) {
6822
- if (!isUndefined$1(globalStylesheets[content])) {
6823
- return;
6824
- }
6825
- globalStylesheets[content] = true;
6826
- const elm = document.createElement('style');
6827
- elm.type = 'text/css';
6828
- elm.textContent = content;
6829
- globalStylesheetsParentElement.appendChild(elm);
6830
- }
6831
- function insertStylesheet(content, target) {
6832
- if (supportsConstructableStyleSheets) {
6833
- insertConstructableStyleSheet(content, target);
6834
- }
6835
- else {
6836
- // Fall back to <style> element
6837
- insertStyleElement(content, target);
6838
- }
6839
- }
6840
7043
  function assertInstanceOfHTMLElement(elm, msg) {
6841
7044
  assert.invariant(elm instanceof HTMLElement, msg);
6842
7045
  }
@@ -6870,10 +7073,7 @@ var LWC = (function (exports) {
6870
7073
  setGetProperty(getProperty);
6871
7074
  setHTMLElement(HTMLElementExported);
6872
7075
  setInsert(insert);
6873
- setInsertGlobalStylesheet(insertGlobalStylesheet);
6874
- setInsertStylesheet(insertStylesheet);
6875
7076
  setIsConnected(isConnected);
6876
- setIsHydrating$1(isHydrating);
6877
7077
  setIsNativeShadowDefined(isNativeShadowDefined);
6878
7078
  setIsSyntheticShadowDefined(isSyntheticShadowDefined);
6879
7079
  setNextSibling(nextSibling);
@@ -6888,6 +7088,32 @@ var LWC = (function (exports) {
6888
7088
  setSetText(setText);
6889
7089
  setSsr(ssr);
6890
7090
  setAddEventListener(addEventListener);
7091
+ setInsertStylesheet(insertStylesheet);
7092
+
7093
+ /*
7094
+ * Copyright (c) 2018, salesforce.com, inc.
7095
+ * All rights reserved.
7096
+ * SPDX-License-Identifier: MIT
7097
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7098
+ */
7099
+ // @ts-ignore
7100
+
7101
+ if (process.env.NODE_ENV !== 'production' && typeof __karma__ !== 'undefined') {
7102
+ window.addEventListener('test-dummy-flag', () => {
7103
+ let hasFlag = false;
7104
+
7105
+ if (runtimeFlags.DUMMY_TEST_FLAG) {
7106
+ hasFlag = true;
7107
+ }
7108
+
7109
+ window.dispatchEvent(new CustomEvent('has-dummy-flag', {
7110
+ detail: {
7111
+ package: '@lwc/engine-dom',
7112
+ hasFlag
7113
+ }
7114
+ }));
7115
+ });
7116
+ }
6891
7117
 
6892
7118
  /*
6893
7119
  * Copyright (c) 2018, salesforce.com, inc.
@@ -6913,6 +7139,7 @@ var LWC = (function (exports) {
6913
7139
  mode: 'open',
6914
7140
  owner: null,
6915
7141
  tagName: element.tagName.toLowerCase(),
7142
+ hydrated: true,
6916
7143
  });
6917
7144
  for (const [key, value] of Object.entries(props)) {
6918
7145
  element[key] = value;
@@ -7115,27 +7342,6 @@ var LWC = (function (exports) {
7115
7342
  return element;
7116
7343
  }
7117
7344
 
7118
- /*
7119
- * Copyright (c) 2018, salesforce.com, inc.
7120
- * All rights reserved.
7121
- * SPDX-License-Identifier: MIT
7122
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7123
- */
7124
- /**
7125
- * EXPERIMENTAL: This function provides access to the component constructor, given an HTMLElement.
7126
- * This API is subject to change or being removed.
7127
- */
7128
- function getComponentConstructor(elm) {
7129
- let ctor = null;
7130
- if (elm instanceof HTMLElement) {
7131
- const vm = getAssociatedVMIfPresent(elm);
7132
- if (!isUndefined$1(vm)) {
7133
- ctor = vm.def.ctor;
7134
- }
7135
- }
7136
- return ctor;
7137
- }
7138
-
7139
7345
  /*
7140
7346
  * Copyright (c) 2018, salesforce.com, inc.
7141
7347
  * All rights reserved.
@@ -7204,7 +7410,7 @@ var LWC = (function (exports) {
7204
7410
  });
7205
7411
  freeze(LightningElement);
7206
7412
  seal(LightningElement.prototype);
7207
- /* version: 2.13.1 */
7413
+ /* version: 2.13.4 */
7208
7414
 
7209
7415
  exports.LightningElement = LightningElement;
7210
7416
  exports.__unstable__ProfilerControl = profilerControl;
@@ -7212,6 +7418,7 @@ var LWC = (function (exports) {
7212
7418
  exports.buildCustomElementConstructor = deprecatedBuildCustomElementConstructor;
7213
7419
  exports.createContextProvider = createContextProvider;
7214
7420
  exports.createElement = createElement;
7421
+ exports.freezeTemplate = freezeTemplate;
7215
7422
  exports.getComponentConstructor = getComponentConstructor;
7216
7423
  exports.getComponentDef = getComponentDef;
7217
7424
  exports.hydrateComponent = hydrateComponent;