refactoring
This commit is contained in:
@@ -19,16 +19,14 @@ import Mark from './Mark'
|
|||||||
import ComponentRenderer from './ComponentRenderer'
|
import ComponentRenderer from './ComponentRenderer'
|
||||||
import defaultPlugins from './plugins'
|
import defaultPlugins from './plugins'
|
||||||
import * as commands from './commands'
|
import * as commands from './commands'
|
||||||
import { deleteSelection } from 'prosemirror-commands'
|
|
||||||
|
|
||||||
export type Command = (props: {
|
export type Command = (props: {
|
||||||
editor: Editor
|
editor: Editor,
|
||||||
tr: Transaction
|
tr: Transaction,
|
||||||
// TODO: find correct type
|
commands: SingleCommands,
|
||||||
commands: any
|
|
||||||
state: EditorState,
|
state: EditorState,
|
||||||
view: EditorView,
|
view: EditorView,
|
||||||
dispatch: (args?: any) => any
|
dispatch: (args?: any) => any,
|
||||||
}) => boolean
|
}) => boolean
|
||||||
|
|
||||||
export interface CommandSpec {
|
export interface CommandSpec {
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ declare module '../Editor' {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const blur: BlurCommand = () => ({ editor }) => {
|
export const blur: BlurCommand = () => ({ view }) => {
|
||||||
const element = editor.view.dom as HTMLElement
|
const element = view.dom as HTMLElement
|
||||||
|
|
||||||
element.blur()
|
element.blur()
|
||||||
|
|
||||||
|
|||||||
@@ -44,33 +44,7 @@ function resolveSelection(editor: Editor, position: Position = null): ResolvedSe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// export default (next: Function, editor: Editor) => (position = null) => {
|
export const focus: FocusCommand = (position = null) => ({ editor, view, tr }) => {
|
||||||
// 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
|
|
||||||
|
|
||||||
if ((view.hasFocus() && position === null) || position === false) {
|
if ((view.hasFocus() && position === null) || position === false) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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))
|
tr.setSelection(Selection.near(tr.doc.resolve(end as unknown as number), bias))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const insertHTML: InsertHTMLCommand = value => ({ tr, editor }) => {
|
export const insertHTML: InsertHTMLCommand = value => ({ tr, state }) => {
|
||||||
const { state } = editor
|
|
||||||
const { selection } = tr
|
const { selection } = tr
|
||||||
const element = elementFromString(value)
|
const element = elementFromString(value)
|
||||||
const slice = DOMParser.fromSchema(state.schema).parseSlice(element)
|
const slice = DOMParser.fromSchema(state.schema).parseSlice(element)
|
||||||
|
|||||||
Reference in New Issue
Block a user