@kingteza/crud-component 1.45.0 → 1.46.1
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.
- package/dist/common/rich/index.cjs.js +2 -2
- package/dist/common/rich/index.es.js +79 -75
- package/dist/crud/CrudField.cjs.js +1 -1
- package/dist/crud/CrudField.es.js +103 -101
- package/dist/crud/FileCrudField.cjs.js +1 -1
- package/dist/crud/FileCrudField.d.ts +2 -1
- package/dist/crud/FileCrudField.es.js +133 -132
- package/dist/crud/ImageCrudField.cjs.js +1 -1
- package/dist/crud/ImageCrudField.d.ts +1 -0
- package/dist/crud/ImageCrudField.es.js +114 -103
- package/package.json +1 -1
|
@@ -1,179 +1,180 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { FileOutlined as
|
|
3
|
-
import { Form as
|
|
4
|
-
import
|
|
5
|
-
import { useState as
|
|
6
|
-
import { useTranslationLib as
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
function
|
|
1
|
+
import { jsxs as h, jsx as e, Fragment as D } from "react/jsx-runtime";
|
|
2
|
+
import { UploadOutlined as B, FileOutlined as v, FilePptOutlined as y, FileExcelOutlined as m, FileTextOutlined as T, FileWordOutlined as tt, FilePdfOutlined as et, FileImageOutlined as st, ExportOutlined as rt } from "@ant-design/icons";
|
|
3
|
+
import { Form as V, Upload as lt, Modal as nt } from "antd";
|
|
4
|
+
import z from "mime";
|
|
5
|
+
import { useState as g, useCallback as H, useEffect as A, useMemo as S } from "react";
|
|
6
|
+
import { useTranslationLib as it } from "../locale/index.es.js";
|
|
7
|
+
import at from "../util/ValidationUtil.es.js";
|
|
8
|
+
import I from "../common/button/Button.es.js";
|
|
9
|
+
import ct from "../common/layout/VerticalSpace.es.js";
|
|
10
|
+
import ot from "../util/CrudUtil.es.js";
|
|
11
|
+
import ut from "../util/ImageUtil.es.js";
|
|
12
|
+
function pt({
|
|
13
13
|
name: n,
|
|
14
14
|
label: t,
|
|
15
|
-
required:
|
|
16
|
-
provider:
|
|
17
|
-
onUploading:
|
|
18
|
-
onRemoved:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
required: r,
|
|
16
|
+
provider: s,
|
|
17
|
+
onUploading: i,
|
|
18
|
+
onRemoved: f,
|
|
19
|
+
onUploadComplete: u,
|
|
20
|
+
fieldClassName: b,
|
|
21
|
+
accept: L,
|
|
22
|
+
rules: W,
|
|
23
|
+
maxCount: N = 1,
|
|
24
|
+
block: _,
|
|
25
|
+
fieldHelper: q,
|
|
26
|
+
formLayoutProps: R,
|
|
27
|
+
preprocessBeforeUpload: w,
|
|
28
|
+
...G
|
|
28
29
|
}) {
|
|
29
|
-
const d =
|
|
30
|
-
async (
|
|
30
|
+
const d = V.useFormInstance(), J = ot.getRealName(n, "upsertFieldName"), F = V.useWatch(J, d), [k, E] = g(!1), [M, K] = g(!1), Q = H(
|
|
31
|
+
async (l) => {
|
|
31
32
|
var o, c;
|
|
32
33
|
try {
|
|
33
|
-
const { file:
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
let
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
{ ...
|
|
40
|
-
|
|
34
|
+
const { file: a } = l, O = a.name;
|
|
35
|
+
E(!0), K(!0), i == null || i(!0);
|
|
36
|
+
const P = O ?? "", j = P.split("."), Y = j[j.length - 1], Z = s.generateFileName(P), U = `${await s.getInitialPath()}/${Z}.${Y}`;
|
|
37
|
+
let C = a;
|
|
38
|
+
w && (typeof w == "function" ? C = await w(a) : w.compressImage && (C = await ut.resizeImage(a)));
|
|
39
|
+
const p = await s.upload(
|
|
40
|
+
{ ...a, originFileObj: C },
|
|
41
|
+
U
|
|
41
42
|
);
|
|
42
|
-
|
|
43
|
-
} catch (
|
|
44
|
-
(c =
|
|
43
|
+
u == null || u(p), i == null || i(!1), d.setFieldValue(n, p), (o = l.onSuccess) == null || o.call(l, p);
|
|
44
|
+
} catch (a) {
|
|
45
|
+
(c = l.onError) == null || c.call(l, a);
|
|
45
46
|
} finally {
|
|
46
|
-
|
|
47
|
+
E(!1);
|
|
47
48
|
}
|
|
48
49
|
},
|
|
49
|
-
[d, n,
|
|
50
|
-
), [
|
|
50
|
+
[d, n, u, i, w, s]
|
|
51
|
+
), [x, $] = g([]);
|
|
51
52
|
A(() => {
|
|
52
|
-
!
|
|
53
|
-
(Array.isArray(
|
|
54
|
-
async (
|
|
55
|
-
const o =
|
|
53
|
+
!M && F && Promise.all(
|
|
54
|
+
(Array.isArray(F) ? F : [F]).map(
|
|
55
|
+
async (l) => {
|
|
56
|
+
const o = z.getType(l), c = l.split("/").pop(), a = await s.getRealUrl(l);
|
|
56
57
|
return {
|
|
57
|
-
uid:
|
|
58
|
-
url:
|
|
58
|
+
uid: l,
|
|
59
|
+
url: a,
|
|
59
60
|
type: o,
|
|
60
61
|
name: c
|
|
61
62
|
};
|
|
62
63
|
}
|
|
63
64
|
)
|
|
64
|
-
).then((
|
|
65
|
-
}, [
|
|
66
|
-
const
|
|
67
|
-
async (
|
|
68
|
-
const o =
|
|
69
|
-
await
|
|
65
|
+
).then((l) => $(() => l.map(({ url: c, type: a, uid: O, name: P }) => ({ uid: O, url: c, type: a, response: O, thumbUrl: c, name: P }))));
|
|
66
|
+
}, [F, M, k, s]);
|
|
67
|
+
const X = H(
|
|
68
|
+
async (l) => {
|
|
69
|
+
const o = l.response, c = o || d.getFieldValue(n);
|
|
70
|
+
await s.delete(c), f == null || f(), l && d.setFieldsValue({ [n]: null });
|
|
70
71
|
},
|
|
71
|
-
[d, n,
|
|
72
|
+
[d, n, f, s]
|
|
72
73
|
);
|
|
73
|
-
return /* @__PURE__ */
|
|
74
|
-
|
|
74
|
+
return /* @__PURE__ */ h(
|
|
75
|
+
V.Item,
|
|
75
76
|
{
|
|
76
77
|
label: t,
|
|
77
|
-
required:
|
|
78
|
+
required: r,
|
|
78
79
|
name: n,
|
|
79
|
-
...
|
|
80
|
-
className:
|
|
80
|
+
...R,
|
|
81
|
+
className: b,
|
|
81
82
|
rules: [
|
|
82
|
-
...
|
|
83
|
-
...
|
|
83
|
+
...r ? at.required(t) : [],
|
|
84
|
+
...W ?? []
|
|
84
85
|
],
|
|
85
|
-
help:
|
|
86
|
+
help: q,
|
|
86
87
|
children: [
|
|
87
|
-
/* @__PURE__ */
|
|
88
|
-
/* @__PURE__ */
|
|
89
|
-
|
|
88
|
+
/* @__PURE__ */ e("input", { hidden: !0 }),
|
|
89
|
+
/* @__PURE__ */ e(
|
|
90
|
+
lt,
|
|
90
91
|
{
|
|
91
|
-
...
|
|
92
|
-
fileList:
|
|
93
|
-
className: ((
|
|
94
|
-
maxCount:
|
|
95
|
-
customRequest:
|
|
96
|
-
onRemove:
|
|
92
|
+
...G,
|
|
93
|
+
fileList: x,
|
|
94
|
+
className: ((x == null ? void 0 : x.length) ?? 0) >= N ? "hide-upload" : "",
|
|
95
|
+
maxCount: N,
|
|
96
|
+
customRequest: Q,
|
|
97
|
+
onRemove: X,
|
|
97
98
|
listType: "picture",
|
|
98
|
-
onChange: ({ fileList:
|
|
99
|
-
|
|
99
|
+
onChange: ({ fileList: l }) => {
|
|
100
|
+
$(l);
|
|
100
101
|
},
|
|
101
|
-
accept:
|
|
102
|
-
style:
|
|
103
|
-
children: /* @__PURE__ */
|
|
102
|
+
accept: L,
|
|
103
|
+
style: _ ? { width: "100%" } : void 0,
|
|
104
|
+
children: /* @__PURE__ */ e(I, { icon: /* @__PURE__ */ e(B, {}), block: !0, size: "large", loading: k, children: "Upload File" })
|
|
104
105
|
}
|
|
105
106
|
)
|
|
106
107
|
]
|
|
107
108
|
}
|
|
108
109
|
);
|
|
109
110
|
}
|
|
110
|
-
const
|
|
111
|
-
const [
|
|
111
|
+
const Vt = ({ provider: n, value: t }) => {
|
|
112
|
+
const [r, s] = g();
|
|
112
113
|
return A(() => {
|
|
113
|
-
t && n.getRealUrl(t).then((
|
|
114
|
-
|
|
115
|
-
mimeType:
|
|
116
|
-
url:
|
|
114
|
+
t && n.getRealUrl(t).then((i) => {
|
|
115
|
+
s({
|
|
116
|
+
mimeType: z.getType(t),
|
|
117
|
+
url: i,
|
|
117
118
|
fileName: t.split("/").pop() ?? t
|
|
118
119
|
});
|
|
119
120
|
});
|
|
120
|
-
}, [n, t]),
|
|
121
|
-
|
|
121
|
+
}, [n, t]), r ? /* @__PURE__ */ e(
|
|
122
|
+
ft,
|
|
122
123
|
{
|
|
123
|
-
fileName:
|
|
124
|
-
url:
|
|
125
|
-
mimeType:
|
|
124
|
+
fileName: r.fileName,
|
|
125
|
+
url: r == null ? void 0 : r.url,
|
|
126
|
+
mimeType: r == null ? void 0 : r.mimeType
|
|
126
127
|
}
|
|
127
|
-
) : /* @__PURE__ */
|
|
128
|
-
},
|
|
129
|
-
const
|
|
130
|
-
switch (
|
|
128
|
+
) : /* @__PURE__ */ e(D, {});
|
|
129
|
+
}, ft = ({ url: n, mimeType: t = "", fileName: r }) => {
|
|
130
|
+
const s = S(() => t != null && t.includes("image") ? "image" : t != null && t.includes("pdf") ? "pdf" : t != null && t.includes("word") ? "word" : t != null && t.includes("text") ? "text" : t != null && t.includes("presentation") ? "presentation" : t != null && t.includes("excel") || t != null && t.includes("spreadsheet") ? "excel" : "file", [t]), i = S(() => {
|
|
131
|
+
switch (s) {
|
|
131
132
|
case "image":
|
|
132
|
-
return /* @__PURE__ */
|
|
133
|
+
return /* @__PURE__ */ e(st, {});
|
|
133
134
|
case "pdf":
|
|
134
|
-
return /* @__PURE__ */
|
|
135
|
+
return /* @__PURE__ */ e(et, {});
|
|
135
136
|
case "word":
|
|
136
|
-
return /* @__PURE__ */
|
|
137
|
+
return /* @__PURE__ */ e(tt, {});
|
|
137
138
|
case "text":
|
|
138
|
-
return /* @__PURE__ */
|
|
139
|
+
return /* @__PURE__ */ e(T, {});
|
|
139
140
|
case "excel":
|
|
140
|
-
return /* @__PURE__ */
|
|
141
|
+
return /* @__PURE__ */ e(m, {});
|
|
141
142
|
case "presentation":
|
|
142
|
-
return /* @__PURE__ */
|
|
143
|
+
return /* @__PURE__ */ e(y, {});
|
|
143
144
|
default:
|
|
144
|
-
return /* @__PURE__ */
|
|
145
|
+
return /* @__PURE__ */ e(v, {});
|
|
145
146
|
}
|
|
146
|
-
}, [
|
|
147
|
-
return
|
|
148
|
-
/* @__PURE__ */
|
|
149
|
-
|
|
147
|
+
}, [s]), [f, u] = g(!1), { t: b } = it();
|
|
148
|
+
return s !== "file" && s !== "text" ? /* @__PURE__ */ h(D, { children: [
|
|
149
|
+
/* @__PURE__ */ e(
|
|
150
|
+
nt,
|
|
150
151
|
{
|
|
151
|
-
open:
|
|
152
|
-
title:
|
|
153
|
-
onCancel: () =>
|
|
154
|
-
footer: /* @__PURE__ */
|
|
152
|
+
open: f,
|
|
153
|
+
title: r,
|
|
154
|
+
onCancel: () => u(!1),
|
|
155
|
+
footer: /* @__PURE__ */ e(D, {}),
|
|
155
156
|
width: "100%",
|
|
156
157
|
style: { top: "8px", minHeight: "700px" },
|
|
157
158
|
destroyOnHidden: !0,
|
|
158
|
-
children: /* @__PURE__ */
|
|
159
|
-
/* @__PURE__ */
|
|
160
|
-
|
|
159
|
+
children: /* @__PURE__ */ h(ct, { children: [
|
|
160
|
+
/* @__PURE__ */ e(
|
|
161
|
+
I,
|
|
161
162
|
{
|
|
162
|
-
tooltip:
|
|
163
|
-
icon: /* @__PURE__ */
|
|
163
|
+
tooltip: r,
|
|
164
|
+
icon: /* @__PURE__ */ e(rt, {}),
|
|
164
165
|
target: "_blank",
|
|
165
166
|
href: n,
|
|
166
167
|
style: { textDecoration: "none" },
|
|
167
|
-
children:
|
|
168
|
+
children: b("str.openInNewTab")
|
|
168
169
|
}
|
|
169
170
|
),
|
|
170
|
-
|
|
171
|
+
s === "image" ? /* @__PURE__ */ e("img", { src: n, alt: r, style: { width: "100%" } }) : s === "pdf" ? /* @__PURE__ */ h("iframe", { title: r, src: n, width: "100%", height: "700px", children: [
|
|
171
172
|
"This browser does not support PDFs. Please download the PDF to view it:",
|
|
172
|
-
/* @__PURE__ */
|
|
173
|
-
] }) : /* @__PURE__ */
|
|
173
|
+
/* @__PURE__ */ e("a", { href: n, children: "Download PDF" })
|
|
174
|
+
] }) : /* @__PURE__ */ h(
|
|
174
175
|
"iframe",
|
|
175
176
|
{
|
|
176
|
-
title:
|
|
177
|
+
title: r,
|
|
177
178
|
src: `https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(
|
|
178
179
|
n
|
|
179
180
|
)}`,
|
|
@@ -181,13 +182,13 @@ const Ot = ({ provider: n, value: t }) => {
|
|
|
181
182
|
height: "700px",
|
|
182
183
|
children: [
|
|
183
184
|
"This browser does not support open ",
|
|
184
|
-
|
|
185
|
+
s.toUpperCase(),
|
|
185
186
|
". Please download the",
|
|
186
|
-
|
|
187
|
+
s.toUpperCase(),
|
|
187
188
|
" to view it:",
|
|
188
|
-
/* @__PURE__ */
|
|
189
|
+
/* @__PURE__ */ h("a", { href: n, children: [
|
|
189
190
|
"Download ",
|
|
190
|
-
|
|
191
|
+
s.toUpperCase()
|
|
191
192
|
] }),
|
|
192
193
|
"."
|
|
193
194
|
]
|
|
@@ -196,20 +197,20 @@ const Ot = ({ provider: n, value: t }) => {
|
|
|
196
197
|
] })
|
|
197
198
|
}
|
|
198
199
|
),
|
|
199
|
-
/* @__PURE__ */
|
|
200
|
-
|
|
200
|
+
/* @__PURE__ */ e(
|
|
201
|
+
I,
|
|
201
202
|
{
|
|
202
|
-
tooltip:
|
|
203
|
-
icon:
|
|
203
|
+
tooltip: r,
|
|
204
|
+
icon: i,
|
|
204
205
|
shape: "circle",
|
|
205
|
-
onClick: () =>
|
|
206
|
+
onClick: () => u(!0)
|
|
206
207
|
}
|
|
207
208
|
)
|
|
208
|
-
] }) : /* @__PURE__ */
|
|
209
|
-
|
|
209
|
+
] }) : /* @__PURE__ */ e(
|
|
210
|
+
I,
|
|
210
211
|
{
|
|
211
|
-
tooltip:
|
|
212
|
-
icon:
|
|
212
|
+
tooltip: r,
|
|
213
|
+
icon: i,
|
|
213
214
|
target: "_blank",
|
|
214
215
|
href: n,
|
|
215
216
|
shape: "circle"
|
|
@@ -217,7 +218,7 @@ const Ot = ({ provider: n, value: t }) => {
|
|
|
217
218
|
);
|
|
218
219
|
};
|
|
219
220
|
export {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
221
|
+
ft as FileCellValue,
|
|
222
|
+
Vt as FileCrudCellValue,
|
|
223
|
+
pt as default
|
|
223
224
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var G=Object.defineProperty;var J=(s,e,t)=>e in s?G(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var A=(s,e,t)=>J(s,typeof e!="symbol"?e+"":e,t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("react/jsx-runtime"),K=require("@ant-design/icons"),F=require("antd"),b=require("path-browserify"),h=require("react"),L=require("../util/NumberUtil.cjs.js"),Q=require("../util/ValidationUtil.cjs.js"),X=require("uuid"),Y=require("../common/picker/ImagePicker.cjs.js"),Z=require("../util/ImageUtil.cjs.js");class ${}class p extends ${constructor(t="",l=""){super();A(this,"rootPath");A(this,"subPath");this.rootPath=t,this.subPath=l}cloneFilePath(t){const l=b.parse(t),r=`${l.name}_cloned_${L.default.randInt(1e5)}`;return b.format({dir:l.dir,ext:l.ext,name:r})}generateFileName(t){return`${t.split(".")[0]}_${X.v4().replace("-","")}`}}function R({formLayoutProps:s,name:e,label:t,required:l,provider:r,onUploading:i,aspectRatio:O,onRemoved:m,onUploadComplete:g,fieldClassName:x,hideLabel:S=!1,listType:_,fieldHelper:B,showSkipCropButton:M=!1,skipCrop:z=!1,skipResize:D=!1,asyncUpload:E=!1,maxCount:d=1},H){const o=F.Form.useFormInstance(),f=e,y=F.Form.useWatch(f,o),T=h.useCallback(a=>r.getRealUrl(a),[r]),P=h.useCallback(async(a,I)=>{if(I){i==null||i(!0);try{const u=a.name,c=u.split("."),N=c[c.length-1],V=r.generateFileName(u),q=`${await r.getInitialPath()}/${V}.${N}`,w=await r.upload(a,q);g==null||g(w);const j=o.getFieldValue(f);if(d>1){const C=Array.isArray(j)?j:j?[j]:[];o.setFieldValue(f,[...C,w].filter(Boolean))}else o.setFieldValue(f,w);return w}finally{i==null||i(!1)}}else{const u=o.getFieldValue(f);if(d>1){const c=a.response??(typeof a.uid=="string"?a.uid:void 0);if(!c)return;await r.delete(c),m==null||m();const V=(Array.isArray(u)?u:u?[u]:[]).filter(q=>q!==c);o.setFieldValue(f,V.length?V:null)}else{const c=await r.delete(u);m==null||m(),c&&o.setFieldValue(f,null)}}},[o,d,f,m,g,i,r]);h.useImperativeHandle(H,()=>({async uploadBlob(a,I){const u=await Z.getBase64(a),c={name:I,uid:I+Math.random().toString(36).substring(2,15),url:u,originFileObj:a};await P(c,!0)}}),[P]);const W=h.useMemo(()=>y?(Array.isArray(y),y):d>1?[]:void 0,[y,d]);return n.jsxs(F.Form.Item,{rules:l?Q.required(t):[],label:S?null:t,required:l,name:f,help:B,...s,className:x,children:[n.jsx(Y.default,{noStyle:!0,asyncUpload:E,listType:_,aspectRatio:O,values:W,getRealUrl:T,onRemove:a=>{a&&P(a,!1)},onAdd:async a=>{if(a)return P(a,!0)},className:x,showSkipCropButton:M,skipCrop:z,skipResize:D,maxCount:d}),n.jsx(F.Input,{hidden:!0})]})}const U=h.forwardRef(R),v=({provider:s,value:e})=>{const[t,l]=h.useState([]);return h.useEffect(()=>{if(!e){l([]);return}const r=Array.isArray(e)?e:[e];Promise.all(r.filter(Boolean).map(i=>s.getRealUrl(i))).then(l)},[s,e]),t.length?n.jsx(n.Fragment,{children:t.map(r=>n.jsx(k,{url:r},r))}):n.jsx(n.Fragment,{})},k=({url:s})=>n.jsx(F.Avatar,{className:"p-0",children:n.jsx(F.Image,{className:"m-0 p-0 position-relative",src:s,preview:{mask:n.jsx(K.EyeOutlined,{})}})});exports.FileDownloadProvider=$;exports.FileUploadProvider=p;exports.ImageCellValue=k;exports.ImageCrudCellValue=v;exports.default=U;
|
|
@@ -6,6 +6,7 @@ export interface _ImageCrudField<T> extends InitialCrudField<T> {
|
|
|
6
6
|
provider: FileUploadProvider;
|
|
7
7
|
onUploading?: (isUploading: boolean) => void;
|
|
8
8
|
onRemoved?: () => void;
|
|
9
|
+
onUploadComplete?: (finalPath: string) => void;
|
|
9
10
|
aspectRatio?: number;
|
|
10
11
|
fieldClassName?: string;
|
|
11
12
|
listType?: UploadListType;
|