lwc 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.
Files changed (41) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +389 -174
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +389 -174
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +2 -2
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +359 -137
  5. package/dist/engine-dom/iife/es5/engine-dom.js +404 -198
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +2 -2
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +372 -159
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +389 -174
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +2 -2
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +359 -137
  11. package/dist/engine-dom/umd/es5/engine-dom.js +404 -198
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +2 -2
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +372 -159
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +333 -181
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +2 -2
  16. package/dist/engine-server/esm/es2017/engine-server.js +333 -181
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +29 -16
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +29 -16
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +2 -2
  20. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +29 -16
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +31 -16
  22. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js +2 -2
  23. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +31 -16
  24. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +29 -16
  25. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +2 -2
  26. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +29 -16
  27. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +31 -16
  28. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js +2 -2
  29. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +31 -16
  30. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  31. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/iife/es5/wire-service.js +3 -3
  34. package/dist/wire-service/iife/es5/wire-service.min.js +1 -1
  35. package/dist/wire-service/iife/es5/wire-service_debug.js +3 -3
  36. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  37. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  38. package/dist/wire-service/umd/es5/wire-service.js +3 -3
  39. package/dist/wire-service/umd/es5/wire-service.min.js +1 -1
  40. package/dist/wire-service/umd/es5/wire-service_debug.js +3 -3
  41. package/package.json +8 -8
@@ -30,7 +30,7 @@
30
30
 
31
31
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf2(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf2(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
32
32
 
33
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
33
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
34
34
 
35
35
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
36
36
 
@@ -152,6 +152,10 @@
152
152
  return obj === false;
153
153
  }
154
154
 
155
+ function isBoolean(obj) {
156
+ return typeof obj === 'boolean';
157
+ }
158
+
155
159
  function isFunction$1(obj) {
156
160
  return typeof obj === 'function';
157
161
  }
@@ -291,6 +295,7 @@
291
295
  var KEY__SHADOW_RESOLVER = '$shadowResolver$';
292
296
  var KEY__SHADOW_TOKEN = '$shadowToken$';
293
297
  var KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode';
298
+ var KEY__SCOPED_CSS = '$scoped$';
294
299
  /**
295
300
  * Map composed of properties to attributes not following the HTML property to attribute mapping
296
301
  * convention.
@@ -339,7 +344,7 @@
339
344
  CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
340
345
  return attributeName;
341
346
  }
342
- /** version: 2.3.4 */
347
+ /** version: 2.5.1 */
343
348
 
344
349
  /*
345
350
  * Copyright (c) 2018, salesforce.com, inc.
@@ -442,19 +447,33 @@
442
447
  */
443
448
 
444
449
 
450
+ var features = {
451
+ ENABLE_REACTIVE_SETTER: null,
452
+ ENABLE_HMR: null,
453
+ ENABLE_INNER_OUTER_TEXT_PATCH: null,
454
+ ENABLE_ELEMENT_PATCH: null,
455
+ ENABLE_NODE_LIST_PATCH: null,
456
+ ENABLE_HTML_COLLECTIONS_PATCH: null,
457
+ ENABLE_NODE_PATCH: null,
458
+ ENABLE_NON_COMPOSED_EVENTS_LEAKAGE: null,
459
+ ENABLE_MIXED_SHADOW_MODE: null,
460
+ ENABLE_WIRE_SYNC_EMIT: null
461
+ };
462
+
445
463
  if (!_globalThis.lwcRuntimeFlags) {
446
464
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', {
447
465
  value: create(null)
448
466
  });
449
467
  }
450
468
 
451
- var runtimeFlags = _globalThis.lwcRuntimeFlags; // This function is not supported for use within components and is meant for
452
- // configuring runtime feature flags during app initialization.
469
+ var runtimeFlags = _globalThis.lwcRuntimeFlags;
470
+ /**
471
+ * Set the value at runtime of a given feature flag. This method only be invoked once per feature
472
+ * flag. It is meant to be used during the app initialization.
473
+ */
453
474
 
