@content-blocks/js 0.4.0 → 0.4.2

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 (107) hide show
  1. package/dist/cjs/content-accordion.cjs.entry.js +1 -1
  2. package/dist/cjs/content-blocks.cjs.js +2 -2
  3. package/dist/cjs/content-blocks.cjs.js.map +1 -1
  4. package/dist/cjs/content-button_10.cjs.entry.js +1 -1
  5. package/dist/cjs/content-button_10.cjs.entry.js.map +1 -1
  6. package/dist/cjs/{content-carousel-c8e0a9a9.js → content-carousel-d866cb77.js} +27 -22
  7. package/dist/cjs/content-carousel-d866cb77.js.map +1 -0
  8. package/dist/cjs/content-carousel.cjs.entry.js +2 -2
  9. package/dist/cjs/content-navigation-block.cjs.entry.js +4 -6
  10. package/dist/cjs/content-navigation-block.cjs.entry.js.map +1 -1
  11. package/dist/cjs/content-split-block.cjs.entry.js +1 -1
  12. package/dist/cjs/content-split-block.cjs.entry.js.map +1 -1
  13. package/dist/cjs/content-tabs.cjs.entry.js +1 -1
  14. package/dist/cjs/{index-e93f381a.js → index-239b1c46.js} +232 -102
  15. package/dist/cjs/index-239b1c46.js.map +1 -0
  16. package/dist/cjs/loader.cjs.js +1 -1
  17. package/dist/cjs/{swiper-d0296c76.js → swiper-2fe1b80b.js} +421 -149
  18. package/dist/cjs/swiper-2fe1b80b.js.map +1 -0
  19. package/dist/collection/blocks/content-hero-block/content-hero-block.js.map +1 -1
  20. package/dist/collection/blocks/content-split-block/content-split-block.js.map +1 -1
  21. package/dist/collection/blocks/content-text-block/content-text-block.js.map +1 -1
  22. package/dist/collection/collection-manifest.json +2 -2
  23. package/dist/collection/components/content-carousel/content-carousel.css +3 -3
  24. package/dist/collection/components/content-navigation-block/content-navigation-block.js +3 -5
  25. package/dist/collection/components/content-navigation-block/content-navigation-block.js.map +1 -1
  26. package/dist/collection/elements/content-button/content-button.js.map +1 -1
  27. package/dist/collection/elements/content-line/content-line.js.map +1 -1
  28. package/dist/collection/elements/content-video/content-video.js.map +1 -1
  29. package/dist/collection/formatters/content-grid-formatter/content-grid-formatter.js.map +1 -1
  30. package/dist/components/content-button.js.map +1 -1
  31. package/dist/components/content-carousel.js +24 -20
  32. package/dist/components/content-carousel.js.map +1 -1
  33. package/dist/components/content-grid-formatter2.js.map +1 -1
  34. package/dist/components/content-hero-block.js.map +1 -1
  35. package/dist/components/content-line.js.map +1 -1
  36. package/dist/components/content-navigation-block.js +3 -5
  37. package/dist/components/content-navigation-block.js.map +1 -1
  38. package/dist/components/content-split-block.js.map +1 -1
  39. package/dist/components/content-text-block.js.map +1 -1
  40. package/dist/components/content-video.js.map +1 -1
  41. package/dist/components/swiper.js +419 -147
  42. package/dist/components/swiper.js.map +1 -1
  43. package/dist/content-blocks/content-blocks.esm.js +1 -1
  44. package/dist/content-blocks/content-blocks.esm.js.map +1 -1
  45. package/dist/content-blocks/p-08143d3f.js +2 -0
  46. package/dist/content-blocks/p-08143d3f.js.map +1 -0
  47. package/dist/content-blocks/{p-057c0e4d.entry.js → p-14dd6549.entry.js} +2 -2
  48. package/dist/content-blocks/p-14dd6549.entry.js.map +1 -0
  49. package/dist/content-blocks/{p-b1300b9a.entry.js → p-1947500c.entry.js} +2 -2
  50. package/dist/content-blocks/p-1947500c.entry.js.map +1 -0
  51. package/dist/content-blocks/p-26ff44fc.js +6 -6
  52. package/dist/content-blocks/{p-01952c81.entry.js → p-3732482d.entry.js} +2 -2
  53. package/dist/content-blocks/p-3732482d.entry.js.map +1 -0
  54. package/dist/content-blocks/p-3b4be54b.js +2 -0
  55. package/dist/content-blocks/p-3b4be54b.js.map +1 -0
  56. package/dist/content-blocks/{p-914e3550.entry.js → p-8d44f285.entry.js} +2 -2
  57. package/dist/content-blocks/p-a802c984.entry.js +2 -0
  58. package/dist/content-blocks/{p-2ec7fda2.entry.js → p-b27f84ad.entry.js} +2 -2
  59. package/dist/content-blocks/p-dc53dda7.js +3 -0
  60. package/dist/content-blocks/p-dc53dda7.js.map +1 -0
  61. package/dist/esm/content-accordion.entry.js +1 -1
  62. package/dist/esm/content-blocks.js +3 -3
  63. package/dist/esm/content-blocks.js.map +1 -1
  64. package/dist/esm/content-button_10.entry.js +1 -1
  65. package/dist/esm/content-button_10.entry.js.map +1 -1
  66. package/dist/esm/{content-carousel-f971cfcd.js → content-carousel-af580def.js} +27 -23
  67. package/dist/esm/content-carousel-af580def.js.map +1 -0
  68. package/dist/esm/content-carousel.entry.js +2 -2
  69. package/dist/esm/content-navigation-block.entry.js +4 -6
  70. package/dist/esm/content-navigation-block.entry.js.map +1 -1
  71. package/dist/esm/content-split-block.entry.js +1 -1
  72. package/dist/esm/content-split-block.entry.js.map +1 -1
  73. package/dist/esm/content-tabs.entry.js +1 -1
  74. package/dist/esm/{index-9501de67.js → index-6e48707b.js} +232 -102
  75. package/dist/esm/index-6e48707b.js.map +1 -0
  76. package/dist/esm/loader.js +2 -2
  77. package/dist/esm/{swiper-7d87458d.js → swiper-3d1a80cc.js} +421 -149
  78. package/dist/esm/swiper-3d1a80cc.js.map +1 -0
  79. package/dist/types/blocks/content-hero-block/content-hero-block.d.ts +0 -2
  80. package/dist/types/blocks/content-text-block/content-text-block.d.ts +0 -2
  81. package/dist/types/components/content-navigation-block/content-navigation-block.d.ts +0 -2
  82. package/dist/types/components.d.ts +11 -0
  83. package/dist/types/elements/content-button/content-button.d.ts +0 -2
  84. package/dist/types/elements/content-line/content-line.d.ts +0 -2
  85. package/dist/types/elements/content-video/content-video.d.ts +0 -2
  86. package/dist/types/formatters/content-grid-formatter/content-grid-formatter.d.ts +0 -2
  87. package/dist/types/stencil-public-runtime.d.ts +21 -0
  88. package/package.json +13 -13
  89. package/dist/cjs/content-carousel-c8e0a9a9.js.map +0 -1
  90. package/dist/cjs/index-e93f381a.js.map +0 -1
  91. package/dist/cjs/swiper-d0296c76.js.map +0 -1
  92. package/dist/content-blocks/p-01952c81.entry.js.map +0 -1
  93. package/dist/content-blocks/p-057c0e4d.entry.js.map +0 -1
  94. package/dist/content-blocks/p-3f3a30b1.entry.js +0 -2
  95. package/dist/content-blocks/p-8a8f13fb.js +0 -2
  96. package/dist/content-blocks/p-8a8f13fb.js.map +0 -1
  97. package/dist/content-blocks/p-b1300b9a.entry.js.map +0 -1
  98. package/dist/content-blocks/p-cd3c0fce.js +0 -3
  99. package/dist/content-blocks/p-cd3c0fce.js.map +0 -1
  100. package/dist/content-blocks/p-d8dc8d1e.js +0 -2
  101. package/dist/content-blocks/p-d8dc8d1e.js.map +0 -1
  102. package/dist/esm/content-carousel-f971cfcd.js.map +0 -1
  103. package/dist/esm/index-9501de67.js.map +0 -1
  104. package/dist/esm/swiper-7d87458d.js.map +0 -1
  105. /package/dist/content-blocks/{p-914e3550.entry.js.map → p-8d44f285.entry.js.map} +0 -0
  106. /package/dist/content-blocks/{p-3f3a30b1.entry.js.map → p-a802c984.entry.js.map} +0 -0
  107. /package/dist/content-blocks/{p-2ec7fda2.entry.js.map → p-b27f84ad.entry.js.map} +0 -0
