forked from ueberdosis/tiptap
/
BackgroundColor.js
43 lines (39 loc) · 1.07 KB
/
BackgroundColor.js
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
import { Mark } from 'tiptap'
import { updateMark } from 'tiptap-commands'
export default class BackgroundColor extends Mark {
get name () {
return 'background_color'
}
get defaultOptions () {
return {
colors: ['red', 'blue', 'yellow'],
}
}
get schema () {
return {
attrs: {
color: {
default: 'rgba(255,255,255,0)'
},
},
inline: true,
parseDOM: [
{
style: 'background-color',
getAttrs: (value) => ({ color: value }),
}, {
style: 'background',
getAttrs: (value) => ({ color: value }),
},
],
toDOM: mark => [
"span",
{ style: `background-color: ${mark.attrs.color}` },
0
]
}
}
commands ({ type }) {
return (attrs) => updateMark(type, attrs)
}
}