oxform-core 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +751 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +443 -0
- package/dist/index.d.ts +443 -0
- package/dist/index.js +747 -0
- package/dist/index.js.map +1 -0
- package/package.json +20 -15
- package/export/index.ts +0 -7
- package/export/schema.ts +0 -1
- package/src/field-api.constants.ts +0 -15
- package/src/field-api.ts +0 -139
- package/src/form-api.ts +0 -84
- package/src/form-api.types.ts +0 -148
- package/src/form-array-field-api.ts +0 -233
- package/src/form-context-api.ts +0 -232
- package/src/form-field-api.ts +0 -174
- package/src/more-types.ts +0 -178
- package/src/tests/array/append.spec.ts +0 -138
- package/src/tests/array/insert.spec.ts +0 -182
- package/src/tests/array/move.spec.ts +0 -175
- package/src/tests/array/prepend.spec.ts +0 -138
- package/src/tests/array/remove.spec.ts +0 -174
- package/src/tests/array/swap.spec.ts +0 -152
- package/src/tests/array/update.spec.ts +0 -148
- package/src/tests/field/change.spec.ts +0 -226
- package/src/tests/field/reset.spec.ts +0 -617
- package/src/tests/field/set-errors.spec.ts +0 -254
- package/src/tests/field-api/field-api.spec.ts +0 -341
- package/src/tests/form-api/reset.spec.ts +0 -535
- package/src/tests/form-api/submit.spec.ts +0 -409
- package/src/types.ts +0 -5
- package/src/utils/get.ts +0 -5
- package/src/utils/testing/sleep.ts +0 -1
- package/src/utils/testing/tests.ts +0 -18
- package/src/utils/update.ts +0 -6
- package/src/utils/validate.ts +0 -8
- package/tsconfig.json +0 -3
- package/tsdown.config.ts +0 -10
- package/vitest.config.ts +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["array: any[]","Store","Derived","validate","related: string[]","field","context: FormContextApi<Values>","updated: FormIssue[]","Derived"],"sources":["../src/field-api.constants.ts","../src/utils/get.ts","../src/utils/update.ts","../src/form-array-field-api.ts","../src/utils/validate.ts","../src/form-context-api.ts","../src/form-field-api.ts","../src/form-api.ts","../src/field-api.ts","../src/array-field-api.ts"],"sourcesContent":["import type { PersistedFieldMeta, PersistedFormStatus } from '#form-api.types';\n\nexport const defaultMeta = {\n blurred: false,\n touched: false,\n dirty: false,\n} satisfies PersistedFieldMeta;\n\nexport const defaultStatus = {\n submits: 0,\n submitting: false,\n validating: false,\n successful: false,\n dirty: false,\n} satisfies PersistedFormStatus;\n","export const get = (data: unknown, path: (string | number)[]) => {\n return path.reduce((acc, key) => {\n if (acc === undefined) return undefined;\n if (acc === null) return null;\n\n return (acc as any)[key];\n }, data);\n};\n","export type UpdaterFn<TInput, TOutput = TInput> = (input: TInput) => TOutput;\nexport type Updater<TInput, TOutput = TInput> = TOutput | UpdaterFn<TInput, TOutput>;\n\nexport function update<TInput, TOutput = TInput>(updater: Updater<TInput, TOutput>, input: TInput): TOutput {\n return typeof updater === 'function' ? (updater as UpdaterFn<TInput, TOutput>)(input) : updater;\n}\n","import { defaultMeta } from '#field-api.constants';\nimport type { FormApi, FormArrayFields } from '#form-api';\nimport type { FieldChangeOptions } from '#form-api.types';\nimport type { FormContextApi } from '#form-context-api';\nimport type { FormFieldApi } from '#form-field-api';\nimport type { DeepValue, UnwrapOneLevelOfArray } from '#more-types';\nimport { get } from '#utils/get';\nimport { update, type Updater } from '#utils/update';\nimport { stringToPath } from 'remeda';\n\nexport class FormArrayFieldApi<Values> {\n private context: FormContextApi<Values>;\n private field: FormFieldApi<Values>;\n\n constructor({ field, context }: { field: FormFieldApi<Values>; context: FormContextApi<Values> }) {\n this.context = context;\n this.field = field;\n }\n\n public insert = <const Name extends FormArrayFields<FormApi<Values>>>(\n name: Name,\n index: number,\n value: Updater<UnwrapOneLevelOfArray<DeepValue<Values, Name>>>,\n options?: FieldChangeOptions,\n ) => {\n if (index < 0) index = 0;\n\n this.field.change(\n name,\n current => {\n const array = (current as any[]) ?? [];\n\n return [\n ...array.slice(0, index),\n ...(Array.from({ length: index - array.length }, () => undefined) as any[]),\n update(value, current as never),\n ...array.slice(index),\n ] as never;\n },\n options,\n );\n\n this.context.persisted.setState(current => {\n const fields = { ...current.fields };\n const value = get(current.values as never, stringToPath(name)) as any[] | undefined;\n const length = value?.length;\n\n if (length === undefined) return current;\n\n for (let i = index; i < length; i++) {\n const moving = current.fields[`${name}.${i}`];\n fields[`${name}.${i + 1}`] = moving ?? defaultMeta;\n }\n\n fields[`${name}.${index}`] = defaultMeta;\n\n return {\n ...current,\n fields,\n };\n });\n };\n\n public append = <const Name extends FormArrayFields<FormApi<Values>>>(\n name: Name,\n value: UnwrapOneLevelOfArray<DeepValue<Values, Name>>,\n options?: FieldChangeOptions,\n ) => {\n const current = this.field.get(name) as any[];\n return this.insert(name, current?.length ?? 0, value, options);\n };\n\n public prepend = <const Name extends FormArrayFields<FormApi<Values>>>(\n name: Name,\n value: UnwrapOneLevelOfArray<DeepValue<Values, Name>>,\n options?: FieldChangeOptions,\n ) => {\n return this.insert(name, 0, value, options);\n };\n\n public swap = <const Name extends FormArrayFields<FormApi<Values>>>(\n name: Name,\n from: number,\n to: number,\n options?: FieldChangeOptions,\n ) => {\n const start = from >= 0 ? from : 0;\n const end = to >= 0 ? to : 0;\n\n this.field.change(\n name,\n current => {\n const array = (current as any[]) ?? [];\n\n if (start === end) return array as never; // no-op\n\n const a = array[start];\n const b = array[end];\n\n return [...array.slice(0, start), b, ...array.slice(start + 1, end), a, ...array.slice(end + 1)] as never;\n },\n options,\n );\n\n this.context.persisted.setState(current => {\n const fields = { ...current.fields };\n\n fields[`${name}.${start}`] = current.fields[`${name}.${end}`] ?? defaultMeta;\n fields[`${name}.${end}`] = current.fields[`${name}.${start}`] ?? defaultMeta;\n\n return {\n ...current,\n fields,\n };\n });\n };\n\n public move<const Name extends FormArrayFields<FormApi<Values>>>(\n name: Name,\n _from: number,\n _to: number,\n options?: FieldChangeOptions,\n ) {\n const from = Math.max(_from, 0);\n const to = Math.max(_to, 0);\n const backwards = from > to;\n\n this.field.change(\n name,\n current => {\n const array: any[] = current ? [...(current as any[])] : [];\n\n if (from === to) return array as never;\n\n const moved = array[from];\n return array.toSpliced(backwards ? to : to + 1, 0, moved).toSpliced(backwards ? from + 1 : from, 1) as never;\n },\n options,\n );\n\n this.context.persisted.setState(current => {\n const fields = { ...current.fields };\n const value = get(current.values as never, stringToPath(name)) as any[] | undefined;\n const length = value?.length;\n\n const start = Math.min(from, to);\n const end = Math.max(from, to);\n\n if (length === undefined) return current;\n\n if (!backwards) {\n fields[`${name}.${to}`] = current.fields[`${name}.${from}`] ?? defaultMeta;\n }\n\n for (let i = backwards ? start + 1 : start; i < end; i++) {\n const shift = backwards ? -1 : 1;\n const moving = current.fields[`${name}.${i + shift}`];\n fields[`${name}.${i}`] = moving ?? defaultMeta;\n }\n\n return {\n ...current,\n fields,\n };\n });\n }\n\n public update = <const Name extends FormArrayFields<FormApi<Values>>>(\n name: Name,\n index: number,\n value: Updater<UnwrapOneLevelOfArray<DeepValue<Values, Name>>>,\n options?: FieldChangeOptions,\n ) => {\n this.field.change(\n name,\n current => {\n const array = (current as any[]) ?? [];\n const position = Math.max(Math.min(index, array.length - 1), 0);\n\n return [...array.slice(0, position), update(value, current as never), ...array.slice(position + 1)] as never;\n },\n options,\n );\n\n this.context.resetFieldMeta(`${name}.${index}`);\n this.context.setFieldMeta(`${name}.${index}`, {\n dirty: options?.should?.dirty !== false,\n touched: options?.should?.touch !== false,\n });\n };\n\n public remove<const Name extends FormArrayFields<FormApi<Values>>>(\n name: Name,\n index: number,\n options?: FieldChangeOptions,\n ) {\n let position = index;\n\n this.field.change(\n name,\n current => {\n const array = (current as any[]) ?? [];\n position = Math.max(Math.min(index, array.length - 1), 0);\n\n return [...array.slice(0, position), ...array.slice(position + 1)] as never;\n },\n { ...options, should: { ...options?.should, validate: false } },\n );\n\n this.context.persisted.setState(current => {\n const fields = { ...current.fields };\n const value = get(current.values as never, stringToPath(name)) as any[] | undefined;\n const length = value?.length ?? 0;\n\n for (let i = position; i < length; i++) {\n const moving = current.fields[`${name}.${i + 1}`];\n fields[`${name}.${i}`] = moving ?? defaultMeta;\n }\n\n delete fields[`${name}.${length}`];\n\n return {\n ...current,\n fields,\n };\n });\n\n const shouldValidate = options?.should?.validate !== false;\n if (shouldValidate) void this.context.validate(name, { type: 'change' });\n }\n\n public replace<const Name extends FormArrayFields<FormApi<Values>>>(\n name: Name,\n value: Updater<DeepValue<Values, Name>>,\n options?: FieldChangeOptions,\n ) {\n this.context.resetFieldMeta(name);\n this.field.change(name, value as never, options);\n }\n}\n","import type { StandardSchema } from '#types';\n\nexport const validate = async <Schema extends StandardSchema>(schema: Schema, input: unknown) => {\n let result = schema['~standard'].validate(input);\n if (result instanceof Promise) result = await result;\n\n return result as StandardSchema.Result<StandardSchema.InferOutput<Schema>>;\n};\n","import { defaultMeta, defaultStatus } from '#field-api.constants';\nimport type { FormApi, FormFields } from '#form-api';\nimport type {\n FieldMeta,\n FormBaseStore,\n FormIssue,\n FormOptions,\n FormStore,\n PersistedFieldMeta,\n PersistedFormStatus,\n ValidateOptions,\n} from '#form-api.types';\nimport { get } from '#utils/get';\nimport { validate } from '#utils/validate';\nimport { Derived, Store } from '@tanstack/store';\nimport { isDeepEqual, isFunction, mergeDeep, stringToPath } from 'remeda';\n\nexport class FormContextApi<Values> {\n public options!: FormOptions<Values>;\n public persisted: Store<FormBaseStore<Values>>;\n public store!: Derived<FormStore<Values>>;\n\n constructor(options: FormOptions<Values>) {\n const values = mergeDeep(options.defaultValues as never, options.values ?? {}) as Values;\n\n this.options = options;\n\n this.persisted = new Store<FormBaseStore<Values>>({\n values,\n fields: {},\n refs: {},\n status: defaultStatus,\n errors: {},\n });\n\n this.store = new Derived<FormStore<Values>>({\n deps: [this.persisted],\n fn: ({ currDepVals }) => {\n const persisted = currDepVals[0] as FormBaseStore<Values>;\n\n const invalid = Object.values(persisted.errors).some(issues => issues.length > 0);\n const dirty = Object.values(persisted.fields).some(meta => meta.dirty);\n const fields = Object.fromEntries(\n Object.entries(persisted.fields).map(([key, meta]) => {\n return [key, this.buildFieldMeta(key, meta, persisted.values as Values, persisted.errors)];\n }),\n );\n\n return {\n ...persisted,\n fields,\n status: {\n ...persisted.status,\n submitted: persisted.status.submits > 0,\n valid: !invalid,\n dirty: persisted.status.dirty || dirty,\n },\n };\n },\n });\n }\n\n public get status() {\n return this.store.state.status;\n }\n\n public get values() {\n return this.store.state.values;\n }\n\n private get validator() {\n const store = this.store.state;\n const validate = this.options.validate;\n\n return {\n change: isFunction(validate?.change) ? validate.change(store) : validate?.change,\n submit: isFunction(validate?.submit) ? validate.submit(store) : (validate?.submit ?? this.options.schema),\n blur: isFunction(validate?.blur) ? validate.blur(store) : validate?.blur,\n focus: isFunction(validate?.focus) ? validate.focus(store) : validate?.focus,\n };\n }\n\n public buildFieldMeta = (\n fieldName: string,\n persistedMeta: PersistedFieldMeta | undefined,\n values: Values,\n errors: Record<string, FormIssue[]>,\n ): FieldMeta => {\n const path = stringToPath(fieldName);\n const value = get(values as never, path);\n const defaultValue = get(this.options.defaultValues, path);\n const invalid = errors[fieldName]?.length > 0;\n const baseMeta = persistedMeta ?? defaultMeta;\n\n return {\n ...baseMeta,\n default: isDeepEqual(value, defaultValue),\n pristine: !baseMeta.dirty,\n valid: !invalid,\n } satisfies FieldMeta;\n };\n\n public setFieldMeta = (name: string, meta: Partial<PersistedFieldMeta>) => {\n this.persisted.setState(current => {\n return {\n ...current,\n fields: {\n ...current.fields,\n [name]: {\n ...defaultMeta,\n ...this.persisted.state.fields[name],\n ...meta,\n },\n },\n };\n });\n };\n\n public resetFieldMeta = (name: string) => {\n this.persisted.setState(current => {\n const fields = { ...current.fields };\n const all = Object.keys(current.fields);\n const affected = all.filter(key => key.startsWith(name));\n\n for (const key of affected) {\n delete fields[key];\n }\n\n return {\n ...current,\n fields,\n };\n });\n };\n\n public recomputeFieldMeta = (name: string) => {\n this.persisted.setState(current => {\n const related: string[] = this.options.related?.[name as never] ?? [];\n const all = Object.keys(current.fields);\n const affected = all.filter(key => key.startsWith(name) || related.includes(key));\n const updated = affected.reduce(\n (acc, key) => {\n return {\n ...acc,\n [key]: this.buildFieldMeta(key, current.fields[key], current.values as Values, current.errors),\n };\n },\n {} as Record<string, FieldMeta>,\n );\n\n return {\n ...current,\n fields: {\n ...current.fields,\n ...updated,\n },\n };\n });\n };\n\n public setStatus = (status: Partial<PersistedFormStatus>) => {\n this.persisted.setState(current => {\n return {\n ...current,\n status: {\n ...current.status,\n ...status,\n },\n };\n });\n };\n\n public validate = async (\n field?: FormFields<FormApi<Values>> | FormFields<FormApi<Values>>[],\n options?: ValidateOptions,\n ) => {\n const validator = options?.type ? this.validator[options.type] : this.options.schema;\n\n if (!validator) return [];\n\n this.setStatus({ validating: true });\n\n const { issues: allIssues } = await validate(validator, this.store.state.values);\n\n if (!allIssues) {\n this.persisted.setState(current => {\n return { ...current, errors: {}, status: { ...current.status, validating: false } };\n });\n\n return [];\n }\n\n const fields = field ? (Array.isArray(field) ? field : [field]) : undefined;\n const related: string[] = fields?.flatMap(field => this.options.related?.[field as never] ?? []) ?? [];\n const affected = [...(fields ?? []), ...related];\n\n const issues = allIssues.filter(issue => {\n const path = issue.path?.join('.') ?? 'root';\n return !fields || affected.some(key => path.startsWith(key));\n });\n\n const errors = issues.reduce((acc, issue) => {\n const path = issue.path?.join('.') ?? 'root';\n return {\n ...acc,\n [path]: [...(acc[path] ?? []), issue],\n };\n }, {} as any);\n\n this.persisted.setState(current => {\n const existing = { ...current.errors };\n\n for (const key of affected) {\n delete existing[key];\n }\n\n return {\n ...current,\n errors: {\n ...(fields ? existing : {}), // when validating a specific set of fields, keep the existing errors\n ...errors,\n },\n };\n });\n\n this.setStatus({ validating: false });\n\n return issues;\n };\n}\n","import { defaultMeta } from '#field-api.constants';\nimport type { FormApi, FormFields } from '#form-api';\nimport type { FieldChangeOptions, FormIssue, FormResetFieldOptions, FormSetErrorsOptions } from '#form-api.types';\nimport type { FormContextApi } from '#form-context-api';\nimport type { DeepValue } from '#more-types';\nimport { get } from '#utils/get';\nimport { update, type Updater } from '#utils/update';\nimport { batch } from '@tanstack/store';\nimport { setPath, stringToPath } from 'remeda';\n\nexport class FormFieldApi<Values> {\n constructor(private context: FormContextApi<Values>) {}\n\n /**\n * Changes the value of a specific field with optional control over side effects.\n * @param name - The name of the field to change\n * @param value - The new value to set for the field\n * @param options - Optional configuration for controlling validation, dirty state, and touched state\n */\n public change = <const Name extends FormFields<FormApi<Values>>>(\n name: Name,\n updater: Updater<DeepValue<Values, Name>>,\n options?: FieldChangeOptions,\n ) => {\n const shouldDirty = options?.should?.dirty !== false;\n const shouldTouch = options?.should?.touch !== false;\n const shouldValidate = options?.should?.validate !== false;\n\n this.context.persisted.setState(current => {\n const value = get(current.values as never, stringToPath(name)) as DeepValue<Values, Name>;\n\n const values = setPath(\n current.values as never,\n stringToPath(name) as never,\n update(updater, value) as never,\n ) as Values;\n\n return {\n ...current,\n values,\n };\n });\n\n if (shouldValidate) void this.context.validate(name, { type: 'change' });\n\n batch(() => {\n if (shouldDirty) this.context.setFieldMeta(name, { dirty: true });\n if (shouldTouch) this.context.setFieldMeta(name, { touched: true });\n });\n };\n\n public focus = <const Name extends FormFields<FormApi<Values>>>(name: Name) => {\n const ref = this.context.store.state.refs[name as never];\n\n if (ref) ref.focus();\n\n this.context.setFieldMeta(name as never, { touched: true });\n void this.context.validate(name as never, { type: 'focus' });\n };\n\n public blur = <const Name extends FormFields<FormApi<Values>>>(name: Name) => {\n const ref = this.context.store.state.refs[name as never];\n\n if (ref) ref.blur();\n\n this.context.setFieldMeta(name as never, { blurred: true });\n void this.context.validate(name as never, { type: 'blur' });\n };\n\n public get = <const Name extends FormFields<FormApi<Values>>>(name: Name) => {\n return get(this.context.store.state.values as never, stringToPath(name)) as DeepValue<Values, Name>;\n };\n\n public meta = <const Name extends FormFields<FormApi<Values>>>(name: Name) => {\n const meta = this.context.store.state.fields[name];\n\n if (meta) return meta;\n\n const updated = this.context.buildFieldMeta(\n name,\n undefined,\n this.context.store.state.values as Values,\n this.context.store.state.errors,\n );\n\n this.context.setFieldMeta(name, updated);\n\n return updated;\n };\n\n public register = <const Name extends FormFields<FormApi<Values>>>(name: Name) => {\n return (element: HTMLElement | null) => {\n if (!element) return;\n\n this.context.persisted.setState(current => {\n return {\n ...current,\n refs: {\n ...current.refs,\n [name]: element,\n },\n };\n });\n };\n };\n\n public errors = <const Name extends FormFields<FormApi<Values>>>(name: Name) => {\n return this.context.store.state.errors[name] ?? [];\n };\n\n public setErrors = <const Name extends FormFields<FormApi<Values>>>(\n name: Name,\n errors: FormIssue[],\n options?: FormSetErrorsOptions,\n ) => {\n this.context.persisted.setState(current => {\n const existing = current.errors[name] ?? [];\n let updated: FormIssue[];\n\n switch (options?.mode) {\n case 'append':\n updated = [...existing, ...errors];\n break;\n case 'keep':\n updated = existing.length > 0 ? existing : errors;\n break;\n case 'replace':\n default:\n updated = errors;\n break;\n }\n\n return {\n ...current,\n errors: {\n ...current.errors,\n [name]: updated,\n },\n };\n });\n };\n\n public reset = <const Name extends FormFields<FormApi<Values>>>(\n name: Name,\n options?: FormResetFieldOptions<DeepValue<Values, Name>>,\n ) => {\n const path = stringToPath(name as never);\n const defaultValue = get(this.context.options.defaultValues, path) as DeepValue<Values, Name>;\n const value = options?.value ?? defaultValue;\n\n this.context.persisted.setState(current => {\n const values = setPath(current.values as never, path as never, value as never);\n const fields = { ...current.fields };\n const refs = { ...current.refs };\n const errors = { ...current.errors };\n\n if (options?.meta) {\n const currentMeta = options?.keep?.meta ? (fields[name as string] ?? defaultMeta) : defaultMeta;\n fields[name as string] = {\n ...currentMeta,\n ...options.meta,\n };\n } else if (!options?.keep?.meta) delete fields[name as string];\n\n if (!options?.keep?.refs) delete refs[name as string];\n if (!options?.keep?.errors) delete errors[name as string];\n\n return {\n ...current,\n values,\n fields,\n refs,\n errors,\n };\n });\n };\n}\n","import { defaultStatus } from '#field-api.constants';\nimport type { FormOptions, FormResetOptions, FormSubmitErrorHandler, FormSubmitSuccessHandler } from '#form-api.types';\nimport { FormArrayFieldApi } from '#form-array-field-api';\nimport { FormContextApi } from '#form-context-api';\nimport { FormFieldApi } from '#form-field-api';\nimport type { DeepKeys, DeepKeysOfType, DeepValue } from '#more-types';\nimport type { ArrayLike, StandardSchema } from '#types';\n\nexport type AnyFormApi = FormApi<any>;\n\nexport type FormValues<Form extends AnyFormApi> = Form extends FormApi<infer Values> ? Values : never;\nexport type FormFields<Form extends AnyFormApi> = DeepKeys<FormValues<Form>>;\nexport type FormArrayFields<Form extends AnyFormApi> = DeepKeysOfType<FormValues<Form>, ArrayLike>;\nexport type FormFieldValue<Form extends AnyFormApi, Name extends FormFields<Form>> = DeepValue<FormValues<Form>, Name>;\n\nexport class FormApi<Values> {\n private context: FormContextApi<Values>;\n public field: FormFieldApi<Values>;\n public array: FormArrayFieldApi<Values>;\n\n constructor(options: FormOptions<Values>) {\n // todo: add form id to options\n\n this.context = new FormContextApi(options);\n this.field = new FormFieldApi(this.context);\n this.array = new FormArrayFieldApi({ field: this.field, context: this.context });\n }\n\n public '~mount' = () => {\n const unsubscribe = this.context.store.mount();\n\n return unsubscribe;\n };\n\n public '~update' = (options: FormOptions<Values>) => {\n this.context.options = options;\n };\n\n public store = () => {\n return this.context.store;\n };\n\n public status = () => {\n return this.context.store.state.status;\n };\n\n public values = () => {\n return this.context.store.state.values;\n };\n\n public options = () => {\n return this.context.options;\n };\n\n public get validate() {\n return this.context.validate;\n }\n\n public submit =\n (\n onSuccess: FormSubmitSuccessHandler<StandardSchema<Values>>,\n onError?: FormSubmitErrorHandler<StandardSchema<Values>>,\n ) =>\n async () => {\n this.context.setStatus({ submitting: true, dirty: true });\n\n const issues = await this.context.validate(undefined, { type: 'submit' });\n const valid = issues.length === 0;\n\n if (valid) {\n await onSuccess(this.context.store.state.values as never, this as never);\n } else {\n await onError?.(issues, this as never);\n }\n\n this.context.setStatus({\n submits: this.context.persisted.state.status.submits + 1,\n submitting: false,\n successful: valid,\n });\n };\n\n public reset = (options?: FormResetOptions<Values>) => {\n this.context.persisted.setState(current => {\n return {\n values: options?.values ?? this.context.options.defaultValues,\n fields: options?.keep?.fields ? current.fields : {},\n refs: options?.keep?.refs ? current.refs : {},\n errors: options?.keep?.errors ? current.errors : {},\n status: {\n ...defaultStatus,\n ...options?.status,\n },\n };\n });\n };\n}\n","import { type AnyFormApi, type FormFields, type FormFieldValue } from '#form-api';\nimport type {\n FieldChangeOptions,\n FieldMeta,\n FormIssue,\n FormResetFieldOptions,\n FormSetErrorsOptions,\n ValidateOptions,\n} from '#form-api.types';\nimport { get } from '#utils/get';\nimport type { Updater } from '#utils/update';\nimport { Derived } from '@tanstack/store';\nimport { isDeepEqual, stringToPath } from 'remeda';\n\nexport type FieldOptions<Form extends AnyFormApi, Name extends FormFields<Form>> = {\n form: Form;\n name: Name;\n};\n\nexport type FieldState<Value> = {\n value: Value;\n defaultValue: Value;\n meta: FieldMeta;\n errors: FormIssue[];\n};\n\nexport type AnyFieldApi = FieldApi<any>;\n\nexport class FieldApi<Value> {\n private _options: FieldOptions<AnyFormApi, string>;\n private form: AnyFormApi;\n private _store: Derived<FieldState<Value>>;\n\n constructor(options: FieldOptions<AnyFormApi, string>) {\n this._options = options;\n this.form = options.form;\n\n this._store = new Derived<FieldState<Value>>({\n deps: [this.form.store()],\n fn: ({ prevVal }) => {\n const previous = prevVal as FieldState<Value> | undefined;\n\n const value = this.form.field.get(this._options.name as never) as Value;\n const defaultValue = get(this.form.options().defaultValues as never, stringToPath(this._options.name)) as Value;\n const meta = this.form.field.meta(this._options.name as never);\n const errors = this.form.field.errors(this._options.name as never);\n\n const updated = {\n value,\n defaultValue,\n meta,\n errors,\n };\n\n if (previous && isDeepEqual(previous, updated)) return previous;\n\n return updated;\n },\n });\n }\n\n public '~mount' = () => {\n const unsubscribe = this._store.mount();\n\n return unsubscribe;\n };\n\n public '~update' = (options: FieldOptions<AnyFormApi, string>) => {\n // ref: https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1300\n this._options = options;\n };\n\n public options = () => {\n return this._options;\n };\n\n public store = () => {\n return this._store;\n };\n\n public state = () => {\n return this._store.state;\n };\n\n public focus = () => {\n return this.form.field.focus(this._options.name);\n };\n\n public blur = () => {\n return this.form.field.blur(this._options.name);\n };\n\n /**\n * Changes the value of this field with optional control over side effects.\n * @param value - The new value to set for the field\n * @param options - Optional configuration for controlling validation, dirty state, and touched state\n */\n public change = (value: Updater<Value>, options?: FieldChangeOptions) => {\n return this.form.field.change(this._options.name, value as never, options);\n };\n\n public register = () => this.form.field.register(this._options.name);\n\n /**\n * Validates this specific field using the specified validation type.\n * @param options - Optional validation options specifying the validation type ('change' | 'submit' | 'blur' | 'focus')\n * @returns Promise resolving to an array of validation issues for this field\n */\n public validate = (options?: ValidateOptions) => {\n return this.form.validate(this._options.name, options);\n };\n\n /**\n * Resets this field to its default value and optionally resets metadata and errors.\n * @param options - Reset options for controlling what gets reset and what gets kept\n */\n public reset = (options?: FormResetFieldOptions<Value>) => {\n return this.form.field.reset(this._options.name, options);\n };\n\n /**\n * Sets validation errors for this specific field.\n * @param errors - Array of validation errors to set\n * @param mode - How to handle existing errors: 'replace' (default), 'append', or 'keep'\n */\n public setErrors = (errors: FormIssue[], options?: FormSetErrorsOptions) => {\n return this.form.field.setErrors(this._options.name, errors, options);\n };\n}\n\nexport const createFieldApi = <Form extends AnyFormApi, const Name extends FormFields<Form>>(\n options: FieldOptions<Form, Name>,\n) => {\n type Value = FormFieldValue<Form, Name>;\n\n return new FieldApi(options) as FieldApi<Value>;\n};\n\n// const schema = z.object({ name: z.string(), nested: z.object({ deep: z.object({ deeper: z.string().array() }) }) });\n// const form = new FormApi({ schema });\n// const field = createFieldApi({ form, name: 'name' });\n","import { FieldApi, type FieldOptions } from '#field-api';\nimport { type AnyFormApi, type FormArrayFields, type FormFieldValue } from '#form-api';\nimport type {\n FieldChangeOptions,\n FormIssue,\n FormResetFieldOptions,\n FormSetErrorsOptions,\n ValidateOptions,\n} from '#form-api.types';\nimport type { UnwrapOneLevelOfArray } from '#more-types';\nimport type { ArrayLike } from '#types';\nimport type { Updater } from '#utils/update';\n\nexport type ArrayFieldOptions<Form extends AnyFormApi, Name extends FormArrayFields<Form>> = {\n form: Form;\n name: Name;\n};\n\nexport type AnyArrayFieldApi = ArrayFieldApi<any>;\n\nexport class ArrayFieldApi<Value extends ArrayLike> {\n private field: FieldApi<Value>;\n\n constructor(options: FieldOptions<AnyFormApi, string>) {\n this.field = new FieldApi<Value>(options);\n }\n\n private get _options() {\n return this.field.options();\n }\n\n public '~mount' = () => {\n const unsubscribe = this.field.store().mount();\n\n return unsubscribe;\n };\n\n public '~update' = (options: FieldOptions<AnyFormApi, string>) => {\n this.field['~update'](options);\n };\n\n public store = () => {\n return this.field.store();\n };\n\n public state = () => {\n return this.field.store().state;\n };\n\n /**\n * Appends a new item to the end of the array.\n * @param value - The value to append to the array\n * @param options - Optional configuration for controlling validation, dirty state, and touched state\n */\n public append = (value: UnwrapOneLevelOfArray<Value>, options?: FieldChangeOptions) => {\n return this._options.form.array.append(this._options.name as never, value as never, options);\n };\n\n /**\n * Prepends a new item to the beginning of the array.\n * @param value - The value to prepend to the array\n * @param options - Optional configuration for controlling validation, dirty state, and touched state\n */\n public prepend = (value: UnwrapOneLevelOfArray<Value>, options?: FieldChangeOptions) => {\n return this._options.form.array.prepend(this._options.name as never, value as never, options);\n };\n\n /**\n * Inserts a new item at the specified index in the array.\n * @param index - The index at which to insert the value\n * @param value - The value to insert into the array\n * @param options - Optional configuration for controlling validation, dirty state, and touched state\n */\n public insert = (index: number, value: Updater<UnwrapOneLevelOfArray<Value>>, options?: FieldChangeOptions) => {\n return this._options.form.array.insert(this._options.name as never, index, value as never, options);\n };\n\n /**\n * Updates an item at the specified index in the array.\n * @param index - The index of the item to update\n * @param value - The new value or updater function\n * @param options - Optional configuration for controlling validation, dirty state, and touched state\n */\n public update = (index: number, value: Updater<UnwrapOneLevelOfArray<Value>>, options?: FieldChangeOptions) => {\n return this._options.form.array.update(this._options.name as never, index, value as never, options);\n };\n\n /**\n * Removes an item at the specified index from the array.\n * @param index - The index of the item to remove\n * @param options - Optional configuration for controlling validation, dirty state, and touched state\n */\n public remove = (index: number, options?: FieldChangeOptions) => {\n return this._options.form.array.remove(this._options.name as never, index, options);\n };\n\n /**\n * Swaps two items in the array by their indices.\n * @param from - The index of the first item\n * @param to - The index of the second item\n * @param options - Optional configuration for controlling validation, dirty state, and touched state\n */\n public swap = (from: number, to: number, options?: FieldChangeOptions) => {\n return this._options.form.array.swap(this._options.name as never, from, to, options);\n };\n\n /**\n * Moves an item from one index to another in the array.\n * @param from - The index of the item to move\n * @param to - The target index\n * @param options - Optional configuration for controlling validation, dirty state, and touched state\n */\n public move = (from: number, to: number, options?: FieldChangeOptions) => {\n return this._options.form.array.move(this._options.name as never, from, to, options);\n };\n\n /**\n * Replaces the entire array with a new value.\n * @param value - The new array value or updater function\n * @param options - Optional configuration for controlling validation, dirty state, and touched state\n */\n public replace = (value: Updater<Value>, options?: FieldChangeOptions) => {\n return this._options.form.array.replace(this._options.name as never, value as never, options);\n };\n\n /**\n * Validates this specific array field using the specified validation type.\n * @param options - Optional validation options specifying the validation type ('change' | 'submit' | 'blur' | 'focus')\n * @returns Promise resolving to an array of validation issues for this field\n */\n public validate = (options?: ValidateOptions) => {\n return this._options.form.validate(this._options.name, options);\n };\n\n /**\n * Resets this array field to its default value and optionally resets metadata and errors.\n * @param options - Reset options for controlling what gets reset and what gets kept\n */\n public reset = (options?: FormResetFieldOptions<Value>) => {\n return this._options.form.field.reset(this._options.name, options);\n };\n\n /**\n * Sets validation errors for this specific array field.\n * @param errors - Array of validation errors to set\n * @param mode - How to handle existing errors: 'replace' (default), 'append', or 'keep'\n */\n public setErrors = (errors: FormIssue[], options?: FormSetErrorsOptions) => {\n return this._options.form.field.setErrors(this._options.name, errors, options);\n };\n}\n\nexport const createArrayFieldApi = <FormApi extends AnyFormApi, const Name extends FormArrayFields<FormApi>>(\n options: ArrayFieldOptions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S,MAAM,QAAQ;;;;;;;CAQpE,AAAO,aAAa,QAAqB,YAAmC;AAC1E,SAAO,KAAK,SAAS,KAAK,MAAM,UAAU,KAAK,SAAS,MAAM,QAAQ,QAAQ;;;AAIlF,MAAa,uBACX,YACG;AACH,QAAO,IAAI,cAAc,QAAQ"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
import * as _standard_schema_spec1 from "@standard-schema/spec";
|
|
2
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
+
import { PartialDeep, Simplify } from "type-fest";
|
|
4
|
+
import * as _tanstack_store0 from "@tanstack/store";
|
|
5
|
+
import { Derived, Store } from "@tanstack/store";
|
|
6
|
+
|
|
7
|
+
//#region src/more-types.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
type UnwrapOneLevelOfArray<T> = T extends (infer U)[] ? U : T;
|
|
12
|
+
type Narrowable = string | number | bigint | boolean;
|
|
13
|
+
type NarrowRaw<A> = (A extends [] ? [] : never) | (A extends Narrowable ? A : never) | { [K in keyof A]: A[K] extends Function ? A[K] : NarrowRaw<A[K]> };
|
|
14
|
+
type Try<A1, A2, Catch = never> = A1 extends A2 ? A1 : Catch;
|
|
15
|
+
/**
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
type Narrow<A> = Try<A, [], NarrowRaw<A>>;
|
|
19
|
+
interface AnyDeepKeyAndValue<K$1 extends string = string, V extends any = any> {
|
|
20
|
+
key: K$1;
|
|
21
|
+
value: V;
|
|
22
|
+
}
|
|
23
|
+
type ArrayAccessor<TParent extends AnyDeepKeyAndValue> = `${TParent['key'] extends never ? '' : TParent['key']}.${number}`;
|
|
24
|
+
interface ArrayDeepKeyAndValue<in out TParent extends AnyDeepKeyAndValue, in out T extends ReadonlyArray<any>> extends AnyDeepKeyAndValue {
|
|
25
|
+
key: ArrayAccessor<TParent>;
|
|
26
|
+
value: T[number] | Nullable<TParent['value']>;
|
|
27
|
+
}
|
|
28
|
+
type DeepKeyAndValueArray<TParent extends AnyDeepKeyAndValue, T extends ReadonlyArray<any>, TAcc> = DeepKeysAndValuesImpl<NonNullable<T[number]>, ArrayDeepKeyAndValue<TParent, T>, TAcc | ArrayDeepKeyAndValue<TParent, T>>;
|
|
29
|
+
type TupleAccessor<TParent extends AnyDeepKeyAndValue, TKey extends string> = `${TParent['key'] extends never ? '' : TParent['key']}[${TKey}]`;
|
|
30
|
+
interface TupleDeepKeyAndValue<in out TParent extends AnyDeepKeyAndValue, in out T, in out TKey extends AllTupleKeys<T>> extends AnyDeepKeyAndValue {
|
|
31
|
+
key: TupleAccessor<TParent, TKey>;
|
|
32
|
+
value: T[TKey] | Nullable<TParent['value']>;
|
|
33
|
+
}
|
|
34
|
+
type AllTupleKeys<T> = T extends any ? keyof T & `${number}` : never;
|
|
35
|
+
type DeepKeyAndValueTuple<TParent extends AnyDeepKeyAndValue, T extends ReadonlyArray<any>, TAcc, TAllKeys extends AllTupleKeys<T> = AllTupleKeys<T>> = TAllKeys extends any ? DeepKeysAndValuesImpl<NonNullable<T[TAllKeys]>, TupleDeepKeyAndValue<TParent, T, TAllKeys>, TAcc | TupleDeepKeyAndValue<TParent, T, TAllKeys>> : never;
|
|
36
|
+
type AllObjectKeys<T> = T extends any ? keyof T & (string | number) : never;
|
|
37
|
+
type ObjectAccessor<TParent extends AnyDeepKeyAndValue, TKey extends string | number> = TParent['key'] extends never ? `${TKey}` : `${TParent['key']}.${TKey}`;
|
|
38
|
+
type Nullable<T> = T & (undefined | null);
|
|
39
|
+
type ObjectValue<TParent extends AnyDeepKeyAndValue, T, TKey extends AllObjectKeys<T>> = T[TKey] | Nullable<TParent['value']>;
|
|
40
|
+
interface ObjectDeepKeyAndValue<in out TParent extends AnyDeepKeyAndValue, in out T, in out TKey extends AllObjectKeys<T>> extends AnyDeepKeyAndValue {
|
|
41
|
+
key: ObjectAccessor<TParent, TKey>;
|
|
42
|
+
value: ObjectValue<TParent, T, TKey>;
|
|
43
|
+
}
|
|
44
|
+
type DeepKeyAndValueObject<TParent extends AnyDeepKeyAndValue, T, TAcc, TAllKeys extends AllObjectKeys<T> = AllObjectKeys<T>> = TAllKeys extends any ? DeepKeysAndValuesImpl<NonNullable<T[TAllKeys]>, ObjectDeepKeyAndValue<TParent, T, TAllKeys>, TAcc | ObjectDeepKeyAndValue<TParent, T, TAllKeys>> : never;
|
|
45
|
+
type UnknownAccessor<TParent extends AnyDeepKeyAndValue> = TParent['key'] extends never ? string : `${TParent['key']}.${string}`;
|
|
46
|
+
interface UnknownDeepKeyAndValue<TParent extends AnyDeepKeyAndValue> extends AnyDeepKeyAndValue {
|
|
47
|
+
key: UnknownAccessor<TParent>;
|
|
48
|
+
value: unknown;
|
|
49
|
+
}
|
|
50
|
+
type DeepKeysAndValues<T> = DeepKeysAndValuesImpl<T> extends AnyDeepKeyAndValue ? DeepKeysAndValuesImpl<T> : never;
|
|
51
|
+
type DeepKeysAndValuesImpl<T, TParent extends AnyDeepKeyAndValue = never, TAcc = never> = unknown extends T ? TAcc | UnknownDeepKeyAndValue<TParent> : unknown extends T ? T : T extends string | number | boolean | bigint | Date ? TAcc : T extends ReadonlyArray<any> ? number extends T['length'] ? DeepKeyAndValueArray<TParent, T, TAcc> : DeepKeyAndValueTuple<TParent, T, TAcc> : keyof T extends never ? TAcc | UnknownDeepKeyAndValue<TParent> : T extends object ? DeepKeyAndValueObject<TParent, T, TAcc> : TAcc;
|
|
52
|
+
type DeepRecord<T> = { [TRecord in DeepKeysAndValues<T> as TRecord['key']]: TRecord['value'] };
|
|
53
|
+
/**
|
|
54
|
+
* The keys of an object or array, deeply nested.
|
|
55
|
+
*/
|
|
56
|
+
type DeepKeys<T> = unknown extends T ? string : DeepKeysAndValues<T>['key'];
|
|
57
|
+
/**
|
|
58
|
+
* Infer the type of a deeply nested property within an object or an array.
|
|
59
|
+
*/
|
|
60
|
+
type DeepValue<TValue, TAccessor> = unknown extends TValue ? TValue : TAccessor extends DeepKeys<TValue> ? DeepRecord<TValue>[TAccessor] : never;
|
|
61
|
+
/**
|
|
62
|
+
* The keys of an object or array, deeply nested and only with a value of TValue
|
|
63
|
+
*/
|
|
64
|
+
type DeepKeysOfType<TData, TValue> = Extract<DeepKeysAndValues<TData>, AnyDeepKeyAndValue<string, TValue>>['key'];
|
|
65
|
+
/**
|
|
66
|
+
* Maps the deep keys of TFormData to the shallow keys of TFieldGroupData.
|
|
67
|
+
* Since using template strings as keys is impractical, it relies on shallow keys only.
|
|
68
|
+
*/
|
|
69
|
+
type FieldsMap<TFormData, TFieldGroupData> = TFieldGroupData extends any[] ? never : string extends keyof TFieldGroupData ? never : { [K in keyof TFieldGroupData]: DeepKeysOfType<TFormData, TFieldGroupData[K]> };
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/types.d.ts
|
|
72
|
+
type EventLike = {
|
|
73
|
+
target?: {
|
|
74
|
+
value: any;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
type ArrayLike = any[] | undefined | null;
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/form-api.types.d.ts
|
|
80
|
+
type PersistedFormStatus = {
|
|
81
|
+
submits: number;
|
|
82
|
+
submitting: boolean;
|
|
83
|
+
validating: boolean;
|
|
84
|
+
successful: boolean;
|
|
85
|
+
dirty: boolean;
|
|
86
|
+
};
|
|
87
|
+
type FormStatus = Simplify<PersistedFormStatus & {
|
|
88
|
+
submitted: boolean;
|
|
89
|
+
valid: boolean;
|
|
90
|
+
}>;
|
|
91
|
+
type PersistedFieldMeta = {
|
|
92
|
+
blurred: boolean;
|
|
93
|
+
touched: boolean;
|
|
94
|
+
dirty: boolean;
|
|
95
|
+
};
|
|
96
|
+
type FieldMeta = Simplify<PersistedFieldMeta & {
|
|
97
|
+
touched: boolean;
|
|
98
|
+
default: boolean;
|
|
99
|
+
valid: boolean;
|
|
100
|
+
pristine: boolean;
|
|
101
|
+
}>;
|
|
102
|
+
type FormBaseStore<Values> = {
|
|
103
|
+
values: Values;
|
|
104
|
+
fields: Record<string, PersistedFieldMeta>;
|
|
105
|
+
refs: Record<string, HTMLElement | null>;
|
|
106
|
+
status: PersistedFormStatus;
|
|
107
|
+
errors: Record<string, FormIssue[]>;
|
|
108
|
+
};
|
|
109
|
+
type FormStore<Values> = {
|
|
110
|
+
values: Values;
|
|
111
|
+
fields: Record<string, FieldMeta>;
|
|
112
|
+
refs: Record<string, HTMLElement | null>;
|
|
113
|
+
status: FormStatus;
|
|
114
|
+
errors: Record<string, FormIssue[]>;
|
|
115
|
+
};
|
|
116
|
+
type FieldControl<Value> = {
|
|
117
|
+
focus: () => void;
|
|
118
|
+
blur: () => void;
|
|
119
|
+
change: (value: Value) => void;
|
|
120
|
+
register: (element: HTMLElement | null) => void;
|
|
121
|
+
};
|
|
122
|
+
type FormValidatorSchema<Values> = StandardSchemaV1<PartialDeep<Values>>;
|
|
123
|
+
type FormValidatorFunction<Values> = (store: FormStore<Values>) => FormValidatorSchema<Values>;
|
|
124
|
+
type FormValidator<Values> = FormValidatorSchema<Values> | FormValidatorFunction<Values>;
|
|
125
|
+
type FormOptions<Values> = {
|
|
126
|
+
schema: StandardSchemaV1<Values>;
|
|
127
|
+
values?: Values;
|
|
128
|
+
defaultValues: Values;
|
|
129
|
+
validate?: {
|
|
130
|
+
change?: FormValidator<Values>;
|
|
131
|
+
submit?: FormValidator<Values>;
|
|
132
|
+
blur?: FormValidator<Values>;
|
|
133
|
+
focus?: FormValidator<Values>;
|
|
134
|
+
};
|
|
135
|
+
related?: Record<DeepKeys<Values>, DeepKeys<Values>[]>;
|
|
136
|
+
};
|
|
137
|
+
type FormIssue = StandardSchemaV1.Issue;
|
|
138
|
+
type ValidationType = 'change' | 'submit' | 'blur' | 'focus';
|
|
139
|
+
type ValidateOptions = {
|
|
140
|
+
type?: ValidationType;
|
|
141
|
+
};
|
|
142
|
+
type FieldChangeOptions = {
|
|
143
|
+
should?: {
|
|
144
|
+
/** Whether to validate the field after changing its value. Defaults to true. */
|
|
145
|
+
validate?: boolean;
|
|
146
|
+
/** Whether to mark the field as dirty after changing its value. Defaults to true. */
|
|
147
|
+
dirty?: boolean;
|
|
148
|
+
/** Whether to mark the field as touched after changing its value. Defaults to true. */
|
|
149
|
+
touch?: boolean;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
type FieldResetMeta = {
|
|
153
|
+
blurred?: boolean;
|
|
154
|
+
touched?: boolean;
|
|
155
|
+
dirty?: boolean;
|
|
156
|
+
};
|
|
157
|
+
type FieldResetKeepOptions = {
|
|
158
|
+
errors?: boolean;
|
|
159
|
+
refs?: boolean;
|
|
160
|
+
meta?: boolean;
|
|
161
|
+
};
|
|
162
|
+
type FormResetFieldOptions<Value> = {
|
|
163
|
+
value?: Value;
|
|
164
|
+
meta?: FieldResetMeta;
|
|
165
|
+
keep?: FieldResetKeepOptions;
|
|
166
|
+
};
|
|
167
|
+
type FormResetKeepOptions = {
|
|
168
|
+
/** Keep current field errors */
|
|
169
|
+
errors?: boolean;
|
|
170
|
+
/** Keep current references to html input elements */
|
|
171
|
+
refs?: boolean;
|
|
172
|
+
/** Keep current field metadata */
|
|
173
|
+
fields?: boolean;
|
|
174
|
+
};
|
|
175
|
+
type FormResetOptions<Values> = {
|
|
176
|
+
values?: Values;
|
|
177
|
+
status?: Partial<PersistedFormStatus>;
|
|
178
|
+
keep?: FormResetKeepOptions;
|
|
179
|
+
};
|
|
180
|
+
type FieldSetErrorsMode = 'replace' | 'append' | 'keep';
|
|
181
|
+
type FormSetErrorsOptions = {
|
|
182
|
+
mode?: FieldSetErrorsMode;
|
|
183
|
+
};
|
|
184
|
+
type FormSubmitSuccessHandler<Schema extends StandardSchemaV1> = (data: StandardSchemaV1.InferOutput<Schema>, form: FormApi<Schema>) => void | Promise<void>;
|
|
185
|
+
type FormSubmitErrorHandler<Schema extends StandardSchemaV1> = (issues: FormIssue[], form: FormApi<Schema>) => void | Promise<void>;
|
|
186
|
+
type FormSubmitHandlers<Schema extends StandardSchemaV1> = {
|
|
187
|
+
onSuccess: FormSubmitSuccessHandler<Schema>;
|
|
188
|
+
onError?: FormSubmitErrorHandler<Schema>;
|
|
189
|
+
};
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region src/form-context-api.d.ts
|
|
192
|
+
declare class FormContextApi<Values> {
|
|
193
|
+
options: FormOptions<Values>;
|
|
194
|
+
persisted: Store<FormBaseStore<Values>>;
|
|
195
|
+
store: Derived<FormStore<Values>>;
|
|
196
|
+
constructor(options: FormOptions<Values>);
|
|
197
|
+
get status(): {
|
|
198
|
+
submits: number;
|
|
199
|
+
submitting: boolean;
|
|
200
|
+
validating: boolean;
|
|
201
|
+
successful: boolean;
|
|
202
|
+
dirty: boolean;
|
|
203
|
+
submitted: boolean;
|
|
204
|
+
valid: boolean;
|
|
205
|
+
};
|
|
206
|
+
get values(): Values;
|
|
207
|
+
private get validator();
|
|
208
|
+
buildFieldMeta: (fieldName: string, persistedMeta: PersistedFieldMeta | undefined, values: Values, errors: Record<string, FormIssue[]>) => FieldMeta;
|
|
209
|
+
setFieldMeta: (name: string, meta: Partial<PersistedFieldMeta>) => void;
|
|
210
|
+
resetFieldMeta: (name: string) => void;
|
|
211
|
+
recomputeFieldMeta: (name: string) => void;
|
|
212
|
+
setStatus: (status: Partial<PersistedFormStatus>) => void;
|
|
213
|
+
validate: (field?: FormFields<FormApi<Values>> | FormFields<FormApi<Values>>[], options?: ValidateOptions) => Promise<_standard_schema_spec1.StandardSchemaV1.Issue[]>;
|
|
214
|
+
}
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region src/utils/update.d.ts
|
|
217
|
+
type UpdaterFn<TInput, TOutput = TInput> = (input: TInput) => TOutput;
|
|
218
|
+
type Updater<TInput, TOutput = TInput> = TOutput | UpdaterFn<TInput, TOutput>;
|
|
219
|
+
//#endregion
|
|
220
|
+
//#region src/form-field-api.d.ts
|
|
221
|
+
declare class FormFieldApi<Values> {
|
|
222
|
+
private context;
|
|
223
|
+
constructor(context: FormContextApi<Values>);
|
|
224
|
+
/**
|
|
225
|
+
* Changes the value of a specific field with optional control over side effects.
|
|
226
|
+
* @param name - The name of the field to change
|
|
227
|
+
* @param value - The new value to set for the field
|
|
228
|
+
* @param options - Optional configuration for controlling validation, dirty state, and touched state
|
|
229
|
+
*/
|
|
230
|
+
change: <const Name extends FormFields<FormApi<Values>>>(name: Name, updater: Updater<DeepValue<Values, Name>>, options?: FieldChangeOptions) => void;
|
|
231
|
+
focus: <const Name extends FormFields<FormApi<Values>>>(name: Name) => void;
|
|
232
|
+
blur: <const Name extends FormFields<FormApi<Values>>>(name: Name) => void;
|
|
233
|
+
get: <const Name extends FormFields<FormApi<Values>>>(name: Name) => DeepValue<Values, Name>;
|
|
234
|
+
meta: <const Name extends FormFields<FormApi<Values>>>(name: Name) => {
|
|
235
|
+
blurred: boolean;
|
|
236
|
+
touched: boolean;
|
|
237
|
+
dirty: boolean;
|
|
238
|
+
default: boolean;
|
|
239
|
+
valid: boolean;
|
|
240
|
+
pristine: boolean;
|
|
241
|
+
};
|
|
242
|
+
register: <const Name extends FormFields<FormApi<Values>>>(name: Name) => (element: HTMLElement | null) => void;
|
|
243
|
+
errors: <const Name extends FormFields<FormApi<Values>>>(name: Name) => _standard_schema_spec1.StandardSchemaV1.Issue[];
|
|
244
|
+
setErrors: <const Name extends FormFields<FormApi<Values>>>(name: Name, errors: FormIssue[], options?: FormSetErrorsOptions) => void;
|
|
245
|
+
reset: <const Name extends FormFields<FormApi<Values>>>(name: Name, options?: FormResetFieldOptions<DeepValue<Values, Name>>) => void;
|
|
246
|
+
}
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region src/form-array-field-api.d.ts
|
|
249
|
+
declare class FormArrayFieldApi<Values> {
|
|
250
|
+
private context;
|
|
251
|
+
private field;
|
|
252
|
+
constructor({
|
|
253
|
+
field,
|
|
254
|
+
context
|
|
255
|
+
}: {
|
|
256
|
+
field: FormFieldApi<Values>;
|
|
257
|
+
context: FormContextApi<Values>;
|
|
258
|
+
});
|
|
259
|
+
insert: <const Name extends FormArrayFields<FormApi<Values>>>(name: Name, index: number, value: Updater<UnwrapOneLevelOfArray<DeepValue<Values, Name>>>, options?: FieldChangeOptions) => void;
|
|
260
|
+
append: <const Name extends FormArrayFields<FormApi<Values>>>(name: Name, value: UnwrapOneLevelOfArray<DeepValue<Values, Name>>, options?: FieldChangeOptions) => void;
|
|
261
|
+
prepend: <const Name extends FormArrayFields<FormApi<Values>>>(name: Name, value: UnwrapOneLevelOfArray<DeepValue<Values, Name>>, options?: FieldChangeOptions) => void;
|
|
262
|
+
swap: <const Name extends FormArrayFields<FormApi<Values>>>(name: Name, from: number, to: number, options?: FieldChangeOptions) => void;
|
|
263
|
+
move<const Name extends FormArrayFields<FormApi<Values>>>(name: Name, _from: number, _to: number, options?: FieldChangeOptions): void;
|
|
264
|
+
update: <const Name extends FormArrayFields<FormApi<Values>>>(name: Name, index: number, value: Updater<UnwrapOneLevelOfArray<DeepValue<Values, Name>>>, options?: FieldChangeOptions) => void;
|
|
265
|
+
remove<const Name extends FormArrayFields<FormApi<Values>>>(name: Name, index: number, options?: FieldChangeOptions): void;
|
|
266
|
+
replace<const Name extends FormArrayFields<FormApi<Values>>>(name: Name, value: Updater<DeepValue<Values, Name>>, options?: FieldChangeOptions): void;
|
|
267
|
+
}
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region src/form-api.d.ts
|
|
270
|
+
type AnyFormApi = FormApi<any>;
|
|
271
|
+
type FormValues<Form extends AnyFormApi> = Form extends FormApi<infer Values> ? Values : never;
|
|
272
|
+
type FormFields<Form extends AnyFormApi> = DeepKeys<FormValues<Form>>;
|
|
273
|
+
type FormArrayFields<Form extends AnyFormApi> = DeepKeysOfType<FormValues<Form>, ArrayLike>;
|
|
274
|
+
type FormFieldValue<Form extends AnyFormApi, Name extends FormFields<Form>> = DeepValue<FormValues<Form>, Name>;
|
|
275
|
+
declare class FormApi<Values> {
|
|
276
|
+
private context;
|
|
277
|
+
field: FormFieldApi<Values>;
|
|
278
|
+
array: FormArrayFieldApi<Values>;
|
|
279
|
+
constructor(options: FormOptions<Values>);
|
|
280
|
+
'~mount': () => () => void;
|
|
281
|
+
'~update': (options: FormOptions<Values>) => void;
|
|
282
|
+
store: () => _tanstack_store0.Derived<FormStore<Values>, readonly any[]>;
|
|
283
|
+
status: () => {
|
|
284
|
+
submits: number;
|
|
285
|
+
submitting: boolean;
|
|
286
|
+
validating: boolean;
|
|
287
|
+
successful: boolean;
|
|
288
|
+
dirty: boolean;
|
|
289
|
+
submitted: boolean;
|
|
290
|
+
valid: boolean;
|
|
291
|
+
};
|
|
292
|
+
values: () => Values;
|
|
293
|
+
options: () => FormOptions<Values>;
|
|
294
|
+
get validate(): (field?: DeepKeys<Values> | DeepKeys<Values>[] | undefined, options?: ValidateOptions) => Promise<StandardSchemaV1.Issue[]>;
|
|
295
|
+
submit: (onSuccess: FormSubmitSuccessHandler<StandardSchemaV1<Values>>, onError?: FormSubmitErrorHandler<StandardSchemaV1<Values>>) => () => Promise<void>;
|
|
296
|
+
reset: (options?: FormResetOptions<Values>) => void;
|
|
297
|
+
}
|
|
298
|
+
//#endregion
|
|
299
|
+
//#region src/field-api.d.ts
|
|
300
|
+
type FieldOptions<Form extends AnyFormApi, Name extends FormFields<Form>> = {
|
|
301
|
+
form: Form;
|
|
302
|
+
name: Name;
|
|
303
|
+
};
|
|
304
|
+
type FieldState<Value> = {
|
|
305
|
+
value: Value;
|
|
306
|
+
defaultValue: Value;
|
|
307
|
+
meta: FieldMeta;
|
|
308
|
+
errors: FormIssue[];
|
|
309
|
+
};
|
|
310
|
+
type AnyFieldApi = FieldApi<any>;
|
|
311
|
+
declare class FieldApi<Value> {
|
|
312
|
+
private _options;
|
|
313
|
+
private form;
|
|
314
|
+
private _store;
|
|
315
|
+
constructor(options: FieldOptions<AnyFormApi, string>);
|
|
316
|
+
'~mount': () => () => void;
|
|
317
|
+
'~update': (options: FieldOptions<AnyFormApi, string>) => void;
|
|
318
|
+
options: () => FieldOptions<AnyFormApi, string>;
|
|
319
|
+
store: () => Derived<FieldState<Value>, readonly any[]>;
|
|
320
|
+
state: () => FieldState<Value>;
|
|
321
|
+
focus: () => void;
|
|
322
|
+
blur: () => void;
|
|
323
|
+
/**
|
|
324
|
+
* Changes the value of this field with optional control over side effects.
|
|
325
|
+
* @param value - The new value to set for the field
|
|
326
|
+
* @param options - Optional configuration for controlling validation, dirty state, and touched state
|
|
327
|
+
*/
|
|
328
|
+
change: (value: Updater<Value>, options?: FieldChangeOptions) => void;
|
|
329
|
+
register: () => (element: HTMLElement | null) => void;
|
|
330
|
+
/**
|
|
331
|
+
* Validates this specific field using the specified validation type.
|
|
332
|
+
* @param options - Optional validation options specifying the validation type ('change' | 'submit' | 'blur' | 'focus')
|
|
333
|
+
* @returns Promise resolving to an array of validation issues for this field
|
|
334
|
+
*/
|
|
335
|
+
validate: (options?: ValidateOptions) => Promise<_standard_schema_spec1.StandardSchemaV1.Issue[]>;
|
|
336
|
+
/**
|
|
337
|
+
* Resets this field to its default value and optionally resets metadata and errors.
|
|
338
|
+
* @param options - Reset options for controlling what gets reset and what gets kept
|
|
339
|
+
*/
|
|
340
|
+
reset: (options?: FormResetFieldOptions<Value>) => void;
|
|
341
|
+
/**
|
|
342
|
+
* Sets validation errors for this specific field.
|
|
343
|
+
* @param errors - Array of validation errors to set
|
|
344
|
+
* @param mode - How to handle existing errors: 'replace' (default), 'append', or 'keep'
|
|
345
|
+
*/
|
|
346
|
+
setErrors: (errors: FormIssue[], options?: FormSetErrorsOptions) => void;
|
|
347
|
+
}
|
|
348
|
+
declare const createFieldApi: <Form extends AnyFormApi, const Name extends FormFields<Form>>(options: FieldOptions<Form, Name>) => FieldApi<FormFieldValue<Form, Name>>;
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/array-field-api.d.ts
|
|
351
|
+
type ArrayFieldOptions<Form extends AnyFormApi, Name extends FormArrayFields<Form>> = {
|
|
352
|
+
form: Form;
|
|
353
|
+
name: Name;
|
|
354
|
+
};
|
|
355
|
+
type AnyArrayFieldApi = ArrayFieldApi<any>;
|
|
356
|
+
declare class ArrayFieldApi<Value extends ArrayLike> {
|
|
357
|
+
private field;
|
|
358
|
+
constructor(options: FieldOptions<AnyFormApi, string>);
|
|
359
|
+
private get _options();
|
|
360
|
+
'~mount': () => () => void;
|
|
361
|
+
'~update': (options: FieldOptions<AnyFormApi, string>) => void;
|
|
362
|
+
store: () => _tanstack_store0.Derived<FieldState<Value>, readonly any[]>;
|
|
363
|
+
state: () => FieldState<Value>;
|
|
364
|
+
/**
|
|
365
|
+
* Appends a new item to the end of the array.
|
|
366
|
+
* @param value - The value to append to the array
|
|
367
|
+
* @param options - Optional configuration for controlling validation, dirty state, and touched state
|
|
368
|
+
*/
|
|
369
|
+
append: (value: UnwrapOneLevelOfArray<Value>, options?: FieldChangeOptions) => void;
|
|
370
|
+
/**
|
|
371
|
+
* Prepends a new item to the beginning of the array.
|
|
372
|
+
* @param value - The value to prepend to the array
|
|
373
|
+
* @param options - Optional configuration for controlling validation, dirty state, and touched state
|
|
374
|
+
*/
|
|
375
|
+
prepend: (value: UnwrapOneLevelOfArray<Value>, options?: FieldChangeOptions) => void;
|
|
376
|
+
/**
|
|
377
|
+
* Inserts a new item at the specified index in the array.
|
|
378
|
+
* @param index - The index at which to insert the value
|
|
379
|
+
* @param value - The value to insert into the array
|
|
380
|
+
* @param options - Optional configuration for controlling validation, dirty state, and touched state
|
|
381
|
+
*/
|
|
382
|
+
insert: (index: number, value: Updater<UnwrapOneLevelOfArray<Value>>, options?: FieldChangeOptions) => void;
|
|
383
|
+
/**
|
|
384
|
+
* Updates an item at the specified index in the array.
|
|
385
|
+
* @param index - The index of the item to update
|
|
386
|
+
* @param value - The new value or updater function
|
|
387
|
+
* @param options - Optional configuration for controlling validation, dirty state, and touched state
|
|
388
|
+
*/
|
|
389
|
+
update: (index: number, value: Updater<UnwrapOneLevelOfArray<Value>>, options?: FieldChangeOptions) => void;
|
|
390
|
+
/**
|
|
391
|
+
* Removes an item at the specified index from the array.
|
|
392
|
+
* @param index - The index of the item to remove
|
|
393
|
+
* @param options - Optional configuration for controlling validation, dirty state, and touched state
|
|
394
|
+
*/
|
|
395
|
+
remove: (index: number, options?: FieldChangeOptions) => void;
|
|
396
|
+
/**
|
|
397
|
+
* Swaps two items in the array by their indices.
|
|
398
|
+
* @param from - The index of the first item
|
|
399
|
+
* @param to - The index of the second item
|
|
400
|
+
* @param options - Optional configuration for controlling validation, dirty state, and touched state
|
|
401
|
+
*/
|
|
402
|
+
swap: (from: number, to: number, options?: FieldChangeOptions) => void;
|
|
403
|
+
/**
|
|
404
|
+
* Moves an item from one index to another in the array.
|
|
405
|
+
* @param from - The index of the item to move
|
|
406
|
+
* @param to - The target index
|
|
407
|
+
* @param options - Optional configuration for controlling validation, dirty state, and touched state
|
|
408
|
+
*/
|
|
409
|
+
move: (from: number, to: number, options?: FieldChangeOptions) => void;
|
|
410
|
+
/**
|
|
411
|
+
* Replaces the entire array with a new value.
|
|
412
|
+
* @param value - The new array value or updater function
|
|
413
|
+
* @param options - Optional configuration for controlling validation, dirty state, and touched state
|
|
414
|
+
*/
|
|
415
|
+
replace: (value: Updater<Value>, options?: FieldChangeOptions) => void;
|
|
416
|
+
/**
|
|
417
|
+
* Validates this specific array field using the specified validation type.
|
|
418
|
+
* @param options - Optional validation options specifying the validation type ('change' | 'submit' | 'blur' | 'focus')
|
|
419
|
+
* @returns Promise resolving to an array of validation issues for this field
|
|
420
|
+
*/
|
|
421
|
+
validate: (options?: ValidateOptions) => Promise<StandardSchemaV1.Issue[]>;
|
|
422
|
+
/**
|
|
423
|
+
* Resets this array field to its default value and optionally resets metadata and errors.
|
|
424
|
+
* @param options - Reset options for controlling what gets reset and what gets kept
|
|
425
|
+
*/
|
|
426
|
+
reset: (options?: FormResetFieldOptions<Value>) => void;
|
|
427
|
+
/**
|
|
428
|
+
* Sets validation errors for this specific array field.
|
|
429
|
+
* @param errors - Array of validation errors to set
|
|
430
|
+
* @param mode - How to handle existing errors: 'replace' (default), 'append', or 'keep'
|
|
431
|
+
*/
|
|
432
|
+
setErrors: (errors: FormIssue[], options?: FormSetErrorsOptions) => void;
|
|
433
|
+
}
|
|
434
|
+
declare const createArrayFieldApi: <FormApi$1 extends AnyFormApi, const Name extends FormArrayFields<FormApi$1>>(options: ArrayFieldOptions<FormApi$1, Name>) => ArrayFieldApi<FormFieldValue<FormApi$1, Name>>;
|
|
435
|
+
//#endregion
|
|
436
|
+
//#region src/types/any-form-like-api.d.ts
|
|
437
|
+
type AnyFormLikeApi = AnyFormApi | AnyArrayFieldApi | AnyFieldApi;
|
|
438
|
+
//#endregion
|
|
439
|
+
//#region src/types/api-selector.d.ts
|
|
440
|
+
type ApiSelector<Api extends AnyFormLikeApi, Selected> = (state: ReturnType<Api['store']>['state']) => Selected;
|
|
441
|
+
//#endregion
|
|
442
|
+
export { AllObjectKeys, AllTupleKeys, type AnyArrayFieldApi, AnyDeepKeyAndValue, type AnyFieldApi, type AnyFormApi, type AnyFormLikeApi, type ApiSelector, ArrayAccessor, ArrayDeepKeyAndValue, ArrayFieldApi, type ArrayFieldOptions, type ArrayLike, DeepKeyAndValueArray, DeepKeyAndValueObject, DeepKeyAndValueTuple, DeepKeys, DeepKeysAndValues, DeepKeysAndValuesImpl, DeepKeysOfType, DeepRecord, DeepValue, type EventLike, FieldApi, FieldChangeOptions, FieldControl, FieldMeta, type FieldOptions, FieldResetKeepOptions, FieldResetMeta, FieldSetErrorsMode, type FieldState, FieldsMap, FormApi, type FormArrayFields, FormBaseStore, type FormFieldValue, type FormFields, FormIssue, FormOptions, FormResetFieldOptions, FormResetKeepOptions, FormResetOptions, FormSetErrorsOptions, FormStatus, FormStore, FormSubmitErrorHandler, FormSubmitHandlers, FormSubmitSuccessHandler, type FormValues, Narrow, Nullable, ObjectAccessor, ObjectDeepKeyAndValue, ObjectValue, PersistedFieldMeta, PersistedFormStatus, type Simplify, type StandardSchemaV1 as StandardSchema, TupleAccessor, TupleDeepKeyAndValue, UnknownAccessor, UnknownDeepKeyAndValue, UnwrapOneLevelOfArray, ValidateOptions, ValidationType, createArrayFieldApi, createFieldApi };
|
|
443
|
+
//# sourceMappingURL=index.d.cts.map
|