@conform-to/dom 1.0.4 → 1.0.5

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 CHANGED
@@ -8,7 +8,7 @@
8
8
  ╚══════╝ ╚═════╝ ╚═╝ ╚══╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
9
9
 
10
10
 
11
- Version 1.0.3 / License MIT / Copyright (c) 2024 Edmund Hung
11
+ Version 1.0.4 / 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
@@ -117,7 +117,12 @@ function handleIntent(meta, intent, fields, initialized) {
117
117
  if (initialized) {
118
118
  meta.initialValue = util.clone(meta.initialValue);
119
119
  meta.key = util.clone(meta.key);
120
- submission.setListState(meta.key, intent, util.generateId);
120
+ submission.setListState(meta.key, intent, (defaultValue, name) => {
121
+ if (!Array.isArray(defaultValue) && !formdata.isPlainObject(defaultValue)) {
122
+ return util.generateId();
123
+ }
124
+ return getDefaultKey(defaultValue, name);
125
+ });
121
126
  submission.setListValue(meta.initialValue, intent);
122
127
  }
123
128
  submission.setListState(meta.validated, intent);
@@ -134,6 +139,12 @@ function handleIntent(meta, intent, fields, initialized) {
134
139
  }, {});
135
140
  }
136
141
  function updateValue(meta, name, value) {
142
+ if (name === '') {
143
+ meta.initialValue = value;
144
+ meta.value = value;
145
+ meta.key = getDefaultKey(value);
146
+ return;
147
+ }
137
148
  meta.initialValue = util.clone(meta.initialValue);
138
149
  meta.value = util.clone(meta.value);
139
150
  meta.key = util.clone(meta.key);
package/form.mjs CHANGED
@@ -113,7 +113,12 @@ function handleIntent(meta, intent, fields, initialized) {
113
113
  if (initialized) {
114
114
  meta.initialValue = clone(meta.initialValue);
115
115
  meta.key = clone(meta.key);
116
- setListState(meta.key, intent, generateId);
116
+ setListState(meta.key, intent, (defaultValue, name) => {
117
+ if (!Array.isArray(defaultValue) && !isPlainObject(defaultValue)) {
118
+ return generateId();
119
+ }
120
+ return getDefaultKey(defaultValue, name);
121
+ });
117
122
  setListValue(meta.initialValue, intent);
118
123
  }
119
124
  setListState(meta.validated, intent);
@@ -130,6 +135,12 @@ function handleIntent(meta, intent, fields, initialized) {
130
135
  }, {});
131
136
  }
132
137
  function updateValue(meta, name, value) {
138
+ if (name === '') {
139
+ meta.initialValue = value;
140
+ meta.value = value;
141
+ meta.key = getDefaultKey(value);
142
+ return;
143
+ }
133
144
  meta.initialValue = clone(meta.initialValue);
134
145
  meta.value = clone(meta.value);
135
146
  meta.key = clone(meta.key);
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.4",
6
+ "version": "1.0.5",
7
7
  "main": "index.js",
8
8
  "module": "index.mjs",
9
9
  "types": "index.d.ts",
package/submission.d.ts CHANGED
@@ -117,5 +117,5 @@ export declare function serializeIntent<Schema>(intent: Intent<Schema>): string;
117
117
  export declare function updateList(list: unknown, intent: InsertIntent | RemoveIntent | ReorderIntent): void;
118
118
  export declare function setListValue(data: Record<string, unknown>, intent: InsertIntent | RemoveIntent | ReorderIntent): void;
119
119
  export declare function setState(state: Record<string, unknown>, name: string, valueFn: (value: unknown) => unknown): void;
120
- export declare function setListState(state: Record<string, unknown>, intent: InsertIntent | RemoveIntent | ReorderIntent, getDefaultValue?: () => string): void;
120
+ export declare function setListState(state: Record<string, unknown>, intent: InsertIntent | RemoveIntent | ReorderIntent, getDefaultValue?: (defaultValue: any, prefix?: string) => any): void;
121
121
  export declare function serialize<Schema>(defaultValue: DefaultValue<Schema>): FormValue<Schema>;
package/submission.js CHANGED
@@ -239,7 +239,7 @@ function setListState(state, intent, getDefaultValue) {
239
239
  updateList(list, {
240
240
  type: intent.type,
241
241
  payload: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, intent.payload), {}, {
242
- defaultValue: getDefaultValue === null || getDefaultValue === void 0 ? void 0 : getDefaultValue()
242
+ defaultValue: getDefaultValue === null || getDefaultValue === void 0 ? void 0 : getDefaultValue(intent.payload.defaultValue, intent.payload.name)
243
243
  })
244
244
  });
245
245
  break;
package/submission.mjs CHANGED
@@ -235,7 +235,7 @@ function setListState(state, intent, getDefaultValue) {
235
235
  updateList(list, {
236
236
  type: intent.type,
237
237
  payload: _objectSpread2(_objectSpread2({}, intent.payload), {}, {
238
- defaultValue: getDefaultValue === null || getDefaultValue === void 0 ? void 0 : getDefaultValue()
238
+ defaultValue: getDefaultValue === null || getDefaultValue === void 0 ? void 0 : getDefaultValue(intent.payload.defaultValue, intent.payload.name)
239
239
  })
240
240
  });
241
241
  break;