next-recomponents 2.0.56 → 2.0.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -38510,10 +38510,10 @@ function Table3({
38510
38510
  }
38511
38511
 
38512
38512
  // src/table-advanced/index.tsx
38513
- var import_react21 = require("react");
38513
+ var import_react22 = require("react");
38514
38514
 
38515
38515
  // src/table-advanced/h.table.tsx
38516
- var import_react19 = __toESM(require("react"));
38516
+ var import_react20 = __toESM(require("react"));
38517
38517
 
38518
38518
  // src/table-advanced/header.tsx
38519
38519
  var import_react18 = require("react");
@@ -38541,6 +38541,44 @@ function DropIcon() {
38541
38541
  }
38542
38542
  );
38543
38543
  }
38544
+ function PrevIcon() {
38545
+ return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
38546
+ "svg",
38547
+ {
38548
+ stroke: "currentColor",
38549
+ fill: "currentColor",
38550
+ strokeWidth: "0",
38551
+ viewBox: "0 0 24 24",
38552
+ height: "1em",
38553
+ width: "1em",
38554
+ xmlns: "http://www.w3.org/2000/svg",
38555
+ children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
38556
+ "polyline",
38557
+ {
38558
+ fill: "none",
38559
+ strokeWidth: "2",
38560
+ points: "7 2 17 12 7 22",
38561
+ transform: "matrix(-1 0 0 1 24 0)"
38562
+ }
38563
+ )
38564
+ }
38565
+ );
38566
+ }
38567
+ function NextIcon() {
38568
+ return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
38569
+ "svg",
38570
+ {
38571
+ stroke: "currentColor",
38572
+ fill: "currentColor",
38573
+ strokeWidth: "0",
38574
+ viewBox: "0 0 24 24",
38575
+ height: "1em",
38576
+ width: "1em",
38577
+ xmlns: "http://www.w3.org/2000/svg",
38578
+ children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("polyline", { fill: "none", "stroke-width": "2", points: "7 2 17 12 7 22" })
38579
+ }
38580
+ );
38581
+ }
38544
38582
  function EditIcon3() {
38545
38583
  return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
38546
38584
  "svg",
@@ -38728,23 +38766,29 @@ function Header({
38728
38766
  header,
38729
38767
  context,
38730
38768
  drag,
38731
- padding
38769
+ padding,
38770
+ index,
38771
+ length
38732
38772
  }) {
38733
38773
  const [visible, setVisible] = (0, import_react18.useState)(false);
38774
+ const [hovered, setHovered] = (0, import_react18.useState)(false);
38734
38775
  const sortIndex = context.sort.findIndex((b) => b.field == header);
38735
38776
  const [text, setText] = (0, import_react18.useState)("");
38736
38777
  const cellRef = (0, import_react18.useRef)(null);
38737
38778
  const [coords, setCoords] = (0, import_react18.useState)(
38738
38779
  null
38739
38780
  );
38740
- const filteredValues = [
38741
- ...new Set(context.data.map((d) => d[header]))
38742
- ].filter((d) => {
38743
- if (text == "") return true;
38744
- return `${d}`.toLowerCase().includes(text.toLowerCase());
38745
- });
38746
- const [selected, setSelected] = (0, import_react18.useState)([...filteredValues]);
38781
+ const filteredValues = (0, import_react18.useMemo)(() => {
38782
+ return [...new Set(context.data.map((d) => d[header]))].filter((d) => {
38783
+ if (text == "") return true;
38784
+ return `${d}`.toLowerCase().includes(text.toLowerCase());
38785
+ });
38786
+ }, [context.data, header, text]);
38787
+ const [selected, setSelected] = (0, import_react18.useState)([]);
38747
38788
  const hasFilter = context.filters.find((b) => b.field == header);
38789
+ (0, import_react18.useEffect)(() => {
38790
+ setSelected(filteredValues);
38791
+ }, [filteredValues]);
38748
38792
  (0, import_react18.useEffect)(() => {
38749
38793
  if (visible) {
38750
38794
  context.setCurrentHeader(header);
@@ -38785,7 +38829,7 @@ function Header({
38785
38829
  return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: "", children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
38786
38830
  "div",
38787
38831
  {
38788
- className: "border flex items-center justify-center text-center relative ",
38832
+ className: " flex items-center justify-center text-center relative ",
38789
38833
  style: { zIndex: 10, height: `${padding}px`, maxHeight: "100px" },
38790
38834
  children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
38791
38835
  "input",
@@ -38807,15 +38851,17 @@ function Header({
38807
38851
  }
38808
38852
  ) });
38809
38853
  } else
38810
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: "", children: /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(
38854
+ return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: " ", children: /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(
38811
38855
  "div",
38812
38856
  {
38813
38857
  ref: cellRef,
38814
- className: "shadow ",
38858
+ className: index < length - 1 ? "border-r" : "",
38859
+ onMouseEnter: (e) => setHovered(true),
38860
+ onMouseLeave: (e) => setHovered(false),
38815
38861
  style: { zIndex: 10, height: `${padding}px`, maxHeight: "100px" },
38816
38862
  children: [
38817
38863
  /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex justify-between items-center ", children: [
38818
- /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex gap-2", children: [
38864
+ !context.disabled ? /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex gap-2", children: [
38819
38865
  hasFilter ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
38820
38866
  "div",
38821
38867
  {
@@ -38838,7 +38884,7 @@ function Header({
38838
38884
  children: sortIndex >= 0 ? context.sort[sortIndex].type === "ASC" ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(ArrowUPIcon, {}) : /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(ArrowDownIcon2, {}) : /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", {})
38839
38885
  }
38840
38886
  )
38841
- ] }),
38887
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", {}),
38842
38888
  /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
38843
38889
  "div",
38844
38890
  {
@@ -38852,21 +38898,21 @@ function Header({
38852
38898
  children: header
38853
38899
  }
38854
38900
  ),
38855
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
38901
+ !context.disabled ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
38856
38902
  "div",
38857
38903
  {
38858
38904
  style: { zIndex: 10 },
38859
38905
  className: "icon font-bold p-1 cursor-pointer pr-3 ",
38860
38906
  onClick: (e) => setVisible(true),
38861
- children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(DropIcon, {})
38907
+ children: hovered ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(DropIcon, {}) : ""
38862
38908
  }
38863
- )
38909
+ ) : /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", {})
38864
38910
  ] }),
38865
- context.currentHeader != header && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
38911
+ !context.disabled && context.currentHeader != header && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
38866
38912
  "div",
38867
38913
  {
38868
38914
  onMouseDown: (e) => drag.startDrag(e, header),
38869
- className: "absolute top-0 h-full cursor-col-resize hover:bg-blue-300 p-2",
38915
+ className: "absolute top-0 h-full cursor-col-resize hover:bg-blue-300 ",
38870
38916
  style: { right: -2, width: 6, zIndex: 20 }
38871
38917
  }
38872
38918
  ),
@@ -38988,9 +39034,9 @@ function Header({
38988
39034
  type: "checkbox",
38989
39035
  onChange: (e) => {
38990
39036
  const ns = [...selected];
38991
- const index = ns.findIndex((n) => n == d);
38992
- if (index >= 0) {
38993
- ns.splice(index, 1);
39037
+ const index2 = ns.findIndex((n) => n == d);
39038
+ if (index2 >= 0) {
39039
+ ns.splice(index2, 1);
38994
39040
  } else {
38995
39041
  ns.push(d);
38996
39042
  }
@@ -38999,7 +39045,7 @@ function Header({
38999
39045
  checked: text != "" || selected.includes(d)
39000
39046
  }
39001
39047
  ),
39002
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: "truncate", children: d })
39048
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: "truncate", children: d == "" ? "Vacias" : !Boolean(d) ? "null" : d })
39003
39049
  ] }, d);
