lwc 2.5.6 → 2.5.10-alpha1

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 (54) hide show
  1. package/dist/engine/esm/es2017/engine.js +7981 -0
  2. package/dist/engine/iife/es2017/engine.js +8013 -0
  3. package/dist/engine/iife/es2017/engine.min.js +9 -0
  4. package/dist/engine/iife/es2017/engine_debug.js +6541 -0
  5. package/dist/engine/iife/es5/engine.js +6060 -0
  6. package/dist/engine/iife/es5/engine.min.js +23 -0
  7. package/dist/engine/iife/es5/engine_debug.js +4856 -0
  8. package/dist/engine/umd/es2017/engine.js +8014 -0
  9. package/dist/engine/umd/es2017/engine.min.js +9 -0
  10. package/dist/engine/umd/es2017/engine_debug.js +6542 -0
  11. package/dist/engine/umd/es5/engine.js +6061 -0
  12. package/dist/engine/umd/es5/engine.min.js +23 -0
  13. package/dist/engine/umd/es5/engine_debug.js +4857 -0
  14. package/dist/engine-dom/esm/es2017/engine-dom.js +521 -122
  15. package/dist/engine-dom/iife/es2017/engine-dom.js +522 -123
  16. package/dist/engine-dom/iife/es2017/engine-dom.min.js +2 -2
  17. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +337 -112
  18. package/dist/engine-dom/iife/es5/engine-dom.js +596 -185
  19. package/dist/engine-dom/iife/es5/engine-dom.min.js +2 -2
  20. package/dist/engine-dom/iife/es5/engine-dom_debug.js +392 -165
  21. package/dist/engine-dom/umd/es2017/engine-dom.js +523 -124
  22. package/dist/engine-dom/umd/es2017/engine-dom.min.js +2 -2
  23. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +338 -113
  24. package/dist/engine-dom/umd/es5/engine-dom.js +597 -186
  25. package/dist/engine-dom/umd/es5/engine-dom.min.js +2 -2
  26. package/dist/engine-dom/umd/es5/engine-dom_debug.js +393 -166
  27. package/dist/engine-server/commonjs/es2017/engine-server.js +400 -74
  28. package/dist/engine-server/commonjs/es2017/engine-server.min.js +2 -2
  29. package/dist/engine-server/esm/es2017/engine-server.js +401 -74
  30. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +3 -3
  31. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +4 -4
  32. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +2 -2
  33. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +4 -4
  34. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +4 -4
  35. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js +2 -2
  36. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +4 -4
  37. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +5 -5
  38. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +2 -2
  39. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +5 -5
  40. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +5 -5
  41. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js +2 -2
  42. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +5 -5
  43. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  44. package/dist/wire-service/iife/es2017/wire-service.js +3 -3
  45. package/dist/wire-service/iife/es2017/wire-service_debug.js +3 -3
  46. package/dist/wire-service/iife/es5/wire-service.js +3 -3
  47. package/dist/wire-service/iife/es5/wire-service.min.js +1 -1
  48. package/dist/wire-service/iife/es5/wire-service_debug.js +3 -3
  49. package/dist/wire-service/umd/es2017/wire-service.js +4 -4
  50. package/dist/wire-service/umd/es2017/wire-service_debug.js +4 -4
  51. package/dist/wire-service/umd/es5/wire-service.js +4 -4
  52. package/dist/wire-service/umd/es5/wire-service.min.js +1 -1
  53. package/dist/wire-service/umd/es5/wire-service_debug.js +4 -4
  54. package/package.json +8 -8
