add AllExtensions interface
This commit is contained in:
@@ -14,7 +14,7 @@ import createStyleTag from './utils/createStyleTag'
|
|||||||
import CommandManager from './CommandManager'
|
import CommandManager from './CommandManager'
|
||||||
import ExtensionManager from './ExtensionManager'
|
import ExtensionManager from './ExtensionManager'
|
||||||
import EventEmitter from './EventEmitter'
|
import EventEmitter from './EventEmitter'
|
||||||
import { Extensions } from './types'
|
import { Extensions, UnionToIntersection, PickValue } from './types'
|
||||||
import defaultPlugins from './plugins'
|
import defaultPlugins from './plugins'
|
||||||
import * as coreCommands from './commands'
|
import * as coreCommands from './commands'
|
||||||
import style from './style'
|
import style from './style'
|
||||||
@@ -35,19 +35,13 @@ export interface CommandsSpec {
|
|||||||
[key: string]: CommandSpec
|
[key: string]: CommandSpec
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Commands {}
|
export interface AllExtensions {}
|
||||||
|
|
||||||
export type CommandNames = Extract<keyof Commands, string>
|
export type SingleCommands = UnionToIntersection<ReturnType<PickValue<ReturnType<AllExtensions[keyof AllExtensions]>, 'addCommands'>>>
|
||||||
|
|
||||||
export type SingleCommands = {
|
|
||||||
[Item in keyof Commands]: Commands[Item] extends (...args: any[]) => any
|
|
||||||
? (...args: Parameters<Commands[Item]>) => boolean
|
|
||||||
: never
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ChainedCommands = {
|
export type ChainedCommands = {
|
||||||
[Item in keyof Commands]: Commands[Item] extends (...args: any[]) => any
|
[Item in keyof SingleCommands]: SingleCommands[Item] extends (...args: any[]) => any
|
||||||
? (...args: Parameters<Commands[Item]>) => ChainedCommands
|
? (...args: Parameters<SingleCommands[Item]>) => ChainedCommands
|
||||||
: never
|
: never
|
||||||
} & {
|
} & {
|
||||||
run: () => boolean
|
run: () => boolean
|
||||||
|
|||||||
@@ -27,3 +27,9 @@ export type GlobalAttributes = {
|
|||||||
types: string[],
|
types: string[],
|
||||||
attributes: Attributes,
|
attributes: Attributes,
|
||||||
}[]
|
}[]
|
||||||
|
|
||||||
|
export type PickValue<T, K extends keyof T> = T[K]
|
||||||
|
|
||||||
|
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I)=>void)
|
||||||
|
? I
|
||||||
|
: never
|
||||||
|
|||||||
@@ -1,17 +1,9 @@
|
|||||||
import { Command, createNode } from '@tiptap/core'
|
import { Command, createNode } from '@tiptap/core'
|
||||||
import { wrappingInputRule } from 'prosemirror-inputrules'
|
import { wrappingInputRule } from 'prosemirror-inputrules'
|
||||||
|
|
||||||
// export type BlockquoteCommand = () => Command
|
|
||||||
|
|
||||||
// declare module '@tiptap/core/src/Editor' {
|
|
||||||
// interface Commands {
|
|
||||||
// blockquote: BlockquoteCommand,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
export const inputRegex = /^\s*>\s$/gm
|
export const inputRegex = /^\s*>\s$/gm
|
||||||
|
|
||||||
export default createNode({
|
const Blockquote = createNode({
|
||||||
name: 'blockquote',
|
name: 'blockquote',
|
||||||
|
|
||||||
content: 'block*',
|
content: 'block*',
|
||||||
@@ -32,7 +24,7 @@ export default createNode({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
blockquote: () => ({ commands }) => {
|
blockquote: (): Command => ({ commands }) => {
|
||||||
return commands.toggleWrap('blockquote')
|
return commands.toggleWrap('blockquote')
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -50,3 +42,11 @@ export default createNode({
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default Blockquote
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
Blockquote: typeof Blockquote,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ 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 default createMark({
|
const Bold = createMark({
|
||||||
name: 'bold',
|
name: 'bold',
|
||||||
|
|
||||||
parseHTML() {
|
parseHTML() {
|
||||||
@@ -40,7 +40,10 @@ export default createMark({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
bold: () => ({ commands }) => {
|
/**
|
||||||
|
* bold command
|
||||||
|
*/
|
||||||
|
bold: (): Command => ({ commands }) => {
|
||||||
return commands.toggleMark('bold')
|
return commands.toggleMark('bold')
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -66,3 +69,11 @@ export default createMark({
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default Bold
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
Bold: typeof Bold,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,15 +1,7 @@
|
|||||||
import { Command, createNode } from '@tiptap/core'
|
import { Command, createNode } from '@tiptap/core'
|
||||||
import { wrappingInputRule } from 'prosemirror-inputrules'
|
import { wrappingInputRule } from 'prosemirror-inputrules'
|
||||||
|
|
||||||
// export type BulletListCommand = () => Command
|
const BulletList = createNode({
|
||||||
|
|
||||||
// declare module '@tiptap/core/src/Editor' {
|
|
||||||
// interface Commands {
|
|
||||||
// bulletList: BulletListCommand,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
export default createNode({
|
|
||||||
name: 'bullet_list',
|
name: 'bullet_list',
|
||||||
|
|
||||||
content: 'list_item+',
|
content: 'list_item+',
|
||||||
@@ -28,7 +20,7 @@ export default createNode({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
bulletList: () => ({ commands }) => {
|
bulletList: (): Command => ({ commands }) => {
|
||||||
return commands.toggleList('bullet_list', 'list_item')
|
return commands.toggleList('bullet_list', 'list_item')
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -46,3 +38,11 @@ export default createNode({
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default BulletList
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
BulletList: typeof BulletList,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,18 +5,10 @@ export interface CodeBlockOptions {
|
|||||||
languageClassPrefix: string,
|
languageClassPrefix: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
// export type CodeBlockCommand = () => Command
|
|
||||||
|
|
||||||
// declare module '@tiptap/core/src/Editor' {
|
|
||||||
// interface Commands {
|
|
||||||
// codeBlock: CodeBlockCommand,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
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 default createNode({
|
const CodeBlock = createNode({
|
||||||
name: 'code_block',
|
name: 'code_block',
|
||||||
|
|
||||||
defaultOptions: <CodeBlockOptions>{
|
defaultOptions: <CodeBlockOptions>{
|
||||||
@@ -70,7 +62,7 @@ export default createNode({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
codeBlock: attrs => ({ commands }) => {
|
codeBlock: (attrs?: CodeBlockOptions): Command => ({ commands }) => {
|
||||||
return commands.toggleBlockType('code_block', 'paragraph', attrs)
|
return commands.toggleBlockType('code_block', 'paragraph', attrs)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -89,3 +81,11 @@ export default createNode({
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default CodeBlock
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
CodeBlock: typeof CodeBlock,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,18 +2,10 @@ import {
|
|||||||
Command, createMark, markInputRule, markPasteRule,
|
Command, createMark, markInputRule, markPasteRule,
|
||||||
} from '@tiptap/core'
|
} from '@tiptap/core'
|
||||||
|
|
||||||
// export type CodeCommand = () => Command
|
|
||||||
|
|
||||||
// declare module '@tiptap/core/src/Editor' {
|
|
||||||
// interface Commands {
|
|
||||||
// code: CodeCommand,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
export const inputRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))$/gm
|
export const inputRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))$/gm
|
||||||
export const pasteRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))/gm
|
export const pasteRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))/gm
|
||||||
|
|
||||||
export default createMark({
|
const Code = createMark({
|
||||||
name: 'code',
|
name: 'code',
|
||||||
|
|
||||||
excludes: '_',
|
excludes: '_',
|
||||||
@@ -30,7 +22,7 @@ export default createMark({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
code: () => ({ commands }) => {
|
code: (): Command => ({ commands }) => {
|
||||||
return commands.toggleMark('code')
|
return commands.toggleMark('code')
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -54,3 +46,11 @@ export default createMark({
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default Code
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
Code: typeof Code,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,18 +8,7 @@ export interface CollaborationCursorOptions {
|
|||||||
render (user: { name: string, color: string }): HTMLElement,
|
render (user: { name: string, color: string }): HTMLElement,
|
||||||
}
|
}
|
||||||
|
|
||||||
// export type UserCommand = (attributes: {
|
const CollaborationCursor = createExtension({
|
||||||
// name: string,
|
|
||||||
// color: string,
|
|
||||||
// }) => Command
|
|
||||||
|
|
||||||
// declare module '@tiptap/core/src/Editor' {
|
|
||||||
// interface Commands {
|
|
||||||
// user: UserCommand,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
export default createExtension({
|
|
||||||
name: 'collaboration_cursor',
|
name: 'collaboration_cursor',
|
||||||
|
|
||||||
defaultOptions: <CollaborationCursorOptions>{
|
defaultOptions: <CollaborationCursorOptions>{
|
||||||
@@ -43,7 +32,10 @@ export default createExtension({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
user: attributes => () => {
|
user: (attributes: {
|
||||||
|
name: string,
|
||||||
|
color: string,
|
||||||
|
}): Command => () => {
|
||||||
this.options.provider.awareness.setLocalStateField('user', attributes)
|
this.options.provider.awareness.setLocalStateField('user', attributes)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@@ -68,3 +60,11 @@ export default createExtension({
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default CollaborationCursor
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
CollaborationCursor: typeof CollaborationCursor,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export interface CollaborationOptions {
|
|||||||
type: any,
|
type: any,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default createExtension({
|
const Collaboration = createExtension({
|
||||||
name: 'collaboration',
|
name: 'collaboration',
|
||||||
|
|
||||||
defaultOptions: <CollaborationOptions>{
|
defaultOptions: <CollaborationOptions>{
|
||||||
@@ -31,3 +31,11 @@ export default createExtension({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default Collaboration
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
Collaboration: typeof Collaboration,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,15 @@
|
|||||||
import { createNode } from '@tiptap/core'
|
import { createNode } from '@tiptap/core'
|
||||||
|
|
||||||
export default createNode({
|
const Document = createNode({
|
||||||
name: 'document',
|
name: 'document',
|
||||||
topNode: true,
|
topNode: true,
|
||||||
content: 'block+',
|
content: 'block+',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default Document
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
Document: typeof Document,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export interface FocusOptions {
|
|||||||
nested: boolean,
|
nested: boolean,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default createExtension({
|
const Focus = createExtension({
|
||||||
name: 'focus',
|
name: 'focus',
|
||||||
|
|
||||||
defaultOptions: <FocusOptions>{
|
defaultOptions: <FocusOptions>{
|
||||||
@@ -48,3 +48,11 @@ export default createExtension({
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default Focus
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
Focus: typeof Focus,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,15 +1,7 @@
|
|||||||
import { Command, createNode } from '@tiptap/core'
|
import { Command, createNode } from '@tiptap/core'
|
||||||
import { chainCommands, exitCode } from 'prosemirror-commands'
|
import { chainCommands, exitCode } from 'prosemirror-commands'
|
||||||
|
|
||||||
// export type HardBreakCommand = () => Command
|
const HardBreak = createNode({
|
||||||
|
|
||||||
// declare module '@tiptap/core/src/Editor' {
|
|
||||||
// interface Commands {
|
|
||||||
// hardBreak: HardBreakCommand,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
export default createNode({
|
|
||||||
name: 'hardBreak',
|
name: 'hardBreak',
|
||||||
|
|
||||||
inline: true,
|
inline: true,
|
||||||
@@ -30,7 +22,7 @@ export default createNode({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
hardBreak: () => ({
|
hardBreak: (): Command => ({
|
||||||
tr, state, dispatch, view,
|
tr, state, dispatch, view,
|
||||||
}) => {
|
}) => {
|
||||||
return chainCommands(exitCode, () => {
|
return chainCommands(exitCode, () => {
|
||||||
@@ -48,3 +40,11 @@ export default createNode({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default HardBreak
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
HardBreak: typeof HardBreak,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,15 +7,7 @@ export interface HeadingOptions {
|
|||||||
levels: Level[],
|
levels: Level[],
|
||||||
}
|
}
|
||||||
|
|
||||||
// export type HeadingCommand = (options: { level: Level }) => Command
|
const Heading = createNode({
|
||||||
|
|
||||||
// declare module '@tiptap/core/src/Editor' {
|
|
||||||
// interface Commands {
|
|
||||||
// heading: HeadingCommand,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
export default createNode({
|
|
||||||
name: 'heading',
|
name: 'heading',
|
||||||
|
|
||||||
defaultOptions: <HeadingOptions>{
|
defaultOptions: <HeadingOptions>{
|
||||||
@@ -51,8 +43,11 @@ export default createNode({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
heading: attrs => ({ commands }) => {
|
/**
|
||||||
return commands.toggleBlockType('heading', 'paragraph', attrs)
|
* heading command
|
||||||
|
*/
|
||||||
|
heading: (options: { level: Level }): Command => ({ commands }) => {
|
||||||
|
return commands.toggleBlockType('heading', 'paragraph', options)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -72,3 +67,11 @@ export default createNode({
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default Heading
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
Heading: typeof Heading,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,23 +1,12 @@
|
|||||||
import { Command, createExtension } from '@tiptap/core'
|
import { Command, createExtension } from '@tiptap/core'
|
||||||
import {
|
import { history, undo, redo } from 'prosemirror-history'
|
||||||
history,
|
|
||||||
undo,
|
|
||||||
redo,
|
|
||||||
} from 'prosemirror-history'
|
|
||||||
|
|
||||||
// declare module '@tiptap/core/src/Editor' {
|
|
||||||
// interface Commands {
|
|
||||||
// undo: () => Command,
|
|
||||||
// redo: () => Command,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
export interface HistoryOptions {
|
export interface HistoryOptions {
|
||||||
depth: number,
|
depth: number,
|
||||||
newGroupDelay: number,
|
newGroupDelay: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default createExtension({
|
const History = createExtension({
|
||||||
name: 'history',
|
name: 'history',
|
||||||
|
|
||||||
defaultOptions: <HistoryOptions>{
|
defaultOptions: <HistoryOptions>{
|
||||||
@@ -27,10 +16,10 @@ export default createExtension({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
undo: () => ({ state, dispatch }) => {
|
undo: (): Command => ({ state, dispatch }) => {
|
||||||
return undo(state, dispatch)
|
return undo(state, dispatch)
|
||||||
},
|
},
|
||||||
redo: () => ({ state, dispatch }) => {
|
redo: (): Command => ({ state, dispatch }) => {
|
||||||
return redo(state, dispatch)
|
return redo(state, dispatch)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -50,3 +39,11 @@ export default createExtension({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default History
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
History: typeof History,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,14 +1,6 @@
|
|||||||
import { Command, createNode, nodeInputRule } from '@tiptap/core'
|
import { Command, createNode, nodeInputRule } from '@tiptap/core'
|
||||||
|
|
||||||
// export type HorizontalRuleCommand = () => Command
|
const HorizontalRule = createNode({
|
||||||
|
|
||||||
// declare module '@tiptap/core/src/Editor' {
|
|
||||||
// interface Commands {
|
|
||||||
// horizontalRule: HorizontalRuleCommand,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
export default createNode({
|
|
||||||
name: 'horizontalRule',
|
name: 'horizontalRule',
|
||||||
|
|
||||||
group: 'block',
|
group: 'block',
|
||||||
@@ -25,7 +17,7 @@ export default createNode({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
horizontalRule: () => ({ tr }) => {
|
horizontalRule: (): Command => ({ tr }) => {
|
||||||
tr.replaceSelectionWith(this.type.create())
|
tr.replaceSelectionWith(this.type.create())
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@@ -39,3 +31,11 @@ export default createNode({
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default HorizontalRule
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
HorizontalRule: typeof HorizontalRule,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,20 +2,12 @@ import {
|
|||||||
Command, createMark, markInputRule, markPasteRule,
|
Command, createMark, markInputRule, markPasteRule,
|
||||||
} from '@tiptap/core'
|
} from '@tiptap/core'
|
||||||
|
|
||||||
// export type ItalicCommand = () => Command
|
|
||||||
|
|
||||||
// declare module '@tiptap/core/src/Editor' {
|
|
||||||
// interface Commands {
|
|
||||||
// italic: ItalicCommand,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
export const starInputRegex = /(?:^|\s)((?:\*)((?:[^*]+))(?:\*))$/gm
|
export const starInputRegex = /(?:^|\s)((?:\*)((?:[^*]+))(?:\*))$/gm
|
||||||
export const starPasteRegex = /(?:^|\s)((?:\*)((?:[^*]+))(?:\*))/gm
|
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 default createMark({
|
const Italic = createMark({
|
||||||
name: 'italic',
|
name: 'italic',
|
||||||
|
|
||||||
parseHTML() {
|
parseHTML() {
|
||||||
@@ -39,7 +31,7 @@ export default createMark({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
italic: () => ({ commands }) => {
|
italic: (): Command => ({ commands }) => {
|
||||||
return commands.toggleMark('italic')
|
return commands.toggleMark('italic')
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -65,3 +57,11 @@ export default createMark({
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default Italic
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
Italic: typeof Italic,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,17 +9,9 @@ export interface LinkOptions {
|
|||||||
rel: string,
|
rel: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
// export type LinkCommand = (options: {href?: string, target?: string}) => Command
|
|
||||||
|
|
||||||
// declare module '@tiptap/core/src/Editor' {
|
|
||||||
// interface Commands {
|
|
||||||
// link: LinkCommand,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
export const pasteRegex = /https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,}\b(?:[-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@:%_+.~#?&//=]*)/gi
|
||||||
|
|
||||||
export default createMark({
|
const Link = createMark({
|
||||||
name: 'link',
|
name: 'link',
|
||||||
|
|
||||||
inclusive: false,
|
inclusive: false,
|
||||||
@@ -66,12 +58,12 @@ export default createMark({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
link: attributes => ({ commands }) => {
|
link: (options: { href?: string, target?: string }): Command => ({ commands }) => {
|
||||||
if (!attributes.href) {
|
if (!options.href) {
|
||||||
return commands.removeMark('link')
|
return commands.removeMark('link')
|
||||||
}
|
}
|
||||||
|
|
||||||
return commands.updateMark('link', attributes)
|
return commands.updateMark('link', options)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -113,3 +105,11 @@ export default createMark({
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default Link
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
Link: typeof Link,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createNode } from '@tiptap/core'
|
import { createNode } from '@tiptap/core'
|
||||||
|
|
||||||
export default createNode({
|
const ListItem = createNode({
|
||||||
name: 'list_item',
|
name: 'list_item',
|
||||||
|
|
||||||
content: 'paragraph block*',
|
content: 'paragraph block*',
|
||||||
@@ -25,3 +25,11 @@ export default createNode({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default ListItem
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
ListItem: typeof ListItem,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,15 +1,7 @@
|
|||||||
import { Command, createNode } from '@tiptap/core'
|
import { Command, createNode } from '@tiptap/core'
|
||||||
import { wrappingInputRule } from 'prosemirror-inputrules'
|
import { wrappingInputRule } from 'prosemirror-inputrules'
|
||||||
|
|
||||||
// export type OrderedListCommand = () => Command
|
const OrderedList = createNode({
|
||||||
|
|
||||||
// declare module '@tiptap/core/src/Editor' {
|
|
||||||
// interface Commands {
|
|
||||||
// orderedList: OrderedListCommand,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
export default createNode({
|
|
||||||
name: 'ordered_list',
|
name: 'ordered_list',
|
||||||
|
|
||||||
content: 'list_item+',
|
content: 'list_item+',
|
||||||
@@ -46,7 +38,7 @@ export default createNode({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
orderedList: () => ({ commands }) => {
|
orderedList: (): Command => ({ commands }) => {
|
||||||
return commands.toggleList('ordered_list', 'list_item')
|
return commands.toggleList('ordered_list', 'list_item')
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -69,3 +61,11 @@ export default createNode({
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default OrderedList
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
OrderedList: typeof OrderedList,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,15 +1,7 @@
|
|||||||
import { createNode } from '@tiptap/core'
|
import { Command, createNode } from '@tiptap/core'
|
||||||
// import ParagraphComponent from './paragraph.vue'
|
// import ParagraphComponent from './paragraph.vue'
|
||||||
|
|
||||||
// export type ParagraphCommand = () => Command
|
const Paragraph = createNode({
|
||||||
|
|
||||||
// declare module '@tiptap/core/src/Editor' {
|
|
||||||
// interface Commands {
|
|
||||||
// paragraph: ParagraphCommand,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
export default createNode({
|
|
||||||
name: 'paragraph',
|
name: 'paragraph',
|
||||||
|
|
||||||
group: 'block',
|
group: 'block',
|
||||||
@@ -58,7 +50,7 @@ export default createNode({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
paragraph: () => ({ commands }) => {
|
paragraph: (): Command => ({ commands }) => {
|
||||||
return commands.toggleBlockType('paragraph', 'paragraph')
|
return commands.toggleBlockType('paragraph', 'paragraph')
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -70,3 +62,11 @@ export default createNode({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default Paragraph
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
Paragraph: typeof Paragraph,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,18 +2,10 @@ import {
|
|||||||
Command, createMark, markInputRule, markPasteRule,
|
Command, createMark, markInputRule, markPasteRule,
|
||||||
} from '@tiptap/core'
|
} from '@tiptap/core'
|
||||||
|
|
||||||
// type StrikeCommand = () => Command
|
|
||||||
|
|
||||||
// declare module '@tiptap/core/src/Editor' {
|
|
||||||
// interface Commands {
|
|
||||||
// strike: StrikeCommand,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
export const inputRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))$/gm
|
export const inputRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))$/gm
|
||||||
export const pasteRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))/gm
|
export const pasteRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))/gm
|
||||||
|
|
||||||
export default createMark({
|
const Strike = createMark({
|
||||||
name: 'strike',
|
name: 'strike',
|
||||||
|
|
||||||
parseHTML() {
|
parseHTML() {
|
||||||
@@ -40,7 +32,7 @@ export default createMark({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
strike: () => ({ commands }) => {
|
strike: (): Command => ({ commands }) => {
|
||||||
return commands.toggleMark('strike')
|
return commands.toggleMark('strike')
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -64,3 +56,11 @@ export default createMark({
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default Strike
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
Strike: typeof Strike,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
import { createNode } from '@tiptap/core'
|
import { createNode } from '@tiptap/core'
|
||||||
|
|
||||||
export default createNode({
|
const Text = createNode({
|
||||||
name: 'text',
|
name: 'text',
|
||||||
group: 'inline',
|
group: 'inline',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default Text
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
Text: typeof Text,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,14 +1,6 @@
|
|||||||
import { Command, createMark } from '@tiptap/core'
|
import { Command, createMark } from '@tiptap/core'
|
||||||
|
|
||||||
// export type UnderlineCommand = () => Command
|
const Underline = createMark({
|
||||||
|
|
||||||
// declare module '@tiptap/core/src/Editor' {
|
|
||||||
// interface Commands {
|
|
||||||
// underline: UnderlineCommand,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
export default createMark({
|
|
||||||
name: 'underline',
|
name: 'underline',
|
||||||
|
|
||||||
parseHTML() {
|
parseHTML() {
|
||||||
@@ -29,7 +21,7 @@ export default createMark({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
underline: () => ({ commands }) => {
|
underline: (): Command => ({ commands }) => {
|
||||||
return commands.toggleMark('underline')
|
return commands.toggleMark('underline')
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -41,3 +33,11 @@ export default createMark({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default Underline
|
||||||
|
|
||||||
|
declare module '@tiptap/core/src/Editor' {
|
||||||
|
interface AllExtensions {
|
||||||
|
Underline: typeof Underline,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user