@conform-to/dom
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -120,7 +120,9 @@ 'use strict'; | ||
meta.key = util.clone(meta.key); | ||
submission.setListState(meta.key, intent, (defaultValue, name) => { | ||
submission.setListState(meta.key, intent, defaultValue => { | ||
if (!Array.isArray(defaultValue) && !formdata.isPlainObject(defaultValue)) { | ||
return util.generateId(); | ||
} | ||
return getDefaultKey(defaultValue, name); | ||
return Object.assign(getDefaultKey(defaultValue), { | ||
[submission.root]: util.generateId() | ||
}); | ||
}); | ||
@@ -369,3 +371,3 @@ submission.setListValue(meta.initialValue, intent); | ||
var element = event.target; | ||
if (!form || !dom.isFieldElement(element) || element.form !== form || element.name === '') { | ||
if (!form || !dom.isFieldElement(element) || element.form !== form || !element.form.isConnected || element.name === '') { | ||
return null; | ||
@@ -372,0 +374,0 @@ } |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"main": "index.js", | ||
@@ -9,0 +9,0 @@ "module": "index.mjs", |
@@ -119,4 +119,8 @@ import type { DefaultValue, FieldName, FormValue } from './form'; | ||
export declare function setListValue(data: Record<string, unknown>, intent: InsertIntent | RemoveIntent | ReorderIntent): void; | ||
/** | ||
* A placeholder symbol for the root value of a nested object | ||
*/ | ||
export declare const root: unique symbol; | ||
export declare function setState(state: Record<string, unknown>, name: string, valueFn: (value: unknown) => unknown): void; | ||
export declare function setListState(state: Record<string, unknown>, intent: InsertIntent | RemoveIntent | ReorderIntent, getDefaultValue?: (defaultValue: any, prefix?: string) => any): void; | ||
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>; |
@@ -84,2 +84,11 @@ 'use strict'; | ||
case 'insert': | ||
{ | ||
setListValue(context.payload, { | ||
type: intent.type, | ||
payload: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, intent.payload), {}, { | ||
defaultValue: serialize(intent.payload.defaultValue) | ||
}) | ||
}); | ||
break; | ||
} | ||
case 'remove': | ||
@@ -172,3 +181,3 @@ case 'reorder': | ||
case 'insert': | ||
list.splice((_intent$payload$index = intent.payload.index) !== null && _intent$payload$index !== void 0 ? _intent$payload$index : list.length, 0, serialize(intent.payload.defaultValue)); | ||
list.splice((_intent$payload$index = intent.payload.index) !== null && _intent$payload$index !== void 0 ? _intent$payload$index : list.length, 0, intent.payload.defaultValue); | ||
break; | ||
@@ -192,5 +201,8 @@ case 'remove': | ||
} | ||
/** | ||
* A placeholder symbol for the root value of a nested object | ||
*/ | ||
var root = Symbol.for('root'); | ||
function setState(state, name, valueFn) { | ||
var root = Symbol.for('root'); | ||
// The keys are sorted in desc so that the root value is handled last | ||
@@ -245,3 +257,3 @@ var keys = Object.keys(state).sort((prev, next) => next.localeCompare(prev)); | ||
payload: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, intent.payload), {}, { | ||
defaultValue: getDefaultValue === null || getDefaultValue === void 0 ? void 0 : getDefaultValue(intent.payload.defaultValue, intent.payload.name) | ||
defaultValue: getDefaultValue === null || getDefaultValue === void 0 ? void 0 : getDefaultValue(intent.payload.defaultValue) | ||
}) | ||
@@ -293,2 +305,3 @@ }); | ||
exports.replySubmission = replySubmission; | ||
exports.root = root; | ||
exports.serialize = serialize; | ||
@@ -295,0 +308,0 @@ exports.serializeIntent = serializeIntent; |
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
105081
2775