@frollo/frollo-web-ui 0.0.8 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/fw-input.js CHANGED
@@ -1,3141 +1,6 @@
1
1
  import { o as descriptors, v as functionName, f as functionUncurryThis, x as objectDefineProperty, u as styleInject } from './style-inject.es-da8f7768.js';
2
- import { getCurrentInstance, inject, warn as warn$1, ref, unref, computed, reactive, watch, nextTick, onUnmounted, onMounted, provide, isRef, onBeforeUnmount, defineComponent, toRef, resolveDynamicComponent, h, markRaw, watchEffect, readonly, createElementVNode, resolveComponent, openBlock, createBlock, withCtx, createElementBlock, toDisplayString, createCommentVNode, renderSlot, mergeProps, createVNode, Transition } from 'vue';
3
-
4
- function getDevtoolsGlobalHook() {
5
- return getTarget().__VUE_DEVTOOLS_GLOBAL_HOOK__;
6
- }
7
- function getTarget() {
8
- // @ts-ignore
9
- return (typeof navigator !== 'undefined' && typeof window !== 'undefined')
10
- ? window
11
- : typeof global !== 'undefined'
12
- ? global
13
- : {};
14
- }
15
- const isProxyAvailable = typeof Proxy === 'function';
16
-
17
- const HOOK_SETUP = 'devtools-plugin:setup';
18
- const HOOK_PLUGIN_SETTINGS_SET = 'plugin:settings:set';
19
-
20
- class ApiProxy {
21
- constructor(plugin, hook) {
22
- this.target = null;
23
- this.targetQueue = [];
24
- this.onQueue = [];
25
- this.plugin = plugin;
26
- this.hook = hook;
27
- const defaultSettings = {};
28
- if (plugin.settings) {
29
- for (const id in plugin.settings) {
30
- const item = plugin.settings[id];
31
- defaultSettings[id] = item.defaultValue;
32
- }
33
- }
34
- const localSettingsSaveId = `__vue-devtools-plugin-settings__${plugin.id}`;
35
- let currentSettings = Object.assign({}, defaultSettings);
36
- try {
37
- const raw = localStorage.getItem(localSettingsSaveId);
38
- const data = JSON.parse(raw);
39
- Object.assign(currentSettings, data);
40
- }
41
- catch (e) {
42
- // noop
43
- }
44
- this.fallbacks = {
45
- getSettings() {
46
- return currentSettings;
47
- },
48
- setSettings(value) {
49
- try {
50
- localStorage.setItem(localSettingsSaveId, JSON.stringify(value));
51
- }
52
- catch (e) {
53
- // noop
54
- }
55
- currentSettings = value;
56
- },
57
- };
58
- if (hook) {
59
- hook.on(HOOK_PLUGIN_SETTINGS_SET, (pluginId, value) => {
60
- if (pluginId === this.plugin.id) {
61
- this.fallbacks.setSettings(value);
62
- }
63
- });
64
- }
65
- this.proxiedOn = new Proxy({}, {
66
- get: (_target, prop) => {
67
- if (this.target) {
68
- return this.target.on[prop];
69
- }
70
- else {
71
- return (...args) => {
72
- this.onQueue.push({
73
- method: prop,
74
- args,
75
- });
76
- };
77
- }
78
- },
79
- });
80
- this.proxiedTarget = new Proxy({}, {
81
- get: (_target, prop) => {
82
- if (this.target) {
83
- return this.target[prop];
84
- }
85
- else if (prop === 'on') {
86
- return this.proxiedOn;
87
- }
88
- else if (Object.keys(this.fallbacks).includes(prop)) {
89
- return (...args) => {
90
- this.targetQueue.push({
91
- method: prop,
92
- args,
93
- resolve: () => { },
94
- });
95
- return this.fallbacks[prop](...args);
96
- };
97
- }
98
- else {
99
- return (...args) => {
100
- return new Promise(resolve => {
101
- this.targetQueue.push({
102
- method: prop,
103
- args,
104
- resolve,
105
- });
106
- });
107
- };
108
- }
109
- },
110
- });
111
- }
112
- async setRealTarget(target) {
113
- this.target = target;
114
- for (const item of this.onQueue) {
115
- this.target.on[item.method](...item.args);
116
- }
117
- for (const item of this.targetQueue) {
118
- item.resolve(await this.target[item.method](...item.args));
119
- }
120
- }
121
- }
122
-
123
- function setupDevtoolsPlugin(pluginDescriptor, setupFn) {
124
- const descriptor = pluginDescriptor;
125
- const target = getTarget();
126
- const hook = getDevtoolsGlobalHook();
127
- const enableProxy = isProxyAvailable && descriptor.enableEarlyProxy;
128
- if (hook && (target.__VUE_DEVTOOLS_PLUGIN_API_AVAILABLE__ || !enableProxy)) {
129
- hook.emit(HOOK_SETUP, pluginDescriptor, setupFn);
130
- }
131
- else {
132
- const proxy = enableProxy ? new ApiProxy(descriptor, hook) : null;
133
- const list = target.__VUE_DEVTOOLS_PLUGINS__ = target.__VUE_DEVTOOLS_PLUGINS__ || [];
134
- list.push({
135
- pluginDescriptor: descriptor,
136
- setupFn,
137
- proxy,
138
- });
139
- if (proxy)
140
- setupFn(proxy.proxiedTarget);
141
- }
142
- }
143
-
144
- /**
145
- * vee-validate v4.5.9
146
- * (c) 2022 Abdelrahman Awad
147
- * @license MIT
148
- */
149
-
150
- function isCallable(fn) {
151
- return typeof fn === 'function';
152
- }
153
- function isNullOrUndefined(value) {
154
- return value === null || value === undefined;
155
- }
156
- const isObject = (obj) => obj !== null && !!obj && typeof obj === 'object' && !Array.isArray(obj);
157
- function isIndex(value) {
158
- return Number(value) >= 0;
159
- }
160
- function toNumber(value) {
161
- const n = parseFloat(value);
162
- return isNaN(n) ? value : n;
163
- }
164
-
165
- const RULES = {};
166
- /**
167
- * Adds a custom validator to the list of validation rules.
168
- */
169
- function defineRule(id, validator) {
170
- // makes sure new rules are properly formatted.
171
- guardExtend(id, validator);
172
- RULES[id] = validator;
173
- }
174
- /**
175
- * Gets an already defined rule
176
- */
177
- function resolveRule(id) {
178
- return RULES[id];
179
- }
180
- /**
181
- * Guards from extension violations.
182
- */
183
- function guardExtend(id, validator) {
184
- if (isCallable(validator)) {
185
- return;
186
- }
187
- throw new Error(`Extension Error: The validator '${id}' must be a function.`);
188
- }
189
-
190
- const FormContextKey = Symbol('vee-validate-form');
191
- const FieldContextKey = Symbol('vee-validate-field-instance');
192
- const IS_ABSENT = Symbol('Default empty value');
193
-
194
- function isLocator(value) {
195
- return isCallable(value) && !!value.__locatorRef;
196
- }
197
- /**
198
- * Checks if an tag name is a native HTML tag and not a Vue component
199
- */
200
- function isHTMLTag(tag) {
201
- return ['input', 'textarea', 'select'].includes(tag);
202
- }
203
- /**
204
- * Checks if an input is of type file
205
- */
206
- function isFileInputNode(tag, attrs) {
207
- return isHTMLTag(tag) && attrs.type === 'file';
208
- }
209
- function isYupValidator(value) {
210
- return !!value && isCallable(value.validate);
211
- }
212
- function hasCheckedAttr(type) {
213
- return type === 'checkbox' || type === 'radio';
214
- }
215
- function isContainerValue(value) {
216
- return isObject(value) || Array.isArray(value);
217
- }
218
- /**
219
- * True if the value is an empty object or array
220
- */
221
- function isEmptyContainer(value) {
222
- if (Array.isArray(value)) {
223
- return value.length === 0;
224
- }
225
- return isObject(value) && Object.keys(value).length === 0;
226
- }
227
- /**
228
- * Checks if the path opted out of nested fields using `[fieldName]` syntax
229
- */
230
- function isNotNestedPath(path) {
231
- return /^\[.+\]$/i.test(path);
232
- }
233
- /**
234
- * Checks if an element is a native HTML5 multi-select input element
235
- */
236
- function isNativeMultiSelect(el) {
237
- return isNativeSelect(el) && el.multiple;
238
- }
239
- /**
240
- * Checks if an element is a native HTML5 select input element
241
- */
242
- function isNativeSelect(el) {
243
- return el.tagName === 'SELECT';
244
- }
245
- /**
246
- * Checks if a tag name with attrs object will render a native multi-select element
247
- */
248
- function isNativeMultiSelectNode(tag, attrs) {
249
- // The falsy value array is the values that Vue won't add the `multiple` prop if it has one of these values
250
- const hasTruthyBindingValue = ![false, null, undefined, 0].includes(attrs.multiple) && !Number.isNaN(attrs.multiple);
251
- return tag === 'select' && 'multiple' in attrs && hasTruthyBindingValue;
252
- }
253
- /**
254
- * Checks if a node should have a `:value` binding or not
255
- *
256
- * These nodes should not have a value binding
257
- * For files, because they are not reactive
258
- * For multi-selects because the value binding will reset the value
259
- */
260
- function shouldHaveValueBinding(tag, attrs) {
261
- return isNativeMultiSelectNode(tag, attrs) || isFileInputNode(tag, attrs);
262
- }
263
- function isFormSubmitEvent(evt) {
264
- return isEvent(evt) && evt.target && 'submit' in evt.target;
265
- }
266
- function isEvent(evt) {
267
- if (!evt) {
268
- return false;
269
- }
270
- if (typeof Event !== 'undefined' && isCallable(Event) && evt instanceof Event) {
271
- return true;
272
- }
273
- // this is for IE and Cypress #3161
274
- /* istanbul ignore next */
275
- if (evt && evt.srcElement) {
276
- return true;
277
- }
278
- return false;
279
- }
280
- function isPropPresent(obj, prop) {
281
- return prop in obj && obj[prop] !== IS_ABSENT;
282
- }
283
-
284
- function cleanupNonNestedPath(path) {
285
- if (isNotNestedPath(path)) {
286
- return path.replace(/\[|\]/gi, '');
287
- }
288
- return path;
289
- }
290
- function getFromPath(object, path, fallback) {
291
- if (!object) {
292
- return fallback;
293
- }
294
- if (isNotNestedPath(path)) {
295
- return object[cleanupNonNestedPath(path)];
296
- }
297
- const resolvedValue = (path || '')
298
- .split(/\.|\[(\d+)\]/)
299
- .filter(Boolean)
300
- .reduce((acc, propKey) => {
301
- if (isContainerValue(acc) && propKey in acc) {
302
- return acc[propKey];
303
- }
304
- return fallback;
305
- }, object);
306
- return resolvedValue;
307
- }
308
- /**
309
- * Sets a nested property value in a path, creates the path properties if it doesn't exist
310
- */
311
- function setInPath(object, path, value) {
312
- if (isNotNestedPath(path)) {
313
- object[cleanupNonNestedPath(path)] = value;
314
- return;
315
- }
316
- const keys = path.split(/\.|\[(\d+)\]/).filter(Boolean);
317
- let acc = object;
318
- for (let i = 0; i < keys.length; i++) {
319
- // Last key, set it
320
- if (i === keys.length - 1) {
321
- acc[keys[i]] = value;
322
- return;
323
- }
324
- // Key does not exist, create a container for it
325
- if (!(keys[i] in acc) || isNullOrUndefined(acc[keys[i]])) {
326
- // container can be either an object or an array depending on the next key if it exists
327
- acc[keys[i]] = isIndex(keys[i + 1]) ? [] : {};
328
- }
329
- acc = acc[keys[i]];
330
- }
331
- }
332
- function unset(object, key) {
333
- if (Array.isArray(object) && isIndex(key)) {
334
- object.splice(Number(key), 1);
335
- return;
336
- }
337
- if (isObject(object)) {
338
- delete object[key];
339
- }
340
- }
341
- /**
342
- * Removes a nested property from object
343
- */
344
- function unsetPath(object, path) {
345
- if (isNotNestedPath(path)) {
346
- delete object[cleanupNonNestedPath(path)];
347
- return;
348
- }
349
- const keys = path.split(/\.|\[(\d+)\]/).filter(Boolean);
350
- let acc = object;
351
- for (let i = 0; i < keys.length; i++) {
352
- // Last key, unset it
353
- if (i === keys.length - 1) {
354
- unset(acc, keys[i]);
355
- break;
356
- }
357
- // Key does not exist, exit
358
- if (!(keys[i] in acc) || isNullOrUndefined(acc[keys[i]])) {
359
- break;
360
- }
361
- acc = acc[keys[i]];
362
- }
363
- const pathValues = keys.map((_, idx) => {
364
- return getFromPath(object, keys.slice(0, idx).join('.'));
365
- });
366
- for (let i = pathValues.length - 1; i >= 0; i--) {
367
- if (!isEmptyContainer(pathValues[i])) {
368
- continue;
369
- }
370
- if (i === 0) {
371
- unset(object, keys[0]);
372
- continue;
373
- }
374
- unset(pathValues[i - 1], keys[i - 1]);
375
- }
376
- }
377
- /**
378
- * A typed version of Object.keys
379
- */
380
- function keysOf(record) {
381
- return Object.keys(record);
382
- }
383
- // Uses same component provide as its own injections
384
- // Due to changes in https://github.com/vuejs/vue-next/pull/2424
385
- function injectWithSelf(symbol, def = undefined) {
386
- const vm = getCurrentInstance();
387
- return (vm === null || vm === void 0 ? void 0 : vm.provides[symbol]) || inject(symbol, def);
388
- }
389
- function warn(message) {
390
- warn$1(`[vee-validate]: ${message}`);
391
- }
392
- /**
393
- * Ensures we deal with a singular field value
394
- */
395
- function normalizeField(field) {
396
- if (Array.isArray(field)) {
397
- return field[0];
398
- }
399
- return field;
400
- }
401
- function resolveNextCheckboxValue(currentValue, checkedValue, uncheckedValue) {
402
- if (Array.isArray(currentValue)) {
403
- const newVal = [...currentValue];
404
- const idx = newVal.indexOf(checkedValue);
405
- idx >= 0 ? newVal.splice(idx, 1) : newVal.push(checkedValue);
406
- return newVal;
407
- }
408
- return currentValue === checkedValue ? uncheckedValue : checkedValue;
409
- }
410
- /**
411
- * Creates a throttled function that only invokes the provided function (`func`) at most once per within a given number of milliseconds
412
- * (`limit`)
413
- */
414
- function throttle(func, limit) {
415
- let inThrottle;
416
- let lastResult;
417
- return function (...args) {
418
- // eslint-disable-next-line @typescript-eslint/no-this-alias
419
- const context = this;
420
- if (!inThrottle) {
421
- inThrottle = true;
422
- setTimeout(() => (inThrottle = false), limit);
423
- lastResult = func.apply(context, args);
424
- }
425
- return lastResult;
426
- };
427
- }
428
- function debounceAsync(inner, ms = 0) {
429
- let timer = null;
430
- let resolves = [];
431
- return function (...args) {
432
- // Run the function after a certain amount of time
433
- if (timer) {
434
- window.clearTimeout(timer);
435
- }
436
- timer = window.setTimeout(() => {
437
- // Get the result of the inner function, then apply it to the resolve function of
438
- // each promise that has been created since the last time the inner function was run
439
- const result = inner(...args);
440
- resolves.forEach(r => r(result));
441
- resolves = [];
442
- }, ms);
443
- return new Promise(resolve => resolves.push(resolve));
444
- };
445
- }
446
-
447
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
448
- const normalizeChildren = (tag, context, slotProps) => {
449
- if (!context.slots.default) {
450
- return context.slots.default;
451
- }
452
- if (typeof tag === 'string' || !tag) {
453
- return context.slots.default(slotProps());
454
- }
455
- return {
456
- default: () => { var _a, _b; return (_b = (_a = context.slots).default) === null || _b === void 0 ? void 0 : _b.call(_a, slotProps()); },
457
- };
458
- };
459
- /**
460
- * 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
461
- * as they do not get casted to strings unlike `el.value` which preserves user-code behavior
462
- */
463
- function getBoundValue(el) {
464
- if (hasValueBinding(el)) {
465
- return el._value;
466
- }
467
- return undefined;
468
- }
469
- /**
470
- * 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
471
- * as they do not get casted to strings unlike `el.value` which preserves user-code behavior
472
- */
473
- function hasValueBinding(el) {
474
- return '_value' in el;
475
- }
476
-
477
- function normalizeEventValue(value) {
478
- if (!isEvent(value)) {
479
- return value;
480
- }
481
- const input = value.target;
482
- // Vue sets the current bound value on `_value` prop
483
- // for checkboxes it it should fetch the value binding type as is (boolean instead of string)
484
- if (hasCheckedAttr(input.type) && hasValueBinding(input)) {
485
- return getBoundValue(input);
486
- }
487
- if (input.type === 'file' && input.files) {
488
- return Array.from(input.files);
489
- }
490
- if (isNativeMultiSelect(input)) {
491
- return Array.from(input.options)
492
- .filter(opt => opt.selected && !opt.disabled)
493
- .map(getBoundValue);
494
- }
495
- // makes sure we get the actual `option` bound value
496
- // #3440
497
- if (isNativeSelect(input)) {
498
- const selectedOption = Array.from(input.options).find(opt => opt.selected);
499
- return selectedOption ? getBoundValue(selectedOption) : input.value;
500
- }
501
- return input.value;
502
- }
503
-
504
- /**
505
- * Normalizes the given rules expression.
506
- */
507
- function normalizeRules(rules) {
508
- const acc = {};
509
- Object.defineProperty(acc, '_$$isNormalized', {
510
- value: true,
511
- writable: false,
512
- enumerable: false,
513
- configurable: false,
514
- });
515
- if (!rules) {
516
- return acc;
517
- }
518
- // Object is already normalized, skip.
519
- if (isObject(rules) && rules._$$isNormalized) {
520
- return rules;
521
- }
522
- if (isObject(rules)) {
523
- return Object.keys(rules).reduce((prev, curr) => {
524
- const params = normalizeParams(rules[curr]);
525
- if (rules[curr] !== false) {
526
- prev[curr] = buildParams(params);
527
- }
528
- return prev;
529
- }, acc);
530
- }
531
- /* istanbul ignore if */
532
- if (typeof rules !== 'string') {
533
- return acc;
534
- }
535
- return rules.split('|').reduce((prev, rule) => {
536
- const parsedRule = parseRule(rule);
537
- if (!parsedRule.name) {
538
- return prev;
539
- }
540
- prev[parsedRule.name] = buildParams(parsedRule.params);
541
- return prev;
542
- }, acc);
543
- }
544
- /**
545
- * Normalizes a rule param.
546
- */
547
- function normalizeParams(params) {
548
- if (params === true) {
549
- return [];
550
- }
551
- if (Array.isArray(params)) {
552
- return params;
553
- }
554
- if (isObject(params)) {
555
- return params;
556
- }
557
- return [params];
558
- }
559
- function buildParams(provided) {
560
- const mapValueToLocator = (value) => {
561
- // A target param using interpolation
562
- if (typeof value === 'string' && value[0] === '@') {
563
- return createLocator(value.slice(1));
564
- }
565
- return value;
566
- };
567
- if (Array.isArray(provided)) {
568
- return provided.map(mapValueToLocator);
569
- }
570
- // #3073
571
- if (provided instanceof RegExp) {
572
- return [provided];
573
- }
574
- return Object.keys(provided).reduce((prev, key) => {
575
- prev[key] = mapValueToLocator(provided[key]);
576
- return prev;
577
- }, {});
578
- }
579
- /**
580
- * Parses a rule string expression.
581
- */
582
- const parseRule = (rule) => {
583
- let params = [];
584
- const name = rule.split(':')[0];
585
- if (rule.includes(':')) {
586
- params = rule.split(':').slice(1).join(':').split(',');
587
- }
588
- return { name, params };
589
- };
590
- function createLocator(value) {
591
- const locator = (crossTable) => {
592
- const val = getFromPath(crossTable, value) || crossTable[value];
593
- return val;
594
- };
595
- locator.__locatorRef = value;
596
- return locator;
597
- }
598
- function extractLocators(params) {
599
- if (Array.isArray(params)) {
600
- return params.filter(isLocator);
601
- }
602
- return keysOf(params)
603
- .filter(key => isLocator(params[key]))
604
- .map(key => params[key]);
605
- }
606
-
607
- const DEFAULT_CONFIG = {
608
- generateMessage: ({ field }) => `${field} is not valid.`,
609
- bails: true,
610
- validateOnBlur: true,
611
- validateOnChange: true,
612
- validateOnInput: false,
613
- validateOnModelUpdate: true,
614
- };
615
- let currentConfig = Object.assign({}, DEFAULT_CONFIG);
616
- const getConfig = () => currentConfig;
617
- const setConfig = (newConf) => {
618
- currentConfig = Object.assign(Object.assign({}, currentConfig), newConf);
619
- };
620
- const configure = setConfig;
621
-
622
- /**
623
- * Validates a value against the rules.
624
- */
625
- async function validate(value, rules, options = {}) {
626
- const shouldBail = options === null || options === void 0 ? void 0 : options.bails;
627
- const field = {
628
- name: (options === null || options === void 0 ? void 0 : options.name) || '{field}',
629
- rules,
630
- bails: shouldBail !== null && shouldBail !== void 0 ? shouldBail : true,
631
- formData: (options === null || options === void 0 ? void 0 : options.values) || {},
632
- };
633
- const result = await _validate(field, value);
634
- const errors = result.errors;
635
- return {
636
- errors,
637
- valid: !errors.length,
638
- };
639
- }
640
- /**
641
- * Starts the validation process.
642
- */
643
- async function _validate(field, value) {
644
- if (isYupValidator(field.rules)) {
645
- return validateFieldWithYup(value, field.rules, { bails: field.bails });
646
- }
647
- // if a generic function, use it as the pipeline.
648
- if (isCallable(field.rules)) {
649
- const ctx = {
650
- field: field.name,
651
- form: field.formData,
652
- value: value,
653
- };
654
- const result = await field.rules(value, ctx);
655
- const isValid = typeof result !== 'string' && result;
656
- const message = typeof result === 'string' ? result : _generateFieldError(ctx);
657
- return {
658
- errors: !isValid ? [message] : [],
659
- };
660
- }
661
- const normalizedContext = Object.assign(Object.assign({}, field), { rules: normalizeRules(field.rules) });
662
- const errors = [];
663
- const rulesKeys = Object.keys(normalizedContext.rules);
664
- const length = rulesKeys.length;
665
- for (let i = 0; i < length; i++) {
666
- const rule = rulesKeys[i];
667
- const result = await _test(normalizedContext, value, {
668
- name: rule,
669
- params: normalizedContext.rules[rule],
670
- });
671
- if (result.error) {
672
- errors.push(result.error);
673
- if (field.bails) {
674
- return {
675
- errors,
676
- };
677
- }
678
- }
679
- }
680
- return {
681
- errors,
682
- };
683
- }
684
- /**
685
- * Handles yup validation
686
- */
687
- async function validateFieldWithYup(value, validator, opts) {
688
- var _a;
689
- const errors = await validator
690
- .validate(value, {
691
- abortEarly: (_a = opts.bails) !== null && _a !== void 0 ? _a : true,
692
- })
693
- .then(() => [])
694
- .catch((err) => {
695
- // Yup errors have a name prop one them.
696
- // https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string
697
- if (err.name === 'ValidationError') {
698
- return err.errors;
699
- }
700
- // re-throw the error so we don't hide it
701
- throw err;
702
- });
703
- return {
704
- errors,
705
- };
706
- }
707
- /**
708
- * Tests a single input value against a rule.
709
- */
710
- async function _test(field, value, rule) {
711
- const validator = resolveRule(rule.name);
712
- if (!validator) {
713
- throw new Error(`No such validator '${rule.name}' exists.`);
714
- }
715
- const params = fillTargetValues(rule.params, field.formData);
716
- const ctx = {
717
- field: field.name,
718
- value,
719
- form: field.formData,
720
- rule: Object.assign(Object.assign({}, rule), { params }),
721
- };
722
- const result = await validator(value, params, ctx);
723
- if (typeof result === 'string') {
724
- return {
725
- error: result,
726
- };
727
- }
728
- return {
729
- error: result ? undefined : _generateFieldError(ctx),
730
- };
731
- }
732
- /**
733
- * Generates error messages.
734
- */
735
- function _generateFieldError(fieldCtx) {
736
- const message = getConfig().generateMessage;
737
- if (!message) {
738
- return 'Field is invalid';
739
- }
740
- return message(fieldCtx);
741
- }
742
- function fillTargetValues(params, crossTable) {
743
- const normalize = (value) => {
744
- if (isLocator(value)) {
745
- return value(crossTable);
746
- }
747
- return value;
748
- };
749
- if (Array.isArray(params)) {
750
- return params.map(normalize);
751
- }
752
- return Object.keys(params).reduce((acc, param) => {
753
- acc[param] = normalize(params[param]);
754
- return acc;
755
- }, {});
756
- }
757
- async function validateYupSchema(schema, values) {
758
- const errorObjects = await schema
759
- .validate(values, { abortEarly: false })
760
- .then(() => [])
761
- .catch((err) => {
762
- // Yup errors have a name prop one them.
763
- // https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string
764
- if (err.name !== 'ValidationError') {
765
- throw err;
766
- }
767
- // list of aggregated errors
768
- return err.inner || [];
769
- });
770
- const results = {};
771
- const errors = {};
772
- for (const error of errorObjects) {
773
- const messages = error.errors;
774
- results[error.path] = { valid: !messages.length, errors: messages };
775
- if (messages.length) {
776
- errors[error.path] = messages[0];
777
- }
778
- }
779
- return {
780
- valid: !errorObjects.length,
781
- results,
782
- errors,
783
- };
784
- }
785
- async function validateObjectSchema(schema, values, opts) {
786
- const paths = keysOf(schema);
787
- const validations = paths.map(async (path) => {
788
- var _a, _b, _c;
789
- const fieldResult = await validate(getFromPath(values, path), schema[path], {
790
- name: ((_a = opts === null || opts === void 0 ? void 0 : opts.names) === null || _a === void 0 ? void 0 : _a[path]) || path,
791
- values: values,
792
- 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,
793
- });
794
- return Object.assign(Object.assign({}, fieldResult), { path });
795
- });
796
- let isAllValid = true;
797
- const validationResults = await Promise.all(validations);
798
- const results = {};
799
- const errors = {};
800
- for (const result of validationResults) {
801
- results[result.path] = {
802
- valid: result.valid,
803
- errors: result.errors,
804
- };
805
- if (!result.valid) {
806
- isAllValid = false;
807
- errors[result.path] = result.errors[0];
808
- }
809
- }
810
- return {
811
- valid: isAllValid,
812
- results,
813
- errors,
814
- };
815
- }
816
-
817
- function set(obj, key, val) {
818
- if (typeof val.value === 'object') val.value = klona(val.value);
819
- if (!val.enumerable || val.get || val.set || !val.configurable || !val.writable || key === '__proto__') {
820
- Object.defineProperty(obj, key, val);
821
- } else obj[key] = val.value;
822
- }
823
-
824
- function klona(x) {
825
- if (typeof x !== 'object') return x;
826
-
827
- var i=0, k, list, tmp, str=Object.prototype.toString.call(x);
828
-
829
- if (str === '[object Object]') {
830
- tmp = Object.create(x.__proto__ || null);
831
- } else if (str === '[object Array]') {
832
- tmp = Array(x.length);
833
- } else if (str === '[object Set]') {
834
- tmp = new Set;
835
- x.forEach(function (val) {
836
- tmp.add(klona(val));
837
- });
838
- } else if (str === '[object Map]') {
839
- tmp = new Map;
840
- x.forEach(function (val, key) {
841
- tmp.set(klona(key), klona(val));
842
- });
843
- } else if (str === '[object Date]') {
844
- tmp = new Date(+x);
845
- } else if (str === '[object RegExp]') {
846
- tmp = new RegExp(x.source, x.flags);
847
- } else if (str === '[object DataView]') {
848
- tmp = new x.constructor( klona(x.buffer) );
849
- } else if (str === '[object ArrayBuffer]') {
850
- tmp = x.slice(0);
851
- } else if (str.slice(-6) === 'Array]') {
852
- // ArrayBuffer.isView(x)
853
- // ~> `new` bcuz `Buffer.slice` => ref
854
- tmp = new x.constructor(x);
855
- }
856
-
857
- if (tmp) {
858
- for (list=Object.getOwnPropertySymbols(x); i < list.length; i++) {
859
- set(tmp, list[i], Object.getOwnPropertyDescriptor(x, list[i]));
860
- }
861
-
862
- for (i=0, list=Object.getOwnPropertyNames(x); i < list.length; i++) {
863
- if (Object.hasOwnProperty.call(tmp, k=list[i]) && tmp[k] === x[k]) continue;
864
- set(tmp, k, Object.getOwnPropertyDescriptor(x, k));
865
- }
866
- }
867
-
868
- return tmp || x;
869
- }
870
-
871
- var es6 = function equal(a, b) {
872
- if (a === b) return true;
873
-
874
- if (a && b && typeof a == 'object' && typeof b == 'object') {
875
- if (a.constructor !== b.constructor) return false;
876
-
877
- var length, i, keys;
878
- if (Array.isArray(a)) {
879
- length = a.length;
880
- if (length != b.length) return false;
881
- for (i = length; i-- !== 0;)
882
- if (!equal(a[i], b[i])) return false;
883
- return true;
884
- }
885
-
886
-
887
- if ((a instanceof Map) && (b instanceof Map)) {
888
- if (a.size !== b.size) return false;
889
- for (i of a.entries())
890
- if (!b.has(i[0])) return false;
891
- for (i of a.entries())
892
- if (!equal(i[1], b.get(i[0]))) return false;
893
- return true;
894
- }
895
-
896
- if ((a instanceof Set) && (b instanceof Set)) {
897
- if (a.size !== b.size) return false;
898
- for (i of a.entries())
899
- if (!b.has(i[0])) return false;
900
- return true;
901
- }
902
-
903
- if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
904
- length = a.length;
905
- if (length != b.length) return false;
906
- for (i = length; i-- !== 0;)
907
- if (a[i] !== b[i]) return false;
908
- return true;
909
- }
910
-
911
-
912
- if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
913
- if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
914
- if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
915
-
916
- keys = Object.keys(a);
917
- length = keys.length;
918
- if (length !== Object.keys(b).length) return false;
919
-
920
- for (i = length; i-- !== 0;)
921
- if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
922
-
923
- for (i = length; i-- !== 0;) {
924
- var key = keys[i];
925
-
926
- if (!equal(a[key], b[key])) return false;
927
- }
928
-
929
- return true;
930
- }
931
-
932
- // true if both NaN, false otherwise
933
- return a!==a && b!==b;
934
- };
935
-
936
- let ID_COUNTER = 0;
937
- function useFieldState(path, init) {
938
- const { value, initialValue, setInitialValue } = _useFieldValue(path, init.modelValue, !init.standalone);
939
- const { errorMessage, errors, setErrors } = _useFieldErrors(path, !init.standalone);
940
- const meta = _useFieldMeta(value, initialValue, errors);
941
- const id = ID_COUNTER >= Number.MAX_SAFE_INTEGER ? 0 : ++ID_COUNTER;
942
- function setState(state) {
943
- var _a;
944
- if ('value' in state) {
945
- value.value = state.value;
946
- }
947
- if ('errors' in state) {
948
- setErrors(state.errors);
949
- }
950
- if ('touched' in state) {
951
- meta.touched = (_a = state.touched) !== null && _a !== void 0 ? _a : meta.touched;
952
- }
953
- if ('initialValue' in state) {
954
- setInitialValue(state.initialValue);
955
- }
956
- }
957
- return {
958
- id,
959
- path,
960
- value,
961
- initialValue,
962
- meta,
963
- errors,
964
- errorMessage,
965
- setState,
966
- };
967
- }
968
- /**
969
- * Creates the field value and resolves the initial value
970
- */
971
- function _useFieldValue(path, modelValue, shouldInjectForm) {
972
- const form = shouldInjectForm ? injectWithSelf(FormContextKey, undefined) : undefined;
973
- const modelRef = ref(unref(modelValue));
974
- function resolveInitialValue() {
975
- if (!form) {
976
- return unref(modelRef);
977
- }
978
- return getFromPath(form.meta.value.initialValues, unref(path), unref(modelRef));
979
- }
980
- function setInitialValue(value) {
981
- if (!form) {
982
- modelRef.value = value;
983
- return;
984
- }
985
- form.setFieldInitialValue(unref(path), value);
986
- }
987
- const initialValue = computed(resolveInitialValue);
988
- // if no form is associated, use a regular ref.
989
- if (!form) {
990
- const value = ref(resolveInitialValue());
991
- return {
992
- value,
993
- initialValue,
994
- setInitialValue,
995
- };
996
- }
997
- // to set the initial value, first check if there is a current value, if there is then use it.
998
- // otherwise use the configured initial value if it exists.
999
- // prioritize model value over form values
1000
- // #3429
1001
- const currentValue = modelValue ? unref(modelValue) : getFromPath(form.values, unref(path), unref(initialValue));
1002
- form.stageInitialValue(unref(path), currentValue);
1003
- // otherwise use a computed setter that triggers the `setFieldValue`
1004
- const value = computed({
1005
- get() {
1006
- return getFromPath(form.values, unref(path));
1007
- },
1008
- set(newVal) {
1009
- form.setFieldValue(unref(path), newVal);
1010
- },
1011
- });
1012
- return {
1013
- value,
1014
- initialValue,
1015
- setInitialValue,
1016
- };
1017
- }
1018
- /**
1019
- * Creates meta flags state and some associated effects with them
1020
- */
1021
- function _useFieldMeta(currentValue, initialValue, errors) {
1022
- const meta = reactive({
1023
- touched: false,
1024
- pending: false,
1025
- valid: true,
1026
- validated: !!unref(errors).length,
1027
- initialValue: computed(() => unref(initialValue)),
1028
- dirty: computed(() => {
1029
- return !es6(unref(currentValue), unref(initialValue));
1030
- }),
1031
- });
1032
- watch(errors, value => {
1033
- meta.valid = !value.length;
1034
- }, {
1035
- immediate: true,
1036
- flush: 'sync',
1037
- });
1038
- return meta;
1039
- }
1040
- /**
1041
- * Creates the error message state for the field state
1042
- */
1043
- function _useFieldErrors(path, shouldInjectForm) {
1044
- const form = shouldInjectForm ? injectWithSelf(FormContextKey, undefined) : undefined;
1045
- function normalizeErrors(messages) {
1046
- if (!messages) {
1047
- return [];
1048
- }
1049
- return Array.isArray(messages) ? messages : [messages];
1050
- }
1051
- if (!form) {
1052
- const errors = ref([]);
1053
- return {
1054
- errors,
1055
- errorMessage: computed(() => errors.value[0]),
1056
- setErrors: (messages) => {
1057
- errors.value = normalizeErrors(messages);
1058
- },
1059
- };
1060
- }
1061
- const errors = computed(() => form.errorBag.value[unref(path)] || []);
1062
- return {
1063
- errors,
1064
- errorMessage: computed(() => errors.value[0]),
1065
- setErrors: (messages) => {
1066
- form.setFieldErrorBag(unref(path), normalizeErrors(messages));
1067
- },
1068
- };
1069
- }
1070
-
1071
- function installDevtoolsPlugin(app) {
1072
- if (("production" !== 'production')) {
1073
- setupDevtoolsPlugin({
1074
- id: 'vee-validate-devtools-plugin',
1075
- label: 'VeeValidate Plugin',
1076
- packageName: 'vee-validate',
1077
- homepage: 'https://vee-validate.logaretm.com/v4',
1078
- app,
1079
- logo: 'https://vee-validate.logaretm.com/v4/logo.png',
1080
- }, setupApiHooks);
1081
- }
1082
- }
1083
- const DEVTOOLS_FORMS = {};
1084
- const DEVTOOLS_FIELDS = {};
1085
- let API;
1086
- const refreshInspector = throttle(() => {
1087
- setTimeout(async () => {
1088
- await nextTick();
1089
- API === null || API === void 0 ? void 0 : API.sendInspectorState(INSPECTOR_ID);
1090
- API === null || API === void 0 ? void 0 : API.sendInspectorTree(INSPECTOR_ID);
1091
- }, 100);
1092
- }, 100);
1093
- function registerFormWithDevTools(form) {
1094
- const vm = getCurrentInstance();
1095
- if (!API) {
1096
- const app = vm === null || vm === void 0 ? void 0 : vm.appContext.app;
1097
- if (!app) {
1098
- return;
1099
- }
1100
- installDevtoolsPlugin(app);
1101
- }
1102
- DEVTOOLS_FORMS[form.formId] = Object.assign({}, form);
1103
- DEVTOOLS_FORMS[form.formId]._vm = vm;
1104
- onUnmounted(() => {
1105
- delete DEVTOOLS_FORMS[form.formId];
1106
- refreshInspector();
1107
- });
1108
- refreshInspector();
1109
- }
1110
- function registerSingleFieldWithDevtools(field) {
1111
- const vm = getCurrentInstance();
1112
- if (!API) {
1113
- const app = vm === null || vm === void 0 ? void 0 : vm.appContext.app;
1114
- if (!app) {
1115
- return;
1116
- }
1117
- installDevtoolsPlugin(app);
1118
- }
1119
- DEVTOOLS_FIELDS[field.id] = Object.assign({}, field);
1120
- DEVTOOLS_FIELDS[field.id]._vm = vm;
1121
- onUnmounted(() => {
1122
- delete DEVTOOLS_FIELDS[field.id];
1123
- refreshInspector();
1124
- });
1125
- refreshInspector();
1126
- }
1127
- const INSPECTOR_ID = 'vee-validate-inspector';
1128
- const COLORS = {
1129
- error: 0xbd4b4b,
1130
- success: 0x06d77b,
1131
- unknown: 0x54436b,
1132
- white: 0xffffff,
1133
- black: 0x000000,
1134
- blue: 0x035397,
1135
- purple: 0xb980f0,
1136
- orange: 0xf5a962,
1137
- gray: 0xbbbfca,
1138
- };
1139
- let SELECTED_NODE = null;
1140
- function setupApiHooks(api) {
1141
- API = api;
1142
- api.addInspector({
1143
- id: INSPECTOR_ID,
1144
- icon: 'rule',
1145
- label: 'vee-validate',
1146
- noSelectionText: 'Select a vee-validate node to inspect',
1147
- actions: [
1148
- {
1149
- icon: 'done_outline',
1150
- tooltip: 'Validate selected item',
1151
- action: async () => {
1152
- if (!SELECTED_NODE) {
1153
- console.error('There is not a valid selected vee-validate node or component');
1154
- return;
1155
- }
1156
- const result = await SELECTED_NODE.validate();
1157
- console.log(result);
1158
- },
1159
- },
1160
- {
1161
- icon: 'delete_sweep',
1162
- tooltip: 'Clear validation state of the selected item',
1163
- action: () => {
1164
- if (!SELECTED_NODE) {
1165
- console.error('There is not a valid selected vee-validate node or component');
1166
- return;
1167
- }
1168
- if ('id' in SELECTED_NODE) {
1169
- SELECTED_NODE.resetField();
1170
- return;
1171
- }
1172
- SELECTED_NODE.resetForm();
1173
- },
1174
- },
1175
- ],
1176
- });
1177
- api.on.getInspectorTree(payload => {
1178
- if (payload.inspectorId !== INSPECTOR_ID) {
1179
- return;
1180
- }
1181
- const forms = Object.values(DEVTOOLS_FORMS);
1182
- const fields = Object.values(DEVTOOLS_FIELDS);
1183
- payload.rootNodes = [
1184
- ...forms.map(mapFormForDevtoolsInspector),
1185
- ...fields.map(field => mapFieldForDevtoolsInspector(field)),
1186
- ];
1187
- });
1188
- api.on.getInspectorState((payload, ctx) => {
1189
- if (payload.inspectorId !== INSPECTOR_ID || ctx.currentTab !== `custom-inspector:${INSPECTOR_ID}`) {
1190
- return;
1191
- }
1192
- const { form, field, type } = decodeNodeId(payload.nodeId);
1193
- if (form && type === 'form') {
1194
- payload.state = buildFormState(form);
1195
- SELECTED_NODE = form;
1196
- return;
1197
- }
1198
- if (field && type === 'field') {
1199
- payload.state = buildFieldState(field);
1200
- SELECTED_NODE = field;
1201
- return;
1202
- }
1203
- SELECTED_NODE = null;
1204
- });
1205
- }
1206
- function mapFormForDevtoolsInspector(form) {
1207
- const { textColor, bgColor } = getTagTheme(form);
1208
- const formTreeNodes = {};
1209
- Object.values(form.fieldsByPath.value).forEach(field => {
1210
- const fieldInstance = Array.isArray(field) ? field[0] : field;
1211
- if (!fieldInstance) {
1212
- return;
1213
- }
1214
- setInPath(formTreeNodes, unref(fieldInstance.name), mapFieldForDevtoolsInspector(fieldInstance, form));
1215
- });
1216
- function buildFormTree(tree, path = []) {
1217
- const key = [...path].pop();
1218
- if ('id' in tree) {
1219
- return Object.assign(Object.assign({}, tree), { label: key || tree.label });
1220
- }
1221
- if (isObject(tree)) {
1222
- return {
1223
- id: `${path.join('.')}`,
1224
- label: key || '',
1225
- children: Object.keys(tree).map(key => buildFormTree(tree[key], [...path, key])),
1226
- };
1227
- }
1228
- if (Array.isArray(tree)) {
1229
- return {
1230
- id: `${path.join('.')}`,
1231
- label: `${key}[]`,
1232
- children: tree.map((c, idx) => buildFormTree(c, [...path, String(idx)])),
1233
- };
1234
- }
1235
- return { id: '', label: '', children: [] };
1236
- }
1237
- const { children } = buildFormTree(formTreeNodes);
1238
- return {
1239
- id: encodeNodeId(form),
1240
- label: 'Form',
1241
- children,
1242
- tags: [
1243
- {
1244
- label: 'Form',
1245
- textColor,
1246
- backgroundColor: bgColor,
1247
- },
1248
- {
1249
- label: `${Object.keys(form.fieldsByPath.value).length} fields`,
1250
- textColor: COLORS.white,
1251
- backgroundColor: COLORS.unknown,
1252
- },
1253
- ],
1254
- };
1255
- }
1256
- function mapFieldForDevtoolsInspector(field, form) {
1257
- const fieldInstance = normalizeField(field);
1258
- const { textColor, bgColor } = getTagTheme(fieldInstance);
1259
- const isGroup = Array.isArray(field) && field.length > 1;
1260
- return {
1261
- id: encodeNodeId(form, fieldInstance, !isGroup),
1262
- label: unref(fieldInstance.name),
1263
- children: Array.isArray(field) ? field.map(fieldItem => mapFieldForDevtoolsInspector(fieldItem, form)) : undefined,
1264
- tags: [
1265
- isGroup
1266
- ? undefined
1267
- : {
1268
- label: 'Field',
1269
- textColor,
1270
- backgroundColor: bgColor,
1271
- },
1272
- !form
1273
- ? {
1274
- label: 'Standalone',
1275
- textColor: COLORS.black,
1276
- backgroundColor: COLORS.gray,
1277
- }
1278
- : undefined,
1279
- !isGroup && fieldInstance.type === 'checkbox'
1280
- ? {
1281
- label: 'Checkbox',
1282
- textColor: COLORS.white,
1283
- backgroundColor: COLORS.blue,
1284
- }
1285
- : undefined,
1286
- !isGroup && fieldInstance.type === 'radio'
1287
- ? {
1288
- label: 'Radio',
1289
- textColor: COLORS.white,
1290
- backgroundColor: COLORS.purple,
1291
- }
1292
- : undefined,
1293
- isGroup
1294
- ? {
1295
- label: 'Group',
1296
- textColor: COLORS.black,
1297
- backgroundColor: COLORS.orange,
1298
- }
1299
- : undefined,
1300
- ].filter(Boolean),
1301
- };
1302
- }
1303
- function encodeNodeId(form, field, encodeIndex = true) {
1304
- const fieldPath = form ? unref(field === null || field === void 0 ? void 0 : field.name) : field === null || field === void 0 ? void 0 : field.id;
1305
- const fieldGroup = fieldPath ? form === null || form === void 0 ? void 0 : form.fieldsByPath.value[fieldPath] : undefined;
1306
- let idx;
1307
- if (encodeIndex && field && Array.isArray(fieldGroup)) {
1308
- idx = fieldGroup.indexOf(field);
1309
- }
1310
- const idObject = { f: form === null || form === void 0 ? void 0 : form.formId, ff: fieldPath, idx, type: field ? 'field' : 'form' };
1311
- return btoa(JSON.stringify(idObject));
1312
- }
1313
- function decodeNodeId(nodeId) {
1314
- try {
1315
- const idObject = JSON.parse(atob(nodeId));
1316
- const form = DEVTOOLS_FORMS[idObject.f];
1317
- if (!form && idObject.ff) {
1318
- const field = DEVTOOLS_FIELDS[idObject.ff];
1319
- if (!field) {
1320
- return {};
1321
- }
1322
- return {
1323
- type: idObject.type,
1324
- field,
1325
- };
1326
- }
1327
- if (!form) {
1328
- return {};
1329
- }
1330
- const fieldGroup = form.fieldsByPath.value[idObject.ff];
1331
- return {
1332
- type: idObject.type,
1333
- form,
1334
- field: Array.isArray(fieldGroup) ? fieldGroup[idObject.idx || 0] : fieldGroup,
1335
- };
1336
- }
1337
- catch (err) {
1338
- // console.error(`Devtools: [vee-validate] Failed to parse node id ${nodeId}`);
1339
- }
1340
- return {};
1341
- }
1342
- function buildFieldState(field) {
1343
- const { errors, meta, value } = field;
1344
- return {
1345
- 'Field state': [
1346
- { key: 'errors', value: errors.value },
1347
- {
1348
- key: 'initialValue',
1349
- value: meta.initialValue,
1350
- },
1351
- {
1352
- key: 'currentValue',
1353
- value: value.value,
1354
- },
1355
- {
1356
- key: 'touched',
1357
- value: meta.touched,
1358
- },
1359
- {
1360
- key: 'dirty',
1361
- value: meta.dirty,
1362
- },
1363
- {
1364
- key: 'valid',
1365
- value: meta.valid,
1366
- },
1367
- ],
1368
- };
1369
- }
1370
- function buildFormState(form) {
1371
- const { errorBag, meta, values, isSubmitting, submitCount } = form;
1372
- return {
1373
- 'Form state': [
1374
- {
1375
- key: 'submitCount',
1376
- value: submitCount.value,
1377
- },
1378
- {
1379
- key: 'isSubmitting',
1380
- value: isSubmitting.value,
1381
- },
1382
- {
1383
- key: 'touched',
1384
- value: meta.value.touched,
1385
- },
1386
- {
1387
- key: 'dirty',
1388
- value: meta.value.dirty,
1389
- },
1390
- {
1391
- key: 'valid',
1392
- value: meta.value.valid,
1393
- },
1394
- {
1395
- key: 'initialValues',
1396
- value: meta.value.initialValues,
1397
- },
1398
- {
1399
- key: 'currentValues',
1400
- value: values,
1401
- },
1402
- {
1403
- key: 'errors',
1404
- value: keysOf(errorBag.value).reduce((acc, key) => {
1405
- var _a;
1406
- const message = (_a = errorBag.value[key]) === null || _a === void 0 ? void 0 : _a[0];
1407
- if (message) {
1408
- acc[key] = message;
1409
- }
1410
- return acc;
1411
- }, {}),
1412
- },
1413
- ],
1414
- };
1415
- }
1416
- /**
1417
- * Resolves the tag color based on the form state
1418
- */
1419
- function getTagTheme(fieldOrForm) {
1420
- // const fallbackColors = {
1421
- // bgColor: COLORS.unknown,
1422
- // textColor: COLORS.white,
1423
- // };
1424
- const isValid = 'id' in fieldOrForm ? fieldOrForm.meta.valid : fieldOrForm.meta.value.valid;
1425
- return {
1426
- bgColor: isValid ? COLORS.success : COLORS.error,
1427
- textColor: isValid ? COLORS.black : COLORS.white,
1428
- };
1429
- }
1430
-
1431
- /**
1432
- * Creates a field composite.
1433
- */
1434
- function useField(name, rules, opts) {
1435
- if (hasCheckedAttr(opts === null || opts === void 0 ? void 0 : opts.type)) {
1436
- return useCheckboxField(name, rules, opts);
1437
- }
1438
- return _useField(name, rules, opts);
1439
- }
1440
- function _useField(name, rules, opts) {
1441
- const { initialValue: modelValue, validateOnMount, bails, type, checkedValue, label, validateOnValueUpdate, uncheckedValue, standalone, } = normalizeOptions(unref(name), opts);
1442
- const form = !standalone ? injectWithSelf(FormContextKey) : undefined;
1443
- const { id, value, initialValue, meta, setState, errors, errorMessage } = useFieldState(name, {
1444
- modelValue,
1445
- standalone,
1446
- });
1447
- /**
1448
- * Handles common onBlur meta update
1449
- */
1450
- const handleBlur = () => {
1451
- meta.touched = true;
1452
- };
1453
- const normalizedRules = computed(() => {
1454
- let rulesValue = unref(rules);
1455
- const schema = unref(form === null || form === void 0 ? void 0 : form.schema);
1456
- if (schema && !isYupValidator(schema)) {
1457
- rulesValue = extractRuleFromSchema(schema, unref(name)) || rulesValue;
1458
- }
1459
- if (isYupValidator(rulesValue) || isCallable(rulesValue)) {
1460
- return rulesValue;
1461
- }
1462
- return normalizeRules(rulesValue);
1463
- });
1464
- async function validateCurrentValue(mode) {
1465
- var _a, _b;
1466
- if (form === null || form === void 0 ? void 0 : form.validateSchema) {
1467
- return (_a = (await form.validateSchema(mode)).results[unref(name)]) !== null && _a !== void 0 ? _a : { valid: true, errors: [] };
1468
- }
1469
- return validate(value.value, normalizedRules.value, {
1470
- name: unref(label) || unref(name),
1471
- values: (_b = form === null || form === void 0 ? void 0 : form.values) !== null && _b !== void 0 ? _b : {},
1472
- bails,
1473
- });
1474
- }
1475
- async function validateWithStateMutation() {
1476
- meta.pending = true;
1477
- meta.validated = true;
1478
- const result = await validateCurrentValue('validated-only');
1479
- setState({ errors: result.errors });
1480
- meta.pending = false;
1481
- return result;
1482
- }
1483
- async function validateValidStateOnly() {
1484
- const result = await validateCurrentValue('silent');
1485
- meta.valid = result.valid;
1486
- return result;
1487
- }
1488
- function validate$1(opts) {
1489
- if (!(opts === null || opts === void 0 ? void 0 : opts.mode) || (opts === null || opts === void 0 ? void 0 : opts.mode) === 'force') {
1490
- return validateWithStateMutation();
1491
- }
1492
- if ((opts === null || opts === void 0 ? void 0 : opts.mode) === 'validated-only') {
1493
- return validateWithStateMutation();
1494
- }
1495
- return validateValidStateOnly();
1496
- }
1497
- // Common input/change event handler
1498
- const handleChange = (e, shouldValidate = true) => {
1499
- const newValue = normalizeEventValue(e);
1500
- value.value = newValue;
1501
- if (!validateOnValueUpdate && shouldValidate) {
1502
- validateWithStateMutation();
1503
- }
1504
- };
1505
- // Runs the initial validation
1506
- onMounted(() => {
1507
- if (validateOnMount) {
1508
- return validateWithStateMutation();
1509
- }
1510
- // validate self initially if no form was handling this
1511
- // forms should have their own initial silent validation run to make things more efficient
1512
- if (!form || !form.validateSchema) {
1513
- validateValidStateOnly();
1514
- }
1515
- });
1516
- function setTouched(isTouched) {
1517
- meta.touched = isTouched;
1518
- }
1519
- let unwatchValue;
1520
- function watchValue() {
1521
- unwatchValue = watch(value, validateOnValueUpdate ? validateWithStateMutation : validateValidStateOnly, {
1522
- deep: true,
1523
- });
1524
- }
1525
- watchValue();
1526
- function resetField(state) {
1527
- var _a;
1528
- unwatchValue === null || unwatchValue === void 0 ? void 0 : unwatchValue();
1529
- const newValue = state && 'value' in state ? state.value : initialValue.value;
1530
- setState({
1531
- value: klona(newValue),
1532
- initialValue: klona(newValue),
1533
- touched: (_a = state === null || state === void 0 ? void 0 : state.touched) !== null && _a !== void 0 ? _a : false,
1534
- errors: (state === null || state === void 0 ? void 0 : state.errors) || [],
1535
- });
1536
- meta.pending = false;
1537
- meta.validated = false;
1538
- validateValidStateOnly();
1539
- // need to watch at next tick to avoid triggering the value watcher
1540
- nextTick(() => {
1541
- watchValue();
1542
- });
1543
- }
1544
- function setValue(newValue) {
1545
- value.value = newValue;
1546
- }
1547
- function setErrors(errors) {
1548
- setState({ errors: Array.isArray(errors) ? errors : [errors] });
1549
- }
1550
- const field = {
1551
- id,
1552
- name,
1553
- label,
1554
- value,
1555
- meta,
1556
- errors,
1557
- errorMessage,
1558
- type,
1559
- checkedValue,
1560
- uncheckedValue,
1561
- bails,
1562
- resetField,
1563
- handleReset: () => resetField(),
1564
- validate: validate$1,
1565
- handleChange,
1566
- handleBlur,
1567
- setState,
1568
- setTouched,
1569
- setErrors,
1570
- setValue,
1571
- };
1572
- provide(FieldContextKey, field);
1573
- if (isRef(rules) && typeof unref(rules) !== 'function') {
1574
- watch(rules, (value, oldValue) => {
1575
- if (es6(value, oldValue)) {
1576
- return;
1577
- }
1578
- meta.validated ? validateWithStateMutation() : validateValidStateOnly();
1579
- }, {
1580
- deep: true,
1581
- });
1582
- }
1583
- if (("production" !== 'production')) {
1584
- field._vm = getCurrentInstance();
1585
- watch(() => (Object.assign(Object.assign({ errors: errors.value }, meta), { value: value.value })), refreshInspector, {
1586
- deep: true,
1587
- });
1588
- if (!form) {
1589
- registerSingleFieldWithDevtools(field);
1590
- }
1591
- }
1592
- // if no associated form return the field API immediately
1593
- if (!form) {
1594
- return field;
1595
- }
1596
- // associate the field with the given form
1597
- form.register(field);
1598
- onBeforeUnmount(() => {
1599
- form.unregister(field);
1600
- });
1601
- // extract cross-field dependencies in a computed prop
1602
- const dependencies = computed(() => {
1603
- const rulesVal = normalizedRules.value;
1604
- // is falsy, a function schema or a yup schema
1605
- if (!rulesVal || isCallable(rulesVal) || isYupValidator(rulesVal)) {
1606
- return {};
1607
- }
1608
- return Object.keys(rulesVal).reduce((acc, rule) => {
1609
- const deps = extractLocators(rulesVal[rule])
1610
- .map((dep) => dep.__locatorRef)
1611
- .reduce((depAcc, depName) => {
1612
- const depValue = getFromPath(form.values, depName) || form.values[depName];
1613
- if (depValue !== undefined) {
1614
- depAcc[depName] = depValue;
1615
- }
1616
- return depAcc;
1617
- }, {});
1618
- Object.assign(acc, deps);
1619
- return acc;
1620
- }, {});
1621
- });
1622
- // Adds a watcher that runs the validation whenever field dependencies change
1623
- watch(dependencies, (deps, oldDeps) => {
1624
- // Skip if no dependencies or if the field wasn't manipulated
1625
- if (!Object.keys(deps).length) {
1626
- return;
1627
- }
1628
- const shouldValidate = !es6(deps, oldDeps);
1629
- if (shouldValidate) {
1630
- meta.validated ? validateWithStateMutation() : validateValidStateOnly();
1631
- }
1632
- });
1633
- return field;
1634
- }
1635
- /**
1636
- * Normalizes partial field options to include the full options
1637
- */
1638
- function normalizeOptions(name, opts) {
1639
- const defaults = () => ({
1640
- initialValue: undefined,
1641
- validateOnMount: false,
1642
- bails: true,
1643
- rules: '',
1644
- label: name,
1645
- validateOnValueUpdate: true,
1646
- standalone: false,
1647
- });
1648
- if (!opts) {
1649
- return defaults();
1650
- }
1651
- // TODO: Deprecate this in next major release
1652
- const checkedValue = 'valueProp' in opts ? opts.valueProp : opts.checkedValue;
1653
- return Object.assign(Object.assign(Object.assign({}, defaults()), (opts || {})), { checkedValue });
1654
- }
1655
- /**
1656
- * Extracts the validation rules from a schema
1657
- */
1658
- function extractRuleFromSchema(schema, fieldName) {
1659
- // no schema at all
1660
- if (!schema) {
1661
- return undefined;
1662
- }
1663
- // there is a key on the schema object for this field
1664
- return schema[fieldName];
1665
- }
1666
- function useCheckboxField(name, rules, opts) {
1667
- const form = !(opts === null || opts === void 0 ? void 0 : opts.standalone) ? injectWithSelf(FormContextKey) : undefined;
1668
- const checkedValue = opts === null || opts === void 0 ? void 0 : opts.checkedValue;
1669
- const uncheckedValue = opts === null || opts === void 0 ? void 0 : opts.uncheckedValue;
1670
- function patchCheckboxApi(field) {
1671
- const handleChange = field.handleChange;
1672
- const checked = computed(() => {
1673
- const currentValue = unref(field.value);
1674
- const checkedVal = unref(checkedValue);
1675
- return Array.isArray(currentValue) ? currentValue.includes(checkedVal) : checkedVal === currentValue;
1676
- });
1677
- function handleCheckboxChange(e, shouldValidate = true) {
1678
- var _a, _b;
1679
- if (checked.value === ((_b = (_a = e) === null || _a === void 0 ? void 0 : _a.target) === null || _b === void 0 ? void 0 : _b.checked)) {
1680
- return;
1681
- }
1682
- let newValue = normalizeEventValue(e);
1683
- // Single checkbox field without a form to toggle it's value
1684
- if (!form) {
1685
- newValue = resolveNextCheckboxValue(unref(field.value), unref(checkedValue), unref(uncheckedValue));
1686
- }
1687
- handleChange(newValue, shouldValidate);
1688
- }
1689
- onBeforeUnmount(() => {
1690
- // toggles the checkbox value if it was checked
1691
- if (checked.value) {
1692
- handleCheckboxChange(unref(checkedValue), false);
1693
- }
1694
- });
1695
- return Object.assign(Object.assign({}, field), { checked,
1696
- checkedValue,
1697
- uncheckedValue, handleChange: handleCheckboxChange });
1698
- }
1699
- return patchCheckboxApi(_useField(name, rules, opts));
1700
- }
1701
-
1702
- const FieldImpl = defineComponent({
1703
- name: 'Field',
1704
- inheritAttrs: false,
1705
- props: {
1706
- as: {
1707
- type: [String, Object],
1708
- default: undefined,
1709
- },
1710
- name: {
1711
- type: String,
1712
- required: true,
1713
- },
1714
- rules: {
1715
- type: [Object, String, Function],
1716
- default: undefined,
1717
- },
1718
- validateOnMount: {
1719
- type: Boolean,
1720
- default: false,
1721
- },
1722
- validateOnBlur: {
1723
- type: Boolean,
1724
- default: undefined,
1725
- },
1726
- validateOnChange: {
1727
- type: Boolean,
1728
- default: undefined,
1729
- },
1730
- validateOnInput: {
1731
- type: Boolean,
1732
- default: undefined,
1733
- },
1734
- validateOnModelUpdate: {
1735
- type: Boolean,
1736
- default: undefined,
1737
- },
1738
- bails: {
1739
- type: Boolean,
1740
- default: () => getConfig().bails,
1741
- },
1742
- label: {
1743
- type: String,
1744
- default: undefined,
1745
- },
1746
- uncheckedValue: {
1747
- type: null,
1748
- default: undefined,
1749
- },
1750
- modelValue: {
1751
- type: null,
1752
- default: IS_ABSENT,
1753
- },
1754
- modelModifiers: {
1755
- type: null,
1756
- default: () => ({}),
1757
- },
1758
- 'onUpdate:modelValue': {
1759
- type: null,
1760
- default: undefined,
1761
- },
1762
- standalone: {
1763
- type: Boolean,
1764
- default: false,
1765
- },
1766
- },
1767
- setup(props, ctx) {
1768
- const rules = toRef(props, 'rules');
1769
- const name = toRef(props, 'name');
1770
- const label = toRef(props, 'label');
1771
- const uncheckedValue = toRef(props, 'uncheckedValue');
1772
- const hasModelEvents = isPropPresent(props, 'onUpdate:modelValue');
1773
- const { errors, value, errorMessage, validate: validateField, handleChange, handleBlur, setTouched, resetField, handleReset, meta, checked, setErrors, } = useField(name, rules, {
1774
- validateOnMount: props.validateOnMount,
1775
- bails: props.bails,
1776
- standalone: props.standalone,
1777
- type: ctx.attrs.type,
1778
- initialValue: resolveInitialValue(props, ctx),
1779
- // Only for checkboxes and radio buttons
1780
- checkedValue: ctx.attrs.value,
1781
- uncheckedValue,
1782
- label,
1783
- validateOnValueUpdate: false,
1784
- });
1785
- // If there is a v-model applied on the component we need to emit the `update:modelValue` whenever the value binding changes
1786
- const onChangeHandler = hasModelEvents
1787
- ? function handleChangeWithModel(e, shouldValidate = true) {
1788
- handleChange(e, shouldValidate);
1789
- ctx.emit('update:modelValue', value.value);
1790
- }
1791
- : handleChange;
1792
- const handleInput = (e) => {
1793
- if (!hasCheckedAttr(ctx.attrs.type)) {
1794
- value.value = normalizeEventValue(e);
1795
- }
1796
- };
1797
- const onInputHandler = hasModelEvents
1798
- ? function handleInputWithModel(e) {
1799
- handleInput(e);
1800
- ctx.emit('update:modelValue', value.value);
1801
- }
1802
- : handleInput;
1803
- const fieldProps = computed(() => {
1804
- const { validateOnInput, validateOnChange, validateOnBlur, validateOnModelUpdate } = resolveValidationTriggers(props);
1805
- const baseOnBlur = [handleBlur, ctx.attrs.onBlur, validateOnBlur ? validateField : undefined].filter(Boolean);
1806
- const baseOnInput = [(e) => onChangeHandler(e, validateOnInput), ctx.attrs.onInput].filter(Boolean);
1807
- const baseOnChange = [(e) => onChangeHandler(e, validateOnChange), ctx.attrs.onChange].filter(Boolean);
1808
- const attrs = {
1809
- name: props.name,
1810
- onBlur: baseOnBlur,
1811
- onInput: baseOnInput,
1812
- onChange: baseOnChange,
1813
- };
1814
- attrs['onUpdate:modelValue'] = e => onChangeHandler(e, validateOnModelUpdate);
1815
- if (hasCheckedAttr(ctx.attrs.type) && checked) {
1816
- attrs.checked = checked.value;
1817
- }
1818
- else {
1819
- attrs.value = value.value;
1820
- }
1821
- const tag = resolveTag(props, ctx);
1822
- if (shouldHaveValueBinding(tag, ctx.attrs)) {
1823
- delete attrs.value;
1824
- }
1825
- return attrs;
1826
- });
1827
- const modelValue = toRef(props, 'modelValue');
1828
- watch(modelValue, newModelValue => {
1829
- // Don't attempt to sync absent values
1830
- if (newModelValue === IS_ABSENT && value.value === undefined) {
1831
- return;
1832
- }
1833
- if (newModelValue !== applyModifiers(value.value, props.modelModifiers)) {
1834
- value.value = newModelValue === IS_ABSENT ? undefined : newModelValue;
1835
- validateField();
1836
- }
1837
- });
1838
- function slotProps() {
1839
- return {
1840
- field: fieldProps.value,
1841
- value: value.value,
1842
- meta,
1843
- errors: errors.value,
1844
- errorMessage: errorMessage.value,
1845
- validate: validateField,
1846
- resetField,
1847
- handleChange: onChangeHandler,
1848
- handleInput: onInputHandler,
1849
- handleReset,
1850
- handleBlur,
1851
- setTouched,
1852
- setErrors,
1853
- };
1854
- }
1855
- ctx.expose({
1856
- setErrors,
1857
- setTouched,
1858
- reset: resetField,
1859
- validate: validateField,
1860
- handleChange,
1861
- });
1862
- return () => {
1863
- const tag = resolveDynamicComponent(resolveTag(props, ctx));
1864
- const children = normalizeChildren(tag, ctx, slotProps);
1865
- if (tag) {
1866
- return h(tag, Object.assign(Object.assign({}, ctx.attrs), fieldProps.value), children);
1867
- }
1868
- return children;
1869
- };
1870
- },
1871
- });
1872
- function resolveTag(props, ctx) {
1873
- let tag = props.as || '';
1874
- if (!props.as && !ctx.slots.default) {
1875
- tag = 'input';
1876
- }
1877
- return tag;
1878
- }
1879
- function resolveValidationTriggers(props) {
1880
- var _a, _b, _c, _d;
1881
- const { validateOnInput, validateOnChange, validateOnBlur, validateOnModelUpdate } = getConfig();
1882
- return {
1883
- validateOnInput: (_a = props.validateOnInput) !== null && _a !== void 0 ? _a : validateOnInput,
1884
- validateOnChange: (_b = props.validateOnChange) !== null && _b !== void 0 ? _b : validateOnChange,
1885
- validateOnBlur: (_c = props.validateOnBlur) !== null && _c !== void 0 ? _c : validateOnBlur,
1886
- validateOnModelUpdate: (_d = props.validateOnModelUpdate) !== null && _d !== void 0 ? _d : validateOnModelUpdate,
1887
- };
1888
- }
1889
- function applyModifiers(value, modifiers) {
1890
- if (modifiers.number) {
1891
- return toNumber(value);
1892
- }
1893
- return value;
1894
- }
1895
- function resolveInitialValue(props, ctx) {
1896
- // Gets the initial value either from `value` prop/attr or `v-model` binding (modelValue)
1897
- // For checkboxes and radio buttons it will always be the model value not the `value` attribute
1898
- if (!hasCheckedAttr(ctx.attrs.type)) {
1899
- return isPropPresent(props, 'modelValue') ? props.modelValue : ctx.attrs.value;
1900
- }
1901
- return isPropPresent(props, 'modelValue') ? props.modelValue : undefined;
1902
- }
1903
- const Field = FieldImpl;
1904
-
1905
- let FORM_COUNTER = 0;
1906
- function useForm(opts) {
1907
- const formId = FORM_COUNTER++;
1908
- // Prevents fields from double resetting their values, which causes checkboxes to toggle their initial value
1909
- // TODO: This won't be needed if we centralize all the state inside the `form` for form inputs
1910
- let RESET_LOCK = false;
1911
- // A lookup containing fields or field groups
1912
- const fieldsByPath = ref({});
1913
- // If the form is currently submitting
1914
- const isSubmitting = ref(false);
1915
- // The number of times the user tried to submit the form
1916
- const submitCount = ref(0);
1917
- // dictionary for field arrays to receive various signals like reset
1918
- const fieldArraysLookup = {};
1919
- // a private ref for all form values
1920
- const formValues = reactive(klona(unref(opts === null || opts === void 0 ? void 0 : opts.initialValues) || {}));
1921
- // the source of errors for the form fields
1922
- const { errorBag, setErrorBag, setFieldErrorBag } = useErrorBag(opts === null || opts === void 0 ? void 0 : opts.initialErrors);
1923
- // Gets the first error of each field
1924
- const errors = computed(() => {
1925
- return keysOf(errorBag.value).reduce((acc, key) => {
1926
- const bag = errorBag.value[key];
1927
- if (bag && bag.length) {
1928
- acc[key] = bag[0];
1929
- }
1930
- return acc;
1931
- }, {});
1932
- });
1933
- function getFirstFieldAtPath(path) {
1934
- const fieldOrGroup = fieldsByPath.value[path];
1935
- return Array.isArray(fieldOrGroup) ? fieldOrGroup[0] : fieldOrGroup;
1936
- }
1937
- function fieldExists(path) {
1938
- return !!fieldsByPath.value[path];
1939
- }
1940
- /**
1941
- * Holds a computed reference to all fields names and labels
1942
- */
1943
- const fieldNames = computed(() => {
1944
- return keysOf(fieldsByPath.value).reduce((names, path) => {
1945
- const field = getFirstFieldAtPath(path);
1946
- if (field) {
1947
- names[path] = unref(field.label || field.name) || '';
1948
- }
1949
- return names;
1950
- }, {});
1951
- });
1952
- const fieldBailsMap = computed(() => {
1953
- return keysOf(fieldsByPath.value).reduce((map, path) => {
1954
- var _a;
1955
- const field = getFirstFieldAtPath(path);
1956
- if (field) {
1957
- map[path] = (_a = field.bails) !== null && _a !== void 0 ? _a : true;
1958
- }
1959
- return map;
1960
- }, {});
1961
- });
1962
- // mutable non-reactive reference to initial errors
1963
- // we need this to process initial errors then unset them
1964
- const initialErrors = Object.assign({}, ((opts === null || opts === void 0 ? void 0 : opts.initialErrors) || {}));
1965
- // initial form values
1966
- const { initialValues, originalInitialValues, setInitialValues } = useFormInitialValues(fieldsByPath, formValues, opts === null || opts === void 0 ? void 0 : opts.initialValues);
1967
- // form meta aggregations
1968
- const meta = useFormMeta(fieldsByPath, formValues, initialValues, errors);
1969
- const schema = opts === null || opts === void 0 ? void 0 : opts.validationSchema;
1970
- const formCtx = {
1971
- formId,
1972
- fieldsByPath,
1973
- values: formValues,
1974
- errorBag,
1975
- errors,
1976
- schema,
1977
- submitCount,
1978
- meta,
1979
- isSubmitting,
1980
- fieldArraysLookup,
1981
- validateSchema: unref(schema) ? validateSchema : undefined,
1982
- validate,
1983
- register: registerField,
1984
- unregister: unregisterField,
1985
- setFieldErrorBag,
1986
- validateField,
1987
- setFieldValue,
1988
- setValues,
1989
- setErrors,
1990
- setFieldError,
1991
- setFieldTouched,
1992
- setTouched,
1993
- resetForm,
1994
- handleSubmit,
1995
- stageInitialValue,
1996
- unsetInitialValue,
1997
- setFieldInitialValue,
1998
- };
1999
- function isFieldGroup(fieldOrGroup) {
2000
- return Array.isArray(fieldOrGroup);
2001
- }
2002
- function applyFieldMutation(fieldOrGroup, mutation) {
2003
- if (Array.isArray(fieldOrGroup)) {
2004
- return fieldOrGroup.forEach(mutation);
2005
- }
2006
- return mutation(fieldOrGroup);
2007
- }
2008
- function mutateAllFields(mutation) {
2009
- Object.values(fieldsByPath.value).forEach(field => {
2010
- if (!field) {
2011
- return;
2012
- }
2013
- // avoid resetting the field values, because they should've been reset already.
2014
- applyFieldMutation(field, mutation);
2015
- });
2016
- }
2017
- /**
2018
- * Manually sets an error message on a specific field
2019
- */
2020
- function setFieldError(field, message) {
2021
- setFieldErrorBag(field, message);
2022
- }
2023
- /**
2024
- * Sets errors for the fields specified in the object
2025
- */
2026
- function setErrors(fields) {
2027
- setErrorBag(fields);
2028
- }
2029
- /**
2030
- * Sets a single field value
2031
- */
2032
- function setFieldValue(field, value, { force } = { force: false }) {
2033
- var _a;
2034
- const fieldInstance = fieldsByPath.value[field];
2035
- const clonedValue = klona(value);
2036
- // field wasn't found, create a virtual field as a placeholder
2037
- if (!fieldInstance) {
2038
- setInPath(formValues, field, clonedValue);
2039
- return;
2040
- }
2041
- if (isFieldGroup(fieldInstance) && ((_a = fieldInstance[0]) === null || _a === void 0 ? void 0 : _a.type) === 'checkbox' && !Array.isArray(value)) {
2042
- // Multiple checkboxes, and only one of them got updated
2043
- const newValue = klona(resolveNextCheckboxValue(getFromPath(formValues, field) || [], value, undefined));
2044
- setInPath(formValues, field, newValue);
2045
- return;
2046
- }
2047
- let newValue = value;
2048
- // Single Checkbox: toggles the field value unless the field is being reset then force it
2049
- if (!isFieldGroup(fieldInstance) && fieldInstance.type === 'checkbox' && !force && !RESET_LOCK) {
2050
- newValue = klona(resolveNextCheckboxValue(getFromPath(formValues, field), value, unref(fieldInstance.uncheckedValue)));
2051
- }
2052
- setInPath(formValues, field, newValue);
2053
- }
2054
- /**
2055
- * Sets multiple fields values
2056
- */
2057
- function setValues(fields) {
2058
- // clean up old values
2059
- keysOf(formValues).forEach(key => {
2060
- delete formValues[key];
2061
- });
2062
- // set up new values
2063
- keysOf(fields).forEach(path => {
2064
- setFieldValue(path, fields[path]);
2065
- });
2066
- // regenerate the arrays when the form values change
2067
- Object.values(fieldArraysLookup).forEach(f => f && f.reset());
2068
- }
2069
- /**
2070
- * Sets the touched meta state on a field
2071
- */
2072
- function setFieldTouched(field, isTouched) {
2073
- const fieldInstance = fieldsByPath.value[field];
2074
- if (fieldInstance) {
2075
- applyFieldMutation(fieldInstance, f => f.setTouched(isTouched));
2076
- }
2077
- }
2078
- /**
2079
- * Sets the touched meta state on multiple fields
2080
- */
2081
- function setTouched(fields) {
2082
- keysOf(fields).forEach(field => {
2083
- setFieldTouched(field, !!fields[field]);
2084
- });
2085
- }
2086
- /**
2087
- * Resets all fields
2088
- */
2089
- function resetForm(state) {
2090
- RESET_LOCK = true;
2091
- // set initial values if provided
2092
- if (state === null || state === void 0 ? void 0 : state.values) {
2093
- setInitialValues(state.values);
2094
- setValues(state === null || state === void 0 ? void 0 : state.values);
2095
- }
2096
- else {
2097
- // clean up the initial values back to the original
2098
- setInitialValues(originalInitialValues.value);
2099
- // otherwise clean the current values
2100
- setValues(originalInitialValues.value);
2101
- }
2102
- // avoid resetting the field values, because they should've been reset already.
2103
- mutateAllFields(f => f.resetField());
2104
- if (state === null || state === void 0 ? void 0 : state.touched) {
2105
- setTouched(state.touched);
2106
- }
2107
- setErrors((state === null || state === void 0 ? void 0 : state.errors) || {});
2108
- submitCount.value = (state === null || state === void 0 ? void 0 : state.submitCount) || 0;
2109
- nextTick(() => {
2110
- RESET_LOCK = false;
2111
- });
2112
- }
2113
- function insertFieldAtPath(field, path) {
2114
- const rawField = markRaw(field);
2115
- const fieldPath = path;
2116
- // first field at that path
2117
- if (!fieldsByPath.value[fieldPath]) {
2118
- fieldsByPath.value[fieldPath] = rawField;
2119
- return;
2120
- }
2121
- const fieldAtPath = fieldsByPath.value[fieldPath];
2122
- if (fieldAtPath && !Array.isArray(fieldAtPath)) {
2123
- fieldsByPath.value[fieldPath] = [fieldAtPath];
2124
- }
2125
- // add the new array to that path
2126
- fieldsByPath.value[fieldPath] = [...fieldsByPath.value[fieldPath], rawField];
2127
- }
2128
- function removeFieldFromPath(field, path) {
2129
- const fieldPath = path;
2130
- const fieldAtPath = fieldsByPath.value[fieldPath];
2131
- if (!fieldAtPath) {
2132
- return;
2133
- }
2134
- // same field at path
2135
- if (!isFieldGroup(fieldAtPath) && field.id === fieldAtPath.id) {
2136
- delete fieldsByPath.value[fieldPath];
2137
- return;
2138
- }
2139
- if (isFieldGroup(fieldAtPath)) {
2140
- const idx = fieldAtPath.findIndex(f => f.id === field.id);
2141
- if (idx === -1) {
2142
- return;
2143
- }
2144
- fieldAtPath.splice(idx, 1);
2145
- if (fieldAtPath.length === 1) {
2146
- fieldsByPath.value[fieldPath] = fieldAtPath[0];
2147
- return;
2148
- }
2149
- if (!fieldAtPath.length) {
2150
- delete fieldsByPath.value[fieldPath];
2151
- }
2152
- }
2153
- }
2154
- function registerField(field) {
2155
- const fieldPath = unref(field.name);
2156
- insertFieldAtPath(field, fieldPath);
2157
- if (isRef(field.name)) {
2158
- // ensures when a field's name was already taken that it preserves its same value
2159
- // necessary for fields generated by loops
2160
- watch(field.name, async (newPath, oldPath) => {
2161
- // cache the value
2162
- await nextTick();
2163
- removeFieldFromPath(field, oldPath);
2164
- insertFieldAtPath(field, newPath);
2165
- // re-validate if either path had errors before
2166
- if (errors.value[oldPath] || errors.value[newPath]) {
2167
- // clear up both paths errors
2168
- setFieldError(oldPath, undefined);
2169
- validateField(newPath);
2170
- }
2171
- // clean up the old path if no other field is sharing that name
2172
- // #3325
2173
- await nextTick();
2174
- if (!fieldExists(oldPath)) {
2175
- unsetPath(formValues, oldPath);
2176
- }
2177
- });
2178
- }
2179
- // if field already had errors (initial errors) that's not user-set, validate it again to ensure state is correct
2180
- // the difference being that `initialErrors` will contain the error message while other errors (pre-validated schema) won't have them as initial errors
2181
- // #3342
2182
- const initialErrorMessage = unref(field.errorMessage);
2183
- if (initialErrorMessage && (initialErrors === null || initialErrors === void 0 ? void 0 : initialErrors[fieldPath]) !== initialErrorMessage) {
2184
- validateField(fieldPath);
2185
- }
2186
- // marks the initial error as "consumed" so it won't be matched later with same non-initial error
2187
- delete initialErrors[fieldPath];
2188
- }
2189
- function unregisterField(field) {
2190
- const fieldName = unref(field.name);
2191
- removeFieldFromPath(field, fieldName);
2192
- nextTick(() => {
2193
- // clears a field error on unmounted
2194
- // we wait till next tick to make sure if the field is completely removed and doesn't have any siblings like checkboxes
2195
- // #3384
2196
- if (!fieldExists(fieldName)) {
2197
- setFieldError(fieldName, undefined);
2198
- unsetPath(formValues, fieldName);
2199
- }
2200
- });
2201
- }
2202
- async function validate(opts) {
2203
- mutateAllFields(f => (f.meta.validated = true));
2204
- if (formCtx.validateSchema) {
2205
- return formCtx.validateSchema((opts === null || opts === void 0 ? void 0 : opts.mode) || 'force');
2206
- }
2207
- // No schema, each field is responsible to validate itself
2208
- const validations = await Promise.all(Object.values(fieldsByPath.value).map(field => {
2209
- const fieldInstance = Array.isArray(field) ? field[0] : field;
2210
- if (!fieldInstance) {
2211
- return Promise.resolve({ key: '', valid: true, errors: [] });
2212
- }
2213
- return fieldInstance.validate(opts).then((result) => {
2214
- return {
2215
- key: unref(fieldInstance.name),
2216
- valid: result.valid,
2217
- errors: result.errors,
2218
- };
2219
- });
2220
- }));
2221
- const results = {};
2222
- const errors = {};
2223
- for (const validation of validations) {
2224
- results[validation.key] = {
2225
- valid: validation.valid,
2226
- errors: validation.errors,
2227
- };
2228
- if (validation.errors.length) {
2229
- errors[validation.key] = validation.errors[0];
2230
- }
2231
- }
2232
- return {
2233
- valid: validations.every(r => r.valid),
2234
- results,
2235
- errors,
2236
- };
2237
- }
2238
- async function validateField(field) {
2239
- const fieldInstance = fieldsByPath.value[field];
2240
- if (!fieldInstance) {
2241
- warn$1(`field with name ${field} was not found`);
2242
- return Promise.resolve({ errors: [], valid: true });
2243
- }
2244
- if (Array.isArray(fieldInstance)) {
2245
- return fieldInstance.map(f => f.validate())[0];
2246
- }
2247
- return fieldInstance.validate();
2248
- }
2249
- function handleSubmit(fn, onValidationError) {
2250
- return function submissionHandler(e) {
2251
- if (e instanceof Event) {
2252
- e.preventDefault();
2253
- e.stopPropagation();
2254
- }
2255
- // Touch all fields
2256
- setTouched(keysOf(fieldsByPath.value).reduce((acc, field) => {
2257
- acc[field] = true;
2258
- return acc;
2259
- }, {}));
2260
- isSubmitting.value = true;
2261
- submitCount.value++;
2262
- return validate()
2263
- .then(result => {
2264
- if (result.valid && typeof fn === 'function') {
2265
- return fn(klona(formValues), {
2266
- evt: e,
2267
- setErrors,
2268
- setFieldError,
2269
- setTouched,
2270
- setFieldTouched,
2271
- setValues,
2272
- setFieldValue,
2273
- resetForm,
2274
- });
2275
- }
2276
- if (!result.valid && typeof onValidationError === 'function') {
2277
- onValidationError({
2278
- values: klona(formValues),
2279
- evt: e,
2280
- errors: result.errors,
2281
- results: result.results,
2282
- });
2283
- }
2284
- })
2285
- .then(returnVal => {
2286
- isSubmitting.value = false;
2287
- return returnVal;
2288
- }, err => {
2289
- isSubmitting.value = false;
2290
- // re-throw the err so it doesn't go silent
2291
- throw err;
2292
- });
2293
- };
2294
- }
2295
- function setFieldInitialValue(path, value) {
2296
- setInPath(initialValues.value, path, klona(value));
2297
- }
2298
- function unsetInitialValue(path) {
2299
- unsetPath(initialValues.value, path);
2300
- }
2301
- /**
2302
- * Sneaky function to set initial field values
2303
- */
2304
- function stageInitialValue(path, value) {
2305
- setInPath(formValues, path, value);
2306
- setFieldInitialValue(path, value);
2307
- }
2308
- async function _validateSchema() {
2309
- const schemaValue = unref(schema);
2310
- if (!schemaValue) {
2311
- return { valid: true, results: {}, errors: {} };
2312
- }
2313
- const formResult = isYupValidator(schemaValue)
2314
- ? await validateYupSchema(schemaValue, formValues)
2315
- : await validateObjectSchema(schemaValue, formValues, {
2316
- names: fieldNames.value,
2317
- bailsMap: fieldBailsMap.value,
2318
- });
2319
- return formResult;
2320
- }
2321
- /**
2322
- * Batches validation runs in 5ms batches
2323
- */
2324
- const debouncedSchemaValidation = debounceAsync(_validateSchema, 5);
2325
- async function validateSchema(mode) {
2326
- const formResult = await debouncedSchemaValidation();
2327
- // fields by id lookup
2328
- const fieldsById = formCtx.fieldsByPath.value || {};
2329
- // errors fields names, we need it to also check if custom errors are updated
2330
- const currentErrorsPaths = keysOf(formCtx.errorBag.value);
2331
- // collect all the keys from the schema and all fields
2332
- // this ensures we have a complete keymap of all the fields
2333
- const paths = [
2334
- ...new Set([...keysOf(formResult.results), ...keysOf(fieldsById), ...currentErrorsPaths]),
2335
- ];
2336
- // aggregates the paths into a single result object while applying the results on the fields
2337
- return paths.reduce((validation, path) => {
2338
- const field = fieldsById[path];
2339
- const messages = (formResult.results[path] || { errors: [] }).errors;
2340
- const fieldResult = {
2341
- errors: messages,
2342
- valid: !messages.length,
2343
- };
2344
- validation.results[path] = fieldResult;
2345
- if (!fieldResult.valid) {
2346
- validation.errors[path] = fieldResult.errors[0];
2347
- }
2348
- // field not rendered
2349
- if (!field) {
2350
- setFieldError(path, messages);
2351
- return validation;
2352
- }
2353
- // always update the valid flag regardless of the mode
2354
- applyFieldMutation(field, f => (f.meta.valid = fieldResult.valid));
2355
- if (mode === 'silent') {
2356
- return validation;
2357
- }
2358
- const wasValidated = Array.isArray(field) ? field.some(f => f.meta.validated) : field.meta.validated;
2359
- if (mode === 'validated-only' && !wasValidated) {
2360
- return validation;
2361
- }
2362
- applyFieldMutation(field, f => f.setState({ errors: fieldResult.errors }));
2363
- return validation;
2364
- }, { valid: formResult.valid, results: {}, errors: {} });
2365
- }
2366
- const submitForm = handleSubmit((_, { evt }) => {
2367
- if (isFormSubmitEvent(evt)) {
2368
- evt.target.submit();
2369
- }
2370
- });
2371
- // Trigger initial validation
2372
- onMounted(() => {
2373
- if (opts === null || opts === void 0 ? void 0 : opts.initialErrors) {
2374
- setErrors(opts.initialErrors);
2375
- }
2376
- if (opts === null || opts === void 0 ? void 0 : opts.initialTouched) {
2377
- setTouched(opts.initialTouched);
2378
- }
2379
- // if validate on mount was enabled
2380
- if (opts === null || opts === void 0 ? void 0 : opts.validateOnMount) {
2381
- validate();
2382
- return;
2383
- }
2384
- // otherwise run initial silent validation through schema if available
2385
- // the useField should skip their own silent validation if a yup schema is present
2386
- if (formCtx.validateSchema) {
2387
- formCtx.validateSchema('silent');
2388
- }
2389
- });
2390
- if (isRef(schema)) {
2391
- watch(schema, () => {
2392
- var _a;
2393
- (_a = formCtx.validateSchema) === null || _a === void 0 ? void 0 : _a.call(formCtx, 'validated-only');
2394
- });
2395
- }
2396
- // Provide injections
2397
- provide(FormContextKey, formCtx);
2398
- if (("production" !== 'production')) {
2399
- registerFormWithDevTools(formCtx);
2400
- watch(() => (Object.assign(Object.assign({ errors: errorBag.value }, meta.value), { values: formValues, isSubmitting: isSubmitting.value, submitCount: submitCount.value })), refreshInspector, {
2401
- deep: true,
2402
- });
2403
- }
2404
- return {
2405
- errors,
2406
- meta,
2407
- values: formValues,
2408
- isSubmitting,
2409
- submitCount,
2410
- validate,
2411
- validateField,
2412
- handleReset: () => resetForm(),
2413
- resetForm,
2414
- handleSubmit,
2415
- submitForm,
2416
- setFieldError,
2417
- setErrors,
2418
- setFieldValue,
2419
- setValues,
2420
- setFieldTouched,
2421
- setTouched,
2422
- };
2423
- }
2424
- /**
2425
- * Manages form meta aggregation
2426
- */
2427
- function useFormMeta(fieldsByPath, currentValues, initialValues, errors) {
2428
- const MERGE_STRATEGIES = {
2429
- touched: 'some',
2430
- pending: 'some',
2431
- valid: 'every',
2432
- };
2433
- const isDirty = computed(() => {
2434
- return !es6(currentValues, unref(initialValues));
2435
- });
2436
- function calculateFlags() {
2437
- const fields = Object.values(fieldsByPath.value).flat(1).filter(Boolean);
2438
- return keysOf(MERGE_STRATEGIES).reduce((acc, flag) => {
2439
- const mergeMethod = MERGE_STRATEGIES[flag];
2440
- acc[flag] = fields[mergeMethod](field => field.meta[flag]);
2441
- return acc;
2442
- }, {});
2443
- }
2444
- const flags = reactive(calculateFlags());
2445
- watchEffect(() => {
2446
- const value = calculateFlags();
2447
- flags.touched = value.touched;
2448
- flags.valid = value.valid;
2449
- flags.pending = value.pending;
2450
- });
2451
- return computed(() => {
2452
- return Object.assign(Object.assign({ initialValues: unref(initialValues) }, flags), { valid: flags.valid && !keysOf(errors.value).length, dirty: isDirty.value });
2453
- });
2454
- }
2455
- /**
2456
- * Manages the initial values prop
2457
- */
2458
- function useFormInitialValues(fields, formValues, providedValues) {
2459
- // these are the mutable initial values as the fields are mounted/unmounted
2460
- const initialValues = ref(klona(unref(providedValues)) || {});
2461
- // these are the original initial value as provided by the user initially, they don't keep track of conditional fields
2462
- // this is important because some conditional fields will overwrite the initial values for other fields who had the same name
2463
- // like array fields, any push/insert operation will overwrite the initial values because they "create new fields"
2464
- // so these are the values that the reset function should use
2465
- // these only change when the user explicitly chanegs the initial values or when the user resets them with new values.
2466
- const originalInitialValues = ref(klona(unref(providedValues)) || {});
2467
- function setInitialValues(values, updateFields = false) {
2468
- initialValues.value = klona(values);
2469
- originalInitialValues.value = klona(values);
2470
- if (!updateFields) {
2471
- return;
2472
- }
2473
- // update the pristine non-touched fields
2474
- // those are excluded because it's unlikely you want to change the form values using initial values
2475
- // we mostly watch them for API population or newly inserted fields
2476
- // 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
2477
- keysOf(fields.value).forEach(fieldPath => {
2478
- const field = fields.value[fieldPath];
2479
- const wasTouched = Array.isArray(field) ? field.some(f => f.meta.touched) : field === null || field === void 0 ? void 0 : field.meta.touched;
2480
- if (!field || wasTouched) {
2481
- return;
2482
- }
2483
- const newValue = getFromPath(initialValues.value, fieldPath);
2484
- setInPath(formValues, fieldPath, klona(newValue));
2485
- });
2486
- }
2487
- if (isRef(providedValues)) {
2488
- watch(providedValues, value => {
2489
- setInitialValues(value, true);
2490
- }, {
2491
- deep: true,
2492
- });
2493
- }
2494
- return {
2495
- initialValues,
2496
- originalInitialValues,
2497
- setInitialValues,
2498
- };
2499
- }
2500
- function useErrorBag(initialErrors) {
2501
- const errorBag = ref({});
2502
- function normalizeErrorItem(message) {
2503
- return Array.isArray(message) ? message : message ? [message] : [];
2504
- }
2505
- /**
2506
- * Manually sets an error message on a specific field
2507
- */
2508
- function setFieldErrorBag(field, message) {
2509
- if (!message) {
2510
- delete errorBag.value[field];
2511
- return;
2512
- }
2513
- errorBag.value[field] = normalizeErrorItem(message);
2514
- }
2515
- /**
2516
- * Sets errors for the fields specified in the object
2517
- */
2518
- function setErrorBag(fields) {
2519
- errorBag.value = keysOf(fields).reduce((acc, key) => {
2520
- const message = fields[key];
2521
- if (message) {
2522
- acc[key] = normalizeErrorItem(message);
2523
- }
2524
- return acc;
2525
- }, {});
2526
- }
2527
- if (initialErrors) {
2528
- setErrorBag(initialErrors);
2529
- }
2530
- return {
2531
- errorBag,
2532
- setErrorBag,
2533
- setFieldErrorBag,
2534
- };
2535
- }
2536
-
2537
- const FormImpl = defineComponent({
2538
- name: 'Form',
2539
- inheritAttrs: false,
2540
- props: {
2541
- as: {
2542
- type: String,
2543
- default: 'form',
2544
- },
2545
- validationSchema: {
2546
- type: Object,
2547
- default: undefined,
2548
- },
2549
- initialValues: {
2550
- type: Object,
2551
- default: undefined,
2552
- },
2553
- initialErrors: {
2554
- type: Object,
2555
- default: undefined,
2556
- },
2557
- initialTouched: {
2558
- type: Object,
2559
- default: undefined,
2560
- },
2561
- validateOnMount: {
2562
- type: Boolean,
2563
- default: false,
2564
- },
2565
- onSubmit: {
2566
- type: Function,
2567
- default: undefined,
2568
- },
2569
- onInvalidSubmit: {
2570
- type: Function,
2571
- default: undefined,
2572
- },
2573
- },
2574
- setup(props, ctx) {
2575
- const initialValues = toRef(props, 'initialValues');
2576
- const validationSchema = toRef(props, 'validationSchema');
2577
- const { errors, values, meta, isSubmitting, submitCount, validate, validateField, handleReset, resetForm, handleSubmit, submitForm, setErrors, setFieldError, setFieldValue, setValues, setFieldTouched, setTouched, } = useForm({
2578
- validationSchema: validationSchema.value ? validationSchema : undefined,
2579
- initialValues,
2580
- initialErrors: props.initialErrors,
2581
- initialTouched: props.initialTouched,
2582
- validateOnMount: props.validateOnMount,
2583
- });
2584
- const onSubmit = props.onSubmit ? handleSubmit(props.onSubmit, props.onInvalidSubmit) : submitForm;
2585
- function handleFormReset(e) {
2586
- if (isEvent(e)) {
2587
- // Prevent default form reset behavior
2588
- e.preventDefault();
2589
- }
2590
- handleReset();
2591
- if (typeof ctx.attrs.onReset === 'function') {
2592
- ctx.attrs.onReset();
2593
- }
2594
- }
2595
- function handleScopedSlotSubmit(evt, onSubmit) {
2596
- const onSuccess = typeof evt === 'function' && !onSubmit ? evt : onSubmit;
2597
- return handleSubmit(onSuccess, props.onInvalidSubmit)(evt);
2598
- }
2599
- function slotProps() {
2600
- return {
2601
- meta: meta.value,
2602
- errors: errors.value,
2603
- values: values,
2604
- isSubmitting: isSubmitting.value,
2605
- submitCount: submitCount.value,
2606
- validate,
2607
- validateField,
2608
- handleSubmit: handleScopedSlotSubmit,
2609
- handleReset,
2610
- submitForm,
2611
- setErrors,
2612
- setFieldError,
2613
- setFieldValue,
2614
- setValues,
2615
- setFieldTouched,
2616
- setTouched,
2617
- resetForm,
2618
- };
2619
- }
2620
- // expose these functions and methods as part of public API
2621
- ctx.expose({
2622
- setFieldError,
2623
- setErrors,
2624
- setFieldValue,
2625
- setValues,
2626
- setFieldTouched,
2627
- setTouched,
2628
- resetForm,
2629
- validate,
2630
- validateField,
2631
- });
2632
- return function renderForm() {
2633
- // avoid resolving the form component as itself
2634
- const tag = props.as === 'form' ? props.as : resolveDynamicComponent(props.as);
2635
- const children = normalizeChildren(tag, ctx, slotProps);
2636
- if (!props.as) {
2637
- return children;
2638
- }
2639
- // Attributes to add on a native `form` tag
2640
- const formAttrs = props.as === 'form'
2641
- ? {
2642
- // Disables native validation as vee-validate will handle it.
2643
- novalidate: true,
2644
- }
2645
- : {};
2646
- return h(tag, Object.assign(Object.assign(Object.assign({}, formAttrs), ctx.attrs), { onSubmit, onReset: handleFormReset }), children);
2647
- };
2648
- },
2649
- });
2650
- const Form = FormImpl;
2651
-
2652
- let FIELD_ARRAY_COUNTER = 0;
2653
- function useFieldArray(arrayPath) {
2654
- const id = FIELD_ARRAY_COUNTER++;
2655
- const form = injectWithSelf(FormContextKey, undefined);
2656
- const fields = ref([]);
2657
- // eslint-disable-next-line @typescript-eslint/no-empty-function
2658
- const noOp = () => { };
2659
- const noOpApi = {
2660
- fields: readonly(fields),
2661
- remove: noOp,
2662
- push: noOp,
2663
- swap: noOp,
2664
- insert: noOp,
2665
- update: noOp,
2666
- replace: noOp,
2667
- prepend: noOp,
2668
- };
2669
- if (!form) {
2670
- warn('FieldArray requires being a child of `<Form/>` or `useForm` being called before it. Array fields may not work correctly');
2671
- return noOpApi;
2672
- }
2673
- if (!unref(arrayPath)) {
2674
- warn('FieldArray requires a field path to be provided, did you forget to pass the `name` prop?');
2675
- return noOpApi;
2676
- }
2677
- let entryCounter = 0;
2678
- function initFields() {
2679
- const currentValues = getFromPath(form === null || form === void 0 ? void 0 : form.values, unref(arrayPath), []);
2680
- fields.value = currentValues.map(createEntry);
2681
- updateEntryFlags();
2682
- }
2683
- initFields();
2684
- function updateEntryFlags() {
2685
- const fieldsLength = fields.value.length;
2686
- for (let i = 0; i < fieldsLength; i++) {
2687
- const entry = fields.value[i];
2688
- entry.isFirst = i === 0;
2689
- entry.isLast = i === fieldsLength - 1;
2690
- }
2691
- }
2692
- function createEntry(value) {
2693
- const key = entryCounter++;
2694
- const entry = {
2695
- key,
2696
- value: computed(() => {
2697
- const currentValues = getFromPath(form === null || form === void 0 ? void 0 : form.values, unref(arrayPath), []);
2698
- const idx = fields.value.findIndex(e => e.key === key);
2699
- return idx === -1 ? value : currentValues[idx];
2700
- }),
2701
- isFirst: false,
2702
- isLast: false,
2703
- };
2704
- return entry;
2705
- }
2706
- function remove(idx) {
2707
- const pathName = unref(arrayPath);
2708
- const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName);
2709
- if (!pathValue || !Array.isArray(pathValue)) {
2710
- return;
2711
- }
2712
- const newValue = [...pathValue];
2713
- newValue.splice(idx, 1);
2714
- form === null || form === void 0 ? void 0 : form.unsetInitialValue(pathName + `[${idx}]`);
2715
- form === null || form === void 0 ? void 0 : form.setFieldValue(pathName, newValue);
2716
- fields.value.splice(idx, 1);
2717
- updateEntryFlags();
2718
- }
2719
- function push(value) {
2720
- const pathName = unref(arrayPath);
2721
- const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName);
2722
- const normalizedPathValue = isNullOrUndefined(pathValue) ? [] : pathValue;
2723
- if (!Array.isArray(normalizedPathValue)) {
2724
- return;
2725
- }
2726
- const newValue = [...normalizedPathValue];
2727
- newValue.push(value);
2728
- form === null || form === void 0 ? void 0 : form.stageInitialValue(pathName + `[${newValue.length - 1}]`, value);
2729
- form === null || form === void 0 ? void 0 : form.setFieldValue(pathName, newValue);
2730
- fields.value.push(createEntry(value));
2731
- updateEntryFlags();
2732
- }
2733
- function swap(indexA, indexB) {
2734
- const pathName = unref(arrayPath);
2735
- const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName);
2736
- if (!Array.isArray(pathValue) || !(indexA in pathValue) || !(indexB in pathValue)) {
2737
- return;
2738
- }
2739
- const newValue = [...pathValue];
2740
- const newFields = [...fields.value];
2741
- // the old switcheroo
2742
- const temp = newValue[indexA];
2743
- newValue[indexA] = newValue[indexB];
2744
- newValue[indexB] = temp;
2745
- const tempEntry = newFields[indexA];
2746
- newFields[indexA] = newFields[indexB];
2747
- newFields[indexB] = tempEntry;
2748
- form === null || form === void 0 ? void 0 : form.setFieldValue(pathName, newValue);
2749
- fields.value = newFields;
2750
- updateEntryFlags();
2751
- }
2752
- function insert(idx, value) {
2753
- const pathName = unref(arrayPath);
2754
- const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName);
2755
- if (!Array.isArray(pathValue) || pathValue.length < idx) {
2756
- return;
2757
- }
2758
- const newValue = [...pathValue];
2759
- const newFields = [...fields.value];
2760
- newValue.splice(idx, 0, value);
2761
- newFields.splice(idx, 0, createEntry(value));
2762
- form === null || form === void 0 ? void 0 : form.setFieldValue(pathName, newValue);
2763
- fields.value = newFields;
2764
- updateEntryFlags();
2765
- }
2766
- function replace(arr) {
2767
- const pathName = unref(arrayPath);
2768
- form === null || form === void 0 ? void 0 : form.setFieldValue(pathName, arr);
2769
- initFields();
2770
- }
2771
- function update(idx, value) {
2772
- const pathName = unref(arrayPath);
2773
- const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName);
2774
- if (!Array.isArray(pathValue) || pathValue.length - 1 < idx) {
2775
- return;
2776
- }
2777
- form === null || form === void 0 ? void 0 : form.setFieldValue(`${pathName}[${idx}]`, value);
2778
- }
2779
- function prepend(value) {
2780
- const pathName = unref(arrayPath);
2781
- const pathValue = getFromPath(form === null || form === void 0 ? void 0 : form.values, pathName);
2782
- const normalizedPathValue = isNullOrUndefined(pathValue) ? [] : pathValue;
2783
- if (!Array.isArray(normalizedPathValue)) {
2784
- return;
2785
- }
2786
- const newValue = [value, ...normalizedPathValue];
2787
- form === null || form === void 0 ? void 0 : form.stageInitialValue(pathName + `[${newValue.length - 1}]`, value);
2788
- form === null || form === void 0 ? void 0 : form.setFieldValue(pathName, newValue);
2789
- fields.value.unshift(createEntry(value));
2790
- updateEntryFlags();
2791
- }
2792
- form.fieldArraysLookup[id] = {
2793
- reset: initFields,
2794
- };
2795
- onBeforeUnmount(() => {
2796
- delete form.fieldArraysLookup[id];
2797
- });
2798
- return {
2799
- fields: readonly(fields),
2800
- remove,
2801
- push,
2802
- swap,
2803
- insert,
2804
- update,
2805
- replace,
2806
- prepend,
2807
- };
2808
- }
2809
-
2810
- const FieldArrayImpl = defineComponent({
2811
- name: 'FieldArray',
2812
- inheritAttrs: false,
2813
- props: {
2814
- name: {
2815
- type: String,
2816
- required: true,
2817
- },
2818
- },
2819
- setup(props, ctx) {
2820
- const { push, remove, swap, insert, replace, update, prepend, fields } = useFieldArray(toRef(props, 'name'));
2821
- function slotProps() {
2822
- return {
2823
- fields: fields.value,
2824
- push,
2825
- remove,
2826
- swap,
2827
- insert,
2828
- update,
2829
- replace,
2830
- prepend,
2831
- };
2832
- }
2833
- ctx.expose({
2834
- push,
2835
- remove,
2836
- swap,
2837
- insert,
2838
- update,
2839
- replace,
2840
- prepend,
2841
- });
2842
- return () => {
2843
- const children = normalizeChildren(undefined, ctx, slotProps);
2844
- return children;
2845
- };
2846
- },
2847
- });
2848
- const FieldArray = FieldArrayImpl;
2849
-
2850
- const ErrorMessageImpl = defineComponent({
2851
- name: 'ErrorMessage',
2852
- props: {
2853
- as: {
2854
- type: String,
2855
- default: undefined,
2856
- },
2857
- name: {
2858
- type: String,
2859
- required: true,
2860
- },
2861
- },
2862
- setup(props, ctx) {
2863
- const form = inject(FormContextKey, undefined);
2864
- const message = computed(() => {
2865
- return form === null || form === void 0 ? void 0 : form.errors.value[props.name];
2866
- });
2867
- function slotProps() {
2868
- return {
2869
- message: message.value,
2870
- };
2871
- }
2872
- return () => {
2873
- // Renders nothing if there are no messages
2874
- if (!message.value) {
2875
- return undefined;
2876
- }
2877
- const tag = (props.as ? resolveDynamicComponent(props.as) : props.as);
2878
- const children = normalizeChildren(tag, ctx, slotProps);
2879
- const attrs = Object.assign({ role: 'alert' }, ctx.attrs);
2880
- // If no tag was specified and there are children
2881
- // render the slot as is without wrapping it
2882
- if (!tag && (Array.isArray(children) || !children) && (children === null || children === void 0 ? void 0 : children.length)) {
2883
- return children;
2884
- }
2885
- // If no children in slot
2886
- // render whatever specified and fallback to a <span> with the message in it's contents
2887
- if ((Array.isArray(children) || !children) && !(children === null || children === void 0 ? void 0 : children.length)) {
2888
- return h(tag || 'span', attrs, message.value);
2889
- }
2890
- return h(tag, attrs, children);
2891
- };
2892
- },
2893
- });
2894
- const ErrorMessage = ErrorMessageImpl;
2895
-
2896
- function useResetForm() {
2897
- const form = injectWithSelf(FormContextKey);
2898
- if (!form) {
2899
- warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
2900
- }
2901
- return function resetForm(state) {
2902
- if (!form) {
2903
- return;
2904
- }
2905
- return form.resetForm(state);
2906
- };
2907
- }
2908
-
2909
- /**
2910
- * If a field is dirty or not
2911
- */
2912
- function useIsFieldDirty(path) {
2913
- const form = injectWithSelf(FormContextKey);
2914
- let field = path ? undefined : inject(FieldContextKey);
2915
- return computed(() => {
2916
- if (path) {
2917
- field = normalizeField(form === null || form === void 0 ? void 0 : form.fieldsByPath.value[unref(path)]);
2918
- }
2919
- if (!field) {
2920
- warn(`field with name ${unref(path)} was not found`);
2921
- return false;
2922
- }
2923
- return field.meta.dirty;
2924
- });
2925
- }
2926
-
2927
- /**
2928
- * If a field is touched or not
2929
- */
2930
- function useIsFieldTouched(path) {
2931
- const form = injectWithSelf(FormContextKey);
2932
- let field = path ? undefined : inject(FieldContextKey);
2933
- return computed(() => {
2934
- if (path) {
2935
- field = normalizeField(form === null || form === void 0 ? void 0 : form.fieldsByPath.value[unref(path)]);
2936
- }
2937
- if (!field) {
2938
- warn(`field with name ${unref(path)} was not found`);
2939
- return false;
2940
- }
2941
- return field.meta.touched;
2942
- });
2943
- }
2944
-
2945
- /**
2946
- * If a field is validated and is valid
2947
- */
2948
- function useIsFieldValid(path) {
2949
- const form = injectWithSelf(FormContextKey);
2950
- let field = path ? undefined : inject(FieldContextKey);
2951
- return computed(() => {
2952
- if (path) {
2953
- field = normalizeField(form === null || form === void 0 ? void 0 : form.fieldsByPath.value[unref(path)]);
2954
- }
2955
- if (!field) {
2956
- warn(`field with name ${unref(path)} was not found`);
2957
- return false;
2958
- }
2959
- return field.meta.valid;
2960
- });
2961
- }
2962
-
2963
- /**
2964
- * If the form is submitting or not
2965
- */
2966
- function useIsSubmitting() {
2967
- const form = injectWithSelf(FormContextKey);
2968
- if (!form) {
2969
- warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
2970
- }
2971
- return computed(() => {
2972
- var _a;
2973
- return (_a = form === null || form === void 0 ? void 0 : form.isSubmitting.value) !== null && _a !== void 0 ? _a : false;
2974
- });
2975
- }
2976
-
2977
- /**
2978
- * Validates a single field
2979
- */
2980
- function useValidateField(path) {
2981
- const form = injectWithSelf(FormContextKey);
2982
- let field = path ? undefined : inject(FieldContextKey);
2983
- return function validateField() {
2984
- if (path) {
2985
- field = normalizeField(form === null || form === void 0 ? void 0 : form.fieldsByPath.value[unref(path)]);
2986
- }
2987
- if (!field) {
2988
- warn(`field with name ${unref(path)} was not found`);
2989
- return Promise.resolve({
2990
- errors: [],
2991
- valid: true,
2992
- });
2993
- }
2994
- return field.validate();
2995
- };
2996
- }
2997
-
2998
- /**
2999
- * If the form is dirty or not
3000
- */
3001
- function useIsFormDirty() {
3002
- const form = injectWithSelf(FormContextKey);
3003
- if (!form) {
3004
- warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
3005
- }
3006
- return computed(() => {
3007
- var _a;
3008
- return (_a = form === null || form === void 0 ? void 0 : form.meta.value.dirty) !== null && _a !== void 0 ? _a : false;
3009
- });
3010
- }
3011
-
3012
- /**
3013
- * If the form is touched or not
3014
- */
3015
- function useIsFormTouched() {
3016
- const form = injectWithSelf(FormContextKey);
3017
- if (!form) {
3018
- warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
3019
- }
3020
- return computed(() => {
3021
- var _a;
3022
- return (_a = form === null || form === void 0 ? void 0 : form.meta.value.touched) !== null && _a !== void 0 ? _a : false;
3023
- });
3024
- }
3025
-
3026
- /**
3027
- * If the form has been validated and is valid
3028
- */
3029
- function useIsFormValid() {
3030
- const form = injectWithSelf(FormContextKey);
3031
- if (!form) {
3032
- warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
3033
- }
3034
- return computed(() => {
3035
- var _a;
3036
- return (_a = form === null || form === void 0 ? void 0 : form.meta.value.valid) !== null && _a !== void 0 ? _a : false;
3037
- });
3038
- }
3039
-
3040
- /**
3041
- * Validate multiple fields
3042
- */
3043
- function useValidateForm() {
3044
- const form = injectWithSelf(FormContextKey);
3045
- if (!form) {
3046
- warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
3047
- }
3048
- return function validateField() {
3049
- if (!form) {
3050
- return Promise.resolve({ results: {}, errors: {}, valid: true });
3051
- }
3052
- return form.validate();
3053
- };
3054
- }
3055
-
3056
- /**
3057
- * The number of form's submission count
3058
- */
3059
- function useSubmitCount() {
3060
- const form = injectWithSelf(FormContextKey);
3061
- if (!form) {
3062
- warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
3063
- }
3064
- return computed(() => {
3065
- var _a;
3066
- return (_a = form === null || form === void 0 ? void 0 : form.submitCount.value) !== null && _a !== void 0 ? _a : 0;
3067
- });
3068
- }
3069
-
3070
- /**
3071
- * Gives access to a field's current value
3072
- */
3073
- function useFieldValue(path) {
3074
- const form = injectWithSelf(FormContextKey);
3075
- // We don't want to use self injected context as it doesn't make sense
3076
- const field = path ? undefined : inject(FieldContextKey);
3077
- return computed(() => {
3078
- if (path) {
3079
- return getFromPath(form === null || form === void 0 ? void 0 : form.values, unref(path));
3080
- }
3081
- return unref(field === null || field === void 0 ? void 0 : field.value);
3082
- });
3083
- }
3084
-
3085
- /**
3086
- * Gives access to a form's values
3087
- */
3088
- function useFormValues() {
3089
- const form = injectWithSelf(FormContextKey);
3090
- if (!form) {
3091
- warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
3092
- }
3093
- return computed(() => {
3094
- return (form === null || form === void 0 ? void 0 : form.values) || {};
3095
- });
3096
- }
3097
-
3098
- /**
3099
- * Gives access to all form errors
3100
- */
3101
- function useFormErrors() {
3102
- const form = injectWithSelf(FormContextKey);
3103
- if (!form) {
3104
- warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
3105
- }
3106
- return computed(() => {
3107
- return ((form === null || form === void 0 ? void 0 : form.errors.value) || {});
3108
- });
3109
- }
3110
-
3111
- /**
3112
- * Gives access to a single field error
3113
- */
3114
- function useFieldError(path) {
3115
- const form = injectWithSelf(FormContextKey);
3116
- // We don't want to use self injected context as it doesn't make sense
3117
- const field = path ? undefined : inject(FieldContextKey);
3118
- return computed(() => {
3119
- if (path) {
3120
- return form === null || form === void 0 ? void 0 : form.errors.value[unref(path)];
3121
- }
3122
- return field === null || field === void 0 ? void 0 : field.errorMessage.value;
3123
- });
3124
- }
3125
-
3126
- function useSubmitForm(cb) {
3127
- const form = injectWithSelf(FormContextKey);
3128
- if (!form) {
3129
- warn('No vee-validate <Form /> or `useForm` was detected in the component tree');
3130
- }
3131
- const onSubmit = form ? form.handleSubmit(cb) : undefined;
3132
- return function submitForm(e) {
3133
- if (!onSubmit) {
3134
- return;
3135
- }
3136
- return onSubmit(e);
3137
- };
3138
- }
2
+ import { defineComponent, computed, createElementVNode, resolveComponent, openBlock, createElementBlock, createVNode, withCtx, toDisplayString, createCommentVNode, renderSlot, mergeProps, Transition } from 'vue';
3
+ import { a as Field } from './vee-validate.esm-028c6424.js';
3139
4
 
