@visiion/forms-library 1.4.1 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -83,6 +83,16 @@ function __generator(thisArg, body) {
83
83
  }
84
84
  }
85
85
 
86
+ function __spreadArray(to, from, pack) {
87
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
88
+ if (ar || !(i in from)) {
89
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
90
+ ar[i] = from[i];
91
+ }
92
+ }
93
+ return to.concat(ar || Array.prototype.slice.call(from));
94
+ }
95
+
86
96
  typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
87
97
  var e = new Error(message);
88
98
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
@@ -10181,7 +10191,12 @@ var SelectInput = function (_a) {
10181
10191
  var RadioInput = function (_a) {
10182
10192
  var _b;
10183
10193
  var field = _a.field, value = _a.value, onChange = _a.onChange, error = _a.error;
10184
- return (jsxs(InputWrapper, __assign({}, field, { error: error, children: [jsx("div", { className: "space-y-2", children: (_b = field.options) === null || _b === void 0 ? void 0 : _b.map(function (option) { return (jsx(RadioOption, { id: "".concat(field.id, "-").concat(option.value), name: field.name, value: option.value, checked: value === option.value, onChange: onChange, label: option.label }, option.value)); }) }), error && jsx("span", { className: "text-red-500 text-sm", children: error })] })));
10194
+ var handleSearch = function (e) {
10195
+ var _a;
10196
+ onChange(e);
10197
+ (_a = field === null || field === void 0 ? void 0 : field.onSearch) === null || _a === void 0 ? void 0 : _a.call(field, { value: e.target.value });
10198
+ };
10199
+ return (jsxs(InputWrapper, __assign({}, field, { error: error, children: [jsx("div", { className: "space-y-2", children: (_b = field.options) === null || _b === void 0 ? void 0 : _b.map(function (option) { return (jsx(RadioOption, { id: "".concat(field.id, "-").concat(option.value), name: field.name, value: option.value, checked: value === option.value, onChange: handleSearch, label: option.label }, option.value)); }) }), error && jsx("span", { className: "text-red-500 text-sm", children: error })] })));
10185
10200
  };
10186
10201
 
10187
10202
  var TextareaInput = function (_a) {
@@ -10208,7 +10223,7 @@ var TextareaInput = function (_a) {
10208
10223
  }
10209
10224
  }
10210
10225
  };
10211
- return (jsx(InputWrapper, { id: finalId || "", label: finalLabel || "", tooltip: finalTooltip, error: error, children: jsxs("div", { className: "space-y-2", children: [jsx(Textarea, { id: finalId, name: finalName, placeholder: finalPlaceholder, value: value, onChange: handleChange, disabled: finalDisabled, required: finalRequired, rows: rows, className: "".concat(className || "", " resize-none bg-white"), color: error ? "failure" : undefined }), jsxs("div", { className: "flex justify-between", children: [jsx("span", { className: " text-sm text-red-500 font-bold", children: error }), jsxs("div", { className: " justify-end text-gray-400 text-sm", children: [charCount, "/", finalMaxLength] })] })] }) }));
10226
+ return (jsx(InputWrapper, { id: finalId || "", label: finalLabel || "", tooltip: finalTooltip, error: error, children: jsxs("div", { className: "space-y-2", children: [jsx(Textarea, { id: finalId, name: finalName, placeholder: finalPlaceholder, value: value || "", onChange: handleChange, disabled: finalDisabled, required: finalRequired, rows: rows, className: "".concat(className || "", " resize-none bg-white"), color: error ? "failure" : undefined }), jsxs("div", { className: "flex justify-between", children: [jsx("span", { className: " text-sm text-red-500 font-bold", children: error }), jsxs("div", { className: " justify-end text-gray-400 text-sm", children: [charCount, "/", finalMaxLength] })] })] }) }));
10212
10227
  };
10213
10228
 
