@kingteza/crud-component 1.0.56 → 1.0.57

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,70 +1,71 @@
1
1
  import { jsxs as f, jsx as s, Fragment as O } from "react/jsx-runtime";
2
2
  /* empty css */
3
- import { FileOutlined as J, FilePptOutlined as K, FileExcelOutlined as Q, FileTextOutlined as R, FileWordOutlined as X, FilePdfOutlined as Y, FileImageOutlined as Z, ExportOutlined as v } from "@ant-design/icons";
4
- import { Form as P, Upload as y, Modal as m } from "antd";
3
+ import { FileOutlined as J, FilePptOutlined as K, FileExcelOutlined as Q, FileTextOutlined as X, FileWordOutlined as Y, FilePdfOutlined as Z, FileImageOutlined as v, ExportOutlined as y } from "@ant-design/icons";
4
+ import { Form as P, Upload as m, Modal as T } from "antd";
5
5
  import S from "mime";
6
- import { useState as p, useCallback as j, useEffect as A, useMemo as N } from "react";
7
- import { useTranslationLib as T } from "../locale/index.es.js";
8
- import tt from "../util/ValidationUtil.es.js";
6
+ import { useState as p, useCallback as $, useEffect as A, useMemo as j } from "react";
7
+ import { useTranslationLib as tt } from "../locale/index.es.js";
8
+ import et from "../util/ValidationUtil.es.js";
9
9
  import C from "../common/button/Button.es.js";