3140
5
  var script = defineComponent({
3141
6
  name: 'FwInput',
@@ -3191,6 +56,14 @@ var script = defineComponent({
3191
56
  */
3192
57
  rules: {
3193
58
  type: [String, Object, Function]
59
+ },
60
+
61
+ /**
62
+ * Converts the input into a readonly disabled field
63
+ */
64
+ readonly: {
65
+ type: Boolean,
66
+ "default": false
3194
67
  }
3195
68
  },
3196
69
  setup: function setup(props, ctx) {
@@ -3237,23 +110,26 @@ if (DESCRIPTORS && !FUNCTION_NAME_EXISTS) {
3237
110
  }
3238
111
 
3239
112
  var _hoisted_1 = {
113
+ "class": "fw-input w-full"
114
+ };
115
+ var _hoisted_2 = {
3240
116
  "class": "flex flex-col"
3241
117
  };
3242
- var _hoisted_2 = ["for"];
3243
- var _hoisted_3 = {
118
+ var _hoisted_3 = ["for"];
119
+ var _hoisted_4 = {
3244
120
  "class": "relative"
3245
121
  };
3246
- var _hoisted_4 = {
122
+ var _hoisted_5 = {
3247
123
  key: 0,
3248
124
  "class": "flex text-grey-base absolute w-9 h-full inset-y-0 left-0 items-center pl-3 pointer-events-none"
3249
125
  };
3250
- var _hoisted_5 = ["placeholder", "type"];
3251
- var _hoisted_6 = {
126
+ var _hoisted_6 = ["placeholder", "type", "readonly", "disabled"];
127
+ var _hoisted_7 = {
3252
128
  key: 0,
3253
129
  "class": "flex text-error absolute w-9 h-full inset-y-0 right-0 items-center pr-3 pointer-events-none"
3254
130
  };
3255
131
 
3256
- var _hoisted_7 = /*#__PURE__*/createElementVNode("svg", {
132
+ var _hoisted_8 = /*#__PURE__*/createElementVNode("svg", {
3257
133
  fill: "currentColor",
3258
134
  "aria-hidden": "true",
3259
135
  focusable: "false",
@@ -3261,20 +137,20 @@ var _hoisted_7 = /*#__PURE__*/createElementVNode("svg", {
3261
137
  xmlns: "http://www.w3.org/2000/svg",
3262
138
  viewBox: "0 0 512 512"
3263
139
  }, [/*#__PURE__*/createElementVNode("path", {
3264
- d: "M256 0C114.6 0 0 114.6 0 256s114.6 256 256 256s256-114.6 256-256S397.4 0 256 0zM232 152C232 138.8\n 242.8 128 256 128s24 10.75 24 24v128c0 13.25-10.75 24-24 24S232 293.3 232 280V152zM256 400c-17.36\n 0-31.44-14.08-31.44-31.44c0-17.36 14.07-31.44 31.44-31.44s31.44 14.08 31.44 31.44C287.4 385.9 273.4\n 400 256 400z"
140
+ d: "M256 0C114.6 0 0 114.6 0 256s114.6 256 256 256s256-114.6 256-256S397.4 0 256 0zM232 152C232 138.8\n 242.8 128 256 128s24 10.75 24 24v128c0 13.25-10.75 24-24 24S232 293.3 232 280V152zM256 400c-17.36\n 0-31.44-14.08-31.44-31.44c0-17.36 14.07-31.44 31.44-31.44s31.44 14.08 31.44 31.44C287.4 385.9 273.4\n 400 256 400z"
3265
141
  })], -1);
3266
142
 
3267
- var _hoisted_8 = [_hoisted_7];
3268
- var _hoisted_9 = {
3269
- "class": "text-error text-right text-sm font-medium mt-2 min-h-[21px]"
3270
- };
143
+ var _hoisted_9 = [_hoisted_8];
3271
144
  var _hoisted_10 = {
145
+ "class": "text-error italic text-right text-sm font-medium mt-2 min-h-[21px]"
146
+ };
147
+ var _hoisted_11 = {
3272
148
  key: 0
3273
149
  };
3274
150
  function render(_ctx, _cache, $props, $setup, $data, $options) {
3275
151
  var _component_InputField = resolveComponent("InputField");
3276
152
 
3277
- return openBlock(), createBlock(_component_InputField, {
153
+ return openBlock(), createElementBlock("div", _hoisted_1, [createVNode(_component_InputField, {
3278
154
  modelValue: _ctx.inputValue,
3279
155
  "onUpdate:modelValue": _cache[0] || (_cache[0] = function ($event) {
3280
156
  return _ctx.inputValue = $event;
@@ -3284,36 +160,39 @@ function render(_ctx, _cache, $props, $setup, $data, $options) {
3284
160
  }, {
3285
161
  "default": withCtx(function (_ref) {
3286
162
  var field = _ref.field,
163
+ errors = _ref.errors,
3287
164
  errorMessage = _ref.errorMessage,
3288
165
  meta = _ref.meta;
3289
- return [createElementVNode("div", _hoisted_1, [_ctx.label ? (openBlock(), createElementBlock("label", {
166
+ return [createElementVNode("div", _hoisted_2, [_ctx.label ? (openBlock(), createElementBlock("label", {
3290
167
  key: 0,
3291
168
  "for": _ctx.name,
3292
169
  "class": "block mb-2"
3293
- }, toDisplayString(_ctx.label), 9, _hoisted_2)) : createCommentVNode("", true), createElementVNode("div", _hoisted_3, [_ctx.$slots.prefixIcon ? (openBlock(), createElementBlock("div", _hoisted_4, [renderSlot(_ctx.$slots, "prefixIcon")])) : createCommentVNode("", true), createElementVNode("input", mergeProps(field, {
170
+ }, toDisplayString(_ctx.label), 9, _hoisted_3)) : createCommentVNode("", true), createElementVNode("div", _hoisted_4, [_ctx.$slots.prefixIcon ? (openBlock(), createElementBlock("div", _hoisted_5, [renderSlot(_ctx.$slots, "prefixIcon")])) : createCommentVNode("", true), createElementVNode("input", mergeProps(field, {
3294
171
  placeholder: _ctx.placeholder,
3295
172
  type: _ctx.type,
173
+ readonly: _ctx.readonly,
174
+ disabled: _ctx.readonly,
3296
175
  "class": ["border-2 border-grey-lightest rounded-lg focus:outline-none focus:ring-2 focus:ring-primary block w-full p-2.5", {
3297
176
  'pl-10': !!_ctx.$slots.prefixIcon
3298
177
  }]
3299
- }), null, 16, _hoisted_5), createVNode(Transition, {
178
+ }), null, 16, _hoisted_6), createVNode(Transition, {
3300
179
  name: "errorFadeIn"
3301
180
  }, {
3302
181
  "default": withCtx(function () {
3303
- return [errorMessage && meta.touched ? (openBlock(), createElementBlock("div", _hoisted_6, _hoisted_8)) : createCommentVNode("", true)];
182
+ return [(errorMessage || errors[0]) && meta.touched ? (openBlock(), createElementBlock("div", _hoisted_7, _hoisted_9)) : createCommentVNode("", true)];
3304
183
  }),
3305
184
  _: 2
3306
- }, 1024)]), createElementVNode("div", _hoisted_9, [createVNode(Transition, {
185
+ }, 1024)]), createElementVNode("div", _hoisted_10, [createVNode(Transition, {
3307
186
  name: "errorFadeIn"
3308
187
  }, {
3309
188
  "default": withCtx(function () {
3310
- return [errorMessage && meta.touched ? (openBlock(), createElementBlock("span", _hoisted_10, toDisplayString(errorMessage), 1)) : createCommentVNode("", true)];
189
+ return [(errorMessage || errors[0]) && meta.touched ? (openBlock(), createElementBlock("span", _hoisted_11, toDisplayString(errorMessage || errors[0]), 1)) : createCommentVNode("", true)];
3311
190
  }),
3312
191
  _: 2
3313
192
  }, 1024)])])];
3314
193
  }),
3315
194
  _: 3
3316
- }, 8, ["modelValue", "name", "rules"]);
195
+ }, 8, ["modelValue", "name", "rules"])]);
3317
196
  }
3318
197
 
3319
198
  var css_248z = ".errorFadeIn-enter-active{-webkit-animation:errorFadeIn .35s;animation:errorFadeIn .35s;-webkit-transition:opacity .35s ease-in;-o-transition:opacity .35s ease-in;transition:opacity .35s ease-in}.errorFadeIn-leave-active{animation:errorFadeIn .35s reverse;-webkit-transition:opacity .35s ease-out;-o-transition:opacity .35s ease-out;transition:opacity .35s ease-out}@-webkit-keyframes errorFadeIn{0%{opacity:0}to{opacity:1}}@keyframes errorFadeIn{0%{opacity:0}to{opacity:1}}";