10214
10229
  var CheckboxInput = function (_a) {
@@ -19653,27 +19668,40 @@ var useMiDt = create(function (set) { return ({
19653
19668
  var Common = /** @class */ (function () {
19654
19669
  function Common() {
19655
19670
  }
19671
+ // Función para limpiar acentos de un texto
19672
+ Common.removeAccents = function (text) {
19673
+ return text
19674
+ .normalize("NFD")
19675
+ .replace(/[\u0300-\u036f]/g, "")
19676
+ .toLowerCase();
19677
+ };
19656
19678
  // Función para obtener región por nombre
19657
19679
  Common.getRegionByName = function (regionName, regiones) {
19680
+ var _this = this;
19681
+ var _a;
19658
19682
  if (!regiones || !Array.isArray(regiones))
19659
19683
  return null;
19684
+ var cleanRegionName = this.removeAccents(regionName);
19660
19685
  var region = regiones.find(function (r) {
19661
- var _a, _b;
19662
- return ((_a = r.nombre) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(regionName.toLowerCase())) ||
19663
- regionName.toLowerCase().includes((_b = r.nombre) === null || _b === void 0 ? void 0 : _b.toLowerCase());
19686
+ var cleanRegionNombre = _this.removeAccents(r.Nombre || "");
19687
+ return (cleanRegionNombre.includes(cleanRegionName) ||
19688
+ cleanRegionName.includes(cleanRegionNombre));
19664
19689
  });
19665
- return region ? region.id : null;
19690
+ return (_a = region === null || region === void 0 ? void 0 : region.Codigo) !== null && _a !== void 0 ? _a : null;
19666
19691
  };
19667
19692
  // Función para obtener comuna por nombre
19668
19693
  Common.getComunaByName = function (comunaName, comunas) {
19694
+ var _this = this;
19695
+ var _a;
19669
19696
  if (!comunas || !Array.isArray(comunas))
19670
19697
  return null;
19698
+ var cleanComunaName = this.removeAccents(comunaName);
19671
19699
  var comuna = comunas.find(function (c) {
19672
- var _a, _b;
19673
- return ((_a = c.nombre) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(comunaName.toLowerCase())) ||
19674
- comunaName.toLowerCase().includes((_b = c.nombre) === null || _b === void 0 ? void 0 : _b.toLowerCase());
19700
+ var cleanComunaNombre = _this.removeAccents(c.Nombre || "");
19701
+ return (cleanComunaNombre.includes(cleanComunaName) ||
19702
+ cleanComunaName.includes(cleanComunaNombre));
19675
19703
  });
19676
- return comuna ? comuna.id : null;
19704
+ return (_a = comuna === null || comuna === void 0 ? void 0 : comuna.Codigo) !== null && _a !== void 0 ? _a : null;
19677
19705
  };
19678
19706
  // Función para obtener región por ID de comuna
19679
19707
  Common.getRegionIdByComunaId = function (comunaId, comunas) {
@@ -19723,7 +19751,7 @@ var AddressInput = function (_a) {
19723
19751
  localStorage.setItem("lastLocation", JSON.stringify(newLocation));
19724
19752
  var addressComponents = extractAddressComponents(place, newLocation);
19725
19753
  if (onSearch) {
19726
- onSearch(__assign(__assign({}, addressComponents), { address: place.formatted_address }));
19754
+ onSearch(__assign(__assign({}, addressComponents), { value: place.formatted_address }));
19727
19755
  }
19728
19756
  }
19729
19757
  }
@@ -19761,7 +19789,7 @@ var AddressInput = function (_a) {
19761
19789
  if (address) {
19762
19790
  addressComponents = extractAddressComponents(address, newLocation);
19763
19791
  if (onSearch) {
19764
- onSearch(__assign(__assign({}, addressComponents), { address: address.formatted_address }));
19792
+ onSearch(__assign(__assign({}, addressComponents), { value: address.formatted_address }));
19765
19793
  }
19766
19794
  }
19767
19795
  return [3 /*break*/, 4];
@@ -19798,7 +19826,7 @@ var AddressInput = function (_a) {
19798
19826
  if (response.results[0]) {
19799
19827
  addressComponents = extractAddressComponents(response.results[0], newLocation);
19800
19828
  if (onSearch) {
19801
- onSearch(__assign(__assign({}, addressComponents), { address: response.results[0].formatted_address }));
19829
+ onSearch(__assign(__assign({}, addressComponents), { value: response.results[0].formatted_address }));
19802
19830
  }
19803
19831
  }
19804
19832
  return [3 /*break*/, 4];
@@ -19885,7 +19913,7 @@ var GoogleMaps = function (_a) {
19885
19913
  };
19886
19914
 
19887
19915
  var SubtitleInput = function (_a) {
19888
- var title = _a.title, description = _a.description, _b = _a.className, className = _b === void 0 ? "" : _b, _c = _a.textClassName, textClassName = _c === void 0 ? "pl-5 text-[24px] text-text text-xl font-bold font-roboto" : _c;
19916
+ var title = _a.title, description = _a.description, _b = _a.className, className = _b === void 0 ? "" : _b, _c = _a.textClassName, textClassName = _c === void 0 ? "pl-5 pb-2 text-[24px] text-text text-xl font-bold font-roboto" : _c;
19889
19917
  return (jsxs("div", { className: "col-span-12 ".concat(className), children: [title && jsx("h3", { className: textClassName, children: title }), description && jsx("p", { className: "text-gray-600 mb-4", children: description }), jsx("hr", { className: "border-gray-300 mb-4" })] }));
19890
19918
  };
19891
19919
 
@@ -19988,8 +20016,148 @@ var Typography = function (_a) {
19988
20016
  return (jsx("div", { className: (_b = props === null || props === void 0 ? void 0 : props.className) !== null && _b !== void 0 ? _b : "text-sm text font-medium", children: label }));
19989
20017
  };
19990
20018
 
20019
+ var Checklist = function (_a) {
20020
+ var field = _a.field, _b = _a.value, value = _b === void 0 ? [] : _b, onChange = _a.onChange, error = _a.error, props = _a.props;
20021
+ var _c = useState(value), selectedOptions = _c[0], setSelectedOptions = _c[1];
20022
+ var _d = useState(props.valueOtraMedida), otraMedida = _d[0], setOtraMedida = _d[1];
20023
+ var options = field.options || [];
20024
+ useEffect(function () {
20025
+ setSelectedOptions(value);
20026
+ }, [value]);
20027
+ var handleOptionChange = function (optionValue, checked) {
20028
+ var newSelectedOptions;
20029
+ if (checked) {
20030
+ // Validaciones específicas para separación de espacios vs total
20031
+ if (optionValue === "separacion-espacios" &&
20032
+ selectedOptions.includes("separacion-total")) {
20033
+ // Si selecciona separación de espacios, remover separación total
20034
+ newSelectedOptions = selectedOptions.filter(function (opt) { return opt !== "separacion-total"; });
20035
+ }
20036
+ else if (optionValue === "separacion-total" &&
20037
+ selectedOptions.includes("separacion-espacios")) {
20038
+ // Si selecciona separación total, remover separación de espacios
20039
+ newSelectedOptions = selectedOptions.filter(function (opt) { return opt !== "separacion-espacios"; });
20040
+ }
20041
+ else {
20042
+ newSelectedOptions = __spreadArray(__spreadArray([], selectedOptions, true), [optionValue], false);
20043
+ }
20044
+ }
20045
+ else {
20046
+ newSelectedOptions = selectedOptions.filter(function (opt) { return opt !== optionValue; });
20047
+ }
20048
+ setSelectedOptions(newSelectedOptions);
20049
+ onChange === null || onChange === void 0 ? void 0 : onChange(newSelectedOptions);
20050
+ };
20051
+ var handleOtraMedidaChange = function (text) {
20052
+ var _a;
20053
+ setOtraMedida(text);
20054
+ // Actualizar el valor con la otra medida
20055
+ var updatedOptions = selectedOptions.filter(function (opt) { return opt !== "otra-medida"; });
20056
+ if (text.trim()) {
20057
+ updatedOptions.push("otra-medida");
20058
+ }
20059
+ onChange === null || onChange === void 0 ? void 0 : onChange(updatedOptions);
20060
+ (_a = props.onOtraMedidaChange) === null || _a === void 0 ? void 0 : _a.call(props, text);
20061
+ };
20062
+ var isOtraMedidaRequired = selectedOptions.includes("otra-medida");
20063
+ return (jsxs("div", { className: "space-y-4", children: [jsx("div", { className: "space-y-2", children: options.map(function (option) { return (jsxs("div", { className: "flex items-center gap-2", children: [jsx("input", { type: "checkbox", checked: selectedOptions.includes(option.value), onChange: function (e) {
20064
+ return handleOptionChange(option.value, e.target.checked);
20065
+ }, className: "w-4 h-4 text-orange-600 border-gray-800 rounded focus:ring-orange-500 bg-white border-2" }), jsx("label", { className: "font-normal text-text font-roboto font-normal font-weight-400 text-sm leading-4 text-gray-600", children: option.label })] }, option.value)); }) }), isOtraMedidaRequired && (jsx("div", { className: "mt-4", children: jsx("input", { type: "text", value: otraMedida, onChange: function (e) { return handleOtraMedidaChange(e.target.value); }, placeholder: "-", maxLength: 100, className: "w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500" }) })), error && jsx("div", { className: "text-red-600 text-sm mt-2", children: error })] }));
20066
+ };
20067
+
20068
+ var Upload = function (_a) {
20069
+ _a.field; var value = _a.value, onChange = _a.onChange, error = _a.error;
20070
+ var _b = useState({
20071
+ file: value || null,
20072
+ error: null,
20073
+ isDragOver: false,
20074
+ }), state = _b[0], setState = _b[1];
20075
+ var fileInputRef = useRef(null);
20076
+ var dropZoneRef = useRef(null);
20077
+ var validateFile = function (file) {
20078
+ // Validar formato PDF
20079
+ if (file.type !== "application/pdf") {
20080
+ return "Formato no es PDF";
20081
+ }
20082
+ // Validar tamaño máximo (5MB = 5 * 1024 * 1024 bytes)
20083
+ var maxSize = 5 * 1024 * 1024;
20084
+ if (file.size > maxSize) {
20085
+ return "Archivo supera los 5MB";
20086
+ }
20087
+ return null;
20088
+ };
20089
+ var handleFileSelect = useCallback(function (file) {
20090
+ var validationError = validateFile(file);
20091
+ if (validationError) {
20092
+ setState(function (prev) { return (__assign(__assign({}, prev), { file: null, error: validationError })); });
20093
+ onChange === null || onChange === void 0 ? void 0 : onChange(null);
20094
+ }
20095
+ else {
20096
+ setState(function (prev) { return (__assign(__assign({}, prev), { file: file, error: null })); });
20097
+ onChange === null || onChange === void 0 ? void 0 : onChange(file);
20098
+ }
20099
+ }, [onChange]);
20100
+ var handleFileInputChange = function (event) {
20101
+ var _a;
20102
+ var file = (_a = event.target.files) === null || _a === void 0 ? void 0 : _a[0];
20103
+ if (file) {
20104
+ handleFileSelect(file);
20105
+ }
20106
+ };
20107
+ var handleDrop = useCallback(function (event) {
20108
+ event.preventDefault();
20109
+ setState(function (prev) { return (__assign(__assign({}, prev), { isDragOver: false })); });
20110
+ var file = event.dataTransfer.files[0];
20111
+ if (file) {
20112
+ handleFileSelect(file);
20113
+ }
20114
+ }, [handleFileSelect]);
20115
+ var handleDragOver = useCallback(function (event) {
20116
+ event.preventDefault();
20117
+ setState(function (prev) { return (__assign(__assign({}, prev), { isDragOver: true })); });
20118
+ }, []);
20119
+ var handleDragLeave = useCallback(function (event) {
20120
+ event.preventDefault();
20121
+ setState(function (prev) { return (__assign(__assign({}, prev), { isDragOver: false })); });
20122
+ }, []);
20123
+ var handleRemoveFile = function () {
20124
+ setState(function (prev) { return (__assign(__assign({}, prev), { file: null, error: null })); });
20125
+ onChange === null || onChange === void 0 ? void 0 : onChange(null);
20126
+ if (fileInputRef.current) {
20127
+ fileInputRef.current.value = "";
20128
+ }
20129
+ };
20130
+ var handleUploadClick = function () {
20131
+ var _a;
20132
+ (_a = fileInputRef.current) === null || _a === void 0 ? void 0 : _a.click();
20133
+ };
20134
+ var formatFileSize = function (bytes) {
20135
+ if (bytes === 0)
20136
+ return "0 Bytes";
20137
+ var k = 1024;
20138
+ var sizes = ["Bytes", "KB", "MB", "GB"];
20139
+ var i = Math.floor(Math.log(bytes) / Math.log(k));
20140
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
20141
+ };
20142
+ var renderUploadZone = function () {
20143
+ var hasError = state.error || error;
20144
+ var isErrorState = hasError && !state.file;
20145
+ return (jsxs("div", { ref: dropZoneRef, className: "\n relative border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors\n ".concat(isErrorState
20146
+ ? "border-red-500 bg-red-50"
20147
+ : state.isDragOver
20148
+ ? "border-blue-500 bg-blue-50"
20149
+ : "border-gray-300 hover:border-gray-400", "\n "), onDrop: handleDrop, onDragOver: handleDragOver, onDragLeave: handleDragLeave, onClick: handleUploadClick, children: [jsx("input", { ref: fileInputRef, type: "file", accept: ".pdf", onChange: handleFileInputChange, className: "hidden" }), jsx("div", { className: "\n w-20 h-12 mx-auto mb-4 rounded-lg flex items-center justify-center\n ".concat(isErrorState ? "bg-red-500" : "bg-blue", "\n "), children: jsx("svg", { width: "25", height: "25", viewBox: "0 0 25 25", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: jsx("path", { d: "M18.5 15.5005V18.5005H6.5V15.5005H4.5V18.5005C4.5 19.6005 5.4 20.5005 6.5 20.5005H18.5C19.6 20.5005 20.5 19.6005 20.5 18.5005V15.5005H18.5ZM7.5 9.50049L8.91 10.9105L11.5 8.33049V16.5005H13.5V8.33049L16.09 10.9105L17.5 9.50049L12.5 4.50049L7.5 9.50049Z", fill: "white" }) }) }), jsx("h3", { className: "\n text-lg font-semibold mb-2\n ".concat(isErrorState ? "text-red-600" : "text-gray-700", "\n "), children: isErrorState ? "Error" : "Sube tu archivo" }), jsx("p", { className: "\n text-sm\n ".concat(isErrorState ? "text-red-500" : "text-gray-500", "\n "), children: isErrorState ? state.error : "Formato PDF y máximo 5MB" })] }));
20150
+ };
20151
+ var renderFilePreview = function () {
20152
+ if (!state.file)
20153
+ return null;
20154
+ return (jsx("div", { className: "bg-white border border-gray-200 rounded-lg p-4 shadow-sm", children: jsxs("div", { className: "flex items-center justify-between", children: [jsxs("div", { className: "flex items-center space-x-3", children: [jsx("div", { className: "w-10 h-10 bg-blue-100 rounded-lg flex items-center justify-center", children: jsx("svg", { className: "w-6 h-6 text-blue-600", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" }) }) }), jsxs("div", { children: [jsx("p", { className: "text-sm font-medium text-gray-900", children: state.file.name }), jsx("p", { className: "text-xs text-gray-500", children: formatFileSize(state.file.size) })] })] }), jsxs("button", { onClick: handleRemoveFile, className: "px-3 py-1 bg-red-500 text-white text-sm rounded hover:bg-red-600 transition-colors flex items-center space-x-1", children: [jsx("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" }) }), jsx("span", { children: "Eliminar" })] })] }) }));
20155
+ };
20156
+ return (jsxs("div", { className: "space-y-4", children: [state.file ? renderFilePreview() : renderUploadZone(), error && !state.error && jsx("p", { className: "text-sm text-red-600", children: error })] }));
20157
+ };
20158
+
19991
20159
  var DynamicInput = function (_a) {
19992
- var field = _a.field, value = _a.value, onChange = _a.onChange, error = _a.error;
20160
+ var field = _a.field, value = _a.value, onChange = _a.onChange, error = _a.error, formData = _a.formData;
19993
20161
  switch (field.type) {
19994
20162
  case "status":
19995
20163
  return (jsx(StatusScreen, __assign({}, field, { title: field.props.title, message: field.props.message, type: field.props.type, leftButton: field.props.leftButton, rightButton: field.props.rightButton })));
@@ -20009,6 +20177,39 @@ var DynamicInput = function (_a) {
20009
20177
  return jsx(Typography, __assign({}, field));
20010
20178
  case "checkbox":
20011
20179
  return (jsx(CheckboxInput, { field: field, value: value, onChange: onChange, error: error }));
20180
+ case "checklist":
20181
+ return (jsx(Checklist, { field: field, value: value, onChange: function (newValue) {
20182
+ // Convertir el array de strings a un evento de cambio
20183
+ var event = {
20184
+ target: {
20185
+ name: field.name,
20186
+ value: newValue,
20187
+ },
20188
+ };
20189
+ onChange(event);
20190
+ }, error: error, props: {
20191
+ valueOtraMedida: formData["otraMedida"] || "",
20192
+ onOtraMedidaChange: function (text) {
20193
+ var event = {
20194
+ target: {
20195
+ name: "otraMedida",
20196
+ value: text,
20197
+ },
20198
+ };
20199
+ onChange(event);
20200
+ },
20201
+ } }));
20202
+ case "upload":
20203
+ return (jsx(Upload, { field: field, value: value, onChange: function (file) {
20204
+ // Convertir el archivo a un evento de cambio
20205
+ var event = {
20206
+ target: {
20207
+ name: field.name,
20208
+ value: file,
20209
+ },
20210
+ };
20211
+ onChange(event);
20212
+ }, error: error }));
20012
20213
  case "rut":
20013
20214
  return (jsx(RutInput, { field: field, value: value, onChange: onChange, error: error, onSearch: field.onSearch, disabled: field.disabled, placeholder: field.placeholder, minLength: field.minLength, maxLength: field.maxLength }));
20014
20215
  case "address":
@@ -21409,6 +21610,23 @@ for (const method of ['validate', 'validateSync']) Schema.prototype[`${method}At
21409
21610
  for (const alias of ['equals', 'is']) Schema.prototype[alias] = Schema.prototype.oneOf;
21410
21611
  for (const alias of ['not', 'nope']) Schema.prototype[alias] = Schema.prototype.notOneOf;
21411
21612
 
21613
+ const returnsTrue = () => true;
21614
+ function create$8(spec) {
21615
+ return new MixedSchema(spec);
21616
+ }
21617
+ class MixedSchema extends Schema {
21618
+ constructor(spec) {
21619
+ super(typeof spec === 'function' ? {
21620
+ type: 'mixed',
21621
+ check: spec
21622
+ } : Object.assign({
21623
+ type: 'mixed',
21624
+ check: returnsTrue
21625
+ }, spec));
21626
+ }
21627
+ }
21628
+ create$8.prototype = MixedSchema.prototype;
21629
+
21412
21630
  /**
21413
21631
  * This file is a modified version of the file from the following repository:
21414
21632
  * Date.parse with progressive enhancement for ISO 8601 <https://github.com/csnover/js-iso8601>
@@ -22153,6 +22371,189 @@ class ObjectSchema extends Schema {
22153
22371
  }
22154
22372
  create$3.prototype = ObjectSchema.prototype;
22155
22373
 
22374
+ function create$2(type) {
22375
+ return new ArraySchema(type);
22376
+ }
22377
+ class ArraySchema extends Schema {
22378
+ constructor(type) {
22379
+ super({
22380
+ type: 'array',
22381
+ spec: {
22382
+ types: type
22383
+ },
22384
+ check(v) {
22385
+ return Array.isArray(v);
22386
+ }
22387
+ });
22388
+
22389
+ // `undefined` specifically means uninitialized, as opposed to "no subtype"
22390
+ this.innerType = void 0;
22391
+ this.innerType = type;
22392
+ }
22393
+ _cast(_value, _opts) {
22394
+ const value = super._cast(_value, _opts);
22395
+
22396
+ // should ignore nulls here
22397
+ if (!this._typeCheck(value) || !this.innerType) {
22398
+ return value;
22399
+ }
22400
+ let isChanged = false;
22401
+ const castArray = value.map((v, idx) => {
22402
+ const castElement = this.innerType.cast(v, Object.assign({}, _opts, {
22403
+ path: `${_opts.path || ''}[${idx}]`
22404
+ }));
22405
+ if (castElement !== v) {
22406
+ isChanged = true;
22407
+ }
22408
+ return castElement;
22409
+ });
22410
+ return isChanged ? castArray : value;
22411
+ }
22412
+ _validate(_value, options = {}, panic, next) {
22413
+ var _options$recursive;
22414
+ // let sync = options.sync;
22415
+ // let path = options.path;
22416
+ let innerType = this.innerType;
22417
+ // let endEarly = options.abortEarly ?? this.spec.abortEarly;
22418
+ let recursive = (_options$recursive = options.recursive) != null ? _options$recursive : this.spec.recursive;
22419
+ options.originalValue != null ? options.originalValue : _value;
22420
+ super._validate(_value, options, panic, (arrayErrors, value) => {
22421
+ var _options$originalValu2;
22422
+ if (!recursive || !innerType || !this._typeCheck(value)) {
22423
+ next(arrayErrors, value);
22424
+ return;
22425
+ }
22426
+
22427
+ // #950 Ensure that sparse array empty slots are validated
22428
+ let tests = new Array(value.length);
22429
+ for (let index = 0; index < value.length; index++) {
22430
+ var _options$originalValu;
22431
+ tests[index] = innerType.asNestedTest({
22432
+ options,
22433
+ index,
22434
+ parent: value,
22435
+ parentPath: options.path,
22436
+ originalParent: (_options$originalValu = options.originalValue) != null ? _options$originalValu : _value
22437
+ });
22438
+ }
22439
+ this.runTests({
22440
+ value,
22441
+ tests,
22442
+ originalValue: (_options$originalValu2 = options.originalValue) != null ? _options$originalValu2 : _value,
22443
+ options
22444
+ }, panic, innerTypeErrors => next(innerTypeErrors.concat(arrayErrors), value));
22445
+ });
22446
+ }
22447
+ clone(spec) {
22448
+ const next = super.clone(spec);
22449
+ // @ts-expect-error readonly
22450
+ next.innerType = this.innerType;
22451
+ return next;
22452
+ }
22453
+
22454
+ /** Parse an input JSON string to an object */
22455
+ json() {
22456
+ return this.transform(parseJson);
22457
+ }
22458
+ concat(schema) {
22459
+ let next = super.concat(schema);
22460
+
22461
+ // @ts-expect-error readonly
22462
+ next.innerType = this.innerType;
22463
+ if (schema.innerType)
22464
+ // @ts-expect-error readonly
22465
+ next.innerType = next.innerType ?
22466
+ // @ts-expect-error Lazy doesn't have concat and will break
22467
+ next.innerType.concat(schema.innerType) : schema.innerType;
22468
+ return next;
22469
+ }
22470
+ of(schema) {
22471
+ // FIXME: this should return a new instance of array without the default to be
22472
+ let next = this.clone();
22473
+ if (!isSchema(schema)) throw new TypeError('`array.of()` sub-schema must be a valid yup schema not: ' + printValue(schema));
22474
+
22475
+ // @ts-expect-error readonly
22476
+ next.innerType = schema;
22477
+ next.spec = Object.assign({}, next.spec, {
22478
+ types: schema
22479
+ });
22480
+ return next;
22481
+ }
22482
+ length(length, message = array.length) {
22483
+ return this.test({
22484
+ message,
22485
+ name: 'length',
22486
+ exclusive: true,
22487
+ params: {
22488
+ length
22489
+ },
22490
+ skipAbsent: true,
22491
+ test(value) {
22492
+ return value.length === this.resolve(length);
22493
+ }
22494
+ });
22495
+ }
22496
+ min(min, message) {
22497
+ message = message || array.min;
22498
+ return this.test({
22499
+ message,
22500
+ name: 'min',
22501
+ exclusive: true,
22502
+ params: {
22503
+ min
22504
+ },
22505
+ skipAbsent: true,
22506
+ // FIXME(ts): Array<typeof T>
22507
+ test(value) {
22508
+ return value.length >= this.resolve(min);
22509
+ }
22510
+ });
22511
+ }
22512
+ max(max, message) {
22513
+ message = message || array.max;
22514
+ return this.test({
22515
+ message,
22516
+ name: 'max',
22517
+ exclusive: true,
22518
+ params: {
22519
+ max
22520
+ },
22521
+ skipAbsent: true,
22522
+ test(value) {
22523
+ return value.length <= this.resolve(max);
22524
+ }
22525
+ });
22526
+ }
22527
+ ensure() {
22528
+ return this.default(() => []).transform((val, original) => {
22529
+ // We don't want to return `null` for nullable schema
22530
+ if (this._typeCheck(val)) return val;
22531
+ return original == null ? [] : [].concat(original);
22532
+ });
22533
+ }
22534
+ compact(rejector) {
22535
+ let reject = !rejector ? v => !!v : (v, i, a) => !rejector(v, i, a);
22536
+ return this.transform(values => values != null ? values.filter(reject) : values);
22537
+ }
22538
+ describe(options) {
22539
+ const next = (options ? this.resolve(options) : this).clone();
22540
+ const base = super.describe(options);
22541
+ if (next.innerType) {
22542
+ var _innerOptions;
22543
+ let innerOptions = options;
22544
+ if ((_innerOptions = innerOptions) != null && _innerOptions.value) {
22545
+ innerOptions = Object.assign({}, innerOptions, {
22546
+ parent: innerOptions.value,
22547
+ value: innerOptions.value[0]
22548
+ });
22549
+ }
22550
+ base.innerType = next.innerType.describe(innerOptions);
22551
+ }
22552
+ return base;
22553
+ }
22554
+ }
22555
+ create$2.prototype = ArraySchema.prototype;
22556
+
22156
22557
  var createValidationSchema = function (fields) {
22157
22558
  var schema = {};
22158
22559
  // Filtrar campos válidos antes de procesarlos
@@ -22170,7 +22571,20 @@ var createValidationSchema = function (fields) {
22170
22571
  });
22171
22572
  validFields.forEach(function (field) {
22172
22573
  if (field.validations && field.validations.length > 0) {
22173
- var fieldSchema_1 = create$6();
22574
+ // Determinar el tipo de esquema basado en el tipo de campo
22575
+ var fieldSchema_1;
22576
+ switch (field.type) {
22577
+ case "checkbox":
22578
+ case "checklist":
22579
+ fieldSchema_1 = create$2().of(create$6());
22580
+ break;
22581
+ case "upload":
22582
+ fieldSchema_1 = create$8();
22583
+ break;
22584
+ default:
22585
+ fieldSchema_1 = create$6();
22586
+ break;
22587
+ }
22174
22588
  field.validations.forEach(function (validation) {
22175
22589
  switch (validation.type) {
22176
22590
  case "required":
@@ -22220,7 +22634,24 @@ var createValidationSchema = function (fields) {
22220
22634
  }
22221
22635
  else if (field.required) {
22222
22636
  // Validación básica de requerido si no hay validaciones específicas
22223
- schema[field.name] = create$6().required("El campo ".concat(field.label || field.name || "sin nombre", " es requerido"));
22637
+ var requiredSchema = void 0;
22638
+ switch (field.type) {
22639
+ case "checkbox":
22640
+ requiredSchema = create$2().min(1, "El campo ".concat(field.label || field.name || "sin nombre", " es requerido"));
22641
+ break;
22642
+ case "checklist":
22643
+ requiredSchema = create$2()
22644
+ .of(create$6())
22645
+ .min(1, "El campo ".concat(field.label || field.name || "sin nombre", " es requerido"));
22646
+ break;
22647
+ case "upload":
22648
+ requiredSchema = create$8().required("El campo ".concat(field.label || field.name || "sin nombre", " es requerido"));
22649
+ break;
22650
+ default:
22651
+ requiredSchema = create$6().required("El campo ".concat(field.label || field.name || "sin nombre", " es requerido"));
22652
+ break;
22653
+ }
22654
+ schema[field.name] = requiredSchema;
22224
22655
  }
22225
22656
  });
22226
22657
  return create$3().shape(schema);
@@ -22311,12 +22742,13 @@ var GenericForm = function (_a) {
22311
22742
  var _s = useState(getInitialFormData), formData = _s[0], setFormData = _s[1];
22312
22743
  var _t = useState({}), errors = _t[0], setErrors = _t[1];
22313
22744
  useEffect(function () {
22745
+ var _a, _b;
22314
22746
  if (allData) {
22315
22747
  setMiDtData({
22316
22748
  allData: {
22317
22749
  metadata: {
22318
- Regiones: allData.metadata.Regiones,
22319
- Comunas: allData.metadata.Comunas,
22750
+ Regiones: (_a = allData === null || allData === void 0 ? void 0 : allData.metadata) === null || _a === void 0 ? void 0 : _a.Regiones,
22751
+ Comunas: (_b = allData === null || allData === void 0 ? void 0 : allData.metadata) === null || _b === void 0 ? void 0 : _b.Comunas,
22320
22752
  },
22321
22753
  },
22322
22754
  });
@@ -22419,18 +22851,21 @@ var GenericForm = function (_a) {
22419
22851
  }
22420
22852
  };
22421
22853
  var renderField = function (field) {
22422
- var _a, _b, _c, _d;
22854
+ var _a, _b, _c;
22423
22855
  // Prioridad: field.value > formData > getFieldValue
22424
22856
  var fieldValue = (_b = (_a = formData[field.name]) !== null && _a !== void 0 ? _a : field.value) !== null && _b !== void 0 ? _b : getFieldValue(field);
22425
22857
  // Preparar el campo con las funciones de búsqueda si están disponibles
22426
- var fieldWithHandlers = __assign(__assign({}, field), { onSearch: function (value) {
22427
- var _a;
22858
+ var fieldWithHandlers = __assign(__assign({}, field), { onSearch: function (_a) {
22859
+ var searchField = _a.field, value = _a.value, searchFormData = _a.formData;
22428
22860
  if (field.onSearch) {
22429
- (_a = config.onSearch) === null || _a === void 0 ? void 0 : _a.call(config, field, value, __assign(__assign({}, stepperData), formData));
22861
+ field.onSearch({
22862
+ field: searchField || field,
22863
+ value: value,
22864
+ formData: searchFormData || __assign(__assign({}, stepperData), formData),
22865
+ });
22430
22866
  }
22431
22867
  } });
22432
- console.log(field, field.className, (_c = field.className) !== null && _c !== void 0 ? _c : "col-span-12 md:col-span-6");
22433
- return (jsx("div", { className: (_d = field.className) !== null && _d !== void 0 ? _d : "col-span-12 md:col-span-6", children: jsx(DynamicInput, { field: fieldWithHandlers, value: fieldValue, onChange: handleInputChange, error: errors[field.name] }) }, field.id));
22868
+ return (jsx("div", { className: (_c = field.className) !== null && _c !== void 0 ? _c : "col-span-12 md:col-span-6", children: jsx(DynamicInput, { field: fieldWithHandlers, value: fieldValue, onChange: handleInputChange, error: errors[field.name], formData: formData }) }, field.id));
22434
22869
  };
22435
22870
  var buttonHandlers = {
22436
22871
  handleBack: handleBack,
@@ -22451,7 +22886,9 @@ var GenericForm = function (_a) {
22451
22886
  if (loading) {
22452
22887
  return (jsxs("div", { className: "min-h-[550px] flex flex-col justify-between gap-10 ".concat(className), children: [jsxs("div", { className: "flex flex-col gap-10", children: [jsxs("div", { id: "title", children: [jsx("div", { className: "h-8 bg-gray-200 rounded animate-pulse w-3/4 mb-2" }), jsx("div", { className: "w-full h-[3px] bg-gray-200 rounded-full animate-pulse" })] }), jsxs("div", { className: "text-gray-500 text-lg font-normal flex flex-col gap-2", children: [jsx("div", { className: "h-6 bg-gray-200 rounded animate-pulse w-1/2 ml-5" }), jsx("div", { className: "w-full h-[1px] bg-gray-200 animate-pulse" })] }), jsx("div", { children: jsx("div", { className: "flex max-w-1xl mx-auto flex-col gap-4", children: jsx("div", { className: "grid grid-cols-12 gap-4", children: (_b = config === null || config === void 0 ? void 0 : config.fields) === null || _b === void 0 ? void 0 : _b.map(function (field) { return (jsxs("div", { className: "col-span-12 md:col-span-6", children: [jsx("div", { className: "h-4 bg-gray-200 rounded animate-pulse w-1/3 mb-2" }), jsx("div", { className: "h-10 bg-gray-200 rounded animate-pulse w-full" })] }, field.id)); }) }) }) })] }), jsxs("div", { className: "flex justify-between", children: [jsxs("div", { className: "flex gap-2", children: [jsx("div", { className: "h-10 bg-gray-200 rounded animate-pulse w-20" }), jsx("div", { className: "h-10 bg-gray-200 rounded animate-pulse w-20" })] }), jsx("div", { className: "h-10 bg-gray-200 rounded animate-pulse w-24" })] })] }));
22453
22888
  }
22454
- var formContent = (jsxs("div", { className: "min-h-[550px] flex flex-col justify-between gap-10 ".concat(className), children: [jsxs("div", { className: "flex flex-col gap-10", children: [config.title ? (jsxs("div", { id: "title", children: [jsx("h1", { className: "text-text text-3xl font-bold font-roboto", children: config.title }), jsx("div", { className: "w-full h-[3px] bg-orange-500 rounded-full mt-2" })] })) : null, (config === null || config === void 0 ? void 0 : config.steps) && (jsx(FormStepper, { steps: (_c = config === null || config === void 0 ? void 0 : config.steps) === null || _c === void 0 ? void 0 : _c.obj, activeStep: (_d = config === null || config === void 0 ? void 0 : config.steps) === null || _d === void 0 ? void 0 : _d.activeStep, completedSteps: (_e = config === null || config === void 0 ? void 0 : config.steps) === null || _e === void 0 ? void 0 : _e.completedSteps, changeActiveStep: (_f = config === null || config === void 0 ? void 0 : config.steps) === null || _f === void 0 ? void 0 : _f.changeActiveStep })), (config === null || config === void 0 ? void 0 : config.subtitle) && (jsx(Fragment$1, { children: jsxs("div", { className: "text-gray-500 text-lg font-normal flex flex-col gap-2", children: [jsx("h3", { className: "pl-5 text-[24px] text-text text-xl font-bold font-roboto", children: config.subtitle }), jsx("hr", { className: "w-full border-gray-400" })] }) })), config.showInfoAlert && config.infoMessage && (jsx(Alert, { type: (_g = config.infoMessage.type) !== null && _g !== void 0 ? _g : "info", text: config.infoMessage.message })), jsx("div", { children: jsx("form", { className: "flex max-w-1xl mx-auto flex-col gap-4", children: jsx("div", { className: "grid grid-cols-12 gap-4", children: config.fields.map(renderField) }) }) })] }), ((_h = config === null || config === void 0 ? void 0 : config.navigation) === null || _h === void 0 ? void 0 : _h.buttons) && (jsx("div", { className: (_k = (_j = config.navigation) === null || _j === void 0 ? void 0 : _j.containerClass) !== null && _k !== void 0 ? _k : "flex justify-between", children: (_m = (_l = config === null || config === void 0 ? void 0 : config.navigation) === null || _l === void 0 ? void 0 : _l.buttons) === null || _m === void 0 ? void 0 : _m.map(function (btn, index) {
22889
+ var formContent = (jsxs("div", { className: "min-h-[550px] flex flex-col justify-between gap-10 ".concat(className), children: [jsxs("div", { className: "flex flex-col gap-10", children: [config.title ? (jsxs("div", { id: "title", children: [jsx("h1", { className: "text-text text-3xl font-bold font-roboto", children: config.title }), jsx("div", { className: config.titleClassName
22890
+ ? config.titleClassName
22891
+ : "w-full h-[3px] bg-orange-500 rounded-full mt-2" })] })) : null, (config === null || config === void 0 ? void 0 : config.steps) && (jsx(FormStepper, { steps: (_c = config === null || config === void 0 ? void 0 : config.steps) === null || _c === void 0 ? void 0 : _c.obj, activeStep: (_d = config === null || config === void 0 ? void 0 : config.steps) === null || _d === void 0 ? void 0 : _d.activeStep, completedSteps: (_e = config === null || config === void 0 ? void 0 : config.steps) === null || _e === void 0 ? void 0 : _e.completedSteps, changeActiveStep: (_f = config === null || config === void 0 ? void 0 : config.steps) === null || _f === void 0 ? void 0 : _f.changeActiveStep })), (config === null || config === void 0 ? void 0 : config.subtitle) && (jsx(Fragment$1, { children: jsxs("div", { className: "text-gray-500 text-lg font-normal flex flex-col gap-2", children: [jsx("h3", { className: "pl-5 text-[24px] text-text text-xl font-bold font-roboto", children: config.subtitle }), jsx("hr", { className: "w-full border-gray-400" })] }) })), config.showInfoAlert && config.infoMessage && (jsx(Alert, { type: (_g = config.infoMessage.type) !== null && _g !== void 0 ? _g : "info", text: config.infoMessage.message })), jsx("div", { children: jsx("form", { className: "flex max-w-1xl mx-auto flex-col gap-4", children: jsx("div", { className: "grid grid-cols-12 gap-4", children: config.fields.map(renderField) }) }) })] }), ((_h = config === null || config === void 0 ? void 0 : config.navigation) === null || _h === void 0 ? void 0 : _h.buttons) && (jsx("div", { className: (_k = (_j = config.navigation) === null || _j === void 0 ? void 0 : _j.containerClass) !== null && _k !== void 0 ? _k : "flex justify-between", children: (_m = (_l = config === null || config === void 0 ? void 0 : config.navigation) === null || _l === void 0 ? void 0 : _l.buttons) === null || _m === void 0 ? void 0 : _m.map(function (btn, index) {
22455
22892
  var _a;
22456
22893
  return btn.show ? (jsx("div", { className: (_a = btn.className) !== null && _a !== void 0 ? _a : "", children: jsx(NavigationButton, { direction: btn.direction, onClick: buttonHandlers[btn.onClick], disabled: isButtonDisabled(btn), label: btn.label }) }, index)) : null;
22457
22894
  }) }))] }));