@@ -2,7 +2,7 @@
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
3
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.LWC = {}));
5
- })(this, (function (exports) { 'use strict';
5
+ }(this, (function (exports) { 'use strict';
6
6
 
7
7
  /* proxy-compat-disable */
8
8
 
@@ -305,7 +305,7 @@
305
305
  CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
306
306
  return attributeName;
307
307
  }
308
- /** version: 2.5.6 */
308
+ /** version: 2.5.10-alpha1 */
309
309
 
310
310
  /*
311
311
  * Copyright (c) 2018, salesforce.com, inc.
@@ -485,7 +485,7 @@
485
485
  setFeatureFlag(name, value);
486
486
  }
487
487
  }
488
- /** version: 2.5.6 */
488
+ /** version: 2.5.10-alpha1 */
489
489
 
490
490
  /* proxy-compat-disable */
491
491
 
@@ -537,6 +537,28 @@
537
537
  }
538
538
 
539
539
  return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
540
+ } // Borrowed from Vue template compiler.
541
+ // https://github.com/vuejs/vue/blob/531371b818b0e31a989a06df43789728f23dc4e8/src/platforms/web/util/style.js#L5-L16
542
+
543
+
544
+ const DECLARATION_DELIMITER = /;(?![^(]*\))/g;
545
+ const PROPERTY_DELIMITER = /:(.+)/;
546
+
547
+ function parseStyleText(cssText) {
548
+ const styleMap = {};
549
+ const declarations = cssText.split(DECLARATION_DELIMITER);
550
+
551
+ for (const declaration of declarations) {
552
+ if (declaration) {
553
+ const [prop, value] = declaration.split(PROPERTY_DELIMITER);
554
+
555
+ if (prop !== undefined && value !== undefined) {
556
+ styleMap[prop.trim()] = value.trim();
557
+ }
558
+ }
559
+ }
560
+
561
+ return styleMap;
540
562
  }
541
563
  /*
542
564
  * Copyright (c) 2019, salesforce.com, inc.
@@ -718,8 +740,8 @@
718
740
  */
719
741
 
720
742
 
721
- function logError(message, vm) {
722
- let msg = `[LWC error]: ${message}`;
743
+ function log(method, message, vm) {
744
+ let msg = `[LWC ${method}]: ${message}`;
723
745
 
724
746
  if (!isUndefined$1(vm)) {
725
747
  msg = `${msg}\n${getComponentStack(vm)}`;
@@ -727,7 +749,7 @@
727
749
 
728
750
  if (process.env.NODE_ENV === 'test') {
729
751
  /* eslint-disable-next-line no-console */
730
- console.error(msg);
752
+ console[method](msg);
731
753
  return;
732
754
  }
733
755
 
@@ -735,9 +757,17 @@
735
757
  throw new Error(msg);
736
758
  } catch (e) {
737
759
  /* eslint-disable-next-line no-console */
738
- console.error(e);
760
+ console[method](e);
739
761
  }
740
762
  }
763
+
764
+ function logError(message, vm) {
765
+ log('error', message, vm);
766
+ }
767
+
768
+ function logWarn(message, vm) {
769
+ log('warn', message, vm);
770
+ }
741
771
  /*
742
772
  * Copyright (c) 2018, salesforce.com, inc.
743
773
  * All rights reserved.
@@ -3101,8 +3131,10 @@
3101
3131
  }
3102
3132
 
3103
3133
  return renderer[rendererMethod](elm);
3104
- }
3134
+ },
3105
3135
 
3136
+ configurable: true,
3137
+ enumerable: true
3106
3138
  };
3107
3139
  }
3108
3140
 
@@ -3122,8 +3154,11 @@
3122
3154
  }
3123
3155
 
3124
3156
  return renderer[queryMethod](elm, arg);
3125
- }
3157
+ },
3126
3158
 
3159
+ configurable: true,
3160
+ enumerable: true,
3161
+ writable: true
3127
3162
  };
3128
3163
  }
3129
3164
 
@@ -4281,7 +4316,7 @@
4281
4316
  if (!isUndefined$1(ctorShadowSupportMode)) {
4282
4317
  assert.invariant(ctorShadowSupportMode === "any"
4283
4318
  /* Any */
4284
- || ctorShadowSupportMode === "default"
4319
+ || ctorShadowSupportMode === "reset"
4285
4320
  /* Default */
4286
4321
  , `Invalid value for static property shadowSupportMode: '${ctorShadowSupportMode}'`);
4287
4322
  }
@@ -4443,7 +4478,7 @@
4443
4478
  renderMode: 1
4444
4479
  /* Shadow */
4445
4480
  ,
4446
- shadowSupportMode: "default"
4481
+ shadowSupportMode: "reset"
4447
4482
  /* Default */
4448
4483
  ,
4449
4484
  wire: EmptyObject,
@@ -4592,6 +4627,17 @@
4592
4627
  modComputedStyle.create(vnode);
4593
4628
  }
4594
4629
 
4630
+ function hydrateElmHook(vnode) {
4631
+ modEvents.create(vnode); // Attrs are already on the element.
4632
+ // modAttrs.create(vnode);
4633
+
4634
+ modProps.create(vnode); // Already set.
4635
+ // modStaticClassName.create(vnode);
4636
+ // modStaticStyle.create(vnode);
4637
+ // modComputedClassName.create(vnode);
4638
+ // modComputedStyle.create(vnode);
4639
+ }
4640
+
4595
4641
  function fallbackElmHook(elm, vnode) {
4596
4642
  const {
4597
4643
  owner
@@ -4763,6 +4809,179 @@
4763
4809
  }
4764
4810
  }
4765
4811
 
