antd-crud-table 0.0.13 → 0.1.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 +0 -10
- package/dist/CrudTable-CDqv0ksy.cjs +387 -0
- package/dist/CrudTable-DbG9ZeYQ.js +73031 -0
- package/dist/CrudTable.cjs +1 -1
- package/dist/CrudTable.js +211 -234
- package/dist/CrudTableExperimental.cjs +1 -1
- package/dist/CrudTableExperimental.js +303 -372
- package/dist/CrudTableLazy.cjs +1 -1
- package/dist/CrudTableLazy.js +23 -23
- package/dist/antd-crud-table.css +2 -1
- package/dist/chunk-BZRuZbSa.cjs +1 -0
- package/dist/chunk-DrlAKpkd.js +23 -0
- package/dist/jsx-runtime-Blo4gjKb.js +475 -0
- package/dist/jsx-runtime-D8R_Hd8N.cjs +16 -0
- package/dist/message-C5ORE39N.cjs +124 -0
- package/dist/message-C9NNC2sM.js +7083 -0
- package/dist/useCrudTable.cjs +1 -1
- package/dist/useCrudTable.js +234 -194
- package/dist/utils/exportData.d.ts +37 -0
- package/package.json +13 -15
- package/dist/CrudTable-W5dD5mDc.js +0 -74793
- package/dist/CrudTable-ck226KHr.cjs +0 -407
- package/dist/index-DNXRWKhU.js +0 -6314
- package/dist/index-DygfPlBI.cjs +0 -145
- package/dist/jsx-runtime-Drh4NO5G.js +0 -633
- package/dist/jsx-runtime-qcKc-DpB.cjs +0 -30
package/dist/CrudTable.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const e=require(`./chunk-BZRuZbSa.cjs`),t=require(`./CrudTable-CDqv0ksy.cjs`),n=require(`./message-C5ORE39N.cjs`),r=require(`./jsx-runtime-D8R_Hd8N.cjs`);let i=require(`react`);var a=e.i(t.h(),1),o=r.t(),s=e=>{let r=(0,i.useRef)(null),{columns:s,service:c,rowKey:l,title:u,defaultPageSize:d=5}=e,[f,p]=(0,i.useState)(!1),[m,h]=(0,i.useState)(null),[g]=t.d.useForm(),_=(s||[]).map(e=>{let n={...e,dataIndex:e.dataIndex,title:e.title};switch(e.fieldType){case`date`:return{...n,valueType:`dateTime`,render:(n,r)=>(0,o.jsx)(`span`,{children:t.r(t.t(r[e.dataIndex]),`yyyy-MM-dd HH:mm`)})};case`enum`:return{...n,valueType:`select`,valueEnum:e.enumOptions};case`number`:return{...n,valueType:`digit`};case`boolean`:return{...n,valueType:`switch`,render:(n,r)=>(0,o.jsx)(t.s,{color:r[e.dataIndex]?`green`:`red`,children:r[e.dataIndex]?`Yes`:`No`})};case`custom`:return{...n,render:(t,n)=>e.customRender?.(n[e.dataIndex],n)};default:return n}});_.push({title:`Actions`,valueType:`option`,render:(e,n)=>[(0,o.jsx)(t.g,{type:`primary`,onClick:()=>y(n),children:`Edit`},`edit`),(0,o.jsx)(t.g,{type:`primary`,danger:!0,onClick:async()=>{await c.delete(n[l]),r.current?.reload()},children:`Delete`},`delete`)]});let v=async(e,t,r)=>{try{let n={...e,sortBy:Object.keys(t)[0],sortOrder:Object.values(t)[0],...r},{data:i,total:a}=await c.getList(n);return{data:i,success:!0,total:a}}catch{return n.t.error(`Failed to fetch data`),{data:[],success:!1,total:0}}},y=e=>{if(h(e||null),e){let t={...e};s.forEach(e=>{let n=e.dataIndex;e.fieldType===`date`&&t[n]&&(t[n]=(0,a.default)(t[n]))}),g.setFieldsValue(t)}else g.resetFields();p(!0)};return(0,o.jsxs)(t.a,{needDeps:!0,intl:t.o,children:[(0,o.jsx)(t.i,{headerTitle:u,rowKey:l,rowClassName:(e,t)=>t%2==0&&`row-differentiator`||``,actionRef:r,columns:_,request:v,search:{labelWidth:`auto`},pagination:{pageSize:d},toolBarRender:()=>[(0,o.jsx)(t.g,{type:`primary`,icon:(0,o.jsx)(t.v,{}),onClick:()=>y(),children:`New`},`add`),(0,o.jsx)(t.f,{menu:{items:[{key:`export`,label:`Export`},{key:`refresh`,label:`Refresh`,onClick:()=>r.current?.reload()}]},children:(0,o.jsx)(t.g,{children:(0,o.jsx)(t.y,{})})},`menu`)],options:{setting:{listsHeight:400},reload:()=>r.current?.reload()},dateFormatter:`string`}),(0,o.jsx)(t.l,{forceRender:!0,title:m?`Edit Item`:`Create Item`,open:f,onOk:async()=>{try{let e=await g.validateFields(),i={...e};s.forEach(n=>{let r=n.dataIndex;n.fieldType===`date`&&e[r]&&(i[r]=t.n(e[r])),n.formConfig?.transform&&(i[r]=n.formConfig.transform(e[r]))}),m&&m[l]?(await c.update(m[l],i),n.t.success(`Updated successfully`)):(await c.create(i),n.t.success(`Created successfully`)),p(!1),r.current?.reload()}catch(e){console.error(e),n.t.error(`Submit failed`)}},onCancel:()=>{p(!1)},destroyOnClose:!0,children:(0,o.jsx)(t.d,{form:g,layout:`vertical`,children:s.map(e=>{if(!e.dataIndex)return null;let n=e.dataIndex,r=e.title,i=!(e.fieldEditable??!0);switch(e.fieldType){case`string`:return(0,o.jsx)(t.d.Item,{name:n,label:r,rules:[{required:e.formConfig?.required,message:`${r} is required`}],children:(0,o.jsx)(t.u,{disabled:i})},n);case`number`:return(0,o.jsx)(t.d.Item,{name:n,label:r,rules:[{required:e.formConfig?.required,message:`${r} is required`}],children:(0,o.jsx)(t.m,{style:{width:`100%`},disabled:i})},n);case`date`:return(0,o.jsx)(t.d.Item,{name:n,label:r,rules:[{required:e.formConfig?.required,message:`${r} is required`}],children:(0,o.jsx)(t.p,{style:{width:`100%`},showTime:!0,disabled:i})},n);case`boolean`:return(0,o.jsx)(t.d.Item,{name:n,label:r,valuePropName:`checked`,children:(0,o.jsx)(t.c,{disabled:i})},n);case`enum`:return(0,o.jsx)(t.d.Item,{name:n,label:r,rules:[{required:e.formConfig?.required,message:`${r} is required`}],children:(0,o.jsx)(t._,{disabled:i,options:Object.entries(e.enumOptions||{}).map(([e,t])=>({label:t.text,value:e}))})},n);default:return null}})})})]})};module.exports=s;
|
package/dist/CrudTable.js
CHANGED
|
@@ -1,235 +1,212 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
label: r,
|
|
211
|
-
rules: [{ required: (g = e.formConfig) == null ? void 0 : g.required, message: `${r} is required` }],
|
|
212
|
-
children: /* @__PURE__ */ a.jsx(
|
|
213
|
-
A,
|
|
214
|
-
{
|
|
215
|
-
disabled: s,
|
|
216
|
-
options: Object.entries(e.enumOptions || {}).map(([S, E]) => ({
|
|
217
|
-
label: E.text,
|
|
218
|
-
value: S
|
|
219
|
-
}))
|
|
220
|
-
}
|
|
221
|
-
)
|
|
222
|
-
},
|
|
223
|
-
t
|
|
224
|
-
);
|
|
225
|
-
default:
|
|
226
|
-
return null;
|
|
227
|
-
}
|
|
228
|
-
}) })
|
|
229
|
-
}
|
|
230
|
-
)
|
|
231
|
-
] });
|
|
232
|
-
};
|
|
233
|
-
export {
|
|
234
|
-
Z as default
|
|
1
|
+
import { a as e } from "./chunk-DrlAKpkd.js";
|
|
2
|
+
import { _ as t, a as n, c as r, d as i, f as a, g as o, h as s, i as c, l, m as u, n as d, o as f, p, r as m, s as h, t as g, u as _, v, y } from "./CrudTable-DbG9ZeYQ.js";
|
|
3
|
+
import { t as b } from "./message-C9NNC2sM.js";
|
|
4
|
+
import { t as x } from "./jsx-runtime-Blo4gjKb.js";
|
|
5
|
+
import { useRef as S, useState as C } from "react";
|
|
6
|
+
//#region lib/CrudTable.tsx
|
|
7
|
+
var w = /* @__PURE__ */ e(s(), 1), T = x(), E = (e) => {
|
|
8
|
+
let s = S(null), { columns: x, service: E, rowKey: D, title: O, defaultPageSize: k = 5 } = e, [A, j] = C(!1), [M, N] = C(null), [P] = i.useForm(), F = (x || []).map((e) => {
|
|
9
|
+
let t = {
|
|
10
|
+
...e,
|
|
11
|
+
dataIndex: e.dataIndex,
|
|
12
|
+
title: e.title
|
|
13
|
+
};
|
|
14
|
+
switch (e.fieldType) {
|
|
15
|
+
case "date": return {
|
|
16
|
+
...t,
|
|
17
|
+
valueType: "dateTime",
|
|
18
|
+
render: (t, n) => /* @__PURE__ */ (0, T.jsx)("span", { children: m(g(n[e.dataIndex]), "yyyy-MM-dd HH:mm") })
|
|
19
|
+
};
|
|
20
|
+
case "enum": return {
|
|
21
|
+
...t,
|
|
22
|
+
valueType: "select",
|
|
23
|
+
valueEnum: e.enumOptions
|
|
24
|
+
};
|
|
25
|
+
case "number": return {
|
|
26
|
+
...t,
|
|
27
|
+
valueType: "digit"
|
|
28
|
+
};
|
|
29
|
+
case "boolean": return {
|
|
30
|
+
...t,
|
|
31
|
+
valueType: "switch",
|
|
32
|
+
render: (t, n) => /* @__PURE__ */ (0, T.jsx)(h, {
|
|
33
|
+
color: n[e.dataIndex] ? "green" : "red",
|
|
34
|
+
children: n[e.dataIndex] ? "Yes" : "No"
|
|
35
|
+
})
|
|
36
|
+
};
|
|
37
|
+
case "custom": return {
|
|
38
|
+
...t,
|
|
39
|
+
render: (t, n) => e.customRender?.(n[e.dataIndex], n)
|
|
40
|
+
};
|
|
41
|
+
default: return t;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
F.push({
|
|
45
|
+
title: "Actions",
|
|
46
|
+
valueType: "option",
|
|
47
|
+
render: (e, t) => [/* @__PURE__ */ (0, T.jsx)(o, {
|
|
48
|
+
type: "primary",
|
|
49
|
+
onClick: () => L(t),
|
|
50
|
+
children: "Edit"
|
|
51
|
+
}, "edit"), /* @__PURE__ */ (0, T.jsx)(o, {
|
|
52
|
+
type: "primary",
|
|
53
|
+
danger: !0,
|
|
54
|
+
onClick: async () => {
|
|
55
|
+
await E.delete(t[D]), s.current?.reload();
|
|
56
|
+
},
|
|
57
|
+
children: "Delete"
|
|
58
|
+
}, "delete")]
|
|
59
|
+
});
|
|
60
|
+
let I = async (e, t, n) => {
|
|
61
|
+
try {
|
|
62
|
+
let r = {
|
|
63
|
+
...e,
|
|
64
|
+
sortBy: Object.keys(t)[0],
|
|
65
|
+
sortOrder: Object.values(t)[0],
|
|
66
|
+
...n
|
|
67
|
+
}, { data: i, total: a } = await E.getList(r);
|
|
68
|
+
return {
|
|
69
|
+
data: i,
|
|
70
|
+
success: !0,
|
|
71
|
+
total: a
|
|
72
|
+
};
|
|
73
|
+
} catch {
|
|
74
|
+
return b.error("Failed to fetch data"), {
|
|
75
|
+
data: [],
|
|
76
|
+
success: !1,
|
|
77
|
+
total: 0
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}, L = (e) => {
|
|
81
|
+
if (N(e || null), e) {
|
|
82
|
+
let t = { ...e };
|
|
83
|
+
x.forEach((e) => {
|
|
84
|
+
let n = e.dataIndex;
|
|
85
|
+
e.fieldType === "date" && t[n] && (t[n] = (0, w.default)(t[n]));
|
|
86
|
+
}), P.setFieldsValue(t);
|
|
87
|
+
} else P.resetFields();
|
|
88
|
+
j(!0);
|
|
89
|
+
};
|
|
90
|
+
return /* @__PURE__ */ (0, T.jsxs)(n, {
|
|
91
|
+
needDeps: !0,
|
|
92
|
+
intl: f,
|
|
93
|
+
children: [/* @__PURE__ */ (0, T.jsx)(c, {
|
|
94
|
+
headerTitle: O,
|
|
95
|
+
rowKey: D,
|
|
96
|
+
rowClassName: (e, t) => t % 2 == 0 && "row-differentiator" || "",
|
|
97
|
+
actionRef: s,
|
|
98
|
+
columns: F,
|
|
99
|
+
request: I,
|
|
100
|
+
search: { labelWidth: "auto" },
|
|
101
|
+
pagination: { pageSize: k },
|
|
102
|
+
toolBarRender: () => [/* @__PURE__ */ (0, T.jsx)(o, {
|
|
103
|
+
type: "primary",
|
|
104
|
+
icon: /* @__PURE__ */ (0, T.jsx)(v, {}),
|
|
105
|
+
onClick: () => L(),
|
|
106
|
+
children: "New"
|
|
107
|
+
}, "add"), /* @__PURE__ */ (0, T.jsx)(a, {
|
|
108
|
+
menu: { items: [{
|
|
109
|
+
key: "export",
|
|
110
|
+
label: "Export"
|
|
111
|
+
}, {
|
|
112
|
+
key: "refresh",
|
|
113
|
+
label: "Refresh",
|
|
114
|
+
onClick: () => s.current?.reload()
|
|
115
|
+
}] },
|
|
116
|
+
children: /* @__PURE__ */ (0, T.jsx)(o, { children: /* @__PURE__ */ (0, T.jsx)(y, {}) })
|
|
117
|
+
}, "menu")],
|
|
118
|
+
options: {
|
|
119
|
+
setting: { listsHeight: 400 },
|
|
120
|
+
reload: () => s.current?.reload()
|
|
121
|
+
},
|
|
122
|
+
dateFormatter: "string"
|
|
123
|
+
}), /* @__PURE__ */ (0, T.jsx)(l, {
|
|
124
|
+
forceRender: !0,
|
|
125
|
+
title: M ? "Edit Item" : "Create Item",
|
|
126
|
+
open: A,
|
|
127
|
+
onOk: async () => {
|
|
128
|
+
try {
|
|
129
|
+
let e = await P.validateFields(), t = { ...e };
|
|
130
|
+
x.forEach((n) => {
|
|
131
|
+
let r = n.dataIndex;
|
|
132
|
+
n.fieldType === "date" && e[r] && (t[r] = d(e[r])), n.formConfig?.transform && (t[r] = n.formConfig.transform(e[r]));
|
|
133
|
+
}), M && M[D] ? (await E.update(M[D], t), b.success("Updated successfully")) : (await E.create(t), b.success("Created successfully")), j(!1), s.current?.reload();
|
|
134
|
+
} catch (e) {
|
|
135
|
+
console.error(e), b.error("Submit failed");
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
onCancel: () => {
|
|
139
|
+
j(!1);
|
|
140
|
+
},
|
|
141
|
+
destroyOnClose: !0,
|
|
142
|
+
children: /* @__PURE__ */ (0, T.jsx)(i, {
|
|
143
|
+
form: P,
|
|
144
|
+
layout: "vertical",
|
|
145
|
+
children: x.map((e) => {
|
|
146
|
+
if (!e.dataIndex) return null;
|
|
147
|
+
let n = e.dataIndex, a = e.title, o = !(e.fieldEditable ?? !0);
|
|
148
|
+
switch (e.fieldType) {
|
|
149
|
+
case "string": return /* @__PURE__ */ (0, T.jsx)(i.Item, {
|
|
150
|
+
name: n,
|
|
151
|
+
label: a,
|
|
152
|
+
rules: [{
|
|
153
|
+
required: e.formConfig?.required,
|
|
154
|
+
message: `${a} is required`
|
|
155
|
+
}],
|
|
156
|
+
children: /* @__PURE__ */ (0, T.jsx)(_, { disabled: o })
|
|
157
|
+
}, n);
|
|
158
|
+
case "number": return /* @__PURE__ */ (0, T.jsx)(i.Item, {
|
|
159
|
+
name: n,
|
|
160
|
+
label: a,
|
|
161
|
+
rules: [{
|
|
162
|
+
required: e.formConfig?.required,
|
|
163
|
+
message: `${a} is required`
|
|
164
|
+
}],
|
|
165
|
+
children: /* @__PURE__ */ (0, T.jsx)(u, {
|
|
166
|
+
style: { width: "100%" },
|
|
167
|
+
disabled: o
|
|
168
|
+
})
|
|
169
|
+
}, n);
|
|
170
|
+
case "date": return /* @__PURE__ */ (0, T.jsx)(i.Item, {
|
|
171
|
+
name: n,
|
|
172
|
+
label: a,
|
|
173
|
+
rules: [{
|
|
174
|
+
required: e.formConfig?.required,
|
|
175
|
+
message: `${a} is required`
|
|
176
|
+
}],
|
|
177
|
+
children: /* @__PURE__ */ (0, T.jsx)(p, {
|
|
178
|
+
style: { width: "100%" },
|
|
179
|
+
showTime: !0,
|
|
180
|
+
disabled: o
|
|
181
|
+
})
|
|
182
|
+
}, n);
|
|
183
|
+
case "boolean": return /* @__PURE__ */ (0, T.jsx)(i.Item, {
|
|
184
|
+
name: n,
|
|
185
|
+
label: a,
|
|
186
|
+
valuePropName: "checked",
|
|
187
|
+
children: /* @__PURE__ */ (0, T.jsx)(r, { disabled: o })
|
|
188
|
+
}, n);
|
|
189
|
+
case "enum": return /* @__PURE__ */ (0, T.jsx)(i.Item, {
|
|
190
|
+
name: n,
|
|
191
|
+
label: a,
|
|
192
|
+
rules: [{
|
|
193
|
+
required: e.formConfig?.required,
|
|
194
|
+
message: `${a} is required`
|
|
195
|
+
}],
|
|
196
|
+
children: /* @__PURE__ */ (0, T.jsx)(t, {
|
|
197
|
+
disabled: o,
|
|
198
|
+
options: Object.entries(e.enumOptions || {}).map(([e, t]) => ({
|
|
199
|
+
label: t.text,
|
|
200
|
+
value: e
|
|
201
|
+
}))
|
|
202
|
+
})
|
|
203
|
+
}, n);
|
|
204
|
+
default: return null;
|
|
205
|
+
}
|
|
206
|
+
})
|
|
207
|
+
})
|
|
208
|
+
})]
|
|
209
|
+
});
|
|
235
210
|
};
|
|
211
|
+
//#endregion
|
|
212
|
+
export { E as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const e=require(`./chunk-BZRuZbSa.cjs`),t=require(`./CrudTable-CDqv0ksy.cjs`),n=require(`./message-C5ORE39N.cjs`),r=require(`./jsx-runtime-D8R_Hd8N.cjs`),i=require(`./useCrudTable.cjs`);let a=require(`react`);var o=e.i(t.h(),1),s=r.t(),c=e=>{let{columns:r,rowKey:c,title:l,defaultPageSize:u=10,hookConfig:d,enableBulkOperations:f=!1,customActions:p}=e,m=i.useCrudTable(c,{defaultPageSize:u,...d}),[h,g]=(0,a.useState)(!1),[_,v]=(0,a.useState)(null),[y,b]=(0,a.useState)([]),[x]=t.d.useForm();(0,a.useEffect)(()=>{m.refresh()},[]);let S=r.map(e=>{let n={...e,dataIndex:e.dataIndex,title:e.title,search:e.searchable!==!1};switch(e.fieldType){case`date`:return{...n,valueType:`dateTime`,render:(n,r)=>{let i=r[e.dataIndex];if(!i)return`-`;try{return(0,s.jsx)(`span`,{children:t.r(t.t(i),`yyyy-MM-dd HH:mm`)})}catch{return(0,s.jsx)(`span`,{children:i})}}};case`enum`:return{...n,valueType:`select`,valueEnum:e.enumOptions,render:(n,r)=>{let i=r[e.dataIndex],a=e.enumOptions?.[i];return a?(0,s.jsx)(t.s,{color:a.color,children:a.text}):i}};case`number`:return{...n,valueType:`digit`,render:(t,n)=>{let r=n[e.dataIndex];return typeof r==`number`?r.toLocaleString():r}};case`boolean`:return{...n,valueType:`switch`,render:(n,r)=>(0,s.jsx)(t.s,{color:r[e.dataIndex]?`green`:`red`,children:r[e.dataIndex]?`Yes`:`No`})};case`custom`:return{...n,render:(t,n)=>e.customRender?.(n[e.dataIndex],n)};default:return n}});S.push({title:`Actions`,valueType:`option`,width:200,render:(e,n)=>{let r=[(0,s.jsx)(t.g,{type:`link`,size:`small`,onClick:()=>w(n),children:`Edit`},`edit`),(0,s.jsx)(t.g,{type:`link`,size:`small`,danger:!0,onClick:()=>E(n[c]),children:`Delete`},`delete`)],i=p?.(n,m)||[];return[...r,...i]}});let C=async(e,t,r)=>{try{let n={current:e.current,pageSize:e.pageSize,sortBy:Object.keys(t)[0],sortOrder:Object.values(t)[0],...r,...e},i=m.operations;if(i?.getList){let e=await i.getList(n);return{data:e.data,success:!0,total:e.total}}return{data:m.state.data,success:!0,total:m.state.total}}catch{return n.t.error(`Failed to fetch data`),{data:[],success:!1,total:0}}},w=e=>{if(v(e||null),e){let t={...e};r.forEach(e=>{let n=e.dataIndex;if(e.fieldType===`date`&&t[n])try{t[n]=(0,o.default)(t[n])}catch{}}),x.setFieldsValue(t)}else x.resetFields();g(!0)},T=async()=>{try{let e=await x.validateFields(),n={...e};r.forEach(r=>{let i=r.dataIndex;if(r.fieldType===`date`&&e[i])try{n[i]=t.n(e[i])}catch{}r.formConfig?.transform&&(n[i]=r.formConfig.transform(e[i]))}),_&&_[c]?await m.update(_[c],n):await m.create(n),g(!1),m.actionRef.current?.reload()}catch(e){console.error(`Form validation failed:`,e)}},E=async e=>{t.l.confirm({title:`Are you sure?`,content:`This action cannot be undone.`,okText:`Yes, Delete`,okType:`danger`,cancelText:`Cancel`,onOk:async()=>{await m.delete(e)&&m.actionRef.current?.reload()}})},D=async()=>{if(y.length===0){n.t.warning(`Please select items to delete`);return}t.l.confirm({title:`Delete ${y.length} items?`,content:`This action cannot be undone.`,okText:`Yes, Delete All`,okType:`danger`,cancelText:`Cancel`,onOk:async()=>{let e=y.map(e=>m.delete(e));await Promise.allSettled(e),b([]),m.actionRef.current?.reload()}})},O=f?{selectedRowKeys:y,onChange:b}:void 0;return(0,s.jsxs)(t.a,{needDeps:!0,intl:t.o,children:[(0,s.jsx)(t.i,{headerTitle:l,rowKey:c,rowClassName:(e,t)=>t%2==0?`row-differentiator`:``,actionRef:m.actionRef,columns:S,request:C,search:{labelWidth:`auto`},pagination:{pageSize:u,showSizeChanger:!0,showQuickJumper:!0},loading:m.state.loading,rowSelection:O,toolBarRender:()=>[(0,s.jsx)(t.g,{type:`primary`,icon:(0,s.jsx)(t.v,{}),onClick:()=>w(),children:`New`},`add`),...f&&y.length>0?[(0,s.jsxs)(t.g,{danger:!0,onClick:D,children:[`Delete Selected (`,y.length,`)`]},`bulk-delete`)]:[],(0,s.jsx)(t.f,{menu:{items:[{key:`export`,label:`Export`,disabled:!0},{key:`refresh`,label:`Refresh`,onClick:()=>m.refresh()}]},children:(0,s.jsx)(t.g,{children:(0,s.jsx)(t.y,{})})},`menu`)],options:{setting:{listsHeight:400},reload:()=>m.refresh()},dateFormatter:`string`}),(0,s.jsx)(t.l,{title:_?`Edit Item`:`Create Item`,open:h,onOk:T,onCancel:()=>g(!1),destroyOnClose:!0,width:600,children:(0,s.jsx)(t.d,{form:x,layout:`vertical`,children:r.map(e=>{if(!e.dataIndex)return null;let n=e.dataIndex,r=e.title,i=!(e.fieldEditable??!0),a=e.formConfig?.rules||(e.formConfig?.required?[{required:!0,message:`${r} is required`}]:[]);if(e.formConfig?.component)return(0,s.jsx)(t.d.Item,{name:n,label:r,rules:a,children:e.formConfig.component},n);switch(e.fieldType){case`string`:return(0,s.jsx)(t.d.Item,{name:n,label:r,rules:a,children:(0,s.jsx)(t.u,{disabled:i})},n);case`number`:return(0,s.jsx)(t.d.Item,{name:n,label:r,rules:a,children:(0,s.jsx)(t.m,{style:{width:`100%`},disabled:i})},n);case`date`:return(0,s.jsx)(t.d.Item,{name:n,label:r,rules:a,children:(0,s.jsx)(t.p,{style:{width:`100%`},showTime:!0,disabled:i})},n);case`boolean`:return(0,s.jsx)(t.d.Item,{name:n,label:r,valuePropName:`checked`,children:(0,s.jsx)(t.c,{disabled:i})},n);case`enum`:return(0,s.jsx)(t.d.Item,{name:n,label:r,rules:a,children:(0,s.jsx)(t._,{disabled:i,placeholder:`Select ${r.toLowerCase()}`,options:Object.entries(e.enumOptions||{}).map(([e,t])=>({label:t.text,value:e}))})},n);default:return null}})})})]})};module.exports=c;
|