@kingteza/crud-component 1.44.0 → 1.44.1
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.
|
@@ -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: [
|