next-recomponents 2.0.12 → 2.0.14
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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +32 -14
- package/dist/index.mjs +40 -22
- package/package.json +1 -1
- package/src/modal/index.tsx +10 -10
- package/src/pop/index.tsx +29 -7
- package/src/pop/overlay.tsx +8 -3
package/dist/index.d.mts
CHANGED
|
@@ -224,6 +224,7 @@ declare function usePopup(): {
|
|
|
224
224
|
modal: (message: ReactNode, color?: PopupColor, icons?: boolean, full?: boolean) => Promise<void>;
|
|
225
225
|
PopupComponent: react_jsx_runtime.JSX.Element | null;
|
|
226
226
|
close: (confirmed: boolean, value?: string) => void;
|
|
227
|
+
updateMessage: (message: ReactNode) => void;
|
|
227
228
|
};
|
|
228
229
|
|
|
229
230
|
export { Alert, Button, Container, DocumentViewer, Form, Input, Modal, MyCalendar, Pre, Select, Table, Table3, type TableButtonProps, type TableButtonProps as TableEventProps, TextArea, regularExpresions, useDates, useExcel, useFormValues, usePopup, useResources };
|
package/dist/index.d.ts
CHANGED
|
@@ -224,6 +224,7 @@ declare function usePopup(): {
|
|
|
224
224
|
modal: (message: ReactNode, color?: PopupColor, icons?: boolean, full?: boolean) => Promise<void>;
|
|
225
225
|
PopupComponent: react_jsx_runtime.JSX.Element | null;
|
|
226
226
|
close: (confirmed: boolean, value?: string) => void;
|
|
227
|
+
updateMessage: (message: ReactNode) => void;
|
|
227
228
|
};
|
|
228
229
|
|
|
229
230
|
export { Alert, Button, Container, DocumentViewer, Form, Input, Modal, MyCalendar, Pre, Select, Table, Table3, type TableButtonProps, type TableButtonProps as TableEventProps, TextArea, regularExpresions, useDates, useExcel, useFormValues, usePopup, useResources };
|
package/dist/index.js
CHANGED
|
@@ -36783,7 +36783,7 @@ function Select({
|
|
|
36783
36783
|
}
|
|
36784
36784
|
|
|
36785
36785
|
// src/modal/index.tsx
|
|
36786
|
-
var import_react10 =
|
|
36786
|
+
var import_react10 = require("react");
|
|
36787
36787
|
|
|
36788
36788
|
// src/pop/index.tsx
|
|
36789
36789
|
var import_react9 = require("react");
|
|
@@ -36967,7 +36967,15 @@ function PopupOverlay({
|
|
|
36967
36967
|
iconText: c.iconText
|
|
36968
36968
|
}
|
|
36969
36969
|
),
|
|
36970
|
-
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "w-full flex justify-end", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
36970
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "relative w-full flex justify-end", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
36971
|
+
Button,
|
|
36972
|
+
{
|
|
36973
|
+
color: "danger",
|
|
36974
|
+
className: "fixed text-xs font-bold",
|
|
36975
|
+
onClick: (e) => onClose(false),
|
|
36976
|
+
children: "x"
|
|
36977
|
+
}
|
|
36978
|
+
) }),
|
|
36971
36979
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
36972
36980
|
"div",
|
|
36973
36981
|
{
|
|
@@ -37009,7 +37017,6 @@ function PopupOverlay({
|
|
|
37009
37017
|
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
37010
37018
|
var INITIAL_STATE = {
|
|
37011
37019
|
type: "alert",
|
|
37012
|
-
message: "",
|
|
37013
37020
|
visible: false,
|
|
37014
37021
|
inputValue: "",
|
|
37015
37022
|
color: "primary",
|
|
@@ -37018,9 +37025,12 @@ var INITIAL_STATE = {
|
|
|
37018
37025
|
};
|
|
37019
37026
|
function usePopup() {
|
|
37020
37027
|
const [popup, setPopup] = (0, import_react9.useState)(INITIAL_STATE);
|
|
37028
|
+
const messageRef = (0, import_react9.useRef)(null);
|
|
37021
37029
|
const open = (0, import_react9.useCallback)(
|
|
37022
37030
|
(partial) => {
|
|
37023
|
-
|
|
37031
|
+
const { message, ...rest } = partial;
|
|
37032
|
+
messageRef.current = message;
|
|
37033
|
+
setPopup({ ...rest, visible: true, inputValue: "" });
|
|
37024
37034
|
},
|
|
37025
37035
|
[]
|
|
37026
37036
|
);
|
|
@@ -37082,15 +37092,27 @@ function usePopup() {
|
|
|
37082
37092
|
),
|
|
37083
37093
|
[open]
|
|
37084
37094
|
);
|
|
37095
|
+
const updateMessage = (0, import_react9.useCallback)((message) => {
|
|
37096
|
+
messageRef.current = message;
|
|
37097
|
+
setPopup((prev) => ({ ...prev }));
|
|
37098
|
+
}, []);
|
|
37085
37099
|
const PopupComponent = popup.visible ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
37086
37100
|
PopupOverlay,
|
|
37087
37101
|
{
|
|
37088
|
-
popup,
|
|
37102
|
+
popup: { ...popup, message: messageRef.current },
|
|
37089
37103
|
onClose: close,
|
|
37090
37104
|
onInputChange: (v) => setPopup((prev) => ({ ...prev, inputValue: v }))
|
|
37091
37105
|
}
|
|
37092
37106
|
) : null;
|
|
37093
|
-
return {
|
|
37107
|
+
return {
|
|
37108
|
+
alert: alert2,
|
|
37109
|
+
confirm,
|
|
37110
|
+
prompt,
|
|
37111
|
+
modal,
|
|
37112
|
+
PopupComponent,
|
|
37113
|
+
close,
|
|
37114
|
+
updateMessage
|
|
37115
|
+
};
|
|
37094
37116
|
}
|
|
37095
37117
|
|
|
37096
37118
|
// src/modal/index.tsx
|
|
@@ -37101,16 +37123,12 @@ function Modal({
|
|
|
37101
37123
|
color = "primary"
|
|
37102
37124
|
}) {
|
|
37103
37125
|
const pop = usePopup();
|
|
37126
|
+
(0, import_react10.useEffect)(() => {
|
|
37127
|
+
pop.updateMessage(children);
|
|
37128
|
+
}, [children]);
|
|
37104
37129
|
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
|
|
37105
37130
|
(0, import_react10.cloneElement)(button, {
|
|
37106
|
-
onClick:
|
|
37107
|
-
await pop.modal(
|
|
37108
|
-
import_react10.default.cloneElement(children, { hide: () => pop.close(false) }),
|
|
37109
|
-
color,
|
|
37110
|
-
false,
|
|
37111
|
-
true
|
|
37112
|
-
);
|
|
37113
|
-
}
|
|
37131
|
+
onClick: () => pop.modal(children, color, false, true)
|
|
37114
37132
|
}),
|
|
37115
37133
|
pop.PopupComponent
|
|
37116
37134
|
] });
|
package/dist/index.mjs
CHANGED
|
@@ -36769,10 +36769,10 @@ function Select({
|
|
|
36769
36769
|
}
|
|
36770
36770
|
|
|
36771
36771
|
// src/modal/index.tsx
|
|
36772
|
-
import
|
|
36772
|
+
import { cloneElement as cloneElement2, useEffect as useEffect6 } from "react";
|
|
36773
36773
|
|
|
36774
36774
|
// src/pop/index.tsx
|
|
36775
|
-
import { useState as useState8, useCallback } from "react";
|
|
36775
|
+
import { useState as useState8, useCallback, useRef as useRef4 } from "react";
|
|
36776
36776
|
|
|
36777
36777
|
// src/pop/actions.tsx
|
|
36778
36778
|
import { jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
@@ -36953,7 +36953,15 @@ function PopupOverlay({
|
|
|
36953
36953
|
iconText: c.iconText
|
|
36954
36954
|
}
|
|
36955
36955
|
),
|
|
36956
|
-
/* @__PURE__ */ jsx14("div", { className: "w-full flex justify-end", children: /* @__PURE__ */ jsx14(
|
|
36956
|
+
/* @__PURE__ */ jsx14("div", { className: "relative w-full flex justify-end", children: /* @__PURE__ */ jsx14(
|
|
36957
|
+
Button,
|
|
36958
|
+
{
|
|
36959
|
+
color: "danger",
|
|
36960
|
+
className: "fixed text-xs font-bold",
|
|
36961
|
+
onClick: (e) => onClose(false),
|
|
36962
|
+
children: "x"
|
|
36963
|
+
}
|
|
36964
|
+
) }),
|
|
36957
36965
|
/* @__PURE__ */ jsx14(
|
|
36958
36966
|
"div",
|
|
36959
36967
|
{
|
|
@@ -36995,7 +37003,6 @@ function PopupOverlay({
|
|
|
36995
37003
|
import { jsx as jsx15 } from "react/jsx-runtime";
|
|
36996
37004
|
var INITIAL_STATE = {
|
|
36997
37005
|
type: "alert",
|
|
36998
|
-
message: "",
|
|
36999
37006
|
visible: false,
|
|
37000
37007
|
inputValue: "",
|
|
37001
37008
|
color: "primary",
|
|
@@ -37004,9 +37011,12 @@ var INITIAL_STATE = {
|
|
|
37004
37011
|
};
|
|
37005
37012
|
function usePopup() {
|
|
37006
37013
|
const [popup, setPopup] = useState8(INITIAL_STATE);
|
|
37014
|
+
const messageRef = useRef4(null);
|
|
37007
37015
|
const open = useCallback(
|
|
37008
37016
|
(partial) => {
|
|
37009
|
-
|
|
37017
|
+
const { message, ...rest } = partial;
|
|
37018
|
+
messageRef.current = message;
|
|
37019
|
+
setPopup({ ...rest, visible: true, inputValue: "" });
|
|
37010
37020
|
},
|
|
37011
37021
|
[]
|
|
37012
37022
|
);
|
|
@@ -37068,15 +37078,27 @@ function usePopup() {
|
|
|
37068
37078
|
),
|
|
37069
37079
|
[open]
|
|
37070
37080
|
);
|
|
37081
|
+
const updateMessage = useCallback((message) => {
|
|
37082
|
+
messageRef.current = message;
|
|
37083
|
+
setPopup((prev) => ({ ...prev }));
|
|
37084
|
+
}, []);
|
|
37071
37085
|
const PopupComponent = popup.visible ? /* @__PURE__ */ jsx15(
|
|
37072
37086
|
PopupOverlay,
|
|
37073
37087
|
{
|
|
37074
|
-
popup,
|
|
37088
|
+
popup: { ...popup, message: messageRef.current },
|
|
37075
37089
|
onClose: close,
|
|
37076
37090
|
onInputChange: (v) => setPopup((prev) => ({ ...prev, inputValue: v }))
|
|
37077
37091
|
}
|
|
37078
37092
|
) : null;
|
|
37079
|
-
return {
|
|
37093
|
+
return {
|
|
37094
|
+
alert: alert2,
|
|
37095
|
+
confirm,
|
|
37096
|
+
prompt,
|
|
37097
|
+
modal,
|
|
37098
|
+
PopupComponent,
|
|
37099
|
+
close,
|
|
37100
|
+
updateMessage
|
|
37101
|
+
};
|
|
37080
37102
|
}
|
|
37081
37103
|
|
|
37082
37104
|
// src/modal/index.tsx
|
|
@@ -37087,16 +37109,12 @@ function Modal({
|
|
|
37087
37109
|
color = "primary"
|
|
37088
37110
|
}) {
|
|
37089
37111
|
const pop = usePopup();
|
|
37112
|
+
useEffect6(() => {
|
|
37113
|
+
pop.updateMessage(children);
|
|
37114
|
+
}, [children]);
|
|
37090
37115
|
return /* @__PURE__ */ jsxs10(Fragment2, { children: [
|
|
37091
37116
|
cloneElement2(button, {
|
|
37092
|
-
onClick:
|
|
37093
|
-
await pop.modal(
|
|
37094
|
-
React6.cloneElement(children, { hide: () => pop.close(false) }),
|
|
37095
|
-
color,
|
|
37096
|
-
false,
|
|
37097
|
-
true
|
|
37098
|
-
);
|
|
37099
|
-
}
|
|
37117
|
+
onClick: () => pop.modal(children, color, false, true)
|
|
37100
37118
|
}),
|
|
37101
37119
|
pop.PopupComponent
|
|
37102
37120
|
] });
|
|
@@ -37344,15 +37362,15 @@ function DocumentViewer({ item }) {
|
|
|
37344
37362
|
|
|
37345
37363
|
// src/table3/index.tsx
|
|
37346
37364
|
import React9, {
|
|
37347
|
-
useEffect as
|
|
37365
|
+
useEffect as useEffect9,
|
|
37348
37366
|
useMemo as useMemo6,
|
|
37349
37367
|
useReducer as useReducer2,
|
|
37350
|
-
useRef as
|
|
37368
|
+
useRef as useRef6,
|
|
37351
37369
|
useState as useState12
|
|
37352
37370
|
} from "react";
|
|
37353
37371
|
|
|
37354
37372
|
// src/table3/filter.tsx
|
|
37355
|
-
import { useEffect as
|
|
37373
|
+
import { useEffect as useEffect8, useMemo as useMemo4, useState as useState10 } from "react";
|
|
37356
37374
|
|
|
37357
37375
|
// src/table3/filters.tsx
|
|
37358
37376
|
import { jsx as jsx21, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
@@ -37506,7 +37524,7 @@ function Filter({
|
|
|
37506
37524
|
const hidden = Object.values(objectData).filter(
|
|
37507
37525
|
(d) => d._visible === false
|
|
37508
37526
|
);
|
|
37509
|
-
|
|
37527
|
+
useEffect8(() => {
|
|
37510
37528
|
if (data.length != Object.values(objectData).map((o) => (o == null ? void 0 : o._id) || (o == null ? void 0 : o.id)).length) {
|
|
37511
37529
|
const news = [...new Set(data.map((o) => o[h]))];
|
|
37512
37530
|
setSelected(news);
|
|
@@ -38194,7 +38212,7 @@ function Table3({
|
|
|
38194
38212
|
}
|
|
38195
38213
|
}
|
|
38196
38214
|
const [objectData, setObjectData] = useReducer2(dataReducer, null);
|
|
38197
|
-
|
|
38215
|
+
useEffect9(() => {
|
|
38198
38216
|
setObjectData(data);
|
|
38199
38217
|
setPage(1);
|
|
38200
38218
|
}, [data]);
|
|
@@ -38211,7 +38229,7 @@ function Table3({
|
|
|
38211
38229
|
return maxItems ? Math.ceil(Object.keys(objectData).length / maxItems) : 1;
|
|
38212
38230
|
}, [objectData, maxItems]);
|
|
38213
38231
|
const [sort, setSort] = useState12(sortBy);
|
|
38214
|
-
const modalRef =
|
|
38232
|
+
const modalRef = useRef6(null);
|
|
38215
38233
|
const [dialogRow, setDialogRow] = useState12({});
|
|
38216
38234
|
const context = {
|
|
38217
38235
|
objectData,
|
|
@@ -38239,7 +38257,7 @@ function Table3({
|
|
|
38239
38257
|
setSort,
|
|
38240
38258
|
...props
|
|
38241
38259
|
};
|
|
38242
|
-
|
|
38260
|
+
useEffect9(() => {
|
|
38243
38261
|
if ((dialogRow == null ? void 0 : dialogRow.id) || (dialogRow == null ? void 0 : dialogRow._id)) {
|
|
38244
38262
|
const newDialogRow = objectData[dialogRow == null ? void 0 : dialogRow.id] || objectData[dialogRow == null ? void 0 : dialogRow._id];
|
|
38245
38263
|
setDialogRow(newDialogRow);
|
package/package.json
CHANGED
package/src/modal/index.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// Modal.tsx
|
|
2
|
+
import React, { ReactElement, cloneElement, useEffect } from "react";
|
|
2
3
|
import usePopup from "../pop";
|
|
3
4
|
export type PopupColor =
|
|
4
5
|
| "white"
|
|
@@ -8,6 +9,7 @@ export type PopupColor =
|
|
|
8
9
|
| "danger"
|
|
9
10
|
| "warning"
|
|
10
11
|
| "success";
|
|
12
|
+
|
|
11
13
|
export default function Modal({
|
|
12
14
|
button,
|
|
13
15
|
children,
|
|
@@ -21,19 +23,17 @@ export default function Modal({
|
|
|
21
23
|
}) {
|
|
22
24
|
const pop = usePopup();
|
|
23
25
|
|
|
26
|
+
// ✅ Cada vez que children cambia (estado del padre actualizado),
|
|
27
|
+
// propagamos el nuevo ReactNode al modal si está abierto
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
pop.updateMessage(children);
|
|
30
|
+
}, [children]);
|
|
31
|
+
|
|
24
32
|
return (
|
|
25
33
|
<>
|
|
26
34
|
{cloneElement(button, {
|
|
27
|
-
onClick:
|
|
28
|
-
await pop.modal(
|
|
29
|
-
React.cloneElement(children, { hide: () => pop.close(false) }),
|
|
30
|
-
color,
|
|
31
|
-
false,
|
|
32
|
-
true,
|
|
33
|
-
);
|
|
34
|
-
},
|
|
35
|
+
onClick: () => pop.modal(children, color, false, true),
|
|
35
36
|
})}
|
|
36
|
-
|
|
37
37
|
{pop.PopupComponent}
|
|
38
38
|
</>
|
|
39
39
|
);
|
package/src/pop/index.tsx
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
// usePopup.ts - Solución definitiva
|
|
1
2
|
"use client";
|
|
2
3
|
|
|
3
|
-
import { useState, useCallback, type ReactNode } from "react";
|
|
4
|
+
import { useState, useCallback, useRef, type ReactNode } from "react";
|
|
4
5
|
import { PopupColor, PopupState } from "./types";
|
|
5
6
|
import { PopupOverlay } from "./overlay";
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
type PopupStateWithoutMessage = Omit<PopupState, "message">;
|
|
9
|
+
|
|
10
|
+
const INITIAL_STATE: PopupStateWithoutMessage = {
|
|
8
11
|
type: "alert",
|
|
9
|
-
message: "",
|
|
10
12
|
visible: false,
|
|
11
13
|
inputValue: "",
|
|
12
14
|
color: "primary",
|
|
@@ -15,11 +17,15 @@ const INITIAL_STATE: PopupState = {
|
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
export default function usePopup() {
|
|
18
|
-
const [popup, setPopup] = useState<
|
|
20
|
+
const [popup, setPopup] = useState<PopupStateWithoutMessage>(INITIAL_STATE);
|
|
21
|
+
// El message vive FUERA del estado para no quedar congelado
|
|
22
|
+
const messageRef = useRef<ReactNode>(null);
|
|
19
23
|
|
|
20
24
|
const open = useCallback(
|
|
21
25
|
(partial: Omit<PopupState, "visible" | "inputValue">) => {
|
|
22
|
-
|
|
26
|
+
const { message, ...rest } = partial;
|
|
27
|
+
messageRef.current = message as any;
|
|
28
|
+
setPopup({ ...rest, visible: true, inputValue: "" });
|
|
23
29
|
},
|
|
24
30
|
[],
|
|
25
31
|
);
|
|
@@ -95,13 +101,29 @@ export default function usePopup() {
|
|
|
95
101
|
[open],
|
|
96
102
|
);
|
|
97
103
|
|
|
104
|
+
// ✅ Actualiza la ref en cada render cuando el modal está abierto
|
|
105
|
+
// Esto permite que cambios en el children del padre se reflejen
|
|
106
|
+
const updateMessage = useCallback((message: ReactNode) => {
|
|
107
|
+
messageRef.current = message;
|
|
108
|
+
// Fuerza re-render del PopupComponent
|
|
109
|
+
setPopup((prev) => ({ ...prev }));
|
|
110
|
+
}, []);
|
|
111
|
+
|
|
98
112
|
const PopupComponent = popup.visible ? (
|
|
99
113
|
<PopupOverlay
|
|
100
|
-
popup={popup}
|
|
114
|
+
popup={{ ...popup, message: messageRef.current }}
|
|
101
115
|
onClose={close}
|
|
102
116
|
onInputChange={(v) => setPopup((prev) => ({ ...prev, inputValue: v }))}
|
|
103
117
|
/>
|
|
104
118
|
) : null;
|
|
105
119
|
|
|
106
|
-
return {
|
|
120
|
+
return {
|
|
121
|
+
alert,
|
|
122
|
+
confirm,
|
|
123
|
+
prompt,
|
|
124
|
+
modal,
|
|
125
|
+
PopupComponent,
|
|
126
|
+
close,
|
|
127
|
+
updateMessage,
|
|
128
|
+
};
|
|
107
129
|
}
|
package/src/pop/overlay.tsx
CHANGED
|
@@ -13,6 +13,7 @@ export function PopupOverlay({
|
|
|
13
13
|
const c = COLOR_CONFIG[popup.color];
|
|
14
14
|
const resolvedMessage =
|
|
15
15
|
typeof popup.message === "function" ? popup.message() : popup.message;
|
|
16
|
+
|
|
16
17
|
return (
|
|
17
18
|
<div
|
|
18
19
|
className={"fixed inset-0 flex items-center justify-center z-[1000] "}
|
|
@@ -45,9 +46,13 @@ export function PopupOverlay({
|
|
|
45
46
|
/>
|
|
46
47
|
)}
|
|
47
48
|
{
|
|
48
|
-
<div className="w-full flex justify-end">
|
|
49
|
-
<Button
|
|
50
|
-
|
|
49
|
+
<div className="relative w-full flex justify-end">
|
|
50
|
+
<Button
|
|
51
|
+
color="danger"
|
|
52
|
+
className="fixed text-xs font-bold"
|
|
53
|
+
onClick={(e) => onClose(false)}
|
|
54
|
+
>
|
|
55
|
+
x
|
|
51
56
|
</Button>
|
|
52
57
|
</div>
|
|
53
58
|
}
|