@kingteza/crud-component 1.25.0 → 1.26.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.
@@ -57,6 +57,7 @@ export interface InitialCrudField<T> {
57
57
  };
58
58
  hideLabel?: boolean;
59
59
  sorter?: ColumnType<T>["sorter"];
60
+ defaultSortOrder?: ColumnType<T>["defaultSortOrder"];
60
61
  }
61
62
  export type CrudFieldGrid = {
62
63
  xs?: number;
@@ -1 +1 @@
1
- "use strict";const s=require("react/jsx-runtime"),c=require("@ant-design/icons"),f=require("antd"),L=require("mime"),o=require("react"),Z=require("../util/ValidationUtil.cjs.js"),{Dragger:_}=f.Upload;function G({name:S,label:M,required:N,provider:a,onUploading:m,onRemoved:p,fieldClassName:W,accept:i,rules:k,maxCount:r=1,block:B,showInGrid:$=!1,gridConfig:q={draggerSpan:12,previewSpan:12},fieldHelper:R,formLayoutProps:C,...I}){const u=f.Form.useFormInstance(),n=o.useMemo(()=>S,[S]),y=f.Form.useWatch(n,u),[A,H]=o.useState(!1),[j,h]=o.useState([]),T=o.useCallback(async e=>{var x,w;const l=e.file,t=(l==null?void 0:l.name)??"",d=`${Date.now()}-${Math.random().toString(36).substring(2,9)}`;h(F=>[...F,{uid:d,name:t,status:"uploading",originFileObj:l}]);try{H(!0),m==null||m(!0);const F=t??"",V=F.split("."),O=V[V.length-1],Q=a.generateFileName(F),X=`${await a.getInitialPath()}/${Q}.${O}`,g=await a.upload({...l,originFileObj:l},X),D=await a.getRealUrl(g),Y=L.getType(g),P=u.getFieldValue(n);if(r>1){const b=[...Array.isArray(P)?P:P?[P]:[],g].filter(Boolean);u.setFieldValue(n,b)}else u.setFieldValue(n,g);h(E=>E.map(b=>b.uid===d?{uid:g,url:D,type:Y,name:F,status:"done",response:g,thumbUrl:D}:b)),(x=e.onSuccess)==null||x.call(e,g)}catch(F){(w=e.onError)==null||w.call(e,F),h(V=>V.filter(O=>O.uid!==d))}finally{m==null||m(!1)}},[u,r,m,a,n]);o.useEffect(()=>{!A&&y&&Promise.all((Array.isArray(y)?y:[y]).map(async e=>{const l=L.getType(e),t=e.split("/").pop(),d=await a.getRealUrl(e);return{uid:e,url:d,type:l,name:t,response:e,thumbUrl:d}})).then(e=>h(e))},[y,A,a]);const z=o.useCallback(async e=>{const l=e.response??e.uid;await a.delete(l),p==null||p();const t=u.getFieldValue(n);if(r>1){const x=(Array.isArray(t)?t:t?[t]:[]).filter(w=>w!==l);u.setFieldValue(n,x.length?x:void 0)}else u.setFieldValue(n,void 0);h(d=>d.filter(x=>x.uid!==e.uid))},[u,r,p,a,n]),U=o.useMemo(()=>{if(!i)return"all files";const e=i.split(",").map(l=>{const t=l.trim().toLowerCase();return t.startsWith("image/")?"images":t===".pdf"||t==="application/pdf"?"PDF files":t.includes("excel")||t.includes(".xls")?"Excel files":t.includes("word")||t.includes(".doc")?"Word files":t.includes("text")||t===".txt"?"text files":t.includes("presentation")||t.includes(".ppt")?"PowerPoint files":t.replace(".","").toUpperCase()});return[...new Set(e)].join(", ")},[i]),J=o.useMemo(()=>i?i.includes("image")?s.jsx(c.FileImageOutlined,{}):i.includes("pdf")?s.jsx(c.FilePdfOutlined,{}):i.includes("word")||i.includes(".doc")?s.jsx(c.FileWordOutlined,{}):i.includes("text")||i.includes(".txt")?s.jsx(c.FileTextOutlined,{}):i.includes("excel")||i.includes(".xls")?s.jsx(c.FileExcelOutlined,{}):i.includes("presentation")||i.includes(".ppt")?s.jsx(c.FilePptOutlined,{}):s.jsx(c.FileOutlined,{}):s.jsx(c.InboxOutlined,{}),[i]),K=((j==null?void 0:j.length)??0)>=r;return s.jsxs(f.Form.Item,{label:M,required:N,name:n,...C,className:W,rules:[...N?Z.required(M):[],...k??[]],help:R,children:[s.jsx("input",{hidden:!0}),s.jsxs(f.Row,{gutter:[8,8],align:"top",style:{width:"100%",margin:0},children:[s.jsx(f.Col,{span:$?q.draggerSpan:24,xs:24,sm:24,children:s.jsxs(_,{...I,accept:i,disabled:K,fileList:[],multiple:r>1,maxCount:r,customRequest:T,onRemove:z,onChange:({file:e})=>{e.status==="error"&&h(l=>l.filter(t=>t.uid!==e.uid))},style:B?{width:"100%"}:void 0,children:[s.jsx("p",{className:"ant-upload-drag-icon",children:J}),s.jsx("p",{className:"ant-upload-text",children:"Click or drag file to this area to upload"}),s.jsx("p",{className:"ant-upload-hint",children:`Maximum file size: 10 MB. Supported formats: ${U}. ${r>1?`Maximum number of files: ${r}`:""}`})]})}),j.length>0&&s.jsx(f.Col,{span:$?q.previewSpan:24,xs:24,sm:24,children:s.jsx(f.Upload,{...I,accept:i,fileList:j,maxCount:r,customRequest:T,onRemove:z,listType:"picture",onChange:({fileList:e})=>h(e),style:{width:"100%"}})})]})]})}module.exports=G;
1
+ "use strict";const s=require("react/jsx-runtime"),c=require("@ant-design/icons"),f=require("antd"),L=require("mime"),o=require("react"),Z=require("../util/ValidationUtil.cjs.js"),{Dragger:_}=f.Upload;function G({name:S,label:M,required:N,provider:a,onUploading:m,onRemoved:p,fieldClassName:W,accept:i,rules:k,maxCount:r=1,block:B,showInGrid:$=!1,gridConfig:q={draggerSpan:12,previewSpan:12},fieldHelper:R,formLayoutProps:H,...I}){const u=f.Form.useFormInstance(),n=o.useMemo(()=>S,[S]),y=f.Form.useWatch(n,u),[A,U]=o.useState(!1),[j,h]=o.useState([]),T=o.useCallback(async e=>{var x,w;const l=e.file,t=(l==null?void 0:l.name)??"",d=`${Date.now()}-${Math.random().toString(36).substring(2,9)}`;h(F=>[...F,{uid:d,name:t,status:"uploading",originFileObj:l}]);try{U(!0),m==null||m(!0);const F=t??"",V=F.split("."),O=V[V.length-1],Q=a.generateFileName(F),X=`${await a.getInitialPath()}/${Q}.${O}`,g=await a.upload({...l,originFileObj:l},X),D=await a.getRealUrl(g),Y=L.getType(g),P=u.getFieldValue(n);if(r>1){const b=[...Array.isArray(P)?P:P?[P]:[],g].filter(Boolean);u.setFieldValue(n,b)}else u.setFieldValue(n,g);h(E=>E.map(b=>b.uid===d?{uid:g,url:D,type:Y,name:F,status:"done",response:g,thumbUrl:D}:b)),(x=e.onSuccess)==null||x.call(e,g)}catch(F){(w=e.onError)==null||w.call(e,F),h(V=>V.filter(O=>O.uid!==d))}finally{m==null||m(!1)}},[u,r,m,a,n]);o.useEffect(()=>{!A&&y&&Promise.all((Array.isArray(y)?y:[y]).map(async e=>{const l=L.getType(e),t=e.split("/").pop(),d=await a.getRealUrl(e);return{uid:e,url:d,type:l,name:t,response:e,thumbUrl:d}})).then(e=>h(e))},[y,A,a]);const z=o.useCallback(async e=>{const l=e.response??e.uid;await a.delete(l),p==null||p();const t=u.getFieldValue(n);if(r>1){const x=(Array.isArray(t)?t:t?[t]:[]).filter(w=>w!==l);u.setFieldValue(n,x.length?x:void 0)}else u.setFieldValue(n,void 0);h(d=>d.filter(x=>x.uid!==e.uid))},[u,r,p,a,n]),C=o.useMemo(()=>{if(!i)return"all files";const e=i.split(",").map(l=>{const t=l.trim().toLowerCase();return t.startsWith("image/")?"images":t===".pdf"||t==="application/pdf"?"PDF files":t.includes("excel")||t.includes(".xls")?"Excel files":t.includes("word")||t.includes(".doc")?"Word files":t.includes("text")||t===".txt"?"text files":t.includes("presentation")||t.includes(".ppt")?"PowerPoint files":t.replace(".","").toUpperCase()});return[...new Set(e)].join(", ")},[i]),J=o.useMemo(()=>i?i.includes("image")?s.jsx(c.FileImageOutlined,{}):i.includes("pdf")?s.jsx(c.FilePdfOutlined,{}):i.includes("word")||i.includes(".doc")?s.jsx(c.FileWordOutlined,{}):i.includes("text")||i.includes(".txt")?s.jsx(c.FileTextOutlined,{}):i.includes("excel")||i.includes(".xls")?s.jsx(c.FileExcelOutlined,{}):i.includes("presentation")||i.includes(".ppt")?s.jsx(c.FilePptOutlined,{}):s.jsx(c.FileOutlined,{}):s.jsx(c.InboxOutlined,{}),[i]),K=((j==null?void 0:j.length)??0)>=r;return s.jsxs(f.Form.Item,{label:M,required:N,name:n,...H,className:W,rules:[...N?Z.required(M):[],...k??[]],help:R,children:[s.jsx("input",{hidden:!0}),s.jsxs(f.Row,{gutter:[8,8],align:"top",style:{width:"100%",margin:0},children:[s.jsx(f.Col,{span:$?q.draggerSpan:24,xs:24,sm:24,children:s.jsxs(_,{...I,accept:i,disabled:K,fileList:[],multiple:r>1,maxCount:r,customRequest:T,onRemove:z,onChange:({file:e})=>{e.status==="error"&&h(l=>l.filter(t=>t.uid!==e.uid))},style:B?{width:"100%"}:void 0,children:[s.jsx("p",{className:"ant-upload-drag-icon",children:J}),s.jsx("p",{className:"ant-upload-text",children:"Click or drag file to this area to upload"}),s.jsx("p",{className:"ant-upload-hint",children:`Maximum file size: 10 MB. Supported formats: ${C}. ${r>1?`Maximum number of files: ${r}`:""}`})]})}),j.length>0&&s.jsx(f.Col,{span:$?q.previewSpan:24,xs:24,sm:24,children:s.jsx(f.Upload,{...I,accept:i,fileList:j,maxCount:r,customRequest:T,onRemove:z,listType:"picture",onChange:({fileList:e})=>h(e),style:{width:"100%"}})})]})]})}module.exports=G;
@@ -2,7 +2,7 @@ import { UploadProps } from 'antd';
2
2
  import { ReactNode } from 'react';
3
3
  import { InitialCrudField } from './CrudComponent';
4
4
  import { FileUploadProvider } from './ImageCrudField';
5
- export interface FileCrudDragNDropField<T> extends _FileCrudDragNDropField<T> {
5
+ export interface FileCrudDragNDropFieldProps<T> extends _FileCrudDragNDropField<T> {
6
6
  type: "file";
7
7
  }
8
8
  export interface _FileCrudDragNDropField<T> extends InitialCrudField<T> {
@@ -21,4 +21,4 @@ export interface _FileCrudDragNDropField<T> extends InitialCrudField<T> {
21
21
  previewSpan?: number;
22
22
  };
23
23
  }
24
- export default function FileCrudDragNDropFieldComponent<T>({ name, label, required, provider, onUploading, onRemoved, fieldClassName, accept, rules, maxCount, block, showInGrid, gridConfig, fieldHelper: help, formLayoutProps, ...props }: Readonly<_FileCrudDragNDropField<T>> & Omit<UploadProps, "customRequest">): import("react/jsx-runtime").JSX.Element;
24
+ export default function FileCrudDragNDropField<T>({ name, label, required, provider, onUploading, onRemoved, fieldClassName, accept, rules, maxCount, block, showInGrid, gridConfig, fieldHelper: help, formLayoutProps, ...props }: Readonly<_FileCrudDragNDropField<T>> & Omit<UploadProps, "customRequest">): import("react/jsx-runtime").JSX.Element;
@@ -28,10 +28,10 @@ function Fe({
28
28
  }) {
29
29
  const u = b.useFormInstance(), n = S(() => N, [N]), p = b.useWatch(n, u), [j, X] = B(!1), [g, f] = B([]), z = q(
30
30
  async (e) => {
31
- var o, F;
31
+ var m, F;
32
32
  const l = e.file, t = (l == null ? void 0 : l.name) ?? "", d = `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
33
- f((m) => [
34
- ...m,
33
+ f((o) => [
34
+ ...o,
35
35
  {
36
36
  uid: d,
37
37
  name: t,
@@ -41,9 +41,9 @@ function Fe({
41
41
  ]);
42
42
  try {
43
43
  X(!0), c == null || c(!0);
44
- const m = t ?? "", w = m.split("."), P = w[w.length - 1], C = a.generateFileName(m), G = `${await a.getInitialPath()}/${C}.${P}`, h = await a.upload(
44
+ const o = t ?? "", w = o.split("."), P = w[w.length - 1], G = a.generateFileName(o), C = `${await a.getInitialPath()}/${G}.${P}`, h = await a.upload(
45
45
  { ...l, originFileObj: l },
46
- G
46
+ C
47
47
  ), E = await a.getRealUrl(h), v = k.getType(h), x = u.getFieldValue(n);
48
48
  if (r > 1) {
49
49
  const V = [...Array.isArray(x) ? x : x ? [x] : [], h].filter(Boolean);
@@ -56,15 +56,15 @@ function Fe({
56
56
  uid: h,
57
57
  url: E,
58
58
  type: v,
59
- name: m,
59
+ name: o,
60
60
  status: "done",
61
61
  response: h,
62
62
  thumbUrl: E
63
63
  } : V
64
64
  )
65
- ), (o = e.onSuccess) == null || o.call(e, h);
66
- } catch (m) {
67
- (F = e.onError) == null || F.call(e, m), f((w) => w.filter((P) => P.uid !== d));
65
+ ), (m = e.onSuccess) == null || m.call(e, h);
66
+ } catch (o) {
67
+ (F = e.onError) == null || F.call(e, o), f((w) => w.filter((P) => P.uid !== d));
68
68
  } finally {
69
69
  c == null || c(!1);
70
70
  }
@@ -85,11 +85,11 @@ function Fe({
85
85
  await a.delete(l), y == null || y();
86
86
  const t = u.getFieldValue(n);
87
87
  if (r > 1) {
88
- const o = (Array.isArray(t) ? t : t ? [t] : []).filter((F) => F !== l);
89
- u.setFieldValue(n, o.length ? o : void 0);
88
+ const m = (Array.isArray(t) ? t : t ? [t] : []).filter((F) => F !== l);
89
+ u.setFieldValue(n, m.length ? m : void 0);
90
90
  } else
91
91
  u.setFieldValue(n, void 0);
92
- f((d) => d.filter((o) => o.uid !== e.uid));
92
+ f((d) => d.filter((m) => m.uid !== e.uid));
93
93
  },
94
94
  [u, r, y, a, n]
95
95
  ), Y = S(() => {
@@ -13,8 +13,7 @@ export { default as ImageCrudField, FileDownloadProvider, FileUploadProvider, Im
13
13
  export type { ImageCrudField as ImageCrudFieldProps } from './ImageCrudField';
14
14
  export { default as FileCrudField, FileCellValue, FileCrudCellValue, } from './FileCrudField';
15
15
  export type { FileCrudField as FileCrudFieldProps } from './FileCrudField';
16
- export { default as FileCrudDragNDropField } from './FileCrudDragNDropField';
17
- export type { FileCrudDragNDropField as FileCrudDragNDropFieldProps, } from './FileCrudDragNDropField';
16
+ export { default as FileCrudDragNDropField, type FileCrudDragNDropFieldProps, } from './FileCrudDragNDropField';
18
17
  export { default as CrudTextAreaComponent } from './CrudTextAreaComponent';
19
18
  export type { TextAreaBasedFieldProps } from './CrudTextAreaComponent';
20
19
  export { default as CrudImportComponent } from './import/CrudImportComponent';
@@ -1 +1 @@
1
- "use strict";const n=require("react/jsx-runtime"),ht=require("antd"),yt=require("@dnd-kit/core"),qt=require("@dnd-kit/modifiers"),Ct=require("@dnd-kit/utilities"),d=require("@dnd-kit/sortable"),lt=require("../../common/button/Button.cjs.js"),It=require("../../common/button/RefreshButton.cjs.js"),St=require("../../common/button/ViewButtonTable.cjs.js"),Rt=require("../actions/index.cjs.js"),Mt=require("../../common/table/table.cjs.js"),s=require("react"),dt=require("../../locale/index.cjs.js"),Tt=require("../CrudSearchComponent.cjs.js"),Vt=require("./CrudDecListView.cjs.js"),nt=require("./CrudViewerUtil.cjs.js"),Bt=require("@ant-design/icons"),ot=require("../../util/CrudUtil.cjs.js"),Dt=require("../../common/layout/VerticalSpace.cjs.js"),Nt=s.memo(Mt);function kt({summary:j,idField:o="id",loadingData:q,fields:h,isDeleting:R,isHiding:T,viewable:c=!1,paginateProps:m,onDelete:C,onHide:V,onUpdate:B,data:l=[],extraAction:D,onClickUpdate:N,minusHeight:E,scroll:v,onClickClone:z,className:$,expandable:A,size:_,bordered:G,descListColumn:rt,extraView:L,decListLayout:ct,scrollToTop:Ot,onClickRefresh:J,closeViewOnClickUpdate:K,onExport:Q,confirmHiding:X,confirmDeleting:Y,rowClassName:Z,actionWidth:W=190,draggable:t,rowSelection:p,...ut}){const{t:P}=dt.useTranslationLib(),H=s.useMemo(()=>h.map(({hideInTable:e,hidden:r,width:u,label:x,halign:I,...S})=>{const k=ot.getRealName(S.name);return{title:x,width:u,key:k,dataIndex:k,hidden:e||r,align:I??(S.type==="number"?"right":void 0),render:nt.getRendererValueCrudViewer(S),sorter:S.sorter}}),[h]),[i,M]=s.useState(),[U,w]=s.useState(),[y,F]=s.useState([]),it=s.useCallback(e=>{M(e)},[]);s.useEffect(()=>{l&&F(l)},[l]),s.useEffect(()=>{l&&M(e=>{if(e)return l.find(r=>r[o]===e[o])})},[l,o,i]);const a=s.useCallback(e=>{var x;const{active:r,over:u}=e;if(t!=null&&t.onDragEnd&&(t==null||t.onDragEnd(e)),r.id!==(u==null?void 0:u.id)){const I=y.findIndex(f=>f[o]===r.id),S=y.findIndex(f=>f[o]===(u==null?void 0:u.id)),k=d.arrayMove(y,I,S);F(f=>{const ft=f.findIndex(O=>O[o]===(r==null?void 0:r.id)),jt=f.findIndex(O=>O[o]===(u==null?void 0:u.id));return d.arrayMove(f,ft,jt)}),(x=t==null?void 0:t.onDrag)==null||x.call(t,{newOrder:k.map(f=>f[o])})}},[y,o,t]),mt=s.useMemo(()=>{let e=typeof c=="string"?i==null?void 0:i[c]:void 0;if(typeof e=="object"){const r=h.find(u=>ot.getRealName(u.name)===c);e=nt.getRendererValueCrudViewer(r)(e,i,0)}return e},[c,i,h]),b=s.useMemo(()=>({rowSelection:p,rowClassName:Z,className:$,scroll:v??(E?{y:`calc(100vh - ${E})`}:void 0),id:"crud-table",bordered:G,size:_,expandable:A}),[p,Z,$,v,E,G,_,A]),g=s.useMemo(()=>m?{...m,total:m.count,onChange:m.setPage,current:m.page,pageSize:m.pageSize}:void 0,[m]),tt=s.useMemo(()=>{const e=B||N||C||D||c,r=[];return t&&r.push({key:"key",align:"center",width:5,title:t==null?void 0:t.columnLabel,render:()=>n.jsx(Et,{tooltip:t==null?void 0:t.tooltip})}),r.push(...H),e&&e&&r.push({title:P("str.action"),fixed:"right",width:W,render:(u,x)=>n.jsxs(n.Fragment,{children:[c&&n.jsx(St,{value:x,onClick:typeof c=="object"?()=>{var I;return(I=c.onClick)==null?void 0:I.call(c,x)}:it}),n.jsx(Rt,{data:x,idField:o,extraAction:D,onUpdate:B,onClickUpdate:N,onClickClone:z,onDelete:C,onHide:V,onExport:Q,isHiding:T,isDeleting:R,confirmHiding:X,confirmDeleting:Y,closeViewOnClickUpdate:K,recentUpdateOrDeleteId:U,setRecentUpdateOrDeleteId:w,setOpenView:M})]})}),r},[H,B,N,C,D,c,P,W]),et=s.useMemo(()=>y.map(e=>e[o]),[y,o]),xt=s.useCallback(()=>{const e=n.jsx(Nt,{...b,summary:j,dataSource:y,loading:q,components:t?{body:{row:Lt}}:void 0,pagination:g,columns:tt});return t?n.jsx(yt.DndContext,{modifiers:[qt.restrictToVerticalAxis],onDragEnd:a,children:n.jsx(d.SortableContext,{items:et,strategy:d.verticalListSortingStrategy,children:e})}):e},[b,y,q,g,tt,j,t,et,a]);return n.jsxs("div",{children:[(typeof c=="boolean"||typeof c=="string")&&n.jsx(ht.Modal,{width:"100%",open:!!i,title:mt??n.jsx("div",{children:" "}),footer:n.jsx(n.Fragment,{}),closable:!0,onCancel:()=>M(void 0),children:!!i&&n.jsxs("div",{children:[n.jsx(Vt.CrudDecListView,{layout:ct,descListColumn:rt,data:i,fields:h,idField:o,extraAction:D,onUpdate:B,onClickUpdate:N,onClickClone:z,onDelete:C,onHide:V,onExport:Q,isHiding:T,isDeleting:R,confirmHiding:X,confirmDeleting:Y,closeViewOnClickUpdate:K,recentUpdateOrDeleteId:U,setRecentUpdateOrDeleteId:w,setOpenView:M}),L==null?void 0:L(i)]},i==null?void 0:i[o])}),n.jsx(Tt,{fields:h,...ut}),n.jsxs(Dt,{children:[!!J&&n.jsx(It.RefreshButton,{onClick:J}),xt()]})]})}const st=s.createContext({}),Et=({tooltip:j})=>{const{setActivatorNodeRef:o,listeners:q}=s.useContext(st);return n.jsx(lt,{type:"text",size:"small",tooltip:j,icon:n.jsx(Bt.HolderOutlined,{}),style:{cursor:"move",border:"none"},ref:o,...q})},Lt=j=>{const{attributes:o,listeners:q,setNodeRef:h,setActivatorNodeRef:R,transform:T,transition:c,isDragging:m}=d.useSortable({id:j["data-row-key"]}),C={...j.style,transform:Ct.CSS.Translate.toString(T),transition:c,...m?{position:"relative",zIndex:9999}:{}},V=s.useMemo(()=>({setActivatorNodeRef:R,listeners:q}),[R,q]);return n.jsx(st.Provider,{value:V,children:n.jsx("tr",{...j,ref:h,style:C,...o})})};module.exports=kt;
1
+ "use strict";const n=require("react/jsx-runtime"),ht=require("antd"),yt=require("@dnd-kit/core"),qt=require("@dnd-kit/modifiers"),Ct=require("@dnd-kit/utilities"),M=require("@dnd-kit/sortable"),lt=require("../../common/button/Button.cjs.js"),St=require("../../common/button/RefreshButton.cjs.js"),dt=require("../../common/button/ViewButtonTable.cjs.js"),It=require("../actions/index.cjs.js"),Rt=require("../../common/table/table.cjs.js"),s=require("react"),Mt=require("../../locale/index.cjs.js"),Tt=require("../CrudSearchComponent.cjs.js"),Vt=require("./CrudDecListView.cjs.js"),nt=require("./CrudViewerUtil.cjs.js"),Bt=require("@ant-design/icons"),ot=require("../../util/CrudUtil.cjs.js"),Dt=require("../../common/layout/VerticalSpace.cjs.js"),Ot=s.memo(Rt);function Nt({summary:j,idField:o="id",loadingData:q,fields:h,isDeleting:I,isHiding:T,viewable:c=!1,paginateProps:f,onDelete:l,onHide:V,onUpdate:B,data:S=[],extraAction:D,onClickUpdate:O,minusHeight:k,scroll:v,onClickClone:z,className:$,expandable:A,size:_,bordered:G,descListColumn:rt,extraView:E,decListLayout:ct,scrollToTop:Lt,onClickRefresh:J,closeViewOnClickUpdate:K,onExport:Q,confirmHiding:X,confirmDeleting:Y,rowClassName:Z,actionWidth:W=190,draggable:t,rowSelection:P,...ut}){const{t:H}=Mt.useTranslationLib(),U=s.useMemo(()=>h.map(({hideInTable:e,hidden:r,width:u,label:m,halign:d,...C})=>{const N=ot.getRealName(C.name);return{title:m,width:u,key:N,dataIndex:N,hidden:e||r,align:d??(C.type==="number"?"right":void 0),render:nt.getRendererValueCrudViewer(C),sorter:C.sorter,defaultSortOrder:C.defaultSortOrder}}),[h]),[i,R]=s.useState(),[p,w]=s.useState(),[y,a]=s.useState([]),it=s.useCallback(e=>{R(e)},[]);s.useEffect(()=>{S&&a(S)},[S]),s.useEffect(()=>{S&&R(e=>{if(e)return S.find(r=>r[o]===e[o])})},[S,o,i]);const F=s.useCallback(e=>{var m;const{active:r,over:u}=e;if(t!=null&&t.onDragEnd&&(t==null||t.onDragEnd(e)),r.id!==(u==null?void 0:u.id)){const d=y.findIndex(x=>x[o]===r.id),C=y.findIndex(x=>x[o]===(u==null?void 0:u.id)),N=M.arrayMove(y,d,C);a(x=>{const xt=x.findIndex(L=>L[o]===(r==null?void 0:r.id)),jt=x.findIndex(L=>L[o]===(u==null?void 0:u.id));return M.arrayMove(x,xt,jt)}),(m=t==null?void 0:t.onDrag)==null||m.call(t,{newOrder:N.map(x=>x[o])})}},[y,o,t]),ft=s.useMemo(()=>{let e=typeof c=="string"?i==null?void 0:i[c]:void 0;if(typeof e=="object"){const r=h.find(u=>ot.getRealName(u.name)===c);e=nt.getRendererValueCrudViewer(r)(e,i,0)}return e},[c,i,h]),b=s.useMemo(()=>({rowSelection:P,rowClassName:Z,className:$,scroll:v??(k?{y:`calc(100vh - ${k})`}:void 0),id:"crud-table",bordered:G,size:_,expandable:A}),[P,Z,$,v,k,G,_,A]),g=s.useMemo(()=>f?{...f,total:f.count,onChange:f.setPage,current:f.page,pageSize:f.pageSize}:void 0,[f]),tt=s.useMemo(()=>{const e=B||O||l||D||c,r=[];return t&&r.push({key:"key",align:"center",width:5,title:t==null?void 0:t.columnLabel,render:()=>n.jsx(kt,{tooltip:t==null?void 0:t.tooltip})}),r.push(...U),e&&e&&r.push({title:H("str.action"),fixed:"right",width:W,render:(u,m)=>n.jsxs(n.Fragment,{children:[c&&n.jsx(dt,{value:m,onClick:typeof c=="object"?()=>{var d;return(d=c.onClick)==null?void 0:d.call(c,m)}:it}),n.jsx(It,{data:m,idField:o,extraAction:D,onUpdate:B,onClickUpdate:O,onClickClone:z,onDelete:l,onHide:V,onExport:Q,isHiding:T,isDeleting:I,confirmHiding:X,confirmDeleting:Y,closeViewOnClickUpdate:K,recentUpdateOrDeleteId:p,setRecentUpdateOrDeleteId:w,setOpenView:R})]})}),r},[U,B,O,l,D,c,H,W]),et=s.useMemo(()=>y.map(e=>e[o]),[y,o]),mt=s.useCallback(()=>{const e=n.jsx(Ot,{...b,summary:j,dataSource:y,loading:q,components:t?{body:{row:Et}}:void 0,pagination:g,columns:tt});return t?n.jsx(yt.DndContext,{modifiers:[qt.restrictToVerticalAxis],onDragEnd:F,children:n.jsx(M.SortableContext,{items:et,strategy:M.verticalListSortingStrategy,children:e})}):e},[b,y,q,g,tt,j,t,et,F]);return n.jsxs("div",{children:[(typeof c=="boolean"||typeof c=="string")&&n.jsx(ht.Modal,{width:"100%",open:!!i,title:ft??n.jsx("div",{children:" "}),footer:n.jsx(n.Fragment,{}),closable:!0,onCancel:()=>R(void 0),children:!!i&&n.jsxs("div",{children:[n.jsx(Vt.CrudDecListView,{layout:ct,descListColumn:rt,data:i,fields:h,idField:o,extraAction:D,onUpdate:B,onClickUpdate:O,onClickClone:z,onDelete:l,onHide:V,onExport:Q,isHiding:T,isDeleting:I,confirmHiding:X,confirmDeleting:Y,closeViewOnClickUpdate:K,recentUpdateOrDeleteId:p,setRecentUpdateOrDeleteId:w,setOpenView:R}),E==null?void 0:E(i)]},i==null?void 0:i[o])}),n.jsx(Tt,{fields:h,...ut}),n.jsxs(Dt,{children:[!!J&&n.jsx(St.RefreshButton,{onClick:J}),mt()]})]})}const st=s.createContext({}),kt=({tooltip:j})=>{const{setActivatorNodeRef:o,listeners:q}=s.useContext(st);return n.jsx(lt,{type:"text",size:"small",tooltip:j,icon:n.jsx(Bt.HolderOutlined,{}),style:{cursor:"move",border:"none"},ref:o,...q})},Et=j=>{const{attributes:o,listeners:q,setNodeRef:h,setActivatorNodeRef:I,transform:T,transition:c,isDragging:f}=M.useSortable({id:j["data-row-key"]}),l={...j.style,transform:Ct.CSS.Translate.toString(T),transition:c,...f?{position:"relative",zIndex:9999}:{}},V=s.useMemo(()=>({setActivatorNodeRef:I,listeners:q}),[I,q]);return n.jsx(st.Provider,{value:V,children:n.jsx("tr",{...j,ref:h,style:l,...o})})};module.exports=Nt;
@@ -1,9 +1,9 @@
1
1
  import { jsx as e, jsxs as L, Fragment as et } from "react/jsx-runtime";
2
- import { Modal as Rt } from "antd";
3
- import { DndContext as lt } from "@dnd-kit/core";
4
- import { restrictToVerticalAxis as Bt } from "@dnd-kit/modifiers";
5
- import { CSS as Dt } from "@dnd-kit/utilities";
6
- import { arrayMove as ct, SortableContext as Nt, verticalListSortingStrategy as Ot, useSortable as dt } from "@dnd-kit/sortable";
2
+ import { Modal as lt } from "antd";
3
+ import { DndContext as Rt } from "@dnd-kit/core";
4
+ import { restrictToVerticalAxis as dt } from "@dnd-kit/modifiers";
5
+ import { CSS as Ot } from "@dnd-kit/utilities";
6
+ import { arrayMove as ct, SortableContext as Bt, verticalListSortingStrategy as Dt, useSortable as Nt } from "@dnd-kit/sortable";
7
7
  import jt from "../../common/button/Button.es.js";
8
8
  import { RefreshButton as Et } from "../../common/button/RefreshButton.es.js";
9
9
  import Lt from "../../common/button/ViewButtonTable.es.js";
@@ -22,16 +22,16 @@ function so({
22
22
  summary: h,
23
23
  idField: n = "id",
24
24
  loadingData: C,
25
- fields: p,
26
- isDeleting: l,
27
- isHiding: D,
25
+ fields: y,
26
+ isDeleting: R,
27
+ isHiding: O,
28
28
  viewable: c = !1,
29
29
  paginateProps: u,
30
30
  onDelete: I,
31
- onHide: N,
32
- onUpdate: O,
33
- data: S = [],
34
- extraAction: d,
31
+ onHide: B,
32
+ onUpdate: D,
33
+ data: T = [],
34
+ extraAction: N,
35
35
  onClickUpdate: j,
36
36
  minusHeight: M,
37
37
  scroll: A,
@@ -42,7 +42,7 @@ function so({
42
42
  bordered: J,
43
43
  descListColumn: ht,
44
44
  extraView: V,
45
- decListLayout: pt,
45
+ decListLayout: yt,
46
46
  scrollToTop: Kt,
47
47
  onClickRefresh: K,
48
48
  closeViewOnClickUpdate: Q,
@@ -53,61 +53,62 @@ function so({
53
53
  actionWidth: P = 190,
54
54
  draggable: t,
55
55
  rowSelection: H,
56
- ...yt
56
+ ...pt
57
57
  }) {
58
58
  const { t: U } = zt(), w = x(
59
- () => p.map(({ hideInTable: o, hidden: r, width: s, label: f, halign: T, ...R }) => {
60
- const E = ut.getRealName(R.name);
59
+ () => y.map(({ hideInTable: o, hidden: r, width: s, label: f, halign: l, ...S }) => {
60
+ const E = ut.getRealName(S.name);
61
61
  return {
62
62
  title: f,
63
63
  width: s,
64
64
  key: E,
65
65
  dataIndex: E,
66
66
  hidden: o || r,
67
- align: T ?? (R.type === "number" ? "right" : void 0),
68
- render: mt(R),
69
- sorter: R.sorter
67
+ align: l ?? (S.type === "number" ? "right" : void 0),
68
+ render: mt(S),
69
+ sorter: S.sorter,
70
+ defaultSortOrder: S.defaultSortOrder
70
71
  };
71
72
  }),
72
- [p]
73
- ), [m, B] = z(), [F, a] = z(), [y, b] = z([]), Ct = v((o) => {
74
- B(o);
73
+ [y]
74
+ ), [m, d] = z(), [F, a] = z(), [p, b] = z([]), Ct = v((o) => {
75
+ d(o);
75
76
  }, []);
76
77
  st(() => {
77
- S && b(S);
78
- }, [S]), st(() => {
79
- S && B((o) => {
78
+ T && b(T);
79
+ }, [T]), st(() => {
80
+ T && d((o) => {
80
81
  if (o)
81
- return S.find((r) => r[n] === o[n]);
82
+ return T.find((r) => r[n] === o[n]);
82
83
  });
83
- }, [S, n, m]);
84
+ }, [T, n, m]);
84
85
  const g = v(
85
86
  (o) => {
86
87
  var f;
87
88
  const { active: r, over: s } = o;
88
89
  if (t != null && t.onDragEnd && (t == null || t.onDragEnd(o)), r.id !== (s == null ? void 0 : s.id)) {
89
- const T = y.findIndex(
90
+ const l = p.findIndex(
90
91
  (i) => i[n] === r.id
91
- ), R = y.findIndex(
92
+ ), S = p.findIndex(
92
93
  (i) => i[n] === (s == null ? void 0 : s.id)
93
- ), E = ct(y, T, R);
94
+ ), E = ct(p, l, S);
94
95
  b((i) => {
95
- const St = i.findIndex(
96
+ const It = i.findIndex(
96
97
  (k) => k[n] === (r == null ? void 0 : r.id)
97
98
  ), Tt = i.findIndex(
98
99
  (k) => k[n] === (s == null ? void 0 : s.id)
99
100
  );
100
- return ct(i, St, Tt);
101
+ return ct(i, It, Tt);
101
102
  }), (f = t == null ? void 0 : t.onDrag) == null || f.call(t, {
102
103
  newOrder: E.map((i) => i[n])
103
104
  });
104
105
  }
105
106
  },
106
- [y, n, t]
107
- ), xt = x(() => {
107
+ [p, n, t]
108
+ ), St = x(() => {
108
109
  let o = typeof c == "string" ? m == null ? void 0 : m[c] : void 0;
109
110
  if (typeof o == "object") {
110
- const r = p.find((s) => ut.getRealName(s.name) === c);
111
+ const r = y.find((s) => ut.getRealName(s.name) === c);
111
112
  o = mt(r)(
112
113
  o,
113
114
  m,
@@ -115,7 +116,7 @@ function so({
115
116
  );
116
117
  }
117
118
  return o;
118
- }, [c, m, p]), tt = x(
119
+ }, [c, m, y]), tt = x(
119
120
  () => ({
120
121
  rowSelection: H,
121
122
  rowClassName: W,
@@ -146,7 +147,7 @@ function so({
146
147
  } : void 0,
147
148
  [u]
148
149
  ), nt = x(() => {
149
- const o = O || j || I || d || c, r = [];
150
+ const o = D || j || I || N || c, r = [];
150
151
  return t && r.push({
151
152
  key: "key",
152
153
  align: "center",
@@ -163,8 +164,8 @@ function so({
163
164
  {
164
165
  value: f,
165
166
  onClick: typeof c == "object" ? () => {
166
- var T;
167
- return (T = c.onClick) == null ? void 0 : T.call(c, f);
167
+ var l;
168
+ return (l = c.onClick) == null ? void 0 : l.call(c, f);
168
169
  } : Ct
169
170
  }
170
171
  ),
@@ -173,61 +174,61 @@ function so({
173
174
  {
174
175
  data: f,
175
176
  idField: n,
176
- extraAction: d,
177
- onUpdate: O,
177
+ extraAction: N,
178
+ onUpdate: D,
178
179
  onClickUpdate: j,
179
180
  onClickClone: _,
180
181
  onDelete: I,
181
- onHide: N,
182
+ onHide: B,
182
183
  onExport: X,
183
- isHiding: D,
184
- isDeleting: l,
184
+ isHiding: O,
185
+ isDeleting: R,
185
186
  confirmHiding: Y,
186
187
  confirmDeleting: Z,
187
188
  closeViewOnClickUpdate: Q,
188
189
  recentUpdateOrDeleteId: F,
189
190
  setRecentUpdateOrDeleteId: a,
190
- setOpenView: B
191
+ setOpenView: d
191
192
  }
192
193
  )
193
194
  ] })
194
195
  }), r;
195
196
  }, [
196
197
  w,
197
- O,
198
+ D,
198
199
  j,
199
200
  I,
200
- d,
201
+ N,
201
202
  c,
202
203
  U,
203
204
  P
204
205
  ]), rt = x(
205
- () => y.map((o) => o[n]),
206
- [y, n]
207
- ), It = v(() => {
206
+ () => p.map((o) => o[n]),
207
+ [p, n]
208
+ ), xt = v(() => {
208
209
  const o = /* @__PURE__ */ e(
209
210
  qt,
210
211
  {
211
212
  ...tt,
212
213
  summary: h,
213
- dataSource: y,
214
+ dataSource: p,
214
215
  loading: C,
215
216
  components: t ? { body: { row: Jt } } : void 0,
216
217
  pagination: ot,
217
218
  columns: nt
218
219
  }
219
220
  );
220
- return t ? /* @__PURE__ */ e(lt, { modifiers: [Bt], onDragEnd: g, children: /* @__PURE__ */ e(
221
- Nt,
221
+ return t ? /* @__PURE__ */ e(Rt, { modifiers: [dt], onDragEnd: g, children: /* @__PURE__ */ e(
222
+ Bt,
222
223
  {
223
224
  items: rt,
224
- strategy: Ot,
225
+ strategy: Dt,
225
226
  children: o
226
227
  }
227
228
  ) }) : o;
228
229
  }, [
229
230
  tt,
230
- y,
231
+ p,
231
232
  C,
232
233
  ot,
233
234
  nt,
@@ -238,48 +239,48 @@ function so({
238
239
  ]);
239
240
  return /* @__PURE__ */ L("div", { children: [
240
241
  (typeof c == "boolean" || typeof c == "string") && /* @__PURE__ */ e(
241
- Rt,
242
+ lt,
242
243
  {
243
244
  width: "100%",
244
245
  open: !!m,
245
- title: xt ?? /* @__PURE__ */ e("div", { children: " " }),
246
+ title: St ?? /* @__PURE__ */ e("div", { children: " " }),
246
247
  footer: /* @__PURE__ */ e(et, {}),
247
248
  closable: !0,
248
- onCancel: () => B(void 0),
249
+ onCancel: () => d(void 0),
249
250
  children: !!m && /* @__PURE__ */ L("div", { children: [
250
251
  /* @__PURE__ */ e(
251
252
  At,
252
253
  {
253
- layout: pt,
254
+ layout: yt,
254
255
  descListColumn: ht,
255
256
  data: m,
256
- fields: p,
257
+ fields: y,
257
258
  idField: n,
258
- extraAction: d,
259
- onUpdate: O,
259
+ extraAction: N,
260
+ onUpdate: D,
260
261
  onClickUpdate: j,
261
262
  onClickClone: _,
262
263
  onDelete: I,
263
- onHide: N,
264
+ onHide: B,
264
265
  onExport: X,
265
- isHiding: D,
266
- isDeleting: l,
266
+ isHiding: O,
267
+ isDeleting: R,
267
268
  confirmHiding: Y,
268
269
  confirmDeleting: Z,
269
270
  closeViewOnClickUpdate: Q,
270
271
  recentUpdateOrDeleteId: F,
271
272
  setRecentUpdateOrDeleteId: a,
272
- setOpenView: B
273
+ setOpenView: d
273
274
  }
274
275
  ),
275
276
  V == null ? void 0 : V(m)
276
277
  ] }, m == null ? void 0 : m[n])
277
278
  }
278
279
  ),
279
- /* @__PURE__ */ e(vt, { fields: p, ...yt }),
280
+ /* @__PURE__ */ e(vt, { fields: y, ...pt }),
280
281
  /* @__PURE__ */ L($t, { children: [
281
282
  !!K && /* @__PURE__ */ e(Et, { onClick: K }),
282
- It()
283
+ xt()
283
284
  ] })
284
285
  ] });
285
286
  }
@@ -301,21 +302,21 @@ const it = ft.createContext({}), Gt = ({ tooltip: h }) => {
301
302
  const {
302
303
  attributes: n,
303
304
  listeners: C,
304
- setNodeRef: p,
305
- setActivatorNodeRef: l,
306
- transform: D,
305
+ setNodeRef: y,
306
+ setActivatorNodeRef: R,
307
+ transform: O,
307
308
  transition: c,
308
309
  isDragging: u
309
- } = dt({ id: h["data-row-key"] }), I = {
310
+ } = Nt({ id: h["data-row-key"] }), I = {
310
311
  ...h.style,
311
- transform: Dt.Translate.toString(D),
312
+ transform: Ot.Translate.toString(O),
312
313
  transition: c,
313
314
  ...u ? { position: "relative", zIndex: 9999 } : {}
314
- }, N = x(
315
- () => ({ setActivatorNodeRef: l, listeners: C }),
316
- [l, C]
315
+ }, B = x(
316
+ () => ({ setActivatorNodeRef: R, listeners: C }),
317
+ [R, C]
317
318
  );
318
- return /* @__PURE__ */ e(it.Provider, { value: N, children: /* @__PURE__ */ e("tr", { ...h, ref: p, style: I, ...n }) });
319
+ return /* @__PURE__ */ e(it.Provider, { value: B, children: /* @__PURE__ */ e("tr", { ...h, ref: y, style: I, ...n }) });
319
320
  };
320
321
  export {
321
322
  so as default
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kingteza/crud-component",
3
3
  "private": false,
4
- "version": "1.25.0",
4
+ "version": "1.26.0",
5
5
  "description": "React CRUD component library with Ant Design",
6
6
  "keywords": [
7
7
  "react",