@kingteza/crud-component 1.40.0 → 1.41.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";const e=require("react/jsx-runtime"),o=require("react"),p=require("@ant-design/icons"),l=require("antd"),N=require("./CrudField.cjs.js"),w=require("../util/CrudUtil.cjs.js"),C=require("../context/CrudSearchContext.cjs.js"),M=require("../common/button/Button.cjs.js");function R({searchFields:t=[],fields:g,searchOnChange:a,onSearch:m,searchDefaultValues:b,searchFieldsCustomColumnProps:d}){const y=o.useMemo(()=>t.map(n=>typeof n=="string"?{...g.find(x=>n===x.name),required:!1}:{...g.find(r=>(n==null?void 0:n.name)===r.name),...n}).filter(n=>n&&!(n!=null&&n.hidden)),[t,g]),c=o.useMemo(()=>t.length===1?{field:22,button:2}:t.length===2?{field:11,button:2}:t.length===3?{field:6,button:6}:t.length===4?{field:5,button:4}:t.length===5?{field:4,button:4}:{field:4,button:4},[t.length]),j=o.useMemo(()=>t.length===1?{field:22,button:2}:t.length===2?{field:11,button:2}:t.length===3?{field:6,button:6}:t.length===4?{field:5,button:4}:t.length===5?{field:4,button:4}:{field:4,button:4},[t.length]),q=o.useMemo(()=>t.length===1?{field:21,button:3}:t.length===2?{field:11,button:2}:t.length===3?{field:24,button:24}:t.length===4?{field:5,button:4}:t.length===5?{field:4,button:4}:{field:4,button:4},[t.length]),[u]=l.Form.useForm(),f=o.useCallback(async n=>{if((n||a)&&m){const i=await u.validateFields();m(i)}},[u,m,a]);return o.useEffect(()=>{b&&(u.setFieldsValue(b),f(!0))},[u,b]),t!=null&&t.length?e.jsx(l.Form,{form:u,onFinish:()=>f(!0),layout:"vertical",className:"mb-2",onChange:()=>f(!1),children:e.jsx(C.CrudSearchContextProvider,{search:()=>f(!1),children:e.jsxs(l.Row,{gutter:[4,8],className:"w-100",children:[y.map((n,i)=>{const r=(d==null?void 0:d[i])??{md:c.field,sm:j.field,xs:q.field},x=w.getRealName(n.name);return o.createElement(l.Col,{...r,key:`search_field_${String(x)}`,className:"align-self-end"},e.jsx(N.default,{...n,readonly:!1,fieldClassName:"mb-0"}))}),e.jsx(l.Col,{md:c.button,sm:j.button,xs:q.button,style:{alignSelf:"end"},children:e.jsx(M,{type:"primary",htmlType:"submit",block:!0,icon:e.jsx(p.SearchOutlined,{})})})]})})}):e.jsx(e.Fragment,{})}module.exports=R;
1
+ "use strict";const o=require("react/jsx-runtime"),e=require("react"),p=require("@ant-design/icons"),i=require("antd"),N=require("./CrudField.cjs.js"),E=require("../util/CrudUtil.cjs.js"),C=require("../context/CrudSearchContext.cjs.js"),_=require("../common/button/Button.cjs.js");function k({searchFields:t=[],fields:g,searchOnChange:c,onSearch:b,searchDefaultValues:a,searchFieldsCustomColumnProps:d}){const j=e.useMemo(()=>t.map(n=>{if(e.isValidElement(n))return n;if(typeof n=="string"){const l=g.find(m=>n===m.name);return l?{...l,required:!1}:null}const u=g.find(l=>(n==null?void 0:n.name)===l.name);return u?{...u,...n}:null}).filter(n=>e.isValidElement(n)||n&&!(n!=null&&n.hidden)),[t,g]),x=e.useMemo(()=>t.length===1?{field:22,button:2}:t.length===2?{field:11,button:2}:t.length===3?{field:6,button:6}:t.length===4?{field:5,button:4}:t.length===5?{field:4,button:4}:{field:4,button:4},[t.length]),s=e.useMemo(()=>t.length===1?{field:22,button:2}:t.length===2?{field:11,button:2}:t.length===3?{field:6,button:6}:t.length===4?{field:5,button:4}:t.length===5?{field:4,button:4}:{field:4,button:4},[t.length]),y=e.useMemo(()=>t.length===1?{field:21,button:3}:t.length===2?{field:11,button:2}:t.length===3?{field:24,button:24}:t.length===4?{field:5,button:4}:t.length===5?{field:4,button:4}:{field:4,button:4},[t.length]),[r]=i.Form.useForm(),f=e.useCallback(async n=>{if((n||c)&&b){const u=await r.validateFields();b(u)}},[r,b,c]);return e.useEffect(()=>{a&&(r.setFieldsValue(a),f(!0))},[r,a]),t!=null&&t.length?o.jsx(i.Form,{form:r,onFinish:()=>f(!0),layout:"vertical",className:"mb-2",onChange:()=>f(!1),children:o.jsx(C.CrudSearchContextProvider,{search:()=>f(!1),children:o.jsxs(i.Row,{gutter:[4,8],className:"w-100",children:[j.map((n,u)=>{const l=(d==null?void 0:d[u])??{md:x.field,sm:s.field,xs:y.field};if(e.isValidElement(n))return e.createElement(i.Col,{...l,key:`search_field_element_${u}`,className:"align-self-end"},n);const m=n,q=E.getRealName(m.name);return e.createElement(i.Col,{...l,key:`search_field_${String(q)}`,className:"align-self-end"},o.jsx(N.default,{...m,readonly:!1,fieldClassName:"mb-0"}))}),o.jsx(i.Col,{md:x.button,sm:s.button,xs:y.button,style:{alignSelf:"end"},children:o.jsx(_,{type:"primary",htmlType:"submit",block:!0,icon:o.jsx(p.SearchOutlined,{})})})]})})}):o.jsx(o.Fragment,{})}module.exports=k;
@@ -1,4 +1,5 @@
1
1
  import { ColProps } from 'antd/lib';
