| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- 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 (
- <Tabs
- className={
- "sent_tabs" +
- (isCompact ? " compact" : "") +
- (currKey === "close" ? " curr_close" : "")
- }
- onMouseEnter={() => setHover(true)}
- onMouseLeave={() => setHover(false)}
- activeKey={currKey}
- type="card"
- onChange={(activeKey: string) => {
- setCurrKey(activeKey);
- }}
- tabBarStyle={{ marginBottom: 0 }}
- size="small"
- tabBarGutter={0}
- tabBarExtraContent={
- <Space>
- <TocPath
- link="none"
- data={mPath}
- channels={channelsId}
- trigger={path ? path.length > 0 ? path[0].title : <></> : <></>}
- />
- <Text>{sentId[0]}</Text>
- <SentTabCopy wbwData={wbwData} text={`{{${sentId[0]}}}`} />
- <SentMenu
- book={book}
- para={para}
- loading={magicDictLoading}
- mode={mode}
- onMagicDict={(type: string) => {
- 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;
- }
- }}
- />
- </Space>
- }
- items={[
- {
- label: (
- <span style={tabButtonStyle}>
- <Badge size="small" count={0}>
- <CloseOutlined />
- </Badge>
- </span>
- ),
- key: "close",
- children: <></>,
- },
- {
- label: (
- <SentTabButton
- style={tabButtonStyle}
- icon={<TranslationOutlined />}
- type="translation"
- sentId={id}
- count={
- currTranNum
- ? currTranNum -
- (loadedRes?.translation ? loadedRes.translation : 0)
- : undefined
- }
- title={intl.formatMessage({
- id: "channel.type.translation.label",
- })}
- />
- ),
- key: "translation",
- children: (
- <div className="content">
- <SentCanRead
- book={parseInt(sId[0])}
- para={parseInt(sId[1])}
- wordStart={parseInt(sId[2])}
- wordEnd={parseInt(sId[3])}
- type="translation"
- channelsId={channelsId}
- onCreate={() => setCurrTranNum((origin) => origin + 1)}
- />
- </div>
- ),
- },
- {
- label: (
- <SentTabButton
- style={tabButtonStyle}
- icon={<CloseOutlined />}
- type="nissaya"
- sentId={id}
- count={
- currNissayaNum
- ? currNissayaNum -
- (loadedRes?.nissaya ? loadedRes.nissaya : 0)
- : undefined
- }
- title={intl.formatMessage({
- id: "channel.type.nissaya.label",
- })}
- />
- ),
- key: "nissaya",
- children: (
- <SentCanRead
- book={parseInt(sId[0])}
- para={parseInt(sId[1])}
- wordStart={parseInt(sId[2])}
- wordEnd={parseInt(sId[3])}
- type="nissaya"
- channelsId={channelsId}
- onCreate={() => setCurrNissayaNum((origin) => origin + 1)}
- />
- ),
- },
- {
- label: (
- <SentTabButton
- style={tabButtonStyle}
- icon={<TranslationOutlined />}
- type="commentary"
- sentId={id}
- count={
- currCommNum
- ? currCommNum -
- (loadedRes?.commentary ? loadedRes.commentary : 0)
- : undefined
- }
- title={intl.formatMessage({
- id: "channel.type.commentary.label",
- })}
- />
- ),
- key: "commentary",
- children: (
- <SentCanRead
- book={parseInt(sId[0])}
- para={parseInt(sId[1])}
- wordStart={parseInt(sId[2])}
- wordEnd={parseInt(sId[3])}
- type="commentary"
- channelsId={channelsId}
- onCreate={() => setCurrCommNum((origin) => origin + 1)}
- />
- ),
- },
- {
- label: (
- <SentTabButton
- icon={<BlockOutlined />}
- type="original"
- sentId={id}
- count={originNum}
- title={intl.formatMessage({
- id: "channel.type.original.label",
- })}
- />
- ),
- key: "original",
- children: (
- <SentCanRead
- book={parseInt(sId[0])}
- para={parseInt(sId[1])}
- wordStart={parseInt(sId[2])}
- wordEnd={parseInt(sId[3])}
- type="original"
- origin={origin}
- />
- ),
- },
- {
- label: (
- <SentTabButton
- style={tabButtonStyle}
- icon={<BlockOutlined />}
- type="original"
- sentId={id}
- count={currSimilarNum}
- title={intl.formatMessage({
- id: "buttons.sim",
- })}
- />
- ),
- key: "sim",
- children: (
- <SentSim
- book={parseInt(sId[0])}
- para={parseInt(sId[1])}
- wordStart={parseInt(sId[2])}
- wordEnd={parseInt(sId[3])}
- channelsId={channelsId}
- limit={5}
- onCreate={() => setCurrSimilarNum((origin) => origin + 1)}
- />
- ),
- },
- {
- label: (
- <SentTabButtonWbw
- style={tabButtonStyle}
- sentId={id}
- count={0}
- onMenuClick={(keyPath: string[]) => {
- switch (keyPath.join("-")) {
- case "show-progress":
- setShowWbwProgress((origin) => !origin);
- break;
- }
- }}
- />
- ),
- key: "wbw",
- children: (
- <SentWbw
- book={parseInt(sId[0])}
- para={parseInt(sId[1])}
- wordStart={parseInt(sId[2])}
- wordEnd={parseInt(sId[3])}
- channelsId={channelsId}
- wbwProgress={showWbwProgress}
- />
- ),
- },
- {
- label: <span style={tabButtonStyle}>{"关系图"}</span>,
- key: "relation-graphic",
- children: <RelaGraphic wbwData={wbwData} />,
- },
- ]}
- />
- );
- };
- export default SentTabWidget;
|