@formisch/preact 0.7.5 → 0.9.0
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/dist/index.d.ts +23 -4
- package/dist/index.js +7 -3
- package/package.json +4 -5
package/dist/index.d.ts
CHANGED
|
@@ -282,7 +282,11 @@ interface BaseFormStore<TSchema extends Schema = Schema> {
|
|
|
282
282
|
/**
|
|
283
283
|
* Submit handler type.
|
|
284
284
|
*/
|
|
285
|
-
type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema
|
|
285
|
+
type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>) => MaybePromise<unknown>;
|
|
286
|
+
/**
|
|
287
|
+
* Submit event handler type.
|
|
288
|
+
*/
|
|
289
|
+
type SubmitEventHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<unknown>;
|
|
286
290
|
//#endregion
|
|
287
291
|
//#region src/types/path.d.ts
|
|
288
292
|
/**
|
|
@@ -467,6 +471,17 @@ declare function getInput<TSchema extends Schema, TFieldPath extends RequiredPat
|
|
|
467
471
|
//#endregion
|
|
468
472
|
//#region src/handleSubmit/handleSubmit.d.ts
|
|
469
473
|
/**
|
|
474
|
+
* Creates a submit event handler for the form that validates the form input,
|
|
475
|
+
* and calls the provided handler if validation succeeds. This is designed to
|
|
476
|
+
* be used with the form's onsubmit event.
|
|
477
|
+
*
|
|
478
|
+
* @param form The form store to handle submission for.
|
|
479
|
+
* @param handler The submit handler function called with validated output if validation succeeds.
|
|
480
|
+
*
|
|
481
|
+
* @returns A submit event handler function to attach to the form element.
|
|
482
|
+
*/
|
|
483
|
+
declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitHandler<TSchema>): () => Promise<void>;
|
|
484
|
+
/**
|
|
470
485
|
* Creates a submit event handler for the form that prevents default browser
|
|
471
486
|
* submission, validates the form input, and calls the provided handler if
|
|
472
487
|
* validation succeeds. This is designed to be used with the form's onsubmit event.
|
|
@@ -476,7 +491,7 @@ declare function getInput<TSchema extends Schema, TFieldPath extends RequiredPat
|
|
|
476
491
|
*
|
|
477
492
|
* @returns A submit event handler function to attach to the form element.
|
|
478
493
|
*/
|
|
479
|
-
declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler:
|
|
494
|
+
declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitEventHandler<TSchema>): (event: SubmitEvent) => Promise<void>;
|
|
480
495
|
//#endregion
|
|
481
496
|
//#region src/insert/insert.d.ts
|
|
482
497
|
/**
|
|
@@ -853,6 +868,10 @@ interface FieldStore<TSchema extends Schema = Schema, TFieldPath extends Require
|
|
|
853
868
|
*/
|
|
854
869
|
readonly isValid: ReadonlySignal<boolean>;
|
|
855
870
|
/**
|
|
871
|
+
* Sets the field input value programmatically.
|
|
872
|
+
*/
|
|
873
|
+
readonly onInput: (value: PartialValues<PathValue<v.InferInput<TSchema>, TFieldPath>>) => void;
|
|
874
|
+
/**
|
|
856
875
|
* The props to spread onto the field element for integration.
|
|
857
876
|
*/
|
|
858
877
|
readonly props: FieldElementProps;
|
|
@@ -1004,7 +1023,7 @@ type FormProps<TSchema extends Schema = Schema> = Omit<JSX.FormHTMLAttributes<HT
|
|
|
1004
1023
|
/**
|
|
1005
1024
|
* The submit handler called when the form is submitted and validation succeeds.
|
|
1006
1025
|
*/
|
|
1007
|
-
readonly onSubmit: SubmitHandler<TSchema>;
|
|
1026
|
+
readonly onSubmit: SubmitHandler<TSchema> | SubmitEventHandler<TSchema>;
|
|
1008
1027
|
};
|
|
1009
1028
|
/**
|
|
1010
1029
|
* Form component that manages form submission and applies internal state.
|
|
@@ -1067,4 +1086,4 @@ declare function useFieldArray<TSchema extends Schema, TFieldArrayPath extends R
|
|
|
1067
1086
|
*/
|
|
1068
1087
|
declare function useForm<TSchema extends Schema>(config: FormConfig<TSchema>): FormStore<TSchema>;
|
|
1069
1088
|
//#endregion
|
|
1070
|
-
export { type DeepPartial, Field, FieldArray, FieldArrayProps, FieldArrayStore, type FieldElement, FieldElementProps, FieldProps, FieldStore, FocusFieldConfig, Form, type FormConfig, FormProps, FormStore, GetFieldErrorsConfig, GetFieldInputConfig, GetFormErrorsConfig, GetFormInputConfig, InsertConfig, MoveConfig, type PartialValues, type PathValue, RemoveConfig, ReplaceConfig, type RequiredPath, ResetFieldConfig, ResetFormConfig, type Schema, SetFieldErrorsConfig, SetFieldInputConfig, SetFormErrorsConfig, SetFormInputConfig, type SubmitHandler, SwapConfig, UseFieldArrayConfig, UseFieldConfig, type ValidArrayPath, type ValidPath, ValidateFormConfig, type ValidationMode, focus, getAllErrors, getErrors, getInput, handleSubmit, insert, move, remove, replace, reset, setErrors, setInput, submit, swap, useField, useFieldArray, useForm, validate };
|
|
1089
|
+
export { type DeepPartial, Field, FieldArray, FieldArrayProps, FieldArrayStore, type FieldElement, FieldElementProps, FieldProps, FieldStore, FocusFieldConfig, Form, type FormConfig, FormProps, FormStore, GetFieldErrorsConfig, GetFieldInputConfig, GetFormErrorsConfig, GetFormInputConfig, InsertConfig, MoveConfig, type PartialValues, type PathValue, RemoveConfig, ReplaceConfig, type RequiredPath, ResetFieldConfig, ResetFormConfig, type Schema, SetFieldErrorsConfig, SetFieldInputConfig, SetFormErrorsConfig, SetFormInputConfig, type SubmitEventHandler, type SubmitHandler, SwapConfig, UseFieldArrayConfig, UseFieldConfig, type ValidArrayPath, type ValidPath, ValidateFormConfig, type ValidationMode, focus, getAllErrors, getErrors, getInput, handleSubmit, insert, move, remove, replace, reset, setErrors, setInput, submit, swap, useField, useFieldArray, useForm, validate };
|
package/dist/index.js
CHANGED
|
@@ -55,7 +55,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path, nu
|
|
|
55
55
|
initializeFieldStore(internalFieldStore.children[index], schema.item, initialInput[index], path);
|
|
56
56
|
path.pop();
|
|
57
57
|
}
|
|
58
|
-
} else for (let index = 0; index < schema.items; index++) {
|
|
58
|
+
} else for (let index = 0; index < schema.items.length; index++) {
|
|
59
59
|
internalFieldStore.children[index] = {};
|
|
60
60
|
path.push(index);
|
|
61
61
|
initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput?.[index], path);
|
|
@@ -368,7 +368,7 @@ function setNestedInput(internalFieldStore, input) {
|
|
|
368
368
|
}
|
|
369
369
|
for (let index = 0; index < arrayInput.length; index++) setNestedInput(internalFieldStore.children[index], arrayInput[index]);
|
|
370
370
|
internalFieldStore.input.value = input == null ? input : true;
|
|
371
|
-
internalFieldStore.isDirty.value = internalFieldStore.startInput.value !== internalFieldStore.input.value || internalFieldStore.startItems.value.length !== items.length;
|
|
371
|
+
internalFieldStore.isDirty.value = internalFieldStore.startInput.value !== internalFieldStore.input.value || internalFieldStore.startItems.value.length !== internalFieldStore.items.value.length;
|
|
372
372
|
} else if (internalFieldStore.kind === "object") {
|
|
373
373
|
for (const key in internalFieldStore.children) setNestedInput(internalFieldStore.children[key], input?.[key]);
|
|
374
374
|
internalFieldStore.input.value = input == null ? input : true;
|
|
@@ -575,7 +575,7 @@ function getInput(form, config) {
|
|
|
575
575
|
/* @__NO_SIDE_EFFECTS__ */
|
|
576
576
|
function handleSubmit(form, handler) {
|
|
577
577
|
return async (event) => {
|
|
578
|
-
event
|
|
578
|
+
event?.preventDefault();
|
|
579
579
|
const internalFormStore = form[INTERNAL];
|
|
580
580
|
internalFormStore.isSubmitted.value = true;
|
|
581
581
|
internalFormStore.isSubmitting.value = true;
|
|
@@ -825,6 +825,10 @@ function useField(form, config) {
|
|
|
825
825
|
isTouched: computed(() => getFieldBool(internalFieldStore.value, "isTouched")),
|
|
826
826
|
isDirty: computed(() => getFieldBool(internalFieldStore.value, "isDirty")),
|
|
827
827
|
isValid: computed(() => !getFieldBool(internalFieldStore.value, "errors")),
|
|
828
|
+
onInput(value) {
|
|
829
|
+
setFieldInput(internalFormStore, pathSignal.value, value);
|
|
830
|
+
validateIfRequired(internalFormStore, internalFieldStore.value, "input");
|
|
831
|
+
},
|
|
828
832
|
props: {
|
|
829
833
|
get name() {
|
|
830
834
|
return internalFieldStore.value.name;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formisch/preact",
|
|
3
3
|
"description": "The modular and type-safe form library for Preact",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.9.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Fabian Hiller",
|
|
7
7
|
"homepage": "https://formisch.dev",
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@eslint/js": "^9.31.0",
|
|
37
36
|
"@preact/preset-vite": "^2.9.3",
|
|
38
37
|
"@preact/signals": "^2.2.1",
|
|
39
38
|
"eslint": "^9.31.0",
|
|
@@ -41,11 +40,11 @@
|
|
|
41
40
|
"preact": "^10.25.3",
|
|
42
41
|
"tsdown": "^0.16.8",
|
|
43
42
|
"typescript": "^5.8.3",
|
|
44
|
-
"typescript-eslint": "^8.37.0",
|
|
45
43
|
"valibot": "^1.2.0",
|
|
46
44
|
"vite": "^6.0.4",
|
|
47
|
-
"@formisch/
|
|
48
|
-
"@formisch/
|
|
45
|
+
"@formisch/eslint-config": "0.1.0",
|
|
46
|
+
"@formisch/core": "0.6.0",
|
|
47
|
+
"@formisch/methods": "0.7.0"
|
|
49
48
|
},
|
|
50
49
|
"peerDependencies": {
|
|
51
50
|
"@preact/signals": "^2.0.0",
|