454
475
  function setFeatureFlag(name, value) {
455
- var isBoolean = isTrue(value) || isFalse(value);
456
-
457
- if (!isBoolean) {
476
+ if (!isBoolean(value)) {
458
477
  var message = "Failed to set the value \"".concat(value, "\" for the runtime feature flag \"").concat(name, "\". Runtime feature flags can only be set to a boolean value.");
459
478
 
460
479
  {
@@ -464,9 +483,12 @@
464
483
  }
465
484
  }
466
485
 
467
- if (isUndefined$1(featureFlagLookup[name])) {
468
- // eslint-disable-next-line no-console
469
- console.warn("Failed to set the value \"".concat(value, "\" for the runtime feature flag \"").concat(name, "\" because it is undefined. Possible reasons are that 1) it was misspelled or 2) it was removed from the @lwc/features package."));
486
+ if (isUndefined$1(features[name])) {
487
+ var availableFlags = keys(features).map(function (name) {
488
+ return "\"".concat(name, "\"");
489
+ }).join(', '); // eslint-disable-next-line no-console
490
+
491
+ console.warn("Failed to set the value \"".concat(value, "\" for the runtime feature flag \"").concat(name, "\" because it is undefined. Available flags: ").concat(availableFlags, "."));
470
492
  return;
471
493
  }
472
494
 
@@ -480,34 +502,20 @@
480
502
  return;
481
503
  }
482
504
 
483
- Object.defineProperty(runtimeFlags, name, {
505
+ defineProperty(runtimeFlags, name, {
484
506
  value: value
485
507
  });
486
508
  }
487
- } // This function is exposed to components to facilitate testing so we add a
488
- // check to make sure it is not invoked in production.
509
+ }
510
+ /**
511
+ * Set the value at runtime of a given feature flag. This method should only be used for testing
512
+ * purposes. It is a no-op when invoked in production mode.
513
+ */
489
514
 
490
515
 
491
516
  function setFeatureFlagForTest(name, value) {
492
517
  }
493
-
494
- var featureFlagLookup = {
495
- ENABLE_REACTIVE_SETTER: null,
496
- ENABLE_HMR: null,
497
- // Flag to toggle on/off the enforcement of innerText/outerText shadow dom semantic in elements when using synthetic shadow.
498
- // Note: Once active, elements outside the lwc boundary are controlled by the ENABLE_ELEMENT_PATCH flag.
499
- ENABLE_INNER_OUTER_TEXT_PATCH: null,
500
- // Flags to toggle on/off the enforcement of shadow dom semantic in element/node outside lwc boundary when using synthetic shadow.
501
- ENABLE_ELEMENT_PATCH: null,
502
- ENABLE_NODE_LIST_PATCH: null,
503
- ENABLE_HTML_COLLECTIONS_PATCH: null,
504
- ENABLE_NODE_PATCH: null,
505
- // Disables the fix for #2121 where non-composed events are visible outside of their shadow root.
506
- ENABLE_NON_COMPOSED_EVENTS_LEAKAGE: null,
507
- ENABLE_LIGHT_DOM_COMPONENTS: null,
508
- ENABLE_MIXED_SHADOW_MODE: null
509
- };
510
- /** version: 2.3.4 */
518
+ /** version: 2.5.1 */
511
519
 
512
520
  /* proxy-compat-disable */
513
521
 
@@ -518,6 +526,7 @@
518
526
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
519
527
  */
520
528
 
529
+
521
530
  var nextTickCallbackQueue = [];
522
531
  var SPACE_CHAR = 32;
523
532
  var EmptyObject = seal(create(null));
@@ -2213,12 +2222,6 @@
2213
2222
  associateVM(component, vm);
2214
2223
  associateVM(elm, vm);
2215
2224
 
2216
- if (!runtimeFlags.ENABLE_LIGHT_DOM_COMPONENTS) {
2217
- assert.isTrue(def.renderMode !== 0
2218
- /* Light */
2219
- , "".concat(def.name || 'Anonymous class', " is an invalid LWC component. Light DOM components are not available in this environment."));
2220
- }
2221
-
2222
2225
  if (vm.renderMode === 1
2223
2226
  /* Shadow */
2224
2227
  ) {
@@ -2239,7 +2242,7 @@
2239
2242
  var cmpRoot = renderer.attachShadow(elm, (_renderer$attachShado = {}, _defineProperty(_renderer$attachShado, KEY__SYNTHETIC_MODE, shadowMode === 1), _defineProperty(_renderer$attachShado, "delegatesFocus", Boolean(ctor.delegatesFocus)), _defineProperty(_renderer$attachShado, "mode", mode), _renderer$attachShado));
2240
2243
  vm.cmpRoot = cmpRoot;
2241
2244
  associateVM(cmpRoot, vm);
2242
- } // @ts-ignore
2245
+ }
2243
2246
 
2244
2247
 
2245
2248
  LightningElement.prototype = {
@@ -2693,8 +2696,15 @@
2693
2696
 
2694
2697
  descriptor = createPublicAccessorDescriptor(fieldName, descriptor);
2695
2698
  } else {
2699
+ // with the same name, the property is defined as a public accessor. This branch is
2700
+ // only here for backward compatibility reasons.
2701
+
2696
2702
 
2697
- descriptor = createPublicPropertyDescriptor(fieldName);
2703
+ if (!isUndefined$1(descriptor) && !isUndefined$1(descriptor.get)) {
2704
+ descriptor = createPublicAccessorDescriptor(fieldName, descriptor);
2705
+ } else {
2706
+ descriptor = createPublicPropertyDescriptor(fieldName);
2707
+ }
2698
2708
  }
2699
2709
 
2700
2710
  apiFields[fieldName] = descriptor;
@@ -2755,8 +2765,15 @@
2755
2765
  for (var _i9 = 0, n = fields.length; _i9 < n; _i9++) {
2756
2766
  var _fieldName2 = fields[_i9];
2757
2767
  descriptor = getOwnPropertyDescriptor$1(proto, _fieldName2);
2768
+ // tracked property. This is only here for backward compatibility purposes.
2769
+
2770
+
2771
+ var isDuplicatePublicProp = !isUndefined$1(publicProps) && _fieldName2 in publicProps;
2772
+ var isDuplicateTrackedProp = !isUndefined$1(track) && _fieldName2 in track;
2758
2773
 
2759
- observedFields[_fieldName2] = createObservedFieldPropertyDescriptor(_fieldName2);
2774
+ if (!isDuplicatePublicProp && !isDuplicateTrackedProp) {
2775
+ observedFields[_fieldName2] = createObservedFieldPropertyDescriptor(_fieldName2);
2776
+ }
2760
2777
  }
2761
2778
  }
2762
2779
 
@@ -3296,6 +3313,17 @@
3296
3313
 
3297
3314
  function setElementShadowToken(elm, token) {
3298
3315
  elm.$shadowToken$ = token;
3316
+ } // Set the scope token class for *.scoped.css styles
3317
+
3318
+
3319
+ function setScopeTokenClassIfNecessary(elm, owner) {
3320
+ var cmpTemplate = owner.cmpTemplate,
3321
+ context = owner.context;
3322
+ var token = cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken;
3323
+
3324
+ if (!isUndefined$1(token) && context.hasScopedStyles) {
3325
+ owner.renderer.getClassList(elm).add(token);
3326
+ }
3299
3327
  }
