From 69d16937706d5e07f2eda756dc9b298b400814a6 Mon Sep 17 00:00:00 2001 From: Rain120 <1085131904@qq.com> Date: Fri, 31 Oct 2025 16:01:10 +0800 Subject: [PATCH 01/10] feat: mermaid actions --- .../x-markdown/src/plugins/Mermaid/index.tsx | 100 ++++++++++++------ 1 file changed, 65 insertions(+), 35 deletions(-) diff --git a/packages/x-markdown/src/plugins/Mermaid/index.tsx b/packages/x-markdown/src/plugins/Mermaid/index.tsx index bb1639b9d..b5b8e0149 100644 --- a/packages/x-markdown/src/plugins/Mermaid/index.tsx +++ b/packages/x-markdown/src/plugins/Mermaid/index.tsx @@ -1,9 +1,17 @@ -import { CopyOutlined, DownloadOutlined, ZoomInOutlined, ZoomOutOutlined } from '@ant-design/icons'; +import { + CopyOutlined, + DownloadOutlined, + UndoOutlined, + ZoomInOutlined, + ZoomOutOutlined, +} from '@ant-design/icons'; import useXComponentConfig from '@ant-design/x/es/_util/hooks/use-x-component-config'; +import Actions from '@ant-design/x/es/actions'; +import type { ActionsProps } from '@ant-design/x/es/actions/interface'; import useLocale from '@ant-design/x/es/locale/useLocale'; import useXProviderContext from '@ant-design/x/es/x-provider/hooks/use-x-provider-context'; import locale_EN from '@ant-design/x/locale/en_US'; -import { Button, message, Segmented, Space, Tooltip } from 'antd'; +import { message, Segmented } from 'antd'; import classnames from 'classnames'; import throttle from 'lodash.throttle'; import mermaid from 'mermaid'; @@ -222,6 +230,60 @@ const Mermaid: React.FC = React.memo((props) => { } }; + const onClick: ActionsProps['onClick'] = ({ keyPath }) => { + switch (keyPath[0]) { + case 'copy': + handleCopyCode(); + break; + case 'zoomOut': + handleZoomOut(); + break; + case 'zoomIn': + handleZoomIn(); + break; + case 'zoomReset': + handleReset(); + break; + case 'download': + handleDownload(); + break; + default: + break; + } + }; + + const actionItems = [ + { + key: 'copy', + label: contextLocale.copy, + icon: , + }, + { + key: 'zoomOut', + label: contextLocale.zoomOut, + icon: , + }, + { + key: 'zoomIn', + label: contextLocale.zoomOut, + icon: , + }, + { + key: 'zoomReset', + label: contextLocale.zoomReset, + icon: , + }, + { + key: 'download', + label: contextLocale.download, + icon: , + }, + ]; + + const activeActions = actionItems.filter( + (item) => item.key === 'copy' || renderType === RenderType.Image, + ); + const renderHeader = () => { if (header === null) return null; if (header) return header; @@ -244,39 +306,7 @@ const Mermaid: React.FC = React.memo((props) => { value={renderType} onChange={setRenderType} /> - - - - - -