refactoring

This commit is contained in:
Philipp Kühn
2020-09-22 15:22:24 +02:00
parent 119fdd0dff
commit 8ca8e041fd
4 changed files with 8 additions and 37 deletions

View File

@@ -19,16 +19,14 @@ import Mark from './Mark'
import ComponentRenderer from './ComponentRenderer'
import defaultPlugins from './plugins'
import * as commands from './commands'
import { deleteSelection } from 'prosemirror-commands'
export type Command = (props: {
editor: Editor
tr: Transaction
// TODO: find correct type
commands: any
editor: Editor,
tr: Transaction,
commands: SingleCommands,
state: EditorState,
view: EditorView,
dispatch: (args?: any) => any
dispatch: (args?: any) => any,
}) => boolean
export interface CommandSpec {

View File

@@ -8,8 +8,8 @@ declare module '../Editor' {
}
}
export const blur: BlurCommand = () => ({ editor }) => {
const element = editor.view.dom as HTMLElement
export const blur: BlurCommand = () => ({ view }) => {
const element = view.dom as HTMLElement
element.blur()

View File

@@ -44,33 +44,7 @@ function resolveSelection(editor: Editor, position: Position = null): ResolvedSe
}
}
// export default (next: Function, editor: Editor) => (position = null) => {
// const { view, state } = editor
// if ((view.hasFocus() && position === null) || position === false) {
// next()
// return
// }
// const { from, to } = resolveSelection(editor, position)
// const { doc, tr } = state
// const resolvedFrom = minMax(from, 0, doc.content.size)
// const resolvedEnd = minMax(to, 0, doc.content.size)
// const selection = TextSelection.create(doc, resolvedFrom, resolvedEnd)
// const transaction = tr.setSelection(selection)
// view.dispatch(transaction)
// view.focus()
// //@ts-ignore
// // console.log(bla)
// // return 'FOCUS'
// next()
// }
export const focus: FocusCommand = (position = null) => ({ editor, tr }) => {
const { view } = editor
export const focus: FocusCommand = (position = null) => ({ editor, view, tr }) => {
if ((view.hasFocus() && position === null) || position === false) {
return true
}

View File

@@ -25,8 +25,7 @@ function selectionToInsertionEnd(tr: Transaction, startLen: number, bias: number
tr.setSelection(Selection.near(tr.doc.resolve(end as unknown as number), bias))
}
export const insertHTML: InsertHTMLCommand = value => ({ tr, editor }) => {
const { state } = editor
export const insertHTML: InsertHTMLCommand = value => ({ tr, state }) => {
const { selection } = tr
const element = elementFromString(value)
const slice = DOMParser.fromSchema(state.schema).parseSlice(element)