add basic extension manager

This commit is contained in:
Philipp Kühn
2020-03-05 21:05:01 +01:00
parent 6e85098741
commit 54dcbfc473
8 changed files with 89 additions and 11 deletions

View File

@@ -11,6 +11,8 @@ import {exampleSetup} from "prosemirror-example-setup"
import elementFromString from './utils/elementFromString'
import injectCSS from './utils/injectCSS'
import ExtensionManager from './ExtensionManager'
type EditorContent = string | JSON
interface Options {
@@ -24,10 +26,12 @@ export class Editor {
private lastCommand = Promise.resolve()
private schema: Schema = new Schema({
nodes: addListNodes(schema.spec.nodes, "paragraph block*", "block"),
marks: schema.spec.marks
})
schema: Schema
// private schema: Schema = new Schema({
// nodes: addListNodes(schema.spec.nodes, "paragraph block*", "block"),
// marks: schema.spec.marks
// })
selection = { from: 0, to: 0 }
@@ -39,8 +43,12 @@ export class Editor {
extensions: [],
}
extensionManager: ExtensionManager
constructor(options: Options) {
this.options = { ...this.options, ...options }
this.extensionManager = new ExtensionManager(this.options.extensions, this)
this.schema = this.createSchema()
this.view = this.createView()
this.registerCommand('focus', require('./commands/focus').default)
this.registerCommand('insertText', require('./commands/insertText').default)
@@ -55,6 +63,14 @@ export class Editor {
return this.view.state
}
private createSchema() {
return new Schema({
// topNode: this.options.topNode,
nodes: this.extensionManager.nodes,
marks: this.extensionManager.marks,
})
}
private createState() {
return EditorState.create({
doc: this.createDocument(this.options.content),