antd-crud-table 0.3.1 → 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.
@@ -0,0 +1,524 @@
1
+ import { t as e } from "./useCrudTable-DpF-oZHz.js";
2
+ import t from "./exportData.js";
3
+ import { EllipsisOutlined as n, PlusOutlined as r } from "@ant-design/icons";
4
+ import { ProConfigProvider as i, ProTable as a, enUSIntl as o } from "@ant-design/pro-components";
5
+ import { Button as s, ColorPicker as c, DatePicker as l, Dropdown as u, Form as d, Image as f, Input as p, InputNumber as m, Modal as h, Progress as g, Rate as _, Select as v, Switch as y, Tag as b, TimePicker as x, Typography as S, message as C } from "antd";
6
+ import { useRef as w, useState as T } from "react";
7
+ import E from "dayjs";
8
+ import { Fragment as D, jsx as O, jsxs as k } from "react/jsx-runtime";
9
+ //#region lib/fields/registry.tsx
10
+ var A = (e, t) => t[e.dataIndex], j = "YYYY-MM-DD HH:mm", M = "YYYY-MM-DD", N = "HH:mm:ss", P = {
11
+ string: { formControl: (e, t) => /* @__PURE__ */ O(p, { disabled: t }) },
12
+ number: {
13
+ column: (e) => ({
14
+ valueType: "digit",
15
+ render: (t, n) => {
16
+ let r = A(e, n);
17
+ return typeof r == "number" ? r.toLocaleString() : r;
18
+ }
19
+ }),
20
+ formControl: (e, t) => /* @__PURE__ */ O(m, {
21
+ style: { width: "100%" },
22
+ disabled: t
23
+ })
24
+ },
25
+ date: {
26
+ column: (e) => ({
27
+ valueType: "dateTime",
28
+ render: (t, n) => {
29
+ let r = A(e, n);
30
+ if (!r) return "-";
31
+ let i = E(r);
32
+ return /* @__PURE__ */ O("span", { children: i.isValid() ? i.format(j) : String(r) });
33
+ }
34
+ }),
35
+ formControl: (e, t) => /* @__PURE__ */ O(l, {
36
+ style: { width: "100%" },
37
+ showTime: !0,
38
+ disabled: t
39
+ }),
40
+ toFormValue: (e) => e && E(e),
41
+ fromFormValue: (e) => E.isDayjs(e) ? e.toISOString() : e
42
+ },
43
+ boolean: {
44
+ column: (e) => ({
45
+ valueType: "switch",
46
+ render: (t, n) => /* @__PURE__ */ O(b, {
47
+ color: A(e, n) ? "green" : "red",
48
+ children: A(e, n) ? "Yes" : "No"
49
+ })
50
+ }),
51
+ formControl: (e, t) => /* @__PURE__ */ O(y, { disabled: t }),
52
+ valuePropName: "checked"
53
+ },
54
+ enum: {
55
+ column: (e) => ({
56
+ valueType: "select",
57
+ valueEnum: e.enumOptions,
58
+ render: (t, n) => {
59
+ let r = A(e, n), i = e.enumOptions?.[r];
60
+ return i ? /* @__PURE__ */ O(b, {
61
+ color: i.color,
62
+ children: i.text
63
+ }) : r;
64
+ }
65
+ }),
66
+ formControl: (e, t) => /* @__PURE__ */ O(v, {
67
+ disabled: t,
68
+ placeholder: `Select ${String(e.title ?? "").toLowerCase()}`,
69
+ options: Object.entries(e.enumOptions || {}).map(([e, t]) => ({
70
+ label: t.text,
71
+ value: e
72
+ }))
73
+ })
74
+ },
75
+ custom: {
76
+ column: (e) => ({ render: (t, n) => e.customRender?.(A(e, n), n) }),
77
+ formControl: () => null
78
+ },
79
+ textarea: {
80
+ column: () => ({
81
+ valueType: "textarea",
82
+ ellipsis: !0
83
+ }),
84
+ formControl: (e, t) => /* @__PURE__ */ O(p.TextArea, {
85
+ rows: 3,
86
+ disabled: t
87
+ })
88
+ },
89
+ email: {
90
+ column: (e) => ({ render: (t, n) => {
91
+ let r = A(e, n);
92
+ return r ? /* @__PURE__ */ O("a", {
93
+ href: `mailto:${r}`,
94
+ children: r
95
+ }) : "-";
96
+ } }),
97
+ formControl: (e, t) => /* @__PURE__ */ O(p, {
98
+ type: "email",
99
+ disabled: t
100
+ }),
101
+ rules: () => [{
102
+ type: "email",
103
+ message: "Please enter a valid email"
104
+ }]
105
+ },
106
+ url: {
107
+ column: (e) => ({ render: (t, n) => {
108
+ let r = A(e, n);
109
+ return r ? /* @__PURE__ */ O("a", {
110
+ href: r,
111
+ target: "_blank",
112
+ rel: "noopener noreferrer",
113
+ children: r
114
+ }) : "-";
115
+ } }),
116
+ formControl: (e, t) => /* @__PURE__ */ O(p, { disabled: t }),
117
+ rules: () => [{
118
+ type: "url",
119
+ message: "Please enter a valid URL"
120
+ }]
121
+ },
122
+ password: {
123
+ column: (e) => ({
124
+ search: !1,
125
+ render: (t, n) => A(e, n) ? "••••••••" : "-"
126
+ }),
127
+ formControl: (e, t) => /* @__PURE__ */ O(p.Password, { disabled: t })
128
+ },
129
+ money: {
130
+ column: () => ({ valueType: "money" }),
131
+ formControl: (e, t) => /* @__PURE__ */ O(m, {
132
+ style: { width: "100%" },
133
+ precision: 2,
134
+ min: 0,
135
+ disabled: t
136
+ })
137
+ },
138
+ percent: {
139
+ column: () => ({ valueType: "percent" }),
140
+ formControl: (e, t) => /* @__PURE__ */ O(m, {
141
+ style: { width: "100%" },
142
+ min: 0,
143
+ max: 100,
144
+ addonAfter: "%",
145
+ disabled: t
146
+ })
147
+ },
148
+ rating: {
149
+ column: (e) => ({
150
+ search: !1,
151
+ render: (t, n) => /* @__PURE__ */ O(_, {
152
+ disabled: !0,
153
+ allowHalf: !0,
154
+ value: Number(A(e, n)) || 0
155
+ })
156
+ }),
157
+ formControl: (e, t) => /* @__PURE__ */ O(_, {
158
+ allowHalf: !0,
159
+ disabled: t
160
+ })
161
+ },
162
+ progress: {
163
+ column: (e) => ({
164
+ search: !1,
165
+ render: (t, n) => /* @__PURE__ */ O(g, {
166
+ percent: Number(A(e, n)) || 0,
167
+ size: "small"
168
+ })
169
+ }),
170
+ formControl: (e, t) => /* @__PURE__ */ O(m, {
171
+ style: { width: "100%" },
172
+ min: 0,
173
+ max: 100,
174
+ disabled: t
175
+ })
176
+ },
177
+ time: {
178
+ column: () => ({ valueType: "time" }),
179
+ formControl: (e, t) => /* @__PURE__ */ O(x, {
180
+ style: { width: "100%" },
181
+ disabled: t
182
+ }),
183
+ toFormValue: (e) => e && E(e, N),
184
+ fromFormValue: (e) => E.isDayjs(e) ? e.format(N) : e
185
+ },
186
+ dateRange: {
187
+ column: (e) => ({
188
+ valueType: "dateRange",
189
+ render: (t, n) => {
190
+ let r = A(e, n);
191
+ if (!Array.isArray(r) || r.length !== 2) return "-";
192
+ let [i, a] = r.map((e) => E(e));
193
+ return !i.isValid() || !a.isValid() ? String(r) : `${i.format(M)} ~ ${a.format(M)}`;
194
+ }
195
+ }),
196
+ formControl: (e, t) => /* @__PURE__ */ O(l.RangePicker, {
197
+ style: { width: "100%" },
198
+ disabled: t
199
+ }),
200
+ toFormValue: (e) => Array.isArray(e) ? e.map((e) => e && E(e)) : e,
201
+ fromFormValue: (e) => Array.isArray(e) ? e.map((e) => E.isDayjs(e) ? e.toISOString() : e) : e
202
+ },
203
+ tags: {
204
+ column: (e) => ({ render: (t, n) => {
205
+ let r = A(e, n);
206
+ return !Array.isArray(r) || r.length === 0 ? "-" : /* @__PURE__ */ O(D, { children: r.map((e) => /* @__PURE__ */ O(b, { children: e }, e)) });
207
+ } }),
208
+ formControl: (e, t) => /* @__PURE__ */ O(v, {
209
+ mode: "tags",
210
+ open: !1,
211
+ suffixIcon: null,
212
+ disabled: t,
213
+ placeholder: "Type and press enter"
214
+ })
215
+ },
216
+ image: {
217
+ column: (e) => ({
218
+ search: !1,
219
+ render: (t, n) => {
220
+ let r = A(e, n);
221
+ return r ? /* @__PURE__ */ O(f, {
222
+ src: r,
223
+ width: 48,
224
+ height: 48,
225
+ style: { objectFit: "cover" }
226
+ }) : "-";
227
+ }
228
+ }),
229
+ formControl: (e, t) => /* @__PURE__ */ O(p, {
230
+ placeholder: "https://...",
231
+ disabled: t
232
+ }),
233
+ rules: () => [{
234
+ type: "url",
235
+ message: "Please enter a valid image URL"
236
+ }]
237
+ },
238
+ color: {
239
+ column: (e) => ({
240
+ search: !1,
241
+ render: (t, n) => {
242
+ let r = A(e, n);
243
+ return r ? /* @__PURE__ */ k("span", {
244
+ style: {
245
+ display: "inline-flex",
246
+ alignItems: "center",
247
+ gap: 8
248
+ },
249
+ children: [/* @__PURE__ */ O("span", { style: {
250
+ display: "inline-block",
251
+ width: 14,
252
+ height: 14,
253
+ borderRadius: 3,
254
+ border: "1px solid rgba(0,0,0,0.15)",
255
+ backgroundColor: r
256
+ } }), r]
257
+ }) : "-";
258
+ }
259
+ }),
260
+ formControl: (e, t) => /* @__PURE__ */ O(c, {
261
+ showText: !0,
262
+ disabled: t
263
+ }),
264
+ fromFormValue: (e) => e && typeof e == "object" && "toHexString" in e ? e.toHexString() : e
265
+ },
266
+ json: {
267
+ column: (e) => ({
268
+ search: !1,
269
+ ellipsis: !0,
270
+ render: (t, n) => {
271
+ let r = A(e, n);
272
+ return r == null ? "-" : /* @__PURE__ */ O(S.Text, {
273
+ code: !0,
274
+ children: JSON.stringify(r)
275
+ });
276
+ }
277
+ }),
278
+ formControl: (e, t) => /* @__PURE__ */ O(p.TextArea, {
279
+ rows: 4,
280
+ style: { fontFamily: "monospace" },
281
+ disabled: t
282
+ }),
283
+ toFormValue: (e) => typeof e == "string" ? e : JSON.stringify(e, null, 2),
284
+ fromFormValue: (e) => typeof e == "string" && e.trim() !== "" ? JSON.parse(e) : e,
285
+ rules: () => [{ validator: async (e, t) => {
286
+ if (!(t == null || t === "") && typeof t == "string") try {
287
+ JSON.parse(t);
288
+ } catch {
289
+ throw Error("Please enter valid JSON");
290
+ }
291
+ } }]
292
+ }
293
+ }, F = (e) => P[e ?? "string"] ?? P.string, I = (c) => {
294
+ let { columns: l, rowKey: f, title: p, defaultPageSize: m = 10, hookConfig: g, enableBulkOperations: _ = !1, enableExport: v = !0, customActions: y } = c, b = e(f, {
295
+ defaultPageSize: m,
296
+ ...g
297
+ }), [x, S] = T(!1), [E, D] = T(null), [A, j] = T([]), [M] = d.useForm(), N = w([]), P = l.map((e) => {
298
+ let t = {
299
+ ...e,
300
+ dataIndex: e.dataIndex,
301
+ title: e.title,
302
+ search: e.searchable !== !1
303
+ }, n = F(e.fieldType);
304
+ return {
305
+ ...t,
306
+ ...n.column?.(e)
307
+ };
308
+ });
309
+ P.push({
310
+ title: "Actions",
311
+ valueType: "option",
312
+ width: 200,
313
+ render: (e, t) => {
314
+ let n = [/* @__PURE__ */ O(s, {
315
+ type: "link",
316
+ size: "small",
317
+ onClick: () => L(t),
318
+ children: "Edit"
319
+ }, "edit"), /* @__PURE__ */ O(s, {
320
+ type: "link",
321
+ size: "small",
322
+ danger: !0,
323
+ onClick: () => z(t[f]),
324
+ children: "Delete"
325
+ }, "delete")], r = y?.(t, b) || [];
326
+ return [...n, ...r];
327
+ }
328
+ });
329
+ let I = async (e, t, n) => {
330
+ try {
331
+ let r = {
332
+ current: e.current,
333
+ pageSize: e.pageSize,
334
+ sortBy: Object.keys(t)[0],
335
+ sortOrder: Object.values(t)[0] ?? void 0,
336
+ ...n,
337
+ ...e
338
+ }, { operations: i } = b;
339
+ if (i.getList) {
340
+ let e = await i.getList(r);
341
+ return N.current = e.data ?? [], {
342
+ data: e.data,
343
+ success: !0,
344
+ total: e.total
345
+ };
346
+ }
347
+ return N.current = b.state.data, {
348
+ data: b.state.data,
349
+ success: !0,
350
+ total: b.state.total
351
+ };
352
+ } catch {
353
+ return C.error("Failed to fetch data"), {
354
+ data: [],
355
+ success: !1,
356
+ total: 0
357
+ };
358
+ }
359
+ }, L = (e) => {
360
+ if (D(e || null), e) {
361
+ let t = { ...e };
362
+ l.forEach((e) => {
363
+ let n = e.dataIndex, r = F(e.fieldType).toFormValue;
364
+ if (r && t[n] !== void 0) try {
365
+ t[n] = r(t[n]);
366
+ } catch {}
367
+ }), M.setFieldsValue(t);
368
+ } else M.resetFields();
369
+ S(!0);
370
+ }, R = async () => {
371
+ try {
372
+ let e = await M.validateFields(), t = { ...e };
373
+ l.forEach((n) => {
374
+ let r = n.dataIndex, i = F(n.fieldType).fromFormValue;
375
+ if (i && e[r] !== void 0) try {
376
+ t[r] = i(e[r]);
377
+ } catch {}
378
+ n.formConfig?.transform && (t[r] = n.formConfig.transform(t[r]));
379
+ }), E && E[f] ? await b.update(E[f], t) : await b.create(t), S(!1), b.actionRef.current?.reload();
380
+ } catch (e) {
381
+ console.error("Form validation failed:", e);
382
+ }
383
+ }, z = async (e) => {
384
+ h.confirm({
385
+ title: "Are you sure?",
386
+ content: "This action cannot be undone.",
387
+ okText: "Yes, Delete",
388
+ okType: "danger",
389
+ cancelText: "Cancel",
390
+ onOk: async () => {
391
+ await b.delete(e) && b.actionRef.current?.reload();
392
+ }
393
+ });
394
+ }, B = async () => {
395
+ if (A.length === 0) {
396
+ C.warning("Please select items to delete");
397
+ return;
398
+ }
399
+ h.confirm({
400
+ title: `Delete ${A.length} items?`,
401
+ content: "This action cannot be undone.",
402
+ okText: "Yes, Delete All",
403
+ okType: "danger",
404
+ cancelText: "Cancel",
405
+ onOk: async () => {
406
+ let e = A.map((e) => b.delete(e));
407
+ await Promise.allSettled(e), j([]), b.actionRef.current?.reload();
408
+ }
409
+ });
410
+ }, V = (e) => {
411
+ let n = N.current;
412
+ if (n.length === 0) {
413
+ C.warning("Nothing to export");
414
+ return;
415
+ }
416
+ t({
417
+ data: n,
418
+ columns: l.filter((e) => e.dataIndex && e.fieldType !== "password").map((e) => ({
419
+ title: typeof e.title == "string" ? e.title : String(e.dataIndex),
420
+ dataIndex: String(e.dataIndex),
421
+ fieldType: e.fieldType,
422
+ enumOptions: e.enumOptions
423
+ })),
424
+ filename: p ? p.toLowerCase().replace(/\s+/g, "-") : "export",
425
+ format: e
426
+ });
427
+ }, H = _ ? {
428
+ selectedRowKeys: A,
429
+ onChange: j
430
+ } : void 0;
431
+ return /* @__PURE__ */ k(i, {
432
+ needDeps: !0,
433
+ intl: o,
434
+ children: [/* @__PURE__ */ O(a, {
435
+ headerTitle: p,
436
+ rowKey: f,
437
+ rowClassName: (e, t) => t % 2 == 0 ? "row-differentiator" : "",
438
+ actionRef: b.actionRef,
439
+ columns: P,
440
+ request: I,
441
+ search: { labelWidth: "auto" },
442
+ pagination: {
443
+ pageSize: m,
444
+ showSizeChanger: !0,
445
+ showQuickJumper: !0
446
+ },
447
+ rowSelection: H,
448
+ toolBarRender: () => [
449
+ /* @__PURE__ */ O(s, {
450
+ type: "primary",
451
+ icon: /* @__PURE__ */ O(r, {}),
452
+ onClick: () => L(),
453
+ children: "New"
454
+ }, "add"),
455
+ ..._ && A.length > 0 ? [/* @__PURE__ */ k(s, {
456
+ danger: !0,
457
+ onClick: B,
458
+ children: [
459
+ "Delete Selected (",
460
+ A.length,
461
+ ")"
462
+ ]
463
+ }, "bulk-delete")] : [],
464
+ /* @__PURE__ */ O(u, {
465
+ menu: { items: [...v ? [
466
+ {
467
+ key: "export-csv",
468
+ label: "Export CSV",
469
+ onClick: () => V("csv")
470
+ },
471
+ {
472
+ key: "export-json",
473
+ label: "Export JSON",
474
+ onClick: () => V("json")
475
+ },
476
+ {
477
+ key: "export-excel",
478
+ label: "Export Excel",
479
+ onClick: () => V("xlsx")
480
+ },
481
+ { type: "divider" }
482
+ ] : [], {
483
+ key: "refresh",
484
+ label: "Refresh",
485
+ onClick: () => b.actionRef.current?.reload()
486
+ }] },
487
+ children: /* @__PURE__ */ O(s, { children: /* @__PURE__ */ O(n, {}) })
488
+ }, "menu")
489
+ ],
490
+ options: {
491
+ setting: { listsHeight: 400 },
492
+ reload: !0
493
+ },
494
+ dateFormatter: "string"
495
+ }), /* @__PURE__ */ O(h, {
496
+ title: E ? "Edit Item" : "Create Item",
497
+ open: x,
498
+ onOk: R,
499
+ onCancel: () => S(!1),
500
+ destroyOnClose: !0,
501
+ width: 600,
502
+ children: /* @__PURE__ */ O(d, {
503
+ form: M,
504
+ layout: "vertical",
505
+ children: l.map((e) => {
506
+ if (!e.dataIndex) return null;
507
+ let t = e.dataIndex, n = e.title, r = !(e.fieldEditable ?? !0), i = F(e.fieldType), a = e.formConfig?.rules || (e.formConfig?.required ? [{
508
+ required: !0,
509
+ message: `${n} is required`
510
+ }] : []), o = [...i.rules?.(e) ?? [], ...a], s = e.formConfig?.component ?? i.formControl(e, r);
511
+ return s ? /* @__PURE__ */ O(d.Item, {
512
+ name: t,
513
+ label: n,
514
+ rules: o,
515
+ valuePropName: i.valuePropName,
516
+ children: s
517
+ }, t) : null;
518
+ })
519
+ })
520
+ })]
521
+ });
522
+ };
523
+ //#endregion
524
+ export { P as n, F as r, I as t };
@@ -0,0 +1 @@
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=require(`./useCrudTable-CEY_riQg.cjs`),l=require(`./exportData.cjs`);let u=require(`@ant-design/icons`),d=require(`@ant-design/pro-components`),f=require(`antd`),p=require(`react`),m=require(`dayjs`);m=s(m,1);let h=require(`react/jsx-runtime`);var g=(e,t)=>t[e.dataIndex],_=`YYYY-MM-DD HH:mm`,v=`YYYY-MM-DD`,y=`HH:mm:ss`,b={string:{formControl:(e,t)=>(0,h.jsx)(f.Input,{disabled:t})},number:{column:e=>({valueType:`digit`,render:(t,n)=>{let r=g(e,n);return typeof r==`number`?r.toLocaleString():r}}),formControl:(e,t)=>(0,h.jsx)(f.InputNumber,{style:{width:`100%`},disabled:t})},date:{column:e=>({valueType:`dateTime`,render:(t,n)=>{let r=g(e,n);if(!r)return`-`;let i=(0,m.default)(r);return(0,h.jsx)(`span`,{children:i.isValid()?i.format(_):String(r)})}}),formControl:(e,t)=>(0,h.jsx)(f.DatePicker,{style:{width:`100%`},showTime:!0,disabled:t}),toFormValue:e=>e&&(0,m.default)(e),fromFormValue:e=>m.default.isDayjs(e)?e.toISOString():e},boolean:{column:e=>({valueType:`switch`,render:(t,n)=>(0,h.jsx)(f.Tag,{color:g(e,n)?`green`:`red`,children:g(e,n)?`Yes`:`No`})}),formControl:(e,t)=>(0,h.jsx)(f.Switch,{disabled:t}),valuePropName:`checked`},enum:{column:e=>({valueType:`select`,valueEnum:e.enumOptions,render:(t,n)=>{let r=g(e,n),i=e.enumOptions?.[r];return i?(0,h.jsx)(f.Tag,{color:i.color,children:i.text}):r}}),formControl:(e,t)=>(0,h.jsx)(f.Select,{disabled:t,placeholder:`Select ${String(e.title??``).toLowerCase()}`,options:Object.entries(e.enumOptions||{}).map(([e,t])=>({label:t.text,value:e}))})},custom:{column:e=>({render:(t,n)=>e.customRender?.(g(e,n),n)}),formControl:()=>null},textarea:{column:()=>({valueType:`textarea`,ellipsis:!0}),formControl:(e,t)=>(0,h.jsx)(f.Input.TextArea,{rows:3,disabled:t})},email:{column:e=>({render:(t,n)=>{let r=g(e,n);return r?(0,h.jsx)(`a`,{href:`mailto:${r}`,children:r}):`-`}}),formControl:(e,t)=>(0,h.jsx)(f.Input,{type:`email`,disabled:t}),rules:()=>[{type:`email`,message:`Please enter a valid email`}]},url:{column:e=>({render:(t,n)=>{let r=g(e,n);return r?(0,h.jsx)(`a`,{href:r,target:`_blank`,rel:`noopener noreferrer`,children:r}):`-`}}),formControl:(e,t)=>(0,h.jsx)(f.Input,{disabled:t}),rules:()=>[{type:`url`,message:`Please enter a valid URL`}]},password:{column:e=>({search:!1,render:(t,n)=>g(e,n)?`••••••••`:`-`}),formControl:(e,t)=>(0,h.jsx)(f.Input.Password,{disabled:t})},money:{column:()=>({valueType:`money`}),formControl:(e,t)=>(0,h.jsx)(f.InputNumber,{style:{width:`100%`},precision:2,min:0,disabled:t})},percent:{column:()=>({valueType:`percent`}),formControl:(e,t)=>(0,h.jsx)(f.InputNumber,{style:{width:`100%`},min:0,max:100,addonAfter:`%`,disabled:t})},rating:{column:e=>({search:!1,render:(t,n)=>(0,h.jsx)(f.Rate,{disabled:!0,allowHalf:!0,value:Number(g(e,n))||0})}),formControl:(e,t)=>(0,h.jsx)(f.Rate,{allowHalf:!0,disabled:t})},progress:{column:e=>({search:!1,render:(t,n)=>(0,h.jsx)(f.Progress,{percent:Number(g(e,n))||0,size:`small`})}),formControl:(e,t)=>(0,h.jsx)(f.InputNumber,{style:{width:`100%`},min:0,max:100,disabled:t})},time:{column:()=>({valueType:`time`}),formControl:(e,t)=>(0,h.jsx)(f.TimePicker,{style:{width:`100%`},disabled:t}),toFormValue:e=>e&&(0,m.default)(e,y),fromFormValue:e=>m.default.isDayjs(e)?e.format(y):e},dateRange:{column:e=>({valueType:`dateRange`,render:(t,n)=>{let r=g(e,n);if(!Array.isArray(r)||r.length!==2)return`-`;let[i,a]=r.map(e=>(0,m.default)(e));return!i.isValid()||!a.isValid()?String(r):`${i.format(v)} ~ ${a.format(v)}`}}),formControl:(e,t)=>(0,h.jsx)(f.DatePicker.RangePicker,{style:{width:`100%`},disabled:t}),toFormValue:e=>Array.isArray(e)?e.map(e=>e&&(0,m.default)(e)):e,fromFormValue:e=>Array.isArray(e)?e.map(e=>m.default.isDayjs(e)?e.toISOString():e):e},tags:{column:e=>({render:(t,n)=>{let r=g(e,n);return!Array.isArray(r)||r.length===0?`-`:(0,h.jsx)(h.Fragment,{children:r.map(e=>(0,h.jsx)(f.Tag,{children:e},e))})}}),formControl:(e,t)=>(0,h.jsx)(f.Select,{mode:`tags`,open:!1,suffixIcon:null,disabled:t,placeholder:`Type and press enter`})},image:{column:e=>({search:!1,render:(t,n)=>{let r=g(e,n);return r?(0,h.jsx)(f.Image,{src:r,width:48,height:48,style:{objectFit:`cover`}}):`-`}}),formControl:(e,t)=>(0,h.jsx)(f.Input,{placeholder:`https://...`,disabled:t}),rules:()=>[{type:`url`,message:`Please enter a valid image URL`}]},color:{column:e=>({search:!1,render:(t,n)=>{let r=g(e,n);return r?(0,h.jsxs)(`span`,{style:{display:`inline-flex`,alignItems:`center`,gap:8},children:[(0,h.jsx)(`span`,{style:{display:`inline-block`,width:14,height:14,borderRadius:3,border:`1px solid rgba(0,0,0,0.15)`,backgroundColor:r}}),r]}):`-`}}),formControl:(e,t)=>(0,h.jsx)(f.ColorPicker,{showText:!0,disabled:t}),fromFormValue:e=>e&&typeof e==`object`&&`toHexString`in e?e.toHexString():e},json:{column:e=>({search:!1,ellipsis:!0,render:(t,n)=>{let r=g(e,n);return r==null?`-`:(0,h.jsx)(f.Typography.Text,{code:!0,children:JSON.stringify(r)})}}),formControl:(e,t)=>(0,h.jsx)(f.Input.TextArea,{rows:4,style:{fontFamily:`monospace`},disabled:t}),toFormValue:e=>typeof e==`string`?e:JSON.stringify(e,null,2),fromFormValue:e=>typeof e==`string`&&e.trim()!==``?JSON.parse(e):e,rules:()=>[{validator:async(e,t)=>{if(!(t==null||t===``)&&typeof t==`string`)try{JSON.parse(t)}catch{throw Error(`Please enter valid JSON`)}}}]}},x=e=>b[e??`string`]??b.string,S=e=>{let{columns:t,rowKey:n,title:r,defaultPageSize:i=10,hookConfig:a,enableBulkOperations:o=!1,enableExport:s=!0,customActions:m}=e,g=c.t(n,{defaultPageSize:i,...a}),[_,v]=(0,p.useState)(!1),[y,b]=(0,p.useState)(null),[S,C]=(0,p.useState)([]),[w]=f.Form.useForm(),T=(0,p.useRef)([]),E=t.map(e=>{let t={...e,dataIndex:e.dataIndex,title:e.title,search:e.searchable!==!1},n=x(e.fieldType);return{...t,...n.column?.(e)}});E.push({title:`Actions`,valueType:`option`,width:200,render:(e,t)=>{let r=[(0,h.jsx)(f.Button,{type:`link`,size:`small`,onClick:()=>O(t),children:`Edit`},`edit`),(0,h.jsx)(f.Button,{type:`link`,size:`small`,danger:!0,onClick:()=>A(t[n]),children:`Delete`},`delete`)],i=m?.(t,g)||[];return[...r,...i]}});let D=async(e,t,n)=>{try{let r={current:e.current,pageSize:e.pageSize,sortBy:Object.keys(t)[0],sortOrder:Object.values(t)[0]??void 0,...n,...e},{operations:i}=g;if(i.getList){let e=await i.getList(r);return T.current=e.data??[],{data:e.data,success:!0,total:e.total}}return T.current=g.state.data,{data:g.state.data,success:!0,total:g.state.total}}catch{return f.message.error(`Failed to fetch data`),{data:[],success:!1,total:0}}},O=e=>{if(b(e||null),e){let n={...e};t.forEach(e=>{let t=e.dataIndex,r=x(e.fieldType).toFormValue;if(r&&n[t]!==void 0)try{n[t]=r(n[t])}catch{}}),w.setFieldsValue(n)}else w.resetFields();v(!0)},k=async()=>{try{let e=await w.validateFields(),r={...e};t.forEach(t=>{let n=t.dataIndex,i=x(t.fieldType).fromFormValue;if(i&&e[n]!==void 0)try{r[n]=i(e[n])}catch{}t.formConfig?.transform&&(r[n]=t.formConfig.transform(r[n]))}),y&&y[n]?await g.update(y[n],r):await g.create(r),v(!1),g.actionRef.current?.reload()}catch(e){console.error(`Form validation failed:`,e)}},A=async e=>{f.Modal.confirm({title:`Are you sure?`,content:`This action cannot be undone.`,okText:`Yes, Delete`,okType:`danger`,cancelText:`Cancel`,onOk:async()=>{await g.delete(e)&&g.actionRef.current?.reload()}})},j=async()=>{if(S.length===0){f.message.warning(`Please select items to delete`);return}f.Modal.confirm({title:`Delete ${S.length} items?`,content:`This action cannot be undone.`,okText:`Yes, Delete All`,okType:`danger`,cancelText:`Cancel`,onOk:async()=>{let e=S.map(e=>g.delete(e));await Promise.allSettled(e),C([]),g.actionRef.current?.reload()}})},M=e=>{let n=T.current;if(n.length===0){f.message.warning(`Nothing to export`);return}l.default({data:n,columns:t.filter(e=>e.dataIndex&&e.fieldType!==`password`).map(e=>({title:typeof e.title==`string`?e.title:String(e.dataIndex),dataIndex:String(e.dataIndex),fieldType:e.fieldType,enumOptions:e.enumOptions})),filename:r?r.toLowerCase().replace(/\s+/g,`-`):`export`,format:e})},N=o?{selectedRowKeys:S,onChange:C}:void 0;return(0,h.jsxs)(d.ProConfigProvider,{needDeps:!0,intl:d.enUSIntl,children:[(0,h.jsx)(d.ProTable,{headerTitle:r,rowKey:n,rowClassName:(e,t)=>t%2==0?`row-differentiator`:``,actionRef:g.actionRef,columns:E,request:D,search:{labelWidth:`auto`},pagination:{pageSize:i,showSizeChanger:!0,showQuickJumper:!0},rowSelection:N,toolBarRender:()=>[(0,h.jsx)(f.Button,{type:`primary`,icon:(0,h.jsx)(u.PlusOutlined,{}),onClick:()=>O(),children:`New`},`add`),...o&&S.length>0?[(0,h.jsxs)(f.Button,{danger:!0,onClick:j,children:[`Delete Selected (`,S.length,`)`]},`bulk-delete`)]:[],(0,h.jsx)(f.Dropdown,{menu:{items:[...s?[{key:`export-csv`,label:`Export CSV`,onClick:()=>M(`csv`)},{key:`export-json`,label:`Export JSON`,onClick:()=>M(`json`)},{key:`export-excel`,label:`Export Excel`,onClick:()=>M(`xlsx`)},{type:`divider`}]:[],{key:`refresh`,label:`Refresh`,onClick:()=>g.actionRef.current?.reload()}]},children:(0,h.jsx)(f.Button,{children:(0,h.jsx)(u.EllipsisOutlined,{})})},`menu`)],options:{setting:{listsHeight:400},reload:!0},dateFormatter:`string`}),(0,h.jsx)(f.Modal,{title:y?`Edit Item`:`Create Item`,open:_,onOk:k,onCancel:()=>v(!1),destroyOnClose:!0,width:600,children:(0,h.jsx)(f.Form,{form:w,layout:`vertical`,children:t.map(e=>{if(!e.dataIndex)return null;let t=e.dataIndex,n=e.title,r=!(e.fieldEditable??!0),i=x(e.fieldType),a=e.formConfig?.rules||(e.formConfig?.required?[{required:!0,message:`${n} is required`}]:[]),o=[...i.rules?.(e)??[],...a],s=e.formConfig?.component??i.formControl(e,r);return s?(0,h.jsx)(f.Form.Item,{name:t,label:n,rules:o,valuePropName:i.valuePropName,children:s},t):null})})})]})};Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return S}});