3300
3328
 
3301
3329
  function updateNodeHook(oldVnode, vnode) {
@@ -3336,12 +3364,13 @@
3336
3364
 
3337
3365
  function fallbackElmHook(elm, vnode) {
3338
3366
  var owner = vnode.owner;
3367
+ setScopeTokenClassIfNecessary(elm, owner);
3339
3368
 
3340
3369
  if (owner.shadowMode === 1
3341
3370
  /* Synthetic */
3342
3371
  ) {
3343
3372
  var context = vnode.data.context;
3344
- var shadowAttribute = owner.context.shadowAttribute;
3373
+ var stylesheetToken = owner.context.stylesheetToken;
3345
3374
 
3346
3375
  if (!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
3347
3376
  /* manual */
@@ -3352,7 +3381,7 @@
3352
3381
  // into each element from the template, so they can be styled accordingly.
3353
3382
 
3354
3383
 
3355
- setElementShadowToken(elm, shadowAttribute);
3384
+ setElementShadowToken(elm, stylesheetToken);
3356
3385
  }
3357
3386
  }
3358
3387
 
@@ -3417,14 +3446,15 @@
3417
3446
  mode = vnode.mode,
3418
3447
  ctor = vnode.ctor,
3419
3448
  owner = vnode.owner;
3449
+ setScopeTokenClassIfNecessary(elm, owner);
3420
3450
 
3421
3451
  if (owner.shadowMode === 1
3422
3452
  /* Synthetic */
3423
3453
  ) {
3424
- var shadowAttribute = owner.context.shadowAttribute; // when running in synthetic shadow mode, we need to set the shadowToken value
3454
+ var stylesheetToken = owner.context.stylesheetToken; // when running in synthetic shadow mode, we need to set the shadowToken value
3425
3455
  // into each element from the template, so they can be styled accordingly.
3426
3456
 
3427
- setElementShadowToken(elm, shadowAttribute);
3457
+ setElementShadowToken(elm, stylesheetToken);
3428
3458
  }
3429
3459
 
3430
3460
  var def = getComponentInternalDef(ctor);
@@ -3701,12 +3731,18 @@
3701
3731
  };
3702
3732
 
3703
3733
  function linkNodeToShadow(elm, owner) {
3704
- var shadowMode = owner.shadowMode; // TODO [#1164]: this should eventually be done by the polyfill directly
3734
+ var renderer = owner.renderer,
3735
+ renderMode = owner.renderMode,
3736
+ shadowMode = owner.shadowMode; // TODO [#1164]: this should eventually be done by the polyfill directly
3705
3737
 
3706
- if (shadowMode === 1
3707
- /* Synthetic */
3708
- ) {
3709
- elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
3738
+ if (renderer.isSyntheticShadowDefined) {
3739
+ if (shadowMode === 1
3740
+ /* Synthetic */
3741
+ || renderMode === 0
3742
+ /* Light */
3743
+ ) {
3744
+ elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
3745
+ }
3710
3746
  }
3711
3747
  }
3712
3748
 
@@ -3934,13 +3970,10 @@
3934
3970
  }
3935
3971
 
3936
3972
  var idx = vmBeingRendered.idx,
3937
- renderMode = vmBeingRendered.renderMode,
3938
3973
  shadowMode = vmBeingRendered.shadowMode;
3939
3974
 
3940
3975
  if (shadowMode === 1
3941
3976
  /* Synthetic */
3942
- && renderMode === 1
3943
- /* Shadow */
3944
3977
  ) {
3945
3978
  return StringReplace.call(id, /\S+/g, function (id) {
3946
3979
  return "".concat(id, "-").concat(idx);
@@ -3965,13 +3998,10 @@
3965
3998
  }
3966
3999
 
3967
4000
  var idx = vmBeingRendered.idx,
3968
- renderMode = vmBeingRendered.renderMode,
3969
4001
  shadowMode = vmBeingRendered.shadowMode; // Apply transformation only for fragment-only-urls, and only in shadow DOM
3970
4002
 
3971
4003
  if (shadowMode === 1
3972
4004
  /* Synthetic */
3973
- && renderMode === 1
3974
- /* Shadow */
3975
4005
  && /^#/.test(url)) {
3976
4006
  return "".concat(url, "-").concat(idx);
3977
4007
  }
@@ -4064,6 +4094,10 @@
4064
4094
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4065
4095
  */
4066
4096
 
4097
+ function makeHostToken(token) {
4098
+ return "".concat(token, "-host");
4099
+ }
4100
+
4067
4101
  function createInlineStyleVNode(content) {
4068
4102
  return h('style', {
4069
4103
  key: 'style',
@@ -4073,49 +4107,86 @@
4073
4107
  }, [t(content)]);
4074
4108
  }
4075
4109
 
4076
- function updateSyntheticShadowAttributes(vm, template) {
4110
+ function updateStylesheetToken(vm, template) {
4077
4111
  var elm = vm.elm,
4078
4112
  context = vm.context,
4079
4113
  renderer = vm.renderer,
4080
- renderMode = vm.renderMode;
4114
+ renderMode = vm.renderMode,
4115
+ shadowMode = vm.shadowMode;
4081
4116
  var newStylesheets = template.stylesheets,
4082
- newStylesheetTokens = template.stylesheetTokens;
4083
- var newTokens; // Reset the styling token applied to the host element.
4117
+ newStylesheetToken = template.stylesheetToken;
4118
+ var isSyntheticShadow = renderMode === 1
4119
+ /* Shadow */
4120
+ && shadowMode === 1
4121
+ /* Synthetic */
4122
+ ;
4123
+ var hasScopedStyles = context.hasScopedStyles;
4124
+ var newToken;
4125
+ var newHasTokenInClass;
4126
+ var newHasTokenInAttribute; // Reset the styling token applied to the host element.
4084
4127
 
4085
- var oldHostAttribute = context.hostAttribute;
4128
+ var oldToken = context.stylesheetToken,
4129
+ oldHasTokenInClass = context.hasTokenInClass,
4130
+ oldHasTokenInAttribute = context.hasTokenInAttribute;
4086
4131
 
4087
- if (!isUndefined$1(oldHostAttribute)) {
4088
- renderer.removeAttribute(elm, oldHostAttribute);
4132
+ if (oldHasTokenInClass) {
4133
+ renderer.getClassList(elm).remove(makeHostToken(oldToken));
4134
+ }
4135
+
4136
+ if (oldHasTokenInAttribute) {
4137
+ renderer.removeAttribute(elm, makeHostToken(oldToken));
4089
4138
  } // Apply the new template styling token to the host element, if the new template has any
4090
- // associated stylesheets.
4139
+ // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
4091
4140
 
4092
4141
 
4093
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0 && renderMode === 1
4094
- /* Shadow */
4095
- ) {
4096
- newTokens = newStylesheetTokens;
4097
- }
4142
+ if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
4143
+ newToken = newStylesheetToken;
4144
+ } // Set the new styling token on the host element
4145
+
4098
4146
 
4099
- if (!isUndefined$1(newTokens)) {
4100
- renderer.setAttribute(elm, newTokens.hostAttribute, '');
4147
+ if (!isUndefined$1(newToken)) {
4148
+ if (hasScopedStyles) {
4149
+ renderer.getClassList(elm).add(makeHostToken(newToken));
4150
+ newHasTokenInClass = true;
4151
+ }
4152
+
4153
+ if (isSyntheticShadow) {
4154
+ renderer.setAttribute(elm, makeHostToken(newToken), '');
4155
+ newHasTokenInAttribute = true;
4156
+ }
4101
4157
  } // Update the styling tokens present on the context object.
4102
4158
 
4103
4159
 
4104
- context.hostAttribute = newTokens === null || newTokens === void 0 ? void 0 : newTokens.hostAttribute;
4105
- context.shadowAttribute = newTokens === null || newTokens === void 0 ? void 0 : newTokens.shadowAttribute;
4160
+ context.stylesheetToken = newToken;
4161
+ context.hasTokenInClass = newHasTokenInClass;
4162
+ context.hasTokenInAttribute = newHasTokenInAttribute;
4106
4163
  }
4107
4164
 
4108
- function evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, nativeShadow) {
4165
+ function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
4109
4166
  var content = [];
4110
4167
 
4111
4168
  for (var _i12 = 0; _i12 < stylesheets.length; _i12++) {
4112
4169
  var stylesheet = stylesheets[_i12];
4113
4170
 
4114
4171
  if (isArray$1(stylesheet)) {
4115
- ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, hostSelector, shadowSelector, nativeShadow));
4172
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
4116
4173
  } else {
4117
-
4118
- ArrayPush$1.call(content, stylesheet(hostSelector, shadowSelector, nativeShadow));
4174
+ // native shadow DOM. Synthetic shadow DOM never uses `:host`.
4175
+
4176
+
4177
+ var isScopedCss = stylesheet[KEY__SCOPED_CSS];
4178
+ var useActualHostSelector = vm.renderMode === 0
4179
+ /* Light */
4180
+ ? !isScopedCss : vm.shadowMode === 0
4181
+ /* Native */
4182
+ ; // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
4183
+
4184
+ var scopeToken = isScopedCss || vm.shadowMode === 1
4185
+ /* Synthetic */
4186
+ && vm.renderMode === 1
4187
+ /* Shadow */
4188
+ ? stylesheetToken : undefined;
4189
+ ArrayPush$1.call(content, stylesheet(useActualHostSelector, scopeToken));
4119
4190
  }
4120
4191
  }
4121
4192
 
@@ -4124,34 +4195,35 @@
4124
4195
 
4125
4196
  function getStylesheetsContent(vm, template) {
4126
4197
  var stylesheets = template.stylesheets,
4127
- stylesheetTokens = template.stylesheetTokens;
4128
- var renderMode = vm.renderMode,
4129
- shadowMode = vm.shadowMode;
4198
+ stylesheetToken = template.stylesheetToken;
4130
4199
  var content = [];
4131
4200
 
4132
4201
  if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
4133
- var hostSelector;
4134
- var shadowSelector; // Scoping with the tokens is only necessary for synthetic shadow. For both
4135
- // light DOM elements and native shadow, we just render the CSS as-is.
4202
+ content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
4203
+ }
4204
+
4205
+ return content;
4206
+ } // It might be worth caching this to avoid doing the lookup repeatedly, but
4207
+ // perf testing has not shown it to be a huge improvement yet:
4208
+ // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
4209
+
4210
+
4211
+ function getNearestNativeShadowComponent(vm) {
4212
+ var owner = vm;
4136
4213
 
4137
- if (renderMode === 1
4214
+ while (!isNull(owner)) {
4215
+ if (owner.renderMode === 1
4138
4216
  /* Shadow */
4139
- && shadowMode === 1
4140
- /* Synthetic */
4141
- && !isUndefined$1(stylesheetTokens)) {
4142
- hostSelector = "[".concat(stylesheetTokens.hostAttribute, "]");
4143
- shadowSelector = "[".concat(stylesheetTokens.shadowAttribute, "]");
4144
- } else {
4145
- hostSelector = '';
4146
- shadowSelector = '';
4217
+ && owner.shadowMode === 0
4218
+ /* Native */
4219
+ ) {
4220
+ return owner;
4147
4221
  }
4148
4222
 
4149
- content = evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, shadowMode === 0
4150
- /* Native */
4151
- );
4223
+ owner = owner.owner;
4152
4224
  }
4153
4225
 
4154
- return content;
4226
+ return owner;
4155
4227
  }
4156
4228
 
4157
4229
  function createStylesheet(vm, stylesheets) {
@@ -4167,13 +4239,26 @@
4167
4239
  for (var _i13 = 0; _i13 < stylesheets.length; _i13++) {
4168
4240
  renderer.insertGlobalStylesheet(stylesheets[_i13]);
4169
4241
  }
4170
-
4171
- return null;
4172
- } else {
4173
- // native shadow or light DOM
4242
+ } else if (renderer.ssr) {
4243
+ // native shadow or light DOM, SSR
4174
4244
  var combinedStylesheetContent = ArrayJoin.call(stylesheets, '\n');
4175
4245
  return createInlineStyleVNode(combinedStylesheetContent);
4246
+ } else {
4247
+ // native shadow or light DOM, DOM renderer
4248
+ var root = getNearestNativeShadowComponent(vm);
4249
+ var isGlobal = isNull(root);
4250
+
4251
+ for (var _i14 = 0; _i14 < stylesheets.length; _i14++) {
4252
+ if (isGlobal) {
4253
+ renderer.insertGlobalStylesheet(stylesheets[_i14]);
4254
+ } else {
4255
+ // local level
4256
+ renderer.insertStylesheet(stylesheets[_i14], root.cmpRoot);
4257
+ }
4258
+ }
4176
4259
  }
4260
+
4261
+ return null;
4177
4262
  }
4178
4263
  /** Indicates if operations should be logged by the profiler. */
4179
4264
 
@@ -4290,8 +4375,7 @@
4290
4375
  context = vm.context,
4291
4376
  cmpSlots = vm.cmpSlots,
4292
4377
  cmpTemplate = vm.cmpTemplate,
4293
- tro = vm.tro,
4294
- shadowMode = vm.shadowMode;
4378
+ tro = vm.tro;
4295
4379
  tro.observe(function () {
4296
4380
  // Reset the cache memoizer for template when needed.
4297
4381
  if (html !== cmpTemplate) {
@@ -4313,15 +4397,12 @@
4313
4397
 
4314
4398
  vm.cmpTemplate = html; // Create a brand new template cache for the swapped templated.
4315
4399
 
4316
- context.tplCache = create(null); // Update the synthetic shadow attributes on the host element if necessary.
4400
+ context.tplCache = create(null); // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
4317
4401
 
4318
- if (shadowMode === 1
4319
- /* Synthetic */
4320
- ) {
4321
- updateSyntheticShadowAttributes(vm, html);
4322
- } // Evaluate, create stylesheet and cache the produced VNode for future
4323
- // re-rendering.
4402
+ context.hasScopedStyles = computeHasScopedStyles(html); // Update the scoping token on the host element.
4324
4403
 
4404
+ updateStylesheetToken(vm, html); // Evaluate, create stylesheet and cache the produced VNode for future
4405
+ // re-rendering.
4325
4406
 
4326
4407
  var stylesheetsContent = getStylesheetsContent(vm, html);
4327
4408
  context.styleVNode = stylesheetsContent.length === 0 ? null : createStylesheet(vm, stylesheetsContent);
@@ -4352,6 +4433,20 @@
4352
4433
 
4353
4434
  return vnodes;
4354
4435
  }
4436
+
4437
+ function computeHasScopedStyles(template) {
4438
+ var stylesheets = template.stylesheets;
4439
+
4440
+ if (!isUndefined$1(stylesheets)) {
4441
+ for (var _i15 = 0; _i15 < stylesheets.length; _i15++) {
4442
+ if (isTrue(stylesheets[_i15][KEY__SCOPED_CSS])) {
4443
+ return true;
4444
+ }
4445
+ }
4446
+ }
4447
+
4448
+ return false;
4449
+ }
4355
4450
  /*
4356
4451
  * Copyright (c) 2018, salesforce.com, inc.
4357
4452
  * All rights reserved.
@@ -4545,8 +4640,8 @@
4545
4640
 
4546
4641
  function register(service) {
4547
4642
 
4548
- for (var _i14 = 0; _i14 < hooks.length; ++_i14) {
4549
- var hookName = hooks[_i14];
4643
+ for (var _i16 = 0; _i16 < hooks.length; ++_i16) {
4644
+ var hookName = hooks[_i16];
4550
4645
 
4551
4646
  if (hookName in service) {
4552
4647
  var l = Services[hookName];
@@ -4566,8 +4661,8 @@
4566
4661
  def = vm.def,
4567
4662
  context = vm.context;
4568
4663
 
4569
- for (var _i15 = 0, _len6 = cbs.length; _i15 < _len6; ++_i15) {
4570
- cbs[_i15].call(undefined, component, {}, def, context);
4664
+ for (var _i17 = 0, _len6 = cbs.length; _i17 < _len6; ++_i17) {
4665
+ cbs[_i17].call(undefined, component, {}, def, context);
4571
4666
  }
4572
4667
  }
4573
4668
  /*
@@ -4578,7 +4673,6 @@
4578
4673
  */
4579
4674
 
4580
4675
 
4581
- var isNativeShadowRootDefined = _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED];
4582
4676
  var idx = 0;
4583
4677
  /** The internal slot used to associate different objects the engine manipulates with the VM */
4584
4678
 
@@ -4661,27 +4755,23 @@
4661
4755
  resetComponentStateWhenRemoved(vm);
4662
4756
  }
