@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.cjs.js
CHANGED
|
@@ -2312,12 +2312,6 @@ const LightningElement = function () {
|
|
|
2312
2312
|
associateVM(component, vm);
|
|
2313
2313
|
associateVM(elm, vm);
|
|
2314
2314
|
|
|
2315
|
-
if (!features.runtimeFlags.ENABLE_LIGHT_DOM_COMPONENTS) {
|
|
2316
|
-
shared.assert.isTrue(def.renderMode !== 0
|
|
2317
|
-
/* Light */
|
|
2318
|
-
, `${def.name || 'Anonymous class'} is an invalid LWC component. Light DOM components are not available in this environment.`);
|
|
2319
|
-
}
|
|
2320
|
-
|
|
2321
2315
|
if (vm.renderMode === 1
|
|
2322
2316
|
/* Shadow */
|
|
2323
2317
|
) {
|
|
@@ -2356,6 +2350,12 @@ function attachShadow(vm) {
|
|
|
2356
2350
|
if (process.env.NODE_ENV !== 'production') {
|
|
2357
2351
|
patchShadowRootWithRestrictions(cmpRoot);
|
|
2358
2352
|
}
|
|
2353
|
+
}
|
|
2354
|
+
|
|
2355
|
+
function warnIfInvokedDuringConstruction(vm, methodName) {
|
|
2356
|
+
if (isBeingConstructed(vm)) {
|
|
2357
|
+
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.`);
|
|
2358
|
+
}
|
|
2359
2359
|
} // @ts-ignore
|
|
2360
2360
|
|
|
2361
2361
|
|
|
@@ -2514,7 +2514,7 @@ LightningElement.prototype = {
|
|
|
2514
2514
|
} = vm;
|
|
2515
2515
|
|
|
2516
2516
|
if (process.env.NODE_ENV !== 'production') {
|
|
2517
|
-
|
|
2517
|
+
warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect');
|
|
2518
2518
|
}
|
|
2519
2519
|
|
|
2520
2520
|
return getBoundingClientRect(elm);
|
|
@@ -2530,7 +2530,7 @@ LightningElement.prototype = {
|
|
|
2530
2530
|
} = vm;
|
|
2531
2531
|
|
|
2532
2532
|
if (process.env.NODE_ENV !== 'production') {
|
|
2533
|
-
|
|
2533
|
+
warnIfInvokedDuringConstruction(vm, 'querySelector');
|
|
2534
2534
|
}
|
|
2535
2535
|
|
|
2536
2536
|
return querySelector(elm, selectors);
|
|
@@ -2546,7 +2546,7 @@ LightningElement.prototype = {
|
|
|
2546
2546
|
} = vm;
|
|
2547
2547
|
|
|
2548
2548
|
if (process.env.NODE_ENV !== 'production') {
|
|
2549
|
-
|
|
2549
|
+
warnIfInvokedDuringConstruction(vm, 'querySelectorAll');
|
|
2550
2550
|
}
|
|
2551
2551
|
|
|
2552
2552
|
return querySelectorAll(elm, selectors);
|
|
@@ -2562,7 +2562,7 @@ LightningElement.prototype = {
|
|
|
2562
2562
|
} = vm;
|
|
2563
2563
|
|
|
2564
2564
|
if (process.env.NODE_ENV !== 'production') {
|
|
2565
|
-
|
|
2565
|
+
warnIfInvokedDuringConstruction(vm, 'getElementsByTagName');
|
|
2566
2566
|
}
|
|
2567
2567
|
|
|
2568
2568
|
return getElementsByTagName(elm, tagNameOrWildCard);
|
|
@@ -2578,7 +2578,7 @@ LightningElement.prototype = {
|
|
|
2578
2578
|
} = vm;
|
|
2579
2579
|
|
|
2580
2580
|
if (process.env.NODE_ENV !== 'production') {
|
|
2581
|
-
|
|
2581
|
+
warnIfInvokedDuringConstruction(vm, 'getElementsByClassName');
|
|
2582
2582
|
}
|
|
2583
2583
|
|
|
2584
2584
|
return getElementsByClassName(elm, names);
|
|
@@ -2943,18 +2943,33 @@ function createObservedFieldPropertyDescriptor(key) {
|
|
|
2943
2943
|
|
|
2944
2944
|
function getClassDescriptorType(descriptor) {
|
|
2945
2945
|
if (shared.isFunction(descriptor.value)) {
|
|
2946
|
-
return
|
|
2946
|
+
return "method"
|
|
2947
|
+
/* Method */
|
|
2948
|
+
;
|
|
2947
2949
|
} else if (shared.isFunction(descriptor.set) || shared.isFunction(descriptor.get)) {
|
|
2948
|
-
return
|
|
2950
|
+
return "accessor"
|
|
2951
|
+
/* Accessor */
|
|
2952
|
+
;
|
|
2949
2953
|
} else {
|
|
2950
|
-
return
|
|
2954
|
+
return "field"
|
|
2955
|
+
/* Field */
|
|
2956
|
+
;
|
|
2951
2957
|
}
|
|
2952
2958
|
}
|
|
2953
2959
|
|
|
2954
2960
|
function validateObservedField(Ctor, fieldName, descriptor) {
|
|
2955
2961
|
if (!shared.isUndefined(descriptor)) {
|
|
2956
2962
|
const type = getClassDescriptorType(descriptor);
|
|
2957
|
-
|
|
2963
|
+
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.
|
|
2964
|
+
// This branch is only here for backward compatibility reasons.
|
|
2965
|
+
|
|
2966
|
+
if (type === "accessor"
|
|
2967
|
+
/* Accessor */
|
|
2968
|
+
) {
|
|
2969
|
+
logError(message);
|
|
2970
|
+
} else {
|
|
2971
|
+
shared.assert.fail(message);
|
|
2972
|
+
}
|
|
2958
2973
|
}
|
|
2959
2974
|
}
|
|
2960
2975
|
|
|
@@ -2981,7 +2996,16 @@ function validateMethodDecoratedWithWire(Ctor, methodName, descriptor) {
|
|
|
2981
2996
|
function validateFieldDecoratedWithApi(Ctor, fieldName, descriptor) {
|
|
2982
2997
|
if (!shared.isUndefined(descriptor)) {
|
|
2983
2998
|
const type = getClassDescriptorType(descriptor);
|
|
2984
|
-
|
|
2999
|
+
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.
|
|
3000
|
+
// This branch is only here for backward compatibility reasons.
|
|
3001
|
+
|
|
3002
|
+
if (type === "accessor"
|
|
3003
|
+
/* Accessor */
|
|
3004
|
+
) {
|
|
3005
|
+
logError(message);
|
|
3006
|
+
} else {
|
|
3007
|
+
shared.assert.fail(message);
|
|
3008
|
+
}
|
|
2985
3009
|
}
|
|
2986
3010
|
}
|
|
2987
3011
|
|
|
@@ -3044,9 +3068,16 @@ function registerDecorators(Ctor, meta) {
|
|
|
3044
3068
|
// field declaration
|
|
3045
3069
|
if (process.env.NODE_ENV !== 'production') {
|
|
3046
3070
|
validateFieldDecoratedWithApi(Ctor, fieldName, descriptor);
|
|
3047
|
-
}
|
|
3071
|
+
} // [W-9927596] If a component has both a public property and a private setter/getter
|
|
3072
|
+
// with the same name, the property is defined as a public accessor. This branch is
|
|
3073
|
+
// only here for backward compatibility reasons.
|
|
3074
|
+
|
|
3048
3075
|
|
|
3049
|
-
descriptor
|
|
3076
|
+
if (!shared.isUndefined(descriptor) && !shared.isUndefined(descriptor.get)) {
|
|
3077
|
+
descriptor = createPublicAccessorDescriptor(fieldName, descriptor);
|
|
3078
|
+
} else {
|
|
3079
|
+
descriptor = createPublicPropertyDescriptor(fieldName);
|
|
3080
|
+
}
|
|
3050
3081
|
}
|
|
3051
3082
|
|
|
3052
3083
|
apiFields[fieldName] = descriptor;
|
|
@@ -3126,9 +3157,16 @@ function registerDecorators(Ctor, meta) {
|
|
|
3126
3157
|
|
|
3127
3158
|
if (process.env.NODE_ENV !== 'production') {
|
|
3128
3159
|
validateObservedField(Ctor, fieldName, descriptor);
|
|
3129
|
-
}
|
|
3160
|
+
} // [W-9927596] Only mark a field as observed whenever it isn't a duplicated public nor
|
|
3161
|
+
// tracked property. This is only here for backward compatibility purposes.
|
|
3162
|
+
|
|
3163
|
+
|
|
3164
|
+
const isDuplicatePublicProp = !shared.isUndefined(publicProps) && fieldName in publicProps;
|
|
3165
|
+
const isDuplicateTrackedProp = !shared.isUndefined(track) && fieldName in track;
|
|
3130
3166
|
|
|
3131
|
-
|
|
3167
|
+
if (!isDuplicatePublicProp && !isDuplicateTrackedProp) {
|
|
3168
|
+
observedFields[fieldName] = createObservedFieldPropertyDescriptor(fieldName);
|
|
3169
|
+
}
|
|
3132
3170
|
}
|
|
3133
3171
|
}
|
|
3134
3172
|
|
|
@@ -3960,6 +3998,19 @@ function observeElementChildNodes(elm) {
|
|
|
3960
3998
|
|
|
3961
3999
|
function setElementShadowToken(elm, token) {
|
|
3962
4000
|
elm.$shadowToken$ = token;
|
|
4001
|
+
} // Set the scope token class for *.scoped.css styles
|
|
4002
|
+
|
|
4003
|
+
|
|
4004
|
+
function setScopeTokenClassIfNecessary(elm, owner) {
|
|
4005
|
+
const {
|
|
4006
|
+
cmpTemplate,
|
|
4007
|
+
context
|
|
4008
|
+
} = owner;
|
|
4009
|
+
const token = cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken;
|
|
4010
|
+
|
|
4011
|
+
if (!shared.isUndefined(token) && context.hasScopedStyles) {
|
|
4012
|
+
owner.renderer.getClassList(elm).add(token);
|
|
4013
|
+
}
|
|
3963
4014
|
}
|
|
3964
4015
|
|
|
3965
4016
|
function updateNodeHook(oldVnode, vnode) {
|
|
@@ -4029,6 +4080,7 @@ function fallbackElmHook(elm, vnode) {
|
|
|
4029
4080
|
const {
|
|
4030
4081
|
owner
|
|
4031
4082
|
} = vnode;
|
|
4083
|
+
setScopeTokenClassIfNecessary(elm, owner);
|
|
4032
4084
|
|
|
4033
4085
|
if (owner.shadowMode === 1
|
|
4034
4086
|
/* Synthetic */
|
|
@@ -4039,7 +4091,7 @@ function fallbackElmHook(elm, vnode) {
|
|
|
4039
4091
|
}
|
|
4040
4092
|
} = vnode;
|
|
4041
4093
|
const {
|
|
4042
|
-
|
|
4094
|
+
stylesheetToken
|
|
4043
4095
|
} = owner.context;
|
|
4044
4096
|
|
|
4045
4097
|
if (!shared.isUndefined(context) && !shared.isUndefined(context.lwc) && context.lwc.dom === "manual"
|
|
@@ -4051,7 +4103,7 @@ function fallbackElmHook(elm, vnode) {
|
|
|
4051
4103
|
// into each element from the template, so they can be styled accordingly.
|
|
4052
4104
|
|
|
4053
4105
|
|
|
4054
|
-
setElementShadowToken(elm,
|
|
4106
|
+
setElementShadowToken(elm, stylesheetToken);
|
|
4055
4107
|
}
|
|
4056
4108
|
|
|
4057
4109
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -4136,16 +4188,17 @@ function createViewModelHook(elm, vnode) {
|
|
|
4136
4188
|
ctor,
|
|
4137
4189
|
owner
|
|
4138
4190
|
} = vnode;
|
|
4191
|
+
setScopeTokenClassIfNecessary(elm, owner);
|
|
4139
4192
|
|
|
4140
4193
|
if (owner.shadowMode === 1
|
|
4141
4194
|
/* Synthetic */
|
|
4142
4195
|
) {
|
|
4143
4196
|
const {
|
|
4144
|
-
|
|
4197
|
+
stylesheetToken
|
|
4145
4198
|
} = owner.context; // when running in synthetic shadow mode, we need to set the shadowToken value
|
|
4146
4199
|
// into each element from the template, so they can be styled accordingly.
|
|
4147
4200
|
|
|
4148
|
-
setElementShadowToken(elm,
|
|
4201
|
+
setElementShadowToken(elm, stylesheetToken);
|
|
4149
4202
|
}
|
|
4150
4203
|
|
|
4151
4204
|
const def = getComponentInternalDef(ctor);
|
|
@@ -4437,13 +4490,19 @@ const CustomElementHook = {
|
|
|
4437
4490
|
|
|
4438
4491
|
function linkNodeToShadow(elm, owner) {
|
|
4439
4492
|
const {
|
|
4493
|
+
renderer,
|
|
4494
|
+
renderMode,
|
|
4440
4495
|
shadowMode
|
|
4441
4496
|
} = owner; // TODO [#1164]: this should eventually be done by the polyfill directly
|
|
4442
4497
|
|
|
4443
|
-
if (
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4498
|
+
if (renderer.isSyntheticShadowDefined) {
|
|
4499
|
+
if (shadowMode === 1
|
|
4500
|
+
/* Synthetic */
|
|
4501
|
+
|| renderMode === 0
|
|
4502
|
+
/* Light */
|
|
4503
|
+
) {
|
|
4504
|
+
elm[shared.KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[shared.KEY__SHADOW_RESOLVER];
|
|
4505
|
+
}
|
|
4447
4506
|
}
|
|
4448
4507
|
}
|
|
4449
4508
|
|
|
@@ -4778,14 +4837,11 @@ function gid(id) {
|
|
|
4778
4837
|
|
|
4779
4838
|
const {
|
|
4780
4839
|
idx,
|
|
4781
|
-
renderMode,
|
|
4782
4840
|
shadowMode
|
|
4783
4841
|
} = vmBeingRendered;
|
|
4784
4842
|
|
|
4785
4843
|
if (shadowMode === 1
|
|
4786
4844
|
/* Synthetic */
|
|
4787
|
-
&& renderMode === 1
|
|
4788
|
-
/* Shadow */
|
|
4789
4845
|
) {
|
|
4790
4846
|
return shared.StringReplace.call(id, /\S+/g, id => `${id}-${idx}`);
|
|
4791
4847
|
}
|
|
@@ -4813,14 +4869,11 @@ function fid(url) {
|
|
|
4813
4869
|
|
|
4814
4870
|
const {
|
|
4815
4871
|
idx,
|
|
4816
|
-
renderMode,
|
|
4817
4872
|
shadowMode
|
|
4818
4873
|
} = vmBeingRendered; // Apply transformation only for fragment-only-urls, and only in shadow DOM
|
|
4819
4874
|
|
|
4820
4875
|
if (shadowMode === 1
|
|
4821
4876
|
/* Synthetic */
|
|
4822
|
-
&& renderMode === 1
|
|
4823
|
-
/* Shadow */
|
|
4824
4877
|
&& /^#/.test(url)) {
|
|
4825
4878
|
return `${url}-${idx}`;
|
|
4826
4879
|
}
|
|
@@ -4920,6 +4973,10 @@ var api = /*#__PURE__*/Object.freeze({
|
|
|
4920
4973
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
4921
4974
|
*/
|
|
4922
4975
|
|
|
4976
|
+
function makeHostToken(token) {
|
|
4977
|
+
return `${token}-host`;
|
|
4978
|
+
}
|
|
4979
|
+
|
|
4923
4980
|
function createInlineStyleVNode(content) {
|
|
4924
4981
|
return h('style', {
|
|
4925
4982
|
key: 'style',
|
|
@@ -4929,59 +4986,100 @@ function createInlineStyleVNode(content) {
|
|
|
4929
4986
|
}, [t(content)]);
|
|
4930
4987
|
}
|
|
4931
4988
|
|
|
4932
|
-
function
|
|
4989
|
+
function updateStylesheetToken(vm, template) {
|
|
4933
4990
|
const {
|
|
4934
4991
|
elm,
|
|
4935
4992
|
context,
|
|
4936
4993
|
renderer,
|
|
4937
|
-
renderMode
|
|
4994
|
+
renderMode,
|
|
4995
|
+
shadowMode
|
|
4938
4996
|
} = vm;
|
|
4939
4997
|
const {
|
|
4940
4998
|
stylesheets: newStylesheets,
|
|
4941
|
-
|
|
4999
|
+
stylesheetToken: newStylesheetToken
|
|
4942
5000
|
} = template;
|
|
4943
|
-
|
|
5001
|
+
const isSyntheticShadow = renderMode === 1
|
|
5002
|
+
/* Shadow */
|
|
5003
|
+
&& shadowMode === 1
|
|
5004
|
+
/* Synthetic */
|
|
5005
|
+
;
|
|
5006
|
+
const {
|
|
5007
|
+
hasScopedStyles
|
|
5008
|
+
} = context;
|
|
5009
|
+
let newToken;
|
|
5010
|
+
let newHasTokenInClass;
|
|
5011
|
+
let newHasTokenInAttribute; // Reset the styling token applied to the host element.
|
|
4944
5012
|
|
|
4945
|
-
const
|
|
5013
|
+
const {
|
|
5014
|
+
stylesheetToken: oldToken,
|
|
5015
|
+
hasTokenInClass: oldHasTokenInClass,
|
|
5016
|
+
hasTokenInAttribute: oldHasTokenInAttribute
|
|
5017
|
+
} = context;
|
|
5018
|
+
|
|
5019
|
+
if (oldHasTokenInClass) {
|
|
5020
|
+
renderer.getClassList(elm).remove(makeHostToken(oldToken));
|
|
5021
|
+
}
|
|
4946
5022
|
|
|
4947
|
-
if (
|
|
4948
|
-
renderer.removeAttribute(elm,
|
|
5023
|
+
if (oldHasTokenInAttribute) {
|
|
5024
|
+
renderer.removeAttribute(elm, makeHostToken(oldToken));
|
|
4949
5025
|
} // Apply the new template styling token to the host element, if the new template has any
|
|
4950
|
-
// associated stylesheets.
|
|
5026
|
+
// associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
|
|
4951
5027
|
|
|
4952
5028
|
|
|
4953
|
-
if (!shared.isUndefined(newStylesheets) && newStylesheets.length !== 0
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
}
|
|
5029
|
+
if (!shared.isUndefined(newStylesheets) && newStylesheets.length !== 0) {
|
|
5030
|
+
newToken = newStylesheetToken;
|
|
5031
|
+
} // Set the new styling token on the host element
|
|
5032
|
+
|
|
4958
5033
|
|
|
4959
|
-
if (!shared.isUndefined(
|
|
4960
|
-
|
|
5034
|
+
if (!shared.isUndefined(newToken)) {
|
|
5035
|
+
if (hasScopedStyles) {
|
|
5036
|
+
renderer.getClassList(elm).add(makeHostToken(newToken));
|
|
5037
|
+
newHasTokenInClass = true;
|
|
5038
|
+
}
|
|
5039
|
+
|
|
5040
|
+
if (isSyntheticShadow) {
|
|
5041
|
+
renderer.setAttribute(elm, makeHostToken(newToken), '');
|
|
5042
|
+
newHasTokenInAttribute = true;
|
|
5043
|
+
}
|
|
4961
5044
|
} // Update the styling tokens present on the context object.
|
|
4962
5045
|
|
|
4963
5046
|
|
|
4964
|
-
context.
|
|
4965
|
-
context.
|
|
5047
|
+
context.stylesheetToken = newToken;
|
|
5048
|
+
context.hasTokenInClass = newHasTokenInClass;
|
|
5049
|
+
context.hasTokenInAttribute = newHasTokenInAttribute;
|
|
4966
5050
|
}
|
|
4967
5051
|
|
|
4968
|
-
function evaluateStylesheetsContent(stylesheets,
|
|
5052
|
+
function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
|
|
4969
5053
|
const content = [];
|
|
4970
5054
|
|
|
4971
5055
|
for (let i = 0; i < stylesheets.length; i++) {
|
|
4972
5056
|
let stylesheet = stylesheets[i];
|
|
4973
5057
|
|
|
4974
5058
|
if (shared.isArray(stylesheet)) {
|
|
4975
|
-
shared.ArrayPush.apply(content, evaluateStylesheetsContent(stylesheet,
|
|
5059
|
+
shared.ArrayPush.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
|
|
4976
5060
|
} else {
|
|
4977
5061
|
if (process.env.NODE_ENV !== 'production') {
|
|
4978
5062
|
// in dev-mode, we support hot swapping of stylesheet, which means that
|
|
4979
5063
|
// the component instance might be attempting to use an old version of
|
|
4980
5064
|
// the stylesheet, while internally, we have a replacement for it.
|
|
4981
5065
|
stylesheet = getStyleOrSwappedStyle(stylesheet);
|
|
4982
|
-
}
|
|
5066
|
+
} // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
|
|
5067
|
+
// native shadow DOM. Synthetic shadow DOM never uses `:host`.
|
|
5068
|
+
|
|
5069
|
+
|
|
5070
|
+
const isScopedCss = stylesheet[shared.KEY__SCOPED_CSS];
|
|
5071
|
+
const useActualHostSelector = vm.renderMode === 0
|
|
5072
|
+
/* Light */
|
|
5073
|
+
? !isScopedCss : vm.shadowMode === 0
|
|
5074
|
+
/* Native */
|
|
5075
|
+
; // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
|
|
4983
5076
|
|
|
4984
|
-
|
|
5077
|
+
const scopeToken = isScopedCss || vm.shadowMode === 1
|
|
5078
|
+
/* Synthetic */
|
|
5079
|
+
&& vm.renderMode === 1
|
|
5080
|
+
/* Shadow */
|
|
5081
|
+
? stylesheetToken : undefined;
|
|
5082
|
+
shared.ArrayPush.call(content, stylesheet(useActualHostSelector, scopeToken));
|
|
4985
5083
|
}
|
|
4986
5084
|
}
|
|
4987
5085
|
|
|
@@ -4991,38 +5089,37 @@ function evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, n
|
|
|
4991
5089
|
function getStylesheetsContent(vm, template) {
|
|
4992
5090
|
const {
|
|
4993
5091
|
stylesheets,
|
|
4994
|
-
|
|
5092
|
+
stylesheetToken
|
|
4995
5093
|
} = template;
|
|
4996
|
-
const {
|
|
4997
|
-
renderMode,
|
|
4998
|
-
shadowMode
|
|
4999
|
-
} = vm;
|
|
5000
5094
|
let content = [];
|
|
5001
5095
|
|
|
5002
5096
|
if (!shared.isUndefined(stylesheets) && stylesheets.length !== 0) {
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5097
|
+
content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
|
|
5098
|
+
}
|
|
5099
|
+
|
|
5100
|
+
return content;
|
|
5101
|
+
} // It might be worth caching this to avoid doing the lookup repeatedly, but
|
|
5102
|
+
// perf testing has not shown it to be a huge improvement yet:
|
|
5103
|
+
// https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
|
|
5006
5104
|
|
|
5007
|
-
|
|
5105
|
+
function getNearestNativeShadowComponent(vm) {
|
|
5106
|
+
let owner = vm;
|
|
5107
|
+
|
|
5108
|
+
while (!shared.isNull(owner)) {
|
|
5109
|
+
if (owner.renderMode === 1
|
|
5008
5110
|
/* Shadow */
|
|
5009
|
-
&& shadowMode ===
|
|
5010
|
-
/*
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
shadowSelector = `[${stylesheetTokens.shadowAttribute}]`;
|
|
5014
|
-
} else {
|
|
5015
|
-
hostSelector = '';
|
|
5016
|
-
shadowSelector = '';
|
|
5111
|
+
&& owner.shadowMode === 0
|
|
5112
|
+
/* Native */
|
|
5113
|
+
) {
|
|
5114
|
+
return owner;
|
|
5017
5115
|
}
|
|
5018
5116
|
|
|
5019
|
-
|
|
5020
|
-
/* Native */
|
|
5021
|
-
);
|
|
5117
|
+
owner = owner.owner;
|
|
5022
5118
|
}
|
|
5023
5119
|
|
|
5024
|
-
return
|
|
5120
|
+
return owner;
|
|
5025
5121
|
}
|
|
5122
|
+
|
|
5026
5123
|
function createStylesheet(vm, stylesheets) {
|
|
5027
5124
|
const {
|
|
5028
5125
|
renderer,
|
|
@@ -5038,13 +5135,26 @@ function createStylesheet(vm, stylesheets) {
|
|
|
5038
5135
|
for (let i = 0; i < stylesheets.length; i++) {
|
|
5039
5136
|
renderer.insertGlobalStylesheet(stylesheets[i]);
|
|
5040
5137
|
}
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
} else {
|
|
5044
|
-
// native shadow or light DOM
|
|
5138
|
+
} else if (renderer.ssr) {
|
|
5139
|
+
// native shadow or light DOM, SSR
|
|
5045
5140
|
const combinedStylesheetContent = shared.ArrayJoin.call(stylesheets, '\n');
|
|
5046
5141
|
return createInlineStyleVNode(combinedStylesheetContent);
|
|
5142
|
+
} else {
|
|
5143
|
+
// native shadow or light DOM, DOM renderer
|
|
5144
|
+
const root = getNearestNativeShadowComponent(vm);
|
|
5145
|
+
const isGlobal = shared.isNull(root);
|
|
5146
|
+
|
|
5147
|
+
for (let i = 0; i < stylesheets.length; i++) {
|
|
5148
|
+
if (isGlobal) {
|
|
5149
|
+
renderer.insertGlobalStylesheet(stylesheets[i]);
|
|
5150
|
+
} else {
|
|
5151
|
+
// local level
|
|
5152
|
+
renderer.insertStylesheet(stylesheets[i], root.cmpRoot);
|
|
5153
|
+
}
|
|
5154
|
+
}
|
|
5047
5155
|
}
|
|
5156
|
+
|
|
5157
|
+
return null;
|
|
5048
5158
|
}
|
|
5049
5159
|
|
|
5050
5160
|
/*
|
|
@@ -5242,8 +5352,7 @@ function evaluateTemplate(vm, html) {
|
|
|
5242
5352
|
context,
|
|
5243
5353
|
cmpSlots,
|
|
5244
5354
|
cmpTemplate,
|
|
5245
|
-
tro
|
|
5246
|
-
shadowMode
|
|
5355
|
+
tro
|
|
5247
5356
|
} = vm;
|
|
5248
5357
|
tro.observe(() => {
|
|
5249
5358
|
// Reset the cache memoizer for template when needed.
|
|
@@ -5268,15 +5377,12 @@ function evaluateTemplate(vm, html) {
|
|
|
5268
5377
|
|
|
5269
5378
|
vm.cmpTemplate = html; // Create a brand new template cache for the swapped templated.
|
|
5270
5379
|
|
|
5271
|
-
context.tplCache = shared.create(null); //
|
|
5380
|
+
context.tplCache = shared.create(null); // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
|
|
5272
5381
|
|
|
5273
|
-
|
|
5274
|
-
/* Synthetic */
|
|
5275
|
-
) {
|
|
5276
|
-
updateSyntheticShadowAttributes(vm, html);
|
|
5277
|
-
} // Evaluate, create stylesheet and cache the produced VNode for future
|
|
5278
|
-
// re-rendering.
|
|
5382
|
+
context.hasScopedStyles = computeHasScopedStyles(html); // Update the scoping token on the host element.
|
|
5279
5383
|
|
|
5384
|
+
updateStylesheetToken(vm, html); // Evaluate, create stylesheet and cache the produced VNode for future
|
|
5385
|
+
// re-rendering.
|
|
5280
5386
|
|
|
5281
5387
|
const stylesheetsContent = getStylesheetsContent(vm, html);
|
|
5282
5388
|
context.styleVNode = stylesheetsContent.length === 0 ? null : createStylesheet(vm, stylesheetsContent);
|
|
@@ -5318,6 +5424,21 @@ function evaluateTemplate(vm, html) {
|
|
|
5318
5424
|
|
|
5319
5425
|
return vnodes;
|
|
5320
5426
|
}
|
|
5427
|
+
function computeHasScopedStyles(template) {
|
|
5428
|
+
const {
|
|
5429
|
+
stylesheets
|
|
5430
|
+
} = template;
|
|
5431
|
+
|
|
5432
|
+
if (!shared.isUndefined(stylesheets)) {
|
|
5433
|
+
for (let i = 0; i < stylesheets.length; i++) {
|
|
5434
|
+
if (shared.isTrue(stylesheets[i][shared.KEY__SCOPED_CSS])) {
|
|
5435
|
+
return true;
|
|
5436
|
+
}
|
|
5437
|
+
}
|
|
5438
|
+
}
|
|
5439
|
+
|
|
5440
|
+
return false;
|
|
5441
|
+
}
|
|
5321
5442
|
|
|
5322
5443
|
/*
|
|
5323
5444
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
@@ -5572,7 +5693,6 @@ function invokeServiceHook(vm, cbs) {
|
|
|
5572
5693
|
* SPDX-License-Identifier: MIT
|
|
5573
5694
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
5574
5695
|
*/
|
|
5575
|
-
const isNativeShadowRootDefined = shared.globalThis[shared.KEY__IS_NATIVE_SHADOW_ROOT_DEFINED];
|
|
5576
5696
|
let idx = 0;
|
|
5577
5697
|
/** The internal slot used to associate different objects the engine manipulates with the VM */
|
|
5578
5698
|
|
|
@@ -5677,29 +5797,6 @@ function getNearestShadowAncestor(vm) {
|
|
|
5677
5797
|
return ancestor;
|
|
5678
5798
|
}
|
|
5679
5799
|
|
|
5680
|
-
function assertNotSyntheticComposedWithinNative(vm) {
|
|
5681
|
-
const isSynthetic = vm.renderMode === 1
|
|
5682
|
-
/* Shadow */
|
|
5683
|
-
&& vm.shadowMode === 1
|
|
5684
|
-
/* Synthetic */
|
|
5685
|
-
;
|
|
5686
|
-
|
|
5687
|
-
if (!isSynthetic) {
|
|
5688
|
-
return;
|
|
5689
|
-
}
|
|
5690
|
-
|
|
5691
|
-
const ancestor = getNearestShadowAncestor(vm);
|
|
5692
|
-
|
|
5693
|
-
if (!shared.isNull(ancestor)) {
|
|
5694
|
-
// Any native shadow component being an ancestor of a synthetic shadow component is disallowed.
|
|
5695
|
-
shared.assert.isFalse(ancestor.renderMode === 1
|
|
5696
|
-
/* Shadow */
|
|
5697
|
-
&& ancestor.shadowMode === 0
|
|
5698
|
-
/* Native */
|
|
5699
|
-
, `${getComponentTag(vm)} (synthetic shadow DOM) cannot be composed inside of ${getComponentTag(ancestor)} (native shadow DOM), because synthetic-within-native composition is disallowed`);
|
|
5700
|
-
}
|
|
5701
|
-
}
|
|
5702
|
-
|
|
5703
5800
|
function createVM(elm, def, options) {
|
|
5704
5801
|
const {
|
|
5705
5802
|
mode,
|
|
@@ -5707,22 +5804,6 @@ function createVM(elm, def, options) {
|
|
|
5707
5804
|
renderer,
|
|
5708
5805
|
tagName
|
|
5709
5806
|
} = options;
|
|
5710
|
-
let shadowMode;
|
|
5711
|
-
|
|
5712
|
-
if (renderer.syntheticShadow) {
|
|
5713
|
-
shadowMode = def.shadowSupportMode === "any"
|
|
5714
|
-
/* Any */
|
|
5715
|
-
&& isNativeShadowRootDefined ? 0
|
|
5716
|
-
/* Native */
|
|
5717
|
-
: 1
|
|
5718
|
-
/* Synthetic */
|
|
5719
|
-
;
|
|
5720
|
-
} else {
|
|
5721
|
-
shadowMode = 0
|
|
5722
|
-
/* Native */
|
|
5723
|
-
;
|
|
5724
|
-
}
|
|
5725
|
-
|
|
5726
5807
|
const vm = {
|
|
5727
5808
|
elm,
|
|
5728
5809
|
def,
|
|
@@ -5745,10 +5826,12 @@ function createVM(elm, def, options) {
|
|
|
5745
5826
|
oar: shared.create(null),
|
|
5746
5827
|
cmpTemplate: null,
|
|
5747
5828
|
renderMode: def.renderMode,
|
|
5748
|
-
shadowMode,
|
|
5829
|
+
shadowMode: null,
|
|
5749
5830
|
context: {
|
|
5750
|
-
|
|
5751
|
-
|
|
5831
|
+
stylesheetToken: undefined,
|
|
5832
|
+
hasTokenInClass: undefined,
|
|
5833
|
+
hasTokenInAttribute: undefined,
|
|
5834
|
+
hasScopedStyles: undefined,
|
|
5752
5835
|
styleVNode: null,
|
|
5753
5836
|
tplCache: EmptyObject,
|
|
5754
5837
|
wiredConnecting: EmptyArray,
|
|
@@ -5761,26 +5844,87 @@ function createVM(elm, def, options) {
|
|
|
5761
5844
|
setHook,
|
|
5762
5845
|
getHook
|
|
5763
5846
|
};
|
|
5847
|
+
vm.shadowMode = computeShadowMode(vm);
|
|
5764
5848
|
vm.tro = getTemplateReactiveObserver(vm);
|
|
5765
5849
|
|
|
5766
5850
|
if (process.env.NODE_ENV !== 'production') {
|
|
5767
5851
|
vm.toString = () => {
|
|
5768
5852
|
return `[object:vm ${def.name} (${vm.idx})]`;
|
|
5769
5853
|
};
|
|
5770
|
-
|
|
5771
|
-
assertNotSyntheticComposedWithinNative(vm);
|
|
5772
5854
|
} // Create component instance associated to the vm and the element.
|
|
5773
5855
|
|
|
5774
5856
|
|
|
5775
5857
|
invokeComponentConstructor(vm, def.ctor); // Initializing the wire decorator per instance only when really needed
|
|
5776
5858
|
|
|
5777
|
-
if (
|
|
5859
|
+
if (hasWireAdapters(vm)) {
|
|
5778
5860
|
installWireAdapters(vm);
|
|
5779
5861
|
}
|
|
5780
5862
|
|
|
5781
5863
|
return vm;
|
|
5782
5864
|
}
|
|
5783
5865
|
|
|
5866
|
+
function computeShadowMode(vm) {
|
|
5867
|
+
const {
|
|
5868
|
+
def,
|
|
5869
|
+
renderer
|
|
5870
|
+
} = vm;
|
|
5871
|
+
const {
|
|
5872
|
+
isNativeShadowDefined,
|
|
5873
|
+
isSyntheticShadowDefined
|
|
5874
|
+
} = renderer;
|
|
5875
|
+
let shadowMode;
|
|
5876
|
+
|
|
5877
|
+
if (isSyntheticShadowDefined) {
|
|
5878
|
+
if (def.renderMode === 0
|
|
5879
|
+
/* Light */
|
|
5880
|
+
) {
|
|
5881
|
+
// ShadowMode.Native implies "not synthetic shadow" which is consistent with how
|
|
5882
|
+
// everything defaults to native when the synthetic shadow polyfill is unavailable.
|
|
5883
|
+
shadowMode = 0
|
|
5884
|
+
/* Native */
|
|
5885
|
+
;
|
|
5886
|
+
} else if (isNativeShadowDefined) {
|
|
5887
|
+
if (def.shadowSupportMode === "any"
|
|
5888
|
+
/* Any */
|
|
5889
|
+
) {
|
|
5890
|
+
shadowMode = 0
|
|
5891
|
+
/* Native */
|
|
5892
|
+
;
|
|
5893
|
+
} else {
|
|
5894
|
+
const shadowAncestor = getNearestShadowAncestor(vm);
|
|
5895
|
+
|
|
5896
|
+
if (!shared.isNull(shadowAncestor) && shadowAncestor.shadowMode === 0
|
|
5897
|
+
/* Native */
|
|
5898
|
+
) {
|
|
5899
|
+
// Transitive support for native Shadow DOM. A component in native mode
|
|
5900
|
+
// transitively opts all of its descendants into native.
|
|
5901
|
+
shadowMode = 0
|
|
5902
|
+
/* Native */
|
|
5903
|
+
;
|
|
5904
|
+
} else {
|
|
5905
|
+
// Synthetic if neither this component nor any of its ancestors are configured
|
|
5906
|
+
// to be native.
|
|
5907
|
+
shadowMode = 1
|
|
5908
|
+
/* Synthetic */
|
|
5909
|
+
;
|
|
5910
|
+
}
|
|
5911
|
+
}
|
|
5912
|
+
} else {
|
|
5913
|
+
// Synthetic if there is no native Shadow DOM support.
|
|
5914
|
+
shadowMode = 1
|
|
5915
|
+
/* Synthetic */
|
|
5916
|
+
;
|
|
5917
|
+
}
|
|
5918
|
+
} else {
|
|
5919
|
+
// Native if the synthetic shadow polyfill is unavailable.
|
|
5920
|
+
shadowMode = 0
|
|
5921
|
+
/* Native */
|
|
5922
|
+
;
|
|
5923
|
+
}
|
|
5924
|
+
|
|
5925
|
+
return shadowMode;
|
|
5926
|
+
}
|
|
5927
|
+
|
|
5784
5928
|
function assertIsVM(obj) {
|
|
5785
5929
|
if (shared.isNull(obj) || !shared.isObject(obj) || !('cmpRoot' in obj)) {
|
|
5786
5930
|
throw new TypeError(`${obj} is not a VM.`);
|
|
@@ -6509,11 +6653,14 @@ function installWireAdapters(vm) {
|
|
|
6509
6653
|
shared.ArrayPush.call(wiredConnecting, () => {
|
|
6510
6654
|
connector.connect();
|
|
6511
6655
|
|
|
6512
|
-
if (
|
|
6513
|
-
|
|
6514
|
-
|
|
6515
|
-
|
|
6656
|
+
if (!features.runtimeFlags.ENABLE_WIRE_SYNC_EMIT) {
|
|
6657
|
+
if (hasDynamicParams) {
|
|
6658
|
+
Promise.resolve().then(computeConfigAndUpdate);
|
|
6659
|
+
return;
|
|
6660
|
+
}
|
|
6516
6661
|
}
|
|
6662
|
+
|
|
6663
|
+
computeConfigAndUpdate();
|
|
6517
6664
|
});
|
|
6518
6665
|
shared.ArrayPush.call(wiredDisconnecting, () => {
|
|
6519
6666
|
connector.disconnect();
|
|
@@ -6654,4 +6801,4 @@ exports.swapTemplate = swapTemplate;
|
|
|
6654
6801
|
exports.track = track;
|
|
6655
6802
|
exports.unwrap = unwrap;
|
|
6656
6803
|
exports.wire = wire;
|
|
6657
|
-
/* version: 2.
|
|
6804
|
+
/* version: 2.5.1 */
|