@gsc-basic/components 1.0.1 → 1.0.2

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.
Files changed (108) hide show
  1. package/README.md +59 -0
  2. package/dist/es/index.js +34 -30
  3. package/dist/es/node_modules/@codemirror/commands/dist/index.js +26 -20
  4. package/dist/es/node_modules/@codemirror/language/dist/index.js +77 -77
  5. package/dist/es/node_modules/@codemirror/search/dist/index.js +432 -465
  6. package/dist/es/node_modules/@codemirror/state/dist/index.js +272 -268
  7. package/dist/es/node_modules/@codemirror/view/dist/index.js +1732 -1647
  8. package/dist/es/node_modules/@lezer/common/dist/index.js +191 -190
  9. package/dist/es/node_modules/@lezer/lr/dist/index.js +3 -3
  10. package/dist/es/node_modules/@tanstack/devtools-event-client/dist/esm/plugin.js +178 -0
  11. package/dist/es/node_modules/@tanstack/form-core/dist/esm/EventClient.js +13 -0
  12. package/dist/es/node_modules/@tanstack/form-core/dist/esm/FieldApi.js +406 -0
  13. package/dist/es/node_modules/@tanstack/form-core/dist/esm/FormApi.js +768 -0
  14. package/dist/es/node_modules/@tanstack/form-core/dist/esm/ValidationLogic.js +55 -0
  15. package/dist/es/node_modules/@tanstack/form-core/dist/esm/metaHelper.js +109 -0
  16. package/dist/es/node_modules/@tanstack/form-core/dist/esm/standardSchemaValidator.js +45 -0
  17. package/dist/es/node_modules/@tanstack/form-core/dist/esm/utils.js +213 -0
  18. package/dist/es/node_modules/@tanstack/pacer-lite/dist/lite-throttler.js +29 -0
  19. package/dist/es/node_modules/@tanstack/store/dist/esm/derived.js +74 -0
  20. package/dist/es/node_modules/@tanstack/store/dist/esm/scheduler.js +79 -0
  21. package/dist/es/node_modules/@tanstack/store/dist/esm/store.js +21 -0
  22. package/dist/es/node_modules/@tanstack/store/dist/esm/types.js +6 -0
  23. package/dist/es/node_modules/@tanstack/table-core/build/lib/index.js +1885 -0
  24. package/dist/es/node_modules/@tanstack/vue-form/dist/esm/useField.js +38 -0
  25. package/dist/es/node_modules/@tanstack/vue-form/dist/esm/useForm.js +33 -0
  26. package/dist/es/node_modules/@tanstack/vue-store/dist/esm/index.js +48 -0
  27. package/dist/es/node_modules/@tanstack/vue-table/build/lib/index.js +159 -0
  28. package/dist/es/src/Grid/index.js +6 -0
  29. package/dist/es/src/Grid/src/Grid.css +1 -0
  30. package/dist/es/src/Grid/src/Grid.vue.js +186 -0
  31. package/dist/es/src/Grid/src/components/ActionBar.css +1 -0
  32. package/dist/es/src/Grid/src/components/ActionBar.vue.js +58 -0
  33. package/dist/es/src/Grid/src/components/CellEditor.css +1 -0
  34. package/dist/es/src/Grid/src/components/CellEditor.vue.js +121 -0
  35. package/dist/es/src/Grid/src/components/CellEditor2.css +1 -0
  36. package/dist/es/src/Grid/src/components/ColumnFilter.css +1 -0
  37. package/dist/es/src/Grid/src/components/ColumnFilter.vue.js +61 -0
  38. package/dist/es/src/Grid/src/components/ColumnSettings.css +1 -0
  39. package/dist/es/src/Grid/src/components/ColumnSettings.vue.js +86 -0
  40. package/dist/es/src/Grid/src/components/DataTable.css +1 -0
  41. package/dist/es/src/Grid/src/components/DataTable.vue.js +533 -0
  42. package/dist/es/src/Grid/src/components/Pager.css +1 -0
  43. package/dist/es/src/Grid/src/components/Pager.vue.js +55 -0
  44. package/dist/es/src/Grid/src/components/QueryBar.css +1 -0
  45. package/dist/es/src/Grid/src/components/QueryBar.vue.js +184 -0
  46. package/dist/es/src/Grid/src/composables/useCellEditor.js +20 -0
  47. package/dist/es/src/Grid/src/composables/useGridTable.js +212 -0
  48. package/dist/es/src/Grid/src/styles/antd.css +1 -0
  49. package/dist/es/src/Grid/src/utils/exportCsv.js +15 -0
  50. package/dist/es/src/index.js +23 -21
  51. package/dist/es/src/locale/lang/en-US.js +40 -0
  52. package/dist/es/src/locale/lang/ja-JP.js +42 -2
  53. package/dist/es/src/locale/lang/zh-CN.js +42 -2
  54. package/dist/es/src/styles/tokens.css +1 -1
  55. package/dist/lib/index.js +1 -1
  56. package/dist/lib/node_modules/@codemirror/commands/dist/index.js +1 -1
  57. package/dist/lib/node_modules/@codemirror/language/dist/index.js +1 -1
  58. package/dist/lib/node_modules/@codemirror/search/dist/index.js +2 -2
  59. package/dist/lib/node_modules/@codemirror/state/dist/index.js +4 -4
  60. package/dist/lib/node_modules/@codemirror/view/dist/index.js +5 -5
  61. package/dist/lib/node_modules/@lezer/common/dist/index.js +1 -1
  62. package/dist/lib/node_modules/@lezer/lr/dist/index.js +1 -1
  63. package/dist/lib/node_modules/@tanstack/devtools-event-client/dist/esm/plugin.js +1 -0
  64. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/EventClient.js +1 -0
  65. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/FieldApi.js +1 -0
  66. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/FormApi.js +1 -0
  67. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/ValidationLogic.js +1 -0
  68. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/metaHelper.js +1 -0
  69. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/standardSchemaValidator.js +1 -0
  70. package/dist/lib/node_modules/@tanstack/form-core/dist/esm/utils.js +1 -0
  71. package/dist/lib/node_modules/@tanstack/pacer-lite/dist/lite-throttler.js +1 -0
  72. package/dist/lib/node_modules/@tanstack/store/dist/esm/derived.js +1 -0
  73. package/dist/lib/node_modules/@tanstack/store/dist/esm/scheduler.js +1 -0
  74. package/dist/lib/node_modules/@tanstack/store/dist/esm/store.js +1 -0
  75. package/dist/lib/node_modules/@tanstack/store/dist/esm/types.js +1 -0
  76. package/dist/lib/node_modules/@tanstack/table-core/build/lib/index.js +4 -0
  77. package/dist/lib/node_modules/@tanstack/vue-form/dist/esm/useField.js +1 -0
  78. package/dist/lib/node_modules/@tanstack/vue-form/dist/esm/useForm.js +1 -0
  79. package/dist/lib/node_modules/@tanstack/vue-store/dist/esm/index.js +1 -0
  80. package/dist/lib/node_modules/@tanstack/vue-table/build/lib/index.js +1 -0
  81. package/dist/lib/src/Grid/index.js +1 -0
  82. package/dist/lib/src/Grid/src/Grid.css +1 -0
  83. package/dist/lib/src/Grid/src/Grid.vue.js +1 -0
  84. package/dist/lib/src/Grid/src/components/ActionBar.css +1 -0
  85. package/dist/lib/src/Grid/src/components/ActionBar.vue.js +1 -0
  86. package/dist/lib/src/Grid/src/components/CellEditor.css +1 -0
  87. package/dist/lib/src/Grid/src/components/CellEditor.vue.js +1 -0
  88. package/dist/lib/src/Grid/src/components/CellEditor2.css +1 -0
  89. package/dist/lib/src/Grid/src/components/ColumnFilter.css +1 -0
  90. package/dist/lib/src/Grid/src/components/ColumnFilter.vue.js +1 -0
  91. package/dist/lib/src/Grid/src/components/ColumnSettings.css +1 -0
  92. package/dist/lib/src/Grid/src/components/ColumnSettings.vue.js +1 -0
  93. package/dist/lib/src/Grid/src/components/DataTable.css +1 -0
  94. package/dist/lib/src/Grid/src/components/DataTable.vue.js +1 -0
  95. package/dist/lib/src/Grid/src/components/Pager.css +1 -0
  96. package/dist/lib/src/Grid/src/components/Pager.vue.js +1 -0
  97. package/dist/lib/src/Grid/src/components/QueryBar.css +1 -0
  98. package/dist/lib/src/Grid/src/components/QueryBar.vue.js +1 -0
  99. package/dist/lib/src/Grid/src/composables/useCellEditor.js +1 -0
  100. package/dist/lib/src/Grid/src/composables/useGridTable.js +1 -0
  101. package/dist/lib/src/Grid/src/styles/antd.css +1 -0
  102. package/dist/lib/src/Grid/src/utils/exportCsv.js +3 -0
  103. package/dist/lib/src/index.js +1 -1
  104. package/dist/lib/src/locale/lang/en-US.js +1 -1
  105. package/dist/lib/src/locale/lang/ja-JP.js +1 -1
  106. package/dist/lib/src/locale/lang/zh-CN.js +1 -1
  107. package/dist/lib/src/styles/tokens.css +1 -1
  108. package/package.json +6 -3
