@kingteza/crud-component 1.9.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/button/NewButton.cjs.js +1 -1
- package/dist/common/button/NewButton.d.ts +4 -3
- package/dist/common/button/NewButton.es.js +20 -10
- package/dist/crud/CrudComponent.cjs.js +1 -1
- package/dist/crud/CrudComponent.d.ts +6 -2
- package/dist/crud/CrudComponent.es.js +97 -95
- package/dist/crud/ImageCrudField.cjs.js +1 -1
- package/dist/crud/ImageCrudField.d.ts +7 -2
- package/dist/crud/ImageCrudField.es.js +76 -61
- package/dist/crud/index.d.ts +1 -1
- package/dist/util/ImageUtil.cjs.js +1 -1
- package/dist/util/ImageUtil.d.ts +2 -1
- package/dist/util/ImageUtil.es.js +29 -16
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),d=require("@ant-design/icons"),j=require("../../locale/index.cjs.js"),q=require("./Button.cjs.js"),x=({size:n,block:r,className:o,type:u="primary",onClick:e,title:i,to:s,...c})=>{const{t:l}=j.useTranslationLib();return t.jsx(q,{type:u,className:o,to:s,block:r,size:n,onClick:e&&(a=>e(!0,a)),icon:t.jsx(d.PlusOutlined,{}),...c,children:i??l("str.new")})};exports.NewButton=x;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { SizeType } from 'antd/es/config-provider/SizeContext';
|
|
2
2
|
import { ButtonType } from 'antd/lib/button';
|
|
3
|
-
import { FC } from 'react';
|
|
3
|
+
import { FC, MouseEvent } from 'react';
|
|
4
|
+
import { ButtonProps } from 'antd';
|
|
4
5
|
export declare const NewButton: FC<{
|
|
5
6
|
to?: string;
|
|
6
|
-
onClick?: (value: boolean) => void;
|
|
7
|
+
onClick?: (value: boolean, event: MouseEvent<HTMLElement>) => void;
|
|
7
8
|
title?: string;
|
|
8
9
|
type?: ButtonType;
|
|
9
10
|
block?: boolean;
|
|
10
11
|
className?: string;
|
|
11
12
|
size?: SizeType;
|
|
12
|
-
}
|
|
13
|
+
} & Omit<ButtonProps, "onClick">>;
|
|
@@ -1,23 +1,33 @@
|
|
|
1
1
|
import { jsx as o } from "react/jsx-runtime";
|
|
2
|
-
import { PlusOutlined as
|
|
3
|
-
import { useTranslationLib as
|
|
4
|
-
import
|
|
5
|
-
const
|
|
6
|
-
|
|
2
|
+
import { PlusOutlined as f } from "@ant-design/icons";
|
|
3
|
+
import { useTranslationLib as l } from "../../locale/index.es.js";
|
|
4
|
+
import a from "./Button.es.js";
|
|
5
|
+
const b = ({
|
|
6
|
+
size: r,
|
|
7
|
+
block: n,
|
|
8
|
+
className: i,
|
|
9
|
+
type: m = "primary",
|
|
10
|
+
onClick: t,
|
|
11
|
+
title: e,
|
|
12
|
+
to: p,
|
|
13
|
+
...s
|
|
14
|
+
}) => {
|
|
15
|
+
const { t: u } = l();
|
|
7
16
|
return /* @__PURE__ */ o(
|
|
8
|
-
|
|
17
|
+
a,
|
|
9
18
|
{
|
|
10
19
|
type: m,
|
|
11
20
|
className: i,
|
|
12
21
|
to: p,
|
|
13
22
|
block: n,
|
|
14
23
|
size: r,
|
|
15
|
-
onClick: t && (() => t(!0)),
|
|
16
|
-
icon: /* @__PURE__ */ o(
|
|
17
|
-
|
|
24
|
+
onClick: t && ((c) => t(!0, c)),
|
|
25
|
+
icon: /* @__PURE__ */ o(f, {}),
|
|
26
|
+
...s,
|
|
27
|
+
children: e ?? u("str.new")
|
|
18
28
|
}
|
|
19
29
|
);
|
|
20
30
|
};
|
|
21
31
|
export {
|
|
22
|
-
|
|
32
|
+
b as NewButton
|
|
23
33
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";const e=require("react/jsx-runtime"),j=require("antd"),n=require("react"),H=require("./modal/index.cjs.js"),J=require("./import/CrudImportButton.cjs.js"),K=require("./view/CrudViewer.cjs.js"),L=require("../common/button/NewButton.cjs.js"),Q=require("../common/button/PrintButton.cjs.js");function T({idField:o="id",onCreate:f,onDelete:m,onHide:h,onUpdate:l,onClickUpdate:u,fields:r,data:q,grid:N,isHiding:v,isCreating:R,isDeleting:g,isUpdating:y,paginateProps:b,onPrint:C,printing:B,viewable:S,loadingData:w,formBuilder:I,extraAction:M,minusHeight:O,cloneable:V,fullWidthModal:W=!0,wizard:_,extraView:p,importable:d,onClickNew:x,newButtonProps:s,size:z,...A}){const t=n.useRef(null),D=n.useCallback(()=>{var c;(c=t.current)==null||c.create()},[]),i=n.useCallback(async(c,a=!0,G=!1)=>{var k;await((k=t.current)==null?void 0:k.update(c,a,G))},[]),E=n.useCallback(async c=>{i(c,!1,!0)},[i]),{onClick:X,...F}=n.useMemo(()=>s||{},[s]);return e.jsxs(e.Fragment,{children:[e.jsxs(j.Space,{direction:"vertical",className:"w-100",children:[e.jsxs("div",{className:"w-100 d-flex",children:[e.jsx("div",{style:{flex:1},children:e.jsx(L.NewButton,{onClick:(c,a)=>{x?x():s!=null&&s.onClick?s.onClick(a):D()},className:"flex-1",...F})}),e.jsxs(j.Space,{children:[!!C&&e.jsx(Q.PrintButton,{className:"float-right",loading:B,onClick:C}),!!d&&e.jsx(J,{fields:r,importProps:d})]})]}),e.jsx(K,{...A,minusHeight:O,data:q,size:z,fields:r,extraAction:M,idField:o,isDeleting:g,loadingData:w,onClickUpdate:u||(l?i:void 0),onHide:h,isHiding:v,onDelete:m,onUpdate:l,onClickClone:V?E:void 0,paginateProps:b,viewable:S,extraView:p})]}),e.jsx(H,{ref:t,fields:r,wizard:_,grid:N,fullWidthModal:W,isCreating:R,isUpdating:y,onCreate:f,onUpdate:l,idField:o,formBuilder:I})]})}module.exports=T;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ColorPickerProps } from 'antd';
|
|
1
|
+
import { ButtonProps, ColorPickerProps } from 'antd';
|
|
2
2
|
import { Rule } from 'antd/es/form';
|
|
3
3
|
import { FormInstance } from 'antd/lib';
|
|
4
4
|
import { Dayjs } from 'dayjs';
|
|
@@ -259,9 +259,13 @@ export type CrudComponentProps<T, FormType = T> = {
|
|
|
259
259
|
wizard?: CrudWizardProp<T>[];
|
|
260
260
|
extraView?: (t: T) => React.ReactElement;
|
|
261
261
|
importable?: CrudImportProps<T>;
|
|
262
|
+
/**
|
|
263
|
+
* @deprecated Use {@link CrudComponentProps.newButtonProps?.onClick} instead.
|
|
264
|
+
*/
|
|
262
265
|
onClickNew?: () => void;
|
|
266
|
+
newButtonProps?: ButtonProps;
|
|
263
267
|
draggable?: CrudDragableProps<T>;
|
|
264
268
|
size?: SizeType;
|
|
265
269
|
} & CrudSearchComponentProps<T, FormType>;
|
|
266
|
-
declare function CrudComponent<T, FormType = T>({ idField, onCreate, onDelete, onHide, onUpdate, onClickUpdate, 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;
|
|
270
|
+
declare function CrudComponent<T, FormType = T>({ idField, onCreate, onDelete, onHide, onUpdate, onClickUpdate, fields, data, grid, isHiding, isCreating, isDeleting, isUpdating, paginateProps, onPrint, printing, viewable, loadingData, formBuilder, extraAction, minusHeight, cloneable, fullWidthModal, wizard, extraView, importable, onClickNew, newButtonProps, size, ...props }: CrudComponentProps<T, FormType>): import("react/jsx-runtime").JSX.Element;
|
|
267
271
|
export default CrudComponent;
|
|
@@ -1,123 +1,125 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { Space as
|
|
3
|
-
import { useRef as K, useCallback as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { NewButton as
|
|
8
|
-
import { PrintButton as
|
|
9
|
-
function
|
|
10
|
-
idField:
|
|
11
|
-
onCreate:
|
|
12
|
-
onDelete:
|
|
13
|
-
onHide:
|
|
14
|
-
onUpdate:
|
|
15
|
-
onClickUpdate:
|
|
16
|
-
fields:
|
|
17
|
-
data:
|
|
18
|
-
grid:
|
|
19
|
-
isHiding:
|
|
20
|
-
isCreating:
|
|
21
|
-
isDeleting:
|
|
22
|
-
isUpdating:
|
|
23
|
-
paginateProps:
|
|
24
|
-
onPrint:
|
|
25
|
-
printing:
|
|
26
|
-
viewable:
|
|
27
|
-
loadingData:
|
|
28
|
-
formBuilder:
|
|
29
|
-
extraAction:
|
|
30
|
-
minusHeight:
|
|
31
|
-
cloneable:
|
|
32
|
-
fullWidthModal:
|
|
33
|
-
wizard:
|
|
34
|
-
extraView:
|
|
35
|
-
importable:
|
|
36
|
-
onClickNew:
|
|
37
|
-
|
|
1
|
+
import { jsxs as l, Fragment as J, jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import { Space as h } from "antd";
|
|
3
|
+
import { useRef as K, useCallback as m, useMemo as L } from "react";
|
|
4
|
+
import Q from "./modal/index.es.js";
|
|
5
|
+
import T from "./import/CrudImportButton.es.js";
|
|
6
|
+
import X from "./view/CrudViewer.es.js";
|
|
7
|
+
import { NewButton as Y } from "../common/button/NewButton.es.js";
|
|
8
|
+
import { PrintButton as Z } from "../common/button/PrintButton.es.js";
|
|
9
|
+
function te({
|
|
10
|
+
idField: s = "id",
|
|
11
|
+
onCreate: p,
|
|
12
|
+
onDelete: x,
|
|
13
|
+
onHide: N,
|
|
14
|
+
onUpdate: i,
|
|
15
|
+
onClickUpdate: f,
|
|
16
|
+
fields: c,
|
|
17
|
+
data: v,
|
|
18
|
+
grid: g,
|
|
19
|
+
isHiding: y,
|
|
20
|
+
isCreating: j,
|
|
21
|
+
isDeleting: M,
|
|
22
|
+
isUpdating: R,
|
|
23
|
+
paginateProps: I,
|
|
24
|
+
onPrint: d,
|
|
25
|
+
printing: O,
|
|
26
|
+
viewable: S,
|
|
27
|
+
loadingData: V,
|
|
28
|
+
formBuilder: W,
|
|
29
|
+
extraAction: _,
|
|
30
|
+
minusHeight: b,
|
|
31
|
+
cloneable: q,
|
|
32
|
+
fullWidthModal: w = !0,
|
|
33
|
+
wizard: z,
|
|
34
|
+
extraView: A,
|
|
35
|
+
importable: C,
|
|
36
|
+
onClickNew: u,
|
|
37
|
+
newButtonProps: o,
|
|
38
|
+
size: B,
|
|
38
39
|
...D
|
|
39
40
|
}) {
|
|
40
|
-
const
|
|
41
|
-
var
|
|
42
|
-
(
|
|
43
|
-
}, []), a =
|
|
44
|
-
async (
|
|
45
|
-
var
|
|
46
|
-
await ((
|
|
41
|
+
const t = K(null), E = m(() => {
|
|
42
|
+
var e;
|
|
43
|
+
(e = t.current) == null || e.create();
|
|
44
|
+
}, []), a = m(
|
|
45
|
+
async (e, n = !0, H = !1) => {
|
|
46
|
+
var k;
|
|
47
|
+
await ((k = t.current) == null ? void 0 : k.update(e, n, H));
|
|
47
48
|
},
|
|
48
49
|
[]
|
|
49
|
-
), F =
|
|
50
|
-
async (
|
|
51
|
-
a(
|
|
50
|
+
), F = m(
|
|
51
|
+
async (e) => {
|
|
52
|
+
a(e, !1, !0);
|
|
52
53
|
},
|
|
53
54
|
[a]
|
|
54
|
-
);
|
|
55
|
-
return /* @__PURE__ */
|
|
56
|
-
/* @__PURE__ */
|
|
57
|
-
/* @__PURE__ */
|
|
58
|
-
/* @__PURE__ */
|
|
59
|
-
|
|
55
|
+
), { onClick: $, ...G } = L(() => o || {}, [o]);
|
|
56
|
+
return /* @__PURE__ */ l(J, { children: [
|
|
57
|
+
/* @__PURE__ */ l(h, { direction: "vertical", className: "w-100", children: [
|
|
58
|
+
/* @__PURE__ */ l("div", { className: "w-100 d-flex", children: [
|
|
59
|
+
/* @__PURE__ */ r("div", { style: { flex: 1 }, children: /* @__PURE__ */ r(
|
|
60
|
+
Y,
|
|
60
61
|
{
|
|
61
|
-
onClick: () => {
|
|
62
|
-
|
|
62
|
+
onClick: (e, n) => {
|
|
63
|
+
u ? u() : o != null && o.onClick ? o.onClick(n) : E();
|
|
63
64
|
},
|
|
64
|
-
className: "flex-1"
|
|
65
|
+
className: "flex-1",
|
|
66
|
+
...G
|
|
65
67
|
}
|
|
66
68
|
) }),
|
|
67
|
-
/* @__PURE__ */
|
|
68
|
-
!!
|
|
69
|
-
|
|
69
|
+
/* @__PURE__ */ l(h, { children: [
|
|
70
|
+
!!d && /* @__PURE__ */ r(
|
|
71
|
+
Z,
|
|
70
72
|
{
|
|
71
73
|
className: "float-right",
|
|
72
|
-
loading:
|
|
73
|
-
onClick:
|
|
74
|
+
loading: O,
|
|
75
|
+
onClick: d
|
|
74
76
|
}
|
|
75
77
|
),
|
|
76
|
-
!!
|
|
78
|
+
!!C && /* @__PURE__ */ r(T, { fields: c, importProps: C })
|
|
77
79
|
] })
|
|
78
80
|
] }),
|
|
79
|
-
/* @__PURE__ */
|
|
80
|
-
|
|
81
|
+
/* @__PURE__ */ r(
|
|
82
|
+
X,
|
|
81
83
|
{
|
|
82
84
|
...D,
|
|
83
|
-
minusHeight:
|
|
84
|
-
data:
|
|
85
|
-
size:
|
|
86
|
-
fields:
|
|
87
|
-
extraAction:
|
|
88
|
-
idField:
|
|
89
|
-
isDeleting:
|
|
90
|
-
loadingData:
|
|
91
|
-
onClickUpdate:
|
|
92
|
-
onHide:
|
|
93
|
-
isHiding:
|
|
94
|
-
onDelete:
|
|
95
|
-
onUpdate:
|
|
96
|
-
onClickClone:
|
|
97
|
-
paginateProps:
|
|
98
|
-
viewable:
|
|
99
|
-
extraView:
|
|
85
|
+
minusHeight: b,
|
|
86
|
+
data: v,
|
|
87
|
+
size: B,
|
|
88
|
+
fields: c,
|
|
89
|
+
extraAction: _,
|
|
90
|
+
idField: s,
|
|
91
|
+
isDeleting: M,
|
|
92
|
+
loadingData: V,
|
|
93
|
+
onClickUpdate: f || (i ? a : void 0),
|
|
94
|
+
onHide: N,
|
|
95
|
+
isHiding: y,
|
|
96
|
+
onDelete: x,
|
|
97
|
+
onUpdate: i,
|
|
98
|
+
onClickClone: q ? F : void 0,
|
|
99
|
+
paginateProps: I,
|
|
100
|
+
viewable: S,
|
|
101
|
+
extraView: A
|
|
100
102
|
}
|
|
101
103
|
)
|
|
102
104
|
] }),
|
|
103
|
-
/* @__PURE__ */
|
|
104
|
-
|
|
105
|
+
/* @__PURE__ */ r(
|
|
106
|
+
Q,
|
|
105
107
|
{
|
|
106
|
-
ref:
|
|
107
|
-
fields:
|
|
108
|
-
wizard:
|
|
109
|
-
grid:
|
|
110
|
-
fullWidthModal:
|
|
111
|
-
isCreating:
|
|
112
|
-
isUpdating:
|
|
113
|
-
onCreate:
|
|
114
|
-
onUpdate:
|
|
115
|
-
idField:
|
|
116
|
-
formBuilder:
|
|
108
|
+
ref: t,
|
|
109
|
+
fields: c,
|
|
110
|
+
wizard: z,
|
|
111
|
+
grid: g,
|
|
112
|
+
fullWidthModal: w,
|
|
113
|
+
isCreating: j,
|
|
114
|
+
isUpdating: R,
|
|
115
|
+
onCreate: p,
|
|
116
|
+
onUpdate: i,
|
|
117
|
+
idField: s,
|
|
118
|
+
formBuilder: W
|
|
117
119
|
}
|
|
118
120
|
)
|
|
119
121
|
] });
|
|
120
122
|
}
|
|
121
123
|
export {
|
|
122
|
-
|
|
124
|
+
te as default
|
|
123
125
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var E=Object.defineProperty;var M=(e,a,t)=>a in e?E(e,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[a]=t;var P=(e,a,t)=>M(e,typeof a!="symbol"?a+"":a,t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("react/jsx-runtime");;/* empty css */const A=require("@ant-design/icons"),o=require("antd"),j=require("path-browserify"),u=require("react"),B=require("../util/NumberUtil.cjs.js"),D=require("../util/ValidationUtil.cjs.js"),H=require("uuid"),R=require("../common/picker/ImagePicker.cjs.js"),T=require("../util/ImageUtil.cjs.js");class q{}class W extends q{constructor(t="",s=""){super();P(this,"rootPath");P(this,"subPath");this.rootPath=t,this.subPath=s}cloneFilePath(t){const s=j.parse(t),r=`${s.name}_cloned_${B.default.randInt(1e5)}`;return j.format({dir:s.dir,ext:s.ext,name:r})}generateFileName(t){return`${t.split(".")[0]}_${H.v4().replace("-","")}`}}function v({name:e,label:a,required:t,provider:s,onUploading:r,aspectRatio:g,onRemoved:m,fieldClassName:V,hideLabel:y=!1,listType:N,fieldHelper:b},S){const f=o.Form.useFormInstance(),F=o.Form.useWatch(e,f),[x,$]=u.useState(!1),d=u.useCallback(async(l,h)=>{if(h){r==null||r(!0);const i=l.name,c=i.split("."),p=c[c.length-1],O=s.generateFileName(i),_=`${await s.getInitialPath()}/${O}.${p}`,k=await s.upload(l,_);$(!0),r==null||r(!1),f.setFieldValue(e,k)}else{const i=f.getFieldsValue(),c=await s.delete(i[e]);m==null||m(),c&&f.setFieldsValue({[e]:null})}},[f,e,m,r,s]),[I,w]=u.useState();return u.useEffect(()=>{!x&&F?s.getRealUrl(F).then(w):w(I)},[F,x,s,I]),u.useImperativeHandle(S,()=>({async uploadBlob(l,h){const i=await T.getBase64(l),c={name:h,uid:h+Math.random().toString(36).substring(2,15),url:i,originFileObj:l};return d(c,!0)}}),[d]),n.jsxs(o.Form.Item,{rules:t?D.required(a):[],label:y?null:a,required:t,name:e,help:b,children:[n.jsx(R.default,{noStyle:!0,listType:N,aspectRatio:g,values:I,onRemove:l=>{l&&d(l,!1)},onAdd:async l=>{l&&await d(l,!0)},className:V}),n.jsx(o.Input,{hidden:!0})]})}const z=u.forwardRef(v),G=({provider:e,value:a})=>{const[t,s]=u.useState();return u.useEffect(()=>{a&&e.getRealUrl(a).then(s)},[e,a]),t?n.jsx(C,{url:t}):n.jsx(n.Fragment,{})},C=({url:e})=>n.jsx(o.Avatar,{className:"p-0",children:n.jsx(o.Image,{className:"m-0 p-0 position-relative",src:e,preview:{mask:n.jsx(A.EyeOutlined,{})}})});exports.FileDownloadProvider=q;exports.FileUploadProvider=W;exports.ImageCellValue=C;exports.ImageCrudCellValue=G;exports.default=z;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UploadListType } from 'antd/es/upload/interface';
|
|
2
2
|
import { UploadFile } from 'antd/lib';
|
|
3
|
-
import { FC } from 'react';
|
|
3
|
+
import { default as React, FC, ForwardedRef } from 'react';
|
|
4
4
|
import { InitialCrudField } from './CrudComponent';
|
|
5
5
|
export interface _ImageCrudField<T> extends InitialCrudField<T> {
|
|
6
6
|
provider: FileUploadProvider;
|
|
@@ -28,7 +28,12 @@ export declare abstract class FileUploadProvider extends FileDownloadProvider {
|
|
|
28
28
|
abstract getRealUrl(filePath: string): Promise<string>;
|
|
29
29
|
generateFileName(initialFileName: string): string;
|
|
30
30
|
}
|
|
31
|
-
export
|
|
31
|
+
export interface ImageCrudFieldRef {
|
|
32
|
+
uploadBlob: (blob: Blob, fileName: string) => Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
declare function Component<T>({ name, label, required, provider, onUploading, aspectRatio, onRemoved, fieldClassName, hideLabel, listType, fieldHelper: help, }: Readonly<_ImageCrudField<T>>, ref: ForwardedRef<ImageCrudFieldRef>): import("react/jsx-runtime").JSX.Element;
|
|
35
|
+
declare const ImageCrudFieldComponent: <T>(props: React.ComponentProps<typeof Component<T>>, ref: React.Ref<any>) => React.ReactElement | null;
|
|
36
|
+
export default ImageCrudFieldComponent;
|
|
32
37
|
export declare const ImageCrudCellValue: FC<{
|
|
33
38
|
value: string;
|
|
34
39
|
provider: FileDownloadProvider;
|
|
@@ -1,114 +1,129 @@
|
|
|
1
1
|
var A = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import {
|
|
2
|
+
var B = (e, s, t) => s in e ? A(e, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[s] = t;
|
|
3
|
+
var F = (e, s, t) => B(e, typeof s != "symbol" ? s + "" : s, t);
|
|
4
|
+
import { jsx as n, Fragment as E, jsxs as H } from "react/jsx-runtime";
|
|
5
5
|
/* empty css */
|
|
6
|
-
import { EyeOutlined as
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import { useState as
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import { v4 as
|
|
13
|
-
import
|
|
14
|
-
|
|
6
|
+
import { EyeOutlined as D } from "@ant-design/icons";
|
|
7
|
+
import { Avatar as M, Image as W, Form as d, Input as q } from "antd";
|
|
8
|
+
import N from "path-browserify";
|
|
9
|
+
import z, { useState as I, useEffect as y, useCallback as G, useImperativeHandle as J } from "react";
|
|
10
|
+
import K from "../util/NumberUtil.es.js";
|
|
11
|
+
import L from "../util/ValidationUtil.es.js";
|
|
12
|
+
import { v4 as Q } from "uuid";
|
|
13
|
+
import R from "../common/picker/ImagePicker.es.js";
|
|
14
|
+
import T from "../util/ImageUtil.es.js";
|
|
15
|
+
class X {
|
|
15
16
|
}
|
|
16
|
-
class
|
|
17
|
+
class me extends X {
|
|
17
18
|
constructor(t = "", a = "") {
|
|
18
19
|
super();
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
F(this, "rootPath");
|
|
21
|
+
F(this, "subPath");
|
|
21
22
|
this.rootPath = t, this.subPath = a;
|
|
22
23
|
}
|
|
23
24
|
cloneFilePath(t) {
|
|
24
|
-
const a =
|
|
25
|
-
return
|
|
25
|
+
const a = N.parse(t), l = `${a.name}_cloned_${K.randInt(1e5)}`;
|
|
26
|
+
return N.format({
|
|
26
27
|
dir: a.dir,
|
|
27
28
|
ext: a.ext,
|
|
28
29
|
name: l
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
generateFileName(t) {
|
|
32
|
-
return `${t.split(".")[0]}_${
|
|
33
|
+
return `${t.split(".")[0]}_${Q().replace("-", "")}`;
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
|
-
function
|
|
36
|
+
function Y({
|
|
36
37
|
name: e,
|
|
37
38
|
label: s,
|
|
38
39
|
required: t,
|
|
39
40
|
provider: a,
|
|
40
41
|
onUploading: l,
|
|
41
|
-
aspectRatio:
|
|
42
|
-
onRemoved:
|
|
43
|
-
fieldClassName:
|
|
44
|
-
hideLabel:
|
|
45
|
-
listType:
|
|
42
|
+
aspectRatio: P,
|
|
43
|
+
onRemoved: m,
|
|
44
|
+
fieldClassName: C,
|
|
45
|
+
hideLabel: V = !1,
|
|
46
|
+
listType: x,
|
|
46
47
|
fieldHelper: $
|
|
47
|
-
}) {
|
|
48
|
-
const
|
|
49
|
-
async (r,
|
|
50
|
-
if (
|
|
48
|
+
}, b) {
|
|
49
|
+
const c = d.useFormInstance(), h = d.useWatch(e, c), [w, O] = I(!1), u = G(
|
|
50
|
+
async (r, f) => {
|
|
51
|
+
if (f) {
|
|
51
52
|
l == null || l(!0);
|
|
52
|
-
const
|
|
53
|
-
|
|
53
|
+
const i = r.name, o = i.split("."), j = o[o.length - 1], k = a.generateFileName(i), S = `${await a.getInitialPath()}/${k}.${j}`, _ = await a.upload(r, S);
|
|
54
|
+
O(!0), l == null || l(!1), c.setFieldValue(e, _);
|
|
54
55
|
} else {
|
|
55
|
-
const
|
|
56
|
-
|
|
56
|
+
const i = c.getFieldsValue(), o = await a.delete(i[e]);
|
|
57
|
+
m == null || m(), o && c.setFieldsValue({ [e]: null });
|
|
57
58
|
}
|
|
58
59
|
},
|
|
59
|
-
[
|
|
60
|
-
), [
|
|
61
|
-
return
|
|
62
|
-
!
|
|
63
|
-
}, [
|
|
64
|
-
|
|
60
|
+
[c, e, m, l, a]
|
|
61
|
+
), [p, g] = I();
|
|
62
|
+
return y(() => {
|
|
63
|
+
!w && h ? a.getRealUrl(h).then(g) : g(p);
|
|
64
|
+
}, [h, w, a, p]), J(
|
|
65
|
+
b,
|
|
66
|
+
() => ({
|
|
67
|
+
async uploadBlob(r, f) {
|
|
68
|
+
const i = await T.getBase64(r), o = {
|
|
69
|
+
name: f,
|
|
70
|
+
uid: f + Math.random().toString(36).substring(2, 15),
|
|
71
|
+
url: i,
|
|
72
|
+
originFileObj: r
|
|
73
|
+
};
|
|
74
|
+
return u(o, !0);
|
|
75
|
+
}
|
|
76
|
+
}),
|
|
77
|
+
[u]
|
|
78
|
+
), /* @__PURE__ */ H(
|
|
79
|
+
d.Item,
|
|
65
80
|
{
|
|
66
|
-
rules: t ?
|
|
67
|
-
label:
|
|
81
|
+
rules: t ? L.required(s) : [],
|
|
82
|
+
label: V ? null : s,
|
|
68
83
|
required: t,
|
|
69
84
|
name: e,
|
|
70
85
|
help: $,
|
|
71
86
|
children: [
|
|
72
|
-
/* @__PURE__ */
|
|
73
|
-
|
|
87
|
+
/* @__PURE__ */ n(
|
|
88
|
+
R,
|
|
74
89
|
{
|
|
75
90
|
noStyle: !0,
|
|
76
|
-
listType:
|
|
77
|
-
aspectRatio:
|
|
78
|
-
values:
|
|
91
|
+
listType: x,
|
|
92
|
+
aspectRatio: P,
|
|
93
|
+
values: p,
|
|
79
94
|
onRemove: (r) => {
|
|
80
|
-
r &&
|
|
95
|
+
r && u(r, !1);
|
|
81
96
|
},
|
|
82
97
|
onAdd: async (r) => {
|
|
83
|
-
r && await
|
|
98
|
+
r && await u(r, !0);
|
|
84
99
|
},
|
|
85
|
-
className:
|
|
100
|
+
className: C
|
|
86
101
|
}
|
|
87
102
|
),
|
|
88
|
-
/* @__PURE__ */
|
|
103
|
+
/* @__PURE__ */ n(q, { hidden: !0 })
|
|
89
104
|
]
|
|
90
105
|
}
|
|
91
106
|
);
|
|
92
107
|
}
|
|
93
|
-
const
|
|
94
|
-
const [t, a] =
|
|
95
|
-
return
|
|
108
|
+
const ue = z.forwardRef(Y), fe = ({ provider: e, value: s }) => {
|
|
109
|
+
const [t, a] = I();
|
|
110
|
+
return y(() => {
|
|
96
111
|
s && e.getRealUrl(s).then(a);
|
|
97
|
-
}, [e, s]), t ? /* @__PURE__ */
|
|
98
|
-
},
|
|
99
|
-
|
|
112
|
+
}, [e, s]), t ? /* @__PURE__ */ n(Z, { url: t }) : /* @__PURE__ */ n(E, {});
|
|
113
|
+
}, Z = ({ url: e }) => /* @__PURE__ */ n(M, { className: "p-0", children: /* @__PURE__ */ n(
|
|
114
|
+
W,
|
|
100
115
|
{
|
|
101
116
|
className: "m-0 p-0 position-relative",
|
|
102
117
|
src: e,
|
|
103
118
|
preview: {
|
|
104
|
-
mask: /* @__PURE__ */
|
|
119
|
+
mask: /* @__PURE__ */ n(D, {})
|
|
105
120
|
}
|
|
106
121
|
}
|
|
107
122
|
) });
|
|
108
123
|
export {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
124
|
+
X as FileDownloadProvider,
|
|
125
|
+
me as FileUploadProvider,
|
|
126
|
+
Z as ImageCellValue,
|
|
127
|
+
fe as ImageCrudCellValue,
|
|
128
|
+
ue as default
|
|
114
129
|
};
|
package/dist/crud/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type { CrudReportComponentProps, CrudReportSubmitForm, ReportCrudFields,
|
|
|
9
9
|
export { default as CrudReportComponent } from './CrudReportComponent';
|
|
10
10
|
export { default as CrudSearchComponent } from './CrudSearchComponent';
|
|
11
11
|
export type { CrudSearchComponentProps, CrudSearchOption, } from './CrudSearchComponent';
|
|
12
|
-
export { default as ImageCrudField, FileDownloadProvider, FileUploadProvider, ImageCellValue, ImageCrudCellValue, } from './ImageCrudField';
|
|
12
|
+
export { default as ImageCrudField, FileDownloadProvider, FileUploadProvider, ImageCellValue, ImageCrudCellValue, type ImageCrudFieldRef, } from './ImageCrudField';
|
|
13
13
|
export type { ImageCrudField as ImageCrudFieldProps } from './ImageCrudField';
|
|
14
14
|
export { default as FileCrudField, FileCellValue, FileCrudCellValue, } from './FileCrudField';
|
|
15
15
|
export type { FileCrudField as FileCrudFieldProps } from './FileCrudField';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const c=require("browser-image-compression");class
|
|
1
|
+
"use strict";const c=require("browser-image-compression");class d{async resizeImage(t){const e=await c(t,{maxSizeMB:1,maxWidthOrHeight:1920,useWebWorker:!0}),a=t.uid;return Object.assign(e,{uid:a,lastModifiedDate:new Date})}async getImageData(t){const e=await this.getImageData0(t);if(e){const a=new Image;a.src=e.data;const n=await new Promise(r=>{a.onload=function(){r({height:a.height,width:a.width})}});return Object.assign(e,n),e}else return null}async getImageData0(t){try{if(t.startsWith("data:image/")){const e=t.match(/^data:image\/(png|jpeg|jpg);base64,(.*)$/);if(!e)throw new Error("Invalid base64 image data");return{data:t,type:e[1]}}else{const e=await fetch(t);if(!e.ok)throw new Error("Network response was not ok");const a=await e.blob();return new Promise((n,r)=>{const s=new FileReader;s.onloadend=function(){const o=s.result,i=o.match(/^data:image\/(png|jpeg|jpg);base64,/);i?n({data:o,type:i[1]}):r(new Error("Could not determine image type"))},s.onerror=r,s.readAsDataURL(a)})}}catch(e){return console.warn(e),null}}getBase64(t){return new Promise((e,a)=>{const n=new FileReader;n.readAsDataURL(t),n.onload=()=>e(n.result),n.onerror=r=>a(r)})}}const g=new d;module.exports=g;
|
package/dist/util/ImageUtil.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RcFile } from 'antd/lib/upload';
|
|
2
2
|
export type ImageDataReturn = {
|
|
3
3
|
data: string;
|
|
4
|
-
type:
|
|
4
|
+
type: "png" | "jpeg" | "jpg";
|
|
5
5
|
width: number;
|
|
6
6
|
height: number;
|
|
7
7
|
} | null;
|
|
@@ -9,6 +9,7 @@ declare class ImageUtl {
|
|
|
9
9
|
resizeImage(file: RcFile): Promise<RcFile>;
|
|
10
10
|
getImageData(uriOrBase64: string): Promise<ImageDataReturn>;
|
|
11
11
|
getImageData0(uriOrBase64: string): Promise<ImageDataReturn>;
|
|
12
|
+
getBase64(file: any): Promise<string>;
|
|
12
13
|
}
|
|
13
14
|
declare const _default: ImageUtl;
|
|
14
15
|
export default _default;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
class
|
|
1
|
+
import d from "browser-image-compression";
|
|
2
|
+
class c {
|
|
3
3
|
async resizeImage(t) {
|
|
4
|
-
const e = await
|
|
4
|
+
const e = await d(t, {
|
|
5
5
|
maxSizeMB: 1,
|
|
6
6
|
maxWidthOrHeight: 1920,
|
|
7
7
|
useWebWorker: !0
|
|
@@ -16,48 +16,61 @@ class g {
|
|
|
16
16
|
if (e) {
|
|
17
17
|
const a = new Image();
|
|
18
18
|
a.src = e.data;
|
|
19
|
-
const
|
|
20
|
-
(
|
|
19
|
+
const n = await new Promise(
|
|
20
|
+
(r) => {
|
|
21
21
|
a.onload = function() {
|
|
22
|
-
|
|
22
|
+
r({
|
|
23
23
|
height: a.height,
|
|
24
24
|
width: a.width
|
|
25
25
|
});
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
);
|
|
29
|
-
return Object.assign(e,
|
|
29
|
+
return Object.assign(e, n), e;
|
|
30
30
|
} else
|
|
31
31
|
return null;
|
|
32
32
|
}
|
|
33
33
|
async getImageData0(t) {
|
|
34
34
|
try {
|
|
35
35
|
if (t.startsWith("data:image/")) {
|
|
36
|
-
const e = t.match(
|
|
36
|
+
const e = t.match(
|
|
37
|
+
/^data:image\/(png|jpeg|jpg);base64,(.*)$/
|
|
38
|
+
);
|
|
37
39
|
if (!e)
|
|
38
40
|
throw new Error("Invalid base64 image data");
|
|
39
|
-
return {
|
|
41
|
+
return {
|
|
42
|
+
data: t,
|
|
43
|
+
type: e[1]
|
|
44
|
+
};
|
|
40
45
|
} else {
|
|
41
46
|
const e = await fetch(t);
|
|
42
47
|
if (!e.ok) throw new Error("Network response was not ok");
|
|
43
48
|
const a = await e.blob();
|
|
44
|
-
return new Promise((
|
|
49
|
+
return new Promise((n, r) => {
|
|
45
50
|
const s = new FileReader();
|
|
46
51
|
s.onloadend = function() {
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
const o = s.result, i = o.match(
|
|
53
|
+
/^data:image\/(png|jpeg|jpg);base64,/
|
|
54
|
+
);
|
|
55
|
+
i ? n({
|
|
56
|
+
data: o,
|
|
50
57
|
type: i[1]
|
|
51
|
-
}) :
|
|
52
|
-
}, s.onerror =
|
|
58
|
+
}) : r(new Error("Could not determine image type"));
|
|
59
|
+
}, s.onerror = r, s.readAsDataURL(a);
|
|
53
60
|
});
|
|
54
61
|
}
|
|
55
62
|
} catch (e) {
|
|
56
63
|
return console.warn(e), null;
|
|
57
64
|
}
|
|
58
65
|
}
|
|
66
|
+
getBase64(t) {
|
|
67
|
+
return new Promise((e, a) => {
|
|
68
|
+
const n = new FileReader();
|
|
69
|
+
n.readAsDataURL(t), n.onload = () => e(n.result), n.onerror = (r) => a(r);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
59
72
|
}
|
|
60
|
-
const l = new
|
|
73
|
+
const l = new c();
|
|
61
74
|
export {
|
|
62
75
|
l as default
|
|
63
76
|
};
|