@@ -21,6 +21,7 @@ function _interopNamespace(e) {
21
21
  }
22
22
 
23
23
  const NAMESPACE = 'content-blocks';
24
+ const BUILD = /* content-blocks */ { allRenderFn: true, appendChildSlotFix: false, asyncLoading: true, asyncQueue: false, attachStyles: true, cloneNodeFix: false, cmpDidLoad: true, cmpDidRender: true, cmpDidUnload: false, cmpDidUpdate: false, cmpShouldUpdate: false, cmpWillLoad: true, cmpWillRender: true, cmpWillUpdate: false, connectedCallback: false, constructableCSS: true, cssAnnotations: true, devTools: false, disconnectedCallback: false, element: false, event: true, experimentalSlotFixes: false, formAssociated: false, hasRenderFn: true, hostListener: true, hostListenerTarget: true, hostListenerTargetBody: false, hostListenerTargetDocument: false, hostListenerTargetParent: false, hostListenerTargetWindow: true, hotModuleReplacement: false, hydrateClientSide: false, hydrateServerSide: false, hydratedAttribute: false, hydratedClass: true, initializeNextTick: false, invisiblePrehydration: true, isDebug: false, isDev: false, isTesting: false, lazyLoad: true, lifecycle: true, lifecycleDOMEvents: false, member: true, method: true, mode: false, observeAttribute: true, profile: false, prop: true, propBoolean: true, propMutable: true, propNumber: true, propString: true, reflect: true, scoped: false, scopedSlotTextContentFix: false, scriptDataOpts: false, shadowDelegatesFocus: false, shadowDom: false, slot: true, slotChildNodesFix: false, slotRelocation: true, state: true, style: true, svg: false, taskQueue: true, transformTagName: false, updatable: true, vdomAttribute: true, vdomClass: true, vdomFunctional: true, vdomKey: false, vdomListener: true, vdomPropOrAttr: true, vdomRef: true, vdomRender: true, vdomStyle: true, vdomText: true, vdomXlink: false, watchCallback: true };
24
25
 