@@ -0,0 +1,768 @@
1
+ import { Derived as N } from "../../../store/dist/esm/derived.js";
2
+ import { Store as G } from "../../../store/dist/esm/store.js";
3
+ import { batch as A } from "../../../store/dist/esm/scheduler.js";
4
+ import { throttleFormState as H, evaluate as w, getSyncValidatorArray as J, getAsyncValidatorArray as Q, determineFormLevelErrorSourceAndValue as q, getBy as T, functionalUpdate as X, deleteBy as Y, mergeOpts as B, setBy as _, uuid as Z, isNonEmptyArray as x, isGlobalFormValidationError as W } from "./utils.js";
5
+ import { defaultValidationLogic as z } from "./ValidationLogic.js";
6
+ import { standardSchemaValidators as U, isStandardSchemaValidator as tt } from "./standardSchemaValidator.js";
7
+ import { defaultFieldMeta as $, metaHelper as P } from "./metaHelper.js";
8
+ import { formEventClient as y } from "./EventClient.js";
9
+ function R(f) {
10
+ return {
11
+ values: f.values ?? {},
12
+ errorMap: f.errorMap ?? {},
13
+ fieldMetaBase: f.fieldMetaBase ?? {},
14
+ isSubmitted: f.isSubmitted ?? !1,
15
+ isSubmitting: f.isSubmitting ?? !1,
16
+ isValidating: f.isValidating ?? !1,
17
+ submissionAttempts: f.submissionAttempts ?? 0,
18
+ isSubmitSuccessful: f.isSubmitSuccessful ?? !1,
19
+ validationMetaMap: f.validationMetaMap ?? {
20
+ onChange: void 0,
21
+ onBlur: void 0,
22
+ onSubmit: void 0,
23
+ onMount: void 0,
24
+ onServer: void 0,
25
+ onDynamic: void 0
26
+ }
27
+ };
28
+ }
29
+ class ut {
30
+ /**
31
+ * Constructs a new `FormApi` instance with the given form options.
32
+ */
33
+ constructor(p) {
34
+ this.options = {}, this.fieldInfo = {}, this.prevTransformArray = [], this.mount = () => {
35
+ const t = this.fieldMetaDerived.mount(), i = this.store.mount(), s = this.store.subscribe(() => {
36
+ H(this);
37
+ }), e = y.on(
38
+ "request-form-state",
39
+ (n) => {
40
+ n.payload.id === this._formId && y.emit("form-api", {
41
+ id: this._formId,
42
+ state: this.store.state,
43
+ options: this.options
44
+ });
45
+ }
46
+ ), o = y.on(
47
+ "request-form-reset",
48
+ (n) => {
49
+ n.payload.id === this._formId && this.reset();
50
+ }
51
+ ), a = y.on(
52
+ "request-form-force-submit",
53
+ (n) => {
54
+ n.payload.id === this._formId && (this._devtoolsSubmissionOverride = !0, this.handleSubmit(), this._devtoolsSubmissionOverride = !1);
55
+ }
56
+ ), r = () => {
57
+ a(), o(), e(), s(), t(), i(), y.emit("form-unmounted", {
58
+ id: this._formId
59
+ });
60
+ };
61
+ this.options.listeners?.onMount?.({ formApi: this });
62
+ const { onMount: l } = this.options.validators || {};
63
+ return y.emit("form-api", {
64
+ id: this._formId,
65
+ state: this.store.state,
66
+ options: this.options
67
+ }), l && this.validateSync("mount"), r;
68
+ }, this.update = (t) => {
69
+ if (!t) return;
70
+ const i = this.options;
71
+ this.options = t;
72
+ const s = !!t.transform?.deps?.some(
73
+ (a, r) => a !== this.prevTransformArray[r]
74
+ ), e = t.defaultValues && !w(t.defaultValues, i.defaultValues) && !this.state.isTouched, o = !w(t.defaultState, i.defaultState) && !this.state.isTouched;
75
+ !e && !o && !s || (A(() => {
76
+ this.baseStore.setState(
77
+ () => R(
78
+ Object.assign(
79
+ {},
80
+ this.state,
81
+ o ? t.defaultState : {},
82
+ e ? {
83
+ values: t.defaultValues
84
+ } : {},
85
+ s ? { _force_re_eval: !this.state._force_re_eval } : {}
86
+ )
87
+ )
88
+ );
89
+ }), y.emit("form-api", {
90
+ id: this._formId,
91
+ state: this.store.state,
92
+ options: this.options
93
+ }));
94
+ }, this.reset = (t, i) => {
95
+ const { fieldMeta: s } = this.state, e = this.resetFieldMeta(s);
96
+ t && !i?.keepDefaultValues && (this.options = {
97
+ ...this.options,
98
+ defaultValues: t
99
+ }), this.baseStore.setState(
100
+ () => R({
101
+ ...this.options.defaultState,
102
+ values: t ?? this.options.defaultValues ?? this.options.defaultState?.values,
103
+ fieldMetaBase: e
104
+ })
105
+ );
106
+ }, this.validateAllFields = async (t) => {
107
+ const i = [];
108
+ return A(() => {
109
+ Object.values(this.fieldInfo).forEach(
110
+ (e) => {
111
+ if (!e.instance) return;
112
+ const o = e.instance;
113
+ i.push(
114
+ // Remember, `validate` is either a sync operation or a promise
115
+ Promise.resolve().then(
116
+ () => o.validate(t, { skipFormValidation: !0 })
117
+ )
118
+ ), e.instance.state.meta.isTouched || e.instance.setMeta((a) => ({ ...a, isTouched: !0 }));
119
+ }
120
+ );
121
+ }), (await Promise.all(i)).flat();
122
+ }, this.validateArrayFieldsStartingFrom = async (t, i, s) => {
123
+ const e = this.getFieldValue(t), o = Array.isArray(e) ? Math.max(e.length - 1, 0) : null, a = [`${t}[${i}]`];
124
+ for (let d = i + 1; d <= (o ?? 0); d++)
125
+ a.push(`${t}[${d}]`);
126
+ const r = Object.keys(this.fieldInfo).filter(
127
+ (d) => a.some((c) => d.startsWith(c))
128
+ ), l = [];
129
+ return A(() => {
130
+ r.forEach((d) => {
131
+ l.push(
132
+ Promise.resolve().then(() => this.validateField(d, s))
133
+ );
134
+ });
135
+ }), (await Promise.all(l)).flat();
136
+ }, this.validateField = (t, i) => {
137
+ const s = this.fieldInfo[t]?.instance;
138
+ return s ? (s.state.meta.isTouched || s.setMeta((e) => ({ ...e, isTouched: !0 })), s.validate(i)) : [];
139
+ }, this.validateSync = (t) => {
140
+ const i = J(t, {
141
+ ...this.options,
142
+ form: this,
143
+ validationLogic: this.options.validationLogic || z
144
+ });
145
+ let s = !1;
146
+ const e = {};
147
+ return A(() => {
148
+ for (const r of i) {
149
+ if (!r.validate) continue;
150
+ const l = this.runValidator({
151
+ validate: r.validate,
152
+ value: {
153
+ value: this.state.values,
154
+ formApi: this,
155
+ validationSource: "form"
156
+ },
157
+ type: "validate"
158
+ }), { formError: n, fieldErrors: d } = k(l), c = j(r.cause), m = /* @__PURE__ */ new Set([
159
+ ...Object.keys(this.state.fieldMeta),
160
+ ...Object.keys(d || {})
161
+ ]);
162
+ for (const v of m) {
163
+ if (this.baseStore.state.fieldMetaBase[v] === void 0 && !d?.[v])
164
+ continue;
165
+ const S = this.getFieldMeta(v) ?? $, {
166
+ errorMap: M,
167
+ errorSourceMap: h
168
+ } = S, V = d?.[v], { newErrorValue: F, newSource: b } = q({
169
+ newFormValidatorError: V,
170
+ isPreviousErrorFromFormValidator: (
171
+ // These conditional checks are required, otherwise we get runtime errors.
172
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
173
+ h?.[c] === "form"
174
+ ),
175
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
176
+ previousErrorValue: M?.[c]
177
+ });
178
+ b === "form" && (e[v] = {
179
+ ...e[v],
180
+ [c]: V
181
+ }), M?.[c] !== F && this.setFieldMeta(v, (g = $) => ({
182
+ ...g,
183
+ errorMap: {
184
+ ...g.errorMap,
185
+ [c]: F
186
+ },
187
+ errorSourceMap: {
188
+ ...g.errorSourceMap,
189
+ [c]: b
190
+ }
191
+ }));
192
+ }
193
+ this.state.errorMap?.[c] !== n && this.baseStore.setState((v) => ({
194
+ ...v,
195
+ errorMap: {
196
+ ...v.errorMap,
197
+ [c]: n
198
+ }
199
+ })), (n || d) && (s = !0);
200
+ }
201
+ const o = j("submit");
202
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
203
+ this.state.errorMap?.[o] && t !== "submit" && !s && this.baseStore.setState((r) => ({
204
+ ...r,
205
+ errorMap: {
206
+ ...r.errorMap,
207
+ [o]: void 0
208
+ }
209
+ }));
210
+ const a = j("server");
211
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
212
+ this.state.errorMap?.[a] && t !== "server" && !s && this.baseStore.setState((r) => ({
213
+ ...r,
214
+ errorMap: {
215
+ ...r.errorMap,
216
+ [a]: void 0
217
+ }
218
+ }));
219
+ }), { hasErrored: s, fieldsErrorMap: e };
220
+ }, this.validateAsync = async (t) => {
221
+ const i = Q(t, {
222
+ ...this.options,
223
+ form: this,
224
+ validationLogic: this.options.validationLogic || z
225
+ });
226
+ this.state.isFormValidating || this.baseStore.setState((r) => ({ ...r, isFormValidating: !0 }));
227
+ const s = [];
228
+ let e;
229
+ for (const r of i) {
230
+ if (!r.validate) continue;
231
+ const l = j(r.cause);
232
+ this.state.validationMetaMap[l]?.lastAbortController.abort();
233
+ const d = new AbortController();
234
+ this.state.validationMetaMap[l] = {
235
+ lastAbortController: d
236
+ }, s.push(
237
+ new Promise(async (c) => {
238
+ let m;
239
+ try {
240
+ m = await new Promise((h, V) => {
241
+ setTimeout(async () => {
242
+ if (d.signal.aborted) return h(void 0);
243
+ try {
244
+ h(
245
+ await this.runValidator({
246
+ validate: r.validate,
247
+ value: {
248
+ value: this.state.values,
249
+ formApi: this,
250
+ validationSource: "form",
251
+ signal: d.signal
252
+ },
253
+ type: "validateAsync"
254
+ })
255
+ );
256
+ } catch (F) {
257
+ V(F);
258
+ }
259
+ }, r.debounceMs);
260
+ });
261
+ } catch (h) {
262
+ m = h;
263
+ }
264
+ const { formError: v, fieldErrors: S } = k(m);
265
+ S && (e = e ? {
266
+ ...e,
267
+ ...S
268
+ } : S);
269
+ const M = j(r.cause);
270
+ for (const h of Object.keys(
271
+ this.state.fieldMeta
272
+ )) {
273
+ if (this.baseStore.state.fieldMetaBase[h] === void 0)
274
+ continue;
275
+ const V = this.getFieldMeta(h);
276
+ if (!V) continue;
277
+ const {
278
+ errorMap: F,
279
+ errorSourceMap: b
280
+ } = V, g = e?.[h], { newErrorValue: I, newSource: L } = q({
281
+ newFormValidatorError: g,
282
+ isPreviousErrorFromFormValidator: (
283
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
284
+ b?.[M] === "form"
285
+ ),
286
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
287
+ previousErrorValue: F?.[M]
288
+ });
289
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
290
+ F?.[M] !== I && this.setFieldMeta(h, (O) => ({
291
+ ...O,
292
+ errorMap: {
293
+ ...O.errorMap,
294
+ [M]: I
295
+ },
296
+ errorSourceMap: {
297
+ ...O.errorSourceMap,
298
+ [M]: L
299
+ }
300
+ }));
301
+ }
302
+ this.baseStore.setState((h) => ({
303
+ ...h,
304
+ errorMap: {
305
+ ...h.errorMap,
306
+ [M]: v
307
+ }
308
+ })), c(
309
+ e ? { fieldErrors: e, errorMapKey: M } : void 0
310
+ );
311
+ })
312
+ );
313
+ }
314
+ let o = [];
315
+ const a = {};
316
+ if (s.length) {
317
+ o = await Promise.all(s);
318
+ for (const r of o)
319
+ if (r?.fieldErrors) {
320
+ const { errorMapKey: l } = r;
321
+ for (const [n, d] of Object.entries(
322
+ r.fieldErrors
323
+ )) {
324
+ const m = {
325
+ ...a[n] || {},
326
+ [l]: d
327
+ };
328
+ a[n] = m;
329
+ }
330
+ }
331
+ }
332
+ return this.baseStore.setState((r) => ({
333
+ ...r,
334
+ isFormValidating: !1
335
+ })), a;
336
+ }, this.validate = (t) => {
337
+ const { hasErrored: i, fieldsErrorMap: s } = this.validateSync(t);
338
+ return i && !this.options.asyncAlways ? s : this.validateAsync(t);
339
+ }, this._handleSubmit = async (t) => {
340
+ this.baseStore.setState((e) => ({
341
+ ...e,
342
+ // Submission attempts mark the form as not submitted
343
+ isSubmitted: !1,
344
+ // Count submission attempts
345
+ submissionAttempts: e.submissionAttempts + 1,
346
+ isSubmitSuccessful: !1
347
+ // Reset isSubmitSuccessful at the start of submission
348
+ })), A(() => {
349
+ Object.values(this.fieldInfo).forEach(
350
+ (e) => {
351
+ e.instance && (e.instance.state.meta.isTouched || e.instance.setMeta((o) => ({ ...o, isTouched: !0 })));
352
+ }
353
+ );
354
+ });
355
+ const i = t ?? this.options.onSubmitMeta;
356
+ if (!this.state.canSubmit && !this._devtoolsSubmissionOverride) {
357
+ this.options.onSubmitInvalid?.({
358
+ value: this.state.values,
359
+ formApi: this,
360
+ meta: i
361
+ });
362
+ return;
363
+ }
364
+ this.baseStore.setState((e) => ({ ...e, isSubmitting: !0 }));
365
+ const s = () => {
366
+ this.baseStore.setState((e) => ({ ...e, isSubmitting: !1 }));
367
+ };
368
+ if (await this.validateAllFields("submit"), !this.state.isFieldsValid) {
369
+ s(), this.options.onSubmitInvalid?.({
370
+ value: this.state.values,
371
+ formApi: this,
372
+ meta: i
373
+ }), y.emit("form-submission", {
374
+ id: this._formId,
375
+ submissionAttempt: this.state.submissionAttempts,
376
+ successful: !1,
377
+ stage: "validateAllFields",
378
+ errors: Object.values(this.state.fieldMeta).map((e) => e.errors).flat()
379
+ });
380
+ return;
381
+ }
382
+ if (await this.validate("submit"), !this.state.isValid) {
383
+ s(), this.options.onSubmitInvalid?.({
384
+ value: this.state.values,
385
+ formApi: this,
386
+ meta: i
387
+ }), y.emit("form-submission", {
388
+ id: this._formId,
389
+ submissionAttempt: this.state.submissionAttempts,
390
+ successful: !1,
391
+ stage: "validate",
392
+ errors: this.state.errors
393
+ });
394
+ return;
395
+ }
396
+ A(() => {
397
+ Object.values(this.fieldInfo).forEach(
398
+ (e) => {
399
+ e.instance?.options.listeners?.onSubmit?.({
400
+ value: e.instance.state.value,
401
+ fieldApi: e.instance
402
+ });
403
+ }
404
+ );
405
+ }), this.options.listeners?.onSubmit?.({ formApi: this, meta: i });
406
+ try {
407
+ await this.options.onSubmit?.({
408
+ value: this.state.values,
409
+ formApi: this,
410
+ meta: i
411
+ }), A(() => {
412
+ this.baseStore.setState((e) => ({
413
+ ...e,
414
+ isSubmitted: !0,
415
+ isSubmitSuccessful: !0
416
+ // Set isSubmitSuccessful to true on successful submission
417
+ })), y.emit("form-submission", {
418
+ id: this._formId,
419
+ submissionAttempt: this.state.submissionAttempts,
420
+ successful: !0
421
+ }), s();
422
+ });
423
+ } catch (e) {
424
+ throw this.baseStore.setState((o) => ({
425
+ ...o,
426
+ isSubmitSuccessful: !1
427
+ // Ensure isSubmitSuccessful is false if an error occurs
428
+ })), y.emit("form-submission", {
429
+ id: this._formId,
430
+ submissionAttempt: this.state.submissionAttempts,
431
+ successful: !1,
432
+ stage: "inflight",
433
+ onError: e
434
+ }), s(), e;
435
+ }
436
+ }, this.getFieldValue = (t) => T(this.state.values, t), this.getFieldMeta = (t) => this.state.fieldMeta[t], this.getFieldInfo = (t) => this.fieldInfo[t] ||= {
437
+ instance: null,
438
+ validationMetaMap: {
439
+ onChange: void 0,
440
+ onBlur: void 0,
441
+ onSubmit: void 0,
442
+ onMount: void 0,
443
+ onServer: void 0,
444
+ onDynamic: void 0
445
+ }
446
+ }, this.setFieldMeta = (t, i) => {
447
+ this.baseStore.setState((s) => ({
448
+ ...s,
449
+ fieldMetaBase: {
450
+ ...s.fieldMetaBase,
451
+ [t]: X(
452
+ i,
453
+ s.fieldMetaBase[t]
454
+ )
455
+ }
456
+ }));
457
+ }, this.resetFieldMeta = (t) => Object.keys(t).reduce(
458
+ (i, s) => {
459
+ const e = s;
460
+ return i[e] = $, i;
461
+ },
462
+ {}
463
+ ), this.setFieldValue = (t, i, s) => {
464
+ const e = s?.dontUpdateMeta ?? !1, o = s?.dontRunListeners ?? !1, a = s?.dontValidate ?? !1;
465
+ A(() => {
466
+ e || this.setFieldMeta(t, (r) => ({
467
+ ...r,
468
+ isTouched: !0,
469
+ isDirty: !0,
470
+ errorMap: {
471
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
472
+ ...r?.errorMap,
473
+ onMount: void 0
474
+ }
475
+ })), this.baseStore.setState((r) => ({
476
+ ...r,
477
+ values: _(r.values, t, i)
478
+ }));
479
+ }), o || this.getFieldInfo(t).instance?.triggerOnChangeListener(), a || this.validateField(t, "change");
480
+ }, this.deleteField = (t) => {
481
+ const s = [...Object.keys(this.fieldInfo).filter((e) => {
482
+ const o = t.toString();
483
+ return e !== o && e.startsWith(o);
484
+ }), t];
485
+ this.baseStore.setState((e) => {
486
+ const o = { ...e };
487
+ return s.forEach((a) => {
488
+ o.values = Y(o.values, a), delete this.fieldInfo[a], delete o.fieldMetaBase[a];
489
+ }), o;
490
+ });
491
+ }, this.pushFieldValue = (t, i, s) => {
492
+ this.setFieldValue(
493
+ t,
494
+ (e) => [...Array.isArray(e) ? e : [], i],
495
+ s
496
+ );
497
+ }, this.insertFieldValue = async (t, i, s, e) => {
498
+ this.setFieldValue(
499
+ t,
500
+ (a) => [
501
+ ...a.slice(0, i),
502
+ s,
503
+ ...a.slice(i)
504
+ ],
505
+ B(e, { dontValidate: !0 })
506
+ );
507
+ const o = e?.dontValidate ?? !1;
508
+ o || await this.validateField(t, "change"), P(this).handleArrayInsert(t, i), o || await this.validateArrayFieldsStartingFrom(t, i, "change");
509
+ }, this.replaceFieldValue = async (t, i, s, e) => {
510
+ this.setFieldValue(
511
+ t,
512
+ (a) => a.map(
513
+ (r, l) => l === i ? s : r
514
+ ),
515
+ B(e, { dontValidate: !0 })
516
+ ), (e?.dontValidate ?? !1) || (await this.validateField(t, "change"), await this.validateArrayFieldsStartingFrom(t, i, "change"));
517
+ }, this.removeFieldValue = async (t, i, s) => {
518
+ const e = this.getFieldValue(t), o = Array.isArray(e) ? Math.max(e.length - 1, 0) : null;
519
+ if (this.setFieldValue(
520
+ t,
521
+ (r) => r.filter(
522
+ (l, n) => n !== i
523
+ ),
524
+ B(s, { dontValidate: !0 })
525
+ ), P(this).handleArrayRemove(t, i), o !== null) {
526
+ const r = `${t}[${o}]`;
527
+ this.deleteField(r);
528
+ }
529
+ (s?.dontValidate ?? !1) || (await this.validateField(t, "change"), await this.validateArrayFieldsStartingFrom(t, i, "change"));
530
+ }, this.swapFieldValues = (t, i, s, e) => {
531
+ this.setFieldValue(
532
+ t,
533
+ (a) => {
534
+ const r = a[i], l = a[s];
535
+ return _(_(a, `${i}`, l), `${s}`, r);
536
+ },
537
+ B(e, { dontValidate: !0 })
538
+ ), P(this).handleArraySwap(t, i, s), (e?.dontValidate ?? !1) || (this.validateField(t, "change"), this.validateField(`${t}[${i}]`, "change"), this.validateField(`${t}[${s}]`, "change"));
539
+ }, this.moveFieldValues = (t, i, s, e) => {
540
+ this.setFieldValue(
541
+ t,
542
+ (a) => {
543
+ const r = [...a];
544
+ return r.splice(s, 0, r.splice(i, 1)[0]), r;
545
+ },
546
+ B(e, { dontValidate: !0 })
547
+ ), P(this).handleArrayMove(t, i, s), (e?.dontValidate ?? !1) || (this.validateField(t, "change"), this.validateField(`${t}[${i}]`, "change"), this.validateField(`${t}[${s}]`, "change"));
548
+ }, this.clearFieldValues = (t, i) => {
549
+ const s = this.getFieldValue(t), e = Array.isArray(s) ? Math.max(s.length - 1, 0) : null;
550
+ if (this.setFieldValue(
551
+ t,
552
+ [],
553
+ B(i, { dontValidate: !0 })
554
+ ), e !== null)
555
+ for (let a = 0; a <= e; a++) {
556
+ const r = `${t}[${a}]`;
557
+ this.deleteField(r);
558
+ }
559
+ (i?.dontValidate ?? !1) || this.validateField(t, "change");
560
+ }, this.resetField = (t) => {
561
+ this.baseStore.setState((i) => ({
562
+ ...i,
563
+ fieldMetaBase: {
564
+ ...i.fieldMetaBase,
565
+ [t]: $
566
+ },
567
+ values: this.options.defaultValues ? _(i.values, t, T(this.options.defaultValues, t)) : i.values
568
+ }));
569
+ }, this.setErrorMap = (t) => {
570
+ A(() => {
571
+ Object.entries(t).forEach(([i, s]) => {
572
+ const e = i;
573
+ if (W(s)) {
574
+ const { formError: o, fieldErrors: a } = k(s);
575
+ for (const r of Object.keys(
576
+ this.fieldInfo
577
+ ))
578
+ this.getFieldMeta(r) && this.setFieldMeta(r, (n) => ({
579
+ ...n,
580
+ errorMap: {
581
+ ...n.errorMap,
582
+ [e]: a?.[r]
583
+ },
584
+ errorSourceMap: {
585
+ ...n.errorSourceMap,
586
+ [e]: "form"
587
+ }
588
+ }));
589
+ this.baseStore.setState((r) => ({
590
+ ...r,
591
+ errorMap: {
592
+ ...r.errorMap,
593
+ [e]: o
594
+ }
595
+ }));
596
+ } else
597
+ this.baseStore.setState((o) => ({
598
+ ...o,
599
+ errorMap: {
600
+ ...o.errorMap,
601
+ [e]: s
602
+ }
603
+ }));
604
+ });
605
+ });
606
+ }, this.getAllErrors = () => ({
607
+ form: {
608
+ errors: this.state.errors,
609
+ errorMap: this.state.errorMap
610
+ },
611
+ fields: Object.entries(this.state.fieldMeta).reduce(
612
+ (t, [i, s]) => (Object.keys(s).length && s.errors.length && (t[i] = {
613
+ errors: s.errors,
614
+ errorMap: s.errorMap
615
+ }), t),
616
+ {}
617
+ )
618
+ }), this.parseValuesWithSchema = (t) => U.validate(
619
+ { value: this.state.values, validationSource: "form" },
620
+ t
621
+ ), this.parseValuesWithSchemaAsync = (t) => U.validateAsync(
622
+ { value: this.state.values, validationSource: "form" },
623
+ t
624
+ ), this.timeoutIds = {
625
+ validations: {},
626
+ listeners: {},
627
+ formListeners: {}
628
+ }, this._formId = p?.formId ?? Z(), this._devtoolsSubmissionOverride = !1, this.baseStore = new G(
629
+ R({
630
+ ...p?.defaultState,
631
+ values: p?.defaultValues ?? p?.defaultState?.values
632
+ })
633
+ ), this.fieldMetaDerived = new N({
634
+ deps: [this.baseStore],
635
+ fn: ({ prevDepVals: t, currDepVals: i, prevVal: s }) => {
636
+ const e = s, o = t?.[0], a = i[0];
637
+ let r = 0;
638
+ const l = {};
639
+ for (const n of Object.keys(
640
+ a.fieldMetaBase
641
+ )) {
642
+ const d = a.fieldMetaBase[n], c = o?.fieldMetaBase[n], m = e?.[n], v = T(a.values, n);
643
+ let S = m?.errors;
644
+ if (!c || d.errorMap !== c.errorMap) {
645
+ S = Object.values(d.errorMap ?? {}).filter(
646
+ (b) => b !== void 0
647
+ );
648
+ const F = this.getFieldInfo(n)?.instance;
649
+ F && !F.options.disableErrorFlat && (S = S.flat(1));
650
+ }
651
+ const M = !x(S), h = !d.isDirty, V = w(
652
+ v,
653
+ T(this.options.defaultValues, n)
654
+ ) || w(
655
+ v,
656
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
657
+ this.getFieldInfo(n)?.instance?.options.defaultValue
658
+ );
659
+ if (m && m.isPristine === h && m.isValid === M && m.isDefaultValue === V && m.errors === S && d === c) {
660
+ l[n] = m, r++;
661
+ continue;
662
+ }
663
+ l[n] = {
664
+ ...d,
665
+ errors: S ?? [],
666
+ isPristine: h,
667
+ isValid: M,
668
+ isDefaultValue: V
669
+ };
670
+ }
671
+ return Object.keys(a.fieldMetaBase).length && e && r === Object.keys(a.fieldMetaBase).length ? e : l;
672
+ }
673
+ }), this.store = new N({
674
+ deps: [this.baseStore, this.fieldMetaDerived],
675
+ fn: ({ prevDepVals: t, currDepVals: i, prevVal: s }) => {
676
+ const e = s, o = t?.[0], a = i[0], r = i[1], l = Object.values(r).filter(
677
+ Boolean
678
+ ), n = l.some(
679
+ (u) => u.isValidating
680
+ ), d = l.every((u) => u.isValid), c = l.some((u) => u.isTouched), m = l.some((u) => u.isBlurred), v = l.every(
681
+ (u) => u.isDefaultValue
682
+ ), S = (
683
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
684
+ c && a.errorMap?.onMount
685
+ ), M = l.some((u) => u.isDirty), h = !M, V = !!// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
686
+ (a.errorMap?.onMount || // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
687
+ l.some((u) => u?.errorMap?.onMount)), F = !!n;
688
+ let b = e?.errors ?? [];
689
+ (!o || a.errorMap !== o.errorMap) && (b = Object.values(a.errorMap).reduce((u, E) => E === void 0 ? u : E && W(E) ? (u.push(E.form), u) : (u.push(E), u), []));
690
+ const g = b.length === 0, I = d && g, L = this.options.canSubmitWhenInvalid ?? !1, O = a.submissionAttempts === 0 && !c && !V || !F && !a.isSubmitting && I || L;
691
+ let D = a.errorMap;
692
+ if (S && (b = b.filter(
693
+ (u) => u !== a.errorMap.onMount
694
+ ), D = Object.assign(D, { onMount: void 0 })), e && o && e.errorMap === D && e.fieldMeta === this.fieldMetaDerived.state && e.errors === b && e.isFieldsValidating === n && e.isFieldsValid === d && e.isFormValid === g && e.isValid === I && e.canSubmit === O && e.isTouched === c && e.isBlurred === m && e.isPristine === h && e.isDefaultValue === v && e.isDirty === M && w(o, a))
695
+ return e;
696
+ let K = {
697
+ ...a,
698
+ errorMap: D,
699
+ fieldMeta: this.fieldMetaDerived.state,
700
+ errors: b,
701
+ isFieldsValidating: n,
702
+ isFieldsValid: d,
703
+ isFormValid: g,
704
+ isValid: I,
705
+ canSubmit: O,
706
+ isTouched: c,
707
+ isBlurred: m,
708
+ isPristine: h,
709
+ isDefaultValue: v,
710
+ isDirty: M
711
+ };
712
+ const C = this.options.transform?.deps ?? [];
713
+ if (C.length !== this.prevTransformArray.length || C.some((u, E) => u !== this.prevTransformArray[E])) {
714
+ const u = Object.assign({}, this, { state: K });
715
+ this.options.transform?.fn(u), K = u.state, this.prevTransformArray = C;
716
+ }
717
+ return K;
718
+ }
719
+ }), this.handleSubmit = this.handleSubmit.bind(this), this.update(p || {});
720
+ }
721
+ get state() {
722
+ return this.store.state;
723
+ }
724
+ get formId() {
725
+ return this._formId;
726
+ }
727
+ /**
728
+ * @private
729
+ */
730
+ runValidator(p) {
731
+ return tt(p.validate) ? U[p.type](
732
+ p.value,
733
+ p.validate
734
+ ) : p.validate(p.value);
735
+ }
736
+ handleSubmit(p) {
737
+ return this._handleSubmit(p);
738
+ }
739
+ }
740
+ function k(f) {
741
+ if (f) {
742
+ if (W(f)) {
743
+ const p = k(f.form).formError, t = f.fields;
744
+ return { formError: p, fieldErrors: t };
745
+ }
746
+ return { formError: f };
747
+ }
748
+ return { formError: void 0 };
749
+ }
750
+ function j(f) {
751
+ switch (f) {
752
+ case "submit":
753
+ return "onSubmit";
754
+ case "blur":
755
+ return "onBlur";
756
+ case "mount":
757
+ return "onMount";
758
+ case "server":
759
+ return "onServer";
760
+ case "dynamic":
761
+ return "onDynamic";
762
+ default:
763
+ return "onChange";
764
+ }
765
+ }
766
+ export {
767
+ ut as FormApi
768
+ };