2
0
mirror of https://github.com/iconify/iconify.git synced 2024-12-22 09:48:54 +00:00

Update demo packages

This commit is contained in:
Vjacheslav Trushkin 2022-09-08 09:16:41 +03:00
parent 427280d9dc
commit 059eb2ee8c
40 changed files with 1572 additions and 3054 deletions

View File

@ -27,41 +27,41 @@
"@ember/test-helpers": "^2.8.1",
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
"@iconify-icons/mdi-light": "^1.2.1",
"@iconify-icons/mdi-light": "^1.2.2",
"@iconify/ember": "workspace:*",
"babel-eslint": "^10.1.0",
"broccoli-asset-rev": "^3.0.0",
"ember-auto-import": "^2.4.2",
"ember-cli": "~4.1.1",
"ember-cli": "~4.4.1",
"ember-cli-app-version": "^5.0.0",
"ember-cli-babel": "^7.26.11",
"ember-cli-dependency-checker": "^3.3.1",
"ember-cli-htmlbars": "^6.0.1",
"ember-cli-htmlbars": "^6.1.0",
"ember-cli-inject-live-reload": "^2.1.0",
"ember-cli-sri": "^2.1.1",
"ember-cli-terser": "^4.0.2",
"ember-data": "~4.1.0",
"ember-data": "~4.7.1",
"ember-export-application-global": "^2.0.1",
"ember-fetch": "^8.1.1",
"ember-fetch": "^8.1.2",
"ember-load-initializers": "^2.1.2",
"ember-page-title": "^7.0.0",
"ember-qunit": "^5.1.5",
"ember-resolver": "^8.0.3",
"ember-source": "~4.1.0",
"ember-template-lint": "^3.16.0",
"ember-source": "~4.7.0",
"ember-template-lint": "^4.14.0",
"ember-welcome-page": "^6.2.0",
"eslint": "^7.32.0",
"eslint": "^8.23.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-ember": "^10.6.1",
"eslint-plugin-ember": "^11.0.6",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-qunit": "^7.3.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-qunit": "^7.3.1",
"loader.js": "^4.7.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.7.1",
"qunit": "^2.19.1",
"qunit-dom": "^2.0.0",
"webpack": "^5.73.0"
"webpack": "^5.74.0"
},
"engines": {
"node": "12.* || 14.* || >= 16"

View File

@ -9,11 +9,11 @@
},
"dependencies": {
"@iconify/react": "workspace:*",
"next": "^12.1.6",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"next": "^12.2.5",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@iconify-icons/mdi-light": "^1.2.1"
"@iconify-icons/mdi-light": "^1.2.2"
}
}

View File

@ -8,18 +8,18 @@
"preview": "vite preview"
},
"dependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@iconify-icons/mdi-light": "^1.2.1",
"@iconify-icons/uil": "^1.2.1",
"@iconify-icons/mdi-light": "^1.2.2",
"@iconify-icons/uil": "^1.2.2",
"@iconify/core": "workspace:*",
"@iconify/react": "workspace:*",
"@types/react": "^17.0.47",
"@types/react-dom": "^17.0.17",
"@vitejs/plugin-react": "^1.3.2",
"typescript": "^4.7.4",
"vite": "^2.9.12"
"@types/react": "^17.0.49",
"@types/react-dom": "^18.0.6",
"@vitejs/plugin-react": "^2.1.0",
"typescript": "^4.8.2",
"vite": "^3.1.0"
}
}

View File

@ -18,22 +18,22 @@
"sirv": "^2.0.2"
},
"devDependencies": {
"@babel/core": "^7.18.5",
"@babel/core": "^7.19.0",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.18.5",
"@babel/preset-env": "^7.18.2",
"@babel/runtime": "^7.18.3",
"@iconify-icons/openmoji": "^1.2.7",
"@babel/plugin-transform-runtime": "^7.18.10",
"@babel/preset-env": "^7.19.0",
"@babel/runtime": "^7.19.0",
"@iconify-icons/openmoji": "^1.2.11",
"@iconify/svelte": "workspace:*",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-commonjs": "^21.1.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@rollup/plugin-replace": "^3.1.0",
"@rollup/plugin-commonjs": "^22.0.2",
"@rollup/plugin-node-resolve": "^14.0.0",
"@rollup/plugin-replace": "^4.0.0",
"npm-run-all": "^4.1.5",
"rollup": "^2.75.6",
"rollup": "^2.79.0",
"rollup-plugin-svelte": "^7.1.0",
"rollup-plugin-terser": "^7.0.2",
"sapper": "^0.29.3",
"svelte": "^3.48.0"
"svelte": "^3.50.0"
}
}

View File

@ -10,15 +10,15 @@
"check": "svelte-check --tsconfig ./tsconfig.json"
},
"devDependencies": {
"@iconify-icons/mdi-light": "^1.2.1",
"@iconify-icons/mdi-light": "^1.2.2",
"@iconify/svelte": "workspace:*",
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.49",
"@sveltejs/vite-plugin-svelte": "^1.0.5",
"@tsconfig/svelte": "^3.0.0",
"svelte": "^3.48.0",
"svelte-check": "^2.7.2",
"svelte": "^3.50.0",
"svelte-check": "^2.9.0",
"svelte-preprocess": "^4.10.7",
"tslib": "^2.4.0",
"typescript": "^4.7.4",
"vite": "^2.9.12"
"typescript": "^4.8.2",
"vite": "^3.1.0"
}
}

View File

@ -8,16 +8,16 @@
"start": "sirv public --single --port 3000"
},
"devDependencies": {
"@iconify-icons/mdi-light": "^1.2.1",
"@iconify-icons/uil": "^1.2.1",
"@iconify-icons/mdi-light": "^1.2.2",
"@iconify-icons/uil": "^1.2.2",
"@iconify/svelte": "workspace:*",
"@rollup/plugin-commonjs": "^16.0.0",
"@rollup/plugin-node-resolve": "^10.0.0",
"rollup": "^2.75.6",
"@rollup/plugin-commonjs": "^22.0.2",
"@rollup/plugin-node-resolve": "^14.0.0",
"rollup": "^2.79.0",
"rollup-plugin-livereload": "^2.0.5",
"rollup-plugin-svelte": "^7.1.0",
"rollup-plugin-terser": "^7.0.2",
"svelte": "^3.48.0"
"svelte": "^3.50.0"
},
"dependencies": {
"sirv-cli": "^2.0.2"

View File

@ -3,3 +3,8 @@ node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
.vercel
.output

View File

@ -0,0 +1 @@
engine-strict=true

View File

@ -1,6 +1,6 @@
# create-svelte
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte);
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
## Creating a project
@ -8,14 +8,12 @@ If you're seeing this, you've probably already done this step. Congrats!
```bash
# create a new project in the current directory
npm init svelte@next
npm create svelte@latest
# create a new project in my-app
npm init svelte@next my-app
npm create svelte@latest my-app
```
> Note: the `@next` is temporary
## Developing
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
@ -29,10 +27,12 @@ npm run dev -- --open
## Building
Before creating a production version of your app, install an [adapter](https://kit.svelte.dev/docs#adapters) for your target environment. Then:
To create a production version of your app:
```bash
npm run build
```
> 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.
You can preview the production build with `npm run preview`.
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.

View File

@ -1,29 +1,28 @@
{
"name": "@iconify-demo/sveltekit",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "svelte-kit dev",
"build": "svelte-kit build",
"preview": "svelte-kit preview",
"check": "svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch"
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
},
"devDependencies": {
"@iconify-icons/mdi-light": "^1.2.1",
"@iconify-icons/mdi-light": "^1.2.2",
"@iconify/svelte": "workspace:*",
"@sveltejs/adapter-auto": "next",
"@sveltejs/kit": "next",
"@types/cookie": "^0.4.1",
"svelte": "^3.48.0",
"svelte-check": "^2.7.2",
"svelte-preprocess": "^4.10.7",
"tslib": "^2.4.0",
"typescript": "^4.7.4"
"@types/cookie": "^0.5.1",
"svelte": "^3.46.0",
"svelte-check": "^2.7.1",
"svelte-preprocess": "^4.10.6",
"tslib": "^2.3.1",
"typescript": "^4.7.4",
"vite": "^3.1.0"
},
"type": "module",
"dependencies": {
"@fontsource/fira-mono": "^4.5.8",
"@lukeed/uuid": "^2.0.0",
"cookie": "^0.4.2"
"@fontsource/fira-mono": "^4.5.0"
}
}

View File

@ -0,0 +1,12 @@
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
// and what to do when importing types
declare namespace App {
interface Locals {
userid: string;
}
// interface PageData {}
// interface Platform {}
}

View File

@ -2,12 +2,11 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>
<body>
<div id="svelte">%sveltekit.body%</div>
<div>%sveltekit.body%</div>
</body>
</html>

View File

@ -1 +0,0 @@
/// <reference types="@sveltejs/kit" />

View File

@ -1,24 +0,0 @@
import cookie from 'cookie';
import { v4 as uuid } from '@lukeed/uuid';
import type { Handle } from '@sveltejs/kit';
export const handle: Handle = async ({ event, resolve }) => {
const cookies = cookie.parse(event.request.headers.get('cookie') || '');
event.locals.userid = cookies.userid || uuid();
const response = await resolve(event);
if (!cookies.userid) {
// if this is the first time the user has visited this app,
// set a cookie so that we recognise them when they return
response.headers.set(
'set-cookie',
cookie.serialize('userid', event.locals.userid, {
path: '/',
httpOnly: true,
})
);
}
return response;
};

View File

@ -22,7 +22,7 @@
<div class="counter-viewport">
<div class="counter-digits" style="transform: translate(0, {100 * offset}%)">
<strong style="top: -100%" aria-hidden="true">{Math.floor($displayed_count + 1)}</strong>
<strong class="hidden" aria-hidden="true">{Math.floor($displayed_count + 1)}</strong>
<strong>{Math.floor($displayed_count)}</strong>
</div>
</div>
@ -50,6 +50,7 @@
justify-content: center;
border: 0;
background-color: transparent;
touch-action: manipulation;
color: var(--text-color);
font-size: 2rem;
}
@ -94,4 +95,9 @@
width: 100%;
height: 100%;
}
.hidden {
top: -100%;
user-select: none;
}
</style>

View File

@ -1,60 +0,0 @@
// this action (https://svelte.dev/tutorial/actions) allows us to
// progressively enhance a <form> that already works without JS
export function enhance(
form: HTMLFormElement,
{
pending,
error,
result
}: {
pending?: (data: FormData, form: HTMLFormElement) => void;
error?: (res: Response, error: Error, form: HTMLFormElement) => void;
result: (res: Response, form: HTMLFormElement) => void;
}
) {
let current_token: {};
async function handle_submit(e: Event) {
const token = (current_token = {});
e.preventDefault();
const body = new FormData(form);
if (pending) pending(body, form);
try {
const res = await fetch(form.action, {
method: form.method,
headers: {
accept: 'application/json'
},
body
});
if (token !== current_token) return;
if (res.ok) {
result(res, form);
} else if (error) {
error(res, null, form);
} else {
console.error(await res.text());
}
} catch (e) {
if (error) {
error(null, e, form);
} else {
throw e;
}
}
}
form.addEventListener('submit', handle_submit);
return {
destroy() {
form.removeEventListener('submit', handle_submit);
}
};
}

View File

@ -21,18 +21,24 @@
</a>
</div>
<nav>
<nav data-sveltekit-prefetch>
<Icon icon="corner-left" height="auto" />
<ul>
<li class:active={$page.url.pathname === '/'}><a sveltekit:prefetch href="/">Home</a></li>
<li class:active={$page.url.pathname === '/about'}><a sveltekit:prefetch href="/about">About</a></li>
<li class:active={$page.url.pathname === '/todos'}><a sveltekit:prefetch href="/todos">Todos</a></li>
<li class:active={$page.url.pathname === '/'}>
<a href="/">Home</a>
</li>
<li class:active={$page.url.pathname === '/about'}>
<a href="/about">About</a>
</li>
<li class:active={$page.url.pathname === '/todos'}>
<a href="/todos">Todos</a>
</li>
</ul>
<Icon icon="corner-right" height="auto" />
</nav>
<div class="corner">
<a href="https://github.com/iconify/iconify/tree/master/packages/svelte">
<a href="https://github.com/iconify/iconify/tree/main/components/svelte">
<Icon icon="line-md:iconify1" title="Iconify" />
</a>
</div>

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="107" height="128" viewBox="0 0 107 128"><title>svelte-logo</title><path d="M94.1566,22.8189c-10.4-14.8851-30.94-19.2971-45.7914-9.8348L22.2825,29.6078A29.9234,29.9234,0,0,0,8.7639,49.6506a31.5136,31.5136,0,0,0,3.1076,20.2318A30.0061,30.0061,0,0,0,7.3953,81.0653a31.8886,31.8886,0,0,0,5.4473,24.1157c10.4022,14.8865,30.9423,19.2966,45.7914,9.8348L84.7167,98.3921A29.9177,29.9177,0,0,0,98.2353,78.3493,31.5263,31.5263,0,0,0,95.13,58.117a30,30,0,0,0,4.4743-11.1824,31.88,31.88,0,0,0-5.4473-24.1157" style="fill:#ff3e00"/><path d="M45.8171,106.5815A20.7182,20.7182,0,0,1,23.58,98.3389a19.1739,19.1739,0,0,1-3.2766-14.5025,18.1886,18.1886,0,0,1,.6233-2.4357l.4912-1.4978,1.3363.9815a33.6443,33.6443,0,0,0,10.203,5.0978l.9694.2941-.0893.9675a5.8474,5.8474,0,0,0,1.052,3.8781,6.2389,6.2389,0,0,0,6.6952,2.485,5.7449,5.7449,0,0,0,1.6021-.7041L69.27,76.281a5.4306,5.4306,0,0,0,2.4506-3.631,5.7948,5.7948,0,0,0-.9875-4.3712,6.2436,6.2436,0,0,0-6.6978-2.4864,5.7427,5.7427,0,0,0-1.6.7036l-9.9532,6.3449a19.0329,19.0329,0,0,1-5.2965,2.3259,20.7181,20.7181,0,0,1-22.2368-8.2427,19.1725,19.1725,0,0,1-3.2766-14.5024,17.9885,17.9885,0,0,1,8.13-12.0513L55.8833,23.7472a19.0038,19.0038,0,0,1,5.3-2.3287A20.7182,20.7182,0,0,1,83.42,29.6611a19.1739,19.1739,0,0,1,3.2766,14.5025,18.4,18.4,0,0,1-.6233,2.4357l-.4912,1.4978-1.3356-.98a33.6175,33.6175,0,0,0-10.2037-5.1l-.9694-.2942.0893-.9675a5.8588,5.8588,0,0,0-1.052-3.878,6.2389,6.2389,0,0,0-6.6952-2.485,5.7449,5.7449,0,0,0-1.6021.7041L37.73,51.719a5.4218,5.4218,0,0,0-2.4487,3.63,5.7862,5.7862,0,0,0,.9856,4.3717,6.2437,6.2437,0,0,0,6.6978,2.4864,5.7652,5.7652,0,0,0,1.602-.7041l9.9519-6.3425a18.978,18.978,0,0,1,5.2959-2.3278,20.7181,20.7181,0,0,1,22.2368,8.2427,19.1725,19.1725,0,0,1,3.2766,14.5024,17.9977,17.9977,0,0,1-8.13,12.0532L51.1167,104.2528a19.0038,19.0038,0,0,1-5.3,2.3287" style="fill:#fff"/></svg>

Before

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -1,7 +0,0 @@
/**
* Can be made globally available by placing this
* inside `global.d.ts` and removing `export` keyword
*/
export interface Locals {
userid: string;
}

View File

@ -1,29 +1,26 @@
<script context="module" lang="ts">
export const prerender = true;
</script>
<script lang="ts">
import Counter from '$lib/Counter.svelte';
</script>
<svelte:head>
<title>Home</title>
<meta name="description" content="Svelte demo app" />
</svelte:head>
<section>
<h1>
<div class="welcome">
<span class="welcome">
<picture>
<source srcset="svelte-welcome.webp" type="image/webp" />
<img src="svelte-welcome.png" alt="Welcome" />
</picture>
</div>
</span>
to your new<br />SvelteKit app
</h1>
<h2>
try editing <strong>src/routes/index.svelte</strong>
try editing <strong>src/routes/+page.svelte</strong>
</h2>
<Counter />
@ -43,6 +40,7 @@
}
.welcome {
display: block;
position: relative;
width: 100%;
height: 0;

View File

@ -0,0 +1 @@
export const prerender = true;

View File

@ -1,21 +1,6 @@
<script context="module">
import { browser, dev } from '$app/env';
// we don't need any JS on this page, though we'll load
// it in dev so that we get hot module replacement...
export const hydrate = dev;
// ...but if the client-side router is already loaded
// (i.e. we came here from elsewhere in the app), use it
export const router = browser;
// since there's no dynamic data here, we can prerender
// it so that it gets served as a static asset in prod
export const prerender = true;
</script>
<svelte:head>
<title>About</title>
<meta name="description" content="About this app" />
</svelte:head>
<div class="content">
@ -26,8 +11,7 @@
following into your command line and following the prompts:
</p>
<!-- TODO lose the @next! -->
<pre>npm init svelte@next</pre>
<pre>npm create svelte@latest</pre>
<p>
The page you're looking at is purely static HTML, with no client-side interactivity needed.

View File

@ -0,0 +1,9 @@
import { dev } from '$app/environment';
// we don't need any JS on this page, though we'll load
// it in dev so that we get hot module replacement...
export const csr = dev;
// since there's no dynamic data here, we can prerender
// it so that it gets served as a static asset in prod
export const prerender = true;

View File

@ -0,0 +1,61 @@
import { error } from '@sveltejs/kit';
import { api } from './api';
import type { PageServerLoad, Actions } from './$types';
type Todo = {
uid: string;
created_at: Date;
text: string;
done: boolean;
pending_delete: boolean;
};
export const load: PageServerLoad = async ({ locals }) => {
// locals.userid comes from src/hooks.js
const response = await api('GET', `todos/${locals.userid}`);
if (response.status === 404) {
// user hasn't created a todo list.
// start with an empty array
return {
todos: [] as Todo[]
};
}
if (response.status === 200) {
return {
todos: (await response.json()) as Todo[]
};
}
throw error(response.status);
};
export const actions: Actions = {
add: async ({ request, locals }) => {
const form = await request.formData();
await api('POST', `todos/${locals.userid}`, {
text: form.get('text')
});
},
edit: async ({ request, locals }) => {
const form = await request.formData();
await api('PATCH', `todos/${locals.userid}/${form.get('uid')}`, {
text: form.get('text')
});
},
toggle: async ({ request, locals }) => {
const form = await request.formData();
await api('PATCH', `todos/${locals.userid}/${form.get('uid')}`, {
done: !!form.get('done')
});
},
delete: async ({ request, locals }) => {
const form = await request.formData();
await api('DELETE', `todos/${locals.userid}/${form.get('uid')}`);
}
};

View File

@ -1,53 +1,17 @@
<script context="module" lang="ts">
import { enhance } from '$lib/form';
import type { Load } from '@sveltejs/kit';
// see https://kit.svelte.dev/docs#loading
export const load: Load = async ({ fetch }) => {
const res = await fetch('/todos.json');
if (res.ok) {
const todos = await res.json();
return {
props: { todos }
};
}
const { message } = await res.json();
return {
error: new Error(message)
};
};
</script>
<script lang="ts">
import { enhance } from '$app/forms';
import { invalidateAll } from '$app/navigation';
import { scale } from 'svelte/transition';
import { flip } from 'svelte/animate';
import type { PageData } from './$types';
type Todo = {
uid: string;
created_at: Date;
text: string;
done: boolean;
pending_delete: boolean;
};
export let todos: Todo[];
async function patch(res: Response) {
const todo = await res.json();
todos = todos.map((t) => {
if (t.uid === todo.uid) return todo;
return t;
});
}
export let data: PageData;
$: todos = data.todos;
</script>
<svelte:head>
<title>Todos</title>
<meta name="description" content="A todo list app" />
</svelte:head>
<div class="todos">
@ -55,15 +19,15 @@
<form
class="new"
action="/todos.json"
action="/todos?/add"
method="post"
use:enhance={{
result: async (res, form) => {
const created = await res.json();
todos = [...todos, created];
form.reset();
}
use:enhance={({ form }) => {
return (result) => {
if (result.type === 'success') {
form.reset();
invalidateAll();
}
};
}}
>
<input name="text" aria-label="Add todo" placeholder="+ tap to add a todo" />
@ -77,41 +41,31 @@
animate:flip={{ duration: 200 }}
>
<form
action="/todos/{todo.uid}.json?_method=patch"
action="/todos?/toggle"
method="post"
use:enhance={{
pending: (data) => {
todo.done = !!data.get('done');
},
result: patch
use:enhance={({ data }) => {
todo.done = !!data.get('done');
}}
>
<input type="hidden" name="uid" value={todo.uid} />
<input type="hidden" name="done" value={todo.done ? '' : 'true'} />
<button class="toggle" aria-label="Mark todo as {todo.done ? 'not done' : 'done'}" />
</form>
<form
class="text"
action="/todos/{todo.uid}.json?_method=patch"
method="post"
use:enhance={{
result: patch
}}
>
<form class="text" action="/todos?/edit" method="post" use:enhance>
<input type="hidden" name="uid" value={todo.uid} />
<input aria-label="Edit todo" type="text" name="text" value={todo.text} />
<button class="save" aria-label="Save todo" />
</form>
<form
action="/todos/{todo.uid}.json?_method=delete"
action="/todos?/delete"
method="post"
use:enhance={{
pending: () => (todo.pending_delete = true),
result: () => {
todos = todos.filter((t) => t.uid !== todo.uid);
}
use:enhance={() => {
todo.pending_delete = true;
}}
>
<input type="hidden" name="uid" value={todo.uid} />
<button class="delete" aria-label="Delete todo" disabled={todo.pending_delete} />
</form>
</div>
@ -167,7 +121,7 @@
.done {
transform: none;
opacity: 0.4;
filter: drop-shadow(0px 0px 1px rgba(0, 0, 0, 0.1));
filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.1));
}
form.text {

View File

@ -1,18 +0,0 @@
import { api } from './_api';
import type { RequestHandler } from '@sveltejs/kit';
import type { Locals } from '$lib/types';
// PATCH /todos/:uid.json
export const patch: RequestHandler<Locals> = async (event) => {
const data = await event.request.formData();
return api(event, `todos/${event.locals.userid}/${event.params.uid}`, {
text: data.get('text'),
done: data.has('done') ? !!data.get('done') : undefined,
});
};
// DELETE /todos/:uid.json
export const del: RequestHandler<Locals> = async (event) => {
return api(event, `todos/${event.locals.userid}/${event.params.uid}`);
};

View File

@ -1,56 +0,0 @@
import type { EndpointOutput, RequestEvent } from '@sveltejs/kit';
import type { Locals } from '$lib/types';
/*
This module is used by the /todos.json and /todos/[uid].json
endpoints to make calls to api.svelte.dev, which stores todos
for each user. The leading underscore indicates that this is
a private module, _not_ an endpoint visiting /todos/_api
will net you a 404 response.
(The data on the todo app will expire periodically; no
guarantees are made. Don't use it to organise your life.)
*/
const base = 'https://api.svelte.dev';
export async function api(
event: RequestEvent<Locals>,
resource: string,
data?: Record<string, unknown>
): Promise<EndpointOutput> {
// user must have a cookie set
if (!event.locals.userid) {
return { status: 401 };
}
const res = await fetch(`${base}/${resource}`, {
method: event.request.method,
headers: {
'content-type': 'application/json',
},
body: data && JSON.stringify(data),
});
// if the request came from a <form> submission, the browser's default
// behaviour is to show the URL corresponding to the form's "action"
// attribute. in those cases, we want to redirect them back to the
// /todos page, rather than showing the response
if (
res.ok &&
event.request.method !== 'GET' &&
event.request.headers.get('accept') !== 'application/json'
) {
return {
status: 303,
headers: {
location: '/todos',
},
};
}
return {
status: res.status,
body: await res.json(),
};
}

View File

@ -0,0 +1,20 @@
/*
This module is used by the /todos endpoint to
make calls to api.svelte.dev, which stores todos
for each user.
(The data on the todo app will expire periodically; no
guarantees are made. Don't use it to organise your life.)
*/
const base = 'https://api.svelte.dev';
export function api(method: string, resource: string, data?: Record<string, unknown>) {
return fetch(`${base}/${resource}`, {
method,
headers: {
'content-type': 'application/json'
},
body: data && JSON.stringify(data)
});
}

View File

@ -1,32 +0,0 @@
import { api } from './_api';
import type { RequestHandler } from '@sveltejs/kit';
import type { Locals } from '$lib/types';
// GET /todos.json
export const get: RequestHandler<Locals> = async (event) => {
// event.locals.userid comes from src/hooks.js
const response = await api(event, `todos/${event.locals.userid}`);
if (response.status === 404) {
// user hasn't created a todo list.
// start with an empty array
return { body: [] };
}
return response;
};
// POST /todos.json
export const post: RequestHandler<Locals> = async (event) => {
const data = await event.request.formData();
const response = await api(event, `todos/${event.locals.userid}`, {
// because index.svelte posts a FormData object,
// request.body is _also_ a (readonly) FormData
// object, which allows us to get form data
// with the `body.get(key)` method
text: data.get('text'),
});
return response;
};

View File

@ -1,3 +1,4 @@
import adapter from '@sveltejs/adapter-auto';
import preprocess from 'svelte-preprocess';
/** @type {import('@sveltejs/kit').Config} */
@ -7,9 +8,8 @@ const config = {
preprocess: preprocess(),
kit: {
// hydrate the <div id="svelte"> element in src/app.html
// target: '#svelte'
},
adapter: adapter()
}
};
export default config;

View File

@ -1,37 +1,17 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"moduleResolution": "node",
"module": "es2020",
"lib": ["es2020", "DOM"],
"target": "es2019",
/**
svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript
to enforce using \`import type\` instead of \`import\` for Types.
*/
"importsNotUsedAsValues": "error",
"isolatedModules": true,
"resolveJsonModule": true,
/**
To have warnings/errors of the Svelte compiler at the correct position,
enable source maps by default.
*/
"sourceMap": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"allowJs": true,
"checkJs": true,
"paths": {
"$lib": ["src/lib"],
"$lib/*": ["src/lib/*"]
}
},
"include": [
"src/**/*.d.ts",
"src/**/*.js",
"src/**/*.ts",
"src/**/*.svelte"
]
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true
}
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
//
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
// from the referenced tsconfig.json - TypeScript does not merge them in
}

View File

@ -0,0 +1,8 @@
import { sveltekit } from '@sveltejs/kit/vite';
import type { UserConfig } from 'vite';
const config: UserConfig = {
plugins: [sveltekit()]
};
export default config;

View File

@ -7,15 +7,15 @@
"build": "vite build"
},
"dependencies": {
"vue": "^3.2.37"
"vue": "^3.2.38"
},
"devDependencies": {
"@iconify-icons/bx": "^1.2.3",
"@iconify-icons/dashicons": "^1.2.2",
"@iconify-icons/bx": "^1.2.4",
"@iconify-icons/dashicons": "^1.2.3",
"@iconify/types": "workspace:*",
"@iconify/vue": "workspace:*",
"@vitejs/plugin-vue": "^2.3.3",
"typescript": "^4.7.4",
"vite": "^2.9.12"
"@vitejs/plugin-vue": "^3.1.0",
"typescript": "^4.8.2",
"vite": "^3.1.0"
}
}

View File

@ -8,15 +8,15 @@
"preview": "vite preview"
},
"dependencies": {
"vue": "^2.6.14",
"vue": "^2.7.10",
"vue-class-component": "^7.2.6",
"vue-property-decorator": "^9.1.2"
},
"devDependencies": {
"@iconify-icons/bx": "^1.2.3",
"@iconify-icons/dashicons": "^1.2.2",
"@iconify-icons/bx": "^1.2.4",
"@iconify-icons/dashicons": "^1.2.3",
"@iconify/vue2": "workspace:*",
"vite": "^2.9.12",
"vite-plugin-vue2": "^2.0.1"
"vite": "^2.9.15",
"vite-plugin-vue2": "^2.0.2"
}
}

View File

@ -0,0 +1,16 @@
import type { Handle } from '@sveltejs/kit';
export const handle: Handle = async ({ event, resolve }) => {
let userid = event.cookies.get('userid');
if (!userid) {
// if this is the first time the user has visited this app,
// set a cookie so that we recognise them when they return
userid = crypto.randomUUID();
event.cookies.set('userid', userid, { path: '/' });
}
event.locals.userid = userid;
return resolve(event);
};

View File

@ -38,7 +38,7 @@
</nav>
<div class="corner">
<a href="https://github.com/iconify/iconify/tree/master/packages/svelte">
<a href="https://github.com/iconify/iconify/tree/main/iconify-icon/icon">
<iconify-icon icon="line-md:iconify1" title="Iconify" />
</a>
</div>

View File

@ -22,7 +22,7 @@
"packageExtensions": {
"vue-template-compiler": {
"peerDependencies": {
"vue": "^2.6.14"
"vue": "^2.*"
}
},
"tsutils": {

File diff suppressed because it is too large Load Diff