fix more commands
This commit is contained in:
@@ -28,7 +28,7 @@ export type Command = (props: {
|
||||
commands: any
|
||||
state: EditorState,
|
||||
view: EditorView,
|
||||
dispatch: () => any
|
||||
dispatch: (args?: any) => any
|
||||
}) => boolean
|
||||
|
||||
export interface CommandSpec {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { Node } from '@tiptap/core'
|
||||
import { Command, Node } from '@tiptap/core'
|
||||
import { wrappingInputRule } from 'prosemirror-inputrules'
|
||||
|
||||
export type BulletListCommand = () => Command
|
||||
|
||||
declare module '@tiptap/core/src/Editor' {
|
||||
interface Editor {
|
||||
bulletList(): Editor,
|
||||
bulletList: BulletListCommand,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +20,8 @@ export default new Node()
|
||||
toDOM: () => ['ul', 0],
|
||||
}))
|
||||
// .commands(({ editor, type }) => ({
|
||||
// [name]: next => attrs => {
|
||||
// // editor.toggleList(type, editor.schema.nodes.list_item)
|
||||
// next()
|
||||
// bulletList: () => ({ commands }) => {
|
||||
// return commands.toggleList(type, editor.schema.nodes.list_item)
|
||||
// },
|
||||
// }))
|
||||
.keys(({ editor }) => ({
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import { Node } from '@tiptap/core'
|
||||
import { Command, Node } from '@tiptap/core'
|
||||
import { textblockTypeInputRule } from 'prosemirror-inputrules'
|
||||
|
||||
export type CodeBlockCommand = () => Command
|
||||
|
||||
declare module '@tiptap/core/src/Editor' {
|
||||
interface Editor {
|
||||
codeBlock(): Editor,
|
||||
codeBlock: CodeBlockCommand,
|
||||
}
|
||||
}
|
||||
|
||||
export default new Node()
|
||||
.name('codeBlock')
|
||||
.name('code_block')
|
||||
.schema(() => ({
|
||||
content: 'text*',
|
||||
marks: '',
|
||||
@@ -21,12 +23,11 @@ export default new Node()
|
||||
],
|
||||
toDOM: () => ['pre', ['code', 0]],
|
||||
}))
|
||||
// .commands(({ editor, name }) => ({
|
||||
// [name]: next => attrs => {
|
||||
// editor.toggleNode(name, 'paragraph', attrs)
|
||||
// next()
|
||||
// },
|
||||
// }))
|
||||
.commands(({ name }) => ({
|
||||
codeBlock: attrs => ({ commands }) => {
|
||||
return commands.toggleNode(name, 'paragraph', attrs)
|
||||
},
|
||||
}))
|
||||
.keys(({ editor }) => ({
|
||||
'Shift-Ctrl-\\': () => editor.codeBlock()
|
||||
}))
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { Mark, markInputRule, markPasteRule } from '@tiptap/core'
|
||||
import { Command, Mark, markInputRule, markPasteRule } from '@tiptap/core'
|
||||
|
||||
export type CodeCommand = () => Command
|
||||
|
||||
declare module '@tiptap/core/src/Editor' {
|
||||
interface Editor {
|
||||
code(): Editor,
|
||||
code: CodeCommand,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +20,11 @@ export default new Mark()
|
||||
],
|
||||
toDOM: () => ['code', 0],
|
||||
}))
|
||||
// .commands(({ editor, name }) => ({
|
||||
// code: next => () => {
|
||||
// editor.toggleMark(name)
|
||||
// next()
|
||||
// },
|
||||
// }))
|
||||
.commands(({ name }) => ({
|
||||
code: () => ({ commands }) => {
|
||||
return commands.toggleMark(name)
|
||||
},
|
||||
}))
|
||||
.keys(({ editor }) => ({
|
||||
'Mod-`': () => editor.code()
|
||||
}))
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { Node } from '@tiptap/core'
|
||||
import { Command, Node } from '@tiptap/core'
|
||||
import { chainCommands, exitCode } from 'prosemirror-commands'
|
||||
|
||||
export type HardBreakCommand = () => Command
|
||||
|
||||
declare module '@tiptap/core/src/Editor' {
|
||||
interface Editor {
|
||||
hardBreak(): Editor,
|
||||
hardBreak: HardBreakCommand,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,19 +20,14 @@ export default new Node()
|
||||
],
|
||||
toDOM: () => ['br'],
|
||||
}))
|
||||
// .commands(({ editor, type }) => ({
|
||||
// hardBreak: next => () => {
|
||||
// const { state, view } = editor
|
||||
// const { dispatch } = view
|
||||
|
||||
// chainCommands(exitCode, () => {
|
||||
// dispatch(state.tr.replaceSelectionWith(type.create()).scrollIntoView())
|
||||
// return true
|
||||
// })(state, dispatch, view)
|
||||
|
||||
// next()
|
||||
// },
|
||||
// }))
|
||||
.commands(({ editor, type }) => ({
|
||||
hardBreak: () => ({ tr, state, dispatch, view }) => {
|
||||
return chainCommands(exitCode, () => {
|
||||
dispatch(tr.replaceSelectionWith(type.create()).scrollIntoView())
|
||||
return true
|
||||
})(state, dispatch, view)
|
||||
},
|
||||
}))
|
||||
.keys(({ editor }) => ({
|
||||
'Mod-Enter': () => editor.hardBreak(),
|
||||
'Shift-Enter': () => editor.hardBreak(),
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { Node, nodeInputRule } from '@tiptap/core'
|
||||
import { Command, Node, nodeInputRule } from '@tiptap/core'
|
||||
|
||||
export type HorizontalRuleCommand = () => Command
|
||||
|
||||
declare module '@tiptap/core/src/Editor' {
|
||||
interface Editor {
|
||||
horizontalRule(): Editor,
|
||||
horizontalRule: HorizontalRuleCommand,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,15 +15,13 @@ export default new Node()
|
||||
parseDOM: [{ tag: 'hr' }],
|
||||
toDOM: () => ['hr'],
|
||||
}))
|
||||
// .commands(({ editor, type }) => ({
|
||||
// horizontalRule: next => () => {
|
||||
// const { state, view } = editor
|
||||
// const { dispatch } = view
|
||||
.commands(({ type }) => ({
|
||||
horizontalRule: () => ({ tr }) => {
|
||||
tr.replaceSelectionWith(type.create())
|
||||
|
||||
// dispatch(state.tr.replaceSelectionWith(type.create()))
|
||||
// next()
|
||||
// },
|
||||
// }))
|
||||
return true
|
||||
},
|
||||
}))
|
||||
.inputRules(({ type }) => [
|
||||
nodeInputRule(/^(?:---|___\s|\*\*\*\s)$/, type),
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user