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 ## Commands
### toggleBulletList() ### toggleBulletList()

View File

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

View File

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

View File

@ -1,6 +1,7 @@
import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core' import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core'
export interface BulletListOptions { export interface BulletListOptions {
itemTypeName: string,
HTMLAttributes: Record<string, any>, HTMLAttributes: Record<string, any>,
} }
@ -22,13 +23,16 @@ export const BulletList = Node.create<BulletListOptions>({
addOptions() { addOptions() {
return { return {
itemTypeName: 'listItem',
HTMLAttributes: {}, HTMLAttributes: {},
} }
}, },
group: 'block list', group: 'block list',
content: 'listItem+', content() {
return `${this.options.itemTypeName}+`
},
parseHTML() { parseHTML() {
return [ return [
@ -43,7 +47,7 @@ export const BulletList = Node.create<BulletListOptions>({
addCommands() { addCommands() {
return { return {
toggleBulletList: () => ({ commands }) => { 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' import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core'
export interface OrderedListOptions { export interface OrderedListOptions {
itemTypeName: string,
HTMLAttributes: Record<string, any>, HTMLAttributes: Record<string, any>,
} }
@ -22,13 +23,16 @@ export const OrderedList = Node.create<OrderedListOptions>({
addOptions() { addOptions() {
return { return {
itemTypeName: 'listItem',
HTMLAttributes: {}, HTMLAttributes: {},
} }
}, },
group: 'block list', group: 'block list',
content: 'listItem+', content() {
return `${this.options.itemTypeName}+`
},
addAttributes() { addAttributes() {
return { return {
@ -62,7 +66,7 @@ export const OrderedList = Node.create<OrderedListOptions>({
addCommands() { addCommands() {
return { return {
toggleOrderedList: () => ({ commands }) => { 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' import { Node, mergeAttributes } from '@tiptap/core'
export interface TaskListOptions { export interface TaskListOptions {
itemTypeName: string,
HTMLAttributes: Record<string, any>, HTMLAttributes: Record<string, any>,
} }
@ -20,13 +21,16 @@ export const TaskList = Node.create<TaskListOptions>({
addOptions() { addOptions() {
return { return {
itemTypeName: 'taskItem',
HTMLAttributes: {}, HTMLAttributes: {},
} }
}, },
group: 'block list', group: 'block list',
content: 'taskItem+', content() {
return `${this.options.itemTypeName}+`
},
parseHTML() { parseHTML() {
return [ return [
@ -44,7 +48,7 @@ export const TaskList = Node.create<TaskListOptions>({
addCommands() { addCommands() {
return { return {
toggleTaskList: () => ({ commands }) => { toggleTaskList: () => ({ commands }) => {
return commands.toggleList(this.name, 'taskItem') return commands.toggleList(this.name, this.options.itemTypeName)
}, },
} }
}, },