4812
+ function isElementNode(node) {
4813
+ // eslint-disable-next-line lwc-internal/no-global-node
4814
+ return node.nodeType === Node.ELEMENT_NODE;
4815
+ }
4816
+
4817
+ function vnodesAndElementHaveCompatibleAttrs(vnode, elm) {
4818
+ const {
4819
+ data: {
4820
+ attrs = {}
4821
+ },
4822
+ owner: {
4823
+ renderer
4824
+ }
4825
+ } = vnode;
4826
+ let nodesAreCompatible = true; // Validate attributes, though we could always recovery from those by running the update mods.
4827
+ // Note: intentionally ONLY matching vnodes.attrs to elm.attrs, in case SSR is adding extra attributes.
4828
+
4829
+ for (const [attrName, attrValue] of Object.entries(attrs)) {
4830
+ const elmAttrValue = renderer.getAttribute(elm, attrName);
4831
+
4832
+ if (String(attrValue) !== elmAttrValue) {
4833
+ logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "${attrName}" has different values, expected "${attrValue}" but found "${elmAttrValue}"`, vnode.owner);
4834
+ nodesAreCompatible = false;
4835
+ }
4836
+ }
4837
+
4838
+ return nodesAreCompatible;
4839
+ }
4840
+
4841
+ function vnodesAndElementHaveCompatibleClass(vnode, elm) {
4842
+ const {
4843
+ data: {
4844
+ className,
4845
+ classMap
4846
+ },
4847
+ owner: {
4848
+ renderer
4849
+ }
4850
+ } = vnode;
4851
+ let nodesAreCompatible = true;
4852
+ let vnodeClassName;
4853
+
4854
+ if (!isUndefined$1(className) && String(className) !== elm.className) {
4855
+ // className is used when class is bound to an expr.
4856
+ nodesAreCompatible = false;
4857
+ vnodeClassName = className;
4858
+ } else if (!isUndefined$1(classMap)) {
4859
+ // classMap is used when class is set to static value.
4860
+ const classList = renderer.getClassList(elm);
4861
+ let computedClassName = ''; // all classes from the vnode should be in the element.classList
4862
+
4863
+ for (const name in classMap) {
4864
+ computedClassName += ' ' + name;
4865
+
4866
+ if (!classList.contains(name)) {
4867
+ nodesAreCompatible = false;
4868
+ }
4869
+ }
4870
+
4871
+ vnodeClassName = computedClassName.trim();
4872
+
4873
+ if (classList.length > keys(classMap).length) {
4874
+ nodesAreCompatible = false;
4875
+ }
4876
+ }
4877
+
4878
+ if (!nodesAreCompatible) {
4879
+ logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "class" has different values, expected "${vnodeClassName}" but found "${elm.className}"`, vnode.owner);
4880
+ }
4881
+
4882
+ return nodesAreCompatible;
4883
+ }
4884
+
4885
+ function vnodesAndElementHaveCompatibleStyle(vnode, elm) {
4886
+ const {
4887
+ data: {
4888
+ style,
4889
+ styleDecls
4890
+ },
4891
+ owner: {
4892
+ renderer
4893
+ }
4894
+ } = vnode;
4895
+ const elmStyle = renderer.getAttribute(elm, 'style') || '';
4896
+ let vnodeStyle;
4897
+ let nodesAreCompatible = true;
4898
+
4899
+ if (!isUndefined$1(style) && style !== elmStyle) {
4900
+ nodesAreCompatible = false;
4901
+ vnodeStyle = style;
4902
+ } else if (!isUndefined$1(styleDecls)) {
4903
+ const parsedVnodeStyle = parseStyleText(elmStyle);
4904
+ const expectedStyle = []; // styleMap is used when style is set to static value.
4905
+
4906
+ for (let i = 0, n = styleDecls.length; i < n; i++) {
4907
+ const [prop, value, important] = styleDecls[i];
4908
+ expectedStyle.push(`${prop}: ${value + (important ? ' important!' : '')}`);
4909
+ const parsedPropValue = parsedVnodeStyle[prop];
4910
+
4911
+ if (isUndefined$1(parsedPropValue)) {
4912
+ nodesAreCompatible = false;
4913
+ } else if (!parsedPropValue.startsWith(value)) {
4914
+ nodesAreCompatible = false;
4915
+ } else if (important && !parsedPropValue.endsWith('!important')) {
4916
+ nodesAreCompatible = false;
4917
+ }
4918
+ }
4919
+
4920
+ if (keys(parsedVnodeStyle).length > styleDecls.length) {
4921
+ nodesAreCompatible = false;
4922
+ }
4923
+
4924
+ vnodeStyle = ArrayJoin.call(expectedStyle, ';');
4925
+ }
4926
+
4927
+ if (!nodesAreCompatible) {
4928
+ // style is used when class is bound to an expr.
4929
+ logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "style" has different values, expected "${vnodeStyle}" but found "${elmStyle}".`, vnode.owner);
4930
+ }
4931
+
4932
+ return nodesAreCompatible;
4933
+ }
4934
+
4935
+ function throwHydrationError() {
4936
+ assert.fail('Server rendered elements do not match client side generated elements');
4937
+ }
4938
+
4939
+ function hydrateChildrenHook(elmChildren, children, vm) {
4940
+ var _a, _b;
4941
+
4942
+ if (process.env.NODE_ENV !== 'production') {
4943
+ const filteredVNodes = ArrayFilter.call(children, vnode => !!vnode);
4944
+
4945
+ if (elmChildren.length !== filteredVNodes.length) {
4946
+ logError(`Hydration mismatch: incorrect number of rendered nodes, expected ${filteredVNodes.length} but found ${elmChildren.length}.`, vm);
4947
+ throwHydrationError();
4948
+ }
4949
+ }
4950
+
4951
+ let elmCurrentChildIdx = 0;
4952
+
4953
+ for (let j = 0, n = children.length; j < n; j++) {
4954
+ const ch = children[j];
4955
+
4956
+ if (ch != null) {
4957
+ const childNode = elmChildren[elmCurrentChildIdx];
4958
+
4959
+ if (process.env.NODE_ENV !== 'production') {
4960
+ // VComments and VTexts validation is handled in their hooks
4961
+ if (isElementNode(childNode)) {
4962
+ if (((_a = ch.sel) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== childNode.tagName.toLowerCase()) {
4963
+ logError(`Hydration mismatch: expecting element with tag "${(_b = ch.sel) === null || _b === void 0 ? void 0 : _b.toLowerCase()}" but found "${childNode.tagName.toLowerCase()}".`, vm);
4964
+ throwHydrationError();
4965
+ } // Note: props are not yet set
4966
+
4967
+
4968
+ const hasIncompatibleAttrs = vnodesAndElementHaveCompatibleAttrs(ch, childNode);
4969
+ const hasIncompatibleClass = vnodesAndElementHaveCompatibleClass(ch, childNode);
4970
+ const hasIncompatibleStyle = vnodesAndElementHaveCompatibleStyle(ch, childNode);
4971
+ const isVNodeAndElementCompatible = hasIncompatibleAttrs && hasIncompatibleClass && hasIncompatibleStyle;
4972
+
4973
+ if (!isVNodeAndElementCompatible) {
4974
+ throwHydrationError();
4975
+ }
4976
+ }
4977
+ }
4978
+
4979
+ ch.hook.hydrate(ch, childNode);
4980
+ elmCurrentChildIdx++;
4981
+ }
4982
+ }
4983
+ }
4984
+
4766
4985
  function updateCustomElmHook(oldVnode, vnode) {
4767
4986
  // Attrs need to be applied to element before props
4768
4987
  // IE11 will wipe out value on radio inputs if value
@@ -4846,38 +5065,6 @@
4846
5065
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4847
5066
  */
4848
5067
 
4849
- /**
4850
- * EXPERIMENTAL: This function acts like a hook for Lightning Locker Service and other similar
4851
- * libraries to sanitize HTML content. This hook process the content passed via the template to
4852
- * lwc:inner-html directive.
4853
- * It is meant to be overridden with setSanitizeHtmlContentHook
4854
- */
4855
-
4856
-
4857
- let sanitizeHtmlContentHook = () => {
4858
- // locker-service patches this function during runtime to sanitize HTML content.
4859
- throw new Error('sanitizeHtmlContent hook must be implemented.');
4860
- };
4861
- /**
4862
- * Sets the sanitizeHtmlContentHook.
4863
- *
4864
- * @param newHookImpl
4865
- * @returns oldHookImplementation.
4866
- */
4867
-
4868
-
4869
- function setSanitizeHtmlContentHook(newHookImpl) {
4870
- const currentHook = sanitizeHtmlContentHook;
4871
- sanitizeHtmlContentHook = newHookImpl;
4872
- return currentHook;
4873
- }
4874
- /*
4875
- * Copyright (c) 2018, salesforce.com, inc.
4876
- * All rights reserved.
4877
- * SPDX-License-Identifier: MIT
4878
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4879
- */
4880
-
4881
5068
 
4882
5069
  const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
4883
5070
  const SymbolIterator = Symbol.iterator;
@@ -4896,7 +5083,26 @@
4896
5083
  update: updateNodeHook,
4897
5084
  insert: insertNodeHook,
4898
5085
  move: insertNodeHook,
4899
- remove: removeNodeHook
5086
+ remove: removeNodeHook,
5087
+ hydrate: (vNode, node) => {
5088
+ var _a;
5089
+
5090
+ if (process.env.NODE_ENV !== 'production') {
5091
+ // eslint-disable-next-line lwc-internal/no-global-node
5092
+ if (node.nodeType !== Node.TEXT_NODE) {
5093
+ logError('Hydration mismatch: incorrect node type received', vNode.owner);
5094
+ assert.fail('Hydration mismatch: incorrect node type received.');
5095
+ }
5096
+
5097
+ if (node.nodeValue !== vNode.text) {
5098
+ logWarn('Hydration mismatch: text values do not match, will recover from the difference', vNode.owner);
5099
+ }
5100
+ } // always set the text value to the one from the vnode.
5101
+
5102
+
5103
+ node.nodeValue = (_a = vNode.text) !== null && _a !== void 0 ? _a : null;
5104
+ vNode.elm = node;
5105
+ }
4900
5106
  };
4901
5107
  const CommentHook = {
4902
5108
  create: vnode => {
@@ -4914,7 +5120,26 @@
4914
5120
  update: updateNodeHook,
4915
5121
  insert: insertNodeHook,
4916
5122
  move: insertNodeHook,
4917
- remove: removeNodeHook
5123
+ remove: removeNodeHook,
5124
+ hydrate: (vNode, node) => {
5125
+ var _a;
5126
+
5127
+ if (process.env.NODE_ENV !== 'production') {
5128
+ // eslint-disable-next-line lwc-internal/no-global-node
5129
+ if (node.nodeType !== Node.COMMENT_NODE) {
5130
+ logError('Hydration mismatch: incorrect node type received', vNode.owner);
5131
+ assert.fail('Hydration mismatch: incorrect node type received.');
5132
+ }
5133
+
5134
+ if (node.nodeValue !== vNode.text) {
5135
+ logWarn('Hydration mismatch: comment values do not match, will recover from the difference', vNode.owner);
5136
+ }
5137
+ } // always set the text value to the one from the vnode.
5138
+
5139
+
5140
+ node.nodeValue = (_a = vNode.text) !== null && _a !== void 0 ? _a : null;
5141
+ vNode.elm = node;
5142
+ }
4918
5143
  }; // insert is called after update, which is used somewhere else (via a module)
4919
5144
  // to mark the vm as inserted, that means we cannot use update as the main channel
4920
5145
  // to rehydrate when dirty, because sometimes the element is not inserted just yet,
@@ -4954,6 +5179,38 @@
4954
5179
  remove: (vnode, parentNode) => {
4955
5180
  removeNodeHook(vnode, parentNode);
4956
5181
  removeElmHook(vnode);
5182
+ },
5183
+ hydrate: (vnode, node) => {
5184
+ const elm = node;
5185
+ vnode.elm = elm;
5186
+ const {
5187
+ context
5188
+ } = vnode.data;
5189
+ const isDomManual = Boolean(!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
5190
+ /* manual */
5191
+ );
5192
+
5193
+ if (isDomManual) {
5194
+ // it may be that this element has lwc:inner-html, we need to diff and in case are the same,
5195
+ // remove the innerHTML from props so it reuses the existing dom elements.
5196
+ const {
5197
+ props
5198
+ } = vnode.data;
5199
+
5200
+ if (!isUndefined$1(props) && !isUndefined$1(props.innerHTML)) {
5201
+ if (elm.innerHTML === props.innerHTML) {
5202
+ delete props.innerHTML;
5203
+ } else {
5204
+ logWarn(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: innerHTML values do not match for element, will recover from the difference`, vnode.owner);
5205
+ }
5206
+ }
5207
+ }
5208
+
5209
+ hydrateElmHook(vnode);
5210
+
5211
+ if (!isDomManual) {
5212
+ hydrateChildrenHook(vnode.elm.childNodes, vnode.children, vnode.owner);
5213
+ }
4957
5214
  }
