2022-01-07 11:37:36 -05:00
|
|
|
import {EditorState} from "prosemirror-state";
|
|
|
|
import {EditorView} from "prosemirror-view";
|
|
|
|
import {exampleSetup} from "prosemirror-example-setup";
|
|
|
|
|
2022-01-19 06:31:02 -05:00
|
|
|
import {DOMParser} from "prosemirror-model";
|
2022-01-07 11:37:36 -05:00
|
|
|
|
|
|
|
import schema from "./schema";
|
2022-01-09 11:37:16 -05:00
|
|
|
import menu from "./menu";
|
2022-01-17 12:43:16 -05:00
|
|
|
import nodeViews from "./node-views";
|
2022-01-19 06:31:02 -05:00
|
|
|
import {stateToHtml} from "./util";
|
2022-01-07 11:37:36 -05:00
|
|
|
|
|
|
|
class ProseMirrorView {
|
|
|
|
constructor(target, content) {
|
|
|
|
|
|
|
|
// Build DOM from content
|
|
|
|
const renderDoc = document.implementation.createHTMLDocument();
|
|
|
|
renderDoc.body.innerHTML = content;
|
|
|
|
|
|
|
|
this.view = new EditorView(target, {
|
|
|
|
state: EditorState.create({
|
|
|
|
doc: DOMParser.fromSchema(schema).parse(renderDoc.body),
|
2022-01-09 11:37:16 -05:00
|
|
|
plugins: [
|
|
|
|
...exampleSetup({schema, menuBar: false}),
|
|
|
|
menu,
|
|
|
|
]
|
2022-01-17 12:43:16 -05:00
|
|
|
}),
|
|
|
|
nodeViews,
|
2022-01-07 11:37:36 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
get content() {
|
2022-01-19 06:31:02 -05:00
|
|
|
return stateToHtml(this.view.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
focus() {
|
|
|
|
this.view.focus()
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy() {
|
|
|
|
this.view.destroy()
|
2022-01-07 11:37:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ProseMirrorView;
|