diff --git a/packages/core/src/commands/focus.ts b/packages/core/src/commands/focus.ts index 80c6038a..c27423a5 100644 --- a/packages/core/src/commands/focus.ts +++ b/packages/core/src/commands/focus.ts @@ -1,16 +1,14 @@ import { TextSelection } from 'prosemirror-state' import { Editor } from '../Editor' -import { Command } from '../types' +import { Command, FocusPosition } from '../types' import minMax from '../utils/minMax' -type Position = 'start' | 'end' | number | boolean | null - interface ResolvedSelection { from: number, to: number, } -function resolveSelection(editor: Editor, position: Position = null): ResolvedSelection { +function resolveSelection(editor: Editor, position: FocusPosition = null): ResolvedSelection { if (position === null) { return editor.selection } @@ -37,8 +35,11 @@ function resolveSelection(editor: Editor, position: Position = null): ResolvedSe } } -export default (position: Position = null): Command => ({ - editor, view, tr, dispatch, +export default (position: FocusPosition = null): Command => ({ + editor, + view, + tr, + dispatch, }) => { if ((view.hasFocus() && position === null) || position === false) { return true diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 0328e4d5..d9b6afeb 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -14,7 +14,7 @@ export interface EditorOptions { content: EditorContent, extensions: Extensions, injectCSS: boolean, - autofocus: 'start' | 'end' | number | boolean | null, + autofocus: FocusPosition, editable: boolean, onInit: () => void, onUpdate: () => void, @@ -116,3 +116,5 @@ export type ChainedCommands = { } export type CanCommands = SingleCommands & { chain: () => ChainedCommands } + +export type FocusPosition = 'start' | 'end' | number | boolean | null