@conform-to/dom 1.19.2 → 1.19.4
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.md +1 -1
- package/dist/formdata.js +51 -31
- package/dist/formdata.mjs +51 -31
- package/dist/vitest.config.d.ts +4 -0
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
╚══════╝ ╚═════╝ ╚═╝ ╚══╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
|
|
8
8
|
```
|
|
9
9
|
|
|
10
|
-
Version 1.19.
|
|
10
|
+
Version 1.19.4 / License MIT / Copyright (c) 2026 Edmund Hung
|
|
11
11
|
|
|
12
12
|
Progressively enhance HTML forms with React. Build resilient, type-safe forms with no hassle using web standards.
|
|
13
13
|
|
package/dist/formdata.js
CHANGED
|
@@ -330,49 +330,69 @@ function isEmptyValue(value) {
|
|
|
330
330
|
* ```
|
|
331
331
|
*/
|
|
332
332
|
function parseSubmission(formData, options) {
|
|
333
|
-
var _options$intentName;
|
|
333
|
+
var _options$intentName, _options$stripEmptyVa;
|
|
334
334
|
var intentName = (_options$intentName = options === null || options === void 0 ? void 0 : options.intentName) !== null && _options$intentName !== void 0 ? _options$intentName : DEFAULT_INTENT_NAME;
|
|
335
335
|
var submission = {
|
|
336
336
|
payload: {},
|
|
337
337
|
fields: [],
|
|
338
338
|
intent: null
|
|
339
339
|
};
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
// If the name ends with [], remove the empty segment and keep the full array
|
|
348
|
-
// Otherwise, unwrap single values
|
|
349
|
-
if (segments.length > 0 && segments[segments.length - 1] === '') {
|
|
350
|
-
segments.pop();
|
|
351
|
-
} else {
|
|
352
|
-
value = value.length > 1 ? value : value[0];
|
|
353
|
-
}
|
|
354
|
-
var stripEmptyValues = (_options$stripEmptyVa = options === null || options === void 0 ? void 0 : options.stripEmptyValues) !== null && _options$stripEmptyVa !== void 0 ? _options$stripEmptyVa : false;
|
|
355
|
-
if (stripEmptyValues) {
|
|
356
|
-
// For arrays, filter out individual empty items
|
|
357
|
-
if (Array.isArray(value)) {
|
|
358
|
-
value = value.filter(item => !isEmptyValue(item));
|
|
340
|
+
var segmentsByName = new Map();
|
|
341
|
+
var stripEmptyValues = (_options$stripEmptyVa = options === null || options === void 0 ? void 0 : options.stripEmptyValues) !== null && _options$stripEmptyVa !== void 0 ? _options$stripEmptyVa : false;
|
|
342
|
+
var intentValue = undefined;
|
|
343
|
+
var _loop = function _loop(entryValue) {
|
|
344
|
+
if (_name === intentName) {
|
|
345
|
+
if (intentValue === undefined) {
|
|
346
|
+
intentValue = typeof entryValue === 'string' ? entryValue : null;
|
|
359
347
|
}
|
|
360
|
-
|
|
361
|
-
|
|
348
|
+
return 0; // continue
|
|
349
|
+
}
|
|
350
|
+
var segments = segmentsByName.get(_name);
|
|
351
|
+
var isArrayField = segments != null;
|
|
352
|
+
|
|
353
|
+
// If segments are not cached for this name, parse and cache them
|
|
354
|
+
if (segments === undefined) {
|
|
355
|
+
var _options$skipEntry;
|
|
356
|
+
if (options !== null && options !== void 0 && (_options$skipEntry = options.skipEntry) !== null && _options$skipEntry !== void 0 && _options$skipEntry.call(options, _name)) {
|
|
357
|
+
// If the entry should be skipped, mark its segments as null
|
|
358
|
+
segments = null;
|
|
359
|
+
} else {
|
|
360
|
+
segments = parsePath(_name);
|
|
361
|
+
// If the name ends with empty brackets "[]", treat it as an array field and push values into an array
|
|
362
|
+
isArrayField = segments.length > 0 && segments[segments.length - 1] === '';
|
|
363
|
+
if (isArrayField) {
|
|
364
|
+
segments = segments.slice(0, -1);
|
|
365
|
+
}
|
|
366
|
+
submission.fields.push(_name);
|
|
362
367
|
}
|
|
368
|
+
segmentsByName.set(_name, segments);
|
|
363
369
|
}
|
|
364
|
-
|
|
370
|
+
if (segments === null) {
|
|
371
|
+
return 0; // continue
|
|
372
|
+
}
|
|
373
|
+
setPathValue(submission.payload, segments, current => {
|
|
374
|
+
if (stripEmptyValues && isEmptyValue(entryValue)) {
|
|
375
|
+
return current;
|
|
376
|
+
}
|
|
377
|
+
if (Array.isArray(current)) {
|
|
378
|
+
current.push(entryValue);
|
|
379
|
+
return current;
|
|
380
|
+
}
|
|
381
|
+
if (current !== undefined) {
|
|
382
|
+
return [current, entryValue];
|
|
383
|
+
}
|
|
384
|
+
return isArrayField ? [entryValue] : entryValue;
|
|
385
|
+
}, {
|
|
365
386
|
silent: true // Avoid errors if the path is invalid
|
|
366
387
|
});
|
|
367
|
-
|
|
368
|
-
|
|
388
|
+
},
|
|
389
|
+
_ret;
|
|
390
|
+
for (var [_name, entryValue] of formData) {
|
|
391
|
+
_ret = _loop(entryValue);
|
|
392
|
+
if (_ret === 0) continue;
|
|
369
393
|
}
|
|
370
|
-
if (
|
|
371
|
-
|
|
372
|
-
var intent = formData.get(intentName);
|
|
373
|
-
if (typeof intent === 'string') {
|
|
374
|
-
submission.intent = intent;
|
|
375
|
-
}
|
|
394
|
+
if (intentValue != null) {
|
|
395
|
+
submission.intent = intentValue;
|
|
376
396
|
}
|
|
377
397
|
return submission;
|
|
378
398
|
}
|
package/dist/formdata.mjs
CHANGED
|
@@ -326,49 +326,69 @@ function isEmptyValue(value) {
|
|
|
326
326
|
* ```
|
|
327
327
|
*/
|
|
328
328
|
function parseSubmission(formData, options) {
|
|
329
|
-
var _options$intentName;
|
|
329
|
+
var _options$intentName, _options$stripEmptyVa;
|
|
330
330
|
var intentName = (_options$intentName = options === null || options === void 0 ? void 0 : options.intentName) !== null && _options$intentName !== void 0 ? _options$intentName : DEFAULT_INTENT_NAME;
|
|
331
331
|
var submission = {
|
|
332
332
|
payload: {},
|
|
333
333
|
fields: [],
|
|
334
334
|
intent: null
|
|
335
335
|
};
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
// If the name ends with [], remove the empty segment and keep the full array
|
|
344
|
-
// Otherwise, unwrap single values
|
|
345
|
-
if (segments.length > 0 && segments[segments.length - 1] === '') {
|
|
346
|
-
segments.pop();
|
|
347
|
-
} else {
|
|
348
|
-
value = value.length > 1 ? value : value[0];
|
|
349
|
-
}
|
|
350
|
-
var stripEmptyValues = (_options$stripEmptyVa = options === null || options === void 0 ? void 0 : options.stripEmptyValues) !== null && _options$stripEmptyVa !== void 0 ? _options$stripEmptyVa : false;
|
|
351
|
-
if (stripEmptyValues) {
|
|
352
|
-
// For arrays, filter out individual empty items
|
|
353
|
-
if (Array.isArray(value)) {
|
|
354
|
-
value = value.filter(item => !isEmptyValue(item));
|
|
336
|
+
var segmentsByName = new Map();
|
|
337
|
+
var stripEmptyValues = (_options$stripEmptyVa = options === null || options === void 0 ? void 0 : options.stripEmptyValues) !== null && _options$stripEmptyVa !== void 0 ? _options$stripEmptyVa : false;
|
|
338
|
+
var intentValue = undefined;
|
|
339
|
+
var _loop = function _loop(entryValue) {
|
|
340
|
+
if (_name === intentName) {
|
|
341
|
+
if (intentValue === undefined) {
|
|
342
|
+
intentValue = typeof entryValue === 'string' ? entryValue : null;
|
|
355
343
|
}
|
|
356
|
-
|
|
357
|
-
|
|
344
|
+
return 0; // continue
|
|
345
|
+
}
|
|
346
|
+
var segments = segmentsByName.get(_name);
|
|
347
|
+
var isArrayField = segments != null;
|
|
348
|
+
|
|
349
|
+
// If segments are not cached for this name, parse and cache them
|
|
350
|
+
if (segments === undefined) {
|
|
351
|
+
var _options$skipEntry;
|
|
352
|
+
if (options !== null && options !== void 0 && (_options$skipEntry = options.skipEntry) !== null && _options$skipEntry !== void 0 && _options$skipEntry.call(options, _name)) {
|
|
353
|
+
// If the entry should be skipped, mark its segments as null
|
|
354
|
+
segments = null;
|
|
355
|
+
} else {
|
|
356
|
+
segments = parsePath(_name);
|
|
357
|
+
// If the name ends with empty brackets "[]", treat it as an array field and push values into an array
|
|
358
|
+
isArrayField = segments.length > 0 && segments[segments.length - 1] === '';
|
|
359
|
+
if (isArrayField) {
|
|
360
|
+
segments = segments.slice(0, -1);
|
|
361
|
+
}
|
|
362
|
+
submission.fields.push(_name);
|
|
358
363
|
}
|
|
364
|
+
segmentsByName.set(_name, segments);
|
|
359
365
|
}
|
|
360
|
-
|
|
366
|
+
if (segments === null) {
|
|
367
|
+
return 0; // continue
|
|
368
|
+
}
|
|
369
|
+
setPathValue(submission.payload, segments, current => {
|
|
370
|
+
if (stripEmptyValues && isEmptyValue(entryValue)) {
|
|
371
|
+
return current;
|
|
372
|
+
}
|
|
373
|
+
if (Array.isArray(current)) {
|
|
374
|
+
current.push(entryValue);
|
|
375
|
+
return current;
|
|
376
|
+
}
|
|
377
|
+
if (current !== undefined) {
|
|
378
|
+
return [current, entryValue];
|
|
379
|
+
}
|
|
380
|
+
return isArrayField ? [entryValue] : entryValue;
|
|
381
|
+
}, {
|
|
361
382
|
silent: true // Avoid errors if the path is invalid
|
|
362
383
|
});
|
|
363
|
-
|
|
364
|
-
|
|
384
|
+
},
|
|
385
|
+
_ret;
|
|
386
|
+
for (var [_name, entryValue] of formData) {
|
|
387
|
+
_ret = _loop(entryValue);
|
|
388
|
+
if (_ret === 0) continue;
|
|
365
389
|
}
|
|
366
|
-
if (
|
|
367
|
-
|
|
368
|
-
var intent = formData.get(intentName);
|
|
369
|
-
if (typeof intent === 'string') {
|
|
370
|
-
submission.intent = intent;
|
|
371
|
-
}
|
|
390
|
+
if (intentValue != null) {
|
|
391
|
+
submission.intent = intentValue;
|
|
372
392
|
}
|
|
373
393
|
return submission;
|
|
374
394
|
}
|
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.19.
|
|
6
|
+
"version": "1.19.4",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"module": "./dist/index.mjs",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
@@ -56,8 +56,11 @@
|
|
|
56
56
|
"@babel/preset-typescript": "^7.20.2",
|
|
57
57
|
"@rollup/plugin-babel": "^5.3.1",
|
|
58
58
|
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
59
|
+
"@vitest/browser-playwright": "^4.1.5",
|
|
60
|
+
"playwright": "^1.49.1",
|
|
59
61
|
"rollup-plugin-copy": "^3.4.0",
|
|
60
|
-
"rollup": "^2.79.1"
|
|
62
|
+
"rollup": "^2.79.1",
|
|
63
|
+
"vitest": "^4.1.5"
|
|
61
64
|
},
|
|
62
65
|
"scripts": {
|
|
63
66
|
"build:js": "rollup -c",
|
|
@@ -66,6 +69,7 @@
|
|
|
66
69
|
"dev:js": "pnpm run build:js --watch",
|
|
67
70
|
"dev:ts": "pnpm run build:ts --watch",
|
|
68
71
|
"dev": "pnpm run \"/^dev:.*/\"",
|
|
72
|
+
"test": "vitest",
|
|
69
73
|
"typecheck": "tsc"
|
|
70
74
|
}
|
|
71
75
|
}
|