@kingteza/crud-component 1.10.4 → 1.12.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.
- package/README.md +64 -16
- package/dist/common/button/Button.cjs.js +1 -1
- package/dist/common/button/Button.es.js +9 -10
- package/dist/common/picker/ImagePicker.cjs.js +1 -1
- package/dist/common/picker/ImagePicker.d.ts +2 -0
- package/dist/common/picker/ImagePicker.es.js +217 -185
- package/dist/common/rich/index.cjs.js +1 -1
- package/dist/common/rich/index.es.js +14 -16
- package/dist/context/CrudComponentProvider.cjs.js +1 -0
- package/dist/context/CrudComponentProvider.d.ts +12 -0
- package/dist/context/CrudComponentProvider.es.js +14 -0
- package/dist/context/index.d.ts +1 -0
- package/dist/crud/CrudField.cjs.js +1 -1
- package/dist/crud/CrudField.es.js +272 -284
- package/dist/crud/FileCrudField.cjs.js +1 -1
- package/dist/crud/FileCrudField.es.js +41 -42
- package/dist/crud/ImageCrudField.cjs.js +1 -1
- package/dist/crud/ImageCrudField.d.ts +2 -0
- package/dist/crud/ImageCrudField.es.js +61 -57
- package/dist/crud-component.css +7 -2
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +22 -20
- package/dist/locale/index.cjs.js +1 -1
- package/dist/locale/index.d.ts +1 -0
- package/dist/locale/index.es.js +51 -39
- package/dist/locale/translations/en.cjs.js +1 -1
- package/dist/locale/translations/en.d.ts +1 -0
- package/dist/locale/translations/en.es.js +2 -1
- package/dist/main.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,9 +18,52 @@ npm install antd@^5.22.6 react@^18.3.1 react-dom@^18.3.1 react-router-dom@^7.0.0
|
|
|
18
18
|
|
|
19
19
|
## Setup
|
|
20
20
|
|
|
21
|
-
### 1
|
|
21
|
+
### Option 1: Using CrudComponentProvider (Recommended)
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
Wrap your app with `CrudComponentProvider` to automatically initialize the library:
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { CrudComponentProvider } from '@kingteza/crud-component';
|
|
27
|
+
|
|
28
|
+
function App() {
|
|
29
|
+
return (
|
|
30
|
+
<CrudComponentProvider>
|
|
31
|
+
{/* Your app components */}
|
|
32
|
+
<YourComponents />
|
|
33
|
+
</CrudComponentProvider>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
With custom i18n options:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { CrudComponentProvider } from '@kingteza/crud-component';
|
|
42
|
+
|
|
43
|
+
function App() {
|
|
44
|
+
return (
|
|
45
|
+
<CrudComponentProvider
|
|
46
|
+
i18nOptions={{
|
|
47
|
+
language: 'en',
|
|
48
|
+
translations: {
|
|
49
|
+
en: {
|
|
50
|
+
'crud-component': {
|
|
51
|
+
// your custom translations
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
i18nInstance: existingI18nInstance // optional: use your existing i18n instance
|
|
56
|
+
}}
|
|
57
|
+
>
|
|
58
|
+
<YourComponents />
|
|
59
|
+
</CrudComponentProvider>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Option 2: Manual Setup (Legacy)
|
|
65
|
+
|
|
66
|
+
If you prefer to initialize manually, you can still use `setupI18n()`:
|
|
24
67
|
|
|
25
68
|
```typescript
|
|
26
69
|
import { setupI18n } from '@kingteza/crud-component';
|
|
@@ -30,7 +73,7 @@ setupI18n();
|
|
|
30
73
|
|
|
31
74
|
// Or with custom options
|
|
32
75
|
setupI18n({
|
|
33
|
-
language: 'en',
|
|
76
|
+
language: 'en',
|
|
34
77
|
translations: {
|
|
35
78
|
en: {
|
|
36
79
|
'crud-component': {
|
|
@@ -42,30 +85,32 @@ setupI18n({
|
|
|
42
85
|
});
|
|
43
86
|
```
|
|
44
87
|
|
|
45
|
-
###
|
|
88
|
+
### Usage
|
|
46
89
|
|
|
47
90
|
```typescript
|
|
48
|
-
import { CrudComponent } from '@kingteza/crud-component';
|
|
91
|
+
import { CrudComponentProvider, CrudComponent } from '@kingteza/crud-component';
|
|
49
92
|
import { Button } from '@kingteza/crud-component/common';
|
|
50
93
|
|
|
51
94
|
function App() {
|
|
52
95
|
return (
|
|
53
|
-
<
|
|
54
|
-
|
|
55
|
-
{
|
|
56
|
-
|
|
57
|
-
{
|
|
58
|
-
|
|
96
|
+
<CrudComponentProvider>
|
|
97
|
+
<CrudComponent
|
|
98
|
+
fields={[
|
|
99
|
+
{ type: "text", name: "name", label: "Name", required: true },
|
|
100
|
+
{ type: "select", name: "status", label: "Status", options: [
|
|
101
|
+
{ value: "active", label: "Active" },
|
|
102
|
+
{ value: "inactive", label: "Inactive" }
|
|
103
|
+
]}
|
|
59
104
|
]}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
105
|
+
data={[]}
|
|
106
|
+
onSave={(data) => console.log(data)}
|
|
107
|
+
/>
|
|
108
|
+
</CrudComponentProvider>
|
|
64
109
|
);
|
|
65
110
|
}
|
|
66
111
|
```
|
|
67
112
|
|
|
68
|
-
###
|
|
113
|
+
### Available Imports
|
|
69
114
|
|
|
70
115
|
The library provides several entry points for importing components:
|
|
71
116
|
|
|
@@ -73,6 +118,9 @@ The library provides several entry points for importing components:
|
|
|
73
118
|
// Main CRUD component
|
|
74
119
|
import { CrudComponent } from '@kingteza/crud-component';
|
|
75
120
|
|
|
121
|
+
// Provider component
|
|
122
|
+
import { CrudComponentProvider } from '@kingteza/crud-component';
|
|
123
|
+
|
|
76
124
|
// Common components
|
|
77
125
|
import { Button, Select, DatePicker } from '@kingteza/crud-component/common';
|
|
78
126
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const l=require("react/jsx-runtime"),d=require("antd"),s=require("react"),
|
|
1
|
+
"use strict";const l=require("react/jsx-runtime"),d=require("antd"),s=require("react"),q=require("../../locale/index.cjs.js"),x=require("../../hooks/NavigatorHooks.cjs.js"),y=s.forwardRef(({className:a,to:n,onClick:t,tooltip:r,...e},u)=>{const{t:i}=q.useTranslationLib(),o=x.useNavigateOptional(),c=s.useMemo(()=>l.jsx(d.Button,{ref:u,onClick:t??(n&&o?()=>o(n):void 0),className:a,...e,children:e.children}),[a,o,t,e,i,n]);return r?l.jsx(d.Tooltip,{title:r,children:c}):c}),h=s.forwardRef(({className:a,to:n,onClick:t,tooltip:r,...e},u)=>{const i=x.useNavigateOptional(),[o,c]=s.useState(!1),f=s.useCallback(async j=>{try{return c(!0),await t(j)}finally{c(!1)}},[t]),g=s.useMemo(()=>l.jsx(d.Button,{ref:u,loading:o||e.loading,onClick:t?f:n?()=>{i?i==null||i(n):window.location.href=n}:void 0,className:a,...e}),[f,a,o,i,t,e,n,u]);return r?l.jsx(d.Tooltip,{title:r,children:g}):g});h.displayName="ButtonComponent.Async";y.Async=h;module.exports=y;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { jsx as c } from "react/jsx-runtime";
|
|
2
|
-
import { Button as
|
|
2
|
+
import { Button as f, Tooltip as m } from "antd";
|
|
3
3
|
import { forwardRef as y, useMemo as g, useState as v, useCallback as A } from "react";
|
|
4
4
|
import { useTranslationLib as B } from "../../locale/index.es.js";
|
|
5
|
-
/* empty css */
|
|
6
5
|
import { useNavigateOptional as h } from "../../hooks/NavigatorHooks.es.js";
|
|
7
|
-
const
|
|
6
|
+
const x = y(
|
|
8
7
|
({ className: r, to: n, onClick: t, tooltip: a, ...o }, l) => {
|
|
9
8
|
const { t: e } = B(), i = h(), s = g(
|
|
10
9
|
() => /* @__PURE__ */ c(
|
|
11
|
-
|
|
10
|
+
f,
|
|
12
11
|
{
|
|
13
12
|
ref: l,
|
|
14
13
|
onClick: t ?? (n && i ? () => i(n) : void 0),
|
|
@@ -19,7 +18,7 @@ const p = y(
|
|
|
19
18
|
),
|
|
20
19
|
[r, i, t, o, e, n]
|
|
21
20
|
);
|
|
22
|
-
return a ? /* @__PURE__ */ c(
|
|
21
|
+
return a ? /* @__PURE__ */ c(m, { title: a, children: s }) : s;
|
|
23
22
|
}
|
|
24
23
|
), b = y(
|
|
25
24
|
({ className: r, to: n, onClick: t, tooltip: a, ...o }, l) => {
|
|
@@ -32,9 +31,9 @@ const p = y(
|
|
|
32
31
|
}
|
|
33
32
|
},
|
|
34
33
|
[t]
|
|
35
|
-
),
|
|
34
|
+
), u = g(
|
|
36
35
|
() => /* @__PURE__ */ c(
|
|
37
|
-
|
|
36
|
+
f,
|
|
38
37
|
{
|
|
39
38
|
ref: l,
|
|
40
39
|
loading: i || o.loading,
|
|
@@ -47,11 +46,11 @@ const p = y(
|
|
|
47
46
|
),
|
|
48
47
|
[d, r, i, e, t, o, n, l]
|
|
49
48
|
);
|
|
50
|
-
return a ? /* @__PURE__ */ c(
|
|
49
|
+
return a ? /* @__PURE__ */ c(m, { title: a, children: u }) : u;
|
|
51
50
|
}
|
|
52
51
|
);
|
|
53
52
|
b.displayName = "ButtonComponent.Async";
|
|
54
|
-
|
|
53
|
+
x.Async = b;
|
|
55
54
|
export {
|
|
56
|
-
|
|
55
|
+
x as default
|
|
57
56
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
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;
|