-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathindex.tsx
More file actions
35 lines (27 loc) · 1.01 KB
/
Copy pathindex.tsx
File metadata and controls
35 lines (27 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import "./styles/index.scss";
import type { CommandFn, EditorKit } from "doc-editor-core";
import { BlockPlugin } from "doc-editor-core";
import type { RenderElementProps } from "doc-editor-delta";
import { Transforms } from "doc-editor-delta";
import { existKey } from "doc-editor-utils";
import { DividingLine } from "./components/dividing";
import { DIVIDING_LINE_KEY } from "./types";
export class DividingLinePlugin extends BlockPlugin {
public key: string = DIVIDING_LINE_KEY;
constructor(private editor: EditorKit) {
super();
}
public destroy(): void {}
public match(props: RenderElementProps): boolean {
return existKey(props.element, DIVIDING_LINE_KEY);
}
public render(): JSX.Element {
return <DividingLine></DividingLine>;
}
public onCommand?: CommandFn = () => {
const key = this.key;
const editor = this.editor;
Transforms.insertNodes(editor.raw, { [key]: true, children: [{ text: "" }] });
Transforms.insertNodes(editor.raw, { children: [{ text: "" }] });
};
}