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
@@ -301,7 +301,7 @@
301
301
  CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
302
302
  return attributeName;
303
303
  }
304
- /** version: 2.5.4 */
304
+ /** version: 2.5.8 */
305
305
 
306
306
  /*
307
307
  * Copyright (c) 2018, salesforce.com, inc.
@@ -473,7 +473,7 @@
473
473
 
474
474
  function setFeatureFlagForTest(name, value) {
475
475
  }
476
- /** version: 2.5.4 */
476
+ /** version: 2.5.8 */
477
477
 
478
478
  /* proxy-compat-disable */
479
479
 
@@ -515,7 +515,7 @@
515
515
  }
516
516
 
517
517
  return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
518
- }
518
+ } // Borrowed from Vue template compiler.
519
519
  /*
520
520
  * Copyright (c) 2019, salesforce.com, inc.
521
521
  * All rights reserved.
@@ -663,6 +663,20 @@
663
663
  return `<${StringToLowerCase.call(vm.tagName)}>`;
664
664
  } // TODO [#1695]: Unify getComponentStack and getErrorComponentStack
665
665
 
666
+
667
+ function getComponentStack(vm) {
668
+ const stack = [];
669
+ let prefix = '';
670
+
671
+ while (!isNull(vm.owner)) {
672
+ ArrayPush$1.call(stack, prefix + getComponentTag(vm));
673
+ vm = vm.owner;
674
+ prefix += '\t';
675
+ }
676
+
677
+ return ArrayJoin.call(stack, '\n');
678
+ }
679
+
666
680
  function getErrorComponentStack(vm) {
667
681
  const wcStack = [];
668
682
  let currentVm = vm;
@@ -682,6 +696,32 @@
682
696
  */
683
697
 
684
698
 
699
+ function log(method, message, vm) {
700
+ let msg = `[LWC ${method}]: ${message}`;
701
+
702
+ if (!isUndefined$1(vm)) {
703
+ msg = `${msg}\n${getComponentStack(vm)}`;
704
+ }
705
+
706
+ try {
707
+ throw new Error(msg);
708
+ } catch (e) {
709
+ /* eslint-disable-next-line no-console */
710
+ console[method](e);
711
+ }
712
+ }
713
+
714
+ function logWarn(message, vm) {
715
+ log('warn', message, vm);
716
+ }
717
+ /*
718
+ * Copyright (c) 2018, salesforce.com, inc.
719
+ * All rights reserved.
720
+ * SPDX-License-Identifier: MIT
721
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
722
+ */
723
+
724
+
685
725
  function handleEvent(event, vnode) {
686
726
  const {
687
727
  type
@@ -2434,8 +2474,10 @@
2434
2474
  } = vm;
2435
2475
 
2436
2476
  return renderer[rendererMethod](elm);
2437
- }
2477
+ },
2438
2478
 
2479
+ configurable: true,
2480
+ enumerable: true
2439
2481
  };
2440
2482
  }
2441
2483
 
@@ -2451,8 +2493,11 @@
2451
2493
  } = vm;
2452
2494
 
2453
2495
  return renderer[queryMethod](elm, arg);
2454
- }
2496
+ },
2455
2497
 
2498
+ configurable: true,
2499
+ enumerable: true,
2500
+ writable: true
2456
2501
  };
2457
2502
  }
2458
2503
 
@@ -2884,15 +2929,14 @@
2884
2929
  return tpl;
2885
2930
  }
2886
2931
  /**
2887
- * EXPERIMENTAL: This function acts like a hook for Lightning Locker
2888
- * Service and other similar libraries to sanitize vulnerable attributes.
2889
- * This API is subject to change or being removed.
2932
+ * EXPERIMENTAL: This function acts like a hook for Lightning Locker Service and other similar
2933
+ * libraries to sanitize vulnerable attributes.
2890
2934
  */
2891
2935
 
2892
2936
 
