@frollo/frollo-web-ui 7.0.0 → 8.0.0

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 (172) hide show
  1. package/cjs/index.js +34084 -33914
  2. package/esm/_rollupPluginBabelHelpers-DpC_oIQV.js +2566 -0
  3. package/esm/{check-94a5917a.js → check--YD4Ts6g.js} +4 -4
  4. package/esm/fw-accordion.js +27 -26
  5. package/esm/fw-animations.js +23 -26
  6. package/esm/fw-bar-chart.js +15289 -19
  7. package/esm/{fw-button-c8502414.js → fw-button-4QLZlu0U.js} +44 -44
  8. package/esm/fw-button.js +5 -10
  9. package/esm/{fw-card-1b6a67fe.js → fw-card-bsYbpPmW.js} +12 -12
  10. package/esm/fw-card.js +1 -1
  11. package/esm/fw-checkbox.js +23 -32
  12. package/esm/fw-date-picker.js +143 -80
  13. package/esm/fw-drawer.js +33 -36
  14. package/esm/fw-dropdown-nLtzu2fS.js +277 -0
  15. package/esm/fw-dropdown.js +7 -15
  16. package/esm/fw-form.js +1 -1
  17. package/esm/fw-image-DOgM8i8X.js +200 -0
  18. package/esm/fw-image.js +5 -21
  19. package/esm/{fw-input-8969b226.js → fw-input-Qiy53nRk.js} +61 -53
  20. package/esm/fw-input.js +6 -19
  21. package/esm/fw-loading-bar-DThRjdw1.js +22 -0
  22. package/esm/{fw-loading-spinner-72d70258.js → fw-loading-spinner-Dn52RI5h.js} +1 -1
  23. package/esm/fw-loading.js +3 -7
  24. package/esm/fw-modal.js +79 -53
  25. package/esm/fw-navigation-menu.js +15 -20
  26. package/esm/fw-popover.js +39 -375
  27. package/esm/fw-progress-bar.js +8 -11
  28. package/esm/fw-provider-list.js +41 -84
  29. package/esm/fw-sidebar-menu.js +33 -24
  30. package/esm/{fw-table-row-23f78218.js → fw-table-row-DkZaaMmE.js} +15 -301
  31. package/esm/fw-table.js +6 -16
  32. package/esm/fw-tabs.js +21 -103
  33. package/esm/{fw-tag-ac28200a.js → fw-tag-CPp1P480.js} +29 -20
  34. package/esm/fw-tag.js +7 -12
  35. package/esm/fw-toast.js +22 -37
  36. package/esm/fw-transactions-card.js +14 -30
  37. package/esm/index-CUPvK0Aa.js +586 -0
  38. package/esm/index.js +66 -228
  39. package/esm/vee-validate.esm-3ptvCDR1.js +4071 -0
  40. package/frollo-web-ui.esm.js +34091 -34339
  41. package/icons/chart-line-up.svg +3 -0
  42. package/icons/icons.stories.ts +24 -29
  43. package/icons/index.ts +5 -1
  44. package/icons/sack-dollar.svg +3 -0
  45. package/icons/xmark.svg +2 -2
  46. package/index.d.ts +2789 -2573
  47. package/package.json +75 -73
  48. package/styles/tailwind.scss +6 -0
  49. package/types/components/fw-accordion/fw-accordion.vue.d.ts +128 -128
  50. package/types/components/fw-accordion/index.d.ts +2 -2
  51. package/types/components/fw-accordion/index.types.d.ts +10 -10
  52. package/types/components/fw-animations/fw-email-pulse.vue.d.ts +24 -24
  53. package/types/components/fw-animations/fw-loading-spinner.vue.d.ts +2 -2
  54. package/types/components/fw-animations/fw-success-pulse.vue.d.ts +24 -24
  55. package/types/components/fw-animations/index.d.ts +4 -4
  56. package/types/components/fw-bar-chart/fw-bar-chart.vue.d.ts +83 -83
  57. package/types/components/fw-bar-chart/index.d.ts +2 -2
  58. package/types/components/fw-bar-chart/index.types.d.ts +11 -11
  59. package/types/components/fw-button/fw-button.vue.d.ts +190 -176
  60. package/types/components/fw-button/index.d.ts +2 -2
  61. package/types/components/fw-button/index.types.d.ts +27 -26
  62. package/types/components/fw-card/fw-card.vue.d.ts +82 -82
  63. package/types/components/fw-card/index.d.ts +2 -2
  64. package/types/components/fw-card/index.types.d.ts +8 -8
  65. package/types/components/fw-checkbox/fw-checkbox.vue.d.ts +108 -108
  66. package/types/components/fw-checkbox/index.d.ts +2 -2
  67. package/types/components/fw-checkbox/index.types.d.ts +9 -9
  68. package/types/components/fw-date-picker/fw-date-picker.vue.d.ts +249 -177
  69. package/types/components/fw-date-picker/index.d.ts +2 -2
  70. package/types/components/fw-date-picker/index.types.d.ts +21 -16
  71. package/types/components/fw-drawer/fw-drawer.vue.d.ts +165 -165
  72. package/types/components/fw-drawer/index.d.ts +2 -2
  73. package/types/components/fw-drawer/index.types.d.ts +13 -13
  74. package/types/components/fw-dropdown/fw-dropdown.vue.d.ts +154 -130
  75. package/types/components/fw-dropdown/index.d.ts +2 -2
  76. package/types/components/fw-dropdown/index.types.d.ts +16 -13
  77. package/types/components/fw-form/index.d.ts +2 -2
  78. package/types/components/fw-image/fw-image.vue.d.ts +103 -84
  79. package/types/components/fw-image/index.d.ts +2 -2
  80. package/types/components/fw-image/index.types.d.ts +9 -8
  81. package/types/components/fw-input/fw-input.vue.d.ts +214 -197
  82. package/types/components/fw-input/index.d.ts +2 -2
  83. package/types/components/fw-input/index.types.d.ts +18 -16
  84. package/types/components/fw-loading/fw-loading-bar.vue.d.ts +2 -2
  85. package/types/components/fw-loading/fw-loading-card.vue.d.ts +2 -2
  86. package/types/components/fw-loading/fw-loading-table.vue.d.ts +25 -25
  87. package/types/components/fw-loading/index.d.ts +4 -4
  88. package/types/components/fw-modal/fw-modal.vue.d.ts +205 -175
  89. package/types/components/fw-modal/index.d.ts +2 -2
  90. package/types/components/fw-modal/index.types.d.ts +16 -14
  91. package/types/components/fw-navigation-menu/fw-navigation-menu.vue.d.ts +57 -57
  92. package/types/components/fw-navigation-menu/index.d.ts +2 -2
  93. package/types/components/fw-navigation-menu/index.types.d.ts +7 -7
  94. package/types/components/fw-popover/fw-popover.vue.d.ts +157 -157
  95. package/types/components/fw-popover/index.d.ts +2 -2
  96. package/types/components/fw-popover/index.types.d.ts +11 -11
  97. package/types/components/fw-progress-bar/fw-progress-bar.vue.d.ts +52 -52
  98. package/types/components/fw-progress-bar/index.d.ts +2 -2
  99. package/types/components/fw-progress-bar/index.types.d.ts +5 -5
  100. package/types/components/fw-provider-list/fw-provider-list.vue.d.ts +100 -100
  101. package/types/components/fw-provider-list/index.d.ts +2 -2
  102. package/types/components/fw-provider-list/index.types.d.ts +11 -11
  103. package/types/components/fw-sidebar-menu/fw-sidebar-menu.vue.d.ts +88 -72
  104. package/types/components/fw-sidebar-menu/index.d.ts +2 -2
  105. package/types/components/fw-sidebar-menu/index.types.d.ts +9 -8
  106. package/types/components/fw-table/fw-table-head.vue.d.ts +2 -2
  107. package/types/components/fw-table/fw-table-row.vue.d.ts +2 -2
  108. package/types/components/fw-table/fw-table.vue.d.ts +71 -71
  109. package/types/components/fw-table/index.d.ts +4 -4
  110. package/types/components/fw-table/index.types.d.ts +16 -16
  111. package/types/components/fw-tabs/fw-tab.vue.d.ts +24 -32
  112. package/types/components/fw-tabs/fw-tabs.vue.d.ts +24 -24
  113. package/types/components/fw-tabs/index.d.ts +3 -3
  114. package/types/components/fw-tabs/index.types.d.ts +8 -0
  115. package/types/components/fw-tag/fw-tag.vue.d.ts +80 -70
  116. package/types/components/fw-tag/index.d.ts +2 -2
  117. package/types/components/fw-tag/index.types.d.ts +18 -18
  118. package/types/components/fw-toast/fw-toast.vue.d.ts +121 -121
  119. package/types/components/fw-toast/index.d.ts +2 -2
  120. package/types/components/fw-toast/index.types.d.ts +13 -13
  121. package/types/components/fw-transactions-card/fw-transactions-card.vue.d.ts +58 -58
  122. package/types/components/fw-transactions-card/index.d.ts +2 -2
  123. package/types/components/fw-transactions-card/index.types.d.ts +6 -6
  124. package/types/components/index.d.ts +24 -24
  125. package/types/components/index.types.d.ts +21 -20
  126. package/types/directives/index.d.ts +2 -2
  127. package/types/directives/lazy-loader.d.ts +3 -3
  128. package/types/helpers/get-root-colours.d.ts +17 -17
  129. package/types/icons/index.d.ts +43 -41
  130. package/types/index-types.esm.d.ts +6 -6
  131. package/types/index.browser-umd.d.ts +2 -1
  132. package/types/index.d.ts +3 -3
  133. package/types/index.esm.d.ts +5 -5
  134. package/types/services/index.d.ts +2 -2
  135. package/types/services/modal.d.ts +9 -9
  136. package/types/services/toast.d.ts +9 -9
  137. package/web-components/index.js +19670 -19722
  138. package/esm/add-to-unscopables-ee05b58f.js +0 -25
  139. package/esm/array-iteration-8267bf22.js +0 -92
  140. package/esm/array-method-has-species-support-6c675094.js +0 -23
  141. package/esm/array-method-is-strict-d313436f.js +0 -14
  142. package/esm/array-species-create-1c67e297.js +0 -97
  143. package/esm/classof-d44bf093.js +0 -42
  144. package/esm/create-property-eb329361.js +0 -14
  145. package/esm/defineProperty-b85f2e0f.js +0 -42
  146. package/esm/does-not-exceed-safe-integer-de37ce28.js +0 -11
  147. package/esm/es.array.concat-99b85557.js +0 -69
  148. package/esm/es.array.find-1ded15d5.js +0 -28
  149. package/esm/es.array.includes-08e25019.js +0 -27
  150. package/esm/es.array.map-c56ebffd.js +0 -22
  151. package/esm/es.date.to-string-15eb9936.js +0 -23
  152. package/esm/es.function.name-6cafd747.js +0 -29
  153. package/esm/es.number.constructor-fb16fe05.js +0 -204
  154. package/esm/es.object.to-string-4b07c4d1.js +0 -24
  155. package/esm/es.string.includes-061e8272.js +0 -66
  156. package/esm/es.string.iterator-25db8cd2.js +0 -469
  157. package/esm/export-10c4adbc.js +0 -95
  158. package/esm/function-apply-e17cf65b.js +0 -14
  159. package/esm/fw-dropdown-6856e66e.js +0 -224
  160. package/esm/fw-image-aca2c61d.js +0 -296
  161. package/esm/fw-loading-bar-f5ca605c.js +0 -22
  162. package/esm/index-6758f755.js +0 -15797
  163. package/esm/index-bced3b35.js +0 -560
  164. package/esm/is-forced-7cb3ee8f.js +0 -927
  165. package/esm/object-create-51bf02dc.js +0 -125
  166. package/esm/regexp-flags-c09864e5.js +0 -50
  167. package/esm/vee-validate.esm-a17a23c3.js +0 -3192
  168. package/esm/web.timers-e406c8e6.js +0 -72
  169. /package/esm/{get-root-colours-865a52ba.js → get-root-colours-DYEoJPEb.js} +0 -0
  170. /package/esm/{index-0c5cae4f.js → index-BVcOAKar.js} +0 -0
  171. /package/esm/{style-inject.es-1f59c1d0.js → style-inject.es-tgCJW-Cu.js} +0 -0
  172. /package/esm/{uniqueId-fe08534a.js → uniqueId-DK6xzFd8.js} +0 -0
