Skip to content

Commit 8c099a1

Browse files
committed
Merge remote-tracking branch 'sveltejs/main' into update-up-to-20240216
2 parents f9ef2d3 + 034037f commit 8c099a1

File tree

44 files changed

+851
-727
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+851
-727
lines changed

.github/workflows/node.js.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
node-version: [18.x]
19+
node-version: [20.x]
2020
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
2121

2222
steps:

content/tutorial/01-svelte/02-reactivity/04-updating-arrays-and-objects/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ function addNumber() {
3838

3939
```js
4040
/// no-file
41+
const obj = { foo: { bar: 1 } };
4142
const foo = obj.foo;
42-
foo.bar = 'baz';
43+
foo.bar = 2;
4344
```
4445

4546
`obj.foo.bar` に対するリアクティビティはトリガーされません。もしトリガーしたければ、`obj = obj` を続けて書く必要があります。

content/tutorial/01-svelte/04-logic/05-keyed-each-blocks/README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
title: Keyed each blocks
33
---
44

5-
デフォルトでは、`each` ブロックの値を変更すると、ブロックの *末尾* にアイテムを追加・削除し、変更された値を更新します。これはあなたが望むものではないかもしれません
5+
デフォルトでは、`each` ブロックの値を変更すると、ブロックの *末尾* で DOM ノードが追加・削除され、変更された値が更新されます。これはあなたが期待した動作ではないかもしれません
66

7-
説明するより見ていただいたほうがおわかり頂けるでしょう。'Remove first thing' ボタンを何度かクリックして、何が起きるか確認してください。先頭の `<Thing>` コンポーネントは削除されず、 _末尾の_ DOM ノードが削除されます。そして残りの DOM ノードの `name` の値は更新されますが、絵文字は更新されません。この絵文字は、それぞれの `<Thing>` が作成されるときに固定されているのです。
7+
説明するより見ていただいたほうがおわかり頂けるでしょう。この `<Thing>` コンポーネントでは初期化時に絵文字を定数としてセットしていますが、name は prop として渡されています。
8+
9+
'Remove first thing' ボタンを何回かクリックすると、以下のことが発生します:
10+
11+
1. 一番最後のコンポーネントが削除される
12+
2. 残りの DOM ノードの `name` の値が更新されるが、絵文字は更新されず、それぞれの `<Thing>` が作成されたときのまま固定されている
813

914
代わりに、先頭の `<Thing>` コンポーネントとその DOM ノードだけを削除して、残りには影響を与えないようにしたいと思います。
1015

11-
そのためには、`each` ブロックに一意な識別子 (または"key") を指定します。
16+
そのためには、`each` ブロックの each イテレーションに一意な識別子 (または"key") を指定します。
1217

1318
```svelte
1419
/// file: App.svelte
@@ -17,6 +22,6 @@ title: Keyed each blocks
1722
{/each}
1823
```
1924

20-
ここで、`(thing.id)`*key* であり、コンポーネントが更新されたときに変更するDOMノードを特定する方法を Svelte に伝えます
25+
ここで、`(thing.id)`_key_ であり、値 (この例では `name`) が更新されたときに何を更新するのか Svelte に指示しています
2126

2227
> Svelte は内部的に `Map` を使用しているので、どんなオブジェクトでもキーとして使用できます。つまり `(thing.id)` の代わりに `(thing)` を使うことができます。しかし、文字列または数値を使用する方が一般的に安全です。なぜなら、例えばAPIサーバーからの新しいデータで更新する場合に、参照が等しくなくても同一性が持続することを意味するからです。

content/tutorial/01-svelte/05-events/02-inline-handlers/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ title: Inline handlers
2020
m = { x: e.clientX, y: e.clientY };
2121
}+++}
2222
>
23-
The mouse position is {m.x} x {m.y}
23+
The pointer is at {m.x} x {m.y}
2424
</div>
2525
```
2626

content/tutorial/01-svelte/05-events/06-dom-event-forwarding/app-a/src/lib/App.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
audio.src = horn;
77
88
function handleClick() {
9+
audio.load();
910
audio.play();
1011
}
1112
</script>

content/tutorial/01-svelte/07-lifecycle/01-onmount/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ title: onMount
1414
</script>
1515
```
1616

