@kingteza/crud-component 1.9.0 → 1.10.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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),l=require("@ant-design/icons"),a=require("../../locale/index.cjs.js"),d=require("./Button.cjs.js"),j=({size:n,block:r,className:o,type:u="primary",onClick:e,title:i,to:s})=>{const{t:c}=a.useTranslationLib();return t.jsx(d,{type:u,className:o,to:s,block:r,size:n,onClick:e&&(()=>e(!0)),icon:t.jsx(l.PlusOutlined,{}),children:i??c("str.new")})};exports.NewButton=j;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),d=require("@ant-design/icons"),j=require("../../locale/index.cjs.js"),q=require("./Button.cjs.js"),x=({size:n,block:r,className:o,type:u="primary",onClick:e,title:i,to:s,...c})=>{const{t:l}=j.useTranslationLib();return t.jsx(q,{type:u,className:o,to:s,block:r,size:n,onClick:e&&(a=>e(!0,a)),icon:t.jsx(d.PlusOutlined,{}),...c,children:i??l("str.new")})};exports.NewButton=x;
@@ -1,12 +1,13 @@
1
1
  import { SizeType } from 'antd/es/config-provider/SizeContext';
2
2
  import { ButtonType } from 'antd/lib/button';
3
- import { FC } from 'react';
3
+ import { FC, MouseEvent } from 'react';
4
+ import { ButtonProps } from 'antd';
4
5
  export declare const NewButton: FC<{
5
6
  to?: string;
6
- onClick?: (value: boolean) => void;
7
+ onClick?: (value: boolean, event: MouseEvent<HTMLElement>) => void;
7
8
  title?: string;
8
9
  type?: ButtonType;
9
10
  block?: boolean;
10
11
  className?: string;
11
12
  size?: SizeType;
12
- }>;
13
+ } & Omit<ButtonProps, "onClick">>;
@@ -1,23 +1,33 @@
1
1
  import { jsx as o } from "react/jsx-runtime";
