next-recomponents 2.0.41 → 2.0.42

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.mjs CHANGED
@@ -37010,7 +37010,7 @@ var COLOR_CONFIG = {
37010
37010
  label: "\u25CE"
37011
37011
  },
37012
37012
  white: {
37013
- bg: "from-gray-50 to-white",
37013
+ bg: "from-white to-white",
37014
37014
  iconBg: "bg-gray-100",
37015
37015
  iconText: "text-gray-500",
37016
37016
  border: "border-gray-200",
@@ -37071,7 +37071,7 @@ function PopupOverlay({
37071
37071
  return /* @__PURE__ */ jsxs9(
37072
37072
  "div",
37073
37073
  {
37074
- className: "fixed inset-0 flex items-center justify-center z-[1000] ",
37074
+ className: "fixed inset-0 flex items-center justify-center z-[1000] overflow-auto p-1",
37075
37075
  style: { background: "rgba(15,23,42,0.45)", backdropFilter: "blur(2px)" },
37076
37076
  children: [
37077
37077
  /* @__PURE__ */ jsx14("style", { children: `
@@ -37083,7 +37083,7 @@ function PopupOverlay({
37083
37083
  /* @__PURE__ */ jsxs9(
37084
37084
  "div",
37085
37085
  {
37086
- className: `bg-gradient-to-br ${c.bg} border ${c.border} ${popup.full == true ? " w-full h-screen m-20 " : " max-w-sm "} rounded-2xl shadow-2xl mx-4`,
37086
+ className: `bg-gradient-to-br ${c.bg} border ${c.border} ${popup.full == true ? " w-screen h-screen mt-10 " : " max-w-sm "} rounded shadow m-2`,
37087
37087
  style: { animation: "fadeInScale 0.18s ease-out", overflow: "auto" },
37088
37088
  children: [
37089
37089
  /* @__PURE__ */ jsxs9("div", { className: "flex flex-col items-center gap-3 px-8 pt-8 pb-5 text-center ", children: [
@@ -37128,7 +37128,7 @@ function PopupOverlay({
37128
37128
  onEnter: () => onClose(true, popup.inputValue)
37129
37129
  }
37130
37130
  ),
37131
- /* @__PURE__ */ jsx14("div", { className: `border-t ${c.border} mt-4` }),
37131
+ popup.type !== "modal" && /* @__PURE__ */ jsx14("div", { className: `border-t ${c.border} mt-4` }),
37132
37132
  popup.type !== "modal" && /* @__PURE__ */ jsx14(
37133
37133
  PopupActions,
37134
37134
  {
@@ -37168,14 +37168,21 @@ function usePopup() {
37168
37168
  },
37169
37169
  []
37170
37170
  );
37171
- const close = useCallback((confirmed, value) => {
37172
- setPopup((prev) => {
37171
+ const close = useCallback(
37172
+ async (confirmed, value) => {
37173
37173
  var _a, _b;
37174
- if (confirmed) (_a = prev.onConfirm) == null ? void 0 : _a.call(prev, value);
37175
- else (_b = prev.onCancel) == null ? void 0 : _b.call(prev);
37176
- return { ...prev, visible: false, inputValue: "" };
37177
- });
37178
- }, []);
37174
+ const prev = { ...popup };
37175
+ let visible = false;
37176
+ if (confirmed) {
37177
+ (_a = prev.onConfirm) == null ? void 0 : _a.call(prev, value);
37178
+ } else if (prev == null ? void 0 : prev.onCancel) {
37179
+ visible = !Boolean(await ((_b = prev.onCancel) == null ? void 0 : _b.call(prev)));
37180
+ }
37181
+ const data = { ...prev, visible, inputValue: "" };
37182
+ setPopup(data);
37183
+ },
37184
+ [popup]
37185
+ );
37179
37186
  const alert2 = useCallback(
37180
37187
  (message, color = "primary") => new Promise(
37181
37188
  (resolve) => open({
@@ -37189,13 +37196,17 @@ function usePopup() {
37189
37196
  [open]
37190
37197
  );
37191
37198
  const modal = useCallback(
37192
- (message, color = "primary", icons = false, full = false) => new Promise(
37199
+ (message, color = "primary", icons = false, full = false, onClose) => new Promise(
37193
37200
  (resolve) => open({
37194
37201
  type: "modal",
37195
37202
  message,
37196
37203
  color,
37197
- onConfirm: () => resolve(),
37198
- onCancel: () => resolve(),
37204
+ // onConfirm: () => {
37205
+ // resolve();
37206
+ // },
37207
+ onCancel: async () => {
37208
+ return await (onClose == null ? void 0 : onClose());
37209
+ },
37199
37210
  icons,
37200
37211
  full
37201
37212
  })
@@ -37250,15 +37261,18 @@ function usePopup() {
37250
37261
  }
37251
37262
 
37252
37263
  // src/modal/index.tsx
37253
- import { Fragment as Fragment2, jsxs as jsxs10 } from "react/jsx-runtime";
37264
+ import { jsxs as jsxs10 } from "react/jsx-runtime";
37254
37265
  function Modal({
37255
37266
  button,
37256
37267
  children,
37257
37268
  color = "primary",
37258
- title
37269
+ title,
37270
+ onClose
37259
37271
  }) {
37260
37272
  const pop = usePopup();
37261
- const hide = () => pop.close(false);
37273
+ const hide = () => {
37274
+ pop.close(false);
37275
+ };
37262
37276
  const childrenWithHide = useMemo4(
37263
37277
  () => cloneElement2(children, { hide }),
37264
37278
  [children]
@@ -37268,11 +37282,11 @@ function Modal({
37268
37282
  }, [childrenWithHide]);
37269
37283
  const props = button == null ? void 0 : button.props;
37270
37284
  const onClick = props == null ? void 0 : props.onClick;
37271
- return /* @__PURE__ */ jsxs10(Fragment2, { children: [
37285
+ return /* @__PURE__ */ jsxs10("div", { className: "", children: [
37272
37286
  cloneElement2(button, {
37273
37287
  onClick: (e) => {
37274
37288
  onClick == null ? void 0 : onClick(e);
37275
- pop.modal(childrenWithHide, color, false, true);
37289
+ pop.modal(childrenWithHide, color, false, true, onClose);
37276
37290
  }
37277
37291
  }),
37278
37292
  pop.PopupComponent
@@ -38444,6 +38458,1126 @@ function Table3({
38444
38458
  ] })
38445
38459
  ] });
38446
38460
  }
38461
+
38462
+ // src/table-advanced/index.tsx
38463
+ import { useEffect as useEffect13 } from "react";
38464
+
38465
+ // src/table-advanced/h.table.tsx
38466
+ import React10, {
38467
+ useCallback as useCallback2,
38468
+ useEffect as useEffect11,
38469
+ useRef as useRef7,
38470
+ useState as useState15
38471
+ } from "react";
38472
+
38473
+ // src/table-advanced/header.tsx
38474
+ import { useEffect as useEffect10, useRef as useRef6, useState as useState14 } from "react";
38475
+ import { createPortal } from "react-dom";
38476
+
38477
+ // src/table-advanced/icons.tsx
38478
+ import { jsx as jsx30, jsxs as jsxs21 } from "react/jsx-runtime";
38479
+ function DropIcon() {
38480
+ return /* @__PURE__ */ jsxs21(
38481
+ "svg",
38482
+ {
38483
+ stroke: "currentColor",
38484
+ fill: "currentColor",
38485
+ strokeWidth: "0",
38486
+ viewBox: "0 0 512 512",
38487
+ height: "1em",
38488
+ className: "text-blue-500",
38489
+ width: "1em",
38490
+ xmlns: "http://www.w3.org/2000/svg",
38491
+ children: [
38492
+ /* @__PURE__ */ jsx30("circle", { cx: "256", cy: "256", r: "48" }),
38493
+ /* @__PURE__ */ jsx30("circle", { cx: "256", cy: "416", r: "48" }),
38494
+ /* @__PURE__ */ jsx30("circle", { cx: "256", cy: "96", r: "48" })
38495
+ ]
38496
+ }
38497
+ );
38498
+ }
38499
+ function EditIcon3() {
38500
+ return /* @__PURE__ */ jsx30(
38501
+ "svg",
38502
+ {
38503
+ className: "text-white",
38504
+ stroke: "currentColor",
38505
+ fill: "currentColor",
38506
+ strokeWidth: "0",
38507
+ viewBox: "0 0 24 24",
38508
+ height: "1em",
38509
+ width: "1em",
38510
+ xmlns: "http://www.w3.org/2000/svg",
38511
+ children: /* @__PURE__ */ jsx30("path", { d: "M16.7574 2.99678L14.7574 4.99678H5V18.9968H19V9.23943L21 7.23943V19.9968C21 20.5491 20.5523 20.9968 20 20.9968H4C3.44772 20.9968 3 20.5491 3 19.9968V3.99678C3 3.4445 3.44772 2.99678 4 2.99678H16.7574ZM20.4853 2.09729L21.8995 3.5115L12.7071 12.7039L11.2954 12.7064L11.2929 11.2897L20.4853 2.09729Z" })
38512
+ }
38513
+ );
38514
+ }
38515
+ function ExcelIcon2() {
38516
+ return /* @__PURE__ */ jsx30(
38517
+ "svg",
38518
+ {
38519
+ stroke: "currentColor",
38520
+ fill: "currentColor",
38521
+ strokeWidth: "0",
38522
+ viewBox: "0 0 24 24",
38523
+ height: "1em",
38524
+ width: "1em",
38525
+ xmlns: "http://www.w3.org/2000/svg",
38526
+ children: /* @__PURE__ */ jsx30("path", { d: "M2.85858 2.87732L15.4293 1.0815C15.7027 1.04245 15.9559 1.2324 15.995 1.50577C15.9983 1.52919 16 1.55282 16 1.57648V22.4235C16 22.6996 15.7761 22.9235 15.5 22.9235C15.4763 22.9235 15.4527 22.9218 15.4293 22.9184L2.85858 21.1226C2.36593 21.0522 2 20.6303 2 20.1327V3.86727C2 3.36962 2.36593 2.9477 2.85858 2.87732ZM4 4.73457V19.2654L14 20.694V3.30599L4 4.73457ZM17 19H20V4.99997H17V2.99997H21C21.5523 2.99997 22 3.44769 22 3.99997V20C22 20.5523 21.5523 21 21 21H17V19ZM10.2 12L13 16H10.6L9 13.7143L7.39999 16H5L7.8 12L5 7.99997H7.39999L9 10.2857L10.6 7.99997H13L10.2 12Z" })
38527
+ }
38528
+ );
38529
+ }
38530
+ function OrderAscIcon() {
38531
+ return /* @__PURE__ */ jsxs21(
38532
+ "svg",
38533
+ {
38534
+ stroke: "currentColor",
38535
+ fill: "currentColor",
38536
+ strokeWidth: "0",
38537
+ version: "1",
38538
+ viewBox: "0 0 48 48",
38539
+ enableBackground: "new 0 0 48 48",
38540
+ height: "1em",
38541
+ width: "1em",
38542
+ xmlns: "http://www.w3.org/2000/svg",
38543
+ children: [
38544
+ /* @__PURE__ */ jsx30(
38545
+ "polygon",
38546
+ {
38547
+ fill: "#546E7A",
38548
+ points: "38,33 38,5 34,5 34,33 28,33 36,43 44,33"
38549
+ }
38550
+ ),
38551
+ /* @__PURE__ */ jsxs21("g", { fill: "#2196F3", children: [
38552
+ /* @__PURE__ */ jsx30("path", { d: "M16.8,17.2h-5.3l-1.1,3H6.9L12.6,5h2.9l5.7,15.2h-3.2L16.8,17.2z M12.2,14.5H16l-1.9-5.7L12.2,14.5z" }),
38553
+ /* @__PURE__ */ jsx30("path", { d: "M12.4,40.5H20V43H8.4v-1.9L16,30.3H8.4v-2.5h11.4v1.7L12.4,40.5z" })
38554
+ ] })
38555
+ ]
38556
+ }
38557
+ );
38558
+ }
38559
+ function OrderDesIcon() {
38560
+ return /* @__PURE__ */ jsxs21(
38561
+ "svg",
38562
+ {
38563
+ stroke: "currentColor",
38564
+ fill: "currentColor",
38565
+ strokeWidth: "0",
38566
+ version: "1",
38567
+ viewBox: "0 0 48 48",
38568
+ enableBackground: "new 0 0 48 48",
38569
+ height: "1em",
38570
+ width: "1em",
38571
+ className: "text-blue-500",
38572
+ xmlns: "http://www.w3.org/2000/svg",
38573
+ children: [
38574
+ /* @__PURE__ */ jsxs21("g", { fill: "#2196F3", children: [
38575
+ /* @__PURE__ */ jsx30("path", { d: "M16.8,40h-5.3l-1.1,3H6.9l5.7-15.2h2.9L21.1,43h-3.2L16.8,40z M12.2,37.3H16l-1.9-5.7L12.2,37.3z" }),
38576
+ /* @__PURE__ */ jsx30("path", { d: "M12.4,17.7H20v2.5H8.4v-1.9L16,7.5H8.4V5h11.4v1.7L12.4,17.7z" })
38577
+ ] }),
38578
+ /* @__PURE__ */ jsx30(
38579
+ "polygon",
38580
+ {
38581
+ fill: "#546E7A",
38582
+ points: "38,33 38,5 34,5 34,33 28,33 36,43 44,33"
38583
+ }
38584
+ )
38585
+ ]
38586
+ }
38587
+ );
38588
+ }
38589
+ function ArrowDownIcon2() {
38590
+ return /* @__PURE__ */ jsx30(
38591
+ "svg",
38592
+ {
38593
+ stroke: "currentColor",
38594
+ fill: "currentColor",
38595
+ strokeWidth: "0",
38596
+ className: "text-blue-500",
38597
+ viewBox: "0 0 512 512",
38598
+ height: "1em",
38599
+ width: "1em",
38600
+ xmlns: "http://www.w3.org/2000/svg",
38601
+ children: /* @__PURE__ */ jsx30("path", { d: "M348.3 295.6c-5-5.1-13.3-5.1-18.4-.1L269 356.2V124.9c0-7.1-5.8-12.9-13-12.9s-13 5.8-13 12.9v231.3l-60.9-60.8c-5.1-5-13.3-4.9-18.4.1-5 5.1-5 13.2.1 18.3l83 82.4c1.2 1.1 2.5 2 4.1 2.7 1.6.7 3.3 1 5 1 3.4 0 6.6-1.3 9.1-3.7l83-82.4c5.2-4.9 5.3-13.1.3-18.2z" })
38602
+ }
38603
+ );
38604
+ }
38605
+ function ArrowUPIcon() {
38606
+ return /* @__PURE__ */ jsx30(
38607
+ "svg",
38608
+ {
38609
+ stroke: "currentColor",
38610
+ fill: "currentColor",
38611
+ strokeWidth: "0",
38612
+ className: "text-blue-500",
38613
+ viewBox: "0 0 512 512",
38614
+ height: "1em",
38615
+ width: "1em",
38616
+ xmlns: "http://www.w3.org/2000/svg",
38617
+ children: /* @__PURE__ */ jsx30("path", { d: "M348.3 216.4c-5 5.1-13.3 5.1-18.4.1L269 155.8v231.3c0 7.1-5.8 12.9-13 12.9s-13-5.8-13-12.9V155.8l-60.9 60.8c-5.1 5-13.3 4.9-18.4-.1-5-5.1-5-13.2.1-18.3l83-82.4c1.2-1.1 2.5-2 4.1-2.7 1.6-.7 3.3-1 5-1 3.4 0 6.6 1.3 9.1 3.7l83 82.4c5.2 4.9 5.3 13.1.3 18.2z" })
38618
+ }
38619
+ );
38620
+ }
38621
+ function SearchIcon() {
38622
+ return /* @__PURE__ */ jsxs21(
38623
+ "svg",
38624
+ {
38625
+ stroke: "currentColor",
38626
+ fill: "currentColor",
38627
+ strokeWidth: "0",
38628
+ viewBox: "0 0 24 24",
38629
+ className: "text-blue-500",
38630
+ height: "1em",
38631
+ width: "1em",
38632
+ xmlns: "http://www.w3.org/2000/svg",
38633
+ children: [
38634
+ /* @__PURE__ */ jsx30("path", { fill: "none", d: "M0 0h24v24H0z" }),
38635
+ /* @__PURE__ */ jsx30("path", { d: "M7 9H2V7h5zm0 3H2v2h5zm13.59 7-3.83-3.83c-.8.52-1.74.83-2.76.83-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5c0 1.02-.31 1.96-.83 2.75L22 17.59zM17 11c0-1.65-1.35-3-3-3s-3 1.35-3 3 1.35 3 3 3 3-1.35 3-3M2 19h10v-2H2z" })
38636
+ ]
38637
+ }
38638
+ );
38639
+ }
38640
+ function FilterIcon() {
38641
+ return /* @__PURE__ */ jsxs21(
38642
+ "svg",
38643
+ {
38644
+ className: "text-red-300",
38645
+ stroke: "currentColor",
38646
+ fill: "currentColor",
38647
+ strokeWidth: "0",
38648
+ viewBox: "0 0 24 24",
38649
+ height: "1em",
38650
+ width: "1em",
38651
+ xmlns: "http://www.w3.org/2000/svg",
38652
+ children: [
38653
+ /* @__PURE__ */ jsx30("path", { fill: "none", d: "M0 0h24v24H0zM0 0h24m0 24H0" }),
38654
+ /* @__PURE__ */ jsx30("path", { d: "M4.25 5.66c.1.13 5.74 7.33 5.74 7.33V19c0 .55.45 1 1.01 1h2.01c.55 0 1.01-.45 1.01-1v-6.02s5.49-7.02 5.75-7.34S20 5 20 5c0-.55-.45-1-1.01-1H5.01C4.4 4 4 4.48 4 5c0 .2.06.44.25.66" })
38655
+ ]
38656
+ }
38657
+ );
38658
+ }
38659
+
38660
+ // src/table-advanced/menu.item.tsx
38661
+ import { jsxs as jsxs22 } from "react/jsx-runtime";
38662
+ function MenuItem({
38663
+ label,
38664
+ icon,
38665
+ onClick
38666
+ }) {
38667
+ return /* @__PURE__ */ jsxs22(
38668
+ "div",
38669
+ {
38670
+ className: "cursor-pointer border p-2 hover:bg-gray-100 flex items-center bg-white gap-2",
38671
+ onClick,
38672
+ children: [
38673
+ icon,
38674
+ label
38675
+ ]
38676
+ }
38677
+ );
38678
+ }
38679
+
38680
+ // src/table-advanced/header.tsx
38681
+ import { Fragment as Fragment2, jsx as jsx31, jsxs as jsxs23 } from "react/jsx-runtime";
38682
+ function Header({
38683
+ header,
38684
+ context,
38685
+ drag,
38686
+ padding
38687
+ }) {
38688
+ const [visible, setVisible] = useState14(false);
38689
+ const sortIndex = context.sort.findIndex((b) => b.field == header);
38690
+ const [text, setText] = useState14("");
38691
+ const cellRef = useRef6(null);
38692
+ const [coords, setCoords] = useState14(
38693
+ null
38694
+ );
38695
+ const filteredValues = [
38696
+ ...new Set(context.data.map((d) => d[header]))
38697
+ ].filter((d) => {
38698
+ if (text == "") return true;
38699
+ return `${d}`.toLowerCase().includes(text.toLowerCase());
38700
+ });
38701
+ const [selected, setSelected] = useState14([...filteredValues]);
38702
+ const hasFilter = context.filters.find((b) => b.field == header);
38703
+ useEffect10(() => {
38704
+ if (visible) {
38705
+ context.setCurrentHeader(header);
38706
+ }
38707
+ setText("");
38708
+ }, [visible]);
38709
+ useEffect10(() => {
38710
+ if (!visible || !cellRef.current) {
38711
+ setCoords(null);
38712
+ return;
38713
+ }
38714
+ const updateCoords = () => {
38715
+ if (!cellRef.current) return;
38716
+ const rect = cellRef.current.getBoundingClientRect();
38717
+ const POPUP_WIDTH = 300;
38718
+ setCoords({
38719
+ top: rect.bottom,
38720
+ left: Math.max(8, rect.right - POPUP_WIDTH)
38721
+ });
38722
+ };
38723
+ updateCoords();
38724
+ window.addEventListener("scroll", updateCoords, true);
38725
+ window.addEventListener("resize", updateCoords);
38726
+ return () => {
38727
+ window.removeEventListener("scroll", updateCoords, true);
38728
+ window.removeEventListener("resize", updateCoords);
38729
+ };
38730
+ }, [visible]);
38731
+ if (header == "__modal__") {
38732
+ return /* @__PURE__ */ jsx31("div", { className: "", children: /* @__PURE__ */ jsx31(
38733
+ "div",
38734
+ {
38735
+ className: "break-words border text-center relative ",
38736
+ style: { zIndex: 10, height: `${padding}px`, maxHeight: "100px" }
38737
+ }
38738
+ ) });
38739
+ } else if (header == "__select__") {
38740
+ return /* @__PURE__ */ jsx31("div", { className: "", children: /* @__PURE__ */ jsx31(
38741
+ "div",
38742
+ {
38743
+ className: "border flex items-center justify-center text-center relative ",
38744
+ style: { zIndex: 10, height: `${padding}px`, maxHeight: "100px" },
38745
+ children: /* @__PURE__ */ jsx31(
38746
+ "input",
38747
+ {
38748
+ type: "checkbox",
38749
+ className: "w-5 h-5 accent-blue-600 transition-all duration-300 checked:scale-110",
38750
+ checked: Boolean(
38751
+ context.selected.length == context.filteredData.length
38752
+ ),
38753
+ onChange: (e) => {
38754
+ if (context.selected.length < context.filteredData.length) {
38755
+ context.setSelected(context.filteredData.map((d) => d.id));
38756
+ } else {
38757
+ context.setSelected([]);
38758
+ }
38759
+ }
38760
+ }
38761
+ )
38762
+ }
38763
+ ) });
38764
+ } else
38765
+ return /* @__PURE__ */ jsx31("div", { className: "", children: /* @__PURE__ */ jsxs23(
38766
+ "div",
38767
+ {
38768
+ ref: cellRef,
38769
+ className: "break-words border text-center relative ",
38770
+ style: { zIndex: 10, height: `${padding}px`, maxHeight: "100px" },
38771
+ children: [
38772
+ /* @__PURE__ */ jsxs23("div", { className: "flex gap-5 items-center justify-between h-full cursor-pointer", children: [
38773
+ /* @__PURE__ */ jsxs23("div", { className: "flex gap-2", children: [
38774
+ hasFilter ? /* @__PURE__ */ jsx31(
38775
+ "div",
38776
+ {
38777
+ className: "cursor-pointer",
38778
+ onClick: (e) => {
38779
+ context.setFilters(null);
38780
+ setSelected(filteredValues);
38781
+ },
38782
+ children: /* @__PURE__ */ jsx31(FilterIcon, {})
38783
+ }
38784
+ ) : /* @__PURE__ */ jsx31("div", {}),
38785
+ /* @__PURE__ */ jsx31(
38786
+ "div",
38787
+ {
38788
+ onClick: (e) => {
38789
+ context.setSort({
38790
+ [header]: "TOGGLE"
38791
+ });
38792
+ },
38793
+ children: sortIndex >= 0 ? context.sort[sortIndex].type === "ASC" ? /* @__PURE__ */ jsx31(ArrowUPIcon, {}) : /* @__PURE__ */ jsx31(ArrowDownIcon2, {}) : /* @__PURE__ */ jsx31("div", {})
38794
+ }
38795
+ )
38796
+ ] }),
38797
+ /* @__PURE__ */ jsx31(
38798
+ "div",
38799
+ {
38800
+ className: "w-full",
38801
+ onClick: (e) => {
38802
+ context.setSort({
38803
+ [header]: "TOGGLE"
38804
+ });
38805
+ },
38806
+ children: header
38807
+ }
38808
+ ),
38809
+ /* @__PURE__ */ jsx31(
38810
+ "div",
38811
+ {
38812
+ style: { zIndex: 10 },
38813
+ className: "icon font-bold p-1 cursor-pointer pr-3 ",
38814
+ onClick: (e) => setVisible(true),
38815
+ children: /* @__PURE__ */ jsx31(DropIcon, {})
38816
+ }
38817
+ )
38818
+ ] }),
38819
+ context.currentHeader != header && /* @__PURE__ */ jsx31(
38820
+ "div",
38821
+ {
38822
+ onMouseDown: (e) => drag.startDrag(e, header),
38823
+ className: "absolute top-0 h-full cursor-col-resize hover:bg-blue-300 p-2",
38824
+ style: { right: -2, width: 6, zIndex: 20 }
38825
+ }
38826
+ ),
38827
+ visible && context.currentHeader == header && createPortal(
38828
+ /* @__PURE__ */ jsxs23(Fragment2, { children: [
38829
+ /* @__PURE__ */ jsx31(
38830
+ "div",
38831
+ {
38832
+ className: "w-screen h-screen fixed top-0 left-0",
38833
+ onClick: (e) => {
38834
+ setVisible(false);
38835
+ },
38836
+ style: { zIndex: 9998 }
38837
+ }
38838
+ ),
38839
+ coords && /* @__PURE__ */ jsx31(
38840
+ "div",
38841
+ {
38842
+ className: "fixed",
38843
+ style: { top: coords.top, left: coords.left, zIndex: 9999 },
38844
+ children: /* @__PURE__ */ jsxs23("div", { className: "bg-gray-100 w-[300px] flex flex-col border shadow rounded ", children: [
38845
+ hasFilter && /* @__PURE__ */ jsx31(
38846
+ MenuItem,
38847
+ {
38848
+ label: "Quitar filtro",
38849
+ icon: /* @__PURE__ */ jsx31(FilterIcon, {}),
38850
+ onClick: (e) => {
38851
+ setVisible(false);
38852
+ context.setFilters(null);
38853
+ setSelected(filteredValues);
38854
+ }
38855
+ }
38856
+ ),
38857
+ /* @__PURE__ */ jsx31(
38858
+ MenuItem,
38859
+ {
38860
+ label: "Orenar de A a Z",
38861
+ icon: /* @__PURE__ */ jsx31(OrderAscIcon, {}),
38862
+ onClick: (e) => {
38863
+ setVisible(false);
38864
+ context.setSort({ [header]: "ASC" });
38865
+ context.setCurrentHeader(null);
38866
+ }
38867
+ }
38868
+ ),
38869
+ /* @__PURE__ */ jsx31(
38870
+ MenuItem,
38871
+ {
38872
+ label: "Orenar de Z a A",
38873
+ icon: /* @__PURE__ */ jsx31(OrderDesIcon, {}),
38874
+ onClick: (e) => {
38875
+ setVisible(false);
38876
+ context.setSort({ [header]: "DESC" });
38877
+ context.setCurrentHeader(null);
38878
+ }
38879
+ }
38880
+ ),
38881
+ /* @__PURE__ */ jsxs23(
38882
+ Form,
38883
+ {
38884
+ onSubmit: (e) => {
38885
+ if (text != "") {
38886
+ setSelected(filteredValues);
38887
+ }
38888
+ context.setFilters({
38889
+ field: header,
38890
+ values: text != "" ? filteredValues : selected
38891
+ });
38892
+ setVisible(false);
38893
+ context.setCurrentHeader(null);
38894
+ },
38895
+ children: [
38896
+ /* @__PURE__ */ jsxs23("div", { className: "m-2 bg-white gap-2 flex flex-col", children: [
38897
+ /* @__PURE__ */ jsx31(
38898
+ "input",
38899
+ {
38900
+ placeholder: "Buscar...",
38901
+ className: "border shadow rounded p-2 w-full",
38902
+ value: text,
38903
+ onChange: (e) => setText(e.target.value)
38904
+ }
38905
+ ),
38906
+ /* @__PURE__ */ jsxs23(
38907
+ "div",
38908
+ {
38909
+ className: "flex items-start flex-col p-2 border shadow rounded max-w-[600px] h-[300px] bg-white ",
38910
+ style: { overflow: "auto" },
38911
+ children: [
38912
+ /* @__PURE__ */ jsxs23(
38913
+ "div",
38914
+ {
38915
+ className: "flex gap-2 " + (text != "" ? "text-gray-400" : ""),
38916
+ children: [
38917
+ /* @__PURE__ */ jsx31(
38918
+ "input",
38919
+ {
38920
+ type: "checkbox",
38921
+ checked: text != "" || selected.length == filteredValues.length,
38922
+ onClick: (e) => {
38923
+ if (selected.length == filteredValues.length) {
38924
+ setSelected([]);
38925
+ } else {
38926
+ setSelected(filteredValues);
38927
+ }
38928
+ },
38929
+ disabled: text != ""
38930
+ }
38931
+ ),
38932
+ /* @__PURE__ */ jsx31("div", { className: "truncate", children: "Seleccionar todo" })
38933
+ ]
38934
+ }
38935
+ ),
38936
+ filteredValues.map((d) => {
38937
+ return /* @__PURE__ */ jsxs23("div", { className: "flex gap-2 ", children: [
38938
+ /* @__PURE__ */ jsx31(
38939
+ "input",
38940
+ {
38941
+ disabled: text != "",
38942
+ type: "checkbox",
38943
+ onChange: (e) => {
38944
+ const ns = [...selected];
38945
+ const index = ns.findIndex((n) => n == d);
38946
+ if (index >= 0) {
38947
+ ns.splice(index, 1);
38948
+ } else {
38949
+ ns.push(d);
38950
+ }
38951
+ setSelected(ns);
38952
+ },
38953
+ checked: text != "" || selected.includes(d)
38954
+ }
38955
+ ),
38956
+ /* @__PURE__ */ jsx31("div", { className: "truncate", children: d })
38957
+ ] }, d);
38958
+ })
38959
+ ]
38960
+ }
38961
+ )
38962
+ ] }),
38963
+ /* @__PURE__ */ jsxs23("div", { className: "flex justify-between p-2", children: [
38964
+ /* @__PURE__ */ jsx31(
38965
+ "button",
38966
+ {
38967
+ onClick: (e) => {
38968
+ setVisible(false);
38969
+ context.setCurrentHeader(null);
38970
+ },
38971
+ className: "p-2 border shadow rounded bg-gray-300 text-black",
38972
+ type: "button",
38973
+ children: "Cancelar"
38974
+ }
38975
+ ),
38976
+ /* @__PURE__ */ jsx31("button", { className: "p-2 border shadow rounded bg-blue-500 text-white", children: "Aceptar" })
38977
+ ] })
38978
+ ]
38979
+ }
38980
+ )
38981
+ ] })
38982
+ }
38983
+ )
38984
+ ] }),
38985
+ document.body
38986
+ )
38987
+ ]
38988
+ }
38989
+ ) });
38990
+ }
38991
+
38992
+ // src/table-advanced/searchable.tsx
38993
+ import { jsx as jsx32, jsxs as jsxs24 } from "react/jsx-runtime";
38994
+ function Searchable({
38995
+ context
38996
+ }) {
38997
+ return /* @__PURE__ */ jsxs24("div", { className: "flex justify-start p-2 relative w-96", children: [
38998
+ /* @__PURE__ */ jsx32(
38999
+ "input",
39000
+ {
39001
+ type: "search",
39002
+ placeholder: "Buscar por ....",
39003
+ className: "border shadow rounded p-2 w-full pr-10",
39004
+ value: context.searchBy,
39005
+ onChange: (e) => context.setSearchBy(e.target.value)
39006
+ }
39007
+ ),
39008
+ /* @__PURE__ */ jsx32("div", { className: "absolute top-0 right-0 p-5", children: /* @__PURE__ */ jsx32(SearchIcon, {}) })
39009
+ ] });
39010
+ }
39011
+
39012
+ // src/table-advanced/types.ts
39013
+ var regularExpresions2 = {
39014
+ email: /^[\w.-]+@[a-zA-Z\d.-]+\.[a-zA-Z]{2,}$/,
39015
+ phone: /^\d{10}$/,
39016
+ number: /^\d+$/
39017
+ };
39018
+ var types_default = regularExpresions2;
39019
+
39020
+ // src/table-advanced/h.table.tsx
39021
+ import { jsx as jsx33, jsxs as jsxs25 } from "react/jsx-runtime";
39022
+ function HTable({
39023
+ context
39024
+ }) {
39025
+ const [isLoading, setIsloading] = useState15(false);
39026
+ const { cols, headers } = context;
39027
+ const [currentIndex, setCurrentIndex] = useState15(-1);
39028
+ const tableRef = useRef7(null);
39029
+ const modalRef = useRef7(null);
39030
+ const catDensities = { confortable: 80, compact: 30, standard: 53 };
39031
+ const padding = (context == null ? void 0 : context.rowHeight) || (context == null ? void 0 : context.density) ? catDensities[context == null ? void 0 : context.density] : 53;
39032
+ function useResizableColumns(headers2, defaultWidth = 160, minWidth = 60) {
39033
+ function getWidth(h) {
39034
+ return [
39035
+ "__select__",
39036
+ "__modal__",
39037
+ ...(context == null ? void 0 : context.hideColumns) || []
39038
+ ].includes(h) ? minWidth : defaultWidth;
39039
+ }
39040
+ function resize(headers3) {
39041
+ return Object.fromEntries(headers3.map((h) => [h, getWidth(h)]));
39042
+ }
39043
+ const [widths2, setWidths2] = useState15({});
39044
+ const startDrag2 = useCallback2(
39045
+ (e, headerKey) => {
39046
+ var _a;
39047
+ e.preventDefault();
39048
+ const startX = e.clientX;
39049
+ const startWidth = (_a = widths2[headerKey]) != null ? _a : defaultWidth;
39050
+ const onMove = (ev) => {
39051
+ const newWidth = Math.max(
39052
+ minWidth,
39053
+ startWidth + (ev.clientX - startX)
39054
+ );
39055
+ setWidths2((prev) => ({ ...prev, [headerKey]: newWidth }));
39056
+ };
39057
+ const onUp = () => {
39058
+ window.removeEventListener("mousemove", onMove);
39059
+ window.removeEventListener("mouseup", onUp);
39060
+ };
39061
+ window.addEventListener("mousemove", onMove);
39062
+ window.addEventListener("mouseup", onUp);
39063
+ },
39064
+ [widths2, defaultWidth, minWidth]
39065
+ );
39066
+ const gridTemplateColumns2 = headers2.filter((h) => {
39067
+ var _a, _b;
39068
+ return !((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, h));
39069
+ }).map((h) => {
39070
+ var _a;
39071
+ return `${(_a = widths2[h]) != null ? _a : defaultWidth}px`;
39072
+ }).join(" ");
39073
+ return { widths: widths2, gridTemplateColumns: gridTemplateColumns2, startDrag: startDrag2, setWidths: setWidths2 };
39074
+ }
39075
+ const { gridTemplateColumns, startDrag, widths, setWidths } = useResizableColumns(headers);
39076
+ useEffect11(() => {
39077
+ if (!tableRef.current) return;
39078
+ const observer = new ResizeObserver(([entry]) => {
39079
+ const sizeados = headers.filter(
39080
+ (h) => [
39081
+ "__select__",
39082
+ "__modal__"
39083
+ // ...(context?.hideColumns || []),
39084
+ // ...(context?.colSize ? Object.keys(context.colSize) : []),
39085
+ ].includes(h)
39086
+ );
39087
+ const personalizados = (context == null ? void 0 : context.colSize) ? Object.values(context.colSize) : [];
39088
+ const personalizadosSum = personalizados.length > 0 ? personalizados.reduce((acc, i) => acc + i, 0) : 0;
39089
+ const ancho = +entry.contentRect.width;
39090
+ const sizeadosLength = sizeados.length;
39091
+ const sizeadosWidth = sizeadosLength * 60;
39092
+ const w = (ancho - sizeadosWidth - personalizadosSum) / (headers.length - sizeadosLength - personalizados.length);
39093
+ console.log({
39094
+ w,
39095
+ ancho,
39096
+ sizeadosWidth,
39097
+ sizeadosLength,
39098
+ personalizadosSum,
39099
+ headers: headers.length,
39100
+ personalizados: personalizados.length
39101
+ });
39102
+ setWidths(
39103
+ Object.fromEntries(
39104
+ headers.map((h) => {
39105
+ var _a, _b;
39106
+ return [
39107
+ h,
39108
+ ((_a = context == null ? void 0 : context.colSize) == null ? void 0 : _a[h]) ? (_b = context == null ? void 0 : context.colSize) == null ? void 0 : _b[h] : ["__select__", "__modal__"].includes(h) ? 60 : w
39109
+ ];
39110
+ })
39111
+ )
39112
+ );
39113
+ });
39114
+ observer.observe(tableRef.current);
39115
+ return () => observer.disconnect();
39116
+ }, [headers.length]);
39117
+ const searchedData = context.filteredData.filter((row) => {
39118
+ if (context.searchBy === "") return true;
39119
+ return Object.values(row).some(
39120
+ (value) => String(value).toLowerCase().includes(context.searchBy.toLowerCase())
39121
+ );
39122
+ });
39123
+ return /* @__PURE__ */ jsxs25(
39124
+ "div",
39125
+ {
39126
+ className: [context.className, "bg-white relative"].join(" "),
39127
+ ref: tableRef,
39128
+ children: [
39129
+ /* @__PURE__ */ jsx33("div", { className: "bg-white px-1 font-bold", children: context.header }),
39130
+ /* @__PURE__ */ jsxs25("div", { className: "bg-white flex gap-2 items-center", children: [
39131
+ context.searchable && /* @__PURE__ */ jsx33(Searchable, { context }),
39132
+ context.exportName && /* @__PURE__ */ jsxs25(
39133
+ "button",
39134
+ {
39135
+ onClick: (e) => {
39136
+ context.excel.export(
39137
+ context.data.map((d) => {
39138
+ const { __select__, __modal__, ...datums } = d;
39139
+ return datums;
39140
+ })
39141
+ );
39142
+ },
39143
+ className: "flex gap-1 items-center border shadow rounded p-1 text-white bg-green-800 px-2",
39144
+ children: [
39145
+ /* @__PURE__ */ jsx33(ExcelIcon2, {}),
39146
+ "Exportar"
39147
+ ]
39148
+ }
39149
+ ),
39150
+ context.onSelect && /* @__PURE__ */ jsx33(
39151
+ "button",
39152
+ {
39153
+ className: "border shadow rounded p-1 text-white px-2 " + (context.selected.length > 0 ? "bg-blue-500" : "bg-gray-500"),
39154
+ disabled: context.selected.length == 0,
39155
+ onClick: async (e) => {
39156
+ setIsloading(true);
39157
+ const ex = context.filteredData.filter((d) => context.selected.includes(d.id)).map((d) => {
39158
+ const { __select__, __modal__, ...datums } = d;
39159
+ return datums;
39160
+ });
39161
+ await context.onSelect(ex);
39162
+ setIsloading(false);
39163
+ },
39164
+ children: (context == null ? void 0 : context.onSelectLabel) || "Guardar selecci\xF3n"
39165
+ }
39166
+ ),
39167
+ context.onSave && /* @__PURE__ */ jsx33(
39168
+ "button",
39169
+ {
39170
+ className: "border shadow rounded p-1 text-white px-2 " + (context.editions.length > 0 ? "bg-blue-500" : "bg-gray-500"),
39171
+ disabled: context.editions.length == 0,
39172
+ onClick: async (e) => {
39173
+ setIsloading(true);
39174
+ const ex = context.filteredData.map((d) => {
39175
+ const { __select__, __modal__, ...datums } = d;
39176
+ return datums;
39177
+ });
39178
+ await context.onSave(ex);
39179
+ setIsloading(false);
39180
+ },
39181
+ children: context.onSaveLabel || "Guardar cambios"
39182
+ }
39183
+ )
39184
+ ] }),
39185
+ /* @__PURE__ */ jsxs25("div", { className: "grid ", style: { gridTemplateColumns }, children: [
39186
+ headers.map((header, i) => {
39187
+ var _a, _b;
39188
+ if ((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, header)) return null;
39189
+ return /* @__PURE__ */ jsxs25(
39190
+ "div",
39191
+ {
39192
+ className: "bg-white",
39193
+ style: { position: "relative" },
39194
+ children: [
39195
+ /* @__PURE__ */ jsx33(
39196
+ Header,
39197
+ {
39198
+ padding,
39199
+ header,
39200
+ context,
39201
+ drag: { gridTemplateColumns, startDrag, widths }
39202
+ }
39203
+ ),
39204
+ i < headers.length - 1 && /* @__PURE__ */ jsx33(
39205
+ "div",
39206
+ {
39207
+ onMouseDown: (e) => startDrag(e, header),
39208
+ style: {
39209
+ position: "absolute",
39210
+ right: -3,
39211
+ top: 0,
39212
+ width: 6,
39213
+ height: "100%",
39214
+ cursor: "col-resize",
39215
+ background: "transparent"
39216
+ },
39217
+ onMouseEnter: (e) => e.currentTarget.style.background = "var(--border-strong, #ccc)",
39218
+ onMouseLeave: (e) => e.currentTarget.style.background = "transparent"
39219
+ }
39220
+ )
39221
+ ]
39222
+ },
39223
+ header
39224
+ );
39225
+ }),
39226
+ searchedData.map((row, rowIndex) => {
39227
+ const items = Object.entries(row);
39228
+ return items.map(([key, item], i) => {
39229
+ var _a, _b, _c, _d, _e, _f, _g;
39230
+ if ((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, key)) return null;
39231
+ if (key == "__modal__") {
39232
+ return /* @__PURE__ */ jsx33(
39233
+ "div",
39234
+ {
39235
+ onMouseEnter: (e) => setCurrentIndex(rowIndex),
39236
+ style: {
39237
+ height: `${padding}px`
39238
+ },
39239
+ 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" : ""),
39240
+ children: (context == null ? void 0 : context.modalButton) || /* @__PURE__ */ jsx33(
39241
+ "button",
39242
+ {
39243
+ className: "border shadow rounded bg-blue-500 text-white p-2 ",
39244
+ onClick: (e) => {
39245
+ var _a2;
39246
+ setCurrentIndex(rowIndex);
39247
+ (_a2 = modalRef.current) == null ? void 0 : _a2.click();
39248
+ },
39249
+ children: /* @__PURE__ */ jsx33(EditIcon3, {})
39250
+ }
39251
+ )
39252
+ },
39253
+ row.id + i
39254
+ );
39255
+ }
39256
+ if (key == "__select__") {
39257
+ return /* @__PURE__ */ jsx33(
39258
+ "div",
39259
+ {
39260
+ onMouseEnter: (e) => setCurrentIndex(rowIndex),
39261
+ style: {
39262
+ height: `${padding}px`
39263
+ },
39264
+ 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" : ""),
39265
+ children: /* @__PURE__ */ jsx33(
39266
+ "input",
39267
+ {
39268
+ type: "checkbox",
39269
+ className: "w-5 h-5 accent-blue-600 transition-all duration-300 checked:scale-110 ",
39270
+ checked: Boolean(
39271
+ context.selected.find((s) => s == (row == null ? void 0 : row.id))
39272
+ ),
39273
+ onChange: (e) => {
39274
+ const newSelected = [...context.selected];
39275
+ const index = newSelected.findIndex((s) => s == (row == null ? void 0 : row.id));
39276
+ if (index >= 0) {
39277
+ newSelected.splice(index, 1);
39278
+ } else {
39279
+ newSelected.push(row == null ? void 0 : row.id);
39280
+ }
39281
+ context.setSelected(newSelected);
39282
+ }
39283
+ }
39284
+ )
39285
+ },
39286
+ row.id + i
39287
+ );
39288
+ }
39289
+ return /* @__PURE__ */ jsx33(
39290
+ "div",
39291
+ {
39292
+ onMouseEnter: (e) => setCurrentIndex(rowIndex),
39293
+ style: {
39294
+ fontSize: context.fontSize,
39295
+ ...(context == null ? void 0 : context.wrapText) ? { minHeight: `${padding}px` } : { height: `${padding}px` }
39296
+ },
39297
+ 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 " : ""),
39298
+ children: (context == null ? void 0 : context.editableFields) && context.editableFields.includes(key) ? /* @__PURE__ */ jsx33(
39299
+ "input",
39300
+ {
39301
+ defaultValue: item,
39302
+ className: "w-full " + (context.editions.includes(row == null ? void 0 : row.id) ? "bg-blue-400 text-white" : "bg-blue-100"),
39303
+ onBlur: (e) => {
39304
+ const id = row == null ? void 0 : row.id;
39305
+ const newData = [...context.data];
39306
+ const index = newData.findIndex((d) => +d.id == +id);
39307
+ newData[index][key] = e.target.value;
39308
+ context.setData(newData);
39309
+ const newEditions = [
39310
+ .../* @__PURE__ */ new Set([...context.editions, id])
39311
+ ];
39312
+ context.setEditions(newEditions);
39313
+ }
39314
+ }
39315
+ ) : ((_c = context.buttons) == null ? void 0 : _c[key]) ? React10.cloneElement(context.buttons[key], {
39316
+ // children: context.buttons[key]?.props?.children
39317
+ // ? item
39318
+ // : undefined,
39319
+ value: item,
39320
+ children: ((_e = (_d = context.buttons[key]) == null ? void 0 : _d.props) == null ? void 0 : _e.children) ? item : null,
39321
+ onClick: async (e) => {
39322
+ var _a2, _b2;
39323
+ const ret = await ((_b2 = (_a2 = context.buttons[key].props) == null ? void 0 : _a2.onClick) == null ? void 0 : _b2.call(_a2, e)) || {};
39324
+ const newData = [...context.data];
39325
+ const index = newData.findIndex((f) => f.id == (row == null ? void 0 : row.id));
39326
+ newData[index] = { ...newData[index], ...ret };
39327
+ context.setData(newData);
39328
+ },
39329
+ onChange: async (e) => {
39330
+ var _a2, _b2, _c2;
39331
+ const value = e.target.value;
39332
+ const ret = await ((_b2 = (_a2 = context.buttons[key].props) == null ? void 0 : _a2.onChange) == null ? void 0 : _b2.call(_a2, e)) || {};
39333
+ const newData = [...context.data];
39334
+ const index = newData.findIndex((f) => f.id == (row == null ? void 0 : row.id));
39335
+ if (index >= 0) {
39336
+ newData[index][key] = value;
39337
+ }
39338
+ for (let i2 in ret) {
39339
+ if ((_c2 = newData[index]) == null ? void 0 : _c2[i2]) {
39340
+ const v = ret[i2];
39341
+ newData[index][i2] = v;
39342
+ }
39343
+ }
39344
+ context.setData(newData);
39345
+ },
39346
+ className: `${(_g = (_f = context.buttons[key]) == null ? void 0 : _f.props) == null ? void 0 : _g.className} text-xs w-full`
39347
+ }) : ["number", "string"].includes(typeof item) ? valueFormatter({
39348
+ value: item,
39349
+ currentCoin: context.currentCoin
39350
+ }) : JSON.stringify(item)
39351
+ },
39352
+ row.id + i
39353
+ );
39354
+ });
39355
+ }),
39356
+ Object.keys((context == null ? void 0 : context.footer) || {}).length > 0 && headers.map((header) => {
39357
+ var _a;
39358
+ return /* @__PURE__ */ jsx33(
39359
+ "div",
39360
+ {
39361
+ style: {
39362
+ height: `${padding}px`,
39363
+ maxHeight: "100px"
39364
+ },
39365
+ className: "border-b font-bold bg-white flex items-center justify-center",
39366
+ children: valueFormatter({
39367
+ currentCoin: context.currentCoin,
39368
+ value: ((_a = context.footer) == null ? void 0 : _a[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) : "" : ""
39369
+ })
39370
+ },
39371
+ header
39372
+ );
39373
+ })
39374
+ ] }),
39375
+ context.modal && /* @__PURE__ */ jsx33(
39376
+ Modal,
39377
+ {
39378
+ button: /* @__PURE__ */ jsx33("button", { ref: modalRef }),
39379
+ color: "white",
39380
+ onClose: async () => {
39381
+ var _a;
39382
+ const c = await ((_a = context == null ? void 0 : context.onCloseModal) == null ? void 0 : _a.call(context, searchedData[currentIndex]));
39383
+ return c;
39384
+ },
39385
+ children: /* @__PURE__ */ jsxs25("div", { className: "relative", children: [
39386
+ /* @__PURE__ */ jsxs25("div", { className: "fixed top-0 left-0 p-10 ", children: [
39387
+ /* @__PURE__ */ jsx33(
39388
+ "button",
39389
+ {
39390
+ className: "p-2 border shadow rounded " + (currentIndex > 0 ? "bg-white " : "bg-gray-100"),
39391
+ onClick: (e) => {
39392
+ currentIndex > 0 && setCurrentIndex(currentIndex - 1);
39393
+ },
39394
+ children: "Anterior"
39395
+ }
39396
+ ),
39397
+ /* @__PURE__ */ jsx33(
39398
+ "button",
39399
+ {
39400
+ className: "p-2 border shadow rounded " + (currentIndex < searchedData.length - 1 ? "bg-white " : "bg-gray-100"),
39401
+ onClick: (e) => {
39402
+ currentIndex < searchedData.length - 1 && setCurrentIndex(currentIndex + 1);
39403
+ },
39404
+ children: "Siguiente"
39405
+ }
39406
+ )
39407
+ ] }),
39408
+ React10.cloneElement(context.modal, {
39409
+ row: searchedData[currentIndex]
39410
+ })
39411
+ ] })
39412
+ }
39413
+ ),
39414
+ isLoading && /* @__PURE__ */ jsx33(
39415
+ "div",
39416
+ {
39417
+ className: "bg-white/40 absolute inset-0 text-black flex items-center justify-center",
39418
+ style: { zIndex: 9999999 },
39419
+ children: "Loading..."
39420
+ }
39421
+ )
39422
+ ]
39423
+ }
39424
+ );
39425
+ }
39426
+ function valueFormatter({
39427
+ value,
39428
+ currentCoin = ""
39429
+ }) {
39430
+ if (value == null || value === "") return "";
39431
+ const isDate = /(\d{4}-\d{2}-\d{2})(T[\d:,.+-]*(Z)?)?/;
39432
+ if (`${value}`.match(isDate)) {
39433
+ return value.toString().split("T")[0].split("-").reverse().join("/");
39434
+ }
39435
+ const splited = `${value}`.split(".");
39436
+ const hasDecimals = splited.length == 2 && splited.every((v) => `${v}`.match(types_default.number));
39437
+ if (hasDecimals) {
39438
+ return [
39439
+ currentCoin,
39440
+ (+`${value}`).toLocaleString("en-US", {
39441
+ minimumFractionDigits: 2,
39442
+ maximumFractionDigits: 2
39443
+ })
39444
+ ].join(" ");
39445
+ }
39446
+ return value;
39447
+ }
39448
+
39449
+ // src/table-advanced/context.ts
39450
+ import { useEffect as useEffect12, useMemo as useMemo9, useReducer as useReducer3, useState as useState16 } from "react";
39451
+
39452
+ // src/table-advanced/filter.reducer.ts
39453
+ var filterReducer = (acc, b) => {
39454
+ if (b == null) return [];
39455
+ const newAcc = [];
39456
+ newAcc.push(b);
39457
+ return newAcc;
39458
+ };
39459
+
39460
+ // src/table-advanced/sort.reducer.ts
39461
+ var sortReducer = (acc, b) => {
39462
+ var _a;
39463
+ const oldAcc = [...acc];
39464
+ const newAcc = [];
39465
+ const keys2 = Object.keys(b);
39466
+ const k = keys2[0];
39467
+ let newType = b[k];
39468
+ if (b[k] == "TOGGLE") {
39469
+ newType = ((_a = oldAcc == null ? void 0 : oldAcc[0]) == null ? void 0 : _a.type) == "ASC" ? "DESC" : "ASC";
39470
+ }
39471
+ newAcc.push({ field: k, type: newType });
39472
+ return newAcc;
39473
+ };
39474
+
39475
+ // src/table-advanced/context.ts
39476
+ function useContext({ onSelect }) {
39477
+ const excel = useExcel();
39478
+ const [editions, setEditions] = useState16([]);
39479
+ const [selected, setSelected] = useState16([]);
39480
+ const [data, setData] = useState16([]);
39481
+ const headers = [...new Set(data.map((b) => Object.keys(b)).flat())];
39482
+ const [currentHeader, setCurrentHeader] = useState16(null);
39483
+ const cols = headers.length;
39484
+ const [filters, setFilters] = useReducer3(
39485
+ filterReducer,
39486
+ new Array()
39487
+ );
39488
+ const [searchBy, setSearchBy] = useState16("");
39489
+ const [sort, setSort] = useReducer3(sortReducer, new Array());
39490
+ const sortedData = useMemo9(() => {
39491
+ return [...data].sort((a, b) => {
39492
+ for (const { field, type } of sort.reverse()) {
39493
+ const av = a[field];
39494
+ const bv = b[field];
39495
+ if (av == null && bv == null) continue;
39496
+ if (av == null) return 1;
39497
+ if (bv == null) return -1;
39498
+ let cmp;
39499
+ if (typeof av === "number" && typeof bv === "number") {
39500
+ cmp = av - bv;
39501
+ } else {
39502
+ cmp = `${av}`.localeCompare(`${bv}`, void 0, { numeric: true });
39503
+ }
39504
+ if (cmp !== 0) {
39505
+ return type === "DESC" ? -cmp : cmp;
39506
+ }
39507
+ }
39508
+ return 0;
39509
+ });
39510
+ }, [data, sort]);
39511
+ const filteredData = [...sortedData].filter((d) => {
39512
+ if (editions.includes(d == null ? void 0 : d.id)) return true;
39513
+ for (const { field, values } of filters) {
39514
+ if (!values.includes(d[field])) {
39515
+ return false;
39516
+ }
39517
+ }
39518
+ return true;
39519
+ });
39520
+ useEffect12(() => {
39521
+ if (filters.length == 0) {
39522
+ setEditions([]);
39523
+ }
39524
+ }, [filters]);
39525
+ return {
39526
+ currentHeader,
39527
+ setCurrentHeader,
39528
+ sort,
39529
+ setSort,
39530
+ cols,
39531
+ headers,
39532
+ data,
39533
+ sortedData,
39534
+ filters,
39535
+ setFilters,
39536
+ filteredData,
39537
+ setData,
39538
+ searchBy,
39539
+ setSearchBy,
39540
+ selected,
39541
+ setSelected,
39542
+ editions,
39543
+ excel,
39544
+ setEditions
39545
+ };
39546
+ }
39547
+
39548
+ // src/table-advanced/index.tsx
39549
+ import { jsx as jsx34 } from "react/jsx-runtime";
39550
+ function TableAdvanced(tableProps) {
39551
+ const { data, ...props } = tableProps;
39552
+ const context = useContext({ onSelect: Boolean(tableProps.onSelect) });
39553
+ useEffect13(() => {
39554
+ context.setData(
39555
+ Array.isArray(data) ? data.map((d) => {
39556
+ return {
39557
+ ...(tableProps == null ? void 0 : tableProps.modal) ? { __modal__: "" } : {},
39558
+ ...(tableProps == null ? void 0 : tableProps.onSelect) ? { __select__: "" } : {},
39559
+ ...d
39560
+ };
39561
+ }) : data
39562
+ );
39563
+ }, [data]);
39564
+ useEffect13(() => {
39565
+ if (tableProps == null ? void 0 : tableProps.sortBy) {
39566
+ const [k, v] = Object.entries(tableProps.sortBy)[0];
39567
+ context.setSort({ [k]: v });
39568
+ }
39569
+ }, [tableProps == null ? void 0 : tableProps.sortBy]);
39570
+ if (Array.isArray(data) && data.length > 0) {
39571
+ if (data.every((d) => !(d == null ? void 0 : d.id))) {
39572
+ throw new Error("All data rows must have an 'id' property.");
39573
+ }
39574
+ if ((props == null ? void 0 : props.onSave) && props.onSelect) {
39575
+ throw new Error("Must have only one of onSave or onSelect");
39576
+ }
39577
+ return /* @__PURE__ */ jsx34(HTable, { context: { ...context, ...props } });
39578
+ }
39579
+ return null;
39580
+ }
38447
39581
  export {
38448
39582
  Alert,
38449
39583
  Button,
@@ -38457,6 +39591,7 @@ export {
38457
39591
  Select,
38458
39592
  Table,
38459
39593
  Table3,
39594
+ TableAdvanced,
38460
39595
  TextArea,
38461
39596
  regular_expresions_default as regularExpresions,
38462
39597
  useDates,