@kingteza/crud-component 1.25.0 → 1.25.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";const s=require("react/jsx-runtime"),c=require("@ant-design/icons"),f=require("antd"),L=require("mime"),o=require("react"),Z=require("../util/ValidationUtil.cjs.js"),{Dragger:_}=f.Upload;function G({name:S,label:M,required:N,provider:a,onUploading:m,onRemoved:p,fieldClassName:W,accept:i,rules:k,maxCount:r=1,block:B,showInGrid:$=!1,gridConfig:q={draggerSpan:12,previewSpan:12},fieldHelper:R,formLayoutProps:
|
|
1
|
+
"use strict";const s=require("react/jsx-runtime"),c=require("@ant-design/icons"),f=require("antd"),L=require("mime"),o=require("react"),Z=require("../util/ValidationUtil.cjs.js"),{Dragger:_}=f.Upload;function G({name:S,label:M,required:N,provider:a,onUploading:m,onRemoved:p,fieldClassName:W,accept:i,rules:k,maxCount:r=1,block:B,showInGrid:$=!1,gridConfig:q={draggerSpan:12,previewSpan:12},fieldHelper:R,formLayoutProps:H,...I}){const u=f.Form.useFormInstance(),n=o.useMemo(()=>S,[S]),y=f.Form.useWatch(n,u),[A,U]=o.useState(!1),[j,h]=o.useState([]),T=o.useCallback(async e=>{var x,w;const l=e.file,t=(l==null?void 0:l.name)??"",d=`${Date.now()}-${Math.random().toString(36).substring(2,9)}`;h(F=>[...F,{uid:d,name:t,status:"uploading",originFileObj:l}]);try{U(!0),m==null||m(!0);const F=t??"",V=F.split("."),O=V[V.length-1],Q=a.generateFileName(F),X=`${await a.getInitialPath()}/${Q}.${O}`,g=await a.upload({...l,originFileObj:l},X),D=await a.getRealUrl(g),Y=L.getType(g),P=u.getFieldValue(n);if(r>1){const b=[...Array.isArray(P)?P:P?[P]:[],g].filter(Boolean);u.setFieldValue(n,b)}else u.setFieldValue(n,g);h(E=>E.map(b=>b.uid===d?{uid:g,url:D,type:Y,name:F,status:"done",response:g,thumbUrl:D}:b)),(x=e.onSuccess)==null||x.call(e,g)}catch(F){(w=e.onError)==null||w.call(e,F),h(V=>V.filter(O=>O.uid!==d))}finally{m==null||m(!1)}},[u,r,m,a,n]);o.useEffect(()=>{!A&&y&&Promise.all((Array.isArray(y)?y:[y]).map(async e=>{const l=L.getType(e),t=e.split("/").pop(),d=await a.getRealUrl(e);return{uid:e,url:d,type:l,name:t,response:e,thumbUrl:d}})).then(e=>h(e))},[y,A,a]);const z=o.useCallback(async e=>{const l=e.response??e.uid;await a.delete(l),p==null||p();const t=u.getFieldValue(n);if(r>1){const x=(Array.isArray(t)?t:t?[t]:[]).filter(w=>w!==l);u.setFieldValue(n,x.length?x:void 0)}else u.setFieldValue(n,void 0);h(d=>d.filter(x=>x.uid!==e.uid))},[u,r,p,a,n]),C=o.useMemo(()=>{if(!i)return"all files";const e=i.split(",").map(l=>{const t=l.trim().toLowerCase();return t.startsWith("image/")?"images":t===".pdf"||t==="application/pdf"?"PDF files":t.includes("excel")||t.includes(".xls")?"Excel files":t.includes("word")||t.includes(".doc")?"Word files":t.includes("text")||t===".txt"?"text files":t.includes("presentation")||t.includes(".ppt")?"PowerPoint files":t.replace(".","").toUpperCase()});return[...new Set(e)].join(", ")},[i]),J=o.useMemo(()=>i?i.includes("image")?s.jsx(c.FileImageOutlined,{}):i.includes("pdf")?s.jsx(c.FilePdfOutlined,{}):i.includes("word")||i.includes(".doc")?s.jsx(c.FileWordOutlined,{}):i.includes("text")||i.includes(".txt")?s.jsx(c.FileTextOutlined,{}):i.includes("excel")||i.includes(".xls")?s.jsx(c.FileExcelOutlined,{}):i.includes("presentation")||i.includes(".ppt")?s.jsx(c.FilePptOutlined,{}):s.jsx(c.FileOutlined,{}):s.jsx(c.InboxOutlined,{}),[i]),K=((j==null?void 0:j.length)??0)>=r;return s.jsxs(f.Form.Item,{label:M,required:N,name:n,...H,className:W,rules:[...N?Z.required(M):[],...k??[]],help:R,children:[s.jsx("input",{hidden:!0}),s.jsxs(f.Row,{gutter:[8,8],align:"top",style:{width:"100%",margin:0},children:[s.jsx(f.Col,{span:$?q.draggerSpan:24,xs:24,sm:24,children:s.jsxs(_,{...I,accept:i,disabled:K,fileList:[],multiple:r>1,maxCount:r,customRequest:T,onRemove:z,onChange:({file:e})=>{e.status==="error"&&h(l=>l.filter(t=>t.uid!==e.uid))},style:B?{width:"100%"}:void 0,children:[s.jsx("p",{className:"ant-upload-drag-icon",children:J}),s.jsx("p",{className:"ant-upload-text",children:"Click or drag file to this area to upload"}),s.jsx("p",{className:"ant-upload-hint",children:`Maximum file size: 10 MB. Supported formats: ${C}. ${r>1?`Maximum number of files: ${r}`:""}`})]})}),j.length>0&&s.jsx(f.Col,{span:$?q.previewSpan:24,xs:24,sm:24,children:s.jsx(f.Upload,{...I,accept:i,fileList:j,maxCount:r,customRequest:T,onRemove:z,listType:"picture",onChange:({fileList:e})=>h(e),style:{width:"100%"}})})]})]})}module.exports=G;
|
|
@@ -2,7 +2,7 @@ import { UploadProps } from 'antd';
|
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import { InitialCrudField } from './CrudComponent';
|
|
4
4
|
import { FileUploadProvider } from './ImageCrudField';
|
|
5
|
-
export interface
|
|
5
|
+
export interface FileCrudDragNDropFieldProps<T> extends _FileCrudDragNDropField<T> {
|
|
6
6
|
type: "file";
|
|
7
7
|
}
|
|
8
8
|
export interface _FileCrudDragNDropField<T> extends InitialCrudField<T> {
|
|
@@ -21,4 +21,4 @@ export interface _FileCrudDragNDropField<T> extends InitialCrudField<T> {
|
|
|
21
21
|
previewSpan?: number;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
export default function
|
|
24
|
+
export default function FileCrudDragNDropField<T>({ name, label, required, provider, onUploading, onRemoved, fieldClassName, accept, rules, maxCount, block, showInGrid, gridConfig, fieldHelper: help, formLayoutProps, ...props }: Readonly<_FileCrudDragNDropField<T>> & Omit<UploadProps, "customRequest">): import("react/jsx-runtime").JSX.Element;
|
|
@@ -28,10 +28,10 @@ function Fe({
|
|
|
28
28
|
}) {
|
|
29
29
|
const u = b.useFormInstance(), n = S(() => N, [N]), p = b.useWatch(n, u), [j, X] = B(!1), [g, f] = B([]), z = q(
|
|
30
30
|
async (e) => {
|
|
31
|
-
var
|
|
31
|
+
var m, F;
|
|
32
32
|
const l = e.file, t = (l == null ? void 0 : l.name) ?? "", d = `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
33
|
-
f((
|
|
34
|
-
...
|
|
33
|
+
f((o) => [
|
|
34
|
+
...o,
|
|
35
35
|
{
|
|
36
36
|
uid: d,
|
|
37
37
|
name: t,
|
|
@@ -41,9 +41,9 @@ function Fe({
|
|
|
41
41
|
]);
|
|
42
42
|
try {
|
|
43
43
|
X(!0), c == null || c(!0);
|
|
44
|
-
const
|
|
44
|
+
const o = t ?? "", w = o.split("."), P = w[w.length - 1], G = a.generateFileName(o), C = `${await a.getInitialPath()}/${G}.${P}`, h = await a.upload(
|
|
45
45
|
{ ...l, originFileObj: l },
|
|
46
|
-
|
|
46
|
+
C
|
|
47
47
|
), E = await a.getRealUrl(h), v = k.getType(h), x = u.getFieldValue(n);
|
|
48
48
|
if (r > 1) {
|
|
49
49
|
const V = [...Array.isArray(x) ? x : x ? [x] : [], h].filter(Boolean);
|
|
@@ -56,15 +56,15 @@ function Fe({
|
|
|
56
56
|
uid: h,
|
|
57
57
|
url: E,
|
|
58
58
|
type: v,
|
|
59
|
-
name:
|
|
59
|
+
name: o,
|
|
60
60
|
status: "done",
|
|
61
61
|
response: h,
|
|
62
62
|
thumbUrl: E
|
|
63
63
|
} : V
|
|
64
64
|
)
|
|
65
|
-
), (
|
|
66
|
-
} catch (
|
|
67
|
-
(F = e.onError) == null || F.call(e,
|
|
65
|
+
), (m = e.onSuccess) == null || m.call(e, h);
|
|
66
|
+
} catch (o) {
|
|
67
|
+
(F = e.onError) == null || F.call(e, o), f((w) => w.filter((P) => P.uid !== d));
|
|
68
68
|
} finally {
|
|
69
69
|
c == null || c(!1);
|
|
70
70
|
}
|
|
@@ -85,11 +85,11 @@ function Fe({
|
|
|
85
85
|
await a.delete(l), y == null || y();
|
|
86
86
|
const t = u.getFieldValue(n);
|
|
87
87
|
if (r > 1) {
|
|
88
|
-
const
|
|
89
|
-
u.setFieldValue(n,
|
|
88
|
+
const m = (Array.isArray(t) ? t : t ? [t] : []).filter((F) => F !== l);
|
|
89
|
+
u.setFieldValue(n, m.length ? m : void 0);
|
|
90
90
|
} else
|
|
91
91
|
u.setFieldValue(n, void 0);
|
|
92
|
-
f((d) => d.filter((
|
|
92
|
+
f((d) => d.filter((m) => m.uid !== e.uid));
|
|
93
93
|
},
|
|
94
94
|
[u, r, y, a, n]
|
|
95
95
|
), Y = S(() => {
|
package/dist/crud/index.d.ts
CHANGED
|
@@ -13,8 +13,7 @@ export { default as ImageCrudField, FileDownloadProvider, FileUploadProvider, Im
|
|
|
13
13
|
export type { ImageCrudField as ImageCrudFieldProps } from './ImageCrudField';
|
|
14
14
|
export { default as FileCrudField, FileCellValue, FileCrudCellValue, } from './FileCrudField';
|
|
15
15
|
export type { FileCrudField as FileCrudFieldProps } from './FileCrudField';
|
|
16
|
-
export { default as FileCrudDragNDropField } from './FileCrudDragNDropField';
|
|
17
|
-
export type { FileCrudDragNDropField as FileCrudDragNDropFieldProps, } from './FileCrudDragNDropField';
|
|
16
|
+
export { default as FileCrudDragNDropField, type FileCrudDragNDropFieldProps, } from './FileCrudDragNDropField';
|
|
18
17
|
export { default as CrudTextAreaComponent } from './CrudTextAreaComponent';
|
|
19
18
|
export type { TextAreaBasedFieldProps } from './CrudTextAreaComponent';
|
|
20
19
|
export { default as CrudImportComponent } from './import/CrudImportComponent';
|