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