Extensions
textAlign
Alignment as an attribute on existing blocks.
It is an extension rather than a node because alignment applies to whatever textblock is already there — turning a heading into a "centered heading" node type would double the schema for no gain. The attribute is declared here and lands on every type named, so a paragraph that knows nothing about alignment still keeps, renders and parses it.
1 · Install
One package for every extension · there is no @matrajs/textAlign to install.
npm i @matrajs/core2 · Add it to the editor
Import it and put it in the extensions array. That array is the whole feature list:
what is not in it is not in your bundle and not in the document's schema.
import { createEditor, document, paragraph, text, textAlign } from '@matrajs/core'
const editor = createEditor({
extensions: [document, paragraph, text, textAlign({ … })],
element: document.querySelector('#editor'),
})3 · Use it
Run a command, and give focus back · a click on a button takes it away.
editor.commands.setTextAlign('center')
editor.focus()From the keyboard: Mod-Shift-l , Mod-Shift-e , Mod-Shift-r .
Wired to a button:
const button = document.querySelector('#setTextAlign')
button.addEventListener('click', () => {
editor.commands.setTextAlign('center')
editor.focus()
})Commands
Every one returns true if it changed the document and false
if it could not · a command that does not apply where the caret is says so rather than
throwing.
| Command | Call |
|---|---|
setTextAlign |
editor.commands.setTextAlign(value: TextAlign)
|
unsetTextAlign |
editor.commands.unsetTextAlign()
|
Keyboard shortcuts
- Mod-Shift-l ·
- Mod-Shift-e ·
- Mod-Shift-r ·
Mod is Command on a Mac and Control everywhere else. To rebind one, put
your own extension after this in the array · later keys win.