mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-18 14:13:21 +08:00
rename addMark to setMark
This commit is contained in:
parent
1b45acd5d5
commit
e3a3d99c51
@ -6,7 +6,7 @@ import getMarkAttributes from '../utils/getMarkAttributes'
|
||||
/**
|
||||
* Add a mark with new attributes.
|
||||
*/
|
||||
export const addMark = (typeOrName: string | MarkType, attributes?: {}): Command => ({ tr, state, dispatch }) => {
|
||||
export const setMark = (typeOrName: string | MarkType, attributes?: {}): Command => ({ tr, state, dispatch }) => {
|
||||
const { selection } = tr
|
||||
const { from, to, empty } = selection
|
||||
const type = getMarkType(typeOrName, state.schema)
|
@ -15,7 +15,7 @@ export const toggleMark = (typeOrName: string | MarkType, attributes?: {}): Comm
|
||||
&& !markIsActive(state, type, attributes)
|
||||
|
||||
if (attributes && hasMarkWithDifferentAttributes) {
|
||||
return commands.addMark(type, attributes)
|
||||
return commands.setMark(type, attributes)
|
||||
}
|
||||
|
||||
return originalToggleMark(type, attributes)(state, dispatch)
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Extension } from '../Extension'
|
||||
import * as addMark from '../commands/addMark'
|
||||
import * as setMark from '../commands/setMark'
|
||||
import * as blur from '../commands/blur'
|
||||
import * as clearContent from '../commands/clearContent'
|
||||
import * as command from '../commands/command'
|
||||
@ -34,7 +34,7 @@ import * as wrapInList from '../commands/wrapInList'
|
||||
export const Commands = Extension.create({
|
||||
addCommands() {
|
||||
return {
|
||||
...addMark,
|
||||
...setMark,
|
||||
...blur,
|
||||
...clearContent,
|
||||
...clearNodes,
|
||||
|
@ -49,7 +49,7 @@ const Bold = Mark.create({
|
||||
* Set a bold mark
|
||||
*/
|
||||
setBold: (): Command => ({ commands }) => {
|
||||
return commands.addMark('bold')
|
||||
return commands.setMark('bold')
|
||||
},
|
||||
/**
|
||||
* Toggle a bold mark
|
||||
|
@ -39,7 +39,7 @@ const Code = Mark.create({
|
||||
* Set a code mark
|
||||
*/
|
||||
setCode: (): Command => ({ commands }) => {
|
||||
return commands.addMark('code')
|
||||
return commands.setMark('code')
|
||||
},
|
||||
/**
|
||||
* Toggle inline code
|
||||
@ -51,7 +51,7 @@ const Code = Mark.create({
|
||||
* Unset a code mark
|
||||
*/
|
||||
unsetCode: (): Command => ({ commands }) => {
|
||||
return commands.addMark('code')
|
||||
return commands.removeMark('code')
|
||||
},
|
||||
}
|
||||
},
|
||||
|
@ -42,7 +42,7 @@ const FontFamily = Extension.create({
|
||||
*/
|
||||
setFontFamily: (fontFamily: string): Command => ({ chain }) => {
|
||||
return chain()
|
||||
.addMark('textStyle', { fontFamily })
|
||||
.setMark('textStyle', { fontFamily })
|
||||
.run()
|
||||
},
|
||||
/**
|
||||
@ -50,7 +50,7 @@ const FontFamily = Extension.create({
|
||||
*/
|
||||
unsetFontFamily: (): Command => ({ chain }) => {
|
||||
return chain()
|
||||
.addMark('textStyle', { fontFamily: null })
|
||||
.setMark('textStyle', { fontFamily: null })
|
||||
.removeEmptyTextStyle()
|
||||
.run()
|
||||
},
|
||||
|
@ -62,7 +62,7 @@ const Highlight = Mark.create({
|
||||
* Set a highlight mark
|
||||
*/
|
||||
setHighlight: (attributes?: { color: string }): Command => ({ commands }) => {
|
||||
return commands.addMark('highlight', attributes)
|
||||
return commands.setMark('highlight', attributes)
|
||||
},
|
||||
/**
|
||||
* Toggle a highlight mark
|
||||
|
@ -48,7 +48,7 @@ const Italic = Mark.create({
|
||||
* Set an italic mark
|
||||
*/
|
||||
setItalic: (): Command => ({ commands }) => {
|
||||
return commands.addMark('italic')
|
||||
return commands.setMark('italic')
|
||||
},
|
||||
/**
|
||||
* Toggle an italic mark
|
||||
@ -60,7 +60,7 @@ const Italic = Mark.create({
|
||||
* Unset an italic mark
|
||||
*/
|
||||
unsetItalic: (): Command => ({ commands }) => {
|
||||
return commands.addMark('italic')
|
||||
return commands.removeMark('italic')
|
||||
},
|
||||
}
|
||||
},
|
||||
|
@ -50,7 +50,7 @@ const Link = Mark.create({
|
||||
* Set a link mark
|
||||
*/
|
||||
setLink: (attributes: { href?: string, target?: string } = {}): Command => ({ commands }) => {
|
||||
return commands.addMark('link', attributes)
|
||||
return commands.setMark('link', attributes)
|
||||
},
|
||||
/**
|
||||
* Toggle a link mark
|
||||
|
@ -48,7 +48,7 @@ const Strike = Mark.create({
|
||||
* Set a strike mark
|
||||
*/
|
||||
setStrike: (): Command => ({ commands }) => {
|
||||
return commands.addMark('strike')
|
||||
return commands.setMark('strike')
|
||||
},
|
||||
/**
|
||||
* Toggle a strike mark
|
||||
@ -60,7 +60,7 @@ const Strike = Mark.create({
|
||||
* Unset a strike mark
|
||||
*/
|
||||
unsetStrike: (): Command => ({ commands }) => {
|
||||
return commands.addMark('strike')
|
||||
return commands.removeMark('strike')
|
||||
},
|
||||
}
|
||||
},
|
||||
|
@ -34,7 +34,7 @@ const Underline = Mark.create({
|
||||
* Set an underline mark
|
||||
*/
|
||||
setUnderline: (): Command => ({ commands }) => {
|
||||
return commands.addMark('underline')
|
||||
return commands.setMark('underline')
|
||||
},
|
||||
/**
|
||||
* Toggle an underline mark
|
||||
@ -46,7 +46,7 @@ const Underline = Mark.create({
|
||||
* Unset an underline mark
|
||||
*/
|
||||
unsetUnderline: (): Command => ({ commands }) => {
|
||||
return commands.addMark('underline')
|
||||
return commands.removeMark('underline')
|
||||
},
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user