next-recomponents 1.4.6 → 1.4.7

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
@@ -69,7 +69,10 @@ interface TableProps extends React.DetailedHTMLProps<React.TableHTMLAttributes<H
69
69
  exportName?: string;
70
70
  onSave?: (e: {
71
71
  data: Record<string, any>;
72
- }) => void;
72
+ }) => void | Promise<(e: {
73
+ data: Record<string, any>;
74
+ }) => void>;
75
+ loader: React.ReactNode;
73
76
  }
74
77
  declare function Table({ ...props }: TableProps): react_jsx_runtime.JSX.Element;
75
78
 
package/dist/index.d.ts CHANGED
@@ -69,7 +69,10 @@ interface TableProps extends React.DetailedHTMLProps<React.TableHTMLAttributes<H
69
69
  exportName?: string;
70
70
  onSave?: (e: {
71
71
  data: Record<string, any>;
72
- }) => void;
72
+ }) => void | Promise<(e: {
73
+ data: Record<string, any>;
74
+ }) => void>;
75
+ loader: React.ReactNode;
73
76
  }
74
77
  declare function Table({ ...props }: TableProps): react_jsx_runtime.JSX.Element;
75
78
 
package/dist/index.js CHANGED
@@ -31940,15 +31940,18 @@ function HTable(_a) {
31940
31940
  symbols,
31941
31941
  totals,
31942
31942
  exportName,
31943
- onSave
31943
+ onSave,
31944
+ loader = "Loading..."
31944
31945
  } = _b, props = __objRest(_b, [
31945
31946
  "data",
31946
31947
  "symbols",
31947
31948
  "totals",
31948
31949
  "exportName",
31949
- "onSave"
31950
+ "onSave",
31951
+ "loader"
31950
31952
  ]);
31951
31953
  if (!Array.isArray(data)) return null;
31954
+ const [isLoading, setIsLoading] = (0, import_react25.useState)(false);
31952
31955
  const [mapedData, setMapedData] = (0, import_react25.useState)([...data]);
31953
31956
  const exported = useExportdata();
31954
31957
  const [selected, setSelected] = (0, import_react25.useState)(null);
@@ -31971,9 +31974,6 @@ function HTable(_a) {
31971
31974
  return acc;
31972
31975
  }, {});
31973
31976
  }, [mapedData]);
31974
- (0, import_react25.useEffect)(() => {
31975
- setMapedData(data);
31976
- }, [data]);
31977
31977
  (0, import_react25.useEffect)(() => {
31978
31978
  const newData = data.map((d, trkey) => {
31979
31979
  var _a2, _b2;
@@ -32016,9 +32016,11 @@ function HTable(_a) {
32016
32016
  "button",
32017
32017
  {
32018
32018
  className: "p-2 border rounded shadow bg-blue-800 text-white flex gap-1",
32019
- onClick: (e) => {
32020
- onSave({ data: values });
32021
- },
32019
+ onClick: (e) => __async(null, null, function* () {
32020
+ setIsLoading(true);
32021
+ yield onSave({ data: values });
32022
+ setIsLoading(false);
32023
+ }),
32022
32024
  children: [
32023
32025
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(SaveIcon, {}),
32024
32026
  " Guardar"
@@ -32133,7 +32135,8 @@ function HTable(_a) {
32133
32135
  fkey
32134
32136
  );
32135
32137
  }) }) })
32136
- ] }))
32138
+ ] })),
32139
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "fixed top-0 left-0 w-full h-screen flex items-center justify-center bg-white bg-opacity-50", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { children: loader }) })
32137
32140
  ] });
32138
32141
  }
32139
32142
 
@@ -32387,7 +32390,7 @@ function useResources({
32387
32390
  }
32388
32391
  }),
