@conform-to/dom 1.0.1 → 1.0.2
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/README +1 -1
- package/form.d.ts +7 -7
- package/form.js +6 -1
- package/form.mjs +6 -1
- package/formdata.js +10 -1
- package/formdata.mjs +10 -1
- package/index.d.ts +1 -1
- package/package.json +1 -1
package/README
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
╚══════╝ ╚═════╝ ╚═╝ ╚══╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
Version 1.0.
|
|
11
|
+
Version 1.0.2 / License MIT / Copyright (c) 2024 Edmund Hung
|
|
12
12
|
|
|
13
13
|
A type-safe form validation library utilizing web fundamentals to progressively enhance HTML Forms with full support for server frameworks like Remix and Next.js.
|
|
14
14
|
|
package/form.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { getFormAction, getFormEncType, getFormMethod } from './dom';
|
|
2
2
|
import { type Intent, type Submission, type SubmissionResult } from './submission';
|
|
3
|
-
|
|
4
|
-
export type
|
|
5
|
-
[
|
|
6
|
-
}
|
|
3
|
+
type BaseCombine<T, K extends PropertyKey = T extends unknown ? keyof T : never> = T extends unknown ? T & Partial<Record<Exclude<K, keyof T>, never>> : never;
|
|
4
|
+
export type Combine<T> = {
|
|
5
|
+
[K in keyof BaseCombine<T>]: BaseCombine<T>[K];
|
|
6
|
+
};
|
|
7
7
|
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> ? {
|
|
8
|
-
[Key in
|
|
8
|
+
[Key in keyof Combine<Schema>]?: DefaultValue<Combine<Schema>[Key]>;
|
|
9
9
|
} | null | undefined : string | null | undefined;
|
|
10
|
-
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> ? {
|
|
11
|
-
[Key in
|
|
10
|
+
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> ? {
|
|
11
|
+
[Key in keyof Combine<Schema>]?: DefaultValue<Combine<Schema>[Key]>;
|
|
12
12
|
} | undefined : unknown;
|
|
13
13
|
declare const error: unique symbol;
|
|
14
14
|
declare const field: unique symbol;
|
package/form.js
CHANGED
|
@@ -11,7 +11,9 @@ var submission = require('./submission.js');
|
|
|
11
11
|
function createFormMeta(options, initialized) {
|
|
12
12
|
var _lastResult$initialVa, _options$constraint, _lastResult$state$val, _lastResult$state, _ref;
|
|
13
13
|
var lastResult = !initialized ? options.lastResult : undefined;
|
|
14
|
-
var defaultValue = options.defaultValue ?
|
|
14
|
+
var defaultValue = options.defaultValue ?
|
|
15
|
+
// @ts-expect-error
|
|
16
|
+
submission.serialize(options.defaultValue) : {};
|
|
15
17
|
var initialValue = (_lastResult$initialVa = lastResult === null || lastResult === void 0 ? void 0 : lastResult.initialValue) !== null && _lastResult$initialVa !== void 0 ? _lastResult$initialVa : defaultValue;
|
|
16
18
|
var result = {
|
|
17
19
|
submissionStatus: lastResult === null || lastResult === void 0 ? void 0 : lastResult.status,
|
|
@@ -96,6 +98,9 @@ function createStateProxy(fn) {
|
|
|
96
98
|
return new Proxy(cache, {
|
|
97
99
|
get(_, name, receiver) {
|
|
98
100
|
var _cache$name;
|
|
101
|
+
if (typeof name !== 'string') {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
99
104
|
return (_cache$name = cache[name]) !== null && _cache$name !== void 0 ? _cache$name : cache[name] = fn(name, receiver);
|
|
100
105
|
}
|
|
101
106
|
});
|
package/form.mjs
CHANGED
|
@@ -7,7 +7,9 @@ import { serialize, setListState, setListValue, setState, getSubmissionContext,
|
|
|
7
7
|
function createFormMeta(options, initialized) {
|
|
8
8
|
var _lastResult$initialVa, _options$constraint, _lastResult$state$val, _lastResult$state, _ref;
|
|
9
9
|
var lastResult = !initialized ? options.lastResult : undefined;
|
|
10
|
-
var defaultValue = options.defaultValue ?
|
|
10
|
+
var defaultValue = options.defaultValue ?
|
|
11
|
+
// @ts-expect-error
|
|
12
|
+
serialize(options.defaultValue) : {};
|
|
11
13
|
var initialValue = (_lastResult$initialVa = lastResult === null || lastResult === void 0 ? void 0 : lastResult.initialValue) !== null && _lastResult$initialVa !== void 0 ? _lastResult$initialVa : defaultValue;
|
|
12
14
|
var result = {
|
|
13
15
|
submissionStatus: lastResult === null || lastResult === void 0 ? void 0 : lastResult.status,
|
|
@@ -92,6 +94,9 @@ function createStateProxy(fn) {
|
|
|
92
94
|
return new Proxy(cache, {
|
|
93
95
|
get(_, name, receiver) {
|
|
94
96
|
var _cache$name;
|
|
97
|
+
if (typeof name !== 'string') {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
95
100
|
return (_cache$name = cache[name]) !== null && _cache$name !== void 0 ? _cache$name : cache[name] = fn(name, receiver);
|
|
96
101
|
}
|
|
97
102
|
});
|
package/formdata.js
CHANGED
|
@@ -155,9 +155,18 @@ function normalize(value) {
|
|
|
155
155
|
}
|
|
156
156
|
return value.map(normalize);
|
|
157
157
|
}
|
|
158
|
-
if (typeof value === 'string' && value === '' || value === null || isFile(value)) {
|
|
158
|
+
if (typeof value === 'string' && value === '' || value === null || isFile(value) && value.size === 0) {
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
161
|
+
|
|
162
|
+
// We will skip serializing file if the result is sent to the client
|
|
163
|
+
if (isFile(value)) {
|
|
164
|
+
return Object.assign(value, {
|
|
165
|
+
toJSON() {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
161
170
|
return value;
|
|
162
171
|
}
|
|
163
172
|
|
package/formdata.mjs
CHANGED
|
@@ -151,9 +151,18 @@ function normalize(value) {
|
|
|
151
151
|
}
|
|
152
152
|
return value.map(normalize);
|
|
153
153
|
}
|
|
154
|
-
if (typeof value === 'string' && value === '' || value === null || isFile(value)) {
|
|
154
|
+
if (typeof value === 'string' && value === '' || value === null || isFile(value) && value.size === 0) {
|
|
155
155
|
return;
|
|
156
156
|
}
|
|
157
|
+
|
|
158
|
+
// We will skip serializing file if the result is sent to the client
|
|
159
|
+
if (isFile(value)) {
|
|
160
|
+
return Object.assign(value, {
|
|
161
|
+
toJSON() {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
157
166
|
return value;
|
|
158
167
|
}
|
|
159
168
|
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { type
|
|
1
|
+
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';
|
|
2
2
|
export { type FieldElement, isFieldElement } from './dom';
|
|
3
3
|
export { type Submission, type SubmissionResult, type Intent, INTENT, STATE, serializeIntent, parse, } from './submission';
|
|
4
4
|
export { getPaths, formatPaths, isPrefix } from './formdata';
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "A set of opinionated helpers built on top of the Constraint Validation API",
|
|
4
4
|
"homepage": "https://conform.guide",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.2",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"module": "index.mjs",
|
|
9
9
|
"types": "index.d.ts",
|