25
26
  /**
26
27
  * Virtual DOM patching algorithm based on Snabbdom by
@@ -471,11 +472,19 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
471
472
  // except for the first character, we keep the event name case
472
473
  memberName = ln[2] + memberName.slice(3);
473
474
  }
474
- if (oldValue) {
475
- plt.rel(elm, memberName, oldValue, false);
476
- }
477
- if (newValue) {
478
- plt.ael(elm, memberName, newValue, false);
475
+ if (oldValue || newValue) {
476
+ // Need to account for "capture" events.
477
+ // If the event name ends with "Capture", we'll update the name to remove
478
+ // the "Capture" suffix and make sure the event listener is setup to handle the capture event.
479
+ const capture = memberName.endsWith(CAPTURE_EVENT_SUFFIX);
480
+ // Make sure we only replace the last instance of "Capture"
481
+ memberName = memberName.replace(CAPTURE_EVENT_REGEX, '');
482
+ if (oldValue) {
483
+ plt.rel(elm, memberName, oldValue, capture);
484
+ }
485
+ if (newValue) {
486
+ plt.ael(elm, memberName, newValue, capture);
487
+ }
479
488
  }
480
489
  }
481
490
  else {
@@ -517,6 +526,8 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
517
526
  };
518
527
  const parseClassListRegex = /\s/;
519
528
  const parseClassList = (value) => (!value ? [] : value.split(parseClassListRegex));
529
+ const CAPTURE_EVENT_SUFFIX = 'Capture';
530
+ const CAPTURE_EVENT_REGEX = new RegExp(CAPTURE_EVENT_SUFFIX + '$');
520
531
  const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
521
532
  // if the element passed in is a shadow root, which is a document fragment
522
533
  // then we want to be adding attrs/props to the shadow root's "host" element
@@ -550,6 +561,7 @@ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
550
561
  * @returns the newly created node
551
562
  */
552
563
  const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
564
+ var _a;
553
565
  // tslint:disable-next-line: prefer-const
554
566
  const newVNode = newParentVNode.$children$[childIndex];
555
567
  let i = 0;
@@ -602,6 +614,8 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
602
614
  if (newVNode.$flags$ & (2 /* VNODE_FLAGS.isSlotFallback */ | 1 /* VNODE_FLAGS.isSlotReference */)) {
603
615
  // remember the content reference comment
604
616
  elm['s-sr'] = true;
617
+ // Persist the name of the slot that this slot was going to be projected into.
618
+ elm['s-fs'] = (_a = newVNode.$attrs$) === null || _a === void 0 ? void 0 : _a.slot;
605
619
  // remember the content reference comment
606
620
  elm['s-cr'] = contentRef;
607
621
  // remember the slot name, or empty string for default slot
@@ -618,6 +632,7 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
618
632
  return elm;
619
633
  };
