lwc 2.20.2 → 2.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +203 -171
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +203 -171
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +193 -161
  5. package/dist/engine-dom/iife/es5/engine-dom.js +288 -254
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +278 -243
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +203 -171
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +193 -161
  11. package/dist/engine-dom/umd/es5/engine-dom.js +288 -254
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +278 -243
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +280 -258
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +280 -258
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +3 -3
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +3 -3
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +3 -3
  20. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +3 -3
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +3 -3
  22. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +3 -3
  23. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +3 -3
  24. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +3 -3
  25. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +3 -3
  26. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  27. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  28. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  29. package/dist/wire-service/iife/es5/wire-service.js +2 -2
  30. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  31. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/umd/es5/wire-service.js +2 -2
  34. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  35. package/package.json +7 -7
@@ -294,7 +294,7 @@
294
294
  CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
295
295
  return attributeName;
296
296
  }
297
- /** version: 2.20.2 */
297
+ /** version: 2.21.0 */
298
298
 
299
299
  /*
300
300
  * Copyright (c) 2018, salesforce.com, inc.
@@ -2293,6 +2293,167 @@
2293
2293
  };
2294
2294
  }
2295
2295
 
2296
+ /*
2297
+ * Copyright (c) 2018, salesforce.com, inc.
2298
+ * All rights reserved.
2299
+ * SPDX-License-Identifier: MIT
2300
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2301
+ */
2302
+ function makeHostToken(token) {
2303
+ return `${token}-host`;
2304
+ }
2305
+ function createInlineStyleVNode(content) {
2306
+ return api.h('style', {
2307
+ key: 'style',
2308
+ attrs: {
2309
+ type: 'text/css',
2310
+ },
2311
+ }, [api.t(content)]);
2312
+ }
2313
+ function updateStylesheetToken(vm, template) {
2314
+ const { elm, context, renderMode, shadowMode, renderer: { getClassList, removeAttribute, setAttribute }, } = vm;
2315
+ const { stylesheets: newStylesheets, stylesheetToken: newStylesheetToken } = template;
2316
+ const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
2317
+ const { hasScopedStyles } = context;
2318
+ let newToken;
2319
+ let newHasTokenInClass;
2320
+ let newHasTokenInAttribute;
2321
+ // Reset the styling token applied to the host element.
2322
+ const { stylesheetToken: oldToken, hasTokenInClass: oldHasTokenInClass, hasTokenInAttribute: oldHasTokenInAttribute, } = context;
2323
+ if (!isUndefined$1(oldToken)) {
2324
+ if (oldHasTokenInClass) {
2325
+ getClassList(elm).remove(makeHostToken(oldToken));
2326
+ }
2327
+ if (oldHasTokenInAttribute) {
2328
+ removeAttribute(elm, makeHostToken(oldToken));
2329
+ }
2330
+ }
2331
+ // Apply the new template styling token to the host element, if the new template has any
2332
+ // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
2333
+ if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
2334
+ newToken = newStylesheetToken;
2335
+ }
2336
+ // Set the new styling token on the host element
2337
+ if (!isUndefined$1(newToken)) {
2338
+ if (hasScopedStyles) {
2339
+ getClassList(elm).add(makeHostToken(newToken));
2340
+ newHasTokenInClass = true;
2341
+ }
2342
+ if (isSyntheticShadow) {
2343
+ setAttribute(elm, makeHostToken(newToken), '');
2344
+ newHasTokenInAttribute = true;
2345
+ }
2346
+ }
2347
+ // Update the styling tokens present on the context object.
2348
+ context.stylesheetToken = newToken;
2349
+ context.hasTokenInClass = newHasTokenInClass;
2350
+ context.hasTokenInAttribute = newHasTokenInAttribute;
2351
+ }
2352
+ function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
2353
+ const content = [];
2354
+ let root;
2355
+ for (let i = 0; i < stylesheets.length; i++) {
2356
+ let stylesheet = stylesheets[i];
2357
+ if (isArray$1(stylesheet)) {
2358
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
2359
+ }
2360
+ else {
2361
+ const isScopedCss = stylesheet[KEY__SCOPED_CSS];
2362
+ // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
2363
+ const scopeToken = isScopedCss ||
2364
+ (vm.shadowMode === 1 /* ShadowMode.Synthetic */ && vm.renderMode === 1 /* RenderMode.Shadow */)
2365
+ ? stylesheetToken
2366
+ : undefined;
2367
+ // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
2368
+ // native shadow DOM. Synthetic shadow DOM never uses `:host`.
2369
+ const useActualHostSelector = vm.renderMode === 0 /* RenderMode.Light */
2370
+ ? !isScopedCss
2371
+ : vm.shadowMode === 0 /* ShadowMode.Native */;
2372
+ // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
2373
+ // we use an attribute selector on the host to simulate :dir().
2374
+ let useNativeDirPseudoclass;
2375
+ if (vm.renderMode === 1 /* RenderMode.Shadow */) {
2376
+ useNativeDirPseudoclass = vm.shadowMode === 0 /* ShadowMode.Native */;
2377
+ }
2378
+ else {
2379
+ // Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
2380
+ // At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
2381
+ if (isUndefined$1(root)) {
2382
+ // Only calculate the root once as necessary
2383
+ root = getNearestShadowComponent(vm);
2384
+ }
2385
+ useNativeDirPseudoclass = isNull(root) || root.shadowMode === 0 /* ShadowMode.Native */;
2386
+ }
2387
+ ArrayPush$1.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
2388
+ }
2389
+ }
2390
+ return content;
2391
+ }
2392
+ function getStylesheetsContent(vm, template) {
2393
+ const { stylesheets, stylesheetToken } = template;
2394
+ let content = [];
2395
+ if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
2396
+ content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
2397
+ }
2398
+ return content;
2399
+ }
2400
+ // It might be worth caching this to avoid doing the lookup repeatedly, but
2401
+ // perf testing has not shown it to be a huge improvement yet:
2402
+ // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
2403
+ function getNearestShadowComponent(vm) {
2404
+ let owner = vm;
2405
+ while (!isNull(owner)) {
2406
+ if (owner.renderMode === 1 /* RenderMode.Shadow */) {
2407
+ return owner;
2408
+ }
2409
+ owner = owner.owner;
2410
+ }
2411
+ return owner;
2412
+ }
2413
+ /**
2414
+ * If the component that is currently being rendered uses scoped styles,
2415
+ * this returns the unique token for that scoped stylesheet. Otherwise
2416
+ * it returns null.
2417
+ */
2418
+ function getScopeTokenClass(owner) {
2419
+ const { cmpTemplate, context } = owner;
2420
+ return (context.hasScopedStyles && (cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken)) || null;
2421
+ }
2422
+ function getNearestNativeShadowComponent(vm) {
2423
+ const owner = getNearestShadowComponent(vm);
2424
+ if (!isNull(owner) && owner.shadowMode === 1 /* ShadowMode.Synthetic */) {
2425
+ // Synthetic-within-native is impossible. So if the nearest shadow component is
2426
+ // synthetic, we know we won't find a native component if we go any further.
2427
+ return null;
2428
+ }
2429
+ return owner;
2430
+ }
2431
+ function createStylesheet(vm, stylesheets) {
2432
+ const { renderMode, shadowMode, renderer: { ssr, insertStylesheet }, } = vm;
2433
+ if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
2434
+ for (let i = 0; i < stylesheets.length; i++) {
2435
+ insertStylesheet(stylesheets[i]);
2436
+ }
2437
+ }
2438
+ else if (ssr || vm.hydrated) {
2439
+ // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
2440
+ // This works in the client, because the stylesheets are created, and cached in the VM
2441
+ // the first time the VM renders.
2442
+ // native shadow or light DOM, SSR
2443
+ return ArrayMap.call(stylesheets, createInlineStyleVNode);
2444
+ }
2445
+ else {
2446
+ // native shadow or light DOM, DOM renderer
2447
+ const root = getNearestNativeShadowComponent(vm);
2448
+ // null root means a global style
2449
+ const target = isNull(root) ? undefined : root.shadowRoot;
2450
+ for (let i = 0; i < stylesheets.length; i++) {
2451
+ insertStylesheet(stylesheets[i], target);
2452
+ }
2453
+ }
2454
+ return null;
2455
+ }
2456
+
2296
2457
  /*
2297
2458
  * Copyright (c) 2020, salesforce.com, inc.
2298
2459
  * All rights reserved.
@@ -2785,10 +2946,9 @@
2785
2946
  }
2786
2947
  // Set the scope token class for *.scoped.css styles
2787
2948
  function setScopeTokenClassIfNecessary(elm, owner, renderer) {
2788
- const { cmpTemplate, context } = owner;
2789
- const { getClassList } = renderer;
2790
- const token = cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken;
2791
- if (!isUndefined$1(token) && context.hasScopedStyles) {
2949
+ const token = getScopeTokenClass(owner);
2950
+ if (!isNull(token)) {
2951
+ const { getClassList } = renderer;
2792
2952
  // TODO [#2762]: this dot notation with add is probably problematic
2793
2953
  // probably we should have a renderer api for just the add operation
2794
2954
  getClassList(elm).add(token);
@@ -3408,158 +3568,6 @@
3408
3568
  fid,
3409
3569
  shc,
3410
3570
  });
3411
-
3412
- /*
3413
- * Copyright (c) 2018, salesforce.com, inc.
3414
- * All rights reserved.
3415
- * SPDX-License-Identifier: MIT
3416
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3417
- */
3418
- function makeHostToken(token) {
3419
- return `${token}-host`;
3420
- }
3421
- function createInlineStyleVNode(content) {
3422
- return api.h('style', {
3423
- key: 'style',
3424
- attrs: {
3425
- type: 'text/css',
3426
- },
3427
- }, [api.t(content)]);
3428
- }
3429
- function updateStylesheetToken(vm, template) {
3430
- const { elm, context, renderMode, shadowMode, renderer: { getClassList, removeAttribute, setAttribute }, } = vm;
3431
- const { stylesheets: newStylesheets, stylesheetToken: newStylesheetToken } = template;
3432
- const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
3433
- const { hasScopedStyles } = context;
3434
- let newToken;
3435
- let newHasTokenInClass;
3436
- let newHasTokenInAttribute;
3437
- // Reset the styling token applied to the host element.
3438
- const { stylesheetToken: oldToken, hasTokenInClass: oldHasTokenInClass, hasTokenInAttribute: oldHasTokenInAttribute, } = context;
3439
- if (!isUndefined$1(oldToken)) {
3440
- if (oldHasTokenInClass) {
3441
- getClassList(elm).remove(makeHostToken(oldToken));
3442
- }
3443
- if (oldHasTokenInAttribute) {
3444
- removeAttribute(elm, makeHostToken(oldToken));
3445
- }
3446
- }
3447
- // Apply the new template styling token to the host element, if the new template has any
3448
- // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
3449
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
3450
- newToken = newStylesheetToken;
3451
- }
3452
- // Set the new styling token on the host element
3453
- if (!isUndefined$1(newToken)) {
3454
- if (hasScopedStyles) {
3455
- getClassList(elm).add(makeHostToken(newToken));
3456
- newHasTokenInClass = true;
3457
- }
3458
- if (isSyntheticShadow) {
3459
- setAttribute(elm, makeHostToken(newToken), '');
3460
- newHasTokenInAttribute = true;
3461
- }
3462
- }
3463
- // Update the styling tokens present on the context object.
3464
- context.stylesheetToken = newToken;
3465
- context.hasTokenInClass = newHasTokenInClass;
3466
- context.hasTokenInAttribute = newHasTokenInAttribute;
3467
- }
3468
- function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
3469
- const content = [];
3470
- let root;
3471
- for (let i = 0; i < stylesheets.length; i++) {
3472
- let stylesheet = stylesheets[i];
3473
- if (isArray$1(stylesheet)) {
3474
- ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
3475
- }
3476
- else {
3477
- const isScopedCss = stylesheet[KEY__SCOPED_CSS];
3478
- // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
3479
- const scopeToken = isScopedCss ||
3480
- (vm.shadowMode === 1 /* ShadowMode.Synthetic */ && vm.renderMode === 1 /* RenderMode.Shadow */)
3481
- ? stylesheetToken
3482
- : undefined;
3483
- // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
3484
- // native shadow DOM. Synthetic shadow DOM never uses `:host`.
3485
- const useActualHostSelector = vm.renderMode === 0 /* RenderMode.Light */
3486
- ? !isScopedCss
3487
- : vm.shadowMode === 0 /* ShadowMode.Native */;
3488
- // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
3489
- // we use an attribute selector on the host to simulate :dir().
3490
- let useNativeDirPseudoclass;
3491
- if (vm.renderMode === 1 /* RenderMode.Shadow */) {
3492
- useNativeDirPseudoclass = vm.shadowMode === 0 /* ShadowMode.Native */;
3493
- }
3494
- else {
3495
- // Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
3496
- // At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
3497
- if (isUndefined$1(root)) {
3498
- // Only calculate the root once as necessary
3499
- root = getNearestShadowComponent(vm);
3500
- }
3501
- useNativeDirPseudoclass = isNull(root) || root.shadowMode === 0 /* ShadowMode.Native */;
3502
- }
3503
- ArrayPush$1.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
3504
- }
3505
- }
3506
- return content;
3507
- }
3508
- function getStylesheetsContent(vm, template) {
3509
- const { stylesheets, stylesheetToken } = template;
3510
- let content = [];
3511
- if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
3512
- content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
3513
- }
3514
- return content;
3515
- }
3516
- // It might be worth caching this to avoid doing the lookup repeatedly, but
3517
- // perf testing has not shown it to be a huge improvement yet:
3518
- // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
3519
- function getNearestShadowComponent(vm) {
3520
- let owner = vm;
3521
- while (!isNull(owner)) {
3522
- if (owner.renderMode === 1 /* RenderMode.Shadow */) {
3523
- return owner;
3524
- }
3525
- owner = owner.owner;
3526
- }
3527
- return owner;
3528
- }
3529
- function getNearestNativeShadowComponent(vm) {
3530
- const owner = getNearestShadowComponent(vm);
3531
- if (!isNull(owner) && owner.shadowMode === 1 /* ShadowMode.Synthetic */) {
3532
- // Synthetic-within-native is impossible. So if the nearest shadow component is
3533
- // synthetic, we know we won't find a native component if we go any further.
3534
- return null;
3535
- }
3536
- return owner;
3537
- }
3538
- function createStylesheet(vm, stylesheets) {
3539
- const { renderMode, shadowMode, renderer: { ssr, insertStylesheet }, } = vm;
3540
- if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
3541
- for (let i = 0; i < stylesheets.length; i++) {
3542
- insertStylesheet(stylesheets[i]);
3543
- }
3544
- }
3545
- else if (ssr || vm.hydrated) {
3546
- // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
3547
- // This works in the client, because the stylesheets are created, and cached in the VM
3548
- // the first time the VM renders.
3549
- // native shadow or light DOM, SSR
3550
- return ArrayMap.call(stylesheets, createInlineStyleVNode);
3551
- }
3552
- else {
3553
- // native shadow or light DOM, DOM renderer
3554
- const root = getNearestNativeShadowComponent(vm);
3555
- // null root means a global style
3556
- const target = isNull(root) ? undefined : root.shadowRoot;
3557
- for (let i = 0; i < stylesheets.length; i++) {
3558
- insertStylesheet(stylesheets[i], target);
3559
- }
3560
- }
3561
- return null;
3562
- }
3563
3571
  /** Indicates if operations should be logged by the profiler. */
