vue-admin-core
Version:
A Component Library for Vue 3
47 lines (44 loc) • 1.2 kB
JavaScript
import { SlateEditor, SlateElement, SlateNode, SlateText, SlateTransforms } from '@wangeditor/editor';
function deleteHandler(newEditor) {
const [nodeEntry] = SlateEditor.nodes(newEditor, {
match: (n2) => newEditor.children[0] === n2,
// editor 第一个节点
mode: "highest"
// 最高层级
});
if (nodeEntry == null)
return false;
const n = nodeEntry[0];
if (!SlateElement.isElement(n))
return false;
if (n.type === "paragraph")
return false;
if (SlateNode.string(n) !== "")
return false;
const { children = [] } = n;
if (!SlateText.isText(children[0]))
return false;
SlateTransforms.setNodes(newEditor, {
type: "paragraph"
});
return true;
}
function withParagraph(editor) {
const { deleteBackward, deleteForward } = editor;
const newEditor = editor;
newEditor.deleteBackward = (unit) => {
const res = deleteHandler(newEditor);
if (res)
return;
deleteBackward(unit);
};
newEditor.deleteForward = (unit) => {
const res = deleteHandler(newEditor);
if (res)
return;
deleteForward(unit);
};
return newEditor;
}
export { withParagraph as default };
//# sourceMappingURL=plugin.mjs.map