@conform-to/dom 1.0.3 → 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 +1 -1
- package/form.d.ts +0 -4
- package/form.js +14 -5
- package/form.mjs +14 -5
- package/package.json +1 -1
- package/submission.d.ts +1 -1
- package/submission.js +1 -1
- package/submission.mjs +1 -1
package/README
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
╚══════╝ ╚═════╝ ╚═╝ ╚══╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
Version 1.0.
|
|
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.d.ts
CHANGED
|
@@ -90,10 +90,6 @@ export type FormOptions<Schema, FormError = string[], FormValue = Schema> = {
|
|
|
90
90
|
submitter: HTMLInputElement | HTMLButtonElement | null;
|
|
91
91
|
formData: FormData;
|
|
92
92
|
}) => Submission<Schema, FormError, FormValue>;
|
|
93
|
-
/**
|
|
94
|
-
* To schedule when an intent should be dispatched.
|
|
95
|
-
*/
|
|
96
|
-
onSchedule?: (callback: () => void) => void;
|
|
97
93
|
};
|
|
98
94
|
export type SubscriptionSubject = {
|
|
99
95
|
[key in 'error' | 'initialValue' | 'value' | 'key' | 'valid' | 'dirty']?: SubscriptionScope;
|
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,
|
|
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);
|
|
@@ -485,14 +496,12 @@ function createFormContext(options) {
|
|
|
485
496
|
};
|
|
486
497
|
}
|
|
487
498
|
function createFormControl(type) {
|
|
488
|
-
var _latestOptions$onSche;
|
|
489
|
-
var schedule = (_latestOptions$onSche = latestOptions.onSchedule) !== null && _latestOptions$onSche !== void 0 ? _latestOptions$onSche : callback => callback();
|
|
490
499
|
var control = function control() {
|
|
491
500
|
var payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
492
|
-
return
|
|
501
|
+
return dispatch({
|
|
493
502
|
type,
|
|
494
503
|
payload
|
|
495
|
-
})
|
|
504
|
+
});
|
|
496
505
|
};
|
|
497
506
|
return Object.assign(control, {
|
|
498
507
|
getButtonProps() {
|
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,
|
|
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);
|
|
@@ -481,14 +492,12 @@ function createFormContext(options) {
|
|
|
481
492
|
};
|
|
482
493
|
}
|
|
483
494
|
function createFormControl(type) {
|
|
484
|
-
var _latestOptions$onSche;
|
|
485
|
-
var schedule = (_latestOptions$onSche = latestOptions.onSchedule) !== null && _latestOptions$onSche !== void 0 ? _latestOptions$onSche : callback => callback();
|
|
486
495
|
var control = function control() {
|
|
487
496
|
var payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
488
|
-
return
|
|
497
|
+
return dispatch({
|
|
489
498
|
type,
|
|
490
499
|
payload
|
|
491
|
-
})
|
|
500
|
+
});
|
|
492
501
|
};
|
|
493
502
|
return Object.assign(control, {
|
|
494
503
|
getButtonProps() {
|
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.
|
|
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?: () =>
|
|
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;
|