@lwc/synthetic-shadow 2.23.6 → 2.25.0

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.
@@ -148,7 +148,7 @@ const KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode';
148
148
  // We use this to detect symbol support in order to avoid the expensive symbol polyfill. Note that
149
149
  // we can't use typeof since it will fail when transpiling.
150
150
  const hasNativeSymbolSupport = /*@__PURE__*/ (() => Symbol('x').toString() === 'Symbol(x)')();
151
- /** version: 2.23.6 */
151
+ /** version: 2.25.0 */
152
152
 
153
153
  /*
154
154
  * Copyright (c) 2018, salesforce.com, inc.
@@ -462,7 +462,7 @@ if (!_globalThis.lwcRuntimeFlags) {
462
462
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
463
463
  }
464
464
  const lwcRuntimeFlags = _globalThis.lwcRuntimeFlags;
465
- /** version: 2.23.6 */
465
+ /** version: 2.25.0 */
466
466
 
467
467
  /*
468
468
  * Copyright (c) 2018, salesforce.com, inc.
@@ -543,201 +543,238 @@ function isNodeShadowed(node) {
543
543
  * SPDX-License-Identifier: MIT
544
544
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
545
545
  */
546
- // when finding a slot in the DOM, we can fold it if it is contained
547
546
  // inside another slot.
547
+
548
548
  function foldSlotElement(slot) {
549
- let parent = parentElementGetter.call(slot);
550
- while (!isNull(parent) && isSlotElement(parent)) {
551
- slot = parent;
552
- parent = parentElementGetter.call(slot);
553
- }
554
- return slot;
549
+ let parent = parentElementGetter.call(slot);
550
+
551
+ while (!isNull(parent) && isSlotElement(parent)) {
552
+ slot = parent;
553
+ parent = parentElementGetter.call(slot);
554
+ }
555
+
556
+ return slot;
555
557
  }
