@kingteza/crud-component 1.44.2 → 1.46.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/common/picker/ImagePicker.cjs.js +1 -1
- package/dist/common/picker/ImagePicker.d.ts +2 -0
- package/dist/common/picker/ImagePicker.es.js +141 -135
- package/dist/crud/CrudField.cjs.js +1 -1
- package/dist/crud/CrudField.es.js +103 -101
- package/dist/crud/FileCrudField.cjs.js +1 -1
- package/dist/crud/FileCrudField.d.ts +2 -1
- package/dist/crud/FileCrudField.es.js +133 -132
- package/dist/crud/ImageCrudField.cjs.js +1 -1
- package/dist/crud/ImageCrudField.d.ts +3 -0
- package/dist/crud/ImageCrudField.es.js +115 -102
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("react/jsx-runtime"),Ie=require("react-advanced-cropper"),q=require("@ant-design/icons"),R=require("antd"),r=require("react"),ke=require("../../locale/index.cjs.js"),O=require("../button/Button.cjs.js"),le=require("../../util/ImageUtil.cjs.js"),Oe=require("../../icons/FlipHIcon.cjs.js"),Re=require("../../icons/FlipVIcon.cjs.js"),Ue=R.Form.Item,ue="crud-component.image-picker.button-state";function $(u){return new Promise((w,b)=>{const i=new FileReader;i.readAsDataURL(u),i.onload=()=>w(i.result),i.onerror=f=>b(f)})}const Pe=({values:u=[],getRealUrl:w,required:b,buttonType:i,label:f,name:H,onChange:y,aspectRatio:S,buttonTitle:N,hidePreview:F,buttonSize:C="large",showButtonText:T=!0,showOnlyIcon:A=!1,icon:z=t.jsx(q.UploadOutlined,{}),loading:U,maxCount:a=1,onAdd:I,onRemove:B,listType:G,showSkipCropButton:pe,skipCrop:K=!1,skipResize:V,asyncUpload:M,...Q})=>{const[me,fe]=r.useState(""),[ge,je]=r.useState(""),[xe,X]=r.useState(!1),E=r.useRef(),g=r.useRef(null),[d,j]=r.useState([]),[k,L]=r.useState(),he=r.useRef(),ve=()=>X(!1),we=async e=>{!e.url&&!e.preview&&(e.preview=await $(e.originFileObj)),je(e.url||e.preview),X(!0),fe(e.name)},[Y,P]=r.useState(!1),Z=e=>{var s;(s=g.current)==null||s.rotateImage(e?-90:90)},ee=r.useCallback(e=>{var s;g.current&&((s=g.current)==null||s.flipImage(e==="h",e==="v"))},[]);r.useEffect(()=>{y==null||y(d[0],d)},[d,y]);const[_,J]=r.useState(),D=r.useCallback(async e=>{var ae;const{type:s,size:o,name:h,uid:c}=E.current;J(e?"skip-crop":"crop"),P(!0);const v=async n=>{if(I)try{if(P(!0),M)j(l=>a<=1?[n]:[n,...l]),I(n).then(l=>{j(p=>p.map(m=>m.uid===n.uid?{...m,status:"done",response:l??m.response}:m))});else{const l=await I(n),p={...n,response:l??n.response,status:"done"};j(m=>a<=1?[p]:[p,...m])}}finally{P(!1)}else j(l=>a<=1?[n]:[n,...l])};if(e){const n=E.current,l=V?n:await le.resizeImage(n),p=await $(l);await v({url:p,name:h,uid:c,type:s,size:o,thumbUrl:p,originFileObj:l,status:M?"uploading":void 0}),P(!1),L(void 0),J(void 0)}else{const n=(ae=g.current)==null?void 0:ae.getCanvas();n==null||n.toBlob(async l=>{const p=Object.assign(new File([l],h,{type:s}),{uid:c}),m=V?p:await le.resizeImage(p),ce=await $(m);await v({url:ce,name:h,uid:c,type:s,size:o,thumbUrl:ce,originFileObj:m,status:M?"uploading":void 0}),P(!1),L(void 0),J(void 0)})}},[M,a,I,V]),be=()=>{L(void 0),E.current=void 0},te=r.useCallback(e=>{const s=e;if(!s)return;if(E.current=s,K){D(!0);return}const o=new FileReader;o.addEventListener("load",()=>{var h;if(typeof o.result=="string"){L(o.result);const c=localStorage.getItem(ue),v=c?JSON.parse(c):void 0;v&&((h=g.current)==null||h.setState(v)),setTimeout(()=>{ie(g.current)},100)}}),o.readAsDataURL(s)},[D,K]);r.useEffect(()=>{let e=!1;return(async()=>{if(u==null||u===""){e||j([]);return}const o=typeof u=="string"?[u]:u;if(!o.length){e||j([]);return}const h=await Promise.all(o.map(async c=>{const v=w?await w(c):c;return{uid:c,url:v,thumbUrl:v,response:c,name:c.split("/").pop()??c}}));e||j(h)})(),()=>{e=!0}},[u,w]);const{t:x}=ke.useTranslationLib(),Se=r.useMemo(()=>b?{required:b,validator:(e,s,o)=>{k||d!=null&&d.length?o():o(`${f??""} ${x("err.validation.required")}`)}}:void 0,[b,k,d==null?void 0:d.length,f,x]),se=N??x("message.uploadButtonText"),re=r.useMemo(()=>t.jsx(de,{showLoadingIndicator:Y,_buttonTitle:se,buttonSize:C,buttonType:i,fileList:d,hidePreview:F,icon:z,loading:U,listType:G,maxCount:a,onChangeFile:te,onRemove:B,showButtonText:T,handlePreview:we,setFileList:j}),[Y,se,C,i,d,F,z,U,G,a,te,B,T]);he.current=re.props.beforeUpload;const[ye,ne]=r.useState(0),[Fe,oe]=r.useState(0),[W,Ce]=r.useState();r.useEffect(()=>{const e=setTimeout(()=>{W&&localStorage.setItem(ue,JSON.stringify(W))},400);return()=>clearTimeout(e)},[W]),r.useEffect(()=>{if(!k){ne(0),oe(0);const e=setTimeout(()=>{var s;(s=g.current)==null||s.reset()},1500);return()=>clearTimeout(e)}},[k]);const ie=r.useCallback(async e=>{if(e){const s=e.getCoordinates();Ce(e.getState()),ne((s==null?void 0:s.width)??10),oe((s==null?void 0:s.height)??10)}},[]);return t.jsxs(t.Fragment,{children:[t.jsx(Ue,{label:f,...Q,name:H,className:"mb-0",rules:[Se,...Q.rules??[]],children:re}),t.jsxs(R.Modal,{open:!!k,maskClosable:!1,onOk:()=>D(!1),closable:!1,okButtonProps:{loading:_==="crop",disabled:_==="skip-crop"},onCancel:be,footer:(e,{CancelBtn:s,OkBtn:o})=>pe?t.jsxs(R.Space,{children:[t.jsx(s,{}),t.jsx(O,{type:"primary",loading:_==="skip-crop",disabled:_==="crop",onClick:()=>D(!0),children:x("str.skipCrop")}),t.jsx(o,{})]}):t.jsx(t.Fragment,{children:e}),destroyOnHidden:!0,children:[t.jsx(Ie.Cropper,{ref:g,stencilProps:{grid:!0},style:{border:"1px solid black"},src:k,onChange:e=>{ie(e)},aspectRatio:S?{minimum:S,maximum:S}:void 0}),t.jsx("p",{className:"text-center",children:[ye,Fe].join(" ⨉ ")}),t.jsx("div",{className:"mt-2 d-flex justify-content-center",children:t.jsxs(R.Space.Compact,{children:[t.jsx(O,{size:"large",tooltip:x("str.rotateLeft"),icon:t.jsx(q.RotateLeftOutlined,{}),onClick:()=>Z(!0)}),t.jsx(O,{size:"large",icon:t.jsx(q.RotateRightOutlined,{}),tooltip:x("str.rotateRight"),onClick:()=>Z(!1)}),t.jsx(O,{size:"large",icon:t.jsx(Oe,{}),tooltip:x("str.flipHorizontal"),onClick:()=>ee("h")}),t.jsx(O,{size:"large",icon:t.jsx(Re,{}),tooltip:x("str.flipVertical"),onClick:()=>ee("v")})]})})]}),t.jsx(R.Modal,{open:xe,title:me,footer:null,onCancel:ve,children:t.jsx("div",{className:"text-center",children:t.jsx("img",{alt:"example",style:{maxWidth:"400px"},src:ge})})})]})},de=({_buttonTitle:u,buttonSize:w,buttonType:b,fileList:i,hidePreview:f,icon:H,loading:y,maxCount:S,onChangeFile:N,onRemove:F,showButtonText:C,handlePreview:T,setFileList:A,showLoadingIndicator:z,listType:U="picture"})=>t.jsxs(R.Upload,{accept:"image/x-png,image/gif,image/jpeg",fileList:i,defaultFileList:i,onChange:()=>{},className:(i.length>=S?" hide-upload ":"")+" mb-0",multiple:!1,onPreview:f?void 0:T,onDrop:a=>(N(a.dataTransfer.files.item(0)),!1),listType:U,showUploadList:!f,onRemove:a=>{const I=i.filter(B=>a.uid!==B.uid);F==null||F(a),A(I)},beforeUpload:async a=>(N(a),!1),maxCount:S,children:[z&&t.jsx(q.LoadingOutlined,{}),t.jsx("div",{className:"d-flex flex-column",children:i.length<S&&(U==="picture-circle"?t.jsx(q.UploadOutlined,{}):t.jsx(O,{loading:y,tooltip:C?void 0:u,size:w,icon:H,type:C?b:"text",children:C?u:void 0}))})]},i.length);exports.UploadComponent=de;exports.default=Pe;
|
|
@@ -28,6 +28,8 @@ interface Props extends FormItemProps {
|
|
|
28
28
|
onAdd?: (file?: UploadFileExtended) => Promise<string | void>;
|
|
29
29
|
onRemove?: (file?: UploadFileExtended) => void;
|
|
30
30
|
showSkipCropButton?: boolean;
|
|
31
|
+
/** When true, skips the crop modal entirely and uploads the original image. */
|
|
32
|
+
skipCrop?: boolean;
|
|
31
33
|
skipResize?: boolean;
|
|
32
34
|
asyncUpload?: boolean;
|
|
33
35
|
}
|
|
@@ -1,72 +1,73 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { Cropper as
|
|
3
|
-
import { RotateLeftOutlined as
|
|
4
|
-
import { Form as
|
|
5
|
-
import
|
|
6
|
-
import { useTranslationLib as
|
|
1
|
+
import { jsx as r, jsxs as U, Fragment as ue } from "react/jsx-runtime";
|
|
2
|
+
import { Cropper as Be } from "react-advanced-cropper";
|
|
3
|
+
import { RotateLeftOutlined as Re, RotateRightOutlined as Te, UploadOutlined as ve, LoadingOutlined as Le } from "@ant-design/icons";
|
|
4
|
+
import { Form as De, Modal as me, Space as fe, Upload as He } from "antd";
|
|
5
|
+
import G, { useRef as K, useState as I, useCallback as E, useEffect as M, useMemo as ge } from "react";
|
|
6
|
+
import { useTranslationLib as Ve } from "../../locale/index.es.js";
|
|
7
7
|
import x from "../button/Button.es.js";
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
const
|
|
12
|
-
function
|
|
8
|
+
import he from "../../util/ImageUtil.es.js";
|
|
9
|
+
import _e from "../../icons/FlipHIcon.es.js";
|
|
10
|
+
import Ee from "../../icons/FlipVIcon.es.js";
|
|
11
|
+
const Me = De.Item, we = "crud-component.image-picker.button-state";
|
|
12
|
+
function Q(c) {
|
|
13
13
|
return new Promise((b, y) => {
|
|
14
14
|
const n = new FileReader();
|
|
15
15
|
n.readAsDataURL(c), n.onload = () => b(n.result), n.onerror = (m) => y(m);
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
-
const
|
|
18
|
+
const tt = ({
|
|
19
19
|
values: c = [],
|
|
20
20
|
getRealUrl: b,
|
|
21
21
|
required: y,
|
|
22
22
|
buttonType: n,
|
|
23
23
|
label: m,
|
|
24
|
-
name:
|
|
24
|
+
name: J,
|
|
25
25
|
onChange: C,
|
|
26
26
|
aspectRatio: F,
|
|
27
27
|
buttonTitle: z,
|
|
28
|
-
hidePreview:
|
|
29
|
-
buttonSize:
|
|
28
|
+
hidePreview: O,
|
|
29
|
+
buttonSize: k = "large",
|
|
30
30
|
showButtonText: B = !0,
|
|
31
|
-
showOnlyIcon:
|
|
32
|
-
icon: R = /* @__PURE__ */
|
|
31
|
+
showOnlyIcon: X = !1,
|
|
32
|
+
icon: R = /* @__PURE__ */ r(ve, {}),
|
|
33
33
|
loading: N,
|
|
34
34
|
maxCount: s = 1,
|
|
35
35
|
onAdd: S,
|
|
36
36
|
onRemove: T,
|
|
37
|
-
listType:
|
|
38
|
-
showSkipCropButton:
|
|
39
|
-
|
|
37
|
+
listType: Y,
|
|
38
|
+
showSkipCropButton: be,
|
|
39
|
+
skipCrop: Z = !1,
|
|
40
|
+
skipResize: W,
|
|
40
41
|
asyncUpload: L,
|
|
41
|
-
...
|
|
42
|
+
...q
|
|
42
43
|
}) => {
|
|
43
|
-
const [
|
|
44
|
-
!e.url && !e.preview && (e.preview = await
|
|
45
|
-
}, [
|
|
44
|
+
const [ye, Fe] = G.useState(""), [Ie, Ce] = G.useState(""), [Oe, ee] = G.useState(!1), D = K(), f = K(null), [d, g] = I([]), [j, H] = I(), ke = K(), Se = () => ee(!1), je = async (e) => {
|
|
45
|
+
!e.url && !e.preview && (e.preview = await Q(e.originFileObj)), Ce(e.url || e.preview), ee(!0), Fe(e.name);
|
|
46
|
+
}, [te, P] = I(!1), re = (e) => {
|
|
46
47
|
var t;
|
|
47
48
|
(t = f.current) == null || t.rotateImage(e ? -90 : 90);
|
|
48
|
-
},
|
|
49
|
+
}, oe = E((e) => {
|
|
49
50
|
var t;
|
|
50
51
|
f.current && ((t = f.current) == null || t.flipImage(e === "h", e === "v"));
|
|
51
52
|
}, []);
|
|
52
|
-
|
|
53
|
+
M(() => {
|
|
53
54
|
C == null || C(d[0], d);
|
|
54
55
|
}, [d, C]);
|
|
55
|
-
const [V,
|
|
56
|
+
const [V, $] = I(), _ = E(
|
|
56
57
|
async (e) => {
|
|
57
|
-
var
|
|
58
|
+
var de;
|
|
58
59
|
const { type: t, size: i, name: w, uid: a } = D.current;
|
|
59
|
-
|
|
60
|
-
const v = async (
|
|
60
|
+
$(e ? "skip-crop" : "crop"), P(!0);
|
|
61
|
+
const v = async (o) => {
|
|
61
62
|
if (S)
|
|
62
63
|
try {
|
|
63
64
|
if (P(!0), L)
|
|
64
65
|
g(
|
|
65
|
-
(l) => s <= 1 ? [
|
|
66
|
-
), S(
|
|
66
|
+
(l) => s <= 1 ? [o] : [o, ...l]
|
|
67
|
+
), S(o).then((l) => {
|
|
67
68
|
g(
|
|
68
69
|
(p) => p.map(
|
|
69
|
-
(u) => u.uid ===
|
|
70
|
+
(u) => u.uid === o.uid ? {
|
|
70
71
|
...u,
|
|
71
72
|
status: "done",
|
|
72
73
|
response: l ?? u.response
|
|
@@ -75,9 +76,9 @@ const et = ({
|
|
|
75
76
|
);
|
|
76
77
|
});
|
|
77
78
|
else {
|
|
78
|
-
const l = await S(
|
|
79
|
-
...
|
|
80
|
-
response: l ??
|
|
79
|
+
const l = await S(o), p = {
|
|
80
|
+
...o,
|
|
81
|
+
response: l ?? o.response,
|
|
81
82
|
status: "done"
|
|
82
83
|
};
|
|
83
84
|
g(
|
|
@@ -88,10 +89,10 @@ const et = ({
|
|
|
88
89
|
P(!1);
|
|
89
90
|
}
|
|
90
91
|
else
|
|
91
|
-
g((l) => s <= 1 ? [
|
|
92
|
+
g((l) => s <= 1 ? [o] : [o, ...l]);
|
|
92
93
|
};
|
|
93
94
|
if (e) {
|
|
94
|
-
const
|
|
95
|
+
const o = D.current, l = W ? o : await he.resizeImage(o), p = await Q(l);
|
|
95
96
|
await v({
|
|
96
97
|
url: p,
|
|
97
98
|
name: w,
|
|
@@ -101,47 +102,52 @@ const et = ({
|
|
|
101
102
|
thumbUrl: p,
|
|
102
103
|
originFileObj: l,
|
|
103
104
|
status: L ? "uploading" : void 0
|
|
104
|
-
}), P(!1), H(void 0),
|
|
105
|
+
}), P(!1), H(void 0), $(void 0);
|
|
105
106
|
} else {
|
|
106
|
-
const
|
|
107
|
-
|
|
107
|
+
const o = (de = f.current) == null ? void 0 : de.getCanvas();
|
|
108
|
+
o == null || o.toBlob(async (l) => {
|
|
108
109
|
const p = Object.assign(new File([l], w, { type: t }), {
|
|
109
110
|
uid: a
|
|
110
|
-
}), u =
|
|
111
|
+
}), u = W ? p : await he.resizeImage(p), pe = await Q(u);
|
|
111
112
|
await v({
|
|
112
|
-
url:
|
|
113
|
+
url: pe,
|
|
113
114
|
name: w,
|
|
114
115
|
uid: a,
|
|
115
116
|
type: t,
|
|
116
117
|
size: i,
|
|
117
|
-
thumbUrl:
|
|
118
|
+
thumbUrl: pe,
|
|
118
119
|
originFileObj: u,
|
|
119
120
|
status: L ? "uploading" : void 0
|
|
120
|
-
}), P(!1), H(void 0),
|
|
121
|
+
}), P(!1), H(void 0), $(void 0);
|
|
121
122
|
});
|
|
122
123
|
}
|
|
123
124
|
},
|
|
124
|
-
[L, s, S,
|
|
125
|
-
),
|
|
125
|
+
[L, s, S, W]
|
|
126
|
+
), xe = () => {
|
|
126
127
|
H(void 0), D.current = void 0;
|
|
127
|
-
},
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
}, ie = E(
|
|
129
|
+
(e) => {
|
|
130
|
+
const t = e;
|
|
131
|
+
if (!t) return;
|
|
132
|
+
if (D.current = t, Z) {
|
|
133
|
+
_(!0);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
131
136
|
const i = new FileReader();
|
|
132
137
|
i.addEventListener("load", () => {
|
|
133
138
|
var w;
|
|
134
139
|
if (typeof i.result == "string") {
|
|
135
140
|
H(i.result);
|
|
136
|
-
const a = localStorage.getItem(
|
|
141
|
+
const a = localStorage.getItem(we), v = a ? JSON.parse(a) : void 0;
|
|
137
142
|
v && ((w = f.current) == null || w.setState(v)), setTimeout(() => {
|
|
138
|
-
|
|
143
|
+
ce(f.current);
|
|
139
144
|
}, 100);
|
|
140
145
|
}
|
|
141
146
|
}), i.readAsDataURL(t);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
147
|
+
},
|
|
148
|
+
[_, Z]
|
|
149
|
+
);
|
|
150
|
+
M(() => {
|
|
145
151
|
let e = !1;
|
|
146
152
|
return (async () => {
|
|
147
153
|
if (c == null || c === "") {
|
|
@@ -170,7 +176,7 @@ const et = ({
|
|
|
170
176
|
e = !0;
|
|
171
177
|
};
|
|
172
178
|
}, [c, b]);
|
|
173
|
-
const { t: h } =
|
|
179
|
+
const { t: h } = Ve(), Ne = ge(
|
|
174
180
|
() => y ? {
|
|
175
181
|
required: y,
|
|
176
182
|
validator: (e, t, i) => {
|
|
@@ -178,53 +184,53 @@ const et = ({
|
|
|
178
184
|
}
|
|
179
185
|
} : void 0,
|
|
180
186
|
[y, j, d == null ? void 0 : d.length, m, h]
|
|
181
|
-
),
|
|
182
|
-
() => /* @__PURE__ */
|
|
183
|
-
|
|
187
|
+
), ne = z ?? h("message.uploadButtonText"), se = ge(
|
|
188
|
+
() => /* @__PURE__ */ r(
|
|
189
|
+
Je,
|
|
184
190
|
{
|
|
185
|
-
showLoadingIndicator:
|
|
186
|
-
_buttonTitle:
|
|
187
|
-
buttonSize:
|
|
191
|
+
showLoadingIndicator: te,
|
|
192
|
+
_buttonTitle: ne,
|
|
193
|
+
buttonSize: k,
|
|
188
194
|
buttonType: n,
|
|
189
195
|
fileList: d,
|
|
190
|
-
hidePreview:
|
|
196
|
+
hidePreview: O,
|
|
191
197
|
icon: R,
|
|
192
198
|
loading: N,
|
|
193
|
-
listType:
|
|
199
|
+
listType: Y,
|
|
194
200
|
maxCount: s,
|
|
195
|
-
onChangeFile:
|
|
201
|
+
onChangeFile: ie,
|
|
196
202
|
onRemove: T,
|
|
197
203
|
showButtonText: B,
|
|
198
|
-
handlePreview:
|
|
204
|
+
handlePreview: je,
|
|
199
205
|
setFileList: g
|
|
200
206
|
}
|
|
201
207
|
),
|
|
202
208
|
[
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
209
|
+
te,
|
|
210
|
+
ne,
|
|
211
|
+
k,
|
|
206
212
|
n,
|
|
207
213
|
d,
|
|
208
|
-
|
|
214
|
+
O,
|
|
209
215
|
R,
|
|
210
216
|
N,
|
|
211
|
-
|
|
217
|
+
Y,
|
|
212
218
|
s,
|
|
213
|
-
|
|
219
|
+
ie,
|
|
214
220
|
T,
|
|
215
221
|
B
|
|
216
222
|
]
|
|
217
223
|
);
|
|
218
|
-
ke.current =
|
|
219
|
-
const [
|
|
220
|
-
|
|
224
|
+
ke.current = se.props.beforeUpload;
|
|
225
|
+
const [Pe, ae] = I(0), [Ue, le] = I(0), [A, ze] = I();
|
|
226
|
+
M(() => {
|
|
221
227
|
const e = setTimeout(() => {
|
|
222
|
-
|
|
228
|
+
A && localStorage.setItem(we, JSON.stringify(A));
|
|
223
229
|
}, 400);
|
|
224
230
|
return () => clearTimeout(e);
|
|
225
|
-
}, [
|
|
231
|
+
}, [A]), M(() => {
|
|
226
232
|
if (!j) {
|
|
227
|
-
|
|
233
|
+
ae(0), le(0);
|
|
228
234
|
const e = setTimeout(() => {
|
|
229
235
|
var t;
|
|
230
236
|
(t = f.current) == null || t.reset();
|
|
@@ -232,54 +238,54 @@ const et = ({
|
|
|
232
238
|
return () => clearTimeout(e);
|
|
233
239
|
}
|
|
234
240
|
}, [j]);
|
|
235
|
-
const
|
|
241
|
+
const ce = E(async (e) => {
|
|
236
242
|
if (e) {
|
|
237
243
|
const t = e.getCoordinates();
|
|
238
|
-
|
|
244
|
+
ze(e.getState()), ae((t == null ? void 0 : t.width) ?? 10), le((t == null ? void 0 : t.height) ?? 10);
|
|
239
245
|
}
|
|
240
246
|
}, []);
|
|
241
|
-
return /* @__PURE__ */ U(
|
|
242
|
-
/* @__PURE__ */
|
|
243
|
-
|
|
247
|
+
return /* @__PURE__ */ U(ue, { children: [
|
|
248
|
+
/* @__PURE__ */ r(
|
|
249
|
+
Me,
|
|
244
250
|
{
|
|
245
251
|
label: m,
|
|
246
|
-
...
|
|
247
|
-
name:
|
|
252
|
+
...q,
|
|
253
|
+
name: J,
|
|
248
254
|
className: "mb-0",
|
|
249
|
-
rules: [
|
|
250
|
-
children:
|
|
255
|
+
rules: [Ne, ...q.rules ?? []],
|
|
256
|
+
children: se
|
|
251
257
|
}
|
|
252
258
|
),
|
|
253
259
|
/* @__PURE__ */ U(
|
|
254
|
-
|
|
260
|
+
me,
|
|
255
261
|
{
|
|
256
262
|
open: !!j,
|
|
257
263
|
maskClosable: !1,
|
|
258
|
-
onOk: () =>
|
|
264
|
+
onOk: () => _(!1),
|
|
259
265
|
closable: !1,
|
|
260
266
|
okButtonProps: {
|
|
261
267
|
loading: V === "crop",
|
|
262
268
|
disabled: V === "skip-crop"
|
|
263
269
|
},
|
|
264
|
-
onCancel:
|
|
265
|
-
footer: (e, { CancelBtn: t, OkBtn: i }) =>
|
|
266
|
-
/* @__PURE__ */
|
|
267
|
-
/* @__PURE__ */
|
|
270
|
+
onCancel: xe,
|
|
271
|
+
footer: (e, { CancelBtn: t, OkBtn: i }) => be ? /* @__PURE__ */ U(fe, { children: [
|
|
272
|
+
/* @__PURE__ */ r(t, {}),
|
|
273
|
+
/* @__PURE__ */ r(
|
|
268
274
|
x,
|
|
269
275
|
{
|
|
270
276
|
type: "primary",
|
|
271
277
|
loading: V === "skip-crop",
|
|
272
278
|
disabled: V === "crop",
|
|
273
|
-
onClick: () =>
|
|
279
|
+
onClick: () => _(!0),
|
|
274
280
|
children: h("str.skipCrop")
|
|
275
281
|
}
|
|
276
282
|
),
|
|
277
|
-
/* @__PURE__ */
|
|
278
|
-
] }) : /* @__PURE__ */
|
|
283
|
+
/* @__PURE__ */ r(i, {})
|
|
284
|
+
] }) : /* @__PURE__ */ r(ue, { children: e }),
|
|
279
285
|
destroyOnHidden: !0,
|
|
280
286
|
children: [
|
|
281
|
-
/* @__PURE__ */
|
|
282
|
-
|
|
287
|
+
/* @__PURE__ */ r(
|
|
288
|
+
Be,
|
|
283
289
|
{
|
|
284
290
|
ref: f,
|
|
285
291
|
stencilProps: {
|
|
@@ -288,7 +294,7 @@ const et = ({
|
|
|
288
294
|
style: { border: "1px solid black" },
|
|
289
295
|
src: j,
|
|
290
296
|
onChange: (e) => {
|
|
291
|
-
|
|
297
|
+
ce(e);
|
|
292
298
|
},
|
|
293
299
|
aspectRatio: F ? {
|
|
294
300
|
minimum: F,
|
|
@@ -296,77 +302,77 @@ const et = ({
|
|
|
296
302
|
} : void 0
|
|
297
303
|
}
|
|
298
304
|
),
|
|
299
|
-
/* @__PURE__ */
|
|
300
|
-
/* @__PURE__ */
|
|
301
|
-
/* @__PURE__ */
|
|
305
|
+
/* @__PURE__ */ r("p", { className: "text-center", children: [Pe, Ue].join(" ⨉ ") }),
|
|
306
|
+
/* @__PURE__ */ r("div", { className: "mt-2 d-flex justify-content-center", children: /* @__PURE__ */ U(fe.Compact, { children: [
|
|
307
|
+
/* @__PURE__ */ r(
|
|
302
308
|
x,
|
|
303
309
|
{
|
|
304
310
|
size: "large",
|
|
305
311
|
tooltip: h("str.rotateLeft"),
|
|
306
|
-
icon: /* @__PURE__ */
|
|
307
|
-
onClick: () =>
|
|
312
|
+
icon: /* @__PURE__ */ r(Re, {}),
|
|
313
|
+
onClick: () => re(!0)
|
|
308
314
|
}
|
|
309
315
|
),
|
|
310
|
-
/* @__PURE__ */
|
|
316
|
+
/* @__PURE__ */ r(
|
|
311
317
|
x,
|
|
312
318
|
{
|
|
313
319
|
size: "large",
|
|
314
|
-
icon: /* @__PURE__ */
|
|
320
|
+
icon: /* @__PURE__ */ r(Te, {}),
|
|
315
321
|
tooltip: h("str.rotateRight"),
|
|
316
|
-
onClick: () =>
|
|
322
|
+
onClick: () => re(!1)
|
|
317
323
|
}
|
|
318
324
|
),
|
|
319
|
-
/* @__PURE__ */
|
|
325
|
+
/* @__PURE__ */ r(
|
|
320
326
|
x,
|
|
321
327
|
{
|
|
322
328
|
size: "large",
|
|
323
|
-
icon: /* @__PURE__ */
|
|
329
|
+
icon: /* @__PURE__ */ r(_e, {}),
|
|
324
330
|
tooltip: h("str.flipHorizontal"),
|
|
325
|
-
onClick: () =>
|
|
331
|
+
onClick: () => oe("h")
|
|
326
332
|
}
|
|
327
333
|
),
|
|
328
|
-
/* @__PURE__ */
|
|
334
|
+
/* @__PURE__ */ r(
|
|
329
335
|
x,
|
|
330
336
|
{
|
|
331
337
|
size: "large",
|
|
332
|
-
icon: /* @__PURE__ */
|
|
338
|
+
icon: /* @__PURE__ */ r(Ee, {}),
|
|
333
339
|
tooltip: h("str.flipVertical"),
|
|
334
|
-
onClick: () =>
|
|
340
|
+
onClick: () => oe("v")
|
|
335
341
|
}
|
|
336
342
|
)
|
|
337
343
|
] }) })
|
|
338
344
|
]
|
|
339
345
|
}
|
|
340
346
|
),
|
|
341
|
-
/* @__PURE__ */
|
|
342
|
-
|
|
347
|
+
/* @__PURE__ */ r(
|
|
348
|
+
me,
|
|
343
349
|
{
|
|
344
|
-
open:
|
|
345
|
-
title:
|
|
350
|
+
open: Oe,
|
|
351
|
+
title: ye,
|
|
346
352
|
footer: null,
|
|
347
|
-
onCancel:
|
|
348
|
-
children: /* @__PURE__ */
|
|
353
|
+
onCancel: Se,
|
|
354
|
+
children: /* @__PURE__ */ r("div", { className: "text-center", children: /* @__PURE__ */ r("img", { alt: "example", style: { maxWidth: "400px" }, src: Ie }) })
|
|
349
355
|
}
|
|
350
356
|
)
|
|
351
357
|
] });
|
|
352
|
-
},
|
|
358
|
+
}, Je = ({
|
|
353
359
|
_buttonTitle: c,
|
|
354
360
|
buttonSize: b,
|
|
355
361
|
buttonType: y,
|
|
356
362
|
fileList: n,
|
|
357
363
|
hidePreview: m,
|
|
358
|
-
icon:
|
|
364
|
+
icon: J,
|
|
359
365
|
loading: C,
|
|
360
366
|
maxCount: F,
|
|
361
367
|
onChangeFile: z,
|
|
362
|
-
onRemove:
|
|
363
|
-
showButtonText:
|
|
368
|
+
onRemove: O,
|
|
369
|
+
showButtonText: k,
|
|
364
370
|
handlePreview: B,
|
|
365
|
-
setFileList:
|
|
371
|
+
setFileList: X,
|
|
366
372
|
showLoadingIndicator: R,
|
|
367
373
|
listType: N = "picture"
|
|
368
374
|
}) => /* @__PURE__ */ U(
|
|
369
|
-
|
|
375
|
+
He,
|
|
370
376
|
{
|
|
371
377
|
accept: "image/x-png,image/gif,image/jpeg",
|
|
372
378
|
fileList: n,
|
|
@@ -381,21 +387,21 @@ const et = ({
|
|
|
381
387
|
showUploadList: !m,
|
|
382
388
|
onRemove: (s) => {
|
|
383
389
|
const S = n.filter((T) => s.uid !== T.uid);
|
|
384
|
-
|
|
390
|
+
O == null || O(s), X(S);
|
|
385
391
|
},
|
|
386
392
|
beforeUpload: async (s) => (z(s), !1),
|
|
387
393
|
maxCount: F,
|
|
388
394
|
children: [
|
|
389
|
-
R && /* @__PURE__ */
|
|
390
|
-
/* @__PURE__ */
|
|
395
|
+
R && /* @__PURE__ */ r(Le, {}),
|
|
396
|
+
/* @__PURE__ */ r("div", { className: "d-flex flex-column", children: n.length < F && (N === "picture-circle" ? /* @__PURE__ */ r(ve, {}) : /* @__PURE__ */ r(
|
|
391
397
|
x,
|
|
392
398
|
{
|
|
393
399
|
loading: C,
|
|
394
|
-
tooltip:
|
|
400
|
+
tooltip: k ? void 0 : c,
|
|
395
401
|
size: b,
|
|
396
|
-
icon:
|
|
397
|
-
type:
|
|
398
|
-
children:
|
|
402
|
+
icon: J,
|
|
403
|
+
type: k ? y : "text",
|
|
404
|
+
children: k ? c : void 0
|
|
399
405
|
}
|
|
400
406
|
)) })
|
|
401
407
|
]
|
|
@@ -403,6 +409,6 @@ const et = ({
|
|
|
403
409
|
n.length
|
|
404
410
|
);
|
|
405
411
|
export {
|
|
406
|
-
|
|
407
|
-
|
|
412
|
+
Je as UploadComponent,
|
|
413
|
+
tt as default
|
|
408
414
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),g=require("antd"),T=require("react"),Y=require("react-highlight-words"),Z=require("../locale/index.cjs.js"),ee=require("./FileCrudField.cjs.js"),te=require("./ImageCrudField.cjs.js"),re=require("../common/check-box/CheckBox.cjs.js"),ne=require("../common/date-picker/DatePicker.cjs.js"),ae=require("../common/date-picker/TimePicker.cjs.js"),D=require("../common/select/SelectComponent.cjs.js"),oe=require("../common/text-field/NumberField.cjs.js"),le=require("../common/text-field/PhoneNumberField.cjs.js"),se=require("../common/text-field/TextField.cjs.js"),ie=require("../common/tooltip/TooltipComponent.cjs.js"),de=require("./CrudTextAreaComponent.cjs.js"),_=require("../util/CrudUtil.cjs.js"),E=require("../context/CrudSearchContext.cjs.js");function ce(F){const{label:s,name:d,type:c,required:h,hidden:O,rules:b=[],updatable:m=!0,readonly:y=!1,fieldClassName:f,customFormFieldRender:k,fieldTooltip:S,fieldHelper:p,formLayoutProps:q,...t}=F,l=g.Form.useFormInstance();T.useEffect(()=>{if(c==="select"){const{items:a=[],onSearch:o,searchOnType:u}=t;!(a!=null&&a.length)&&!u&&(o==null||o(void 0,l,t==null?void 0:t.updatingValue))}},[l,t,c,t==null?void 0:t.updatingValue]);const R=E.useCrudSearchContext(),x=T.useCallback((a,o)=>{R&&R.search(),!y&&o&&o(a,l)},[R,y,l]);if(y||O)return e.jsx(e.Fragment,{});if(k)return k(l,F);switch(c){case"text":case"email":case"password":{const{maxLength:a,onChange:o,placeholder:u,addonAfter:v,addonBefore:i}=t;return e.jsx(se.default,{...q,maxLength:a,placeholder:u,disabled:!m,rules:b,required:h,onChange:o?N=>o(N,l):void 0,type:c,name:d,tooltip:S,label:s,className:f,autoComplete:"new-password",addonAfter:v,addonBefore:i,help:p})}case"phone":{const{onChange:a,placeholder:o,addonAfter:u,addonBefore:v}=t;return e.jsx(le,{...t,...q,placeholder:o,disabled:!m,rules:b,required:h,onChange:a?i=>a(i,l):void 0,type:c,name:d,tooltip:S,label:s,className:f,autoComplete:"new-password",addonAfter:u,addonBefore:v,help:p})}case"number":{const{onChange:a,placeholder:o,allowMinus:u,min:v,max:i,addonAfter:N,addonBefore:w,int:P,step:n,changeOnWheel:j=!1}=t;return e.jsx(oe,{...q,step:n,changeOnWheel:j,placeholder:o,disabled:!m,moneyField:!!t.formatted,type:c,onChange:a?H=>a(H,l):void 0,rules:b,autoComplete:"false",required:h,tooltip:S,className:f,min:u?null:v,max:i,addonAfter:N,addonBefore:w,name:d,label:s,help:p,isInt:P})}case"date":{const{range:a,disableToday:o,disabledFutureDays:u,disabledPastDays:v,onChange:i,placeholder:N,format:w}=t;return e.jsx(ne,{...q,placeholder:N,required:h,disabled:!m,type:c,format:w,tooltip:S,range:a,name:d,label:s,onChange:x,className:f,disableToday:o,disabledFutureDays:u,disabledPastDays:v,help:p})}case"time":{const{range:a=!1,disableCurrent:o,disabledFuture:u,disabledPast:v,onChange:i,use12Hours:N,format:w,placeholder:P}=t;return e.jsx(ae,{...q,placeholder:P,required:h,format:w,disabled:!m,type:c,tooltip:S,range:a,use12Hours:N,name:d,label:s,onChange:x,className:f,disableCurrent:o,disabledFuture:u,disabledPast:v,help:p})}case"textarea":return e.jsx(de,{...F});case"image":return e.jsx(te.default,{...t,required:h,name:d,label:s,rules:b,fieldHelper:p,fieldClassName:f,onRemoved:t.onRemoved,onUploadComplete:t.onUploadComplete,onUploading:t.onUploading,provider:t.provider});case"file":return e.jsx(ee.default,{...t,required:h,name:d,label:s,rules:b,fieldHelper:p,fieldClassName:f,onRemoved:t.onRemoved,onUploadComplete:t.onUploadComplete,onUploading:t.onUploading,provider:t.provider});case"select":return e.jsx($,{...t,required:h,name:d,label:s,rules:b,fieldClassName:f,form:l,help:p,updatable:m,readonly:y,fieldTooltip:S,fieldHelper:p});case"enum":return e.jsx(W,{...F});case"checkbox":{const{onChange:a,switch:o}=t;return e.jsx(re,{...q,className:f,rules:b,onChange:x,label:s,tooltip:S,disabled:!m,name:d,help:p,switch:o})}case"color":return e.jsx(z,{...t,type:"color",required:h,name:d,label:s,rules:b,fieldClassName:f,updatable:m,readonly:y,fieldTooltip:S,fieldHelper:p});default:return e.jsx(e.Fragment,{children:`${c} Not Implemented`})}}function W(F){const s=g.Form.useFormInstance(),{label:d,name:c,type:h,required:O,hidden:b,rules:m=[],updatable:y=!0,readonly:f=!1,fieldClassName:k,customFormFieldRender:S,fieldTooltip:p,fieldHelper:q,formLayoutProps:t,...l}=F,{t:R}=Z.useTranslationLibNoNS(),{enum:x,translation:a,onChange:o,onSearch:u,multiple:v,tagRender:i}=l,N=Array.isArray(x)?x:Object.keys(x),w=E.useCrudSearchContext(),P=T.useCallback(n=>{w&&w.search(),!f&&o&&o(n,s)},[w,f,o,s]);return"radio"in l&&l.radio?e.jsx(g.Form.Item,{...l,...t,name:c,required:O,tooltip:p,rules:m,label:d,className:["w-100",k].join(" "),help:q,children:e.jsx(g.Radio.Group,{...l,onChange:n=>{var j;return P((j=n==null?void 0:n.target)==null?void 0:j.value)},children:N.map(n=>e.jsx(g.Radio,{disabled:!y,value:n,children:a?R(a[n]):n},n))})}):"checkbox"in l&&l.checkbox?e.jsx(g.Form.Item,{...l,...t,name:c,required:O,tooltip:p,rules:m,label:d,className:["w-100",k].join(" "),help:q,children:e.jsx(g.Checkbox.Group,{className:"w-100",onChange:P,children:N.map(n=>{const j=e.jsx(g.Checkbox,{disabled:!y,value:n,children:a?R(a[n]):n},n);return"checkboxGrid"in l&&l.checkboxGrid?e.jsx(g.Col,{...l.checkboxGrid,children:j}):j})})}):e.jsx(D,{...l,...t,notSearch:!0,tagRender:typeof i=="function"?i:i?n=>{const{value:j,label:H}=n,I=i[j];return I?e.jsx(g.Tag,{color:I.color,children:H}):e.jsx(g.Tag,{children:H})}:void 0,onChange:P,className:["w-100",k].join(" "),name:c,items:N,required:O,tooltip:p,rules:m,label:d,help:q,disabled:!y,onSearch:u?n=>u(n,s):void 0,allowClear:!0,mode:v?"multiple":void 0,showLoadingInEmptyIndicator:!0,itemBuilder:n=>e.jsx(g.Select.Option,{value:n,children:a?R(a[n]):n},n)})}function $(F){const{items:s=[],loading:d,searchOnType:c,onSearch:h,multiple:O,onChange:b,highlightSearch:m,required:y,fieldClassName:f,rules:k,fieldTooltip:S,updatable:p,label:q,name:t,tagRender:l,updatingValue:R,onSet:x,placeholder:a,allowClear:o=!0,selectOptionRender:u,formLayoutProps:v}=F,i=F.form,[N,w]=T.useState(""),P=T.useMemo(()=>_.getRealName(t),[t]),n=T.useMemo(()=>_.getRealName(t,"upsertFieldName"),[t]),j=g.Form.useWatch(P,i),[H,I]=T.useState(!0);T.useEffect(()=>{x&&H&&j&&(x==null||x(j,s,i),I(!1))},[H,i,s,P,x,j]),T.useEffect(()=>{j&&I(!0)},[j]);const J=T.useCallback(async r=>{w(r),c&&(h==null||h(r,i,R))},[i,h,c,R]),K=T.useCallback(r=>u?u(r):r.value,[u]),L=E.useCrudSearchContext(),Q=T.useCallback(r=>{L&&L.search(),b&&(w(""),b(r,i))},[L,b,i]);return e.jsx(D,{...F,...v,showLoadingInEmptyIndicator:!0,maxTagCount:"responsive",maxTagPlaceholder:r=>e.jsxs(ie,{title:e.jsx(e.Fragment,{children:r.map(C=>e.jsxs(e.Fragment,{children:[C.label," ",e.jsx("br",{})]}))}),children:["+",r==null?void 0:r.length]}),placeholder:a,onSelect:r=>{x==null||x(r==null?void 0:r.key,s,i)},onChange:Q,mode:O?"multiple":void 0,className:["w-100",f].join(" "),name:n,items:s,required:y,tooltip:S,tagRender:l,rules:k,disabled:!p,label:q,allowClear:o,onSearch:J,loading:d,filterOption:m?(r,C)=>{var U,A,B;try{const G=r.toLowerCase().split(/\s+/),V=((typeof(C==null?void 0:C.children)=="string"?C==null?void 0:C.children:(A=(U=C==null?void 0:C.children)==null?void 0:U.props)==null?void 0:A.textToHighlight)??"").toLowerCase(),X=(((B=C==null?void 0:C.value)==null?void 0:B.toString())??"").toLowerCase();return G.every(M=>V.indexOf(M)>=0||X.indexOf(M)>=0)}catch{return!0}}:void 0,itemBuilder:m?r=>{const C=r.value?String(r.value):void 0;return e.jsx(g.Select.Option,{value:r.key,title:C,disabled:r.disabled,children:e.jsx(Y,{highlightClassName:"highlight-text",searchWords:(N??"").split(" "),autoEscape:!0,textToHighlight:C??""})},r.key)}:r=>e.jsx(g.Select.Option,{value:r.key,title:r.value,disabled:r.disabled,children:K(r)},r.key)})}function z(F){const{formLayoutProps:s,required:d,fieldClassName:c,rules:h,fieldTooltip:O,updatable:b,label:m,name:y,fieldHelper:f}=F;return e.jsx(g.Form.Item,{...s,label:m,name:y,required:d,rules:h,tooltip:O,help:f,getValueFromEvent:k=>typeof k=="object"?k.toHexString():k,children:e.jsx(g.ColorPicker,{disabledAlpha:!0,format:"hex",defaultFormat:"hex",showText:!0,trigger:"click",className:c,disabled:!b,...F.innerProps})})}exports.ColorCrudFieldComponent=z;exports.EnumCrudFieldComponent=W;exports.SelectCrudFieldComponent=$;exports.default=ce;
|