next-recomponents 2.0.40 → 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.d.mts +53 -13
- package/dist/index.d.ts +53 -13
- package/dist/index.js +1157 -26
- package/dist/index.mjs +1162 -27
- package/package.json +1 -1
- package/src/index.tsx +1 -0
- package/src/input/index.tsx +4 -4
- package/src/modal/index.tsx +8 -4
- package/src/pop/color.tsx +1 -1
- package/src/pop/index.tsx +22 -9
- package/src/pop/overlay.tsx +5 -3
- package/src/pop/types.ts +1 -1
- package/src/select/index.tsx +2 -2
- package/src/table/index.tsx +6 -8
- package/src/table-advanced/context.ts +88 -0
- package/src/table-advanced/filter.reducer.ts +19 -0
- package/src/table-advanced/h.table.tsx +579 -0
- package/src/table-advanced/header.tsx +335 -0
- package/src/table-advanced/icons.tsx +167 -0
- package/src/table-advanced/index.tsx +43 -0
- package/src/table-advanced/menu.item.tsx +21 -0
- package/src/table-advanced/searchable.tsx +24 -0
- package/src/table-advanced/sort.reducer.ts +29 -0
- package/src/table-advanced/types.ts +82 -0
- package/src/text-area/index.tsx +2 -2
package/dist/index.js
CHANGED
|
@@ -3500,6 +3500,7 @@ __export(index_exports, {
|
|
|
3500
3500
|
Select: () => Select,
|
|
3501
3501
|
Table: () => Table,
|
|
3502
3502
|
Table3: () => Table3,
|
|
3503
|
+
TableAdvanced: () => TableAdvanced,
|
|
3503
3504
|
TextArea: () => TextArea,
|
|
3504
3505
|
regularExpresions: () => regular_expresions_default,
|
|
3505
3506
|
useDates: () => useDates,
|
|
@@ -3890,15 +3891,15 @@ function Input({
|
|
|
3890
3891
|
const isPassword = props.type === "password";
|
|
3891
3892
|
const [showPassword, setShowPassword] = (0, import_react4.useState)(false);
|
|
3892
3893
|
const svg = icon;
|
|
3893
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "w-full relative", children: [
|
|
3894
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "relative flex items-center border rounded bg-white pr-1 mb-5", children: [
|
|
3894
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "w-full relative my-3", children: [
|
|
3895
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "relative flex items-center border rounded bg-white pr-1 mb-5 w-full", children: [
|
|
3895
3896
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
3896
3897
|
"input",
|
|
3897
3898
|
{
|
|
3898
3899
|
...props,
|
|
3899
3900
|
type: isPassword && showPassword ? "text" : props.type,
|
|
3900
3901
|
className: [
|
|
3901
|
-
"
|
|
3902
|
+
"block p-2 w-full bg-transparent min-w-0",
|
|
3902
3903
|
isPassword && "pr-10",
|
|
3903
3904
|
value !== "" && !isValid && "bg-red-200 text-black",
|
|
3904
3905
|
value !== "" && isValid && "bg-green-200 text-black",
|
|
@@ -3906,7 +3907,7 @@ function Input({
|
|
|
3906
3907
|
].filter(Boolean).join(" ")
|
|
3907
3908
|
}
|
|
3908
3909
|
),
|
|
3909
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("label", { className: "absolute -top-2.5 left-2 text-xs font-bold
|
|
3910
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("label", { className: "absolute -top-2.5 left-2 text-xs font-bold px-1", children: [
|
|
3910
3911
|
label,
|
|
3911
3912
|
(props == null ? void 0 : props.required) && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "text-red-500 ml-1", children: "*" })
|
|
3912
3913
|
] }),
|
|
@@ -36177,7 +36178,7 @@ function TextArea({
|
|
|
36177
36178
|
...props
|
|
36178
36179
|
}) {
|
|
36179
36180
|
const [value, setValue] = (0, import_react6.useState)((props == null ? void 0 : props.value) || "");
|
|
36180
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "w-full relative
|
|
36181
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "w-full relative my-3", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "relative flex items-center border rounded bg-white ", children: [
|
|
36181
36182
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
36182
36183
|
"textarea",
|
|
36183
36184
|
{
|
|
@@ -36194,7 +36195,7 @@ function TextArea({
|
|
|
36194
36195
|
}
|
|
36195
36196
|
),
|
|
36196
36197
|
" ",
|
|
36197
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("label", { className: "absolute -top-2.5 left-2 text-xs font-bold
|
|
36198
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("label", { className: "absolute -top-2.5 left-2 text-xs font-bold px-1", children: [
|
|
36198
36199
|
label,
|
|
36199
36200
|
" ",
|
|
36200
36201
|
(props == null ? void 0 : props.required) && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "text-red-500", children: "*" })
|
|
@@ -36814,7 +36815,7 @@ function Select({
|
|
|
36814
36815
|
}
|
|
36815
36816
|
}
|
|
36816
36817
|
}, [isOpen]);
|
|
36817
|
-
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { ref: containerRef, className: "w-full relative
|
|
36818
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { ref: containerRef, className: "w-full relative my-3", children: [
|
|
36818
36819
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "relative flex items-center border rounded bg-white", children: [
|
|
36819
36820
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
36820
36821
|
"input",
|
|
@@ -36852,7 +36853,7 @@ function Select({
|
|
|
36852
36853
|
onKeyDown: handleKeyDown
|
|
36853
36854
|
}
|
|
36854
36855
|
),
|
|
36855
|
-
label && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("label", { className: "absolute -top-2.5 left-2 text-xs font-bold
|
|
36856
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("label", { className: "absolute -top-2.5 left-2 text-xs font-bold px-1", children: [
|
|
36856
36857
|
label,
|
|
36857
36858
|
" ",
|
|
36858
36859
|
(props == null ? void 0 : props.required) && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "text-red-500", children: "*" })
|
|
@@ -37024,7 +37025,7 @@ var COLOR_CONFIG = {
|
|
|
37024
37025
|
label: "\u25CE"
|
|
37025
37026
|
},
|
|
37026
37027
|
white: {
|
|
37027
|
-
bg: "from-
|
|
37028
|
+
bg: "from-white to-white",
|
|
37028
37029
|
iconBg: "bg-gray-100",
|
|
37029
37030
|
iconText: "text-gray-500",
|
|
37030
37031
|
border: "border-gray-200",
|
|
@@ -37085,7 +37086,7 @@ function PopupOverlay({
|
|
|
37085
37086
|
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
|
|
37086
37087
|
"div",
|
|
37087
37088
|
{
|
|
37088
|
-
className: "fixed inset-0 flex items-center justify-center z-[1000]
|
|
37089
|
+
className: "fixed inset-0 flex items-center justify-center z-[1000] overflow-auto p-1",
|
|
37089
37090
|
style: { background: "rgba(15,23,42,0.45)", backdropFilter: "blur(2px)" },
|
|
37090
37091
|
children: [
|
|
37091
37092
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("style", { children: `
|
|
@@ -37097,7 +37098,7 @@ function PopupOverlay({
|
|
|
37097
37098
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
|
|
37098
37099
|
"div",
|
|
37099
37100
|
{
|
|
37100
|
-
className: `bg-gradient-to-br ${c.bg} border ${c.border} ${popup.full == true ? " w-
|
|
37101
|
+
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`,
|
|
37101
37102
|
style: { animation: "fadeInScale 0.18s ease-out", overflow: "auto" },
|
|
37102
37103
|
children: [
|
|
37103
37104
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "flex flex-col items-center gap-3 px-8 pt-8 pb-5 text-center ", children: [
|
|
@@ -37142,7 +37143,7 @@ function PopupOverlay({
|
|
|
37142
37143
|
onEnter: () => onClose(true, popup.inputValue)
|
|
37143
37144
|
}
|
|
37144
37145
|
),
|
|
37145
|
-
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: `border-t ${c.border} mt-4` }),
|
|
37146
|
+
popup.type !== "modal" && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: `border-t ${c.border} mt-4` }),
|
|
37146
37147
|
popup.type !== "modal" && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
37147
37148
|
PopupActions,
|
|
37148
37149
|
{
|
|
@@ -37182,14 +37183,21 @@ function usePopup() {
|
|
|
37182
37183
|
},
|
|
37183
37184
|
[]
|
|
37184
37185
|
);
|
|
37185
|
-
const close = (0, import_react10.useCallback)(
|
|
37186
|
-
|
|
37186
|
+
const close = (0, import_react10.useCallback)(
|
|
37187
|
+
async (confirmed, value) => {
|
|
37187
37188
|
var _a, _b;
|
|
37188
|
-
|
|
37189
|
-
|
|
37190
|
-
|
|
37191
|
-
|
|
37192
|
-
|
|
37189
|
+
const prev = { ...popup };
|
|
37190
|
+
let visible = false;
|
|
37191
|
+
if (confirmed) {
|
|
37192
|
+
(_a = prev.onConfirm) == null ? void 0 : _a.call(prev, value);
|
|
37193
|
+
} else if (prev == null ? void 0 : prev.onCancel) {
|
|
37194
|
+
visible = !Boolean(await ((_b = prev.onCancel) == null ? void 0 : _b.call(prev)));
|
|
37195
|
+
}
|
|
37196
|
+
const data = { ...prev, visible, inputValue: "" };
|
|
37197
|
+
setPopup(data);
|
|
37198
|
+
},
|
|
37199
|
+
[popup]
|
|
37200
|
+
);
|
|
37193
37201
|
const alert2 = (0, import_react10.useCallback)(
|
|
37194
37202
|
(message, color = "primary") => new Promise(
|
|
37195
37203
|
(resolve) => open({
|
|
@@ -37203,13 +37211,17 @@ function usePopup() {
|
|
|
37203
37211
|
[open]
|
|
37204
37212
|
);
|
|
37205
37213
|
const modal = (0, import_react10.useCallback)(
|
|
37206
|
-
(message, color = "primary", icons = false, full = false) => new Promise(
|
|
37214
|
+
(message, color = "primary", icons = false, full = false, onClose) => new Promise(
|
|
37207
37215
|
(resolve) => open({
|
|
37208
37216
|
type: "modal",
|
|
37209
37217
|
message,
|
|
37210
37218
|
color,
|
|
37211
|
-
onConfirm: () =>
|
|
37212
|
-
|
|
37219
|
+
// onConfirm: () => {
|
|
37220
|
+
// resolve();
|
|
37221
|
+
// },
|
|
37222
|
+
onCancel: async () => {
|
|
37223
|
+
return await (onClose == null ? void 0 : onClose());
|
|
37224
|
+
},
|
|
37213
37225
|
icons,
|
|
37214
37226
|
full
|
|
37215
37227
|
})
|
|
@@ -37269,10 +37281,13 @@ function Modal({
|
|
|
37269
37281
|
button,
|
|
37270
37282
|
children,
|
|
37271
37283
|
color = "primary",
|
|
37272
|
-
title
|
|
37284
|
+
title,
|
|
37285
|
+
onClose
|
|
37273
37286
|
}) {
|
|
37274
37287
|
const pop = usePopup();
|
|
37275
|
-
const hide = () =>
|
|
37288
|
+
const hide = () => {
|
|
37289
|
+
pop.close(false);
|
|
37290
|
+
};
|
|
37276
37291
|
const childrenWithHide = (0, import_react11.useMemo)(
|
|
37277
37292
|
() => (0, import_react11.cloneElement)(children, { hide }),
|
|
37278
37293
|
[children]
|
|
@@ -37282,11 +37297,11 @@ function Modal({
|
|
|
37282
37297
|
}, [childrenWithHide]);
|
|
37283
37298
|
const props = button == null ? void 0 : button.props;
|
|
37284
37299
|
const onClick = props == null ? void 0 : props.onClick;
|
|
37285
|
-
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
37300
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "", children: [
|
|
37286
37301
|
(0, import_react11.cloneElement)(button, {
|
|
37287
37302
|
onClick: (e) => {
|
|
37288
37303
|
onClick == null ? void 0 : onClick(e);
|
|
37289
|
-
pop.modal(childrenWithHide, color, false, true);
|
|
37304
|
+
pop.modal(childrenWithHide, color, false, true, onClose);
|
|
37290
37305
|
}
|
|
37291
37306
|
}),
|
|
37292
37307
|
pop.PopupComponent
|
|
@@ -38450,6 +38465,1121 @@ function Table3({
|
|
|
38450
38465
|
] })
|
|
38451
38466
|
] });
|
|
38452
38467
|
}
|
|
38468
|
+
|
|
38469
|
+
// src/table-advanced/index.tsx
|
|
38470
|
+
var import_react21 = require("react");
|
|
38471
|
+
|
|
38472
|
+
// src/table-advanced/h.table.tsx
|
|
38473
|
+
var import_react19 = __toESM(require("react"));
|
|
38474
|
+
|
|
38475
|
+
// src/table-advanced/header.tsx
|
|
38476
|
+
var import_react18 = require("react");
|
|
38477
|
+
var import_react_dom = require("react-dom");
|
|
38478
|
+
|
|
38479
|
+
// src/table-advanced/icons.tsx
|
|
38480
|
+
var import_jsx_runtime32 = require("react/jsx-runtime");
|
|
38481
|
+
function DropIcon() {
|
|
38482
|
+
return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(
|
|
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__ */ (0, import_jsx_runtime32.jsx)("circle", { cx: "256", cy: "256", r: "48" }),
|
|
38495
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)("circle", { cx: "256", cy: "416", r: "48" }),
|
|
38496
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)("circle", { cx: "256", cy: "96", r: "48" })
|
|
38497
|
+
]
|
|
38498
|
+
}
|
|
38499
|
+
);
|
|
38500
|
+
}
|
|
38501
|
+
function EditIcon3() {
|
|
38502
|
+
return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
|
|
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__ */ (0, import_jsx_runtime32.jsx)("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__ */ (0, import_jsx_runtime32.jsx)(
|
|
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__ */ (0, import_jsx_runtime32.jsx)("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__ */ (0, import_jsx_runtime32.jsxs)(
|
|
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__ */ (0, import_jsx_runtime32.jsx)(
|
|
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__ */ (0, import_jsx_runtime32.jsxs)("g", { fill: "#2196F3", children: [
|
|
38554
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)("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__ */ (0, import_jsx_runtime32.jsx)("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__ */ (0, import_jsx_runtime32.jsxs)(
|
|
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__ */ (0, import_jsx_runtime32.jsxs)("g", { fill: "#2196F3", children: [
|
|
38577
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)("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__ */ (0, import_jsx_runtime32.jsx)("path", { d: "M12.4,17.7H20v2.5H8.4v-1.9L16,7.5H8.4V5h11.4v1.7L12.4,17.7z" })
|
|
38579
|
+
] }),
|
|
38580
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
|
|
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__ */ (0, import_jsx_runtime32.jsx)(
|
|
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__ */ (0, import_jsx_runtime32.jsx)("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__ */ (0, import_jsx_runtime32.jsx)(
|
|
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__ */ (0, import_jsx_runtime32.jsx)("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__ */ (0, import_jsx_runtime32.jsxs)(
|
|
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__ */ (0, import_jsx_runtime32.jsx)("path", { fill: "none", d: "M0 0h24v24H0z" }),
|
|
38637
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)("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__ */ (0, import_jsx_runtime32.jsxs)(
|
|
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__ */ (0, import_jsx_runtime32.jsx)("path", { fill: "none", d: "M0 0h24v24H0zM0 0h24m0 24H0" }),
|
|
38656
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)("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
|
+
var import_jsx_runtime33 = require("react/jsx-runtime");
|
|
38664
|
+
function MenuItem({
|
|
38665
|
+
label,
|
|
38666
|
+
icon,
|
|
38667
|
+
onClick
|
|
38668
|
+
}) {
|
|
38669
|
+
return /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(
|
|
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
|
+
var import_jsx_runtime34 = require("react/jsx-runtime");
|
|
38684
|
+
function Header({
|
|
38685
|
+
header,
|
|
38686
|
+
context,
|
|
38687
|
+
drag,
|
|
38688
|
+
padding
|
|
38689
|
+
}) {
|
|
38690
|
+
const [visible, setVisible] = (0, import_react18.useState)(false);
|
|
38691
|
+
const sortIndex = context.sort.findIndex((b) => b.field == header);
|
|
38692
|
+
const [text, setText] = (0, import_react18.useState)("");
|
|
38693
|
+
const cellRef = (0, import_react18.useRef)(null);
|
|
38694
|
+
const [coords, setCoords] = (0, import_react18.useState)(
|
|
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] = (0, import_react18.useState)([...filteredValues]);
|
|
38704
|
+
const hasFilter = context.filters.find((b) => b.field == header);
|
|
38705
|
+
(0, import_react18.useEffect)(() => {
|
|
38706
|
+
if (visible) {
|
|
38707
|
+
context.setCurrentHeader(header);
|
|
38708
|
+
}
|
|
38709
|
+
setText("");
|
|
38710
|
+
}, [visible]);
|
|
38711
|
+
(0, import_react18.useEffect)(() => {
|
|
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__ */ (0, import_jsx_runtime34.jsx)("div", { className: "", children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
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__ */ (0, import_jsx_runtime34.jsx)("div", { className: "", children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
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__ */ (0, import_jsx_runtime34.jsx)(
|
|
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__ */ (0, import_jsx_runtime34.jsx)("div", { className: "", children: /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(
|
|
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__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex gap-5 items-center justify-between h-full cursor-pointer", children: [
|
|
38775
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex gap-2", children: [
|
|
38776
|
+
hasFilter ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
38777
|
+
"div",
|
|
38778
|
+
{
|
|
38779
|
+
className: "cursor-pointer",
|
|
38780
|
+
onClick: (e) => {
|
|
38781
|
+
context.setFilters(null);
|
|
38782
|
+
setSelected(filteredValues);
|
|
38783
|
+
},
|
|
38784
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(FilterIcon, {})
|
|
38785
|
+
}
|
|
38786
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", {}),
|
|
38787
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
38788
|
+
"div",
|
|
38789
|
+
{
|
|
38790
|
+
onClick: (e) => {
|
|
38791
|
+
context.setSort({
|
|
38792
|
+
[header]: "TOGGLE"
|
|
38793
|
+
});
|
|
38794
|
+
},
|
|
38795
|
+
children: sortIndex >= 0 ? context.sort[sortIndex].type === "ASC" ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(ArrowUPIcon, {}) : /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(ArrowDownIcon2, {}) : /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", {})
|
|
38796
|
+
}
|
|
38797
|
+
)
|
|
38798
|
+
] }),
|
|
38799
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
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__ */ (0, import_jsx_runtime34.jsx)(
|
|
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__ */ (0, import_jsx_runtime34.jsx)(DropIcon, {})
|
|
38818
|
+
}
|
|
38819
|
+
)
|
|
38820
|
+
] }),
|
|
38821
|
+
context.currentHeader != header && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
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 && (0, import_react_dom.createPortal)(
|
|
38830
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(import_jsx_runtime34.Fragment, { children: [
|
|
38831
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
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__ */ (0, import_jsx_runtime34.jsx)(
|
|
38842
|
+
"div",
|
|
38843
|
+
{
|
|
38844
|
+
className: "fixed",
|
|
38845
|
+
style: { top: coords.top, left: coords.left, zIndex: 9999 },
|
|
38846
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "bg-gray-100 w-[300px] flex flex-col border shadow rounded ", children: [
|
|
38847
|
+
hasFilter && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
38848
|
+
MenuItem,
|
|
38849
|
+
{
|
|
38850
|
+
label: "Quitar filtro",
|
|
38851
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(FilterIcon, {}),
|
|
38852
|
+
onClick: (e) => {
|
|
38853
|
+
setVisible(false);
|
|
38854
|
+
context.setFilters(null);
|
|
38855
|
+
setSelected(filteredValues);
|
|
38856
|
+
}
|
|
38857
|
+
}
|
|
38858
|
+
),
|
|
38859
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
38860
|
+
MenuItem,
|
|
38861
|
+
{
|
|
38862
|
+
label: "Orenar de A a Z",
|
|
38863
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(OrderAscIcon, {}),
|
|
38864
|
+
onClick: (e) => {
|
|
38865
|
+
setVisible(false);
|
|
38866
|
+
context.setSort({ [header]: "ASC" });
|
|
38867
|
+
context.setCurrentHeader(null);
|
|
38868
|
+
}
|
|
38869
|
+
}
|
|
38870
|
+
),
|
|
38871
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
38872
|
+
MenuItem,
|
|
38873
|
+
{
|
|
38874
|
+
label: "Orenar de Z a A",
|
|
38875
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(OrderDesIcon, {}),
|
|
38876
|
+
onClick: (e) => {
|
|
38877
|
+
setVisible(false);
|
|
38878
|
+
context.setSort({ [header]: "DESC" });
|
|
38879
|
+
context.setCurrentHeader(null);
|
|
38880
|
+
}
|
|
38881
|
+
}
|
|
38882
|
+
),
|
|
38883
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(
|
|
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__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "m-2 bg-white gap-2 flex flex-col", children: [
|
|
38899
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
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__ */ (0, import_jsx_runtime34.jsxs)(
|
|
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__ */ (0, import_jsx_runtime34.jsxs)(
|
|
38915
|
+
"div",
|
|
38916
|
+
{
|
|
38917
|
+
className: "flex gap-2 " + (text != "" ? "text-gray-400" : ""),
|
|
38918
|
+
children: [
|
|
38919
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
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__ */ (0, import_jsx_runtime34.jsx)("div", { className: "truncate", children: "Seleccionar todo" })
|
|
38935
|
+
]
|
|
38936
|
+
}
|
|
38937
|
+
),
|
|
38938
|
+
filteredValues.map((d) => {
|
|
38939
|
+
return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex gap-2 ", children: [
|
|
38940
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
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__ */ (0, import_jsx_runtime34.jsx)("div", { className: "truncate", children: d })
|
|
38959
|
+
] }, d);
|
|
38960
|
+
})
|
|
38961
|
+
]
|
|
38962
|
+
}
|
|
38963
|
+
)
|
|
38964
|
+
] }),
|
|
38965
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex justify-between p-2", children: [
|
|
38966
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
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__ */ (0, import_jsx_runtime34.jsx)("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
|
+
var import_jsx_runtime35 = require("react/jsx-runtime");
|
|
38996
|
+
function Searchable({
|
|
38997
|
+
context
|
|
38998
|
+
}) {
|
|
38999
|
+
return /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("div", { className: "flex justify-start p-2 relative w-96", children: [
|
|
39000
|
+
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
|
|
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__ */ (0, import_jsx_runtime35.jsx)("div", { className: "absolute top-0 right-0 p-5", children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(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/h.table.tsx
|
|
39023
|
+
var import_jsx_runtime36 = require("react/jsx-runtime");
|
|
39024
|
+
function HTable({
|
|
39025
|
+
context
|
|
39026
|
+
}) {
|
|
39027
|
+
const [isLoading, setIsloading] = (0, import_react19.useState)(false);
|
|
39028
|
+
const { cols, headers } = context;
|
|
39029
|
+
const [currentIndex, setCurrentIndex] = (0, import_react19.useState)(-1);
|
|
39030
|
+
const tableRef = (0, import_react19.useRef)(null);
|
|
39031
|
+
const modalRef = (0, import_react19.useRef)(null);
|
|
39032
|
+
const catDensities = { confortable: 80, compact: 30, standard: 53 };
|
|
39033
|
+
const padding = (context == null ? void 0 : context.rowHeight) || (context == null ? void 0 : context.density) ? catDensities[context == null ? void 0 : context.density] : 53;
|
|
39034
|
+
function useResizableColumns(headers2, defaultWidth = 160, minWidth = 60) {
|
|
39035
|
+
function getWidth(h) {
|
|
39036
|
+
return [
|
|
39037
|
+
"__select__",
|
|
39038
|
+
"__modal__",
|
|
39039
|
+
...(context == null ? void 0 : context.hideColumns) || []
|
|
39040
|
+
].includes(h) ? minWidth : defaultWidth;
|
|
39041
|
+
}
|
|
39042
|
+
function resize(headers3) {
|
|
39043
|
+
return Object.fromEntries(headers3.map((h) => [h, getWidth(h)]));
|
|
39044
|
+
}
|
|
39045
|
+
const [widths2, setWidths2] = (0, import_react19.useState)({});
|
|
39046
|
+
const startDrag2 = (0, import_react19.useCallback)(
|
|
39047
|
+
(e, headerKey) => {
|
|
39048
|
+
var _a;
|
|
39049
|
+
e.preventDefault();
|
|
39050
|
+
const startX = e.clientX;
|
|
39051
|
+
const startWidth = (_a = widths2[headerKey]) != null ? _a : defaultWidth;
|
|
39052
|
+
const onMove = (ev) => {
|
|
39053
|
+
const newWidth = Math.max(
|
|
39054
|
+
minWidth,
|
|
39055
|
+
startWidth + (ev.clientX - startX)
|
|
39056
|
+
);
|
|
39057
|
+
setWidths2((prev) => ({ ...prev, [headerKey]: newWidth }));
|
|
39058
|
+
};
|
|
39059
|
+
const onUp = () => {
|
|
39060
|
+
window.removeEventListener("mousemove", onMove);
|
|
39061
|
+
window.removeEventListener("mouseup", onUp);
|
|
39062
|
+
};
|
|
39063
|
+
window.addEventListener("mousemove", onMove);
|
|
39064
|
+
window.addEventListener("mouseup", onUp);
|
|
39065
|
+
},
|
|
39066
|
+
[widths2, defaultWidth, minWidth]
|
|
39067
|
+
);
|
|
39068
|
+
const gridTemplateColumns2 = headers2.filter((h) => {
|
|
39069
|
+
var _a, _b;
|
|
39070
|
+
return !((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, h));
|
|
39071
|
+
}).map((h) => {
|
|
39072
|
+
var _a;
|
|
39073
|
+
return `${(_a = widths2[h]) != null ? _a : defaultWidth}px`;
|
|
39074
|
+
}).join(" ");
|
|
39075
|
+
return { widths: widths2, gridTemplateColumns: gridTemplateColumns2, startDrag: startDrag2, setWidths: setWidths2 };
|
|
39076
|
+
}
|
|
39077
|
+
const { gridTemplateColumns, startDrag, widths, setWidths } = useResizableColumns(headers);
|
|
39078
|
+
(0, import_react19.useEffect)(() => {
|
|
39079
|
+
if (!tableRef.current) return;
|
|
39080
|
+
const observer = new ResizeObserver(([entry]) => {
|
|
39081
|
+
const sizeados = headers.filter(
|
|
39082
|
+
(h) => [
|
|
39083
|
+
"__select__",
|
|
39084
|
+
"__modal__"
|
|
39085
|
+
// ...(context?.hideColumns || []),
|
|
39086
|
+
// ...(context?.colSize ? Object.keys(context.colSize) : []),
|
|
39087
|
+
].includes(h)
|
|
39088
|
+
);
|
|
39089
|
+
const personalizados = (context == null ? void 0 : context.colSize) ? Object.values(context.colSize) : [];
|
|
39090
|
+
const personalizadosSum = personalizados.length > 0 ? personalizados.reduce((acc, i) => acc + i, 0) : 0;
|
|
39091
|
+
const ancho = +entry.contentRect.width;
|
|
39092
|
+
const sizeadosLength = sizeados.length;
|
|
39093
|
+
const sizeadosWidth = sizeadosLength * 60;
|
|
39094
|
+
const w = (ancho - sizeadosWidth - personalizadosSum) / (headers.length - sizeadosLength - personalizados.length);
|
|
39095
|
+
console.log({
|
|
39096
|
+
w,
|
|
39097
|
+
ancho,
|
|
39098
|
+
sizeadosWidth,
|
|
39099
|
+
sizeadosLength,
|
|
39100
|
+
personalizadosSum,
|
|
39101
|
+
headers: headers.length,
|
|
39102
|
+
personalizados: personalizados.length
|
|
39103
|
+
});
|
|
39104
|
+
setWidths(
|
|
39105
|
+
Object.fromEntries(
|
|
39106
|
+
headers.map((h) => {
|
|
39107
|
+
var _a, _b;
|
|
39108
|
+
return [
|
|
39109
|
+
h,
|
|
39110
|
+
((_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
|
|
39111
|
+
];
|
|
39112
|
+
})
|
|
39113
|
+
)
|
|
39114
|
+
);
|
|
39115
|
+
});
|
|
39116
|
+
observer.observe(tableRef.current);
|
|
39117
|
+
return () => observer.disconnect();
|
|
39118
|
+
}, [headers.length]);
|
|
39119
|
+
const searchedData = context.filteredData.filter((row) => {
|
|
39120
|
+
if (context.searchBy === "") return true;
|
|
39121
|
+
return Object.values(row).some(
|
|
39122
|
+
(value) => String(value).toLowerCase().includes(context.searchBy.toLowerCase())
|
|
39123
|
+
);
|
|
39124
|
+
});
|
|
39125
|
+
return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
|
|
39126
|
+
"div",
|
|
39127
|
+
{
|
|
39128
|
+
className: [context.className, "bg-white relative"].join(" "),
|
|
39129
|
+
ref: tableRef,
|
|
39130
|
+
children: [
|
|
39131
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "bg-white px-1 font-bold", children: context.header }),
|
|
39132
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "bg-white flex gap-2 items-center", children: [
|
|
39133
|
+
context.searchable && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(Searchable, { context }),
|
|
39134
|
+
context.exportName && /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
|
|
39135
|
+
"button",
|
|
39136
|
+
{
|
|
39137
|
+
onClick: (e) => {
|
|
39138
|
+
context.excel.export(
|
|
39139
|
+
context.data.map((d) => {
|
|
39140
|
+
const { __select__, __modal__, ...datums } = d;
|
|
39141
|
+
return datums;
|
|
39142
|
+
})
|
|
39143
|
+
);
|
|
39144
|
+
},
|
|
39145
|
+
className: "flex gap-1 items-center border shadow rounded p-1 text-white bg-green-800 px-2",
|
|
39146
|
+
children: [
|
|
39147
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)(ExcelIcon2, {}),
|
|
39148
|
+
"Exportar"
|
|
39149
|
+
]
|
|
39150
|
+
}
|
|
39151
|
+
),
|
|
39152
|
+
context.onSelect && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
39153
|
+
"button",
|
|
39154
|
+
{
|
|
39155
|
+
className: "border shadow rounded p-1 text-white px-2 " + (context.selected.length > 0 ? "bg-blue-500" : "bg-gray-500"),
|
|
39156
|
+
disabled: context.selected.length == 0,
|
|
39157
|
+
onClick: async (e) => {
|
|
39158
|
+
setIsloading(true);
|
|
39159
|
+
const ex = context.filteredData.filter((d) => context.selected.includes(d.id)).map((d) => {
|
|
39160
|
+
const { __select__, __modal__, ...datums } = d;
|
|
39161
|
+
return datums;
|
|
39162
|
+
});
|
|
39163
|
+
await context.onSelect(ex);
|
|
39164
|
+
setIsloading(false);
|
|
39165
|
+
},
|
|
39166
|
+
children: (context == null ? void 0 : context.onSelectLabel) || "Guardar selecci\xF3n"
|
|
39167
|
+
}
|
|
39168
|
+
),
|
|
39169
|
+
context.onSave && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
39170
|
+
"button",
|
|
39171
|
+
{
|
|
39172
|
+
className: "border shadow rounded p-1 text-white px-2 " + (context.editions.length > 0 ? "bg-blue-500" : "bg-gray-500"),
|
|
39173
|
+
disabled: context.editions.length == 0,
|
|
39174
|
+
onClick: async (e) => {
|
|
39175
|
+
setIsloading(true);
|
|
39176
|
+
const ex = context.filteredData.map((d) => {
|
|
39177
|
+
const { __select__, __modal__, ...datums } = d;
|
|
39178
|
+
return datums;
|
|
39179
|
+
});
|
|
39180
|
+
await context.onSave(ex);
|
|
39181
|
+
setIsloading(false);
|
|
39182
|
+
},
|
|
39183
|
+
children: context.onSaveLabel || "Guardar cambios"
|
|
39184
|
+
}
|
|
39185
|
+
)
|
|
39186
|
+
] }),
|
|
39187
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "grid ", style: { gridTemplateColumns }, children: [
|
|
39188
|
+
headers.map((header, i) => {
|
|
39189
|
+
var _a, _b;
|
|
39190
|
+
if ((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, header)) return null;
|
|
39191
|
+
return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
|
|
39192
|
+
"div",
|
|
39193
|
+
{
|
|
39194
|
+
className: "bg-white",
|
|
39195
|
+
style: { position: "relative" },
|
|
39196
|
+
children: [
|
|
39197
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
39198
|
+
Header,
|
|
39199
|
+
{
|
|
39200
|
+
padding,
|
|
39201
|
+
header,
|
|
39202
|
+
context,
|
|
39203
|
+
drag: { gridTemplateColumns, startDrag, widths }
|
|
39204
|
+
}
|
|
39205
|
+
),
|
|
39206
|
+
i < headers.length - 1 && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
39207
|
+
"div",
|
|
39208
|
+
{
|
|
39209
|
+
onMouseDown: (e) => startDrag(e, header),
|
|
39210
|
+
style: {
|
|
39211
|
+
position: "absolute",
|
|
39212
|
+
right: -3,
|
|
39213
|
+
top: 0,
|
|
39214
|
+
width: 6,
|
|
39215
|
+
height: "100%",
|
|
39216
|
+
cursor: "col-resize",
|
|
39217
|
+
background: "transparent"
|
|
39218
|
+
},
|
|
39219
|
+
onMouseEnter: (e) => e.currentTarget.style.background = "var(--border-strong, #ccc)",
|
|
39220
|
+
onMouseLeave: (e) => e.currentTarget.style.background = "transparent"
|
|
39221
|
+
}
|
|
39222
|
+
)
|
|
39223
|
+
]
|
|
39224
|
+
},
|
|
39225
|
+
header
|
|
39226
|
+
);
|
|
39227
|
+
}),
|
|
39228
|
+
searchedData.map((row, rowIndex) => {
|
|
39229
|
+
const items = Object.entries(row);
|
|
39230
|
+
return items.map(([key, item], i) => {
|
|
39231
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
39232
|
+
if ((_b = (_a = context == null ? void 0 : context.hideColumns) == null ? void 0 : _a.includes) == null ? void 0 : _b.call(_a, key)) return null;
|
|
39233
|
+
if (key == "__modal__") {
|
|
39234
|
+
return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
39235
|
+
"div",
|
|
39236
|
+
{
|
|
39237
|
+
onMouseEnter: (e) => setCurrentIndex(rowIndex),
|
|
39238
|
+
style: {
|
|
39239
|
+
height: `${padding}px`
|
|
39240
|
+
},
|
|
39241
|
+
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" : ""),
|
|
39242
|
+
children: (context == null ? void 0 : context.modalButton) || /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
39243
|
+
"button",
|
|
39244
|
+
{
|
|
39245
|
+
className: "border shadow rounded bg-blue-500 text-white p-2 ",
|
|
39246
|
+
onClick: (e) => {
|
|
39247
|
+
var _a2;
|
|
39248
|
+
setCurrentIndex(rowIndex);
|
|
39249
|
+
(_a2 = modalRef.current) == null ? void 0 : _a2.click();
|
|
39250
|
+
},
|
|
39251
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(EditIcon3, {})
|
|
39252
|
+
}
|
|
39253
|
+
)
|
|
39254
|
+
},
|
|
39255
|
+
row.id + i
|
|
39256
|
+
);
|
|
39257
|
+
}
|
|
39258
|
+
if (key == "__select__") {
|
|
39259
|
+
return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
39260
|
+
"div",
|
|
39261
|
+
{
|
|
39262
|
+
onMouseEnter: (e) => setCurrentIndex(rowIndex),
|
|
39263
|
+
style: {
|
|
39264
|
+
height: `${padding}px`
|
|
39265
|
+
},
|
|
39266
|
+
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" : ""),
|
|
39267
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
39268
|
+
"input",
|
|
39269
|
+
{
|
|
39270
|
+
type: "checkbox",
|
|
39271
|
+
className: "w-5 h-5 accent-blue-600 transition-all duration-300 checked:scale-110 ",
|
|
39272
|
+
checked: Boolean(
|
|
39273
|
+
context.selected.find((s) => s == (row == null ? void 0 : row.id))
|
|
39274
|
+
),
|
|
39275
|
+
onChange: (e) => {
|
|
39276
|
+
const newSelected = [...context.selected];
|
|
39277
|
+
const index = newSelected.findIndex((s) => s == (row == null ? void 0 : row.id));
|
|
39278
|
+
if (index >= 0) {
|
|
39279
|
+
newSelected.splice(index, 1);
|
|
39280
|
+
} else {
|
|
39281
|
+
newSelected.push(row == null ? void 0 : row.id);
|
|
39282
|
+
}
|
|
39283
|
+
context.setSelected(newSelected);
|
|
39284
|
+
}
|
|
39285
|
+
}
|
|
39286
|
+
)
|
|
39287
|
+
},
|
|
39288
|
+
row.id + i
|
|
39289
|
+
);
|
|
39290
|
+
}
|
|
39291
|
+
return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
39292
|
+
"div",
|
|
39293
|
+
{
|
|
39294
|
+
onMouseEnter: (e) => setCurrentIndex(rowIndex),
|
|
39295
|
+
style: {
|
|
39296
|
+
fontSize: context.fontSize,
|
|
39297
|
+
...(context == null ? void 0 : context.wrapText) ? { minHeight: `${padding}px` } : { height: `${padding}px` }
|
|
39298
|
+
},
|
|
39299
|
+
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 " : ""),
|
|
39300
|
+
children: (context == null ? void 0 : context.editableFields) && context.editableFields.includes(key) ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
39301
|
+
"input",
|
|
39302
|
+
{
|
|
39303
|
+
defaultValue: item,
|
|
39304
|
+
className: "w-full " + (context.editions.includes(row == null ? void 0 : row.id) ? "bg-blue-400 text-white" : "bg-blue-100"),
|
|
39305
|
+
onBlur: (e) => {
|
|
39306
|
+
const id = row == null ? void 0 : row.id;
|
|
39307
|
+
const newData = [...context.data];
|
|
39308
|
+
const index = newData.findIndex((d) => +d.id == +id);
|
|
39309
|
+
newData[index][key] = e.target.value;
|
|
39310
|
+
context.setData(newData);
|
|
39311
|
+
const newEditions = [
|
|
39312
|
+
.../* @__PURE__ */ new Set([...context.editions, id])
|
|
39313
|
+
];
|
|
39314
|
+
context.setEditions(newEditions);
|
|
39315
|
+
}
|
|
39316
|
+
}
|
|
39317
|
+
) : ((_c = context.buttons) == null ? void 0 : _c[key]) ? import_react19.default.cloneElement(context.buttons[key], {
|
|
39318
|
+
// children: context.buttons[key]?.props?.children
|
|
39319
|
+
// ? item
|
|
39320
|
+
// : undefined,
|
|
39321
|
+
value: item,
|
|
39322
|
+
children: ((_e = (_d = context.buttons[key]) == null ? void 0 : _d.props) == null ? void 0 : _e.children) ? item : null,
|
|
39323
|
+
onClick: async (e) => {
|
|
39324
|
+
var _a2, _b2;
|
|
39325
|
+
const ret = await ((_b2 = (_a2 = context.buttons[key].props) == null ? void 0 : _a2.onClick) == null ? void 0 : _b2.call(_a2, e)) || {};
|
|
39326
|
+
const newData = [...context.data];
|
|
39327
|
+
const index = newData.findIndex((f) => f.id == (row == null ? void 0 : row.id));
|
|
39328
|
+
newData[index] = { ...newData[index], ...ret };
|
|
39329
|
+
context.setData(newData);
|
|
39330
|
+
},
|
|
39331
|
+
onChange: async (e) => {
|
|
39332
|
+
var _a2, _b2, _c2;
|
|
39333
|
+
const value = e.target.value;
|
|
39334
|
+
const ret = await ((_b2 = (_a2 = context.buttons[key].props) == null ? void 0 : _a2.onChange) == null ? void 0 : _b2.call(_a2, e)) || {};
|
|
39335
|
+
const newData = [...context.data];
|
|
39336
|
+
const index = newData.findIndex((f) => f.id == (row == null ? void 0 : row.id));
|
|
39337
|
+
if (index >= 0) {
|
|
39338
|
+
newData[index][key] = value;
|
|
39339
|
+
}
|
|
39340
|
+
for (let i2 in ret) {
|
|
39341
|
+
if ((_c2 = newData[index]) == null ? void 0 : _c2[i2]) {
|
|
39342
|
+
const v = ret[i2];
|
|
39343
|
+
newData[index][i2] = v;
|
|
39344
|
+
}
|
|
39345
|
+
}
|
|
39346
|
+
context.setData(newData);
|
|
39347
|
+
},
|
|
39348
|
+
className: `${(_g = (_f = context.buttons[key]) == null ? void 0 : _f.props) == null ? void 0 : _g.className} text-xs w-full`
|
|
39349
|
+
}) : ["number", "string"].includes(typeof item) ? valueFormatter({
|
|
39350
|
+
value: item,
|
|
39351
|
+
currentCoin: context.currentCoin
|
|
39352
|
+
}) : JSON.stringify(item)
|
|
39353
|
+
},
|
|
39354
|
+
row.id + i
|
|
39355
|
+
);
|
|
39356
|
+
});
|
|
39357
|
+
}),
|
|
39358
|
+
Object.keys((context == null ? void 0 : context.footer) || {}).length > 0 && headers.map((header) => {
|
|
39359
|
+
var _a;
|
|
39360
|
+
return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
39361
|
+
"div",
|
|
39362
|
+
{
|
|
39363
|
+
style: {
|
|
39364
|
+
height: `${padding}px`,
|
|
39365
|
+
maxHeight: "100px"
|
|
39366
|
+
},
|
|
39367
|
+
className: "border-b font-bold bg-white flex items-center justify-center",
|
|
39368
|
+
children: valueFormatter({
|
|
39369
|
+
currentCoin: context.currentCoin,
|
|
39370
|
+
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) : "" : ""
|
|
39371
|
+
})
|
|
39372
|
+
},
|
|
39373
|
+
header
|
|
39374
|
+
);
|
|
39375
|
+
})
|
|
39376
|
+
] }),
|
|
39377
|
+
context.modal && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
39378
|
+
Modal,
|
|
39379
|
+
{
|
|
39380
|
+
button: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("button", { ref: modalRef }),
|
|
39381
|
+
color: "white",
|
|
39382
|
+
onClose: async () => {
|
|
39383
|
+
var _a;
|
|
39384
|
+
const c = await ((_a = context == null ? void 0 : context.onCloseModal) == null ? void 0 : _a.call(context, searchedData[currentIndex]));
|
|
39385
|
+
return c;
|
|
39386
|
+
},
|
|
39387
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "relative", children: [
|
|
39388
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "fixed top-0 left-0 p-10 ", children: [
|
|
39389
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
39390
|
+
"button",
|
|
39391
|
+
{
|
|
39392
|
+
className: "p-2 border shadow rounded " + (currentIndex > 0 ? "bg-white " : "bg-gray-100"),
|
|
39393
|
+
onClick: (e) => {
|
|
39394
|
+
currentIndex > 0 && setCurrentIndex(currentIndex - 1);
|
|
39395
|
+
},
|
|
39396
|
+
children: "Anterior"
|
|
39397
|
+
}
|
|
39398
|
+
),
|
|
39399
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
39400
|
+
"button",
|
|
39401
|
+
{
|
|
39402
|
+
className: "p-2 border shadow rounded " + (currentIndex < searchedData.length - 1 ? "bg-white " : "bg-gray-100"),
|
|
39403
|
+
onClick: (e) => {
|
|
39404
|
+
currentIndex < searchedData.length - 1 && setCurrentIndex(currentIndex + 1);
|
|
39405
|
+
},
|
|
39406
|
+
children: "Siguiente"
|
|
39407
|
+
}
|
|
39408
|
+
)
|
|
39409
|
+
] }),
|
|
39410
|
+
import_react19.default.cloneElement(context.modal, {
|
|
39411
|
+
row: searchedData[currentIndex]
|
|
39412
|
+
})
|
|
39413
|
+
] })
|
|
39414
|
+
}
|
|
39415
|
+
),
|
|
39416
|
+
isLoading && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
39417
|
+
"div",
|
|
39418
|
+
{
|
|
39419
|
+
className: "bg-white/40 absolute inset-0 text-black flex items-center justify-center",
|
|
39420
|
+
style: { zIndex: 9999999 },
|
|
39421
|
+
children: "Loading..."
|
|
39422
|
+
}
|
|
39423
|
+
)
|
|
39424
|
+
]
|
|
39425
|
+
}
|
|
39426
|
+
);
|
|
39427
|
+
}
|
|
39428
|
+
function valueFormatter({
|
|
39429
|
+
value,
|
|
39430
|
+
currentCoin = ""
|
|
39431
|
+
}) {
|
|
39432
|
+
if (value == null || value === "") return "";
|
|
39433
|
+
const isDate = /(\d{4}-\d{2}-\d{2})(T[\d:,.+-]*(Z)?)?/;
|
|
39434
|
+
if (`${value}`.match(isDate)) {
|
|
39435
|
+
return value.toString().split("T")[0].split("-").reverse().join("/");
|
|
39436
|
+
}
|
|
39437
|
+
const splited = `${value}`.split(".");
|
|
39438
|
+
const hasDecimals = splited.length == 2 && splited.every((v) => `${v}`.match(types_default.number));
|
|
39439
|
+
if (hasDecimals) {
|
|
39440
|
+
return [
|
|
39441
|
+
currentCoin,
|
|
39442
|
+
(+`${value}`).toLocaleString("en-US", {
|
|
39443
|
+
minimumFractionDigits: 2,
|
|
39444
|
+
maximumFractionDigits: 2
|
|
39445
|
+
})
|
|
39446
|
+
].join(" ");
|
|
39447
|
+
}
|
|
39448
|
+
return value;
|
|
39449
|
+
}
|
|
39450
|
+
|
|
39451
|
+
// src/table-advanced/context.ts
|
|
39452
|
+
var import_react20 = require("react");
|
|
39453
|
+
|
|
39454
|
+
// src/table-advanced/filter.reducer.ts
|
|
39455
|
+
var filterReducer = (acc, b) => {
|
|
39456
|
+
if (b == null) return [];
|
|
39457
|
+
const newAcc = [];
|
|
39458
|
+
newAcc.push(b);
|
|
39459
|
+
return newAcc;
|
|
39460
|
+
};
|
|
39461
|
+
|
|
39462
|
+
// src/table-advanced/sort.reducer.ts
|
|
39463
|
+
var sortReducer = (acc, b) => {
|
|
39464
|
+
var _a;
|
|
39465
|
+
const oldAcc = [...acc];
|
|
39466
|
+
const newAcc = [];
|
|
39467
|
+
const keys2 = Object.keys(b);
|
|
39468
|
+
const k = keys2[0];
|
|
39469
|
+
let newType = b[k];
|
|
39470
|
+
if (b[k] == "TOGGLE") {
|
|
39471
|
+
newType = ((_a = oldAcc == null ? void 0 : oldAcc[0]) == null ? void 0 : _a.type) == "ASC" ? "DESC" : "ASC";
|
|
39472
|
+
}
|
|
39473
|
+
newAcc.push({ field: k, type: newType });
|
|
39474
|
+
return newAcc;
|
|
39475
|
+
};
|
|
39476
|
+
|
|
39477
|
+
// src/table-advanced/context.ts
|
|
39478
|
+
function useContext({ onSelect }) {
|
|
39479
|
+
const excel = useExcel();
|
|
39480
|
+
const [editions, setEditions] = (0, import_react20.useState)([]);
|
|
39481
|
+
const [selected, setSelected] = (0, import_react20.useState)([]);
|
|
39482
|
+
const [data, setData] = (0, import_react20.useState)([]);
|
|
39483
|
+
const headers = [...new Set(data.map((b) => Object.keys(b)).flat())];
|
|
39484
|
+
const [currentHeader, setCurrentHeader] = (0, import_react20.useState)(null);
|
|
39485
|
+
const cols = headers.length;
|
|
39486
|
+
const [filters, setFilters] = (0, import_react20.useReducer)(
|
|
39487
|
+
filterReducer,
|
|
39488
|
+
new Array()
|
|
39489
|
+
);
|
|
39490
|
+
const [searchBy, setSearchBy] = (0, import_react20.useState)("");
|
|
39491
|
+
const [sort, setSort] = (0, import_react20.useReducer)(sortReducer, new Array());
|
|
39492
|
+
const sortedData = (0, import_react20.useMemo)(() => {
|
|
39493
|
+
return [...data].sort((a, b) => {
|
|
39494
|
+
for (const { field, type } of sort.reverse()) {
|
|
39495
|
+
const av = a[field];
|
|
39496
|
+
const bv = b[field];
|
|
39497
|
+
if (av == null && bv == null) continue;
|
|
39498
|
+
if (av == null) return 1;
|
|
39499
|
+
if (bv == null) return -1;
|
|
39500
|
+
let cmp;
|
|
39501
|
+
if (typeof av === "number" && typeof bv === "number") {
|
|
39502
|
+
cmp = av - bv;
|
|
39503
|
+
} else {
|
|
39504
|
+
cmp = `${av}`.localeCompare(`${bv}`, void 0, { numeric: true });
|
|
39505
|
+
}
|
|
39506
|
+
if (cmp !== 0) {
|
|
39507
|
+
return type === "DESC" ? -cmp : cmp;
|
|
39508
|
+
}
|
|
39509
|
+
}
|
|
39510
|
+
return 0;
|
|
39511
|
+
});
|
|
39512
|
+
}, [data, sort]);
|
|
39513
|
+
const filteredData = [...sortedData].filter((d) => {
|
|
39514
|
+
if (editions.includes(d == null ? void 0 : d.id)) return true;
|
|
39515
|
+
for (const { field, values } of filters) {
|
|
39516
|
+
if (!values.includes(d[field])) {
|
|
39517
|
+
return false;
|
|
39518
|
+
}
|
|
39519
|
+
}
|
|
39520
|
+
return true;
|
|
39521
|
+
});
|
|
39522
|
+
(0, import_react20.useEffect)(() => {
|
|
39523
|
+
if (filters.length == 0) {
|
|
39524
|
+
setEditions([]);
|
|
39525
|
+
}
|
|
39526
|
+
}, [filters]);
|
|
39527
|
+
return {
|
|
39528
|
+
currentHeader,
|
|
39529
|
+
setCurrentHeader,
|
|
39530
|
+
sort,
|
|
39531
|
+
setSort,
|
|
39532
|
+
cols,
|
|
39533
|
+
headers,
|
|
39534
|
+
data,
|
|
39535
|
+
sortedData,
|
|
39536
|
+
filters,
|
|
39537
|
+
setFilters,
|
|
39538
|
+
filteredData,
|
|
39539
|
+
setData,
|
|
39540
|
+
searchBy,
|
|
39541
|
+
setSearchBy,
|
|
39542
|
+
selected,
|
|
39543
|
+
setSelected,
|
|
39544
|
+
editions,
|
|
39545
|
+
excel,
|
|
39546
|
+
setEditions
|
|
39547
|
+
};
|
|
39548
|
+
}
|
|
39549
|
+
|
|
39550
|
+
// src/table-advanced/index.tsx
|
|
39551
|
+
var import_jsx_runtime37 = require("react/jsx-runtime");
|
|
39552
|
+
function TableAdvanced(tableProps) {
|
|
39553
|
+
const { data, ...props } = tableProps;
|
|
39554
|
+
const context = useContext({ onSelect: Boolean(tableProps.onSelect) });
|
|
39555
|
+
(0, import_react21.useEffect)(() => {
|
|
39556
|
+
context.setData(
|
|
39557
|
+
Array.isArray(data) ? data.map((d) => {
|
|
39558
|
+
return {
|
|
39559
|
+
...(tableProps == null ? void 0 : tableProps.modal) ? { __modal__: "" } : {},
|
|
39560
|
+
...(tableProps == null ? void 0 : tableProps.onSelect) ? { __select__: "" } : {},
|
|
39561
|
+
...d
|
|
39562
|
+
};
|
|
39563
|
+
}) : data
|
|
39564
|
+
);
|
|
39565
|
+
}, [data]);
|
|
39566
|
+
(0, import_react21.useEffect)(() => {
|
|
39567
|
+
if (tableProps == null ? void 0 : tableProps.sortBy) {
|
|
39568
|
+
const [k, v] = Object.entries(tableProps.sortBy)[0];
|
|
39569
|
+
context.setSort({ [k]: v });
|
|
39570
|
+
}
|
|
39571
|
+
}, [tableProps == null ? void 0 : tableProps.sortBy]);
|
|
39572
|
+
if (Array.isArray(data) && data.length > 0) {
|
|
39573
|
+
if (data.every((d) => !(d == null ? void 0 : d.id))) {
|
|
39574
|
+
throw new Error("All data rows must have an 'id' property.");
|
|
39575
|
+
}
|
|
39576
|
+
if ((props == null ? void 0 : props.onSave) && props.onSelect) {
|
|
39577
|
+
throw new Error("Must have only one of onSave or onSelect");
|
|
39578
|
+
}
|
|
39579
|
+
return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(HTable, { context: { ...context, ...props } });
|
|
39580
|
+
}
|
|
39581
|
+
return null;
|
|
39582
|
+
}
|
|
38453
39583
|
// Annotate the CommonJS export names for ESM import in node:
|
|
38454
39584
|
0 && (module.exports = {
|
|
38455
39585
|
Alert,
|
|
@@ -38464,6 +39594,7 @@ function Table3({
|
|
|
38464
39594
|
Select,
|
|
38465
39595
|
Table,
|
|
38466
39596
|
Table3,
|
|
39597
|
+
TableAdvanced,
|
|
38467
39598
|
TextArea,
|
|
38468
39599
|
regularExpresions,
|
|
38469
39600
|
useDates,
|