refactoring
This commit is contained in:
@@ -46,7 +46,7 @@ export default {
|
|||||||
return {
|
return {
|
||||||
state: null,
|
state: null,
|
||||||
view: null,
|
view: null,
|
||||||
pluginplugins: [],
|
extensionPlugins: [],
|
||||||
plugins,
|
plugins,
|
||||||
schema: null,
|
schema: null,
|
||||||
nodes,
|
nodes,
|
||||||
@@ -94,7 +94,7 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
initEditor() {
|
initEditor() {
|
||||||
this.schema = this.createSchema()
|
this.schema = this.createSchema()
|
||||||
this.pluginplugins = this.createPlugins()
|
this.extensionPlugins = this.createPlugins()
|
||||||
this.keymaps = this.createKeymaps()
|
this.keymaps = this.createKeymaps()
|
||||||
this.inputRules = this.createInputRules()
|
this.inputRules = this.createInputRules()
|
||||||
this.state = this.createState()
|
this.state = this.createState()
|
||||||
@@ -112,7 +112,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
createPlugins() {
|
createPlugins() {
|
||||||
return this.plugins.pluginplugins
|
return this.plugins.plugins
|
||||||
},
|
},
|
||||||
|
|
||||||
createKeymaps() {
|
createKeymaps() {
|
||||||
@@ -139,7 +139,7 @@ export default {
|
|||||||
schema: this.schema,
|
schema: this.schema,
|
||||||
doc: this.getDocument(),
|
doc: this.getDocument(),
|
||||||
plugins: [
|
plugins: [
|
||||||
...this.pluginplugins,
|
...this.extensionPlugins,
|
||||||
...this.getPlugins(),
|
...this.getPlugins(),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ import { keymap } from 'prosemirror-keymap'
|
|||||||
|
|
||||||
export default class ExtensionManager {
|
export default class ExtensionManager {
|
||||||
|
|
||||||
constructor(plugins = []) {
|
constructor(extensions = []) {
|
||||||
this.plugins = plugins
|
this.extensions = extensions
|
||||||
}
|
}
|
||||||
|
|
||||||
get nodes() {
|
get nodes() {
|
||||||
return this.plugins
|
return this.extensions
|
||||||
.filter(plugin => plugin.type === 'node')
|
.filter(extension => extension.type === 'node')
|
||||||
.reduce((nodes, { name, schema }) => ({
|
.reduce((nodes, { name, schema }) => ({
|
||||||
...nodes,
|
...nodes,
|
||||||
[name]: schema,
|
[name]: schema,
|
||||||
@@ -16,17 +16,17 @@ export default class ExtensionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get marks() {
|
get marks() {
|
||||||
return this.plugins
|
return this.extensions
|
||||||
.filter(plugin => plugin.type === 'mark')
|
.filter(extension => extension.type === 'mark')
|
||||||
.reduce((marks, { name, schema }) => ({
|
.reduce((marks, { name, schema }) => ({
|
||||||
...marks,
|
...marks,
|
||||||
[name]: schema,
|
[name]: schema,
|
||||||
}), {})
|
}), {})
|
||||||
}
|
}
|
||||||
|
|
||||||
get pluginplugins() {
|
get plugins() {
|
||||||
return this.plugins
|
return this.extensions
|
||||||
.filter(plugin => plugin.plugins)
|
.filter(extension => extension.plugins)
|
||||||
.reduce((allPlugins, { plugins }) => ([
|
.reduce((allPlugins, { plugins }) => ([
|
||||||
...allPlugins,
|
...allPlugins,
|
||||||
...plugins,
|
...plugins,
|
||||||
@@ -34,8 +34,8 @@ export default class ExtensionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get views() {
|
get views() {
|
||||||
return this.plugins
|
return this.extensions
|
||||||
.filter(plugin => plugin.view)
|
.filter(extension => extension.view)
|
||||||
.reduce((views, { name, view }) => ({
|
.reduce((views, { name, view }) => ({
|
||||||
...views,
|
...views,
|
||||||
[name]: view,
|
[name]: view,
|
||||||
@@ -43,20 +43,20 @@ export default class ExtensionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
keymaps({ schema }) {
|
keymaps({ schema }) {
|
||||||
return this.plugins
|
return this.extensions
|
||||||
.filter(plugin => plugin.keys)
|
.filter(extension => extension.keys)
|
||||||
.map(plugin => plugin.keys({
|
.map(extension => extension.keys({
|
||||||
type: schema[`${plugin.type}s`][plugin.name],
|
type: schema[`${extension.type}s`][extension.name],
|
||||||
schema,
|
schema,
|
||||||
}))
|
}))
|
||||||
.map(keys => keymap(keys))
|
.map(keys => keymap(keys))
|
||||||
}
|
}
|
||||||
|
|
||||||
inputRules({ schema }) {
|
inputRules({ schema }) {
|
||||||
return this.plugins
|
return this.extensions
|
||||||
.filter(plugin => plugin.inputRules)
|
.filter(extension => extension.inputRules)
|
||||||
.map(plugin => plugin.inputRules({
|
.map(extension => extension.inputRules({
|
||||||
type: schema[`${plugin.type}s`][plugin.name],
|
type: schema[`${extension.type}s`][extension.name],
|
||||||
schema,
|
schema,
|
||||||
}))
|
}))
|
||||||
.reduce((allInputRules, inputRules) => ([
|
.reduce((allInputRules, inputRules) => ([
|
||||||
@@ -66,8 +66,8 @@ export default class ExtensionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
commands({ schema, view }) {
|
commands({ schema, view }) {
|
||||||
return this.plugins
|
return this.extensions
|
||||||
.filter(plugin => plugin.command)
|
.filter(extension => extension.command)
|
||||||
.reduce((commands, { name, type, command }) => ({
|
.reduce((commands, { name, type, command }) => ({
|
||||||
...commands,
|
...commands,
|
||||||
[name]: attrs => {
|
[name]: attrs => {
|
||||||
|
|||||||
Reference in New Issue
Block a user