next-recomponents 2.0.31 → 2.0.33

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
@@ -232,12 +232,12 @@ type PopupColor = "white" | "primary" | "secondary" | "info" | "danger" | "warni
232
232
 
233
233
  declare function usePopup(): {
234
234
  alert: (message: string, color?: PopupColor) => Promise<void>;
235
- confirm: (message: string, color?: PopupColor) => Promise<boolean>;
236
- prompt: (message: string, color?: PopupColor) => Promise<string | null>;
235
+ confirm: typeof confirm;
236
+ prompt: typeof prompt;
237
237
  modal: (message: ReactNode, color?: PopupColor, icons?: boolean, full?: boolean) => Promise<void>;
238
- PopupComponent: react_jsx_runtime.JSX.Element | null;
239
238
  close: (confirmed: boolean, value?: string) => void;
240
239
  updateMessage: (message: ReactNode) => void;
240
+ PopupComponent: () => react_jsx_runtime.JSX.Element | null;
241
241
  };
242
242
 
243
243
  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
@@ -232,12 +232,12 @@ type PopupColor = "white" | "primary" | "secondary" | "info" | "danger" | "warni
232
232
 
233
233
  declare function usePopup(): {
234
234
  alert: (message: string, color?: PopupColor) => Promise<void>;
235
- confirm: (message: string, color?: PopupColor) => Promise<boolean>;
236
- prompt: (message: string, color?: PopupColor) => Promise<string | null>;
235
+ confirm: typeof confirm;
236
+ prompt: typeof prompt;
237
237
  modal: (message: ReactNode, color?: PopupColor, icons?: boolean, full?: boolean) => Promise<void>;
238
- PopupComponent: react_jsx_runtime.JSX.Element | null;
239
238
  close: (confirmed: boolean, value?: string) => void;
240
239
  updateMessage: (message: ReactNode) => void;
240
+ PopupComponent: () => react_jsx_runtime.JSX.Element | null;
241
241
  };
242
242
 
243
243
  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
