@tanstack/form-core 1.24.3 → 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 +22 -11
- 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 +22 -11
- package/dist/esm/FormApi.js.map +1 -1
- package/package.json +3 -2
- package/src/EventClient.ts +14 -18
- package/src/FormApi.ts +27 -17
|
@@ -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
|
|
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
|
|
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
|
|
40
|
-
'form-devtools:form-
|
|
41
|
-
'form-devtools:form-
|
|
42
|
-
'form-devtools:request-form-state':
|
|
43
|
-
'form-devtools:request-form-reset':
|
|
44
|
-
'form-devtools:request-form-force-submit':
|
|
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>;
|
package/dist/cjs/FormApi.cjs
CHANGED
|
@@ -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-
|
|
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;
|
|
@@ -809,16 +815,21 @@ class FormApi {
|
|
|
809
815
|
});
|
|
810
816
|
this.handleSubmit = this.handleSubmit.bind(this);
|
|
811
817
|
this.update(opts || {});
|
|
812
|
-
|
|
813
|
-
EventClient.formEventClient.emit("form-state
|
|
818
|
+
const debouncedDevtoolState = pacer.throttle(
|
|
819
|
+
(state) => EventClient.formEventClient.emit("form-state", {
|
|
814
820
|
id: this._formId,
|
|
815
|
-
state
|
|
816
|
-
|
|
817
|
-
|
|
821
|
+
state
|
|
822
|
+
}),
|
|
823
|
+
{
|
|
824
|
+
wait: 300
|
|
825
|
+
}
|
|
826
|
+
);
|
|
827
|
+
this.store.subscribe(() => {
|
|
828
|
+
debouncedDevtoolState(this.store.state);
|
|
818
829
|
});
|
|
819
830
|
EventClient.formEventClient.on("request-form-state", (e) => {
|
|
820
831
|
if (e.payload.id === this._formId) {
|
|
821
|
-
EventClient.formEventClient.emit("form-
|
|
832
|
+
EventClient.formEventClient.emit("form-api", {
|
|
822
833
|
id: this._formId,
|
|
823
834
|
state: this.store.state,
|
|
824
835
|
options: this.options
|
|
@@ -897,7 +908,7 @@ class FormApi {
|
|
|
897
908
|
formApi: this,
|
|
898
909
|
meta: submitMetaArg
|
|
899
910
|
});
|
|
900
|
-
EventClient.formEventClient.emit("form-submission
|
|
911
|
+
EventClient.formEventClient.emit("form-submission", {
|
|
901
912
|
id: this._formId,
|
|
902
913
|
submissionAttempt: this.state.submissionAttempts,
|
|
903
914
|
successful: false,
|
|
@@ -914,7 +925,7 @@ class FormApi {
|
|
|
914
925
|
formApi: this,
|
|
915
926
|
meta: submitMetaArg
|
|
916
927
|
});
|
|
917
|
-
EventClient.formEventClient.emit("form-submission
|
|
928
|
+
EventClient.formEventClient.emit("form-submission", {
|
|
918
929
|
id: this._formId,
|
|
919
930
|
submissionAttempt: this.state.submissionAttempts,
|
|
920
931
|
successful: false,
|
|
@@ -947,7 +958,7 @@ class FormApi {
|
|
|
947
958
|
isSubmitSuccessful: true
|
|
948
959
|
// Set isSubmitSuccessful to true on successful submission
|
|
949
960
|
}));
|
|
950
|
-
EventClient.formEventClient.emit("form-submission
|
|
961
|
+
EventClient.formEventClient.emit("form-submission", {
|
|
951
962
|
id: this._formId,
|
|
952
963
|
submissionAttempt: this.state.submissionAttempts,
|
|
953
964
|
successful: true
|
|
@@ -960,7 +971,7 @@ class FormApi {
|
|
|
960
971
|
isSubmitSuccessful: false
|
|
961
972
|
// Ensure isSubmitSuccessful is false if an error occurs
|
|
962
973
|
}));
|
|
963
|
-
EventClient.formEventClient.emit("form-submission
|
|
974
|
+
EventClient.formEventClient.emit("form-submission", {
|
|
964
975
|
id: this._formId,
|
|
965
976
|
submissionAttempt: this.state.submissionAttempts,
|
|
966
977
|
successful: false,
|