-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1d3a6e
commit eedf6f1
Showing
6 changed files
with
170 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { useEffect, useState } from "react"; | ||
import { useRecoilState } from "recoil"; | ||
import { isExportTreeTextPanelOpenAtom } from "../state"; | ||
import { cn } from "../utils/cn"; | ||
import { StageSaveManager } from "../core/stage/StageSaveManager"; | ||
import { StageManager } from "../core/stage/stageManager/StageManager"; | ||
import { TextNode } from "../core/stageObject/entity/TextNode"; | ||
|
||
/** | ||
* 导出节点纯文本相关的面板 | ||
* 树形的 | ||
*/ | ||
export default function ExportTreeTextPanel() { | ||
const [isExportTreeTextPanelOpen, setIsExportTreeTextPanelOpen] = | ||
useRecoilState(isExportTreeTextPanelOpenAtom); | ||
|
||
const [markdownText, setMarkdownText] = useState(""); | ||
const [tabText, setTabText] = useState(""); | ||
|
||
useEffect(() => { | ||
if (!isExportTreeTextPanelOpen) { | ||
return; | ||
} | ||
// 当前选择的节点通常来说是一个节点,且在上游已经确定了是树形结构 | ||
const selectedNode = StageManager.getSelectedEntities()[0]; | ||
if (!(selectedNode instanceof TextNode)) { | ||
return; | ||
} | ||
|
||
setMarkdownText(StageSaveManager.getMarkdownStringByTextNode(selectedNode)); | ||
setTabText(StageSaveManager.getTabStringByTextNode(selectedNode)); | ||
}, [isExportTreeTextPanelOpen]); | ||
|
||
return ( | ||
<div | ||
className={cn( | ||
"fixed left-1/2 top-1/2 z-10 flex h-4/5 w-3/4 -translate-x-1/2 -translate-y-1/2 transform flex-col items-center overflow-y-scroll rounded-md bg-gray-800 px-2 py-6", | ||
{ | ||
hidden: !isExportTreeTextPanelOpen, | ||
}, | ||
)} | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
}} | ||
> | ||
<h2 className="text-lg font-bold">导出节点纯文本</h2> | ||
<div className="flex gap-2"> | ||
<CodePre text={tabText} title="纯缩进类型" /> | ||
<CodePre text={markdownText} title="markdown类型" /> | ||
</div> | ||
<button | ||
className="absolute right-0 top-0 rounded bg-red-500 px-4 py-2 font-bold text-white hover:bg-red-700" | ||
onClick={() => setIsExportTreeTextPanelOpen(false)} | ||
> | ||
关闭 | ||
</button> | ||
</div> | ||
); | ||
} | ||
|
||
function CodePre({ text, title }: { text: string; title: string }) { | ||
return ( | ||
<div> | ||
<h4 className="text-sm font-bold">{title}</h4> | ||
<pre className="select-text rounded-md bg-black p-2 text-xs text-slate-400"> | ||
{text} | ||
</pre> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters