next-recomponents 2.0.41 → 2.0.43

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