@kingteza/crud-component 1.29.1 → 1.30.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.
|
@@ -27,7 +27,7 @@ export interface InitialCrudField<T> {
|
|
|
27
27
|
updatingValue?: T;
|
|
28
28
|
render?: (value: any, obj: T, index: number) => any;
|
|
29
29
|
required?: boolean;
|
|
30
|
-
updatable?: boolean;
|
|
30
|
+
updatable?: boolean | ((data: T) => boolean);
|
|
31
31
|
fieldTooltip?: string;
|
|
32
32
|
hideInTable?: boolean;
|
|
33
33
|
hideInDescList?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const g=require("react/jsx-runtime"),q=require("antd"),t=require("react"),Z=require("../CrudForm.cjs.js"),z=require("../CrudFormWizard.cjs.js"),ee=require("../../locale/index.cjs.js"),B=require("../../util/CrudUtil.cjs.js"),te=require("dayjs"),r=require("../../util/ObjectUtil.cjs.js"),ae=({fields:l,wizard:i,grid:_,fullWidthModal:A,isCreating:N,isUpdating:M,onCreate:V,onUpdate:h,idField:v="id",formBuilder:L,onValuesChange:U},E)=>{const[n]=q.Form.useForm(),{t:S}=ee.useTranslationLib(),[k,y]=t.useState(!1),[p,R]=t.useState("new"),[f,F]=t.useState(),[$,b]=t.useState(),[G,O]=t.useState(!1),[J,P]=t.useState(!1),[K,w]=t.useState(!1),W=t.useCallback(async s=>{var m;const d=i?s:await n.validateFields(),u=l.filter(a=>a.type==="color"),o={};for(const a of u){const c=B.getRealName(a.name,"upsertFieldName"),e=n.getFieldValue(c);r.setValueByPath(o,c,typeof e=="string"?e:(m=e==null?void 0:e.toHexString())==null?void 0:m.toUpperCase())}Object.assign(d,o),f&&h?(await h({...d,[v]:f[v]}),F(void 0)):!f&&V&&await V(d),b(void 0),x(new Map),n.resetFields(),y(!1)},[l,n,v,V,h,f,i]),D=t.useCallback(async s=>{O(s),P(!0)},[]),H=t.useCallback(async()=>{P(!0)},[]),I=t.useCallback(()=>{y(!0),R("new"),n.resetFields(),F(void 0),b(void 0)},[n]),[C,x]=t.useState(new Map),Q=t.useMemo(()=>C.size===0?l:l.map(s=>typeof s.updatable=="function"?{...s,updatable:C.get(B.getRealName(s.name,"name"))??s.updatable}:s),[l,C]),T=t.useCallback(async(s,d=!0,u=!1)=>{try{w(!0),y(!0),R(u?"clone":"update");const o={};for(const a of l){const c=B.getRealName(a.name,"upsertFieldName"),e=r.getValueByPath(s,c);if(u&&a.type==="image"){const j=e;try{const Y=await a.provider.clone(j);r.setValueByPath(o,c,Y);continue}catch{continue}}a.type==="date"||a.type==="time"?e&&r.setValueByPath(o,c,te(e)):a.type==="select"?a.multiple&&Array.isArray(e)?r.setValueByPath(o,c,e.map(j=>j[a.innerFieldId??"id"])):e&&typeof e=="object"?r.setValueByPath(o,c,e[a.innerFieldId??"id"]):(e&&typeof e=="string"||typeof e=="number")&&r.setValueByPath(o,c,e):r.setValueByPath(o,c,e)}n.setFieldsValue(o);const m=new Map;for(const a of l)typeof a.updatable=="function"&&m.set(B.getRealName(a.name,"name"),a.updatable(s));x(m),b(o),d&&F(s)}finally{w(!1)}},[l,n]);t.useImperativeHandle(E,()=>({create:I,update:T}),[I,T]),t.useEffect(()=>{k&&(O(!1),P(!1))},[k]);const X=t.useCallback(async()=>{x(new Map);try{if(p==="clone"){const s=i?f:n.getFieldsValue(),d=l.filter(u=>u.type==="image");for(const u of d)s[u.name]&&u.provider.delete(s[u.name])}}finally{}i||n.resetFields(),b(void 0),F(void 0),y(!1)},[p,i,n,f,l]);return g.jsx(q.Modal,{width:A?"100%":void 0,title:S("str."+(p??"new")),open:k,confirmLoading:N||M,okText:S("str."+(p==="update"?"update":"save")),cancelText:S("str.cancel"),cancelButtonProps:{disabled:J,hidden:!!i},okButtonProps:{disabled:G,hidden:!!i},onCancel:X,onOk:()=>W(),destroyOnHidden:!0,children:g.jsxs(q.Spin,{spinning:K,children:[i?null:g.jsx(Z.CrudForm,{purpose:p,fields:Q,form:n,formBuilder:L,grid:_,onDeleteFile:H,onUploadFile:D,onValuesChange:U}),i&&g.jsx(z,{submitting:N||M,className:"mt-2",onSave:W,updatingValue:$,fields:l,onDeleteFile:H,onUploadFile:D,purpose:p,wizard:i,onValuesChange:U})]})})},se=t.forwardRef(ae);module.exports=se;
|
|
@@ -1,154 +1,171 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { Form as
|
|
3
|
-
import { forwardRef as
|
|
4
|
-
import { CrudForm as
|
|
5
|
-
import
|
|
6
|
-
import { useTranslationLib as
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import { setValueByPath as
|
|
10
|
-
const
|
|
11
|
-
fields:
|
|
12
|
-
wizard:
|
|
13
|
-
grid:
|
|
14
|
-
fullWidthModal:
|
|
15
|
-
isCreating:
|
|
16
|
-
isUpdating:
|
|
17
|
-
onCreate:
|
|
18
|
-
onUpdate:
|
|
1
|
+
import { jsx as x, jsxs as Z } from "react/jsx-runtime";
|
|
2
|
+
import { Form as z, Modal as ee, Spin as te } from "antd";
|
|
3
|
+
import { forwardRef as oe, useState as c, useCallback as m, useMemo as ae, useImperativeHandle as ne, useEffect as le } from "react";
|
|
4
|
+
import { CrudForm as se } from "../CrudForm.es.js";
|
|
5
|
+
import ie from "../CrudFormWizard.es.js";
|
|
6
|
+
import { useTranslationLib as re } from "../../locale/index.es.js";
|
|
7
|
+
import v from "../../util/CrudUtil.es.js";
|
|
8
|
+
import ce from "dayjs";
|
|
9
|
+
import { setValueByPath as d, getValueByPath as ue } from "../../util/ObjectUtil.es.js";
|
|
10
|
+
const de = ({
|
|
11
|
+
fields: n,
|
|
12
|
+
wizard: s,
|
|
13
|
+
grid: A,
|
|
14
|
+
fullWidthModal: L,
|
|
15
|
+
isCreating: C,
|
|
16
|
+
isUpdating: j,
|
|
17
|
+
onCreate: B,
|
|
18
|
+
onUpdate: V,
|
|
19
19
|
idField: h = "id",
|
|
20
|
-
formBuilder:
|
|
21
|
-
onValuesChange:
|
|
22
|
-
},
|
|
23
|
-
const [
|
|
24
|
-
async (
|
|
25
|
-
var
|
|
26
|
-
const
|
|
27
|
-
for (const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
typeof
|
|
20
|
+
formBuilder: E,
|
|
21
|
+
onValuesChange: R
|
|
22
|
+
}, $) => {
|
|
23
|
+
const [a] = z.useForm(), { t: N } = re(), [k, y] = c(!1), [p, w] = c("new"), [f, g] = c(), [q, b] = c(), [G, O] = c(!1), [J, M] = c(!1), [K, W] = c(!1), D = m(
|
|
24
|
+
async (o) => {
|
|
25
|
+
var F;
|
|
26
|
+
const u = s ? o : await a.validateFields(), i = n.filter((t) => t.type === "color"), l = {};
|
|
27
|
+
for (const t of i) {
|
|
28
|
+
const r = v.getRealName(t.name, "upsertFieldName"), e = a.getFieldValue(r);
|
|
29
|
+
d(
|
|
30
|
+
l,
|
|
31
|
+
r,
|
|
32
|
+
typeof e == "string" ? e : (F = e == null ? void 0 : e.toHexString()) == null ? void 0 : F.toUpperCase()
|
|
33
33
|
);
|
|
34
34
|
}
|
|
35
|
-
Object.assign(
|
|
36
|
-
...
|
|
37
|
-
[h]:
|
|
38
|
-
}), g(void 0)) : !
|
|
35
|
+
Object.assign(u, l), f && V ? (await V({
|
|
36
|
+
...u,
|
|
37
|
+
[h]: f[h]
|
|
38
|
+
}), g(void 0)) : !f && B && await B(u), b(void 0), S(/* @__PURE__ */ new Map()), a.resetFields(), y(!1);
|
|
39
39
|
},
|
|
40
|
-
[
|
|
41
|
-
), H =
|
|
42
|
-
|
|
43
|
-
}, []), I =
|
|
44
|
-
|
|
45
|
-
}, []),
|
|
46
|
-
y(!0),
|
|
47
|
-
}, [
|
|
48
|
-
|
|
40
|
+
[n, a, h, B, V, f, s]
|
|
41
|
+
), H = m(async (o) => {
|
|
42
|
+
O(o), M(!0);
|
|
43
|
+
}, []), I = m(async () => {
|
|
44
|
+
M(!0);
|
|
45
|
+
}, []), T = m(() => {
|
|
46
|
+
y(!0), w("new"), a.resetFields(), g(void 0), b(void 0);
|
|
47
|
+
}, [a]), [P, S] = c(/* @__PURE__ */ new Map()), Q = ae(() => P.size === 0 ? n : n.map((o) => typeof o.updatable == "function" ? {
|
|
48
|
+
...o,
|
|
49
|
+
updatable: P.get(v.getRealName(o.name, "name")) ?? o.updatable
|
|
50
|
+
} : o), [n, P]), _ = m(
|
|
51
|
+
async (o, u = !0, i = !1) => {
|
|
49
52
|
try {
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
for (const
|
|
53
|
-
const
|
|
54
|
-
|
|
53
|
+
W(!0), y(!0), w(i ? "clone" : "update");
|
|
54
|
+
const l = {};
|
|
55
|
+
for (const t of n) {
|
|
56
|
+
const r = v.getRealName(
|
|
57
|
+
t.name,
|
|
55
58
|
"upsertFieldName"
|
|
56
|
-
), e =
|
|
57
|
-
if (
|
|
58
|
-
const
|
|
59
|
+
), e = ue(o, r);
|
|
60
|
+
if (i && t.type === "image") {
|
|
61
|
+
const U = e;
|
|
59
62
|
try {
|
|
60
|
-
const
|
|
61
|
-
|
|
63
|
+
const Y = await t.provider.clone(U);
|
|
64
|
+
d(l, r, Y);
|
|
62
65
|
continue;
|
|
63
66
|
} catch {
|
|
64
67
|
continue;
|
|
65
68
|
}
|
|
66
69
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
t.type === "date" || t.type === "time" ? e && d(l, r, ce(e)) : t.type === "select" ? t.multiple && Array.isArray(e) ? d(
|
|
71
|
+
l,
|
|
72
|
+
r,
|
|
73
|
+
e.map((U) => U[t.innerFieldId ?? "id"])
|
|
74
|
+
) : e && typeof e == "object" ? d(
|
|
75
|
+
l,
|
|
76
|
+
r,
|
|
77
|
+
e[t.innerFieldId ?? "id"]
|
|
78
|
+
) : (e && typeof e == "string" || typeof e == "number") && d(l, r, e) : d(l, r, e);
|
|
70
79
|
}
|
|
71
|
-
|
|
80
|
+
a.setFieldsValue(l);
|
|
81
|
+
const F = /* @__PURE__ */ new Map();
|
|
82
|
+
for (const t of n)
|
|
83
|
+
typeof t.updatable == "function" && F.set(
|
|
84
|
+
v.getRealName(t.name, "name"),
|
|
85
|
+
t.updatable(o)
|
|
86
|
+
);
|
|
87
|
+
S(F), b(l), u && g(o);
|
|
72
88
|
} finally {
|
|
73
|
-
|
|
89
|
+
W(!1);
|
|
74
90
|
}
|
|
75
91
|
},
|
|
76
|
-
[
|
|
92
|
+
[n, a]
|
|
77
93
|
);
|
|
78
|
-
|
|
79
|
-
|
|
94
|
+
ne(
|
|
95
|
+
$,
|
|
80
96
|
() => ({
|
|
81
|
-
create:
|
|
82
|
-
update:
|
|
97
|
+
create: T,
|
|
98
|
+
update: _
|
|
83
99
|
}),
|
|
84
|
-
[
|
|
85
|
-
),
|
|
86
|
-
|
|
87
|
-
}, [
|
|
88
|
-
const
|
|
100
|
+
[T, _]
|
|
101
|
+
), le(() => {
|
|
102
|
+
k && (O(!1), M(!1));
|
|
103
|
+
}, [k]);
|
|
104
|
+
const X = m(async () => {
|
|
105
|
+
S(/* @__PURE__ */ new Map());
|
|
89
106
|
try {
|
|
90
|
-
if (
|
|
91
|
-
const
|
|
92
|
-
for (const
|
|
93
|
-
i
|
|
107
|
+
if (p === "clone") {
|
|
108
|
+
const o = s ? f : a.getFieldsValue(), u = n.filter((i) => i.type === "image");
|
|
109
|
+
for (const i of u)
|
|
110
|
+
o[i.name] && i.provider.delete(o[i.name]);
|
|
94
111
|
}
|
|
95
112
|
} finally {
|
|
96
113
|
}
|
|
97
|
-
|
|
98
|
-
}, [
|
|
99
|
-
return /* @__PURE__ */
|
|
100
|
-
|
|
114
|
+
s || a.resetFields(), b(void 0), g(void 0), y(!1);
|
|
115
|
+
}, [p, s, a, f, n]);
|
|
116
|
+
return /* @__PURE__ */ x(
|
|
117
|
+
ee,
|
|
101
118
|
{
|
|
102
|
-
width:
|
|
103
|
-
title:
|
|
104
|
-
open:
|
|
105
|
-
confirmLoading:
|
|
106
|
-
okText:
|
|
107
|
-
cancelText:
|
|
119
|
+
width: L ? "100%" : void 0,
|
|
120
|
+
title: N("str." + (p ?? "new")),
|
|
121
|
+
open: k,
|
|
122
|
+
confirmLoading: C || j,
|
|
123
|
+
okText: N("str." + (p === "update" ? "update" : "save")),
|
|
124
|
+
cancelText: N("str.cancel"),
|
|
108
125
|
cancelButtonProps: {
|
|
109
|
-
disabled:
|
|
110
|
-
hidden: !!
|
|
126
|
+
disabled: J,
|
|
127
|
+
hidden: !!s
|
|
111
128
|
},
|
|
112
129
|
okButtonProps: {
|
|
113
|
-
disabled:
|
|
114
|
-
hidden: !!
|
|
130
|
+
disabled: G,
|
|
131
|
+
hidden: !!s
|
|
115
132
|
},
|
|
116
|
-
onCancel:
|
|
133
|
+
onCancel: X,
|
|
117
134
|
onOk: () => D(),
|
|
118
135
|
destroyOnHidden: !0,
|
|
119
|
-
children: /* @__PURE__ */
|
|
120
|
-
|
|
121
|
-
|
|
136
|
+
children: /* @__PURE__ */ Z(te, { spinning: K, children: [
|
|
137
|
+
s ? null : /* @__PURE__ */ x(
|
|
138
|
+
se,
|
|
122
139
|
{
|
|
123
|
-
purpose:
|
|
124
|
-
fields:
|
|
125
|
-
form:
|
|
126
|
-
formBuilder:
|
|
127
|
-
grid:
|
|
140
|
+
purpose: p,
|
|
141
|
+
fields: Q,
|
|
142
|
+
form: a,
|
|
143
|
+
formBuilder: E,
|
|
144
|
+
grid: A,
|
|
128
145
|
onDeleteFile: I,
|
|
129
146
|
onUploadFile: H,
|
|
130
|
-
onValuesChange:
|
|
147
|
+
onValuesChange: R
|
|
131
148
|
}
|
|
132
149
|
),
|
|
133
|
-
|
|
134
|
-
|
|
150
|
+
s && /* @__PURE__ */ x(
|
|
151
|
+
ie,
|
|
135
152
|
{
|
|
136
|
-
submitting:
|
|
153
|
+
submitting: C || j,
|
|
137
154
|
className: "mt-2",
|
|
138
155
|
onSave: D,
|
|
139
|
-
updatingValue:
|
|
140
|
-
fields:
|
|
156
|
+
updatingValue: q,
|
|
157
|
+
fields: n,
|
|
141
158
|
onDeleteFile: I,
|
|
142
159
|
onUploadFile: H,
|
|
143
|
-
purpose:
|
|
144
|
-
wizard:
|
|
145
|
-
onValuesChange:
|
|
160
|
+
purpose: p,
|
|
161
|
+
wizard: s,
|
|
162
|
+
onValuesChange: R
|
|
146
163
|
}
|
|
147
164
|
)
|
|
148
165
|
] })
|
|
149
166
|
}
|
|
150
167
|
);
|
|
151
|
-
},
|
|
168
|
+
}, Ve = oe(de);
|
|
152
169
|
export {
|
|
153
|
-
|
|
170
|
+
Ve as default
|
|
154
171
|
};
|