2
+ import { ReactElement } from 'react';
2
3
  import { ReadonlyCrudFields } from './CrudComponent';
3
4
  export type CrudSearchOption<T> = {
4
5
  required?: boolean;
@@ -28,7 +29,7 @@ export type CrudSearchOption<T> = {
28
29
  disableToday?: boolean;
29
30
  });
30
31
  export interface CrudSearchComponentProps<T, FormType> {
31
- searchFields?: Array<keyof T | CrudSearchOption<T>>;
32
+ searchFields?: Array<keyof T | CrudSearchOption<T> | ReactElement>;
32
33
  fields: ReadonlyCrudFields<T>;
33
34
  searchOnChange?: boolean;
34
35
  searchDefaultValues?: FormType;
@@ -1,97 +1,124 @@
1
- import { jsx as o, Fragment as v, jsxs as S } from "react/jsx-runtime";
2
- import { useMemo as u, useCallback as j, useEffect as C, createElement as E } from "react";
1
+ import { jsx as f, Fragment as S, jsxs as c } from "react/jsx-runtime";
2
+ import { useMemo as r, isValidElement as d, useCallback as j, useEffect as C, createElement as k } from "react";
3
3
  import { SearchOutlined as R } from "@ant-design/icons";
4
- import { Form as N, Row as _, Col as w } from "antd";
5
- import q from "./CrudField.es.js";
6
- import B from "../util/CrudUtil.es.js";
7
- import { CrudSearchContextProvider as M } from "../context/CrudSearchContext.es.js";
8
- import T from "../common/button/Button.es.js";
9
- function J({
4
+ import { Form as w, Row as $, Col as a } from "antd";
5
+ import h from "./CrudField.es.js";
6
+ import q from "../util/CrudUtil.es.js";
7
+ import { CrudSearchContextProvider as B } from "../context/CrudSearchContext.es.js";
8
+ import M from "../common/button/Button.es.js";
9
+ function K({
10
10
  searchFields: t = [],
11
11
  fields: i,
12
- searchOnChange: p,
12
+ searchOnChange: y,
13
13
  onSearch: g,
14
14
  searchDefaultValues: b,
15
- searchFieldsCustomColumnProps: r
15
+ searchFieldsCustomColumnProps: p
16
16
  }) {
17
- const k = u(
18
- () => t.map((n) => typeof n == "string" ? {
19
- ...i.find((d) => n === d.name),
20
- required: !1
21
- } : {
22
- ...i.find(
23
- (l) => (n == null ? void 0 : n.name) === l.name
24
- ),
25
- ...n
26
- }).filter((n) => n && !(n != null && n.hidden)),
17
+ const v = r(
18
+ () => t.map((n) => {
19
+ if (d(n))
20
+ return n;
21
+ if (typeof n == "string") {
22
+ const e = i.find((u) => n === u.name);
23
+ return e ? {
24
+ ...e,
25
+ required: !1
26
+ } : null;
27
+ }
28
+ const o = i.find(
29
+ (e) => (n == null ? void 0 : n.name) === e.name
30
+ );
31
+ return o ? {
32
+ ...o,
33
+ ...n
34
+ } : null;
35
+ }).filter((n) => d(n) || n && !(n != null && n.hidden)),
27
36
  [t, i]
28
- ), a = u(
37
+ ), x = r(
29
38
  () => t.length === 1 ? { field: 22, button: 2 } : t.length === 2 ? { field: 11, button: 2 } : t.length === 3 ? { field: 6, button: 6 } : t.length === 4 ? { field: 5, button: 4 } : t.length === 5 ? { field: 4, button: 4 } : { field: 4, button: 4 },
30
39
  [t.length]
31
- ), y = u(
40
+ ), N = r(
32
41
  () => t.length === 1 ? { field: 22, button: 2 } : t.length === 2 ? { field: 11, button: 2 } : t.length === 3 ? { field: 6, button: 6 } : t.length === 4 ? { field: 5, button: 4 } : t.length === 5 ? { field: 4, button: 4 } : { field: 4, button: 4 },
33
42
  [t.length]
34
- ), x = u(
43
+ ), _ = r(
35
44
  () => t.length === 1 ? { field: 21, button: 3 } : t.length === 2 ? { field: 11, button: 2 } : t.length === 3 ? { field: 24, button: 24 } : t.length === 4 ? { field: 5, button: 4 } : t.length === 5 ? { field: 4, button: 4 } : { field: 4, button: 4 },
36
45
  [t.length]
37
- ), [f] = N.useForm(), e = j(
46
+ ), [l] = w.useForm(), m = j(
38
47
  async (n) => {
39
- if ((n || p) && g) {
40
- const m = await f.validateFields();
41
- g(m);
48
+ if ((n || y) && g) {
49
+ const o = await l.validateFields();
50
+ g(o);
42
51
  }
43
52
  },
44
- [f, g, p]
53
+ [l, g, y]
45
54
  );
46
55
  return C(() => {
47
- b && (f.setFieldsValue(b), e(!0));
48
- }, [f, b]), t != null && t.length ? /* @__PURE__ */ o(
49
- N,
56
+ b && (l.setFieldsValue(b), m(!0));
57
+ }, [l, b]), t != null && t.length ? /* @__PURE__ */ f(
58
+ w,
50
59
  {
51
- form: f,
52
- onFinish: () => e(!0),
60
+ form: l,
61
+ onFinish: () => m(!0),
53
62
  layout: "vertical",
54
63
  className: "mb-2",
55
- onChange: () => e(!1),
56
- children: /* @__PURE__ */ o(M, { search: () => e(!1), children: /* @__PURE__ */ S(_, { gutter: [4, 8], className: "w-100", children: [
57
- k.map((n, m) => {
58
- const l = (r == null ? void 0 : r[m]) ?? {
59
- md: a.field,
60
- sm: y.field,
61
- xs: x.field
62
- }, d = B.getRealName(n.name);
63
- return /* @__PURE__ */ E(
64
- w,
64
+ onChange: () => m(!1),
65
+ children: /* @__PURE__ */ f(B, { search: () => m(!1), children: /* @__PURE__ */ c($, { gutter: [4, 8], className: "w-100", children: [
66
+ v.map((n, o) => {
67
+ const e = (p == null ? void 0 : p[o]) ?? {
68
+ md: x.field,
69
+ sm: N.field,
70
+ xs: _.field
71
+ };
72
+ if (d(n))
73
+ return /* @__PURE__ */ k(
74
+ a,
75
+ {
76
+ ...e,
77
+ key: `search_field_element_${o}`,
78
+ className: "align-self-end"
79
+ },
80
+ n
81
+ );
82
+ const u = n, E = q.getRealName(u.name);
83
+ return /* @__PURE__ */ k(
84
+ a,
65
85
  {
66
- ...l,
67
- key: `search_field_${String(d)}`,
86
+ ...e,
87
+ key: `search_field_${String(E)}`,
68
88
  className: "align-self-end"
69
89
  },
70
- /* @__PURE__ */ o(q, { ...n, readonly: !1, fieldClassName: "mb-0" })
90
+ /* @__PURE__ */ f(
91
+ h,
92
+ {
93
+ ...u,
94
+ readonly: !1,
95
+ fieldClassName: "mb-0"
96
+ }
97
+ )
71
98
  );
72
99
  }),
73
- /* @__PURE__ */ o(
74
- w,
100
+ /* @__PURE__ */ f(
101
+ a,
75
102
  {
76
- md: a.button,
77
- sm: y.button,
78
- xs: x.button,
103
+ md: x.button,
104
+ sm: N.button,
105
+ xs: _.button,
79
106
  style: { alignSelf: "end" },
80
- children: /* @__PURE__ */ o(
81
- T,
107
+ children: /* @__PURE__ */ f(
108
+ M,
82
109
  {
83
110
  type: "primary",
84
111
  htmlType: "submit",
85
112
  block: !0,
86
- icon: /* @__PURE__ */ o(R, {})
113
+ icon: /* @__PURE__ */ f(R, {})
87
114
  }
88
115
  )
89
116
  }
90
117
  )
91
118
  ] }) })
92
119
  }
93
- ) : /* @__PURE__ */ o(v, {});
120
+ ) : /* @__PURE__ */ f(S, {});
94
121
  }
95
122
  export {
96
- J as default
123
+ K as default
97
124
  };
@@ -1 +1 @@
1
- "use strict";const e={str:{delete:"Delete",clone:"Clone",update:"Update",new:"New",back:"Back",next:"Next",save:"Save",import:"Import",cancel:"Cancel",print:"Print",hide:"Hide",no:"No",action:"Action",remove:"Remove",view:"View",ok:"Ok",yes:"Yes",warning:"Warning",success:"Success",error:"Error",retry:"Retry",previous:"Previous",unhide:"Unhide",downloadCsvTemplate:"Download CSV Template",importCsvFile:"Import CSV File",export:"Export",goBack:"Go Back",refresh:"Refresh",fileUploadMessage1:"Drag file here or ",fileUploadMessage2:"Click to Upload",rotateLeft:"Rotate Left",rotateRight:"Rotate Right",flipHorizontal:"Flip Horizontal",flipVertical:"Flip Vertical",skipCrop:"Skip Crop",showFields:"Show Fields"},err:{save:"An error occurred while saving",validation:{required:"is required",minLength8:"must be at least 8 characters",percentage:"must be a percentage",maximumValueExceeded:"must be less than %maxValue%",invalidNic:"must be a valid NIC",invalid:"must be a valid",integer:"must be an integer"},notFound:"Not Found"},message:{loading:{saving:"Saving"},uploadButtonText:"Click to Upload"},qus:{importWithIssues:"Some fields have issues. Do you want to proceed with the import?",doYouWantToDelete:"Do you want to delete?",doYouWantToHide:"Do you want to hide?",doYouWantToUnhide:"Do you want to unhide?"}};module.exports=e;
1
+ "use strict";const e={str:{delete:"Delete",clone:"Clone",update:"Update",new:"New",back:"Back",next:"Next",save:"Save",import:"Import",cancel:"Cancel",print:"Print",hide:"Hide",no:"No",action:"Action",remove:"Remove",view:"View",ok:"Ok",yes:"Yes",warning:"Warning",success:"Success",error:"Error",retry:"Retry",previous:"Previous",unhide:"Unhide",downloadCsvTemplate:"Download CSV Template",importCsvFile:"Import CSV File",export:"Export",goBack:"Go Back",refresh:"Refresh",fileUploadMessage1:"Drag file here or ",fileUploadMessage2:"Click to Upload",rotateLeft:"Rotate Left",rotateRight:"Rotate Right",flipHorizontal:"Flip Horizontal",flipVertical:"Flip Vertical",skipCrop:"Skip Crop",showFields:"Show Fields"},err:{save:"An error occurred while saving",validation:{required:"is required",minLength8:"must be at least 8 characters",percentage:"must be a percentage",maximumValueExceeded:"must be less than %maxValue%",invalidNic:"must be a valid NIC",invalid:"must be a valid",invalidEmail:"Invalid email address",integer:"must be an integer"},notFound:"Not Found"},message:{loading:{saving:"Saving"},uploadButtonText:"Click to Upload"},qus:{importWithIssues:"Some fields have issues. Do you want to proceed with the import?",doYouWantToDelete:"Do you want to delete?",doYouWantToHide:"Do you want to hide?",doYouWantToUnhide:"Do you want to unhide?"}};module.exports=e;
@@ -46,6 +46,7 @@ declare const _default: {
46
46
  maximumValueExceeded: string;
47
47
  invalidNic: string;
48
48
  invalid: string;
49
+ invalidEmail: string;
49
50
  integer: string;
50
51
  };
51
52
  notFound: string;
@@ -46,6 +46,7 @@ const e = {
46
46
  maximumValueExceeded: "must be less than %maxValue%",
47
47
  invalidNic: "must be a valid NIC",
48
48
  invalid: "must be a valid",
49
+ invalidEmail: "Invalid email address",
49
50
  integer: "must be an integer"
50
51
  },
51
52
  notFound: "Not Found"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kingteza/crud-component",
3
3
  "private": false,
4
- "version": "1.40.0",
4
+ "version": "1.41.0",
5
5
  "description": "React CRUD component library with Ant Design",
6
6
  "keywords": [
7
7
  "react",