@jumpgroup/jump-design-system 0.1.8 → 0.1.9

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 (35) hide show
  1. package/dist/cjs/{index-91a3ed32.js → index-46644e39.js} +448 -42
  2. package/dist/cjs/index-46644e39.js.map +1 -0
  3. package/dist/cjs/jump-button.cjs.entry.js +2 -2
  4. package/dist/cjs/jump-button.cjs.entry.js.map +1 -1
  5. package/dist/cjs/jump-design-system.cjs.js +2 -2
  6. package/dist/cjs/jump-icon.cjs.entry.js +1 -1
  7. package/dist/cjs/jump-pagination.cjs.entry.js +1 -1
  8. package/dist/cjs/loader.cjs.js +2 -2
  9. package/dist/collection/components/jump-button/jump-button.js +1 -2
  10. package/dist/collection/components/jump-button/jump-button.js.map +1 -1
  11. package/dist/components/jump-button.js +2 -3
  12. package/dist/components/jump-button.js.map +1 -1
  13. package/dist/esm/{index-3cf3394c.js → index-b0176170.js} +448 -42
  14. package/dist/esm/index-b0176170.js.map +1 -0
  15. package/dist/esm/jump-button.entry.js +2 -2
  16. package/dist/esm/jump-button.entry.js.map +1 -1
  17. package/dist/esm/jump-design-system.js +3 -3
  18. package/dist/esm/jump-icon.entry.js +1 -1
  19. package/dist/esm/jump-pagination.entry.js +1 -1
  20. package/dist/esm/loader.js +3 -3
  21. package/dist/jump-design-system/jump-design-system.esm.js +1 -1
  22. package/dist/jump-design-system/{p-85fbbf60.entry.js → p-0d2b55a8.entry.js} +2 -2
  23. package/dist/jump-design-system/{p-f4cfa17d.entry.js → p-3cbc3a68.entry.js} +2 -2
  24. package/dist/jump-design-system/p-68bce598.js +3 -0
  25. package/dist/jump-design-system/p-68bce598.js.map +1 -0
  26. package/dist/jump-design-system/{p-e2af0fd9.entry.js → p-c34f0f2c.entry.js} +2 -2
  27. package/dist/jump-design-system/p-c34f0f2c.entry.js.map +1 -0
  28. package/package.json +1 -1
  29. package/dist/cjs/index-91a3ed32.js.map +0 -1
  30. package/dist/esm/index-3cf3394c.js.map +0 -1
  31. package/dist/jump-design-system/p-7216d46f.js +0 -3
  32. package/dist/jump-design-system/p-7216d46f.js.map +0 -1
  33. package/dist/jump-design-system/p-e2af0fd9.entry.js.map +0 -1
  34. /package/dist/jump-design-system/{p-85fbbf60.entry.js.map → p-0d2b55a8.entry.js.map} +0 -0
  35. /package/dist/jump-design-system/{p-f4cfa17d.entry.js.map → p-3cbc3a68.entry.js.map} +0 -0
@@ -21,6 +21,7 @@ function _interopNamespace(e) {
21
21
  }
22
22
 
23
23
  const NAMESPACE = 'jump-design-system';
24
+ const BUILD = /* jump-design-system */ { allRenderFn: true, appendChildSlotFix: false, asyncLoading: true, asyncQueue: false, attachStyles: true, cloneNodeFix: false, cmpDidLoad: true, cmpDidRender: false, cmpDidUnload: false, cmpDidUpdate: false, cmpShouldUpdate: false, cmpWillLoad: false, cmpWillRender: false, cmpWillUpdate: false, connectedCallback: false, constructableCSS: true, cssAnnotations: true, devTools: false, disconnectedCallback: false, element: false, event: false, experimentalScopedSlotChanges: false, experimentalSlotFixes: false, formAssociated: false, hasRenderFn: true, hostListener: false, hostListenerTarget: false, hostListenerTargetBody: false, hostListenerTargetDocument: false, hostListenerTargetParent: false, hostListenerTargetWindow: false, 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: false, mode: false, observeAttribute: true, profile: false, prop: true, propBoolean: true, propMutable: false, propNumber: true, propString: true, reflect: true, scoped: false, scopedSlotTextContentFix: false, scriptDataOpts: false, shadowDelegatesFocus: false, shadowDom: false, slot: true, slotChildNodesFix: false, slotRelocation: true, state: false, style: true, svg: false, taskQueue: true, transformTagName: false, updatable: true, vdomAttribute: true, vdomClass: true, vdomFunctional: false, vdomKey: true, vdomListener: false, vdomPropOrAttr: true, vdomRef: false, vdomRender: true, vdomStyle: false, vdomText: true, vdomXlink: false, watchCallback: false };
24
25
 
