@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.
- package/dist/cjs/EventClient.cjs.map +1 -1
- package/dist/cjs/EventClient.d.cts +12 -16
- package/dist/cjs/FormApi.cjs +55 -24
- package/dist/cjs/FormApi.cjs.map +1 -1
- package/dist/esm/EventClient.d.ts +12 -16
- package/dist/esm/EventClient.js.map +1 -1
- package/dist/esm/FormApi.js +55 -24
- package/dist/esm/FormApi.js.map +1 -1
- package/package.json +3 -2
- package/src/EventClient.ts +14 -18
- package/src/FormApi.ts +68 -38
package/dist/esm/FormApi.js
CHANGED
|
@@ -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-
|
|
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;
|
|
@@ -504,9 +510,14 @@ class FormApi {
|
|
|
504
510
|
},
|
|
505
511
|
mergeOpts(options, { dontValidate: true })
|
|
506
512
|
);
|
|
507
|
-
|
|
513
|
+
const dontValidate = options?.dontValidate ?? false;
|
|
514
|
+
if (!dontValidate) {
|
|
515
|
+
await this.validateField(field, "change");
|
|
516
|
+
}
|
|
508
517
|
metaHelper(this).handleArrayFieldMetaShift(field, index, "insert");
|
|
509
|
-
|
|
518
|
+
if (!dontValidate) {
|
|
519
|
+
await this.validateArrayFieldsStartingFrom(field, index, "change");
|
|
520
|
+
}
|
|
510
521
|
};
|
|
511
522
|
this.replaceFieldValue = async (field, index, value, options) => {
|
|
512
523
|
this.setFieldValue(
|
|
@@ -518,8 +529,11 @@ class FormApi {
|
|
|
518
529
|
},
|
|
519
530
|
mergeOpts(options, { dontValidate: true })
|
|
520
531
|
);
|
|
521
|
-
|
|
522
|
-
|
|
532
|
+
const dontValidate = options?.dontValidate ?? false;
|
|
533
|
+
if (!dontValidate) {
|
|
534
|
+
await this.validateField(field, "change");
|
|
535
|
+
await this.validateArrayFieldsStartingFrom(field, index, "change");
|
|
536
|
+
}
|
|
523
537
|
};
|
|
524
538
|
this.removeFieldValue = async (field, index, options) => {
|
|
525
539
|
const fieldValue = this.getFieldValue(field);
|
|
@@ -538,8 +552,11 @@ class FormApi {
|
|
|
538
552
|
const start = `${field}[${lastIndex}]`;
|
|
539
553
|
this.deleteField(start);
|
|
540
554
|
}
|
|
541
|
-
|
|
542
|
-
|
|
555
|
+
const dontValidate = options?.dontValidate ?? false;
|
|
556
|
+
if (!dontValidate) {
|
|
557
|
+
await this.validateField(field, "change");
|
|
558
|
+
await this.validateArrayFieldsStartingFrom(field, index, "change");
|
|
559
|
+
}
|
|
543
560
|
};
|
|
544
561
|
this.swapFieldValues = (field, index1, index2, options) => {
|
|
545
562
|
this.setFieldValue(
|
|
@@ -552,9 +569,12 @@ class FormApi {
|
|
|
552
569
|
mergeOpts(options, { dontValidate: true })
|
|
553
570
|
);
|
|
554
571
|
metaHelper(this).handleArrayFieldMetaShift(field, index1, "swap", index2);
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
572
|
+
const dontValidate = options?.dontValidate ?? false;
|
|
573
|
+
if (!dontValidate) {
|
|
574
|
+
this.validateField(field, "change");
|
|
575
|
+
this.validateField(`${field}[${index1}]`, "change");
|
|
576
|
+
this.validateField(`${field}[${index2}]`, "change");
|
|
577
|
+
}
|
|
558
578
|
};
|
|
559
579
|
this.moveFieldValues = (field, index1, index2, options) => {
|
|
560
580
|
this.setFieldValue(
|
|
@@ -567,9 +587,12 @@ class FormApi {
|
|
|
567
587
|
mergeOpts(options, { dontValidate: true })
|
|
568
588
|
);
|
|
569
589
|
metaHelper(this).handleArrayFieldMetaShift(field, index1, "move", index2);
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
590
|
+
const dontValidate = options?.dontValidate ?? false;
|
|
591
|
+
if (!dontValidate) {
|
|
592
|
+
this.validateField(field, "change");
|
|
593
|
+
this.validateField(`${field}[${index1}]`, "change");
|
|
594
|
+
this.validateField(`${field}[${index2}]`, "change");
|
|
595
|
+
}
|
|
573
596
|
};
|
|
574
597
|
this.clearFieldValues = (field, options) => {
|
|
575
598
|
const fieldValue = this.getFieldValue(field);
|
|
@@ -585,7 +608,10 @@ class FormApi {
|
|
|
585
608
|
this.deleteField(fieldKey);
|
|
586
609
|
}
|
|
587
610
|
}
|
|
588
|
-
|
|
611
|
+
const dontValidate = options?.dontValidate ?? false;
|
|
612
|
+
if (!dontValidate) {
|
|
613
|
+
this.validateField(field, "change");
|
|
614
|
+
}
|
|
589
615
|
};
|
|
590
616
|
this.resetField = (field) => {
|
|
591
617
|
this.baseStore.setState((prev) => {
|
|
@@ -787,16 +813,21 @@ class FormApi {
|
|
|
787
813
|
});
|
|
788
814
|
this.handleSubmit = this.handleSubmit.bind(this);
|
|
789
815
|
this.update(opts || {});
|
|
790
|
-
|
|
791
|
-
formEventClient.emit("form-state
|
|
816
|
+
const debouncedDevtoolState = throttle(
|
|
817
|
+
(state) => formEventClient.emit("form-state", {
|
|
792
818
|
id: this._formId,
|
|
793
|
-
state
|
|
794
|
-
|
|
795
|
-
|
|
819
|
+
state
|
|
820
|
+
}),
|
|
821
|
+
{
|
|
822
|
+
wait: 300
|
|
823
|
+
}
|
|
824
|
+
);
|
|
825
|
+
this.store.subscribe(() => {
|
|
826
|
+
debouncedDevtoolState(this.store.state);
|
|
796
827
|
});
|
|
797
828
|
formEventClient.on("request-form-state", (e) => {
|
|
798
829
|
if (e.payload.id === this._formId) {
|
|
799
|
-
formEventClient.emit("form-
|
|
830
|
+
formEventClient.emit("form-api", {
|
|
800
831
|
id: this._formId,
|
|
801
832
|
state: this.store.state,
|
|
802
833
|
options: this.options
|
|
@@ -875,7 +906,7 @@ class FormApi {
|
|
|
875
906
|
formApi: this,
|
|
876
907
|
meta: submitMetaArg
|
|
877
908
|
});
|
|
878
|
-
formEventClient.emit("form-submission
|
|
909
|
+
formEventClient.emit("form-submission", {
|
|
879
910
|
id: this._formId,
|
|
880
911
|
submissionAttempt: this.state.submissionAttempts,
|
|
881
912
|
successful: false,
|
|
@@ -892,7 +923,7 @@ class FormApi {
|
|
|
892
923
|
formApi: this,
|
|
893
924
|
meta: submitMetaArg
|
|
894
925
|
});
|
|
895
|
-
formEventClient.emit("form-submission
|
|
926
|
+
formEventClient.emit("form-submission", {
|
|
896
927
|
id: this._formId,
|
|
897
928
|
submissionAttempt: this.state.submissionAttempts,
|
|
898
929
|
successful: false,
|
|
@@ -925,7 +956,7 @@ class FormApi {
|
|
|
925
956
|
isSubmitSuccessful: true
|
|
926
957
|
// Set isSubmitSuccessful to true on successful submission
|
|
927
958
|
}));
|
|
928
|
-
formEventClient.emit("form-submission
|
|
959
|
+
formEventClient.emit("form-submission", {
|
|
929
960
|
id: this._formId,
|
|
930
961
|
submissionAttempt: this.state.submissionAttempts,
|
|
931
962
|
successful: true
|
|
@@ -938,7 +969,7 @@ class FormApi {
|
|
|
938
969
|
isSubmitSuccessful: false
|
|
939
970
|
// Ensure isSubmitSuccessful is false if an error occurs
|
|
940
971
|
}));
|
|
941
|
-
formEventClient.emit("form-submission
|
|
972
|
+
formEventClient.emit("form-submission", {
|
|
942
973
|
id: this._formId,
|
|
943
974
|
submissionAttempt: this.state.submissionAttempts,
|
|
944
975
|
successful: false,
|