Skip to content

Commit 918ce0f

Browse files
committed
use event attributes
1 parent e9115f2 commit 918ce0f

14 files changed

+122
-116
lines changed

src/lib/components/Modal.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<script>
22
import { onMount } from 'svelte';
33
4+
/** @type {{ onclose?: () => void; children?: import('svelte').Snippet }}*/
5+
let { onclose } = $props();
6+
47
/** @type {HTMLDialogElement} */
58
let modal;
69
@@ -41,7 +44,7 @@
4144
4245
<div class="modal-background" />
4346
44-
<dialog class="modal" tabindex="-1" bind:this={modal} on:close>
47+
<dialog class="modal" tabindex="-1" bind:this={modal} {onclose}>
4548
<slot />
4649
</dialog>
4750

src/routes/tutorial/[slug]/+page.svelte

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
show_editor = true;
112112
}
113113
114-
/** @param {string} name */
114+
/** @param {string | null} name */
115115
function navigate_to_file(name) {
116116
if (name === s.selected_name) return;
117117
@@ -158,7 +158,7 @@
158158
159159
<svelte:window
160160
bind:innerWidth={w}
161-
on:popstate={(e) => {
161+
onpopstate={(e) => {
162162
const q = new URLSearchParams(location.search);
163163
const file = q.get('file');
164164
@@ -181,8 +181,8 @@
181181
bind:sidebar
182182
index={data.index}
183183
exercise={data.exercise}
184-
on:select={(e) => {
185-
navigate_to_file(e.detail.file);
184+
on_select={(file) => {
185+
navigate_to_file(file);
186186
}}
187187
/>
188188
</section>
@@ -199,7 +199,7 @@
199199
>
200200
<section class="navigator" slot="a">
201201
{#if mobile}
202-
<button class="file" on:click={() => (show_filetree = !show_filetree)}>
202+
<button class="file" onclick={() => (show_filetree = !show_filetree)}>
203203
{s.selected_file?.name.replace(
204204
data.exercise.scope.prefix,
205205
data.exercise.scope.name + '/'
@@ -208,8 +208,8 @@
208208
{:else}
209209
<Filetree
210210
exercise={data.exercise}
211-
on:select={(e) => {
212-
select_file(e.detail.name);
211+
on_select={(name) => {
212+
select_file(name);
213213
}}
214214
/>
215215
{/if}
@@ -218,7 +218,7 @@
218218
class="solve"
219219
class:completed
220220
disabled={!data.exercise.has_solution}
221-
on:click={() => {
221+
onclick={() => {
222222
reset_files(Object.values(completed ? data.exercise.a : data.exercise.b));
223223
}}
224224
>
@@ -239,8 +239,8 @@
239239
<Filetree
240240
mobile
241241
exercise={data.exercise}
242-
on:select={(e) => {
243-
navigate_to_file(e.detail.name);
242+
on_select={(name) => {
243+
navigate_to_file(name);
244244
}}
245245
/>
246246
</div>
@@ -259,8 +259,8 @@
259259
260260
<div class="screen-toggle">
261261
<ScreenToggle
262-
on:change={(e) => {
263-
show_editor = e.detail.pressed;
262+
on_change={(pressed) => {
263+
show_editor = pressed;
264264
265265
const url = new URL(location.origin + location.pathname);
266266

src/routes/tutorial/[slug]/Chrome.svelte

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
<script>
2-
import { createEventDispatcher } from 'svelte';
3-
4-
/** @type {{path: string; loading: boolean; href: string | null;}}*/
5-
let { path, loading, href } = $props();
6-
7-
const dispatch = createEventDispatcher();
2+
/** @type {{
3+
* path: string;
4+
* loading: boolean;
5+
* href: string | null;
6+
* on_refresh?: () => void;
7+
* on_change?: (value: string) => void;
8+
* on_toggle_terminal?: () => void;
9+
* }}*/
10+
let { path, loading, href, on_refresh, on_change, on_toggle_terminal } = $props();
811
</script>
912

1013
<div class="chrome" class:loading>
1114
<button
1215
disabled={loading}
1316
class="reload icon"
14-
on:click={() => dispatch('refresh')}
17+
onclick={() => on_refresh?.()}
1518
aria-label="reload"
1619
/>
1720

1821
<input
1922
disabled={loading}
2023
aria-label="URL"
2124
value={path}
22-
on:change={(e) => {
23-
dispatch('change', { value: e.currentTarget.value });
25+
onchange={(e) => {
26+
on_change?.(e.currentTarget.value);
2427
}}
25-
on:keydown={(e) => {
28+
onkeydown={(e) => {
2629
if (e.key !== 'Enter') return;
2730

28-
dispatch('change', { value: e.currentTarget.value });
31+
on_change?.(e.currentTarget.value);
2932
e.currentTarget.blur();
3033
}}
3134
/>
@@ -41,7 +44,7 @@
4144
<button
4245
disabled={loading}
4346
class="terminal icon"
44-
on:click={() => dispatch('toggle_terminal')}
47+
onclick={() => on_toggle_terminal?.()}
4548
aria-label="toggle terminal"
4649
/>
4750
</div>

src/routes/tutorial/[slug]/Editor.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,12 @@
203203
</script>
204204

205205
<svelte:window
206-
on:pointerdown={(e) => {
206+
onpointerdown={(e) => {
207207
if (!container.contains(/** @type {HTMLElement} */ (e.target))) {
208208
preserve_editor_focus = false;
209209
}
210210
}}
211-
on:message={(e) => {
211+
onmessage={(e) => {
212212
if (preserve_editor_focus && e.data.type === 'iframe_took_focus') {
213213
editor_view.focus();
214214
}
@@ -218,11 +218,11 @@
218218
<div
219219
class="container"
220220
bind:this={container}
221-
on:focusin={() => {
221+
onfocusin={() => {
222222
clearTimeout(remove_focus_timeout);
223223
preserve_editor_focus = true;
224224
}}
225-
on:focusout={() => {
225+
onfocusout={() => {
226226
// Heuristic: user did refocus themmselves if iframe_took_focus
227227
// doesn't happen in the next few miliseconds. Needed
228228
// because else navigations inside the iframe refocus the editor.

src/routes/tutorial/[slug]/Menu.svelte

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
<button
4646
class="heading"
47-
on:click={() => ($is_mobile ? open_nav() : (is_open = !is_open))}
47+
onclick={() => ($is_mobile ? open_nav() : (is_open = !is_open))}
4848
class:open={is_open}
4949
>
5050
<h1>
@@ -87,7 +87,8 @@
8787
transition:slide={{ duration }}
8888
>
8989
<button
90-
on:click|stopPropagation={() => {
90+
onclick={(e) => {
91+
e.stopPropagation();
9192
if (expanded_part !== part.slug) {
9293
expanded_part = part.slug;
9394
expanded_chapter = part.chapters[0].slug;
@@ -106,7 +107,10 @@
106107
aria-current={chapter.slug === current.chapter.slug ? 'step' : undefined}
107108
>
108109
<button
109-
on:click|stopPropagation={() => (expanded_chapter = chapter.slug)}
110+
onclick={(e) => {
111+
e.stopPropagation();
112+
expanded_chapter = chapter.slug;
113+
}}
110114
style="width: 100%; text-align: start;"
111115
>
112116
<!-- <img src={arrow} alt="Arrow icon" /> -->
@@ -126,7 +130,7 @@
126130
>
127131
<a
128132
href="/tutorial/{exercise.slug}"
129-
on:click={() => (is_open = false)}
133+
onclick={() => (is_open = false)}
130134
>
131135
{exercise.title}
132136
</a>

src/routes/tutorial/[slug]/Output.svelte

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
8686
// To prevent iframe flickering.
8787
// Set to `visible` by calling `set_iframe_visible` function
88-
// from iframe on:load or setTimeout
88+
// from iframe onload or setTimeout
8989
iframe.style.visibility = 'hidden';
9090
setTimeout(set_iframe_visible, 1000);
9191
@@ -109,20 +109,20 @@
109109
}
110110
</script>
111111
112-
<svelte:window on:message={handle_message} />
112+
<svelte:window onmessage={handle_message} />
113113
<Chrome
114114
{path}
115115
{loading}
116116
href={a.base && a.base + path}
117-
on:refresh={() => {
117+
on_refresh={() => {
118118
set_iframe_src(a.base + path);
119119
}}
120-
on:toggle_terminal={() => {
120+
on_toggle_terminal={() => {
121121
terminal_visible = !terminal_visible;
122122
}}
123-
on:change={(e) => {
123+
on_change={(value) => {
124124
if (a.base) {
125-
const url = new URL(e.detail.value, a.base);
125+
const url = new URL(value, a.base);
126126
path = url.pathname + url.search + url.hash;
127127
set_iframe_src(a.base + path);
128128
}
@@ -131,7 +131,7 @@
131131
132132
<div class="content">
133133
{#if browser}
134-
<iframe bind:this={iframe} title="Output" on:load={set_iframe_visible} />
134+
<iframe bind:this={iframe} title="Output" onload={set_iframe_visible} />
135135
{/if}
136136
137137
{#if paused || loading || a.error}

src/routes/tutorial/[slug]/ScreenToggle.svelte

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
<script>
2-
import { createEventDispatcher } from 'svelte';
32
import ToggleButton from './ToggleButton.svelte';
43
5-
/** @type {{pressed: boolean}} */
6-
let { pressed = false } = $props();
7-
8-
const dispatch = createEventDispatcher();
4+
/** @type {{pressed: boolean; on_change?: (pressed: boolean) => void}} */
5+
let { pressed = false, on_change } = $props();
96
</script>
107

118
<div class="input-output-toggle">
129
<button
1310
aria-hidden="true"
14-
on:click={() => {
11+
onclick={() => {
1512
if (pressed) {
1613
pressed = false;
17-
dispatch('change', { pressed });
14+
on_change?.(pressed);
1815
}
1916
}}>Tutorial</button
2017
>
21-
<ToggleButton label="Show editor" {pressed} on:change />
18+
<ToggleButton label="Show editor" {pressed} {on_change} />
2219
<button
2320
aria-hidden="true"
24-
on:click={() => {
21+
onclick={() => {
2522
if (!pressed) {
2623
pressed = true;
27-
dispatch('change', { pressed });
24+
on_change?.(pressed);
2825
}
2926
}}>Editor</button
3027
>

src/routes/tutorial/[slug]/Sidebar.svelte

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
<script>
2-
import { createEventDispatcher } from 'svelte';
32
import Modal from '$lib/components/Modal.svelte';
43
import Menu from './Menu.svelte';
54
6-
/** @type {{ index: import('$lib/types').PartStub[]; exercise: import('$lib/types').Exercise; sidebar: HTMLElement }}*/
7-
let { index, exercise, sidebar } = $props();
8-
9-
const dispatch = createEventDispatcher();
5+
/** @type {{ index: import('$lib/types').PartStub[]; exercise: import('$lib/types').Exercise; sidebar: HTMLElement; on_select?: (file: string) => void }}*/
6+
let { index, exercise, sidebar, on_select } = $props();
107
118
const namespace = 'learn.svelte.dev';
129
const copy_enabled = `${namespace}:copy_enabled`;
@@ -19,7 +16,7 @@
1916
<section bind:this={sidebar}>
2017
<div
2118
class="text"
22-
on:copy={(e) => {
19+
oncopy={(e) => {
2320
if (sessionStorage[copy_enabled]) return;
2421

2522
/** @type {HTMLElement | null} */
@@ -40,19 +37,19 @@
4037
<!-- svelte-ignore a11y-click-events-have-key-events -->
4138
<!-- svelte-ignore a11y-no-static-element-interactions -->
4239
<div
43-
on:click={(e) => {
40+
onclick={(e) => {
4441
const node = /** @type {HTMLElement} */ (e.target);
4542

4643
if (node.nodeName === 'CODE') {
4744
const { file } = node.dataset;
4845
if (file) {
49-
dispatch('select', { file });
46+
on_select?.(file);
5047
}
5148
}
5249

5350
if (node.nodeName === 'SPAN' && node.classList.contains('filename')) {
5451
const file = exercise.scope.prefix + node.textContent;
55-
dispatch('select', { file });
52+
on_select?.(file);
5653
}
5754
}}
5855
>
@@ -77,7 +74,7 @@
7774
</section>
7875

7976
{#if show_modal}
80-
<Modal on:close={() => (show_modal = false)}>
77+
<Modal onclose={() => (show_modal = false)}>
8178
<div class="modal-contents">
8279
<h2>Copy and paste is currently disabled!</h2>
8380

@@ -88,14 +85,14 @@
8885
<label>
8986
<input
9087
type="checkbox"
91-
on:change={(e) => {
88+
onchange={(e) => {
9289
sessionStorage[copy_enabled] = e.currentTarget.checked ? 'true' : '';
9390
}}
9491
/>
9592
enable copy-and-paste for the duration of this session
9693
</label>
9794

98-
<button on:click={() => (show_modal = false)}>OK</button>
95+
<button onclick={() => (show_modal = false)}>OK</button>
9996
</div>
10097
</Modal>
10198
{/if}

0 commit comments

Comments
 (0)