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