4663
4757
 
4758
+ function getNearestShadowAncestor(vm) {
4759
+ var ancestor = vm.owner;
4760
+
4761
+ while (!isNull(ancestor) && ancestor.renderMode === 0
4762
+ /* Light */
4763
+ ) {
4764
+ ancestor = ancestor.owner;
4765
+ }
4766
+
4767
+ return ancestor;
4768
+ }
4769
+
4664
4770
  function createVM(elm, def, options) {
4665
4771
  var mode = options.mode,
4666
4772
  owner = options.owner,
4667
4773
  renderer = options.renderer,
4668
4774
  tagName = options.tagName;
4669
- var shadowMode;
4670
-
4671
- if (renderer.syntheticShadow) {
4672
- shadowMode = def.shadowSupportMode === "any"
4673
- /* Any */
4674
- && isNativeShadowRootDefined ? 0
4675
- /* Native */
4676
- : 1
4677
- /* Synthetic */
4678
- ;
4679
- } else {
4680
- shadowMode = 0
4681
- /* Native */
4682
- ;
4683
- }
4684
-
4685
4775
  var vm = {
4686
4776
  elm: elm,
4687
4777
  def: def,
@@ -4704,10 +4794,12 @@
4704
4794
  oar: create(null),
4705
4795
  cmpTemplate: null,
4706
4796
  renderMode: def.renderMode,
4707
- shadowMode: shadowMode,
4797
+ shadowMode: null,
4708
4798
  context: {
4709
- hostAttribute: undefined,
4710
- shadowAttribute: undefined,
4799
+ stylesheetToken: undefined,
4800
+ hasTokenInClass: undefined,
4801
+ hasTokenInAttribute: undefined,
4802
+ hasScopedStyles: undefined,
4711
4803
  styleVNode: null,
4712
4804
  tplCache: EmptyObject,
4713
4805
  wiredConnecting: EmptyArray,
@@ -4720,18 +4812,77 @@
4720
4812
  setHook: setHook,
4721
4813
  getHook: getHook
4722
4814
  };
4815
+ vm.shadowMode = computeShadowMode(vm);
4723
4816
  vm.tro = getTemplateReactiveObserver(vm);
4724
4817
 
4725
4818
 
4726
4819
  invokeComponentConstructor(vm, def.ctor); // Initializing the wire decorator per instance only when really needed
4727
4820
 
4728
- if (isFalse(renderer.ssr) && hasWireAdapters(vm)) {
4821
+ if (hasWireAdapters(vm)) {
4729
4822
  installWireAdapters(vm);
4730
4823
  }
4731
4824
 
4732
4825
  return vm;
4733
4826
  }
4734
4827
 
4828
+ function computeShadowMode(vm) {
4829
+ var def = vm.def,
4830
+ renderer = vm.renderer;
4831
+ var isNativeShadowDefined = renderer.isNativeShadowDefined,
4832
+ isSyntheticShadowDefined = renderer.isSyntheticShadowDefined;
4833
+ var shadowMode;
4834
+
4835
+ if (isSyntheticShadowDefined) {
4836
+ if (def.renderMode === 0
4837
+ /* Light */
4838
+ ) {
4839
+ // ShadowMode.Native implies "not synthetic shadow" which is consistent with how
4840
+ // everything defaults to native when the synthetic shadow polyfill is unavailable.
4841
+ shadowMode = 0
4842
+ /* Native */
4843
+ ;
4844
+ } else if (isNativeShadowDefined) {
4845
+ if (def.shadowSupportMode === "any"
4846
+ /* Any */
4847
+ ) {
4848
+ shadowMode = 0
4849
+ /* Native */
4850
+ ;
4851
+ } else {
4852
+ var shadowAncestor = getNearestShadowAncestor(vm);
4853
+
4854
+ if (!isNull(shadowAncestor) && shadowAncestor.shadowMode === 0
4855
+ /* Native */
4856
+ ) {
4857
+ // Transitive support for native Shadow DOM. A component in native mode
4858
+ // transitively opts all of its descendants into native.
4859
+ shadowMode = 0
4860
+ /* Native */
4861
+ ;
4862
+ } else {
4863
+ // Synthetic if neither this component nor any of its ancestors are configured
4864
+ // to be native.
4865
+ shadowMode = 1
4866
+ /* Synthetic */
4867
+ ;
4868
+ }
4869
+ }
4870
+ } else {
4871
+ // Synthetic if there is no native Shadow DOM support.
4872
+ shadowMode = 1
4873
+ /* Synthetic */
4874
+ ;
4875
+ }
4876
+ } else {
4877
+ // Native if the synthetic shadow polyfill is unavailable.
4878
+ shadowMode = 0
4879
+ /* Native */
4880
+ ;
4881
+ }
4882
+
4883
+ return shadowMode;
4884
+ }
4885
+
4735
4886
  function associateVM(obj, vm) {
4736
4887
  ViewModelReflection.set(obj, vm);
4737
4888
  }
@@ -4831,19 +4982,19 @@
4831
4982
  });
