@tanstack/form-core 1.24.3 → 1.24.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.
@@ -1 +1 @@
1
- {"version":3,"file":"EventClient.js","sources":["../../src/EventClient.ts"],"sourcesContent":["import { EventClient } from '@tanstack/devtools-event-client'\n\nimport type { AnyFormOptions, AnyFormState } from './FormApi'\n\ntype ExtractEventNames<T> = T extends `${string}:${infer EventName}`\n ? EventName\n : never\n\nexport type BroadcastFormState = {\n id: string\n state: AnyFormState\n options: AnyFormOptions\n}\n\nexport type BroadcastFormSubmissionState =\n | {\n id: string\n submissionAttempt: number\n successful: false\n stage: 'validateAllFields' | 'validate'\n errors: any[]\n }\n | {\n id: string\n submissionAttempt: number\n successful: false\n stage: 'inflight'\n onError: unknown\n }\n | {\n id: string\n submissionAttempt: number\n successful: true\n }\n\nexport type BroadcastFormUnmounted = {\n id: string\n}\n\nexport type RequestFormState = {\n id: string\n}\n\nexport type RequestFormReset = {\n id: string\n}\n\nexport type RequestFormForceReset = {\n id: string\n}\n\ntype EventMap = {\n 'form-devtools:form-state-change': BroadcastFormState\n 'form-devtools:form-submission-state-change': BroadcastFormSubmissionState\n 'form-devtools:form-unmounted': BroadcastFormUnmounted\n 'form-devtools:request-form-state': RequestFormState\n 'form-devtools:request-form-reset': RequestFormReset\n 'form-devtools:request-form-force-submit': RequestFormForceReset\n}\n\nexport type EventClientEventMap = keyof EventMap\n\nexport type EventClientEventNames = ExtractEventNames<EventClientEventMap>\n\nclass FormEventClient extends EventClient<EventMap> {\n constructor() {\n super({\n pluginId: 'form-devtools',\n })\n }\n}\n\nexport const formEventClient = new FormEventClient()\n"],"names":[],"mappings":";AAgEA,MAAM,wBAAwB,YAAsB;AAAA,EAClD,cAAc;AACZ,UAAM;AAAA,MACJ,UAAU;AAAA,IAAA,CACX;AAAA,EACH;AACF;AAEO,MAAM,kBAAkB,IAAI,gBAAA;"}
1
+ {"version":3,"file":"EventClient.js","sources":["../../src/EventClient.ts"],"sourcesContent":["import { EventClient } from '@tanstack/devtools-event-client'\n\nimport type { AnyFormOptions, AnyFormState } from './FormApi'\n\ntype ExtractEventNames<T> = T extends `${string}:${infer EventName}`\n ? EventName\n : never\n\nexport type BroadcastFormState = {\n id: string\n state: AnyFormState\n}\n\nexport type BroadcastFormApi = {\n id: string\n state: AnyFormState\n options: AnyFormOptions\n}\n\nexport type BroadcastFormSubmissionState =\n | {\n id: string\n submissionAttempt: number\n successful: false\n stage: 'validateAllFields' | 'validate'\n errors: any[]\n }\n | {\n id: string\n submissionAttempt: number\n successful: false\n stage: 'inflight'\n onError: unknown\n }\n | {\n id: string\n submissionAttempt: number\n successful: true\n }\n\nexport type BroadcastFormId = {\n id: string\n}\n\ntype EventMap = {\n 'form-devtools:form-state': BroadcastFormState\n 'form-devtools:form-api': BroadcastFormApi\n 'form-devtools:form-submission': BroadcastFormSubmissionState\n\n 'form-devtools:request-form-state': BroadcastFormId\n 'form-devtools:request-form-reset': BroadcastFormId\n 'form-devtools:request-form-force-submit': BroadcastFormId\n\n 'form-devtools:form-unmounted': BroadcastFormId\n}\n\nexport type EventClientEventMap = keyof EventMap\n\nexport type EventClientEventNames = ExtractEventNames<EventClientEventMap>\n\nclass FormEventClient extends EventClient<EventMap> {\n constructor() {\n super({\n pluginId: 'form-devtools',\n debug: true,\n reconnectEveryMs: 4000,\n })\n }\n}\n\nexport const formEventClient = new FormEventClient()\n"],"names":[],"mappings":";AA4DA,MAAM,wBAAwB,YAAsB;AAAA,EAClD,cAAc;AACZ,UAAM;AAAA,MACJ,UAAU;AAAA,MACV,OAAO;AAAA,MACP,kBAAkB;AAAA,IAAA,CACnB;AAAA,EACH;AACF;AAEO,MAAM,kBAAkB,IAAI,gBAAA;"}
@@ -206,7 +206,7 @@ export type BaseFormState<in out TFormData, in out TOnMount extends undefined |
206
206
  /**
207
207
  * A record of field metadata for each field in the form, not including the derived properties, like `errors` and such
208
208
  */
