@ecoding/components.antd 0.3.57 → 0.3.58
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.
|
@@ -56,7 +56,15 @@ const MultiPileImgUpload = (props) => {
|
|
|
56
56
|
const updateItems = (newItems) => {
|
|
57
57
|
var _a;
|
|
58
58
|
setItems(newItems);
|
|
59
|
-
|
|
59
|
+
let isEmpty = true;
|
|
60
|
+
const urls = newItems.map((item) => item.url);
|
|
61
|
+
urls.forEach((item) => {
|
|
62
|
+
if (item) {
|
|
63
|
+
isEmpty = false;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
props.onChange && ((_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, !isEmpty ? urls : undefined));
|
|
60
68
|
};
|
|
61
69
|
useEffect(() => {
|
|
62
70
|
const initItems = Array(props.max)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { PlusOutlined } from '@ant-design/icons';
|
|
3
|
+
import { isEqual } from "@ecoding/helper.is";
|
|
4
|
+
import { Flex, Input, Tag, theme, Tooltip } from 'antd';
|
|
5
|
+
const tagInputStyle = {
|
|
6
|
+
width: 64,
|
|
7
|
+
height: 22,
|
|
8
|
+
marginInlineEnd: 8,
|
|
9
|
+
verticalAlign: 'top'
|
|
10
|
+
};
|
|
11
|
+
const C = (props) => {
|
|
12
|
+
const { token } = theme.useToken();
|
|
13
|
+
const [tags, setTags] = useState([]);
|
|
14
|
+
const [inputVisible, setInputVisible] = useState(false);
|
|
15
|
+
const [inputValue, setInputValue] = useState('');
|
|
16
|
+
const [editInputIndex, setEditInputIndex] = useState(-1);
|
|
17
|
+
const [editInputValue, setEditInputValue] = useState('');
|
|
18
|
+
const inputRef = useRef(null);
|
|
19
|
+
const editInputRef = useRef(null);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
var _a;
|
|
22
|
+
if (inputVisible) {
|
|
23
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
24
|
+
}
|
|
25
|
+
}, [inputVisible]);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
var _a;
|
|
28
|
+
(_a = editInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
29
|
+
}, [editInputValue]);
|
|
30
|
+
const handleClose = (removedTag) => {
|
|
31
|
+
const newTags = tags.filter((tag) => tag !== removedTag);
|
|
32
|
+
setTags(newTags);
|
|
33
|
+
props.onChange && props.onChange(newTags && newTags.length > 0 ? newTags : undefined);
|
|
34
|
+
};
|
|
35
|
+
const showInput = () => {
|
|
36
|
+
setInputVisible(true);
|
|
37
|
+
};
|
|
38
|
+
const handleInputChange = (e) => {
|
|
39
|
+
setInputValue(e.target.value);
|
|
40
|
+
};
|
|
41
|
+
const handleInputConfirm = () => {
|
|
42
|
+
if (inputValue && !tags.includes(inputValue)) {
|
|
43
|
+
const values = [...tags, inputValue];
|
|
44
|
+
setTags(values);
|
|
45
|
+
props.onChange && props.onChange(values && values.length > 0 ? values : undefined);
|
|
46
|
+
}
|
|
47
|
+
setInputVisible(false);
|
|
48
|
+
setInputValue('');
|
|
49
|
+
};
|
|
50
|
+
const handleEditInputChange = (e) => {
|
|
51
|
+
setEditInputValue(e.target.value);
|
|
52
|
+
};
|
|
53
|
+
const handleEditInputConfirm = () => {
|
|
54
|
+
const newTags = [...(tags || [])];
|
|
55
|
+
newTags[editInputIndex] = editInputValue;
|
|
56
|
+
setTags(newTags);
|
|
57
|
+
props.onChange && props.onChange(newTags && newTags.length > 0 ? newTags : undefined);
|
|
58
|
+
setEditInputIndex(-1);
|
|
59
|
+
setEditInputValue('');
|
|
60
|
+
};
|
|
61
|
+
const tagPlusStyle = {
|
|
62
|
+
height: 22,
|
|
63
|
+
background: token.colorBgContainer,
|
|
64
|
+
borderStyle: 'dashed'
|
|
65
|
+
};
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (props.value && !isEqual(props.value, tags)) {
|
|
68
|
+
setTags(props.value);
|
|
69
|
+
}
|
|
70
|
+
}, [props.value]);
|
|
71
|
+
return (React.createElement(Flex, { gap: "4px 0", wrap: "wrap" },
|
|
72
|
+
tags.map((tag, index) => {
|
|
73
|
+
if (editInputIndex === index) {
|
|
74
|
+
return (React.createElement(Input, { ref: editInputRef, key: tag, size: "small", style: tagInputStyle, value: editInputValue, onChange: handleEditInputChange, onBlur: handleEditInputConfirm, onPressEnter: handleEditInputConfirm }));
|
|
75
|
+
}
|
|
76
|
+
const isLongTag = tag.length > 20;
|
|
77
|
+
const tagElem = (React.createElement(Tag, { key: tag, closable: props.fixedFirst ? index !== 0 : true, style: { userSelect: 'none' }, onClose: () => handleClose(tag) },
|
|
78
|
+
React.createElement("span", { onDoubleClick: (e) => {
|
|
79
|
+
if (props.disabled) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (props.fixedFirst ? index !== 0 : true) {
|
|
83
|
+
setEditInputIndex(index);
|
|
84
|
+
setEditInputValue(tag);
|
|
85
|
+
e.preventDefault();
|
|
86
|
+
}
|
|
87
|
+
} }, isLongTag ? `${tag.slice(0, 20)}...` : tag)));
|
|
88
|
+
return isLongTag ? (React.createElement(Tooltip, { title: tag, key: tag }, tagElem)) : (tagElem);
|
|
89
|
+
}),
|
|
90
|
+
props.disabled ? null : inputVisible ? (React.createElement(Input, { ref: inputRef, type: "text", size: "small", style: tagInputStyle, value: inputValue, onChange: handleInputChange, onBlur: handleInputConfirm, onPressEnter: handleInputConfirm })) : (React.createElement(Tag, { style: tagPlusStyle, icon: React.createElement(PlusOutlined, null), onClick: showInput }, props.addTagText))));
|
|
91
|
+
};
|
|
92
|
+
C.defaultProps = {
|
|
93
|
+
disabled: false,
|
|
94
|
+
fixedFirst: false,
|
|
95
|
+
addTagText: 'New Tag'
|
|
96
|
+
};
|
|
97
|
+
export default C;
|
package/lib/index.d.ts
CHANGED
|
@@ -19,5 +19,6 @@ export { default as FormLabelAttachment } from "./core/form.label.attachment";
|
|
|
19
19
|
export { default as FormList } from "./core/form.list";
|
|
20
20
|
export { default as AsyncSelect } from "./core/async-select";
|
|
21
21
|
export { default as AsyncTransfer } from "./core/async-transfer";
|
|
22
|
+
export { default as TagItems } from "./core/tag.items";
|
|
22
23
|
export { default as TablePro } from "./core/table-pro";
|
|
23
24
|
export { default as http } from "./helpers/http";
|
package/lib/index.js
CHANGED
|
@@ -19,5 +19,6 @@ export { default as FormLabelAttachment } from "./core/form.label.attachment";
|
|
|
19
19
|
export { default as FormList } from "./core/form.list";
|
|
20
20
|
export { default as AsyncSelect } from "./core/async-select";
|
|
21
21
|
export { default as AsyncTransfer } from "./core/async-transfer";
|
|
22
|
+
export { default as TagItems } from "./core/tag.items";
|
|
22
23
|
export { default as TablePro } from "./core/table-pro";
|
|
23
24
|
export { default as http } from "./helpers/http";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecoding/components.antd",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.58",
|
|
4
4
|
"author": "cxc",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,6 +24,8 @@
|
|
|
24
24
|
"build": "rm -rf lib && tsc && rollup -c"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
+
"@dnd-kit/core": ">=6.3.1",
|
|
28
|
+
"@dnd-kit/sortable": ">=10.0.0",
|
|
27
29
|
"@ecoding/helper.event": "*",
|
|
28
30
|
"@ecoding/helper.is": "*",
|
|
29
31
|
"@ecoding/helper.json": "*",
|
|
@@ -45,5 +47,5 @@
|
|
|
45
47
|
"antd": "5.27.0",
|
|
46
48
|
"axios": "^1.1.2"
|
|
47
49
|
},
|
|
48
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "d005731c58467d76d54228231819e2489af8ab2c"
|
|
49
51
|
}
|