lwc 2.23.1 → 2.23.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +1182 -856
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +1182 -855
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +1101 -803
  5. package/dist/engine-dom/iife/es5/engine-dom.js +449 -368
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +409 -335
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +1182 -855
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +1101 -803
  11. package/dist/engine-dom/umd/es5/engine-dom.js +449 -368
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +409 -335
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +782 -521
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +782 -521
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +3 -3
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +3 -3
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +3 -3
  20. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +3 -3
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +3 -3
  22. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +3 -3
  23. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +3 -3
  24. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +3 -3
  25. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +3 -3
  26. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  27. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  28. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  29. package/dist/wire-service/iife/es5/wire-service.js +2 -2
  30. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  31. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/umd/es5/wire-service.js +2 -2
  34. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  35. package/package.json +7 -7
@@ -291,7 +291,7 @@ var LWC = (function (exports) {
291
291
  CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
292
292
  return attributeName;
293
293
  }
294
- /** version: 2.23.1 */
294
+ /** version: 2.23.2 */
295
295
 
296
296
  /**
297
297
  * Copyright (C) 2018 salesforce.com, inc.
@@ -373,7 +373,7 @@ var LWC = (function (exports) {
373
373
  patch$1(propName);
374
374
  }
375
375
  }
376
- /** version: 2.23.1 */
376
+ /** version: 2.23.2 */
377
377
 
378
378
  /**
379
379
  * Copyright (C) 2018 salesforce.com, inc.
@@ -393,6 +393,7 @@ var LWC = (function (exports) {
393
393
  ENABLE_HTML_COLLECTIONS_PATCH: null,
394
394
  ENABLE_INNER_OUTER_TEXT_PATCH: null,
395
395
  ENABLE_MIXED_SHADOW_MODE: null,
396
+ ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE: null,
396
397
  ENABLE_NODE_LIST_PATCH: null,
397
398
  ENABLE_NODE_PATCH: null,
398
399
  ENABLE_REACTIVE_SETTER: null,
@@ -706,8 +707,8 @@ var LWC = (function (exports) {
706
707
  */
707
708
  // This is a temporary workaround to get the @lwc/engine-server to evaluate in node without having
708
709
  // to inject at runtime.
709
- const HTMLElementConstructor$1 = typeof HTMLElement !== 'undefined' ? HTMLElement : function () { };
710
- const HTMLElementPrototype = HTMLElementConstructor$1.prototype;
710
+ const HTMLElementConstructor = typeof HTMLElement !== 'undefined' ? HTMLElement : function () { };
711
+ const HTMLElementPrototype = HTMLElementConstructor.prototype;
711
712
 
712
713
  /*
713
714
  * Copyright (c) 2018, salesforce.com, inc.
@@ -2097,7 +2098,7 @@ var LWC = (function (exports) {
2097
2098
  defineProperties(HTMLBridgeElement.prototype, descriptors);
2098
2099
  return HTMLBridgeElement;
2099
2100
  }
2100
- const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor$1, getOwnPropertyNames$1(HTMLElementOriginalDescriptors), []);
2101
+ const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, getOwnPropertyNames$1(HTMLElementOriginalDescriptors), []);
2101
2102
  freeze(BaseBridgeElement);
2102
2103
  seal(BaseBridgeElement.prototype);
2103
2104
  function setActiveVM(vm) {
@@ -2472,30 +2473,61 @@ var LWC = (function (exports) {
2472
2473
  * SPDX-License-Identifier: MIT
2473
2474
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2474
2475
  */
2476
+
2477
+ function checkHasVM(elm) {
2478
+ const hasVM = !isUndefined$1(getAssociatedVMIfPresent(elm));
2479
+
2480
+ return hasVM;
2481
+ }
2482
+
2475
2483
  function getUpgradableConstructor(tagName, renderer) {
2476
- const { getCustomElement, HTMLElementExported: RendererHTMLElement, defineCustomElement, } = renderer;
2477
- // Should never get a tag with upper case letter at this point, the compiler should
2478
- // produce only tags with lowercase letters
2479
- // But, for backwards compatibility, we will lower case the tagName
2480
- tagName = tagName.toLowerCase();
2481
- let CE = getCustomElement(tagName);
2482
- if (!isUndefined$1(CE)) {
2483
- return CE;
2484
+ const {
2485
+ getCustomElement,
2486
+ HTMLElementExported: RendererHTMLElement,
2487
+ defineCustomElement
2488
+ } = renderer; // Should never get a tag with upper case letter at this point, the compiler should
2489
+ // produce only tags with lowercase letters
2490
+ // But, for backwards compatibility, we will lower case the tagName
2491
+
2492
+ tagName = tagName.toLowerCase();
2493
+ let CE = getCustomElement(tagName);
2494
+
2495
+ if (!isUndefined$1(CE)) {
2496
+ return CE;
2497
+ }
2498
+ /**
2499
+ * LWC Upgradable Element reference to an element that was created
2500
+ * via the scoped registry mechanism, and that is ready to be upgraded.
2501
+ */
2502
+
2503
+
2504
+ CE = class LWCUpgradableElement extends RendererHTMLElement {
2505
+ constructor(upgradeCallback) {
2506
+ super();
2507
+
2508
+ if (isFunction$1(upgradeCallback)) {
2509
+ upgradeCallback(this); // nothing to do with the result for now
2510
+ }
2484
2511
  }
2485
- /**
2486
- * LWC Upgradable Element reference to an element that was created
2487
- * via the scoped registry mechanism, and that is ready to be upgraded.
2488
- */
2489
- CE = class LWCUpgradableElement extends RendererHTMLElement {
2490
- constructor(upgradeCallback) {
2491
- super();
2492
- if (isFunction$1(upgradeCallback)) {
2493
- upgradeCallback(this); // nothing to do with the result for now
2494
- }
2495
- }
2512
+
2513
+ };
2514
+
2515
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
2516
+ CE.prototype.connectedCallback = function () {
2517
+ if (checkHasVM(this)) {
2518
+ connectRootElement(this);
2519
+ }
2496
2520
  };
2497
- defineCustomElement(tagName, CE);
2498
- return CE;
2521
+
2522
+ CE.prototype.disconnectedCallback = function () {
2523
+ if (checkHasVM(this)) {
2524
+ disconnectRootElement(this);
2525
+ }
2526
+ };
2527
+ }
2528
+
2529
+ defineCustomElement(tagName, CE);
2530
+ return CE;
2499
2531
  }
2500
2532
 
2501
2533
  /*
@@ -2737,534 +2769,732 @@ var LWC = (function (exports) {
2737
2769
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2738
2770
  */
2739
2771
  function patchChildren(c1, c2, parent, renderer) {
2740
- if (hasDynamicChildren(c2)) {
2741
- updateDynamicChildren(c1, c2, parent, renderer);
2742
- }
2743
- else {
2744
- updateStaticChildren(c1, c2, parent, renderer);
2745
- }
2772
+ if (hasDynamicChildren(c2)) {
2773
+ updateDynamicChildren(c1, c2, parent, renderer);
2774
+ } else {
2775
+ updateStaticChildren(c1, c2, parent, renderer);
2776
+ }
2746
2777
  }
2778
+
2747
2779
  function patch(n1, n2, parent, renderer) {
2748
- var _a, _b;
2749
- if (n1 === n2) {
2750
- return;
2751
- }
2752
- switch (n2.type) {
2753
- case 0 /* VNodeType.Text */:
2754
- // VText has no special capability, fallback to the owner's renderer
2755
- patchText(n1, n2, renderer);
2756
- break;
2757
- case 1 /* VNodeType.Comment */:
2758
- // VComment has no special capability, fallback to the owner's renderer
2759
- patchComment(n1, n2, renderer);
2760
- break;
2761
- case 4 /* VNodeType.Static */:
2762
- n2.elm = n1.elm;
2763
- break;
2764
- case 2 /* VNodeType.Element */:
2765
- patchElement(n1, n2, (_a = n2.data.renderer) !== null && _a !== void 0 ? _a : renderer);
2766
- break;
2767
- case 3 /* VNodeType.CustomElement */:
2768
- patchCustomElement(n1, n2, parent, (_b = n2.data.renderer) !== null && _b !== void 0 ? _b : renderer);
2769
- break;
2770
- }
2780
+ var _a, _b;
2781
+
2782
+ if (n1 === n2) {
2783
+ return;
2784
+ }
2785
+
2786
+ switch (n2.type) {
2787
+ case 0
2788
+ /* VNodeType.Text */
2789
+ :
2790
+ // VText has no special capability, fallback to the owner's renderer
2791
+ patchText(n1, n2, renderer);
2792
+ break;
2793
+
2794
+ case 1
2795
+ /* VNodeType.Comment */
2796
+ :
2797
+ // VComment has no special capability, fallback to the owner's renderer
2798
+ patchComment(n1, n2, renderer);
2799
+ break;
2800
+
2801
+ case 4
2802
+ /* VNodeType.Static */
2803
+ :
2804
+ n2.elm = n1.elm;
2805
+ break;
2806
+
2807
+ case 2
2808
+ /* VNodeType.Element */
2809
+ :
2810
+ patchElement(n1, n2, (_a = n2.data.renderer) !== null && _a !== void 0 ? _a : renderer);
2811
+ break;
2812
+
2813
+ case 3
2814
+ /* VNodeType.CustomElement */
2815
+ :
2816
+ patchCustomElement(n1, n2, parent, (_b = n2.data.renderer) !== null && _b !== void 0 ? _b : renderer);
2817
+ break;
2818
+ }
2771
2819
  }
2820
+
2772
2821
  function mount(node, parent, renderer, anchor) {
2773
- var _a, _b;
2774
- switch (node.type) {
2775
- case 0 /* VNodeType.Text */:
2776
- // VText has no special capability, fallback to the owner's renderer
2777
- mountText(node, parent, anchor, renderer);
2778
- break;
2779
- case 1 /* VNodeType.Comment */:
2780
- // VComment has no special capability, fallback to the owner's renderer
2781
- mountComment(node, parent, anchor, renderer);
2782
- break;
2783
- case 4 /* VNodeType.Static */:
2784
- // VStatic cannot have a custom renderer associated to them, using owner's renderer
2785
- mountStatic(node, parent, anchor, renderer);
2786
- break;
2787
- case 2 /* VNodeType.Element */:
2788
- // If the vnode data has a renderer override use it, else fallback to owner's renderer
2789
- mountElement(node, parent, anchor, (_a = node.data.renderer) !== null && _a !== void 0 ? _a : renderer);
2790
- break;
2791
- case 3 /* VNodeType.CustomElement */:
2792
- // If the vnode data has a renderer override use it, else fallback to owner's renderer
2793
- mountCustomElement(node, parent, anchor, (_b = node.data.renderer) !== null && _b !== void 0 ? _b : renderer);
2794
- break;
2795
- }
2822
+ var _a, _b;
2823
+
2824
+ switch (node.type) {
2825
+ case 0
2826
+ /* VNodeType.Text */
2827
+ :
2828
+ // VText has no special capability, fallback to the owner's renderer
2829
+ mountText(node, parent, anchor, renderer);
2830
+ break;
2831
+
2832
+ case 1
2833
+ /* VNodeType.Comment */
2834
+ :
2835
+ // VComment has no special capability, fallback to the owner's renderer
2836
+ mountComment(node, parent, anchor, renderer);
2837
+ break;
2838
+
2839
+ case 4
2840
+ /* VNodeType.Static */
2841
+ :
2842
+ // VStatic cannot have a custom renderer associated to them, using owner's renderer
2843
+ mountStatic(node, parent, anchor, renderer);
2844
+ break;
2845
+
2846
+ case 2
2847
+ /* VNodeType.Element */
2848
+ :
2849
+ // If the vnode data has a renderer override use it, else fallback to owner's renderer
2850
+ mountElement(node, parent, anchor, (_a = node.data.renderer) !== null && _a !== void 0 ? _a : renderer);
2851
+ break;
2852
+
2853
+ case 3
2854
+ /* VNodeType.CustomElement */
2855
+ :
2856
+ // If the vnode data has a renderer override use it, else fallback to owner's renderer
2857
+ mountCustomElement(node, parent, anchor, (_b = node.data.renderer) !== null && _b !== void 0 ? _b : renderer);
2858
+ break;
2859
+ }
2796
2860
  }
2861
+
2797
2862
  function patchText(n1, n2, renderer) {
2798
- n2.elm = n1.elm;
2799
- if (n2.text !== n1.text) {
2800
- updateTextContent(n2, renderer);
2801
- }
2863
+ n2.elm = n1.elm;
2864
+
2865
+ if (n2.text !== n1.text) {
2866
+ updateTextContent(n2, renderer);
2867
+ }
2802
2868
  }
2869
+
2803
2870
  function mountText(vnode, parent, anchor, renderer) {
2804
- const { owner } = vnode;
2805
- const { createText } = renderer;
2806
- const textNode = (vnode.elm = createText(vnode.text));
2807
- linkNodeToShadow(textNode, owner, renderer);
2808
- insertNode(textNode, parent, anchor, renderer);
2871
+ const {
2872
+ owner
2873
+ } = vnode;
2874
+ const {
2875
+ createText
2876
+ } = renderer;
2877
+ const textNode = vnode.elm = createText(vnode.text);
2878
+ linkNodeToShadow(textNode, owner, renderer);
2879
+ insertNode(textNode, parent, anchor, renderer);
2809
2880
  }
2881
+
2810
2882
  function patchComment(n1, n2, renderer) {
2811
- n2.elm = n1.elm;
2812
- // FIXME: Comment nodes should be static, we shouldn't need to diff them together. However
2813
- // it is the case today.
2814
- if (n2.text !== n1.text) {
2815
- updateTextContent(n2, renderer);
2816
- }
2883
+ n2.elm = n1.elm; // FIXME: Comment nodes should be static, we shouldn't need to diff them together. However
2884
+ // it is the case today.
2885
+
2886
+ if (n2.text !== n1.text) {
2887
+ updateTextContent(n2, renderer);
2888
+ }
2817
2889
  }
2890
+
2818
2891
  function mountComment(vnode, parent, anchor, renderer) {
2819
- const { owner } = vnode;
2820
- const { createComment } = renderer;
2821
- const commentNode = (vnode.elm = createComment(vnode.text));
2822
- linkNodeToShadow(commentNode, owner, renderer);
2823
- insertNode(commentNode, parent, anchor, renderer);
2892
+ const {
2893
+ owner
2894
+ } = vnode;
2895
+ const {
2896
+ createComment
2897
+ } = renderer;
2898
+ const commentNode = vnode.elm = createComment(vnode.text);
2899
+ linkNodeToShadow(commentNode, owner, renderer);
2900
+ insertNode(commentNode, parent, anchor, renderer);
2824
2901
  }
2902
+
2825
2903
  function mountElement(vnode, parent, anchor, renderer) {
2826
- const { sel, owner, data: { svg }, } = vnode;
2827
- const { createElement } = renderer;
2828
- const namespace = isTrue(svg) ? SVG_NAMESPACE : undefined;
2829
- const elm = (vnode.elm = createElement(sel, namespace));
2830
- linkNodeToShadow(elm, owner, renderer);
2831
- applyStyleScoping(elm, owner, renderer);
2832
- applyDomManual(elm, vnode);
2833
- patchElementPropsAndAttrs$1(null, vnode, renderer);
2834
- insertNode(elm, parent, anchor, renderer);
2835
- mountVNodes(vnode.children, elm, renderer, null);
2904
+ const {
2905
+ sel,
2906
+ owner,
2907
+ data: {
2908
+ svg
2909
+ }
2910
+ } = vnode;
2911
+ const {
2912
+ createElement
2913
+ } = renderer;
2914
+ const namespace = isTrue(svg) ? SVG_NAMESPACE : undefined;
2915
+ const elm = vnode.elm = createElement(sel, namespace);
2916
+ linkNodeToShadow(elm, owner, renderer);
2917
+ applyStyleScoping(elm, owner, renderer);
2918
+ applyDomManual(elm, vnode);
2919
+ patchElementPropsAndAttrs$1(null, vnode, renderer);
2920
+ insertNode(elm, parent, anchor, renderer);
2921
+ mountVNodes(vnode.children, elm, renderer, null);
2836
2922
  }
2923
+
2837
2924
  function patchElement(n1, n2, renderer) {
2838
- const elm = (n2.elm = n1.elm);
2839
- patchElementPropsAndAttrs$1(n1, n2, renderer);
2840
- patchChildren(n1.children, n2.children, elm, renderer);
2925
+ const elm = n2.elm = n1.elm;
2926
+ patchElementPropsAndAttrs$1(n1, n2, renderer);
2927
+ patchChildren(n1.children, n2.children, elm, renderer);
2841
2928
  }
2929
+
2842
2930
  function mountStatic(vnode, parent, anchor, renderer) {
2843
- const { owner } = vnode;
2844
- const { cloneNode, isSyntheticShadowDefined } = renderer;
2845
- const elm = (vnode.elm = cloneNode(vnode.fragment, true));
2846
- linkNodeToShadow(elm, owner, renderer);
2847
- // Marks this node as Static to propagate the shadow resolver. must happen after elm is assigned to the proper shadow
2848
- const { renderMode, shadowMode } = owner;
2849
- if (isSyntheticShadowDefined) {
2850
- if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
2851
- elm[KEY__SHADOW_STATIC] = true;
2852
- }
2931
+ const {
2932
+ owner
2933
+ } = vnode;
2934
+ const {
2935
+ cloneNode,
2936
+ isSyntheticShadowDefined
2937
+ } = renderer;
2938
+ const elm = vnode.elm = cloneNode(vnode.fragment, true);
2939
+ linkNodeToShadow(elm, owner, renderer);
2940
+
2941
+ const {
2942
+ renderMode,
2943
+ shadowMode
2944
+ } = owner;
2945
+
2946
+ if (isSyntheticShadowDefined) {
2947
+ if (shadowMode === 1
2948
+ /* ShadowMode.Synthetic */
2949
+ || renderMode === 0
2950
+ /* RenderMode.Light */
2951
+ ) {
2952
+ elm[KEY__SHADOW_STATIC] = true;
2853
2953
  }
2854
- insertNode(elm, parent, anchor, renderer);
2954
+ }
2955
+
2956
+ insertNode(elm, parent, anchor, renderer);
2855
2957
  }
2958
+
2856
2959
  function mountCustomElement(vnode, parent, anchor, renderer) {
2857
- const { sel, owner } = vnode;
2858
- const UpgradableConstructor = getUpgradableConstructor(sel, renderer);
2859
- /**
2860
- * Note: if the upgradable constructor does not expect, or throw when we new it
2861
- * with a callback as the first argument, we could implement a more advanced
2862
- * mechanism that only passes that argument if the constructor is known to be
2863
- * an upgradable custom element.
2864
- */
2865
- let vm;
2866
- const elm = new UpgradableConstructor((elm) => {
2867
- // the custom element from the registry is expecting an upgrade callback
2868
- vm = createViewModelHook(elm, vnode, renderer);
2869
- });
2870
- vnode.elm = elm;
2871
- vnode.vm = vm;
2872
- linkNodeToShadow(elm, owner, renderer);
2873
- applyStyleScoping(elm, owner, renderer);
2874
- if (vm) {
2875
- allocateChildren(vnode, vm);
2876
- }
2877
- else if (vnode.ctor !== UpgradableConstructor) {
2878
- throw new TypeError(`Incorrect Component Constructor`);
2879
- }
2880
- patchElementPropsAndAttrs$1(null, vnode, renderer);
2881
- insertNode(elm, parent, anchor, renderer);
2882
- if (vm) {
2960
+ const {
2961
+ sel,
2962
+ owner
2963
+ } = vnode;
2964
+ const UpgradableConstructor = getUpgradableConstructor(sel, renderer);
2965
+ /**
2966
+ * Note: if the upgradable constructor does not expect, or throw when we new it
2967
+ * with a callback as the first argument, we could implement a more advanced
2968
+ * mechanism that only passes that argument if the constructor is known to be
2969
+ * an upgradable custom element.
2970
+ */
2971
+
2972
+ let vm;
2973
+ const elm = new UpgradableConstructor(elm => {
2974
+ // the custom element from the registry is expecting an upgrade callback
2975
+ vm = createViewModelHook(elm, vnode, renderer);
2976
+ });
2977
+ vnode.elm = elm;
2978
+ vnode.vm = vm;
2979
+ linkNodeToShadow(elm, owner, renderer);
2980
+ applyStyleScoping(elm, owner, renderer);
2981
+
2982
+ if (vm) {
2983
+ allocateChildren(vnode, vm);
2984
+ } else if (vnode.ctor !== UpgradableConstructor) {
2985
+ throw new TypeError(`Incorrect Component Constructor`);
2986
+ }
2987
+
2988
+ patchElementPropsAndAttrs$1(null, vnode, renderer);
2989
+ insertNode(elm, parent, anchor, renderer);
2990
+
2991
+ if (vm) {
2992
+ {
2993
+ if (!lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
2994
+
2883
2995
  runConnectedCallback(vm);
2996
+ }
2884
2997
  }
2885
- mountVNodes(vnode.children, elm, renderer, null);
2886
- if (vm) {
2887
- appendVM(vm);
2888
- }
2998
+ }
2999
+
3000
+ mountVNodes(vnode.children, elm, renderer, null);
3001
+
3002
+ if (vm) {
3003
+ appendVM(vm);
3004
+ }
2889
3005
  }
3006
+
2890
3007
  function patchCustomElement(n1, n2, parent, renderer) {
2891
- if (n1.ctor !== n2.ctor) {
2892
- // If the constructor, unmount the current component and mount a new one using the new
2893
- // constructor.
2894
- const anchor = renderer.nextSibling(n1.elm);
2895
- unmount(n1, parent, renderer, true);
2896
- mountCustomElement(n2, parent, anchor, renderer);
2897
- }
2898
- else {
2899
- // Otherwise patch the existing component with new props/attrs/etc.
2900
- const elm = (n2.elm = n1.elm);
2901
- const vm = (n2.vm = n1.vm);
2902
- patchElementPropsAndAttrs$1(n1, n2, renderer);
2903
- if (!isUndefined$1(vm)) {
2904
- // in fallback mode, the allocation will always set children to
2905
- // empty and delegate the real allocation to the slot elements
2906
- allocateChildren(n2, vm);
2907
- }
2908
- // in fallback mode, the children will be always empty, so, nothing
2909
- // will happen, but in native, it does allocate the light dom
2910
- patchChildren(n1.children, n2.children, elm, renderer);
2911
- if (!isUndefined$1(vm)) {
2912
- // this will probably update the shadowRoot, but only if the vm is in a dirty state
2913
- // this is important to preserve the top to bottom synchronous rendering phase.
2914
- rerenderVM(vm);
2915
- }
3008
+ if (n1.ctor !== n2.ctor) {
3009
+ // If the constructor, unmount the current component and mount a new one using the new
3010
+ // constructor.
3011
+ const anchor = renderer.nextSibling(n1.elm);
3012
+ unmount(n1, parent, renderer, true);
3013
+ mountCustomElement(n2, parent, anchor, renderer);
3014
+ } else {
3015
+ // Otherwise patch the existing component with new props/attrs/etc.
3016
+ const elm = n2.elm = n1.elm;
3017
+ const vm = n2.vm = n1.vm;
3018
+ patchElementPropsAndAttrs$1(n1, n2, renderer);
3019
+
3020
+ if (!isUndefined$1(vm)) {
3021
+ // in fallback mode, the allocation will always set children to
3022
+ // empty and delegate the real allocation to the slot elements
3023
+ allocateChildren(n2, vm);
3024
+ } // in fallback mode, the children will be always empty, so, nothing
3025
+ // will happen, but in native, it does allocate the light dom
3026
+
3027
+
3028
+ patchChildren(n1.children, n2.children, elm, renderer);
3029
+
3030
+ if (!isUndefined$1(vm)) {
3031
+ // this will probably update the shadowRoot, but only if the vm is in a dirty state
3032
+ // this is important to preserve the top to bottom synchronous rendering phase.
3033
+ rerenderVM(vm);
2916
3034
  }
3035
+ }
2917
3036
  }
3037
+
2918
3038
  function mountVNodes(vnodes, parent, renderer, anchor, start = 0, end = vnodes.length) {
2919
- for (; start < end; ++start) {
2920
- const vnode = vnodes[start];
2921
- if (isVNode(vnode)) {
2922
- mount(vnode, parent, renderer, anchor);
2923
- }
3039
+ for (; start < end; ++start) {
3040
+ const vnode = vnodes[start];
3041
+
3042
+ if (isVNode(vnode)) {
3043
+ mount(vnode, parent, renderer, anchor);
2924
3044
  }
3045
+ }
2925
3046
  }
3047
+
2926
3048
  function unmount(vnode, parent, renderer, doRemove = false) {
2927
- const { type, elm, sel } = vnode;
2928
- // When unmounting a VNode subtree not all the elements have to removed from the DOM. The
2929
- // subtree root, is the only element worth unmounting from the subtree.
2930
- if (doRemove) {
2931
- // The vnode might or might not have a data.renderer associated to it
2932
- // but the removal used here is from the owner instead.
2933
- removeNode(elm, parent, renderer);
2934
- }
2935
- switch (type) {
2936
- case 2 /* VNodeType.Element */: {
2937
- // Slot content is removed to trigger slotchange event when removing slot.
2938
- // Only required for synthetic shadow.
2939
- const shouldRemoveChildren = sel === 'slot' && vnode.owner.shadowMode === 1 /* ShadowMode.Synthetic */;
2940
- unmountVNodes(vnode.children, elm, renderer, shouldRemoveChildren);
2941
- break;
2942
- }
2943
- case 3 /* VNodeType.CustomElement */: {
2944
- const { vm } = vnode;
2945
- // No need to unmount the children here, `removeVM` will take care of removing the
2946
- // children.
2947
- if (!isUndefined$1(vm)) {
2948
- removeVM(vm);
2949
- }
3049
+ const {
3050
+ type,
3051
+ elm,
3052
+ sel
3053
+ } = vnode; // When unmounting a VNode subtree not all the elements have to removed from the DOM. The
3054
+ // subtree root, is the only element worth unmounting from the subtree.
3055
+
3056
+ if (doRemove) {
3057
+ // The vnode might or might not have a data.renderer associated to it
3058
+ // but the removal used here is from the owner instead.
3059
+ removeNode(elm, parent, renderer);
3060
+ }
3061
+
3062
+ switch (type) {
3063
+ case 2
3064
+ /* VNodeType.Element */
3065
+ :
3066
+ {
3067
+ // Slot content is removed to trigger slotchange event when removing slot.
3068
+ // Only required for synthetic shadow.
3069
+ const shouldRemoveChildren = sel === 'slot' && vnode.owner.shadowMode === 1
3070
+ /* ShadowMode.Synthetic */
3071
+ ;
3072
+ unmountVNodes(vnode.children, elm, renderer, shouldRemoveChildren);
3073
+ break;
3074
+ }
3075
+
3076
+ case 3
3077
+ /* VNodeType.CustomElement */
3078
+ :
3079
+ {
3080
+ const {
3081
+ vm
3082
+ } = vnode; // No need to unmount the children here, `removeVM` will take care of removing the
3083
+ // children.
3084
+
3085
+ if (!isUndefined$1(vm)) {
3086
+ removeVM(vm);
2950
3087
  }
2951
- }
3088
+ }
3089
+ }
2952
3090
  }
3091
+
2953
3092
  function unmountVNodes(vnodes, parent, renderer, doRemove = false, start = 0, end = vnodes.length) {
2954
- for (; start < end; ++start) {
2955
- const ch = vnodes[start];
2956
- if (isVNode(ch)) {
2957
- unmount(ch, parent, renderer, doRemove);
2958
- }
3093
+ for (; start < end; ++start) {
3094
+ const ch = vnodes[start];
3095
+
3096
+ if (isVNode(ch)) {
3097
+ unmount(ch, parent, renderer, doRemove);
2959
3098
  }
3099
+ }
2960
3100
  }
3101
+
2961
3102
  function isVNode(vnode) {
2962
- return vnode != null;
3103
+ return vnode != null;
2963
3104
  }
3105
+
2964
3106
  function linkNodeToShadow(elm, owner, renderer) {
2965
- const { renderRoot, renderMode, shadowMode } = owner;
2966
- const { isSyntheticShadowDefined } = renderer;
2967
- // TODO [#1164]: this should eventually be done by the polyfill directly
2968
- if (isSyntheticShadowDefined) {
2969
- if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
2970
- elm[KEY__SHADOW_RESOLVER] = renderRoot[KEY__SHADOW_RESOLVER];
2971
- }
3107
+ const {
3108
+ renderRoot,
3109
+ renderMode,
3110
+ shadowMode
3111
+ } = owner;
3112
+ const {
3113
+ isSyntheticShadowDefined
3114
+ } = renderer; // TODO [#1164]: this should eventually be done by the polyfill directly
3115
+
3116
+ if (isSyntheticShadowDefined) {
3117
+ if (shadowMode === 1
3118
+ /* ShadowMode.Synthetic */
3119
+ || renderMode === 0
3120
+ /* RenderMode.Light */
3121
+ ) {
3122
+ elm[KEY__SHADOW_RESOLVER] = renderRoot[KEY__SHADOW_RESOLVER];
2972
3123
  }
3124
+ }
2973
3125
  }
3126
+
2974
3127
  function updateTextContent(vnode, renderer) {
2975
- const { elm, text } = vnode;
2976
- const { setText } = renderer;
2977
- setText(elm, text);
3128
+ const {
3129
+ elm,
3130
+ text
3131
+ } = vnode;
3132
+ const {
3133
+ setText
3134
+ } = renderer;
3135
+
3136
+ setText(elm, text);
2978
3137
  }
3138
+
2979
3139
  function insertNode(node, parent, anchor, renderer) {
2980
- renderer.insert(node, parent, anchor);
3140
+
3141
+ renderer.insert(node, parent, anchor);
2981
3142
  }
3143
+
2982
3144
  function removeNode(node, parent, renderer) {
2983
- renderer.remove(node, parent);
3145
+
3146
+ renderer.remove(node, parent);
2984
3147
  }
3148
+
2985
3149
  function patchElementPropsAndAttrs$1(oldVnode, vnode, renderer) {
2986
- if (isNull(oldVnode)) {
2987
- applyEventListeners(vnode, renderer);
2988
- applyStaticClassAttribute(vnode, renderer);
2989
- applyStaticStyleAttribute(vnode, renderer);
2990
- }
2991
- // Attrs need to be applied to element before props IE11 will wipe out value on radio inputs if
2992
- // value is set before type=radio.
2993
- patchClassAttribute(oldVnode, vnode, renderer);
2994
- patchStyleAttribute(oldVnode, vnode, renderer);
2995
- patchAttributes(oldVnode, vnode, renderer);
2996
- patchProps(oldVnode, vnode, renderer);
3150
+ if (isNull(oldVnode)) {
3151
+ applyEventListeners(vnode, renderer);
3152
+ applyStaticClassAttribute(vnode, renderer);
3153
+ applyStaticStyleAttribute(vnode, renderer);
3154
+ } // Attrs need to be applied to element before props IE11 will wipe out value on radio inputs if
3155
+ // value is set before type=radio.
3156
+
3157
+
3158
+ patchClassAttribute(oldVnode, vnode, renderer);
3159
+ patchStyleAttribute(oldVnode, vnode, renderer);
3160
+ patchAttributes(oldVnode, vnode, renderer);
3161
+ patchProps(oldVnode, vnode, renderer);
2997
3162
  }
3163
+
2998
3164
  function applyStyleScoping(elm, owner, renderer) {
2999
- // Set the class name for `*.scoped.css` style scoping.
3000
- const scopeToken = getScopeTokenClass(owner);
3001
- if (!isNull(scopeToken)) {
3002
- const { getClassList } = renderer;
3003
- // TODO [#2762]: this dot notation with add is probably problematic
3004
- // probably we should have a renderer api for just the add operation
3005
- getClassList(elm).add(scopeToken);
3006
- }
3007
- // Set property element for synthetic shadow DOM style scoping.
3008
- const { stylesheetToken: syntheticToken } = owner.context;
3009
- if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && !isUndefined$1(syntheticToken)) {
3010
- elm.$shadowToken$ = syntheticToken;
3011
- }
3165
+ // Set the class name for `*.scoped.css` style scoping.
3166
+ const scopeToken = getScopeTokenClass(owner);
3167
+
3168
+ if (!isNull(scopeToken)) {
3169
+ const {
3170
+ getClassList
3171
+ } = renderer; // TODO [#2762]: this dot notation with add is probably problematic
3172
+ // probably we should have a renderer api for just the add operation
3173
+
3174
+ getClassList(elm).add(scopeToken);
3175
+ } // Set property element for synthetic shadow DOM style scoping.
3176
+
3177
+
3178
+ const {
3179
+ stylesheetToken: syntheticToken
3180
+ } = owner.context;
3181
+
3182
+ if (owner.shadowMode === 1
3183
+ /* ShadowMode.Synthetic */
3184
+ && !isUndefined$1(syntheticToken)) {
3185
+ elm.$shadowToken$ = syntheticToken;
3186
+ }
3012
3187
  }
3188
+
3013
3189
  function applyDomManual(elm, vnode) {
3014
- var _a;
3015
- const { owner, data: { context }, } = vnode;
3016
- if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && ((_a = context === null || context === void 0 ? void 0 : context.lwc) === null || _a === void 0 ? void 0 : _a.dom) === "manual" /* LwcDomMode.Manual */) {
3017
- elm.$domManual$ = true;
3190
+ var _a;
3191
+
3192
+ const {
3193
+ owner,
3194
+ data: {
3195
+ context
3018
3196
  }
3197
+ } = vnode;
3198
+
3199
+ if (owner.shadowMode === 1
3200
+ /* ShadowMode.Synthetic */
3201
+ && ((_a = context === null || context === void 0 ? void 0 : context.lwc) === null || _a === void 0 ? void 0 : _a.dom) === "manual"
3202
+ /* LwcDomMode.Manual */
3203
+ ) {
3204
+ elm.$domManual$ = true;
3205
+ }
3019
3206
  }
3207
+
3020
3208
  function allocateChildren(vnode, vm) {
3021
- // A component with slots will re-render because:
3022
- // 1- There is a change of the internal state.
3023
- // 2- There is a change on the external api (ex: slots)
3024
- //
3025
- // In case #1, the vnodes in the cmpSlots will be reused since they didn't changed. This routine emptied the
3026
- // slotted children when those VCustomElement were rendered and therefore in subsequent calls to allocate children
3027
- // in a reused VCustomElement, there won't be any slotted children.
3028
- // For those cases, we will use the reference for allocated children stored when rendering the fresh VCustomElement.
3029
- //
3030
- // In case #2, we will always get a fresh VCustomElement.
3031
- const children = vnode.aChildren || vnode.children;
3032
- vm.aChildren = children;
3033
- const { renderMode, shadowMode } = vm;
3034
- if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
3035
- // slow path
3036
- allocateInSlot(vm, children);
3037
- // save the allocated children in case this vnode is reused.
3038
- vnode.aChildren = children;
3039
- // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
3040
- vnode.children = EmptyArray;
3041
- }
3209
+ // A component with slots will re-render because:
3210
+ // 1- There is a change of the internal state.
3211
+ // 2- There is a change on the external api (ex: slots)
3212
+ //
3213
+ // In case #1, the vnodes in the cmpSlots will be reused since they didn't changed. This routine emptied the
3214
+ // slotted children when those VCustomElement were rendered and therefore in subsequent calls to allocate children
3215
+ // in a reused VCustomElement, there won't be any slotted children.
3216
+ // For those cases, we will use the reference for allocated children stored when rendering the fresh VCustomElement.
3217
+ //
3218
+ // In case #2, we will always get a fresh VCustomElement.
3219
+ const children = vnode.aChildren || vnode.children;
3220
+ vm.aChildren = children;
3221
+ const {
3222
+ renderMode,
3223
+ shadowMode
3224
+ } = vm;
3225
+
3226
+ if (shadowMode === 1
3227
+ /* ShadowMode.Synthetic */
3228
+ || renderMode === 0
3229
+ /* RenderMode.Light */
3230
+ ) {
3231
+ // slow path
3232
+ allocateInSlot(vm, children); // save the allocated children in case this vnode is reused.
3233
+
3234
+ vnode.aChildren = children; // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
3235
+
3236
+ vnode.children = EmptyArray;
3237
+ }
3042
3238
  }
3239
+
3043
3240
  function createViewModelHook(elm, vnode, renderer) {
3044
- let vm = getAssociatedVMIfPresent(elm);
3045
- // There is a possibility that a custom element is registered under tagName, in which case, the
3046
- // initialization is already carry on, and there is nothing else to do here since this hook is
3047
- // called right after invoking `document.createElement`.
3048
- if (!isUndefined$1(vm)) {
3049
- return vm;
3241
+ let vm = getAssociatedVMIfPresent(elm); // There is a possibility that a custom element is registered under tagName, in which case, the
3242
+ // initialization is already carry on, and there is nothing else to do here since this hook is
3243
+ // called right after invoking `document.createElement`.
3244
+
3245
+ if (!isUndefined$1(vm)) {
3246
+ return vm;
3247
+ }
3248
+
3249
+ const {
3250
+ sel,
3251
+ mode,
3252
+ ctor,
3253
+ owner
3254
+ } = vnode;
3255
+ vm = createVM(elm, ctor, renderer, {
3256
+ mode,
3257
+ owner,
3258
+ tagName: sel
3259
+ });
3260
+
3261
+ return vm;
3262
+ }
3263
+
3264
+ function allocateInSlot(vm, children) {
3265
+ var _a;
3266
+
3267
+ const {
3268
+ cmpSlots: oldSlots
3269
+ } = vm;
3270
+ const cmpSlots = vm.cmpSlots = create(null);
3271
+
3272
+ for (let i = 0, len = children.length; i < len; i += 1) {
3273
+ const vnode = children[i];
3274
+
3275
+ if (isNull(vnode)) {
3276
+ continue;
3277
+ }
3278
+
3279
+ let slotName = '';
3280
+
3281
+ if (isVBaseElement(vnode)) {
3282
+ slotName = ((_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) || '';
3283
+ }
3284
+
3285
+ const vnodes = cmpSlots[slotName] = cmpSlots[slotName] || [];
3286
+ ArrayPush$1.call(vnodes, vnode);
3287
+ }
3288
+
3289
+ if (isFalse(vm.isDirty)) {
3290
+ // We need to determine if the old allocation is really different from the new one
3291
+ // and mark the vm as dirty
3292
+ const oldKeys = keys(oldSlots);
3293
+
3294
+ if (oldKeys.length !== keys(cmpSlots).length) {
3295
+ markComponentAsDirty(vm);
3296
+ return;
3050
3297
  }
3051
- const { sel, mode, ctor, owner } = vnode;
3052
- vm = createVM(elm, ctor, renderer, {
3053
- mode,
3054
- owner,
3055
- tagName: sel,
3056
- });
3057
- return vm;
3058
- }
3059
- function allocateInSlot(vm, children) {
3060
- var _a;
3061
- const { cmpSlots: oldSlots } = vm;
3062
- const cmpSlots = (vm.cmpSlots = create(null));
3063
- for (let i = 0, len = children.length; i < len; i += 1) {
3064
- const vnode = children[i];
3065
- if (isNull(vnode)) {
3066
- continue;
3067
- }
3068
- let slotName = '';
3069
- if (isVBaseElement(vnode)) {
3070
- slotName = ((_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) || '';
3071
- }
3072
- const vnodes = (cmpSlots[slotName] = cmpSlots[slotName] || []);
3073
- ArrayPush$1.call(vnodes, vnode);
3074
- }
3075
- if (isFalse(vm.isDirty)) {
3076
- // We need to determine if the old allocation is really different from the new one
3077
- // and mark the vm as dirty
3078
- const oldKeys = keys(oldSlots);
3079
- if (oldKeys.length !== keys(cmpSlots).length) {
3080
- markComponentAsDirty(vm);
3081
- return;
3082
- }
3083
- for (let i = 0, len = oldKeys.length; i < len; i += 1) {
3084
- const key = oldKeys[i];
3085
- if (isUndefined$1(cmpSlots[key]) || oldSlots[key].length !== cmpSlots[key].length) {
3086
- markComponentAsDirty(vm);
3087
- return;
3088
- }
3089
- const oldVNodes = oldSlots[key];
3090
- const vnodes = cmpSlots[key];
3091
- for (let j = 0, a = cmpSlots[key].length; j < a; j += 1) {
3092
- if (oldVNodes[j] !== vnodes[j]) {
3093
- markComponentAsDirty(vm);
3094
- return;
3095
- }
3096
- }
3298
+
3299
+ for (let i = 0, len = oldKeys.length; i < len; i += 1) {
3300
+ const key = oldKeys[i];
3301
+
3302
+ if (isUndefined$1(cmpSlots[key]) || oldSlots[key].length !== cmpSlots[key].length) {
3303
+ markComponentAsDirty(vm);
3304
+ return;
3305
+ }
3306
+
3307
+ const oldVNodes = oldSlots[key];
3308
+ const vnodes = cmpSlots[key];
3309
+
3310
+ for (let j = 0, a = cmpSlots[key].length; j < a; j += 1) {
3311
+ if (oldVNodes[j] !== vnodes[j]) {
3312
+ markComponentAsDirty(vm);
3313
+ return;
3097
3314
  }
3315
+ }
3098
3316
  }
3099
- }
3100
- // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
3101
- const FromIteration = new WeakMap();
3102
- // dynamic children means it was generated by an iteration
3317
+ }
3318
+ } // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
3319
+
3320
+
3321
+ const FromIteration = new WeakMap(); // dynamic children means it was generated by an iteration
3103
3322
  // in a template, and will require a more complex diffing algo.
3323
+
3104
3324
  function markAsDynamicChildren(children) {
3105
- FromIteration.set(children, 1);
3325
+ FromIteration.set(children, 1);
3106
3326
  }
3327
+
3107
3328
  function hasDynamicChildren(children) {
3108
- return FromIteration.has(children);
3329
+ return FromIteration.has(children);
3109
3330
  }
3331
+
3110
3332
  function createKeyToOldIdx(children, beginIdx, endIdx) {
3111
- const map = {};
3112
- // TODO [#1637]: simplify this by assuming that all vnodes has keys
3113
- for (let j = beginIdx; j <= endIdx; ++j) {
3114
- const ch = children[j];
3115
- if (isVNode(ch)) {
3116
- const { key } = ch;
3117
- if (key !== undefined) {
3118
- map[key] = j;
3119
- }
3120
- }
3333
+ const map = {}; // TODO [#1637]: simplify this by assuming that all vnodes has keys
3334
+
3335
+ for (let j = beginIdx; j <= endIdx; ++j) {
3336
+ const ch = children[j];
3337
+
3338
+ if (isVNode(ch)) {
3339
+ const {
3340
+ key
3341
+ } = ch;
3342
+
3343
+ if (key !== undefined) {
3344
+ map[key] = j;
3345
+ }
3121
3346
  }
3122
- return map;
3347
+ }
3348
+
3349
+ return map;
3123
3350
  }
3351
+
3124
3352
  function updateDynamicChildren(oldCh, newCh, parent, renderer) {
3125
- let oldStartIdx = 0;
3126
- let newStartIdx = 0;
3127
- let oldEndIdx = oldCh.length - 1;
3128
- let oldStartVnode = oldCh[0];
3129
- let oldEndVnode = oldCh[oldEndIdx];
3130
- const newChEnd = newCh.length - 1;
3131
- let newEndIdx = newChEnd;
3132
- let newStartVnode = newCh[0];
3133
- let newEndVnode = newCh[newEndIdx];
3134
- let oldKeyToIdx;
3135
- let idxInOld;
3136
- let elmToMove;
3137
- let before;
3138
- let clonedOldCh = false;
3139
- while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
3140
- if (!isVNode(oldStartVnode)) {
3141
- oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left
3142
- }
3143
- else if (!isVNode(oldEndVnode)) {
3144
- oldEndVnode = oldCh[--oldEndIdx];
3145
- }
3146
- else if (!isVNode(newStartVnode)) {
3147
- newStartVnode = newCh[++newStartIdx];
3148
- }
3149
- else if (!isVNode(newEndVnode)) {
3150
- newEndVnode = newCh[--newEndIdx];
3151
- }
3152
- else if (isSameVnode(oldStartVnode, newStartVnode)) {
3153
- patch(oldStartVnode, newStartVnode, parent, renderer);
3154
- oldStartVnode = oldCh[++oldStartIdx];
3155
- newStartVnode = newCh[++newStartIdx];
3156
- }
3157
- else if (isSameVnode(oldEndVnode, newEndVnode)) {
3158
- patch(oldEndVnode, newEndVnode, parent, renderer);
3159
- oldEndVnode = oldCh[--oldEndIdx];
3160
- newEndVnode = newCh[--newEndIdx];
3161
- }
3162
- else if (isSameVnode(oldStartVnode, newEndVnode)) {
3163
- // Vnode moved right
3164
- patch(oldStartVnode, newEndVnode, parent, renderer);
3165
- insertNode(oldStartVnode.elm, parent, renderer.nextSibling(oldEndVnode.elm), renderer);
3166
- oldStartVnode = oldCh[++oldStartIdx];
3167
- newEndVnode = newCh[--newEndIdx];
3168
- }
3169
- else if (isSameVnode(oldEndVnode, newStartVnode)) {
3170
- // Vnode moved left
3171
- patch(oldEndVnode, newStartVnode, parent, renderer);
3172
- insertNode(newStartVnode.elm, parent, oldStartVnode.elm, renderer);
3173
- oldEndVnode = oldCh[--oldEndIdx];
3174
- newStartVnode = newCh[++newStartIdx];
3175
- }
3176
- else {
3177
- if (oldKeyToIdx === undefined) {
3178
- oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
3179
- }
3180
- idxInOld = oldKeyToIdx[newStartVnode.key];
3181
- if (isUndefined$1(idxInOld)) {
3182
- // New element
3183
- mount(newStartVnode, parent, renderer, oldStartVnode.elm);
3184
- newStartVnode = newCh[++newStartIdx];
3185
- }
3186
- else {
3187
- elmToMove = oldCh[idxInOld];
3188
- if (isVNode(elmToMove)) {
3189
- if (elmToMove.sel !== newStartVnode.sel) {
3190
- // New element
3191
- mount(newStartVnode, parent, renderer, oldStartVnode.elm);
3192
- }
3193
- else {
3194
- patch(elmToMove, newStartVnode, parent, renderer);
3195
- // Delete the old child, but copy the array since it is read-only.
3196
- // The `oldCh` will be GC'ed after `updateDynamicChildren` is complete,
3197
- // so we only care about the `oldCh` object inside this function.
3198
- // To avoid cloning over and over again, we check `clonedOldCh`
3199
- // and only clone once.
3200
- if (!clonedOldCh) {
3201
- clonedOldCh = true;
3202
- oldCh = [...oldCh];
3203
- }
3204
- // We've already cloned at least once, so it's no longer read-only
3205
- oldCh[idxInOld] = undefined;
3206
- insertNode(elmToMove.elm, parent, oldStartVnode.elm, renderer);
3207
- }
3208
- }
3209
- newStartVnode = newCh[++newStartIdx];
3210
- }
3353
+ let oldStartIdx = 0;
3354
+ let newStartIdx = 0;
3355
+ let oldEndIdx = oldCh.length - 1;
3356
+ let oldStartVnode = oldCh[0];
3357
+ let oldEndVnode = oldCh[oldEndIdx];
3358
+ const newChEnd = newCh.length - 1;
3359
+ let newEndIdx = newChEnd;
3360
+ let newStartVnode = newCh[0];
3361
+ let newEndVnode = newCh[newEndIdx];
3362
+ let oldKeyToIdx;
3363
+ let idxInOld;
3364
+ let elmToMove;
3365
+ let before;
3366
+ let clonedOldCh = false;
3367
+
3368
+ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
3369
+ if (!isVNode(oldStartVnode)) {
3370
+ oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left
3371
+ } else if (!isVNode(oldEndVnode)) {
3372
+ oldEndVnode = oldCh[--oldEndIdx];
3373
+ } else if (!isVNode(newStartVnode)) {
3374
+ newStartVnode = newCh[++newStartIdx];
3375
+ } else if (!isVNode(newEndVnode)) {
3376
+ newEndVnode = newCh[--newEndIdx];
3377
+ } else if (isSameVnode(oldStartVnode, newStartVnode)) {
3378
+ patch(oldStartVnode, newStartVnode, parent, renderer);
3379
+ oldStartVnode = oldCh[++oldStartIdx];
3380
+ newStartVnode = newCh[++newStartIdx];
3381
+ } else if (isSameVnode(oldEndVnode, newEndVnode)) {
3382
+ patch(oldEndVnode, newEndVnode, parent, renderer);
3383
+ oldEndVnode = oldCh[--oldEndIdx];
3384
+ newEndVnode = newCh[--newEndIdx];
3385
+ } else if (isSameVnode(oldStartVnode, newEndVnode)) {
3386
+ // Vnode moved right
3387
+ patch(oldStartVnode, newEndVnode, parent, renderer);
3388
+ insertNode(oldStartVnode.elm, parent, renderer.nextSibling(oldEndVnode.elm), renderer);
3389
+ oldStartVnode = oldCh[++oldStartIdx];
3390
+ newEndVnode = newCh[--newEndIdx];
3391
+ } else if (isSameVnode(oldEndVnode, newStartVnode)) {
3392
+ // Vnode moved left
3393
+ patch(oldEndVnode, newStartVnode, parent, renderer);
3394
+ insertNode(newStartVnode.elm, parent, oldStartVnode.elm, renderer);
3395
+ oldEndVnode = oldCh[--oldEndIdx];
3396
+ newStartVnode = newCh[++newStartIdx];
3397
+ } else {
3398
+ if (oldKeyToIdx === undefined) {
3399
+ oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
3400
+ }
3401
+
3402
+ idxInOld = oldKeyToIdx[newStartVnode.key];
3403
+
3404
+ if (isUndefined$1(idxInOld)) {
3405
+ // New element
3406
+ mount(newStartVnode, parent, renderer, oldStartVnode.elm);
3407
+ newStartVnode = newCh[++newStartIdx];
3408
+ } else {
3409
+ elmToMove = oldCh[idxInOld];
3410
+
3411
+ if (isVNode(elmToMove)) {
3412
+ if (elmToMove.sel !== newStartVnode.sel) {
3413
+ // New element
3414
+ mount(newStartVnode, parent, renderer, oldStartVnode.elm);
3415
+ } else {
3416
+ patch(elmToMove, newStartVnode, parent, renderer); // Delete the old child, but copy the array since it is read-only.
3417
+ // The `oldCh` will be GC'ed after `updateDynamicChildren` is complete,
3418
+ // so we only care about the `oldCh` object inside this function.
3419
+ // To avoid cloning over and over again, we check `clonedOldCh`
3420
+ // and only clone once.
3421
+
3422
+ if (!clonedOldCh) {
3423
+ clonedOldCh = true;
3424
+ oldCh = [...oldCh];
3425
+ } // We've already cloned at least once, so it's no longer read-only
3426
+
3427
+
3428
+ oldCh[idxInOld] = undefined;
3429
+ insertNode(elmToMove.elm, parent, oldStartVnode.elm, renderer);
3430
+ }
3211
3431
  }
3432
+
3433
+ newStartVnode = newCh[++newStartIdx];
3434
+ }
3212
3435
  }
3213
- if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
3214
- if (oldStartIdx > oldEndIdx) {
3215
- // There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
3216
- // already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
3217
- let i = newEndIdx;
3218
- let n;
3219
- do {
3220
- n = newCh[++i];
3221
- } while (!isVNode(n) && i < newChEnd);
3222
- before = isVNode(n) ? n.elm : null;
3223
- mountVNodes(newCh, parent, renderer, before, newStartIdx, newEndIdx + 1);
3224
- }
3225
- else {
3226
- unmountVNodes(oldCh, parent, renderer, true, oldStartIdx, oldEndIdx + 1);
3227
- }
3436
+ }
3437
+
3438
+ if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
3439
+ if (oldStartIdx > oldEndIdx) {
3440
+ // There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
3441
+ // already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
3442
+ let i = newEndIdx;
3443
+ let n;
3444
+
3445
+ do {
3446
+ n = newCh[++i];
3447
+ } while (!isVNode(n) && i < newChEnd);
3448
+
3449
+ before = isVNode(n) ? n.elm : null;
3450
+ mountVNodes(newCh, parent, renderer, before, newStartIdx, newEndIdx + 1);
3451
+ } else {
3452
+ unmountVNodes(oldCh, parent, renderer, true, oldStartIdx, oldEndIdx + 1);
3228
3453
  }
3454
+ }
3229
3455
  }
3456
+
3230
3457
  function updateStaticChildren(c1, c2, parent, renderer) {
3231
- const c1Length = c1.length;
3232
- const c2Length = c2.length;
3233
- if (c1Length === 0) {
3234
- // the old list is empty, we can directly insert anything new
3235
- mountVNodes(c2, parent, renderer, null);
3236
- return;
3237
- }
3238
- if (c2Length === 0) {
3239
- // the old list is nonempty and the new list is empty so we can directly remove all old nodes
3240
- // this is the case in which the dynamic children of an if-directive should be removed
3241
- unmountVNodes(c1, parent, renderer, true);
3242
- return;
3243
- }
3244
- // if the old list is not empty, the new list MUST have the same
3245
- // amount of nodes, that's why we call this static children
3246
- let anchor = null;
3247
- for (let i = c2Length - 1; i >= 0; i -= 1) {
3248
- const n1 = c1[i];
3249
- const n2 = c2[i];
3250
- if (n2 !== n1) {
3251
- if (isVNode(n1)) {
3252
- if (isVNode(n2)) {
3253
- // both vnodes are equivalent, and we just need to patch them
3254
- patch(n1, n2, parent, renderer);
3255
- anchor = n2.elm;
3256
- }
3257
- else {
3258
- // removing the old vnode since the new one is null
3259
- unmount(n1, parent, renderer, true);
3260
- }
3261
- }
3262
- else if (isVNode(n2)) {
3263
- mount(n2, parent, renderer, anchor);
3264
- anchor = n2.elm;
3265
- }
3458
+ const c1Length = c1.length;
3459
+ const c2Length = c2.length;
3460
+
3461
+ if (c1Length === 0) {
3462
+ // the old list is empty, we can directly insert anything new
3463
+ mountVNodes(c2, parent, renderer, null);
3464
+ return;
3465
+ }
3466
+
3467
+ if (c2Length === 0) {
3468
+ // the old list is nonempty and the new list is empty so we can directly remove all old nodes
3469
+ // this is the case in which the dynamic children of an if-directive should be removed
3470
+ unmountVNodes(c1, parent, renderer, true);
3471
+ return;
3472
+ } // if the old list is not empty, the new list MUST have the same
3473
+ // amount of nodes, that's why we call this static children
3474
+
3475
+
3476
+ let anchor = null;
3477
+
3478
+ for (let i = c2Length - 1; i >= 0; i -= 1) {
3479
+ const n1 = c1[i];
3480
+ const n2 = c2[i];
3481
+
3482
+ if (n2 !== n1) {
3483
+ if (isVNode(n1)) {
3484
+ if (isVNode(n2)) {
3485
+ // both vnodes are equivalent, and we just need to patch them
3486
+ patch(n1, n2, parent, renderer);
3487
+ anchor = n2.elm;
3488
+ } else {
3489
+ // removing the old vnode since the new one is null
3490
+ unmount(n1, parent, renderer, true);
3266
3491
  }
3492
+ } else if (isVNode(n2)) {
3493
+ mount(n2, parent, renderer, anchor);
3494
+ anchor = n2.elm;
3495
+ }
3267
3496
  }
3497
+ }
3268
3498
  }
3269
3499
 
3270
3500
  /*
@@ -4899,6 +5129,7 @@ var LWC = (function (exports) {
4899
5129
  }
4900
5130
  return renderer.nextSibling(hydratedNode);
4901
5131
  }
5132
+ const NODE_VALUE_PROP = 'nodeValue';
4902
5133
  function hydrateText(node, vnode, renderer) {
4903
5134
  var _a;
4904
5135
  if (!hasCorrectNodeType(vnode, node, 3 /* EnvNodeTypes.TEXT */, renderer)) {
@@ -4915,7 +5146,7 @@ var LWC = (function (exports) {
4915
5146
  return handleMismatch(node, vnode, renderer);
4916
5147
  }
4917
5148
  const { setProperty } = renderer;
4918
- setProperty(node, 'nodeValue', (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
5149
+ setProperty(node, NODE_VALUE_PROP, (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
4919
5150
  vnode.elm = node;
4920
5151
  return node;
4921
5152
  }
@@ -5136,13 +5367,13 @@ var LWC = (function (exports) {
5136
5367
  if (!hasCorrectNodeType(vnode, ssr, 3 /* EnvNodeTypes.TEXT */, renderer)) {
5137
5368
  return false;
5138
5369
  }
5139
- return getProperty(client, 'nodeValue') === getProperty(ssr, 'nodeValue');
5370
+ return getProperty(client, NODE_VALUE_PROP) === getProperty(ssr, NODE_VALUE_PROP);
5140
5371
  }
5141
5372
  if (getProperty(client, 'nodeType') === 8 /* EnvNodeTypes.COMMENT */) {
5142
5373
  if (!hasCorrectNodeType(vnode, ssr, 8 /* EnvNodeTypes.COMMENT */, renderer)) {
5143
5374
  return false;
5144
5375
  }
5145
- return getProperty(client, 'nodeValue') === getProperty(ssr, 'nodeValue');
5376
+ return getProperty(client, NODE_VALUE_PROP) === getProperty(ssr, NODE_VALUE_PROP);
5146
5377
  }
5147
5378
  if (!hasCorrectNodeType(vnode, ssr, 1 /* EnvNodeTypes.ELEMENT */, renderer)) {
5148
5379
  return false;
@@ -5200,7 +5431,7 @@ var LWC = (function (exports) {
5200
5431
  }
5201
5432
  return ctor;
5202
5433
  }
5203
- /* version: 2.23.1 */
5434
+ /* version: 2.23.2 */
5204
5435
 
5205
5436
  /*
5206
5437
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5341,61 +5572,303 @@ var LWC = (function (exports) {
5341
5572
  * SPDX-License-Identifier: MIT
5342
5573
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5343
5574
  */
5344
- const SUPPORTS_TEMPLATE = typeof HTMLTemplateElement === 'function';
5345
- let createFragment;
5346
- if (SUPPORTS_TEMPLATE) {
5347
- // Parse the fragment HTML string into DOM
5348
- createFragment = function (html) {
5349
- const template = document.createElement('template');
5350
- template.innerHTML = html;
5351
- return template.content.firstChild;
5352
- };
5353
- }
5354
- else {
5355
- // In browsers that don't support <template> (e.g. IE11), we need to be careful to wrap elements like
5356
- // <td> in the proper container elements (e.g. <tbody>), because otherwise they will be parsed as null.
5357
- // Via https://github.com/webcomponents/polyfills/blob/ee1db33/packages/template/template.js#L273-L280
5358
- // With other elements added from:
5359
- // https://github.com/sindresorhus/html-tags/blob/95dcdd5/index.js
5360
- // Using the test:
5361
- // document.createRange().createContextualFragment(`<${tag}></${tag}>`).firstChild === null
5362
- // And omitting <html>, <head>, and <body> as these are not practical in an LWC component.
5363
- const topLevelWrappingMap = {
5364
- caption: ['table'],
5365
- col: ['colgroup', 'table'],
5366
- colgroup: ['table'],
5367
- option: ['select'],
5368
- tbody: ['table'],
5369
- td: ['tr', 'tbody', 'table'],
5370
- th: ['tr', 'tbody', 'table'],
5371
- thead: ['table'],
5372
- tfoot: ['table'],
5373
- tr: ['tbody', 'table'],
5374
- };
5375
- // Via https://github.com/webcomponents/polyfills/blob/ee1db33/packages/template/template.js#L282-L288
5376
- const getTagName = function (text) {
5377
- return (/<([a-z][^/\0>\x20\t\r\n\f]+)/i.exec(text) || ['', ''])[1].toLowerCase();
5378
- };
5379
- // Via https://github.com/webcomponents/polyfills/blob/ee1db33/packages/template/template.js#L295-L320
5380
- createFragment = function (html) {
5381
- const wrapperTags = topLevelWrappingMap[getTagName(html)];
5382
- if (!isUndefined$1(wrapperTags)) {
5383
- for (const wrapperTag of wrapperTags) {
5384
- html = `<${wrapperTag}>${html}</${wrapperTag}>`;
5575
+ /**
5576
+ * A factory function that produces a renderer.
5577
+ * Renderer encapsulates operations that are required to render an LWC component into the underlying
5578
+ * runtime environment. In the case of @lwc/enigne-dom, it is meant to be used in a DOM environment.
5579
+ * Example usage:
5580
+ * import { renderer, rendererFactory } from 'lwc';
5581
+ * const customRenderer = rendererFactory(renderer);
5582
+ *
5583
+ * @param baseRenderer Either null or the base renderer imported from 'lwc'.
5584
+ */
5585
+ function rendererFactory(baseRenderer) {
5586
+ // Util functions
5587
+ function assertInvariant(value, msg) {
5588
+ if (!value) {
5589
+ throw new Error(`Invariant Violation: ${msg}`);
5590
+ }
5591
+ }
5592
+ function isNull(obj) {
5593
+ return obj === null;
5594
+ }
5595
+ function isUndefined(obj) {
5596
+ return obj === undefined;
5597
+ }
5598
+ let getCustomElement;
5599
+ let defineCustomElement;
5600
+ let HTMLElementConstructor;
5601
+ function isCustomElementRegistryAvailable() {
5602
+ if (typeof customElements === 'undefined') {
5603
+ return false;
5604
+ }
5605
+ try {
5606
+ // dereference HTMLElement global because babel wraps globals in compat mode with a
5607
+ // _wrapNativeSuper()
5608
+ // This is a problem because LWCUpgradableElement extends renderer.HTMLElementExported which does not
5609
+ // get wrapped by babel.
5610
+ const HTMLElementAlias = HTMLElement;
5611
+ // In case we use compat mode with a modern browser, the compat mode transformation
5612
+ // invokes the DOM api with an .apply() or .call() to initialize any DOM api sub-classing,
5613
+ // which are not equipped to be initialized that way.
5614
+ class clazz extends HTMLElementAlias {
5385
5615
  }
5616
+ customElements.define('lwc-test-' + Math.floor(Math.random() * 1000000), clazz);
5617
+ new clazz();
5618
+ return true;
5619
+ }
5620
+ catch (_a) {
5621
+ return false;
5386
5622
  }
5387
- // For IE11, the document title must not be undefined, but it can be an empty string
5388
- // https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createHTMLDocument#browser_compatibility
5389
- const doc = document.implementation.createHTMLDocument('');
5390
- doc.body.innerHTML = html;
5391
- let content = doc.body;
5392
- if (!isUndefined$1(wrapperTags)) {
5393
- for (let i = 0; i < wrapperTags.length; i++) {
5394
- content = content.firstChild;
5623
+ }
5624
+ if (isCustomElementRegistryAvailable()) {
5625
+ getCustomElement = customElements.get.bind(customElements);
5626
+ defineCustomElement = customElements.define.bind(customElements);
5627
+ HTMLElementConstructor = HTMLElement;
5628
+ }
5629
+ else {
5630
+ const registry = Object.create(null);
5631
+ const reverseRegistry = new WeakMap();
5632
+ defineCustomElement = function define(name, ctor) {
5633
+ if (name !== String.prototype.toLowerCase.call(name) || registry[name]) {
5634
+ throw new TypeError(`Invalid Registration`);
5395
5635
  }
5636
+ registry[name] = ctor;
5637
+ reverseRegistry.set(ctor, name);
5638
+ };
5639
+ getCustomElement = function get(name) {
5640
+ return registry[name];
5641
+ };
5642
+ HTMLElementConstructor = function HTMLElement() {
5643
+ if (!(this instanceof HTMLElement)) {
5644
+ throw new TypeError(`Invalid Invocation`);
5645
+ }
5646
+ const { constructor } = this;
5647
+ const name = reverseRegistry.get(constructor);
5648
+ if (!name) {
5649
+ throw new TypeError(`Invalid Construction`);
5650
+ }
5651
+ const elm = document.createElement(name);
5652
+ Object.setPrototypeOf(elm, constructor.prototype);
5653
+ return elm;
5654
+ };
5655
+ HTMLElementConstructor.prototype = HTMLElement.prototype;
5656
+ }
5657
+ function cloneNode(node, deep) {
5658
+ return node.cloneNode(deep);
5659
+ }
5660
+ function createElement(tagName, namespace) {
5661
+ return isUndefined(namespace)
5662
+ ? document.createElement(tagName)
5663
+ : document.createElementNS(namespace, tagName);
5664
+ }
5665
+ function createText(content) {
5666
+ return document.createTextNode(content);
5667
+ }
5668
+ function createComment(content) {
5669
+ return document.createComment(content);
5670
+ }
5671
+ let createFragment;
5672
+ // IE11 lacks support for this feature
5673
+ const SUPPORTS_TEMPLATE = typeof HTMLTemplateElement === 'function';
5674
+ if (SUPPORTS_TEMPLATE) {
5675
+ // Parse the fragment HTML string into DOM
5676
+ createFragment = function (html) {
5677
+ const template = document.createElement('template');
5678
+ template.innerHTML = html;
5679
+ return template.content.firstChild;
5680
+ };
5681
+ }
5682
+ else {
5683
+ // In browsers that don't support <template> (e.g. IE11), we need to be careful to wrap elements like
5684
+ // <td> in the proper container elements (e.g. <tbody>), because otherwise they will be parsed as null.
5685
+ // Via https://github.com/webcomponents/polyfills/blob/ee1db33/packages/template/template.js#L273-L280
5686
+ // With other elements added from:
5687
+ // https://github.com/sindresorhus/html-tags/blob/95dcdd5/index.js
5688
+ // Using the test:
5689
+ // document.createRange().createContextualFragment(`<${tag}></${tag}>`).firstChild === null
5690
+ // And omitting <html>, <head>, and <body> as these are not practical in an LWC component.
5691
+ const topLevelWrappingMap = {
5692
+ caption: ['table'],
5693
+ col: ['colgroup', 'table'],
5694
+ colgroup: ['table'],
5695
+ option: ['select'],
5696
+ tbody: ['table'],
5697
+ td: ['tr', 'tbody', 'table'],
5698
+ th: ['tr', 'tbody', 'table'],
5699
+ thead: ['table'],
5700
+ tfoot: ['table'],
5701
+ tr: ['tbody', 'table'],
5702
+ };
5703
+ // Via https://github.com/webcomponents/polyfills/blob/ee1db33/packages/template/template.js#L282-L288
5704
+ const getTagName = function (text) {
5705
+ return (/<([a-z][^/\0>\x20\t\r\n\f]+)/i.exec(text) || ['', ''])[1].toLowerCase();
5706
+ };
5707
+ // Via https://github.com/webcomponents/polyfills/blob/ee1db33/packages/template/template.js#L295-L320
5708
+ createFragment = function (html) {
5709
+ const wrapperTags = topLevelWrappingMap[getTagName(html)];
5710
+ if (!isUndefined(wrapperTags)) {
5711
+ for (const wrapperTag of wrapperTags) {
5712
+ html = `<${wrapperTag}>${html}</${wrapperTag}>`;
5713
+ }
5714
+ }
5715
+ // For IE11, the document title must not be undefined, but it can be an empty string
5716
+ // https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createHTMLDocument#browser_compatibility
5717
+ const doc = document.implementation.createHTMLDocument('');
5718
+ doc.body.innerHTML = html;
5719
+ let content = doc.body;
5720
+ if (!isUndefined(wrapperTags)) {
5721
+ for (let i = 0; i < wrapperTags.length; i++) {
5722
+ content = content.firstChild;
5723
+ }
5724
+ }
5725
+ return content.firstChild;
5726
+ };
5727
+ }
5728
+ function insert(node, parent, anchor) {
5729
+ parent.insertBefore(node, anchor);
5730
+ }
5731
+ function remove(node, parent) {
5732
+ parent.removeChild(node);
5733
+ }
5734
+ function nextSibling(node) {
5735
+ return node.nextSibling;
5736
+ }
5737
+ function attachShadow(element, options) {
5738
+ // `shadowRoot` will be non-null in two cases:
5739
+ // 1. upon initial load with an SSR-generated DOM, while in Shadow render mode
5740
+ // 2. when a webapp author places <c-app> in their static HTML and mounts their
5741
+ // root component with customElement.define('c-app', Ctor)
5742
+ if (!isNull(element.shadowRoot)) {
5743
+ return element.shadowRoot;
5744
+ }
5745
+ return element.attachShadow(options);
5746
+ }
5747
+ function setText(node, content) {
5748
+ node.nodeValue = content;
5749
+ }
5750
+ function getProperty(node, key) {
5751
+ return node[key];
5752
+ }
5753
+ function setProperty(node, key, value) {
5754
+ node[key] = value;
5755
+ }
5756
+ function getAttribute(element, name, namespace) {
5757
+ return isUndefined(namespace)
5758
+ ? element.getAttribute(name)
5759
+ : element.getAttributeNS(namespace, name);
5760
+ }
5761
+ function setAttribute(element, name, value, namespace) {
5762
+ return isUndefined(namespace)
5763
+ ? element.setAttribute(name, value)
5764
+ : element.setAttributeNS(namespace, name, value);
5765
+ }
5766
+ function removeAttribute(element, name, namespace) {
5767
+ if (isUndefined(namespace)) {
5768
+ element.removeAttribute(name);
5396
5769
  }
5397
- return content.firstChild;
5770
+ else {
5771
+ element.removeAttributeNS(namespace, name);
5772
+ }
5773
+ }
5774
+ function addEventListener(target, type, callback, options) {
5775
+ target.addEventListener(type, callback, options);
5776
+ }
5777
+ function removeEventListener(target, type, callback, options) {
5778
+ target.removeEventListener(type, callback, options);
5779
+ }
5780
+ function dispatchEvent(target, event) {
5781
+ return target.dispatchEvent(event);
5782
+ }
5783
+ function getClassList(element) {
5784
+ return element.classList;
5785
+ }
5786
+ function setCSSStyleProperty(element, name, value, important) {
5787
+ // TODO [#0]: How to avoid this type casting? Shall we use a different type interface to
5788
+ // represent elements in the engine?
5789
+ element.style.setProperty(name, value, important ? 'important' : '');
5790
+ }
5791
+ function getBoundingClientRect(element) {
5792
+ return element.getBoundingClientRect();
5793
+ }
5794
+ function querySelector(element, selectors) {
5795
+ return element.querySelector(selectors);
5796
+ }
5797
+ function querySelectorAll(element, selectors) {
5798
+ return element.querySelectorAll(selectors);
5799
+ }
5800
+ function getElementsByTagName(element, tagNameOrWildCard) {
5801
+ return element.getElementsByTagName(tagNameOrWildCard);
5802
+ }
5803
+ function getElementsByClassName(element, names) {
5804
+ return element.getElementsByClassName(names);
5805
+ }
5806
+ function getChildren(element) {
5807
+ return element.children;
5808
+ }
5809
+ function getChildNodes(element) {
5810
+ return element.childNodes;
5811
+ }
5812
+ function getFirstChild(element) {
5813
+ return element.firstChild;
5814
+ }
5815
+ function getFirstElementChild(element) {
5816
+ return element.firstElementChild;
5817
+ }
5818
+ function getLastChild(element) {
5819
+ return element.lastChild;
5820
+ }
5821
+ function getLastElementChild(element) {
5822
+ return element.lastElementChild;
5823
+ }
5824
+ function isConnected(node) {
5825
+ return node.isConnected;
5826
+ }
5827
+ function assertInstanceOfHTMLElement(elm, msg) {
5828
+ assertInvariant(elm instanceof HTMLElement, msg);
5829
+ }
5830
+ const HTMLElementExported = HTMLElementConstructor;
5831
+ const renderer = {
5832
+ HTMLElementExported,
5833
+ insert,
5834
+ remove,
5835
+ cloneNode,
5836
+ createFragment,
5837
+ createElement,
5838
+ createText,
5839
+ createComment,
5840
+ nextSibling,
5841
+ attachShadow,
5842
+ getProperty,
5843
+ setProperty,
5844
+ setText,
5845
+ getAttribute,
5846
+ setAttribute,
5847
+ removeAttribute,
5848
+ addEventListener,
5849
+ removeEventListener,
5850
+ dispatchEvent,
5851
+ getClassList,
5852
+ setCSSStyleProperty,
5853
+ getBoundingClientRect,
5854
+ querySelector,
5855
+ querySelectorAll,
5856
+ getElementsByTagName,
5857
+ getElementsByClassName,
5858
+ getChildren,
5859
+ getChildNodes,
5860
+ getFirstChild,
5861
+ getFirstElementChild,
5862
+ getLastChild,
5863
+ getLastElementChild,
5864
+ isConnected,
5865
+ assertInstanceOfHTMLElement,
5866
+ defineCustomElement,
5867
+ getCustomElement,
5398
5868
  };
5869
+ // Meant to inherit any properties passed via the base renderer as the argument to the factory.
5870
+ Object.setPrototypeOf(renderer, baseRenderer);
5871
+ return renderer;
5399
5872
  }
5400
5873
 
5401
5874
  /*
@@ -5404,225 +5877,21 @@ var LWC = (function (exports) {
5404
5877
  * SPDX-License-Identifier: MIT
5405
5878
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5406
5879
  */
5407
- let getCustomElement;
5408
- let defineCustomElement;
5409
- let HTMLElementConstructor;
5410
- function isCustomElementRegistryAvailable() {
5411
- if (typeof customElements === 'undefined') {
5412
- return false;
5413
- }
5414
- try {
5415
- // dereference HTMLElement global because babel wraps globals in compat mode with a
5416
- // _wrapNativeSuper()
5417
- // This is a problem because LWCUpgradableElement extends renderer.HTMLElementExported which does not
5418
- // get wrapped by babel.
5419
- const HTMLElementAlias = HTMLElement;
5420
- // In case we use compat mode with a modern browser, the compat mode transformation
5421
- // invokes the DOM api with an .apply() or .call() to initialize any DOM api sub-classing,
5422
- // which are not equipped to be initialized that way.
5423
- class clazz extends HTMLElementAlias {
5424
- }
5425
- customElements.define('lwc-test-' + Math.floor(Math.random() * 1000000), clazz);
5426
- new clazz();
5427
- return true;
5428
- }
5429
- catch (_a) {
5430
- return false;
5431
- }
5432
- }
5433
- if (isCustomElementRegistryAvailable()) {
5434
- getCustomElement = customElements.get.bind(customElements);
5435
- defineCustomElement = customElements.define.bind(customElements);
5436
- HTMLElementConstructor = HTMLElement;
5437
- }
5438
- else {
5439
- const registry = create(null);
5440
- const reverseRegistry = new WeakMap();
5441
- defineCustomElement = function define(name, ctor) {
5442
- if (name !== StringToLowerCase.call(name) || registry[name]) {
5443
- throw new TypeError(`Invalid Registration`);
5444
- }
5445
- registry[name] = ctor;
5446
- reverseRegistry.set(ctor, name);
5447
- };
5448
- getCustomElement = function get(name) {
5449
- return registry[name];
5450
- };
5451
- HTMLElementConstructor = function HTMLElement() {
5452
- if (!(this instanceof HTMLElement)) {
5453
- throw new TypeError(`Invalid Invocation`);
5454
- }
5455
- const { constructor } = this;
5456
- const name = reverseRegistry.get(constructor);
5457
- if (!name) {
5458
- throw new TypeError(`Invalid Construction`);
5459
- }
5460
- const elm = document.createElement(name);
5461
- setPrototypeOf(elm, constructor.prototype);
5462
- return elm;
5463
- };
5464
- HTMLElementConstructor.prototype = HTMLElement.prototype;
5465
- }
5466
- const isNativeShadowDefined = _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED];
5467
- const isSyntheticShadowDefined = hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN);
5468
- function cloneNode(node, deep) {
5469
- return node.cloneNode(deep);
5470
- }
5471
- function createElement$1(tagName, namespace) {
5472
- return isUndefined$1(namespace)
5473
- ? document.createElement(tagName)
5474
- : document.createElementNS(namespace, tagName);
5475
- }
5476
- function createText(content) {
5477
- return document.createTextNode(content);
5478
- }
5479
- function createComment(content) {
5480
- return document.createComment(content);
5481
- }
5482
- function insert(node, parent, anchor) {
5483
- parent.insertBefore(node, anchor);
5484
- }
5485
- function remove(node, parent) {
5486
- parent.removeChild(node);
5487
- }
5488
- function nextSibling(node) {
5489
- return node.nextSibling;
5490
- }
5491
- function attachShadow(element, options) {
5492
- // `shadowRoot` will be non-null in two cases:
5493
- // 1. upon initial load with an SSR-generated DOM, while in Shadow render mode
5494
- // 2. when a webapp author places <c-app> in their static HTML and mounts their
5495
- // root component with customElement.define('c-app', Ctor)
5496
- if (!isNull(element.shadowRoot)) {
5497
- return element.shadowRoot;
5498
- }
5499
- return element.attachShadow(options);
5500
- }
5501
- function setText(node, content) {
5502
- node.nodeValue = content;
5503
- }
5504
- function getProperty(node, key) {
5505
- return node[key];
5506
- }
5507
- function setProperty(node, key, value) {
5508
- node[key] = value;
5509
- }
5510
- function getAttribute(element, name, namespace) {
5511
- return isUndefined$1(namespace)
5512
- ? element.getAttribute(name)
5513
- : element.getAttributeNS(namespace, name);
5514
- }
5515
- function setAttribute(element, name, value, namespace) {
5516
- return isUndefined$1(namespace)
5517
- ? element.setAttribute(name, value)
5518
- : element.setAttributeNS(namespace, name, value);
5519
- }
5520
- function removeAttribute(element, name, namespace) {
5521
- if (isUndefined$1(namespace)) {
5522
- element.removeAttribute(name);
5523
- }
5524
- else {
5525
- element.removeAttributeNS(namespace, name);
5526
- }
5527
- }
5528
- function addEventListener(target, type, callback, options) {
5529
- target.addEventListener(type, callback, options);
5530
- }
5531
- function removeEventListener(target, type, callback, options) {
5532
- target.removeEventListener(type, callback, options);
5533
- }
5534
- function dispatchEvent(target, event) {
5535
- return target.dispatchEvent(event);
5536
- }
5537
- function getClassList(element) {
5538
- return element.classList;
5539
- }
5540
- function setCSSStyleProperty(element, name, value, important) {
5541
- // TODO [#0]: How to avoid this type casting? Shall we use a different type interface to
5542
- // represent elements in the engine?
5543
- element.style.setProperty(name, value, important ? 'important' : '');
5544
- }
5545
- function getBoundingClientRect(element) {
5546
- return element.getBoundingClientRect();
5547
- }
5548
- function querySelector(element, selectors) {
5549
- return element.querySelector(selectors);
5550
- }
5551
- function querySelectorAll(element, selectors) {
5552
- return element.querySelectorAll(selectors);
5553
- }
5554
- function getElementsByTagName(element, tagNameOrWildCard) {
5555
- return element.getElementsByTagName(tagNameOrWildCard);
5556
- }
5557
- function getElementsByClassName(element, names) {
5558
- return element.getElementsByClassName(names);
5559
- }
5560
- function getChildren(element) {
5561
- return element.children;
5562
- }
5563
- function getChildNodes(element) {
5564
- return element.childNodes;
5565
- }
5566
- function getFirstChild(element) {
5567
- return element.firstChild;
5568
- }
5569
- function getFirstElementChild(element) {
5570
- return element.firstElementChild;
5571
- }
5572
- function getLastChild(element) {
5573
- return element.lastChild;
5574
- }
5575
- function getLastElementChild(element) {
5576
- return element.lastElementChild;
5577
- }
5578
- function isConnected(node) {
5579
- return node.isConnected;
5580
- }
5581
- function assertInstanceOfHTMLElement(elm, msg) {
5582
- assert.invariant(elm instanceof HTMLElement, msg);
5583
- }
5584
- const HTMLElementExported = HTMLElementConstructor;
5585
- const renderer = {
5586
- isNativeShadowDefined,
5587
- isSyntheticShadowDefined,
5588
- HTMLElementExported,
5589
- insert,
5590
- remove,
5591
- cloneNode,
5592
- createFragment,
5593
- createElement: createElement$1,
5594
- createText,
5595
- createComment,
5596
- nextSibling,
5597
- attachShadow,
5598
- getProperty,
5599
- setProperty,
5600
- setText,
5601
- getAttribute,
5602
- setAttribute,
5603
- removeAttribute,
5604
- addEventListener,
5605
- removeEventListener,
5606
- dispatchEvent,
5607
- getClassList,
5608
- setCSSStyleProperty,
5609
- getBoundingClientRect,
5610
- querySelector,
5611
- querySelectorAll,
5612
- getElementsByTagName,
5613
- getElementsByClassName,
5614
- getChildren,
5615
- getChildNodes,
5616
- getFirstChild,
5617
- getFirstElementChild,
5618
- getLastChild,
5619
- getLastElementChild,
5620
- isConnected,
5880
+ /**
5881
+ * The base renderer that will be used by engine-core.
5882
+ * This will be used for DOM operations when lwc is running in a browser environment.
5883
+ */
5884
+ const renderer = assign(
5885
+ // The base renderer will invoke the factory with null and assign additional properties that are
5886
+ // shared across renderers
5887
+ rendererFactory(null),
5888
+ // Properties that are either not required to be sandboxed or rely on a globally shared information
5889
+ {
5890
+ // insertStyleSheet implementation shares a global cache of stylesheet data
5621
5891
  insertStylesheet,
5622
- assertInstanceOfHTMLElement,
5623
- defineCustomElement,
5624
- getCustomElement,
5625
- };
5892
+ isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
5893
+ isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
5894
+ });
5626
5895
 
5627
5896
  /*
5628
5897
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5753,41 +6022,57 @@ var LWC = (function (exports) {
5753
6022
  * SPDX-License-Identifier: MIT
5754
6023
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5755
6024
  */
5756
- // TODO [#2472]: Remove this workaround when appropriate.
5757
6025
  // eslint-disable-next-line @lwc/lwc-internal/no-global-node
6026
+
5758
6027
  const _Node$1 = Node;
5759
6028
  const ConnectingSlot = new WeakMap();
5760
6029
  const DisconnectingSlot = new WeakMap();
6030
+
5761
6031
  function callNodeSlot(node, slot) {
5762
- const fn = slot.get(node);
5763
- if (!isUndefined$1(fn)) {
5764
- fn(node);
5765
- }
5766
- return node; // for convenience
6032
+
6033
+ const fn = slot.get(node);
6034
+
6035
+ if (!isUndefined$1(fn)) {
6036
+ fn(node);
6037
+ }
6038
+
6039
+ return node; // for convenience
5767
6040
  }
5768
- // Monkey patching Node methods to be able to detect the insertions and removal of root elements
5769
- // created via createElement.
5770
- const { appendChild, insertBefore, removeChild, replaceChild } = _Node$1.prototype;
5771
- assign(_Node$1.prototype, {
6041
+
6042
+ if (!lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
6043
+ // Monkey patching Node methods to be able to detect the insertions and removal of root elements
6044
+ // created via createElement.
6045
+ const {
6046
+ appendChild,
6047
+ insertBefore,
6048
+ removeChild,
6049
+ replaceChild
6050
+ } = _Node$1.prototype;
6051
+ assign(_Node$1.prototype, {
5772
6052
  appendChild(newChild) {
5773
- const appendedNode = appendChild.call(this, newChild);
5774
- return callNodeSlot(appendedNode, ConnectingSlot);
6053
+ const appendedNode = appendChild.call(this, newChild);
6054
+ return callNodeSlot(appendedNode, ConnectingSlot);
5775
6055
  },
6056
+
5776
6057
  insertBefore(newChild, referenceNode) {
5777
- const insertedNode = insertBefore.call(this, newChild, referenceNode);
5778
- return callNodeSlot(insertedNode, ConnectingSlot);
6058
+ const insertedNode = insertBefore.call(this, newChild, referenceNode);
6059
+ return callNodeSlot(insertedNode, ConnectingSlot);
5779
6060
  },
6061
+
5780
6062
  removeChild(oldChild) {
5781
- const removedNode = removeChild.call(this, oldChild);
5782
- return callNodeSlot(removedNode, DisconnectingSlot);
6063
+ const removedNode = removeChild.call(this, oldChild);
6064
+ return callNodeSlot(removedNode, DisconnectingSlot);
5783
6065
  },
6066
+
5784
6067
  replaceChild(newChild, oldChild) {
5785
- const replacedNode = replaceChild.call(this, newChild, oldChild);
5786
- callNodeSlot(replacedNode, DisconnectingSlot);
5787
- callNodeSlot(newChild, ConnectingSlot);
5788
- return replacedNode;
5789
- },
5790
- });
6068
+ const replacedNode = replaceChild.call(this, newChild, oldChild);
6069
+ callNodeSlot(replacedNode, DisconnectingSlot);
6070
+ callNodeSlot(newChild, ConnectingSlot);
6071
+ return replacedNode;
6072
+ }
6073
+
6074
+ });
6075
+ }
5791
6076
  /**
5792
6077
  * EXPERIMENTAL: This function is almost identical to document.createElement with the slightly
5793
6078
  * difference that in the options, you can pass the `is` property set to a Constructor instead of
@@ -5799,38 +6084,50 @@ var LWC = (function (exports) {
5799
6084
  * const el = createElement('x-foo', { is: FooCtor });
5800
6085
  * ```
5801
6086
  */
6087
+
6088
+
5802
6089
  function createElement(sel, options) {
5803
- if (!isObject(options) || isNull(options)) {
5804
- throw new TypeError(`"createElement" function expects an object as second parameter but received "${toString$1(options)}".`);
5805
- }
5806
- const Ctor = options.is;
5807
- if (!isFunction$1(Ctor)) {
5808
- throw new TypeError(`"createElement" function expects an "is" option with a valid component constructor.`);
5809
- }
5810
- const UpgradableConstructor = getUpgradableConstructor(sel, renderer);
5811
- let wasComponentUpgraded = false;
5812
- // the custom element from the registry is expecting an upgrade callback
5813
- /**
5814
- * Note: if the upgradable constructor does not expect, or throw when we new it
5815
- * with a callback as the first argument, we could implement a more advanced
5816
- * mechanism that only passes that argument if the constructor is known to be
5817
- * an upgradable custom element.
5818
- */
5819
- const element = new UpgradableConstructor((elm) => {
5820
- createVM(elm, Ctor, renderer, {
5821
- tagName: sel,
5822
- mode: options.mode !== 'closed' ? 'open' : 'closed',
5823
- owner: null,
5824
- });
5825
- ConnectingSlot.set(elm, connectRootElement);
5826
- DisconnectingSlot.set(elm, disconnectRootElement);
5827
- wasComponentUpgraded = true;
6090
+ if (!isObject(options) || isNull(options)) {
6091
+ throw new TypeError(`"createElement" function expects an object as second parameter but received "${toString$1(options)}".`);
6092
+ }
6093
+
6094
+ const Ctor = options.is;
6095
+
6096
+ if (!isFunction$1(Ctor)) {
6097
+ throw new TypeError(`"createElement" function expects an "is" option with a valid component constructor.`);
6098
+ }
6099
+
6100
+ const UpgradableConstructor = getUpgradableConstructor(sel, renderer);
6101
+ let wasComponentUpgraded = false; // the custom element from the registry is expecting an upgrade callback
6102
+
6103
+ /**
6104
+ * Note: if the upgradable constructor does not expect, or throw when we new it
6105
+ * with a callback as the first argument, we could implement a more advanced
6106
+ * mechanism that only passes that argument if the constructor is known to be
6107
+ * an upgradable custom element.
6108
+ */
6109
+
6110
+ const element = new UpgradableConstructor(elm => {
6111
+ createVM(elm, Ctor, renderer, {
6112
+ tagName: sel,
6113
+ mode: options.mode !== 'closed' ? 'open' : 'closed',
6114
+ owner: null
5828
6115
  });
5829
- if (!wasComponentUpgraded) {
5830
- /* eslint-disable-next-line no-console */
5831
- console.error(`Unexpected tag name "${sel}". This name is a registered custom element, preventing LWC to upgrade the element.`);
6116
+
6117
+ if (!lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
6118
+ ConnectingSlot.set(elm, connectRootElement);
6119
+ DisconnectingSlot.set(elm, disconnectRootElement);
5832
6120
  }
5833
- return element;
6121
+
6122
+ wasComponentUpgraded = true;
6123
+ });
6124
+
6125
+ if (!wasComponentUpgraded) {
6126
+ /* eslint-disable-next-line no-console */
6127
+ console.error(`Unexpected tag name "${sel}". This name is a registered custom element, preventing LWC to upgrade the element.`);
6128
+ }
6129
+
6130
+ return element;
5834
6131
  }
5835
6132
 
5836
6133
  /*
@@ -5864,7 +6161,7 @@ var LWC = (function (exports) {
5864
6161
  }
5865
6162
  // TODO [#1252]: Old behavior that is still used by some pieces of the platform. Manually
5866
6163
  // inserted nodes without the `lwc:dom=manual` directive will be considered as global elements.
5867
- return isSyntheticShadowDefined && !isUndefined$1(node[KEY__SHADOW_RESOLVER]);
6164
+ return renderer.isSyntheticShadowDefined && !isUndefined$1(node[KEY__SHADOW_RESOLVER]);
5868
6165
  }
5869
6166
 
5870
6167
  /*
@@ -5901,7 +6198,7 @@ var LWC = (function (exports) {
5901
6198
  });
5902
6199
  freeze(LightningElement);
5903
6200
  seal(LightningElement.prototype);
5904
- /* version: 2.23.1 */
6201
+ /* version: 2.23.2 */
5905
6202
 
5906
6203
  exports.LightningElement = LightningElement;
5907
6204
  exports.__unstable__ProfilerControl = profilerControl;
@@ -5923,6 +6220,7 @@ var LWC = (function (exports) {
5923
6220
  exports.registerDecorators = registerDecorators;
5924
6221
  exports.registerTemplate = registerTemplate;
5925
6222
  exports.renderer = renderer;
6223
+ exports.rendererFactory = rendererFactory;
5926
6224
  exports.sanitizeAttribute = sanitizeAttribute;
5927
6225
  exports.setFeatureFlag = setFeatureFlag;
5928
6226
  exports.setFeatureFlagForTest = setFeatureFlagForTest;