32389
32392
  create: (data) => __async(null, null, function* () {
32390
- var _a, _b, _c2;
32393
+ var _a, _b, _c2, _d2, _e2, _f2;
32391
32394
  const options = {
32392
32395
  method: "POST",
32393
32396
  url: `${baseURI}/${key}`,
@@ -32404,17 +32407,34 @@ function useResources({
32404
32407
  const d = consulta.data;
32405
32408
  newInfo[key].state = "success";
32406
32409
  newInfo[key].errorMessage = "";
32407
- newInfo[key].selectedItem = d;
32408
- const index = (_b = (_a = newInfo[key]) == null ? void 0 : _a.data) == null ? void 0 : _b.findIndex(
32409
- (d2) => (d2 == null ? void 0 : d2.id) == (d2 == null ? void 0 : d2.id)
32410
- );
32411
- if (index >= 0) {
32412
- newInfo[key].data[index] = d;
32410
+ if (Array.isArray(data)) {
32411
+ for (let datum of data) {
32412
+ const index = (_b = (_a = newInfo[key]) == null ? void 0 : _a.data) == null ? void 0 : _b.findIndex(
32413
+ (d2) => (d2 == null ? void 0 : d2.id) == (datum == null ? void 0 : datum.id)
32414
+ );
32415
+ if (index >= 0) {
32416
+ newInfo[key].data[index] = d;
32417
+ } else {
32418
+ if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
32419
+ newInfo[key].data.unshift(d);
32420
+ } else {
32421
+ newInfo[key].data = [d];
32422
+ }
32423
+ }
32424
+ }
32413
32425
  } else {
32414
- if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
32415
- newInfo[key].data.unshift(d);
32426
+ newInfo[key].selectedItem = d;
32427
+ const index = (_e2 = (_d2 = newInfo[key]) == null ? void 0 : _d2.data) == null ? void 0 : _e2.findIndex(
32428
+ (d2) => (d2 == null ? void 0 : d2.id) == (d2 == null ? void 0 : d2.id)
32429
+ );
32430
+ if (index >= 0) {
32431
+ newInfo[key].data[index] = d;
32416
32432
  } else {
32417
- newInfo[key].data = [d];
32433
+ if ((_f2 = newInfo[key]) == null ? void 0 : _f2.data) {
32434
+ newInfo[key].data.unshift(d);
32435
+ } else {
32436
+ newInfo[key].data = [d];
32437
+ }
32418
32438
  }
32419
32439
  }
32420
32440
  setInfo(__spreadValues({}, newInfo));
@@ -32779,13 +32799,14 @@ function Modal({ button, children, ref }) {
32779
32799
  return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
32780
32800
  import_react30.default.Children.map(button, (child) => {
32781
32801
  if (import_react30.default.isValidElement(child)) {
32782
- return import_react30.default.cloneElement(child, {
32802
+ const { type, props } = child;
32803
+ return import_react30.default.createElement(type, __spreadProps(__spreadValues({}, props), {
32783
32804
  onClick: (e) => {
32784
32805
  var _a, _b;
32785
32806
  show();
32786
32807
  (_b = (_a = child.props) == null ? void 0 : _a.onClick) == null ? void 0 : _b.call(_a, e);
32787
32808
  }
32788
- });
32809
+ }));
32789
32810
  }
32790
32811
  return child;
32791
32812
  }),
@@ -32800,7 +32821,8 @@ function Modal({ button, children, ref }) {
32800
32821
  ),
32801
32822
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "flex flex-col gap-3 pt-6", children: import_react30.default.Children.map(children, (child) => {
32802
32823
  if (import_react30.default.isValidElement(child)) {
32803
- return import_react30.default.cloneElement(child, { hide });
32824
+ const { type, props } = child;
32825
+ return import_react30.default.createElement(type, __spreadProps(__spreadValues({}, props), { hide }));
32804
32826
  }
32805
32827
  return child;
32806
32828
  }) })
package/dist/index.mjs CHANGED
@@ -31928,15 +31928,18 @@ function HTable(_a) {
31928
31928
  symbols,
31929
31929
  totals,
31930
31930
  exportName,
31931
- onSave
31931
+ onSave,
31932
+ loader = "Loading..."
31932
31933
  } = _b, props = __objRest(_b, [
31933
31934
  "data",
31934
31935
  "symbols",
31935
31936
  "totals",
31936
31937
  "exportName",
31937
- "onSave"
31938
+ "onSave",
31939
+ "loader"
31938
31940
  ]);
31939
31941
  if (!Array.isArray(data)) return null;
31942
+ const [isLoading, setIsLoading] = useState6(false);
31940
31943
  const [mapedData, setMapedData] = useState6([...data]);
31941
31944
  const exported = useExportdata();
31942
31945
  const [selected, setSelected] = useState6(null);
@@ -31959,9 +31962,6 @@ function HTable(_a) {
31959
31962
  return acc;
31960
31963
  }, {});
31961
31964
  }, [mapedData]);
31962
- useEffect7(() => {
31963
- setMapedData(data);
31964
- }, [data]);
31965
31965
  useEffect7(() => {
31966
31966
  const newData = data.map((d, trkey) => {
31967
31967
  var _a2, _b2;
@@ -32004,9 +32004,11 @@ function HTable(_a) {
32004
32004
  "button",
32005
32005
  {
32006
32006
  className: "p-2 border rounded shadow bg-blue-800 text-white flex gap-1",
32007
- onClick: (e) => {
32008
- onSave({ data: values });
32009
- },
32007
+ onClick: (e) => __async(null, null, function* () {
32008
+ setIsLoading(true);
32009
+ yield onSave({ data: values });
32010
+ setIsLoading(false);
32011
+ }),
32010
32012
  children: [
32011
32013
  /* @__PURE__ */ jsx11(SaveIcon, {}),
32012
32014
  " Guardar"
@@ -32121,7 +32123,8 @@ function HTable(_a) {
32121
32123
  fkey
32122
32124
  );
32123
32125
  }) }) })
32124
- ] }))
32126
+ ] })),
32127
+ isLoading && /* @__PURE__ */ jsx11("div", { className: "fixed top-0 left-0 w-full h-screen flex items-center justify-center bg-white bg-opacity-50", children: /* @__PURE__ */ jsx11("div", { children: loader }) })
32125
32128
  ] });
