@tanstack/form-core 1.24.2 → 1.24.4

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.cjs","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":["EventClient"],"mappings":";;;AAgEA,MAAM,wBAAwBA,oBAAAA,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.cjs","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 })\n }\n}\n\nexport const formEventClient = new FormEventClient()\n"],"names":["EventClient"],"mappings":";;;AA4DA,MAAM,wBAAwBA,oBAAAA,YAAsB;AAAA,EAClD,cAAc;AACZ,UAAM;AAAA,MACJ,UAAU;AAAA,IAAA,CACX;AAAA,EACH;AACF;AAEO,MAAM,kBAAkB,IAAI,gBAAA;;"}
@@ -4,6 +4,10 @@ type ExtractEventNames<T> = T extends `${string}:${infer EventName}` ? EventName
4
4
  export type BroadcastFormState = {
5
5
  id: string;
6
6
  state: AnyFormState;
7
+ };
8
+ export type BroadcastFormApi = {
9
+ id: string;
10
+ state: AnyFormState;
7
11
  options: AnyFormOptions;
8
12
  };
9
13
  export type BroadcastFormSubmissionState = {
@@ -23,25 +27,17 @@ export type BroadcastFormSubmissionState = {
23
27
  submissionAttempt: number;
24
28
  successful: true;
25
29
  };
26
- export type BroadcastFormUnmounted = {
27
- id: string;
28
- };
29
- export type RequestFormState = {
30
- id: string;
31
- };
32
- export type RequestFormReset = {
33
- id: string;
34
- };
35
- export type RequestFormForceReset = {
30
+ export type BroadcastFormId = {
36
31
  id: string;
37
32
  };
38
33
  type EventMap = {
39
- 'form-devtools:form-state-change': BroadcastFormState;
40
- 'form-devtools:form-submission-state-change': BroadcastFormSubmissionState;
41
- 'form-devtools:form-unmounted': BroadcastFormUnmounted;
42
- 'form-devtools:request-form-state': RequestFormState;
43
- 'form-devtools:request-form-reset': RequestFormReset;
44
- 'form-devtools:request-form-force-submit': RequestFormForceReset;
34
+ 'form-devtools:form-state': BroadcastFormState;
35
+ 'form-devtools:form-api': BroadcastFormApi;
36
+ 'form-devtools:form-submission': BroadcastFormSubmissionState;
37
+ 'form-devtools:request-form-state': BroadcastFormId;
38
+ 'form-devtools:request-form-reset': BroadcastFormId;
39
+ 'form-devtools:request-form-force-submit': BroadcastFormId;
40
+ 'form-devtools:form-unmounted': BroadcastFormId;
45
41
  };
46
42
  export type EventClientEventMap = keyof EventMap;
47
43
  export type EventClientEventNames = ExtractEventNames<EventClientEventMap>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const store = require("@tanstack/store");
4
+ const pacer = require("@tanstack/pacer");
4
5
  const utils = require("./utils.cjs");
5
6
  const ValidationLogic = require("./ValidationLogic.cjs");
6
7
  const standardSchemaValidator = require("./standardSchemaValidator.cjs");
@@ -46,7 +47,7 @@ class FormApi {
46
47
  };
47
48
  this.options.listeners?.onMount?.({ formApi: this });
48
49
  const { onMount } = this.options.validators || {};
49
- EventClient.formEventClient.emit("form-state-change", {
50
+ EventClient.formEventClient.emit("form-api", {
50
51
  id: this._formId,
51
52
  state: this.store.state,
52
53
  options: this.options
@@ -80,6 +81,11 @@ class FormApi {
80
81
  )
81
82
  );
82
83
  });
84
+ EventClient.formEventClient.emit("form-api", {
85
+ id: this._formId,
86
+ state: this.store.state,
87
+ options: this.options
88
+ });
83
89
  };
84
90
  this.reset = (values, opts2) => {
85
91
  const { fieldMeta: currentFieldMeta } = this.state;
@@ -506,9 +512,14 @@ class FormApi {
506
512
  },
507
513
  utils.mergeOpts(options, { dontValidate: true })
508
514
  );
509
- await this.validateField(field, "change");
515
+ const dontValidate = options?.dontValidate ?? false;
516
+ if (!dontValidate) {
517
+ await this.validateField(field, "change");
518
+ }
510
519
  metaHelper.metaHelper(this).handleArrayFieldMetaShift(field, index, "insert");
511
- await this.validateArrayFieldsStartingFrom(field, index, "change");
520
+ if (!dontValidate) {
521
+ await this.validateArrayFieldsStartingFrom(field, index, "change");
522
+ }
512
523
  };
513
524
  this.replaceFieldValue = async (field, index, value, options) => {
514
525
  this.setFieldValue(
@@ -520,8 +531,11 @@ class FormApi {
520
531
  },
521
532
  utils.mergeOpts(options, { dontValidate: true })
522
533
  );
523
- await this.validateField(field, "change");
524
- await this.validateArrayFieldsStartingFrom(field, index, "change");
534
+ const dontValidate = options?.dontValidate ?? false;
535
+ if (!dontValidate) {
536
+ await this.validateField(field, "change");
537
+ await this.validateArrayFieldsStartingFrom(field, index, "change");
538
+ }
525
539
  };
526
540
  this.removeFieldValue = async (field, index, options) => {
527
541
  const fieldValue = this.getFieldValue(field);
@@ -540,8 +554,11 @@ class FormApi {
540
554
  const start = `${field}[${lastIndex}]`;
541
555
  this.deleteField(start);
542
556
  }
543
- await this.validateField(field, "change");
544
- await this.validateArrayFieldsStartingFrom(field, index, "change");
557
+ const dontValidate = options?.dontValidate ?? false;
558
+ if (!dontValidate) {
559
+ await this.validateField(field, "change");
560
+ await this.validateArrayFieldsStartingFrom(field, index, "change");
561
+ }
545
562
  };
546
563
  this.swapFieldValues = (field, index1, index2, options) => {
547
564
  this.setFieldValue(
@@ -554,9 +571,12 @@ class FormApi {
554
571
  utils.mergeOpts(options, { dontValidate: true })
555
572
  );
556
573
  metaHelper.metaHelper(this).handleArrayFieldMetaShift(field, index1, "swap", index2);
557
- this.validateField(field, "change");
558
- this.validateField(`${field}[${index1}]`, "change");
559
- this.validateField(`${field}[${index2}]`, "change");
574
+ const dontValidate = options?.dontValidate ?? false;
575
+ if (!dontValidate) {
576
+ this.validateField(field, "change");
577
+ this.validateField(`${field}[${index1}]`, "change");
578
+ this.validateField(`${field}[${index2}]`, "change");
579
+ }
560
580
  };
561
581
  this.moveFieldValues = (field, index1, index2, options) => {
562
582
  this.setFieldValue(
@@ -569,9 +589,12 @@ class FormApi {
569
589
  utils.mergeOpts(options, { dontValidate: true })
570
590
  );
571
591
  metaHelper.metaHelper(this).handleArrayFieldMetaShift(field, index1, "move", index2);
572
- this.validateField(field, "change");
573
- this.validateField(`${field}[${index1}]`, "change");
574
- this.validateField(`${field}[${index2}]`, "change");
592
+ const dontValidate = options?.dontValidate ?? false;
593
+ if (!dontValidate) {
594
+ this.validateField(field, "change");
595
+ this.validateField(`${field}[${index1}]`, "change");
596
+ this.validateField(`${field}[${index2}]`, "change");
597
+ }
575
598
  };
576
599
  this.clearFieldValues = (field, options) => {
577
600
  const fieldValue = this.getFieldValue(field);
@@ -587,7 +610,10 @@ class FormApi {
587
610
  this.deleteField(fieldKey);
588
611
  }
589
612
  }
590
- this.validateField(field, "change");
613
+ const dontValidate = options?.dontValidate ?? false;
614
+ if (!dontValidate) {
615
+ this.validateField(field, "change");
616
+ }
591
617
  };
592
618
  this.resetField = (field) => {
593
619
  this.baseStore.setState((prev) => {
@@ -789,16 +815,21 @@ class FormApi {
789
815
  });
790
816
  this.handleSubmit = this.handleSubmit.bind(this);
791
817
  this.update(opts || {});
792
- this.store.subscribe(() => {
793
- EventClient.formEventClient.emit("form-state-change", {
818
+ const debouncedDevtoolState = pacer.throttle(
819
+ (state) => EventClient.formEventClient.emit("form-state", {
794
820
  id: this._formId,
795
- state: this.store.state,
796
- options: this.options
797
- });
821
+ state
822
+ }),
823
+ {
824
+ wait: 300
825
+ }
826
+ );
827
+ this.store.subscribe(() => {
828
+ debouncedDevtoolState(this.store.state);
798
829
  });
799
830
  EventClient.formEventClient.on("request-form-state", (e) => {
800
831
  if (e.payload.id === this._formId) {
801
- EventClient.formEventClient.emit("form-state-change", {
832
+ EventClient.formEventClient.emit("form-api", {
802
833
  id: this._formId,
803
834
  state: this.store.state,
804
835
  options: this.options
@@ -877,7 +908,7 @@ class FormApi {
877
908
  formApi: this,
878
909
  meta: submitMetaArg
879
910
  });
880
- EventClient.formEventClient.emit("form-submission-state-change", {
911
+ EventClient.formEventClient.emit("form-submission", {
881
912
  id: this._formId,
882
913
  submissionAttempt: this.state.submissionAttempts,
883
914
  successful: false,
@@ -894,7 +925,7 @@ class FormApi {
894
925
  formApi: this,
895
926
  meta: submitMetaArg
896
927
  });
897
- EventClient.formEventClient.emit("form-submission-state-change", {
928
+ EventClient.formEventClient.emit("form-submission", {
898
929
  id: this._formId,
899
930
  submissionAttempt: this.state.submissionAttempts,
900
931
  successful: false,
@@ -927,7 +958,7 @@ class FormApi {
927
958
  isSubmitSuccessful: true
928
959
  // Set isSubmitSuccessful to true on successful submission
929
960
  }));
930
- EventClient.formEventClient.emit("form-submission-state-change", {
961
+ EventClient.formEventClient.emit("form-submission", {
931
962
  id: this._formId,
932
963
  submissionAttempt: this.state.submissionAttempts,
933
964
  successful: true
@@ -940,7 +971,7 @@ class FormApi {
940
971
  isSubmitSuccessful: false
941
972
  // Ensure isSubmitSuccessful is false if an error occurs
942
973
  }));
943
- EventClient.formEventClient.emit("form-submission-state-change", {
974
+ EventClient.formEventClient.emit("form-submission", {
944
975
  id: this._formId,
945
976
  submissionAttempt: this.state.submissionAttempts,
946
977
  successful: false,