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