refactor: embeddding input list
This commit is contained in:
@@ -46,4 +46,4 @@ const AlertInfo: React.FC<AlertInfoProps> = (props) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default React.memo(AlertInfo);
|
export default AlertInfo;
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ interface SingleImageProps {
|
|||||||
maxWidth?: number;
|
maxWidth?: number;
|
||||||
dataUrl: string;
|
dataUrl: string;
|
||||||
label?: React.ReactNode;
|
label?: React.ReactNode;
|
||||||
uid: number;
|
uid: number | string;
|
||||||
preview?: boolean;
|
preview?: boolean;
|
||||||
autoSize?: boolean;
|
autoSize?: boolean;
|
||||||
onDelete: (uid: number) => void;
|
onDelete: (uid: number | string) => void;
|
||||||
onClick?: (item: any) => void;
|
onClick?: (item: any) => void;
|
||||||
autoBgColor?: boolean;
|
autoBgColor?: boolean;
|
||||||
editable?: boolean;
|
editable?: boolean;
|
||||||
@@ -94,7 +94,7 @@ const SingleImage: React.FC<SingleImageProps> = (props) => {
|
|||||||
|
|
||||||
const handleOnLoad = React.useCallback(async () => {}, []);
|
const handleOnLoad = React.useCallback(async () => {}, []);
|
||||||
|
|
||||||
const handleOnDelete = (uid: number, e: any) => {
|
const handleOnDelete = (uid: number | string, e: any) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
onDelete(uid);
|
onDelete(uid);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { CloseOutlined } from '@ant-design/icons';
|
import SmallCloseButton from '@/pages/_components/small-close-button';
|
||||||
|
import ThumbImg from '@/pages/playground/components/thumb-img';
|
||||||
|
import useAddImage from '@/pages/playground/hooks/use-add-image';
|
||||||
|
import { DeleteOutlined } from '@ant-design/icons';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Button, Input, Tooltip } from 'antd';
|
import { Button, Input, Tooltip } from 'antd';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
@@ -7,12 +10,20 @@ import './styles/row-textarea.less';
|
|||||||
|
|
||||||
interface SystemMessageProps {
|
interface SystemMessageProps {
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
value: string;
|
data: {
|
||||||
|
text: string;
|
||||||
|
uid: number | string;
|
||||||
|
name: string;
|
||||||
|
dataUrl?: string;
|
||||||
|
};
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
label?: React.ReactNode;
|
label?: React.ReactNode;
|
||||||
height?: number;
|
height?: number;
|
||||||
|
onUploadImage?: (list: { uid: number | string; dataUrl: string }[]) => void;
|
||||||
|
onDeleteImage?: () => void;
|
||||||
onChange: (e: any) => void;
|
onChange: (e: any) => void;
|
||||||
onPaste?: (e: any) => void;
|
onPaste?: (e: any) => void;
|
||||||
|
onDelete?: () => void;
|
||||||
onSelect?: (data: {
|
onSelect?: (data: {
|
||||||
start: number;
|
start: number;
|
||||||
end: number;
|
end: number;
|
||||||
@@ -23,9 +34,12 @@ interface SystemMessageProps {
|
|||||||
|
|
||||||
const RowTextarea: React.FC<SystemMessageProps> = (props) => {
|
const RowTextarea: React.FC<SystemMessageProps> = (props) => {
|
||||||
const {
|
const {
|
||||||
value,
|
data,
|
||||||
|
onDeleteImage,
|
||||||
|
onUploadImage,
|
||||||
onChange,
|
onChange,
|
||||||
onSelect,
|
onSelect,
|
||||||
|
onDelete,
|
||||||
style,
|
style,
|
||||||
label,
|
label,
|
||||||
placeholder,
|
placeholder,
|
||||||
@@ -76,8 +90,8 @@ const RowTextarea: React.FC<SystemMessageProps> = (props) => {
|
|||||||
const start = e.target.selectionStart;
|
const start = e.target.selectionStart;
|
||||||
const end = e.target.selectionEnd;
|
const end = e.target.selectionEnd;
|
||||||
|
|
||||||
const beforeText = value.substring(0, start);
|
const beforeText = data.text.substring(0, start);
|
||||||
const afterText = value.substring(end, value.length);
|
const afterText = data.text.substring(end, data.text.length);
|
||||||
onSelect?.({
|
onSelect?.({
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
@@ -86,64 +100,130 @@ const RowTextarea: React.FC<SystemMessageProps> = (props) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleUploadImage = (
|
||||||
|
list: { uid: number | string; dataUrl: string }[]
|
||||||
|
) => {
|
||||||
|
onUploadImage?.(list);
|
||||||
|
};
|
||||||
|
|
||||||
|
const { ImageURLInput, UploadImageButton, isFromUrl, dropDownOpen } =
|
||||||
|
useAddImage({
|
||||||
|
size: 'small',
|
||||||
|
inputProps: {
|
||||||
|
variant: 'filled'
|
||||||
|
},
|
||||||
|
handleUpdateImgList: handleUploadImage,
|
||||||
|
updateUidCount: () => `img-${Date.now()}`
|
||||||
|
});
|
||||||
|
|
||||||
|
const expanded = autoSize.focus || !!data.dataUrl || isFromUrl;
|
||||||
|
// const expanded = true;
|
||||||
|
|
||||||
|
console.log('expanded===========', expanded);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={classNames('row-textarea', {
|
className={classNames('row-textarea-wrapper', {
|
||||||
focus: autoSize.focus
|
dropDownOpen: dropDownOpen,
|
||||||
|
expanded: expanded
|
||||||
})}
|
})}
|
||||||
style={{ ...style }}
|
|
||||||
>
|
>
|
||||||
{
|
<div
|
||||||
|
className={classNames('row-textarea', {
|
||||||
|
expanded: expanded
|
||||||
|
})}
|
||||||
|
style={{ ...style }}
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
style={{ display: autoSize.focus ? 'block' : 'none' }}
|
style={{
|
||||||
|
display: expanded ? 'block' : 'none'
|
||||||
|
}}
|
||||||
className="textarea-wrapper"
|
className="textarea-wrapper"
|
||||||
>
|
>
|
||||||
{label && <span className="textarea-label">{label}</span>}
|
{label && <span className="textarea-label">{label}</span>}
|
||||||
|
{data.dataUrl && (
|
||||||
|
<div style={{ padding: 8 }}>
|
||||||
|
<ThumbImg
|
||||||
|
editable
|
||||||
|
dataList={
|
||||||
|
data.dataUrl ? [{ uid: data.uid, dataUrl: data.dataUrl }] : []
|
||||||
|
}
|
||||||
|
onDelete={onDeleteImage}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<Input.TextArea
|
<Input.TextArea
|
||||||
className="custome-scrollbar"
|
className="custome-scrollbar"
|
||||||
|
allowClear
|
||||||
ref={rowTextAreaRef}
|
ref={rowTextAreaRef}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
style={{
|
style={{
|
||||||
borderRadius: '0',
|
borderRadius: '0',
|
||||||
border: 'none'
|
border: 'none',
|
||||||
}}
|
width: '100%',
|
||||||
value={value}
|
boxShadow: 'none'
|
||||||
autoSize={{
|
|
||||||
minRows: autoSize.minRows,
|
|
||||||
maxRows: autoSize.maxRows
|
|
||||||
}}
|
}}
|
||||||
|
value={data.text}
|
||||||
|
autoSize={
|
||||||
|
expanded
|
||||||
|
? {
|
||||||
|
minRows: 5,
|
||||||
|
maxRows: 5
|
||||||
|
}
|
||||||
|
: { minRows: autoSize.minRows, maxRows: autoSize.maxRows }
|
||||||
|
}
|
||||||
onFocus={handleFocus}
|
onFocus={handleFocus}
|
||||||
onBlur={handleBlur}
|
onBlur={handleBlur}
|
||||||
allowClear={false}
|
|
||||||
onChange={handleOnChange}
|
onChange={handleOnChange}
|
||||||
onSelect={handleOnSelect}
|
onSelect={handleOnSelect}
|
||||||
onPaste={handleOnPaste}
|
onPaste={handleOnPaste}
|
||||||
|
onClear={handleClear}
|
||||||
></Input.TextArea>
|
></Input.TextArea>
|
||||||
</div>
|
</div>
|
||||||
}
|
|
||||||
{!autoSize.focus && (
|
{!expanded && (
|
||||||
<div className="content-wrap" onClick={handleFocus}>
|
<div
|
||||||
<div className="content" style={{ height: height }}>
|
className={classNames('content-wrap', {
|
||||||
{label && <span className="title">{label}</span>}
|
dropDownOpen: dropDownOpen
|
||||||
{value || (
|
})}
|
||||||
<span style={{ color: 'var(--ant-color-text-tertiary)' }}>
|
onClick={handleFocus}
|
||||||
{placeholder}
|
>
|
||||||
</span>
|
{
|
||||||
)}
|
<div className="content" style={{ height: height }}>
|
||||||
|
{label && <span className="title">{label}</span>}
|
||||||
|
{data.text || (
|
||||||
|
<span style={{ color: 'var(--ant-color-text-tertiary)' }}>
|
||||||
|
{placeholder}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
{value && (
|
)}
|
||||||
<Tooltip title={intl.formatMessage({ id: 'common.button.clear' })}>
|
<div
|
||||||
|
className={classNames('actions-wrapper', {
|
||||||
|
show: expanded
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{ImageURLInput}
|
||||||
|
<div className={'actions'}>
|
||||||
|
{!expanded && data.text && (
|
||||||
|
<SmallCloseButton onClick={handleClear}></SmallCloseButton>
|
||||||
|
)}
|
||||||
|
{UploadImageButton}
|
||||||
|
<Tooltip title={intl.formatMessage({ id: 'common.button.delete' })}>
|
||||||
<Button
|
<Button
|
||||||
className="clear-btn"
|
danger
|
||||||
type="text"
|
|
||||||
icon={<CloseOutlined />}
|
|
||||||
size="small"
|
size="small"
|
||||||
onClick={handleClear}
|
type="text"
|
||||||
|
icon={<DeleteOutlined></DeleteOutlined>}
|
||||||
|
onClick={onDelete}
|
||||||
></Button>
|
></Button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,89 @@
|
|||||||
.row-textarea {
|
.row-textarea-wrapper {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
&.focus {
|
.actions-wrapper {
|
||||||
// padding-top: 9px;
|
display: none;
|
||||||
|
position: absolute;
|
||||||
|
right: 6px;
|
||||||
|
bottom: 50%;
|
||||||
|
transform: translateY(50%);
|
||||||
|
gap: 8px;
|
||||||
|
z-index: 10;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actions {
|
||||||
|
gap: 4px;
|
||||||
|
align-items: center;
|
||||||
|
border-radius: var(--ant-border-radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
&.show {
|
||||||
|
display: flex;
|
||||||
|
bottom: 8px;
|
||||||
|
transform: unset;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
.actions-wrapper {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.dropDownOpen {
|
||||||
|
.actions-wrapper {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.expanded {
|
||||||
|
.actions-wrapper {
|
||||||
|
display: flex;
|
||||||
|
bottom: 8px;
|
||||||
|
transform: unset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.row-textarea {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color 0.3s ease;
|
||||||
|
border-radius: var(--border-radius-base);
|
||||||
|
border: 1px solid var(--ant-color-border);
|
||||||
|
|
||||||
|
.textarea-wrapper {
|
||||||
|
flex: 1;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
&::before {
|
||||||
|
content: '';
|
||||||
|
display: flex;
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
bottom: 0;
|
||||||
|
right: 0;
|
||||||
|
top: 0;
|
||||||
|
background-color: var(--ant-color-fill-tertiary);
|
||||||
|
z-index: 5;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&:focus-within {
|
||||||
|
background-color: transparent;
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.content-wrap {
|
.content-wrap {
|
||||||
@@ -10,13 +91,12 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
padding-right: 20px;
|
flex: 1;
|
||||||
|
width: 100%;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
||||||
&:hover {
|
.content {
|
||||||
.clear-btn {
|
margin-right: 60px;
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,14 +105,6 @@
|
|||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.clear-btn {
|
|
||||||
display: none;
|
|
||||||
position: absolute;
|
|
||||||
right: 6px;
|
|
||||||
top: 50%;
|
|
||||||
transform: translateY(-50%);
|
|
||||||
}
|
|
||||||
|
|
||||||
.textarea-label {
|
.textarea-label {
|
||||||
position: relative;
|
position: relative;
|
||||||
top: 4px;
|
top: 4px;
|
||||||
@@ -45,7 +117,6 @@
|
|||||||
height: 46px;
|
height: 46px;
|
||||||
line-height: 30px;
|
line-height: 30px;
|
||||||
padding: 8px 14px;
|
padding: 8px 14px;
|
||||||
padding-right: 4px;
|
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
|||||||
@@ -330,7 +330,6 @@ const langConfigMap = {
|
|||||||
title: '語言'
|
title: '語言'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export type LangConfigType = keyof typeof langConfigMap;
|
export type LangConfigType = keyof typeof langConfigMap;
|
||||||
|
|
||||||
export default langConfigMap;
|
export default langConfigMap;
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { CloseCircleFilled } from '@ant-design/icons';
|
||||||
|
import { Button } from 'antd';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
const StyledButton = styled(Button)`
|
||||||
|
background-color: transparent !important;
|
||||||
|
padding: 0;
|
||||||
|
.anticon {
|
||||||
|
color: var(--ant-color-text-quaternary);
|
||||||
|
font-size: 12px !important;
|
||||||
|
transition: color 0.3s ease;
|
||||||
|
}
|
||||||
|
&:hover {
|
||||||
|
.anticon {
|
||||||
|
color: var(--ant-color-text-tertiary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
interface SmallCloseButtonProps {
|
||||||
|
onClick?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SmallCloseButton: React.FC<SmallCloseButtonProps> = ({ onClick }) => {
|
||||||
|
return (
|
||||||
|
<StyledButton
|
||||||
|
icon={<CloseCircleFilled />}
|
||||||
|
shape="circle"
|
||||||
|
type="text"
|
||||||
|
onClick={onClick}
|
||||||
|
size="small"
|
||||||
|
></StyledButton>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SmallCloseButton;
|
||||||
@@ -80,17 +80,19 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
const selectionTextRef = useRef<any>(null);
|
const selectionTextRef = useRef<any>(null);
|
||||||
|
|
||||||
const [textList, setTextList] = useState<
|
const [textList, setTextList] = useState<
|
||||||
{ text: string; uid: number | string; name: string }[]
|
{ text: string; dataUrl?: string; uid: number | string; name: string }[]
|
||||||
>([
|
>([
|
||||||
{
|
{
|
||||||
text: '',
|
text: '',
|
||||||
uid: -1,
|
uid: -1,
|
||||||
name: ''
|
name: '',
|
||||||
|
dataUrl: ''
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: '',
|
text: '',
|
||||||
uid: -2,
|
uid: -2,
|
||||||
name: ''
|
name: '',
|
||||||
|
dataUrl: ''
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -169,12 +171,14 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
try {
|
try {
|
||||||
await formRef.current?.form.validateFields();
|
await formRef.current?.form.validateFields();
|
||||||
if (!parameters.model) return;
|
if (!parameters.model) return;
|
||||||
const validTextList = textList.filter((item) => item.text);
|
const validTextList = textList.filter(
|
||||||
|
(item) => item.text || item.dataUrl
|
||||||
|
);
|
||||||
const validFileList = fileList.filter((item) => item.text);
|
const validFileList = fileList.filter((item) => item.text);
|
||||||
|
|
||||||
const inputList = [
|
const inputList = [
|
||||||
...validTextList.map((item) => item.text),
|
...validTextList.map((item) => item.text || item.dataUrl || ''),
|
||||||
...validFileList.map((item) => item.text)
|
...validFileList.map((item) => item.text || '')
|
||||||
];
|
];
|
||||||
|
|
||||||
if (inputList.length < 2) {
|
if (inputList.length < 2) {
|
||||||
@@ -280,6 +284,44 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
setTextList(list);
|
setTextList(list);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleOnUploadImage = (
|
||||||
|
list: { uid: number | string; dataUrl: string }[],
|
||||||
|
index: number
|
||||||
|
) => {
|
||||||
|
// replace the text with dataUrl in the textList
|
||||||
|
setTextList((preList) => {
|
||||||
|
const newList = [...preList];
|
||||||
|
const current = newList[index];
|
||||||
|
if (current) {
|
||||||
|
newList[index] = {
|
||||||
|
...current,
|
||||||
|
text: '',
|
||||||
|
uid: list[0].uid,
|
||||||
|
dataUrl: list[0].dataUrl
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return newList;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleOnDeleteImage = (item: {
|
||||||
|
text: string;
|
||||||
|
uid: number | string;
|
||||||
|
name: string;
|
||||||
|
dataUrl?: string;
|
||||||
|
}) => {
|
||||||
|
// replace the dataUrl with empty text in the textList
|
||||||
|
setTextList((preList) => {
|
||||||
|
const newList = [...preList];
|
||||||
|
const current = newList.find((i) => i.uid === item.uid);
|
||||||
|
if (current) {
|
||||||
|
current.text = '';
|
||||||
|
current.dataUrl = '';
|
||||||
|
}
|
||||||
|
return newList;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const handleonSelect = useCallback(
|
const handleonSelect = useCallback(
|
||||||
(data: {
|
(data: {
|
||||||
start: number;
|
start: number;
|
||||||
@@ -540,6 +582,8 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
onChange={handleTextListChange}
|
onChange={handleTextListChange}
|
||||||
onSelect={handleonSelect}
|
onSelect={handleonSelect}
|
||||||
onPaste={handleOnPaste}
|
onPaste={handleOnPaste}
|
||||||
|
onUploadImage={handleOnUploadImage}
|
||||||
|
onDeleteImage={handleOnDeleteImage}
|
||||||
></InputList>
|
></InputList>
|
||||||
{fileList.length > 0 && (
|
{fileList.length > 0 && (
|
||||||
<div style={{ marginTop: 8 }}>
|
<div style={{ marginTop: 8 }}>
|
||||||
@@ -576,7 +620,7 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<h3 className="m-l-10 flex-between flex-center font-size-14 line-24 m-b-16">
|
<h3 className="m-l-10 flex-between flex-center font-size-14 line-24 m-b-16">
|
||||||
<div className="flex gap-20">
|
<div className="flex gap-16">
|
||||||
<span className="flex-center">
|
<span className="flex-center">
|
||||||
{intl.formatMessage({ id: 'playground.embedding.output' })}
|
{intl.formatMessage({ id: 'playground.embedding.output' })}
|
||||||
<Tooltip
|
<Tooltip
|
||||||
@@ -602,6 +646,7 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
</span>
|
</span>
|
||||||
<AlertInfo
|
<AlertInfo
|
||||||
type="danger"
|
type="danger"
|
||||||
|
style={{ marginRight: 16 }}
|
||||||
message={tokenResult?.errorMessage}
|
message={tokenResult?.errorMessage}
|
||||||
></AlertInfo>
|
></AlertInfo>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
name: string;
|
name: string;
|
||||||
score?: number;
|
score?: number;
|
||||||
showExtra?: boolean;
|
showExtra?: boolean;
|
||||||
|
dataUrl?: string;
|
||||||
percent?: number;
|
percent?: number;
|
||||||
rank?: number;
|
rank?: number;
|
||||||
}[]
|
}[]
|
||||||
@@ -129,12 +130,14 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
{
|
{
|
||||||
text: '',
|
text: '',
|
||||||
uid: -1,
|
uid: -1,
|
||||||
name: ''
|
name: '',
|
||||||
|
dataUrl: ''
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: '',
|
text: '',
|
||||||
uid: -2,
|
uid: -2,
|
||||||
name: ''
|
name: '',
|
||||||
|
dataUrl: ''
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
const [queryValue, setQueryValue] = useState<string>('');
|
const [queryValue, setQueryValue] = useState<string>('');
|
||||||
@@ -388,6 +391,44 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
selectionTextRef.current = data;
|
selectionTextRef.current = data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleOnUploadImage = (
|
||||||
|
list: { uid: number | string; dataUrl: string }[],
|
||||||
|
index: number
|
||||||
|
) => {
|
||||||
|
// replace the text with dataUrl in the textList
|
||||||
|
setTextList((preList) => {
|
||||||
|
const newList = [...preList];
|
||||||
|
const current = newList[index];
|
||||||
|
if (current) {
|
||||||
|
newList[index] = {
|
||||||
|
...current,
|
||||||
|
text: '',
|
||||||
|
uid: list[0].uid,
|
||||||
|
dataUrl: list[0].dataUrl
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return newList;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleOnDeleteImage = (item: {
|
||||||
|
text: string;
|
||||||
|
uid: number | string;
|
||||||
|
name: string;
|
||||||
|
dataUrl?: string;
|
||||||
|
}) => {
|
||||||
|
// replace the dataUrl with empty text in the textList
|
||||||
|
setTextList((preList) => {
|
||||||
|
const newList = [...preList];
|
||||||
|
const current = newList.find((i) => i.uid === item.uid);
|
||||||
|
if (current) {
|
||||||
|
current.text = '';
|
||||||
|
current.dataUrl = '';
|
||||||
|
}
|
||||||
|
return newList;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const handleOnPaste = (e: any, index: number) => {
|
const handleOnPaste = (e: any, index: number) => {
|
||||||
if (!multiplePasteEnable.current) return;
|
if (!multiplePasteEnable.current) return;
|
||||||
const text = e.clipboardData.getData('text');
|
const text = e.clipboardData.getData('text');
|
||||||
@@ -559,7 +600,9 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
onChange={handleTextListChange}
|
onChange={handleTextListChange}
|
||||||
extra={renderPercent}
|
extra={renderPercent}
|
||||||
onSelect={handleonSelect}
|
onSelect={handleonSelect}
|
||||||
|
onUploadImage={handleOnUploadImage}
|
||||||
onPaste={handleOnPaste}
|
onPaste={handleOnPaste}
|
||||||
|
onDeleteImage={handleOnDeleteImage}
|
||||||
></InputList>
|
></InputList>
|
||||||
{isEmptyText && (
|
{isEmptyText && (
|
||||||
<div className="m-t-16">
|
<div className="m-t-16">
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import RowTextarea from '@/components/seal-form/row-textarea';
|
import RowTextarea from '@/components/seal-form/row-textarea';
|
||||||
import { DeleteOutlined } from '@ant-design/icons';
|
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Button, Tooltip } from 'antd';
|
|
||||||
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
|
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
|
||||||
import '../style/input-list.less';
|
import '../style/input-list.less';
|
||||||
|
|
||||||
@@ -14,11 +12,26 @@ interface InputListProps {
|
|||||||
text: string;
|
text: string;
|
||||||
uid: number | string;
|
uid: number | string;
|
||||||
name: string;
|
name: string;
|
||||||
|
dataUrl?: string;
|
||||||
}[];
|
}[];
|
||||||
onChange?: (
|
onChange?: (
|
||||||
textList: { text: string; uid: number | string; name: string }[]
|
textList: {
|
||||||
|
text: string;
|
||||||
|
uid: number | string;
|
||||||
|
name: string;
|
||||||
|
dataUrl?: string;
|
||||||
|
}[]
|
||||||
) => void;
|
) => void;
|
||||||
onPaste?: (e: any, index: number) => void;
|
onPaste?: (e: any, index: number) => void;
|
||||||
|
onDeleteImage?: (dataItem: {
|
||||||
|
text: string;
|
||||||
|
uid: number | string;
|
||||||
|
name: string;
|
||||||
|
}) => void;
|
||||||
|
onUploadImage?: (
|
||||||
|
list: { uid: number | string; dataUrl: string }[],
|
||||||
|
index: number
|
||||||
|
) => void;
|
||||||
onSelect?: (data: {
|
onSelect?: (data: {
|
||||||
start: number;
|
start: number;
|
||||||
end: number;
|
end: number;
|
||||||
@@ -30,7 +43,17 @@ interface InputListProps {
|
|||||||
|
|
||||||
const InputList: React.FC<InputListProps> = forwardRef(
|
const InputList: React.FC<InputListProps> = forwardRef(
|
||||||
(
|
(
|
||||||
{ textList, showLabel = true, height, onChange, extra, onPaste, onSelect },
|
{
|
||||||
|
textList,
|
||||||
|
showLabel = true,
|
||||||
|
height,
|
||||||
|
onUploadImage,
|
||||||
|
onDeleteImage,
|
||||||
|
onChange,
|
||||||
|
extra,
|
||||||
|
onPaste,
|
||||||
|
onSelect
|
||||||
|
},
|
||||||
ref
|
ref
|
||||||
) => {
|
) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
@@ -53,19 +76,19 @@ const InputList: React.FC<InputListProps> = forwardRef(
|
|||||||
onChange?.(dataList);
|
onChange?.(dataList);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDelete = (text: { text: string; uid: number | string }) => {
|
const handleDelete = (dataItem: { text: string; uid: number | string }) => {
|
||||||
const dataList = [...textList];
|
const dataList = [...textList];
|
||||||
const index = dataList.findIndex((item) => item.uid === text.uid);
|
const index = dataList.findIndex((item) => item.uid === dataItem.uid);
|
||||||
dataList.splice(index, 1);
|
dataList.splice(index, 1);
|
||||||
onChange?.(dataList);
|
onChange?.(dataList);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleTextChange = (
|
const handleTextChange = (
|
||||||
value: string,
|
value: string,
|
||||||
text: { text: string; uid: number | string }
|
dataItem: { text: string; uid: number | string }
|
||||||
) => {
|
) => {
|
||||||
const dataList = [...textList];
|
const dataList = [...textList];
|
||||||
const index = dataList.findIndex((item) => item.uid === text.uid);
|
const index = dataList.findIndex((item) => item.uid === dataItem.uid);
|
||||||
dataList[index].text = value;
|
dataList[index].text = value;
|
||||||
onChange?.(dataList);
|
onChange?.(dataList);
|
||||||
};
|
};
|
||||||
@@ -79,36 +102,26 @@ const InputList: React.FC<InputListProps> = forwardRef(
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="input-list" ref={containerRef}>
|
<div className="input-list" ref={containerRef}>
|
||||||
{textList.map((text, index) => {
|
{textList.map((item, index) => {
|
||||||
return (
|
return (
|
||||||
<div key={text.uid} className="input-item" data-uid={text.uid}>
|
<div key={item.uid} className="input-item" data-uid={item.uid}>
|
||||||
<div className="input-wrap">
|
<div className="input-wrap">
|
||||||
<RowTextarea
|
<RowTextarea
|
||||||
height={height}
|
height={height}
|
||||||
label={showLabel ? `${index + 1}` : null}
|
label={showLabel ? `${index + 1}` : null}
|
||||||
value={text.text}
|
data={item}
|
||||||
placeholder={intl.formatMessage({
|
placeholder={intl.formatMessage({
|
||||||
id: 'playground.embedding.inputyourtext'
|
id: 'playground.embedding.inputyourtext'
|
||||||
})}
|
})}
|
||||||
onChange={(e) => handleTextChange(e.target.value, text)}
|
onChange={(e) => handleTextChange(e.target.value, item)}
|
||||||
onPaste={(e) => onPaste?.(e, index)}
|
onPaste={(e) => onPaste?.(e, index)}
|
||||||
onSelect={(data) => onSelect?.({ ...data, index })}
|
onSelect={(data) => onSelect?.({ ...data, index })}
|
||||||
|
onUploadImage={(list) => onUploadImage?.(list, index)}
|
||||||
|
onDeleteImage={() => onDeleteImage?.(item)}
|
||||||
|
onDelete={() => handleDelete(item)}
|
||||||
></RowTextarea>
|
></RowTextarea>
|
||||||
</div>
|
</div>
|
||||||
<span className="btn-group">
|
{extra?.(item)}
|
||||||
<Tooltip
|
|
||||||
title={intl.formatMessage({ id: 'common.button.delete' })}
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
danger
|
|
||||||
size="small"
|
|
||||||
type="text"
|
|
||||||
icon={<DeleteOutlined></DeleteOutlined>}
|
|
||||||
onClick={() => handleDelete(text)}
|
|
||||||
></Button>
|
|
||||||
</Tooltip>
|
|
||||||
</span>
|
|
||||||
{extra?.(text)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -30,15 +30,27 @@ const ImgInputWrapper = styled.div`
|
|||||||
|
|
||||||
const useAddImage = (options: {
|
const useAddImage = (options: {
|
||||||
size?: 'small' | 'middle' | 'large';
|
size?: 'small' | 'middle' | 'large';
|
||||||
|
inputProps?: Record<string, any>;
|
||||||
handleUpdateImgList: (
|
handleUpdateImgList: (
|
||||||
list: { uid: number | string; dataUrl: string }[]
|
list: { uid: number | string; dataUrl: string }[]
|
||||||
) => void;
|
) => void;
|
||||||
updateUidCount: () => number | string;
|
updateUidCount: () => number | string;
|
||||||
}) => {
|
}) => {
|
||||||
const { handleUpdateImgList, updateUidCount, size = 'middle' } = options;
|
const {
|
||||||
|
handleUpdateImgList,
|
||||||
|
updateUidCount,
|
||||||
|
size = 'middle',
|
||||||
|
inputProps
|
||||||
|
} = options;
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const [isFromUrl, setIsFromUrl] = useState(false);
|
const [isFromUrl, setIsFromUrl] = useState(false);
|
||||||
const [openImgTips, setOpenImgTips] = useState(false);
|
const [openImgTips, setOpenImgTips] = useState(false);
|
||||||
|
const [dropDownOpen, setDropDownOpen] = useState(false);
|
||||||
|
|
||||||
|
const handleOnOpenChange = (open: boolean) => {
|
||||||
|
setDropDownOpen(open);
|
||||||
|
console.log('handleOnOpenChange', open);
|
||||||
|
};
|
||||||
const inputImgRef = useRef<any>(null);
|
const inputImgRef = useRef<any>(null);
|
||||||
|
|
||||||
const handleAddImgFromUrl = () => {
|
const handleAddImgFromUrl = () => {
|
||||||
@@ -93,6 +105,7 @@ const useAddImage = (options: {
|
|||||||
>
|
>
|
||||||
<ImgInputWrapper>
|
<ImgInputWrapper>
|
||||||
<Input
|
<Input
|
||||||
|
{...inputProps}
|
||||||
ref={inputImgRef}
|
ref={inputImgRef}
|
||||||
status={openImgTips ? 'error' : ''}
|
status={openImgTips ? 'error' : ''}
|
||||||
placeholder={intl.formatMessage({
|
placeholder={intl.formatMessage({
|
||||||
@@ -117,6 +130,7 @@ const useAddImage = (options: {
|
|||||||
|
|
||||||
const UploadImageButton = (
|
const UploadImageButton = (
|
||||||
<DropDownActions
|
<DropDownActions
|
||||||
|
onOpenChange={handleOnOpenChange}
|
||||||
placement={'topLeft'}
|
placement={'topLeft'}
|
||||||
menu={{
|
menu={{
|
||||||
items: [
|
items: [
|
||||||
@@ -143,13 +157,21 @@ const useAddImage = (options: {
|
|||||||
]
|
]
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Button type="text" size={size} icon={<PictureOutlined />}></Button>
|
<Button
|
||||||
|
type="text"
|
||||||
|
size={size}
|
||||||
|
icon={<PictureOutlined />}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
}}
|
||||||
|
></Button>
|
||||||
</DropDownActions>
|
</DropDownActions>
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isFromUrl,
|
isFromUrl,
|
||||||
ImageURLInput,
|
ImageURLInput,
|
||||||
|
dropDownOpen,
|
||||||
UploadImageButton
|
UploadImageButton
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,53 +1,12 @@
|
|||||||
.input-list {
|
.input-list {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 12px;
|
gap: 16px;
|
||||||
|
|
||||||
.input-item {
|
.input-item {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
padding: 0;
|
|
||||||
padding-right: 6px;
|
|
||||||
overflow: hidden;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: background-color 0.3s ease;
|
|
||||||
border-radius: var(--border-radius-base);
|
|
||||||
border: 1px solid var(--ant-color-border);
|
|
||||||
|
|
||||||
.btn-group {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
//background-color: var(--ant-color-fill-tertiary);
|
|
||||||
&::before {
|
|
||||||
content: '';
|
|
||||||
display: flex;
|
|
||||||
position: absolute;
|
|
||||||
left: 0;
|
|
||||||
bottom: 0;
|
|
||||||
right: 0;
|
|
||||||
top: 0;
|
|
||||||
background-color: var(--ant-color-fill-tertiary);
|
|
||||||
z-index: 5;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-group {
|
|
||||||
display: flex;
|
|
||||||
gap: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hover-hidden {
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&:focus-within {
|
&:focus-within {
|
||||||
//background-color: transparent;
|
|
||||||
|
|
||||||
&::before {
|
&::before {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user