improve command handling
This commit is contained in:
@@ -37,7 +37,13 @@ export interface CommandSpec {
|
|||||||
|
|
||||||
export interface Commands {}
|
export interface Commands {}
|
||||||
|
|
||||||
// export type CommandNames = Extract<keyof Commands, string>
|
export type CommandNames = Extract<keyof Commands, string>
|
||||||
|
|
||||||
|
export type SingleCommands = {
|
||||||
|
[Command in keyof Commands]: Commands[Command] extends (...args: any[]) => any
|
||||||
|
? (...args: Parameters<Commands[Command]>) => boolean
|
||||||
|
: never
|
||||||
|
}
|
||||||
|
|
||||||
export type ChainedCommands = {
|
export type ChainedCommands = {
|
||||||
[Command in keyof Commands]: Commands[Command] extends (...args: any[]) => any
|
[Command in keyof Commands]: Commands[Command] extends (...args: any[]) => any
|
||||||
@@ -62,6 +68,10 @@ interface EditorOptions {
|
|||||||
editable: boolean,
|
editable: boolean,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare module './Editor' {
|
||||||
|
interface Editor extends SingleCommands {}
|
||||||
|
}
|
||||||
|
|
||||||
@magicMethods
|
@magicMethods
|
||||||
export class Editor extends EventEmitter {
|
export class Editor extends EventEmitter {
|
||||||
|
|
||||||
@@ -85,7 +95,6 @@ export class Editor extends EventEmitter {
|
|||||||
editable: true,
|
editable: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
constructor(options: Partial<EditorOptions> = {}) {
|
constructor(options: Partial<EditorOptions> = {}) {
|
||||||
super()
|
super()
|
||||||
this.options = { ...this.options, ...options }
|
this.options = { ...this.options, ...options }
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Command } from '../Editor'
|
|||||||
type BlurCommand = () => Command
|
type BlurCommand = () => Command
|
||||||
|
|
||||||
declare module '../Editor' {
|
declare module '../Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
blur: BlurCommand,
|
blur: BlurCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Command } from '../Editor'
|
|||||||
type ClearContentCommand = (emitUpdate?: Boolean) => Command
|
type ClearContentCommand = (emitUpdate?: Boolean) => Command
|
||||||
|
|
||||||
declare module '../Editor' {
|
declare module '../Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
clearContent: ClearContentCommand,
|
clearContent: ClearContentCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,17 +4,11 @@ import { deleteSelection as originalDeleteSelection } from 'prosemirror-commands
|
|||||||
type DeleteSelectionCommand = () => Command
|
type DeleteSelectionCommand = () => Command
|
||||||
|
|
||||||
declare module '../Editor' {
|
declare module '../Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
deleteSelection: DeleteSelectionCommand,
|
deleteSelection: DeleteSelectionCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// declare module '../Editor' {
|
|
||||||
// interface Commands {
|
|
||||||
// deleteSelection: DeleteSelectionCommand,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
export const deleteSelection: DeleteSelectionCommand = () => ({ state, dispatch }) => {
|
export const deleteSelection: DeleteSelectionCommand = () => ({ state, dispatch }) => {
|
||||||
return originalDeleteSelection(state, dispatch)
|
return originalDeleteSelection(state, dispatch)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import minMax from '../utils/minMax'
|
|||||||
type FocusCommand = (position?: Position) => Command
|
type FocusCommand = (position?: Position) => Command
|
||||||
|
|
||||||
declare module '../Editor' {
|
declare module '../Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
focus: FocusCommand
|
focus: FocusCommand
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {ReplaceStep, ReplaceAroundStep} from "prosemirror-transform"
|
|||||||
type InsertHTMLCommand = (value: string) => Command
|
type InsertHTMLCommand = (value: string) => Command
|
||||||
|
|
||||||
declare module '../Editor' {
|
declare module '../Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
insertHTML: InsertHTMLCommand,
|
insertHTML: InsertHTMLCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Command } from '../Editor'
|
|||||||
type InsertTextCommand = (value: string) => Command
|
type InsertTextCommand = (value: string) => Command
|
||||||
|
|
||||||
declare module '../Editor' {
|
declare module '../Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
insertText: InsertTextCommand,
|
insertText: InsertTextCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import getNodeType from '../utils/getNodeType'
|
|||||||
type LiftListItem = (typeOrName: string | NodeType) => Command
|
type LiftListItem = (typeOrName: string | NodeType) => Command
|
||||||
|
|
||||||
declare module '../Editor' {
|
declare module '../Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
liftListItem: LiftListItem,
|
liftListItem: LiftListItem,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import getMarkRange from '../utils/getMarkRange'
|
|||||||
type RemoveMarkCommand = (typeOrName: string | MarkType) => Command
|
type RemoveMarkCommand = (typeOrName: string | MarkType) => Command
|
||||||
|
|
||||||
declare module '../Editor' {
|
declare module '../Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
toggleMark: RemoveMarkCommand,
|
toggleMark: RemoveMarkCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Command } from '../Editor'
|
|||||||
type RemoveMarksCommand = () => Command
|
type RemoveMarksCommand = () => Command
|
||||||
|
|
||||||
declare module '../Editor' {
|
declare module '../Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
removeMarks: RemoveMarksCommand,
|
removeMarks: RemoveMarksCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ type ReplaceWithNodeCommand = (
|
|||||||
) => Command
|
) => Command
|
||||||
|
|
||||||
declare module '../Editor' {
|
declare module '../Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
replaceText: ReplaceWithNodeCommand,
|
replaceText: ReplaceWithNodeCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { selectAll as originalSelectAll } from 'prosemirror-commands'
|
|||||||
type SelectAllCommand = () => Command
|
type SelectAllCommand = () => Command
|
||||||
|
|
||||||
declare module '../Editor' {
|
declare module '../Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
selectAll: SelectAllCommand,
|
selectAll: SelectAllCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { selectParentNode as originalSelectParentNode } from 'prosemirror-comman
|
|||||||
type SelectParentNodeCommand = () => Command
|
type SelectParentNodeCommand = () => Command
|
||||||
|
|
||||||
declare module '../Editor' {
|
declare module '../Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
selectParentNode: SelectParentNodeCommand,
|
selectParentNode: SelectParentNodeCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ type SetContentCommand = (
|
|||||||
) => Command
|
) => Command
|
||||||
|
|
||||||
declare module '../Editor' {
|
declare module '../Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
setContent: SetContentCommand,
|
setContent: SetContentCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import getNodeType from '../utils/getNodeType'
|
|||||||
type SinkListItem = (typeOrName: string | NodeType) => Command
|
type SinkListItem = (typeOrName: string | NodeType) => Command
|
||||||
|
|
||||||
declare module '../Editor' {
|
declare module '../Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
sinkListItem: SinkListItem,
|
sinkListItem: SinkListItem,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import getNodeType from '../utils/getNodeType'
|
|||||||
type SplitListItem = (typeOrName: string | NodeType) => Command
|
type SplitListItem = (typeOrName: string | NodeType) => Command
|
||||||
|
|
||||||
declare module '../Editor' {
|
declare module '../Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
splitListItem: SplitListItem,
|
splitListItem: SplitListItem,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import getMarkType from '../utils/getMarkType'
|
|||||||
type ToggleMarkCommand = (typeOrName: string | MarkType) => Command
|
type ToggleMarkCommand = (typeOrName: string | MarkType) => Command
|
||||||
|
|
||||||
declare module '../Editor' {
|
declare module '../Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
toggleMark: ToggleMarkCommand,
|
toggleMark: ToggleMarkCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ type ToggleNodeCommand = (
|
|||||||
) => Command
|
) => Command
|
||||||
|
|
||||||
declare module '../Editor' {
|
declare module '../Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
toggleNode: ToggleNodeCommand,
|
toggleNode: ToggleNodeCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ type UpdateMarkCommand = (
|
|||||||
) => Command
|
) => Command
|
||||||
|
|
||||||
declare module '../Editor' {
|
declare module '../Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
updateMark: UpdateMarkCommand,
|
updateMark: UpdateMarkCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { textblockTypeInputRule } from 'prosemirror-inputrules'
|
|||||||
export type BlockquoteCommand = () => Command
|
export type BlockquoteCommand = () => Command
|
||||||
|
|
||||||
declare module '@tiptap/core/src/Editor' {
|
declare module '@tiptap/core/src/Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
blockquote: BlockquoteCommand,
|
blockquote: BlockquoteCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Command, Mark, markInputRule, markPasteRule } from '@tiptap/core'
|
|||||||
export type BoldCommand = () => Command
|
export type BoldCommand = () => Command
|
||||||
|
|
||||||
declare module '@tiptap/core/src/Editor' {
|
declare module '@tiptap/core/src/Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
bold: BoldCommand,
|
bold: BoldCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { wrappingInputRule } from 'prosemirror-inputrules'
|
|||||||
export type BulletListCommand = () => Command
|
export type BulletListCommand = () => Command
|
||||||
|
|
||||||
declare module '@tiptap/core/src/Editor' {
|
declare module '@tiptap/core/src/Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
bulletList: BulletListCommand,
|
bulletList: BulletListCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { textblockTypeInputRule } from 'prosemirror-inputrules'
|
|||||||
export type CodeBlockCommand = () => Command
|
export type CodeBlockCommand = () => Command
|
||||||
|
|
||||||
declare module '@tiptap/core/src/Editor' {
|
declare module '@tiptap/core/src/Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
codeBlock: CodeBlockCommand,
|
codeBlock: CodeBlockCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Command, Mark, markInputRule, markPasteRule } from '@tiptap/core'
|
|||||||
export type CodeCommand = () => Command
|
export type CodeCommand = () => Command
|
||||||
|
|
||||||
declare module '@tiptap/core/src/Editor' {
|
declare module '@tiptap/core/src/Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
code: CodeCommand,
|
code: CodeCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { chainCommands, exitCode } from 'prosemirror-commands'
|
|||||||
export type HardBreakCommand = () => Command
|
export type HardBreakCommand = () => Command
|
||||||
|
|
||||||
declare module '@tiptap/core/src/Editor' {
|
declare module '@tiptap/core/src/Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
hardBreak: HardBreakCommand,
|
hardBreak: HardBreakCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export interface HeadingOptions {
|
|||||||
export type HeadingCommand = (level: Level) => Command
|
export type HeadingCommand = (level: Level) => Command
|
||||||
|
|
||||||
declare module '@tiptap/core/src/Editor' {
|
declare module '@tiptap/core/src/Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
heading: HeadingCommand,
|
heading: HeadingCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
} from 'prosemirror-history'
|
} from 'prosemirror-history'
|
||||||
|
|
||||||
declare module '@tiptap/core/src/Editor' {
|
declare module '@tiptap/core/src/Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
undo: () => Command,
|
undo: () => Command,
|
||||||
redo: () => Command,
|
redo: () => Command,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Command, Node, nodeInputRule } from '@tiptap/core'
|
|||||||
export type HorizontalRuleCommand = () => Command
|
export type HorizontalRuleCommand = () => Command
|
||||||
|
|
||||||
declare module '@tiptap/core/src/Editor' {
|
declare module '@tiptap/core/src/Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
horizontalRule: HorizontalRuleCommand,
|
horizontalRule: HorizontalRuleCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Command, Mark, markInputRule, markPasteRule } from '@tiptap/core'
|
|||||||
export type ItalicCommand = () => Command
|
export type ItalicCommand = () => Command
|
||||||
|
|
||||||
declare module '@tiptap/core/src/Editor' {
|
declare module '@tiptap/core/src/Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
italic: ItalicCommand,
|
italic: ItalicCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Command, Mark, markInputRule, markPasteRule } from '@tiptap/core'
|
|||||||
type StrikeCommand = () => Command
|
type StrikeCommand = () => Command
|
||||||
|
|
||||||
declare module '@tiptap/core/src/Editor' {
|
declare module '@tiptap/core/src/Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
strike: StrikeCommand,
|
strike: StrikeCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Command, Mark } from '@tiptap/core'
|
|||||||
export type UnderlineCommand = () => Command
|
export type UnderlineCommand = () => Command
|
||||||
|
|
||||||
declare module '@tiptap/core/src/Editor' {
|
declare module '@tiptap/core/src/Editor' {
|
||||||
interface Editor {
|
interface Commands {
|
||||||
underline: UnderlineCommand,
|
underline: UnderlineCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user