4958
5215
  };
4959
5216
  const CustomElementHook = {
@@ -5045,6 +5302,44 @@
5045
5302
  // will take care of disconnecting any child VM attached to its shadow as well.
5046
5303
  removeVM(vm);
5047
5304
  }
5305
+ },
5306
+ hydrate: (vnode, elm) => {
5307
+ // the element is created, but the vm is not
5308
+ const {
5309
+ sel,
5310
+ mode,
5311
+ ctor,
5312
+ owner
5313
+ } = vnode;
5314
+ const def = getComponentInternalDef(ctor);
5315
+ createVM(elm, def, {
5316
+ mode,
5317
+ owner,
5318
+ tagName: sel,
5319
+ renderer: owner.renderer
5320
+ });
5321
+ vnode.elm = elm;
5322
+ const vm = getAssociatedVM(elm);
5323
+ allocateChildrenHook(vnode, vm);
5324
+ hydrateElmHook(vnode); // Insert hook section:
5325
+
5326
+ if (process.env.NODE_ENV !== 'production') {
5327
+ assert.isTrue(vm.state === 0
5328
+ /* created */
5329
+ , `${vm} cannot be recycled.`);
5330
+ }
5331
+
5332
+ runConnectedCallback(vm);
5333
+
5334
+ if (vm.renderMode !== 0
5335
+ /* Light */
5336
+ ) {
5337
+ // VM is not rendering in Light DOM, we can proceed and hydrate the slotted content.
5338
+ // Note: for Light DOM, this is handled while hydrating the VM
5339
+ hydrateChildrenHook(vnode.elm.childNodes, vnode.children, vm);
5340
+ }
5341
+
5342
+ hydrateVM(vm);
5048
5343
  }