@@ -35882,6 +35882,7 @@ function ModalDialog({
35882
35882
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "mt-4 m-auto p-5", children: selectedRow && import_react5.default.cloneElement(
35883
35883
  modal,
35884
35884
  {
35885
+ key: selectedRow.id,
35885
35886
  row: selectedRow,
35886
35887
  hide: onClose
35887
35888
  }
@@ -36957,7 +36958,7 @@ var import_react10 = require("react");
36957
36958
  var import_jsx_runtime12 = require("react/jsx-runtime");
36958
36959
  function PopupActions({
36959
36960
  type,
36960
- confirm,
36961
+ confirm: confirm2,
36961
36962
  focusRing,
36962
36963
  onConfirm,
36963
36964
  onCancel
@@ -36976,7 +36977,7 @@ function PopupActions({
36976
36977
  "button",
36977
36978
  {
36978
36979
  onClick: onConfirm,
36979
- className: `px-5 py-2 rounded-lg text-sm font-semibold text-white ${confirm} transition focus:outline-none focus:ring-2 ${focusRing}`,
36980
+ className: `px-5 py-2 rounded-lg text-sm font-semibold text-white ${confirm2} transition focus:outline-none focus:ring-2 ${focusRing}`,
36980
36981
  children: "Aceptar"
36981
36982
  }
36982
36983
  )
@@ -37192,16 +37193,18 @@ var INITIAL_STATE = {
37192
37193
  inputValue: "",
37193
37194
  color: "primary",
37194
37195
  icons: true,
37195
- full: false
37196
+ full: false,
37197
+ message: null
37196
37198
  };
37197
37199
  function usePopup() {
37198
37200
  const [popup, setPopup] = (0, import_react10.useState)(INITIAL_STATE);
37199
- const messageRef = (0, import_react10.useRef)(null);
37200
37201
  const open = (0, import_react10.useCallback)(
37201
37202
  (partial) => {
37202
- const { message, ...rest } = partial;
37203
- messageRef.current = message;
37204
- setPopup({ ...rest, visible: true, inputValue: "" });
37203
+ setPopup({
37204
+ ...partial,
37205
+ visible: true,
37206
+ inputValue: ""
37207
+ });
37205
37208
  },
37206
37209
  []
37207
37210
  );
@@ -37210,9 +37213,19 @@ function usePopup() {
37210
37213
  var _a, _b;
37211
37214
  if (confirmed) (_a = prev.onConfirm) == null ? void 0 : _a.call(prev, value);
37212
37215
  else (_b = prev.onCancel) == null ? void 0 : _b.call(prev);
37213
- return { ...prev, visible: false, inputValue: "" };
37216
+ return {
37217
+ ...prev,
37218
+ visible: false,
37219
+ inputValue: ""
37220
+ };
37214
37221
  });
37215
37222
  }, []);
37223
+ const updateMessage = (0, import_react10.useCallback)((message) => {
37224
+ setPopup((prev) => ({
37225
+ ...prev,
37226
+ message
37227
+ }));
37228
+ }, []);
37216
37229
  const alert2 = (0, import_react10.useCallback)(
37217
37230
  (message, color = "primary") => new Promise(
37218
37231
  (resolve) => open({
@@ -37220,7 +37233,9 @@ function usePopup() {
37220
37233
  message,
37221
37234
  color,
37222
37235
  onConfirm: () => resolve(),
37223
- onCancel: () => resolve()
37236
+ onCancel: () => resolve(),
37237
+ icons: true,
37238
+ full: false
37224
37239
  })
37225
37240
  ),
37226
37241
  [open]
@@ -37231,58 +37246,36 @@ function usePopup() {
37231
37246
  type: "modal",
37232
37247
  message,
37233
37248
  color,
37234
- onConfirm: () => resolve(),
37235
- onCancel: () => resolve(),
37236
37249
  icons,
37237
- full
37238
- })
37239
- ),
37240
- [open]
37241
- );
37242
- const confirm = (0, import_react10.useCallback)(
37243
- (message, color = "primary") => new Promise(
37244
- (resolve) => open({
37245
- type: "confirm",
37246
- message,
37247
- color,
37248
- onConfirm: () => resolve(true),
37249
- onCancel: () => resolve(false)
37250
- })
37251
- ),
37252
- [open]
37253
- );
37254
- const prompt = (0, import_react10.useCallback)(
37255
- (message, color = "primary") => new Promise(
37256
- (resolve) => open({
37257
- type: "prompt",
37258
- message,
37259
- color,
37260
- onConfirm: (value) => resolve(value != null ? value : ""),
37261
- onCancel: () => resolve(null)
37250
+ full,
37251
+ onConfirm: () => resolve(),
37252
+ onCancel: () => resolve()
37262
37253
  })
37263
37254
  ),
37264
37255
  [open]
37265
37256
  );
37266
- const updateMessage = (0, import_react10.useCallback)((message) => {
37267
- messageRef.current = message;
37268
- setPopup((prev) => ({ ...prev }));
37269
- }, []);
37270
- const PopupComponent = popup.visible ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
37271
- PopupOverlay,
37272
- {
37273
- popup: { ...popup, message: messageRef.current },
37274
- onClose: close,
37275
- onInputChange: (v) => setPopup((prev) => ({ ...prev, inputValue: v }))
37276
- }
37277
- ) : null;
37257
+ const PopupComponent = () => {
37258
+ if (!popup.visible) return null;
37259
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
37260
+ PopupOverlay,
37261
+ {
37262
+ popup,
37263
+ onClose: close,
37264
+ onInputChange: (v) => setPopup((prev) => ({
37265
+ ...prev,
37266
+ inputValue: v
37267
+ }))
37268
+ }
37269
+ );
37270
+ };
37278
37271
  return {
37279
37272
  alert: alert2,
37280
37273
  confirm,
37281
37274
  prompt,
37282
37275
  modal,
37283
- PopupComponent,
37284
37276
  close,
37285
- updateMessage
37277
+ updateMessage,
37278
+ PopupComponent
37286
37279
  };
37287
37280
  }
37288
37281
 
@@ -37296,20 +37289,25 @@ function Modal({
37296
37289
  }) {
37297
37290
  const pop = usePopup();
37298
37291
  const hide = () => pop.close(false);
37299
- const childrenWithHide = (0, import_react11.cloneElement)(children, { hide });
37300
- (0, import_react11.useEffect)(() => {
37301
- pop.updateMessage(childrenWithHide);
37292
+ const content = (0, import_react11.useMemo)(() => {
37293
+ return (0, import_react11.cloneElement)(children, {
37294
+ hide,
37295
+ key: crypto.randomUUID()
37296
+ });
37302
37297
  }, [children]);
37298
+ (0, import_react11.useEffect)(() => {
37299
+ pop.updateMessage(content);
37300
+ }, [content]);
37303
37301
  const props = button == null ? void 0 : button.props;
37304
- const onClick = props == null ? void 0 : props.onClick;
37302
+ const originalOnClick = props == null ? void 0 : props.onClick;
37305
37303
  return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
37306
37304
  (0, import_react11.cloneElement)(button, {
37307
- onClick: (e) => {
37308
- onClick == null ? void 0 : onClick(e);
37309
- pop.modal(childrenWithHide, color, false, true);
37305
+ onClick: async (e) => {
37306
+ originalOnClick == null ? void 0 : originalOnClick(e);
37307
+ await pop.modal(content, color, false, true);
37310
37308
  }
37311
37309
  }),
37312
- pop.PopupComponent
37310
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(pop.PopupComponent, {})
37313
37311
  ] });
37314
37312
  }
37315
37313