-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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: add back <svelte:document>
#7149
Merged
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bb349a9
add <svelte:document>
hgiesel eb5ac64
Add warnings for svelte:document mouse events
hgiesel a49153b
Add test svelte:document element
hgiesel 5192cbf
Add documentation
hgiesel 816ddd8
Adjust error message
hgiesel 3a51b7c
Squashed commit of the following:
hgiesel bc7ad99
Merge branch 'master' into feat/3310
hgiesel 98c0368
docs, tutorial
dummdidumm 667e43c
Update compiler_warnings.ts
dummdidumm aa88164
fix
dummdidumm 3f80612
forward error output
dummdidumm 47ad382
woops
dummdidumm 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Node from './shared/Node'; | ||
import EventHandler from './EventHandler'; | ||
import Action from './Action'; | ||
import Component from '../Component'; | ||
import TemplateScope from './shared/TemplateScope'; | ||
import { Element } from '../../interfaces'; | ||
import compiler_warnings from '../compiler_warnings'; | ||
|
||
export default class Document extends Node { | ||
type: 'Document'; | ||
handlers: EventHandler[] = []; | ||
actions: Action[] = []; | ||
|
||
constructor(component: Component, parent: Node, scope: TemplateScope, info: Element) { | ||
super(component, parent, scope, info); | ||
|
||
info.attributes.forEach((node) => { | ||
if (node.type === 'EventHandler') { | ||
this.handlers.push(new EventHandler(component, this, scope, node)); | ||
} else if (node.type === 'Action') { | ||
this.actions.push(new Action(component, this, scope, node)); | ||
} else { | ||
// TODO there shouldn't be anything else here... | ||
} | ||
}); | ||
|
||
const handlers_map = new Set(); | ||
|
||
this.handlers.forEach(handler => ( | ||
handlers_map.add(handler.name) | ||
)); | ||
|
||
if (handlers_map.has('mouseenter') || handlers_map.has('mouseleave')) { | ||
component.warn(this, compiler_warnings.avoid_mouse_events_on_document); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Block from '../Block'; | ||
import Wrapper from './shared/Wrapper'; | ||
import { x } from 'code-red'; | ||
import Document from '../../nodes/Document'; | ||
import { Identifier } from 'estree'; | ||
import EventHandler from './Element/EventHandler'; | ||
import add_event_handlers from './shared/add_event_handlers'; | ||
import { TemplateNode } from '../../../interfaces'; | ||
import Renderer from '../Renderer'; | ||
import add_actions from './shared/add_actions'; | ||
|
||
export default class DocumentWrapper extends Wrapper { | ||
node: Document; | ||
handlers: EventHandler[]; | ||
|
||
constructor(renderer: Renderer, block: Block, parent: Wrapper, node: TemplateNode) { | ||
super(renderer, block, parent, node); | ||
this.handlers = this.node.handlers.map(handler => new EventHandler(handler, this)); | ||
} | ||
|
||
render(block: Block, _parent_node: Identifier, _parent_nodes: Identifier) { | ||
add_event_handlers(block, x`@_document`, this.handlers); | ||
add_actions(block, x`@_document`, this.node.actions); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default { | ||
html: '<div></div>', | ||
|
||
async test({ assert, target, window }) { | ||
const visibility = new window.Event('visibilitychange'); | ||
|
||
await window.document.dispatchEvent(visibility); | ||
assert.htmlEqual(target.innerHTML, ` | ||
<div> | ||
<div class="tooltip">Perform an Action</div> | ||
</div> | ||
`); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<script> | ||
let container; | ||
function tooltip(node, text) { | ||
let tooltip = null; | ||
|
||
function onVisibilityChange() { | ||
tooltip = document.createElement('div'); | ||
tooltip.classList.add('tooltip'); | ||
tooltip.textContent = text; | ||
container.appendChild(tooltip); | ||
} | ||
|
||
node.addEventListener('visibilitychange', onVisibilityChange); | ||
|
||
return { | ||
destroy() { | ||
node.removeEventListener('visibilitychange', onVisibilityChange); | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<svelte:document use:tooltip="{'Perform an Action'}" /> | ||
<div bind:this={container} /> |
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.
Similar instead of Similarly (this typo is originally from svelte:body).
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.
That sounds worse to me. Though they're possibly both a bit awkward. Perhaps we should just remove that part and start with "This element..."