add basic text align extension
This commit is contained in:
18
docs/src/demos/Extensions/TextAlign/index.spec.js
Normal file
18
docs/src/demos/Extensions/TextAlign/index.spec.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
context('/api/extensions/text', () => {
|
||||||
|
before(() => {
|
||||||
|
cy.visit('/api/extensions/text')
|
||||||
|
})
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||||
|
editor.clearContent()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('text should be wrapped in a paragraph by default', () => {
|
||||||
|
cy.get('.ProseMirror')
|
||||||
|
.type('Example Text')
|
||||||
|
.find('p')
|
||||||
|
.should('contain', 'Example Text')
|
||||||
|
})
|
||||||
|
})
|
||||||
54
docs/src/demos/Extensions/TextAlign/index.vue
Normal file
54
docs/src/demos/Extensions/TextAlign/index.vue
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<template>
|
||||||
|
<div v-if="editor">
|
||||||
|
<button @click="editor.chain().focus().setAttributes({ align: 'left' }).run()">
|
||||||
|
left
|
||||||
|
</button>
|
||||||
|
<button @click="editor.chain().focus().setAttributes({ align: 'center' }).run()">
|
||||||
|
center
|
||||||
|
</button>
|
||||||
|
<button @click="editor.chain().focus().setAttributes({ align: 'right' }).run()">
|
||||||
|
right
|
||||||
|
</button>
|
||||||
|
<editor-content :editor="editor" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { Editor } from '@tiptap/core'
|
||||||
|
import { EditorContent } from '@tiptap/vue'
|
||||||
|
import Document from '@tiptap/extension-document'
|
||||||
|
import Paragraph from '@tiptap/extension-paragraph'
|
||||||
|
import Text from '@tiptap/extension-text'
|
||||||
|
import TextAlign from '@tiptap/extension-text-align'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
EditorContent,
|
||||||
|
},
|
||||||
|
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
editor: null,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
this.editor = new Editor({
|
||||||
|
extensions: [
|
||||||
|
Document(),
|
||||||
|
Paragraph(),
|
||||||
|
Text(),
|
||||||
|
TextAlign(),
|
||||||
|
],
|
||||||
|
content: `
|
||||||
|
<p>first paragraph</p>
|
||||||
|
<p>second paragraph</p>
|
||||||
|
`,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
beforeDestroy() {
|
||||||
|
this.editor.destroy()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
16
docs/src/docPages/api/extensions/text-align.md
Normal file
16
docs/src/docPages/api/extensions/text-align.md
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# Text Align
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
```bash
|
||||||
|
# With npm
|
||||||
|
npm install @tiptap/extension-text-align
|
||||||
|
|
||||||
|
# Or: With Yarn
|
||||||
|
yarn add @tiptap/extension-text-align
|
||||||
|
```
|
||||||
|
|
||||||
|
## Source code
|
||||||
|
[packages/extension-text-align/](https://github.com/ueberdosis/tiptap-next/blob/main/packages/extension-text-align/)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
<demo name="Extensions/TextAlign" highlight="12,30" />
|
||||||
@@ -161,6 +161,8 @@
|
|||||||
# draft: true
|
# draft: true
|
||||||
- title: Text
|
- title: Text
|
||||||
link: /api/extensions/text
|
link: /api/extensions/text
|
||||||
|
- title: Text Align
|
||||||
|
link: /api/extensions/text-align
|
||||||
# - title: TodoItem
|
# - title: TodoItem
|
||||||
# link: /api/extensions/todo-item
|
# link: /api/extensions/todo-item
|
||||||
# draft: true
|
# draft: true
|
||||||
|
|||||||
@@ -8,36 +8,6 @@ const Paragraph = createNode({
|
|||||||
|
|
||||||
content: 'inline*',
|
content: 'inline*',
|
||||||
|
|
||||||
// addGlobalAttributes() {
|
|
||||||
// return [
|
|
||||||
// {
|
|
||||||
// types: ['paragraph'],
|
|
||||||
// attributes: {
|
|
||||||
// align: {
|
|
||||||
// default: 'right',
|
|
||||||
// renderHTML: attributes => ({
|
|
||||||
// class: 'foo',
|
|
||||||
// style: `text-align: ${attributes.align}`,
|
|
||||||
// }),
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// ]
|
|
||||||
// },
|
|
||||||
|
|
||||||
// addAttributes() {
|
|
||||||
// return {
|
|
||||||
// id: {
|
|
||||||
// default: '123',
|
|
||||||
// rendered: true,
|
|
||||||
// renderHTML: attributes => ({
|
|
||||||
// class: 'bar',
|
|
||||||
// style: 'color: red',
|
|
||||||
// }),
|
|
||||||
// },
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
|
|
||||||
parseHTML() {
|
parseHTML() {
|
||||||
return [
|
return [
|
||||||
{ tag: 'p' },
|
{ tag: 'p' },
|
||||||
|
|||||||
27
packages/extension-text-align/index.ts
Normal file
27
packages/extension-text-align/index.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { createExtension } from '@tiptap/core'
|
||||||
|
|
||||||
|
const TextAlign = createExtension({
|
||||||
|
addGlobalAttributes() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
types: ['paragraph'],
|
||||||
|
attributes: {
|
||||||
|
align: {
|
||||||
|
default: 'left',
|
||||||
|
renderHTML: attributes => ({
|
||||||
|
style: `text-align: ${attributes.align}`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default TextAlign
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
TextAlign: typeof TextAlign,
|
||||||
|
}
|
||||||
|
}
|
||||||
17
packages/extension-text-align/package.json
Normal file
17
packages/extension-text-align/package.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"name": "@tiptap/extension-text-align",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"source": "index.ts",
|
||||||
|
"main": "dist/tiptap-extension-text-align.js",
|
||||||
|
"umd:main": "dist/tiptap-extension-text-align.umd.js",
|
||||||
|
"module": "dist/tiptap-extension-text-align.mjs",
|
||||||
|
"unpkg": "dist/tiptap-extension-text-align.js",
|
||||||
|
"jsdelivr": "dist/tiptap-extension-text-align.js",
|
||||||
|
"files": [
|
||||||
|
"src",
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
|
"peerDependencies": {
|
||||||
|
"@tiptap/core": "2.x"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user