@kingteza/crud-component 1.0.64 → 1.0.65

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 t=require("react/jsx-runtime"),y=require("antd"),ce=require("dayjs"),n=require("react"),re=require("./CrudForm.cjs.js"),ue=require("./CrudFormWizard.cjs.js"),de=require("./import/CrudImportButton.cjs.js"),fe=require("./view/CrudViewer.cjs.js"),pe=require("../common/button/NewButton.cjs.js"),me=require("../common/button/PrintButton.cjs.js"),Fe=require("../locale/index.cjs.js"),M=require("../util/CrudUtil.cjs.js"),{useForm:ye}=y.Form;function ge({idField:g="id",onCreate:v,onDelete:T,onHide:W,onUpdate:p,fields:i,data:_,grid:A,isHiding:E,isCreating:q,isDeleting:H,isUpdating:N,paginateProps:L,onPrint:V,printing:G,viewable:J,loadingData:K,formBuilder:Q,extraAction:X,minusHeight:Y,cloneable:Z,fullWidthModal:$=!0,wizard:c,extraView:z,importable:P,onClickNew:O,size:ee,...te}){const{t:j}=Fe.useTranslationLib(),[k,x]=n.useState(!1),[m,B]=n.useState(),[se,b]=n.useState(),[r]=ye(),R=n.useCallback(async s=>{const d=c?s:await r.validateFields(),u=i.filter(o=>o.type==="color"),a={};u.forEach(o=>{var f;const l=M.getRealName(o.name,"upsertFieldName"),e=r.getFieldValue(l);a[l]=typeof e=="string"?e:(f=e==null?void 0:e.toHexString())==null?void 0:f.toUpperCase()}),Object.assign(d,a),m&&p?(await p({...d,[g]:m[g]}),B(void 0)):!m&&v&&await v(d),b(void 0),r.resetFields(),x(!1)},[i,r,g,v,p,m,c]),[ne,U]=n.useState(!1),[oe,h]=n.useState(!1);n.useEffect(()=>{k?(U(!1),h(!1)):C(void 0)},[k]);const w=n.useCallback(async s=>{U(s),h(!0)},[]),D=n.useCallback(async()=>{h(!0)},[]),[ae,I]=n.useState(!1),S=n.useCallback(async(s,d=!0,u=!1)=>{try{I(!0),x(!0),d&&C("update");const a={};for(const o of i){const l=M.getRealName(o.name,"upsertFieldName"),e=s[l];if(u&&o.type==="image"){const f=e;try{const ie=await o.provider.clone(f);a[l]=ie;continue}catch{continue}}o.type==="date"?e&&(a[l]=ce(e)):o.type==="select"?o.multiple&&Array.isArray(e)?a[l]=e.map(f=>f[o.innerFieldId??"id"]):e&&typeof e=="object"?a[l]=e[o.innerFieldId??"id"]:(e&&typeof e=="string"||typeof e=="number")&&(a[l]=e):a[l]=e}r.setFieldsValue(a),b(a),d&&B(s)}finally{I(!1)}},[i,r]),[F,C]=n.useState(),le=n.useCallback(async s=>{C("clone"),S(s,!1,!0)},[S]);return t.jsxs(t.Fragment,{children:[t.jsxs(y.Space,{direction:"vertical",className:"w-100",children:[t.jsxs("div",{className:"w-100 d-flex",children:[t.jsx("div",{style:{flex:1},children:t.jsx(pe.NewButton,{onClick:()=>{O?O():(x(s=>!s),C("new"))},className:"flex-1"})}),t.jsxs(y.Space,{children:[!!V&&t.jsx(me.PrintButton,{className:"float-right",loading:G,onClick:V}),!!P&&t.jsx(de,{fields:i,importProps:P})]})]}),t.jsx(fe,{...te,minusHeight:Y,data:_,size:ee,fields:i,extraAction:X,idField:g,isDeleting:H,loadingData:K,onClickUpdate:p?S:void 0,onHide:W,isHiding:E,onDelete:T,onUpdate:p,onClickClone:Z?le:void 0,paginateProps:L,viewable:J,extraView:z})]}),t.jsx(y.Modal,{width:$?"100%":void 0,title:j(F??"new"),open:k,confirmLoading:q||N,okText:j("str."+(F==="update"?"update":"save")),cancelText:j("str.cancel"),cancelButtonProps:{disabled:oe,hidden:!!c},okButtonProps:{disabled:ne,hidden:!!c},onCancel:async()=>{try{if(F==="clone"){const s=c?m:r.getFieldsValue(),d=i.filter(u=>u.type==="image");for(const u of d)s[u.name]&&u.provider.delete(s[u.name])}}finally{}c||r.resetFields(),b(void 0),B(void 0),x(!1)},onOk:()=>R(),destroyOnHidden:!0,children:t.jsxs(y.Spin,{spinning:ae,children:[!c&&t.jsx(re.CrudForm,{purpose:F,fields:i,form:r,formBuilder:Q,grid:A,onDeleteFile:D,onUploadFile:w}),c&&t.jsx(ue,{submitting:q||N,className:"mt-2",onSave:R,updatingValue:se,fields:i,onDeleteFile:D,onUploadFile:w,purpose:F,wizard:c})]})})]})}module.exports=ge;
1
+ "use strict";const e=require("react/jsx-runtime"),l=require("antd"),t=require("react"),H=require("./modal/index.cjs.js"),J=require("./import/CrudImportButton.cjs.js"),K=require("./view/CrudViewer.cjs.js"),L=require("../common/button/NewButton.cjs.js"),M=require("../common/button/PrintButton.cjs.js"),{useForm:Q}=l.Form;function O({idField:a="id",onCreate:C,onDelete:j,onHide:m,onUpdate:n,fields:r,data:f,grid:k,isHiding:q,isCreating:h,isDeleting:p,isUpdating:B,paginateProps:w,onPrint:i,printing:N,viewable:v,loadingData:R,formBuilder:g,extraAction:y,minusHeight:b,cloneable:F,fullWidthModal:P=!0,wizard:S,extraView:I,importable:u,onClickNew:d,size:V,...z}){const c=t.useRef(null),A=t.useCallback(()=>{var s;(s=c.current)==null||s.create()},[]),o=t.useCallback(async(s,E=!0,G=!1)=>{var x;await((x=c.current)==null?void 0:x.update(s,E,G))},[]),D=t.useCallback(async s=>{o(s,!1,!0)},[o]);return e.jsxs(e.Fragment,{children:[e.jsxs(l.Space,{direction:"vertical",className:"w-100",children:[e.jsxs("div",{className:"w-100 d-flex",children:[e.jsx("div",{style:{flex:1},children:e.jsx(L.NewButton,{onClick:()=>{d?d():A()},className:"flex-1"})}),e.jsxs(l.Space,{children:[!!i&&e.jsx(M.PrintButton,{className:"float-right",loading:N,onClick:i}),!!u&&e.jsx(J,{fields:r,importProps:u})]})]}),e.jsx(K,{...z,minusHeight:b,data:f,size:V,fields:r,extraAction:y,idField:a,isDeleting:p,loadingData:R,onClickUpdate:n?o:void 0,onHide:m,isHiding:q,onDelete:j,onUpdate:n,onClickClone:F?D:void 0,paginateProps:w,viewable:v,extraView:I})]}),e.jsx(H,{ref:c,fields:r,wizard:S,grid:k,fullWidthModal:P,isCreating:h,isUpdating:B,onCreate:C,onUpdate:n,idField:a,formBuilder:g})]})}module.exports=O;
@@ -1,212 +1,123 @@
1
- import { jsxs as F, Fragment as de, jsx as d } from "react/jsx-runtime";
2
- import { Form as me, Space as w, Modal as ue, Spin as fe } from "antd";
3
- import pe from "dayjs";
4
- import { useState as m, useCallback as g, useEffect as ye } from "react";
5
- import { CrudForm as Fe } from "./CrudForm.es.js";
6
- import ge from "./CrudFormWizard.es.js";
7
- import ve from "./import/CrudImportButton.es.js";
8
- import Ce from "./view/CrudViewer.es.js";
9
- import { NewButton as Be } from "../common/button/NewButton.es.js";
10
- import { PrintButton as he } from "../common/button/PrintButton.es.js";
11
- import { useTranslationLib as ke } from "../locale/index.es.js";
12
- import A from "../util/CrudUtil.es.js";
13
- const { useForm: be } = me;
14
- function We({
15
- idField: v = "id",
16
- onCreate: h,
17
- onDelete: E,
18
- onHide: H,
19
- onUpdate: f,
20
- fields: i,
21
- data: L,
22
- grid: R,
23
- isHiding: q,
24
- isCreating: P,
25
- isDeleting: G,
26
- isUpdating: j,
27
- paginateProps: J,
28
- onPrint: O,
29
- printing: K,
30
- viewable: Q,
31
- loadingData: X,
32
- formBuilder: Y,
33
- extraAction: Z,
34
- minusHeight: $,
35
- cloneable: z,
36
- fullWidthModal: ee = !0,
37
- wizard: s,
38
- extraView: te,
39
- importable: U,
40
- onClickNew: D,
41
- size: oe,
42
- ...ne
1
+ import { jsxs as e, Fragment as H, jsx as r } from "react/jsx-runtime";
2
+ import { Space as f, Form as J } from "antd";
3
+ import { useRef as K, useCallback as c } from "react";
4
+ import L from "./modal/index.es.js";
5
+ import O from "./import/CrudImportButton.es.js";
6
+ import Q from "./view/CrudViewer.es.js";
7
+ import { NewButton as T } from "../common/button/NewButton.es.js";
8
+ import { PrintButton as U } from "../common/button/PrintButton.es.js";
9
+ const { useForm: eo } = J;
10
+ function to({
11
+ idField: i = "id",
12
+ onCreate: p,
13
+ onDelete: C,
14
+ onHide: h,
15
+ onUpdate: t,
16
+ fields: n,
17
+ data: k,
18
+ grid: x,
19
+ isHiding: v,
20
+ isCreating: w,
21
+ isDeleting: B,
22
+ isUpdating: N,
23
+ paginateProps: g,
24
+ onPrint: m,
25
+ printing: y,
26
+ viewable: j,
27
+ loadingData: F,
28
+ formBuilder: R,
29
+ extraAction: I,
30
+ minusHeight: M,
31
+ cloneable: P,
32
+ fullWidthModal: S = !0,
33
+ wizard: V,
34
+ extraView: b,
35
+ importable: s,
36
+ onClickNew: u,
37
+ size: q,
38
+ ...z
43
39
  }) {
44
- const { t: k } = ke(), [b, C] = m(!1), [p, N] = m(), [le, x] = m(), [a] = be(), I = g(
45
- async (t) => {
46
- const c = s ? t : await a.validateFields(), r = i.filter((o) => o.type === "color"), n = {};
47
- r.forEach((o) => {
48
- var u;
49
- const l = A.getRealName(o.name, "upsertFieldName"), e = a.getFieldValue(l);
50
- n[l] = typeof e == "string" ? e : (u = e == null ? void 0 : e.toHexString()) == null ? void 0 : u.toUpperCase();
51
- }), Object.assign(c, n), p && f ? (await f({
52
- ...c,
53
- [v]: p[v]
54
- }), N(void 0)) : !p && h && await h(c), x(void 0), a.resetFields(), C(!1);
40
+ const l = K(null), A = c(() => {
41
+ var o;
42
+ (o = l.current) == null || o.create();
43
+ }, []), a = c(
44
+ async (o, E = !0, G = !1) => {
45
+ var d;
46
+ await ((d = l.current) == null ? void 0 : d.update(o, E, G));
55
47
  },
56
- [i, a, v, h, f, p, s]
57
- ), [ie, M] = m(!1), [se, V] = m(!1);
58
- ye(() => {
59
- b ? (M(!1), V(!1)) : B(void 0);
60
- }, [b]);
61
- const T = g(async (t) => {
62
- M(t), V(!0);
63
- }, []), W = g(async () => {
64
- V(!0);
65
- }, []), [ae, _] = m(!1), S = g(
66
- async (t, c = !0, r = !1) => {
67
- try {
68
- _(!0), C(!0), c && B("update");
69
- const n = {};
70
- for (const o of i) {
71
- const l = A.getRealName(o.name, "upsertFieldName"), e = t[l];
72
- if (r && o.type === "image") {
73
- const u = e;
74
- try {
75
- const ce = await o.provider.clone(u);
76
- n[l] = ce;
77
- continue;
78
- } catch {
79
- continue;
80
- }
81
- }
82
- o.type === "date" ? e && (n[l] = pe(e)) : o.type === "select" ? o.multiple && Array.isArray(e) ? n[l] = e.map(
83
- (u) => u[o.innerFieldId ?? "id"]
84
- ) : e && typeof e == "object" ? n[l] = e[o.innerFieldId ?? "id"] : (e && typeof e == "string" || typeof e == "number") && (n[l] = e) : n[l] = e;
85
- }
86
- a.setFieldsValue(n), x(n), c && N(t);
87
- } finally {
88
- _(!1);
89
- }
48
+ []
49
+ ), D = c(
50
+ async (o) => {
51
+ a(o, !1, !0);
90
52
  },
91
- [i, a]
92
- ), [y, B] = m(), re = g(
93
- async (t) => {
94
- B("clone"), S(t, !1, !0);
95
- },
96
- [S]
53
+ [a]
97
54
  );
98
- return /* @__PURE__ */ F(de, { children: [
99
- /* @__PURE__ */ F(w, { direction: "vertical", className: "w-100", children: [
100
- /* @__PURE__ */ F("div", { className: "w-100 d-flex", children: [
101
- /* @__PURE__ */ d("div", { style: { flex: 1 }, children: /* @__PURE__ */ d(
102
- Be,
55
+ return /* @__PURE__ */ e(H, { children: [
56
+ /* @__PURE__ */ e(f, { direction: "vertical", className: "w-100", children: [
57
+ /* @__PURE__ */ e("div", { className: "w-100 d-flex", children: [
58
+ /* @__PURE__ */ r("div", { style: { flex: 1 }, children: /* @__PURE__ */ r(
59
+ T,
103
60
  {
104
61
  onClick: () => {
105
- D ? D() : (C((t) => !t), B("new"));
62
+ u ? u() : A();
106
63
  },
107
64
  className: "flex-1"
108
65
  }
109
66
  ) }),
110
- /* @__PURE__ */ F(w, { children: [
111
- !!O && /* @__PURE__ */ d(
112
- he,
67
+ /* @__PURE__ */ e(f, { children: [
68
+ !!m && /* @__PURE__ */ r(
69
+ U,
113
70
  {
114
71
  className: "float-right",
115
- loading: K,
116
- onClick: O
72
+ loading: y,
73
+ onClick: m
117
74
  }
118
75
  ),
119
- !!U && /* @__PURE__ */ d(ve, { fields: i, importProps: U })
76
+ !!s && /* @__PURE__ */ r(O, { fields: n, importProps: s })
120
77
  ] })
121
78
  ] }),
122
- /* @__PURE__ */ d(
123
- Ce,
79
+ /* @__PURE__ */ r(
80
+ Q,
124
81
  {
125
- ...ne,
126
- minusHeight: $,
127
- data: L,
128
- size: oe,
129
- fields: i,
130
- extraAction: Z,
131
- idField: v,
132
- isDeleting: G,
133
- loadingData: X,
134
- onClickUpdate: f ? S : void 0,
135
- onHide: H,
136
- isHiding: q,
137
- onDelete: E,
138
- onUpdate: f,
139
- onClickClone: z ? re : void 0,
140
- paginateProps: J,
141
- viewable: Q,
142
- extraView: te
82
+ ...z,
83
+ minusHeight: M,
84
+ data: k,
85
+ size: q,
86
+ fields: n,
87
+ extraAction: I,
88
+ idField: i,
89
+ isDeleting: B,
90
+ loadingData: F,
91
+ onClickUpdate: t ? a : void 0,
92
+ onHide: h,
93
+ isHiding: v,
94
+ onDelete: C,
95
+ onUpdate: t,
96
+ onClickClone: P ? D : void 0,
97
+ paginateProps: g,
98
+ viewable: j,
99
+ extraView: b
143
100
  }
144
101
  )
145
102
  ] }),
146
- /* @__PURE__ */ d(
147
- ue,
103
+ /* @__PURE__ */ r(
104
+ L,
148
105
  {
149
- width: ee ? "100%" : void 0,
150
- title: k(y ?? "new"),
151
- open: b,
152
- confirmLoading: P || j,
153
- okText: k("str." + (y === "update" ? "update" : "save")),
154
- cancelText: k("str.cancel"),
155
- cancelButtonProps: {
156
- disabled: se,
157
- hidden: !!s
158
- },
159
- okButtonProps: {
160
- disabled: ie,
161
- hidden: !!s
162
- },
163
- onCancel: async () => {
164
- try {
165
- if (y === "clone") {
166
- const t = s ? p : a.getFieldsValue(), c = i.filter((r) => r.type === "image");
167
- for (const r of c)
168
- t[r.name] && r.provider.delete(
169
- t[r.name]
170
- );
171
- }
172
- } finally {
173
- }
174
- s || a.resetFields(), x(void 0), N(void 0), C(!1);
175
- },
176
- onOk: () => I(),
177
- destroyOnHidden: !0,
178
- children: /* @__PURE__ */ F(fe, { spinning: ae, children: [
179
- !s && /* @__PURE__ */ d(
180
- Fe,
181
- {
182
- purpose: y,
183
- fields: i,
184
- form: a,
185
- formBuilder: Y,
186
- grid: R,
187
- onDeleteFile: W,
188
- onUploadFile: T
189
- }
190
- ),
191
- s && /* @__PURE__ */ d(
192
- ge,
193
- {
194
- submitting: P || j,
195
- className: "mt-2",
196
- onSave: I,
197
- updatingValue: le,
198
- fields: i,
199
- onDeleteFile: W,
200
- onUploadFile: T,
201
- purpose: y,
202
- wizard: s
203
- }
204
- )
205
- ] })
106
+ ref: l,
107
+ fields: n,
108
+ wizard: V,
109
+ grid: x,
110
+ fullWidthModal: S,
111
+ isCreating: w,
112
+ isUpdating: N,
113
+ onCreate: p,
114
+ onUpdate: t,
115
+ idField: i,
116
+ formBuilder: R
206
117
  }
207
118
  )
208
119
  ] });
209
120
  }
210
121
  export {
211
- We as default
122
+ to as default
212
123
  };
@@ -0,0 +1 @@
1
+ "use strict";const v=require("react/jsx-runtime"),W=require("react"),$=require("../../common/button/CloneButtonTable.cjs.js"),w=require("../../common/button/DeleteButtonTable.cjs.js"),A=require("../../common/button/ExportButton.cjs.js"),H=require("../../common/button/HideButtonTable.cjs.js"),V=require("../../common/button/UpdateButtonTable.cjs.js"),c=require("../modal/index.cjs.js");function k({data:b,idField:j="id",extraAction:h,onUpdate:r,onClickUpdate:x,onClickClone:y,onDelete:s,onHide:g,onExport:E,isHiding:z,isDeleting:G,confirmHiding:X,confirmDeleting:Y,closeViewOnClickUpdate:Z,recentUpdateOrDeleteId:J,setRecentUpdateOrDeleteId:q,setOpenView:T,inBuiltModalProps:f}){var N;const m=h==null?void 0:h(b),K=W.useRef(null),L=W.useCallback((u,_=!0,Q=!1)=>{var S;q==null||q(u[j]),f?(S=K.current)==null||S.update(u,_,Q):Q?y==null||y(u):x==null||x(u),Z&&(T==null||T(void 0))},[f,x]);return(Array.isArray(m)?(N=m==null?void 0:m.filter(Boolean))!=null&&N.length:m)||r||x||y||s?v.jsxs(v.Fragment,{children:[f&&v.jsx(c,{ref:K,...f}),m,(r||x||(f==null?void 0:f.onUpdate))&&v.jsx(V,{value:b,onClick:u=>L(u)}),(y||(f==null?void 0:f.onCreate))&&v.jsx($,{value:b,onClick:u=>L(u,!1,!0)}),E&&v.jsx(A.ExportButton,{value:b,onClick:async u=>await E(u)}),g&&v.jsx(H,{value:b,disabled:z,shouldConfirm:X,loading:z&&b[j]===J,onClick:async u=>{q==null||q(u[j]),await g({[j]:u[j]})}}),s&&v.jsx(w,{value:b,disabled:G,shouldConfirm:Y,loading:G&&b[j]===J,onClick:async u=>{q==null||q(u[j]),await s({[j]:u[j]})}})]}):void 0}module.exports=k;
@@ -0,0 +1,26 @@
1
+ import { ReactElement } from 'react';
2
+ import { default as IdProps } from '../../types/Id';
3
+ import { CrudModalProps } from '../modal';
4
+ export interface CrudActionsProps<T, FormType> {
5
+ idField?: string;
6
+ extraAction?: (t: T) => ReactElement | undefined | ReactElement[];
7
+ onUpdate?: (t: FormType & IdProps) => Promise<any>;
8
+ onClickUpdate?: (t: T) => void;
9
+ onClickClone?: (t: T) => Promise<any>;
10
+ onDelete?: (id: any) => Promise<any>;
11
+ onHide?: (id: any) => Promise<any>;
12
+ onExport?: (t: T) => Promise<any>;
13
+ isHiding?: boolean;
14
+ isDeleting?: boolean;
15
+ confirmHiding?: boolean;
16
+ confirmDeleting?: boolean;
17
+ closeViewOnClickUpdate?: boolean;
18
+ recentUpdateOrDeleteId?: string;
19
+ setRecentUpdateOrDeleteId?: (id: string) => void;
20
+ setOpenView?: (data: T | undefined) => void;
21
+ inBuiltModalProps?: CrudModalProps<T, FormType>;
22
+ }
23
+ declare function CrudActions<T, FormType>({ data, idField, extraAction, onUpdate, onClickUpdate, onClickClone, onDelete, onHide, onExport, isHiding, isDeleting, confirmHiding, confirmDeleting, closeViewOnClickUpdate, recentUpdateOrDeleteId, setRecentUpdateOrDeleteId, setOpenView, inBuiltModalProps, }: CrudActionsProps<T, FormType> & {
24
+ data: T;
25
+ }): import("react/jsx-runtime").JSX.Element | undefined;
26
+ export default CrudActions;
@@ -0,0 +1,83 @@
1
+ import { jsxs as w, Fragment as A, jsx as T } from "react/jsx-runtime";
2
+ import { useRef as H, useCallback as x } from "react";
3
+ import V from "../../common/button/CloneButtonTable.es.js";
4
+ import k from "../../common/button/DeleteButtonTable.es.js";
5
+ import { ExportButton as o } from "../../common/button/ExportButton.es.js";
6
+ import B from "../../common/button/HideButtonTable.es.js";
7
+ import C from "../../common/button/UpdateButtonTable.es.js";
8
+ import F from "../modal/index.es.js";
9
+ function O({
10
+ data: v,
11
+ idField: u = "id",
12
+ extraAction: j,
13
+ onUpdate: z,
14
+ onClickUpdate: y,
15
+ onClickClone: g,
16
+ onDelete: r,
17
+ onHide: E,
18
+ onExport: G,
19
+ isHiding: J,
20
+ isDeleting: K,
21
+ confirmHiding: Y,
22
+ confirmDeleting: Z,
23
+ closeViewOnClickUpdate: _,
24
+ recentUpdateOrDeleteId: L,
25
+ setRecentUpdateOrDeleteId: b,
26
+ setOpenView: q,
27
+ inBuiltModalProps: m
28
+ }) {
29
+ var S;
30
+ const h = j == null ? void 0 : j(v), N = H(null), Q = x(
31
+ (f, $ = !0, W = !1) => {
32
+ var X;
33
+ b == null || b(f[u]), m ? (X = N.current) == null || X.update(f, $, W) : W ? g == null || g(f) : y == null || y(f), _ && (q == null || q(void 0));
34
+ },
35
+ [m, y]
36
+ );
37
+ return (Array.isArray(h) ? (S = h == null ? void 0 : h.filter(Boolean)) != null && S.length : h) || z || y || g || r ? /* @__PURE__ */ w(A, { children: [
38
+ m && /* @__PURE__ */ T(F, { ref: N, ...m }),
39
+ h,
40
+ (z || y || (m == null ? void 0 : m.onUpdate)) && /* @__PURE__ */ T(C, { value: v, onClick: (f) => Q(f) }),
41
+ (g || (m == null ? void 0 : m.onCreate)) && /* @__PURE__ */ T(
42
+ V,
43
+ {
44
+ value: v,
45
+ onClick: (f) => Q(f, !1, !0)
46
+ }
47
+ ),
48
+ G && /* @__PURE__ */ T(
49
+ o,
50
+ {
51
+ value: v,
52
+ onClick: async (f) => await G(f)
53
+ }
54
+ ),
55
+ E && /* @__PURE__ */ T(
56
+ B,
57
+ {
58
+ value: v,
59
+ disabled: J,
60
+ shouldConfirm: Y,
61
+ loading: J && v[u] === L,
62
+ onClick: async (f) => {
63
+ b == null || b(f[u]), await E({ [u]: f[u] });
64
+ }
65
+ }
66
+ ),
67
+ r && /* @__PURE__ */ T(
68
+ k,
69
+ {
70
+ value: v,
71
+ disabled: K,
72
+ shouldConfirm: Z,
73
+ loading: K && v[u] === L,
74
+ onClick: async (f) => {
75
+ b == null || b(f[u]), await r({ [u]: f[u] });
76
+ }
77
+ }
78
+ )
79
+ ] }) : void 0;
80
+ }
81
+ export {
82
+ O as default
83
+ };
package/crud/index.d.ts CHANGED
@@ -16,4 +16,8 @@ export type { FileCrudField as FileCrudFieldProps } from './FileCrudField';
16
16
  export { default as CrudImportComponent } from './import/CrudImportComponent';
17
17
  export type { CrudImportComponentProps, CrudImportProps, } from './import/CrudImportComponent';
18
18
  export { default as CrudImportButton } from './import/CrudImportButton';
19
+ export { default as CrudActions } from './actions';
20
+ export type { CrudActionsProps } from './actions';
21
+ export { default as CrudModal } from './modal';
22
+ export type { CrudModalProps, CrudModalRef } from './modal';
19
23
  export * from './view';
@@ -0,0 +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 o;const d=l?c:await s.validateFields(),i=u.filter(a=>a.type==="color"),n={};for(const a of i){const e=H.getRealName(a.name,"upsertFieldName"),r=s.getFieldValue(e);n[e]=typeof r=="string"?r:(o=r==null?void 0:r.toHexString())==null?void 0:o.toUpperCase()}Object.assign(d,n),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 n={};for(const o of u){const a=H.getRealName(o.name,"upsertFieldName"),e=c[a];if(i&&o.type==="image"){const r=e;try{const w=await o.provider.clone(r);n[a]=w;continue}catch{continue}}o.type==="date"?e&&(n[a]=Q(e)):o.type==="select"?o.multiple&&Array.isArray(e)?n[a]=e.map(r=>r[o.innerFieldId??"id"]):e&&typeof e=="object"?n[a]=e[o.innerFieldId??"id"]:(e&&typeof e=="string"||typeof e=="number")&&(n[a]=e):n[a]=e}s.setFieldsValue(n),y(n),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;
@@ -0,0 +1,24 @@
1
+ import { Ref } from 'react';
2
+ import { CrudFieldProps, CrudWizardProp, FormBuilderFunc } from '../CrudComponent';
3
+ import { default as IdProps } from '../../types/Id';
4
+ export interface CrudModalProps<T, FormType> {
5
+ fields: CrudFieldProps<T>[];
6
+ wizard?: CrudWizardProp<T>[];
7
+ grid?: boolean;
8
+ fullWidthModal?: boolean;
9
+ isCreating?: boolean;
10
+ isUpdating?: boolean;
11
+ onCreate?: (data: FormType) => Promise<any>;
12
+ onUpdate?: (data: FormType & IdProps) => Promise<any>;
13
+ idField?: string;
14
+ formBuilder?: FormBuilderFunc<T>;
15
+ }
16
+ export interface CrudModalRef<T> {
17
+ create: () => void;
18
+ update: (data: T, shouldSetUpdatingField?: boolean, isClone?: boolean) => Promise<void>;
19
+ }
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;
21
+ declare const _default: <T, FormType = T>(props: CrudModalProps<T, FormType> & {
22
+ ref?: Ref<CrudModalRef<T>>;
23
+ }) => ReturnType<typeof CrudModal>;
24
+ export default _default;
@@ -0,0 +1,146 @@
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 = ({
10
+ fields: c,
11
+ wizard: l,
12
+ grid: R,
13
+ fullWidthModal: T,
14
+ isCreating: S,
15
+ isUpdating: V,
16
+ onCreate: v,
17
+ onUpdate: b,
18
+ idField: B = "id",
19
+ formBuilder: W
20
+ }, _) => {
21
+ const [t] = J.useForm(), { t: h } = te(), [k, F] = u(!1), [f, x] = u("new"), [p, y] = u(), [A, g] = u(), [L, j] = u(!1), [E, C] = u(!1), [$, P] = u(!1), U = m(
22
+ async (i) => {
23
+ var n;
24
+ const d = l ? i : await t.validateFields(), a = c.filter((s) => s.type === "color"), o = {};
25
+ for (const s of a) {
26
+ const e = M.getRealName(s.name, "upsertFieldName"), r = t.getFieldValue(e);
27
+ o[e] = typeof r == "string" ? r : (n = r == null ? void 0 : r.toHexString()) == null ? void 0 : n.toUpperCase();
28
+ }
29
+ Object.assign(d, o), p && b ? (await b({
30
+ ...d,
31
+ [B]: p[B]
32
+ }), y(void 0)) : !p && v && await v(d), g(void 0), t.resetFields(), F(!1);
33
+ },
34
+ [c, t, B, v, b, p, 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(
42
+ async (i, d = !0, a = !1) => {
43
+ try {
44
+ P(!0), F(!0), x(a ? "clone" : "update");
45
+ const o = {};
46
+ for (const n of c) {
47
+ const s = M.getRealName(
48
+ n.name,
49
+ "upsertFieldName"
50
+ ), e = i[s];
51
+ if (a && n.type === "image") {
52
+ const r = e;
53
+ try {
54
+ const w = await n.provider.clone(r);
55
+ o[s] = w;
56
+ continue;
57
+ } catch {
58
+ continue;
59
+ }
60
+ }
61
+ n.type === "date" ? e && (o[s] = oe(e)) : n.type === "select" ? n.multiple && Array.isArray(e) ? o[s] = e.map(
62
+ (r) => r[n.innerFieldId ?? "id"]
63
+ ) : e && typeof e == "object" ? o[s] = e[n.innerFieldId ?? "id"] : (e && typeof e == "string" || typeof e == "number") && (o[s] = e) : o[s] = e;
64
+ }
65
+ t.setFieldsValue(o), g(o), d && y(i);
66
+ } finally {
67
+ P(!1);
68
+ }
69
+ },
70
+ [c, t]
71
+ );
72
+ Y(
73
+ _,
74
+ () => ({
75
+ create: H,
76
+ update: I
77
+ }),
78
+ [H, I]
79
+ ), Z(() => {
80
+ k && (j(!1), C(!1));
81
+ }, [k]);
82
+ const q = m(async () => {
83
+ try {
84
+ if (f === "clone") {
85
+ const i = l ? p : t.getFieldsValue(), d = c.filter((a) => a.type === "image");
86
+ for (const a of d)
87
+ i[a.name] && a.provider.delete(i[a.name]);
88
+ }
89
+ } finally {
90
+ }
91
+ l || t.resetFields(), g(void 0), y(void 0), F(!1);
92
+ }, [f, l, t, p, c]);
93
+ return /* @__PURE__ */ N(
94
+ K,
95
+ {
96
+ width: T ? "100%" : void 0,
97
+ title: h(f ?? "new"),
98
+ open: k,
99
+ confirmLoading: S || V,
100
+ okText: h("str." + (f === "update" ? "update" : "save")),
101
+ cancelText: h("str.cancel"),
102
+ cancelButtonProps: {
103
+ disabled: E,
104
+ hidden: !!l
105
+ },
106
+ okButtonProps: {
107
+ disabled: L,
108
+ hidden: !!l
109
+ },
110
+ onCancel: q,
111
+ onOk: () => U(),
112
+ destroyOnHidden: !0,
113
+ children: /* @__PURE__ */ G(Q, { spinning: $, children: [
114
+ l ? null : /* @__PURE__ */ N(
115
+ z,
116
+ {
117
+ purpose: f,
118
+ fields: c,
119
+ form: t,
120
+ formBuilder: W,
121
+ grid: R,
122
+ onDeleteFile: D,
123
+ onUploadFile: O
124
+ }
125
+ ),
126
+ l && /* @__PURE__ */ N(
127
+ ee,
128
+ {
129
+ submitting: S || V,
130
+ className: "mt-2",
131
+ onSave: U,
132
+ updatingValue: A,
133
+ fields: c,
134
+ onDeleteFile: D,
135
+ onUploadFile: O,
136
+ purpose: f,
137
+ wizard: l
138
+ }
139
+ )
140
+ ] })
141
+ }
142
+ );
143
+ }, fe = X(ne);
144
+ export {
145
+ fe as default
146
+ };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),q=require("../../common/description/DescList.cjs.js"),f=require("react"),x=require("../../locale/index.cjs.js"),C=require("./CrudViewerUtil.cjs.js"),V=require("../../util/CrudUtil.cjs.js");function j({className:o,fields:s,data:e,descListColumn:c={xs:1,md:3,sm:2,lg:4},layout:m,action:t,keepEmptyValues:b}){const{t:n}=x.useTranslationLib(),g=f.useMemo(()=>{const l=s.filter(({hidden:r,hideInDescList:u})=>!r&&!u).map((r,u)=>{const d=V.getRealName(r.name);return{label:r.label,noFormatting:!0,value:C.getRendererValueCrudViewer(r)(e==null?void 0:e[d],e,u)}});return t&&l.push({label:n("str.action"),value:t}),l},[t,e,s,n]);return e?i.jsx(q,{keepEmptyValues:b,bordered:!0,column:c,className:o,layout:m,list:g}):i.jsx(i.Fragment,{})}exports.CrudDecListView=j;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),d=require("../../common/description/DescList.cjs.js"),f=require("react"),j=require("../../locale/index.cjs.js"),V=require("./CrudViewerUtil.cjs.js"),p=require("../../util/CrudUtil.cjs.js"),v=require("../actions/index.cjs.js");function w({className:c,fields:n,data:e,descListColumn:m={xs:1,md:3,sm:2,lg:4},layout:b,keepEmptyValues:g,inBuiltModalProps:q,...s}){const{t:u}=j.useTranslationLib(),x=f.useMemo(()=>{const o=n.filter(({hidden:r,hideInDescList:i})=>!r&&!i).map((r,i)=>{const C=p.getRealName(r.name);return{label:r.label,noFormatting:!0,value:V.getRendererValueCrudViewer(r)(e==null?void 0:e[C],e,i)}}),l=e?t.jsx(v,{data:e,...s,inBuiltModalProps:q}):void 0;return l&&o.push({label:u("str.action"),value:l}),o},[e,n,u,s]);return e?t.jsx(d,{keepEmptyValues:g,bordered:!0,column:m,className:c,layout:b,list:x}):t.jsx(t.Fragment,{})}exports.CrudDecListView=w;