@kingteza/crud-component 1.0.21 → 1.0.23

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
@@ -8,23 +8,82 @@ React CRUD component library built with Ant Design and TypeScript.
8
8
  npm install @kingteza/crud-component
9
9
  ```
10
10
 
11
- ## Usage
11
+ ## Prerequisites
12
12
 
13
- ```typescript
14
- import { CrudComponent } from '@kingteza/crud-component';
15
- import { Button } from '@kingteza/crud-component/common';
13
+ This library has the following peer dependencies that need to be installed:
14
+
15
+ ```bash
16
+ npm install antd@^5.22.6 react@^18.3.1 react-dom@^18.3.1 react-router-dom@^7.0.0
17
+ ```
18
+
19
+ ## Setup
20
+
21
+ ### 1. Initialize translations
16
22
 
17
- // Initialize translations
23
+ The library uses i18next for internationalization. You need to set it up before using the components:
24
+
25
+ ```typescript
18
26
  import { setupI18n } from '@kingteza/crud-component';
27
+
28
+ // Basic setup with default English translations
19
29
  setupI18n();
20
30
 
31
+ // Or with custom options
32
+ setupI18n({
33
+ language: 'en', // default language
34
+ translations: {
35
+ en: {
36
+ 'crud-component': {
37
+ // your custom translations
38
+ }
39
+ }
40
+ },
41
+ i18nInstance: existingI18nInstance // optional: use your existing i18n instance
42
+ });
43
+ ```
44
+
45
+ ### 2. Usage
46
+
47
+ ```typescript
48
+ import { CrudComponent } from '@kingteza/crud-component';
49
+ import { Button } from '@kingteza/crud-component/common';
50
+
21
51
  function App() {
22
52
  return (
23
53
  <CrudComponent
24
54
  fields={[
25
- { type: "text", name: "name", label: "Name" }
55
+ { type: "text", name: "name", label: "Name", required: true },
56
+ { type: "select", name: "status", label: "Status", options: [
57
+ { value: "active", label: "Active" },
58
+ { value: "inactive", label: "Inactive" }
59
+ ]}
26
60
  ]}
27
61
  data={[]}
62
+ onSave={(data) => console.log(data)}
28
63
  />
29
64
  );
30
- }
65
+ }
66
+ ```
67
+
68
+ ### 3. Available Imports
69
+
70
+ The library provides several entry points for importing components:
71
+
72
+ ```typescript
73
+ // Main CRUD component
74
+ import { CrudComponent } from '@kingteza/crud-component';
75
+
76
+ // Common components
77
+ import { Button, Select, DatePicker } from '@kingteza/crud-component/common';
78
+
79
+ // Utility functions
80
+ import { DateUtil } from '@kingteza/crud-component/util';
81
+ ```
82
+
83
+ ## Documentation
84
+
85
+ For detailed documentation of components and their props, please visit our [GitHub repository](https://github.com/kingteza/crud-component).
86
+
87
+ ## License
88
+
89
+ MIT
@@ -1 +1 @@
1
- "use strict";const g=require("react/jsx-runtime"),q=require("antd"),A=require("../../../locale/hooks/translation-constants.cjs"),l=require("react"),f=require("react-i18next");;/* empty css */const d=require("react-router-dom"),x=({className:s,to:n,onClick:t,tooltip:i,ref:y,...e})=>{var o;const{t:a}=f.useTranslation(A.TRANSLATION_NAMESPACE);let r;try{r=(o=d.useNavigate)==null?void 0:o.call(d)}catch(u){console.error(u)}const c=l.useMemo(()=>g.jsx(q.Button,{onClick:t||(n&&r?()=>r(n):void 0),className:s,...e,children:e.children||a(`button.${e.type}`)}),[s,r,t,e,a,n]);return i?g.jsx(q.Tooltip,{title:i,children:c}):c},h=({className:s,to:n,onClick:t,tooltip:i,ref:y,...e})=>{const a=d.useNavigate(),[r,c]=l.useState(!1),o=l.useCallback(async v=>{try{return c(!0),await t(v)}finally{c(!1)}},[t]),u=l.useMemo(()=>g.jsx(q.Button,{loading:r||e.loading,onClick:t?o:n?()=>a(n):void 0,className:s,...e}),[o,s,r,a,t,e,n]);return i?g.jsx(q.Tooltip,{title:i,children:u}):u};x.Async=h;module.exports=x;
1
+ "use strict";const y=require("react/jsx-runtime"),f=require("antd"),g=require("../../../locale/hooks/translation-constants.cjs"),l=require("react"),A=require("react-i18next");;/* empty css */const d=require("react-router-dom"),q=({className:i,to:t,onClick:n,tooltip:o,ref:x,...r})=>{var a;const{t:e}=A.useTranslation(g.TRANSLATION_NAMESPACE);let s;try{s=(a=d.useNavigate)==null?void 0:a.call(d)}catch(u){console.error(u)}const c=l.useMemo(()=>y.jsx(f.Button,{onClick:n||(t&&s?()=>s(t):void 0),className:i,...r,children:r.children||e(`button.${r.type}`)}),[i,s,n,r,e,t]);return o?y.jsx(f.Tooltip,{title:o,children:c}):c},j=({className:i,to:t,onClick:n,tooltip:o,ref:x,...r})=>{let e;try{e=d.useNavigate()}catch(h){console.error(h)}const[s,c]=l.useState(!1),a=l.useCallback(async h=>{try{return c(!0),await n(h)}finally{c(!1)}},[n]),u=l.useMemo(()=>y.jsx(f.Button,{loading:s||r.loading,onClick:n?a:t?()=>{e?e==null||e(t):window.location.href=t}:void 0,className:i,...r}),[a,i,s,e,n,r,t]);return o?y.jsx(f.Tooltip,{title:o,children:u}):u};q.Async=j;module.exports=q;
@@ -1,71 +1,79 @@
1
- import { jsx as m } from "react/jsx-runtime";
2
- import { Button as u, Tooltip as f } from "antd";
3
- import { TRANSLATION_NAMESPACE as h } from "../../../locale/hooks/translation-constants.js";
4
- import { useMemo as d, useState as v, useCallback as b } from "react";
5
- import { useTranslation as T } from "react-i18next";
1
+ import { jsx as f } from "react/jsx-runtime";
2
+ import { Button as u, Tooltip as d } from "antd";
3
+ import { TRANSLATION_NAMESPACE as g } from "../../../locale/hooks/translation-constants.js";
4
+ import { useMemo as y, useState as b, useCallback as T } from "react";
5
+ import { useTranslation as v } from "react-i18next";
6
6
  /* empty css */
7
- import { useNavigate as g } from "react-router-dom";
8
- const S = ({
9
- className: o,
10
- to: e,
11
- onClick: t,
12
- tooltip: i,
13
- ref: y,
7
+ import { useNavigate as h } from "react-router-dom";
8
+ const w = ({
9
+ className: i,
10
+ to: r,
11
+ onClick: e,
12
+ tooltip: a,
13
+ ref: A,
14
14
  ...n
15
15
  }) => {
16
16
  var l;
17
- const { t: a } = T(h);
18
- let r;
17
+ const { t } = v(g);
18
+ let o;
19
19
  try {
20
- r = (l = g) == null ? void 0 : l();
20
+ o = (l = h) == null ? void 0 : l();
21
21
  } catch (s) {
22
22
  console.error(s);
23
23
  }
24
- const c = d(
25
- () => /* @__PURE__ */ m(
24
+ const c = y(
25
+ () => /* @__PURE__ */ f(
26
26
  u,
27
27
  {
28
- onClick: t || (e && r ? () => r(e) : void 0),
29
- className: o,
28
+ onClick: e || (r && o ? () => o(r) : void 0),
29
+ className: i,
30
30
  ...n,
31
- children: n.children || a(`button.${n.type}`)
31
+ children: n.children || t(`button.${n.type}`)
32
32
  }
33
33
  ),
34
- [o, r, t, n, a, e]
34
+ [i, o, e, n, t, r]
35
35
  );
36
- return i ? /* @__PURE__ */ m(f, { title: i, children: c }) : c;
37
- }, x = ({
38
- className: o,
39
- to: e,
40
- onClick: t,
41
- tooltip: i,
42
- ref: y,
36
+ return a ? /* @__PURE__ */ f(d, { title: a, children: c }) : c;
37
+ }, S = ({
38
+ className: i,
39
+ to: r,
40
+ onClick: e,
41
+ tooltip: a,
42
+ ref: A,
43
43
  ...n
44
44
  }) => {
45
- const a = g(), [r, c] = v(!1), l = b(
46
- async (A) => {
45
+ let t;
46
+ try {
47
+ t = h();
48
+ } catch (m) {
49
+ console.error(m);
50
+ }
51
+ const [o, c] = b(!1), l = T(
52
+ async (m) => {
47
53
  try {
48
- return c(!0), await t(A);
54
+ return c(!0), await e(m);
49
55
  } finally {
50
56
  c(!1);
51
57
  }
52
58
  },
53
- [t]
54
- ), s = d(
55
- () => /* @__PURE__ */ m(
59
+ [e]
60
+ ), s = y(
61
+ () => /* @__PURE__ */ f(
56
62
  u,
57
63
  {
58
- loading: r || n.loading,
59
- onClick: t ? l : e ? () => a(e) : void 0,
60
- className: o,
64
+ loading: o || n.loading,
65
+ onClick: e ? l : r ? () => {
66
+ t ? t == null || t(r) : window.location.href = r;
67
+ } : void 0,
68
+ className: i,
61
69
  ...n
62
70
  }
63
71
  ),
64
- [l, o, r, a, t, n, e]
72
+ [l, i, o, t, e, n, r]
65
73
  );
66
- return i ? /* @__PURE__ */ m(f, { title: i, children: s }) : s;
74
+ return a ? /* @__PURE__ */ f(d, { title: a, children: s }) : s;
67
75
  };
68
- S.Async = x;
76
+ w.Async = S;
69
77
  export {
70
- S as default
78
+ w as default
71
79
  };
@@ -1,2 +1,2 @@
1
- "use strict";const r=require("react/jsx-runtime"),T=require("@ant-design/icons"),B=require("papaparse"),d=require("antd"),O=require("file-saver"),a=require("react"),V=require("react-i18next"),R=require("../../../locale/hooks/translation-constants.cjs"),W=require("../view/CrudViewer.cjs"),L=require("../../../util/DateUtil.cjs"),z=require("../../common/button/Button.cjs"),_=require("../../common/button/ImportButton.cjs");function $({onCloseMethod:C,open:h,fields:g,importProps:o}){const[u,v]=a.useState([]),[y,k]=a.useState(!1),[A,N]=a.useState(0);a.useEffect(()=>{h||(v([]),k(!1))},[h]);const x=a.useMemo(()=>new Map(g.filter(e=>{var t;return!e.hidden&&!((t=e.importProps)!=null&&t.hidden)&&!e.readonly}).map(e=>[e.name,e])),[g]),S=a.useMemo(()=>Array.from(x.values()).flatMap(e=>{var t;return[e.name,...((t=e.importProps)==null?void 0:t.extraFields)??[]]}),[x]),E=a.useCallback(async function(){const e=`${S.join(",")}
2
- `,t=new Blob([e],{type:"text/csv;charset=utf-8;"});O.saveAs(t,(o==null?void 0:o.name)+" - "+L.formatDateTimeWithSecond(new Date).replaceAll(":","-")+".csv")},[S,o==null?void 0:o.name]),{t:i}=V.useTranslation(R.TRANSLATION_NAMESPACE),F=a.useCallback(async e=>{const t=new FileReader;t.onerror=console.error,t.onload=async n=>{var s;const c=(s=n==null?void 0:n.target)==null?void 0:s.result,l=B.parse(c,{header:!0});v(l.data)},t.readAsText(e)},[]),j=a.useMemo(()=>{var t,n,c;let e=!1;for(const l of u)for(const[s,f]of x.entries()){const b=l[s],m=b||!isNaN(b);if(f.required&&!m)if((n=(t=f.importProps)==null?void 0:t.extraFields)!=null&&n.length)for(const w of((c=f.importProps)==null?void 0:c.extraFields)??[])if(l[w]||!isNaN(l[w])){e=!1;break}else return!0;else return!0}return e},[u,x]),p=a.useCallback(e=>(t,n)=>{var l,s,f;const c=t||!isNaN(t);if(e.required&&!c){let b=i("err.validation.required");if((s=(l=e.importProps)==null?void 0:l.extraFields)!=null&&s.length){const m=(f=e.importProps)==null?void 0:f.extraFields;(m==null?void 0:m.find(I=>!n[I]))&&(b="Either one of these fields is required: "+[e.name,...m].join(", "))}return r.jsxs(d.Tooltip,{className:"d-flex",title:b,children:[r.jsx(T.WarningTwoTone,{twoToneColor:"#ee9702"}),t]})}return t},[i]),D=a.useCallback(async e=>{N(e)},[]),q=a.useCallback(async()=>{try{k(!0),await o.onClickImport(u,D),C(!1)}finally{k(!1),N(0)}},[u,o,C,D]),M=a.useCallback(async()=>{j?d.Modal.warn({title:i("str.warning"),content:i("qus.importWithIssues"),okText:i("str.import"),onOk:q,okCancel:!0,closable:!0}):q()},[j,q,i]);return r.jsxs(d.Modal,{title:[i("str.import"),o==null?void 0:o.name].filter(Boolean).join(" "),width:"100%",open:h,onOk:M,destroyOnClose:!0,onCancel:()=>C(!1),okText:i("str.import"),confirmLoading:y,okButtonProps:{disabled:!(u!=null&&u.length)},footer:(e,{OkBtn:t,CancelBtn:n})=>r.jsxs(d.Space,{children:[r.jsx(n,{}),r.jsx(t,{}),j&&r.jsx(d.Tooltip,{className:"d-flex",title:"Some fields have issue. Please review before submit.",children:r.jsx(T.WarningTwoTone,{twoToneColor:"#ee9702"})})]}),children:[r.jsxs(d.Space,{children:[r.jsx(z,{onClick:E,icon:r.jsx(T.DownloadOutlined,{}),children:i("str.downloadCsvTemplate")}),r.jsx(_.ImportButton,{disabled:y,type:"default",onClick:F,accept:".csv",children:i("str.importCsvFile")})]}),r.jsx(d.Spin,{spinning:y,indicator:A?r.jsx(d.Progress,{type:"circle",percent:A*100,size:50,format:e=>`${parseInt(e)}%`}):void 0,children:r.jsx(W,{data:u,bordered:!0,size:"small",fields:Array.from(x.values()).flatMap(e=>{var t,n,c,l;return e.type==="text"?[{...e,label:e.name,render:p(e)},...((n=(t=e.importProps)==null?void 0:t.extraFields)==null?void 0:n.map(s=>({...e,name:s,label:s,render:p(e)})))??[]]:e.type==="select"?[{...e,label:e.name,type:"text",render:p(e)},...((l=(c=e.importProps)==null?void 0:c.extraFields)==null?void 0:l.map(s=>({...e,name:s,label:s,type:"text",render:p(e)})))??[]]:[{...e,label:e.name,render:p(e)}]})})})]})}module.exports=$;
1
+ "use strict";const n=require("react/jsx-runtime"),q=require("@ant-design/icons"),O=require("papaparse"),d=require("antd"),V=require("file-saver"),a=require("react"),W=require("react-i18next"),R=require("../../../locale/hooks/translation-constants.cjs"),L=require("../view/CrudViewer.cjs"),z=require("../../../util/DateUtil.cjs"),_=require("../../common/button/Button.cjs"),$=require("../../common/button/ImportButton.cjs");function U({onCloseMethod:C,open:w,fields:T,importProps:o}){const[u,A]=a.useState([]),[y,k]=a.useState(!1),[v,N]=a.useState(0);a.useEffect(()=>{w||(A([]),k(!1))},[w]);const p=a.useMemo(()=>new Map(T.filter(e=>{var t;return!e.hidden&&!((t=e.importProps)!=null&&t.hidden)&&!e.readonly}).map(e=>[e.name,e])),[T]),S=a.useMemo(()=>Array.from(p.values()).flatMap(e=>{var t;return[e.name,...((t=e.importProps)==null?void 0:t.extraFields)??[]]}),[p]),F=a.useCallback(async function(){const e=`${S.join(",")}
2
+ `,t=new Blob([e],{type:"text/csv;charset=utf-8;"});V.saveAs(t,(o==null?void 0:o.name)+" - "+z.formatDateTimeWithSecond(new Date).replaceAll(":","-")+".csv")},[S,o==null?void 0:o.name]),{t:i}=W.useTranslation(R.TRANSLATION_NAMESPACE),B=a.useCallback(async e=>{const t=new FileReader;t.onerror=console.error,t.onload=async r=>{var s;const c=(s=r==null?void 0:r.target)==null?void 0:s.result,l=O.parse(c,{header:!0});A(l.data)},t.readAsText(e)},[]),g=a.useMemo(()=>{var t,r,c;let e=!1;for(const l of u)for(const[s,f]of p.entries()){const h=l[s],m=h||!isNaN(h);if(f.required&&!m)if((r=(t=f.importProps)==null?void 0:t.extraFields)!=null&&r.length)for(const j of((c=f.importProps)==null?void 0:c.extraFields)??[])if(l[j]||!isNaN(l[j])){e=!1;break}else return!0;else return!0}return e},[u,p]),x=a.useCallback(e=>(t,r)=>{var l,s,f;const c=t||!isNaN(t);if(e.required&&!c){let h=i("err.validation.required");if((s=(l=e.importProps)==null?void 0:l.extraFields)!=null&&s.length){const m=(f=e.importProps)==null?void 0:f.extraFields;(m==null?void 0:m.find(E=>!r[E]))&&(h="Either one of these fields is required: "+[e.name,...m].join(", "))}return n.jsxs(d.Tooltip,{className:"d-flex",title:h,children:[n.jsx(q.WarningTwoTone,{twoToneColor:"#ee9702"}),t]})}return t},[i]),I=a.useCallback(async e=>{N(e)},[]),b=a.useCallback(async()=>{try{k(!0),await o.onClickImport(u,I),C(!1)}finally{k(!1),N(0)}},[u,o,C,I]),{modal:D}=d.App.useApp(),M=a.useCallback(async()=>{g?D.warning?D.warning({title:i("str.warning"),content:i("qus.importWithIssues"),okText:i("str.import"),onOk:b,okCancel:!0,closable:!0}):(console.error("You must wrap your react app with App component. https://ant.design/components/app"),window.confirm(i("qus.importWithIssues"))&&b()):b()},[g,b,i]);return n.jsxs(d.Modal,{title:[i("str.import"),o==null?void 0:o.name].filter(Boolean).join(" "),width:"100%",open:w,onOk:M,destroyOnClose:!0,onCancel:()=>C(!1),okText:i("str.import"),confirmLoading:y,okButtonProps:{disabled:!(u!=null&&u.length)},footer:(e,{OkBtn:t,CancelBtn:r})=>n.jsxs(d.Space,{children:[n.jsx(r,{}),n.jsx(t,{}),g&&n.jsx(d.Tooltip,{className:"d-flex",title:"Some fields have issue. Please review before submit.",children:n.jsx(q.WarningTwoTone,{twoToneColor:"#ee9702"})})]}),children:[n.jsxs(d.Space,{children:[n.jsx(_,{onClick:F,icon:n.jsx(q.DownloadOutlined,{}),children:i("str.downloadCsvTemplate")}),n.jsx($.ImportButton,{disabled:y,type:"default",onClick:B,accept:".csv",children:i("str.importCsvFile")})]}),n.jsx(d.Spin,{spinning:y,indicator:v?n.jsx(d.Progress,{type:"circle",percent:v*100,size:50,format:e=>`${parseInt(e)}%`}):void 0,children:n.jsx(L,{data:u,bordered:!0,size:"small",fields:Array.from(p.values()).flatMap(e=>{var t,r,c,l;return e.type==="text"?[{...e,label:e.name,render:x(e)},...((r=(t=e.importProps)==null?void 0:t.extraFields)==null?void 0:r.map(s=>({...e,name:s,label:s,render:x(e)})))??[]]:e.type==="select"?[{...e,label:e.name,type:"text",render:x(e)},...((l=(c=e.importProps)==null?void 0:c.extraFields)==null?void 0:l.map(s=>({...e,name:s,label:s,type:"text",render:x(e)})))??[]]:[{...e,label:e.name,render:x(e)}]})})})]})}module.exports=U;
@@ -1,26 +1,26 @@
1
- import { jsxs as y, jsx as s } from "react/jsx-runtime";
2
- import { WarningTwoTone as q, DownloadOutlined as z } from "@ant-design/icons";
1
+ import { jsxs as w, jsx as i } from "react/jsx-runtime";
2
+ import { WarningTwoTone as B, DownloadOutlined as z } from "@ant-design/icons";
3
3
  import R from "papaparse";
4
- import { Tooltip as B, Modal as O, Space as V, Spin as _, Progress as $ } from "antd";
5
- import { saveAs as U } from "file-saver";
6
- import { useState as v, useEffect as G, useMemo as A, useCallback as m } from "react";
7
- import { useTranslation as H } from "react-i18next";
8
- import { TRANSLATION_NAMESPACE as J } from "../../../locale/hooks/translation-constants.js";
9
- import K from "../view/CrudViewer.js";
10
- import Q from "../../../util/DateUtil.js";
11
- import X from "../../common/button/Button.js";
12
- import { ImportButton as Y } from "../../common/button/ImportButton.js";
13
- function de({
4
+ import { Tooltip as O, App as _, Modal as $, Space as V, Spin as U, Progress as Y } from "antd";
5
+ import { saveAs as G } from "file-saver";
6
+ import { useState as T, useEffect as H, useMemo as v, useCallback as f } from "react";
7
+ import { useTranslation as J } from "react-i18next";
8
+ import { TRANSLATION_NAMESPACE as K } from "../../../locale/hooks/translation-constants.js";
9
+ import Q from "../view/CrudViewer.js";
10
+ import X from "../../../util/DateUtil.js";
11
+ import Z from "../../common/button/Button.js";
12
+ import { ImportButton as P } from "../../common/button/ImportButton.js";
13
+ function fe({
14
14
  onCloseMethod: x,
15
15
  open: b,
16
16
  fields: N,
17
17
  importProps: o
18
18
  }) {
19
- const [c, D] = v([]), [C, w] = v(!1), [E, F] = v(0);
20
- G(() => {
21
- b || (D([]), w(!1));
19
+ const [c, D] = T([]), [C, g] = T(!1), [E, F] = T(0);
20
+ H(() => {
21
+ b || (D([]), g(!1));
22
22
  }, [b]);
23
- const u = A(
23
+ const u = v(
24
24
  () => new Map(
25
25
  N.filter((e) => {
26
26
  var t;
@@ -28,7 +28,7 @@ function de({
28
28
  }).map((e) => [e.name, e])
29
29
  ),
30
30
  [N]
31
- ), I = A(
31
+ ), I = v(
32
32
  () => Array.from(u.values()).flatMap((e) => {
33
33
  var t;
34
34
  return [
@@ -37,128 +37,130 @@ function de({
37
37
  ];
38
38
  }),
39
39
  [u]
40
- ), M = m(
40
+ ), M = f(
41
41
  async function() {
42
42
  const e = `${I.join(",")}
43
43
  `, t = new Blob([e], { type: "text/csv;charset=utf-8;" });
44
- U(
44
+ G(
45
45
  t,
46
- (o == null ? void 0 : o.name) + " - " + Q.formatDateTimeWithSecond(/* @__PURE__ */ new Date()).replaceAll(":", "-") + ".csv"
46
+ (o == null ? void 0 : o.name) + " - " + X.formatDateTimeWithSecond(/* @__PURE__ */ new Date()).replaceAll(":", "-") + ".csv"
47
47
  );
48
48
  },
49
49
  [I, o == null ? void 0 : o.name]
50
- ), { t: l } = H(J), L = m(async (e) => {
50
+ ), { t: s } = J(K), W = f(async (e) => {
51
51
  const t = new FileReader();
52
52
  t.onerror = console.error, t.onload = async (r) => {
53
53
  var n;
54
- const i = (n = r == null ? void 0 : r.target) == null ? void 0 : n.result, a = R.parse(i, { header: !0 });
54
+ const l = (n = r == null ? void 0 : r.target) == null ? void 0 : n.result, a = R.parse(l, { header: !0 });
55
55
  D(a.data);
56
56
  }, t.readAsText(e);
57
- }, []), g = A(() => {
58
- var t, r, i;
57
+ }, []), k = v(() => {
58
+ var t, r, l;
59
59
  let e = !1;
60
60
  for (const a of c)
61
61
  for (const [n, d] of u.entries()) {
62
- const h = a[n], f = h || !isNaN(h);
63
- if (d.required && !f)
62
+ const h = a[n], m = h || !isNaN(h);
63
+ if (d.required && !m)
64
64
  if ((r = (t = d.importProps) == null ? void 0 : t.extraFields) != null && r.length)
65
- for (const T of ((i = d.importProps) == null ? void 0 : i.extraFields) ?? [])
66
- if (a[T] || !isNaN(a[T])) {
65
+ for (const A of ((l = d.importProps) == null ? void 0 : l.extraFields) ?? [])
66
+ if (a[A] || !isNaN(a[A])) {
67
67
  e = !1;
68
68
  break;
69
69
  } else return !0;
70
70
  else return !0;
71
71
  }
72
72
  return e;
73
- }, [c, u]), p = m(
73
+ }, [c, u]), p = f(
74
74
  (e) => (t, r) => {
75
75
  var a, n, d;
76
- const i = t || !isNaN(t);
77
- if (e.required && !i) {
78
- let h = l("err.validation.required");
76
+ const l = t || !isNaN(t);
77
+ if (e.required && !l) {
78
+ let h = s("err.validation.required");
79
79
  if ((n = (a = e.importProps) == null ? void 0 : a.extraFields) != null && n.length) {
80
- const f = (d = e.importProps) == null ? void 0 : d.extraFields;
81
- (f == null ? void 0 : f.find((j) => !r[j])) && (h = "Either one of these fields is required: " + [e.name, ...f].join(", "));
80
+ const m = (d = e.importProps) == null ? void 0 : d.extraFields;
81
+ (m == null ? void 0 : m.find((j) => !r[j])) && (h = "Either one of these fields is required: " + [e.name, ...m].join(", "));
82
82
  }
83
- return /* @__PURE__ */ y(B, { className: "d-flex", title: h, children: [
84
- /* @__PURE__ */ s(q, { twoToneColor: "#ee9702" }),
83
+ return /* @__PURE__ */ w(O, { className: "d-flex", title: h, children: [
84
+ /* @__PURE__ */ i(B, { twoToneColor: "#ee9702" }),
85
85
  t
86
86
  ] });
87
87
  }
88
88
  return t;
89
89
  },
90
- [l]
91
- ), S = m(async (e) => {
90
+ [s]
91
+ ), S = f(async (e) => {
92
92
  F(e);
93
- }, []), k = m(async () => {
93
+ }, []), y = f(async () => {
94
94
  try {
95
- w(!0), await o.onClickImport(c, S), x(!1);
95
+ g(!0), await o.onClickImport(c, S), x(!1);
96
96
  } finally {
97
- w(!1), F(0);
97
+ g(!1), F(0);
98
98
  }
99
- }, [c, o, x, S]), W = m(async () => {
100
- g ? O.warn({
101
- title: l("str.warning"),
102
- content: l("qus.importWithIssues"),
103
- okText: l("str.import"),
104
- onOk: k,
99
+ }, [c, o, x, S]), { modal: q } = _.useApp(), L = f(async () => {
100
+ k ? q.warning ? q.warning({
101
+ title: s("str.warning"),
102
+ content: s("qus.importWithIssues"),
103
+ okText: s("str.import"),
104
+ onOk: y,
105
105
  okCancel: !0,
106
106
  closable: !0
107
- }) : k();
108
- }, [g, k, l]);
109
- return /* @__PURE__ */ y(
110
- O,
107
+ }) : (console.error(
108
+ "You must wrap your react app with App component. https://ant.design/components/app"
109
+ ), window.confirm(s("qus.importWithIssues")) && y()) : y();
110
+ }, [k, y, s]);
111
+ return /* @__PURE__ */ w(
112
+ $,
111
113
  {
112
- title: [l("str.import"), o == null ? void 0 : o.name].filter(Boolean).join(" "),
114
+ title: [s("str.import"), o == null ? void 0 : o.name].filter(Boolean).join(" "),
113
115
  width: "100%",
114
116
  open: b,
115
- onOk: W,
117
+ onOk: L,
116
118
  destroyOnClose: !0,
117
119
  onCancel: () => x(!1),
118
- okText: l("str.import"),
120
+ okText: s("str.import"),
119
121
  confirmLoading: C,
120
122
  okButtonProps: {
121
123
  disabled: !(c != null && c.length)
122
124
  },
123
- footer: (e, { OkBtn: t, CancelBtn: r }) => /* @__PURE__ */ y(V, { children: [
124
- /* @__PURE__ */ s(r, {}),
125
- /* @__PURE__ */ s(t, {}),
126
- g && /* @__PURE__ */ s(
127
- B,
125
+ footer: (e, { OkBtn: t, CancelBtn: r }) => /* @__PURE__ */ w(V, { children: [
126
+ /* @__PURE__ */ i(r, {}),
127
+ /* @__PURE__ */ i(t, {}),
128
+ k && /* @__PURE__ */ i(
129
+ O,
128
130
  {
129
131
  className: "d-flex",
130
132
  title: "Some fields have issue. Please review before submit.",
131
- children: /* @__PURE__ */ s(q, { twoToneColor: "#ee9702" })
133
+ children: /* @__PURE__ */ i(B, { twoToneColor: "#ee9702" })
132
134
  }
133
135
  )
134
136
  ] }),
135
137
  children: [
136
- /* @__PURE__ */ y(V, { children: [
137
- /* @__PURE__ */ s(
138
- X,
138
+ /* @__PURE__ */ w(V, { children: [
139
+ /* @__PURE__ */ i(
140
+ Z,
139
141
  {
140
142
  onClick: M,
141
- icon: /* @__PURE__ */ s(z, {}),
142
- children: l("str.downloadCsvTemplate")
143
+ icon: /* @__PURE__ */ i(z, {}),
144
+ children: s("str.downloadCsvTemplate")
143
145
  }
144
146
  ),
145
- /* @__PURE__ */ s(
146
- Y,
147
+ /* @__PURE__ */ i(
148
+ P,
147
149
  {
148
150
  disabled: C,
149
151
  type: "default",
150
- onClick: L,
152
+ onClick: W,
151
153
  accept: ".csv",
152
- children: l("str.importCsvFile")
154
+ children: s("str.importCsvFile")
153
155
  }
154
156
  )
155
157
  ] }),
156
- /* @__PURE__ */ s(
157
- _,
158
+ /* @__PURE__ */ i(
159
+ U,
158
160
  {
159
161
  spinning: C,
160
- indicator: E ? /* @__PURE__ */ s(
161
- $,
162
+ indicator: E ? /* @__PURE__ */ i(
163
+ Y,
162
164
  {
163
165
  type: "circle",
164
166
  percent: E * 100,
@@ -166,14 +168,14 @@ function de({
166
168
  format: (e) => `${parseInt(e)}%`
167
169
  }
168
170
  ) : void 0,
169
- children: /* @__PURE__ */ s(
170
- K,
171
+ children: /* @__PURE__ */ i(
172
+ Q,
171
173
  {
172
174
  data: c,
173
175
  bordered: !0,
174
176
  size: "small",
175
177
  fields: Array.from(u.values()).flatMap((e) => {
176
- var t, r, i, a;
178
+ var t, r, l, a;
177
179
  return e.type === "text" ? [
178
180
  {
179
181
  ...e,
@@ -193,7 +195,7 @@ function de({
193
195
  type: "text",
194
196
  render: p(e)
195
197
  },
196
- ...((a = (i = e.importProps) == null ? void 0 : i.extraFields) == null ? void 0 : a.map((n) => ({
198
+ ...((a = (l = e.importProps) == null ? void 0 : l.extraFields) == null ? void 0 : a.map((n) => ({
197
199
  ...e,
198
200
  name: n,
199
201
  label: n,
@@ -217,5 +219,5 @@ function de({
217
219
  );
218
220
  }
219
221
  export {
220
- de as default
222
+ fe as default
221
223
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),m=require("@ant-design/icons"),s=require("antd"),y=require("../../common/show-more/index.cjs"),C=require("../FileCrudField.cjs"),g=require("../ImageCrudField.cjs"),x=require("../../../locale/hooks/translation-constants.cjs"),d=require("i18next"),r=require("../../../util/DateUtil.cjs"),v=require("../../../util/NumberUtil.cjs");function j({type:a,render:i,...n}){return a==="object"?(t,u,o)=>typeof i=="function"?i(t,u,o):"":a==="select"?(t,u,o)=>{const e=n;let c=e.multiple?Array.isArray(t)?t.map(f=>f==null?void 0:f[e.innerFieldLabel??"name"]):void 0:t==null?void 0:t[e.innerFieldLabel??"name"];return(!c&&typeof t=="string"||typeof t=="number")&&(c=t),typeof i=="function"?i(c,u,o):Array.isArray(c)?c.join(", "):c}:a==="number"?(t,u,o)=>typeof i=="function"?i(t,u,o):n!=null&&n.int?v.default.toInt(t,n.formatted):v.default.toMoney(t):a==="enum"?(t,u,o)=>{var c;const e=d.t(((c=n==null?void 0:n.translation)==null?void 0:c[t??""])??t,{ns:x.TRANSLATION_NAMESPACE});return typeof i=="function"?i(t,u,o):e}:a==="date"?(t,u,o)=>{if(!t)return"-";const e=n!=null&&n.formatTime?r.formatDateTime(t):r.formatDate(t);return typeof i=="function"?i(t,u,o):e}:a==="checkbox"?(t,u,o)=>typeof i=="function"?i(t,u,o):t?l.jsx(m.CheckOutlined,{}):l.jsx(m.CloseOutlined,{}):a==="image"?(t,u,o)=>typeof i=="function"?i(t,u,o):l.jsx(g.ImageCrudCellValue,{value:t,provider:n.provider}):a==="file"?(t,u,o)=>typeof i=="function"?i(t,u,o):l.jsx(C.FileCrudCellValue,{value:t,provider:n.provider}):a==="time"?(t,u,o)=>{if(!t)return"-";const e=n==null?void 0:n.format,c=n==null?void 0:n.use12Hours,f=r.formatTime(t,e||(c?"hh:mm:ss A":void 0));return typeof i=="function"?i(t,u,o):f}:a==="color"?(t,u,o)=>typeof i=="function"?i(t,u,o):typeof t=="string"&&t.startsWith("#")?l.jsx(s.Tooltip,{title:t,children:l.jsx(s.Avatar,{style:{backgroundColor:t}})}):String(t):a==="textarea"?(t,u,o)=>{const e=(n==null?void 0:n.truncated)??1;return typeof i=="function"?i(t,u,o):e?l.jsx(y.ShowMore,{lines:e===!0?1:e,children:t}):t}:typeof i=="function"?i:t=>t}exports.getRendererValueCrudViewer=j;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),m=require("@ant-design/icons"),s=require("antd"),y=require("../../common/show-more/index.cjs"),C=require("../FileCrudField.cjs"),g=require("../ImageCrudField.cjs"),d=require("../../../locale/hooks/translation-constants.cjs"),j=require("i18next"),r=require("../../../util/DateUtil.cjs"),v=require("../../../util/NumberUtil.cjs");function x({type:a,render:i,...n}){return a==="object"?(t,u,o)=>typeof i=="function"?i(t,u,o):"":a==="select"?(t,u,o)=>{const e=n;let c=e.multiple?Array.isArray(t)?t.map(f=>f==null?void 0:f[e.innerFieldLabel??"name"]):void 0:t==null?void 0:t[e.innerFieldLabel??"name"];return(!c&&typeof t=="string"||typeof t=="number")&&(c=t),typeof i=="function"?i(c,u,o):Array.isArray(c)?c.join(", "):c}:a==="number"?(t,u,o)=>typeof i=="function"?i(t,u,o):n!=null&&n.int?v.default.toInt(t,n.formatted):v.default.toMoney(t):a==="enum"?(t,u,o)=>{var c;const e=j.t(((c=n==null?void 0:n.translation)==null?void 0:c[t??""])??t,{ns:d.TRANSLATION_NAMESPACE});return typeof i=="function"?i(t,u,o):e}:a==="date"?(t,u,o)=>{if(!t)return"-";const e=n!=null&&n.formatTime?r.formatDateTime(t):r.formatDate(t);return typeof i=="function"?i(t,u,o):e}:a==="checkbox"?(t,u,o)=>typeof i=="function"?i(t,u,o):t?l.jsx(m.CheckOutlined,{}):l.jsx(m.CloseOutlined,{}):a==="image"?(t,u,o)=>typeof i=="function"?i(t,u,o):l.jsx(g.ImageCrudCellValue,{value:t,provider:n.provider}):a==="file"?(t,u,o)=>typeof i=="function"?i(t,u,o):l.jsx(C.FileCrudCellValue,{value:t,provider:n.provider}):a==="time"?(t,u,o)=>{if(!t)return"-";const e=n==null?void 0:n.format,c=n==null?void 0:n.use12Hours,f=r.formatTime(t,e||(c?"hh:mm:ss A":void 0));return typeof i=="function"?i(t,u,o):f}:a==="color"?(t,u,o)=>typeof i=="function"?i(t,u,o):typeof t=="string"&&t.startsWith("#")?l.jsx(s.Tooltip,{title:t,children:l.jsx(s.Avatar,{style:{backgroundColor:t}})}):String(t):a==="textarea"?(t,u,o)=>{const e=(n==null?void 0:n.truncated)??1;return typeof i=="function"?i(t,u,o):e?l.jsx(y.ShowMore,{lines:e===!0?1:e,children:t}):t}:typeof i=="function"?i:t=>t}exports.getRendererValueCrudViewer=x;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./hooks/translation-constants.cjs"),o=require("./translations/en.cjs"),t=require("i18next"),u=require("react-i18next"),a={en:{[s.TRANSLATION_NAMESPACE]:o}},i=(e={})=>{const{translations:n=a,language:r="en"}=e;return t.use(u.initReactI18next).init({resources:n,lng:r,fallbackLng:"en",ns:s.TRANSLATION_NAMESPACE,interpolation:{escapeValue:!1}}),t},l=(e,n)=>{t.addResourceBundle(e,s.TRANSLATION_NAMESPACE,n,!0,!0)};exports.defaultTranslations=a;exports.setupI18n=i;exports.updateTranslations=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./hooks/translation-constants.cjs"),d=require("./translations/en.cjs"),n=require("i18next"),A=require("react-i18next"),o={en:{[a.TRANSLATION_NAMESPACE]:d}},I=(t={})=>{const{translations:e=o,language:s="en",i18nInstance:r}=t,i=r||n;return i.isInitialized?Object.entries(e).forEach(([u,c])=>{Object.entries(c).forEach(([l,T])=>{n.addResourceBundle(u,l,T,!0,!0)})}):i.use(A.initReactI18next).init({resources:e,lng:s,fallbackLng:"en",ns:a.TRANSLATION_NAMESPACE,interpolation:{escapeValue:!1}}),n},N=(t,e,s)=>{(s||n).addResourceBundle(t,a.TRANSLATION_NAMESPACE,e,!0,!0)};exports.defaultTranslations=o;exports.setupI18n=I;exports.updateTranslations=N;
@@ -1,4 +1,6 @@
1
+ import { TRANSLATION_NAMESPACE } from 'locale/hooks/translation-constants';
1
2
  import { default as en } from './translations/en';
3
+ import { default as i18n } from 'i18next';
2
4
  export declare const defaultTranslations: {
3
5
  en: {
4
6
  "crud-component": {
@@ -62,8 +64,11 @@ export declare const defaultTranslations: {
62
64
  };
63
65
  export type LibTranslations = typeof en;
64
66
  export interface SetupI18nOptions {
65
- translations?: typeof defaultTranslations;
67
+ translations?: Record<string, {
68
+ [TRANSLATION_NAMESPACE]: LibTranslations;
69
+ }>;
66
70
  language?: string;
71
+ i18nInstance?: typeof i18n;
67
72
  }
68
73
  export declare const setupI18n: (options?: SetupI18nOptions) => import('i18next').i18n;
69
- export declare const updateTranslations: (language: string, translations: Record<string, any>) => void;
74
+ export declare const updateTranslations: (language: string, translations: Record<string, any>, i18nInstance?: typeof i18n) => void;
@@ -1,25 +1,29 @@
1
1
  import { TRANSLATION_NAMESPACE as o } from "./hooks/translation-constants.js";
2
- import a from "./translations/en.js";
3
- import t from "i18next";
4
- import { initReactI18next as s } from "react-i18next";
5
- const i = {
2
+ import f from "./translations/en.js";
3
+ import n from "i18next";
4
+ import { initReactI18next as d } from "react-i18next";
5
+ const p = {
6
6
  en: {
7
- [o]: a
7
+ [o]: f
8
8
  }
9
- }, m = (n = {}) => {
10
- const { translations: e = i, language: r = "en" } = n;
11
- return t.use(s).init({
9
+ }, A = (t = {}) => {
10
+ const { translations: e = p, language: s = "en", i18nInstance: r } = t, i = r || n;
11
+ return i.isInitialized ? Object.entries(e).forEach(([a, c]) => {
12
+ Object.entries(c).forEach(([u, l]) => {
13
+ n.addResourceBundle(a, u, l, !0, !0);
14
+ });
15
+ }) : i.use(d).init({
12
16
  resources: e,
13
- lng: r,
17
+ lng: s,
14
18
  fallbackLng: "en",
15
19
  ns: o,
16
20
  interpolation: {
17
21
  escapeValue: !1
18
22
  }
19
- }), t;
20
- }, f = (n, e) => {
21
- t.addResourceBundle(
22
- n,
23
+ }), n;
24
+ }, E = (t, e, s) => {
25
+ (s || n).addResourceBundle(
26
+ t,
23
27
  o,
24
28
  e,
25
29
  !0,
@@ -27,7 +31,7 @@ const i = {
27
31
  );
28
32
  };
29
33
  export {
30
- i as defaultTranslations,
31
- m as setupI18n,
32
- f as updateTranslations
34
+ p as defaultTranslations,
35
+ A as setupI18n,
36
+ E as updateTranslations
33
37
  };
@@ -1,6 +1,6 @@
1
- import a from "dayjs";
2
- import e from "i18next";
3
- const m = (t) => a(t).locale(e.language).format("YYYY-MM-DD HH:mm"), r = (t) => a(t).locale(e.language).format("YYYY-MM-DD HH:mm:ss"), n = (t) => a(t).locale(e.language).format("YYYY-MM-DD"), l = (t, o = "HH:mm:ss") => a(t).locale(e.language).format(o), s = { formatDateTime: m, formatDate: n, formatDateTimeWithSecond: r, formatTime: l };
1
+ import t from "dayjs";
2
+ import o from "i18next";
3
+ const m = (a) => t(a).locale(o.language).format("YYYY-MM-DD HH:mm"), r = (a) => t(a).locale(o.language).format("YYYY-MM-DD HH:mm:ss"), n = (a) => t(a).locale(o.language).format("YYYY-MM-DD"), l = (a, e = "HH:mm:ss") => t(a).locale(o.language).format(e), s = { formatDateTime: m, formatDate: n, formatDateTimeWithSecond: r, formatTime: l };
4
4
  export {
5
5
  s as default
6
6
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kingteza/crud-component",
3
3
  "private": false,
4
- "version": "1.0.21",
4
+ "version": "1.0.23",
5
5
  "description": "React CRUD component library with Ant Design",
6
6
  "keywords": [
7
7
  "react",