diff --git a/packages/core/src/Editor.ts b/packages/core/src/Editor.ts index e35aa46e..f17d3907 100644 --- a/packages/core/src/Editor.ts +++ b/packages/core/src/Editor.ts @@ -1,11 +1,7 @@ import { EditorState, Plugin } from 'prosemirror-state' import { EditorView} from 'prosemirror-view' import { Schema, DOMParser, DOMSerializer } from 'prosemirror-model' -import { undoInputRule } from 'prosemirror-inputrules' -import { keymap } from 'prosemirror-keymap' -import { baseKeymap } from 'prosemirror-commands' -import { dropCursor } from 'prosemirror-dropcursor' -import { gapCursor } from 'prosemirror-gapcursor' + import magicMethods from './utils/magicMethods' import elementFromString from './utils/elementFromString' import getAllMethodNames from './utils/getAllMethodNames' @@ -21,6 +17,7 @@ import Node from './Node' import Mark from './Mark' import EventEmitter from './EventEmitter' import ComponentRenderer from './ComponentRenderer' +import defaultPlugins from './plugins' // commands import clearContent from './commands/clearContent' @@ -38,9 +35,6 @@ import toggleMark from './commands/toggleMark' import toggleNode from './commands/toggleNode' import updateMark from './commands/updateMark' -// plugins -import focusPlugin from './plugins/focus' - export type Command = (next: Function, editor: Editor) => (...args: any) => any export interface CommandSpec { @@ -181,11 +175,7 @@ export class Editor extends EventEmitter { private get plugins() { return [ ...this.extensionManager.plugins, - keymap({ Backspace: undoInputRule }), - keymap(baseKeymap), - dropCursor(), - gapCursor(), - focusPlugin(this.proxy), + ...defaultPlugins.map(plugin => plugin(this.proxy)), ] } diff --git a/packages/core/src/plugins/editable.ts b/packages/core/src/plugins/editable.ts new file mode 100644 index 00000000..ee2f3798 --- /dev/null +++ b/packages/core/src/plugins/editable.ts @@ -0,0 +1,9 @@ +import { Plugin, PluginKey } from 'prosemirror-state' +import Editor from '../..' + +export default (editor: Editor) => new Plugin({ + key: new PluginKey('editable'), + props: { + editable: () => editor.isEditable, + }, +}) \ No newline at end of file diff --git a/packages/core/src/plugins/index.ts b/packages/core/src/plugins/index.ts new file mode 100644 index 00000000..94fc6a97 --- /dev/null +++ b/packages/core/src/plugins/index.ts @@ -0,0 +1,16 @@ +import { undoInputRule } from 'prosemirror-inputrules' +import { keymap } from 'prosemirror-keymap' +import { baseKeymap } from 'prosemirror-commands' +import { dropCursor } from 'prosemirror-dropcursor' +import { gapCursor } from 'prosemirror-gapcursor' +import editable from './editable' +import focus from './focus' + +export default [ + () => dropCursor(), + () => gapCursor(), + () => keymap({ Backspace: undoInputRule }), + () => keymap(baseKeymap), + editable, + focus, +] \ No newline at end of file