improve options interface

This commit is contained in:
Philipp Kühn 2021-02-10 18:25:08 +01:00
parent 55ff908423
commit 215c26748b
33 changed files with 68 additions and 67 deletions

View File

@ -26,11 +26,11 @@ declare module '@tiptap/core' {
export const inputRegex = /^\s*>\s$/gm export const inputRegex = /^\s*>\s$/gm
export const Blockquote = Node.create({ export const Blockquote = Node.create<BlockquoteOptions>({
name: 'blockquote', name: 'blockquote',
defaultOptions: <BlockquoteOptions>{ defaultOptions: {
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -34,10 +34,10 @@ export const starPasteRegex = /(?:^|\s)((?:\*\*)((?:[^*]+))(?:\*\*))/gm
export const underscoreInputRegex = /(?:^|\s)((?:__)((?:[^__]+))(?:__))$/gm export const underscoreInputRegex = /(?:^|\s)((?:__)((?:[^__]+))(?:__))$/gm
export const underscorePasteRegex = /(?:^|\s)((?:__)((?:[^__]+))(?:__))/gm export const underscorePasteRegex = /(?:^|\s)((?:__)((?:[^__]+))(?:__))/gm
export const Bold = Mark.create({ export const Bold = Mark.create<BoldOptions>({
name: 'bold', name: 'bold',
defaultOptions: <BoldOptions>{ defaultOptions: {
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -18,10 +18,10 @@ declare module '@tiptap/core' {
export const inputRegex = /^\s*([-+*])\s$/ export const inputRegex = /^\s*([-+*])\s$/
export const BulletList = Node.create({ export const BulletList = Node.create<BulletListOptions>({
name: 'bulletList', name: 'bulletList',
defaultOptions: <BulletListOptions>{ defaultOptions: {
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -7,10 +7,10 @@ export interface CharacterCountOptions {
limit?: number, limit?: number,
} }
export const CharacterCount = Extension.create({ export const CharacterCount = Extension.create<CharacterCountOptions>({
name: 'characterCount', name: 'characterCount',
defaultOptions: <CharacterCountOptions>{ defaultOptions: {
limit: 0, limit: 0,
}, },

View File

@ -24,10 +24,10 @@ declare module '@tiptap/core' {
export const backtickInputRegex = /^```(?<language>[a-z]*)? $/ export const backtickInputRegex = /^```(?<language>[a-z]*)? $/
export const tildeInputRegex = /^~~~(?<language>[a-z]*)? $/ export const tildeInputRegex = /^~~~(?<language>[a-z]*)? $/
export const CodeBlock = Node.create({ export const CodeBlock = Node.create<CodeBlockOptions>({
name: 'codeBlock', name: 'codeBlock',
defaultOptions: <CodeBlockOptions>{ defaultOptions: {
languageClassPrefix: 'language-', languageClassPrefix: 'language-',
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -32,10 +32,10 @@ declare module '@tiptap/core' {
export const inputRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))$/gm export const inputRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))$/gm
export const pasteRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))/gm export const pasteRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))/gm
export const Code = Mark.create({ export const Code = Mark.create<CodeOptions>({
name: 'code', name: 'code',
defaultOptions: <CodeOptions>{ defaultOptions: {
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -26,10 +26,10 @@ const awarenessStatesToArray = (states: Map<number, { [key: string]: any }>) =>
}) })
} }
export const CollaborationCursor = Extension.create({ export const CollaborationCursor = Extension.create<CollaborationCursorOptions>({
name: 'collaborationCursor', name: 'collaborationCursor',
defaultOptions: <CollaborationCursorOptions>{ defaultOptions: {
provider: null, provider: null,
user: { user: {
name: null, name: null,

View File

@ -34,10 +34,10 @@ export interface CollaborationOptions {
fragment: any, fragment: any,
} }
export const Collaboration = Extension.create({ export const Collaboration = Extension.create<CollaborationOptions>({
name: 'collaboration', name: 'collaboration',
defaultOptions: <CollaborationOptions>{ defaultOptions: {
document: null, document: null,
field: 'default', field: 'default',
fragment: null, fragment: null,

View File

@ -7,10 +7,10 @@ export interface DropcursorOptions {
class: string | null, class: string | null,
} }
export const Dropcursor = Extension.create({ export const Dropcursor = Extension.create<DropcursorOptions>({
name: 'dropCursor', name: 'dropCursor',
defaultOptions: <DropcursorOptions>{ defaultOptions: {
color: 'black', color: 'black',
width: 1, width: 1,
class: null, class: null,

View File

@ -7,10 +7,10 @@ export interface FocusOptions {
mode: 'all' | 'deepest' | 'shallowest', mode: 'all' | 'deepest' | 'shallowest',
} }
export const FocusClasses = Extension.create({ export const FocusClasses = Extension.create<FocusOptions>({
name: 'focus', name: 'focus',
defaultOptions: <FocusOptions>{ defaultOptions: {
className: 'has-focus', className: 'has-focus',
mode: 'all', mode: 'all',
}, },

View File

@ -18,10 +18,10 @@ declare module '@tiptap/core' {
} }
} }
export const FontFamily = Extension.create({ export const FontFamily = Extension.create<FontFamilyOptions>({
name: 'fontFamily', name: 'fontFamily',
defaultOptions: <FontFamilyOptions>{ defaultOptions: {
types: ['textStyle'], types: ['textStyle'],
}, },

View File

@ -16,11 +16,10 @@ declare module '@tiptap/core' {
} }
} }
export const HardBreak = Node.create({ export const HardBreak = Node.create<HardBreakOptions>({
name: 'hardBreak', name: 'hardBreak',
defaultOptions: <HardBreakOptions>{ defaultOptions: {
languageClassPrefix: 'language-',
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -23,10 +23,10 @@ declare module '@tiptap/core' {
} }
} }
export const Heading = Node.create({ export const Heading = Node.create<HeadingOptions>({
name: 'heading', name: 'heading',
defaultOptions: <HeadingOptions>{ defaultOptions: {
levels: [1, 2, 3, 4, 5, 6], levels: [1, 2, 3, 4, 5, 6],
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -33,10 +33,10 @@ declare module '@tiptap/core' {
export const inputRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))$/gm export const inputRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))$/gm
export const pasteRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))/gm export const pasteRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))/gm
export const Highlight = Mark.create({ export const Highlight = Mark.create<HighlightOptions>({
name: 'highlight', name: 'highlight',
defaultOptions: <HighlightOptions>{ defaultOptions: {
multicolor: false, multicolor: false,
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -19,10 +19,10 @@ declare module '@tiptap/core' {
} }
} }
export const History = Extension.create({ export const History = Extension.create<HistoryOptions>({
name: 'history', name: 'history',
defaultOptions: <HistoryOptions>{ defaultOptions: {
depth: 100, depth: 100,
newGroupDelay: 500, newGroupDelay: 500,
}, },

View File

@ -20,10 +20,10 @@ declare module '@tiptap/core' {
} }
} }
export const HorizontalRule = Node.create({ export const HorizontalRule = Node.create<HorizontalRuleOptions>({
name: 'horizontalRule', name: 'horizontalRule',
defaultOptions: <HorizontalRuleOptions>{ defaultOptions: {
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -23,10 +23,10 @@ declare module '@tiptap/core' {
export const inputRegex = /!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\)/ export const inputRegex = /!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\)/
export const Image = Node.create({ export const Image = Node.create<ImageOptions>({
name: 'image', name: 'image',
defaultOptions: <ImageOptions>{ defaultOptions: {
inline: false, inline: false,
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -34,10 +34,10 @@ export const starPasteRegex = /(?:^|\s)((?:\*)((?:[^*]+))(?:\*))/gm
export const underscoreInputRegex = /(?:^|\s)((?:_)((?:[^_]+))(?:_))$/gm export const underscoreInputRegex = /(?:^|\s)((?:_)((?:[^_]+))(?:_))$/gm
export const underscorePasteRegex = /(?:^|\s)((?:_)((?:[^_]+))(?:_))/gm export const underscorePasteRegex = /(?:^|\s)((?:_)((?:[^_]+))(?:_))/gm
export const Italic = Mark.create({ export const Italic = Mark.create<ItalicOptions>({
name: 'italic', name: 'italic',
defaultOptions: <ItalicOptions>{ defaultOptions: {
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -33,12 +33,12 @@ declare module '@tiptap/core' {
export const pasteRegex = /https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,}\b(?:[-a-zA-Z0-9@:%._+~#=?!&/]*)(?:[-a-zA-Z0-9@:%._+~#=?!&/]*)/gi export const pasteRegex = /https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,}\b(?:[-a-zA-Z0-9@:%._+~#=?!&/]*)(?:[-a-zA-Z0-9@:%._+~#=?!&/]*)/gi
export const pasteRegexWithBrackets = /(?:\()https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,}\b(?:[-a-zA-Z0-9@:%._+~#=?!&/()]*)(?:\))/gi export const pasteRegexWithBrackets = /(?:\()https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,}\b(?:[-a-zA-Z0-9@:%._+~#=?!&/()]*)(?:\))/gi
export const Link = Mark.create({ export const Link = Mark.create<LinkOptions>({
name: 'link', name: 'link',
inclusive: false, inclusive: false,
defaultOptions: <LinkOptions>{ defaultOptions: {
openOnClick: true, openOnClick: true,
HTMLAttributes: { HTMLAttributes: {
target: '_blank', target: '_blank',

View File

@ -6,10 +6,10 @@ export interface ListItemOptions {
}, },
} }
export const ListItem = Node.create({ export const ListItem = Node.create<ListItemOptions>({
name: 'listItem', name: 'listItem',
defaultOptions: <ListItemOptions>{ defaultOptions: {
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -8,10 +8,10 @@ export type MentionOptions = {
suggestion: Omit<SuggestionOptions, 'editor'>, suggestion: Omit<SuggestionOptions, 'editor'>,
} }
export const Mention = Node.create({ export const Mention = Node.create<MentionOptions>({
name: 'mention', name: 'mention',
defaultOptions: <MentionOptions>{ defaultOptions: {
HTMLAttributes: {}, HTMLAttributes: {},
suggestion: { suggestion: {
char: '@', char: '@',

View File

@ -18,10 +18,10 @@ declare module '@tiptap/core' {
export const inputRegex = /^(\d+)\.\s$/ export const inputRegex = /^(\d+)\.\s$/
export const OrderedList = Node.create({ export const OrderedList = Node.create<OrderedListOptions>({
name: 'orderedList', name: 'orderedList',
defaultOptions: <OrderedListOptions>{ defaultOptions: {
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -15,10 +15,10 @@ declare module '@tiptap/core' {
} }
} }
export const Paragraph = Node.create({ export const Paragraph = Node.create<ParagraphOptions>({
name: 'paragraph', name: 'paragraph',
defaultOptions: <ParagraphOptions>{ defaultOptions: {
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -32,10 +32,10 @@ declare module '@tiptap/core' {
export const inputRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))$/gm export const inputRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))$/gm
export const pasteRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))/gm export const pasteRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))/gm
export const Strike = Mark.create({ export const Strike = Mark.create<StrikeOptions>({
name: 'strike', name: 'strike',
defaultOptions: <StrikeOptions>{ defaultOptions: {
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -5,10 +5,10 @@ export interface TableCellOptions {
[key: string]: any [key: string]: any
}, },
} }
export const TableCell = Node.create({ export const TableCell = Node.create<TableCellOptions>({
name: 'tableCell', name: 'tableCell',
defaultOptions: <TableCellOptions>{ defaultOptions: {
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -5,10 +5,10 @@ export interface TableHeaderOptions {
[key: string]: any [key: string]: any
}, },
} }
export const TableHeader = Node.create({ export const TableHeader = Node.create<TableHeaderOptions>({
name: 'tableHeader', name: 'tableHeader',
defaultOptions: <TableHeaderOptions>{ defaultOptions: {
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -6,10 +6,10 @@ export interface TableRowOptions {
}, },
} }
export const TableRow = Node.create({ export const TableRow = Node.create<TableRowOptions>({
name: 'tableRow', name: 'tableRow',
defaultOptions: <TableRowOptions>{ defaultOptions: {
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -64,14 +64,16 @@ declare module '@tiptap/core' {
} }
} }
export const Table = Node.create({ export const Table = Node.create<TableOptions>({
name: 'table', name: 'table',
defaultOptions: <TableOptions>{ defaultOptions: {
HTMLAttributes: {}, HTMLAttributes: {},
resizable: false, resizable: false,
handleWidth: 5, handleWidth: 5,
cellMinWidth: 25, cellMinWidth: 25,
// TODO: fix
// @ts-ignore
View: TableView, View: TableView,
lastColumnResizable: true, lastColumnResizable: true,
allowTableNodeSelection: false, allowTableNodeSelection: false,

View File

@ -10,10 +10,10 @@ export interface TaskItemOptions {
export const inputRegex = /^\s*(\[([ |x])\])\s$/ export const inputRegex = /^\s*(\[([ |x])\])\s$/
export const TaskItem = Node.create({ export const TaskItem = Node.create<TaskItemOptions>({
name: 'taskItem', name: 'taskItem',
defaultOptions: <TaskItemOptions>{ defaultOptions: {
nested: false, nested: false,
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -15,10 +15,10 @@ declare module '@tiptap/core' {
} }
} }
export const TaskList = Node.create({ export const TaskList = Node.create<TaskListOptions>({
name: 'taskList', name: 'taskList',
defaultOptions: <TaskListOptions>{ defaultOptions: {
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -19,10 +19,10 @@ declare module '@tiptap/core' {
} }
} }
export const TextAlign = Extension.create({ export const TextAlign = Extension.create<TextAlignOptions>({
name: 'textAlign', name: 'textAlign',
defaultOptions: <TextAlignOptions>{ defaultOptions: {
types: ['heading', 'paragraph'], types: ['heading', 'paragraph'],
alignments: ['left', 'center', 'right', 'justify'], alignments: ['left', 'center', 'right', 'justify'],
defaultAlignment: 'left', defaultAlignment: 'left',

View File

@ -20,10 +20,10 @@ declare module '@tiptap/core' {
} }
} }
export const TextStyle = Mark.create({ export const TextStyle = Mark.create<TextStyleOptions>({
name: 'textStyle', name: 'textStyle',
defaultOptions: <TextStyleOptions>{ defaultOptions: {
HTMLAttributes: {}, HTMLAttributes: {},
}, },

View File

@ -23,10 +23,10 @@ declare module '@tiptap/core' {
} }
} }
export const Underline = Mark.create({ export const Underline = Mark.create<UnderlineOptions>({
name: 'underline', name: 'underline',
defaultOptions: <UnderlineOptions>{ defaultOptions: {
HTMLAttributes: {}, HTMLAttributes: {},
}, },