@visiion/forms-library 1.4.8 → 1.4.9

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.
@@ -9,6 +9,7 @@ interface SwornDeclarationProps {
9
9
  disabled?: boolean;
10
10
  className?: string;
11
11
  error?: string;
12
+ value?: boolean;
12
13
  }
13
14
  declare const SwornDeclaration: React.FC<SwornDeclarationProps>;
14
15
  export default SwornDeclaration;
package/dist/index.esm.js CHANGED
@@ -10329,9 +10329,14 @@ function maskRut(rut) {
10329
10329
 
10330
10330
  var RutInput = function (_a) {
10331
10331
  var field = _a.field, value = _a.value, onChange = _a.onChange, error = _a.error, onSearch = _a.onSearch, _b = _a.disabled, disabled = _b === void 0 ? false : _b, _c = _a.placeholder, placeholder = _c === void 0 ? "0.000.000-0" : _c, _d = _a.minLength, minLength = _d === void 0 ? 12 : _d, _e = _a.maxLength, maxLength = _e === void 0 ? 12 : _e;
10332
+ console.log(value);
10333
+ // crear variable que si value tiene -error-no-empleador sea true
10334
+ var errorEmpleador = value.includes("-error-no-empleador") ? true : false;
10335
+ //sacar el -error-no-empleador de value
10336
+ var valueWithoutError = value.replace("-error-no-empleador", "");
10332
10337
  var inputRef = useRef(null);
10333
10338
  var _f = useState(false), isValidRut = _f[0], setIsValidRut = _f[1];
10334
- var _g = useState(clean(value)), displayValue = _g[0], setDisplayValue = _g[1];
10339
+ var _g = useState(errorEmpleador ? valueWithoutError : clean(value)), displayValue = _g[0], setDisplayValue = _g[1];
10335
10340
  useEffect(function () {
10336
10341
  setIsValidRut(validate(clean(value)));
10337
10342
  setDisplayValue(formatRut(clean(value)));
@@ -10355,7 +10360,7 @@ var RutInput = function (_a) {
10355
10360
  onSearch({ value: clean(displayValue) });
10356
10361
  }
10357
10362
  };
10358
- return (jsxs("div", { className: "flex flex-col gap-1", children: [jsx("label", { htmlFor: field.id, className: "font-medium text-gray-700", children: field.label }), jsxs("div", { className: "flex", children: [jsx("input", { ref: inputRef, id: field.id, name: field.name, type: "text", value: displayValue || "", onChange: handleRutChange, onKeyDown: handleKeyDown, placeholder: placeholder, minLength: minLength, maxLength: maxLength, disabled: disabled, className: "flex-1 px-3 py-2 border rounded-l-md focus:outline-none focus:ring-2 focus:ring-orange-500 h-10 ".concat(error ? "border-red-500" : "border-gray-300", " ").concat(disabled ? "bg-gray-100 cursor-not-allowed" : "") }), onSearch && (jsx(Button, { type: "button", color: "blue", className: "flex items-center justify-center w-10 h-10 rounded-none rounded-tr-md rounded-br-md border-l-0", onClick: handleSearch, disabled: !isValidRut || disabled, children: jsx(IoMdSearch, { className: "w-5 h-5" }) }))] }), error && jsx("span", { className: "text-red-500 text-sm", children: error }), displayValue && !error && (jsx("span", { className: "text-sm ".concat(isValidRut ? "text-green-600" : "text-orange-600"), children: isValidRut ? "✓ RUT válido" : "⚠ Verificar formato del RUT" }))] }));
10363
+ return (jsxs("div", { className: "flex flex-col gap-1", children: [jsx("label", { htmlFor: field.id, className: "font-medium text-gray-700", children: field.label }), jsxs("div", { className: "flex", children: [jsx("input", { ref: inputRef, id: field.id, name: field.name, type: "text", value: displayValue || "", onChange: handleRutChange, onKeyDown: handleKeyDown, placeholder: placeholder, minLength: minLength, maxLength: maxLength, disabled: disabled, className: "flex-1 px-3 py-2 border rounded-l-md focus:outline-none focus:ring-2 focus:ring-orange-500 h-10 ".concat(error ? "border-red-500" : "border-gray-300", " ").concat(disabled ? "bg-gray-100 cursor-not-allowed" : "") }), onSearch && (jsx(Button, { type: "button", color: "blue", className: "flex items-center justify-center w-10 h-10 rounded-none rounded-tr-md rounded-br-md border-l-0", onClick: handleSearch, disabled: !isValidRut || disabled, children: jsx(IoMdSearch, { className: "w-5 h-5" }) }))] }), errorEmpleador && (jsx("span", { className: "text-red-500 text-sm", children: "El RUT ingresado no corresponde al RUT de una entidad empleadora" })), error && jsx("span", { className: "text-red-500 text-sm", children: error }), !errorEmpleador && displayValue && !error && !disabled && (jsx("span", { className: "text-sm ".concat(isValidRut ? "text-green-600" : "text-orange-600"), children: isValidRut ? "✓ RUT válido" : "⚠ Verificar formato del RUT" }))] }));
10359
10364
  };
10360
10365
 
10361
10366
  function _typeof(o) {
@@ -19963,8 +19968,9 @@ var DatePicker = function (_a) {
19963
19968
  };
19964
19969
 
19965
19970
  var SwornDeclaration = function (_a) {
19966
- var _b = _a.title, title = _b === void 0 ? "Declaración Jurada" : _b, _c = _a.name, name = _c === void 0 ? "sworn_declaration" : _c, _d = _a.declarationText, declarationText = _d === void 0 ? "Declaro bajo juramento ante la Dirección del Trabajo, que los antecedentes entregados son verídicos y que corresponden a la realidad. De ser falsa la presente declaración me hará incurrir en las penas establecidas en el artículo 210 del Código Penal." : _d, _e = _a.checked, checked = _e === void 0 ? false : _e, onChange = _a.onChange, _f = _a.required, required = _f === void 0 ? true : _f, _g = _a.disabled, disabled = _g === void 0 ? false : _g, _h = _a.className, className = _h === void 0 ? "" : _h, error = _a.error;
19967
- var _j = useState(checked), isChecked = _j[0], setIsChecked = _j[1];
19971
+ var _b = _a.title, title = _b === void 0 ? "Declaración Jurada" : _b, _c = _a.name, name = _c === void 0 ? "sworn_declaration" : _c, _d = _a.declarationText, declarationText = _d === void 0 ? "Declaro bajo juramento ante la Dirección del Trabajo, que los antecedentes entregados son verídicos y que corresponden a la realidad. De ser falsa la presente declaración me hará incurrir en las penas establecidas en el artículo 210 del Código Penal." : _d, _e = _a.value, value = _e === void 0 ? false : _e, onChange = _a.onChange, _f = _a.required, required = _f === void 0 ? true : _f, _g = _a.disabled, disabled = _g === void 0 ? false : _g, _h = _a.className, className = _h === void 0 ? "" : _h, error = _a.error;
19972
+ console.log("value", value);
19973
+ var _j = useState(value || false), isChecked = _j[0], setIsChecked = _j[1];
19968
19974
  var handleCheckboxChange = function (e) {
19969
19975
  var newChecked = e.target.checked;
19970
19976
  setIsChecked(newChecked);
@@ -20108,8 +20114,25 @@ var Upload = function (_a) {
20108
20114
  onChange === null || onChange === void 0 ? void 0 : onChange(null);
20109
20115
  }
20110
20116
  else {
20111
- setState(function (prev) { return (__assign(__assign({}, prev), { file: file, error: null })); });
20112
- onChange === null || onChange === void 0 ? void 0 : onChange(file);
20117
+ if (file) {
20118
+ var reader = new FileReader();
20119
+ reader.onload = function (e) {
20120
+ var _a;
20121
+ var base64 = (_a = e.target) === null || _a === void 0 ? void 0 : _a.result;
20122
+ var lastDotIndex = file.name.lastIndexOf(".");
20123
+ var extension = lastDotIndex === -1 ? "" : file.name.substring(lastDotIndex + 1);
20124
+ var fileData = {
20125
+ name: (file === null || file === void 0 ? void 0 : file.name) || "",
20126
+ size: (file === null || file === void 0 ? void 0 : file.size) || 0,
20127
+ extension: (file === null || file === void 0 ? void 0 : file.name.split(".").pop()) || "pdf",
20128
+ base64: base64.split(",")[1], // Remove data:application/pdf;base64, prefix
20129
+ extensionId: extension ? ".".concat(extension) : ".pdf",
20130
+ };
20131
+ setState(function (prev) { return (__assign(__assign({}, prev), { file: file, error: null })); });
20132
+ onChange === null || onChange === void 0 ? void 0 : onChange(fileData);
20133
+ };
20134
+ reader.readAsDataURL(file);
20135
+ }
20113
20136
  }
20114
20137
  }, [onChange]);
20115
20138
  var handleFileInputChange = function (event) {
@@ -20146,14 +20169,6 @@ var Upload = function (_a) {
20146
20169
  var _a;
20147
20170
  (_a = fileInputRef.current) === null || _a === void 0 ? void 0 : _a.click();
20148
20171
  };
20149
- var formatFileSize = function (bytes) {
20150
- if (bytes === 0)
20151
- return "0 Bytes";
20152
- var k = 1024;
20153
- var sizes = ["Bytes", "KB", "MB", "GB"];
20154
- var i = Math.floor(Math.log(bytes) / Math.log(k));
20155
- return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
20156
- };
20157
20172
  var renderUploadZone = function () {
20158
20173
  var hasError = state.error || error;
20159
20174
  var isErrorState = hasError && !state.file;
@@ -20166,7 +20181,7 @@ var Upload = function (_a) {
20166
20181
  var renderFilePreview = function () {
20167
20182
  if (!state.file)
20168
20183
  return null;
20169
- 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" })] })] }) }));
20184
+ return (jsx("div", { className: "bg-white border border-gray-300 rounded-lg p-4", children: jsxs("div", { className: "flex flex-col items-center space-y-3", children: [jsx("div", { className: "w-16 h-16 rounded-lg flex items-center justify-center", children: jsx("svg", { width: "53", height: "52", viewBox: "0 0 53 52", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: jsx("path", { d: "M30.8337 4.33398H13.5003C11.117 4.33398 9.16699 6.28398 9.16699 8.66732V43.334C9.16699 45.7173 11.117 47.6673 13.5003 47.6673H39.5003C41.8837 47.6673 43.8337 45.7173 43.8337 43.334V17.334L30.8337 4.33398ZM39.5003 43.334H13.5003V8.66732H30.8337V17.334H39.5003V43.334ZM26.5003 36.834C24.117 36.834 22.167 34.884 22.167 32.5007V20.584C22.167 19.9773 22.6437 19.5007 23.2503 19.5007C23.857 19.5007 24.3337 19.9773 24.3337 20.584V32.5007H28.667V20.584C28.667 17.594 26.2403 15.1673 23.2503 15.1673C20.2603 15.1673 17.8337 17.594 17.8337 20.584V32.5007C17.8337 37.289 21.712 41.1673 26.5003 41.1673C31.2887 41.1673 35.167 37.289 35.167 32.5007V23.834H30.8337V32.5007C30.8337 34.884 28.8837 36.834 26.5003 36.834Z", fill: "#0F69B4" }) }) }), jsx("p", { className: "text-sm font-medium text-gray-700 text-center", children: state.file.name }), jsxs("button", { type: "button", onClick: handleRemoveFile, style: { backgroundColor: "#0F69B4" }, className: "px-4 py-2 bg-blue-500 text-white text-sm rounded-lg hover:bg-blue-600 transition-colors flex items-center space-x-2", 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" })] })] }) }));
20170
20185
  };
20171
20186
  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 })] }));
20172
20187
  };
@@ -20184,7 +20199,7 @@ var DynamicInput = function (_a) {
20184
20199
  case "date":
20185
20200
  return (jsx(DatePicker, __assign({}, field, { id: field.id, label: field.label, error: error, value: value, onChange: onChange })));
20186
20201
  case "declaration":
20187
- return (jsx(SwornDeclaration, __assign({}, field, { onChange: onChange, error: error })));
20202
+ return (jsx(SwornDeclaration, __assign({}, field, { value: value, onChange: onChange, error: error })));
20188
20203
  case "subtitle":
20189
20204
  return jsx(SubtitleInput, __assign({}, field.props));
20190
20205
  case "textarea":
@@ -21767,6 +21782,81 @@ class MixedSchema extends Schema {
21767
21782
  }
21768
21783
  create$8.prototype = MixedSchema.prototype;
21769
21784
 
21785
+ function create$7() {
21786
+ return new BooleanSchema();
21787
+ }
21788
+ class BooleanSchema extends Schema {
21789
+ constructor() {
21790
+ super({
21791
+ type: 'boolean',
21792
+ check(v) {
21793
+ if (v instanceof Boolean) v = v.valueOf();
21794
+ return typeof v === 'boolean';
21795
+ }
21796
+ });
21797
+ this.withMutation(() => {
21798
+ this.transform((value, _raw, ctx) => {
21799
+ if (ctx.spec.coerce && !ctx.isType(value)) {
21800
+ if (/^(true|1)$/i.test(String(value))) return true;
21801
+ if (/^(false|0)$/i.test(String(value))) return false;
21802
+ }
21803
+ return value;
21804
+ });
21805
+ });
21806
+ }
21807
+ isTrue(message = boolean.isValue) {
21808
+ return this.test({
21809
+ message,
21810
+ name: 'is-value',
21811
+ exclusive: true,
21812
+ params: {
21813
+ value: 'true'
21814
+ },
21815
+ test(value) {
21816
+ return isAbsent(value) || value === true;
21817
+ }
21818
+ });
21819
+ }
21820
+ isFalse(message = boolean.isValue) {
21821
+ return this.test({
21822
+ message,
21823
+ name: 'is-value',
21824
+ exclusive: true,
21825
+ params: {
21826
+ value: 'false'
21827
+ },
21828
+ test(value) {
21829
+ return isAbsent(value) || value === false;
21830
+ }
21831
+ });
21832
+ }
21833
+ default(def) {
21834
+ return super.default(def);
21835
+ }
21836
+ defined(msg) {
21837
+ return super.defined(msg);
21838
+ }
21839
+ optional() {
21840
+ return super.optional();
21841
+ }
21842
+ required(msg) {
21843
+ return super.required(msg);
21844
+ }
21845
+ notRequired() {
21846
+ return super.notRequired();
21847
+ }
21848
+ nullable() {
21849
+ return super.nullable();
21850
+ }
21851
+ nonNullable(msg) {
21852
+ return super.nonNullable(msg);
21853
+ }
21854
+ strip(v) {
21855
+ return super.strip(v);
21856
+ }
21857
+ }
21858
+ create$7.prototype = BooleanSchema.prototype;
21859
+
21770
21860
  /**
21771
21861
  * This file is a modified version of the file from the following repository:
21772
21862
  * Date.parse with progressive enhancement for ISO 8601 <https://github.com/csnover/js-iso8601>
@@ -22721,6 +22811,9 @@ var createValidationSchema = function (fields) {
22721
22811
  .min(1, field.validations[0].params[0] ||
22722
22812
  "El campo ".concat(field.label || field.name || "sin nombre", " es requerido"));
22723
22813
  break;
22814
+ case "declaration":
22815
+ fieldSchema_1 = create$7();
22816
+ break;
22724
22817
  case "upload":
22725
22818
  fieldSchema_1 = create$8();
22726
22819
  break;
@@ -22800,6 +22893,9 @@ var createValidationSchema = function (fields) {
22800
22893
  case "checkbox":
22801
22894
  requiredSchema = create$2().min(1, "El campo ".concat(field.label || field.name || "sin nombre", " es requerido"));
22802
22895
  break;
22896
+ case "declaration":
22897
+ requiredSchema = create$7().oneOf([true], "El campo ".concat(field.label || field.name || "sin nombre", " es requerido"));
22898
+ break;
22803
22899
  case "checklist":
22804
22900
  requiredSchema = create$2()
22805
22901
  .of(create$6())
package/dist/index.js CHANGED
@@ -10348,9 +10348,14 @@ function maskRut(rut) {
10348
10348
 
10349
10349
  var RutInput = function (_a) {
10350
10350
  var field = _a.field, value = _a.value, onChange = _a.onChange, error = _a.error, onSearch = _a.onSearch, _b = _a.disabled, disabled = _b === void 0 ? false : _b, _c = _a.placeholder, placeholder = _c === void 0 ? "0.000.000-0" : _c, _d = _a.minLength, minLength = _d === void 0 ? 12 : _d, _e = _a.maxLength, maxLength = _e === void 0 ? 12 : _e;
10351
+ console.log(value);
10352
+ // crear variable que si value tiene -error-no-empleador sea true
10353
+ var errorEmpleador = value.includes("-error-no-empleador") ? true : false;
10354
+ //sacar el -error-no-empleador de value
10355
+ var valueWithoutError = value.replace("-error-no-empleador", "");
10351
10356
  var inputRef = React.useRef(null);
10352
10357
  var _f = React.useState(false), isValidRut = _f[0], setIsValidRut = _f[1];
10353
- var _g = React.useState(clean(value)), displayValue = _g[0], setDisplayValue = _g[1];
10358
+ var _g = React.useState(errorEmpleador ? valueWithoutError : clean(value)), displayValue = _g[0], setDisplayValue = _g[1];
10354
10359
  React.useEffect(function () {
10355
10360
  setIsValidRut(validate(clean(value)));
10356
10361
  setDisplayValue(formatRut(clean(value)));
@@ -10374,7 +10379,7 @@ var RutInput = function (_a) {
10374
10379
  onSearch({ value: clean(displayValue) });
10375
10380
  }
10376
10381
  };
10377
- return (jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [jsxRuntime.jsx("label", { htmlFor: field.id, className: "font-medium text-gray-700", children: field.label }), jsxRuntime.jsxs("div", { className: "flex", children: [jsxRuntime.jsx("input", { ref: inputRef, id: field.id, name: field.name, type: "text", value: displayValue || "", onChange: handleRutChange, onKeyDown: handleKeyDown, placeholder: placeholder, minLength: minLength, maxLength: maxLength, disabled: disabled, className: "flex-1 px-3 py-2 border rounded-l-md focus:outline-none focus:ring-2 focus:ring-orange-500 h-10 ".concat(error ? "border-red-500" : "border-gray-300", " ").concat(disabled ? "bg-gray-100 cursor-not-allowed" : "") }), onSearch && (jsxRuntime.jsx(flowbiteReact.Button, { type: "button", color: "blue", className: "flex items-center justify-center w-10 h-10 rounded-none rounded-tr-md rounded-br-md border-l-0", onClick: handleSearch, disabled: !isValidRut || disabled, children: jsxRuntime.jsx(IoMdSearch, { className: "w-5 h-5" }) }))] }), error && jsxRuntime.jsx("span", { className: "text-red-500 text-sm", children: error }), displayValue && !error && (jsxRuntime.jsx("span", { className: "text-sm ".concat(isValidRut ? "text-green-600" : "text-orange-600"), children: isValidRut ? "✓ RUT válido" : "⚠ Verificar formato del RUT" }))] }));
10382
+ return (jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [jsxRuntime.jsx("label", { htmlFor: field.id, className: "font-medium text-gray-700", children: field.label }), jsxRuntime.jsxs("div", { className: "flex", children: [jsxRuntime.jsx("input", { ref: inputRef, id: field.id, name: field.name, type: "text", value: displayValue || "", onChange: handleRutChange, onKeyDown: handleKeyDown, placeholder: placeholder, minLength: minLength, maxLength: maxLength, disabled: disabled, className: "flex-1 px-3 py-2 border rounded-l-md focus:outline-none focus:ring-2 focus:ring-orange-500 h-10 ".concat(error ? "border-red-500" : "border-gray-300", " ").concat(disabled ? "bg-gray-100 cursor-not-allowed" : "") }), onSearch && (jsxRuntime.jsx(flowbiteReact.Button, { type: "button", color: "blue", className: "flex items-center justify-center w-10 h-10 rounded-none rounded-tr-md rounded-br-md border-l-0", onClick: handleSearch, disabled: !isValidRut || disabled, children: jsxRuntime.jsx(IoMdSearch, { className: "w-5 h-5" }) }))] }), errorEmpleador && (jsxRuntime.jsx("span", { className: "text-red-500 text-sm", children: "El RUT ingresado no corresponde al RUT de una entidad empleadora" })), error && jsxRuntime.jsx("span", { className: "text-red-500 text-sm", children: error }), !errorEmpleador && displayValue && !error && !disabled && (jsxRuntime.jsx("span", { className: "text-sm ".concat(isValidRut ? "text-green-600" : "text-orange-600"), children: isValidRut ? "✓ RUT válido" : "⚠ Verificar formato del RUT" }))] }));
10378
10383
  };
10379
10384
 
10380
10385
  function _typeof(o) {
@@ -19982,8 +19987,9 @@ var DatePicker = function (_a) {
19982
19987
  };
19983
19988
 
19984
19989
  var SwornDeclaration = function (_a) {
19985
- var _b = _a.title, title = _b === void 0 ? "Declaración Jurada" : _b, _c = _a.name, name = _c === void 0 ? "sworn_declaration" : _c, _d = _a.declarationText, declarationText = _d === void 0 ? "Declaro bajo juramento ante la Dirección del Trabajo, que los antecedentes entregados son verídicos y que corresponden a la realidad. De ser falsa la presente declaración me hará incurrir en las penas establecidas en el artículo 210 del Código Penal." : _d, _e = _a.checked, checked = _e === void 0 ? false : _e, onChange = _a.onChange, _f = _a.required, required = _f === void 0 ? true : _f, _g = _a.disabled, disabled = _g === void 0 ? false : _g, _h = _a.className, className = _h === void 0 ? "" : _h, error = _a.error;
19986
- var _j = React.useState(checked), isChecked = _j[0], setIsChecked = _j[1];
19990
+ var _b = _a.title, title = _b === void 0 ? "Declaración Jurada" : _b, _c = _a.name, name = _c === void 0 ? "sworn_declaration" : _c, _d = _a.declarationText, declarationText = _d === void 0 ? "Declaro bajo juramento ante la Dirección del Trabajo, que los antecedentes entregados son verídicos y que corresponden a la realidad. De ser falsa la presente declaración me hará incurrir en las penas establecidas en el artículo 210 del Código Penal." : _d, _e = _a.value, value = _e === void 0 ? false : _e, onChange = _a.onChange, _f = _a.required, required = _f === void 0 ? true : _f, _g = _a.disabled, disabled = _g === void 0 ? false : _g, _h = _a.className, className = _h === void 0 ? "" : _h, error = _a.error;
19991
+ console.log("value", value);
19992
+ var _j = React.useState(value || false), isChecked = _j[0], setIsChecked = _j[1];
19987
19993
  var handleCheckboxChange = function (e) {
19988
19994
  var newChecked = e.target.checked;
19989
19995
  setIsChecked(newChecked);
@@ -20127,8 +20133,25 @@ var Upload = function (_a) {
20127
20133
  onChange === null || onChange === void 0 ? void 0 : onChange(null);
20128
20134
  }
20129
20135
  else {
20130
- setState(function (prev) { return (__assign(__assign({}, prev), { file: file, error: null })); });
20131
- onChange === null || onChange === void 0 ? void 0 : onChange(file);
20136
+ if (file) {
20137
+ var reader = new FileReader();
20138
+ reader.onload = function (e) {
20139
+ var _a;
20140
+ var base64 = (_a = e.target) === null || _a === void 0 ? void 0 : _a.result;
20141
+ var lastDotIndex = file.name.lastIndexOf(".");
20142
+ var extension = lastDotIndex === -1 ? "" : file.name.substring(lastDotIndex + 1);
20143
+ var fileData = {
20144
+ name: (file === null || file === void 0 ? void 0 : file.name) || "",
20145
+ size: (file === null || file === void 0 ? void 0 : file.size) || 0,
20146
+ extension: (file === null || file === void 0 ? void 0 : file.name.split(".").pop()) || "pdf",
20147
+ base64: base64.split(",")[1], // Remove data:application/pdf;base64, prefix
20148
+ extensionId: extension ? ".".concat(extension) : ".pdf",
20149
+ };
20150
+ setState(function (prev) { return (__assign(__assign({}, prev), { file: file, error: null })); });
20151
+ onChange === null || onChange === void 0 ? void 0 : onChange(fileData);
20152
+ };
20153
+ reader.readAsDataURL(file);
20154
+ }
20132
20155
  }
20133
20156
  }, [onChange]);
20134
20157
  var handleFileInputChange = function (event) {
@@ -20165,14 +20188,6 @@ var Upload = function (_a) {
20165
20188
  var _a;
20166
20189
  (_a = fileInputRef.current) === null || _a === void 0 ? void 0 : _a.click();
20167
20190
  };
20168
- var formatFileSize = function (bytes) {
20169
- if (bytes === 0)
20170
- return "0 Bytes";
20171
- var k = 1024;
20172
- var sizes = ["Bytes", "KB", "MB", "GB"];
20173
- var i = Math.floor(Math.log(bytes) / Math.log(k));
20174
- return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
20175
- };
20176
20191
  var renderUploadZone = function () {
20177
20192
  var hasError = state.error || error;
20178
20193
  var isErrorState = hasError && !state.file;
@@ -20185,7 +20200,7 @@ var Upload = function (_a) {
20185
20200
  var renderFilePreview = function () {
20186
20201
  if (!state.file)
20187
20202
  return null;
20188
- return (jsxRuntime.jsx("div", { className: "bg-white border border-gray-200 rounded-lg p-4 shadow-sm", children: jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [jsxRuntime.jsxs("div", { className: "flex items-center space-x-3", children: [jsxRuntime.jsx("div", { className: "w-10 h-10 bg-blue-100 rounded-lg flex items-center justify-center", children: jsxRuntime.jsx("svg", { className: "w-6 h-6 text-blue-600", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: jsxRuntime.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" }) }) }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("p", { className: "text-sm font-medium text-gray-900", children: state.file.name }), jsxRuntime.jsx("p", { className: "text-xs text-gray-500", children: formatFileSize(state.file.size) })] })] }), jsxRuntime.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: [jsxRuntime.jsx("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: jsxRuntime.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" }) }), jsxRuntime.jsx("span", { children: "Eliminar" })] })] }) }));
20203
+ return (jsxRuntime.jsx("div", { className: "bg-white border border-gray-300 rounded-lg p-4", children: jsxRuntime.jsxs("div", { className: "flex flex-col items-center space-y-3", children: [jsxRuntime.jsx("div", { className: "w-16 h-16 rounded-lg flex items-center justify-center", children: jsxRuntime.jsx("svg", { width: "53", height: "52", viewBox: "0 0 53 52", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: jsxRuntime.jsx("path", { d: "M30.8337 4.33398H13.5003C11.117 4.33398 9.16699 6.28398 9.16699 8.66732V43.334C9.16699 45.7173 11.117 47.6673 13.5003 47.6673H39.5003C41.8837 47.6673 43.8337 45.7173 43.8337 43.334V17.334L30.8337 4.33398ZM39.5003 43.334H13.5003V8.66732H30.8337V17.334H39.5003V43.334ZM26.5003 36.834C24.117 36.834 22.167 34.884 22.167 32.5007V20.584C22.167 19.9773 22.6437 19.5007 23.2503 19.5007C23.857 19.5007 24.3337 19.9773 24.3337 20.584V32.5007H28.667V20.584C28.667 17.594 26.2403 15.1673 23.2503 15.1673C20.2603 15.1673 17.8337 17.594 17.8337 20.584V32.5007C17.8337 37.289 21.712 41.1673 26.5003 41.1673C31.2887 41.1673 35.167 37.289 35.167 32.5007V23.834H30.8337V32.5007C30.8337 34.884 28.8837 36.834 26.5003 36.834Z", fill: "#0F69B4" }) }) }), jsxRuntime.jsx("p", { className: "text-sm font-medium text-gray-700 text-center", children: state.file.name }), jsxRuntime.jsxs("button", { type: "button", onClick: handleRemoveFile, style: { backgroundColor: "#0F69B4" }, className: "px-4 py-2 bg-blue-500 text-white text-sm rounded-lg hover:bg-blue-600 transition-colors flex items-center space-x-2", children: [jsxRuntime.jsx("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: jsxRuntime.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" }) }), jsxRuntime.jsx("span", { children: "Eliminar" })] })] }) }));
20189
20204
  };
20190
20205
  return (jsxRuntime.jsxs("div", { className: "space-y-4", children: [state.file ? renderFilePreview() : renderUploadZone(), error && !state.error && jsxRuntime.jsx("p", { className: "text-sm text-red-600", children: error })] }));
20191
20206
  };
@@ -20203,7 +20218,7 @@ var DynamicInput = function (_a) {
20203
20218
  case "date":
20204
20219
  return (jsxRuntime.jsx(DatePicker, __assign({}, field, { id: field.id, label: field.label, error: error, value: value, onChange: onChange })));
20205
20220
  case "declaration":
20206
- return (jsxRuntime.jsx(SwornDeclaration, __assign({}, field, { onChange: onChange, error: error })));
20221
+ return (jsxRuntime.jsx(SwornDeclaration, __assign({}, field, { value: value, onChange: onChange, error: error })));
20207
20222
  case "subtitle":
20208
20223
  return jsxRuntime.jsx(SubtitleInput, __assign({}, field.props));
20209
20224
  case "textarea":
@@ -21786,6 +21801,81 @@ class MixedSchema extends Schema {
21786
21801
  }
21787
21802
  create$8.prototype = MixedSchema.prototype;
21788
21803
 
21804
+ function create$7() {
21805
+ return new BooleanSchema();
21806
+ }
21807
+ class BooleanSchema extends Schema {
21808
+ constructor() {
21809
+ super({
21810
+ type: 'boolean',
21811
+ check(v) {
21812
+ if (v instanceof Boolean) v = v.valueOf();
21813
+ return typeof v === 'boolean';
21814
+ }
21815
+ });
21816
+ this.withMutation(() => {
21817
+ this.transform((value, _raw, ctx) => {
21818
+ if (ctx.spec.coerce && !ctx.isType(value)) {
21819
+ if (/^(true|1)$/i.test(String(value))) return true;
21820
+ if (/^(false|0)$/i.test(String(value))) return false;
21821
+ }
21822
+ return value;
21823
+ });
21824
+ });
21825
+ }
21826
+ isTrue(message = boolean.isValue) {
21827
+ return this.test({
21828
+ message,
21829
+ name: 'is-value',
21830
+ exclusive: true,
21831
+ params: {
21832
+ value: 'true'
21833
+ },
21834
+ test(value) {
21835
+ return isAbsent(value) || value === true;
21836
+ }
21837
+ });
21838
+ }
21839
+ isFalse(message = boolean.isValue) {
21840
+ return this.test({
21841
+ message,
21842
+ name: 'is-value',
21843
+ exclusive: true,
21844
+ params: {
21845
+ value: 'false'
21846
+ },
21847
+ test(value) {
21848
+ return isAbsent(value) || value === false;
21849
+ }
21850
+ });
21851
+ }
21852
+ default(def) {
21853
+ return super.default(def);
21854
+ }
21855
+ defined(msg) {
21856
+ return super.defined(msg);
21857
+ }
21858
+ optional() {
21859
+ return super.optional();
21860
+ }
21861
+ required(msg) {
21862
+ return super.required(msg);
21863
+ }
21864
+ notRequired() {
21865
+ return super.notRequired();
21866
+ }
21867
+ nullable() {
21868
+ return super.nullable();
21869
+ }
21870
+ nonNullable(msg) {
21871
+ return super.nonNullable(msg);
21872
+ }
21873
+ strip(v) {
21874
+ return super.strip(v);
21875
+ }
21876
+ }
21877
+ create$7.prototype = BooleanSchema.prototype;
21878
+
21789
21879
  /**
21790
21880
  * This file is a modified version of the file from the following repository:
21791
21881
  * Date.parse with progressive enhancement for ISO 8601 <https://github.com/csnover/js-iso8601>
@@ -22740,6 +22830,9 @@ var createValidationSchema = function (fields) {
22740
22830
  .min(1, field.validations[0].params[0] ||
22741
22831
  "El campo ".concat(field.label || field.name || "sin nombre", " es requerido"));
22742
22832
  break;
22833
+ case "declaration":
22834
+ fieldSchema_1 = create$7();
22835
+ break;
22743
22836
  case "upload":
22744
22837
  fieldSchema_1 = create$8();
22745
22838
  break;
@@ -22819,6 +22912,9 @@ var createValidationSchema = function (fields) {
22819
22912
  case "checkbox":
22820
22913
  requiredSchema = create$2().min(1, "El campo ".concat(field.label || field.name || "sin nombre", " es requerido"));
22821
22914
  break;
22915
+ case "declaration":
22916
+ requiredSchema = create$7().oneOf([true], "El campo ".concat(field.label || field.name || "sin nombre", " es requerido"));
22917
+ break;
22822
22918
  case "checklist":
22823
22919
  requiredSchema = create$2()
22824
22920
  .of(create$6())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visiion/forms-library",
3
- "version": "1.4.8",
3
+ "version": "1.4.9",
4
4
  "description": "Librería de componentes de formularios reutilizables",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",