sveltekit-superforms
Advanced tools
Comparing version 2.0.0-alpha.49 to 2.0.0-alpha.51
@@ -8,3 +8,3 @@ import type { JSONSchema } from '../jsonSchema/index.js'; | ||
export type InferIn<T extends Schema> = NonNullable<InferInSchema<T>>; | ||
export type ValidationLibrary = 'ajv' | 'arktype' | 'custom' | 'joi' | 'superform' | 'superstruct' | 'typebox' | 'valibot' | 'yup' | 'zod'; | ||
export type ValidationLibrary = 'arktype' | 'custom' | 'joi' | 'superform' | 'typebox' | 'valibot' | 'yup' | 'zod'; | ||
export type AdapterOptions<T extends Schema> = { | ||
@@ -11,0 +11,0 @@ jsonSchema?: JSONSchema; |
@@ -1,2 +0,2 @@ | ||
export type { ValidationAdapter } from './adapters.js'; | ||
export type { ValidationAdapter, Infer, InferIn } from './adapters.js'; | ||
export { arktype, arktypeClient } from './arktype.js'; | ||
@@ -3,0 +3,0 @@ export { joi, joiClient } from './joi.js'; |
@@ -1,5 +0,4 @@ | ||
import type { SchemaObject } from 'ajv'; | ||
import type { TSchema, Static as Static$1 } from '@sinclair/typebox'; | ||
import type { Type } from 'arktype'; | ||
import type { AnySchema } from 'joi'; | ||
import type { TSchema, Static as Static$1 } from '@sinclair/typebox'; | ||
import type { BaseSchema, BaseSchemaAsync, Input, Output } from 'valibot'; | ||
@@ -37,5 +36,2 @@ import type { Schema as Schema$2, InferType } from 'yup'; | ||
}; | ||
interface AjvResolver extends Resolver { | ||
base: SchemaObject; | ||
} | ||
interface ArkTypeResolver extends Resolver { | ||
@@ -76,3 +72,2 @@ base: Type; | ||
type Registry = { | ||
ajv: AjvResolver; | ||
arktype: ArkTypeResolver; | ||
@@ -79,0 +74,0 @@ custom: CustomResolver; |
@@ -39,2 +39,3 @@ /** @typedef {typeof __propDef.props} SuperDebugProps */ | ||
collapsed?: boolean | undefined; | ||
children?: any; | ||
}, { | ||
@@ -64,2 +65,3 @@ [evt: string]: CustomEvent<any>; | ||
collapsed?: boolean | undefined; | ||
children?: any; | ||
}; | ||
@@ -66,0 +68,0 @@ events: { |
@@ -309,2 +309,6 @@ import { derived, get, readonly, writable } from 'svelte/store'; | ||
* Make a client-side validation, updating the form data if successful. | ||
* @param event A change event, from html input or programmatically | ||
* @param force Is true if called from validateForm with update: true | ||
* @param adapter ValidationAdapter, if called from validateForm with schema set | ||
* @returns SuperValidated, or undefined if options prevented validation. | ||
*/ | ||
@@ -337,12 +341,14 @@ async function Form_clientValidation(event, force = false, adapter) { | ||
} | ||
if (options.validationMethod == 'oninput' || force) { | ||
/* | ||
if (force) { | ||
Errors.set(result.errors); | ||
return result; | ||
} | ||
*/ | ||
// Wait for tainted, so object errors can be displayed | ||
await tick(); | ||
Form__displayNewErrors(result.errors, event); | ||
Form__displayNewErrors(result.errors, event, force); | ||
return result; | ||
} | ||
async function Form__displayNewErrors(errors, event) { | ||
async function Form__displayNewErrors(errors, event, force) { | ||
const { type, immediate, multiple, paths } = event; | ||
@@ -352,6 +358,7 @@ const previous = Data.errors; | ||
const validity = new Map(); | ||
if (options.customValidity && event.formElement) { | ||
const formElement = event.formElement ?? EnhancedForm; | ||
if (options.customValidity && formElement) { | ||
for (const path of event.paths) { | ||
const name = CSS.escape(mergePath(path)); | ||
const el = event.formElement.querySelector(`[name="${name}"]`); | ||
const el = formElement.querySelector(`[name="${name}"]`); | ||
if (el) { | ||
@@ -371,4 +378,2 @@ const message = 'validationMessage' in el ? String(el.validationMessage) : ''; | ||
} | ||
const isEventError = error.value && | ||
paths.map((path) => path.join('.')).some((path) => path.startsWith(joinedPath)); | ||
function addError() { | ||
@@ -381,2 +386,3 @@ //console.log('Adding error', `[${error.path.join('.')}]`, error.value); //debug | ||
updateCustomValidity(el, error.value); | ||
// Only need one error to display | ||
validity.clear(); | ||
@@ -386,2 +392,8 @@ } | ||
} | ||
if (force) | ||
return addError(); | ||
const isEventError = error.value && | ||
paths.map((path) => path.join('.')).some((path) => path.startsWith(joinedPath)); | ||
if (isEventError && options.validationMethod == 'oninput') | ||
return addError(); | ||
// Immediate, non-multiple input should display the errors | ||
@@ -414,4 +426,5 @@ if (immediate && !multiple && isEventError) | ||
// or the (parent) path is or has been tainted. | ||
if (type == 'blur' && | ||
Tainted_hasBeenTainted(mergePath(error.path.slice(0, -1)))) { | ||
if (options.validationMethod == 'oninput' || | ||
(type == 'blur' && | ||
Tainted_hasBeenTainted(mergePath(error.path.slice(0, -1))))) { | ||
return addError(); | ||
@@ -675,2 +688,4 @@ } | ||
const AllErrors = derived(Errors, ($errors) => ($errors ? flattenErrors($errors) : [])); | ||
// Used for options.customValidity to display errors, even if programmatically set | ||
let EnhancedForm; | ||
///// End of Roles ////////////////////////////////////////////////////////// | ||
@@ -886,2 +901,3 @@ // Need to clear this and set it again when use:enhance has run, to avoid showing the | ||
enhance(FormElement, events) { | ||
EnhancedForm = FormElement; | ||
if (events) { | ||
@@ -946,2 +962,3 @@ if (events.onError) { | ||
FormElement.removeEventListener('input', onInput); | ||
EnhancedForm = undefined; | ||
}); | ||
@@ -1211,4 +1228,9 @@ ///// SvelteKit enhance function ////////////////////////////////// | ||
setTimeout(() => { | ||
if (unsub) | ||
unsub(); | ||
try { | ||
if (unsub) | ||
unsub(); | ||
} | ||
catch { | ||
// If component is already destroyed? | ||
} | ||
}); | ||
@@ -1215,0 +1237,0 @@ if (htmlForm.isSubmitting()) { |
{ | ||
"name": "sveltekit-superforms", | ||
"version": "2.0.0-alpha.49", | ||
"version": "2.0.0-alpha.51", | ||
"author": "Andreas Söderlund <ciscoheat@gmail.com> (https://blog.encodeart.dev)", | ||
@@ -96,8 +96,8 @@ "description": "Making SvelteKit forms a pleasure to use!", | ||
"peerDependencies": { | ||
"@sinclair/typebox": "^0.32.13", | ||
"@sveltejs/kit": "1.x || 2.x", | ||
"svelte": "3.x || 4.x", | ||
"@sinclair/typebox": "^0.32.13", | ||
"arktype": "1.0.29-alpha", | ||
"joi": "^17.12.1", | ||
"superstruct": "^1.0.3", | ||
"svelte": "3.x || 4.x || >=5.0.0-next.51", | ||
"valibot": "^0.28.1", | ||
@@ -161,4 +161,4 @@ "yup": "^1.3.3", | ||
"sass": "^1.70.0", | ||
"svelte": "^4.2.10", | ||
"svelte-check": "^3.6.3", | ||
"svelte": "5.0.0-next.51", | ||
"svelte-check": "^3.6.4", | ||
"sveltekit-flash-message": "^2.4.1", | ||
@@ -165,0 +165,0 @@ "sveltekit-rate-limiter": "^0.4.3", |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
242070
109
5178