lwc 2.5.4 → 2.5.8

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 (39) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +567 -99
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +568 -98
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +2 -2
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +383 -90
  5. package/dist/engine-dom/iife/es5/engine-dom.js +634 -150
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +2 -2
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +430 -133
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +568 -98
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +2 -2
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +383 -90
  11. package/dist/engine-dom/umd/es5/engine-dom.js +634 -150
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +2 -2
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +430 -133
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +457 -49
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +2 -2
  16. package/dist/engine-server/esm/es2017/engine-server.js +457 -50
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +9 -39
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +9 -39
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +2 -2
  20. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +9 -39
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +9 -39
  22. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js +2 -2
  23. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +9 -39
  24. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +9 -39
  25. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +2 -2
  26. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +9 -39
  27. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +9 -39
  28. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js +2 -2
  29. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +9 -39
  30. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  31. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/iife/es5/wire-service.js +2 -2
  34. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  35. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  36. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  37. package/dist/wire-service/umd/es5/wire-service.js +2 -2
  38. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  39. package/package.json +8 -8
@@ -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.4 */
302
+ /** version: 2.5.8 */
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.4 */
482
+ /** version: 2.5.8 */
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.
@@ -3095,8 +3125,10 @@ for (const [elementProp, rendererMethod] of childGetters) {
3095
3125
  }
3096
3126
 
3097
3127
  return renderer[rendererMethod](elm);
3098
- }
3128
+ },
3099
3129
 
3130
+ configurable: true,
3131
+ enumerable: true
3100
3132
  };
3101
3133
  }
3102
3134
 
@@ -3116,8 +3148,11 @@ for (const queryMethod of queryMethods) {
3116
3148
  }
3117
3149
 
3118
3150
  return renderer[queryMethod](elm, arg);
3119
- }
3151
+ },
3120
3152
 
3153
+ configurable: true,
3154
+ enumerable: true,
3155
+ writable: true
3121
3156
  };
3122
3157
  }
3123
3158
 
@@ -3712,15 +3747,14 @@ function registerTemplate(tpl) {
3712
3747
  return tpl;
3713
3748
  }
3714
3749
  /**
3715
- * EXPERIMENTAL: This function acts like a hook for Lightning Locker
3716
- * Service and other similar libraries to sanitize vulnerable attributes.
3717
- * This API is subject to change or being removed.
3750
+ * EXPERIMENTAL: This function acts like a hook for Lightning Locker Service and other similar
3751
+ * libraries to sanitize vulnerable attributes.
3718
3752
  */
3719
3753
 
3720
3754
 
3721
3755
  function sanitizeAttribute(tagName, namespaceUri, attrName, attrValue) {
3722
- // locker-service patches this function during runtime to sanitize vulnerable attributes.
3723
- // when ran off-core this function becomes a noop and returns the user authored value.
3756
+ // locker-service patches this function during runtime to sanitize vulnerable attributes. When
3757
+ // ran off-core this function becomes a noop and returns the user authored value.
3724
3758
  return attrValue;
3725
3759
  }
3726
3760
  /*
@@ -4276,7 +4310,7 @@ function createComponentDef(Ctor) {
4276
4310
  if (!isUndefined$1(ctorShadowSupportMode)) {
4277
4311
  assert.invariant(ctorShadowSupportMode === "any"
4278
4312
  /* Any */
4279
- || ctorShadowSupportMode === "default"
4313
+ || ctorShadowSupportMode === "reset"
4280
4314
  /* Default */
4281
4315
  , `Invalid value for static property shadowSupportMode: '${ctorShadowSupportMode}'`);
4282
4316
  }
@@ -4438,7 +4472,7 @@ const lightingElementDef = {
4438
4472
  renderMode: 1
4439
4473
  /* Shadow */
4440
4474
  ,
4441
- shadowSupportMode: "default"
4475
+ shadowSupportMode: "reset"
4442
4476
  /* Default */
4443
4477
  ,
4444
4478
  wire: EmptyObject,
@@ -4587,6 +4621,17 @@ function createElmHook(vnode) {
4587
4621
  modComputedStyle.create(vnode);
4588
4622
  }
4589
4623
 
4624
+ function hydrateElmHook(vnode) {
4625
+ modEvents.create(vnode); // Attrs are already on the element.
4626
+ // modAttrs.create(vnode);
4627
+
4628
+ modProps.create(vnode); // Already set.
4629
+ // modStaticClassName.create(vnode);
4630
+ // modStaticStyle.create(vnode);
4631
+ // modComputedClassName.create(vnode);
4632
+ // modComputedStyle.create(vnode);
4633
+ }
4634
+
4590
4635
  function fallbackElmHook(elm, vnode) {
4591
4636
  const {
4592
4637
  owner
@@ -4758,6 +4803,179 @@ function createChildrenHook(vnode) {
4758
4803
  }
4759
4804
  }
4760
4805
 
4806
+ function isElementNode(node) {
4807
+ // eslint-disable-next-line lwc-internal/no-global-node
4808
+ return node.nodeType === Node.ELEMENT_NODE;
4809
+ }
4810
+
4811
+ function vnodesAndElementHaveCompatibleAttrs(vnode, elm) {
4812
+ const {
4813
+ data: {
4814
+ attrs = {}
4815
+ },
4816
+ owner: {
4817
+ renderer
4818
+ }
4819
+ } = vnode;
4820
+ let nodesAreCompatible = true; // Validate attributes, though we could always recovery from those by running the update mods.
4821
+ // Note: intentionally ONLY matching vnodes.attrs to elm.attrs, in case SSR is adding extra attributes.
4822
+
4823
+ for (const [attrName, attrValue] of Object.entries(attrs)) {
4824
+ const elmAttrValue = renderer.getAttribute(elm, attrName);
4825
+
4826
+ if (attrValue !== elmAttrValue) {
4827
+ logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "${attrName}" has different values, expected "${attrValue}" but found "${elmAttrValue}"`, vnode.owner);
4828
+ nodesAreCompatible = false;
4829
+ }
4830
+ }
4831
+
4832
+ return nodesAreCompatible;
4833
+ }
4834
+
4835
+ function vnodesAndElementHaveCompatibleClass(vnode, elm) {
4836
+ const {
4837
+ data: {
4838
+ className,
4839
+ classMap
4840
+ },
4841
+ owner: {
4842
+ renderer
4843
+ }
4844
+ } = vnode;
4845
+ let nodesAreCompatible = true;
4846
+ let vnodeClassName;
4847
+
4848
+ if (!isUndefined$1(className) && className !== elm.className) {
4849
+ // className is used when class is bound to an expr.
4850
+ nodesAreCompatible = false;
4851
+ vnodeClassName = className;
4852
+ } else if (!isUndefined$1(classMap)) {
4853
+ // classMap is used when class is set to static value.
4854
+ const classList = renderer.getClassList(elm);
4855
+ let computedClassName = ''; // all classes from the vnode should be in the element.classList
4856
+
4857
+ for (const name in classMap) {
4858
+ computedClassName += ' ' + name;
4859
+
4860
+ if (!classList.contains(name)) {
4861
+ nodesAreCompatible = false;
4862
+ }
4863
+ }
4864
+
4865
+ vnodeClassName = computedClassName.trim();
4866
+
4867
+ if (classList.length > keys(classMap).length) {
4868
+ nodesAreCompatible = false;
4869
+ }
4870
+ }
4871
+
4872
+ if (!nodesAreCompatible) {
4873
+ logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "class" has different values, expected "${vnodeClassName}" but found "${elm.className}"`, vnode.owner);
4874
+ }
4875
+
4876
+ return nodesAreCompatible;
4877
+ }
4878
+
4879
+ function vnodesAndElementHaveCompatibleStyle(vnode, elm) {
4880
+ const {
4881
+ data: {
4882
+ style,
4883
+ styleDecls
4884
+ },
4885
+ owner: {
4886
+ renderer
4887
+ }
4888
+ } = vnode;
4889
+ const elmStyle = renderer.getAttribute(elm, 'style') || '';
4890
+ let vnodeStyle;
4891
+ let nodesAreCompatible = true;
4892
+
4893
+ if (!isUndefined$1(style) && style !== elmStyle) {
4894
+ nodesAreCompatible = false;
4895
+ vnodeStyle = style;
4896
+ } else if (!isUndefined$1(styleDecls)) {
4897
+ const parsedVnodeStyle = parseStyleText(elmStyle);
4898
+ const expectedStyle = []; // styleMap is used when style is set to static value.
4899
+
4900
+ for (let i = 0, n = styleDecls.length; i < n; i++) {
4901
+ const [prop, value, important] = styleDecls[i];
4902
+ expectedStyle.push(`${prop}: ${value + (important ? ' important!' : '')}`);
4903
+ const parsedPropValue = parsedVnodeStyle[prop];
4904
+
4905
+ if (isUndefined$1(parsedPropValue)) {
4906
+ nodesAreCompatible = false;
4907
+ } else if (!parsedPropValue.startsWith(value)) {
4908
+ nodesAreCompatible = false;
4909
+ } else if (important && !parsedPropValue.endsWith('!important')) {
4910
+ nodesAreCompatible = false;
4911
+ }
4912
+ }
4913
+
4914
+ if (keys(parsedVnodeStyle).length > styleDecls.length) {
4915
+ nodesAreCompatible = false;
4916
+ }
4917
+
4918
+ vnodeStyle = ArrayJoin.call(expectedStyle, ';');
4919
+ }
4920
+
4921
+ if (!nodesAreCompatible) {
4922
+ // style is used when class is bound to an expr.
4923
+ logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "style" has different values, expected "${vnodeStyle}" but found "${elmStyle}".`, vnode.owner);
4924
+ }
4925
+
4926
+ return nodesAreCompatible;
4927
+ }
4928
+
4929
+ function throwHydrationError() {
4930
+ assert.fail('Server rendered elements do not match client side generated elements');
4931
+ }
4932
+
4933
+ function hydrateChildrenHook(elmChildren, children, vm) {
4934
+ var _a, _b;
4935
+
4936
+ if (process.env.NODE_ENV !== 'production') {
4937
+ const filteredVNodes = ArrayFilter.call(children, vnode => !!vnode);
4938
+
4939
+ if (elmChildren.length !== filteredVNodes.length) {
4940
+ logError(`Hydration mismatch: incorrect number of rendered nodes, expected ${filteredVNodes.length} but found ${elmChildren.length}.`, vm);
4941
+ throwHydrationError();
4942
+ }
4943
+ }
4944
+
4945
+ let elmCurrentChildIdx = 0;
4946
+
4947
+ for (let j = 0, n = children.length; j < n; j++) {
4948
+ const ch = children[j];
4949
+
4950
+ if (ch != null) {
4951
+ const childNode = elmChildren[elmCurrentChildIdx];
4952
+
4953
+ if (process.env.NODE_ENV !== 'production') {
4954
+ // VComments and VTexts validation is handled in their hooks
4955
+ if (isElementNode(childNode)) {
4956
+ if (((_a = ch.sel) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== childNode.tagName.toLowerCase()) {
4957
+ logError(`Hydration mismatch: expecting element with tag "${(_b = ch.sel) === null || _b === void 0 ? void 0 : _b.toLowerCase()}" but found "${childNode.tagName.toLowerCase()}".`, vm);
4958
+ throwHydrationError();
4959
+ } // Note: props are not yet set
4960
+
4961
+
4962
+ const hasIncompatibleAttrs = vnodesAndElementHaveCompatibleAttrs(ch, childNode);
4963
+ const hasIncompatibleClass = vnodesAndElementHaveCompatibleClass(ch, childNode);
4964
+ const hasIncompatibleStyle = vnodesAndElementHaveCompatibleStyle(ch, childNode);
4965
+ const isVNodeAndElementCompatible = hasIncompatibleAttrs && hasIncompatibleClass && hasIncompatibleStyle;
4966
+
4967
+ if (!isVNodeAndElementCompatible) {
4968
+ throwHydrationError();
4969
+ }
4970
+ }
4971
+ }
4972
+
4973
+ ch.hook.hydrate(ch, childNode);
4974
+ elmCurrentChildIdx++;
4975
+ }
4976
+ }
4977
+ }
4978
+
4761
4979
  function updateCustomElmHook(oldVnode, vnode) {
4762
4980
  // Attrs need to be applied to element before props
4763
4981
  // IE11 will wipe out value on radio inputs if value
@@ -4859,7 +5077,26 @@ const TextHook = {
4859
5077
  update: updateNodeHook,
4860
5078
  insert: insertNodeHook,
4861
5079
  move: insertNodeHook,
4862
- remove: removeNodeHook
5080
+ remove: removeNodeHook,
5081
+ hydrate: (vNode, node) => {
5082
+ var _a;
5083
+
5084
+ if (process.env.NODE_ENV !== 'production') {
5085
+ // eslint-disable-next-line lwc-internal/no-global-node
5086
+ if (node.nodeType !== Node.TEXT_NODE) {
5087
+ logError('Hydration mismatch: incorrect node type received', vNode.owner);
5088
+ assert.fail('Hydration mismatch: incorrect node type received.');
5089
+ }
5090
+
5091
+ if (node.nodeValue !== vNode.text) {
5092
+ logWarn('Hydration mismatch: text values do not match, will recover from the difference', vNode.owner);
5093
+ }
5094
+ } // always set the text value to the one from the vnode.
5095
+
5096
+
5097
+ node.nodeValue = (_a = vNode.text) !== null && _a !== void 0 ? _a : null;
5098
+ vNode.elm = node;
5099
+ }
4863
5100
  };
4864
5101
  const CommentHook = {
4865
5102
  create: vnode => {
@@ -4877,7 +5114,26 @@ const CommentHook = {
4877
5114
  update: updateNodeHook,
4878
5115
  insert: insertNodeHook,
4879
5116
  move: insertNodeHook,
4880
- remove: removeNodeHook
5117
+ remove: removeNodeHook,
5118
+ hydrate: (vNode, node) => {
5119
+ var _a;
5120
+
5121
+ if (process.env.NODE_ENV !== 'production') {
5122
+ // eslint-disable-next-line lwc-internal/no-global-node
5123
+ if (node.nodeType !== Node.COMMENT_NODE) {
5124
+ logError('Hydration mismatch: incorrect node type received', vNode.owner);
5125
+ assert.fail('Hydration mismatch: incorrect node type received.');
5126
+ }
5127
+
5128
+ if (node.nodeValue !== vNode.text) {
5129
+ logWarn('Hydration mismatch: comment values do not match, will recover from the difference', vNode.owner);
5130
+ }
5131
+ } // always set the text value to the one from the vnode.
5132
+
5133
+
5134
+ node.nodeValue = (_a = vNode.text) !== null && _a !== void 0 ? _a : null;
5135
+ vNode.elm = node;
5136
+ }
4881
5137
  }; // insert is called after update, which is used somewhere else (via a module)
4882
5138
  // to mark the vm as inserted, that means we cannot use update as the main channel
4883
5139
  // to rehydrate when dirty, because sometimes the element is not inserted just yet,
@@ -4917,6 +5173,38 @@ const ElementHook = {
4917
5173
  remove: (vnode, parentNode) => {
4918
5174
  removeNodeHook(vnode, parentNode);
4919
5175
  removeElmHook(vnode);
5176
+ },
5177
+ hydrate: (vnode, node) => {
5178
+ const elm = node;
5179
+ vnode.elm = elm;
5180
+ const {
5181
+ context
5182
+ } = vnode.data;
5183
+ const isDomManual = Boolean(!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
5184
+ /* manual */
5185
+ );
5186
+
5187
+ if (isDomManual) {
5188
+ // it may be that this element has lwc:inner-html, we need to diff and in case are the same,
5189
+ // remove the innerHTML from props so it reuses the existing dom elements.
5190
+ const {
5191
+ props
5192
+ } = vnode.data;
5193
+
5194
+ if (!isUndefined$1(props) && !isUndefined$1(props.innerHTML)) {
5195
+ if (elm.innerHTML === props.innerHTML) {
5196
+ delete props.innerHTML;
5197
+ } else {
5198
+ logWarn(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: innerHTML values do not match for element, will recover from the difference`, vnode.owner);
5199
+ }
5200
+ }
5201
+ }
5202
+
5203
+ hydrateElmHook(vnode);
5204
+
5205
+ if (!isDomManual) {
5206
+ hydrateChildrenHook(vnode.elm.childNodes, vnode.children, vnode.owner);
5207
+ }
4920
5208
  }
4921
5209
  };
4922
5210
  const CustomElementHook = {
@@ -5008,6 +5296,44 @@ const CustomElementHook = {
5008
5296
  // will take care of disconnecting any child VM attached to its shadow as well.
5009
5297
  removeVM(vm);
5010
5298
  }
5299
+ },
5300
+ hydrate: (vnode, elm) => {
5301
+ // the element is created, but the vm is not
5302
+ const {
5303
+ sel,
5304
+ mode,
5305
+ ctor,
5306
+ owner
5307
+ } = vnode;
5308
+ const def = getComponentInternalDef(ctor);
5309
+ createVM(elm, def, {
5310
+ mode,
5311
+ owner,
5312
+ tagName: sel,
5313
+ renderer: owner.renderer
5314
+ });
5315
+ vnode.elm = elm;
5316
+ const vm = getAssociatedVM(elm);
5317
+ allocateChildrenHook(vnode, vm);
5318
+ hydrateElmHook(vnode); // Insert hook section:
5319
+
5320
+ if (process.env.NODE_ENV !== 'production') {
5321
+ assert.isTrue(vm.state === 0
5322
+ /* created */
5323
+ , `${vm} cannot be recycled.`);
5324
+ }
5325
+
5326
+ runConnectedCallback(vm);
5327
+
5328
+ if (vm.renderMode !== 0
5329
+ /* Light */
5330
+ ) {
5331
+ // VM is not rendering in Light DOM, we can proceed and hydrate the slotted content.
5332
+ // Note: for Light DOM, this is handled while hydrating the VM
5333
+ hydrateChildrenHook(vnode.elm.childNodes, vnode.children, vm);
5334
+ }
5335
+
5336
+ hydrateVM(vm);
5011
5337
  }