209
- fieldMetaBase: Record<DeepKeys<TFormData>, AnyFieldMetaBase>;
209
+ fieldMetaBase: Partial<Record<DeepKeys<TFormData>, AnyFieldMetaBase>>;
210
210
  /**
211
211
  * A boolean indicating if the form is currently in the process of being submitted after `handleSubmit` is called.
212
212
  *
@@ -297,7 +297,7 @@ export type DerivedFormState<in out TFormData, in out TOnMount extends undefined
297
297
  /**
298
298
  * A record of field metadata for each field in the form.
299
299
  */
300
- fieldMeta: Record<DeepKeys<TFormData>, AnyFieldMeta>;
300
+ fieldMeta: Partial<Record<DeepKeys<TFormData>, AnyFieldMeta>>;
301
301
  };
302
302
  export interface FormState<in out TFormData, in out TOnMount extends undefined | FormValidateOrFn<TFormData>, in out TOnChange extends undefined | FormValidateOrFn<TFormData>, in out TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>, in out TOnBlur extends undefined | FormValidateOrFn<TFormData>, in out TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>, in out TOnSubmit extends undefined | FormValidateOrFn<TFormData>, in out TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>, in out TOnDynamic extends undefined | FormValidateOrFn<TFormData>, in out TOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TFormData>, in out TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>> extends BaseFormState<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TOnServer>, DerivedFormState<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TOnServer> {
303
303
  }
@@ -321,7 +321,7 @@ export declare class FormApi<in out TFormData, in out TOnMount extends undefined
321
321
  */
322
322
  options: FormOptions<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TOnServer, TSubmitMeta>;
323
323
  baseStore: Store<BaseFormState<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TOnServer>>;
324
- fieldMetaDerived: Derived<Record<DeepKeys<TFormData>, AnyFieldMeta>>;
324
+ fieldMetaDerived: Derived<FormState<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TOnServer>['fieldMeta']>;
325
325
  store: Derived<FormState<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TOnServer>>;
326
326
  /**
327
327
  * A record of field information for each field in the form.
@@ -430,7 +430,7 @@ export declare class FormApi<in out TFormData, in out TOnMount extends undefined
430
430
  /**
431
431
  * resets every field's meta
432
432
  */
433
- resetFieldMeta: <TField extends DeepKeys<TFormData>>(fieldMeta: Record<TField, AnyFieldMeta>) => Record<TField, AnyFieldMeta>;
433
+ resetFieldMeta: <TField extends DeepKeys<TFormData>>(fieldMeta: Partial<Record<TField, AnyFieldMeta>>) => Partial<Record<TField, AnyFieldMeta>>;
434
434
  /**
435
435
  * Sets the value of the specified field and optionally updates the touched state.
436
436
  */
@@ -1,4 +1,5 @@
1
1
  import { batch, Store, Derived } from "@tanstack/store";
