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