-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathcommands.ts
69 lines (55 loc) · 2.14 KB
/
commands.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import {
insertNodeOfType,
isMarkActive,
promptForURL,
setListTypeOrWrapInList,
toggleWrap,
} from '@aeaton/prosemirror-commands'
import { Command, setBlockType, toggleMark, wrapIn } from 'prosemirror-commands'
import {
liftListItem,
sinkListItem,
splitListItem,
} from 'prosemirror-schema-list'
import { schema } from './schema'
// marks
export const toggleMarkBold = toggleMark(schema.marks.bold)
export const toggleMarkItalic = toggleMark(schema.marks.italic)
export const toggleMarkCode = toggleMark(schema.marks.code)
export const toggleMarkSubscript = toggleMark(schema.marks.subscript)
export const toggleMarkSuperscript = toggleMark(schema.marks.superscript)
export const toggleMarkUnderline = toggleMark(schema.marks.underline)
export const toggleMarkStrikethrough = toggleMark(schema.marks.strikethrough)
export const toggleLink: Command = (state, dispatch) => {
if (isMarkActive(schema.marks.link)(state)) {
toggleMark(schema.marks.link)(state, dispatch)
return true
}
const href = promptForURL()
if (!href) {
return false
}
toggleMark(schema.marks.link, { href })(state, dispatch)
// view.focus()
return true
}
// nodes
export const setBlockTypeParagraph = setBlockType(schema.nodes.paragraph)
export const setBlockTypeCodeBlock = setBlockType(schema.nodes.codeBlock)
export const setBlockTypeHeading = (level: number): Command =>
setBlockType(schema.nodes.heading, { level })
export const toggleWrapBlockquote = toggleWrap(schema.nodes.blockquote)
export const wrapInBlockquote = wrapIn(schema.nodes.blockquote)
export const setListTypeBullet = setListTypeOrWrapInList(schema.nodes.list, {
type: 'bullet',
})
export const setListTypeOrdered = setListTypeOrWrapInList(schema.nodes.list, {
type: 'ordered',
})
export const liftListItemCommand = liftListItem(schema.nodes.listItem)
export const sinkListItemCommand = sinkListItem(schema.nodes.listItem) // TODO: same list type
export const splitListItemCommand = splitListItem(schema.nodes.listItem)
export const insertNodeLineBreak = insertNodeOfType(schema.nodes.lineBreak)
export const insertNodeHorizontalRule = insertNodeOfType(
schema.nodes.horizontalRule
)