25
26
  /**
26
27
  * Virtual DOM patching algorithm based on Snabbdom by
@@ -30,9 +31,11 @@ const NAMESPACE = 'jump-design-system';
30
31
  *
31
32
  * Modified for Stencil's renderer and slot projection
32
33
  */
33
- let scopeId;
34
+ let contentRef;
34
35
  let hostTagName;
35
36
  let useNativeShadowDom = false;
37
+ let checkSlotFallbackVisibility = false;
38
+ let checkSlotRelocate = false;
36
39
  let isSvgMode = false;
37
40
  let queuePending = false;
38
41
  const createTime = (fnName, tagName = '') => {
@@ -65,7 +68,6 @@ const SLOT_FB_CSS = 'slot-fb{display:contents}slot-fb[hidden]{display:none}';
65
68
  * Don't add values to these!!
66
69
  */
67
70
  const EMPTY_OBJ = {};
68
- const isDef = (v) => v != null;
69
71
  /**
70
72
  * Check whether a value is a 'complex type', defined here as an object or a
71
73
  * function.
@@ -103,6 +105,7 @@ function queryNonceMetaTagContent(doc) {
103
105
  const h = (nodeName, vnodeData, ...children) => {
104
106
  let child = null;
105
107
  let key = null;
108
+ let slotName = null;
106
109
  let simple = false;
107
110
  let lastSimple = false;
108
111
  const vNodeChildren = [];
@@ -133,6 +136,9 @@ const h = (nodeName, vnodeData, ...children) => {
133
136
  if (vnodeData.key) {
134
137
  key = vnodeData.key;
135
138
  }
139
+ if (vnodeData.name) {
140
+ slotName = vnodeData.name;
141
+ }
136
142
  // normalize class / className attributes
137
143
  {
138
144
  const classData = vnodeData.className || vnodeData.class;
@@ -154,6 +160,9 @@ const h = (nodeName, vnodeData, ...children) => {
154
160
  {
155
161
  vnode.$key$ = key;
156
162
  }
163
+ {
164
+ vnode.$name$ = slotName;
165
+ }
157
166
  return vnode;
158
167
  };
159
168
  /**
@@ -178,6 +187,9 @@ const newVNode = (tag, text) => {
178
187
  {
179
188
  vnode.$key$ = null;
180
189
  }
190
+ {
191
+ vnode.$name$ = null;
192
+ }
181
193
  return vnode;
182
194
  };
183
195
  const Host = {};
@@ -308,20 +320,8 @@ const addStyle = (styleContainerNode, cmpMeta, mode) => {
308
320
  const attachStyles = (hostRef) => {
309
321
  const cmpMeta = hostRef.$cmpMeta$;
310
322
  const elm = hostRef.$hostElement$;
311
- const flags = cmpMeta.$flags$;
312
323
  const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
313
- const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta);
314
- if (flags & 10 /* CMP_FLAGS.needsScopedEncapsulation */) {
315
- // only required when we're NOT using native shadow dom (slot)
316
- // or this browser doesn't support native shadow dom
317
- // and this host element was NOT created with SSR
318
- // let's pick out the inner content for slot projection
319
- // create a node to represent where the original
320
- // content was first placed, which is useful later on
321
- // DOM WRITE!!
322
- elm['s-sc'] = scopeId;
323
- elm.classList.add(scopeId + '-h');
324
- }
324
+ addStyle(elm.getRootNode(), cmpMeta);
325
325
  endAttachStyles();
326
326
  };
327
327
  const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
@@ -447,22 +447,36 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
447
447
  let i = 0;
448
448
  let elm;
449
449
  let childNode;
450
+ let oldVNode;
451
+ if (!useNativeShadowDom) {
452
+ // remember for later we need to check to relocate nodes
453
+ checkSlotRelocate = true;
454
+ if (newVNode.$tag$ === 'slot') {
455
+ newVNode.$flags$ |= newVNode.$children$
456
+ ? // slot element has fallback content
457
+ 2 /* VNODE_FLAGS.isSlotFallback */
458
+ : // slot element does not have fallback content
459
+ 1 /* VNODE_FLAGS.isSlotReference */;
460
+ }
461
+ }
450
462
  if (newVNode.$text$ !== null) {
451
463
  // create text node
452
464
  elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
453
465
  }
