-
Notifications
You must be signed in to change notification settings - Fork 392
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(engine): dom patching #688
Changes from 10 commits
f41a2f7
e25eb65
6abb9e3
ca0aeaf
d20b0e2
572f8eb
c94fa6c
ed72e3b
2ed6513
047a5b8
07d5dfd
2727135
1b23ee4
e860436
1eabfb7
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,12 +7,14 @@ const { | |
createElementNS, | ||
createTextNode, | ||
createComment, | ||
} = document; | ||
elementsFromPoint, | ||
} = Document.prototype; | ||
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. any particular reason for this change? 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. Not really, just mostly just to match other patterns. |
||
|
||
export { | ||
createElement, | ||
createElementNS, | ||
createTextNode, | ||
createComment, | ||
DocumentPrototypeActiveElement, | ||
elementsFromPoint, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,9 @@ import { | |
getRootNode, | ||
parentNodeGetter, | ||
} from "./node"; | ||
import { ArraySlice, ArraySplice, ArrayIndexOf, create, ArrayPush, isUndefined, isFunction, getOwnPropertyDescriptor, defineProperties, isNull, toString, forEach, defineProperty, isFalse } from "../shared/language"; | ||
import { patchShadowDomTraversalMethods } from "./traverse"; | ||
import { ArraySlice, ArraySplice, ArrayIndexOf, create, ArrayPush, isUndefined, isFunction, getOwnPropertyDescriptor, defineProperties, toString, forEach, defineProperty, isFalse } from "../shared/language"; | ||
import { compareDocumentPosition, DOCUMENT_POSITION_CONTAINED_BY, getNodeOwnerKey, getNodeKey } from "./node"; | ||
import { getHost } from "./shadow-root"; | ||
import { getHost, SyntheticShadowRoot } from "./shadow-root"; | ||
|
||
interface WrappedListener extends EventListener { | ||
placement: EventListenerContext; | ||
|
@@ -33,18 +32,6 @@ const eventCurrentTargetGetter: (this: Event) => Element | null = getOwnProperty | |
const GET_ROOT_NODE_CONFIG_FALSE = { composed: false }; | ||
|
||
const EventPatchDescriptors: PropertyDescriptorMap = { | ||
currentTarget: { | ||
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. very nice! |
||
get(this: Event): EventTarget | null { | ||
const currentTarget: EventTarget = eventCurrentTargetGetter.call(this); | ||
if (isNull(currentTarget) || isUndefined(getNodeOwnerKey(currentTarget as Node))) { | ||
// event is already beyond the boundaries of our controlled shadow roots | ||
return currentTarget; | ||
} | ||
return patchShadowDomTraversalMethods(currentTarget as Element); | ||
}, | ||
enumerable: true, | ||
configurable: true, | ||
}, | ||
target: { | ||
get(this: Event): EventTarget { | ||
const currentTarget: EventTarget = eventCurrentTargetGetter.call(this); | ||
|
@@ -71,7 +58,7 @@ const EventPatchDescriptors: PropertyDescriptorMap = { | |
const eventContext = eventToContextMap.get(this); | ||
// Executing event listener on component, target is always currentTarget | ||
if (eventContext === EventListenerContext.CUSTOM_ELEMENT_LISTENER) { | ||
return patchShadowDomTraversalMethods(currentTarget as Element); | ||
return currentTarget as Element; | ||
} | ||
const currentTargetRootNode = getRootNode.call(currentTarget, GET_ROOT_NODE_CONFIG_FALSE); // x-child | ||
|
||
|
@@ -160,10 +147,7 @@ const EventPatchDescriptors: PropertyDescriptorMap = { | |
* while the event is patched because the component is listening for it internally | ||
* via this.addEventListener('click') in constructor or something similar | ||
*/ | ||
if (isUndefined(getNodeOwnerKey(closestTarget as Node))) { | ||
return closestTarget; | ||
} | ||
return patchShadowDomTraversalMethods(closestTarget as Element); | ||
return closestTarget as Element; | ||
pmdartus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
enumerable: true, | ||
configurable: true, | ||
|
@@ -194,7 +178,7 @@ function getEventMap(elm: HTMLElement): ListenerMap { | |
|
||
const shadowRootEventListenerMap: WeakMap<EventListener, WrappedListener> = new WeakMap(); | ||
|
||
function getWrappedShadowRootListener(sr: ShadowRoot, listener: EventListener): WrappedListener { | ||
function getWrappedShadowRootListener(sr: SyntheticShadowRoot, listener: EventListener): WrappedListener { | ||
if (!isFunction(listener)) { | ||
throw new TypeError(); // avoiding problems with non-valid listeners | ||
} | ||
|
@@ -373,7 +357,7 @@ export function removeCustomElementEventListener(elm: HTMLElement, type: string, | |
detachDOMListener(elm, type, wrappedListener); | ||
} | ||
|
||
export function addShadowRootEventListener(sr: ShadowRoot, type: string, listener: EventListener, options?: boolean | AddEventListenerOptions) { | ||
export function addShadowRootEventListener(sr: SyntheticShadowRoot, type: string, listener: EventListener, options?: boolean | AddEventListenerOptions) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert.invariant(isFunction(listener), `Invalid second argument for this.template.addEventListener() in ${toString(sr)} for event "${type}". Expected an EventListener but received ${listener}.`); | ||
// TODO: issue #420 | ||
|
@@ -390,7 +374,7 @@ export function addShadowRootEventListener(sr: ShadowRoot, type: string, listene | |
attachDOMListener(elm, type, wrappedListener); | ||
} | ||
|
||
export function removeShadowRootEventListener(sr: ShadowRoot, type: string, listener: EventListener, options?: boolean | AddEventListenerOptions) { | ||
export function removeShadowRootEventListener(sr: SyntheticShadowRoot, type: string, listener: EventListener, options?: boolean | AddEventListenerOptions) { | ||
const elm = getHost(sr); | ||
const wrappedListener = getWrappedShadowRootListener(sr, listener); | ||
detachDOMListener(elm, type, wrappedListener); | ||
|
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 should take into consideration the
mode
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.
to match native.