add editorcontent component

This commit is contained in:
Philipp Kühn
2020-03-08 23:25:48 +01:00
parent a067259da1
commit a580e257f5
5 changed files with 65 additions and 9 deletions

View File

@@ -18,7 +18,6 @@ type EditorContent = string | JSON
type Command = (next: Function, editor: Editor, ...args: any) => any
interface Options {
element?: globalThis.Node
content: EditorContent
extensions: (Extension | Node)[]
injectCSS: Boolean
@@ -26,6 +25,7 @@ interface Options {
export class Editor extends EventEmitter {
element = document.createElement('div')
extensionManager!: ExtensionManager
schema!: Schema
view!: EditorView
@@ -77,7 +77,7 @@ export class Editor extends EventEmitter {
}
private createView() {
this.view = new EditorView(this.options.element, {
this.view = new EditorView(this.element, {
state: EditorState.create({
doc: this.createDocument(this.options.content),
plugins: this.plugins,
@@ -172,6 +172,22 @@ export class Editor extends EventEmitter {
return this[name](...args)
}
// public setParentComponent(component = null) {
// if (!component) {
// return
// }
// this.view.setProps({
// nodeViews: this.initNodeViews({
// parent: component,
// extensions: [
// ...this.builtInExtensions,
// ...this.options.extensions,
// ],
// }),
// })
// }
public json() {
return this.state.doc.toJSON()
}