@conform-to/dom
Advanced tools
Comparing version 1.0.1 to 1.0.2
import { getFormAction, getFormEncType, getFormMethod } from './dom'; | ||
import { type Intent, type Submission, type SubmissionResult } from './submission'; | ||
export type UnionKeyof<T> = T extends any ? keyof T : never; | ||
export type UnionKeyType<T, K extends UnionKeyof<T>> = T extends { | ||
[k in K]?: any; | ||
} ? T[K] : undefined; | ||
type BaseCombine<T, K extends PropertyKey = T extends unknown ? keyof T : never> = T extends unknown ? T & Partial<Record<Exclude<K, keyof T>, never>> : never; | ||
export type Combine<T> = { | ||
[K in keyof BaseCombine<T>]: BaseCombine<T>[K]; | ||
}; | ||
export type DefaultValue<Schema> = Schema extends string | number | boolean | Date | bigint | null | undefined ? Schema | string | null | undefined : Schema extends File ? null | undefined : Schema extends Array<infer Item> ? Array<DefaultValue<Item>> | null | undefined : Schema extends Record<string, any> ? { | ||
[Key in UnionKeyof<Schema>]?: DefaultValue<UnionKeyType<Schema, Key>>; | ||
[Key in keyof Combine<Schema>]?: DefaultValue<Combine<Schema>[Key]>; | ||
} | null | undefined : string | null | undefined; | ||
export type FormValue<Schema> = Schema extends string | number | boolean | Date | bigint | null | undefined ? string | undefined : Schema extends File ? File | undefined : Schema extends Array<infer Item> ? string | Array<FormValue<Item>> | undefined : Schema extends Record<string, any> ? { | ||
[Key in UnionKeyof<Schema>]?: FormValue<UnionKeyType<Schema, Key>>; | ||
export type FormValue<Schema> = Schema extends string | number | boolean | Date | bigint | null | undefined ? string | undefined : Schema extends File ? File | undefined : Schema extends File[] ? File | Array<File> | undefined : Schema extends Array<infer Item> ? string | Array<FormValue<Item>> | undefined : Schema extends Record<string, any> ? { | ||
[Key in keyof Combine<Schema>]?: DefaultValue<Combine<Schema>[Key]>; | ||
} | undefined : unknown; | ||
@@ -13,0 +13,0 @@ declare const error: unique symbol; |
@@ -14,3 +14,5 @@ 'use strict'; | ||
var lastResult = !initialized ? options.lastResult : undefined; | ||
var defaultValue = options.defaultValue ? submission.serialize(options.defaultValue) : {}; | ||
var defaultValue = options.defaultValue ? | ||
// @ts-expect-error | ||
submission.serialize(options.defaultValue) : {}; | ||
var initialValue = (_lastResult$initialVa = lastResult === null || lastResult === void 0 ? void 0 : lastResult.initialValue) !== null && _lastResult$initialVa !== void 0 ? _lastResult$initialVa : defaultValue; | ||
@@ -100,2 +102,5 @@ var result = { | ||
var _cache$name; | ||
if (typeof name !== 'string') { | ||
return; | ||
} | ||
return (_cache$name = cache[name]) !== null && _cache$name !== void 0 ? _cache$name : cache[name] = fn(name, receiver); | ||
@@ -102,0 +107,0 @@ } |
@@ -158,5 +158,14 @@ 'use strict'; | ||
} | ||
if (typeof value === 'string' && value === '' || value === null || isFile(value)) { | ||
if (typeof value === 'string' && value === '' || value === null || isFile(value) && value.size === 0) { | ||
return; | ||
} | ||
// We will skip serializing file if the result is sent to the client | ||
if (isFile(value)) { | ||
return Object.assign(value, { | ||
toJSON() { | ||
return; | ||
} | ||
}); | ||
} | ||
return value; | ||
@@ -163,0 +172,0 @@ } |
@@ -1,4 +0,4 @@ | ||
export { type UnionKeyof, type UnionKeyType, type Constraint, type ControlButtonProps, type FormId, type FieldName, type DefaultValue, type FormValue, type FormOptions, type FormState, type FormContext, type SubscriptionSubject, type SubscriptionScope, createFormContext as unstable_createFormContext, } from './form'; | ||
export { type Combine, type Constraint, type ControlButtonProps, type FormId, type FieldName, type DefaultValue, type FormValue, type FormOptions, type FormState, type FormContext, type SubscriptionSubject, type SubscriptionScope, createFormContext as unstable_createFormContext, } from './form'; | ||
export { type FieldElement, isFieldElement } from './dom'; | ||
export { type Submission, type SubmissionResult, type Intent, INTENT, STATE, serializeIntent, parse, } from './submission'; | ||
export { getPaths, formatPaths, isPrefix } from './formdata'; |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"main": "index.js", | ||
@@ -9,0 +9,0 @@ "module": "index.mjs", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105036
2777