@kingteza/crud-component 1.0.51 → 1.0.54

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.
Files changed (60) hide show
  1. package/App.d.ts +1 -0
  2. package/Play.d.ts +2 -0
  3. package/_virtual/_commonjsHelpers.cjs.js +1 -0
  4. package/_virtual/_commonjsHelpers.es.js +8 -0
  5. package/_virtual/_nodeUtil.cjs.js +1 -0
  6. package/_virtual/_nodeUtil.es.js +4 -0
  7. package/_virtual/index.cjs.js +1 -0
  8. package/_virtual/index.cjs2.js +1 -0
  9. package/_virtual/index.cjs3.js +1 -0
  10. package/_virtual/index.es.js +11 -0
  11. package/_virtual/index.es2.js +7 -0
  12. package/_virtual/index.es3.js +4 -0
  13. package/_virtual/isBuffer.cjs.js +1 -0
  14. package/_virtual/isBuffer.es.js +4 -0
  15. package/_virtual/quill.cjs.js +1 -0
  16. package/_virtual/quill.es.js +4 -0
  17. package/common/button/Button.cjs.js +1 -1
  18. package/common/button/Button.es.js +38 -52
  19. package/common/button/CloneButtonTable.cjs.js +1 -1
  20. package/common/button/HideButtonTable.cjs.js +1 -1
  21. package/common/button/NewButton.cjs.js +1 -1
  22. package/common/button/PrintButton.cjs.js +1 -1
  23. package/common/button/RefreshButton.cjs.js +1 -1
  24. package/common/button/UnHideButton.cjs.js +1 -1
  25. package/common/button/UpdateButtonTable.cjs.js +1 -1
  26. package/common/button/ViewButtonTable.cjs.js +1 -1
  27. package/common/icon/KIcon.cjs.js +1 -0
  28. package/common/icon/KIcon.d.ts +9 -0
  29. package/common/icon/KIcon.es.js +11 -0
  30. package/common/index.cjs.js +1 -1
  31. package/common/index.es.js +68 -68
  32. package/common/picker/ImagePicker.cjs.js +1 -1
  33. package/common/picker/ImagePicker.es.js +228 -189
  34. package/common/rich/index.cjs.js +1 -1
  35. package/common/rich/index.es.js +10 -10
  36. package/common/select/SelectComponent.es.js +4 -4
  37. package/common/tab/TabViewWithRoute.cjs.js +1 -1
  38. package/common/tab/TabViewWithRoute.es.js +21 -21
  39. package/common/table/table.d.ts +1 -1
  40. package/common/text-field/TextField.cjs.js +1 -1
  41. package/common/wizard/WizardResult.es.js +4 -4
  42. package/crud/CrudComponent.cjs.js +1 -1
  43. package/crud/CrudComponent.d.ts +5 -1
  44. package/crud/CrudComponent.es.js +66 -64
  45. package/crud/CrudField.es.js +1 -1
  46. package/crud/CrudReportComponent.cjs.js +1 -1
  47. package/crud/FileCrudField.cjs.js +1 -1
  48. package/crud/FileCrudField.es.js +23 -23
  49. package/crud/import/CrudImportComponent.cjs.js +2 -2
  50. package/crud/import/CrudImportComponent.es.js +10 -10
  51. package/crud/view/CrudViewer.cjs.js +1 -1
  52. package/crud/view/CrudViewer.d.ts +11 -1
  53. package/crud/view/CrudViewer.es.js +285 -174
  54. package/index.cjs.js +1 -1
  55. package/index.es.js +19 -19
  56. package/locale/index.d.ts +5 -0
  57. package/locale/translations/en.cjs.js +1 -1
  58. package/locale/translations/en.d.ts +5 -0
  59. package/locale/translations/en.es.js +7 -2
  60. package/package.json +7 -2