32126
32129
  }
32127
32130
 
@@ -32377,7 +32380,7 @@ function useResources({
32377
32380
  }
32378
32381
  }),
32379
32382
  create: (data) => __async(null, null, function* () {
32380
- var _a, _b, _c2;
32383
+ var _a, _b, _c2, _d2, _e2, _f2;
32381
32384
  const options = {
32382
32385
  method: "POST",
32383
32386
  url: `${baseURI}/${key}`,
@@ -32394,17 +32397,34 @@ function useResources({
32394
32397
  const d = consulta.data;
32395
32398
  newInfo[key].state = "success";
32396
32399
  newInfo[key].errorMessage = "";
32397
- newInfo[key].selectedItem = d;
32398
- const index = (_b = (_a = newInfo[key]) == null ? void 0 : _a.data) == null ? void 0 : _b.findIndex(
32399
- (d2) => (d2 == null ? void 0 : d2.id) == (d2 == null ? void 0 : d2.id)
32400
- );
32401
- if (index >= 0) {
32402
- newInfo[key].data[index] = d;
32400
+ if (Array.isArray(data)) {
32401
+ for (let datum of data) {
32402
+ const index = (_b = (_a = newInfo[key]) == null ? void 0 : _a.data) == null ? void 0 : _b.findIndex(
32403
+ (d2) => (d2 == null ? void 0 : d2.id) == (datum == null ? void 0 : datum.id)
32404
+ );
32405
+ if (index >= 0) {
32406
+ newInfo[key].data[index] = d;
32407
+ } else {
32408
+ if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
32409
+ newInfo[key].data.unshift(d);
32410
+ } else {
32411
+ newInfo[key].data = [d];
32412
+ }
32413
+ }
32414
+ }
32403
32415
  } else {
32404
- if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
32405
- newInfo[key].data.unshift(d);
32416
+ newInfo[key].selectedItem = d;
32417
+ const index = (_e2 = (_d2 = newInfo[key]) == null ? void 0 : _d2.data) == null ? void 0 : _e2.findIndex(
32418
+ (d2) => (d2 == null ? void 0 : d2.id) == (d2 == null ? void 0 : d2.id)
32419
+ );
32420
+ if (index >= 0) {
32421
+ newInfo[key].data[index] = d;
32406
32422
  } else {
32407
- newInfo[key].data = [d];
32423
+ if ((_f2 = newInfo[key]) == null ? void 0 : _f2.data) {
32424
+ newInfo[key].data.unshift(d);
32425
+ } else {
32426
+ newInfo[key].data = [d];
32427
+ }
32408
32428
  }
32409
32429
  }
32410
32430
  setInfo(__spreadValues({}, newInfo));
@@ -32773,13 +32793,14 @@ function Modal({ button, children, ref }) {
32773
32793
  return /* @__PURE__ */ jsxs12(Fragment5, { children: [
32774
32794
  React7.Children.map(button, (child) => {
32775
32795
  if (React7.isValidElement(child)) {
32776
- return React7.cloneElement(child, {
32796
+ const { type, props } = child;
32797
+ return React7.createElement(type, __spreadProps(__spreadValues({}, props), {
32777
32798
  onClick: (e) => {
32778
32799
  var _a, _b;
32779
32800
  show();
32780
32801
  (_b = (_a = child.props) == null ? void 0 : _a.onClick) == null ? void 0 : _b.call(_a, e);
32781
32802
  }
32782
- });
32803
+ }));
32783
32804
  }
32784
32805
  return child;
32785
32806
  }),
@@ -32794,7 +32815,8 @@ function Modal({ button, children, ref }) {
32794
32815
  ),
32795
32816
  /* @__PURE__ */ jsx17("div", { className: "flex flex-col gap-3 pt-6", children: React7.Children.map(children, (child) => {
32796
32817
  if (React7.isValidElement(child)) {
32797
- return React7.cloneElement(child, { hide });
32818
+ const { type, props } = child;
32819
+ return React7.createElement(type, __spreadProps(__spreadValues({}, props), { hide }));
32798
32820
  }
32799
32821
  return child;
32800
32822
  }) })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-recomponents",
3
- "version": "1.4.6",
3
+ "version": "1.4.7",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -17,6 +17,7 @@
17
17
  "typescript": "^5.8.3"
18
18
  },
19
19
  "dependencies": {
20
+ "@emotion/is-prop-valid": "^1.3.1",
20
21
  "axios": "^1.9.0",
21
22
  "moment": "^2.30.1",
22
23
  "react": "^19.1.0",
@@ -21,8 +21,10 @@ export default function Modal({ button, children, ref }: Props) {
21
21
  <>
22
22
  {React.Children.map(button, (child) => {
23
23
  if (React.isValidElement(child)) {
24
- return React.cloneElement(child, {
25
- onClick: (e) => {
24
+ const { type, props } = child;
25
+ return React.createElement(type, {
26
+ ...props,
27
+ onClick: (e: any) => {
26
28
  show();
27
29
  child.props?.onClick?.(e);
28
30
  },
@@ -42,7 +44,8 @@ export default function Modal({ button, children, ref }: Props) {
42
44
  <div className="flex flex-col gap-3 pt-6">
43
45
  {React.Children.map(children, (child) => {
44
46
  if (React.isValidElement(child)) {
45
- return React.cloneElement(child, { hide });
47
+ const { type, props } = child;
48
+ return React.createElement(type, { ...props, hide });
46
49
  }
47
50
  return child;
48
51
  })}
package/src/table/h.tsx CHANGED
@@ -11,9 +11,12 @@ export default function HTable({
11
11
  totals,
12
12
  exportName,
13
13
  onSave,
14
+ loader = "Loading...",
14
15
  ...props
15
16
  }: TableProps) {
16
17
  if (!Array.isArray(data)) return null;
18
+
19
+ const [isLoading, setIsLoading] = useState(false);
17
20
  const [mapedData, setMapedData] = useState([...data]);
18
21
  const exported = useExportdata();
19
22
  const [selected, setSelected] = useState<number | null>(null);
@@ -37,10 +40,6 @@ export default function HTable({
37
40
  }, {});
38
41
  }, [mapedData]);
39
42
 
40
- useEffect(() => {
41
- setMapedData(data);
42
- }, [data]);
43
-
44
43
  useEffect(() => {
45
44
  const newData = data.map((d: any, trkey: number) => {
46
45
  const obj: any = {};
@@ -92,8 +91,10 @@ export default function HTable({
92
91
  {onSave && (
93
92
  <button
94
93
  className="p-2 border rounded shadow bg-blue-800 text-white flex gap-1"
95
- onClick={(e) => {
96
- onSave({ data: values });
94
+ onClick={async (e) => {
95
+ setIsLoading(true);
96
+ await onSave({ data: values });
97
+ setIsLoading(false);
97
98
  }}
98
99
  >
99
100
  <SaveIcon /> Guardar
@@ -215,6 +216,11 @@ export default function HTable({
215
216
  </tfoot>
216
217
  )}
217
218
  </table>
219
+ {isLoading && (
220
+ <div className="fixed top-0 left-0 w-full h-screen flex items-center justify-center bg-white bg-opacity-50">
221
+ <div>{loader}</div>
222
+ </div>
223
+ )}
218
224
  </>
219
225
  );
220
226
  }
@@ -14,7 +14,10 @@ export interface TableProps
14
14
  totals?: Array<string>;
15
15
  symbols?: Record<string, ReactNode>;
16
16
  exportName?: string;
17
- onSave?: (e: { data: Record<string, any> }) => void;
17
+ onSave?: (e: {
18
+ data: Record<string, any>;
19
+ }) => void | Promise<(e: { data: Record<string, any> }) => void>;
20
+ loader: React.ReactNode;
18
21
  }
19
22
 
20
23
  export default function Table({ ...props }: TableProps) {
@@ -116,7 +116,7 @@ export default function useResources<T extends Record<string, ItemsRecord>>({
116
116
  return error;
117
117
  }
118
118
  },
119
- create: async (data: any) => {
119
+ create: async (data: Record<string, any> | Record<string, any>[]) => {
120
120
  const options = {
121
121
  method: "POST",
122
122
  url: `${baseURI}/${key}`,
@@ -135,17 +135,34 @@ export default function useResources<T extends Record<string, ItemsRecord>>({
135
135
  const d = consulta.data;
136
136
  newInfo[key].state = "success";
137
137
  newInfo[key].errorMessage = "";
138
- newInfo[key].selectedItem = d;
139
- const index = newInfo[key]?.data?.findIndex(
140
- (d: any) => d?.id == d?.id
141
- );
142
- if (index >= 0) {
143
- newInfo[key].data[index] = d;
138
+ if (Array.isArray(data)) {
139
+ for (let datum of data) {
140
+ const index = newInfo[key]?.data?.findIndex(
141
+ (d: any) => d?.id == datum?.id
142
+ );
143
+ if (index >= 0) {
144
+ newInfo[key].data[index] = d;
145
+ } else {
146
+ if (newInfo[key]?.data) {
147
+ newInfo[key].data.unshift(d);
148
+ } else {
149
+ newInfo[key].data = [d];
150
+ }
151
+ }
152
+ }
144
153
  } else {
145
- if (newInfo[key]?.data) {
146
- newInfo[key].data.unshift(d);
154
+ newInfo[key].selectedItem = d;
155
+ const index = newInfo[key]?.data?.findIndex(
156
+ (d: any) => d?.id == d?.id
157
+ );
158
+ if (index >= 0) {
159
+ newInfo[key].data[index] = d;
147
160
  } else {
148
- newInfo[key].data = [d];
161
+ if (newInfo[key]?.data) {
162
+ newInfo[key].data.unshift(d);
163
+ } else {
164
+ newInfo[key].data = [d];
165
+ }
149
166
  }
150
167
  }
151
168
  setInfo({ ...newInfo });