@apia/validations 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,2264 +1,2 @@
1
- import { jsx, jsxs } from 'react/jsx-runtime';
2
- import { customEvents, propsStore, usePropsSelector, useUpdateEffect, useUnmount, useMount, PropsSelectorUndefinedObject, formatMessage, toBoolean } from '@apia/util';
3
- import { uniqueId } from 'lodash';
4
- import React from 'react';
5
- import { shallowEqual } from 'react-redux';
6
- import { makeStyledComponent, getVariant } from '@apia/theme';
7
- import { notify } from '@apia/notifications';
8
- import { RequiredMark, Captcha, Checkbox as Checkbox$1, IconButton, getFieldErrorStyles, DateInput, parseNumberInputValueToNumber, NumberInput } from '@apia/components';
9
- import { Box, Input as Input$1, Label, Radio as Radio$1, Select as Select$1, Switch, Textarea as Textarea$1 } from 'theme-ui';
10
-
11
- const FormContext = React.createContext(
12
- {}
13
- );
14
- function useFormContext() {
15
- const formContext = React.useContext(FormContext);
16
- if (!formContext)
17
- throw new Error("There is no FormContext");
18
- return formContext;
19
- }
20
-
21
- function validateByRules({
22
- rules,
23
- value
24
- }) {
25
- const validationResult = getValidations(rules).validate(value);
26
- return validationResult;
27
- }
28
-
29
- var __defProp$e = Object.defineProperty;
30
- var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
31
- var __hasOwnProp$f = Object.prototype.hasOwnProperty;
32
- var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
33
- var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
34
- var __spreadValues$e = (a, b) => {
35
- for (var prop in b || (b = {}))
36
- if (__hasOwnProp$f.call(b, prop))
37
- __defNormalProp$e(a, prop, b[prop]);
38
- if (__getOwnPropSymbols$f)
39
- for (var prop of __getOwnPropSymbols$f(b)) {
40
- if (__propIsEnum$f.call(b, prop))
41
- __defNormalProp$e(a, prop, b[prop]);
42
- }
43
- return a;
44
- };
45
- var __async$2 = (__this, __arguments, generator) => {
46
- return new Promise((resolve, reject) => {
47
- var fulfilled = (value) => {
48
- try {
49
- step(generator.next(value));
50
- } catch (e) {
51
- reject(e);
52
- }
53
- };
54
- var rejected = (value) => {
55
- try {
56
- step(generator.throw(value));
57
- } catch (e) {
58
- reject(e);
59
- }
60
- };
61
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
62
- step((generator = generator.apply(__this, __arguments)).next());
63
- });
64
- };
65
- function validateField(field, formName) {
66
- return __async$2(this, null, function* () {
67
- let validationResult = null;
68
- const fieldValue = field.validationValueParser ? field.validationValueParser(field.value) : field.value;
69
- if (field.validationFunction) {
70
- validationResult = yield field.validationFunction(fieldValue, formName);
71
- }
72
- if ((!field.validationFunction || validationResult === true) && field.validationRules) {
73
- validationResult = validateByRules({
74
- rules: field.validationRules,
75
- value: fieldValue
76
- });
77
- } else if (validationResult === null)
78
- validationResult = true;
79
- return validationResult;
80
- });
81
- }
82
- function hasSucceedFieldValidation(result) {
83
- return result === true;
84
- }
85
- function hasSucceedFormValidation(result) {
86
- return !("errors" in result);
87
- }
88
- function focusOnField(formName, field) {
89
- return __async$2(this, null, function* () {
90
- const formElement = document.getElementById(
91
- `ValidationForm-${formName}`
92
- );
93
- const fieldElement = formElement == null ? void 0 : formElement.querySelector(
94
- `[name="${field.name}"], #${field.name}`
95
- );
96
- if (fieldElement) {
97
- return new Promise((resolve) => {
98
- const event = new CustomEvent(customEvents.focus, { bubbles: true });
99
- fieldElement.focus();
100
- fieldElement.dispatchEvent(event);
101
- fieldElement.scrollIntoView({
102
- block: "center",
103
- behavior: "auto"
104
- });
105
- resolve(true);
106
- });
107
- }
108
- return false;
109
- });
110
- }
111
- let langDefinition;
112
- function lang(errorCode, ...replacements) {
113
- if (!langDefinition[errorCode])
114
- return "";
115
- let returnString = langDefinition[errorCode];
116
- replacements.forEach((replace, index) => {
117
- returnString = returnString.replace(`%${index}`, replace.toString());
118
- });
119
- return returnString;
120
- }
121
- function classToValidationFunction(className) {
122
- const match = className == null ? void 0 : className.match(/'confirm:(\w+):(.+?)']/);
123
- if (match) {
124
- const validationFunction = (value, formName) => {
125
- var _a, _b;
126
- return value === ((_a = validationsStore.getFieldStore(formName, match[1])) == null ? void 0 : _a.value) ? true : lang("confirm", (_b = match[2]) != null ? _b : match[1]);
127
- };
128
- return validationFunction;
129
- }
130
- return void 0;
131
- }
132
- function classToValidate(className) {
133
- const validations = {};
134
- if (className) {
135
- const match = className.match(/validate\[([^\]]+)\]/);
136
- if (match) {
137
- const definitions = match[1].replaceAll("~", "").split(",");
138
- definitions.forEach((definition) => {
139
- const definitionMatch = definition.match(/(\w+)(?:=([\w\d]+))?/);
140
- if (definitionMatch) {
141
- const prop = definitionMatch[1];
142
- if (prop === "pattern" && definitionMatch[2])
143
- validations[prop] = new RegExp(definitionMatch[2]);
144
- else if (definitionMatch[2]) {
145
- const value = definitionMatch[2].split(",");
146
- const actualValue = value.length < 2 ? value.join() : value;
147
- validations[prop] = actualValue;
148
- } else
149
- validations[prop] = true;
150
- }
151
- });
152
- return validations;
153
- }
154
- }
155
- return {};
156
- }
157
- function initValidations() {
158
- return __async$2(this, null, function* () {
159
- var _a;
160
- if (langDefinition)
161
- return;
162
- const code = (_a = document.documentElement.lang) != null ? _a : "es";
163
- langDefinition = (yield import(
164
- /* webpackChunkName: "val-lang-[request]" */
165
- `../lang/${code}.ts`
166
- ).catch((error) => {
167
- notify({
168
- type: "danger",
169
- message: window.NO_LANGUAGE_EXCEPTION
170
- });
171
- throw error;
172
- })).default;
173
- });
174
- }
175
- function getValidations(outerValidation) {
176
- const validation = __spreadValues$e({}, outerValidation);
177
- if (!validation)
178
- return {
179
- validate: () => {
180
- return true;
181
- }
182
- };
183
- return {
184
- validate: (outerV) => {
185
- var _a;
186
- const v = outerV != null ? outerV : "";
187
- let returnValue = true;
188
- if (returnValue && validation.pattern) {
189
- let actualRegexp;
190
- if (!(validation.pattern instanceof RegExp)) {
191
- const patternResult = validation.pattern.match(
192
- /(?:^\/(.+)\/(\w+)?$)|(^.*$)/
193
- );
194
- const regexp = patternResult[1];
195
- const flags = patternResult[2];
196
- const stringPattern = patternResult[3];
197
- actualRegexp = new RegExp(
198
- regexp || stringPattern,
199
- flags || void 0
200
- );
201
- } else
202
- actualRegexp = validation.pattern;
203
- returnValue = !!outerV.match(actualRegexp) || ((_a = validation.patternMessage) != null ? _a : window.MSG_INVALID_REG_EXP);
204
- }
205
- if (returnValue === true && validation.maxLength)
206
- returnValue = v.length <= validation.maxLength || lang("lengthmax", validation.maxLength);
207
- if (returnValue === true && validation.minLength)
208
- returnValue = v.length >= validation.minLength || lang("lengthmin", validation.minLength);
209
- if (returnValue === true && validation.max && validation.min)
210
- returnValue = Number(v) <= validation.max && Number(v) >= validation.min || lang("digitltd", validation.min, validation.max);
211
- if (returnValue === true && validation.min)
212
- returnValue = Number(v) >= validation.min || lang("digitmin", validation.min);
213
- if (returnValue === true && validation.max)
214
- returnValue = Number(v) <= validation.max || lang("digitltd", 0, validation.max);
215
- if (returnValue === true && validation.validName)
216
- returnValue = !!v.match(/^[a-zA-Z0-9_.]*$/) || window.GNR_INVALID_NAME;
217
- if (returnValue === true && (validation.alpha || validation.nodigit))
218
- returnValue = !!v.match(/^[a-zA-Z]*$/) || lang("alpha");
219
- if (returnValue === true && validation.alphanum)
220
- returnValue = !!v.match(/^[a-zA-Z0-9]*$/) || lang("alphanum");
221
- if (returnValue === true && (validation.digit || validation.number))
222
- returnValue = !!v.match(/^[0-9]*$/) || lang("digit");
223
- if (returnValue === true && validation.email)
224
- returnValue = !!v.match(
225
- // eslint-disable-next-line no-control-regex
226
- /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/
227
- ) || lang("email");
228
- if (returnValue === true && validation.differs)
229
- returnValue = v !== validation.differs || lang("differs", validation.differs);
230
- if (returnValue === true && validation.length_str)
231
- returnValue = v.length >= validation.length_str[0] && v.length <= validation.length_str[1] || lang("length_str", ...validation.length_str);
232
- if (returnValue === true && validation.length_fix)
233
- returnValue = v.length === validation.length_fix || lang("length_fix", validation.length_fix);
234
- if (returnValue === true && validation.words_min) {
235
- const words = v.split(" ").length;
236
- return words >= validation.words_min || lang("words_min", validation.words_min);
237
- }
238
- if (returnValue === true && validation.words_max) {
239
- const words = v.split(" ").length;
240
- return words <= validation.words_max || lang("words_max", validation.words_max);
241
- }
242
- if (returnValue === true && validation.words_range) {
243
- const words = v.split(" ").length;
244
- return words <= validation.words_range[0] && words >= validation.words_range[1] || lang("words_range", ...validation.words_range);
245
- }
246
- if (returnValue === true && validation.required)
247
- returnValue = Array.isArray(outerV) && outerV.length > 0 || typeof outerV === "number" || !Array.isArray(v) && !!v || lang("required");
248
- return returnValue;
249
- }
250
- };
251
- }
252
-
253
- var __defProp$d = Object.defineProperty;
254
- var __defProps$b = Object.defineProperties;
255
- var __getOwnPropDescs$b = Object.getOwnPropertyDescriptors;
256
- var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
257
- var __hasOwnProp$e = Object.prototype.hasOwnProperty;
258
- var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
259
- var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
260
- var __spreadValues$d = (a, b) => {
261
- for (var prop in b || (b = {}))
262
- if (__hasOwnProp$e.call(b, prop))
263
- __defNormalProp$d(a, prop, b[prop]);
264
- if (__getOwnPropSymbols$e)
265
- for (var prop of __getOwnPropSymbols$e(b)) {
266
- if (__propIsEnum$e.call(b, prop))
267
- __defNormalProp$d(a, prop, b[prop]);
268
- }
269
- return a;
270
- };
271
- var __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
272
- var __objRest$c = (source, exclude) => {
273
- var target = {};
274
- for (var prop in source)
275
- if (__hasOwnProp$e.call(source, prop) && exclude.indexOf(prop) < 0)
276
- target[prop] = source[prop];
277
- if (source != null && __getOwnPropSymbols$e)
278
- for (var prop of __getOwnPropSymbols$e(source)) {
279
- if (exclude.indexOf(prop) < 0 && __propIsEnum$e.call(source, prop))
280
- target[prop] = source[prop];
281
- }
282
- return target;
283
- };
284
- var __async$1 = (__this, __arguments, generator) => {
285
- return new Promise((resolve, reject) => {
286
- var fulfilled = (value) => {
287
- try {
288
- step(generator.next(value));
289
- } catch (e) {
290
- reject(e);
291
- }
292
- };
293
- var rejected = (value) => {
294
- try {
295
- step(generator.throw(value));
296
- } catch (e) {
297
- reject(e);
298
- }
299
- };
300
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
301
- step((generator = generator.apply(__this, __arguments)).next());
302
- });
303
- };
304
- const validationsStore = new class {
305
- constructor() {
306
- this.activeForms = [];
307
- this.timeouts = {};
308
- this.existsField = (formName, fieldName) => {
309
- var _a, _b;
310
- return !!((_b = (_a = this.getFormStore(formName)) == null ? void 0 : _a.fields) == null ? void 0 : _b.includes(fieldName));
311
- };
312
- this.registerField = (formName, registerData, options = { registerIfExists: true }) => {
313
- var _a, _b, _c;
314
- const formProps = this.getFormStore(formName);
315
- if (formProps === void 0)
316
- this.registerForm(formName);
317
- if (!((_a = this.getFormStore(formName)) == null ? void 0 : _a.fields.includes(registerData.name)))
318
- this.updateFormStore(formName, {
319
- fields: [
320
- ...(_c = (_b = this.getFormStore(formName)) == null ? void 0 : _b.fields) != null ? _c : [],
321
- registerData.name
322
- ]
323
- });
324
- const existsInStore = this.getFieldStore(formName, registerData.name);
325
- if (((formProps == null ? void 0 : formProps.avoidFieldsOverride) || !options.registerIfExists) && existsInStore) {
326
- const _d = registerData, updateData = __objRest$c(_d, ["value"]);
327
- this.updateField(formName, updateData, {
328
- markFormAsTouched: false,
329
- avoidPropagation: options.avoidPropagation
330
- });
331
- return;
332
- }
333
- this.updateFieldStore(
334
- formName,
335
- registerData.name,
336
- registerData,
337
- options.avoidPropagation
338
- );
339
- };
340
- /**
341
- * Inicializa el estado de un nuevo formulario
342
- */
343
- this.registerForm = (formName, props = { avoidFieldsOverride: false }) => {
344
- var _a;
345
- if (this.activeForms.includes(formName)) {
346
- this.updateFormStore(formName, {
347
- avoidFieldsOverride: props.avoidFieldsOverride
348
- });
349
- if (props.initialValues)
350
- Object.entries(props.initialValues).forEach(([fieldId, fieldProps]) => {
351
- if (fieldProps instanceof Object)
352
- this.updateField(formName, __spreadValues$d({ name: fieldId }, fieldProps));
353
- });
354
- return;
355
- }
356
- this.activeForms.push(formName);
357
- this.updateFormStore(formName, {
358
- avoidFieldsOverride: props.avoidFieldsOverride,
359
- fields: [],
360
- isTouched: false,
361
- isValid: false,
362
- name: formName,
363
- validationResult: null
364
- });
365
- Object.entries((_a = props.initialValues) != null ? _a : {}).forEach(([name, value]) => {
366
- this.updateField(formName, { name, value }, { markFormAsTouched: false });
367
- });
368
- };
369
- /**
370
- * Setea el valor del campo con el nombre provisto. Si el campo no existe
371
- * en el formulario lo crea.
372
- */
373
- this.setFieldValue = (formName, fieldName, newValue, options) => {
374
- if (!this.getFieldStore(formName, fieldName))
375
- this.registerField(formName, { name: fieldName, value: newValue });
376
- else
377
- this.updateField(
378
- formName,
379
- {
380
- name: fieldName,
381
- value: newValue,
382
- error: null
383
- },
384
- options
385
- );
386
- if (this.getFormStore(formName).isValid)
387
- this.updateFormStore(formName, { isValid: false });
388
- };
389
- this.setFormIsTouched = (formName, isTouched = true) => {
390
- this.updateFormStore(formName, { isTouched });
391
- };
392
- /**
393
- * Elimina un campo del registro de validación de un formulario. De esta
394
- * forma cualquier validación que pudiera aplicarse sobre el mismo, ya no se
395
- * aplicará.
396
- */
397
- this.unregisterField = (formName, fieldName) => {
398
- if (this.getFormStore(formName))
399
- this.updateFormStore(formName, {
400
- fields: this.getFormStore(formName).fields.filter((current) => {
401
- return current !== fieldName;
402
- })
403
- });
404
- propsStore.removeField(this.makeFieldName(formName, fieldName));
405
- };
406
- /**
407
- * Elimina un formulario del store de validación junto con todos los campos
408
- * asociados al mismo.
409
- */
410
- this.unregisterForm = (formName) => {
411
- var _a, _b;
412
- (_b = (_a = this.getFormStore(formName)) == null ? void 0 : _a.fields) == null ? void 0 : _b.forEach((current) => {
413
- return propsStore.removeField(this.makeFieldName(formName, current));
414
- });
415
- this.activeForms = this.activeForms.filter((current) => {
416
- return current !== formName;
417
- });
418
- propsStore.removeField(this.makeFormName(formName));
419
- delete this.timeouts[formName];
420
- };
421
- /**
422
- * Actualiza las propiedades de un campo, si no existe, lo registra en el
423
- * formulario.
424
- */
425
- this.updateField = (formName, field, options) => {
426
- var _a, _b;
427
- const previousValue = (_a = this.getFieldStore(formName, field.name)) == null ? void 0 : _a.value;
428
- if (this.getFormStore(formName))
429
- this.updateFormStore(formName, { isValid: false });
430
- else
431
- this.registerForm(formName);
432
- const isTouched = field.value !== void 0 && field.value !== previousValue && (options == null ? void 0 : options.markFormAsTouched) !== false;
433
- if (!this.existsField(formName, field.name))
434
- this.registerField(formName, field, {
435
- avoidPropagation: options == null ? void 0 : options.avoidPropagation
436
- });
437
- this.updateFieldStore(
438
- formName,
439
- field.name,
440
- __spreadProps$b(__spreadValues$d({}, field), {
441
- isTouched: isTouched || ((_b = this.getFieldStore(formName, field.name)) == null ? void 0 : _b.isTouched)
442
- }),
443
- options == null ? void 0 : options.avoidPropagation
444
- );
445
- if (isTouched)
446
- this.setFormIsTouched(formName);
447
- };
448
- /**
449
- * Actualiza múltiples campos al mismo tiempo.
450
- */
451
- this.updateMultipleFields = (formName, fields, options) => {
452
- fields.forEach((current) => {
453
- return this.updateField(formName, current, options);
454
- });
455
- };
456
- /**
457
- * Ejecuta la validación sobre un formulario. En caso de que la validación
458
- * falle, se intenta hacer foco sobre el campo que no pudo validar.
459
- * Es importante notar que en caso de que un campo requiera validación,
460
- * debería estar presente en el DOM.
461
- *
462
- * No es necesario que el campo esté visible, ya que en caso de estar oculto
463
- * (por ejemplo por ser hijo de un acordeón), se emitirá un evento para
464
- * expandir al elemento padre que lo estuviera ocultando.
465
- *
466
- * @returns Devuelve una promesa que al ser resuelta otorga un objeto de tipo
467
- * TValidationResult. Este tipo está pensado para ser usado en conjunto con
468
- * el método hasSucceedFormValidation, que determinará si la validación fue
469
- * exitosa o hubo errores.
470
- *
471
- * @example
472
- *
473
- * const result = await validationStore.validateForm('myForm');
474
- * if(hasSucceedValidation(result)) {
475
- * console.log('Success!', result);
476
- * } else {
477
- * console.error('Validation error', result);
478
- * }
479
- */
480
- this.validateForm = (formName) => __async$1(this, null, function* () {
481
- var _a;
482
- const state = this.getFormStore(formName);
483
- const fields = state.fields.map((current) => {
484
- return this.getFieldStore(formName, current);
485
- });
486
- const validationErrors = { errors: {} };
487
- const validationValues = {
488
- submitValues: {},
489
- values: {}
490
- };
491
- let hasFiredFocus = false;
492
- let existsErrors = false;
493
- const fieldsWithError = {};
494
- for (const field of fields.filter((current) => {
495
- return current !== void 0;
496
- })) {
497
- const validationResult = yield validateField(field, formName);
498
- fieldsWithError[field.name] = validationResult;
499
- if (hasSucceedFieldValidation(validationResult)) {
500
- validationValues.submitValues[(_a = field.submitName) != null ? _a : field.name] = field.submitValueParser ? field.submitValueParser(field.value) : field.value;
501
- validationValues.values[field.name] = field.value;
502
- } else {
503
- this.updateField(formName, {
504
- name: field.name,
505
- error: validationResult
506
- });
507
- if (!hasFiredFocus) {
508
- if (yield focusOnField(formName, field))
509
- hasFiredFocus = true;
510
- }
511
- existsErrors = true;
512
- validationErrors.errors[field.name] = validationResult;
513
- }
514
- }
515
- if (existsErrors) {
516
- if (!hasFiredFocus) {
517
- notify({
518
- message: window.MSG_WRONG_VALIDATION_NO_FOCUSED_FILE,
519
- type: "danger"
520
- });
521
- console.error("Campos que fallaron la validaci\xF3n", fieldsWithError);
522
- }
523
- this.updateFormStore(formName, {
524
- isValid: false,
525
- validationResult: validationErrors
526
- });
527
- return validationErrors;
528
- }
529
- this.updateFormStore(formName, {
530
- isValid: true,
531
- validationResult: validationValues
532
- });
533
- return validationValues;
534
- });
535
- }
536
- getFieldStore(formName, fieldName) {
537
- return propsStore.getFieldProps(
538
- this.makeFieldName(formName, fieldName)
539
- );
540
- }
541
- getFormStore(formName) {
542
- return propsStore.getFieldProps(this.makeFormName(formName));
543
- }
544
- updateFieldStore(formName, fieldName, props, noEmit) {
545
- propsStore.updateField(
546
- this.makeFieldName(formName, fieldName),
547
- __spreadValues$d(__spreadValues$d({}, this.getFieldStore(formName, fieldName)), props),
548
- { noEmit }
549
- );
550
- }
551
- updateFormStore(formName, newState) {
552
- propsStore.updateField(this.makeFormName(formName), newState);
553
- }
554
- enableFormTouch(formName) {
555
- this.timeouts[formName] = true;
556
- }
557
- makeFieldName(formName, fieldName) {
558
- return `validation_${formName}_${fieldName}`;
559
- }
560
- makeFormName(formName) {
561
- return `validation_${formName}`;
562
- }
563
- }();
564
- function useFormSelector(formName, selector, comparator) {
565
- return usePropsSelector(
566
- validationsStore.makeFormName(formName),
567
- selector,
568
- comparator
569
- );
570
- }
571
- function useFieldSelector(formName, fieldName, confOrSelector, comparator) {
572
- const fieldId = validationsStore.makeFieldName(formName, fieldName);
573
- return usePropsSelector(fieldId, confOrSelector, comparator);
574
- }
575
-
576
- const formStyles = {
577
- ".fieldWrapper": {
578
- display: "flex",
579
- flexDirection: "column",
580
- alignItems: "stretch",
581
- "&.checkbox": {
582
- alignItems: "center"
583
- }
584
- },
585
- ".error": {
586
- borderLeftStyle: "solid",
587
- borderLeftWidth: "4px",
588
- borderLeftColor: "danger"
589
- },
590
- ".touched": {
591
- borderStyle: "solid",
592
- borderWidth: "1px",
593
- borderColor: "orange"
594
- }
595
- };
596
-
597
- var __async = (__this, __arguments, generator) => {
598
- return new Promise((resolve, reject) => {
599
- var fulfilled = (value) => {
600
- try {
601
- step(generator.next(value));
602
- } catch (e) {
603
- reject(e);
604
- }
605
- };
606
- var rejected = (value) => {
607
- try {
608
- step(generator.throw(value));
609
- } catch (e) {
610
- reject(e);
611
- }
612
- };
613
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
614
- step((generator = generator.apply(__this, __arguments)).next());
615
- });
616
- };
617
- const UnstyledForm = ({
618
- avoidFieldsOverride,
619
- avoidFieldsTouch,
620
- children,
621
- className,
622
- name,
623
- initialValues,
624
- onUnmount,
625
- onValidate,
626
- unregisterOnUnmount
627
- }) => {
628
- const actualName = React.useMemo(
629
- () => name != null ? name : `ValidationForm${uniqueId()}`,
630
- // eslint-disable-next-line react-hooks/exhaustive-deps
631
- []
632
- );
633
- const validationResult = useFormSelector(
634
- actualName,
635
- (props) => props.validationResult,
636
- shallowEqual
637
- );
638
- useUpdateEffect(() => {
639
- if (validationResult && onValidate)
640
- onValidate(validationResult);
641
- }, [validationResult]);
642
- const handleSubmit = React.useCallback(
643
- (ev) => {
644
- ev.preventDefault();
645
- void validationsStore.validateForm(actualName);
646
- },
647
- [actualName]
648
- );
649
- const contextValue = React.useMemo(
650
- () => ({
651
- avoidFieldsTouch,
652
- name: actualName,
653
- validate: () => __async(void 0, null, function* () {
654
- return validationsStore.validateForm(actualName);
655
- })
656
- }),
657
- [actualName, avoidFieldsTouch]
658
- );
659
- useUnmount(() => {
660
- onUnmount == null ? void 0 : onUnmount();
661
- if (unregisterOnUnmount !== false)
662
- validationsStore.unregisterForm(actualName);
663
- });
664
- const [hasRegistered, setHasRegistered] = React.useState(false);
665
- useMount(() => {
666
- validationsStore.registerForm(actualName, {
667
- avoidFieldsOverride: avoidFieldsOverride != null ? avoidFieldsOverride : initialValues !== void 0,
668
- initialValues
669
- });
670
- setHasRegistered(true);
671
- });
672
- if (!hasRegistered)
673
- return null;
674
- return /* @__PURE__ */ jsx(FormContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
675
- "form",
676
- {
677
- className,
678
- id: `ValidationForm-${actualName}`,
679
- name: actualName,
680
- onSubmit: handleSubmit,
681
- children
682
- }
683
- ) });
684
- };
685
- const Form = makeStyledComponent(
686
- "Form",
687
- "layout.common.validations.form",
688
- formStyles,
689
- UnstyledForm
690
- );
691
-
692
- var __defProp$c = Object.defineProperty;
693
- var __getOwnPropSymbols$d = Object.getOwnPropertySymbols;
694
- var __hasOwnProp$d = Object.prototype.hasOwnProperty;
695
- var __propIsEnum$d = Object.prototype.propertyIsEnumerable;
696
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
697
- var __spreadValues$c = (a, b) => {
698
- for (var prop in b || (b = {}))
699
- if (__hasOwnProp$d.call(b, prop))
700
- __defNormalProp$c(a, prop, b[prop]);
701
- if (__getOwnPropSymbols$d)
702
- for (var prop of __getOwnPropSymbols$d(b)) {
703
- if (__propIsEnum$d.call(b, prop))
704
- __defNormalProp$c(a, prop, b[prop]);
705
- }
706
- return a;
707
- };
708
- function useField(fieldDefinition) {
709
- var _a;
710
- const formContext = React.useContext(FormContext);
711
- const formName = (_a = fieldDefinition.formName) != null ? _a : formContext.name;
712
- if (!formName) {
713
- console.error(fieldDefinition);
714
- throw new Error(
715
- `useField: It was not possible to determine the formName in field with name ${fieldDefinition.name}`
716
- );
717
- }
718
- React.useMemo(() => {
719
- validationsStore.registerField(
720
- formName,
721
- __spreadValues$c(__spreadValues$c({}, fieldDefinition), fieldDefinition.initialValue !== void 0 ? { value: fieldDefinition.initialValue } : null),
722
- {
723
- avoidPropagation: true,
724
- registerIfExists: !fieldDefinition.avoidRegisterIfExists
725
- }
726
- );
727
- }, []);
728
- useMount(() => {
729
- var _a2;
730
- if (fieldDefinition.initialValue !== void 0 && (!((_a2 = validationsStore.getFormStore(formName)) == null ? void 0 : _a2.avoidFieldsOverride) && !fieldDefinition.avoidRegisterIfExists || validationsStore.getFieldStore(formName, fieldDefinition.name) === void 0))
731
- validationsStore.setFieldValue(
732
- formName,
733
- fieldDefinition.name,
734
- fieldDefinition.initialValue
735
- );
736
- });
737
- useUnmount(() => {
738
- if (fieldDefinition.removeOnUnmount)
739
- validationsStore.unregisterField(formName, fieldDefinition.name);
740
- });
741
- const {
742
- name,
743
- value: storeValue,
744
- error,
745
- isTouched
746
- } = useFieldSelector(
747
- formName,
748
- fieldDefinition.name,
749
- (props) => {
750
- return props;
751
- },
752
- (a, b) => {
753
- if (a === PropsSelectorUndefinedObject && fieldDefinition.initialValue !== void 0)
754
- return true;
755
- return shallowEqual(a, b);
756
- }
757
- );
758
- const [localValue, setLocalValue] = React.useState(
759
- fieldDefinition.initialValue
760
- );
761
- React.useEffect(() => {
762
- setLocalValue(storeValue);
763
- }, [storeValue]);
764
- const onChange = React.useCallback(
765
- (ev) => {
766
- const reactChangeEvent = ev;
767
- let newValue;
768
- if (typeof reactChangeEvent === "object" && reactChangeEvent && reactChangeEvent.target !== void 0 && reactChangeEvent.target.value !== void 0) {
769
- newValue = reactChangeEvent.target.value;
770
- } else
771
- newValue = ev;
772
- setLocalValue(newValue);
773
- validationsStore.setFieldValue(formName, fieldDefinition.name, newValue);
774
- },
775
- [fieldDefinition.name, formName]
776
- );
777
- return {
778
- error,
779
- isTouched,
780
- name,
781
- onChange,
782
- updateValidations: React.useCallback(
783
- ({
784
- validationFunction,
785
- validationRules
786
- }) => {
787
- validationsStore.updateField(formName, {
788
- name: fieldDefinition.name,
789
- validationFunction,
790
- validationRules
791
- });
792
- },
793
- [formName, fieldDefinition.name]
794
- ),
795
- value: localValue != null ? localValue : fieldDefinition.initialValue
796
- };
797
- }
798
-
799
- function useFieldStatesClassNames(name, formName) {
800
- const { error, isTouched } = useField({
801
- name,
802
- formName,
803
- avoidRegisterIfExists: true,
804
- removeOnUnmount: false
805
- });
806
- const { avoidFieldsTouch } = useFormContext();
807
- if (error)
808
- return "error";
809
- if (!avoidFieldsTouch && isTouched)
810
- return "touched";
811
- return "";
812
- }
813
-
814
- function useFieldValue({ formName, name }) {
815
- const { name: hookFormName } = useFormContext();
816
- if (!formName && !hookFormName) {
817
- throw new Error(
818
- `useFieldValue: It was not possible to determine the formName in field with name ${name}`
819
- );
820
- }
821
- const { value } = useFieldSelector(
822
- formName != null ? formName : hookFormName,
823
- name,
824
- (props) => {
825
- return props;
826
- },
827
- (a, b) => {
828
- if (a === PropsSelectorUndefinedObject && (b == null ? void 0 : b.value) === void 0)
829
- return true;
830
- return shallowEqual(a == null ? void 0 : a.value, b == null ? void 0 : b.value);
831
- }
832
- );
833
- return value;
834
- }
835
-
836
- var __defProp$b = Object.defineProperty;
837
- var __getOwnPropSymbols$c = Object.getOwnPropertySymbols;
838
- var __hasOwnProp$c = Object.prototype.hasOwnProperty;
839
- var __propIsEnum$c = Object.prototype.propertyIsEnumerable;
840
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
841
- var __spreadValues$b = (a, b) => {
842
- for (var prop in b || (b = {}))
843
- if (__hasOwnProp$c.call(b, prop))
844
- __defNormalProp$b(a, prop, b[prop]);
845
- if (__getOwnPropSymbols$c)
846
- for (var prop of __getOwnPropSymbols$c(b)) {
847
- if (__propIsEnum$c.call(b, prop))
848
- __defNormalProp$b(a, prop, b[prop]);
849
- }
850
- return a;
851
- };
852
- function useValidationClass({
853
- customValidation,
854
- validationClass,
855
- validationFunction,
856
- validationRules
857
- }) {
858
- const classesValidationFunction = React.useMemo(
859
- () => validationClass !== void 0 ? classToValidationFunction(validationClass) : void 0,
860
- [validationClass]
861
- );
862
- const actualValidationFunction = React.useCallback(
863
- (currentValue, parameterFormName) => {
864
- var _a;
865
- let result = (_a = validationFunction == null ? void 0 : validationFunction(currentValue, parameterFormName)) != null ? _a : true;
866
- if (typeof result === "string")
867
- return result;
868
- if (customValidation) {
869
- result = customValidation(currentValue, parameterFormName);
870
- }
871
- if (typeof result === "string")
872
- return result;
873
- if (classesValidationFunction)
874
- return classesValidationFunction(currentValue, parameterFormName);
875
- return true;
876
- },
877
- [classesValidationFunction, customValidation, validationFunction]
878
- );
879
- const actualValidationRules = React.useMemo(() => {
880
- return __spreadValues$b(__spreadValues$b({}, validationRules), validationClass !== void 0 ? classToValidate(validationClass) : {});
881
- }, [validationClass, validationRules]);
882
- return {
883
- actualValidationFunction,
884
- actualValidationRules
885
- };
886
- }
887
-
888
- const ValidationError = ({ name }) => {
889
- const formContext = useFormContext();
890
- const error = useFieldSelector(formContext.name, name, (state) => {
891
- return state == null ? void 0 : state.error;
892
- });
893
- return error ? /* @__PURE__ */ jsx(
894
- Box,
895
- {
896
- as: "strong",
897
- role: "alert",
898
- sx: {
899
- color: "danger"
900
- },
901
- dangerouslySetInnerHTML: { __html: error }
902
- }
903
- ) : null;
904
- };
905
-
906
- var __defProp$a = Object.defineProperty;
907
- var __defProps$a = Object.defineProperties;
908
- var __getOwnPropDescs$a = Object.getOwnPropertyDescriptors;
909
- var __getOwnPropSymbols$b = Object.getOwnPropertySymbols;
910
- var __hasOwnProp$b = Object.prototype.hasOwnProperty;
911
- var __propIsEnum$b = Object.prototype.propertyIsEnumerable;
912
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
913
- var __spreadValues$a = (a, b) => {
914
- for (var prop in b || (b = {}))
915
- if (__hasOwnProp$b.call(b, prop))
916
- __defNormalProp$a(a, prop, b[prop]);
917
- if (__getOwnPropSymbols$b)
918
- for (var prop of __getOwnPropSymbols$b(b)) {
919
- if (__propIsEnum$b.call(b, prop))
920
- __defNormalProp$a(a, prop, b[prop]);
921
- }
922
- return a;
923
- };
924
- var __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
925
- var __objRest$b = (source, exclude) => {
926
- var target = {};
927
- for (var prop in source)
928
- if (__hasOwnProp$b.call(source, prop) && exclude.indexOf(prop) < 0)
929
- target[prop] = source[prop];
930
- if (source != null && __getOwnPropSymbols$b)
931
- for (var prop of __getOwnPropSymbols$b(source)) {
932
- if (exclude.indexOf(prop) < 0 && __propIsEnum$b.call(source, prop))
933
- target[prop] = source[prop];
934
- }
935
- return target;
936
- };
937
- const FieldWrapper = (_a) => {
938
- var _b = _a, {
939
- name,
940
- label,
941
- avoidSemicolon,
942
- children,
943
- className,
944
- as = "label",
945
- type
946
- } = _b, props = __objRest$b(_b, [
947
- "name",
948
- "label",
949
- "avoidSemicolon",
950
- "children",
951
- "className",
952
- "as",
953
- "type"
954
- ]);
955
- const { name: formName } = useFormContext();
956
- const isRequired = useFieldSelector(
957
- formName,
958
- name,
959
- (global) => {
960
- var _a2;
961
- return (_a2 = global == null ? void 0 : global.validationRules) == null ? void 0 : _a2.required;
962
- }
963
- );
964
- if (type === "checkbox") {
965
- return /* @__PURE__ */ jsxs(
966
- Box,
967
- __spreadProps$a(__spreadValues$a({
968
- className: `fieldWrapper checkboxWrapper ${className != null ? className : ""}`
969
- }, props), {
970
- as,
971
- children: [
972
- window.SHOW_REQUIRED_POSITION !== "0" && label && /* @__PURE__ */ jsx(RequiredMark, { isRequired }),
973
- children,
974
- /* @__PURE__ */ jsxs("span", { children: [
975
- label,
976
- window.SHOW_REQUIRED_POSITION === "0" && label && /* @__PURE__ */ jsx(RequiredMark, { isRequired })
977
- ] }),
978
- /* @__PURE__ */ jsx(ValidationError, { name })
979
- ]
980
- })
981
- );
982
- }
983
- return /* @__PURE__ */ jsxs(Box, __spreadProps$a(__spreadValues$a({ className: `fieldWrapper ${className != null ? className : ""}` }, props), { as, children: [
984
- /* @__PURE__ */ jsxs(Box, { as: "span", children: [
985
- window.SHOW_REQUIRED_POSITION !== "0" && label && /* @__PURE__ */ jsx(RequiredMark, { isRequired }),
986
- label,
987
- !avoidSemicolon && label && /* @__PURE__ */ jsx("abbr", { className: "semicolon", children: ": " }),
988
- window.SHOW_REQUIRED_POSITION === "0" && label && /* @__PURE__ */ jsx(RequiredMark, { isRequired })
989
- ] }),
990
- children,
991
- /* @__PURE__ */ jsx(ValidationError, { name })
992
- ] }));
993
- };
994
-
995
- var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
996
- var __hasOwnProp$a = Object.prototype.hasOwnProperty;
997
- var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
998
- var __objRest$a = (source, exclude) => {
999
- var target = {};
1000
- for (var prop in source)
1001
- if (__hasOwnProp$a.call(source, prop) && exclude.indexOf(prop) < 0)
1002
- target[prop] = source[prop];
1003
- if (source != null && __getOwnPropSymbols$a)
1004
- for (var prop of __getOwnPropSymbols$a(source)) {
1005
- if (exclude.indexOf(prop) < 0 && __propIsEnum$a.call(source, prop))
1006
- target[prop] = source[prop];
1007
- }
1008
- return target;
1009
- };
1010
- const InnerCaptcha = ({
1011
- className,
1012
- name,
1013
- imageUrl,
1014
- /**
1015
- * useField
1016
- */
1017
- avoidRegisterIfExists,
1018
- avoidSemicolon,
1019
- formName,
1020
- label,
1021
- removeOnUnmount,
1022
- submitName,
1023
- submitValueParser,
1024
- validationValueParser
1025
- }) => {
1026
- const _a = useField({
1027
- name,
1028
- avoidRegisterIfExists,
1029
- formName,
1030
- initialValue: "",
1031
- removeOnUnmount,
1032
- submitName,
1033
- submitValueParser,
1034
- validationValueParser,
1035
- validationRules: { required: true }
1036
- }), { error, updateValidations, onChange, isTouched } = _a, validationProps = __objRest$a(_a, ["error", "updateValidations", "onChange", "isTouched"]);
1037
- const handleOnChange = React.useCallback(
1038
- (ev) => {
1039
- onChange(ev);
1040
- },
1041
- [onChange]
1042
- );
1043
- const stateClassName = useFieldStatesClassNames(name);
1044
- return /* @__PURE__ */ jsx(
1045
- FieldWrapper,
1046
- {
1047
- name,
1048
- label,
1049
- className: `input ${className != null ? className : ""}`,
1050
- avoidSemicolon,
1051
- children: /* @__PURE__ */ jsx(
1052
- Captcha,
1053
- {
1054
- name,
1055
- imageUrl,
1056
- onChange: handleOnChange,
1057
- value: validationProps.value,
1058
- className: stateClassName
1059
- }
1060
- )
1061
- }
1062
- );
1063
- };
1064
-
1065
- var __defProp$9 = Object.defineProperty;
1066
- var __defProps$9 = Object.defineProperties;
1067
- var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
1068
- var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
1069
- var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
1070
- var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
1071
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1072
- var __spreadValues$9 = (a, b) => {
1073
- for (var prop in b || (b = {}))
1074
- if (__hasOwnProp$9.call(b, prop))
1075
- __defNormalProp$9(a, prop, b[prop]);
1076
- if (__getOwnPropSymbols$9)
1077
- for (var prop of __getOwnPropSymbols$9(b)) {
1078
- if (__propIsEnum$9.call(b, prop))
1079
- __defNormalProp$9(a, prop, b[prop]);
1080
- }
1081
- return a;
1082
- };
1083
- var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
1084
- var __objRest$9 = (source, exclude) => {
1085
- var target = {};
1086
- for (var prop in source)
1087
- if (__hasOwnProp$9.call(source, prop) && exclude.indexOf(prop) < 0)
1088
- target[prop] = source[prop];
1089
- if (source != null && __getOwnPropSymbols$9)
1090
- for (var prop of __getOwnPropSymbols$9(source)) {
1091
- if (exclude.indexOf(prop) < 0 && __propIsEnum$9.call(source, prop))
1092
- target[prop] = source[prop];
1093
- }
1094
- return target;
1095
- };
1096
- const Checkbox = React.forwardRef(
1097
- (_a, ref) => {
1098
- var _b = _a, {
1099
- avoidSemicolon,
1100
- className,
1101
- label,
1102
- native,
1103
- onChange: outerOnChange,
1104
- type,
1105
- avoidRegisterIfExists: avoidRegisterIfExists,
1106
- formName,
1107
- initialValue,
1108
- name,
1109
- removeOnUnmount,
1110
- submitValueParser,
1111
- validationClass,
1112
- validationFunction,
1113
- validationRules,
1114
- value
1115
- } = _b, props = __objRest$9(_b, [
1116
- "avoidSemicolon",
1117
- "className",
1118
- "label",
1119
- "native",
1120
- "onChange",
1121
- "type",
1122
- /**
1123
- * useField
1124
- */
1125
- "avoidRegisterIfExists",
1126
- "formName",
1127
- "initialValue",
1128
- "name",
1129
- "removeOnUnmount",
1130
- "submitValueParser",
1131
- "validationClass",
1132
- "validationFunction",
1133
- "validationRules",
1134
- "value"
1135
- ]);
1136
- var _a2, _c;
1137
- const { actualValidationFunction, actualValidationRules } = useValidationClass({
1138
- validationClass,
1139
- validationFunction,
1140
- validationRules
1141
- });
1142
- const _b2 = useField({
1143
- avoidRegisterIfExists,
1144
- formName,
1145
- name,
1146
- initialValue: (_a2 = initialValue === true || initialValue === "on") != null ? _a2 : false,
1147
- removeOnUnmount,
1148
- submitValueParser,
1149
- validationFunction: actualValidationFunction,
1150
- validationRules: actualValidationRules
1151
- }), {
1152
- value: innerValue,
1153
- onChange,
1154
- updateValidations,
1155
- isTouched
1156
- } = _b2, inputProps = __objRest$9(_b2, [
1157
- "value",
1158
- "onChange",
1159
- "updateValidations",
1160
- "isTouched"
1161
- ]);
1162
- return /* @__PURE__ */ jsx(
1163
- FieldWrapper,
1164
- {
1165
- name,
1166
- label,
1167
- className: `checkbox ${className != null ? className : ""}`,
1168
- avoidSemicolon,
1169
- children: /* @__PURE__ */ jsx(
1170
- Checkbox$1,
1171
- __spreadProps$9(__spreadValues$9(__spreadValues$9({}, props), inputProps), {
1172
- native,
1173
- "aria-label": (_c = props["aria-label"]) != null ? _c : label,
1174
- onChange: (ev) => {
1175
- onChange(ev.target.checked);
1176
- if (outerOnChange)
1177
- outerOnChange(ev);
1178
- },
1179
- checked: innerValue === true || innerValue === "on",
1180
- ref
1181
- })
1182
- )
1183
- }
1184
- );
1185
- }
1186
- );
1187
- Checkbox.displayName = "Checkbox";
1188
-
1189
- var __defProp$8 = Object.defineProperty;
1190
- var __defProps$8 = Object.defineProperties;
1191
- var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
1192
- var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
1193
- var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
1194
- var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
1195
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1196
- var __spreadValues$8 = (a, b) => {
1197
- for (var prop in b || (b = {}))
1198
- if (__hasOwnProp$8.call(b, prop))
1199
- __defNormalProp$8(a, prop, b[prop]);
1200
- if (__getOwnPropSymbols$8)
1201
- for (var prop of __getOwnPropSymbols$8(b)) {
1202
- if (__propIsEnum$8.call(b, prop))
1203
- __defNormalProp$8(a, prop, b[prop]);
1204
- }
1205
- return a;
1206
- };
1207
- var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
1208
- var __objRest$8 = (source, exclude) => {
1209
- var target = {};
1210
- for (var prop in source)
1211
- if (__hasOwnProp$8.call(source, prop) && exclude.indexOf(prop) < 0)
1212
- target[prop] = source[prop];
1213
- if (source != null && __getOwnPropSymbols$8)
1214
- for (var prop of __getOwnPropSymbols$8(source)) {
1215
- if (exclude.indexOf(prop) < 0 && __propIsEnum$8.call(source, prop))
1216
- target[prop] = source[prop];
1217
- }
1218
- return target;
1219
- };
1220
- const DeletableInput = React.forwardRef(
1221
- (_a, ref) => {
1222
- var _b = _a, {
1223
- avoidSemicolon,
1224
- className,
1225
- label,
1226
- onChange: outerOnChange,
1227
- type,
1228
- avoidRegisterIfExists: avoidRegisterIfExists,
1229
- formName: propsFormName,
1230
- initialValue,
1231
- name,
1232
- removeOnUnmount,
1233
- submitValueParser,
1234
- validationClass,
1235
- validationFunction,
1236
- validationRules,
1237
- value
1238
- } = _b, props = __objRest$8(_b, [
1239
- "avoidSemicolon",
1240
- "className",
1241
- "label",
1242
- "onChange",
1243
- "type",
1244
- /**
1245
- * useField
1246
- */
1247
- "avoidRegisterIfExists",
1248
- "formName",
1249
- "initialValue",
1250
- "name",
1251
- "removeOnUnmount",
1252
- "submitValueParser",
1253
- "validationClass",
1254
- "validationFunction",
1255
- "validationRules",
1256
- "value"
1257
- ]);
1258
- var _a2, _b2, _c, _e, _f;
1259
- const { name: contextFormName } = React.useContext(FormContext);
1260
- const formName = propsFormName != null ? propsFormName : contextFormName;
1261
- const { actualValidationFunction, actualValidationRules } = useValidationClass({
1262
- validationClass,
1263
- validationFunction,
1264
- validationRules
1265
- });
1266
- const _d = useField({
1267
- formName,
1268
- name,
1269
- initialValue: (_c = (_b2 = initialValue != null ? initialValue : value) != null ? _b2 : (_a2 = validationsStore.getFieldStore(formName, name)) == null ? void 0 : _a2.value) != null ? _c : "",
1270
- removeOnUnmount,
1271
- submitValueParser,
1272
- validationFunction: actualValidationFunction,
1273
- validationRules: actualValidationRules
1274
- }), {
1275
- error,
1276
- updateValidations,
1277
- onChange,
1278
- isTouched
1279
- } = _d, validationProps = __objRest$8(_d, [
1280
- "error",
1281
- "updateValidations",
1282
- "onChange",
1283
- "isTouched"
1284
- ]);
1285
- const handleOnChange = React.useCallback(
1286
- (ev) => {
1287
- onChange(ev);
1288
- outerOnChange == null ? void 0 : outerOnChange(ev);
1289
- },
1290
- [onChange, outerOnChange]
1291
- );
1292
- const stateClassName = useFieldStatesClassNames(name);
1293
- return /* @__PURE__ */ jsxs(
1294
- FieldWrapper,
1295
- {
1296
- name,
1297
- label,
1298
- sx: React.useCallback(
1299
- () => ({
1300
- display: "flex",
1301
- flexDirection: "column",
1302
- alignItems: "start"
1303
- }),
1304
- []
1305
- ),
1306
- className: `deletableInput ${className != null ? className : ""}`,
1307
- avoidSemicolon,
1308
- children: [
1309
- /* @__PURE__ */ jsx(
1310
- Input$1,
1311
- __spreadProps$8(__spreadValues$8(__spreadValues$8({
1312
- type
1313
- }, props), validationProps), {
1314
- "aria-label": (_e = props["aria-label"]) != null ? _e : label,
1315
- ref,
1316
- onChange: handleOnChange,
1317
- value: (_f = validationProps.value) != null ? _f : "",
1318
- className: `deletableInput__input ${stateClassName != null ? stateClassName : ""}`
1319
- })
1320
- ),
1321
- /* @__PURE__ */ jsx(
1322
- IconButton,
1323
- {
1324
- icon: "Close",
1325
- className: "deletableInput__deleteButton",
1326
- onClick: () => onChange("")
1327
- }
1328
- )
1329
- ]
1330
- }
1331
- );
1332
- }
1333
- );
1334
- DeletableInput.displayName = "DeletableInput";
1335
-
1336
- var __defProp$7 = Object.defineProperty;
1337
- var __defProps$7 = Object.defineProperties;
1338
- var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
1339
- var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
1340
- var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
1341
- var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
1342
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1343
- var __spreadValues$7 = (a, b) => {
1344
- for (var prop in b || (b = {}))
1345
- if (__hasOwnProp$7.call(b, prop))
1346
- __defNormalProp$7(a, prop, b[prop]);
1347
- if (__getOwnPropSymbols$7)
1348
- for (var prop of __getOwnPropSymbols$7(b)) {
1349
- if (__propIsEnum$7.call(b, prop))
1350
- __defNormalProp$7(a, prop, b[prop]);
1351
- }
1352
- return a;
1353
- };
1354
- var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
1355
- var __objRest$7 = (source, exclude) => {
1356
- var target = {};
1357
- for (var prop in source)
1358
- if (__hasOwnProp$7.call(source, prop) && exclude.indexOf(prop) < 0)
1359
- target[prop] = source[prop];
1360
- if (source != null && __getOwnPropSymbols$7)
1361
- for (var prop of __getOwnPropSymbols$7(source)) {
1362
- if (exclude.indexOf(prop) < 0 && __propIsEnum$7.call(source, prop))
1363
- target[prop] = source[prop];
1364
- }
1365
- return target;
1366
- };
1367
- const FieldLabel = (_a) => {
1368
- var _b = _a, {
1369
- avoidSemicolon,
1370
- children,
1371
- required
1372
- } = _b, props = __objRest$7(_b, [
1373
- "avoidSemicolon",
1374
- "children",
1375
- "required"
1376
- ]);
1377
- return /* @__PURE__ */ jsxs(Label, __spreadProps$7(__spreadValues$7({}, props), { children: [
1378
- window.SHOW_REQUIRED_POSITION !== "0" && /* @__PURE__ */ jsx(RequiredMark, { isRequired: required }),
1379
- children,
1380
- !avoidSemicolon && ": ",
1381
- window.SHOW_REQUIRED_POSITION === "0" && /* @__PURE__ */ jsx(RequiredMark, { isRequired: required })
1382
- ] }));
1383
- };
1384
-
1385
- var __defProp$6 = Object.defineProperty;
1386
- var __defProps$6 = Object.defineProperties;
1387
- var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
1388
- var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
1389
- var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
1390
- var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
1391
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1392
- var __spreadValues$6 = (a, b) => {
1393
- for (var prop in b || (b = {}))
1394
- if (__hasOwnProp$6.call(b, prop))
1395
- __defNormalProp$6(a, prop, b[prop]);
1396
- if (__getOwnPropSymbols$6)
1397
- for (var prop of __getOwnPropSymbols$6(b)) {
1398
- if (__propIsEnum$6.call(b, prop))
1399
- __defNormalProp$6(a, prop, b[prop]);
1400
- }
1401
- return a;
1402
- };
1403
- var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
1404
- var __objRest$6 = (source, exclude) => {
1405
- var target = {};
1406
- for (var prop in source)
1407
- if (__hasOwnProp$6.call(source, prop) && exclude.indexOf(prop) < 0)
1408
- target[prop] = source[prop];
1409
- if (source != null && __getOwnPropSymbols$6)
1410
- for (var prop of __getOwnPropSymbols$6(source)) {
1411
- if (exclude.indexOf(prop) < 0 && __propIsEnum$6.call(source, prop))
1412
- target[prop] = source[prop];
1413
- }
1414
- return target;
1415
- };
1416
- const FileInput = React.memo(
1417
- React.forwardRef(
1418
- (_a, ref) => {
1419
- var _b = _a, {
1420
- avoidSemicolon,
1421
- className,
1422
- label,
1423
- avoidRegisterIfExists: avoidRegisterIfExists,
1424
- formName: propsFormName,
1425
- initialValue,
1426
- name,
1427
- removeOnUnmount,
1428
- submitValueParser,
1429
- validationClass,
1430
- validationFunction,
1431
- validationRules
1432
- } = _b, props = __objRest$6(_b, [
1433
- "avoidSemicolon",
1434
- "className",
1435
- "label",
1436
- /**
1437
- * useField
1438
- */
1439
- "avoidRegisterIfExists",
1440
- "formName",
1441
- "initialValue",
1442
- "name",
1443
- "removeOnUnmount",
1444
- "submitValueParser",
1445
- "validationClass",
1446
- "validationFunction",
1447
- "validationRules"
1448
- ]);
1449
- var _b2;
1450
- const { name: formName } = useFormContext();
1451
- const { actualValidationFunction, actualValidationRules } = useValidationClass({
1452
- customValidation(fileValue) {
1453
- return fileValue !== null && fileValue !== void 0 ? true : lang("required");
1454
- },
1455
- validationClass,
1456
- validationFunction,
1457
- validationRules
1458
- });
1459
- const _a2 = useField({
1460
- formName,
1461
- name,
1462
- removeOnUnmount,
1463
- submitValueParser,
1464
- validationFunction: actualValidationFunction,
1465
- validationRules: actualValidationRules
1466
- }), {
1467
- error,
1468
- onChange,
1469
- value,
1470
- updateValidations,
1471
- isTouched
1472
- } = _a2, validationProps = __objRest$6(_a2, [
1473
- "error",
1474
- "onChange",
1475
- "value",
1476
- "updateValidations",
1477
- "isTouched"
1478
- ]);
1479
- return /* @__PURE__ */ jsx(
1480
- FieldWrapper,
1481
- {
1482
- name,
1483
- label,
1484
- className: `input ${className != null ? className : ""}`,
1485
- avoidSemicolon,
1486
- children: /* @__PURE__ */ jsx(
1487
- Input$1,
1488
- __spreadProps$6(__spreadValues$6(__spreadValues$6({}, props), validationProps), {
1489
- type: "file",
1490
- "aria-label": (_b2 = props["aria-label"]) != null ? _b2 : label,
1491
- ref,
1492
- sx: getFieldErrorStyles(!error),
1493
- onChange: React.useCallback(
1494
- (ev) => {
1495
- var _a3, _b3, _c;
1496
- onChange((_c = (_b3 = (_a3 = ev.target) == null ? void 0 : _a3.files) == null ? void 0 : _b3[0]) != null ? _c : null);
1497
- },
1498
- [onChange]
1499
- )
1500
- })
1501
- )
1502
- }
1503
- );
1504
- }
1505
- )
1506
- );
1507
- FileInput.displayName = "FileInput";
1508
-
1509
- var __defProp$5 = Object.defineProperty;
1510
- var __defProps$5 = Object.defineProperties;
1511
- var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
1512
- var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
1513
- var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
1514
- var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
1515
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1516
- var __spreadValues$5 = (a, b) => {
1517
- for (var prop in b || (b = {}))
1518
- if (__hasOwnProp$5.call(b, prop))
1519
- __defNormalProp$5(a, prop, b[prop]);
1520
- if (__getOwnPropSymbols$5)
1521
- for (var prop of __getOwnPropSymbols$5(b)) {
1522
- if (__propIsEnum$5.call(b, prop))
1523
- __defNormalProp$5(a, prop, b[prop]);
1524
- }
1525
- return a;
1526
- };
1527
- var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
1528
- var __objRest$5 = (source, exclude) => {
1529
- var target = {};
1530
- for (var prop in source)
1531
- if (__hasOwnProp$5.call(source, prop) && exclude.indexOf(prop) < 0)
1532
- target[prop] = source[prop];
1533
- if (source != null && __getOwnPropSymbols$5)
1534
- for (var prop of __getOwnPropSymbols$5(source)) {
1535
- if (exclude.indexOf(prop) < 0 && __propIsEnum$5.call(source, prop))
1536
- target[prop] = source[prop];
1537
- }
1538
- return target;
1539
- };
1540
- const Input = React.memo(
1541
- React.forwardRef(
1542
- (_a, ref) => {
1543
- var _b = _a, {
1544
- avoidSemicolon,
1545
- className,
1546
- label,
1547
- onChange: outerOnChange,
1548
- type,
1549
- avoidRegisterIfExists: avoidRegisterIfExists,
1550
- formName: propsFormName,
1551
- initialValue,
1552
- name,
1553
- removeOnUnmount,
1554
- submitValueParser,
1555
- validationClass,
1556
- validationFunction,
1557
- validationRules,
1558
- value
1559
- } = _b, props = __objRest$5(_b, [
1560
- "avoidSemicolon",
1561
- "className",
1562
- "label",
1563
- "onChange",
1564
- "type",
1565
- /**
1566
- * useField
1567
- */
1568
- "avoidRegisterIfExists",
1569
- "formName",
1570
- "initialValue",
1571
- "name",
1572
- "removeOnUnmount",
1573
- "submitValueParser",
1574
- "validationClass",
1575
- "validationFunction",
1576
- "validationRules",
1577
- "value"
1578
- ]);
1579
- var _a2, _b2, _c, _e, _f, _g, _h;
1580
- const { name: contextFormName } = React.useContext(FormContext);
1581
- const formName = propsFormName != null ? propsFormName : contextFormName;
1582
- const { actualValidationFunction, actualValidationRules } = useValidationClass({
1583
- validationClass,
1584
- validationFunction,
1585
- validationRules
1586
- });
1587
- const _d = useField({
1588
- formName,
1589
- name,
1590
- initialValue: (_c = (_b2 = initialValue != null ? initialValue : value) != null ? _b2 : (_a2 = validationsStore.getFieldStore(formName, name)) == null ? void 0 : _a2.value) != null ? _c : "",
1591
- removeOnUnmount,
1592
- submitValueParser,
1593
- validationFunction: actualValidationFunction,
1594
- validationRules: actualValidationRules
1595
- }), {
1596
- error,
1597
- updateValidations,
1598
- onChange,
1599
- isTouched
1600
- } = _d, validationProps = __objRest$5(_d, [
1601
- "error",
1602
- "updateValidations",
1603
- "onChange",
1604
- "isTouched"
1605
- ]);
1606
- const handleOnChange = React.useCallback(
1607
- (ev) => {
1608
- onChange(ev);
1609
- if (typeof ev === "string") {
1610
- outerOnChange == null ? void 0 : outerOnChange({
1611
- target: ref
1612
- });
1613
- } else {
1614
- outerOnChange == null ? void 0 : outerOnChange(ev);
1615
- }
1616
- },
1617
- [onChange, outerOnChange, ref]
1618
- );
1619
- const stateClassName = useFieldStatesClassNames(name);
1620
- return /* @__PURE__ */ jsx(
1621
- FieldWrapper,
1622
- {
1623
- name,
1624
- label,
1625
- className: `input ${className != null ? className : ""}`,
1626
- avoidSemicolon,
1627
- children: type === "date" ? /* @__PURE__ */ jsx(
1628
- DateInput,
1629
- __spreadProps$5(__spreadValues$5(__spreadValues$5({}, props), validationProps), {
1630
- "aria-label": (_e = props["aria-label"]) != null ? _e : label,
1631
- onError: void 0,
1632
- ref,
1633
- onChange: handleOnChange,
1634
- value: (_f = validationProps.value) != null ? _f : "",
1635
- className: stateClassName
1636
- })
1637
- ) : /* @__PURE__ */ jsx(
1638
- Input$1,
1639
- __spreadProps$5(__spreadValues$5(__spreadValues$5({
1640
- type
1641
- }, props), validationProps), {
1642
- "aria-label": (_g = props["aria-label"]) != null ? _g : label,
1643
- ref,
1644
- onChange: handleOnChange,
1645
- value: (_h = validationProps.value) != null ? _h : "",
1646
- className: stateClassName
1647
- })
1648
- )
1649
- }
1650
- );
1651
- }
1652
- )
1653
- );
1654
- Input.displayName = "Input";
1655
-
1656
- var __defProp$4 = Object.defineProperty;
1657
- var __defProps$4 = Object.defineProperties;
1658
- var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
1659
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
1660
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
1661
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
1662
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1663
- var __spreadValues$4 = (a, b) => {
1664
- for (var prop in b || (b = {}))
1665
- if (__hasOwnProp$4.call(b, prop))
1666
- __defNormalProp$4(a, prop, b[prop]);
1667
- if (__getOwnPropSymbols$4)
1668
- for (var prop of __getOwnPropSymbols$4(b)) {
1669
- if (__propIsEnum$4.call(b, prop))
1670
- __defNormalProp$4(a, prop, b[prop]);
1671
- }
1672
- return a;
1673
- };
1674
- var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
1675
- var __objRest$4 = (source, exclude) => {
1676
- var target = {};
1677
- for (var prop in source)
1678
- if (__hasOwnProp$4.call(source, prop) && exclude.indexOf(prop) < 0)
1679
- target[prop] = source[prop];
1680
- if (source != null && __getOwnPropSymbols$4)
1681
- for (var prop of __getOwnPropSymbols$4(source)) {
1682
- if (exclude.indexOf(prop) < 0 && __propIsEnum$4.call(source, prop))
1683
- target[prop] = source[prop];
1684
- }
1685
- return target;
1686
- };
1687
- const NumberInputf = React.memo(
1688
- React.forwardRef(
1689
- (_a, ref) => {
1690
- var _b = _a, {
1691
- avoidSemicolon,
1692
- className,
1693
- label,
1694
- onChange: outerOnChange,
1695
- avoidRegisterIfExists: avoidRegisterIfExists,
1696
- formName: propsFormName,
1697
- initialValue,
1698
- name,
1699
- removeOnUnmount,
1700
- submitValueParser,
1701
- validationClass,
1702
- validationFunction,
1703
- validationRules,
1704
- value
1705
- } = _b, props = __objRest$4(_b, [
1706
- "avoidSemicolon",
1707
- "className",
1708
- "label",
1709
- "onChange",
1710
- /**
1711
- * useField
1712
- */
1713
- "avoidRegisterIfExists",
1714
- "formName",
1715
- "initialValue",
1716
- "name",
1717
- "removeOnUnmount",
1718
- "submitValueParser",
1719
- "validationClass",
1720
- "validationFunction",
1721
- "validationRules",
1722
- "value"
1723
- ]);
1724
- var _a2, _b2, _c;
1725
- const { name: contextFormName } = React.useContext(FormContext);
1726
- const formName = propsFormName != null ? propsFormName : contextFormName;
1727
- const { actualValidationFunction, actualValidationRules } = useValidationClass({
1728
- validationClass,
1729
- validationFunction,
1730
- validationRules
1731
- });
1732
- const { onChange, value: innerValue } = useField({
1733
- formName,
1734
- name,
1735
- initialValue: (_c = (_b2 = initialValue != null ? initialValue : value) != null ? _b2 : (_a2 = validationsStore.getFieldStore(formName, name)) == null ? void 0 : _a2.value) != null ? _c : "",
1736
- removeOnUnmount,
1737
- submitValueParser: React.useCallback(
1738
- (current) => parseNumberInputValueToNumber(current != null ? current : ""),
1739
- []
1740
- ),
1741
- validationValueParser: React.useCallback(
1742
- (current) => parseNumberInputValueToNumber(current != null ? current : ""),
1743
- []
1744
- ),
1745
- validationFunction: actualValidationFunction,
1746
- validationRules: actualValidationRules
1747
- });
1748
- const handleOnChange = React.useCallback(
1749
- (ev) => {
1750
- if (ev.error) {
1751
- outerOnChange == null ? void 0 : outerOnChange(__spreadProps$4(__spreadValues$4({}, ev), { value: "" }));
1752
- onChange("");
1753
- validationsStore.updateField(formName, {
1754
- name,
1755
- error: formatMessage(window.GNR_NUMERIC, { TOK: "" })
1756
- });
1757
- } else {
1758
- onChange(ev.value);
1759
- outerOnChange == null ? void 0 : outerOnChange(ev);
1760
- validationsStore.updateField(formName, { name, error: null });
1761
- }
1762
- },
1763
- [formName, name, onChange, outerOnChange]
1764
- );
1765
- const stateClassName = useFieldStatesClassNames(name);
1766
- return /* @__PURE__ */ jsx(
1767
- FieldWrapper,
1768
- {
1769
- name,
1770
- label,
1771
- sx: React.useMemo(
1772
- () => ({
1773
- display: "flex",
1774
- flexDirection: "column",
1775
- alignItems: "start"
1776
- }),
1777
- []
1778
- ),
1779
- className: `input ${className != null ? className : ""}`,
1780
- avoidSemicolon,
1781
- children: /* @__PURE__ */ jsx(
1782
- NumberInput,
1783
- __spreadProps$4(__spreadValues$4({
1784
- ref
1785
- }, props), {
1786
- name,
1787
- value: innerValue,
1788
- onChange: handleOnChange,
1789
- className: stateClassName
1790
- })
1791
- )
1792
- }
1793
- );
1794
- }
1795
- )
1796
- );
1797
- NumberInputf.displayName = "NumberInputf";
1798
-
1799
- var __defProp$3 = Object.defineProperty;
1800
- var __defProps$3 = Object.defineProperties;
1801
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
1802
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
1803
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
1804
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
1805
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1806
- var __spreadValues$3 = (a, b) => {
1807
- for (var prop in b || (b = {}))
1808
- if (__hasOwnProp$3.call(b, prop))
1809
- __defNormalProp$3(a, prop, b[prop]);
1810
- if (__getOwnPropSymbols$3)
1811
- for (var prop of __getOwnPropSymbols$3(b)) {
1812
- if (__propIsEnum$3.call(b, prop))
1813
- __defNormalProp$3(a, prop, b[prop]);
1814
- }
1815
- return a;
1816
- };
1817
- var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
1818
- var __objRest$3 = (source, exclude) => {
1819
- var target = {};
1820
- for (var prop in source)
1821
- if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
1822
- target[prop] = source[prop];
1823
- if (source != null && __getOwnPropSymbols$3)
1824
- for (var prop of __getOwnPropSymbols$3(source)) {
1825
- if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
1826
- target[prop] = source[prop];
1827
- }
1828
- return target;
1829
- };
1830
- const Radio = React.forwardRef(
1831
- (_a, ref) => {
1832
- var _b = _a, {
1833
- avoidSemicolon,
1834
- className,
1835
- formName,
1836
- label,
1837
- onChange: outerOnChange,
1838
- options,
1839
- value: outerValue,
1840
- avoidRegisterIfExists: avoidRegisterIfExists,
1841
- initialValue,
1842
- name,
1843
- removeOnUnmount,
1844
- submitValueParser,
1845
- validationClass,
1846
- validationFunction,
1847
- validationRules
1848
- } = _b, props = __objRest$3(_b, [
1849
- "avoidSemicolon",
1850
- "className",
1851
- "formName",
1852
- "label",
1853
- "onChange",
1854
- "options",
1855
- "value",
1856
- /**
1857
- * useField
1858
- */
1859
- "avoidRegisterIfExists",
1860
- "initialValue",
1861
- "name",
1862
- "removeOnUnmount",
1863
- "submitValueParser",
1864
- "validationClass",
1865
- "validationFunction",
1866
- "validationRules"
1867
- ]);
1868
- const { actualValidationFunction, actualValidationRules } = useValidationClass({
1869
- validationClass,
1870
- validationFunction,
1871
- validationRules
1872
- });
1873
- const _a2 = useField({
1874
- formName,
1875
- name,
1876
- initialValue: initialValue != null ? initialValue : outerValue,
1877
- removeOnUnmount,
1878
- submitValueParser,
1879
- validationFunction: actualValidationFunction,
1880
- validationRules: actualValidationRules
1881
- }), { value, updateValidations, onChange, isTouched } = _a2, inputProps = __objRest$3(_a2, ["value", "updateValidations", "onChange", "isTouched"]);
1882
- const handleOnChange = React.useCallback(
1883
- (ev) => {
1884
- onChange(ev);
1885
- if (outerOnChange) {
1886
- outerOnChange(ev);
1887
- }
1888
- },
1889
- [onChange, outerOnChange]
1890
- );
1891
- return /* @__PURE__ */ jsx(
1892
- FieldWrapper,
1893
- {
1894
- name,
1895
- label,
1896
- className: `radio ${className != null ? className : ""}`,
1897
- avoidSemicolon,
1898
- as: "ul",
1899
- children: options == null ? void 0 : options.map((option) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(Label, { title: option.label, className: "radio-label", children: [
1900
- /* @__PURE__ */ jsx(
1901
- Radio$1,
1902
- __spreadProps$3(__spreadValues$3(__spreadValues$3({}, props), inputProps), {
1903
- role: "radio",
1904
- className: "radio-button",
1905
- "aria-label": option.label,
1906
- ref,
1907
- value: option.value,
1908
- checked: value === option.value,
1909
- onChange: handleOnChange
1910
- })
1911
- ),
1912
- /* @__PURE__ */ jsx(Box, { as: "span", className: "radio-text", children: option.label })
1913
- ] }) }, option.value))
1914
- }
1915
- );
1916
- }
1917
- );
1918
- Radio.displayName = "Radio";
1919
-
1920
- var __defProp$2 = Object.defineProperty;
1921
- var __defProps$2 = Object.defineProperties;
1922
- var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
1923
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
1924
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
1925
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
1926
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1927
- var __spreadValues$2 = (a, b) => {
1928
- for (var prop in b || (b = {}))
1929
- if (__hasOwnProp$2.call(b, prop))
1930
- __defNormalProp$2(a, prop, b[prop]);
1931
- if (__getOwnPropSymbols$2)
1932
- for (var prop of __getOwnPropSymbols$2(b)) {
1933
- if (__propIsEnum$2.call(b, prop))
1934
- __defNormalProp$2(a, prop, b[prop]);
1935
- }
1936
- return a;
1937
- };
1938
- var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
1939
- var __objRest$2 = (source, exclude) => {
1940
- var target = {};
1941
- for (var prop in source)
1942
- if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
1943
- target[prop] = source[prop];
1944
- if (source != null && __getOwnPropSymbols$2)
1945
- for (var prop of __getOwnPropSymbols$2(source)) {
1946
- if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
1947
- target[prop] = source[prop];
1948
- }
1949
- return target;
1950
- };
1951
- const Select = React.forwardRef(
1952
- (_a, ref) => {
1953
- var _b = _a, {
1954
- avoidSemicolon,
1955
- className,
1956
- formName,
1957
- label,
1958
- onChange: outerOnChange,
1959
- options,
1960
- avoidRegisterIfExists: avoidRegisterIfExists,
1961
- initialValue,
1962
- name,
1963
- removeOnUnmount,
1964
- submitValueParser,
1965
- validationClass,
1966
- validationFunction,
1967
- validationRules,
1968
- value
1969
- } = _b, props = __objRest$2(_b, [
1970
- "avoidSemicolon",
1971
- "className",
1972
- "formName",
1973
- "label",
1974
- "onChange",
1975
- "options",
1976
- /**
1977
- * useField
1978
- */
1979
- "avoidRegisterIfExists",
1980
- "initialValue",
1981
- "name",
1982
- "removeOnUnmount",
1983
- "submitValueParser",
1984
- "validationClass",
1985
- "validationFunction",
1986
- "validationRules",
1987
- "value"
1988
- ]);
1989
- var _a2, _b2, _d, _e;
1990
- const { actualValidationFunction, actualValidationRules } = useValidationClass({
1991
- validationClass,
1992
- validationFunction,
1993
- validationRules
1994
- });
1995
- const _c = useField({
1996
- avoidRegisterIfExists,
1997
- initialValue: (_b2 = initialValue != null ? initialValue : value) != null ? _b2 : (_a2 = options[0]) == null ? void 0 : _a2.value,
1998
- name,
1999
- removeOnUnmount,
2000
- submitValueParser,
2001
- validationFunction: actualValidationFunction,
2002
- validationRules: actualValidationRules
2003
- }), { updateValidations, onChange, isTouched } = _c, inputProps = __objRest$2(_c, ["updateValidations", "onChange", "isTouched"]);
2004
- return /* @__PURE__ */ jsx(
2005
- FieldWrapper,
2006
- {
2007
- name,
2008
- label,
2009
- className: `select ${className != null ? className : ""}`,
2010
- avoidSemicolon,
2011
- children: /* @__PURE__ */ jsxs(
2012
- Select$1,
2013
- __spreadProps$2(__spreadValues$2(__spreadValues$2(__spreadValues$2({}, getVariant("forms.select")), props), inputProps), {
2014
- onChange: React.useCallback(
2015
- (ev) => {
2016
- onChange(ev);
2017
- if (outerOnChange) {
2018
- outerOnChange(ev);
2019
- }
2020
- },
2021
- [onChange, outerOnChange]
2022
- ),
2023
- "aria-label": (_d = props["aria-label"]) != null ? _d : label,
2024
- ref,
2025
- value: (_e = inputProps.value) != null ? _e : "",
2026
- children: [
2027
- options == null ? void 0 : options.map((option) => /* @__PURE__ */ jsx("option", { value: option.value, children: option.label }, option.value)),
2028
- props.children
2029
- ]
2030
- })
2031
- )
2032
- }
2033
- );
2034
- }
2035
- );
2036
- Select.displayName = "Select";
2037
-
2038
- var __defProp$1 = Object.defineProperty;
2039
- var __defProps$1 = Object.defineProperties;
2040
- var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
2041
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
2042
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
2043
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
2044
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2045
- var __spreadValues$1 = (a, b) => {
2046
- for (var prop in b || (b = {}))
2047
- if (__hasOwnProp$1.call(b, prop))
2048
- __defNormalProp$1(a, prop, b[prop]);
2049
- if (__getOwnPropSymbols$1)
2050
- for (var prop of __getOwnPropSymbols$1(b)) {
2051
- if (__propIsEnum$1.call(b, prop))
2052
- __defNormalProp$1(a, prop, b[prop]);
2053
- }
2054
- return a;
2055
- };
2056
- var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
2057
- var __objRest$1 = (source, exclude) => {
2058
- var target = {};
2059
- for (var prop in source)
2060
- if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
2061
- target[prop] = source[prop];
2062
- if (source != null && __getOwnPropSymbols$1)
2063
- for (var prop of __getOwnPropSymbols$1(source)) {
2064
- if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
2065
- target[prop] = source[prop];
2066
- }
2067
- return target;
2068
- };
2069
- const Switchbox = React.forwardRef(
2070
- (_a, ref) => {
2071
- var _b = _a, {
2072
- avoidSemicolon,
2073
- className,
2074
- label,
2075
- onChange: outerOnChange,
2076
- type,
2077
- reverse = false,
2078
- avoidRegisterIfExists,
2079
- formName,
2080
- initialValue,
2081
- name,
2082
- removeOnUnmount,
2083
- submitValueParser,
2084
- validationClass,
2085
- validationFunction,
2086
- validationRules,
2087
- value
2088
- } = _b, props = __objRest$1(_b, [
2089
- "avoidSemicolon",
2090
- "className",
2091
- "label",
2092
- "onChange",
2093
- "type",
2094
- "reverse",
2095
- "avoidRegisterIfExists",
2096
- "formName",
2097
- "initialValue",
2098
- "name",
2099
- "removeOnUnmount",
2100
- "submitValueParser",
2101
- "validationClass",
2102
- "validationFunction",
2103
- "validationRules",
2104
- "value"
2105
- ]);
2106
- var _b2, _c;
2107
- const { actualValidationFunction, actualValidationRules } = useValidationClass({
2108
- validationClass,
2109
- validationFunction,
2110
- validationRules
2111
- });
2112
- const _a2 = useField({
2113
- avoidRegisterIfExists,
2114
- formName,
2115
- name,
2116
- initialValue: (initialValue != null ? initialValue : "off") === "on" || toBoolean(initialValue) ? "on" : "off",
2117
- removeOnUnmount,
2118
- submitValueParser,
2119
- validationFunction: actualValidationFunction,
2120
- validationRules: actualValidationRules
2121
- }), { onChange, updateValidations, isTouched } = _a2, inputProps = __objRest$1(_a2, ["onChange", "updateValidations", "isTouched"]);
2122
- return /* @__PURE__ */ jsx(
2123
- FieldWrapper,
2124
- {
2125
- name,
2126
- label,
2127
- className: `switchbox ${className != null ? className : ""}`,
2128
- avoidSemicolon,
2129
- children: /* @__PURE__ */ jsx(
2130
- Switch,
2131
- __spreadProps$1(__spreadValues$1(__spreadValues$1({}, props), inputProps), {
2132
- "aria-label": (_b2 = props["aria-label"]) != null ? _b2 : label,
2133
- onChange: (ev) => {
2134
- onChange(ev.target.checked !== reverse ? "on" : "off");
2135
- if (outerOnChange) {
2136
- outerOnChange(ev);
2137
- }
2138
- },
2139
- checked: ((_c = inputProps.value) != null ? _c : "off") === "on" !== reverse,
2140
- ref
2141
- })
2142
- )
2143
- }
2144
- );
2145
- }
2146
- );
2147
- Switchbox.displayName = "Switchbox";
2148
-
2149
- var __defProp = Object.defineProperty;
2150
- var __defProps = Object.defineProperties;
2151
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
2152
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
2153
- var __hasOwnProp = Object.prototype.hasOwnProperty;
2154
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
2155
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2156
- var __spreadValues = (a, b) => {
2157
- for (var prop in b || (b = {}))
2158
- if (__hasOwnProp.call(b, prop))
2159
- __defNormalProp(a, prop, b[prop]);
2160
- if (__getOwnPropSymbols)
2161
- for (var prop of __getOwnPropSymbols(b)) {
2162
- if (__propIsEnum.call(b, prop))
2163
- __defNormalProp(a, prop, b[prop]);
2164
- }
2165
- return a;
2166
- };
2167
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
2168
- var __objRest = (source, exclude) => {
2169
- var target = {};
2170
- for (var prop in source)
2171
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
2172
- target[prop] = source[prop];
2173
- if (source != null && __getOwnPropSymbols)
2174
- for (var prop of __getOwnPropSymbols(source)) {
2175
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
2176
- target[prop] = source[prop];
2177
- }
2178
- return target;
2179
- };
2180
- const Textarea = React.forwardRef(
2181
- (_a, ref) => {
2182
- var _b = _a, {
2183
- avoidSemicolon,
2184
- className,
2185
- formName,
2186
- label,
2187
- onChange: outerOnChange,
2188
- avoidRegisterIfExists: avoidRegisterIfExists,
2189
- initialValue,
2190
- name,
2191
- removeOnUnmount,
2192
- submitValueParser,
2193
- validationClass,
2194
- validationFunction,
2195
- validationRules,
2196
- value
2197
- } = _b, props = __objRest(_b, [
2198
- "avoidSemicolon",
2199
- "className",
2200
- "formName",
2201
- "label",
2202
- "onChange",
2203
- /**
2204
- * useField
2205
- */
2206
- "avoidRegisterIfExists",
2207
- "initialValue",
2208
- "name",
2209
- "removeOnUnmount",
2210
- "submitValueParser",
2211
- "validationClass",
2212
- "validationFunction",
2213
- "validationRules",
2214
- "value"
2215
- ]);
2216
- var _b2, _c;
2217
- const { actualValidationFunction, actualValidationRules } = useValidationClass({
2218
- validationClass,
2219
- validationFunction,
2220
- validationRules
2221
- });
2222
- const _a2 = useField({
2223
- avoidRegisterIfExists,
2224
- formName,
2225
- initialValue: initialValue != null ? initialValue : value,
2226
- name,
2227
- removeOnUnmount,
2228
- submitValueParser,
2229
- validationRules: actualValidationRules,
2230
- validationFunction: actualValidationFunction
2231
- }), { updateValidations, onChange, isTouched } = _a2, inputProps = __objRest(_a2, ["updateValidations", "onChange", "isTouched"]);
2232
- const handleOnChange = React.useCallback(
2233
- (ev) => {
2234
- onChange(ev);
2235
- if (outerOnChange) {
2236
- outerOnChange(ev);
2237
- }
2238
- },
2239
- [onChange, outerOnChange]
2240
- );
2241
- return /* @__PURE__ */ jsx(
2242
- FieldWrapper,
2243
- {
2244
- name,
2245
- label,
2246
- className: `textarea ${className != null ? className : ""}`,
2247
- avoidSemicolon,
2248
- children: /* @__PURE__ */ jsx(
2249
- Textarea$1,
2250
- __spreadProps(__spreadValues(__spreadValues({}, props), inputProps), {
2251
- "aria-label": (_b2 = props["aria-label"]) != null ? _b2 : label,
2252
- ref,
2253
- value: (_c = inputProps.value) != null ? _c : "",
2254
- onChange: handleOnChange
2255
- })
2256
- )
2257
- }
2258
- );
2259
- }
2260
- );
2261
- Textarea.displayName = "Textarea";
2262
-
2263
- export { InnerCaptcha as Captcha, Checkbox, DeletableInput, FieldLabel, FieldWrapper, FileInput, Form, FormContext, Input, NumberInputf, Radio, Select, Switchbox, Textarea, ValidationError, classToValidate, classToValidationFunction, hasSucceedFieldValidation, hasSucceedFormValidation, initValidations, useField, useFieldSelector, useFieldStatesClassNames, useFieldValue, useFormContext, useFormSelector, useValidationClass, validationsStore };
1
+ import{jsx as f,jsxs as D}from"react/jsx-runtime";import{customEvents as Xa,propsStore as W,usePropsSelector as Oe,useUpdateEffect as Ja,useUnmount as Fe,useMount as ye,PropsSelectorUndefinedObject as xe,formatMessage as Za,toBoolean as Ya}from"@apia/util";import{uniqueId as el}from"lodash";import c from"react";import{shallowEqual as ce}from"react-redux";import{makeStyledComponent as al,getVariant as ll}from"@apia/theme";import{notify as Ve}from"@apia/notifications";import{RequiredMark as A,Captcha as il,Checkbox as rl,IconButton as nl,getFieldErrorStyles as tl,DateInput as ol,parseNumberInputValueToNumber as $e,NumberInput as sl}from"@apia/components";import{Box as G,Input as ve,Label as Pe,Radio as ul,Select as dl,Switch as ml,Textarea as cl}from"theme-ui";const q=c.createContext({});function M(){const e=c.useContext(q);if(!e)throw new Error("There is no FormContext");return e}function vl({rules:e,value:a}){return xl(e).validate(a)}var fl=Object.defineProperty,we=Object.getOwnPropertySymbols,pl=Object.prototype.hasOwnProperty,bl=Object.prototype.propertyIsEnumerable,Se=(e,a,l)=>a in e?fl(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,hl=(e,a)=>{for(var l in a||(a={}))pl.call(a,l)&&Se(e,l,a[l]);if(we)for(var l of we(a))bl.call(a,l)&&Se(e,l,a[l]);return e},fe=(e,a,l)=>new Promise((i,r)=>{var n=t=>{try{u(l.next(t))}catch(s){r(s)}},o=t=>{try{u(l.throw(t))}catch(s){r(s)}},u=t=>t.done?i(t.value):Promise.resolve(t.value).then(n,o);u((l=l.apply(e,a)).next())});function gl(e,a){return fe(this,null,function*(){let l=null;const i=e.validationValueParser?e.validationValueParser(e.value):e.value;return e.validationFunction&&(l=yield e.validationFunction(i,a)),(!e.validationFunction||l===!0)&&e.validationRules?l=vl({rules:e.validationRules,value:i}):l===null&&(l=!0),l})}function Ne(e){return e===!0}function Ol(e){return!("errors"in e)}function Fl(e,a){return fe(this,null,function*(){const l=document.getElementById(`ValidationForm-${e}`),i=l?.querySelector(`[name="${a.name}"], #${a.name}`);return i?new Promise(r=>{const n=new CustomEvent(Xa.focus,{bubbles:!0});i.focus(),i.dispatchEvent(n),i.scrollIntoView({block:"center",behavior:"auto"}),r(!0)}):!1})}let X;function I(e,...a){if(!X[e])return"";let l=X[e];return a.forEach((i,r)=>{l=l.replace(`%${r}`,i.toString())}),l}function Re(e){const a=e?.match(/'confirm:(\w+):(.+?)']/);if(a)return(l,i)=>{var r,n;return l===((r=R.getFieldStore(i,a[1]))==null?void 0:r.value)?!0:I("confirm",(n=a[2])!=null?n:a[1])}}function Ce(e){const a={};if(e){const l=e.match(/validate\[([^\]]+)\]/);if(l)return l[1].replaceAll("~","").split(",").forEach(i=>{const r=i.match(/(\w+)(?:=([\w\d]+))?/);if(r){const n=r[1];if(n==="pattern"&&r[2])a[n]=new RegExp(r[2]);else if(r[2]){const o=r[2].split(","),u=o.length<2?o.join():o;a[n]=u}else a[n]=!0}}),a}return{}}function yl(){return fe(this,null,function*(){var e;X||(X=(yield import(`../lang/${(e=document.documentElement.lang)!=null?e:"es"}.ts`).catch(a=>{throw Ve({type:"danger",message:window.NO_LANGUAGE_EXCEPTION}),a})).default)})}function xl(e){const a=hl({},e);return a?{validate:l=>{var i;const r=l??"";let n=!0;if(n&&a.pattern){let o;if(a.pattern instanceof RegExp)o=a.pattern;else{const u=a.pattern.match(/(?:^\/(.+)\/(\w+)?$)|(^.*$)/),t=u[1],s=u[2],m=u[3];o=new RegExp(t||m,s||void 0)}n=!!l.match(o)||((i=a.patternMessage)!=null?i:window.MSG_INVALID_REG_EXP)}if(n===!0&&a.maxLength&&(n=r.length<=a.maxLength||I("lengthmax",a.maxLength)),n===!0&&a.minLength&&(n=r.length>=a.minLength||I("lengthmin",a.minLength)),n===!0&&a.max&&a.min&&(n=Number(r)<=a.max&&Number(r)>=a.min||I("digitltd",a.min,a.max)),n===!0&&a.min&&(n=Number(r)>=a.min||I("digitmin",a.min)),n===!0&&a.max&&(n=Number(r)<=a.max||I("digitltd",0,a.max)),n===!0&&a.validName&&(n=!!r.match(/^[a-zA-Z0-9_.]*$/)||window.GNR_INVALID_NAME),n===!0&&(a.alpha||a.nodigit)&&(n=!!r.match(/^[a-zA-Z]*$/)||I("alpha")),n===!0&&a.alphanum&&(n=!!r.match(/^[a-zA-Z0-9]*$/)||I("alphanum")),n===!0&&(a.digit||a.number)&&(n=!!r.match(/^[0-9]*$/)||I("digit")),n===!0&&a.email&&(n=!!r.match(/(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/)||I("email")),n===!0&&a.differs&&(n=r!==a.differs||I("differs",a.differs)),n===!0&&a.length_str&&(n=r.length>=a.length_str[0]&&r.length<=a.length_str[1]||I("length_str",...a.length_str)),n===!0&&a.length_fix&&(n=r.length===a.length_fix||I("length_fix",a.length_fix)),n===!0&&a.words_min)return r.split(" ").length>=a.words_min||I("words_min",a.words_min);if(n===!0&&a.words_max)return r.split(" ").length<=a.words_max||I("words_max",a.words_max);if(n===!0&&a.words_range){const o=r.split(" ").length;return o<=a.words_range[0]&&o>=a.words_range[1]||I("words_range",...a.words_range)}return n===!0&&a.required&&(n=Array.isArray(l)&&l.length>0||typeof l=="number"||!Array.isArray(r)&&!!r||I("required")),n}}:{validate:()=>!0}}var Vl=Object.defineProperty,$l=Object.defineProperties,Pl=Object.getOwnPropertyDescriptors,J=Object.getOwnPropertySymbols,Ie=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable,je=(e,a,l)=>a in e?Vl(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,Z=(e,a)=>{for(var l in a||(a={}))Ie.call(a,l)&&je(e,l,a[l]);if(J)for(var l of J(a))Ee.call(a,l)&&je(e,l,a[l]);return e},wl=(e,a)=>$l(e,Pl(a)),Sl=(e,a)=>{var l={};for(var i in e)Ie.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&J)for(var i of J(e))a.indexOf(i)<0&&Ee.call(e,i)&&(l[i]=e[i]);return l},Nl=(e,a,l)=>new Promise((i,r)=>{var n=t=>{try{u(l.next(t))}catch(s){r(s)}},o=t=>{try{u(l.throw(t))}catch(s){r(s)}},u=t=>t.done?i(t.value):Promise.resolve(t.value).then(n,o);u((l=l.apply(e,a)).next())});const R=new class{constructor(){this.activeForms=[],this.timeouts={},this.existsField=(e,a)=>{var l,i;return!!((i=(l=this.getFormStore(e))==null?void 0:l.fields)!=null&&i.includes(a))},this.registerField=(e,a,l={registerIfExists:!0})=>{var i,r,n;const o=this.getFormStore(e);o===void 0&&this.registerForm(e),(i=this.getFormStore(e))!=null&&i.fields.includes(a.name)||this.updateFormStore(e,{fields:[...(n=(r=this.getFormStore(e))==null?void 0:r.fields)!=null?n:[],a.name]});const u=this.getFieldStore(e,a.name);if((o!=null&&o.avoidFieldsOverride||!l.registerIfExists)&&u){const t=a,s=Sl(t,["value"]);this.updateField(e,s,{markFormAsTouched:!1,avoidPropagation:l.avoidPropagation});return}this.updateFieldStore(e,a.name,a,l.avoidPropagation)},this.registerForm=(e,a={avoidFieldsOverride:!1})=>{var l;if(this.activeForms.includes(e)){this.updateFormStore(e,{avoidFieldsOverride:a.avoidFieldsOverride}),a.initialValues&&Object.entries(a.initialValues).forEach(([i,r])=>{r instanceof Object&&this.updateField(e,Z({name:i},r))});return}this.activeForms.push(e),this.updateFormStore(e,{avoidFieldsOverride:a.avoidFieldsOverride,fields:[],isTouched:!1,isValid:!1,name:e,validationResult:null}),Object.entries((l=a.initialValues)!=null?l:{}).forEach(([i,r])=>{this.updateField(e,{name:i,value:r},{markFormAsTouched:!1})})},this.setFieldValue=(e,a,l,i)=>{this.getFieldStore(e,a)?this.updateField(e,{name:a,value:l,error:null},i):this.registerField(e,{name:a,value:l}),this.getFormStore(e).isValid&&this.updateFormStore(e,{isValid:!1})},this.setFormIsTouched=(e,a=!0)=>{this.updateFormStore(e,{isTouched:a})},this.unregisterField=(e,a)=>{this.getFormStore(e)&&this.updateFormStore(e,{fields:this.getFormStore(e).fields.filter(l=>l!==a)}),W.removeField(this.makeFieldName(e,a))},this.unregisterForm=e=>{var a,l;(l=(a=this.getFormStore(e))==null?void 0:a.fields)==null||l.forEach(i=>W.removeField(this.makeFieldName(e,i))),this.activeForms=this.activeForms.filter(i=>i!==e),W.removeField(this.makeFormName(e)),delete this.timeouts[e]},this.updateField=(e,a,l)=>{var i,r;const n=(i=this.getFieldStore(e,a.name))==null?void 0:i.value;this.getFormStore(e)?this.updateFormStore(e,{isValid:!1}):this.registerForm(e);const o=a.value!==void 0&&a.value!==n&&l?.markFormAsTouched!==!1;this.existsField(e,a.name)||this.registerField(e,a,{avoidPropagation:l?.avoidPropagation}),this.updateFieldStore(e,a.name,wl(Z({},a),{isTouched:o||((r=this.getFieldStore(e,a.name))==null?void 0:r.isTouched)}),l?.avoidPropagation),o&&this.setFormIsTouched(e)},this.updateMultipleFields=(e,a,l)=>{a.forEach(i=>this.updateField(e,i,l))},this.validateForm=e=>Nl(this,null,function*(){var a;const l=this.getFormStore(e).fields.map(t=>this.getFieldStore(e,t)),i={errors:{}},r={submitValues:{},values:{}};let n=!1,o=!1;const u={};for(const t of l.filter(s=>s!==void 0)){const s=yield gl(t,e);u[t.name]=s,Ne(s)?(r.submitValues[(a=t.submitName)!=null?a:t.name]=t.submitValueParser?t.submitValueParser(t.value):t.value,r.values[t.name]=t.value):(this.updateField(e,{name:t.name,error:s}),n||(yield Fl(e,t))&&(n=!0),o=!0,i.errors[t.name]=s)}return o?(n||(Ve({message:window.MSG_WRONG_VALIDATION_NO_FOCUSED_FILE,type:"danger"}),console.error("Campos que fallaron la validaci\xF3n",u)),this.updateFormStore(e,{isValid:!1,validationResult:i}),i):(this.updateFormStore(e,{isValid:!0,validationResult:r}),r)})}getFieldStore(e,a){return W.getFieldProps(this.makeFieldName(e,a))}getFormStore(e){return W.getFieldProps(this.makeFormName(e))}updateFieldStore(e,a,l,i){W.updateField(this.makeFieldName(e,a),Z(Z({},this.getFieldStore(e,a)),l),{noEmit:i})}updateFormStore(e,a){W.updateField(this.makeFormName(e),a)}enableFormTouch(e){this.timeouts[e]=!0}makeFieldName(e,a){return`validation_${e}_${a}`}makeFormName(e){return`validation_${e}`}};function Te(e,a,l){return Oe(R.makeFormName(e),a,l)}function B(e,a,l,i){const r=R.makeFieldName(e,a);return Oe(r,l,i)}const Rl={".fieldWrapper":{display:"flex",flexDirection:"column",alignItems:"stretch","&.checkbox":{alignItems:"center"}},".error":{borderLeftStyle:"solid",borderLeftWidth:"4px",borderLeftColor:"danger"},".touched":{borderStyle:"solid",borderWidth:"1px",borderColor:"orange"}};var Cl=(e,a,l)=>new Promise((i,r)=>{var n=t=>{try{u(l.next(t))}catch(s){r(s)}},o=t=>{try{u(l.throw(t))}catch(s){r(s)}},u=t=>t.done?i(t.value):Promise.resolve(t.value).then(n,o);u((l=l.apply(e,a)).next())});const Il=({avoidFieldsOverride:e,avoidFieldsTouch:a,children:l,className:i,name:r,initialValues:n,onUnmount:o,onValidate:u,unregisterOnUnmount:t})=>{const s=c.useMemo(()=>r??`ValidationForm${el()}`,[]),m=Te(s,x=>x.validationResult,ce);Ja(()=>{m&&u&&u(m)},[m]);const d=c.useCallback(x=>{x.preventDefault(),R.validateForm(s)},[s]),v=c.useMemo(()=>({avoidFieldsTouch:a,name:s,validate:()=>Cl(void 0,null,function*(){return R.validateForm(s)})}),[s,a]);Fe(()=>{o?.(),t!==!1&&R.unregisterForm(s)});const[p,$]=c.useState(!1);return ye(()=>{R.registerForm(s,{avoidFieldsOverride:e??n!==void 0,initialValues:n}),$(!0)}),p?f(q.Provider,{value:v,children:f("form",{className:i,id:`ValidationForm-${s}`,name:s,onSubmit:d,children:l})}):null},El=al("Form","layout.common.validations.form",Rl,Il);var jl=Object.defineProperty,_e=Object.getOwnPropertySymbols,Tl=Object.prototype.hasOwnProperty,_l=Object.prototype.propertyIsEnumerable,ke=(e,a,l)=>a in e?jl(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,Ue=(e,a)=>{for(var l in a||(a={}))Tl.call(a,l)&&ke(e,l,a[l]);if(_e)for(var l of _e(a))_l.call(a,l)&&ke(e,l,a[l]);return e};function _(e){var a;const l=c.useContext(q),i=(a=e.formName)!=null?a:l.name;if(!i)throw console.error(e),new Error(`useField: It was not possible to determine the formName in field with name ${e.name}`);c.useMemo(()=>{R.registerField(i,Ue(Ue({},e),e.initialValue!==void 0?{value:e.initialValue}:null),{avoidPropagation:!0,registerIfExists:!e.avoidRegisterIfExists})},[]),ye(()=>{var d;e.initialValue!==void 0&&(!((d=R.getFormStore(i))!=null&&d.avoidFieldsOverride)&&!e.avoidRegisterIfExists||R.getFieldStore(i,e.name)===void 0)&&R.setFieldValue(i,e.name,e.initialValue)}),Fe(()=>{e.removeOnUnmount&&R.unregisterField(i,e.name)});const{name:r,value:n,error:o,isTouched:u}=B(i,e.name,d=>d,(d,v)=>d===xe&&e.initialValue!==void 0?!0:ce(d,v)),[t,s]=c.useState(e.initialValue);c.useEffect(()=>{s(n)},[n]);const m=c.useCallback(d=>{const v=d;let p;typeof v=="object"&&v&&v.target!==void 0&&v.target.value!==void 0?p=v.target.value:p=d,s(p),R.setFieldValue(i,e.name,p)},[e.name,i]);return{error:o,isTouched:u,name:r,onChange:m,updateValidations:c.useCallback(({validationFunction:d,validationRules:v})=>{R.updateField(i,{name:e.name,validationFunction:d,validationRules:v})},[i,e.name]),value:t??e.initialValue}}function Q(e,a){const{error:l,isTouched:i}=_({name:e,formName:a,avoidRegisterIfExists:!0,removeOnUnmount:!1}),{avoidFieldsTouch:r}=M();return l?"error":!r&&i?"touched":""}function kl({formName:e,name:a}){const{name:l}=M();if(!e&&!l)throw new Error(`useFieldValue: It was not possible to determine the formName in field with name ${a}`);const{value:i}=B(e??l,a,r=>r,(r,n)=>r===xe&&n?.value===void 0?!0:ce(r?.value,n?.value));return i}var Ul=Object.defineProperty,De=Object.getOwnPropertySymbols,Dl=Object.prototype.hasOwnProperty,Ll=Object.prototype.propertyIsEnumerable,Le=(e,a,l)=>a in e?Ul(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,We=(e,a)=>{for(var l in a||(a={}))Dl.call(a,l)&&Le(e,l,a[l]);if(De)for(var l of De(a))Ll.call(a,l)&&Le(e,l,a[l]);return e};function U({customValidation:e,validationClass:a,validationFunction:l,validationRules:i}){const r=c.useMemo(()=>a!==void 0?Re(a):void 0,[a]),n=c.useCallback((u,t)=>{var s;let m=(s=l?.(u,t))!=null?s:!0;return typeof m=="string"||(e&&(m=e(u,t)),typeof m=="string")?m:r?r(u,t):!0},[r,e,l]),o=c.useMemo(()=>We(We({},i),a!==void 0?Ce(a):{}),[a,i]);return{actualValidationFunction:n,actualValidationRules:o}}const pe=({name:e})=>{const a=M(),l=B(a.name,e,i=>i?.error);return l?f(G,{as:"strong",role:"alert",sx:{color:"danger"},dangerouslySetInnerHTML:{__html:l}}):null};var Wl=Object.defineProperty,ql=Object.defineProperties,Al=Object.getOwnPropertyDescriptors,Y=Object.getOwnPropertySymbols,qe=Object.prototype.hasOwnProperty,Ae=Object.prototype.propertyIsEnumerable,Me=(e,a,l)=>a in e?Wl(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,ze=(e,a)=>{for(var l in a||(a={}))qe.call(a,l)&&Me(e,l,a[l]);if(Y)for(var l of Y(a))Ae.call(a,l)&&Me(e,l,a[l]);return e},He=(e,a)=>ql(e,Al(a)),Ml=(e,a)=>{var l={};for(var i in e)qe.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&Y)for(var i of Y(e))a.indexOf(i)<0&&Ae.call(e,i)&&(l[i]=e[i]);return l};const k=e=>{var a=e,{name:l,label:i,avoidSemicolon:r,children:n,className:o,as:u="label",type:t}=a,s=Ml(a,["name","label","avoidSemicolon","children","className","as","type"]);const{name:m}=M(),d=B(m,l,v=>{var p;return(p=v?.validationRules)==null?void 0:p.required});return t==="checkbox"?D(G,He(ze({className:`fieldWrapper checkboxWrapper ${o??""}`},s),{as:u,children:[window.SHOW_REQUIRED_POSITION!=="0"&&i&&f(A,{isRequired:d}),n,D("span",{children:[i,window.SHOW_REQUIRED_POSITION==="0"&&i&&f(A,{isRequired:d})]}),f(pe,{name:l})]})):D(G,He(ze({className:`fieldWrapper ${o??""}`},s),{as:u,children:[D(G,{as:"span",children:[window.SHOW_REQUIRED_POSITION!=="0"&&i&&f(A,{isRequired:d}),i,!r&&i&&f("abbr",{className:"semicolon",children:": "}),window.SHOW_REQUIRED_POSITION==="0"&&i&&f(A,{isRequired:d})]}),n,f(pe,{name:l})]}))};var Ge=Object.getOwnPropertySymbols,zl=Object.prototype.hasOwnProperty,Hl=Object.prototype.propertyIsEnumerable,Gl=(e,a)=>{var l={};for(var i in e)zl.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&Ge)for(var i of Ge(e))a.indexOf(i)<0&&Hl.call(e,i)&&(l[i]=e[i]);return l};const Bl=({className:e,name:a,imageUrl:l,avoidRegisterIfExists:i,avoidSemicolon:r,formName:n,label:o,removeOnUnmount:u,submitName:t,submitValueParser:s,validationValueParser:m})=>{const d=_({name:a,avoidRegisterIfExists:i,formName:n,initialValue:"",removeOnUnmount:u,submitName:t,submitValueParser:s,validationValueParser:m,validationRules:{required:!0}}),{error:v,updateValidations:p,onChange:$,isTouched:x}=d,w=Gl(d,["error","updateValidations","onChange","isTouched"]),S=c.useCallback(h=>{$(h)},[$]),O=Q(a);return f(k,{name:a,label:o,className:`input ${e??""}`,avoidSemicolon:r,children:f(il,{name:a,imageUrl:l,onChange:S,value:w.value,className:O})})};var Ql=Object.defineProperty,Kl=Object.defineProperties,Xl=Object.getOwnPropertyDescriptors,ee=Object.getOwnPropertySymbols,Be=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable,Ke=(e,a,l)=>a in e?Ql(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,Xe=(e,a)=>{for(var l in a||(a={}))Be.call(a,l)&&Ke(e,l,a[l]);if(ee)for(var l of ee(a))Qe.call(a,l)&&Ke(e,l,a[l]);return e},Jl=(e,a)=>Kl(e,Xl(a)),Je=(e,a)=>{var l={};for(var i in e)Be.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&ee)for(var i of ee(e))a.indexOf(i)<0&&Qe.call(e,i)&&(l[i]=e[i]);return l};const Ze=c.forwardRef((e,a)=>{var l=e,{avoidSemicolon:i,className:r,label:n,native:o,onChange:u,type:t,avoidRegisterIfExists:s,formName:m,initialValue:d,name:v,removeOnUnmount:p,submitValueParser:$,validationClass:x,validationFunction:w,validationRules:S,value:O}=l,h=Je(l,["avoidSemicolon","className","label","native","onChange","type","avoidRegisterIfExists","formName","initialValue","name","removeOnUnmount","submitValueParser","validationClass","validationFunction","validationRules","value"]),F,V;const{actualValidationFunction:g,actualValidationRules:E}=U({validationClass:x,validationFunction:w,validationRules:S}),P=_({avoidRegisterIfExists:s,formName:m,name:v,initialValue:(F=d===!0||d==="on")!=null?F:!1,removeOnUnmount:p,submitValueParser:$,validationFunction:g,validationRules:E}),{value:N,onChange:j,updateValidations:C,isTouched:b}=P,y=Je(P,["value","onChange","updateValidations","isTouched"]);return f(k,{name:v,label:n,className:`checkbox ${r??""}`,avoidSemicolon:i,children:f(rl,Jl(Xe(Xe({},h),y),{native:o,"aria-label":(V=h["aria-label"])!=null?V:n,onChange:T=>{j(T.target.checked),u&&u(T)},checked:N===!0||N==="on",ref:a}))})});Ze.displayName="Checkbox";var Zl=Object.defineProperty,Yl=Object.defineProperties,ei=Object.getOwnPropertyDescriptors,ae=Object.getOwnPropertySymbols,Ye=Object.prototype.hasOwnProperty,ea=Object.prototype.propertyIsEnumerable,aa=(e,a,l)=>a in e?Zl(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,la=(e,a)=>{for(var l in a||(a={}))Ye.call(a,l)&&aa(e,l,a[l]);if(ae)for(var l of ae(a))ea.call(a,l)&&aa(e,l,a[l]);return e},ai=(e,a)=>Yl(e,ei(a)),ia=(e,a)=>{var l={};for(var i in e)Ye.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&ae)for(var i of ae(e))a.indexOf(i)<0&&ea.call(e,i)&&(l[i]=e[i]);return l};const ra=c.forwardRef((e,a)=>{var l=e,{avoidSemicolon:i,className:r,label:n,onChange:o,type:u,avoidRegisterIfExists:t,formName:s,initialValue:m,name:d,removeOnUnmount:v,submitValueParser:p,validationClass:$,validationFunction:x,validationRules:w,value:S}=l,O=ia(l,["avoidSemicolon","className","label","onChange","type","avoidRegisterIfExists","formName","initialValue","name","removeOnUnmount","submitValueParser","validationClass","validationFunction","validationRules","value"]),h,F,V,g,E;const{name:P}=c.useContext(q),N=s??P,{actualValidationFunction:j,actualValidationRules:C}=U({validationClass:$,validationFunction:x,validationRules:w}),b=_({formName:N,name:d,initialValue:(V=(F=m??S)!=null?F:(h=R.getFieldStore(N,d))==null?void 0:h.value)!=null?V:"",removeOnUnmount:v,submitValueParser:p,validationFunction:j,validationRules:C}),{error:y,updateValidations:T,onChange:K,isTouched:Ka}=b,z=ia(b,["error","updateValidations","onChange","isTouched"]),he=c.useCallback(H=>{K(H),o?.(H)},[K,o]),L=Q(d);return D(k,{name:d,label:n,sx:c.useCallback(()=>({display:"flex",flexDirection:"column",alignItems:"start"}),[]),className:`deletableInput ${r??""}`,avoidSemicolon:i,children:[f(ve,ai(la(la({type:u},O),z),{"aria-label":(g=O["aria-label"])!=null?g:n,ref:a,onChange:he,value:(E=z.value)!=null?E:"",className:`deletableInput__input ${L??""}`})),f(nl,{icon:"Close",className:"deletableInput__deleteButton",onClick:()=>K("")})]})});ra.displayName="DeletableInput";var li=Object.defineProperty,ii=Object.defineProperties,ri=Object.getOwnPropertyDescriptors,le=Object.getOwnPropertySymbols,na=Object.prototype.hasOwnProperty,ta=Object.prototype.propertyIsEnumerable,oa=(e,a,l)=>a in e?li(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,ni=(e,a)=>{for(var l in a||(a={}))na.call(a,l)&&oa(e,l,a[l]);if(le)for(var l of le(a))ta.call(a,l)&&oa(e,l,a[l]);return e},ti=(e,a)=>ii(e,ri(a)),oi=(e,a)=>{var l={};for(var i in e)na.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&le)for(var i of le(e))a.indexOf(i)<0&&ta.call(e,i)&&(l[i]=e[i]);return l};const si=e=>{var a=e,{avoidSemicolon:l,children:i,required:r}=a,n=oi(a,["avoidSemicolon","children","required"]);return D(Pe,ti(ni({},n),{children:[window.SHOW_REQUIRED_POSITION!=="0"&&f(A,{isRequired:r}),i,!l&&": ",window.SHOW_REQUIRED_POSITION==="0"&&f(A,{isRequired:r})]}))};var ui=Object.defineProperty,di=Object.defineProperties,mi=Object.getOwnPropertyDescriptors,ie=Object.getOwnPropertySymbols,sa=Object.prototype.hasOwnProperty,ua=Object.prototype.propertyIsEnumerable,da=(e,a,l)=>a in e?ui(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,ma=(e,a)=>{for(var l in a||(a={}))sa.call(a,l)&&da(e,l,a[l]);if(ie)for(var l of ie(a))ua.call(a,l)&&da(e,l,a[l]);return e},ci=(e,a)=>di(e,mi(a)),ca=(e,a)=>{var l={};for(var i in e)sa.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&ie)for(var i of ie(e))a.indexOf(i)<0&&ua.call(e,i)&&(l[i]=e[i]);return l};const va=c.memo(c.forwardRef((e,a)=>{var l=e,{avoidSemicolon:i,className:r,label:n,avoidRegisterIfExists:o,formName:u,initialValue:t,name:s,removeOnUnmount:m,submitValueParser:d,validationClass:v,validationFunction:p,validationRules:$}=l,x=ca(l,["avoidSemicolon","className","label","avoidRegisterIfExists","formName","initialValue","name","removeOnUnmount","submitValueParser","validationClass","validationFunction","validationRules"]),w;const{name:S}=M(),{actualValidationFunction:O,actualValidationRules:h}=U({customValidation(C){return C!=null?!0:I("required")},validationClass:v,validationFunction:p,validationRules:$}),F=_({formName:S,name:s,removeOnUnmount:m,submitValueParser:d,validationFunction:O,validationRules:h}),{error:V,onChange:g,value:E,updateValidations:P,isTouched:N}=F,j=ca(F,["error","onChange","value","updateValidations","isTouched"]);return f(k,{name:s,label:n,className:`input ${r??""}`,avoidSemicolon:i,children:f(ve,ci(ma(ma({},x),j),{type:"file","aria-label":(w=x["aria-label"])!=null?w:n,ref:a,sx:tl(!V),onChange:c.useCallback(C=>{var b,y,T;g((T=(y=(b=C.target)==null?void 0:b.files)==null?void 0:y[0])!=null?T:null)},[g])}))})}));va.displayName="FileInput";var vi=Object.defineProperty,fi=Object.defineProperties,pi=Object.getOwnPropertyDescriptors,re=Object.getOwnPropertySymbols,fa=Object.prototype.hasOwnProperty,pa=Object.prototype.propertyIsEnumerable,ba=(e,a,l)=>a in e?vi(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,ne=(e,a)=>{for(var l in a||(a={}))fa.call(a,l)&&ba(e,l,a[l]);if(re)for(var l of re(a))pa.call(a,l)&&ba(e,l,a[l]);return e},ha=(e,a)=>fi(e,pi(a)),ga=(e,a)=>{var l={};for(var i in e)fa.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&re)for(var i of re(e))a.indexOf(i)<0&&pa.call(e,i)&&(l[i]=e[i]);return l};const Oa=c.memo(c.forwardRef((e,a)=>{var l=e,{avoidSemicolon:i,className:r,label:n,onChange:o,type:u,avoidRegisterIfExists:t,formName:s,initialValue:m,name:d,removeOnUnmount:v,submitValueParser:p,validationClass:$,validationFunction:x,validationRules:w,value:S}=l,O=ga(l,["avoidSemicolon","className","label","onChange","type","avoidRegisterIfExists","formName","initialValue","name","removeOnUnmount","submitValueParser","validationClass","validationFunction","validationRules","value"]),h,F,V,g,E,P,N;const{name:j}=c.useContext(q),C=s??j,{actualValidationFunction:b,actualValidationRules:y}=U({validationClass:$,validationFunction:x,validationRules:w}),T=_({formName:C,name:d,initialValue:(V=(F=m??S)!=null?F:(h=R.getFieldStore(C,d))==null?void 0:h.value)!=null?V:"",removeOnUnmount:v,submitValueParser:p,validationFunction:b,validationRules:y}),{error:K,updateValidations:Ka,onChange:z,isTouched:he}=T,L=ga(T,["error","updateValidations","onChange","isTouched"]),H=c.useCallback(me=>{z(me),typeof me=="string"?o?.({target:a}):o?.(me)},[z,o,a]),ge=Q(d);return f(k,{name:d,label:n,className:`input ${r??""}`,avoidSemicolon:i,children:u==="date"?f(ol,ha(ne(ne({},O),L),{"aria-label":(g=O["aria-label"])!=null?g:n,onError:void 0,ref:a,onChange:H,value:(E=L.value)!=null?E:"",className:ge})):f(ve,ha(ne(ne({type:u},O),L),{"aria-label":(P=O["aria-label"])!=null?P:n,ref:a,onChange:H,value:(N=L.value)!=null?N:"",className:ge}))})}));Oa.displayName="Input";var bi=Object.defineProperty,hi=Object.defineProperties,gi=Object.getOwnPropertyDescriptors,te=Object.getOwnPropertySymbols,Fa=Object.prototype.hasOwnProperty,ya=Object.prototype.propertyIsEnumerable,xa=(e,a,l)=>a in e?bi(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,Va=(e,a)=>{for(var l in a||(a={}))Fa.call(a,l)&&xa(e,l,a[l]);if(te)for(var l of te(a))ya.call(a,l)&&xa(e,l,a[l]);return e},$a=(e,a)=>hi(e,gi(a)),Oi=(e,a)=>{var l={};for(var i in e)Fa.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&te)for(var i of te(e))a.indexOf(i)<0&&ya.call(e,i)&&(l[i]=e[i]);return l};const Pa=c.memo(c.forwardRef((e,a)=>{var l=e,{avoidSemicolon:i,className:r,label:n,onChange:o,avoidRegisterIfExists:u,formName:t,initialValue:s,name:m,removeOnUnmount:d,submitValueParser:v,validationClass:p,validationFunction:$,validationRules:x,value:w}=l,S=Oi(l,["avoidSemicolon","className","label","onChange","avoidRegisterIfExists","formName","initialValue","name","removeOnUnmount","submitValueParser","validationClass","validationFunction","validationRules","value"]),O,h,F;const{name:V}=c.useContext(q),g=t??V,{actualValidationFunction:E,actualValidationRules:P}=U({validationClass:p,validationFunction:$,validationRules:x}),{onChange:N,value:j}=_({formName:g,name:m,initialValue:(F=(h=s??w)!=null?h:(O=R.getFieldStore(g,m))==null?void 0:O.value)!=null?F:"",removeOnUnmount:d,submitValueParser:c.useCallback(y=>$e(y??""),[]),validationValueParser:c.useCallback(y=>$e(y??""),[]),validationFunction:E,validationRules:P}),C=c.useCallback(y=>{y.error?(o?.($a(Va({},y),{value:""})),N(""),R.updateField(g,{name:m,error:Za(window.GNR_NUMERIC,{TOK:""})})):(N(y.value),o?.(y),R.updateField(g,{name:m,error:null}))},[g,m,N,o]),b=Q(m);return f(k,{name:m,label:n,sx:c.useMemo(()=>({display:"flex",flexDirection:"column",alignItems:"start"}),[]),className:`input ${r??""}`,avoidSemicolon:i,children:f(sl,$a(Va({ref:a},S),{name:m,value:j,onChange:C,className:b}))})}));Pa.displayName="NumberInputf";var Fi=Object.defineProperty,yi=Object.defineProperties,xi=Object.getOwnPropertyDescriptors,oe=Object.getOwnPropertySymbols,wa=Object.prototype.hasOwnProperty,Sa=Object.prototype.propertyIsEnumerable,Na=(e,a,l)=>a in e?Fi(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,Ra=(e,a)=>{for(var l in a||(a={}))wa.call(a,l)&&Na(e,l,a[l]);if(oe)for(var l of oe(a))Sa.call(a,l)&&Na(e,l,a[l]);return e},Vi=(e,a)=>yi(e,xi(a)),Ca=(e,a)=>{var l={};for(var i in e)wa.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&oe)for(var i of oe(e))a.indexOf(i)<0&&Sa.call(e,i)&&(l[i]=e[i]);return l};const Ia=c.forwardRef((e,a)=>{var l=e,{avoidSemicolon:i,className:r,formName:n,label:o,onChange:u,options:t,value:s,avoidRegisterIfExists:m,initialValue:d,name:v,removeOnUnmount:p,submitValueParser:$,validationClass:x,validationFunction:w,validationRules:S}=l,O=Ca(l,["avoidSemicolon","className","formName","label","onChange","options","value","avoidRegisterIfExists","initialValue","name","removeOnUnmount","submitValueParser","validationClass","validationFunction","validationRules"]);const{actualValidationFunction:h,actualValidationRules:F}=U({validationClass:x,validationFunction:w,validationRules:S}),V=_({formName:n,name:v,initialValue:d??s,removeOnUnmount:p,submitValueParser:$,validationFunction:h,validationRules:F}),{value:g,updateValidations:E,onChange:P,isTouched:N}=V,j=Ca(V,["value","updateValidations","onChange","isTouched"]),C=c.useCallback(b=>{P(b),u&&u(b)},[P,u]);return f(k,{name:v,label:o,className:`radio ${r??""}`,avoidSemicolon:i,as:"ul",children:t?.map(b=>f("li",{children:D(Pe,{title:b.label,className:"radio-label",children:[f(ul,Vi(Ra(Ra({},O),j),{role:"radio",className:"radio-button","aria-label":b.label,ref:a,value:b.value,checked:g===b.value,onChange:C})),f(G,{as:"span",className:"radio-text",children:b.label})]})},b.value))})});Ia.displayName="Radio";var $i=Object.defineProperty,Pi=Object.defineProperties,wi=Object.getOwnPropertyDescriptors,se=Object.getOwnPropertySymbols,Ea=Object.prototype.hasOwnProperty,ja=Object.prototype.propertyIsEnumerable,Ta=(e,a,l)=>a in e?$i(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,be=(e,a)=>{for(var l in a||(a={}))Ea.call(a,l)&&Ta(e,l,a[l]);if(se)for(var l of se(a))ja.call(a,l)&&Ta(e,l,a[l]);return e},Si=(e,a)=>Pi(e,wi(a)),_a=(e,a)=>{var l={};for(var i in e)Ea.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&se)for(var i of se(e))a.indexOf(i)<0&&ja.call(e,i)&&(l[i]=e[i]);return l};const ka=c.forwardRef((e,a)=>{var l=e,{avoidSemicolon:i,className:r,formName:n,label:o,onChange:u,options:t,avoidRegisterIfExists:s,initialValue:m,name:d,removeOnUnmount:v,submitValueParser:p,validationClass:$,validationFunction:x,validationRules:w,value:S}=l,O=_a(l,["avoidSemicolon","className","formName","label","onChange","options","avoidRegisterIfExists","initialValue","name","removeOnUnmount","submitValueParser","validationClass","validationFunction","validationRules","value"]),h,F,V,g;const{actualValidationFunction:E,actualValidationRules:P}=U({validationClass:$,validationFunction:x,validationRules:w}),N=_({avoidRegisterIfExists:s,initialValue:(F=m??S)!=null?F:(h=t[0])==null?void 0:h.value,name:d,removeOnUnmount:v,submitValueParser:p,validationFunction:E,validationRules:P}),{updateValidations:j,onChange:C,isTouched:b}=N,y=_a(N,["updateValidations","onChange","isTouched"]);return f(k,{name:d,label:o,className:`select ${r??""}`,avoidSemicolon:i,children:D(dl,Si(be(be(be({},ll("forms.select")),O),y),{onChange:c.useCallback(T=>{C(T),u&&u(T)},[C,u]),"aria-label":(V=O["aria-label"])!=null?V:o,ref:a,value:(g=y.value)!=null?g:"",children:[t?.map(T=>f("option",{value:T.value,children:T.label},T.value)),O.children]}))})});ka.displayName="Select";var Ni=Object.defineProperty,Ri=Object.defineProperties,Ci=Object.getOwnPropertyDescriptors,ue=Object.getOwnPropertySymbols,Ua=Object.prototype.hasOwnProperty,Da=Object.prototype.propertyIsEnumerable,La=(e,a,l)=>a in e?Ni(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,Wa=(e,a)=>{for(var l in a||(a={}))Ua.call(a,l)&&La(e,l,a[l]);if(ue)for(var l of ue(a))Da.call(a,l)&&La(e,l,a[l]);return e},Ii=(e,a)=>Ri(e,Ci(a)),qa=(e,a)=>{var l={};for(var i in e)Ua.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&ue)for(var i of ue(e))a.indexOf(i)<0&&Da.call(e,i)&&(l[i]=e[i]);return l};const Aa=c.forwardRef((e,a)=>{var l=e,{avoidSemicolon:i,className:r,label:n,onChange:o,type:u,reverse:t=!1,avoidRegisterIfExists:s,formName:m,initialValue:d,name:v,removeOnUnmount:p,submitValueParser:$,validationClass:x,validationFunction:w,validationRules:S,value:O}=l,h=qa(l,["avoidSemicolon","className","label","onChange","type","reverse","avoidRegisterIfExists","formName","initialValue","name","removeOnUnmount","submitValueParser","validationClass","validationFunction","validationRules","value"]),F,V;const{actualValidationFunction:g,actualValidationRules:E}=U({validationClass:x,validationFunction:w,validationRules:S}),P=_({avoidRegisterIfExists:s,formName:m,name:v,initialValue:(d??"off")==="on"||Ya(d)?"on":"off",removeOnUnmount:p,submitValueParser:$,validationFunction:g,validationRules:E}),{onChange:N,updateValidations:j,isTouched:C}=P,b=qa(P,["onChange","updateValidations","isTouched"]);return f(k,{name:v,label:n,className:`switchbox ${r??""}`,avoidSemicolon:i,children:f(ml,Ii(Wa(Wa({},h),b),{"aria-label":(F=h["aria-label"])!=null?F:n,onChange:y=>{N(y.target.checked!==t?"on":"off"),o&&o(y)},checked:((V=b.value)!=null?V:"off")==="on"!==t,ref:a}))})});Aa.displayName="Switchbox";var Ei=Object.defineProperty,ji=Object.defineProperties,Ti=Object.getOwnPropertyDescriptors,de=Object.getOwnPropertySymbols,Ma=Object.prototype.hasOwnProperty,za=Object.prototype.propertyIsEnumerable,Ha=(e,a,l)=>a in e?Ei(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,Ga=(e,a)=>{for(var l in a||(a={}))Ma.call(a,l)&&Ha(e,l,a[l]);if(de)for(var l of de(a))za.call(a,l)&&Ha(e,l,a[l]);return e},_i=(e,a)=>ji(e,Ti(a)),Ba=(e,a)=>{var l={};for(var i in e)Ma.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&de)for(var i of de(e))a.indexOf(i)<0&&za.call(e,i)&&(l[i]=e[i]);return l};const Qa=c.forwardRef((e,a)=>{var l=e,{avoidSemicolon:i,className:r,formName:n,label:o,onChange:u,avoidRegisterIfExists:t,initialValue:s,name:m,removeOnUnmount:d,submitValueParser:v,validationClass:p,validationFunction:$,validationRules:x,value:w}=l,S=Ba(l,["avoidSemicolon","className","formName","label","onChange","avoidRegisterIfExists","initialValue","name","removeOnUnmount","submitValueParser","validationClass","validationFunction","validationRules","value"]),O,h;const{actualValidationFunction:F,actualValidationRules:V}=U({validationClass:p,validationFunction:$,validationRules:x}),g=_({avoidRegisterIfExists:t,formName:n,initialValue:s??w,name:m,removeOnUnmount:d,submitValueParser:v,validationRules:V,validationFunction:F}),{updateValidations:E,onChange:P,isTouched:N}=g,j=Ba(g,["updateValidations","onChange","isTouched"]),C=c.useCallback(b=>{P(b),u&&u(b)},[P,u]);return f(k,{name:m,label:o,className:`textarea ${r??""}`,avoidSemicolon:i,children:f(cl,_i(Ga(Ga({},S),j),{"aria-label":(O=S["aria-label"])!=null?O:o,ref:a,value:(h=j.value)!=null?h:"",onChange:C}))})});Qa.displayName="Textarea";export{Bl as Captcha,Ze as Checkbox,ra as DeletableInput,si as FieldLabel,k as FieldWrapper,va as FileInput,El as Form,q as FormContext,Oa as Input,Pa as NumberInputf,Ia as Radio,ka as Select,Aa as Switchbox,Qa as Textarea,pe as ValidationError,Ce as classToValidate,Re as classToValidationFunction,Ne as hasSucceedFieldValidation,Ol as hasSucceedFormValidation,yl as initValidations,_ as useField,B as useFieldSelector,Q as useFieldStatesClassNames,kl as useFieldValue,M as useFormContext,Te as useFormSelector,U as useValidationClass,R as validationsStore};
2264
2
  //# sourceMappingURL=index.js.map