@kingteza/crud-component 1.27.0 → 1.27.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.
@@ -1 +1 @@
1
- "use strict";const e=require("react/jsx-runtime"),q=require("antd"),n=require("react"),X=require("./modal/index.cjs.js"),Y=require("./import/CrudImportButton.cjs.js"),Z=require("./view/CrudViewer.cjs.js"),$=require("../common/button/NewButton.cjs.js"),p=require("../common/button/PrintButton.cjs.js");function U({idField:x="id",onCreate:h,onDelete:N,onHide:v,onUpdate:t,onClickUpdate:d,fields:l,data:b,grid:g,isHiding:R,isCreating:y,isDeleting:B,isUpdating:M,paginateProps:S,onPrint:k,printing:I,viewable:O,loadingData:V,formBuilder:W,extraAction:_,minusHeight:w,scroll:z,cloneable:A,fullWidthModal:D=!0,wizard:E,extraView:F,importable:m,onClickNew:r,newButtonProps:c,size:G,headerRender:i,actionWidth:H,...J}){const a=n.useRef(null),K=n.useCallback(()=>{var s;(s=a.current)==null||s.create()},[]),o=n.useCallback(async(s,C=!0,T=!1)=>{var j;await((j=a.current)==null?void 0:j.update(s,C,T))},[]),L=n.useCallback(async s=>{o(s,!1,!0)},[o]),{onClick:P,...f}=n.useMemo(()=>c||{},[c]),u=n.useMemo(()=>e.jsx($.NewButton,{onClick:(s,C)=>{r?r():c!=null&&c.onClick?c.onClick(C):K()},className:"flex-1",...f}),[r,c,f]),Q=n.useCallback(()=>i?i({newButton:u}):u,[u,i]);return e.jsxs(e.Fragment,{children:[e.jsxs(q.Space,{direction:"vertical",className:"w-100",children:[e.jsxs("div",{className:"w-100 d-flex",children:[e.jsx("div",{className:"flex-1",children:Q()}),e.jsxs(q.Space,{children:[!!k&&e.jsx(p.PrintButton,{className:"float-right",loading:I,onClick:k}),!!m&&e.jsx(Y,{fields:l,importProps:m})]})]}),e.jsx(Z,{...J,minusHeight:w,scroll:z,data:b,size:G,fields:l,extraAction:_,actionWidth:H,idField:x,isDeleting:B,loadingData:V,onClickUpdate:d||(t?o:void 0),onHide:v,isHiding:R,onDelete:N,onUpdate:t,onClickClone:A?L:void 0,paginateProps:S,viewable:O,extraView:F})]}),e.jsx(X,{ref:a,fields:l,wizard:E,grid:g,fullWidthModal:D,isCreating:y,isUpdating:M,onCreate:h,onUpdate:t,idField:x,formBuilder:W})]})}module.exports=U;
1
+ "use strict";const e=require("react/jsx-runtime"),q=require("antd"),n=require("react"),Y=require("./modal/index.cjs.js"),Z=require("./import/CrudImportButton.cjs.js"),$=require("./view/CrudViewer.cjs.js"),p=require("../common/button/NewButton.cjs.js"),U=require("../common/button/PrintButton.cjs.js");function P({idField:x="id",onCreate:h,onDelete:N,onHide:v,onUpdate:t,onClickUpdate:d,fields:l,data:b,grid:g,isHiding:R,isCreating:y,isDeleting:B,isUpdating:M,paginateProps:S,onPrint:k,printing:I,viewable:O,loadingData:V,formBuilder:W,extraAction:_,minusHeight:w,scroll:z,cloneable:A,fullWidthModal:D=!0,wizard:E,extraView:F,importable:m,onClickNew:r,newButtonProps:c,size:G,headerRender:i,actionWidth:H,onValuesChange:J,...K}){const a=n.useRef(null),L=n.useCallback(()=>{var s;(s=a.current)==null||s.create()},[]),o=n.useCallback(async(s,C=!0,X=!1)=>{var j;await((j=a.current)==null?void 0:j.update(s,C,X))},[]),Q=n.useCallback(async s=>{o(s,!1,!0)},[o]),{onClick:ee,...f}=n.useMemo(()=>c||{},[c]),u=n.useMemo(()=>e.jsx(p.NewButton,{onClick:(s,C)=>{r?r():c!=null&&c.onClick?c.onClick(C):L()},className:"flex-1",...f}),[r,c,f]),T=n.useCallback(()=>i?i({newButton:u}):u,[u,i]);return e.jsxs(e.Fragment,{children:[e.jsxs(q.Space,{direction:"vertical",className:"w-100",children:[e.jsxs("div",{className:"w-100 d-flex",children:[e.jsx("div",{className:"flex-1",children:T()}),e.jsxs(q.Space,{children:[!!k&&e.jsx(U.PrintButton,{className:"float-right",loading:I,onClick:k}),!!m&&e.jsx(Z,{fields:l,importProps:m})]})]}),e.jsx($,{...K,minusHeight:w,scroll:z,data:b,size:G,fields:l,extraAction:_,actionWidth:H,idField:x,isDeleting:B,loadingData:V,onClickUpdate:d||(t?o:void 0),onHide:v,isHiding:R,onDelete:N,onUpdate:t,onClickClone:A?Q:void 0,paginateProps:S,viewable:O,extraView:F})]}),e.jsx(Y,{ref:a,fields:l,wizard:E,grid:g,fullWidthModal:D,isCreating:y,isUpdating:M,onCreate:h,onUpdate:t,idField:x,formBuilder:W,onValuesChange:J})]})}module.exports=P;
@@ -1,4 +1,4 @@
1
- import { ButtonProps, ColorPickerProps } from 'antd';
1
+ import { ButtonProps, ColorPickerProps, FormProps } from 'antd';
2
2
  import { Rule } from 'antd/es/form';
3
3
  import { FormInstance, FormItemProps, TablePaginationConfig, TableProps } from 'antd/lib';
4
4
  import { Dayjs } from 'dayjs';
@@ -21,7 +21,7 @@ export type SelectFieldItem = {
21
21
  disabled?: boolean;
22
22
  };