558
+
556
559
  function isNodeSlotted(host, node) {
557
- if (process.env.NODE_ENV !== 'production') {
558
- assert.invariant(host instanceof HTMLElement, `isNodeSlotted() should be called with a host as the first argument instead of ${host}`);
559
- assert.invariant(node instanceof _Node, `isNodeSlotted() should be called with a node as the second argument instead of ${node}`);
560
- assert.invariant(compareDocumentPosition.call(node, host) & DOCUMENT_POSITION_CONTAINS, `isNodeSlotted() should never be called with a node that is not a child node of ${host}`);
561
- }
562
- const hostKey = getNodeKey(host);
563
- // this routine assumes that the node is coming from a different shadow (it is not owned by the host)
564
- // just in case the provided node is not an element
565
- let currentElement = node instanceof Element ? node : parentElementGetter.call(node);
566
- while (!isNull(currentElement) && currentElement !== host) {
567
- const elmOwnerKey = getNodeNearestOwnerKey(currentElement);
568
- const parent = parentElementGetter.call(currentElement);
569
- if (elmOwnerKey === hostKey) {
570
- // we have reached an element inside the host's template, and only if
571
- // that element is an slot, then the node is considered slotted
572
- return isSlotElement(currentElement);
573
- }
574
- else if (parent === host) {
575
- return false;
576
- }
577
- else if (!isNull(parent) && getNodeNearestOwnerKey(parent) !== elmOwnerKey) {
578
- // we are crossing a boundary of some sort since the elm and its parent
579
- // have different owner key. for slotted elements, this is possible
580
- // if the parent happens to be a slot.
581
- if (isSlotElement(parent)) {
582
- /**
583
- * the slot parent might be allocated inside another slot, think of:
584
- * <x-root> (<--- root element)
585
- * <x-parent> (<--- own by x-root)
586
- * <x-child> (<--- own by x-root)
587
- * <slot> (<--- own by x-child)
588
- * <slot> (<--- own by x-parent)
589
- * <div> (<--- own by x-root)
590
- *
591
- * while checking if x-parent has the div slotted, we need to traverse
592
- * up, but when finding the first slot, we skip that one in favor of the
593
- * most outer slot parent before jumping into its corresponding host.
594
- */
595
- currentElement = getNodeOwner(foldSlotElement(parent));
596
- if (!isNull(currentElement)) {
597
- if (currentElement === host) {
598
- // the slot element is a top level element inside the shadow
599
- // of a host that was allocated into host in question
600
- return true;
601
- }
602
- else if (getNodeNearestOwnerKey(currentElement) === hostKey) {
603
- // the slot element is an element inside the shadow
604
- // of a host that was allocated into host in question
605
- return true;
606
- }
607
- }
608
- }
609
- else {
610
- return false;
611
- }
612
- }
613
- else {
614
- currentElement = parent;
560
+ if (process.env.NODE_ENV !== 'production') {
561
+ assert.invariant(host instanceof HTMLElement, `isNodeSlotted() should be called with a host as the first argument instead of ${host}`);
562
+ assert.invariant(node instanceof _Node, `isNodeSlotted() should be called with a node as the second argument instead of ${node}`);
563
+ assert.invariant(compareDocumentPosition.call(node, host) & DOCUMENT_POSITION_CONTAINS, `isNodeSlotted() should never be called with a node that is not a child node of ${host}`);
564
+ }
565
+
566
+ const hostKey = getNodeKey(host); // this routine assumes that the node is coming from a different shadow (it is not owned by the host)
567
+ // just in case the provided node is not an element
568
+
569
+ let currentElement = node instanceof Element ? node : parentElementGetter.call(node);
570
+
571
+ while (!isNull(currentElement) && currentElement !== host) {
572
+ const elmOwnerKey = getNodeNearestOwnerKey(currentElement);
573
+ const parent = parentElementGetter.call(currentElement);
574
+
575
+ if (elmOwnerKey === hostKey) {
576
+ // we have reached an element inside the host's template, and only if
577
+ // that element is an slot, then the node is considered slotted
578
+ return isSlotElement(currentElement);
579
+ } else if (parent === host) {
580
+ return false;
581
+ } else if (!isNull(parent) && getNodeNearestOwnerKey(parent) !== elmOwnerKey) {
582
+ // we are crossing a boundary of some sort since the elm and its parent
583
+ // have different owner key. for slotted elements, this is possible
584
+ // if the parent happens to be a slot.
585
+ if (isSlotElement(parent)) {
586
+ /**
587
+ * the slot parent might be allocated inside another slot, think of:
588
+ * <x-root> (<--- root element)
589
+ * <x-parent> (<--- own by x-root)
590
+ * <x-child> (<--- own by x-root)
591
+ * <slot> (<--- own by x-child)
592
+ * <slot> (<--- own by x-parent)
593
+ * <div> (<--- own by x-root)
594
+ *
595
+ * while checking if x-parent has the div slotted, we need to traverse
596
+ * up, but when finding the first slot, we skip that one in favor of the
597
+ * most outer slot parent before jumping into its corresponding host.
598
+ */
599
+ currentElement = getNodeOwner(foldSlotElement(parent));
600
+
601
+ if (!isNull(currentElement)) {
602
+ if (currentElement === host) {
603
+ // the slot element is a top level element inside the shadow
604
+ // of a host that was allocated into host in question
605
+ return true;
606
+ } else if (getNodeNearestOwnerKey(currentElement) === hostKey) {
607
+ // the slot element is an element inside the shadow
608
+ // of a host that was allocated into host in question
609
+ return true;
610
+ }
615
611
  }
612
+ } else {
613
+ return false;
614
+ }
615
+ } else {
616
+ currentElement = parent;
616
617
  }
617
- return false;
618
+ }
619
+
620
+ return false;
618
621
  }
622
+
619
623
  function getNodeOwner(node) {
620
- if (!(node instanceof _Node)) {
621
- return null;
622
- }
623
- const ownerKey = getNodeNearestOwnerKey(node);
624
- if (isUndefined(ownerKey)) {
625
- return null;
626
- }
627
- let nodeOwner = node;
628
- // At this point, node is a valid node with owner identity, now we need to find the owner node
629
- // search for a custom element with a VM that owns the first element with owner identity attached to it
630
- while (!isNull(nodeOwner) && getNodeKey(nodeOwner) !== ownerKey) {
631
- nodeOwner = parentNodeGetter.call(nodeOwner);
632
- }
633
- if (isNull(nodeOwner)) {
634
- return null;
635
- }
636
- return nodeOwner;
624
+ if (!(node instanceof _Node)) {
625
+ return null;
626
+ }
627
+
628
+ const ownerKey = getNodeNearestOwnerKey(node);
629
+
630
+ if (isUndefined(ownerKey)) {
631
+ return null;
632
+ }
633
+
634
+ let nodeOwner = node; // At this point, node is a valid node with owner identity, now we need to find the owner node
635
+ // search for a custom element with a VM that owns the first element with owner identity attached to it
636
+
637
+ while (!isNull(nodeOwner) && getNodeKey(nodeOwner) !== ownerKey) {
638
+ nodeOwner = parentNodeGetter.call(nodeOwner);
639
+ }
640
+
641
+ if (isNull(nodeOwner)) {
642
+ return null;
643
+ }
644
+
645
+ return nodeOwner;
637
646
  }
638
647
  function isSyntheticSlotElement(node) {
639
- return isSlotElement(node) && isNodeShadowed(node);
648
+ return isSlotElement(node) && isNodeShadowed(node);
640
649
  }
641
650
  function isSlotElement(node) {
642
- return node instanceof HTMLSlotElement;
651
+ return node instanceof HTMLSlotElement;
643
652
  }
644
653
  function isNodeOwnedBy(owner, node) {
645
- if (process.env.NODE_ENV !== 'production') {
646
- assert.invariant(owner instanceof HTMLElement, `isNodeOwnedBy() should be called with an element as the first argument instead of ${owner}`);
647
- assert.invariant(node instanceof _Node, `isNodeOwnedBy() should be called with a node as the second argument instead of ${node}`);
648
- assert.invariant(compareDocumentPosition.call(node, owner) & DOCUMENT_POSITION_CONTAINS, `isNodeOwnedBy() should never be called with a node that is not a child node of ${owner}`);
649
- }
650
- const ownerKey = getNodeNearestOwnerKey(node);
651
- return isUndefined(ownerKey) || getNodeKey(owner) === ownerKey;
654
+ if (process.env.NODE_ENV !== 'production') {
655
+ assert.invariant(owner instanceof HTMLElement, `isNodeOwnedBy() should be called with an element as the first argument instead of ${owner}`);
656
+ assert.invariant(node instanceof _Node, `isNodeOwnedBy() should be called with a node as the second argument instead of ${node}`);
657
+ assert.invariant(compareDocumentPosition.call(node, owner) & DOCUMENT_POSITION_CONTAINS, `isNodeOwnedBy() should never be called with a node that is not a child node of ${owner}`);
658
+ }
659
+
660
+ const ownerKey = getNodeNearestOwnerKey(node);
661
+
662
+ if (isUndefined(ownerKey)) {
663
+ if (lwcRuntimeFlags.ENABLE_LIGHT_GET_ROOT_NODE_PATCH) {
664
+ // in case of root level light DOM element slotting into a synthetic shadow
665
+ const host = parentNodeGetter.call(node);
666
+
667
+ if (!isNull(host) && isSyntheticSlotElement(host)) {
668
+ return false;
669
+ }
670
+ } // in case of manually inserted elements
671
+
672
+
673
+ return true;
674
+ }
675
+
676
+ return getNodeKey(owner) === ownerKey;
652
677
  }
653
678
  function shadowRootChildNodes(root) {
654
- const elm = getHost(root);
655
- return getAllMatches(elm, arrayFromCollection(childNodesGetter.call(elm)));
679
+ const elm = getHost(root);
680
+ return getAllMatches(elm, arrayFromCollection(childNodesGetter.call(elm)));
656
681
  }
657
682
  function getAllSlottedMatches(host, nodeList) {
658
- const filteredAndPatched = [];
659
- for (let i = 0, len = nodeList.length; i < len; i += 1) {
660
- const node = nodeList[i];
661
- if (!isNodeOwnedBy(host, node) && isNodeSlotted(host, node)) {
662
- ArrayPush.call(filteredAndPatched, node);
663
- }
683
+ const filteredAndPatched = [];
684
+
685
+ for (let i = 0, len = nodeList.length; i < len; i += 1) {
686
+ const node = nodeList[i];
687
+
688
+ if (!isNodeOwnedBy(host, node) && isNodeSlotted(host, node)) {
689
+ ArrayPush.call(filteredAndPatched, node);
664
690
  }
665
- return filteredAndPatched;
691
+ }
692
+
693
+ return filteredAndPatched;
666
694
  }
667
695
  function getFirstSlottedMatch(host, nodeList) {
668
- for (let i = 0, len = nodeList.length; i < len; i += 1) {
669
- const node = nodeList[i];
670
- if (!isNodeOwnedBy(host, node) && isNodeSlotted(host, node)) {
671
- return node;
672
- }
696
+ for (let i = 0, len = nodeList.length; i < len; i += 1) {
697
+ const node = nodeList[i];
698
+
699
+ if (!isNodeOwnedBy(host, node) && isNodeSlotted(host, node)) {
700
+ return node;
673
701
  }
674
- return null;
702
+ }
703
+
704
+ return null;
675
705
  }
676
706
  function getAllMatches(owner, nodeList) {
677
- const filteredAndPatched = [];
678
- for (let i = 0, len = nodeList.length; i < len; i += 1) {
679
- const node = nodeList[i];
680
- const isOwned = isNodeOwnedBy(owner, node);
681
- if (isOwned) {
682
- // Patch querySelector, querySelectorAll, etc
683
- // if element is owned by VM
684
- ArrayPush.call(filteredAndPatched, node);
685
- }
707
+ const filteredAndPatched = [];
708
+
709
+ for (let i = 0, len = nodeList.length; i < len; i += 1) {
710
+ const node = nodeList[i];
711
+ const isOwned = isNodeOwnedBy(owner, node);
712
+
713
+ if (isOwned) {
714
+ // Patch querySelector, querySelectorAll, etc
715
+ // if element is owned by VM
716
+ ArrayPush.call(filteredAndPatched, node);
686
717
  }
687
- return filteredAndPatched;
718
+ }
719
+
720
+ return filteredAndPatched;
688
721
  }
689
722
  function getFirstMatch(owner, nodeList) {
690
- for (let i = 0, len = nodeList.length; i < len; i += 1) {
691
- if (isNodeOwnedBy(owner, nodeList[i])) {
692
- return nodeList[i];
693
- }
723
+ for (let i = 0, len = nodeList.length; i < len; i += 1) {
724
+ if (isNodeOwnedBy(owner, nodeList[i])) {
725
+ return nodeList[i];
694
726
  }
695
- return null;
727
+ }
728
+
729
+ return null;
696
730
  }
697
731
  function shadowRootQuerySelector(root, selector) {
698
- const elm = getHost(root);
699
- const nodeList = arrayFromCollection(querySelectorAll$1.call(elm, selector));
700
- return getFirstMatch(elm, nodeList);
732
+ const elm = getHost(root);
733
+ const nodeList = arrayFromCollection(querySelectorAll$1.call(elm, selector));
734
+ return getFirstMatch(elm, nodeList);
701
735
  }
702
736
  function shadowRootQuerySelectorAll(root, selector) {
703
- const elm = getHost(root);
704
- const nodeList = querySelectorAll$1.call(elm, selector);
705
- return getAllMatches(elm, arrayFromCollection(nodeList));
737
+ const elm = getHost(root);
738
+ const nodeList = querySelectorAll$1.call(elm, selector);
739
+ return getAllMatches(elm, arrayFromCollection(nodeList));
706
740
  }
707
741
  function getFilteredChildNodes(node) {
708
- if (!isSyntheticShadowHost(node) && !isSlotElement(node)) {
709
- // regular element - fast path
710
- const children = childNodesGetter.call(node);
711
- return arrayFromCollection(children);
712
- }
713
- if (isSyntheticShadowHost(node)) {
714
- // we need to get only the nodes that were slotted
715
- const slots = arrayFromCollection(querySelectorAll$1.call(node, 'slot'));
716
- const resolver = getShadowRootResolver(getShadowRoot(node));
717
- // Typescript is inferring the wrong function type for this particular
718
- // overloaded method: https://github.com/Microsoft/TypeScript/issues/27972
719
- // @ts-ignore type-mismatch
720
- return ArrayReduce.call(slots, (seed, slot) => {
721
- if (resolver === getShadowRootResolver(slot)) {
722
- ArrayPush.apply(seed, getFilteredSlotAssignedNodes(slot));
723
- }
724
- return seed;
725
- }, []);
726
- }
727
- else {
728
- // slot element
729
- const children = arrayFromCollection(childNodesGetter.call(node));
730
- const resolver = getShadowRootResolver(node);
731
- return ArrayFilter.call(children, (child) => resolver === getShadowRootResolver(child));
732
- }
742
+ if (!isSyntheticShadowHost(node) && !isSlotElement(node)) {
743
+ // regular element - fast path
744
+ const children = childNodesGetter.call(node);
745
+ return arrayFromCollection(children);
746
+ }
747
+
748
+ if (isSyntheticShadowHost(node)) {
749
+ // we need to get only the nodes that were slotted
750
+ const slots = arrayFromCollection(querySelectorAll$1.call(node, 'slot'));
751
+ const resolver = getShadowRootResolver(getShadowRoot(node)); // Typescript is inferring the wrong function type for this particular
752
+ // overloaded method: https://github.com/Microsoft/TypeScript/issues/27972
753
+ // @ts-ignore type-mismatch
754
+
755
+ return ArrayReduce.call(slots, (seed, slot) => {
756
+ if (resolver === getShadowRootResolver(slot)) {
757
+ ArrayPush.apply(seed, getFilteredSlotAssignedNodes(slot));
758
+ }
759
+
760
+ return seed;
761
+ }, []);
762
+ } else {
763
+ // slot element
764
+ const children = arrayFromCollection(childNodesGetter.call(node));
765
+ const resolver = getShadowRootResolver(node);
766
+ return ArrayFilter.call(children, child => resolver === getShadowRootResolver(child));
767
+ }
733
768
  }
734
769
  function getFilteredSlotAssignedNodes(slot) {
735
- const owner = getNodeOwner(slot);
736
- if (isNull(owner)) {
737
- return [];
738
- }
739
- const childNodes = arrayFromCollection(childNodesGetter.call(slot));
740
- return ArrayFilter.call(childNodes, (child) => !isNodeShadowed(child) || !isNodeOwnedBy(owner, child));
770
+ const owner = getNodeOwner(slot);
771
+
772
+ if (isNull(owner)) {
773
+ return [];
774
+ }
775
+
776
+ const childNodes = arrayFromCollection(childNodesGetter.call(slot));
777
+ return ArrayFilter.call(childNodes, child => !isNodeShadowed(child) || !isNodeOwnedBy(owner, child));
741
778
  }
742
779
 
743
780
  /*
@@ -3962,11 +3999,11 @@ function querySelectorPatched() {
3962
3999
  // element with shadowRoot attached
3963
4000
  const owner = getNodeOwner(this);
3964
4001
 
3965
- if (isNull(owner)) {
3966
- return null;
3967
- } else if (getNodeKey(this)) {
4002
+ if (!isUndefined(getNodeKey(this))) {
3968
4003
  // it is a custom element, and we should then filter by slotted elements
3969
4004
  return getFirstSlottedMatch(this, nodeList);
4005
+ } else if (isNull(owner)) {
4006
+ return null;
3970
4007
  } else {
3971
4008
  // regular element, we should then filter by ownership
3972
4009
  return getFirstMatch(owner, nodeList);
@@ -4013,11 +4050,11 @@ function getFilteredArrayOfNodes(context, unfilteredNodes, shadowDomSemantic) {
4013
4050
  // element with shadowRoot attached
4014
4051
  const owner = getNodeOwner(context);
4015
4052
 
4016
- if (isNull(owner)) {
4017
- filtered = [];
4018
- } else if (getNodeKey(context)) {
4053
+ if (!isUndefined(getNodeKey(context))) {
4019
4054
  // it is a custom element, and we should then filter by slotted elements
4020
4055
  filtered = getAllSlottedMatches(context, unfilteredNodes);
4056
+ } else if (isNull(owner)) {
4057
+ filtered = [];
4021
4058
  } else {
4022
4059
  // regular element, we should then filter by ownership
4023
4060
  filtered = getAllMatches(owner, unfilteredNodes);
@@ -5133,4 +5170,4 @@ if (process.env.NODE_ENV !== 'production' && typeof __karma__ !== 'undefined') {
5133
5170
  }));
5134
5171
  });
5135
5172
  }
5136
- /** version: 2.23.6 */
5173
+ /** version: 2.25.0 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lwc/synthetic-shadow",
3
- "version": "2.23.6",
3
+ "version": "2.25.0",
4
4
  "description": "Synthetic Shadow Root for LWC",
5
5
  "homepage": "https://lwc.dev/",
6
6
  "repository": {
@@ -36,8 +36,8 @@
36
36
  "access": "public"
37
37
  },
38
38
  "devDependencies": {
39
- "@lwc/features": "2.23.6",
40
- "@lwc/shared": "2.23.6"
39
+ "@lwc/features": "2.25.0",
40
+ "@lwc/shared": "2.25.0"
41
41
  },
42
42
  "nx": {
43
43
  "targets": {