mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-06 00:42:59 +08:00
add Commands interface
This commit is contained in:
parent
0ed368e9f4
commit
290ff76e37
@ -68,6 +68,8 @@ module.exports = {
|
||||
'no-dupe-class-members': 'off',
|
||||
'@typescript-eslint/no-dupe-class-members': ['error'],
|
||||
'lines-between-class-members': 'off',
|
||||
'no-shadow': 'off',
|
||||
'@typescript-eslint/no-shadow': ['error'],
|
||||
'@typescript-eslint/lines-between-class-members': ['error'],
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-empty-interface': 'off',
|
||||
|
@ -27,9 +27,3 @@ export const ColorHighlighter = Extension.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
ColorHighlighter: typeof ColorHighlighter,
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,13 @@ export interface AnnotationOptions {
|
||||
onUpdate: (items: [any?]) => {},
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
addAnnotation: (content: any) => Command,
|
||||
deleteAnnotation: (id: number) => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const Annotation = Extension.create({
|
||||
name: 'annotation',
|
||||
|
||||
@ -25,7 +32,7 @@ export const Annotation = Extension.create({
|
||||
|
||||
addCommands() {
|
||||
return {
|
||||
addAnnotation: (content: any): Command => ({ dispatch, state }) => {
|
||||
addAnnotation: (content: any) => ({ dispatch, state }) => {
|
||||
const { selection } = state
|
||||
|
||||
if (selection.empty) {
|
||||
@ -46,7 +53,7 @@ export const Annotation = Extension.create({
|
||||
|
||||
return true
|
||||
},
|
||||
deleteAnnotation: (id: number): Command => ({ dispatch, state }) => {
|
||||
deleteAnnotation: (id: number) => ({ dispatch, state }) => {
|
||||
if (dispatch) {
|
||||
dispatch(state.tr.setMeta(AnnotationPluginKey, { type: 'deleteAnnotation', id }))
|
||||
}
|
||||
@ -62,9 +69,3 @@ export const Annotation = Extension.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Annotation: typeof Annotation,
|
||||
}
|
||||
}
|
||||
|
@ -60,9 +60,3 @@ export const Color = Extension.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Color: typeof Color,
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,12 @@ export interface IframeOptions {
|
||||
},
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setIframe: (options: { src: string }) => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export default Node.create({
|
||||
name: 'iframe',
|
||||
|
||||
@ -55,7 +61,7 @@ export default Node.create({
|
||||
/**
|
||||
* Add an iframe
|
||||
*/
|
||||
setIframe: (options: { src: string }): Command => ({ tr, dispatch }) => {
|
||||
setIframe: (options: { src: string }) => ({ tr, dispatch }) => {
|
||||
const { selection } = tr
|
||||
const node = this.type.create(options)
|
||||
|
||||
|
@ -90,9 +90,3 @@ export const Linter = Extension.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Linter: typeof Linter,
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import {
|
||||
EditorOptions,
|
||||
EditorContent,
|
||||
CommandSpec,
|
||||
Commands,
|
||||
CanCommands,
|
||||
ChainedCommands,
|
||||
SingleCommands,
|
||||
|
@ -2,9 +2,9 @@ import { Plugin, Transaction } from 'prosemirror-state'
|
||||
import { InputRule } from 'prosemirror-inputrules'
|
||||
import { Editor } from './Editor'
|
||||
import mergeDeep from './utilities/mergeDeep'
|
||||
import { GlobalAttributes } from './types'
|
||||
import { GlobalAttributes, Commands } from './types'
|
||||
|
||||
export interface ExtensionConfig<Options = any, Commands = {}> {
|
||||
export interface ExtensionConfig<Options = any> {
|
||||
/**
|
||||
* Name
|
||||
*/
|
||||
@ -28,7 +28,7 @@ export interface ExtensionConfig<Options = any, Commands = {}> {
|
||||
addCommands?: (this: {
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
}) => Commands,
|
||||
}) => Partial<Commands>,
|
||||
|
||||
/**
|
||||
* Keyboard shortcuts
|
||||
@ -136,7 +136,7 @@ export interface ExtensionConfig<Options = any, Commands = {}> {
|
||||
}) => void) | null,
|
||||
}
|
||||
|
||||
export class Extension<Options = any, Commands = any> {
|
||||
export class Extension<Options = any> {
|
||||
type = 'extension'
|
||||
|
||||
config: Required<ExtensionConfig> = {
|
||||
@ -159,7 +159,7 @@ export class Extension<Options = any, Commands = any> {
|
||||
|
||||
options!: Options
|
||||
|
||||
constructor(config: ExtensionConfig<Options, Commands>) {
|
||||
constructor(config: ExtensionConfig<Options>) {
|
||||
this.config = {
|
||||
...this.config,
|
||||
...config,
|
||||
@ -168,13 +168,13 @@ export class Extension<Options = any, Commands = any> {
|
||||
this.options = this.config.defaultOptions
|
||||
}
|
||||
|
||||
static create<O, C>(config: ExtensionConfig<O, C>) {
|
||||
return new Extension<O, C>(config)
|
||||
static create<O>(config: ExtensionConfig<O>) {
|
||||
return new Extension<O>(config)
|
||||
}
|
||||
|
||||
configure(options: Partial<Options> = {}) {
|
||||
return Extension
|
||||
.create<Options, Commands>(this.config as ExtensionConfig<Options, Commands>)
|
||||
.create<Options>(this.config as ExtensionConfig<Options>)
|
||||
.#configure(options)
|
||||
}
|
||||
|
||||
@ -184,10 +184,10 @@ export class Extension<Options = any, Commands = any> {
|
||||
return this
|
||||
}
|
||||
|
||||
extend<ExtendedOptions = Options, ExtendedCommands = Commands>(extendedConfig: Partial<ExtensionConfig<ExtendedOptions, ExtendedCommands>>) {
|
||||
return new Extension<ExtendedOptions, ExtendedCommands>({
|
||||
extend<ExtendedOptions = Options>(extendedConfig: Partial<ExtensionConfig<ExtendedOptions>>) {
|
||||
return new Extension<ExtendedOptions>({
|
||||
...this.config,
|
||||
...extendedConfig,
|
||||
} as ExtensionConfig<ExtendedOptions, ExtendedCommands>)
|
||||
} as ExtensionConfig<ExtendedOptions>)
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ export default class ExtensionManager {
|
||||
|
||||
const commands = extension.config.addCommands.bind(context)()
|
||||
|
||||
// @ts-ignore
|
||||
editor.registerCommands(commands)
|
||||
|
||||
if (typeof extension.config.onCreate === 'function') {
|
||||
|
@ -8,10 +8,10 @@ import { Plugin, Transaction } from 'prosemirror-state'
|
||||
import { InputRule } from 'prosemirror-inputrules'
|
||||
import { ExtensionConfig } from './Extension'
|
||||
import mergeDeep from './utilities/mergeDeep'
|
||||
import { Attributes, Overwrite } from './types'
|
||||
import { Attributes, Overwrite, Commands } from './types'
|
||||
import { Editor } from './Editor'
|
||||
|
||||
export interface MarkConfig<Options = any, Commands = {}> extends Overwrite<ExtensionConfig<Options, Commands>, {
|
||||
export interface MarkConfig<Options = any> extends Overwrite<ExtensionConfig<Options>, {
|
||||
/**
|
||||
* Inclusive
|
||||
*/
|
||||
@ -70,7 +70,7 @@ export interface MarkConfig<Options = any, Commands = {}> extends Overwrite<Exte
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
type: MarkType,
|
||||
}) => Commands,
|
||||
}) => Partial<Commands>,
|
||||
|
||||
/**
|
||||
* Keyboard shortcuts
|
||||
@ -189,7 +189,7 @@ export interface MarkConfig<Options = any, Commands = {}> extends Overwrite<Exte
|
||||
}) => void) | null,
|
||||
}> {}
|
||||
|
||||
export class Mark<Options = any, Commands = {}> {
|
||||
export class Mark<Options = any> {
|
||||
type = 'mark'
|
||||
|
||||
config: Required<MarkConfig> = {
|
||||
@ -219,7 +219,7 @@ export class Mark<Options = any, Commands = {}> {
|
||||
|
||||
options!: Options
|
||||
|
||||
constructor(config: MarkConfig<Options, Commands>) {
|
||||
constructor(config: MarkConfig<Options>) {
|
||||
this.config = {
|
||||
...this.config,
|
||||
...config,
|
||||
@ -228,13 +228,13 @@ export class Mark<Options = any, Commands = {}> {
|
||||
this.options = this.config.defaultOptions
|
||||
}
|
||||
|
||||
static create<O, C>(config: MarkConfig<O, C>) {
|
||||
return new Mark<O, C>(config)
|
||||
static create<O>(config: MarkConfig<O>) {
|
||||
return new Mark<O>(config)
|
||||
}
|
||||
|
||||
configure(options: Partial<Options> = {}) {
|
||||
return Mark
|
||||
.create<Options, Commands>(this.config as MarkConfig<Options, Commands>)
|
||||
.create<Options>(this.config as MarkConfig<Options>)
|
||||
.#configure(options)
|
||||
}
|
||||
|
||||
@ -244,10 +244,10 @@ export class Mark<Options = any, Commands = {}> {
|
||||
return this
|
||||
}
|
||||
|
||||
extend<ExtendedOptions = Options, ExtendedCommands = Commands>(extendedConfig: Partial<MarkConfig<ExtendedOptions, ExtendedCommands>>) {
|
||||
return new Mark<ExtendedOptions, ExtendedCommands>({
|
||||
extend<ExtendedOptions = Options>(extendedConfig: Partial<MarkConfig<ExtendedOptions>>) {
|
||||
return new Mark<ExtendedOptions>({
|
||||
...this.config,
|
||||
...extendedConfig,
|
||||
} as MarkConfig<ExtendedOptions, ExtendedCommands>)
|
||||
} as MarkConfig<ExtendedOptions>)
|
||||
}
|
||||
}
|
||||
|
@ -9,10 +9,12 @@ import { Plugin, Transaction } from 'prosemirror-state'
|
||||
import { InputRule } from 'prosemirror-inputrules'
|
||||
import { ExtensionConfig } from './Extension'
|
||||
import mergeDeep from './utilities/mergeDeep'
|
||||
import { Attributes, NodeViewRenderer, Overwrite } from './types'
|
||||
import {
|
||||
Attributes, NodeViewRenderer, Overwrite, Commands,
|
||||
} from './types'
|
||||
import { Editor } from './Editor'
|
||||
|
||||
export interface NodeConfig<Options = any, Commands = {}> extends Overwrite<ExtensionConfig<Options, Commands>, {
|
||||
export interface NodeConfig<Options = any> extends Overwrite<ExtensionConfig<Options>, {
|
||||
/**
|
||||
* TopNode
|
||||
*/
|
||||
@ -125,7 +127,7 @@ export interface NodeConfig<Options = any, Commands = {}> extends Overwrite<Exte
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
type: NodeType,
|
||||
}) => Commands,
|
||||
}) => Partial<Commands>,
|
||||
|
||||
/**
|
||||
* Keyboard shortcuts
|
||||
@ -135,7 +137,8 @@ export interface NodeConfig<Options = any, Commands = {}> extends Overwrite<Exte
|
||||
editor: Editor,
|
||||
type: NodeType,
|
||||
}) => {
|
||||
[key: string]: any
|
||||
// [key: string]: any
|
||||
[key: string]: () => boolean
|
||||
},
|
||||
|
||||
/**
|
||||
@ -253,7 +256,7 @@ export interface NodeConfig<Options = any, Commands = {}> extends Overwrite<Exte
|
||||
}) => void) | null,
|
||||
}> {}
|
||||
|
||||
export class Node<Options = any, Commands = {}> {
|
||||
export class Node<Options = any> {
|
||||
type = 'node'
|
||||
|
||||
config: Required<NodeConfig> = {
|
||||
@ -292,7 +295,7 @@ export class Node<Options = any, Commands = {}> {
|
||||
|
||||
options!: Options
|
||||
|
||||
constructor(config: NodeConfig<Options, Commands>) {
|
||||
constructor(config: NodeConfig<Options>) {
|
||||
this.config = {
|
||||
...this.config,
|
||||
...config,
|
||||
@ -301,13 +304,13 @@ export class Node<Options = any, Commands = {}> {
|
||||
this.options = this.config.defaultOptions
|
||||
}
|
||||
|
||||
static create<O, C>(config: NodeConfig<O, C>) {
|
||||
return new Node<O, C>(config)
|
||||
static create<O>(config: NodeConfig<O>) {
|
||||
return new Node<O>(config)
|
||||
}
|
||||
|
||||
configure(options: Partial<Options> = {}) {
|
||||
return Node
|
||||
.create<Options, Commands>(this.config as NodeConfig<Options, Commands>)
|
||||
.create<Options>(this.config as NodeConfig<Options>)
|
||||
.#configure(options)
|
||||
}
|
||||
|
||||
@ -317,10 +320,10 @@ export class Node<Options = any, Commands = {}> {
|
||||
return this
|
||||
}
|
||||
|
||||
extend<ExtendedOptions = Options, ExtendedCommands = Commands>(extendedConfig: Partial<NodeConfig<ExtendedOptions, ExtendedCommands>>) {
|
||||
return new Node<ExtendedOptions, ExtendedCommands>({
|
||||
extend<ExtendedOptions = Options>(extendedConfig: Partial<NodeConfig<ExtendedOptions>>) {
|
||||
return new Node<ExtendedOptions>({
|
||||
...this.config,
|
||||
...extendedConfig,
|
||||
} as NodeConfig<ExtendedOptions, ExtendedCommands>)
|
||||
} as NodeConfig<ExtendedOptions>)
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,18 @@
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Removes focus from the editor.
|
||||
*/
|
||||
export const blur = (): Command => ({ view }) => {
|
||||
export const blur: Commands['blur'] = () => ({ view }) => {
|
||||
const element = view.dom as HTMLElement
|
||||
|
||||
element.blur()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
blur: () => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,14 @@
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Clear the whole document.
|
||||
*/
|
||||
export const clearContent = (emitUpdate: Boolean = false): Command => ({ commands }) => {
|
||||
export const clearContent: Commands['clearContent'] = (emitUpdate = false) => ({ commands }) => {
|
||||
return commands.setContent('', emitUpdate)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
clearContent: (emitUpdate: Boolean) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { liftTarget } from 'prosemirror-transform'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Normalize nodes to a simple paragraph.
|
||||
*/
|
||||
export const clearNodes = (): Command => ({ state, tr, dispatch }) => {
|
||||
export const clearNodes: Commands['clearNodes'] = () => ({ state, tr, dispatch }) => {
|
||||
const { selection } = tr
|
||||
const { from, to } = selection
|
||||
|
||||
@ -30,3 +30,9 @@ export const clearNodes = (): Command => ({ state, tr, dispatch }) => {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
clearNodes: () => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,14 @@
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Define a command inline.
|
||||
*/
|
||||
export const command = (fn: (props: Parameters<Command>[0]) => boolean): Command => props => {
|
||||
export const command: Commands['command'] = fn => props => {
|
||||
return fn(props)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
command: (fn: (props: Parameters<Command>[0]) => boolean) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,15 @@
|
||||
import { createParagraphNear as originalCreateParagraphNear } from 'prosemirror-commands'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Create a paragraph nearby.
|
||||
*/
|
||||
export const createParagraphNear = (): Command => ({ state, dispatch }) => {
|
||||
export const createParagraphNear: Commands['createParagraphNear'] = () => ({ state, dispatch }) => {
|
||||
return originalCreateParagraphNear(state, dispatch)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
createParagraphNear: () => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { Command, Range } from '../types'
|
||||
import { Command, Commands, Range } from '../types'
|
||||
|
||||
/**
|
||||
* Delete a given range.
|
||||
*/
|
||||
export const deleteRange = (range: Range): Command => ({ tr, dispatch }) => {
|
||||
export const deleteRange: Commands['deleteRange'] = range => ({ tr, dispatch }) => {
|
||||
const { from, to } = range
|
||||
|
||||
if (dispatch) {
|
||||
@ -12,3 +12,9 @@ export const deleteRange = (range: Range): Command => ({ tr, dispatch }) => {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
deleteRange: (range: Range) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,15 @@
|
||||
import { deleteSelection as originalDeleteSelection } from 'prosemirror-commands'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Delete the selection, if there is one.
|
||||
*/
|
||||
export const deleteSelection = (): Command => ({ state, dispatch }) => {
|
||||
export const deleteSelection: Commands['deleteSelection'] = () => ({ state, dispatch }) => {
|
||||
return originalDeleteSelection(state, dispatch)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
deleteSelection: () => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,14 @@
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Trigger enter.
|
||||
*/
|
||||
export const enter = (): Command => ({ commands }) => {
|
||||
export const enter: Commands['enter'] = () => ({ commands }) => {
|
||||
return commands.keyboardShortcut('Enter')
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
enter: () => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,15 @@
|
||||
import { exitCode as originalExitCode } from 'prosemirror-commands'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Exit from a code block.
|
||||
*/
|
||||
export const exitCode = (): Command => ({ state, dispatch }) => {
|
||||
export const exitCode: Commands['exitCode'] = () => ({ state, dispatch }) => {
|
||||
return originalExitCode(state, dispatch)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
exitCode: () => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { TextSelection } from 'prosemirror-state'
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
import getMarkType from '../helpers/getMarkType'
|
||||
import getMarkRange from '../helpers/getMarkRange'
|
||||
|
||||
/**
|
||||
* Extends the text selection to the current mark.
|
||||
*/
|
||||
export const extendMarkRange = (typeOrName: string | MarkType): Command => ({ tr, state, dispatch }) => {
|
||||
export const extendMarkRange: Commands['extendMarkRange'] = typeOrName => ({ tr, state, dispatch }) => {
|
||||
const type = getMarkType(typeOrName, state.schema)
|
||||
const { doc, selection } = tr
|
||||
const { $from, empty } = selection
|
||||
@ -24,3 +24,9 @@ export const extendMarkRange = (typeOrName: string | MarkType): Command => ({ tr
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
extendMarkRange: (typeOrName: string | MarkType) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Runs one command after the other and stops at the first which returns true.
|
||||
*/
|
||||
export const first = (commands: Command[] | ((props: Parameters<Command>[0]) => Command[])): Command => props => {
|
||||
export const first: Commands['first'] = commands => props => {
|
||||
const items = typeof commands === 'function'
|
||||
? commands(props)
|
||||
: commands
|
||||
@ -16,3 +16,9 @@ export const first = (commands: Command[] | ((props: Parameters<Command>[0]) =>
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
first: (commands: Command[] | ((props: Parameters<Command>[0]) => Command[])) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { EditorState, TextSelection } from 'prosemirror-state'
|
||||
import { Command, FocusPosition } from '../types'
|
||||
import { Command, Commands, FocusPosition } from '../types'
|
||||
import minMax from '../utilities/minMax'
|
||||
import isTextSelection from '../helpers/isTextSelection'
|
||||
|
||||
@ -33,7 +33,7 @@ function resolveSelection(state: EditorState, position: FocusPosition = null) {
|
||||
/**
|
||||
* Focus the editor at the given position.
|
||||
*/
|
||||
export const focus = (position: FocusPosition = null): Command => ({
|
||||
export const focus: Commands['focus'] = (position = null) => ({
|
||||
editor,
|
||||
view,
|
||||
tr,
|
||||
@ -62,3 +62,9 @@ export const focus = (position: FocusPosition = null): Command => ({
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
focus: (position?: FocusPosition) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ import { DOMParser } from 'prosemirror-model'
|
||||
import { Selection, Transaction } from 'prosemirror-state'
|
||||
import { ReplaceStep, ReplaceAroundStep } from 'prosemirror-transform'
|
||||
import elementFromString from '../utilities/elementFromString'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
// TODO: move to utils
|
||||
// https://github.com/ProseMirror/prosemirror-state/blob/master/src/selection.js#L466
|
||||
@ -20,7 +20,7 @@ function selectionToInsertionEnd(tr: Transaction, startLen: number, bias: number
|
||||
/**
|
||||
* Insert a string of HTML at the current position.
|
||||
*/
|
||||
export const insertHTML = (value: string): Command => ({ tr, state, dispatch }) => {
|
||||
export const insertHTML: Commands['insertHTML'] = value => ({ tr, state, dispatch }) => {
|
||||
const { selection } = tr
|
||||
const element = elementFromString(value)
|
||||
const slice = DOMParser.fromSchema(state.schema).parseSlice(element)
|
||||
@ -32,3 +32,9 @@ export const insertHTML = (value: string): Command => ({ tr, state, dispatch })
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
insertHTML: (value: string) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,18 @@
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Insert a string of text at the current position.
|
||||
*/
|
||||
export const insertText = (value: string): Command => ({ tr, dispatch }) => {
|
||||
export const insertText: Commands['insertText'] = value => ({ tr, dispatch }) => {
|
||||
if (dispatch) {
|
||||
tr.insertText(value)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
insertText: (value: string) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,15 @@
|
||||
import { joinBackward as originalJoinBackward } from 'prosemirror-commands'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Join two nodes backward.
|
||||
*/
|
||||
export const joinBackward = (): Command => ({ state, dispatch }) => {
|
||||
export const joinBackward: Commands['joinBackward'] = () => ({ state, dispatch }) => {
|
||||
return originalJoinBackward(state, dispatch)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
joinBackward: () => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,15 @@
|
||||
import { joinForward as originalJoinForward } from 'prosemirror-commands'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Join two nodes forward.
|
||||
*/
|
||||
export const joinForward = (): Command => ({ state, dispatch }) => {
|
||||
export const joinForward: Commands['joinForward'] = () => ({ state, dispatch }) => {
|
||||
return originalJoinForward(state, dispatch)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
joinForward: () => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
const mac = typeof navigator !== 'undefined' ? /Mac/.test(navigator.platform) : false
|
||||
|
||||
@ -59,7 +59,7 @@ function normalizeKeyName(name: string) {
|
||||
/**
|
||||
* Trigger a keyboard shortcut.
|
||||
*/
|
||||
export const keyboardShortcut = (name: string): Command => ({
|
||||
export const keyboardShortcut: Commands['keyboardShortcut'] = name => ({
|
||||
editor,
|
||||
view,
|
||||
tr,
|
||||
@ -93,3 +93,9 @@ export const keyboardShortcut = (name: string): Command => ({
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
keyboardShortcut: (name: string) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { lift as originalLift } from 'prosemirror-commands'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands, AnyObject } from '../types'
|
||||
import isNodeActive from '../helpers/isNodeActive'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
* Removes an existing wrap.
|
||||
*/
|
||||
export const lift = (typeOrName: string | NodeType, attributes = {}): Command => ({ state, dispatch }) => {
|
||||
export const lift: Commands['lift'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const isActive = isNodeActive(state, type, attributes)
|
||||
|
||||
@ -17,3 +17,9 @@ export const lift = (typeOrName: string | NodeType, attributes = {}): Command =>
|
||||
|
||||
return originalLift(state, dispatch)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
lift: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,15 @@
|
||||
import { liftEmptyBlock as originalLiftEmptyBlock } from 'prosemirror-commands'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Lift block if empty.
|
||||
*/
|
||||
export const liftEmptyBlock = (): Command => ({ state, dispatch }) => {
|
||||
export const liftEmptyBlock: Commands['liftEmptyBlock'] = () => ({ state, dispatch }) => {
|
||||
return originalLiftEmptyBlock(state, dispatch)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
liftEmptyBlock: () => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,19 @@
|
||||
import { liftListItem as originalLiftListItem } from 'prosemirror-schema-list'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
* Lift the list item into a wrapping list.
|
||||
*/
|
||||
export const liftListItem = (typeOrName: string | NodeType): Command => ({ state, dispatch }) => {
|
||||
export const liftListItem: Commands['liftListItem'] = typeOrName => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
|
||||
return originalLiftListItem(type)(state, dispatch)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
liftListItem: (typeOrName: string | NodeType) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,15 @@
|
||||
import { newlineInCode as originalNewlineInCode } from 'prosemirror-commands'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Add a newline character in code.
|
||||
*/
|
||||
export const newlineInCode = (): Command => ({ state, dispatch }) => {
|
||||
export const newlineInCode: Commands['newlineInCode'] = () => ({ state, dispatch }) => {
|
||||
return originalNewlineInCode(state, dispatch)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
newlineInCode: () => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,18 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command, AnyObject } from '../types'
|
||||
import { Command, Commands, AnyObject } from '../types'
|
||||
|
||||
/**
|
||||
* Replaces text with a node.
|
||||
*/
|
||||
export const replace = (typeOrName: string | NodeType, attributes: AnyObject = {}): Command => ({ state, commands }) => {
|
||||
export const replace: Commands['replace'] = (typeOrName, attributes = {}) => ({ state, commands }) => {
|
||||
const { from, to } = state.selection
|
||||
const range = { from, to }
|
||||
|
||||
return commands.replaceRange(range, typeOrName, attributes)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
replace: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,16 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
import { Command, Range, AnyObject } from '../types'
|
||||
import {
|
||||
Command,
|
||||
Commands,
|
||||
Range,
|
||||
AnyObject,
|
||||
} from '../types'
|
||||
|
||||
/**
|
||||
* Replaces text with a node within a range.
|
||||
*/
|
||||
export const replaceRange = (range: Range, typeOrName: string | NodeType, attributes: AnyObject = {}): Command => ({ tr, state, dispatch }) => {
|
||||
export const replaceRange: Commands['replaceRange'] = (range, typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const { from, to } = range
|
||||
const $from = tr.doc.resolve(from)
|
||||
@ -21,3 +26,9 @@ export const replaceRange = (range: Range, typeOrName: string | NodeType, attrib
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
replaceRange: (range: Range, typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
import deleteProps from '../utilities/deleteProps'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Resets node attributes to the default value.
|
||||
*/
|
||||
export const resetNodeAttributes = (typeOrName: string | NodeType, attributes: string | string[]): Command => ({ tr, state, dispatch }) => {
|
||||
export const resetNodeAttributes: Commands['resetNodeAttributes'] = (typeOrName, attributes) => ({ tr, state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const { selection } = tr
|
||||
const { from, to } = selection
|
||||
@ -19,3 +19,9 @@ export const resetNodeAttributes = (typeOrName: string | NodeType, attributes: s
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
resetNodeAttributes: (typeOrName: string | NodeType, attributes: string | string[]) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,18 @@
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Scroll the selection into view.
|
||||
*/
|
||||
export const scrollIntoView = (): Command => ({ tr, dispatch }) => {
|
||||
export const scrollIntoView: Commands['scrollIntoView'] = () => ({ tr, dispatch }) => {
|
||||
if (dispatch) {
|
||||
tr.scrollIntoView()
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
scrollIntoView: () => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,15 @@
|
||||
import { selectAll as originalSelectAll } from 'prosemirror-commands'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Select the whole document.
|
||||
*/
|
||||
export const selectAll = (): Command => ({ state, dispatch }) => {
|
||||
export const selectAll: Commands['selectAll'] = () => ({ state, dispatch }) => {
|
||||
return originalSelectAll(state, dispatch)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
selectAll: () => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,15 @@
|
||||
import { selectNodeBackward as originalSelectNodeBackward } from 'prosemirror-commands'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Select a node backward.
|
||||
*/
|
||||
export const selectNodeBackward = (): Command => ({ state, dispatch }) => {
|
||||
export const selectNodeBackward: Commands['selectNodeBackward'] = () => ({ state, dispatch }) => {
|
||||
return originalSelectNodeBackward(state, dispatch)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
selectNodeBackward: () => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,15 @@
|
||||
import { selectNodeForward as originalSelectNodeForward } from 'prosemirror-commands'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Select a node forward.
|
||||
*/
|
||||
export const selectNodeForward = (): Command => ({ state, dispatch }) => {
|
||||
export const selectNodeForward: Commands['selectNodeForward'] = () => ({ state, dispatch }) => {
|
||||
return originalSelectNodeForward(state, dispatch)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
selectNodeForward: () => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,15 @@
|
||||
import { selectParentNode as originalSelectParentNode } from 'prosemirror-commands'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Select the parent node.
|
||||
*/
|
||||
export const selectParentNode = (): Command => ({ state, dispatch }) => {
|
||||
export const selectParentNode: Commands['selectParentNode'] = () => ({ state, dispatch }) => {
|
||||
return originalSelectParentNode(state, dispatch)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
selectParentNode: () => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { TextSelection } from 'prosemirror-state'
|
||||
import { Command } from '../types'
|
||||
import { AnyObject, Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Replace the whole document with new content.
|
||||
*/
|
||||
export const setContent = (content: string, emitUpdate: Boolean = false, parseOptions = {}): Command => ({ tr, editor, dispatch }) => {
|
||||
export const setContent: Commands['setContent'] = (content, emitUpdate = false, parseOptions = {}) => ({ tr, editor, dispatch }) => {
|
||||
const { createDocument } = editor
|
||||
const { doc } = tr
|
||||
const document = createDocument(content, parseOptions)
|
||||
@ -18,3 +18,9 @@ export const setContent = (content: string, emitUpdate: Boolean = false, parseOp
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setContent: (content: string, emitUpdate?: Boolean, parseOptions?: AnyObject) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import { AnyObject, Command, Commands } from '../types'
|
||||
import getMarkType from '../helpers/getMarkType'
|
||||
import getMarkAttributes from '../helpers/getMarkAttributes'
|
||||
|
||||
/**
|
||||
* Add a mark with new attributes.
|
||||
*/
|
||||
export const setMark = (typeOrName: string | MarkType, attributes?: {}): Command => ({ tr, state, dispatch }) => {
|
||||
export const setMark: Commands['setMark'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
|
||||
const { selection } = tr
|
||||
const { from, to, empty } = selection
|
||||
const type = getMarkType(typeOrName, state.schema)
|
||||
@ -26,3 +26,9 @@ export const setMark = (typeOrName: string | MarkType, attributes?: {}): Command
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,19 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { setBlockType } from 'prosemirror-commands'
|
||||
import { Command } from '../types'
|
||||
import { AnyObject, Command, Commands } from '../types'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
* Replace a given range with a node.
|
||||
*/
|
||||
export const setNode = (typeOrName: string | NodeType, attrs = {}): Command => ({ state, dispatch }) => {
|
||||
export const setNode: Commands['setNode'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
|
||||
return setBlockType(type, attrs)(state, dispatch)
|
||||
return setBlockType(type, attributes)(state, dispatch)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setNode: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,19 @@
|
||||
import { sinkListItem as originalSinkListItem } from 'prosemirror-schema-list'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
* Sink the list item down into an inner list.
|
||||
*/
|
||||
export const sinkListItem = (typeOrName: string | NodeType): Command => ({ state, dispatch }) => {
|
||||
export const sinkListItem: Commands['sinkListItem'] = typeOrName => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
|
||||
return originalSinkListItem(type)(state, dispatch)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
sinkListItem: (typeOrName: string | NodeType) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { canSplit } from 'prosemirror-transform'
|
||||
import { ContentMatch, Fragment } from 'prosemirror-model'
|
||||
import { EditorState, NodeSelection, TextSelection } from 'prosemirror-state'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
import getSplittedAttributes from '../helpers/getSplittedAttributes'
|
||||
|
||||
function defaultBlockAt(match: ContentMatch) {
|
||||
@ -31,7 +31,7 @@ function keepMarks(state: EditorState) {
|
||||
/**
|
||||
* Forks a new node from an existing node.
|
||||
*/
|
||||
export const splitBlock = (options: Partial<SplitBlockOptions> = {}): Command => ({
|
||||
export const splitBlock: Commands['splitBlock'] = (options = {}) => ({
|
||||
tr,
|
||||
state,
|
||||
dispatch,
|
||||
@ -126,3 +126,9 @@ export const splitBlock = (options: Partial<SplitBlockOptions> = {}): Command =>
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
splitBlock: (options?: Partial<SplitBlockOptions>) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -6,14 +6,14 @@ import {
|
||||
} from 'prosemirror-model'
|
||||
import { canSplit } from 'prosemirror-transform'
|
||||
import { TextSelection } from 'prosemirror-state'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
import getSplittedAttributes from '../helpers/getSplittedAttributes'
|
||||
|
||||
/**
|
||||
* Splits one list item into two list items.
|
||||
*/
|
||||
export const splitListItem = (typeOrName: string | NodeType): Command => ({
|
||||
export const splitListItem: Commands['splitListItem'] = typeOrName => ({
|
||||
tr, state, dispatch, editor,
|
||||
}) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
@ -110,3 +110,9 @@ export const splitListItem = (typeOrName: string | NodeType): Command => ({
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
splitListItem: (typeOrName: string | NodeType) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
import findParentNode from '../helpers/findParentNode'
|
||||
import isList from '../helpers/isList'
|
||||
@ -7,7 +7,7 @@ import isList from '../helpers/isList'
|
||||
/**
|
||||
* Toggle between different list types.
|
||||
*/
|
||||
export const toggleList = (listTypeOrName: string | NodeType, itemTypeOrName: string | NodeType): Command => ({
|
||||
export const toggleList: Commands['toggleList'] = (listTypeOrName, itemTypeOrName) => ({
|
||||
editor, tr, state, dispatch, chain, commands, can,
|
||||
}) => {
|
||||
const { extensions } = editor.options
|
||||
@ -53,3 +53,9 @@ export const toggleList = (listTypeOrName: string | NodeType, itemTypeOrName: st
|
||||
|
||||
return commands.wrapInList(listType)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
toggleList: (listTypeOrName: string | NodeType, itemTypeOrName: string | NodeType) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import { AnyObject, Command, Commands } from '../types'
|
||||
import getMarkType from '../helpers/getMarkType'
|
||||
import isMarkActive from '../helpers/isMarkActive'
|
||||
|
||||
/**
|
||||
* Toggle a mark on and off.
|
||||
*/
|
||||
export const toggleMark = (typeOrName: string | MarkType, attributes?: {}): Command => ({ state, commands }) => {
|
||||
export const toggleMark: Commands['toggleMark'] = (typeOrName, attributes = {}) => ({ state, commands }) => {
|
||||
const type = getMarkType(typeOrName, state.schema)
|
||||
const isActive = isMarkActive(state, type, attributes)
|
||||
|
||||
@ -16,3 +16,9 @@ export const toggleMark = (typeOrName: string | MarkType, attributes?: {}): Comm
|
||||
|
||||
return commands.setMark(type, attributes)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
toggleMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,25 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import { AnyObject, Command, Commands } from '../types'
|
||||
import isNodeActive from '../helpers/isNodeActive'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
* Toggle a node with another node.
|
||||
*/
|
||||
export const toggleNode = (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attrs = {}): Command => ({ state, commands }) => {
|
||||
export const toggleNode: Commands['toggleNode'] = (typeOrName, toggleTypeOrName, attributes = {}) => ({ state, commands }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const toggleType = getNodeType(toggleTypeOrName, state.schema)
|
||||
const isActive = isNodeActive(state, type, attrs)
|
||||
const isActive = isNodeActive(state, type, attributes)
|
||||
|
||||
if (isActive) {
|
||||
return commands.setNode(toggleType)
|
||||
}
|
||||
|
||||
return commands.setNode(type, attrs)
|
||||
return commands.setNode(type, attributes)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
toggleNode: (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { wrapIn, lift } from 'prosemirror-commands'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import { AnyObject, Command, Commands } from '../types'
|
||||
import isNodeActive from '../helpers/isNodeActive'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
* Wraps nodes in another node, or removes an existing wrap.
|
||||
*/
|
||||
export const toggleWrap = (typeOrName: string | NodeType, attributes = {}): Command => ({ state, dispatch }) => {
|
||||
export const toggleWrap: Commands['toggleWrap'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const isActive = isNodeActive(state, type, attributes)
|
||||
|
||||
@ -17,3 +17,9 @@ export const toggleWrap = (typeOrName: string | NodeType, attributes = {}): Comm
|
||||
|
||||
return wrapIn(type, attributes)(state, dispatch)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
toggleWrap: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,15 @@
|
||||
import { undoInputRule as originalUndoInputRule } from 'prosemirror-inputrules'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Undo an input rule.
|
||||
*/
|
||||
export const undoInputRule = (): Command => ({ state, dispatch }) => {
|
||||
export const undoInputRule: Commands['undoInputRule'] = () => ({ state, dispatch }) => {
|
||||
return originalUndoInputRule(state, dispatch)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
undoInputRule: () => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Remove all marks in the current selection.
|
||||
*/
|
||||
export const unsetAllMarks = (): Command => ({ tr, state, dispatch }) => {
|
||||
export const unsetAllMarks: Commands['unsetAllMarks'] = () => ({ tr, state, dispatch }) => {
|
||||
const { selection } = tr
|
||||
const { from, to, empty } = selection
|
||||
|
||||
@ -21,3 +21,9 @@ export const unsetAllMarks = (): Command => ({ tr, state, dispatch }) => {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
unsetAllMarks: () => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import { Command, Commands } from '../types'
|
||||
import getMarkType from '../helpers/getMarkType'
|
||||
import getMarkRange from '../helpers/getMarkRange'
|
||||
|
||||
/**
|
||||
* Remove all marks in the current selection.
|
||||
*/
|
||||
export const unsetMark = (typeOrName: string | MarkType): Command => ({ tr, state, dispatch }) => {
|
||||
export const unsetMark: Commands['unsetMark'] = typeOrName => ({ tr, state, dispatch }) => {
|
||||
const { selection } = tr
|
||||
const type = getMarkType(typeOrName, state.schema)
|
||||
let { from, to } = selection
|
||||
@ -28,3 +28,9 @@ export const unsetMark = (typeOrName: string | MarkType): Command => ({ tr, stat
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
unsetMark: (typeOrName: string | MarkType) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
import { Command } from '../types'
|
||||
import { AnyObject, Command, Commands } from '../types'
|
||||
|
||||
/**
|
||||
* Update attributes of a node.
|
||||
*/
|
||||
export const updateNodeAttributes = (typeOrName: string | NodeType, attributes: {}): Command => ({ tr, state, dispatch }) => {
|
||||
export const updateNodeAttributes: Commands['updateNodeAttributes'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const { selection } = tr
|
||||
const { from, to } = selection
|
||||
@ -21,3 +21,9 @@ export const updateNodeAttributes = (typeOrName: string | NodeType, attributes:
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
updateNodeAttributes: (typeOrName: string | NodeType, attributes: AnyObject) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { wrapIn as originalWrapIn } from 'prosemirror-commands'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import { AnyObject, Command, Commands } from '../types'
|
||||
import isNodeActive from '../helpers/isNodeActive'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
* Wraps nodes in another node.
|
||||
*/
|
||||
export const wrapIn = (typeOrName: string | NodeType, attributes = {}): Command => ({ state, dispatch }) => {
|
||||
export const wrapIn: Commands['wrapIn'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const isActive = isNodeActive(state, type, attributes)
|
||||
|
||||
@ -17,3 +17,9 @@ export const wrapIn = (typeOrName: string | NodeType, attributes = {}): Command
|
||||
|
||||
return originalWrapIn(type, attributes)(state, dispatch)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
wrapIn: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,19 @@
|
||||
import { wrapInList as originalWrapInList } from 'prosemirror-schema-list'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import { AnyObject, Command, Commands } from '../types'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
* Wrap a node in a list.
|
||||
*/
|
||||
export const wrapInList = (typeOrName: string | NodeType, attrs?: {}): Command => ({ state, dispatch }) => {
|
||||
export const wrapInList: Commands['wrapInList'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
|
||||
return originalWrapInList(type, attrs)(state, dispatch)
|
||||
return originalWrapInList(type, attributes)(state, dispatch)
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
wrapInList: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
||||
}
|
||||
}
|
||||
|
@ -52,9 +52,3 @@ export const ClipboardTextSerializer = Extension.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
ClipboardTextSerializer: typeof ClipboardTextSerializer,
|
||||
}
|
||||
}
|
||||
|
@ -98,9 +98,3 @@ export const Commands = Extension.create({
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Commands: typeof Commands,
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,3 @@ export const Editable = Extension.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Editable: typeof Editable,
|
||||
}
|
||||
}
|
||||
|
@ -43,9 +43,3 @@ export const FocusEvents = Extension.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
FocusEvents: typeof FocusEvents,
|
||||
}
|
||||
}
|
||||
|
@ -34,9 +34,3 @@ export const Keymap = Extension.create({
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Keymap: typeof Keymap,
|
||||
}
|
||||
}
|
||||
|
@ -22,3 +22,4 @@ export { default as isCellSelection } from './helpers/isCellSelection'
|
||||
export { default as findParentNodeClosestToPos } from './helpers/findParentNodeClosestToPos'
|
||||
|
||||
export interface AllExtensions {}
|
||||
export interface Commands {}
|
||||
|
@ -14,7 +14,9 @@ import { Extension } from './Extension'
|
||||
import { Node } from './Node'
|
||||
import { Mark } from './Mark'
|
||||
import { Editor } from './Editor'
|
||||
import { AllExtensions } from '.'
|
||||
import { Commands } from '.'
|
||||
|
||||
export { Commands }
|
||||
|
||||
export type Extensions = (Extension | Node | Mark)[]
|
||||
|
||||
@ -106,29 +108,31 @@ export type NodeViewRendererProps = {
|
||||
|
||||
export type NodeViewRenderer = (props: NodeViewRendererProps) => (NodeView | {})
|
||||
|
||||
export type UnfilteredCommands = {
|
||||
[Item in keyof AllExtensions]: AllExtensions[Item] extends Extension<any, infer ExtensionCommands>
|
||||
? ExtensionCommands
|
||||
: AllExtensions[Item] extends Node<any, infer NodeCommands>
|
||||
? NodeCommands
|
||||
: AllExtensions[Item] extends Mark<any, infer MarkCommands>
|
||||
? MarkCommands
|
||||
: never
|
||||
}
|
||||
// export type UnfilteredCommands = {
|
||||
// [Item in keyof AllExtensions]: AllExtensions[Item] extends Extension<any, infer ExtensionCommands>
|
||||
// ? ExtensionCommands
|
||||
// : AllExtensions[Item] extends Node<any, infer NodeCommands>
|
||||
// ? NodeCommands
|
||||
// : AllExtensions[Item] extends Mark<any, infer MarkCommands>
|
||||
// ? MarkCommands
|
||||
// : never
|
||||
// }
|
||||
|
||||
export type ValuesOf<T> = T[keyof T];
|
||||
export type KeysWithTypeOf<T, Type> = ({[P in keyof T]: T[P] extends Type ? P : never })[keyof T]
|
||||
export type AllCommands = UnionToIntersection<ValuesOf<Pick<UnfilteredCommands, KeysWithTypeOf<UnfilteredCommands, {}>>>>
|
||||
// export type Commands = UnionToIntersection<ValuesOf<Pick<UnfilteredCommands, KeysWithTypeOf<UnfilteredCommands, {}>>>>
|
||||
|
||||
// export type Commands = Commands
|
||||
|
||||
export type SingleCommands = {
|
||||
[Item in keyof AllCommands]: AllCommands[Item] extends (...args: any[]) => any
|
||||
? (...args: Parameters<AllCommands[Item]>) => boolean
|
||||
[Item in keyof Commands]: Commands[Item] extends (...args: any[]) => any
|
||||
? (...args: Parameters<Commands[Item]>) => boolean
|
||||
: never
|
||||
}
|
||||
|
||||
export type ChainedCommands = {
|
||||
[Item in keyof AllCommands]: AllCommands[Item] extends (...args: any[]) => any
|
||||
? (...args: Parameters<AllCommands[Item]>) => ChainedCommands
|
||||
[Item in keyof Commands]: Commands[Item] extends (...args: any[]) => any
|
||||
? (...args: Parameters<Commands[Item]>) => ChainedCommands
|
||||
: never
|
||||
} & {
|
||||
run: () => boolean
|
||||
|
@ -7,9 +7,18 @@ export interface BlockquoteOptions {
|
||||
},
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setBlockquote: () => Command,
|
||||
toggleBlockquote: () => Command,
|
||||
unsetBlockquote: () => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const inputRegex = /^\s*>\s$/gm
|
||||
|
||||
export const Blockquote = Node.create({
|
||||
|
||||
name: 'blockquote',
|
||||
|
||||
defaultOptions: <BlockquoteOptions>{
|
||||
@ -37,19 +46,19 @@ export const Blockquote = Node.create({
|
||||
/**
|
||||
* Set a blockquote node
|
||||
*/
|
||||
setBlockquote: (): Command => ({ commands }) => {
|
||||
setBlockquote: () => ({ commands }) => {
|
||||
return commands.wrapIn('blockquote')
|
||||
},
|
||||
/**
|
||||
* Toggle a blockquote node
|
||||
*/
|
||||
toggleBlockquote: (): Command => ({ commands }) => {
|
||||
toggleBlockquote: () => ({ commands }) => {
|
||||
return commands.toggleWrap('blockquote')
|
||||
},
|
||||
/**
|
||||
* Unset a blockquote node
|
||||
*/
|
||||
unsetBlockquote: (): Command => ({ commands }) => {
|
||||
unsetBlockquote: () => ({ commands }) => {
|
||||
return commands.lift('blockquote')
|
||||
},
|
||||
}
|
||||
@ -67,9 +76,3 @@ export const Blockquote = Node.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Blockquote: typeof Blockquote,
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,14 @@ export interface BoldOptions {
|
||||
},
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setBold: () => Command,
|
||||
toggleBold: () => Command,
|
||||
unsetBold: () => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const starInputRegex = /(?:^|\s)((?:\*\*)((?:[^*]+))(?:\*\*))$/gm
|
||||
export const starPasteRegex = /(?:^|\s)((?:\*\*)((?:[^*]+))(?:\*\*))/gm
|
||||
export const underscoreInputRegex = /(?:^|\s)((?:__)((?:[^__]+))(?:__))$/gm
|
||||
@ -49,19 +57,19 @@ export const Bold = Mark.create({
|
||||
/**
|
||||
* Set a bold mark
|
||||
*/
|
||||
setBold: (): Command => ({ commands }) => {
|
||||
setBold: () => ({ commands }) => {
|
||||
return commands.setMark('bold')
|
||||
},
|
||||
/**
|
||||
* Toggle a bold mark
|
||||
*/
|
||||
toggleBold: (): Command => ({ commands }) => {
|
||||
toggleBold: () => ({ commands }) => {
|
||||
return commands.toggleMark('bold')
|
||||
},
|
||||
/**
|
||||
* Unset a bold mark
|
||||
*/
|
||||
unsetBold: (): Command => ({ commands }) => {
|
||||
unsetBold: () => ({ commands }) => {
|
||||
return commands.unsetMark('bold')
|
||||
},
|
||||
}
|
||||
@ -87,9 +95,3 @@ export const Bold = Mark.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Bold: typeof Bold,
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,12 @@ export interface BulletListOptions {
|
||||
},
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
toggleBulletList: () => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const inputRegex = /^\s*([-+*])\s$/
|
||||
|
||||
export const BulletList = Node.create({
|
||||
@ -35,7 +41,7 @@ export const BulletList = Node.create({
|
||||
/**
|
||||
* Toggle a bullet list
|
||||
*/
|
||||
toggleBulletList: (): Command => ({ commands }) => {
|
||||
toggleBulletList: () => ({ commands }) => {
|
||||
return commands.toggleList('bulletList', 'listItem')
|
||||
},
|
||||
}
|
||||
@ -53,9 +59,3 @@ export const BulletList = Node.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
BulletList: typeof BulletList,
|
||||
}
|
||||
}
|
||||
|
@ -33,9 +33,3 @@ export const CharacterCount = Extension.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
CharacterCount: typeof CharacterCount,
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,13 @@ export interface CodeBlockOptions {
|
||||
},
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setCodeBlock: (attributes?: { language: string }) => Command,
|
||||
toggleCodeBlock: (attributes?: { language: string }) => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const backtickInputRegex = /^```(?<language>[a-z]*)? $/
|
||||
export const tildeInputRegex = /^~~~(?<language>[a-z]*)? $/
|
||||
|
||||
@ -77,13 +84,13 @@ export const CodeBlock = Node.create({
|
||||
/**
|
||||
* Set a code block
|
||||
*/
|
||||
setCodeBlock: (attributes?: { language: string }): Command => ({ commands }) => {
|
||||
setCodeBlock: attributes => ({ commands }) => {
|
||||
return commands.setNode('codeBlock', attributes)
|
||||
},
|
||||
/**
|
||||
* Toggle a code block
|
||||
*/
|
||||
toggleCodeBlock: (attributes?: { language: string }): Command => ({ commands }) => {
|
||||
toggleCodeBlock: attributes => ({ commands }) => {
|
||||
return commands.toggleNode('codeBlock', 'paragraph', attributes)
|
||||
},
|
||||
}
|
||||
@ -102,9 +109,3 @@ export const CodeBlock = Node.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
CodeBlock: typeof CodeBlock,
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,14 @@ export interface CodeOptions {
|
||||
},
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setCode: () => Command,
|
||||
toggleCode: () => Command,
|
||||
unsetCode: () => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const inputRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))$/gm
|
||||
export const pasteRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))/gm
|
||||
|
||||
@ -39,19 +47,19 @@ export const Code = Mark.create({
|
||||
/**
|
||||
* Set a code mark
|
||||
*/
|
||||
setCode: (): Command => ({ commands }) => {
|
||||
setCode: () => ({ commands }) => {
|
||||
return commands.setMark('code')
|
||||
},
|
||||
/**
|
||||
* Toggle inline code
|
||||
*/
|
||||
toggleCode: (): Command => ({ commands }) => {
|
||||
toggleCode: () => ({ commands }) => {
|
||||
return commands.toggleMark('code')
|
||||
},
|
||||
/**
|
||||
* Unset a code mark
|
||||
*/
|
||||
unsetCode: (): Command => ({ commands }) => {
|
||||
unsetCode: () => ({ commands }) => {
|
||||
return commands.unsetMark('code')
|
||||
},
|
||||
}
|
||||
@ -75,9 +83,3 @@ export const Code = Mark.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Code: typeof Code,
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Extension, Command } from '@tiptap/core'
|
||||
import { Extension, Command, AnyObject } from '@tiptap/core'
|
||||
import { yCursorPlugin } from 'y-prosemirror'
|
||||
|
||||
export interface CollaborationCursorOptions {
|
||||
@ -8,6 +8,12 @@ export interface CollaborationCursorOptions {
|
||||
onUpdate: (users: { clientId: string, [key: string]: any }[]) => null,
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
user: (attributes: AnyObject) => Command,
|
||||
}
|
||||
}
|
||||
|
||||
const awarenessStatesToArray = (states: Map<number, { [key: string]: any }>) => {
|
||||
return Array.from(states.entries()).map(([key, value]) => {
|
||||
return {
|
||||
@ -47,7 +53,7 @@ export const CollaborationCursor = Extension.create({
|
||||
/**
|
||||
* Update details of the current user
|
||||
*/
|
||||
user: (attributes: { [key: string]: any }): Command => () => {
|
||||
user: attributes => () => {
|
||||
this.options.user = attributes
|
||||
|
||||
this.options.provider.awareness.setLocalStateField('user', this.options.user)
|
||||
@ -87,9 +93,3 @@ export const CollaborationCursor = Extension.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
CollaborationCursor: typeof CollaborationCursor,
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,13 @@ import {
|
||||
yUndoPlugin,
|
||||
} from 'y-prosemirror'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
undo: () => Command,
|
||||
redo: () => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export interface CollaborationOptions {
|
||||
/**
|
||||
* An initialized Y.js document.
|
||||
@ -35,7 +42,7 @@ export const Collaboration = Extension.create({
|
||||
/**
|
||||
* Undo recent changes
|
||||
*/
|
||||
undo: (): Command => ({ tr, state }) => {
|
||||
undo: () => ({ tr, state }) => {
|
||||
tr.setMeta('preventDispatch', true)
|
||||
|
||||
return undo(state)
|
||||
@ -43,7 +50,7 @@ export const Collaboration = Extension.create({
|
||||
/**
|
||||
* Reapply reverted changes
|
||||
*/
|
||||
redo: (): Command => ({ tr, state }) => {
|
||||
redo: () => ({ tr, state }) => {
|
||||
tr.setMeta('preventDispatch', true)
|
||||
|
||||
return redo(state)
|
||||
@ -70,9 +77,3 @@ export const Collaboration = Extension.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Collaboration: typeof Collaboration,
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,3 @@ export const Document = Node.create({
|
||||
topNode: true,
|
||||
content: 'block+',
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Document: typeof Document,
|
||||
}
|
||||
}
|
||||
|
@ -22,9 +22,3 @@ export const Dropcursor = Extension.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Dropcursor: typeof Dropcursor,
|
||||
}
|
||||
}
|
||||
|
@ -79,9 +79,3 @@ export const FocusClasses = Extension.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
FocusClasses: typeof FocusClasses,
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,13 @@ type FontFamilyOptions = {
|
||||
types: string[],
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setFontFamily: (fontFamily: string) => Command,
|
||||
unsetFontFamily: () => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const FontFamily = Extension.create({
|
||||
name: 'fontFamily',
|
||||
|
||||
@ -42,7 +49,7 @@ export const FontFamily = Extension.create({
|
||||
/**
|
||||
* Set the font family
|
||||
*/
|
||||
setFontFamily: (fontFamily: string): Command => ({ chain }) => {
|
||||
setFontFamily: fontFamily => ({ chain }) => {
|
||||
return chain()
|
||||
.setMark('textStyle', { fontFamily })
|
||||
.run()
|
||||
@ -50,7 +57,7 @@ export const FontFamily = Extension.create({
|
||||
/**
|
||||
* Unset the font family
|
||||
*/
|
||||
unsetFontFamily: (): Command => ({ chain }) => {
|
||||
unsetFontFamily: () => ({ chain }) => {
|
||||
return chain()
|
||||
.setMark('textStyle', { fontFamily: null })
|
||||
.removeEmptyTextStyle()
|
||||
@ -59,9 +66,3 @@ export const FontFamily = Extension.create({
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
FontFamily: typeof FontFamily,
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,3 @@ export const Gapcursor = Extension.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Gapcursor: typeof Gapcursor,
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,12 @@ export interface HardBreakOptions {
|
||||
},
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setHardBreak: () => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const HardBreak = Node.create({
|
||||
name: 'hardBreak',
|
||||
|
||||
@ -36,7 +42,7 @@ export const HardBreak = Node.create({
|
||||
/**
|
||||
* Add a hard break
|
||||
*/
|
||||
setHardBreak: (): Command => ({ commands, state, dispatch }) => {
|
||||
setHardBreak: () => ({ commands, state, dispatch }) => {
|
||||
return commands.first([
|
||||
() => exitCode(state, dispatch),
|
||||
() => {
|
||||
@ -58,9 +64,3 @@ export const HardBreak = Node.create({
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
HardBreak: typeof HardBreak,
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,13 @@ export interface HeadingOptions {
|
||||
},
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setHeading: (attributes: { level: Level }) => Command,
|
||||
toggleHeading: (attributes: { level: Level }) => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const Heading = Node.create({
|
||||
name: 'heading',
|
||||
|
||||
@ -55,7 +62,7 @@ export const Heading = Node.create({
|
||||
/**
|
||||
* Set a heading node
|
||||
*/
|
||||
setHeading: (attributes: { level: Level }): Command => ({ commands }) => {
|
||||
setHeading: attributes => ({ commands }) => {
|
||||
if (!this.options.levels.includes(attributes.level)) {
|
||||
return false
|
||||
}
|
||||
@ -65,7 +72,7 @@ export const Heading = Node.create({
|
||||
/**
|
||||
* Toggle a heading node
|
||||
*/
|
||||
toggleHeading: (attributes: { level: Level }): Command => ({ commands }) => {
|
||||
toggleHeading: attributes => ({ commands }) => {
|
||||
if (!this.options.levels.includes(attributes.level)) {
|
||||
return false
|
||||
}
|
||||
@ -90,9 +97,3 @@ export const Heading = Node.create({
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Heading: typeof Heading,
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,14 @@ export interface HighlightOptions {
|
||||
},
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setHighlight: (attributes?: { color: string }) => Command,
|
||||
toggleHighlight: (attributes?: { color: string }) => Command,
|
||||
unsetHighlight: () => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const inputRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))$/gm
|
||||
export const pasteRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))/gm
|
||||
|
||||
@ -68,19 +76,19 @@ export const Highlight = Mark.create({
|
||||
/**
|
||||
* Set a highlight mark
|
||||
*/
|
||||
setHighlight: (attributes?: { color: string }): Command => ({ commands }) => {
|
||||
setHighlight: attributes => ({ commands }) => {
|
||||
return commands.setMark('highlight', attributes)
|
||||
},
|
||||
/**
|
||||
* Toggle a highlight mark
|
||||
*/
|
||||
toggleHighlight: (attributes?: { color: string }): Command => ({ commands }) => {
|
||||
toggleHighlight: attributes => ({ commands }) => {
|
||||
return commands.toggleMark('highlight', attributes)
|
||||
},
|
||||
/**
|
||||
* Unset a highlight mark
|
||||
*/
|
||||
unsetHighlight: (): Command => ({ commands }) => {
|
||||
unsetHighlight: () => ({ commands }) => {
|
||||
return commands.unsetMark('highlight')
|
||||
},
|
||||
}
|
||||
@ -104,9 +112,3 @@ export const Highlight = Mark.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Highlight: typeof Highlight,
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,13 @@ export interface HistoryOptions {
|
||||
newGroupDelay: number,
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
undo: () => Command,
|
||||
redo: () => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const History = Extension.create({
|
||||
name: 'history',
|
||||
|
||||
@ -19,13 +26,13 @@ export const History = Extension.create({
|
||||
/**
|
||||
* Undo recent changes
|
||||
*/
|
||||
undo: (): Command => ({ state, dispatch }) => {
|
||||
undo: () => ({ state, dispatch }) => {
|
||||
return undo(state, dispatch)
|
||||
},
|
||||
/**
|
||||
* Reapply reverted changes
|
||||
*/
|
||||
redo: (): Command => ({ state, dispatch }) => {
|
||||
redo: () => ({ state, dispatch }) => {
|
||||
return redo(state, dispatch)
|
||||
},
|
||||
}
|
||||
@ -45,9 +52,3 @@ export const History = Extension.create({
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
History: typeof History,
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,12 @@ export interface HorizontalRuleOptions {
|
||||
},
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setHorizontalRule: () => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const HorizontalRule = Node.create({
|
||||
name: 'horizontalRule',
|
||||
|
||||
@ -35,7 +41,7 @@ export const HorizontalRule = Node.create({
|
||||
/**
|
||||
* Add a horizontal rule
|
||||
*/
|
||||
setHorizontalRule: (): Command => ({ tr, dispatch }) => {
|
||||
setHorizontalRule: () => ({ tr, dispatch }) => {
|
||||
if (dispatch) {
|
||||
tr.replaceSelectionWith(this.type.create())
|
||||
}
|
||||
@ -51,9 +57,3 @@ export const HorizontalRule = Node.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
HorizontalRule: typeof HorizontalRule,
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,12 @@ export interface ImageOptions {
|
||||
},
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setImage: (options: { src: string, alt?: string, title?: string }) => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const inputRegex = /!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\)/
|
||||
|
||||
export const Image = Node.create({
|
||||
@ -63,7 +69,7 @@ export const Image = Node.create({
|
||||
/**
|
||||
* Add an image
|
||||
*/
|
||||
setImage: (options: { src: string, alt?: string, title?: string }): Command => ({ tr, dispatch }) => {
|
||||
setImage: options => ({ tr, dispatch }) => {
|
||||
const { selection } = tr
|
||||
const node = this.type.create(options)
|
||||
|
||||
@ -86,9 +92,3 @@ export const Image = Node.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Image: typeof Image,
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,14 @@ export interface ItalicOptions {
|
||||
},
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setItalic: () => Command,
|
||||
toggleItalic: () => Command,
|
||||
unsetItalic: () => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const starInputRegex = /(?:^|\s)((?:\*)((?:[^*]+))(?:\*))$/gm
|
||||
export const starPasteRegex = /(?:^|\s)((?:\*)((?:[^*]+))(?:\*))/gm
|
||||
export const underscoreInputRegex = /(?:^|\s)((?:_)((?:[^_]+))(?:_))$/gm
|
||||
@ -48,19 +56,19 @@ export const Italic = Mark.create({
|
||||
/**
|
||||
* Set an italic mark
|
||||
*/
|
||||
setItalic: (): Command => ({ commands }) => {
|
||||
setItalic: () => ({ commands }) => {
|
||||
return commands.setMark('italic')
|
||||
},
|
||||
/**
|
||||
* Toggle an italic mark
|
||||
*/
|
||||
toggleItalic: (): Command => ({ commands }) => {
|
||||
toggleItalic: () => ({ commands }) => {
|
||||
return commands.toggleMark('italic')
|
||||
},
|
||||
/**
|
||||
* Unset an italic mark
|
||||
*/
|
||||
unsetItalic: (): Command => ({ commands }) => {
|
||||
unsetItalic: () => ({ commands }) => {
|
||||
return commands.unsetMark('italic')
|
||||
},
|
||||
}
|
||||
@ -86,9 +94,3 @@ export const Italic = Mark.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Italic: typeof Italic,
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,14 @@ export interface LinkOptions {
|
||||
},
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setLink: (attributes: { href: string, target?: string }) => Command,
|
||||
toggleLink: (attributes: { href: string, target?: string }) => Command,
|
||||
unsetLink: () => Command,
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@ -55,19 +63,19 @@ export const Link = Mark.create({
|
||||
/**
|
||||
* Set a link mark
|
||||
*/
|
||||
setLink: (attributes: { href?: string, target?: string } = {}): Command => ({ commands }) => {
|
||||
setLink: attributes => ({ commands }) => {
|
||||
return commands.setMark('link', attributes)
|
||||
},
|
||||
/**
|
||||
* Toggle a link mark
|
||||
*/
|
||||
toggleLink: (attributes: { href?: string, target?: string } = {}): Command => ({ commands }) => {
|
||||
toggleLink: attributes => ({ commands }) => {
|
||||
return commands.toggleMark('link', attributes)
|
||||
},
|
||||
/**
|
||||
* Unset a link mark
|
||||
*/
|
||||
unsetLink: (): Command => ({ commands }) => {
|
||||
unsetLink: () => ({ commands }) => {
|
||||
return commands.unsetMark('link')
|
||||
},
|
||||
}
|
||||
@ -105,9 +113,3 @@ export const Link = Mark.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Link: typeof Link,
|
||||
}
|
||||
}
|
||||
|
@ -37,9 +37,3 @@ export const ListItem = Node.create({
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
ListItem: typeof ListItem,
|
||||
}
|
||||
}
|
||||
|
@ -106,9 +106,3 @@ export const Mention = Node.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Mention: typeof Mention,
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,12 @@ export interface OrderedListOptions {
|
||||
},
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
toggleOrderedList: () => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const inputRegex = /^(\d+)\.\s$/
|
||||
|
||||
export const OrderedList = Node.create({
|
||||
@ -54,7 +60,7 @@ export const OrderedList = Node.create({
|
||||
/**
|
||||
* Toggle an ordered list
|
||||
*/
|
||||
toggleOrderedList: (): Command => ({ commands }) => {
|
||||
toggleOrderedList: () => ({ commands }) => {
|
||||
return commands.toggleList('orderedList', 'listItem')
|
||||
},
|
||||
}
|
||||
@ -77,9 +83,3 @@ export const OrderedList = Node.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
OrderedList: typeof OrderedList,
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,12 @@ export interface ParagraphOptions {
|
||||
},
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setParagraph: () => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const Paragraph = Node.create({
|
||||
name: 'paragraph',
|
||||
|
||||
@ -32,7 +38,7 @@ export const Paragraph = Node.create({
|
||||
/**
|
||||
* Toggle a paragraph
|
||||
*/
|
||||
setParagraph: (): Command => ({ commands }) => {
|
||||
setParagraph: () => ({ commands }) => {
|
||||
return commands.toggleNode('paragraph', 'paragraph')
|
||||
},
|
||||
}
|
||||
@ -44,9 +50,3 @@ export const Paragraph = Node.create({
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Paragraph: typeof Paragraph,
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,14 @@ export interface StrikeOptions {
|
||||
},
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setStrike: () => Command,
|
||||
toggleStrike: () => Command,
|
||||
unsetStrike: () => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const inputRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))$/gm
|
||||
export const pasteRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))/gm
|
||||
|
||||
@ -48,19 +56,19 @@ export const Strike = Mark.create({
|
||||
/**
|
||||
* Set a strike mark
|
||||
*/
|
||||
setStrike: (): Command => ({ commands }) => {
|
||||
setStrike: () => ({ commands }) => {
|
||||
return commands.setMark('strike')
|
||||
},
|
||||
/**
|
||||
* Toggle a strike mark
|
||||
*/
|
||||
toggleStrike: (): Command => ({ commands }) => {
|
||||
toggleStrike: () => ({ commands }) => {
|
||||
return commands.toggleMark('strike')
|
||||
},
|
||||
/**
|
||||
* Unset a strike mark
|
||||
*/
|
||||
unsetStrike: (): Command => ({ commands }) => {
|
||||
unsetStrike: () => ({ commands }) => {
|
||||
return commands.unsetMark('strike')
|
||||
},
|
||||
}
|
||||
@ -84,9 +92,3 @@ export const Strike = Mark.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Strike: typeof Strike,
|
||||
}
|
||||
}
|
||||
|
@ -43,9 +43,3 @@ export const TableCell = Node.create({
|
||||
},
|
||||
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
TableCell: typeof TableCell,
|
||||
}
|
||||
}
|
||||
|
@ -43,9 +43,3 @@ export const TableHeader = Node.create({
|
||||
},
|
||||
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
TableHeader: typeof TableHeader,
|
||||
}
|
||||
}
|
||||
|
@ -27,9 +27,3 @@ export const TableRow = Node.create({
|
||||
return ['tr', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
TableRow: typeof TableRow,
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +41,29 @@ export interface TableOptions {
|
||||
allowTableNodeSelection: boolean,
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
insertTable: (options?: { rows?: number, cols?: number, withHeaderRow?: boolean }) => Command,
|
||||
addColumnBefore: () => Command,
|
||||
addColumnAfter: () => Command,
|
||||
deleteColumn: () => Command,
|
||||
addRowBefore: () => Command,
|
||||
addRowAfter: () => Command,
|
||||
deleteRow: () => Command,
|
||||
deleteTable: () => Command,
|
||||
mergeCells: () => Command,
|
||||
splitCell: () => Command,
|
||||
toggleHeaderColumn: () => Command,
|
||||
toggleHeaderRow: () => Command,
|
||||
toggleHeaderCell: () => Command,
|
||||
mergeOrSplit: () => Command,
|
||||
setCellAttribute: (name: string, value: any) => Command,
|
||||
goToNextCell: () => Command,
|
||||
goToPreviousCell: () => Command,
|
||||
fixTables: () => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const Table = Node.create({
|
||||
name: 'table',
|
||||
|
||||
@ -74,8 +97,8 @@ export const Table = Node.create({
|
||||
|
||||
addCommands() {
|
||||
return {
|
||||
insertTable: (options = { rows: 3, cols: 3, withHeaderRow: true }): Command => ({ tr, dispatch, editor }) => {
|
||||
const node = createTable(editor.schema, options.rows, options.cols, options.withHeaderRow)
|
||||
insertTable: ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr, dispatch, editor }) => {
|
||||
const node = createTable(editor.schema, rows, cols, withHeaderRow)
|
||||
|
||||
if (dispatch) {
|
||||
const offset = tr.selection.anchor + 1
|
||||
@ -87,59 +110,59 @@ export const Table = Node.create({
|
||||
|
||||
return true
|
||||
},
|
||||
addColumnBefore: (): Command => ({ state, dispatch }) => {
|
||||
addColumnBefore: () => ({ state, dispatch }) => {
|
||||
return addColumnBefore(state, dispatch)
|
||||
},
|
||||
addColumnAfter: (): Command => ({ state, dispatch }) => {
|
||||
addColumnAfter: () => ({ state, dispatch }) => {
|
||||
return addColumnAfter(state, dispatch)
|
||||
},
|
||||
deleteColumn: (): Command => ({ state, dispatch }) => {
|
||||
deleteColumn: () => ({ state, dispatch }) => {
|
||||
return deleteColumn(state, dispatch)
|
||||
},
|
||||
addRowBefore: (): Command => ({ state, dispatch }) => {
|
||||
addRowBefore: () => ({ state, dispatch }) => {
|
||||
return addRowBefore(state, dispatch)
|
||||
},
|
||||
addRowAfter: (): Command => ({ state, dispatch }) => {
|
||||
addRowAfter: () => ({ state, dispatch }) => {
|
||||
return addRowAfter(state, dispatch)
|
||||
},
|
||||
deleteRow: (): Command => ({ state, dispatch }) => {
|
||||
deleteRow: () => ({ state, dispatch }) => {
|
||||
return deleteRow(state, dispatch)
|
||||
},
|
||||
deleteTable: (): Command => ({ state, dispatch }) => {
|
||||
deleteTable: () => ({ state, dispatch }) => {
|
||||
return deleteTable(state, dispatch)
|
||||
},
|
||||
mergeCells: (): Command => ({ state, dispatch }) => {
|
||||
mergeCells: () => ({ state, dispatch }) => {
|
||||
return mergeCells(state, dispatch)
|
||||
},
|
||||
splitCell: (): Command => ({ state, dispatch }) => {
|
||||
splitCell: () => ({ state, dispatch }) => {
|
||||
return splitCell(state, dispatch)
|
||||
},
|
||||
toggleHeaderColumn: (): Command => ({ state, dispatch }) => {
|
||||
toggleHeaderColumn: () => ({ state, dispatch }) => {
|
||||
return toggleHeaderColumn(state, dispatch)
|
||||
},
|
||||
toggleHeaderRow: (): Command => ({ state, dispatch }) => {
|
||||
toggleHeaderRow: () => ({ state, dispatch }) => {
|
||||
return toggleHeaderRow(state, dispatch)
|
||||
},
|
||||
toggleHeaderCell: (): Command => ({ state, dispatch }) => {
|
||||
toggleHeaderCell: () => ({ state, dispatch }) => {
|
||||
return toggleHeaderCell(state, dispatch)
|
||||
},
|
||||
mergeOrSplit: (): Command => ({ state, dispatch }) => {
|
||||
mergeOrSplit: () => ({ state, dispatch }) => {
|
||||
if (mergeCells(state, dispatch)) {
|
||||
return true
|
||||
}
|
||||
|
||||
return splitCell(state, dispatch)
|
||||
},
|
||||
setCellAttribute: (name: string, value: any): Command => ({ state, dispatch }) => {
|
||||
setCellAttribute: (name, value) => ({ state, dispatch }) => {
|
||||
return setCellAttr(name, value)(state, dispatch)
|
||||
},
|
||||
goToNextCell: (): Command => ({ state, dispatch }) => {
|
||||
goToNextCell: () => ({ state, dispatch }) => {
|
||||
return goToNextCell(1)(state, dispatch)
|
||||
},
|
||||
goToPreviousCell: (): Command => ({ state, dispatch }) => {
|
||||
goToPreviousCell: () => ({ state, dispatch }) => {
|
||||
return goToNextCell(-1)(state, dispatch)
|
||||
},
|
||||
fixTables: (): Command => ({ state, dispatch }) => {
|
||||
fixTables: () => ({ state, dispatch }) => {
|
||||
if (dispatch) {
|
||||
fixTables(state)
|
||||
}
|
||||
@ -223,9 +246,3 @@ export const Table = Node.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Table: typeof Table,
|
||||
}
|
||||
}
|
||||
|
@ -139,9 +139,3 @@ export const TaskItem = Node.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
TaskItem: typeof TaskItem,
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,12 @@ export interface TaskListOptions {
|
||||
},
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
toggleTaskList: () => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const TaskList = Node.create({
|
||||
name: 'taskList',
|
||||
|
||||
@ -35,7 +41,7 @@ export const TaskList = Node.create({
|
||||
/**
|
||||
* Toggle a task list
|
||||
*/
|
||||
toggleTaskList: (): Command => ({ commands }) => {
|
||||
toggleTaskList: () => ({ commands }) => {
|
||||
return commands.toggleList('taskList', 'taskItem')
|
||||
},
|
||||
}
|
||||
@ -47,9 +53,3 @@ export const TaskList = Node.create({
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
TaskList: typeof TaskList,
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,13 @@ type TextAlignOptions = {
|
||||
defaultAlignment: string,
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setTextAlign: (alignment: string) => Command,
|
||||
unsetTextAlign: () => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const TextAlign = Extension.create({
|
||||
name: 'textAlign',
|
||||
|
||||
@ -39,7 +46,7 @@ export const TextAlign = Extension.create({
|
||||
/**
|
||||
* Set the text align attribute
|
||||
*/
|
||||
setTextAlign: (alignment: string): Command => ({ commands }) => {
|
||||
setTextAlign: (alignment: string) => ({ commands }) => {
|
||||
if (!this.options.alignments.includes(alignment)) {
|
||||
return false
|
||||
}
|
||||
@ -49,7 +56,7 @@ export const TextAlign = Extension.create({
|
||||
/**
|
||||
* Unset the text align attribute
|
||||
*/
|
||||
unsetTextAlign: (): Command => ({ commands }) => {
|
||||
unsetTextAlign: () => ({ commands }) => {
|
||||
return this.options.types.every(type => commands.resetNodeAttributes(type, 'textAlign'))
|
||||
},
|
||||
}
|
||||
@ -64,9 +71,3 @@ export const TextAlign = Extension.create({
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
TextAlign: typeof TextAlign,
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,12 @@ export interface TextStyleOptions {
|
||||
},
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
removeEmptyTextStyle: () => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const TextStyle = Mark.create({
|
||||
name: 'textStyle',
|
||||
|
||||
@ -44,7 +50,7 @@ export const TextStyle = Mark.create({
|
||||
/**
|
||||
* Remove spans without inline style attributes.
|
||||
*/
|
||||
removeEmptyTextStyle: (): Command => ({ state, commands }) => {
|
||||
removeEmptyTextStyle: () => ({ state, commands }) => {
|
||||
const attributes = getMarkAttributes(state, this.type)
|
||||
const hasStyles = Object.entries(attributes).every(([, value]) => !!value)
|
||||
|
||||
@ -58,9 +64,3 @@ export const TextStyle = Mark.create({
|
||||
},
|
||||
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
TextStyle: typeof TextStyle,
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,3 @@ export const Text = Node.create({
|
||||
name: 'text',
|
||||
group: 'inline',
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Text: typeof Text,
|
||||
}
|
||||
}
|
||||
|
@ -44,9 +44,3 @@ export const Typography = Extension.create({
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Typography: typeof Typography,
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,14 @@ export interface UnderlineOptions {
|
||||
},
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setUnderline: () => Command,
|
||||
toggleUnderline: () => Command,
|
||||
unsetUnderline: () => Command,
|
||||
}
|
||||
}
|
||||
|
||||
export const Underline = Mark.create({
|
||||
name: 'underline',
|
||||
|
||||
@ -33,19 +41,19 @@ export const Underline = Mark.create({
|
||||
/**
|
||||
* Set an underline mark
|
||||
*/
|
||||
setUnderline: (): Command => ({ commands }) => {
|
||||
setUnderline: () => ({ commands }) => {
|
||||
return commands.setMark('underline')
|
||||
},
|
||||
/**
|
||||
* Toggle an underline mark
|
||||
*/
|
||||
toggleUnderline: (): Command => ({ commands }) => {
|
||||
toggleUnderline: () => ({ commands }) => {
|
||||
return commands.toggleMark('underline')
|
||||
},
|
||||
/**
|
||||
* Unset an underline mark
|
||||
*/
|
||||
unsetUnderline: (): Command => ({ commands }) => {
|
||||
unsetUnderline: () => ({ commands }) => {
|
||||
return commands.unsetMark('underline')
|
||||
},
|
||||
}
|
||||
@ -57,9 +65,3 @@ export const Underline = Mark.create({
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllExtensions {
|
||||
Underline: typeof Underline,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user