@lwc/engine-core 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.
@@ -3089,30 +3089,67 @@ function createStylesheet(vm, stylesheets) {
3089
3089
  * SPDX-License-Identifier: MIT
3090
3090
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3091
3091
  */
3092
+
3093
+ function checkHasVM(elm) {
3094
+ const hasVM = !isUndefined$1(getAssociatedVMIfPresent(elm));
3095
+
3096
+ if (process.env.NODE_ENV !== 'production' && !hasVM) {
3097
+ // Occurs when an element is manually created with the same tag name as an existing LWC component. In that case,
3098
+ // we skip calling the LWC connectedCallback/disconnectedCallback logic and log an error.
3099
+ logError(`VM for tag name "${elm.tagName.toLowerCase()}" is undefined. ` + `This indicates that an element was created with this tag name, ` + `which is already reserved by an LWC component. Use lwc.createElement ` + `instead to create elements.`);
3100
+ }
3101
+
3102
+ return hasVM;
3103
+ }
3104
+
3092
3105
  function getUpgradableConstructor(tagName, renderer) {
3093
- const { getCustomElement, HTMLElementExported: RendererHTMLElement, defineCustomElement, } = renderer;
3094
- // Should never get a tag with upper case letter at this point, the compiler should
3095
- // produce only tags with lowercase letters
3096
- // But, for backwards compatibility, we will lower case the tagName
3097
- tagName = tagName.toLowerCase();
3098
- let CE = getCustomElement(tagName);
3099
- if (!isUndefined$1(CE)) {
3100
- return CE;
3106
+ const {
3107
+ getCustomElement,
3108
+ HTMLElementExported: RendererHTMLElement,
3109
+ defineCustomElement
3110
+ } = renderer; // Should never get a tag with upper case letter at this point, the compiler should
3111
+ // produce only tags with lowercase letters
3112
+ // But, for backwards compatibility, we will lower case the tagName
3113
+
3114
+ tagName = tagName.toLowerCase();
3115
+ let CE = getCustomElement(tagName);
3116
+
3117
+ if (!isUndefined$1(CE)) {
3118
+ return CE;
3119
+ }
3120
+ /**
3121
+ * LWC Upgradable Element reference to an element that was created
3122
+ * via the scoped registry mechanism, and that is ready to be upgraded.
3123
+ */
3124
+
3125
+
3126
+ CE = class LWCUpgradableElement extends RendererHTMLElement {
3127
+ constructor(upgradeCallback) {
3128
+ super();
3129
+
3130
+ if (isFunction$1(upgradeCallback)) {
3131
+ upgradeCallback(this); // nothing to do with the result for now
3132
+ }
3101
3133
  }
3102
- /**
3103
- * LWC Upgradable Element reference to an element that was created
3104
- * via the scoped registry mechanism, and that is ready to be upgraded.
3105
- */
3106
- CE = class LWCUpgradableElement extends RendererHTMLElement {
3107
- constructor(upgradeCallback) {
3108
- super();
3109
- if (isFunction$1(upgradeCallback)) {
3110
- upgradeCallback(this); // nothing to do with the result for now
3111
- }
3112
- }
3134
+
3135
+ };
3136
+
3137
+ if (lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3138
+ CE.prototype.connectedCallback = function () {
3139
+ if (checkHasVM(this)) {
3140
+ connectRootElement(this);
3141
+ }
3113
3142
  };
3114
- defineCustomElement(tagName, CE);
3115
- return CE;
3143
+
3144
+ CE.prototype.disconnectedCallback = function () {
3145
+ if (checkHasVM(this)) {
3146
+ disconnectRootElement(this);
3147
+ }
3148
+ };
3149
+ }
3150
+
3151
+ defineCustomElement(tagName, CE);
3152
+ return CE;
3116
3153
  }
3117
3154
 
3118
3155
  /*
@@ -3200,6 +3237,14 @@ function patchProps(oldVnode, vnode, renderer) {
3200
3237
  // different than the one previously set.
3201
3238
  if (isFirstPatch ||
3202
3239
  cur !== (isLiveBindingProp(sel, key) ? getProperty(elm, key) : oldProps[key])) {
3240
+ // Additional verification if properties are supported by the element
3241
+ // Validation relies on html properties and public properties being defined on the element,
3242
+ // SSR has its own custom validation.
3243
+ if (process.env.IS_BROWSER && process.env.NODE_ENV !== 'production') {
3244
+ if (!(key in elm)) {
3245
+ logWarn(`Unknown public property "${key}" of element <${elm.tagName.toLowerCase()}>. This is either a typo on the corresponding attribute "${htmlPropertyToAttribute(key)}", or the attribute does not exist in this browser or DOM implementation.`);
3246
+ }
3247
+ }
3203
3248
  setProperty(elm, key, cur);
3204
3249
  }
3205
3250
  }
@@ -3358,579 +3403,802 @@ function applyStaticStyleAttribute(vnode, renderer) {
3358
3403
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3359
3404
  */
3360
3405
  function patchChildren(c1, c2, parent, renderer) {
3361
- if (hasDynamicChildren(c2)) {
3362
- updateDynamicChildren(c1, c2, parent, renderer);
3363
- }
3364
- else {
3365
- updateStaticChildren(c1, c2, parent, renderer);
3366
- }
3406
+ if (hasDynamicChildren(c2)) {
3407
+ updateDynamicChildren(c1, c2, parent, renderer);
3408
+ } else {
3409
+ updateStaticChildren(c1, c2, parent, renderer);
3410
+ }
3367
3411
  }
3412
+
3368
3413
  function patch(n1, n2, parent, renderer) {
3369
- var _a, _b;
3370
- if (n1 === n2) {
3371
- return;
3372
- }
3373
- if (process.env.NODE_ENV !== 'production') {
3374
- if (!isSameVnode(n1, n2)) {
3375
- throw new Error('Expected these VNodes to be the same: ' +
3376
- JSON.stringify({ sel: n1.sel, key: n1.key }) +
3377
- ', ' +
3378
- JSON.stringify({ sel: n2.sel, key: n2.key }));
3379
- }
3380
- }
3381
- switch (n2.type) {
3382
- case 0 /* VNodeType.Text */:
3383
- // VText has no special capability, fallback to the owner's renderer
3384
- patchText(n1, n2, renderer);
3385
- break;
3386
- case 1 /* VNodeType.Comment */:
3387
- // VComment has no special capability, fallback to the owner's renderer
3388
- patchComment(n1, n2, renderer);
3389
- break;
3390
- case 4 /* VNodeType.Static */:
3391
- n2.elm = n1.elm;
3392
- break;
3393
- case 2 /* VNodeType.Element */:
3394
- patchElement(n1, n2, (_a = n2.data.renderer) !== null && _a !== void 0 ? _a : renderer);
3395
- break;
3396
- case 3 /* VNodeType.CustomElement */:
3397
- patchCustomElement(n1, n2, parent, (_b = n2.data.renderer) !== null && _b !== void 0 ? _b : renderer);
3398
- break;
3414
+ var _a, _b;
3415
+
3416
+ if (n1 === n2) {
3417
+ return;
3418
+ }
3419
+
3420
+ if (process.env.NODE_ENV !== 'production') {
3421
+ if (!isSameVnode(n1, n2)) {
3422
+ throw new Error('Expected these VNodes to be the same: ' + JSON.stringify({
3423
+ sel: n1.sel,
3424
+ key: n1.key
3425
+ }) + ', ' + JSON.stringify({
3426
+ sel: n2.sel,
3427
+ key: n2.key
3428
+ }));
3399
3429
  }
3430
+ }
3431
+
3432
+ switch (n2.type) {
3433
+ case 0
3434
+ /* VNodeType.Text */
3435
+ :
3436
+ // VText has no special capability, fallback to the owner's renderer
3437
+ patchText(n1, n2, renderer);
3438
+ break;
3439
+
3440
+ case 1
3441
+ /* VNodeType.Comment */
3442
+ :
3443
+ // VComment has no special capability, fallback to the owner's renderer
3444
+ patchComment(n1, n2, renderer);
3445
+ break;
3446
+
3447
+ case 4
3448
+ /* VNodeType.Static */
3449
+ :
3450
+ n2.elm = n1.elm;
3451
+ break;
3452
+
3453
+ case 2
3454
+ /* VNodeType.Element */
3455
+ :
3456
+ patchElement(n1, n2, (_a = n2.data.renderer) !== null && _a !== void 0 ? _a : renderer);
3457
+ break;
3458
+
3459
+ case 3
3460
+ /* VNodeType.CustomElement */
3461
+ :
3462
+ patchCustomElement(n1, n2, parent, (_b = n2.data.renderer) !== null && _b !== void 0 ? _b : renderer);
3463
+ break;
3464
+ }
3400
3465
  }
3466
+
3401
3467
  function mount(node, parent, renderer, anchor) {
3402
- var _a, _b;
3403
- switch (node.type) {
3404
- case 0 /* VNodeType.Text */:
3405
- // VText has no special capability, fallback to the owner's renderer
3406
- mountText(node, parent, anchor, renderer);
3407
- break;
3408
- case 1 /* VNodeType.Comment */:
3409
- // VComment has no special capability, fallback to the owner's renderer
3410
- mountComment(node, parent, anchor, renderer);
3411
- break;
3412
- case 4 /* VNodeType.Static */:
3413
- // VStatic cannot have a custom renderer associated to them, using owner's renderer
3414
- mountStatic(node, parent, anchor, renderer);
3415
- break;
3416
- case 2 /* VNodeType.Element */:
3417
- // If the vnode data has a renderer override use it, else fallback to owner's renderer
3418
- mountElement(node, parent, anchor, (_a = node.data.renderer) !== null && _a !== void 0 ? _a : renderer);
3419
- break;
3420
- case 3 /* VNodeType.CustomElement */:
3421
- // If the vnode data has a renderer override use it, else fallback to owner's renderer
3422
- mountCustomElement(node, parent, anchor, (_b = node.data.renderer) !== null && _b !== void 0 ? _b : renderer);
3423
- break;
3424
- }
3468
+ var _a, _b;
3469
+
3470
+ switch (node.type) {
3471
+ case 0
3472
+ /* VNodeType.Text */
3473
+ :
3474
+ // VText has no special capability, fallback to the owner's renderer
3475
+ mountText(node, parent, anchor, renderer);
3476
+ break;
3477
+
3478
+ case 1
3479
+ /* VNodeType.Comment */
3480
+ :
3481
+ // VComment has no special capability, fallback to the owner's renderer
3482
+ mountComment(node, parent, anchor, renderer);
3483
+ break;
3484
+
3485
+ case 4
3486
+ /* VNodeType.Static */
3487
+ :
3488
+ // VStatic cannot have a custom renderer associated to them, using owner's renderer
3489
+ mountStatic(node, parent, anchor, renderer);
3490
+ break;
3491
+
3492
+ case 2
3493
+ /* VNodeType.Element */
3494
+ :
3495
+ // If the vnode data has a renderer override use it, else fallback to owner's renderer
3496
+ mountElement(node, parent, anchor, (_a = node.data.renderer) !== null && _a !== void 0 ? _a : renderer);
3497
+ break;
3498
+
3499
+ case 3
3500
+ /* VNodeType.CustomElement */
3501
+ :
3502
+ // If the vnode data has a renderer override use it, else fallback to owner's renderer
3503
+ mountCustomElement(node, parent, anchor, (_b = node.data.renderer) !== null && _b !== void 0 ? _b : renderer);
3504
+ break;
3505
+ }
3425
3506
  }
3507
+
3426
3508
  function patchText(n1, n2, renderer) {
3427
- n2.elm = n1.elm;
3428
- if (n2.text !== n1.text) {
3429
- updateTextContent(n2, renderer);
3430
- }
3509
+ n2.elm = n1.elm;
3510
+
3511
+ if (n2.text !== n1.text) {
3512
+ updateTextContent(n2, renderer);
3513
+ }
3431
3514
  }
3515
+
3432
3516
  function mountText(vnode, parent, anchor, renderer) {
3433
- const { owner } = vnode;
3434
- const { createText } = renderer;
3435
- const textNode = (vnode.elm = createText(vnode.text));
3436
- linkNodeToShadow(textNode, owner, renderer);
3437
- insertNode(textNode, parent, anchor, renderer);
3517
+ const {
3518
+ owner
3519
+ } = vnode;
3520
+ const {
3521
+ createText
3522
+ } = renderer;
3523
+ const textNode = vnode.elm = createText(vnode.text);
3524
+ linkNodeToShadow(textNode, owner, renderer);
3525
+ insertNode(textNode, parent, anchor, renderer);
3438
3526
  }
3527
+
3439
3528
  function patchComment(n1, n2, renderer) {
3440
- n2.elm = n1.elm;
3441
- // FIXME: Comment nodes should be static, we shouldn't need to diff them together. However
3442
- // it is the case today.
3443
- if (n2.text !== n1.text) {
3444
- updateTextContent(n2, renderer);
3445
- }
3529
+ n2.elm = n1.elm; // FIXME: Comment nodes should be static, we shouldn't need to diff them together. However
3530
+ // it is the case today.
3531
+
3532
+ if (n2.text !== n1.text) {
3533
+ updateTextContent(n2, renderer);
3534
+ }
3446
3535
  }
3536
+
3447
3537
  function mountComment(vnode, parent, anchor, renderer) {
3448
- const { owner } = vnode;
3449
- const { createComment } = renderer;
3450
- const commentNode = (vnode.elm = createComment(vnode.text));
3451
- linkNodeToShadow(commentNode, owner, renderer);
3452
- insertNode(commentNode, parent, anchor, renderer);
3538
+ const {
3539
+ owner
3540
+ } = vnode;
3541
+ const {
3542
+ createComment
3543
+ } = renderer;
3544
+ const commentNode = vnode.elm = createComment(vnode.text);
3545
+ linkNodeToShadow(commentNode, owner, renderer);
3546
+ insertNode(commentNode, parent, anchor, renderer);
3453
3547
  }
3548
+
3454
3549
  function mountElement(vnode, parent, anchor, renderer) {
3455
- const { sel, owner, data: { svg }, } = vnode;
3456
- const { createElement } = renderer;
3457
- const namespace = isTrue(svg) ? SVG_NAMESPACE : undefined;
3458
- const elm = (vnode.elm = createElement(sel, namespace));
3459
- linkNodeToShadow(elm, owner, renderer);
3460
- applyStyleScoping(elm, owner, renderer);
3461
- applyDomManual(elm, vnode);
3462
- applyElementRestrictions(elm, vnode);
3463
- patchElementPropsAndAttrs$1(null, vnode, renderer);
3464
- insertNode(elm, parent, anchor, renderer);
3465
- mountVNodes(vnode.children, elm, renderer, null);
3550
+ const {
3551
+ sel,
3552
+ owner,
3553
+ data: {
3554
+ svg
3555
+ }
3556
+ } = vnode;
3557
+ const {
3558
+ createElement
3559
+ } = renderer;
3560
+ const namespace = isTrue(svg) ? SVG_NAMESPACE : undefined;
3561
+ const elm = vnode.elm = createElement(sel, namespace);
3562
+ linkNodeToShadow(elm, owner, renderer);
3563
+ applyStyleScoping(elm, owner, renderer);
3564
+ applyDomManual(elm, vnode);
3565
+ applyElementRestrictions(elm, vnode);
3566
+ patchElementPropsAndAttrs$1(null, vnode, renderer);
3567
+ insertNode(elm, parent, anchor, renderer);
3568
+ mountVNodes(vnode.children, elm, renderer, null);
3466
3569
  }
3570
+
3467
3571
  function patchElement(n1, n2, renderer) {
3468
- const elm = (n2.elm = n1.elm);
3469
- patchElementPropsAndAttrs$1(n1, n2, renderer);
3470
- patchChildren(n1.children, n2.children, elm, renderer);
3572
+ const elm = n2.elm = n1.elm;
3573
+ patchElementPropsAndAttrs$1(n1, n2, renderer);
3574
+ patchChildren(n1.children, n2.children, elm, renderer);
3471
3575
  }
3576
+
3472
3577
  function mountStatic(vnode, parent, anchor, renderer) {
3473
- const { owner } = vnode;
3474
- const { cloneNode, isSyntheticShadowDefined } = renderer;
3475
- const elm = (vnode.elm = cloneNode(vnode.fragment, true));
3476
- linkNodeToShadow(elm, owner, renderer);
3477
- applyElementRestrictions(elm, vnode);
3478
- // Marks this node as Static to propagate the shadow resolver. must happen after elm is assigned to the proper shadow
3479
- const { renderMode, shadowMode } = owner;
3480
- if (isSyntheticShadowDefined) {
3481
- if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
3482
- elm[KEY__SHADOW_STATIC] = true;
3483
- }
3578
+ const {
3579
+ owner
3580
+ } = vnode;
3581
+ const {
3582
+ cloneNode,
3583
+ isSyntheticShadowDefined
3584
+ } = renderer;
3585
+ const elm = vnode.elm = cloneNode(vnode.fragment, true);
3586
+ linkNodeToShadow(elm, owner, renderer);
3587
+ applyElementRestrictions(elm, vnode); // Marks this node as Static to propagate the shadow resolver. must happen after elm is assigned to the proper shadow
3588
+
3589
+ const {
3590
+ renderMode,
3591
+ shadowMode
3592
+ } = owner;
3593
+
3594
+ if (isSyntheticShadowDefined) {
3595
+ if (shadowMode === 1
3596
+ /* ShadowMode.Synthetic */
3597
+ || renderMode === 0
3598
+ /* RenderMode.Light */
3599
+ ) {
3600
+ elm[KEY__SHADOW_STATIC] = true;
3484
3601
  }
3485
- insertNode(elm, parent, anchor, renderer);
3602
+ }
3603
+
3604
+ insertNode(elm, parent, anchor, renderer);
3486
3605
  }
3606
+
3487
3607
  function mountCustomElement(vnode, parent, anchor, renderer) {
3488
- const { sel, owner } = vnode;
3489
- const UpgradableConstructor = getUpgradableConstructor(sel, renderer);
3490
- /**
3491
- * Note: if the upgradable constructor does not expect, or throw when we new it
3492
- * with a callback as the first argument, we could implement a more advanced
3493
- * mechanism that only passes that argument if the constructor is known to be
3494
- * an upgradable custom element.
3495
- */
3496
- let vm;
3497
- const elm = new UpgradableConstructor((elm) => {
3498
- // the custom element from the registry is expecting an upgrade callback
3499
- vm = createViewModelHook(elm, vnode, renderer);
3500
- });
3501
- vnode.elm = elm;
3502
- vnode.vm = vm;
3503
- linkNodeToShadow(elm, owner, renderer);
3504
- applyStyleScoping(elm, owner, renderer);
3505
- if (vm) {
3506
- allocateChildren(vnode, vm);
3507
- }
3508
- else if (vnode.ctor !== UpgradableConstructor) {
3509
- throw new TypeError(`Incorrect Component Constructor`);
3510
- }
3511
- patchElementPropsAndAttrs$1(null, vnode, renderer);
3512
- insertNode(elm, parent, anchor, renderer);
3513
- if (vm) {
3608
+ const {
3609
+ sel,
3610
+ owner
3611
+ } = vnode;
3612
+ const UpgradableConstructor = getUpgradableConstructor(sel, renderer);
3613
+ /**
3614
+ * Note: if the upgradable constructor does not expect, or throw when we new it
3615
+ * with a callback as the first argument, we could implement a more advanced
3616
+ * mechanism that only passes that argument if the constructor is known to be
3617
+ * an upgradable custom element.
3618
+ */
3619
+
3620
+ let vm;
3621
+ const elm = new UpgradableConstructor(elm => {
3622
+ // the custom element from the registry is expecting an upgrade callback
3623
+ vm = createViewModelHook(elm, vnode, renderer);
3624
+ });
3625
+ vnode.elm = elm;
3626
+ vnode.vm = vm;
3627
+ linkNodeToShadow(elm, owner, renderer);
3628
+ applyStyleScoping(elm, owner, renderer);
3629
+
3630
+ if (vm) {
3631
+ allocateChildren(vnode, vm);
3632
+ } else if (vnode.ctor !== UpgradableConstructor) {
3633
+ throw new TypeError(`Incorrect Component Constructor`);
3634
+ }
3635
+
3636
+ patchElementPropsAndAttrs$1(null, vnode, renderer);
3637
+ insertNode(elm, parent, anchor, renderer);
3638
+
3639
+ if (vm) {
3640
+ if (process.env.IS_BROWSER) {
3641
+ if (!lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
3514
3642
  if (process.env.NODE_ENV !== 'production') {
3515
- assert.isTrue(vm.state === 0 /* VMState.created */, `${vm} cannot be recycled.`);
3643
+ // With synthetic lifecycle callbacks, it's possible for elements to be removed without the engine
3644
+ // noticing it (e.g. `appendChild` the same host element twice). This test ensures we don't regress.
3645
+ assert.isTrue(vm.state === 0
3646
+ /* VMState.created */
3647
+ , `${vm} cannot be recycled.`);
3516
3648
  }
3649
+
3517
3650
  runConnectedCallback(vm);
3651
+ }
3652
+ } else {
3653
+ // On the server, we don't have native custom element lifecycle callbacks, so we must
3654
+ // manually invoke the connectedCallback for a child component.
3655
+ runConnectedCallback(vm);
3518
3656
  }
3519
- mountVNodes(vnode.children, elm, renderer, null);
3520
- if (vm) {
3521
- appendVM(vm);
3522
- }
3657
+ }
3658
+
3659
+ mountVNodes(vnode.children, elm, renderer, null);
3660
+
3661
+ if (vm) {
3662
+ appendVM(vm);
3663
+ }
3523
3664
  }
3665
+
3524
3666
  function patchCustomElement(n1, n2, parent, renderer) {
3525
- if (n1.ctor !== n2.ctor) {
3526
- // If the constructor, unmount the current component and mount a new one using the new
3527
- // constructor.
3528
- const anchor = renderer.nextSibling(n1.elm);
3529
- unmount(n1, parent, renderer, true);
3530
- mountCustomElement(n2, parent, anchor, renderer);
3531
- }
3532
- else {
3533
- // Otherwise patch the existing component with new props/attrs/etc.
3534
- const elm = (n2.elm = n1.elm);
3535
- const vm = (n2.vm = n1.vm);
3536
- patchElementPropsAndAttrs$1(n1, n2, renderer);
3537
- if (!isUndefined$1(vm)) {
3538
- // in fallback mode, the allocation will always set children to
3539
- // empty and delegate the real allocation to the slot elements
3540
- allocateChildren(n2, vm);
3541
- }
3542
- // in fallback mode, the children will be always empty, so, nothing
3543
- // will happen, but in native, it does allocate the light dom
3544
- patchChildren(n1.children, n2.children, elm, renderer);
3545
- if (!isUndefined$1(vm)) {
3546
- // this will probably update the shadowRoot, but only if the vm is in a dirty state
3547
- // this is important to preserve the top to bottom synchronous rendering phase.
3548
- rerenderVM(vm);
3549
- }
3667
+ if (n1.ctor !== n2.ctor) {
3668
+ // If the constructor, unmount the current component and mount a new one using the new
3669
+ // constructor.
3670
+ const anchor = renderer.nextSibling(n1.elm);
3671
+ unmount(n1, parent, renderer, true);
3672
+ mountCustomElement(n2, parent, anchor, renderer);
3673
+ } else {
3674
+ // Otherwise patch the existing component with new props/attrs/etc.
3675
+ const elm = n2.elm = n1.elm;
3676
+ const vm = n2.vm = n1.vm;
3677
+ patchElementPropsAndAttrs$1(n1, n2, renderer);
3678
+
3679
+ if (!isUndefined$1(vm)) {
3680
+ // in fallback mode, the allocation will always set children to
3681
+ // empty and delegate the real allocation to the slot elements
3682
+ allocateChildren(n2, vm);
3683
+ } // in fallback mode, the children will be always empty, so, nothing
3684
+ // will happen, but in native, it does allocate the light dom
3685
+
3686
+
3687
+ patchChildren(n1.children, n2.children, elm, renderer);
3688
+
3689
+ if (!isUndefined$1(vm)) {
3690
+ // this will probably update the shadowRoot, but only if the vm is in a dirty state
3691
+ // this is important to preserve the top to bottom synchronous rendering phase.
3692
+ rerenderVM(vm);
3550
3693
  }
3694
+ }
3551
3695
  }
3696
+
3552
3697
  function mountVNodes(vnodes, parent, renderer, anchor, start = 0, end = vnodes.length) {
3553
- for (; start < end; ++start) {
3554
- const vnode = vnodes[start];
3555
- if (isVNode(vnode)) {
3556
- mount(vnode, parent, renderer, anchor);
3557
- }
3698
+ for (; start < end; ++start) {
3699
+ const vnode = vnodes[start];
3700
+
3701
+ if (isVNode(vnode)) {
3702
+ mount(vnode, parent, renderer, anchor);
3558
3703
  }
3704
+ }
3559
3705
  }
3706
+
3560
3707
  function unmount(vnode, parent, renderer, doRemove = false) {
3561
- const { type, elm, sel } = vnode;
3562
- // When unmounting a VNode subtree not all the elements have to removed from the DOM. The
3563
- // subtree root, is the only element worth unmounting from the subtree.
3564
- if (doRemove) {
3565
- // The vnode might or might not have a data.renderer associated to it
3566
- // but the removal used here is from the owner instead.
3567
- removeNode(elm, parent, renderer);
3568
- }
3569
- switch (type) {
3570
- case 2 /* VNodeType.Element */: {
3571
- // Slot content is removed to trigger slotchange event when removing slot.
3572
- // Only required for synthetic shadow.
3573
- const shouldRemoveChildren = sel === 'slot' && vnode.owner.shadowMode === 1 /* ShadowMode.Synthetic */;
3574
- unmountVNodes(vnode.children, elm, renderer, shouldRemoveChildren);
3575
- break;
3576
- }
3577
- case 3 /* VNodeType.CustomElement */: {
3578
- const { vm } = vnode;
3579
- // No need to unmount the children here, `removeVM` will take care of removing the
3580
- // children.
3581
- if (!isUndefined$1(vm)) {
3582
- removeVM(vm);
3583
- }
3708
+ const {
3709
+ type,
3710
+ elm,
3711
+ sel
3712
+ } = vnode; // When unmounting a VNode subtree not all the elements have to removed from the DOM. The
3713
+ // subtree root, is the only element worth unmounting from the subtree.
3714
+
3715
+ if (doRemove) {
3716
+ // The vnode might or might not have a data.renderer associated to it
3717
+ // but the removal used here is from the owner instead.
3718
+ removeNode(elm, parent, renderer);
3719
+ }
3720
+
3721
+ switch (type) {
3722
+ case 2
3723
+ /* VNodeType.Element */
3724
+ :
3725
+ {
3726
+ // Slot content is removed to trigger slotchange event when removing slot.
3727
+ // Only required for synthetic shadow.
3728
+ const shouldRemoveChildren = sel === 'slot' && vnode.owner.shadowMode === 1
3729
+ /* ShadowMode.Synthetic */
3730
+ ;
3731
+ unmountVNodes(vnode.children, elm, renderer, shouldRemoveChildren);
3732
+ break;
3733
+ }
3734
+
3735
+ case 3
3736
+ /* VNodeType.CustomElement */
3737
+ :
3738
+ {
3739
+ const {
3740
+ vm
3741
+ } = vnode; // No need to unmount the children here, `removeVM` will take care of removing the
3742
+ // children.
3743
+
3744
+ if (!isUndefined$1(vm)) {
3745
+ removeVM(vm);
3584
3746
  }
3585
- }
3747
+ }
3748
+ }
3586
3749
  }
3750
+
3587
3751
  function unmountVNodes(vnodes, parent, renderer, doRemove = false, start = 0, end = vnodes.length) {
3588
- for (; start < end; ++start) {
3589
- const ch = vnodes[start];
3590
- if (isVNode(ch)) {
3591
- unmount(ch, parent, renderer, doRemove);
3592
- }
3752
+ for (; start < end; ++start) {
3753
+ const ch = vnodes[start];
3754
+
3755
+ if (isVNode(ch)) {
3756
+ unmount(ch, parent, renderer, doRemove);
3593
3757
  }
3758
+ }
3594
3759
  }
3760
+
3595
3761
  function isVNode(vnode) {
3596
- return vnode != null;
3762
+ return vnode != null;
3597
3763
  }
3764
+
3598
3765
  function linkNodeToShadow(elm, owner, renderer) {
3599
- const { renderRoot, renderMode, shadowMode } = owner;
3600
- const { isSyntheticShadowDefined } = renderer;
3601
- // TODO [#1164]: this should eventually be done by the polyfill directly
3602
- if (isSyntheticShadowDefined) {
3603
- if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
3604
- elm[KEY__SHADOW_RESOLVER] = renderRoot[KEY__SHADOW_RESOLVER];
3605
- }
3766
+ const {
3767
+ renderRoot,
3768
+ renderMode,
3769
+ shadowMode
3770
+ } = owner;
3771
+ const {
3772
+ isSyntheticShadowDefined
3773
+ } = renderer; // TODO [#1164]: this should eventually be done by the polyfill directly
3774
+
3775
+ if (isSyntheticShadowDefined) {
3776
+ if (shadowMode === 1
3777
+ /* ShadowMode.Synthetic */
3778
+ || renderMode === 0
3779
+ /* RenderMode.Light */
3780
+ ) {
3781
+ elm[KEY__SHADOW_RESOLVER] = renderRoot[KEY__SHADOW_RESOLVER];
3606
3782
  }
3783
+ }
3607
3784
  }
3785
+
3608
3786
  function updateTextContent(vnode, renderer) {
3609
- const { elm, text } = vnode;
3610
- const { setText } = renderer;
3611
- if (process.env.NODE_ENV !== 'production') {
3612
- unlockDomMutation();
3613
- }
3614
- setText(elm, text);
3615
- if (process.env.NODE_ENV !== 'production') {
3616
- lockDomMutation();
3617
- }
3787
+ const {
3788
+ elm,
3789
+ text
3790
+ } = vnode;
3791
+ const {
3792
+ setText
3793
+ } = renderer;
3794
+
3795
+ if (process.env.NODE_ENV !== 'production') {
3796
+ unlockDomMutation();
3797
+ }
3798
+
3799
+ setText(elm, text);
3800
+
3801
+ if (process.env.NODE_ENV !== 'production') {
3802
+ lockDomMutation();
3803
+ }
3618
3804
  }
3805
+
3619
3806
  function insertNode(node, parent, anchor, renderer) {
3620
- if (process.env.NODE_ENV !== 'production') {
3621
- unlockDomMutation();
3622
- }
3623
- renderer.insert(node, parent, anchor);
3624
- if (process.env.NODE_ENV !== 'production') {
3625
- lockDomMutation();
3626
- }
3807
+ if (process.env.NODE_ENV !== 'production') {
3808
+ unlockDomMutation();
3809
+ }
3810
+
3811
+ renderer.insert(node, parent, anchor);
3812
+
3813
+ if (process.env.NODE_ENV !== 'production') {
3814
+ lockDomMutation();
3815
+ }
3627
3816
  }
3817
+
3628
3818
  function removeNode(node, parent, renderer) {
3629
- if (process.env.NODE_ENV !== 'production') {
3630
- unlockDomMutation();
3631
- }
3632
- renderer.remove(node, parent);
3633
- if (process.env.NODE_ENV !== 'production') {
3634
- lockDomMutation();
3635
- }
3819
+ if (process.env.NODE_ENV !== 'production') {
3820
+ unlockDomMutation();
3821
+ }
3822
+
3823
+ renderer.remove(node, parent);
3824
+
3825
+ if (process.env.NODE_ENV !== 'production') {
3826
+ lockDomMutation();
3827
+ }
3636
3828
  }
3829
+
3637
3830
  function patchElementPropsAndAttrs$1(oldVnode, vnode, renderer) {
3638
- if (isNull(oldVnode)) {
3639
- applyEventListeners(vnode, renderer);
3640
- applyStaticClassAttribute(vnode, renderer);
3641
- applyStaticStyleAttribute(vnode, renderer);
3642
- }
3643
- // Attrs need to be applied to element before props IE11 will wipe out value on radio inputs if
3644
- // value is set before type=radio.
3645
- patchClassAttribute(oldVnode, vnode, renderer);
3646
- patchStyleAttribute(oldVnode, vnode, renderer);
3647
- patchAttributes(oldVnode, vnode, renderer);
3648
- patchProps(oldVnode, vnode, renderer);
3831
+ if (isNull(oldVnode)) {
3832
+ applyEventListeners(vnode, renderer);
3833
+ applyStaticClassAttribute(vnode, renderer);
3834
+ applyStaticStyleAttribute(vnode, renderer);
3835
+ } // Attrs need to be applied to element before props IE11 will wipe out value on radio inputs if
3836
+ // value is set before type=radio.
3837
+
3838
+
3839
+ patchClassAttribute(oldVnode, vnode, renderer);
3840
+ patchStyleAttribute(oldVnode, vnode, renderer);
3841
+ patchAttributes(oldVnode, vnode, renderer);
3842
+ patchProps(oldVnode, vnode, renderer);
3649
3843
  }
3844
+
3650
3845
  function applyStyleScoping(elm, owner, renderer) {
3651
- // Set the class name for `*.scoped.css` style scoping.
3652
- const scopeToken = getScopeTokenClass(owner);
3653
- if (!isNull(scopeToken)) {
3654
- const { getClassList } = renderer;
3655
- // TODO [#2762]: this dot notation with add is probably problematic
3656
- // probably we should have a renderer api for just the add operation
3657
- getClassList(elm).add(scopeToken);
3658
- }
3659
- // Set property element for synthetic shadow DOM style scoping.
3660
- const { stylesheetToken: syntheticToken } = owner.context;
3661
- if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && !isUndefined$1(syntheticToken)) {
3662
- elm.$shadowToken$ = syntheticToken;
3663
- }
3846
+ // Set the class name for `*.scoped.css` style scoping.
3847
+ const scopeToken = getScopeTokenClass(owner);
3848
+
3849
+ if (!isNull(scopeToken)) {
3850
+ const {
3851
+ getClassList
3852
+ } = renderer; // TODO [#2762]: this dot notation with add is probably problematic
3853
+ // probably we should have a renderer api for just the add operation
3854
+
3855
+ getClassList(elm).add(scopeToken);
3856
+ } // Set property element for synthetic shadow DOM style scoping.
3857
+
3858
+
3859
+ const {
3860
+ stylesheetToken: syntheticToken
3861
+ } = owner.context;
3862
+
3863
+ if (owner.shadowMode === 1
3864
+ /* ShadowMode.Synthetic */
3865
+ && !isUndefined$1(syntheticToken)) {
3866
+ elm.$shadowToken$ = syntheticToken;
3867
+ }
3664
3868
  }
3869
+
3665
3870
  function applyDomManual(elm, vnode) {
3666
- var _a;
3667
- const { owner, data: { context }, } = vnode;
3668
- 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 */) {
3669
- elm.$domManual$ = true;
3871
+ var _a;
3872
+
3873
+ const {
3874
+ owner,
3875
+ data: {
3876
+ context
3670
3877
  }
3878
+ } = vnode;
3879
+
3880
+ if (owner.shadowMode === 1
3881
+ /* ShadowMode.Synthetic */
3882
+ && ((_a = context === null || context === void 0 ? void 0 : context.lwc) === null || _a === void 0 ? void 0 : _a.dom) === "manual"
3883
+ /* LwcDomMode.Manual */
3884
+ ) {
3885
+ elm.$domManual$ = true;
3886
+ }
3671
3887
  }
3888
+
3672
3889
  function applyElementRestrictions(elm, vnode) {
3673
- var _a, _b;
3674
- if (process.env.NODE_ENV !== 'production') {
3675
- const isPortal = vnode.type === 2 /* VNodeType.Element */ && ((_b = (_a = vnode.data.context) === null || _a === void 0 ? void 0 : _a.lwc) === null || _b === void 0 ? void 0 : _b.dom) === "manual" /* LwcDomMode.Manual */;
3676
- const isLight = vnode.owner.renderMode === 0 /* RenderMode.Light */;
3677
- patchElementWithRestrictions(elm, {
3678
- isPortal,
3679
- isLight,
3680
- });
3681
- }
3890
+ var _a, _b;
3891
+
3892
+ if (process.env.NODE_ENV !== 'production') {
3893
+ const isPortal = vnode.type === 2
3894
+ /* VNodeType.Element */
3895
+ && ((_b = (_a = vnode.data.context) === null || _a === void 0 ? void 0 : _a.lwc) === null || _b === void 0 ? void 0 : _b.dom) === "manual"
3896
+ /* LwcDomMode.Manual */
3897
+ ;
3898
+ const isLight = vnode.owner.renderMode === 0
3899
+ /* RenderMode.Light */
3900
+ ;
3901
+ patchElementWithRestrictions(elm, {
3902
+ isPortal,
3903
+ isLight
3904
+ });
3905
+ }
3682
3906
  }
3907
+
3683
3908
  function allocateChildren(vnode, vm) {
3684
- // A component with slots will re-render because:
3685
- // 1- There is a change of the internal state.
3686
- // 2- There is a change on the external api (ex: slots)
3687
- //
3688
- // In case #1, the vnodes in the cmpSlots will be reused since they didn't changed. This routine emptied the
3689
- // slotted children when those VCustomElement were rendered and therefore in subsequent calls to allocate children
3690
- // in a reused VCustomElement, there won't be any slotted children.
3691
- // For those cases, we will use the reference for allocated children stored when rendering the fresh VCustomElement.
3692
- //
3693
- // In case #2, we will always get a fresh VCustomElement.
3694
- const children = vnode.aChildren || vnode.children;
3695
- vm.aChildren = children;
3696
- const { renderMode, shadowMode } = vm;
3697
- if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
3698
- // slow path
3699
- allocateInSlot(vm, children);
3700
- // save the allocated children in case this vnode is reused.
3701
- vnode.aChildren = children;
3702
- // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
3703
- vnode.children = EmptyArray;
3704
- }
3909
+ // A component with slots will re-render because:
3910
+ // 1- There is a change of the internal state.
3911
+ // 2- There is a change on the external api (ex: slots)
3912
+ //
3913
+ // In case #1, the vnodes in the cmpSlots will be reused since they didn't changed. This routine emptied the
3914
+ // slotted children when those VCustomElement were rendered and therefore in subsequent calls to allocate children
3915
+ // in a reused VCustomElement, there won't be any slotted children.
3916
+ // For those cases, we will use the reference for allocated children stored when rendering the fresh VCustomElement.
3917
+ //
3918
+ // In case #2, we will always get a fresh VCustomElement.
3919
+ const children = vnode.aChildren || vnode.children;
3920
+ vm.aChildren = children;
3921
+ const {
3922
+ renderMode,
3923
+ shadowMode
3924
+ } = vm;
3925
+
3926
+ if (shadowMode === 1
3927
+ /* ShadowMode.Synthetic */
3928
+ || renderMode === 0
3929
+ /* RenderMode.Light */
3930
+ ) {
3931
+ // slow path
3932
+ allocateInSlot(vm, children); // save the allocated children in case this vnode is reused.
3933
+
3934
+ vnode.aChildren = children; // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
3935
+
3936
+ vnode.children = EmptyArray;
3937
+ }
3705
3938
  }
3939
+
3706
3940
  function createViewModelHook(elm, vnode, renderer) {
3707
- let vm = getAssociatedVMIfPresent(elm);
3708
- // There is a possibility that a custom element is registered under tagName, in which case, the
3709
- // initialization is already carry on, and there is nothing else to do here since this hook is
3710
- // called right after invoking `document.createElement`.
3711
- if (!isUndefined$1(vm)) {
3712
- return vm;
3713
- }
3714
- const { sel, mode, ctor, owner } = vnode;
3715
- vm = createVM(elm, ctor, renderer, {
3716
- mode,
3717
- owner,
3718
- tagName: sel,
3719
- });
3720
- if (process.env.NODE_ENV !== 'production') {
3721
- assert.isTrue(isArray$1(vnode.children), `Invalid vnode for a custom element, it must have children defined.`);
3722
- }
3941
+ let vm = getAssociatedVMIfPresent(elm); // There is a possibility that a custom element is registered under tagName, in which case, the
3942
+ // initialization is already carry on, and there is nothing else to do here since this hook is
3943
+ // called right after invoking `document.createElement`.
3944
+
3945
+ if (!isUndefined$1(vm)) {
3723
3946
  return vm;
3947
+ }
3948
+
3949
+ const {
3950
+ sel,
3951
+ mode,
3952
+ ctor,
3953
+ owner
3954
+ } = vnode;
3955
+ vm = createVM(elm, ctor, renderer, {
3956
+ mode,
3957
+ owner,
3958
+ tagName: sel
3959
+ });
3960
+
3961
+ if (process.env.NODE_ENV !== 'production') {
3962
+ assert.isTrue(isArray$1(vnode.children), `Invalid vnode for a custom element, it must have children defined.`);
3963
+ }
3964
+
3965
+ return vm;
3724
3966
  }
3967
+
3725
3968
  function allocateInSlot(vm, children) {
3726
- var _a;
3727
- const { cmpSlots: oldSlots } = vm;
3728
- const cmpSlots = (vm.cmpSlots = create(null));
3729
- for (let i = 0, len = children.length; i < len; i += 1) {
3730
- const vnode = children[i];
3731
- if (isNull(vnode)) {
3732
- continue;
3733
- }
3734
- let slotName = '';
3735
- if (isVBaseElement(vnode)) {
3736
- slotName = ((_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) || '';
3737
- }
3738
- const vnodes = (cmpSlots[slotName] = cmpSlots[slotName] || []);
3739
- ArrayPush$1.call(vnodes, vnode);
3740
- }
3741
- if (isFalse(vm.isDirty)) {
3742
- // We need to determine if the old allocation is really different from the new one
3743
- // and mark the vm as dirty
3744
- const oldKeys = keys(oldSlots);
3745
- if (oldKeys.length !== keys(cmpSlots).length) {
3746
- markComponentAsDirty(vm);
3747
- return;
3748
- }
3749
- for (let i = 0, len = oldKeys.length; i < len; i += 1) {
3750
- const key = oldKeys[i];
3751
- if (isUndefined$1(cmpSlots[key]) || oldSlots[key].length !== cmpSlots[key].length) {
3752
- markComponentAsDirty(vm);
3753
- return;
3754
- }
3755
- const oldVNodes = oldSlots[key];
3756
- const vnodes = cmpSlots[key];
3757
- for (let j = 0, a = cmpSlots[key].length; j < a; j += 1) {
3758
- if (oldVNodes[j] !== vnodes[j]) {
3759
- markComponentAsDirty(vm);
3760
- return;
3761
- }
3762
- }
3969
+ var _a;
3970
+
3971
+ const {
3972
+ cmpSlots: oldSlots
3973
+ } = vm;
3974
+ const cmpSlots = vm.cmpSlots = create(null);
3975
+
3976
+ for (let i = 0, len = children.length; i < len; i += 1) {
3977
+ const vnode = children[i];
3978
+
3979
+ if (isNull(vnode)) {
3980
+ continue;
3981
+ }
3982
+
3983
+ let slotName = '';
3984
+
3985
+ if (isVBaseElement(vnode)) {
3986
+ slotName = ((_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) || '';
3987
+ }
3988
+
3989
+ const vnodes = cmpSlots[slotName] = cmpSlots[slotName] || [];
3990
+ ArrayPush$1.call(vnodes, vnode);
3991
+ }
3992
+
3993
+ if (isFalse(vm.isDirty)) {
3994
+ // We need to determine if the old allocation is really different from the new one
3995
+ // and mark the vm as dirty
3996
+ const oldKeys = keys(oldSlots);
3997
+
3998
+ if (oldKeys.length !== keys(cmpSlots).length) {
3999
+ markComponentAsDirty(vm);
4000
+ return;
4001
+ }
4002
+
4003
+ for (let i = 0, len = oldKeys.length; i < len; i += 1) {
4004
+ const key = oldKeys[i];
4005
+
4006
+ if (isUndefined$1(cmpSlots[key]) || oldSlots[key].length !== cmpSlots[key].length) {
4007
+ markComponentAsDirty(vm);
4008
+ return;
4009
+ }
4010
+
4011
+ const oldVNodes = oldSlots[key];
4012
+ const vnodes = cmpSlots[key];
4013
+
4014
+ for (let j = 0, a = cmpSlots[key].length; j < a; j += 1) {
4015
+ if (oldVNodes[j] !== vnodes[j]) {
4016
+ markComponentAsDirty(vm);
4017
+ return;
3763
4018
  }
4019
+ }
3764
4020
  }
3765
- }
3766
- // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
3767
- const FromIteration = new WeakMap();
3768
- // dynamic children means it was generated by an iteration
4021
+ }
4022
+ } // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
4023
+
4024
+
4025
+ const FromIteration = new WeakMap(); // dynamic children means it was generated by an iteration
3769
4026
  // in a template, and will require a more complex diffing algo.
4027
+
3770
4028
  function markAsDynamicChildren(children) {
3771
- FromIteration.set(children, 1);
4029
+ FromIteration.set(children, 1);
3772
4030
  }
4031
+
3773
4032
  function hasDynamicChildren(children) {
3774
- return FromIteration.has(children);
4033
+ return FromIteration.has(children);
3775
4034
  }
4035
+
3776
4036
  function createKeyToOldIdx(children, beginIdx, endIdx) {
3777
- const map = {};
3778
- // TODO [#1637]: simplify this by assuming that all vnodes has keys
3779
- for (let j = beginIdx; j <= endIdx; ++j) {
3780
- const ch = children[j];
3781
- if (isVNode(ch)) {
3782
- const { key } = ch;
3783
- if (key !== undefined) {
3784
- map[key] = j;
3785
- }
3786
- }
4037
+ const map = {}; // TODO [#1637]: simplify this by assuming that all vnodes has keys
4038
+
4039
+ for (let j = beginIdx; j <= endIdx; ++j) {
4040
+ const ch = children[j];
4041
+
4042
+ if (isVNode(ch)) {
4043
+ const {
4044
+ key
4045
+ } = ch;
4046
+
4047
+ if (key !== undefined) {
4048
+ map[key] = j;
4049
+ }
3787
4050
  }
3788
- return map;
4051
+ }
4052
+
4053
+ return map;
3789
4054
  }
4055
+
3790
4056
  function updateDynamicChildren(oldCh, newCh, parent, renderer) {
3791
- let oldStartIdx = 0;
3792
- let newStartIdx = 0;
3793
- let oldEndIdx = oldCh.length - 1;
3794
- let oldStartVnode = oldCh[0];
3795
- let oldEndVnode = oldCh[oldEndIdx];
3796
- const newChEnd = newCh.length - 1;
3797
- let newEndIdx = newChEnd;
3798
- let newStartVnode = newCh[0];
3799
- let newEndVnode = newCh[newEndIdx];
3800
- let oldKeyToIdx;
3801
- let idxInOld;
3802
- let elmToMove;
3803
- let before;
3804
- let clonedOldCh = false;
3805
- while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
3806
- if (!isVNode(oldStartVnode)) {
3807
- oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left
3808
- }
3809
- else if (!isVNode(oldEndVnode)) {
3810
- oldEndVnode = oldCh[--oldEndIdx];
3811
- }
3812
- else if (!isVNode(newStartVnode)) {
3813
- newStartVnode = newCh[++newStartIdx];
3814
- }
3815
- else if (!isVNode(newEndVnode)) {
3816
- newEndVnode = newCh[--newEndIdx];
3817
- }
3818
- else if (isSameVnode(oldStartVnode, newStartVnode)) {
3819
- patch(oldStartVnode, newStartVnode, parent, renderer);
3820
- oldStartVnode = oldCh[++oldStartIdx];
3821
- newStartVnode = newCh[++newStartIdx];
3822
- }
3823
- else if (isSameVnode(oldEndVnode, newEndVnode)) {
3824
- patch(oldEndVnode, newEndVnode, parent, renderer);
3825
- oldEndVnode = oldCh[--oldEndIdx];
3826
- newEndVnode = newCh[--newEndIdx];
3827
- }
3828
- else if (isSameVnode(oldStartVnode, newEndVnode)) {
3829
- // Vnode moved right
3830
- patch(oldStartVnode, newEndVnode, parent, renderer);
3831
- insertNode(oldStartVnode.elm, parent, renderer.nextSibling(oldEndVnode.elm), renderer);
3832
- oldStartVnode = oldCh[++oldStartIdx];
3833
- newEndVnode = newCh[--newEndIdx];
3834
- }
3835
- else if (isSameVnode(oldEndVnode, newStartVnode)) {
3836
- // Vnode moved left
3837
- patch(oldEndVnode, newStartVnode, parent, renderer);
3838
- insertNode(newStartVnode.elm, parent, oldStartVnode.elm, renderer);
3839
- oldEndVnode = oldCh[--oldEndIdx];
3840
- newStartVnode = newCh[++newStartIdx];
3841
- }
3842
- else {
3843
- if (oldKeyToIdx === undefined) {
3844
- oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
3845
- }
3846
- idxInOld = oldKeyToIdx[newStartVnode.key];
3847
- if (isUndefined$1(idxInOld)) {
3848
- // New element
3849
- mount(newStartVnode, parent, renderer, oldStartVnode.elm);
3850
- newStartVnode = newCh[++newStartIdx];
3851
- }
3852
- else {
3853
- elmToMove = oldCh[idxInOld];
3854
- if (isVNode(elmToMove)) {
3855
- if (elmToMove.sel !== newStartVnode.sel) {
3856
- // New element
3857
- mount(newStartVnode, parent, renderer, oldStartVnode.elm);
3858
- }
3859
- else {
3860
- patch(elmToMove, newStartVnode, parent, renderer);
3861
- // Delete the old child, but copy the array since it is read-only.
3862
- // The `oldCh` will be GC'ed after `updateDynamicChildren` is complete,
3863
- // so we only care about the `oldCh` object inside this function.
3864
- // To avoid cloning over and over again, we check `clonedOldCh`
3865
- // and only clone once.
3866
- if (!clonedOldCh) {
3867
- clonedOldCh = true;
3868
- oldCh = [...oldCh];
3869
- }
3870
- // We've already cloned at least once, so it's no longer read-only
3871
- oldCh[idxInOld] = undefined;
3872
- insertNode(elmToMove.elm, parent, oldStartVnode.elm, renderer);
3873
- }
3874
- }
3875
- newStartVnode = newCh[++newStartIdx];
3876
- }
4057
+ let oldStartIdx = 0;
4058
+ let newStartIdx = 0;
4059
+ let oldEndIdx = oldCh.length - 1;
4060
+ let oldStartVnode = oldCh[0];
4061
+ let oldEndVnode = oldCh[oldEndIdx];
4062
+ const newChEnd = newCh.length - 1;
4063
+ let newEndIdx = newChEnd;
4064
+ let newStartVnode = newCh[0];
4065
+ let newEndVnode = newCh[newEndIdx];
4066
+ let oldKeyToIdx;
4067
+ let idxInOld;
4068
+ let elmToMove;
4069
+ let before;
4070
+ let clonedOldCh = false;
4071
+
4072
+ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
4073
+ if (!isVNode(oldStartVnode)) {
4074
+ oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left
4075
+ } else if (!isVNode(oldEndVnode)) {
4076
+ oldEndVnode = oldCh[--oldEndIdx];
4077
+ } else if (!isVNode(newStartVnode)) {
4078
+ newStartVnode = newCh[++newStartIdx];
4079
+ } else if (!isVNode(newEndVnode)) {
4080
+ newEndVnode = newCh[--newEndIdx];
4081
+ } else if (isSameVnode(oldStartVnode, newStartVnode)) {
4082
+ patch(oldStartVnode, newStartVnode, parent, renderer);
4083
+ oldStartVnode = oldCh[++oldStartIdx];
4084
+ newStartVnode = newCh[++newStartIdx];
4085
+ } else if (isSameVnode(oldEndVnode, newEndVnode)) {
4086
+ patch(oldEndVnode, newEndVnode, parent, renderer);
4087
+ oldEndVnode = oldCh[--oldEndIdx];
4088
+ newEndVnode = newCh[--newEndIdx];
4089
+ } else if (isSameVnode(oldStartVnode, newEndVnode)) {
4090
+ // Vnode moved right
4091
+ patch(oldStartVnode, newEndVnode, parent, renderer);
4092
+ insertNode(oldStartVnode.elm, parent, renderer.nextSibling(oldEndVnode.elm), renderer);
4093
+ oldStartVnode = oldCh[++oldStartIdx];
4094
+ newEndVnode = newCh[--newEndIdx];
4095
+ } else if (isSameVnode(oldEndVnode, newStartVnode)) {
4096
+ // Vnode moved left
4097
+ patch(oldEndVnode, newStartVnode, parent, renderer);
4098
+ insertNode(newStartVnode.elm, parent, oldStartVnode.elm, renderer);
4099
+ oldEndVnode = oldCh[--oldEndIdx];
4100
+ newStartVnode = newCh[++newStartIdx];
4101
+ } else {
4102
+ if (oldKeyToIdx === undefined) {
4103
+ oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
4104
+ }
4105
+
4106
+ idxInOld = oldKeyToIdx[newStartVnode.key];
4107
+
4108
+ if (isUndefined$1(idxInOld)) {
4109
+ // New element
4110
+ mount(newStartVnode, parent, renderer, oldStartVnode.elm);
4111
+ newStartVnode = newCh[++newStartIdx];
4112
+ } else {
4113
+ elmToMove = oldCh[idxInOld];
4114
+
4115
+ if (isVNode(elmToMove)) {
4116
+ if (elmToMove.sel !== newStartVnode.sel) {
4117
+ // New element
4118
+ mount(newStartVnode, parent, renderer, oldStartVnode.elm);
4119
+ } else {
4120
+ patch(elmToMove, newStartVnode, parent, renderer); // Delete the old child, but copy the array since it is read-only.
4121
+ // The `oldCh` will be GC'ed after `updateDynamicChildren` is complete,
4122
+ // so we only care about the `oldCh` object inside this function.
4123
+ // To avoid cloning over and over again, we check `clonedOldCh`
4124
+ // and only clone once.
4125
+
4126
+ if (!clonedOldCh) {
4127
+ clonedOldCh = true;
4128
+ oldCh = [...oldCh];
4129
+ } // We've already cloned at least once, so it's no longer read-only
4130
+
4131
+
4132
+ oldCh[idxInOld] = undefined;
4133
+ insertNode(elmToMove.elm, parent, oldStartVnode.elm, renderer);
4134
+ }
3877
4135
  }
4136
+
4137
+ newStartVnode = newCh[++newStartIdx];
4138
+ }
3878
4139
  }
3879
- if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
3880
- if (oldStartIdx > oldEndIdx) {
3881
- // There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
3882
- // already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
3883
- let i = newEndIdx;
3884
- let n;
3885
- do {
3886
- n = newCh[++i];
3887
- } while (!isVNode(n) && i < newChEnd);
3888
- before = isVNode(n) ? n.elm : null;
3889
- mountVNodes(newCh, parent, renderer, before, newStartIdx, newEndIdx + 1);
3890
- }
3891
- else {
3892
- unmountVNodes(oldCh, parent, renderer, true, oldStartIdx, oldEndIdx + 1);
3893
- }
4140
+ }
4141
+
4142
+ if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
4143
+ if (oldStartIdx > oldEndIdx) {
4144
+ // There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
4145
+ // already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
4146
+ let i = newEndIdx;
4147
+ let n;
4148
+
4149
+ do {
4150
+ n = newCh[++i];
4151
+ } while (!isVNode(n) && i < newChEnd);
4152
+
4153
+ before = isVNode(n) ? n.elm : null;
4154
+ mountVNodes(newCh, parent, renderer, before, newStartIdx, newEndIdx + 1);
4155
+ } else {
4156
+ unmountVNodes(oldCh, parent, renderer, true, oldStartIdx, oldEndIdx + 1);
3894
4157
  }
4158
+ }
3895
4159
  }
4160
+
3896
4161
  function updateStaticChildren(c1, c2, parent, renderer) {
3897
- const c1Length = c1.length;
3898
- const c2Length = c2.length;
3899
- if (c1Length === 0) {
3900
- // the old list is empty, we can directly insert anything new
3901
- mountVNodes(c2, parent, renderer, null);
3902
- return;
3903
- }
3904
- if (c2Length === 0) {
3905
- // the old list is nonempty and the new list is empty so we can directly remove all old nodes
3906
- // this is the case in which the dynamic children of an if-directive should be removed
3907
- unmountVNodes(c1, parent, renderer, true);
3908
- return;
3909
- }
3910
- // if the old list is not empty, the new list MUST have the same
3911
- // amount of nodes, that's why we call this static children
3912
- let anchor = null;
3913
- for (let i = c2Length - 1; i >= 0; i -= 1) {
3914
- const n1 = c1[i];
3915
- const n2 = c2[i];
3916
- if (n2 !== n1) {
3917
- if (isVNode(n1)) {
3918
- if (isVNode(n2)) {
3919
- // both vnodes are equivalent, and we just need to patch them
3920
- patch(n1, n2, parent, renderer);
3921
- anchor = n2.elm;
3922
- }
3923
- else {
3924
- // removing the old vnode since the new one is null
3925
- unmount(n1, parent, renderer, true);
3926
- }
3927
- }
3928
- else if (isVNode(n2)) {
3929
- mount(n2, parent, renderer, anchor);
3930
- anchor = n2.elm;
3931
- }
4162
+ const c1Length = c1.length;
4163
+ const c2Length = c2.length;
4164
+
4165
+ if (c1Length === 0) {
4166
+ // the old list is empty, we can directly insert anything new
4167
+ mountVNodes(c2, parent, renderer, null);
4168
+ return;
4169
+ }
4170
+
4171
+ if (c2Length === 0) {
4172
+ // the old list is nonempty and the new list is empty so we can directly remove all old nodes
4173
+ // this is the case in which the dynamic children of an if-directive should be removed
4174
+ unmountVNodes(c1, parent, renderer, true);
4175
+ return;
4176
+ } // if the old list is not empty, the new list MUST have the same
4177
+ // amount of nodes, that's why we call this static children
4178
+
4179
+
4180
+ let anchor = null;
4181
+
4182
+ for (let i = c2Length - 1; i >= 0; i -= 1) {
4183
+ const n1 = c1[i];
4184
+ const n2 = c2[i];
4185
+
4186
+ if (n2 !== n1) {
4187
+ if (isVNode(n1)) {
4188
+ if (isVNode(n2)) {
4189
+ // both vnodes are equivalent, and we just need to patch them
4190
+ patch(n1, n2, parent, renderer);
4191
+ anchor = n2.elm;
4192
+ } else {
4193
+ // removing the old vnode since the new one is null
4194
+ unmount(n1, parent, renderer, true);
3932
4195
  }
4196
+ } else if (isVNode(n2)) {
4197
+ mount(n2, parent, renderer, anchor);
4198
+ anchor = n2.elm;
4199
+ }
3933
4200
  }
4201
+ }
3934
4202
  }
3935
4203
 
3936
4204
  /*
@@ -5889,6 +6157,7 @@ function hydrateNode(node, vnode, renderer) {
5889
6157
  }
5890
6158
  return renderer.nextSibling(hydratedNode);
5891
6159
  }
6160
+ const NODE_VALUE_PROP = 'nodeValue';
5892
6161
  function hydrateText(node, vnode, renderer) {
5893
6162
  var _a;
5894
6163
  if (!hasCorrectNodeType(vnode, node, 3 /* EnvNodeTypes.TEXT */, renderer)) {
@@ -5896,7 +6165,7 @@ function hydrateText(node, vnode, renderer) {
5896
6165
  }
5897
6166
  if (process.env.NODE_ENV !== 'production') {
5898
6167
  const { getProperty } = renderer;
5899
- const nodeValue = getProperty(node, 'nodeValue');
6168
+ const nodeValue = getProperty(node, NODE_VALUE_PROP);
5900
6169
  if (nodeValue !== vnode.text && !(nodeValue === '\u200D' && vnode.text === '')) {
5901
6170
  logWarn('Hydration mismatch: text values do not match, will recover from the difference', vnode.owner);
5902
6171
  }
@@ -5913,13 +6182,13 @@ function hydrateComment(node, vnode, renderer) {
5913
6182
  }
5914
6183
  if (process.env.NODE_ENV !== 'production') {
5915
6184
  const { getProperty } = renderer;
5916
- const nodeValue = getProperty(node, 'nodeValue');
6185
+ const nodeValue = getProperty(node, NODE_VALUE_PROP);
5917
6186
  if (nodeValue !== vnode.text) {
5918
6187
  logWarn('Hydration mismatch: comment values do not match, will recover from the difference', vnode.owner);
5919
6188
  }
5920
6189
  }
5921
6190
  const { setProperty } = renderer;
5922
- setProperty(node, 'nodeValue', (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
6191
+ setProperty(node, NODE_VALUE_PROP, (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
5923
6192
  vnode.elm = node;
5924
6193
  return node;
5925
6194
  }
@@ -6187,13 +6456,13 @@ function areCompatibleNodes(client, ssr, vnode, renderer) {
6187
6456
  if (!hasCorrectNodeType(vnode, ssr, 3 /* EnvNodeTypes.TEXT */, renderer)) {
6188
6457
  return false;
6189
6458
  }
6190
- return getProperty(client, 'nodeValue') === getProperty(ssr, 'nodeValue');
6459
+ return getProperty(client, NODE_VALUE_PROP) === getProperty(ssr, NODE_VALUE_PROP);
6191
6460
  }
6192
6461
  if (getProperty(client, 'nodeType') === 8 /* EnvNodeTypes.COMMENT */) {
6193
6462
  if (!hasCorrectNodeType(vnode, ssr, 8 /* EnvNodeTypes.COMMENT */, renderer)) {
6194
6463
  return false;
6195
6464
  }
6196
- return getProperty(client, 'nodeValue') === getProperty(ssr, 'nodeValue');
6465
+ return getProperty(client, NODE_VALUE_PROP) === getProperty(ssr, NODE_VALUE_PROP);
6197
6466
  }
6198
6467
  if (!hasCorrectNodeType(vnode, ssr, 1 /* EnvNodeTypes.ELEMENT */, renderer)) {
6199
6468
  return false;
@@ -6351,4 +6620,4 @@ function getComponentConstructor(elm) {
6351
6620
  }
6352
6621
 
6353
6622
  export { LightningElement, profilerControl as __unstable__ProfilerControl, api$1 as api, connectRootElement, createContextProvider, createVM, disconnectRootElement, freezeTemplate, getAssociatedVMIfPresent, getComponentConstructor, getComponentDef, getComponentHtmlPrototype, getUpgradableConstructor, hydrateRoot, isComponentConstructor, parseFragment, parseSVGFragment, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setHooks, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
6354
- /* version: 2.23.1 */
6623
+ /* version: 2.23.2 */