@@ -0,0 +1,4071 @@
1
+ import { getCurrentInstance, inject, warn as warn$1, ref, watch, computed, toValue, nextTick, unref, isRef, reactive, onUnmounted, onMounted, provide, onBeforeUnmount, defineComponent, toRef, resolveDynamicComponent, h, shallowRef, readonly, watchEffect } from 'vue';
2
+
3
+ function getDevtoolsGlobalHook() {
4
+ return getTarget().__VUE_DEVTOOLS_GLOBAL_HOOK__;
5
+ }
6
+ function getTarget() {
7
+ // @ts-expect-error navigator and windows are not available in all environments
8
+ return (typeof navigator !== 'undefined' && typeof window !== 'undefined')
9
+ ? window
10
+ : typeof globalThis !== 'undefined'
11
+ ? globalThis
12
+ : {};
13
+ }
14
+ const isProxyAvailable = typeof Proxy === 'function';
15
+
16
+ const HOOK_SETUP = 'devtools-plugin:setup';
17
+ const HOOK_PLUGIN_SETTINGS_SET = 'plugin:settings:set';
18
+
19
+ let supported;
20
+ let perf;
21
+ function isPerformanceSupported() {
22
+ var _a;
23
+ if (supported !== undefined) {
24
+ return supported;
25
+ }
26
+ if (typeof window !== 'undefined' && window.performance) {
27
+ supported = true;
28
+ perf = window.performance;
29
+ }
30
+ else if (typeof globalThis !== 'undefined' && ((_a = globalThis.perf_hooks) === null || _a === void 0 ? void 0 : _a.performance)) {
31
+ supported = true;
32
+ perf = globalThis.perf_hooks.performance;
33
+ }
34
+ else {
35
+ supported = false;
36
+ }
37
+ return supported;
38
+ }
39
+ function now() {
40
+ return isPerformanceSupported() ? perf.now() : Date.now();
41
+ }
42
+
43
+ class ApiProxy {
44
+ constructor(plugin, hook) {
45
+ this.target = null;
46
+ this.targetQueue = [];
47
+ this.onQueue = [];
48
+ this.plugin = plugin;
49
+ this.hook = hook;
50
+ const defaultSettings = {};
51
+ if (plugin.settings) {
52
+ for (const id in plugin.settings) {
53
+ const item = plugin.settings[id];
54
+ defaultSettings[id] = item.defaultValue;
55
+ }
56
+ }
57
+ const localSettingsSaveId = `__vue-devtools-plugin-settings__${plugin.id}`;
58
+ let currentSettings = Object.assign({}, defaultSettings);
59
+ try {
60
+ const raw = localStorage.getItem(localSettingsSaveId);
61
+ const data = JSON.parse(raw);
62
+ Object.assign(currentSettings, data);
63
+ }
64
+ catch (e) {
65
+ // noop
66
+ }
67
+ this.fallbacks = {
68
+ getSettings() {
69
+ return currentSettings;
70
+ },
71
+ setSettings(value) {
72
+ try {
73
+ localStorage.setItem(localSettingsSaveId, JSON.stringify(value));
74
+ }
75
+ catch (e) {
76
+ // noop
77
+ }
78
+ currentSettings = value;
79
+ },
80
+ now() {
81
+ return now();
82
+ },
83
+ };
84
+ if (hook) {
85
+ hook.on(HOOK_PLUGIN_SETTINGS_SET, (pluginId, value) => {
86
+ if (pluginId === this.plugin.id) {
87
+ this.fallbacks.setSettings(value);
88
+ }
89
+ });
90
+ }
91
+ this.proxiedOn = new Proxy({}, {
92
+ get: (_target, prop) => {
93
+ if (this.target) {
94
+ return this.target.on[prop];
95
+ }
96
+ else {
97
+ return (...args) => {
98
+ this.onQueue.push({
99
+ method: prop,
100
+ args,
101
+ });
102
+ };
103
+ }
104
+ },
105
+ });
106
+ this.proxiedTarget = new Proxy({}, {
107
+ get: (_target, prop) => {
108
+ if (this.target) {
109
+ return this.target[prop];
110
+ }
111
+ else if (prop === 'on') {
112
+ return this.proxiedOn;
113
+ }
114
+ else if (Object.keys(this.fallbacks).includes(prop)) {
115
+ return (...args) => {
116
+ this.targetQueue.push({
117
+ method: prop,
118
+ args,
119
+ resolve: () => { },
120
+ });
121
+ return this.fallbacks[prop](...args);
122
+ };
123
+ }
124
+ else {
125
+ return (...args) => {
126
+ return new Promise((resolve) => {
127
+ this.targetQueue.push({
128
+ method: prop,
129
+ args,
130
+ resolve,
131
+ });
132
+ });
133
+ };
134
+ }
135
+ },
136
+ });
137
+ }
138
+ async setRealTarget(target) {
139
+ this.target = target;
140
+ for (const item of this.onQueue) {
141
+ this.target.on[item.method](...item.args);
142
+ }
143
+ for (const item of this.targetQueue) {
144
+ item.resolve(await this.target[item.method](...item.args));
145
+ }
146
+ }
147
+ }
148
+
149
+ function setupDevtoolsPlugin(pluginDescriptor, setupFn) {
150
+ const descriptor = pluginDescriptor;
151
+ const target = getTarget();
152
+ const hook = getDevtoolsGlobalHook();
153
+ const enableProxy = isProxyAvailable && descriptor.enableEarlyProxy;
154
+ if (hook && (target.__VUE_DEVTOOLS_PLUGIN_API_AVAILABLE__ || !enableProxy)) {
155
+ hook.emit(HOOK_SETUP, pluginDescriptor, setupFn);
156
+ }
157
+ else {
158
+ const proxy = enableProxy ? new ApiProxy(descriptor, hook) : null;
159
+ const list = target.__VUE_DEVTOOLS_PLUGINS__ = target.__VUE_DEVTOOLS_PLUGINS__ || [];
160
+ list.push({
161
+ pluginDescriptor: descriptor,
162
+ setupFn,
163
+ proxy,
164
+ });
165
+ if (proxy) {
166
+ setupFn(proxy.proxiedTarget);
167
+ }
168
+ }
169
+ }
170
+
171
+ /**
172
+ * vee-validate v4.13.1
173
+ * (c) 2024 Abdelrahman Awad
174
+ * @license MIT
175
+ */
176
+
177
+ function isCallable(fn) {
178
+ return typeof fn === 'function';
179
+ }
180
+ function isNullOrUndefined(value) {
181
+ return value === null || value === undefined;
182
+ }
183
+ const isObject = (obj) => obj !== null && !!obj && typeof obj === 'object' && !Array.isArray(obj);
184
+ function isIndex(value) {
185
+ return Number(value) >= 0;
186
+ }
187
+ function toNumber(value) {
188
+ const n = parseFloat(value);
189
+ return isNaN(n) ? value : n;
190
+ }
191
+ function isObjectLike(value) {
192
+ return typeof value === 'object' && value !== null;
193
+ }
194
+ function getTag(value) {
195
+ if (value == null) {
196
+ return value === undefined ? '[object Undefined]' : '[object Null]';
197
+ }
198
+ return Object.prototype.toString.call(value);
199
+ }
200
+ // Reference: https://github.com/lodash/lodash/blob/master/isPlainObject.js
201
+ function isPlainObject(value) {
202
+ if (!isObjectLike(value) || getTag(value) !== '[object Object]') {
203
+ return false;
204
+ }
205
+ if (Object.getPrototypeOf(value) === null) {
206
+ return true;
207
+ }
208
+ let proto = value;
209
+ while (Object.getPrototypeOf(proto) !== null) {
210
+ proto = Object.getPrototypeOf(proto);
211
+ }
212
+ return Object.getPrototypeOf(value) === proto;
213
+ }
214
+ function merge(target, source) {
215
+ Object.keys(source).forEach(key => {
216
+ if (isPlainObject(source[key]) && isPlainObject(target[key])) {
217
+ if (!target[key]) {
218
+ target[key] = {};
219
+ }
220
+ merge(target[key], source[key]);
221
+ return;
222
+ }
223
+ target[key] = source[key];
224
+ });
225
+ return target;
226
+ }
227
+ /**
228
+ * Constructs a path with dot paths for arrays to use brackets to be compatible with vee-validate path syntax
229
+ */
230
+ function normalizeFormPath(path) {
231
+ const pathArr = path.split('.');
232
+ if (!pathArr.length) {
233
+ return '';
234
+ }
235
+ let fullPath = String(pathArr[0]);
236
+ for (let i = 1; i < pathArr.length; i++) {
237
+ if (isIndex(pathArr[i])) {
238
+ fullPath += `[${pathArr[i]}]`;
239
+ continue;
240
+ }
241
+ fullPath += `.${pathArr[i]}`;
242
+ }
243
+ return fullPath;
244
+ }
245
+
246
+ const RULES = {};
247
+ /**
248
+ * Adds a custom validator to the list of validation rules.
249
+ */
250
+ function defineRule(id, validator) {
251
+ // makes sure new rules are properly formatted.
252
+ guardExtend(id, validator);
253
+ RULES[id] = validator;
254
+ }
255
+ /**
256
+ * Gets an already defined rule
257
+ */
258
+ function resolveRule(id) {
259
+ return RULES[id];
260
+ }
261
+ /**
262
+ * Guards from extension violations.
263
+ */
264
+ function guardExtend(id, validator) {
265
+ if (isCallable(validator)) {
266
+ return;
267
+ }
268
+ throw new Error(`Extension Error: The validator '${id}' must be a function.`);
269
+ }
270
+
271
+ function set(obj, key, val) {
272
+ if (typeof val.value === 'object') val.value = klona(val.value);
273
+ if (!val.enumerable || val.get || val.set || !val.configurable || !val.writable || key === '__proto__') {
274
+ Object.defineProperty(obj, key, val);
275
+ } else obj[key] = val.value;
276
+ }
277
+
278
+ function klona(x) {
279
+ if (typeof x !== 'object') return x;
280
+
281
+ var i=0, k, list, tmp, str=Object.prototype.toString.call(x);
282
+
283
+ if (str === '[object Object]') {
284
+ tmp = Object.create(x.__proto__ || null);
285
+ } else if (str === '[object Array]') {
286
+ tmp = Array(x.length);
287
+ } else if (str === '[object Set]') {
288
+ tmp = new Set;
289
+ x.forEach(function (val) {
290
+ tmp.add(klona(val));
291
+ });
292
+ } else if (str === '[object Map]') {
293
+ tmp = new Map;
294
+ x.forEach(function (val, key) {
295
+ tmp.set(klona(key), klona(val));
296
+ });
297
+ } else if (str === '[object Date]') {
298
+ tmp = new Date(+x);
299
+ } else if (str === '[object RegExp]') {
300
+ tmp = new RegExp(x.source, x.flags);
301
+ } else if (str === '[object DataView]') {
302
+ tmp = new x.constructor( klona(x.buffer) );
303
+ } else if (str === '[object ArrayBuffer]') {
304
+ tmp = x.slice(0);
305
+ } else if (str.slice(-6) === 'Array]') {
306
+ // ArrayBuffer.isView(x)
307
+ // ~> `new` bcuz `Buffer.slice` => ref
308
+ tmp = new x.constructor(x);
309
+ }
310
+
311
+ if (tmp) {
312
+ for (list=Object.getOwnPropertySymbols(x); i < list.length; i++) {
313
+ set(tmp, list[i], Object.getOwnPropertyDescriptor(x, list[i]));
314
+ }
315
+
316
+ for (i=0, list=Object.getOwnPropertyNames(x); i < list.length; i++) {
317
+ if (Object.hasOwnProperty.call(tmp, k=list[i]) && tmp[k] === x[k]) continue;
318
+ set(tmp, k, Object.getOwnPropertyDescriptor(x, k));
319
+ }
320
+ }
321
+
322
+ return tmp || x;
323
+ }
324
+
325
+ const FormContextKey = Symbol('vee-validate-form');
326
+ const FieldContextKey = Symbol('vee-validate-field-instance');
327
+ const IS_ABSENT = Symbol('Default empty value');
328
+
329
+ const isClient = typeof window !== 'undefined';
330
+ function isLocator(value) {
331
+ return isCallable(value) && !!value.__locatorRef;
332
+ }
333
+ function isTypedSchema(value) {
334
+ return !!value && isCallable(value.parse) && value.__type === 'VVTypedSchema';
335
+ }
336
+ function isYupValidator(value) {
337
+ return !!value && isCallable(value.validate);
338
+ }
339
+ function hasCheckedAttr(type) {
340
+ return type === 'checkbox' || type === 'radio';
341
+ }
342
+ function isContainerValue(value) {
343
+ return isObject(value) || Array.isArray(value);
344
+ }
345
+ /**
346
+ * True if the value is an empty object or array
347
+ */
348
+ function isEmptyContainer(value) {
349
+ if (Array.isArray(value)) {
350
+ return value.length === 0;
351
+ }
352
+ return isObject(value) && Object.keys(value).length === 0;
353
+ }
354
+ /**
355
+ * Checks if the path opted out of nested fields using `[fieldName]` syntax
356
+ */
357
+ function isNotNestedPath(path) {
358
+ return /^\[.+\]$/i.test(path);
359
+ }
360
+ /**
361
+ * Checks if an element is a native HTML5 multi-select input element
362
+ */
363
+ function isNativeMultiSelect(el) {
364
+ return isNativeSelect(el) && el.multiple;
365
+ }
366
+ /**
367
+ * Checks if an element is a native HTML5 select input element
368
+ */
369
+ function isNativeSelect(el) {
370
+ return el.tagName === 'SELECT';
371
+ }
372
+ /**
373
+ * Checks if a tag name with attrs object will render a native multi-select element
374
+ */
375
+ function isNativeMultiSelectNode(tag, attrs) {
376
+ // The falsy value array is the values that Vue won't add the `multiple` prop if it has one of these values
377
+ const hasTruthyBindingValue = ![false, null, undefined, 0].includes(attrs.multiple) && !Number.isNaN(attrs.multiple);
378
+ return tag === 'select' && 'multiple' in attrs && hasTruthyBindingValue;
379
+ }
380
+ /**
381
+ * Checks if a node should have a `:value` binding or not
382
+ *
383
+ * These nodes should not have a value binding
384
+ * For files, because they are not reactive
385
+ * For multi-selects because the value binding will reset the value
386
+ */
387
+ function shouldHaveValueBinding(tag, attrs) {
388
+ return !isNativeMultiSelectNode(tag, attrs) && attrs.type !== 'file' && !hasCheckedAttr(attrs.type);
389
+ }
390
+ function isFormSubmitEvent(evt) {
391
+ return isEvent(evt) && evt.target && 'submit' in evt.target;
392
+ }
393
+ function isEvent(evt) {
394
+ if (!evt) {
395
+ return false;
396
+ }
397
+ if (typeof Event !== 'undefined' && isCallable(Event) && evt instanceof Event) {
398
+ return true;
399
+ }
400
+ // this is for IE and Cypress #3161
401
+ /* istanbul ignore next */
402
+ if (evt && evt.srcElement) {
403
+ return true;
404
+ }
405
+ return false;
406
+ }
407
+ function isPropPresent(obj, prop) {
408
+ return prop in obj && obj[prop] !== IS_ABSENT;
409
+ }
410
+ /**
411
+ * Compares if two values are the same borrowed from:
412
+ * https://github.com/epoberezkin/fast-deep-equal
413
+ * We added a case for file matching since `Object.keys` doesn't work with Files.
414
+ * */
415
+ function isEqual(a, b) {
416
+ if (a === b)
417
+ return true;
418
+ if (a && b && typeof a === 'object' && typeof b === 'object') {
419
+ if (a.constructor !== b.constructor)
420
+ return false;
421
+ // eslint-disable-next-line no-var
422
+ var length, i, keys;
423
+ if (Array.isArray(a)) {
424
+ length = a.length;
425
+ if (length != b.length)
426
+ return false;
427
+ for (i = length; i-- !== 0;)
428
+ if (!isEqual(a[i], b[i]))
429
+ return false;
430
+ return true;
431
+ }
432
+ if (a instanceof Map && b instanceof Map) {
433
+ if (a.size !== b.size)
434
+ return false;
435
+ for (i of a.entries())
436
+ if (!b.has(i[0]))
437
+ return false;
438
+ for (i of a.entries())
439
+ if (!isEqual(i[1], b.get(i[0])))
440
+ return false;
441
+ return true;
442
+ }
443
+ // We added this part for file comparison, arguably a little naive but should work for most cases.
444
+ // #3911
445
+ if (isFile(a) && isFile(b)) {
446
+ if (a.size !== b.size)
447
+ return false;
448
+ if (a.name !== b.name)
449
+ return false;
450
+ if (a.lastModified !== b.lastModified)
451
+ return false;
452
+ if (a.type !== b.type)
453
+ return false;
454
+ return true;
455
+ }
456
+ if (a instanceof Set && b instanceof Set) {
457
+ if (a.size !== b.size)
458
+ return false;
459
+ for (i of a.entries())
460
+ if (!b.has(i[0]))
461
+ return false;
462
+ return true;
463
+ }
464
+ if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
465
+ length = a.length;
466
+ if (length != b.length)
467
+ return false;
468
+ for (i = length; i-- !== 0;)
469
+ if (a[i] !== b[i])
470
+ return false;
471
+ return true;
472
+ }
473
+ if (a.constructor === RegExp)
474
+ return a.source === b.source && a.flags === b.flags;
475
+ if (a.valueOf !== Object.prototype.valueOf)
476
+ return a.valueOf() === b.valueOf();
477
+ if (a.toString !== Object.prototype.toString)
478
+ return a.toString() === b.toString();
479
+ keys = Object.keys(a);
480
+ length = keys.length;
481
+ for (i = length; i-- !== 0;) {
482
+ // eslint-disable-next-line no-var
483
+ var key = keys[i];
484
+ if (!isEqual(a[key], b[key]))
485
+ return false;
486
+ }
487
+ return true;
488
+ }
489
+ // true if both NaN, false otherwise
490
+ return a !== a && b !== b;
491
+ }
492
+ function isFile(a) {
493
+ if (!isClient) {
494
+ return false;
495
+ }
496
+ return a instanceof File;
497
+ }
498
+
499
+ function cleanupNonNestedPath(path) {
500
+ if (isNotNestedPath(path)) {
501
+ return path.replace(/\[|\]/gi, '');
502
+ }
503
+ return path;
504
+ }
505
+ function getFromPath(object, path, fallback) {
506
+ if (!object) {
507
+ return fallback;
508
+ }
509
+ if (isNotNestedPath(path)) {
510
+ return object[cleanupNonNestedPath(path)];
511
+ }
512
+ const resolvedValue = (path || '')
513
+ .split(/\.|\[(\d+)\]/)
514
+ .filter(Boolean)
515
+ .reduce((acc, propKey) => {
516
+ if (isContainerValue(acc) && propKey in acc) {
517
+ return acc[propKey];
518
+ }
519
+ return fallback;
520
+ }, object);
521
+ return resolvedValue;
522
+ }
523
+ /**
524
+ * Sets a nested property value in a path, creates the path properties if it doesn't exist
525
+ */
526
+ function setInPath(object, path, value) {
527
+ if (isNotNestedPath(path)) {
528
+ object[cleanupNonNestedPath(path)] = value;
529
+ return;
530
+ }
531
+ const keys = path.split(/\.|\[(\d+)\]/).filter(Boolean);
532
+ let acc = object;
533
+ for (let i = 0; i < keys.length; i++) {
534
+ // Last key, set it
535
+ if (i === keys.length - 1) {
536
+ acc[keys[i]] = value;
537
+ return;
538
+ }
539
+ // Key does not exist, create a container for it
540
+ if (!(keys[i] in acc) || isNullOrUndefined(acc[keys[i]])) {
541
+ // container can be either an object or an array depending on the next key if it exists
542
+ acc[keys[i]] = isIndex(keys[i + 1]) ? [] : {};
543
+ }
544
+ acc = acc[keys[i]];
545
+ }
546
+ }
547
+ function unset(object, key) {
548
+ if (Array.isArray(object) && isIndex(key)) {
549
+ object.splice(Number(key), 1);
550
+ return;
551
+ }
552
+ if (isObject(object)) {
553
+ delete object[key];
554
+ }
555
+ }
556
+ /**
557
+ * Removes a nested property from object
558
+ */
559
+ function unsetPath(object, path) {
560
+ if (isNotNestedPath(path)) {
561
+ delete object[cleanupNonNestedPath(path)];
562
+ return;
563
+ }
564
+ const keys = path.split(/\.|\[(\d+)\]/).filter(Boolean);
565
+ let acc = object;
566
+ for (let i = 0; i < keys.length; i++) {
567
+ // Last key, unset it
568
+ if (i === keys.length - 1) {
569
+ unset(acc, keys[i]);
570
+ break;
571
+ }
572
+ // Key does not exist, exit
573
+ if (!(keys[i] in acc) || isNullOrUndefined(acc[keys[i]])) {
574
+ break;
575
+ }
576
+ acc = acc[keys[i]];
577
+ }
578
+ const pathValues = keys.map((_, idx) => {
579
+ return getFromPath(object, keys.slice(0, idx).join('.'));
580
+ });
581
+ for (let i = pathValues.length - 1; i >= 0; i--) {
582
+ if (!isEmptyContainer(pathValues[i])) {
583
+ continue;
584
+ }
585
+ if (i === 0) {
586
+ unset(object, keys[0]);
587
+ continue;
588
+ }
589
+ unset(pathValues[i - 1], keys[i - 1]);
590
+ }
591
+ }
592
+ /**
593
+ * A typed version of Object.keys
594
+ */
595
+ function keysOf(record) {
596
+ return Object.keys(record);
597
+ }
598
+ // Uses same component provide as its own injections
599
+ // Due to changes in https://github.com/vuejs/vue-next/pull/2424
600
+ function injectWithSelf(symbol, def = undefined) {
601
+ const vm = getCurrentInstance();
602
+ return (vm === null || vm === void 0 ? void 0 : vm.provides[symbol]) || inject(symbol, def);
603
+ }
604
+ function warn(message) {
605
+ warn$1(`[vee-validate]: ${message}`);
606
+ }
607
+ function resolveNextCheckboxValue(currentValue, checkedValue, uncheckedValue) {
608
+ if (Array.isArray(currentValue)) {
609
+ const newVal = [...currentValue];
610
+ // Use isEqual since checked object values can possibly fail the equality check #3883
611
+ const idx = newVal.findIndex(v => isEqual(v, checkedValue));
612
+ idx >= 0 ? newVal.splice(idx, 1) : newVal.push(checkedValue);
613
+ return newVal;
614
+ }
615
+ return isEqual(currentValue, checkedValue) ? uncheckedValue : checkedValue;
616
+ }
617
+ /**
618
+ * Creates a throttled function that only invokes the provided function (`func`) at most once per within a given number of milliseconds
619
+ * (`limit`)
620
+ */
621
+ function throttle(func, limit) {
622
+ let inThrottle;
623
+ let lastResult;
624
+ return function (...args) {
625
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
626
+ const context = this;
627
+ if (!inThrottle) {
628
+ inThrottle = true;
629
+ setTimeout(() => (inThrottle = false), limit);
630
+ lastResult = func.apply(context, args);
631
+ }
632
+ return lastResult;
633
+ };
634
+ }
635
+ function debounceAsync(inner, ms = 0) {
636
+ let timer = null;
637
+ let resolves = [];
638
+ return function (...args) {
639
+ // Run the function after a certain amount of time
640
+ if (timer) {
641
+ clearTimeout(timer);
642
+ }
643
+ // @ts-expect-error timer is a number
644
+ timer = setTimeout(() => {
645
+ // Get the result of the inner function, then apply it to the resolve function of
646
+ // each promise that has been created since the last time the inner function was run
647
+ const result = inner(...args);
648
+ resolves.forEach(r => r(result));
649
+ resolves = [];
650
+ }, ms);
651
+ return new Promise(resolve => resolves.push(resolve));
652
+ };
653
+ }
654
+ function applyModelModifiers(value, modifiers) {
655
+ if (!isObject(modifiers)) {
656
+ return value;
657
+ }
658
+ if (modifiers.number) {
659
+ return toNumber(value);
660
+ }
661
+ return value;
662
+ }
663
+ function withLatest(fn, onDone) {
664
+ let latestRun;
665
+ return async function runLatest(...args) {
666
+ const pending = fn(...args);
667
+ latestRun = pending;
668
+ const result = await pending;
669
+ if (pending !== latestRun) {
670
+ return result;
671
+ }
672
+ latestRun = undefined;
673
+ return onDone(result, args);
674
+ };
675
+ }
676
+ function computedDeep({ get, set }) {
677
+ const baseRef = ref(klona(get()));
678
+ watch(get, newValue => {
679
+ if (isEqual(newValue, baseRef.value)) {
680
+ return;
681
+ }
682
+ baseRef.value = klona(newValue);
683
+ }, {
684
+ deep: true,
685
+ });
686
+ watch(baseRef, newValue => {
687
+ if (isEqual(newValue, get())) {
688
+ return;
689
+ }
690
+ set(klona(newValue));
691
+ }, {
692
+ deep: true,
693
+ });
694
+ return baseRef;
695
+ }
696
+ function normalizeErrorItem(message) {
697
+ return Array.isArray(message) ? message : message ? [message] : [];
698
+ }
699
+ function resolveFieldOrPathState(path) {
700
+ const form = injectWithSelf(FormContextKey);
701
+ const state = path ? computed(() => form === null || form === void 0 ? void 0 : form.getPathState(toValue(path))) : undefined;
702
+ const field = path ? undefined : inject(FieldContextKey);
703
+ if (!field && !(state === null || state === void 0 ? void 0 : state.value)) {
704
+ if (("production" !== 'production')) {
705
+ warn(`field with name ${toValue(path)} was not found`);
706
+ }
707
+ }
708
+ return state || field;
709
+ }
710
+ function omit(obj, keys) {
711
+ const target = {};
712
+ for (const key in obj) {
713
+ if (!keys.includes(key)) {
714
+ target[key] = obj[key];
715
+ }
716
+ }
717
+ return target;
718
+ }
719
+ function debounceNextTick(inner) {
720
+ let lastTick = null;
721
+ let resolves = [];
722
+ return function (...args) {
723
+ // Run the function after a certain amount of time
724
+ const thisTick = nextTick(() => {
725
+ if (lastTick !== thisTick) {
726
+ return;
727
+ }
728
+ // Get the result of the inner function, then apply it to the resolve function of
729
+ // each promise that has been created since the last time the inner function was run
730
+ const result = inner(...args);
731
+ resolves.forEach(r => r(result));
732
+ resolves = [];
733
+ lastTick = null;
734
+ });
735
+ lastTick = thisTick;
736
+ return new Promise(resolve => resolves.push(resolve));
737
+ };
738
+ }
739
+
740
+ function normalizeChildren(tag, context, slotProps) {
741
+ if (!context.slots.default) {
742
+ return context.slots.default;
743
+ }
744
+ if (typeof tag === 'string' || !tag) {
745
+ return context.slots.default(slotProps());
746
+ }
747
+ return {
748
+ default: () => { var _a, _b; return (_b = (_a = context.slots).default) === null || _b === void 0 ? void 0 : _b.call(_a, slotProps()); },
749
+ };
750
+ }
751
+ /**
752
+ * Vue adds a `_value` prop at the moment on the input elements to store the REAL value on them, real values are different than the `value` attribute
753
+ * as they do not get casted to strings unlike `el.value` which preserves user-code behavior
754
+ */
755
+ function getBoundValue(el) {
756
+ if (hasValueBinding(el)) {
757
+ return el._value;
758
+ }
759
+ return undefined;
760
+ }
761
+ /**
762
+ * Vue adds a `_value` prop at the moment on the input elements to store the REAL value on them, real values are different than the `value` attribute
763
+ * as they do not get casted to strings unlike `el.value` which preserves user-code behavior
764
+ */
765
+ function hasValueBinding(el) {
766
+ return '_value' in el;
767
+ }
768
+
769
+ function parseInputValue(el) {
770
+ if (el.type === 'number') {
771
+ return Number.isNaN(el.valueAsNumber) ? el.value : el.valueAsNumber;
772
+ }
773
+ if (el.type === 'range') {
774
+ return Number.isNaN(el.valueAsNumber) ? el.value : el.valueAsNumber;
775
+ }
776
+ return el.value;
777
+ }
778
+ function normalizeEventValue(value) {
779
+ if (!isEvent(value)) {
780
+ return value;
781
+ }
782
+ const input = value.target;
783
+ // Vue sets the current bound value on `_value` prop
784
+ // for checkboxes it it should fetch the value binding type as is (boolean instead of string)
785
+ if (hasCheckedAttr(input.type) && hasValueBinding(input)) {
786
+ return getBoundValue(input);
787
+ }
788
+ if (input.type === 'file' && input.files) {
789
+ const files = Array.from(input.files);
790
+ return input.multiple ? files : files[0];
791
+ }
792
+ if (isNativeMultiSelect(input)) {
793
+ return Array.from(input.options)
794
+ .filter(opt => opt.selected && !opt.disabled)
795
+ .map(getBoundValue);
796
+ }
797
+ // makes sure we get the actual `option` bound value
798
+ // #3440
799
+ if (isNativeSelect(input)) {
800
+ const selectedOption = Array.from(input.options).find(opt => opt.selected);
801
+ return selectedOption ? getBoundValue(selectedOption) : input.value;
802
+ }
803
+ return parseInputValue(input);
804
+ }
805
+
806
+ /**
807
+ * Normalizes the given rules expression.
808
+ */
809
+ function normalizeRules(rules) {
810
+ const acc = {};
811
+ Object.defineProperty(acc, '_$$isNormalized', {
812
+ value: true,
813
+ writable: false,
814
+ enumerable: false,
815
+ configurable: false,
816
+ });
817
+ if (!rules) {
818
+ return acc;
819
+ }
820
+ // Object is already normalized, skip.
821
+ if (isObject(rules) && rules._$$isNormalized) {
822
+ return rules;
823
+ }
824
+ if (isObject(rules)) {
825
+ return Object.keys(rules).reduce((prev, curr) => {
826
+ const params = normalizeParams(rules[curr]);
827
+ if (rules[curr] !== false) {
828
+ prev[curr] = buildParams(params);
829
+ }
830
+ return prev;
831
+ }, acc);
832
+ }
833
+ /* istanbul ignore if */
834
+ if (typeof rules !== 'string') {
835
+ return acc;
836
+ }
837
+ return rules.split('|').reduce((prev, rule) => {
838
+ const parsedRule = parseRule(rule);
839
+ if (!parsedRule.name) {
840
+ return prev;
841
+ }
842
+ prev[parsedRule.name] = buildParams(parsedRule.params);
843
+ return prev;
844
+ }, acc);
845
+ }
846
+ /**
847
+ * Normalizes a rule param.
848
+ */
849
+ function normalizeParams(params) {
850
+ if (params === true) {
851
+ return [];
852
+ }
853
+ if (Array.isArray(params)) {
854
+ return params;
855
+ }
856
+ if (isObject(params)) {
857
+ return params;
858
+ }
859
+ return [params];
860
+ }
861
+ function buildParams(provided) {
862
+ const mapValueToLocator = (value) => {
863
+ // A target param using interpolation
864
+ if (typeof value === 'string' && value[0] === '@') {
865
+ return createLocator(value.slice(1));
866
+ }
867
+ return value;
868
+ };
869
+ if (Array.isArray(provided)) {
870
+ return provided.map(mapValueToLocator);
871
+ }
872
+ // #3073
873
+ if (provided instanceof RegExp) {
874
+ return [provided];
875
+ }
876
+ return Object.keys(provided).reduce((prev, key) => {
877
+ prev[key] = mapValueToLocator(provided[key]);
878
+ return prev;
879
+ }, {});
880
+ }
881
+ /**
882
+ * Parses a rule string expression.
883
+ */
884
+ const parseRule = (rule) => {
885
+ let params = [];
886
+ const name = rule.split(':')[0];
887
+ if (rule.includes(':')) {
888
+ params = rule.split(':').slice(1).join(':').split(',');
889
+ }
890
+ return { name, params };
891
+ };
892
+ function createLocator(value) {
893
+ const locator = (crossTable) => {
894
+ const val = getFromPath(crossTable, value) || crossTable[value];
895
+ return val;
896
+ };
897
+ locator.__locatorRef = value;
898
+ return locator;
899
+ }
900
+ function extractLocators(params) {
901
+ if (Array.isArray(params)) {
902
+ return params.filter(isLocator);
903
+ }
904
+ return keysOf(params)
905
+ .filter(key => isLocator(params[key]))
906
+ .map(key => params[key]);
907
+ }
908
+
909
+ const DEFAULT_CONFIG = {
910
+ generateMessage: ({ field }) => `${field} is not valid.`,
911
+ bails: true,
912
+ validateOnBlur: true,
913
+ validateOnChange: true,
914
+ validateOnInput: false,
915
+ validateOnModelUpdate: true,
916
+ };
917
+ let currentConfig = Object.assign({}, DEFAULT_CONFIG);
918
+ const getConfig = () => currentConfig;
919
+ const setConfig = (newConf) => {
920
+ currentConfig = Object.assign(Object.assign({}, currentConfig), newConf);
921
+ };
922
+ const configure = setConfig;
923
+
924
+ /**
925
+ * Validates a value against the rules.
926
+ */
927
+ async function validate(value, rules, options = {}) {
928
+ const shouldBail = options === null || options === void 0 ? void 0 : options.bails;
929
+ const field = {
930
+ name: (options === null || options === void 0 ? void 0 : options.name) || '{field}',
931
+ rules,
932
+ label: options === null || options === void 0 ? void 0 : options.label,
933
+ bails: shouldBail !== null && shouldBail !== void 0 ? shouldBail : true,
934
+ formData: (options === null || options === void 0 ? void 0 : options.values) || {},
935
+ };
936
+ const result = await _validate(field, value);
937
+ return Object.assign(Object.assign({}, result), { valid: !result.errors.length });
938
+ }
939
+ /**
940
+ * Starts the validation process.
941
+ */
942
+ async function _validate(field, value) {
943
+ const rules = field.rules;
944
+ if (isTypedSchema(rules) || isYupValidator(rules)) {
945
+ return validateFieldWithTypedSchema(value, Object.assign(Object.assign({}, field), { rules }));
946
+ }
947
+ // if a generic function or chain of generic functions
948
+ if (isCallable(rules) || Array.isArray(rules)) {
949
+ const ctx = {
950
+ field: field.label || field.name,
951
+ name: field.name,
952
+ label: field.label,
953
+ form: field.formData,
954
+ value,
955
+ };
956
+ // Normalize the pipeline
957
+ const pipeline = Array.isArray(rules) ? rules : [rules];
958
+ const length = pipeline.length;
959
+ const errors = [];
960
+ for (let i = 0; i < length; i++) {
961
+ const rule = pipeline[i];
962
+ const result = await rule(value, ctx);
963
+ const isValid = typeof result !== 'string' && !Array.isArray(result) && result;
964
+ if (isValid) {
965
+ continue;
966
+ }
967
+ if (Array.isArray(result)) {
968
+ errors.push(...result);
969
+ }
970
+ else {
971
+ const message = typeof result === 'string' ? result : _generateFieldError(ctx);
972
+ errors.push(message);
973
+ }
974
+ if (field.bails) {
975
+ return {
976
+ errors,
977
+ };
978
+ }
979
+ }
980
+ return {
981
+ errors,
982
+ };
983
+ }
984
+ const normalizedContext = Object.assign(Object.assign({}, field), { rules: normalizeRules(rules) });
985
+ const errors = [];
986
+ const rulesKeys = Object.keys(normalizedContext.rules);
987
+ const length = rulesKeys.length;
988
+ for (let i = 0; i < length; i++) {
989
+ const rule = rulesKeys[i];
990
+ const result = await _test(normalizedContext, value, {
991
+ name: rule,
992
+ params: normalizedContext.rules[rule],
993
+ });
994
+ if (result.error) {
995
+ errors.push(result.error);
996
+ if (field.bails) {
997
+ return {
998
+ errors,
999
+ };
1000
+ }
1001
+ }
1002
+ }
1003
+ return {
1004
+ errors,
1005
+ };
1006
+ }
1007
+ function isYupError(err) {
1008
+ return !!err && err.name === 'ValidationError';
1009
+ }
1010
+ function yupToTypedSchema(yupSchema) {
1011
+ const schema = {
1012
+ __type: 'VVTypedSchema',
1013
+ async parse(values, context) {
1014
+ var _a;
1015
+ try {
1016
+ const output = await yupSchema.validate(values, { abortEarly: false, context: (context === null || context === void 0 ? void 0 : context.formData) || {} });
1017
+ return {
1018
+ output,
1019
+ errors: [],
1020
+ };
1021
+ }
1022
+ catch (err) {
1023
+ // Yup errors have a name prop one them.
1024
+ // https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string
1025
+ if (!isYupError(err)) {
1026
+ throw err;
1027
+ }
1028
+ if (!((_a = err.inner) === null || _a === void 0 ? void 0 : _a.length) && err.errors.length) {
1029
+ return { errors: [{ path: err.path, errors: err.errors }] };
1030
+ }
1031
+ const errors = err.inner.reduce((acc, curr) => {
1032
+ const path = curr.path || '';
1033
+ if (!acc[path]) {
1034
+ acc[path] = { errors: [], path };
1035
+ }
1036
+ acc[path].errors.push(...curr.errors);
1037
+ return acc;
1038
+ }, {});
1039
+ return { errors: Object.values(errors) };
1040
+ }
1041
+ },
1042
+ };
1043
+ return schema;
1044
+ }
1045
+ /**
1046
+ * Handles yup validation
1047
+ */
1048
+ async function validateFieldWithTypedSchema(value, context) {
1049
+ const typedSchema = isTypedSchema(context.rules) ? context.rules : yupToTypedSchema(context.rules);
1050
+ const result = await typedSchema.parse(value, { formData: context.formData });
1051
+ const messages = [];
1052
+ for (const error of result.errors) {
1053
+ if (error.errors.length) {
1054
+ messages.push(...error.errors);
1055
+ }
1056
+ }
1057
+ return {
1058
+ value: result.value,
1059
+ errors: messages,
1060
+ };
1061
+ }
1062
+ /**
1063
+ * Tests a single input value against a rule.
1064
+ */
1065
+ async function _test(field, value, rule) {
1066
+ const validator = resolveRule(rule.name);
1067
+ if (!validator) {
1068
+ throw new Error(`No such validator '${rule.name}' exists.`);
1069
+ }
1070
+ const params = fillTargetValues(rule.params, field.formData);
1071
+ const ctx = {
1072
+ field: field.label || field.name,
1073
+ name: field.name,
1074
+ label: field.label,
1075
+ value,
1076
+ form: field.formData,
1077
+ rule: Object.assign(Object.assign({}, rule), { params }),
1078
+ };
1079
+ const result = await validator(value, params, ctx);
1080
+ if (typeof result === 'string') {
1081
+ return {
1082
+ error: result,
1083
+ };
1084
+ }
1085
+ return {
1086
+ error: result ? undefined : _generateFieldError(ctx),
1087
+ };
1088
+ }
1089
+ /**
1090
+ * Generates error messages.
1091
+ */
1092
+ function _generateFieldError(fieldCtx) {
1093
+ const message = getConfig().generateMessage;
1094
+ if (!message) {
1095
+ return 'Field is invalid';
1096
+ }
1097
+ return message(fieldCtx);
1098
+ }
1099
+ function fillTargetValues(params, crossTable) {
1100
+ const normalize = (value) => {
1101
+ if (isLocator(value)) {
1102
+ return value(crossTable);
1103
+ }
1104
+ return value;
1105
+ };
1106
+ if (Array.isArray(params)) {
1107
+ return params.map(normalize);
1108
+ }
1109
+ return Object.keys(params).reduce((acc, param) => {
1110
+ acc[param] = normalize(params[param]);
1111
+ return acc;
1112
+ }, {});
1113
+ }
1114
+ async function validateTypedSchema(schema, values) {
1115
+ const typedSchema = isTypedSchema(schema) ? schema : yupToTypedSchema(schema);
1116
+ const validationResult = await typedSchema.parse(klona(values));
1117
+ const results = {};
1118
+ const errors = {};
1119
+ for (const error of validationResult.errors) {
1120
+ const messages = error.errors;
1121
+ // Fixes issue with path mapping with Yup 1.0 including quotes around array indices
1122
+ const path = (error.path || '').replace(/\["(\d+)"\]/g, (_, m) => {
1123
+ return `[${m}]`;
1124
+ });
1125
+ results[path] = { valid: !messages.length, errors: messages };
1126
+ if (messages.length) {
1127
+ errors[path] = messages[0];
1128
+ }
1129
+ }
1130
+ return {
1131
+ valid: !validationResult.errors.length,
1132
+ results,
1133
+ errors,
1134
+ values: validationResult.value,
1135
+ source: 'schema',
1136
+ };
1137
+ }
1138
+ async function validateObjectSchema(schema, values, opts) {
1139
+ const paths = keysOf(schema);
1140
+ const validations = paths.map(async (path) => {
1141
+ var _a, _b, _c;
1142
+ const strings = (_a = opts === null || opts === void 0 ? void 0 : opts.names) === null || _a === void 0 ? void 0 : _a[path];
1143
+ const fieldResult = await validate(getFromPath(values, path), schema[path], {
1144
+ name: (strings === null || strings === void 0 ? void 0 : strings.name) || path,
1145
+ label: strings === null || strings === void 0 ? void 0 : strings.label,
1146
+ values: values,
1147
+ bails: (_c = (_b = opts === null || opts === void 0 ? void 0 : opts.bailsMap) === null || _b === void 0 ? void 0 : _b[path]) !== null && _c !== void 0 ? _c : true,
1148
+ });
1149
+ return Object.assign(Object.assign({}, fieldResult), { path });
1150
+ });
1151
+ let isAllValid = true;
1152
+ const validationResults = await Promise.all(validations);
1153
+ const results = {};
1154
+ const errors = {};
1155
+ for (const result of validationResults) {
1156
+ results[result.path] = {
1157
+ valid: result.valid,
1158
+ errors: result.errors,
1159
+ };
1160
+ if (!result.valid) {
1161
+ isAllValid = false;
1162
+ errors[result.path] = result.errors[0];
1163
+ }
1164
+ }
1165
+ return {
1166
+ valid: isAllValid,
1167
+ results,
1168
+ errors,
1169
+ source: 'schema',
1170
+ };
1171
+ }
1172
+
1173
+ let ID_COUNTER = 0;
1174
+ function useFieldState(path, init) {
1175
+ const { value, initialValue, setInitialValue } = _useFieldValue(path, init.modelValue, init.form);
1176
+ if (!init.form) {
1177
+ const { errors, setErrors } = createFieldErrors();
1178
+ const id = ID_COUNTER >= Number.MAX_SAFE_INTEGER ? 0 : ++ID_COUNTER;
1179
+ const meta = createFieldMeta(value, initialValue, errors, init.schema);
1180
+ function setState(state) {
1181
+ var _a;
1182
+ if ('value' in state) {
1183
+ value.value = state.value;
1184
+ }
1185
+ if ('errors' in state) {
1186
+ setErrors(state.errors);
1187
+ }
1188
+ if ('touched' in state) {
1189
+ meta.touched = (_a = state.touched) !== null && _a !== void 0 ? _a : meta.touched;
1190
+ }
1191
+ if ('initialValue' in state) {
1192
+ setInitialValue(state.initialValue);
1193
+ }
1194
+ }
1195
+ return {
1196
+ id,
1197
+ path,
1198
+ value,
1199
+ initialValue,
1200
+ meta,
1201
+ flags: { pendingUnmount: { [id]: false }, pendingReset: false },
1202
+ errors,
1203
+ setState,
1204
+ };
1205
+ }
1206
+ const state = init.form.createPathState(path, {
1207
+ bails: init.bails,
1208
+ label: init.label,
1209
+ type: init.type,
1210
+ validate: init.validate,
1211
+ schema: init.schema,
1212
+ });
1213
+ const errors = computed(() => state.errors);
1214
+ function setState(state) {
1215
+ var _a, _b, _c;
1216
+ if ('value' in state) {
1217
+ value.value = state.value;
1218
+ }
1219
+ if ('errors' in state) {
1220
+ (_a = init.form) === null || _a === void 0 ? void 0 : _a.setFieldError(unref(path), state.errors);
1221
+ }
1222
+ if ('touched' in state) {
1223
+ (_b = init.form) === null || _b === void 0 ? void 0 : _b.setFieldTouched(unref(path), (_c = state.touched) !== null && _c !== void 0 ? _c : false);
1224
+ }
1225
+ if ('initialValue' in state) {
1226
+ setInitialValue(state.initialValue);
1227
+ }
1228
+ }
1229
+ return {
1230
+ id: Array.isArray(state.id) ? state.id[state.id.length - 1] : state.id,
1231
+ path,
1232
+ value,
1233
+ errors,
1234
+ meta: state,
1235
+ initialValue,
1236
+ flags: state.__flags,
1237
+ setState,
1238
+ };
1239
+ }
1240
+ /**
1241
+ * Creates the field value and resolves the initial value
1242
+ */
1243
+ function _useFieldValue(path, modelValue, form) {
1244
+ const modelRef = ref(unref(modelValue));
1245
+ function resolveInitialValue() {
1246
+ if (!form) {
1247
+ return unref(modelRef);
1248
+ }
1249
+ return getFromPath(form.initialValues.value, unref(path), unref(modelRef));
1250
+ }
1251
+ function setInitialValue(value) {
1252
+ if (!form) {
1253
+ modelRef.value = value;
1254
+ return;
1255
+ }
1256
+ form.setFieldInitialValue(unref(path), value, true);
1257
+ }
1258
+ const initialValue = computed(resolveInitialValue);
1259
+ // if no form is associated, use a regular ref.
1260
+ if (!form) {
1261
+ const value = ref(resolveInitialValue());
1262
+ return {
1263
+ value,
1264
+ initialValue,
1265
+ setInitialValue,
1266
+ };
1267
+ }
1268
+ // to set the initial value, first check if there is a current value, if there is then use it.
1269
+ // otherwise use the configured initial value if it exists.
1270
+ // prioritize model value over form values
1271
+ // #3429
1272
+ const currentValue = resolveModelValue(modelValue, form, initialValue, path);
1273
+ form.stageInitialValue(unref(path), currentValue, true);
1274
+ // otherwise use a computed setter that triggers the `setFieldValue`
1275
+ const value = computed({
1276
+ get() {
1277
+ return getFromPath(form.values, unref(path));
1278
+ },
1279
+ set(newVal) {
1280
+ form.setFieldValue(unref(path), newVal, false);
1281
+ },
1282
+ });
1283
+ return {
1284
+ value,
1285
+ initialValue,
1286
+ setInitialValue,
1287
+ };
1288
+ }
1289
+ /*
1290
+ to set the initial value, first check if there is a current value, if there is then use it.
1291
+ otherwise use the configured initial value if it exists.
1292
+ prioritize model value over form values
1293
+ #3429
1294
+ */
1295
+ function resolveModelValue(modelValue, form, initialValue, path) {
1296
+ if (isRef(modelValue)) {
1297
+ return unref(modelValue);
1298
+ }
1299
+ if (modelValue !== undefined) {
1300
+ return modelValue;
1301
+ }
1302
+ return getFromPath(form.values, unref(path), unref(initialValue));
1303
+ }
1304
+ /**
1305
+ * Creates meta flags state and some associated effects with them
1306
+ */
1307
+ function createFieldMeta(currentValue, initialValue, errors, schema) {
1308
+ const isRequired = computed(() => { var _a, _b, _c; return (_c = (_b = (_a = toValue(schema)) === null || _a === void 0 ? void 0 : _a.describe) === null || _b === void 0 ? void 0 : _b.call(_a).required) !== null && _c !== void 0 ? _c : false; });
1309
+ const meta = reactive({
1310
+ touched: false,
1311
+ pending: false,
1312
+ valid: true,
1313
+ required: isRequired,
1314
+ validated: !!unref(errors).length,
1315
+ initialValue: computed(() => unref(initialValue)),
1316
+ dirty: computed(() => {
1317
+ return !isEqual(unref(currentValue), unref(initialValue));
1318
+ }),
1319
+ });
1320
+ watch(errors, value => {
1321
+ meta.valid = !value.length;
1322
+ }, {
1323
+ immediate: true,
1324
+ flush: 'sync',
1325
+ });
1326
+ return meta;
1327
+ }
1328
+ /**
1329
+ * Creates the error message state for the field state
1330
+ */
1331
+ function createFieldErrors() {
1332
+ const errors = ref([]);
1333
+ return {
1334
+ errors,
1335
+ setErrors: (messages) => {
1336
+ errors.value = normalizeErrorItem(messages);
1337
+ },
1338
+ };
1339
+ }
1340
+
1341
+ function installDevtoolsPlugin(app) {
1342
+ if (("production" !== 'production')) {
1343
+ setupDevtoolsPlugin({
1344
+ id: 'vee-validate-devtools-plugin',
1345
+ label: 'VeeValidate Plugin',
1346
+ packageName: 'vee-validate',
1347
+ homepage: 'https://vee-validate.logaretm.com/v4',
1348
+ app,
1349
+ logo: 'https://vee-validate.logaretm.com/v4/logo.png',
1350
+ }, setupApiHooks);
1351
+ }
1352
+ }
1353
+ const DEVTOOLS_FORMS = {};
1354
+ const DEVTOOLS_FIELDS = {};
1355
+ let API;
1356
+ const refreshInspector = throttle(() => {
1357
+ setTimeout(async () => {
1358
+ await nextTick();
1359
+ API === null || API === void 0 ? void 0 : API.sendInspectorState(INSPECTOR_ID);
1360
+ API === null || API === void 0 ? void 0 : API.sendInspectorTree(INSPECTOR_ID);
1361
+ }, 100);
1362
+ }, 100);
1363
+ function registerFormWithDevTools(form) {
1364
+ const vm = getCurrentInstance();
1365
+ if (!API) {
1366
+ const app = vm === null || vm === void 0 ? void 0 : vm.appContext.app;
1367
+ if (!app) {
1368
+ return;
1369
+ }
1370
+ installDevtoolsPlugin(app);
1371
+ }
1372
+ DEVTOOLS_FORMS[form.formId] = Object.assign({}, form);
1373
+ DEVTOOLS_FORMS[form.formId]._vm = vm;
1374
+ onUnmounted(() => {
1375
+ delete DEVTOOLS_FORMS[form.formId];
1376
+ refreshInspector();
1377
+ });
1378
+ refreshInspector();
1379
+ }
1380
+ function registerSingleFieldWithDevtools(field) {
1381
+ const vm = getCurrentInstance();
1382
+ if (!API) {
1383
+ const app = vm === null || vm === void 0 ? void 0 : vm.appContext.app;
1384
+ if (!app) {
1385
+ return;
1386
+ }
1387
+ installDevtoolsPlugin(app);
1388
+ }
1389
+ DEVTOOLS_FIELDS[field.id] = Object.assign({}, field);
1390
+ DEVTOOLS_FIELDS[field.id]._vm = vm;
1391
+ onUnmounted(() => {
1392
+ delete DEVTOOLS_FIELDS[field.id];
1393
+ refreshInspector();
1394
+ });
1395
+ refreshInspector();
1396
+ }
1397
+ const INSPECTOR_ID = 'vee-validate-inspector';
1398
+ const COLORS = {
1399
+ error: 0xbd4b4b,
1400
+ success: 0x06d77b,
1401
+ unknown: 0x54436b,
1402
+ white: 0xffffff,
1403
+ black: 0x000000,
1404
+ blue: 0x035397,
1405
+ purple: 0xb980f0,
1406
+ orange: 0xf5a962,
1407
+ gray: 0xbbbfca,
1408
+ };
1409
+ let SELECTED_NODE = null;
1410
+ function setupApiHooks(api) {
1411
+ API = api;
1412
+ api.addInspector({
1413
+ id: INSPECTOR_ID,
1414
+ icon: 'rule',
1415
+ label: 'vee-validate',
1416
+ noSelectionText: 'Select a vee-validate node to inspect',
1417
+ actions: [
1418
+ {
1419
+ icon: 'done_outline',
1420
+ tooltip: 'Validate selected item',
1421
+ action: async () => {
1422
+ if (!SELECTED_NODE) {
1423
+ console.error('There is not a valid selected vee-validate node or component');
1424
+ return;
1425
+ }
1426
+ if (SELECTED_NODE.type === 'field') {
1427
+ await SELECTED_NODE.field.validate();
1428
+ return;
1429
+ }
1430
+ if (SELECTED_NODE.type === 'form') {
1431
+ await SELECTED_NODE.form.validate();
1432
+ return;
1433
+ }
1434
+ if (SELECTED_NODE.type === 'pathState') {
1435
+ await SELECTED_NODE.form.validateField(SELECTED_NODE.state.path);
1436
+ }
1437
+ },
1438
+ },
1439
+ {
1440
+ icon: 'delete_sweep',
1441
+ tooltip: 'Clear validation state of the selected item',
1442
+ action: () => {
1443
+ if (!SELECTED_NODE) {
1444
+ console.error('There is not a valid selected vee-validate node or component');
1445
+ return;
1446
+ }
1447
+ if (SELECTED_NODE.type === 'field') {
1448
+ SELECTED_NODE.field.resetField();
1449
+ return;
1450
+ }
1451
+ if (SELECTED_NODE.type === 'form') {
1452
+ SELECTED_NODE.form.resetForm();
1453
+ }
1454
+ if (SELECTED_NODE.type === 'pathState') {
1455
+ SELECTED_NODE.form.resetField(SELECTED_NODE.state.path);
1456
+ }
1457
+ },
1458
+ },
1459
+ ],
1460
+ });
1461
+ api.on.getInspectorTree(payload => {
1462
+ if (payload.inspectorId !== INSPECTOR_ID) {
1463
+ return;
1464
+ }
1465
+ const forms = Object.values(DEVTOOLS_FORMS);
1466
+ const fields = Object.values(DEVTOOLS_FIELDS);
1467
+ payload.rootNodes = [
1468
+ ...forms.map(mapFormForDevtoolsInspector),
1469
+ ...fields.map(field => mapFieldForDevtoolsInspector(field)),
1470
+ ];
1471
+ });
1472
+ api.on.getInspectorState((payload, ctx) => {
1473
+ if (payload.inspectorId !== INSPECTOR_ID || ctx.currentTab !== `custom-inspector:${INSPECTOR_ID}`) {
1474
+ return;
1475
+ }
1476
+ const { form, field, state, type } = decodeNodeId(payload.nodeId);
1477
+ if (form && type === 'form') {
1478
+ payload.state = buildFormState(form);
1479
+ SELECTED_NODE = { type: 'form', form };
1480
+ return;
1481
+ }
1482
+ if (state && type === 'pathState' && form) {
1483
+ payload.state = buildFieldState(state);
1484
+ SELECTED_NODE = { type: 'pathState', state, form };
1485
+ return;
1486
+ }
1487
+ if (field && type === 'field') {
1488
+ payload.state = buildFieldState({
1489
+ errors: field.errors.value,
1490
+ dirty: field.meta.dirty,
1491
+ valid: field.meta.valid,
1492
+ touched: field.meta.touched,
1493
+ value: field.value.value,
1494
+ initialValue: field.meta.initialValue,
1495
+ });
1496
+ SELECTED_NODE = { field, type: 'field' };
1497
+ return;
1498
+ }
1499
+ SELECTED_NODE = null;
1500
+ });
1501
+ }
1502
+ function mapFormForDevtoolsInspector(form) {
1503
+ const { textColor, bgColor } = getValidityColors(form.meta.value.valid);
1504
+ const formTreeNodes = {};
1505
+ Object.values(form.getAllPathStates()).forEach(state => {
1506
+ setInPath(formTreeNodes, unref(state.path), mapPathForDevtoolsInspector(state, form));
1507
+ });
1508
+ function buildFormTree(tree, path = []) {
1509
+ const key = [...path].pop();
1510
+ if ('id' in tree) {
1511
+ return Object.assign(Object.assign({}, tree), { label: key || tree.label });
1512
+ }
1513
+ if (isObject(tree)) {
1514
+ return {
1515
+ id: `${path.join('.')}`,
1516
+ label: key || '',
1517
+ children: Object.keys(tree).map(key => buildFormTree(tree[key], [...path, key])),
1518
+ };
1519
+ }
1520
+ if (Array.isArray(tree)) {
1521
+ return {
1522
+ id: `${path.join('.')}`,
1523
+ label: `${key}[]`,
1524
+ children: tree.map((c, idx) => buildFormTree(c, [...path, String(idx)])),
1525
+ };
1526
+ }
1527
+ return { id: '', label: '', children: [] };
1528
+ }
1529
+ const { children } = buildFormTree(formTreeNodes);
1530
+ return {
1531
+ id: encodeNodeId(form),
1532
+ label: 'Form',
1533
+ children,
1534
+ tags: [
1535
+ {
1536
+ label: 'Form',
1537
+ textColor,
1538
+ backgroundColor: bgColor,
1539
+ },
1540
+ {
1541
+ label: `${form.getAllPathStates().length} fields`,
1542
+ textColor: COLORS.white,
1543
+ backgroundColor: COLORS.unknown,
1544
+ },
1545
+ ],
1546
+ };
1547
+ }
1548
+ function mapPathForDevtoolsInspector(state, form) {
1549
+ return {
1550
+ id: encodeNodeId(form, state),
1551
+ label: unref(state.path),
1552
+ tags: getFieldNodeTags(state.multiple, state.fieldsCount, state.type, state.valid, form),
1553
+ };
1554
+ }
1555
+ function mapFieldForDevtoolsInspector(field, form) {
1556
+ return {
1557
+ id: encodeNodeId(form, field),
1558
+ label: unref(field.name),
1559
+ tags: getFieldNodeTags(false, 1, field.type, field.meta.valid, form),
1560
+ };
1561
+ }
1562
+ function getFieldNodeTags(multiple, fieldsCount, type, valid, form) {
1563
+ const { textColor, bgColor } = getValidityColors(valid);
1564
+ return [
1565
+ multiple
1566
+ ? undefined
1567
+ : {
1568
+ label: 'Field',
1569
+ textColor,
1570
+ backgroundColor: bgColor,
1571
+ },
1572
+ !form
1573
+ ? {
1574
+ label: 'Standalone',
1575
+ textColor: COLORS.black,
1576
+ backgroundColor: COLORS.gray,
1577
+ }
1578
+ : undefined,
1579
+ type === 'checkbox'
1580
+ ? {
1581
+ label: 'Checkbox',
1582
+ textColor: COLORS.white,
1583
+ backgroundColor: COLORS.blue,
1584
+ }
1585
+ : undefined,
1586
+ type === 'radio'
1587
+ ? {
1588
+ label: 'Radio',
1589
+ textColor: COLORS.white,
1590
+ backgroundColor: COLORS.purple,
1591
+ }
1592
+ : undefined,
1593
+ multiple
1594
+ ? {
1595
+ label: 'Multiple',
1596
+ textColor: COLORS.black,
1597
+ backgroundColor: COLORS.orange,
1598
+ }
1599
+ : undefined,
1600
+ ].filter(Boolean);
1601
+ }
1602
+ function encodeNodeId(form, stateOrField) {
1603
+ const type = stateOrField ? ('path' in stateOrField ? 'pathState' : 'field') : 'form';
1604
+ const fieldPath = stateOrField ? ('path' in stateOrField ? stateOrField === null || stateOrField === void 0 ? void 0 : stateOrField.path : unref(stateOrField === null || stateOrField === void 0 ? void 0 : stateOrField.name)) : '';
1605
+ const idObject = { f: form === null || form === void 0 ? void 0 : form.formId, ff: fieldPath, type };
1606
+ return btoa(encodeURIComponent(JSON.stringify(idObject)));
1607
+ }
1608
+ function decodeNodeId(nodeId) {
1609
+ try {
1610
+ const idObject = JSON.parse(decodeURIComponent(atob(nodeId)));
1611
+ const form = DEVTOOLS_FORMS[idObject.f];
1612
+ if (!form && idObject.ff) {
1613
+ const field = DEVTOOLS_FIELDS[idObject.ff];
1614
+ if (!field) {
1615
+ return {};
1616
+ }
1617
+ return {
1618
+ type: idObject.type,
1619
+ field,
1620
+ };
1621
+ }
1622
+ if (!form) {
1623
+ return {};
1624
+ }
1625
+ const state = form.getPathState(idObject.ff);
1626
+ return {
1627
+ type: idObject.type,
1628
+ form,
1629
+ state,
1630
+ };
1631
+ }
1632
+ catch (err) {
1633
+ // console.error(`Devtools: [vee-validate] Failed to parse node id ${nodeId}`);
1634
+ }
1635
+ return {};
1636
+ }
1637
+ function buildFieldState(state) {
1638
+ return {
1639
+ 'Field state': [
1640
+ { key: 'errors', value: state.errors },
1641
+ {
1642
+ key: 'initialValue',
1643
+ value: state.initialValue,
1644
+ },
1645
+ {
1646
+ key: 'currentValue',
1647
+ value: state.value,
1648
+ },
1649
+ {
1650
+ key: 'touched',
1651
+ value: state.touched,
1652
+ },
1653
+ {
1654
+ key: 'dirty',
1655
+ value: state.dirty,
1656
+ },
1657
+ {
1658
+ key: 'valid',
1659
+ value: state.valid,
1660
+ },
1661
+ ],
1662
+ };
1663
+ }
1664
+ function buildFormState(form) {
1665
+ const { errorBag, meta, values, isSubmitting, isValidating, submitCount } = form;
1666
+ return {
1667
+ 'Form state': [
1668
+ {
1669
+ key: 'submitCount',
1670
+ value: submitCount.value,
1671
+ },
1672
+ {
1673
+ key: 'isSubmitting',
1674
+ value: isSubmitting.value,
1675
+ },
1676
+ {
1677
+ key: 'isValidating',
1678
+ value: isValidating.value,
1679
+ },
1680
+ {
1681
+ key: 'touched',
1682
+ value: meta.value.touched,
1683
+ },
1684
+ {
1685
+ key: 'dirty',
1686
+ value: meta.value.dirty,
1687
+ },
1688
+ {
1689
+ key: 'valid',
1690
+ value: meta.value.valid,
1691
+ },
1692
+ {
1693
+ key: 'initialValues',
1694
+ value: meta.value.initialValues,
1695
+ },
1696
+ {
1697
+ key: 'currentValues',
1698
+ value: values,
1699
+ },
1700
+ {
1701
+ key: 'errors',
1702
+ value: keysOf(errorBag.value).reduce((acc, key) => {
1703
+ var _a;
1704
+ const message = (_a = errorBag.value[key]) === null || _a === void 0 ? void 0 : _a[0];
1705
+ if (message) {
1706
+ acc[key] = message;
1707
+ }
1708
+ return acc;
1709
+ }, {}),
1710
+ },
1711
+ ],
1712
+ };
1713
+ }
1714
+ /**
1715
+ * Resolves the tag color based on the form state
1716
+ */
1717
+ function getValidityColors(valid) {
1718
+ return {
1719
+ bgColor: valid ? COLORS.success : COLORS.error,
1720
+ textColor: valid ? COLORS.black : COLORS.white,
1721
+ };
1722
+ }
1723
+
1724
+ /**
1725
+ * Creates a field composite.
1726
+ */
1727
+ function useField(path, rules, opts) {
1728
+ if (hasCheckedAttr(opts === null || opts === void 0 ? void 0 : opts.type)) {
1729
+ return useFieldWithChecked(path, rules, opts);
1730
+ }
1731
+ return _useField(path, rules, opts);
1732
+ }
1733
+ function _useField(path, rules, opts) {
1734
+ const { initialValue: modelValue, validateOnMount, bails, type, checkedValue, label, validateOnValueUpdate, uncheckedValue, controlled, keepValueOnUnmount, syncVModel, form: controlForm, } = normalizeOptions(opts);
1735
+ const injectedForm = controlled ? injectWithSelf(FormContextKey) : undefined;
1736
+ const form = controlForm || injectedForm;
1737
+ const name = computed(() => normalizeFormPath(toValue(path)));
1738
+ const validator = computed(() => {
1739
+ const schema = toValue(form === null || form === void 0 ? void 0 : form.schema);
1740
+ if (schema) {
1741
+ return undefined;
1742
+ }
1743
+ const rulesValue = unref(rules);
1744
+ if (isYupValidator(rulesValue) ||
1745
+ isTypedSchema(rulesValue) ||
1746
+ isCallable(rulesValue) ||
1747
+ Array.isArray(rulesValue)) {
1748
+ return rulesValue;
1749
+ }
1750
+ return normalizeRules(rulesValue);
1751
+ });
1752
+ const isTyped = !isCallable(validator.value) && isTypedSchema(toValue(rules));
1753
+ const { id, value, initialValue, meta, setState, errors, flags } = useFieldState(name, {
1754
+ modelValue,
1755
+ form,
1756
+ bails,
1757
+ label,
1758
+ type,
1759
+ validate: validator.value ? validate$1 : undefined,
1760
+ schema: isTyped ? rules : undefined,
1761
+ });
1762
+ const errorMessage = computed(() => errors.value[0]);
1763
+ if (syncVModel) {
1764
+ useVModel({
1765
+ value,
1766
+ prop: syncVModel,
1767
+ handleChange,
1768
+ shouldValidate: () => validateOnValueUpdate && !flags.pendingReset,
1769
+ });
1770
+ }
1771
+ /**
1772
+ * Handles common onBlur meta update
1773
+ */
1774
+ const handleBlur = (evt, shouldValidate = false) => {
1775
+ meta.touched = true;
1776
+ if (shouldValidate) {
1777
+ validateWithStateMutation();
1778
+ }
1779
+ };
1780
+ async function validateCurrentValue(mode) {
1781
+ var _a, _b;
1782
+ if (form === null || form === void 0 ? void 0 : form.validateSchema) {
1783
+ const { results } = await form.validateSchema(mode);
1784
+ return (_a = results[toValue(name)]) !== null && _a !== void 0 ? _a : { valid: true, errors: [] };
1785
+ }
1786
+ if (validator.value) {
1787
+ return validate(value.value, validator.value, {
1788
+ name: toValue(name),
1789
+ label: toValue(label),
1790
+ values: (_b = form === null || form === void 0 ? void 0 : form.values) !== null && _b !== void 0 ? _b : {},
1791
+ bails,
1792
+ });
1793
+ }
1794
+ return { valid: true, errors: [] };
1795
+ }
1796
+ const validateWithStateMutation = withLatest(async () => {
1797
+ meta.pending = true;
1798
+ meta.validated = true;
1799
+ return validateCurrentValue('validated-only');
1800
+ }, result => {
1801
+ if (flags.pendingUnmount[field.id]) {
1802
+ return result;
1803
+ }
1804
+ setState({ errors: result.errors });
1805
+ meta.pending = false;
1806
+ meta.valid = result.valid;
1807
+ return result;
1808
+ });
1809
+ const validateValidStateOnly = withLatest(async () => {
1810
+ return validateCurrentValue('silent');
1811
+ }, result => {
1812
+ meta.valid = result.valid;
1813
+ return result;
1814
+ });
1815
+ function validate$1(opts) {
1816
+ if ((opts === null || opts === void 0 ? void 0 : opts.mode) === 'silent') {
1817
+ return validateValidStateOnly();
1818
+ }
1819
+ return validateWithStateMutation();
1820
+ }
1821
+ // Common input/change event handler
1822
+ function handleChange(e, shouldValidate = true) {
1823
+ const newValue = normalizeEventValue(e);
1824
+ setValue(newValue, shouldValidate);
1825
+ }
1826
+ // Runs the initial validation
1827
+ onMounted(() => {
1828
+ if (validateOnMount) {
1829
+ return validateWithStateMutation();
1830
+ }
1831
+ // validate self initially if no form was handling this
1832
+ // forms should have their own initial silent validation run to make things more efficient
1833
+ if (!form || !form.validateSchema) {
1834
+ validateValidStateOnly();
1835
+ }
1836
+ });
1837
+ function setTouched(isTouched) {
1838
+ meta.touched = isTouched;
1839
+ }
1840
+ function resetField(state) {
1841
+ var _a;
1842
+ const newValue = state && 'value' in state ? state.value : initialValue.value;
1843
+ setState({
1844
+ value: klona(newValue),
1845
+ initialValue: klona(newValue),
1846
+ touched: (_a = state === null || state === void 0 ? void 0 : state.touched) !== null && _a !== void 0 ? _a : false,
1847
+ errors: (state === null || state === void 0 ? void 0 : state.errors) || [],
1848
+ });
1849
+ meta.pending = false;
1850
+ meta.validated = false;
1851
+ validateValidStateOnly();
1852
+ }
1853
+ const vm = getCurrentInstance();
1854
+ function setValue(newValue, shouldValidate = true) {
1855
+ value.value = vm && syncVModel ? applyModelModifiers(newValue, vm.props.modelModifiers) : newValue;
1856
+ const validateFn = shouldValidate ? validateWithStateMutation : validateValidStateOnly;
1857
+ validateFn();
1858
+ }
1859
+ function setErrors(errors) {
1860
+ setState({ errors: Array.isArray(errors) ? errors : [errors] });
1861
+ }
1862
+ const valueProxy = computed({
1863
+ get() {
1864
+ return value.value;
1865
+ },
1866
+ set(newValue) {
1867
+ setValue(newValue, validateOnValueUpdate);
1868
+ },
1869
+ });
1870
+ const field = {
1871
+ id,
1872
+ name,
1873
+ label,
1874
+ value: valueProxy,
1875
+ meta,
1876
+ errors,
1877
+ errorMessage,
1878
+ type,
1879
+ checkedValue,
1880
+ uncheckedValue,
1881
+ bails,
1882
+ keepValueOnUnmount,
1883
+ resetField,
1884
+ handleReset: () => resetField(),
1885
+ validate: validate$1,
1886
+ handleChange,
1887
+ handleBlur,
1888
+ setState,
1889
+ setTouched,
1890
+ setErrors,
1891
+ setValue,
1892
+ };
1893
+ provide(FieldContextKey, field);
1894
+ if (isRef(rules) && typeof unref(rules) !== 'function') {
1895
+ watch(rules, (value, oldValue) => {
1896
+ if (isEqual(value, oldValue)) {
1897
+ return;
1898
+ }
1899
+ meta.validated ? validateWithStateMutation() : validateValidStateOnly();
1900
+ }, {
1901
+ deep: true,
1902
+ });
1903
+ }
1904
+ if (("production" !== 'production')) {
1905
+ field._vm = getCurrentInstance();
1906
+ watch(() => (Object.assign(Object.assign({ errors: errors.value }, meta), { value: value.value })), refreshInspector, {
1907
+ deep: true,
1908
+ });
1909
+ if (!form) {
1910
+ registerSingleFieldWithDevtools(field);
1911
+ }
1912
+ }
1913
+ // if no associated form return the field API immediately
1914
+ if (!form) {
1915
+ return field;
1916
+ }
1917
+ // associate the field with the given form
1918
+ // extract cross-field dependencies in a computed prop
1919
+ const dependencies = computed(() => {
1920
+ const rulesVal = validator.value;
1921
+ // is falsy, a function schema or a yup schema
1922
+ if (!rulesVal ||
1923
+ isCallable(rulesVal) ||
1924
+ isYupValidator(rulesVal) ||
1925
+ isTypedSchema(rulesVal) ||
1926
+ Array.isArray(rulesVal)) {
1927
+ return {};
1928
+ }
1929
+ return Object.keys(rulesVal).reduce((acc, rule) => {
1930
+ const deps = extractLocators(rulesVal[rule])
1931
+ .map((dep) => dep.__locatorRef)
1932
+ .reduce((depAcc, depName) => {
1933
+ const depValue = getFromPath(form.values, depName) || form.values[depName];
1934
+ if (depValue !== undefined) {
1935
+ depAcc[depName] = depValue;
1936
+ }
1937
+ return depAcc;
1938
+ }, {});
1939
+ Object.assign(acc, deps);
1940
+ return acc;
1941
+ }, {});
1942
+ });
1943
+ // Adds a watcher that runs the validation whenever field dependencies change
1944
+ watch(dependencies, (deps, oldDeps) => {
1945
+ // Skip if no dependencies or if the field wasn't manipulated
1946
+ if (!Object.keys(deps).length) {
1947
+ return;
1948
+ }
1949
+ const shouldValidate = !isEqual(deps, oldDeps);
1950
+ if (shouldValidate) {
1951
+ meta.validated ? validateWithStateMutation() : validateValidStateOnly();
1952
+ }
1953
+ });
1954
+ onBeforeUnmount(() => {
1955
+ var _a;
1956
+ const shouldKeepValue = (_a = toValue(field.keepValueOnUnmount)) !== null && _a !== void 0 ? _a : toValue(form.keepValuesOnUnmount);
1957
+ const path = toValue(name);
1958
+ if (shouldKeepValue || !form || flags.pendingUnmount[field.id]) {
1959
+ form === null || form === void 0 ? void 0 : form.removePathState(path, id);
1960
+ return;
1961
+ }
1962
+ flags.pendingUnmount[field.id] = true;
1963
+ const pathState = form.getPathState(path);
1964
+ const matchesId = Array.isArray(pathState === null || pathState === void 0 ? void 0 : pathState.id) && (pathState === null || pathState === void 0 ? void 0 : pathState.multiple)
1965
+ ? pathState === null || pathState === void 0 ? void 0 : pathState.id.includes(field.id)
1966
+ : (pathState === null || pathState === void 0 ? void 0 : pathState.id) === field.id;
1967
+ if (!matchesId) {
1968
+ return;
1969
+ }
1970
+ if ((pathState === null || pathState === void 0 ? void 0 : pathState.multiple) && Array.isArray(pathState.value)) {
1971
+ const valueIdx = pathState.value.findIndex(i => isEqual(i, toValue(field.checkedValue)));
1972
+ if (valueIdx > -1) {
1973
+ const newVal = [...pathState.value];
1974
+ newVal.splice(valueIdx, 1);
1975
+ form.setFieldValue(path, newVal);
1976
+ }
1977
+ if (Array.isArray(pathState.id)) {
1978
+ pathState.id.splice(pathState.id.indexOf(field.id), 1);
1979
+ }
1980
+ }
1981
+ else {
1982
+ form.unsetPathValue(toValue(name));
1983
+ }
1984
+ form.removePathState(path, id);
1985
+ });
1986
+ return field;
1987
+ }
1988
+ /**
1989
+ * Normalizes partial field options to include the full options
1990
+ */
1991
+ function normalizeOptions(opts) {
1992
+ const defaults = () => ({
1993
+ initialValue: undefined,
1994
+ validateOnMount: false,
1995
+ bails: true,
1996
+ label: undefined,
1997
+ validateOnValueUpdate: true,
1998
+ keepValueOnUnmount: undefined,
1999
+ syncVModel: false,
2000
+ controlled: true,
2001
+ });
2002
+ const isVModelSynced = !!(opts === null || opts === void 0 ? void 0 : opts.syncVModel);
2003
+ const modelPropName = typeof (opts === null || opts === void 0 ? void 0 : opts.syncVModel) === 'string' ? opts.syncVModel : (opts === null || opts === void 0 ? void 0 : opts.modelPropName) || 'modelValue';
2004
+ const initialValue = isVModelSynced && !('initialValue' in (opts || {}))
2005
+ ? getCurrentModelValue(getCurrentInstance(), modelPropName)
2006
+ : opts === null || opts === void 0 ? void 0 : opts.initialValue;
2007
+ if (!opts) {
2008
+ return Object.assign(Object.assign({}, defaults()), { initialValue });
2009
+ }
2010
+ // TODO: Deprecate this in next major release
2011
+ const checkedValue = 'valueProp' in opts ? opts.valueProp : opts.checkedValue;
2012
+ const controlled = 'standalone' in opts ? !opts.standalone : opts.controlled;
2013
+ const syncVModel = (opts === null || opts === void 0 ? void 0 : opts.modelPropName) || (opts === null || opts === void 0 ? void 0 : opts.syncVModel) || false;
2014
+ return Object.assign(Object.assign(Object.assign({}, defaults()), (opts || {})), { initialValue, controlled: controlled !== null && controlled !== void 0 ? controlled : true, checkedValue,
2015
+ syncVModel });
2016
+ }
2017
+ function useFieldWithChecked(name, rules, opts) {
2018
+ const form = !(opts === null || opts === void 0 ? void 0 : opts.standalone) ? injectWithSelf(FormContextKey) : undefined;
2019
+ const checkedValue = opts === null || opts === void 0 ? void 0 : opts.checkedValue;
2020
+ const uncheckedValue = opts === null || opts === void 0 ? void 0 : opts.uncheckedValue;
2021
+ function patchCheckedApi(field) {
2022
+ const handleChange = field.handleChange;
2023
+ const checked = computed(() => {
2024
+ const currentValue = toValue(field.value);
2025
+ const checkedVal = toValue(checkedValue);
2026
+ return Array.isArray(currentValue)
2027
+ ? currentValue.findIndex(v => isEqual(v, checkedVal)) >= 0
2028
+ : isEqual(checkedVal, currentValue);
2029
+ });
2030
+ function handleCheckboxChange(e, shouldValidate = true) {
2031
+ var _a, _b;
2032
+ if (checked.value === ((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.checked)) {
2033
+ if (shouldValidate) {
2034
+ field.validate();
2035
+ }
2036
+ return;
2037
+ }
2038
+ const path = toValue(name);
2039
+ const pathState = form === null || form === void 0 ? void 0 : form.getPathState(path);
2040
+ const value = normalizeEventValue(e);
2041
+ let newValue = (_b = toValue(checkedValue)) !== null && _b !== void 0 ? _b : value;
2042
+ if (form && (pathState === null || pathState === void 0 ? void 0 : pathState.multiple) && pathState.type === 'checkbox') {
2043
+ newValue = resolveNextCheckboxValue(getFromPath(form.values, path) || [], newValue, undefined);
2044
+ }
2045
+ else if ((opts === null || opts === void 0 ? void 0 : opts.type) === 'checkbox') {
2046
+ newValue = resolveNextCheckboxValue(toValue(field.value), newValue, toValue(uncheckedValue));
2047
+ }
2048
+ handleChange(newValue, shouldValidate);
2049
+ }
2050
+ return Object.assign(Object.assign({}, field), { checked,
2051
+ checkedValue,
2052
+ uncheckedValue, handleChange: handleCheckboxChange });
2053
+ }
2054
+ return patchCheckedApi(_useField(name, rules, opts));
2055
+ }
2056
+ function useVModel({ prop, value, handleChange, shouldValidate }) {
2057
+ const vm = getCurrentInstance();
2058
+ /* istanbul ignore next */
2059
+ if (!vm || !prop) {
2060
+ if (("production" !== 'production')) {
2061
+ console.warn('Failed to setup model events because `useField` was not called in setup.');
2062
+ }
2063
+ return;
2064
+ }
2065
+ const propName = typeof prop === 'string' ? prop : 'modelValue';
2066
+ const emitName = `update:${propName}`;
2067
+ // Component doesn't have a model prop setup (must be defined on the props)
2068
+ if (!(propName in vm.props)) {
2069
+ return;
2070
+ }
2071
+ watch(value, newValue => {
2072
+ if (isEqual(newValue, getCurrentModelValue(vm, propName))) {
2073
+ return;
2074
+ }
2075
+ vm.emit(emitName, newValue);
2076
+ });
2077
+ watch(() => getCurrentModelValue(vm, propName), propValue => {
2078
+ if (propValue === IS_ABSENT && value.value === undefined) {
2079
+ return;
2080
+ }
2081
+ const newValue = propValue === IS_ABSENT ? undefined : propValue;
2082
+ if (isEqual(newValue, value.value)) {
2083
+ return;
2084
+ }
2085
+ handleChange(newValue, shouldValidate());
2086
+ });
2087
+ }
2088
+ function getCurrentModelValue(vm, propName) {
2089
+ if (!vm) {
2090
+ return undefined;
2091
+ }
2092
+ return vm.props[propName];
2093
+ }
2094
+
2095
+ const FieldImpl = /** #__PURE__ */ defineComponent({
2096
+ name: 'Field',
2097
+ inheritAttrs: false,
2098
+ props: {
2099
+ as: {
2100
+ type: [String, Object],
2101
+ default: undefined,
2102
+ },
2103
+ name: {
2104
+ type: String,
2105
+ required: true,
2106
+ },
2107
+ rules: {
2108
+ type: [Object, String, Function],
2109
+ default: undefined,
2110
+ },
2111
+ validateOnMount: {
2112
+ type: Boolean,
2113
+ default: false,
2114
+ },
2115
+ validateOnBlur: {
2116
+ type: Boolean,
2117
+ default: undefined,
2118
+ },
2119
+ validateOnChange: {
2120
+ type: Boolean,
2121
+ default: undefined,
2122
+ },
2123
+ validateOnInput: {
2124
+ type: Boolean,
2125
+ default: undefined,
2126
+ },
2127
+ validateOnModelUpdate: {
2128
+ type: Boolean,
2129
+ default: undefined,
2130
+ },
2131
+ bails: {
2132
+ type: Boolean,
2133
+ default: () => getConfig().bails,
2134
+ },
2135
+ label: {
2136
+ type: String,
2137
+ default: undefined,
2138
+ },
2139
+ uncheckedValue: {
2140
+ type: null,
2141
+ default: undefined,
2142
+ },
2143
+ modelValue: {
2144
+ type: null,
2145
+ default: IS_ABSENT,
2146
+ },
2147
+ modelModifiers: {
2148
+ type: null,
2149
+ default: () => ({}),
2150
+ },
2151
+ 'onUpdate:modelValue': {
2152
+ type: null,
2153
+ default: undefined,
2154
+ },
2155
+ standalone: {
2156
+ type: Boolean,
2157
+ default: false,
2158
+ },
2159
+ keepValue: {
2160
+ type: Boolean,
2161
+ default: undefined,
2162
+ },
2163
+ },
2164
+ setup(props, ctx) {
2165
+ const rules = toRef(props, 'rules');
2166
+ const name = toRef(props, 'name');
2167
+ const label = toRef(props, 'label');
2168
+ const uncheckedValue = toRef(props, 'uncheckedValue');
2169
+ const keepValue = toRef(props, 'keepValue');
2170
+ const { errors, value, errorMessage, validate: validateField, handleChange, handleBlur, setTouched, resetField, handleReset, meta, checked, setErrors, setValue, } = useField(name, rules, {
2171
+ validateOnMount: props.validateOnMount,
2172
+ bails: props.bails,
2173
+ standalone: props.standalone,
2174
+ type: ctx.attrs.type,
2175
+ initialValue: resolveInitialValue(props, ctx),
2176
+ // Only for checkboxes and radio buttons
2177
+ checkedValue: ctx.attrs.value,
2178
+ uncheckedValue,
2179
+ label,
2180
+ validateOnValueUpdate: props.validateOnModelUpdate,
2181
+ keepValueOnUnmount: keepValue,
2182
+ syncVModel: true,
2183
+ });
2184
+ // If there is a v-model applied on the component we need to emit the `update:modelValue` whenever the value binding changes
2185
+ const onChangeHandler = function handleChangeWithModel(e, shouldValidate = true) {
2186
+ handleChange(e, shouldValidate);
2187
+ };
2188
+ const sharedProps = computed(() => {
2189
+ const { validateOnInput, validateOnChange, validateOnBlur, validateOnModelUpdate } = resolveValidationTriggers(props);
2190
+ function baseOnBlur(e) {
2191
+ handleBlur(e, validateOnBlur);
2192
+ if (isCallable(ctx.attrs.onBlur)) {
2193
+ ctx.attrs.onBlur(e);
2194
+ }
2195
+ }
2196
+ function baseOnInput(e) {
2197
+ onChangeHandler(e, validateOnInput);
2198
+ if (isCallable(ctx.attrs.onInput)) {
2199
+ ctx.attrs.onInput(e);
2200
+ }
2201
+ }
2202
+ function baseOnChange(e) {
2203
+ onChangeHandler(e, validateOnChange);
2204
+ if (isCallable(ctx.attrs.onChange)) {
2205
+ ctx.attrs.onChange(e);
2206
+ }
2207
+ }
2208
+ const attrs = {
2209
+ name: props.name,
2210
+ onBlur: baseOnBlur,
2211
+ onInput: baseOnInput,
2212
+ onChange: baseOnChange,
2213
+ };
2214
+ attrs['onUpdate:modelValue'] = e => onChangeHandler(e, validateOnModelUpdate);
2215
+ return attrs;
2216
+ });
2217
+ const fieldProps = computed(() => {
2218
+ const attrs = Object.assign({}, sharedProps.value);
2219
+ if (hasCheckedAttr(ctx.attrs.type) && checked) {
2220
+ attrs.checked = checked.value;
2221
+ }
2222
+ const tag = resolveTag(props, ctx);
2223
+ if (shouldHaveValueBinding(tag, ctx.attrs)) {
2224
+ attrs.value = value.value;
2225
+ }
2226
+ return attrs;
2227
+ });
2228
+ const componentProps = computed(() => {
2229
+ return Object.assign(Object.assign({}, sharedProps.value), { modelValue: value.value });
2230
+ });
2231
+ function slotProps() {
2232
+ return {
2233
+ field: fieldProps.value,
2234
+ componentField: componentProps.value,
2235
+ value: value.value,
2236
+ meta,
2237
+ errors: errors.value,
2238
+ errorMessage: errorMessage.value,
2239
+ validate: validateField,
2240
+ resetField,
2241
+ handleChange: onChangeHandler,
2242
+ handleInput: e => onChangeHandler(e, false),
2243
+ handleReset,
2244
+ handleBlur: sharedProps.value.onBlur,
2245
+ setTouched,
2246
+ setErrors,
2247
+ setValue,
2248
+ };
2249
+ }
2250
+ ctx.expose({
2251
+ value,
2252
+ meta,
2253
+ errors,
2254
+ errorMessage,
2255
+ setErrors,
2256
+ setTouched,
2257
+ setValue,
2258
+ reset: resetField,
2259
+ validate: validateField,
2260
+ handleChange,
2261
+ });
2262
+ return () => {
2263
+ const tag = resolveDynamicComponent(resolveTag(props, ctx));
2264
+ const children = normalizeChildren(tag, ctx, slotProps);
2265
+ if (tag) {
2266
+ return h(tag, Object.assign(Object.assign({}, ctx.attrs), fieldProps.value), children);
2267
+ }
2268
+ return children;
2269
+ };
2270
+ },
2271
+ });
2272
+ function resolveTag(props, ctx) {
2273
+ let tag = props.as || '';
2274
+ if (!props.as && !ctx.slots.default) {
2275
+ tag = 'input';
2276
+ }
2277
+ return tag;
2278
+ }
2279
+ function resolveValidationTriggers(props) {
2280
+ var _a, _b, _c, _d;
2281
+ const { validateOnInput, validateOnChange, validateOnBlur, validateOnModelUpdate } = getConfig();
2282
+ return {
2283
+ validateOnInput: (_a = props.validateOnInput) !== null && _a !== void 0 ? _a : validateOnInput,
2284
+ validateOnChange: (_b = props.validateOnChange) !== null && _b !== void 0 ? _b : validateOnChange,
2285
+ validateOnBlur: (_c = props.validateOnBlur) !== null && _c !== void 0 ? _c : validateOnBlur,
2286
+ validateOnModelUpdate: (_d = props.validateOnModelUpdate) !== null && _d !== void 0 ? _d : validateOnModelUpdate,
2287
+ };
2288
+ }
2289
+ function resolveInitialValue(props, ctx) {
2290
+ // Gets the initial value either from `value` prop/attr or `v-model` binding (modelValue)
2291
+ // For checkboxes and radio buttons it will always be the model value not the `value` attribute
2292
+ if (!hasCheckedAttr(ctx.attrs.type)) {
2293
+ return isPropPresent(props, 'modelValue') ? props.modelValue : ctx.attrs.value;
2294
+ }
2295
+ return isPropPresent(props, 'modelValue') ? props.modelValue : undefined;
2296
+ }
2297
+ const Field = FieldImpl;
2298
+
2299
+ let FORM_COUNTER = 0;
2300
+ const PRIVATE_PATH_STATE_KEYS = ['bails', 'fieldsCount', 'id', 'multiple', 'type', 'validate'];
2301
+ function resolveInitialValues(opts) {
2302
+ const givenInitial = (opts === null || opts === void 0 ? void 0 : opts.initialValues) || {};
2303
+ const providedValues = Object.assign({}, toValue(givenInitial));
2304
+ const schema = unref(opts === null || opts === void 0 ? void 0 : opts.validationSchema);
2305
+ if (schema && isTypedSchema(schema) && isCallable(schema.cast)) {
2306
+ return klona(schema.cast(providedValues) || {});
2307
+ }
2308
+ return klona(providedValues);
2309
+ }
2310
+ function useForm(opts) {
2311
+ var _a;
2312
+ const formId = FORM_COUNTER++;
2313
+ // Prevents fields from double resetting their values, which causes checkboxes to toggle their initial value
2314
+ let FIELD_ID_COUNTER = 0;
2315
+ // If the form is currently submitting
2316
+ const isSubmitting = ref(false);
2317
+ // If the form is currently validating
2318
+ const isValidating = ref(false);
2319
+ // The number of times the user tried to submit the form
2320
+ const submitCount = ref(0);
2321
+ // field arrays managed by this form
2322
+ const fieldArrays = [];
2323
+ // a private ref for all form values
2324
+ const formValues = reactive(resolveInitialValues(opts));
2325
+ const pathStates = ref([]);
2326
+ const extraErrorsBag = ref({});
2327
+ const pathStateLookup = ref({});
2328
+ const rebuildPathLookup = debounceNextTick(() => {
2329
+ pathStateLookup.value = pathStates.value.reduce((names, state) => {
2330
+ names[normalizeFormPath(toValue(state.path))] = state;
2331
+ return names;
2332
+ }, {});
2333
+ });
2334
+ /**
2335
+ * Manually sets an error message on a specific field
2336
+ */
2337
+ function setFieldError(field, message) {
2338
+ const state = findPathState(field);
2339
+ if (!state) {
2340
+ if (typeof field === 'string') {
2341
+ extraErrorsBag.value[normalizeFormPath(field)] = normalizeErrorItem(message);
2342
+ }
2343
+ return;
2344
+ }
2345
+ // Move the error from the extras path if exists
2346
+ if (typeof field === 'string') {
2347
+ const normalizedPath = normalizeFormPath(field);
2348
+ if (extraErrorsBag.value[normalizedPath]) {
2349
+ delete extraErrorsBag.value[normalizedPath];
2350
+ }
2351
+ }
2352
+ state.errors = normalizeErrorItem(message);
2353
+ state.valid = !state.errors.length;
2354
+ }
2355
+ /**
2356
+ * Sets errors for the fields specified in the object
2357
+ */
2358
+ function setErrors(paths) {
2359
+ keysOf(paths).forEach(path => {
2360
+ setFieldError(path, paths[path]);
2361
+ });
2362
+ }
2363
+ if (opts === null || opts === void 0 ? void 0 : opts.initialErrors) {
2364
+ setErrors(opts.initialErrors);
2365
+ }
2366
+ const errorBag = computed(() => {
2367
+ const pathErrors = pathStates.value.reduce((acc, state) => {
2368
+ if (state.errors.length) {
2369
+ acc[state.path] = state.errors;
2370
+ }
2371
+ return acc;
2372
+ }, {});
2373
+ return Object.assign(Object.assign({}, extraErrorsBag.value), pathErrors);
2374
+ });
2375
+ // Gets the first error of each field
2376
+ const errors = computed(() => {
2377
+ return keysOf(errorBag.value).reduce((acc, key) => {
2378
+ const errors = errorBag.value[key];
2379
+ if (errors === null || errors === void 0 ? void 0 : errors.length) {
2380
+ acc[key] = errors[0];
2381
+ }
2382
+ return acc;
2383
+ }, {});
2384
+ });
2385
+ /**
2386
+ * Holds a computed reference to all fields names and labels
2387
+ */
2388
+ const fieldNames = computed(() => {
2389
+ return pathStates.value.reduce((names, state) => {
2390
+ names[state.path] = { name: state.path || '', label: state.label || '' };
2391
+ return names;
2392
+ }, {});
2393
+ });
2394
+ const fieldBailsMap = computed(() => {
2395
+ return pathStates.value.reduce((map, state) => {
2396
+ var _a;
2397
+ map[state.path] = (_a = state.bails) !== null && _a !== void 0 ? _a : true;
2398
+ return map;
2399
+ }, {});
2400
+ });
2401
+ // mutable non-reactive reference to initial errors
2402
+ // we need this to process initial errors then unset them
2403
+ const initialErrors = Object.assign({}, ((opts === null || opts === void 0 ? void 0 : opts.initialErrors) || {}));
2404
+ const keepValuesOnUnmount = (_a = opts === null || opts === void 0 ? void 0 : opts.keepValuesOnUnmount) !== null && _a !== void 0 ? _a : false;
2405
+ // initial form values
2406
+ const { initialValues, originalInitialValues, setInitialValues } = useFormInitialValues(pathStates, formValues, opts);
2407
+ // form meta aggregations
2408
+ const meta = useFormMeta(pathStates, formValues, originalInitialValues, errors);
2409
+ const controlledValues = computed(() => {
2410
+ return pathStates.value.reduce((acc, state) => {
2411
+ const value = getFromPath(formValues, state.path);
2412
+ setInPath(acc, state.path, value);
2413
+ return acc;
2414
+ }, {});
2415
+ });
2416
+ const schema = opts === null || opts === void 0 ? void 0 : opts.validationSchema;
2417
+ function createPathState(path, config) {
2418
+ var _a, _b;
2419
+ const initialValue = computed(() => getFromPath(initialValues.value, toValue(path)));
2420
+ const pathStateExists = pathStateLookup.value[toValue(path)];
2421
+ const isCheckboxOrRadio = (config === null || config === void 0 ? void 0 : config.type) === 'checkbox' || (config === null || config === void 0 ? void 0 : config.type) === 'radio';
2422
+ if (pathStateExists && isCheckboxOrRadio) {
2423
+ pathStateExists.multiple = true;
2424
+ const id = FIELD_ID_COUNTER++;
2425
+ if (Array.isArray(pathStateExists.id)) {
2426
+ pathStateExists.id.push(id);
2427
+ }
2428
+ else {
2429
+ pathStateExists.id = [pathStateExists.id, id];
2430
+ }
2431
+ pathStateExists.fieldsCount++;
2432
+ pathStateExists.__flags.pendingUnmount[id] = false;
2433
+ return pathStateExists;
2434
+ }
2435
+ const currentValue = computed(() => getFromPath(formValues, toValue(path)));
2436
+ const pathValue = toValue(path);
2437
+ const unsetBatchIndex = UNSET_BATCH.findIndex(_path => _path === pathValue);
2438
+ if (unsetBatchIndex !== -1) {
2439
+ UNSET_BATCH.splice(unsetBatchIndex, 1);
2440
+ }
2441
+ const isRequired = computed(() => {
2442
+ var _a, _b, _c, _d;
2443
+ const schemaValue = toValue(schema);
2444
+ if (isTypedSchema(schemaValue)) {
2445
+ return (_b = (_a = schemaValue.describe) === null || _a === void 0 ? void 0 : _a.call(schemaValue, toValue(path)).required) !== null && _b !== void 0 ? _b : false;
2446
+ }
2447
+ // Path own schema
2448
+ const configSchemaValue = toValue(config === null || config === void 0 ? void 0 : config.schema);
2449
+ if (isTypedSchema(configSchemaValue)) {
2450
+ return (_d = (_c = configSchemaValue.describe) === null || _c === void 0 ? void 0 : _c.call(configSchemaValue).required) !== null && _d !== void 0 ? _d : false;
2451
+ }
2452
+ return false;
2453
+ });
2454
+ const id = FIELD_ID_COUNTER++;
2455
+ const state = reactive({
2456
+ id,
2457
+ path,
2458
+ touched: false,
2459
+ pending: false,
2460
+ valid: true,
2461
+ validated: !!((_a = initialErrors[pathValue]) === null || _a === void 0 ? void 0 : _a.length),
2462
+ required: isRequired,
2463
+ initialValue,
2464
+ errors: shallowRef([]),
2465
+ bails: (_b = config === null || config === void 0 ? void 0 : config.bails) !== null && _b !== void 0 ? _b : false,
2466
+ label: config === null || config === void 0 ? void 0 : config.label,
2467
+ type: (config === null || config === void 0 ? void 0 : config.type) || 'default',
2468
+ value: currentValue,
2469
+ multiple: false,
2470
+ __flags: {
2471
+ pendingUnmount: { [id]: false },
2472
+ pendingReset: false,
2473
+ },
2474
+ fieldsCount: 1,
2475
+ validate: config === null || config === void 0 ? void 0 : config.validate,
2476
+ dirty: computed(() => {
2477
+ return !isEqual(unref(currentValue), unref(initialValue));
2478
+ }),
2479
+ });
2480
+ pathStates.value.push(state);
2481
+ pathStateLookup.value[pathValue] = state;
2482
+ rebuildPathLookup();
2483
+ if (errors.value[pathValue] && !initialErrors[pathValue]) {
2484
+ nextTick(() => {
2485
+ validateField(pathValue, { mode: 'silent' });
2486
+ });
2487
+ }
2488
+ // Handles when a path changes
2489
+ if (isRef(path)) {
2490
+ watch(path, newPath => {
2491
+ rebuildPathLookup();
2492
+ const nextValue = klona(currentValue.value);
2493
+ pathStateLookup.value[newPath] = state;
2494
+ nextTick(() => {
2495
+ setInPath(formValues, newPath, nextValue);
2496
+ });
2497
+ });
2498
+ }
2499
+ return state;
2500
+ }
2501
+ /**
2502
+ * Batches validation runs in 5ms batches
2503
+ * Must have two distinct batch queues to make sure they don't override each other settings #3783
2504
+ */
2505
+ const debouncedSilentValidation = debounceAsync(_validateSchema, 5);
2506
+ const debouncedValidation = debounceAsync(_validateSchema, 5);
2507
+ const validateSchema = withLatest(async (mode) => {
2508
+ return (await (mode === 'silent'
2509
+ ? debouncedSilentValidation()
2510
+ : debouncedValidation()));
2511
+ }, (formResult, [mode]) => {
2512
+ // fields by id lookup
2513
+ // errors fields names, we need it to also check if custom errors are updated
2514
+ const currentErrorsPaths = keysOf(formCtx.errorBag.value);
2515
+ // collect all the keys from the schema and all fields
2516
+ // this ensures we have a complete key map of all the fields
2517
+ const paths = [
2518
+ ...new Set([...keysOf(formResult.results), ...pathStates.value.map(p => p.path), ...currentErrorsPaths]),
2519
+ ].sort();
2520
+ // aggregates the paths into a single result object while applying the results on the fields
2521
+ const results = paths.reduce((validation, _path) => {
2522
+ var _a;
2523
+ const expectedPath = _path;
2524
+ const pathState = findPathState(expectedPath) || findHoistedPath(expectedPath);
2525
+ const messages = ((_a = formResult.results[expectedPath]) === null || _a === void 0 ? void 0 : _a.errors) || [];
2526
+ // This is the real path of the field, because it might've been a hoisted field
2527
+ const path = (toValue(pathState === null || pathState === void 0 ? void 0 : pathState.path) || expectedPath);
2528
+ // It is possible that multiple paths are collected across loops
2529
+ // We want to merge them to avoid overriding any iteration's results
2530
+ const fieldResult = mergeValidationResults({ errors: messages, valid: !messages.length }, validation.results[path]);
2531
+ validation.results[path] = fieldResult;
2532
+ if (!fieldResult.valid) {
2533
+ validation.errors[path] = fieldResult.errors[0];
2534
+ }
2535
+ // clean up extra errors if path state exists
2536
+ if (pathState && extraErrorsBag.value[path]) {
2537
+ delete extraErrorsBag.value[path];
2538
+ }
2539
+ // field not rendered
2540
+ if (!pathState) {
2541
+ setFieldError(path, messages);
2542
+ return validation;
2543
+ }
2544
+ // always update the valid flag regardless of the mode
2545
+ pathState.valid = fieldResult.valid;
2546
+ if (mode === 'silent') {
2547
+ return validation;
2548
+ }
2549
+ if (mode === 'validated-only' && !pathState.validated) {
2550
+ return validation;
2551
+ }
2552
+ setFieldError(pathState, fieldResult.errors);
2553
+ return validation;
2554
+ }, {
2555
+ valid: formResult.valid,
2556
+ results: {},
2557
+ errors: {},
2558
+ source: formResult.source,
2559
+ });
2560
+ if (formResult.values) {
2561
+ results.values = formResult.values;
2562
+ results.source = formResult.source;
2563
+ }
2564
+ keysOf(results.results).forEach(path => {
2565
+ var _a;
2566
+ const pathState = findPathState(path);
2567
+ if (!pathState) {
2568
+ return;
2569
+ }
2570
+ if (mode === 'silent') {
2571
+ return;
2572
+ }
2573
+ if (mode === 'validated-only' && !pathState.validated) {
2574
+ return;
2575
+ }
2576
+ setFieldError(pathState, (_a = results.results[path]) === null || _a === void 0 ? void 0 : _a.errors);
2577
+ });
2578
+ return results;
2579
+ });
2580
+ function mutateAllPathState(mutation) {
2581
+ pathStates.value.forEach(mutation);
2582
+ }
2583
+ function findPathState(path) {
2584
+ const normalizedPath = typeof path === 'string' ? normalizeFormPath(path) : path;
2585
+ const pathState = typeof normalizedPath === 'string' ? pathStateLookup.value[normalizedPath] : normalizedPath;
2586
+ return pathState;
2587
+ }
2588
+ function findHoistedPath(path) {
2589
+ const candidates = pathStates.value.filter(state => path.startsWith(state.path));
2590
+ return candidates.reduce((bestCandidate, candidate) => {
2591
+ if (!bestCandidate) {
2592
+ return candidate;
2593
+ }
2594
+ return (candidate.path.length > bestCandidate.path.length ? candidate : bestCandidate);
2595
+ }, undefined);
2596
+ }
2597
+ let UNSET_BATCH = [];
2598
+ let PENDING_UNSET;
2599
+ function unsetPathValue(path) {
2600
+ UNSET_BATCH.push(path);
2601
+ if (!PENDING_UNSET) {
2602
+ PENDING_UNSET = nextTick(() => {
2603
+ const sortedPaths = [...UNSET_BATCH].sort().reverse();
2604
+ sortedPaths.forEach(p => {
2605
+ unsetPath(formValues, p);
2606
+ });
2607
+ UNSET_BATCH = [];
2608
+ PENDING_UNSET = null;
2609
+ });
2610
+ }
2611
+ return PENDING_UNSET;
2612
+ }
2613
+ function makeSubmissionFactory(onlyControlled) {
2614
+ return function submitHandlerFactory(fn, onValidationError) {
2615
+ return function submissionHandler(e) {
2616
+ if (e instanceof Event) {
2617
+ e.preventDefault();
2618
+ e.stopPropagation();
2619
+ }
2620
+ // Touch all fields
2621
+ mutateAllPathState(s => (s.touched = true));
2622
+ isSubmitting.value = true;
2623
+ submitCount.value++;
2624
+ return validate()
2625
+ .then(result => {
2626
+ const values = klona(formValues);
2627
+ if (result.valid && typeof fn === 'function') {
2628
+ const controlled = klona(controlledValues.value);
2629
+ let submittedValues = (onlyControlled ? controlled : values);
2630
+ if (result.values) {
2631
+ submittedValues =
2632
+ result.source === 'schema'
2633
+ ? result.values
2634
+ : Object.assign({}, submittedValues, result.values);
2635
+ }
2636
+ return fn(submittedValues, {
2637
+ evt: e,
2638
+ controlledValues: controlled,
2639
+ setErrors,
2640
+ setFieldError,
2641
+ setTouched,
2642
+ setFieldTouched,
2643
+ setValues,
2644
+ setFieldValue,
2645
+ resetForm,
2646
+ resetField,
2647
+ });
2648
+ }
2649
+ if (!result.valid && typeof onValidationError === 'function') {
2650
+ onValidationError({
2651
+ values,
2652
+ evt: e,
2653
+ errors: result.errors,
2654
+ results: result.results,
2655
+ });
2656
+ }
2657
+ })
2658
+ .then(returnVal => {
2659
+ isSubmitting.value = false;
2660
+ return returnVal;
2661
+ }, err => {
2662
+ isSubmitting.value = false;
2663
+ // re-throw the err so it doesn't go silent
2664
+ throw err;
2665
+ });
2666
+ };
2667
+ };
2668
+ }
2669
+ const handleSubmitImpl = makeSubmissionFactory(false);
2670
+ const handleSubmit = handleSubmitImpl;
2671
+ handleSubmit.withControlled = makeSubmissionFactory(true);
2672
+ function removePathState(path, id) {
2673
+ const idx = pathStates.value.findIndex(s => {
2674
+ return s.path === path && (Array.isArray(s.id) ? s.id.includes(id) : s.id === id);
2675
+ });
2676
+ const pathState = pathStates.value[idx];
2677
+ if (idx === -1 || !pathState) {
2678
+ return;
2679
+ }
2680
+ nextTick(() => {
2681
+ validateField(path, { mode: 'silent', warn: false });
2682
+ });
2683
+ if (pathState.multiple && pathState.fieldsCount) {
2684
+ pathState.fieldsCount--;
2685
+ }
2686
+ if (Array.isArray(pathState.id)) {
2687
+ const idIndex = pathState.id.indexOf(id);
2688
+ if (idIndex >= 0) {
2689
+ pathState.id.splice(idIndex, 1);
2690
+ }
2691
+ delete pathState.__flags.pendingUnmount[id];
2692
+ }
2693
+ if (!pathState.multiple || pathState.fieldsCount <= 0) {
2694
+ pathStates.value.splice(idx, 1);
2695
+ unsetInitialValue(path);
2696
+ rebuildPathLookup();
2697
+ delete pathStateLookup.value[path];
2698
+ }
2699
+ }
2700
+ function destroyPath(path) {
2701
+ keysOf(pathStateLookup.value).forEach(key => {
2702
+ if (key.startsWith(path)) {
2703
+ delete pathStateLookup.value[key];
2704
+ }
2705
+ });
2706
+ pathStates.value = pathStates.value.filter(s => !s.path.startsWith(path));
2707
+ nextTick(() => {
2708
+ rebuildPathLookup();
2709
+ });
2710
+ }
2711
+ const formCtx = {
2712
+ formId,
2713
+ values: formValues,
2714
+ controlledValues,
2715
+ errorBag,
2716
+ errors,
2717
+ schema,
2718
+ submitCount,
2719
+ meta,
2720
+ isSubmitting,
2721
+ isValidating,
2722
+ fieldArrays,
2723
+ keepValuesOnUnmount,
2724
+ validateSchema: unref(schema) ? validateSchema : undefined,
2725
+ validate,
2726
+ setFieldError,
2727
+ validateField,
2728
+ setFieldValue,
2729
+ setValues,
2730
+ setErrors,
2731
+ setFieldTouched,
2732
+ setTouched,
2733
+ resetForm,
2734
+ resetField,
2735
+ handleSubmit,
2736
+ useFieldModel,
2737
+ defineInputBinds,
2738
+ defineComponentBinds: defineComponentBinds,
2739
+ defineField,
2740
+ stageInitialValue,
2741
+ unsetInitialValue,
2742
+ setFieldInitialValue,
2743
+ createPathState,
2744
+ getPathState: findPathState,
2745
+ unsetPathValue,
2746
+ removePathState,
2747
+ initialValues: initialValues,
2748
+ getAllPathStates: () => pathStates.value,
2749
+ destroyPath,
2750
+ isFieldTouched,
2751
+ isFieldDirty,
2752
+ isFieldValid,
2753
+ };
2754
+ /**
2755
+ * Sets a single field value
2756
+ */
2757
+ function setFieldValue(field, value, shouldValidate = true) {
2758
+ const clonedValue = klona(value);
2759
+ const path = typeof field === 'string' ? field : field.path;
2760
+ const pathState = findPathState(path);
2761
+ if (!pathState) {
2762
+ createPathState(path);
2763
+ }
2764
+ setInPath(formValues, path, clonedValue);
2765
+ if (shouldValidate) {
2766
+ validateField(path);
2767
+ }
2768
+ }
2769
+ function forceSetValues(fields, shouldValidate = true) {
2770
+ // clean up old values
2771
+ keysOf(formValues).forEach(key => {
2772
+ delete formValues[key];
2773
+ });
2774
+ // set up new values
2775
+ keysOf(fields).forEach(path => {
2776
+ setFieldValue(path, fields[path], false);
2777
+ });
2778
+ if (shouldValidate) {
2779
+ validate();
2780
+ }
2781
+ }
2782
+ /**
2783
+ * Sets multiple fields values
2784
+ */
2785
+ function setValues(fields, shouldValidate = true) {
2786
+ merge(formValues, fields);
2787
+ // regenerate the arrays when the form values change
2788
+ fieldArrays.forEach(f => f && f.reset());
2789
+ if (shouldValidate) {
2790
+ validate();
2791
+ }
2792
+ }
2793
+ function createModel(path, shouldValidate) {
2794
+ const pathState = findPathState(toValue(path)) || createPathState(path);
2795
+ return computed({
2796
+ get() {
2797
+ return pathState.value;
2798
+ },
2799
+ set(value) {
2800
+ var _a;
2801
+ const pathValue = toValue(path);
2802
+ setFieldValue(pathValue, value, (_a = toValue(shouldValidate)) !== null && _a !== void 0 ? _a : false);
2803
+ },
2804
+ });
2805
+ }
2806
+ /**
2807
+ * Sets the touched meta state on a field
2808
+ */
2809
+ function setFieldTouched(field, isTouched) {
2810
+ const pathState = findPathState(field);
2811
+ if (pathState) {
2812
+ pathState.touched = isTouched;
2813
+ }
2814
+ }
2815
+ function isFieldTouched(field) {
2816
+ const pathState = findPathState(field);
2817
+ if (pathState) {
2818
+ return pathState.touched;
2819
+ }
2820
+ // Find all nested paths and consider their touched state
2821
+ return pathStates.value.filter(s => s.path.startsWith(field)).some(s => s.touched);
2822
+ }
2823
+ function isFieldDirty(field) {
2824
+ const pathState = findPathState(field);
2825
+ if (pathState) {
2826
+ return pathState.dirty;
2827
+ }
2828
+ return pathStates.value.filter(s => s.path.startsWith(field)).some(s => s.dirty);
2829
+ }
2830
+ function isFieldValid(field) {
2831
+ const pathState = findPathState(field);
2832
+ if (pathState) {
2833
+ return pathState.valid;
2834
+ }
2835
+ return pathStates.value.filter(s => s.path.startsWith(field)).every(s => s.valid);
2836
+ }
2837
+ /**
2838
+ * Sets the touched meta state on multiple fields
2839
+ */
2840
+ function setTouched(fields) {
2841
+ if (typeof fields === 'boolean') {
2842
+ mutateAllPathState(state => {
2843
+ state.touched = fields;
2844
+ });
2845
+ return;
2846
+ }
2847
+ keysOf(fields).forEach(field => {
2848
+ setFieldTouched(field, !!fields[field]);
2849
+ });
2850
+ }
2851
+ function resetField(field, state) {
2852
+ var _a;
2853
+ const newValue = state && 'value' in state ? state.value : getFromPath(initialValues.value, field);
2854
+ const pathState = findPathState(field);
2855
+ if (pathState) {
2856
+ pathState.__flags.pendingReset = true;
2857
+ }
2858
+ setFieldInitialValue(field, klona(newValue), true);
2859
+ setFieldValue(field, newValue, false);
2860
+ setFieldTouched(field, (_a = state === null || state === void 0 ? void 0 : state.touched) !== null && _a !== void 0 ? _a : false);
2861
+ setFieldError(field, (state === null || state === void 0 ? void 0 : state.errors) || []);
2862
+ nextTick(() => {
2863
+ if (pathState) {
2864
+ pathState.__flags.pendingReset = false;
2865
+ }
2866
+ });
2867
+ }
2868
+ /**
2869
+ * Resets all fields
2870
+ */
2871
+ function resetForm(resetState, opts) {
2872
+ let newValues = klona((resetState === null || resetState === void 0 ? void 0 : resetState.values) ? resetState.values : originalInitialValues.value);
2873
+ newValues = (opts === null || opts === void 0 ? void 0 : opts.force) ? newValues : merge(originalInitialValues.value, newValues);
2874
+ newValues = isTypedSchema(schema) && isCallable(schema.cast) ? schema.cast(newValues) : newValues;
2875
+ setInitialValues(newValues, { force: opts === null || opts === void 0 ? void 0 : opts.force });
2876
+ mutateAllPathState(state => {
2877
+ var _a;
2878
+ state.__flags.pendingReset = true;
2879
+ state.validated = false;
2880
+ state.touched = ((_a = resetState === null || resetState === void 0 ? void 0 : resetState.touched) === null || _a === void 0 ? void 0 : _a[state.path]) || false;
2881
+ setFieldValue(state.path, getFromPath(newValues, state.path), false);
2882
+ setFieldError(state.path, undefined);
2883
+ });
2884
+ (opts === null || opts === void 0 ? void 0 : opts.force) ? forceSetValues(newValues, false) : setValues(newValues, false);
2885
+ setErrors((resetState === null || resetState === void 0 ? void 0 : resetState.errors) || {});
2886
+ submitCount.value = (resetState === null || resetState === void 0 ? void 0 : resetState.submitCount) || 0;
2887
+ nextTick(() => {
2888
+ validate({ mode: 'silent' });
2889
+ mutateAllPathState(state => {
2890
+ state.__flags.pendingReset = false;
2891
+ });
2892
+ });
2893
+ }
2894
+ async function validate(opts) {
2895
+ const mode = (opts === null || opts === void 0 ? void 0 : opts.mode) || 'force';
2896
+ if (mode === 'force') {
2897
+ mutateAllPathState(f => (f.validated = true));
2898
+ }
2899
+ if (formCtx.validateSchema) {
2900
+ return formCtx.validateSchema(mode);
2901
+ }
2902
+ isValidating.value = true;
2903
+ // No schema, each field is responsible to validate itself
2904
+ const validations = await Promise.all(pathStates.value.map(state => {
2905
+ if (!state.validate) {
2906
+ return Promise.resolve({
2907
+ key: state.path,
2908
+ valid: true,
2909
+ errors: [],
2910
+ value: undefined,
2911
+ });
2912
+ }
2913
+ return state.validate(opts).then(result => {
2914
+ return {
2915
+ key: state.path,
2916
+ valid: result.valid,
2917
+ errors: result.errors,
2918
+ value: result.value,
2919
+ };
2920
+ });
2921
+ }));
2922
+ isValidating.value = false;
2923
+ const results = {};
2924
+ const errors = {};
2925
+ const values = {};
2926
+ for (const validation of validations) {
2927
+ results[validation.key] = {
2928
+ valid: validation.valid,
2929
+ errors: validation.errors,
2930
+ };
2931
+ if (validation.value) {
2932
+ setInPath(values, validation.key, validation.value);
2933
+ }
2934
+ if (validation.errors.length) {
2935
+ errors[validation.key] = validation.errors[0];
2936
+ }
2937
+ }
2938
+ return {
2939
+ valid: validations.every(r => r.valid),
2940
+ results,
2941
+ errors,
2942
+ values,
2943
+ source: 'fields',
2944
+ };
2945
+ }
2946
+ async function validateField(path, opts) {
2947
+ var _a;
2948
+ const state = findPathState(path);
2949
+ if (state && (opts === null || opts === void 0 ? void 0 : opts.mode) !== 'silent') {
2950
+ state.validated = true;
2951
+ }
2952
+ if (schema) {
2953
+ const { results } = await validateSchema((opts === null || opts === void 0 ? void 0 : opts.mode) || 'validated-only');
2954
+ return results[path] || { errors: [], valid: true };
2955
+ }
2956
+ if (state === null || state === void 0 ? void 0 : state.validate) {
2957
+ return state.validate(opts);
2958
+ }
2959
+ const shouldWarn = !state && ((_a = opts === null || opts === void 0 ? void 0 : opts.warn) !== null && _a !== void 0 ? _a : true);
2960
+ if (shouldWarn) {
2961
+ if (("production" !== 'production')) {
2962
+ warn$1(`field with path ${path} was not found`);
2963
+ }
2964
+ }
2965
+ return Promise.resolve({ errors: [], valid: true });
2966
+ }
2967
+ function unsetInitialValue(path) {
2968
+ unsetPath(initialValues.value, path);
2969
+ }
2970
+ /**
2971
+ * Sneaky function to set initial field values
2972
+ */
2973
+ function stageInitialValue(path, value, updateOriginal = false) {
2974
+ setFieldInitialValue(path, value);
2975
+ setInPath(formValues, path, value);
2976
+ if (updateOriginal && !(opts === null || opts === void 0 ? void 0 : opts.initialValues)) {
2977
+ setInPath(originalInitialValues.value, path, klona(value));
2978
+ }
2979
+ }
2980
+ function setFieldInitialValue(path, value, updateOriginal = false) {
2981
+ setInPath(initialValues.value, path, klona(value));
2982
+ if (updateOriginal) {
2983
+ setInPath(originalInitialValues.value, path, klona(value));
2984
+ }
2985
+ }
2986
+ async function _validateSchema() {
2987
+ const schemaValue = unref(schema);
2988
+ if (!schemaValue) {
2989
+ return { valid: true, results: {}, errors: {}, source: 'none' };
2990
+ }
2991
+ isValidating.value = true;
2992
+ const formResult = isYupValidator(schemaValue) || isTypedSchema(schemaValue)
2993
+ ? await validateTypedSchema(schemaValue, formValues)
2994
+ : await validateObjectSchema(schemaValue, formValues, {
2995
+ names: fieldNames.value,
2996
+ bailsMap: fieldBailsMap.value,
2997
+ });
2998
+ isValidating.value = false;
2999
+ return formResult;
3000
+ }
3001
+ const submitForm = handleSubmit((_, { evt }) => {
3002
+ if (isFormSubmitEvent(evt)) {
3003
+ evt.target.submit();
3004
+ }
3005
+ });
3006
+ // Trigger initial validation
3007
+ onMounted(() => {
3008
+ if (opts === null || opts === void 0 ? void 0 : opts.initialErrors) {
3009
+ setErrors(opts.initialErrors);
3010
+ }
3011
+ if (opts === null || opts === void 0 ? void 0 : opts.initialTouched) {
3012
+ setTouched(opts.initialTouched);
3013
+ }
3014
+ // if validate on mount was enabled
3015
+ if (opts === null || opts === void 0 ? void 0 : opts.validateOnMount) {
3016
+ validate();
3017
+ return;
3018
+ }
3019
+ // otherwise run initial silent validation through schema if available
3020
+ // the useField should skip their own silent validation if a yup schema is present
3021
+ if (formCtx.validateSchema) {
3022
+ formCtx.validateSchema('silent');
3023
+ }
3024
+ });
3025
+ if (isRef(schema)) {
3026
+ watch(schema, () => {
3027
+ var _a;
3028
+ (_a = formCtx.validateSchema) === null || _a === void 0 ? void 0 : _a.call(formCtx, 'validated-only');
3029
+ });
3030
+ }
3031
+ // Provide injections
3032
+ provide(FormContextKey, formCtx);
3033
+ if (("production" !== 'production')) {
3034
+ registerFormWithDevTools(formCtx);
3035
+ watch(() => (Object.assign(Object.assign({ errors: errorBag.value }, meta.value), { values: formValues, isSubmitting: isSubmitting.value, isValidating: isValidating.value, submitCount: submitCount.value })), refreshInspector, {
3036
+ deep: true,
3037
+ });
3038
+ }
3039
+ function defineField(path, config) {
3040
+ const label = isCallable(config) ? undefined : config === null || config === void 0 ? void 0 : config.label;
3041
+ const pathState = (findPathState(toValue(path)) || createPathState(path, { label }));
3042
+ const evalConfig = () => (isCallable(config) ? config(omit(pathState, PRIVATE_PATH_STATE_KEYS)) : config || {});
3043
+ function onBlur() {
3044
+ var _a;
3045
+ pathState.touched = true;
3046
+ const validateOnBlur = (_a = evalConfig().validateOnBlur) !== null && _a !== void 0 ? _a : getConfig().validateOnBlur;
3047
+ if (validateOnBlur) {
3048
+ validateField(pathState.path);
3049
+ }
3050
+ }
3051
+ function onInput() {
3052
+ var _a;
3053
+ const validateOnInput = (_a = evalConfig().validateOnInput) !== null && _a !== void 0 ? _a : getConfig().validateOnInput;
3054
+ if (validateOnInput) {
3055
+ nextTick(() => {
3056
+ validateField(pathState.path);
3057
+ });
3058
+ }
3059
+ }
3060
+ function onChange() {
3061
+ var _a;
3062
+ const validateOnChange = (_a = evalConfig().validateOnChange) !== null && _a !== void 0 ? _a : getConfig().validateOnChange;
3063
+ if (validateOnChange) {
3064
+ nextTick(() => {
3065
+ validateField(pathState.path);
3066
+ });
3067
+ }
3068
+ }
3069
+ const props = computed(() => {
3070
+ const base = {
3071
+ onChange,
3072
+ onInput,
3073
+ onBlur,
3074
+ };
3075
+ if (isCallable(config)) {
3076
+ return Object.assign(Object.assign({}, base), (config(omit(pathState, PRIVATE_PATH_STATE_KEYS)).props || {}));
3077
+ }
3078
+ if (config === null || config === void 0 ? void 0 : config.props) {
3079
+ return Object.assign(Object.assign({}, base), config.props(omit(pathState, PRIVATE_PATH_STATE_KEYS)));
3080
+ }
3081
+ return base;
3082
+ });
3083
+ const model = createModel(path, () => { var _a, _b, _c; return (_c = (_a = evalConfig().validateOnModelUpdate) !== null && _a !== void 0 ? _a : (_b = getConfig()) === null || _b === void 0 ? void 0 : _b.validateOnModelUpdate) !== null && _c !== void 0 ? _c : true; });
3084
+ return [model, props];
3085
+ }
3086
+ function useFieldModel(pathOrPaths) {
3087
+ if (!Array.isArray(pathOrPaths)) {
3088
+ return createModel(pathOrPaths);
3089
+ }
3090
+ return pathOrPaths.map(p => createModel(p, true));
3091
+ }
3092
+ /**
3093
+ * @deprecated use defineField instead
3094
+ */
3095
+ function defineInputBinds(path, config) {
3096
+ const [model, props] = defineField(path, config);
3097
+ function onBlur() {
3098
+ props.value.onBlur();
3099
+ }
3100
+ function onInput(e) {
3101
+ const value = normalizeEventValue(e);
3102
+ setFieldValue(toValue(path), value, false);
3103
+ props.value.onInput();
3104
+ }
3105
+ function onChange(e) {
3106
+ const value = normalizeEventValue(e);
3107
+ setFieldValue(toValue(path), value, false);
3108
+ props.value.onChange();
3109
+ }
3110
+ return computed(() => {
3111
+ return Object.assign(Object.assign({}, props.value), { onBlur,
3112
+ onInput,
3113
+ onChange, value: model.value });
3114
+ });
3115
+ }
3116
+ /**
3117
+ * @deprecated use defineField instead
3118
+ */
3119
+ function defineComponentBinds(path, config) {
3120
+ const [model, props] = defineField(path, config);
3121
+ const pathState = findPathState(toValue(path));
3122
+ function onUpdateModelValue(value) {
3123
+ model.value = value;
3124
+ }
3125
+ return computed(() => {
3126
+ const conf = isCallable(config) ? config(omit(pathState, PRIVATE_PATH_STATE_KEYS)) : config || {};
3127
+ return Object.assign({ [conf.model || 'modelValue']: model.value, [`onUpdate:${conf.model || 'modelValue'}`]: onUpdateModelValue }, props.value);
3128
+ });
3129
+ }
3130
+ return Object.assign(Object.assign({}, formCtx), { values: readonly(formValues), handleReset: () => resetForm(), submitForm });
3131
+ }
3132
+ /**
3133
+ * Manages form meta aggregation
3134
+ */
3135
+ function useFormMeta(pathsState, currentValues, initialValues, errors) {
3136
+ const MERGE_STRATEGIES = {
3137
+ touched: 'some',
3138
+ pending: 'some',
3139
+ valid: 'every',
3140
+ };
3141
+ const isDirty = computed(() => {
3142
+ return !isEqual(currentValues, unref(initialValues));
3143
+ });
3144
+ function calculateFlags() {
3145
+ const states = pathsState.value;
3146
+ return keysOf(MERGE_STRATEGIES).reduce((acc, flag) => {
3147
+ const mergeMethod = MERGE_STRATEGIES[flag];
3148
+ acc[flag] = states[mergeMethod](s => s[flag]);
3149
+ return acc;
3150
+ }, {});
3151
+ }
3152
+ const flags = reactive(calculateFlags());
3153
+ watchEffect(() => {
3154
+ const value = calculateFlags();
3155
+ flags.touched = value.touched;
3156
+ flags.valid = value.valid;
3157
+ flags.pending = value.pending;
3158
+ });
3159
+ return computed(() => {
3160
+ return Object.assign(Object.assign({ initialValues: unref(initialValues) }, flags), { valid: flags.valid && !keysOf(errors.value).length, dirty: isDirty.value });
3161
+ });
3162
+ }
3163
+ /**
3164
+ * Manages the initial values prop
3165
+ */
3166
+ function useFormInitialValues(pathsState, formValues, opts) {
3167
+ const values = resolveInitialValues(opts);
3168
+ // these are the mutable initial values as the fields are mounted/unmounted
3169
+ const initialValues = ref(values);
3170
+ // these are the original initial value as provided by the user initially, they don't keep track of conditional fields
3171
+ // this is important because some conditional fields will overwrite the initial values for other fields who had the same name
3172
+ // like array fields, any push/insert operation will overwrite the initial values because they "create new fields"
3173
+ // so these are the values that the reset function should use
3174
+ // these only change when the user explicitly changes the initial values or when the user resets them with new values.
3175
+ const originalInitialValues = ref(klona(values));
3176
+ function setInitialValues(values, opts) {
3177
+ if (opts === null || opts === void 0 ? void 0 : opts.force) {
3178
+ initialValues.value = klona(values);
3179
+ originalInitialValues.value = klona(values);
3180
+ }
3181
+ else {
3182
+ initialValues.value = merge(klona(initialValues.value) || {}, klona(values));
3183
+ originalInitialValues.value = merge(klona(originalInitialValues.value) || {}, klona(values));
3184
+ }
3185
+ if (!(opts === null || opts === void 0 ? void 0 : opts.updateFields)) {
3186
+ return;
3187
+ }
3188
+ // update the pristine non-touched fields
3189
+ // those are excluded because it's unlikely you want to change the form values using initial values
3190
+ // we mostly watch them for API population or newly inserted fields
3191
+ // if the user API is taking too much time before user interaction they should consider disabling or hiding their inputs until the values are ready
3192
+ pathsState.value.forEach(state => {
3193
+ const wasTouched = state.touched;
3194
+ if (wasTouched) {
3195
+ return;
3196
+ }
3197
+ const newValue = getFromPath(initialValues.value, state.path);
3198
+ setInPath(formValues, state.path, klona(newValue));
3199
+ });
3200
+ }
3201
+ return {
3202
+ initialValues,
3203
+ originalInitialValues,
3204
+ setInitialValues,
3205
+ };
3206
+ }
3207
+ function mergeValidationResults(a, b) {
3208
+ if (!b) {
3209
+ return a;
3210
+ }
3211
+ return {
3212
+ valid: a.valid && b.valid,
3213
+ errors: [...a.errors, ...b.errors],
3214
+ };
3215
+ }
3216
+
3217
+ const FormImpl = /** #__PURE__ */ defineComponent({
3218
+ name: 'Form',
3219
+ inheritAttrs: false,
3220
+ props: {
3221
+ as: {
3222
+ type: null,
3223
+ default: 'form',
3224
+ },
3225
+ validationSchema: {
3226
+ type: Object,
3227
+ default: undefined,
3228
+ },
3229
+ initialValues: {
3230
+ type: Object,
3231
+ default: undefined,
3232
+ },
3233
+ initialErrors: {
3234
+ type: Object,
3235
+ default: undefined,
3236
+ },
3237
+ initialTouched: {
3238
+ type: Object,
3239
+ default: undefined,
3240
+ },
3241
+ validateOnMount: {
3242
+ type: Boolean,
3243
+ default: false,
3244
+ },
3245
+ onSubmit: {
3246
+ type: Function,
3247
+ default: undefined,
3248
+ },
3249
+ onInvalidSubmit: {
3250
+ type: Function,
3251
+ default: undefined,
3252
+ },
3253
+ keepValues: {
3254
+ type: Boolean,
3255
+ default: false,
3256
+ },
3257
+ },
3258
+ setup(props, ctx) {
3259
+ const validationSchema = toRef(props, 'validationSchema');
3260
+ const keepValues = toRef(props, 'keepValues');
3261
+ const { errors, errorBag, values, meta, isSubmitting, isValidating, submitCount, controlledValues, validate, validateField, handleReset, resetForm, handleSubmit, setErrors, setFieldError, setFieldValue, setValues, setFieldTouched, setTouched, resetField, } = useForm({
3262
+ validationSchema: validationSchema.value ? validationSchema : undefined,
3263
+ initialValues: props.initialValues,
3264
+ initialErrors: props.initialErrors,
3265
+ initialTouched: props.initialTouched,
3266
+ validateOnMount: props.validateOnMount,
3267
+ keepValuesOnUnmount: keepValues,
3268
+ });
3269
+ const submitForm = handleSubmit((_, { evt }) => {
3270
+ if (isFormSubmitEvent(evt)) {
3271
+ evt.target.submit();
3272
+ }
3273
+ }, props.onInvalidSubmit);
3274
+ const onSubmit = props.onSubmit ? handleSubmit(props.onSubmit, props.onInvalidSubmit) : submitForm;
3275
+ function handleFormReset(e) {
3276
+ if (isEvent(e)) {
3277
+ // Prevent default form reset behavior
3278
+ e.preventDefault();
3279
+ }
3280
+ handleReset();
3281
+ if (typeof ctx.attrs.onReset === 'function') {
3282
+ ctx.attrs.onReset();
3283
+ }
3284
+ }
3285
+ function handleScopedSlotSubmit(evt, onSubmit) {
3286
+ const onSuccess = typeof evt === 'function' && !onSubmit ? evt : onSubmit;
3287
+ return handleSubmit(onSuccess, props.onInvalidSubmit)(evt);
3288
+ }
3289
+ function getValues() {
3290
+ return klona(values);
3291
+ }
3292
+ function getMeta() {
3293
+ return klona(meta.value);
3294
+ }
3295
+ function getErrors() {
3296
+ return klona(errors.value);
3297
+ }
3298
+ function slotProps() {
3299
+ return {
3300
+ meta: meta.value,
3301
+ errors: errors.value,
3302
+ errorBag: errorBag.value,
3303
+ values,
3304
+ isSubmitting: isSubmitting.value,
3305
+ isValidating: isValidating.value,
3306
+ submitCount: submitCount.value,
3307
+ controlledValues: controlledValues.value,
3308
+ validate,
3309
+ validateField,
3310
+ handleSubmit: handleScopedSlotSubmit,
3311
+ handleReset,
3312
+ submitForm,
3313
+ setErrors,
3314
+ setFieldError,
3315
+ setFieldValue,
3316
+ setValues,
3317
+ setFieldTouched,
3318
+ setTouched,
3319
+ resetForm,
3320
+ resetField,
3321
+ getValues,
3322
+ getMeta,
3323
+ getErrors,
3324
+ };
3325
+ }
3326
+ // expose these functions and methods as part of public API
3327
+ ctx.expose({
3328
+ setFieldError,
3329
+ setErrors,
3330
+ setFieldValue,
3331
+ setValues,
3332
+ setFieldTouched,
3333
+ setTouched,
3334
+ resetForm,
3335
+ validate,
3336
+ validateField,
3337
+ resetField,
3338
+ getValues,
3339
+ getMeta,
3340
+ getErrors,
3341
+ values,
3342
+ meta,
3343
+ errors,
3344
+ });
3345
+ return function renderForm() {
3346
+ // avoid resolving the form component as itself
3347
+ const tag = props.as === 'form' ? props.as : !props.as ? null : resolveDynamicComponent(props.as);
3348
+ const children = normalizeChildren(tag, ctx, slotProps);
3349
+ if (!tag) {
3350
+ return children;
3351
+ }
3352
+ // Attributes to add on a native `form` tag
3353
+ const formAttrs = tag === 'form'
3354
+ ? {
3355
+ // Disables native validation as vee-validate will handle it.
3356
+ novalidate: true,
3357
+ }
3358
+ : {};
3359
+ return h(tag, Object.assign(Object.assign(Object.assign({}, formAttrs), ctx.attrs), { onSubmit, onReset: handleFormReset }), children);
3360
+ };
3361
+ },
3362
+ });
3363
+ const Form = FormImpl;
3364
+
3365
+ function useFieldArray(arrayPath) {
3366
+ const form = injectWithSelf(FormContextKey, undefined);
3367
+ const fields = ref([]);
3368
+ const noOp = () => { };
3369
+ const noOpApi = {
3370
+ fields,
3371
+ remove: noOp,
3372
+ push: noOp,
3373
+ swap: noOp,
3374
+ insert: noOp,
3375
+ update: noOp,
3376
+ replace: noOp,
3377
+ prepend: noOp,
3378
+ move: noOp,
3379
+ };
3380
+ if (!form) {
3381
+ if (("production" !== 'production')) {
3382
+ warn('FieldArray requires being a child of `<Form/>` or `useForm` being called before it. Array fields may not work correctly');
3383
+ }
3384
+ return noOpApi;
3385
+ }
3386
+ if (!unref(arrayPath)) {
3387
+ if (("production" !== 'production')) {
3388
+ warn('FieldArray requires a field path to be provided, did you forget to pass the `name` prop?');
3389
+ }
3390
+ return noOpApi;
3391
+ }
3392
+ const alreadyExists = form.fieldArrays.find(a => unref(a.path) === unref(arrayPath));
3393
+ if (alreadyExists) {
3394
+ return alreadyExists;
3395
+ }
3396
+ let entryCounter = 0;
3397
+ function getCurrentValues() {
3398
+ return getFromPath(form === null || form === void 0 ? void 0 : form.values, toValue(arrayPath), []) || [];
3399
+ }
3400
+ function initFields() {
3401
+ const currentValues = getCurrentValues();
3402
+ if (!Array.isArray(currentValues)) {
3403
+ return;
3404
+ }
3405
+ fields.value = currentValues.map((v, idx) => createEntry(v, idx, fields.value));
3406
+ updateEntryFlags();
3407
+ }
3408
+ initFields();
3409
+ function updateEntryFlags() {
3410
+ const fieldsLength = fields.value.length;
3411
+ for (let i = 0; i < fieldsLength; i++) {
3412
+ const entry = fields.value[i];
3413
+ entry.isFirst = i === 0;
3414
+ entry.isLast = i === fieldsLength - 1;
3415
+ }
3416
+ }
3417
+ function createEntry(value, idx, currentFields) {
3418
+ // Skips the work by returning the current entry if it already exists
3419
+ // This should make the `key` prop stable and doesn't cause more re-renders than needed
3420
+ // The value is computed and should update anyways
3421
+ if (currentFields && !isNullOrUndefined(idx) && currentFields[idx]) {
3422
+ return currentFields[idx];
3423
+ }
3424
+ const key = entryCounter++;
3425
+ const entry = {
3426
+ key,
3427
+ value: computedDeep({
3428
+ get() {
3429
+ const currentValues = getFromPath(form === null || form === void 0 ? void 0 : form.values, toValue(arrayPath), []) || [];
3430
+ const idx = fields.value.findIndex(e => e.key === key);
3431
+ return idx === -1 ? value : currentValues[idx];
3432
+ },
3433
+ set(value) {
3434
+ const idx = fields.value.findIndex(e => e.key === key);
3435
+ if (idx === -1) {
3436
+ if (("production" !== 'production')) {
3437
+ warn(`Attempting to update a non-existent array item`);
3438
+ }
3439
+ return;
3440
+ }
3441
+ update(idx, value);
3442
+ },
3443
+ }), // will be auto unwrapped
3444
+ isFirst: false,
3445
+ isLast: false,
3446
+ };
3447
+ return entry;
3448
+ }
3449
+ function afterMutation() {
3450
+ updateEntryFlags();
3451
+ // Should trigger a silent validation since a field may not do that #4096
3452
+ form === null || form === void 0 ? void 0 : form.validate({ mode: 'silent' });
3453
+ }
3454
+ function remove(idx) {
3455
+ const pathName = toValue(arrayPath);
3456
+ const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName);
3457
+ if (!pathValue || !Array.isArray(pathValue)) {
3458
+ return;
3459
+ }
3460
+ const newValue = [...pathValue];
3461
+ newValue.splice(idx, 1);
3462
+ const fieldPath = pathName + `[${idx}]`;
3463
+ form.destroyPath(fieldPath);
3464
+ form.unsetInitialValue(fieldPath);
3465
+ setInPath(form.values, pathName, newValue);
3466
+ fields.value.splice(idx, 1);
3467
+ afterMutation();
3468
+ }
3469
+ function push(initialValue) {
3470
+ const value = klona(initialValue);
3471
+ const pathName = toValue(arrayPath);
3472
+ const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName);
3473
+ const normalizedPathValue = isNullOrUndefined(pathValue) ? [] : pathValue;
3474
+ if (!Array.isArray(normalizedPathValue)) {
3475
+ return;
3476
+ }
3477
+ const newValue = [...normalizedPathValue];
3478
+ newValue.push(value);
3479
+ form.stageInitialValue(pathName + `[${newValue.length - 1}]`, value);
3480
+ setInPath(form.values, pathName, newValue);
3481
+ fields.value.push(createEntry(value));
3482
+ afterMutation();
3483
+ }
3484
+ function swap(indexA, indexB) {
3485
+ const pathName = toValue(arrayPath);
3486
+ const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName);
3487
+ if (!Array.isArray(pathValue) || !(indexA in pathValue) || !(indexB in pathValue)) {
3488
+ return;
3489
+ }
3490
+ const newValue = [...pathValue];
3491
+ const newFields = [...fields.value];
3492
+ // the old switcheroo
3493
+ const temp = newValue[indexA];
3494
+ newValue[indexA] = newValue[indexB];
3495
+ newValue[indexB] = temp;
3496
+ const tempEntry = newFields[indexA];
3497
+ newFields[indexA] = newFields[indexB];
3498
+ newFields[indexB] = tempEntry;
3499
+ setInPath(form.values, pathName, newValue);
3500
+ fields.value = newFields;
3501
+ updateEntryFlags();
3502
+ }
3503
+ function insert(idx, initialValue) {
3504
+ const value = klona(initialValue);
3505
+ const pathName = toValue(arrayPath);
3506
+ const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName);
3507
+ if (!Array.isArray(pathValue) || pathValue.length < idx) {
3508
+ return;
3509
+ }
3510
+ const newValue = [...pathValue];
3511
+ const newFields = [...fields.value];
3512
+ newValue.splice(idx, 0, value);
3513
+ newFields.splice(idx, 0, createEntry(value));
3514
+ setInPath(form.values, pathName, newValue);
3515
+ fields.value = newFields;
3516
+ afterMutation();
3517
+ }
3518
+ function replace(arr) {
3519
+ const pathName = toValue(arrayPath);
3520
+ form.stageInitialValue(pathName, arr);
3521
+ setInPath(form.values, pathName, arr);
3522
+ initFields();
3523
+ afterMutation();
3524
+ }
3525
+ function update(idx, value) {
3526
+ const pathName = toValue(arrayPath);
3527
+ const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName);
3528
+ if (!Array.isArray(pathValue) || pathValue.length - 1 < idx) {
3529
+ return;
3530
+ }
3531
+ setInPath(form.values, `${pathName}[${idx}]`, value);
3532
+ form === null || form === void 0 ? void 0 : form.validate({ mode: 'validated-only' });
3533
+ }
3534
+ function prepend(initialValue) {
3535
+ const value = klona(initialValue);
3536
+ const pathName = toValue(arrayPath);
3537
+ const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName);
3538
+ const normalizedPathValue = isNullOrUndefined(pathValue) ? [] : pathValue;
3539
+ if (!Array.isArray(normalizedPathValue)) {
3540
+ return;
3541
+ }
3542
+ const newValue = [value, ...normalizedPathValue];
3543
+ setInPath(form.values, pathName, newValue);
3544
+ form.stageInitialValue(pathName + `[0]`, value);
3545
+ fields.value.unshift(createEntry(value));
3546
+ afterMutation();
3547
+ }
3548
+ function move(oldIdx, newIdx) {
3549
+ const pathName = toValue(arrayPath);
3550
+ const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName);
3551
+ const newValue = isNullOrUndefined(pathValue) ? [] : [...pathValue];
3552
+ if (!Array.isArray(pathValue) || !(oldIdx in pathValue) || !(newIdx in pathValue)) {
3553
+ return;
3554
+ }
3555
+ const newFields = [...fields.value];
3556
+ const movedItem = newFields[oldIdx];
3557
+ newFields.splice(oldIdx, 1);
3558
+ newFields.splice(newIdx, 0, movedItem);
3559
+ const movedValue = newValue[oldIdx];
3560
+ newValue.splice(oldIdx, 1);
3561
+ newValue.splice(newIdx, 0, movedValue);
3562
+ setInPath(form.values, pathName, newValue);
3563
+ fields.value = newFields;
3564
+ afterMutation();
3565
+ }
3566
+ const fieldArrayCtx = {
3567
+ fields,
3568
+ remove,
3569
+ push,
3570
+ swap,
3571
+ insert,
3572
+ update,
3573
+ replace,
3574
+ prepend,
3575
+ move,
3576
+ };
3577
+ form.fieldArrays.push(Object.assign({ path: arrayPath, reset: initFields }, fieldArrayCtx));
3578
+ onBeforeUnmount(() => {
3579
+ const idx = form.fieldArrays.findIndex(i => toValue(i.path) === toValue(arrayPath));
3580
+ if (idx >= 0) {
3581
+ form.fieldArrays.splice(idx, 1);
3582
+ }
3583
+ });
3584
+ // Makes sure to sync the form values with the array value if they go out of sync
3585
+ // #4153
3586
+ watch(getCurrentValues, formValues => {
3587
+ const fieldsValues = fields.value.map(f => f.value);
3588
+ // If form values are not the same as the current values then something overrode them.
3589
+ if (!isEqual(formValues, fieldsValues)) {
3590
+ initFields();
3591
+ }
3592
+ });
3593
+ return fieldArrayCtx;
3594
+ }
3595
+
3596
+ const FieldArrayImpl = /** #__PURE__ */ defineComponent({
3597
+ name: 'FieldArray',
3598
+ inheritAttrs: false,
3599
+ props: {
3600
+ name: {
3601
+ type: String,
3602
+ required: true,
3603
+ },
3604
+ },
3605
+ setup(props, ctx) {
3606
+ const { push, remove, swap, insert, replace, update, prepend, move, fields } = useFieldArray(() => props.name);
3607
+ function slotProps() {
3608
+ return {
3609
+ fields: fields.value,
3610
+ push,
3611
+ remove,
3612
+ swap,
3613
+ insert,
3614
+ update,
3615
+ replace,
3616
+ prepend,
3617
+ move,
3618
+ };
3619
+ }
3620
+ ctx.expose({
3621
+ push,
3622
+ remove,
3623
+ swap,
3624
+ insert,
3625
+ update,
3626
+ replace,
3627
+ prepend,
3628
+ move,
3629
+ });
3630
+ return () => {
3631
+ const children = normalizeChildren(undefined, ctx, slotProps);
3632
+ return children;
3633
+ };
3634
+ },
3635
+ });
3636
+ const FieldArray = FieldArrayImpl;
3637
+
3638
+ const ErrorMessageImpl = /** #__PURE__ */ defineComponent({
3639
+ name: 'ErrorMessage',
3640
+ props: {
3641
+ as: {
3642
+ type: String,
3643
+ default: undefined,
3644
+ },
3645
+ name: {
3646
+ type: String,
3647
+ required: true,
3648
+ },
3649
+ },
3650
+ setup(props, ctx) {
3651
+ const form = inject(FormContextKey, undefined);
3652
+ const message = computed(() => {
3653
+ return form === null || form === void 0 ? void 0 : form.errors.value[props.name];
3654
+ });
3655
+ function slotProps() {
3656
+ return {
3657
+ message: message.value,
3658
+ };
3659
+ }
3660
+ return () => {
3661
+ // Renders nothing if there are no messages
3662
+ if (!message.value) {
3663
+ return undefined;
3664
+ }
3665
+ const tag = (props.as ? resolveDynamicComponent(props.as) : props.as);
3666
+ const children = normalizeChildren(tag, ctx, slotProps);
3667
+ const attrs = Object.assign({ role: 'alert' }, ctx.attrs);
3668
+ // If no tag was specified and there are children
3669
+ // render the slot as is without wrapping it
3670
+ if (!tag && (Array.isArray(children) || !children) && (children === null || children === void 0 ? void 0 : children.length)) {
3671
+ return children;
3672
+ }
3673
+ // If no children in slot
3674
+ // render whatever specified and fallback to a <span> with the message in it's contents
3675
+ if ((Array.isArray(children) || !children) && !(children === null || children === void 0 ? void 0 : children.length)) {
3676
+ return h(tag || 'span', attrs, message.value);
3677
+ }
3678
+ return h(tag, attrs, children);
3679
+ };
3680
+ },
3681
+ });
3682
+ const ErrorMessage = ErrorMessageImpl;
3683
+
3684
+ function useResetForm() {
3685
+ const form = injectWithSelf(FormContextKey);
3686
+ if (!form) {
3687
+ if (("production" !== 'production')) {
3688
+ warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
3689
+ }
3690
+ }
3691
+ return function resetForm(state, opts) {
3692
+ if (!form) {
3693
+ return;
3694
+ }
3695
+ return form.resetForm(state, opts);
3696
+ };
3697
+ }
3698
+
3699
+ /**
3700
+ * If a field is dirty or not
3701
+ */
3702
+ function useIsFieldDirty(path) {
3703
+ const fieldOrPath = resolveFieldOrPathState(path);
3704
+ return computed(() => {
3705
+ var _a, _b;
3706
+ if (!fieldOrPath) {
3707
+ return false;
3708
+ }
3709
+ return (_b = ('meta' in fieldOrPath ? fieldOrPath.meta.dirty : (_a = fieldOrPath === null || fieldOrPath === void 0 ? void 0 : fieldOrPath.value) === null || _a === void 0 ? void 0 : _a.dirty)) !== null && _b !== void 0 ? _b : false;
3710
+ });
3711
+ }
3712
+
3713
+ /**
3714
+ * If a field is touched or not
3715
+ */
3716
+ function useIsFieldTouched(path) {
3717
+ const fieldOrPath = resolveFieldOrPathState(path);
3718
+ return computed(() => {
3719
+ var _a, _b;
3720
+ if (!fieldOrPath) {
3721
+ return false;
3722
+ }
3723
+ return (_b = ('meta' in fieldOrPath ? fieldOrPath.meta.touched : (_a = fieldOrPath === null || fieldOrPath === void 0 ? void 0 : fieldOrPath.value) === null || _a === void 0 ? void 0 : _a.touched)) !== null && _b !== void 0 ? _b : false;
3724
+ });
3725
+ }
3726
+
3727
+ /**
3728
+ * If a field is validated and is valid
3729
+ */
3730
+ function useIsFieldValid(path) {
3731
+ const fieldOrPath = resolveFieldOrPathState(path);
3732
+ return computed(() => {
3733
+ var _a, _b;
3734
+ if (!fieldOrPath) {
3735
+ return false;
3736
+ }
3737
+ return (_b = ('meta' in fieldOrPath ? fieldOrPath.meta.valid : (_a = fieldOrPath === null || fieldOrPath === void 0 ? void 0 : fieldOrPath.value) === null || _a === void 0 ? void 0 : _a.valid)) !== null && _b !== void 0 ? _b : false;
3738
+ });
3739
+ }
3740
+
3741
+ /**
3742
+ * If the form is submitting or not
3743
+ */
3744
+ function useIsSubmitting() {
3745
+ const form = injectWithSelf(FormContextKey);
3746
+ if (!form) {
3747
+ if (("production" !== 'production')) {
3748
+ warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
3749
+ }
3750
+ }
3751
+ return computed(() => {
3752
+ var _a;
3753
+ return (_a = form === null || form === void 0 ? void 0 : form.isSubmitting.value) !== null && _a !== void 0 ? _a : false;
3754
+ });
3755
+ }
3756
+
3757
+ /**
3758
+ * If the form is validating or not
3759
+ */
3760
+ function useIsValidating() {
3761
+ const form = injectWithSelf(FormContextKey);
3762
+ if (!form) {
3763
+ if (("production" !== 'production')) {
3764
+ warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
3765
+ }
3766
+ }
3767
+ return computed(() => {
3768
+ var _a;
3769
+ return (_a = form === null || form === void 0 ? void 0 : form.isValidating.value) !== null && _a !== void 0 ? _a : false;
3770
+ });
3771
+ }
3772
+
3773
+ /**
3774
+ * Validates a single field
3775
+ */
3776
+ function useValidateField(path) {
3777
+ const form = injectWithSelf(FormContextKey);
3778
+ const field = path ? undefined : inject(FieldContextKey);
3779
+ return function validateField() {
3780
+ if (field) {
3781
+ return field.validate();
3782
+ }
3783
+ if (form && path) {
3784
+ return form === null || form === void 0 ? void 0 : form.validateField(toValue(path));
3785
+ }
3786
+ if (("production" !== 'production')) {
3787
+ warn(`field with name ${unref(path)} was not found`);
3788
+ }
3789
+ return Promise.resolve({
3790
+ errors: [],
3791
+ valid: true,
3792
+ });
3793
+ };
3794
+ }
3795
+
3796
+ /**
3797
+ * If the form is dirty or not
3798
+ */
3799
+ function useIsFormDirty() {
3800
+ const form = injectWithSelf(FormContextKey);
3801
+ if (!form) {
3802
+ if (("production" !== 'production')) {
3803
+ warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
3804
+ }
3805
+ }
3806
+ return computed(() => {
3807
+ var _a;
3808
+ return (_a = form === null || form === void 0 ? void 0 : form.meta.value.dirty) !== null && _a !== void 0 ? _a : false;
3809
+ });
3810
+ }
3811
+
3812
+ /**
3813
+ * If the form is touched or not
3814
+ */
3815
+ function useIsFormTouched() {
3816
+ const form = injectWithSelf(FormContextKey);
3817
+ if (!form) {
3818
+ if (("production" !== 'production')) {
3819
+ warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
3820
+ }
3821
+ }
3822
+ return computed(() => {
3823
+ var _a;
3824
+ return (_a = form === null || form === void 0 ? void 0 : form.meta.value.touched) !== null && _a !== void 0 ? _a : false;
3825
+ });
3826
+ }
3827
+
3828
+ /**
3829
+ * If the form has been validated and is valid
3830
+ */
3831
+ function useIsFormValid() {
3832
+ const form = injectWithSelf(FormContextKey);
3833
+ if (!form) {
3834
+ if (("production" !== 'production')) {
3835
+ warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
3836
+ }
3837
+ }
3838
+ return computed(() => {
3839
+ var _a;
3840
+ return (_a = form === null || form === void 0 ? void 0 : form.meta.value.valid) !== null && _a !== void 0 ? _a : false;
3841
+ });
3842
+ }
3843
+
3844
+ /**
3845
+ * Validate multiple fields
3846
+ */
3847
+ function useValidateForm() {
3848
+ const form = injectWithSelf(FormContextKey);
3849
+ if (!form) {
3850
+ if (("production" !== 'production')) {
3851
+ warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
3852
+ }
3853
+ }
3854
+ return function validateField() {
3855
+ if (!form) {
3856
+ return Promise.resolve({ results: {}, errors: {}, valid: true, source: 'none' });
3857
+ }
3858
+ return form.validate();
3859
+ };
3860
+ }
3861
+
3862
+ /**
3863
+ * The number of form's submission count
3864
+ */
3865
+ function useSubmitCount() {
3866
+ const form = injectWithSelf(FormContextKey);
3867
+ if (!form) {
3868
+ if (("production" !== 'production')) {
3869
+ warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
3870
+ }
3871
+ }
3872
+ return computed(() => {
3873
+ var _a;
3874
+ return (_a = form === null || form === void 0 ? void 0 : form.submitCount.value) !== null && _a !== void 0 ? _a : 0;
3875
+ });
3876
+ }
3877
+
3878
+ /**
3879
+ * Gives access to a field's current value
3880
+ */
3881
+ function useFieldValue(path) {
3882
+ const form = injectWithSelf(FormContextKey);
3883
+ // We don't want to use self injected context as it doesn't make sense
3884
+ const field = path ? undefined : inject(FieldContextKey);
3885
+ return computed(() => {
3886
+ if (path) {
3887
+ return getFromPath(form === null || form === void 0 ? void 0 : form.values, toValue(path));
3888
+ }
3889
+ return toValue(field === null || field === void 0 ? void 0 : field.value);
3890
+ });
3891
+ }
3892
+
3893
+ /**
3894
+ * Gives access to a form's values
3895
+ */
3896
+ function useFormValues() {
3897
+ const form = injectWithSelf(FormContextKey);
3898
+ if (!form) {
3899
+ if (("production" !== 'production')) {
3900
+ warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
3901
+ }
3902
+ }
3903
+ return computed(() => {
3904
+ return (form === null || form === void 0 ? void 0 : form.values) || {};
3905
+ });
3906
+ }
3907
+
3908
+ /**
3909
+ * Gives access to all form errors
3910
+ */
3911
+ function useFormErrors() {
3912
+ const form = injectWithSelf(FormContextKey);
3913
+ if (!form) {
3914
+ if (("production" !== 'production')) {
3915
+ warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
3916
+ }
3917
+ }
3918
+ return computed(() => {
3919
+ return ((form === null || form === void 0 ? void 0 : form.errors.value) || {});
3920
+ });
3921
+ }
3922
+
3923
+ /**
3924
+ * Gives access to a single field error
3925
+ */
3926
+ function useFieldError(path) {
3927
+ const form = injectWithSelf(FormContextKey);
3928
+ // We don't want to use self injected context as it doesn't make sense
3929
+ const field = path ? undefined : inject(FieldContextKey);
3930
+ return computed(() => {
3931
+ if (path) {
3932
+ return form === null || form === void 0 ? void 0 : form.errors.value[toValue(path)];
3933
+ }
3934
+ return field === null || field === void 0 ? void 0 : field.errorMessage.value;
3935
+ });
3936
+ }
3937
+
3938
+ function useSubmitForm(cb) {
3939
+ const form = injectWithSelf(FormContextKey);
3940
+ if (!form) {
3941
+ if (("production" !== 'production')) {
3942
+ warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
3943
+ }
3944
+ }
3945
+ const onSubmit = form ? form.handleSubmit(cb) : undefined;
3946
+ return function submitForm(e) {
3947
+ if (!onSubmit) {
3948
+ return;
3949
+ }
3950
+ return onSubmit(e);
3951
+ };
3952
+ }
3953
+
3954
+ /**
3955
+ * Sets a field's error message
3956
+ */
3957
+ function useSetFieldError(path) {
3958
+ const form = injectWithSelf(FormContextKey);
3959
+ // We don't want to use self injected context as it doesn't make sense
3960
+ const field = path ? undefined : inject(FieldContextKey);
3961
+ return function setFieldError(message) {
3962
+ if (path && form) {
3963
+ form.setFieldError(toValue(path), message);
3964
+ return;
3965
+ }
3966
+ if (field) {
3967
+ field.setErrors(message || []);
3968
+ return;
3969
+ }
3970
+ if (("production" !== 'production')) {
3971
+ warn(`Could not set error message since there is no form context or a field named "${toValue(path)}", did you forget to call "useField" or "useForm"?`);
3972
+ }
3973
+ };
3974
+ }
3975
+
3976
+ /**
3977
+ * Sets a field's touched meta state
3978
+ */
3979
+ function useSetFieldTouched(path) {
3980
+ const form = injectWithSelf(FormContextKey);
3981
+ // We don't want to use self injected context as it doesn't make sense
3982
+ const field = path ? undefined : inject(FieldContextKey);
3983
+ return function setFieldTouched(touched) {
3984
+ if (path && form) {
3985
+ form.setFieldTouched(toValue(path), touched);
3986
+ return;
3987
+ }
3988
+ if (field) {
3989
+ field.setTouched(touched);
3990
+ return;
3991
+ }
3992
+ if (("production" !== 'production')) {
3993
+ warn(`Could not set touched state since there is no form context or a field named "${toValue(path)}", did you forget to call "useField" or "useForm"?`);
3994
+ }
3995
+ };
3996
+ }
3997
+
3998
+ /**
3999
+ * Sets a field's value
4000
+ */
4001
+ function useSetFieldValue(path) {
4002
+ const form = injectWithSelf(FormContextKey);
4003
+ // We don't want to use self injected context as it doesn't make sense
4004
+ const field = path ? undefined : inject(FieldContextKey);
4005
+ return function setFieldValue(value, shouldValidate = true) {
4006
+ if (path && form) {
4007
+ form.setFieldValue(toValue(path), value, shouldValidate);
4008
+ return;
4009
+ }
4010
+ if (field) {
4011
+ field.setValue(value, shouldValidate);
4012
+ return;
4013
+ }
4014
+ if (("production" !== 'production')) {
4015
+ warn(`Could not set value since there is no form context or a field named "${toValue(path)}", did you forget to call "useField" or "useForm"?`);
4016
+ }
4017
+ };
4018
+ }
4019
+
4020
+ /**
4021
+ * Sets multiple fields errors
4022
+ */
4023
+ function useSetFormErrors() {
4024
+ const form = injectWithSelf(FormContextKey);
4025
+ function setFormErrors(fields) {
4026
+ if (form) {
4027
+ form.setErrors(fields);
4028
+ return;
4029
+ }
4030
+ if (("production" !== 'production')) {
4031
+ warn(`Could not set errors because a form was not detected, did you forget to use "useForm" in a parent component?`);
4032
+ }
4033
+ }
4034
+ return setFormErrors;
4035
+ }
4036
+
4037
+ /**
4038
+ * Sets multiple fields touched or all fields in the form
4039
+ */
4040
+ function useSetFormTouched() {
4041
+ const form = injectWithSelf(FormContextKey);
4042
+ function setFormTouched(fields) {
4043
+ if (form) {
4044
+ form.setTouched(fields);
4045
+ return;
4046
+ }
4047
+ if (("production" !== 'production')) {
4048
+ warn(`Could not set touched state because a form was not detected, did you forget to use "useForm" in a parent component?`);
4049
+ }
4050
+ }
4051
+ return setFormTouched;
4052
+ }
4053
+
4054
+ /**
4055
+ * Sets multiple fields values
4056
+ */
4057
+ function useSetFormValues() {
4058
+ const form = injectWithSelf(FormContextKey);
4059
+ function setFormValues(fields, shouldValidate = true) {
4060
+ if (form) {
4061
+ form.setValues(fields, shouldValidate);
4062
+ return;
4063
+ }
4064
+ if (("production" !== 'production')) {
4065
+ warn(`Could not set form values because a form was not detected, did you forget to use "useForm" in a parent component?`);
4066
+ }
4067
+ }
4068
+ return setFormValues;
4069
+ }
4070
+
4071
+ export { Form as F, Field as a, useField as u };