fix: mermaid图表代码一键复制功能 #460
This commit is contained in:
parent
daf2e035b2
commit
88cd4f2144
@ -244,7 +244,8 @@
|
|||||||
"upgrade.success.button": "Restart",
|
"upgrade.success.button": "Restart",
|
||||||
"upgrade.success.content": "Please restart the application to complete the upgrade",
|
"upgrade.success.content": "Please restart the application to complete the upgrade",
|
||||||
"upgrade.success.title": "Upgrade successfully",
|
"upgrade.success.title": "Upgrade successfully",
|
||||||
"regenerate.confirm": "Regenerating will replace current message"
|
"regenerate.confirm": "Regenerating will replace current message",
|
||||||
|
"copy.success": "Copied!"
|
||||||
},
|
},
|
||||||
"minapp": {
|
"minapp": {
|
||||||
"title": "MinApp"
|
"title": "MinApp"
|
||||||
|
|||||||
@ -244,7 +244,8 @@
|
|||||||
"upgrade.success.button": "Перезапустить",
|
"upgrade.success.button": "Перезапустить",
|
||||||
"upgrade.success.content": "Пожалуйста, перезапустите приложение для завершения обновления",
|
"upgrade.success.content": "Пожалуйста, перезапустите приложение для завершения обновления",
|
||||||
"upgrade.success.title": "Обновление успешно",
|
"upgrade.success.title": "Обновление успешно",
|
||||||
"regenerate.confirm": "Перегенерация заменит текущее сообщение"
|
"regenerate.confirm": "Перегенерация заменит текущее сообщение",
|
||||||
|
"copy.success": "Скопировано!"
|
||||||
},
|
},
|
||||||
"minapp": {
|
"minapp": {
|
||||||
"title": "Встроенные приложения"
|
"title": "Встроенные приложения"
|
||||||
|
|||||||
@ -244,7 +244,8 @@
|
|||||||
"upgrade.success.button": "重启",
|
"upgrade.success.button": "重启",
|
||||||
"upgrade.success.content": "重启用以完成升级",
|
"upgrade.success.content": "重启用以完成升级",
|
||||||
"upgrade.success.title": "升级成功",
|
"upgrade.success.title": "升级成功",
|
||||||
"regenerate.confirm": "重新生成会覆盖当前消息"
|
"regenerate.confirm": "重新生成会覆盖当前消息",
|
||||||
|
"copy.success": "复制成功"
|
||||||
},
|
},
|
||||||
"minapp": {
|
"minapp": {
|
||||||
"title": "小程序"
|
"title": "小程序"
|
||||||
|
|||||||
@ -244,7 +244,8 @@
|
|||||||
"upgrade.success.button": "重新啟動",
|
"upgrade.success.button": "重新啟動",
|
||||||
"upgrade.success.content": "請重新啟動應用以完成升級",
|
"upgrade.success.content": "請重新啟動應用以完成升級",
|
||||||
"upgrade.success.title": "升級成功",
|
"upgrade.success.title": "升級成功",
|
||||||
"regenerate.confirm": "重新生成會覆蓋當前訊息"
|
"regenerate.confirm": "重新生成會覆蓋當前訊息",
|
||||||
|
"copy.success": "複製成功"
|
||||||
},
|
},
|
||||||
"minapp": {
|
"minapp": {
|
||||||
"title": "小程序"
|
"title": "小程序"
|
||||||
|
|||||||
@ -17,6 +17,7 @@ const PopupContainer: React.FC<Props> = ({ resolve, chart }) => {
|
|||||||
const [open, setOpen] = useState(true)
|
const [open, setOpen] = useState(true)
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const mermaidId = `mermaid-popup-${Date.now()}`
|
const mermaidId = `mermaid-popup-${Date.now()}`
|
||||||
|
const [activeTab, setActiveTab] = useState('preview')
|
||||||
|
|
||||||
const onOk = () => {
|
const onOk = () => {
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
@ -86,6 +87,11 @@ const PopupContainer: React.FC<Props> = ({ resolve, chart }) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleCopy = () => {
|
||||||
|
navigator.clipboard.writeText(chart)
|
||||||
|
window.message.success(t('message.copy.success'))
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
window?.mermaid?.contentLoaded()
|
window?.mermaid?.contentLoaded()
|
||||||
}, [])
|
}, [])
|
||||||
@ -101,11 +107,18 @@ const PopupContainer: React.FC<Props> = ({ resolve, chart }) => {
|
|||||||
centered
|
centered
|
||||||
footer={[
|
footer={[
|
||||||
<Space key="download-buttons">
|
<Space key="download-buttons">
|
||||||
<Button onClick={() => handleDownload('svg')}>{t('mermaid.download.svg')}</Button>
|
{activeTab === 'source' && <Button onClick={() => handleCopy()}>{t('common.copy')}</Button>}
|
||||||
<Button onClick={() => handleDownload('png')}>{t('mermaid.download.png')}</Button>
|
{activeTab === 'preview' && (
|
||||||
|
<>
|
||||||
|
<Button onClick={() => handleDownload('svg')}>{t('mermaid.download.svg')}</Button>
|
||||||
|
<Button onClick={() => handleDownload('png')}>{t('mermaid.download.png')}</Button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Space>
|
</Space>
|
||||||
]}>
|
]}>
|
||||||
<Tabs
|
<Tabs
|
||||||
|
activeKey={activeTab}
|
||||||
|
onChange={(key) => setActiveTab(key)}
|
||||||
items={[
|
items={[
|
||||||
{
|
{
|
||||||
key: 'preview',
|
key: 'preview',
|
||||||
|
|||||||
@ -51,7 +51,7 @@ const initialState: SettingsState = {
|
|||||||
proxyMode: 'system',
|
proxyMode: 'system',
|
||||||
proxyUrl: undefined,
|
proxyUrl: undefined,
|
||||||
userName: '',
|
userName: '',
|
||||||
showMessageDivider: false,
|
showMessageDivider: true,
|
||||||
messageFont: 'system',
|
messageFont: 'system',
|
||||||
showInputEstimatedTokens: false,
|
showInputEstimatedTokens: false,
|
||||||
tray: true,
|
tray: true,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user