@kingteza/crud-component 1.0.64 → 1.0.65
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/crud/CrudComponent.cjs.js +1 -1
- package/crud/CrudComponent.es.js +96 -185
- package/crud/actions/index.cjs.js +1 -0
- package/crud/actions/index.d.ts +26 -0
- package/crud/actions/index.es.js +83 -0
- package/crud/index.d.ts +4 -0
- package/crud/modal/index.cjs.js +1 -0
- package/crud/modal/index.d.ts +24 -0
- package/crud/modal/index.es.js +146 -0
- package/crud/view/CrudDecListView.cjs.js +1 -1
- package/crud/view/CrudDecListView.d.ts +5 -4
- package/crud/view/CrudDecListView.es.js +38 -26
- package/crud/view/CrudViewer.cjs.js +1 -1
- package/crud/view/CrudViewer.d.ts +3 -16
- package/crud/view/CrudViewer.es.js +239 -273
- package/index.cjs.js +1 -1
- package/index.es.js +24 -20
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const e=require("react/jsx-runtime"),l=require("antd"),t=require("react"),H=require("./modal/index.cjs.js"),J=require("./import/CrudImportButton.cjs.js"),K=require("./view/CrudViewer.cjs.js"),L=require("../common/button/NewButton.cjs.js"),M=require("../common/button/PrintButton.cjs.js"),{useForm:Q}=l.Form;function O({idField:a="id",onCreate:C,onDelete:j,onHide:m,onUpdate:n,fields:r,data:f,grid:k,isHiding:q,isCreating:h,isDeleting:p,isUpdating:B,paginateProps:w,onPrint:i,printing:N,viewable:v,loadingData:R,formBuilder:g,extraAction:y,minusHeight:b,cloneable:F,fullWidthModal:P=!0,wizard:S,extraView:I,importable:u,onClickNew:d,size:V,...z}){const c=t.useRef(null),A=t.useCallback(()=>{var s;(s=c.current)==null||s.create()},[]),o=t.useCallback(async(s,E=!0,G=!1)=>{var x;await((x=c.current)==null?void 0:x.update(s,E,G))},[]),D=t.useCallback(async s=>{o(s,!1,!0)},[o]);return e.jsxs(e.Fragment,{children:[e.jsxs(l.Space,{direction:"vertical",className:"w-100",children:[e.jsxs("div",{className:"w-100 d-flex",children:[e.jsx("div",{style:{flex:1},children:e.jsx(L.NewButton,{onClick:()=>{d?d():A()},className:"flex-1"})}),e.jsxs(l.Space,{children:[!!i&&e.jsx(M.PrintButton,{className:"float-right",loading:N,onClick:i}),!!u&&e.jsx(J,{fields:r,importProps:u})]})]}),e.jsx(K,{...z,minusHeight:b,data:f,size:V,fields:r,extraAction:y,idField:a,isDeleting:p,loadingData:R,onClickUpdate:n?o:void 0,onHide:m,isHiding:q,onDelete:j,onUpdate:n,onClickClone:F?D:void 0,paginateProps:w,viewable:v,extraView:I})]}),e.jsx(H,{ref:c,fields:r,wizard:S,grid:k,fullWidthModal:P,isCreating:h,isUpdating:B,onCreate:C,onUpdate:n,idField:a,formBuilder:g})]})}module.exports=O;
|
package/crud/CrudComponent.es.js
CHANGED
|
@@ -1,212 +1,123 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
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
|
-
importable: U,
|
|
40
|
-
onClickNew: D,
|
|
41
|
-
size: oe,
|
|
42
|
-
...ne
|
|
1
|
+
import { jsxs as e, Fragment as H, jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import { Space as f, Form as J } from "antd";
|
|
3
|
+
import { useRef as K, useCallback as c } from "react";
|
|
4
|
+
import L from "./modal/index.es.js";
|
|
5
|
+
import O from "./import/CrudImportButton.es.js";
|
|
6
|
+
import Q from "./view/CrudViewer.es.js";
|
|
7
|
+
import { NewButton as T } from "../common/button/NewButton.es.js";
|
|
8
|
+
import { PrintButton as U } from "../common/button/PrintButton.es.js";
|
|
9
|
+
const { useForm: eo } = J;
|
|
10
|
+
function to({
|
|
11
|
+
idField: i = "id",
|
|
12
|
+
onCreate: p,
|
|
13
|
+
onDelete: C,
|
|
14
|
+
onHide: h,
|
|
15
|
+
onUpdate: t,
|
|
16
|
+
fields: n,
|
|
17
|
+
data: k,
|
|
18
|
+
grid: x,
|
|
19
|
+
isHiding: v,
|
|
20
|
+
isCreating: w,
|
|
21
|
+
isDeleting: B,
|
|
22
|
+
isUpdating: N,
|
|
23
|
+
paginateProps: g,
|
|
24
|
+
onPrint: m,
|
|
25
|
+
printing: y,
|
|
26
|
+
viewable: j,
|
|
27
|
+
loadingData: F,
|
|
28
|
+
formBuilder: R,
|
|
29
|
+
extraAction: I,
|
|
30
|
+
minusHeight: M,
|
|
31
|
+
cloneable: P,
|
|
32
|
+
fullWidthModal: S = !0,
|
|
33
|
+
wizard: V,
|
|
34
|
+
extraView: b,
|
|
35
|
+
importable: s,
|
|
36
|
+
onClickNew: u,
|
|
37
|
+
size: q,
|
|
38
|
+
...z
|
|
43
39
|
}) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}), Object.assign(c, n), p && f ? (await f({
|
|
52
|
-
...c,
|
|
53
|
-
[v]: p[v]
|
|
54
|
-
}), N(void 0)) : !p && h && await h(c), x(void 0), a.resetFields(), C(!1);
|
|
40
|
+
const l = K(null), A = c(() => {
|
|
41
|
+
var o;
|
|
42
|
+
(o = l.current) == null || o.create();
|
|
43
|
+
}, []), a = c(
|
|
44
|
+
async (o, E = !0, G = !1) => {
|
|
45
|
+
var d;
|
|
46
|
+
await ((d = l.current) == null ? void 0 : d.update(o, E, G));
|
|
55
47
|
},
|
|
56
|
-
[
|
|
57
|
-
),
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}, [b]);
|
|
61
|
-
const T = g(async (t) => {
|
|
62
|
-
M(t), V(!0);
|
|
63
|
-
}, []), W = g(async () => {
|
|
64
|
-
V(!0);
|
|
65
|
-
}, []), [ae, _] = m(!1), S = g(
|
|
66
|
-
async (t, c = !0, r = !1) => {
|
|
67
|
-
try {
|
|
68
|
-
_(!0), C(!0), c && B("update");
|
|
69
|
-
const n = {};
|
|
70
|
-
for (const o of i) {
|
|
71
|
-
const l = A.getRealName(o.name, "upsertFieldName"), e = t[l];
|
|
72
|
-
if (r && o.type === "image") {
|
|
73
|
-
const u = e;
|
|
74
|
-
try {
|
|
75
|
-
const ce = await o.provider.clone(u);
|
|
76
|
-
n[l] = ce;
|
|
77
|
-
continue;
|
|
78
|
-
} catch {
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
o.type === "date" ? e && (n[l] = pe(e)) : o.type === "select" ? o.multiple && Array.isArray(e) ? n[l] = e.map(
|
|
83
|
-
(u) => u[o.innerFieldId ?? "id"]
|
|
84
|
-
) : e && typeof e == "object" ? n[l] = e[o.innerFieldId ?? "id"] : (e && typeof e == "string" || typeof e == "number") && (n[l] = e) : n[l] = e;
|
|
85
|
-
}
|
|
86
|
-
a.setFieldsValue(n), x(n), c && N(t);
|
|
87
|
-
} finally {
|
|
88
|
-
_(!1);
|
|
89
|
-
}
|
|
48
|
+
[]
|
|
49
|
+
), D = c(
|
|
50
|
+
async (o) => {
|
|
51
|
+
a(o, !1, !0);
|
|
90
52
|
},
|
|
91
|
-
[
|
|
92
|
-
), [y, B] = m(), re = g(
|
|
93
|
-
async (t) => {
|
|
94
|
-
B("clone"), S(t, !1, !0);
|
|
95
|
-
},
|
|
96
|
-
[S]
|
|
53
|
+
[a]
|
|
97
54
|
);
|
|
98
|
-
return /* @__PURE__ */
|
|
99
|
-
/* @__PURE__ */
|
|
100
|
-
/* @__PURE__ */
|
|
101
|
-
/* @__PURE__ */
|
|
102
|
-
|
|
55
|
+
return /* @__PURE__ */ e(H, { children: [
|
|
56
|
+
/* @__PURE__ */ e(f, { direction: "vertical", className: "w-100", children: [
|
|
57
|
+
/* @__PURE__ */ e("div", { className: "w-100 d-flex", children: [
|
|
58
|
+
/* @__PURE__ */ r("div", { style: { flex: 1 }, children: /* @__PURE__ */ r(
|
|
59
|
+
T,
|
|
103
60
|
{
|
|
104
61
|
onClick: () => {
|
|
105
|
-
|
|
62
|
+
u ? u() : A();
|
|
106
63
|
},
|
|
107
64
|
className: "flex-1"
|
|
108
65
|
}
|
|
109
66
|
) }),
|
|
110
|
-
/* @__PURE__ */
|
|
111
|
-
!!
|
|
112
|
-
|
|
67
|
+
/* @__PURE__ */ e(f, { children: [
|
|
68
|
+
!!m && /* @__PURE__ */ r(
|
|
69
|
+
U,
|
|
113
70
|
{
|
|
114
71
|
className: "float-right",
|
|
115
|
-
loading:
|
|
116
|
-
onClick:
|
|
72
|
+
loading: y,
|
|
73
|
+
onClick: m
|
|
117
74
|
}
|
|
118
75
|
),
|
|
119
|
-
!!
|
|
76
|
+
!!s && /* @__PURE__ */ r(O, { fields: n, importProps: s })
|
|
120
77
|
] })
|
|
121
78
|
] }),
|
|
122
|
-
/* @__PURE__ */
|
|
123
|
-
|
|
79
|
+
/* @__PURE__ */ r(
|
|
80
|
+
Q,
|
|
124
81
|
{
|
|
125
|
-
...
|
|
126
|
-
minusHeight:
|
|
127
|
-
data:
|
|
128
|
-
size:
|
|
129
|
-
fields:
|
|
130
|
-
extraAction:
|
|
131
|
-
idField:
|
|
132
|
-
isDeleting:
|
|
133
|
-
loadingData:
|
|
134
|
-
onClickUpdate:
|
|
135
|
-
onHide:
|
|
136
|
-
isHiding:
|
|
137
|
-
onDelete:
|
|
138
|
-
onUpdate:
|
|
139
|
-
onClickClone:
|
|
140
|
-
paginateProps:
|
|
141
|
-
viewable:
|
|
142
|
-
extraView:
|
|
82
|
+
...z,
|
|
83
|
+
minusHeight: M,
|
|
84
|
+
data: k,
|
|
85
|
+
size: q,
|
|
86
|
+
fields: n,
|
|
87
|
+
extraAction: I,
|
|
88
|
+
idField: i,
|
|
89
|
+
isDeleting: B,
|
|
90
|
+
loadingData: F,
|
|
91
|
+
onClickUpdate: t ? a : void 0,
|
|
92
|
+
onHide: h,
|
|
93
|
+
isHiding: v,
|
|
94
|
+
onDelete: C,
|
|
95
|
+
onUpdate: t,
|
|
96
|
+
onClickClone: P ? D : void 0,
|
|
97
|
+
paginateProps: g,
|
|
98
|
+
viewable: j,
|
|
99
|
+
extraView: b
|
|
143
100
|
}
|
|
144
101
|
)
|
|
145
102
|
] }),
|
|
146
|
-
/* @__PURE__ */
|
|
147
|
-
|
|
103
|
+
/* @__PURE__ */ r(
|
|
104
|
+
L,
|
|
148
105
|
{
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
disabled: ie,
|
|
161
|
-
hidden: !!s
|
|
162
|
-
},
|
|
163
|
-
onCancel: async () => {
|
|
164
|
-
try {
|
|
165
|
-
if (y === "clone") {
|
|
166
|
-
const t = s ? p : a.getFieldsValue(), c = i.filter((r) => r.type === "image");
|
|
167
|
-
for (const r of c)
|
|
168
|
-
t[r.name] && r.provider.delete(
|
|
169
|
-
t[r.name]
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
} finally {
|
|
173
|
-
}
|
|
174
|
-
s || a.resetFields(), x(void 0), N(void 0), C(!1);
|
|
175
|
-
},
|
|
176
|
-
onOk: () => I(),
|
|
177
|
-
destroyOnHidden: !0,
|
|
178
|
-
children: /* @__PURE__ */ F(fe, { spinning: ae, children: [
|
|
179
|
-
!s && /* @__PURE__ */ d(
|
|
180
|
-
Fe,
|
|
181
|
-
{
|
|
182
|
-
purpose: y,
|
|
183
|
-
fields: i,
|
|
184
|
-
form: a,
|
|
185
|
-
formBuilder: Y,
|
|
186
|
-
grid: R,
|
|
187
|
-
onDeleteFile: W,
|
|
188
|
-
onUploadFile: T
|
|
189
|
-
}
|
|
190
|
-
),
|
|
191
|
-
s && /* @__PURE__ */ d(
|
|
192
|
-
ge,
|
|
193
|
-
{
|
|
194
|
-
submitting: P || j,
|
|
195
|
-
className: "mt-2",
|
|
196
|
-
onSave: I,
|
|
197
|
-
updatingValue: le,
|
|
198
|
-
fields: i,
|
|
199
|
-
onDeleteFile: W,
|
|
200
|
-
onUploadFile: T,
|
|
201
|
-
purpose: y,
|
|
202
|
-
wizard: s
|
|
203
|
-
}
|
|
204
|
-
)
|
|
205
|
-
] })
|
|
106
|
+
ref: l,
|
|
107
|
+
fields: n,
|
|
108
|
+
wizard: V,
|
|
109
|
+
grid: x,
|
|
110
|
+
fullWidthModal: S,
|
|
111
|
+
isCreating: w,
|
|
112
|
+
isUpdating: N,
|
|
113
|
+
onCreate: p,
|
|
114
|
+
onUpdate: t,
|
|
115
|
+
idField: i,
|
|
116
|
+
formBuilder: R
|
|
206
117
|
}
|
|
207
118
|
)
|
|
208
119
|
] });
|
|
209
120
|
}
|
|
210
121
|
export {
|
|
211
|
-
|
|
122
|
+
to as default
|
|
212
123
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const v=require("react/jsx-runtime"),W=require("react"),$=require("../../common/button/CloneButtonTable.cjs.js"),w=require("../../common/button/DeleteButtonTable.cjs.js"),A=require("../../common/button/ExportButton.cjs.js"),H=require("../../common/button/HideButtonTable.cjs.js"),V=require("../../common/button/UpdateButtonTable.cjs.js"),c=require("../modal/index.cjs.js");function k({data:b,idField:j="id",extraAction:h,onUpdate:r,onClickUpdate:x,onClickClone:y,onDelete:s,onHide:g,onExport:E,isHiding:z,isDeleting:G,confirmHiding:X,confirmDeleting:Y,closeViewOnClickUpdate:Z,recentUpdateOrDeleteId:J,setRecentUpdateOrDeleteId:q,setOpenView:T,inBuiltModalProps:f}){var N;const m=h==null?void 0:h(b),K=W.useRef(null),L=W.useCallback((u,_=!0,Q=!1)=>{var S;q==null||q(u[j]),f?(S=K.current)==null||S.update(u,_,Q):Q?y==null||y(u):x==null||x(u),Z&&(T==null||T(void 0))},[f,x]);return(Array.isArray(m)?(N=m==null?void 0:m.filter(Boolean))!=null&&N.length:m)||r||x||y||s?v.jsxs(v.Fragment,{children:[f&&v.jsx(c,{ref:K,...f}),m,(r||x||(f==null?void 0:f.onUpdate))&&v.jsx(V,{value:b,onClick:u=>L(u)}),(y||(f==null?void 0:f.onCreate))&&v.jsx($,{value:b,onClick:u=>L(u,!1,!0)}),E&&v.jsx(A.ExportButton,{value:b,onClick:async u=>await E(u)}),g&&v.jsx(H,{value:b,disabled:z,shouldConfirm:X,loading:z&&b[j]===J,onClick:async u=>{q==null||q(u[j]),await g({[j]:u[j]})}}),s&&v.jsx(w,{value:b,disabled:G,shouldConfirm:Y,loading:G&&b[j]===J,onClick:async u=>{q==null||q(u[j]),await s({[j]:u[j]})}})]}):void 0}module.exports=k;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { default as IdProps } from '../../types/Id';
|
|
3
|
+
import { CrudModalProps } from '../modal';
|
|
4
|
+
export interface CrudActionsProps<T, FormType> {
|
|
5
|
+
idField?: string;
|
|
6
|
+
extraAction?: (t: T) => ReactElement | undefined | ReactElement[];
|
|
7
|
+
onUpdate?: (t: FormType & IdProps) => Promise<any>;
|
|
8
|
+
onClickUpdate?: (t: T) => void;
|
|
9
|
+
onClickClone?: (t: T) => Promise<any>;
|
|
10
|
+
onDelete?: (id: any) => Promise<any>;
|
|
11
|
+
onHide?: (id: any) => Promise<any>;
|
|
12
|
+
onExport?: (t: T) => Promise<any>;
|
|
13
|
+
isHiding?: boolean;
|
|
14
|
+
isDeleting?: boolean;
|
|
15
|
+
confirmHiding?: boolean;
|
|
16
|
+
confirmDeleting?: boolean;
|
|
17
|
+
closeViewOnClickUpdate?: boolean;
|
|
18
|
+
recentUpdateOrDeleteId?: string;
|
|
19
|
+
setRecentUpdateOrDeleteId?: (id: string) => void;
|
|
20
|
+
setOpenView?: (data: T | undefined) => void;
|
|
21
|
+
inBuiltModalProps?: CrudModalProps<T, FormType>;
|
|
22
|
+
}
|
|
23
|
+
declare function CrudActions<T, FormType>({ data, idField, extraAction, onUpdate, onClickUpdate, onClickClone, onDelete, onHide, onExport, isHiding, isDeleting, confirmHiding, confirmDeleting, closeViewOnClickUpdate, recentUpdateOrDeleteId, setRecentUpdateOrDeleteId, setOpenView, inBuiltModalProps, }: CrudActionsProps<T, FormType> & {
|
|
24
|
+
data: T;
|
|
25
|
+
}): import("react/jsx-runtime").JSX.Element | undefined;
|
|
26
|
+
export default CrudActions;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { jsxs as w, Fragment as A, jsx as T } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as H, useCallback as x } from "react";
|
|
3
|
+
import V from "../../common/button/CloneButtonTable.es.js";
|
|
4
|
+
import k from "../../common/button/DeleteButtonTable.es.js";
|
|
5
|
+
import { ExportButton as o } from "../../common/button/ExportButton.es.js";
|
|
6
|
+
import B from "../../common/button/HideButtonTable.es.js";
|
|
7
|
+
import C from "../../common/button/UpdateButtonTable.es.js";
|
|
8
|
+
import F from "../modal/index.es.js";
|
|
9
|
+
function O({
|
|
10
|
+
data: v,
|
|
11
|
+
idField: u = "id",
|
|
12
|
+
extraAction: j,
|
|
13
|
+
onUpdate: z,
|
|
14
|
+
onClickUpdate: y,
|
|
15
|
+
onClickClone: g,
|
|
16
|
+
onDelete: r,
|
|
17
|
+
onHide: E,
|
|
18
|
+
onExport: G,
|
|
19
|
+
isHiding: J,
|
|
20
|
+
isDeleting: K,
|
|
21
|
+
confirmHiding: Y,
|
|
22
|
+
confirmDeleting: Z,
|
|
23
|
+
closeViewOnClickUpdate: _,
|
|
24
|
+
recentUpdateOrDeleteId: L,
|
|
25
|
+
setRecentUpdateOrDeleteId: b,
|
|
26
|
+
setOpenView: q,
|
|
27
|
+
inBuiltModalProps: m
|
|
28
|
+
}) {
|
|
29
|
+
var S;
|
|
30
|
+
const h = j == null ? void 0 : j(v), N = H(null), Q = x(
|
|
31
|
+
(f, $ = !0, W = !1) => {
|
|
32
|
+
var X;
|
|
33
|
+
b == null || b(f[u]), m ? (X = N.current) == null || X.update(f, $, W) : W ? g == null || g(f) : y == null || y(f), _ && (q == null || q(void 0));
|
|
34
|
+
},
|
|
35
|
+
[m, y]
|
|
36
|
+
);
|
|
37
|
+
return (Array.isArray(h) ? (S = h == null ? void 0 : h.filter(Boolean)) != null && S.length : h) || z || y || g || r ? /* @__PURE__ */ w(A, { children: [
|
|
38
|
+
m && /* @__PURE__ */ T(F, { ref: N, ...m }),
|
|
39
|
+
h,
|
|
40
|
+
(z || y || (m == null ? void 0 : m.onUpdate)) && /* @__PURE__ */ T(C, { value: v, onClick: (f) => Q(f) }),
|
|
41
|
+
(g || (m == null ? void 0 : m.onCreate)) && /* @__PURE__ */ T(
|
|
42
|
+
V,
|
|
43
|
+
{
|
|
44
|
+
value: v,
|
|
45
|
+
onClick: (f) => Q(f, !1, !0)
|
|
46
|
+
}
|
|
47
|
+
),
|
|
48
|
+
G && /* @__PURE__ */ T(
|
|
49
|
+
o,
|
|
50
|
+
{
|
|
51
|
+
value: v,
|
|
52
|
+
onClick: async (f) => await G(f)
|
|
53
|
+
}
|
|
54
|
+
),
|
|
55
|
+
E && /* @__PURE__ */ T(
|
|
56
|
+
B,
|
|
57
|
+
{
|
|
58
|
+
value: v,
|
|
59
|
+
disabled: J,
|
|
60
|
+
shouldConfirm: Y,
|
|
61
|
+
loading: J && v[u] === L,
|
|
62
|
+
onClick: async (f) => {
|
|
63
|
+
b == null || b(f[u]), await E({ [u]: f[u] });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
),
|
|
67
|
+
r && /* @__PURE__ */ T(
|
|
68
|
+
k,
|
|
69
|
+
{
|
|
70
|
+
value: v,
|
|
71
|
+
disabled: K,
|
|
72
|
+
shouldConfirm: Z,
|
|
73
|
+
loading: K && v[u] === L,
|
|
74
|
+
onClick: async (f) => {
|
|
75
|
+
b == null || b(f[u]), await r({ [u]: f[u] });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
] }) : void 0;
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
O as default
|
|
83
|
+
};
|
package/crud/index.d.ts
CHANGED
|
@@ -16,4 +16,8 @@ export type { FileCrudField as FileCrudFieldProps } from './FileCrudField';
|
|
|
16
16
|
export { default as CrudImportComponent } from './import/CrudImportComponent';
|
|
17
17
|
export type { CrudImportComponentProps, CrudImportProps, } from './import/CrudImportComponent';
|
|
18
18
|
export { default as CrudImportButton } from './import/CrudImportButton';
|
|
19
|
+
export { default as CrudActions } from './actions';
|
|
20
|
+
export type { CrudActionsProps } from './actions';
|
|
21
|
+
export { default as CrudModal } from './modal';
|
|
22
|
+
export type { CrudModalProps, CrudModalRef } from './modal';
|
|
19
23
|
export * from './view';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const g=require("react/jsx-runtime"),B=require("antd"),t=require("react"),G=require("../CrudForm.cjs.js"),J=require("../CrudFormWizard.cjs.js"),K=require("../../locale/index.cjs.js"),H=require("../../util/CrudUtil.cjs.js"),Q=require("dayjs"),X=({fields:u,wizard:l,grid:I,fullWidthModal:M,isCreating:h,isUpdating:j,onCreate:b,onUpdate:v,idField:k="id",formBuilder:T},W)=>{const[s]=B.Form.useForm(),{t:C}=K.useTranslationLib(),[S,m]=t.useState(!1),[p,q]=t.useState("new"),[f,F]=t.useState(),[_,y]=t.useState(),[A,N]=t.useState(!1),[L,x]=t.useState(!1),[E,V]=t.useState(!1),P=t.useCallback(async c=>{var o;const d=l?c:await s.validateFields(),i=u.filter(a=>a.type==="color"),n={};for(const a of i){const e=H.getRealName(a.name,"upsertFieldName"),r=s.getFieldValue(e);n[e]=typeof r=="string"?r:(o=r==null?void 0:r.toHexString())==null?void 0:o.toUpperCase()}Object.assign(d,n),f&&v?(await v({...d,[k]:f[k]}),F(void 0)):!f&&b&&await b(d),y(void 0),s.resetFields(),m(!1)},[u,s,k,b,v,f,l]),R=t.useCallback(async c=>{N(c),x(!0)},[]),U=t.useCallback(async()=>{x(!0)},[]),O=t.useCallback(()=>{m(!0),q("new"),s.resetFields(),F(void 0),y(void 0)},[s]),D=t.useCallback(async(c,d=!0,i=!1)=>{try{V(!0),m(!0),q(i?"clone":"update");const n={};for(const o of u){const a=H.getRealName(o.name,"upsertFieldName"),e=c[a];if(i&&o.type==="image"){const r=e;try{const w=await o.provider.clone(r);n[a]=w;continue}catch{continue}}o.type==="date"?e&&(n[a]=Q(e)):o.type==="select"?o.multiple&&Array.isArray(e)?n[a]=e.map(r=>r[o.innerFieldId??"id"]):e&&typeof e=="object"?n[a]=e[o.innerFieldId??"id"]:(e&&typeof e=="string"||typeof e=="number")&&(n[a]=e):n[a]=e}s.setFieldsValue(n),y(n),d&&F(c)}finally{V(!1)}},[u,s]);t.useImperativeHandle(W,()=>({create:O,update:D}),[O,D]),t.useEffect(()=>{S&&(N(!1),x(!1))},[S]);const $=t.useCallback(async()=>{try{if(p==="clone"){const c=l?f:s.getFieldsValue(),d=u.filter(i=>i.type==="image");for(const i of d)c[i.name]&&i.provider.delete(c[i.name])}}finally{}l||s.resetFields(),y(void 0),F(void 0),m(!1)},[p,l,s,f,u]);return g.jsx(B.Modal,{width:M?"100%":void 0,title:C(p??"new"),open:S,confirmLoading:h||j,okText:C("str."+(p==="update"?"update":"save")),cancelText:C("str.cancel"),cancelButtonProps:{disabled:L,hidden:!!l},okButtonProps:{disabled:A,hidden:!!l},onCancel:$,onOk:()=>P(),destroyOnHidden:!0,children:g.jsxs(B.Spin,{spinning:E,children:[l?null:g.jsx(G.CrudForm,{purpose:p,fields:u,form:s,formBuilder:T,grid:I,onDeleteFile:U,onUploadFile:R}),l&&g.jsx(J,{submitting:h||j,className:"mt-2",onSave:P,updatingValue:_,fields:u,onDeleteFile:U,onUploadFile:R,purpose:p,wizard:l})]})})},Y=t.forwardRef(X);module.exports=Y;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Ref } from 'react';
|
|
2
|
+
import { CrudFieldProps, CrudWizardProp, FormBuilderFunc } from '../CrudComponent';
|
|
3
|
+
import { default as IdProps } from '../../types/Id';
|
|
4
|
+
export interface CrudModalProps<T, FormType> {
|
|
5
|
+
fields: CrudFieldProps<T>[];
|
|
6
|
+
wizard?: CrudWizardProp<T>[];
|
|
7
|
+
grid?: boolean;
|
|
8
|
+
fullWidthModal?: boolean;
|
|
9
|
+
isCreating?: boolean;
|
|
10
|
+
isUpdating?: boolean;
|
|
11
|
+
onCreate?: (data: FormType) => Promise<any>;
|
|
12
|
+
onUpdate?: (data: FormType & IdProps) => Promise<any>;
|
|
13
|
+
idField?: string;
|
|
14
|
+
formBuilder?: FormBuilderFunc<T>;
|
|
15
|
+
}
|
|
16
|
+
export interface CrudModalRef<T> {
|
|
17
|
+
create: () => void;
|
|
18
|
+
update: (data: T, shouldSetUpdatingField?: boolean, isClone?: boolean) => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
declare const CrudModal: <T, FormType = T>({ fields, wizard, grid, fullWidthModal, isCreating, isUpdating, onCreate, onUpdate, idField, formBuilder, }: CrudModalProps<T, FormType>, ref: Ref<CrudModalRef<T>>) => import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
declare const _default: <T, FormType = T>(props: CrudModalProps<T, FormType> & {
|
|
22
|
+
ref?: Ref<CrudModalRef<T>>;
|
|
23
|
+
}) => ReturnType<typeof CrudModal>;
|
|
24
|
+
export default _default;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { jsx as N, jsxs as G } from "react/jsx-runtime";
|
|
2
|
+
import { Form as J, Modal as K, Spin as Q } from "antd";
|
|
3
|
+
import { forwardRef as X, useState as u, useCallback as m, useImperativeHandle as Y, useEffect as Z } from "react";
|
|
4
|
+
import { CrudForm as z } from "../CrudForm.es.js";
|
|
5
|
+
import ee from "../CrudFormWizard.es.js";
|
|
6
|
+
import { useTranslationLib as te } from "../../locale/index.es.js";
|
|
7
|
+
import M from "../../util/CrudUtil.es.js";
|
|
8
|
+
import oe from "dayjs";
|
|
9
|
+
const ne = ({
|
|
10
|
+
fields: c,
|
|
11
|
+
wizard: l,
|
|
12
|
+
grid: R,
|
|
13
|
+
fullWidthModal: T,
|
|
14
|
+
isCreating: S,
|
|
15
|
+
isUpdating: V,
|
|
16
|
+
onCreate: v,
|
|
17
|
+
onUpdate: b,
|
|
18
|
+
idField: B = "id",
|
|
19
|
+
formBuilder: W
|
|
20
|
+
}, _) => {
|
|
21
|
+
const [t] = J.useForm(), { t: h } = te(), [k, F] = u(!1), [f, x] = u("new"), [p, y] = u(), [A, g] = u(), [L, j] = u(!1), [E, C] = u(!1), [$, P] = u(!1), U = m(
|
|
22
|
+
async (i) => {
|
|
23
|
+
var n;
|
|
24
|
+
const d = l ? i : await t.validateFields(), a = c.filter((s) => s.type === "color"), o = {};
|
|
25
|
+
for (const s of a) {
|
|
26
|
+
const e = M.getRealName(s.name, "upsertFieldName"), r = t.getFieldValue(e);
|
|
27
|
+
o[e] = typeof r == "string" ? r : (n = r == null ? void 0 : r.toHexString()) == null ? void 0 : n.toUpperCase();
|
|
28
|
+
}
|
|
29
|
+
Object.assign(d, o), p && b ? (await b({
|
|
30
|
+
...d,
|
|
31
|
+
[B]: p[B]
|
|
32
|
+
}), y(void 0)) : !p && v && await v(d), g(void 0), t.resetFields(), F(!1);
|
|
33
|
+
},
|
|
34
|
+
[c, t, B, v, b, p, l]
|
|
35
|
+
), O = m(async (i) => {
|
|
36
|
+
j(i), C(!0);
|
|
37
|
+
}, []), D = m(async () => {
|
|
38
|
+
C(!0);
|
|
39
|
+
}, []), H = m(() => {
|
|
40
|
+
F(!0), x("new"), t.resetFields(), y(void 0), g(void 0);
|
|
41
|
+
}, [t]), I = m(
|
|
42
|
+
async (i, d = !0, a = !1) => {
|
|
43
|
+
try {
|
|
44
|
+
P(!0), F(!0), x(a ? "clone" : "update");
|
|
45
|
+
const o = {};
|
|
46
|
+
for (const n of c) {
|
|
47
|
+
const s = M.getRealName(
|
|
48
|
+
n.name,
|
|
49
|
+
"upsertFieldName"
|
|
50
|
+
), e = i[s];
|
|
51
|
+
if (a && n.type === "image") {
|
|
52
|
+
const r = e;
|
|
53
|
+
try {
|
|
54
|
+
const w = await n.provider.clone(r);
|
|
55
|
+
o[s] = w;
|
|
56
|
+
continue;
|
|
57
|
+
} catch {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
n.type === "date" ? e && (o[s] = oe(e)) : n.type === "select" ? n.multiple && Array.isArray(e) ? o[s] = e.map(
|
|
62
|
+
(r) => r[n.innerFieldId ?? "id"]
|
|
63
|
+
) : e && typeof e == "object" ? o[s] = e[n.innerFieldId ?? "id"] : (e && typeof e == "string" || typeof e == "number") && (o[s] = e) : o[s] = e;
|
|
64
|
+
}
|
|
65
|
+
t.setFieldsValue(o), g(o), d && y(i);
|
|
66
|
+
} finally {
|
|
67
|
+
P(!1);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
[c, t]
|
|
71
|
+
);
|
|
72
|
+
Y(
|
|
73
|
+
_,
|
|
74
|
+
() => ({
|
|
75
|
+
create: H,
|
|
76
|
+
update: I
|
|
77
|
+
}),
|
|
78
|
+
[H, I]
|
|
79
|
+
), Z(() => {
|
|
80
|
+
k && (j(!1), C(!1));
|
|
81
|
+
}, [k]);
|
|
82
|
+
const q = m(async () => {
|
|
83
|
+
try {
|
|
84
|
+
if (f === "clone") {
|
|
85
|
+
const i = l ? p : t.getFieldsValue(), d = c.filter((a) => a.type === "image");
|
|
86
|
+
for (const a of d)
|
|
87
|
+
i[a.name] && a.provider.delete(i[a.name]);
|
|
88
|
+
}
|
|
89
|
+
} finally {
|
|
90
|
+
}
|
|
91
|
+
l || t.resetFields(), g(void 0), y(void 0), F(!1);
|
|
92
|
+
}, [f, l, t, p, c]);
|
|
93
|
+
return /* @__PURE__ */ N(
|
|
94
|
+
K,
|
|
95
|
+
{
|
|
96
|
+
width: T ? "100%" : void 0,
|
|
97
|
+
title: h(f ?? "new"),
|
|
98
|
+
open: k,
|
|
99
|
+
confirmLoading: S || V,
|
|
100
|
+
okText: h("str." + (f === "update" ? "update" : "save")),
|
|
101
|
+
cancelText: h("str.cancel"),
|
|
102
|
+
cancelButtonProps: {
|
|
103
|
+
disabled: E,
|
|
104
|
+
hidden: !!l
|
|
105
|
+
},
|
|
106
|
+
okButtonProps: {
|
|
107
|
+
disabled: L,
|
|
108
|
+
hidden: !!l
|
|
109
|
+
},
|
|
110
|
+
onCancel: q,
|
|
111
|
+
onOk: () => U(),
|
|
112
|
+
destroyOnHidden: !0,
|
|
113
|
+
children: /* @__PURE__ */ G(Q, { spinning: $, children: [
|
|
114
|
+
l ? null : /* @__PURE__ */ N(
|
|
115
|
+
z,
|
|
116
|
+
{
|
|
117
|
+
purpose: f,
|
|
118
|
+
fields: c,
|
|
119
|
+
form: t,
|
|
120
|
+
formBuilder: W,
|
|
121
|
+
grid: R,
|
|
122
|
+
onDeleteFile: D,
|
|
123
|
+
onUploadFile: O
|
|
124
|
+
}
|
|
125
|
+
),
|
|
126
|
+
l && /* @__PURE__ */ N(
|
|
127
|
+
ee,
|
|
128
|
+
{
|
|
129
|
+
submitting: S || V,
|
|
130
|
+
className: "mt-2",
|
|
131
|
+
onSave: U,
|
|
132
|
+
updatingValue: A,
|
|
133
|
+
fields: c,
|
|
134
|
+
onDeleteFile: D,
|
|
135
|
+
onUploadFile: O,
|
|
136
|
+
purpose: f,
|
|
137
|
+
wizard: l
|
|
138
|
+
}
|
|
139
|
+
)
|
|
140
|
+
] })
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
}, fe = X(ne);
|
|
144
|
+
export {
|
|
145
|
+
fe as default
|
|
146
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),d=require("../../common/description/DescList.cjs.js"),f=require("react"),j=require("../../locale/index.cjs.js"),V=require("./CrudViewerUtil.cjs.js"),p=require("../../util/CrudUtil.cjs.js"),v=require("../actions/index.cjs.js");function w({className:c,fields:n,data:e,descListColumn:m={xs:1,md:3,sm:2,lg:4},layout:b,keepEmptyValues:g,inBuiltModalProps:q,...s}){const{t:u}=j.useTranslationLib(),x=f.useMemo(()=>{const o=n.filter(({hidden:r,hideInDescList:i})=>!r&&!i).map((r,i)=>{const C=p.getRealName(r.name);return{label:r.label,noFormatting:!0,value:V.getRendererValueCrudViewer(r)(e==null?void 0:e[C],e,i)}}),l=e?t.jsx(v,{data:e,...s,inBuiltModalProps:q}):void 0;return l&&o.push({label:u("str.action"),value:l}),o},[e,n,u,s]);return e?t.jsx(d,{keepEmptyValues:g,bordered:!0,column:m,className:c,layout:b,list:x}):t.jsx(t.Fragment,{})}exports.CrudDecListView=w;
|