@tanstack/svelte-form 1.33.4 → 2.0.0-alpha.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/AppForm/AppForm.svelte +14 -0
- package/dist/AppForm/Components.lib.d.ts +7 -0
- package/dist/AppForm/Components.lib.js +8 -0
- package/dist/AppForm/SvelteAppFormApi.public.d.ts +10 -0
- package/dist/AppForm/appFormOptions.public.d.ts +12 -0
- package/dist/AppForm/appFormOptions.public.js +1 -0
- package/dist/AppForm/componentMap.public.d.ts +7 -0
- package/dist/AppForm/componentMap.public.js +1 -0
- package/dist/AppForm/contexts.lib.d.ts +4 -0
- package/dist/AppForm/contexts.lib.js +16 -0
- package/dist/AppForm/createFormHook.public.d.ts +3 -0
- package/dist/AppForm/createFormHook.public.js +20 -0
- package/dist/AppForm/createFormHookTypes.public.d.ts +12 -0
- package/dist/AppForm/createFormHookTypes.public.js +1 -0
- package/dist/AppForm/fieldComponentHelpers.lib.d.ts +5 -0
- package/dist/AppForm/fieldComponentHelpers.lib.js +10 -0
- package/dist/AppForm/getFormHookHelpers.public.d.ts +31 -0
- package/dist/AppForm/getFormHookHelpers.public.js +13 -0
- package/dist/AppForm/initializeAppForm.lib.d.ts +4 -0
- package/dist/AppForm/initializeAppForm.lib.js +5 -0
- package/dist/Components.public.d.ts +52 -0
- package/dist/Components.public.js +1 -0
- package/dist/Field.svelte +125 -314
- package/dist/Field.svelte.d.ts +14 -30
- package/dist/FieldGroup/FieldGroupApi.public.d.ts +15 -0
- package/dist/FieldGroup/FieldGroupApi.public.js +1 -0
- package/dist/FieldGroup/withFields.lib.d.ts +5 -0
- package/dist/FieldGroup/withFields.lib.js +44 -0
- package/dist/FieldGroup/withFields.public.d.ts +70 -0
- package/dist/FieldGroup/withFields.public.js +3 -0
- package/dist/FormGroup.svelte +81 -302
- package/dist/FormGroup.svelte.d.ts +13 -30
- package/dist/Subscribe.svelte +18 -8
- package/dist/Subscribe.svelte.d.ts +5 -3
- package/dist/createForm.public.d.ts +5 -0
- package/dist/createForm.public.js +5 -0
- package/dist/createForm.svelte.d.ts +11 -27
- package/dist/createForm.svelte.js +29 -19
- package/dist/formApiTypes.public.d.ts +13 -0
- package/dist/formApiTypes.public.js +1 -0
- package/dist/formType.public.d.ts +7 -0
- package/dist/formType.public.js +1 -0
- package/dist/index.d.ts +13 -4
- package/dist/index.js +13 -3
- package/dist/utils.lib.d.ts +1 -0
- package/dist/utils.lib.js +28 -0
- package/package.json +5 -5
- package/src/AppForm/AppForm.svelte +14 -0
- package/src/AppForm/Components.lib.ts +28 -0
- package/src/AppForm/SvelteAppFormApi.public.ts +14 -0
- package/src/AppForm/appFormOptions.public.ts +57 -0
- package/src/AppForm/componentMap.public.ts +19 -0
- package/src/AppForm/contexts.lib.ts +24 -0
- package/src/AppForm/createFormHook.public.ts +33 -0
- package/src/AppForm/createFormHookTypes.public.ts +30 -0
- package/src/AppForm/fieldComponentHelpers.lib.ts +24 -0
- package/src/AppForm/getFormHookHelpers.public.ts +82 -0
- package/src/AppForm/initializeAppForm.lib.ts +18 -0
- package/src/Components.public.ts +371 -0
- package/src/Field.svelte +125 -314
- package/src/FieldGroup/FieldGroupApi.public.ts +100 -0
- package/src/FieldGroup/withFields.lib.ts +82 -0
- package/src/FieldGroup/withFields.public.ts +179 -0
- package/src/FormGroup.svelte +81 -302
- package/src/Subscribe.svelte +18 -8
- package/src/createForm.public.ts +26 -0
- package/src/createForm.svelte.ts +62 -336
- package/src/formApiTypes.public.ts +48 -0
- package/src/formType.public.ts +46 -0
- package/src/index.ts +13 -12
- package/src/utils.lib.ts +30 -0
- package/dist/AppField.svelte +0 -19
- package/dist/AppField.svelte.d.ts +0 -10
- package/dist/AppForm.svelte +0 -16
- package/dist/InnerAppField.svelte +0 -17
- package/dist/InnerAppField.svelte.d.ts +0 -9
- package/dist/createFormCreator.svelte.d.ts +0 -26
- package/dist/createFormCreator.svelte.js +0 -51
- package/dist/types.d.ts +0 -21
- package/src/AppField.svelte +0 -19
- package/src/AppForm.svelte +0 -16
- package/src/InnerAppField.svelte +0 -17
- package/src/createFormCreator.svelte.ts +0 -321
- package/src/types.ts +0 -567
- /package/dist/{AppForm.svelte.d.ts → AppForm/AppForm.svelte.d.ts} +0 -0
- /package/dist/{types.js → AppForm/SvelteAppFormApi.public.js} +0 -0
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { getContext } from 'svelte';
|
|
2
|
-
import { createForm } from './createForm.svelte';
|
|
3
|
-
import AppFormSvelte from './AppForm.svelte';
|
|
4
|
-
import AppFieldSvelte from './AppField.svelte';
|
|
5
|
-
import { fieldContextKey, formContextKey } from './context-keys.js';
|
|
6
|
-
export function createFormCreatorContexts() {
|
|
7
|
-
function useFieldContext() {
|
|
8
|
-
const field = getContext(fieldContextKey);
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
10
|
-
if (!field) {
|
|
11
|
-
throw new Error('`fieldContext` only works when within a `fieldComponent` passed to `createFormCreator`');
|
|
12
|
-
}
|
|
13
|
-
return field;
|
|
14
|
-
}
|
|
15
|
-
function useFormContext() {
|
|
16
|
-
const form = getContext(formContextKey);
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
18
|
-
if (!form) {
|
|
19
|
-
throw new Error('`formContext` only works when within a `formComponent` passed to `createFormCreator`');
|
|
20
|
-
}
|
|
21
|
-
return form;
|
|
22
|
-
}
|
|
23
|
-
return { useFieldContext, useFormContext };
|
|
24
|
-
}
|
|
25
|
-
export function createFormCreator({ fieldComponents, formComponents, }) {
|
|
26
|
-
function createAppForm(props) {
|
|
27
|
-
const form = createForm(props);
|
|
28
|
-
const AppForm = ((internal, props) => {
|
|
29
|
-
return AppFormSvelte(internal, { ...props, form });
|
|
30
|
-
});
|
|
31
|
-
const AppField = ((internal, { children, ...fieldProps }) => AppFieldSvelte(internal, {
|
|
32
|
-
fieldProps,
|
|
33
|
-
form,
|
|
34
|
-
fieldComponents,
|
|
35
|
-
children,
|
|
36
|
-
}));
|
|
37
|
-
const extendedForm = Object.assign(form, {
|
|
38
|
-
AppField,
|
|
39
|
-
AppForm,
|
|
40
|
-
...formComponents,
|
|
41
|
-
});
|
|
42
|
-
return extendedForm;
|
|
43
|
-
}
|
|
44
|
-
function getFormType(_formProps) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
createAppForm,
|
|
49
|
-
getFormType,
|
|
50
|
-
};
|
|
51
|
-
}
|
package/dist/types.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { DeepKeys, DeepValue, FieldApi, FieldApiOptions, FieldAsyncValidateOrFn, FieldValidateOrFn, FormAsyncValidateOrFn, FormGroupApi, FormGroupApiOptions, FormGroupAsyncValidateOrFn, FormGroupValidateOrFn, FormValidateOrFn } from '@tanstack/form-core';
|
|
2
|
-
import type { Component, ComponentConstructorOptions, Snippet, SvelteComponent } from 'svelte';
|
|
3
|
-
export type CreateFieldOptions<TParentData, TName extends DeepKeys<TParentData>, TData extends DeepValue<TParentData, TName>, TOnMount extends undefined | FieldValidateOrFn<TParentData, TName, TData>, TOnChange extends undefined | FieldValidateOrFn<TParentData, TName, TData>, TOnChangeAsync extends undefined | FieldAsyncValidateOrFn<TParentData, TName, TData>, TOnBlur extends undefined | FieldValidateOrFn<TParentData, TName, TData>, TOnBlurAsync extends undefined | FieldAsyncValidateOrFn<TParentData, TName, TData>, TOnSubmit extends undefined | FieldValidateOrFn<TParentData, TName, TData>, TOnSubmitAsync extends undefined | FieldAsyncValidateOrFn<TParentData, TName, TData>, TOnDynamic extends undefined | FieldValidateOrFn<TParentData, TName, TData>, TOnDynamicAsync extends undefined | FieldAsyncValidateOrFn<TParentData, TName, TData>, TFormOnMount extends undefined | FormValidateOrFn<TParentData>, TFormOnChange extends undefined | FormValidateOrFn<TParentData>, TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnBlur extends undefined | FormValidateOrFn<TParentData>, TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>, TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>, TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>, TSubmitMeta> = FieldApiOptions<TParentData, TName, TData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnDynamic, TFormOnDynamicAsync, TFormOnServer, TSubmitMeta> & {
|
|
4
|
-
mode?: 'value' | 'array';
|
|
5
|
-
};
|
|
6
|
-
export type WithoutFunction<T> = {
|
|
7
|
-
[K in keyof T as T[K] extends Function ? never : K]: T[K];
|
|
8
|
-
};
|
|
9
|
-
export type FieldComponent<TParentData, TFormOnMount extends undefined | FormValidateOrFn<TParentData>, TFormOnChange extends undefined | FormValidateOrFn<TParentData>, TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnBlur extends undefined | FormValidateOrFn<TParentData>, TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>, TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>, TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>, TParentSubmitMeta, ExtendedApi = {}> = (<TName extends DeepKeys<TParentData>, TData extends DeepValue<TParentData, TName>, TOnMount extends undefined | FieldValidateOrFn<TParentData, TName, TData>, TOnChange extends undefined | FieldValidateOrFn<TParentData, TName, TData>, TOnChangeAsync extends undefined | FieldAsyncValidateOrFn<TParentData, TName, TData>, TOnBlur extends undefined | FieldValidateOrFn<TParentData, TName, TData>, TOnBlurAsync extends undefined | FieldAsyncValidateOrFn<TParentData, TName, TData>, TOnSubmit extends undefined | FieldValidateOrFn<TParentData, TName, TData>, TOnSubmitAsync extends undefined | FieldAsyncValidateOrFn<TParentData, TName, TData>, TOnDynamic extends undefined | FieldValidateOrFn<TParentData, TName, TData>, TOnDynamicAsync extends undefined | FieldAsyncValidateOrFn<TParentData, TName, TData>>(internal: any, { children, ...fieldOptions }: Omit<FieldComponentProps<TParentData, TName, TData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnDynamic, TFormOnDynamicAsync, TFormOnServer, TParentSubmitMeta, ExtendedApi>, 'form'>) => {}) & (new <TName extends DeepKeys<TParentData>, TData extends DeepValue<TParentData, TName>, TOnMount extends undefined | FieldValidateOrFn<TParentData, TName, TData>, TOnChange extends undefined | FieldValidateOrFn<TParentData, TName, TData>, TOnChangeAsync extends undefined | FieldAsyncValidateOrFn<TParentData, TName, TData>, TOnBlur extends undefined | FieldValidateOrFn<TParentData, TName, TData>, TOnBlurAsync extends undefined | FieldAsyncValidateOrFn<TParentData, TName, TData>, TOnSubmit extends undefined | FieldValidateOrFn<TParentData, TName, TData>, TOnSubmitAsync extends undefined | FieldAsyncValidateOrFn<TParentData, TName, TData>, TOnDynamic extends undefined | FieldValidateOrFn<TParentData, TName, TData>, TOnDynamicAsync extends undefined | FieldAsyncValidateOrFn<TParentData, TName, TData>>(opts: ComponentConstructorOptions<Omit<FieldComponentProps<TParentData, TName, TData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnDynamic, TFormOnDynamicAsync, TFormOnServer, TParentSubmitMeta, ExtendedApi>, 'form'>>) => SvelteComponent) & WithoutFunction<Component>;
|
|
10
|
-
type FieldComponentProps<TParentData, TName extends DeepKeys<TParentData>, TData extends DeepValue<TParentData, TName>, TOnMount extends undefined | FieldValidateOrFn<TParentData, TName, TData>, TOnChange extends undefined | FieldValidateOrFn<TParentData, TName, TData>, TOnChangeAsync extends undefined | FieldAsyncValidateOrFn<TParentData, TName, TData>, TOnBlur extends undefined | FieldValidateOrFn<TParentData, TName, TData>, TOnBlurAsync extends undefined | FieldAsyncValidateOrFn<TParentData, TName, TData>, TOnSubmit extends undefined | FieldValidateOrFn<TParentData, TName, TData>, TOnSubmitAsync extends undefined | FieldAsyncValidateOrFn<TParentData, TName, TData>, TOnDynamic extends undefined | FieldValidateOrFn<TParentData, TName, TData>, TOnDynamicAsync extends undefined | FieldAsyncValidateOrFn<TParentData, TName, TData>, TFormOnMount extends undefined | FormValidateOrFn<TParentData>, TFormOnChange extends undefined | FormValidateOrFn<TParentData>, TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnBlur extends undefined | FormValidateOrFn<TParentData>, TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>, TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>, TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>, TParentSubmitMeta, ExtendedApi = {}> = {
|
|
11
|
-
children: Snippet<[
|
|
12
|
-
FieldApi<TParentData, TName, TData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnDynamic, TFormOnDynamicAsync, TFormOnServer, TParentSubmitMeta> & ExtendedApi
|
|
13
|
-
]>;
|
|
14
|
-
} & Omit<CreateFieldOptions<TParentData, TName, TData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnDynamic, TFormOnDynamicAsync, TFormOnServer, TParentSubmitMeta>, 'form'>;
|
|
15
|
-
export type FormGroupComponent<TParentData, TFormOnMount extends undefined | FormValidateOrFn<TParentData>, TFormOnChange extends undefined | FormValidateOrFn<TParentData>, TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnBlur extends undefined | FormValidateOrFn<TParentData>, TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>, TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>, TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>, TParentSubmitMeta, ExtendedApi = {}> = (<TName extends DeepKeys<TParentData>, TData extends DeepValue<TParentData, TName>, TOnMount extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>, TOnChange extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>, TOnChangeAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>, TOnBlur extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>, TOnBlurAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>, TOnSubmit extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>, TOnSubmitAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>, TOnDynamic extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>, TOnDynamicAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>, TSubmitMeta>(internal: any, { children, ...formGroupOptions }: Omit<FormGroupComponentProps<TParentData, TName, TData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TSubmitMeta, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnDynamic, TFormOnDynamicAsync, TFormOnServer, TParentSubmitMeta, ExtendedApi>, 'form'>) => {}) & (new <TName extends DeepKeys<TParentData>, TData extends DeepValue<TParentData, TName>, TOnMount extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>, TOnChange extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>, TOnChangeAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>, TOnBlur extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>, TOnBlurAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>, TOnSubmit extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>, TOnSubmitAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>, TOnDynamic extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>, TOnDynamicAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>, TSubmitMeta>(opts: ComponentConstructorOptions<Omit<FormGroupComponentProps<TParentData, TName, TData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TSubmitMeta, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnDynamic, TFormOnDynamicAsync, TFormOnServer, TParentSubmitMeta, ExtendedApi>, 'form'>>) => SvelteComponent) & WithoutFunction<Component>;
|
|
16
|
-
type FormGroupComponentProps<TParentData, TName extends DeepKeys<TParentData>, TData extends DeepValue<TParentData, TName>, TOnMount extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>, TOnChange extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>, TOnChangeAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>, TOnBlur extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>, TOnBlurAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>, TOnSubmit extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>, TOnSubmitAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>, TOnDynamic extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>, TOnDynamicAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>, TSubmitMeta, TFormOnMount extends undefined | FormValidateOrFn<TParentData>, TFormOnChange extends undefined | FormValidateOrFn<TParentData>, TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnBlur extends undefined | FormValidateOrFn<TParentData>, TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>, TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>, TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>, TParentSubmitMeta, ExtendedApi = {}> = {
|
|
17
|
-
children: Snippet<[
|
|
18
|
-
FormGroupApi<TParentData, TName, TData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TSubmitMeta, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnDynamic, TFormOnDynamicAsync, TFormOnServer, TParentSubmitMeta> & ExtendedApi
|
|
19
|
-
]>;
|
|
20
|
-
} & FormGroupApiOptions<TParentData, TName, TData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TSubmitMeta, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnDynamic, TFormOnDynamicAsync, TFormOnServer, TParentSubmitMeta>;
|
|
21
|
-
export {};
|
package/src/AppField.svelte
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
<!-- Take "form" as an prop, pass it to context, and render children -->
|
|
2
|
-
<script lang="ts">
|
|
3
|
-
import type { Snippet } from 'svelte'
|
|
4
|
-
import InnerAppField from './InnerAppField.svelte'
|
|
5
|
-
|
|
6
|
-
interface Props {
|
|
7
|
-
form: any
|
|
8
|
-
fieldComponents: any
|
|
9
|
-
children: Snippet
|
|
10
|
-
fieldProps: any
|
|
11
|
-
}
|
|
12
|
-
const { children: childrenProp, form, fieldComponents, fieldProps }: Props = $props()
|
|
13
|
-
</script>
|
|
14
|
-
|
|
15
|
-
<form.Field {...fieldProps}>
|
|
16
|
-
{#snippet children(field: any)}
|
|
17
|
-
<InnerAppField field={field} children={childrenProp} fieldComponents={fieldComponents}/>
|
|
18
|
-
{/snippet}
|
|
19
|
-
</form.Field>
|
package/src/AppForm.svelte
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
<!-- Take "form" as an prop, pass it to context, and render children -->
|
|
2
|
-
<script lang="ts">
|
|
3
|
-
import { setContext, type Snippet } from 'svelte'
|
|
4
|
-
import { formContextKey } from './context-keys.js'
|
|
5
|
-
|
|
6
|
-
interface Props {
|
|
7
|
-
form: any
|
|
8
|
-
children: Snippet
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const { children, form }: Props = $props()
|
|
12
|
-
|
|
13
|
-
setContext(formContextKey, form)
|
|
14
|
-
</script>
|
|
15
|
-
|
|
16
|
-
{@render children?.()}
|
package/src/InnerAppField.svelte
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<!-- Take "form" as an prop, pass it to context, and render children -->
|
|
2
|
-
<script lang="ts">
|
|
3
|
-
import { setContext, type Snippet } from 'svelte'
|
|
4
|
-
import { fieldContextKey } from './context-keys.js'
|
|
5
|
-
|
|
6
|
-
interface Props {
|
|
7
|
-
field: any
|
|
8
|
-
fieldComponents: any
|
|
9
|
-
children: Snippet<[any]>
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const { children, field, fieldComponents }: Props = $props()
|
|
13
|
-
|
|
14
|
-
setContext(fieldContextKey, field)
|
|
15
|
-
</script>
|
|
16
|
-
|
|
17
|
-
{@render children?.(Object.assign(field, fieldComponents))}
|
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
import { getContext } from 'svelte'
|
|
2
|
-
import { createForm } from './createForm.svelte'
|
|
3
|
-
import AppFormSvelte from './AppForm.svelte'
|
|
4
|
-
import AppFieldSvelte from './AppField.svelte'
|
|
5
|
-
import { fieldContextKey, formContextKey } from './context-keys.js'
|
|
6
|
-
import type {
|
|
7
|
-
AnyFieldApi,
|
|
8
|
-
AnyFormApi,
|
|
9
|
-
FieldApi,
|
|
10
|
-
FormAsyncValidateOrFn,
|
|
11
|
-
FormOptions,
|
|
12
|
-
FormValidateOrFn,
|
|
13
|
-
} from '@tanstack/form-core'
|
|
14
|
-
import type { FieldComponent } from './types.js'
|
|
15
|
-
import type { SvelteFormExtendedApi } from './createForm.svelte'
|
|
16
|
-
import type { Component, Snippet } from 'svelte'
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* TypeScript inferencing is weird.
|
|
20
|
-
*
|
|
21
|
-
* If you have:
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
*
|
|
25
|
-
* interface Args<T> {
|
|
26
|
-
* arg?: T
|
|
27
|
-
* }
|
|
28
|
-
*
|
|
29
|
-
* function test<T>(arg?: Partial<Args<T>>): T {
|
|
30
|
-
* return 0 as any;
|
|
31
|
-
* }
|
|
32
|
-
*
|
|
33
|
-
* const a = test({});
|
|
34
|
-
*
|
|
35
|
-
* Then `T` will default to `unknown`.
|
|
36
|
-
*
|
|
37
|
-
* However, if we change `test` to be:
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
*
|
|
41
|
-
* function test<T extends undefined>(arg?: Partial<Args<T>>): T;
|
|
42
|
-
*
|
|
43
|
-
* Then `T` becomes `undefined`.
|
|
44
|
-
*
|
|
45
|
-
* Here, we are checking if the passed type `T` extends `DefaultT` and **only**
|
|
46
|
-
* `DefaultT`, as if that's the case we assume that inferencing has not occured.
|
|
47
|
-
*/
|
|
48
|
-
type UnwrapOrAny<T> = [unknown] extends [T] ? any : T
|
|
49
|
-
type UnwrapDefaultOrAny<DefaultT, T> = [DefaultT] extends [T]
|
|
50
|
-
? [T] extends [DefaultT]
|
|
51
|
-
? any
|
|
52
|
-
: T
|
|
53
|
-
: T
|
|
54
|
-
|
|
55
|
-
export function createFormCreatorContexts() {
|
|
56
|
-
function useFieldContext<TData>() {
|
|
57
|
-
const field = getContext(fieldContextKey) as AnyFieldApi
|
|
58
|
-
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
60
|
-
if (!field) {
|
|
61
|
-
throw new Error(
|
|
62
|
-
'`fieldContext` only works when within a `fieldComponent` passed to `createFormCreator`',
|
|
63
|
-
)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return field as FieldApi<
|
|
67
|
-
any,
|
|
68
|
-
string,
|
|
69
|
-
TData,
|
|
70
|
-
any,
|
|
71
|
-
any,
|
|
72
|
-
any,
|
|
73
|
-
any,
|
|
74
|
-
any,
|
|
75
|
-
any,
|
|
76
|
-
any,
|
|
77
|
-
any,
|
|
78
|
-
any,
|
|
79
|
-
any,
|
|
80
|
-
any,
|
|
81
|
-
any,
|
|
82
|
-
any,
|
|
83
|
-
any,
|
|
84
|
-
any,
|
|
85
|
-
any,
|
|
86
|
-
any,
|
|
87
|
-
any,
|
|
88
|
-
any,
|
|
89
|
-
any
|
|
90
|
-
>
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function useFormContext() {
|
|
94
|
-
const form = getContext(formContextKey) as AnyFormApi
|
|
95
|
-
|
|
96
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
97
|
-
if (!form) {
|
|
98
|
-
throw new Error(
|
|
99
|
-
'`formContext` only works when within a `formComponent` passed to `createFormCreator`',
|
|
100
|
-
)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return form as SvelteFormExtendedApi<
|
|
104
|
-
// If you need access to the form data, you need to use `withForm` instead
|
|
105
|
-
Record<string, never>,
|
|
106
|
-
any,
|
|
107
|
-
any,
|
|
108
|
-
any,
|
|
109
|
-
any,
|
|
110
|
-
any,
|
|
111
|
-
any,
|
|
112
|
-
any,
|
|
113
|
-
any,
|
|
114
|
-
any,
|
|
115
|
-
any,
|
|
116
|
-
any
|
|
117
|
-
>
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return { useFieldContext, useFormContext }
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
interface CreateFormRuneProps<
|
|
124
|
-
TFieldComponents extends Record<string, Component<any, any>>,
|
|
125
|
-
TFormComponents extends Record<string, Component<any, any>>,
|
|
126
|
-
> {
|
|
127
|
-
fieldComponents: TFieldComponents
|
|
128
|
-
formComponents: TFormComponents
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* @private
|
|
133
|
-
*/
|
|
134
|
-
type AppFieldExtendedSvelteFormApi<
|
|
135
|
-
TFormData,
|
|
136
|
-
TOnMount extends undefined | FormValidateOrFn<TFormData>,
|
|
137
|
-
TOnChange extends undefined | FormValidateOrFn<TFormData>,
|
|
138
|
-
TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
139
|
-
TOnBlur extends undefined | FormValidateOrFn<TFormData>,
|
|
140
|
-
TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
141
|
-
TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
|
|
142
|
-
TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
143
|
-
TOnDynamic extends undefined | FormValidateOrFn<TFormData>,
|
|
144
|
-
TOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
145
|
-
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
146
|
-
TSubmitMeta,
|
|
147
|
-
TFieldComponents extends Record<string, Component<any, any>>,
|
|
148
|
-
TFormComponents extends Record<string, Component<any, any>>,
|
|
149
|
-
> = SvelteFormExtendedApi<
|
|
150
|
-
TFormData,
|
|
151
|
-
TOnMount,
|
|
152
|
-
TOnChange,
|
|
153
|
-
TOnChangeAsync,
|
|
154
|
-
TOnBlur,
|
|
155
|
-
TOnBlurAsync,
|
|
156
|
-
TOnSubmit,
|
|
157
|
-
TOnSubmitAsync,
|
|
158
|
-
TOnDynamic,
|
|
159
|
-
TOnDynamicAsync,
|
|
160
|
-
TOnServer,
|
|
161
|
-
TSubmitMeta
|
|
162
|
-
> &
|
|
163
|
-
NoInfer<TFormComponents> & {
|
|
164
|
-
AppField: FieldComponent<
|
|
165
|
-
TFormData,
|
|
166
|
-
TOnMount,
|
|
167
|
-
TOnChange,
|
|
168
|
-
TOnChangeAsync,
|
|
169
|
-
TOnBlur,
|
|
170
|
-
TOnBlurAsync,
|
|
171
|
-
TOnSubmit,
|
|
172
|
-
TOnSubmitAsync,
|
|
173
|
-
TOnDynamic,
|
|
174
|
-
TOnDynamicAsync,
|
|
175
|
-
TOnServer,
|
|
176
|
-
TSubmitMeta,
|
|
177
|
-
NoInfer<TFieldComponents>
|
|
178
|
-
>
|
|
179
|
-
AppForm: Component<{ children: Snippet }>
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export function createFormCreator<
|
|
183
|
-
const TComponents extends Record<string, Component<any, any>>,
|
|
184
|
-
const TFormComponents extends Record<string, Component<any, any>>,
|
|
185
|
-
>({
|
|
186
|
-
fieldComponents,
|
|
187
|
-
formComponents,
|
|
188
|
-
}: CreateFormRuneProps<TComponents, TFormComponents>) {
|
|
189
|
-
function createAppForm<
|
|
190
|
-
TFormData,
|
|
191
|
-
TOnMount extends undefined | FormValidateOrFn<TFormData>,
|
|
192
|
-
TOnChange extends undefined | FormValidateOrFn<TFormData>,
|
|
193
|
-
TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
194
|
-
TOnBlur extends undefined | FormValidateOrFn<TFormData>,
|
|
195
|
-
TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
196
|
-
TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
|
|
197
|
-
TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
198
|
-
TOnDynamic extends undefined | FormValidateOrFn<TFormData>,
|
|
199
|
-
TOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
200
|
-
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
201
|
-
TSubmitMeta,
|
|
202
|
-
>(
|
|
203
|
-
props: () => FormOptions<
|
|
204
|
-
TFormData,
|
|
205
|
-
TOnMount,
|
|
206
|
-
TOnChange,
|
|
207
|
-
TOnChangeAsync,
|
|
208
|
-
TOnBlur,
|
|
209
|
-
TOnBlurAsync,
|
|
210
|
-
TOnSubmit,
|
|
211
|
-
TOnSubmitAsync,
|
|
212
|
-
TOnDynamic,
|
|
213
|
-
TOnDynamicAsync,
|
|
214
|
-
TOnServer,
|
|
215
|
-
TSubmitMeta
|
|
216
|
-
>,
|
|
217
|
-
): AppFieldExtendedSvelteFormApi<
|
|
218
|
-
TFormData,
|
|
219
|
-
TOnMount,
|
|
220
|
-
TOnChange,
|
|
221
|
-
TOnChangeAsync,
|
|
222
|
-
TOnBlur,
|
|
223
|
-
TOnBlurAsync,
|
|
224
|
-
TOnSubmit,
|
|
225
|
-
TOnSubmitAsync,
|
|
226
|
-
TOnDynamic,
|
|
227
|
-
TOnDynamicAsync,
|
|
228
|
-
TOnServer,
|
|
229
|
-
TSubmitMeta,
|
|
230
|
-
TComponents,
|
|
231
|
-
TFormComponents
|
|
232
|
-
> {
|
|
233
|
-
const form = createForm(props)
|
|
234
|
-
|
|
235
|
-
const AppForm = ((internal, props) => {
|
|
236
|
-
return AppFormSvelte(internal, { ...props, form })
|
|
237
|
-
}) as Component<{ children: Snippet }>
|
|
238
|
-
|
|
239
|
-
const AppField = ((internal, { children, ...fieldProps }) =>
|
|
240
|
-
AppFieldSvelte(internal, {
|
|
241
|
-
fieldProps,
|
|
242
|
-
form,
|
|
243
|
-
fieldComponents,
|
|
244
|
-
children,
|
|
245
|
-
} as never)) as FieldComponent<
|
|
246
|
-
TFormData,
|
|
247
|
-
TOnMount,
|
|
248
|
-
TOnChange,
|
|
249
|
-
TOnChangeAsync,
|
|
250
|
-
TOnBlur,
|
|
251
|
-
TOnBlurAsync,
|
|
252
|
-
TOnSubmit,
|
|
253
|
-
TOnSubmitAsync,
|
|
254
|
-
TOnDynamic,
|
|
255
|
-
TOnDynamicAsync,
|
|
256
|
-
TOnServer,
|
|
257
|
-
TSubmitMeta,
|
|
258
|
-
TComponents
|
|
259
|
-
>
|
|
260
|
-
|
|
261
|
-
const extendedForm = Object.assign(form, {
|
|
262
|
-
AppField,
|
|
263
|
-
AppForm,
|
|
264
|
-
...formComponents,
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
return extendedForm
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function getFormType<
|
|
271
|
-
TFormData,
|
|
272
|
-
TOnMount extends undefined | FormValidateOrFn<TFormData>,
|
|
273
|
-
TOnChange extends undefined | FormValidateOrFn<TFormData>,
|
|
274
|
-
TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
275
|
-
TOnBlur extends undefined | FormValidateOrFn<TFormData>,
|
|
276
|
-
TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
277
|
-
TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
|
|
278
|
-
TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
279
|
-
TOnDynamic extends undefined | FormValidateOrFn<TFormData>,
|
|
280
|
-
TOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
281
|
-
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
282
|
-
TSubmitMeta,
|
|
283
|
-
>(
|
|
284
|
-
_formProps: FormOptions<
|
|
285
|
-
TFormData,
|
|
286
|
-
TOnMount,
|
|
287
|
-
TOnChange,
|
|
288
|
-
TOnChangeAsync,
|
|
289
|
-
TOnBlur,
|
|
290
|
-
TOnBlurAsync,
|
|
291
|
-
TOnSubmit,
|
|
292
|
-
TOnSubmitAsync,
|
|
293
|
-
TOnDynamic,
|
|
294
|
-
TOnDynamicAsync,
|
|
295
|
-
TOnServer,
|
|
296
|
-
TSubmitMeta
|
|
297
|
-
>,
|
|
298
|
-
): AppFieldExtendedSvelteFormApi<
|
|
299
|
-
TFormData,
|
|
300
|
-
TOnMount,
|
|
301
|
-
TOnChange,
|
|
302
|
-
TOnChangeAsync,
|
|
303
|
-
TOnBlur,
|
|
304
|
-
TOnBlurAsync,
|
|
305
|
-
TOnSubmit,
|
|
306
|
-
TOnSubmitAsync,
|
|
307
|
-
TOnDynamic,
|
|
308
|
-
TOnDynamicAsync,
|
|
309
|
-
TOnServer,
|
|
310
|
-
TSubmitMeta,
|
|
311
|
-
TComponents,
|
|
312
|
-
TFormComponents
|
|
313
|
-
> {
|
|
314
|
-
return undefined as never
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
return {
|
|
318
|
-
createAppForm,
|
|
319
|
-
getFormType,
|
|
320
|
-
}
|
|
321
|
-
}
|