feat:内容加载Spin

This commit is contained in:
shixiaohua 2024-03-05 09:49:03 +08:00
parent 337b0bda48
commit bbcd633d02
3 changed files with 21 additions and 8 deletions

View File

@ -33,6 +33,8 @@ import TableCellActionMenuPlugin from './plugins/TableActionMenuPlugin';
import ExcalidrawPlugin from "./plugins/ExcalidrawPlugin"; import ExcalidrawPlugin from "./plugins/ExcalidrawPlugin";
import TableOfContentsPlugin from "./plugins/TableOfContentsPlugin"; import TableOfContentsPlugin from "./plugins/TableOfContentsPlugin";
import ContextMenuPlugin from "./plugins/ContextMenuPlugin" import ContextMenuPlugin from "./plugins/ContextMenuPlugin"
import {Spin} from "antd";
import {useState} from "react";
function Placeholder() { function Placeholder() {
return <div className="editor-placeholder">Enter some rich text...</div>; return <div className="editor-placeholder">Enter some rich text...</div>;
} }
@ -45,28 +47,35 @@ export default function Hlexical(props) {
}, },
nodes: UsefulNodes nodes: UsefulNodes
}; };
const [spinningState,setSpinningState]=useState(true)
console.log("Hlexical(props):this.props.filePath:", props.filePath) console.log("Hlexical(props):this.props.filePath:", props.filePath)
if (!isEmpty(props.filePath)&&props.filePath.endsWith(".md")){ if (!isEmpty(props.filePath)&&props.filePath.endsWith(".md")){
importFile(props.filePath).then(value => {
let promise = importFile(props.filePath);
promise.then(value => {
if (isEmpty(value)) { if (isEmpty(value)) {
return return
} }
editorConfig={...editorConfig,editorState: () => $convertFromMarkdownString(value.toString(), TRANSFORMERS)} editorConfig={...editorConfig,editorState: () => $convertFromMarkdownString(value.toString(), TRANSFORMERS)}
setSpinningState(false)
}).catch(error => }).catch(error =>
console.error(error) console.error(error)
) )
} }
return ( return (
<LexicalComposer initialConfig={editorConfig}> <LexicalComposer initialConfig={editorConfig}>
<div className="editor-container"> <div className="editor-container">
{/* 富文本插件 */} {/* 富文本插件 */}
<ToolbarPlugin/> <ToolbarPlugin/>
<div className="editor-inner"> <div className="editor-inner">
<Spin size="large" fullscreen="ture" spinning={spinningState}>
<RichTextPlugin <RichTextPlugin
contentEditable={<ContentEditable className="editor-input"/>} contentEditable={<ContentEditable className="editor-input"/>}
placeholder={<Placeholder/>} placeholder={<Placeholder/>}
ErrorBoundary={LexicalErrorBoundary} ErrorBoundary={LexicalErrorBoundary}
/> /> </Spin>
<HistoryPlugin/> <HistoryPlugin/>
{/*黑窗口动态记录当前操作*/} {/*黑窗口动态记录当前操作*/}
{/*<TreeViewPlugin/>*/} {/*<TreeViewPlugin/>*/}
@ -83,7 +92,7 @@ export default function Hlexical(props) {
/> />
{/* 表格单元格操作 */} {/* 表格单元格操作 */}
<TableCellActionMenuPlugin/> <TableCellActionMenuPlugin/>
<TabIndentationPlugin /> <TabIndentationPlugin/>
{/*markdown 快捷键*/} {/*markdown 快捷键*/}
<MarkdownShortcutPlugin transformers={TRANSFORMERS}/> <MarkdownShortcutPlugin transformers={TRANSFORMERS}/>
{/*图片加载*/} {/*图片加载*/}
@ -91,22 +100,24 @@ export default function Hlexical(props) {
<InlineImagePlugin/> <InlineImagePlugin/>
{/*分割线 */} {/*分割线 */}
<HorizontalRulePlugin /> <HorizontalRulePlugin/>
{/*页分割线*/} {/*页分割线*/}
{/*目录加载*/} {/*目录加载*/}
<TableOfContentsPlugin filePath={props.filePath}/> <TableOfContentsPlugin filePath={props.filePath}/>
{/*右键菜单*/} {/*右键菜单*/}
<ContextMenuPlugin /> <ContextMenuPlugin/>
{/* 画图 */} {/* 画图 */}
<ExcalidrawPlugin /> <ExcalidrawPlugin/>
<ImportFilePlugin filePath={props.filePath}/> <ImportFilePlugin filePath={props.filePath} setSpinningState={setSpinningState}/>
<SaveFilePlugin filePath={props.filePath}/> <SaveFilePlugin filePath={props.filePath}/>
{/*文件操作导入文件*/} {/*文件操作导入文件*/}
{/*<ActionPlugin/>*/} {/*<ActionPlugin/>*/}
</div> </div>
</div> </div>
</LexicalComposer> </LexicalComposer>
); );
} }

View File

@ -28,6 +28,7 @@ export default function ImportFilePlugin(props) {
); );
editor.setEditorState(editorState); editor.setEditorState(editorState);
editor.dispatchCommand(CLEAR_HISTORY_COMMAND, undefined); editor.dispatchCommand(CLEAR_HISTORY_COMMAND, undefined);
props.setSpinningState(false)
} }
}).catch(error => }).catch(error =>
console.error(error) console.error(error)

View File

@ -17,6 +17,7 @@ export const tableBarItemSlice = createSlice({
activeKey:"", activeKey:"",
expandedKeyList:[], expandedKeyList:[],
leftTableOfContents:"" leftTableOfContents:""
// document.querySelectorAll("[data-node-key='/media/shixiaohua/homedisk/work/202402/note使用记录.lexical']")[0].setAttribute('style','background:black')
}, },
reducers: { reducers: {
addTableBarItem: (state, action) => { addTableBarItem: (state, action) => {