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
@@ -45,7 +45,7 @@ const { assign, create, defineProperties, defineProperty, freeze, getOwnProperty
45
45
  const { isArray: isArray$1 } = Array;
46
46
  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;
47
47
  const { fromCharCode: StringFromCharCode } = String;
48
- const { charCodeAt: StringCharCodeAt, replace: StringReplace, slice: StringSlice, toLowerCase: StringToLowerCase, } = String.prototype;
48
+ const { charCodeAt: StringCharCodeAt, replace: StringReplace, split: StringSplit, slice: StringSlice, toLowerCase: StringToLowerCase, } = String.prototype;
49
49
  function isUndefined$1(obj) {
50
50
  return obj === undefined;
51
51
  }
@@ -231,6 +231,8 @@ const KEY__SHADOW_RESOLVER = '$shadowResolver$';
231
231
  const KEY__SHADOW_STATIC = '$shadowStaticNode$';
232
232
  const KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode';
233
233
  const KEY__SCOPED_CSS = '$scoped$';
234
+ const KEY__NATIVE_GET_ELEMENT_BY_ID = '$nativeGetElementById$';
235
+ const KEY__NATIVE_QUERY_SELECTOR_ALL = '$nativeQuerySelectorAll$';
234
236
 
235
237
  /*
236
238
  * Copyright (c) 2022, salesforce.com, inc.
@@ -470,9 +472,9 @@ function htmlEscape(str, attrMode = false) {
470
472
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
471
473
  */
472
474
  // Increment whenever the LWC template compiler changes
473
- const LWC_VERSION = "2.33.0";
475
+ const LWC_VERSION = "2.35.0";
474
476
  const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
475
- /** version: 2.33.0 */
477
+ /** version: 2.35.0 */
476
478
 
477
479
  /*
478
480
  * Copyright (c) 2020, salesforce.com, inc.
@@ -527,6 +529,7 @@ const features = {
527
529
  ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
528
530
  ENABLE_FROZEN_TEMPLATE: null,
529
531
  DISABLE_ARIA_REFLECTION_POLYFILL: null,
532
+ ENABLE_PROGRAMMATIC_STYLESHEETS: null,
530
533
  };
531
534
  if (!_globalThis.lwcRuntimeFlags) {
532
535
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
@@ -580,7 +583,7 @@ function setFeatureFlagForTest(name, value) {
580
583
  setFeatureFlag(name, value);
581
584
  }
582
585
  }
583
- /** version: 2.33.0 */
586
+ /** version: 2.35.0 */
584
587
 
585
588
  /**
586
589
  * Copyright (C) 2018 salesforce.com, inc.
@@ -644,7 +647,7 @@ function applyAriaReflection(prototype = Element.prototype) {
644
647
  }
645
648
  }
646
649
  }
647
- /** version: 2.33.0 */
650
+ /** version: 2.35.0 */
648
651
 
649
652
  /* proxy-compat-disable */
650
653
 
@@ -670,87 +673,6 @@ if (process.env.NODE_ENV !== 'production' && typeof __karma__ !== 'undefined') {
670
673
  }));
671
674
  });
672
675
  }
673
- const SPACE_CHAR = 32;
674
- const EmptyObject = seal(create(null));
675
- const EmptyArray = seal([]);
676
- function guid() {
677
- function s4() {
678
- return Math.floor((1 + Math.random()) * 0x10000)
679
- .toString(16)
680
- .substring(1);
681
- }
682
- return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
683
- }
684
- function flattenStylesheets(stylesheets) {
685
- const list = [];
686
- for (const stylesheet of stylesheets) {
687
- if (!Array.isArray(stylesheet)) {
688
- list.push(stylesheet);
689
- }
690
- else {
691
- list.push(...flattenStylesheets(stylesheet));
692
- }
693
- }
694
- return list;
695
- }
696
- // Set a ref (lwc:ref) on a VM, from a template API
697
- function setRefVNode(vm, ref, vnode) {
698
- if (process.env.NODE_ENV !== 'production' && isUndefined$1(vm.refVNodes)) {
699
- throw new Error('refVNodes must be defined when setting a ref');
700
- }
701
- // If this method is called, then vm.refVNodes is set as the template has refs.
702
- // If not, then something went wrong and we threw an error above.
703
- const refVNodes = vm.refVNodes;
704
- // In cases of conflict (two elements with the same ref), prefer, the last one,
705
- // in depth-first traversal order.
706
- if (!(ref in refVNodes) || refVNodes[ref].key < vnode.key) {
707
- refVNodes[ref] = vnode;
708
- }
709
- }
710
-
711
- /*
712
- * Copyright (c) 2019, salesforce.com, inc.
713
- * All rights reserved.
714
- * SPDX-License-Identifier: MIT
715
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
716
- */
717
- const TargetToReactiveRecordMap = new WeakMap();
718
- function valueMutated(target, key) {
719
- const reactiveRecord = TargetToReactiveRecordMap.get(target);
720
- if (!isUndefined$1(reactiveRecord)) {
721
- const reactiveObservers = reactiveRecord[key];
722
- if (!isUndefined$1(reactiveObservers)) {
723
- for (let i = 0, len = reactiveObservers.length; i < len; i += 1) {
724
- const ro = reactiveObservers[i];
725
- ro.notify();
726
- }
727
- }
728
- }
729
- }
730
- function valueObserved(target, key) {
731
- // We should determine if an active Observing Record is present to track mutations.
732
- {
733
- return;
734
- }
735
- }
736
-
737
- /*
738
- * Copyright (c) 2018, salesforce.com, inc.
739
- * All rights reserved.
740
- * SPDX-License-Identifier: MIT
741
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
742
- */
743
- const DUMMY_REACTIVE_OBSERVER = {
744
- observe(job) {
745
- job();
746
- },
747
- reset() { },
748
- link() { },
749
- };
750
- function createReactiveObserver(callback) {
751
- // On the server side, we don't need mutation tracking. Skipping it improves performance.
752
- return DUMMY_REACTIVE_OBSERVER;
753
- }
754
676
 
755
677
  /*
756
678
  * Copyright (c) 2018, salesforce.com, inc.
@@ -805,11 +727,26 @@ function addErrorComponentStack(vm, error) {
805
727
  * SPDX-License-Identifier: MIT
806
728
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
807
729
  */
