feat: add itemTypeName option

This commit is contained in:
Philipp Kühn 2021-12-11 00:13:24 +01:00
parent d64fb22e7c
commit 3d7c8e642f
6 changed files with 51 additions and 6 deletions

View File

@ -31,6 +31,17 @@ BulletList.configure({
})
```
### itemTypeName
Specify the list item name.
Default: `'listItem'`
```js
BulletList.configure({
itemTypeName: 'listItem',
})
```
## Commands
### toggleBulletList()

View File

@ -31,6 +31,17 @@ OrderedList.configure({
})
```
### itemTypeName
Specify the list item name.
Default: `'listItem'`
```js
OrderedList.configure({
itemTypeName: 'listItem',
})
```
## Commands
### toggleOrderedList()

View File

@ -31,6 +31,17 @@ TaskList.configure({
})
```
### itemTypeName
Specify the list item name.
Default: `'taskItem'`
```js
TaskList.configure({
itemTypeName: 'taskItem',
})
```
## Commands
# toggleTaskList()

View File

@ -1,6 +1,7 @@
import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core'
export interface BulletListOptions {
itemTypeName: string,
HTMLAttributes: Record<string, any>,
}
@ -22,13 +23,16 @@ export const BulletList = Node.create<BulletListOptions>({
addOptions() {
return {
itemTypeName: 'listItem',
HTMLAttributes: {},
}
},
group: 'block list',
content: 'listItem+',
content() {
return `${this.options.itemTypeName}+`
},
parseHTML() {
return [
@ -43,7 +47,7 @@ export const BulletList = Node.create<BulletListOptions>({
addCommands() {
return {
toggleBulletList: () => ({ commands }) => {
return commands.toggleList(this.name, 'listItem')
return commands.toggleList(this.name, this.options.itemTypeName)
},
}
},

View File

@ -1,6 +1,7 @@
import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core'
export interface OrderedListOptions {
itemTypeName: string,
HTMLAttributes: Record<string, any>,
}
@ -22,13 +23,16 @@ export const OrderedList = Node.create<OrderedListOptions>({
addOptions() {
return {
itemTypeName: 'listItem',
HTMLAttributes: {},
}
},
group: 'block list',
content: 'listItem+',
content() {
return `${this.options.itemTypeName}+`
},
addAttributes() {
return {
@ -62,7 +66,7 @@ export const OrderedList = Node.create<OrderedListOptions>({
addCommands() {
return {
toggleOrderedList: () => ({ commands }) => {
return commands.toggleList(this.name, 'listItem')
return commands.toggleList(this.name, this.options.itemTypeName)
},
}
},

View File

@ -1,6 +1,7 @@
import { Node, mergeAttributes } from '@tiptap/core'
export interface TaskListOptions {
itemTypeName: string,
HTMLAttributes: Record<string, any>,
}
@ -20,13 +21,16 @@ export const TaskList = Node.create<TaskListOptions>({
addOptions() {
return {
itemTypeName: 'taskItem',
HTMLAttributes: {},
}
},
group: 'block list',
content: 'taskItem+',
content() {
return `${this.options.itemTypeName}+`
},
parseHTML() {
return [
@ -44,7 +48,7 @@ export const TaskList = Node.create<TaskListOptions>({
addCommands() {
return {
toggleTaskList: () => ({ commands }) => {
return commands.toggleList(this.name, 'taskItem')
return commands.toggleList(this.name, this.options.itemTypeName)
},
}
},