sveltekit-superforms
Advanced tools
Comparing version 2.10.1 to 2.10.2
@@ -15,2 +15,3 @@ /// <reference types="svelte" /> | ||
type Nullable<T extends Record<string, unknown>, Path extends FormPaths<T> | FormPathArrays<T> | FormPathLeaves<T>> = null extends FormPathType<T, Path> ? null : never; | ||
type Optional<T extends Record<string, unknown>, Path extends FormPaths<T> | FormPathArrays<T> | FormPathLeaves<T>> = [undefined] extends [FormPathType<T, Path>] ? undefined : never; | ||
type DefaultOptions = { | ||
@@ -36,6 +37,10 @@ trueStringValue: string; | ||
}): Writable<string>; | ||
export declare function fileFieldProxy<T extends Record<string, unknown>, Path extends FormPathLeaves<T, File>>(form: SuperForm<T>, path: Path, options?: ProxyOptions): FormFieldProxy<FileList | File | Nullable<T, Path>, Path>; | ||
export declare function fileProxy<T extends Record<string, unknown>, Path extends FormPathLeaves<T, File>>(form: Writable<T> | SuperForm<T>, path: Path, options?: ProxyOptions): { | ||
export declare function fileFieldProxy<T extends Record<string, unknown>, Path extends FormPathLeaves<T, File>>(form: SuperForm<T>, path: Path, options?: ProxyOptions & { | ||
empty?: 'null' | 'undefined'; | ||
}): FormFieldProxy<FileList | File | Nullable<T, Path> | Optional<T, Path>, Path>; | ||
export declare function fileProxy<T extends Record<string, unknown>, Path extends FormPathLeaves<T, File>>(form: Writable<T> | SuperForm<T>, path: Path, options?: ProxyOptions & { | ||
empty?: 'null' | 'undefined'; | ||
}): { | ||
subscribe(this: void, run: (value: FileList) => void): import("svelte/store").Unsubscriber; | ||
set(this: void, file: FileList | File | Nullable<T, Path>): void; | ||
set(this: void, file: FileList | File | Nullable<T, Path> | Optional<T, Path>): void; | ||
update(this: void): never; | ||
@@ -46,4 +51,4 @@ }; | ||
subscribe(run: (value: FileList) => void): import("svelte/store").Unsubscriber; | ||
set(files: FileList | File[] | Nullable<T, Path>): void; | ||
update(updater: Updater<File[] | Nullable<T, Path>>): void; | ||
set(files: FileList | File[] | Nullable<T, Path> | Optional<T, Path>): void; | ||
update(updater: Updater<File[] | Nullable<T, Path> | Optional<T, Path>>): void; | ||
}; | ||
@@ -56,4 +61,4 @@ path: Path; | ||
subscribe(run: (value: FileList) => void): import("svelte/store").Unsubscriber; | ||
set(files: FileList | File[] | Nullable<T, Path>): void; | ||
update(updater: Updater<File[] | Nullable<T, Path>>): void; | ||
set(files: FileList | File[] | Nullable<T, Path> | Optional<T, Path>): void; | ||
update(updater: Updater<File[] | Nullable<T, Path> | Optional<T, Path>>): void; | ||
}; | ||
@@ -60,0 +65,0 @@ type ValueErrors = any[]; |
@@ -51,5 +51,11 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
const fileProxy = writable(browser ? new DataTransfer().files : {}); | ||
let initialized = false; | ||
let initialValue; | ||
formFile.subscribe((file) => { | ||
if (!browser) | ||
return; | ||
if (!initialized) { | ||
initialValue = options?.empty ? (options.empty === 'undefined' ? undefined : null) : file; | ||
initialized = true; | ||
} | ||
const dt = new DataTransfer(); | ||
@@ -78,2 +84,4 @@ if (file) | ||
formFile.set(file.item(0)); | ||
else | ||
formFile.set(initialValue); | ||
}, | ||
@@ -80,0 +88,0 @@ update() { |
{ | ||
"name": "sveltekit-superforms", | ||
"version": "2.10.1", | ||
"version": "2.10.2", | ||
"author": "Andreas Söderlund <ciscoheat@gmail.com> (https://blog.encodeart.dev)", | ||
@@ -5,0 +5,0 @@ "description": "Making SvelteKit forms a pleasure to use!", |
266410
5638