fix: remove default types for textAlign extension, fix #1430

There are no default types for TextAlign extension anymore. You have to configure by yourself. Usually something like:

```js
TextAlign.configure({
  types: ['heading', 'paragraph'],
})
```
This commit is contained in:
Philipp Kühn
2021-06-18 12:33:18 +02:00
parent 081b93bfae
commit b4e41afd17
4 changed files with 14 additions and 10 deletions

View File

@@ -63,7 +63,9 @@ export default {
this.editor = new Editor({ this.editor = new Editor({
extensions: [ extensions: [
StarterKit, StarterKit,
TextAlign, TextAlign.configure({
types: ['heading', 'paragraph'],
}),
Highlight, Highlight,
], ],
content: ` content: `

View File

@@ -45,7 +45,9 @@ export default {
Paragraph, Paragraph,
Text, Text,
Heading, Heading,
TextAlign, TextAlign.configure({
types: ['heading', 'paragraph'],
}),
], ],
content: ` content: `
<h2>Heading</h2> <h2>Heading</h2>

View File

@@ -19,8 +19,8 @@ yarn add @tiptap/extension-text-align
## Settings ## Settings
| Option | Type | Default | Description | | Option | Type | Default | Description |
| ---------------- | -------- | ---------------------------------------- | -------------------------------------------------------------------- | | ---------------- | -------- | ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| types | `Array` | `['heading', 'paragraph']` | A list of nodes where the text align attribute should be applied to. | | types | `Array` | `[]` | A list of nodes where the text align attribute should be applied to. Usually something like `['heading', 'paragraph']`.|
| alignments | `Array` | `['left', 'center', 'right', 'justify']` | A list of available options for the text align attribute. | | alignments | `Array` | `['left', 'center', 'right', 'justify']` | A list of available options for the text align attribute. |
| defaultAlignment | `String` | `'left'` | The default text align. | | defaultAlignment | `String` | `'left'` | The default text align. |

View File

@@ -25,7 +25,7 @@ export const TextAlign = Extension.create<TextAlignOptions>({
name: 'textAlign', name: 'textAlign',
defaultOptions: { defaultOptions: {
types: ['heading', 'paragraph'], types: [],
alignments: ['left', 'center', 'right', 'justify'], alignments: ['left', 'center', 'right', 'justify'],
defaultAlignment: 'left', defaultAlignment: 'left',
}, },
@@ -60,10 +60,10 @@ export const TextAlign = Extension.create<TextAlignOptions>({
return false return false
} }
return this.options.types.some(type => commands.updateAttributes(type, { textAlign: alignment })) return this.options.types.every(type => commands.updateAttributes(type, { textAlign: alignment }))
}, },
unsetTextAlign: () => ({ commands }) => { unsetTextAlign: () => ({ commands }) => {
return this.options.types.some(type => commands.resetAttributes(type, 'textAlign')) return this.options.types.every(type => commands.resetAttributes(type, 'textAlign'))
}, },
} }
}, },