@formisch/svelte 0.6.0 → 0.7.1

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.md CHANGED
@@ -30,7 +30,7 @@ Every form starts with the `createForm` function. It initializes your form's sto
30
30
  const loginForm = createForm({ schema: LoginSchema });
31
31
  </script>
32
32
 
33
- <Form of={loginForm} onsubmit={(output) => console.log(output)}>
33
+ <Form of={loginForm} onsubmit={(output, event) => console.log(output)}>
34
34
  <Field of={loginForm} path={['email']}>
35
35
  {#snippet children(field)}
36
36
  <div>
@@ -3,6 +3,7 @@
3
3
  INTERNAL,
4
4
  type Schema,
5
5
  type SubmitHandler,
6
+ type SubmitEventHandler,
6
7
  } from '../../core/index.svelte';
7
8
  import { handleSubmit } from '../../methods/index.svelte';
8
9
  import type { FormStore } from '../../types/index';
@@ -23,7 +24,7 @@
23
24
  /**
24
25
  * The submit handler called when the form is submitted and validation succeeds.
25
26
  */
26
- onsubmit: SubmitHandler<TSchema>;
27
+ onsubmit: SubmitHandler<TSchema> | SubmitEventHandler<TSchema>;
27
28
  /**
28
29
  * The child elements to render within the form.
29
30
  */
@@ -1,4 +1,4 @@
1
- import { type Schema, type SubmitHandler } from '../../core/index.svelte';
1
+ import { type Schema, type SubmitHandler, type SubmitEventHandler } from '../../core/index.svelte';
2
2
  import type { FormStore } from '../../types/index';
3
3
  import type { Snippet } from 'svelte';
4
4
  import type { HTMLFormAttributes } from 'svelte/elements';
@@ -13,7 +13,7 @@ export type FormProps<TSchema extends Schema = Schema> = Omit<HTMLFormAttributes
13
13
  /**
14
14
  * The submit handler called when the form is submitted and validation succeeds.
15
15
  */
16
- onsubmit: SubmitHandler<TSchema>;
16
+ onsubmit: SubmitHandler<TSchema> | SubmitEventHandler<TSchema>;
17
17
  /**
18
18
  * The child elements to render within the form.
19
19
  */
@@ -212,11 +212,11 @@ type MaybePromise<TValue> = TValue | Promise<TValue>;
212
212
  /**
213
213
  * Makes all properties deeply optional.
214
214
  */
215
- type DeepPartial<TValue> = TValue extends readonly unknown[] ? number extends TValue["length"] ? TValue : { [Key in keyof TValue]?: DeepPartial<TValue[Key]> | undefined } : TValue extends Record<PropertyKey, unknown> ? { [Key in keyof TValue]?: DeepPartial<TValue[Key]> | undefined } : TValue | undefined;
215
+ type DeepPartial<TValue> = TValue extends Record<PropertyKey, unknown> | readonly unknown[] ? { [Key in keyof TValue]?: DeepPartial<TValue[Key]> | undefined } : TValue | undefined;
216
216
  /**
217
217
  * Makes all value properties optional.
218
218
  */
219
- type PartialValues<TValue> = TValue extends readonly unknown[] ? number extends TValue["length"] ? TValue : { [Key in keyof TValue]: PartialValues<TValue[Key]> } : TValue extends Record<PropertyKey, unknown> ? { [Key in keyof TValue]: PartialValues<TValue[Key]> } : TValue | undefined;
219
+ type PartialValues<TValue> = TValue extends Record<PropertyKey, unknown> | readonly unknown[] ? { [Key in keyof TValue]: PartialValues<TValue[Key]> } : TValue | undefined;
220
220
  //#endregion
221
221
  //#region src/types/form.d.ts
222
222
  /**
@@ -295,7 +295,11 @@ interface BaseFormStore<TSchema extends Schema = Schema> {
295
295
  /**
296
296
  * Submit handler type.
297
297
  */
298
- type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<unknown>;
298
+ type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>) => MaybePromise<unknown>;
299
+ /**
300
+ * Submit event handler type.
301
+ */
302
+ type SubmitEventHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<unknown>;
299
303
  //#endregion
300
304
  //#region src/types/path.d.ts
301
305
  /**
@@ -578,4 +582,4 @@ declare function createSignal<T>(initialValue: T): Signal<T>;
578
582
  */
579
583
  declare function batch<T>(fn: () => T): T;
580
584
  //#endregion