466
+ else if (newVNode.$flags$ & 1 /* VNODE_FLAGS.isSlotReference */) {
467
+ // create a slot reference node
468
+ elm = newVNode.$elm$ =
469
+ doc.createTextNode('');
470
+ }
454
471
  else {
455
472
  // create element
456
- elm = newVNode.$elm$ = (doc.createElement(newVNode.$tag$));
473
+ elm = newVNode.$elm$ = (doc.createElement(newVNode.$flags$ & 2 /* VNODE_FLAGS.isSlotFallback */
474
+ ? 'slot-fb'
475
+ : newVNode.$tag$));
457
476
  // add css classes, attrs, props, listeners, etc.
458
477
  {
459
478
  updateElement(null, newVNode, isSvgMode);
460
479
  }
461
- if (isDef(scopeId) && elm['s-si'] !== scopeId) {
462
- // if there is a scopeId and this is the initial render
463
- // then let's add the scopeId as a css class
464
- elm.classList.add((elm['s-si'] = scopeId));
465
- }
466
480
  if (newVNode.$children$) {
467
481
  for (i = 0; i < newVNode.$children$.length; ++i) {
468
482
  // create the node
@@ -478,8 +492,50 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
478
492
  // This needs to always happen so we can hide nodes that are projected
479
493
  // to another component but don't end up in a slot
480
494
  elm['s-hn'] = hostTagName;
495
+ {
496
+ if (newVNode.$flags$ & (2 /* VNODE_FLAGS.isSlotFallback */ | 1 /* VNODE_FLAGS.isSlotReference */)) {
497
+ // remember the content reference comment
498
+ elm['s-sr'] = true;
499
+ // remember the content reference comment
500
+ elm['s-cr'] = contentRef;
501
+ // remember the slot name, or empty string for default slot
502
+ elm['s-sn'] = newVNode.$name$ || '';
503
+ // check if we've got an old vnode for this slot
504
+ oldVNode = oldParentVNode && oldParentVNode.$children$ && oldParentVNode.$children$[childIndex];
505
+ if (oldVNode && oldVNode.$tag$ === newVNode.$tag$ && oldParentVNode.$elm$) {
506
+ {
507
+ // we've got an old slot vnode and the wrapper is being replaced
508
+ // so let's move the old slot content back to its original location
509
+ putBackInOriginalLocation(oldParentVNode.$elm$, false);
510
+ }
511
+ }
512
+ }
513
+ }
481
514
  return elm;
482
515
  };
516
+ const putBackInOriginalLocation = (parentElm, recursive) => {
517
+ plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
518
+ const oldSlotChildNodes = parentElm.childNodes;
519
+ for (let i = oldSlotChildNodes.length - 1; i >= 0; i--) {
520
+ const childNode = oldSlotChildNodes[i];
521
+ if (childNode['s-hn'] !== hostTagName && childNode['s-ol']) {
522
+ // and relocate it back to it's original location
523
+ parentReferenceNode(childNode).insertBefore(childNode, referenceNode(childNode));
524
+ // remove the old original location comment entirely
525
+ // later on the patch function will know what to do
526
+ // and move this to the correct spot if need be
527
+ childNode['s-ol'].remove();
528
+ childNode['s-ol'] = undefined;
529
+ // Reset so we can correctly move the node around again.
530
+ childNode['s-sh'] = undefined;
531
+ checkSlotRelocate = true;
532
+ }
533
+ if (recursive) {
534
+ putBackInOriginalLocation(childNode, recursive);
535
+ }
536
+ }
537
+ plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
538
+ };
483
539
  /**
484
540
  * Create DOM nodes corresponding to a list of {@link d.Vnode} objects and
485
541
  * add them to the DOM in the appropriate place.
@@ -496,17 +552,14 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
496
552
  * creating DOM nodes (inclusive)
497
553
  */
498
554
  const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
499
- let containerElm = (parentElm);
555
+ let containerElm = ((parentElm['s-cr'] && parentElm['s-cr'].parentNode) || parentElm);
500
556
  let childNode;
501
- if (containerElm.shadowRoot && containerElm.tagName === hostTagName) {
502
- containerElm = containerElm.shadowRoot;
503
- }
504
557
  for (; startIdx <= endIdx; ++startIdx) {
505
558
  if (vnodes[startIdx]) {
506
559
  childNode = createElm(null, parentVNode, startIdx);
507
560
  if (childNode) {
508
561
  vnodes[startIdx].$elm$ = childNode;
509
- containerElm.insertBefore(childNode, before);
562
+ containerElm.insertBefore(childNode, referenceNode(before) );
510
563
  }
511
564
  }
512
565
  }
@@ -528,6 +581,20 @@ const removeVnodes = (vnodes, startIdx, endIdx) => {
528
581
  if (vnode) {
529
582
  const elm = vnode.$elm$;
530
583
  if (elm) {
584
+ {
585
+ // we're removing this element
586
+ // so it's possible we need to show slot fallback content now
587
+ checkSlotFallbackVisibility = true;
588
+ if (elm['s-ol']) {
589
+ // remove the original location comment
590
+ elm['s-ol'].remove();
591
+ }
592
+ else {
593
+ // it's possible that child nodes of the node
594
+ // that's being removed are slot nodes
595
+ putBackInOriginalLocation(elm, true);
596
+ }
597
+ }
531
598
  // remove the vnode's element from the dom
532
599
  elm.remove();
533
600
  }
@@ -648,6 +715,23 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh, isInitialRender = fal
648
715
  newEndVnode = newCh[--newEndIdx];
649
716
  }
650
717
  else if (isSameVnode(oldStartVnode, newEndVnode, isInitialRender)) {
718
+ // case: "Vnode moved right"
719
+ //
720
+ // We've found that the last node in our window on the new children is
721
+ // the same VNode as the _first_ node in our window on the old children
722
+ // we're dealing with now. Visually, this is the layout of these two
723
+ // nodes:
724
+ //
725
+ // newCh: [..., newStartVnode , ... , newEndVnode , ...]
726
+ // ^^^^^^^^^^^
727
+ // oldCh: [..., oldStartVnode , ... , oldEndVnode , ...]
728
+ // ^^^^^^^^^^^^^
729
+ //
730
+ // In this situation we need to patch `newEndVnode` onto `oldStartVnode`
731
+ // and move the DOM element for `oldStartVnode`.
732
+ if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
733
+ putBackInOriginalLocation(oldStartVnode.$elm$.parentNode, false);
734
+ }
651
735
  patch(oldStartVnode, newEndVnode, isInitialRender);
652
736
  // We need to move the element for `oldStartVnode` into a position which
653
737
  // will be appropriate for `newEndVnode`. For this we can use
@@ -671,6 +755,24 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh, isInitialRender = fal
671
755
  newEndVnode = newCh[--newEndIdx];
672
756
  }
673
757
  else if (isSameVnode(oldEndVnode, newStartVnode, isInitialRender)) {
758
+ // case: "Vnode moved left"
759
+ //
760
+ // We've found that the first node in our window on the new children is
761
+ // the same VNode as the _last_ node in our window on the old children.
762
+ // Visually, this is the layout of these two nodes:
763
+ //
764
+ // newCh: [..., newStartVnode , ... , newEndVnode , ...]
765
+ // ^^^^^^^^^^^^^
766
+ // oldCh: [..., oldStartVnode , ... , oldEndVnode , ...]
767
+ // ^^^^^^^^^^^
768
+ //
769
+ // In this situation we need to patch `newStartVnode` onto `oldEndVnode`
770
+ // (which will handle updating any changed attributes, reconciling their
771
+ // children etc) but we also need to move the DOM node to which
772
+ // `oldEndVnode` corresponds.
773
+ if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
774
+ putBackInOriginalLocation(oldEndVnode.$elm$.parentNode, false);
775
+ }
674
776
  patch(oldEndVnode, newStartVnode, isInitialRender);
675
777
  // We've already checked above if `oldStartVnode` and `newStartVnode` are
676
778
  // the same node, so since we're here we know that they are not. Thus we
@@ -727,7 +829,7 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh, isInitialRender = fal
727
829
  if (node) {
728
830
  // if we created a new node then handle inserting it to the DOM
729
831
  {
730
- oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
832
+ parentReferenceNode(oldStartVnode.$elm$).insertBefore(node, referenceNode(oldStartVnode.$elm$));
731
833
  }
732
834
  }
733
835
  }
@@ -766,6 +868,9 @@ const isSameVnode = (leftVNode, rightVNode, isInitialRender = false) => {
766
868
  // compare if two vnode to see if they're "technically" the same
767
869
  // need to have the same element tag, and same key to be the same
768
870
  if (leftVNode.$tag$ === rightVNode.$tag$) {
871
+ if (leftVNode.$tag$ === 'slot') {
872
+ return leftVNode.$name$ === rightVNode.$name$;
873
+ }
769
874
  // this will be set if JSX tags in the build have `key` attrs set on them
770
875
  // we only want to check this if we're not on the first render since on
771
876
  // first render `leftVNode.$key$` will always be `null`, so we can be led
@@ -778,6 +883,14 @@ const isSameVnode = (leftVNode, rightVNode, isInitialRender = false) => {
778
883
  }
779
884
  return false;
780
885
  };
886
+ const referenceNode = (node) => {
887
+ // this node was relocated to a new location in the dom
888
+ // because of some other component's slot
889
+ // but we still have an html comment in place of where
890
+ // it's original location was according to it's original vdom
891
+ return (node && node['s-ol']) || node;
892
+ };
893
+ const parentReferenceNode = (node) => (node['s-ol'] ? node['s-ol'] : node).parentNode;
781
894
  /**
782
895
  * Handle reconciling an outdated VNode with a new one which corresponds to
783
896
  * it. This function handles flushing updates to the DOM and reconciling the
@@ -793,6 +906,7 @@ const patch = (oldVNode, newVNode, isInitialRender = false) => {
793
906
  const newChildren = newVNode.$children$;
794
907
  const tag = newVNode.$tag$;
795
908
  const text = newVNode.$text$;
909
+ let defaultHolder;
796
910
  if (text === null) {
797
911
  {
798
912
  if (tag === 'slot' && !useNativeShadowDom) ;
@@ -822,12 +936,193 @@ const patch = (oldVNode, newVNode, isInitialRender = false) => {
822
936
  removeVnodes(oldChildren, 0, oldChildren.length - 1);
823
937
  }
824
938
  }
939
+ else if ((defaultHolder = elm['s-cr'])) {
940
+ // this element has slotted content
941
+ defaultHolder.parentNode.textContent = text;
942
+ }
825
943
  else if (oldVNode.$text$ !== text) {
826
944
  // update the text content for the text only vnode
827
945
  // and also only if the text is different than before
828
946
  elm.data = text;
829
947
  }
830
948
  };
949
+ /**
950
+ * Adjust the `.hidden` property as-needed on any nodes in a DOM subtree which
951
+ * are slot fallbacks nodes.
952
+ *
953
+ * A slot fallback node should be visible by default. Then, it should be
954
+ * conditionally hidden if:
955
+ *
956
+ * - it has a sibling with a `slot` property set to its slot name or if
957
+ * - it is a default fallback slot node, in which case we hide if it has any
958
+ * content
959
+ *
960
+ * @param elm the element of interest
961
+ */
962
+ const updateFallbackSlotVisibility = (elm) => {
963
+ const childNodes = elm.childNodes;
964
+ for (const childNode of childNodes) {
965
+ if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
966
+ if (childNode['s-sr']) {
967
+ // this is a slot fallback node
968
+ // get the slot name for this slot reference node
969
+ const slotName = childNode['s-sn'];
970
+ // by default always show a fallback slot node
971
+ // then hide it if there are other slots in the light dom
972
+ childNode.hidden = false;
973
+ // we need to check all of its sibling nodes in order to see if
974
+ // `childNode` should be hidden
975
+ for (const siblingNode of childNodes) {
976
+ // Don't check the node against itself
977
+ if (siblingNode !== childNode) {
978
+ if (siblingNode['s-hn'] !== childNode['s-hn'] || slotName !== '') {
979
+ // this sibling node is from a different component OR is a named
980
+ // fallback slot node
981
+ if (siblingNode.nodeType === 1 /* NODE_TYPE.ElementNode */ &&
982
+ (slotName === siblingNode.getAttribute('slot') || slotName === siblingNode['s-sn'])) {
983
+ childNode.hidden = true;
984
+ break;
985
+ }
986
+ }
987
+ else {
988
+ // this is a default fallback slot node
989
+ // any element or text node (with content)
990
+ // should hide the default fallback slot node
991
+ if (siblingNode.nodeType === 1 /* NODE_TYPE.ElementNode */ ||
992
+ (siblingNode.nodeType === 3 /* NODE_TYPE.TextNode */ && siblingNode.textContent.trim() !== '')) {
993
+ childNode.hidden = true;
994
+ break;
995
+ }
996
+ }
997
+ }
998
+ }
999
+ }
1000
+ // keep drilling down
1001
+ updateFallbackSlotVisibility(childNode);
1002
+ }
1003
+ }
1004
+ };
1005
+ /**
1006
+ * Component-global information about nodes which are either currently being
1007
+ * relocated or will be shortly.
1008
+ */
1009
+ const relocateNodes = [];
1010
+ /**
1011
+ * Mark the contents of a slot for relocation via adding references to them to
1012
+ * the {@link relocateNodes} data structure. The actual work of relocating them
1013
+ * will then be handled in {@link renderVdom}.
1014
+ *
1015
+ * @param elm a render node whose child nodes need to be relocated
1016
+ */
1017
+ const markSlotContentForRelocation = (elm) => {
1018
+ // tslint:disable-next-line: prefer-const
1019
+ let node;
1020
+ let hostContentNodes;
1021
+ let j;
1022
+ for (const childNode of elm.childNodes) {
1023
+ // we need to find child nodes which are slot references so we can then try
1024
+ // to match them up with nodes that need to be relocated
1025
+ if (childNode['s-sr'] && (node = childNode['s-cr']) && node.parentNode) {
1026
+ // first get the content reference comment node ('s-cr'), then we get
1027
+ // its parent, which is where all the host content is now
1028
+ hostContentNodes = node.parentNode.childNodes;
1029
+ const slotName = childNode['s-sn'];
1030
+ // iterate through all the nodes under the location where the host was
1031
+ // originally rendered
1032
+ for (j = hostContentNodes.length - 1; j >= 0; j--) {
1033
+ node = hostContentNodes[j];
1034
+ // check that the node is not a content reference node or a node
1035
+ // reference and then check that the host name does not match that of
1036
+ // childNode.
1037
+ // In addition, check that the slot either has not already been relocated, or
1038
+ // that its current location's host is not childNode's host. This is essentially
1039
+ // a check so that we don't try to relocate (and then hide) a node that is already
1040
+ // where it should be.
1041
+ if (!node['s-cn'] &&
1042
+ !node['s-nr'] &&
1043
+ node['s-hn'] !== childNode['s-hn'] &&
1044
+ (!BUILD.experimentalSlotFixes )) {
1045
+ // if `node` is located in the slot that `childNode` refers to (via the
1046
+ // `'s-sn'` property) then we need to relocate it from it's current spot
1047
+ // (under the host element parent) to the right slot location
1048
+ if (isNodeLocatedInSlot(node, slotName)) {
1049
+ // it's possible we've already decided to relocate this node
1050
+ let relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
1051
+ // made some changes to slots
1052
+ // let's make sure we also double check
1053
+ // fallbacks are correctly hidden or shown
1054
+ checkSlotFallbackVisibility = true;
1055
+ // ensure that the slot-name attr is correct
1056
+ node['s-sn'] = node['s-sn'] || slotName;
1057
+ if (relocateNodeData) {
1058
+ relocateNodeData.$nodeToRelocate$['s-sh'] = childNode['s-hn'];
1059
+ // we marked this node for relocation previously but didn't find
1060
+ // out the slot reference node to which it needs to be relocated
1061
+ // so write it down now!
1062
+ relocateNodeData.$slotRefNode$ = childNode;
1063
+ }
1064
+ else {
1065
+ node['s-sh'] = childNode['s-hn'];
1066
+ // add to our list of nodes to relocate
1067
+ relocateNodes.push({
1068
+ $slotRefNode$: childNode,
1069
+ $nodeToRelocate$: node,
1070
+ });
1071
+ }
1072
+ if (node['s-sr']) {
1073
+ relocateNodes.map((relocateNode) => {
1074
+ if (isNodeLocatedInSlot(relocateNode.$nodeToRelocate$, node['s-sn'])) {
1075
+ relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
1076
+ if (relocateNodeData && !relocateNode.$slotRefNode$) {
1077
+ relocateNode.$slotRefNode$ = relocateNodeData.$slotRefNode$;
1078
+ }
1079
+ }
1080
+ });
1081
+ }
1082
+ }
1083
+ else if (!relocateNodes.some((r) => r.$nodeToRelocate$ === node)) {
1084
+ // the node is not found within the slot (`childNode`) that we're
1085
+ // currently looking at, so we stick it into `relocateNodes` to
1086
+ // handle later. If we never find a home for this element then
1087
+ // we'll need to hide it
1088
+ relocateNodes.push({
1089
+ $nodeToRelocate$: node,
1090
+ });
1091
+ }
1092
+ }
1093
+ }
1094
+ }
1095
+ // if we're dealing with any type of element (capable of itself being a
1096
+ // slot reference or containing one) then we recur
1097
+ if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1098
+ markSlotContentForRelocation(childNode);
1099
+ }
1100
+ }
1101
+ };
1102
+ /**
1103
+ * Check whether a node is located in a given named slot.
1104
+ *
1105
+ * @param nodeToRelocate the node of interest
1106
+ * @param slotName the slot name to check
1107
+ * @returns whether the node is located in the slot or not
1108
+ */
1109
+ const isNodeLocatedInSlot = (nodeToRelocate, slotName) => {
1110
+ if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1111
+ if (nodeToRelocate.getAttribute('slot') === null && slotName === '') {
1112
+ // if the node doesn't have a slot attribute, and the slot we're checking
1113
+ // is not a named slot, then we assume the node should be within the slot
1114
+ return true;
1115
+ }
1116
+ if (nodeToRelocate.getAttribute('slot') === slotName) {
1117
+ return true;
1118
+ }
1119
+ return false;
1120
+ }
1121
+ if (nodeToRelocate['s-sn'] === slotName) {
1122
+ return true;
1123
+ }
1124
+ return slotName === '';
1125
+ };
831
1126
  /**
832
1127
  * The main entry point for Stencil's virtual DOM-based rendering engine
833
1128
  *
@@ -842,6 +1137,7 @@ const patch = (oldVNode, newVNode, isInitialRender = false) => {
842
1137
  * @param isInitialLoad whether or not this is the first call after page load
843
1138
  */
