Skip to content

Commit b2a2550

Browse files
authored
Merge branch 'main' into pkg-pr-new-version
2 parents 2354f9a + 8e11751 commit b2a2550

File tree

18 files changed

+227
-232
lines changed

18 files changed

+227
-232
lines changed

apps/svelte.dev/content/docs/svelte/06-runtime/03-lifecycle-hooks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ While there's no "after update" hook, you can use `tick` to ensure that the UI i
8484
8585
$effect.pre(() => {
8686
console.log('the component is about to update');
87-
tick().then(
87+
tick().then(() => {
8888
console.log('the component just updated');
89-
);
89+
});
9090
});
9191
</script>
9292
```
Lines changed: 2 additions & 2 deletions
Loading

apps/svelte.dev/src/routes/docs/[...path]/OnThisPage.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
background-size: 2rem;
130130
top: 0.4rem;
131131
right: 0.2rem;
132-
rotate: -90deg;
132+
rotate: 0deg;
133133
transition: rotate 0.2s;
134134
transition: rotate 0.2s;
135135
}
@@ -153,7 +153,7 @@
153153
154154
label:has(:checked) {
155155
&::after {
156-
rotate: 90deg;
156+
rotate: 180deg;
157157
}
158158
159159
/* TODO remove :global once https://github.com/sveltejs/svelte/issues/13779 is fixed */

apps/svelte.dev/src/routes/tutorial/[...slug]/filetree/ContextMenu.svelte

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,33 @@
11
<!-- @component
22
A context menu for the tutorial's file tree
33
-->
4-
<script module>
5-
import { writable } from 'svelte/store';
4+
<script module lang="ts">
5+
import type { MenuItem } from '$lib/tutorial';
66
7-
/**
8-
* @type {import("svelte/store").Writable<{x: number; y: number; items: import('$lib/tutorial').MenuItem[]} | null>}
9-
*/
10-
let menu_items = writable(null);
7+
let menu_items: { x: number; y: number; items: MenuItem[] } | null = $state(null);
118
12-
/**
13-
* @param {number} x
14-
* @param {number} y
15-
* @param {import('$lib/tutorial').MenuItem[]} items
16-
*/
17-
export function open(x, y, items) {
9+
export function open(x: number, y: number, items: MenuItem[]) {
1810
if (items.length > 0) {
19-
menu_items.set({ x, y, items });
11+
menu_items = { x, y, items };
2012
}
2113
}
2214
</script>
2315

24-
{#if $menu_items}
25-
<nav style="position: fixed; z-index: 5; top:{$menu_items.y}px; left:{$menu_items.x}px">
16+
{#if menu_items}
17+
<nav style="position: fixed; z-index: 5; top:{menu_items.y}px; left:{menu_items.x}px">
2618
<div class="context-menu">
2719
<ul>
28-
{#each $menu_items.items as item}
20+
{#each menu_items.items as item}
2921
<li>
30-
<button on:click={item.fn}>{item.label}</button>
22+
<button onclick={item.fn}>{item.label}</button>
3123
</li>
3224
{/each}
3325
</ul>
3426
</div>
3527
</nav>
3628
{/if}
3729

38-
<svelte:window on:click={() => menu_items.set(null)} />
30+
<svelte:window onclick={() => (menu_items = null)} />
3931

4032
<style>
4133
.context-menu {

apps/svelte.dev/src/routes/tutorial/[...slug]/filetree/Item.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { tick } from 'svelte';
33
import { open } from './ContextMenu.svelte';
44
import type { MenuItem } from '$lib/tutorial';
5+
import { forcefocus } from '@sveltejs/site-kit/actions';
56
67
interface Props {
78
basename?: string;
@@ -63,7 +64,7 @@
6364
<!-- svelte-ignore a11y_autofocus -->
6465
<input
6566
type="text"
66-
autofocus
67+
use:forcefocus
6768
autocomplete="off"
6869
spellcheck="false"
6970
value={basename}
@@ -135,7 +136,7 @@
135136
}
136137
137138
input {
138-
background: var(--sk-bg-1);
139+
background: var(--sk-bg-3);
139140
margin: 0 0.5rem 0 calc(0.5rem + var(--inset));
140141
border: 2px solid transparent;
141142
padding: 0 0.5rem;

packages/editor/src/lib/Editor.svelte

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,26 +105,20 @@
105105
display: grid;
106106
grid-template-columns: 4rem 1fr;
107107
grid-gap: 1rem;
108-
padding: 1rem 0;
109-
font: var(--sk-font-mono);
108+
padding: 0.4rem 0;
110109
}
111110
112111
.fake * {
113-
color: #ccc;
112+
color: var(--sk-fg-4);
113+
font: var(--sk-font-mono);
114114
}
115115
116116
.fake-gutter {
117117
text-align: right;
118-
padding-right: 3px;
118+
padding-right: 0.7rem;
119119
}
120120
121121
.fake-content {
122122
padding: 0 1rem;
123123
}
124-
125-
@media (prefers-color-scheme: dark) {
126-
.fake * {
127-
color: #666;
128-
}
129-
}
130124
</style>

packages/editor/src/lib/Workspace.svelte.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CompileError, CompileOptions, CompileResult } from 'svelte/compiler';
1+
import type { CompileError, CompileResult } from 'svelte/compiler';
22
import { Compartment, EditorState } from '@codemirror/state';
33
import { compile_file } from './compile-worker';
44
import { BROWSER } from 'esm-env';
@@ -77,7 +77,7 @@ const default_extensions = [
7777
// extensions.push(vim());
7878
// }
7979

80-
interface ExposedCompilerOptions {
80+
export interface ExposedCompilerOptions {
8181
generate: 'client' | 'server';
8282
dev: boolean;
8383
modernAst: boolean;
@@ -124,7 +124,10 @@ export class Workspace {
124124
span.innerHTML = `${error.message
125125
.replace(/&/g, '&amp;')
126126
.replace(/</g, '&lt;')
127-
.replace(/`(.+?)`/g, `<code>$1</code>`)} <strong>(${error.code})</strong>`;
127+
.replace(
128+
/`(.+?)`/g,
129+
`<code>$1</code>`
130+
)} (<a href="/docs/svelte/compiler-errors#${error.code}">${error.code}</a>)`;
128131

