@kingteza/crud-component 1.29.1 → 1.30.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.
@@ -27,7 +27,7 @@ export interface InitialCrudField<T> {
27
27
  updatingValue?: T;
28
28
  render?: (value: any, obj: T, index: number) => any;
29
29
  required?: boolean;
30
- updatable?: boolean;
30
+ updatable?: boolean | ((data: T) => boolean);
31
31
  fieldTooltip?: string;
32
32
  hideInTable?: boolean;
33
33
  hideInDescList?: boolean;
@@ -1 +1 @@
1
- "use strict";const b=require("react/jsx-runtime"),S=require("antd"),t=require("react"),K=require("../CrudForm.cjs.js"),Q=require("../CrudFormWizard.cjs.js"),X=require("../../locale/index.cjs.js"),M=require("../../util/CrudUtil.cjs.js"),Y=require("dayjs"),d=require("../../util/ObjectUtil.cjs.js"),Z=({fields:r,wizard:l,grid:T,fullWidthModal:W,isCreating:C,isUpdating:x,onCreate:B,onUpdate:h,idField:v="id",formBuilder:_,onValuesChange:j},A)=>{const[s]=S.Form.useForm(),{t:V}=X.useTranslationLib(),[k,m]=t.useState(!1),[f,q]=t.useState("new"),[y,F]=t.useState(),[L,g]=t.useState(),[E,N]=t.useState(!1),[$,P]=t.useState(!1),[w,U]=t.useState(!1),O=t.useCallback(async c=>{var a;const p=l?c:await s.validateFields(),i=r.filter(o=>o.type==="color"),n={};for(const o of i){const e=M.getRealName(o.name,"upsertFieldName"),u=s.getFieldValue(e);d.setValueByPath(n,e,typeof u=="string"?u:(a=u==null?void 0:u.toHexString())==null?void 0:a.toUpperCase())}Object.assign(p,n),y&&h?(await h({...p,[v]:y[v]}),F(void 0)):!y&&B&&await B(p),g(void 0),s.resetFields(),m(!1)},[r,s,v,B,h,y,l]),R=t.useCallback(async c=>{N(c),P(!0)},[]),D=t.useCallback(async()=>{P(!0)},[]),H=t.useCallback(()=>{m(!0),q("new"),s.resetFields(),F(void 0),g(void 0)},[s]),I=t.useCallback(async(c,p=!0,i=!1)=>{try{U(!0),m(!0),q(i?"clone":"update");const n={};for(const a of r){const o=M.getRealName(a.name,"upsertFieldName"),e=d.getValueByPath(c,o);if(i&&a.type==="image"){const u=e;try{const J=await a.provider.clone(u);d.setValueByPath(n,o,J);continue}catch{continue}}a.type==="date"||a.type==="time"?e&&d.setValueByPath(n,o,Y(e)):a.type==="select"?a.multiple&&Array.isArray(e)?d.setValueByPath(n,o,e.map(u=>u[a.innerFieldId??"id"])):e&&typeof e=="object"?d.setValueByPath(n,o,e[a.innerFieldId??"id"]):(e&&typeof e=="string"||typeof e=="number")&&d.setValueByPath(n,o,e):d.setValueByPath(n,o,e)}s.setFieldsValue(n),g(n),p&&F(c)}finally{U(!1)}},[r,s]);t.useImperativeHandle(A,()=>({create:H,update:I}),[H,I]),t.useEffect(()=>{k&&(N(!1),P(!1))},[k]);const G=t.useCallback(async()=>{try{if(f==="clone"){const c=l?y:s.getFieldsValue(),p=r.filter(i=>i.type==="image");for(const i of p)c[i.name]&&i.provider.delete(c[i.name])}}finally{}l||s.resetFields(),g(void 0),F(void 0),m(!1)},[f,l,s,y,r]);return b.jsx(S.Modal,{width:W?"100%":void 0,title:V("str."+(f??"new")),open:k,confirmLoading:C||x,okText:V("str."+(f==="update"?"update":"save")),cancelText:V("str.cancel"),cancelButtonProps:{disabled:$,hidden:!!l},okButtonProps:{disabled:E,hidden:!!l},onCancel:G,onOk:()=>O(),destroyOnHidden:!0,children:b.jsxs(S.Spin,{spinning:w,children:[l?null:b.jsx(K.CrudForm,{purpose:f,fields:r,form:s,formBuilder:_,grid:T,onDeleteFile:D,onUploadFile:R,onValuesChange:j}),l&&b.jsx(Q,{submitting:C||x,className:"mt-2",onSave:O,updatingValue:L,fields:r,onDeleteFile:D,onUploadFile:R,purpose:f,wizard:l,onValuesChange:j})]})})},z=t.forwardRef(Z);module.exports=z;
1
+ "use strict";const g=require("react/jsx-runtime"),q=require("antd"),t=require("react"),Z=require("../CrudForm.cjs.js"),z=require("../CrudFormWizard.cjs.js"),ee=require("../../locale/index.cjs.js"),B=require("../../util/CrudUtil.cjs.js"),te=require("dayjs"),r=require("../../util/ObjectUtil.cjs.js"),ae=({fields:l,wizard:i,grid:_,fullWidthModal:A,isCreating:N,isUpdating:M,onCreate:V,onUpdate:h,idField:v="id",formBuilder:L,onValuesChange:U},E)=>{const[n]=q.Form.useForm(),{t:S}=ee.useTranslationLib(),[k,y]=t.useState(!1),[p,R]=t.useState("new"),[f,F]=t.useState(),[$,b]=t.useState(),[G,O]=t.useState(!1),[J,P]=t.useState(!1),[K,w]=t.useState(!1),W=t.useCallback(async s=>{var m;const d=i?s:await n.validateFields(),u=l.filter(a=>a.type==="color"),o={};for(const a of u){const c=B.getRealName(a.name,"upsertFieldName"),e=n.getFieldValue(c);r.setValueByPath(o,c,typeof e=="string"?e:(m=e==null?void 0:e.toHexString())==null?void 0:m.toUpperCase())}Object.assign(d,o),f&&h?(await h({...d,[v]:f[v]}),F(void 0)):!f&&V&&await V(d),b(void 0),x(new Map),n.resetFields(),y(!1)},[l,n,v,V,h,f,i]),D=t.useCallback(async s=>{O(s),P(!0)},[]),H=t.useCallback(async()=>{P(!0)},[]),I=t.useCallback(()=>{y(!0),R("new"),n.resetFields(),F(void 0),b(void 0)},[n]),[C,x]=t.useState(new Map),Q=t.useMemo(()=>C.size===0?l:l.map(s=>typeof s.updatable=="function"?{...s,updatable:C.get(B.getRealName(s.name,"name"))??s.updatable}:s),[l,C]),T=t.useCallback(async(s,d=!0,u=!1)=>{try{w(!0),y(!0),R(u?"clone":"update");const o={};for(const a of l){const c=B.getRealName(a.name,"upsertFieldName"),e=r.getValueByPath(s,c);if(u&&a.type==="image"){const j=e;try{const Y=await a.provider.clone(j);r.setValueByPath(o,c,Y);continue}catch{continue}}a.type==="date"||a.type==="time"?e&&r.setValueByPath(o,c,te(e)):a.type==="select"?a.multiple&&Array.isArray(e)?r.setValueByPath(o,c,e.map(j=>j[a.innerFieldId??"id"])):e&&typeof e=="object"?r.setValueByPath(o,c,e[a.innerFieldId??"id"]):(e&&typeof e=="string"||typeof e=="number")&&r.setValueByPath(o,c,e):r.setValueByPath(o,c,e)}n.setFieldsValue(o);const m=new Map;for(const a of l)typeof a.updatable=="function"&&m.set(B.getRealName(a.name,"name"),a.updatable(s));x(m),b(o),d&&F(s)}finally{w(!1)}},[l,n]);t.useImperativeHandle(E,()=>({create:I,update:T}),[I,T]),t.useEffect(()=>{k&&(O(!1),P(!1))},[k]);const X=t.useCallback(async()=>{x(new Map);try{if(p==="clone"){const s=i?f:n.getFieldsValue(),d=l.filter(u=>u.type==="image");for(const u of d)s[u.name]&&u.provider.delete(s[u.name])}}finally{}i||n.resetFields(),b(void 0),F(void 0),y(!1)},[p,i,n,f,l]);return g.jsx(q.Modal,{width:A?"100%":void 0,title:S("str."+(p??"new")),open:k,confirmLoading:N||M,okText:S("str."+(p==="update"?"update":"save")),cancelText:S("str.cancel"),cancelButtonProps:{disabled:J,hidden:!!i},okButtonProps:{disabled:G,hidden:!!i},onCancel:X,onOk:()=>W(),destroyOnHidden:!0,children:g.jsxs(q.Spin,{spinning:K,children:[i?null:g.jsx(Z.CrudForm,{purpose:p,fields:Q,form:n,formBuilder:L,grid:_,onDeleteFile:H,onUploadFile:D,onValuesChange:U}),i&&g.jsx(z,{submitting:N||M,className:"mt-2",onSave:W,updatingValue:$,fields:l,onDeleteFile:H,onUploadFile:D,purpose:p,wizard:i,onValuesChange:U})]})})},se=t.forwardRef(ae);module.exports=se;
@@ -1,154 +1,171 @@
1
- import { jsx as P, jsxs as K } from "react/jsx-runtime";
2
- import { Form as Q, Modal as X, Spin as Y } from "antd";
3
- import { forwardRef as Z, useState as u, useCallback as F, useImperativeHandle as z, useEffect as ee } from "react";
4
- import { CrudForm as te } from "../CrudForm.es.js";
5
- import oe from "../CrudFormWizard.es.js";
6
- import { useTranslationLib as ne } from "../../locale/index.es.js";
7
- import T from "../../util/CrudUtil.es.js";
8
- import se from "dayjs";
9
- import { setValueByPath as p, getValueByPath as ae } from "../../util/ObjectUtil.es.js";
10
- const le = ({
11
- fields: c,
12
- wizard: a,
13
- grid: W,
14
- fullWidthModal: _,
15
- isCreating: S,
16
- isUpdating: x,
17
- onCreate: b,
18
- onUpdate: B,
1
+ import { jsx as x, jsxs as Z } from "react/jsx-runtime";
2
+ import { Form as z, Modal as ee, Spin as te } from "antd";
3
+ import { forwardRef as oe, useState as c, useCallback as m, useMemo as ae, useImperativeHandle as ne, useEffect as le } from "react";
4
+ import { CrudForm as se } from "../CrudForm.es.js";
5
+ import ie from "../CrudFormWizard.es.js";
6
+ import { useTranslationLib as re } from "../../locale/index.es.js";
7
+ import v from "../../util/CrudUtil.es.js";
8
+ import ce from "dayjs";
9
+ import { setValueByPath as d, getValueByPath as ue } from "../../util/ObjectUtil.es.js";
10
+ const de = ({
11
+ fields: n,
12
+ wizard: s,
13
+ grid: A,
14
+ fullWidthModal: L,
15
+ isCreating: C,
16
+ isUpdating: j,
17
+ onCreate: B,
18
+ onUpdate: V,
19
19
  idField: h = "id",
20
- formBuilder: A,
21
- onValuesChange: C
22
- }, L) => {
23
- const [t] = Q.useForm(), { t: k } = ne(), [V, y] = u(!1), [f, j] = u("new"), [m, g] = u(), [E, v] = u(), [$, U] = u(!1), [q, N] = u(!1), [w, O] = u(!1), D = F(
24
- async (i) => {
25
- var o;
26
- const d = a ? i : await t.validateFields(), l = c.filter((s) => s.type === "color"), n = {};
27
- for (const s of l) {
28
- const e = T.getRealName(s.name, "upsertFieldName"), r = t.getFieldValue(e);
29
- p(
30
- n,
31
- e,
32
- typeof r == "string" ? r : (o = r == null ? void 0 : r.toHexString()) == null ? void 0 : o.toUpperCase()
20
+ formBuilder: E,
21
+ onValuesChange: R
22
+ }, $) => {
23
+ const [a] = z.useForm(), { t: N } = re(), [k, y] = c(!1), [p, w] = c("new"), [f, g] = c(), [q, b] = c(), [G, O] = c(!1), [J, M] = c(!1), [K, W] = c(!1), D = m(
24
+ async (o) => {
25
+ var F;
26
+ const u = s ? o : await a.validateFields(), i = n.filter((t) => t.type === "color"), l = {};
27
+ for (const t of i) {
28
+ const r = v.getRealName(t.name, "upsertFieldName"), e = a.getFieldValue(r);
29
+ d(
30
+ l,
31
+ r,
32
+ typeof e == "string" ? e : (F = e == null ? void 0 : e.toHexString()) == null ? void 0 : F.toUpperCase()
33
33
  );
34
34
  }
35
- Object.assign(d, n), m && B ? (await B({
36
- ...d,
37
- [h]: m[h]
38
- }), g(void 0)) : !m && b && await b(d), v(void 0), t.resetFields(), y(!1);
35
+ Object.assign(u, l), f && V ? (await V({
36
+ ...u,
37
+ [h]: f[h]
38
+ }), g(void 0)) : !f && B && await B(u), b(void 0), S(/* @__PURE__ */ new Map()), a.resetFields(), y(!1);
39
39
  },
40
- [c, t, h, b, B, m, a]
41
- ), H = F(async (i) => {
42
- U(i), N(!0);
43
- }, []), I = F(async () => {
44
- N(!0);
45
- }, []), M = F(() => {
46
- y(!0), j("new"), t.resetFields(), g(void 0), v(void 0);
47
- }, [t]), R = F(
48
- async (i, d = !0, l = !1) => {
40
+ [n, a, h, B, V, f, s]
41
+ ), H = m(async (o) => {
42
+ O(o), M(!0);
43
+ }, []), I = m(async () => {
44
+ M(!0);
45
+ }, []), T = m(() => {
46
+ y(!0), w("new"), a.resetFields(), g(void 0), b(void 0);
47
+ }, [a]), [P, S] = c(/* @__PURE__ */ new Map()), Q = ae(() => P.size === 0 ? n : n.map((o) => typeof o.updatable == "function" ? {
48
+ ...o,
49
+ updatable: P.get(v.getRealName(o.name, "name")) ?? o.updatable
50
+ } : o), [n, P]), _ = m(
51
+ async (o, u = !0, i = !1) => {
49
52
  try {
50
- O(!0), y(!0), j(l ? "clone" : "update");
51
- const n = {};
52
- for (const o of c) {
53
- const s = T.getRealName(
54
- o.name,
53
+ W(!0), y(!0), w(i ? "clone" : "update");
54
+ const l = {};
55
+ for (const t of n) {
56
+ const r = v.getRealName(
57
+ t.name,
55
58
  "upsertFieldName"
56
- ), e = ae(i, s);
57
- if (l && o.type === "image") {
58
- const r = e;
59
+ ), e = ue(o, r);
60
+ if (i && t.type === "image") {
61
+ const U = e;
59
62
  try {
60
- const J = await o.provider.clone(r);
61
- p(n, s, J);
63
+ const Y = await t.provider.clone(U);
64
+ d(l, r, Y);
62
65
  continue;
63
66
  } catch {
64
67
  continue;
65
68
  }
66
69
  }
67
- o.type === "date" || o.type === "time" ? e && p(n, s, se(e)) : o.type === "select" ? o.multiple && Array.isArray(e) ? p(n, s, e.map(
68
- (r) => r[o.innerFieldId ?? "id"]
69
- )) : e && typeof e == "object" ? p(n, s, e[o.innerFieldId ?? "id"]) : (e && typeof e == "string" || typeof e == "number") && p(n, s, e) : p(n, s, e);
70
+ t.type === "date" || t.type === "time" ? e && d(l, r, ce(e)) : t.type === "select" ? t.multiple && Array.isArray(e) ? d(
71
+ l,
72
+ r,
73
+ e.map((U) => U[t.innerFieldId ?? "id"])
74
+ ) : e && typeof e == "object" ? d(
75
+ l,
76
+ r,
77
+ e[t.innerFieldId ?? "id"]
78
+ ) : (e && typeof e == "string" || typeof e == "number") && d(l, r, e) : d(l, r, e);
70
79
  }
71
- t.setFieldsValue(n), v(n), d && g(i);
80
+ a.setFieldsValue(l);
81
+ const F = /* @__PURE__ */ new Map();
82
+ for (const t of n)
83
+ typeof t.updatable == "function" && F.set(
84
+ v.getRealName(t.name, "name"),
85
+ t.updatable(o)
86
+ );
87
+ S(F), b(l), u && g(o);
72
88
  } finally {
73
- O(!1);
89
+ W(!1);
74
90
  }
75
91
  },
76
- [c, t]
92
+ [n, a]
77
93
  );
78
- z(
79
- L,
94
+ ne(
95
+ $,
80
96
  () => ({
81
- create: M,
82
- update: R
97
+ create: T,
98
+ update: _
83
99
  }),
84
- [M, R]
85
- ), ee(() => {
86
- V && (U(!1), N(!1));
87
- }, [V]);
88
- const G = F(async () => {
100
+ [T, _]
101
+ ), le(() => {
102
+ k && (O(!1), M(!1));
103
+ }, [k]);
104
+ const X = m(async () => {
105
+ S(/* @__PURE__ */ new Map());
89
106
  try {
90
- if (f === "clone") {
91
- const i = a ? m : t.getFieldsValue(), d = c.filter((l) => l.type === "image");
92
- for (const l of d)
93
- i[l.name] && l.provider.delete(i[l.name]);
107
+ if (p === "clone") {
108
+ const o = s ? f : a.getFieldsValue(), u = n.filter((i) => i.type === "image");
109
+ for (const i of u)
110
+ o[i.name] && i.provider.delete(o[i.name]);
94
111
  }
95
112
  } finally {
96
113
  }
97
- a || t.resetFields(), v(void 0), g(void 0), y(!1);
98
- }, [f, a, t, m, c]);
99
- return /* @__PURE__ */ P(
100
- X,
114
+ s || a.resetFields(), b(void 0), g(void 0), y(!1);
115
+ }, [p, s, a, f, n]);
116
+ return /* @__PURE__ */ x(
117
+ ee,
101
118
  {
102
- width: _ ? "100%" : void 0,
103
- title: k("str." + (f ?? "new")),
104
- open: V,
105
- confirmLoading: S || x,
106
- okText: k("str." + (f === "update" ? "update" : "save")),
107
- cancelText: k("str.cancel"),
119
+ width: L ? "100%" : void 0,
120
+ title: N("str." + (p ?? "new")),
121
+ open: k,
122
+ confirmLoading: C || j,
123
+ okText: N("str." + (p === "update" ? "update" : "save")),
124
+ cancelText: N("str.cancel"),
108
125
  cancelButtonProps: {
109
- disabled: q,
110
- hidden: !!a
126
+ disabled: J,
127
+ hidden: !!s
111
128
  },
112
129
  okButtonProps: {
113
- disabled: $,
114
- hidden: !!a
130
+ disabled: G,
131
+ hidden: !!s
115
132
  },
116
- onCancel: G,
133
+ onCancel: X,
117
134
  onOk: () => D(),
118
135
  destroyOnHidden: !0,
119
- children: /* @__PURE__ */ K(Y, { spinning: w, children: [
120
- a ? null : /* @__PURE__ */ P(
121
- te,
136
+ children: /* @__PURE__ */ Z(te, { spinning: K, children: [
137
+ s ? null : /* @__PURE__ */ x(
138
+ se,
122
139
  {
123
- purpose: f,
124
- fields: c,
125
- form: t,
126
- formBuilder: A,
127
- grid: W,
140
+ purpose: p,
141
+ fields: Q,
142
+ form: a,
143
+ formBuilder: E,
144
+ grid: A,
128
145
  onDeleteFile: I,
129
146
  onUploadFile: H,
130
- onValuesChange: C
147
+ onValuesChange: R
131
148
  }
132
149
  ),
133
- a && /* @__PURE__ */ P(
134
- oe,
150
+ s && /* @__PURE__ */ x(
151
+ ie,
135
152
  {
136
- submitting: S || x,
153
+ submitting: C || j,
137
154
  className: "mt-2",
138
155
  onSave: D,
139
- updatingValue: E,
140
- fields: c,
156
+ updatingValue: q,
157
+ fields: n,
141
158
  onDeleteFile: I,
142
159
  onUploadFile: H,
143
- purpose: f,
144
- wizard: a,
145
- onValuesChange: C
160
+ purpose: p,
161
+ wizard: s,
162
+ onValuesChange: R
146
163
  }
147
164
  )
148
165
  ] })
149
166
  }
150
167
  );
151
- }, ye = Z(le);
168
+ }, Ve = oe(de);
152
169
  export {
153
- ye as default
170
+ Ve as default
154
171
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kingteza/crud-component",
3
3
  "private": false,
4
- "version": "1.29.1",
4
+ "version": "1.30.0",
5
5
  "description": "React CRUD component library with Ant Design",
6
6
  "keywords": [
7
7
  "react",