mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-25 12:39:03 +08:00
add basic ChainedCommands type
This commit is contained in:
parent
4c392d5759
commit
778e064979
@ -5,7 +5,7 @@
|
||||
<button @click="editor.chain().focus().insertText('wat').insertHTML('<p>2</p>').run()">chain 1</button>
|
||||
<button @click="editor.chain().insertText('1').focus().run()">chain 2</button>
|
||||
<button @click="editor.chain().setContent('reset').insertText('1').clearContent().run()">setContent</button>
|
||||
<button @click="editor.chain().deleteSelection().run()">deleteSelection</button>
|
||||
<button @click="editor.chain().focus().deleteSelection().run()">deleteSelection</button>
|
||||
<editor-content :editor="editor" />
|
||||
</div>
|
||||
</template>
|
||||
|
@ -19,6 +19,7 @@ import Mark from './Mark'
|
||||
import ComponentRenderer from './ComponentRenderer'
|
||||
import defaultPlugins from './plugins'
|
||||
import * as commands from './commands'
|
||||
import { deleteSelection } from 'prosemirror-commands'
|
||||
|
||||
// export type Command = (next: Function, editor: Editor) => (...args: any) => any
|
||||
|
||||
@ -35,18 +36,24 @@ export interface CommandSpec {
|
||||
[key: string]: Command
|
||||
}
|
||||
|
||||
type EditorContent = string | JSON | null
|
||||
export interface Commands {}
|
||||
|
||||
// interface Element {
|
||||
// editor?: Editor
|
||||
// }
|
||||
// export type CommandNames = Extract<keyof Commands, string>
|
||||
|
||||
export type ChainedCommands = {
|
||||
[Command in keyof Commands]: Commands[Command] extends (...args: any[]) => any
|
||||
? (...args: Parameters<Commands[Command]>) => ChainedCommands
|
||||
: never
|
||||
} & {
|
||||
run: () => boolean
|
||||
}
|
||||
|
||||
type EditorContent = string | JSON | null
|
||||
|
||||
interface HTMLElement {
|
||||
editor?: Editor
|
||||
}
|
||||
|
||||
// Element.prototype.editor = Editor
|
||||
|
||||
interface EditorOptions {
|
||||
element: Element,
|
||||
content: EditorContent,
|
||||
@ -176,7 +183,7 @@ export class Editor extends EventEmitter {
|
||||
return proxy
|
||||
}
|
||||
}
|
||||
})
|
||||
}) as ChainedCommands
|
||||
}
|
||||
|
||||
protected chainableEditorState(tr: Transaction, state: EditorState): EditorState {
|
||||
|
@ -9,6 +9,12 @@ declare module '../Editor' {
|
||||
}
|
||||
}
|
||||
|
||||
// declare module '../Editor' {
|
||||
// interface Commands {
|
||||
// deleteSelection: DeleteSelectionCommand,
|
||||
// }
|
||||
// }
|
||||
|
||||
export const deleteSelection: DeleteSelectionCommand = () => ({ state, dispatch }) => {
|
||||
return originalDeleteSelection(state, dispatch)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user