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