5049
5344
  };
5050
5345
 
@@ -5357,7 +5652,7 @@
5357
5652
 
5358
5653
 
5359
5654
  function d(value) {
5360
- return value == null ? '' : value;
5655
+ return value == null ? '' : String(value);
5361
5656
  } // [b]ind function
5362
5657
 
5363
5658
 
@@ -5519,6 +5814,26 @@
5519
5814
 
5520
5815
  markAsDynamicChildren(vnodes);
5521
5816
  return vnodes;
5817
+ }
5818
+ /**
5819
+ * EXPERIMENTAL: This function acts like a hook for Lightning Locker Service and other similar
5820
+ * libraries to sanitize HTML content. This hook process the content passed via the template to
5821
+ * lwc:inner-html directive.
5822
+ * It is meant to be overridden with setSanitizeHtmlContentHook, it throws an error by default.
5823
+ */
5824
+
5825
+
5826
+ let sanitizeHtmlContentHook = () => {
5827
+ // locker-service patches this function during runtime to sanitize HTML content.
5828
+ throw new Error('sanitizeHtmlContent hook must be implemented.');
5829
+ };
5830
+ /**
5831
+ * Sets the sanitizeHtmlContentHook.
5832
+ */
5833
+
5834
+
5835
+ function setSanitizeHtmlContentHook(newHookImpl) {
5836
+ sanitizeHtmlContentHook = newHookImpl;
5522
5837
  } // [s]anitize [h]tml [c]ontent