2
- import { PlusOutlined as u } from "@ant-design/icons";
3
- import { useTranslationLib as c } from "../../locale/index.es.js";
4
- import f from "./Button.es.js";
5
- const x = ({ size: r, block: n, className: i, type: m = "primary", onClick: t, title: e, to: p }) => {
6
- const { t: s } = c();
2
+ import { PlusOutlined as f } from "@ant-design/icons";
3
+ import { useTranslationLib as l } from "../../locale/index.es.js";
4
+ import a from "./Button.es.js";
5
+ const b = ({
6
+ size: r,
7
+ block: n,
8
+ className: i,
9
+ type: m = "primary",
10
+ onClick: t,
11
+ title: e,
12
+ to: p,
13
+ ...s
14
+ }) => {
15
+ const { t: u } = l();
7
16
  return /* @__PURE__ */ o(
8
- f,
17
+ a,
9
18
  {
10
19
  type: m,
11
20
  className: i,
12
21
  to: p,
13
22
  block: n,
14
23
  size: r,
15
- onClick: t && (() => t(!0)),
16
- icon: /* @__PURE__ */ o(u, {}),
17
- children: e ?? s("str.new")
24
+ onClick: t && ((c) => t(!0, c)),
25
+ icon: /* @__PURE__ */ o(f, {}),
26
+ ...s,
27
+ children: e ?? u("str.new")
18
28
  }
19
29
  );
20
30
  };
21
31
  export {
22
- x as NewButton
32
+ b as NewButton
23
33
  };
@@ -1 +1 @@
1
- "use strict";const e=require("react/jsx-runtime"),C=require("antd"),t=require("react"),J=require("./modal/index.cjs.js"),K=require("./import/CrudImportButton.cjs.js"),L=require("./view/CrudViewer.cjs.js"),M=require("../common/button/NewButton.cjs.js"),O=require("../common/button/PrintButton.cjs.js");function Q({idField:l="id",onCreate:j,onDelete:f,onHide:m,onUpdate:n,onClickUpdate:a,fields:r,data:q,grid:h,isHiding:k,isCreating:B,isDeleting:p,isUpdating:w,paginateProps:N,onPrint:i,printing:v,viewable:R,loadingData:g,formBuilder:y,extraAction:b,minusHeight:P,cloneable:S,fullWidthModal:I=!0,wizard:V,extraView:z,importable:u,onClickNew:d,size:A,...D}){const c=t.useRef(null),E=t.useCallback(()=>{var s;(s=c.current)==null||s.create()},[]),o=t.useCallback(async(s,G=!0,H=!1)=>{var x;await((x=c.current)==null?void 0:x.update(s,G,H))},[]),F=t.useCallback(async s=>{o(s,!1,!0)},[o]);return e.jsxs(e.Fragment,{children:[e.jsxs(C.Space,{direction:"vertical",className:"w-100",children:[e.jsxs("div",{className:"w-100 d-flex",children:[e.jsx("div",{style:{flex:1},children:e.jsx(M.NewButton,{onClick:()=>{d?d():E()},className:"flex-1"})}),e.jsxs(C.Space,{children:[!!i&&e.jsx(O.PrintButton,{className:"float-right",loading:v,onClick:i}),!!u&&e.jsx(K,{fields:r,importProps:u})]})]}),e.jsx(L,{...D,minusHeight:P,data:q,size:A,fields:r,extraAction:b,idField:l,isDeleting:p,loadingData:g,onClickUpdate:a||(n?o:void 0),onHide:m,isHiding:k,onDelete:f,onUpdate:n,onClickClone:S?F:void 0,paginateProps:N,viewable:R,extraView:z})]}),e.jsx(J,{ref:c,fields:r,wizard:V,grid:h,fullWidthModal:I,isCreating:B,isUpdating:w,onCreate:j,onUpdate:n,idField:l,formBuilder:y})]})}module.exports=Q;
1
+ "use strict";const e=require("react/jsx-runtime"),j=require("antd"),n=require("react"),H=require("./modal/index.cjs.js"),J=require("./import/CrudImportButton.cjs.js"),K=require("./view/CrudViewer.cjs.js"),L=require("../common/button/NewButton.cjs.js"),Q=require("../common/button/PrintButton.cjs.js");function T({idField:o="id",onCreate:f,onDelete:m,onHide:h,onUpdate:l,onClickUpdate:u,fields:r,data:q,grid:N,isHiding:v,isCreating:R,isDeleting:g,isUpdating:y,paginateProps:b,onPrint:C,printing:B,viewable:S,loadingData:w,formBuilder:I,extraAction:M,minusHeight:O,cloneable:V,fullWidthModal:W=!0,wizard:_,extraView:p,importable:d,onClickNew:x,newButtonProps:s,size:z,...A}){const t=n.useRef(null),D=n.useCallback(()=>{var c;(c=t.current)==null||c.create()},[]),i=n.useCallback(async(c,a=!0,G=!1)=>{var k;await((k=t.current)==null?void 0:k.update(c,a,G))},[]),E=n.useCallback(async c=>{i(c,!1,!0)},[i]),{onClick:X,...F}=n.useMemo(()=>s||{},[s]);return e.jsxs(e.Fragment,{children:[e.jsxs(j.Space,{direction:"vertical",className:"w-100",children:[e.jsxs("div",{className:"w-100 d-flex",children:[e.jsx("div",{style:{flex:1},children:e.jsx(L.NewButton,{onClick:(c,a)=>{x?x():s!=null&&s.onClick?s.onClick(a):D()},className:"flex-1",...F})}),e.jsxs(j.Space,{children:[!!C&&e.jsx(Q.PrintButton,{className:"float-right",loading:B,onClick:C}),!!d&&e.jsx(J,{fields:r,importProps:d})]})]}),e.jsx(K,{...A,minusHeight:O,data:q,size:z,fields:r,extraAction:M,idField:o,isDeleting:g,loadingData:w,onClickUpdate:u||(l?i:void 0),onHide:h,isHiding:v,onDelete:m,onUpdate:l,onClickClone:V?E:void 0,paginateProps:b,viewable:S,extraView:p})]}),e.jsx(H,{ref:t,fields:r,wizard:_,grid:N,fullWidthModal:W,isCreating:R,isUpdating:y,onCreate:f,onUpdate:l,idField:o,formBuilder:I})]})}module.exports=T;
@@ -1,4 +1,4 @@
1
- import { ColorPickerProps } from 'antd';
1
+ import { ButtonProps, ColorPickerProps } from 'antd';
2
2
  import { Rule } from 'antd/es/form';
3
3
  import { FormInstance } from 'antd/lib';
4
4
  import { Dayjs } from 'dayjs';
@@ -259,9 +259,13 @@ export type CrudComponentProps<T, FormType = T> = {
259
259
  wizard?: CrudWizardProp<T>[];
260
260
  extraView?: (t: T) => React.ReactElement;
261
261
  importable?: CrudImportProps<T>;
262
+ /**
263
+ * @deprecated Use {@link CrudComponentProps.newButtonProps?.onClick} instead.
264
+ */
262
265
  onClickNew?: () => void;
266
+ newButtonProps?: ButtonProps;
263
267
  draggable?: CrudDragableProps<T>;
264
268
  size?: SizeType;
265
269
  } & CrudSearchComponentProps<T, FormType>;
266
- declare function CrudComponent<T, FormType = T>({ idField, onCreate, onDelete, onHide, onUpdate, onClickUpdate, fields, data, grid, isHiding, isCreating, isDeleting, isUpdating, paginateProps, onPrint, printing, viewable, loadingData, formBuilder, extraAction, minusHeight, cloneable, fullWidthModal, wizard, extraView, importable, onClickNew, size, ...props }: CrudComponentProps<T, FormType>): import("react/jsx-runtime").JSX.Element;
270
+ declare function CrudComponent<T, FormType = T>({ idField, onCreate, onDelete, onHide, onUpdate, onClickUpdate, fields, data, grid, isHiding, isCreating, isDeleting, isUpdating, paginateProps, onPrint, printing, viewable, loadingData, formBuilder, extraAction, minusHeight, cloneable, fullWidthModal, wizard, extraView, importable, onClickNew, newButtonProps, size, ...props }: CrudComponentProps<T, FormType>): import("react/jsx-runtime").JSX.Element;
267
271
  export default CrudComponent;
@@ -1,123 +1,125 @@
1
- import { jsxs as e, Fragment as J, jsx as o } from "react/jsx-runtime";
2
- import { Space as p } from "antd";
3
- import { useRef as K, useCallback as c } from "react";
4
- import L from "./modal/index.es.js";
5
- import O from "./import/CrudImportButton.es.js";
6
- import Q from "./view/CrudViewer.es.js";
7
- import { NewButton as T } from "../common/button/NewButton.es.js";
8
- import { PrintButton as W } from "../common/button/PrintButton.es.js";
9
- function er({
10
- idField: i = "id",
11
- onCreate: C,
12
- onDelete: h,
13
- onHide: x,
14
- onUpdate: t,
15
- onClickUpdate: m,
16
- fields: l,
17
- data: k,
18
- grid: v,
19
- isHiding: w,
20
- isCreating: B,
21
- isDeleting: N,
22
- isUpdating: g,
23
- paginateProps: y,
24
- onPrint: s,
25
- printing: j,
26
- viewable: R,
27
- loadingData: I,
28
- formBuilder: M,
29
- extraAction: P,
30
- minusHeight: S,
31
- cloneable: V,
32
- fullWidthModal: b = !0,
33
- wizard: q,
34
- extraView: z,
35
- importable: u,
36
- onClickNew: f,
37
- size: A,
1
+ import { jsxs as l, Fragment as J, jsx as r } from "react/jsx-runtime";
2
+ import { Space as h } from "antd";
3
+ import { useRef as K, useCallback as m, useMemo as L } from "react";
4
+ import Q from "./modal/index.es.js";
5
+ import T from "./import/CrudImportButton.es.js";
6
+ import X from "./view/CrudViewer.es.js";
7
+ import { NewButton as Y } from "../common/button/NewButton.es.js";
8
+ import { PrintButton as Z } from "../common/button/PrintButton.es.js";
9
+ function te({
10
+ idField: s = "id",
11
+ onCreate: p,
12
+ onDelete: x,
13
+ onHide: N,
14
+ onUpdate: i,
15
+ onClickUpdate: f,
16
+ fields: c,
17
+ data: v,
18
+ grid: g,
19
+ isHiding: y,
20
+ isCreating: j,
21
+ isDeleting: M,
22
+ isUpdating: R,
23
+ paginateProps: I,
24
+ onPrint: d,
25
+ printing: O,
26
+ viewable: S,
27
+ loadingData: V,
28
+ formBuilder: W,
29
+ extraAction: _,
30
+ minusHeight: b,
31
+ cloneable: q,
32
+ fullWidthModal: w = !0,
33
+ wizard: z,
34
+ extraView: A,
35
+ importable: C,
36
+ onClickNew: u,
37
+ newButtonProps: o,
38
+ size: B,
38
39
  ...D
39
40
  }) {
40
- const n = K(null), E = c(() => {
41
- var r;
42
- (r = n.current) == null || r.create();
43
- }, []), a = c(
44
- async (r, G = !0, H = !1) => {
45
- var d;
46
- await ((d = n.current) == null ? void 0 : d.update(r, G, H));
41
+ const t = K(null), E = m(() => {
42
+ var e;
43
+ (e = t.current) == null || e.create();
44
+ }, []), a = m(
45
+ async (e, n = !0, H = !1) => {
46
+ var k;
47
+ await ((k = t.current) == null ? void 0 : k.update(e, n, H));
47
48
  },
48
49
  []
49
- ), F = c(
50
- async (r) => {
51
- a(r, !1, !0);
50
+ ), F = m(
51
+ async (e) => {
52
+ a(e, !1, !0);
52
53
  },
53
54
  [a]
54
- );
55
- return /* @__PURE__ */ e(J, { children: [
56
- /* @__PURE__ */ e(p, { direction: "vertical", className: "w-100", children: [
57
- /* @__PURE__ */ e("div", { className: "w-100 d-flex", children: [
58
- /* @__PURE__ */ o("div", { style: { flex: 1 }, children: /* @__PURE__ */ o(
59
- T,
55
+ ), { onClick: $, ...G } = L(() => o || {}, [o]);
56
+ return /* @__PURE__ */ l(J, { children: [
57
+ /* @__PURE__ */ l(h, { direction: "vertical", className: "w-100", children: [
58
+ /* @__PURE__ */ l("div", { className: "w-100 d-flex", children: [
59
+ /* @__PURE__ */ r("div", { style: { flex: 1 }, children: /* @__PURE__ */ r(
60
+ Y,
60
61
  {
61
- onClick: () => {
62
- f ? f() : E();
62
+ onClick: (e, n) => {
63
+ u ? u() : o != null && o.onClick ? o.onClick(n) : E();
63
64
  },
64
- className: "flex-1"
65
+ className: "flex-1",
66
+ ...G
65
67
  }
66
68
  ) }),
67
- /* @__PURE__ */ e(p, { children: [
68
- !!s && /* @__PURE__ */ o(
69
- W,
69
+ /* @__PURE__ */ l(h, { children: [
70
+ !!d && /* @__PURE__ */ r(
71
+ Z,
70
72
  {
71
73
  className: "float-right",
72
- loading: j,
73
- onClick: s
74
+ loading: O,
75
+ onClick: d
74
76
  }
75
77
  ),
76
- !!u && /* @__PURE__ */ o(O, { fields: l, importProps: u })
78
+ !!C && /* @__PURE__ */ r(T, { fields: c, importProps: C })
77
79
  ] })
78
80
  ] }),
79
- /* @__PURE__ */ o(
80
- Q,
81
+ /* @__PURE__ */ r(
82
+ X,
81
83
  {
82
84
  ...D,
83
- minusHeight: S,
84
- data: k,
85
- size: A,
86
- fields: l,
87
- extraAction: P,
88
- idField: i,
89
- isDeleting: N,
90
- loadingData: I,
91
- onClickUpdate: m || (t ? a : void 0),
92
- onHide: x,
93
- isHiding: w,
94
- onDelete: h,
95
- onUpdate: t,
96
- onClickClone: V ? F : void 0,
97
- paginateProps: y,
98
- viewable: R,
99
- extraView: z
85
+ minusHeight: b,
86
+ data: v,
87
+ size: B,
88
+ fields: c,
89
+ extraAction: _,
90
+ idField: s,
91
+ isDeleting: M,
92
+ loadingData: V,
93
+ onClickUpdate: f || (i ? a : void 0),
94
+ onHide: N,
95
+ isHiding: y,
96
+ onDelete: x,
97
+ onUpdate: i,
98
+ onClickClone: q ? F : void 0,
99
+ paginateProps: I,
100
+ viewable: S,
101
+ extraView: A
100
102
  }
101
103
  )
102
104
  ] }),
103
- /* @__PURE__ */ o(
104
- L,
105
+ /* @__PURE__ */ r(
106
+ Q,
105
107
  {
106
- ref: n,
107
- fields: l,
108
- wizard: q,
109
- grid: v,
110
- fullWidthModal: b,
111
- isCreating: B,
112
- isUpdating: g,
113
- onCreate: C,
114
- onUpdate: t,
115
- idField: i,
116
- formBuilder: M
108
+ ref: t,
109
+ fields: c,
110
+ wizard: z,
111
+ grid: g,
112
+ fullWidthModal: w,
113
+ isCreating: j,
114
+ isUpdating: R,
115
+ onCreate: p,
116
+ onUpdate: i,
117
+ idField: s,
118
+ formBuilder: W
117
119
  }
118
120
  )
119
121
  ] });
120
122
  }
121
123
  export {
122
- er as default
124
+ te as default
123
125
  };
@@ -1 +1 @@
1
- "use strict";var p=Object.defineProperty;var E=(e,a,t)=>a in e?p(e,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[a]=t;var F=(e,a,t)=>E(e,typeof a!="symbol"?a+"":a,t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("react/jsx-runtime");;/* empty css */const A=require("@ant-design/icons"),n=require("antd"),q=require("path-browserify"),i=require("react"),D=require("../util/NumberUtil.cjs.js"),M=require("../util/ValidationUtil.cjs.js"),H=require("uuid"),T=require("../common/picker/ImagePicker.cjs.js");class w{}class W extends w{constructor(t="",s=""){super();F(this,"rootPath");F(this,"subPath");this.rootPath=t,this.subPath=s}cloneFilePath(t){const s=q.parse(t),l=`${s.name}_cloned_${D.default.randInt(1e5)}`;return q.format({dir:s.dir,ext:s.ext,name:l})}generateFileName(t){return`${t.split(".")[0]}_${H.v4().replace("-","")}`}}function z({name:e,label:a,required:t,provider:s,onUploading:l,aspectRatio:P,onRemoved:o,fieldClassName:N,hideLabel:V=!1,listType:g,fieldHelper:y}){const c=n.Form.useFormInstance(),d=n.Form.useWatch(e,c),[I,$]=i.useState(!1),x=i.useCallback(async(u,b)=>{if(b){l==null||l(!0);const f=u.name,m=f.split("."),S=m[m.length-1],_=s.generateFileName(f),O=`${await s.getInitialPath()}/${_}.${S}`,k=await s.upload(u,O);$(!0),l==null||l(!1),c.setFieldValue(e,k)}else{const f=c.getFieldsValue(),m=await s.delete(f[e]);o==null||o(),m&&c.setFieldsValue({[e]:null})}},[c,e,o,l,s]),[h,j]=i.useState();return i.useEffect(()=>{!I&&d?s.getRealUrl(d).then(j):j(h)},[d,I,s,h]),r.jsxs(n.Form.Item,{rules:t?M.required(a):[],label:V?null:a,required:t,name:e,help:y,children:[r.jsx(T.default,{noStyle:!0,listType:g,aspectRatio:P,values:h,onRemove:u=>{u&&x(u,!1)},onAdd:async u=>{u&&await x(u,!0)},className:N}),r.jsx(n.Input,{hidden:!0})]})}const B=({provider:e,value:a})=>{const[t,s]=i.useState();return i.useEffect(()=>{a&&e.getRealUrl(a).then(s)},[e,a]),t?r.jsx(C,{url:t}):r.jsx(r.Fragment,{})},C=({url:e})=>r.jsx(n.Avatar,{className:"p-0",children:r.jsx(n.Image,{className:"m-0 p-0 position-relative",src:e,preview:{mask:r.jsx(A.EyeOutlined,{})}})});exports.FileDownloadProvider=w;exports.FileUploadProvider=W;exports.ImageCellValue=C;exports.ImageCrudCellValue=B;exports.default=z;
1
+ "use strict";var E=Object.defineProperty;var M=(e,a,t)=>a in e?E(e,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[a]=t;var P=(e,a,t)=>M(e,typeof a!="symbol"?a+"":a,t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("react/jsx-runtime");;/* empty css */const A=require("@ant-design/icons"),o=require("antd"),j=require("path-browserify"),u=require("react"),B=require("../util/NumberUtil.cjs.js"),D=require("../util/ValidationUtil.cjs.js"),H=require("uuid"),R=require("../common/picker/ImagePicker.cjs.js"),T=require("../util/ImageUtil.cjs.js");class q{}class W extends q{constructor(t="",s=""){super();P(this,"rootPath");P(this,"subPath");this.rootPath=t,this.subPath=s}cloneFilePath(t){const s=j.parse(t),r=`${s.name}_cloned_${B.default.randInt(1e5)}`;return j.format({dir:s.dir,ext:s.ext,name:r})}generateFileName(t){return`${t.split(".")[0]}_${H.v4().replace("-","")}`}}function v({name:e,label:a,required:t,provider:s,onUploading:r,aspectRatio:g,onRemoved:m,fieldClassName:V,hideLabel:y=!1,listType:N,fieldHelper:b},S){const f=o.Form.useFormInstance(),F=o.Form.useWatch(e,f),[x,$]=u.useState(!1),d=u.useCallback(async(l,h)=>{if(h){r==null||r(!0);const i=l.name,c=i.split("."),p=c[c.length-1],O=s.generateFileName(i),_=`${await s.getInitialPath()}/${O}.${p}`,k=await s.upload(l,_);$(!0),r==null||r(!1),f.setFieldValue(e,k)}else{const i=f.getFieldsValue(),c=await s.delete(i[e]);m==null||m(),c&&f.setFieldsValue({[e]:null})}},[f,e,m,r,s]),[I,w]=u.useState();return u.useEffect(()=>{!x&&F?s.getRealUrl(F).then(w):w(I)},[F,x,s,I]),u.useImperativeHandle(S,()=>({async uploadBlob(l,h){const i=await T.getBase64(l),c={name:h,uid:h+Math.random().toString(36).substring(2,15),url:i,originFileObj:l};return d(c,!0)}}),[d]),n.jsxs(o.Form.Item,{rules:t?D.required(a):[],label:y?null:a,required:t,name:e,help:b,children:[n.jsx(R.default,{noStyle:!0,listType:N,aspectRatio:g,values:I,onRemove:l=>{l&&d(l,!1)},onAdd:async l=>{l&&await d(l,!0)},className:V}),n.jsx(o.Input,{hidden:!0})]})}const z=u.forwardRef(v),G=({provider:e,value:a})=>{const[t,s]=u.useState();return u.useEffect(()=>{a&&e.getRealUrl(a).then(s)},[e,a]),t?n.jsx(C,{url:t}):n.jsx(n.Fragment,{})},C=({url:e})=>n.jsx(o.Avatar,{className:"p-0",children:n.jsx(o.Image,{className:"m-0 p-0 position-relative",src:e,preview:{mask:n.jsx(A.EyeOutlined,{})}})});exports.FileDownloadProvider=q;exports.FileUploadProvider=W;exports.ImageCellValue=C;exports.ImageCrudCellValue=G;exports.default=z;
@@ -1,6 +1,6 @@
1
1
  import { UploadListType } from 'antd/es/upload/interface';
2
2
  import { UploadFile } from 'antd/lib';
3
- import { FC } from 'react';
3
+ import { default as React, FC, ForwardedRef } from 'react';
4
4
  import { InitialCrudField } from './CrudComponent';
5
5
  export interface _ImageCrudField<T> extends InitialCrudField<T> {
6
6
  provider: FileUploadProvider;
@@ -28,7 +28,12 @@ export declare abstract class FileUploadProvider extends FileDownloadProvider {
28
28
  abstract getRealUrl(filePath: string): Promise<string>;
29
29
  generateFileName(initialFileName: string): string;
30
30
  }
31
- export default function ImageCrudFieldComponent<T>({ name, label, required, provider, onUploading, aspectRatio, onRemoved, fieldClassName, hideLabel, listType, fieldHelper: help, }: Readonly<_ImageCrudField<T>>): import("react/jsx-runtime").JSX.Element;
31
+ export interface ImageCrudFieldRef {
32
+ uploadBlob: (blob: Blob, fileName: string) => Promise<void>;
33
+ }
34
+ declare function Component<T>({ name, label, required, provider, onUploading, aspectRatio, onRemoved, fieldClassName, hideLabel, listType, fieldHelper: help, }: Readonly<_ImageCrudField<T>>, ref: ForwardedRef<ImageCrudFieldRef>): import("react/jsx-runtime").JSX.Element;
35
+ declare const ImageCrudFieldComponent: <T>(props: React.ComponentProps<typeof Component<T>>, ref: React.Ref<any>) => React.ReactElement | null;
36
+ export default ImageCrudFieldComponent;
32
37
  export declare const ImageCrudCellValue: FC<{
33
38
  value: string;
34
39
  provider: FileDownloadProvider;
@@ -1,114 +1,129 @@
1
1
  var A = Object.defineProperty;
2
- var E = (e, s, t) => s in e ? A(e, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[s] = t;
3
- var h = (e, s, t) => E(e, typeof s != "symbol" ? s + "" : s, t);
4
- import { jsxs as S, jsx as i, Fragment as D } from "react/jsx-runtime";
2
+ var B = (e, s, t) => s in e ? A(e, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[s] = t;
3
+ var F = (e, s, t) => B(e, typeof s != "symbol" ? s + "" : s, t);
4
+ import { jsx as n, Fragment as E, jsxs as H } from "react/jsx-runtime";
5
5
  /* empty css */
6
- import { EyeOutlined as H } from "@ant-design/icons";
7
- import { Form as F, Input as W, Avatar as q, Image as z } from "antd";
8
- import w from "path-browserify";
9
- import { useState as P, useCallback as B, useEffect as V } from "react";
10
- import G from "../util/NumberUtil.es.js";
11
- import J from "../util/ValidationUtil.es.js";
12
- import { v4 as K } from "uuid";
13
- import L from "../common/picker/ImagePicker.es.js";
14
- class M {
6
+ import { EyeOutlined as D } from "@ant-design/icons";
7
+ import { Avatar as M, Image as W, Form as d, Input as q } from "antd";
8
+ import N from "path-browserify";
9
+ import z, { useState as I, useEffect as y, useCallback as G, useImperativeHandle as J } from "react";
10
+ import K from "../util/NumberUtil.es.js";
11
+ import L from "../util/ValidationUtil.es.js";
12
+ import { v4 as Q } from "uuid";
13
+ import R from "../common/picker/ImagePicker.es.js";
14
+ import T from "../util/ImageUtil.es.js";
15
+ class X {
15
16
  }
16
- class le extends M {
17
+ class me extends X {
17
18
  constructor(t = "", a = "") {
18
19
  super();
19
- h(this, "rootPath");
20
- h(this, "subPath");
20
+ F(this, "rootPath");
21
+ F(this, "subPath");
21
22
  this.rootPath = t, this.subPath = a;
22
23
  }
23
24
  cloneFilePath(t) {
24
- const a = w.parse(t), l = `${a.name}_cloned_${G.randInt(1e5)}`;
25
- return w.format({
25
+ const a = N.parse(t), l = `${a.name}_cloned_${K.randInt(1e5)}`;
26
+ return N.format({
26
27
  dir: a.dir,
27
28
  ext: a.ext,
28
29
  name: l
29
30
  });
30
31
  }
31
32
  generateFileName(t) {
32
- return `${t.split(".")[0]}_${K().replace("-", "")}`;
33
+ return `${t.split(".")[0]}_${Q().replace("-", "")}`;
33
34
  }
34
35
  }
35
- function re({
36
+ function Y({
36
37
  name: e,
37
38
  label: s,
38
39
  required: t,
39
40
  provider: a,
40
41
  onUploading: l,
41
- aspectRatio: p,
42
- onRemoved: c,
43
- fieldClassName: x,
44
- hideLabel: y = !1,
45
- listType: C,
42
+ aspectRatio: P,
43
+ onRemoved: m,
44
+ fieldClassName: C,
45
+ hideLabel: V = !1,
46
+ listType: x,
46
47
  fieldHelper: $
47
- }) {
48
- const n = F.useFormInstance(), o = F.useWatch(e, n), [I, b] = P(!1), N = B(
49
- async (r, g) => {
50
- if (g) {
48
+ }, b) {
49
+ const c = d.useFormInstance(), h = d.useWatch(e, c), [w, O] = I(!1), u = G(
50
+ async (r, f) => {
51
+ if (f) {
51
52
  l == null || l(!0);
52
- const m = r.name, u = m.split("."), k = u[u.length - 1], O = a.generateFileName(m), _ = `${await a.getInitialPath()}/${O}.${k}`, j = await a.upload(r, _);
53
- b(!0), l == null || l(!1), n.setFieldValue(e, j);
53
+ const i = r.name, o = i.split("."), j = o[o.length - 1], k = a.generateFileName(i), S = `${await a.getInitialPath()}/${k}.${j}`, _ = await a.upload(r, S);
54
+ O(!0), l == null || l(!1), c.setFieldValue(e, _);
54
55
  } else {
55
- const m = n.getFieldsValue(), u = await a.delete(m[e]);
56
- c == null || c(), u && n.setFieldsValue({ [e]: null });
56
+ const i = c.getFieldsValue(), o = await a.delete(i[e]);
57
+ m == null || m(), o && c.setFieldsValue({ [e]: null });
57
58
  }
58
59
  },
59
- [n, e, c, l, a]
60
- ), [f, d] = P();
61
- return V(() => {
62
- !I && o ? a.getRealUrl(o).then(d) : d(f);
63
- }, [o, I, a, f]), /* @__PURE__ */ S(
64
- F.Item,
60
+ [c, e, m, l, a]
61
+ ), [p, g] = I();
62
+ return y(() => {
63
+ !w && h ? a.getRealUrl(h).then(g) : g(p);
64
+ }, [h, w, a, p]), J(
65
+ b,
66
+ () => ({
67
+ async uploadBlob(r, f) {
68
+ const i = await T.getBase64(r), o = {
69
+ name: f,
70
+ uid: f + Math.random().toString(36).substring(2, 15),
71
+ url: i,
72
+ originFileObj: r
73
+ };
74
+ return u(o, !0);
75
+ }
76
+ }),
77
+ [u]
78
+ ), /* @__PURE__ */ H(
79
+ d.Item,
65
80
  {
66
- rules: t ? J.required(s) : [],
67
- label: y ? null : s,
81
+ rules: t ? L.required(s) : [],
82
+ label: V ? null : s,
68
83
  required: t,
69
84
  name: e,
70
85
  help: $,
71
86
  children: [
72
- /* @__PURE__ */ i(
73
- L,
87
+ /* @__PURE__ */ n(
88
+ R,
74
89
  {
75
90
  noStyle: !0,
76
- listType: C,
77
- aspectRatio: p,
78
- values: f,
91
+ listType: x,
92
+ aspectRatio: P,
93
+ values: p,
79
94
  onRemove: (r) => {
80
- r && N(r, !1);
95
+ r && u(r, !1);
81
96
  },
82
97
  onAdd: async (r) => {
83
- r && await N(r, !0);
98
+ r && await u(r, !0);
84
99
  },
85
- className: x
100
+ className: C
86
101
  }
87
102
  ),
88
- /* @__PURE__ */ i(W, { hidden: !0 })
103
+ /* @__PURE__ */ n(q, { hidden: !0 })
89
104
  ]
90
105
  }
91
106
  );
92
107
  }
93
- const ie = ({ provider: e, value: s }) => {
94
- const [t, a] = P();
95
- return V(() => {
108
+ const ue = z.forwardRef(Y), fe = ({ provider: e, value: s }) => {
109
+ const [t, a] = I();
110
+ return y(() => {
96
111
  s && e.getRealUrl(s).then(a);
97
- }, [e, s]), t ? /* @__PURE__ */ i(Q, { url: t }) : /* @__PURE__ */ i(D, {});
98
- }, Q = ({ url: e }) => /* @__PURE__ */ i(q, { className: "p-0", children: /* @__PURE__ */ i(
99
- z,
112
+ }, [e, s]), t ? /* @__PURE__ */ n(Z, { url: t }) : /* @__PURE__ */ n(E, {});
113
+ }, Z = ({ url: e }) => /* @__PURE__ */ n(M, { className: "p-0", children: /* @__PURE__ */ n(
114
+ W,
100
115
  {
101
116
  className: "m-0 p-0 position-relative",
102
117
  src: e,
103
118
  preview: {
104
- mask: /* @__PURE__ */ i(H, {})
119
+ mask: /* @__PURE__ */ n(D, {})
105
120
  }
106
121
  }
107
122
  ) });
108
123
  export {
109
- M as FileDownloadProvider,
110
- le as FileUploadProvider,
111
- Q as ImageCellValue,
112
- ie as ImageCrudCellValue,
113
- re as default
124
+ X as FileDownloadProvider,
125
+ me as FileUploadProvider,
126
+ Z as ImageCellValue,
127
+ fe as ImageCrudCellValue,
128
+ ue as default
114
129
  };
@@ -9,7 +9,7 @@ export type { CrudReportComponentProps, CrudReportSubmitForm, ReportCrudFields,
9
9
  export { default as CrudReportComponent } from './CrudReportComponent';
10
10
  export { default as CrudSearchComponent } from './CrudSearchComponent';
11
11
  export type { CrudSearchComponentProps, CrudSearchOption, } from './CrudSearchComponent';
12
- export { default as ImageCrudField, FileDownloadProvider, FileUploadProvider, ImageCellValue, ImageCrudCellValue, } from './ImageCrudField';
12
+ export { default as ImageCrudField, FileDownloadProvider, FileUploadProvider, ImageCellValue, ImageCrudCellValue, type ImageCrudFieldRef, } from './ImageCrudField';
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';
@@ -1 +1 @@
1
- "use strict";const c=require("browser-image-compression");class g{async resizeImage(t){const e=await c(t,{maxSizeMB:1,maxWidthOrHeight:1920,useWebWorker:!0}),a=t.uid;return Object.assign(e,{uid:a,lastModifiedDate:new Date})}async getImageData(t){const e=await this.getImageData0(t);if(e){const a=new Image;a.src=e.data;const o=await new Promise(n=>{a.onload=function(){n({height:a.height,width:a.width})}});return Object.assign(e,o),e}else return null}async getImageData0(t){try{if(t.startsWith("data:image/")){const e=t.match(/^data:image\/(png|jpeg|jpg);base64,(.*)$/);if(!e)throw new Error("Invalid base64 image data");return{data:t,type:e[1]}}else{const e=await fetch(t);if(!e.ok)throw new Error("Network response was not ok");const a=await e.blob();return new Promise((o,n)=>{const s=new FileReader;s.onloadend=function(){const r=s.result,i=r.match(/^data:image\/(png|jpeg|jpg);base64,/);i?o({data:r,type:i[1]}):n(new Error("Could not determine image type"))},s.onerror=n,s.readAsDataURL(a)})}}catch(e){return console.warn(e),null}}}const d=new g;module.exports=d;
1
+ "use strict";const c=require("browser-image-compression");class d{async resizeImage(t){const e=await c(t,{maxSizeMB:1,maxWidthOrHeight:1920,useWebWorker:!0}),a=t.uid;return Object.assign(e,{uid:a,lastModifiedDate:new Date})}async getImageData(t){const e=await this.getImageData0(t);if(e){const a=new Image;a.src=e.data;const n=await new Promise(r=>{a.onload=function(){r({height:a.height,width:a.width})}});return Object.assign(e,n),e}else return null}async getImageData0(t){try{if(t.startsWith("data:image/")){const e=t.match(/^data:image\/(png|jpeg|jpg);base64,(.*)$/);if(!e)throw new Error("Invalid base64 image data");return{data:t,type:e[1]}}else{const e=await fetch(t);if(!e.ok)throw new Error("Network response was not ok");const a=await e.blob();return new Promise((n,r)=>{const s=new FileReader;s.onloadend=function(){const o=s.result,i=o.match(/^data:image\/(png|jpeg|jpg);base64,/);i?n({data:o,type:i[1]}):r(new Error("Could not determine image type"))},s.onerror=r,s.readAsDataURL(a)})}}catch(e){return console.warn(e),null}}getBase64(t){return new Promise((e,a)=>{const n=new FileReader;n.readAsDataURL(t),n.onload=()=>e(n.result),n.onerror=r=>a(r)})}}const g=new d;module.exports=g;
@@ -1,7 +1,7 @@
1
1
  import { RcFile } from 'antd/lib/upload';
2
2
  export type ImageDataReturn = {
3
3
  data: string;
4
- type: 'png' | 'jpeg' | 'jpg';
4
+ type: "png" | "jpeg" | "jpg";
5
5
  width: number;
6
6
  height: number;
7
7
  } | null;
@@ -9,6 +9,7 @@ declare class ImageUtl {
9
9
  resizeImage(file: RcFile): Promise<RcFile>;
10
10
  getImageData(uriOrBase64: string): Promise<ImageDataReturn>;
11
11
  getImageData0(uriOrBase64: string): Promise<ImageDataReturn>;
12
+ getBase64(file: any): Promise<string>;
12
13
  }
13
14
  declare const _default: ImageUtl;
14
15
  export default _default;
@@ -1,7 +1,7 @@
1
- import c from "browser-image-compression";
2
- class g {
1
+ import d from "browser-image-compression";
2
+ class c {
3
3
  async resizeImage(t) {
4
- const e = await c(t, {
4
+ const e = await d(t, {
5
5
  maxSizeMB: 1,
6
6
  maxWidthOrHeight: 1920,
7
7
  useWebWorker: !0
@@ -16,48 +16,61 @@ class g {
16
16
  if (e) {
17
17
  const a = new Image();
18
18
  a.src = e.data;
19
- const o = await new Promise(
20
- (n) => {
19
+ const n = await new Promise(
20
+ (r) => {
21
21
  a.onload = function() {
22
- n({
22
+ r({
23
23
  height: a.height,
24
24
  width: a.width
25
25
  });
26
26
  };
27
27
  }
28
28
  );
29
- return Object.assign(e, o), e;
29
+ return Object.assign(e, n), e;
30
30
  } else
31
31
  return null;
32
32
  }
33
33
  async getImageData0(t) {
34
34
  try {
35
35
  if (t.startsWith("data:image/")) {
36
- const e = t.match(/^data:image\/(png|jpeg|jpg);base64,(.*)$/);
36
+ const e = t.match(
37
+ /^data:image\/(png|jpeg|jpg);base64,(.*)$/
38
+ );
37
39
  if (!e)
38
40
  throw new Error("Invalid base64 image data");
39
- return { data: t, type: e[1] };
41
+ return {
42
+ data: t,
43
+ type: e[1]
44
+ };
40
45
  } else {
41
46
  const e = await fetch(t);
42
47
  if (!e.ok) throw new Error("Network response was not ok");
43
48
  const a = await e.blob();
44
- return new Promise((o, n) => {
49
+ return new Promise((n, r) => {
45
50
  const s = new FileReader();
46
51
  s.onloadend = function() {
47
- const r = s.result, i = r.match(/^data:image\/(png|jpeg|jpg);base64,/);
48
- i ? o({
49
- data: r,
52
+ const o = s.result, i = o.match(
53
+ /^data:image\/(png|jpeg|jpg);base64,/
54
+ );
55
+ i ? n({
56
+ data: o,
50
57
  type: i[1]
51
- }) : n(new Error("Could not determine image type"));
52
- }, s.onerror = n, s.readAsDataURL(a);
58
+ }) : r(new Error("Could not determine image type"));
59
+ }, s.onerror = r, s.readAsDataURL(a);
53
60
  });
54
61
  }
55
62
  } catch (e) {
56
63
  return console.warn(e), null;
57
64
  }
58
65
  }
66
+ getBase64(t) {
67
+ return new Promise((e, a) => {
68
+ const n = new FileReader();
69
+ n.readAsDataURL(t), n.onload = () => e(n.result), n.onerror = (r) => a(r);
70
+ });
71
+ }
59
72
  }
60
- const l = new g();
73
+ const l = new c();
61
74
  export {
62
75
  l as default
63
76
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kingteza/crud-component",
3
3
  "private": false,
4
- "version": "1.9.0",
4
+ "version": "1.10.0",
5
5
  "description": "React CRUD component library with Ant Design",
6
6
  "keywords": [
7
7
  "react",