Merge pull request #10 from ueberdosis/feature/add-paragraph-command
add paragraph command and keyboard shortcut
This commit is contained in:
@@ -28,6 +28,9 @@
|
|||||||
<button @click="editor.chain().focus().codeBlock().run()" :class="{ 'is-active': editor.isActive('codeBlock') }">
|
<button @click="editor.chain().focus().codeBlock().run()" :class="{ 'is-active': editor.isActive('codeBlock') }">
|
||||||
code block
|
code block
|
||||||
</button>
|
</button>
|
||||||
|
<button @click="editor.chain().focus().paragraph().run()" :class="{ 'is-active': editor.isActive('paragraph') }">
|
||||||
|
paragraph
|
||||||
|
</button>
|
||||||
<button @click="editor.chain().focus().heading({ level: 1 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 1 }) }">
|
<button @click="editor.chain().focus().heading({ level: 1 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 1 }) }">
|
||||||
h1
|
h1
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ yarn add @tiptap/extension-ordered-list @tiptap/extension-list-item
|
|||||||
| class | string | – | Add a custom class to the rendered HTML tag. |
|
| class | string | – | Add a custom class to the rendered HTML tag. |
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
| Command | Options | Description |
|
| Command | Options | Description |
|
||||||
| ----------- | ------- | --------------------- |
|
| ------------ | ------- | ---------------------- |
|
||||||
| ordered_list | — | Toggle a ordered list. |
|
| ordered_list | — | Toggle a ordered list. |
|
||||||
|
|
||||||
## Keyboard shortcuts
|
## Keyboard shortcuts
|
||||||
|
|||||||
@@ -20,10 +20,13 @@ yarn add @tiptap/extension-paragraph
|
|||||||
| class | string | – | Add a custom class to the rendered HTML tag. |
|
| class | string | – | Add a custom class to the rendered HTML tag. |
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
*None*
|
| Command | Options | Description |
|
||||||
|
| --------- | ------- | -------------------------------------------- |
|
||||||
|
| paragraph | — | Transforms all selected nodes to paragraphs. |
|
||||||
|
|
||||||
## Keyboard shortcuts
|
## Keyboard shortcuts
|
||||||
*None*
|
* Windows & Linux: `Control` `Alt` `0`
|
||||||
|
* macOS: `Cmd` `Alt` `0`
|
||||||
|
|
||||||
## Source code
|
## Source code
|
||||||
[packages/extension-paragraph/](https://github.com/ueberdosis/tiptap-next/blob/main/packages/extension-paragraph/)
|
[packages/extension-paragraph/](https://github.com/ueberdosis/tiptap-next/blob/main/packages/extension-paragraph/)
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
import { Node } from '@tiptap/core'
|
import { Command, Node } from '@tiptap/core'
|
||||||
// import ParagraphComponent from './paragraph.vue'
|
// import ParagraphComponent from './paragraph.vue'
|
||||||
|
|
||||||
|
export type ParagraphCommand = () => Command
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface Commands {
|
||||||
|
paragraph: ParagraphCommand,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default new Node()
|
export default new Node()
|
||||||
.name('paragraph')
|
.name('paragraph')
|
||||||
.schema(() => ({
|
.schema(() => ({
|
||||||
@@ -10,4 +18,12 @@ export default new Node()
|
|||||||
toDOM: () => ['p', 0],
|
toDOM: () => ['p', 0],
|
||||||
// toVue: ParagraphComponent,
|
// toVue: ParagraphComponent,
|
||||||
}))
|
}))
|
||||||
|
.commands(({ name }) => ({
|
||||||
|
[name]: () => ({ commands }) => {
|
||||||
|
return commands.toggleNode(name, 'paragraph')
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
.keys(({ editor }) => ({
|
||||||
|
'Mod-Alt-0': () => editor.paragraph(),
|
||||||
|
}))
|
||||||
.create()
|
.create()
|
||||||
|
|||||||
Reference in New Issue
Block a user