5523
5838
 
5524
5839
 
@@ -5713,7 +6028,10 @@
5713
6028
  for (let i = 0; i < stylesheets.length; i++) {
5714
6029
  renderer.insertGlobalStylesheet(stylesheets[i]);
5715
6030
  }
5716
- } else if (renderer.ssr) {
6031
+ } else if (renderer.ssr || renderer.isHydrating()) {
6032
+ // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
6033
+ // This works in the client, because the stylesheets are created, and cached in the VM
6034
+ // the first time the VM renders.
5717
6035
  // native shadow or light DOM, SSR
5718
6036
  const combinedStylesheetContent = ArrayJoin.call(stylesheets, '\n');
5719
6037
  return createInlineStyleVNode(combinedStylesheetContent);
@@ -6338,6 +6656,12 @@
6338
6656
  , vm);
6339
6657
  }
6340
6658
 
6659
+ function hydrateRootElement(elm) {
6660
+ const vm = getAssociatedVM(elm);
6661
+ runConnectedCallback(vm);
6662
+ hydrateVM(vm);
6663
+ }
6664
+
6341
6665
  function disconnectRootElement(elm) {
6342
6666
  const vm = getAssociatedVM(elm);
6343
6667
  resetComponentStateWhenRemoved(vm);
@@ -6345,6 +6669,10 @@
6345
6669
 
6346
6670
  function appendVM(vm) {
6347
6671
  rehydrate(vm);
6672
+ }
6673
+
6674
+ function hydrateVM(vm) {
6675
+ hydrate(vm);
6348
6676
  } // just in case the component comes back, with this we guarantee re-rendering it
6349
6677
  // while preventing any attempt to rehydration until after reinsertion.
6350
6678
 
@@ -6578,6 +6906,22 @@
6578
6906
  }
6579
6907
  }
6580
6908
 
