lwc 2.5.6 → 2.5.10

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 +605 -181
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +605 -181
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +2 -2
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +406 -169
  5. package/dist/engine-dom/iife/es5/engine-dom.js +684 -242
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +2 -2
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +466 -221
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +605 -181
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +2 -2
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +406 -169
  11. package/dist/engine-dom/umd/es5/engine-dom.js +684 -242
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +2 -2
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +466 -221
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +484 -133
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +2 -2
  16. package/dist/engine-server/esm/es2017/engine-server.js +485 -133
  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 +8 -8
@@ -69,7 +69,7 @@ const {
69
69
  find: ArrayFind,
70
70
  indexOf: ArrayIndexOf,
71
71
  join: ArrayJoin,
72
- map: ArrayMap$1,
72
+ map: ArrayMap,
73
73
  push: ArrayPush$1,
74
74
  reduce: ArrayReduce,
75
75
  reverse: ArrayReverse,
@@ -136,7 +136,7 @@ function toString$1(obj) {
136
136
  // Array.prototype.toString directly will cause an error Iterate through
137
137
  // all the items and handle individually.
138
138
  if (isArray$1(obj)) {
139
- return ArrayJoin.call(ArrayMap$1.call(obj, toString$1), ',');
139
+ return ArrayJoin.call(ArrayMap.call(obj, toString$1), ',');
140
140
  }
141
141
 
142
142
  return obj.toString();
@@ -299,7 +299,7 @@ function htmlPropertyToAttribute(propName) {
299
299
  CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
300
300
  return attributeName;
301
301
  }
302
- /** version: 2.5.6 */
302
+ /** version: 2.5.10 */
303
303
 
304
304
  /*
305
305
  * Copyright (c) 2018, salesforce.com, inc.
@@ -479,7 +479,7 @@ function setFeatureFlagForTest(name, value) {
479
479
  setFeatureFlag(name, value);
480
480
  }
481
481
  }
482
- /** version: 2.5.6 */
482
+ /** version: 2.5.10 */
483
483
 
484
484
  /* proxy-compat-disable */
485
485
 
@@ -531,6 +531,28 @@ function guid() {
531
531
  }
532
532
 
533
533
  return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
534
+ } // Borrowed from Vue template compiler.
535
+ // https://github.com/vuejs/vue/blob/531371b818b0e31a989a06df43789728f23dc4e8/src/platforms/web/util/style.js#L5-L16
536
+
537
+
538
+ const DECLARATION_DELIMITER = /;(?![^(]*\))/g;
539
+ const PROPERTY_DELIMITER = /:(.+)/;
540
+
541
+ function parseStyleText(cssText) {
542
+ const styleMap = {};
543
+ const declarations = cssText.split(DECLARATION_DELIMITER);
544
+
545
+ for (const declaration of declarations) {
546
+ if (declaration) {
547
+ const [prop, value] = declaration.split(PROPERTY_DELIMITER);
548
+
549
+ if (prop !== undefined && value !== undefined) {
550
+ styleMap[prop.trim()] = value.trim();
551
+ }
552
+ }
553
+ }
554
+
555
+ return styleMap;
534
556
  }
535
557
  /*
536
558
  * Copyright (c) 2019, salesforce.com, inc.
@@ -712,8 +734,8 @@ function getErrorComponentStack(vm) {
712
734
  */
713
735
 
714
736
 
715
- function logError(message, vm) {
716
- let msg = `[LWC error]: ${message}`;
737
+ function log(method, message, vm) {
738
+ let msg = `[LWC ${method}]: ${message}`;
717
739
 
718
740
  if (!isUndefined$1(vm)) {
719
741
  msg = `${msg}\n${getComponentStack(vm)}`;
@@ -721,7 +743,7 @@ function logError(message, vm) {
721
743
 
722
744
  if (process.env.NODE_ENV === 'test') {
723
745
  /* eslint-disable-next-line no-console */
724
- console.error(msg);
746
+ console[method](msg);
725
747
  return;
726
748
  }
727
749
 
@@ -729,9 +751,17 @@ function logError(message, vm) {
729
751
  throw new Error(msg);
730
752
  } catch (e) {
731
753
  /* eslint-disable-next-line no-console */
732
- console.error(e);
754
+ console[method](e);
733
755
  }
734
756
  }
757
+
758
+ function logError(message, vm) {
759
+ log('error', message, vm);
760
+ }
761
+
762
+ function logWarn(message, vm) {
763
+ log('warn', message, vm);
764
+ }
735
765
  /*
736
766
  * Copyright (c) 2018, salesforce.com, inc.
737
767
  * All rights reserved.
@@ -1899,7 +1929,6 @@ const {
1899
1929
  getPrototypeOf,
1900
1930
  create: ObjectCreate,
1901
1931
  defineProperty: ObjectDefineProperty,
1902
- defineProperties: ObjectDefineProperties,
1903
1932
  isExtensible,
1904
1933
  getOwnPropertyDescriptor,
1905
1934
  getOwnPropertyNames,
@@ -1909,8 +1938,7 @@ const {
1909
1938
  } = Object;
1910
1939
  const {
1911
1940
  push: ArrayPush,
1912
- concat: ArrayConcat,
1913
- map: ArrayMap
1941
+ concat: ArrayConcat
1914
1942
  } = Array.prototype;
1915
1943
  const OtS = {}.toString;
1916
1944
 
@@ -1975,7 +2003,9 @@ class BaseProxyHandler {
1975
2003
  // but it will always be compatible with the previous descriptor
1976
2004
  // to preserve the object invariants, which makes these lines safe.
1977
2005
 
1978
- const originalDescriptor = getOwnPropertyDescriptor(originalTarget, key);
2006
+ const originalDescriptor = getOwnPropertyDescriptor(originalTarget, key); // TODO: it should be impossible for the originalDescriptor to ever be undefined, this `if` can be removed
2007
+
2008
+ /* istanbul ignore else */
1979
2009
 
1980
2010
  if (!isUndefined(originalDescriptor)) {
1981
2011
  const wrappedDesc = this.wrapDescriptor(originalDescriptor);
@@ -2003,11 +2033,17 @@ class BaseProxyHandler {
2003
2033
 
2004
2034
  preventExtensions(shadowTarget);
2005
2035
  } // Shared Traps
2036
+ // TODO: apply() is never called
2037
+
2038
+ /* istanbul ignore next */
2006
2039
 
2007
2040
 
2008
2041
  apply(shadowTarget, thisArg, argArray) {
2009
2042
  /* No op */
2010
- }
2043
+ } // TODO: construct() is never called
2044
+
2045
+ /* istanbul ignore next */
2046
+
2011
2047
 
2012
2048
  construct(shadowTarget, argArray, newTarget) {
2013
2049
  /* No op */
@@ -2120,8 +2156,8 @@ class BaseProxyHandler {
2120
2156
 
2121
2157
  }
2122
2158
 
2123
- const getterMap = new WeakMap();
2124
- const setterMap = new WeakMap();
2159
+ const getterMap$1 = new WeakMap();
2160
+ const setterMap$1 = new WeakMap();
2125
2161
  const reverseGetterMap = new WeakMap();
2126
2162
  const reverseSetterMap = new WeakMap();
2127
2163
 
@@ -2131,7 +2167,7 @@ class ReactiveProxyHandler extends BaseProxyHandler {
2131
2167
  }
2132
2168
 
2133
2169
  wrapGetter(originalGet) {
2134
- const wrappedGetter = getterMap.get(originalGet);
2170
+ const wrappedGetter = getterMap$1.get(originalGet);
2135
2171
 
2136
2172
  if (!isUndefined(wrappedGetter)) {
2137
2173
  return wrappedGetter;
@@ -2144,13 +2180,13 @@ class ReactiveProxyHandler extends BaseProxyHandler {
2144
2180
  return handler.wrapValue(originalGet.call(unwrap$1(this)));
2145
2181
  };
2146
2182
 
2147
- getterMap.set(originalGet, get);
2183
+ getterMap$1.set(originalGet, get);
2148
2184
  reverseGetterMap.set(get, originalGet);
2149
2185
  return get;
2150
2186
  }
2151
2187
 
2152
2188
  wrapSetter(originalSet) {
2153
- const wrappedSetter = setterMap.get(originalSet);
2189
+ const wrappedSetter = setterMap$1.get(originalSet);
2154
2190
 
2155
2191
  if (!isUndefined(wrappedSetter)) {
2156
2192
  return wrappedSetter;
@@ -2161,7 +2197,7 @@ class ReactiveProxyHandler extends BaseProxyHandler {
2161
2197
  originalSet.call(unwrap$1(this), unwrap$1(v));
2162
2198
  };
2163
2199
 
2164
- setterMap.set(originalSet, set);
2200
+ setterMap$1.set(originalSet, set);
2165
2201
  reverseSetterMap.set(set, originalSet);
2166
2202
  return set;
2167
2203
  }
@@ -2202,7 +2238,7 @@ class ReactiveProxyHandler extends BaseProxyHandler {
2202
2238
  return unwrap$1(redGet.call(handler.wrapValue(this)));
2203
2239
  };
2204
2240
 
2205
- getterMap.set(get, redGet);
2241
+ getterMap$1.set(get, redGet);
2206
2242
  reverseGetterMap.set(redGet, get);
2207
2243
  return get;
2208
2244
  }
@@ -2221,7 +2257,7 @@ class ReactiveProxyHandler extends BaseProxyHandler {
2221
2257
  redSet.call(handler.wrapValue(this), handler.wrapValue(v));
2222
2258
  };
2223
2259
 
2224
- setterMap.set(set, redSet);
2260
+ setterMap$1.set(set, redSet);
2225
2261
  reverseSetterMap.set(redSet, set);
2226
2262
  return set;
2227
2263
  }
@@ -2262,6 +2298,7 @@ class ReactiveProxyHandler extends BaseProxyHandler {
2262
2298
  }
2263
2299
 
2264
2300
  setPrototypeOf(shadowTarget, prototype) {
2301
+ /* istanbul ignore else */
2265
2302
  if (process.env.NODE_ENV !== 'production') {
2266
2303
  throw new Error(`Invalid setPrototypeOf invocation for reactive proxy ${toString(this.originalTarget)}. Prototype of reactive objects cannot be changed.`);
2267
2304
  }
@@ -2275,6 +2312,11 @@ class ReactiveProxyHandler extends BaseProxyHandler {
2275
2312
  preventExtensions(originalTarget); // if the originalTarget is a proxy itself, it might reject
2276
2313
  // the preventExtension call, in which case we should not attempt to lock down
2277
2314
  // the shadow target.
2315
+ // TODO: It should not actually be possible to reach this `if` statement.
2316
+ // If a proxy rejects extensions, then calling preventExtensions will throw an error:
2317
+ // https://codepen.io/nolanlawson-the-selector/pen/QWMOjbY
2318
+
2319
+ /* istanbul ignore if */
2278
2320
 
2279
2321
  if (isExtensible(originalTarget)) {
2280
2322
  return false;
@@ -2316,8 +2358,8 @@ class ReactiveProxyHandler extends BaseProxyHandler {
2316
2358
 
2317
2359
  }
2318
2360
 
2319
- const getterMap$1 = new WeakMap();
2320
- const setterMap$1 = new WeakMap();
2361
+ const getterMap = new WeakMap();
2362
+ const setterMap = new WeakMap();
2321
2363
 
2322
2364
  class ReadOnlyHandler extends BaseProxyHandler {
2323
2365
  wrapValue(value) {
@@ -2325,7 +2367,7 @@ class ReadOnlyHandler extends BaseProxyHandler {
2325
2367
  }
2326
2368
 
2327
2369
  wrapGetter(originalGet) {
2328
- const wrappedGetter = getterMap$1.get(originalGet);
2370
+ const wrappedGetter = getterMap.get(originalGet);
2329
2371
 
2330
2372
  if (!isUndefined(wrappedGetter)) {
2331
2373
  return wrappedGetter;
@@ -2338,12 +2380,12 @@ class ReadOnlyHandler extends BaseProxyHandler {
2338
2380
  return handler.wrapValue(originalGet.call(unwrap$1(this)));
2339
2381
  };
2340
2382
 
2341
- getterMap$1.set(originalGet, get);
2383
+ getterMap.set(originalGet, get);
2342
2384
  return get;
2343
2385
  }
2344
2386
 
2345
2387
  wrapSetter(originalSet) {
2346
- const wrappedSetter = setterMap$1.get(originalSet);
2388
+ const wrappedSetter = setterMap.get(originalSet);
2347
2389
 
2348
2390
  if (!isUndefined(wrappedSetter)) {
2349
2391
  return wrappedSetter;
@@ -2352,6 +2394,7 @@ class ReadOnlyHandler extends BaseProxyHandler {
2352
2394
  const handler = this;
2353
2395
 
2354
2396
  const set = function (v) {
2397
+ /* istanbul ignore else */
2355
2398
  if (process.env.NODE_ENV !== 'production') {
2356
2399
  const {
2357
2400
  originalTarget
@@ -2360,33 +2403,41 @@ class ReadOnlyHandler extends BaseProxyHandler {
2360
2403
  }
2361
2404
  };
2362
2405
 
2363
- setterMap$1.set(originalSet, set);
2406
+ setterMap.set(originalSet, set);
2364
2407
  return set;
2365
2408
  }
2366
2409
 
2367
2410
  set(shadowTarget, key, value) {
2411
+ /* istanbul ignore else */
2368
2412
  if (process.env.NODE_ENV !== 'production') {
2369
2413
  const {
2370
2414
  originalTarget
2371
2415
  } = this;
2372
- throw new Error(`Invalid mutation: Cannot set "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
2416
+ const msg = isArray(originalTarget) ? `Invalid mutation: Cannot mutate array at index ${key.toString()}. Array is read-only.` : `Invalid mutation: Cannot set "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`;
2417
+ throw new Error(msg);
2373
2418
  }
2419
+ /* istanbul ignore next */
2420
+
2374
2421
 
2375
2422
  return false;
2376
2423
  }
2377
2424
 
2378
2425
  deleteProperty(shadowTarget, key) {
2426
+ /* istanbul ignore else */
2379
2427
  if (process.env.NODE_ENV !== 'production') {
2380
2428
  const {
2381
2429
  originalTarget
2382
2430
  } = this;
2383
2431
  throw new Error(`Invalid mutation: Cannot delete "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
2384
2432
  }
2433
+ /* istanbul ignore next */
2434
+
2385
2435
 
2386
2436
  return false;
2387
2437
  }
2388
2438
 
2389
2439
  setPrototypeOf(shadowTarget, prototype) {
2440
+ /* istanbul ignore else */
2390
2441
  if (process.env.NODE_ENV !== 'production') {
2391
2442
  const {
2392
2443
  originalTarget
@@ -2396,23 +2447,29 @@ class ReadOnlyHandler extends BaseProxyHandler {
2396
2447
  }
2397
2448
 
2398
2449
  preventExtensions(shadowTarget) {
2450
+ /* istanbul ignore else */
2399
2451
  if (process.env.NODE_ENV !== 'production') {
2400
2452
  const {
2401
2453
  originalTarget
2402
2454
  } = this;
2403
2455
  throw new Error(`Invalid mutation: Cannot preventExtensions on ${originalTarget}". "${originalTarget} is read-only.`);
2404
2456
  }
2457
+ /* istanbul ignore next */
2458
+
2405
2459
 
2406
2460
  return false;
2407
2461
  }
2408
2462
 
2409
2463
  defineProperty(shadowTarget, key, descriptor) {
2464
+ /* istanbul ignore else */
2410
2465
  if (process.env.NODE_ENV !== 'production') {
2411
2466
  const {
2412
2467
  originalTarget
2413
2468
  } = this;
2414
2469
  throw new Error(`Invalid mutation: Cannot defineProperty "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
2415
2470
  }
2471
+ /* istanbul ignore next */
2472
+
2416
2473
 
2417
2474
  return false;
2418
2475
  }
@@ -2470,6 +2527,8 @@ const formatter = {
2470
2527
  }; // Inspired from paulmillr/es6-shim
2471
2528
  // https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L176-L185
2472
2529
 
2530
+ /* istanbul ignore next */
2531
+
2473
2532
  function getGlobal() {
2474
2533
  // the only reliable means to get the global object is `Function('return this')()`
2475
2534
  // However, this causes CSP violations in Chrome apps.
@@ -2494,6 +2553,7 @@ function getGlobal() {
2494
2553
  }
2495
2554
 
2496
2555
  function init() {
2556
+ /* istanbul ignore if */
2497
2557
  if (process.env.NODE_ENV === 'production') {
2498
2558
  // this method should never leak to prod
2499
2559
  throw new ReferenceError();
@@ -2508,6 +2568,8 @@ function init() {
2508
2568
  ArrayPush.call(devtoolsFormatters, formatter);
2509
2569
  global.devtoolsFormatters = devtoolsFormatters;
2510
2570
  }
2571
+ /* istanbul ignore else */
2572
+
2511
2573
 
2512
2574
  if (process.env.NODE_ENV !== 'production') {
2513
2575
  init();
@@ -2554,7 +2616,8 @@ class ReactiveMembrane {
2554
2616
  this.valueMutated = defaultValueMutated;
2555
2617
  this.valueObserved = defaultValueObserved;
2556
2618
  this.valueIsObservable = defaultValueIsObservable;
2557
- this.objectGraph = new WeakMap();
2619
+ this.readOnlyObjectGraph = new WeakMap();
2620
+ this.reactiveObjectGraph = new WeakMap();
2558
2621
 
2559
2622
  if (!isUndefined(options)) {
2560
2623
  const {
@@ -2577,10 +2640,13 @@ class ReactiveMembrane {
2577
2640
  const distorted = this.valueDistortion(unwrappedValue);
2578
2641
 
2579
2642
  if (this.valueIsObservable(distorted)) {
2580
- const o = this.getReactiveState(unwrappedValue, distorted); // when trying to extract the writable version of a readonly
2581
- // we return the readonly.
2643
+ if (this.readOnlyObjectGraph.get(distorted) === value) {
2644
+ // when trying to extract the writable version of a readonly
2645
+ // we return the readonly.
2646
+ return value;
2647
+ }
2582
2648
 
2583
- return o.readOnly === value ? value : o.reactive;
2649
+ return this.getReactiveHandler(unwrappedValue, distorted);
2584
2650
  }
2585
2651
 
2586
2652
  return distorted;
@@ -2591,7 +2657,7 @@ class ReactiveMembrane {
2591
2657
  const distorted = this.valueDistortion(value);
2592
2658
 
2593
2659
  if (this.valueIsObservable(distorted)) {
2594
- return this.getReactiveState(value, distorted).readOnly;
2660
+ return this.getReadOnlyHandler(value, distorted);
2595
2661
  }
2596
2662
 
2597
2663
  return distorted;
@@ -2601,47 +2667,36 @@ class ReactiveMembrane {
2601
2667
  return unwrap$1(p);
2602
2668
  }
2603
2669
 
2604
- getReactiveState(value, distortedValue) {
2605
- const {
2606
- objectGraph
2607
- } = this;
2608
- let reactiveState = objectGraph.get(distortedValue);
2670
+ getReactiveHandler(value, distortedValue) {
2671
+ let proxy = this.reactiveObjectGraph.get(distortedValue);
2609
2672
 
2610
- if (reactiveState) {
2611
- return reactiveState;
2673
+ if (isUndefined(proxy)) {
2674
+ // caching the proxy after the first time it is accessed
2675
+ const handler = new ReactiveProxyHandler(this, distortedValue);
2676
+ proxy = new Proxy(createShadowTarget(distortedValue), handler);
2677
+ registerProxy(proxy, value);
2678
+ this.reactiveObjectGraph.set(distortedValue, proxy);
2612
2679
  }
2613
2680
 
2614
- const membrane = this;
2615
- reactiveState = {
2616
- get reactive() {
2617
- const reactiveHandler = new ReactiveProxyHandler(membrane, distortedValue); // caching the reactive proxy after the first time it is accessed
2618
-
2619
- const proxy = new Proxy(createShadowTarget(distortedValue), reactiveHandler);
2620
- registerProxy(proxy, value);
2621
- ObjectDefineProperty(this, 'reactive', {
2622
- value: proxy
2623
- });
2624
- return proxy;
2625
- },
2681
+ return proxy;
2682
+ }
2626
2683
 
2627
- get readOnly() {
2628
- const readOnlyHandler = new ReadOnlyHandler(membrane, distortedValue); // caching the readOnly proxy after the first time it is accessed
2684
+ getReadOnlyHandler(value, distortedValue) {
2685
+ let proxy = this.readOnlyObjectGraph.get(distortedValue);
2629
2686
 
2630
- const proxy = new Proxy(createShadowTarget(distortedValue), readOnlyHandler);
2631
- registerProxy(proxy, value);
2632
- ObjectDefineProperty(this, 'readOnly', {
2633
- value: proxy
2634
- });
2635
- return proxy;
2636
- }
2687
+ if (isUndefined(proxy)) {
2688
+ // caching the proxy after the first time it is accessed
2689
+ const handler = new ReadOnlyHandler(this, distortedValue);
2690
+ proxy = new Proxy(createShadowTarget(distortedValue), handler);
2691
+ registerProxy(proxy, value);
2692
+ this.readOnlyObjectGraph.set(distortedValue, proxy);
2693
+ }
2637
2694
 
2638
- };
2639
- objectGraph.set(distortedValue, reactiveState);
2640
- return reactiveState;
2695
+ return proxy;
2641
2696
  }
2642
2697
 
2643
2698
  }
2644
- /** version: 1.0.0 */
2699
+ /** version: 1.1.5 */
2645
2700
 
2646
2701
  /*
2647
2702
  * Copyright (c) 2018, salesforce.com, inc.
@@ -3095,8 +3150,10 @@ for (const [elementProp, rendererMethod] of childGetters) {
3095
3150
  }
3096
3151
 
3097
3152
  return renderer[rendererMethod](elm);
3098
- }
3153
+ },
3099
3154
 
3155
+ configurable: true,
3156
+ enumerable: true
3100
3157
  };
3101
3158
  }
3102
3159
 
@@ -3116,8 +3173,11 @@ for (const queryMethod of queryMethods) {
3116
3173
  }
3117
3174
 
3118
3175
  return renderer[queryMethod](elm, arg);
3119
- }
3176
+ },
3120
3177
 
3178
+ configurable: true,
3179
+ enumerable: true,
3180
+ writable: true
3121
3181
  };
3122
3182
  }
3123
3183
 
@@ -4275,7 +4335,7 @@ function createComponentDef(Ctor) {
4275
4335
  if (!isUndefined$1(ctorShadowSupportMode)) {
4276
4336
  assert.invariant(ctorShadowSupportMode === "any"
4277
4337
  /* Any */
4278
- || ctorShadowSupportMode === "default"
4338
+ || ctorShadowSupportMode === "reset"
4279
4339
  /* Default */
4280
4340
  , `Invalid value for static property shadowSupportMode: '${ctorShadowSupportMode}'`);
4281
4341
  }
@@ -4437,7 +4497,7 @@ const lightingElementDef = {
4437
4497
  renderMode: 1
4438
4498
  /* Shadow */
4439
4499
  ,
4440
- shadowSupportMode: "default"
4500
+ shadowSupportMode: "reset"
4441
4501
  /* Default */
4442
4502
  ,
4443
4503
  wire: EmptyObject,
@@ -4586,6 +4646,17 @@ function createElmHook(vnode) {
4586
4646
  modComputedStyle.create(vnode);
4587
4647
  }
4588
4648
 
4649
+ function hydrateElmHook(vnode) {
4650
+ modEvents.create(vnode); // Attrs are already on the element.
4651
+ // modAttrs.create(vnode);
4652
+
4653
+ modProps.create(vnode); // Already set.
4654
+ // modStaticClassName.create(vnode);
4655
+ // modStaticStyle.create(vnode);
4656
+ // modComputedClassName.create(vnode);
4657
+ // modComputedStyle.create(vnode);
4658
+ }
4659
+
4589
4660
  function fallbackElmHook(elm, vnode) {
4590
4661
  const {
4591
4662
  owner
@@ -4757,6 +4828,179 @@ function createChildrenHook(vnode) {
4757
4828
  }
4758
4829
  }
4759
4830
 
4831
+ function isElementNode(node) {
4832
+ // eslint-disable-next-line lwc-internal/no-global-node
4833
+ return node.nodeType === Node.ELEMENT_NODE;
4834
+ }
4835
+
4836
+ function vnodesAndElementHaveCompatibleAttrs(vnode, elm) {
4837
+ const {
4838
+ data: {
4839
+ attrs = {}
4840
+ },
4841
+ owner: {
4842
+ renderer
4843
+ }
4844
+ } = vnode;
4845
+ let nodesAreCompatible = true; // Validate attributes, though we could always recovery from those by running the update mods.
4846
+ // Note: intentionally ONLY matching vnodes.attrs to elm.attrs, in case SSR is adding extra attributes.
4847
+
4848
+ for (const [attrName, attrValue] of Object.entries(attrs)) {
4849
+ const elmAttrValue = renderer.getAttribute(elm, attrName);
4850
+
4851
+ if (String(attrValue) !== elmAttrValue) {
4852
+ logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "${attrName}" has different values, expected "${attrValue}" but found "${elmAttrValue}"`, vnode.owner);
4853
+ nodesAreCompatible = false;
4854
+ }
4855
+ }
4856
+
4857
+ return nodesAreCompatible;
4858
+ }
4859
+
4860
+ function vnodesAndElementHaveCompatibleClass(vnode, elm) {
4861
+ const {
4862
+ data: {
4863
+ className,
4864
+ classMap
4865
+ },
4866
+ owner: {
4867
+ renderer
4868
+ }
4869
+ } = vnode;
4870
+ let nodesAreCompatible = true;
4871
+ let vnodeClassName;
4872
+
4873
+ if (!isUndefined$1(className) && String(className) !== elm.className) {
4874
+ // className is used when class is bound to an expr.
4875
+ nodesAreCompatible = false;
4876
+ vnodeClassName = className;
4877
+ } else if (!isUndefined$1(classMap)) {
4878
+ // classMap is used when class is set to static value.
4879
+ const classList = renderer.getClassList(elm);
4880
+ let computedClassName = ''; // all classes from the vnode should be in the element.classList
4881
+
4882
+ for (const name in classMap) {
4883
+ computedClassName += ' ' + name;
4884
+
4885
+ if (!classList.contains(name)) {
4886
+ nodesAreCompatible = false;
4887
+ }
4888
+ }
4889
+
4890
+ vnodeClassName = computedClassName.trim();
4891
+
4892
+ if (classList.length > keys(classMap).length) {
4893
+ nodesAreCompatible = false;
4894
+ }
4895
+ }
4896
+
4897
+ if (!nodesAreCompatible) {
4898
+ logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "class" has different values, expected "${vnodeClassName}" but found "${elm.className}"`, vnode.owner);
4899
+ }
4900
+
4901
+ return nodesAreCompatible;
4902
+ }
4903
+
4904
+ function vnodesAndElementHaveCompatibleStyle(vnode, elm) {
4905
+ const {
4906
+ data: {
4907
+ style,
4908
+ styleDecls
4909
+ },
4910
+ owner: {
4911
+ renderer
4912
+ }
4913
+ } = vnode;
4914
+ const elmStyle = renderer.getAttribute(elm, 'style') || '';
4915
+ let vnodeStyle;
4916
+ let nodesAreCompatible = true;
4917
+
4918
+ if (!isUndefined$1(style) && style !== elmStyle) {
4919
+ nodesAreCompatible = false;
4920
+ vnodeStyle = style;
4921
+ } else if (!isUndefined$1(styleDecls)) {
4922
+ const parsedVnodeStyle = parseStyleText(elmStyle);
4923
+ const expectedStyle = []; // styleMap is used when style is set to static value.
4924
+
4925
+ for (let i = 0, n = styleDecls.length; i < n; i++) {
4926
+ const [prop, value, important] = styleDecls[i];
4927
+ expectedStyle.push(`${prop}: ${value + (important ? ' important!' : '')}`);
4928
+ const parsedPropValue = parsedVnodeStyle[prop];
4929
+
4930
+ if (isUndefined$1(parsedPropValue)) {
4931
+ nodesAreCompatible = false;
4932
+ } else if (!parsedPropValue.startsWith(value)) {
4933
+ nodesAreCompatible = false;
4934
+ } else if (important && !parsedPropValue.endsWith('!important')) {
4935
+ nodesAreCompatible = false;
4936
+ }
4937
+ }
4938
+
4939
+ if (keys(parsedVnodeStyle).length > styleDecls.length) {
4940
+ nodesAreCompatible = false;
4941
+ }
4942
+
4943
+ vnodeStyle = ArrayJoin.call(expectedStyle, ';');
4944
+ }
4945
+
4946
+ if (!nodesAreCompatible) {
4947
+ // style is used when class is bound to an expr.
4948
+ logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "style" has different values, expected "${vnodeStyle}" but found "${elmStyle}".`, vnode.owner);
4949
+ }
4950
+
4951
+ return nodesAreCompatible;
4952
+ }
4953
+
4954
+ function throwHydrationError() {
4955
+ assert.fail('Server rendered elements do not match client side generated elements');
4956
+ }
4957
+
4958
+ function hydrateChildrenHook(elmChildren, children, vm) {
4959
+ var _a, _b;
4960
+
4961
+ if (process.env.NODE_ENV !== 'production') {
4962
+ const filteredVNodes = ArrayFilter.call(children, vnode => !!vnode);
4963
+
4964
+ if (elmChildren.length !== filteredVNodes.length) {
4965
+ logError(`Hydration mismatch: incorrect number of rendered nodes, expected ${filteredVNodes.length} but found ${elmChildren.length}.`, vm);
4966
+ throwHydrationError();
4967
+ }
4968
+ }
4969
+
4970
+ let elmCurrentChildIdx = 0;
4971
+
4972
+ for (let j = 0, n = children.length; j < n; j++) {
4973
+ const ch = children[j];
4974
+
4975
+ if (ch != null) {
4976
+ const childNode = elmChildren[elmCurrentChildIdx];
4977
+
4978
+ if (process.env.NODE_ENV !== 'production') {
4979
+ // VComments and VTexts validation is handled in their hooks
4980
+ if (isElementNode(childNode)) {
4981
+ if (((_a = ch.sel) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== childNode.tagName.toLowerCase()) {
4982
+ logError(`Hydration mismatch: expecting element with tag "${(_b = ch.sel) === null || _b === void 0 ? void 0 : _b.toLowerCase()}" but found "${childNode.tagName.toLowerCase()}".`, vm);
4983
+ throwHydrationError();
4984
+ } // Note: props are not yet set
4985
+
4986
+
4987
+ const hasIncompatibleAttrs = vnodesAndElementHaveCompatibleAttrs(ch, childNode);
4988
+ const hasIncompatibleClass = vnodesAndElementHaveCompatibleClass(ch, childNode);
4989
+ const hasIncompatibleStyle = vnodesAndElementHaveCompatibleStyle(ch, childNode);
4990
+ const isVNodeAndElementCompatible = hasIncompatibleAttrs && hasIncompatibleClass && hasIncompatibleStyle;
4991
+
4992
+ if (!isVNodeAndElementCompatible) {
4993
+ throwHydrationError();
4994
+ }
4995
+ }
4996
+ }
4997
+
4998
+ ch.hook.hydrate(ch, childNode);
4999
+ elmCurrentChildIdx++;
5000
+ }
5001
+ }
5002
+ }
5003
+
4760
5004
  function updateCustomElmHook(oldVnode, vnode) {
4761
5005
  // Attrs need to be applied to element before props
4762
5006
  // IE11 will wipe out value on radio inputs if value
@@ -4840,38 +5084,6 @@ function getUpgradableConstructor(tagName, renderer) {
4840
5084
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4841
5085
  */
4842
5086
 
4843
- /**
4844
- * EXPERIMENTAL: This function acts like a hook for Lightning Locker Service and other similar
4845
- * libraries to sanitize HTML content. This hook process the content passed via the template to
4846
- * lwc:inner-html directive.
4847
- * It is meant to be overridden with setSanitizeHtmlContentHook
4848
- */
4849
-
4850
-
4851
- let sanitizeHtmlContentHook = () => {
4852
- // locker-service patches this function during runtime to sanitize HTML content.
4853
- throw new Error('sanitizeHtmlContent hook must be implemented.');
4854
- };
4855
- /**
4856
- * Sets the sanitizeHtmlContentHook.
4857
- *
4858
- * @param newHookImpl
4859
- * @returns oldHookImplementation.
4860
- */
4861
-
4862
-
4863
- function setSanitizeHtmlContentHook(newHookImpl) {
4864
- const currentHook = sanitizeHtmlContentHook;
4865
- sanitizeHtmlContentHook = newHookImpl;
4866
- return currentHook;
4867
- }
4868
- /*
4869
- * Copyright (c) 2018, salesforce.com, inc.
4870
- * All rights reserved.
4871
- * SPDX-License-Identifier: MIT
4872
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4873
- */
4874
-
4875
5087
 
4876
5088
  const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
4877
5089
  const SymbolIterator = Symbol.iterator;
@@ -4890,7 +5102,26 @@ const TextHook = {
4890
5102
  update: updateNodeHook,
4891
5103
  insert: insertNodeHook,
4892
5104
  move: insertNodeHook,
4893
- remove: removeNodeHook
5105
+ remove: removeNodeHook,
5106
+ hydrate: (vNode, node) => {
5107
+ var _a;
5108
+
5109
+ if (process.env.NODE_ENV !== 'production') {
5110
+ // eslint-disable-next-line lwc-internal/no-global-node
5111
+ if (node.nodeType !== Node.TEXT_NODE) {
5112
+ logError('Hydration mismatch: incorrect node type received', vNode.owner);
5113
+ assert.fail('Hydration mismatch: incorrect node type received.');
5114
+ }
5115
+
5116
+ if (node.nodeValue !== vNode.text) {
5117
+ logWarn('Hydration mismatch: text values do not match, will recover from the difference', vNode.owner);
5118
+ }
5119
+ } // always set the text value to the one from the vnode.
5120
+
5121
+
5122
+ node.nodeValue = (_a = vNode.text) !== null && _a !== void 0 ? _a : null;
5123
+ vNode.elm = node;
5124
+ }
4894
5125
  };
4895
5126
  const CommentHook = {
4896
5127
  create: vnode => {
@@ -4908,7 +5139,26 @@ const CommentHook = {
4908
5139
  update: updateNodeHook,
4909
5140
  insert: insertNodeHook,
4910
5141
  move: insertNodeHook,
4911
- remove: removeNodeHook
5142
+ remove: removeNodeHook,
5143
+ hydrate: (vNode, node) => {
5144
+ var _a;
5145
+
5146
+ if (process.env.NODE_ENV !== 'production') {
5147
+ // eslint-disable-next-line lwc-internal/no-global-node
5148
+ if (node.nodeType !== Node.COMMENT_NODE) {
5149
+ logError('Hydration mismatch: incorrect node type received', vNode.owner);
5150
+ assert.fail('Hydration mismatch: incorrect node type received.');
5151
+ }
5152
+
5153
+ if (node.nodeValue !== vNode.text) {
5154
+ logWarn('Hydration mismatch: comment values do not match, will recover from the difference', vNode.owner);
5155
+ }
5156
+ } // always set the text value to the one from the vnode.
5157
+
5158
+
5159
+ node.nodeValue = (_a = vNode.text) !== null && _a !== void 0 ? _a : null;
5160
+ vNode.elm = node;
5161
+ }
4912
5162
  }; // insert is called after update, which is used somewhere else (via a module)
4913
5163
  // to mark the vm as inserted, that means we cannot use update as the main channel
4914
5164
  // to rehydrate when dirty, because sometimes the element is not inserted just yet,
@@ -4948,6 +5198,38 @@ const ElementHook = {
4948
5198
  remove: (vnode, parentNode) => {
4949
5199
  removeNodeHook(vnode, parentNode);
4950
5200
  removeElmHook(vnode);
5201
+ },
5202
+ hydrate: (vnode, node) => {
5203
+ const elm = node;
5204
+ vnode.elm = elm;
5205
+ const {
5206
+ context
5207
+ } = vnode.data;
5208
+ const isDomManual = Boolean(!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
5209
+ /* manual */
5210
+ );
5211
+
5212
+ if (isDomManual) {
5213
+ // it may be that this element has lwc:inner-html, we need to diff and in case are the same,
5214
+ // remove the innerHTML from props so it reuses the existing dom elements.
5215
+ const {
5216
+ props
5217
+ } = vnode.data;
5218
+
5219
+ if (!isUndefined$1(props) && !isUndefined$1(props.innerHTML)) {
5220
+ if (elm.innerHTML === props.innerHTML) {
5221
+ delete props.innerHTML;
5222
+ } else {
5223
+ logWarn(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: innerHTML values do not match for element, will recover from the difference`, vnode.owner);
5224
+ }
5225
+ }
5226
+ }
5227
+
5228
+ hydrateElmHook(vnode);
5229
+
5230
+ if (!isDomManual) {
5231
+ hydrateChildrenHook(vnode.elm.childNodes, vnode.children, vnode.owner);
5232
+ }
4951
5233
  }
4952
5234
  };
4953
5235
  const CustomElementHook = {
@@ -5039,6 +5321,44 @@ const CustomElementHook = {
5039
5321
  // will take care of disconnecting any child VM attached to its shadow as well.
5040
5322
  removeVM(vm);
5041
5323
  }
5324
+ },
5325
+ hydrate: (vnode, elm) => {
5326
+ // the element is created, but the vm is not
5327
+ const {
5328
+ sel,
5329
+ mode,
5330
+ ctor,
5331
+ owner
5332
+ } = vnode;
5333
+ const def = getComponentInternalDef(ctor);
5334
+ createVM(elm, def, {
5335
+ mode,
5336
+ owner,
5337
+ tagName: sel,
5338
+ renderer: owner.renderer
5339
+ });
5340
+ vnode.elm = elm;
5341
+ const vm = getAssociatedVM(elm);
5342
+ allocateChildrenHook(vnode, vm);
5343
+ hydrateElmHook(vnode); // Insert hook section:
5344
+
5345
+ if (process.env.NODE_ENV !== 'production') {
5346
+ assert.isTrue(vm.state === 0
5347
+ /* created */
5348
+ , `${vm} cannot be recycled.`);
5349
+ }
5350
+
5351
+ runConnectedCallback(vm);
5352
+
5353
+ if (vm.renderMode !== 0
5354
+ /* Light */
5355
+ ) {
5356
+ // VM is not rendering in Light DOM, we can proceed and hydrate the slotted content.
5357
+ // Note: for Light DOM, this is handled while hydrating the VM
5358
+ hydrateChildrenHook(vnode.elm.childNodes, vnode.children, vm);
5359
+ }
5360
+
5361
+ hydrateVM(vm);
5042
5362
  }
5043
5363
  };
5044
5364
 
@@ -5351,7 +5671,7 @@ function co(text) {
5351
5671
 
5352
5672
 
5353
5673
  function d(value) {
5354
- return value == null ? '' : value;
5674
+ return value == null ? '' : String(value);
5355
5675
  } // [b]ind function
5356
5676
 
5357
5677
 
@@ -5513,6 +5833,26 @@ function sc(vnodes) {
5513
5833
 
5514
5834
  markAsDynamicChildren(vnodes);
5515
5835
  return vnodes;
5836
+ }
5837
+ /**
5838
+ * EXPERIMENTAL: This function acts like a hook for Lightning Locker Service and other similar
5839
+ * libraries to sanitize HTML content. This hook process the content passed via the template to
5840
+ * lwc:inner-html directive.
5841
+ * It is meant to be overridden with setSanitizeHtmlContentHook, it throws an error by default.
5842
+ */
5843
+
5844
+
5845
+ let sanitizeHtmlContentHook = () => {
5846
+ // locker-service patches this function during runtime to sanitize HTML content.
5847
+ throw new Error('sanitizeHtmlContent hook must be implemented.');
5848
+ };
5849
+ /**
5850
+ * Sets the sanitizeHtmlContentHook.
5851
+ */
5852
+
5853
+
5854
+ function setSanitizeHtmlContentHook(newHookImpl) {
5855
+ sanitizeHtmlContentHook = newHookImpl;
5516
5856
  } // [s]anitize [h]tml [c]ontent
5517
5857
 
5518
5858
 
@@ -5707,7 +6047,10 @@ function createStylesheet(vm, stylesheets) {
5707
6047
  for (let i = 0; i < stylesheets.length; i++) {
5708
6048
  renderer.insertGlobalStylesheet(stylesheets[i]);
5709
6049
  }
5710
- } else if (renderer.ssr) {
6050
+ } else if (renderer.ssr || renderer.isHydrating()) {
6051
+ // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
6052
+ // This works in the client, because the stylesheets are created, and cached in the VM
6053
+ // the first time the VM renders.
5711
6054
  // native shadow or light DOM, SSR
5712
6055
  const combinedStylesheetContent = ArrayJoin.call(stylesheets, '\n');
5713
6056
  return createInlineStyleVNode(combinedStylesheetContent);
@@ -6332,6 +6675,12 @@ function connectRootElement(elm) {
6332
6675
  , vm);
6333
6676
  }
6334
6677
 
6678
+ function hydrateRootElement(elm) {
6679
+ const vm = getAssociatedVM(elm);
6680
+ runConnectedCallback(vm);
6681
+ hydrateVM(vm);
6682
+ }
6683
+
6335
6684
  function disconnectRootElement(elm) {
6336
6685
  const vm = getAssociatedVM(elm);
6337
6686
  resetComponentStateWhenRemoved(vm);
@@ -6339,6 +6688,10 @@ function disconnectRootElement(elm) {
6339
6688
 
6340
6689
  function appendVM(vm) {
6341
6690
  rehydrate(vm);
6691
+ }
6692
+
6693
+ function hydrateVM(vm) {
6694
+ hydrate(vm);
6342
6695
  } // just in case the component comes back, with this we guarantee re-rendering it
6343
6696
  // while preventing any attempt to rehydration until after reinsertion.
6344
6697
 
@@ -6572,6 +6925,22 @@ function rehydrate(vm) {
6572
6925
  }
6573
6926
  }
6574
6927
 
6928
+ function hydrate(vm) {
6929
+ if (isTrue(vm.isDirty)) {
6930
+ // manually diffing/patching here.
6931
+ // This routine is:
6932
+ // patchShadowRoot(vm, children);
6933
+ // -> addVnodes.
6934
+ const children = renderComponent(vm);
6935
+ vm.children = children;
6936
+ const vmChildren = vm.renderMode === 0
6937
+ /* Light */
6938
+ ? vm.elm.childNodes : vm.elm.shadowRoot.childNodes;
6939
+ hydrateChildrenHook(vmChildren, children, vm);
6940
+ runRenderedCallback(vm);
6941
+ }
6942
+ }
6943
+
6575
6944
  function patchShadowRoot(vm, newCh) {
6576
6945
  const {
6577
6946
  children: oldCh
@@ -7398,28 +7767,12 @@ function readonly(obj) {
7398
7767
 
7399
7768
  let hooksAreSet = false;
7400
7769
 
7401
- function overrideHooks(hooks) {
7402
- const oldHooks = {};
7403
-
7404
- if (!isUndefined$1(hooks.sanitizeHtmlContent)) {
7405
- oldHooks.sanitizeHtmlContent = setSanitizeHtmlContentHook(hooks.sanitizeHtmlContent);
7406
- }
7407
-
7408
- return oldHooks;
7409
- }
7410
-
7411
7770
  function setHooks(hooks) {
7412
7771
  assert.isFalse(hooksAreSet, 'Hooks are already overridden, only one definition is allowed.');
7413
- overrideHooks(hooks);
7414
7772
  hooksAreSet = true;
7773
+ setSanitizeHtmlContentHook(hooks.sanitizeHtmlContent);
7415
7774
  }
7416
-
7417
- function setHooksForTest(hooks) {
7418
- if (process.env.NODE_ENV !== 'production') {
7419
- return overrideHooks(hooks);
7420
- }
7421
- }
7422
- /* version: 2.5.6 */
7775
+ /* version: 2.5.10 */
7423
7776
 
7424
7777
  /*
7425
7778
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7563,8 +7916,19 @@ if (isCustomElementRegistryAvailable()) {
7563
7916
  HTMLElementConstructor.prototype = HTMLElement.prototype;
7564
7917
  }
7565
7918
 
7919
+ let isHydrating = false;
7920
+
7921
+ function setIsHydrating(v) {
7922
+ isHydrating = v;
7923
+ }
7924
+
7566
7925
  const renderer = {
7567
7926
  ssr: false,
7927
+
7928
+ isHydrating() {
7929
+ return isHydrating;
7930
+ },
7931
+
7568
7932
  isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
7569
7933
  isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
7570
7934
 
@@ -7593,6 +7957,10 @@ const renderer = {
7593
7957
  },
7594
7958
 
7595
7959
  attachShadow(element, options) {
7960
+ if (isHydrating) {
7961
+ return element.shadowRoot;
7962
+ }
7963
+
7596
7964
  return element.attachShadow(options);
7597
7965
  },
7598
7966
 
@@ -7730,61 +8098,6 @@ const renderer = {
7730
8098
  getCustomElement,
7731
8099
  HTMLElement: HTMLElementConstructor
7732
8100
  };
7733
- /*
7734
- * Copyright (c) 2018, salesforce.com, inc.
7735
- * All rights reserved.
7736
- * SPDX-License-Identifier: MIT
7737
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7738
- */
7739
-
7740
- /**
7741
- * This function builds a Web Component class from a LWC constructor so it can be
7742
- * registered as a new element via customElements.define() at any given time.
7743
- *
7744
- * @deprecated since version 1.3.11
7745
- *
7746
- * @example
7747
- * ```
7748
- * import { buildCustomElementConstructor } from 'lwc';
7749
- * import Foo from 'ns/foo';
7750
- * const WC = buildCustomElementConstructor(Foo);
7751
- * customElements.define('x-foo', WC);
7752
- * const elm = document.createElement('x-foo');
7753
- * ```
7754
- */
7755
-
7756
- function deprecatedBuildCustomElementConstructor(Ctor) {
7757
- if (process.env.NODE_ENV !== 'production') {
7758
- /* eslint-disable-next-line no-console */
7759
- console.warn('Deprecated function called: "buildCustomElementConstructor" function is deprecated and it will be removed.' + `Use "${Ctor.name}.CustomElementConstructor" static property of the component constructor to access the corresponding custom element constructor instead.`);
7760
- }
7761
-
7762
- return Ctor.CustomElementConstructor;
7763
- }
7764
-
7765
- function buildCustomElementConstructor(Ctor) {
7766
- const def = getComponentInternalDef(Ctor);
7767
- return class extends def.bridge {
7768
- constructor() {
7769
- super();
7770
- createVM(this, def, {
7771
- mode: 'open',
7772
- owner: null,
7773
- tagName: this.tagName,
7774
- renderer
7775
- });
7776
- }
7777
-
7778
- connectedCallback() {
7779
- connectRootElement(this);
7780
- }
7781
-
7782
- disconnectedCallback() {
7783
- disconnectRootElement(this);
7784
- }
7785
-
7786
- };
7787
- }
7788
8101
  /*
7789
8102
  * Copyright (c) 2018, salesforce.com, inc.
7790
8103
  * All rights reserved.
@@ -7794,7 +8107,6 @@ function buildCustomElementConstructor(Ctor) {
7794
8107
  // TODO [#2472]: Remove this workaround when appropriate.
7795
8108
  // eslint-disable-next-line lwc-internal/no-global-node
7796
8109
 
7797
-
7798
8110
  const _Node$1 = Node;
7799
8111
  const ConnectingSlot = new WeakMap();
7800
8112
  const DisconnectingSlot = new WeakMap();
@@ -7905,6 +8217,118 @@ function createElement(sel, options) {
7905
8217
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7906
8218
  */
7907
8219
 
8220
+
8221
+ function hydrateComponent(element, Ctor, props = {}) {
8222
+ if (!isFunction$1(Ctor)) {
8223
+ throw new TypeError(`"hydrateComponent" expects a valid component constructor as the second parameter but instead received ${Ctor}.`);
8224
+ }
8225
+
8226
+ if (!isObject(props) || isNull(props)) {
8227
+ throw new TypeError(`"hydrateComponent" expects an object as the third parameter but instead received ${props}.`);
8228
+ }
8229
+
8230
+ const def = getComponentInternalDef(Ctor);
8231
+
8232
+ try {
8233
+ // Let the renderer know we are hydrating, so it does not replace the existing shadowRoot
8234
+ // and uses the same algo to create the stylesheets as in SSR.
8235
+ setIsHydrating(true);
8236
+ createVM(element, def, {
8237
+ mode: 'open',
8238
+ owner: null,
8239
+ renderer,
8240
+ tagName: element.tagName.toLowerCase()
8241
+ });
8242
+
8243
+ for (const [key, value] of Object.entries(props)) {
8244
+ element[key] = value;
8245
+ }
8246
+
8247
+ hydrateRootElement(element); // set it back since now we finished hydration.
8248
+
8249
+ setIsHydrating(false);
8250
+ } catch (e) {
8251
+ // Fallback: In case there's an error while hydrating, let's log the error, and replace the element with
8252
+ // the client generated DOM.
8253
+
8254
+ /* eslint-disable-next-line no-console */
8255
+ console.error('Recovering from error while hydrating: ', e);
8256
+ setIsHydrating(false);
8257
+ const newElem = createElement(element.tagName, {
8258
+ is: Ctor,
8259
+ mode: 'open'
8260
+ });
8261
+
8262
+ for (const [key, value] of Object.entries(props)) {
8263
+ newElem[key] = value;
8264
+ }
8265
+
8266
+ element.parentNode.replaceChild(newElem, element);
8267
+ }
8268
+ }
8269
+ /*
8270
+ * Copyright (c) 2018, salesforce.com, inc.
8271
+ * All rights reserved.
8272
+ * SPDX-License-Identifier: MIT
8273
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
8274
+ */
8275
+
8276
+ /**
8277
+ * This function builds a Web Component class from a LWC constructor so it can be
8278
+ * registered as a new element via customElements.define() at any given time.
8279
+ *
8280
+ * @deprecated since version 1.3.11
8281
+ *
8282
+ * @example
8283
+ * ```
8284
+ * import { buildCustomElementConstructor } from 'lwc';
8285
+ * import Foo from 'ns/foo';
8286
+ * const WC = buildCustomElementConstructor(Foo);
8287
+ * customElements.define('x-foo', WC);
8288
+ * const elm = document.createElement('x-foo');
8289
+ * ```
8290
+ */
8291
+
8292
+
8293
+ function deprecatedBuildCustomElementConstructor(Ctor) {
8294
+ if (process.env.NODE_ENV !== 'production') {
8295
+ /* eslint-disable-next-line no-console */
8296
+ console.warn('Deprecated function called: "buildCustomElementConstructor" function is deprecated and it will be removed.' + `Use "${Ctor.name}.CustomElementConstructor" static property of the component constructor to access the corresponding custom element constructor instead.`);
8297
+ }
8298
+
8299
+ return Ctor.CustomElementConstructor;
8300
+ }
8301
+
8302
+ function buildCustomElementConstructor(Ctor) {
8303
+ const def = getComponentInternalDef(Ctor);
8304
+ return class extends def.bridge {
8305
+ constructor() {
8306
+ super();
8307
+ createVM(this, def, {
8308
+ mode: 'open',
8309
+ owner: null,
8310
+ tagName: this.tagName,
8311
+ renderer
8312
+ });
8313
+ }
8314
+
8315
+ connectedCallback() {
8316
+ connectRootElement(this);
8317
+ }
8318
+
8319
+ disconnectedCallback() {
8320
+ disconnectRootElement(this);
8321
+ }
8322
+
8323
+ };
8324
+ }
8325
+ /*
8326
+ * Copyright (c) 2018, salesforce.com, inc.
8327
+ * All rights reserved.
8328
+ * SPDX-License-Identifier: MIT
8329
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
8330
+ */
8331
+
7908
8332
  /**
7909
8333
  * EXPERIMENTAL: This function provides access to the component constructor, given an HTMLElement.
7910
8334
  * This API is subject to change or being removed.
@@ -8004,6 +8428,6 @@ defineProperty(LightningElement, 'CustomElementConstructor', {
8004
8428
  });
8005
8429
  freeze(LightningElement);
8006
8430
  seal(LightningElement.prototype);
8007
- /* version: 2.5.6 */
8431
+ /* version: 2.5.10 */
8008
8432
 
8009
- export { LightningElement, profilerControl as __unstable__ProfilerControl, api$1 as api, deprecatedBuildCustomElementConstructor as buildCustomElementConstructor, createContextProvider, createElement, getComponentConstructor, getComponentDef, isComponentConstructor, isNodeFromTemplate, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setFeatureFlag, setFeatureFlagForTest, setHooks, setHooksForTest, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
8433
+ export { LightningElement, profilerControl as __unstable__ProfilerControl, api$1 as api, deprecatedBuildCustomElementConstructor as buildCustomElementConstructor, createContextProvider, createElement, getComponentConstructor, getComponentDef, hydrateComponent, isComponentConstructor, isNodeFromTemplate, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setFeatureFlag, setFeatureFlagForTest, setHooks, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };