create-svelte
Advanced tools
Comparing version 2.0.0-next.83 to 2.0.0-next.84
@@ -16,3 +16,3 @@ [ | ||
"name": "src/lib/form.ts", | ||
"contents": "// this action (https://svelte.dev/tutorial/actions) allows us to\n// progressively enhance a <form> that already works without JS\nexport function enhance(\n\tform: HTMLFormElement,\n\t{\n\t\tpending,\n\t\terror,\n\t\tresult\n\t}: {\n\t\tpending?: (data: FormData, form: HTMLFormElement) => void;\n\t\terror?: (res: Response, error: Error, form: HTMLFormElement) => void;\n\t\tresult: (res: Response, form: HTMLFormElement) => void;\n\t}\n) {\n\tlet current_token: {};\n\n\tasync function handle_submit(e: Event) {\n\t\tconst token = (current_token = {});\n\n\t\te.preventDefault();\n\n\t\tconst body = new FormData(form);\n\n\t\tif (pending) pending(body, form);\n\n\t\ttry {\n\t\t\tconst res = await fetch(form.action, {\n\t\t\t\tmethod: form.method,\n\t\t\t\theaders: {\n\t\t\t\t\taccept: 'application/json'\n\t\t\t\t},\n\t\t\t\tbody\n\t\t\t});\n\n\t\t\tif (token !== current_token) return;\n\n\t\t\tif (res.ok) {\n\t\t\t\tresult(res, form);\n\t\t\t} else if (error) {\n\t\t\t\terror(res, null, form);\n\t\t\t} else {\n\t\t\t\tconsole.error(await res.text());\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tif (error) {\n\t\t\t\terror(null, e, form);\n\t\t\t} else {\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\t}\n\n\tform.addEventListener('submit', handle_submit);\n\n\treturn {\n\t\tdestroy() {\n\t\t\tform.removeEventListener('submit', handle_submit);\n\t\t}\n\t};\n}\n" | ||
"contents": "// this action (https://svelte.dev/tutorial/actions) allows us to\n// progressively enhance a <form> that already works without JS\nexport function enhance(\n\tform: HTMLFormElement,\n\t{\n\t\tpending,\n\t\terror,\n\t\tresult\n\t}: {\n\t\tpending?: (data: FormData, form: HTMLFormElement) => void;\n\t\terror?: (res: Response, error: Error, form: HTMLFormElement) => void;\n\t\tresult: (res: Response, form: HTMLFormElement) => void;\n\t}\n): { destroy: () => void } {\n\tlet current_token: unknown;\n\n\tasync function handle_submit(e: Event) {\n\t\tconst token = (current_token = {});\n\n\t\te.preventDefault();\n\n\t\tconst body = new FormData(form);\n\n\t\tif (pending) pending(body, form);\n\n\t\ttry {\n\t\t\tconst res = await fetch(form.action, {\n\t\t\t\tmethod: form.method,\n\t\t\t\theaders: {\n\t\t\t\t\taccept: 'application/json'\n\t\t\t\t},\n\t\t\t\tbody\n\t\t\t});\n\n\t\t\tif (token !== current_token) return;\n\n\t\t\tif (res.ok) {\n\t\t\t\tresult(res, form);\n\t\t\t} else if (error) {\n\t\t\t\terror(res, null, form);\n\t\t\t} else {\n\t\t\t\tconsole.error(await res.text());\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tif (error) {\n\t\t\t\terror(null, e, form);\n\t\t\t} else {\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\t}\n\n\tform.addEventListener('submit', handle_submit);\n\n\treturn {\n\t\tdestroy() {\n\t\t\tform.removeEventListener('submit', handle_submit);\n\t\t}\n\t};\n}\n" | ||
}, | ||
@@ -45,3 +45,3 @@ { | ||
"name": "src/routes/todos/_api.ts", | ||
"contents": "import type { Request } from '@sveltejs/kit';\nimport type { Locals } from '$lib/types';\n\n/*\n\tThis module is used by the /todos.json and /todos/[uid].json\n\tendpoints to make calls to api.svelte.dev, which stores todos\n\tfor each user. The leading underscore indicates that this is\n\ta private module, _not_ an endpoint — visiting /todos/_api\n\twill net you a 404 response.\n\n\t(The data on the todo app will expire periodically; no\n\tguarantees are made. Don't use it to organise your life.)\n*/\n\nconst base = 'https://api.svelte.dev';\n\nexport async function api(request: Request<Locals>, resource: string, data?: {}) {\n\t// user must have a cookie set\n\tif (!request.locals.userid) {\n\t\treturn { status: 401 };\n\t}\n\n\tconst res = await fetch(`${base}/${resource}`, {\n\t\tmethod: request.method,\n\t\theaders: {\n\t\t\t'content-type': 'application/json'\n\t\t},\n\t\tbody: data && JSON.stringify(data)\n\t});\n\n\t// if the request came from a <form> submission, the browser's default\n\t// behaviour is to show the URL corresponding to the form's \"action\"\n\t// attribute. in those cases, we want to redirect them back to the\n\t// /todos page, rather than showing the response\n\tif (res.ok && request.method !== 'GET' && request.headers.accept !== 'application/json') {\n\t\treturn {\n\t\t\tstatus: 303,\n\t\t\theaders: {\n\t\t\t\tlocation: '/todos'\n\t\t\t}\n\t\t};\n\t}\n\n\treturn {\n\t\tstatus: res.status,\n\t\tbody: await res.json()\n\t};\n}\n" | ||
"contents": "import type { EndpointOutput, Request } from '@sveltejs/kit';\nimport type { Locals } from '$lib/types';\n\n/*\n\tThis module is used by the /todos.json and /todos/[uid].json\n\tendpoints to make calls to api.svelte.dev, which stores todos\n\tfor each user. The leading underscore indicates that this is\n\ta private module, _not_ an endpoint — visiting /todos/_api\n\twill net you a 404 response.\n\n\t(The data on the todo app will expire periodically; no\n\tguarantees are made. Don't use it to organise your life.)\n*/\n\nconst base = 'https://api.svelte.dev';\n\nexport async function api(\n\trequest: Request<Locals>,\n\tresource: string,\n\tdata?: Record<string, unknown>\n): Promise<EndpointOutput> {\n\t// user must have a cookie set\n\tif (!request.locals.userid) {\n\t\treturn { status: 401 };\n\t}\n\n\tconst res = await fetch(`${base}/${resource}`, {\n\t\tmethod: request.method,\n\t\theaders: {\n\t\t\t'content-type': 'application/json'\n\t\t},\n\t\tbody: data && JSON.stringify(data)\n\t});\n\n\t// if the request came from a <form> submission, the browser's default\n\t// behaviour is to show the URL corresponding to the form's \"action\"\n\t// attribute. in those cases, we want to redirect them back to the\n\t// /todos page, rather than showing the response\n\tif (res.ok && request.method !== 'GET' && request.headers.accept !== 'application/json') {\n\t\treturn {\n\t\t\tstatus: 303,\n\t\t\theaders: {\n\t\t\t\tlocation: '/todos'\n\t\t\t}\n\t\t};\n\t}\n\n\treturn {\n\t\tstatus: res.status,\n\t\tbody: await res.json()\n\t};\n}\n" | ||
}, | ||
@@ -48,0 +48,0 @@ { |
{ | ||
"name": "create-svelte", | ||
"version": "2.0.0-next.83", | ||
"version": "2.0.0-next.84", | ||
"repository": { | ||
@@ -16,3 +16,3 @@ "type": "git", | ||
"devDependencies": { | ||
"@sveltejs/kit": "1.0.0-next.184", | ||
"@sveltejs/kit": "1.0.0-next.188", | ||
"@types/gitignore-parser": "^0.0.0", | ||
@@ -25,3 +25,3 @@ "@types/prettier": "^2.4.1", | ||
"sucrase": "^3.20.2", | ||
"svelte": "^3.43.1", | ||
"svelte": "^3.44.0", | ||
"svelte-preprocess": "^4.9.8", | ||
@@ -28,0 +28,0 @@ "tiny-glob": "^0.2.9" |
543951
800