6909
+ function hydrate(vm) {
6910
+ if (isTrue(vm.isDirty)) {
6911
+ // manually diffing/patching here.
6912
+ // This routine is:
6913
+ // patchShadowRoot(vm, children);
6914
+ // -> addVnodes.
6915
+ const children = renderComponent(vm);
6916
+ vm.children = children;
6917
+ const vmChildren = vm.renderMode === 0
6918
+ /* Light */
6919
+ ? vm.elm.childNodes : vm.elm.shadowRoot.childNodes;
6920
+ hydrateChildrenHook(vmChildren, children, vm);
6921
+ runRenderedCallback(vm);
6922
+ }
6923
+ }
6924
+
6581
6925
  function patchShadowRoot(vm, newCh) {
6582
6926
  const {
6583
6927
  children: oldCh
@@ -7404,28 +7748,12 @@
7404
7748
 
7405
7749
  let hooksAreSet = false;
7406
7750
 
7407
- function overrideHooks(hooks) {
7408
- const oldHooks = {};
7409
-
7410
- if (!isUndefined$1(hooks.sanitizeHtmlContent)) {
7411
- oldHooks.sanitizeHtmlContent = setSanitizeHtmlContentHook(hooks.sanitizeHtmlContent);
7412
- }
7413
-
7414
- return oldHooks;
7415
- }
7416
-
7417
7751
  function setHooks(hooks) {
7418
7752
  assert.isFalse(hooksAreSet, 'Hooks are already overridden, only one definition is allowed.');
7419
- overrideHooks(hooks);
7420
7753
  hooksAreSet = true;
7754
+ setSanitizeHtmlContentHook(hooks.sanitizeHtmlContent);
7421
7755
  }
7422
-
7423
- function setHooksForTest(hooks) {
7424
- if (process.env.NODE_ENV !== 'production') {
7425
- return overrideHooks(hooks);
7426
- }
7427
- }
7428
- /* version: 2.5.6 */
7756
+ /* version: 2.5.10-alpha1 */
7429
7757
 
7430
7758
  /*
7431
7759
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7569,8 +7897,19 @@
7569
7897
  HTMLElementConstructor.prototype = HTMLElement.prototype;
7570
7898
  }
7571
7899
 
7900
+ let isHydrating = false;
7901
+
7902
+ function setIsHydrating(v) {
7903
+ isHydrating = v;
7904
+ }
7905
+
7572
7906
  const renderer = {
7573
7907
  ssr: false,
7908
+
7909
+ isHydrating() {
7910
+ return isHydrating;
7911
+ },
7912
+
7574
7913
  isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
7575
7914
  isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
7576
7915
 
@@ -7599,6 +7938,10 @@
7599
7938
  },
7600
7939
 
7601
7940
  attachShadow(element, options) {
7941
+ if (isHydrating) {
7942
+ return element.shadowRoot;
7943
+ }
7944
+
7602
7945
  return element.attachShadow(options);
7603
7946
  },
7604
7947
 
@@ -7736,61 +8079,6 @@
7736
8079
  getCustomElement,
7737
8080
  HTMLElement: HTMLElementConstructor
7738
8081
  };
7739
- /*
7740
- * Copyright (c) 2018, salesforce.com, inc.
7741
- * All rights reserved.
7742
- * SPDX-License-Identifier: MIT
7743
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7744
- */
7745
-
7746
- /**
7747
- * This function builds a Web Component class from a LWC constructor so it can be
7748
- * registered as a new element via customElements.define() at any given time.
7749
- *
7750
- * @deprecated since version 1.3.11
7751
- *
7752
- * @example
7753
- * ```
7754
- * import { buildCustomElementConstructor } from 'lwc';
7755
- * import Foo from 'ns/foo';
7756
- * const WC = buildCustomElementConstructor(Foo);
7757
- * customElements.define('x-foo', WC);
7758
- * const elm = document.createElement('x-foo');
7759
- * ```
7760
- */
7761
-
7762
- function deprecatedBuildCustomElementConstructor(Ctor) {
7763
- if (process.env.NODE_ENV !== 'production') {
7764
- /* eslint-disable-next-line no-console */
7765
- 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.`);
7766
- }
7767
-
7768
- return Ctor.CustomElementConstructor;
7769
- }
7770
-
7771
- function buildCustomElementConstructor(Ctor) {
7772
- const def = getComponentInternalDef(Ctor);
7773
- return class extends def.bridge {
7774
- constructor() {
7775
- super();
7776
- createVM(this, def, {
7777
- mode: 'open',
7778
- owner: null,
7779
- tagName: this.tagName,
7780
- renderer
7781
- });
7782
- }
7783
-
7784
- connectedCallback() {
7785
- connectRootElement(this);
7786
- }
7787
-
7788
- disconnectedCallback() {
7789
- disconnectRootElement(this);
7790
- }
7791
-
7792
- };
7793
- }
7794
8082
  /*
7795
8083
  * Copyright (c) 2018, salesforce.com, inc.
7796
8084
  * All rights reserved.
@@ -7800,7 +8088,6 @@
7800
8088
  // TODO [#2472]: Remove this workaround when appropriate.
7801
8089
  // eslint-disable-next-line lwc-internal/no-global-node
7802
8090
 
7803
-
7804
8091
  const _Node$1 = Node;
7805
8092
  const ConnectingSlot = new WeakMap();
7806
8093
  const DisconnectingSlot = new WeakMap();
@@ -7911,6 +8198,118 @@
7911
8198
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7912
8199
  */
7913
8200
 
8201
+
8202
+ function hydrateComponent(element, Ctor, props = {}) {
8203
+ if (!isFunction$1(Ctor)) {
8204
+ throw new TypeError(`"hydrateComponent" expects a valid component constructor as the second parameter but instead received ${Ctor}.`);
8205
+ }
8206
+
8207
+ if (!isObject(props) || isNull(props)) {
8208
+ throw new TypeError(`"hydrateComponent" expects an object as the third parameter but instead received ${props}.`);
8209
+ }
8210
+
8211
+ const def = getComponentInternalDef(Ctor);
8212
+
8213
+ try {
8214
+ // Let the renderer know we are hydrating, so it does not replace the existing shadowRoot
8215
+ // and uses the same algo to create the stylesheets as in SSR.
8216
+ setIsHydrating(true);
8217
+ createVM(element, def, {
8218
+ mode: 'open',
8219
+ owner: null,
8220
+ renderer,
8221
+ tagName: element.tagName.toLowerCase()
8222
+ });
8223
+
8224
+ for (const [key, value] of Object.entries(props)) {
8225
+ element[key] = value;
8226
+ }
8227
+
8228
+ hydrateRootElement(element); // set it back since now we finished hydration.
8229
+
8230
+ setIsHydrating(false);
8231
+ } catch (e) {
8232
+ // Fallback: In case there's an error while hydrating, let's log the error, and replace the element with
8233
+ // the client generated DOM.
8234
+
8235
+ /* eslint-disable-next-line no-console */
8236
+ console.error('Recovering from error while hydrating: ', e);
8237
+ setIsHydrating(false);
8238
+ const newElem = createElement(element.tagName, {
8239
+ is: Ctor,
8240
+ mode: 'open'
8241
+ });
8242
+
8243
+ for (const [key, value] of Object.entries(props)) {
8244
+ newElem[key] = value;
8245
+ }
8246
+
8247
+ element.parentNode.replaceChild(newElem, element);
8248
+ }
8249
+ }
8250
+ /*
8251
+ * Copyright (c) 2018, salesforce.com, inc.
8252
+ * All rights reserved.
8253
+ * SPDX-License-Identifier: MIT
8254
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
8255
+ */
8256
+
8257
+ /**
8258
+ * This function builds a Web Component class from a LWC constructor so it can be
8259
+ * registered as a new element via customElements.define() at any given time.
8260
+ *
8261
+ * @deprecated since version 1.3.11
8262
+ *
8263
+ * @example
8264
+ * ```
8265
+ * import { buildCustomElementConstructor } from 'lwc';
8266
+ * import Foo from 'ns/foo';
8267
+ * const WC = buildCustomElementConstructor(Foo);
8268
+ * customElements.define('x-foo', WC);
8269
+ * const elm = document.createElement('x-foo');
8270
+ * ```
8271
+ */
8272
+
8273
+
8274
+ function deprecatedBuildCustomElementConstructor(Ctor) {
8275
+ if (process.env.NODE_ENV !== 'production') {
8276
+ /* eslint-disable-next-line no-console */
8277
+ 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.`);
8278
+ }
8279
+
8280
+ return Ctor.CustomElementConstructor;
8281
+ }
8282
+
8283
+ function buildCustomElementConstructor(Ctor) {
8284
+ const def = getComponentInternalDef(Ctor);
8285
+ return class extends def.bridge {
8286
+ constructor() {
8287
+ super();
8288
+ createVM(this, def, {
8289
+ mode: 'open',
8290
+ owner: null,
8291
+ tagName: this.tagName,
8292
+ renderer
8293
+ });
8294
+ }
8295
+
8296
+ connectedCallback() {
8297
+ connectRootElement(this);
8298
+ }
8299
+
8300
+ disconnectedCallback() {
8301
+ disconnectRootElement(this);
8302
+ }
8303
+
8304
+ };
8305
+ }
8306
+ /*
8307
+ * Copyright (c) 2018, salesforce.com, inc.
8308
+ * All rights reserved.
8309
+ * SPDX-License-Identifier: MIT
8310
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
8311
+ */
8312
+
7914
8313
  /**
7915
8314
  * EXPERIMENTAL: This function provides access to the component constructor, given an HTMLElement.
7916
8315
  * This API is subject to change or being removed.
@@ -8010,7 +8409,7 @@
8010
8409
  });
8011
8410
  freeze(LightningElement);
8012
8411
  seal(LightningElement.prototype);
8013
- /* version: 2.5.6 */
8412
+ /* version: 2.5.10-alpha1 */
8014
8413
 
8015
8414
  exports.LightningElement = LightningElement;
8016
8415
  exports.__unstable__ProfilerControl = profilerControl;
@@ -8020,6 +8419,7 @@
8020
8419
  exports.createElement = createElement;
8021
8420
  exports.getComponentConstructor = getComponentConstructor;
8022
8421
  exports.getComponentDef = getComponentDef;
8422
+ exports.hydrateComponent = hydrateComponent;
8023
8423
  exports.isComponentConstructor = isComponentConstructor;
8024
8424
  exports.isNodeFromTemplate = isNodeFromTemplate;
8025
8425
  exports.readonly = readonly;
@@ -8031,7 +8431,6 @@
8031
8431
  exports.setFeatureFlag = setFeatureFlag;
8032
8432
  exports.setFeatureFlagForTest = setFeatureFlagForTest;
8033
8433
  exports.setHooks = setHooks;
8034
- exports.setHooksForTest = setHooksForTest;
8035
8434
  exports.swapComponent = swapComponent;
8036
8435
  exports.swapStyle = swapStyle;
8037
8436
  exports.swapTemplate = swapTemplate;
@@ -8041,4 +8440,4 @@
8041
8440
 
8042
8441
  Object.defineProperty(exports, '__esModule', { value: true });
8043
8442
 
8044
- }));
8443
+ })));