perf: 删除调试代码,合并 onChange 判断

2.0/email-builder
Jimmy Liow 11 months ago
parent 24a3fd878c
commit 42879ed09d

@ -87,38 +87,29 @@ function LexicalDefaultValuePlugin({ value = "" }= {}) {
const nodes = $generateNodesFromDOM(editor, dom);
if (clear) {
root.clear();
// $getRoot().clear();
// $getRoot().select();
}
// const p = $createParagraphNode();
// const _p =
nodes.filter(n => n.__size !== 0).forEach((n) => {
const paragraphNode = $createParagraphNode();
paragraphNode.append(n);
// p.append(paragraphNode);
root.append(paragraphNode);
});
// root.append(...nodes.filter(n => n));
};
//
// HTML
useEffect(() => {
if (editor && !isEmpty(value)) {
editor.update(() => {
updateHTML(editor, value, true);
});
}
}, [value]);
}, [editor, value]);
return null;
}
function MyOnChangePlugin({ ignoreHistoryMergeTagChange = true, ignoreSelectionChange = true, onChange }) {
const [editor] = useLexicalComposerContext();
useEffect(() => {
if (onChange) {
if (typeof onChange === 'function') {
return editor.registerUpdateListener(({editorState, dirtyElements, dirtyLeaves, prevEditorState, tags}) => {
if (
@ -130,21 +121,11 @@ function MyOnChangePlugin({ ignoreHistoryMergeTagChange = true, ignoreSelectionC
) {
return;
}
// const editorStateJSON = editorState.toJSON();
let html;
let textContent;
editorState.read(() => {
const root = $getRoot();
const textContent = root.getTextContent();
// console.log('textContent', textContent);
const html = $generateHtmlFromNodes(editor);
// console.log('html', html);
// setEditorContent(content);
if (typeof onChange === 'function') {
onChange({ editorStateJSON: editorState.toJSON(), editor, tags, htmlContent: html, textContent });
}
onChange({ editorStateJSON: editorState.toJSON(), editor, tags, htmlContent: html, textContent });
});
});
}

Loading…
Cancel
Save