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
@@ -305,7 +305,7 @@
305
305
  CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
306
306
  return attributeName;
307
307
  }
308
- /** version: 2.5.4 */
308
+ /** version: 2.5.8 */
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.4 */
488
+ /** version: 2.5.8 */
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
 
@@ -3718,15 +3753,14 @@
3718
3753
  return tpl;
3719
3754
  }
3720
3755
  /**
3721
- * EXPERIMENTAL: This function acts like a hook for Lightning Locker
3722
- * Service and other similar libraries to sanitize vulnerable attributes.
3723
- * This API is subject to change or being removed.
3756
+ * EXPERIMENTAL: This function acts like a hook for Lightning Locker Service and other similar
3757
+ * libraries to sanitize vulnerable attributes.
3724
3758
  */
3725
3759
 
3726
3760
 
3727
3761
  function sanitizeAttribute(tagName, namespaceUri, attrName, attrValue) {
3728
- // locker-service patches this function during runtime to sanitize vulnerable attributes.
3729
- // when ran off-core this function becomes a noop and returns the user authored value.
3762
+ // locker-service patches this function during runtime to sanitize vulnerable attributes. When
3763
+ // ran off-core this function becomes a noop and returns the user authored value.
3730
3764
  return attrValue;
3731
3765
  }
3732
3766
  /*
@@ -4282,7 +4316,7 @@
4282
4316
  if (!isUndefined$1(ctorShadowSupportMode)) {
4283
4317
  assert.invariant(ctorShadowSupportMode === "any"
4284
4318
  /* Any */
4285
- || ctorShadowSupportMode === "default"
4319
+ || ctorShadowSupportMode === "reset"
4286
4320
  /* Default */
4287
4321
  , `Invalid value for static property shadowSupportMode: '${ctorShadowSupportMode}'`);
4288
4322
  }
@@ -4444,7 +4478,7 @@
4444
4478
  renderMode: 1
4445
4479
  /* Shadow */
4446
4480
  ,
4447
- shadowSupportMode: "default"
4481
+ shadowSupportMode: "reset"
4448
4482
  /* Default */
4449
4483
  ,
4450
4484
  wire: EmptyObject,
@@ -4593,6 +4627,17 @@
4593
4627
  modComputedStyle.create(vnode);
4594
4628
  }
4595
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
+
4596
4641
  function fallbackElmHook(elm, vnode) {
4597
4642
  const {
4598
4643
  owner
@@ -4764,6 +4809,179 @@
4764
4809
  }
4765
4810
  }
4766
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 (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) && 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
+
4767
4985
  function updateCustomElmHook(oldVnode, vnode) {
4768
4986
  // Attrs need to be applied to element before props
4769
4987
  // IE11 will wipe out value on radio inputs if value
@@ -4865,7 +5083,26 @@
4865
5083
  update: updateNodeHook,
4866
5084
  insert: insertNodeHook,
4867
5085
  move: insertNodeHook,
4868
- 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
+ }
4869
5106
  };
4870
5107
  const CommentHook = {
4871
5108
  create: vnode => {
@@ -4883,7 +5120,26 @@
4883
5120
  update: updateNodeHook,
4884
5121
  insert: insertNodeHook,
4885
5122
  move: insertNodeHook,
4886
- 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
+ }
4887
5143
  }; // insert is called after update, which is used somewhere else (via a module)
4888
5144
  // to mark the vm as inserted, that means we cannot use update as the main channel
4889
5145
  // to rehydrate when dirty, because sometimes the element is not inserted just yet,
@@ -4923,6 +5179,38 @@
4923
5179
  remove: (vnode, parentNode) => {
4924
5180
  removeNodeHook(vnode, parentNode);
4925
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
+ }
4926
5214
  }
4927
5215
  };
4928
5216
  const CustomElementHook = {
@@ -5014,6 +5302,44 @@
5014
5302
  // will take care of disconnecting any child VM attached to its shadow as well.
5015
5303
  removeVM(vm);
5016
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);
5017
5343
  }
5018
5344
  };
5019
5345
 
@@ -5222,7 +5548,7 @@
5222
5548
  next = iterator.next();
5223
5549
  last = next.done; // template factory logic based on the previous collected value
5224
5550
 
5225
- const vnode = factory(value, j, j === 0, last);
5551
+ const vnode = factory(value, j, j === 0, last === true);
5226
5552
 