5012
5338
  };
5013
5339
 
@@ -5216,7 +5542,7 @@ function i(iterable, factory) {
5216
5542
  next = iterator.next();
5217
5543
  last = next.done; // template factory logic based on the previous collected value
5218
5544
 
5219
- const vnode = factory(value, j, j === 0, last);
5545
+ const vnode = factory(value, j, j === 0, last === true);
5220
5546
 
5221
5547
  if (isArray$1(vnode)) {
5222
5548
  ArrayPush$1.apply(list, vnode);
@@ -5483,24 +5809,48 @@ function sc(vnodes) {
5483
5809
  markAsDynamicChildren(vnodes);
5484
5810
  return vnodes;
5485
5811
  }
5812
+ /**
5813
+ * EXPERIMENTAL: This function acts like a hook for Lightning Locker Service and other similar
5814
+ * libraries to sanitize HTML content. This hook process the content passed via the template to
5815
+ * lwc:inner-html directive.
5816
+ * It is meant to be overridden with setSanitizeHtmlContentHook, it throws an error by default.
5817
+ */
5486
5818
 
5487
- var api = /*#__PURE__*/Object.freeze({
5488
- __proto__: null,
5489
- h: h,
5490
- ti: ti,
5491
- s: s,
5492
- c: c,
5493
- i: i,
5494
- f: f,
5495
- t: t,
5496
- co: co,
5497
- d: d,
5498
- b: b,
5499
- k: k,
5500
- gid: gid,
5501
- fid: fid,
5502
- dc: dc,
5503
- sc: sc
5819
+
5820
+ let sanitizeHtmlContentHook = () => {
5821
+ // locker-service patches this function during runtime to sanitize HTML content.
5822
+ throw new Error('sanitizeHtmlContent hook must be implemented.');
5823
+ };
5824
+ /**
5825
+ * Sets the sanitizeHtmlContentHook.
5826
+ */
5827
+
5828
+
5829
+ function setSanitizeHtmlContentHook(newHookImpl) {
5830
+ sanitizeHtmlContentHook = newHookImpl;
5831
+ } // [s]anitize [h]tml [c]ontent
5832
+
5833
+
5834
+ function shc(content) {
5835
+ return sanitizeHtmlContentHook(content);
5836
+ }
5837
+
5838
+ const api = freeze({
5839
+ s,
5840
+ h,
5841
+ c,
5842
+ i,
5843
+ f,
5844
+ t,
5845
+ d,
5846
+ b,
5847
+ k,
5848
+ co,
5849
+ dc,
5850
+ ti,
5851
+ gid,
5852
+ fid,
5853
+ shc
5504
5854
  });
5505
5855
  /*
5506
5856
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5514,12 +5864,12 @@ function makeHostToken(token) {
5514
5864
  }
5515
5865
 
5516
5866
  function createInlineStyleVNode(content) {
5517
- return h('style', {
5867
+ return api.h('style', {
5518
5868
  key: 'style',
5519
5869
  attrs: {
5520
5870
  type: 'text/css'
5521
5871
  }
5522
- }, [t(content)]);
5872
+ }, [api.t(content)]);
5523
5873
  }
5524
5874
 
5525
5875
  function updateStylesheetToken(vm, template) {
@@ -5672,7 +6022,10 @@ function createStylesheet(vm, stylesheets) {
5672
6022
  for (let i = 0; i < stylesheets.length; i++) {
5673
6023
  renderer.insertGlobalStylesheet(stylesheets[i]);
5674
6024
  }
5675
- } else if (renderer.ssr) {
6025
+ } else if (renderer.ssr || renderer.isHydrating) {
6026
+ // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
6027
+ // This works in the client, because the stylesheets are created, and cached in the VM
6028
+ // the first time the VM renders.
5676
6029
  // native shadow or light DOM, SSR
5677
6030
  const combinedStylesheetContent = ArrayJoin.call(stylesheets, '\n');
5678
6031
  return createInlineStyleVNode(combinedStylesheetContent);
@@ -6297,6 +6650,12 @@ function connectRootElement(elm) {
6297
6650
  , vm);
6298
6651
  }
6299
6652
 
6653
+ function hydrateRootElement(elm) {
6654
+ const vm = getAssociatedVM(elm);
6655
+ runConnectedCallback(vm);
6656
+ hydrateVM(vm);
6657
+ }
6658
+
6300
6659
  function disconnectRootElement(elm) {
6301
6660
  const vm = getAssociatedVM(elm);
6302
6661
  resetComponentStateWhenRemoved(vm);
@@ -6304,6 +6663,10 @@ function disconnectRootElement(elm) {
6304
6663
 
6305
6664
  function appendVM(vm) {
6306
6665
  rehydrate(vm);
6666
+ }
6667
+
6668
+ function hydrateVM(vm) {
6669
+ hydrate(vm);
6307
6670
  } // just in case the component comes back, with this we guarantee re-rendering it
6308
6671
  // while preventing any attempt to rehydration until after reinsertion.
6309
6672
 
@@ -6537,6 +6900,22 @@ function rehydrate(vm) {
6537
6900
  }
6538
6901
  }
6539
6902
 
6903
+ function hydrate(vm) {
6904
+ if (isTrue(vm.isDirty)) {
6905
+ // manually diffing/patching here.
6906
+ // This routine is:
6907
+ // patchShadowRoot(vm, children);
6908
+ // -> addVnodes.
6909
+ const children = renderComponent(vm);
6910
+ vm.children = children;
6911
+ const vmChildren = vm.renderMode === 0
6912
+ /* Light */
6913
+ ? vm.elm.childNodes : vm.elm.shadowRoot.childNodes;
6914
+ hydrateChildrenHook(vmChildren, children, vm);
6915
+ runRenderedCallback(vm);
6916
+ }
6917
+ }
6918
+
6540
6919
  function patchShadowRoot(vm, newCh) {
6541
6920
  const {
6542
6921
  children: oldCh
@@ -7353,7 +7732,22 @@ function readonly(obj) {
7353
7732
 
7354
7733
  return reactiveMembrane.getReadOnlyProxy(obj);
7355
7734
  }
7356
- /* version: 2.5.4 */
7735
+ /*
7736
+ * Copyright (c) 2018, salesforce.com, inc.
7737
+ * All rights reserved.
7738
+ * SPDX-License-Identifier: MIT
7739
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7740
+ */
7741
+
7742
+
7743
+ let hooksAreSet = false;
7744
+
7745
+ function setHooks(hooks) {
7746
+ assert.isFalse(hooksAreSet, 'Hooks are already overridden, only one definition is allowed.');
7747
+ hooksAreSet = true;
7748
+ setSanitizeHtmlContentHook(hooks.sanitizeHtmlContent);
7749
+ }
7750
+ /* version: 2.5.8 */
7357
7751
 
7358
7752
  /*
7359
7753
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7374,8 +7768,11 @@ if (process.env.NODE_ENV === 'development') {
7374
7768
  };
7375
7769
  }
7376
7770
 
7377
- const globalStylesheetsParentElement = document.head || document.body || document;
7378
- const supportsConstructableStyleSheets = isFunction$1(CSSStyleSheet.prototype.replaceSync);
7771
+ const globalStylesheetsParentElement = document.head || document.body || document; // This check for constructable stylesheets is similar to Fast's:
7772
+ // https://github.com/microsoft/fast/blob/d49d1ec/packages/web-components/fast-element/src/dom.ts#L51-L53
7773
+ // See also: https://github.com/whatwg/webidl/issues/1027#issuecomment-934510070
7774
+
7775
+ const supportsConstructableStyleSheets = isFunction$1(CSSStyleSheet.prototype.replaceSync) && isArray$1(document.adoptedStyleSheets);
7379
7776
  const styleElements = create(null);
7380
7777
  const styleSheets = create(null);
7381
7778
  const nodesToStyleSheets = new WeakMap();
@@ -7494,8 +7891,19 @@ if (isCustomElementRegistryAvailable()) {
7494
7891
  HTMLElementConstructor.prototype = HTMLElement.prototype;
7495
7892
  }
7496
7893
 
7894
+ let isHydrating = false;
7895
+
7896
+ function setIsHydrating(v) {
7897
+ isHydrating = v;
7898
+ }
7899
+
7497
7900
  const renderer = {
7498
7901
  ssr: false,
7902
+
7903
+ get isHydrating() {
7904
+ return isHydrating;
7905
+ },
7906
+
7499
7907
  isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
7500
7908
  isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
7501
7909
 
@@ -7524,6 +7932,10 @@ const renderer = {
7524
7932
  },
7525
7933
 
7526
7934
  attachShadow(element, options) {
7935
+ if (isHydrating) {
7936
+ return element.shadowRoot;
7937
+ }
7938
+
7527
7939
  return element.attachShadow(options);
7528
7940
  },
7529
7941
 
@@ -7661,61 +8073,6 @@ const renderer = {
7661
8073
  getCustomElement,
7662
8074
  HTMLElement: HTMLElementConstructor
7663
8075
  };
7664
- /*
7665
- * Copyright (c) 2018, salesforce.com, inc.
7666
- * All rights reserved.
7667
- * SPDX-License-Identifier: MIT
7668
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7669
- */
7670
-
7671
- /**
7672
- * This function builds a Web Component class from a LWC constructor so it can be
7673
- * registered as a new element via customElements.define() at any given time.
7674
- *
7675
- * @deprecated since version 1.3.11
7676
- *
7677
- * @example
7678
- * ```
7679
- * import { buildCustomElementConstructor } from 'lwc';
7680
- * import Foo from 'ns/foo';
7681
- * const WC = buildCustomElementConstructor(Foo);
7682
- * customElements.define('x-foo', WC);
7683
- * const elm = document.createElement('x-foo');
7684
- * ```
7685
- */
7686
-
7687
- function deprecatedBuildCustomElementConstructor(Ctor) {
7688
- if (process.env.NODE_ENV !== 'production') {
7689
- /* eslint-disable-next-line no-console */
7690
- 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.`);
7691
- }
7692
-
7693
- return Ctor.CustomElementConstructor;
7694
- }
7695
-
7696
- function buildCustomElementConstructor(Ctor) {
7697
- const def = getComponentInternalDef(Ctor);
7698
- return class extends def.bridge {
7699
- constructor() {
7700
- super();
7701
- createVM(this, def, {
7702
- mode: 'open',
7703
- owner: null,
7704
- tagName: this.tagName,
7705
- renderer
7706
- });
7707
- }
7708
-
7709
- connectedCallback() {
7710
- connectRootElement(this);
7711
- }
7712
-
7713
- disconnectedCallback() {
7714
- disconnectRootElement(this);
7715
- }
7716
-
7717
- };
7718
- }
7719
8076
  /*
7720
8077
  * Copyright (c) 2018, salesforce.com, inc.
7721
8078
  * All rights reserved.
@@ -7725,7 +8082,6 @@ function buildCustomElementConstructor(Ctor) {
7725
8082
  // TODO [#2472]: Remove this workaround when appropriate.
7726
8083
  // eslint-disable-next-line lwc-internal/no-global-node
7727
8084
 
7728
-
7729
8085
  const _Node$1 = Node;
7730
8086
  const ConnectingSlot = new WeakMap();
7731
8087
  const DisconnectingSlot = new WeakMap();
@@ -7836,6 +8192,118 @@ function createElement(sel, options) {
7836
8192
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7837
8193
  */
7838
8194
 
8195
+
8196
+ function hydrateComponent(element, Ctor, props = {}) {
8197
+ if (!isFunction$1(Ctor)) {
8198
+ throw new TypeError(`"hydrateComponent" expects a valid component constructor as the second parameter but instead received ${Ctor}.`);
8199
+ }
8200
+
8201
+ if (!isObject(props) || isNull(props)) {
8202
+ throw new TypeError(`"hydrateComponent" expects an object as the third parameter but instead received ${props}.`);
8203
+ }
8204
+
8205
+ const def = getComponentInternalDef(Ctor);
8206
+
8207
+ try {
8208
+ // Let the renderer know we are hydrating, so it does not replace the existing shadowRoot
8209
+ // and uses the same algo to create the stylesheets as in SSR.
8210
+ setIsHydrating(true);
8211
+ createVM(element, def, {
8212
+ mode: 'open',
8213
+ owner: null,
8214
+ renderer,
8215
+ tagName: element.tagName.toLowerCase()
8216
+ });
8217
+
8218
+ for (const [key, value] of Object.entries(props)) {
8219
+ element[key] = value;
8220
+ }
8221
+
8222
+ hydrateRootElement(element); // set it back since now we finished hydration.
8223
+
8224
+ setIsHydrating(false);
8225
+ } catch (e) {
8226
+ // Fallback: In case there's an error while hydrating, let's log the error, and replace the element with
8227
+ // the client generated DOM.
8228
+
8229
+ /* eslint-disable-next-line no-console */
8230
+ console.error('Recovering from error while hydrating: ', e);
8231
+ setIsHydrating(false);
8232
+ const newElem = createElement(element.tagName, {
8233
+ is: Ctor,
8234
+ mode: 'open'
8235
+ });
8236
+
8237
+ for (const [key, value] of Object.entries(props)) {
8238
+ newElem[key] = value;
8239
+ }
8240
+
8241
+ element.parentNode.replaceChild(newElem, element);
8242
+ }
8243
+ }
8244
+ /*
8245
+ * Copyright (c) 2018, salesforce.com, inc.
8246
+ * All rights reserved.
8247
+ * SPDX-License-Identifier: MIT
8248
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
8249
+ */
8250
+
8251
+ /**
8252
+ * This function builds a Web Component class from a LWC constructor so it can be
8253
+ * registered as a new element via customElements.define() at any given time.
8254
+ *
8255
+ * @deprecated since version 1.3.11
8256
+ *
8257
+ * @example
8258
+ * ```
8259
+ * import { buildCustomElementConstructor } from 'lwc';
8260
+ * import Foo from 'ns/foo';
8261
+ * const WC = buildCustomElementConstructor(Foo);
8262
+ * customElements.define('x-foo', WC);
8263
+ * const elm = document.createElement('x-foo');
8264
+ * ```
8265
+ */
8266
+
8267
+
8268
+ function deprecatedBuildCustomElementConstructor(Ctor) {
8269
+ if (process.env.NODE_ENV !== 'production') {
8270
+ /* eslint-disable-next-line no-console */
8271
+ 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.`);
8272
+ }
8273
+
8274
+ return Ctor.CustomElementConstructor;
8275
+ }
8276
+
8277
+ function buildCustomElementConstructor(Ctor) {
8278
+ const def = getComponentInternalDef(Ctor);
8279
+ return class extends def.bridge {
8280
+ constructor() {
8281
+ super();
8282
+ createVM(this, def, {
8283
+ mode: 'open',
8284
+ owner: null,
8285
+ tagName: this.tagName,
8286
+ renderer
8287
+ });
8288
+ }
8289
+
8290
+ connectedCallback() {
8291
+ connectRootElement(this);
8292
+ }
8293
+
8294
+ disconnectedCallback() {
8295
+ disconnectRootElement(this);
8296
+ }
8297
+
8298
+ };
8299
+ }
8300
+ /*
8301
+ * Copyright (c) 2018, salesforce.com, inc.
8302
+ * All rights reserved.
8303
+ * SPDX-License-Identifier: MIT
8304
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
8305
+ */
8306
+
7839
8307
  /**
7840
8308
  * EXPERIMENTAL: This function provides access to the component constructor, given an HTMLElement.
7841
8309
  * This API is subject to change or being removed.
@@ -7935,6 +8403,6 @@ defineProperty(LightningElement, 'CustomElementConstructor', {
7935
8403
  });
7936
8404
  freeze(LightningElement);
7937
8405
  seal(LightningElement.prototype);
7938
- /* version: 2.5.4 */
8406
+ /* version: 2.5.8 */
7939
8407
 
7940
- 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, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
8408
+ 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 };