@kingteza/crud-component 1.44.0 → 1.44.2
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 +4 -2
- package/dist/common/picker/ImagePicker.es.js +291 -251
- package/dist/crud/FileCrudField.cjs.js +1 -1
- package/dist/crud/FileCrudField.es.js +18 -17
- package/dist/crud/ImageCrudField.cjs.js +1 -1
- package/dist/crud/ImageCrudField.d.ts +1 -1
- package/dist/crud/ImageCrudField.es.js +127 -92
- package/dist/crud/modal/index.cjs.js +1 -1
- package/dist/crud/modal/index.es.js +120 -109
- 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"),d=require("@ant-design/icons"),F=require("antd"),k=require("mime"),c=require("react"),Q=require("../locale/index.cjs.js"),X=require("../util/ValidationUtil.cjs.js"),q=require("../common/button/Button.cjs.js"),Y=require("../common/layout/VerticalSpace.cjs.js"),Z=require("../util/CrudUtil.cjs.js"),B=require("../util/ImageUtil.cjs.js");function v({name:n,label:e,required:l,provider:s,onUploading:a,onRemoved:f,fieldClassName:j,accept:
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("react/jsx-runtime"),d=require("@ant-design/icons"),F=require("antd"),k=require("mime"),c=require("react"),Q=require("../locale/index.cjs.js"),X=require("../util/ValidationUtil.cjs.js"),q=require("../common/button/Button.cjs.js"),Y=require("../common/layout/VerticalSpace.cjs.js"),Z=require("../util/CrudUtil.cjs.js"),B=require("../util/ImageUtil.cjs.js");function v({name:n,label:e,required:l,provider:s,onUploading:a,onRemoved:f,fieldClassName:j,accept:I,rules:U,maxCount:b=1,block:_,fieldHelper:$,formLayoutProps:H,preprocessBeforeUpload:w,...R}){const h=F.Form.useFormInstance(),A=Z.getRealName(n,"upsertFieldName"),x=F.Form.useWatch(A,h),[V,S]=c.useState(!1),[p,L]=c.useState(!1),W=c.useCallback(async r=>{var o,u;try{const{file:i}=r,C=i.name;S(!0),L(!0),a==null||a(!0);const P=C??"",D=P.split("."),G=D[D.length-1],J=s.generateFileName(P),K=`${await s.getInitialPath()}/${J}.${G}`;let O=i;w&&(typeof w=="function"?O=await w(i):w.compressImage&&(O=await B.resizeImage(i)));const N=await s.upload({...i,originFileObj:O},K);a==null||a(!1),h.setFieldValue(n,N),(o=r.onSuccess)==null||o.call(r,N)}catch(i){(u=r.onError)==null||u.call(r,i)}finally{S(!1)}},[h,n,a,s]),[g,M]=c.useState([]);c.useEffect(()=>{!p&&x&&Promise.all((Array.isArray(x)?x:[x]).map(async r=>{const o=k.getType(r),u=r.split("/").pop(),i=await s.getRealUrl(r);return{uid:r,url:i,type:o,name:u}})).then(r=>M(()=>r.map(({url:u,type:i,uid:C,name:P})=>({uid:C,url:u,type:i,response:C,thumbUrl:u,name:P}))))},[x,p,V,s]);const z=c.useCallback(async r=>{const o=r.response,u=o||h.getFieldValue(n);await s.delete(u),f==null||f(),r&&h.setFieldsValue({[n]:null})},[h,n,f,s]);return t.jsxs(F.Form.Item,{label:e,required:l,name:n,...H,className:j,rules:[...l?X.required(e):[],...U??[]],help:$,children:[t.jsx("input",{hidden:!0}),t.jsx(F.Upload,{...R,fileList:g,className:((g==null?void 0:g.length)??0)>=b?"hide-upload":"",maxCount:b,customRequest:W,onRemove:z,listType:"picture",onChange:({fileList:r})=>{M(r)},accept:I,style:_?{width:"100%"}:void 0,children:t.jsx(q,{loading:V,children:"Upload File"})})]})}const y=({provider:n,value:e})=>{const[l,s]=c.useState();return c.useEffect(()=>{e&&n.getRealUrl(e).then(a=>{s({mimeType:k.getType(e),url:a,fileName:e.split("/").pop()??e})})},[n,e]),l?t.jsx(E,{fileName:l.fileName,url:l==null?void 0:l.url,mimeType:l==null?void 0:l.mimeType}):t.jsx(t.Fragment,{})},E=({url:n,mimeType:e="",fileName:l})=>{const s=c.useMemo(()=>e!=null&&e.includes("image")?"image":e!=null&&e.includes("pdf")?"pdf":e!=null&&e.includes("word")?"word":e!=null&&e.includes("text")?"text":e!=null&&e.includes("presentation")?"presentation":e!=null&&e.includes("excel")||e!=null&&e.includes("spreadsheet")?"excel":"file",[e]),a=c.useMemo(()=>{switch(s){case"image":return t.jsx(d.FileImageOutlined,{});case"pdf":return t.jsx(d.FilePdfOutlined,{});case"word":return t.jsx(d.FileWordOutlined,{});case"text":return t.jsx(d.FileTextOutlined,{});case"excel":return t.jsx(d.FileExcelOutlined,{});case"presentation":return t.jsx(d.FilePptOutlined,{});default:return t.jsx(d.FileOutlined,{})}},[s]),[f,j]=c.useState(!1),{t:I}=Q.useTranslationLib();return s!=="file"&&s!=="text"?t.jsxs(t.Fragment,{children:[t.jsx(F.Modal,{open:f,title:l,onCancel:()=>j(!1),footer:t.jsx(t.Fragment,{}),width:"100%",style:{top:"8px",minHeight:"700px"},destroyOnHidden:!0,children:t.jsxs(Y,{children:[t.jsx(q,{tooltip:l,icon:t.jsx(d.ExportOutlined,{}),target:"_blank",href:n,style:{textDecoration:"none"},children:I("str.openInNewTab")}),s==="image"?t.jsx("img",{src:n,alt:l,style:{width:"100%"}}):s==="pdf"?t.jsxs("iframe",{title:l,src:n,width:"100%",height:"700px",children:["This browser does not support PDFs. Please download the PDF to view it:",t.jsx("a",{href:n,children:"Download PDF"})]}):t.jsxs("iframe",{title:l,src:`https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(n)}`,width:"100%",height:"700px",children:["This browser does not support open ",s.toUpperCase(),". Please download the",s.toUpperCase()," to view it:",t.jsxs("a",{href:n,children:["Download ",s.toUpperCase()]}),"."]})]})}),t.jsx(q,{tooltip:l,icon:a,shape:"circle",onClick:()=>j(!0)})]}):t.jsx(q,{tooltip:l,icon:a,target:"_blank",href:n,shape:"circle"})};exports.FileCellValue=E;exports.FileCrudCellValue=y;exports.default=v;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsxs as f, jsx as s, Fragment as
|
|
1
|
+
import { jsxs as f, jsx as s, Fragment as V } from "react/jsx-runtime";
|
|
2
2
|
import { FileOutlined as Z, FilePptOutlined as B, FileExcelOutlined as m, FileTextOutlined as v, FileWordOutlined as y, FilePdfOutlined as T, FileImageOutlined as tt, ExportOutlined as et } from "@ant-design/icons";
|
|
3
|
-
import { Form as
|
|
3
|
+
import { Form as b, Upload as st, Modal as lt } from "antd";
|
|
4
4
|
import S from "mime";
|
|
5
5
|
import { useState as w, useCallback as j, useEffect as A, useMemo as H } from "react";
|
|
6
6
|
import { useTranslationLib as rt } from "../locale/index.es.js";
|
|
@@ -17,26 +17,26 @@ function It({
|
|
|
17
17
|
onUploading: a,
|
|
18
18
|
onRemoved: u,
|
|
19
19
|
fieldClassName: F,
|
|
20
|
-
accept:
|
|
20
|
+
accept: I,
|
|
21
21
|
rules: L,
|
|
22
22
|
maxCount: D = 1,
|
|
23
23
|
block: W,
|
|
24
24
|
fieldHelper: _,
|
|
25
25
|
formLayoutProps: q,
|
|
26
|
-
preprocessBeforeUpload:
|
|
26
|
+
preprocessBeforeUpload: g,
|
|
27
27
|
...z
|
|
28
28
|
}) {
|
|
29
|
-
const d =
|
|
29
|
+
const d = b.useFormInstance(), R = it.getRealName(n, "upsertFieldName"), h = b.useWatch(R, d), [N, k] = w(!1), [E, G] = w(!1), J = j(
|
|
30
30
|
async (r) => {
|
|
31
31
|
var o, c;
|
|
32
32
|
try {
|
|
33
33
|
const { file: i } = r, x = i.name;
|
|
34
34
|
k(!0), G(!0), a == null || a(!0);
|
|
35
35
|
const C = x ?? "", U = C.split("."), Q = U[U.length - 1], X = e.generateFileName(C), Y = `${await e.getInitialPath()}/${X}.${Q}`;
|
|
36
|
-
let
|
|
37
|
-
|
|
36
|
+
let O = i;
|
|
37
|
+
g && (typeof g == "function" ? O = await g(i) : g.compressImage && (O = await ct.resizeImage(i)));
|
|
38
38
|
const $ = await e.upload(
|
|
39
|
-
{ ...i, originFileObj:
|
|
39
|
+
{ ...i, originFileObj: O },
|
|
40
40
|
Y
|
|
41
41
|
);
|
|
42
42
|
a == null || a(!1), d.setFieldValue(n, $), (o = r.onSuccess) == null || o.call(r, $);
|
|
@@ -47,7 +47,7 @@ function It({
|
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
[d, n, a, e]
|
|
50
|
-
), [
|
|
50
|
+
), [p, M] = w([]);
|
|
51
51
|
A(() => {
|
|
52
52
|
!E && h && Promise.all(
|
|
53
53
|
(Array.isArray(h) ? h : [h]).map(
|
|
@@ -71,7 +71,7 @@ function It({
|
|
|
71
71
|
[d, n, u, e]
|
|
72
72
|
);
|
|
73
73
|
return /* @__PURE__ */ f(
|
|
74
|
-
|
|
74
|
+
b.Item,
|
|
75
75
|
{
|
|
76
76
|
label: t,
|
|
77
77
|
required: l,
|
|
@@ -89,8 +89,8 @@ function It({
|
|
|
89
89
|
st,
|
|
90
90
|
{
|
|
91
91
|
...z,
|
|
92
|
-
fileList:
|
|
93
|
-
className: ((
|
|
92
|
+
fileList: p,
|
|
93
|
+
className: ((p == null ? void 0 : p.length) ?? 0) >= D ? "hide-upload" : "",
|
|
94
94
|
maxCount: D,
|
|
95
95
|
customRequest: J,
|
|
96
96
|
onRemove: K,
|
|
@@ -98,6 +98,7 @@ function It({
|
|
|
98
98
|
onChange: ({ fileList: r }) => {
|
|
99
99
|
M(r);
|
|
100
100
|
},
|
|
101
|
+
accept: I,
|
|
101
102
|
style: W ? { width: "100%" } : void 0,
|
|
102
103
|
children: /* @__PURE__ */ s(P, { loading: N, children: "Upload File" })
|
|
103
104
|
}
|
|
@@ -123,7 +124,7 @@ const Ot = ({ provider: n, value: t }) => {
|
|
|
123
124
|
url: l == null ? void 0 : l.url,
|
|
124
125
|
mimeType: l == null ? void 0 : l.mimeType
|
|
125
126
|
}
|
|
126
|
-
) : /* @__PURE__ */ s(
|
|
127
|
+
) : /* @__PURE__ */ s(V, {});
|
|
127
128
|
}, ot = ({ url: n, mimeType: t = "", fileName: l }) => {
|
|
128
129
|
const e = H(() => t != null && t.includes("image") ? "image" : t != null && t.includes("pdf") ? "pdf" : t != null && t.includes("word") ? "word" : t != null && t.includes("text") ? "text" : t != null && t.includes("presentation") ? "presentation" : t != null && t.includes("excel") || t != null && t.includes("spreadsheet") ? "excel" : "file", [t]), a = H(() => {
|
|
129
130
|
switch (e) {
|
|
@@ -142,15 +143,15 @@ const Ot = ({ provider: n, value: t }) => {
|
|
|
142
143
|
default:
|
|
143
144
|
return /* @__PURE__ */ s(Z, {});
|
|
144
145
|
}
|
|
145
|
-
}, [e]), [u, F] = w(!1), { t:
|
|
146
|
-
return e !== "file" && e !== "text" ? /* @__PURE__ */ f(
|
|
146
|
+
}, [e]), [u, F] = w(!1), { t: I } = rt();
|
|
147
|
+
return e !== "file" && e !== "text" ? /* @__PURE__ */ f(V, { children: [
|
|
147
148
|
/* @__PURE__ */ s(
|
|
148
149
|
lt,
|
|
149
150
|
{
|
|
150
151
|
open: u,
|
|
151
152
|
title: l,
|
|
152
153
|
onCancel: () => F(!1),
|
|
153
|
-
footer: /* @__PURE__ */ s(
|
|
154
|
+
footer: /* @__PURE__ */ s(V, {}),
|
|
154
155
|
width: "100%",
|
|
155
156
|
style: { top: "8px", minHeight: "700px" },
|
|
156
157
|
destroyOnHidden: !0,
|
|
@@ -163,7 +164,7 @@ const Ot = ({ provider: n, value: t }) => {
|
|
|
163
164
|
target: "_blank",
|
|
164
165
|
href: n,
|
|
165
166
|
style: { textDecoration: "none" },
|
|
166
|
-
children:
|
|
167
|
+
children: I("str.openInNewTab")
|
|
167
168
|
}
|
|
168
169
|
),
|
|
169
170
|
e === "image" ? /* @__PURE__ */ s("img", { src: n, alt: l, style: { width: "100%" } }) : e === "pdf" ? /* @__PURE__ */ f("iframe", { title: l, src: n, width: "100%", height: "700px", children: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var H=Object.defineProperty;var
|
|
1
|
+
"use strict";var H=Object.defineProperty;var T=(s,e,t)=>e in s?H(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var q=(s,e,t)=>T(s,typeof e!="symbol"?e+"":e,t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("react/jsx-runtime"),W=require("@ant-design/icons"),F=require("antd"),x=require("path-browserify"),d=require("react"),G=require("../util/NumberUtil.cjs.js"),J=require("../util/ValidationUtil.cjs.js"),K=require("uuid"),L=require("../common/picker/ImagePicker.cjs.js"),Q=require("../util/ImageUtil.cjs.js");class N{}class X 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_${G.default.randInt(1e5)}`;return x.format({dir:l.dir,ext:l.ext,name:a})}generateFileName(t){return`${t.split(".")[0]}_${K.v4().replace("-","")}`}}function Y({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,skipResize:_=!1,asyncUpload:B=!1,maxCount:h=1},M){const f=F.Form.useFormInstance(),o=e,y=F.Form.useWatch(o,f),z=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 E=Array.isArray(V)?V:V?[V]:[];f.setFieldValue(o,[...E,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(M,()=>({async uploadBlob(r,P){const u=await Q.getBase64(r),c={name:P,uid:P+Math.random().toString(36).substring(2,15),url:u,originFileObj:r};await g(c,!0)}}),[g]);const D=d.useMemo(()=>y?(Array.isArray(y),y):h>1?[]:void 0,[y,h]);return n.jsxs(F.Form.Item,{rules:l?J.required(t):[],label:k?null:t,required:l,name:o,help:O,...s,className:A,children:[n.jsx(L.default,{noStyle:!0,asyncUpload:B,listType:C,aspectRatio:$,values:D,getRealUrl:z,onRemove:r=>{r&&g(r,!1)},onAdd:async r=>{if(r)return g(r,!0)},className:A,showSkipCropButton:S,skipResize:_,maxCount:h}),n.jsx(F.Input,{hidden:!0})]})}const Z=d.forwardRef(Y),U=({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(W.EyeOutlined,{})}})});exports.FileDownloadProvider=N;exports.FileUploadProvider=X;exports.ImageCellValue=b;exports.ImageCrudCellValue=U;exports.default=Z;
|
|
@@ -40,7 +40,7 @@ declare const ImageCrudField: <T>(p: Readonly<_ImageCrudField<T>> & {
|
|
|
40
40
|
}) => ReactElement;
|
|
41
41
|
export default ImageCrudField;
|
|
42
42
|
export declare const ImageCrudCellValue: FC<{
|
|
43
|
-
value: string;
|
|
43
|
+
value: string | string[];
|
|
44
44
|
provider: FileDownloadProvider;
|
|
45
45
|
}>;
|
|
46
46
|
export declare const ImageCellValue: FC<{
|
|
@@ -1,139 +1,174 @@
|
|
|
1
|
-
var
|
|
2
|
-
var W = (
|
|
3
|
-
var
|
|
4
|
-
import { jsx as
|
|
1
|
+
var D = Object.defineProperty;
|
|
2
|
+
var W = (s, e, t) => e in s ? D(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
+
var w = (s, e, t) => W(s, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { jsx as o, Fragment as $, jsxs as q } from "react/jsx-runtime";
|
|
5
5
|
import { EyeOutlined as G } from "@ant-design/icons";
|
|
6
|
-
import { Avatar as J, Image as K, Form as
|
|
7
|
-
import
|
|
8
|
-
import Q, { useState as
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import { v4 as
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
class
|
|
6
|
+
import { Avatar as J, Image as K, Form as I, Input as L } from "antd";
|
|
7
|
+
import b from "path-browserify";
|
|
8
|
+
import Q, { useState as T, useEffect as X, useCallback as k, useImperativeHandle as Y, useMemo as Z } from "react";
|
|
9
|
+
import U from "../util/NumberUtil.es.js";
|
|
10
|
+
import R from "../util/ValidationUtil.es.js";
|
|
11
|
+
import { v4 as v } from "uuid";
|
|
12
|
+
import ee from "../common/picker/ImagePicker.es.js";
|
|
13
|
+
import te from "../util/ImageUtil.es.js";
|
|
14
|
+
class ae {
|
|
15
15
|
}
|
|
16
|
-
class Fe extends
|
|
17
|
-
constructor(t = "",
|
|
16
|
+
class Fe extends ae {
|
|
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_${U.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]}_${v().replace("-", "")}`;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
function
|
|
36
|
-
formLayoutProps:
|
|
35
|
+
function re({
|
|
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
|
-
skipResize:
|
|
50
|
-
asyncUpload:
|
|
51
|
-
maxCount:
|
|
52
|
-
},
|
|
53
|
-
const
|
|
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
|
+
skipResize: _ = !1,
|
|
50
|
+
asyncUpload: x = !1,
|
|
51
|
+
maxCount: h = 1
|
|
52
|
+
}, E) {
|
|
53
|
+
const m = I.useFormInstance(), u = e, d = I.useWatch(u, m), H = k(
|
|
54
|
+
(r) => a.getRealUrl(r),
|
|
55
|
+
[a]
|
|
56
|
+
), y = k(
|
|
57
|
+
async (r, F) => {
|
|
58
|
+
if (F) {
|
|
56
59
|
n == null || n(!0);
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
try {
|
|
61
|
+
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);
|
|
62
|
+
if (h > 1) {
|
|
63
|
+
const C = Array.isArray(P) ? P : P ? [P] : [];
|
|
64
|
+
m.setFieldValue(u, [
|
|
65
|
+
...C,
|
|
66
|
+
V
|
|
67
|
+
].filter(Boolean));
|
|
68
|
+
} else
|
|
69
|
+
m.setFieldValue(u, V);
|
|
70
|
+
return V;
|
|
71
|
+
} finally {
|
|
72
|
+
n == null || n(!1);
|
|
73
|
+
}
|
|
59
74
|
} else {
|
|
60
|
-
const
|
|
61
|
-
|
|
75
|
+
const i = m.getFieldValue(u);
|
|
76
|
+
if (h > 1) {
|
|
77
|
+
const c = r.response ?? (typeof r.uid == "string" ? r.uid : void 0);
|
|
78
|
+
if (!c) return;
|
|
79
|
+
await a.delete(c), f == null || f();
|
|
80
|
+
const p = (Array.isArray(i) ? i : i ? [i] : []).filter((g) => g !== c);
|
|
81
|
+
m.setFieldValue(
|
|
82
|
+
u,
|
|
83
|
+
p.length ? p : null
|
|
84
|
+
);
|
|
85
|
+
} else {
|
|
86
|
+
const c = await a.delete(i);
|
|
87
|
+
f == null || f(), c && m.setFieldValue(u, null);
|
|
88
|
+
}
|
|
62
89
|
}
|
|
63
90
|
},
|
|
64
|
-
[
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}, [F, g, l, p]), T(
|
|
69
|
-
_,
|
|
91
|
+
[m, h, u, f, n, a]
|
|
92
|
+
);
|
|
93
|
+
Y(
|
|
94
|
+
E,
|
|
70
95
|
() => ({
|
|
71
|
-
async uploadBlob(r,
|
|
72
|
-
const
|
|
73
|
-
name:
|
|
74
|
-
uid:
|
|
75
|
-
url:
|
|
96
|
+
async uploadBlob(r, F) {
|
|
97
|
+
const i = await te.getBase64(r), c = {
|
|
98
|
+
name: F,
|
|
99
|
+
uid: F + Math.random().toString(36).substring(2, 15),
|
|
100
|
+
url: i,
|
|
76
101
|
originFileObj: r
|
|
77
102
|
};
|
|
78
|
-
|
|
103
|
+
await y(c, !0);
|
|
79
104
|
}
|
|
80
105
|
}),
|
|
81
|
-
[
|
|
82
|
-
)
|
|
83
|
-
|
|
106
|
+
[y]
|
|
107
|
+
);
|
|
108
|
+
const M = Z(() => d ? (Array.isArray(d), d) : h > 1 ? [] : void 0, [d, h]);
|
|
109
|
+
return /* @__PURE__ */ q(
|
|
110
|
+
I.Item,
|
|
84
111
|
{
|
|
85
|
-
rules:
|
|
86
|
-
label:
|
|
87
|
-
required:
|
|
88
|
-
name:
|
|
89
|
-
help:
|
|
90
|
-
...
|
|
91
|
-
className:
|
|
112
|
+
rules: l ? R.required(t) : [],
|
|
113
|
+
label: O ? null : t,
|
|
114
|
+
required: l,
|
|
115
|
+
name: u,
|
|
116
|
+
help: z,
|
|
117
|
+
...s,
|
|
118
|
+
className: A,
|
|
92
119
|
children: [
|
|
93
|
-
/* @__PURE__ */
|
|
94
|
-
|
|
120
|
+
/* @__PURE__ */ o(
|
|
121
|
+
ee,
|
|
95
122
|
{
|
|
96
123
|
noStyle: !0,
|
|
97
|
-
asyncUpload:
|
|
98
|
-
listType:
|
|
99
|
-
aspectRatio:
|
|
100
|
-
values:
|
|
124
|
+
asyncUpload: x,
|
|
125
|
+
listType: j,
|
|
126
|
+
aspectRatio: B,
|
|
127
|
+
values: M,
|
|
128
|
+
getRealUrl: H,
|
|
101
129
|
onRemove: (r) => {
|
|
102
|
-
r &&
|
|
130
|
+
r && y(r, !1);
|
|
103
131
|
},
|
|
104
132
|
onAdd: async (r) => {
|
|
105
|
-
r
|
|
133
|
+
if (r) return y(r, !0);
|
|
106
134
|
},
|
|
107
|
-
className:
|
|
108
|
-
showSkipCropButton:
|
|
109
|
-
skipResize:
|
|
110
|
-
maxCount:
|
|
135
|
+
className: A,
|
|
136
|
+
showSkipCropButton: S,
|
|
137
|
+
skipResize: _,
|
|
138
|
+
maxCount: h
|
|
111
139
|
}
|
|
112
140
|
),
|
|
113
|
-
/* @__PURE__ */
|
|
141
|
+
/* @__PURE__ */ o(L, { hidden: !0 })
|
|
114
142
|
]
|
|
115
143
|
}
|
|
116
144
|
);
|
|
117
145
|
}
|
|
118
|
-
const pe = Q.forwardRef(
|
|
119
|
-
const [t,
|
|
120
|
-
return
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
146
|
+
const pe = Q.forwardRef(re), Pe = ({ provider: s, value: e }) => {
|
|
147
|
+
const [t, l] = T([]);
|
|
148
|
+
return X(() => {
|
|
149
|
+
if (!e) {
|
|
150
|
+
l([]);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const a = Array.isArray(e) ? e : [e];
|
|
154
|
+
Promise.all(a.filter(Boolean).map((n) => s.getRealUrl(n))).then(
|
|
155
|
+
l
|
|
156
|
+
);
|
|
157
|
+
}, [s, e]), t.length ? /* @__PURE__ */ o($, { children: t.map((a) => /* @__PURE__ */ o(se, { url: a }, a)) }) : /* @__PURE__ */ o($, {});
|
|
158
|
+
}, se = ({ url: s }) => /* @__PURE__ */ o(J, { className: "p-0", children: /* @__PURE__ */ o(
|
|
124
159
|
K,
|
|
125
160
|
{
|
|
126
161
|
className: "m-0 p-0 position-relative",
|
|
127
|
-
src:
|
|
162
|
+
src: s,
|
|
128
163
|
preview: {
|
|
129
|
-
mask: /* @__PURE__ */
|
|
164
|
+
mask: /* @__PURE__ */ o(G, {})
|
|
130
165
|
}
|
|
131
166
|
}
|
|
132
167
|
) });
|
|
133
168
|
export {
|
|
134
|
-
|
|
169
|
+
ae as FileDownloadProvider,
|
|
135
170
|
Fe as FileUploadProvider,
|
|
136
|
-
|
|
137
|
-
|
|
171
|
+
se as ImageCellValue,
|
|
172
|
+
Pe as ImageCrudCellValue,
|
|
138
173
|
pe as default
|
|
139
174
|
};
|
|
@@ -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;
|