129132
return span;
130133
}
@@ -142,7 +145,10 @@ export class Workspace {
142145
span.innerHTML = `${warning.message
143146
.replace(/&/g, '&amp;')
144147
.replace(/</g, '&lt;')
145-
.replace(/`(.+?)`/g, `<code>$1</code>`)} <strong>(${warning.code})</strong>`;
148+
.replace(
149+
/`(.+?)`/g,
150+
`<code>$1</code>`
151+
)} (<a href="/docs/svelte/compiler-warnings#${warning.code}">${warning.code}</a>)`;
146152

147153
return span;
148154
}
@@ -206,6 +212,8 @@ export class Workspace {
206212
if (is_file(item)) {
207213
this.#select(item);
208214
this.#onreset?.(this.#files);
215+
216+
this.modified[item.name] = true;
209217
}
210218

211219
return item;
@@ -320,6 +328,11 @@ export class Workspace {
320328
this.#select(new_item as File);
321329
}
322330

331+
if (this.modified[previous.name]) {
332+
delete this.modified[previous.name];
333+
this.modified[name] = true;
334+
}
335+
323336
this.#onreset?.(this.#files);
324337
}
325338

packages/editor/src/lib/codemirror.css

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
height: 100%;
99

1010
&.cm-focused {
11+
outline: none;
12+
1113
.cm-cursor {
1214
border-left-color: var(--sk-fg-3);
1315
}
@@ -36,6 +38,14 @@
3638
}
3739

3840
.cm-activeLine {
41+
background: inherit;
42+
}
43+
44+
.cm-foldGutter {
45+
width: 1.4rem;
46+
}
47+
48+
.cm-activeLineGutter {
3949
/* this must be translucent, or it will obscure the selection */
4050
background: hsl(0, 0%, 0%, 0.04);
4151

@@ -44,8 +54,29 @@
4454
}
4555
}
4656

47-
.cm-activeLineGutter {
48-
background-color: var(--sk-bg-3);
57+
.cm-gutterElement {
58+
position: relative;
59+
60+
&:where(:has([title='Fold line']), :has([title='Unfold line']))::after {
61+
content: '';
62+
position: absolute;
63+
width: 100%;
64+
right: 0;
65+
top: 0;
66+
height: 2.4rem;
67+
background: url($lib/icons/chevron.svg) no-repeat 50% 50%;
68+
background-size: contain;
69+
transition: transform 0.2s;
70+
cursor: pointer;
71+
}
72+
73+
&:has([title='Unfold line'])::after {
74+
transform: rotate(-90deg);
75+
}
76+
77+
span {
78+
color: transparent;
79+
}
4980
}
5081

5182
.cm-lineNumbers {
@@ -58,10 +89,6 @@
5889
}
5990
}
6091

61-
.cm-foldGutter {
62-
width: 1rem;
63-
}
64-
6592
.cm-foldPlaceholder {
6693
background-color: transparent;
6794
border: none;
@@ -83,17 +110,7 @@
83110
}
84111

85112
.cm-content {
86-
/* ensure no gap between top of editor and highlighted first/last line */
87-
padding-top: 0;
88-
padding-bottom: 0;
89-
90-
.cm-line:first-child {
91-
padding-top: 4px;
92-
}
93-
94-
.cm-line:last-child {
95-
padding-bottom: 4px;
96-
}
113+
padding: 0.4rem 0;
97114
}
98115

99116
.cm-line {
@@ -275,21 +292,15 @@
275292
padding: 0.2rem 0.4rem;
276293
}
277294

278-
strong {
295+
a {
279296
font: var(--sk-font-mono);
297+
color: inherit;
280298
font-size: 1em;
281-
opacity: 0.7;
299+
/* opacity: 0.7; */
300+
text-decoration: underline;
282301
}
283302
}
284303
}
285304
}
286-
287-
&.cm-tooltip-below .cm-tooltip-section {
288-
/* top: 1rem; */
289-
}
290-
291-
&.cm-tooltip-above .cm-tooltip-section {
292-
/* bottom: 1rem; */
293-
}
294305
}
295306
}

packages/editor/src/lib/compile-worker/worker.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import type { File } from '../Workspace.svelte';
21
import { parseTar } from 'tarparser';
2+
import type { CompileResult } from 'svelte/compiler';
3+
import type { ExposedCompilerOptions, File } from '../Workspace.svelte';
34

45
// hack for magic-string and Svelte 4 compiler
56
// do not put this into a separate module and import it, would be treeshaken in prod
@@ -68,12 +69,10 @@ addEventListener('message', async (event) => {
6869
const { id, file, options } = event.data as {
6970
id: number;
7071
file: File;
71-
options: { generate: 'client' | 'server'; dev: boolean };
72+
options: ExposedCompilerOptions;
7273
};
7374

74-
const fn = file.name.endsWith('.svelte') ? self.svelte.compile : self.svelte.compileModule;
75-
76-
if (!fn) {
75+
if (!file.name.endsWith('.svelte') && !self.svelte.compileModule) {
7776
// .svelte.js file compiled with Svelte 3/4 compiler
7877
postMessage({
7978
id,
@@ -98,7 +97,22 @@ addEventListener('message', async (event) => {
9897
}
9998

10099
try {
101-
const result = fn(file.contents, { ...options, filename: file.name });
100+
let result: CompileResult;
101+
102+
if (file.name.endsWith('.svelte')) {
103+
result = self.svelte.compile(file.contents, {
104+
generate: options.generate, // TODO do we need to adjust this for 3/4?
105+
dev: options.dev,
106+
modernAst: options.modernAst,
107+
filename: file.name
108+
});
109+
} else {
110+
result = self.svelte.compileModule(file.contents, {
111+
generate: options.generate,
112+
dev: options.dev,
113+
filename: file.name
114+
});
115+
}
102116

103117
postMessage({
104118
id,

0 commit comments

Comments
 (0)