@kingteza/crud-component 1.0.64 → 1.0.66
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/App.d.ts +126 -0
- 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 +88 -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 +39 -27
- 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
package/App.d.ts
CHANGED
|
@@ -23,3 +23,129 @@ export type Purchase = {
|
|
|
23
23
|
};
|
|
24
24
|
declare function App(): import("react/jsx-runtime").JSX.Element;
|
|
25
25
|
export default App;
|
|
26
|
+
export declare const useWorkShiftCrudComponentProps: () => {
|
|
27
|
+
onCreate: (e: any) => Promise<void>;
|
|
28
|
+
onUpdate: (e: any) => Promise<void>;
|
|
29
|
+
onDelete: (e: any) => Promise<void>;
|
|
30
|
+
isCreating: boolean;
|
|
31
|
+
isUpdating: boolean;
|
|
32
|
+
isDeleting: boolean;
|
|
33
|
+
fields: ({
|
|
34
|
+
grid: {
|
|
35
|
+
md: number;
|
|
36
|
+
xs: number;
|
|
37
|
+
};
|
|
38
|
+
name: string;
|
|
39
|
+
label: string;
|
|
40
|
+
type: string;
|
|
41
|
+
required: boolean;
|
|
42
|
+
hideInTable?: undefined;
|
|
43
|
+
format?: undefined;
|
|
44
|
+
use12Hours?: undefined;
|
|
45
|
+
readonly?: undefined;
|
|
46
|
+
int?: undefined;
|
|
47
|
+
max?: undefined;
|
|
48
|
+
} | {
|
|
49
|
+
grid: {
|
|
50
|
+
md: number;
|
|
51
|
+
xs: number;
|
|
52
|
+
};
|
|
53
|
+
name: string;
|
|
54
|
+
label: string;
|
|
55
|
+
type: string;
|
|
56
|
+
hideInTable: boolean;
|
|
57
|
+
required?: undefined;
|
|
58
|
+
format?: undefined;
|
|
59
|
+
use12Hours?: undefined;
|
|
60
|
+
readonly?: undefined;
|
|
61
|
+
int?: undefined;
|
|
62
|
+
max?: undefined;
|
|
63
|
+
} | {
|
|
64
|
+
grid: {
|
|
65
|
+
md: number;
|
|
66
|
+
xs: number;
|
|
67
|
+
};
|
|
68
|
+
name: string;
|
|
69
|
+
label: string;
|
|
70
|
+
type: string;
|
|
71
|
+
format: string;
|
|
72
|
+
use12Hours: boolean;
|
|
73
|
+
required: boolean;
|
|
74
|
+
hideInTable?: undefined;
|
|
75
|
+
readonly?: undefined;
|
|
76
|
+
int?: undefined;
|
|
77
|
+
max?: undefined;
|
|
78
|
+
} | {
|
|
79
|
+
grid: {
|
|
80
|
+
md: number;
|
|
81
|
+
xs: number;
|
|
82
|
+
};
|
|
83
|
+
name: string;
|
|
84
|
+
label: string;
|
|
85
|
+
type: string;
|
|
86
|
+
format: string;
|
|
87
|
+
use12Hours: boolean;
|
|
88
|
+
readonly: boolean;
|
|
89
|
+
required?: undefined;
|
|
90
|
+
hideInTable?: undefined;
|
|
91
|
+
int?: undefined;
|
|
92
|
+
max?: undefined;
|
|
93
|
+
} | {
|
|
94
|
+
grid: {
|
|
95
|
+
md: number;
|
|
96
|
+
xs: number;
|
|
97
|
+
};
|
|
98
|
+
name: string;
|
|
99
|
+
label: string;
|
|
100
|
+
type: string;
|
|
101
|
+
int: boolean;
|
|
102
|
+
required: boolean;
|
|
103
|
+
hideInTable: boolean;
|
|
104
|
+
format?: undefined;
|
|
105
|
+
use12Hours?: undefined;
|
|
106
|
+
readonly?: undefined;
|
|
107
|
+
max?: undefined;
|
|
108
|
+
} | {
|
|
109
|
+
grid: {
|
|
110
|
+
md: number;
|
|
111
|
+
xs: number;
|
|
112
|
+
};
|
|
113
|
+
name: string;
|
|
114
|
+
label: string;
|
|
115
|
+
type: string;
|
|
116
|
+
int: boolean;
|
|
117
|
+
required: boolean;
|
|
118
|
+
hideInTable: boolean;
|
|
119
|
+
max: number;
|
|
120
|
+
format?: undefined;
|
|
121
|
+
use12Hours?: undefined;
|
|
122
|
+
readonly?: undefined;
|
|
123
|
+
} | {
|
|
124
|
+
name: string;
|
|
125
|
+
label: string;
|
|
126
|
+
type: string;
|
|
127
|
+
int: boolean;
|
|
128
|
+
required: boolean;
|
|
129
|
+
grid?: undefined;
|
|
130
|
+
hideInTable?: undefined;
|
|
131
|
+
format?: undefined;
|
|
132
|
+
use12Hours?: undefined;
|
|
133
|
+
readonly?: undefined;
|
|
134
|
+
max?: undefined;
|
|
135
|
+
} | {
|
|
136
|
+
grid: {
|
|
137
|
+
md: number;
|
|
138
|
+
xs: number;
|
|
139
|
+
};
|
|
140
|
+
name: string;
|
|
141
|
+
label: string;
|
|
142
|
+
type: string;
|
|
143
|
+
int: boolean;
|
|
144
|
+
required: boolean;
|
|
145
|
+
hideInTable?: undefined;
|
|
146
|
+
format?: undefined;
|
|
147
|
+
use12Hours?: undefined;
|
|
148
|
+
readonly?: undefined;
|
|
149
|
+
max?: undefined;
|
|
150
|
+
})[];
|
|
151
|
+
};
|
|
@@ -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"),Y=require("react"),A=require("../../common/button/CloneButtonTable.cjs.js"),H=require("../../common/button/DeleteButtonTable.cjs.js"),V=require("../../common/button/ExportButton.cjs.js"),s=require("../../common/button/HideButtonTable.cjs.js"),c=require("../../common/button/UpdateButtonTable.cjs.js"),r=require("../modal/index.cjs.js");function F({data:b,idField:j="id",extraAction:T,onUpdate:g,onClickUpdate:m,onClickClone:x,onDelete:h,onHide:z,onExport:E,isHiding:J,isDeleting:K,confirmHiding:Z,confirmDeleting:_,closeViewOnClickUpdate:$,recentUpdateOrDeleteId:L,setRecentUpdateOrDeleteId:q,setOpenView:G,inBuiltModalProps:f}){var S;const y=T==null?void 0:T(b),N=Y.useRef(null),Q=Y.useCallback((u,w=!0,W=!1)=>{var X;q==null||q(u[j]),f?(X=N.current)==null||X.update(u,w,W):W?x==null||x(u):m==null||m(u),$&&(G==null||G(void 0))},[f,m]);return console.log({onUpdate:g,onClickUpdate:m,onClickClone:x,onDelete:h}),(Array.isArray(y)?(S=y==null?void 0:y.filter(Boolean))!=null&&S.length:y)||g||m||f!=null&&f.onUpdate||x||f!=null&&f.onCreate||h||E||z?v.jsxs(v.Fragment,{children:[f&&v.jsx(r,{ref:N,...f}),y,(g||m||(f==null?void 0:f.onUpdate))&&v.jsx(c,{value:b,onClick:u=>Q(u)}),(x||(f==null?void 0:f.onCreate))&&v.jsx(A,{value:b,onClick:u=>Q(u,!1,!0)}),E&&v.jsx(V.ExportButton,{value:b,onClick:async u=>await E(u)}),z&&v.jsx(s,{value:b,disabled:J,shouldConfirm:Z,loading:J&&b[j]===L,onClick:async u=>{q==null||q(u[j]),await z({[j]:u[j]})}}),h&&v.jsx(H,{value:b,disabled:K,shouldConfirm:_,loading:K&&b[j]===L,onClick:async u=>{q==null||q(u[j]),await h({[j]:u[j]})}})]}):void 0}module.exports=F;
|
|
@@ -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,88 @@
|
|
|
1
|
+
import { jsxs as E, Fragment as H, jsx as j } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as x, useCallback as V } from "react";
|
|
3
|
+
import F from "../../common/button/CloneButtonTable.es.js";
|
|
4
|
+
import k from "../../common/button/DeleteButtonTable.es.js";
|
|
5
|
+
import { ExportButton as r } from "../../common/button/ExportButton.es.js";
|
|
6
|
+
import C from "../../common/button/HideButtonTable.es.js";
|
|
7
|
+
import R from "../../common/button/UpdateButtonTable.es.js";
|
|
8
|
+
import I from "../modal/index.es.js";
|
|
9
|
+
function a({
|
|
10
|
+
data: y,
|
|
11
|
+
idField: b = "id",
|
|
12
|
+
extraAction: q,
|
|
13
|
+
onUpdate: z,
|
|
14
|
+
onClickUpdate: h,
|
|
15
|
+
onClickClone: T,
|
|
16
|
+
onDelete: u,
|
|
17
|
+
onHide: G,
|
|
18
|
+
onExport: J,
|
|
19
|
+
isHiding: L,
|
|
20
|
+
isDeleting: N,
|
|
21
|
+
confirmHiding: _,
|
|
22
|
+
confirmDeleting: $,
|
|
23
|
+
closeViewOnClickUpdate: w,
|
|
24
|
+
recentUpdateOrDeleteId: Q,
|
|
25
|
+
setRecentUpdateOrDeleteId: v,
|
|
26
|
+
setOpenView: K,
|
|
27
|
+
inBuiltModalProps: f
|
|
28
|
+
}) {
|
|
29
|
+
var X;
|
|
30
|
+
const g = q == null ? void 0 : q(y), S = x(null), W = V(
|
|
31
|
+
(m, A = !0, Y = !1) => {
|
|
32
|
+
var Z;
|
|
33
|
+
v == null || v(m[b]), f ? (Z = S.current) == null || Z.update(m, A, Y) : Y ? T == null || T(m) : h == null || h(m), w && (K == null || K(void 0));
|
|
34
|
+
},
|
|
35
|
+
[f, h]
|
|
36
|
+
);
|
|
37
|
+
return console.log({
|
|
38
|
+
onUpdate: z,
|
|
39
|
+
onClickUpdate: h,
|
|
40
|
+
onClickClone: T,
|
|
41
|
+
onDelete: u
|
|
42
|
+
}), (Array.isArray(g) ? (X = g == null ? void 0 : g.filter(Boolean)) != null && X.length : g) || z || h || f != null && f.onUpdate || T || f != null && f.onCreate || u || J || G ? /* @__PURE__ */ E(H, { children: [
|
|
43
|
+
f && /* @__PURE__ */ j(I, { ref: S, ...f }),
|
|
44
|
+
g,
|
|
45
|
+
(z || h || (f == null ? void 0 : f.onUpdate)) && /* @__PURE__ */ j(R, { value: y, onClick: (m) => W(m) }),
|
|
46
|
+
(T || (f == null ? void 0 : f.onCreate)) && /* @__PURE__ */ j(
|
|
47
|
+
F,
|
|
48
|
+
{
|
|
49
|
+
value: y,
|
|
50
|
+
onClick: (m) => W(m, !1, !0)
|
|
51
|
+
}
|
|
52
|
+
),
|
|
53
|
+
J && /* @__PURE__ */ j(
|
|
54
|
+
r,
|
|
55
|
+
{
|
|
56
|
+
value: y,
|
|
57
|
+
onClick: async (m) => await J(m)
|
|
58
|
+
}
|
|
59
|
+
),
|
|
60
|
+
G && /* @__PURE__ */ j(
|
|
61
|
+
C,
|
|
62
|
+
{
|
|
63
|
+
value: y,
|
|
64
|
+
disabled: L,
|
|
65
|
+
shouldConfirm: _,
|
|
66
|
+
loading: L && y[b] === Q,
|
|
67
|
+
onClick: async (m) => {
|
|
68
|
+
v == null || v(m[b]), await G({ [b]: m[b] });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
),
|
|
72
|
+
u && /* @__PURE__ */ j(
|
|
73
|
+
k,
|
|
74
|
+
{
|
|
75
|
+
value: y,
|
|
76
|
+
disabled: N,
|
|
77
|
+
shouldConfirm: $,
|
|
78
|
+
loading: N && y[b] === Q,
|
|
79
|
+
onClick: async (m) => {
|
|
80
|
+
v == null || v(m[b]), await u({ [b]: m[b] });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
] }) : void 0;
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
a as default
|
|
88
|
+
};
|
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 n;const d=l?c:await s.validateFields(),i=u.filter(a=>a.type==="color"),o={};for(const a of i){const e=H.getRealName(a.name,"upsertFieldName"),r=s.getFieldValue(e);o[e]=typeof r=="string"?r:(n=r==null?void 0:r.toHexString())==null?void 0:n.toUpperCase()}Object.assign(d,o),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 o={};for(const n of u){const a=H.getRealName(n.name,"upsertFieldName"),e=c[a];if(i&&n.type==="image"){const r=e;try{const w=await n.provider.clone(r);o[a]=w;continue}catch{continue}}n.type==="date"||n.type==="time"?e&&(o[a]=Q(e)):n.type==="select"?n.multiple&&Array.isArray(e)?o[a]=e.map(r=>r[n.innerFieldId??"id"]):e&&typeof e=="object"?o[a]=e[n.innerFieldId??"id"]:(e&&typeof e=="string"||typeof e=="number")&&(o[a]=e):o[a]=e}s.setFieldsValue(o),y(o),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;
|