5227
5553
  if (isArray$1(vnode)) {
5228
5554
  ArrayPush$1.apply(list, vnode);
@@ -5489,24 +5815,48 @@
5489
5815
  markAsDynamicChildren(vnodes);
5490
5816
  return vnodes;
5491
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
+ */
5492
5824
 
5493
- var api = /*#__PURE__*/Object.freeze({
5494
- __proto__: null,
5495
- h: h,
5496
- ti: ti,
5497
- s: s,
5498
- c: c,
5499
- i: i,
5500
- f: f,
5501
- t: t,
5502
- co: co,
5503
- d: d,
5504
- b: b,
5505
- k: k,
5506
- gid: gid,
5507
- fid: fid,
5508
- dc: dc,
5509
- sc: sc
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;
5837
+ } // [s]anitize [h]tml [c]ontent
5838
+
5839
+
5840
+ function shc(content) {
5841
+ return sanitizeHtmlContentHook(content);
5842
+ }
5843
+
5844
+ const api = freeze({
5845
+ s,
5846
+ h,
5847
+ c,
5848
+ i,
5849
+ f,
5850
+ t,
5851
+ d,
5852
+ b,
5853
+ k,
5854
+ co,
5855
+ dc,
5856
+ ti,
5857
+ gid,
5858
+ fid,
5859
+ shc
5510
5860
  });
5511
5861
  /*
5512
5862
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5520,12 +5870,12 @@
5520
5870
  }
5521
5871
 
5522
5872
  function createInlineStyleVNode(content) {
5523
- return h('style', {
5873
+ return api.h('style', {
5524
5874
  key: 'style',
5525
5875
  attrs: {
5526
5876
  type: 'text/css'
5527
5877
  }
5528
- }, [t(content)]);
5878
+ }, [api.t(content)]);
5529
5879
  }
5530
5880
 
5531
5881
  function updateStylesheetToken(vm, template) {
@@ -5678,7 +6028,10 @@
5678
6028
  for (let i = 0; i < stylesheets.length; i++) {
5679
6029
  renderer.insertGlobalStylesheet(stylesheets[i]);
5680
6030
  }
5681
- } 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.
5682
6035
  // native shadow or light DOM, SSR
5683
6036
  const combinedStylesheetContent = ArrayJoin.call(stylesheets, '\n');
5684
6037
  return createInlineStyleVNode(combinedStylesheetContent);
@@ -6303,6 +6656,12 @@
6303
6656
  , vm);
6304
6657
  }
6305
6658
 
6659
+ function hydrateRootElement(elm) {
6660
+ const vm = getAssociatedVM(elm);
6661
+ runConnectedCallback(vm);
6662
+ hydrateVM(vm);
6663
+ }
6664
+
6306
6665
  function disconnectRootElement(elm) {
6307
6666
  const vm = getAssociatedVM(elm);
6308
6667
  resetComponentStateWhenRemoved(vm);
@@ -6310,6 +6669,10 @@
6310
6669
 
6311
6670
  function appendVM(vm) {
6312
6671
  rehydrate(vm);
6672
+ }
6673
+
6674
+ function hydrateVM(vm) {
6675
+ hydrate(vm);
6313
6676
  } // just in case the component comes back, with this we guarantee re-rendering it
6314
6677
  // while preventing any attempt to rehydration until after reinsertion.
6315
6678
 
@@ -6543,6 +6906,22 @@
6543
6906
  }
6544
6907
  }
6545
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
+
6546
6925
  function patchShadowRoot(vm, newCh) {
6547
6926
  const {
6548
6927
  children: oldCh
@@ -7359,7 +7738,22 @@
7359
7738
 
7360
7739
  return reactiveMembrane.getReadOnlyProxy(obj);
7361
7740
  }
7362
- /* version: 2.5.4 */
7741
+ /*
7742
+ * Copyright (c) 2018, salesforce.com, inc.
7743
+ * All rights reserved.
7744
+ * SPDX-License-Identifier: MIT
7745
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7746
+ */
7747
+
7748
+
7749
+ let hooksAreSet = false;
7750
+
7751
+ function setHooks(hooks) {
7752
+ assert.isFalse(hooksAreSet, 'Hooks are already overridden, only one definition is allowed.');
7753
+ hooksAreSet = true;
7754
+ setSanitizeHtmlContentHook(hooks.sanitizeHtmlContent);
7755
+ }
7756
+ /* version: 2.5.8 */
7363
7757
 
7364
7758
  /*
7365
7759
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7380,8 +7774,11 @@
7380
7774
  };
7381
7775
  }
7382
7776
 
7383
- const globalStylesheetsParentElement = document.head || document.body || document;
7384
- const supportsConstructableStyleSheets = isFunction$1(CSSStyleSheet.prototype.replaceSync);
7777
+ const globalStylesheetsParentElement = document.head || document.body || document; // This check for constructable stylesheets is similar to Fast's:
7778
+ // https://github.com/microsoft/fast/blob/d49d1ec/packages/web-components/fast-element/src/dom.ts#L51-L53
7779
+ // See also: https://github.com/whatwg/webidl/issues/1027#issuecomment-934510070
7780
+
7781
+ const supportsConstructableStyleSheets = isFunction$1(CSSStyleSheet.prototype.replaceSync) && isArray$1(document.adoptedStyleSheets);
7385
7782
  const styleElements = create(null);
7386
7783
  const styleSheets = create(null);
7387
7784
  const nodesToStyleSheets = new WeakMap();
@@ -7500,8 +7897,19 @@
7500
7897
  HTMLElementConstructor.prototype = HTMLElement.prototype;
7501
7898
  }
7502
7899
 
7900
+ let isHydrating = false;
7901
+
7902
+ function setIsHydrating(v) {
7903
+ isHydrating = v;
7904
+ }
7905
+
7503
7906
  const renderer = {
7504
7907
  ssr: false,
7908
+
7909
+ get isHydrating() {
7910
+ return isHydrating;
7911
+ },
7912
+
7505
7913
  isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
7506
7914
  isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
7507
7915
 
@@ -7530,6 +7938,10 @@
7530
7938
  },
7531
7939
 
7532
7940
  attachShadow(element, options) {
7941
+ if (isHydrating) {
7942
+ return element.shadowRoot;
7943
+ }
7944
+
7533
7945
  return element.attachShadow(options);
7534
7946
  },
7535
7947
 
@@ -7667,61 +8079,6 @@
7667
8079
  getCustomElement,
7668
8080
  HTMLElement: HTMLElementConstructor
7669
8081
  };
7670
- /*
7671
- * Copyright (c) 2018, salesforce.com, inc.
7672
- * All rights reserved.
7673
- * SPDX-License-Identifier: MIT
7674
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7675
- */
7676
-
7677
- /**
7678
- * This function builds a Web Component class from a LWC constructor so it can be
7679
- * registered as a new element via customElements.define() at any given time.
7680
- *
7681
- * @deprecated since version 1.3.11
7682
- *
7683
- * @example
7684
- * ```
7685
- * import { buildCustomElementConstructor } from 'lwc';
7686
- * import Foo from 'ns/foo';
7687
- * const WC = buildCustomElementConstructor(Foo);
7688
- * customElements.define('x-foo', WC);
7689
- * const elm = document.createElement('x-foo');
7690
- * ```
7691
- */
7692
-
7693
- function deprecatedBuildCustomElementConstructor(Ctor) {
7694
- if (process.env.NODE_ENV !== 'production') {
7695
- /* eslint-disable-next-line no-console */
7696
- 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.`);
7697
- }
7698
-
7699
- return Ctor.CustomElementConstructor;
7700
- }
7701
-
7702
- function buildCustomElementConstructor(Ctor) {
7703
- const def = getComponentInternalDef(Ctor);
7704
- return class extends def.bridge {
7705
- constructor() {
7706
- super();
7707
- createVM(this, def, {
7708
- mode: 'open',
7709
- owner: null,
7710
- tagName: this.tagName,
7711
- renderer
7712
- });
7713
- }
7714
-
7715
- connectedCallback() {
7716
- connectRootElement(this);
7717
- }
7718
-
7719
- disconnectedCallback() {
7720
- disconnectRootElement(this);
7721
- }
7722
-
7723
- };
7724
- }
7725
8082
  /*
7726
8083
  * Copyright (c) 2018, salesforce.com, inc.
7727
8084
  * All rights reserved.
@@ -7731,7 +8088,6 @@
7731
8088
  // TODO [#2472]: Remove this workaround when appropriate.
7732
8089
  // eslint-disable-next-line lwc-internal/no-global-node
7733
8090
 
7734
-
7735
8091
  const _Node$1 = Node;
7736
8092
  const ConnectingSlot = new WeakMap();
7737
8093
  const DisconnectingSlot = new WeakMap();
@@ -7842,6 +8198,118 @@
7842
8198
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7843
8199
  */
7844
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
+
7845
8313
  /**
7846
8314
  * EXPERIMENTAL: This function provides access to the component constructor, given an HTMLElement.
7847
8315
  * This API is subject to change or being removed.
@@ -7941,7 +8409,7 @@
7941
8409
  });
7942
8410
  freeze(LightningElement);
7943
8411
  seal(LightningElement.prototype);
7944
- /* version: 2.5.4 */
8412
+ /* version: 2.5.8 */
7945
8413
 
7946
8414
  exports.LightningElement = LightningElement;
7947
8415
  exports.__unstable__ProfilerControl = profilerControl;
@@ -7951,6 +8419,7 @@
7951
8419
  exports.createElement = createElement;
7952
8420
  exports.getComponentConstructor = getComponentConstructor;
7953
8421
  exports.getComponentDef = getComponentDef;
8422
+ exports.hydrateComponent = hydrateComponent;
7954
8423
  exports.isComponentConstructor = isComponentConstructor;
7955
8424
  exports.isNodeFromTemplate = isNodeFromTemplate;
7956
8425
  exports.readonly = readonly;
@@ -7961,6 +8430,7 @@
7961
8430
  exports.sanitizeAttribute = sanitizeAttribute;
7962
8431
  exports.setFeatureFlag = setFeatureFlag;
7963
8432
  exports.setFeatureFlagForTest = setFeatureFlagForTest;
8433
+ exports.setHooks = setHooks;
7964
8434
  exports.swapComponent = swapComponent;
7965
8435
  exports.swapStyle = swapStyle;
7966
8436
  exports.swapTemplate = swapTemplate;