lwc 2.33.0 → 2.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +1022 -649
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +1022 -648
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +824 -557
  5. package/dist/engine-dom/iife/es5/engine-dom.js +1179 -802
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +1002 -720
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +1022 -648
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +824 -557
  11. package/dist/engine-dom/umd/es5/engine-dom.js +1179 -802
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +1002 -720
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +789 -638
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +789 -638
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +15 -4
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +15 -4
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +2 -2
  20. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +15 -4
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +18 -3
  22. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js +2 -2
  23. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +18 -3
  24. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +15 -4
  25. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +2 -2
  26. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +15 -4
  27. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +18 -3
  28. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js +2 -2
  29. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +18 -3
  30. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  31. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/iife/es5/wire-service.js +2 -2
  34. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  35. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  36. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  37. package/dist/wire-service/umd/es5/wire-service.js +2 -2
  38. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  39. package/package.json +7 -7
@@ -48,7 +48,7 @@ var LWC = (function (exports) {
48
48
  const { isArray: isArray$1 } = Array;
49
49
  const { concat: ArrayConcat$1, 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, some: ArraySome, sort: ArraySort, splice: ArraySplice, unshift: ArrayUnshift, forEach, } = Array.prototype;
50
50
  const { fromCharCode: StringFromCharCode } = String;
51
- const { charCodeAt: StringCharCodeAt, replace: StringReplace, slice: StringSlice, toLowerCase: StringToLowerCase, } = String.prototype;
51
+ const { charCodeAt: StringCharCodeAt, replace: StringReplace, split: StringSplit, slice: StringSlice, toLowerCase: StringToLowerCase, } = String.prototype;
52
52
  function isUndefined$1(obj) {
53
53
  return obj === undefined;
54
54
  }
@@ -185,6 +185,19 @@ var LWC = (function (exports) {
185
185
  });
186
186
  return { AriaAttrNameToPropNameMap, AriaPropNameToAttrNameMap };
187
187
  })();
188
+ // These attributes take either an ID or a list of IDs as values.
189
+ // This includes aria-* attributes as well as the special non-ARIA "for" attribute
190
+ const ID_REFERENCING_ATTRIBUTES_SET = new Set([
191
+ 'aria-activedescendant',
192
+ 'aria-controls',
193
+ 'aria-describedby',
194
+ 'aria-details',
195
+ 'aria-errormessage',
196
+ 'aria-flowto',
197
+ 'aria-labelledby',
198
+ 'aria-owns',
199
+ 'for',
200
+ ]);
188
201
 
189
202
  /*
190
203
  * Copyright (c) 2018, salesforce.com, inc.
@@ -240,6 +253,8 @@ var LWC = (function (exports) {
240
253
  const KEY__SHADOW_TOKEN = '$shadowToken$';
241
254
  const KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode';
242
255
  const KEY__SCOPED_CSS = '$scoped$';
256
+ const KEY__NATIVE_GET_ELEMENT_BY_ID = '$nativeGetElementById$';
257
+ const KEY__NATIVE_QUERY_SELECTOR_ALL = '$nativeQuerySelectorAll$';
243
258
  const XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
244
259
  const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
245
260
  const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
@@ -347,9 +362,9 @@ var LWC = (function (exports) {
347
362
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
348
363
  */
349
364
  // Increment whenever the LWC template compiler changes
350
- const LWC_VERSION = "2.33.0";
365
+ const LWC_VERSION = "2.35.0";
351
366
  const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
352
- /** version: 2.33.0 */
367
+ /** version: 2.35.0 */
353
368
 
354
369
  /**
355
370
  * Copyright (C) 2018 salesforce.com, inc.
@@ -372,6 +387,7 @@ var LWC = (function (exports) {
372
387
  ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
373
388
  ENABLE_FROZEN_TEMPLATE: null,
374
389
  DISABLE_ARIA_REFLECTION_POLYFILL: null,
390
+ ENABLE_PROGRAMMATIC_STYLESHEETS: null,
375
391
  };
376
392
  if (!_globalThis.lwcRuntimeFlags) {
377
393
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
@@ -425,7 +441,7 @@ var LWC = (function (exports) {
425
441
  setFeatureFlag(name, value);
426
442
  }
427
443
  }
428
- /** version: 2.33.0 */
444
+ /** version: 2.35.0 */
429
445
 
430
446
  /**
431
447
  * Copyright (C) 2018 salesforce.com, inc.
@@ -489,7 +505,7 @@ var LWC = (function (exports) {
489
505
  }
490
506
  }
491
507
  }
492
- /** version: 2.33.0 */
508
+ /** version: 2.35.0 */
493
509
 
494
510
  /*
495
511
  * Copyright (c) 2018, salesforce.com, inc.
@@ -557,94 +573,167 @@ var LWC = (function (exports) {
557
573
  * SPDX-License-Identifier: MIT
558
574
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
559
575
  */
