@gsc-basic/components 1.0.1 → 1.0.3

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