808
- function log(method, message, vm) {
730
+ const alreadyLoggedMessages = new Set();
731
+ // @ts-ignore
732
+ if (process.env.NODE_ENV !== 'production' && typeof __karma__ !== 'undefined') {
733
+ // @ts-ignore
734
+ window.__lwcResetAlreadyLoggedMessages = () => {
735
+ alreadyLoggedMessages.clear();
736
+ };
737
+ }
738
+ function log(method, message, vm, once) {
809
739
  let msg = `[LWC ${method}]: ${message}`;
810
740
  if (!isUndefined$1(vm)) {
811
741
  msg = `${msg}\n${getComponentStack(vm)}`;
812
742
  }
743
+ if (once) {
744
+ if (alreadyLoggedMessages.has(msg)) {
745
+ return;
746
+ }
747
+ alreadyLoggedMessages.add(msg);
748
+ }
749
+ // In Jest tests, reduce the warning and error verbosity by not printing the callstack
813
750
  if (process.env.NODE_ENV === 'test') {
814
751
  /* eslint-disable-next-line no-console */
815
752
  console[method](msg);
@@ -824,7 +761,88 @@ function log(method, message, vm) {
824
761
  }
825
762
  }
826
763
  function logError(message, vm) {
827
- log('error', message, vm);
764
+ log('error', message, vm, false);
765
+ }
766
+
767
+ /*
768
+ * Copyright (c) 2019, salesforce.com, inc.
769
+ * All rights reserved.
770
+ * SPDX-License-Identifier: MIT
771
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
772
+ */
773
+ const TargetToReactiveRecordMap = new WeakMap();
774
+ function valueMutated(target, key) {
775
+ const reactiveRecord = TargetToReactiveRecordMap.get(target);
776
+ if (!isUndefined$1(reactiveRecord)) {
777
+ const reactiveObservers = reactiveRecord[key];
778
+ if (!isUndefined$1(reactiveObservers)) {
779
+ for (let i = 0, len = reactiveObservers.length; i < len; i += 1) {
780
+ const ro = reactiveObservers[i];
781
+ ro.notify();
782
+ }
783
+ }
784
+ }
785
+ }
786
+ function valueObserved(target, key) {
787
+ // We should determine if an active Observing Record is present to track mutations.
788
+ {
789
+ return;
790
+ }
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
+ const DUMMY_REACTIVE_OBSERVER = {
800
+ observe(job) {
801
+ job();
802
+ },
803
+ reset() { },
804
+ link() { },
805
+ };
806
+ function createReactiveObserver(callback) {
807
+ // On the server side, we don't need mutation tracking. Skipping it improves performance.
808
+ return DUMMY_REACTIVE_OBSERVER;
809
+ }
810
+ const SPACE_CHAR = 32;
811
+ const EmptyObject = seal(create(null));
812
+ const EmptyArray = seal([]);
813
+ function guid() {
814
+ function s4() {
815
+ return Math.floor((1 + Math.random()) * 0x10000)
816
+ .toString(16)
817
+ .substring(1);
818
+ }
819
+ return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
820
+ }
821
+ function flattenStylesheets(stylesheets) {
822
+ const list = [];
823
+ for (const stylesheet of stylesheets) {
824
+ if (!Array.isArray(stylesheet)) {
825
+ list.push(stylesheet);
826
+ }
827
+ else {
828
+ list.push(...flattenStylesheets(stylesheet));
829
+ }
830
+ }
831
+ return list;
832
+ }
833
+ // Set a ref (lwc:ref) on a VM, from a template API
834
+ function setRefVNode(vm, ref, vnode) {
835
+ if (process.env.NODE_ENV !== 'production' && isUndefined$1(vm.refVNodes)) {
836
+ throw new Error('refVNodes must be defined when setting a ref');
837
+ }
838
+ // If this method is called, then vm.refVNodes is set as the template has refs.
839
+ // If not, then something went wrong and we threw an error above.
840
+ const refVNodes = vm.refVNodes;
841
+ // In cases of conflict (two elements with the same ref), prefer, the last one,
842
+ // in depth-first traversal order.
843
+ if (!(ref in refVNodes) || refVNodes[ref].key < vnode.key) {
844
+ refVNodes[ref] = vnode;
845
+ }
828
846
  }
829
847
 
830
848
  /*
@@ -876,7 +894,10 @@ function offsetPropertyErrorMessage(name) {
876
894
  // Global HTML Attributes & Properties
877
895
  // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
878
896
  // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
879
- const globalHTMLProperties = assign(create(null), {
897
+ //
898
+ // If you update this list, check for test files that recapitulate the same list. Searching the codebase
899
+ // for e.g. "dropzone" should suffice.
900
+ const globalHTMLProperties = {
880
901
  accessKey: {
881
902
  attribute: 'accesskey',
882
903
  },
@@ -961,7 +982,7 @@ const globalHTMLProperties = assign(create(null), {
961
982
  role: {
962
983
  attribute: 'role',
963
984
  },
964
- });
985
+ };
965
986
  let controlledElement = null;
966
987
  let controlledAttributeName;
967
988
  function isAttributeLocked(elm, attrName) {
@@ -2414,70 +2435,273 @@ function createObservedFieldPropertyDescriptor(key) {
2414
2435
  * SPDX-License-Identifier: MIT
2415
2436
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2416
2437
  */
2417
- function api$1() {
2418
- if (process.env.NODE_ENV !== 'production') {
2419
- assert.fail(`@api decorator can only be used as a decorator function.`);
2420
- }
2421
- throw new Error();
2438
+ const DeprecatedWiredElementHost = '$$DeprecatedWiredElementHostKey$$';
2439
+ const DeprecatedWiredParamsMeta = '$$DeprecatedWiredParamsMetaKey$$';
2440
+ const WIRE_DEBUG_ENTRY = '@wire';
2441
+ const WireMetaMap = new Map();
2442
+ class WireContextRegistrationEvent extends CustomEvent {
2443
+ constructor(adapterToken, {
2444
+ setNewContext,
2445
+ setDisconnectedCallback
2446
+ }) {
2447
+ super(adapterToken, {
2448
+ bubbles: true,
2449
+ composed: true
2450
+ });
2451
+ defineProperties(this, {
2452
+ setNewContext: {
2453
+ value: setNewContext
2454
+ },
2455
+ setDisconnectedCallback: {
2456
+ value: setDisconnectedCallback
2457
+ }
2458
+ });
2459
+ }
2422
2460
  }
2423
- function createPublicPropertyDescriptor(key) {
2424
- return {
2425
- get() {
2426
- const vm = getAssociatedVM(this);
2427
- if (isBeingConstructed(vm)) {
2428
- if (process.env.NODE_ENV !== 'production') {
2429
- 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);
2430
- }
2431
- return;
2432
- }
2433
- return vm.cmpProps[key];
2434
- },
2435
- set(newValue) {
2436
- const vm = getAssociatedVM(this);
2437
- if (process.env.NODE_ENV !== 'production') {
2438
- const vmBeingRendered = getVMBeingRendered();
2439
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2440
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2441
- }
2442
- vm.cmpProps[key] = newValue;
2443
- },
2444
- enumerable: true,
2445
- configurable: true,
2446
- };
2461
+ function createFieldDataCallback(vm, name) {
2462
+ return value => {
2463
+ updateComponentValue(vm, name, value);
2464
+ };
2447
2465
  }
2448
- function createPublicAccessorDescriptor(key, descriptor) {
2449
- const { get, set, enumerable, configurable } = descriptor;
2450
- if (!isFunction$1(get)) {
2451
- if (process.env.NODE_ENV !== 'production') {
2452
- assert.invariant(isFunction$1(get), `Invalid compiler output for public accessor ${toString$1(key)} decorated with @api`);
2453
- }
2454
- throw new Error();
2455
- }
2456
- return {
2457
- get() {
2458
- if (process.env.NODE_ENV !== 'production') {
2459
- // Assert that the this value is an actual Component with an associated VM.
2460
- getAssociatedVM(this);
2461
- }
2462
- return get.call(this);
2463
- },
2464
- set(newValue) {
2465
- const vm = getAssociatedVM(this);
2466
- if (process.env.NODE_ENV !== 'production') {
2467
- const vmBeingRendered = getVMBeingRendered();
2468
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2469
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2470
- }
2471
- if (set) {
2472
- set.call(this, newValue);
2473
- }
2474
- else if (process.env.NODE_ENV !== 'production') {
2475
- 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.`);
2476
- }
2477
- },
2478
- enumerable,
2479
- configurable,
2480
- };
2466
+ function createMethodDataCallback(vm, method) {
2467
+ return value => {
2468
+ // dispatching new value into the wired method
2469
+ runWithBoundaryProtection(vm, vm.owner, noop, () => {
2470
+ // job
2471
+ method.call(vm.component, value);
2472
+ }, noop);
2473
+ };
2474
+ }
2475
+ function createConfigWatcher(component, configCallback, callbackWhenConfigIsReady) {
2476
+ // creating the reactive observer for reactive params when needed
2477
+ const ro = createReactiveObserver();
2478
+ const computeConfigAndUpdate = () => {
2479
+ let config;
2480
+ ro.observe(() => config = configCallback(component));
2481
+ // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
2482
+ // TODO: dev-mode validation of config based on the adapter.configSchema
2483
+ // @ts-ignore it is assigned in the observe() callback
2484
+ callbackWhenConfigIsReady(config);
2485
+ };
2486
+ return {
2487
+ computeConfigAndUpdate,
2488
+ ro
2489
+ };
2490
+ }
2491
+ function createContextWatcher(vm, wireDef, callbackWhenContextIsReady) {
2492
+ const {
2493
+ adapter
2494
+ } = wireDef;
2495
+ const adapterContextToken = getAdapterToken(adapter);
2496
+ if (isUndefined$1(adapterContextToken)) {
2497
+ return; // no provider found, nothing to be done
2498
+ }
2499
+
2500
+ const {
2501
+ elm,
2502
+ context: {
2503
+ wiredConnecting,
2504
+ wiredDisconnecting
2505
+ },
2506
+ renderer: {
2507
+ dispatchEvent
2508
+ }
2509
+ } = vm;
2510
+ // waiting for the component to be connected to formally request the context via the token
2511
+ ArrayPush$1.call(wiredConnecting, () => {
2512
+ // This event is responsible for connecting the host element with another
2513
+ // element in the composed path that is providing contextual data. The provider
2514
+ // must be listening for a special dom event with the name corresponding to the value of
2515
+ // `adapterContextToken`, which will remain secret and internal to this file only to
2516
+ // guarantee that the linkage can be forged.
2517
+ const contextRegistrationEvent = new WireContextRegistrationEvent(adapterContextToken, {
2518
+ setNewContext(newContext) {
2519
+ // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
2520
+ // TODO: dev-mode validation of config based on the adapter.contextSchema
2521
+ callbackWhenContextIsReady(newContext);
2522
+ },
2523
+ setDisconnectedCallback(disconnectCallback) {
2524
+ // adds this callback into the disconnect bucket so it gets disconnected from parent
2525
+ // the the element hosting the wire is disconnected
2526
+ ArrayPush$1.call(wiredDisconnecting, disconnectCallback);
2527
+ }
2528
+ });
2529
+ dispatchEvent(elm, contextRegistrationEvent);
2530
+ });
2531
+ }
2532
+ function createConnector(vm, name, wireDef) {
2533
+ const {
2534
+ method,
2535
+ adapter,
2536
+ configCallback,
2537
+ dynamic
2538
+ } = wireDef;
2539
+ let debugInfo;
2540
+ if (process.env.NODE_ENV !== 'production') {
2541
+ const wiredPropOrMethod = isUndefined$1(method) ? name : method.name;
2542
+ debugInfo = create(null);
2543
+ debugInfo.wasDataProvisionedForConfig = false;
2544
+ vm.debugInfo[WIRE_DEBUG_ENTRY][wiredPropOrMethod] = debugInfo;
2545
+ }
2546
+ const fieldOrMethodCallback = isUndefined$1(method) ? createFieldDataCallback(vm, name) : createMethodDataCallback(vm, method);
2547
+ const dataCallback = value => {
2548
+ if (process.env.NODE_ENV !== 'production') {
2549
+ debugInfo.data = value;
2550
+ // Note: most of the time, the data provided is for the current config, but there may be
2551
+ // some conditions in which it does not, ex:
2552
+ // race conditions in a poor network while the adapter does not cancel a previous request.
2553
+ debugInfo.wasDataProvisionedForConfig = true;
2554
+ }
2555
+ fieldOrMethodCallback(value);
2556
+ };
2557
+ let context;
2558
+ let connector;
2559
+ // Workaround to pass the component element associated to this wire adapter instance.
2560
+ defineProperty(dataCallback, DeprecatedWiredElementHost, {
2561
+ value: vm.elm
2562
+ });
2563
+ defineProperty(dataCallback, DeprecatedWiredParamsMeta, {
2564
+ value: dynamic
2565
+ });
2566
+ runWithBoundaryProtection(vm, vm, noop, () => {
2567
+ // job
2568
+ connector = new adapter(dataCallback);
2569
+ }, noop);
2570
+ const updateConnectorConfig = config => {
2571
+ // every time the config is recomputed due to tracking,
2572
+ // this callback will be invoked with the new computed config
2573
+ runWithBoundaryProtection(vm, vm, noop, () => {
2574
+ // job
2575
+ if (process.env.NODE_ENV !== 'production') {
2576
+ debugInfo.config = config;
2577
+ debugInfo.context = context;
2578
+ debugInfo.wasDataProvisionedForConfig = false;
2579
+ }
2580
+ connector.update(config, context);
2581
+ }, noop);
2582
+ };
2583
+ // Computes the current wire config and calls the update method on the wire adapter.
2584
+ // If it has params, we will need to observe changes in the next tick.
2585
+ const {
2586
+ computeConfigAndUpdate,
2587
+ ro
2588
+ } = createConfigWatcher(vm.component, configCallback, updateConnectorConfig);
2589
+ // if the adapter needs contextualization, we need to watch for new context and push it alongside the config
2590
+ if (!isUndefined$1(adapter.contextSchema)) {
2591
+ createContextWatcher(vm, wireDef, newContext => {
2592
+ // every time the context is pushed into this component,
2593
+ // this callback will be invoked with the new computed context
2594
+ if (context !== newContext) {
2595
+ context = newContext;
2596
+ // Note: when new context arrives, the config will be recomputed and pushed along side the new
2597
+ // context, this is to preserve the identity characteristics, config should not have identity
2598
+ // (ever), while context can have identity
2599
+ if (vm.state === 1 /* VMState.connected */) {
2600
+ computeConfigAndUpdate();
2601
+ }
2602
+ }
2603
+ });
2604
+ }
2605
+ return {
2606
+ // @ts-ignore the boundary protection executes sync, connector is always defined
2607
+ connector,
2608
+ computeConfigAndUpdate,
2609
+ resetConfigWatcher: () => ro.reset()
2610
+ };
2611
+ }
2612
+ const AdapterToTokenMap = new Map();
2613
+ function getAdapterToken(adapter) {
2614
+ return AdapterToTokenMap.get(adapter);
2615
+ }
2616
+ function setAdapterToken(adapter, token) {
2617
+ AdapterToTokenMap.set(adapter, token);
2618
+ }
2619
+ function storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic) {
2620
+ // support for callable adapters
2621
+ if (adapter.adapter) {
2622
+ adapter = adapter.adapter;
2623
+ }
2624
+ const method = descriptor.value;
2625
+ const def = {
2626
+ adapter,
2627
+ method,
2628
+ configCallback,
2629
+ dynamic
2630
+ };
2631
+ WireMetaMap.set(descriptor, def);
2632
+ }
2633
+ function storeWiredFieldMeta(descriptor, adapter, configCallback, dynamic) {
2634
+ // support for callable adapters
2635
+ if (adapter.adapter) {
2636
+ adapter = adapter.adapter;
2637
+ }
2638
+ const def = {
2639
+ adapter,
2640
+ configCallback,
2641
+ dynamic
2642
+ };
2643
+ WireMetaMap.set(descriptor, def);
2644
+ }
2645
+ function installWireAdapters(vm) {
2646
+ const {
2647
+ context,
2648
+ def: {
2649
+ wire
2650
+ }
2651
+ } = vm;
2652
+ if (process.env.NODE_ENV !== 'production') {
2653
+ vm.debugInfo[WIRE_DEBUG_ENTRY] = create(null);
2654
+ }
2655
+ const wiredConnecting = context.wiredConnecting = [];
2656
+ const wiredDisconnecting = context.wiredDisconnecting = [];
2657
+ for (const fieldNameOrMethod in wire) {
2658
+ const descriptor = wire[fieldNameOrMethod];
2659
+ const wireDef = WireMetaMap.get(descriptor);
2660
+ if (process.env.NODE_ENV !== 'production') {
2661
+ assert.invariant(wireDef, `Internal Error: invalid wire definition found.`);
2662
+ }
2663
+ if (!isUndefined$1(wireDef)) {
2664
+ const {
2665
+ connector,
2666
+ computeConfigAndUpdate,
2667
+ resetConfigWatcher
2668
+ } = createConnector(vm, fieldNameOrMethod, wireDef);
2669
+ const hasDynamicParams = wireDef.dynamic.length > 0;
2670
+ ArrayPush$1.call(wiredConnecting, () => {
2671
+ connector.connect();
2672
+ if (!lwcRuntimeFlags.ENABLE_WIRE_SYNC_EMIT) {
2673
+ if (hasDynamicParams) {
2674
+ Promise.resolve().then(computeConfigAndUpdate);
2675
+ return;
2676
+ }
2677
+ }
2678
+ computeConfigAndUpdate();
2679
+ });
2680
+ ArrayPush$1.call(wiredDisconnecting, () => {
2681
+ connector.disconnect();
2682
+ resetConfigWatcher();
2683
+ });
2684
+ }
2685
+ }
2686
+ }
2687
+ function connectWireAdapters(vm) {
2688
+ const {
2689
+ wiredConnecting
2690
+ } = vm.context;
2691
+ for (let i = 0, len = wiredConnecting.length; i < len; i += 1) {
2692
+ wiredConnecting[i]();
2693
+ }
2694
+ }
2695
+ function disconnectWireAdapters(vm) {
2696
+ const {
2697
+ wiredDisconnecting
2698
+ } = vm.context;
2699
+ runWithBoundaryProtection(vm, vm, noop, () => {
2700
+ // job
2701
+ for (let i = 0, len = wiredDisconnecting.length; i < len; i += 1) {
2702
+ wiredDisconnecting[i]();
2703
+ }
2704
+ }, noop);
2481
2705
  }
2482
2706
 
2483
2707
  /*
@@ -2486,23 +2710,95 @@ function createPublicAccessorDescriptor(key, descriptor) {
2486
2710
  * SPDX-License-Identifier: MIT
2487
2711
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2488
2712
  */
2489
- function track(target) {
2490
- if (arguments.length === 1) {
2491
- return getReactiveProxy(target);
2492
- }
2713
+ function api$1() {
2493
2714
  if (process.env.NODE_ENV !== 'production') {
2494
- assert.fail(`@track decorator can only be used with one argument to return a trackable object, or as a decorator function.`);
2715
+ assert.fail(`@api decorator can only be used as a decorator function.`);
2495
2716
  }
2496
2717
  throw new Error();
2497
2718
  }
2498
- function internalTrackDecorator(key) {
2719
+ function createPublicPropertyDescriptor(key) {
2499
2720
  return {
2500
2721
  get() {
2501
2722
  const vm = getAssociatedVM(this);
2502
- return vm.cmpFields[key];
2503
- },
2504
- set(newValue) {
2505
- const vm = getAssociatedVM(this);
2723
+ if (isBeingConstructed(vm)) {
2724
+ if (process.env.NODE_ENV !== 'production') {
2725
+ 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);
2726
+ }
2727
+ return;
2728
+ }
2729
+ return vm.cmpProps[key];
2730
+ },
2731
+ set(newValue) {
2732
+ const vm = getAssociatedVM(this);
2733
+ if (process.env.NODE_ENV !== 'production') {
2734
+ const vmBeingRendered = getVMBeingRendered();
2735
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2736
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2737
+ }
2738
+ vm.cmpProps[key] = newValue;
2739
+ },
2740
+ enumerable: true,
2741
+ configurable: true,
2742
+ };
2743
+ }
2744
+ function createPublicAccessorDescriptor(key, descriptor) {
2745
+ const { get, set, enumerable, configurable } = descriptor;
2746
+ if (!isFunction$1(get)) {
2747
+ if (process.env.NODE_ENV !== 'production') {
2748
+ assert.invariant(isFunction$1(get), `Invalid compiler output for public accessor ${toString$1(key)} decorated with @api`);
2749
+ }
2750
+ throw new Error();
2751
+ }
2752
+ return {
2753
+ get() {
2754
+ if (process.env.NODE_ENV !== 'production') {
2755
+ // Assert that the this value is an actual Component with an associated VM.
2756
+ getAssociatedVM(this);
2757
+ }
2758
+ return get.call(this);
2759
+ },
2760
+ set(newValue) {
2761
+ const vm = getAssociatedVM(this);
2762
+ if (process.env.NODE_ENV !== 'production') {
2763
+ const vmBeingRendered = getVMBeingRendered();
2764
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
2765
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
2766
+ }
2767
+ if (set) {
2768
+ set.call(this, newValue);
2769
+ }
2770
+ else if (process.env.NODE_ENV !== 'production') {
2771
+ 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.`);
2772
+ }
2773
+ },
2774
+ enumerable,
2775
+ configurable,
2776
+ };
2777
+ }
2778
+
2779
+ /*
2780
+ * Copyright (c) 2018, salesforce.com, inc.
2781
+ * All rights reserved.
2782
+ * SPDX-License-Identifier: MIT
2783
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2784
+ */
2785
+ function track(target) {
2786
+ if (arguments.length === 1) {
2787
+ return getReactiveProxy(target);
2788
+ }
2789
+ if (process.env.NODE_ENV !== 'production') {
2790
+ assert.fail(`@track decorator can only be used with one argument to return a trackable object, or as a decorator function.`);
2791
+ }
2792
+ throw new Error();
2793
+ }
2794
+ function internalTrackDecorator(key) {
2795
+ return {
2796
+ get() {
2797
+ const vm = getAssociatedVM(this);
2798
+ return vm.cmpFields[key];
2799
+ },
2800
+ set(newValue) {
2801
+ const vm = getAssociatedVM(this);
2506
2802
  if (process.env.NODE_ENV !== 'production') {
2507
2803
  const vmBeingRendered = getVMBeingRendered();
2508
2804
  assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
@@ -3344,6 +3640,9 @@ function updateStylesheetToken(vm, template) {
3344
3640
  stylesheets: newStylesheets,
3345
3641
  stylesheetToken: newStylesheetToken
3346
3642
  } = template;
3643
+ const {
3644
+ stylesheets: newVmStylesheets
3645
+ } = vm;
3347
3646
  const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
3348
3647
  const {
3349
3648
  hasScopedStyles
@@ -3367,7 +3666,9 @@ function updateStylesheetToken(vm, template) {
3367
3666
  }
3368
3667
  // Apply the new template styling token to the host element, if the new template has any
3369
3668
  // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
3370
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
3669
+ const hasNewStylesheets = hasStyles(newStylesheets);
3670
+ const hasNewVmStylesheets = hasStyles(newVmStylesheets);
3671
+ if (hasNewStylesheets || hasNewVmStylesheets) {
3371
3672
  newToken = newStylesheetToken;
3372
3673
  }
3373
3674
  // Set the new styling token on the host element
@@ -3439,10 +3740,17 @@ function getStylesheetsContent(vm, template) {
3439
3740
  stylesheets,
3440
3741
  stylesheetToken
3441
3742
  } = template;
3743
+ const {
3744
+ stylesheets: vmStylesheets
3745
+ } = vm;
3442
3746
  let content = [];
3443
- if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
3747
+ if (hasStyles(stylesheets)) {
3444
3748
  content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
3445
3749
  }
3750
+ // VM (component) stylesheets apply after template stylesheets
3751
+ if (hasStyles(vmStylesheets)) {
3752
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
3753
+ }
3446
3754
  return content;
3447
3755
  }
3448
3756
  // It might be worth caching this to avoid doing the lookup repeatedly, but
@@ -4048,6 +4356,28 @@ function patchCustomElement(n1, n2, parent, renderer) {
4048
4356
  // in fallback mode, the allocation will always set children to
4049
4357
  // empty and delegate the real allocation to the slot elements
4050
4358
  allocateChildren(n2, vm);
4359
+ // Solves an edge case with slotted VFragments in native shadow mode.
4360
+ //
4361
+ // During allocation, in native shadow, slotted VFragment nodes are flattened and their text delimiters are removed
4362
+ // to avoid interfering with native slot behavior. When this happens, if any of the fragments
4363
+ // were not stable, the children must go through the dynamic diffing algo.
4364
+ //
4365
+ // If the new children (n2.children) contain no VFragments, but the previous children (n1.children) were dynamic,
4366
+ // the new nodes must be marked dynamic so that all nodes are properly updated. The only indicator that the new
4367
+ // nodes need to be dynamic comes from the previous children, so we check that to determine whether we need to
4368
+ // mark the new children dynamic.
4369
+ //
4370
+ // Example:
4371
+ // n1.children: [div, VFragment('', div, null, ''), div] => [div, div, null, div]; // marked dynamic
4372
+ // n2.children: [div, null, div] => [div, null, div] // marked ???
4373
+ const {
4374
+ shadowMode,
4375
+ renderMode
4376
+ } = vm;
4377
+ if (shadowMode == 0 /* ShadowMode.Native */ && renderMode !== 0 /* RenderMode.Light */ && hasDynamicChildren(n1.children)) {
4378
+ // No-op if children has already been marked dynamic by 'allocateChildren()'.
4379
+ markAsDynamicChildren(n2.children);
4380
+ }
4051
4381
  }
4052
4382
  // in fallback mode, the children will be always empty, so, nothing
4053
4383
  // will happen, but in native, it does allocate the light dom
@@ -4240,7 +4570,6 @@ function allocateChildren(vnode, vm) {
4240
4570
  //
4241
4571
  // In case #2, we will always get a fresh VCustomElement.
4242
4572
  const children = vnode.aChildren || vnode.children;
4243
- vm.aChildren = children;
4244
4573
  const {
4245
4574
  renderMode,
4246
4575
  shadowMode
@@ -4253,15 +4582,61 @@ function allocateChildren(vnode, vm) {
4253
4582
  logError(`Invalid usage of 'lwc:slot-data' on ${getComponentTag(vm)} tag. Scoped slot content can only be passed to a light dom child.`);
4254
4583
  }
4255
4584
  }
4585
+ // If any of the children being allocated are VFragments, we remove the text delimiters and flatten all immediate
4586
+ // children VFragments to avoid them interfering with default slot behavior.
4587
+ const allocatedChildren = flattenFragmentsInChildren(children);
4588
+ vnode.children = allocatedChildren;
4589
+ vm.aChildren = allocatedChildren;
4256
4590
  if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
4257
4591
  // slow path
4258
- allocateInSlot(vm, children, vnode.owner);
4592
+ allocateInSlot(vm, allocatedChildren, vnode.owner);
4259
4593
  // save the allocated children in case this vnode is reused.
4260
- vnode.aChildren = children;
4594
+ vnode.aChildren = allocatedChildren;
4261
4595
  // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
4262
4596
  vnode.children = EmptyArray;
4263
4597
  }
4264
4598
  }
4599
+ /**
4600
+ * Flattens the contents of all VFragments in an array of VNodes, removes the text delimiters on those VFragments, and
4601
+ * marks the resulting children array as dynamic. Uses a stack (array) to iteratively traverse the nested VFragments
4602
+ * and avoid the perf overhead of creating/destroying throwaway arrays/objects in a recursive approach.
4603
+ *
4604
+ * With the delimiters removed, the contents are marked dynamic so they are diffed correctly.
4605
+ *
4606
+ * This function is used for slotted VFragments to avoid the text delimiters interfering with slotting functionality.
4607
+ */
4608
+ function flattenFragmentsInChildren(children) {
4609
+ const flattenedChildren = [];
4610
+ // Initialize our stack with the direct children of the custom component and check whether we have a VFragment.
4611
+ // If no VFragment is found in children, we don't need to traverse anything or mark the children dynamic and can return early.
4612
+ const nodeStack = [];
4613
+ let fragmentFound = false;
4614
+ for (let i = children.length - 1; i > -1; i -= 1) {
4615
+ const child = children[i];
4616
+ ArrayPush$1.call(nodeStack, child);
4617
+ fragmentFound = fragmentFound || !!(child && isVFragment(child));
4618
+ }
4619
+ if (!fragmentFound) {
4620
+ return children;
4621
+ }
4622
+ let currentNode;
4623
+ while (!isUndefined$1(currentNode = ArrayPop.call(nodeStack))) {
4624
+ if (!isNull(currentNode) && isVFragment(currentNode)) {
4625
+ const fChildren = currentNode.children;
4626
+ // Ignore the start and end text node delimiters
4627
+ for (let i = fChildren.length - 2; i > 0; i -= 1) {
4628
+ ArrayPush$1.call(nodeStack, fChildren[i]);
4629
+ }
4630
+ } else {
4631
+ ArrayPush$1.call(flattenedChildren, currentNode);
4632
+ }
4633
+ }
4634
+ // We always mark the children as dynamic because nothing generates stable VFragments yet.
4635
+ // If/when stable VFragments are generated by the compiler, this code should be updated to
4636
+ // not mark dynamic if all flattened VFragments were stable.
4637
+ markAsDynamicChildren(flattenedChildren);
4638
+ return flattenedChildren;
4639
+ }
4265
4640
  function createViewModelHook(elm, vnode, renderer) {
4266
4641
  let vm = getAssociatedVMIfPresent(elm);
4267
4642
  // There is a possibility that a custom element is registered under tagName, in which case, the
@@ -4286,22 +4661,20 @@ function createViewModelHook(elm, vnode, renderer) {
4286
4661
  }
4287
4662
  return vm;
4288
4663
  }
4289
- /**
4290
- * Collects all slots into a SlotSet, traversing through VFragment Nodes
4291
- */
4292
- function collectSlots(vm, children, cmpSlotsMapping) {
4664
+ function allocateInSlot(vm, children, owner) {
4293
4665
  var _a, _b;
4666
+ const {
4667
+ cmpSlots: {
4668
+ slotAssignments: oldSlotsMapping
4669
+ }
4670
+ } = vm;
4671
+ const cmpSlotsMapping = create(null);
4672
+ // Collect all slots into cmpSlotsMapping
4294
4673
  for (let i = 0, len = children.length; i < len; i += 1) {
4295
4674
  const vnode = children[i];
4296
4675
  if (isNull(vnode)) {
4297
4676
  continue;
4298
4677
  }
4299
- // Dive further iff the content is wrapped in a VFragment
4300
- if (isVFragment(vnode)) {
4301
- // Remove the text delimiter nodes to avoid overriding default slot content
4302
- collectSlots(vm, vnode.children.slice(1, -1), cmpSlotsMapping);
4303
- continue;
4304
- }
4305
4678
  let slotName = '';
4306
4679
  if (isVBaseElement(vnode)) {
4307
4680
  slotName = (_b = (_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : '';
@@ -4311,15 +4684,6 @@ function collectSlots(vm, children, cmpSlotsMapping) {
4311
4684
  const vnodes = cmpSlotsMapping[slotName] = cmpSlotsMapping[slotName] || [];
4312
4685
  ArrayPush$1.call(vnodes, vnode);
4313
4686
  }
4314
- }
4315
- function allocateInSlot(vm, children, owner) {
4316
- const {
4317
- cmpSlots: {
4318
- slotAssignments: oldSlotsMapping
4319
- }
4320
- } = vm;
4321
- const cmpSlotsMapping = create(null);
4322
- collectSlots(vm, children, cmpSlotsMapping);
4323
4687
  vm.cmpSlots = {
4324
4688
  owner,
4325
4689
  slotAssignments: cmpSlotsMapping
@@ -4350,14 +4714,14 @@ function allocateInSlot(vm, children, owner) {
4350
4714
  }
4351
4715
  }
4352
4716
  // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
4353
- const FromIteration = new WeakMap();
4354
- // dynamic children means it was generated by an iteration
4355
- // in a template, and will require a more complex diffing algo.
4717
+ const DynamicChildren = new WeakMap();
4718
+ // dynamic children means it was either generated by an iteration in a template
4719
+ // or part of an unstable fragment, and will require a more complex diffing algo.
4356
4720
  function markAsDynamicChildren(children) {
4357
- FromIteration.set(children, 1);
4721
+ DynamicChildren.set(children, 1);
4358
4722
  }
4359
4723
  function hasDynamicChildren(children) {
4360
- return FromIteration.has(children);
4724
+ return DynamicChildren.has(children);
4361
4725
  }
4362
4726
  function createKeyToOldIdx(children, beginIdx, endIdx) {
4363
4727
  const map = {};
@@ -5184,7 +5548,7 @@ function evaluateTemplate(vm, html) {
5184
5548
  // Create a brand new template cache for the swapped templated.
5185
5549
  context.tplCache = create(null);
5186
5550
  // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
5187
- context.hasScopedStyles = computeHasScopedStyles(html);
5551
+ context.hasScopedStyles = computeHasScopedStyles(html, vm);
5188
5552
  // Update the scoping token on the host element.
5189
5553
  updateStylesheetToken(vm, html);
5190
5554
  // Evaluate, create stylesheet and cache the produced VNode for future
@@ -5227,9 +5591,8 @@ function evaluateTemplate(vm, html) {
5227
5591
  }
5228
5592
  return vnodes;
5229
5593
  }
5230
- function computeHasScopedStyles(template) {
5231
- const { stylesheets } = template;
5232
- if (!isUndefined$1(stylesheets)) {
5594
+ function computeHasScopedStylesInStylesheets(stylesheets) {
5595
+ if (hasStyles(stylesheets)) {
5233
5596
  for (let i = 0; i < stylesheets.length; i++) {
5234
5597
  if (isTrue(stylesheets[i][KEY__SCOPED_CSS])) {
5235
5598
  return true;
@@ -5238,6 +5601,15 @@ function computeHasScopedStyles(template) {
5238
5601
  }
5239
5602
  return false;
5240
5603
  }
5604
+ function computeHasScopedStyles(template, vm) {
5605
+ const { stylesheets } = template;
5606
+ const vmStylesheets = !isUndefined$1(vm) ? vm.stylesheets : null;
5607
+ return (computeHasScopedStylesInStylesheets(stylesheets) ||
5608
+ computeHasScopedStylesInStylesheets(vmStylesheets));
5609
+ }
5610
+ function hasStyles(stylesheets) {
5611
+ return !isUndefined$1(stylesheets) && !isNull(stylesheets) && stylesheets.length > 0;
5612
+ }
5241
5613
 
5242
5614
  /*
5243
5615
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5547,6 +5919,7 @@ function createVM(elm, ctor, renderer, options) {
5547
5919
  // Properties set right after VM creation.
5548
5920
  tro: null,
5549
5921
  shadowMode: null,
5922
+ stylesheets: null,
5550
5923
  // Properties set by the LightningElement constructor.
5551
5924
  component: null,
5552
5925
  shadowRoot: null,
@@ -5559,6 +5932,7 @@ function createVM(elm, ctor, renderer, options) {
5559
5932
  if (process.env.NODE_ENV !== 'production') {
5560
5933
  vm.debugInfo = create(null);
5561
5934
  }
5935
+ vm.stylesheets = computeStylesheets(vm, def.ctor);
5562
5936
  vm.shadowMode = computeShadowMode(vm, renderer);
5563
5937
  vm.tro = getTemplateReactiveObserver();
5564
5938
  if (process.env.NODE_ENV !== 'production') {
@@ -5577,6 +5951,42 @@ function createVM(elm, ctor, renderer, options) {
5577
5951
  }
5578
5952
  return vm;
5579
5953
  }
5954
+ function validateComponentStylesheets(vm, stylesheets) {
5955
+ let valid = true;
5956
+ const validate = arrayOrStylesheet => {
5957
+ if (isArray$1(arrayOrStylesheet)) {
5958
+ for (let i = 0; i < arrayOrStylesheet.length; i++) {
5959
+ validate(arrayOrStylesheet[i]);
5960
+ }
5961
+ } else if (!isFunction$1(arrayOrStylesheet)) {
5962
+ // function assumed to be a stylesheet factory
5963
+ valid = false;
5964
+ }
5965
+ };
5966
+ if (!isArray$1(stylesheets)) {
5967
+ valid = false;
5968
+ } else {
5969
+ validate(stylesheets);
5970
+ }
5971
+ return valid;
5972
+ }
5973
+ // Validate and flatten any stylesheets defined as `static stylesheets`
5974
+ function computeStylesheets(vm, ctor) {
5975
+ if (lwcRuntimeFlags.ENABLE_PROGRAMMATIC_STYLESHEETS) {
5976
+ const {
5977
+ stylesheets
5978
+ } = ctor;
5979
+ if (!isUndefined$1(stylesheets)) {
5980
+ const valid = validateComponentStylesheets(vm, stylesheets);
5981
+ if (valid) {
5982
+ return flattenStylesheets(stylesheets);
5983
+ } else if (process.env.NODE_ENV !== 'production') {
5984
+ logError(`static stylesheets must be an array of CSS stylesheets. Found invalid stylesheets on <${vm.tagName}>`, vm);
5985
+ }
5986
+ }
5987
+ }
5988
+ return null;
5989
+ }
5580
5990
  function computeShadowMode(vm, renderer) {
5581
5991
  const {
5582
5992
  def
@@ -5672,466 +6082,207 @@ function patchShadowRoot(vm, newCh) {
5672
6082
  // job
5673
6083
  patchChildren(oldCh, newCh, renderRoot, renderer);
5674
6084
  }, () => {
5675
- // post
5676
- logOperationEnd(2 /* OperationId.Patch */, vm);
5677
- });
5678
- }
5679
- }
5680
- if (vm.state === 1 /* VMState.connected */) ;
5681
- }
5682
-
5683
- function runConnectedCallback(vm) {
5684
- const {
5685
- state
5686
- } = vm;
5687
- if (state === 1 /* VMState.connected */) {
5688
- return; // nothing to do since it was already connected
5689
- }
5690
-
5691
- vm.state = 1 /* VMState.connected */;
5692
- // reporting connection
5693
- const {
5694
- connected
5695
- } = Services;
5696
- if (connected) {
5697
- invokeServiceHook(vm, connected);
5698
- }
5699
- if (hasWireAdapters(vm)) {
5700
- connectWireAdapters(vm);
5701
- }
5702
- const {
5703
- connectedCallback
5704
- } = vm.def;
5705
- if (!isUndefined$1(connectedCallback)) {
5706
- logOperationStart(3 /* OperationId.ConnectedCallback */, vm);
5707
- invokeComponentCallback(vm, connectedCallback);
5708
- logOperationEnd(3 /* OperationId.ConnectedCallback */, vm);
5709
- }
5710
- }
5711
- function hasWireAdapters(vm) {
5712
- return getOwnPropertyNames$1(vm.def.wire).length > 0;
5713
- }
5714
- function runDisconnectedCallback(vm) {
5715
- if (process.env.NODE_ENV !== 'production') {
5716
- assert.isTrue(vm.state !== 2 /* VMState.disconnected */, `${vm} must be inserted.`);
5717
- }
5718
- if (isFalse(vm.isDirty)) {
5719
- // this guarantees that if the component is reused/reinserted,
5720
- // it will be re-rendered because we are disconnecting the reactivity
5721
- // linking, so mutations are not automatically reflected on the state
5722
- // of disconnected components.
5723
- vm.isDirty = true;
5724
- }
5725
- vm.state = 2 /* VMState.disconnected */;
5726
- // reporting disconnection
5727
- const {
5728
- disconnected
5729
- } = Services;
5730
- if (disconnected) {
5731
- invokeServiceHook(vm, disconnected);
5732
- }
5733
- if (hasWireAdapters(vm)) {
5734
- disconnectWireAdapters(vm);
5735
- }
5736
- const {
5737
- disconnectedCallback
5738
- } = vm.def;
5739
- if (!isUndefined$1(disconnectedCallback)) {
5740
- logOperationStart(5 /* OperationId.DisconnectedCallback */, vm);
5741
- invokeComponentCallback(vm, disconnectedCallback);
5742
- logOperationEnd(5 /* OperationId.DisconnectedCallback */, vm);
5743
- }
5744
- }
5745
- function runChildNodesDisconnectedCallback(vm) {
5746
- const {
5747
- velements: vCustomElementCollection
5748
- } = vm;
5749
- // Reporting disconnection for every child in inverse order since they are
5750
- // inserted in reserved order.
5751
- for (let i = vCustomElementCollection.length - 1; i >= 0; i -= 1) {
5752
- const {
5753
- elm
5754
- } = vCustomElementCollection[i];
5755
- // There are two cases where the element could be undefined:
5756
- // * when there is an error during the construction phase, and an error
5757
- // boundary picks it, there is a possibility that the VCustomElement
5758
- // is not properly initialized, and therefore is should be ignored.
5759
- // * when slotted custom element is not used by the element where it is
5760
- // slotted into it, as a result, the custom element was never
5761
- // initialized.
5762
- if (!isUndefined$1(elm)) {
5763
- const childVM = getAssociatedVMIfPresent(elm);
5764
- // The VM associated with the element might be associated undefined
5765
- // in the case where the VM failed in the middle of its creation,
5766
- // eg: constructor throwing before invoking super().
5767
- if (!isUndefined$1(childVM)) {
5768
- resetComponentStateWhenRemoved(childVM);
5769
- }
5770
- }
5771
- }
5772
- }
5773
- function runLightChildNodesDisconnectedCallback(vm) {
5774
- const {
5775
- aChildren: adoptedChildren
5776
- } = vm;
5777
- recursivelyDisconnectChildren(adoptedChildren);
5778
- }
5779
- /**
5780
- * The recursion doesn't need to be a complete traversal of the vnode graph,
5781
- * instead it can be partial, when a custom element vnode is found, we don't
5782
- * need to continue into its children because by attempting to disconnect the
5783
- * custom element itself will trigger the removal of anything slotted or anything
5784
- * defined on its shadow.
5785
- */
5786
- function recursivelyDisconnectChildren(vnodes) {
5787
- for (let i = 0, len = vnodes.length; i < len; i += 1) {
5788
- const vnode = vnodes[i];
5789
- if (!isNull(vnode) && !isUndefined$1(vnode.elm)) {
5790
- switch (vnode.type) {
5791
- case 2 /* VNodeType.Element */:
5792
- recursivelyDisconnectChildren(vnode.children);
5793
- break;
5794
- case 3 /* VNodeType.CustomElement */:
5795
- {
5796
- const vm = getAssociatedVM(vnode.elm);
5797
- resetComponentStateWhenRemoved(vm);
5798
- break;
5799
- }
5800
- }
5801
- }
5802
- }
5803
- }
5804
- // This is a super optimized mechanism to remove the content of the root node (shadow root
5805
- // for shadow DOM components and the root element itself for light DOM) without having to go
5806
- // into snabbdom. Especially useful when the reset is a consequence of an error, in which case the
5807
- // children VNodes might not be representing the current state of the DOM.
5808
- function resetComponentRoot(vm) {
5809
- const {
5810
- children,
5811
- renderRoot,
5812
- renderer: {
5813
- remove
5814
- }
5815
- } = vm;
5816
- for (let i = 0, len = children.length; i < len; i++) {
5817
- const child = children[i];
5818
- if (!isNull(child) && !isUndefined$1(child.elm)) {
5819
- remove(child.elm, renderRoot);
5820
- }
5821
- }
5822
- vm.children = EmptyArray;
5823
- runChildNodesDisconnectedCallback(vm);
5824
- vm.velements = EmptyArray;
5825
- }
5826
- function getErrorBoundaryVM(vm) {
5827
- let currentVm = vm;
5828
- while (!isNull(currentVm)) {
5829
- if (!isUndefined$1(currentVm.def.errorCallback)) {
5830
- return currentVm;
5831
- }
5832
- currentVm = currentVm.owner;
5833
- }
5834
- }
5835
- function runWithBoundaryProtection(vm, owner, pre, job, post) {
5836
- let error;
5837
- pre();
5838
- try {
5839
- job();
5840
- } catch (e) {
5841
- error = Object(e);
5842
- } finally {
5843
- post();
5844
- if (!isUndefined$1(error)) {
5845
- addErrorComponentStack(vm, error);
5846
- const errorBoundaryVm = isNull(owner) ? undefined : getErrorBoundaryVM(owner);
5847
- if (isUndefined$1(errorBoundaryVm)) {
5848
- throw error; // eslint-disable-line no-unsafe-finally
5849
- }
5850
-
5851
- resetComponentRoot(vm); // remove offenders
5852
- logOperationStart(6 /* OperationId.ErrorCallback */, vm);
5853
- // error boundaries must have an ErrorCallback
5854
- const errorCallback = errorBoundaryVm.def.errorCallback;
5855
- invokeComponentCallback(errorBoundaryVm, errorCallback, [error, error.wcStack]);
5856
- logOperationEnd(6 /* OperationId.ErrorCallback */, vm);
5857
- }
5858
- }
5859
- }
5860
-
5861
- /*
5862
- * Copyright (c) 2018, salesforce.com, inc.
5863
- * All rights reserved.
5864
- * SPDX-License-Identifier: MIT
5865
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5866
- */
5867
- const DeprecatedWiredElementHost = '$$DeprecatedWiredElementHostKey$$';
5868
- const DeprecatedWiredParamsMeta = '$$DeprecatedWiredParamsMetaKey$$';
5869
- const WIRE_DEBUG_ENTRY = '@wire';
5870
- const WireMetaMap = new Map();
5871
- class WireContextRegistrationEvent extends CustomEvent {
5872
- constructor(adapterToken, {
5873
- setNewContext,
5874
- setDisconnectedCallback
5875
- }) {
5876
- super(adapterToken, {
5877
- bubbles: true,
5878
- composed: true
5879
- });
5880
- defineProperties(this, {
5881
- setNewContext: {
5882
- value: setNewContext
5883
- },
5884
- setDisconnectedCallback: {
5885
- value: setDisconnectedCallback
5886
- }
5887
- });
5888
- }
5889
- }
5890
- function createFieldDataCallback(vm, name) {
5891
- return value => {
5892
- updateComponentValue(vm, name, value);
5893
- };
5894
- }
5895
- function createMethodDataCallback(vm, method) {
5896
- return value => {
5897
- // dispatching new value into the wired method
5898
- runWithBoundaryProtection(vm, vm.owner, noop, () => {
5899
- // job
5900
- method.call(vm.component, value);
5901
- }, noop);
5902
- };
5903
- }
5904
- function createConfigWatcher(component, configCallback, callbackWhenConfigIsReady) {
5905
- // creating the reactive observer for reactive params when needed
5906
- const ro = createReactiveObserver();
5907
- const computeConfigAndUpdate = () => {
5908
- let config;
5909
- ro.observe(() => config = configCallback(component));
5910
- // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
5911
- // TODO: dev-mode validation of config based on the adapter.configSchema
5912
- // @ts-ignore it is assigned in the observe() callback
5913
- callbackWhenConfigIsReady(config);
5914
- };
5915
- return {
5916
- computeConfigAndUpdate,
5917
- ro
5918
- };
5919
- }
5920
- function createContextWatcher(vm, wireDef, callbackWhenContextIsReady) {
5921
- const {
5922
- adapter
5923
- } = wireDef;
5924
- const adapterContextToken = getAdapterToken(adapter);
5925
- if (isUndefined$1(adapterContextToken)) {
5926
- return; // no provider found, nothing to be done
5927
- }
5928
-
5929
- const {
5930
- elm,
5931
- context: {
5932
- wiredConnecting,
5933
- wiredDisconnecting
5934
- },
5935
- renderer: {
5936
- dispatchEvent
5937
- }
5938
- } = vm;
5939
- // waiting for the component to be connected to formally request the context via the token
5940
- ArrayPush$1.call(wiredConnecting, () => {
5941
- // This event is responsible for connecting the host element with another
5942
- // element in the composed path that is providing contextual data. The provider
5943
- // must be listening for a special dom event with the name corresponding to the value of
5944
- // `adapterContextToken`, which will remain secret and internal to this file only to
5945
- // guarantee that the linkage can be forged.
5946
- const contextRegistrationEvent = new WireContextRegistrationEvent(adapterContextToken, {
5947
- setNewContext(newContext) {
5948
- // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
5949
- // TODO: dev-mode validation of config based on the adapter.contextSchema
5950
- callbackWhenContextIsReady(newContext);
5951
- },
5952
- setDisconnectedCallback(disconnectCallback) {
5953
- // adds this callback into the disconnect bucket so it gets disconnected from parent
5954
- // the the element hosting the wire is disconnected
5955
- ArrayPush$1.call(wiredDisconnecting, disconnectCallback);
5956
- }
5957
- });
5958
- dispatchEvent(elm, contextRegistrationEvent);
5959
- });
5960
- }
5961
- function createConnector(vm, name, wireDef) {
5962
- const {
5963
- method,
5964
- adapter,
5965
- configCallback,
5966
- dynamic
5967
- } = wireDef;
5968
- let debugInfo;
5969
- if (process.env.NODE_ENV !== 'production') {
5970
- const wiredPropOrMethod = isUndefined$1(method) ? name : method.name;
5971
- debugInfo = create(null);
5972
- debugInfo.wasDataProvisionedForConfig = false;
5973
- vm.debugInfo[WIRE_DEBUG_ENTRY][wiredPropOrMethod] = debugInfo;
5974
- }
5975
- const fieldOrMethodCallback = isUndefined$1(method) ? createFieldDataCallback(vm, name) : createMethodDataCallback(vm, method);
5976
- const dataCallback = value => {
5977
- if (process.env.NODE_ENV !== 'production') {
5978
- debugInfo.data = value;
5979
- // Note: most of the time, the data provided is for the current config, but there may be
5980
- // some conditions in which it does not, ex:
5981
- // race conditions in a poor network while the adapter does not cancel a previous request.
5982
- debugInfo.wasDataProvisionedForConfig = true;
5983
- }
5984
- fieldOrMethodCallback(value);
5985
- };
5986
- let context;
5987
- let connector;
5988
- // Workaround to pass the component element associated to this wire adapter instance.
5989
- defineProperty(dataCallback, DeprecatedWiredElementHost, {
5990
- value: vm.elm
5991
- });
5992
- defineProperty(dataCallback, DeprecatedWiredParamsMeta, {
5993
- value: dynamic
5994
- });
5995
- runWithBoundaryProtection(vm, vm, noop, () => {
5996
- // job
5997
- connector = new adapter(dataCallback);
5998
- }, noop);
5999
- const updateConnectorConfig = config => {
6000
- // every time the config is recomputed due to tracking,
6001
- // this callback will be invoked with the new computed config
6002
- runWithBoundaryProtection(vm, vm, noop, () => {
6003
- // job
6004
- if (process.env.NODE_ENV !== 'production') {
6005
- debugInfo.config = config;
6006
- debugInfo.context = context;
6007
- debugInfo.wasDataProvisionedForConfig = false;
6008
- }
6009
- connector.update(config, context);
6010
- }, noop);
6011
- };
6012
- // Computes the current wire config and calls the update method on the wire adapter.
6013
- // If it has params, we will need to observe changes in the next tick.
6014
- const {
6015
- computeConfigAndUpdate,
6016
- ro
6017
- } = createConfigWatcher(vm.component, configCallback, updateConnectorConfig);
6018
- // if the adapter needs contextualization, we need to watch for new context and push it alongside the config
6019
- if (!isUndefined$1(adapter.contextSchema)) {
6020
- createContextWatcher(vm, wireDef, newContext => {
6021
- // every time the context is pushed into this component,
6022
- // this callback will be invoked with the new computed context
6023
- if (context !== newContext) {
6024
- context = newContext;
6025
- // Note: when new context arrives, the config will be recomputed and pushed along side the new
6026
- // context, this is to preserve the identity characteristics, config should not have identity
6027
- // (ever), while context can have identity
6028
- if (vm.state === 1 /* VMState.connected */) {
6029
- computeConfigAndUpdate();
6030
- }
6031
- }
6032
- });
6085
+ // post
6086
+ logOperationEnd(2 /* OperationId.Patch */, vm);
6087
+ });
6088
+ }
6033
6089
  }
6034
- return {
6035
- // @ts-ignore the boundary protection executes sync, connector is always defined
6036
- connector,
6037
- computeConfigAndUpdate,
6038
- resetConfigWatcher: () => ro.reset()
6039
- };
6090
+ if (vm.state === 1 /* VMState.connected */) ;
6040
6091
  }
6041
- const AdapterToTokenMap = new Map();
6042
- function getAdapterToken(adapter) {
6043
- return AdapterToTokenMap.get(adapter);
6092
+
6093
+ function runConnectedCallback(vm) {
6094
+ const {
6095
+ state
6096
+ } = vm;
6097
+ if (state === 1 /* VMState.connected */) {
6098
+ return; // nothing to do since it was already connected
6099
+ }
6100
+
6101
+ vm.state = 1 /* VMState.connected */;
6102
+ // reporting connection
6103
+ const {
6104
+ connected
6105
+ } = Services;
6106
+ if (connected) {
6107
+ invokeServiceHook(vm, connected);
6108
+ }
6109
+ if (hasWireAdapters(vm)) {
6110
+ connectWireAdapters(vm);
6111
+ }
6112
+ const {
6113
+ connectedCallback
6114
+ } = vm.def;
6115
+ if (!isUndefined$1(connectedCallback)) {
6116
+ logOperationStart(3 /* OperationId.ConnectedCallback */, vm);
6117
+ invokeComponentCallback(vm, connectedCallback);
6118
+ logOperationEnd(3 /* OperationId.ConnectedCallback */, vm);
6119
+ }
6044
6120
  }
6045
- function setAdapterToken(adapter, token) {
6046
- AdapterToTokenMap.set(adapter, token);
6121
+ function hasWireAdapters(vm) {
6122
+ return getOwnPropertyNames$1(vm.def.wire).length > 0;
6047
6123
  }
6048
- function storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic) {
6049
- // support for callable adapters
6050
- if (adapter.adapter) {
6051
- adapter = adapter.adapter;
6124
+ function runDisconnectedCallback(vm) {
6125
+ if (process.env.NODE_ENV !== 'production') {
6126
+ assert.isTrue(vm.state !== 2 /* VMState.disconnected */, `${vm} must be inserted.`);
6052
6127
  }
6053
- const method = descriptor.value;
6054
- const def = {
6055
- adapter,
6056
- method,
6057
- configCallback,
6058
- dynamic
6059
- };
6060
- WireMetaMap.set(descriptor, def);
6061
- }
6062
- function storeWiredFieldMeta(descriptor, adapter, configCallback, dynamic) {
6063
- // support for callable adapters
6064
- if (adapter.adapter) {
6065
- adapter = adapter.adapter;
6128
+ if (isFalse(vm.isDirty)) {
6129
+ // this guarantees that if the component is reused/reinserted,
6130
+ // it will be re-rendered because we are disconnecting the reactivity
6131
+ // linking, so mutations are not automatically reflected on the state
6132
+ // of disconnected components.
6133
+ vm.isDirty = true;
6134
+ }
6135
+ vm.state = 2 /* VMState.disconnected */;
6136
+ // reporting disconnection
6137
+ const {
6138
+ disconnected
6139
+ } = Services;
6140
+ if (disconnected) {
6141
+ invokeServiceHook(vm, disconnected);
6142
+ }
6143
+ if (hasWireAdapters(vm)) {
6144
+ disconnectWireAdapters(vm);
6145
+ }
6146
+ const {
6147
+ disconnectedCallback
6148
+ } = vm.def;
6149
+ if (!isUndefined$1(disconnectedCallback)) {
6150
+ logOperationStart(5 /* OperationId.DisconnectedCallback */, vm);
6151
+ invokeComponentCallback(vm, disconnectedCallback);
6152
+ logOperationEnd(5 /* OperationId.DisconnectedCallback */, vm);
6066
6153
  }
6067
- const def = {
6068
- adapter,
6069
- configCallback,
6070
- dynamic
6071
- };
6072
- WireMetaMap.set(descriptor, def);
6073
6154
  }
6074
- function installWireAdapters(vm) {
6155
+ function runChildNodesDisconnectedCallback(vm) {
6075
6156
  const {
6076
- context,
6077
- def: {
6078
- wire
6079
- }
6157
+ velements: vCustomElementCollection
6080
6158
  } = vm;
6081
- if (process.env.NODE_ENV !== 'production') {
6082
- vm.debugInfo[WIRE_DEBUG_ENTRY] = create(null);
6083
- }
6084
- const wiredConnecting = context.wiredConnecting = [];
6085
- const wiredDisconnecting = context.wiredDisconnecting = [];
6086
- for (const fieldNameOrMethod in wire) {
6087
- const descriptor = wire[fieldNameOrMethod];
6088
- const wireDef = WireMetaMap.get(descriptor);
6089
- if (process.env.NODE_ENV !== 'production') {
6090
- assert.invariant(wireDef, `Internal Error: invalid wire definition found.`);
6159
+ // Reporting disconnection for every child in inverse order since they are
6160
+ // inserted in reserved order.
6161
+ for (let i = vCustomElementCollection.length - 1; i >= 0; i -= 1) {
6162
+ const {
6163
+ elm
6164
+ } = vCustomElementCollection[i];
6165
+ // There are two cases where the element could be undefined:
6166
+ // * when there is an error during the construction phase, and an error
6167
+ // boundary picks it, there is a possibility that the VCustomElement
6168
+ // is not properly initialized, and therefore is should be ignored.
6169
+ // * when slotted custom element is not used by the element where it is
6170
+ // slotted into it, as a result, the custom element was never
6171
+ // initialized.
6172
+ if (!isUndefined$1(elm)) {
6173
+ const childVM = getAssociatedVMIfPresent(elm);
6174
+ // The VM associated with the element might be associated undefined
6175
+ // in the case where the VM failed in the middle of its creation,
6176
+ // eg: constructor throwing before invoking super().
6177
+ if (!isUndefined$1(childVM)) {
6178
+ resetComponentStateWhenRemoved(childVM);
6179
+ }
6091
6180
  }
6092
- if (!isUndefined$1(wireDef)) {
6093
- const {
6094
- connector,
6095
- computeConfigAndUpdate,
6096
- resetConfigWatcher
6097
- } = createConnector(vm, fieldNameOrMethod, wireDef);
6098
- const hasDynamicParams = wireDef.dynamic.length > 0;
6099
- ArrayPush$1.call(wiredConnecting, () => {
6100
- connector.connect();
6101
- if (!lwcRuntimeFlags.ENABLE_WIRE_SYNC_EMIT) {
6102
- if (hasDynamicParams) {
6103
- Promise.resolve().then(computeConfigAndUpdate);
6104
- return;
6181
+ }
6182
+ }
6183
+ function runLightChildNodesDisconnectedCallback(vm) {
6184
+ const {
6185
+ aChildren: adoptedChildren
6186
+ } = vm;
6187
+ recursivelyDisconnectChildren(adoptedChildren);
6188
+ }
6189
+ /**
6190
+ * The recursion doesn't need to be a complete traversal of the vnode graph,
6191
+ * instead it can be partial, when a custom element vnode is found, we don't
6192
+ * need to continue into its children because by attempting to disconnect the
6193
+ * custom element itself will trigger the removal of anything slotted or anything
6194
+ * defined on its shadow.
6195
+ */
6196
+ function recursivelyDisconnectChildren(vnodes) {
6197
+ for (let i = 0, len = vnodes.length; i < len; i += 1) {
6198
+ const vnode = vnodes[i];
6199
+ if (!isNull(vnode) && !isUndefined$1(vnode.elm)) {
6200
+ switch (vnode.type) {
6201
+ case 2 /* VNodeType.Element */:
6202
+ recursivelyDisconnectChildren(vnode.children);
6203
+ break;
6204
+ case 3 /* VNodeType.CustomElement */:
6205
+ {
6206
+ const vm = getAssociatedVM(vnode.elm);
6207
+ resetComponentStateWhenRemoved(vm);
6208
+ break;
6105
6209
  }
6106
- }
6107
- computeConfigAndUpdate();
6108
- });
6109
- ArrayPush$1.call(wiredDisconnecting, () => {
6110
- connector.disconnect();
6111
- resetConfigWatcher();
6112
- });
6210
+ }
6113
6211
  }
6114
6212
  }
6115
6213
  }
6116
- function connectWireAdapters(vm) {
6214
+ // This is a super optimized mechanism to remove the content of the root node (shadow root
6215
+ // for shadow DOM components and the root element itself for light DOM) without having to go
6216
+ // into snabbdom. Especially useful when the reset is a consequence of an error, in which case the
6217
+ // children VNodes might not be representing the current state of the DOM.
6218
+ function resetComponentRoot(vm) {
6117
6219
  const {
6118
- wiredConnecting
6119
- } = vm.context;
6120
- for (let i = 0, len = wiredConnecting.length; i < len; i += 1) {
6121
- wiredConnecting[i]();
6220
+ children,
6221
+ renderRoot,
6222
+ renderer: {
6223
+ remove
6224
+ }
6225
+ } = vm;
6226
+ for (let i = 0, len = children.length; i < len; i++) {
6227
+ const child = children[i];
6228
+ if (!isNull(child) && !isUndefined$1(child.elm)) {
6229
+ remove(child.elm, renderRoot);
6230
+ }
6122
6231
  }
6232
+ vm.children = EmptyArray;
6233
+ runChildNodesDisconnectedCallback(vm);
6234
+ vm.velements = EmptyArray;
6123
6235
  }
6124
- function disconnectWireAdapters(vm) {
6125
- const {
6126
- wiredDisconnecting
6127
- } = vm.context;
6128
- runWithBoundaryProtection(vm, vm, noop, () => {
6129
- // job
6130
- for (let i = 0, len = wiredDisconnecting.length; i < len; i += 1) {
6131
- wiredDisconnecting[i]();
6236
+ function getErrorBoundaryVM(vm) {
6237
+ let currentVm = vm;
6238
+ while (!isNull(currentVm)) {
6239
+ if (!isUndefined$1(currentVm.def.errorCallback)) {
6240
+ return currentVm;
6132
6241
  }
6133
- }, noop);
6242
+ currentVm = currentVm.owner;
6243
+ }
6134
6244
  }
6245
+ function runWithBoundaryProtection(vm, owner, pre, job, post) {
6246
+ let error;
6247
+ pre();
6248
+ try {
6249
+ job();
6250
+ } catch (e) {
6251
+ error = Object(e);
6252
+ } finally {
6253
+ post();
6254
+ if (!isUndefined$1(error)) {
6255
+ addErrorComponentStack(vm, error);
6256
+ const errorBoundaryVm = isNull(owner) ? undefined : getErrorBoundaryVM(owner);
6257
+ if (isUndefined$1(errorBoundaryVm)) {
6258
+ throw error; // eslint-disable-line no-unsafe-finally
6259
+ }
6260
+
6261
+ resetComponentRoot(vm); // remove offenders
6262
+ logOperationStart(6 /* OperationId.ErrorCallback */, vm);
6263
+ // error boundaries must have an ErrorCallback
6264
+ const errorCallback = errorBoundaryVm.def.errorCallback;
6265
+ invokeComponentCallback(errorBoundaryVm, errorCallback, [error, error.wcStack]);
6266
+ logOperationEnd(6 /* OperationId.ErrorCallback */, vm);
6267
+ }
6268
+ }
6269
+ }
6270
+
6271
+ /*
6272
+ * Copyright (c) 2018, salesforce.com, inc.
6273
+ * All rights reserved.
6274
+ * SPDX-License-Identifier: MIT
6275
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6276
+ */
6277
+ //
6278
+ // The goal of this code is to detect invalid cross-root ARIA references in synthetic shadow DOM.
6279
+ // These invalid references should be fixed before the offending components can be migrated to native shadow DOM.
6280
+ // When invalid usage is detected, we warn in dev mode and call the reporting API if enabled.
6281
+ // See: https://lwc.dev/guide/accessibility#link-ids-and-aria-attributes-from-different-templates
6282
+ //
6283
+ // Use the unpatched native getElementById/querySelectorAll rather than the synthetic one
6284
+ _globalThis[KEY__NATIVE_GET_ELEMENT_BY_ID];
6285
+ _globalThis[KEY__NATIVE_QUERY_SELECTOR_ALL];
6135
6286
 
6136
6287
  /*
6137
6288
  * Copyright (c) 2018, salesforce.com, inc.
@@ -6377,7 +6528,7 @@ function freezeTemplate(tmpl) {
6377
6528
  }
6378
6529
  }
6379
6530
  }
6380
- /* version: 2.33.0 */
6531
+ /* version: 2.35.0 */
6381
6532
 
6382
6533
  /*
6383
6534
  * Copyright (c) 2020, salesforce.com, inc.
@@ -6848,6 +6999,6 @@ function renderComponent(tagName, Ctor, props = {}) {
6848
6999
  */
6849
7000
  freeze(LightningElement);
6850
7001
  seal(LightningElement.prototype);
6851
- /* version: 2.33.0 */
7002
+ /* version: 2.35.0 */
6852
7003
 
6853
7004
  export { LightningElement, api$1 as api, createContextProvider, freezeTemplate, getComponentDef, isComponentConstructor, parseFragment, parseFragment as parseSVGFragment, readonly, register, registerComponent, registerDecorators, registerTemplate, renderComponent, renderer, sanitizeAttribute, setFeatureFlag, setFeatureFlagForTest, setHooks, track, unwrap, wire };