import { useEffect, useState } from "react"; import { Badge, Space, Tabs, Typography, message } from "antd"; import { TranslationOutlined, CloseOutlined, BlockOutlined, } from "@ant-design/icons"; import SentTabButton from "./SentTabButton"; import SentCanRead from "./SentCanRead"; import SentSim from "./SentSim"; import { useIntl } from "react-intl"; import TocPath, { type ITocPathNode } from "../../corpus/TocPath"; import type { IWbw } from "../Wbw/WbwWord" import RelaGraphic from "../Wbw/RelaGraphic"; import SentMenu from "./SentMenu"; import type { ArticleMode } from "../../article/Article" import type { IResNumber, ISentence } from "../SentEdit" import SentTabCopy from "./SentTabCopy"; import { fullUrl } from "../../../utils"; import SentWbw from "./SentWbw"; import SentTabButtonWbw from "./SentTabButtonWbw"; const { Text } = Typography; interface IWidget { id: string; book: number; para: number; wordStart: number; wordEnd: number; channelsId?: string[]; path?: ITocPathNode[]; layout?: "row" | "column"; tranNum?: number; nissayaNum?: number; commNum?: number; originNum: number; simNum?: number; wbwData?: IWbw[]; magicDictLoading?: boolean; compact?: boolean; mode?: ArticleMode; loadedRes?: IResNumber; origin?: ISentence[]; onMagicDict?: Function; onCompact?: Function; onModeChange?: Function; onAffix?: Function; } const SentTabWidget = ({ id, book, para, wordStart, wordEnd, channelsId, path, tranNum = 0, nissayaNum = 0, commNum = 0, originNum, simNum = 0, wbwData, magicDictLoading = false, compact = false, mode, loadedRes, origin, onMagicDict, onCompact, onModeChange, onAffix, }: IWidget) => { const intl = useIntl(); const [isCompact, setIsCompact] = useState(compact); const [hover, setHover] = useState(false); const [currKey, setCurrKey] = useState("close"); const [currTranNum, setCurrTranNum] = useState(tranNum); const [currNissayaNum, setCurrNissayaNum] = useState(nissayaNum); const [currCommNum, setCurrCommNum] = useState(commNum); const [currSimilarNum, setCurrSimilarNum] = useState(simNum); const [showWbwProgress, setShowWbwProgress] = useState(false); console.log("SentTabWidget render"); useEffect(() => setIsCompact(compact), [compact]); const mPath = path ? [ ...path, { book: book, paragraph: para, title: para.toString(), level: 100 }, ] : []; if (typeof id === "undefined") { return <>; } const sentId = id.split("_"); const sId = sentId[0].split("-"); const tabButtonStyle: React.CSSProperties | undefined = compact ? { visibility: hover || currKey !== "close" ? "visible" : "hidden" } : undefined; return ( setHover(true)} onMouseLeave={() => setHover(false)} activeKey={currKey} type="card" onChange={(activeKey: string) => { setCurrKey(activeKey); }} tabBarStyle={{ marginBottom: 0 }} size="small" tabBarGutter={0} tabBarExtraContent={ 0 ? path[0].title : <> : <>} /> {sentId[0]} { if (typeof onMagicDict !== "undefined") { onMagicDict(type); } }} onMenuClick={(key: string) => { switch (key) { case "compact": if (typeof onCompact !== "undefined") { setIsCompact(true); onCompact(true); } break; case "normal": if (typeof onCompact !== "undefined") { setIsCompact(false); onCompact(false); } break; case "origin-edit": if (typeof onModeChange !== "undefined") { onModeChange("edit"); } break; case "origin-wbw": if (typeof onModeChange !== "undefined") { onModeChange("wbw"); } break; case "copy-id": const id = `{{${book}-${para}-${wordStart}-${wordEnd}}}`; navigator.clipboard.writeText(id).then(() => { message.success("编号已经拷贝到剪贴板"); }); break; case "copy-link": let link = `/article/para/${book}-${para}?mode=edit`; link += `&book=${book}&par=${para}`; if (channelsId) { link += `&channel=` + channelsId?.join("_"); } link += `&focus=${book}-${para}-${wordStart}-${wordEnd}`; navigator.clipboard.writeText(fullUrl(link)).then(() => { message.success("链接地址已经拷贝到剪贴板"); }); break; case "affix": if (typeof onAffix !== "undefined") { onAffix(); } break; default: break; } }} /> } items={[ { label: ( ), key: "close", children: <>, }, { label: ( } type="translation" sentId={id} count={ currTranNum ? currTranNum - (loadedRes?.translation ? loadedRes.translation : 0) : undefined } title={intl.formatMessage({ id: "channel.type.translation.label", })} /> ), key: "translation", children: (
setCurrTranNum((origin) => origin + 1)} />
), }, { label: ( } type="nissaya" sentId={id} count={ currNissayaNum ? currNissayaNum - (loadedRes?.nissaya ? loadedRes.nissaya : 0) : undefined } title={intl.formatMessage({ id: "channel.type.nissaya.label", })} /> ), key: "nissaya", children: ( setCurrNissayaNum((origin) => origin + 1)} /> ), }, { label: ( } type="commentary" sentId={id} count={ currCommNum ? currCommNum - (loadedRes?.commentary ? loadedRes.commentary : 0) : undefined } title={intl.formatMessage({ id: "channel.type.commentary.label", })} /> ), key: "commentary", children: ( setCurrCommNum((origin) => origin + 1)} /> ), }, { label: ( } type="original" sentId={id} count={originNum} title={intl.formatMessage({ id: "channel.type.original.label", })} /> ), key: "original", children: ( ), }, { label: ( } type="original" sentId={id} count={currSimilarNum} title={intl.formatMessage({ id: "buttons.sim", })} /> ), key: "sim", children: ( setCurrSimilarNum((origin) => origin + 1)} /> ), }, { label: ( { switch (keyPath.join("-")) { case "show-progress": setShowWbwProgress((origin) => !origin); break; } }} /> ), key: "wbw", children: ( ), }, { label: {"关系图"}, key: "relation-graphic", children: , }, ]} /> ); }; export default SentTabWidget;