17-
そして、コンポーネントがマウントされるときに実行する関数を追加しましょう:
17+
そして、コンポーネントがマウントされるときに実行されるコールバックを追加しましょう:
1818

1919
```svelte
2020
/// file: App.svelte

content/tutorial/01-svelte/common/src/routes/+error.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
code
1212
<a
1313
target="_blank"
14-
href="https://httpstatusdogs.com/{$page.status}"
14+
href="https://http.dog/{$page.status}"
1515
>{$page.status}</a
1616
>
1717
</p>

content/tutorial/02-advanced-svelte/01-motion/01-tweens/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: Tweens
66

77
値を設定して DOM が自動的に更新されるのを見るのは最高です。もっと最高なのは?それらの値を *トゥイーン(Tween)* することです。Svelte には、変化を表すアニメーションを用いたスムーズなユーザーインターフェースを構築するためのツールがあります。
88

9-
まず `progress` store を `tweened` 値に変更してみましょう
9+
まず `progress` store を `tweened` store に変更してみましょう
1010

1111
```svelte
1212
/// file: App.svelte

content/tutorial/02-advanced-svelte/01-motion/02-springs/app-a/src/lib/App.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
}}
1212
on:mousedown={() => size.set(30)}
1313
on:mouseup={() => size.set(10)}
14+
role="presentation"
1415
>
1516
<circle
1617
cx={$coords.x}

content/tutorial/02-advanced-svelte/01-motion/02-springs/app-b/src/lib/App.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
}}
1616
on:mousedown={() => size.set(30)}
1717
on:mouseup={() => size.set(10)}
18+
role="presentation"
1819
>
1920
<circle
2021
cx={$coords.x}

content/tutorial/02-advanced-svelte/02-transitions/09-deferred-transitions/app-a/src/lib/App.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
<input
1717
placeholder="what needs to be done?"
1818
on:keydown={(e) => {
19-
if (e.key === 'Enter') {
20-
todos.add(e.currentTarget.value);
21-
e.currentTarget.value = '';
22-
}
19+
if (e.key !== 'Enter') return;
20+
21+
todos.add(e.currentTarget.value);
22+
e.currentTarget.value = '';
2323
}}
2424
/>
2525

