mirror of https://github.com/fantasticit/think.git
client: fix #issuecomment-1158885416
This commit is contained in:
parent
9a6c1c40e6
commit
53bfef34b4
|
@ -8,7 +8,7 @@ import { prosemirrorJSONToYDoc } from 'tiptap/core/thritypart/y-prosemirror/y-pr
|
||||||
import { markdownToProsemirror } from 'tiptap/markdown/markdown-to-prosemirror';
|
import { markdownToProsemirror } from 'tiptap/markdown/markdown-to-prosemirror';
|
||||||
import * as Y from 'yjs';
|
import * as Y from 'yjs';
|
||||||
|
|
||||||
export const ImportEditor = ({ content, onChange }) => {
|
export const ImportEditor = ({ content, onChange, onError }) => {
|
||||||
const parsed = useRef(false);
|
const parsed = useRef(false);
|
||||||
const ydoc = useMemo(() => new Y.Doc(), []);
|
const ydoc = useMemo(() => new Y.Doc(), []);
|
||||||
const editor = useEditor(
|
const editor = useEditor(
|
||||||
|
@ -39,14 +39,16 @@ export const ImportEditor = ({ content, onChange }) => {
|
||||||
|
|
||||||
parsed.current = true;
|
parsed.current = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Toast.error('文件内容解析失败,请到 Github 提 issue 寻求解决!');
|
onError();
|
||||||
|
console.error(e.message, e.stack);
|
||||||
|
Toast.error('文件内容解析失败,请打开控制台,截图错误信息,请到 Github 提 issue 寻求解决!');
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
ydoc.destroy();
|
ydoc.destroy();
|
||||||
editor.destroy();
|
editor.destroy();
|
||||||
};
|
};
|
||||||
}, [editor, ydoc, content, onChange]);
|
}, [editor, ydoc, content, onChange, onError]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
|
@ -67,6 +67,18 @@ export const Import: React.FC<IProps> = ({ wikiId }) => {
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const onParsedFileError = useCallback((filename) => {
|
||||||
|
return () => {
|
||||||
|
setUploadFiles((files) => {
|
||||||
|
return files.filter((name) => name !== filename);
|
||||||
|
});
|
||||||
|
setTexts((texts) => {
|
||||||
|
delete texts[filename];
|
||||||
|
return texts;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
const onDeleteFile = useCallback((toDeleteFilename) => {
|
const onDeleteFile = useCallback((toDeleteFilename) => {
|
||||||
return () => {
|
return () => {
|
||||||
setPayloads((payloads) => {
|
setPayloads((payloads) => {
|
||||||
|
@ -112,7 +124,14 @@ export const Import: React.FC<IProps> = ({ wikiId }) => {
|
||||||
<input ref={$upload} type="file" hidden multiple accept="text/markdown" onChange={handleFile} />
|
<input ref={$upload} type="file" hidden multiple accept="text/markdown" onChange={handleFile} />
|
||||||
|
|
||||||
{uploadFiles.map((filename) => {
|
{uploadFiles.map((filename) => {
|
||||||
return <ImportEditor key={filename} content={texts[filename]} onChange={onParsedFile(filename)} />;
|
return (
|
||||||
|
<ImportEditor
|
||||||
|
key={filename}
|
||||||
|
content={texts[filename]}
|
||||||
|
onChange={onParsedFile(filename)}
|
||||||
|
onError={onParsedFileError(filename)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
})}
|
})}
|
||||||
|
|
||||||
<List
|
<List
|
||||||
|
|
|
@ -117,6 +117,5 @@ export const AllExtensions = [
|
||||||
Status,
|
Status,
|
||||||
DocumentWithTitle,
|
DocumentWithTitle,
|
||||||
Title,
|
Title,
|
||||||
Document,
|
|
||||||
Flow,
|
Flow,
|
||||||
];
|
];
|
||||||
|
|
|
@ -256,7 +256,7 @@ function table(state, startLine, endLine, silent) {
|
||||||
|
|
||||||
token = state.push('paragraph_open', 'p', 1);
|
token = state.push('paragraph_open', 'p', 1);
|
||||||
token = state.push('inline', '', 0);
|
token = state.push('inline', '', 0);
|
||||||
token.content = columns[i].trim();
|
token.content = (columns[i] || '').trim();
|
||||||
token.children = [];
|
token.children = [];
|
||||||
token = state.push('paragraph_close', 'p', -1);
|
token = state.push('paragraph_close', 'p', -1);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue