next-recomponents 2.0.13 → 2.0.15

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 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 = __toESM(require("react"));
36786
+ var import_react10 = require("react");
36787
36787
 
36788
36788
  // src/pop/index.tsx
36789
36789
  var import_react9 = require("react");
@@ -37017,7 +37017,6 @@ function PopupOverlay({
37017
37017
  var import_jsx_runtime16 = require("react/jsx-runtime");
37018
37018
  var INITIAL_STATE = {
37019
37019
  type: "alert",
37020
- message: "",
37021
37020
  visible: false,
37022
37021
  inputValue: "",
37023
37022
  color: "primary",
@@ -37026,9 +37025,12 @@ var INITIAL_STATE = {
37026
37025
  };
37027
37026
  function usePopup() {
37028
37027
  const [popup, setPopup] = (0, import_react9.useState)(INITIAL_STATE);
37028
+ const messageRef = (0, import_react9.useRef)(null);
37029
37029
  const open = (0, import_react9.useCallback)(
37030
37030
  (partial) => {
37031
- setPopup({ ...partial, visible: true, inputValue: "" });
37031
+ const { message, ...rest } = partial;
37032
+ messageRef.current = message;
37033
+ setPopup({ ...rest, visible: true, inputValue: "" });
37032
37034
  },
37033
37035
  []
37034
37036
  );
@@ -37090,15 +37092,27 @@ function usePopup() {
37090
37092
  ),
37091
37093
  [open]
37092
37094
  );
37095
+ const updateMessage = (0, import_react9.useCallback)((message) => {
37096
+ messageRef.current = message;
37097
+ setPopup((prev) => ({ ...prev }));
37098
+ }, []);
37093
37099
  const PopupComponent = popup.visible ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
37094
37100
  PopupOverlay,
37095
37101
  {
37096
- popup,
37102
+ popup: { ...popup, message: messageRef.current },
37097
37103
  onClose: close,
37098
37104
  onInputChange: (v) => setPopup((prev) => ({ ...prev, inputValue: v }))
37099
37105
  }
37100
37106
  ) : null;
37101
- return { alert: alert2, confirm, prompt, modal, PopupComponent, close };
37107
+ return {
37108
+ alert: alert2,
37109
+ confirm,
37110
+ prompt,
37111
+ modal,
37112
+ PopupComponent,
37113
+ close,
37114
+ updateMessage
37115
+ };
37102
37116
  }
37103
37117
 
37104
37118
  // src/modal/index.tsx
@@ -37109,15 +37123,16 @@ function Modal({
37109
37123
  color = "primary"
37110
37124
  }) {
37111
37125
  const pop = usePopup();
37126
+ (0, import_react10.useEffect)(() => {
37127
+ pop.updateMessage(children);
37128
+ }, [children]);
37129
+ const props = children == null ? void 0 : children.props;
37130
+ const onClick = props == null ? void 0 : props.onClick;
37112
37131
  return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
37113
37132
  (0, import_react10.cloneElement)(button, {
37114
- onClick: async (e) => {
37115
- await pop.modal(
37116
- import_react10.default.cloneElement(children, { hide: () => pop.close(false) }),
37117
- color,
37118
- false,
37119
- true
37120
- );
37133
+ onClick: (e) => {
37134
+ onClick == null ? void 0 : onClick(e);
37135
+ pop.modal(children, color, false, true);
37121
37136
  }
37122
37137
  }),
37123
37138
  pop.PopupComponent
package/dist/index.mjs CHANGED
@@ -36769,10 +36769,10 @@ function Select({
36769
36769
  }
36770
36770
 
36771
36771
  // src/modal/index.tsx
36772
- import React6, { cloneElement as cloneElement2 } from "react";
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";
@@ -37003,7 +37003,6 @@ function PopupOverlay({
37003
37003
  import { jsx as jsx15 } from "react/jsx-runtime";
37004
37004
  var INITIAL_STATE = {
37005
37005
  type: "alert",
37006
- message: "",
37007
37006
  visible: false,
37008
37007
  inputValue: "",
37009
37008
  color: "primary",
@@ -37012,9 +37011,12 @@ var INITIAL_STATE = {
37012
37011
  };
37013
37012
  function usePopup() {
37014
37013
  const [popup, setPopup] = useState8(INITIAL_STATE);
37014
+ const messageRef = useRef4(null);
37015
37015
  const open = useCallback(
37016
37016
  (partial) => {
37017
- setPopup({ ...partial, visible: true, inputValue: "" });
37017
+ const { message, ...rest } = partial;
37018
+ messageRef.current = message;
37019
+ setPopup({ ...rest, visible: true, inputValue: "" });
37018
37020
  },
37019
37021
  []
37020
37022
  );
@@ -37076,15 +37078,27 @@ function usePopup() {
37076
37078
  ),
37077
37079
  [open]
37078
37080
  );
37081
+ const updateMessage = useCallback((message) => {
37082
+ messageRef.current = message;
37083
+ setPopup((prev) => ({ ...prev }));
37084
+ }, []);
37079
37085
  const PopupComponent = popup.visible ? /* @__PURE__ */ jsx15(
37080
37086
  PopupOverlay,
37081
37087
  {
37082
- popup,
37088
+ popup: { ...popup, message: messageRef.current },
37083
37089
  onClose: close,
37084
37090
  onInputChange: (v) => setPopup((prev) => ({ ...prev, inputValue: v }))
37085
37091
  }
37086
37092
  ) : null;
37087
- return { alert: alert2, confirm, prompt, modal, PopupComponent, close };
37093
+ return {
37094
+ alert: alert2,
37095
+ confirm,
37096
+ prompt,
37097
+ modal,
37098
+ PopupComponent,
37099
+ close,
37100
+ updateMessage
37101
+ };
37088
37102
  }
37089
37103
 
37090
37104
  // src/modal/index.tsx
@@ -37095,15 +37109,16 @@ function Modal({
37095
37109
  color = "primary"
37096
37110
  }) {
37097
37111
  const pop = usePopup();
37112
+ useEffect6(() => {
37113
+ pop.updateMessage(children);
37114
+ }, [children]);
37115
+ const props = children == null ? void 0 : children.props;
37116
+ const onClick = props == null ? void 0 : props.onClick;
37098
37117
  return /* @__PURE__ */ jsxs10(Fragment2, { children: [
37099
37118
  cloneElement2(button, {
37100
- onClick: async (e) => {
37101
- await pop.modal(
37102
- React6.cloneElement(children, { hide: () => pop.close(false) }),
37103
- color,
37104
- false,
37105
- true
37106
- );
37119
+ onClick: (e) => {
37120
+ onClick == null ? void 0 : onClick(e);
37121
+ pop.modal(children, color, false, true);
37107
37122
  }
37108
37123
  }),
37109
37124
  pop.PopupComponent
@@ -37352,15 +37367,15 @@ function DocumentViewer({ item }) {
37352
37367
 
37353
37368
  // src/table3/index.tsx
37354
37369
  import React9, {
37355
- useEffect as useEffect8,
37370
+ useEffect as useEffect9,
37356
37371
  useMemo as useMemo6,
37357
37372
  useReducer as useReducer2,
37358
- useRef as useRef5,
37373
+ useRef as useRef6,
37359
37374
  useState as useState12
37360
37375
  } from "react";
37361
37376
 
37362
37377
  // src/table3/filter.tsx
37363
- import { useEffect as useEffect7, useMemo as useMemo4, useState as useState10 } from "react";
37378
+ import { useEffect as useEffect8, useMemo as useMemo4, useState as useState10 } from "react";
37364
37379
 
37365
37380
  // src/table3/filters.tsx
37366
37381
  import { jsx as jsx21, jsxs as jsxs13 } from "react/jsx-runtime";
@@ -37514,7 +37529,7 @@ function Filter({
37514
37529
  const hidden = Object.values(objectData).filter(
37515
37530
  (d) => d._visible === false
37516
37531
  );
37517
- useEffect7(() => {
37532
+ useEffect8(() => {
37518
37533
  if (data.length != Object.values(objectData).map((o) => (o == null ? void 0 : o._id) || (o == null ? void 0 : o.id)).length) {
37519
37534
  const news = [...new Set(data.map((o) => o[h]))];
37520
37535
  setSelected(news);
@@ -38202,7 +38217,7 @@ function Table3({
38202
38217
  }
38203
38218
  }
38204
38219
  const [objectData, setObjectData] = useReducer2(dataReducer, null);
38205
- useEffect8(() => {
38220
+ useEffect9(() => {
38206
38221
  setObjectData(data);
38207
38222
  setPage(1);
38208
38223
  }, [data]);
@@ -38219,7 +38234,7 @@ function Table3({
38219
38234
  return maxItems ? Math.ceil(Object.keys(objectData).length / maxItems) : 1;
38220
38235
  }, [objectData, maxItems]);
38221
38236
  const [sort, setSort] = useState12(sortBy);
38222
- const modalRef = useRef5(null);
38237
+ const modalRef = useRef6(null);
38223
38238
  const [dialogRow, setDialogRow] = useState12({});
38224
38239
  const context = {
38225
38240
  objectData,
@@ -38247,7 +38262,7 @@ function Table3({
38247
38262
  setSort,
38248
38263
  ...props
38249
38264
  };
38250
- useEffect8(() => {
38265
+ useEffect9(() => {
38251
38266
  if ((dialogRow == null ? void 0 : dialogRow.id) || (dialogRow == null ? void 0 : dialogRow._id)) {
38252
38267
  const newDialogRow = objectData[dialogRow == null ? void 0 : dialogRow.id] || objectData[dialogRow == null ? void 0 : dialogRow._id];
38253
38268
  setDialogRow(newDialogRow);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-recomponents",
3
- "version": "2.0.13",
3
+ "version": "2.0.15",
4
4
  "description": "description nueva",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,4 +1,5 @@
1
- import React, { ReactElement, ReactNode, cloneElement } from "react";
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,21 @@ 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
+ const props = children?.props;
32
+ const onClick = props?.onClick;
24
33
  return (
25
34
  <>
26
35
  {cloneElement(button, {
27
- onClick: async (e: React.MouseEvent<HTMLButtonElement>) => {
28
- await pop.modal(
29
- React.cloneElement(children, { hide: () => pop.close(false) }),
30
- color,
31
- false,
32
- true,
33
- );
36
+ onClick: (e) => {
37
+ onClick?.(e as any);
38
+ pop.modal(children, color, false, true);
34
39
  },
35
40
  })}
36
-
37
41
  {pop.PopupComponent}
38
42
  </>
39
43
  );
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
- const INITIAL_STATE: PopupState = {
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<PopupState>(INITIAL_STATE);
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
- setPopup({ ...partial, visible: true, inputValue: "" });
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 { alert, confirm, prompt, modal, PopupComponent, close };
120
+ return {
121
+ alert,
122
+ confirm,
123
+ prompt,
124
+ modal,
125
+ PopupComponent,
126
+ close,
127
+ updateMessage,
128
+ };
107
129
  }
@@ -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] "}