-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheditor.ts
39 lines (38 loc) · 1.32 KB
/
editor.ts
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
36
37
38
39
import { EditorView } from 'prosemirror-view';
import { EditorState, Plugin } from 'prosemirror-state';
import { schemas } from '@schemas';
import { plugins } from '@plugins';
/*
editor single intance
*/
export default class Editor {
view: EditorView;
constructor(options: any) {
this.view = this.initView(options);
}
initView(options: any) {
const state = EditorState.create({
schema: schemas,
plugins: plugins.concat(new Plugin({
props: {
handleClick(view: EditorView, pos: number): boolean {
return false;
}
}
}))
});
return new EditorView({ mount: document.getElementById(options.root) }, {
state,
editable(view): boolean {
// Note: At the beginning, i want to design the structure like notion, such as not make the whole document contenteditable make the atom block instead to
// but there is a problem which make the plugin view not update, so i have to return it back, sad.
return true;
},
attributes(state) {
return {
style: 'box-sizing: border-box;'
}
}
});
}
}