23
23
  export interface InitialCrudField<T> {
24
- formLayoutProps?: Pick<FormItemProps, "layout" | 'labelCol' | 'wrapperCol'>;
24
+ formLayoutProps?: Pick<FormItemProps, "layout" | "labelCol" | "wrapperCol">;
25
25
  label: string;
26
26
  fieldHelper?: ReactNode;
27
27
  updatingValue?: T;
@@ -281,6 +281,7 @@ export type CrudComponentProps<T, FormType = T> = {
281
281
  headerRender?: (props: {
282
282
  newButton: JSX.Element;
283
283
  }) => React.ReactElement;
284
+ onValuesChange?: FormProps<T>["onValuesChange"];
284
285
  } & CrudSearchComponentProps<T, FormType>;
285
- declare function CrudComponent<T, FormType = T>({ idField, onCreate, onDelete, onHide, onUpdate, onClickUpdate, fields, data, grid, isHiding, isCreating, isDeleting, isUpdating, paginateProps, onPrint, printing, viewable, loadingData, formBuilder, extraAction, minusHeight, scroll, cloneable, fullWidthModal, wizard, extraView, importable, onClickNew, newButtonProps, size, headerRender, actionWidth, ...props }: CrudComponentProps<T, FormType>): import("react/jsx-runtime").JSX.Element;
286
+ declare function CrudComponent<T, FormType = T>({ idField, onCreate, onDelete, onHide, onUpdate, onClickUpdate, fields, data, grid, isHiding, isCreating, isDeleting, isUpdating, paginateProps, onPrint, printing, viewable, loadingData, formBuilder, extraAction, minusHeight, scroll, cloneable, fullWidthModal, wizard, extraView, importable, onClickNew, newButtonProps, size, headerRender, actionWidth, onValuesChange, ...props }: CrudComponentProps<T, FormType>): import("react/jsx-runtime").JSX.Element;
286
287
  export default CrudComponent;
@@ -1,12 +1,12 @@
1
- import { jsx as r, jsxs as l, Fragment as Z } from "react/jsx-runtime";
1
+ import { jsx as r, jsxs as l, Fragment as $ } from "react/jsx-runtime";
2
2
  import { Space as N } from "antd";
3
- import { useRef as $, useCallback as c, useMemo as v } from "react";
4
- import w from "./modal/index.es.js";
5
- import U from "./import/CrudImportButton.es.js";
6
- import P from "./view/CrudViewer.es.js";
7
- import { NewButton as ee } from "../common/button/NewButton.es.js";
8
- import { PrintButton as oe } from "../common/button/PrintButton.es.js";
9
- function fe({
3
+ import { useRef as w, useCallback as c, useMemo as v } from "react";
4
+ import U from "./modal/index.es.js";
5
+ import P from "./import/CrudImportButton.es.js";
6
+ import ee from "./view/CrudViewer.es.js";
7
+ import { NewButton as oe } from "../common/button/NewButton.es.js";
8
+ import { PrintButton as re } from "../common/button/PrintButton.es.js";
9
+ function ue({
10
10
  idField: C = "id",
11
11
  onCreate: g,
12
12
  onDelete: j,
@@ -39,55 +39,56 @@ function fe({
39
39
  size: J,
40
40
  headerRender: n,
41
41
  actionWidth: K,
42
- ...L
42
+ onValuesChange: L,
43
+ ...Q
43
44
  }) {
44
- const m = $(null), Q = c(() => {
45
+ const m = w(null), T = c(() => {
45
46
  var o;
46
47
  (o = m.current) == null || o.create();
47
48
  }, []), s = c(
48
- async (o, u = !0, Y = !1) => {
49
+ async (o, u = !0, Z = !1) => {
49
50
  var x;
50
- await ((x = m.current) == null ? void 0 : x.update(o, u, Y));
51
+ await ((x = m.current) == null ? void 0 : x.update(o, u, Z));
51
52
  },
52
53
  []
53
- ), T = c(
54
+ ), X = c(
54
55
  async (o) => {
55
56
  s(o, !1, !0);
56
57
  },
57
58
  [s]
58
- ), { onClick: re, ...p } = v(() => e || {}, [e]), f = v(
59
+ ), { onClick: le, ...p } = v(() => e || {}, [e]), f = v(
59
60
  () => /* @__PURE__ */ r(
60
- ee,
61
+ oe,
61
62
  {
62
63
  onClick: (o, u) => {
63
- a ? a() : e != null && e.onClick ? e.onClick(u) : Q();
64
+ a ? a() : e != null && e.onClick ? e.onClick(u) : T();
64
65
  },
65
66
  className: "flex-1",
66
67
  ...p
67
68
  }
68
69
  ),
69
70
  [a, e, p]
70
- ), X = c(() => n ? n({ newButton: f }) : f, [f, n]);
71
- return /* @__PURE__ */ l(Z, { children: [
71
+ ), Y = c(() => n ? n({ newButton: f }) : f, [f, n]);
72
+ return /* @__PURE__ */ l($, { children: [
72
73
  /* @__PURE__ */ l(N, { direction: "vertical", className: "w-100", children: [
73
74
  /* @__PURE__ */ l("div", { className: "w-100 d-flex", children: [
74
- /* @__PURE__ */ r("div", { className: "flex-1", children: X() }),
75
+ /* @__PURE__ */ r("div", { className: "flex-1", children: Y() }),
75
76
  /* @__PURE__ */ l(N, { children: [
76
77
  !!k && /* @__PURE__ */ r(
77
- oe,
78
+ re,
78
79
  {
79
80
  className: "float-right",
80
81
  loading: _,
81
82
  onClick: k
82
83
  }
83
84
  ),
84
- !!h && /* @__PURE__ */ r(U, { fields: t, importProps: h })
85
+ !!h && /* @__PURE__ */ r(P, { fields: t, importProps: h })
85
86
  ] })
86
87
  ] }),
87
88
  /* @__PURE__ */ r(
88
- P,
89
+ ee,
89
90
  {
90
- ...L,
91
+ ...Q,
91
92
  minusHeight: B,
92
93
  scroll: D,
93
94
  data: M,
@@ -103,7 +104,7 @@ function fe({
103
104
  isHiding: O,
104
105
  onDelete: j,
105
106
  onUpdate: i,
106
- onClickClone: E ? T : void 0,
107
+ onClickClone: E ? X : void 0,
107
108
  paginateProps: W,
108
109
  viewable: b,
109
110
  extraView: H
@@ -111,7 +112,7 @@ function fe({
111
112
  )
112
113
  ] }),
113
114
  /* @__PURE__ */ r(
114
- w,
115
+ U,
115
116
  {
116
117
  ref: m,
117
118
  fields: t,
@@ -123,11 +124,12 @@ function fe({
123
124
  onCreate: g,
124
125
  onUpdate: i,
125
126
  idField: C,
126
- formBuilder: z
127
+ formBuilder: z,
128
+ onValuesChange: L
127
129
  }
128
130
  )
129
131
  ] });
130
132
  }
131
133
  export {
132
- fe as default
134
+ ue as default
133
135
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("react"),m=require("antd"),j=require("./CrudField.cjs.js"),b=require("../util/CrudUtil.cjs.js");function v({form:i,purpose:y="new",...o}){return e.jsx(m.Form,{form:i,layout:"vertical",children:e.jsx(x,{...o,purpose:y})})}function x({fields:i,formBuilder:y,grid:o,onDeleteFile:d,onUploadFile:u,purpose:c}){const p=s.useMemo(()=>i.filter(t=>!t.readonly&&(t.type!=="object"||typeof t.customFormFieldRender=="function")).map(t=>{const a={onUploading:t.type==="image"||t.type==="file"?r=>{var n;t.onUploading&&((n=t.onUploading)==null||n.call(t,r)),u==null||u(r)}:void 0,onDelete:t.type==="image"||t.type==="file"?r=>{var n;t.onUploading&&((n=t.onDelete)==null||n.call(t,r)),d==null||d(r)}:void 0};return e.jsx(s.Fragment,{children:t.grid&&o?e.jsx(m.Col,{...t.grid,children:s.createElement(j.default,{...t,...a,key:typeof t.name=="string"?t.name:String(t.name),updatable:c!=="update"?!0:t.updatable})}):s.createElement(j.default,{...t,...a,key:typeof t.name=="string"?t.name:String(t.name),updatable:c!=="update"?!0:t.updatable})},t.name)}),[i,o,d,u,c]),C=s.useCallback((t,a={})=>{const r=i.find(n=>b.getRealName(n.name)===t);if(r!=null&&r.hidden)return e.jsx(e.Fragment,{});if(r){const n={onUploading:r.type==="image"||r.type==="file"?g=>{var f;r.onUploading&&((f=r.onUploading)==null||f.call(r,g)),u==null||u(g)}:void 0,onDelete:r.type==="image"||r.type==="file"?g=>{var f;r.onUploading&&((f=r.onDelete)==null||f.call(r,g)),d==null||d(g)}:void 0},l=b.getRealName(r.name),h=s.createElement(j.default,{...r,...a,...n,key:typeof l=="string"?l:String(l),updatable:c!=="update"?!0:r.updatable});return a.render?a.render(h):h}return e.jsx(e.Fragment,{})},[i,c]);return e.jsx(e.Fragment,{children:y?e.jsxs(e.Fragment,{children:[y(C,{isAnyFieldHidden(...t){const a=Array.isArray(t)?t:[t];return i.filter(n=>a.includes(n.name)).some(n=>n.hidden)},isAllFieldsHidden(...t){const a=Array.isArray(t)?t:[t];return i.filter(n=>a.includes(n.name)).every(n=>n.hidden)},purpose:c}),e.jsxs(m.Form.Item,{hidden:!0,noStyle:!0,children:[e.jsx(m.Input,{name:"id"}),e.jsx(m.Input,{})]})]}):o?e.jsx(m.Row,{gutter:[8,8],children:p}):p})}exports.CrudForm=v;exports.CrudFormFields=x;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("react"),m=require("antd"),j=require("./CrudField.cjs.js"),b=require("../util/CrudUtil.cjs.js");function v({form:d,purpose:y="new",onValuesChange:o,...i}){return e.jsx(m.Form,{form:d,layout:"vertical",onValuesChange:o,children:e.jsx(x,{...i,purpose:y})})}function x({fields:d,formBuilder:y,grid:o,onDeleteFile:i,onUploadFile:u,purpose:c}){const p=s.useMemo(()=>d.filter(t=>!t.readonly&&(t.type!=="object"||typeof t.customFormFieldRender=="function")).map(t=>{const a={onUploading:t.type==="image"||t.type==="file"?r=>{var n;t.onUploading&&((n=t.onUploading)==null||n.call(t,r)),u==null||u(r)}:void 0,onDelete:t.type==="image"||t.type==="file"?r=>{var n;t.onUploading&&((n=t.onDelete)==null||n.call(t,r)),i==null||i(r)}:void 0};return e.jsx(s.Fragment,{children:t.grid&&o?e.jsx(m.Col,{...t.grid,children:s.createElement(j.default,{...t,...a,key:typeof t.name=="string"?t.name:String(t.name),updatable:c!=="update"?!0:t.updatable})}):s.createElement(j.default,{...t,...a,key:typeof t.name=="string"?t.name:String(t.name),updatable:c!=="update"?!0:t.updatable})},t.name)}),[d,o,i,u,c]),C=s.useCallback((t,a={})=>{const r=d.find(n=>b.getRealName(n.name)===t);if(r!=null&&r.hidden)return e.jsx(e.Fragment,{});if(r){const n={onUploading:r.type==="image"||r.type==="file"?g=>{var f;r.onUploading&&((f=r.onUploading)==null||f.call(r,g)),u==null||u(g)}:void 0,onDelete:r.type==="image"||r.type==="file"?g=>{var f;r.onUploading&&((f=r.onDelete)==null||f.call(r,g)),i==null||i(g)}:void 0},l=b.getRealName(r.name),h=s.createElement(j.default,{...r,...a,...n,key:typeof l=="string"?l:String(l),updatable:c!=="update"?!0:r.updatable});return a.render?a.render(h):h}return e.jsx(e.Fragment,{})},[d,c]);return e.jsx(e.Fragment,{children:y?e.jsxs(e.Fragment,{children:[y(C,{isAnyFieldHidden(...t){const a=Array.isArray(t)?t:[t];return d.filter(n=>a.includes(n.name)).some(n=>n.hidden)},isAllFieldsHidden(...t){const a=Array.isArray(t)?t:[t];return d.filter(n=>a.includes(n.name)).every(n=>n.hidden)},purpose:c}),e.jsxs(m.Form.Item,{hidden:!0,noStyle:!0,children:[e.jsx(m.Input,{name:"id"}),e.jsx(m.Input,{})]})]}):o?e.jsx(m.Row,{gutter:[8,8],children:p}):p})}exports.CrudForm=v;exports.CrudFormFields=x;
@@ -1,4 +1,4 @@
1
- import { FormInstance } from 'antd';
1
+ import { FormInstance, FormProps } from 'antd';
2
2
  import { CrudFieldProps, CrudPurpose, FormBuilderFunc } from './CrudComponent';
3
3
  export interface CurdFormFieldsProps<T> {
4
4
  onDeleteFile?: (e: any) => void;
@@ -7,8 +7,9 @@ export interface CurdFormFieldsProps<T> {
7
7
  formBuilder?: FormBuilderFunc<T>;
8
8
  fields: CrudFieldProps<T>[];
9
9
  purpose?: CrudPurpose;
10
+ onValuesChange?: FormProps<T>["onValuesChange"];
10
11
  }
11
- export declare function CrudForm<T>({ form, purpose, ...props }: Readonly<CurdFormFieldsProps<T> & {
12
+ export declare function CrudForm<T>({ form, purpose, onValuesChange, ...props }: Readonly<CurdFormFieldsProps<T> & {
12
13
  form: FormInstance;
13
14
  }>): import("react/jsx-runtime").JSX.Element;
14
15
  export declare function CrudFormFields<T>({ fields, formBuilder, grid, onDeleteFile, onUploadFile, purpose, }: Readonly<CurdFormFieldsProps<T>>): import("react/jsx-runtime").JSX.Element;
@@ -4,22 +4,23 @@ import { Form as R, Col as w, Input as A, Row as H } from "antd";
4
4
  import l from "./CrudField.es.js";
5
5
  import C from "../util/CrudUtil.es.js";
6
6
  function z({
7
- form: d,
7
+ form: m,
8
8
  purpose: y = "new",
9
- ...o
9
+ onValuesChange: o,
10
+ ...d
10
11
  }) {
11
- return /* @__PURE__ */ a(R, { form: d, layout: "vertical", children: /* @__PURE__ */ a(I, { ...o, purpose: y }) });
12
+ return /* @__PURE__ */ a(R, { form: m, layout: "vertical", onValuesChange: o, children: /* @__PURE__ */ a(I, { ...d, purpose: y }) });
12
13
  }
13
14
  function I({
14
- fields: d,
15
+ fields: m,
15
16
  formBuilder: y,
16
17
  grid: o,
17
- onDeleteFile: m,
18
+ onDeleteFile: d,
18
19
  onUploadFile: e,
19
20
  purpose: u
20
21
  }) {
21
22
  const h = j(
22
- () => d.filter(
23
+ () => m.filter(
23
24
  (t) => !t.readonly && (t.type !== "object" || typeof t.customFormFieldRender == "function")
24
25
  ).map((t) => {
25
26
  const i = {
@@ -29,7 +30,7 @@ function I({
29
30
  } : void 0,
30
31
  onDelete: t.type === "image" || t.type === "file" ? (r) => {
31
32
  var n;
32
- t.onUploading && ((n = t.onDelete) == null || n.call(t, r)), m == null || m(r);
33
+ t.onUploading && ((n = t.onDelete) == null || n.call(t, r)), d == null || d(r);
33
34
  } : void 0
34
35
  };
35
36
  return /* @__PURE__ */ a(S.Fragment, { children: t.grid && o ? /* @__PURE__ */ a(w, { ...t.grid, children: /* @__PURE__ */ p(
@@ -50,10 +51,10 @@ function I({
50
51
  }
51
52
  ) }, t.name);
52
53
  }),
53
- [d, o, m, e, u]
54
+ [m, o, d, e, u]
54
55
  ), k = N(
55
56
  (t, i = {}) => {
56
- const r = d.find(
57
+ const r = m.find(
57
58
  (n) => C.getRealName(n.name) === t
58
59
  );
59
60
  if (r != null && r.hidden) return /* @__PURE__ */ a(g, {});
@@ -65,7 +66,7 @@ function I({
65
66
  } : void 0,
66
67
  onDelete: r.type === "image" || r.type === "file" ? (c) => {
67
68
  var f;
68
- r.onUploading && ((f = r.onDelete) == null || f.call(r, c)), m == null || m(c);
69
+ r.onUploading && ((f = r.onDelete) == null || f.call(r, c)), d == null || d(c);
69
70
  } : void 0
70
71
  }, s = C.getRealName(r.name), b = /* @__PURE__ */ p(
71
72
  l,
@@ -81,17 +82,17 @@ function I({
81
82
  }
82
83
  return /* @__PURE__ */ a(g, {});
83
84
  },
84
- [d, u]
85
+ [m, u]
85
86
  );
86
87
  return /* @__PURE__ */ a(g, { children: y ? /* @__PURE__ */ v(g, { children: [
87
88
  y(k, {
88
89
  isAnyFieldHidden(...t) {
89
90
  const i = Array.isArray(t) ? t : [t];
90
- return d.filter((n) => i.includes(n.name)).some((n) => n.hidden);
91
+ return m.filter((n) => i.includes(n.name)).some((n) => n.hidden);
91
92
  },
92
93
  isAllFieldsHidden(...t) {
93
94
  const i = Array.isArray(t) ? t : [t];
94
- return d.filter((n) => i.includes(n.name)).every((n) => n.hidden);
95
+ return m.filter((n) => i.includes(n.name)).every((n) => n.hidden);
95
96
  },
96
97
  purpose: u
97
98
  }),
@@ -1 +1 @@
1
- "use strict";const e=require("react/jsx-runtime"),j=require("@ant-design/icons"),u=require("antd"),F=require("react"),y=require("../locale/index.cjs.js"),R=require("./CrudForm.cjs.js"),S=require("../common/wizard/WizardViewForm.cjs.js"),b=require("../util/CrudUtil.cjs.js"),C=require("../common/button/Button.cjs.js");function v({fields:d,className:m,onDeleteFile:h,onUploadFile:s,purpose:l,wizard:t=[],updatingValue:f,onSave:x,submitting:g}){const c=F.useMemo(()=>t.map(r=>{let n=!0;const o=d.filter(i=>r.fields.includes(b.getRealName(i.name)));return o.forEach(i=>n&&(n=i.hidden??!1)),{...r,hidden:n,fieldThatShouldShowing:o}}),[d,t]),a=F.useMemo(()=>c.filter(r=>!r.hidden),[c]);return e.jsx(S,{onSubmit:(r,n)=>{x(n)},className:m,pages:a.map(({title:r,icon:n,fieldThatShouldShowing:o,hidden:i},q)=>({title:r,icon:n,hidden:i,component:k=>e.jsx(N,{fields:o,onDeleteFile:h,onUploadFile:s,purpose:l,i:q,updatingValue:f,backward:k.backward,forward:k.forward,wizard:a,submitting:g},q)}))})}function N({fields:d,onDeleteFile:m,onUploadFile:h,purpose:s,wizard:l=[],i:t,forward:f,backward:x,submitting:g,updatingValue:c}){const a=l[t],{t:r}=y.useTranslationLib(),[n]=u.Form.useForm();return F.useEffect(()=>{if(c&&(s==="update"||s==="clone")){const o={};for(const i of d)o[b.getRealName(i.name,"upsertFieldName")]=c[b.getRealName(i.name,"upsertFieldName")];n.setFieldsValue(o)}},[d,n,s,c]),e.jsxs(u.Form,{name:String(t),form:n,layout:"vertical",children:[e.jsx(R.CrudFormFields,{fields:d,formBuilder:a.formBuilder,grid:a.grid,onDeleteFile:m,onUploadFile:h,purpose:s}),e.jsx(u.Divider,{}),e.jsxs(u.Row,{gutter:[8,8],children:[t>0&&e.jsx(u.Col,{md:12,children:e.jsx(C,{block:!0,icon:e.jsx(j.LeftOutlined,{}),htmlType:"button",type:"default",size:"large",onClick:()=>x(),children:r("str.back")})}),e.jsx(u.Col,{md:t>0?12:24,children:e.jsx(C,{block:!0,icon:l.length-1===t?e.jsx(j.SaveOutlined,{}):e.jsx(j.RightOutlined,{}),htmlType:"submit",type:"primary",loading:g,size:"large",onClick:()=>{n.validateFields().then(o=>{f(o,l.length-1===t,l.length-1===t)})},children:l.length-1===t?r("str."+(s==="update"?"update":"save")):r("str.next")})})]})]})}module.exports=v;
1
+ "use strict";const e=require("react/jsx-runtime"),F=require("@ant-design/icons"),c=require("antd"),b=require("react"),R=require("../locale/index.cjs.js"),S=require("./CrudForm.cjs.js"),v=require("../common/wizard/WizardViewForm.cjs.js"),q=require("../util/CrudUtil.cjs.js"),y=require("../common/button/Button.cjs.js");function N({fields:d,className:h,onDeleteFile:f,onUploadFile:s,purpose:l,wizard:t=[],updatingValue:x,onSave:g,submitting:j,onValuesChange:u}){const m=b.useMemo(()=>t.map(r=>{let n=!0;const o=d.filter(i=>r.fields.includes(q.getRealName(i.name)));return o.forEach(i=>n&&(n=i.hidden??!1)),{...r,hidden:n,fieldThatShouldShowing:o}}),[d,t]),a=b.useMemo(()=>m.filter(r=>!r.hidden),[m]);return e.jsx(v,{onSubmit:(r,n)=>{g(n)},className:h,pages:a.map(({title:r,icon:n,fieldThatShouldShowing:o,hidden:i},k)=>({title:r,icon:n,hidden:i,component:C=>e.jsx(w,{fields:o,onDeleteFile:f,onUploadFile:s,purpose:l,i:k,updatingValue:x,backward:C.backward,forward:C.forward,wizard:a,submitting:j,onValuesChange:u},k)}))})}function w({fields:d,onDeleteFile:h,onUploadFile:f,purpose:s,wizard:l=[],i:t,forward:x,backward:g,submitting:j,updatingValue:u,onValuesChange:m}){const a=l[t],{t:r}=R.useTranslationLib(),[n]=c.Form.useForm();return b.useEffect(()=>{if(u&&(s==="update"||s==="clone")){const o={};for(const i of d)o[q.getRealName(i.name,"upsertFieldName")]=u[q.getRealName(i.name,"upsertFieldName")];n.setFieldsValue(o)}},[d,n,s,u]),e.jsxs(c.Form,{name:String(t),form:n,layout:"vertical",onValuesChange:m,children:[e.jsx(S.CrudFormFields,{fields:d,formBuilder:a.formBuilder,grid:a.grid,onDeleteFile:h,onUploadFile:f,purpose:s}),e.jsx(c.Divider,{}),e.jsxs(c.Row,{gutter:[8,8],children:[t>0&&e.jsx(c.Col,{md:12,children:e.jsx(y,{block:!0,icon:e.jsx(F.LeftOutlined,{}),htmlType:"button",type:"default",size:"large",onClick:()=>g(),children:r("str.back")})}),e.jsx(c.Col,{md:t>0?12:24,children:e.jsx(y,{block:!0,icon:l.length-1===t?e.jsx(F.SaveOutlined,{}):e.jsx(F.RightOutlined,{}),htmlType:"submit",type:"primary",loading:j,size:"large",onClick:()=>{n.validateFields().then(o=>{x(o,l.length-1===t,l.length-1===t)})},children:l.length-1===t?r("str."+(s==="update"?"update":"save")):r("str.next")})})]})]})}module.exports=N;
@@ -1,3 +1,4 @@
1
+ import { FormProps } from 'antd';
1
2
  import { CrudFieldProps, CrudPurpose, CrudWizardProp } from './CrudComponent';
2
3
  export interface CrudFormWizardProps<T> {
3
4
  onDeleteFile?: (e: any) => void;
@@ -9,6 +10,7 @@ export interface CrudFormWizardProps<T> {
9
10
  onSave: (e: T) => void;
10
11
  updatingValue?: T;
11
12
  submitting?: boolean;
13
+ onValuesChange?: FormProps<T>["onValuesChange"];
12
14
  }
13
- declare function CrudFormWizard<T>({ fields, className, onDeleteFile, onUploadFile, purpose, wizard, updatingValue, onSave, submitting, }: Readonly<CrudFormWizardProps<T>>): import("react/jsx-runtime").JSX.Element;
15
+ declare function CrudFormWizard<T>({ fields, className, onDeleteFile, onUploadFile, purpose, wizard, updatingValue, onSave, submitting, onValuesChange, }: Readonly<CrudFormWizardProps<T>>): import("react/jsx-runtime").JSX.Element;
14
16
  export default CrudFormWizard;
@@ -1,140 +1,152 @@
1
- import { jsx as o, jsxs as k } from "react/jsx-runtime";
2
- import { LeftOutlined as N, SaveOutlined as R, RightOutlined as w } from "@ant-design/icons";
3
- import { Form as y, Divider as x, Row as T, Col as C } from "antd";
4
- import { useMemo as S, useEffect as W } from "react";
5
- import { useTranslationLib as j } from "../locale/index.es.js";
6
- import { CrudFormFields as z } from "./CrudForm.es.js";
7
- import B from "../common/wizard/WizardViewForm.es.js";
8
- import p from "../util/CrudUtil.es.js";
9
- import v from "../common/button/Button.es.js";
10
- function H({
1
+ import { jsx as o, jsxs as y } from "react/jsx-runtime";
2
+ import { LeftOutlined as R, SaveOutlined as w, RightOutlined as x } from "@ant-design/icons";
3
+ import { Form as C, Divider as T, Row as W, Col as S } from "antd";
4
+ import { useMemo as v, useEffect as j } from "react";
5
+ import { useTranslationLib as z } from "../locale/index.es.js";
6
+ import { CrudFormFields as B } from "./CrudForm.es.js";
7
+ import O from "../common/wizard/WizardViewForm.es.js";
8
+ import b from "../util/CrudUtil.es.js";
9
+ import N from "../common/button/Button.es.js";
10
+ function I({
11
11
  fields: d,
12
- className: u,
13
- onDeleteFile: f,
12
+ className: f,
13
+ onDeleteFile: s,
14
14
  onUploadFile: m,
15
15
  purpose: l,
16
16
  wizard: e = [],
17
- updatingValue: s,
18
- onSave: h,
19
- submitting: g
17
+ updatingValue: h,
18
+ onSave: g,
19
+ submitting: p,
20
+ onValuesChange: a
20
21
  }) {
21
- const a = S(() => e.map((t) => {
22
+ const u = v(() => e.map((t) => {
22
23
  let r = !0;
23
24
  const n = d.filter(
24
- (i) => t.fields.includes(p.getRealName(i.name))
25
+ (i) => t.fields.includes(b.getRealName(i.name))
25
26
  );
26
27
  return n.forEach((i) => r && (r = i.hidden ?? !1)), {
27
28
  ...t,
28
29
  hidden: r,
29
30
  fieldThatShouldShowing: n
30
31
  };
31
- }), [d, e]), c = S(
32
- () => a.filter((t) => !t.hidden),
33
- [a]
32
+ }), [d, e]), c = v(
33
+ () => u.filter((t) => !t.hidden),
34
+ [u]
34
35
  );
35
36
  return /* @__PURE__ */ o(
36
- B,
37
+ O,
37
38
  {
38
39
  onSubmit: (t, r) => {
39
- h(r);
40
+ g(r);
40
41
  },
41
- className: u,
42
+ className: f,
42
43
  pages: c.map(
43
- ({ title: t, icon: r, fieldThatShouldShowing: n, hidden: i }, b) => ({
44
+ ({ title: t, icon: r, fieldThatShouldShowing: n, hidden: i }, F) => ({
44
45
  title: t,
45
46
  icon: r,
46
47
  hidden: i,
47
- component: (F) => /* @__PURE__ */ o(
48
- O,
48
+ component: (k) => /* @__PURE__ */ o(
49
+ E,
49
50
  {
50
51
  fields: n,
51
- onDeleteFile: f,
52
+ onDeleteFile: s,
52
53
  onUploadFile: m,
53
54
  purpose: l,
54
- i: b,
55
- updatingValue: s,
56
- backward: F.backward,
57
- forward: F.forward,
55
+ i: F,
56
+ updatingValue: h,
57
+ backward: k.backward,
58
+ forward: k.forward,
58
59
  wizard: c,
59
- submitting: g
60
+ submitting: p,
61
+ onValuesChange: a
60
62
  },
61
- b
63
+ F
62
64
  )
63
65
  })
64
66
  )
65
67
  }
66
68
  );
67
69
  }
68
- function O({
70
+ function E({
69
71
  fields: d,
70
- onDeleteFile: u,
71
- onUploadFile: f,
72
+ onDeleteFile: f,
73
+ onUploadFile: s,
72
74
  purpose: m,
73
75
  wizard: l = [],
74
76
  i: e,
75
- forward: s,
76
- backward: h,
77
- submitting: g,
78
- updatingValue: a
77
+ forward: h,
78
+ backward: g,
79
+ submitting: p,
80
+ updatingValue: a,
81
+ onValuesChange: u
79
82
  }) {
80
- const c = l[e], { t } = j(), [r] = y.useForm();
81
- return W(() => {
83
+ const c = l[e], { t } = z(), [r] = C.useForm();
84
+ return j(() => {
82
85
  if (a && (m === "update" || m === "clone")) {
83
86
  const n = {};
84
87
  for (const i of d)
85
- n[p.getRealName(i.name, "upsertFieldName")] = a[p.getRealName(i.name, "upsertFieldName")];
88
+ n[b.getRealName(i.name, "upsertFieldName")] = a[b.getRealName(i.name, "upsertFieldName")];
86
89
  r.setFieldsValue(n);
87
90
  }
88
- }, [d, r, m, a]), /* @__PURE__ */ k(y, { name: String(e), form: r, layout: "vertical", children: [
89
- /* @__PURE__ */ o(
90
- z,
91
- {
92
- fields: d,
93
- formBuilder: c.formBuilder,
94
- grid: c.grid,
95
- onDeleteFile: u,
96
- onUploadFile: f,
97
- purpose: m
98
- }
99
- ),
100
- /* @__PURE__ */ o(x, {}),
101
- /* @__PURE__ */ k(T, { gutter: [8, 8], children: [
102
- e > 0 && /* @__PURE__ */ o(C, { md: 12, children: /* @__PURE__ */ o(
103
- v,
104
- {
105
- block: !0,
106
- icon: /* @__PURE__ */ o(N, {}),
107
- htmlType: "button",
108
- type: "default",
109
- size: "large",
110
- onClick: () => h(),
111
- children: t("str.back")
112
- }
113
- ) }),
114
- /* @__PURE__ */ o(C, { md: e > 0 ? 12 : 24, children: /* @__PURE__ */ o(
115
- v,
116
- {
117
- block: !0,
118
- icon: l.length - 1 === e ? /* @__PURE__ */ o(R, {}) : /* @__PURE__ */ o(w, {}),
119
- htmlType: "submit",
120
- type: "primary",
121
- loading: g,
122
- size: "large",
123
- onClick: () => {
124
- r.validateFields().then((n) => {
125
- s(
126
- n,
127
- l.length - 1 === e,
128
- l.length - 1 === e
129
- );
130
- });
131
- },
132
- children: l.length - 1 === e ? t("str." + (m === "update" ? "update" : "save")) : t("str.next")
133
- }
134
- ) })
135
- ] })
136
- ] });
91
+ }, [d, r, m, a]), /* @__PURE__ */ y(
92
+ C,
93
+ {
94
+ name: String(e),
95
+ form: r,
96
+ layout: "vertical",
97
+ onValuesChange: u,
98
+ children: [
99
+ /* @__PURE__ */ o(
100
+ B,
101
+ {
102
+ fields: d,
103
+ formBuilder: c.formBuilder,
104
+ grid: c.grid,
105
+ onDeleteFile: f,
106
+ onUploadFile: s,
107
+ purpose: m
108
+ }
109
+ ),
110
+ /* @__PURE__ */ o(T, {}),
111
+ /* @__PURE__ */ y(W, { gutter: [8, 8], children: [
112
+ e > 0 && /* @__PURE__ */ o(S, { md: 12, children: /* @__PURE__ */ o(
113
+ N,
114
+ {
115
+ block: !0,
116
+ icon: /* @__PURE__ */ o(R, {}),
117
+ htmlType: "button",
118
+ type: "default",
119
+ size: "large",
120
+ onClick: () => g(),
121
+ children: t("str.back")
122
+ }
123
+ ) }),
124
+ /* @__PURE__ */ o(S, { md: e > 0 ? 12 : 24, children: /* @__PURE__ */ o(
125
+ N,
126
+ {
127
+ block: !0,
128
+ icon: l.length - 1 === e ? /* @__PURE__ */ o(w, {}) : /* @__PURE__ */ o(x, {}),
129
+ htmlType: "submit",
130
+ type: "primary",
131
+ loading: p,
132
+ size: "large",
133
+ onClick: () => {
134
+ r.validateFields().then((n) => {
135
+ h(
136
+ n,
137
+ l.length - 1 === e,
138
+ l.length - 1 === e
139
+ );
140
+ });
141
+ },
142
+ children: l.length - 1 === e ? t("str." + (m === "update" ? "update" : "save")) : t("str.next")
143
+ }
144
+ ) })
145
+ ] })
146
+ ]
147
+ }
148
+ );
137
149
  }
138
150
  export {
139
- H as default
151
+ I as default
140
152
  };
@@ -1 +1 @@
1
- "use strict";const g=require("react/jsx-runtime"),B=require("antd"),t=require("react"),G=require("../CrudForm.cjs.js"),J=require("../CrudFormWizard.cjs.js"),K=require("../../locale/index.cjs.js"),H=require("../../util/CrudUtil.cjs.js"),Q=require("dayjs"),X=({fields:u,wizard:l,grid:I,fullWidthModal:M,isCreating:h,isUpdating:j,onCreate:b,onUpdate:v,idField:k="id",formBuilder:T},W)=>{const[s]=B.Form.useForm(),{t:C}=K.useTranslationLib(),[S,m]=t.useState(!1),[p,q]=t.useState("new"),[f,F]=t.useState(),[_,y]=t.useState(),[A,N]=t.useState(!1),[L,x]=t.useState(!1),[E,V]=t.useState(!1),P=t.useCallback(async c=>{var n;const d=l?c:await s.validateFields(),i=u.filter(a=>a.type==="color"),o={};for(const a of i){const e=H.getRealName(a.name,"upsertFieldName"),r=s.getFieldValue(e);o[e]=typeof r=="string"?r:(n=r==null?void 0:r.toHexString())==null?void 0:n.toUpperCase()}Object.assign(d,o),f&&v?(await v({...d,[k]:f[k]}),F(void 0)):!f&&b&&await b(d),y(void 0),s.resetFields(),m(!1)},[u,s,k,b,v,f,l]),R=t.useCallback(async c=>{N(c),x(!0)},[]),U=t.useCallback(async()=>{x(!0)},[]),O=t.useCallback(()=>{m(!0),q("new"),s.resetFields(),F(void 0),y(void 0)},[s]),D=t.useCallback(async(c,d=!0,i=!1)=>{try{V(!0),m(!0),q(i?"clone":"update");const o={};for(const n of u){const a=H.getRealName(n.name,"upsertFieldName"),e=c[a];if(i&&n.type==="image"){const r=e;try{const w=await n.provider.clone(r);o[a]=w;continue}catch{continue}}n.type==="date"||n.type==="time"?e&&(o[a]=Q(e)):n.type==="select"?n.multiple&&Array.isArray(e)?o[a]=e.map(r=>r[n.innerFieldId??"id"]):e&&typeof e=="object"?o[a]=e[n.innerFieldId??"id"]:(e&&typeof e=="string"||typeof e=="number")&&(o[a]=e):o[a]=e}s.setFieldsValue(o),y(o),d&&F(c)}finally{V(!1)}},[u,s]);t.useImperativeHandle(W,()=>({create:O,update:D}),[O,D]),t.useEffect(()=>{S&&(N(!1),x(!1))},[S]);const $=t.useCallback(async()=>{try{if(p==="clone"){const c=l?f:s.getFieldsValue(),d=u.filter(i=>i.type==="image");for(const i of d)c[i.name]&&i.provider.delete(c[i.name])}}finally{}l||s.resetFields(),y(void 0),F(void 0),m(!1)},[p,l,s,f,u]);return g.jsx(B.Modal,{width:M?"100%":void 0,title:C(p??"new"),open:S,confirmLoading:h||j,okText:C("str."+(p==="update"?"update":"save")),cancelText:C("str.cancel"),cancelButtonProps:{disabled:L,hidden:!!l},okButtonProps:{disabled:A,hidden:!!l},onCancel:$,onOk:()=>P(),destroyOnHidden:!0,children:g.jsxs(B.Spin,{spinning:E,children:[l?null:g.jsx(G.CrudForm,{purpose:p,fields:u,form:s,formBuilder:T,grid:I,onDeleteFile:U,onUploadFile:R}),l&&g.jsx(J,{submitting:h||j,className:"mt-2",onSave:P,updatingValue:_,fields:u,onDeleteFile:U,onUploadFile:R,purpose:p,wizard:l})]})})},Y=t.forwardRef(X);module.exports=Y;
1
+ "use strict";const g=require("react/jsx-runtime"),B=require("antd"),t=require("react"),J=require("../CrudForm.cjs.js"),K=require("../CrudFormWizard.cjs.js"),Q=require("../../locale/index.cjs.js"),I=require("../../util/CrudUtil.cjs.js"),X=require("dayjs"),Y=({fields:u,wizard:l,grid:M,fullWidthModal:T,isCreating:h,isUpdating:j,onCreate:b,onUpdate:v,idField:k="id",formBuilder:W,onValuesChange:q},_)=>{const[s]=B.Form.useForm(),{t:S}=Q.useTranslationLib(),[C,m]=t.useState(!1),[p,N]=t.useState("new"),[f,F]=t.useState(),[A,y]=t.useState(),[L,V]=t.useState(!1),[E,x]=t.useState(!1),[$,P]=t.useState(!1),R=t.useCallback(async c=>{var n;const d=l?c:await s.validateFields(),i=u.filter(a=>a.type==="color"),o={};for(const a of i){const e=I.getRealName(a.name,"upsertFieldName"),r=s.getFieldValue(e);o[e]=typeof r=="string"?r:(n=r==null?void 0:r.toHexString())==null?void 0:n.toUpperCase()}Object.assign(d,o),f&&v?(await v({...d,[k]:f[k]}),F(void 0)):!f&&b&&await b(d),y(void 0),s.resetFields(),m(!1)},[u,s,k,b,v,f,l]),U=t.useCallback(async c=>{V(c),x(!0)},[]),O=t.useCallback(async()=>{x(!0)},[]),D=t.useCallback(()=>{m(!0),N("new"),s.resetFields(),F(void 0),y(void 0)},[s]),H=t.useCallback(async(c,d=!0,i=!1)=>{try{P(!0),m(!0),N(i?"clone":"update");const o={};for(const n of u){const a=I.getRealName(n.name,"upsertFieldName"),e=c[a];if(i&&n.type==="image"){const r=e;try{const G=await n.provider.clone(r);o[a]=G;continue}catch{continue}}n.type==="date"||n.type==="time"?e&&(o[a]=X(e)):n.type==="select"?n.multiple&&Array.isArray(e)?o[a]=e.map(r=>r[n.innerFieldId??"id"]):e&&typeof e=="object"?o[a]=e[n.innerFieldId??"id"]:(e&&typeof e=="string"||typeof e=="number")&&(o[a]=e):o[a]=e}s.setFieldsValue(o),y(o),d&&F(c)}finally{P(!1)}},[u,s]);t.useImperativeHandle(_,()=>({create:D,update:H}),[D,H]),t.useEffect(()=>{C&&(V(!1),x(!1))},[C]);const w=t.useCallback(async()=>{try{if(p==="clone"){const c=l?f:s.getFieldsValue(),d=u.filter(i=>i.type==="image");for(const i of d)c[i.name]&&i.provider.delete(c[i.name])}}finally{}l||s.resetFields(),y(void 0),F(void 0),m(!1)},[p,l,s,f,u]);return g.jsx(B.Modal,{width:T?"100%":void 0,title:S(p??"new"),open:C,confirmLoading:h||j,okText:S("str."+(p==="update"?"update":"save")),cancelText:S("str.cancel"),cancelButtonProps:{disabled:E,hidden:!!l},okButtonProps:{disabled:L,hidden:!!l},onCancel:w,onOk:()=>R(),destroyOnHidden:!0,children:g.jsxs(B.Spin,{spinning:$,children:[l?null:g.jsx(J.CrudForm,{purpose:p,fields:u,form:s,formBuilder:W,grid:M,onDeleteFile:O,onUploadFile:U,onValuesChange:q}),l&&g.jsx(K,{submitting:h||j,className:"mt-2",onSave:R,updatingValue:A,fields:u,onDeleteFile:O,onUploadFile:U,purpose:p,wizard:l,onValuesChange:q})]})})},Z=t.forwardRef(Y);module.exports=Z;
@@ -1,3 +1,4 @@
1
+ import { FormProps } from 'antd';
1
2
  import { Ref } from 'react';
2
3
  import { CrudFieldProps, CrudWizardProp, FormBuilderFunc } from '../CrudComponent';
3
4
  import { default as IdProps } from '../../types/Id';
@@ -12,12 +13,13 @@ export interface CrudModalProps<T, FormType> {
12
13
  onUpdate?: (data: FormType & IdProps) => Promise<any>;
13
14
  idField?: string;
14
15
  formBuilder?: FormBuilderFunc<T>;
16
+ onValuesChange?: FormProps<T>["onValuesChange"];
15
17
  }
16
18
  export interface CrudModalRef<T> {
17
19
  create: () => void;
18
20
  update: (data: T, shouldSetUpdatingField?: boolean, isClone?: boolean) => Promise<void>;
19
21
  }
20
- declare const CrudModal: <T, FormType = T>({ fields, wizard, grid, fullWidthModal, isCreating, isUpdating, onCreate, onUpdate, idField, formBuilder, }: CrudModalProps<T, FormType>, ref: Ref<CrudModalRef<T>>) => import("react/jsx-runtime").JSX.Element;
22
+ declare const CrudModal: <T, FormType = T>({ fields, wizard, grid, fullWidthModal, isCreating, isUpdating, onCreate, onUpdate, idField, formBuilder, onValuesChange, }: CrudModalProps<T, FormType>, ref: Ref<CrudModalRef<T>>) => import("react/jsx-runtime").JSX.Element;
21
23
  declare const _default: <T, FormType = T>(props: CrudModalProps<T, FormType> & {
22
24
  ref?: Ref<CrudModalRef<T>>;
23
25
  }) => ReturnType<typeof CrudModal>;
@@ -1,29 +1,30 @@
1
- import { jsx as N, jsxs as G } from "react/jsx-runtime";
2
- import { Form as J, Modal as K, Spin as Q } from "antd";
3
- import { forwardRef as X, useState as u, useCallback as m, useImperativeHandle as Y, useEffect as Z } from "react";
4
- import { CrudForm as z } from "../CrudForm.es.js";
5
- import ee from "../CrudFormWizard.es.js";
6
- import { useTranslationLib as te } from "../../locale/index.es.js";
7
- import M from "../../util/CrudUtil.es.js";
8
- import oe from "dayjs";
9
- const ne = ({
1
+ import { jsx as S, jsxs as J } from "react/jsx-runtime";
2
+ import { Form as K, Modal as Q, Spin as X } from "antd";
3
+ import { forwardRef as Y, useState as u, useCallback as m, useImperativeHandle as Z, useEffect as z } from "react";
4
+ import { CrudForm as ee } from "../CrudForm.es.js";
5
+ import te from "../CrudFormWizard.es.js";
6
+ import { useTranslationLib as oe } from "../../locale/index.es.js";
7
+ import R from "../../util/CrudUtil.es.js";
8
+ import ne from "dayjs";
9
+ const se = ({
10
10
  fields: c,
11
11
  wizard: l,
12
- grid: R,
13
- fullWidthModal: T,
14
- isCreating: S,
15
- isUpdating: V,
12
+ grid: T,
13
+ fullWidthModal: W,
14
+ isCreating: x,
15
+ isUpdating: C,
16
16
  onCreate: v,
17
17
  onUpdate: b,
18
18
  idField: B = "id",
19
- formBuilder: W
20
- }, _) => {
21
- const [t] = J.useForm(), { t: h } = te(), [k, F] = u(!1), [p, x] = u("new"), [f, y] = u(), [A, g] = u(), [L, j] = u(!1), [E, C] = u(!1), [$, P] = u(!1), U = m(
19
+ formBuilder: _,
20
+ onValuesChange: V
21
+ }, A) => {
22
+ const [t] = K.useForm(), { t: h } = oe(), [k, F] = u(!1), [p, j] = u("new"), [f, y] = u(), [L, g] = u(), [E, P] = u(!1), [$, N] = u(!1), [q, U] = u(!1), O = m(
22
23
  async (i) => {
23
24
  var o;
24
25
  const d = l ? i : await t.validateFields(), a = c.filter((s) => s.type === "color"), n = {};
25
26
  for (const s of a) {
26
- const e = M.getRealName(s.name, "upsertFieldName"), r = t.getFieldValue(e);
27
+ const e = R.getRealName(s.name, "upsertFieldName"), r = t.getFieldValue(e);
27
28
  n[e] = typeof r == "string" ? r : (o = r == null ? void 0 : r.toHexString()) == null ? void 0 : o.toUpperCase();
28
29
  }
29
30
  Object.assign(d, n), f && b ? (await b({
@@ -32,54 +33,54 @@ const ne = ({
32
33
  }), y(void 0)) : !f && v && await v(d), g(void 0), t.resetFields(), F(!1);
33
34
  },
34
35
  [c, t, B, v, b, f, l]
35
- ), O = m(async (i) => {
36
- j(i), C(!0);
37
- }, []), D = m(async () => {
38
- C(!0);
39
- }, []), H = m(() => {
40
- F(!0), x("new"), t.resetFields(), y(void 0), g(void 0);
41
- }, [t]), I = m(
36
+ ), D = m(async (i) => {
37
+ P(i), N(!0);
38
+ }, []), H = m(async () => {
39
+ N(!0);
40
+ }, []), I = m(() => {
41
+ F(!0), j("new"), t.resetFields(), y(void 0), g(void 0);
42
+ }, [t]), M = m(
42
43
  async (i, d = !0, a = !1) => {
43
44
  try {
44
- P(!0), F(!0), x(a ? "clone" : "update");
45
+ U(!0), F(!0), j(a ? "clone" : "update");
45
46
  const n = {};
46
47
  for (const o of c) {
47
- const s = M.getRealName(
48
+ const s = R.getRealName(
48
49
  o.name,
49
50
  "upsertFieldName"
50
51
  ), e = i[s];
51
52
  if (a && o.type === "image") {
52
53
  const r = e;
53
54
  try {
54
- const w = await o.provider.clone(r);
55
- n[s] = w;
55
+ const G = await o.provider.clone(r);
56
+ n[s] = G;
56
57
  continue;
57
58
  } catch {
58
59
  continue;
59
60
  }
60
61
  }
61
- o.type === "date" || o.type === "time" ? e && (n[s] = oe(e)) : o.type === "select" ? o.multiple && Array.isArray(e) ? n[s] = e.map(
62
+ o.type === "date" || o.type === "time" ? e && (n[s] = ne(e)) : o.type === "select" ? o.multiple && Array.isArray(e) ? n[s] = e.map(
62
63
  (r) => r[o.innerFieldId ?? "id"]
63
64
  ) : e && typeof e == "object" ? n[s] = e[o.innerFieldId ?? "id"] : (e && typeof e == "string" || typeof e == "number") && (n[s] = e) : n[s] = e;
64
65
  }
65
66
  t.setFieldsValue(n), g(n), d && y(i);
66
67
  } finally {
67
- P(!1);
68
+ U(!1);
68
69
  }
69
70
  },
70
71
  [c, t]
71
72
  );
72
- Y(
73
- _,
73
+ Z(
74
+ A,
74
75
  () => ({
75
- create: H,
76
- update: I
76
+ create: I,
77
+ update: M
77
78
  }),
78
- [H, I]
79
- ), Z(() => {
80
- k && (j(!1), C(!1));
79
+ [I, M]
80
+ ), z(() => {
81
+ k && (P(!1), N(!1));
81
82
  }, [k]);
82
- const q = m(async () => {
83
+ const w = m(async () => {
83
84
  try {
84
85
  if (p === "clone") {
85
86
  const i = l ? f : t.getFieldsValue(), d = c.filter((a) => a.type === "image");
@@ -90,57 +91,59 @@ const ne = ({
90
91
  }
91
92
  l || t.resetFields(), g(void 0), y(void 0), F(!1);
92
93
  }, [p, l, t, f, c]);
93
- return /* @__PURE__ */ N(
94
- K,
94
+ return /* @__PURE__ */ S(
95
+ Q,
95
96
  {
96
- width: T ? "100%" : void 0,
97
+ width: W ? "100%" : void 0,
97
98
  title: h(p ?? "new"),
98
99
  open: k,
99
- confirmLoading: S || V,
100
+ confirmLoading: x || C,
100
101
  okText: h("str." + (p === "update" ? "update" : "save")),
101
102
  cancelText: h("str.cancel"),
102
103
  cancelButtonProps: {
103
- disabled: E,
104
+ disabled: $,
104
105
  hidden: !!l
105
106
  },
106
107
  okButtonProps: {
107
- disabled: L,
108
+ disabled: E,
108
109
  hidden: !!l
109
110
  },
110
- onCancel: q,
111
- onOk: () => U(),
111
+ onCancel: w,
112
+ onOk: () => O(),
112
113
  destroyOnHidden: !0,
113
- children: /* @__PURE__ */ G(Q, { spinning: $, children: [
114
- l ? null : /* @__PURE__ */ N(
115
- z,
114
+ children: /* @__PURE__ */ J(X, { spinning: q, children: [
115
+ l ? null : /* @__PURE__ */ S(
116
+ ee,
116
117
  {
117
118
  purpose: p,
118
119
  fields: c,
119
120
  form: t,
120
- formBuilder: W,
121
- grid: R,
122
- onDeleteFile: D,
123
- onUploadFile: O
121
+ formBuilder: _,
122
+ grid: T,
123
+ onDeleteFile: H,
124
+ onUploadFile: D,
125
+ onValuesChange: V
124
126
  }
125
127
  ),
126
- l && /* @__PURE__ */ N(
127
- ee,
128
+ l && /* @__PURE__ */ S(
129
+ te,
128
130
  {
129
- submitting: S || V,
131
+ submitting: x || C,
130
132
  className: "mt-2",
131
- onSave: U,
132
- updatingValue: A,
133
+ onSave: O,
134
+ updatingValue: L,
133
135
  fields: c,
134
- onDeleteFile: D,
135
- onUploadFile: O,
136
+ onDeleteFile: H,
137
+ onUploadFile: D,
136
138
  purpose: p,
137
- wizard: l
139
+ wizard: l,
140
+ onValuesChange: V
138
141
  }
139
142
  )
140
143
  ] })
141
144
  }
142
145
  );
143
- }, pe = X(ne);
146
+ }, fe = Y(se);
144
147
  export {
145
- pe as default
148
+ fe as default
146
149
  };
@@ -1 +1 @@
1
- "use strict";class s{static getRealName(t,e="name"){return typeof t=="object"?t[e]:t}}module.exports=s;
1
+ "use strict";class s{static getRealName(r,t="name"){return Array.isArray(r)?r:typeof r=="object"?r[t]:r}}module.exports=s;
@@ -1,5 +1,5 @@
1
1
  import { InitialCrudField, SelectCrudField } from 'src/crud';
2
2
  declare class CrudUtil {
3
- static getRealName<T>(name: InitialCrudField<T>["name"] | SelectCrudField<T>["name"], extract?: "name" | "upsertFieldName"): any;
3
+ static getRealName<T>(name: InitialCrudField<T>["name"] | SelectCrudField<T>["name"], extract?: "name" | "upsertFieldName"): (string | number)[] | keyof T;
4
4
  }
5
5
  export default CrudUtil;
@@ -1,8 +1,8 @@
1
- class l {
2
- static getRealName(t, e = "name") {
3
- return typeof t == "object" ? t[e] : t;
1
+ class a {
2
+ static getRealName(r, t = "name") {
3
+ return Array.isArray(r) ? r : typeof r == "object" ? r[t] : r;
4
4
  }
5
5
  }
6
6
  export {
7
- l as default
7
+ a as default
8
8
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kingteza/crud-component",
3
3
  "private": false,
4
- "version": "1.27.0",
4
+ "version": "1.27.2",
5
5
  "description": "React CRUD component library with Ant Design",
6
6
  "keywords": [
7
7
  "react",