@kingteza/crud-component 1.44.1 → 1.45.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/_virtual/index.cjs.js +1 -1
- package/dist/_virtual/index.cjs2.js +1 -1
- package/dist/_virtual/index.cjs3.js +1 -1
- package/dist/_virtual/index.es.js +2 -5
- package/dist/_virtual/index.es2.js +5 -5
- package/dist/_virtual/index.es3.js +5 -2
- package/dist/common/picker/ImagePicker.cjs.js +1 -1
- package/dist/common/picker/ImagePicker.d.ts +6 -2
- package/dist/common/picker/ImagePicker.es.js +278 -232
- package/dist/crud/ImageCrudField.cjs.js +1 -1
- package/dist/crud/ImageCrudField.d.ts +3 -1
- package/dist/crud/ImageCrudField.es.js +133 -96
- package/dist/crud/modal/index.cjs.js +1 -1
- package/dist/crud/modal/index.es.js +120 -109
- package/dist/node_modules/.pnpm/input-format@0.3.14_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/input-format/modules/react/Input.cjs.js +1 -1
- package/dist/node_modules/.pnpm/input-format@0.3.14_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/input-format/modules/react/Input.es.js +1 -1
- package/dist/node_modules/.pnpm/prop-types@15.8.1/node_modules/prop-types/index.cjs.js +1 -1
- package/dist/node_modules/.pnpm/prop-types@15.8.1/node_modules/prop-types/index.es.js +1 -1
- package/dist/node_modules/.pnpm/react-phone-number-input@3.4.14_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-phone-number-input/modules/CountryIcon.cjs.js +1 -1
- package/dist/node_modules/.pnpm/react-phone-number-input@3.4.14_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-phone-number-input/modules/CountryIcon.es.js +2 -2
- package/dist/node_modules/.pnpm/react-phone-number-input@3.4.14_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-phone-number-input/modules/CountrySelect.cjs.js +1 -1
- package/dist/node_modules/.pnpm/react-phone-number-input@3.4.14_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-phone-number-input/modules/CountrySelect.es.js +2 -2
- package/dist/node_modules/.pnpm/react-phone-number-input@3.4.14_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-phone-number-input/modules/Flag.cjs.js +1 -1
- package/dist/node_modules/.pnpm/react-phone-number-input@3.4.14_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-phone-number-input/modules/Flag.es.js +2 -2
- package/dist/node_modules/.pnpm/react-phone-number-input@3.4.14_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-phone-number-input/modules/InputBasic.cjs.js +1 -1
- package/dist/node_modules/.pnpm/react-phone-number-input@3.4.14_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-phone-number-input/modules/InputBasic.es.js +1 -1
- package/dist/node_modules/.pnpm/react-phone-number-input@3.4.14_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-phone-number-input/modules/InputSmart.cjs.js +1 -1
- package/dist/node_modules/.pnpm/react-phone-number-input@3.4.14_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-phone-number-input/modules/InputSmart.es.js +1 -1
- package/dist/node_modules/.pnpm/react-phone-number-input@3.4.14_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-phone-number-input/modules/InternationalIcon.cjs.js +1 -1
- package/dist/node_modules/.pnpm/react-phone-number-input@3.4.14_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-phone-number-input/modules/InternationalIcon.es.js +1 -1
- package/dist/node_modules/.pnpm/react-phone-number-input@3.4.14_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-phone-number-input/modules/PhoneInputWithCountry.cjs.js +1 -1
- package/dist/node_modules/.pnpm/react-phone-number-input@3.4.14_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-phone-number-input/modules/PhoneInputWithCountry.es.js +2 -2
- package/dist/node_modules/.pnpm/react-phone-number-input@3.4.14_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-phone-number-input/modules/PropTypes.cjs.js +1 -1
- package/dist/node_modules/.pnpm/react-phone-number-input@3.4.14_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-phone-number-input/modules/PropTypes.es.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var T=Object.defineProperty;var W=(s,e,t)=>e in s?T(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var q=(s,e,t)=>W(s,typeof e!="symbol"?e+"":e,t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("react/jsx-runtime"),G=require("@ant-design/icons"),F=require("antd"),x=require("path-browserify"),d=require("react"),J=require("../util/NumberUtil.cjs.js"),K=require("../util/ValidationUtil.cjs.js"),L=require("uuid"),Q=require("../common/picker/ImagePicker.cjs.js"),X=require("../util/ImageUtil.cjs.js");class N{}class Y extends N{constructor(t="",l=""){super();q(this,"rootPath");q(this,"subPath");this.rootPath=t,this.subPath=l}cloneFilePath(t){const l=x.parse(t),a=`${l.name}_cloned_${J.default.randInt(1e5)}`;return x.format({dir:l.dir,ext:l.ext,name:a})}generateFileName(t){return`${t.split(".")[0]}_${L.v4().replace("-","")}`}}function Z({formLayoutProps:s,name:e,label:t,required:l,provider:a,onUploading:i,aspectRatio:$,onRemoved:m,fieldClassName:A,hideLabel:k=!1,listType:C,fieldHelper:O,showSkipCropButton:S=!1,skipCrop:_=!1,skipResize:B=!1,asyncUpload:M=!1,maxCount:h=1},z){const f=F.Form.useFormInstance(),o=e,y=F.Form.useWatch(o,f),D=d.useCallback(r=>a.getRealUrl(r),[a]),g=d.useCallback(async(r,P)=>{if(P){i==null||i(!0);try{const u=r.name,c=u.split("."),p=c[c.length-1],I=a.generateFileName(u),w=`${await a.getInitialPath()}/${I}.${p}`,j=await a.upload(r,w),V=f.getFieldValue(o);if(h>1){const H=Array.isArray(V)?V:V?[V]:[];f.setFieldValue(o,[...H,j].filter(Boolean))}else f.setFieldValue(o,j);return j}finally{i==null||i(!1)}}else{const u=f.getFieldValue(o);if(h>1){const c=r.response??(typeof r.uid=="string"?r.uid:void 0);if(!c)return;await a.delete(c),m==null||m();const I=(Array.isArray(u)?u:u?[u]:[]).filter(w=>w!==c);f.setFieldValue(o,I.length?I:null)}else{const c=await a.delete(u);m==null||m(),c&&f.setFieldValue(o,null)}}},[f,h,o,m,i,a]);d.useImperativeHandle(z,()=>({async uploadBlob(r,P){const u=await X.getBase64(r),c={name:P,uid:P+Math.random().toString(36).substring(2,15),url:u,originFileObj:r};await g(c,!0)}}),[g]);const E=d.useMemo(()=>y?(Array.isArray(y),y):h>1?[]:void 0,[y,h]);return n.jsxs(F.Form.Item,{rules:l?K.required(t):[],label:k?null:t,required:l,name:o,help:O,...s,className:A,children:[n.jsx(Q.default,{noStyle:!0,asyncUpload:M,listType:C,aspectRatio:$,values:E,getRealUrl:D,onRemove:r=>{r&&g(r,!1)},onAdd:async r=>{if(r)return g(r,!0)},className:A,showSkipCropButton:S,skipCrop:_,skipResize:B,maxCount:h}),n.jsx(F.Input,{hidden:!0})]})}const U=d.forwardRef(Z),R=({provider:s,value:e})=>{const[t,l]=d.useState([]);return d.useEffect(()=>{if(!e){l([]);return}const a=Array.isArray(e)?e:[e];Promise.all(a.filter(Boolean).map(i=>s.getRealUrl(i))).then(l)},[s,e]),t.length?n.jsx(n.Fragment,{children:t.map(a=>n.jsx(b,{url:a},a))}):n.jsx(n.Fragment,{})},b=({url:s})=>n.jsx(F.Avatar,{className:"p-0",children:n.jsx(F.Image,{className:"m-0 p-0 position-relative",src:s,preview:{mask:n.jsx(G.EyeOutlined,{})}})});exports.FileDownloadProvider=N;exports.FileUploadProvider=Y;exports.ImageCellValue=b;exports.ImageCrudCellValue=R;exports.default=U;
|
|
@@ -10,6 +10,8 @@ export interface _ImageCrudField<T> extends InitialCrudField<T> {
|
|
|
10
10
|
fieldClassName?: string;
|
|
11
11
|
listType?: UploadListType;
|
|
12
12
|
showSkipCropButton?: boolean;
|
|
13
|
+
/** When true, skips the crop modal entirely and uploads the original image. */
|
|
14
|
+
skipCrop?: boolean;
|
|
13
15
|
skipResize?: boolean;
|
|
14
16
|
asyncUpload?: boolean;
|
|
15
17
|
maxCount?: number;
|
|
@@ -40,7 +42,7 @@ declare const ImageCrudField: <T>(p: Readonly<_ImageCrudField<T>> & {
|
|
|
40
42
|
}) => ReactElement;
|
|
41
43
|
export default ImageCrudField;
|
|
42
44
|
export declare const ImageCrudCellValue: FC<{
|
|
43
|
-
value: string;
|
|
45
|
+
value: string | string[];
|
|
44
46
|
provider: FileDownloadProvider;
|
|
45
47
|
}>;
|
|
46
48
|
export declare const ImageCellValue: FC<{
|
|
@@ -1,139 +1,176 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { jsx as
|
|
5
|
-
import { EyeOutlined as
|
|
6
|
-
import { Avatar as
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import { v4 as
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
class
|
|
1
|
+
var W = Object.defineProperty;
|
|
2
|
+
var q = (s, e, t) => e in s ? W(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
+
var w = (s, e, t) => q(s, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { jsx as o, Fragment as $, jsxs as G } from "react/jsx-runtime";
|
|
5
|
+
import { EyeOutlined as J } from "@ant-design/icons";
|
|
6
|
+
import { Avatar as K, Image as L, Form as I, Input as Q } from "antd";
|
|
7
|
+
import b from "path-browserify";
|
|
8
|
+
import T, { useState as X, useEffect as Y, useCallback as k, useImperativeHandle as Z, useMemo as U } from "react";
|
|
9
|
+
import R from "../util/NumberUtil.es.js";
|
|
10
|
+
import v from "../util/ValidationUtil.es.js";
|
|
11
|
+
import { v4 as ee } from "uuid";
|
|
12
|
+
import te from "../common/picker/ImagePicker.es.js";
|
|
13
|
+
import ae from "../util/ImageUtil.es.js";
|
|
14
|
+
class re {
|
|
15
15
|
}
|
|
16
|
-
class
|
|
17
|
-
constructor(t = "",
|
|
16
|
+
class pe extends re {
|
|
17
|
+
constructor(t = "", l = "") {
|
|
18
18
|
super();
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.rootPath = t, this.subPath =
|
|
19
|
+
w(this, "rootPath");
|
|
20
|
+
w(this, "subPath");
|
|
21
|
+
this.rootPath = t, this.subPath = l;
|
|
22
22
|
}
|
|
23
23
|
cloneFilePath(t) {
|
|
24
|
-
const
|
|
25
|
-
return
|
|
26
|
-
dir:
|
|
27
|
-
ext:
|
|
28
|
-
name:
|
|
24
|
+
const l = b.parse(t), a = `${l.name}_cloned_${R.randInt(1e5)}`;
|
|
25
|
+
return b.format({
|
|
26
|
+
dir: l.dir,
|
|
27
|
+
ext: l.ext,
|
|
28
|
+
name: a
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
generateFileName(t) {
|
|
32
|
-
return `${t.split(".")[0]}_${
|
|
32
|
+
return `${t.split(".")[0]}_${ee().replace("-", "")}`;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
function
|
|
36
|
-
formLayoutProps:
|
|
35
|
+
function se({
|
|
36
|
+
formLayoutProps: s,
|
|
37
37
|
name: e,
|
|
38
38
|
label: t,
|
|
39
|
-
required:
|
|
40
|
-
provider:
|
|
39
|
+
required: l,
|
|
40
|
+
provider: a,
|
|
41
41
|
onUploading: n,
|
|
42
|
-
aspectRatio:
|
|
43
|
-
onRemoved:
|
|
44
|
-
fieldClassName:
|
|
45
|
-
hideLabel:
|
|
46
|
-
listType:
|
|
47
|
-
fieldHelper:
|
|
48
|
-
showSkipCropButton:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
aspectRatio: B,
|
|
43
|
+
onRemoved: f,
|
|
44
|
+
fieldClassName: A,
|
|
45
|
+
hideLabel: O = !1,
|
|
46
|
+
listType: j,
|
|
47
|
+
fieldHelper: z,
|
|
48
|
+
showSkipCropButton: S = !1,
|
|
49
|
+
skipCrop: _ = !1,
|
|
50
|
+
skipResize: x = !1,
|
|
51
|
+
asyncUpload: E = !1,
|
|
52
|
+
maxCount: h = 1
|
|
53
|
+
}, H) {
|
|
54
|
+
const m = I.useFormInstance(), u = e, d = I.useWatch(u, m), M = k(
|
|
55
|
+
(r) => a.getRealUrl(r),
|
|
56
|
+
[a]
|
|
57
|
+
), y = k(
|
|
58
|
+
async (r, F) => {
|
|
59
|
+
if (F) {
|
|
56
60
|
n == null || n(!0);
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
try {
|
|
62
|
+
const i = r.name, c = i.split("."), N = c[c.length - 1], p = a.generateFileName(i), g = `${await a.getInitialPath()}/${p}.${N}`, V = await a.upload(r, g), P = m.getFieldValue(u);
|
|
63
|
+
if (h > 1) {
|
|
64
|
+
const D = Array.isArray(P) ? P : P ? [P] : [];
|
|
65
|
+
m.setFieldValue(u, [
|
|
66
|
+
...D,
|
|
67
|
+
V
|
|
68
|
+
].filter(Boolean));
|
|
69
|
+
} else
|
|
70
|
+
m.setFieldValue(u, V);
|
|
71
|
+
return V;
|
|
72
|
+
} finally {
|
|
73
|
+
n == null || n(!1);
|
|
74
|
+
}
|
|
59
75
|
} else {
|
|
60
|
-
const
|
|
61
|
-
|
|
76
|
+
const i = m.getFieldValue(u);
|
|
77
|
+
if (h > 1) {
|
|
78
|
+
const c = r.response ?? (typeof r.uid == "string" ? r.uid : void 0);
|
|
79
|
+
if (!c) return;
|
|
80
|
+
await a.delete(c), f == null || f();
|
|
81
|
+
const p = (Array.isArray(i) ? i : i ? [i] : []).filter((g) => g !== c);
|
|
82
|
+
m.setFieldValue(
|
|
83
|
+
u,
|
|
84
|
+
p.length ? p : null
|
|
85
|
+
);
|
|
86
|
+
} else {
|
|
87
|
+
const c = await a.delete(i);
|
|
88
|
+
f == null || f(), c && m.setFieldValue(u, null);
|
|
89
|
+
}
|
|
62
90
|
}
|
|
63
91
|
},
|
|
64
|
-
[
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}, [F, g, l, p]), T(
|
|
69
|
-
_,
|
|
92
|
+
[m, h, u, f, n, a]
|
|
93
|
+
);
|
|
94
|
+
Z(
|
|
95
|
+
H,
|
|
70
96
|
() => ({
|
|
71
|
-
async uploadBlob(r,
|
|
72
|
-
const
|
|
73
|
-
name:
|
|
74
|
-
uid:
|
|
75
|
-
url:
|
|
97
|
+
async uploadBlob(r, F) {
|
|
98
|
+
const i = await ae.getBase64(r), c = {
|
|
99
|
+
name: F,
|
|
100
|
+
uid: F + Math.random().toString(36).substring(2, 15),
|
|
101
|
+
url: i,
|
|
76
102
|
originFileObj: r
|
|
77
103
|
};
|
|
78
|
-
|
|
104
|
+
await y(c, !0);
|
|
79
105
|
}
|
|
80
106
|
}),
|
|
81
|
-
[
|
|
82
|
-
)
|
|
83
|
-
|
|
107
|
+
[y]
|
|
108
|
+
);
|
|
109
|
+
const C = U(() => d ? (Array.isArray(d), d) : h > 1 ? [] : void 0, [d, h]);
|
|
110
|
+
return /* @__PURE__ */ G(
|
|
111
|
+
I.Item,
|
|
84
112
|
{
|
|
85
|
-
rules:
|
|
86
|
-
label:
|
|
87
|
-
required:
|
|
88
|
-
name:
|
|
89
|
-
help:
|
|
90
|
-
...
|
|
91
|
-
className:
|
|
113
|
+
rules: l ? v.required(t) : [],
|
|
114
|
+
label: O ? null : t,
|
|
115
|
+
required: l,
|
|
116
|
+
name: u,
|
|
117
|
+
help: z,
|
|
118
|
+
...s,
|
|
119
|
+
className: A,
|
|
92
120
|
children: [
|
|
93
|
-
/* @__PURE__ */
|
|
94
|
-
|
|
121
|
+
/* @__PURE__ */ o(
|
|
122
|
+
te,
|
|
95
123
|
{
|
|
96
124
|
noStyle: !0,
|
|
97
|
-
asyncUpload:
|
|
98
|
-
listType:
|
|
99
|
-
aspectRatio:
|
|
100
|
-
values:
|
|
125
|
+
asyncUpload: E,
|
|
126
|
+
listType: j,
|
|
127
|
+
aspectRatio: B,
|
|
128
|
+
values: C,
|
|
129
|
+
getRealUrl: M,
|
|
101
130
|
onRemove: (r) => {
|
|
102
|
-
r &&
|
|
131
|
+
r && y(r, !1);
|
|
103
132
|
},
|
|
104
133
|
onAdd: async (r) => {
|
|
105
|
-
r
|
|
134
|
+
if (r) return y(r, !0);
|
|
106
135
|
},
|
|
107
|
-
className:
|
|
108
|
-
showSkipCropButton:
|
|
109
|
-
|
|
110
|
-
|
|
136
|
+
className: A,
|
|
137
|
+
showSkipCropButton: S,
|
|
138
|
+
skipCrop: _,
|
|
139
|
+
skipResize: x,
|
|
140
|
+
maxCount: h
|
|
111
141
|
}
|
|
112
142
|
),
|
|
113
|
-
/* @__PURE__ */
|
|
143
|
+
/* @__PURE__ */ o(Q, { hidden: !0 })
|
|
114
144
|
]
|
|
115
145
|
}
|
|
116
146
|
);
|
|
117
147
|
}
|
|
118
|
-
const
|
|
119
|
-
const [t,
|
|
120
|
-
return
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
148
|
+
const Pe = T.forwardRef(se), ge = ({ provider: s, value: e }) => {
|
|
149
|
+
const [t, l] = X([]);
|
|
150
|
+
return Y(() => {
|
|
151
|
+
if (!e) {
|
|
152
|
+
l([]);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const a = Array.isArray(e) ? e : [e];
|
|
156
|
+
Promise.all(a.filter(Boolean).map((n) => s.getRealUrl(n))).then(
|
|
157
|
+
l
|
|
158
|
+
);
|
|
159
|
+
}, [s, e]), t.length ? /* @__PURE__ */ o($, { children: t.map((a) => /* @__PURE__ */ o(le, { url: a }, a)) }) : /* @__PURE__ */ o($, {});
|
|
160
|
+
}, le = ({ url: s }) => /* @__PURE__ */ o(K, { className: "p-0", children: /* @__PURE__ */ o(
|
|
161
|
+
L,
|
|
125
162
|
{
|
|
126
163
|
className: "m-0 p-0 position-relative",
|
|
127
|
-
src:
|
|
164
|
+
src: s,
|
|
128
165
|
preview: {
|
|
129
|
-
mask: /* @__PURE__ */
|
|
166
|
+
mask: /* @__PURE__ */ o(J, {})
|
|
130
167
|
}
|
|
131
168
|
}
|
|
132
169
|
) });
|
|
133
170
|
export {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
171
|
+
re as FileDownloadProvider,
|
|
172
|
+
pe as FileUploadProvider,
|
|
173
|
+
le as ImageCellValue,
|
|
174
|
+
ge as ImageCrudCellValue,
|
|
175
|
+
Pe as default
|
|
139
176
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const h=require("react/jsx-runtime"),N=require("antd"),s=require("react"),z=require("../CrudForm.cjs.js"),ee=require("../CrudFormWizard.cjs.js"),te=require("../../locale/index.cjs.js"),B=require("../../util/CrudUtil.cjs.js"),ae=require("dayjs"),c=require("../../util/ObjectUtil.cjs.js"),se=({fields:i,wizard:r,grid:_,fullWidthModal:L,isCreating:M,isUpdating:U,onCreate:V,onUpdate:v,idField:P="id",formBuilder:E,onValuesChange:R},$)=>{const[l]=N.Form.useForm(),{t:S}=te.useTranslationLib(),[k,F]=s.useState(!1),[f,A]=s.useState("new"),[m,b]=s.useState(),[G,g]=s.useState(),[J,w]=s.useState(!1),[K,C]=s.useState(!1),[Q,O]=s.useState(!1),W=s.useCallback(async t=>{var p;const d=r?t:await l.validateFields(),o=i.filter(a=>a.type==="color"),n={};for(const a of o){const u=B.getRealName(a.name,"upsertFieldName"),e=l.getFieldValue(u);c.setValueByPath(n,u,typeof e=="string"?e:(p=e==null?void 0:e.toHexString())==null?void 0:p.toUpperCase())}Object.assign(d,n),m&&v?(await v({...d,[P]:m[P]}),b(void 0)):!m&&V&&await V(d),g(void 0),j(new Map),l.resetFields(),F(!1)},[i,l,P,V,v,m,r]),D=s.useCallback(async t=>{w(t),C(!0)},[]),H=s.useCallback(async()=>{C(!0)},[]),I=s.useCallback(()=>{F(!0),A("new"),l.resetFields(),b(void 0),g(void 0)},[l]),[x,j]=s.useState(new Map),X=s.useMemo(()=>x.size===0?i:i.map(t=>typeof t.updatable=="function"?{...t,updatable:x.get(B.getRealName(t.name,"name"))??t.updatable}:t),[i,x]),T=s.useCallback(async(t,d=!0,o=!1)=>{try{O(!0),F(!0),A(o?"clone":"update");const n={};for(const a of i){const u=B.getRealName(a.name,"upsertFieldName"),e=c.getValueByPath(t,u);if(o&&a.type==="image"){const y=e;try{if(Array.isArray(y)){const q=await Promise.all(y.map(Z=>a.provider.clone(Z)));c.setValueByPath(n,u,q)}else if(y){const q=await a.provider.clone(y);c.setValueByPath(n,u,q)}continue}catch{continue}}a.type==="date"||a.type==="time"?e&&c.setValueByPath(n,u,ae(e)):a.type==="select"?a.multiple&&Array.isArray(e)?c.setValueByPath(n,u,e.map(y=>y[a.innerFieldId??"id"])):e&&typeof e=="object"?c.setValueByPath(n,u,e[a.innerFieldId??"id"]):(e&&typeof e=="string"||typeof e=="number")&&c.setValueByPath(n,u,e):c.setValueByPath(n,u,e)}l.setFieldsValue(n);const p=new Map;for(const a of i)typeof a.updatable=="function"&&p.set(B.getRealName(a.name,"name"),a.updatable(t));j(p),g(n),d&&b(t)}finally{O(!1)}},[i,l]);s.useImperativeHandle($,()=>({create:I,update:T}),[I,T]),s.useEffect(()=>{k&&(w(!1),C(!1))},[k]);const Y=s.useCallback(async()=>{j(new Map);try{if(f==="clone"){const t=r?m:l.getFieldsValue(),d=i.filter(o=>o.type==="image");for(const o of d)if(t[o.name]){const n=Array.isArray(t[o.name])?t[o.name]:[t[o.name]];for(const p of n)o.provider.delete(p)}}}finally{}r||l.resetFields(),g(void 0),b(void 0),F(!1)},[f,r,l,m,i]);return h.jsx(N.Modal,{width:L?"100%":void 0,title:S("str."+(f??"new")),open:k,confirmLoading:M||U,okText:S("str."+(f==="update"?"update":"save")),cancelText:S("str.cancel"),cancelButtonProps:{disabled:K,hidden:!!r},okButtonProps:{disabled:J,hidden:!!r},onCancel:Y,onOk:()=>W(),destroyOnHidden:!0,children:h.jsxs(N.Spin,{spinning:Q,children:[r?null:h.jsx(z.CrudForm,{purpose:f,fields:X,form:l,formBuilder:E,grid:_,onDeleteFile:H,onUploadFile:D,onValuesChange:R}),r&&h.jsx(ee,{submitting:M||U,className:"mt-2",onSave:W,updatingValue:G,fields:i,onDeleteFile:H,onUploadFile:D,purpose:f,wizard:r,onValuesChange:R})]})})},ne=s.forwardRef(se);module.exports=ne;
|
|
@@ -1,171 +1,182 @@
|
|
|
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:
|
|
1
|
+
import { jsx as A, jsxs as z } from "react/jsx-runtime";
|
|
2
|
+
import { Form as ee, Modal as te, Spin as oe } from "antd";
|
|
3
|
+
import { forwardRef as ae, useState as c, useCallback as F, useMemo as ne, useImperativeHandle as le, useEffect as se } from "react";
|
|
4
|
+
import { CrudForm as ie } from "../CrudForm.es.js";
|
|
5
|
+
import re from "../CrudFormWizard.es.js";
|
|
6
|
+
import { useTranslationLib as ce } from "../../locale/index.es.js";
|
|
7
|
+
import h from "../../util/CrudUtil.es.js";
|
|
8
|
+
import ue from "dayjs";
|
|
9
|
+
import { setValueByPath as u, getValueByPath as de } from "../../util/ObjectUtil.es.js";
|
|
10
|
+
const pe = ({
|
|
11
|
+
fields: s,
|
|
12
|
+
wizard: r,
|
|
13
|
+
grid: L,
|
|
14
|
+
fullWidthModal: E,
|
|
15
15
|
isCreating: C,
|
|
16
16
|
isUpdating: j,
|
|
17
17
|
onCreate: B,
|
|
18
18
|
onUpdate: V,
|
|
19
|
-
idField:
|
|
20
|
-
formBuilder:
|
|
21
|
-
onValuesChange:
|
|
22
|
-
},
|
|
23
|
-
const [
|
|
24
|
-
async (
|
|
25
|
-
var
|
|
26
|
-
const
|
|
27
|
-
for (const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
typeof e == "string" ? e : (
|
|
19
|
+
idField: N = "id",
|
|
20
|
+
formBuilder: $,
|
|
21
|
+
onValuesChange: w
|
|
22
|
+
}, q) => {
|
|
23
|
+
const [n] = ee.useForm(), { t: P } = ce(), [k, g] = c(!1), [f, R] = c("new"), [m, b] = c(), [G, v] = c(), [J, O] = c(!1), [K, M] = c(!1), [Q, W] = c(!1), D = F(
|
|
24
|
+
async (t) => {
|
|
25
|
+
var p;
|
|
26
|
+
const d = r ? t : await n.validateFields(), l = s.filter((o) => o.type === "color"), a = {};
|
|
27
|
+
for (const o of l) {
|
|
28
|
+
const i = h.getRealName(o.name, "upsertFieldName"), e = n.getFieldValue(i);
|
|
29
|
+
u(
|
|
30
|
+
a,
|
|
31
|
+
i,
|
|
32
|
+
typeof e == "string" ? e : (p = e == null ? void 0 : e.toHexString()) == null ? void 0 : p.toUpperCase()
|
|
33
33
|
);
|
|
34
34
|
}
|
|
35
|
-
Object.assign(
|
|
36
|
-
...
|
|
37
|
-
[
|
|
38
|
-
}),
|
|
35
|
+
Object.assign(d, a), m && V ? (await V({
|
|
36
|
+
...d,
|
|
37
|
+
[N]: m[N]
|
|
38
|
+
}), b(void 0)) : !m && B && await B(d), v(void 0), U(/* @__PURE__ */ new Map()), n.resetFields(), g(!1);
|
|
39
39
|
},
|
|
40
|
-
[
|
|
41
|
-
), H =
|
|
42
|
-
O(
|
|
43
|
-
}, []), I =
|
|
40
|
+
[s, n, N, B, V, m, r]
|
|
41
|
+
), H = F(async (t) => {
|
|
42
|
+
O(t), M(!0);
|
|
43
|
+
}, []), I = F(async () => {
|
|
44
44
|
M(!0);
|
|
45
|
-
}, []), T =
|
|
46
|
-
|
|
47
|
-
}, [
|
|
48
|
-
...
|
|
49
|
-
updatable:
|
|
50
|
-
} :
|
|
51
|
-
async (
|
|
45
|
+
}, []), T = F(() => {
|
|
46
|
+
g(!0), R("new"), n.resetFields(), b(void 0), v(void 0);
|
|
47
|
+
}, [n]), [S, U] = c(/* @__PURE__ */ new Map()), X = ne(() => S.size === 0 ? s : s.map((t) => typeof t.updatable == "function" ? {
|
|
48
|
+
...t,
|
|
49
|
+
updatable: S.get(h.getRealName(t.name, "name")) ?? t.updatable
|
|
50
|
+
} : t), [s, S]), _ = F(
|
|
51
|
+
async (t, d = !0, l = !1) => {
|
|
52
52
|
try {
|
|
53
|
-
W(!0),
|
|
54
|
-
const
|
|
55
|
-
for (const
|
|
56
|
-
const
|
|
57
|
-
|
|
53
|
+
W(!0), g(!0), R(l ? "clone" : "update");
|
|
54
|
+
const a = {};
|
|
55
|
+
for (const o of s) {
|
|
56
|
+
const i = h.getRealName(
|
|
57
|
+
o.name,
|
|
58
58
|
"upsertFieldName"
|
|
59
|
-
), e =
|
|
60
|
-
if (
|
|
61
|
-
const
|
|
59
|
+
), e = de(t, i);
|
|
60
|
+
if (l && o.type === "image") {
|
|
61
|
+
const y = e;
|
|
62
62
|
try {
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
if (Array.isArray(y)) {
|
|
64
|
+
const x = await Promise.all(
|
|
65
|
+
y.map((Z) => o.provider.clone(Z))
|
|
66
|
+
);
|
|
67
|
+
u(a, i, x);
|
|
68
|
+
} else if (y) {
|
|
69
|
+
const x = await o.provider.clone(y);
|
|
70
|
+
u(a, i, x);
|
|
71
|
+
}
|
|
65
72
|
continue;
|
|
66
73
|
} catch {
|
|
67
74
|
continue;
|
|
68
75
|
}
|
|
69
76
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
e.map((
|
|
74
|
-
) : e && typeof e == "object" ?
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
e[
|
|
78
|
-
) : (e && typeof e == "string" || typeof e == "number") &&
|
|
77
|
+
o.type === "date" || o.type === "time" ? e && u(a, i, ue(e)) : o.type === "select" ? o.multiple && Array.isArray(e) ? u(
|
|
78
|
+
a,
|
|
79
|
+
i,
|
|
80
|
+
e.map((y) => y[o.innerFieldId ?? "id"])
|
|
81
|
+
) : e && typeof e == "object" ? u(
|
|
82
|
+
a,
|
|
83
|
+
i,
|
|
84
|
+
e[o.innerFieldId ?? "id"]
|
|
85
|
+
) : (e && typeof e == "string" || typeof e == "number") && u(a, i, e) : u(a, i, e);
|
|
79
86
|
}
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
for (const
|
|
83
|
-
typeof
|
|
84
|
-
|
|
85
|
-
|
|
87
|
+
n.setFieldsValue(a);
|
|
88
|
+
const p = /* @__PURE__ */ new Map();
|
|
89
|
+
for (const o of s)
|
|
90
|
+
typeof o.updatable == "function" && p.set(
|
|
91
|
+
h.getRealName(o.name, "name"),
|
|
92
|
+
o.updatable(t)
|
|
86
93
|
);
|
|
87
|
-
|
|
94
|
+
U(p), v(a), d && b(t);
|
|
88
95
|
} finally {
|
|
89
96
|
W(!1);
|
|
90
97
|
}
|
|
91
98
|
},
|
|
92
|
-
[
|
|
99
|
+
[s, n]
|
|
93
100
|
);
|
|
94
|
-
|
|
95
|
-
|
|
101
|
+
le(
|
|
102
|
+
q,
|
|
96
103
|
() => ({
|
|
97
104
|
create: T,
|
|
98
105
|
update: _
|
|
99
106
|
}),
|
|
100
107
|
[T, _]
|
|
101
|
-
),
|
|
108
|
+
), se(() => {
|
|
102
109
|
k && (O(!1), M(!1));
|
|
103
110
|
}, [k]);
|
|
104
|
-
const
|
|
105
|
-
|
|
111
|
+
const Y = F(async () => {
|
|
112
|
+
U(/* @__PURE__ */ new Map());
|
|
106
113
|
try {
|
|
107
|
-
if (
|
|
108
|
-
const
|
|
109
|
-
for (const
|
|
110
|
-
|
|
114
|
+
if (f === "clone") {
|
|
115
|
+
const t = r ? m : n.getFieldsValue(), d = s.filter((l) => l.type === "image");
|
|
116
|
+
for (const l of d)
|
|
117
|
+
if (t[l.name]) {
|
|
118
|
+
const a = Array.isArray(t[l.name]) ? t[l.name] : [t[l.name]];
|
|
119
|
+
for (const p of a)
|
|
120
|
+
l.provider.delete(p);
|
|
121
|
+
}
|
|
111
122
|
}
|
|
112
123
|
} finally {
|
|
113
124
|
}
|
|
114
|
-
|
|
115
|
-
}, [
|
|
116
|
-
return /* @__PURE__ */
|
|
117
|
-
|
|
125
|
+
r || n.resetFields(), v(void 0), b(void 0), g(!1);
|
|
126
|
+
}, [f, r, n, m, s]);
|
|
127
|
+
return /* @__PURE__ */ A(
|
|
128
|
+
te,
|
|
118
129
|
{
|
|
119
|
-
width:
|
|
120
|
-
title:
|
|
130
|
+
width: E ? "100%" : void 0,
|
|
131
|
+
title: P("str." + (f ?? "new")),
|
|
121
132
|
open: k,
|
|
122
133
|
confirmLoading: C || j,
|
|
123
|
-
okText:
|
|
124
|
-
cancelText:
|
|
134
|
+
okText: P("str." + (f === "update" ? "update" : "save")),
|
|
135
|
+
cancelText: P("str.cancel"),
|
|
125
136
|
cancelButtonProps: {
|
|
126
|
-
disabled:
|
|
127
|
-
hidden: !!
|
|
137
|
+
disabled: K,
|
|
138
|
+
hidden: !!r
|
|
128
139
|
},
|
|
129
140
|
okButtonProps: {
|
|
130
|
-
disabled:
|
|
131
|
-
hidden: !!
|
|
141
|
+
disabled: J,
|
|
142
|
+
hidden: !!r
|
|
132
143
|
},
|
|
133
|
-
onCancel:
|
|
144
|
+
onCancel: Y,
|
|
134
145
|
onOk: () => D(),
|
|
135
146
|
destroyOnHidden: !0,
|
|
136
|
-
children: /* @__PURE__ */
|
|
137
|
-
|
|
138
|
-
|
|
147
|
+
children: /* @__PURE__ */ z(oe, { spinning: Q, children: [
|
|
148
|
+
r ? null : /* @__PURE__ */ A(
|
|
149
|
+
ie,
|
|
139
150
|
{
|
|
140
|
-
purpose:
|
|
141
|
-
fields:
|
|
142
|
-
form:
|
|
143
|
-
formBuilder:
|
|
144
|
-
grid:
|
|
151
|
+
purpose: f,
|
|
152
|
+
fields: X,
|
|
153
|
+
form: n,
|
|
154
|
+
formBuilder: $,
|
|
155
|
+
grid: L,
|
|
145
156
|
onDeleteFile: I,
|
|
146
157
|
onUploadFile: H,
|
|
147
|
-
onValuesChange:
|
|
158
|
+
onValuesChange: w
|
|
148
159
|
}
|
|
149
160
|
),
|
|
150
|
-
|
|
151
|
-
|
|
161
|
+
r && /* @__PURE__ */ A(
|
|
162
|
+
re,
|
|
152
163
|
{
|
|
153
164
|
submitting: C || j,
|
|
154
165
|
className: "mt-2",
|
|
155
166
|
onSave: D,
|
|
156
|
-
updatingValue:
|
|
157
|
-
fields:
|
|
167
|
+
updatingValue: G,
|
|
168
|
+
fields: s,
|
|
158
169
|
onDeleteFile: I,
|
|
159
170
|
onUploadFile: H,
|
|
160
|
-
purpose:
|
|
161
|
-
wizard:
|
|
162
|
-
onValuesChange:
|
|
171
|
+
purpose: f,
|
|
172
|
+
wizard: r,
|
|
173
|
+
onValuesChange: w
|
|
163
174
|
}
|
|
164
175
|
)
|
|
165
176
|
] })
|
|
166
177
|
}
|
|
167
178
|
);
|
|
168
|
-
}, Ve =
|
|
179
|
+
}, Ve = ae(pe);
|
|
169
180
|
export {
|
|
170
181
|
Ve as default
|
|
171
182
|
};
|