import React from 'react'; import { ICommand, IMarkdownEditor, ToolBarProps } from '@uiw/react-markdown-editor'; import toast from 'react-hot-toast'; import styled from 'styled-components'; const Button = styled.button` white-space: nowrap; width: initial !important; display: flex; align-items: center; padding: 0 0.4rem !important; `; const CopyView: React.FC<{ command: ICommand; editorProps: IMarkdownEditor & ToolBarProps }> = (props) => { const { editorProps } = props; const handleClick = () => { const dom = editorProps.preview.current; dom?.focus(); window.getSelection()?.removeAllRanges(); let range = document.createRange(); range.setStartBefore(dom?.firstChild!); range.setEndAfter(dom?.lastChild!); window.getSelection()?.addRange(range); document.execCommand(`copy`); window.getSelection()?.removeAllRanges(); toast.success(
复制成功!去公众号编辑器复制吧!
); }; return ( ); }; export const copy: ICommand = { name: 'copy', keyCommand: 'copy', button: (command, props, opts) => , icon: ( ), };