844
1139
  const renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
1140
+ var _a, _b, _c, _d;
845
1141
  const hostElm = hostRef.$hostElement$;
846
1142
  const cmpMeta = hostRef.$cmpMeta$;
847
1143
  const oldVNode = hostRef.$vnode$ || newVNode(null, null);
@@ -880,13 +1176,113 @@ const renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
880
1176
  rootVnode.$tag$ = null;
881
1177
  rootVnode.$flags$ |= 4 /* VNODE_FLAGS.isHost */;
882
1178
  hostRef.$vnode$ = rootVnode;
883
- rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm );
1179
+ rootVnode.$elm$ = oldVNode.$elm$ = (hostElm);
1180
+ useNativeShadowDom = (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) !== 0;
884
1181
  {
885
- scopeId = hostElm['s-sc'];
1182
+ contentRef = hostElm['s-cr'];
1183
+ // always reset
1184
+ checkSlotFallbackVisibility = false;
886
1185
  }
887
- useNativeShadowDom = (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) !== 0;
888
1186
  // synchronous patch
889
1187
  patch(oldVNode, rootVnode, isInitialLoad);
1188
+ {
1189
+ // while we're moving nodes around existing nodes, temporarily disable
1190
+ // the disconnectCallback from working
1191
+ plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
1192
+ if (checkSlotRelocate) {
1193
+ markSlotContentForRelocation(rootVnode.$elm$);
1194
+ for (const relocateData of relocateNodes) {
1195
+ const nodeToRelocate = relocateData.$nodeToRelocate$;
1196
+ if (!nodeToRelocate['s-ol']) {
1197
+ // add a reference node marking this node's original location
1198
+ // keep a reference to this node for later lookups
1199
+ const orgLocationNode = doc.createTextNode('');
1200
+ orgLocationNode['s-nr'] = nodeToRelocate;
1201
+ nodeToRelocate.parentNode.insertBefore((nodeToRelocate['s-ol'] = orgLocationNode), nodeToRelocate);
1202
+ }
1203
+ }
1204
+ for (const relocateData of relocateNodes) {
1205
+ const nodeToRelocate = relocateData.$nodeToRelocate$;
1206
+ const slotRefNode = relocateData.$slotRefNode$;
1207
+ if (slotRefNode) {
1208
+ const parentNodeRef = slotRefNode.parentNode;
1209
+ // When determining where to insert content, the most simple case would be
1210
+ // to relocate the node immediately following the slot reference node. We do this
1211
+ // by getting a reference to the node immediately following the slot reference node
1212
+ // since we will use `insertBefore` to manipulate the DOM.
1213
+ //
1214
+ // If there is no node immediately following the slot reference node, then we will just
1215
+ // end up appending the node as the last child of the parent.
1216
+ let insertBeforeNode = slotRefNode.nextSibling;
1217
+ // If the node we're currently planning on inserting the new node before is an element,
1218
+ // we need to do some additional checks to make sure we're inserting the node in the correct order.
1219
+ // The use case here would be that we have multiple nodes being relocated to the same slot. So, we want
1220
+ // to make sure they get inserted into their new how in the same order they were declared in their original location.
1221
+ //
1222
+ // TODO(STENCIL-914): Remove `experimentalSlotFixes` check
1223
+ {
1224
+ let orgLocationNode = (_a = nodeToRelocate['s-ol']) === null || _a === void 0 ? void 0 : _a.previousSibling;
1225
+ while (orgLocationNode) {
1226
+ let refNode = (_b = orgLocationNode['s-nr']) !== null && _b !== void 0 ? _b : null;
1227
+ if (refNode && refNode['s-sn'] === nodeToRelocate['s-sn'] && parentNodeRef === refNode.parentNode) {
1228
+ refNode = refNode.nextSibling;
1229
+ if (!refNode || !refNode['s-nr']) {
1230
+ insertBeforeNode = refNode;
1231
+ break;
1232
+ }
1233
+ }
1234
+ orgLocationNode = orgLocationNode.previousSibling;
1235
+ }
1236
+ }
1237
+ if ((!insertBeforeNode && parentNodeRef !== nodeToRelocate.parentNode) ||
1238
+ nodeToRelocate.nextSibling !== insertBeforeNode) {
1239
+ // we've checked that it's worth while to relocate
1240
+ // since that the node to relocate
1241
+ // has a different next sibling or parent relocated
1242
+ if (nodeToRelocate !== insertBeforeNode) {
1243
+ if (!nodeToRelocate['s-hn'] && nodeToRelocate['s-ol']) {
1244
+ // probably a component in the index.html that doesn't have its hostname set
1245
+ nodeToRelocate['s-hn'] = nodeToRelocate['s-ol'].parentNode.nodeName;
1246
+ }
1247
+ // Add it back to the dom but in its new home
1248
+ // If we get to this point and `insertBeforeNode` is `null`, that means
1249
+ // we're just going to append the node as the last child of the parent. Passing
1250
+ // `null` as the second arg here will trigger that behavior.
1251
+ parentNodeRef.insertBefore(nodeToRelocate, insertBeforeNode);
1252
+ // Reset the `hidden` value back to what it was defined as originally
1253
+ // This solves a problem where a `slot` is dynamically rendered and `hidden` may have
1254
+ // been set on content originally, but now it has a slot to go to so it should have
1255
+ // the value it was defined as having in the DOM, not what we overrode it to.
1256
+ if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1257
+ nodeToRelocate.hidden = (_c = nodeToRelocate['s-ih']) !== null && _c !== void 0 ? _c : false;
1258
+ }
1259
+ }
1260
+ }
1261
+ }
1262
+ else {
1263
+ // this node doesn't have a slot home to go to, so let's hide it
1264
+ if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1265
+ // Store the initial value of `hidden` so we can reset it later when
1266
+ // moving nodes around.
1267
+ if (isInitialLoad) {
1268
+ nodeToRelocate['s-ih'] = (_d = nodeToRelocate.hidden) !== null && _d !== void 0 ? _d : false;
1269
+ }
1270
+ nodeToRelocate.hidden = true;
1271
+ }
1272
+ }
1273
+ }
1274
+ }
1275
+ if (checkSlotFallbackVisibility) {
1276
+ updateFallbackSlotVisibility(rootVnode.$elm$);
1277
+ }
1278
+ // done moving nodes around
1279
+ // allow the disconnect callback to work again
1280
+ plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
1281
+ // always reset
1282
+ relocateNodes.length = 0;
1283
+ }
1284
+ // Clear the content ref so we don't create a memory leak
1285
+ contentRef = undefined;
890
1286
  };
