mirror of https://github.com/sveltejs/svelte
update custom-elements tests update hydration tests update js tests update some tests update some tests update some tests update some tests update some tests update some tests update some tests update some tests update some tests update some tests update some tests update some tests update some tests update some tests update some tests update some testspull/1864/head
parent
2231a7eb19
commit
7f3cd0d655
@ -1,13 +1,11 @@
|
|||||||
<p>{foo}</p>
|
<svelte:meta tag="custom-element"/>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export function updateFoo(value) {
|
||||||
tag: 'custom-element',
|
foo = value;
|
||||||
|
}
|
||||||
|
|
||||||
methods: {
|
export let foo;
|
||||||
updateFoo(value) {
|
</script>
|
||||||
this.foo = value;
|
|
||||||
}
|
<p>{foo}</p>
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,13 +1,9 @@
|
|||||||
|
<svelte:meta tag="custom-element"/>
|
||||||
|
|
||||||
<span class='icon'></span>
|
<span class='icon'></span>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.icon::before {
|
.icon::before {
|
||||||
content: '\ff'
|
content: '\ff'
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
tag: 'custom-element'
|
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,7 +1,7 @@
|
|||||||
<h1>Hello {name}!</h1>
|
<svelte:meta tag="custom-element"/>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export let name;
|
||||||
tag: 'custom-element'
|
</script>
|
||||||
};
|
|
||||||
</script>
|
<h1>Hello {name}!</h1>
|
@ -1,13 +1,7 @@
|
|||||||
<button on:click='set({ count: count + 1 })'>count: {count}</button>
|
<svelte:meta tag="my-counter"/>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export let count = 0;
|
||||||
tag: 'my-counter',
|
</script>
|
||||||
|
|
||||||
data() {
|
<button on:click='{() => count += 1}'>count: {count}</button>
|
||||||
return {
|
|
||||||
count: 0
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,12 +1,10 @@
|
|||||||
<Counter bind:count/>
|
<svelte:meta tag="my-app"/>
|
||||||
<p>clicked {count} times</p>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Counter from './Counter.html';
|
import Counter from './Counter.html';
|
||||||
|
|
||||||
export default {
|
export let count;
|
||||||
tag: 'my-app',
|
</script>
|
||||||
|
|
||||||
components: { Counter }
|
<Counter bind:count/>
|
||||||
};
|
<p>clicked {count} times</p>
|
||||||
</script>
|
|
@ -1,13 +1,9 @@
|
|||||||
|
<svelte:meta tag="custom-element"/>
|
||||||
|
|
||||||
<p>styled</p>
|
<p>styled</p>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
p {
|
p {
|
||||||
color: red;
|
color: red;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
tag: 'custom-element'
|
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,7 +1,7 @@
|
|||||||
<h1>Hello {name}!</h1>
|
<svelte:meta tag="custom-element"/>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export let name;
|
||||||
tag: 'custom-element'
|
</script>
|
||||||
};
|
|
||||||
</script>
|
<h1>Hello {name}!</h1>
|
@ -1,8 +1,9 @@
|
|||||||
<p>foo: {foo}</p>
|
<svelte:meta tag="my-app"/>
|
||||||
<p>bar: {bar}</p>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export let foo;
|
||||||
tag: 'my-app'
|
export let bar;
|
||||||
};
|
</script>
|
||||||
</script>
|
|
||||||
|
<p>foo: {foo}</p>
|
||||||
|
<p>bar: {bar}</p>
|
@ -1,9 +1,12 @@
|
|||||||
|
<svelte:meta tag="my-app"/>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
import { onmount } from 'svelte';
|
||||||
tag: 'my-app',
|
|
||||||
|
export let wasCreated;
|
||||||
oncreate() {
|
|
||||||
this.wasCreated = true;
|
onmount(() => {
|
||||||
}
|
wasCreated = true;
|
||||||
};
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
<my-widget class="foo" {items}/>
|
<svelte:meta tag="custom-element"/>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import './my-widget.html';
|
import './my-widget.html';
|
||||||
|
|
||||||
export default {
|
export let items = ['a', 'b', 'c'];
|
||||||
tag: 'custom-element',
|
</script>
|
||||||
|
|
||||||
data() {
|
<my-widget class="foo" {items}/>
|
||||||
return {
|
|
||||||
items: ['a', 'b', 'c']
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,14 +1,8 @@
|
|||||||
<p>{items.length} items</p>
|
<svelte:meta tag="my-widget"/>
|
||||||
<p>{items.join(', ')}</p>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export let items = [];
|
||||||
tag: 'my-widget',
|
</script>
|
||||||
|
|
||||||
data() {
|
<p>{items.length} items</p>
|
||||||
return {
|
<p>{items.join(', ')}</p>
|
||||||
items: []
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,13 +1,7 @@
|
|||||||
<div>
|
|
||||||
<Nested/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Nested from './Nested.html';
|
import Nested from './Nested.html';
|
||||||
|
</script>
|
||||||
|
|
||||||
export default {
|
<div>
|
||||||
components: {
|
<Nested/>
|
||||||
Nested
|
</div>
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,11 +1,5 @@
|
|||||||
<Nested/>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Nested from './Nested.html';
|
import Nested from './Nested.html';
|
||||||
|
</script>
|
||||||
|
|
||||||
export default {
|
<Nested/>
|
||||||
components: {
|
|
||||||
Nested
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,4 +1,4 @@
|
|||||||
<button on:click='set({ clicked: true })'>click me</button>
|
<button on:click='{() => clicked = true}'>click me</button>
|
||||||
|
|
||||||
{#if clicked}
|
{#if clicked}
|
||||||
<p>clicked!</p>
|
<p>clicked!</p>
|
||||||
|
@ -1,23 +1,19 @@
|
|||||||
<a href="#" use:link>Test</a>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
function link(node) {
|
||||||
actions: {
|
|
||||||
link(node) {
|
function onClick(event) {
|
||||||
|
event.preventDefault();
|
||||||
function onClick(event) {
|
history.pushState(null, null, event.target.href);
|
||||||
event.preventDefault();
|
}
|
||||||
history.pushState(null, null, event.target.href);
|
|
||||||
}
|
|
||||||
|
|
||||||
node.addEventListener('click', onClick);
|
node.addEventListener('click', onClick);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
destroy() {
|
destroy() {
|
||||||
node.removeEventListener('click', onClick);
|
node.removeEventListener('click', onClick);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<a href="#" use:link>Test</a>
|
@ -1,9 +1,5 @@
|
|||||||
<Nested foo={[1, 2, 3]}/>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
const Nested = window.Nested;
|
||||||
components: {
|
</script>
|
||||||
Nested: window.Nested
|
|
||||||
}
|
<Nested foo={[1, 2, 3]}/>
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,10 +1,7 @@
|
|||||||
<Nested foo='bar'/>
|
<svelte:meta immutable/>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
const Nested = window.Nested;
|
||||||
immutable: true,
|
</script>
|
||||||
components: {
|
|
||||||
Nested: window.Nested
|
<Nested foo='bar'/>
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,9 +1,5 @@
|
|||||||
<Nested foo='bar'/>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
const Nested = window.Nested;
|
||||||
components: {
|
</script>
|
||||||
Nested: window.Nested
|
|
||||||
}
|
<Nested foo='bar'/>
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,9 +1,5 @@
|
|||||||
<Nested foo='bar'/>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
const Nested = window.Nested;
|
||||||
components: {
|
</script>
|
||||||
Nested: window.Nested
|
|
||||||
}
|
<Nested foo='bar'/>
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,8 +1,11 @@
|
|||||||
<script>
|
<script>
|
||||||
export default {
|
export let x;
|
||||||
computed: {
|
|
||||||
a: ({ x }) => x * 2,
|
function a() {
|
||||||
b: ({ x }) => x * 3
|
return x * 2;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
function b() {
|
||||||
|
return x * 3;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
@ -1,11 +1,9 @@
|
|||||||
<script>
|
<script>
|
||||||
export default {
|
import { onmount } from 'svelte';
|
||||||
data: () => ({
|
|
||||||
foo: 'bar'
|
|
||||||
}),
|
|
||||||
|
|
||||||
oncreate() {
|
export let foo = 'bar';
|
||||||
alert(JSON.stringify(data()));
|
|
||||||
}
|
onmount(() => {
|
||||||
};
|
alert(JSON.stringify(data()));
|
||||||
|
});
|
||||||
</script>
|
</script>
|
@ -1,12 +1,12 @@
|
|||||||
|
<script>
|
||||||
|
export let foo;
|
||||||
|
|
||||||
|
function bar() {
|
||||||
|
return foo * 2;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
{Math.max(0, foo)}
|
{Math.max(0, foo)}
|
||||||
{bar}
|
{bar()}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
computed: {
|
|
||||||
bar: ({ foo }) => foo * 2
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,2 +1,2 @@
|
|||||||
<div data-foo='bar'/>
|
<div data-foo='bar'/>
|
||||||
<div data-foo='{bar}'/>
|
<div data-foo='{bar}'/>
|
@ -1,2 +1,2 @@
|
|||||||
<div data-foo='bar'/>
|
<div data-foo='bar'/>
|
||||||
<div data-foo='{bar}'/>
|
<div data-foo='{bar}'/>
|
Before Width: | Height: | Size: 57 B After Width: | Height: | Size: 56 B |
@ -1,9 +1 @@
|
|||||||
<LazyLoad load="{() => import('./Foo.html')}"/>
|
<LazyLoad load="{() => import('./Foo.html')}"/>
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
components: {
|
|
||||||
LazyLoad
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,23 +1,21 @@
|
|||||||
{#each things as thing (thing.id)}
|
|
||||||
<div animate:foo>{thing.name}</div>
|
|
||||||
{/each}
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export let things;
|
||||||
animations: {
|
|
||||||
foo(node, animation, params) {
|
function foo(node, animation, params) {
|
||||||
const dx = animation.from.left - animation.to.left;
|
const dx = animation.from.left - animation.to.left;
|
||||||
const dy = animation.from.top - animation.to.top;
|
const dy = animation.from.top - animation.to.top;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
delay: params.delay,
|
delay: params.delay,
|
||||||
duration: 100,
|
duration: 100,
|
||||||
tick: (t, u) => {
|
tick: (t, u) => {
|
||||||
node.dx = u * dx;
|
node.dx = u * dx;
|
||||||
node.dy = u * dy;
|
node.dy = u * dy;
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#each things as thing (thing.id)}
|
||||||
|
<div animate:foo>{thing.name}</div>
|
||||||
|
{/each}
|
@ -1,16 +1,13 @@
|
|||||||
<button on:foo='foo( bar )'>foo</button>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export let bar;
|
||||||
methods: {
|
|
||||||
foo ( bar ) {
|
function handleFoo(bar) {
|
||||||
console.log( bar );
|
console.log( bar );
|
||||||
}
|
}
|
||||||
},
|
|
||||||
events: {
|
function foo(node, callback) {
|
||||||
foo ( node, callback ) {
|
// code goes here
|
||||||
// code goes here
|
}
|
||||||
}
|
</script>
|
||||||
}
|
|
||||||
};
|
<button on:foo='{() => handleFoo( bar )}'>foo</button>
|
||||||
</script>
|
|
@ -1,19 +1,15 @@
|
|||||||
<div on:touchstart="handleTouchstart()">
|
|
||||||
<button on:click|stopPropagation|preventDefault="handleClick()">click me</button>
|
|
||||||
<button on:click|once|capture="handleClick()">or me</button>
|
|
||||||
<button on:click|capture="handleClick()">or me!</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
function handleTouchstart() {
|
||||||
methods: {
|
// ...
|
||||||
handleTouchstart() {
|
}
|
||||||
// ...
|
|
||||||
},
|
function handleClick() {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
handleClick() {
|
<div on:touchstart="{handleTouchstart}">
|
||||||
// ...
|
<button on:click|stopPropagation|preventDefault="{handleClick}">click me</button>
|
||||||
}
|
<button on:click|once|capture="{handleClick}">or me</button>
|
||||||
}
|
<button on:click|capture="{handleClick}">or me!</button>
|
||||||
};
|
</div>
|
||||||
</script>
|
|
@ -1 +1 @@
|
|||||||
<audio bind:buffered bind:seekable bind:played bind:currentTime bind:duration bind:paused bind:volume/>
|
<audio bind:buffered bind:seekable bind:played bind:currentTime bind:duration bind:paused bind:volume/>
|
@ -1,13 +1,6 @@
|
|||||||
<Imported/>
|
|
||||||
<NonImported/>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Imported from 'Imported.html';
|
import Imported from 'Imported.html';
|
||||||
|
</script>
|
||||||
|
|
||||||
export default {
|
<Imported/>
|
||||||
components: {
|
<NonImported/>
|
||||||
Imported,
|
|
||||||
NonImported
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,18 +1,9 @@
|
|||||||
<script>
|
<script scope="shared">
|
||||||
export default {
|
export const SOME_CONSTANT = 42;
|
||||||
methods: {
|
|
||||||
foo ( bar ) {
|
|
||||||
console.log( bar );
|
|
||||||
}
|
|
||||||
},
|
|
||||||
setup: (Component) => {
|
|
||||||
Component.SOME_CONSTANT = 42;
|
|
||||||
Component.factory = function (target) {
|
|
||||||
return new Component({
|
|
||||||
target: target
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Component.prototype.foo( 'baz' );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export function foo(bar) {
|
||||||
|
console.log( bar );
|
||||||
|
}
|
||||||
|
</script>
|
@ -1,27 +1,25 @@
|
|||||||
|
<script scope="shared">
|
||||||
|
export function preload(input) {
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
import { ondestroy, onmount } from 'svelte';
|
||||||
oncreate() {
|
|
||||||
console.log('oncreate');
|
|
||||||
},
|
|
||||||
|
|
||||||
ondestroy() {
|
onmount(() => {
|
||||||
console.log('ondestroy');
|
console.log('oncreate');
|
||||||
},
|
});
|
||||||
|
|
||||||
methods: {
|
ondestroy(() => {
|
||||||
foo() {
|
console.log('ondestroy');
|
||||||
console.log('foo');
|
});
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
events: {
|
function foo() {
|
||||||
swipe(node, callback) {
|
console.log('foo');
|
||||||
// TODO implement
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
preload(input) {
|
function swipe(node, callback) {
|
||||||
return output;
|
// TODO implement
|
||||||
}
|
}
|
||||||
};
|
|
||||||
</script>
|
</script>
|
@ -1,3 +1,3 @@
|
|||||||
<div>content</div>
|
<div>content</div>
|
||||||
<!-- comment -->
|
<!-- comment -->
|
||||||
<div>more content</div>
|
<div>more content</div>
|
@ -1,21 +1,20 @@
|
|||||||
<h1 use:insert="display ? `Hello ${target}` : ''"></h1>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export let display;
|
||||||
actions: {
|
export let target;
|
||||||
insert(node, text) {
|
|
||||||
|
function insert(node, text) {
|
||||||
|
|
||||||
function onClick() {
|
function onClick() {
|
||||||
node.textContent = text;
|
node.textContent = text;
|
||||||
}
|
}
|
||||||
node.addEventListener('click', onClick);
|
node.addEventListener('click', onClick);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
destroy() {
|
destroy() {
|
||||||
node.removeEventListener('click', onClick);
|
node.removeEventListener('click', onClick);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<h1 use:insert="{display ? `Hello ${target}` : ''}"></h1>
|
@ -1,22 +1,20 @@
|
|||||||
<button use:foo>{x}</button>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export let x;
|
||||||
actions: {
|
|
||||||
foo(node) {
|
function foo(node) {
|
||||||
let x = 0;
|
let x = 0;
|
||||||
|
|
||||||
const handler = () => this.set({ x: x++ });
|
const handler = () => x = x++;
|
||||||
|
|
||||||
node.addEventListener('click', handler);
|
node.addEventListener('click', handler);
|
||||||
handler();
|
handler();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
destroy() {
|
destroy() {
|
||||||
node.removeEventListener('click', handler);
|
node.removeEventListener('click', handler);
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
};
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<button use:foo>{x}</button>
|
@ -1,52 +1,44 @@
|
|||||||
<button use:tooltip="tooltip">action</button>
|
|
||||||
<svelte:window on:keydown="checkForCtrl(event)" on:keyup="checkForCtrl(event)"/>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export let tooltip = 'Perform an Action';
|
||||||
data() {
|
|
||||||
return { tooltip: 'Perform an Action' };
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
function checkForCtrl(event) {
|
||||||
checkForCtrl(event) {
|
if (event.ctrlKey) {
|
||||||
if (event.ctrlKey) {
|
tooltip = 'Perform an augmented Action';
|
||||||
this.set({ tooltip: 'Perform an augmented Action' });
|
} else {
|
||||||
} else {
|
tooltip = 'Perform an Action';
|
||||||
this.set({ tooltip: 'Perform an Action' });
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
actions: {
|
function tooltip(node, text) {
|
||||||
tooltip(node, text) {
|
let tooltip = null;
|
||||||
let tooltip = null;
|
|
||||||
|
|
||||||
function onMouseEnter() {
|
function onMouseEnter() {
|
||||||
tooltip = document.createElement('div');
|
tooltip = document.createElement('div');
|
||||||
tooltip.classList.add('tooltip');
|
tooltip.classList.add('tooltip');
|
||||||
tooltip.textContent = text;
|
tooltip.textContent = text;
|
||||||
node.parentNode.appendChild(tooltip);
|
node.parentNode.appendChild(tooltip);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMouseLeave() {
|
function onMouseLeave() {
|
||||||
if (!tooltip) return;
|
if (!tooltip) return;
|
||||||
tooltip.remove();
|
tooltip.remove();
|
||||||
tooltip = null;
|
tooltip = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
node.addEventListener('mouseenter', onMouseEnter);
|
node.addEventListener('mouseenter', onMouseEnter);
|
||||||
node.addEventListener('mouseleave', onMouseLeave);
|
node.addEventListener('mouseleave', onMouseLeave);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
update(text) {
|
update(text) {
|
||||||
if (tooltip) tooltip.textContent = text;
|
if (tooltip) tooltip.textContent = text;
|
||||||
},
|
},
|
||||||
destroy() {
|
destroy() {
|
||||||
node.removeEventListener('mouseenter', onMouseEnter);
|
node.removeEventListener('mouseenter', onMouseEnter);
|
||||||
node.removeEventListener('mouseleave', onMouseLeave);
|
node.removeEventListener('mouseleave', onMouseLeave);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<button use:tooltip="{tooltip}">action</button>
|
||||||
|
<svelte:window on:keydown="{checkForCtrl}" on:keyup="{checkForCtrl}"/>
|
@ -1,34 +1,30 @@
|
|||||||
<button use:tooltip="'Perform an Action'">action</button>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
function tooltip(node, text) {
|
||||||
actions: {
|
let tooltip = null;
|
||||||
tooltip(node, text) {
|
|
||||||
let tooltip = null;
|
|
||||||
|
|
||||||
function onMouseEnter() {
|
function onMouseEnter() {
|
||||||
tooltip = document.createElement('div');
|
tooltip = document.createElement('div');
|
||||||
tooltip.classList.add('tooltip');
|
tooltip.classList.add('tooltip');
|
||||||
tooltip.textContent = text;
|
tooltip.textContent = text;
|
||||||
node.parentNode.appendChild(tooltip);
|
node.parentNode.appendChild(tooltip);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMouseLeave() {
|
function onMouseLeave() {
|
||||||
if (!tooltip) return;
|
if (!tooltip) return;
|
||||||
tooltip.remove();
|
tooltip.remove();
|
||||||
tooltip = null;
|
tooltip = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
node.addEventListener('mouseenter', onMouseEnter);
|
node.addEventListener('mouseenter', onMouseEnter);
|
||||||
node.addEventListener('mouseleave', onMouseLeave);
|
node.addEventListener('mouseleave', onMouseLeave);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
destroy() {
|
destroy() {
|
||||||
node.removeEventListener('mouseenter', onMouseEnter);
|
node.removeEventListener('mouseenter', onMouseEnter);
|
||||||
node.removeEventListener('mouseleave', onMouseLeave);
|
node.removeEventListener('mouseleave', onMouseLeave);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<button use:tooltip="{'Perform an Action'}">action</button>
|
@ -1,19 +1,17 @@
|
|||||||
{#each things as thing (thing.id)}
|
|
||||||
<div animate:flip>{thing.name}</div>
|
|
||||||
{/each}
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export let things;
|
||||||
animations: {
|
|
||||||
flip(node, animation, params) {
|
function flip(node, animation, params) {
|
||||||
const dx = animation.from.left - animation.to.left;
|
const dx = animation.from.left - animation.to.left;
|
||||||
const dy = animation.from.top - animation.to.top;
|
const dy = animation.from.top - animation.to.top;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
duration: 100,
|
duration: 100,
|
||||||
css: (t, u) => `transform: translate(${u + dx}px, ${u * dy}px)`
|
css: (t, u) => `transform: translate(${u + dx}px, ${u * dy}px)`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
</script>
|
||||||
};
|
|
||||||
</script>
|
{#each things as thing (thing.id)}
|
||||||
|
<div animate:flip>{thing.name}</div>
|
||||||
|
{/each}
|
@ -1,23 +1,21 @@
|
|||||||
{#each things as thing, i (thing.id)}
|
|
||||||
<div animate:flip="{delay: i * 10}">{thing.name}</div>
|
|
||||||
{/each}
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export let things;
|
||||||
animations: {
|
|
||||||
flip(node, animation, params) {
|
function flip(node, animation, params) {
|
||||||
const dx = animation.from.left - animation.to.left;
|
const dx = animation.from.left - animation.to.left;
|
||||||
const dy = animation.from.top - animation.to.top;
|
const dy = animation.from.top - animation.to.top;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
delay: params.delay,
|
delay: params.delay,
|
||||||
duration: 100,
|
duration: 100,
|
||||||
tick: (t, u) => {
|
tick: (t, u) => {
|
||||||
node.dx = u * dx;
|
node.dx = u * dx;
|
||||||
node.dy = u * dy;
|
node.dy = u * dy;
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#each things as thing, i (thing.id)}
|
||||||
|
<div animate:flip="{delay: i * 10}">{thing.name}</div>
|
||||||
|
{/each}
|
@ -1,22 +1,20 @@
|
|||||||
{#each things as thing (thing.id)}
|
|
||||||
<div animate:flip>{thing.name}</div>
|
|
||||||
{/each}
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export let things;
|
||||||
animations: {
|
|
||||||
flip(node, animation, params) {
|
function flip(node, animation, params) {
|
||||||
const dx = animation.from.left - animation.to.left;
|
const dx = animation.from.left - animation.to.left;
|
||||||
const dy = animation.from.top - animation.to.top;
|
const dy = animation.from.top - animation.to.top;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
duration: 100,
|
duration: 100,
|
||||||
tick: (t, u) => {
|
tick: (t, u) => {
|
||||||
node.dx = u * dx;
|
node.dx = u * dx;
|
||||||
node.dy = u * dy;
|
node.dy = u * dy;
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#each things as thing (thing.id)}
|
||||||
|
<div animate:flip>{thing.name}</div>
|
||||||
|
{/each}
|
@ -1 +1 @@
|
|||||||
<textarea readonly="{false}"></textarea>
|
<textarea readonly="{false}"></textarea>
|
@ -1 +1 @@
|
|||||||
<textarea readonly="{true}"></textarea>
|
<textarea readonly="{true}"></textarea>
|
@ -1,3 +1,3 @@
|
|||||||
{#each items as item, i}
|
{#each items as item, i}
|
||||||
<div class='{item.foo ? "foo" : ""} {item.bar ? "bar" : ""}'>{i + 1}</div>
|
<div class='{item.foo ? "foo" : ""} {item.bar ? "bar" : ""}'>{i + 1}</div>
|
||||||
{/each}
|
{/each}
|
@ -1 +1 @@
|
|||||||
<div><div title={'foo'}>bar</div></div>
|
<div><div title={'foo'}>bar</div></div>
|
@ -1 +1 @@
|
|||||||
<span title='{"\"foo\""}'>foo</span>
|
<span title='{"\"foo\""}'>foo</span>
|
@ -1,2 +1,2 @@
|
|||||||
<div class='{class}'></div>{123}
|
<div class='{class}'></div>{123}
|
||||||
<div class='{ class }'></div>{ 123 }
|
<div class='{ class }'></div>{ 123 }
|
@ -1,9 +1,5 @@
|
|||||||
<div {id}/>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export let id = 'foo';
|
||||||
data: () => ({
|
|
||||||
id: 'foo'
|
|
||||||
})
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<div {id}/>
|
@ -1,9 +1,5 @@
|
|||||||
<div style='color: {color};'>{color}</div>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export let color = 'red';
|
||||||
data: () => ({
|
|
||||||
color: 'red'
|
|
||||||
})
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<div style='color: {color};'>{color}</div>
|
Before Width: | Height: | Size: 31 B After Width: | Height: | Size: 30 B |
@ -1 +1 @@
|
|||||||
<div class=''></div>
|
<div class=''></div>
|
@ -1,11 +1,5 @@
|
|||||||
<Component value="10px"/>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Component from './Component.html';
|
import Component from './Component.html';
|
||||||
|
|
||||||
export default {
|
|
||||||
components: {
|
|
||||||
Component
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<Component value="10px"/>
|
@ -1,2 +1,2 @@
|
|||||||
<input type='radio' bind:group='foo' value='{false}'>
|
<input type='radio' bind:group='foo' value='{false}'>
|
||||||
<input type='radio' bind:group='foo' value='{true}'>
|
<input type='radio' bind:group='foo' value='{true}'>
|
@ -1 +1 @@
|
|||||||
<textarea readonly></textarea>
|
<textarea readonly></textarea>
|
@ -1 +1 @@
|
|||||||
<div class='foo'></div>
|
<div class='foo'></div>
|
@ -1,13 +1,9 @@
|
|||||||
{#await promise then value}
|
|
||||||
<Foo {value} />
|
|
||||||
{/await}
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Foo from './Foo.html';
|
import Foo from './Foo.html';
|
||||||
|
|
||||||
export default {
|
export let promise;
|
||||||
components: {
|
</script>
|
||||||
Foo
|
|
||||||
}
|
{#await promise then value}
|
||||||
};
|
<Foo {value} />
|
||||||
</script>
|
{/await}
|
@ -1,7 +1,7 @@
|
|||||||
{#await thePromise}
|
{#await thePromise}
|
||||||
<p>loading...</p>
|
<p>loading...</p>
|
||||||
{:then theValue}
|
{:then theValue}
|
||||||
<button ref:button on:click='set({ clicked: theValue })'>click me</button>
|
<button ref:button on:click='{() => clicked = theValue}'>click me</button>
|
||||||
{:catch theError}
|
{:catch theError}
|
||||||
<p>oh no! {theError.message}</p>
|
<p>oh no! {theError.message}</p>
|
||||||
{/await}
|
{/await}
|
@ -1,2 +1,2 @@
|
|||||||
<audio bind:currentTime='t' bind:duration='d' bind:paused bind:volume='v'
|
<audio bind:currentTime='t' bind:duration='d' bind:paused bind:volume='v'
|
||||||
src='music.mp3'></audio>
|
src='music.mp3'></audio>
|
@ -1,27 +1,22 @@
|
|||||||
|
<script>
|
||||||
|
export let letters = [
|
||||||
|
'a',
|
||||||
|
'b',
|
||||||
|
'c'
|
||||||
|
];
|
||||||
|
export let selected = {
|
||||||
|
letter: ''
|
||||||
|
};
|
||||||
|
|
||||||
|
function uppercase() {
|
||||||
|
return letters.map(x => x.toUpperCase());
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<select bind:value="selected.letter">
|
<select bind:value="selected.letter">
|
||||||
{#each uppercase as letter}
|
{#each uppercase as letter}
|
||||||
<option value="{letter}">{letter}</option>
|
<option value="{letter}">{letter}</option>
|
||||||
{/each}
|
{/each}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
{selected.letter}
|
{selected.letter}
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
letters: [
|
|
||||||
'a',
|
|
||||||
'b',
|
|
||||||
'c'
|
|
||||||
],
|
|
||||||
selected: {
|
|
||||||
letter: ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed:{
|
|
||||||
uppercase: ({ letters }) => letters.map(x => x.toUpperCase())
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,15 +1,13 @@
|
|||||||
|
<script>
|
||||||
|
export let items;
|
||||||
|
|
||||||
|
function numCompleted() {
|
||||||
|
return items.reduce( ( total, item ) => total + ( item.completed ? 1 : 0 ), 0 );
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
{#each items as item}
|
{#each items as item}
|
||||||
<div><input type='checkbox' bind:checked='item.completed'><p>{item.description}</p></div>
|
<div><input type='checkbox' bind:checked='item.completed'><p>{item.description}</p></div>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
<p>{numCompleted} completed</p>
|
<p>{numCompleted()} completed</p>
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
computed: {
|
|
||||||
numCompleted ({ items }) {
|
|
||||||
return items.reduce( ( total, item ) => total + ( item.completed ? 1 : 0 ), 0 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,3 +1,3 @@
|
|||||||
<input type='checkbox' bind:checked bind:indeterminate>
|
<input type='checkbox' bind:checked bind:indeterminate>
|
||||||
<p>checked? {checked}</p>
|
<p>checked? {checked}</p>
|
||||||
<p>indeterminate? {indeterminate}</p>
|
<p>indeterminate? {indeterminate}</p>
|
@ -1,14 +1,11 @@
|
|||||||
{#each cats as cat (cat.name)}
|
|
||||||
<input type="checkbox" bind:checked="cat.checked" on:change="someCheck()">
|
|
||||||
{/each}
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export let cats;
|
||||||
oncreate() {},
|
|
||||||
methods: {
|
function someCheck() {
|
||||||
someCheck() {
|
console.log('Check');
|
||||||
console.log('Check');
|
}
|
||||||
}
|
</script>
|
||||||
},
|
|
||||||
};
|
{#each cats as cat (cat.name)}
|
||||||
</script>
|
<input type="checkbox" bind:checked="cat.checked" on:change="{someCheck}">
|
||||||
|
{/each}
|
@ -1,2 +1,2 @@
|
|||||||
<input type='checkbox' bind:checked='foo'>
|
<input type='checkbox' bind:checked='foo'>
|
||||||
<p>{foo}</p>
|
<p>{foo}</p>
|
@ -1,2 +1,2 @@
|
|||||||
<input type='number' bind:value='count'>
|
<input type='number' bind:value='count'>
|
||||||
<p>{typeof count} {count}</p>
|
<p>{typeof count} {count}</p>
|
@ -1,2 +1,2 @@
|
|||||||
<input type='range' bind:value='count'>
|
<input type='range' bind:value='count'>
|
||||||
<p>{typeof count} {count}</p>
|
<p>{typeof count} {count}</p>
|
@ -1,2 +1,2 @@
|
|||||||
<input type='range' bind:value='count'>
|
<input type='range' bind:value='count'>
|
||||||
<p>{typeof count} {count}</p>
|
<p>{typeof count} {count}</p>
|
@ -1,3 +1,3 @@
|
|||||||
{#each items as item}
|
{#each items as item}
|
||||||
<div><input bind:value='item'><p>{item}</p></div>
|
<div><input bind:value='item'><p>{item}</p></div>
|
||||||
{/each}
|
{/each}
|
@ -1,2 +1,2 @@
|
|||||||
<input bind:value='user[prop]'>
|
<input bind:value='user[prop]'>
|
||||||
<p>hello {user.name}</p>
|
<p>hello {user.name}</p>
|
@ -1,3 +1,3 @@
|
|||||||
{#each items as item}
|
{#each items as item}
|
||||||
<div><input bind:value='item.description'><p>{item.description}</p></div>
|
<div><input bind:value='item.description'><p>{item.description}</p></div>
|
||||||
{/each}
|
{/each}
|
@ -1,2 +1,2 @@
|
|||||||
<input bind:value='user.name'>
|
<input bind:value='user.name'>
|
||||||
<p>hello {user.name}</p>
|
<p>hello {user.name}</p>
|
@ -1,2 +1,2 @@
|
|||||||
<input bind:value='name'>
|
<input bind:value='name'>
|
||||||
<p>hello {name}</p>
|
<p>hello {name}</p>
|
@ -1 +1 @@
|
|||||||
<input bind:value='a' on:input='set({ b: 0 })'>
|
<input bind:value='a' on:input='{() => b = 0}'>
|
@ -1,20 +1,11 @@
|
|||||||
|
<script>
|
||||||
|
export let hidden = true;
|
||||||
|
|
||||||
|
export function toggle() {
|
||||||
|
hidden = !this.get().hidden;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
{#if !hidden}
|
{#if !hidden}
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
hidden: true
|
|
||||||
};
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
toggle () {
|
|
||||||
this.set({
|
|
||||||
hidden: !this.get().hidden
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,2 +1,2 @@
|
|||||||
<textarea bind:value></textarea>
|
<textarea bind:value></textarea>
|
||||||
<p>{value}</p>
|
<p>{value}</p>
|
@ -1,15 +1,13 @@
|
|||||||
<Two bind:foo/>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { onmount } from 'svelte';
|
||||||
import Two from './Two.html';
|
import Two from './Two.html';
|
||||||
|
|
||||||
export default {
|
export let snapshot;
|
||||||
components: {
|
export let foo;
|
||||||
Two
|
|
||||||
},
|
onmount(() => {
|
||||||
|
snapshot = foo;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
oncreate() {
|
<Two bind:foo/>
|
||||||
this.snapshot = this.get().foo;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,15 +1,7 @@
|
|||||||
<script>
|
<script>
|
||||||
export default {
|
export let bar = 1;
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
bar: 1
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
computed: {
|
function foo() {
|
||||||
foo({ bar }) {
|
return bar * 2;
|
||||||
return bar * 2;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
@ -1,9 +1,5 @@
|
|||||||
<One ref:one/>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import One from './One.html';
|
import One from './One.html';
|
||||||
|
</script>
|
||||||
|
|
||||||
export default {
|
<One ref:one/>
|
||||||
components: { One }
|
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,20 +1,12 @@
|
|||||||
<p>bar in Foo: {bar}</p>
|
|
||||||
<p>baz in Foo: {baz}</p>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export let bar = 1;
|
||||||
data() {
|
export let baz = 2;
|
||||||
return {
|
|
||||||
bar: 1,
|
|
||||||
baz: 2
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
export function double() {
|
||||||
double() {
|
bar = bar * 2;
|
||||||
const { bar, baz } = this.get();
|
baz = baz * 2;
|
||||||
this.set({ bar: bar * 2, baz: baz * 2 });
|
}
|
||||||
}
|
</script>
|
||||||
}
|
|
||||||
};
|
<p>bar in Foo: {bar}</p>
|
||||||
</script>
|
<p>baz in Foo: {baz}</p>
|
@ -1,12 +1,9 @@
|
|||||||
<Foo ref:foo bind:bar bind:baz/>
|
|
||||||
<p ref:p>{bar + baz}</p>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Foo from './Foo.html';
|
import Foo from './Foo.html';
|
||||||
|
|
||||||
export default {
|
export let bar;
|
||||||
components: {
|
export let baz;
|
||||||
Foo
|
</script>
|
||||||
}
|
|
||||||
};
|
<Foo ref:foo bind:bar bind:baz/>
|
||||||
</script>
|
<p ref:p>{bar + baz}</p>
|
@ -1 +1 @@
|
|||||||
<div class:one="true"></div>
|
<div class:one="true"></div>
|
@ -1,11 +1,9 @@
|
|||||||
<div class:active="isActive(user)"></div>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export let user;
|
||||||
helpers: {
|
|
||||||
isActive(user) {
|
function isActive(user) {
|
||||||
return user.active;
|
return user.active;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<div class:active="isActive(user)"></div>
|
@ -1,3 +1,3 @@
|
|||||||
{#each things as thing}
|
{#each things as thing}
|
||||||
<div class:selected="selected === thing"></div>
|
<div class:selected="selected === thing"></div>
|
||||||
{/each}
|
{/each}
|
@ -1 +1 @@
|
|||||||
<div class="{ myClass }" class:is-active class:isSelected class:not-used></div>
|
<div class="{ myClass }" class:is-active class:isSelected class:not-used></div>
|
@ -1 +1 @@
|
|||||||
<div class:is-active class:isSelected class:not-used></div>
|
<div class:is-active class:isSelected class:not-used></div>
|
@ -1 +1 @@
|
|||||||
<div class="one" class:two="true" class:three="true"></div>
|
<div class="one" class:two="true" class:three="true"></div>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue