First commit

This commit is contained in:
pswsm 2023-02-03 15:06:55 +01:00
commit 5f3cf38575
S'han modificat 17 arxius amb 1891 adicions i 0 eliminacions

10
.gitignore vendido Normal file
Veure arxiu

@ -0,0 +1,10 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*

1
.npmrc Normal file
Veure arxiu

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

38
README.md Normal file
Veure arxiu

@ -0,0 +1,38 @@
# 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
If you're seeing this, you've probably already done this step. Congrats!
```bash
# create a new project in the current directory
npm create svelte@latest
# create a new project in my-app
npm create svelte@latest my-app
```
## Developing
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
```bash
npm run dev
# or start the server and open the app in a new browser tab
npm run dev -- --open
```
## Building
To create a production version of your app:
```bash
npm run build
```
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.

1641
package-lock.json generado Normal file

La diferencia del archivo ha sido suprimido porque es demasiado grande Cargar Diff

22
package.json Normal file
Veure arxiu

@ -0,0 +1,22 @@
{
"name": "svelte-ts",
"version": "0.0.1",
"private": true,
"scripts": {
"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": {
"@sveltejs/adapter-auto": "^1.0.0",
"@sveltejs/kit": "^1.0.0",
"svelte": "^3.54.0",
"svelte-check": "^3.0.1",
"tslib": "^2.4.1",
"typescript": "^4.9.3",
"vite": "^4.0.0"
},
"type": "module"
}

12
src/app.d.ts vendido Normal file
Veure arxiu

@ -0,0 +1,12 @@
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface Platform {}
}
}
export {};

12
src/app.html Normal file
Veure arxiu

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>

23
src/classes/NavObject.ts Normal file
Veure arxiu

@ -0,0 +1,23 @@
export class NavbarObject {
private _link: string;
private _text: string;
constructor(link: string, text: string) {
this._link = link;
this._text = text;
}
/**
* get link
*/
public get link() {
return this._link;
}
/**
* get text
*/
public get text() {
return this._text;
}
}

Veure arxiu

@ -0,0 +1,33 @@
<script lang="ts">
import { NavbarObject } from "../classes/NavObject";
export let navobjs = [new NavbarObject('/#', 'No nav elements provided')]
</script>
<nav>
{#each navobjs as navobj}
<a href='{navobj.link}'><div class="nav-elem">{navobj.text}</div></a>
{/each}
</nav>
<style>
nav {
background-color: red;
width: 100%;
box-sizing: border-box;
color: white;
display: flex;
flex-direction: row;
}
.nav-elem {
padding: 1.5rem;
}
.nav-elem:hover {
background-color: darkred;
}
a {
text-decoration: none;
color: inherit;
}
</style>

Veure arxiu

@ -0,0 +1,8 @@
<script lang="ts">
import { NavbarObject } from "../classes/NavObject";
import Navbar from "../components/navbar.svelte";
let navbarElemenets: NavbarObject[] = [new NavbarObject('/', 'Home'), new NavbarObject('/aaaa', 'aaaa'), new NavbarObject('/test1', 'test1')]
</script>
<Navbar navobjs={navbarElemenets} />
<slot />

2
src/routes/+page.svelte Normal file
Veure arxiu

@ -0,0 +1,2 @@
<h1>Welcome to SvelteKit</h1>
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>

Veure arxiu

@ -0,0 +1,27 @@
const headers = { 'X-API-KEY': '', 'Content-type': 'application/json' }
let location: string = "L'Hospitalet de Llobregat";
let municipis = await fetch('https://api.meteo.cat/referencia/v1/municipis', { method: 'GET', headers: new Headers(headers), credentials: 'include' }).then( (data) => data.json() );
export function load(): { location: string, weatherData: Promise<any> } {
return { location: location, weatherData: getCityCode( location ) }
};
function changeLocation(newLoc: string) {
location = newLoc;
}
export const actions = {
changeLoc: async ({ request }) => {
const data: FormData = await request.formData();
changeLocation(data.get('newloc'));
}
}
async function getWeather(): Promise<any> {
let response = await fetch('https://api.meteo.cat/referencia/v1/municipis', { method: 'GET', headers: new Headers(headers), credentials: 'include' })
return response.json();
}
function getCityCode(locName: string) {
return municipis.filter( municipi => municipi["nom"].startsWith(location) )
}

Veure arxiu

@ -0,0 +1,22 @@
<script lang="ts">
import { enhance } from "$app/forms";
let display: string = 'none';
export let data: any;
function toggleDisplay(): void {
display = (display === 'none') ? 'block' : 'none';
}
</script>
<div class="box" id="locChange" style="display: {display};">
<form action="?/changeLoc" method="post" use:enhance>
<p>Change location</p>
<div class="schBox"><input type="text" placeholder="Change location" name='newloc'></div>
<button type="button">Change location</button>
</form>
</div>
<p>Weather in {data.location}:</p>
<button type="button" on:click={toggleDisplay}>Change location</button>
<br>
<pre>{ JSON.stringify(data.weatherData) }</pre>

BIN
static/favicon.png Normal file

Archivo binario no mostrado.

Desprès

Amplada:  |  Alçada:  |  Mida: 1,5 KiB

15
svelte.config.js Normal file
Veure arxiu

@ -0,0 +1,15 @@
import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/kit/vite';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
// for more information about preprocessors
preprocess: vitePreprocess(),
kit: {
adapter: adapter()
}
};
export default config;

17
tsconfig.json Normal file
Veure arxiu

@ -0,0 +1,17 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"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
}

8
vite.config.ts Normal file
Veure arxiu

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