refactoring
This commit is contained in:
@@ -1,16 +1,14 @@
|
|||||||
import { TextSelection } from 'prosemirror-state'
|
import { TextSelection } from 'prosemirror-state'
|
||||||
import { Editor } from '../Editor'
|
import { Editor } from '../Editor'
|
||||||
import { Command } from '../types'
|
import { Command, FocusPosition } from '../types'
|
||||||
import minMax from '../utils/minMax'
|
import minMax from '../utils/minMax'
|
||||||
|
|
||||||
type Position = 'start' | 'end' | number | boolean | null
|
|
||||||
|
|
||||||
interface ResolvedSelection {
|
interface ResolvedSelection {
|
||||||
from: number,
|
from: number,
|
||||||
to: number,
|
to: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveSelection(editor: Editor, position: Position = null): ResolvedSelection {
|
function resolveSelection(editor: Editor, position: FocusPosition = null): ResolvedSelection {
|
||||||
if (position === null) {
|
if (position === null) {
|
||||||
return editor.selection
|
return editor.selection
|
||||||
}
|
}
|
||||||
@@ -37,8 +35,11 @@ function resolveSelection(editor: Editor, position: Position = null): ResolvedSe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (position: Position = null): Command => ({
|
export default (position: FocusPosition = null): Command => ({
|
||||||
editor, view, tr, dispatch,
|
editor,
|
||||||
|
view,
|
||||||
|
tr,
|
||||||
|
dispatch,
|
||||||
}) => {
|
}) => {
|
||||||
if ((view.hasFocus() && position === null) || position === false) {
|
if ((view.hasFocus() && position === null) || position === false) {
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export interface EditorOptions {
|
|||||||
content: EditorContent,
|
content: EditorContent,
|
||||||
extensions: Extensions,
|
extensions: Extensions,
|
||||||
injectCSS: boolean,
|
injectCSS: boolean,
|
||||||
autofocus: 'start' | 'end' | number | boolean | null,
|
autofocus: FocusPosition,
|
||||||
editable: boolean,
|
editable: boolean,
|
||||||
onInit: () => void,
|
onInit: () => void,
|
||||||
onUpdate: () => void,
|
onUpdate: () => void,
|
||||||
@@ -116,3 +116,5 @@ export type ChainedCommands = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type CanCommands = SingleCommands & { chain: () => ChainedCommands }
|
export type CanCommands = SingleCommands & { chain: () => ChainedCommands }
|
||||||
|
|
||||||
|
export type FocusPosition = 'start' | 'end' | number | boolean | null
|
||||||
|
|||||||
Reference in New Issue
Block a user