581
- export { BaseFormStore, Batch, DeepPartial, FieldElement, FieldSchema, FormConfig, INTERNAL, InternalArrayStore, InternalBaseStore, InternalFieldStore, InternalFormStore, InternalObjectStore, InternalValueStore, IsAny, IsNever, MaybePromise, PartialValues, Path, PathKey, PathValue, RequiredPath, Schema, Signal, SubmitHandler, Untrack, ValidArrayPath, ValidPath, ValidateFormInputConfig, ValidationMode, batch, copyItemState, createFormStore, createId, createSignal, framework, getElementInput, getFieldBool, getFieldInput, getFieldStore, initializeFieldStore, resetItemState, setFieldBool, setFieldInput, setInitialFieldInput, swapItemState, untrack, validateFormInput, validateIfRequired, walkFieldStore };
585
+ export { BaseFormStore, Batch, DeepPartial, FieldElement, FieldSchema, FormConfig, INTERNAL, InternalArrayStore, InternalBaseStore, InternalFieldStore, InternalFormStore, InternalObjectStore, InternalValueStore, IsAny, IsNever, MaybePromise, PartialValues, Path, PathKey, PathValue, RequiredPath, Schema, Signal, SubmitEventHandler, SubmitHandler, Untrack, ValidArrayPath, ValidPath, ValidateFormInputConfig, ValidationMode, batch, copyItemState, createFormStore, createId, createSignal, framework, getElementInput, getFieldBool, getFieldInput, getFieldStore, initializeFieldStore, resetItemState, setFieldBool, setFieldInput, setInitialFieldInput, swapItemState, untrack, validateFormInput, validateIfRequired, walkFieldStore };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { DeepPartial, FieldElement, FormConfig, PartialValues, PathValue, RequiredPath, Schema, SubmitHandler, ValidArrayPath, ValidationMode, ValidPath, } from './core/index.svelte';
1
+ export type { DeepPartial, FieldElement, FormConfig, PartialValues, PathValue, RequiredPath, Schema, SubmitEventHandler, SubmitHandler, ValidArrayPath, ValidationMode, ValidPath, } from './core/index.svelte';
2
2
  export * from './methods/index.svelte';
3
3
  export * from './components/index';
4
4
  export * from './runes/index';
@@ -1,4 +1,4 @@
1
- import { BaseFormStore, DeepPartial, PartialValues, PathValue, RequiredPath, Schema, SubmitHandler, ValidArrayPath, ValidPath } from "../core/index.svelte";
1
+ import { BaseFormStore, DeepPartial, PartialValues, PathValue, RequiredPath, Schema, SubmitEventHandler, SubmitHandler, ValidArrayPath, ValidPath } from "../core/index.svelte";
2
2
  import * as v from "valibot";
3
3
 
4
4
  //#region src/focus/focus.d.ts
@@ -116,6 +116,17 @@ declare function getInput<TSchema extends Schema, TFieldPath extends RequiredPat
116
116
  //#endregion
117
117
  //#region src/handleSubmit/handleSubmit.d.ts
118
118
  /**
119
+ * Creates a submit event handler for the form that validates the form input,
120
+ * and calls the provided handler if validation succeeds. This is designed to
121
+ * be used with the form's onsubmit event.
122
+ *
123
+ * @param form The form store to handle submission for.
124
+ * @param handler The submit handler function called with validated output if validation succeeds.
125
+ *
126
+ * @returns A submit event handler function to attach to the form element.
127
+ */
128
+ declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitHandler<TSchema>): () => Promise<void>;
129
+ /**
119
130
  * Creates a submit event handler for the form that prevents default browser
120
131
  * submission, validates the form input, and calls the provided handler if
121
132
  * validation succeeds. This is designed to be used with the form's onsubmit event.
@@ -125,7 +136,7 @@ declare function getInput<TSchema extends Schema, TFieldPath extends RequiredPat
125
136
  *
126
137
  * @returns A submit event handler function to attach to the form element.
127
138
  */
128
- declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitHandler<TSchema>): (event: SubmitEvent) => Promise<void>;
139
+ declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitEventHandler<TSchema>): (event: SubmitEvent) => Promise<void>;
129
140
  //#endregion
130
141
  //#region src/insert/insert.d.ts
131
142
  /**
@@ -54,7 +54,7 @@ function getInput(form, config) {
54
54
  /* @__NO_SIDE_EFFECTS__ */
55
55
  function handleSubmit(form, handler) {
56
56
  return async (event) => {
57
- event.preventDefault();
57
+ event?.preventDefault();
58
58
  const internalFormStore = form[INTERNAL];
59
59
  internalFormStore.isSubmitted.value = true;
60
60
  internalFormStore.isSubmitting.value = true;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formisch/svelte",
3
3
  "description": "The modular and type-safe form library for Svelte",
4
- "version": "0.6.0",
4
+ "version": "0.7.1",
5
5
  "license": "MIT",
6
6
  "author": "Fabian Hiller",
7
7
  "homepage": "https://formisch.dev",
@@ -50,9 +50,9 @@
50
50
  "typescript": "^5.9.2",
51
51
  "valibot": "^1.2.0",
52
52
  "vite": "^7.1.5",
53
- "@formisch/core": "0.5.0",
53
+ "@formisch/core": "0.6.1",
54
54
  "@formisch/eslint-config": "0.1.0",
55
- "@formisch/methods": "0.6.0"
55
+ "@formisch/methods": "0.7.0"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "svelte": "^5.29.0",