2893
2937
  function sanitizeAttribute(tagName, namespaceUri, attrName, attrValue) {
2894
- // locker-service patches this function during runtime to sanitize vulnerable attributes.
2895
- // when ran off-core this function becomes a noop and returns the user authored value.
2938
+ // locker-service patches this function during runtime to sanitize vulnerable attributes. When
2939
+ // ran off-core this function becomes a noop and returns the user authored value.
2896
2940
  return attrValue;
2897
2941
  }
2898
2942
  /*
@@ -3304,7 +3348,7 @@
3304
3348
  renderMode: 1
3305
3349
  /* Shadow */
3306
3350
  ,
3307
- shadowSupportMode: "default"
3351
+ shadowSupportMode: "reset"
3308
3352
  /* Default */
3309
3353
  ,
3310
3354
  wire: EmptyObject,
@@ -3430,6 +3474,17 @@
3430
3474
  modComputedStyle.create(vnode);
3431
3475
  }
3432
3476
 
3477
+ function hydrateElmHook(vnode) {
3478
+ modEvents.create(vnode); // Attrs are already on the element.
3479
+ // modAttrs.create(vnode);
3480
+
3481
+ modProps.create(vnode); // Already set.
3482
+ // modStaticClassName.create(vnode);
3483
+ // modStaticStyle.create(vnode);
3484
+ // modComputedClassName.create(vnode);
3485
+ // modComputedStyle.create(vnode);
3486
+ }
3487
+
3433
3488
  function fallbackElmHook(elm, vnode) {
3434
3489
  const {
3435
3490
  owner
@@ -3579,6 +3634,22 @@
3579
3634
  }
3580
3635
  }
3581
3636
 
3637
+ function hydrateChildrenHook(elmChildren, children, vm) {
3638
+
3639
+ let elmCurrentChildIdx = 0;
3640
+
3641
+ for (let j = 0, n = children.length; j < n; j++) {
3642
+ const ch = children[j];
3643
+
3644
+ if (ch != null) {
3645
+ const childNode = elmChildren[elmCurrentChildIdx];
3646
+
3647
+ ch.hook.hydrate(ch, childNode);
3648
+ elmCurrentChildIdx++;
3649
+ }
3650
+ }
3651
+ }
3652
+
3582
3653
  function updateCustomElmHook(oldVnode, vnode) {
3583
3654
  // Attrs need to be applied to element before props
3584
3655
  // IE11 will wipe out value on radio inputs if value
@@ -3680,7 +3751,14 @@
3680
3751
  update: updateNodeHook,
3681
3752
  insert: insertNodeHook,
3682
3753
  move: insertNodeHook,
3683
- remove: removeNodeHook
3754
+ remove: removeNodeHook,
3755
+ hydrate: (vNode, node) => {
3756
+ var _a;
3757
+
3758
+
3759
+ node.nodeValue = (_a = vNode.text) !== null && _a !== void 0 ? _a : null;
3760
+ vNode.elm = node;
3761
+ }
3684
3762
  };
