-
Notifications
You must be signed in to change notification settings - Fork 789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(context): allow selecting shadow DOM nodes #3798
Changes from 1 commit
be9554b
56b91bc
80c0ffd
ecbc232
8cd13d0
b58beb1
5c99df3
0a51dca
9856f70
de63ccf
b8a6fd3
1c395c5
0e58343
09a859a
4f7aad3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,33 +7,25 @@ | |
* @return {Boolean} Whether `vNode` contains `otherVNode` | ||
*/ | ||
export default function contains(vNode, otherVNode) { | ||
/*eslint no-bitwise: 0*/ | ||
if (vNode.shadowId || otherVNode.shadowId) { | ||
do { | ||
if (vNode.shadowId === otherVNode.shadowId) { | ||
return true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was wrong. We never caught it because |
||
} | ||
otherVNode = otherVNode.parent; | ||
} while (otherVNode); | ||
return false; | ||
// Native light DOM method | ||
if ( | ||
!vNode.shadowId && | ||
!otherVNode.shadowId && | ||
vNode.actualNode && | ||
typeof vNode.actualNode.contains === 'function' | ||
) { | ||
return vNode.actualNode.contains(otherVNode.actualNode); | ||
} | ||
|
||
if (!vNode.actualNode) { | ||
// fallback for virtualNode only contexts | ||
// @see https://github.com/Financial-Times/polyfill-service/pull/183/files | ||
do { | ||
if (otherVNode === vNode) { | ||
return true; | ||
} | ||
otherVNode = otherVNode.parent; | ||
} while (otherVNode); | ||
} | ||
// Alternative method for shadow DOM / virtual tree tests | ||
do { | ||
if (vNode === otherVNode) { | ||
return true; | ||
} else if (otherVNode.nodeIndex < vNode.nodeIndex) { | ||
WilcoFiers marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this just a short circuit so you don't have to navigate up the entire parent tree? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. jup |
||
return false; | ||
} | ||
otherVNode = otherVNode.parent; | ||
} while (otherVNode); | ||
|
||
if (typeof vNode.actualNode.contains !== 'function') { | ||
const position = vNode.actualNode.compareDocumentPosition( | ||
otherVNode.actualNode | ||
); | ||
return !!(position & 16); | ||
} | ||
return vNode.actualNode.contains(otherVNode.actualNode); | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cannot happen. After normalising, this is always either a node, or an array..