move plugins to extensions
This commit is contained in:
@@ -15,7 +15,6 @@ import CommandManager from './CommandManager'
|
|||||||
import ExtensionManager from './ExtensionManager'
|
import ExtensionManager from './ExtensionManager'
|
||||||
import EventEmitter from './EventEmitter'
|
import EventEmitter from './EventEmitter'
|
||||||
import { Extensions, UnionToIntersection, PickValue } from './types'
|
import { Extensions, UnionToIntersection, PickValue } from './types'
|
||||||
import defaultPlugins from './plugins'
|
|
||||||
import * as extensions from './extensions'
|
import * as extensions from './extensions'
|
||||||
import style from './style'
|
import style from './style'
|
||||||
|
|
||||||
@@ -264,10 +263,7 @@ export class Editor extends EventEmitter {
|
|||||||
this.view = new EditorView(this.options.element, {
|
this.view = new EditorView(this.options.element, {
|
||||||
state: EditorState.create({
|
state: EditorState.create({
|
||||||
doc: this.createDocument(this.options.content),
|
doc: this.createDocument(this.options.content),
|
||||||
plugins: [
|
plugins: this.extensionManager.plugins,
|
||||||
...this.extensionManager.plugins,
|
|
||||||
...defaultPlugins.map(plugin => plugin(this.proxy)),
|
|
||||||
],
|
|
||||||
}),
|
}),
|
||||||
dispatchTransaction: this.dispatchTransaction.bind(this),
|
dispatchTransaction: this.dispatchTransaction.bind(this),
|
||||||
})
|
})
|
||||||
|
|||||||
15
packages/core/src/extensions/editable.ts
Normal file
15
packages/core/src/extensions/editable.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { Plugin, PluginKey } from 'prosemirror-state'
|
||||||
|
import { createExtension } from '../Extension'
|
||||||
|
|
||||||
|
export const Editable = createExtension({
|
||||||
|
addProseMirrorPlugins() {
|
||||||
|
return [
|
||||||
|
new Plugin({
|
||||||
|
key: new PluginKey('editable'),
|
||||||
|
props: {
|
||||||
|
editable: () => this.editor.options.editable,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
},
|
||||||
|
})
|
||||||
42
packages/core/src/extensions/focusEvents.ts
Normal file
42
packages/core/src/extensions/focusEvents.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import { Plugin } from 'prosemirror-state'
|
||||||
|
import { createExtension } from '../Extension'
|
||||||
|
|
||||||
|
export const FocusEvents = createExtension({
|
||||||
|
addProseMirrorPlugins() {
|
||||||
|
const { editor } = this
|
||||||
|
|
||||||
|
return [
|
||||||
|
new Plugin({
|
||||||
|
props: {
|
||||||
|
attributes: {
|
||||||
|
tabindex: '0',
|
||||||
|
},
|
||||||
|
handleDOMEvents: {
|
||||||
|
focus: () => {
|
||||||
|
editor.isFocused = true
|
||||||
|
|
||||||
|
const transaction = editor.state.tr.setMeta('focused', true)
|
||||||
|
editor.view.dispatch(transaction)
|
||||||
|
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
blur: () => {
|
||||||
|
editor.isFocused = false
|
||||||
|
|
||||||
|
const transaction = editor.state.tr.setMeta('focused', false)
|
||||||
|
editor.view.dispatch(transaction)
|
||||||
|
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
declare module '../Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
FocusEvents: typeof FocusEvents,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,9 +2,12 @@ export { Blur } from './blur'
|
|||||||
export { ClearContent } from './clearContent'
|
export { ClearContent } from './clearContent'
|
||||||
export { ClearNodes } from './clearNodes'
|
export { ClearNodes } from './clearNodes'
|
||||||
export { DeleteSelection } from './deleteSelection'
|
export { DeleteSelection } from './deleteSelection'
|
||||||
|
export { Editable } from './editable'
|
||||||
export { Focus } from './focus'
|
export { Focus } from './focus'
|
||||||
|
export { FocusEvents } from './focusEvents'
|
||||||
export { InsertHTML } from './insertHTML'
|
export { InsertHTML } from './insertHTML'
|
||||||
export { InsertText } from './insertText'
|
export { InsertText } from './insertText'
|
||||||
|
export { Keymap } from './keymap'
|
||||||
export { LiftListItem } from './liftListItem'
|
export { LiftListItem } from './liftListItem'
|
||||||
export { RemoveMark } from './removeMark'
|
export { RemoveMark } from './removeMark'
|
||||||
export { RemoveMarks } from './removeMarks'
|
export { RemoveMarks } from './removeMarks'
|
||||||
|
|||||||
19
packages/core/src/extensions/keymap.ts
Normal file
19
packages/core/src/extensions/keymap.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { keymap } from 'prosemirror-keymap'
|
||||||
|
import { baseKeymap } from 'prosemirror-commands'
|
||||||
|
import { undoInputRule } from 'prosemirror-inputrules'
|
||||||
|
import { createExtension } from '../Extension'
|
||||||
|
|
||||||
|
export const Keymap = createExtension({
|
||||||
|
addProseMirrorPlugins() {
|
||||||
|
return [
|
||||||
|
keymap({ Backspace: undoInputRule }),
|
||||||
|
keymap(baseKeymap),
|
||||||
|
]
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
declare module '../Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
Keymap: typeof Keymap,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import { Plugin, PluginKey } from 'prosemirror-state'
|
|
||||||
import Editor from '../..'
|
|
||||||
|
|
||||||
export default (editor: Editor) => new Plugin({
|
|
||||||
key: new PluginKey('editable'),
|
|
||||||
props: {
|
|
||||||
editable: () => editor.options.editable,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import { Plugin } from 'prosemirror-state'
|
|
||||||
import Editor from '../..'
|
|
||||||
|
|
||||||
export default (editor: Editor) => new Plugin({
|
|
||||||
props: {
|
|
||||||
attributes: {
|
|
||||||
tabindex: '0',
|
|
||||||
},
|
|
||||||
handleDOMEvents: {
|
|
||||||
focus: () => {
|
|
||||||
editor.isFocused = true
|
|
||||||
|
|
||||||
const transaction = editor.state.tr.setMeta('focused', true)
|
|
||||||
editor.view.dispatch(transaction)
|
|
||||||
|
|
||||||
return true
|
|
||||||
},
|
|
||||||
blur: () => {
|
|
||||||
editor.isFocused = false
|
|
||||||
|
|
||||||
const transaction = editor.state.tr.setMeta('focused', false)
|
|
||||||
editor.view.dispatch(transaction)
|
|
||||||
|
|
||||||
return true
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import { keymap } from 'prosemirror-keymap'
|
|
||||||
import { baseKeymap } from 'prosemirror-commands'
|
|
||||||
import { undoInputRule } from 'prosemirror-inputrules'
|
|
||||||
import editable from './editable'
|
|
||||||
import focus from './focus'
|
|
||||||
|
|
||||||
export default [
|
|
||||||
() => keymap({ Backspace: undoInputRule }),
|
|
||||||
() => keymap(baseKeymap),
|
|
||||||
editable,
|
|
||||||
focus,
|
|
||||||
]
|
|
||||||
Reference in New Issue
Block a user