3564
3572
  let isProfilerEnabled = false;
3565
3573
  /** The currently assigned profiler dispatcher. */
@@ -5085,8 +5093,24 @@
5085
5093
  return nodesAreCompatible;
5086
5094
  }
5087
5095
  function validateClassAttr(vnode, elm, renderer) {
5088
- const { data: { className, classMap }, } = vnode;
5096
+ const { data, owner } = vnode;
5097
+ let { className, classMap } = data;
5089
5098
  const { getProperty, getClassList } = renderer;
5099
+ const scopedToken = getScopeTokenClass(owner);
5100
+ // Classnames for scoped CSS are added directly to the DOM during rendering,
5101
+ // or to the VDOM on the server in the case of SSR. As such, these classnames
5102
+ // are never present in VDOM nodes in the browser.
5103
+ //
5104
+ // Consequently, hydration mismatches will occur if scoped CSS token classnames
5105
+ // are rendered during SSR. This needs to be accounted for when validating.
5106
+ if (scopedToken) {
5107
+ if (!isUndefined$1(className)) {
5108
+ className = `${scopedToken} ${className}`;
5109
+ }
5110
+ else if (!isUndefined$1(classMap)) {
5111
+ classMap = Object.assign(Object.assign({}, classMap), { [scopedToken]: true });
5112
+ }
5113
+ }
5090
5114
  let nodesAreCompatible = true;
5091
5115
  if (!isUndefined$1(className) && String(className) !== getProperty(elm, 'className')) {
5092
5116
  // className is used when class is bound to an expr.
@@ -5213,7 +5237,7 @@
5213
5237
  }
5214
5238
  return ctor;
5215
5239
  }
