tiptap/packages/extension-text-align/index.ts

36 lines
670 B
TypeScript
Raw Normal View History

2020-10-23 21:23:40 +08:00
import { createExtension } from '@tiptap/core'
2020-10-23 23:19:12 +08:00
type TextAlignOptions = {
types: string[],
}
2020-10-23 21:23:40 +08:00
const TextAlign = createExtension({
2020-10-23 23:19:12 +08:00
defaultOptions: <TextAlignOptions>{
types: ['heading', 'paragraph'],
},
2020-10-23 21:23:40 +08:00
addGlobalAttributes() {
return [
{
2020-10-23 23:19:12 +08:00
types: this.options.types,
2020-10-23 21:23:40 +08:00
attributes: {
2020-10-23 23:19:12 +08:00
textAlign: {
2020-10-23 21:23:40 +08:00
default: 'left',
renderHTML: attributes => ({
2020-10-23 23:19:12 +08:00
style: `text-align: ${attributes.textAlign}`,
2020-10-23 21:23:40 +08:00
}),
},
},
},
]
},
})
export default TextAlign
declare module '@tiptap/core/src/Editor' {
interface AllExtensions {
TextAlign: typeof TextAlign,
}
}