-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Add shadow dom support #1805
Open
43081j
wants to merge
3
commits into
slab:develop
Choose a base branch
from
43081j:selection-document
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add shadow dom support #1805
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -41,6 +41,47 @@ describe('Selection', function() { | |
}); | ||
}); | ||
|
||
describe('shadow root', function() { | ||
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. @jhchen am i ok to just disable these where |
||
// Some browsers don't support shadow DOM | ||
if (!document.head.attachShadow) { | ||
return; | ||
} | ||
|
||
let container; | ||
let root; | ||
|
||
beforeEach(function() { | ||
root = document.createElement('div'); | ||
root.attachShadow({ mode: 'open' }); | ||
root.shadowRoot.innerHTML = '<div></div>'; | ||
|
||
document.body.appendChild(root); | ||
|
||
container = root.shadowRoot.firstChild; | ||
}); | ||
|
||
afterEach(function() { | ||
document.body.removeChild(root); | ||
}); | ||
|
||
it('getRange()', function() { | ||
const selection = this.initialize(Selection, '<p>0123</p>', container); | ||
selection.setNativeRange(container.firstChild.firstChild, 1); | ||
const [range] = selection.getRange(); | ||
expect(range.index).toEqual(1); | ||
expect(range.length).toEqual(0); | ||
}); | ||
|
||
it('setRange()', function() { | ||
const selection = this.initialize(Selection, '', container); | ||
const expected = new Range(0); | ||
selection.setRange(expected); | ||
const [range] = selection.getRange(); | ||
expect(range).toEqual(expected); | ||
expect(selection.hasFocus()).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('getRange()', function() { | ||
it('empty document', function() { | ||
const selection = this.initialize(Selection, ''); | ||
|
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
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.
@jhchen we could possible iterate through
EMITTERS
here, looking for any with acontainer
which is no longer in the DOM tree. this isn't straight forward, though, becausedocument.body.contains(node)
is false for nodes in shadow trees. we would have to go up the tree (getRootNode
) until we reach a node which is indocument
, if ever.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.
ah this won't work, we don't have any idea what
container
is at this point