@zauru-sdk/components 1.0.116 → 1.0.119

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.
Files changed (104) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/Buttons/Button.d.ts +0 -1
  3. package/dist/HOC/ValidateEmployeeAccess/index.d.ts +1 -1
  4. package/dist/Layouts/errorLayout/index.d.ts +3 -1
  5. package/dist/ProgressBar/ProgressCircle.d.ts +1 -1
  6. package/dist/Zendesk/Chat.d.ts +0 -1
  7. package/dist/esm/Form/SelectField/index.js +2 -2
  8. package/dist/esm/Layouts/errorLayout/index.js +6 -6
  9. package/dist/esm/SidePanel/index.js +1 -1
  10. package/package.json +8 -9
  11. package/src/Form/SelectField/index.tsx +19 -1
  12. package/src/Form/TextField/index.tsx +1 -1
  13. package/src/Layouts/errorLayout/index.tsx +6 -1
  14. package/src/SidePanel/index.tsx +26 -26
  15. package/dist/cjs/Alerts/ErrorBoundaryAlert/ErrorBoundaryAlert.js +0 -9
  16. package/dist/cjs/Alerts/StaticAlert.js +0 -32
  17. package/dist/cjs/Alerts/index.js +0 -18
  18. package/dist/cjs/BlockUI/BlockUI.js +0 -12
  19. package/dist/cjs/BlockUI/index.js +0 -17
  20. package/dist/cjs/Buttons/Button.js +0 -62
  21. package/dist/cjs/Buttons/index.js +0 -17
  22. package/dist/cjs/Card/Card.js +0 -9
  23. package/dist/cjs/Card/index.js +0 -17
  24. package/dist/cjs/Chat/ChatLayout.js +0 -31
  25. package/dist/cjs/Chat/ChatMessageHistory.js +0 -57
  26. package/dist/cjs/Chat/index.js +0 -18
  27. package/dist/cjs/ConnectionState/ConnectionState.js +0 -25
  28. package/dist/cjs/ConnectionState/index.js +0 -17
  29. package/dist/cjs/Containers/BodyContainer.js +0 -9
  30. package/dist/cjs/Containers/ButtonSectionContainer.js +0 -9
  31. package/dist/cjs/Containers/Container.js +0 -10
  32. package/dist/cjs/Containers/DoubleContainer.js +0 -18
  33. package/dist/cjs/Containers/MainContainer.js +0 -9
  34. package/dist/cjs/Containers/OutletContainer.js +0 -9
  35. package/dist/cjs/Containers/SubContainer.js +0 -10
  36. package/dist/cjs/Containers/index.js +0 -23
  37. package/dist/cjs/DynamicTable/BasicPrintDynamicTable.js +0 -31
  38. package/dist/cjs/DynamicTable/DynamicPrintTable.js +0 -158
  39. package/dist/cjs/DynamicTable/DynamicTable.js +0 -219
  40. package/dist/cjs/DynamicTable/GenericDynamicTable.js +0 -200
  41. package/dist/cjs/DynamicTable/index.js +0 -20
  42. package/dist/cjs/Footer/Footer.js +0 -20
  43. package/dist/cjs/Footer/index.js +0 -17
  44. package/dist/cjs/Form/Checkbox/index.js +0 -39
  45. package/dist/cjs/Form/Checklist/index.js +0 -14
  46. package/dist/cjs/Form/DatePicker/index.js +0 -37
  47. package/dist/cjs/Form/DynamicBaculoForm/index.js +0 -144
  48. package/dist/cjs/Form/FieldContainer/DoubleFieldContainer.js +0 -18
  49. package/dist/cjs/Form/FieldContainer/QuadrupleFieldContainer.js +0 -18
  50. package/dist/cjs/Form/FieldContainer/TripleFieldContainer.js +0 -18
  51. package/dist/cjs/Form/FieldContainer/index.js +0 -19
  52. package/dist/cjs/Form/FileUpload/index.js +0 -71
  53. package/dist/cjs/Form/FormButtons/index.js +0 -9
  54. package/dist/cjs/Form/ReactZodForm/index.js +0 -29
  55. package/dist/cjs/Form/SelectField/index.js +0 -176
  56. package/dist/cjs/Form/TextArea/index.js +0 -41
  57. package/dist/cjs/Form/TextField/index.js +0 -73
  58. package/dist/cjs/Form/TimePicker/index.js +0 -38
  59. package/dist/cjs/Form/YesNo/index.js +0 -28
  60. package/dist/cjs/Form/index.js +0 -29
  61. package/dist/cjs/HOC/ValidateEmployeeAccess/index.js +0 -17
  62. package/dist/cjs/Labels/InfoLabel/index.js +0 -9
  63. package/dist/cjs/Labels/index.js +0 -17
  64. package/dist/cjs/Layouts/errorLayout/index.js +0 -14
  65. package/dist/cjs/Layouts/homeLayout/index.js +0 -51
  66. package/dist/cjs/Layouts/index.js +0 -18
  67. package/dist/cjs/LineSeparator/LineSeparator.js +0 -8
  68. package/dist/cjs/LineSeparator/index.js +0 -17
  69. package/dist/cjs/Modal/Modal.js +0 -36
  70. package/dist/cjs/Modal/index.js +0 -17
  71. package/dist/cjs/NavBar/NavBar.js +0 -76
  72. package/dist/cjs/NavBar/NavBar.types.js +0 -2
  73. package/dist/cjs/NavBar/NavBar.utils.js +0 -61
  74. package/dist/cjs/NavBar/index.js +0 -19
  75. package/dist/cjs/ProgressBar/ProgressBar.js +0 -9
  76. package/dist/cjs/ProgressBar/ProgressCircle.js +0 -26
  77. package/dist/cjs/ProgressBar/index.js +0 -18
  78. package/dist/cjs/SidePanel/index.js +0 -48
  79. package/dist/cjs/Skeletons/LoadingInputSkeleton.js +0 -12
  80. package/dist/cjs/Skeletons/index.js +0 -17
  81. package/dist/cjs/Tab/Tab.js +0 -26
  82. package/dist/cjs/Tab/index.js +0 -17
  83. package/dist/cjs/Table/ZauruTable.js +0 -186
  84. package/dist/cjs/Table/index.js +0 -17
  85. package/dist/cjs/TaskList/TaskList.js +0 -40
  86. package/dist/cjs/TaskList/index.js +0 -17
  87. package/dist/cjs/Titles/LabelArray.js +0 -11
  88. package/dist/cjs/Titles/TableColumnTitle.js +0 -9
  89. package/dist/cjs/Titles/TitleH1.js +0 -9
  90. package/dist/cjs/Titles/TitleH2.js +0 -9
  91. package/dist/cjs/Titles/TitleH3.js +0 -9
  92. package/dist/cjs/Titles/index.js +0 -21
  93. package/dist/cjs/Tooltip/Tooltip.js +0 -18
  94. package/dist/cjs/Tooltip/index.js +0 -17
  95. package/dist/cjs/WithTooltip/WithTooltip.js +0 -9
  96. package/dist/cjs/WithTooltip/index.js +0 -17
  97. package/dist/cjs/Wizards/StepWizard.js +0 -18
  98. package/dist/cjs/Wizards/index.js +0 -17
  99. package/dist/cjs/Zendesk/Chat.js +0 -69
  100. package/dist/cjs/Zendesk/index.js +0 -18
  101. package/dist/cjs/Zendesk/zendesk.config.js +0 -29
  102. package/dist/cjs/index.js +0 -43
  103. package/dist/cjs/tailwind.config.js +0 -9
  104. package/tsconfig.cjs.json +0 -8
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConnectionState = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const hooks_1 = require("@zauru-sdk/hooks");
6
- const ConnectionState = () => {
7
- const isOnline = (0, hooks_1.useIsOnline)();
8
- // Definir estilos
9
- const styles = {
10
- container: {
11
- padding: "10px",
12
- borderRadius: "5px",
13
- backgroundColor: isOnline ? "#d4edda" : "#f8d7da",
14
- color: isOnline ? "#155724" : "#721c24",
15
- fontWeight: "bold",
16
- },
17
- text: {
18
- fontSize: "16px",
19
- margin: 0,
20
- },
21
- };
22
- // Renderizar el estado de conexión
23
- return ((0, jsx_runtime_1.jsx)("div", { style: styles.container, children: (0, jsx_runtime_1.jsx)("p", { style: styles.text, children: isOnline ? "ONLINE ✅🌐" : "OFFLINE ❌🌐" }) }));
24
- };
25
- exports.ConnectionState = ConnectionState;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./ConnectionState.js"), exports);
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BodyContainer = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const BodyContainer = (props) => {
6
- const { children } = props;
7
- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)("body", { className: "flex flex-col min-h-screen m-0", children: children }) }));
8
- };
9
- exports.BodyContainer = BodyContainer;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ButtonSectionContainer = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const ButtonSectionContainer = (props) => {
6
- const { children, className, whitBg = true } = props;
7
- return ((0, jsx_runtime_1.jsx)("div", { className: `${whitBg ? "bg-gray-50" : ""} px-4 py-3 text-right sm:px-6 ${className}`, children: children }));
8
- };
9
- exports.ButtonSectionContainer = ButtonSectionContainer;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Container = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const Container = (props) => {
6
- const { title, description, children, className = "", rightContent } = props;
7
- const titleInfo = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [title && ((0, jsx_runtime_1.jsx)("h3", { className: "text-3xl font-bold leading-8 text-gray-900", children: title })), description && ((0, jsx_runtime_1.jsx)("p", { className: "mt-1 text-md text-gray-600", children: description }))] }));
8
- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsxs)("div", { className: `mx-2 ${className}`, children: [rightContent && ((0, jsx_runtime_1.jsxs)("div", { className: "flex justify-between items-center", children: [(0, jsx_runtime_1.jsx)("div", { children: titleInfo }), (0, jsx_runtime_1.jsx)("div", { children: rightContent })] })), !rightContent && titleInfo, (0, jsx_runtime_1.jsx)("div", { className: "mt-5 space-y-5", children: children })] }) }));
9
- };
10
- exports.Container = Container;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DoubleContainer = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const DoubleContainer = (props) => {
6
- const { title, description, className = "", children } = props;
7
- const getChildren = (index) => {
8
- if (children && Array.isArray(children) && children[index]) {
9
- return children[index];
10
- }
11
- if (children && index === 0) {
12
- return children;
13
- }
14
- return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
15
- };
16
- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsxs)("div", { className: `mx-2 ${className}`, children: [title && ((0, jsx_runtime_1.jsx)("h3", { className: "text-3xl font-bold leading-8 text-gray-900", children: title })), description && ((0, jsx_runtime_1.jsx)("p", { className: "mt-1 text-md text-gray-600", children: description })), (0, jsx_runtime_1.jsxs)("div", { className: "grid xl:grid-cols-3 md:grid-cols-1 gap-4", children: [(0, jsx_runtime_1.jsx)("div", { className: "xl:col-span-2 md:col-span-1 mt-5", children: getChildren(0) }), (0, jsx_runtime_1.jsx)("div", { className: "xl:col-span-1 md:col-span-1 mt-5", children: getChildren(1) })] })] }) }));
17
- };
18
- exports.DoubleContainer = DoubleContainer;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MainContainer = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const MainContainer = (props) => {
6
- const { children } = props;
7
- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)("div", { className: "md:p-10 p-0 mt-10 ml-2 mr-2 mb-10 md:mt-0 md:ml-0 md:mr-0 md:mb-0", children: children }) }));
8
- };
9
- exports.MainContainer = MainContainer;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OutletContainer = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const OutletContainer = (props) => {
6
- const { children } = props;
7
- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)("div", { className: "flex-1 overflow-x-auto", children: children }) }));
8
- };
9
- exports.OutletContainer = OutletContainer;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SubContainer = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const SubContainer = (props) => {
6
- const { title, description, children, className = "", rightContent } = props;
7
- const titleInfo = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [title && ((0, jsx_runtime_1.jsx)("h3", { className: "text-xl font-bold leading-8 text-gray-900", children: title })), description && ((0, jsx_runtime_1.jsx)("p", { className: "mt-1 text-md text-gray-600", children: description }))] }));
8
- return ((0, jsx_runtime_1.jsxs)("div", { className: `${className}`, children: [rightContent && ((0, jsx_runtime_1.jsxs)("div", { className: "flex justify-between items-center", children: [(0, jsx_runtime_1.jsx)("div", { children: titleInfo }), (0, jsx_runtime_1.jsx)("div", { children: rightContent })] })), !rightContent && titleInfo, (0, jsx_runtime_1.jsx)("div", { className: "mt-5 space-y-3", children: children })] }));
9
- };
10
- exports.SubContainer = SubContainer;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./BodyContainer.js"), exports);
18
- __exportStar(require("./ButtonSectionContainer.js"), exports);
19
- __exportStar(require("./Container.js"), exports);
20
- __exportStar(require("./DoubleContainer.js"), exports);
21
- __exportStar(require("./MainContainer.js"), exports);
22
- __exportStar(require("./OutletContainer.js"), exports);
23
- __exportStar(require("./SubContainer.js"), exports);
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BasicTableHTML = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const common_1 = require("@zauru-sdk/common");
6
- //TABLA PARA LA IMPRESION:
7
- const BasicTableHTML = (props) => {
8
- const { data, footer, headers } = props;
9
- return ((0, jsx_runtime_1.jsxs)("table", { style: { borderCollapse: "collapse", width: "100%" }, children: [(0, jsx_runtime_1.jsx)("thead", { children: (0, jsx_runtime_1.jsx)("tr", { children: headers?.map((titulo, index) => ((0, jsx_runtime_1.jsx)("th", { style: {
10
- border: "1px solid black",
11
- padding: "10px",
12
- textAlign: "center",
13
- whiteSpace: "normal",
14
- }, children: titulo.label }, index))) }) }), (0, jsx_runtime_1.jsx)("tbody", { children: data?.map((fila, index) => ((0, jsx_runtime_1.jsx)("tr", { children: headers?.map((titulo, index) => ((0, jsx_runtime_1.jsx)("td", { style: {
15
- border: "1px solid black",
16
- padding: "1px",
17
- textAlign: "center",
18
- whiteSpace: "normal",
19
- fontSize: (0, common_1.isNumeric)(fila[titulo.name])
20
- ? "2em"
21
- : "1em",
22
- }, children: fila[titulo.name] }, index))) }, index))) }), (0, jsx_runtime_1.jsx)("tfoot", { children: (0, jsx_runtime_1.jsx)("tr", { children: headers?.map((titulo, index) => ((0, jsx_runtime_1.jsx)("td", { style: {
23
- padding: "10px",
24
- textAlign: "center",
25
- whiteSpace: "normal",
26
- fontSize: (0, common_1.isNumeric)(footer[titulo.name])
27
- ? "2em"
28
- : "1em",
29
- }, children: footer[titulo.name] }, index))) }) })] }));
30
- };
31
- exports.BasicTableHTML = BasicTableHTML;
@@ -1,158 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.DynamicPrintTable = void 0;
27
- const jsx_runtime_1 = require("react/jsx-runtime");
28
- const react_1 = __importStar(require("react"));
29
- const index_js_1 = require("../Form/TextField/index.js");
30
- const index_js_2 = require("../Form/SelectField/index.js");
31
- const redux_1 = require("@zauru-sdk/redux");
32
- const errorAnimation = {
33
- hidden: { opacity: 0, y: -10 },
34
- visible: { opacity: 1, y: 0 },
35
- };
36
- const DynamicPrintTable = ({ forwardedRef, ...props }) => {
37
- const { items, onChange, className } = props;
38
- const { formValidations } = (0, redux_1.useAppSelector)((state) => state.formValidation);
39
- const createItemSelect = (rowIndex, defaultValue) => ((0, jsx_runtime_1.jsx)(index_js_2.SelectField, { name: "item_select", isClearable: true, onChange: (value) => {
40
- const selectedItem = items?.find((x) => x.value === value?.value);
41
- updateRow(rowIndex, selectedItem);
42
- }, options: items, defaultValue: defaultValue }, rowIndex));
43
- const createItemQuantity = (rowIndex, defaultValue) => ((0, jsx_runtime_1.jsx)(index_js_1.TextField, { name: "item_quantity", type: "number", integer: true, defaultValue: defaultValue ?? 1, min: 1, onChange: (value) => {
44
- updateRow(rowIndex, undefined, Number(value));
45
- } }, rowIndex));
46
- const createTemplateName = (rowIndex, defaultValue) => ((0, jsx_runtime_1.jsx)("div", { children: defaultValue != "" ? defaultValue : "No hay etiqueta" }, rowIndex));
47
- const createRow = (rowIndex, item, quantity) => {
48
- const itemCreated = createItemSelect(rowIndex, item ?? undefined);
49
- const quantityCreated = createItemQuantity(rowIndex, quantity ?? 1);
50
- const templateCreated = createTemplateName(rowIndex, item ? item.template : "Seleccione un item para visualizar su etiqueta.");
51
- return [itemCreated, quantityCreated, templateCreated];
52
- };
53
- const [tableData, setTableData] = (0, react_1.useState)([]);
54
- const [isInitialItemAdded, setIsInitialItemAdded] = (0, react_1.useState)(false);
55
- const insertItems = (0, react_1.useCallback)((newItems) => {
56
- setTableData((prevData) => [
57
- ...(prevData ?? []),
58
- ...newItems.map((item, index) => {
59
- const rowIndex = (prevData?.length ?? 0) + index;
60
- const [itemCreated, quantityCreated, templateCreated] = createRow(rowIndex, item);
61
- updateRow(rowIndex, item, 1);
62
- return [itemCreated, quantityCreated, templateCreated];
63
- }),
64
- ]);
65
- }, [items]);
66
- const getTableState = (temp) => {
67
- const updatedData = temp ?? tableData;
68
- const tableState = updatedData?.map((rowData) => {
69
- const firstElement = rowData[0];
70
- const item_id = react_1.default.isValidElement(firstElement)
71
- ? firstElement.props.defaultValue?.value
72
- : undefined;
73
- const secondElement = rowData[1];
74
- const quantity = react_1.default.isValidElement(secondElement)
75
- ? secondElement.props.defaultValue
76
- : undefined;
77
- return {
78
- item_id,
79
- quantity,
80
- };
81
- });
82
- return tableState;
83
- };
84
- const updateRow = (rowIndex, item, quantity) => {
85
- setTableData((prevData) => {
86
- const updatedData = prevData?.map((_, index) => {
87
- if (index === rowIndex) {
88
- const firstElement = prevData[index][0];
89
- const selectedItem = item ??
90
- (react_1.default.isValidElement(firstElement)
91
- ? items?.find((x) => x.value === firstElement.props.defaultValue?.value)
92
- : undefined);
93
- const secondElement = prevData[index][1];
94
- const newQuantity = quantity
95
- ? quantity
96
- : react_1.default.isValidElement(secondElement)
97
- ? secondElement.props.defaultValue
98
- : undefined;
99
- return createRow(rowIndex, selectedItem, newQuantity);
100
- }
101
- else {
102
- return prevData[index];
103
- }
104
- });
105
- if (onChange) {
106
- const tableState = getTableState(updatedData);
107
- onChange(tableState);
108
- }
109
- return updatedData;
110
- });
111
- };
112
- const addRow = () => {
113
- setTableData((prevData) => [
114
- ...(prevData ?? []),
115
- createRow(prevData?.length ?? 0),
116
- ]);
117
- };
118
- const removeRow = (rowIndex) => {
119
- setTableData((prevData) => prevData?.filter((_, index) => index !== rowIndex));
120
- };
121
- react_1.default.useImperativeHandle(forwardedRef, () => ({
122
- insertItems,
123
- getTableState,
124
- }));
125
- const pastelGrayBackground = {
126
- backgroundColor: "#B69E99",
127
- };
128
- const renderHeader = () => ((0, jsx_runtime_1.jsxs)("tr", { style: { ...pastelGrayBackground }, children: [(0, jsx_runtime_1.jsx)("th", { className: "text-left align-middle p-2", children: "Item" }), (0, jsx_runtime_1.jsx)("th", { className: "text-left align-middle p-2", children: "Cantidad" }), (0, jsx_runtime_1.jsx)("th", { className: "text-left align-middle p-2", children: "Etiqueta" }), (0, jsx_runtime_1.jsx)("th", { className: "w-16" })] }));
129
- const renderRow = (rowData, rowIndex) => ((0, jsx_runtime_1.jsxs)("tr", { children: [rowData.map((cellData, cellIndex) => ((0, jsx_runtime_1.jsx)("td", { className: "align-middle p-2", children: cellData }, cellIndex))), rowIndex !== 0 && ((0, jsx_runtime_1.jsx)("td", { className: "align-middle w-16", children: (0, jsx_runtime_1.jsx)("button", { className: "bg-red-500 hover:bg-red-600 font-bold py-1 px-2 rounded ml-2", onClick: (event) => {
130
- event.preventDefault();
131
- event.stopPropagation();
132
- removeRow(rowIndex);
133
- }, type: "button", children: "x" }) }))] }, rowIndex));
134
- const renderRows = () => {
135
- return tableData?.map((rowData, rowIndex) => renderRow(rowData, rowIndex));
136
- };
137
- const error = formValidations[props.formName ?? "-1"][props.name];
138
- const borderColor = error ? "border-red-500" : "border-transparent";
139
- (0, react_1.useEffect)(() => {
140
- if (!isInitialItemAdded && items?.length > 0) {
141
- insertItems([items[0]]);
142
- setIsInitialItemAdded(true);
143
- }
144
- }, [isInitialItemAdded, items, insertItems]);
145
- return ((0, jsx_runtime_1.jsxs)("div", { className: `${className} ${borderColor} border-2`, style: { overflowX: "auto" }, children: [!!error && (0, jsx_runtime_1.jsx)("div", { className: "text-red-500 text-sm mb-2", children: error }), (0, jsx_runtime_1.jsxs)("table", { className: "w-full", children: [(0, jsx_runtime_1.jsx)("thead", { children: renderHeader() }), (0, jsx_runtime_1.jsx)("tbody", { children: renderRows() }), (0, jsx_runtime_1.jsx)("tfoot", { children: (0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsx)("td", { className: "align-middle", children: (0, jsx_runtime_1.jsx)("button", { className: "bg-blue-500 hover:bg-blue-600 font-bold py-2 px-4 rounded", onClick: (event) => {
146
- event.preventDefault();
147
- event.stopPropagation();
148
- addRow();
149
- }, type: "button", children: "+" }) }), (0, jsx_runtime_1.jsxs)("td", { colSpan: 2, children: ["Total de etiquetas a imprimir:", " ", tableData?.reduce((sum, x) => {
150
- const val = react_1.default.isValidElement(x[1])
151
- ? x[1]?.props?.defaultValue
152
- : undefined;
153
- if (!sum)
154
- return val;
155
- return sum + val;
156
- }, 0)] })] }) })] })] }));
157
- };
158
- exports.DynamicPrintTable = DynamicPrintTable;
@@ -1,219 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.DynamicTable = void 0;
27
- const jsx_runtime_1 = require("react/jsx-runtime");
28
- const react_1 = __importStar(require("react"));
29
- const index_js_1 = require("../Form/TextArea/index.js");
30
- const index_js_2 = require("../Form/TextField/index.js");
31
- const index_js_3 = require("../Form/Checkbox/index.js");
32
- const DynamicTable = ({ forwardedRef, ...props }, ref) => {
33
- const [tableData, setTableData] = (0, react_1.useState)({});
34
- const { cellInputs, intersectionTitle, className, onChange, defaultValue, margins, } = props;
35
- (0, react_1.useEffect)(() => {
36
- if (onChange) {
37
- onChange(JSON.stringify(tableData));
38
- }
39
- // eslint-disable-next-line react-hooks/exhaustive-deps
40
- }, [tableData]);
41
- (0, react_1.useEffect)(() => {
42
- if (defaultValue) {
43
- initializeTable(defaultValue);
44
- }
45
- else {
46
- initializeTableWithDefaults();
47
- }
48
- }, [defaultValue]);
49
- const getRows = () => {
50
- const rowsIds = Object.keys(tableData)
51
- .filter((key) => key.startsWith("row"))
52
- .map((key) => parseInt(key.slice(3)));
53
- return rowsIds.sort().map((id) => ({ id }));
54
- };
55
- const getCols = () => {
56
- const colsIds = Object.keys(tableData)
57
- .filter((key) => key.startsWith("column"))
58
- .map((key) => parseInt(key.slice(6)));
59
- return colsIds.sort().map((id) => ({ id }));
60
- };
61
- const addRow = (event) => {
62
- event.stopPropagation();
63
- event.preventDefault();
64
- const rows = getRows();
65
- const lastId = rows[rows.length - 1].id;
66
- handleInputChange(`row${lastId + 1}`, 1);
67
- };
68
- const addCol = (event) => {
69
- event.stopPropagation();
70
- event.preventDefault();
71
- const cols = getCols();
72
- const lastId = cols[cols.length - 1].id;
73
- handleInputChange(`column${lastId + 1}`, 1);
74
- };
75
- const removeRow = (rowId) => {
76
- const newRowData = { ...tableData };
77
- for (const key in newRowData) {
78
- if (key.startsWith(`row${rowId}`) || key.startsWith(`cell-${rowId}-`)) {
79
- delete newRowData[key];
80
- }
81
- }
82
- setTableData(newRowData);
83
- };
84
- const removeCol = (colId) => {
85
- const newRowData = { ...tableData };
86
- for (const key in newRowData) {
87
- if (key.startsWith(`column${colId}`) || key.endsWith(`-${colId}`)) {
88
- delete newRowData[key];
89
- }
90
- }
91
- setTableData(newRowData);
92
- };
93
- const getTotalForRow = (rowId) => {
94
- return Number(tableData[`row${rowId}`] ?? 0) ?? 0;
95
- };
96
- const getTotalForColumn = (colId) => {
97
- return Number(tableData[`column${colId}`] ?? 0) ?? 0;
98
- };
99
- const getTotalForRows = () => {
100
- return getRows()
101
- .map((row) => getTotalForRow(row.id))
102
- .reduce((a, b) => a + b, 0);
103
- };
104
- const getTotalForColumns = () => {
105
- return getCols()
106
- .map((col) => getTotalForColumn(col.id))
107
- .reduce((a, b) => a + b, 0);
108
- };
109
- const getRowsCount = () => {
110
- return getRows().length;
111
- };
112
- const getColumnsCount = () => {
113
- return getCols().length;
114
- };
115
- const handleInputChange = (name, value) => {
116
- setTableData((prevData) => ({ ...prevData, [name]: value }));
117
- };
118
- const handleValidation = (cellId, colId, rowId) => {
119
- const headerValue = tableData[`column${colId}`];
120
- const rowValue = tableData[`row${rowId}`];
121
- if (props.onValidate && props.onValidate(headerValue, rowValue)) {
122
- return handleInputChange(cellId, true);
123
- }
124
- return { stopUIChange: true };
125
- };
126
- const handleRemoveValidation = (cellId) => {
127
- handleInputChange(cellId, false);
128
- };
129
- const initializeTableWithDefaults = () => {
130
- const initialData = { row0: 1, column0: 1 };
131
- setTableData(initialData);
132
- };
133
- const initializeTable = (tableJson) => {
134
- try {
135
- const initialData = JSON.parse(tableJson);
136
- setTableData(initialData);
137
- }
138
- catch (error) {
139
- console.error("Error al inicializar la tabla:", error);
140
- }
141
- };
142
- const cellBordered = {
143
- border: "1px solid #ccc",
144
- };
145
- const pastelGrayBackground = {
146
- backgroundColor: "#B69E99",
147
- };
148
- const cellCenteredContent = {
149
- textAlign: "center",
150
- verticalAlign: "middle",
151
- };
152
- const renderTotalHeight = () => {
153
- const sumaFilas = getRows()
154
- .map((row) => getTotalForRow(row.id))
155
- .reduce((a, b) => a + b, 0);
156
- const sumTotalFilas = sumaFilas +
157
- (margins?.marginTop ?? 0) +
158
- (getRows().length - 1) * (margins?.verticalGap ?? 0);
159
- return ((0, jsx_runtime_1.jsxs)("div", { className: "ml-4 inline-block", children: [(0, jsx_runtime_1.jsxs)("strong", { children: ["Total alto: ", sumTotalFilas, " "] }), margins && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["(Celdas: ", sumaFilas, " + M\u00E1rgen superior: ", margins?.marginTop ?? 0, " +", " ", getRows().length - 1, " Brechas verticales:", " ", Math.round((getRows().length - 1) * (margins?.verticalGap ?? 0)), ")"] }))] }));
160
- };
161
- const renderTotalWidth = () => {
162
- const cols = getCols();
163
- const sumaColumnas = cols
164
- .map((col) => getTotalForColumn(col.id))
165
- .reduce((a, b) => a + b, 0);
166
- const sumaTotal = sumaColumnas +
167
- (margins?.marginLeft ?? 0) +
168
- (getCols().length - 1) * (margins?.horizontalGap ?? 0);
169
- return ((0, jsx_runtime_1.jsxs)("div", { className: "ml-4 inline-block", children: [(0, jsx_runtime_1.jsxs)("strong", { children: ["Total ancho: ", sumaTotal, " "] }), margins && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["(Celdas: ", sumaColumnas, " + M\u00E1rgen izquierdo:", " ", margins?.marginLeft ?? 0, " + ", getCols().length - 1, " Brechas horizontales:", " ", Math.round((getCols().length - 1) * (margins?.horizontalGap ?? 0)), ")"] }))] }));
170
- };
171
- const renderHeader = () => {
172
- const cols = getCols();
173
- return ((0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsx)("th", { className: "align-middle py-2 text-center", style: {
174
- ...cellBordered,
175
- ...pastelGrayBackground,
176
- }, children: intersectionTitle ?? "" }), cols.map((col) => ((0, jsx_runtime_1.jsx)("th", { className: "align-middle py-2 text-center", style: { ...cellBordered, ...pastelGrayBackground }, children: (0, jsx_runtime_1.jsxs)("div", { className: "inline-flex", children: [(0, jsx_runtime_1.jsx)(index_js_2.TextField, { style: { maxWidth: "45%", minWidth: "45%" }, name: `column${col.id}`, defaultValue: tableData[`column${col.id}`] || 1, type: "number", onChange: (value) => handleInputChange(`column${col.id}`, value) }), col.id > 0 && ((0, jsx_runtime_1.jsx)("button", { className: "bg-red-500 hover:bg-red-600 font-bold py-1 px-2 rounded ml-2", onClick: () => removeCol(col.id), children: "x" }))] }) }, col.id))), (0, jsx_runtime_1.jsx)("th", { children: (0, jsx_runtime_1.jsx)("button", { className: "bg-blue-500 hover:bg-blue-600 font-bold py-2 px-4 rounded", onClick: addCol, children: "+" }) })] }));
177
- };
178
- const renderRow = (rowId) => {
179
- const cols = getCols();
180
- return ((0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsx)("td", { className: "align-middle", style: {
181
- ...cellBordered,
182
- ...pastelGrayBackground,
183
- textOverflow: "ellipsis",
184
- msTextOverflow: "ellipsis",
185
- maxWidth: "200px",
186
- }, children: (0, jsx_runtime_1.jsxs)("div", { className: "inline-flex", children: [(0, jsx_runtime_1.jsx)(index_js_2.TextField, { style: { maxWidth: "45%", minWidth: "45%" }, name: `row${rowId}`, defaultValue: tableData[`row${rowId}`] || 1, type: "number", onChange: (value) => handleInputChange(`row${rowId}`, value) }), rowId > 0 && ((0, jsx_runtime_1.jsx)("button", { className: "bg-red-500 hover:bg-red-600 font-bold py-1 px-2 rounded ml-2", onClick: () => {
187
- removeRow(rowId);
188
- }, children: "x" }))] }) }), cols.map((col) => {
189
- const cellId = `cell-${rowId}-${col.id}`;
190
- const cellValidation = tableData[cellId] === true;
191
- if (!cellInputs)
192
- tableData[cellId] = cellValidation;
193
- return ((0, jsx_runtime_1.jsx)("td", { id: cellId, style: { ...cellBordered, ...cellCenteredContent }, children: cellInputs ? ((0, jsx_runtime_1.jsx)(index_js_1.TextArea, { name: cellId, defaultValue: tableData[cellId] || "", onChange: (value) => handleInputChange(cellId, value) })) : ((0, jsx_runtime_1.jsx)(index_js_3.CheckBox, { name: cellId, defaultValue: cellValidation, onChange: (value) => {
194
- if (value) {
195
- return handleValidation(cellId, col.id, rowId);
196
- }
197
- else {
198
- handleRemoveValidation(cellId);
199
- }
200
- } })) }, col.id));
201
- }), rowId === 0 && ((0, jsx_runtime_1.jsx)("td", { rowSpan: getRows().length, style: { maxWidth: "100px" }, children: renderTotalHeight() }))] }, rowId));
202
- };
203
- const renderRows = () => {
204
- const rows = getRows();
205
- return rows.map((row) => renderRow(row.id));
206
- };
207
- // Use el "useImperativeHandle" para que el componente padre pueda acceder a los métodos deseados
208
- react_1.default.useImperativeHandle(forwardedRef, () => ({
209
- getTotalForRows,
210
- getTotalForColumns,
211
- getColumnsCount,
212
- getRowsCount,
213
- }));
214
- return ((0, jsx_runtime_1.jsx)("div", { className: `${className}`, children: (0, jsx_runtime_1.jsxs)("table", { className: "border-collapse", children: [(0, jsx_runtime_1.jsx)("thead", { children: renderHeader() }), (0, jsx_runtime_1.jsx)("tbody", { children: renderRows() }), (0, jsx_runtime_1.jsx)("tfoot", { children: (0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsx)("td", { children: (0, jsx_runtime_1.jsx)("button", { className: "bg-blue-500 hover:bg-blue-600 font-bold py-2 px-4 rounded", onClick: addRow, children: "+" }) }), (0, jsx_runtime_1.jsx)("td", { colSpan: getCols().length + 1, className: "text-left align-middle", style: {
215
- textOverflow: "ellipsis",
216
- msTextOverflow: "ellipsis",
217
- }, children: renderTotalWidth() })] }) })] }) }));
218
- };
219
- exports.DynamicTable = DynamicTable;