@kingteza/crud-component 1.13.0 → 1.13.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/README.md CHANGED
@@ -16,6 +16,16 @@ This library has the following peer dependencies that need to be installed:
16
16
  npm install antd@^5.22.6 react@^18.3.1 react-dom@^18.3.1 react-router-dom@^7.0.0
17
17
  ```
18
18
 
19
+ ## CSS Styles
20
+
21
+ **Important:** You need to import the CSS styles manually in your application entry point:
22
+
23
+ ```typescript
24
+ import '@kingteza/crud-component/styles';
25
+ ```
26
+
27
+ This should be imported once at the root of your application (e.g., in your `main.tsx`, `index.tsx`, or `App.tsx` file).
28
+
19
29
  ## Setup
20
30
 
21
31
  ### Option 1: Using CrudComponentProvider (Recommended)
@@ -23,6 +33,7 @@ npm install antd@^5.22.6 react@^18.3.1 react-dom@^18.3.1 react-router-dom@^7.0.0
23
33
  Wrap your app with `CrudComponentProvider` to automatically initialize the library:
24
34
 
25
35
  ```typescript
36
+ import '@kingteza/crud-component/styles';
26
37
  import { CrudComponentProvider } from '@kingteza/crud-component';
27
38
 
28
39
  function App() {
@@ -66,6 +77,7 @@ function App() {
66
77
  If you prefer to initialize manually, you can still use `setupI18n()`:
67
78
 
68
79
  ```typescript
80
+ import '@kingteza/crud-component/styles';
69
81
  import { setupI18n } from '@kingteza/crud-component';
70
82
 
71
83
  // Basic setup with default English translations
@@ -88,6 +100,7 @@ setupI18n({
88
100
  ### Usage
89
101
 
90
102
  ```typescript
103
+ import '@kingteza/crud-component/styles';
91
104
  import { CrudComponentProvider, CrudComponent } from '@kingteza/crud-component';
92
105
  import { Button } from '@kingteza/crud-component/common';
93
106
 
@@ -115,6 +128,9 @@ function App() {
115
128
  The library provides several entry points for importing components:
116
129
 
117
130
  ```typescript
131
+ // CSS styles (required - import once at your app entry point)
132
+ import '@kingteza/crud-component/styles';
133
+
118
134
  // Main CRUD component
119
135
  import { CrudComponent } from '@kingteza/crud-component';
120
136
 
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),be=require("react-advanced-cropper"),q=require("@ant-design/icons"),v=require("antd"),s=require("react"),ye=require("../../locale/index.cjs.js"),y=require("../button/Button.cjs.js"),ne=require("../../util/ImageUtil.cjs.js"),ve=require("../../icons/FlipHIcon.cjs.js"),Se=require("../../icons/FlipVIcon.cjs.js"),Ie=v.Form.Item,ie="crud-component.image-picker.button-state";function H(n){return new Promise((d,f)=>{const i=new FileReader;i.readAsDataURL(n),i.onload=()=>d(i.result),i.onerror=m=>f(m)})}const Fe=({values:n=[],required:d,buttonType:f,label:i,name:m,onChange:g,aspectRatio:S,buttonTitle:I,hidePreview:F,buttonSize:x="large",showButtonText:j=!0,showOnlyIcon:L=!1,icon:z=e.jsx(q.UploadOutlined,{}),loading:N,maxCount:O=1,onAdd:l,onRemove:T,listType:P,showSkipCropButton:ae,skipResize:V,...A})=>{const[le,ce]=s.useState(""),[ue,de]=s.useState(""),[pe,J]=s.useState(!1),M=s.useRef(),c=s.useRef(null),[o,E]=s.useState([]),[h,_]=s.useState(),fe=s.useRef(),me=()=>J(!1),ge=async t=>{!t.url&&!t.preview&&(t.preview=await H(t.originFileObj)),de(t.url||t.preview),J(!0),ce(t.name)},[W,p]=s.useState(!1),$=t=>{var r;(r=c.current)==null||r.rotateImage(t?-90:90)},G=s.useCallback(t=>{var r;c.current&&((r=c.current)==null||r.flipImage(t==="h",t==="v"))},[]);s.useEffect(()=>{g==null||g(o[0],o)},[o,g]);const K=s.useCallback(async t=>{var k;const{type:r,size:a,name:w,uid:C}=M.current;if(p(!0),t){const b=M.current,B=V?b:await ne.resizeImage(b),U=await H(B),R={url:U,name:w,uid:C,type:r,size:a,thumbUrl:U,originFileObj:B};if(l)try{p(!0),await l(R)}finally{p(!1)}E([R,...o]),p(!1),_(void 0)}else{const b=(k=c.current)==null?void 0:k.getCanvas();b==null||b.toBlob(async B=>{const U=Object.assign(new File([B],w,{type:r}),{uid:C}),R=V?U:await ne.resizeImage(U),re=await H(R),se={url:re,name:w,uid:C,type:r,size:a,thumbUrl:re,originFileObj:R};if(l)try{p(!0),await l(se)}finally{p(!1)}E([se,...o]),p(!1)}),_(void 0)}},[]),xe=()=>{_(void 0),M.current=void 0},Q=s.useCallback(t=>{const r=t;if(r){M.current=r;const a=new FileReader;a.addEventListener("load",()=>{var w;if(typeof a.result=="string"){_(a.result);const C=localStorage.getItem(ie),k=C?JSON.parse(C):void 0;k&&((w=c.current)==null||w.setState(k)),setTimeout(()=>{te(c.current)},100)}}),a.readAsDataURL(r)}},[]);s.useEffect(()=>{if(n!=null&&n.length||typeof n=="string"){const t=Array.isArray(n)?n.map(r=>[{uid:n,url:r}]):[{uid:n,url:n}];E(t)}},[n]);const{t:u}=ye.useTranslationLib(),je=s.useMemo(()=>d?{required:d,validator:(t,r,a)=>{h||o!=null&&o.length?a():a(`${i??""} ${u("err.validation.required")}`)}}:void 0,[d,h,o==null?void 0:o.length,i,u]),X=I??u("message.uploadButtonText"),Y=s.useMemo(()=>e.jsx(oe,{showLoadingIndicator:W,_buttonTitle:X,buttonSize:x,buttonType:f,fileList:o,hidePreview:F,icon:z,loading:N,listType:P,maxCount:O,onChangeFile:Q,onRemove:T,showButtonText:j,handlePreview:ge,setFileList:E}),[W,X,x,f,o,F,z,N,P,O,Q,T,j]);fe.current=Y.props.beforeUpload;const[he,Z]=s.useState(0),[we,ee]=s.useState(0),[D,Ce]=s.useState();s.useEffect(()=>{const t=setTimeout(()=>{D&&localStorage.setItem(ie,JSON.stringify(D))},400);return()=>clearTimeout(t)},[D]),s.useEffect(()=>{if(!h){Z(0),ee(0);const t=setTimeout(()=>{var r;(r=c.current)==null||r.reset()},1500);return()=>clearTimeout(t)}},[h]);const te=s.useCallback(async t=>{if(t){const r=t.getCoordinates();Ce(t.getState()),Z((r==null?void 0:r.width)??10),ee((r==null?void 0:r.height)??10)}},[]);return e.jsxs(e.Fragment,{children:[e.jsx(Ie,{label:i,...A,name:m,className:"mb-0",rules:[je,...A.rules??[]],children:Y}),e.jsxs(v.Modal,{open:!!h,maskClosable:!1,onOk:()=>K(!1),closable:!1,onCancel:xe,footer:(t,{CancelBtn:r,OkBtn:a})=>ae?e.jsxs(v.Space,{children:[e.jsx(r,{}),e.jsx(y,{type:"primary",onClick:()=>K(!0),children:u("str.skipCrop")}),e.jsx(a,{})]}):e.jsx(e.Fragment,{children:t}),destroyOnHidden:!0,children:[e.jsx(be.Cropper,{ref:c,stencilProps:{grid:!0},style:{border:"1px solid black"},src:h,onChange:t=>{te(t)},aspectRatio:S?{minimum:S,maximum:S}:void 0}),e.jsx("p",{className:"text-center",children:[he,we].join(" ⨉ ")}),e.jsx("div",{className:"mt-2 d-flex justify-content-center",children:e.jsxs(v.Space.Compact,{children:[e.jsx(y,{size:"large",tooltip:u("str.rotateLeft"),icon:e.jsx(q.RotateLeftOutlined,{}),onClick:()=>$(!0)}),e.jsx(y,{size:"large",icon:e.jsx(q.RotateRightOutlined,{}),tooltip:u("str.rotateRight"),onClick:()=>$(!1)}),e.jsx(y,{size:"large",icon:e.jsx(ve,{}),tooltip:u("str.flipHorizontal"),onClick:()=>G("h")}),e.jsx(y,{size:"large",icon:e.jsx(Se,{}),tooltip:u("str.flipVertical"),onClick:()=>G("v")})]})})]}),e.jsx(v.Modal,{open:pe,title:le,footer:null,onCancel:me,children:e.jsx("div",{className:"text-center",children:e.jsx("img",{alt:"example",style:{maxWidth:"400px"},src:ue})})})]})},oe=({_buttonTitle:n,buttonSize:d,buttonType:f,fileList:i,hidePreview:m,icon:g,loading:S,maxCount:I,onChangeFile:F,onRemove:x,showButtonText:j,handlePreview:L,setFileList:z,showLoadingIndicator:N,listType:O="picture"})=>e.jsxs(v.Upload,{accept:"image/x-png,image/gif,image/jpeg",fileList:i,defaultFileList:i,onChange:()=>{},className:(i.length>=I?" hide-upload ":"")+" mb-0",multiple:!1,onPreview:m?void 0:L,onDrop:l=>(F(l.dataTransfer.files.item(0)),!1),listType:O,showUploadList:!m,onRemove:l=>{const T=i.filter(P=>l.uid!==P.uid);x==null||x(l),z(T)},beforeUpload:async l=>(F(l),!1),maxCount:I,children:[N&&e.jsx(q.LoadingOutlined,{}),e.jsx("div",{className:"d-flex flex-column",children:i.length<I&&(O==="picture-circle"?e.jsx(q.UploadOutlined,{}):e.jsx(y,{loading:S,tooltip:j?void 0:n,size:d,icon:g,type:j?f:"text",children:j?n:void 0}))})]},i.length);exports.UploadComponent=oe;exports.default=Fe;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("react/jsx-runtime"),ye=require("react-advanced-cropper"),q=require("@ant-design/icons"),y=require("antd"),s=require("react"),Se=require("../../locale/index.cjs.js"),v=require("../button/Button.cjs.js"),ie=require("../../util/ImageUtil.cjs.js"),ke=require("../../icons/FlipHIcon.cjs.js"),Ie=require("../../icons/FlipVIcon.cjs.js"),Fe=y.Form.Item,ae="crud-component.image-picker.button-state";function V(o){return new Promise((d,f)=>{const n=new FileReader;n.readAsDataURL(o),n.onload=()=>d(n.result),n.onerror=m=>f(m)})}const Oe=({values:o=[],required:d,buttonType:f,label:n,name:m,onChange:g,aspectRatio:S,buttonTitle:k,hidePreview:I,buttonSize:x="large",showButtonText:j=!0,showOnlyIcon:A=!1,icon:z=t.jsx(q.UploadOutlined,{}),loading:N,maxCount:F=1,onAdd:l,onRemove:P,listType:T,showSkipCropButton:ce,skipResize:J,...W})=>{const[ue,de]=s.useState(""),[pe,fe]=s.useState(""),[me,$]=s.useState(!1),B=s.useRef(),c=s.useRef(null),[i,M]=s.useState([]),[h,E]=s.useState(),ge=s.useRef(),xe=()=>$(!1),je=async e=>{!e.url&&!e.preview&&(e.preview=await V(e.originFileObj)),fe(e.url||e.preview),$(!0),de(e.name)},[G,p]=s.useState(!1),K=e=>{var r;(r=c.current)==null||r.rotateImage(e?-90:90)},Q=s.useCallback(e=>{var r;c.current&&((r=c.current)==null||r.flipImage(e==="h",e==="v"))},[]);s.useEffect(()=>{g==null||g(i[0],i)},[i,g]);const[_,H]=s.useState(),X=s.useCallback(async e=>{var O;const{type:r,size:a,name:b,uid:w}=B.current;if(H(e?"skip-crop":"crop"),p(!0),e){const C=B.current,D=J?C:await ie.resizeImage(C),U=await V(D),R={url:U,name:b,uid:w,type:r,size:a,thumbUrl:U,originFileObj:D};if(l)try{p(!0),await l(R)}finally{p(!1)}M([R,...i]),p(!1),E(void 0),H(void 0)}else{const C=(O=c.current)==null?void 0:O.getCanvas();C==null||C.toBlob(async D=>{const U=Object.assign(new File([D],b,{type:r}),{uid:w}),R=J?U:await ie.resizeImage(U),oe=await V(R),ne={url:oe,name:b,uid:w,type:r,size:a,thumbUrl:oe,originFileObj:R};if(l)try{p(!0),await l(ne)}finally{p(!1)}M([ne,...i]),p(!1)}),E(void 0),H(void 0)}},[]),he=()=>{E(void 0),B.current=void 0},Y=s.useCallback(e=>{const r=e;if(r){B.current=r;const a=new FileReader;a.addEventListener("load",()=>{var b;if(typeof a.result=="string"){E(a.result);const w=localStorage.getItem(ae),O=w?JSON.parse(w):void 0;O&&((b=c.current)==null||b.setState(O)),setTimeout(()=>{se(c.current)},100)}}),a.readAsDataURL(r)}},[]);s.useEffect(()=>{if(o!=null&&o.length||typeof o=="string"){const e=Array.isArray(o)?o.map(r=>[{uid:o,url:r}]):[{uid:o,url:o}];M(e)}},[o]);const{t:u}=Se.useTranslationLib(),be=s.useMemo(()=>d?{required:d,validator:(e,r,a)=>{h||i!=null&&i.length?a():a(`${n??""} ${u("err.validation.required")}`)}}:void 0,[d,h,i==null?void 0:i.length,n,u]),Z=k??u("message.uploadButtonText"),ee=s.useMemo(()=>t.jsx(le,{showLoadingIndicator:G,_buttonTitle:Z,buttonSize:x,buttonType:f,fileList:i,hidePreview:I,icon:z,loading:N,listType:T,maxCount:F,onChangeFile:Y,onRemove:P,showButtonText:j,handlePreview:je,setFileList:M}),[G,Z,x,f,i,I,z,N,T,F,Y,P,j]);ge.current=ee.props.beforeUpload;const[we,te]=s.useState(0),[Ce,re]=s.useState(0),[L,ve]=s.useState();s.useEffect(()=>{const e=setTimeout(()=>{L&&localStorage.setItem(ae,JSON.stringify(L))},400);return()=>clearTimeout(e)},[L]),s.useEffect(()=>{if(!h){te(0),re(0);const e=setTimeout(()=>{var r;(r=c.current)==null||r.reset()},1500);return()=>clearTimeout(e)}},[h]);const se=s.useCallback(async e=>{if(e){const r=e.getCoordinates();ve(e.getState()),te((r==null?void 0:r.width)??10),re((r==null?void 0:r.height)??10)}},[]);return t.jsxs(t.Fragment,{children:[t.jsx(Fe,{label:n,...W,name:m,className:"mb-0",rules:[be,...W.rules??[]],children:ee}),t.jsxs(y.Modal,{open:!!h,maskClosable:!1,onOk:()=>X(!1),closable:!1,okButtonProps:{loading:_==="crop",disabled:_==="skip-crop"},onCancel:he,footer:(e,{CancelBtn:r,OkBtn:a})=>ce?t.jsxs(y.Space,{children:[t.jsx(r,{}),t.jsx(v,{type:"primary",loading:_==="skip-crop",disabled:_==="crop",onClick:()=>X(!0),children:u("str.skipCrop")}),t.jsx(a,{})]}):t.jsx(t.Fragment,{children:e}),destroyOnHidden:!0,children:[t.jsx(ye.Cropper,{ref:c,stencilProps:{grid:!0},style:{border:"1px solid black"},src:h,onChange:e=>{se(e)},aspectRatio:S?{minimum:S,maximum:S}:void 0}),t.jsx("p",{className:"text-center",children:[we,Ce].join(" ⨉ ")}),t.jsx("div",{className:"mt-2 d-flex justify-content-center",children:t.jsxs(y.Space.Compact,{children:[t.jsx(v,{size:"large",tooltip:u("str.rotateLeft"),icon:t.jsx(q.RotateLeftOutlined,{}),onClick:()=>K(!0)}),t.jsx(v,{size:"large",icon:t.jsx(q.RotateRightOutlined,{}),tooltip:u("str.rotateRight"),onClick:()=>K(!1)}),t.jsx(v,{size:"large",icon:t.jsx(ke,{}),tooltip:u("str.flipHorizontal"),onClick:()=>Q("h")}),t.jsx(v,{size:"large",icon:t.jsx(Ie,{}),tooltip:u("str.flipVertical"),onClick:()=>Q("v")})]})})]}),t.jsx(y.Modal,{open:me,title:ue,footer:null,onCancel:xe,children:t.jsx("div",{className:"text-center",children:t.jsx("img",{alt:"example",style:{maxWidth:"400px"},src:pe})})})]})},le=({_buttonTitle:o,buttonSize:d,buttonType:f,fileList:n,hidePreview:m,icon:g,loading:S,maxCount:k,onChangeFile:I,onRemove:x,showButtonText:j,handlePreview:A,setFileList:z,showLoadingIndicator:N,listType:F="picture"})=>t.jsxs(y.Upload,{accept:"image/x-png,image/gif,image/jpeg",fileList:n,defaultFileList:n,onChange:()=>{},className:(n.length>=k?" hide-upload ":"")+" mb-0",multiple:!1,onPreview:m?void 0:A,onDrop:l=>(I(l.dataTransfer.files.item(0)),!1),listType:F,showUploadList:!m,onRemove:l=>{const P=n.filter(T=>l.uid!==T.uid);x==null||x(l),z(P)},beforeUpload:async l=>(I(l),!1),maxCount:k,children:[N&&t.jsx(q.LoadingOutlined,{}),t.jsx("div",{className:"d-flex flex-column",children:n.length<k&&(F==="picture-circle"?t.jsx(q.UploadOutlined,{}):t.jsx(v,{loading:S,tooltip:j?void 0:o,size:d,icon:g,type:j?f:"text",children:j?o:void 0}))})]},n.length);exports.UploadComponent=le;exports.default=Oe;
@@ -1,279 +1,285 @@
1
- import { jsx as r, jsxs as j, Fragment as se } from "react/jsx-runtime";
2
- import { Cropper as Se } from "react-advanced-cropper";
3
- import { RotateLeftOutlined as Re, RotateRightOutlined as je, UploadOutlined as ue, LoadingOutlined as ze } from "@ant-design/icons";
4
- import { Form as Ne, Modal as le, Space as ce, Upload as Te } from "antd";
5
- import M, { useRef as A, useState as v, useCallback as V, useEffect as _, useMemo as de } from "react";
6
- import { useTranslationLib as Pe } from "../../locale/index.es.js";
1
+ import { jsx as r, jsxs as j, Fragment as ce } from "react/jsx-runtime";
2
+ import { Cropper as je } from "react-advanced-cropper";
3
+ import { RotateLeftOutlined as ze, RotateRightOutlined as Ne, UploadOutlined as ge, LoadingOutlined as Be } from "@ant-design/icons";
4
+ import { Form as Pe, Modal as de, Space as pe, Upload as Te } from "antd";
5
+ import J, { useRef as W, useState as m, useCallback as _, useEffect as E, useMemo as me } from "react";
6
+ import { useTranslationLib as De } from "../../locale/index.es.js";
7
7
  import I from "../button/Button.es.js";
8
- import me from "../../util/ImageUtil.es.js";
9
- import Be from "../../icons/FlipHIcon.es.js";
10
- import De from "../../icons/FlipVIcon.es.js";
11
- const He = Ne.Item, pe = "crud-component.image-picker.button-state";
12
- function J(o) {
13
- return new Promise((d, p) => {
8
+ import ue from "../../util/ImageUtil.es.js";
9
+ import He from "../../icons/FlipHIcon.es.js";
10
+ import Le from "../../icons/FlipVIcon.es.js";
11
+ const Ve = Pe.Item, fe = "crud-component.image-picker.button-state";
12
+ function $(o) {
13
+ return new Promise((d, u) => {
14
14
  const i = new FileReader();
15
- i.readAsDataURL(o), i.onload = () => d(i.result), i.onerror = (u) => p(u);
15
+ i.readAsDataURL(o), i.onload = () => d(i.result), i.onerror = (f) => u(f);
16
16
  });
17
17
  }
18
- const Qe = ({
18
+ const Ye = ({
19
19
  values: o = [],
20
20
  required: d,
21
- buttonType: p,
21
+ buttonType: u,
22
22
  label: i,
23
- name: u,
24
- onChange: f,
25
- aspectRatio: F,
26
- buttonTitle: O,
27
- hidePreview: x,
28
- buttonSize: g = "large",
29
- showButtonText: h = !0,
30
- showOnlyIcon: W = !1,
31
- icon: z = /* @__PURE__ */ r(ue, {}),
23
+ name: f,
24
+ onChange: g,
25
+ aspectRatio: k,
26
+ buttonTitle: F,
27
+ hidePreview: O,
28
+ buttonSize: h = "large",
29
+ showButtonText: w = !0,
30
+ showOnlyIcon: G = !1,
31
+ icon: z = /* @__PURE__ */ r(ge, {}),
32
32
  loading: N,
33
- maxCount: U = 1,
33
+ maxCount: x = 1,
34
34
  onAdd: s,
35
- onRemove: T,
35
+ onRemove: B,
36
36
  listType: P,
37
- showSkipCropButton: fe,
38
- skipResize: $,
39
- ...G
37
+ showSkipCropButton: he,
38
+ skipResize: K,
39
+ ...Q
40
40
  }) => {
41
- const [ge, he] = M.useState(""), [we, ye] = M.useState(""), [Ce, K] = M.useState(!1), B = A(), l = A(null), [n, D] = v([]), [w, H] = v(), be = A(), ve = () => K(!1), Ie = async (e) => {
42
- !e.url && !e.preview && (e.preview = await J(e.originFileObj)), ye(e.url || e.preview), K(!0), he(e.name);
43
- }, [Q, m] = v(!1), X = (e) => {
41
+ const [we, be] = J.useState(""), [ye, ve] = J.useState(""), [Ce, X] = J.useState(!1), T = W(), l = W(null), [n, D] = m([]), [b, H] = m(), Ie = W(), ke = () => X(!1), Fe = async (e) => {
42
+ !e.url && !e.preview && (e.preview = await $(e.originFileObj)), ve(e.url || e.preview), X(!0), be(e.name);
43
+ }, [Y, p] = m(!1), Z = (e) => {
44
44
  var t;
45
45
  (t = l.current) == null || t.rotateImage(e ? -90 : 90);
46
- }, Y = V((e) => {
46
+ }, q = _((e) => {
47
47
  var t;
48
48
  l.current && ((t = l.current) == null || t.flipImage(e === "h", e === "v"));
49
49
  }, []);
50
- _(() => {
51
- f == null || f(n[0], n);
52
- }, [n, f]);
53
- const Z = V(async (e) => {
54
- var k;
55
- const { type: t, size: a, name: y, uid: C } = B.current;
56
- if (m(!0), e) {
57
- const b = B.current, L = $ ? b : await me.resizeImage(b), S = await J(L), R = {
50
+ E(() => {
51
+ g == null || g(n[0], n);
52
+ }, [n, g]);
53
+ const [L, M] = m(), ee = _(async (e) => {
54
+ var U;
55
+ const { type: t, size: a, name: y, uid: v } = T.current;
56
+ if (M(e ? "skip-crop" : "crop"), p(!0), e) {
57
+ const C = T.current, V = K ? C : await ue.resizeImage(C), S = await $(V), R = {
58
58
  url: S,
59
59
  name: y,
60
- uid: C,
60
+ uid: v,
61
61
  type: t,
62
62
  size: a,
63
63
  thumbUrl: S,
64
- originFileObj: L
64
+ originFileObj: V
65
65
  };
66
66
  if (s)
67
67
  try {
68
- m(!0), await s(R);
68
+ p(!0), await s(R);
69
69
  } finally {
70
- m(!1);
70
+ p(!1);
71
71
  }
72
- D([R, ...n]), m(!1), H(void 0);
72
+ D([R, ...n]), p(!1), H(void 0), M(void 0);
73
73
  } else {
74
- const b = (k = l.current) == null ? void 0 : k.getCanvas();
75
- b == null || b.toBlob(async (L) => {
76
- const S = Object.assign(new File([L], y, { type: t }), {
77
- uid: C
78
- }), R = $ ? S : await me.resizeImage(S), ne = await J(R), ae = {
79
- url: ne,
74
+ const C = (U = l.current) == null ? void 0 : U.getCanvas();
75
+ C == null || C.toBlob(async (V) => {
76
+ const S = Object.assign(new File([V], y, { type: t }), {
77
+ uid: v
78
+ }), R = K ? S : await ue.resizeImage(S), se = await $(R), le = {
79
+ url: se,
80
80
  name: y,
81
- uid: C,
81
+ uid: v,
82
82
  type: t,
83
83
  size: a,
84
- thumbUrl: ne,
84
+ thumbUrl: se,
85
85
  originFileObj: R
86
86
  };
87
87
  if (s)
88
88
  try {
89
- m(!0), await s(ae);
89
+ p(!0), await s(le);
90
90
  } finally {
91
- m(!1);
91
+ p(!1);
92
92
  }
93
- D([ae, ...n]), m(!1);
94
- }), H(void 0);
93
+ D([le, ...n]), p(!1);
94
+ }), H(void 0), M(void 0);
95
95
  }
96
- }, []), Fe = () => {
97
- H(void 0), B.current = void 0;
98
- }, q = V((e) => {
96
+ }, []), Oe = () => {
97
+ H(void 0), T.current = void 0;
98
+ }, te = _((e) => {
99
99
  const t = e;
100
100
  if (t) {
101
- B.current = t;
101
+ T.current = t;
102
102
  const a = new FileReader();
103
103
  a.addEventListener("load", () => {
104
104
  var y;
105
105
  if (typeof a.result == "string") {
106
106
  H(a.result);
107
- const C = localStorage.getItem(pe), k = C ? JSON.parse(C) : void 0;
108
- k && ((y = l.current) == null || y.setState(k)), setTimeout(() => {
109
- ie(l.current);
107
+ const v = localStorage.getItem(fe), U = v ? JSON.parse(v) : void 0;
108
+ U && ((y = l.current) == null || y.setState(U)), setTimeout(() => {
109
+ ae(l.current);
110
110
  }, 100);
111
111
  }
112
112
  }), a.readAsDataURL(t);
113
113
  }
114
114
  }, []);
115
- _(() => {
115
+ E(() => {
116
116
  if (o != null && o.length || typeof o == "string") {
117
117
  const e = Array.isArray(o) ? o.map((t) => [{ uid: o, url: t }]) : [{ uid: o, url: o }];
118
118
  D(e);
119
119
  }
120
120
  }, [o]);
121
- const { t: c } = Pe(), Oe = de(
121
+ const { t: c } = De(), xe = me(
122
122
  () => d ? {
123
123
  required: d,
124
124
  validator: (e, t, a) => {
125
- w || n != null && n.length ? a() : a(`${i ?? ""} ${c("err.validation.required")}`);
125
+ b || n != null && n.length ? a() : a(`${i ?? ""} ${c("err.validation.required")}`);
126
126
  }
127
127
  } : void 0,
128
- [d, w, n == null ? void 0 : n.length, i, c]
129
- ), ee = O ?? c("message.uploadButtonText"), te = de(
128
+ [d, b, n == null ? void 0 : n.length, i, c]
129
+ ), re = F ?? c("message.uploadButtonText"), oe = me(
130
130
  () => /* @__PURE__ */ r(
131
- Le,
131
+ _e,
132
132
  {
133
- showLoadingIndicator: Q,
134
- _buttonTitle: ee,
135
- buttonSize: g,
136
- buttonType: p,
133
+ showLoadingIndicator: Y,
134
+ _buttonTitle: re,
135
+ buttonSize: h,
136
+ buttonType: u,
137
137
  fileList: n,
138
- hidePreview: x,
138
+ hidePreview: O,
139
139
  icon: z,
140
140
  loading: N,
141
141
  listType: P,
142
- maxCount: U,
143
- onChangeFile: q,
144
- onRemove: T,
145
- showButtonText: h,
146
- handlePreview: Ie,
142
+ maxCount: x,
143
+ onChangeFile: te,
144
+ onRemove: B,
145
+ showButtonText: w,
146
+ handlePreview: Fe,
147
147
  setFileList: D
148
148
  }
149
149
  ),
150
150
  [
151
- Q,
152
- ee,
153
- g,
154
- p,
151
+ Y,
152
+ re,
153
+ h,
154
+ u,
155
155
  n,
156
- x,
156
+ O,
157
157
  z,
158
158
  N,
159
159
  P,
160
- U,
161
- q,
162
- T,
163
- h
160
+ x,
161
+ te,
162
+ B,
163
+ w
164
164
  ]
165
165
  );
166
- be.current = te.props.beforeUpload;
167
- const [xe, re] = v(0), [Ue, oe] = v(0), [E, ke] = v();
168
- _(() => {
166
+ Ie.current = oe.props.beforeUpload;
167
+ const [Ue, ie] = m(0), [Se, ne] = m(0), [A, Re] = m();
168
+ E(() => {
169
169
  const e = setTimeout(() => {
170
- E && localStorage.setItem(pe, JSON.stringify(E));
170
+ A && localStorage.setItem(fe, JSON.stringify(A));
171
171
  }, 400);
172
172
  return () => clearTimeout(e);
173
- }, [E]), _(() => {
174
- if (!w) {
175
- re(0), oe(0);
173
+ }, [A]), E(() => {
174
+ if (!b) {
175
+ ie(0), ne(0);
176
176
  const e = setTimeout(() => {
177
177
  var t;
178
178
  (t = l.current) == null || t.reset();
179
179
  }, 1500);
180
180
  return () => clearTimeout(e);
181
181
  }
182
- }, [w]);
183
- const ie = V(async (e) => {
182
+ }, [b]);
183
+ const ae = _(async (e) => {
184
184
  if (e) {
185
185
  const t = e.getCoordinates();
186
- ke(e.getState()), re((t == null ? void 0 : t.width) ?? 10), oe((t == null ? void 0 : t.height) ?? 10);
186
+ Re(e.getState()), ie((t == null ? void 0 : t.width) ?? 10), ne((t == null ? void 0 : t.height) ?? 10);
187
187
  }
188
188
  }, []);
189
- return /* @__PURE__ */ j(se, { children: [
189
+ return /* @__PURE__ */ j(ce, { children: [
190
190
  /* @__PURE__ */ r(
191
- He,
191
+ Ve,
192
192
  {
193
193
  label: i,
194
- ...G,
195
- name: u,
194
+ ...Q,
195
+ name: f,
196
196
  className: "mb-0",
197
- rules: [Oe, ...G.rules ?? []],
198
- children: te
197
+ rules: [xe, ...Q.rules ?? []],
198
+ children: oe
199
199
  }
200
200
  ),
201
201
  /* @__PURE__ */ j(
202
- le,
202
+ de,
203
203
  {
204
- open: !!w,
204
+ open: !!b,
205
205
  maskClosable: !1,
206
- onOk: () => Z(!1),
206
+ onOk: () => ee(!1),
207
207
  closable: !1,
208
- onCancel: Fe,
209
- footer: (e, { CancelBtn: t, OkBtn: a }) => fe ? /* @__PURE__ */ j(ce, { children: [
208
+ okButtonProps: {
209
+ loading: L === "crop",
210
+ disabled: L === "skip-crop"
211
+ },
212
+ onCancel: Oe,
213
+ footer: (e, { CancelBtn: t, OkBtn: a }) => he ? /* @__PURE__ */ j(pe, { children: [
210
214
  /* @__PURE__ */ r(t, {}),
211
215
  /* @__PURE__ */ r(
212
216
  I,
213
217
  {
214
218
  type: "primary",
215
- onClick: () => Z(!0),
219
+ loading: L === "skip-crop",
220
+ disabled: L === "crop",
221
+ onClick: () => ee(!0),
216
222
  children: c("str.skipCrop")
217
223
  }
218
224
  ),
219
225
  /* @__PURE__ */ r(a, {})
220
- ] }) : /* @__PURE__ */ r(se, { children: e }),
226
+ ] }) : /* @__PURE__ */ r(ce, { children: e }),
221
227
  destroyOnHidden: !0,
222
228
  children: [
223
229
  /* @__PURE__ */ r(
224
- Se,
230
+ je,
225
231
  {
226
232
  ref: l,
227
233
  stencilProps: {
228
234
  grid: !0
229
235
  },
230
236
  style: { border: "1px solid black" },
231
- src: w,
237
+ src: b,
232
238
  onChange: (e) => {
233
- ie(e);
239
+ ae(e);
234
240
  },
235
- aspectRatio: F ? {
236
- minimum: F,
237
- maximum: F
241
+ aspectRatio: k ? {
242
+ minimum: k,
243
+ maximum: k
238
244
  } : void 0
239
245
  }
240
246
  ),
241
- /* @__PURE__ */ r("p", { className: "text-center", children: [xe, Ue].join(" ⨉ ") }),
242
- /* @__PURE__ */ r("div", { className: "mt-2 d-flex justify-content-center", children: /* @__PURE__ */ j(ce.Compact, { children: [
247
+ /* @__PURE__ */ r("p", { className: "text-center", children: [Ue, Se].join(" ⨉ ") }),
248
+ /* @__PURE__ */ r("div", { className: "mt-2 d-flex justify-content-center", children: /* @__PURE__ */ j(pe.Compact, { children: [
243
249
  /* @__PURE__ */ r(
244
250
  I,
245
251
  {
246
252
  size: "large",
247
253
  tooltip: c("str.rotateLeft"),
248
- icon: /* @__PURE__ */ r(Re, {}),
249
- onClick: () => X(!0)
254
+ icon: /* @__PURE__ */ r(ze, {}),
255
+ onClick: () => Z(!0)
250
256
  }
251
257
  ),
252
258
  /* @__PURE__ */ r(
253
259
  I,
254
260
  {
255
261
  size: "large",
256
- icon: /* @__PURE__ */ r(je, {}),
262
+ icon: /* @__PURE__ */ r(Ne, {}),
257
263
  tooltip: c("str.rotateRight"),
258
- onClick: () => X(!1)
264
+ onClick: () => Z(!1)
259
265
  }
260
266
  ),
261
267
  /* @__PURE__ */ r(
262
268
  I,
263
269
  {
264
270
  size: "large",
265
- icon: /* @__PURE__ */ r(Be, {}),
271
+ icon: /* @__PURE__ */ r(He, {}),
266
272
  tooltip: c("str.flipHorizontal"),
267
- onClick: () => Y("h")
273
+ onClick: () => q("h")
268
274
  }
269
275
  ),
270
276
  /* @__PURE__ */ r(
271
277
  I,
272
278
  {
273
279
  size: "large",
274
- icon: /* @__PURE__ */ r(De, {}),
280
+ icon: /* @__PURE__ */ r(Le, {}),
275
281
  tooltip: c("str.flipVertical"),
276
- onClick: () => Y("v")
282
+ onClick: () => q("v")
277
283
  }
278
284
  )
279
285
  ] }) })
@@ -281,32 +287,32 @@ const Qe = ({
281
287
  }
282
288
  ),
283
289
  /* @__PURE__ */ r(
284
- le,
290
+ de,
285
291
  {
286
292
  open: Ce,
287
- title: ge,
293
+ title: we,
288
294
  footer: null,
289
- onCancel: ve,
290
- children: /* @__PURE__ */ r("div", { className: "text-center", children: /* @__PURE__ */ r("img", { alt: "example", style: { maxWidth: "400px" }, src: we }) })
295
+ onCancel: ke,
296
+ children: /* @__PURE__ */ r("div", { className: "text-center", children: /* @__PURE__ */ r("img", { alt: "example", style: { maxWidth: "400px" }, src: ye }) })
291
297
  }
292
298
  )
293
299
  ] });
294
- }, Le = ({
300
+ }, _e = ({
295
301
  _buttonTitle: o,
296
302
  buttonSize: d,
297
- buttonType: p,
303
+ buttonType: u,
298
304
  fileList: i,
299
- hidePreview: u,
300
- icon: f,
301
- loading: F,
302
- maxCount: O,
303
- onChangeFile: x,
304
- onRemove: g,
305
- showButtonText: h,
306
- handlePreview: W,
305
+ hidePreview: f,
306
+ icon: g,
307
+ loading: k,
308
+ maxCount: F,
309
+ onChangeFile: O,
310
+ onRemove: h,
311
+ showButtonText: w,
312
+ handlePreview: G,
307
313
  setFileList: z,
308
314
  showLoadingIndicator: N,
309
- listType: U = "picture"
315
+ listType: x = "picture"
310
316
  }) => /* @__PURE__ */ j(
311
317
  Te,
312
318
  {
@@ -315,29 +321,29 @@ const Qe = ({
315
321
  defaultFileList: i,
316
322
  onChange: () => {
317
323
  },
318
- className: (i.length >= O ? " hide-upload " : "") + " mb-0",
324
+ className: (i.length >= F ? " hide-upload " : "") + " mb-0",
319
325
  multiple: !1,
320
- onPreview: u ? void 0 : W,
321
- onDrop: (s) => (x(s.dataTransfer.files.item(0)), !1),
322
- listType: U,
323
- showUploadList: !u,
326
+ onPreview: f ? void 0 : G,
327
+ onDrop: (s) => (O(s.dataTransfer.files.item(0)), !1),
328
+ listType: x,
329
+ showUploadList: !f,
324
330
  onRemove: (s) => {
325
- const T = i.filter((P) => s.uid !== P.uid);
326
- g == null || g(s), z(T);
331
+ const B = i.filter((P) => s.uid !== P.uid);
332
+ h == null || h(s), z(B);
327
333
  },
328
- beforeUpload: async (s) => (x(s), !1),
329
- maxCount: O,
334
+ beforeUpload: async (s) => (O(s), !1),
335
+ maxCount: F,
330
336
  children: [
331
- N && /* @__PURE__ */ r(ze, {}),
332
- /* @__PURE__ */ r("div", { className: "d-flex flex-column", children: i.length < O && (U === "picture-circle" ? /* @__PURE__ */ r(ue, {}) : /* @__PURE__ */ r(
337
+ N && /* @__PURE__ */ r(Be, {}),
338
+ /* @__PURE__ */ r("div", { className: "d-flex flex-column", children: i.length < F && (x === "picture-circle" ? /* @__PURE__ */ r(ge, {}) : /* @__PURE__ */ r(
333
339
  I,
334
340
  {
335
- loading: F,
336
- tooltip: h ? void 0 : o,
341
+ loading: k,
342
+ tooltip: w ? void 0 : o,
337
343
  size: d,
338
- icon: f,
339
- type: h ? p : "text",
340
- children: h ? o : void 0
344
+ icon: g,
345
+ type: w ? u : "text",
346
+ children: w ? o : void 0
341
347
  }
342
348
  )) })
343
349
  ]
@@ -345,6 +351,6 @@ const Qe = ({
345
351
  i.length
346
352
  );
347
353
  export {
348
- Le as UploadComponent,
349
- Qe as default
354
+ _e as UploadComponent,
355
+ Ye as default
350
356
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kingteza/crud-component",
3
3
  "private": false,
4
- "version": "1.13.0",
4
+ "version": "1.13.2",
5
5
  "description": "React CRUD component library with Ant Design",
6
6
  "keywords": [
7
7
  "react",