-
Notifications
You must be signed in to change notification settings - Fork 16
/
editor.ts
53 lines (46 loc) · 1.61 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { EditorState } from "prosemirror-state"
import { EditorView } from "prosemirror-view"
import { DOMParser } from "prosemirror-model"
import { buildInputRules, buildKeymap } from "prosemirror-example-setup"
import { keymap } from "prosemirror-keymap"
import { baseKeymap } from "prosemirror-commands"
import { dropCursor } from "prosemirror-dropcursor"
import { gapCursor } from "prosemirror-gapcursor"
import { history } from "prosemirror-history"
import { schema } from "./editor/schema"
export default class Editor {
private view: EditorView
constructor(
editorHolder: Element,
contentHolder: Element
) {
let state = EditorState.create({
doc: DOMParser.fromSchema(schema).parse(contentHolder),
plugins: [
buildInputRules(schema),
// TODO keymap around enter -> new list item
// https://discuss.prosemirror.net/t/lists-paragraph-inside-li-instead-of-new-list-item/455
// TODO keymap around tab and shift-tab
// TODO extract hints about available keys
// https://github.com/prosemirror/prosemirror-example-setup/blob/master/src/keymap.js
keymap(buildKeymap(schema)),
keymap(baseKeymap),
dropCursor(),
gapCursor(),
history(),
]
})
this.view = new EditorView(editorHolder, {
state: state,
dispatchTransaction(transaction) {
let view = this
transaction.before
console.log(`transaction`)
console.log(transaction.before)
console.log(transaction.doc)
let newState = view.state.apply(transaction)
view.updateState(newState)
}
})
}
}