39004
39050
  })
39005
39051
  ]
@@ -39040,7 +39086,7 @@ var import_jsx_runtime35 = require("react/jsx-runtime");
39040
39086
  function Searchable({
39041
39087
  context
39042
39088
  }) {
39043
- return /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("div", { className: "flex justify-start p-2 relative w-96", children: [
39089
+ return /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("div", { className: "flex justify-start p-2 relative w-96 text-xs", children: [
39044
39090
  /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
39045
39091
  "input",
39046
39092
  {
@@ -39087,16 +39133,69 @@ function valueFormatter({
39087
39133
  return value;
39088
39134
  }
39089
39135
 
39136
+ // src/table-advanced/use.pagination.tsx
39137
+ var import_react19 = require("react");
39138
+ function usePaginacion({
39139
+ total,
39140
+ tamanioPagina = 100,
39141
+ paginaInicial = 1
39142
+ }) {
39143
+ const [totalPaginas, setTotalPaginas] = (0, import_react19.useState)(
39144
+ Math.max(1, Math.ceil(total / tamanioPagina))
39145
+ );
39146
+ const [pagina, setPagina] = (0, import_react19.useState)(
39147
+ Math.min(Math.max(paginaInicial, 1), totalPaginas)
39148
+ );
39149
+ const inicio = total === 0 ? 0 : (pagina - 1) * tamanioPagina + 1;
39150
+ const fin = Math.min(pagina * tamanioPagina, total);
39151
+ const rango = (0, import_react19.useMemo)(() => {
39152
+ if (total === 0) return "0 a 0";
39153
+ return `${inicio} a ${fin}`;
39154
+ }, [inicio, fin, total]);
39155
+ const hasNext = pagina < totalPaginas;
39156
+ const hasPrev = pagina > 1;
39157
+ const next = (0, import_react19.useCallback)(() => {
39158
+ setPagina((p) => Math.min(p + 1, totalPaginas));
39159
+ }, [totalPaginas]);
39160
+ const prev = (0, import_react19.useCallback)(() => {
39161
+ setPagina((p) => Math.max(p - 1, 1));
39162
+ }, []);
39163
+ const irAPagina = (0, import_react19.useCallback)(
39164
+ (n) => {
39165
+ setPagina(Math.min(Math.max(n, 1), totalPaginas));
39166
+ },
39167
+ [totalPaginas]
39168
+ );
39169
+ (0, import_react19.useEffect)(() => {
39170
+ setTotalPaginas(Math.max(1, Math.ceil(total / tamanioPagina)));
39171
+ setPagina(1);
39172
+ }, [total]);
39173
+ return {
39174
+ rango,
39175
+ inicio,
39176
+ fin,
39177
+ total,
39178
+ pagina,
39179
+ totalPaginas,
39180
+ hasNext,
39181
+ hasPrev,
39182
+ next,
39183
+ prev,
39184
+ irAPagina
39185
+ };
39186
+ }
39187
+ var use_pagination_default = usePaginacion;
39188
+
39090
39189
  // src/table-advanced/h.table.tsx
39091
39190
  var import_jsx_runtime36 = require("react/jsx-runtime");
39092
39191
  function HTable({
39093
39192
  context
39094
39193
  }) {
39095
- const [isLoading, setIsloading] = (0, import_react19.useState)(false);
39194
+ const [isLoading, setIsloading] = (0, import_react20.useState)(false);
39096
39195
  const { cols, headers } = context;
39097
- const [currentIndex, setCurrentIndex] = (0, import_react19.useState)(-1);
39098
- const tableRef = (0, import_react19.useRef)(null);
39099
- const modalRef = (0, import_react19.useRef)(null);
39196
+ const [currentIndex, setCurrentIndex] = (0, import_react20.useState)(-1);
39197
+ const tableRef = (0, import_react20.useRef)(null);
39198
+ const modalRef = (0, import_react20.useRef)(null);
39100
39199
  const catDensities = { confortable: 80, compact: 30, standard: 53 };
39101
39200
  const padding = (context == null ? void 0 : context.rowHeight) || (context == null ? void 0 : context.density) ? catDensities[context == null ? void 0 : context.density] : 53;
39102
39201
  function useResizableColumns(headers2, defaultWidth = 160, minWidth = 60) {
@@ -39110,8 +39209,8 @@ function HTable({
39110
39209
  function resize(headers3) {
39111
39210
  return Object.fromEntries(headers3.map((h) => [h, getWidth(h)]));
39112
39211
  }
39113
- const [widths2, setWidths2] = (0, import_react19.useState)({});
39114
- const startDrag2 = (0, import_react19.useCallback)(
39212
+ const [widths2, setWidths2] = (0, import_react20.useState)({});
39213
+ const startDrag2 = (0, import_react20.useCallback)(
39115
39214
  (e, headerKey) => {
39116
39215
  var _a;
39117
39216
  e.preventDefault();
@@ -39146,7 +39245,7 @@ function HTable({
39146
39245
  return { widths: widths2, gridTemplateColumns: gridTemplateColumns2, startDrag: startDrag2, setWidths: setWidths2 };
39147
39246
  }
39148
39247
  const { gridTemplateColumns, startDrag, widths, setWidths } = useResizableColumns(headers);
39149
- (0, import_react19.useEffect)(() => {
39248
+ (0, import_react20.useEffect)(() => {
39150
39249
  if (!tableRef.current) return;
39151
39250
  const observer = new ResizeObserver(([entry]) => {
39152
39251
  const ocultos = headers.filter(
@@ -39162,15 +39261,6 @@ function HTable({
39162
39261
  const sizeadosLength = sizeados.length;
39163
39262
  const sizeadosWidth = sizeadosLength * 60;
39164
39263
  const w = (ancho - sizeadosWidth - personalizadosSum) / (headers.length - sizeadosLength - personalizados.length - ocultos.length);
39165
- console.log({
39166
- w,
39167
- ancho,
39168
- sizeadosWidth,
39169
- personalizadosSum,
39170
- headers,
39171
- sizeadosLength,
39172
- personalizados
39173
- });
39174
39264
  setWidths(
39175
39265
  Object.fromEntries(
39176
39266
  headers.map((h) => {
@@ -39186,19 +39276,22 @@ function HTable({
39186
39276
  observer.observe(tableRef.current);
39187
39277
  return () => observer.disconnect();
39188
39278
  }, [headers.length]);
39189
- const searchedData = context.filteredData.filter((row) => {
39190
- if (context.searchBy === "") return true;
39191
- return Object.values(row).some(
39192
- (value) => String(value).toLowerCase().includes(context.searchBy.toLowerCase())
39193
- );
39194
- });
39279
+ const searchedData = (0, import_react20.useMemo)(() => {
39280
+ return context.filteredData.filter((row) => {
39281
+ if (context.searchBy === "") return true;
39282
+ return Object.values(row).some(
39283
+ (value) => String(value).toLowerCase().includes(context.searchBy.toLowerCase())
39284
+ );
39285
+ });
39286
+ }, [context.filteredData]);
39287
+ const pagination = use_pagination_default({ total: searchedData.length });
39195
39288
  return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
39196
39289
  "div",
39197
39290
  {
39198
39291
  className: [
39199
39292
  context.className,
39200
39293
  "bg-white relative",
39201
- "p-2 border shadow rounded-2xl"
39294
+ "p-2 border shadow rounded-2xl w-full rounded-lg "
39202
39295
  ].join(" "),
39203
39296
  ref: tableRef,
39204
39297
  children: [
@@ -39218,10 +39311,11 @@ function HTable({
39218
39311
  }
39219
39312
  }
39220
39313
  return obj;
39221
- })
39314
+ }),
39315
+ `${context.exportName}.xlsx`
39222
39316
  );
39223
39317
  },
39224
- className: "flex gap-1 items-center border shadow rounded p-1 text-white bg-green-800 px-2",
39318
+ className: "flex gap-1 items-center border shadow rounded p-1 text-white bg-green-800 p-1 text-xs",
39225
39319
  children: [
39226
39320
  /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(ExcelIcon2, {}),
39227
39321
  "Exportar"
@@ -39231,7 +39325,7 @@ function HTable({
39231
39325
  context.onSelect && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39232
39326
  "button",
39233
39327
  {
39234
- className: "border shadow rounded p-1 text-white px-2 " + (context.selected.length > 0 ? "bg-blue-500" : "bg-gray-500"),
39328
+ className: "border shadow rounded p-1 text-white p-1 text-xs bg-blue-500 cursor-pointer ",
39235
39329
  disabled: context.selected.length == 0,
39236
39330
  onClick: async (e) => {
39237
39331
  setIsloading(true);
@@ -39248,7 +39342,7 @@ function HTable({
39248
39342
  context.onSave && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39249
39343
  "button",
39250
39344
  {
39251
- className: "border shadow rounded p-1 text-white px-2 bg-blue-500",
39345
+ className: "border shadow rounded p-1 text-white p-1 text-xs bg-blue-500 cursor-pointer ",
39252
39346
  onClick: async (e) => {
39253
39347
  setIsloading(true);
39254
39348
  const ex = context.filteredData.map((d) => {
@@ -39262,204 +39356,256 @@ function HTable({
39262
39356
  }
39263
39357
  )
39264
39358
  ] }),
39265
- /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "grid ", style: { gridTemplateColumns }, children: [
39266
- headers.map((header, i) => {
39267
- var _a, _b;
39268
- if ((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, header)) return null;
39269
- if (header.startsWith("_") && !header.startsWith("__")) return null;
39270
- return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
39271
- "div",
39272
- {
39273
- className: "bg-white relative w-full bg-red-100",
39274
- children: [
39275
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39276
- Header,
39277
- {
39278
- padding,
39279
- header,
39280
- context,
39281
- drag: { gridTemplateColumns, startDrag, widths }
39282
- }
39283
- ),
39284
- i < headers.length - 1 && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39285
- "div",
39286
- {
39287
- onMouseDown: (e) => startDrag(e, header),
39288
- style: {
39289
- position: "absolute",
39290
- right: -3,
39291
- top: 0,
39292
- width: 6,
39293
- height: "100%",
39294
- cursor: "col-resize",
39295
- background: "transparent"
39296
- },
39297
- onMouseEnter: (e) => e.currentTarget.style.background = "var(--border-strong, #ccc)",
39298
- onMouseLeave: (e) => e.currentTarget.style.background = "transparent"
39299
- }
39300
- )
39301
- ]
39302
- },
39303
- header
39304
- );
39305
- }),
39306
- searchedData.map((row, rowIndex) => {
39307
- const items = Object.entries(row);
39308
- return items.map(([key, item], i) => {
39309
- var _a, _b, _c, _d, _e;
39310
- if ((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, key)) return null;
39311
- if (key.startsWith("_") && !key.startsWith("__")) return null;
39312
- if (key == "__modal__") {
39313
- return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39314
- "div",
39315
- {
39316
- onMouseEnter: (e) => setCurrentIndex(rowIndex),
39317
- style: {
39318
- height: `${padding}px`
39319
- },
39320
- className: (rowIndex == currentIndex ? " bg-blue-100 " : " bg-white ") + " border-b p-2 flex items-center justify-center " + (context.searchBy && String(item).toLowerCase().includes(context.searchBy.toLowerCase()) ? "bg-yellow-100" : ""),
39321
- children: (context == null ? void 0 : context.modalButton) || /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39322
- "button",
39323
- {
39324
- className: "border shadow rounded bg-blue-500 text-white p-2 ",
39325
- onClick: (e) => {
39326
- var _a2;
39327
- setCurrentIndex(rowIndex);
39328
- (_a2 = modalRef.current) == null ? void 0 : _a2.click();
39329
- },
39330
- children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(EditIcon3, {})
39331
- }
39332
- )
39359
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
39360
+ "div",
39361
+ {
39362
+ children: [
39363
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39364
+ "div",
39365
+ {
39366
+ style: {
39367
+ gridTemplateColumns,
39368
+ width: Object.values(widths).reduce((acc, i) => acc + i, 0)
39333
39369
  },
39334
- row.id + i
39335
- );
39336
- }
39337
- if (key == "__select__") {
39338
- return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39339
- "div",
39340
- {
39341
- onMouseEnter: (e) => setCurrentIndex(rowIndex),
39342
- style: {
39343
- height: `${padding}px`
39344
- },
39345
- className: (rowIndex == currentIndex ? " bg-blue-100 " : " bg-white ") + " border-b p-2 flex items-center justify-center " + (context.searchBy && String(item).toLowerCase().includes(context.searchBy.toLowerCase()) ? "bg-yellow-100" : ""),
39346
- children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39347
- "input",
39370
+ className: ["grid w-full "].join(" "),
39371
+ children: headers.map((header, i) => {
39372
+ var _a, _b;
39373
+ if ((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, header)) return null;
39374
+ if (header.startsWith("_") && !header.startsWith("__")) return null;
39375
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39376
+ "div",
39348
39377
  {
39349
- type: "checkbox",
39350
- className: "w-5 h-5 accent-blue-600 transition-all duration-300 checked:scale-110 ",
39351
- checked: Boolean(
39352
- context.selected.find((s) => s == (row == null ? void 0 : row.id))
39353
- ),
39354
- onChange: (e) => {
39355
- const newSelected = [...context.selected];
39356
- const index = newSelected.findIndex((s) => s == (row == null ? void 0 : row.id));
39357
- if (index >= 0) {
39358
- newSelected.splice(index, 1);
39359
- } else {
39360
- newSelected.push(row == null ? void 0 : row.id);
39378
+ className: "bg-white relative w-full bg-red-100",
39379
+ children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39380
+ Header,
39381
+ {
39382
+ length: headers.length,
39383
+ index: i,
39384
+ padding,
39385
+ header,
39386
+ context,
39387
+ drag: { gridTemplateColumns, startDrag, widths }
39361
39388
  }
39362
- context.setSelected(newSelected);
39363
- }
39364
- }
39365
- )
39389
+ )
39390
+ },
39391
+ header
39392
+ );
39393
+ })
39394
+ }
39395
+ ),
39396
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39397
+ "div",
39398
+ {
39399
+ style: {
39400
+ gridTemplateColumns,
39401
+ width: Object.values(widths).reduce((acc, i) => acc + i, 0)
39366
39402
  },
39367
- row.id + i
39368
- );
39369
- }
39370
- return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39403
+ className: [
39404
+ "grid max-h-[500px] ",
39405
+ context.filteredData.length >= 5 ? "overflow-hidden overflow-y-scroll " : ""
39406
+ ].join(" "),
39407
+ children: searchedData.slice(pagination.inicio - 1, pagination.fin).map((row, rowIndex) => {
39408
+ const items = Object.entries(row);
39409
+ return items.map(([key, item], i) => {
39410
+ var _a, _b, _c, _d, _e;
39411
+ if ((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, key)) return null;
39412
+ if (key.startsWith("_") && !key.startsWith("__")) return null;
39413
+ if (key == "__modal__") {
39414
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39415
+ "div",
39416
+ {
39417
+ onMouseEnter: (e) => setCurrentIndex(rowIndex),
39418
+ style: {
39419
+ height: `${padding}px`
39420
+ },
39421
+ className: (rowIndex == currentIndex ? " bg-blue-100 " : " bg-white ") + " border-b p-2 flex items-center justify-center " + (context.searchBy && String(item).toLowerCase().includes(context.searchBy.toLowerCase()) ? "bg-yellow-100" : ""),
39422
+ children: (context == null ? void 0 : context.modalButton) || /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39423
+ "button",
39424
+ {
39425
+ className: "border shadow rounded bg-blue-500 text-white p-2 ",
39426
+ onClick: (e) => {
39427
+ var _a2;
39428
+ setCurrentIndex(rowIndex);
39429
+ (_a2 = modalRef.current) == null ? void 0 : _a2.click();
39430
+ },
39431
+ children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(EditIcon3, {})
39432
+ }
39433
+ )
39434
+ },
39435
+ row.id + i
39436
+ );
39437
+ }
39438
+ if (key == "__select__") {
39439
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39440
+ "div",
39441
+ {
39442
+ onMouseEnter: (e) => setCurrentIndex(rowIndex),
39443
+ style: {
39444
+ height: `${padding}px`
39445
+ },
39446
+ className: (rowIndex == currentIndex ? " bg-blue-100 " : " bg-white ") + " border-b flex items-start p-2 justify-center " + (context.searchBy && String(item).toLowerCase().includes(context.searchBy.toLowerCase()) ? "bg-yellow-100" : ""),
39447
+ children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39448
+ "input",
39449
+ {
39450
+ type: "checkbox",
39451
+ className: "w-5 h-5 accent-blue-600 transition-all duration-300 checked:scale-110 ",
39452
+ checked: Boolean(
39453
+ context.selected.find((s) => s == (row == null ? void 0 : row.id))
39454
+ ),
39455
+ onChange: (e) => {
39456
+ const newSelected = [...context.selected];
39457
+ const index = newSelected.findIndex(
39458
+ (s) => s == (row == null ? void 0 : row.id)
39459
+ );
39460
+ if (index >= 0) {
39461
+ newSelected.splice(index, 1);
39462
+ } else {
39463
+ newSelected.push(row == null ? void 0 : row.id);
39464
+ }
39465
+ context.setSelected(newSelected);
39466
+ }
39467
+ }
39468
+ )
39469
+ },
39470
+ row.id + i
39471
+ );
39472
+ }
39473
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39474
+ "div",
39475
+ {
39476
+ onMouseEnter: (e) => setCurrentIndex(rowIndex),
39477
+ style: {
39478
+ fontSize: (context == null ? void 0 : context.fontSize) || "12px",
39479
+ ...(context == null ? void 0 : context.wrapText) ? { minHeight: `${padding}px` } : { height: `${padding}px` }
39480
+ },
39481
+ className: " p-1" + (rowIndex == currentIndex ? " bg-blue-100 " : " bg-white ") + (context.wrapText ? " text-wrap truncate " : " truncate ") + " border-b " + (context.searchBy && String(item).toLowerCase().includes(context.searchBy.toLowerCase()) ? rowIndex == currentIndex ? " bg-yellow-200 " : " bg-yellow-100 " : ""),
39482
+ children: (context == null ? void 0 : context.editableFields) && context.editableFields.includes(key) ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39483
+ "input",
39484
+ {
39485
+ defaultValue: item,
39486
+ className: "w-full " + (context.editions.includes(row == null ? void 0 : row.id) ? "bg-blue-400 text-white" : "bg-blue-100"),
39487
+ onBlur: (e) => {
39488
+ const id = row == null ? void 0 : row.id;
39489
+ const newData = [...context.data];
39490
+ const index = newData.findIndex((d) => +d.id == +id);
39491
+ newData[index][key] = e.target.value;
39492
+ context.setData(newData);
39493
+ const newEditions = [
39494
+ .../* @__PURE__ */ new Set([...context.editions, id])
39495
+ ];
39496
+ context.setEditions(newEditions);
39497
+ }
39498
+ }
39499
+ ) : ((_c = context.buttons) == null ? void 0 : _c[key]) ? import_react20.default.cloneElement(context.buttons[key], {
39500
+ // children: context.buttons[key]?.props?.children
39501
+ // ? item
39502
+ // : undefined,
39503
+ value: item,
39504
+ children: ((_e = (_d = context.buttons[key]) == null ? void 0 : _d.props) == null ? void 0 : _e.children) ? item : null,
39505
+ onClick: async (e) => {
39506
+ var _a2, _b2;
39507
+ const ret = await ((_b2 = (_a2 = context.buttons[key].props) == null ? void 0 : _a2.onClick) == null ? void 0 : _b2.call(_a2, {
39508
+ e,
39509
+ row
39510
+ })) || {};
39511
+ const newData = [...context.data];
39512
+ const index = newData.findIndex(
39513
+ (f) => f.id == (row == null ? void 0 : row.id)
39514
+ );
39515
+ newData[index] = { ...newData[index], ...ret };
39516
+ context.setData(newData);
39517
+ },
39518
+ onChange: async (e) => {
39519
+ var _a2, _b2, _c2;
39520
+ const value = e.target.value;
39521
+ const ret = await ((_b2 = (_a2 = context.buttons[key].props) == null ? void 0 : _a2.onChange) == null ? void 0 : _b2.call(_a2, {
39522
+ e,
39523
+ row
39524
+ })) || {};
39525
+ const newData = [...context.data];
39526
+ const index = newData.findIndex(
39527
+ (f) => f.id == (row == null ? void 0 : row.id)
39528
+ );
39529
+ if (index >= 0) {
39530
+ newData[index][key] = value;
39531
+ }
39532
+ for (let i2 in ret) {
39533
+ if ((_c2 = newData[index]) == null ? void 0 : _c2[i2]) {
39534
+ const v = ret[i2];
39535
+ newData[index][i2] = v;
39536
+ }
39537
+ }
39538
+ context.setData(newData);
39539
+ }
39540
+ }) : ["number", "string"].includes(typeof item) ? valueFormatter({
39541
+ value: item,
39542
+ currentCoin: context.currentCoin
39543
+ }) : import_react20.default.isValidElement(item) ? item : JSON.stringify(item)
39544
+ },
39545
+ row.id + i
39546
+ );
39547
+ });
39548
+ })
39549
+ }
39550
+ ),
39551
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39371
39552
  "div",
39372
39553
  {
39373
- onMouseEnter: (e) => setCurrentIndex(rowIndex),
39374
39554
  style: {
39375
- fontSize: context.fontSize,
39376
- ...(context == null ? void 0 : context.wrapText) ? { minHeight: `${padding}px` } : { height: `${padding}px` }
39555
+ gridTemplateColumns,
39556
+ width: Object.values(widths).reduce((acc, i) => acc + i, 0)
39377
39557
  },
39378
- className: " flex justify-center items-center " + (rowIndex == currentIndex ? " bg-blue-100 " : " bg-white ") + (context.wrapText ? " text-wrap truncate " : " truncate ") + " border-b " + (context.searchBy && String(item).toLowerCase().includes(context.searchBy.toLowerCase()) ? rowIndex == currentIndex ? " bg-yellow-200 " : " bg-yellow-100 " : ""),
39379
- children: (context == null ? void 0 : context.editableFields) && context.editableFields.includes(key) ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39380
- "input",
39558
+ className: ["grid border-b bg-white"].join(" "),
39559
+ children: Object.keys((context == null ? void 0 : context.footer) || {}).length > 0 && headers.map((header) => {
39560
+ var _a, _b, _c, _d, _e;
39561
+ if ((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, header)) return null;
39562
+ if (header.startsWith("_") && !header.startsWith("__"))
39563
+ return null;
39564
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39565
+ "div",
39566
+ {
39567
+ style: {
39568
+ // height: `${padding}px`,
39569
+ maxHeight: "100px"
39570
+ },
39571
+ title: ((_c = context.footer) == null ? void 0 : _c[header]) + " de " + header,
39572
+ className: " cursor-default font-bold bg-white flex items-center justify-center text-xs my-5 " + (((_d = context.footer) == null ? void 0 : _d[header]) ? " border-r border-l " : ""),
39573
+ children: valueFormatter({
39574
+ currentCoin: context.currentCoin,
39575
+ value: ((_e = context.footer) == null ? void 0 : _e[header]) ? context.footer[header] == "sum" ? context.filteredData.map((d) => +d[header]).reduce((acc, h) => h + acc, 0) : context.footer[header] == "count" ? context.filteredData.map((d) => d[header] != "" ? 1 : 0).reduce((acc, h) => acc + h, 0) : context.footer[header] == "avg" ? context.filteredData.map((d) => +d[header]).reduce((acc, h) => h + acc, 0) / context.filteredData.map((d) => d[header] != "" ? 1 : 0).reduce((acc, h) => acc + h, 0) : "" : ""
39576
+ })
39577
+ },
39578
+ header
39579
+ );
39580
+ })
39581
+ }
39582
+ ),
39583
+ searchedData.length > 100 && /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "flex justify-end p-2", children: [
39584
+ pagination.rango,
39585
+ " de ",
39586
+ pagination.total,
39587
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "flex items-center gap-5 mx-5", children: [
39588
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39589
+ "button",
39381
39590
  {
39382
- defaultValue: item,
39383
- className: "w-full " + (context.editions.includes(row == null ? void 0 : row.id) ? "bg-blue-400 text-white" : "bg-blue-100"),
39384
- onBlur: (e) => {
39385
- const id = row == null ? void 0 : row.id;
39386
- const newData = [...context.data];
39387
- const index = newData.findIndex((d) => +d.id == +id);
39388
- newData[index][key] = e.target.value;
39389
- context.setData(newData);
39390
- const newEditions = [
39391
- .../* @__PURE__ */ new Set([...context.editions, id])
39392
- ];
39393
- context.setEditions(newEditions);
39394
- }
39591
+ onClick: (e) => pagination.hasPrev && pagination.prev(),
39592
+ className: pagination.hasPrev ? "" : "text-gray-300",
39593
+ children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(PrevIcon, {})
39395
39594
  }
39396
- ) : ((_c = context.buttons) == null ? void 0 : _c[key]) ? import_react19.default.cloneElement(context.buttons[key], {
39397
- // children: context.buttons[key]?.props?.children
39398
- // ? item
39399
- // : undefined,
39400
- value: item,
39401
- children: ((_e = (_d = context.buttons[key]) == null ? void 0 : _d.props) == null ? void 0 : _e.children) ? item : null,
39402
- onClick: async (e) => {
39403
- var _a2, _b2;
39404
- const ret = await ((_b2 = (_a2 = context.buttons[key].props) == null ? void 0 : _a2.onClick) == null ? void 0 : _b2.call(_a2, {
39405
- e,
39406
- row
39407
- })) || {};
39408
- const newData = [...context.data];
39409
- const index = newData.findIndex((f) => f.id == (row == null ? void 0 : row.id));
39410
- newData[index] = { ...newData[index], ...ret };
39411
- context.setData(newData);
39412
- },
39413
- onChange: async (e) => {
39414
- var _a2, _b2, _c2;
39415
- const value = e.target.value;
39416
- const ret = await ((_b2 = (_a2 = context.buttons[key].props) == null ? void 0 : _a2.onChange) == null ? void 0 : _b2.call(_a2, {
39417
- e,
39418
- row
39419
- })) || {};
39420
- const newData = [...context.data];
39421
- const index = newData.findIndex((f) => f.id == (row == null ? void 0 : row.id));
39422
- if (index >= 0) {
39423
- newData[index][key] = value;
39424
- }
39425
- for (let i2 in ret) {
39426
- if ((_c2 = newData[index]) == null ? void 0 : _c2[i2]) {
39427
- const v = ret[i2];
39428
- newData[index][i2] = v;
39429
- }
39430
- }
39431
- context.setData(newData);
39595
+ ),
39596
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39597
+ "button",
39598
+ {
39599
+ onClick: (e) => pagination.hasNext && pagination.next(),
39600
+ className: pagination.hasNext ? "" : "text-gray-300",
39601
+ children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(NextIcon, {})
39432
39602
  }
39433
- }) : ["number", "string"].includes(typeof item) ? valueFormatter({
39434
- value: item,
39435
- currentCoin: context.currentCoin
39436
- }) : import_react19.default.isValidElement(item) ? item : JSON.stringify(item)
39437
- },
39438
- row.id + i
39439
- );
39440
- });
39441
- }),
39442
- Object.keys((context == null ? void 0 : context.footer) || {}).length > 0 && headers.map((header) => {
39443
- var _a, _b, _c;
39444
- if ((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, header)) return null;
39445
- if (header.startsWith("_") && !header.startsWith("__")) return null;
39446
- return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39447
- "div",
39448
- {
39449
- style: {
39450
- height: `${padding}px`,
39451
- maxHeight: "100px"
39452
- },
39453
- className: "border-b font-bold bg-white flex items-center justify-center",
39454
- children: valueFormatter({
39455
- currentCoin: context.currentCoin,
39456
- value: ((_c = context.footer) == null ? void 0 : _c[header]) ? context.footer[header] == "sum" ? context.filteredData.map((d) => +d[header]).reduce((acc, h) => h + acc, 0) : context.footer[header] == "count" ? context.filteredData.map((d) => d[header] != "" ? 1 : 0).reduce((acc, h) => acc + h, 0) : context.footer[header] == "avg" ? context.filteredData.map((d) => +d[header]).reduce((acc, h) => h + acc, 0) / context.filteredData.map((d) => d[header] != "" ? 1 : 0).reduce((acc, h) => acc + h, 0) : "" : ""
39457
- })
39458
- },
39459
- header
39460
- );
39461
- })
39462
- ] }),
39603
+ )
39604
+ ] })
39605
+ ] })
39606
+ ]
39607
+ }
39608
+ ),
39463
39609
  context.modal && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
39464
39610
  Modal,
39465
39611
  {
@@ -39529,7 +39675,7 @@ function ModalContent({
39529
39675
  }
39530
39676
  )
39531
39677
  ] }),
39532
- import_react19.default.cloneElement(context.modal, {
39678
+ import_react20.default.cloneElement(context.modal, {
39533
39679
  row: searchedData[currentIndex],
39534
39680
  hide
39535
39681
  })
@@ -39537,7 +39683,7 @@ function ModalContent({
39537
39683
  }
39538
39684
 
39539
39685
  // src/table-advanced/context.ts
39540
- var import_react20 = require("react");
39686
+ var import_react21 = require("react");
39541
39687
 
39542
39688
  // src/table-advanced/filter.reducer.ts
39543
39689
  var filterReducer = (acc, b) => {
@@ -39565,19 +39711,19 @@ var sortReducer = (acc, b) => {
39565
39711
  // src/table-advanced/context.ts
39566
39712
  function useContext({ onSelect }) {
39567
39713
  const excel = useExcel();
39568
- const [editions, setEditions] = (0, import_react20.useState)([]);
39569
- const [selected, setSelected] = (0, import_react20.useState)([]);
39570
- const [data, setData] = (0, import_react20.useState)([]);
39714
+ const [editions, setEditions] = (0, import_react21.useState)([]);
39715
+ const [selected, setSelected] = (0, import_react21.useState)([]);
39716
+ const [data, setData] = (0, import_react21.useState)([]);
39571
39717
  const headers = [...new Set(data.map((b) => Object.keys(b)).flat())];
39572
- const [currentHeader, setCurrentHeader] = (0, import_react20.useState)(null);
39718
+ const [currentHeader, setCurrentHeader] = (0, import_react21.useState)(null);
39573
39719
  const cols = headers.length;
39574
- const [filters, setFilters] = (0, import_react20.useReducer)(
39720
+ const [filters, setFilters] = (0, import_react21.useReducer)(
39575
39721
  filterReducer,
39576
39722
  new Array()
39577
39723
  );
39578
- const [searchBy, setSearchBy] = (0, import_react20.useState)("");
39579
- const [sort, setSort] = (0, import_react20.useReducer)(sortReducer, new Array());
39580
- const sortedData = (0, import_react20.useMemo)(() => {
39724
+ const [searchBy, setSearchBy] = (0, import_react21.useState)("");
39725
+ const [sort, setSort] = (0, import_react21.useReducer)(sortReducer, new Array());
39726
+ const sortedData = (0, import_react21.useMemo)(() => {
39581
39727
  return [...data].sort((a, b) => {
39582
39728
  for (const { field, type } of sort.reverse()) {
39583
39729
  const av = a[field];
@@ -39607,7 +39753,7 @@ function useContext({ onSelect }) {
39607
39753
  }
39608
39754
  return true;
39609
39755
  });
39610
- (0, import_react20.useEffect)(() => {
39756
+ (0, import_react21.useEffect)(() => {
39611
39757
  if (filters.length == 0) {
39612
39758
  setEditions([]);
39613
39759
  }
@@ -39640,7 +39786,7 @@ var import_jsx_runtime37 = require("react/jsx-runtime");
39640
39786
  function TableAdvanced(tableProps) {
39641
39787
  const { data, ...props } = tableProps;
39642
39788
  const context = useContext({ onSelect: Boolean(tableProps.onSelect) });
39643
- (0, import_react21.useEffect)(() => {
39789
+ (0, import_react22.useEffect)(() => {
39644
39790
  context.setData(
39645
39791
  Array.isArray(data) ? data.map((d) => {
39646
39792
  return {
@@ -39651,7 +39797,7 @@ function TableAdvanced(tableProps) {
39651
39797
  }) : data
39652
39798
  );
39653
39799
  }, [data]);
39654
- (0, import_react21.useEffect)(() => {
39800
+ (0, import_react22.useEffect)(() => {
39655
39801
  if (tableProps == null ? void 0 : tableProps.sortBy) {
39656
39802
  const [k, v] = Object.entries(tableProps.sortBy)[0];
39657
39803
  context.setSort({ [k]: v });
@@ -39670,15 +39816,15 @@ function TableAdvanced(tableProps) {
39670
39816
  }
39671
39817
 
39672
39818
  // src/tabs/index.tsx
39673
- var import_react22 = __toESM(require("react"));
39819
+ var import_react23 = __toESM(require("react"));
39674
39820
  var import_jsx_runtime38 = require("react/jsx-runtime");
39675
39821
  function TabContainer({
39676
39822
  children,
39677
39823
  labelMaxWidth = 100,
39678
39824
  currentIndex = 0
39679
39825
  }) {
39680
- const [index, setIndex] = (0, import_react22.useState)(0);
39681
- const items = import_react22.default.Children.toArray(
39826
+ const [index, setIndex] = (0, import_react23.useState)(0);
39827
+ const items = import_react23.default.Children.toArray(
39682
39828
  children
39683
39829
  );
39684
39830
  const labels = items.map((c) => c.props.label);
@@ -39687,7 +39833,7 @@ function TabContainer({
39687
39833
  if (e.key === "ArrowLeft")
39688
39834
  setIndex((k - 1 + labels.length) % labels.length);
39689
39835
  };
39690
- (0, import_react22.useEffect)(() => {
39836
+ (0, import_react23.useEffect)(() => {
39691
39837
  setIndex(currentIndex);
39692
39838
  }, [currentIndex]);
39693
39839
  return /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: "w-full bg-white", children: [