891
1287
  const attachToAncestor = (hostRef, ancestorComponent) => {
892
1288
  if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
@@ -1375,6 +1771,16 @@ const connectedCallback = (elm) => {
1375
1771
  if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
1376
1772
  // first time this component has connected
1377
1773
  hostRef.$flags$ |= 1 /* HOST_FLAGS.hasConnected */;
1774
+ {
1775
+ // initUpdate
1776
+ // if the slot polyfill is required we'll need to put some nodes
1777
+ // in here to act as original content anchors as we move nodes around
1778
+ // host element has been connected to the DOM
1779
+ if ((// TODO(STENCIL-854): Remove code related to legacy shadowDomShim field
1780
+ cmpMeta.$flags$ & (4 /* CMP_FLAGS.hasSlotRelocation */ | 8 /* CMP_FLAGS.needsShadowDomShim */))) {
1781
+ setContentReference(elm);
1782
+ }
1783
+ }
1378
1784
  {
1379
1785
  // find the first ancestor component (if there is one) and register
1380
1786
  // this component as one of the actively loading child components for its ancestor
@@ -1415,6 +1821,17 @@ const connectedCallback = (elm) => {
1415
1821
  endConnected();
1416
1822
  }
1417
1823
  };
1824
+ const setContentReference = (elm) => {
1825
+ // only required when we're NOT using native shadow dom (slot)
1826
+ // or this browser doesn't support native shadow dom
1827
+ // and this host element was NOT created with SSR
1828
+ // let's pick out the inner content for slot projection
1829
+ // create a node to represent where the original
1830
+ // content was first placed, which is useful later on
1831
+ const contentRefElm = (elm['s-cr'] = doc.createComment(''));
1832
+ contentRefElm['s-cn'] = true;
1833
+ elm.insertBefore(contentRefElm, elm.firstChild);
1834
+ };
1418
1835
  const disconnectInstance = (instance) => {
1419
1836
  };
1420
1837
  const disconnectedCallback = async (elm) => {
@@ -1468,17 +1885,6 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
1468
1885
  super(self);
1469
1886
  self = this;
1470
1887
  registerHost(self, cmpMeta);
1471
- if (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
1472
- // this component is using shadow dom
1473
- // and this browser supports shadow dom
1474
- // add the read-only property "shadowRoot" to the host element
1475
- // adding the shadow root build conditionals to minimize runtime
1476
- {
1477
- {
1478
- self.attachShadow({ mode: 'open' });
1479
- }
1480
- }
1481
- }
1482
1888
  }
1483
1889
  connectedCallback() {
1484
1890
  if (appLoadFallback) {
@@ -1702,4 +2108,4 @@ exports.promiseResolve = promiseResolve;
1702
2108
  exports.registerInstance = registerInstance;
1703
2109
  exports.setNonce = setNonce;
1704
2110
 
1705
- //# sourceMappingURL=index-91a3ed32.js.map
2111
+ //# sourceMappingURL=index-46644e39.js.map