From 3d7c8e642f31b1fa813e84dddc3968504477d536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20K=C3=BChn?= Date: Sat, 11 Dec 2021 00:13:24 +0100 Subject: [PATCH] feat: add itemTypeName option --- docs/api/nodes/bullet-list.md | 11 +++++++++++ docs/api/nodes/ordered-list.md | 11 +++++++++++ docs/api/nodes/task-list.md | 11 +++++++++++ packages/extension-bullet-list/src/bullet-list.ts | 8 ++++++-- packages/extension-ordered-list/src/ordered-list.ts | 8 ++++++-- packages/extension-task-list/src/task-list.ts | 8 ++++++-- 6 files changed, 51 insertions(+), 6 deletions(-) diff --git a/docs/api/nodes/bullet-list.md b/docs/api/nodes/bullet-list.md index 983e11f9..652bd27c 100644 --- a/docs/api/nodes/bullet-list.md +++ b/docs/api/nodes/bullet-list.md @@ -31,6 +31,17 @@ BulletList.configure({ }) ``` +### itemTypeName +Specify the list item name. + +Default: `'listItem'` + +```js +BulletList.configure({ + itemTypeName: 'listItem', +}) +``` + ## Commands ### toggleBulletList() diff --git a/docs/api/nodes/ordered-list.md b/docs/api/nodes/ordered-list.md index 0be45801..7fab529f 100644 --- a/docs/api/nodes/ordered-list.md +++ b/docs/api/nodes/ordered-list.md @@ -31,6 +31,17 @@ OrderedList.configure({ }) ``` +### itemTypeName +Specify the list item name. + +Default: `'listItem'` + +```js +OrderedList.configure({ + itemTypeName: 'listItem', +}) +``` + ## Commands ### toggleOrderedList() diff --git a/docs/api/nodes/task-list.md b/docs/api/nodes/task-list.md index b731386e..a42f6ad8 100644 --- a/docs/api/nodes/task-list.md +++ b/docs/api/nodes/task-list.md @@ -31,6 +31,17 @@ TaskList.configure({ }) ``` +### itemTypeName +Specify the list item name. + +Default: `'taskItem'` + +```js +TaskList.configure({ + itemTypeName: 'taskItem', +}) +``` + ## Commands # toggleTaskList() diff --git a/packages/extension-bullet-list/src/bullet-list.ts b/packages/extension-bullet-list/src/bullet-list.ts index 4679cebb..ef3aa293 100644 --- a/packages/extension-bullet-list/src/bullet-list.ts +++ b/packages/extension-bullet-list/src/bullet-list.ts @@ -1,6 +1,7 @@ import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core' export interface BulletListOptions { + itemTypeName: string, HTMLAttributes: Record, } @@ -22,13 +23,16 @@ export const BulletList = Node.create({ 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({ addCommands() { return { toggleBulletList: () => ({ commands }) => { - return commands.toggleList(this.name, 'listItem') + return commands.toggleList(this.name, this.options.itemTypeName) }, } }, diff --git a/packages/extension-ordered-list/src/ordered-list.ts b/packages/extension-ordered-list/src/ordered-list.ts index b6f64cb8..c451bc82 100644 --- a/packages/extension-ordered-list/src/ordered-list.ts +++ b/packages/extension-ordered-list/src/ordered-list.ts @@ -1,6 +1,7 @@ import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core' export interface OrderedListOptions { + itemTypeName: string, HTMLAttributes: Record, } @@ -22,13 +23,16 @@ export const OrderedList = Node.create({ 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({ addCommands() { return { toggleOrderedList: () => ({ commands }) => { - return commands.toggleList(this.name, 'listItem') + return commands.toggleList(this.name, this.options.itemTypeName) }, } }, diff --git a/packages/extension-task-list/src/task-list.ts b/packages/extension-task-list/src/task-list.ts index b317d76a..2cb28a7b 100644 --- a/packages/extension-task-list/src/task-list.ts +++ b/packages/extension-task-list/src/task-list.ts @@ -1,6 +1,7 @@ import { Node, mergeAttributes } from '@tiptap/core' export interface TaskListOptions { + itemTypeName: string, HTMLAttributes: Record, } @@ -20,13 +21,16 @@ export const TaskList = Node.create({ 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({ addCommands() { return { toggleTaskList: () => ({ commands }) => { - return commands.toggleList(this.name, 'taskItem') + return commands.toggleList(this.name, this.options.itemTypeName) }, } },