@conform-to/dom 1.1.2 → 1.1.3
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.js +6 -2
- package/form.mjs +7 -3
- package/formdata.js +1 -1
- package/formdata.mjs +1 -1
- package/package.json +20 -2
- package/rollup.config.js +100 -0
- package/submission.d.ts +5 -5
package/README
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
╚══════╝ ╚═════╝ ╚═╝ ╚══╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
Version 1.1.
|
|
11
|
+
Version 1.1.3 / 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.js
CHANGED
|
@@ -51,6 +51,7 @@ function setFieldsValidated(meta, fields) {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
function handleIntent(meta, intent, fields, initialized) {
|
|
54
|
+
var _fields$filter;
|
|
54
55
|
if (!intent) {
|
|
55
56
|
setFieldsValidated(meta, fields);
|
|
56
57
|
return;
|
|
@@ -133,9 +134,10 @@ function handleIntent(meta, intent, fields, initialized) {
|
|
|
133
134
|
break;
|
|
134
135
|
}
|
|
135
136
|
}
|
|
137
|
+
var validatedFields = (_fields$filter = fields === null || fields === void 0 ? void 0 : fields.filter(name => meta.validated[name])) !== null && _fields$filter !== void 0 ? _fields$filter : [];
|
|
136
138
|
meta.error = Object.entries(meta.error).reduce((result, _ref3) => {
|
|
137
139
|
var [name, error] = _ref3;
|
|
138
|
-
if (meta.validated[name]) {
|
|
140
|
+
if (meta.validated[name] || validatedFields.some(field => formdata.isPrefix(name, field))) {
|
|
139
141
|
result[name] = error;
|
|
140
142
|
}
|
|
141
143
|
return result;
|
|
@@ -145,7 +147,9 @@ function updateValue(meta, name, value) {
|
|
|
145
147
|
if (name === '') {
|
|
146
148
|
meta.initialValue = value;
|
|
147
149
|
meta.value = value;
|
|
148
|
-
meta.key = getDefaultKey(value)
|
|
150
|
+
meta.key = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, getDefaultKey(value)), {}, {
|
|
151
|
+
'': util.generateId()
|
|
152
|
+
});
|
|
149
153
|
return;
|
|
150
154
|
}
|
|
151
155
|
meta.initialValue = util.clone(meta.initialValue);
|
package/form.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
|
-
import { flatten, formatName, getValue, isPlainObject, setValue, normalize, getFormData, getPaths, formatPaths
|
|
2
|
+
import { flatten, formatName, getValue, isPlainObject, isPrefix, setValue, normalize, getFormData, getPaths, formatPaths } from './formdata.mjs';
|
|
3
3
|
import { getFormAction, getFormEncType, getFormMethod, isFieldElement, requestSubmit } from './dom.mjs';
|
|
4
4
|
import { generateId, clone, invariant } from './util.mjs';
|
|
5
5
|
import { serialize, setListState, setListValue, setState, INTENT, serializeIntent, root, getSubmissionContext } from './submission.mjs';
|
|
@@ -47,6 +47,7 @@ function setFieldsValidated(meta, fields) {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
function handleIntent(meta, intent, fields, initialized) {
|
|
50
|
+
var _fields$filter;
|
|
50
51
|
if (!intent) {
|
|
51
52
|
setFieldsValidated(meta, fields);
|
|
52
53
|
return;
|
|
@@ -129,9 +130,10 @@ function handleIntent(meta, intent, fields, initialized) {
|
|
|
129
130
|
break;
|
|
130
131
|
}
|
|
131
132
|
}
|
|
133
|
+
var validatedFields = (_fields$filter = fields === null || fields === void 0 ? void 0 : fields.filter(name => meta.validated[name])) !== null && _fields$filter !== void 0 ? _fields$filter : [];
|
|
132
134
|
meta.error = Object.entries(meta.error).reduce((result, _ref3) => {
|
|
133
135
|
var [name, error] = _ref3;
|
|
134
|
-
if (meta.validated[name]) {
|
|
136
|
+
if (meta.validated[name] || validatedFields.some(field => isPrefix(name, field))) {
|
|
135
137
|
result[name] = error;
|
|
136
138
|
}
|
|
137
139
|
return result;
|
|
@@ -141,7 +143,9 @@ function updateValue(meta, name, value) {
|
|
|
141
143
|
if (name === '') {
|
|
142
144
|
meta.initialValue = value;
|
|
143
145
|
meta.value = value;
|
|
144
|
-
meta.key = getDefaultKey(value)
|
|
146
|
+
meta.key = _objectSpread2(_objectSpread2({}, getDefaultKey(value)), {}, {
|
|
147
|
+
'': generateId()
|
|
148
|
+
});
|
|
145
149
|
return;
|
|
146
150
|
}
|
|
147
151
|
meta.initialValue = clone(meta.initialValue);
|
package/formdata.js
CHANGED
|
@@ -93,7 +93,7 @@ function setValue(target, name, valueFn) {
|
|
|
93
93
|
while (pointer != null && ++index < length) {
|
|
94
94
|
var key = paths[index];
|
|
95
95
|
var nextKey = paths[index + 1];
|
|
96
|
-
var newValue = index != lastIndex ? Object.prototype.hasOwnProperty.call(pointer, key) ? pointer[key] : typeof nextKey === 'number' ? [] : {} : valueFn(pointer[key]);
|
|
96
|
+
var newValue = index != lastIndex ? Object.prototype.hasOwnProperty.call(pointer, key) && pointer[key] !== null ? pointer[key] : typeof nextKey === 'number' ? [] : {} : valueFn(pointer[key]);
|
|
97
97
|
pointer[key] = newValue;
|
|
98
98
|
pointer = pointer[key];
|
|
99
99
|
}
|
package/formdata.mjs
CHANGED
|
@@ -89,7 +89,7 @@ function setValue(target, name, valueFn) {
|
|
|
89
89
|
while (pointer != null && ++index < length) {
|
|
90
90
|
var key = paths[index];
|
|
91
91
|
var nextKey = paths[index + 1];
|
|
92
|
-
var newValue = index != lastIndex ? Object.prototype.hasOwnProperty.call(pointer, key) ? pointer[key] : typeof nextKey === 'number' ? [] : {} : valueFn(pointer[key]);
|
|
92
|
+
var newValue = index != lastIndex ? Object.prototype.hasOwnProperty.call(pointer, key) && pointer[key] !== null ? pointer[key] : typeof nextKey === 'number' ? [] : {} : valueFn(pointer[key]);
|
|
93
93
|
pointer[key] = newValue;
|
|
94
94
|
pointer = pointer[key];
|
|
95
95
|
}
|
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.1.
|
|
6
|
+
"version": "1.1.3",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"module": "index.mjs",
|
|
9
9
|
"types": "index.d.ts",
|
|
@@ -16,6 +16,15 @@
|
|
|
16
16
|
"default": "./index.mjs"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build:js": "rollup -c",
|
|
21
|
+
"build:ts": "tsc",
|
|
22
|
+
"build": "pnpm run \"/^build:.*/\"",
|
|
23
|
+
"dev:js": "pnpm run build:js --watch",
|
|
24
|
+
"dev:ts": "pnpm run build:ts --watch",
|
|
25
|
+
"dev": "pnpm run \"/^dev:.*/\"",
|
|
26
|
+
"prepare": "pnpm run build"
|
|
27
|
+
},
|
|
19
28
|
"repository": {
|
|
20
29
|
"type": "git",
|
|
21
30
|
"url": "https://github.com/edmundhung/conform",
|
|
@@ -38,5 +47,14 @@
|
|
|
38
47
|
"validation",
|
|
39
48
|
"dom"
|
|
40
49
|
],
|
|
41
|
-
"sideEffects": false
|
|
50
|
+
"sideEffects": false,
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@babel/core": "^7.17.8",
|
|
53
|
+
"@babel/preset-env": "^7.20.2",
|
|
54
|
+
"@babel/preset-typescript": "^7.20.2",
|
|
55
|
+
"@rollup/plugin-babel": "^5.3.1",
|
|
56
|
+
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
57
|
+
"rollup-plugin-copy": "^3.4.0",
|
|
58
|
+
"rollup": "^2.79.1"
|
|
59
|
+
}
|
|
42
60
|
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import babel from '@rollup/plugin-babel';
|
|
3
|
+
import nodeResolve from '@rollup/plugin-node-resolve';
|
|
4
|
+
import copy from 'rollup-plugin-copy';
|
|
5
|
+
|
|
6
|
+
/** @returns {import("rollup").RollupOptions[]} */
|
|
7
|
+
function configurePackage() {
|
|
8
|
+
let sourceDir = '.';
|
|
9
|
+
let outputDir = sourceDir;
|
|
10
|
+
|
|
11
|
+
/** @type {import("rollup").RollupOptions} */
|
|
12
|
+
let ESM = {
|
|
13
|
+
external(id) {
|
|
14
|
+
return !id.startsWith('.') && !path.isAbsolute(id);
|
|
15
|
+
},
|
|
16
|
+
input: `${sourceDir}/index.ts`,
|
|
17
|
+
output: {
|
|
18
|
+
dir: outputDir,
|
|
19
|
+
format: 'esm',
|
|
20
|
+
preserveModules: true,
|
|
21
|
+
entryFileNames: '[name].mjs',
|
|
22
|
+
},
|
|
23
|
+
plugins: [
|
|
24
|
+
babel({
|
|
25
|
+
babelrc: false,
|
|
26
|
+
configFile: false,
|
|
27
|
+
presets: [
|
|
28
|
+
[
|
|
29
|
+
'@babel/preset-env',
|
|
30
|
+
{
|
|
31
|
+
targets: {
|
|
32
|
+
node: '16',
|
|
33
|
+
esmodules: true,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
'@babel/preset-typescript',
|
|
38
|
+
],
|
|
39
|
+
plugins: [],
|
|
40
|
+
babelHelpers: 'bundled',
|
|
41
|
+
exclude: /node_modules/,
|
|
42
|
+
extensions: ['.ts', '.tsx'],
|
|
43
|
+
}),
|
|
44
|
+
nodeResolve({
|
|
45
|
+
extensions: ['.ts', '.tsx'],
|
|
46
|
+
}),
|
|
47
|
+
copy({
|
|
48
|
+
targets: [
|
|
49
|
+
{ src: `../../README`, dest: sourceDir },
|
|
50
|
+
{ src: `../../LICENSE`, dest: sourceDir },
|
|
51
|
+
],
|
|
52
|
+
}),
|
|
53
|
+
],
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** @type {import("rollup").RollupOptions} */
|
|
57
|
+
let CJS = {
|
|
58
|
+
external(id) {
|
|
59
|
+
return !id.startsWith('.') && !path.isAbsolute(id);
|
|
60
|
+
},
|
|
61
|
+
input: `${sourceDir}/index.ts`,
|
|
62
|
+
output: {
|
|
63
|
+
dir: outputDir,
|
|
64
|
+
format: 'cjs',
|
|
65
|
+
preserveModules: true,
|
|
66
|
+
exports: 'auto',
|
|
67
|
+
},
|
|
68
|
+
plugins: [
|
|
69
|
+
babel({
|
|
70
|
+
babelrc: false,
|
|
71
|
+
configFile: false,
|
|
72
|
+
presets: [
|
|
73
|
+
[
|
|
74
|
+
'@babel/preset-env',
|
|
75
|
+
{
|
|
76
|
+
targets: {
|
|
77
|
+
node: '16',
|
|
78
|
+
esmodules: true,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
'@babel/preset-typescript',
|
|
83
|
+
],
|
|
84
|
+
plugins: [],
|
|
85
|
+
babelHelpers: 'bundled',
|
|
86
|
+
exclude: /node_modules/,
|
|
87
|
+
extensions: ['.ts', '.tsx'],
|
|
88
|
+
}),
|
|
89
|
+
nodeResolve({
|
|
90
|
+
extensions: ['.ts', '.tsx'],
|
|
91
|
+
}),
|
|
92
|
+
],
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
return [ESM, CJS];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export default function rollup() {
|
|
99
|
+
return configurePackage();
|
|
100
|
+
}
|
package/submission.d.ts
CHANGED
|
@@ -84,7 +84,7 @@ export type ResetIntent<Schema = any> = {
|
|
|
84
84
|
index: Schema extends Array<unknown> ? number : never;
|
|
85
85
|
};
|
|
86
86
|
};
|
|
87
|
-
export type UpdateIntent<Schema =
|
|
87
|
+
export type UpdateIntent<Schema = any> = {
|
|
88
88
|
type: 'update';
|
|
89
89
|
payload: {
|
|
90
90
|
name?: FieldName<Schema>;
|
|
@@ -98,14 +98,14 @@ export type UpdateIntent<Schema = unknown> = {
|
|
|
98
98
|
validated?: boolean;
|
|
99
99
|
};
|
|
100
100
|
};
|
|
101
|
-
export type RemoveIntent<Schema
|
|
101
|
+
export type RemoveIntent<Schema = any> = {
|
|
102
102
|
type: 'remove';
|
|
103
103
|
payload: {
|
|
104
104
|
name: FieldName<Schema>;
|
|
105
105
|
index: number;
|
|
106
106
|
};
|
|
107
107
|
};
|
|
108
|
-
export type InsertIntent<Schema
|
|
108
|
+
export type InsertIntent<Schema = any> = {
|
|
109
109
|
type: 'insert';
|
|
110
110
|
payload: {
|
|
111
111
|
name: FieldName<Schema>;
|
|
@@ -113,7 +113,7 @@ export type InsertIntent<Schema extends Array<any> = any> = {
|
|
|
113
113
|
index?: number;
|
|
114
114
|
};
|
|
115
115
|
};
|
|
116
|
-
export type ReorderIntent<Schema
|
|
116
|
+
export type ReorderIntent<Schema = any> = {
|
|
117
117
|
type: 'reorder';
|
|
118
118
|
payload: {
|
|
119
119
|
name: FieldName<Schema>;
|
|
@@ -121,7 +121,7 @@ export type ReorderIntent<Schema extends Array<any> = any> = {
|
|
|
121
121
|
to: number;
|
|
122
122
|
};
|
|
123
123
|
};
|
|
124
|
-
export type Intent<Schema =
|
|
124
|
+
export type Intent<Schema = any> = ValidateIntent<Schema> | ResetIntent<Schema> | UpdateIntent<Schema> | ReorderIntent<Schema> | RemoveIntent<Schema> | InsertIntent<Schema>;
|
|
125
125
|
export declare function getIntent(serializedIntent: string | null | undefined): Intent | null;
|
|
126
126
|
export declare function serializeIntent<Schema>(intent: Intent<Schema>): string;
|
|
127
127
|
export declare function updateList(list: unknown, intent: InsertIntent | RemoveIntent | ReorderIntent): void;
|