620
634
  const putBackInOriginalLocation = (parentElm, recursive) => {
635
+ var _a;
621
636
  plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
622
637
  const oldSlotChildNodes = parentElm.childNodes;
623
638
  for (let i = oldSlotChildNodes.length - 1; i >= 0; i--) {
@@ -630,9 +645,17 @@ const putBackInOriginalLocation = (parentElm, recursive) => {
630
645
  parentReferenceNode(childNode).insertBefore(childNode, referenceNode(childNode));
631
646
  // remove the old original location comment entirely
632
647
  // later on the patch function will know what to do
633
- // and move this to the correct spot in need be
648
+ // and move this to the correct spot if need be
634
649
  childNode['s-ol'].remove();
635
650
  childNode['s-ol'] = undefined;
651
+ // Reset so we can correctly move the node around again.
652
+ childNode['s-sh'] = undefined;
653
+ // When putting an element node back in its original location,
654
+ // we need to reset the `slot` attribute back to the value it originally had
655
+ // so we can correctly relocate it again in the future
656
+ if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
657
+ childNode.setAttribute('slot', (_a = childNode['s-sn']) !== null && _a !== void 0 ? _a : '');
658
+ }
636
659
  checkSlotRelocate = true;
637
660
  }
638
661
  if (recursive) {
@@ -1005,42 +1028,53 @@ const patch = (oldVNode, newVNode) => {
1005
1028
  elm.data = text;
1006
1029
  }
1007
1030
  };
1031
+ /**
1032
+ * Adjust the `.hidden` property as-needed on any nodes in a DOM subtree which
1033
+ * are slot fallbacks nodes.
1034
+ *
1035
+ * A slot fallback node should be visible by default. Then, it should be
1036
+ * conditionally hidden if:
1037
+ *
1038
+ * - it has a sibling with a `slot` property set to its slot name or if
1039
+ * - it is a default fallback slot node, in which case we hide if it has any
1040
+ * content
1041
+ *
1042
+ * @param elm the element of interest
1043
+ */
1008
1044
  const updateFallbackSlotVisibility = (elm) => {
1009
- // tslint:disable-next-line: prefer-const
1010
1045
  const childNodes = elm.childNodes;
1011
- let childNode;
1012
- let i;
1013
- let ilen;
1014
- let j;
1015
- let slotNameAttr;
1016
- let nodeType;
1017
- for (i = 0, ilen = childNodes.length; i < ilen; i++) {
1018
- childNode = childNodes[i];
1046
+ for (const childNode of childNodes) {
1019
1047
  if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1020
1048
  if (childNode['s-sr']) {
1021
1049
  // this is a slot fallback node
1022
1050
  // get the slot name for this slot reference node
1023
- slotNameAttr = childNode['s-sn'];
1051
+ const slotName = childNode['s-sn'];
1024
1052
  // by default always show a fallback slot node
1025
1053
  // then hide it if there are other slots in the light dom
1026
1054
  childNode.hidden = false;
1027
- for (j = 0; j < ilen; j++) {
1028
- nodeType = childNodes[j].nodeType;
1029
- if (childNodes[j]['s-hn'] !== childNode['s-hn'] || slotNameAttr !== '') {
1030
- // this sibling node is from a different component OR is a named fallback slot node
1031
- if (nodeType === 1 /* NODE_TYPE.ElementNode */ && slotNameAttr === childNodes[j].getAttribute('slot')) {
1032
- childNode.hidden = true;
1033
- break;
1055
+ // we need to check all of its sibling nodes in order to see if
1056
+ // `childNode` should be hidden
1057
+ for (const siblingNode of childNodes) {
1058
+ // Don't check the node against itself
1059
+ if (siblingNode !== childNode) {
1060
+ if (siblingNode['s-hn'] !== childNode['s-hn'] || slotName !== '') {
1061
+ // this sibling node is from a different component OR is a named
1062
+ // fallback slot node
1063
+ if (siblingNode.nodeType === 1 /* NODE_TYPE.ElementNode */ &&
1064
+ (slotName === siblingNode.getAttribute('slot') || slotName === siblingNode['s-sn'])) {
1065
+ childNode.hidden = true;
1066
+ break;
1067
+ }
1034
1068
  }
1035
- }
1036
- else {
1037
- // this is a default fallback slot node
1038
- // any element or text node (with content)
1039
- // should hide the default fallback slot node
1040
- if (nodeType === 1 /* NODE_TYPE.ElementNode */ ||
1041
- (nodeType === 3 /* NODE_TYPE.TextNode */ && childNodes[j].textContent.trim() !== '')) {
1042
- childNode.hidden = true;
1043
- break;
1069
+ else {
1070
+ // this is a default fallback slot node
1071
+ // any element or text node (with content)
1072
+ // should hide the default fallback slot node
1073
+ if (siblingNode.nodeType === 1 /* NODE_TYPE.ElementNode */ ||
1074
+ (siblingNode.nodeType === 3 /* NODE_TYPE.TextNode */ && siblingNode.textContent.trim() !== '')) {
1075
+ childNode.hidden = true;
1076
+ break;
1077
+ }
1044
1078
  }
1045
1079
  }
1046
1080
  }
@@ -1050,45 +1084,67 @@ const updateFallbackSlotVisibility = (elm) => {
1050
1084
  }
1051
1085
  }
1052
1086
  };
1087
+ /**
1088
+ * Component-global information about nodes which are either currently being
1089
+ * relocated or will be shortly.
1090
+ */
1053
1091
  const relocateNodes = [];
1054
- const relocateSlotContent = (elm) => {
1092
+ /**
1093
+ * Mark the contents of a slot for relocation via adding references to them to
1094
+ * the {@link relocateNodes} data structure. The actual work of relocating them
1095
+ * will then be handled in {@link renderVdom}.
1096
+ *
1097
+ * @param elm a render node whose child nodes need to be relocated
1098
+ */
1099
+ const markSlotContentForRelocation = (elm) => {
1055
1100
  // tslint:disable-next-line: prefer-const
1056
- let childNode;
1057
1101
  let node;
1058
1102
  let hostContentNodes;
1059
- let slotNameAttr;
1060
- let relocateNodeData;
1061
1103
  let j;
1062
- let i = 0;
1063
- const childNodes = elm.childNodes;
1064
- const ilen = childNodes.length;
1065
- for (; i < ilen; i++) {
1066
- childNode = childNodes[i];
1104
+ for (const childNode of elm.childNodes) {
1105
+ // we need to find child nodes which are slot references so we can then try
1106
+ // to match them up with nodes that need to be relocated
1067
1107
  if (childNode['s-sr'] && (node = childNode['s-cr']) && node.parentNode) {
1068
- // first got the content reference comment node
1069
- // then we got it's parent, which is where all the host content is in now
1108
+ // first get the content reference comment node ('s-cr'), then we get
1109
+ // its parent, which is where all the host content is now
1070
1110
  hostContentNodes = node.parentNode.childNodes;
1071
- slotNameAttr = childNode['s-sn'];
1111
+ const slotName = childNode['s-sn'];
1112
+ // iterate through all the nodes under the location where the host was
1113
+ // originally rendered
1072
1114
  for (j = hostContentNodes.length - 1; j >= 0; j--) {
1073
1115
  node = hostContentNodes[j];
1074
- if (!node['s-cn'] && !node['s-nr'] && node['s-hn'] !== childNode['s-hn']) {
1075
- // let's do some relocating to its new home
1076
- // but never relocate a content reference node
1077
- // that is suppose to always represent the original content location
1078
- if (isNodeLocatedInSlot(node, slotNameAttr)) {
1116
+ // check that the node is not a content reference node or a node
1117
+ // reference and then check that the host name does not match that of
1118
+ // childNode.
1119
+ // In addition, check that the slot either has not already been relocated, or
1120
+ // that its current location's host is not childNode's host. This is essentially
1121
+ // a check so that we don't try to relocate (and then hide) a node that is already
1122
+ // where it should be.
1123
+ if (!node['s-cn'] &&
1124
+ !node['s-nr'] &&
1125
+ node['s-hn'] !== childNode['s-hn'] &&
1126
+ (!BUILD.experimentalSlotFixes )) {
1127
+ // if `node` is located in the slot that `childNode` refers to (via the
1128
+ // `'s-sn'` property) then we need to relocate it from it's current spot
1129
+ // (under the host element parent) to the right slot location
1130
+ if (isNodeLocatedInSlot(node, slotName)) {
1079
1131
  // it's possible we've already decided to relocate this node
1080
- relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
1132
+ let relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
1081
1133
  // made some changes to slots
1082
1134
  // let's make sure we also double check
1083
1135
  // fallbacks are correctly hidden or shown
1084
1136
  checkSlotFallbackVisibility = true;
1085
- node['s-sn'] = node['s-sn'] || slotNameAttr;
1137
+ // ensure that the slot-name attr is correct
1138
+ node['s-sn'] = node['s-sn'] || slotName;
1086
1139
  if (relocateNodeData) {
1087
- // previously we never found a slot home for this node
1088
- // but turns out we did, so let's remember it now
1140
+ relocateNodeData.$nodeToRelocate$['s-sh'] = childNode['s-hn'];
1141
+ // we marked this node for relocation previously but didn't find
1142
+ // out the slot reference node to which it needs to be relocated
1143
+ // so write it down now!
1089
1144
  relocateNodeData.$slotRefNode$ = childNode;
1090
1145
  }
1091
1146
  else {
1147
+ node['s-sh'] = childNode['s-hn'];
1092
1148
  // add to our list of nodes to relocate
1093
1149
  relocateNodes.push({
1094
1150
  $slotRefNode$: childNode,
@@ -1107,8 +1163,10 @@ const relocateSlotContent = (elm) => {
1107
1163
  }
1108
1164
  }
1109
1165
  else if (!relocateNodes.some((r) => r.$nodeToRelocate$ === node)) {
1110
- // so far this element does not have a slot home, not setting slotRefNode on purpose
1111
- // if we never find a home for this element then we'll need to hide it
1166
+ // the node is not found within the slot (`childNode`) that we're
1167
+ // currently looking at, so we stick it into `relocateNodes` to
1168
+ // handle later. If we never find a home for this element then
1169
+ // we'll need to hide it
1112
1170
  relocateNodes.push({
1113
1171
  $nodeToRelocate$: node,
1114
1172
  });
@@ -1116,30 +1174,41 @@ const relocateSlotContent = (elm) => {
1116
1174
  }
1117
1175
  }
1118
1176
  }
1177
+ // if we're dealing with any type of element (capable of itself being a
1178
+ // slot reference or containing one) then we recur
1119
1179
  if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1120
- relocateSlotContent(childNode);
1180
+ markSlotContentForRelocation(childNode);
1121
1181
  }
1122
1182
  }
1123
1183
  };
1124
- const isNodeLocatedInSlot = (nodeToRelocate, slotNameAttr) => {
1184
+ /**
1185
+ * Check whether a node is located in a given named slot.
1186
+ *
1187
+ * @param nodeToRelocate the node of interest
1188
+ * @param slotName the slot name to check
1189
+ * @returns whether the node is located in the slot or not
1190
+ */
1191
+ const isNodeLocatedInSlot = (nodeToRelocate, slotName) => {
1125
1192
  if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1126
- if (nodeToRelocate.getAttribute('slot') === null && slotNameAttr === '') {
1193
+ if (nodeToRelocate.getAttribute('slot') === null && slotName === '') {
1194
+ // if the node doesn't have a slot attribute, and the slot we're checking
1195
+ // is not a named slot, then we assume the node should be within the slot
1127
1196
  return true;
1128
1197
  }
1129
- if (nodeToRelocate.getAttribute('slot') === slotNameAttr) {
1198
+ if (nodeToRelocate.getAttribute('slot') === slotName) {
1130
1199
  return true;
1131
1200
  }
1132
1201
  return false;
1133
1202
  }
1134
- if (nodeToRelocate['s-sn'] === slotNameAttr) {
1203
+ if (nodeToRelocate['s-sn'] === slotName) {
1135
1204
  return true;
1136
1205
  }
1137
- return slotNameAttr === '';
1206
+ return slotName === '';
1138
1207
  };
1139
1208
  /**
1140
- * 'Nullify' any VDom `ref` callbacks on a VDom node or its children by
1141
- * calling them with `null`. This signals that the DOM element corresponding to
1142
- * the VDom node has been removed from the DOM.
1209
+ * 'Nullify' any VDom `ref` callbacks on a VDom node or its children by calling
1210
+ * them with `null`. This signals that the DOM element corresponding to the VDom
1211
+ * node has been removed from the DOM.
1143
1212
  *
1144
1213
  * @param vNode a virtual DOM node
1145
1214
  */
@@ -1163,6 +1232,7 @@ const nullifyVNodeRefs = (vNode) => {
1163
1232
  * @param isInitialLoad whether or not this is the first call after page load
1164
1233
  */
1165
1234
  const renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
1235
+ var _a, _b;
1166
1236
  const hostElm = hostRef.$hostElement$;
1167
1237
  const cmpMeta = hostRef.$cmpMeta$;
1168
1238
  const oldVNode = hostRef.$vnode$ || newVNode(null, null);
@@ -1215,43 +1285,48 @@ const renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
1215
1285
  // the disconnectCallback from working
1216
1286
  plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
1217
1287
  if (checkSlotRelocate) {
1218
- relocateSlotContent(rootVnode.$elm$);
1219
- let relocateData;
1220
- let nodeToRelocate;
1221
- let orgLocationNode;
1222
- let parentNodeRef;
1223
- let insertBeforeNode;
1224
- let refNode;
1225
- let i = 0;
1226
- for (; i < relocateNodes.length; i++) {
1227
- relocateData = relocateNodes[i];
1228
- nodeToRelocate = relocateData.$nodeToRelocate$;
1288
+ markSlotContentForRelocation(rootVnode.$elm$);
1289
+ for (const relocateData of relocateNodes) {
1290
+ const nodeToRelocate = relocateData.$nodeToRelocate$;
1229
1291
  if (!nodeToRelocate['s-ol']) {
1230
1292
  // add a reference node marking this node's original location
1231
1293
  // keep a reference to this node for later lookups
1232
- orgLocationNode =
1233
- doc.createTextNode('');
1294
+ const orgLocationNode = doc.createTextNode('');
1234
1295
  orgLocationNode['s-nr'] = nodeToRelocate;
1235
1296
  nodeToRelocate.parentNode.insertBefore((nodeToRelocate['s-ol'] = orgLocationNode), nodeToRelocate);
1236
1297
  }
1237
1298
  }
1238
- for (i = 0; i < relocateNodes.length; i++) {
1239
- relocateData = relocateNodes[i];
1240
- nodeToRelocate = relocateData.$nodeToRelocate$;
1241
- if (relocateData.$slotRefNode$) {
1242
- // by default we're just going to insert it directly
1243
- // after the slot reference node
1244
- parentNodeRef = relocateData.$slotRefNode$.parentNode;
1245
- insertBeforeNode = relocateData.$slotRefNode$.nextSibling;
1246
- orgLocationNode = nodeToRelocate['s-ol'];
1247
- while ((orgLocationNode = orgLocationNode.previousSibling)) {
1248
- refNode = orgLocationNode['s-nr'];
1249
- if (refNode && refNode['s-sn'] === nodeToRelocate['s-sn'] && parentNodeRef === refNode.parentNode) {
1250
- refNode = refNode.nextSibling;
1251
- if (!refNode || !refNode['s-nr']) {
1252
- insertBeforeNode = refNode;
1253
- break;
1299
+ for (const relocateData of relocateNodes) {
1300
+ const nodeToRelocate = relocateData.$nodeToRelocate$;
1301
+ const slotRefNode = relocateData.$slotRefNode$;
1302
+ if (slotRefNode) {
1303
+ const parentNodeRef = slotRefNode.parentNode;
1304
+ // When determining where to insert content, the most simple case would be
1305
+ // to relocate the node immediately following the slot reference node. We do this
1306
+ // by getting a reference to the node immediately following the slot reference node
1307
+ // since we will use `insertBefore` to manipulate the DOM.
1308
+ //
1309
+ // If there is no node immediately following the slot reference node, then we will just
1310
+ // end up appending the node as the last child of the parent.
1311
+ let insertBeforeNode = slotRefNode.nextSibling;
1312
+ // If the node we're currently planning on inserting the new node before is an element,
1313
+ // we need to do some additional checks to make sure we're inserting the node in the correct order.
1314
+ // The use case here would be that we have multiple nodes being relocated to the same slot. So, we want
1315
+ // to make sure they get inserted into their new how in the same order they were declared in their original location.
1316
+ //
1317
+ // TODO(STENCIL-914): Remove `experimentalSlotFixes` check
1318
+ {
1319
+ let orgLocationNode = (_a = nodeToRelocate['s-ol']) === null || _a === void 0 ? void 0 : _a.previousSibling;
1320
+ while (orgLocationNode) {
1321
+ let refNode = (_b = orgLocationNode['s-nr']) !== null && _b !== void 0 ? _b : null;
1322
+ if (refNode && refNode['s-sn'] === nodeToRelocate['s-sn'] && parentNodeRef === refNode.parentNode) {
1323
+ refNode = refNode.nextSibling;
1324
+ if (!refNode || !refNode['s-nr']) {
1325
+ insertBeforeNode = refNode;
1326
+ break;
1327
+ }
1254
1328
  }
1329
+ orgLocationNode = orgLocationNode.previousSibling;
1255
1330
  }
1256
1331
  }
1257
1332
  if ((!insertBeforeNode && parentNodeRef !== nodeToRelocate.parentNode) ||
@@ -1264,7 +1339,10 @@ const renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
1264
1339
  // probably a component in the index.html that doesn't have its hostname set
1265
1340
  nodeToRelocate['s-hn'] = nodeToRelocate['s-ol'].parentNode.nodeName;
1266
1341
  }
1267
- // add it back to the dom but in its new home
1342
+ // Add it back to the dom but in its new home
1343
+ // If we get to this point and `insertBeforeNode` is `null`, that means
1344
+ // we're just going to append the node as the last child of the parent. Passing
1345
+ // `null` as the second arg here will trigger that behavior.
1268
1346
  parentNodeRef.insertBefore(nodeToRelocate, insertBeforeNode);
1269
1347
  }
1270
1348
  }
@@ -1444,6 +1522,10 @@ const updateComponent = async (hostRef, instance, isInitialLoad) => {
1444
1522
  */
1445
1523
  const callRender = (hostRef, instance, elm, isInitialLoad) => {
1446
1524
  try {
1525
+ /**
1526
+ * minification optimization: `allRenderFn` is `true` if all components have a `render`
1527
+ * method, so we can call the method immediately. If not, check before calling it.
1528
+ */
1447
1529
  instance = instance.render() ;
1448
1530
  {
1449
1531
  hostRef.$flags$ &= ~16 /* HOST_FLAGS.isQueuedForUpdate */;
@@ -1523,6 +1605,16 @@ const appDidLoad = (who) => {
1523
1605
  }
1524
1606
  nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
1525
1607
  };
1608
+ /**
1609
+ * Allows to safely call a method, e.g. `componentDidLoad`, on an instance,
1610
+ * e.g. custom element node. If a build figures out that e.g. no component
1611
+ * has a `componentDidLoad` method, the instance method gets removed from the
1612
+ * output bundle and this function returns `undefined`.
1613
+ * @param instance any object that may or may not contain methods
1614
+ * @param method method name
1615
+ * @param arg single arbitrary argument
1616
+ * @returns result of method call if it exists, otherwise `undefined`
1617
+ */
1526
1618
  const safeCall = (instance, method, arg) => {
1527
1619
  if (instance && instance[method]) {
1528
1620
  try {
@@ -1723,7 +1815,18 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
1723
1815
  }
1724
1816
  return Cstr;
1725
1817
  };
1726
- const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
1818
+ /**
1819
+ * Initialize a Stencil component given a reference to its host element, its
1820
+ * runtime bookkeeping data structure, runtime metadata about the component,
1821
+ * and (optionally) an HMR version ID.
1822
+ *
1823
+ * @param elm a host element
1824
+ * @param hostRef the element's runtime bookkeeping object
1825
+ * @param cmpMeta runtime metadata for the Stencil component
1826
+ * @param hmrVersionId an (optional) HMR version ID
1827
+ */
1828
+ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
1829
+ let Cstr;
1727
1830
  // initializeComponent
1728
1831
  if ((hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
1729
1832
  // Let the runtime know that the component has been initialized
@@ -2028,13 +2131,40 @@ const hostListenerOpts = (flags) => (flags & 2 /* LISTENER_FLAGS.Capture */) !==
2028
2131
  * @returns void
2029
2132
  */
2030
2133
  const setNonce = (nonce) => (plt.$nonce$ = nonce);
2134
+ /**
2135
+ * A WeakMap mapping runtime component references to their corresponding host reference
2136
+ * instances.
2137
+ */
2031
2138
  const hostRefs = /*@__PURE__*/ new WeakMap();
2139
+ /**
2140
+ * Given a {@link d.RuntimeRef} retrieve the corresponding {@link d.HostRef}
2141
+ *
2142
+ * @param ref the runtime ref of interest
2143
+ * @returns the Host reference (if found) or undefined
2144
+ */
2032
2145
  const getHostRef = (ref) => hostRefs.get(ref);
2146
+ /**
2147
+ * Register a lazy instance with the {@link hostRefs} object so it's
2148
+ * corresponding {@link d.HostRef} can be retrieved later.
2149
+ *
2150
+ * @param lazyInstance the lazy instance of interest
2151
+ * @param hostRef that instances `HostRef` object
2152
+ * @returns a reference to the host ref WeakMap
2153
+ */
2033
2154
  const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
2034
- const registerHost = (elm, cmpMeta) => {
2155
+ /**
2156
+ * Register a host element for a Stencil component, setting up various metadata
2157
+ * and callbacks based on {@link BUILD} flags as well as the component's runtime
2158
+ * metadata.
2159
+ *
2160
+ * @param hostElement the host element to register
2161
+ * @param cmpMeta runtime metadata for that component
2162
+ * @returns a reference to the host ref WeakMap
2163
+ */
2164
+ const registerHost = (hostElement, cmpMeta) => {
2035
2165
  const hostRef = {
2036
2166
  $flags$: 0,
2037
- $hostElement$: elm,
2167
+ $hostElement$: hostElement,
2038
2168
  $cmpMeta$: cmpMeta,
2039
2169
  $instanceValues$: new Map(),
2040
2170
  };
@@ -2043,11 +2173,11 @@ const registerHost = (elm, cmpMeta) => {
2043
2173
  }
2044
2174
  {
2045
2175
  hostRef.$onReadyPromise$ = new Promise((r) => (hostRef.$onReadyResolve$ = r));
2046
- elm['s-p'] = [];
2047
- elm['s-rc'] = [];
2176
+ hostElement['s-p'] = [];
2177
+ hostElement['s-rc'] = [];
2048
2178
  }
2049
- addHostEventListeners(elm, hostRef, cmpMeta.$listeners$);
2050
- return hostRefs.set(elm, hostRef);
2179
+ addHostEventListeners(hostElement, hostRef, cmpMeta.$listeners$);
2180
+ return hostRefs.set(hostElement, hostRef);
2051
2181
  };
2052
2182
  const isMemberInElement = (elm, memberName) => memberName in elm;
2053
2183
  const consoleError = (e, el) => (0, console.error)(e, el);
@@ -2147,4 +2277,4 @@ exports.promiseResolve = promiseResolve;
2147
2277
  exports.registerInstance = registerInstance;
2148
2278
  exports.setNonce = setNonce;
2149
2279
 
2150
- //# sourceMappingURL=index-e93f381a.js.map
2280
+ //# sourceMappingURL=index-239b1c46.js.map