@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.
- package/dist/synthetic-shadow.js +205 -168
- package/package.json +3 -3
package/dist/synthetic-shadow.js
CHANGED
@@ -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.
|
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.
|
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
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
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
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
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
|
-
|
618
|
+
}
|
619
|
+
|
620
|
+
return false;
|
618
621
|
}
|
622
|
+
|
619
623
|
function getNodeOwner(node) {
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
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
|
-
|
648
|
+
return isSlotElement(node) && isNodeShadowed(node);
|
640
649
|
}
|
641
650
|
function isSlotElement(node) {
|
642
|
-
|
651
|
+
return node instanceof HTMLSlotElement;
|
643
652
|
}
|
644
653
|
function isNodeOwnedBy(owner, node) {
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
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
|
-
|
655
|
-
|
679
|
+
const elm = getHost(root);
|
680
|
+
return getAllMatches(elm, arrayFromCollection(childNodesGetter.call(elm)));
|
656
681
|
}
|
657
682
|
function getAllSlottedMatches(host, nodeList) {
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
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
|
-
|
691
|
+
}
|
692
|
+
|
693
|
+
return filteredAndPatched;
|
666
694
|
}
|
667
695
|
function getFirstSlottedMatch(host, nodeList) {
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
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
|
-
|
702
|
+
}
|
703
|
+
|
704
|
+
return null;
|
675
705
|
}
|
676
706
|
function getAllMatches(owner, nodeList) {
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
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
|
-
|
718
|
+
}
|
719
|
+
|
720
|
+
return filteredAndPatched;
|
688
721
|
}
|
689
722
|
function getFirstMatch(owner, nodeList) {
|
690
|
-
|
691
|
-
|
692
|
-
|
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
|
-
|
727
|
+
}
|
728
|
+
|
729
|
+
return null;
|
696
730
|
}
|
697
731
|
function shadowRootQuerySelector(root, selector) {
|
698
|
-
|
699
|
-
|
700
|
-
|
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
|
-
|
704
|
-
|
705
|
-
|
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
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
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
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
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 (
|
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 (
|
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.
|
5173
|
+
/** version: 2.25.0 */
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lwc/synthetic-shadow",
|
3
|
-
"version": "2.
|
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.
|
40
|
-
"@lwc/shared": "2.
|
39
|
+
"@lwc/features": "2.25.0",
|
40
|
+
"@lwc/shared": "2.25.0"
|
41
41
|
},
|
42
42
|
"nx": {
|
43
43
|
"targets": {
|