@lwc/engine-core 5.1.0 → 5.1.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/framework/modules/attrs.d.ts +2 -1
- package/dist/framework/vnodes.d.ts +4 -0
- package/dist/index.cjs.js +47 -10
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +47 -10
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { RendererAPI } from '../renderer';
|
|
2
|
-
import { VBaseElement } from '../vnodes';
|
|
2
|
+
import { VBaseElement, VStatic } from '../vnodes';
|
|
3
3
|
export declare function patchAttributes(oldVnode: VBaseElement | null, vnode: VBaseElement, renderer: RendererAPI): void;
|
|
4
|
+
export declare function patchSlotAssignment(oldVnode: VBaseElement | VStatic | null, vnode: VBaseElement | VStatic, renderer: RendererAPI): void;
|
|
@@ -40,6 +40,7 @@ export interface VStatic extends BaseVNode {
|
|
|
40
40
|
readonly fragment: Element;
|
|
41
41
|
readonly parts: VStaticPart[] | undefined;
|
|
42
42
|
elm: Element | undefined;
|
|
43
|
+
slotAssignment: string | undefined;
|
|
43
44
|
}
|
|
44
45
|
export interface VFragment extends BaseVNode, BaseVParent {
|
|
45
46
|
sel: undefined;
|
|
@@ -65,6 +66,7 @@ export interface VBaseElement extends BaseVNode, BaseVParent {
|
|
|
65
66
|
data: VElementData;
|
|
66
67
|
elm: Element | undefined;
|
|
67
68
|
key: Key;
|
|
69
|
+
slotAssignment: string | undefined;
|
|
68
70
|
}
|
|
69
71
|
export interface VElement extends VBaseElement {
|
|
70
72
|
type: VNodeType.Element;
|
|
@@ -93,9 +95,11 @@ export interface VElementData extends VNodeData {
|
|
|
93
95
|
readonly external?: boolean;
|
|
94
96
|
readonly ref?: string;
|
|
95
97
|
readonly slotData?: any;
|
|
98
|
+
readonly slotAssignment?: string;
|
|
96
99
|
}
|
|
97
100
|
export declare function isVBaseElement(vnode: VNode): vnode is VElement | VCustomElement;
|
|
98
101
|
export declare function isSameVnode(vnode1: VNode, vnode2: VNode): boolean;
|
|
99
102
|
export declare function isVCustomElement(vnode: VNode | VBaseElement): vnode is VCustomElement;
|
|
100
103
|
export declare function isVFragment(vnode: VNode): vnode is VFragment;
|
|
101
104
|
export declare function isVScopedSlotFragment(vnode: VNode): vnode is VScopedSlotFragment;
|
|
105
|
+
export declare function isVStatic(vnode: VNode): vnode is VStatic;
|
package/dist/index.cjs.js
CHANGED
|
@@ -3507,6 +3507,9 @@ function isVFragment(vnode) {
|
|
|
3507
3507
|
function isVScopedSlotFragment(vnode) {
|
|
3508
3508
|
return vnode.type === 6 /* VNodeType.ScopedSlotFragment */;
|
|
3509
3509
|
}
|
|
3510
|
+
function isVStatic(vnode) {
|
|
3511
|
+
return vnode.type === 4 /* VNodeType.Static */;
|
|
3512
|
+
}
|
|
3510
3513
|
|
|
3511
3514
|
/*
|
|
3512
3515
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
@@ -3555,6 +3558,19 @@ function patchAttributes(oldVnode, vnode, renderer) {
|
|
|
3555
3558
|
}
|
|
3556
3559
|
}
|
|
3557
3560
|
}
|
|
3561
|
+
function patchSlotAssignment(oldVnode, vnode, renderer) {
|
|
3562
|
+
if ((oldVnode === null || oldVnode === void 0 ? void 0 : oldVnode.slotAssignment) === vnode.slotAssignment) {
|
|
3563
|
+
return;
|
|
3564
|
+
}
|
|
3565
|
+
const { elm } = vnode;
|
|
3566
|
+
const { setAttribute, removeAttribute } = renderer;
|
|
3567
|
+
if (shared.isUndefined(vnode.slotAssignment) || shared.isNull(vnode.slotAssignment)) {
|
|
3568
|
+
removeAttribute(elm, 'slot');
|
|
3569
|
+
}
|
|
3570
|
+
else {
|
|
3571
|
+
setAttribute(elm, 'slot', vnode.slotAssignment);
|
|
3572
|
+
}
|
|
3573
|
+
}
|
|
3558
3574
|
|
|
3559
3575
|
/*
|
|
3560
3576
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
@@ -4004,6 +4020,8 @@ function mountElement(vnode, parent, anchor, renderer) {
|
|
|
4004
4020
|
}
|
|
4005
4021
|
function patchStatic(n1, n2, renderer) {
|
|
4006
4022
|
const elm = (n2.elm = n1.elm);
|
|
4023
|
+
// slotAssignments can only apply to the top level element, never to a static part.
|
|
4024
|
+
patchSlotAssignment(n1, n2, renderer);
|
|
4007
4025
|
// The `refs` object is blown away in every re-render, so we always need to re-apply them
|
|
4008
4026
|
applyStaticParts(elm, n2, renderer, false);
|
|
4009
4027
|
}
|
|
@@ -4025,6 +4043,8 @@ function mountStatic(vnode, parent, anchor, renderer) {
|
|
|
4025
4043
|
elm[shared.KEY__SHADOW_STATIC] = true;
|
|
4026
4044
|
}
|
|
4027
4045
|
}
|
|
4046
|
+
// slotAssignments can only apply to the top level element, never to a static part.
|
|
4047
|
+
patchSlotAssignment(null, vnode, renderer);
|
|
4028
4048
|
insertNode(elm, parent, anchor, renderer);
|
|
4029
4049
|
applyStaticParts(elm, vnode, renderer, true);
|
|
4030
4050
|
}
|
|
@@ -4250,6 +4270,7 @@ function patchElementPropsAndAttrsAndRefs$1(oldVnode, vnode, renderer) {
|
|
|
4250
4270
|
patchStyleAttribute(oldVnode, vnode, renderer);
|
|
4251
4271
|
patchAttributes(oldVnode, vnode, renderer);
|
|
4252
4272
|
patchProps(oldVnode, vnode, renderer);
|
|
4273
|
+
patchSlotAssignment(oldVnode, vnode, renderer);
|
|
4253
4274
|
// The `refs` object is blown away in every re-render, so we always need to re-apply them
|
|
4254
4275
|
applyRefs(vnode, vnode.owner);
|
|
4255
4276
|
}
|
|
@@ -4403,7 +4424,7 @@ function createViewModelHook(elm, vnode, renderer) {
|
|
|
4403
4424
|
return vm;
|
|
4404
4425
|
}
|
|
4405
4426
|
function allocateInSlot(vm, children, owner) {
|
|
4406
|
-
var _a
|
|
4427
|
+
var _a;
|
|
4407
4428
|
const { cmpSlots: { slotAssignments: oldSlotsMapping }, } = vm;
|
|
4408
4429
|
const cmpSlotsMapping = shared.create(null);
|
|
4409
4430
|
// Collect all slots into cmpSlotsMapping
|
|
@@ -4413,8 +4434,8 @@ function allocateInSlot(vm, children, owner) {
|
|
|
4413
4434
|
continue;
|
|
4414
4435
|
}
|
|
4415
4436
|
let slotName = '';
|
|
4416
|
-
if (isVBaseElement(vnode)) {
|
|
4417
|
-
slotName = (
|
|
4437
|
+
if (isVBaseElement(vnode) || isVStatic(vnode)) {
|
|
4438
|
+
slotName = (_a = vnode.slotAssignment) !== null && _a !== void 0 ? _a : '';
|
|
4418
4439
|
}
|
|
4419
4440
|
else if (isVScopedSlotFragment(vnode)) {
|
|
4420
4441
|
slotName = vnode.slotName;
|
|
@@ -4684,6 +4705,7 @@ function st(fragment, key, parts) {
|
|
|
4684
4705
|
fragment,
|
|
4685
4706
|
owner,
|
|
4686
4707
|
parts,
|
|
4708
|
+
slotAssignment: undefined,
|
|
4687
4709
|
};
|
|
4688
4710
|
return vnode;
|
|
4689
4711
|
}
|
|
@@ -4728,7 +4750,7 @@ function h(sel, data, children = EmptyArray) {
|
|
|
4728
4750
|
}
|
|
4729
4751
|
});
|
|
4730
4752
|
}
|
|
4731
|
-
const { key } = data;
|
|
4753
|
+
const { key, slotAssignment } = data;
|
|
4732
4754
|
const vnode = {
|
|
4733
4755
|
type: 2 /* VNodeType.Element */,
|
|
4734
4756
|
sel,
|
|
@@ -4737,6 +4759,7 @@ function h(sel, data, children = EmptyArray) {
|
|
|
4737
4759
|
elm: undefined,
|
|
4738
4760
|
key,
|
|
4739
4761
|
owner: vmBeingRendered,
|
|
4762
|
+
slotAssignment,
|
|
4740
4763
|
};
|
|
4741
4764
|
return vnode;
|
|
4742
4765
|
}
|
|
@@ -4761,6 +4784,8 @@ function s(slotName, data, children, slotset) {
|
|
|
4761
4784
|
shared.assert.isTrue(shared.isObject(data), `s() 2nd argument data must be an object.`);
|
|
4762
4785
|
shared.assert.isTrue(shared.isArray(children), `h() 3rd argument children must be an array.`);
|
|
4763
4786
|
}
|
|
4787
|
+
const vmBeingRendered = getVMBeingRendered();
|
|
4788
|
+
const { renderMode } = vmBeingRendered;
|
|
4764
4789
|
if (!shared.isUndefined(slotset) &&
|
|
4765
4790
|
!shared.isUndefined(slotset.slotAssignments) &&
|
|
4766
4791
|
!shared.isUndefined(slotset.slotAssignments[slotName]) &&
|
|
@@ -4783,7 +4808,6 @@ function s(slotName, data, children, slotset) {
|
|
|
4783
4808
|
}
|
|
4784
4809
|
// If the passed slot content is factory, evaluate it and add the produced vnodes
|
|
4785
4810
|
if (assignedNodeIsScopedSlot) {
|
|
4786
|
-
const vmBeingRenderedInception = getVMBeingRendered();
|
|
4787
4811
|
// Evaluate in the scope of the slot content's owner
|
|
4788
4812
|
// if a slotset is provided, there will always be an owner. The only case where owner is
|
|
4789
4813
|
// undefined is for root components, but root components cannot accept slotted content
|
|
@@ -4797,20 +4821,32 @@ function s(slotName, data, children, slotset) {
|
|
|
4797
4821
|
});
|
|
4798
4822
|
}
|
|
4799
4823
|
finally {
|
|
4800
|
-
setVMBeingRendered(
|
|
4824
|
+
setVMBeingRendered(vmBeingRendered);
|
|
4801
4825
|
}
|
|
4802
4826
|
}
|
|
4803
4827
|
else {
|
|
4828
|
+
// This block is for standard slots (non-scoped slots)
|
|
4829
|
+
let clonedVNode;
|
|
4830
|
+
if (renderMode === 0 /* RenderMode.Light */ &&
|
|
4831
|
+
(isVBaseElement(vnode) || isVStatic(vnode)) &&
|
|
4832
|
+
// We only need to copy the vnodes when the slot assignment changes, copying every time causes issues with
|
|
4833
|
+
// disconnected/connected callback firing.
|
|
4834
|
+
vnode.slotAssignment !== data.slotAssignment) {
|
|
4835
|
+
// When the light DOM slot assignment (slot attribute) changes we can't use the same reference
|
|
4836
|
+
// to the vnode because the current way the diffing algo works, it will replace the original reference
|
|
4837
|
+
// to the host element with a new one. This means the new element will be mounted and immediately unmounted.
|
|
4838
|
+
// Creating a copy of the vnode to preserve a reference to the previous host element.
|
|
4839
|
+
clonedVNode = Object.assign(Object.assign({}, vnode), { slotAssignment: data.slotAssignment });
|
|
4840
|
+
}
|
|
4804
4841
|
// If the slot content is standard type, the content is static, no additional
|
|
4805
4842
|
// processing needed on the vnode
|
|
4806
|
-
shared.ArrayPush.call(newChildren, vnode);
|
|
4843
|
+
shared.ArrayPush.call(newChildren, clonedVNode !== null && clonedVNode !== void 0 ? clonedVNode : vnode);
|
|
4807
4844
|
}
|
|
4808
4845
|
}
|
|
4809
4846
|
}
|
|
4810
4847
|
children = newChildren;
|
|
4811
4848
|
}
|
|
4812
|
-
const
|
|
4813
|
-
const { renderMode, shadowMode, apiVersion } = vmBeingRendered;
|
|
4849
|
+
const { shadowMode, apiVersion } = vmBeingRendered;
|
|
4814
4850
|
if (renderMode === 0 /* RenderMode.Light */) {
|
|
4815
4851
|
// light DOM slots - backwards-compatible behavior uses flattening, new behavior uses fragments
|
|
4816
4852
|
if (shared.isAPIFeatureEnabled(2 /* APIFeature.USE_FRAGMENTS_FOR_LIGHT_DOM_SLOTS */, apiVersion)) {
|
|
@@ -4852,7 +4888,7 @@ function c(sel, Ctor, data, children = EmptyArray) {
|
|
|
4852
4888
|
});
|
|
4853
4889
|
}
|
|
4854
4890
|
}
|
|
4855
|
-
const { key } = data;
|
|
4891
|
+
const { key, slotAssignment } = data;
|
|
4856
4892
|
let elm, aChildren, vm;
|
|
4857
4893
|
const vnode = {
|
|
4858
4894
|
type: 3 /* VNodeType.CustomElement */,
|
|
@@ -4861,6 +4897,7 @@ function c(sel, Ctor, data, children = EmptyArray) {
|
|
|
4861
4897
|
children,
|
|
4862
4898
|
elm,
|
|
4863
4899
|
key,
|
|
4900
|
+
slotAssignment,
|
|
4864
4901
|
ctor: Ctor,
|
|
4865
4902
|
owner: vmBeingRendered,
|
|
4866
4903
|
mode: 'open',
|