content/tutorial/02-advanced-svelte/05-bindings/03-media-elements/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function seek(e) {
6565

6666
`<audio>``<video>` のバインディングの完全なセットは以下の通りです — 7つの _読み取り専用(readonly)_ のバインディング…
6767

68-
- `duration` (readonly) — ビデオの総再生時間 (秒単位)
68+
- `duration` (readonly) — 総再生時間 (秒単位)
6969
- `buffered` (readonly) — `{start, end}` オブジェクトの配列
7070
- `seekable` (readonly) — 同上
7171
- `played` (readonly) — 同上
@@ -75,8 +75,8 @@ function seek(e) {
7575

7676
…と5つの _双方向_ バインディングです:
7777

78-
- `currentTime`ビデオ内の現在のポイント (秒単位)
79-
- `playbackRate`ビデオの再生速度 (`1` が 'normal')
78+
- `currentTime`再生マーカー (playhead) の現在の位置 (秒単位)
79+
- `playbackRate`再生速度を上げるか遅くするか (`1` が 'normal')
8080
- `paused` — これは自明ですね
8181
- `volume` — 0 から 1 の値
8282
- `muted` — boolean で、true はミュートを意味します

content/tutorial/02-advanced-svelte/07-composition/01-slots/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ title: Slots
1515

1616
```svelte
1717
/// file: Card.svelte
18-
<div class="card ">
18+
<div class="card">
1919
+++<slot />+++
2020
</div>
2121
```

content/tutorial/02-advanced-svelte/07-composition/02-named-slots/app-a/src/lib/paper.svg

Lines changed: 2 additions & 2 deletions
Loading

content/tutorial/02-advanced-svelte/09-special-elements/02-svelte-component/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ title: <svelte:component>
2727
{/each}
2828
</select>
2929
30-
+++<svelte:component this={selected.component}/>+++
30+
+++<svelte:component this={selected.component} />+++
3131
```
3232

3333
`this` 値には任意のコンポーネントコンストラクタ、または falsy な値を指定できます。falsy の値を指定した場合、コンポーネントはレンダリングされません。

content/tutorial/02-advanced-svelte/10-module-context/02-module-exports/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ title: Exports
2121
/// file: App.svelte
2222
<script>
2323
import AudioPlayer, +++{ stopAll }+++ from './AudioPlayer.svelte';
24+
import { tracks } from './tracks.js';
2425
</script>
2526
```
2627

content/tutorial/02-advanced-svelte/common/src/routes/+error.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
code
1212
<a
1313
target="_blank"
14-
href="https://httpstatusdogs.com/{$page.status}"
14+
href="https://http.dog/{$page.status}"
1515
>{$page.status}</a
1616
>
1717
</p>

content/tutorial/03-sveltekit/03-loading-data/01-page-data/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ path: /blog
77

88
1. **ルーティング(Routing)** — 受け取ったリクエストにどのルートがマッチするかを判断する
99
2. **ローディング(Loading)** — ルートが必要とするデータを取得する
10-
3. **レンダリング(Rendering)** - (サーバー上で) HTML を生成する、または (ブラウザで) DOMを更新する
10+
3. **レンダリング(Rendering)** (サーバー上で) HTML を生成する、または (ブラウザで) DOMを更新する
1111

1212
これまで、ルーティングとレンダリングがどのように動作するか見てきました。ここではその中間のローディングについて説明します。
1313

content/tutorial/03-sveltekit/04-headers-and-cookies/02-cookies/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function load(+++{ cookies }+++) {
1212
+++const visited = cookies.get('visited');+++
1313

1414
return {
15-
visited
15+
visited: visited === 'true'
1616
};
1717
}
1818
```
@@ -27,7 +27,7 @@ export function load({ cookies }) {
2727
+++cookies.set('visited', 'true', { path: '/' });+++
2828

2929
return {
30-
visited
30+
visited: visited === 'true'
3131
};
3232
}
3333
```
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export function load() {
2-
const visited = false;
2+
const visited = 'false';
33

44
return {
5-
visited
5+
visited: visited === 'true'
66
};
77
}

content/tutorial/03-sveltekit/06-forms/01-the-form-element/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: The <form> element
33
---
44

5-
[Loading Data の章](page-data)では、データをサーバーからブラウザに取得してくる方法を見てきました。時には、その逆方向にデータを送信する必要があります。そこで、web プラットフォームにおけるデータ送信方法である `<form>` の登場です。
5+
[loading data](page-data) の章では、データをサーバーからブラウザに取得してくる方法を見てきました。時には、その逆方向にデータを送信する必要があります。そこで、web プラットフォームにおけるデータ送信方法である `<form>` の登場です。
66

77
todo アプリを作ってみましょう。すでに `src/lib/server/database.js` にセットアップ済みのインメモリデータベースがあり、`src/routes/+page.server.js``load` 関数で [`cookies`](https://kit.svelte.jp/docs/load#cookies) API を使用しているためユーザーごとの todo リストを持つことができるようになっています。ここでは新しい todo を作成するための `<form>` を追加する必要があります。
88

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import * as db from '$lib/server/database.js';
22

33
export function load({ cookies }) {
4-
const id = cookies.get('userid');
4+
let id = cookies.get('userid');
55

66
if (!id) {
7-
cookies.set('userid', crypto.randomUUID(), { path: '/' });
7+
id = crypto.randomUUID();
8+
cookies.set('userid', id, { path: '/' });
89
}
910

1011
return {
11-
todos: db.getTodos(id) ?? []
12+
todos: db.getTodos(id)
1213
};
1314
}

content/tutorial/03-sveltekit/06-forms/01-the-form-element/app-b/src/routes/+page.server.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import * as db from '$lib/server/database.js';
22

33
export function load({ cookies }) {
4-
const id = cookies.get('userid');
4+
let id = cookies.get('userid');
55

66
if (!id) {
7-
cookies.set('userid', crypto.randomUUID(), { path: '/' });
7+
id = crypto.randomUUID();
8+
cookies.set('userid', id, { path: '/' });
89
}
910

1011
return {
11-
todos: db.getTodos(id) ?? []
12+
todos: db.getTodos(id)
1213
};
1314
}
1415

content/tutorial/03-sveltekit/06-forms/02-named-form-actions/app-b/src/routes/+page.server.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import * as db from '$lib/server/database.js';
22

33
export function load({ cookies }) {
4-
const id = cookies.get('userid');
4+
let id = cookies.get('userid');
55

66
if (!id) {
7-
cookies.set('userid', crypto.randomUUID(), { path: '/' });
7+
id = crypto.randomUUID();
8+
cookies.set('userid', id, { path: '/' });
89
}
910

1011
return {
11-
todos: db.getTodos(id) ?? []
12+
todos: db.getTodos(id)
1213
};
1314
}
1415

content/tutorial/03-sveltekit/06-forms/03-form-validation/README.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,24 @@ export const actions = {
8282
+++export let form;+++
8383
</script>
8484

85-
<h1>todos</h1>
86-
87-
+++{#if form?.error}
88-
<p class="error">{form.error}</p>
89-
{/if}+++
90-
91-
<form method="POST" action="?/create">
92-
<label>
93-
add a todo:
94-
<input
95-
name="description"
96-
+++value={form?.description ?? ''}+++
97-
autocomplete="off"
98-
required
99-
/>
100-
</label>
101-
</form>
85+
<div class="centered">
86+
<h1>todos</h1>
87+
88+
+++{#if form?.error}
89+
<p class="error">{form.error}</p>
90+
{/if}+++
91+
92+
<form method="POST" action="?/create">
93+
<label>
94+
add a todo:
95+
<input
96+
name="description"
97+
+++value={form?.description ?? ''}+++
98+
autocomplete="off"
99+
required
100+
/>
101+
</label>
102+
</form>
102103
```
103104
104105
> `fail` でラップしなくても、action から値を返すことができます。例えば、データが保存されたときに 'success!' というメッセージを返すこともできます。それも `form` プロパティを介してアクセスすることができます。

content/tutorial/03-sveltekit/06-forms/03-form-validation/app-b/src/routes/+page.server.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import { fail } from '@sveltejs/kit';
22
import * as db from '$lib/server/database.js';
33

44
export function load({ cookies }) {
5-
const id = cookies.get('userid');
5+
let id = cookies.get('userid');
66

77
if (!id) {
8-
cookies.set('userid', crypto.randomUUID(), { path: '/' });
8+
id = crypto.randomUUID();
9+
cookies.set('userid', id, { path: '/' });
910
}
1011

1112
return {
12-
todos: db.getTodos(id) ?? []
13+
todos: db.getTodos(id)
1314
};
1415
}
1516

content/tutorial/03-sveltekit/06-forms/04-progressive-enhancement/app-b/src/routes/+page.svelte

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,12 @@
6666
opacity: 0.5;
6767
transition: opacity 0.2s;
6868
}
69+
70+
button:hover {
71+
opacity: 1;
72+
}
73+
74+
.saving {
75+
opacity: 0.5;
76+
}
6977
</style>

content/tutorial/03-sveltekit/06-forms/05-customizing-use-enhance/app-b/src/routes/+page.server.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import { fail } from '@sveltejs/kit';
22
import * as db from '$lib/server/database.js';
33

44
export function load({ cookies }) {
5-
const id = cookies.get('userid');
5+
let id = cookies.get('userid');
66

77
if (!id) {
8-
cookies.set('userid', crypto.randomUUID(), { path: '/' });
8+
id = crypto.randomUUID();
9+
cookies.set('userid', id, { path: '/' });
910
}
1011

1112
return {
12-
todos: db.getTodos(id) ?? []
13+
todos: db.getTodos(id)
1314
};
1415
}
1516

0 commit comments

Comments
 (0)