|
|
|
@ -77,27 +77,31 @@ const editorConfig = {
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function LexicalDefaultValuePlugin({ value = "" }= {}) {
|
|
|
|
|
function LexicalDefaultValuePlugin({ value = '' }= {}) {
|
|
|
|
|
const [editor] = useLexicalComposerContext();
|
|
|
|
|
|
|
|
|
|
const updateHTML = (editor, value, clear) => {
|
|
|
|
|
const root = $getRoot();
|
|
|
|
|
const parser = new DOMParser();
|
|
|
|
|
const dom = parser.parseFromString(value, "text/html");
|
|
|
|
|
const nodes = $generateNodesFromDOM(editor, dom);
|
|
|
|
|
if (clear) {
|
|
|
|
|
root.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nodes.filter(n => n.__size !== 0).forEach((n) => {
|
|
|
|
|
const paragraphNode = $createParagraphNode();
|
|
|
|
|
paragraphNode.append(n);
|
|
|
|
|
root.append(paragraphNode);
|
|
|
|
|
});
|
|
|
|
|
if (isEmpty(value)) {
|
|
|
|
|
root.clear();
|
|
|
|
|
} else {
|
|
|
|
|
const parser = new DOMParser();
|
|
|
|
|
const dom = parser.parseFromString(value, "text/html");
|
|
|
|
|
const nodes = $generateNodesFromDOM(editor, dom);
|
|
|
|
|
nodes.filter(n => n.__size !== 0).forEach((n) => {
|
|
|
|
|
const paragraphNode = $createParagraphNode();
|
|
|
|
|
paragraphNode.append(n);
|
|
|
|
|
root.append(paragraphNode);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (editor && !isEmpty(value)) {
|
|
|
|
|
if (editor) {
|
|
|
|
|
editor.update(() => {
|
|
|
|
|
updateHTML(editor, value, true);
|
|
|
|
|
});
|
|
|
|
|