@conform-to/dom
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -77,3 +77,3 @@ 'use strict'; | ||
if (typeof value !== 'undefined') { | ||
updateValue(meta, _name2 !== null && _name2 !== void 0 ? _name2 : '', submission.serialize(value)); | ||
updateValue(meta, _name2 !== null && _name2 !== void 0 ? _name2 : '', value); | ||
} | ||
@@ -80,0 +80,0 @@ if (typeof validated !== 'undefined') { |
@@ -58,5 +58,5 @@ /** | ||
*/ | ||
export declare function flatten(data: Record<string | number | symbol, unknown> | Array<unknown> | undefined, options?: { | ||
resolve?: (data: unknown) => unknown | null; | ||
export declare function flatten(data: unknown, options?: { | ||
resolve?: (data: unknown) => unknown; | ||
prefix?: string; | ||
}): Record<string, unknown>; |
@@ -177,36 +177,19 @@ 'use strict'; | ||
*/ | ||
function flatten(data, options) { | ||
function flatten(data) { | ||
var _options$resolve; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var result = {}; | ||
var resolve = (_options$resolve = options === null || options === void 0 ? void 0 : options.resolve) !== null && _options$resolve !== void 0 ? _options$resolve : data => data; | ||
function setResult(data, name) { | ||
var resolve = (_options$resolve = options.resolve) !== null && _options$resolve !== void 0 ? _options$resolve : data => data; | ||
function process(data, prefix) { | ||
var value = normalize(resolve(data)); | ||
if (typeof value !== 'undefined') { | ||
result[name] = value; | ||
result[prefix] = value; | ||
} | ||
} | ||
function processObject(obj, prefix) { | ||
setResult(obj, prefix); | ||
for (var [key, _value] of Object.entries(obj)) { | ||
var name = prefix ? "".concat(prefix, ".").concat(key) : key; | ||
if (Array.isArray(_value)) { | ||
processArray(_value, name); | ||
} else if (_value && isPlainObject(_value)) { | ||
processObject(_value, name); | ||
} else { | ||
setResult(_value, name); | ||
if (Array.isArray(data)) { | ||
for (var i = 0; i < data.length; i++) { | ||
process(data[i], "".concat(prefix, "[").concat(i, "]")); | ||
} | ||
} | ||
} | ||
function processArray(array, prefix) { | ||
setResult(array, prefix); | ||
for (var i = 0; i < array.length; i++) { | ||
var item = array[i]; | ||
var name = "".concat(prefix, "[").concat(i, "]"); | ||
if (Array.isArray(item)) { | ||
processArray(item, name); | ||
} else if (item && isPlainObject(item)) { | ||
processObject(item, name); | ||
} else { | ||
setResult(item, name); | ||
} else if (isPlainObject(data)) { | ||
for (var [key, _value] of Object.entries(data)) { | ||
process(_value, prefix ? "".concat(prefix, ".").concat(key) : key); | ||
} | ||
@@ -217,8 +200,3 @@ } | ||
var _options$prefix; | ||
var prefix = (_options$prefix = options === null || options === void 0 ? void 0 : options.prefix) !== null && _options$prefix !== void 0 ? _options$prefix : ''; | ||
if (Array.isArray(data)) { | ||
processArray(data, prefix); | ||
} else { | ||
processObject(data, prefix); | ||
} | ||
process(data, (_options$prefix = options.prefix) !== null && _options$prefix !== void 0 ? _options$prefix : ''); | ||
} | ||
@@ -225,0 +203,0 @@ return result; |
117
package.json
{ | ||
"name": "@conform-to/dom", | ||
"description": "A set of opinionated helpers built on top of the Constraint Validation API", | ||
"homepage": "https://conform.guide", | ||
"license": "MIT", | ||
"version": "1.1.3", | ||
"main": "index.js", | ||
"module": "index.mjs", | ||
"types": "index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./index.d.ts", | ||
"module": "./index.mjs", | ||
"import": "./index.mjs", | ||
"require": "./index.js", | ||
"default": "./index.mjs" | ||
} | ||
}, | ||
"scripts": { | ||
"build:js": "rollup -c", | ||
"build:ts": "tsc", | ||
"build": "pnpm run \"/^build:.*/\"", | ||
"dev:js": "pnpm run build:js --watch", | ||
"dev:ts": "pnpm run build:ts --watch", | ||
"dev": "pnpm run \"/^dev:.*/\"", | ||
"prepare": "pnpm run build" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/edmundhung/conform", | ||
"directory": "packages/conform-dom" | ||
}, | ||
"author": { | ||
"name": "Edmund Hung", | ||
"email": "me@edmund.dev", | ||
"url": "https://edmund.dev" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/edmundhung/conform/issues" | ||
}, | ||
"keywords": [ | ||
"constraint-validation", | ||
"form", | ||
"form-validation", | ||
"html", | ||
"progressive-enhancement", | ||
"validation", | ||
"dom" | ||
], | ||
"sideEffects": false, | ||
"devDependencies": { | ||
"@babel/core": "^7.17.8", | ||
"@babel/preset-env": "^7.20.2", | ||
"@babel/preset-typescript": "^7.20.2", | ||
"@rollup/plugin-babel": "^5.3.1", | ||
"@rollup/plugin-node-resolve": "^13.3.0", | ||
"rollup-plugin-copy": "^3.4.0", | ||
"rollup": "^2.79.1" | ||
} | ||
} | ||
"name": "@conform-to/dom", | ||
"description": "A set of opinionated helpers built on top of the Constraint Validation API", | ||
"homepage": "https://conform.guide", | ||
"license": "MIT", | ||
"version": "1.1.4", | ||
"main": "index.js", | ||
"module": "index.mjs", | ||
"types": "index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./index.d.ts", | ||
"module": "./index.mjs", | ||
"import": "./index.mjs", | ||
"require": "./index.js", | ||
"default": "./index.mjs" | ||
} | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/edmundhung/conform", | ||
"directory": "packages/conform-dom" | ||
}, | ||
"author": { | ||
"name": "Edmund Hung", | ||
"email": "me@edmund.dev", | ||
"url": "https://edmund.dev" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/edmundhung/conform/issues" | ||
}, | ||
"keywords": [ | ||
"constraint-validation", | ||
"form", | ||
"form-validation", | ||
"html", | ||
"progressive-enhancement", | ||
"validation", | ||
"dom" | ||
], | ||
"sideEffects": false, | ||
"devDependencies": { | ||
"@babel/core": "^7.17.8", | ||
"@babel/preset-env": "^7.20.2", | ||
"@babel/preset-typescript": "^7.20.2", | ||
"@rollup/plugin-babel": "^5.3.1", | ||
"@rollup/plugin-node-resolve": "^13.3.0", | ||
"rollup-plugin-copy": "^3.4.0", | ||
"rollup": "^2.79.1" | ||
}, | ||
"scripts": { | ||
"build:js": "rollup -c", | ||
"build:ts": "tsc", | ||
"build": "pnpm run \"/^build:.*/\"", | ||
"dev:js": "pnpm run build:js --watch", | ||
"dev:ts": "pnpm run build:ts --watch", | ||
"dev": "pnpm run \"/^dev:.*/\"" | ||
} | ||
} |
@@ -97,3 +97,3 @@ import type { DefaultValue, FieldName, FormValue } from './form'; | ||
index: Schema extends Array<unknown> ? number : never; | ||
value?: NonNullable<DefaultValue<Schema extends Array<infer Item> ? Item : unknown>>; | ||
value?: Schema extends Array<infer Item> ? NonNullable<DefaultValue<Item>> : never; | ||
validated?: boolean; | ||
@@ -136,2 +136,2 @@ }; | ||
export declare function setListState(state: Record<string, unknown>, intent: InsertIntent | RemoveIntent | ReorderIntent, getDefaultValue?: (defaultValue: any) => any): void; | ||
export declare function serialize<Schema>(defaultValue: DefaultValue<Schema>): FormValue<Schema>; | ||
export declare function serialize<Schema>(defaultValue: Schema): FormValue<Schema>; |
@@ -58,8 +58,7 @@ 'use strict'; | ||
var name = formdata.formatName(intent.payload.name, intent.payload.index); | ||
var _value = serialize(intent.payload.value); | ||
if (typeof _value !== 'undefined') { | ||
var _value = intent.payload.value; | ||
if (typeof intent.payload.value !== 'undefined') { | ||
if (name) { | ||
formdata.setValue(context.payload, name, () => _value); | ||
} else { | ||
// @ts-expect-error FIXME - it must be an object if there is no name | ||
context.payload = _value; | ||
@@ -81,11 +80,2 @@ } | ||
case 'insert': | ||
{ | ||
setListValue(context.payload, { | ||
type: intent.type, | ||
payload: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, intent.payload), {}, { | ||
defaultValue: serialize(intent.payload.defaultValue) | ||
}) | ||
}); | ||
break; | ||
} | ||
case 'remove': | ||
@@ -171,3 +161,20 @@ case 'reorder': | ||
function serializeIntent(intent) { | ||
return JSON.stringify(intent); | ||
switch (intent.type) { | ||
case 'insert': | ||
return JSON.stringify({ | ||
type: intent.type, | ||
payload: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, intent.payload), {}, { | ||
defaultValue: serialize(intent.payload.defaultValue) | ||
}) | ||
}); | ||
case 'update': | ||
return JSON.stringify({ | ||
type: intent.type, | ||
payload: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, intent.payload), {}, { | ||
value: serialize(intent.payload.value) | ||
}) | ||
}); | ||
default: | ||
return JSON.stringify(intent); | ||
} | ||
} | ||
@@ -231,5 +238,3 @@ function updateList(list, intent) { | ||
var result = valueFn(formdata.getValue(target, name)); | ||
Object.assign(state, | ||
// @ts-expect-error FIXME flatten should be more flexible | ||
formdata.flatten(result, { | ||
Object.assign(state, formdata.flatten(result, { | ||
resolve(data) { | ||
@@ -270,3 +275,2 @@ if (formdata.isPlainObject(data) || Array.isArray(data)) { | ||
var [key, value] = _ref; | ||
// @ts-ignore-error FIXME | ||
result[key] = serialize(value); | ||
@@ -278,5 +282,3 @@ return result; | ||
return defaultValue.map(serialize); | ||
} else if ( | ||
// @ts-ignore-error FIXME | ||
defaultValue instanceof Date) { | ||
} else if (defaultValue instanceof Date) { | ||
// @ts-expect-error FIXME | ||
@@ -287,3 +289,3 @@ return defaultValue.toISOString(); | ||
return defaultValue ? 'on' : undefined; | ||
} else if (typeof defaultValue === 'number') { | ||
} else if (typeof defaultValue === 'number' || typeof defaultValue === 'bigint') { | ||
// @ts-expect-error FIXME | ||
@@ -290,0 +292,0 @@ return defaultValue.toString(); |
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
125551
31
3399