9d7174557e
This is a copy of the ProseMirror/prosemirror-menu repo files which suggest working from a fork of this. These changes include the ability to select callouts from the menubar.
38 lines
No EOL
1.2 KiB
JavaScript
38 lines
No EOL
1.2 KiB
JavaScript
import {EditorState} from "prosemirror-state";
|
|
import {EditorView} from "prosemirror-view";
|
|
import {exampleSetup} from "prosemirror-example-setup";
|
|
|
|
import {DOMParser, DOMSerializer} from "prosemirror-model";
|
|
|
|
import schema from "./schema";
|
|
import menu from "./menu";
|
|
|
|
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),
|
|
plugins: [
|
|
...exampleSetup({schema, menuBar: false}),
|
|
menu,
|
|
]
|
|
})
|
|
});
|
|
}
|
|
|
|
get content() {
|
|
const fragment = DOMSerializer.fromSchema(schema).serializeFragment(this.view.state.doc.content);
|
|
const renderDoc = document.implementation.createHTMLDocument();
|
|
renderDoc.body.appendChild(fragment);
|
|
return renderDoc.body.innerHTML;
|
|
}
|
|
focus() { this.view.focus() }
|
|
destroy() { this.view.destroy() }
|
|
}
|
|
|
|
export default ProseMirrorView; |