antd-crud-table 0.2.0 → 0.4.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/dist/CrudTable.cjs +1 -1
- package/dist/CrudTable.d.ts +7 -11
- package/dist/CrudTable.js +226 -132
- package/dist/CrudTableLazy.cjs +1 -1
- package/dist/CrudTableLazy.d.ts +1 -0
- package/dist/CrudTableLazy.js +13 -22
- package/dist/exportData.cjs +13 -0
- package/dist/exportData.js +64 -0
- package/dist/index.d.ts +0 -3
- package/dist/useCrudTable.cjs +1 -1
- package/dist/useCrudTable.js +1 -1
- package/dist/useLocalStorageCrud.cjs +1 -0
- package/dist/useLocalStorageCrud.js +201 -0
- package/package.json +13 -1
- package/dist/CrudTable-CDqv0ksy.cjs +0 -387
- package/dist/CrudTable-DbG9ZeYQ.js +0 -73031
- package/dist/CrudTableExperimental.cjs +0 -1
- package/dist/CrudTableExperimental.d.ts +0 -34
- package/dist/CrudTableExperimental.js +0 -304
- package/dist/CrudTableExperimentalLazy.d.ts +0 -4
- package/dist/chunk-BZRuZbSa.cjs +0 -1
- package/dist/chunk-DrlAKpkd.js +0 -23
- package/dist/jsx-runtime-Blo4gjKb.js +0 -475
- package/dist/jsx-runtime-D8R_Hd8N.cjs +0 -16
- package/dist/message-C5ORE39N.cjs +0 -124
- package/dist/message-C9NNC2sM.js +0 -7083
package/dist/CrudTable.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});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.cjs`);let l=require(`@ant-design/icons`),u=require(`@ant-design/pro-components`),d=require(`antd`),f=require(`react`),p=require(`date-fns`),m=require(`dayjs`);m=s(m,1);let h=require(`react/jsx-runtime`);var g=e=>{let{columns:t,rowKey:n,title:r,defaultPageSize:i=10,hookConfig:a,enableBulkOperations:o=!1,customActions:s}=e,g=c.useCrudTable(n,{defaultPageSize:i,...a}),[_,v]=(0,f.useState)(!1),[y,b]=(0,f.useState)(null),[x,S]=(0,f.useState)([]),[C]=d.Form.useForm();(0,f.useEffect)(()=>{g.refresh()},[]);let w=t.map(e=>{let t={...e,dataIndex:e.dataIndex,title:e.title,search:e.searchable!==!1};switch(e.fieldType){case`date`:return{...t,valueType:`dateTime`,render:(t,n)=>{let r=n[e.dataIndex];if(!r)return`-`;try{return(0,h.jsx)(`span`,{children:(0,p.format)((0,p.parseISO)(r),`yyyy-MM-dd HH:mm`)})}catch{return(0,h.jsx)(`span`,{children:r})}}};case`enum`:return{...t,valueType:`select`,valueEnum:e.enumOptions,render:(t,n)=>{let r=n[e.dataIndex],i=e.enumOptions?.[r];return i?(0,h.jsx)(d.Tag,{color:i.color,children:i.text}):r}};case`number`:return{...t,valueType:`digit`,render:(t,n)=>{let r=n[e.dataIndex];return typeof r==`number`?r.toLocaleString():r}};case`boolean`:return{...t,valueType:`switch`,render:(t,n)=>(0,h.jsx)(d.Tag,{color:n[e.dataIndex]?`green`:`red`,children:n[e.dataIndex]?`Yes`:`No`})};case`custom`:return{...t,render:(t,n)=>e.customRender?.(n[e.dataIndex],n)};default:return t}});w.push({title:`Actions`,valueType:`option`,width:200,render:(e,t)=>{let r=[(0,h.jsx)(d.Button,{type:`link`,size:`small`,onClick:()=>E(t),children:`Edit`},`edit`),(0,h.jsx)(d.Button,{type:`link`,size:`small`,danger:!0,onClick:()=>O(t[n]),children:`Delete`},`delete`)],i=s?.(t,g)||[];return[...r,...i]}});let T=async(e,t,n)=>{try{let r={current:e.current,pageSize:e.pageSize,sortBy:Object.keys(t)[0],sortOrder:Object.values(t)[0],...n,...e},i=g.operations;if(i?.getList){let e=await i.getList(r);return{data:e.data,success:!0,total:e.total}}return{data:g.state.data,success:!0,total:g.state.total}}catch{return d.message.error(`Failed to fetch data`),{data:[],success:!1,total:0}}},E=e=>{if(b(e||null),e){let n={...e};t.forEach(e=>{let t=e.dataIndex;if(e.fieldType===`date`&&n[t])try{n[t]=(0,m.default)(n[t])}catch{}}),C.setFieldsValue(n)}else C.resetFields();v(!0)},D=async()=>{try{let e=await C.validateFields(),r={...e};t.forEach(t=>{let n=t.dataIndex;if(t.fieldType===`date`&&e[n])try{r[n]=(0,p.formatISO)(e[n])}catch{}t.formConfig?.transform&&(r[n]=t.formConfig.transform(e[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)}},O=async e=>{d.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()}})},k=async()=>{if(x.length===0){d.message.warning(`Please select items to delete`);return}d.Modal.confirm({title:`Delete ${x.length} items?`,content:`This action cannot be undone.`,okText:`Yes, Delete All`,okType:`danger`,cancelText:`Cancel`,onOk:async()=>{let e=x.map(e=>g.delete(e));await Promise.allSettled(e),S([]),g.actionRef.current?.reload()}})},A=o?{selectedRowKeys:x,onChange:S}:void 0;return(0,h.jsxs)(u.ProConfigProvider,{needDeps:!0,intl:u.enUSIntl,children:[(0,h.jsx)(u.ProTable,{headerTitle:r,rowKey:n,rowClassName:(e,t)=>t%2==0?`row-differentiator`:``,actionRef:g.actionRef,columns:w,request:T,search:{labelWidth:`auto`},pagination:{pageSize:i,showSizeChanger:!0,showQuickJumper:!0},loading:g.state.loading,rowSelection:A,toolBarRender:()=>[(0,h.jsx)(d.Button,{type:`primary`,icon:(0,h.jsx)(l.PlusOutlined,{}),onClick:()=>E(),children:`New`},`add`),...o&&x.length>0?[(0,h.jsxs)(d.Button,{danger:!0,onClick:k,children:[`Delete Selected (`,x.length,`)`]},`bulk-delete`)]:[],(0,h.jsx)(d.Dropdown,{menu:{items:[{key:`export`,label:`Export`,disabled:!0},{key:`refresh`,label:`Refresh`,onClick:()=>g.refresh()}]},children:(0,h.jsx)(d.Button,{children:(0,h.jsx)(l.EllipsisOutlined,{})})},`menu`)],options:{setting:{listsHeight:400},reload:()=>g.refresh()},dateFormatter:`string`}),(0,h.jsx)(d.Modal,{title:y?`Edit Item`:`Create Item`,open:_,onOk:D,onCancel:()=>v(!1),destroyOnClose:!0,width:600,children:(0,h.jsx)(d.Form,{form:C,layout:`vertical`,children:t.map(e=>{if(!e.dataIndex)return null;let t=e.dataIndex,n=e.title,r=!(e.fieldEditable??!0),i=e.formConfig?.rules||(e.formConfig?.required?[{required:!0,message:`${n} is required`}]:[]);if(e.formConfig?.component)return(0,h.jsx)(d.Form.Item,{name:t,label:n,rules:i,children:e.formConfig.component},t);switch(e.fieldType){case`string`:return(0,h.jsx)(d.Form.Item,{name:t,label:n,rules:i,children:(0,h.jsx)(d.Input,{disabled:r})},t);case`number`:return(0,h.jsx)(d.Form.Item,{name:t,label:n,rules:i,children:(0,h.jsx)(d.InputNumber,{style:{width:`100%`},disabled:r})},t);case`date`:return(0,h.jsx)(d.Form.Item,{name:t,label:n,rules:i,children:(0,h.jsx)(d.DatePicker,{style:{width:`100%`},showTime:!0,disabled:r})},t);case`boolean`:return(0,h.jsx)(d.Form.Item,{name:t,label:n,valuePropName:`checked`,children:(0,h.jsx)(d.Switch,{disabled:r})},t);case`enum`:return(0,h.jsx)(d.Form.Item,{name:t,label:n,rules:i,children:(0,h.jsx)(d.Select,{disabled:r,placeholder:`Select ${n.toLowerCase()}`,options:Object.entries(e.enumOptions||{}).map(([e,t])=>({label:t.text,value:e}))})},t);default:return null}})})})]})};exports.default=g,exports.t=s;
|
package/dist/CrudTable.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ProColumns } from '@ant-design/pro-components';
|
|
2
|
-
import {
|
|
2
|
+
import { UseCrudTableConfig, CrudTableActions } from './hooks/useCrudTable';
|
|
3
3
|
type DataType = Record<string, any>;
|
|
4
4
|
type FieldType = 'string' | 'number' | 'date' | 'boolean' | 'enum' | 'custom';
|
|
5
5
|
interface CrudColumn<T extends DataType> extends ProColumns<T> {
|
|
@@ -13,25 +13,21 @@ interface CrudColumn<T extends DataType> extends ProColumns<T> {
|
|
|
13
13
|
required?: boolean;
|
|
14
14
|
component?: React.ReactNode;
|
|
15
15
|
transform?: (value: any) => any;
|
|
16
|
-
rules?:
|
|
16
|
+
rules?: any[];
|
|
17
17
|
};
|
|
18
18
|
fieldEditable?: boolean;
|
|
19
19
|
searchable?: boolean;
|
|
20
20
|
}
|
|
21
21
|
interface CrudTableConfig<T extends DataType> {
|
|
22
22
|
columns: CrudColumn<T>[];
|
|
23
|
-
service: {
|
|
24
|
-
getList: (params: any) => Promise<{
|
|
25
|
-
data: T[];
|
|
26
|
-
total: number;
|
|
27
|
-
}>;
|
|
28
|
-
create: (data: Partial<T>) => Promise<T>;
|
|
29
|
-
update: (id: any, data: Partial<T>) => Promise<T>;
|
|
30
|
-
delete: (id: any) => Promise<void>;
|
|
31
|
-
};
|
|
32
23
|
rowKey: keyof T;
|
|
33
24
|
title: string;
|
|
34
25
|
defaultPageSize?: number;
|
|
26
|
+
hookConfig: UseCrudTableConfig<T>;
|
|
27
|
+
enableBulkOperations?: boolean;
|
|
28
|
+
enableColumnSettings?: boolean;
|
|
29
|
+
enableExport?: boolean;
|
|
30
|
+
customActions?: (record: T, actions: CrudTableActions<T>) => React.ReactNode[];
|
|
35
31
|
}
|
|
36
32
|
declare const CrudTable: <T extends DataType>(config: CrudTableConfig<T>) => import("react/jsx-runtime").JSX.Element;
|
|
37
33
|
export default CrudTable;
|
package/dist/CrudTable.js
CHANGED
|
@@ -1,35 +1,65 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { useCrudTable as e } from "./useCrudTable.js";
|
|
2
|
+
import { EllipsisOutlined as t, PlusOutlined as n } from "@ant-design/icons";
|
|
3
|
+
import { ProConfigProvider as r, ProTable as i, enUSIntl as a } from "@ant-design/pro-components";
|
|
4
|
+
import { Button as o, DatePicker as s, Dropdown as c, Form as l, Input as u, InputNumber as d, Modal as f, Select as p, Switch as m, Tag as h, message as g } from "antd";
|
|
5
|
+
import { useEffect as _, useState as v } from "react";
|
|
6
|
+
import { format as y, formatISO as b, parseISO as x } from "date-fns";
|
|
7
|
+
import S from "dayjs";
|
|
8
|
+
import { jsx as C, jsxs as w } from "react/jsx-runtime";
|
|
6
9
|
//#region lib/CrudTable.tsx
|
|
7
|
-
var
|
|
8
|
-
let
|
|
10
|
+
var T = (T) => {
|
|
11
|
+
let { columns: E, rowKey: D, title: O, defaultPageSize: k = 10, hookConfig: A, enableBulkOperations: j = !1, customActions: M } = T, N = e(D, {
|
|
12
|
+
defaultPageSize: k,
|
|
13
|
+
...A
|
|
14
|
+
}), [P, F] = v(!1), [I, L] = v(null), [R, z] = v([]), [B] = l.useForm();
|
|
15
|
+
_(() => {
|
|
16
|
+
N.refresh();
|
|
17
|
+
}, []);
|
|
18
|
+
let V = E.map((e) => {
|
|
9
19
|
let t = {
|
|
10
20
|
...e,
|
|
11
21
|
dataIndex: e.dataIndex,
|
|
12
|
-
title: e.title
|
|
22
|
+
title: e.title,
|
|
23
|
+
search: e.searchable !== !1
|
|
13
24
|
};
|
|
14
25
|
switch (e.fieldType) {
|
|
15
26
|
case "date": return {
|
|
16
27
|
...t,
|
|
17
28
|
valueType: "dateTime",
|
|
18
|
-
render: (t, n) =>
|
|
29
|
+
render: (t, n) => {
|
|
30
|
+
let r = n[e.dataIndex];
|
|
31
|
+
if (!r) return "-";
|
|
32
|
+
try {
|
|
33
|
+
return /* @__PURE__ */ C("span", { children: y(x(r), "yyyy-MM-dd HH:mm") });
|
|
34
|
+
} catch {
|
|
35
|
+
return /* @__PURE__ */ C("span", { children: r });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
19
38
|
};
|
|
20
39
|
case "enum": return {
|
|
21
40
|
...t,
|
|
22
41
|
valueType: "select",
|
|
23
|
-
valueEnum: e.enumOptions
|
|
42
|
+
valueEnum: e.enumOptions,
|
|
43
|
+
render: (t, n) => {
|
|
44
|
+
let r = n[e.dataIndex], i = e.enumOptions?.[r];
|
|
45
|
+
return i ? /* @__PURE__ */ C(h, {
|
|
46
|
+
color: i.color,
|
|
47
|
+
children: i.text
|
|
48
|
+
}) : r;
|
|
49
|
+
}
|
|
24
50
|
};
|
|
25
51
|
case "number": return {
|
|
26
52
|
...t,
|
|
27
|
-
valueType: "digit"
|
|
53
|
+
valueType: "digit",
|
|
54
|
+
render: (t, n) => {
|
|
55
|
+
let r = n[e.dataIndex];
|
|
56
|
+
return typeof r == "number" ? r.toLocaleString() : r;
|
|
57
|
+
}
|
|
28
58
|
};
|
|
29
59
|
case "boolean": return {
|
|
30
60
|
...t,
|
|
31
61
|
valueType: "switch",
|
|
32
|
-
render: (t, n) => /* @__PURE__ */ (
|
|
62
|
+
render: (t, n) => /* @__PURE__ */ C(h, {
|
|
33
63
|
color: n[e.dataIndex] ? "green" : "red",
|
|
34
64
|
children: n[e.dataIndex] ? "Yes" : "No"
|
|
35
65
|
})
|
|
@@ -41,166 +71,230 @@ var w = /* @__PURE__ */ e(s(), 1), T = x(), E = (e) => {
|
|
|
41
71
|
default: return t;
|
|
42
72
|
}
|
|
43
73
|
});
|
|
44
|
-
|
|
74
|
+
V.push({
|
|
45
75
|
title: "Actions",
|
|
46
76
|
valueType: "option",
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
77
|
+
width: 200,
|
|
78
|
+
render: (e, t) => {
|
|
79
|
+
let n = [/* @__PURE__ */ C(o, {
|
|
80
|
+
type: "link",
|
|
81
|
+
size: "small",
|
|
82
|
+
onClick: () => U(t),
|
|
83
|
+
children: "Edit"
|
|
84
|
+
}, "edit"), /* @__PURE__ */ C(o, {
|
|
85
|
+
type: "link",
|
|
86
|
+
size: "small",
|
|
87
|
+
danger: !0,
|
|
88
|
+
onClick: () => G(t[D]),
|
|
89
|
+
children: "Delete"
|
|
90
|
+
}, "delete")], r = M?.(t, N) || [];
|
|
91
|
+
return [...n, ...r];
|
|
92
|
+
}
|
|
59
93
|
});
|
|
60
|
-
let
|
|
94
|
+
let H = async (e, t, n) => {
|
|
61
95
|
try {
|
|
62
96
|
let r = {
|
|
63
|
-
|
|
97
|
+
current: e.current,
|
|
98
|
+
pageSize: e.pageSize,
|
|
64
99
|
sortBy: Object.keys(t)[0],
|
|
65
100
|
sortOrder: Object.values(t)[0],
|
|
66
|
-
...n
|
|
67
|
-
|
|
101
|
+
...n,
|
|
102
|
+
...e
|
|
103
|
+
}, i = N.operations;
|
|
104
|
+
if (i?.getList) {
|
|
105
|
+
let e = await i.getList(r);
|
|
106
|
+
return {
|
|
107
|
+
data: e.data,
|
|
108
|
+
success: !0,
|
|
109
|
+
total: e.total
|
|
110
|
+
};
|
|
111
|
+
}
|
|
68
112
|
return {
|
|
69
|
-
data:
|
|
113
|
+
data: N.state.data,
|
|
70
114
|
success: !0,
|
|
71
|
-
total:
|
|
115
|
+
total: N.state.total
|
|
72
116
|
};
|
|
73
117
|
} catch {
|
|
74
|
-
return
|
|
118
|
+
return g.error("Failed to fetch data"), {
|
|
75
119
|
data: [],
|
|
76
120
|
success: !1,
|
|
77
121
|
total: 0
|
|
78
122
|
};
|
|
79
123
|
}
|
|
80
|
-
},
|
|
81
|
-
if (
|
|
124
|
+
}, U = (e) => {
|
|
125
|
+
if (L(e || null), e) {
|
|
82
126
|
let t = { ...e };
|
|
83
|
-
|
|
127
|
+
E.forEach((e) => {
|
|
84
128
|
let n = e.dataIndex;
|
|
85
|
-
e.fieldType === "date" && t[n]
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
129
|
+
if (e.fieldType === "date" && t[n]) try {
|
|
130
|
+
t[n] = S(t[n]);
|
|
131
|
+
} catch {}
|
|
132
|
+
}), B.setFieldsValue(t);
|
|
133
|
+
} else B.resetFields();
|
|
134
|
+
F(!0);
|
|
135
|
+
}, W = async () => {
|
|
136
|
+
try {
|
|
137
|
+
let e = await B.validateFields(), t = { ...e };
|
|
138
|
+
E.forEach((n) => {
|
|
139
|
+
let r = n.dataIndex;
|
|
140
|
+
if (n.fieldType === "date" && e[r]) try {
|
|
141
|
+
t[r] = b(e[r]);
|
|
142
|
+
} catch {}
|
|
143
|
+
n.formConfig?.transform && (t[r] = n.formConfig.transform(e[r]));
|
|
144
|
+
}), I && I[D] ? await N.update(I[D], t) : await N.create(t), F(!1), N.actionRef.current?.reload();
|
|
145
|
+
} catch (e) {
|
|
146
|
+
console.error("Form validation failed:", e);
|
|
147
|
+
}
|
|
148
|
+
}, G = async (e) => {
|
|
149
|
+
f.confirm({
|
|
150
|
+
title: "Are you sure?",
|
|
151
|
+
content: "This action cannot be undone.",
|
|
152
|
+
okText: "Yes, Delete",
|
|
153
|
+
okType: "danger",
|
|
154
|
+
cancelText: "Cancel",
|
|
155
|
+
onOk: async () => {
|
|
156
|
+
await N.delete(e) && N.actionRef.current?.reload();
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}, K = async () => {
|
|
160
|
+
if (R.length === 0) {
|
|
161
|
+
g.warning("Please select items to delete");
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
f.confirm({
|
|
165
|
+
title: `Delete ${R.length} items?`,
|
|
166
|
+
content: "This action cannot be undone.",
|
|
167
|
+
okText: "Yes, Delete All",
|
|
168
|
+
okType: "danger",
|
|
169
|
+
cancelText: "Cancel",
|
|
170
|
+
onOk: async () => {
|
|
171
|
+
let e = R.map((e) => N.delete(e));
|
|
172
|
+
await Promise.allSettled(e), z([]), N.actionRef.current?.reload();
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}, q = j ? {
|
|
176
|
+
selectedRowKeys: R,
|
|
177
|
+
onChange: z
|
|
178
|
+
} : void 0;
|
|
179
|
+
return /* @__PURE__ */ w(r, {
|
|
91
180
|
needDeps: !0,
|
|
92
|
-
intl:
|
|
93
|
-
children: [/* @__PURE__ */ (
|
|
181
|
+
intl: a,
|
|
182
|
+
children: [/* @__PURE__ */ C(i, {
|
|
94
183
|
headerTitle: O,
|
|
95
184
|
rowKey: D,
|
|
96
|
-
rowClassName: (e, t) => t % 2 == 0
|
|
97
|
-
actionRef:
|
|
98
|
-
columns:
|
|
99
|
-
request:
|
|
185
|
+
rowClassName: (e, t) => t % 2 == 0 ? "row-differentiator" : "",
|
|
186
|
+
actionRef: N.actionRef,
|
|
187
|
+
columns: V,
|
|
188
|
+
request: H,
|
|
100
189
|
search: { labelWidth: "auto" },
|
|
101
|
-
pagination: {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
190
|
+
pagination: {
|
|
191
|
+
pageSize: k,
|
|
192
|
+
showSizeChanger: !0,
|
|
193
|
+
showQuickJumper: !0
|
|
194
|
+
},
|
|
195
|
+
loading: N.state.loading,
|
|
196
|
+
rowSelection: q,
|
|
197
|
+
toolBarRender: () => [
|
|
198
|
+
/* @__PURE__ */ C(o, {
|
|
199
|
+
type: "primary",
|
|
200
|
+
icon: /* @__PURE__ */ C(n, {}),
|
|
201
|
+
onClick: () => U(),
|
|
202
|
+
children: "New"
|
|
203
|
+
}, "add"),
|
|
204
|
+
...j && R.length > 0 ? [/* @__PURE__ */ w(o, {
|
|
205
|
+
danger: !0,
|
|
206
|
+
onClick: K,
|
|
207
|
+
children: [
|
|
208
|
+
"Delete Selected (",
|
|
209
|
+
R.length,
|
|
210
|
+
")"
|
|
211
|
+
]
|
|
212
|
+
}, "bulk-delete")] : [],
|
|
213
|
+
/* @__PURE__ */ C(c, {
|
|
214
|
+
menu: { items: [{
|
|
215
|
+
key: "export",
|
|
216
|
+
label: "Export",
|
|
217
|
+
disabled: !0
|
|
218
|
+
}, {
|
|
219
|
+
key: "refresh",
|
|
220
|
+
label: "Refresh",
|
|
221
|
+
onClick: () => N.refresh()
|
|
222
|
+
}] },
|
|
223
|
+
children: /* @__PURE__ */ C(o, { children: /* @__PURE__ */ C(t, {}) })
|
|
224
|
+
}, "menu")
|
|
225
|
+
],
|
|
118
226
|
options: {
|
|
119
227
|
setting: { listsHeight: 400 },
|
|
120
|
-
reload: () =>
|
|
228
|
+
reload: () => N.refresh()
|
|
121
229
|
},
|
|
122
230
|
dateFormatter: "string"
|
|
123
|
-
}), /* @__PURE__ */ (
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
},
|
|
231
|
+
}), /* @__PURE__ */ C(f, {
|
|
232
|
+
title: I ? "Edit Item" : "Create Item",
|
|
233
|
+
open: P,
|
|
234
|
+
onOk: W,
|
|
235
|
+
onCancel: () => F(!1),
|
|
141
236
|
destroyOnClose: !0,
|
|
142
|
-
|
|
143
|
-
|
|
237
|
+
width: 600,
|
|
238
|
+
children: /* @__PURE__ */ C(l, {
|
|
239
|
+
form: B,
|
|
144
240
|
layout: "vertical",
|
|
145
|
-
children:
|
|
241
|
+
children: E.map((e) => {
|
|
146
242
|
if (!e.dataIndex) return null;
|
|
147
|
-
let
|
|
243
|
+
let t = e.dataIndex, n = e.title, r = !(e.fieldEditable ?? !0), i = e.formConfig?.rules || (e.formConfig?.required ? [{
|
|
244
|
+
required: !0,
|
|
245
|
+
message: `${n} is required`
|
|
246
|
+
}] : []);
|
|
247
|
+
if (e.formConfig?.component) return /* @__PURE__ */ C(l.Item, {
|
|
248
|
+
name: t,
|
|
249
|
+
label: n,
|
|
250
|
+
rules: i,
|
|
251
|
+
children: e.formConfig.component
|
|
252
|
+
}, t);
|
|
148
253
|
switch (e.fieldType) {
|
|
149
|
-
case "string": return /* @__PURE__ */ (
|
|
150
|
-
name:
|
|
151
|
-
label:
|
|
152
|
-
rules:
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
label: a,
|
|
161
|
-
rules: [{
|
|
162
|
-
required: e.formConfig?.required,
|
|
163
|
-
message: `${a} is required`
|
|
164
|
-
}],
|
|
165
|
-
children: /* @__PURE__ */ (0, T.jsx)(u, {
|
|
254
|
+
case "string": return /* @__PURE__ */ C(l.Item, {
|
|
255
|
+
name: t,
|
|
256
|
+
label: n,
|
|
257
|
+
rules: i,
|
|
258
|
+
children: /* @__PURE__ */ C(u, { disabled: r })
|
|
259
|
+
}, t);
|
|
260
|
+
case "number": return /* @__PURE__ */ C(l.Item, {
|
|
261
|
+
name: t,
|
|
262
|
+
label: n,
|
|
263
|
+
rules: i,
|
|
264
|
+
children: /* @__PURE__ */ C(d, {
|
|
166
265
|
style: { width: "100%" },
|
|
167
|
-
disabled:
|
|
266
|
+
disabled: r
|
|
168
267
|
})
|
|
169
|
-
},
|
|
170
|
-
case "date": return /* @__PURE__ */ (
|
|
171
|
-
name:
|
|
172
|
-
label:
|
|
173
|
-
rules:
|
|
174
|
-
|
|
175
|
-
message: `${a} is required`
|
|
176
|
-
}],
|
|
177
|
-
children: /* @__PURE__ */ (0, T.jsx)(p, {
|
|
268
|
+
}, t);
|
|
269
|
+
case "date": return /* @__PURE__ */ C(l.Item, {
|
|
270
|
+
name: t,
|
|
271
|
+
label: n,
|
|
272
|
+
rules: i,
|
|
273
|
+
children: /* @__PURE__ */ C(s, {
|
|
178
274
|
style: { width: "100%" },
|
|
179
275
|
showTime: !0,
|
|
180
|
-
disabled:
|
|
276
|
+
disabled: r
|
|
181
277
|
})
|
|
182
|
-
},
|
|
183
|
-
case "boolean": return /* @__PURE__ */ (
|
|
184
|
-
name:
|
|
185
|
-
label:
|
|
278
|
+
}, t);
|
|
279
|
+
case "boolean": return /* @__PURE__ */ C(l.Item, {
|
|
280
|
+
name: t,
|
|
281
|
+
label: n,
|
|
186
282
|
valuePropName: "checked",
|
|
187
|
-
children: /* @__PURE__ */ (
|
|
188
|
-
},
|
|
189
|
-
case "enum": return /* @__PURE__ */ (
|
|
190
|
-
name:
|
|
191
|
-
label:
|
|
192
|
-
rules:
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
children: /* @__PURE__ */ (0, T.jsx)(t, {
|
|
197
|
-
disabled: o,
|
|
283
|
+
children: /* @__PURE__ */ C(m, { disabled: r })
|
|
284
|
+
}, t);
|
|
285
|
+
case "enum": return /* @__PURE__ */ C(l.Item, {
|
|
286
|
+
name: t,
|
|
287
|
+
label: n,
|
|
288
|
+
rules: i,
|
|
289
|
+
children: /* @__PURE__ */ C(p, {
|
|
290
|
+
disabled: r,
|
|
291
|
+
placeholder: `Select ${n.toLowerCase()}`,
|
|
198
292
|
options: Object.entries(e.enumOptions || {}).map(([e, t]) => ({
|
|
199
293
|
label: t.text,
|
|
200
294
|
value: e
|
|
201
295
|
}))
|
|
202
296
|
})
|
|
203
|
-
},
|
|
297
|
+
}, t);
|
|
204
298
|
default: return null;
|
|
205
299
|
}
|
|
206
300
|
})
|
|
@@ -209,4 +303,4 @@ var w = /* @__PURE__ */ e(s(), 1), T = x(), E = (e) => {
|
|
|
209
303
|
});
|
|
210
304
|
};
|
|
211
305
|
//#endregion
|
|
212
|
-
export {
|
|
306
|
+
export { T as default };
|
package/dist/CrudTableLazy.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`./
|
|
1
|
+
require(`./CrudTable.cjs`);let e=require(`react`),t=require(`react/jsx-runtime`);var n=(0,e.lazy)(()=>Promise.resolve().then(()=>require(`./CrudTable.cjs`))),r=r=>(0,t.jsx)(e.Suspense,{fallback:(0,t.jsx)(`div`,{style:{textAlign:`center`,padding:`2rem`},children:`Loading curd table w antd`}),children:(0,t.jsx)(n,{...r})});module.exports=r;
|
package/dist/CrudTableLazy.d.ts
CHANGED
package/dist/CrudTableLazy.js
CHANGED
|
@@ -1,24 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Suspense as e, lazy as t } from "react";
|
|
2
|
+
import { jsx as n } from "react/jsx-runtime";
|
|
3
3
|
//#region lib/CrudTableLazy.tsx
|
|
4
|
-
var r =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
children: /* @__PURE__ */ (0, r.jsx)(i, {
|
|
15
|
-
columns: n,
|
|
16
|
-
service: a,
|
|
17
|
-
rowKey: o,
|
|
18
|
-
title: s,
|
|
19
|
-
defaultPageSize: c
|
|
20
|
-
})
|
|
21
|
-
});
|
|
22
|
-
};
|
|
4
|
+
var r = t(() => import("./CrudTable.js")), i = (t) => /* @__PURE__ */ n(e, {
|
|
5
|
+
fallback: /* @__PURE__ */ n("div", {
|
|
6
|
+
style: {
|
|
7
|
+
textAlign: "center",
|
|
8
|
+
padding: "2rem"
|
|
9
|
+
},
|
|
10
|
+
children: "Loading curd table w antd"
|
|
11
|
+
}),
|
|
12
|
+
children: /* @__PURE__ */ n(r, { ...t })
|
|
13
|
+
});
|
|
23
14
|
//#endregion
|
|
24
|
-
export {
|
|
15
|
+
export { i as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=(e,t)=>{let n=t.filter(e=>e.fieldType!==`option`&&e.dataIndex),r=n.map(e=>String(e.title||e.dataIndex)),i=e.map(e=>n.map(t=>{let n=e[t.dataIndex];return n==null?``:t.fieldType===`boolean`?n?`Yes`:`No`:t.fieldType===`date`?String(n):t.fieldType===`enum`&&t.enumOptions&&t.enumOptions[n]?.text||String(n)}));return[r.map(e=>`"${e}"`).join(`,`),...i.map(e=>e.map(e=>`"${String(e).replace(/"/g,`""`)}"`).join(`,`))].join(`
|
|
2
|
+
`)},t=(e,t,n)=>{let r=new Blob([e],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)},n=n=>{let{data:r,columns:i,filename:a=`export`}=n;t(e(r,i),`${a}.csv`,`text/csv;charset=utf-8;`)},r=e=>{let{data:n,filename:r=`export`}=e;t(JSON.stringify(n,null,2),`${r}.json`,`application/json`)},i=e=>{let{data:n,columns:r,filename:i=`export`}=e,a=r.filter(e=>e.fieldType!==`option`&&e.dataIndex),o=a.map(e=>String(e.title||e.dataIndex)),s=n.map(e=>a.map(t=>{let n=e[t.dataIndex];return n==null?``:t.fieldType===`boolean`?n?`Yes`:`No`:t.fieldType===`enum`&&t.enumOptions&&t.enumOptions[n]?.text||String(n)}));t((()=>{let e=e=>e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`);return`<?xml version="1.0" encoding="UTF-8"?>
|
|
3
|
+
<?xml-stylesheet type="text/xsl" href="stylesheet.xsl"?>
|
|
4
|
+
<workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet">
|
|
5
|
+
<sheets>
|
|
6
|
+
<sheet name="Export">
|
|
7
|
+
<table>
|
|
8
|
+
<row>${o.map(t=>`<c t="inlineStr"><is><t>${e(t)}</t></is></c>`).join(``)}</row>
|
|
9
|
+
${s.map(t=>`<row>${t.map(t=>`<c t="inlineStr"><is><t>${e(String(t))}</t></is></c>`).join(``)}</row>`).join(``)}
|
|
10
|
+
</table>
|
|
11
|
+
</sheet>
|
|
12
|
+
</sheets>
|
|
13
|
+
</workbook>`})(),`${i}.xls`,`application/vnd.ms-excel`)},a=e=>{let{format:t=`csv`}=e;switch(t){case`csv`:n(e);break;case`json`:r(e);break;case`xlsx`:i(e);break;default:n(e)}},o=async(e,t,n=`export`,r=`csv`)=>{try{a({data:await e(),columns:t,filename:n,format:r})}catch(e){throw console.error(`Export failed:`,e),e}};exports.default=a,exports.exportData=a,exports.exportAllData=o,exports.exportToCSV=n,exports.exportToJSON=r,exports.exportToXLSX=i;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
//#region lib/utils/exportData.ts
|
|
2
|
+
var e = (e, t) => {
|
|
3
|
+
let n = t.filter((e) => e.fieldType !== "option" && e.dataIndex), r = n.map((e) => String(e.title || e.dataIndex)), i = e.map((e) => n.map((t) => {
|
|
4
|
+
let n = e[t.dataIndex];
|
|
5
|
+
return n == null ? "" : t.fieldType === "boolean" ? n ? "Yes" : "No" : t.fieldType === "date" ? String(n) : t.fieldType === "enum" && t.enumOptions && t.enumOptions[n]?.text || String(n);
|
|
6
|
+
}));
|
|
7
|
+
return [r.map((e) => `"${e}"`).join(","), ...i.map((e) => e.map((e) => `"${String(e).replace(/"/g, "\"\"")}"`).join(","))].join("\n");
|
|
8
|
+
}, t = (e, t, n) => {
|
|
9
|
+
let r = new Blob([e], { type: n }), i = URL.createObjectURL(r), a = document.createElement("a");
|
|
10
|
+
a.href = i, a.download = t, document.body.appendChild(a), a.click(), document.body.removeChild(a), URL.revokeObjectURL(i);
|
|
11
|
+
}, n = (n) => {
|
|
12
|
+
let { data: r, columns: i, filename: a = "export" } = n;
|
|
13
|
+
t(e(r, i), `${a}.csv`, "text/csv;charset=utf-8;");
|
|
14
|
+
}, r = (e) => {
|
|
15
|
+
let { data: n, filename: r = "export" } = e;
|
|
16
|
+
t(JSON.stringify(n, null, 2), `${r}.json`, "application/json");
|
|
17
|
+
}, i = (e) => {
|
|
18
|
+
let { data: n, columns: r, filename: i = "export" } = e, a = r.filter((e) => e.fieldType !== "option" && e.dataIndex), o = a.map((e) => String(e.title || e.dataIndex)), s = n.map((e) => a.map((t) => {
|
|
19
|
+
let n = e[t.dataIndex];
|
|
20
|
+
return n == null ? "" : t.fieldType === "boolean" ? n ? "Yes" : "No" : t.fieldType === "enum" && t.enumOptions && t.enumOptions[n]?.text || String(n);
|
|
21
|
+
}));
|
|
22
|
+
t((() => {
|
|
23
|
+
let e = (e) => e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
24
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
25
|
+
<?xml-stylesheet type="text/xsl" href="stylesheet.xsl"?>
|
|
26
|
+
<workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet">
|
|
27
|
+
<sheets>
|
|
28
|
+
<sheet name="Export">
|
|
29
|
+
<table>
|
|
30
|
+
<row>${o.map((t) => `<c t="inlineStr"><is><t>${e(t)}</t></is></c>`).join("")}</row>
|
|
31
|
+
${s.map((t) => `<row>${t.map((t) => `<c t="inlineStr"><is><t>${e(String(t))}</t></is></c>`).join("")}</row>`).join("")}
|
|
32
|
+
</table>
|
|
33
|
+
</sheet>
|
|
34
|
+
</sheets>
|
|
35
|
+
</workbook>`;
|
|
36
|
+
})(), `${i}.xls`, "application/vnd.ms-excel");
|
|
37
|
+
}, a = (e) => {
|
|
38
|
+
let { format: t = "csv" } = e;
|
|
39
|
+
switch (t) {
|
|
40
|
+
case "csv":
|
|
41
|
+
n(e);
|
|
42
|
+
break;
|
|
43
|
+
case "json":
|
|
44
|
+
r(e);
|
|
45
|
+
break;
|
|
46
|
+
case "xlsx":
|
|
47
|
+
i(e);
|
|
48
|
+
break;
|
|
49
|
+
default: n(e);
|
|
50
|
+
}
|
|
51
|
+
}, o = async (e, t, n = "export", r = "csv") => {
|
|
52
|
+
try {
|
|
53
|
+
a({
|
|
54
|
+
data: await e(),
|
|
55
|
+
columns: t,
|
|
56
|
+
filename: n,
|
|
57
|
+
format: r
|
|
58
|
+
});
|
|
59
|
+
} catch (e) {
|
|
60
|
+
throw console.error("Export failed:", e), e;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
export { a as default, a as exportData, o as exportAllData, n as exportToCSV, r as exportToJSON, i as exportToXLSX };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
export { default as CrudTable } from './CrudTable';
|
|
2
2
|
export { default as CrudTableLazy } from './CrudTableLazy';
|
|
3
|
-
export { default as CrudTableExperimental } from './CrudTableExperimental';
|
|
4
|
-
export { default as CrudTableExperimentalLazy } from './CrudTableExperimentalLazy';
|
|
5
3
|
export { useCrudTable } from './hooks/useCrudTable';
|
|
6
4
|
export { useLocalStorageCrud } from './hooks/useLocalStorageCrud';
|
|
7
5
|
export { exportData, exportToCSV, exportToJSON, exportToXLSX, exportAllData } from './utils/exportData';
|
|
8
6
|
export type { CrudTableConfig, CrudColumn, DataType } from './CrudTable';
|
|
9
|
-
export type { EnhancedCrudTableConfig } from './CrudTableExperimental';
|
|
10
7
|
export type { UseCrudTableConfig, CrudTableActions, CrudOperation, CrudParams, CrudResponse, CrudState } from './hooks/useCrudTable';
|
|
11
8
|
export type { UseLocalStorageCrudConfig } from './hooks/useLocalStorageCrud';
|
|
12
9
|
export type { ExportFormat } from './utils/exportData';
|