Update to svelte 5

This commit is contained in:
2025-10-13 16:05:50 +02:00
parent f936e4c0f2
commit 6d89c5ddd9
129 changed files with 2443 additions and 2180 deletions

View File

@@ -1,10 +1,10 @@
<script lang="ts" context="module">
<script lang="ts" module>
export type FormConfig = {
fields: FormField[],
submit_label: string
submit_red?: boolean,
on_submit: (values: {[key: string]: string}) => Promise<SubmitResult>,
}
};
export type FormField = {
type: string,
name?: string,
@@ -15,20 +15,22 @@ export type FormField = {
radio_values?: string[], // Options to choose from when type is "radio"
pattern?: string, // Used for pattern matching on input fields
binding?: any
}
};
export type SubmitResult = {
success: boolean,
message?: string,
messages?: string[],
error_json?: GenericResponse,
}
};
</script>
<script lang="ts">
import { onMount } from "svelte";
import Spinner from "./Spinner.svelte";
import type { GenericResponse } from "lib/PixeldrainAPI";
export let config: FormConfig
let { config }: {
config: FormConfig;
} = $props();
onMount(() => {
config.fields.forEach(field => {
@@ -38,9 +40,9 @@ onMount(() => {
})
})
let loading = false
let submitted = false
let submit_result: SubmitResult
let loading = $state(false)
let submitted = $state(false)
let submit_result: SubmitResult = $state()
const submit = async (event: SubmitEvent) => {
loading = true
@@ -117,7 +119,7 @@ const handle_errors = (response: GenericResponse) => {
}
</script>
<form method="POST" on:submit={submit}>
<form method="POST" onsubmit={submit}>
{#if submitted && submit_result !== undefined}
{#if submit_result.messages}
<div id="submit_result" class:highlight_green={submit_result.success} class:highlight_red={!submit_result.success}>