antd-crud-table 0.4.0 → 0.5.0
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/README.md +48 -89
- package/dist/CrudTable-DUfRGJW2.js +524 -0
- package/dist/CrudTable-TTRqkEoZ.cjs +1 -0
- package/dist/CrudTable.cjs +1 -1
- package/dist/CrudTable.d.ts +2 -2
- package/dist/CrudTable.js +3 -306
- package/dist/CrudTableLazy.cjs +1 -1
- package/dist/CrudTableLazy.d.ts +1 -1
- package/dist/CrudTableLazy.js +1 -1
- package/dist/exportData.cjs +12 -12
- package/dist/exportData.js +13 -17
- package/dist/fields/registry.d.ts +38 -0
- package/dist/hooks/useCrudTable.d.ts +2 -1
- package/dist/hooks/useCrudTable.test.d.ts +1 -0
- package/dist/hooks/useLocalStorageCrud.d.ts +5 -0
- package/dist/hooks/useLocalStorageCrud.test.d.ts +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +6 -0
- package/dist/useCrudTable-CEY_riQg.cjs +1 -0
- package/dist/useCrudTable-DpF-oZHz.js +246 -0
- package/dist/useCrudTable.cjs +1 -1
- package/dist/useCrudTable.js +2 -235
- package/dist/useLocalStorageCrud.cjs +1 -1
- package/dist/useLocalStorageCrud.js +29 -176
- package/dist/utils/exportData.d.ts +5 -1
- package/dist/utils/exportData.test.d.ts +1 -0
- package/dist/utils/query.d.ts +13 -0
- package/dist/utils/query.test.d.ts +1 -0
- package/package.json +26 -11
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { message as e } from "antd";
|
|
2
|
+
import { useCallback as t, useMemo as n, useRef as r, useState as i } from "react";
|
|
3
|
+
//#region lib/utils/query.ts
|
|
4
|
+
var a = (e, t) => {
|
|
5
|
+
let { current: n = 1, pageSize: r = 10, sortBy: i, sortOrder: a, ...o } = t, s = e.filter((e) => Object.entries(o).every(([t, n]) => {
|
|
6
|
+
if (n == null || n === "") return !0;
|
|
7
|
+
let r = e[t];
|
|
8
|
+
return r == null ? !1 : String(r).toLowerCase().includes(String(n).toLowerCase());
|
|
9
|
+
}));
|
|
10
|
+
i && a && (s = [...s].sort((e, t) => {
|
|
11
|
+
let n = e[i], r = t[i];
|
|
12
|
+
if (n == null) return 1;
|
|
13
|
+
if (r == null) return -1;
|
|
14
|
+
let o = n > r ? 1 : n < r ? -1 : 0;
|
|
15
|
+
return a === "ascend" ? o : -o;
|
|
16
|
+
}));
|
|
17
|
+
let c = (n - 1) * r;
|
|
18
|
+
return {
|
|
19
|
+
data: s.slice(c, c + r),
|
|
20
|
+
total: s.length,
|
|
21
|
+
success: !0
|
|
22
|
+
};
|
|
23
|
+
}, o = (e) => {
|
|
24
|
+
let { baseUrl: t = "", endpoints: n = {}, headers: r = {}, transform: i } = e, a = {
|
|
25
|
+
list: "/list",
|
|
26
|
+
create: "/create",
|
|
27
|
+
update: "/update",
|
|
28
|
+
delete: "/delete",
|
|
29
|
+
...n
|
|
30
|
+
}, o = async (e, n = {}) => {
|
|
31
|
+
let i = await fetch(`${t}${e}`, {
|
|
32
|
+
headers: {
|
|
33
|
+
"Content-Type": "application/json",
|
|
34
|
+
...r
|
|
35
|
+
},
|
|
36
|
+
...n
|
|
37
|
+
});
|
|
38
|
+
if (!i.ok) throw Error(`HTTP error! status: ${i.status}`);
|
|
39
|
+
return i.json();
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
getList: async (e) => {
|
|
43
|
+
let t = new URLSearchParams();
|
|
44
|
+
Object.entries(e).forEach(([e, n]) => {
|
|
45
|
+
n != null && t.append(e, String(n));
|
|
46
|
+
});
|
|
47
|
+
let n = t.toString(), r = await o(n ? `${a.list}?${n}` : a.list);
|
|
48
|
+
return i?.response ? i.response(r) : r;
|
|
49
|
+
},
|
|
50
|
+
create: async (e) => {
|
|
51
|
+
let t = i?.request ? i.request(e) : e;
|
|
52
|
+
return o(a.create, {
|
|
53
|
+
method: "POST",
|
|
54
|
+
body: JSON.stringify(t)
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
update: async (e, t) => {
|
|
58
|
+
let n = i?.request ? i.request(t) : t;
|
|
59
|
+
return o(`${a.update}/${e}`, {
|
|
60
|
+
method: "PUT",
|
|
61
|
+
body: JSON.stringify(n)
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
delete: async (e) => {
|
|
65
|
+
await o(`${a.delete}/${e}`, { method: "DELETE" });
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}, s = (e, t) => {
|
|
69
|
+
let n = [...e], r = n.length > 0 ? Math.max(...n.map((e) => Number(e[t]) || 0)) + 1 : 1;
|
|
70
|
+
return {
|
|
71
|
+
getList: async (e) => a(n, e),
|
|
72
|
+
create: async (e) => {
|
|
73
|
+
let i = {
|
|
74
|
+
[t]: r++,
|
|
75
|
+
...e
|
|
76
|
+
};
|
|
77
|
+
return n.push(i), i;
|
|
78
|
+
},
|
|
79
|
+
update: async (e, r) => {
|
|
80
|
+
let i = n.findIndex((n) => n[t] === e);
|
|
81
|
+
if (i === -1) throw Error("Item not found");
|
|
82
|
+
return n[i] = {
|
|
83
|
+
...n[i],
|
|
84
|
+
...r
|
|
85
|
+
}, n[i];
|
|
86
|
+
},
|
|
87
|
+
delete: async (e) => {
|
|
88
|
+
let r = n.findIndex((n) => n[t] === e);
|
|
89
|
+
if (r === -1) throw Error("Item not found");
|
|
90
|
+
n.splice(r, 1);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}, c = (a, c) => {
|
|
94
|
+
let l = r(void 0), [u, d] = i({
|
|
95
|
+
loading: !1,
|
|
96
|
+
error: null,
|
|
97
|
+
data: [],
|
|
98
|
+
total: 0,
|
|
99
|
+
current: 1,
|
|
100
|
+
pageSize: c.defaultPageSize || 10
|
|
101
|
+
}), f = "operations" in c ? c.operations : void 0, p = "staticData" in c ? c.staticData : void 0, m = "api" in c ? c.api : void 0, h = n(() => {
|
|
102
|
+
if (f) return f;
|
|
103
|
+
if (p) return s(p, a);
|
|
104
|
+
if (m) return o(m);
|
|
105
|
+
throw Error("useCrudTable: Must provide either staticData, api config, or custom operations");
|
|
106
|
+
}, [
|
|
107
|
+
f,
|
|
108
|
+
p,
|
|
109
|
+
m,
|
|
110
|
+
a
|
|
111
|
+
]), { current: g, pageSize: _ } = u, v = t(async () => {
|
|
112
|
+
d((e) => ({
|
|
113
|
+
...e,
|
|
114
|
+
loading: !0,
|
|
115
|
+
error: null
|
|
116
|
+
}));
|
|
117
|
+
try {
|
|
118
|
+
let e = {
|
|
119
|
+
current: g,
|
|
120
|
+
pageSize: _
|
|
121
|
+
}, t = await h.getList(e);
|
|
122
|
+
d((e) => ({
|
|
123
|
+
...e,
|
|
124
|
+
data: t.data,
|
|
125
|
+
total: t.total,
|
|
126
|
+
loading: !1
|
|
127
|
+
}));
|
|
128
|
+
} catch (t) {
|
|
129
|
+
let n = t instanceof Error ? t.message : "Failed to fetch data";
|
|
130
|
+
d((e) => ({
|
|
131
|
+
...e,
|
|
132
|
+
loading: !1,
|
|
133
|
+
error: n
|
|
134
|
+
})), c.onError?.("fetch", t), e.error(n);
|
|
135
|
+
}
|
|
136
|
+
}, [
|
|
137
|
+
g,
|
|
138
|
+
_,
|
|
139
|
+
h,
|
|
140
|
+
c
|
|
141
|
+
]);
|
|
142
|
+
return {
|
|
143
|
+
refresh: v,
|
|
144
|
+
create: t(async (t) => {
|
|
145
|
+
if (!h.create) return e.error("Create operation not supported"), null;
|
|
146
|
+
try {
|
|
147
|
+
d((e) => ({
|
|
148
|
+
...e,
|
|
149
|
+
loading: !0
|
|
150
|
+
}));
|
|
151
|
+
let n = await h.create(t);
|
|
152
|
+
return c.optimisticUpdates ? d((e) => ({
|
|
153
|
+
...e,
|
|
154
|
+
data: [...e.data, n],
|
|
155
|
+
total: e.total + 1,
|
|
156
|
+
loading: !1
|
|
157
|
+
})) : await v(), c.onSuccess?.("create", n), e.success("Created successfully"), n;
|
|
158
|
+
} catch (t) {
|
|
159
|
+
d((e) => ({
|
|
160
|
+
...e,
|
|
161
|
+
loading: !1
|
|
162
|
+
}));
|
|
163
|
+
let n = t instanceof Error ? t.message : "Create failed";
|
|
164
|
+
return c.onError?.("create", t), e.error(n), null;
|
|
165
|
+
}
|
|
166
|
+
}, [
|
|
167
|
+
h,
|
|
168
|
+
c,
|
|
169
|
+
v
|
|
170
|
+
]),
|
|
171
|
+
update: t(async (t, n) => {
|
|
172
|
+
if (!h.update) return e.error("Update operation not supported"), null;
|
|
173
|
+
try {
|
|
174
|
+
d((e) => ({
|
|
175
|
+
...e,
|
|
176
|
+
loading: !0
|
|
177
|
+
}));
|
|
178
|
+
let r = await h.update(t, n);
|
|
179
|
+
return c.optimisticUpdates ? d((e) => ({
|
|
180
|
+
...e,
|
|
181
|
+
data: e.data.map((e) => e[a] === t ? {
|
|
182
|
+
...e,
|
|
183
|
+
...r
|
|
184
|
+
} : e),
|
|
185
|
+
loading: !1
|
|
186
|
+
})) : await v(), c.onSuccess?.("update", r), e.success("Updated successfully"), r;
|
|
187
|
+
} catch (t) {
|
|
188
|
+
d((e) => ({
|
|
189
|
+
...e,
|
|
190
|
+
loading: !1
|
|
191
|
+
}));
|
|
192
|
+
let n = t instanceof Error ? t.message : "Update failed";
|
|
193
|
+
return c.onError?.("update", t), e.error(n), null;
|
|
194
|
+
}
|
|
195
|
+
}, [
|
|
196
|
+
h,
|
|
197
|
+
c,
|
|
198
|
+
a,
|
|
199
|
+
v
|
|
200
|
+
]),
|
|
201
|
+
delete: t(async (t) => {
|
|
202
|
+
if (!h.delete) return e.error("Delete operation not supported"), !1;
|
|
203
|
+
try {
|
|
204
|
+
return d((e) => ({
|
|
205
|
+
...e,
|
|
206
|
+
loading: !0
|
|
207
|
+
})), await h.delete(t), c.optimisticUpdates ? d((e) => ({
|
|
208
|
+
...e,
|
|
209
|
+
data: e.data.filter((e) => e[a] !== t),
|
|
210
|
+
total: e.total - 1,
|
|
211
|
+
loading: !1
|
|
212
|
+
})) : await v(), c.onSuccess?.("delete", t), e.success("Deleted successfully"), !0;
|
|
213
|
+
} catch (t) {
|
|
214
|
+
d((e) => ({
|
|
215
|
+
...e,
|
|
216
|
+
loading: !1
|
|
217
|
+
}));
|
|
218
|
+
let n = t instanceof Error ? t.message : "Delete failed";
|
|
219
|
+
return c.onError?.("delete", t), e.error(n), !1;
|
|
220
|
+
}
|
|
221
|
+
}, [
|
|
222
|
+
h,
|
|
223
|
+
c,
|
|
224
|
+
a,
|
|
225
|
+
v
|
|
226
|
+
]),
|
|
227
|
+
operations: h,
|
|
228
|
+
setPageSize: t((e) => {
|
|
229
|
+
d((t) => ({
|
|
230
|
+
...t,
|
|
231
|
+
pageSize: e,
|
|
232
|
+
current: 1
|
|
233
|
+
}));
|
|
234
|
+
}, []),
|
|
235
|
+
setCurrentPage: t((e) => {
|
|
236
|
+
d((t) => ({
|
|
237
|
+
...t,
|
|
238
|
+
current: e
|
|
239
|
+
}));
|
|
240
|
+
}, []),
|
|
241
|
+
state: u,
|
|
242
|
+
actionRef: l
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
//#endregion
|
|
246
|
+
export { a as n, c as t };
|
package/dist/useCrudTable.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`})
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./useCrudTable-CEY_riQg.cjs`);exports.useCrudTable=e.t;
|
package/dist/useCrudTable.js
CHANGED
|
@@ -1,235 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region lib/hooks/useCrudTable.ts
|
|
4
|
-
var i = (e) => {
|
|
5
|
-
let { baseUrl: t = "", endpoints: n = {}, headers: r = {}, transform: i } = e.api, a = {
|
|
6
|
-
list: "/list",
|
|
7
|
-
create: "/create",
|
|
8
|
-
update: "/update",
|
|
9
|
-
delete: "/delete",
|
|
10
|
-
...n
|
|
11
|
-
}, o = async (e, n = {}) => {
|
|
12
|
-
let i = await fetch(`${t}${e}`, {
|
|
13
|
-
headers: {
|
|
14
|
-
"Content-Type": "application/json",
|
|
15
|
-
...r
|
|
16
|
-
},
|
|
17
|
-
...n
|
|
18
|
-
});
|
|
19
|
-
if (!i.ok) throw Error(`HTTP error! status: ${i.status}`);
|
|
20
|
-
return i.json();
|
|
21
|
-
};
|
|
22
|
-
return {
|
|
23
|
-
getList: async (e) => {
|
|
24
|
-
let n = new URL(`${t}${a.list}`, window.location.origin);
|
|
25
|
-
Object.entries(e).forEach(([e, t]) => {
|
|
26
|
-
t != null && n.searchParams.append(e, String(t));
|
|
27
|
-
});
|
|
28
|
-
let r = await o(n.pathname + n.search);
|
|
29
|
-
return i?.response ? i.response(r) : r;
|
|
30
|
-
},
|
|
31
|
-
create: async (e) => {
|
|
32
|
-
let t = i?.request ? i.request(e) : e;
|
|
33
|
-
return o(a.create, {
|
|
34
|
-
method: "POST",
|
|
35
|
-
body: JSON.stringify(t)
|
|
36
|
-
});
|
|
37
|
-
},
|
|
38
|
-
update: async (e, t) => {
|
|
39
|
-
let n = i?.request ? i.request(t) : t;
|
|
40
|
-
return o(`${a.update}/${e}`, {
|
|
41
|
-
method: "PUT",
|
|
42
|
-
body: JSON.stringify(n)
|
|
43
|
-
});
|
|
44
|
-
},
|
|
45
|
-
delete: async (e) => {
|
|
46
|
-
await o(`${a.delete}/${e}`, { method: "DELETE" });
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
}, a = (e, t) => {
|
|
50
|
-
let n = [...e], r = Math.max(...n.map((e) => Number(e[t]) || 0)) + 1;
|
|
51
|
-
return {
|
|
52
|
-
getList: async (e) => {
|
|
53
|
-
let { current: t = 1, pageSize: r = 10, sortBy: i, sortOrder: a, ...o } = e, s = [...n];
|
|
54
|
-
Object.entries(o).forEach(([e, t]) => {
|
|
55
|
-
t != null && t !== "" && (s = s.filter((n) => String(n[e]).toLowerCase().includes(String(t).toLowerCase())));
|
|
56
|
-
}), i && a && s.sort((e, t) => {
|
|
57
|
-
let n = e[i], r = t[i], o = n > r ? 1 : n < r ? -1 : 0;
|
|
58
|
-
return a === "ascend" ? o : -o;
|
|
59
|
-
});
|
|
60
|
-
let c = (t - 1) * r;
|
|
61
|
-
return {
|
|
62
|
-
data: s.slice(c, c + r),
|
|
63
|
-
total: s.length,
|
|
64
|
-
success: !0
|
|
65
|
-
};
|
|
66
|
-
},
|
|
67
|
-
create: async (e) => {
|
|
68
|
-
let i = {
|
|
69
|
-
[t]: r++,
|
|
70
|
-
...e
|
|
71
|
-
};
|
|
72
|
-
return n.push(i), i;
|
|
73
|
-
},
|
|
74
|
-
update: async (e, r) => {
|
|
75
|
-
let i = n.findIndex((n) => n[t] === e);
|
|
76
|
-
if (i === -1) throw Error("Item not found");
|
|
77
|
-
return n[i] = {
|
|
78
|
-
...n[i],
|
|
79
|
-
...r
|
|
80
|
-
}, n[i];
|
|
81
|
-
},
|
|
82
|
-
delete: async (e) => {
|
|
83
|
-
let r = n.findIndex((n) => n[t] === e);
|
|
84
|
-
if (r === -1) throw Error("Item not found");
|
|
85
|
-
n.splice(r, 1);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
}, o = (o, s) => {
|
|
89
|
-
let c = n(null), [l, u] = r({
|
|
90
|
-
loading: !1,
|
|
91
|
-
error: null,
|
|
92
|
-
data: [],
|
|
93
|
-
total: 0,
|
|
94
|
-
current: 1,
|
|
95
|
-
pageSize: s.defaultPageSize || 10
|
|
96
|
-
}), d = (() => {
|
|
97
|
-
if ("operations" in s) return s.operations;
|
|
98
|
-
if ("staticData" in s) return a(s.staticData, o);
|
|
99
|
-
if ("api" in s) return i(s);
|
|
100
|
-
throw Error("useCrudTable: Must provide either staticData, api config, or custom operations");
|
|
101
|
-
})(), f = t(async () => {
|
|
102
|
-
u((e) => ({
|
|
103
|
-
...e,
|
|
104
|
-
loading: !0,
|
|
105
|
-
error: null
|
|
106
|
-
}));
|
|
107
|
-
try {
|
|
108
|
-
let e = {
|
|
109
|
-
current: l.current,
|
|
110
|
-
pageSize: l.pageSize
|
|
111
|
-
}, t = await d.getList(e);
|
|
112
|
-
u((e) => ({
|
|
113
|
-
...e,
|
|
114
|
-
data: t.data,
|
|
115
|
-
total: t.total,
|
|
116
|
-
loading: !1
|
|
117
|
-
}));
|
|
118
|
-
} catch (t) {
|
|
119
|
-
let n = t instanceof Error ? t.message : "Failed to fetch data";
|
|
120
|
-
u((e) => ({
|
|
121
|
-
...e,
|
|
122
|
-
loading: !1,
|
|
123
|
-
error: n
|
|
124
|
-
})), s.onError?.("fetch", t), e.error(n);
|
|
125
|
-
}
|
|
126
|
-
}, [
|
|
127
|
-
l.current,
|
|
128
|
-
l.pageSize,
|
|
129
|
-
d,
|
|
130
|
-
s
|
|
131
|
-
]);
|
|
132
|
-
return {
|
|
133
|
-
refresh: f,
|
|
134
|
-
create: t(async (t) => {
|
|
135
|
-
if (!d.create) return e.error("Create operation not supported"), null;
|
|
136
|
-
try {
|
|
137
|
-
u((e) => ({
|
|
138
|
-
...e,
|
|
139
|
-
loading: !0
|
|
140
|
-
}));
|
|
141
|
-
let n = await d.create(t);
|
|
142
|
-
return s.optimisticUpdates ? u((e) => ({
|
|
143
|
-
...e,
|
|
144
|
-
data: [...e.data, n],
|
|
145
|
-
total: e.total + 1,
|
|
146
|
-
loading: !1
|
|
147
|
-
})) : await f(), s.onSuccess?.("create", n), e.success("Created successfully"), n;
|
|
148
|
-
} catch (t) {
|
|
149
|
-
u((e) => ({
|
|
150
|
-
...e,
|
|
151
|
-
loading: !1
|
|
152
|
-
}));
|
|
153
|
-
let n = t instanceof Error ? t.message : "Create failed";
|
|
154
|
-
return s.onError?.("create", t), e.error(n), null;
|
|
155
|
-
}
|
|
156
|
-
}, [
|
|
157
|
-
d,
|
|
158
|
-
s,
|
|
159
|
-
f
|
|
160
|
-
]),
|
|
161
|
-
update: t(async (t, n) => {
|
|
162
|
-
if (!d.update) return e.error("Update operation not supported"), null;
|
|
163
|
-
try {
|
|
164
|
-
u((e) => ({
|
|
165
|
-
...e,
|
|
166
|
-
loading: !0
|
|
167
|
-
}));
|
|
168
|
-
let r = await d.update(t, n);
|
|
169
|
-
return s.optimisticUpdates ? u((e) => ({
|
|
170
|
-
...e,
|
|
171
|
-
data: e.data.map((e) => e[o] === t ? {
|
|
172
|
-
...e,
|
|
173
|
-
...r
|
|
174
|
-
} : e),
|
|
175
|
-
loading: !1
|
|
176
|
-
})) : await f(), s.onSuccess?.("update", r), e.success("Updated successfully"), r;
|
|
177
|
-
} catch (t) {
|
|
178
|
-
u((e) => ({
|
|
179
|
-
...e,
|
|
180
|
-
loading: !1
|
|
181
|
-
}));
|
|
182
|
-
let n = t instanceof Error ? t.message : "Update failed";
|
|
183
|
-
return s.onError?.("update", t), e.error(n), null;
|
|
184
|
-
}
|
|
185
|
-
}, [
|
|
186
|
-
d,
|
|
187
|
-
s,
|
|
188
|
-
o,
|
|
189
|
-
f
|
|
190
|
-
]),
|
|
191
|
-
delete: t(async (t) => {
|
|
192
|
-
if (!d.delete) return e.error("Delete operation not supported"), !1;
|
|
193
|
-
try {
|
|
194
|
-
return u((e) => ({
|
|
195
|
-
...e,
|
|
196
|
-
loading: !0
|
|
197
|
-
})), await d.delete(t), s.optimisticUpdates ? u((e) => ({
|
|
198
|
-
...e,
|
|
199
|
-
data: e.data.filter((e) => e[o] !== t),
|
|
200
|
-
total: e.total - 1,
|
|
201
|
-
loading: !1
|
|
202
|
-
})) : await f(), s.onSuccess?.("delete", t), e.success("Deleted successfully"), !0;
|
|
203
|
-
} catch (t) {
|
|
204
|
-
u((e) => ({
|
|
205
|
-
...e,
|
|
206
|
-
loading: !1
|
|
207
|
-
}));
|
|
208
|
-
let n = t instanceof Error ? t.message : "Delete failed";
|
|
209
|
-
return s.onError?.("delete", t), e.error(n), !1;
|
|
210
|
-
}
|
|
211
|
-
}, [
|
|
212
|
-
d,
|
|
213
|
-
s,
|
|
214
|
-
o,
|
|
215
|
-
f
|
|
216
|
-
]),
|
|
217
|
-
setPageSize: t((e) => {
|
|
218
|
-
u((t) => ({
|
|
219
|
-
...t,
|
|
220
|
-
pageSize: e,
|
|
221
|
-
current: 1
|
|
222
|
-
}));
|
|
223
|
-
}, []),
|
|
224
|
-
setCurrentPage: t((e) => {
|
|
225
|
-
u((t) => ({
|
|
226
|
-
...t,
|
|
227
|
-
current: e
|
|
228
|
-
}));
|
|
229
|
-
}, []),
|
|
230
|
-
state: l,
|
|
231
|
-
actionRef: c
|
|
232
|
-
};
|
|
233
|
-
};
|
|
234
|
-
//#endregion
|
|
235
|
-
export { o as useCrudTable };
|
|
1
|
+
import { t as e } from "./useCrudTable-DpF-oZHz.js";
|
|
2
|
+
export { e as useCrudTable };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}}),require(`./CrudTable.cjs`);
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}}),require(`./CrudTable-TTRqkEoZ.cjs`);const e=require(`./useCrudTable-CEY_riQg.cjs`);let t=require(`react`);var n=(e,t=[])=>{try{let n=localStorage.getItem(e);return n?JSON.parse(n):t}catch{return t}},r=(e,t)=>{try{localStorage.setItem(e,JSON.stringify(t))}catch(e){console.error(`Failed to save to localStorage:`,e)}},i=(t,i,a=[])=>({getList:async r=>e.n(n(t,a),r),create:async e=>{let o=n(t,a),s=o.length>0?Math.max(...o.map(e=>Number(e[i])||0),0):0,c={[i]:s+1,...e,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()};return o.push(c),r(t,o),c},update:async(e,o)=>{let s=n(t,a),c=s.findIndex(t=>t[i]===e);if(c===-1)throw Error(`Item not found`);return s[c]={...s[c],...o,updatedAt:new Date().toISOString()},r(t,s),s[c]},delete:async e=>{r(t,n(t,a).filter(t=>t[i]!==e))}}),a=(n,r,a=[],o)=>{let s=(0,t.useMemo)(()=>i(r,n,a),[r,n,a]),c=e.t(n,{...o,operations:s}),{refresh:l}=c;return(0,t.useEffect)(()=>{l()},[]),c};exports.default=a,exports.useLocalStorageCrud=a;
|