@@ -1,38 +1,38 @@
1
- import { jsxs as v, jsx as e } from "react/jsx-runtime";
2
- import { Tabs as r, Layout as x } from "antd";
3
- import { useState as g, useEffect as y } from "react";
4
- import { useNavigate as S, Outlet as w } from "react-router";
5
- import { useLocation as N } from "react-router-dom";
6
- import P from "../../context/WindowDimension.es.js";
7
- const { Content: T } = x, A = ({
8
- positionOfRoute: c,
9
- initialKey: o = "*",
1
+ import { jsxs as x, jsx as e } from "react/jsx-runtime";
2
+ import { Tabs as a, Layout as y } from "antd";
3
+ import { useState as S, useEffect as w } from "react";
4
+ import { useLocation as N, Outlet as P } from "react-router-dom";
5
+ import { useNavigateOptional as T } from "../../hooks/NavigatorHooks.es.js";
6
+ import $ from "../../context/WindowDimension.es.js";
7
+ const { Content: j } = y, E = ({
8
+ positionOfRoute: r,
9
+ initialKey: s = "*",
10
10
  tabs: i,
11
11
  className: m = "",
12
12
  mode: l = "default"
13
13
  }) => {
14
- const [p, u] = g(o), s = S(), f = (t) => {
15
- s(t);
14
+ const [p, u] = S(s), t = T(), f = (o) => {
15
+ t == null || t(o);
16
16
  }, n = N();
17
- y(() => {
18
- const t = n.pathname.split("/")[c];
19
- u(t ?? ""), t || s(o, { replace: !0 });
20
- }, [o, n.pathname, s, c]);
21
- const { isDesktop: d } = P(), a = l === "side" && d, h = a ? "left" : "top";
22
- return /* @__PURE__ */ v("div", { className: `${m} ${a ? "d-flex h-100" : ""}`, children: [
17
+ w(() => {
18
+ const o = n.pathname.split("/")[r];
19
+ u(o ?? ""), o || t == null || t(s, { replace: !0 });
20
+ }, [s, n.pathname, t, r]);
21
+ const { isDesktop: d } = $(), c = l === "side" && d, h = c ? "left" : "top";
22
+ return /* @__PURE__ */ x("div", { className: `${m} ${c ? "d-flex h-100" : ""}`, children: [
23
23
  /* @__PURE__ */ e(
24
- r,
24
+ a,
25
25
  {
26
26
  type: "card",
27
27
  tabPosition: h,
28
28
  activeKey: p,
29
29
  onChange: f,
30
- children: i.map(({ key: t, label: b }) => /* @__PURE__ */ e(r.TabPane, { tab: b }, t))
30
+ children: i.map(({ key: o, label: b }) => /* @__PURE__ */ e(a.TabPane, { tab: b }, o))
31
31
  }
32
32
  ),
33
- /* @__PURE__ */ e(T, { className: `max-height ${a ? "overflow-auto" : ""}`, children: /* @__PURE__ */ e(w, {}) })
33
+ /* @__PURE__ */ e(j, { className: `max-height ${c ? "overflow-auto" : ""}`, children: /* @__PURE__ */ e(P, {}) })
34
34
  ] });
35
35
  };
36
36
  export {
37
- A as TabViewWithRoute
37
+ E as TabViewWithRoute
38
38
  };
@@ -5,7 +5,7 @@ export type TableComponentColumnProp<T> = {
5
5
  render?: (value: any, record: T, index: number) => React.ReactNode;
6
6
  hidden?: boolean;
7
7
  title?: any;
8
- align?: 'right' | 'left';
8
+ align?: 'right' | 'left' | 'center';
9
9
  width?: number | string;
10
10
  }[] & ColumnsType<T>;
11
11
  export interface TableComponentProps<T> extends TableProps<T> {
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("react/jsx-runtime"),R=require("@ant-design/icons"),d=require("antd"),S=require("react"),_=require("../../locale/index.cjs.js"),$=require("../tooltip/TooltipComponent.cjs.js"),c=(n,t,e,i)=>{var s;t&&e&&(n.preventDefault(),(s=e==null?void 0:e.getFieldInstance(t))==null||s.focus()),i&&i(n)},A=({type:n,required:t,label:e,disabled:i,rules:s=[],placeholder:u,onEnter:l,size:p,form:x,addonAfter:g,addonBefore:m,nextFocus:f,autoComplete:j="off",defaultValue:q,readOnly:v,value:I,loading:T,onBlur:F,inputRef:P,status:h,autoFocus:C,onChange:D,tooltip:E,...M})=>{const{t:a}=_.useTranslationLib(),w=S.useMemo(()=>{const r=[...s,{required:t,message:`${e??u??""} ${a("err.validation.required")}`}];return n==="email"&&r.push({type:"email",message:a("err.validation.invalidEmail")}),r},[s,t,e,u,a,n]),L={disabled:i,value:I,readOnly:v,defaultValue:q,autoFocus:C,addonBefore:m,ref:P,onBlur:F,addonAfter:T?o.jsx(R.LoadingOutlined,{}):g,status:h,size:p,autoComplete:j,onPressEnter:r=>c(r,f,x,l),type:n,placeholder:u??e},O=n=="password"?d.Input.Password:d.Input;return o.jsx($,{title:E,children:o.jsx(d.Form.Item,{...M,label:e,rules:w,children:o.jsx(O,{...L})})})};exports.default=A;exports.onEnterInternalTextField=c;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("react/jsx-runtime"),R=require("@ant-design/icons"),d=require("antd"),S=require("react"),_=require("../../locale/index.cjs.js"),$=require("../tooltip/TooltipComponent.cjs.js"),c=(n,t,e,i)=>{var s;t&&e&&(n.preventDefault(),(s=e==null?void 0:e.getFieldInstance(t))==null||s.focus()),i&&i(n)},A=({type:n,required:t,label:e,disabled:i,rules:s=[],placeholder:u,onEnter:l,size:p,form:x,addonAfter:g,addonBefore:m,nextFocus:I,autoComplete:f="off",defaultValue:j,readOnly:q,value:v,loading:T,onBlur:F,inputRef:P,status:h,autoFocus:C,onChange:D,tooltip:E,...M})=>{const{t:a}=_.useTranslationLib(),w=S.useMemo(()=>{const r=[...s,{required:t,message:`${e??u??""} ${a("err.validation.required")}`}];return n==="email"&&r.push({type:"email",message:a("err.validation.invalidEmail")}),r},[s,t,e,u,a,n]),L={disabled:i,value:v,readOnly:q,defaultValue:j,autoFocus:C,addonBefore:m,ref:P,onBlur:F,addonAfter:T?o.jsx(R.LoadingOutlined,{}):g,status:h,size:p,autoComplete:f,onPressEnter:r=>c(r,I,x,l),type:n,placeholder:u??e},O=n=="password"?d.Input.Password:d.Input;return o.jsx($,{title:E,children:o.jsx(d.Form.Item,{...M,label:e,rules:w,children:o.jsx(O,{...L})})})};exports.default=A;exports.onEnterInternalTextField=c;
@@ -1,5 +1,5 @@
1
- import { jsx as o, Fragment as s, jsxs as j } from "react/jsx-runtime";
2
- import { LoadingOutlined as B, ArrowLeftOutlined as C } from "@ant-design/icons";
1
+ import { jsx as o, jsxs as j, Fragment as s } from "react/jsx-runtime";
2
+ import { ArrowLeftOutlined as B, LoadingOutlined as C } from "@ant-design/icons";
3
3
  import { Result as O } from "antd";
4
4
  import e from "../button/Button.es.js";
5
5
  import { useTranslationLib as r } from "../../locale/index.es.js";
@@ -24,7 +24,7 @@ const W = ({
24
24
  {
25
25
  status: l ? void 0 : d ? "success" : t ? ["403", "404", "500"].includes(t == null ? void 0 : t.code) ? t.code : t ? "error" : void 0 : void 0,
26
26
  title: l ? L : d ? x : t ? b : void 0,
27
- icon: l ? /* @__PURE__ */ o(B, {}) : void 0,
27
+ icon: l ? /* @__PURE__ */ o(C, {}) : void 0,
28
28
  subTitle: l ? h : d ? a : t ? typeof i == "function" ? i() ?? u : i ?? u : void 0,
29
29
  extra: [
30
30
  d ? /* @__PURE__ */ o(s, { children: f }) : t ? /* @__PURE__ */ j(s, { children: [
@@ -34,7 +34,7 @@ const W = ({
34
34
  onClick: m,
35
35
  htmlType: "button",
36
36
  type: "primary",
37
- icon: /* @__PURE__ */ o(C, {}),
37
+ icon: /* @__PURE__ */ o(B, {}),
38
38
  children: n("str.previous")
39
39
  }
40
40
  ),
@@ -1 +1 @@
1
- "use strict";const n=require("react/jsx-runtime"),y=require("antd"),ae=require("dayjs"),o=require("react"),le=require("./CrudForm.cjs.js"),ie=require("./CrudFormWizard.cjs.js"),ce=require("./import/CrudImportButton.cjs.js"),re=require("./view/CrudViewer.cjs.js"),ue=require("../common/button/NewButton.cjs.js"),de=require("../common/button/PrintButton.cjs.js"),fe=require("../locale/index.cjs.js"),{useForm:pe}=y.Form;function me({idField:x="id",onCreate:g,onDelete:T,onHide:U,onUpdate:f,fields:l,data:W,grid:_,isHiding:A,isCreating:S,isDeleting:E,isUpdating:q,paginateProps:L,onPrint:V,printing:R,viewable:H,loadingData:G,formBuilder:J,extraAction:K,minusHeight:Q,cloneable:X,fullWidthModal:Y=!0,wizard:i,extraView:Z,importable:P,onClickNew:N,...$}){const{t:v}=fe.useTranslationLib(),[j,F]=o.useState(!1),[p,k]=o.useState(),[z,B]=o.useState(),[c]=pe(),O=o.useCallback(async s=>{const u=i?s:await c.validateFields(),r=l.filter(e=>e.type==="color"),a={};r.forEach(e=>{var d;const t=c.getFieldValue(e.name);a[e.name]=typeof t=="string"?t:(d=t==null?void 0:t.toHexString())==null?void 0:d.toUpperCase()}),Object.assign(u,a),p&&f?(await f({...u,[x]:p[x]}),k(void 0)):!p&&g&&await g(u),B(void 0),c.resetFields(),F(!1)},[l,c,x,g,f,p,i]),[ee,w]=o.useState(!1),[te,b]=o.useState(!1);o.useEffect(()=>{j?(w(!1),b(!1)):C(void 0)},[j]);const D=o.useCallback(async s=>{w(s),b(!0)},[]),I=o.useCallback(async()=>{b(!0)},[]),[ne,M]=o.useState(!1),h=o.useCallback(async(s,u=!0,r=!1)=>{try{M(!0),F(!0),u&&C("update");const a={};for(const e of l){const t=s[e.name];if(r&&e.type==="image"){const d=t;try{const oe=await e.provider.clone(d);a[e.name]=oe;continue}catch{continue}}e.type==="date"?t&&(a[e.name]=ae(t)):e.type==="select"?e.multiple&&Array.isArray(t)?a[e.name]=t.map(d=>d[e.innerFieldId??"id"]):t&&typeof t=="object"?a[e.name]=t[e.innerFieldId??"id"]:(t&&typeof t=="string"||typeof t=="number")&&(a[e.name]=t):a[e.name]=t}c.setFieldsValue(a),B(a),u&&k(s)}finally{M(!1)}},[l,c]),[m,C]=o.useState(),se=o.useCallback(async s=>{C("clone"),h(s,!1,!0)},[h]);return n.jsxs(n.Fragment,{children:[n.jsxs(y.Space,{direction:"vertical",className:"w-100",children:[n.jsxs("div",{className:"w-100 d-flex",children:[n.jsx("div",{style:{flex:1},children:n.jsx(ue.NewButton,{onClick:()=>{N?N():(F(s=>!s),C("new"))},className:"flex-1"})}),n.jsxs(y.Space,{children:[!!V&&n.jsx(de.PrintButton,{className:"float-right",loading:R,onClick:V}),!!P&&n.jsx(ce,{fields:l,importProps:P})]})]}),n.jsx(re,{...$,minusHeight:Q,data:W,fields:l,extraAction:K,idField:x,isDeleting:E,loadingData:G,onClickUpdate:f?h:void 0,onHide:U,isHiding:A,onDelete:T,onUpdate:f,onClickClone:X?se:void 0,paginateProps:L,viewable:H,extraView:Z})]}),n.jsx(y.Modal,{width:Y?"100%":void 0,title:v(m??"new"),open:j,confirmLoading:S||q,okText:v("str."+(m==="update"?"update":"save")),cancelText:v("str.cancel"),cancelButtonProps:{disabled:te,hidden:!!i},okButtonProps:{disabled:ee,hidden:!!i},onCancel:async()=>{try{if(m==="clone"){const s=i?p:c.getFieldsValue(),u=l.filter(r=>r.type==="image");for(const r of u)s[r.name]&&r.provider.delete(s[r.name])}}finally{}i||c.resetFields(),B(void 0),k(void 0),F(!1)},onOk:()=>O(),destroyOnClose:!0,children:n.jsxs(y.Spin,{spinning:ne,children:[!i&&n.jsx(le.CrudForm,{purpose:m,fields:l,form:c,formBuilder:J,grid:_,onDeleteFile:I,onUploadFile:D}),i&&n.jsx(ie,{submitting:S||q,className:"mt-2",onSave:O,updatingValue:z,fields:l,onDeleteFile:I,onUploadFile:D,purpose:m,wizard:i})]})})]})}module.exports=me;
1
+ "use strict";const n=require("react/jsx-runtime"),y=require("antd"),le=require("dayjs"),o=require("react"),ie=require("./CrudForm.cjs.js"),ce=require("./CrudFormWizard.cjs.js"),re=require("./import/CrudImportButton.cjs.js"),ue=require("./view/CrudViewer.cjs.js"),de=require("../common/button/NewButton.cjs.js"),fe=require("../common/button/PrintButton.cjs.js"),pe=require("../locale/index.cjs.js"),{useForm:me}=y.Form;function ye({idField:x="id",onCreate:C,onDelete:T,onHide:U,onUpdate:f,fields:l,data:W,grid:_,isHiding:A,isCreating:S,isDeleting:E,isUpdating:q,paginateProps:H,onPrint:V,printing:L,viewable:R,loadingData:G,formBuilder:J,extraAction:K,minusHeight:Q,cloneable:X,fullWidthModal:Y=!0,wizard:i,extraView:Z,importable:P,onClickNew:N,size:$,...z}){const{t:v}=pe.useTranslationLib(),[j,F]=o.useState(!1),[p,k]=o.useState(),[ee,B]=o.useState(),[c]=me(),O=o.useCallback(async s=>{const u=i?s:await c.validateFields(),r=l.filter(e=>e.type==="color"),a={};r.forEach(e=>{var d;const t=c.getFieldValue(e.name);a[e.name]=typeof t=="string"?t:(d=t==null?void 0:t.toHexString())==null?void 0:d.toUpperCase()}),Object.assign(u,a),p&&f?(await f({...u,[x]:p[x]}),k(void 0)):!p&&C&&await C(u),B(void 0),c.resetFields(),F(!1)},[l,c,x,C,f,p,i]),[te,w]=o.useState(!1),[ne,b]=o.useState(!1);o.useEffect(()=>{j?(w(!1),b(!1)):g(void 0)},[j]);const D=o.useCallback(async s=>{w(s),b(!0)},[]),I=o.useCallback(async()=>{b(!0)},[]),[se,M]=o.useState(!1),h=o.useCallback(async(s,u=!0,r=!1)=>{try{M(!0),F(!0),u&&g("update");const a={};for(const e of l){const t=s[e.name];if(r&&e.type==="image"){const d=t;try{const ae=await e.provider.clone(d);a[e.name]=ae;continue}catch{continue}}e.type==="date"?t&&(a[e.name]=le(t)):e.type==="select"?e.multiple&&Array.isArray(t)?a[e.name]=t.map(d=>d[e.innerFieldId??"id"]):t&&typeof t=="object"?a[e.name]=t[e.innerFieldId??"id"]:(t&&typeof t=="string"||typeof t=="number")&&(a[e.name]=t):a[e.name]=t}c.setFieldsValue(a),B(a),u&&k(s)}finally{M(!1)}},[l,c]),[m,g]=o.useState(),oe=o.useCallback(async s=>{g("clone"),h(s,!1,!0)},[h]);return n.jsxs(n.Fragment,{children:[n.jsxs(y.Space,{direction:"vertical",className:"w-100",children:[n.jsxs("div",{className:"w-100 d-flex",children:[n.jsx("div",{style:{flex:1},children:n.jsx(de.NewButton,{onClick:()=>{N?N():(F(s=>!s),g("new"))},className:"flex-1"})}),n.jsxs(y.Space,{children:[!!V&&n.jsx(fe.PrintButton,{className:"float-right",loading:L,onClick:V}),!!P&&n.jsx(re,{fields:l,importProps:P})]})]}),n.jsx(ue,{...z,minusHeight:Q,data:W,size:$,fields:l,extraAction:K,idField:x,isDeleting:E,loadingData:G,onClickUpdate:f?h:void 0,onHide:U,isHiding:A,onDelete:T,onUpdate:f,onClickClone:X?oe:void 0,paginateProps:H,viewable:R,extraView:Z})]}),n.jsx(y.Modal,{width:Y?"100%":void 0,title:v(m??"new"),open:j,confirmLoading:S||q,okText:v("str."+(m==="update"?"update":"save")),cancelText:v("str.cancel"),cancelButtonProps:{disabled:ne,hidden:!!i},okButtonProps:{disabled:te,hidden:!!i},onCancel:async()=>{try{if(m==="clone"){const s=i?p:c.getFieldsValue(),u=l.filter(r=>r.type==="image");for(const r of u)s[r.name]&&r.provider.delete(s[r.name])}}finally{}i||c.resetFields(),B(void 0),k(void 0),F(!1)},onOk:()=>O(),destroyOnHidden:!0,children:n.jsxs(y.Spin,{spinning:se,children:[!i&&n.jsx(ie.CrudForm,{purpose:m,fields:l,form:c,formBuilder:J,grid:_,onDeleteFile:I,onUploadFile:D}),i&&n.jsx(ce,{submitting:S||q,className:"mt-2",onSave:O,updatingValue:ee,fields:l,onDeleteFile:I,onUploadFile:D,purpose:m,wizard:i})]})})]})}module.exports=ye;
@@ -7,9 +7,11 @@ import { CrudSearchComponentProps } from './CrudSearchComponent';
7
7
  import { FileCrudField } from './FileCrudField';
8
8
  import { ImageCrudField } from './ImageCrudField';
9
9
  import { CrudImportProps } from './import/CrudImportComponent';
10
+ import { CrudDragableProps } from './view/CrudViewer';
10
11
  import { SelectTagRenderProps } from '../common/select/SelectComponent';
11
12
  import { default as IdProps } from '../types/Id';
12
13
  import { TextAreaBasedFieldProps } from './CrudTextAreaComponent';
14
+ import { SizeType } from 'antd/es/config-provider/SizeContext';
13
15
  export type SelectFieldItem = {
14
16
  key?: string | number;
15
17
  value: string | number;
@@ -224,6 +226,8 @@ export type CrudComponentProps<T, FormType = T> = {
224
226
  extraView?: (t: T) => React.ReactElement;
225
227
  importable?: CrudImportProps<T>;
226
228
  onClickNew?: () => void;
229
+ draggable?: CrudDragableProps<T>;
230
+ size?: SizeType;
227
231
  } & CrudSearchComponentProps<T, FormType>;
228
- declare function CrudComponent<T, FormType = T>({ idField, onCreate, onDelete, onHide, onUpdate, fields, data, grid, isHiding, isCreating, isDeleting, isUpdating, paginateProps, onPrint, printing, viewable, loadingData, formBuilder, extraAction, minusHeight, cloneable, fullWidthModal, wizard, extraView, importable, onClickNew, ...props }: CrudComponentProps<T, FormType>): import("react/jsx-runtime").JSX.Element;
232
+ declare function CrudComponent<T, FormType = T>({ idField, onCreate, onDelete, onHide, onUpdate, fields, data, grid, isHiding, isCreating, isDeleting, isUpdating, paginateProps, onPrint, printing, viewable, loadingData, formBuilder, extraAction, minusHeight, cloneable, fullWidthModal, wizard, extraView, importable, onClickNew, size, ...props }: CrudComponentProps<T, FormType>): import("react/jsx-runtime").JSX.Element;
229
233
  export default CrudComponent;
@@ -1,25 +1,25 @@
1
- import { jsxs as y, Fragment as se, jsx as c } from "react/jsx-runtime";
2
- import { Space as _, Modal as re, Spin as ce, Form as me } from "antd";
3
- import de from "dayjs";
4
- import { useState as m, useCallback as F, useEffect as fe } from "react";
5
- import { CrudForm as ue } from "./CrudForm.es.js";
6
- import pe from "./CrudFormWizard.es.js";
7
- import ye from "./import/CrudImportButton.es.js";
8
- import Fe from "./view/CrudViewer.es.js";
9
- import { NewButton as ge } from "../common/button/NewButton.es.js";
10
- import { PrintButton as ve } from "../common/button/PrintButton.es.js";
1
+ import { jsxs as y, Fragment as re, jsx as c } from "react/jsx-runtime";
2
+ import { Form as ce, Space as _, Modal as de, Spin as me } from "antd";
3
+ import fe from "dayjs";
4
+ import { useState as d, useCallback as F, useEffect as ue } from "react";
5
+ import { CrudForm as pe } from "./CrudForm.es.js";
6
+ import ye from "./CrudFormWizard.es.js";
7
+ import Fe from "./import/CrudImportButton.es.js";
8
+ import ge from "./view/CrudViewer.es.js";
9
+ import { NewButton as ve } from "../common/button/NewButton.es.js";
10
+ import { PrintButton as Be } from "../common/button/PrintButton.es.js";
11
11
  import { useTranslationLib as Ce } from "../locale/index.es.js";
12
- const { useForm: Be } = me;
13
- function Ie({
12
+ const { useForm: he } = ce;
13
+ function Me({
14
14
  idField: g = "id",
15
- onCreate: B,
15
+ onCreate: C,
16
16
  onDelete: w,
17
17
  onHide: A,
18
18
  onUpdate: f,
19
19
  fields: l,
20
20
  data: E,
21
- grid: L,
22
- isHiding: H,
21
+ grid: H,
22
+ isHiding: L,
23
23
  isCreating: P,
24
24
  isDeleting: q,
25
25
  isUpdating: j,
@@ -33,96 +33,98 @@ function Ie({
33
33
  minusHeight: Y,
34
34
  cloneable: Z,
35
35
  fullWidthModal: $ = !0,
36
- wizard: a,
36
+ wizard: i,
37
37
  extraView: z,
38
38
  importable: O,
39
39
  onClickNew: D,
40
- ...ee
40
+ size: ee,
41
+ ...te
41
42
  }) {
42
- const { t: h } = Ce(), [k, v] = m(!1), [u, b] = m(), [te, x] = m(), [i] = Be(), I = F(
43
+ const { t: h } = Ce(), [k, v] = d(!1), [u, b] = d(), [oe, x] = d(), [a] = he(), I = F(
43
44
  async (o) => {
44
- const r = a ? o : await i.validateFields(), s = l.filter((e) => e.type === "color"), n = {};
45
+ const r = i ? o : await a.validateFields(), s = l.filter((e) => e.type === "color"), n = {};
45
46
  s.forEach((e) => {
46
- var d;
47
- const t = i.getFieldValue(e.name);
48
- n[e.name] = typeof t == "string" ? t : (d = t == null ? void 0 : t.toHexString()) == null ? void 0 : d.toUpperCase();
47
+ var m;
48
+ const t = a.getFieldValue(e.name);
49
+ n[e.name] = typeof t == "string" ? t : (m = t == null ? void 0 : t.toHexString()) == null ? void 0 : m.toUpperCase();
49
50
  }), Object.assign(r, n), u && f ? (await f({
50
51
  ...r,
51
52
  [g]: u[g]
52
- }), b(void 0)) : !u && B && await B(r), x(void 0), i.resetFields(), v(!1);
53
+ }), b(void 0)) : !u && C && await C(r), x(void 0), a.resetFields(), v(!1);
53
54
  },
54
- [l, i, g, B, f, u, a]
55
- ), [oe, M] = m(!1), [ne, V] = m(!1);
56
- fe(() => {
57
- k ? (M(!1), V(!1)) : C(void 0);
55
+ [l, a, g, C, f, u, i]
56
+ ), [ne, M] = d(!1), [le, V] = d(!1);
57
+ ue(() => {
58
+ k ? (M(!1), V(!1)) : B(void 0);
58
59
  }, [k]);
59
60
  const T = F(async (o) => {
60
61
  M(o), V(!0);
61
62
  }, []), U = F(async () => {
62
63
  V(!0);
63
- }, []), [le, W] = m(!1), S = F(
64
+ }, []), [ie, W] = d(!1), S = F(
64
65
  async (o, r = !0, s = !1) => {
65
66
  try {
66
- W(!0), v(!0), r && C("update");
67
+ W(!0), v(!0), r && B("update");
67
68
  const n = {};
68
69
  for (const e of l) {
69
70
  const t = o[e.name];
70
71
  if (s && e.type === "image") {
71
- const d = t;
72
+ const m = t;
72
73
  try {
73
- const ie = await e.provider.clone(d);
74
- n[e.name] = ie;
74
+ const se = await e.provider.clone(m);
75
+ n[e.name] = se;
75
76
  continue;
76
77
  } catch {
77
78
  continue;
78
79
  }
79
80
  }
80
- e.type === "date" ? t && (n[e.name] = de(t)) : e.type === "select" ? e.multiple && Array.isArray(t) ? n[e.name] = t.map(
81
- (d) => d[e.innerFieldId ?? "id"]
81
+ e.type === "date" ? t && (n[e.name] = fe(t)) : e.type === "select" ? e.multiple && Array.isArray(t) ? n[e.name] = t.map(
82
+ (m) => m[e.innerFieldId ?? "id"]
82
83
  ) : t && typeof t == "object" ? n[e.name] = t[e.innerFieldId ?? "id"] : (t && typeof t == "string" || typeof t == "number") && (n[e.name] = t) : n[e.name] = t;
83
84
  }
84
- i.setFieldsValue(n), x(n), r && b(o);
85
+ a.setFieldsValue(n), x(n), r && b(o);
85
86
  } finally {
86
87
  W(!1);
87
88
  }
88
89
  },
89
- [l, i]
90
- ), [p, C] = m(), ae = F(
90
+ [l, a]
91
+ ), [p, B] = d(), ae = F(
91
92
  async (o) => {
92
- C("clone"), S(o, !1, !0);
93
+ B("clone"), S(o, !1, !0);
93
94
  },
94
95
  [S]
95
96
  );
96
- return /* @__PURE__ */ y(se, { children: [
97
+ return /* @__PURE__ */ y(re, { children: [
97
98
  /* @__PURE__ */ y(_, { direction: "vertical", className: "w-100", children: [
98
99
  /* @__PURE__ */ y("div", { className: "w-100 d-flex", children: [
99
100
  /* @__PURE__ */ c("div", { style: { flex: 1 }, children: /* @__PURE__ */ c(
100
- ge,
101
+ ve,
101
102
  {
102
103
  onClick: () => {
103
- D ? D() : (v((o) => !o), C("new"));
104
+ D ? D() : (v((o) => !o), B("new"));
104
105
  },
105
106
  className: "flex-1"
106
107
  }
107
108
  ) }),
108
109
  /* @__PURE__ */ y(_, { children: [
109
110
  !!N && /* @__PURE__ */ c(
110
- ve,
111
+ Be,
111
112
  {
112
113
  className: "float-right",
113
114
  loading: J,
114
115
  onClick: N
115
116
  }
116
117
  ),
117
- !!O && /* @__PURE__ */ c(ye, { fields: l, importProps: O })
118
+ !!O && /* @__PURE__ */ c(Fe, { fields: l, importProps: O })
118
119
  ] })
119
120
  ] }),
120
121
  /* @__PURE__ */ c(
121
- Fe,
122
+ ge,
122
123
  {
123
- ...ee,
124
+ ...te,
124
125
  minusHeight: Y,
125
126
  data: E,
127
+ size: ee,
126
128
  fields: l,
127
129
  extraAction: X,
128
130
  idField: g,
@@ -130,7 +132,7 @@ function Ie({
130
132
  loadingData: Q,
131
133
  onClickUpdate: f ? S : void 0,
132
134
  onHide: A,
133
- isHiding: H,
135
+ isHiding: L,
134
136
  onDelete: w,
135
137
  onUpdate: f,
136
138
  onClickClone: Z ? ae : void 0,
@@ -141,7 +143,7 @@ function Ie({
141
143
  )
142
144
  ] }),
143
145
  /* @__PURE__ */ c(
144
- re,
146
+ de,
145
147
  {
146
148
  width: $ ? "100%" : void 0,
147
149
  title: h(p ?? "new"),
@@ -150,17 +152,17 @@ function Ie({
150
152
  okText: h("str." + (p === "update" ? "update" : "save")),
151
153
  cancelText: h("str.cancel"),
152
154
  cancelButtonProps: {
153
- disabled: ne,
154
- hidden: !!a
155
+ disabled: le,
156
+ hidden: !!i
155
157
  },
156
158
  okButtonProps: {
157
- disabled: oe,
158
- hidden: !!a
159
+ disabled: ne,
160
+ hidden: !!i
159
161
  },
160
162
  onCancel: async () => {
161
163
  try {
162
164
  if (p === "clone") {
163
- const o = a ? u : i.getFieldsValue(), r = l.filter((s) => s.type === "image");
165
+ const o = i ? u : a.getFieldsValue(), r = l.filter((s) => s.type === "image");
164
166
  for (const s of r)
165
167
  o[s.name] && s.provider.delete(
166
168
  o[s.name]
@@ -168,35 +170,35 @@ function Ie({
168
170
  }
169
171
  } finally {
170
172
  }
171
- a || i.resetFields(), x(void 0), b(void 0), v(!1);
173
+ i || a.resetFields(), x(void 0), b(void 0), v(!1);
172
174
  },
173
175
  onOk: () => I(),
174
- destroyOnClose: !0,
175
- children: /* @__PURE__ */ y(ce, { spinning: le, children: [
176
- !a && /* @__PURE__ */ c(
177
- ue,
176
+ destroyOnHidden: !0,
177
+ children: /* @__PURE__ */ y(me, { spinning: ie, children: [
178
+ !i && /* @__PURE__ */ c(
179
+ pe,
178
180
  {
179
181
  purpose: p,
180
182
  fields: l,
181
- form: i,
183
+ form: a,
182
184
  formBuilder: R,
183
- grid: L,
185
+ grid: H,
184
186
  onDeleteFile: U,
185
187
  onUploadFile: T
186
188
  }
187
189
  ),
188
- a && /* @__PURE__ */ c(
189
- pe,
190
+ i && /* @__PURE__ */ c(
191
+ ye,
190
192
  {
191
193
  submitting: P || j,
192
194
  className: "mt-2",
193
195
  onSave: I,
194
- updatingValue: te,
196
+ updatingValue: oe,
195
197
  fields: l,
196
198
  onDeleteFile: U,
197
199
  onUploadFile: T,
198
200
  purpose: p,
199
- wizard: a
201
+ wizard: i
200
202
  }
201
203
  )
202
204
  ] })
@@ -205,5 +207,5 @@ function Ie({
205
207
  ] });
206
208
  }
207
209
  export {
208
- Ie as default
210
+ Me as default
209
211
  };
@@ -1,5 +1,5 @@
1
1
  import { jsx as o, Fragment as S, jsxs as D } from "react/jsx-runtime";
2
- import { Form as j, Radio as E, Tag as W, Select as I, ColorPicker as z } from "antd";
2
+ import { Form as j, Radio as E, Select as I, Tag as W, ColorPicker as z } from "antd";
3
3
  import { useEffect as L, useState as G, useCallback as J } from "react";
4
4
  import K from "react-highlight-words";
5
5
  import { useTranslationLib as Q } from "../locale/index.es.js";
@@ -1,4 +1,4 @@
1
- "use strict";const r=require("react/jsx-runtime"),J=require("@ant-design/icons"),s=require("antd"),i=require("react"),j=require("./CrudField.cjs.js"),K=require("./view/CrudViewer.cjs.js"),M=require("../common/report/SelectFieldInReport.cjs.js"),v=require("./view/CrudViewerUtil.cjs.js"),Q=require("../common/select/SelectComponent.cjs.js"),V=require("../common/button/Button.cjs.js"),W=require("../common/button/PrintButton.cjs.js"),A={lg:6,md:8,sm:12,xs:24},X={lg:12,md:16,sm:24,xs:24};function Y({fields:d,data:u,idField:L,loadingData:p,onSubmit:x,paginateProps:G,size:O,onClickPrint:h,onClickExcelExport:y,minusHeight:U,extraSearchFields:R,searchOnMount:B,summary:_}){const{searchable:$,selectable:c,sortable:w,defaultSort:m}=i.useMemo(()=>{var b,f,N,T,I;const e=[],t=[],o=[];let a;for(const l of d.filter(H=>!H.hidden))l.type==="image"||!l.report||((b=l.report)!=null&&b.searchable&&e.push(l),(f=l.report)!=null&&f.sortable&&(t.push(l),!a&&((N=l.report)!=null&&N.defaultSort)&&(a=l)),l.hideInTable||o.push({id:l.name,label:l.label,lock:(T=l.report)==null?void 0:T.lock,alreadySelected:(I=l.report)==null?void 0:I.alreadySelected}));return{defaultSort:a,searchable:e,sortable:t,selectable:o}},[d]),[S,F]=i.useState([]),g=i.useCallback(async({sortBy:e,sortByType:t,showFields:o=[],...a})=>{const b=[];e&&b.push({field:e,sort:t??"DESC"}),F(d.filter(f=>o.includes(f.name)).map(f=>({...f,hideInTable:!1}))),x({showFields:o,sortBy:b,...a})},[d,x]),[n]=s.Form.useForm(),[q,z]=i.useState(!1),[C,D]=i.useState(!0);return i.useEffect(()=>{if(B&&C){const e=setTimeout(()=>{n.validateFields().then(t=>{g(t)}),D(!1)},200);return()=>clearTimeout(e)}},[g,n,C,B]),i.useEffect(()=>{var t,o,a;!n.getFieldValue("sortBy")&&m&&(console.log((t=m.report)==null?void 0:t.defaultSort),n.setFieldsValue({sortBy:m.name,sortByType:typeof((o=m.report)==null?void 0:o.defaultSort)=="string"?(a=m.report)==null?void 0:a.defaultSort:"ASC"}))},[m,n]),i.useEffect(()=>{if(q){const e=c.filter(t=>t.alreadySelected).map(t=>t.id);F(d.filter(t=>e.includes(t.name)).map(t=>({...t,hideInTable:!1}))),z(!1)}},[d,q,c]),r.jsxs(s.Space,{className:"w-100",direction:"vertical",children:[r.jsxs(s.Form,{form:n,layout:"vertical",onFinish:g,children:[r.jsxs(s.Row,{gutter:[8,8],children:[$.map(e=>{var t,o,a;return r.jsx(s.Col,{...e.grid??A,style:{alignSelf:"end"},children:(t=e.report)!=null&&t.customRender?e.report.customRender(n):e.type==="date"?r.jsx(j.default,{...e,type:"date",range:(o=e.report)==null?void 0:o.range,required:!!((a=e.report)!=null&&a.required),readonly:!1,fieldClassName:"mb-0"}):e.type==="select"?r.jsx(j.default,{...e,type:"select",multiple:!0,required:!1,readonly:!1,fieldClassName:"mb-0"}):r.jsx(j.default,{...e,readonly:!1,required:!1,fieldClassName:"mb-0"})},e.name)}),!!(c!=null&&c.length)&&r.jsx(s.Col,{...X,children:r.jsx(M.SelectFieldInReport,{items:c,name:"showFields",mode:"multiple",label:"Show Fields",className:"mb-0"})}),!!w.length&&r.jsx(s.Col,{...A,children:r.jsx(Q,{label:"Sort By",name:"sortBy",items:w.map(e=>({id:e.name,label:e.label})),nameFieldInArray:"label",fieldId:"id",className:"mb-0",dropdownRender:e=>r.jsxs(r.Fragment,{children:[e,r.jsx(s.Form.Item,{name:"sortByType",noStyle:!0,className:"mt-3",children:r.jsx(s.Radio.Group,{className:"w-100",defaultValue:"DESC",optionType:"button",children:r.jsxs(s.Row,{children:[r.jsx(s.Col,{xs:12,children:r.jsx(s.Radio,{className:"w-100",style:{borderTopRightRadius:0,borderBottomRightRadius:0},value:"ASC",children:"Ascending"})}),r.jsx(s.Col,{xs:12,children:r.jsx(s.Radio,{className:"w-100",style:{borderTopLeftRadius:0,borderBottomLeftRadius:0},value:"DESC",children:"Descending"})})]})})})]})})}),R?R(n):null]}),r.jsx(V,{className:"mt-3",type:"primary",block:!0,htmlType:"submit",disabled:p,children:"Submit"})]}),r.jsxs(s.Space,{children:[!!h&&r.jsx(W.PrintButton,{disabled:p||!u.length,onClick:()=>h==null?void 0:h({tableId:"#crud-table table",data:u,fields:S.map(e=>({...e,render:v.getRendererValueCrudViewer(e)}))})}),!!y&&r.jsx(V,{disabled:p||!u.length,onClick:()=>y==null?void 0:y({tableId:"#crud-table table",data:u,fields:S.map(e=>({...e,render:v.getRendererValueCrudViewer(e)}))}),icon:r.jsx(J.FileExcelOutlined,{}),className:`group
1
+ "use strict";const r=require("react/jsx-runtime"),J=require("@ant-design/icons"),s=require("antd"),d=require("react"),j=require("./CrudField.cjs.js"),K=require("./view/CrudViewer.cjs.js"),M=require("../common/report/SelectFieldInReport.cjs.js"),v=require("./view/CrudViewerUtil.cjs.js"),Q=require("../common/select/SelectComponent.cjs.js"),V=require("../common/button/Button.cjs.js"),W=require("../common/button/PrintButton.cjs.js"),A={lg:6,md:8,sm:12,xs:24},X={lg:12,md:16,sm:24,xs:24};function Y({fields:i,data:u,idField:L,loadingData:p,onSubmit:x,paginateProps:G,size:O,onClickPrint:h,onClickExcelExport:y,minusHeight:U,extraSearchFields:R,searchOnMount:B,summary:_}){const{searchable:$,selectable:c,sortable:w,defaultSort:m}=d.useMemo(()=>{var b,f,N,I,T;const e=[],t=[],o=[];let a;for(const l of i.filter(H=>!H.hidden))l.type==="image"||!l.report||((b=l.report)!=null&&b.searchable&&e.push(l),(f=l.report)!=null&&f.sortable&&(t.push(l),!a&&((N=l.report)!=null&&N.defaultSort)&&(a=l)),l.hideInTable||o.push({id:l.name,label:l.label,lock:(I=l.report)==null?void 0:I.lock,alreadySelected:(T=l.report)==null?void 0:T.alreadySelected}));return{defaultSort:a,searchable:e,sortable:t,selectable:o}},[i]),[S,F]=d.useState([]),g=d.useCallback(async({sortBy:e,sortByType:t,showFields:o=[],...a})=>{const b=[];e&&b.push({field:e,sort:t??"DESC"}),F(i.filter(f=>o.includes(f.name)).map(f=>({...f,hideInTable:!1}))),x({showFields:o,sortBy:b,...a})},[i,x]),[n]=s.Form.useForm(),[q,z]=d.useState(!1),[C,D]=d.useState(!0);return d.useEffect(()=>{if(B&&C){const e=setTimeout(()=>{n.validateFields().then(t=>{g(t)}),D(!1)},200);return()=>clearTimeout(e)}},[g,n,C,B]),d.useEffect(()=>{var t,o,a;!n.getFieldValue("sortBy")&&m&&(console.log((t=m.report)==null?void 0:t.defaultSort),n.setFieldsValue({sortBy:m.name,sortByType:typeof((o=m.report)==null?void 0:o.defaultSort)=="string"?(a=m.report)==null?void 0:a.defaultSort:"ASC"}))},[m,n]),d.useEffect(()=>{if(q){const e=c.filter(t=>t.alreadySelected).map(t=>t.id);F(i.filter(t=>e.includes(t.name)).map(t=>({...t,hideInTable:!1}))),z(!1)}},[i,q,c]),r.jsxs(s.Space,{className:"w-100",direction:"vertical",children:[r.jsxs(s.Form,{form:n,layout:"vertical",onFinish:g,children:[r.jsxs(s.Row,{gutter:[8,8],children:[$.map(e=>{var t,o,a;return r.jsx(s.Col,{...e.grid??A,style:{alignSelf:"end"},children:(t=e.report)!=null&&t.customRender?e.report.customRender(n):e.type==="date"?r.jsx(j.default,{...e,type:"date",range:(o=e.report)==null?void 0:o.range,required:!!((a=e.report)!=null&&a.required),readonly:!1,fieldClassName:"mb-0"}):e.type==="select"?r.jsx(j.default,{...e,type:"select",multiple:!0,required:!1,readonly:!1,fieldClassName:"mb-0"}):r.jsx(j.default,{...e,readonly:!1,required:!1,fieldClassName:"mb-0"})},e.name)}),!!(c!=null&&c.length)&&r.jsx(s.Col,{...X,children:r.jsx(M.SelectFieldInReport,{items:c,name:"showFields",mode:"multiple",label:"Show Fields",className:"mb-0"})}),!!w.length&&r.jsx(s.Col,{...A,children:r.jsx(Q,{label:"Sort By",name:"sortBy",items:w.map(e=>({id:e.name,label:e.label})),nameFieldInArray:"label",fieldId:"id",className:"mb-0",dropdownRender:e=>r.jsxs(r.Fragment,{children:[e,r.jsx(s.Form.Item,{name:"sortByType",noStyle:!0,className:"mt-3",children:r.jsx(s.Radio.Group,{className:"w-100",defaultValue:"DESC",optionType:"button",children:r.jsxs(s.Row,{children:[r.jsx(s.Col,{xs:12,children:r.jsx(s.Radio,{className:"w-100",style:{borderTopRightRadius:0,borderBottomRightRadius:0},value:"ASC",children:"Ascending"})}),r.jsx(s.Col,{xs:12,children:r.jsx(s.Radio,{className:"w-100",style:{borderTopLeftRadius:0,borderBottomLeftRadius:0},value:"DESC",children:"Descending"})})]})})})]})})}),R?R(n):null]}),r.jsx(V,{className:"mt-3",type:"primary",block:!0,htmlType:"submit",disabled:p,children:"Submit"})]}),r.jsxs(s.Space,{children:[!!h&&r.jsx(W.PrintButton,{disabled:p||!u.length,onClick:()=>h==null?void 0:h({tableId:"#crud-table table",data:u,fields:S.map(e=>({...e,render:v.getRendererValueCrudViewer(e)}))})}),!!y&&r.jsx(V,{disabled:p||!u.length,onClick:()=>y==null?void 0:y({tableId:"#crud-table table",data:u,fields:S.map(e=>({...e,render:v.getRendererValueCrudViewer(e)}))}),icon:r.jsx(J.FileExcelOutlined,{}),className:`group
2
2
  ${p||!u.length?"":"!bg-green-700 hover:!bg-green-600 !text-white !border-green-700 hover:!border-green-600"}
3
3
 
4
4
  `,children:"Excel"})]}),_,r.jsx(K,{minusHeight:U,data:u,size:O,fields:S,idField:L,loadingData:p,paginateProps:G,viewable:!1})]})}module.exports=Y;
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("react/jsx-runtime");;/* empty css */const d=require("@ant-design/icons"),F=require("antd"),k=require("mime"),c=require("react"),B=require("../locale/index.cjs.js"),H=require("../util/ValidationUtil.cjs.js"),p=require("../common/button/Button.cjs.js"),z=require("../common/layout/VerticalSpace.cjs.js");function G({name:n,label:e,required:l,provider:s,onUploading:a,onRemoved:h,fieldClassName:j,accept:P,rules:U,maxCount:O=1,block:_,...$}){const f=F.Form.useFormInstance(),x=F.Form.useWatch(n,f),[b,q]=c.useState(!1),[V,N]=c.useState(!1),A=c.useCallback(async r=>{var i,u;try{const{file:o}=r,g=o.name;q(!0),N(!0),a==null||a(!0);const C=g??"",I=C.split("."),R=I[I.length-1],W=s.generateFileName(C),M=`${await s.getInitialPath()}/${W}.${R}`;console.log({filePath:M});const D=await s.upload({...o,originFileObj:o},M);a==null||a(!1),f.setFieldValue(n,D),(i=r.onSuccess)==null||i.call(r,D)}catch(o){(u=r.onError)==null||u.call(r,o)}finally{q(!1)}},[f,n,a,s]),[w,S]=c.useState([]);c.useEffect(()=>{!V&&x&&Promise.all((Array.isArray(x)?x:[x]).map(async r=>{const i=k.getType(r),u=r.split("/").pop(),o=await s.getRealUrl(r);return{uid:r,url:o,type:i,name:u}})).then(r=>S(()=>{const i=r.map(({url:u,type:o,uid:g,name:C})=>({uid:g,url:u,type:o,response:g,thumbUrl:u,name:C}));return console.log(i),i}))},[x,V,b,s]);const L=c.useCallback(async r=>{const i=r.response,u=i||f.getFieldValue(n);await s.delete(u),h==null||h(),r&&f.setFieldsValue({[n]:null})},[f,n,h,s]);return t.jsxs(F.Form.Item,{label:e,required:l,name:n,className:j,rules:[...l?H.required(e):[],...U??[]],children:[t.jsx("input",{hidden:!0}),t.jsx(F.Upload,{...$,fileList:w,className:((w==null?void 0:w.length)??0)>=O?"hide-upload":"",maxCount:O,customRequest:A,onRemove:L,listType:"picture",onChange:({fileList:r})=>{S(r)},style:_?{width:"100%"}:void 0,children:t.jsx(p,{loading:b,children:"Upload File"})})]})}const J=({provider:n,value:e})=>{const[l,s]=c.useState();return c.useEffect(()=>{e&&n.getRealUrl(e).then(a=>{s({mimeType:k.getType(e),url:a,fileName:e.split("/").pop()??e})})},[n,e]),l?t.jsx(E,{fileName:l.fileName,url:l==null?void 0:l.url,mimeType:l==null?void 0:l.mimeType}):t.jsx(t.Fragment,{})},E=({url:n,mimeType:e="",fileName:l})=>{const s=c.useMemo(()=>e!=null&&e.includes("image")?"image":e!=null&&e.includes("pdf")?"pdf":e!=null&&e.includes("word")?"word":e!=null&&e.includes("text")?"text":e!=null&&e.includes("presentation")?"presentation":e!=null&&e.includes("excel")||e!=null&&e.includes("spreadsheet")?"excel":"file",[e]),a=c.useMemo(()=>{switch(s){case"image":return t.jsx(d.FileImageOutlined,{});case"pdf":return t.jsx(d.FilePdfOutlined,{});case"word":return t.jsx(d.FileWordOutlined,{});case"text":return t.jsx(d.FileTextOutlined,{});case"excel":return t.jsx(d.FileExcelOutlined,{});case"presentation":return t.jsx(d.FilePptOutlined,{});default:return t.jsx(d.FileOutlined,{})}},[s]),[h,j]=c.useState(!1),{t:P}=B.useTranslationLib();return s!=="file"&&s!=="text"?t.jsxs(t.Fragment,{children:[t.jsx(F.Modal,{open:h,title:l,onCancel:()=>j(!1),footer:t.jsx(t.Fragment,{}),width:"100%",style:{top:"8px",minHeight:"700px"},destroyOnClose:!0,children:t.jsxs(z,{children:[t.jsx(p,{tooltip:l,icon:t.jsx(d.ExportOutlined,{}),target:"_blank",href:n,style:{textDecoration:"none"},children:P("str.openInNewTab")}),s==="image"?t.jsx("img",{src:n,alt:l,style:{width:"100%"}}):s==="pdf"?t.jsxs("iframe",{title:l,src:n,width:"100%",height:"700px",children:["This browser does not support PDFs. Please download the PDF to view it:",t.jsx("a",{href:n,children:"Download PDF"})]}):t.jsxs("iframe",{title:l,src:`https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(n)}`,width:"100%",height:"700px",children:["This browser does not support open ",s.toUpperCase(),". Please download the",s.toUpperCase()," to view it:",t.jsxs("a",{href:n,children:["Download ",s.toUpperCase()]}),"."]})]})}),t.jsx(p,{tooltip:l,icon:a,shape:"circle",onClick:()=>j(!0)})]}):t.jsx(p,{tooltip:l,icon:a,target:"_blank",href:n,shape:"circle"})};exports.FileCellValue=E;exports.FileCrudCellValue=J;exports.default=G;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("react/jsx-runtime");;/* empty css */const d=require("@ant-design/icons"),F=require("antd"),k=require("mime"),c=require("react"),W=require("../locale/index.cjs.js"),B=require("../util/ValidationUtil.cjs.js"),p=require("../common/button/Button.cjs.js"),z=require("../common/layout/VerticalSpace.cjs.js");function G({name:n,label:e,required:l,provider:s,onUploading:a,onRemoved:h,fieldClassName:j,accept:P,rules:U,maxCount:O=1,block:_,...$}){const f=F.Form.useFormInstance(),x=F.Form.useWatch(n,f),[b,q]=c.useState(!1),[V,N]=c.useState(!1),A=c.useCallback(async r=>{var i,u;try{const{file:o}=r,g=o.name;q(!0),N(!0),a==null||a(!0);const C=g??"",S=C.split("."),L=S[S.length-1],R=s.generateFileName(C),M=`${await s.getInitialPath()}/${R}.${L}`;console.log({filePath:M});const D=await s.upload({...o,originFileObj:o},M);a==null||a(!1),f.setFieldValue(n,D),(i=r.onSuccess)==null||i.call(r,D)}catch(o){(u=r.onError)==null||u.call(r,o)}finally{q(!1)}},[f,n,a,s]),[w,I]=c.useState([]);c.useEffect(()=>{!V&&x&&Promise.all((Array.isArray(x)?x:[x]).map(async r=>{const i=k.getType(r),u=r.split("/").pop(),o=await s.getRealUrl(r);return{uid:r,url:o,type:i,name:u}})).then(r=>I(()=>{const i=r.map(({url:u,type:o,uid:g,name:C})=>({uid:g,url:u,type:o,response:g,thumbUrl:u,name:C}));return console.log(i),i}))},[x,V,b,s]);const H=c.useCallback(async r=>{const i=r.response,u=i||f.getFieldValue(n);await s.delete(u),h==null||h(),r&&f.setFieldsValue({[n]:null})},[f,n,h,s]);return t.jsxs(F.Form.Item,{label:e,required:l,name:n,className:j,rules:[...l?B.required(e):[],...U??[]],children:[t.jsx("input",{hidden:!0}),t.jsx(F.Upload,{...$,fileList:w,className:((w==null?void 0:w.length)??0)>=O?"hide-upload":"",maxCount:O,customRequest:A,onRemove:H,listType:"picture",onChange:({fileList:r})=>{I(r)},style:_?{width:"100%"}:void 0,children:t.jsx(p,{loading:b,children:"Upload File"})})]})}const J=({provider:n,value:e})=>{const[l,s]=c.useState();return c.useEffect(()=>{e&&n.getRealUrl(e).then(a=>{s({mimeType:k.getType(e),url:a,fileName:e.split("/").pop()??e})})},[n,e]),l?t.jsx(E,{fileName:l.fileName,url:l==null?void 0:l.url,mimeType:l==null?void 0:l.mimeType}):t.jsx(t.Fragment,{})},E=({url:n,mimeType:e="",fileName:l})=>{const s=c.useMemo(()=>e!=null&&e.includes("image")?"image":e!=null&&e.includes("pdf")?"pdf":e!=null&&e.includes("word")?"word":e!=null&&e.includes("text")?"text":e!=null&&e.includes("presentation")?"presentation":e!=null&&e.includes("excel")||e!=null&&e.includes("spreadsheet")?"excel":"file",[e]),a=c.useMemo(()=>{switch(s){case"image":return t.jsx(d.FileImageOutlined,{});case"pdf":return t.jsx(d.FilePdfOutlined,{});case"word":return t.jsx(d.FileWordOutlined,{});case"text":return t.jsx(d.FileTextOutlined,{});case"excel":return t.jsx(d.FileExcelOutlined,{});case"presentation":return t.jsx(d.FilePptOutlined,{});default:return t.jsx(d.FileOutlined,{})}},[s]),[h,j]=c.useState(!1),{t:P}=W.useTranslationLib();return s!=="file"&&s!=="text"?t.jsxs(t.Fragment,{children:[t.jsx(F.Modal,{open:h,title:l,onCancel:()=>j(!1),footer:t.jsx(t.Fragment,{}),width:"100%",style:{top:"8px",minHeight:"700px"},destroyOnHidden:!0,children:t.jsxs(z,{children:[t.jsx(p,{tooltip:l,icon:t.jsx(d.ExportOutlined,{}),target:"_blank",href:n,style:{textDecoration:"none"},children:P("str.openInNewTab")}),s==="image"?t.jsx("img",{src:n,alt:l,style:{width:"100%"}}):s==="pdf"?t.jsxs("iframe",{title:l,src:n,width:"100%",height:"700px",children:["This browser does not support PDFs. Please download the PDF to view it:",t.jsx("a",{href:n,children:"Download PDF"})]}):t.jsxs("iframe",{title:l,src:`https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(n)}`,width:"100%",height:"700px",children:["This browser does not support open ",s.toUpperCase(),". Please download the",s.toUpperCase()," to view it:",t.jsxs("a",{href:n,children:["Download ",s.toUpperCase()]}),"."]})]})}),t.jsx(p,{tooltip:l,icon:a,shape:"circle",onClick:()=>j(!0)})]}):t.jsx(p,{tooltip:l,icon:a,target:"_blank",href:n,shape:"circle"})};exports.FileCellValue=E;exports.FileCrudCellValue=J;exports.default=G;
@@ -17,26 +17,26 @@ function ht({
17
17
  onRemoved: u,
18
18
  fieldClassName: w,
19
19
  accept: b,
20
- rules: L,
20
+ rules: H,
21
21
  maxCount: I = 1,
22
- block: W,
23
- ..._
22
+ block: L,
23
+ ...W
24
24
  }) {
25
- const d = P.useFormInstance(), h = P.useWatch(n, d), [V, D] = p(!1), [U, q] = p(!1), B = j(
25
+ const d = P.useFormInstance(), h = P.useWatch(n, d), [V, D] = p(!1), [U, _] = p(!1), q = j(
26
26
  async (r) => {
27
- var c, o;
27
+ var c, i;
28
28
  try {
29
- const { file: i } = r, x = i.name;
30
- D(!0), q(!0), a == null || a(!0);
29
+ const { file: o } = r, x = o.name;
30
+ D(!0), _(!0), a == null || a(!0);
31
31
  const g = x ?? "", E = g.split("."), z = E[E.length - 1], G = e.generateFileName(g), M = `${await e.getInitialPath()}/${G}.${z}`;
32
32
  console.log({ filePath: M });
33
33
  const $ = await e.upload(
34
- { ...i, originFileObj: i },
34
+ { ...o, originFileObj: o },
35
35
  M
36
36
  );
37
37
  a == null || a(!1), d.setFieldValue(n, $), (c = r.onSuccess) == null || c.call(r, $);
38
- } catch (i) {
39
- (o = r.onError) == null || o.call(r, i);
38
+ } catch (o) {
39
+ (i = r.onError) == null || i.call(r, o);
40
40
  } finally {
41
41
  D(!1);
42
42
  }
@@ -47,24 +47,24 @@ function ht({
47
47
  !U && h && Promise.all(
48
48
  (Array.isArray(h) ? h : [h]).map(
49
49
  async (r) => {
50
- const c = S.getType(r), o = r.split("/").pop(), i = await e.getRealUrl(r);
50
+ const c = S.getType(r), i = r.split("/").pop(), o = await e.getRealUrl(r);
51
51
  return {
52
52
  uid: r,
53
- url: i,
53
+ url: o,
54
54
  type: c,
55
- name: o
55
+ name: i
56
56
  };
57
57
  }
58
58
  )
59
59
  ).then((r) => k(() => {
60
- const c = r.map(({ url: o, type: i, uid: x, name: g }) => ({ uid: x, url: o, type: i, response: x, thumbUrl: o, name: g }));
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 }));
61
61
  return console.log(c), c;
62
62
  }));
63
63
  }, [h, U, V, e]);
64
- const H = j(
64
+ const B = j(
65
65
  async (r) => {
66
- const c = r.response, o = c || d.getFieldValue(n);
67
- await e.delete(o), u == null || u(), r && d.setFieldsValue({ [n]: null });
66
+ const c = r.response, i = c || d.getFieldValue(n);
67
+ await e.delete(i), u == null || u(), r && d.setFieldsValue({ [n]: null });
68
68
  },
69
69
  [d, n, u, e]
70
70
  );
@@ -77,24 +77,24 @@ function ht({
77
77
  className: w,
78
78
  rules: [
79
79
  ...l ? tt.required(t) : [],
80
- ...L ?? []
80
+ ...H ?? []
81
81
  ],
82
82
  children: [
83
83
  /* @__PURE__ */ s("input", { hidden: !0 }),
84
84
  /* @__PURE__ */ s(
85
85
  y,
86
86
  {
87
- ..._,
87
+ ...W,
88
88
  fileList: F,
89
89
  className: ((F == null ? void 0 : F.length) ?? 0) >= I ? "hide-upload" : "",
90
90
  maxCount: I,
91
- customRequest: B,
92
- onRemove: H,
91
+ customRequest: q,
92
+ onRemove: B,
93
93
  listType: "picture",
94
94
  onChange: ({ fileList: r }) => {
95
95
  k(r);
96
96
  },
97
- style: W ? { width: "100%" } : void 0,
97
+ style: L ? { width: "100%" } : void 0,
98
98
  children: /* @__PURE__ */ s(C, { loading: V, children: "Upload File" })
99
99
  }
100
100
  )
@@ -149,7 +149,7 @@ const pt = ({ provider: n, value: t }) => {
149
149
  footer: /* @__PURE__ */ s(O, {}),
150
150
  width: "100%",
151
151
  style: { top: "8px", minHeight: "700px" },
152
- destroyOnClose: !0,
152
+ destroyOnHidden: !0,
153
153
  children: /* @__PURE__ */ f(et, { children: [
154
154
  /* @__PURE__ */ s(
155
155
  C,
@@ -1,2 +1,2 @@
1
- "use strict";const n=require("react/jsx-runtime"),q=require("@ant-design/icons"),V=require("papaparse"),d=require("antd"),W=require("file-saver"),a=require("react"),O=require("../../locale/index.cjs.js"),L=require("../view/CrudViewer.cjs.js"),R=require("../../util/DateUtil.cjs.js"),z=require("../../common/button/Button.cjs.js"),$=require("../../common/button/ImportButton.cjs.js");function U({onCloseMethod:w,open:y,fields:T,importProps:o}){const[u,v]=a.useState([]),[C,k]=a.useState(!1),[A,D]=a.useState(0);a.useEffect(()=>{y||(v([]),k(!1))},[y]);const p=a.useMemo(()=>new Map(T.filter(e=>{var t;return!e.hidden&&!((t=e.importProps)!=null&&t.hidden)&&!e.readonly}).map(e=>[e.name,e])),[T]),S=a.useMemo(()=>Array.from(p.values()).flatMap(e=>{var t;return[e.name,...((t=e.importProps)==null?void 0:t.extraFields)??[]]}),[p]),E=a.useCallback(async function(){const e=`${S.join(",")}
2
- `,t=new Blob([e],{type:"text/csv;charset=utf-8;"});W.saveAs(t,(o==null?void 0:o.name)+" - "+R.formatDateTimeWithSecond(new Date).replaceAll(":","-")+".csv")},[S,o==null?void 0:o.name]),{t:i}=O.useTranslationLib(),B=a.useCallback(async e=>{const t=new FileReader;t.onerror=console.error,t.onload=async r=>{var s;const c=(s=r==null?void 0:r.target)==null?void 0:s.result,l=V.parse(c,{header:!0});v(l.data)},t.readAsText(e)},[]),g=a.useMemo(()=>{var t,r,c;let e=!1;for(const l of u)for(const[s,f]of p.entries()){const h=l[s],m=h||!isNaN(h);if(f.required&&!m)if((r=(t=f.importProps)==null?void 0:t.extraFields)!=null&&r.length)for(const j of((c=f.importProps)==null?void 0:c.extraFields)??[])if(l[j]||!isNaN(l[j])){e=!1;break}else return!0;else return!0}return e},[u,p]),x=a.useCallback(e=>(t,r)=>{var l,s,f;const c=t||!isNaN(t);if(e.required&&!c){let h=i("err.validation.required");if((s=(l=e.importProps)==null?void 0:l.extraFields)!=null&&s.length){const m=(f=e.importProps)==null?void 0:f.extraFields;(m==null?void 0:m.find(N=>!r[N]))&&(h="Either one of these fields is required: "+[e.name,...m].join(", "))}return n.jsxs(d.Tooltip,{className:"d-flex",title:h,children:[n.jsx(q.WarningTwoTone,{twoToneColor:"#ee9702"}),t]})}return t},[i]),F=a.useCallback(async e=>{D(e)},[]),b=a.useCallback(async()=>{try{k(!0),await o.onClickImport(u,F),w(!1)}finally{k(!1),D(0)}},[u,o,w,F]),{modal:I}=d.App.useApp(),M=a.useCallback(async()=>{g?I.warning?I.warning({title:i("str.warning"),content:i("qus.importWithIssues"),okText:i("str.import"),onOk:b,okCancel:!0,closable:!0}):(console.error("You must wrap your react app with App component. https://ant.design/components/app"),window.confirm(i("qus.importWithIssues"))&&b()):b()},[g,b,i]);return n.jsxs(d.Modal,{title:[i("str.import"),o==null?void 0:o.name].filter(Boolean).join(" "),width:"100%",open:y,onOk:M,destroyOnClose:!0,onCancel:()=>w(!1),okText:i("str.import"),confirmLoading:C,okButtonProps:{disabled:!(u!=null&&u.length)},footer:(e,{OkBtn:t,CancelBtn:r})=>n.jsxs(d.Space,{children:[n.jsx(r,{}),n.jsx(t,{}),g&&n.jsx(d.Tooltip,{className:"d-flex",title:"Some fields have issue. Please review before submit.",children:n.jsx(q.WarningTwoTone,{twoToneColor:"#ee9702"})})]}),children:[n.jsxs(d.Space,{children:[n.jsx(z,{onClick:E,icon:n.jsx(q.DownloadOutlined,{}),children:i("str.downloadCsvTemplate")}),n.jsx($.ImportButton,{disabled:C,type:"default",onClick:B,accept:".csv",children:i("str.importCsvFile")})]}),n.jsx(d.Spin,{spinning:C,indicator:A?n.jsx(d.Progress,{type:"circle",percent:A*100,size:50,format:e=>`${parseInt(e)}%`}):void 0,children:n.jsx(L,{data:u,bordered:!0,size:"small",fields:Array.from(p.values()).flatMap(e=>{var t,r,c,l;return e.type==="text"?[{...e,label:e.name,render:x(e)},...((r=(t=e.importProps)==null?void 0:t.extraFields)==null?void 0:r.map(s=>({...e,name:s,label:s,render:x(e)})))??[]]:e.type==="select"?[{...e,label:e.name,type:"text",render:x(e)},...((l=(c=e.importProps)==null?void 0:c.extraFields)==null?void 0:l.map(s=>({...e,name:s,label:s,type:"text",render:x(e)})))??[]]:[{...e,label:e.name,render:x(e)}]})})})]})}module.exports=U;
1
+ "use strict";const n=require("react/jsx-runtime"),q=require("@ant-design/icons"),V=require("papaparse"),d=require("antd"),W=require("file-saver"),a=require("react"),O=require("../../locale/index.cjs.js"),L=require("../view/CrudViewer.cjs.js"),R=require("../../util/DateUtil.cjs.js"),z=require("../../common/button/Button.cjs.js"),$=require("../../common/button/ImportButton.cjs.js");function H({onCloseMethod:w,open:y,fields:T,importProps:o}){const[u,v]=a.useState([]),[C,k]=a.useState(!1),[A,D]=a.useState(0);a.useEffect(()=>{y||(v([]),k(!1))},[y]);const p=a.useMemo(()=>new Map(T.filter(e=>{var t;return!e.hidden&&!((t=e.importProps)!=null&&t.hidden)&&!e.readonly}).map(e=>[e.name,e])),[T]),I=a.useMemo(()=>Array.from(p.values()).flatMap(e=>{var t;return[e.name,...((t=e.importProps)==null?void 0:t.extraFields)??[]]}),[p]),E=a.useCallback(async function(){const e=`${I.join(",")}
2
+ `,t=new Blob([e],{type:"text/csv;charset=utf-8;"});W.saveAs(t,(o==null?void 0:o.name)+" - "+R.formatDateTimeWithSecond(new Date).replaceAll(":","-")+".csv")},[I,o==null?void 0:o.name]),{t:i}=O.useTranslationLib(),B=a.useCallback(async e=>{const t=new FileReader;t.onerror=console.error,t.onload=async r=>{var s;const c=(s=r==null?void 0:r.target)==null?void 0:s.result,l=V.parse(c,{header:!0});v(l.data)},t.readAsText(e)},[]),g=a.useMemo(()=>{var t,r,c;let e=!1;for(const l of u)for(const[s,f]of p.entries()){const h=l[s],m=h||!isNaN(h);if(f.required&&!m)if((r=(t=f.importProps)==null?void 0:t.extraFields)!=null&&r.length)for(const j of((c=f.importProps)==null?void 0:c.extraFields)??[])if(l[j]||!isNaN(l[j])){e=!1;break}else return!0;else return!0}return e},[u,p]),x=a.useCallback(e=>(t,r)=>{var l,s,f;const c=t||!isNaN(t);if(e.required&&!c){let h=i("err.validation.required");if((s=(l=e.importProps)==null?void 0:l.extraFields)!=null&&s.length){const m=(f=e.importProps)==null?void 0:f.extraFields;(m==null?void 0:m.find(N=>!r[N]))&&(h="Either one of these fields is required: "+[e.name,...m].join(", "))}return n.jsxs(d.Tooltip,{className:"d-flex",title:h,children:[n.jsx(q.WarningTwoTone,{twoToneColor:"#ee9702"}),t]})}return t},[i]),S=a.useCallback(async e=>{D(e)},[]),b=a.useCallback(async()=>{try{k(!0),await o.onClickImport(u,S),w(!1)}finally{k(!1),D(0)}},[u,o,w,S]),{modal:F}=d.App.useApp(),M=a.useCallback(async()=>{g?F.warning?F.warning({title:i("str.warning"),content:i("qus.importWithIssues"),okText:i("str.import"),onOk:b,okCancel:!0,closable:!0}):(console.error("You must wrap your react app with App component. https://ant.design/components/app"),window.confirm(i("qus.importWithIssues"))&&b()):b()},[g,b,i]);return n.jsxs(d.Modal,{title:[i("str.import"),o==null?void 0:o.name].filter(Boolean).join(" "),width:"100%",open:y,onOk:M,destroyOnHidden:!0,onCancel:()=>w(!1),okText:i("str.import"),confirmLoading:C,okButtonProps:{disabled:!(u!=null&&u.length)},footer:(e,{OkBtn:t,CancelBtn:r})=>n.jsxs(d.Space,{children:[n.jsx(r,{}),n.jsx(t,{}),g&&n.jsx(d.Tooltip,{className:"d-flex",title:"Some fields have issue. Please review before submit.",children:n.jsx(q.WarningTwoTone,{twoToneColor:"#ee9702"})})]}),children:[n.jsxs(d.Space,{children:[n.jsx(z,{onClick:E,icon:n.jsx(q.DownloadOutlined,{}),children:i("str.downloadCsvTemplate")}),n.jsx($.ImportButton,{disabled:C,type:"default",onClick:B,accept:".csv",children:i("str.importCsvFile")})]}),n.jsx(d.Spin,{spinning:C,indicator:A?n.jsx(d.Progress,{type:"circle",percent:A*100,size:50,format:e=>`${parseInt(e)}%`}):void 0,children:n.jsx(L,{data:u,bordered:!0,size:"small",fields:Array.from(p.values()).flatMap(e=>{var t,r,c,l;return e.type==="text"?[{...e,label:e.name,render:x(e)},...((r=(t=e.importProps)==null?void 0:t.extraFields)==null?void 0:r.map(s=>({...e,name:s,label:s,render:x(e)})))??[]]:e.type==="select"?[{...e,label:e.name,type:"text",render:x(e)},...((l=(c=e.importProps)==null?void 0:c.extraFields)==null?void 0:l.map(s=>({...e,name:s,label:s,type:"text",render:x(e)})))??[]]:[{...e,label:e.name,render:x(e)}]})})})]})}module.exports=H;