@kingteza/crud-component 1.0.13 → 1.0.15

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 (119) hide show
  1. package/dist/components/common/DatePicker/DatePicker.cjs +1 -0
  2. package/dist/components/common/DatePicker/DatePicker.js +88 -0
  3. package/dist/components/common/DatePicker/TimePicker.cjs +1 -0
  4. package/dist/components/common/DatePicker/TimePicker.js +78 -0
  5. package/dist/components/common/appearance/Hider.cjs +1 -0
  6. package/dist/components/common/appearance/Hider.js +5 -0
  7. package/dist/components/common/button/Button.cjs +1 -0
  8. package/dist/components/common/button/Button.js +64 -0
  9. package/dist/components/common/button/CloneButtonTable.cjs +1 -0
  10. package/dist/components/common/button/CloneButtonTable.js +20 -0
  11. package/dist/components/common/button/DeleteButtonTable.cjs +1 -0
  12. package/dist/components/common/button/DeleteButtonTable.js +68 -0
  13. package/dist/components/common/button/ExportButton.cjs +1 -0
  14. package/dist/components/common/button/ExportButton.js +27 -0
  15. package/dist/components/common/button/HideButtonTable.cjs +1 -0
  16. package/dist/components/common/button/HideButtonTable.js +68 -0
  17. package/dist/components/common/button/ImportButton.cjs +1 -0
  18. package/dist/components/common/button/ImportButton.js +56 -0
  19. package/dist/components/common/button/NewButton.cjs +1 -0
  20. package/dist/components/common/button/NewButton.js +24 -0
  21. package/dist/components/common/button/PrintButton.cjs +1 -0
  22. package/dist/components/common/button/PrintButton.js +26 -0
  23. package/dist/components/common/button/RefreshButton.cjs +1 -0
  24. package/dist/components/common/button/RefreshButton.js +24 -0
  25. package/dist/components/common/button/UnHideButton.cjs +1 -0
  26. package/dist/components/common/button/UnHideButton.js +70 -0
  27. package/dist/components/common/button/UpdateButtonTable.cjs +1 -0
  28. package/dist/components/common/button/UpdateButtonTable.js +20 -0
  29. package/dist/components/common/button/ViewButtonTable.cjs +1 -0
  30. package/dist/components/common/button/ViewButtonTable.js +20 -0
  31. package/dist/components/common/check-box/CheckBox.cjs +1 -0
  32. package/dist/components/common/check-box/CheckBox.js +40 -0
  33. package/dist/components/common/description/DescList.cjs +1 -0
  34. package/dist/components/common/description/DescList.js +16 -0
  35. package/dist/components/common/layout/VerticalSpace.cjs +1 -0
  36. package/dist/components/common/layout/VerticalSpace.js +6 -0
  37. package/dist/components/common/loading/LoadingIndicator.cjs +1 -0
  38. package/dist/components/common/loading/LoadingIndicator.js +24 -0
  39. package/dist/components/common/picker/ImagePicker.cjs +1 -0
  40. package/dist/components/common/picker/ImagePicker.js +282 -0
  41. package/dist/components/common/radio/RadioGroupComponent.cjs +1 -0
  42. package/dist/components/common/radio/RadioGroupComponent.js +19 -0
  43. package/dist/components/common/report/SelectFieldInReport.cjs +1 -0
  44. package/dist/components/common/report/SelectFieldInReport.js +30 -0
  45. package/dist/components/common/select/CustomSelectOption.cjs +1 -0
  46. package/dist/components/common/select/CustomSelectOption.js +13 -0
  47. package/dist/components/common/select/SelectComponent.cjs +1 -0
  48. package/dist/components/common/select/SelectComponent.js +89 -0
  49. package/dist/components/common/show-more/index.cjs +1 -0
  50. package/dist/components/common/show-more/index.js +8 -0
  51. package/dist/components/common/tab/TabViewWithRoute.cjs +1 -0
  52. package/dist/components/common/tab/TabViewWithRoute.js +38 -0
  53. package/dist/components/common/table/table.cjs +1 -0
  54. package/dist/components/common/table/table.js +40 -0
  55. package/dist/components/common/tag/StatusTag.cjs +1 -0
  56. package/dist/components/common/tag/StatusTag.js +30 -0
  57. package/dist/components/common/text/index.cjs +1 -0
  58. package/dist/components/common/text/index.js +5 -0
  59. package/dist/components/common/text/title/index.cjs +1 -0
  60. package/dist/components/common/text/title/index.js +5 -0
  61. package/dist/components/common/text-field/NumberField.cjs +1 -0
  62. package/dist/components/common/text-field/NumberField.js +83 -0
  63. package/dist/components/common/text-field/PhoneNumberField.cjs +1 -0
  64. package/dist/components/common/text-field/PhoneNumberField.js +18 -0
  65. package/dist/components/common/text-field/TextArea.cjs +1 -0
  66. package/dist/components/common/text-field/TextArea.js +47 -0
  67. package/dist/components/common/text-field/TextField.cjs +1 -0
  68. package/dist/components/common/text-field/TextField.js +73 -0
  69. package/dist/components/common/tooltip/TooltipComponent.cjs +1 -0
  70. package/dist/components/common/tooltip/TooltipComponent.js +9 -0
  71. package/dist/components/common/wizard/WizardResult.cjs +1 -0
  72. package/dist/components/common/wizard/WizardResult.js +60 -0
  73. package/dist/components/common/wizard/WizardViewForm.cjs +1 -0
  74. package/dist/components/common/wizard/WizardViewForm.js +74 -0
  75. package/dist/components/crud/CrudComponent.cjs +1 -0
  76. package/dist/components/crud/CrudComponent.js +210 -0
  77. package/dist/components/crud/CrudField.cjs +1 -0
  78. package/dist/components/crud/CrudField.js +459 -0
  79. package/dist/components/crud/CrudForm.cjs +1 -0
  80. package/dist/components/crud/CrudForm.js +91 -0
  81. package/dist/components/crud/CrudFormWizard.cjs +1 -0
  82. package/dist/components/crud/CrudFormWizard.js +140 -0
  83. package/dist/components/crud/CrudReportComponent.cjs +4 -0
  84. package/dist/components/crud/CrudReportComponent.js +255 -0
  85. package/dist/components/crud/CrudSearchComponent.cjs +1 -0
  86. package/dist/components/crud/CrudSearchComponent.js +95 -0
  87. package/dist/components/crud/FileCrudField.cjs +1 -0
  88. package/dist/components/crud/FileCrudField.js +220 -0
  89. package/dist/components/crud/ImageCrudField.cjs +1 -0
  90. package/dist/components/crud/ImageCrudField.js +113 -0
  91. package/dist/components/crud/import/CrudImportButton.cjs +1 -0
  92. package/dist/components/crud/import/CrudImportButton.js +31 -0
  93. package/dist/components/crud/import/CrudImportComponent.cjs +2 -0
  94. package/dist/components/crud/import/CrudImportComponent.js +221 -0
  95. package/dist/components/crud/view/CrudDecListView.cjs +1 -0
  96. package/dist/components/crud/view/CrudDecListView.js +42 -0
  97. package/dist/components/crud/view/CrudViewer.cjs +1 -0
  98. package/dist/components/crud/view/CrudViewer.js +217 -0
  99. package/dist/components/crud/view/CrudViewerUtil.cjs +1 -0
  100. package/dist/components/crud/view/CrudViewerUtil.js +57 -0
  101. package/dist/index.cjs +1 -1
  102. package/dist/index.js +10 -10
  103. package/dist/locale/hooks/translation-constants.cjs +1 -0
  104. package/dist/locale/hooks/translation-constants.js +4 -0
  105. package/dist/locale/index.cjs +1 -0
  106. package/dist/locale/index.js +33 -0
  107. package/dist/locale/translations/en.cjs +1 -0
  108. package/dist/locale/translations/en.js +60 -0
  109. package/dist/util/DateUtil.cjs +1 -0
  110. package/dist/util/DateUtil.js +6 -0
  111. package/dist/util/ImageUtil.cjs +1 -0
  112. package/dist/util/ImageUtil.js +63 -0
  113. package/dist/util/NumberUtil.cjs +1 -0
  114. package/dist/util/NumberUtil.js +60 -0
  115. package/dist/util/ValidationUtil.cjs +1 -0
  116. package/dist/util/ValidationUtil.js +60 -0
  117. package/dist/util/index.cjs +1 -1
  118. package/dist/util/index.js +4 -4
  119. package/package.json +1 -1