3685
3763
  const CommentHook = {
3686
3764
  create: vnode => {
@@ -3698,7 +3776,14 @@
3698
3776
  update: updateNodeHook,
3699
3777
  insert: insertNodeHook,
3700
3778
  move: insertNodeHook,
3701
- remove: removeNodeHook
3779
+ remove: removeNodeHook,
3780
+ hydrate: (vNode, node) => {
3781
+ var _a;
3782
+
3783
+
3784
+ node.nodeValue = (_a = vNode.text) !== null && _a !== void 0 ? _a : null;
3785
+ vNode.elm = node;
3786
+ }
3702
3787
  }; // insert is called after update, which is used somewhere else (via a module)
3703
3788
  // to mark the vm as inserted, that means we cannot use update as the main channel
3704
3789
  // to rehydrate when dirty, because sometimes the element is not inserted just yet,
@@ -3738,6 +3823,38 @@
3738
3823
  remove: (vnode, parentNode) => {
3739
3824
  removeNodeHook(vnode, parentNode);
3740
3825
  removeElmHook(vnode);
3826
+ },
3827
+ hydrate: (vnode, node) => {
3828
+ const elm = node;
3829
+ vnode.elm = elm;
3830
+ const {
3831
+ context
3832
+ } = vnode.data;
3833
+ const isDomManual = Boolean(!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
3834
+ /* manual */
3835
+ );
3836
+
3837
+ if (isDomManual) {
3838
+ // it may be that this element has lwc:inner-html, we need to diff and in case are the same,
3839
+ // remove the innerHTML from props so it reuses the existing dom elements.
3840
+ const {
3841
+ props
3842
+ } = vnode.data;
3843
+
3844
+ if (!isUndefined$1(props) && !isUndefined$1(props.innerHTML)) {
3845
+ if (elm.innerHTML === props.innerHTML) {
3846
+ delete props.innerHTML;
3847
+ } else {
3848
+ logWarn(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: innerHTML values do not match for element, will recover from the difference`, vnode.owner);
3849
+ }
3850
+ }
3851
+ }
3852
+
3853
+ hydrateElmHook(vnode);
3854
+
3855
+ if (!isDomManual) {
3856
+ hydrateChildrenHook(vnode.elm.childNodes, vnode.children, vnode.owner);
3857
+ }
3741
3858
  }
3742
3859
  };
3743
3860
  const CustomElementHook = {
@@ -3821,6 +3938,38 @@
3821
3938
  // will take care of disconnecting any child VM attached to its shadow as well.
3822
3939
  removeVM(vm);
3823
3940
  }
3941
+ },
3942
+ hydrate: (vnode, elm) => {
3943
+ // the element is created, but the vm is not
3944
+ const {
3945
+ sel,
3946
+ mode,
3947
+ ctor,
3948
+ owner
3949
+ } = vnode;
3950
+ const def = getComponentInternalDef(ctor);
3951
+ createVM(elm, def, {
3952
+ mode,
3953
+ owner,
3954
+ tagName: sel,
3955
+ renderer: owner.renderer
3956
+ });
3957
+ vnode.elm = elm;
3958
+ const vm = getAssociatedVM(elm);
3959
+ allocateChildrenHook(vnode, vm);
3960
+ hydrateElmHook(vnode); // Insert hook section:
3961
+
3962
+ runConnectedCallback(vm);
3963
+
3964
+ if (vm.renderMode !== 0
3965
+ /* Light */
3966
+ ) {
3967
+ // VM is not rendering in Light DOM, we can proceed and hydrate the slotted content.
3968
+ // Note: for Light DOM, this is handled while hydrating the VM
3969
+ hydrateChildrenHook(vnode.elm.childNodes, vnode.children);
3970
+ }
3971
+
3972
+ hydrateVM(vm);
3824
3973
  }
3825
3974
  };
3826
3975
 
@@ -3956,7 +4105,7 @@
3956
4105
  next = iterator.next();
3957
4106
  last = next.done; // template factory logic based on the previous collected value
3958
4107
 
3959
- const vnode = factory(value, j, j === 0, last);
4108
+ const vnode = factory(value, j, j === 0, last === true);
3960
4109
 
3961
4110
  if (isArray$1(vnode)) {
3962
4111
  ArrayPush$1.apply(list, vnode);
@@ -4172,24 +4321,48 @@
4172
4321
  markAsDynamicChildren(vnodes);
4173
4322
  return vnodes;
4174
4323
  }
4324
+ /**
4325
+ * EXPERIMENTAL: This function acts like a hook for Lightning Locker Service and other similar
4326
+ * libraries to sanitize HTML content. This hook process the content passed via the template to
4327
+ * lwc:inner-html directive.
4328
+ * It is meant to be overridden with setSanitizeHtmlContentHook, it throws an error by default.
4329
+ */
4175
4330
 
4176
- var api = /*#__PURE__*/Object.freeze({
4177
- __proto__: null,
4178
- h: h,
4179
- ti: ti,
4180
- s: s,
4181
- c: c,
4182
- i: i,
4183
- f: f,
4184
- t: t,
4185
- co: co,
4186
- d: d,
4187
- b: b,
4188
- k: k,
4189
- gid: gid,
4190
- fid: fid,
4191
- dc: dc,
4192
- sc: sc
4331
+
4332
+ let sanitizeHtmlContentHook = () => {
4333
+ // locker-service patches this function during runtime to sanitize HTML content.
4334
+ throw new Error('sanitizeHtmlContent hook must be implemented.');
4335
+ };
4336
+ /**
4337
+ * Sets the sanitizeHtmlContentHook.
4338
+ */
4339
+
4340
+
4341
+ function setSanitizeHtmlContentHook(newHookImpl) {
4342
+ sanitizeHtmlContentHook = newHookImpl;
4343
+ } // [s]anitize [h]tml [c]ontent
4344
+
4345
+
4346
+ function shc(content) {
4347
+ return sanitizeHtmlContentHook(content);
4348
+ }
4349
+
4350
+ const api = freeze({
4351
+ s,
4352
+ h,
4353
+ c,
4354
+ i,
4355
+ f,
4356
+ t,
4357
+ d,
4358
+ b,
4359
+ k,
4360
+ co,
4361
+ dc,
4362
+ ti,
4363
+ gid,
4364
+ fid,
4365
+ shc
4193
4366
  });
4194
4367
  /*
4195
4368
  * Copyright (c) 2018, salesforce.com, inc.
@@ -4203,12 +4376,12 @@
4203
4376
  }
4204
4377
 
4205
4378
  function createInlineStyleVNode(content) {
4206
- return h('style', {
4379
+ return api.h('style', {
4207
4380
  key: 'style',
4208
4381
  attrs: {
4209
4382
  type: 'text/css'
4210
4383
  }
4211
- }, [t(content)]);
4384
+ }, [api.t(content)]);
4212
4385
  }
4213
4386
 
4214
4387
  function updateStylesheetToken(vm, template) {
@@ -4355,7 +4528,10 @@
4355
4528
  for (let i = 0; i < stylesheets.length; i++) {
4356
4529
  renderer.insertGlobalStylesheet(stylesheets[i]);
4357
4530
  }
4358
- } else if (renderer.ssr) {
4531
+ } else if (renderer.ssr || renderer.isHydrating) {
4532
+ // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
4533
+ // This works in the client, because the stylesheets are created, and cached in the VM
4534
+ // the first time the VM renders.
4359
4535
  // native shadow or light DOM, SSR
4360
4536
  const combinedStylesheetContent = ArrayJoin.call(stylesheets, '\n');
4361
4537
  return createInlineStyleVNode(combinedStylesheetContent);
@@ -4854,6 +5030,12 @@
4854
5030
  , vm);
4855
5031
  }
4856
5032
 
5033
+ function hydrateRootElement(elm) {
5034
+ const vm = getAssociatedVM(elm);
5035
+ runConnectedCallback(vm);
5036
+ hydrateVM(vm);
5037
+ }
5038
+
4857
5039
  function disconnectRootElement(elm) {
4858
5040
  const vm = getAssociatedVM(elm);
4859
5041
  resetComponentStateWhenRemoved(vm);
@@ -4861,6 +5043,10 @@
4861
5043
 
4862
5044
  function appendVM(vm) {
4863
5045
  rehydrate(vm);
5046
+ }
5047
+
5048
+ function hydrateVM(vm) {
5049
+ hydrate(vm);
4864
5050
  } // just in case the component comes back, with this we guarantee re-rendering it
4865
5051
  // while preventing any attempt to rehydration until after reinsertion.
4866
5052
 
@@ -5055,6 +5241,22 @@
5055
5241
  }
5056
5242
  }
5057
5243
 
5244
+ function hydrate(vm) {
5245
+ if (isTrue(vm.isDirty)) {
5246
+ // manually diffing/patching here.
5247
+ // This routine is:
5248
+ // patchShadowRoot(vm, children);
5249
+ // -> addVnodes.
5250
+ const children = renderComponent(vm);
5251
+ vm.children = children;
5252
+ const vmChildren = vm.renderMode === 0
5253
+ /* Light */
5254
+ ? vm.elm.childNodes : vm.elm.shadowRoot.childNodes;
5255
+ hydrateChildrenHook(vmChildren, children);
5256
+ runRenderedCallback(vm);
5257
+ }
5258
+ }
5259
+
5058
5260
  function patchShadowRoot(vm, newCh) {
5059
5261
  const {
5060
5262
  children: oldCh
@@ -5834,7 +6036,22 @@
5834
6036
 
5835
6037
  return reactiveMembrane.getReadOnlyProxy(obj);
5836
6038
  }
5837
- /* version: 2.5.4 */
6039
+ /*
6040
+ * Copyright (c) 2018, salesforce.com, inc.
6041
+ * All rights reserved.
6042
+ * SPDX-License-Identifier: MIT
6043
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6044
+ */
6045
+
6046
+
6047
+ let hooksAreSet = false;
6048
+
6049
+ function setHooks(hooks) {
6050
+ assert.isFalse(hooksAreSet, 'Hooks are already overridden, only one definition is allowed.');
6051
+ hooksAreSet = true;
6052
+ setSanitizeHtmlContentHook(hooks.sanitizeHtmlContent);
6053
+ }
6054
+ /* version: 2.5.8 */
5838
6055
 
5839
6056
  /*
5840
6057
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5846,8 +6063,11 @@
5846
6063
 
5847
6064
  const globalStylesheets = create(null);
5848
6065
 
5849
- const globalStylesheetsParentElement = document.head || document.body || document;
5850
- const supportsConstructableStyleSheets = isFunction$1(CSSStyleSheet.prototype.replaceSync);
6066
+ const globalStylesheetsParentElement = document.head || document.body || document; // This check for constructable stylesheets is similar to Fast's:
6067
+ // https://github.com/microsoft/fast/blob/d49d1ec/packages/web-components/fast-element/src/dom.ts#L51-L53
6068
+ // See also: https://github.com/whatwg/webidl/issues/1027#issuecomment-934510070
6069
+
6070
+ const supportsConstructableStyleSheets = isFunction$1(CSSStyleSheet.prototype.replaceSync) && isArray$1(document.adoptedStyleSheets);
5851
6071
  const styleElements = create(null);
5852
6072
  const styleSheets = create(null);
5853
6073
  const nodesToStyleSheets = new WeakMap();
@@ -5966,8 +6186,19 @@
5966
6186
  HTMLElementConstructor.prototype = HTMLElement.prototype;
5967
6187
  }
5968
6188
 
6189
+ let isHydrating = false;
6190
+
6191
+ function setIsHydrating(v) {
6192
+ isHydrating = v;
6193
+ }
6194
+
5969
6195
  const renderer = {
5970
6196
  ssr: false,
6197
+
6198
+ get isHydrating() {
6199
+ return isHydrating;
6200
+ },
6201
+
5971
6202
  isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
5972
6203
  isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
5973
6204
 
@@ -5996,6 +6227,10 @@
5996
6227
  },
5997
6228
 
5998
6229
  attachShadow(element, options) {
6230
+ if (isHydrating) {
6231
+ return element.shadowRoot;
6232
+ }
6233
+
5999
6234
  return element.attachShadow(options);
6000
6235
  },
6001
6236
 
@@ -6127,57 +6362,6 @@
6127
6362
  getCustomElement,
6128
6363
  HTMLElement: HTMLElementConstructor
6129
6364
  };
6130
- /*
6131
- * Copyright (c) 2018, salesforce.com, inc.
6132
- * All rights reserved.
6133
- * SPDX-License-Identifier: MIT
6134
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6135
- */
6136
-
6137
- /**
6138
- * This function builds a Web Component class from a LWC constructor so it can be
6139
- * registered as a new element via customElements.define() at any given time.
6140
- *
6141
- * @deprecated since version 1.3.11
6142
- *
6143
- * @example
6144
- * ```
6145
- * import { buildCustomElementConstructor } from 'lwc';
6146
- * import Foo from 'ns/foo';
6147
- * const WC = buildCustomElementConstructor(Foo);
6148
- * customElements.define('x-foo', WC);
6149
- * const elm = document.createElement('x-foo');
6150
- * ```
6151
- */
6152
-
6153
- function deprecatedBuildCustomElementConstructor(Ctor) {
6154
-
6155
- return Ctor.CustomElementConstructor;
6156
- }
6157
-
6158
- function buildCustomElementConstructor(Ctor) {
6159
- const def = getComponentInternalDef(Ctor);
6160
- return class extends def.bridge {
6161
- constructor() {
6162
- super();
6163
- createVM(this, def, {
6164
- mode: 'open',
6165
- owner: null,
6166
- tagName: this.tagName,
6167
- renderer
6168
- });
6169
- }
6170
-
6171
- connectedCallback() {
6172
- connectRootElement(this);
6173
- }
6174
-
6175
- disconnectedCallback() {
6176
- disconnectRootElement(this);
6177
- }
6178
-
6179
- };
6180
- }
6181
6365
  /*
6182
6366
  * Copyright (c) 2018, salesforce.com, inc.
6183
6367
  * All rights reserved.
@@ -6187,7 +6371,6 @@
6187
6371
  // TODO [#2472]: Remove this workaround when appropriate.
6188
6372
  // eslint-disable-next-line lwc-internal/no-global-node
6189
6373
 
6190
-
6191
6374
  const _Node$1 = Node;
6192
6375
  const ConnectingSlot = new WeakMap();
6193
6376
  const DisconnectingSlot = new WeakMap();
@@ -6295,6 +6478,114 @@
6295
6478
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6296
6479
  */
6297
6480
 
6481
+
6482
+ function hydrateComponent(element, Ctor, props = {}) {
6483
+ if (!isFunction$1(Ctor)) {
6484
+ throw new TypeError(`"hydrateComponent" expects a valid component constructor as the second parameter but instead received ${Ctor}.`);
6485
+ }
6486
+
6487
+ if (!isObject(props) || isNull(props)) {
6488
+ throw new TypeError(`"hydrateComponent" expects an object as the third parameter but instead received ${props}.`);
6489
+ }
6490
+
6491
+ const def = getComponentInternalDef(Ctor);
6492
+
6493
+ try {
6494
+ // Let the renderer know we are hydrating, so it does not replace the existing shadowRoot
6495
+ // and uses the same algo to create the stylesheets as in SSR.
6496
+ setIsHydrating(true);
6497
+ createVM(element, def, {
6498
+ mode: 'open',
6499
+ owner: null,
6500
+ renderer,
6501
+ tagName: element.tagName.toLowerCase()
6502
+ });
6503
+
6504
+ for (const [key, value] of Object.entries(props)) {
6505
+ element[key] = value;
6506
+ }
6507
+
6508
+ hydrateRootElement(element); // set it back since now we finished hydration.
6509
+
6510
+ setIsHydrating(false);
6511
+ } catch (e) {
6512
+ // Fallback: In case there's an error while hydrating, let's log the error, and replace the element with
6513
+ // the client generated DOM.
6514
+
6515
+ /* eslint-disable-next-line no-console */
6516
+ console.error('Recovering from error while hydrating: ', e);
6517
+ setIsHydrating(false);
6518
+ const newElem = createElement(element.tagName, {
6519
+ is: Ctor,
6520
+ mode: 'open'
6521
+ });
6522
+
6523
+ for (const [key, value] of Object.entries(props)) {
6524
+ newElem[key] = value;
6525
+ }
6526
+
6527
+ element.parentNode.replaceChild(newElem, element);
6528
+ }
6529
+ }
6530
+ /*
6531
+ * Copyright (c) 2018, salesforce.com, inc.
6532
+ * All rights reserved.
6533
+ * SPDX-License-Identifier: MIT
6534
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6535
+ */
6536
+
6537
+ /**
6538
+ * This function builds a Web Component class from a LWC constructor so it can be
6539
+ * registered as a new element via customElements.define() at any given time.
6540
+ *
6541
+ * @deprecated since version 1.3.11
6542
+ *
6543
+ * @example
6544
+ * ```
6545
+ * import { buildCustomElementConstructor } from 'lwc';
6546
+ * import Foo from 'ns/foo';
6547
+ * const WC = buildCustomElementConstructor(Foo);
6548
+ * customElements.define('x-foo', WC);
6549
+ * const elm = document.createElement('x-foo');
6550
+ * ```
6551
+ */
6552
+
6553
+
6554
+ function deprecatedBuildCustomElementConstructor(Ctor) {
6555
+
6556
+ return Ctor.CustomElementConstructor;
6557
+ }
6558
+
6559
+ function buildCustomElementConstructor(Ctor) {
6560
+ const def = getComponentInternalDef(Ctor);
6561
+ return class extends def.bridge {
6562
+ constructor() {
6563
+ super();
6564
+ createVM(this, def, {
6565
+ mode: 'open',
6566
+ owner: null,
6567
+ tagName: this.tagName,
6568
+ renderer
6569
+ });
6570
+ }
6571
+
6572
+ connectedCallback() {
6573
+ connectRootElement(this);
6574
+ }
6575
+
6576
+ disconnectedCallback() {
6577
+ disconnectRootElement(this);
6578
+ }
6579
+
6580
+ };
6581
+ }
6582
+ /*
6583
+ * Copyright (c) 2018, salesforce.com, inc.
6584
+ * All rights reserved.
6585
+ * SPDX-License-Identifier: MIT
6586
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6587
+ */
6588
+
6298
6589
  /**
6299
6590
  * EXPERIMENTAL: This function provides access to the component constructor, given an HTMLElement.
6300
6591
  * This API is subject to change or being removed.
@@ -6394,7 +6685,7 @@
6394
6685
  });
6395
6686
  freeze(LightningElement);
6396
6687
  seal(LightningElement.prototype);
6397
- /* version: 2.5.4 */
6688
+ /* version: 2.5.8 */
6398
6689
 
6399
6690
  exports.LightningElement = LightningElement;
6400
6691
  exports.__unstable__ProfilerControl = profilerControl;
@@ -6404,6 +6695,7 @@
6404
6695
  exports.createElement = createElement;
6405
6696
  exports.getComponentConstructor = getComponentConstructor;
6406
6697
  exports.getComponentDef = getComponentDef;
6698
+ exports.hydrateComponent = hydrateComponent;
6407
6699
  exports.isComponentConstructor = isComponentConstructor;
6408
6700
  exports.isNodeFromTemplate = isNodeFromTemplate;
6409
6701
  exports.readonly = readonly;
@@ -6414,6 +6706,7 @@
6414
6706
  exports.sanitizeAttribute = sanitizeAttribute;
6415
6707
  exports.setFeatureFlag = setFeatureFlag;
6416
6708
  exports.setFeatureFlagForTest = setFeatureFlagForTest;
6709
+ exports.setHooks = setHooks;
6417
6710
  exports.swapComponent = swapComponent;
6418
6711
  exports.swapStyle = swapStyle;
6419
6712
  exports.swapTemplate = swapTemplate;