From 21384fc7a66dd7d1e3849be52ae4ab9adc26cf4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Thu, 6 May 2021 18:41:05 +0200 Subject: [PATCH] feat: add StarterKit extension --- packages/starter-kit/src/index.ts | 6 ++ packages/starter-kit/src/starter-kit.ts | 122 ++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 packages/starter-kit/src/starter-kit.ts diff --git a/packages/starter-kit/src/index.ts b/packages/starter-kit/src/index.ts index 58c16cf17b7..0fab9a547e6 100644 --- a/packages/starter-kit/src/index.ts +++ b/packages/starter-kit/src/index.ts @@ -17,6 +17,10 @@ import BulletList, { BulletListOptions } from '@tiptap/extension-bullet-list' import OrderedList, { OrderedListOptions } from '@tiptap/extension-ordered-list' import ListItem, { ListItemOptions } from '@tiptap/extension-list-item' +import { StarterKit } from './starter-kit' + +export default StarterKit + export function defaultExtensions(options?: Partial<{ dropcursor: Partial, paragraph: Partial, @@ -34,6 +38,8 @@ export function defaultExtensions(options?: Partial<{ orderedList: Partial, listItem: Partial, }>) { + console.warn('[tiptap warn]: defaultExtensions() is deprecated. please use the default export "StarterKit". "StarterKit" is a regular extension that contains all other extensions.') + return [ Document, Paragraph.configure(options?.paragraph), diff --git a/packages/starter-kit/src/starter-kit.ts b/packages/starter-kit/src/starter-kit.ts new file mode 100644 index 00000000000..c05a434b6a3 --- /dev/null +++ b/packages/starter-kit/src/starter-kit.ts @@ -0,0 +1,122 @@ +import { Extension } from '@tiptap/core' +import Blockquote, { BlockquoteOptions } from '@tiptap/extension-blockquote' +import Bold, { BoldOptions } from '@tiptap/extension-bold' +import BulletList, { BulletListOptions } from '@tiptap/extension-bullet-list' +import Code, { CodeOptions } from '@tiptap/extension-code' +import CodeBlock, { CodeBlockOptions } from '@tiptap/extension-code-block' +import Document from '@tiptap/extension-document' +import Dropcursor, { DropcursorOptions } from '@tiptap/extension-dropcursor' +import Gapcursor from '@tiptap/extension-gapcursor' +import HardBreak, { HardBreakOptions } from '@tiptap/extension-hard-break' +import Heading, { HeadingOptions } from '@tiptap/extension-heading' +import History, { HistoryOptions } from '@tiptap/extension-history' +import HorizontalRule, { HorizontalRuleOptions } from '@tiptap/extension-horizontal-rule' +import Italic, { ItalicOptions } from '@tiptap/extension-italic' +import ListItem, { ListItemOptions } from '@tiptap/extension-list-item' +import OrderedList, { OrderedListOptions } from '@tiptap/extension-ordered-list' +import Paragraph, { ParagraphOptions } from '@tiptap/extension-paragraph' +import Strike, { StrikeOptions } from '@tiptap/extension-strike' +import Text from '@tiptap/extension-text' + +export interface StarterKitOptions { + blockquote: Partial | false, + bold: Partial | false, + bulletList: Partial | false, + code: Partial | false, + codeBlock: Partial | false, + document: false, + dropcursor: Partial | false, + gapcursor: false, + hardBreak: Partial | false, + heading: Partial | false, + history: Partial | false, + horizontalRule: Partial | false, + italic: Partial | false, + listItem: Partial | false, + orderedList: Partial | false, + paragraph: Partial | false, + strike: Partial | false, + text: false, +} + +export const StarterKit = Extension.create({ + name: 'starterKit', + + addExtensions() { + const extensions = [] + + if (this.options.blockquote !== false) { + extensions.push(Blockquote.configure(this.options?.blockquote)) + } + + if (this.options.bold !== false) { + extensions.push(Bold.configure(this.options?.bold)) + } + + if (this.options.bulletList !== false) { + extensions.push(BulletList.configure(this.options?.bulletList)) + } + + if (this.options.code !== false) { + extensions.push(Code.configure(this.options?.code)) + } + + if (this.options.codeBlock !== false) { + extensions.push(CodeBlock.configure(this.options?.codeBlock)) + } + + if (this.options.document !== false) { + extensions.push(Document.configure(this.options?.document)) + } + + if (this.options.dropcursor !== false) { + extensions.push(Dropcursor.configure(this.options?.dropcursor)) + } + + if (this.options.gapcursor !== false) { + extensions.push(Gapcursor.configure(this.options?.gapcursor)) + } + + if (this.options.hardBreak !== false) { + extensions.push(HardBreak.configure(this.options?.hardBreak)) + } + + if (this.options.heading !== false) { + extensions.push(Heading.configure(this.options?.heading)) + } + + if (this.options.history !== false) { + extensions.push(History.configure(this.options?.history)) + } + + if (this.options.horizontalRule !== false) { + extensions.push(HorizontalRule.configure(this.options?.horizontalRule)) + } + + if (this.options.italic !== false) { + extensions.push(Italic.configure(this.options?.italic)) + } + + if (this.options.listItem !== false) { + extensions.push(ListItem.configure(this.options?.listItem)) + } + + if (this.options.orderedList !== false) { + extensions.push(OrderedList.configure(this.options?.orderedList)) + } + + if (this.options.paragraph !== false) { + extensions.push(Paragraph.configure(this.options?.paragraph)) + } + + if (this.options.strike !== false) { + extensions.push(Strike.configure(this.options?.strike)) + } + + if (this.options.text !== false) { + extensions.push(Text.configure(this.options?.text)) + } + + return extensions + }, +})