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