From ebbb784f2152d65cabaa8ed0d4c0b2ee74229189 Mon Sep 17 00:00:00 2001 From: shixiaohua Date: Wed, 27 Mar 2024 08:46:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=90=9C=E7=B4=A2=E5=90=8E=E5=B1=95?= =?UTF-8?q?=E5=BC=80=E6=89=80=E5=9C=A8=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ItemTree/index.jsx | 42 ++----------------- .../plugins/ContextMenuPlugin/index.jsx | 4 +- .../Note/Hlexical/plugins/SaveFilePlugin.js | 18 ++++---- .../Note/Hlexical/plugins/ToolbarPlugin.js | 5 ++- 4 files changed, 18 insertions(+), 51 deletions(-) diff --git a/src/components/ItemTree/index.jsx b/src/components/ItemTree/index.jsx index afe6f9b..e8c2074 100644 --- a/src/components/ItemTree/index.jsx +++ b/src/components/ItemTree/index.jsx @@ -17,7 +17,6 @@ import DirDeleteFile from "./DirDeleteFile"; import DirAddDir from "./DirAddDir"; import {createPortal} from "react-dom"; import {isArray} from "@craco/craco/lib/utils"; -// const defaultData = []; // 将树平铺用于查找 const dataList = []; const generateList = (data) => { @@ -26,7 +25,7 @@ const generateList = (data) => { const {key, title, icon} = node; dataList.push({ key, - title, + "title":title.props.children, icon }); if (node.children) { @@ -34,7 +33,7 @@ const generateList = (data) => { } } }; -// generateList(defaultData); + const getParentKey = (key, tree) => { let parentKey; for (let i = 0; i < tree.length; i++) { @@ -50,12 +49,6 @@ const getParentKey = (key, tree) => { return parentKey; }; -const menuItemClickMap = new Map(); -menuItemClickMap.set('1', ); -menuItemClickMap.set('b', 2); -menuItemClickMap.set('c', 3); - - function generateChildList(fileList) { const result = [] for (let i = 0; i < fileList.length; i++) { @@ -170,6 +163,7 @@ const ItemTree = (prop) => { const [autoExpandParent, setAutoExpandParent] = useState(false); // let filePath = useSelector(state => state.dirMessage.data); const [defaultValueState, setDefaultValueState] = useState(flushTree(prop.filePath)); + generateList(defaultValueState); const [state, setState] = useState(); useEffect(() => { setDefaultValueState(flushTree(prop.filePath)) @@ -190,36 +184,6 @@ const ItemTree = (prop) => { } }) } - const itemTreeAddFile = (dirMessage)=>{ - setDefaultValueState(flushTree(dirMessage)) - // return - // let newFile = { - // "fileName": getFileFullNameByPath(filePath), - // "filePath": filePath, - // "dirFlag": false, - // "children": [] - // } - // // 查找对应的目录并添加信息 - // let fileDir = getFileDirByPath(filePath) - // let updateValueState = [...prop.filePath] - // updateValueState.forEach(file=>{ - // if (fileDir===file.filePath && file.dirFlag){ - // file.children=[...file.children,newFile] - // } else if (fileDir.startsWith(file.filePath) && file.dirFlag ){ - // treeItemChildAddFile(file.children,newFile,fileDir) - // } - // }) - // setDefaultValueState(flushTree(updateValueState)) - } - function treeItemChildAddFile(treeItemList,newFile,fileDir){ - treeItemList.forEach(file=>{ - if (fileDir===file.filePath && file.dirFlag){ - file.children=[...file.children,newFile] - } else if (fileDir.startsWith(file.filePath) && file.dirFlag){ - treeItemChildAddFile(file.children,newFile,fileDir) - } - }) - } const onChange = (e) => { const {value} = e.target; diff --git a/src/pages/Note/Hlexical/plugins/ContextMenuPlugin/index.jsx b/src/pages/Note/Hlexical/plugins/ContextMenuPlugin/index.jsx index 6e1bbdf..f011854 100644 --- a/src/pages/Note/Hlexical/plugins/ContextMenuPlugin/index.jsx +++ b/src/pages/Note/Hlexical/plugins/ContextMenuPlugin/index.jsx @@ -100,7 +100,7 @@ export default function ContextMenuPlugin(){ const items = await navigator.clipboard.read(); const item = items[0]; - + console.log("navigator.clipboard.read:item",item) const permission = await navigator.permissions.query({ // @ts-expect-error These types are incorrect. name: 'clipboard-read', @@ -109,7 +109,7 @@ export default function ContextMenuPlugin(){ alert('Not allowed to paste from clipboard.'); return; } - + // 图片 image/png for (const type of item.types) { const dataString = await (await item.getType(type)).text(); data.setData(type, dataString); diff --git a/src/pages/Note/Hlexical/plugins/SaveFilePlugin.js b/src/pages/Note/Hlexical/plugins/SaveFilePlugin.js index 50bf57b..ed46947 100644 --- a/src/pages/Note/Hlexical/plugins/SaveFilePlugin.js +++ b/src/pages/Note/Hlexical/plugins/SaveFilePlugin.js @@ -86,16 +86,18 @@ const SaveFilePlugin=(props)=> { // 后期不再读取文件,直接读取文件MD5 importFile(filePath).then(value => { - let save + let save =true; let oldFileMd5 let newFileMd5 =md5(resultSave) - if (props.filePath.endsWith(".md")){ - // editorState - oldFileMd5 = md5(value.toString()); - save = (isEmpty(value)) || newFileMd5 !== oldFileMd5; - }else { - oldFileMd5 = md5(JSON.stringify(JSON.parse(value.toString()))); - save = (isEmpty(value)) || newFileMd5 !== oldFileMd5; + if (!value){ + if (props.filePath.endsWith(".md")){ + // editorState + oldFileMd5 = md5(value.toString()); + save = (isEmpty(value)) || newFileMd5 !== oldFileMd5; + }else { + oldFileMd5 = md5(JSON.stringify(JSON.parse(value.toString()))); + save = (isEmpty(value)) || newFileMd5 !== oldFileMd5; + } } if (save) { overWriteFile(filePath, resultSave).then(()=>{ diff --git a/src/pages/Note/Hlexical/plugins/ToolbarPlugin.js b/src/pages/Note/Hlexical/plugins/ToolbarPlugin.js index dafd9f4..1ce529f 100644 --- a/src/pages/Note/Hlexical/plugins/ToolbarPlugin.js +++ b/src/pages/Note/Hlexical/plugins/ToolbarPlugin.js @@ -375,6 +375,7 @@ function BlockOptionsDropdownList({ }; const formatCode = () => { + console.log('blockType !== "code"',blockType) if (blockType !== "code") { editor.update(() => { const selection = $getSelection(); @@ -528,7 +529,7 @@ export default function ToolbarPlugin() { ); }, [editor, updateToolbar]); - const codeLanguges = useMemo(() => getCodeLanguages(), []); + const codeLanguages = useMemo(() => getCodeLanguages(), []); const onCodeLanguageSelect = useCallback( (e) => { editor.update(() => { @@ -605,7 +606,7 @@ export default function ToolbarPlugin() {