Skip to content

Commit 25de38c

Browse files
authored
chore: regenerate playground demo app with latest sveltekit (#279)
1 parent 9539daa commit 25de38c

21 files changed

+205
-164
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
.DS_Store
22
node_modules
3+
/build
34
/.svelte-kit
45
/package
6+
.env
7+
.env.*
8+
!.env.example
9+
.vercel
10+
.output

packages/playground/kit-demo-app/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# create-svelte
22

3-
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte);
3+
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
44

55
## Creating a project
66

@@ -29,10 +29,12 @@ npm run dev -- --open
2929

3030
## Building
3131

32-
Before creating a production version of your app, install an [adapter](https://kit.svelte.dev/docs#adapters) for your target environment. Then:
32+
To create a production version of your app:
3333

3434
```bash
3535
npm run build
3636
```
3737

38-
> You can preview the built app with `npm run preview`, regardless of whether you installed an adapter. This should _not_ be used to serve your app in production.
38+
You can preview the production build with `npm run preview`.
39+
40+
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.

packages/playground/kit-demo-app/jsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"compilerOptions": {
33
"baseUrl": ".",
44
"paths": {
5+
"$lib": ["src/lib"],
56
"$lib/*": ["src/lib/*"]
67
}
78
},

packages/playground/kit-demo-app/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
"scripts": {
66
"dev": "svelte-kit dev",
77
"build": "svelte-kit build",
8+
"package": "svelte-kit package",
89
"preview": "svelte-kit preview"
910
},
1011
"devDependencies": {
11-
"@sveltejs/adapter-node": "^1.0.0-next.68",
12+
"@sveltejs/adapter-auto": "^1.0.0-next.28",
1213
"@sveltejs/kit": "^1.0.0-next.278",
1314
"svelte": "^3.46.4"
1415
},
@@ -17,5 +18,8 @@
1718
"@fontsource/fira-mono": "^4.5.3",
1819
"@lukeed/uuid": "^2.0.0",
1920
"cookie": "^0.4.2"
21+
},
22+
"engines": {
23+
"node": "^14.13.1 || >=16"
2024
}
2125
}

packages/playground/kit-demo-app/src/app.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ a:hover {
7272

7373
h1 {
7474
font-size: 2rem;
75-
margin-bottom: 0 0 1em 0;
7675
text-align: center;
7776
}
7877

packages/playground/kit-demo-app/src/app.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
5-
<link rel="icon" href="/favicon.png" />
5+
<meta name="description" content="Svelte demo app" />
6+
<link rel="icon" href="%svelte.assets%/favicon.png" />
67
<meta name="viewport" content="width=device-width, initial-scale=1" />
7-
88
%svelte.head%
99
</head>
1010
<body>
11-
<div id="svelte">%svelte.body%</div>
11+
<div>%svelte.body%</div>
1212
</body>
1313
</html>

packages/playground/kit-demo-app/src/global.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/playground/kit-demo-app/src/hooks.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import cookie from 'cookie';
22
import { v4 as uuid } from '@lukeed/uuid';
33

4-
export const handle = async ({ request, resolve }) => {
5-
const cookies = cookie.parse(request.headers.cookie || '');
6-
request.locals.userid = cookies.userid || uuid();
4+
export const handle = async ({ event, resolve }) => {
5+
const cookies = cookie.parse(event.request.headers.get('cookie') || '');
6+
event.locals.userid = cookies.userid || uuid();
77

8-
// TODO https://github.com/sveltejs/kit/issues/1046
9-
if (request.query.has('_method')) {
10-
request.method = request.query.get('_method').toUpperCase();
11-
}
12-
13-
const response = await resolve(request);
8+
const response = await resolve(event);
149

1510
if (!cookies.userid) {
1611
// if this is the first time the user has visited this app,
1712
// set a cookie so that we recognise them when they return
18-
response.headers['set-cookie'] = `userid=${request.locals.userid}; Path=/; HttpOnly`;
13+
response.headers.set(
14+
'set-cookie',
15+
cookie.serialize('userid', event.locals.userid, {
16+
path: '/',
17+
httpOnly: true
18+
})
19+
);
1920
}
2021

2122
return response;

packages/playground/kit-demo-app/src/lib/Counter/index.svelte renamed to packages/playground/kit-demo-app/src/lib/Counter.svelte

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
<div class="counter-viewport">
2424
<div class="counter-digits" style="transform: translate(0, {100 * offset}%)">
25-
<strong style="top: -100%" aria-hidden="true">{Math.floor($displayed_count + 1)}</strong>
25+
<strong class="hidden" aria-hidden="true">{Math.floor($displayed_count + 1)}</strong>
2626
<strong>{Math.floor($displayed_count)}</strong>
2727
</div>
2828
</div>
@@ -79,13 +79,12 @@
7979
8080
.counter-viewport strong {
8181
position: absolute;
82-
display: block;
82+
display: flex;
8383
width: 100%;
8484
height: 100%;
8585
font-weight: 400;
8686
color: var(--accent-color);
8787
font-size: 4rem;
88-
display: flex;
8988
align-items: center;
9089
justify-content: center;
9190
}
@@ -95,4 +94,9 @@
9594
width: 100%;
9695
height: 100%;
9796
}
97+
98+
.hidden {
99+
top: -100%;
100+
user-select: none;
101+
}
98102
</style>

packages/playground/kit-demo-app/src/lib/form.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,44 @@
1+
import { invalidate } from '$app/navigation';
2+
13
// this action (https://svelte.dev/tutorial/actions) allows us to
24
// progressively enhance a <form> that already works without JS
3-
export function enhance(form, { pending, error, result }) {
5+
export function enhance(form, { pending, error, result } = {}) {
46
let current_token;
57

68
async function handle_submit(e) {
79
const token = (current_token = {});
810

911
e.preventDefault();
1012

11-
const body = new FormData(form);
13+
const data = new FormData(form);
1214

13-
if (pending) pending(body, form);
15+
if (pending) pending({ data, form });
1416

1517
try {
16-
const res = await fetch(form.action, {
18+
const response = await fetch(form.action, {
1719
method: form.method,
1820
headers: {
1921
accept: 'application/json'
2022
},
21-
body
23+
body: data
2224
});
2325

2426
if (token !== current_token) return;
2527

26-
if (res.ok) {
27-
result(res, form);
28+
if (response.ok) {
29+
if (result) result({ data, form, response });
30+
31+
const url = new URL(form.action);
32+
url.search = url.hash = '';
33+
invalidate(url.href);
2834
} else if (error) {
29-
error(res, null, form);
35+
error({ data, form, error: null, response });
3036
} else {
31-
console.error(await res.text());
37+
console.error(await response.text());
3238
}
3339
} catch (e) {
3440
if (error) {
35-
error(null, e, form);
41+
error({ data, form, error: e, response: null });
3642
} else {
3743
throw e;
3844
}

0 commit comments

Comments
 (0)