@grafosoft/excel-validator 1.0.7 → 1.0.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.
package/README.md CHANGED
@@ -121,7 +121,7 @@ const jsonValidator = [
121
121
  type: "string-empty",
122
122
  url: "api/v1/codesystem/accounts",
123
123
  prop: "code",
124
- validation: "string(20)",
124
+ validation: "code(20)",
125
125
  },
126
126
  "string(255)",
127
127
  "$string(30)",
@@ -242,7 +242,7 @@ const jsonValidator = [
242
242
  type: "string-empty",
243
243
  url: "api/v1/codesystem/contacts",
244
244
  prop: "code",
245
- validation: "string(20)",
245
+ validation: "code(20)",
246
246
  },
247
247
  "$string(255)",
248
248
  "$string(50)",
@@ -284,7 +284,7 @@ const jsonValidator = [
284
284
  prop: "id",
285
285
  },
286
286
  "$string(6)",
287
- "int",
287
+ "bool",
288
288
  {
289
289
  type: "fetch",
290
290
  url: "api/v1/valueset/taxTypes",
@@ -298,7 +298,7 @@ const jsonValidator = [
298
298
  ```ts
299
299
  const jsonValidator = [
300
300
  "int",
301
- "string(20)",
301
+ "code(20)",
302
302
  {
303
303
  type: "fetch",
304
304
  url: "api/v1/valueset/identificationTypes",
@@ -28,7 +28,7 @@ const ExcelFile = ({ initData, fileContent, matrix, error, onFileSelected, onRes
28
28
  }
29
29
  return (bytes / KB).toFixed(2) + " KB";
30
30
  };
31
- return ((0, jsx_runtime_1.jsxs)("section", { className: "h-full bg-content1 p-4 border-r border-default-200", children: [(0, jsx_runtime_1.jsxs)("h2", { className: "text-xl font-semibold text-default-700", children: ["Importa ", initData.title] }), error ? ((0, jsx_runtime_1.jsx)(react_1.Alert, { color: "danger", title: error, className: "mt-3", radius: "sm", hideIconWrapper: true })) : isVisible ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_1.Alert, { radius: "sm", hideIconWrapper: true, hideIcon: true, isVisible: isVisible, className: "mt-4", variant: "bordered", onClose: handleReset, children: (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-2 text-default-700", children: [(0, jsx_runtime_1.jsx)(tb_1.TbFile, { size: 28 }), " ", (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col", children: [(0, jsx_runtime_1.jsx)("p", { className: "text-sm", children: fileContent === null || fileContent === void 0 ? void 0 : fileContent.name }), (0, jsx_runtime_1.jsx)("small", { className: "text-default-500", children: bytesFormat((_a = fileContent === null || fileContent === void 0 ? void 0 : fileContent.size) !== null && _a !== void 0 ? _a : 0) })] })] }) }), initData.type === "accounts" && ((0, jsx_runtime_1.jsxs)("div", { className: "mt-4 space-y-2 flex md:flex-col gap-5 md:gap-0", children: [(0, jsx_runtime_1.jsx)(react_1.Button, { className: "w-full border-1", color: "warning", variant: "bordered", radius: "sm", startContent: (0, jsx_runtime_1.jsx)(tb_1.TbFilter, { size: 18 }), onPress: onApplyStringEmptyFilter, isDisabled: !hasStringEmptyDuplicateErrors || isStringEmptyFilterApplied, children: isStringEmptyFilterApplied
31
+ return ((0, jsx_runtime_1.jsxs)("section", { className: "h-full bg-content1 p-4 border-none md:border-l border-default-200", children: [(0, jsx_runtime_1.jsxs)("h2", { className: "text-xl font-semibold text-default-700", children: ["Importa ", initData.title] }), error ? ((0, jsx_runtime_1.jsx)(react_1.Alert, { color: "danger", title: error, className: "mt-3", radius: "sm", hideIconWrapper: true })) : isVisible ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_1.Alert, { radius: "sm", hideIconWrapper: true, hideIcon: true, isVisible: isVisible, className: "mt-4", variant: "bordered", onClose: handleReset, children: (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-2 text-default-700", children: [(0, jsx_runtime_1.jsx)(tb_1.TbFile, { size: 28 }), " ", (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col", children: [(0, jsx_runtime_1.jsx)("p", { className: "text-sm", children: fileContent === null || fileContent === void 0 ? void 0 : fileContent.name }), (0, jsx_runtime_1.jsx)("small", { className: "text-default-500", children: bytesFormat((_a = fileContent === null || fileContent === void 0 ? void 0 : fileContent.size) !== null && _a !== void 0 ? _a : 0) })] })] }) }), initData.type === "accounts" && ((0, jsx_runtime_1.jsxs)("div", { className: "mt-4 space-y-2 flex md:flex-col gap-5 md:gap-0", children: [(0, jsx_runtime_1.jsx)(react_1.Button, { className: "w-full border-1", color: "warning", variant: "bordered", radius: "sm", startContent: (0, jsx_runtime_1.jsx)(tb_1.TbFilter, { size: 18 }), onPress: onApplyStringEmptyFilter, isDisabled: !hasStringEmptyDuplicateErrors || isStringEmptyFilterApplied, children: isStringEmptyFilterApplied
32
32
  ? "Filtro aplicado"
33
33
  : "Filtrar cuentas ya registradas" }), (0, jsx_runtime_1.jsx)(react_1.Button, { className: "w-full border-1", color: "success", variant: "bordered", radius: "sm", startContent: (0, jsx_runtime_1.jsx)(tb_1.TbDownload, { size: 18 }), onPress: onDownloadFilteredExcel, isDisabled: !isStringEmptyFilterApplied || !hasStringEmptyDuplicateErrors, children: "Descargar Nuevo Excel" })] })), (0, jsx_runtime_1.jsx)(ExcelValidator_1.ExcelValidator, { initData: initData, fileContent: fileContent, matrix: matrix, validationErrors: validationErrors, onSelectError: onSelectError, hasBalanceDifference: hasBalanceDifference })] })) : ((0, jsx_runtime_1.jsx)("label", { className: "mt-4 flex cursor-pointer items-center justify-center rounded-lg border border-dashed border-default-300 px-4 py-8 text-sm font-medium text-default-600 transition hover:border-primary hover:text-primary", htmlFor: "excel-upload", children: (0, jsx_runtime_1.jsxs)("div", { className: "text-center flex flex-col items-center gap-2", children: [(0, jsx_runtime_1.jsx)(tb_1.TbUpload, { size: 28 }), (0, jsx_runtime_1.jsx)("p", { className: "font-semibold text-lg", children: "Seleccionar plantilla" }), (0, jsx_runtime_1.jsx)("small", { className: "text-default-500", children: "Adjunta un archivo .xlsx o .xls para validar y previsualizar." })] }) })), (0, jsx_runtime_1.jsx)("input", { id: "excel-upload", ref: inputRef, className: "hidden", type: "file", accept: ".xlsx,.xls", onChange: (event) => {
34
34
  void onFileSelected(event);
@@ -70,6 +70,9 @@ function ExcelLayout({ initData, jsonValidator, isBalances = false, }) {
70
70
  if (/^string\([^()]+\)$/.test(normalizedRule)) {
71
71
  return false;
72
72
  }
73
+ if (/^code\([^()]+\)$/.test(normalizedRule)) {
74
+ return false;
75
+ }
73
76
  return item.trim().startsWith("$");
74
77
  }
75
78
  const normalizedType = item.type.trim().replace(/^\$/, "").toLowerCase();
@@ -336,6 +339,29 @@ function ExcelLayout({ initData, jsonValidator, isBalances = false, }) {
336
339
  }
337
340
  return validateDateByFormat(trimmedValue, stringRuleArg);
338
341
  }
342
+ const codeRuleMatch = rule.match(/^code\(([^()]+)\)$/);
343
+ if (codeRuleMatch) {
344
+ if (trimmedValue === "") {
345
+ return isOptional
346
+ ? { valid: true, message: "" }
347
+ : { valid: false, message: "Valor vacío" };
348
+ }
349
+ const isAlphanumeric = /^[a-zA-Z0-9]+$/.test(trimmedValue);
350
+ if (!isAlphanumeric) {
351
+ return {
352
+ valid: false,
353
+ message: "Solo se admiten letras y números",
354
+ };
355
+ }
356
+ const maxLength = Number(codeRuleMatch[1].trim());
357
+ const isWithinLength = trimmedValue.length <= maxLength;
358
+ return {
359
+ valid: isWithinLength,
360
+ message: isWithinLength
361
+ ? ""
362
+ : `Longitud máxima permitida: ${maxLength} caracteres`,
363
+ };
364
+ }
339
365
  return { valid: true, message: "" };
340
366
  };
341
367
  const filteredRows = matrix
@@ -549,26 +575,6 @@ function ExcelLayout({ initData, jsonValidator, isBalances = false, }) {
549
575
  });
550
576
  };
551
577
  const mainRef = (0, react_1.useRef)(null);
552
- const [mainHeight, setMainHeight] = (0, react_1.useState)(null);
553
- (0, react_1.useEffect)(() => {
554
- const updateHeight = () => {
555
- if (!mainRef.current) {
556
- return;
557
- }
558
- const { top } = mainRef.current.getBoundingClientRect();
559
- setMainHeight(Math.max(280, Math.floor(window.innerHeight - top - 8)));
560
- };
561
- updateHeight();
562
- window.addEventListener("resize", updateHeight);
563
- const observer = typeof ResizeObserver !== "undefined"
564
- ? new ResizeObserver(updateHeight)
565
- : null;
566
- observer === null || observer === void 0 ? void 0 : observer.observe(document.body);
567
- return () => {
568
- window.removeEventListener("resize", updateHeight);
569
- observer === null || observer === void 0 ? void 0 : observer.disconnect();
570
- };
571
- }, []);
572
578
  const handleReset = () => {
573
579
  setFileContent(undefined);
574
580
  setMatrix([]);
@@ -577,5 +583,5 @@ function ExcelLayout({ initData, jsonValidator, isBalances = false, }) {
577
583
  setFocusTarget(null);
578
584
  setIsStringEmptyFilterApplied(false);
579
585
  };
580
- return ((0, jsx_runtime_1.jsxs)("main", { ref: mainRef, style: mainHeight ? { height: `${mainHeight}px` } : undefined, className: "grid grid-cols-1 grid-rows-2 md:grid-rows-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 overflow-hidden", children: [(0, jsx_runtime_1.jsx)("div", { className: "space-y-4 col-span-1 order-2 ", children: (0, jsx_runtime_1.jsx)(ExcelFile_1.ExcelFile, { initData: initData, fileContent: fileContent, matrix: matrix, error: error, onFileSelected: handleFileSelected, onReset: handleReset, validationErrors: validationErrorsForPanel, onSelectError: handleSelectError, hasBalanceDifference: hasBalanceDifference, onApplyStringEmptyFilter: handleApplyStringEmptyFilter, onDownloadFilteredExcel: handleDownloadFilteredExcel, isStringEmptyFilterApplied: isStringEmptyFilterApplied, hasStringEmptyDuplicateErrors: hasStringEmptyDuplicateErrors }) }), (0, jsx_runtime_1.jsx)("div", { className: "col-span-1 lg:col-span-2 xl:col-span-3", children: (0, jsx_runtime_1.jsx)(ExcelPreview_1.ExcelPreview, { initData: initData, fileContent: fileContent, matrix: matrix, error: error, validationErrors: validationErrors, focusTarget: focusTarget, currentPage: currentPage, onPageChange: setCurrentPage, isBalances: isBalances, hiddenFilteredRowIndexes: isStringEmptyFilterApplied ? stringEmptyDuplicateRowIndexes : [] }) })] }));
586
+ return ((0, jsx_runtime_1.jsxs)("main", { ref: mainRef, className: "grid grid-cols-1 h-full grid-rows-2 md:grid-rows-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 overflow-hidden", children: [(0, jsx_runtime_1.jsx)("div", { className: "space-y-4 col-span-1 order-2 ", children: (0, jsx_runtime_1.jsx)(ExcelFile_1.ExcelFile, { initData: initData, fileContent: fileContent, matrix: matrix, error: error, onFileSelected: handleFileSelected, onReset: handleReset, validationErrors: validationErrorsForPanel, onSelectError: handleSelectError, hasBalanceDifference: hasBalanceDifference, onApplyStringEmptyFilter: handleApplyStringEmptyFilter, onDownloadFilteredExcel: handleDownloadFilteredExcel, isStringEmptyFilterApplied: isStringEmptyFilterApplied, hasStringEmptyDuplicateErrors: hasStringEmptyDuplicateErrors }) }), (0, jsx_runtime_1.jsx)("div", { className: "col-span-1 lg:col-span-2 xl:col-span-3", children: (0, jsx_runtime_1.jsx)(ExcelPreview_1.ExcelPreview, { initData: initData, fileContent: fileContent, matrix: matrix, error: error, validationErrors: validationErrors, focusTarget: focusTarget, currentPage: currentPage, onPageChange: setCurrentPage, isBalances: isBalances, hiddenFilteredRowIndexes: isStringEmptyFilterApplied ? stringEmptyDuplicateRowIndexes : [] }) })] }));
581
587
  }
@@ -57,7 +57,7 @@ const ExcelPreview = ({ initData, fileContent, matrix, error, validationErrors,
57
57
  targetCell.focus();
58
58
  });
59
59
  }, [focusTarget, effectivePage]);
60
- return ((0, jsx_runtime_1.jsxs)("section", { className: "h-full bg-gray-50 dark:bg-content1 border-l border-default-200 px-4 py-2 flex flex-col overflow-hidden", children: [!fileContent ? ((0, jsx_runtime_1.jsx)(react_1.Alert, { color: "primary", title: `Al importar ${initData.title} verás una previsualización de su contenido.`, className: "my-3 max-h-[70px]", radius: "sm", hideIconWrapper: true, variant: "faded" })) : null, fileContent && matrix.length === 0 && !error ? ((0, jsx_runtime_1.jsx)(react_1.Alert, { color: "danger", title: `No se encontraron datos en el archivo seleccionado.`, className: "my-3", radius: "sm", hideIconWrapper: true, variant: "faded" })) : null, fileContent && matrix.length > 0 ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: "mt-4 min-h-0 flex-1 max-w-full overflow-x-auto overflow-y-auto", children: (0, jsx_runtime_1.jsxs)("table", { className: "min-w-max w-full text-sm", children: [(0, jsx_runtime_1.jsx)("thead", { className: "sticky top-0 bg-default-100", children: (0, jsx_runtime_1.jsx)("tr", { children: Array.from({ length: maxColumns }).map((_, columnIndex) => ((0, jsx_runtime_1.jsx)("th", { className: "border-x border-t border-default-200 p-3 font-semibold text-default-700", children: tableHeaders[columnIndex] ||
60
+ return ((0, jsx_runtime_1.jsxs)("section", { className: "h-full border-none md:border-r border-default-200 px-4 py-2 flex flex-col overflow-hidden", children: [!fileContent ? ((0, jsx_runtime_1.jsx)(react_1.Alert, { color: "primary", title: `Al importar ${initData.title} verás una previsualización de su contenido.`, className: "my-3 max-h-[70px]", radius: "sm", hideIconWrapper: true, variant: "faded" })) : null, fileContent && matrix.length === 0 && !error ? ((0, jsx_runtime_1.jsx)(react_1.Alert, { color: "danger", title: `No se encontraron datos en el archivo seleccionado.`, className: "my-3", radius: "sm", hideIconWrapper: true, variant: "faded" })) : null, fileContent && matrix.length > 0 ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: "mt-4 min-h-0 flex-1 max-w-full border-r border-b border-default-200 overflow-x-auto overflow-y-auto", children: (0, jsx_runtime_1.jsxs)("table", { className: "min-w-max w-full text-sm", children: [(0, jsx_runtime_1.jsx)("thead", { className: "sticky top-0 bg-default-100", children: (0, jsx_runtime_1.jsx)("tr", { children: Array.from({ length: maxColumns }).map((_, columnIndex) => ((0, jsx_runtime_1.jsx)("th", { className: "border-x border-t border-default-200 p-3 font-semibold text-default-700", children: tableHeaders[columnIndex] ||
61
61
  `Columna ${columnIndex + 1}` }, `header-${columnIndex}`))) }) }), (0, jsx_runtime_1.jsx)("tbody", { className: "bg-content1", children: dataRows.map((row, rowIndex) => ((0, jsx_runtime_1.jsx)("tr", { children: Array.from({ length: maxColumns }).map((_, columnIndex) => (() => {
62
62
  var _a, _b;
63
63
  const originalFilteredRowIndex = row.originalFilteredRowIndex;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafosoft/excel-validator",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "React component to validate Excel files against configurable JSON rules.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",