2
+ import { throttle } from "@tanstack/pacer";
2
3
  import { evaluate, getSyncValidatorArray, determineFormLevelErrorSourceAndValue, getAsyncValidatorArray, getBy, functionalUpdate, setBy, deleteBy, mergeOpts, uuid, isNonEmptyArray, isGlobalFormValidationError } from "./utils.js";
3
4
  import { defaultValidationLogic } from "./ValidationLogic.js";
4
5
  import { standardSchemaValidators, isStandardSchemaValidator } from "./standardSchemaValidator.js";
@@ -44,7 +45,7 @@ class FormApi {
44
45
  };
45
46
  this.options.listeners?.onMount?.({ formApi: this });
46
47
  const { onMount } = this.options.validators || {};
47
- formEventClient.emit("form-state-change", {
48
+ formEventClient.emit("form-api", {
48
49
  id: this._formId,
49
50
  state: this.store.state,
50
51
  options: this.options
@@ -78,6 +79,11 @@ class FormApi {
78
79
  )
79
80
  );
80
81
  });
82
+ formEventClient.emit("form-api", {
83
+ id: this._formId,
84
+ state: this.store.state,
85
+ options: this.options
86
+ });
81
87
  };
82
88
  this.reset = (values, opts2) => {
83
89
  const { fieldMeta: currentFieldMeta } = this.state;
@@ -807,16 +813,21 @@ class FormApi {
807
813
  });
808
814
  this.handleSubmit = this.handleSubmit.bind(this);
809
815
  this.update(opts || {});
810
- this.store.subscribe(() => {
811
- formEventClient.emit("form-state-change", {
816
+ const debouncedDevtoolState = throttle(
817
+ (state) => formEventClient.emit("form-state", {
812
818
  id: this._formId,
813
- state: this.store.state,
814
- options: this.options
815
- });
819
+ state
820
+ }),
821
+ {
822
+ wait: 300
823
+ }
824
+ );
825
+ this.store.subscribe(() => {
826
+ debouncedDevtoolState(this.store.state);
816
827
  });
817
828
  formEventClient.on("request-form-state", (e) => {
818
829
  if (e.payload.id === this._formId) {
819
- formEventClient.emit("form-state-change", {
830
+ formEventClient.emit("form-api", {
820
831
  id: this._formId,
821
832
  state: this.store.state,
822
833
  options: this.options
@@ -895,7 +906,7 @@ class FormApi {
895
906
  formApi: this,
896
907
  meta: submitMetaArg
897
908
  });
898
- formEventClient.emit("form-submission-state-change", {
909
+ formEventClient.emit("form-submission", {
899
910
  id: this._formId,
900
911
  submissionAttempt: this.state.submissionAttempts,
901
912
  successful: false,
@@ -912,7 +923,7 @@ class FormApi {
912
923
  formApi: this,
913
924
  meta: submitMetaArg
914
925
  });
915
- formEventClient.emit("form-submission-state-change", {
926
+ formEventClient.emit("form-submission", {
916
927
  id: this._formId,
917
928
  submissionAttempt: this.state.submissionAttempts,
918
929
  successful: false,
@@ -945,7 +956,7 @@ class FormApi {
945
956
  isSubmitSuccessful: true
946
957
  // Set isSubmitSuccessful to true on successful submission
947
958
  }));
948
- formEventClient.emit("form-submission-state-change", {
959
+ formEventClient.emit("form-submission", {
949
960
  id: this._formId,
950
961
  submissionAttempt: this.state.submissionAttempts,
951
962
  successful: true
@@ -958,7 +969,7 @@ class FormApi {
958
969
  isSubmitSuccessful: false
959
970
  // Ensure isSubmitSuccessful is false if an error occurs
960
971
  }));
961
- formEventClient.emit("form-submission-state-change", {
972
+ formEventClient.emit("form-submission", {
962
973
  id: this._formId,
963
974
  submissionAttempt: this.state.submissionAttempts,
964
975
  successful: false,