-
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
Merged
davidturissini
merged 15 commits into
caridy/proto-chaining-refactor
from
dturissini/dom-prototype-inserting
Oct 11, 2018
Merged
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f41a2f7
feat(engine): dom patching
davidturissini e25eb65
fix(engine): cleanup descriptors
davidturissini 6abb9e3
feat(engine): rebase
davidturissini ca0aeaf
fix(engine): linting
davidturissini d20b0e2
fix(engine): pr feedback
davidturissini 572f8eb
fix(engine): lint
davidturissini c94fa6c
fix(compiler): updated snapshot testing to account for shadow dom
davidturissini ed72e3b
fix(engine): pr feedback
davidturissini 2ed6513
fix(engine): fixing restrictions on custom elements
davidturissini 047a5b8
fix(engine): exposing host (#705)
davidturissini 07d5dfd
fix(engine): review feedback
davidturissini 2727135
fix(engine): integration tests for elementFromPoint
davidturissini 1b23ee4
fix(engine): ie11 elementsFromPoint
davidturissini e860436
fix(engine): feedback
davidturissini 1eabfb7
fix(engine): ts fix
davidturissini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { defineProperties } from "../shared/language"; | ||
import { attachShadow } from "./shadow-root"; | ||
import { attachShadow, getShadowRoot } from "./shadow-root"; | ||
import { addCustomElementEventListener, removeCustomElementEventListener } from "./events"; | ||
|
||
function addEventListenerPatchedValue(this: EventTarget, type: string, listener: EventListener, options?: boolean | AddEventListenerOptions) { | ||
|
@@ -14,6 +14,10 @@ function attachShadowGetter(this: HTMLElement, options: ShadowRootInit): ShadowR | |
return attachShadow(this, options); | ||
} | ||
|
||
function getShadowRootPatchedValue(this: HTMLElement) { | ||
return getShadowRoot(this); | ||
} | ||
|
||
const CustomElementPatchDescriptors: PropertyDescriptorMap = { | ||
attachShadow: { | ||
value: attachShadowGetter, | ||
|
@@ -31,6 +35,11 @@ const CustomElementPatchDescriptors: PropertyDescriptorMap = { | |
configurable: true, | ||
enumerable: true, | ||
}, | ||
shadowRoot: { | ||
value: getShadowRootPatchedValue, | ||
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 should be a getter instead. |
||
configurable: true, | ||
enumerable: true, | ||
} | ||
}; | ||
|
||
export function patchCustomElement(elm: HTMLElement) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,7 @@ 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"; | ||
|
||
|
@@ -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, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.