4832
4983
  rehydrateQueue = []; // reset to a new queue
4833
4984
 
4834
- for (var _i16 = 0, _len7 = vms.length; _i16 < _len7; _i16 += 1) {
4835
- var vm = vms[_i16];
4985
+ for (var _i18 = 0, _len7 = vms.length; _i18 < _len7; _i18 += 1) {
4986
+ var vm = vms[_i18];
4836
4987
 
4837
4988
  try {
4838
4989
  rehydrate(vm);
4839
4990
  } catch (error) {
4840
- if (_i16 + 1 < _len7) {
4991
+ if (_i18 + 1 < _len7) {
4841
4992
  // pieces of the queue are still pending to be rehydrated, those should have priority
4842
4993
  if (rehydrateQueue.length === 0) {
4843
4994
  addCallbackToNextTick(flushRehydrationQueue);
4844
4995
  }
4845
4996
 
4846
- ArrayUnshift.apply(rehydrateQueue, ArraySlice.call(vms, _i16 + 1));
4997
+ ArrayUnshift.apply(rehydrateQueue, ArraySlice.call(vms, _i18 + 1));
4847
4998
  } // we need to end the measure before throwing.
4848
4999
 
4849
5000
 
@@ -4942,8 +5093,8 @@
4942
5093
  var vCustomElementCollection = vm.velements; // Reporting disconnection for every child in inverse order since they are
4943
5094
  // inserted in reserved order.
4944
5095
 
4945
- for (var _i17 = vCustomElementCollection.length - 1; _i17 >= 0; _i17 -= 1) {
4946
- var elm = vCustomElementCollection[_i17].elm; // There are two cases where the element could be undefined:
5096
+ for (var _i19 = vCustomElementCollection.length - 1; _i19 >= 0; _i19 -= 1) {
5097
+ var elm = vCustomElementCollection[_i19].elm; // There are two cases where the element could be undefined:
4947
5098
  // * when there is an error during the construction phase, and an error
4948
5099
  // boundary picks it, there is a possibility that the VCustomElement
4949
5100
  // is not properly initialized, and therefore is should be ignored.
@@ -4977,8 +5128,8 @@
4977
5128
 
4978
5129
 
4979
5130
  function recursivelyDisconnectChildren(vnodes) {
4980
- for (var _i18 = 0, _len8 = vnodes.length; _i18 < _len8; _i18 += 1) {
4981
- var vnode = vnodes[_i18];
5131
+ for (var _i20 = 0, _len8 = vnodes.length; _i20 < _len8; _i20 += 1) {
5132
+ var vnode = vnodes[_i20];
4982
5133
 
4983
5134
  if (!isNull(vnode) && isArray$1(vnode.children) && !isUndefined$1(vnode.elm)) {
4984
5135
  // vnode is a VElement with children
@@ -5002,8 +5153,8 @@
5002
5153
  renderer = vm.renderer;
5003
5154
  var rootNode = getRenderRoot(vm);
5004
5155
 
5005
- for (var _i19 = 0, _len9 = children.length; _i19 < _len9; _i19++) {
5006
- var child = children[_i19];
5156
+ for (var _i21 = 0, _len9 = children.length; _i21 < _len9; _i21++) {
5157
+ var child = children[_i21];
5007
5158
 
5008
5159
  if (!isNull(child) && !isUndefined$1(child.elm)) {
5009
5160
  renderer.remove(child.elm, rootNode);
@@ -5048,8 +5199,8 @@
5048
5199
  var oldSlots = vm.cmpSlots;
5049
5200
  var cmpSlots = vm.cmpSlots = create(null);
5050
5201
 
5051
- for (var _i20 = 0, _len10 = children.length; _i20 < _len10; _i20 += 1) {
5052
- var vnode = children[_i20];
5202
+ for (var _i22 = 0, _len10 = children.length; _i22 < _len10; _i22 += 1) {
5203
+ var vnode = children[_i22];
5053
5204
 
5054
5205
  if (isNull(vnode)) {
5055
5206
  continue;
@@ -5079,8 +5230,8 @@
5079
5230
  return;
5080
5231
  }
5081
5232
 
5082
- for (var _i21 = 0, _len11 = oldKeys.length; _i21 < _len11; _i21 += 1) {
5083
- var key = oldKeys[_i21];
5233
+ for (var _i23 = 0, _len11 = oldKeys.length; _i23 < _len11; _i23 += 1) {
5234
+ var key = oldKeys[_i23];
5084
5235
 
5085
5236
  if (isUndefined$1(cmpSlots[key]) || oldSlots[key].length !== cmpSlots[key].length) {
5086
5237
  markComponentAsDirty(vm);
@@ -5398,11 +5549,14 @@
5398
5549
  ArrayPush$1.call(wiredConnecting, function () {
5399
5550
  connector.connect();
5400
5551
 
5401
- if (hasDynamicParams) {
5402
- Promise.resolve().then(computeConfigAndUpdate);
5403
- } else {
5404
- computeConfigAndUpdate();
5552
+ if (!runtimeFlags.ENABLE_WIRE_SYNC_EMIT) {
5553
+ if (hasDynamicParams) {
5554
+ Promise.resolve().then(computeConfigAndUpdate);
5555
+ return;
5556
+ }
5405
5557
  }
5558
+
5559
+ computeConfigAndUpdate();
5406
5560
  });
5407
5561
  ArrayPush$1.call(wiredDisconnecting, function () {
5408
5562
  connector.disconnect();
@@ -5416,8 +5570,8 @@
5416
5570
  function connectWireAdapters(vm) {
5417
5571
  var wiredConnecting = vm.context.wiredConnecting;
5418
5572
 
5419
- for (var _i22 = 0, _len12 = wiredConnecting.length; _i22 < _len12; _i22 += 1) {
5420
- wiredConnecting[_i22]();
5573
+ for (var _i24 = 0, _len12 = wiredConnecting.length; _i24 < _len12; _i24 += 1) {
5574
+ wiredConnecting[_i24]();
5421
5575
  }
5422
5576
  }
5423
5577
 
@@ -5425,8 +5579,8 @@
5425
5579
  var wiredDisconnecting = vm.context.wiredDisconnecting;
5426
5580
  runWithBoundaryProtection(vm, vm, noop, function () {
5427
5581
  // job
5428
- for (var _i23 = 0, _len13 = wiredDisconnecting.length; _i23 < _len13; _i23 += 1) {
5429
- wiredDisconnecting[_i23]();
5582
+ for (var _i25 = 0, _len13 = wiredDisconnecting.length; _i25 < _len13; _i25 += 1) {
5583
+ wiredDisconnecting[_i25]();
5430
5584
  }
5431
5585
  }, noop);
5432
5586
  }
@@ -5495,7 +5649,7 @@
5495
5649
 
5496
5650
  return reactiveMembrane.getReadOnlyProxy(obj);
5497
5651
  }
5498
- /* version: 2.3.4 */
5652
+ /* version: 2.5.1 */
5499
5653
 
5500
5654
  /*
5501
5655
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5508,6 +5662,10 @@
5508
5662
  var globalStylesheets = create(null);
5509
5663
 
5510
5664
  var globalStylesheetsParentElement = document.head || document.body || document;
5665
+ var supportsConstructableStyleSheets = isFunction$1(CSSStyleSheet.prototype.replaceSync);
5666
+ var styleElements = create(null);
5667
+ var styleSheets = create(null);
5668
+ var nodesToStyleSheets = new WeakMap();
5511
5669
  var getCustomElement, defineCustomElement, HTMLElementConstructor;
5512
5670
 
5513
5671
  function isCustomElementRegistryAvailable() {
@@ -5546,6 +5704,52 @@
5546
5704
  }
5547
5705
  }
5548
5706
 
5707
+ function insertConstructableStyleSheet(content, target) {
5708
+ // It's important for CSSStyleSheets to be unique based on their content, so that
5709
+ // `shadowRoot.adoptedStyleSheets.includes(sheet)` works.
5710
+ var styleSheet = styleSheets[content];
5711
+
5712
+ if (isUndefined$1(styleSheet)) {
5713
+ styleSheet = new CSSStyleSheet();
5714
+ styleSheet.replaceSync(content);
5715
+ styleSheets[content] = styleSheet;
5716
+ }
5717
+
5718
+ if (!target.adoptedStyleSheets.includes(styleSheet)) {
5719
+ target.adoptedStyleSheets = [].concat(_toConsumableArray(target.adoptedStyleSheets), [styleSheet]);
5720
+ }
5721
+ }
5722
+
5723
+ function insertStyleElement(content, target) {
5724
+ // Avoid inserting duplicate `<style>`s
5725
+ var sheets = nodesToStyleSheets.get(target);
5726
+
5727
+ if (isUndefined$1(sheets)) {
5728
+ sheets = create(null);
5729
+ nodesToStyleSheets.set(target, sheets);
5730
+ }
5731
+
5732
+ if (sheets[content]) {
5733
+ return;
5734
+ }
5735
+
5736
+ sheets[content] = true; // This `<style>` may be repeated multiple times in the DOM, so cache it. It's a bit
5737
+ // faster to call `cloneNode()` on an existing node than to recreate it every time.
5738
+
5739
+ var elm = styleElements[content];
5740
+
5741
+ if (isUndefined$1(elm)) {
5742
+ elm = document.createElement('style');
5743
+ elm.type = 'text/css';
5744
+ elm.textContent = content;
5745
+ styleElements[content] = elm;
5746
+ } else {
5747
+ elm = elm.cloneNode(true);
5748
+ }
5749
+
5750
+ target.appendChild(elm);
5751
+ }
5752
+
5549
5753
  if (isCustomElementRegistryAvailable()) {
5550
5754
  getCustomElement = customElements.get.bind(customElements);
5551
5755
  defineCustomElement = customElements.define.bind(customElements);
@@ -5589,7 +5793,8 @@
5589
5793
 
5590
5794
  var renderer = {
5591
5795
  ssr: false,
5592
- syntheticShadow: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
5796
+ isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
5797
+ isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
5593
5798
  createElement: function createElement(tagName, namespace) {
5594
5799
  return isUndefined$1(namespace) ? document.createElement(tagName) : document.createElementNS(namespace, tagName);
5595
5800
  },
@@ -5680,6 +5885,14 @@
5680
5885
  elm.textContent = content;
5681
5886
  globalStylesheetsParentElement.appendChild(elm);
5682
5887
  },
5888
+ insertStylesheet: function insertStylesheet(content, target) {
5889
+ if (supportsConstructableStyleSheets) {
5890
+ insertConstructableStyleSheet(content, target);
5891
+ } else {
5892
+ // Fall back to <style> element
5893
+ insertStyleElement(content, target);
5894
+ }
5895
+ },
5683
5896
  assertInstanceOfHTMLElement: function assertInstanceOfHTMLElement(elm, msg) {
5684
5897
  assert.invariant(elm instanceof HTMLElement, msg);
5685
5898
  },
@@ -5914,7 +6127,7 @@
5914
6127
  return false;
5915
6128
  }
5916
6129
 
5917
- if (renderer.syntheticShadow) {
6130
+ if (renderer.isSyntheticShadowDefined) {
5918
6131
  // TODO [#1252]: old behavior that is still used by some pieces of the platform,
5919
6132
  // specifically, nodes inserted manually on places where `lwc:dom="manual"` directive is not
5920
6133
  // used, will be considered global elements.
@@ -5966,7 +6179,7 @@
5966
6179
  });
5967
6180
  freeze(LightningElement);
5968
6181
  seal(LightningElement.prototype);
5969
- /* version: 2.3.4 */
6182
+ /* version: 2.5.1 */
5970
6183
 
5971
6184
  exports.LightningElement = LightningElement;
5972
6185
  exports.__unstable__ProfilerControl = profilerControl;