560
- let nextTickCallbackQueue = [];
561
- const SPACE_CHAR = 32;
562
- const EmptyObject = seal(create(null));
563
- const EmptyArray = seal([]);
564
- function flushCallbackQueue() {
565
- if (process.env.NODE_ENV !== 'production') {
566
- if (nextTickCallbackQueue.length === 0) {
567
- throw new Error(`Internal Error: If callbackQueue is scheduled, it is because there must be at least one callback on this pending queue.`);
576
+ /** Callbacks to invoke when reporting is enabled **/
577
+ const onReportingEnabledCallbacks = [];
578
+ /** The currently assigned reporting dispatcher. */
579
+ let currentDispatcher$1 = noop;
580
+ /**
581
+ * Whether reporting is enabled.
582
+ *
583
+ * Note that this may seem redundant, given you can just check if the currentDispatcher is undefined,
584
+ * but it turns out that Terser only strips out unused code if we use this explicit boolean.
585
+ */
586
+ let enabled$1 = false;
587
+ const reportingControl = {
588
+ /**
589
+ * Attach a new reporting control (aka dispatcher).
590
+ *
591
+ * @param dispatcher - reporting control
592
+ */
593
+ attachDispatcher(dispatcher) {
594
+ enabled$1 = true;
595
+ currentDispatcher$1 = dispatcher;
596
+ for (const callback of onReportingEnabledCallbacks) {
597
+ try {
598
+ callback();
599
+ }
600
+ catch (err) {
601
+ // This should never happen. But if it does, we don't want one callback to cause another to fail
602
+ // eslint-disable-next-line no-console
603
+ console.error('Could not invoke callback', err);
604
+ }
568
605
  }
606
+ onReportingEnabledCallbacks.length = 0; // clear the array
607
+ },
608
+ /**
609
+ * Detach the current reporting control (aka dispatcher).
610
+ */
611
+ detachDispatcher() {
612
+ enabled$1 = false;
613
+ currentDispatcher$1 = noop;
614
+ },
615
+ };
616
+ /**
617
+ * Call a callback when reporting is enabled, or immediately if reporting is already enabled.
618
+ * Will only ever be called once.
619
+ * @param callback
620
+ */
621
+ function onReportingEnabled(callback) {
622
+ if (enabled$1) {
623
+ // call immediately
624
+ callback();
569
625
  }
570
- const callbacks = nextTickCallbackQueue;
571
- nextTickCallbackQueue = []; // reset to a new queue
572
- for (let i = 0, len = callbacks.length; i < len; i += 1) {
573
- callbacks[i]();
626
+ else {
627
+ // call later
628
+ onReportingEnabledCallbacks.push(callback);
574
629
  }
575
630
  }
576
- function addCallbackToNextTick(callback) {
577
- if (process.env.NODE_ENV !== 'production') {
578
- if (!isFunction$1(callback)) {
579
- throw new Error(`Internal Error: addCallbackToNextTick() can only accept a function callback`);
580
- }
581
- }
582
- if (nextTickCallbackQueue.length === 0) {
583
- Promise.resolve().then(flushCallbackQueue);
631
+ /**
632
+ * Report to the current dispatcher, if there is one.
633
+ * @param reportingEventId
634
+ * @param vm
635
+ */
636
+ function report(reportingEventId, vm) {
637
+ if (enabled$1) {
638
+ currentDispatcher$1(reportingEventId, vm.tagName, vm.idx);
584
639
  }
585
- ArrayPush$1.call(nextTickCallbackQueue, callback);
586
640
  }
587
- function guid() {
588
- function s4() {
589
- return Math.floor((1 + Math.random()) * 0x10000)
590
- .toString(16)
591
- .substring(1);
641
+
642
+ /*
643
+ * Copyright (c) 2018, salesforce.com, inc.
644
+ * All rights reserved.
645
+ * SPDX-License-Identifier: MIT
646
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
647
+ */
648
+ function getComponentTag(vm) {
649
+ return `<${StringToLowerCase.call(vm.tagName)}>`;
650
+ }
651
+ // TODO [#1695]: Unify getComponentStack and getErrorComponentStack
652
+ function getComponentStack(vm) {
653
+ const stack = [];
654
+ let prefix = '';
655
+ while (!isNull(vm.owner)) {
656
+ ArrayPush$1.call(stack, prefix + getComponentTag(vm));
657
+ vm = vm.owner;
658
+ prefix += '\t';
592
659
  }
593
- return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
660
+ return ArrayJoin.call(stack, '\n');
594
661
  }
595
- // Borrowed from Vue template compiler.
596
- // https://github.com/vuejs/vue/blob/531371b818b0e31a989a06df43789728f23dc4e8/src/platforms/web/util/style.js#L5-L16
597
- const DECLARATION_DELIMITER = /;(?![^(]*\))/g;
598
- const PROPERTY_DELIMITER = /:(.+)/;
599
- function parseStyleText(cssText) {
600
- const styleMap = {};
601
- const declarations = cssText.split(DECLARATION_DELIMITER);
602
- for (const declaration of declarations) {
603
- if (declaration) {
604
- const [prop, value] = declaration.split(PROPERTY_DELIMITER);
605
- if (prop !== undefined && value !== undefined) {
606
- styleMap[prop.trim()] = value.trim();
607
- }
608
- }
662
+ function getErrorComponentStack(vm) {
663
+ const wcStack = [];
664
+ let currentVm = vm;
665
+ while (!isNull(currentVm)) {
666
+ ArrayPush$1.call(wcStack, getComponentTag(currentVm));
667
+ currentVm = currentVm.owner;
609
668
  }
610
- return styleMap;
669
+ return wcStack.reverse().join('\n\t');
611
670
  }
612
- // Make a shallow copy of an object but omit the given key
613
- function cloneAndOmitKey(object, keyToOmit) {
614
- const result = {};
615
- for (const key of Object.keys(object)) {
616
- if (key !== keyToOmit) {
617
- result[key] = object[key];
618
- }
671
+
672
+ /*
673
+ * Copyright (c) 2018, salesforce.com, inc.
674
+ * All rights reserved.
675
+ * SPDX-License-Identifier: MIT
676
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
677
+ */
678
+ function addErrorComponentStack(vm, error) {
679
+ if (!isFrozen(error) && isUndefined$1(error.wcStack)) {
680
+ const wcStack = getErrorComponentStack(vm);
681
+ defineProperty(error, 'wcStack', {
682
+ get() {
683
+ return wcStack;
684
+ },
685
+ });
619
686
  }
620
- return result;
621
687
  }
622
- function flattenStylesheets(stylesheets) {
623
- const list = [];
624
- for (const stylesheet of stylesheets) {
625
- if (!Array.isArray(stylesheet)) {
626
- list.push(stylesheet);
627
- }
628
- else {
629
- list.push(...flattenStylesheets(stylesheet));
688
+
689
+ /*
690
+ * Copyright (c) 2018, salesforce.com, inc.
691
+ * All rights reserved.
692
+ * SPDX-License-Identifier: MIT
693
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
694
+ */
695
+ const alreadyLoggedMessages = new Set();
696
+ // @ts-ignore
697
+ if (process.env.NODE_ENV !== 'production' && typeof __karma__ !== 'undefined') {
698
+ // @ts-ignore
699
+ window.__lwcResetAlreadyLoggedMessages = () => {
700
+ alreadyLoggedMessages.clear();
701
+ };
702
+ }
703
+ function log(method, message, vm, once) {
704
+ let msg = `[LWC ${method}]: ${message}`;
705
+ if (!isUndefined$1(vm)) {
706
+ msg = `${msg}\n${getComponentStack(vm)}`;
707
+ }
708
+ if (once) {
709
+ if (alreadyLoggedMessages.has(msg)) {
710
+ return;
630
711
  }
712
+ alreadyLoggedMessages.add(msg);
631
713
  }
632
- return list;
633
- }
634
- // Set a ref (lwc:ref) on a VM, from a template API
635
- function setRefVNode(vm, ref, vnode) {
636
- if (process.env.NODE_ENV !== 'production' && isUndefined$1(vm.refVNodes)) {
637
- throw new Error('refVNodes must be defined when setting a ref');
714
+ // In Jest tests, reduce the warning and error verbosity by not printing the callstack
715
+ if (process.env.NODE_ENV === 'test') {
716
+ /* eslint-disable-next-line no-console */
717
+ console[method](msg);
718
+ return;
638
719
  }
639
- // If this method is called, then vm.refVNodes is set as the template has refs.
640
- // If not, then something went wrong and we threw an error above.
641
- const refVNodes = vm.refVNodes;
642
- // In cases of conflict (two elements with the same ref), prefer, the last one,
643
- // in depth-first traversal order.
644
- if (!(ref in refVNodes) || refVNodes[ref].key < vnode.key) {
645
- refVNodes[ref] = vnode;
720
+ try {
721
+ throw new Error(msg);
722
+ }
723
+ catch (e) {
724
+ /* eslint-disable-next-line no-console */
725
+ console[method](e);
646
726
  }
647
727
  }
728
+ function logError(message, vm) {
729
+ log('error', message, vm, false);
730
+ }
731
+ function logWarn(message, vm) {
732
+ log('warn', message, vm, false);
733
+ }
734
+ function logWarnOnce(message, vm) {
735
+ log('warn', message, vm, true);
736
+ }
648
737
 
649
738
  /*
650
739
  * Copyright (c) 2019, salesforce.com, inc.
@@ -766,80 +855,97 @@ var LWC = (function (exports) {
766
855
  * SPDX-License-Identifier: MIT
767
856
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
768
857
  */
769
- function getComponentTag(vm) {
770
- return `<${StringToLowerCase.call(vm.tagName)}>`;
771
- }
772
- // TODO [#1695]: Unify getComponentStack and getErrorComponentStack
773
- function getComponentStack(vm) {
774
- const stack = [];
775
- let prefix = '';
776
- while (!isNull(vm.owner)) {
777
- ArrayPush$1.call(stack, prefix + getComponentTag(vm));
778
- vm = vm.owner;
779
- prefix += '\t';
780
- }
781
- return ArrayJoin.call(stack, '\n');
782
- }
783
- function getErrorComponentStack(vm) {
784
- const wcStack = [];
785
- let currentVm = vm;
786
- while (!isNull(currentVm)) {
787
- ArrayPush$1.call(wcStack, getComponentTag(currentVm));
788
- currentVm = currentVm.owner;
858
+ let nextTickCallbackQueue = [];
859
+ const SPACE_CHAR = 32;
860
+ const EmptyObject = seal(create(null));
861
+ const EmptyArray = seal([]);
862
+ function flushCallbackQueue() {
863
+ if (process.env.NODE_ENV !== 'production') {
864
+ if (nextTickCallbackQueue.length === 0) {
865
+ throw new Error(`Internal Error: If callbackQueue is scheduled, it is because there must be at least one callback on this pending queue.`);
866
+ }
789
867
  }
790
- return wcStack.reverse().join('\n\t');
791
- }
792
-
793
- /*
794
- * Copyright (c) 2018, salesforce.com, inc.
795
- * All rights reserved.
796
- * SPDX-License-Identifier: MIT
797
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
798
- */
799
- function addErrorComponentStack(vm, error) {
800
- if (!isFrozen(error) && isUndefined$1(error.wcStack)) {
801
- const wcStack = getErrorComponentStack(vm);
802
- defineProperty(error, 'wcStack', {
803
- get() {
804
- return wcStack;
805
- },
806
- });
868
+ const callbacks = nextTickCallbackQueue;
869
+ nextTickCallbackQueue = []; // reset to a new queue
870
+ for (let i = 0, len = callbacks.length; i < len; i += 1) {
871
+ callbacks[i]();
807
872
  }
808
873
  }
809
-
810
- /*
811
- * Copyright (c) 2018, salesforce.com, inc.
812
- * All rights reserved.
813
- * SPDX-License-Identifier: MIT
814
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
815
- */
816
- function log(method, message, vm) {
817
- let msg = `[LWC ${method}]: ${message}`;
818
- if (!isUndefined$1(vm)) {
819
- msg = `${msg}\n${getComponentStack(vm)}`;
820
- }
821
- if (process.env.NODE_ENV === 'test') {
822
- /* eslint-disable-next-line no-console */
823
- console[method](msg);
824
- return;
825
- }
826
- try {
827
- throw new Error(msg);
874
+ function addCallbackToNextTick(callback) {
875
+ if (process.env.NODE_ENV !== 'production') {
876
+ if (!isFunction$1(callback)) {
877
+ throw new Error(`Internal Error: addCallbackToNextTick() can only accept a function callback`);
878
+ }
828
879
  }
829
- catch (e) {
830
- /* eslint-disable-next-line no-console */
831
- console[method](e);
880
+ if (nextTickCallbackQueue.length === 0) {
881
+ Promise.resolve().then(flushCallbackQueue);
832
882
  }
883
+ ArrayPush$1.call(nextTickCallbackQueue, callback);
833
884
  }
834
- function logError(message, vm) {
835
- log('error', message, vm);
836
- }
837
- function logWarn(message, vm) {
838
- log('warn', message, vm);
885
+ function guid() {
886
+ function s4() {
887
+ return Math.floor((1 + Math.random()) * 0x10000)
888
+ .toString(16)
889
+ .substring(1);
890
+ }
891
+ return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
839
892
  }
840
-
841
- /*
842
- * Copyright (c) 2020, salesforce.com, inc.
893
+ // Borrowed from Vue template compiler.
894
+ // https://github.com/vuejs/vue/blob/531371b818b0e31a989a06df43789728f23dc4e8/src/platforms/web/util/style.js#L5-L16
895
+ const DECLARATION_DELIMITER = /;(?![^(]*\))/g;
896
+ const PROPERTY_DELIMITER = /:(.+)/;
897
+ function parseStyleText(cssText) {
898
+ const styleMap = {};
899
+ const declarations = cssText.split(DECLARATION_DELIMITER);
900
+ for (const declaration of declarations) {
901
+ if (declaration) {
902
+ const [prop, value] = declaration.split(PROPERTY_DELIMITER);
903
+ if (prop !== undefined && value !== undefined) {
904
+ styleMap[prop.trim()] = value.trim();
905
+ }
906
+ }
907
+ }
908
+ return styleMap;
909
+ }
910
+ // Make a shallow copy of an object but omit the given key
911
+ function cloneAndOmitKey(object, keyToOmit) {
912
+ const result = {};
913
+ for (const key of Object.keys(object)) {
914
+ if (key !== keyToOmit) {
915
+ result[key] = object[key];
916
+ }
917
+ }
918
+ return result;
919
+ }
920
+ function flattenStylesheets(stylesheets) {
921
+ const list = [];
922
+ for (const stylesheet of stylesheets) {
923
+ if (!Array.isArray(stylesheet)) {
924
+ list.push(stylesheet);
925
+ }
926
+ else {
927
+ list.push(...flattenStylesheets(stylesheet));
928
+ }
929
+ }
930
+ return list;
931
+ }
932
+ // Set a ref (lwc:ref) on a VM, from a template API
933
+ function setRefVNode(vm, ref, vnode) {
934
+ if (process.env.NODE_ENV !== 'production' && isUndefined$1(vm.refVNodes)) {
935
+ throw new Error('refVNodes must be defined when setting a ref');
936
+ }
937
+ // If this method is called, then vm.refVNodes is set as the template has refs.
938
+ // If not, then something went wrong and we threw an error above.
939
+ const refVNodes = vm.refVNodes;
940
+ // In cases of conflict (two elements with the same ref), prefer, the last one,
941
+ // in depth-first traversal order.
942
+ if (!(ref in refVNodes) || refVNodes[ref].key < vnode.key) {
943
+ refVNodes[ref] = vnode;
944
+ }
945
+ }
946
+
947
+ /*
948
+ * Copyright (c) 2020, salesforce.com, inc.
843
949
  * All rights reserved.
844
950
  * SPDX-License-Identifier: MIT
845
951
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
@@ -887,7 +993,10 @@ var LWC = (function (exports) {
887
993
  // Global HTML Attributes & Properties
888
994
  // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
889
995
  // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
890
- const globalHTMLProperties = assign(create(null), {
996
+ //
997
+ // If you update this list, check for test files that recapitulate the same list. Searching the codebase
998
+ // for e.g. "dropzone" should suffice.
999
+ const globalHTMLProperties = {
891
1000
  accessKey: {
892
1001
  attribute: 'accesskey',
893
1002
  },
@@ -972,7 +1081,7 @@ var LWC = (function (exports) {
972
1081
  role: {
973
1082
  attribute: 'role',
974
1083
  },
975
- });
1084
+ };
976
1085
  let controlledElement = null;
977
1086
  let controlledAttributeName;
978
1087
  function isAttributeLocked(elm, attrName) {
@@ -2434,89 +2543,377 @@ var LWC = (function (exports) {
2434
2543
  * SPDX-License-Identifier: MIT
2435
2544
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2436
2545
  */
2437
- function api$1() {
2438
- if (process.env.NODE_ENV !== 'production') {
2439
- assert.fail(`@api decorator can only be used as a decorator function.`);
2440
- }
2441
- throw new Error();
2546
+ const DeprecatedWiredElementHost = '$$DeprecatedWiredElementHostKey$$';
2547
+ const DeprecatedWiredParamsMeta = '$$DeprecatedWiredParamsMetaKey$$';
2548
+ const WIRE_DEBUG_ENTRY = '@wire';
2549
+ const WireMetaMap = new Map();
2550
+ class WireContextRegistrationEvent extends CustomEvent {
2551
+ constructor(adapterToken, {
2552
+ setNewContext,
2553
+ setDisconnectedCallback
2554
+ }) {
2555
+ super(adapterToken, {
2556
+ bubbles: true,
2557
+ composed: true
2558
+ });
2559
+ defineProperties(this, {
2560
+ setNewContext: {
2561
+ value: setNewContext
2562
+ },
2563
+ setDisconnectedCallback: {
2564
+ value: setDisconnectedCallback
2565
+ }
2566
+ });
2567
+ }
2442
2568
  }
2443
- function createPublicPropertyDescriptor(key) {
2444
- return {
2445
- get() {
2446
- const vm = getAssociatedVM(this);
2447
- if (isBeingConstructed(vm)) {
2448
- if (process.env.NODE_ENV !== 'production') {
2449
- logError(`Can’t read the value of property \`${toString$1(key)}\` from the constructor because the owner component hasn’t set the value yet. Instead, use the constructor to set a default value for the property.`, vm);
2450
- }
2451
- return;
2452
- }
2453
- componentValueObserved(vm, key);
2454
- return vm.cmpProps[key];
2455
- },
2456
- set(newValue) {
2457
- const vm = getAssociatedVM(this);
2458
- if (process.env.NODE_ENV !== 'production') {
2459
- const vmBeingRendered = getVMBeingRendered();
2460
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2461
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2462
- }
2463
- vm.cmpProps[key] = newValue;
2464
- componentValueMutated(vm, key);
2465
- },
2466
- enumerable: true,
2467
- configurable: true,
2468
- };
2569
+ function createFieldDataCallback(vm, name) {
2570
+ return value => {
2571
+ updateComponentValue(vm, name, value);
2572
+ };
2469
2573
  }
2470
- function createPublicAccessorDescriptor(key, descriptor) {
2471
- const { get, set, enumerable, configurable } = descriptor;
2472
- if (!isFunction$1(get)) {
2473
- if (process.env.NODE_ENV !== 'production') {
2474
- assert.invariant(isFunction$1(get), `Invalid compiler output for public accessor ${toString$1(key)} decorated with @api`);
2475
- }
2476
- throw new Error();
2574
+ function createMethodDataCallback(vm, method) {
2575
+ return value => {
2576
+ // dispatching new value into the wired method
2577
+ runWithBoundaryProtection(vm, vm.owner, noop, () => {
2578
+ // job
2579
+ method.call(vm.component, value);
2580
+ }, noop);
2581
+ };
2582
+ }
2583
+ function createConfigWatcher(component, configCallback, callbackWhenConfigIsReady) {
2584
+ let hasPendingConfig = false;
2585
+ // creating the reactive observer for reactive params when needed
2586
+ const ro = createReactiveObserver(() => {
2587
+ if (hasPendingConfig === false) {
2588
+ hasPendingConfig = true;
2589
+ // collect new config in the micro-task
2590
+ Promise.resolve().then(() => {
2591
+ hasPendingConfig = false;
2592
+ // resetting current reactive params
2593
+ ro.reset();
2594
+ // dispatching a new config due to a change in the configuration
2595
+ computeConfigAndUpdate();
2596
+ });
2477
2597
  }
2478
- return {
2479
- get() {
2480
- if (process.env.NODE_ENV !== 'production') {
2481
- // Assert that the this value is an actual Component with an associated VM.
2482
- getAssociatedVM(this);
2483
- }
2484
- return get.call(this);
2485
- },
2486
- set(newValue) {
2487
- const vm = getAssociatedVM(this);
2488
- if (process.env.NODE_ENV !== 'production') {
2489
- const vmBeingRendered = getVMBeingRendered();
2490
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2491
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2492
- }
2493
- if (set) {
2494
- set.call(this, newValue);
2495
- }
2496
- else if (process.env.NODE_ENV !== 'production') {
2497
- assert.fail(`Invalid attempt to set a new value for property ${toString$1(key)} of ${vm} that does not has a setter decorated with @api.`);
2498
- }
2499
- },
2500
- enumerable,
2501
- configurable,
2502
- };
2598
+ });
2599
+ const computeConfigAndUpdate = () => {
2600
+ let config;
2601
+ ro.observe(() => config = configCallback(component));
2602
+ // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
2603
+ // TODO: dev-mode validation of config based on the adapter.configSchema
2604
+ // @ts-ignore it is assigned in the observe() callback
2605
+ callbackWhenConfigIsReady(config);
2606
+ };
2607
+ return {
2608
+ computeConfigAndUpdate,
2609
+ ro
2610
+ };
2503
2611
  }
2612
+ function createContextWatcher(vm, wireDef, callbackWhenContextIsReady) {
2613
+ const {
2614
+ adapter
2615
+ } = wireDef;
2616
+ const adapterContextToken = getAdapterToken(adapter);
2617
+ if (isUndefined$1(adapterContextToken)) {
2618
+ return; // no provider found, nothing to be done
2619
+ }
2504
2620
 
2505
- /*
2506
- * Copyright (c) 2018, salesforce.com, inc.
2507
- * All rights reserved.
2508
- * SPDX-License-Identifier: MIT
2509
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2510
- */
2511
- function track(target) {
2512
- if (arguments.length === 1) {
2513
- return getReactiveProxy(target);
2621
+ const {
2622
+ elm,
2623
+ context: {
2624
+ wiredConnecting,
2625
+ wiredDisconnecting
2626
+ },
2627
+ renderer: {
2628
+ dispatchEvent
2514
2629
  }
2630
+ } = vm;
2631
+ // waiting for the component to be connected to formally request the context via the token
2632
+ ArrayPush$1.call(wiredConnecting, () => {
2633
+ // This event is responsible for connecting the host element with another
2634
+ // element in the composed path that is providing contextual data. The provider
2635
+ // must be listening for a special dom event with the name corresponding to the value of
2636
+ // `adapterContextToken`, which will remain secret and internal to this file only to
2637
+ // guarantee that the linkage can be forged.
2638
+ const contextRegistrationEvent = new WireContextRegistrationEvent(adapterContextToken, {
2639
+ setNewContext(newContext) {
2640
+ // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
2641
+ // TODO: dev-mode validation of config based on the adapter.contextSchema
2642
+ callbackWhenContextIsReady(newContext);
2643
+ },
2644
+ setDisconnectedCallback(disconnectCallback) {
2645
+ // adds this callback into the disconnect bucket so it gets disconnected from parent
2646
+ // the the element hosting the wire is disconnected
2647
+ ArrayPush$1.call(wiredDisconnecting, disconnectCallback);
2648
+ }
2649
+ });
2650
+ dispatchEvent(elm, contextRegistrationEvent);
2651
+ });
2652
+ }
2653
+ function createConnector(vm, name, wireDef) {
2654
+ const {
2655
+ method,
2656
+ adapter,
2657
+ configCallback,
2658
+ dynamic
2659
+ } = wireDef;
2660
+ let debugInfo;
2661
+ if (process.env.NODE_ENV !== 'production') {
2662
+ const wiredPropOrMethod = isUndefined$1(method) ? name : method.name;
2663
+ debugInfo = create(null);
2664
+ debugInfo.wasDataProvisionedForConfig = false;
2665
+ vm.debugInfo[WIRE_DEBUG_ENTRY][wiredPropOrMethod] = debugInfo;
2666
+ }
2667
+ const fieldOrMethodCallback = isUndefined$1(method) ? createFieldDataCallback(vm, name) : createMethodDataCallback(vm, method);
2668
+ const dataCallback = value => {
2515
2669
  if (process.env.NODE_ENV !== 'production') {
2516
- assert.fail(`@track decorator can only be used with one argument to return a trackable object, or as a decorator function.`);
2670
+ debugInfo.data = value;
2671
+ // Note: most of the time, the data provided is for the current config, but there may be
2672
+ // some conditions in which it does not, ex:
2673
+ // race conditions in a poor network while the adapter does not cancel a previous request.
2674
+ debugInfo.wasDataProvisionedForConfig = true;
2517
2675
  }
2518
- throw new Error();
2519
- }
2676
+ fieldOrMethodCallback(value);
2677
+ };
2678
+ let context;
2679
+ let connector;
2680
+ // Workaround to pass the component element associated to this wire adapter instance.
2681
+ defineProperty(dataCallback, DeprecatedWiredElementHost, {
2682
+ value: vm.elm
2683
+ });
2684
+ defineProperty(dataCallback, DeprecatedWiredParamsMeta, {
2685
+ value: dynamic
2686
+ });
2687
+ runWithBoundaryProtection(vm, vm, noop, () => {
2688
+ // job
2689
+ connector = new adapter(dataCallback);
2690
+ }, noop);
2691
+ const updateConnectorConfig = config => {
2692
+ // every time the config is recomputed due to tracking,
2693
+ // this callback will be invoked with the new computed config
2694
+ runWithBoundaryProtection(vm, vm, noop, () => {
2695
+ // job
2696
+ if (process.env.NODE_ENV !== 'production') {
2697
+ debugInfo.config = config;
2698
+ debugInfo.context = context;
2699
+ debugInfo.wasDataProvisionedForConfig = false;
2700
+ }
2701
+ connector.update(config, context);
2702
+ }, noop);
2703
+ };
2704
+ // Computes the current wire config and calls the update method on the wire adapter.
2705
+ // If it has params, we will need to observe changes in the next tick.
2706
+ const {
2707
+ computeConfigAndUpdate,
2708
+ ro
2709
+ } = createConfigWatcher(vm.component, configCallback, updateConnectorConfig);
2710
+ // if the adapter needs contextualization, we need to watch for new context and push it alongside the config
2711
+ if (!isUndefined$1(adapter.contextSchema)) {
2712
+ createContextWatcher(vm, wireDef, newContext => {
2713
+ // every time the context is pushed into this component,
2714
+ // this callback will be invoked with the new computed context
2715
+ if (context !== newContext) {
2716
+ context = newContext;
2717
+ // Note: when new context arrives, the config will be recomputed and pushed along side the new
2718
+ // context, this is to preserve the identity characteristics, config should not have identity
2719
+ // (ever), while context can have identity
2720
+ if (vm.state === 1 /* VMState.connected */) {
2721
+ computeConfigAndUpdate();
2722
+ }
2723
+ }
2724
+ });
2725
+ }
2726
+ return {
2727
+ // @ts-ignore the boundary protection executes sync, connector is always defined
2728
+ connector,
2729
+ computeConfigAndUpdate,
2730
+ resetConfigWatcher: () => ro.reset()
2731
+ };
2732
+ }
2733
+ const AdapterToTokenMap = new Map();
2734
+ function getAdapterToken(adapter) {
2735
+ return AdapterToTokenMap.get(adapter);
2736
+ }
2737
+ function setAdapterToken(adapter, token) {
2738
+ AdapterToTokenMap.set(adapter, token);
2739
+ }
2740
+ function storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic) {
2741
+ // support for callable adapters
2742
+ if (adapter.adapter) {
2743
+ adapter = adapter.adapter;
2744
+ }
2745
+ const method = descriptor.value;
2746
+ const def = {
2747
+ adapter,
2748
+ method,
2749
+ configCallback,
2750
+ dynamic
2751
+ };
2752
+ WireMetaMap.set(descriptor, def);
2753
+ }
2754
+ function storeWiredFieldMeta(descriptor, adapter, configCallback, dynamic) {
2755
+ // support for callable adapters
2756
+ if (adapter.adapter) {
2757
+ adapter = adapter.adapter;
2758
+ }
2759
+ const def = {
2760
+ adapter,
2761
+ configCallback,
2762
+ dynamic
2763
+ };
2764
+ WireMetaMap.set(descriptor, def);
2765
+ }
2766
+ function installWireAdapters(vm) {
2767
+ const {
2768
+ context,
2769
+ def: {
2770
+ wire
2771
+ }
2772
+ } = vm;
2773
+ if (process.env.NODE_ENV !== 'production') {
2774
+ vm.debugInfo[WIRE_DEBUG_ENTRY] = create(null);
2775
+ }
2776
+ const wiredConnecting = context.wiredConnecting = [];
2777
+ const wiredDisconnecting = context.wiredDisconnecting = [];
2778
+ for (const fieldNameOrMethod in wire) {
2779
+ const descriptor = wire[fieldNameOrMethod];
2780
+ const wireDef = WireMetaMap.get(descriptor);
2781
+ if (process.env.NODE_ENV !== 'production') {
2782
+ assert.invariant(wireDef, `Internal Error: invalid wire definition found.`);
2783
+ }
2784
+ if (!isUndefined$1(wireDef)) {
2785
+ const {
2786
+ connector,
2787
+ computeConfigAndUpdate,
2788
+ resetConfigWatcher
2789
+ } = createConnector(vm, fieldNameOrMethod, wireDef);
2790
+ const hasDynamicParams = wireDef.dynamic.length > 0;
2791
+ ArrayPush$1.call(wiredConnecting, () => {
2792
+ connector.connect();
2793
+ if (!lwcRuntimeFlags.ENABLE_WIRE_SYNC_EMIT) {
2794
+ if (hasDynamicParams) {
2795
+ Promise.resolve().then(computeConfigAndUpdate);
2796
+ return;
2797
+ }
2798
+ }
2799
+ computeConfigAndUpdate();
2800
+ });
2801
+ ArrayPush$1.call(wiredDisconnecting, () => {
2802
+ connector.disconnect();
2803
+ resetConfigWatcher();
2804
+ });
2805
+ }
2806
+ }
2807
+ }
2808
+ function connectWireAdapters(vm) {
2809
+ const {
2810
+ wiredConnecting
2811
+ } = vm.context;
2812
+ for (let i = 0, len = wiredConnecting.length; i < len; i += 1) {
2813
+ wiredConnecting[i]();
2814
+ }
2815
+ }
2816
+ function disconnectWireAdapters(vm) {
2817
+ const {
2818
+ wiredDisconnecting
2819
+ } = vm.context;
2820
+ runWithBoundaryProtection(vm, vm, noop, () => {
2821
+ // job
2822
+ for (let i = 0, len = wiredDisconnecting.length; i < len; i += 1) {
2823
+ wiredDisconnecting[i]();
2824
+ }
2825
+ }, noop);
2826
+ }
2827
+
2828
+ /*
2829
+ * Copyright (c) 2018, salesforce.com, inc.
2830
+ * All rights reserved.
2831
+ * SPDX-License-Identifier: MIT
2832
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2833
+ */
2834
+ function api$1() {
2835
+ if (process.env.NODE_ENV !== 'production') {
2836
+ assert.fail(`@api decorator can only be used as a decorator function.`);
2837
+ }
2838
+ throw new Error();
2839
+ }
2840
+ function createPublicPropertyDescriptor(key) {
2841
+ return {
2842
+ get() {
2843
+ const vm = getAssociatedVM(this);
2844
+ if (isBeingConstructed(vm)) {
2845
+ if (process.env.NODE_ENV !== 'production') {
2846
+ logError(`Can’t read the value of property \`${toString$1(key)}\` from the constructor because the owner component hasn’t set the value yet. Instead, use the constructor to set a default value for the property.`, vm);
2847
+ }
2848
+ return;
2849
+ }
2850
+ componentValueObserved(vm, key);
2851
+ return vm.cmpProps[key];
2852
+ },
2853
+ set(newValue) {
2854
+ const vm = getAssociatedVM(this);
2855
+ if (process.env.NODE_ENV !== 'production') {
2856
+ const vmBeingRendered = getVMBeingRendered();
2857
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2858
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2859
+ }
2860
+ vm.cmpProps[key] = newValue;
2861
+ componentValueMutated(vm, key);
2862
+ },
2863
+ enumerable: true,
2864
+ configurable: true,
2865
+ };
2866
+ }
2867
+ function createPublicAccessorDescriptor(key, descriptor) {
2868
+ const { get, set, enumerable, configurable } = descriptor;
2869
+ if (!isFunction$1(get)) {
2870
+ if (process.env.NODE_ENV !== 'production') {
2871
+ assert.invariant(isFunction$1(get), `Invalid compiler output for public accessor ${toString$1(key)} decorated with @api`);
2872
+ }
2873
+ throw new Error();
2874
+ }
2875
+ return {
2876
+ get() {
2877
+ if (process.env.NODE_ENV !== 'production') {
2878
+ // Assert that the this value is an actual Component with an associated VM.
2879
+ getAssociatedVM(this);
2880
+ }
2881
+ return get.call(this);
2882
+ },
2883
+ set(newValue) {
2884
+ const vm = getAssociatedVM(this);
2885
+ if (process.env.NODE_ENV !== 'production') {
2886
+ const vmBeingRendered = getVMBeingRendered();
2887
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2888
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2889
+ }
2890
+ if (set) {
2891
+ set.call(this, newValue);
2892
+ }
2893
+ else if (process.env.NODE_ENV !== 'production') {
2894
+ assert.fail(`Invalid attempt to set a new value for property ${toString$1(key)} of ${vm} that does not has a setter decorated with @api.`);
2895
+ }
2896
+ },
2897
+ enumerable,
2898
+ configurable,
2899
+ };
2900
+ }
2901
+
2902
+ /*
2903
+ * Copyright (c) 2018, salesforce.com, inc.
2904
+ * All rights reserved.
2905
+ * SPDX-License-Identifier: MIT
2906
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2907
+ */
2908
+ function track(target) {
2909
+ if (arguments.length === 1) {
2910
+ return getReactiveProxy(target);
2911
+ }
2912
+ if (process.env.NODE_ENV !== 'production') {
2913
+ assert.fail(`@track decorator can only be used with one argument to return a trackable object, or as a decorator function.`);
2914
+ }
2915
+ throw new Error();
2916
+ }
2520
2917
  function internalTrackDecorator(key) {
2521
2918
  return {
2522
2919
  get() {
@@ -3479,6 +3876,9 @@ var LWC = (function (exports) {
3479
3876
  stylesheets: newStylesheets,
3480
3877
  stylesheetToken: newStylesheetToken
3481
3878
  } = template;
3879
+ const {
3880
+ stylesheets: newVmStylesheets
3881
+ } = vm;
3482
3882
  const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
3483
3883
  const {
3484
3884
  hasScopedStyles
@@ -3502,7 +3902,9 @@ var LWC = (function (exports) {
3502
3902
  }
3503
3903
  // Apply the new template styling token to the host element, if the new template has any
3504
3904
  // 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) {
3905
+ const hasNewStylesheets = hasStyles(newStylesheets);
3906
+ const hasNewVmStylesheets = hasStyles(newVmStylesheets);
3907
+ if (hasNewStylesheets || hasNewVmStylesheets) {
3506
3908
  newToken = newStylesheetToken;
3507
3909
  }
3508
3910
  // Set the new styling token on the host element
@@ -3574,10 +3976,17 @@ var LWC = (function (exports) {
3574
3976
  stylesheets,
3575
3977
  stylesheetToken
3576
3978
  } = template;
3979
+ const {
3980
+ stylesheets: vmStylesheets
3981
+ } = vm;
3577
3982
  let content = [];
3578
- if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
3983
+ if (hasStyles(stylesheets)) {
3579
3984
  content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
3580
3985
  }
3986
+ // VM (component) stylesheets apply after template stylesheets
3987
+ if (hasStyles(vmStylesheets)) {
3988
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
3989
+ }
3581
3990
  return content;
3582
3991
  }
3583
3992
  // It might be worth caching this to avoid doing the lookup repeatedly, but
@@ -3615,10 +4024,13 @@ var LWC = (function (exports) {
3615
4024
  const {
3616
4025
  template
3617
4026
  } = getComponentInternalDef(vnode.ctor);
4027
+ const {
4028
+ vm
4029
+ } = vnode;
3618
4030
  const {
3619
4031
  stylesheetToken
3620
4032
  } = template;
3621
- return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template) ? makeHostToken(stylesheetToken) : null;
4033
+ return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template, vm) ? makeHostToken(stylesheetToken) : null;
3622
4034
  }
3623
4035
  function getNearestNativeShadowComponent(vm) {
3624
4036
  const owner = getNearestShadowComponent(vm);
@@ -4231,6 +4643,28 @@ var LWC = (function (exports) {
4231
4643
  // in fallback mode, the allocation will always set children to
4232
4644
  // empty and delegate the real allocation to the slot elements
4233
4645
  allocateChildren(n2, vm);
4646
+ // Solves an edge case with slotted VFragments in native shadow mode.
4647
+ //
4648
+ // During allocation, in native shadow, slotted VFragment nodes are flattened and their text delimiters are removed
4649
+ // to avoid interfering with native slot behavior. When this happens, if any of the fragments
4650
+ // were not stable, the children must go through the dynamic diffing algo.
4651
+ //
4652
+ // If the new children (n2.children) contain no VFragments, but the previous children (n1.children) were dynamic,
4653
+ // the new nodes must be marked dynamic so that all nodes are properly updated. The only indicator that the new
4654
+ // nodes need to be dynamic comes from the previous children, so we check that to determine whether we need to
4655
+ // mark the new children dynamic.
4656
+ //
4657
+ // Example:
4658
+ // n1.children: [div, VFragment('', div, null, ''), div] => [div, div, null, div]; // marked dynamic
4659
+ // n2.children: [div, null, div] => [div, null, div] // marked ???
4660
+ const {
4661
+ shadowMode,
4662
+ renderMode
4663
+ } = vm;
4664
+ if (shadowMode == 0 /* ShadowMode.Native */ && renderMode !== 0 /* RenderMode.Light */ && hasDynamicChildren(n1.children)) {
4665
+ // No-op if children has already been marked dynamic by 'allocateChildren()'.
4666
+ markAsDynamicChildren(n2.children);
4667
+ }
4234
4668
  }
4235
4669
  // in fallback mode, the children will be always empty, so, nothing
4236
4670
  // will happen, but in native, it does allocate the light dom
@@ -4423,7 +4857,6 @@ var LWC = (function (exports) {
4423
4857
  //
4424
4858
  // In case #2, we will always get a fresh VCustomElement.
4425
4859
  const children = vnode.aChildren || vnode.children;
4426
- vm.aChildren = children;
4427
4860
  const {
4428
4861
  renderMode,
4429
4862
  shadowMode
@@ -4436,20 +4869,66 @@ var LWC = (function (exports) {
4436
4869
  logError(`Invalid usage of 'lwc:slot-data' on ${getComponentTag(vm)} tag. Scoped slot content can only be passed to a light dom child.`);
4437
4870
  }
4438
4871
  }
4872
+ // If any of the children being allocated are VFragments, we remove the text delimiters and flatten all immediate
4873
+ // children VFragments to avoid them interfering with default slot behavior.
4874
+ const allocatedChildren = flattenFragmentsInChildren(children);
4875
+ vnode.children = allocatedChildren;
4876
+ vm.aChildren = allocatedChildren;
4439
4877
  if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
4440
4878
  // slow path
4441
- allocateInSlot(vm, children, vnode.owner);
4879
+ allocateInSlot(vm, allocatedChildren, vnode.owner);
4442
4880
  // save the allocated children in case this vnode is reused.
4443
- vnode.aChildren = children;
4881
+ vnode.aChildren = allocatedChildren;
4444
4882
  // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
4445
4883
  vnode.children = EmptyArray;
4446
4884
  }
4447
4885
  }
4448
- function createViewModelHook(elm, vnode, renderer) {
4449
- let vm = getAssociatedVMIfPresent(elm);
4450
- // There is a possibility that a custom element is registered under tagName, in which case, the
4451
- // initialization is already carry on, and there is nothing else to do here since this hook is
4452
- // called right after invoking `document.createElement`.
4886
+ /**
4887
+ * Flattens the contents of all VFragments in an array of VNodes, removes the text delimiters on those VFragments, and
4888
+ * marks the resulting children array as dynamic. Uses a stack (array) to iteratively traverse the nested VFragments
4889
+ * and avoid the perf overhead of creating/destroying throwaway arrays/objects in a recursive approach.
4890
+ *
4891
+ * With the delimiters removed, the contents are marked dynamic so they are diffed correctly.
4892
+ *
4893
+ * This function is used for slotted VFragments to avoid the text delimiters interfering with slotting functionality.
4894
+ */
4895
+ function flattenFragmentsInChildren(children) {
4896
+ const flattenedChildren = [];
4897
+ // Initialize our stack with the direct children of the custom component and check whether we have a VFragment.
4898
+ // If no VFragment is found in children, we don't need to traverse anything or mark the children dynamic and can return early.
4899
+ const nodeStack = [];
4900
+ let fragmentFound = false;
4901
+ for (let i = children.length - 1; i > -1; i -= 1) {
4902
+ const child = children[i];
4903
+ ArrayPush$1.call(nodeStack, child);
4904
+ fragmentFound = fragmentFound || !!(child && isVFragment(child));
4905
+ }
4906
+ if (!fragmentFound) {
4907
+ return children;
4908
+ }
4909
+ let currentNode;
4910
+ while (!isUndefined$1(currentNode = ArrayPop.call(nodeStack))) {
4911
+ if (!isNull(currentNode) && isVFragment(currentNode)) {
4912
+ const fChildren = currentNode.children;
4913
+ // Ignore the start and end text node delimiters
4914
+ for (let i = fChildren.length - 2; i > 0; i -= 1) {
4915
+ ArrayPush$1.call(nodeStack, fChildren[i]);
4916
+ }
4917
+ } else {
4918
+ ArrayPush$1.call(flattenedChildren, currentNode);
4919
+ }
4920
+ }
4921
+ // We always mark the children as dynamic because nothing generates stable VFragments yet.
4922
+ // If/when stable VFragments are generated by the compiler, this code should be updated to
4923
+ // not mark dynamic if all flattened VFragments were stable.
4924
+ markAsDynamicChildren(flattenedChildren);
4925
+ return flattenedChildren;
4926
+ }
4927
+ function createViewModelHook(elm, vnode, renderer) {
4928
+ let vm = getAssociatedVMIfPresent(elm);
4929
+ // There is a possibility that a custom element is registered under tagName, in which case, the
4930
+ // initialization is already carry on, and there is nothing else to do here since this hook is
4931
+ // called right after invoking `document.createElement`.
4453
4932
  if (!isUndefined$1(vm)) {
4454
4933
  return vm;
4455
4934
  }
@@ -4469,22 +4948,20 @@ var LWC = (function (exports) {
4469
4948
  }
4470
4949
  return vm;
4471
4950
  }
4472
- /**
4473
- * Collects all slots into a SlotSet, traversing through VFragment Nodes
4474
- */
4475
- function collectSlots(vm, children, cmpSlotsMapping) {
4951
+ function allocateInSlot(vm, children, owner) {
4476
4952
  var _a, _b;
4953
+ const {
4954
+ cmpSlots: {
4955
+ slotAssignments: oldSlotsMapping
4956
+ }
4957
+ } = vm;
4958
+ const cmpSlotsMapping = create(null);
4959
+ // Collect all slots into cmpSlotsMapping
4477
4960
  for (let i = 0, len = children.length; i < len; i += 1) {
4478
4961
  const vnode = children[i];
4479
4962
  if (isNull(vnode)) {
4480
4963
  continue;
4481
4964
  }
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
4965
  let slotName = '';
4489
4966
  if (isVBaseElement(vnode)) {
4490
4967
  slotName = (_b = (_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : '';
@@ -4494,15 +4971,6 @@ var LWC = (function (exports) {
4494
4971
  const vnodes = cmpSlotsMapping[slotName] = cmpSlotsMapping[slotName] || [];
4495
4972
  ArrayPush$1.call(vnodes, vnode);
4496
4973
  }
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
4974
  vm.cmpSlots = {
4507
4975
  owner,
4508
4976
  slotAssignments: cmpSlotsMapping
@@ -4533,14 +5001,14 @@ var LWC = (function (exports) {
4533
5001
  }
4534
5002
  }
4535
5003
  // 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.
5004
+ const DynamicChildren = new WeakMap();
5005
+ // dynamic children means it was either generated by an iteration in a template
5006
+ // or part of an unstable fragment, and will require a more complex diffing algo.
4539
5007
  function markAsDynamicChildren(children) {
4540
- FromIteration.set(children, 1);
5008
+ DynamicChildren.set(children, 1);
4541
5009
  }
4542
5010
  function hasDynamicChildren(children) {
4543
- return FromIteration.has(children);
5011
+ return DynamicChildren.has(children);
4544
5012
  }
4545
5013
  function createKeyToOldIdx(children, beginIdx, endIdx) {
4546
5014
  const map = {};
@@ -5406,7 +5874,7 @@ var LWC = (function (exports) {
5406
5874
  // Create a brand new template cache for the swapped templated.
5407
5875
  context.tplCache = create(null);
5408
5876
  // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
5409
- context.hasScopedStyles = computeHasScopedStyles(html);
5877
+ context.hasScopedStyles = computeHasScopedStyles(html, vm);
5410
5878
  // Update the scoping token on the host element.
5411
5879
  updateStylesheetToken(vm, html);
5412
5880
  // Evaluate, create stylesheet and cache the produced VNode for future
@@ -5449,9 +5917,8 @@ var LWC = (function (exports) {
5449
5917
  }
5450
5918
  return vnodes;
5451
5919
  }
5452
- function computeHasScopedStyles(template) {
5453
- const { stylesheets } = template;
5454
- if (!isUndefined$1(stylesheets)) {
5920
+ function computeHasScopedStylesInStylesheets(stylesheets) {
5921
+ if (hasStyles(stylesheets)) {
5455
5922
  for (let i = 0; i < stylesheets.length; i++) {
5456
5923
  if (isTrue(stylesheets[i][KEY__SCOPED_CSS])) {
5457
5924
  return true;
@@ -5460,6 +5927,15 @@ var LWC = (function (exports) {
5460
5927
  }
5461
5928
  return false;
5462
5929
  }
5930
+ function computeHasScopedStyles(template, vm) {
5931
+ const { stylesheets } = template;
5932
+ const vmStylesheets = !isUndefined$1(vm) ? vm.stylesheets : null;
5933
+ return (computeHasScopedStylesInStylesheets(stylesheets) ||
5934
+ computeHasScopedStylesInStylesheets(vmStylesheets));
5935
+ }
5936
+ function hasStyles(stylesheets) {
5937
+ return !isUndefined$1(stylesheets) && !isNull(stylesheets) && stylesheets.length > 0;
5938
+ }
5463
5939
 
5464
5940
  /*
5465
5941
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5775,6 +6251,7 @@ var LWC = (function (exports) {
5775
6251
  // Properties set right after VM creation.
5776
6252
  tro: null,
5777
6253
  shadowMode: null,
6254
+ stylesheets: null,
5778
6255
  // Properties set by the LightningElement constructor.
5779
6256
  component: null,
5780
6257
  shadowRoot: null,
@@ -5787,6 +6264,7 @@ var LWC = (function (exports) {
5787
6264
  if (process.env.NODE_ENV !== 'production') {
5788
6265
  vm.debugInfo = create(null);
5789
6266
  }
6267
+ vm.stylesheets = computeStylesheets(vm, def.ctor);
5790
6268
  vm.shadowMode = computeShadowMode(vm, renderer);
5791
6269
  vm.tro = getTemplateReactiveObserver(vm);
5792
6270
  if (process.env.NODE_ENV !== 'production') {
@@ -5805,6 +6283,42 @@ var LWC = (function (exports) {
5805
6283
  }
5806
6284
  return vm;
5807
6285
  }
6286
+ function validateComponentStylesheets(vm, stylesheets) {
6287
+ let valid = true;
6288
+ const validate = arrayOrStylesheet => {
6289
+ if (isArray$1(arrayOrStylesheet)) {
6290
+ for (let i = 0; i < arrayOrStylesheet.length; i++) {
6291
+ validate(arrayOrStylesheet[i]);
6292
+ }
6293
+ } else if (!isFunction$1(arrayOrStylesheet)) {
6294
+ // function assumed to be a stylesheet factory
6295
+ valid = false;
6296
+ }
6297
+ };
6298
+ if (!isArray$1(stylesheets)) {
6299
+ valid = false;
6300
+ } else {
6301
+ validate(stylesheets);
6302
+ }
6303
+ return valid;
6304
+ }
6305
+ // Validate and flatten any stylesheets defined as `static stylesheets`
6306
+ function computeStylesheets(vm, ctor) {
6307
+ if (lwcRuntimeFlags.ENABLE_PROGRAMMATIC_STYLESHEETS) {
6308
+ const {
6309
+ stylesheets
6310
+ } = ctor;
6311
+ if (!isUndefined$1(stylesheets)) {
6312
+ const valid = validateComponentStylesheets(vm, stylesheets);
6313
+ if (valid) {
6314
+ return flattenStylesheets(stylesheets);
6315
+ } else if (process.env.NODE_ENV !== 'production') {
6316
+ logError(`static stylesheets must be an array of CSS stylesheets. Found invalid stylesheets on <${vm.tagName}>`, vm);
6317
+ }
6318
+ }
6319
+ }
6320
+ return null;
6321
+ }
5808
6322
  function computeShadowMode(vm, renderer) {
5809
6323
  const {
5810
6324
  def
@@ -6047,411 +6561,268 @@ var LWC = (function (exports) {
6047
6561
  // in the case where the VM failed in the middle of its creation,
6048
6562
  // eg: constructor throwing before invoking super().
6049
6563
  if (!isUndefined$1(childVM)) {
6050
- resetComponentStateWhenRemoved(childVM);
6051
- }
6052
- }
6053
- }
6054
- }
6055
- function runLightChildNodesDisconnectedCallback(vm) {
6056
- const {
6057
- aChildren: adoptedChildren
6058
- } = vm;
6059
- recursivelyDisconnectChildren(adoptedChildren);
6060
- }
6061
- /**
6062
- * The recursion doesn't need to be a complete traversal of the vnode graph,
6063
- * instead it can be partial, when a custom element vnode is found, we don't
6064
- * need to continue into its children because by attempting to disconnect the
6065
- * custom element itself will trigger the removal of anything slotted or anything
6066
- * defined on its shadow.
6067
- */
6068
- function recursivelyDisconnectChildren(vnodes) {
6069
- for (let i = 0, len = vnodes.length; i < len; i += 1) {
6070
- const vnode = vnodes[i];
6071
- if (!isNull(vnode) && !isUndefined$1(vnode.elm)) {
6072
- switch (vnode.type) {
6073
- case 2 /* VNodeType.Element */:
6074
- recursivelyDisconnectChildren(vnode.children);
6075
- break;
6076
- case 3 /* VNodeType.CustomElement */:
6077
- {
6078
- const vm = getAssociatedVM(vnode.elm);
6079
- resetComponentStateWhenRemoved(vm);
6080
- break;
6081
- }
6082
- }
6083
- }
6084
- }
6085
- }
6086
- // This is a super optimized mechanism to remove the content of the root node (shadow root
6087
- // for shadow DOM components and the root element itself for light DOM) without having to go
6088
- // into snabbdom. Especially useful when the reset is a consequence of an error, in which case the
6089
- // children VNodes might not be representing the current state of the DOM.
6090
- function resetComponentRoot(vm) {
6091
- const {
6092
- children,
6093
- renderRoot,
6094
- renderer: {
6095
- remove
6096
- }
6097
- } = vm;
6098
- for (let i = 0, len = children.length; i < len; i++) {
6099
- const child = children[i];
6100
- if (!isNull(child) && !isUndefined$1(child.elm)) {
6101
- remove(child.elm, renderRoot);
6102
- }
6103
- }
6104
- vm.children = EmptyArray;
6105
- runChildNodesDisconnectedCallback(vm);
6106
- vm.velements = EmptyArray;
6107
- }
6108
- function scheduleRehydration(vm) {
6109
- if (isTrue(vm.isScheduled)) {
6110
- return;
6111
- }
6112
- vm.isScheduled = true;
6113
- if (rehydrateQueue.length === 0) {
6114
- addCallbackToNextTick(flushRehydrationQueue);
6115
- }
6116
- ArrayPush$1.call(rehydrateQueue, vm);
6117
- }
6118
- function getErrorBoundaryVM(vm) {
6119
- let currentVm = vm;
6120
- while (!isNull(currentVm)) {
6121
- if (!isUndefined$1(currentVm.def.errorCallback)) {
6122
- return currentVm;
6123
- }
6124
- currentVm = currentVm.owner;
6125
- }
6126
- }
6127
- function runWithBoundaryProtection(vm, owner, pre, job, post) {
6128
- let error;
6129
- pre();
6130
- try {
6131
- job();
6132
- } catch (e) {
6133
- error = Object(e);
6134
- } finally {
6135
- post();
6136
- if (!isUndefined$1(error)) {
6137
- addErrorComponentStack(vm, error);
6138
- const errorBoundaryVm = isNull(owner) ? undefined : getErrorBoundaryVM(owner);
6139
- if (isUndefined$1(errorBoundaryVm)) {
6140
- throw error; // eslint-disable-line no-unsafe-finally
6141
- }
6142
-
6143
- resetComponentRoot(vm); // remove offenders
6144
- logOperationStart(6 /* OperationId.ErrorCallback */, vm);
6145
- // error boundaries must have an ErrorCallback
6146
- const errorCallback = errorBoundaryVm.def.errorCallback;
6147
- invokeComponentCallback(errorBoundaryVm, errorCallback, [error, error.wcStack]);
6148
- logOperationEnd(6 /* OperationId.ErrorCallback */, vm);
6149
- }
6150
- }
6151
- }
6152
- function forceRehydration(vm) {
6153
- // if we must reset the shadowRoot content and render the template
6154
- // from scratch on an active instance, the way to force the reset
6155
- // is by replacing the value of old template, which is used during
6156
- // to determine if the template has changed or not during the rendering
6157
- // process. If the template returned by render() is different from the
6158
- // previous stored template, the styles will be reset, along with the
6159
- // content of the shadowRoot, this way we can guarantee that all children
6160
- // elements will be throw away, and new instances will be created.
6161
- vm.cmpTemplate = () => [];
6162
- if (isFalse(vm.isDirty)) {
6163
- // forcing the vm to rehydrate in the next tick
6164
- markComponentAsDirty(vm);
6165
- scheduleRehydration(vm);
6166
- }
6167
- }
6168
-
6169
- /*
6170
- * Copyright (c) 2018, salesforce.com, inc.
6171
- * All rights reserved.
6172
- * SPDX-License-Identifier: MIT
6173
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6174
- */
6175
- const DeprecatedWiredElementHost = '$$DeprecatedWiredElementHostKey$$';
6176
- const DeprecatedWiredParamsMeta = '$$DeprecatedWiredParamsMetaKey$$';
6177
- const WIRE_DEBUG_ENTRY = '@wire';
6178
- const WireMetaMap = new Map();
6179
- class WireContextRegistrationEvent extends CustomEvent {
6180
- constructor(adapterToken, {
6181
- setNewContext,
6182
- setDisconnectedCallback
6183
- }) {
6184
- super(adapterToken, {
6185
- bubbles: true,
6186
- composed: true
6187
- });
6188
- defineProperties(this, {
6189
- setNewContext: {
6190
- value: setNewContext
6191
- },
6192
- setDisconnectedCallback: {
6193
- value: setDisconnectedCallback
6194
- }
6195
- });
6196
- }
6197
- }
6198
- function createFieldDataCallback(vm, name) {
6199
- return value => {
6200
- updateComponentValue(vm, name, value);
6201
- };
6202
- }
6203
- function createMethodDataCallback(vm, method) {
6204
- return value => {
6205
- // dispatching new value into the wired method
6206
- runWithBoundaryProtection(vm, vm.owner, noop, () => {
6207
- // job
6208
- method.call(vm.component, value);
6209
- }, noop);
6210
- };
6211
- }
6212
- function createConfigWatcher(component, configCallback, callbackWhenConfigIsReady) {
6213
- let hasPendingConfig = false;
6214
- // creating the reactive observer for reactive params when needed
6215
- const ro = createReactiveObserver(() => {
6216
- if (hasPendingConfig === false) {
6217
- hasPendingConfig = true;
6218
- // collect new config in the micro-task
6219
- Promise.resolve().then(() => {
6220
- hasPendingConfig = false;
6221
- // resetting current reactive params
6222
- ro.reset();
6223
- // dispatching a new config due to a change in the configuration
6224
- computeConfigAndUpdate();
6225
- });
6226
- }
6227
- });
6228
- const computeConfigAndUpdate = () => {
6229
- let config;
6230
- ro.observe(() => config = configCallback(component));
6231
- // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
6232
- // TODO: dev-mode validation of config based on the adapter.configSchema
6233
- // @ts-ignore it is assigned in the observe() callback
6234
- callbackWhenConfigIsReady(config);
6235
- };
6236
- return {
6237
- computeConfigAndUpdate,
6238
- ro
6239
- };
6240
- }
6241
- function createContextWatcher(vm, wireDef, callbackWhenContextIsReady) {
6242
- const {
6243
- adapter
6244
- } = wireDef;
6245
- const adapterContextToken = getAdapterToken(adapter);
6246
- if (isUndefined$1(adapterContextToken)) {
6247
- return; // no provider found, nothing to be done
6248
- }
6249
-
6250
- const {
6251
- elm,
6252
- context: {
6253
- wiredConnecting,
6254
- wiredDisconnecting
6255
- },
6256
- renderer: {
6257
- dispatchEvent
6258
- }
6259
- } = vm;
6260
- // waiting for the component to be connected to formally request the context via the token
6261
- ArrayPush$1.call(wiredConnecting, () => {
6262
- // This event is responsible for connecting the host element with another
6263
- // element in the composed path that is providing contextual data. The provider
6264
- // must be listening for a special dom event with the name corresponding to the value of
6265
- // `adapterContextToken`, which will remain secret and internal to this file only to
6266
- // guarantee that the linkage can be forged.
6267
- const contextRegistrationEvent = new WireContextRegistrationEvent(adapterContextToken, {
6268
- setNewContext(newContext) {
6269
- // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
6270
- // TODO: dev-mode validation of config based on the adapter.contextSchema
6271
- callbackWhenContextIsReady(newContext);
6272
- },
6273
- setDisconnectedCallback(disconnectCallback) {
6274
- // adds this callback into the disconnect bucket so it gets disconnected from parent
6275
- // the the element hosting the wire is disconnected
6276
- ArrayPush$1.call(wiredDisconnecting, disconnectCallback);
6277
- }
6278
- });
6279
- dispatchEvent(elm, contextRegistrationEvent);
6280
- });
6281
- }
6282
- function createConnector(vm, name, wireDef) {
6283
- const {
6284
- method,
6285
- adapter,
6286
- configCallback,
6287
- dynamic
6288
- } = wireDef;
6289
- let debugInfo;
6290
- if (process.env.NODE_ENV !== 'production') {
6291
- const wiredPropOrMethod = isUndefined$1(method) ? name : method.name;
6292
- debugInfo = create(null);
6293
- debugInfo.wasDataProvisionedForConfig = false;
6294
- vm.debugInfo[WIRE_DEBUG_ENTRY][wiredPropOrMethod] = debugInfo;
6295
- }
6296
- const fieldOrMethodCallback = isUndefined$1(method) ? createFieldDataCallback(vm, name) : createMethodDataCallback(vm, method);
6297
- const dataCallback = value => {
6298
- if (process.env.NODE_ENV !== 'production') {
6299
- debugInfo.data = value;
6300
- // Note: most of the time, the data provided is for the current config, but there may be
6301
- // some conditions in which it does not, ex:
6302
- // race conditions in a poor network while the adapter does not cancel a previous request.
6303
- debugInfo.wasDataProvisionedForConfig = true;
6304
- }
6305
- fieldOrMethodCallback(value);
6306
- };
6307
- let context;
6308
- let connector;
6309
- // Workaround to pass the component element associated to this wire adapter instance.
6310
- defineProperty(dataCallback, DeprecatedWiredElementHost, {
6311
- value: vm.elm
6312
- });
6313
- defineProperty(dataCallback, DeprecatedWiredParamsMeta, {
6314
- value: dynamic
6315
- });
6316
- runWithBoundaryProtection(vm, vm, noop, () => {
6317
- // job
6318
- connector = new adapter(dataCallback);
6319
- }, noop);
6320
- const updateConnectorConfig = config => {
6321
- // every time the config is recomputed due to tracking,
6322
- // this callback will be invoked with the new computed config
6323
- runWithBoundaryProtection(vm, vm, noop, () => {
6324
- // job
6325
- if (process.env.NODE_ENV !== 'production') {
6326
- debugInfo.config = config;
6327
- debugInfo.context = context;
6328
- debugInfo.wasDataProvisionedForConfig = false;
6564
+ resetComponentStateWhenRemoved(childVM);
6329
6565
  }
6330
- connector.update(config, context);
6331
- }, noop);
6332
- };
6333
- // Computes the current wire config and calls the update method on the wire adapter.
6334
- // If it has params, we will need to observe changes in the next tick.
6566
+ }
6567
+ }
6568
+ }
6569
+ function runLightChildNodesDisconnectedCallback(vm) {
6335
6570
  const {
6336
- computeConfigAndUpdate,
6337
- ro
6338
- } = createConfigWatcher(vm.component, configCallback, updateConnectorConfig);
6339
- // if the adapter needs contextualization, we need to watch for new context and push it alongside the config
6340
- if (!isUndefined$1(adapter.contextSchema)) {
6341
- createContextWatcher(vm, wireDef, newContext => {
6342
- // every time the context is pushed into this component,
6343
- // this callback will be invoked with the new computed context
6344
- if (context !== newContext) {
6345
- context = newContext;
6346
- // Note: when new context arrives, the config will be recomputed and pushed along side the new
6347
- // context, this is to preserve the identity characteristics, config should not have identity
6348
- // (ever), while context can have identity
6349
- if (vm.state === 1 /* VMState.connected */) {
6350
- computeConfigAndUpdate();
6351
- }
6571
+ aChildren: adoptedChildren
6572
+ } = vm;
6573
+ recursivelyDisconnectChildren(adoptedChildren);
6574
+ }
6575
+ /**
6576
+ * The recursion doesn't need to be a complete traversal of the vnode graph,
6577
+ * instead it can be partial, when a custom element vnode is found, we don't
6578
+ * need to continue into its children because by attempting to disconnect the
6579
+ * custom element itself will trigger the removal of anything slotted or anything
6580
+ * defined on its shadow.
6581
+ */
6582
+ function recursivelyDisconnectChildren(vnodes) {
6583
+ for (let i = 0, len = vnodes.length; i < len; i += 1) {
6584
+ const vnode = vnodes[i];
6585
+ if (!isNull(vnode) && !isUndefined$1(vnode.elm)) {
6586
+ switch (vnode.type) {
6587
+ case 2 /* VNodeType.Element */:
6588
+ recursivelyDisconnectChildren(vnode.children);
6589
+ break;
6590
+ case 3 /* VNodeType.CustomElement */:
6591
+ {
6592
+ const vm = getAssociatedVM(vnode.elm);
6593
+ resetComponentStateWhenRemoved(vm);
6594
+ break;
6595
+ }
6352
6596
  }
6353
- });
6597
+ }
6354
6598
  }
6355
- return {
6356
- // @ts-ignore the boundary protection executes sync, connector is always defined
6357
- connector,
6358
- computeConfigAndUpdate,
6359
- resetConfigWatcher: () => ro.reset()
6360
- };
6361
- }
6362
- const AdapterToTokenMap = new Map();
6363
- function getAdapterToken(adapter) {
6364
- return AdapterToTokenMap.get(adapter);
6365
6599
  }
6366
- function setAdapterToken(adapter, token) {
6367
- AdapterToTokenMap.set(adapter, token);
6600
+ // This is a super optimized mechanism to remove the content of the root node (shadow root
6601
+ // for shadow DOM components and the root element itself for light DOM) without having to go
6602
+ // into snabbdom. Especially useful when the reset is a consequence of an error, in which case the
6603
+ // children VNodes might not be representing the current state of the DOM.
6604
+ function resetComponentRoot(vm) {
6605
+ const {
6606
+ children,
6607
+ renderRoot,
6608
+ renderer: {
6609
+ remove
6610
+ }
6611
+ } = vm;
6612
+ for (let i = 0, len = children.length; i < len; i++) {
6613
+ const child = children[i];
6614
+ if (!isNull(child) && !isUndefined$1(child.elm)) {
6615
+ remove(child.elm, renderRoot);
6616
+ }
6617
+ }
6618
+ vm.children = EmptyArray;
6619
+ runChildNodesDisconnectedCallback(vm);
6620
+ vm.velements = EmptyArray;
6368
6621
  }
6369
- function storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic) {
6370
- // support for callable adapters
6371
- if (adapter.adapter) {
6372
- adapter = adapter.adapter;
6622
+ function scheduleRehydration(vm) {
6623
+ if (isTrue(vm.isScheduled)) {
6624
+ return;
6373
6625
  }
6374
- const method = descriptor.value;
6375
- const def = {
6376
- adapter,
6377
- method,
6378
- configCallback,
6379
- dynamic
6380
- };
6381
- WireMetaMap.set(descriptor, def);
6626
+ vm.isScheduled = true;
6627
+ if (rehydrateQueue.length === 0) {
6628
+ addCallbackToNextTick(flushRehydrationQueue);
6629
+ }
6630
+ ArrayPush$1.call(rehydrateQueue, vm);
6382
6631
  }
6383
- function storeWiredFieldMeta(descriptor, adapter, configCallback, dynamic) {
6384
- // support for callable adapters
6385
- if (adapter.adapter) {
6386
- adapter = adapter.adapter;
6632
+ function getErrorBoundaryVM(vm) {
6633
+ let currentVm = vm;
6634
+ while (!isNull(currentVm)) {
6635
+ if (!isUndefined$1(currentVm.def.errorCallback)) {
6636
+ return currentVm;
6637
+ }
6638
+ currentVm = currentVm.owner;
6387
6639
  }
6388
- const def = {
6389
- adapter,
6390
- configCallback,
6391
- dynamic
6392
- };
6393
- WireMetaMap.set(descriptor, def);
6394
6640
  }
6395
- function installWireAdapters(vm) {
6396
- const {
6397
- context,
6398
- def: {
6399
- wire
6641
+ function runWithBoundaryProtection(vm, owner, pre, job, post) {
6642
+ let error;
6643
+ pre();
6644
+ try {
6645
+ job();
6646
+ } catch (e) {
6647
+ error = Object(e);
6648
+ } finally {
6649
+ post();
6650
+ if (!isUndefined$1(error)) {
6651
+ addErrorComponentStack(vm, error);
6652
+ const errorBoundaryVm = isNull(owner) ? undefined : getErrorBoundaryVM(owner);
6653
+ if (isUndefined$1(errorBoundaryVm)) {
6654
+ throw error; // eslint-disable-line no-unsafe-finally
6655
+ }
6656
+
6657
+ resetComponentRoot(vm); // remove offenders
6658
+ logOperationStart(6 /* OperationId.ErrorCallback */, vm);
6659
+ // error boundaries must have an ErrorCallback
6660
+ const errorCallback = errorBoundaryVm.def.errorCallback;
6661
+ invokeComponentCallback(errorBoundaryVm, errorCallback, [error, error.wcStack]);
6662
+ logOperationEnd(6 /* OperationId.ErrorCallback */, vm);
6400
6663
  }
6401
- } = vm;
6402
- if (process.env.NODE_ENV !== 'production') {
6403
- vm.debugInfo[WIRE_DEBUG_ENTRY] = create(null);
6404
6664
  }
6405
- const wiredConnecting = context.wiredConnecting = [];
6406
- const wiredDisconnecting = context.wiredDisconnecting = [];
6407
- for (const fieldNameOrMethod in wire) {
6408
- const descriptor = wire[fieldNameOrMethod];
6409
- const wireDef = WireMetaMap.get(descriptor);
6665
+ }
6666
+ function forceRehydration(vm) {
6667
+ // if we must reset the shadowRoot content and render the template
6668
+ // from scratch on an active instance, the way to force the reset
6669
+ // is by replacing the value of old template, which is used during
6670
+ // to determine if the template has changed or not during the rendering
6671
+ // process. If the template returned by render() is different from the
6672
+ // previous stored template, the styles will be reset, along with the
6673
+ // content of the shadowRoot, this way we can guarantee that all children
6674
+ // elements will be throw away, and new instances will be created.
6675
+ vm.cmpTemplate = () => [];
6676
+ if (isFalse(vm.isDirty)) {
6677
+ // forcing the vm to rehydrate in the next tick
6678
+ markComponentAsDirty(vm);
6679
+ scheduleRehydration(vm);
6680
+ }
6681
+ }
6682
+
6683
+ /*
6684
+ * Copyright (c) 2018, salesforce.com, inc.
6685
+ * All rights reserved.
6686
+ * SPDX-License-Identifier: MIT
6687
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6688
+ */
6689
+ //
6690
+ // The goal of this code is to detect invalid cross-root ARIA references in synthetic shadow DOM.
6691
+ // These invalid references should be fixed before the offending components can be migrated to native shadow DOM.
6692
+ // When invalid usage is detected, we warn in dev mode and call the reporting API if enabled.
6693
+ // See: https://lwc.dev/guide/accessibility#link-ids-and-aria-attributes-from-different-templates
6694
+ //
6695
+ // Use the unpatched native getElementById/querySelectorAll rather than the synthetic one
6696
+ const getElementById = _globalThis[KEY__NATIVE_GET_ELEMENT_BY_ID];
6697
+ const querySelectorAll = _globalThis[KEY__NATIVE_QUERY_SELECTOR_ALL];
6698
+ function isSyntheticShadowRootInstance(rootNode) {
6699
+ return rootNode !== document && isTrue(rootNode.synthetic);
6700
+ }
6701
+ function reportViolation(source, target, attrName) {
6702
+ // The vm is either for the source, the target, or both. Either one or both must be using synthetic
6703
+ // shadow for a violation to be detected.
6704
+ let vm = getAssociatedVMIfPresent(source.getRootNode().host);
6705
+ if (isUndefined$1(vm)) {
6706
+ vm = getAssociatedVMIfPresent(target.getRootNode().host);
6707
+ }
6708
+ if (isUndefined$1(vm)) {
6709
+ // vm should never be undefined here, but just to be safe, bail out and don't report
6710
+ return;
6711
+ }
6712
+ report(0 /* ReportingEventId.CrossRootAriaInSyntheticShadow */, vm);
6410
6713
  if (process.env.NODE_ENV !== 'production') {
6411
- assert.invariant(wireDef, `Internal Error: invalid wire definition found.`);
6714
+ // Avoid excessively logging to the console in the case of duplicates.
6715
+ logWarnOnce(`Element <${source.tagName.toLowerCase()}> uses attribute "${attrName}" to reference element ` +
6716
+ `<${target.tagName.toLowerCase()}>, which is not in the same shadow root. This will break in native shadow DOM. ` +
6717
+ `For details, see: https://lwc.dev/guide/accessibility#link-ids-and-aria-attributes-from-different-templates`, vm);
6412
6718
  }
6413
- if (!isUndefined$1(wireDef)) {
6414
- const {
6415
- connector,
6416
- computeConfigAndUpdate,
6417
- resetConfigWatcher
6418
- } = createConnector(vm, fieldNameOrMethod, wireDef);
6419
- const hasDynamicParams = wireDef.dynamic.length > 0;
6420
- ArrayPush$1.call(wiredConnecting, () => {
6421
- connector.connect();
6422
- if (!lwcRuntimeFlags.ENABLE_WIRE_SYNC_EMIT) {
6423
- if (hasDynamicParams) {
6424
- Promise.resolve().then(computeConfigAndUpdate);
6719
+ }
6720
+ function parseIdRefAttributeValue(attrValue) {
6721
+ // split on whitespace and skip empty strings after splitting
6722
+ return isString(attrValue) ? ArrayFilter.call(StringSplit.call(attrValue, /\s+/), Boolean) : [];
6723
+ }
6724
+ function detectSyntheticCrossRootAria(elm, attrName, attrValue) {
6725
+ const root = elm.getRootNode();
6726
+ if (!isSyntheticShadowRootInstance(root)) {
6727
+ return;
6728
+ }
6729
+ if (attrName === 'id') {
6730
+ // elm is the target, find the source
6731
+ if (!isString(attrValue) || attrValue.length === 0) {
6732
+ // if our id is null or empty, nobody can reference us
6425
6733
  return;
6426
- }
6427
6734
  }
6428
- computeConfigAndUpdate();
6429
- });
6430
- ArrayPush$1.call(wiredDisconnecting, () => {
6431
- connector.disconnect();
6432
- resetConfigWatcher();
6433
- });
6735
+ for (const idRefAttrName of ID_REFERENCING_ATTRIBUTES_SET) {
6736
+ // Query all global elements with this attribute. The attribute selector syntax `~=` is for values
6737
+ // that reference multiple IDs, separated by whitespace.
6738
+ const query = `[${idRefAttrName}~="${CSS.escape(attrValue)}"]`;
6739
+ const sourceElements = querySelectorAll.call(document, query);
6740
+ for (let i = 0; i < sourceElements.length; i++) {
6741
+ const sourceElement = sourceElements[i];
6742
+ const sourceRoot = sourceElement.getRootNode();
6743
+ if (sourceRoot !== root) {
6744
+ reportViolation(sourceElement, elm, idRefAttrName);
6745
+ break;
6746
+ }
6747
+ }
6748
+ }
6749
+ }
6750
+ else {
6751
+ // elm is the source, find the target
6752
+ const ids = parseIdRefAttributeValue(attrValue);
6753
+ for (const id of ids) {
6754
+ const target = getElementById.call(document, id);
6755
+ if (!isNull(target)) {
6756
+ const targetRoot = target.getRootNode();
6757
+ if (targetRoot !== root) {
6758
+ // target element's shadow root is not the same as ours
6759
+ reportViolation(elm, target, attrName);
6760
+ }
6761
+ }
6762
+ }
6434
6763
  }
6435
- }
6436
6764
  }
6437
- function connectWireAdapters(vm) {
6438
- const {
6439
- wiredConnecting
6440
- } = vm.context;
6441
- for (let i = 0, len = wiredConnecting.length; i < len; i += 1) {
6442
- wiredConnecting[i]();
6443
- }
6765
+ let enabled = false;
6766
+ // We want to avoid patching globals whenever possible, so this should be tree-shaken out in prod-mode and if
6767
+ // reporting is not enabled. It should also only run once
6768
+ function enableDetection() {
6769
+ if (enabled) {
6770
+ return; // don't double-apply the patches
6771
+ }
6772
+ enabled = true;
6773
+ const { setAttribute } = Element.prototype;
6774
+ // Detect calling `setAttribute` to set an idref or an id
6775
+ assign(Element.prototype, {
6776
+ setAttribute(attrName, attrValue) {
6777
+ setAttribute.call(this, attrName, attrValue);
6778
+ if (attrName === 'id' || ID_REFERENCING_ATTRIBUTES_SET.has(attrName)) {
6779
+ detectSyntheticCrossRootAria(this, attrName, attrValue);
6780
+ }
6781
+ },
6782
+ });
6783
+ // Detect `elm.id = 'foo'`
6784
+ const idDescriptor = getOwnPropertyDescriptor$1(Element.prototype, 'id');
6785
+ if (!isUndefined$1(idDescriptor)) {
6786
+ const { get, set } = idDescriptor;
6787
+ // These should always be a getter and a setter, but if someone is monkeying with the global descriptor, ignore it
6788
+ if (isFunction$1(get) && isFunction$1(set)) {
6789
+ defineProperty(Element.prototype, 'id', {
6790
+ get() {
6791
+ return get.call(this);
6792
+ },
6793
+ set(value) {
6794
+ set.call(this, value);
6795
+ detectSyntheticCrossRootAria(this, 'id', value);
6796
+ },
6797
+ // On the default descriptor for 'id', enumerable and configurable are true
6798
+ enumerable: true,
6799
+ configurable: true,
6800
+ });
6801
+ }
6802
+ }
6444
6803
  }
6445
- function disconnectWireAdapters(vm) {
6446
- const {
6447
- wiredDisconnecting
6448
- } = vm.context;
6449
- runWithBoundaryProtection(vm, vm, noop, () => {
6450
- // job
6451
- for (let i = 0, len = wiredDisconnecting.length; i < len; i += 1) {
6452
- wiredDisconnecting[i]();
6804
+ // Our detection logic relies on some modern browser features. We can just skip reporting the data
6805
+ // for unsupported browsers
6806
+ function supportsCssEscape() {
6807
+ return typeof CSS !== 'undefined' && isFunction$1(CSS.escape);
6808
+ }
6809
+ // If this page is not using synthetic shadow, then we don't need to install detection. Note
6810
+ // that we are assuming synthetic shadow is loaded before LWC.
6811
+ function isSyntheticShadowLoaded() {
6812
+ // We should probably be calling `renderer.isSyntheticShadowDefined`, but 1) we don't have access to the renderer,
6813
+ // and 2) this code needs to run in @lwc/engine-core, so it can access `logWarn()` and `report()`.
6814
+ return hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN);
6815
+ }
6816
+ // Detecting cross-root ARIA in synthetic shadow only makes sense for the browser
6817
+ if (supportsCssEscape() && isSyntheticShadowLoaded()) {
6818
+ // Always run detection in dev mode, so we can at least print to the console
6819
+ if (process.env.NODE_ENV !== 'production') {
6820
+ enableDetection();
6821
+ }
6822
+ else {
6823
+ // In prod mode, only enable detection if reporting is enabled
6824
+ onReportingEnabled(enableDetection);
6453
6825
  }
6454
- }, noop);
6455
6826
  }
6456
6827
 
6457
6828
  /*
@@ -7123,7 +7494,7 @@ var LWC = (function (exports) {
7123
7494
  }
7124
7495
  return ctor;
7125
7496
  }
7126
- /* version: 2.33.0 */
7497
+ /* version: 2.35.0 */
7127
7498
 
7128
7499
  /*
7129
7500
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7230,7 +7601,9 @@ var LWC = (function (exports) {
7230
7601
  //
7231
7602
  // Test utilities
7232
7603
  //
7233
- if (process.env.NODE_ENV === 'development') {
7604
+ // Only used in LWC's Karma tests
7605
+ // @ts-ignore
7606
+ if (process.env.NODE_ENV !== 'production' && typeof __karma__ !== 'undefined') {
7234
7607
  // @ts-ignore
7235
7608
  window.__lwcResetGlobalStylesheets = () => {
7236
7609
  stylesheetCache.clear();
@@ -8096,7 +8469,7 @@ var LWC = (function (exports) {
8096
8469
  function isNull(obj) {
8097
8470
  return obj === null;
8098
8471
  }
8099
- /** version: 2.33.0 */
8472
+ /** version: 2.35.0 */
8100
8473
 
8101
8474
  /*
8102
8475
  * Copyright (c) 2018, salesforce.com, inc.
@@ -8657,10 +9030,11 @@ var LWC = (function (exports) {
8657
9030
  });
8658
9031
  freeze(LightningElement);
8659
9032
  seal(LightningElement.prototype);
8660
- /* version: 2.33.0 */
9033
+ /* version: 2.35.0 */
8661
9034
 
8662
9035
  exports.LightningElement = LightningElement;
8663
9036
  exports.__unstable__ProfilerControl = profilerControl;
9037
+ exports.__unstable__ReportingControl = reportingControl;
8664
9038
  exports.api = api$1;
8665
9039
  exports.buildCustomElementConstructor = deprecatedBuildCustomElementConstructor;
8666
9040
  exports.createContextProvider = createContextProvider;