import { Button, Dropdown, Tooltip, message } from "antd"; import { useState } from "react"; import { EditOutlined, CopyOutlined, MoreOutlined, FieldTimeOutlined, LinkOutlined, FileMarkdownOutlined, DeleteOutlined, ReloadOutlined, } from "@ant-design/icons"; import type { MenuProps } from "antd"; import type { ISentence } from "../SentEdit" import SentHistoryModal from "../../corpus/SentHistoryModal"; import { CommentOutlinedIcon, HandOutlinedIcon, JsonOutlinedIcon, MergeIcon2, PasteOutLinedIcon, } from "../../../assets/icon"; import { useIntl } from "react-intl"; import { fullUrl } from "../../../utils"; interface IWidget { data?: ISentence; children?: React.ReactNode; isPr?: boolean; onModeChange?: Function; onConvert?: Function; onMenuClick?: Function; } const SentEditMenuWidget = ({ data, children, isPr = false, onModeChange, onConvert, onMenuClick, }: IWidget) => { const [isHover, setIsHover] = useState(false); const [timelineOpen, setTimelineOpen] = useState(false); const intl = useIntl(); const onClick: MenuProps["onClick"] = (e) => { if (typeof onMenuClick !== "undefined") { onMenuClick(e.key); } switch (e.key) { case "json": if (typeof onConvert !== "undefined") { onConvert("json"); } break; case "markdown": if (typeof onConvert !== "undefined") { onConvert("markdown"); } break; case "timeline": setTimelineOpen(true); break; case "refresh": break; case "copy-link": if (data) { let link = `/article/para/${data.book}-${data.para}?mode=edit`; link += `&book=${data.book}&par=${data.para}`; link += `&channel=${data.channel.id}`; link += `&focus=${data.book}-${data.para}-${data.wordStart}-${data.wordEnd}`; navigator.clipboard.writeText(fullUrl(link)).then(() => { message.success("链接地址已经拷贝到剪贴板"); }); } break; default: break; } }; const items: MenuProps["items"] = [ { key: "refresh", label: intl.formatMessage({ id: "buttons.refresh", }), icon: , }, { key: "timeline", label: intl.formatMessage({ id: "buttons.timeline", }), icon: , disabled: isPr, }, { key: "copy-to", label: intl.formatMessage({ id: "buttons.copy.to", }), icon: , disabled: isPr, }, { type: "divider", }, { key: "suggestion", label: "suggestion", icon: , disabled: isPr, }, { key: "discussion", label: "discussion", icon: , disabled: isPr, }, { type: "divider", }, { key: "markdown", label: "To Markdown", icon: , disabled: !data || data.contentType === "markdown" || isPr, }, { key: "json", label: "To Json", icon: , disabled: !data || data.channel.type !== "nissaya" || data.contentType === "json" || isPr, }, { type: "divider", }, { key: "copy-link", label: intl.formatMessage({ id: "buttons.copy.link", }), icon: , }, { key: "delete", label: intl.formatMessage({ id: "buttons.delete", }), icon: , danger: true, disabled: !isPr, }, ]; const buttonStyle = { backgroundColor: "rgba(1,1,1,0)", marginRight: 2 }; return (
{ setIsHover(true); }} onMouseLeave={() => { setIsHover(false); }} > setTimelineOpen(false)} sentId={data?.id} />
{children}
); }; export default SentEditMenuWidget;