5216
- /* version: 2.20.2 */
5240
+ /* version: 2.21.0 */
5217
5241
 
5218
5242
  /*
5219
5243
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5450,7 +5474,15 @@
5450
5474
  return node.nextSibling;
5451
5475
  }
5452
5476
  function attachShadow(element, options) {
5453
- if (hydrating) {
5477
+ // `hydrating` will be true in two cases:
5478
+ // 1. upon initial load with an SSR-generated DOM, while in Shadow render mode
5479
+ // 2. when a webapp author places <c-app> in their static HTML and mounts their
5480
+ // root component with customeElement.define('c-app', Ctor)
5481
+ //
5482
+ // The second case can be treated as a failed hydration with nominal impact
5483
+ // to performance. However, because <c-app> won't have a <template shadowroot>
5484
+ // declarative child, `element.shadowRoot` is `null`.
5485
+ if (hydrating && element.shadowRoot) {
5454
5486
  return element.shadowRoot;
5455
5487
  }
5456
5488
  return element.attachShadow(options);
@@ -5870,7 +5902,7 @@
5870
5902
  });
5871
5903
  freeze(LightningElement);
5872
5904
  seal(LightningElement.prototype);
5873
- /* version: 2.20.2 */
5905
+ /* version: 2.21.0 */
5874
5906
 
5875
5907
  exports.LightningElement = LightningElement;
5876
5908
  exports.__unstable__ProfilerControl = profilerControl;