10
- import et from "../common/layout/VerticalSpace.es.js";
11
- function ht({
10
+ import st from "../common/layout/VerticalSpace.es.js";
11
+ import rt from "../util/CrudUtil.es.js";
12
+ function wt({
12
13
  name: n,
13
14
  label: t,
14
- required: l,
15
+ required: r,
15
16
  provider: e,
16
17
  onUploading: a,
17
18
  onRemoved: u,
18
- fieldClassName: w,
19
+ fieldClassName: F,
19
20
  accept: b,
20
21
  rules: H,
21
22
  maxCount: I = 1,
22
23
  block: L,
23
24
  ...W
24
25
  }) {
25
- const d = P.useFormInstance(), h = P.useWatch(n, d), [V, D] = p(!1), [U, _] = p(!1), q = j(
26
- async (r) => {
26
+ const d = P.useFormInstance(), _ = rt.getRealName(n, "upsertFieldName"), h = P.useWatch(_, d), [V, D] = p(!1), [N, q] = p(!1), B = $(
27
+ async (l) => {
27
28
  var c, i;
28
29
  try {
29
- const { file: o } = r, x = o.name;
30
- D(!0), _(!0), a == null || a(!0);
31
- const g = x ?? "", E = g.split("."), z = E[E.length - 1], G = e.generateFileName(g), M = `${await e.getInitialPath()}/${G}.${z}`;
32
- console.log({ filePath: M });
33
- const $ = await e.upload(
30
+ const { file: o } = l, g = o.name;
31
+ D(!0), q(!0), a == null || a(!0);
32
+ const x = g ?? "", k = x.split("."), z = k[k.length - 1], G = e.generateFileName(x), E = `${await e.getInitialPath()}/${G}.${z}`;
33
+ console.log({ filePath: E });
34
+ const M = await e.upload(
34
35
  { ...o, originFileObj: o },
35
- M
36
+ E
36
37
  );
37
- a == null || a(!1), d.setFieldValue(n, $), (c = r.onSuccess) == null || c.call(r, $);
38
+ a == null || a(!1), d.setFieldValue(n, M), (c = l.onSuccess) == null || c.call(l, M);
38
39
  } catch (o) {
39
- (i = r.onError) == null || i.call(r, o);
40
+ (i = l.onError) == null || i.call(l, o);
40
41
  } finally {
41
42
  D(!1);
42
43
  }
43
44
  },
44
45
  [d, n, a, e]
45
- ), [F, k] = p([]);
46
+ ), [w, U] = p([]);
46
47
  A(() => {
47
- !U && h && Promise.all(
48
+ !N && h && Promise.all(
48
49
  (Array.isArray(h) ? h : [h]).map(
49
- async (r) => {
50
- const c = S.getType(r), i = r.split("/").pop(), o = await e.getRealUrl(r);
50
+ async (l) => {
51
+ const c = S.getType(l), i = l.split("/").pop(), o = await e.getRealUrl(l);
51
52
  return {
52
- uid: r,
53
+ uid: l,
53
54
  url: o,
54
55
  type: c,
55
56
  name: i
56
57
  };
57
58
  }
58
59
  )
59
- ).then((r) => k(() => {
60
- const c = r.map(({ url: i, type: o, uid: x, name: g }) => ({ uid: x, url: i, type: o, response: x, thumbUrl: i, name: g }));
60
+ ).then((l) => U(() => {
61
+ const c = l.map(({ url: i, type: o, uid: g, name: x }) => ({ uid: g, url: i, type: o, response: g, thumbUrl: i, name: x }));
61
62
  return console.log(c), c;
62
63
  }));
63
- }, [h, U, V, e]);
64
- const B = j(
65
- async (r) => {
66
- const c = r.response, i = c || d.getFieldValue(n);
67
- await e.delete(i), u == null || u(), r && d.setFieldsValue({ [n]: null });
64
+ }, [h, N, V, e]);
65
+ const R = $(
66
+ async (l) => {
67
+ const c = l.response, i = c || d.getFieldValue(n);
68
+ await e.delete(i), u == null || u(), l && d.setFieldsValue({ [n]: null });
68
69
  },
69
70
  [d, n, u, e]
70
71
  );
@@ -72,27 +73,27 @@ function ht({
72
73
  P.Item,
73
74
  {
74
75
  label: t,
75
- required: l,
76
+ required: r,
76
77
  name: n,
77
- className: w,
78
+ className: F,
78
79
  rules: [
79
- ...l ? tt.required(t) : [],
80
+ ...r ? et.required(t) : [],
80
81
  ...H ?? []
81
82
  ],
82
83
  children: [
83
84
  /* @__PURE__ */ s("input", { hidden: !0 }),
84
85
  /* @__PURE__ */ s(
85
- y,
86
+ m,
86
87
  {
87
88
  ...W,
88
- fileList: F,
89
- className: ((F == null ? void 0 : F.length) ?? 0) >= I ? "hide-upload" : "",
89
+ fileList: w,
90
+ className: ((w == null ? void 0 : w.length) ?? 0) >= I ? "hide-upload" : "",
90
91
  maxCount: I,
91
- customRequest: q,
92
- onRemove: B,
92
+ customRequest: B,
93
+ onRemove: R,
93
94
  listType: "picture",
94
- onChange: ({ fileList: r }) => {
95
- k(r);
95
+ onChange: ({ fileList: l }) => {
96
+ U(l);
96
97
  },
97
98
  style: L ? { width: "100%" } : void 0,
98
99
  children: /* @__PURE__ */ s(C, { loading: V, children: "Upload File" })
@@ -102,8 +103,8 @@ function ht({
102
103
  }
103
104
  );
104
105
  }
105
- const pt = ({ provider: n, value: t }) => {
106
- const [l, e] = p();
106
+ const gt = ({ provider: n, value: t }) => {
107
+ const [r, e] = p();
107
108
  return A(() => {
108
109
  t && n.getRealUrl(t).then((a) => {
109
110
  e({
@@ -112,25 +113,25 @@ const pt = ({ provider: n, value: t }) => {
112
113
  fileName: t.split("/").pop() ?? t
113
114
  });
114
115
  });
115
- }, [n, t]), l ? /* @__PURE__ */ s(
116
- st,
116
+ }, [n, t]), r ? /* @__PURE__ */ s(
117
+ lt,
117
118
  {
118
- fileName: l.fileName,
119
- url: l == null ? void 0 : l.url,
120
- mimeType: l == null ? void 0 : l.mimeType
119
+ fileName: r.fileName,
120
+ url: r == null ? void 0 : r.url,
121
+ mimeType: r == null ? void 0 : r.mimeType
121
122
  }
122
123
  ) : /* @__PURE__ */ s(O, {});
123
- }, st = ({ url: n, mimeType: t = "", fileName: l }) => {
124
- const e = N(() => t != null && t.includes("image") ? "image" : t != null && t.includes("pdf") ? "pdf" : t != null && t.includes("word") ? "word" : t != null && t.includes("text") ? "text" : t != null && t.includes("presentation") ? "presentation" : t != null && t.includes("excel") || t != null && t.includes("spreadsheet") ? "excel" : "file", [t]), a = N(() => {
124
+ }, lt = ({ url: n, mimeType: t = "", fileName: r }) => {
125
+ const e = j(() => t != null && t.includes("image") ? "image" : t != null && t.includes("pdf") ? "pdf" : t != null && t.includes("word") ? "word" : t != null && t.includes("text") ? "text" : t != null && t.includes("presentation") ? "presentation" : t != null && t.includes("excel") || t != null && t.includes("spreadsheet") ? "excel" : "file", [t]), a = j(() => {
125
126
  switch (e) {
126
127
  case "image":
127
- return /* @__PURE__ */ s(Z, {});
128
+ return /* @__PURE__ */ s(v, {});
128
129
  case "pdf":
129
- return /* @__PURE__ */ s(Y, {});
130
+ return /* @__PURE__ */ s(Z, {});
130
131
  case "word":
131
- return /* @__PURE__ */ s(X, {});
132
+ return /* @__PURE__ */ s(Y, {});
132
133
  case "text":
133
- return /* @__PURE__ */ s(R, {});
134
+ return /* @__PURE__ */ s(X, {});
134
135
  case "excel":
135
136
  return /* @__PURE__ */ s(Q, {});
136
137
  case "presentation":
@@ -138,37 +139,37 @@ const pt = ({ provider: n, value: t }) => {
138
139
  default:
139
140
  return /* @__PURE__ */ s(J, {});
140
141
  }
141
- }, [e]), [u, w] = p(!1), { t: b } = T();
142
+ }, [e]), [u, F] = p(!1), { t: b } = tt();
142
143
  return e !== "file" && e !== "text" ? /* @__PURE__ */ f(O, { children: [
143
144
  /* @__PURE__ */ s(
144
- m,
145
+ T,
145
146
  {
146
147
  open: u,
147
- title: l,
148
- onCancel: () => w(!1),
148
+ title: r,
149
+ onCancel: () => F(!1),
149
150
  footer: /* @__PURE__ */ s(O, {}),
150
151
  width: "100%",
151
152
  style: { top: "8px", minHeight: "700px" },
152
153
  destroyOnHidden: !0,
153
- children: /* @__PURE__ */ f(et, { children: [
154
+ children: /* @__PURE__ */ f(st, { children: [
154
155
  /* @__PURE__ */ s(
155
156
  C,
156
157
  {
157
- tooltip: l,
158
- icon: /* @__PURE__ */ s(v, {}),
158
+ tooltip: r,
159
+ icon: /* @__PURE__ */ s(y, {}),
159
160
  target: "_blank",
160
161
  href: n,
161
162
  style: { textDecoration: "none" },
162
163
  children: b("str.openInNewTab")
163
164
  }
164
165
  ),
165
- e === "image" ? /* @__PURE__ */ s("img", { src: n, alt: l, style: { width: "100%" } }) : e === "pdf" ? /* @__PURE__ */ f("iframe", { title: l, src: n, width: "100%", height: "700px", children: [
166
+ e === "image" ? /* @__PURE__ */ s("img", { src: n, alt: r, style: { width: "100%" } }) : e === "pdf" ? /* @__PURE__ */ f("iframe", { title: r, src: n, width: "100%", height: "700px", children: [
166
167
  "This browser does not support PDFs. Please download the PDF to view it:",
167
168
  /* @__PURE__ */ s("a", { href: n, children: "Download PDF" })
168
169
  ] }) : /* @__PURE__ */ f(
169
170
  "iframe",
170
171
  {
171
- title: l,
172
+ title: r,
172
173
  src: `https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(
173
174
  n
174
175
  )}`,
@@ -194,16 +195,16 @@ const pt = ({ provider: n, value: t }) => {
194
195
  /* @__PURE__ */ s(
195
196
  C,
196
197
  {
197
- tooltip: l,
198
+ tooltip: r,
198
199
  icon: a,
199
200
  shape: "circle",
200
- onClick: () => w(!0)
201
+ onClick: () => F(!0)
201
202
  }
202
203
  )
203
204
  ] }) : /* @__PURE__ */ s(
204
205
  C,
205
206
  {
206
- tooltip: l,
207
+ tooltip: r,
207
208
  icon: a,
208
209
  target: "_blank",
209
210
  href: n,
@@ -212,7 +213,7 @@ const pt = ({ provider: n, value: t }) => {
212
213
  );
213
214
  };
214
215
  export {
215
- st as FileCellValue,
216
- pt as FileCrudCellValue,
217
- ht as default
216
+ lt as FileCellValue,
217
+ gt as FileCrudCellValue,
218
+ wt as default
218
219
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),f=require("../../common/description/DescList.cjs.js"),q=require("react"),x=require("../../locale/index.cjs.js"),V=require("./CrudViewerUtil.cjs.js");function d({className:o,fields:u,data:e,descListColumn:c={xs:1,md:3,sm:2,lg:4},layout:m,action:t,keepEmptyValues:b}){const{t:n}=x.useTranslationLib(),g=q.useMemo(()=>{const l=u.filter(({hidden:r,hideInDescList:i})=>!r&&!i).map((r,i)=>({label:r.label,noFormatting:!0,value:V.getRendererValueCrudViewer(r)(e==null?void 0:e[r.name],e,i)}));return t&&l.push({label:n("str.action"),value:t}),l},[t,e,u,n]);return e?s.jsx(f,{keepEmptyValues:b,bordered:!0,column:c,className:o,layout:m,list:g}):s.jsx(s.Fragment,{})}exports.CrudDecListView=d;
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,40 +1,44 @@
1
- import { jsx as l, Fragment as b } from "react/jsx-runtime";
2
- import g from "../../common/description/DescList.es.js";
3
- import { useMemo as x } from "react";
4
- import { useTranslationLib as L } from "../../locale/index.es.js";
5
- import { getRendererValueCrudViewer as V } from "./CrudViewerUtil.es.js";
1
+ import { jsx as s, Fragment as g } from "react/jsx-runtime";
2
+ import x from "../../common/description/DescList.es.js";
3
+ import { useMemo as C } from "react";
4
+ import { useTranslationLib as F } from "../../locale/index.es.js";
5
+ import { getRendererValueCrudViewer as L } from "./CrudViewerUtil.es.js";
6
+ import V from "../../util/CrudUtil.es.js";
6
7
  function h({
7
- className: n,
8
+ className: u,
8
9
  fields: m,
9
10
  data: r,
10
- descListColumn: u = { xs: 1, md: 3, sm: 2, lg: 4 },
11
+ descListColumn: n = { xs: 1, md: 3, sm: 2, lg: 4 },
11
12
  layout: f,
12
- action: o,
13
+ action: t,
13
14
  keepEmptyValues: p
14
15
  }) {
15
- const { t: i } = L(), c = x(() => {
16
- const s = m.filter(({ hidden: e, hideInDescList: t }) => !e && !t).map((e, t) => ({
17
- label: e.label,
18
- noFormatting: !0,
19
- value: V(e)(
20
- r == null ? void 0 : r[e.name],
21
- r,
22
- t
23
- )
24
- }));
25
- return o && s.push({ label: i("str.action"), value: o }), s;
26
- }, [o, r, m, i]);
27
- return r ? /* @__PURE__ */ l(
28
- g,
16
+ const { t: i } = F(), c = C(() => {
17
+ const l = m.filter(({ hidden: e, hideInDescList: o }) => !e && !o).map((e, o) => {
18
+ const b = V.getRealName(e.name);
19
+ return {
20
+ label: e.label,
21
+ noFormatting: !0,
22
+ value: L(e)(
23
+ r == null ? void 0 : r[b],
24
+ r,
25
+ o
26
+ )
27
+ };
28
+ });
29
+ return t && l.push({ label: i("str.action"), value: t }), l;
30
+ }, [t, r, m, i]);
31
+ return r ? /* @__PURE__ */ s(
32
+ x,
29
33
  {
30
34
  keepEmptyValues: p,
31
35
  bordered: !0,
32
- column: u,
33
- className: n,
36
+ column: n,
37
+ className: u,
34
38
  layout: f,
35
39
  list: c
36
40
  }
37
- ) : /* @__PURE__ */ l(b, {});
41
+ ) : /* @__PURE__ */ s(g, {});
38
42
  }
39
43
  export {
40
44
  h as CrudDecListView
@@ -1 +1 @@
1
- "use strict";const n=require("react/jsx-runtime"),xt=require("antd"),mt=require("@dnd-kit/core"),jt=require("@dnd-kit/modifiers"),ht=require("@dnd-kit/utilities"),M=require("@dnd-kit/sortable"),yt=require("../../common/button/Button.cjs.js"),qt=require("../../common/button/CloneButtonTable.cjs.js"),lt=require("../../common/button/DeleteButtonTable.cjs.js"),vt=require("../../common/button/ExportButton.cjs.js"),St=require("../../common/button/HideButtonTable.cjs.js"),Bt=require("../../common/button/RefreshButton.cjs.js"),It=require("../../common/button/UpdateButtonTable.cjs.js"),Tt=require("../../common/button/ViewButtonTable.cjs.js"),Ct=require("../../common/table/table.cjs.js"),u=require("react"),Mt=require("../../locale/index.cjs.js"),Rt=require("../CrudSearchComponent.cjs.js"),Vt=require("./CrudDecListView.cjs.js"),et=require("./CrudViewerUtil.cjs.js"),Et=require("@ant-design/icons"),wt=require("../../common/layout/VerticalSpace.cjs.js"),Dt=u.memo(Ct);function Lt({idField:e="id",loadingData:v,fields:f,isDeleting:T,isHiding:S,viewable:x=!1,paginateProps:j,onDelete:h,onHide:C,onUpdate:l,data:B=[],extraAction:I,onClickUpdate:y,minusHeight:w,scroll:G,onClickClone:R,className:J,expandable:K,size:Q,bordered:X,descListColumn:st,extraView:D,decListLayout:ot,scrollToTop:Nt,onClickRefresh:Y,closeViewOnClickUpdate:Z,onExport:L,confirmHiding:A,confirmDeleting:P,rowClassName:W,actionWidth:H=190,draggable:o,...rt}){const{t:p}=Mt.useTranslationLib(),U=u.useMemo(()=>f.map(({hideInTable:t,hidden:s,width:c,name:r,label:_,halign:$,...E})=>({title:_,width:c,key:r,dataIndex:r,hidden:t||s,align:$??(E.type==="number"?"right":void 0),render:et.getRendererValueCrudViewer(E)})),[f]),[i,V]=u.useState(),[O,z]=u.useState(),[q,d]=u.useState([]);u.useEffect(()=>{B&&d(B)},[B]),u.useEffect(()=>{B&&V(t=>{if(t)return B.find(s=>s[e]===t[e])})},[B,e,i]);const N=u.useCallback(t=>{var c;const s=I==null?void 0:I(t);return(Array.isArray(s)?(c=s==null?void 0:s.filter(Boolean))!=null&&c.length:s)||l||y||R||h?n.jsxs(n.Fragment,{children:[s,(l||y)&&n.jsx(It,{value:t,onClick:r=>{z(r[e]),y==null||y(t),Z&&V(void 0)}}),R&&n.jsx(qt,{value:t,onClick:r=>R(r)}),L&&n.jsx(vt.ExportButton,{value:t,onClick:async r=>await L(r)}),C&&n.jsx(St,{value:t,disabled:S,shouldConfirm:A,loading:S&&t[e]===O,onClick:async r=>{z(r[e]),await C({[e]:r[e]})}}),h&&n.jsx(lt,{value:t,disabled:T,shouldConfirm:P,loading:T&&t[e]===O,onClick:async r=>{z(r[e]),await h({[e]:r[e]})}})]}):void 0},[Z,P,A,I,e,T,S,R,y,h,L,C,l,O]),b=u.useCallback(t=>{var r;const{active:s,over:c}=t;if(o!=null&&o.onDragEnd&&(o==null||o.onDragEnd(t)),s.id!==(c==null?void 0:c.id)){const _=q.findIndex(m=>m[e]===s.id),$=q.findIndex(m=>m[e]===(c==null?void 0:c.id)),E=M.arrayMove(q,_,$);d(m=>{const it=m.findIndex(k=>k[e]===(s==null?void 0:s.id)),ft=m.findIndex(k=>k[e]===(c==null?void 0:c.id));return M.arrayMove(m,it,ft)}),(r=o==null?void 0:o.onDrag)==null||r.call(o,{newOrder:E.map(m=>m[e])})}},[q,e,o]),ut=u.useMemo(()=>{let t=typeof x=="string"?i==null?void 0:i[x]:void 0;if(typeof t=="object"){const s=f.find(c=>c.name===x);t=et.getRendererValueCrudViewer(s)(t,i,0)}return t},[x,i,f]),a=u.useMemo(()=>({rowClassName:W,className:J,scroll:G??(w?{y:`calc(100vh - ${w})`}:void 0),id:"crud-table",bordered:X,size:Q,expandable:K}),[W,J,G,w,X,Q,K]),F=u.useMemo(()=>j?{total:j.count,onChange:j.setPage,current:j.page,pageSize:j.pageSize}:void 0,[j]),g=u.useMemo(()=>{const t=l||y||h||I||x,s=[];return o&&s.push({key:"key",align:"center",width:5,title:o==null?void 0:o.columnLabel,render:()=>n.jsx(Ot,{tooltip:o==null?void 0:o.tooltip})}),s.push(...U),t&&t&&s.push({title:p("str.action"),fixed:"right",width:H,render:(c,r)=>n.jsxs(n.Fragment,{children:[x&&n.jsx(Tt,{value:r,onClick:V}),N(r)]})}),s},[U,l,y,h,I,x,p,H,N]),tt=u.useMemo(()=>q.map(t=>t[e]),[q,e]),ct=u.useCallback(()=>{const t=n.jsx(Dt,{...a,dataSource:q,loading:v,components:o?{body:{row:zt}}:void 0,pagination:F,columns:g});return o?n.jsx(mt.DndContext,{modifiers:[jt.restrictToVerticalAxis],onDragEnd:b,children:n.jsx(M.SortableContext,{items:tt,strategy:M.verticalListSortingStrategy,children:t})}):t},[a,q,v,F,g,o,tt,b]);return n.jsxs("div",{children:[x&&n.jsx(xt.Modal,{width:"100%",open:!!i,title:ut??n.jsx("div",{children:" "}),footer:n.jsx(n.Fragment,{}),closable:!0,onCancel:()=>V(void 0),children:!!i&&n.jsxs("div",{children:[n.jsx(Vt.CrudDecListView,{layout:ot,descListColumn:st,data:i,fields:f,action:N(i)}),D==null?void 0:D(i)]},i==null?void 0:i[e])}),n.jsx(Rt,{fields:f,...rt}),n.jsxs(wt,{children:[!!Y&&n.jsx(Bt.RefreshButton,{onClick:Y}),ct()]})]})}const nt=u.createContext({}),Ot=({tooltip:e})=>{const{setActivatorNodeRef:v,listeners:f}=u.useContext(nt);return n.jsx(yt,{type:"text",size:"small",tooltip:e,icon:n.jsx(Et.HolderOutlined,{}),style:{cursor:"move",border:"none"},ref:v,...f})},zt=e=>{const{attributes:v,listeners:f,setNodeRef:T,setActivatorNodeRef:S,transform:x,transition:j,isDragging:h}=M.useSortable({id:e["data-row-key"]}),C={...e.style,transform:ht.CSS.Translate.toString(x),transition:j,...h?{position:"relative",zIndex:9999}:{}},l=u.useMemo(()=>({setActivatorNodeRef:S,listeners:f}),[S,f]);return n.jsx(nt.Provider,{value:l,children:n.jsx("tr",{...e,ref:T,style:C,...v})})};module.exports=Lt;
1
+ "use strict";const n=require("react/jsx-runtime"),xt=require("antd"),jt=require("@dnd-kit/core"),lt=require("@dnd-kit/modifiers"),ht=require("@dnd-kit/utilities"),M=require("@dnd-kit/sortable"),qt=require("../../common/button/Button.cjs.js"),yt=require("../../common/button/CloneButtonTable.cjs.js"),vt=require("../../common/button/DeleteButtonTable.cjs.js"),St=require("../../common/button/ExportButton.cjs.js"),Bt=require("../../common/button/HideButtonTable.cjs.js"),Ct=require("../../common/button/RefreshButton.cjs.js"),It=require("../../common/button/UpdateButtonTable.cjs.js"),Tt=require("../../common/button/ViewButtonTable.cjs.js"),Rt=require("../../common/table/table.cjs.js"),u=require("react"),Mt=require("../../locale/index.cjs.js"),Vt=require("../CrudSearchComponent.cjs.js"),Et=require("./CrudDecListView.cjs.js"),et=require("./CrudViewerUtil.cjs.js"),Nt=require("@ant-design/icons"),nt=require("../../util/CrudUtil.cjs.js"),wt=require("../../common/layout/VerticalSpace.cjs.js"),Dt=u.memo(Rt);function Lt({idField:e="id",loadingData:v,fields:m,isDeleting:I,isHiding:S,viewable:f=!1,paginateProps:j,onDelete:l,onHide:T,onUpdate:y,data:B=[],extraAction:C,onClickUpdate:h,minusHeight:w,scroll:G,onClickClone:V,className:J,expandable:K,size:Q,bordered:X,descListColumn:ot,extraView:D,decListLayout:rt,scrollToTop:_t,onClickRefresh:Y,closeViewOnClickUpdate:Z,onExport:L,confirmHiding:A,confirmDeleting:P,rowClassName:W,actionWidth:a=190,draggable:o,...ut}){const{t:H}=Mt.useTranslationLib(),p=u.useMemo(()=>m.map(({hideInTable:t,hidden:s,width:c,label:r,halign:$,...R})=>{const N=nt.getRealName(R.name);return{title:r,width:c,key:N,dataIndex:N,hidden:t||s,align:$??(R.type==="number"?"right":void 0),render:et.getRendererValueCrudViewer(R)}}),[m]),[i,E]=u.useState(),[O,z]=u.useState(),[q,U]=u.useState([]);u.useEffect(()=>{B&&U(B)},[B]),u.useEffect(()=>{B&&E(t=>{if(t)return B.find(s=>s[e]===t[e])})},[B,e,i]);const _=u.useCallback(t=>{var c;const s=C==null?void 0:C(t);return(Array.isArray(s)?(c=s==null?void 0:s.filter(Boolean))!=null&&c.length:s)||y||h||V||l?n.jsxs(n.Fragment,{children:[s,(y||h)&&n.jsx(It,{value:t,onClick:r=>{z(r[e]),h==null||h(t),Z&&E(void 0)}}),V&&n.jsx(yt,{value:t,onClick:r=>V(r)}),L&&n.jsx(St.ExportButton,{value:t,onClick:async r=>await L(r)}),T&&n.jsx(Bt,{value:t,disabled:S,shouldConfirm:A,loading:S&&t[e]===O,onClick:async r=>{z(r[e]),await T({[e]:r[e]})}}),l&&n.jsx(vt,{value:t,disabled:I,shouldConfirm:P,loading:I&&t[e]===O,onClick:async r=>{z(r[e]),await l({[e]:r[e]})}})]}):void 0},[Z,P,A,C,e,I,S,V,h,l,L,T,y,O]),d=u.useCallback(t=>{var r;const{active:s,over:c}=t;if(o!=null&&o.onDragEnd&&(o==null||o.onDragEnd(t)),s.id!==(c==null?void 0:c.id)){const $=q.findIndex(x=>x[e]===s.id),R=q.findIndex(x=>x[e]===(c==null?void 0:c.id)),N=M.arrayMove(q,$,R);U(x=>{const mt=x.findIndex(k=>k[e]===(s==null?void 0:s.id)),ft=x.findIndex(k=>k[e]===(c==null?void 0:c.id));return M.arrayMove(x,mt,ft)}),(r=o==null?void 0:o.onDrag)==null||r.call(o,{newOrder:N.map(x=>x[e])})}},[q,e,o]),ct=u.useMemo(()=>{let t=typeof f=="string"?i==null?void 0:i[f]:void 0;if(typeof t=="object"){const s=m.find(c=>nt.getRealName(c.name)===f);t=et.getRendererValueCrudViewer(s)(t,i,0)}return t},[f,i,m]),b=u.useMemo(()=>({rowClassName:W,className:J,scroll:G??(w?{y:`calc(100vh - ${w})`}:void 0),id:"crud-table",bordered:X,size:Q,expandable:K}),[W,J,G,w,X,Q,K]),F=u.useMemo(()=>j?{total:j.count,onChange:j.setPage,current:j.page,pageSize:j.pageSize}:void 0,[j]),g=u.useMemo(()=>{const t=y||h||l||C||f,s=[];return o&&s.push({key:"key",align:"center",width:5,title:o==null?void 0:o.columnLabel,render:()=>n.jsx(Ot,{tooltip:o==null?void 0:o.tooltip})}),s.push(...p),t&&t&&s.push({title:H("str.action"),fixed:"right",width:a,render:(c,r)=>n.jsxs(n.Fragment,{children:[f&&n.jsx(Tt,{value:r,onClick:E}),_(r)]})}),s},[p,y,h,l,C,f,H,a,_]),tt=u.useMemo(()=>q.map(t=>t[e]),[q,e]),it=u.useCallback(()=>{const t=n.jsx(Dt,{...b,dataSource:q,loading:v,components:o?{body:{row:zt}}:void 0,pagination:F,columns:g});return o?n.jsx(jt.DndContext,{modifiers:[lt.restrictToVerticalAxis],onDragEnd:d,children:n.jsx(M.SortableContext,{items:tt,strategy:M.verticalListSortingStrategy,children:t})}):t},[b,q,v,F,g,o,tt,d]);return n.jsxs("div",{children:[f&&n.jsx(xt.Modal,{width:"100%",open:!!i,title:ct??n.jsx("div",{children:" "}),footer:n.jsx(n.Fragment,{}),closable:!0,onCancel:()=>E(void 0),children:!!i&&n.jsxs("div",{children:[n.jsx(Et.CrudDecListView,{layout:rt,descListColumn:ot,data:i,fields:m,action:_(i)}),D==null?void 0:D(i)]},i==null?void 0:i[e])}),n.jsx(Vt,{fields:m,...ut}),n.jsxs(wt,{children:[!!Y&&n.jsx(Ct.RefreshButton,{onClick:Y}),it()]})]})}const st=u.createContext({}),Ot=({tooltip:e})=>{const{setActivatorNodeRef:v,listeners:m}=u.useContext(st);return n.jsx(qt,{type:"text",size:"small",tooltip:e,icon:n.jsx(Nt.HolderOutlined,{}),style:{cursor:"move",border:"none"},ref:v,...m})},zt=e=>{const{attributes:v,listeners:m,setNodeRef:I,setActivatorNodeRef:S,transform:f,transition:j,isDragging:l}=M.useSortable({id:e["data-row-key"]}),T={...e.style,transform:ht.CSS.Translate.toString(f),transition:j,...l?{position:"relative",zIndex:9999}:{}},y=u.useMemo(()=>({setActivatorNodeRef:S,listeners:m}),[S,m]);return n.jsx(st.Provider,{value:y,children:n.jsx("tr",{...e,ref:I,style:T,...v})})};module.exports=Lt;