feat: 增加复制粘贴功能

This commit is contained in:
2021-10-06 20:03:52 +08:00
parent 2048a89d7e
commit 9d81aaa4fb
9 changed files with 143 additions and 51 deletions
+10 -2
View File
@@ -1,8 +1,10 @@
import { createNotation, notations as N } from "./notation";
import { toJS } from "mobx";
import { cloneNotation, createNotation, notations as N } from "./notation";
// 新建段落
function createParagraph(initial) {
const p = {
type: "paragraph",
key: `p_${String(Math.random())}`,
// 符号列表
notations: [],
@@ -25,5 +27,11 @@ function createParagraphWithNotations() {
],
});
}
function cloneParagraph(paragraph) {
const origin = JSON.parse(JSON.stringify(toJS(paragraph)));
delete origin.key;
origin.notations = paragraph.notations.map((n) => cloneNotation(n));
return createParagraph(origin);
}
export { createParagraph, createParagraphWithNotations };
export { createParagraph, createParagraphWithNotations, cloneParagraph };