add defaultAlignment option to text align extension
This commit is contained in:
@@ -3,12 +3,14 @@ import { Command, createExtension } from '@tiptap/core'
|
|||||||
type TextAlignOptions = {
|
type TextAlignOptions = {
|
||||||
types: string[],
|
types: string[],
|
||||||
alignments: string[],
|
alignments: string[],
|
||||||
|
defaultAlignment: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
const TextAlign = createExtension({
|
const TextAlign = createExtension({
|
||||||
defaultOptions: <TextAlignOptions>{
|
defaultOptions: <TextAlignOptions>{
|
||||||
types: ['heading', 'paragraph'],
|
types: ['heading', 'paragraph'],
|
||||||
alignments: ['left', 'center', 'right'],
|
alignments: ['left', 'center', 'right'],
|
||||||
|
defaultAlignment: 'left',
|
||||||
},
|
},
|
||||||
|
|
||||||
addGlobalAttributes() {
|
addGlobalAttributes() {
|
||||||
@@ -17,12 +19,12 @@ const TextAlign = createExtension({
|
|||||||
types: this.options.types,
|
types: this.options.types,
|
||||||
attributes: {
|
attributes: {
|
||||||
textAlign: {
|
textAlign: {
|
||||||
default: 'left',
|
default: this.options.defaultAlignment,
|
||||||
renderHTML: attributes => ({
|
renderHTML: attributes => ({
|
||||||
style: `text-align: ${attributes.textAlign}`,
|
style: `text-align: ${attributes.textAlign}`,
|
||||||
}),
|
}),
|
||||||
parseHTML: node => ({
|
parseHTML: element => ({
|
||||||
textAlign: node.style.textAlign || 'left',
|
textAlign: element.style.textAlign || this.options.defaultAlignment,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user