@lwc/engine-core 2.3.4 → 2.5.1
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/engine-core.cjs.js +287 -140
- package/dist/engine-core.js +288 -141
- package/package.json +4 -4
- package/types/framework/renderer.d.ts +3 -1
- package/types/framework/stylesheet.d.ts +2 -2
- package/types/framework/template.d.ts +3 -11
- package/types/framework/vm.d.ts +8 -4
package/dist/engine-core.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* proxy-compat-disable */
|
|
2
|
-
import { seal, create, isFunction as isFunction$1, ArrayPush as ArrayPush$1, isUndefined as isUndefined$1, ArrayIndexOf, ArraySplice, StringToLowerCase, ArrayJoin, isNull, assign, assert, keys, StringCharCodeAt, isString, StringSlice, freeze, defineProperties, forEach, getOwnPropertyNames as getOwnPropertyNames$1, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, getPropertyDescriptor, isObject, AriaPropNameToAttrNameMap, defineProperty, KEY__SYNTHETIC_MODE, toString as toString$1, isFalse, isTrue, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, htmlPropertyToAttribute, ArraySlice, hasOwnProperty as hasOwnProperty$1, noop, isArray as isArray$1, isNumber, StringReplace, KEY__SHADOW_RESOLVER, ArrayUnshift, isFrozen
|
|
2
|
+
import { seal, create, isFunction as isFunction$1, ArrayPush as ArrayPush$1, isUndefined as isUndefined$1, ArrayIndexOf, ArraySplice, StringToLowerCase, ArrayJoin, isNull, assign, assert, keys, StringCharCodeAt, isString, StringSlice, freeze, defineProperties, forEach, getOwnPropertyNames as getOwnPropertyNames$1, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, getPropertyDescriptor, isObject, AriaPropNameToAttrNameMap, defineProperty, KEY__SYNTHETIC_MODE, toString as toString$1, isFalse, isTrue, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, htmlPropertyToAttribute, ArraySlice, hasOwnProperty as hasOwnProperty$1, noop, isArray as isArray$1, isNumber, StringReplace, KEY__SHADOW_RESOLVER, KEY__SCOPED_CSS, ArrayUnshift, isFrozen } from '@lwc/shared';
|
|
3
3
|
import { runtimeFlags } from '@lwc/features';
|
|
4
4
|
export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
|
|
5
5
|
|
|
@@ -2309,12 +2309,6 @@ const LightningElement = function () {
|
|
|
2309
2309
|
associateVM(component, vm);
|
|
2310
2310
|
associateVM(elm, vm);
|
|
2311
2311
|
|
|
2312
|
-
if (!runtimeFlags.ENABLE_LIGHT_DOM_COMPONENTS) {
|
|
2313
|
-
assert.isTrue(def.renderMode !== 0
|
|
2314
|
-
/* Light */
|
|
2315
|
-
, `${def.name || 'Anonymous class'} is an invalid LWC component. Light DOM components are not available in this environment.`);
|
|
2316
|
-
}
|
|
2317
|
-
|
|
2318
2312
|
if (vm.renderMode === 1
|
|
2319
2313
|
/* Shadow */
|
|
2320
2314
|
) {
|
|
@@ -2353,6 +2347,12 @@ function attachShadow(vm) {
|
|
|
2353
2347
|
if (process.env.NODE_ENV !== 'production') {
|
|
2354
2348
|
patchShadowRootWithRestrictions(cmpRoot);
|
|
2355
2349
|
}
|
|
2350
|
+
}
|
|
2351
|
+
|
|
2352
|
+
function warnIfInvokedDuringConstruction(vm, methodName) {
|
|
2353
|
+
if (isBeingConstructed(vm)) {
|
|
2354
|
+
logError(`this.${methodName}() should not be called during the construction of the custom element for ${getComponentTag(vm)} because the element is not yet in the DOM or has no children yet.`);
|
|
2355
|
+
}
|
|
2356
2356
|
} // @ts-ignore
|
|
2357
2357
|
|
|
2358
2358
|
|
|
@@ -2511,7 +2511,7 @@ LightningElement.prototype = {
|
|
|
2511
2511
|
} = vm;
|
|
2512
2512
|
|
|
2513
2513
|
if (process.env.NODE_ENV !== 'production') {
|
|
2514
|
-
|
|
2514
|
+
warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect');
|
|
2515
2515
|
}
|
|
2516
2516
|
|
|
2517
2517
|
return getBoundingClientRect(elm);
|
|
@@ -2527,7 +2527,7 @@ LightningElement.prototype = {
|
|
|
2527
2527
|
} = vm;
|
|
2528
2528
|
|
|
2529
2529
|
if (process.env.NODE_ENV !== 'production') {
|
|
2530
|
-
|
|
2530
|
+
warnIfInvokedDuringConstruction(vm, 'querySelector');
|
|
2531
2531
|
}
|
|
2532
2532
|
|
|
2533
2533
|
return querySelector(elm, selectors);
|
|
@@ -2543,7 +2543,7 @@ LightningElement.prototype = {
|
|
|
2543
2543
|
} = vm;
|
|
2544
2544
|
|
|
2545
2545
|
if (process.env.NODE_ENV !== 'production') {
|
|
2546
|
-
|
|
2546
|
+
warnIfInvokedDuringConstruction(vm, 'querySelectorAll');
|
|
2547
2547
|
}
|
|
2548
2548
|
|
|
2549
2549
|
return querySelectorAll(elm, selectors);
|
|
@@ -2559,7 +2559,7 @@ LightningElement.prototype = {
|
|
|
2559
2559
|
} = vm;
|
|
2560
2560
|
|
|
2561
2561
|
if (process.env.NODE_ENV !== 'production') {
|
|
2562
|
-
|
|
2562
|
+
warnIfInvokedDuringConstruction(vm, 'getElementsByTagName');
|
|
2563
2563
|
}
|
|
2564
2564
|
|
|
2565
2565
|
return getElementsByTagName(elm, tagNameOrWildCard);
|
|
@@ -2575,7 +2575,7 @@ LightningElement.prototype = {
|
|
|
2575
2575
|
} = vm;
|
|
2576
2576
|
|
|
2577
2577
|
if (process.env.NODE_ENV !== 'production') {
|
|
2578
|
-
|
|
2578
|
+
warnIfInvokedDuringConstruction(vm, 'getElementsByClassName');
|
|
2579
2579
|
}
|
|
2580
2580
|
|
|
2581
2581
|
return getElementsByClassName(elm, names);
|
|
@@ -2940,18 +2940,33 @@ function createObservedFieldPropertyDescriptor(key) {
|
|
|
2940
2940
|
|
|
2941
2941
|
function getClassDescriptorType(descriptor) {
|
|
2942
2942
|
if (isFunction$1(descriptor.value)) {
|
|
2943
|
-
return
|
|
2943
|
+
return "method"
|
|
2944
|
+
/* Method */
|
|
2945
|
+
;
|
|
2944
2946
|
} else if (isFunction$1(descriptor.set) || isFunction$1(descriptor.get)) {
|
|
2945
|
-
return
|
|
2947
|
+
return "accessor"
|
|
2948
|
+
/* Accessor */
|
|
2949
|
+
;
|
|
2946
2950
|
} else {
|
|
2947
|
-
return
|
|
2951
|
+
return "field"
|
|
2952
|
+
/* Field */
|
|
2953
|
+
;
|
|
2948
2954
|
}
|
|
2949
2955
|
}
|
|
2950
2956
|
|
|
2951
2957
|
function validateObservedField(Ctor, fieldName, descriptor) {
|
|
2952
2958
|
if (!isUndefined$1(descriptor)) {
|
|
2953
2959
|
const type = getClassDescriptorType(descriptor);
|
|
2954
|
-
|
|
2960
|
+
const message = `Invalid observed ${fieldName} field. Found a duplicate ${type} with the same name.`; // [W-9927596] Ideally we always throw an error when detecting duplicate observed field.
|
|
2961
|
+
// This branch is only here for backward compatibility reasons.
|
|
2962
|
+
|
|
2963
|
+
if (type === "accessor"
|
|
2964
|
+
/* Accessor */
|
|
2965
|
+
) {
|
|
2966
|
+
logError(message);
|
|
2967
|
+
} else {
|
|
2968
|
+
assert.fail(message);
|
|
2969
|
+
}
|
|
2955
2970
|
}
|
|
2956
2971
|
}
|
|
2957
2972
|
|
|
@@ -2978,7 +2993,16 @@ function validateMethodDecoratedWithWire(Ctor, methodName, descriptor) {
|
|
|
2978
2993
|
function validateFieldDecoratedWithApi(Ctor, fieldName, descriptor) {
|
|
2979
2994
|
if (!isUndefined$1(descriptor)) {
|
|
2980
2995
|
const type = getClassDescriptorType(descriptor);
|
|
2981
|
-
|
|
2996
|
+
const message = `Invalid @api ${fieldName} field. Found a duplicate ${type} with the same name.`; // [W-9927596] Ideally we always throw an error when detecting duplicate public properties.
|
|
2997
|
+
// This branch is only here for backward compatibility reasons.
|
|
2998
|
+
|
|
2999
|
+
if (type === "accessor"
|
|
3000
|
+
/* Accessor */
|
|
3001
|
+
) {
|
|
3002
|
+
logError(message);
|
|
3003
|
+
} else {
|
|
3004
|
+
assert.fail(message);
|
|
3005
|
+
}
|
|
2982
3006
|
}
|
|
2983
3007
|
}
|
|
2984
3008
|
|
|
@@ -3041,9 +3065,16 @@ function registerDecorators(Ctor, meta) {
|
|
|
3041
3065
|
// field declaration
|
|
3042
3066
|
if (process.env.NODE_ENV !== 'production') {
|
|
3043
3067
|
validateFieldDecoratedWithApi(Ctor, fieldName, descriptor);
|
|
3044
|
-
}
|
|
3068
|
+
} // [W-9927596] If a component has both a public property and a private setter/getter
|
|
3069
|
+
// with the same name, the property is defined as a public accessor. This branch is
|
|
3070
|
+
// only here for backward compatibility reasons.
|
|
3071
|
+
|
|
3045
3072
|
|
|
3046
|
-
descriptor
|
|
3073
|
+
if (!isUndefined$1(descriptor) && !isUndefined$1(descriptor.get)) {
|
|
3074
|
+
descriptor = createPublicAccessorDescriptor(fieldName, descriptor);
|
|
3075
|
+
} else {
|
|
3076
|
+
descriptor = createPublicPropertyDescriptor(fieldName);
|
|
3077
|
+
}
|
|
3047
3078
|
}
|
|
3048
3079
|
|
|
3049
3080
|
apiFields[fieldName] = descriptor;
|
|
@@ -3123,9 +3154,16 @@ function registerDecorators(Ctor, meta) {
|
|
|
3123
3154
|
|
|
3124
3155
|
if (process.env.NODE_ENV !== 'production') {
|
|
3125
3156
|
validateObservedField(Ctor, fieldName, descriptor);
|
|
3126
|
-
}
|
|
3157
|
+
} // [W-9927596] Only mark a field as observed whenever it isn't a duplicated public nor
|
|
3158
|
+
// tracked property. This is only here for backward compatibility purposes.
|
|
3159
|
+
|
|
3160
|
+
|
|
3161
|
+
const isDuplicatePublicProp = !isUndefined$1(publicProps) && fieldName in publicProps;
|
|
3162
|
+
const isDuplicateTrackedProp = !isUndefined$1(track) && fieldName in track;
|
|
3127
3163
|
|
|
3128
|
-
|
|
3164
|
+
if (!isDuplicatePublicProp && !isDuplicateTrackedProp) {
|
|
3165
|
+
observedFields[fieldName] = createObservedFieldPropertyDescriptor(fieldName);
|
|
3166
|
+
}
|
|
3129
3167
|
}
|
|
3130
3168
|
}
|
|
3131
3169
|
|
|
@@ -3957,6 +3995,19 @@ function observeElementChildNodes(elm) {
|
|
|
3957
3995
|
|
|
3958
3996
|
function setElementShadowToken(elm, token) {
|
|
3959
3997
|
elm.$shadowToken$ = token;
|
|
3998
|
+
} // Set the scope token class for *.scoped.css styles
|
|
3999
|
+
|
|
4000
|
+
|
|
4001
|
+
function setScopeTokenClassIfNecessary(elm, owner) {
|
|
4002
|
+
const {
|
|
4003
|
+
cmpTemplate,
|
|
4004
|
+
context
|
|
4005
|
+
} = owner;
|
|
4006
|
+
const token = cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken;
|
|
4007
|
+
|
|
4008
|
+
if (!isUndefined$1(token) && context.hasScopedStyles) {
|
|
4009
|
+
owner.renderer.getClassList(elm).add(token);
|
|
4010
|
+
}
|
|
3960
4011
|
}
|
|
3961
4012
|
|
|
3962
4013
|
function updateNodeHook(oldVnode, vnode) {
|
|
@@ -4026,6 +4077,7 @@ function fallbackElmHook(elm, vnode) {
|
|
|
4026
4077
|
const {
|
|
4027
4078
|
owner
|
|
4028
4079
|
} = vnode;
|
|
4080
|
+
setScopeTokenClassIfNecessary(elm, owner);
|
|
4029
4081
|
|
|
4030
4082
|
if (owner.shadowMode === 1
|
|
4031
4083
|
/* Synthetic */
|
|
@@ -4036,7 +4088,7 @@ function fallbackElmHook(elm, vnode) {
|
|
|
4036
4088
|
}
|
|
4037
4089
|
} = vnode;
|
|
4038
4090
|
const {
|
|
4039
|
-
|
|
4091
|
+
stylesheetToken
|
|
4040
4092
|
} = owner.context;
|
|
4041
4093
|
|
|
4042
4094
|
if (!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
|
|
@@ -4048,7 +4100,7 @@ function fallbackElmHook(elm, vnode) {
|
|
|
4048
4100
|
// into each element from the template, so they can be styled accordingly.
|
|
4049
4101
|
|
|
4050
4102
|
|
|
4051
|
-
setElementShadowToken(elm,
|
|
4103
|
+
setElementShadowToken(elm, stylesheetToken);
|
|
4052
4104
|
}
|
|
4053
4105
|
|
|
4054
4106
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -4133,16 +4185,17 @@ function createViewModelHook(elm, vnode) {
|
|
|
4133
4185
|
ctor,
|
|
4134
4186
|
owner
|
|
4135
4187
|
} = vnode;
|
|
4188
|
+
setScopeTokenClassIfNecessary(elm, owner);
|
|
4136
4189
|
|
|
4137
4190
|
if (owner.shadowMode === 1
|
|
4138
4191
|
/* Synthetic */
|
|
4139
4192
|
) {
|
|
4140
4193
|
const {
|
|
4141
|
-
|
|
4194
|
+
stylesheetToken
|
|
4142
4195
|
} = owner.context; // when running in synthetic shadow mode, we need to set the shadowToken value
|
|
4143
4196
|
// into each element from the template, so they can be styled accordingly.
|
|
4144
4197
|
|
|
4145
|
-
setElementShadowToken(elm,
|
|
4198
|
+
setElementShadowToken(elm, stylesheetToken);
|
|
4146
4199
|
}
|
|
4147
4200
|
|
|
4148
4201
|
const def = getComponentInternalDef(ctor);
|
|
@@ -4434,13 +4487,19 @@ const CustomElementHook = {
|
|
|
4434
4487
|
|
|
4435
4488
|
function linkNodeToShadow(elm, owner) {
|
|
4436
4489
|
const {
|
|
4490
|
+
renderer,
|
|
4491
|
+
renderMode,
|
|
4437
4492
|
shadowMode
|
|
4438
4493
|
} = owner; // TODO [#1164]: this should eventually be done by the polyfill directly
|
|
4439
4494
|
|
|
4440
|
-
if (
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4495
|
+
if (renderer.isSyntheticShadowDefined) {
|
|
4496
|
+
if (shadowMode === 1
|
|
4497
|
+
/* Synthetic */
|
|
4498
|
+
|| renderMode === 0
|
|
4499
|
+
/* Light */
|
|
4500
|
+
) {
|
|
4501
|
+
elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
|
|
4502
|
+
}
|
|
4444
4503
|
}
|
|
4445
4504
|
}
|
|
4446
4505
|
|
|
@@ -4775,14 +4834,11 @@ function gid(id) {
|
|
|
4775
4834
|
|
|
4776
4835
|
const {
|
|
4777
4836
|
idx,
|
|
4778
|
-
renderMode,
|
|
4779
4837
|
shadowMode
|
|
4780
4838
|
} = vmBeingRendered;
|
|
4781
4839
|
|
|
4782
4840
|
if (shadowMode === 1
|
|
4783
4841
|
/* Synthetic */
|
|
4784
|
-
&& renderMode === 1
|
|
4785
|
-
/* Shadow */
|
|
4786
4842
|
) {
|
|
4787
4843
|
return StringReplace.call(id, /\S+/g, id => `${id}-${idx}`);
|
|
4788
4844
|
}
|
|
@@ -4810,14 +4866,11 @@ function fid(url) {
|
|
|
4810
4866
|
|
|
4811
4867
|
const {
|
|
4812
4868
|
idx,
|
|
4813
|
-
renderMode,
|
|
4814
4869
|
shadowMode
|
|
4815
4870
|
} = vmBeingRendered; // Apply transformation only for fragment-only-urls, and only in shadow DOM
|
|
4816
4871
|
|
|
4817
4872
|
if (shadowMode === 1
|
|
4818
4873
|
/* Synthetic */
|
|
4819
|
-
&& renderMode === 1
|
|
4820
|
-
/* Shadow */
|
|
4821
4874
|
&& /^#/.test(url)) {
|
|
4822
4875
|
return `${url}-${idx}`;
|
|
4823
4876
|
}
|
|
@@ -4917,6 +4970,10 @@ var api = /*#__PURE__*/Object.freeze({
|
|
|
4917
4970
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
4918
4971
|
*/
|
|
4919
4972
|
|
|
4973
|
+
function makeHostToken(token) {
|
|
4974
|
+
return `${token}-host`;
|
|
4975
|
+
}
|
|
4976
|
+
|
|
4920
4977
|
function createInlineStyleVNode(content) {
|
|
4921
4978
|
return h('style', {
|
|
4922
4979
|
key: 'style',
|
|
@@ -4926,59 +4983,100 @@ function createInlineStyleVNode(content) {
|
|
|
4926
4983
|
}, [t(content)]);
|
|
4927
4984
|
}
|
|
4928
4985
|
|
|
4929
|
-
function
|
|
4986
|
+
function updateStylesheetToken(vm, template) {
|
|
4930
4987
|
const {
|
|
4931
4988
|
elm,
|
|
4932
4989
|
context,
|
|
4933
4990
|
renderer,
|
|
4934
|
-
renderMode
|
|
4991
|
+
renderMode,
|
|
4992
|
+
shadowMode
|
|
4935
4993
|
} = vm;
|
|
4936
4994
|
const {
|
|
4937
4995
|
stylesheets: newStylesheets,
|
|
4938
|
-
|
|
4996
|
+
stylesheetToken: newStylesheetToken
|
|
4939
4997
|
} = template;
|
|
4940
|
-
|
|
4998
|
+
const isSyntheticShadow = renderMode === 1
|
|
4999
|
+
/* Shadow */
|
|
5000
|
+
&& shadowMode === 1
|
|
5001
|
+
/* Synthetic */
|
|
5002
|
+
;
|
|
5003
|
+
const {
|
|
5004
|
+
hasScopedStyles
|
|
5005
|
+
} = context;
|
|
5006
|
+
let newToken;
|
|
5007
|
+
let newHasTokenInClass;
|
|
5008
|
+
let newHasTokenInAttribute; // Reset the styling token applied to the host element.
|
|
4941
5009
|
|
|
4942
|
-
const
|
|
5010
|
+
const {
|
|
5011
|
+
stylesheetToken: oldToken,
|
|
5012
|
+
hasTokenInClass: oldHasTokenInClass,
|
|
5013
|
+
hasTokenInAttribute: oldHasTokenInAttribute
|
|
5014
|
+
} = context;
|
|
5015
|
+
|
|
5016
|
+
if (oldHasTokenInClass) {
|
|
5017
|
+
renderer.getClassList(elm).remove(makeHostToken(oldToken));
|
|
5018
|
+
}
|
|
4943
5019
|
|
|
4944
|
-
if (
|
|
4945
|
-
renderer.removeAttribute(elm,
|
|
5020
|
+
if (oldHasTokenInAttribute) {
|
|
5021
|
+
renderer.removeAttribute(elm, makeHostToken(oldToken));
|
|
4946
5022
|
} // Apply the new template styling token to the host element, if the new template has any
|
|
4947
|
-
// associated stylesheets.
|
|
5023
|
+
// associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
|
|
4948
5024
|
|
|
4949
5025
|
|
|
4950
|
-
if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
}
|
|
5026
|
+
if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
|
|
5027
|
+
newToken = newStylesheetToken;
|
|
5028
|
+
} // Set the new styling token on the host element
|
|
5029
|
+
|
|
4955
5030
|
|
|
4956
|
-
if (!isUndefined$1(
|
|
4957
|
-
|
|
5031
|
+
if (!isUndefined$1(newToken)) {
|
|
5032
|
+
if (hasScopedStyles) {
|
|
5033
|
+
renderer.getClassList(elm).add(makeHostToken(newToken));
|
|
5034
|
+
newHasTokenInClass = true;
|
|
5035
|
+
}
|
|
5036
|
+
|
|
5037
|
+
if (isSyntheticShadow) {
|
|
5038
|
+
renderer.setAttribute(elm, makeHostToken(newToken), '');
|
|
5039
|
+
newHasTokenInAttribute = true;
|
|
5040
|
+
}
|
|
4958
5041
|
} // Update the styling tokens present on the context object.
|
|
4959
5042
|
|
|
4960
5043
|
|
|
4961
|
-
context.
|
|
4962
|
-
context.
|
|
5044
|
+
context.stylesheetToken = newToken;
|
|
5045
|
+
context.hasTokenInClass = newHasTokenInClass;
|
|
5046
|
+
context.hasTokenInAttribute = newHasTokenInAttribute;
|
|
4963
5047
|
}
|
|
4964
5048
|
|
|
4965
|
-
function evaluateStylesheetsContent(stylesheets,
|
|
5049
|
+
function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
|
|
4966
5050
|
const content = [];
|
|
4967
5051
|
|
|
4968
5052
|
for (let i = 0; i < stylesheets.length; i++) {
|
|
4969
5053
|
let stylesheet = stylesheets[i];
|
|
4970
5054
|
|
|
4971
5055
|
if (isArray$1(stylesheet)) {
|
|
4972
|
-
ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet,
|
|
5056
|
+
ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
|
|
4973
5057
|
} else {
|
|
4974
5058
|
if (process.env.NODE_ENV !== 'production') {
|
|
4975
5059
|
// in dev-mode, we support hot swapping of stylesheet, which means that
|
|
4976
5060
|
// the component instance might be attempting to use an old version of
|
|
4977
5061
|
// the stylesheet, while internally, we have a replacement for it.
|
|
4978
5062
|
stylesheet = getStyleOrSwappedStyle(stylesheet);
|
|
4979
|
-
}
|
|
5063
|
+
} // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
|
|
5064
|
+
// native shadow DOM. Synthetic shadow DOM never uses `:host`.
|
|
5065
|
+
|
|
5066
|
+
|
|
5067
|
+
const isScopedCss = stylesheet[KEY__SCOPED_CSS];
|
|
5068
|
+
const useActualHostSelector = vm.renderMode === 0
|
|
5069
|
+
/* Light */
|
|
5070
|
+
? !isScopedCss : vm.shadowMode === 0
|
|
5071
|
+
/* Native */
|
|
5072
|
+
; // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
|
|
4980
5073
|
|
|
4981
|
-
|
|
5074
|
+
const scopeToken = isScopedCss || vm.shadowMode === 1
|
|
5075
|
+
/* Synthetic */
|
|
5076
|
+
&& vm.renderMode === 1
|
|
5077
|
+
/* Shadow */
|
|
5078
|
+
? stylesheetToken : undefined;
|
|
5079
|
+
ArrayPush$1.call(content, stylesheet(useActualHostSelector, scopeToken));
|
|
4982
5080
|
}
|
|
4983
5081
|
}
|
|
4984
5082
|
|
|
@@ -4988,38 +5086,37 @@ function evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, n
|
|
|
4988
5086
|
function getStylesheetsContent(vm, template) {
|
|
4989
5087
|
const {
|
|
4990
5088
|
stylesheets,
|
|
4991
|
-
|
|
5089
|
+
stylesheetToken
|
|
4992
5090
|
} = template;
|
|
4993
|
-
const {
|
|
4994
|
-
renderMode,
|
|
4995
|
-
shadowMode
|
|
4996
|
-
} = vm;
|
|
4997
5091
|
let content = [];
|
|
4998
5092
|
|
|
4999
5093
|
if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5094
|
+
content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
|
|
5095
|
+
}
|
|
5096
|
+
|
|
5097
|
+
return content;
|
|
5098
|
+
} // It might be worth caching this to avoid doing the lookup repeatedly, but
|
|
5099
|
+
// perf testing has not shown it to be a huge improvement yet:
|
|
5100
|
+
// https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
|
|
5003
5101
|
|
|
5004
|
-
|
|
5102
|
+
function getNearestNativeShadowComponent(vm) {
|
|
5103
|
+
let owner = vm;
|
|
5104
|
+
|
|
5105
|
+
while (!isNull(owner)) {
|
|
5106
|
+
if (owner.renderMode === 1
|
|
5005
5107
|
/* Shadow */
|
|
5006
|
-
&& shadowMode ===
|
|
5007
|
-
/*
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
shadowSelector = `[${stylesheetTokens.shadowAttribute}]`;
|
|
5011
|
-
} else {
|
|
5012
|
-
hostSelector = '';
|
|
5013
|
-
shadowSelector = '';
|
|
5108
|
+
&& owner.shadowMode === 0
|
|
5109
|
+
/* Native */
|
|
5110
|
+
) {
|
|
5111
|
+
return owner;
|
|
5014
5112
|
}
|
|
5015
5113
|
|
|
5016
|
-
|
|
5017
|
-
/* Native */
|
|
5018
|
-
);
|
|
5114
|
+
owner = owner.owner;
|
|
5019
5115
|
}
|
|
5020
5116
|
|
|
5021
|
-
return
|
|
5117
|
+
return owner;
|
|
5022
5118
|
}
|
|
5119
|
+
|
|
5023
5120
|
function createStylesheet(vm, stylesheets) {
|
|
5024
5121
|
const {
|
|
5025
5122
|
renderer,
|
|
@@ -5035,13 +5132,26 @@ function createStylesheet(vm, stylesheets) {
|
|
|
5035
5132
|
for (let i = 0; i < stylesheets.length; i++) {
|
|
5036
5133
|
renderer.insertGlobalStylesheet(stylesheets[i]);
|
|
5037
5134
|
}
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
} else {
|
|
5041
|
-
// native shadow or light DOM
|
|
5135
|
+
} else if (renderer.ssr) {
|
|
5136
|
+
// native shadow or light DOM, SSR
|
|
5042
5137
|
const combinedStylesheetContent = ArrayJoin.call(stylesheets, '\n');
|
|
5043
5138
|
return createInlineStyleVNode(combinedStylesheetContent);
|
|
5139
|
+
} else {
|
|
5140
|
+
// native shadow or light DOM, DOM renderer
|
|
5141
|
+
const root = getNearestNativeShadowComponent(vm);
|
|
5142
|
+
const isGlobal = isNull(root);
|
|
5143
|
+
|
|
5144
|
+
for (let i = 0; i < stylesheets.length; i++) {
|
|
5145
|
+
if (isGlobal) {
|
|
5146
|
+
renderer.insertGlobalStylesheet(stylesheets[i]);
|
|
5147
|
+
} else {
|
|
5148
|
+
// local level
|
|
5149
|
+
renderer.insertStylesheet(stylesheets[i], root.cmpRoot);
|
|
5150
|
+
}
|
|
5151
|
+
}
|
|
5044
5152
|
}
|
|
5153
|
+
|
|
5154
|
+
return null;
|
|
5045
5155
|
}
|
|
5046
5156
|
|
|
5047
5157
|
/*
|
|
@@ -5239,8 +5349,7 @@ function evaluateTemplate(vm, html) {
|
|
|
5239
5349
|
context,
|
|
5240
5350
|
cmpSlots,
|
|
5241
5351
|
cmpTemplate,
|
|
5242
|
-
tro
|
|
5243
|
-
shadowMode
|
|
5352
|
+
tro
|
|
5244
5353
|
} = vm;
|
|
5245
5354
|
tro.observe(() => {
|
|
5246
5355
|
// Reset the cache memoizer for template when needed.
|
|
@@ -5265,15 +5374,12 @@ function evaluateTemplate(vm, html) {
|
|
|
5265
5374
|
|
|
5266
5375
|
vm.cmpTemplate = html; // Create a brand new template cache for the swapped templated.
|
|
5267
5376
|
|
|
5268
|
-
context.tplCache = create(null); //
|
|
5377
|
+
context.tplCache = create(null); // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
|
|
5269
5378
|
|
|
5270
|
-
|
|
5271
|
-
/* Synthetic */
|
|
5272
|
-
) {
|
|
5273
|
-
updateSyntheticShadowAttributes(vm, html);
|
|
5274
|
-
} // Evaluate, create stylesheet and cache the produced VNode for future
|
|
5275
|
-
// re-rendering.
|
|
5379
|
+
context.hasScopedStyles = computeHasScopedStyles(html); // Update the scoping token on the host element.
|
|
5276
5380
|
|
|
5381
|
+
updateStylesheetToken(vm, html); // Evaluate, create stylesheet and cache the produced VNode for future
|
|
5382
|
+
// re-rendering.
|
|
5277
5383
|
|
|
5278
5384
|
const stylesheetsContent = getStylesheetsContent(vm, html);
|
|
5279
5385
|
context.styleVNode = stylesheetsContent.length === 0 ? null : createStylesheet(vm, stylesheetsContent);
|
|
@@ -5315,6 +5421,21 @@ function evaluateTemplate(vm, html) {
|
|
|
5315
5421
|
|
|
5316
5422
|
return vnodes;
|
|
5317
5423
|
}
|
|
5424
|
+
function computeHasScopedStyles(template) {
|
|
5425
|
+
const {
|
|
5426
|
+
stylesheets
|
|
5427
|
+
} = template;
|
|
5428
|
+
|
|
5429
|
+
if (!isUndefined$1(stylesheets)) {
|
|
5430
|
+
for (let i = 0; i < stylesheets.length; i++) {
|
|
5431
|
+
if (isTrue(stylesheets[i][KEY__SCOPED_CSS])) {
|
|
5432
|
+
return true;
|
|
5433
|
+
}
|
|
5434
|
+
}
|
|
5435
|
+
}
|
|
5436
|
+
|
|
5437
|
+
return false;
|
|
5438
|
+
}
|
|
5318
5439
|
|
|
5319
5440
|
/*
|
|
5320
5441
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
@@ -5569,7 +5690,6 @@ function invokeServiceHook(vm, cbs) {
|
|
|
5569
5690
|
* SPDX-License-Identifier: MIT
|
|
5570
5691
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
5571
5692
|
*/
|
|
5572
|
-
const isNativeShadowRootDefined = globalThis$1[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED];
|
|
5573
5693
|
let idx = 0;
|
|
5574
5694
|
/** The internal slot used to associate different objects the engine manipulates with the VM */
|
|
5575
5695
|
|
|
@@ -5674,29 +5794,6 @@ function getNearestShadowAncestor(vm) {
|
|
|
5674
5794
|
return ancestor;
|
|
5675
5795
|
}
|
|
5676
5796
|
|
|
5677
|
-
function assertNotSyntheticComposedWithinNative(vm) {
|
|
5678
|
-
const isSynthetic = vm.renderMode === 1
|
|
5679
|
-
/* Shadow */
|
|
5680
|
-
&& vm.shadowMode === 1
|
|
5681
|
-
/* Synthetic */
|
|
5682
|
-
;
|
|
5683
|
-
|
|
5684
|
-
if (!isSynthetic) {
|
|
5685
|
-
return;
|
|
5686
|
-
}
|
|
5687
|
-
|
|
5688
|
-
const ancestor = getNearestShadowAncestor(vm);
|
|
5689
|
-
|
|
5690
|
-
if (!isNull(ancestor)) {
|
|
5691
|
-
// Any native shadow component being an ancestor of a synthetic shadow component is disallowed.
|
|
5692
|
-
assert.isFalse(ancestor.renderMode === 1
|
|
5693
|
-
/* Shadow */
|
|
5694
|
-
&& ancestor.shadowMode === 0
|
|
5695
|
-
/* Native */
|
|
5696
|
-
, `${getComponentTag(vm)} (synthetic shadow DOM) cannot be composed inside of ${getComponentTag(ancestor)} (native shadow DOM), because synthetic-within-native composition is disallowed`);
|
|
5697
|
-
}
|
|
5698
|
-
}
|
|
5699
|
-
|
|
5700
5797
|
function createVM(elm, def, options) {
|
|
5701
5798
|
const {
|
|
5702
5799
|
mode,
|
|
@@ -5704,22 +5801,6 @@ function createVM(elm, def, options) {
|
|
|
5704
5801
|
renderer,
|
|
5705
5802
|
tagName
|
|
5706
5803
|
} = options;
|
|
5707
|
-
let shadowMode;
|
|
5708
|
-
|
|
5709
|
-
if (renderer.syntheticShadow) {
|
|
5710
|
-
shadowMode = def.shadowSupportMode === "any"
|
|
5711
|
-
/* Any */
|
|
5712
|
-
&& isNativeShadowRootDefined ? 0
|
|
5713
|
-
/* Native */
|
|
5714
|
-
: 1
|
|
5715
|
-
/* Synthetic */
|
|
5716
|
-
;
|
|
5717
|
-
} else {
|
|
5718
|
-
shadowMode = 0
|
|
5719
|
-
/* Native */
|
|
5720
|
-
;
|
|
5721
|
-
}
|
|
5722
|
-
|
|
5723
5804
|
const vm = {
|
|
5724
5805
|
elm,
|
|
5725
5806
|
def,
|
|
@@ -5742,10 +5823,12 @@ function createVM(elm, def, options) {
|
|
|
5742
5823
|
oar: create(null),
|
|
5743
5824
|
cmpTemplate: null,
|
|
5744
5825
|
renderMode: def.renderMode,
|
|
5745
|
-
shadowMode,
|
|
5826
|
+
shadowMode: null,
|
|
5746
5827
|
context: {
|
|
5747
|
-
|
|
5748
|
-
|
|
5828
|
+
stylesheetToken: undefined,
|
|
5829
|
+
hasTokenInClass: undefined,
|
|
5830
|
+
hasTokenInAttribute: undefined,
|
|
5831
|
+
hasScopedStyles: undefined,
|
|
5749
5832
|
styleVNode: null,
|
|
5750
5833
|
tplCache: EmptyObject,
|
|
5751
5834
|
wiredConnecting: EmptyArray,
|
|
@@ -5758,26 +5841,87 @@ function createVM(elm, def, options) {
|
|
|
5758
5841
|
setHook,
|
|
5759
5842
|
getHook
|
|
5760
5843
|
};
|
|
5844
|
+
vm.shadowMode = computeShadowMode(vm);
|
|
5761
5845
|
vm.tro = getTemplateReactiveObserver(vm);
|
|
5762
5846
|
|
|
5763
5847
|
if (process.env.NODE_ENV !== 'production') {
|
|
5764
5848
|
vm.toString = () => {
|
|
5765
5849
|
return `[object:vm ${def.name} (${vm.idx})]`;
|
|
5766
5850
|
};
|
|
5767
|
-
|
|
5768
|
-
assertNotSyntheticComposedWithinNative(vm);
|
|
5769
5851
|
} // Create component instance associated to the vm and the element.
|
|
5770
5852
|
|
|
5771
5853
|
|
|
5772
5854
|
invokeComponentConstructor(vm, def.ctor); // Initializing the wire decorator per instance only when really needed
|
|
5773
5855
|
|
|
5774
|
-
if (
|
|
5856
|
+
if (hasWireAdapters(vm)) {
|
|
5775
5857
|
installWireAdapters(vm);
|
|
5776
5858
|
}
|
|
5777
5859
|
|
|
5778
5860
|
return vm;
|
|
5779
5861
|
}
|
|
5780
5862
|
|
|
5863
|
+
function computeShadowMode(vm) {
|
|
5864
|
+
const {
|
|
5865
|
+
def,
|
|
5866
|
+
renderer
|
|
5867
|
+
} = vm;
|
|
5868
|
+
const {
|
|
5869
|
+
isNativeShadowDefined,
|
|
5870
|
+
isSyntheticShadowDefined
|
|
5871
|
+
} = renderer;
|
|
5872
|
+
let shadowMode;
|
|
5873
|
+
|
|
5874
|
+
if (isSyntheticShadowDefined) {
|
|
5875
|
+
if (def.renderMode === 0
|
|
5876
|
+
/* Light */
|
|
5877
|
+
) {
|
|
5878
|
+
// ShadowMode.Native implies "not synthetic shadow" which is consistent with how
|
|
5879
|
+
// everything defaults to native when the synthetic shadow polyfill is unavailable.
|
|
5880
|
+
shadowMode = 0
|
|
5881
|
+
/* Native */
|
|
5882
|
+
;
|
|
5883
|
+
} else if (isNativeShadowDefined) {
|
|
5884
|
+
if (def.shadowSupportMode === "any"
|
|
5885
|
+
/* Any */
|
|
5886
|
+
) {
|
|
5887
|
+
shadowMode = 0
|
|
5888
|
+
/* Native */
|
|
5889
|
+
;
|
|
5890
|
+
} else {
|
|
5891
|
+
const shadowAncestor = getNearestShadowAncestor(vm);
|
|
5892
|
+
|
|
5893
|
+
if (!isNull(shadowAncestor) && shadowAncestor.shadowMode === 0
|
|
5894
|
+
/* Native */
|
|
5895
|
+
) {
|
|
5896
|
+
// Transitive support for native Shadow DOM. A component in native mode
|
|
5897
|
+
// transitively opts all of its descendants into native.
|
|
5898
|
+
shadowMode = 0
|
|
5899
|
+
/* Native */
|
|
5900
|
+
;
|
|
5901
|
+
} else {
|
|
5902
|
+
// Synthetic if neither this component nor any of its ancestors are configured
|
|
5903
|
+
// to be native.
|
|
5904
|
+
shadowMode = 1
|
|
5905
|
+
/* Synthetic */
|
|
5906
|
+
;
|
|
5907
|
+
}
|
|
5908
|
+
}
|
|
5909
|
+
} else {
|
|
5910
|
+
// Synthetic if there is no native Shadow DOM support.
|
|
5911
|
+
shadowMode = 1
|
|
5912
|
+
/* Synthetic */
|
|
5913
|
+
;
|
|
5914
|
+
}
|
|
5915
|
+
} else {
|
|
5916
|
+
// Native if the synthetic shadow polyfill is unavailable.
|
|
5917
|
+
shadowMode = 0
|
|
5918
|
+
/* Native */
|
|
5919
|
+
;
|
|
5920
|
+
}
|
|
5921
|
+
|
|
5922
|
+
return shadowMode;
|
|
5923
|
+
}
|
|
5924
|
+
|
|
5781
5925
|
function assertIsVM(obj) {
|
|
5782
5926
|
if (isNull(obj) || !isObject(obj) || !('cmpRoot' in obj)) {
|
|
5783
5927
|
throw new TypeError(`${obj} is not a VM.`);
|
|
@@ -6506,11 +6650,14 @@ function installWireAdapters(vm) {
|
|
|
6506
6650
|
ArrayPush$1.call(wiredConnecting, () => {
|
|
6507
6651
|
connector.connect();
|
|
6508
6652
|
|
|
6509
|
-
if (
|
|
6510
|
-
|
|
6511
|
-
|
|
6512
|
-
|
|
6653
|
+
if (!runtimeFlags.ENABLE_WIRE_SYNC_EMIT) {
|
|
6654
|
+
if (hasDynamicParams) {
|
|
6655
|
+
Promise.resolve().then(computeConfigAndUpdate);
|
|
6656
|
+
return;
|
|
6657
|
+
}
|
|
6513
6658
|
}
|
|
6659
|
+
|
|
6660
|
+
computeConfigAndUpdate();
|
|
6514
6661
|
});
|
|
6515
6662
|
ArrayPush$1.call(wiredDisconnecting, () => {
|
|
6516
6663
|
connector.disconnect();
|
|
@@ -6616,4 +6763,4 @@ function readonly(obj) {
|
|
|
6616
6763
|
}
|
|
6617
6764
|
|
|
6618
6765
|
export { LightningElement, profilerControl as __unstable__ProfilerControl, api$1 as api, connectRootElement, createContextProvider, createVM, disconnectRootElement, getAssociatedVMIfPresent, getComponentDef, getComponentInternalDef, getUpgradableConstructor, isComponentConstructor, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
|
|
6619
|
-
/* version: 2.
|
|
6766
|
+
/* version: 2.5.1 */
|