@@ -0,0 +1,210 @@
1
+ import { jsxs as y, Fragment as se, jsx as c } from "react/jsx-runtime";
2
+ import { Space as D, Modal as re, Spin as ce, Form as me } from "antd";
3
+ import fe from "dayjs";
4
+ import { useState as m, useCallback as F, useEffect as de } from "react";
5
+ import { useTranslation as ue } from "react-i18next";
6
+ import { TRANSLATION_NAMESPACE as pe } from "../../locale/hooks/translation-constants.js";
7
+ import { CrudForm as ye } from "./CrudForm.js";
8
+ import Fe from "./CrudFormWizard.js";
9
+ import ge from "./import/CrudImportButton.js";
10
+ import ve from "./view/CrudViewer.js";
11
+ import { NewButton as Ce } from "../common/button/NewButton.js";
12
+ import { PrintButton as Be } from "../common/button/PrintButton.js";
13
+ const { useForm: he } = me;
14
+ function Ie({
15
+ idField: g = "id",
16
+ onCreate: B,
17
+ onDelete: U,
18
+ onHide: W,
19
+ onUpdate: d,
20
+ fields: l,
21
+ data: w,
22
+ grid: L,
23
+ isHiding: H,
24
+ isCreating: V,
25
+ isDeleting: R,
26
+ isUpdating: P,
27
+ paginateProps: q,
28
+ onPrint: A,
29
+ printing: G,
30
+ viewable: J,
31
+ loadingData: K,
32
+ formBuilder: Q,
33
+ extraAction: X,
34
+ minusHeight: Y,
35
+ cloneable: Z,
36
+ fullWidthModal: $ = !0,
37
+ wizard: a,
38
+ extraView: z,
39
+ importable: j,
40
+ onClickNew: O,
41
+ ...ee
42
+ }) {
43
+ const { t: h } = ue(pe), [k, v] = m(!1), [u, b] = m(), [te, x] = m(), [i] = he(), T = F(
44
+ async (o) => {
45
+ const r = a ? o : await i.validateFields(), s = l.filter((e) => e.type === "color"), n = {};
46
+ s.forEach((e) => {
47
+ var f;
48
+ const t = i.getFieldValue(e.name);
49
+ n[e.name] = typeof t == "string" ? t : (f = t == null ? void 0 : t.toHexString()) == null ? void 0 : f.toUpperCase();
50
+ }), Object.assign(r, n), u && d ? (await d({
51
+ ...r,
52
+ [g]: u[g]
53
+ }), b(void 0)) : !u && B && await B(r), x(void 0), i.resetFields(), v(!1);
54
+ },
55
+ [l, i, g, B, d, u, a]
56
+ ), [oe, E] = m(!1), [ne, S] = m(!1);
57
+ de(() => {
58
+ k ? (E(!1), S(!1)) : C(void 0);
59
+ }, [k]);
60
+ const I = F(async (o) => {
61
+ E(o), S(!0);
62
+ }, []), M = F(async () => {
63
+ S(!0);
64
+ }, []), [le, _] = m(!1), N = F(
65
+ async (o, r = !0, s = !1) => {
66
+ try {
67
+ _(!0), v(!0), r && C("update");
68
+ const n = {};
69
+ for (const e of l) {
70
+ const t = o[e.name];
71
+ if (s && e.type === "image") {
72
+ const f = t;
73
+ try {
74
+ const ie = await e.provider.clone(f);
75
+ n[e.name] = ie;
76
+ continue;
77
+ } catch {
78
+ continue;
79
+ }
80
+ }
81
+ e.type === "date" ? t && (n[e.name] = fe(t)) : e.type === "select" ? e.multiple && Array.isArray(t) ? n[e.name] = t.map(
82
+ (f) => f[e.innerFieldId ?? "id"]
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;
84
+ }
85
+ i.setFieldsValue(n), x(n), r && b(o);
86
+ } finally {
87
+ _(!1);
88
+ }
89
+ },
90
+ [l, i]
91
+ ), [p, C] = m(), ae = F(
92
+ async (o) => {
93
+ C("clone"), N(o, !1, !0);
94
+ },
95
+ [N]
96
+ );
97
+ return /* @__PURE__ */ y(se, { children: [
98
+ /* @__PURE__ */ y(D, { direction: "vertical", className: "w-100", children: [
99
+ /* @__PURE__ */ y("div", { className: "w-100 d-flex", children: [
100
+ /* @__PURE__ */ c("div", { style: { flex: 1 }, children: /* @__PURE__ */ c(
101
+ Ce,
102
+ {
103
+ onClick: () => {
104
+ O ? O() : (v((o) => !o), C("new"));
105
+ },
106
+ className: "flex-1"
107
+ }
108
+ ) }),
109
+ /* @__PURE__ */ y(D, { children: [
110
+ !!A && /* @__PURE__ */ c(
111
+ Be,
112
+ {
113
+ className: "float-right",
114
+ loading: G,
115
+ onClick: A
116
+ }
117
+ ),
118
+ !!j && /* @__PURE__ */ c(ge, { fields: l, importProps: j })
119
+ ] })
120
+ ] }),
121
+ /* @__PURE__ */ c(
122
+ ve,
123
+ {
124
+ ...ee,
125
+ minusHeight: Y,
126
+ data: w,
127
+ fields: l,
128
+ extraAction: X,
129
+ idField: g,
130
+ isDeleting: R,
131
+ loadingData: K,
132
+ onClickUpdate: d ? N : void 0,
133
+ onHide: W,
134
+ isHiding: H,
135
+ onDelete: U,
136
+ onUpdate: d,
137
+ onClickClone: Z ? ae : void 0,
138
+ paginateProps: q,
139
+ viewable: J,
140
+ extraView: z
141
+ }
142
+ )
143
+ ] }),
144
+ /* @__PURE__ */ c(
145
+ re,
146
+ {
147
+ width: $ ? "100%" : void 0,
148
+ title: h(p ?? "new"),
149
+ open: k,
150
+ confirmLoading: V || P,
151
+ okText: h("str." + (p === "update" ? "update" : "save")),
152
+ cancelText: h("str.cancel"),
153
+ cancelButtonProps: {
154
+ disabled: ne,
155
+ hidden: !!a
156
+ },
157
+ okButtonProps: {
158
+ disabled: oe,
159
+ hidden: !!a
160
+ },
161
+ onCancel: async () => {
162
+ try {
163
+ if (p === "clone") {
164
+ const o = a ? u : i.getFieldsValue(), r = l.filter((s) => s.type === "image");
165
+ for (const s of r)
166
+ o[s.name] && s.provider.delete(
167
+ o[s.name]
168
+ );
169
+ }
170
+ } finally {
171
+ }
172
+ a || i.resetFields(), x(void 0), b(void 0), v(!1);
173
+ },
174
+ onOk: () => T(),
175
+ destroyOnClose: !0,
176
+ children: /* @__PURE__ */ y(ce, { spinning: le, children: [
177
+ !a && /* @__PURE__ */ c(
178
+ ye,
179
+ {
180
+ purpose: p,
181
+ fields: l,
182
+ form: i,
183
+ formBuilder: Q,
184
+ grid: L,
185
+ onDeleteFile: M,
186
+ onUploadFile: I
187
+ }
188
+ ),
189
+ a && /* @__PURE__ */ c(
190
+ Fe,
191
+ {
192
+ submitting: V || P,
193
+ className: "mt-2",
194
+ onSave: T,
195
+ updatingValue: te,
196
+ fields: l,
197
+ onDeleteFile: M,
198
+ onUploadFile: I,
199
+ purpose: p,
200
+ wizard: a
201
+ }
202
+ )
203
+ ] })
204
+ }
205
+ )
206
+ ] });
207
+ }
208
+ export {
209
+ Ie as default
210
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("react/jsx-runtime"),v=require("antd"),q=require("react"),D=require("react-highlight-words"),W=require("react-i18next"),G=require("../../locale/hooks/translation-constants.cjs"),$=require("./FileCrudField.cjs"),z=require("./ImageCrudField.cjs"),J=require("../common/DatePicker/DatePicker.cjs"),K=require("../common/DatePicker/TimePicker.cjs"),Q=require("../common/check-box/CheckBox.cjs"),L=require("../common/select/SelectComponent.cjs"),X=require("../common/text-field/NumberField.cjs"),Y=require("../common/text-field/TextField.cjs"),Z=require("../common/text-field/TextArea.cjs"),V=require("../common/tooltip/TooltipComponent.cjs");function ee(F){const{label:o,name:c,type:p,required:i,hidden:N,rules:m=[],updatable:h=!0,readonly:S=!1,fieldClassName:C,customFormFieldRender:w,fieldTooltip:b,...e}=F,g=v.Form.useFormInstance();q.useEffect(()=>{if(p==="select"){const{items:a=[],onSearch:n,searchOnType:l}=e;!(a!=null&&a.length)&&!l&&(n==null||n(void 0,g,e==null?void 0:e.updatingValue))}},[g,e,p,e==null?void 0:e.updatingValue]);const{t:T}=W.useTranslation(G.TRANSLATION_NAMESPACE);if(S||N)return t.jsx(t.Fragment,{});if(w)return w(g,F);switch(p){case"text":case"email":case"password":{const{onChange:a,placeholder:n}=e;return t.jsx(Y.default,{placeholder:n,disabled:!h,rules:m,required:i,onChange:a?l=>a(l,g):void 0,type:p,name:c,tooltip:b,label:o,className:C,autoComplete:"new-password"})}case"number":{const{onChange:a,placeholder:n,allowMinus:l}=e;return t.jsx(X,{placeholder:n,disabled:!h,moneyField:!!e.formatted,type:p,onChange:a?f=>a(f,g):void 0,rules:m,autoComplete:"false",required:i,tooltip:b,className:C,min:l?null:void 0,name:c,label:o})}case"date":{const{range:a,disableToday:n,disabledFutureDays:l,disabledPastDays:f,onChange:x,placeholder:u,format:y}=e;return t.jsx(J,{placeholder:u,required:i,disabled:!h,type:p,format:y,tooltip:b,range:a,name:c,label:o,onChange:x?s=>x(s,g):void 0,className:C,disableToday:n,disabledFutureDays:l,disabledPastDays:f})}case"time":{const{range:a=!1,disableCurrent:n,disabledFuture:l,disabledPast:f,onChange:x,use12Hours:u,format:y,placeholder:s}=e;return t.jsx(K,{placeholder:s,required:i,format:y,disabled:!h,type:p,tooltip:b,range:a,use12Hours:u,name:c,label:o,onChange:x?j=>x(j,g):void 0,className:C,disableCurrent:n,disabledFuture:l,disabledPast:f})}case"textarea":{const{onChange:a,placeholder:n,rows:l,cols:f}=e;return t.jsx(Z.default,{rules:m,placeholder:n,onChange:a?x=>{var u;return a((u=x==null?void 0:x.target)==null?void 0:u.value,g)}:void 0,tooltip:b,required:i,disabled:!h,name:c,label:o,className:C,rows:l,cols:f})}case"image":return t.jsx(z.default,{...e,required:i,name:c,label:o,rules:m,fieldClassName:C,onRemoved:e.onRemoved,onUploading:e.onUploading,provider:e.provider});case"file":return t.jsx($.default,{...e,required:i,name:c,label:o,rules:m,fieldClassName:C,onRemoved:e.onRemoved,onUploading:e.onUploading,provider:e.provider});case"select":return t.jsx(B,{...e,required:i,name:c,label:o,rules:m,fieldClassName:C,form:g,updatable:h,readonly:S,fieldTooltip:b});case"enum":{const{enum:a,radio:n=!1,translation:l,onChange:f,onSearch:x,multiple:u}=e,y=Array.isArray(a)?a:Object.keys(a);return n?t.jsx(v.Form.Item,{...e,name:c,required:i,tooltip:b,rules:m,label:o,className:["w-100",C].join(" "),children:t.jsx(v.Radio.Group,{...e,onChange:f?s=>{var j;return f((j=s==null?void 0:s.target)==null?void 0:j.value,g)}:void 0,children:y.map(s=>t.jsx(v.Radio,{disabled:!h,value:s,children:l?T(l[s]):s},s))})}):t.jsx(L,{...e,onChange:f?s=>f(s,g):void 0,className:["w-100",C].join(" "),name:c,items:y,required:i,tooltip:b,rules:m,label:o,disabled:!h,onSearch:x?s=>x(s,g):void 0,allowClear:!0,mode:u?"multiple":void 0,itemBuilder:s=>t.jsx(v.Select.Option,{value:s,children:l?T(l[s]):s},s)})}case"checkbox":{const{onChange:a}=e;return t.jsx(Q,{className:C,rules:m,onChange:a?n=>a(n,g):void 0,label:o,tooltip:b,disabled:!h,name:c})}case"color":return t.jsx(H,{...e,type:"color",required:i,name:c,label:o,rules:m,fieldClassName:C,updatable:h,readonly:S,fieldTooltip:b});default:return t.jsx(t.Fragment,{children:`${p} Not Implemented`})}}function B(F){const{items:o=[],loading:c,searchOnType:p,onSearch:i,multiple:N,onChange:m,highlightSearch:h,required:S,fieldClassName:C,rules:w,fieldTooltip:b,updatable:e,label:g,name:T,tagRender:a,updatingValue:n,onSet:l,placeholder:f,allowClear:x=!0}=F,u=F.form,[y,s]=q.useState(""),j=v.Form.useWatch(T,u),[k,O]=q.useState(!0);q.useEffect(()=>{l&&k&&j&&(l==null||l(j,o,u),O(!1))},[k,u,o,T,l,j]),q.useEffect(()=>{j&&O(!0)},[j]);const M=q.useCallback(async r=>{s(r),p&&(i==null||i(r,u,n))},[u,i,p,n]);return t.jsx(L,{...F,maxTagCount:"responsive",maxTagPlaceholder:r=>t.jsxs(V,{title:t.jsx(t.Fragment,{children:r.map(d=>t.jsxs(t.Fragment,{children:[d.label," ",t.jsx("br",{})]}))}),children:["+",r==null?void 0:r.length]}),placeholder:f,onSelect:r=>{l==null||l(r==null?void 0:r.key,o,u)},onChange:m?r=>{s(""),m(r,u)}:void 0,mode:N?"multiple":void 0,className:["w-100",C].join(" "),name:T,items:o,required:S,tooltip:b,tagRender:a,rules:w,disabled:!e,label:g,allowClear:x,onSearch:M,loading:c,filterOption:h?(r,d)=>{var R,P,A;try{const I=r.toLowerCase().split(/\s+/),U=((typeof(d==null?void 0:d.children)=="string"?d==null?void 0:d.children:(P=(R=d==null?void 0:d.children)==null?void 0:R.props)==null?void 0:P.textToHighlight)??"").toLowerCase(),_=(((A=d==null?void 0:d.value)==null?void 0:A.toString())??"").toLowerCase();return I.every(E=>U.indexOf(E)>=0||_.indexOf(E)>=0)}catch{return!0}}:void 0,itemBuilder:h?r=>{const d=r.value?String(r.value):void 0;return t.jsx(v.Select.Option,{value:r.key,title:d,disabled:r.disabled,children:t.jsx(D,{highlightClassName:"highlight-text",searchWords:(y??"").split(" "),autoEscape:!0,textToHighlight:d??""})},r.key)}:r=>t.jsx(v.Select.Option,{value:r.key,title:r.value,disabled:r.disabled,children:r.value},r.key)})}function H(F){const{required:o,fieldClassName:c,rules:p,fieldTooltip:i,updatable:N,label:m,name:h}=F;return t.jsx(v.Form.Item,{label:m,name:h,required:o,rules:p,tooltip:i,children:t.jsx(v.ColorPicker,{disabledAlpha:!0,format:"hex",defaultFormat:"hex",showText:!0,trigger:"click",className:c,disabled:!N,...F.innerProps})})}exports.ColorCrudFieldComponent=H;exports.SelectCrudFieldComponent=B;exports.default=ee;
@@ -0,0 +1,459 @@
1
+ import { jsx as a, Fragment as O, jsxs as U } from "react/jsx-runtime";
2
+ import { Form as S, Radio as q, Select as A, ColorPicker as $ } from "antd";
3
+ import { useEffect as P, useState as D, useCallback as z } from "react";
4
+ import J from "react-highlight-words";
5
+ import { useTranslation as K } from "react-i18next";
6
+ import { TRANSLATION_NAMESPACE as Q } from "../../locale/hooks/translation-constants.js";
7
+ import X from "./FileCrudField.js";
8
+ import Y from "./ImageCrudField.js";
9
+ import Z from "../common/DatePicker/DatePicker.js";
10
+ import V from "../common/DatePicker/TimePicker.js";
11
+ import ee from "../common/check-box/CheckBox.js";
12
+ import M from "../common/select/SelectComponent.js";
13
+ import re from "../common/text-field/NumberField.js";
14
+ import te from "../common/text-field/TextField.js";
15
+ import oe from "../common/text-field/TextArea.js";
16
+ import ae from "../common/tooltip/TooltipComponent.js";
17
+ function Ne(x) {
18
+ const {
19
+ label: i,
20
+ name: c,
21
+ type: b,
22
+ required: s,
23
+ hidden: F,
24
+ rules: u = [],
25
+ updatable: h = !0,
26
+ readonly: w = !1,
27
+ fieldClassName: f,
28
+ customFormFieldRender: k,
29
+ fieldTooltip: v,
30
+ ...e
31
+ } = x, p = S.useFormInstance();
32
+ P(() => {
33
+ if (b === "select") {
34
+ const {
35
+ items: t = [],
36
+ onSearch: n,
37
+ searchOnType: o
38
+ } = e;
39
+ !(t != null && t.length) && !o && (n == null || n(void 0, p, e == null ? void 0 : e.updatingValue));
40
+ }
41
+ }, [p, e, b, e == null ? void 0 : e.updatingValue]);
42
+ const { t: N } = K(Q);
43
+ if (w || F) return /* @__PURE__ */ a(O, {});
44
+ if (k)
45
+ return k(p, x);
46
+ switch (b) {
47
+ case "text":
48
+ case "email":
49
+ case "password": {
50
+ const { onChange: t, placeholder: n } = e;
51
+ return /* @__PURE__ */ a(
52
+ te,
53
+ {
54
+ placeholder: n,
55
+ disabled: !h,
56
+ rules: u,
57
+ required: s,
58
+ onChange: t ? (o) => t(o, p) : void 0,
59
+ type: b,
60
+ name: c,
61
+ tooltip: v,
62
+ label: i,
63
+ className: f,
64
+ autoComplete: "new-password"
65
+ }
66
+ );
67
+ }
68
+ case "number": {
69
+ const { onChange: t, placeholder: n, allowMinus: o } = e;
70
+ return /* @__PURE__ */ a(
71
+ re,
72
+ {
73
+ placeholder: n,
74
+ disabled: !h,
75
+ moneyField: !!e.formatted,
76
+ type: b,
77
+ onChange: t ? (g) => t(g, p) : void 0,
78
+ rules: u,
79
+ autoComplete: "false",
80
+ required: s,
81
+ tooltip: v,
82
+ className: f,
83
+ min: o ? null : void 0,
84
+ name: c,
85
+ label: i
86
+ }
87
+ );
88
+ }
89
+ case "date": {
90
+ const {
91
+ range: t,
92
+ disableToday: n,
93
+ disabledFutureDays: o,
94
+ disabledPastDays: g,
95
+ onChange: C,
96
+ placeholder: m,
97
+ format: T
98
+ } = e;
99
+ return /* @__PURE__ */ a(
100
+ Z,
101
+ {
102
+ placeholder: m,
103
+ required: s,
104
+ disabled: !h,
105
+ type: b,
106
+ format: T,
107
+ tooltip: v,
108
+ range: t,
109
+ name: c,
110
+ label: i,
111
+ onChange: C ? (l) => C(l, p) : void 0,
112
+ className: f,
113
+ disableToday: n,
114
+ disabledFutureDays: o,
115
+ disabledPastDays: g
116
+ }
117
+ );
118
+ }
119
+ case "time": {
120
+ const {
121
+ range: t = !1,
122
+ disableCurrent: n,
123
+ disabledFuture: o,
124
+ disabledPast: g,
125
+ onChange: C,
126
+ use12Hours: m,
127
+ format: T,
128
+ placeholder: l
129
+ } = e;
130
+ return /* @__PURE__ */ a(
131
+ V,
132
+ {
133
+ placeholder: l,
134
+ required: s,
135
+ format: T,
136
+ disabled: !h,
137
+ type: b,
138
+ tooltip: v,
139
+ range: t,
140
+ use12Hours: m,
141
+ name: c,
142
+ label: i,
143
+ onChange: C ? (y) => C(y, p) : void 0,
144
+ className: f,
145
+ disableCurrent: n,
146
+ disabledFuture: o,
147
+ disabledPast: g
148
+ }
149
+ );
150
+ }
151
+ case "textarea": {
152
+ const { onChange: t, placeholder: n, rows: o, cols: g } = e;
153
+ return /* @__PURE__ */ a(
154
+ oe,
155
+ {
156
+ rules: u,
157
+ placeholder: n,
158
+ onChange: t ? (C) => {
159
+ var m;
160
+ return t((m = C == null ? void 0 : C.target) == null ? void 0 : m.value, p);
161
+ } : void 0,
162
+ tooltip: v,
163
+ required: s,
164
+ disabled: !h,
165
+ name: c,
166
+ label: i,
167
+ className: f,
168
+ rows: o,
169
+ cols: g
170
+ }
171
+ );
172
+ }
173
+ case "image":
174
+ return /* @__PURE__ */ a(
175
+ Y,
176
+ {
177
+ ...e,
178
+ required: s,
179
+ name: c,
180
+ label: i,
181
+ rules: u,
182
+ fieldClassName: f,
183
+ onRemoved: e.onRemoved,
184
+ onUploading: e.onUploading,
185
+ provider: e.provider
186
+ }
187
+ );
188
+ case "file":
189
+ return /* @__PURE__ */ a(
190
+ X,
191
+ {
192
+ ...e,
193
+ required: s,
194
+ name: c,
195
+ label: i,
196
+ rules: u,
197
+ fieldClassName: f,
198
+ onRemoved: e.onRemoved,
199
+ onUploading: e.onUploading,
200
+ provider: e.provider
201
+ }
202
+ );
203
+ case "select":
204
+ return /* @__PURE__ */ a(
205
+ le,
206
+ {
207
+ ...e,
208
+ required: s,
209
+ name: c,
210
+ label: i,
211
+ rules: u,
212
+ fieldClassName: f,
213
+ form: p,
214
+ updatable: h,
215
+ readonly: w,
216
+ fieldTooltip: v
217
+ }
218
+ );
219
+ case "enum": {
220
+ const {
221
+ enum: t,
222
+ radio: n = !1,
223
+ translation: o,
224
+ onChange: g,
225
+ onSearch: C,
226
+ multiple: m
227
+ } = e, T = Array.isArray(t) ? t : Object.keys(t);
228
+ return n ? /* @__PURE__ */ a(
229
+ S.Item,
230
+ {
231
+ ...e,
232
+ name: c,
233
+ required: s,
234
+ tooltip: v,
235
+ rules: u,
236
+ label: i,
237
+ className: ["w-100", f].join(" "),
238
+ children: /* @__PURE__ */ a(
239
+ q.Group,
240
+ {
241
+ ...e,
242
+ onChange: g ? (l) => {
243
+ var y;
244
+ return g((y = l == null ? void 0 : l.target) == null ? void 0 : y.value, p);
245
+ } : void 0,
246
+ children: T.map((l) => /* @__PURE__ */ a(q, { disabled: !h, value: l, children: o ? N(o[l]) : l }, l))
247
+ }
248
+ )
249
+ }
250
+ ) : /* @__PURE__ */ a(
251
+ M,
252
+ {
253
+ ...e,
254
+ onChange: g ? (l) => g(l, p) : void 0,
255
+ className: ["w-100", f].join(" "),
256
+ name: c,
257
+ items: T,
258
+ required: s,
259
+ tooltip: v,
260
+ rules: u,
261
+ label: i,
262
+ disabled: !h,
263
+ onSearch: C ? (l) => C(l, p) : void 0,
264
+ allowClear: !0,
265
+ mode: m ? "multiple" : void 0,
266
+ itemBuilder: (l) => /* @__PURE__ */ a(A.Option, { value: l, children: o ? N(o[l]) : l }, l)
267
+ }
268
+ );
269
+ }
270
+ case "checkbox": {
271
+ const { onChange: t } = e;
272
+ return /* @__PURE__ */ a(
273
+ ee,
274
+ {
275
+ className: f,
276
+ rules: u,
277
+ onChange: t ? (n) => t(n, p) : void 0,
278
+ label: i,
279
+ tooltip: v,
280
+ disabled: !h,
281
+ name: c
282
+ }
283
+ );
284
+ }
285
+ case "color":
286
+ return /* @__PURE__ */ a(
287
+ ne,
288
+ {
289
+ ...e,
290
+ type: "color",
291
+ required: s,
292
+ name: c,
293
+ label: i,
294
+ rules: u,
295
+ fieldClassName: f,
296
+ updatable: h,
297
+ readonly: w,
298
+ fieldTooltip: v
299
+ }
300
+ );
301
+ default:
302
+ return /* @__PURE__ */ a(O, { children: `${b} Not Implemented` });
303
+ }
304
+ }
305
+ function le(x) {
306
+ const {
307
+ items: i = [],
308
+ loading: c,
309
+ searchOnType: b,
310
+ onSearch: s,
311
+ multiple: F,
312
+ onChange: u,
313
+ highlightSearch: h,
314
+ required: w,
315
+ fieldClassName: f,
316
+ rules: k,
317
+ fieldTooltip: v,
318
+ updatable: e,
319
+ label: p,
320
+ name: N,
321
+ tagRender: t,
322
+ updatingValue: n,
323
+ onSet: o,
324
+ placeholder: g,
325
+ allowClear: C = !0
326
+ } = x, m = x.form, [T, l] = D(""), y = S.useWatch(N, m), [R, j] = D(!0);
327
+ P(() => {
328
+ o && R && y && (o == null || o(y, i, m), j(!1));
329
+ }, [R, m, i, N, o, y]), P(() => {
330
+ y && j(!0);
331
+ }, [y]);
332
+ const W = z(
333
+ async (r) => {
334
+ l(r), b && (s == null || s(r, m, n));
335
+ },
336
+ [m, s, b, n]
337
+ );
338
+ return /* @__PURE__ */ a(
339
+ M,
340
+ {
341
+ ...x,
342
+ maxTagCount: "responsive",
343
+ maxTagPlaceholder: (r) => /* @__PURE__ */ U(
344
+ ae,
345
+ {
346
+ title: /* @__PURE__ */ a(O, { children: r.map((d) => /* @__PURE__ */ U(O, { children: [
347
+ d.label,
348
+ " ",
349
+ /* @__PURE__ */ a("br", {})
350
+ ] })) }),
351
+ children: [
352
+ "+",
353
+ r == null ? void 0 : r.length
354
+ ]
355
+ }
356
+ ),
357
+ placeholder: g,
358
+ onSelect: (r) => {
359
+ o == null || o(r == null ? void 0 : r.key, i, m);
360
+ },
361
+ onChange: u ? (r) => {
362
+ l(""), u(r, m);
363
+ } : void 0,
364
+ mode: F ? "multiple" : void 0,
365
+ className: ["w-100", f].join(" "),
366
+ name: N,
367
+ items: i,
368
+ required: w,
369
+ tooltip: v,
370
+ tagRender: t,
371
+ rules: k,
372
+ disabled: !e,
373
+ label: p,
374
+ allowClear: C,
375
+ onSearch: W,
376
+ loading: c,
377
+ filterOption: h ? (r, d) => {
378
+ var I, L, B;
379
+ try {
380
+ const E = r.toLowerCase().split(/\s+/), _ = ((typeof (d == null ? void 0 : d.children) == "string" ? d == null ? void 0 : d.children : (L = (I = d == null ? void 0 : d.children) == null ? void 0 : I.props) == null ? void 0 : L.textToHighlight) ?? "").toLowerCase(), G = (((B = d == null ? void 0 : d.value) == null ? void 0 : B.toString()) ?? "").toLowerCase();
381
+ return E.every(
382
+ (H) => _.indexOf(H) >= 0 || G.indexOf(H) >= 0
383
+ );
384
+ } catch {
385
+ return !0;
386
+ }
387
+ } : void 0,
388
+ itemBuilder: h ? (r) => {
389
+ const d = r.value ? String(r.value) : void 0;
390
+ return /* @__PURE__ */ a(
391
+ A.Option,
392
+ {
393
+ value: r.key,
394
+ title: d,
395
+ disabled: r.disabled,
396
+ children: /* @__PURE__ */ a(
397
+ J,
398
+ {
399
+ highlightClassName: "highlight-text",
400
+ searchWords: (T ?? "").split(" "),
401
+ autoEscape: !0,
402
+ textToHighlight: d ?? ""
403
+ }
404
+ )
405
+ },
406
+ r.key
407
+ );
408
+ } : (r) => /* @__PURE__ */ a(
409
+ A.Option,
410
+ {
411
+ value: r.key,
412
+ title: r.value,
413
+ disabled: r.disabled,
414
+ children: r.value
415
+ },
416
+ r.key
417
+ )
418
+ }
419
+ );
420
+ }
421
+ function ne(x) {
422
+ const {
423
+ required: i,
424
+ fieldClassName: c,
425
+ rules: b,
426
+ fieldTooltip: s,
427
+ updatable: F,
428
+ label: u,
429
+ name: h
430
+ } = x;
431
+ return /* @__PURE__ */ a(
432
+ S.Item,
433
+ {
434
+ label: u,
435
+ name: h,
436
+ required: i,
437
+ rules: b,
438
+ tooltip: s,
439
+ children: /* @__PURE__ */ a(
440
+ $,
441
+ {
442
+ disabledAlpha: !0,
443
+ format: "hex",
444
+ defaultFormat: "hex",
445
+ showText: !0,
446
+ trigger: "click",
447
+ className: c,
448
+ disabled: !F,
449
+ ...x.innerProps
450
+ }
451
+ )
452
+ }
453
+ );
454
+ }
455
+ export {
456
+ ne as ColorCrudFieldComponent,
457
+ le as SelectCrudFieldComponent,
458
+ Ne as default
459
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),i=require("react"),u=require("antd"),g=require("./CrudField.cjs");function h({form:d,purpose:m="new",...s}){return t.jsx(t.Fragment,{children:t.jsx(u.Form,{form:d,layout:"vertical",children:t.jsx(y,{...s,purpose:m})})})}function y({fields:d,formBuilder:m,grid:s,onDeleteFile:l,onUploadFile:o,purpose:c}){const f=i.useMemo(()=>d.filter(r=>!r.readonly).map(r=>{const a={onUploading:e=>{var n;r.onUploading&&((n=r.onUploading)==null||n.call(r,e)),o==null||o(e)},onDelete:e=>{var n;r.onUploading&&((n=r.onDelete)==null||n.call(r,e)),l==null||l(e)}};return t.jsx(i.Fragment,{children:r.grid&&s?t.jsx(u.Col,{...r.grid,children:i.createElement(g.default,{...r,...a,key:typeof r.name=="string"?r.name:String(r.name),updatable:c!=="update"?!0:r.updatable})}):i.createElement(g.default,{...r,...a,key:typeof r.name=="string"?r.name:String(r.name),updatable:c!=="update"?!0:r.updatable})},r.name)}),[d,s,l,o,c]),j=i.useCallback((r,a={})=>{const e=d.find(n=>n.name===r);if(e!=null&&e.hidden)return t.jsx(t.Fragment,{});if(e){const n=i.createElement(g.default,{...e,...a,key:typeof e.name=="string"?e.name:String(e.name),updatable:c!=="update"?!0:e.updatable});return a.render?a.render(n):n}return t.jsx(t.Fragment,{})},[d,c]);return t.jsx(t.Fragment,{children:m?t.jsxs(t.Fragment,{children:[m(j,{isAnyFieldHidden(...r){const a=Array.isArray(r)?r:[r];return d.filter(n=>a.includes(n.name)).some(n=>n.hidden)},isAllFieldsHidden(...r){const a=Array.isArray(r)?r:[r];return d.filter(n=>a.includes(n.name)).every(n=>n.hidden)}}),t.jsxs(u.Form.Item,{hidden:!0,noStyle:!0,children:[t.jsx(u.Input,{name:"id"}),t.jsx(u.Input,{})]})]}):s?t.jsx(u.Row,{gutter:[8,8],children:f}):f})}exports.CrudForm=h;exports.CrudFormFields=y;