next-recomponents 1.3.1 → 1.3.3

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.js CHANGED
@@ -3026,25 +3026,23 @@ function Button(_a) {
3026
3026
  "disabled"
3027
3027
  ]);
3028
3028
  const [isLoading, setIsloading] = (0, import_react.useState)(false);
3029
- const [newProps, setNewProps] = (0, import_react.useState)(__spreadValues({}, props));
3030
- (0, import_react.useEffect)(() => {
3031
- const oldProps = __spreadValues({}, props);
3032
- const np = __spreadValues({}, props);
3033
- for (let prop in props) {
3034
- if (prop.startsWith("on")) {
3035
- np[prop] = (e) => __async(null, null, function* () {
3036
- setIsloading(true);
3037
- console.log(oldProps[prop]);
3038
- yield oldProps[prop](e);
3039
- setIsloading(false);
3040
- });
3041
- }
3042
- }
3043
- setNewProps(np);
3044
- }, [props]);
3045
3029
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
3046
3030
  "button",
3047
- __spreadProps(__spreadValues({}, newProps), {
3031
+ __spreadProps(__spreadValues({}, Object.assign(
3032
+ {},
3033
+ ...Object.keys(props).map((prop) => {
3034
+ const originalHandler = props[prop];
3035
+ const newProp = { [prop]: originalHandler };
3036
+ if (prop.startsWith("on") && typeof originalHandler === "function") {
3037
+ newProp[prop] = (e) => __async(null, null, function* () {
3038
+ setIsloading(true);
3039
+ originalHandler && (yield originalHandler(e));
3040
+ setIsloading(false);
3041
+ });
3042
+ }
3043
+ return newProp;
3044
+ })
3045
+ )), {
3048
3046
  className: [
3049
3047
  className,
3050
3048
  "p-2 border shadow rounded flex gap-1 justify-center items-center",
@@ -11174,6 +11172,31 @@ function TD(_a) {
11174
11172
  },
11175
11173
  { defaultValue: item == null ? void 0 : item.content }
11176
11174
  );
11175
+ const newProps2 = handlers && Object.keys(handlers[item == null ? void 0 : item.name].props).reduce(
11176
+ (acc, i) => {
11177
+ try {
11178
+ const newAcc = __spreadValues({}, acc);
11179
+ const hasEvent = `${i}`.startsWith("on");
11180
+ if (hasEvent) {
11181
+ newAcc[i] = (e) => {
11182
+ var _a2, _b2;
11183
+ e.item = item;
11184
+ (_b2 = (_a2 = handlers[item == null ? void 0 : item.name].props)[i]) == null ? void 0 : _b2.call(_a2, e);
11185
+ if (i == "onChange") {
11186
+ const newData = [...mapedData];
11187
+ newData[index][item == null ? void 0 : item.name].content = e.target.value;
11188
+ setMapedData == null ? void 0 : setMapedData(newData);
11189
+ }
11190
+ };
11191
+ } else if (i == "value") {
11192
+ newAcc[i] = item == null ? void 0 : item.content;
11193
+ }
11194
+ return newAcc;
11195
+ } catch (error) {
11196
+ }
11197
+ },
11198
+ { defaultValue: item == null ? void 0 : item.content }
11199
+ );
11177
11200
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
11178
11201
  "td",
11179
11202
  {
@@ -11187,19 +11210,7 @@ function TD(_a) {
11187
11210
  ].join(" "),
11188
11211
  children: handlers && handlers[item == null ? void 0 : item.name] ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { children: import_react23.default.Children.map(handlers[item == null ? void 0 : item.name], (child) => {
11189
11212
  if (import_react23.default.isValidElement(child)) {
11190
- const oldProps = (child == null ? void 0 : child.props) || {};
11191
- const alteredProps = __spreadProps(__spreadValues({}, oldProps), {
11192
- value: item == null ? void 0 : item.content,
11193
- onChange: (e) => {
11194
- var _a2;
11195
- const newData = [...mapedData];
11196
- newData[index][item == null ? void 0 : item.name].content = e.target.value;
11197
- setMapedData == null ? void 0 : setMapedData(newData);
11198
- e.item = item;
11199
- (_a2 = oldProps == null ? void 0 : oldProps.onChange) == null ? void 0 : _a2.call(oldProps, e);
11200
- }
11201
- });
11202
- return import_react23.default.cloneElement(child, __spreadValues({}, alteredProps));
11213
+ return import_react23.default.cloneElement(child, __spreadValues({}, newProps2));
11203
11214
  }
11204
11215
  }) }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
11205
11216
  "div",
package/dist/index.mjs CHANGED
@@ -2991,7 +2991,6 @@ function Alert(_a) {
2991
2991
 
2992
2992
  // src/button/index.tsx
2993
2993
  import {
2994
- useEffect,
2995
2994
  useState
2996
2995
  } from "react";
2997
2996
  import { jsxs } from "react/jsx-runtime";
@@ -3012,25 +3011,23 @@ function Button(_a) {
3012
3011
  "disabled"
3013
3012
  ]);
3014
3013
  const [isLoading, setIsloading] = useState(false);
3015
- const [newProps, setNewProps] = useState(__spreadValues({}, props));
3016
- useEffect(() => {
3017
- const oldProps = __spreadValues({}, props);
3018
- const np = __spreadValues({}, props);
3019
- for (let prop in props) {
3020
- if (prop.startsWith("on")) {
3021
- np[prop] = (e) => __async(null, null, function* () {
3022
- setIsloading(true);
3023
- console.log(oldProps[prop]);
3024
- yield oldProps[prop](e);
3025
- setIsloading(false);
3026
- });
3027
- }
3028
- }
3029
- setNewProps(np);
3030
- }, [props]);
3031
3014
  return /* @__PURE__ */ jsxs(
3032
3015
  "button",
3033
- __spreadProps(__spreadValues({}, newProps), {
3016
+ __spreadProps(__spreadValues({}, Object.assign(
3017
+ {},
3018
+ ...Object.keys(props).map((prop) => {
3019
+ const originalHandler = props[prop];
3020
+ const newProp = { [prop]: originalHandler };
3021
+ if (prop.startsWith("on") && typeof originalHandler === "function") {
3022
+ newProp[prop] = (e) => __async(null, null, function* () {
3023
+ setIsloading(true);
3024
+ originalHandler && (yield originalHandler(e));
3025
+ setIsloading(false);
3026
+ });
3027
+ }
3028
+ return newProp;
3029
+ })
3030
+ )), {
3034
3031
  className: [
3035
3032
  className,
3036
3033
  "p-2 border shadow rounded flex gap-1 justify-center items-center",
@@ -11165,6 +11162,31 @@ function TD(_a) {
11165
11162
  },
11166
11163
  { defaultValue: item == null ? void 0 : item.content }
11167
11164
  );
11165
+ const newProps2 = handlers && Object.keys(handlers[item == null ? void 0 : item.name].props).reduce(
11166
+ (acc, i) => {
11167
+ try {
11168
+ const newAcc = __spreadValues({}, acc);
11169
+ const hasEvent = `${i}`.startsWith("on");
11170
+ if (hasEvent) {
11171
+ newAcc[i] = (e) => {
11172
+ var _a2, _b2;
11173
+ e.item = item;
11174
+ (_b2 = (_a2 = handlers[item == null ? void 0 : item.name].props)[i]) == null ? void 0 : _b2.call(_a2, e);
11175
+ if (i == "onChange") {
11176
+ const newData = [...mapedData];
11177
+ newData[index][item == null ? void 0 : item.name].content = e.target.value;
11178
+ setMapedData == null ? void 0 : setMapedData(newData);
11179
+ }
11180
+ };
11181
+ } else if (i == "value") {
11182
+ newAcc[i] = item == null ? void 0 : item.content;
11183
+ }
11184
+ return newAcc;
11185
+ } catch (error) {
11186
+ }
11187
+ },
11188
+ { defaultValue: item == null ? void 0 : item.content }
11189
+ );
11168
11190
  return /* @__PURE__ */ jsx8(
11169
11191
  "td",
11170
11192
  {
@@ -11178,19 +11200,7 @@ function TD(_a) {
11178
11200
  ].join(" "),
11179
11201
  children: handlers && handlers[item == null ? void 0 : item.name] ? /* @__PURE__ */ jsx8("div", { children: React3.Children.map(handlers[item == null ? void 0 : item.name], (child) => {
11180
11202
  if (React3.isValidElement(child)) {
11181
- const oldProps = (child == null ? void 0 : child.props) || {};
11182
- const alteredProps = __spreadProps(__spreadValues({}, oldProps), {
11183
- value: item == null ? void 0 : item.content,
11184
- onChange: (e) => {
11185
- var _a2;
11186
- const newData = [...mapedData];
11187
- newData[index][item == null ? void 0 : item.name].content = e.target.value;
11188
- setMapedData == null ? void 0 : setMapedData(newData);
11189
- e.item = item;
11190
- (_a2 = oldProps == null ? void 0 : oldProps.onChange) == null ? void 0 : _a2.call(oldProps, e);
11191
- }
11192
- });
11193
- return React3.cloneElement(child, __spreadValues({}, alteredProps));
11203
+ return React3.cloneElement(child, __spreadValues({}, newProps2));
11194
11204
  }
11195
11205
  }) }) : /* @__PURE__ */ jsxs6(
11196
11206
  "div",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-recomponents",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -32,25 +32,26 @@ export default function Button({
32
32
  ...props
33
33
  }: Props) {
34
34
  const [isLoading, setIsloading] = useState(false);
35
- const [newProps, setNewProps] = useState({ ...props });
36
- useEffect(() => {
37
- const oldProps: any = { ...props };
38
- const np: any = { ...props };
39
- for (let prop in props) {
40
- if (prop.startsWith("on")) {
41
- np[prop] = async (e: React.FormEvent<HTMLButtonElement>) => {
42
- setIsloading(true);
43
- console.log(oldProps[prop]);
44
- await oldProps[prop](e);
45
- setIsloading(false);
46
- };
47
- }
48
- }
49
- setNewProps(np);
50
- }, [props]);
35
+
51
36
  return (
52
37
  <button
53
- {...newProps}
38
+ {...Object.assign(
39
+ {},
40
+ ...Object.keys(props).map((prop) => {
41
+ const originalHandler = (props as any)[prop];
42
+ const newProp: any = { [prop]: originalHandler };
43
+
44
+ if (prop.startsWith("on") && typeof originalHandler === "function") {
45
+ newProp[prop] = async (e: any) => {
46
+ setIsloading(true);
47
+ originalHandler && (await originalHandler(e));
48
+ setIsloading(false);
49
+ };
50
+ }
51
+
52
+ return newProp;
53
+ })
54
+ )}
54
55
  className={[
55
56
  className,
56
57
  "p-2 border shadow rounded flex gap-1 justify-center items-center",
package/src/table/td.tsx CHANGED
@@ -57,6 +57,32 @@ export default function TD({
57
57
  },
58
58
  { defaultValue: item?.content }
59
59
  );
60
+
61
+ const newProps2 =
62
+ handlers &&
63
+ Object.keys(handlers[item?.name].props).reduce(
64
+ (acc: any, i) => {
65
+ try {
66
+ const newAcc = { ...acc };
67
+ const hasEvent = `${i}`.startsWith("on");
68
+ if (hasEvent) {
69
+ newAcc[i] = (e: any) => {
70
+ e.item = item;
71
+ handlers[item?.name].props[i]?.(e);
72
+ if (i == "onChange") {
73
+ const newData = [...mapedData];
74
+ newData[index][item?.name].content = e.target.value;
75
+ setMapedData?.(newData);
76
+ }
77
+ };
78
+ } else if (i == "value") {
79
+ newAcc[i] = item?.content;
80
+ }
81
+ return newAcc;
82
+ } catch (error) {}
83
+ },
84
+ { defaultValue: item?.content }
85
+ );
60
86
  return (
61
87
  <td
62
88
  onDoubleClick={(e) => setIsHidded(!isHidded)}
@@ -72,20 +98,8 @@ export default function TD({
72
98
  <div>
73
99
  {React.Children.map(handlers[item?.name], (child) => {
74
100
  if (React.isValidElement(child)) {
75
- const oldProps: any = child?.props || {};
76
- const alteredProps = {
77
- ...oldProps,
78
- value: item?.content,
79
- onChange: (e: any) => {
80
- const newData = [...mapedData];
81
- newData[index][item?.name].content = e.target.value;
82
- setMapedData?.(newData);
83
- e.item = item;
84
- oldProps?.onChange?.(e);
85
- },
86
- };
87
101
  return React.cloneElement(child as any, {
88
- ...alteredProps,
102
+ ...newProps2,
89
103
  });
90
104
  }
91
105
  })}