mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-27 08:25:07 +00:00
fix: context menu
This commit is contained in:
@@ -13,8 +13,8 @@
|
|||||||
"@alicloud/openapi-client": "^0.4.5",
|
"@alicloud/openapi-client": "^0.4.5",
|
||||||
"@alicloud/tea-util": "^1.4.5",
|
"@alicloud/tea-util": "^1.4.5",
|
||||||
"@chakra-ui/icons": "^2.0.17",
|
"@chakra-ui/icons": "^2.0.17",
|
||||||
"@chakra-ui/react": "^2.7.0",
|
"@chakra-ui/react": "^2.5.1",
|
||||||
"@chakra-ui/system": "^2.5.8",
|
"@chakra-ui/system": "^2.5.5",
|
||||||
"@dqbd/tiktoken": "^1.0.6",
|
"@dqbd/tiktoken": "^1.0.6",
|
||||||
"@emotion/react": "^11.10.6",
|
"@emotion/react": "^11.10.6",
|
||||||
"@emotion/styled": "^11.10.6",
|
"@emotion/styled": "^11.10.6",
|
||||||
|
4
client/pnpm-lock.yaml
generated
4
client/pnpm-lock.yaml
generated
@@ -18,10 +18,10 @@ dependencies:
|
|||||||
specifier: ^2.0.17
|
specifier: ^2.0.17
|
||||||
version: registry.npmmirror.com/@chakra-ui/icons@2.0.17(@chakra-ui/system@2.5.8)(react@18.2.0)
|
version: registry.npmmirror.com/@chakra-ui/icons@2.0.17(@chakra-ui/system@2.5.8)(react@18.2.0)
|
||||||
'@chakra-ui/react':
|
'@chakra-ui/react':
|
||||||
specifier: ^2.7.0
|
specifier: ^2.5.1
|
||||||
version: registry.npmmirror.com/@chakra-ui/react@2.7.0(@emotion/react@11.10.6)(@emotion/styled@11.10.6)(@types/react@18.0.28)(framer-motion@9.0.6)(react-dom@18.2.0)(react@18.2.0)
|
version: registry.npmmirror.com/@chakra-ui/react@2.7.0(@emotion/react@11.10.6)(@emotion/styled@11.10.6)(@types/react@18.0.28)(framer-motion@9.0.6)(react-dom@18.2.0)(react@18.2.0)
|
||||||
'@chakra-ui/system':
|
'@chakra-ui/system':
|
||||||
specifier: ^2.5.8
|
specifier: ^2.5.5
|
||||||
version: registry.npmmirror.com/@chakra-ui/system@2.5.8(@emotion/react@11.10.6)(@emotion/styled@11.10.6)(react@18.2.0)
|
version: registry.npmmirror.com/@chakra-ui/system@2.5.8(@emotion/react@11.10.6)(@emotion/styled@11.10.6)(react@18.2.0)
|
||||||
'@dqbd/tiktoken':
|
'@dqbd/tiktoken':
|
||||||
specifier: ^1.0.6
|
specifier: ^1.0.6
|
||||||
|
@@ -24,9 +24,10 @@ mermaidAPI.initialize({
|
|||||||
const MermaidBlock = ({ code }: { code: string }) => {
|
const MermaidBlock = ({ code }: { code: string }) => {
|
||||||
const dom = useRef<HTMLDivElement>(null);
|
const dom = useRef<HTMLDivElement>(null);
|
||||||
const [svg, setSvg] = useState('');
|
const [svg, setSvg] = useState('');
|
||||||
|
const [errorSvgCode, setErrorSvgCode] = useState('');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
try {
|
(async () => {
|
||||||
const punctuationMap: Record<string, string> = {
|
const punctuationMap: Record<string, string> = {
|
||||||
',': ',',
|
',': ',',
|
||||||
';': ';',
|
';': ';',
|
||||||
@@ -50,13 +51,14 @@ const MermaidBlock = ({ code }: { code: string }) => {
|
|||||||
/([,;。:!?“”‘’【】()《》、])/g,
|
/([,;。:!?“”‘’【】()《》、])/g,
|
||||||
(match) => punctuationMap[match]
|
(match) => punctuationMap[match]
|
||||||
);
|
);
|
||||||
|
try {
|
||||||
mermaidAPI.render(`mermaid-${Date.now()}`, formatCode, (svgCode: string) => {
|
const svgCode = await mermaidAPI.render(`mermaid-${Date.now()}`, formatCode);
|
||||||
setSvg(svgCode);
|
setSvg(svgCode);
|
||||||
});
|
} catch (error) {
|
||||||
} catch (error) {
|
setErrorSvgCode(formatCode);
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
|
})();
|
||||||
}, [code]);
|
}, [code]);
|
||||||
|
|
||||||
const onclickExport = useCallback(() => {
|
const onclickExport = useCallback(() => {
|
||||||
|
@@ -41,6 +41,7 @@ const PcSliderBar = ({
|
|||||||
chatId: string;
|
chatId: string;
|
||||||
};
|
};
|
||||||
const ContextMenuRef = useRef(null);
|
const ContextMenuRef = useRef(null);
|
||||||
|
const onclickContext = useRef(false);
|
||||||
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { isPc } = useGlobalStore();
|
const { isPc } = useGlobalStore();
|
||||||
@@ -68,10 +69,16 @@ const PcSliderBar = ({
|
|||||||
// close contextMenu
|
// close contextMenu
|
||||||
useOutsideClick({
|
useOutsideClick({
|
||||||
ref: ContextMenuRef,
|
ref: ContextMenuRef,
|
||||||
handler: () =>
|
handler: () => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setContextMenuData(undefined);
|
if (contextMenuData && !onclickContext.current) {
|
||||||
}, 10)
|
setContextMenuData(undefined);
|
||||||
|
}
|
||||||
|
}, 10);
|
||||||
|
setTimeout(() => {
|
||||||
|
onclickContext.current = false;
|
||||||
|
}, 10);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const onclickContextMenu = useCallback(
|
const onclickContextMenu = useCallback(
|
||||||
@@ -80,9 +87,10 @@ const PcSliderBar = ({
|
|||||||
|
|
||||||
if (!isPc) return;
|
if (!isPc) return;
|
||||||
|
|
||||||
|
onclickContext.current = true;
|
||||||
setContextMenuData({
|
setContextMenuData({
|
||||||
left: e.clientX + 15,
|
left: e.clientX,
|
||||||
top: e.clientY + 10,
|
top: e.clientY,
|
||||||
history
|
history
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@@ -43,35 +43,6 @@ const QuoteModal = ({
|
|||||||
isLoading
|
isLoading
|
||||||
} = useQuery(['getHistoryQuote'], () => getHistoryQuote({ historyId, chatId }));
|
} = useQuery(['getHistoryQuote'], () => getHistoryQuote({ historyId, chatId }));
|
||||||
|
|
||||||
/**
|
|
||||||
* click edit, get new kbDataItem
|
|
||||||
*/
|
|
||||||
const onclickEdit = useCallback(
|
|
||||||
async (item: QuoteItemType) => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
const data = (await getKbDataItemById(item.id)) as QuoteItemType;
|
|
||||||
|
|
||||||
if (!data) {
|
|
||||||
throw new Error('该数据已被删除');
|
|
||||||
}
|
|
||||||
|
|
||||||
setEditDataItem({
|
|
||||||
dataId: data.id,
|
|
||||||
q: data.q,
|
|
||||||
a: data.a
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
toast({
|
|
||||||
status: 'warning',
|
|
||||||
title: getErrText(err)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
setIsLoading(false);
|
|
||||||
},
|
|
||||||
[setIsLoading, toast]
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update kbData, update mongo status and reload quotes
|
* update kbData, update mongo status and reload quotes
|
||||||
*/
|
*/
|
||||||
@@ -98,6 +69,36 @@ const QuoteModal = ({
|
|||||||
[chatId, historyId, refetch, setIsLoading, toast]
|
[chatId, historyId, refetch, setIsLoading, toast]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* click edit, get new kbDataItem
|
||||||
|
*/
|
||||||
|
const onclickEdit = useCallback(
|
||||||
|
async (item: QuoteItemType) => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
const data = (await getKbDataItemById(item.id)) as QuoteItemType;
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
updateQuoteStatus(item.id, '已删除');
|
||||||
|
throw new Error('该数据已被删除');
|
||||||
|
}
|
||||||
|
|
||||||
|
setEditDataItem({
|
||||||
|
dataId: data.id,
|
||||||
|
q: data.q,
|
||||||
|
a: data.a
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
toast({
|
||||||
|
status: 'warning',
|
||||||
|
title: getErrText(err)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
setIsLoading(false);
|
||||||
|
},
|
||||||
|
[setIsLoading, toast, updateQuoteStatus]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Modal isOpen={true} onClose={onClose}>
|
<Modal isOpen={true} onClose={onClose}>
|
||||||
|
@@ -39,6 +39,7 @@ const PcSliderBar = ({
|
|||||||
const { isPc } = useGlobalStore();
|
const { isPc } = useGlobalStore();
|
||||||
|
|
||||||
const ContextMenuRef = useRef(null);
|
const ContextMenuRef = useRef(null);
|
||||||
|
const onclickContext = useRef(false);
|
||||||
|
|
||||||
const [contextMenuData, setContextMenuData] = useState<{
|
const [contextMenuData, setContextMenuData] = useState<{
|
||||||
left: number;
|
left: number;
|
||||||
@@ -51,10 +52,16 @@ const PcSliderBar = ({
|
|||||||
// close contextMenu
|
// close contextMenu
|
||||||
useOutsideClick({
|
useOutsideClick({
|
||||||
ref: ContextMenuRef,
|
ref: ContextMenuRef,
|
||||||
handler: () =>
|
handler: () => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setContextMenuData(undefined);
|
if (contextMenuData && !onclickContext.current) {
|
||||||
})
|
setContextMenuData(undefined);
|
||||||
|
}
|
||||||
|
}, 10);
|
||||||
|
setTimeout(() => {
|
||||||
|
onclickContext.current = false;
|
||||||
|
}, 10);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const onclickContextMenu = useCallback(
|
const onclickContextMenu = useCallback(
|
||||||
@@ -62,10 +69,11 @@ const PcSliderBar = ({
|
|||||||
e.preventDefault(); // 阻止默认右键菜单
|
e.preventDefault(); // 阻止默认右键菜单
|
||||||
|
|
||||||
if (!isPc) return;
|
if (!isPc) return;
|
||||||
|
onclickContext.current = true;
|
||||||
|
|
||||||
setContextMenuData({
|
setContextMenuData({
|
||||||
left: e.clientX + 15,
|
left: e.clientX,
|
||||||
top: e.clientY + 10,
|
top: e.clientY,
|
||||||
history
|
history
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@@ -78,7 +78,6 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
|
|||||||
const [showHistoryQuote, setShowHistoryQuote] = useState<string>();
|
const [showHistoryQuote, setShowHistoryQuote] = useState<string>();
|
||||||
const [showSystemPrompt, setShowSystemPrompt] = useState('');
|
const [showSystemPrompt, setShowSystemPrompt] = useState('');
|
||||||
const [messageContextMenuData, setMessageContextMenuData] = useState<{
|
const [messageContextMenuData, setMessageContextMenuData] = useState<{
|
||||||
// message messageContextMenuData
|
|
||||||
left: number;
|
left: number;
|
||||||
top: number;
|
top: number;
|
||||||
message: ChatSiteItemType;
|
message: ChatSiteItemType;
|
||||||
|
@@ -235,7 +235,7 @@ const Chat = ({ shareId, historyId }: { shareId: string; historyId: string }) =>
|
|||||||
{
|
{
|
||||||
type: 'shareChatFinish',
|
type: 'shareChatFinish',
|
||||||
data: {
|
data: {
|
||||||
question: formatPrompts[0].value,
|
question: formatPrompts[formatPrompts.length - 2].value,
|
||||||
answer: responseText
|
answer: responseText
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@@ -158,8 +158,7 @@ const Test = () => {
|
|||||||
'repeat(1,1fr)',
|
'repeat(1,1fr)',
|
||||||
'repeat(1,1fr)',
|
'repeat(1,1fr)',
|
||||||
'repeat(1,1fr)',
|
'repeat(1,1fr)',
|
||||||
'repeat(2,1fr)',
|
'repeat(2,1fr)'
|
||||||
'repeat(3,1fr)'
|
|
||||||
]}
|
]}
|
||||||
gridGap={4}
|
gridGap={4}
|
||||||
>
|
>
|
||||||
|
Reference in New Issue
Block a user