add color parameter to highlight command
This commit is contained in:
@@ -1,7 +1,22 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-if="editor">
|
<div v-if="editor">
|
||||||
<button @click="editor.chain().focus().highlight().run()" :class="{ 'is-active': editor.isActive('highlight') }">
|
<button @click="editor.chain().focus().highlight().run()" :class="{ 'is-active': editor.isActive('highlight') }">
|
||||||
highlight
|
highlight (default)
|
||||||
|
</button>
|
||||||
|
<button @click="editor.chain().focus().highlight({ color: 'red' }).run()" :class="{ 'is-active': editor.isActive('highlight', { color: 'red' }) }">
|
||||||
|
red
|
||||||
|
</button>
|
||||||
|
<button @click="editor.chain().focus().highlight({ color: 'orange' }).run()" :class="{ 'is-active': editor.isActive('highlight', { color: 'orange' }) }">
|
||||||
|
orange
|
||||||
|
</button>
|
||||||
|
<button @click="editor.chain().focus().highlight({ color: 'green' }).run()" :class="{ 'is-active': editor.isActive('highlight', { color: 'green' }) }">
|
||||||
|
green
|
||||||
|
</button>
|
||||||
|
<button @click="editor.chain().focus().highlight({ color: 'blue' }).run()" :class="{ 'is-active': editor.isActive('highlight', { color: 'blue' }) }">
|
||||||
|
blue
|
||||||
|
</button>
|
||||||
|
<button @click="editor.chain().focus().highlight({ color: 'purple' }).run()" :class="{ 'is-active': editor.isActive('highlight', { color: 'purple' }) }">
|
||||||
|
purple
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<editor-content :editor="editor" />
|
<editor-content :editor="editor" />
|
||||||
@@ -37,7 +52,7 @@ export default {
|
|||||||
],
|
],
|
||||||
content: `
|
content: `
|
||||||
<p>This isn’t highlighted.</s></p>
|
<p>This isn’t highlighted.</s></p>
|
||||||
<p><mark>But this one is.</mark></p>
|
<p><mark>But that one is.</mark></p>
|
||||||
<p><mark style="background-color: pink;">And this is highlighted too, but in a different color.</mark></p>
|
<p><mark style="background-color: pink;">And this is highlighted too, but in a different color.</mark></p>
|
||||||
`,
|
`,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { MarkType } from 'prosemirror-model'
|
|||||||
import { Command } from '../Editor'
|
import { Command } from '../Editor'
|
||||||
import getMarkType from '../utils/getMarkType'
|
import getMarkType from '../utils/getMarkType'
|
||||||
|
|
||||||
type ToggleMarkCommand = (typeOrName: string | MarkType) => Command
|
type ToggleMarkCommand = (typeOrName: string | MarkType, attrs?: {}) => Command
|
||||||
|
|
||||||
declare module '../Editor' {
|
declare module '../Editor' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
@@ -11,8 +11,8 @@ declare module '../Editor' {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const toggleMark: ToggleMarkCommand = typeOrName => ({ state, dispatch }) => {
|
export const toggleMark: ToggleMarkCommand = (typeOrName, attrs) => ({ state, dispatch }) => {
|
||||||
const type = getMarkType(typeOrName, state.schema)
|
const type = getMarkType(typeOrName, state.schema)
|
||||||
|
|
||||||
return originalToggleMark(type)(state, dispatch)
|
return originalToggleMark(type, attrs)(state, dispatch)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ export default new Mark()
|
|||||||
}, 0],
|
}, 0],
|
||||||
}))
|
}))
|
||||||
.commands(({ name }) => ({
|
.commands(({ name }) => ({
|
||||||
highlight: () => ({ commands }) => {
|
highlight: attrs => ({ commands }) => {
|
||||||
return commands.toggleMark(name)
|
return commands.toggleMark(name, attrs)
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
.keys(({ editor }) => ({
|
.keys(({ editor }) => ({
|
||||||
|
|||||||
Reference in New Issue
Block a user