mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-11 11:45:15 +08:00
refactoring
This commit is contained in:
parent
f70974678b
commit
55ff908423
@ -9,6 +9,9 @@ export interface IframeOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Add an iframe
|
||||||
|
*/
|
||||||
setIframe: (options: { src: string }) => Command,
|
setIframe: (options: { src: string }) => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,9 +61,6 @@ export default Node.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Add an iframe
|
|
||||||
*/
|
|
||||||
setIframe: (options: { src: string }) => ({ tr, dispatch }) => {
|
setIframe: (options: { src: string }) => ({ tr, dispatch }) => {
|
||||||
const { selection } = tr
|
const { selection } = tr
|
||||||
const node = this.type.create(options)
|
const node = this.type.create(options)
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Removes focus from the editor.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Removes focus from the editor.
|
||||||
|
*/
|
||||||
|
blur: () => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const blur: Commands['blur'] = () => ({ view }) => {
|
export const blur: Commands['blur'] = () => ({ view }) => {
|
||||||
const element = view.dom as HTMLElement
|
const element = view.dom as HTMLElement
|
||||||
|
|
||||||
@ -10,9 +16,3 @@ export const blur: Commands['blur'] = () => ({ view }) => {
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
blur: () => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear the whole document.
|
|
||||||
*/
|
|
||||||
export const clearContent: Commands['clearContent'] = (emitUpdate = false) => ({ commands }) => {
|
|
||||||
return commands.setContent('', emitUpdate)
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Clear the whole document.
|
||||||
|
*/
|
||||||
clearContent: (emitUpdate: Boolean) => Command,
|
clearContent: (emitUpdate: Boolean) => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const clearContent: Commands['clearContent'] = (emitUpdate = false) => ({ commands }) => {
|
||||||
|
return commands.setContent('', emitUpdate)
|
||||||
|
}
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
import { liftTarget } from 'prosemirror-transform'
|
import { liftTarget } from 'prosemirror-transform'
|
||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Normalize nodes to a simple paragraph.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Normalize nodes to a simple paragraph.
|
||||||
|
*/
|
||||||
|
clearNodes: () => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const clearNodes: Commands['clearNodes'] = () => ({ state, tr, dispatch }) => {
|
export const clearNodes: Commands['clearNodes'] = () => ({ state, tr, dispatch }) => {
|
||||||
const { selection } = tr
|
const { selection } = tr
|
||||||
const { from, to } = selection
|
const { from, to } = selection
|
||||||
@ -30,9 +36,3 @@ export const clearNodes: Commands['clearNodes'] = () => ({ state, tr, dispatch }
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
clearNodes: () => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
|
||||||
* Define a command inline.
|
|
||||||
*/
|
|
||||||
export const command: Commands['command'] = fn => props => {
|
|
||||||
return fn(props)
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Define a command inline.
|
||||||
|
*/
|
||||||
command: (fn: (props: Parameters<Command>[0]) => boolean) => Command,
|
command: (fn: (props: Parameters<Command>[0]) => boolean) => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const command: Commands['command'] = fn => props => {
|
||||||
|
return fn(props)
|
||||||
|
}
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { createParagraphNear as originalCreateParagraphNear } from 'prosemirror-commands'
|
import { createParagraphNear as originalCreateParagraphNear } from 'prosemirror-commands'
|
||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a paragraph nearby.
|
|
||||||
*/
|
|
||||||
export const createParagraphNear: Commands['createParagraphNear'] = () => ({ state, dispatch }) => {
|
|
||||||
return originalCreateParagraphNear(state, dispatch)
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Create a paragraph nearby.
|
||||||
|
*/
|
||||||
createParagraphNear: () => Command,
|
createParagraphNear: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const createParagraphNear: Commands['createParagraphNear'] = () => ({ state, dispatch }) => {
|
||||||
|
return originalCreateParagraphNear(state, dispatch)
|
||||||
|
}
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
import { Command, Commands, Range } from '../types'
|
import { Command, Commands, Range } from '../types'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Delete a given range.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Delete a given range.
|
||||||
|
*/
|
||||||
|
deleteRange: (range: Range) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const deleteRange: Commands['deleteRange'] = range => ({ tr, dispatch }) => {
|
export const deleteRange: Commands['deleteRange'] = range => ({ tr, dispatch }) => {
|
||||||
const { from, to } = range
|
const { from, to } = range
|
||||||
|
|
||||||
@ -12,9 +18,3 @@ export const deleteRange: Commands['deleteRange'] = range => ({ tr, dispatch })
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
deleteRange: (range: Range) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { deleteSelection as originalDeleteSelection } from 'prosemirror-commands'
|
import { deleteSelection as originalDeleteSelection } from 'prosemirror-commands'
|
||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete the selection, if there is one.
|
|
||||||
*/
|
|
||||||
export const deleteSelection: Commands['deleteSelection'] = () => ({ state, dispatch }) => {
|
|
||||||
return originalDeleteSelection(state, dispatch)
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Delete the selection, if there is one.
|
||||||
|
*/
|
||||||
deleteSelection: () => Command,
|
deleteSelection: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const deleteSelection: Commands['deleteSelection'] = () => ({ state, dispatch }) => {
|
||||||
|
return originalDeleteSelection(state, dispatch)
|
||||||
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
|
||||||
* Trigger enter.
|
|
||||||
*/
|
|
||||||
export const enter: Commands['enter'] = () => ({ commands }) => {
|
|
||||||
return commands.keyboardShortcut('Enter')
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Trigger enter.
|
||||||
|
*/
|
||||||
enter: () => Command,
|
enter: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const enter: Commands['enter'] = () => ({ commands }) => {
|
||||||
|
return commands.keyboardShortcut('Enter')
|
||||||
|
}
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { exitCode as originalExitCode } from 'prosemirror-commands'
|
import { exitCode as originalExitCode } from 'prosemirror-commands'
|
||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
|
||||||
* Exit from a code block.
|
|
||||||
*/
|
|
||||||
export const exitCode: Commands['exitCode'] = () => ({ state, dispatch }) => {
|
|
||||||
return originalExitCode(state, dispatch)
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Exit from a code block.
|
||||||
|
*/
|
||||||
exitCode: () => Command,
|
exitCode: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const exitCode: Commands['exitCode'] = () => ({ state, dispatch }) => {
|
||||||
|
return originalExitCode(state, dispatch)
|
||||||
|
}
|
||||||
|
@ -4,9 +4,15 @@ import { Command, Commands } from '../types'
|
|||||||
import getMarkType from '../helpers/getMarkType'
|
import getMarkType from '../helpers/getMarkType'
|
||||||
import getMarkRange from '../helpers/getMarkRange'
|
import getMarkRange from '../helpers/getMarkRange'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Extends the text selection to the current mark.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Extends the text selection to the current mark.
|
||||||
|
*/
|
||||||
|
extendMarkRange: (typeOrName: string | MarkType) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const extendMarkRange: Commands['extendMarkRange'] = typeOrName => ({ tr, state, dispatch }) => {
|
export const extendMarkRange: Commands['extendMarkRange'] = typeOrName => ({ tr, state, dispatch }) => {
|
||||||
const type = getMarkType(typeOrName, state.schema)
|
const type = getMarkType(typeOrName, state.schema)
|
||||||
const { doc, selection } = tr
|
const { doc, selection } = tr
|
||||||
@ -24,9 +30,3 @@ export const extendMarkRange: Commands['extendMarkRange'] = typeOrName => ({ tr,
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
extendMarkRange: (typeOrName: string | MarkType) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Runs one command after the other and stops at the first which returns true.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Runs one command after the other and stops at the first which returns true.
|
||||||
|
*/
|
||||||
|
first: (commands: Command[] | ((props: Parameters<Command>[0]) => Command[])) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const first: Commands['first'] = commands => props => {
|
export const first: Commands['first'] = commands => props => {
|
||||||
const items = typeof commands === 'function'
|
const items = typeof commands === 'function'
|
||||||
? commands(props)
|
? commands(props)
|
||||||
@ -16,9 +22,3 @@ export const first: Commands['first'] = commands => props => {
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
first: (commands: Command[] | ((props: Parameters<Command>[0]) => Command[])) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -30,9 +30,15 @@ function resolveSelection(state: EditorState, position: FocusPosition = null) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Focus the editor at the given position.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Focus the editor at the given position.
|
||||||
|
*/
|
||||||
|
focus: (position?: FocusPosition) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const focus: Commands['focus'] = (position = null) => ({
|
export const focus: Commands['focus'] = (position = null) => ({
|
||||||
editor,
|
editor,
|
||||||
view,
|
view,
|
||||||
@ -62,9 +68,3 @@ export const focus: Commands['focus'] = (position = null) => ({
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
focus: (position?: FocusPosition) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -17,9 +17,15 @@ function selectionToInsertionEnd(tr: Transaction, startLen: number, bias: number
|
|||||||
tr.setSelection(Selection.near(tr.doc.resolve(end as unknown as number), bias))
|
tr.setSelection(Selection.near(tr.doc.resolve(end as unknown as number), bias))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Insert a string of HTML at the current position.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Insert a string of HTML at the current position.
|
||||||
|
*/
|
||||||
|
insertHTML: (value: string) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const insertHTML: Commands['insertHTML'] = value => ({ tr, state, dispatch }) => {
|
export const insertHTML: Commands['insertHTML'] = value => ({ tr, state, dispatch }) => {
|
||||||
const { selection } = tr
|
const { selection } = tr
|
||||||
const element = elementFromString(value)
|
const element = elementFromString(value)
|
||||||
@ -32,9 +38,3 @@ export const insertHTML: Commands['insertHTML'] = value => ({ tr, state, dispatc
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
insertHTML: (value: string) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Insert a string of text at the current position.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Insert a string of text at the current position.
|
||||||
|
*/
|
||||||
|
insertText: (value: string) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const insertText: Commands['insertText'] = value => ({ tr, dispatch }) => {
|
export const insertText: Commands['insertText'] = value => ({ tr, dispatch }) => {
|
||||||
if (dispatch) {
|
if (dispatch) {
|
||||||
tr.insertText(value)
|
tr.insertText(value)
|
||||||
@ -10,9 +16,3 @@ export const insertText: Commands['insertText'] = value => ({ tr, dispatch }) =>
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
insertText: (value: string) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { joinBackward as originalJoinBackward } from 'prosemirror-commands'
|
import { joinBackward as originalJoinBackward } from 'prosemirror-commands'
|
||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
|
||||||
* Join two nodes backward.
|
|
||||||
*/
|
|
||||||
export const joinBackward: Commands['joinBackward'] = () => ({ state, dispatch }) => {
|
|
||||||
return originalJoinBackward(state, dispatch)
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Join two nodes backward.
|
||||||
|
*/
|
||||||
joinBackward: () => Command,
|
joinBackward: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const joinBackward: Commands['joinBackward'] = () => ({ state, dispatch }) => {
|
||||||
|
return originalJoinBackward(state, dispatch)
|
||||||
|
}
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { joinForward as originalJoinForward } from 'prosemirror-commands'
|
import { joinForward as originalJoinForward } from 'prosemirror-commands'
|
||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
|
||||||
* Join two nodes forward.
|
|
||||||
*/
|
|
||||||
export const joinForward: Commands['joinForward'] = () => ({ state, dispatch }) => {
|
|
||||||
return originalJoinForward(state, dispatch)
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Join two nodes forward.
|
||||||
|
*/
|
||||||
joinForward: () => Command,
|
joinForward: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const joinForward: Commands['joinForward'] = () => ({ state, dispatch }) => {
|
||||||
|
return originalJoinForward(state, dispatch)
|
||||||
|
}
|
||||||
|
@ -56,9 +56,15 @@ function normalizeKeyName(name: string) {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Trigger a keyboard shortcut.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Trigger a keyboard shortcut.
|
||||||
|
*/
|
||||||
|
keyboardShortcut: (name: string) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const keyboardShortcut: Commands['keyboardShortcut'] = name => ({
|
export const keyboardShortcut: Commands['keyboardShortcut'] = name => ({
|
||||||
editor,
|
editor,
|
||||||
view,
|
view,
|
||||||
@ -93,9 +99,3 @@ export const keyboardShortcut: Commands['keyboardShortcut'] = name => ({
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
keyboardShortcut: (name: string) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -4,9 +4,15 @@ import { Command, Commands, AnyObject } from '../types'
|
|||||||
import isNodeActive from '../helpers/isNodeActive'
|
import isNodeActive from '../helpers/isNodeActive'
|
||||||
import getNodeType from '../helpers/getNodeType'
|
import getNodeType from '../helpers/getNodeType'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Removes an existing wrap.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Removes an existing wrap.
|
||||||
|
*/
|
||||||
|
lift: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const lift: Commands['lift'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
export const lift: Commands['lift'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||||
const type = getNodeType(typeOrName, state.schema)
|
const type = getNodeType(typeOrName, state.schema)
|
||||||
const isActive = isNodeActive(state, type, attributes)
|
const isActive = isNodeActive(state, type, attributes)
|
||||||
@ -17,9 +23,3 @@ export const lift: Commands['lift'] = (typeOrName, attributes = {}) => ({ state,
|
|||||||
|
|
||||||
return originalLift(state, dispatch)
|
return originalLift(state, dispatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
lift: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { liftEmptyBlock as originalLiftEmptyBlock } from 'prosemirror-commands'
|
import { liftEmptyBlock as originalLiftEmptyBlock } from 'prosemirror-commands'
|
||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
|
||||||
* Lift block if empty.
|
|
||||||
*/
|
|
||||||
export const liftEmptyBlock: Commands['liftEmptyBlock'] = () => ({ state, dispatch }) => {
|
|
||||||
return originalLiftEmptyBlock(state, dispatch)
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Lift block if empty.
|
||||||
|
*/
|
||||||
liftEmptyBlock: () => Command,
|
liftEmptyBlock: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const liftEmptyBlock: Commands['liftEmptyBlock'] = () => ({ state, dispatch }) => {
|
||||||
|
return originalLiftEmptyBlock(state, dispatch)
|
||||||
|
}
|
||||||
|
@ -3,17 +3,17 @@ import { NodeType } from 'prosemirror-model'
|
|||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
import getNodeType from '../helpers/getNodeType'
|
import getNodeType from '../helpers/getNodeType'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Lift the list item into a wrapping list.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Lift the list item into a wrapping list.
|
||||||
|
*/
|
||||||
|
liftListItem: (typeOrName: string | NodeType) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const liftListItem: Commands['liftListItem'] = typeOrName => ({ state, dispatch }) => {
|
export const liftListItem: Commands['liftListItem'] = typeOrName => ({ state, dispatch }) => {
|
||||||
const type = getNodeType(typeOrName, state.schema)
|
const type = getNodeType(typeOrName, state.schema)
|
||||||
|
|
||||||
return originalLiftListItem(type)(state, dispatch)
|
return originalLiftListItem(type)(state, dispatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
liftListItem: (typeOrName: string | NodeType) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { newlineInCode as originalNewlineInCode } from 'prosemirror-commands'
|
import { newlineInCode as originalNewlineInCode } from 'prosemirror-commands'
|
||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a newline character in code.
|
|
||||||
*/
|
|
||||||
export const newlineInCode: Commands['newlineInCode'] = () => ({ state, dispatch }) => {
|
|
||||||
return originalNewlineInCode(state, dispatch)
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Add a newline character in code.
|
||||||
|
*/
|
||||||
newlineInCode: () => Command,
|
newlineInCode: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const newlineInCode: Commands['newlineInCode'] = () => ({ state, dispatch }) => {
|
||||||
|
return originalNewlineInCode(state, dispatch)
|
||||||
|
}
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
import { NodeType } from 'prosemirror-model'
|
import { NodeType } from 'prosemirror-model'
|
||||||
import { Command, Commands, AnyObject } from '../types'
|
import { Command, Commands, AnyObject } from '../types'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Replaces text with a node.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Replaces text with a node.
|
||||||
|
*/
|
||||||
|
replace: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const replace: Commands['replace'] = (typeOrName, attributes = {}) => ({ state, commands }) => {
|
export const replace: Commands['replace'] = (typeOrName, attributes = {}) => ({ state, commands }) => {
|
||||||
const { from, to } = state.selection
|
const { from, to } = state.selection
|
||||||
const range = { from, to }
|
const range = { from, to }
|
||||||
|
|
||||||
return commands.replaceRange(range, typeOrName, attributes)
|
return commands.replaceRange(range, typeOrName, attributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
replace: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -7,9 +7,15 @@ import {
|
|||||||
AnyObject,
|
AnyObject,
|
||||||
} from '../types'
|
} from '../types'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Replaces text with a node within a range.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Replaces text with a node within a range.
|
||||||
|
*/
|
||||||
|
replaceRange: (range: Range, typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const replaceRange: Commands['replaceRange'] = (range, typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
|
export const replaceRange: Commands['replaceRange'] = (range, typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
|
||||||
const type = getNodeType(typeOrName, state.schema)
|
const type = getNodeType(typeOrName, state.schema)
|
||||||
const { from, to } = range
|
const { from, to } = range
|
||||||
@ -26,9 +32,3 @@ export const replaceRange: Commands['replaceRange'] = (range, typeOrName, attrib
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
replaceRange: (range: Range, typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -3,9 +3,15 @@ import getNodeType from '../helpers/getNodeType'
|
|||||||
import deleteProps from '../utilities/deleteProps'
|
import deleteProps from '../utilities/deleteProps'
|
||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Resets node attributes to the default value.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Resets node attributes to the default value.
|
||||||
|
*/
|
||||||
|
resetNodeAttributes: (typeOrName: string | NodeType, attributes: string | string[]) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const resetNodeAttributes: Commands['resetNodeAttributes'] = (typeOrName, attributes) => ({ tr, state, dispatch }) => {
|
export const resetNodeAttributes: Commands['resetNodeAttributes'] = (typeOrName, attributes) => ({ tr, state, dispatch }) => {
|
||||||
const type = getNodeType(typeOrName, state.schema)
|
const type = getNodeType(typeOrName, state.schema)
|
||||||
const { selection } = tr
|
const { selection } = tr
|
||||||
@ -19,9 +25,3 @@ export const resetNodeAttributes: Commands['resetNodeAttributes'] = (typeOrName,
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
resetNodeAttributes: (typeOrName: string | NodeType, attributes: string | string[]) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Scroll the selection into view.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Scroll the selection into view.
|
||||||
|
*/
|
||||||
|
scrollIntoView: () => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const scrollIntoView: Commands['scrollIntoView'] = () => ({ tr, dispatch }) => {
|
export const scrollIntoView: Commands['scrollIntoView'] = () => ({ tr, dispatch }) => {
|
||||||
if (dispatch) {
|
if (dispatch) {
|
||||||
tr.scrollIntoView()
|
tr.scrollIntoView()
|
||||||
@ -10,9 +16,3 @@ export const scrollIntoView: Commands['scrollIntoView'] = () => ({ tr, dispatch
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
scrollIntoView: () => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { selectAll as originalSelectAll } from 'prosemirror-commands'
|
import { selectAll as originalSelectAll } from 'prosemirror-commands'
|
||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
|
||||||
* Select the whole document.
|
|
||||||
*/
|
|
||||||
export const selectAll: Commands['selectAll'] = () => ({ state, dispatch }) => {
|
|
||||||
return originalSelectAll(state, dispatch)
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Select the whole document.
|
||||||
|
*/
|
||||||
selectAll: () => Command,
|
selectAll: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const selectAll: Commands['selectAll'] = () => ({ state, dispatch }) => {
|
||||||
|
return originalSelectAll(state, dispatch)
|
||||||
|
}
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { selectNodeBackward as originalSelectNodeBackward } from 'prosemirror-commands'
|
import { selectNodeBackward as originalSelectNodeBackward } from 'prosemirror-commands'
|
||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
|
||||||
* Select a node backward.
|
|
||||||
*/
|
|
||||||
export const selectNodeBackward: Commands['selectNodeBackward'] = () => ({ state, dispatch }) => {
|
|
||||||
return originalSelectNodeBackward(state, dispatch)
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Select a node backward.
|
||||||
|
*/
|
||||||
selectNodeBackward: () => Command,
|
selectNodeBackward: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const selectNodeBackward: Commands['selectNodeBackward'] = () => ({ state, dispatch }) => {
|
||||||
|
return originalSelectNodeBackward(state, dispatch)
|
||||||
|
}
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { selectNodeForward as originalSelectNodeForward } from 'prosemirror-commands'
|
import { selectNodeForward as originalSelectNodeForward } from 'prosemirror-commands'
|
||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
|
||||||
* Select a node forward.
|
|
||||||
*/
|
|
||||||
export const selectNodeForward: Commands['selectNodeForward'] = () => ({ state, dispatch }) => {
|
|
||||||
return originalSelectNodeForward(state, dispatch)
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Select a node forward.
|
||||||
|
*/
|
||||||
selectNodeForward: () => Command,
|
selectNodeForward: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const selectNodeForward: Commands['selectNodeForward'] = () => ({ state, dispatch }) => {
|
||||||
|
return originalSelectNodeForward(state, dispatch)
|
||||||
|
}
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { selectParentNode as originalSelectParentNode } from 'prosemirror-commands'
|
import { selectParentNode as originalSelectParentNode } from 'prosemirror-commands'
|
||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
|
||||||
* Select the parent node.
|
|
||||||
*/
|
|
||||||
export const selectParentNode: Commands['selectParentNode'] = () => ({ state, dispatch }) => {
|
|
||||||
return originalSelectParentNode(state, dispatch)
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Select the parent node.
|
||||||
|
*/
|
||||||
selectParentNode: () => Command,
|
selectParentNode: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const selectParentNode: Commands['selectParentNode'] = () => ({ state, dispatch }) => {
|
||||||
|
return originalSelectParentNode(state, dispatch)
|
||||||
|
}
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
import { TextSelection } from 'prosemirror-state'
|
import { TextSelection } from 'prosemirror-state'
|
||||||
import { AnyObject, Command, Commands } from '../types'
|
import { AnyObject, Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Replace the whole document with new content.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Replace the whole document with new content.
|
||||||
|
*/
|
||||||
|
setContent: (content: string, emitUpdate?: Boolean, parseOptions?: AnyObject) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const setContent: Commands['setContent'] = (content, emitUpdate = false, parseOptions = {}) => ({ tr, editor, dispatch }) => {
|
export const setContent: Commands['setContent'] = (content, emitUpdate = false, parseOptions = {}) => ({ tr, editor, dispatch }) => {
|
||||||
const { createDocument } = editor
|
const { createDocument } = editor
|
||||||
const { doc } = tr
|
const { doc } = tr
|
||||||
@ -18,9 +24,3 @@ export const setContent: Commands['setContent'] = (content, emitUpdate = false,
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
setContent: (content: string, emitUpdate?: Boolean, parseOptions?: AnyObject) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -3,9 +3,15 @@ import { AnyObject, Command, Commands } from '../types'
|
|||||||
import getMarkType from '../helpers/getMarkType'
|
import getMarkType from '../helpers/getMarkType'
|
||||||
import getMarkAttributes from '../helpers/getMarkAttributes'
|
import getMarkAttributes from '../helpers/getMarkAttributes'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Add a mark with new attributes.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Add a mark with new attributes.
|
||||||
|
*/
|
||||||
|
setMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const setMark: Commands['setMark'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
|
export const setMark: Commands['setMark'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
|
||||||
const { selection } = tr
|
const { selection } = tr
|
||||||
const { from, to, empty } = selection
|
const { from, to, empty } = selection
|
||||||
@ -26,9 +32,3 @@ export const setMark: Commands['setMark'] = (typeOrName, attributes = {}) => ({
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
setMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -3,17 +3,17 @@ import { setBlockType } from 'prosemirror-commands'
|
|||||||
import { AnyObject, Command, Commands } from '../types'
|
import { AnyObject, Command, Commands } from '../types'
|
||||||
import getNodeType from '../helpers/getNodeType'
|
import getNodeType from '../helpers/getNodeType'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Replace a given range with a node.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Replace a given range with a node.
|
||||||
|
*/
|
||||||
|
setNode: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const setNode: Commands['setNode'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
export const setNode: Commands['setNode'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||||
const type = getNodeType(typeOrName, state.schema)
|
const type = getNodeType(typeOrName, state.schema)
|
||||||
|
|
||||||
return setBlockType(type, attributes)(state, dispatch)
|
return setBlockType(type, attributes)(state, dispatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
setNode: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -3,17 +3,17 @@ import { NodeType } from 'prosemirror-model'
|
|||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
import getNodeType from '../helpers/getNodeType'
|
import getNodeType from '../helpers/getNodeType'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Sink the list item down into an inner list.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Sink the list item down into an inner list.
|
||||||
|
*/
|
||||||
|
sinkListItem: (typeOrName: string | NodeType) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const sinkListItem: Commands['sinkListItem'] = typeOrName => ({ state, dispatch }) => {
|
export const sinkListItem: Commands['sinkListItem'] = typeOrName => ({ state, dispatch }) => {
|
||||||
const type = getNodeType(typeOrName, state.schema)
|
const type = getNodeType(typeOrName, state.schema)
|
||||||
|
|
||||||
return originalSinkListItem(type)(state, dispatch)
|
return originalSinkListItem(type)(state, dispatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
sinkListItem: (typeOrName: string | NodeType) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -15,11 +15,7 @@ function defaultBlockAt(match: ContentMatch) {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SplitBlockOptions {
|
function ensureMarks(state: EditorState) {
|
||||||
keepMarks: boolean,
|
|
||||||
}
|
|
||||||
|
|
||||||
function keepMarks(state: EditorState) {
|
|
||||||
const marks = state.storedMarks
|
const marks = state.storedMarks
|
||||||
|| (state.selection.$to.parentOffset && state.selection.$from.marks())
|
|| (state.selection.$to.parentOffset && state.selection.$from.marks())
|
||||||
|
|
||||||
@ -28,19 +24,21 @@ function keepMarks(state: EditorState) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Forks a new node from an existing node.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
export const splitBlock: Commands['splitBlock'] = (options = {}) => ({
|
* Forks a new node from an existing node.
|
||||||
|
*/
|
||||||
|
splitBlock: (options?: { keepMarks?: boolean }) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const splitBlock: Commands['splitBlock'] = ({ keepMarks = true } = {}) => ({
|
||||||
tr,
|
tr,
|
||||||
state,
|
state,
|
||||||
dispatch,
|
dispatch,
|
||||||
editor,
|
editor,
|
||||||
}) => {
|
}) => {
|
||||||
const defaultOptions: SplitBlockOptions = {
|
|
||||||
keepMarks: true,
|
|
||||||
}
|
|
||||||
const config = { ...defaultOptions, ...options }
|
|
||||||
const { selection, doc } = tr
|
const { selection, doc } = tr
|
||||||
const { $from, $to } = selection
|
const { $from, $to } = selection
|
||||||
const extensionAttributes = editor.extensionManager.attributes
|
const extensionAttributes = editor.extensionManager.attributes
|
||||||
@ -56,8 +54,8 @@ export const splitBlock: Commands['splitBlock'] = (options = {}) => ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dispatch) {
|
if (dispatch) {
|
||||||
if (config.keepMarks) {
|
if (keepMarks) {
|
||||||
keepMarks(state)
|
ensureMarks(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
tr.split($from.pos).scrollIntoView()
|
tr.split($from.pos).scrollIntoView()
|
||||||
@ -117,8 +115,8 @@ export const splitBlock: Commands['splitBlock'] = (options = {}) => ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.keepMarks) {
|
if (keepMarks) {
|
||||||
keepMarks(state)
|
ensureMarks(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
tr.scrollIntoView()
|
tr.scrollIntoView()
|
||||||
@ -126,9 +124,3 @@ export const splitBlock: Commands['splitBlock'] = (options = {}) => ({
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
splitBlock: (options?: Partial<SplitBlockOptions>) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -10,9 +10,15 @@ import { Command, Commands } from '../types'
|
|||||||
import getNodeType from '../helpers/getNodeType'
|
import getNodeType from '../helpers/getNodeType'
|
||||||
import getSplittedAttributes from '../helpers/getSplittedAttributes'
|
import getSplittedAttributes from '../helpers/getSplittedAttributes'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Splits one list item into two list items.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Splits one list item into two list items.
|
||||||
|
*/
|
||||||
|
splitListItem: (typeOrName: string | NodeType) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const splitListItem: Commands['splitListItem'] = typeOrName => ({
|
export const splitListItem: Commands['splitListItem'] = typeOrName => ({
|
||||||
tr, state, dispatch, editor,
|
tr, state, dispatch, editor,
|
||||||
}) => {
|
}) => {
|
||||||
@ -110,9 +116,3 @@ export const splitListItem: Commands['splitListItem'] = typeOrName => ({
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
splitListItem: (typeOrName: string | NodeType) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -4,9 +4,15 @@ import getNodeType from '../helpers/getNodeType'
|
|||||||
import findParentNode from '../helpers/findParentNode'
|
import findParentNode from '../helpers/findParentNode'
|
||||||
import isList from '../helpers/isList'
|
import isList from '../helpers/isList'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Toggle between different list types.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Toggle between different list types.
|
||||||
|
*/
|
||||||
|
toggleList: (listTypeOrName: string | NodeType, itemTypeOrName: string | NodeType) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const toggleList: Commands['toggleList'] = (listTypeOrName, itemTypeOrName) => ({
|
export const toggleList: Commands['toggleList'] = (listTypeOrName, itemTypeOrName) => ({
|
||||||
editor, tr, state, dispatch, chain, commands, can,
|
editor, tr, state, dispatch, chain, commands, can,
|
||||||
}) => {
|
}) => {
|
||||||
@ -53,9 +59,3 @@ export const toggleList: Commands['toggleList'] = (listTypeOrName, itemTypeOrNam
|
|||||||
|
|
||||||
return commands.wrapInList(listType)
|
return commands.wrapInList(listType)
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
toggleList: (listTypeOrName: string | NodeType, itemTypeOrName: string | NodeType) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -3,9 +3,15 @@ import { AnyObject, Command, Commands } from '../types'
|
|||||||
import getMarkType from '../helpers/getMarkType'
|
import getMarkType from '../helpers/getMarkType'
|
||||||
import isMarkActive from '../helpers/isMarkActive'
|
import isMarkActive from '../helpers/isMarkActive'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Toggle a mark on and off.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Toggle a mark on and off.
|
||||||
|
*/
|
||||||
|
toggleMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const toggleMark: Commands['toggleMark'] = (typeOrName, attributes = {}) => ({ state, commands }) => {
|
export const toggleMark: Commands['toggleMark'] = (typeOrName, attributes = {}) => ({ state, commands }) => {
|
||||||
const type = getMarkType(typeOrName, state.schema)
|
const type = getMarkType(typeOrName, state.schema)
|
||||||
const isActive = isMarkActive(state, type, attributes)
|
const isActive = isMarkActive(state, type, attributes)
|
||||||
@ -16,9 +22,3 @@ export const toggleMark: Commands['toggleMark'] = (typeOrName, attributes = {})
|
|||||||
|
|
||||||
return commands.setMark(type, attributes)
|
return commands.setMark(type, attributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
toggleMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -3,9 +3,15 @@ import { AnyObject, Command, Commands } from '../types'
|
|||||||
import isNodeActive from '../helpers/isNodeActive'
|
import isNodeActive from '../helpers/isNodeActive'
|
||||||
import getNodeType from '../helpers/getNodeType'
|
import getNodeType from '../helpers/getNodeType'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Toggle a node with another node.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Toggle a node with another node.
|
||||||
|
*/
|
||||||
|
toggleNode: (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const toggleNode: Commands['toggleNode'] = (typeOrName, toggleTypeOrName, attributes = {}) => ({ state, commands }) => {
|
export const toggleNode: Commands['toggleNode'] = (typeOrName, toggleTypeOrName, attributes = {}) => ({ state, commands }) => {
|
||||||
const type = getNodeType(typeOrName, state.schema)
|
const type = getNodeType(typeOrName, state.schema)
|
||||||
const toggleType = getNodeType(toggleTypeOrName, state.schema)
|
const toggleType = getNodeType(toggleTypeOrName, state.schema)
|
||||||
@ -17,9 +23,3 @@ export const toggleNode: Commands['toggleNode'] = (typeOrName, toggleTypeOrName,
|
|||||||
|
|
||||||
return commands.setNode(type, attributes)
|
return commands.setNode(type, attributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
toggleNode: (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -4,9 +4,15 @@ import { AnyObject, Command, Commands } from '../types'
|
|||||||
import isNodeActive from '../helpers/isNodeActive'
|
import isNodeActive from '../helpers/isNodeActive'
|
||||||
import getNodeType from '../helpers/getNodeType'
|
import getNodeType from '../helpers/getNodeType'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Wraps nodes in another node, or removes an existing wrap.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Wraps nodes in another node, or removes an existing wrap.
|
||||||
|
*/
|
||||||
|
toggleWrap: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const toggleWrap: Commands['toggleWrap'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
export const toggleWrap: Commands['toggleWrap'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||||
const type = getNodeType(typeOrName, state.schema)
|
const type = getNodeType(typeOrName, state.schema)
|
||||||
const isActive = isNodeActive(state, type, attributes)
|
const isActive = isNodeActive(state, type, attributes)
|
||||||
@ -17,9 +23,3 @@ export const toggleWrap: Commands['toggleWrap'] = (typeOrName, attributes = {})
|
|||||||
|
|
||||||
return wrapIn(type, attributes)(state, dispatch)
|
return wrapIn(type, attributes)(state, dispatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
toggleWrap: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { undoInputRule as originalUndoInputRule } from 'prosemirror-inputrules'
|
import { undoInputRule as originalUndoInputRule } from 'prosemirror-inputrules'
|
||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
|
||||||
* Undo an input rule.
|
|
||||||
*/
|
|
||||||
export const undoInputRule: Commands['undoInputRule'] = () => ({ state, dispatch }) => {
|
|
||||||
return originalUndoInputRule(state, dispatch)
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Undo an input rule.
|
||||||
|
*/
|
||||||
undoInputRule: () => Command,
|
undoInputRule: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const undoInputRule: Commands['undoInputRule'] = () => ({ state, dispatch }) => {
|
||||||
|
return originalUndoInputRule(state, dispatch)
|
||||||
|
}
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
import { Command, Commands } from '../types'
|
import { Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Remove all marks in the current selection.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Remove all marks in the current selection.
|
||||||
|
*/
|
||||||
|
unsetAllMarks: () => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const unsetAllMarks: Commands['unsetAllMarks'] = () => ({ tr, state, dispatch }) => {
|
export const unsetAllMarks: Commands['unsetAllMarks'] = () => ({ tr, state, dispatch }) => {
|
||||||
const { selection } = tr
|
const { selection } = tr
|
||||||
const { from, to, empty } = selection
|
const { from, to, empty } = selection
|
||||||
@ -21,9 +27,3 @@ export const unsetAllMarks: Commands['unsetAllMarks'] = () => ({ tr, state, disp
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
unsetAllMarks: () => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -3,9 +3,15 @@ import { Command, Commands } from '../types'
|
|||||||
import getMarkType from '../helpers/getMarkType'
|
import getMarkType from '../helpers/getMarkType'
|
||||||
import getMarkRange from '../helpers/getMarkRange'
|
import getMarkRange from '../helpers/getMarkRange'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Remove all marks in the current selection.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Remove all marks in the current selection.
|
||||||
|
*/
|
||||||
|
unsetMark: (typeOrName: string | MarkType) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const unsetMark: Commands['unsetMark'] = typeOrName => ({ tr, state, dispatch }) => {
|
export const unsetMark: Commands['unsetMark'] = typeOrName => ({ tr, state, dispatch }) => {
|
||||||
const { selection } = tr
|
const { selection } = tr
|
||||||
const type = getMarkType(typeOrName, state.schema)
|
const type = getMarkType(typeOrName, state.schema)
|
||||||
@ -28,9 +34,3 @@ export const unsetMark: Commands['unsetMark'] = typeOrName => ({ tr, state, disp
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
unsetMark: (typeOrName: string | MarkType) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -2,9 +2,15 @@ import { NodeType } from 'prosemirror-model'
|
|||||||
import getNodeType from '../helpers/getNodeType'
|
import getNodeType from '../helpers/getNodeType'
|
||||||
import { AnyObject, Command, Commands } from '../types'
|
import { AnyObject, Command, Commands } from '../types'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Update attributes of a node.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Update attributes of a node.
|
||||||
|
*/
|
||||||
|
updateNodeAttributes: (typeOrName: string | NodeType, attributes: AnyObject) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const updateNodeAttributes: Commands['updateNodeAttributes'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
|
export const updateNodeAttributes: Commands['updateNodeAttributes'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
|
||||||
const type = getNodeType(typeOrName, state.schema)
|
const type = getNodeType(typeOrName, state.schema)
|
||||||
const { selection } = tr
|
const { selection } = tr
|
||||||
@ -21,9 +27,3 @@ export const updateNodeAttributes: Commands['updateNodeAttributes'] = (typeOrNam
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
updateNodeAttributes: (typeOrName: string | NodeType, attributes: AnyObject) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -4,9 +4,15 @@ import { AnyObject, Command, Commands } from '../types'
|
|||||||
import isNodeActive from '../helpers/isNodeActive'
|
import isNodeActive from '../helpers/isNodeActive'
|
||||||
import getNodeType from '../helpers/getNodeType'
|
import getNodeType from '../helpers/getNodeType'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Wraps nodes in another node.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Wraps nodes in another node.
|
||||||
|
*/
|
||||||
|
wrapIn: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const wrapIn: Commands['wrapIn'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
export const wrapIn: Commands['wrapIn'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||||
const type = getNodeType(typeOrName, state.schema)
|
const type = getNodeType(typeOrName, state.schema)
|
||||||
const isActive = isNodeActive(state, type, attributes)
|
const isActive = isNodeActive(state, type, attributes)
|
||||||
@ -17,9 +23,3 @@ export const wrapIn: Commands['wrapIn'] = (typeOrName, attributes = {}) => ({ st
|
|||||||
|
|
||||||
return originalWrapIn(type, attributes)(state, dispatch)
|
return originalWrapIn(type, attributes)(state, dispatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
wrapIn: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -3,17 +3,17 @@ import { NodeType } from 'prosemirror-model'
|
|||||||
import { AnyObject, Command, Commands } from '../types'
|
import { AnyObject, Command, Commands } from '../types'
|
||||||
import getNodeType from '../helpers/getNodeType'
|
import getNodeType from '../helpers/getNodeType'
|
||||||
|
|
||||||
/**
|
declare module '@tiptap/core' {
|
||||||
* Wrap a node in a list.
|
interface Commands {
|
||||||
*/
|
/**
|
||||||
|
* Wrap a node in a list.
|
||||||
|
*/
|
||||||
|
wrapInList: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const wrapInList: Commands['wrapInList'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
export const wrapInList: Commands['wrapInList'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||||
const type = getNodeType(typeOrName, state.schema)
|
const type = getNodeType(typeOrName, state.schema)
|
||||||
|
|
||||||
return originalWrapInList(type, attributes)(state, dispatch)
|
return originalWrapInList(type, attributes)(state, dispatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
|
||||||
interface Commands {
|
|
||||||
wrapInList: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -9,8 +9,17 @@ export interface BlockquoteOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Set a blockquote node
|
||||||
|
*/
|
||||||
setBlockquote: () => Command,
|
setBlockquote: () => Command,
|
||||||
|
/**
|
||||||
|
* Toggle a blockquote node
|
||||||
|
*/
|
||||||
toggleBlockquote: () => Command,
|
toggleBlockquote: () => Command,
|
||||||
|
/**
|
||||||
|
* Unset a blockquote node
|
||||||
|
*/
|
||||||
unsetBlockquote: () => Command,
|
unsetBlockquote: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,21 +52,12 @@ export const Blockquote = Node.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Set a blockquote node
|
|
||||||
*/
|
|
||||||
setBlockquote: () => ({ commands }) => {
|
setBlockquote: () => ({ commands }) => {
|
||||||
return commands.wrapIn('blockquote')
|
return commands.wrapIn('blockquote')
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Toggle a blockquote node
|
|
||||||
*/
|
|
||||||
toggleBlockquote: () => ({ commands }) => {
|
toggleBlockquote: () => ({ commands }) => {
|
||||||
return commands.toggleWrap('blockquote')
|
return commands.toggleWrap('blockquote')
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Unset a blockquote node
|
|
||||||
*/
|
|
||||||
unsetBlockquote: () => ({ commands }) => {
|
unsetBlockquote: () => ({ commands }) => {
|
||||||
return commands.lift('blockquote')
|
return commands.lift('blockquote')
|
||||||
},
|
},
|
||||||
|
@ -14,8 +14,17 @@ export interface BoldOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Set a bold mark
|
||||||
|
*/
|
||||||
setBold: () => Command,
|
setBold: () => Command,
|
||||||
|
/**
|
||||||
|
* Toggle a bold mark
|
||||||
|
*/
|
||||||
toggleBold: () => Command,
|
toggleBold: () => Command,
|
||||||
|
/**
|
||||||
|
* Unset a bold mark
|
||||||
|
*/
|
||||||
unsetBold: () => Command,
|
unsetBold: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -54,21 +63,12 @@ export const Bold = Mark.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Set a bold mark
|
|
||||||
*/
|
|
||||||
setBold: () => ({ commands }) => {
|
setBold: () => ({ commands }) => {
|
||||||
return commands.setMark('bold')
|
return commands.setMark('bold')
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Toggle a bold mark
|
|
||||||
*/
|
|
||||||
toggleBold: () => ({ commands }) => {
|
toggleBold: () => ({ commands }) => {
|
||||||
return commands.toggleMark('bold')
|
return commands.toggleMark('bold')
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Unset a bold mark
|
|
||||||
*/
|
|
||||||
unsetBold: () => ({ commands }) => {
|
unsetBold: () => ({ commands }) => {
|
||||||
return commands.unsetMark('bold')
|
return commands.unsetMark('bold')
|
||||||
},
|
},
|
||||||
|
@ -9,6 +9,9 @@ export interface BulletListOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Toggle a bullet list
|
||||||
|
*/
|
||||||
toggleBulletList: () => Command,
|
toggleBulletList: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -38,9 +41,6 @@ export const BulletList = Node.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Toggle a bullet list
|
|
||||||
*/
|
|
||||||
toggleBulletList: () => ({ commands }) => {
|
toggleBulletList: () => ({ commands }) => {
|
||||||
return commands.toggleList('bulletList', 'listItem')
|
return commands.toggleList('bulletList', 'listItem')
|
||||||
},
|
},
|
||||||
|
@ -10,7 +10,13 @@ export interface CodeBlockOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Set a code block
|
||||||
|
*/
|
||||||
setCodeBlock: (attributes?: { language: string }) => Command,
|
setCodeBlock: (attributes?: { language: string }) => Command,
|
||||||
|
/**
|
||||||
|
* Toggle a code block
|
||||||
|
*/
|
||||||
toggleCodeBlock: (attributes?: { language: string }) => Command,
|
toggleCodeBlock: (attributes?: { language: string }) => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,15 +87,9 @@ export const CodeBlock = Node.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Set a code block
|
|
||||||
*/
|
|
||||||
setCodeBlock: attributes => ({ commands }) => {
|
setCodeBlock: attributes => ({ commands }) => {
|
||||||
return commands.setNode('codeBlock', attributes)
|
return commands.setNode('codeBlock', attributes)
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Toggle a code block
|
|
||||||
*/
|
|
||||||
toggleCodeBlock: attributes => ({ commands }) => {
|
toggleCodeBlock: attributes => ({ commands }) => {
|
||||||
return commands.toggleNode('codeBlock', 'paragraph', attributes)
|
return commands.toggleNode('codeBlock', 'paragraph', attributes)
|
||||||
},
|
},
|
||||||
|
@ -14,8 +14,17 @@ export interface CodeOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Set a code mark
|
||||||
|
*/
|
||||||
setCode: () => Command,
|
setCode: () => Command,
|
||||||
|
/**
|
||||||
|
* Toggle inline code
|
||||||
|
*/
|
||||||
toggleCode: () => Command,
|
toggleCode: () => Command,
|
||||||
|
/**
|
||||||
|
* Unset a code mark
|
||||||
|
*/
|
||||||
unsetCode: () => Command,
|
unsetCode: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,21 +53,12 @@ export const Code = Mark.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Set a code mark
|
|
||||||
*/
|
|
||||||
setCode: () => ({ commands }) => {
|
setCode: () => ({ commands }) => {
|
||||||
return commands.setMark('code')
|
return commands.setMark('code')
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Toggle inline code
|
|
||||||
*/
|
|
||||||
toggleCode: () => ({ commands }) => {
|
toggleCode: () => ({ commands }) => {
|
||||||
return commands.toggleMark('code')
|
return commands.toggleMark('code')
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Unset a code mark
|
|
||||||
*/
|
|
||||||
unsetCode: () => ({ commands }) => {
|
unsetCode: () => ({ commands }) => {
|
||||||
return commands.unsetMark('code')
|
return commands.unsetMark('code')
|
||||||
},
|
},
|
||||||
|
@ -10,6 +10,9 @@ export interface CollaborationCursorOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Update details of the current user
|
||||||
|
*/
|
||||||
user: (attributes: AnyObject) => Command,
|
user: (attributes: AnyObject) => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -50,9 +53,6 @@ export const CollaborationCursor = Extension.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Update details of the current user
|
|
||||||
*/
|
|
||||||
user: attributes => () => {
|
user: attributes => () => {
|
||||||
this.options.user = attributes
|
this.options.user = attributes
|
||||||
|
|
||||||
|
@ -8,7 +8,13 @@ import {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Undo recent changes
|
||||||
|
*/
|
||||||
undo: () => Command,
|
undo: () => Command,
|
||||||
|
/**
|
||||||
|
* Reapply reverted changes
|
||||||
|
*/
|
||||||
redo: () => Command,
|
redo: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -39,17 +45,11 @@ export const Collaboration = Extension.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Undo recent changes
|
|
||||||
*/
|
|
||||||
undo: () => ({ tr, state }) => {
|
undo: () => ({ tr, state }) => {
|
||||||
tr.setMeta('preventDispatch', true)
|
tr.setMeta('preventDispatch', true)
|
||||||
|
|
||||||
return undo(state)
|
return undo(state)
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Reapply reverted changes
|
|
||||||
*/
|
|
||||||
redo: () => ({ tr, state }) => {
|
redo: () => ({ tr, state }) => {
|
||||||
tr.setMeta('preventDispatch', true)
|
tr.setMeta('preventDispatch', true)
|
||||||
|
|
||||||
|
@ -7,7 +7,13 @@ type FontFamilyOptions = {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Set the font family
|
||||||
|
*/
|
||||||
setFontFamily: (fontFamily: string) => Command,
|
setFontFamily: (fontFamily: string) => Command,
|
||||||
|
/**
|
||||||
|
* Unset the font family
|
||||||
|
*/
|
||||||
unsetFontFamily: () => Command,
|
unsetFontFamily: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,17 +52,11 @@ export const FontFamily = Extension.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Set the font family
|
|
||||||
*/
|
|
||||||
setFontFamily: fontFamily => ({ chain }) => {
|
setFontFamily: fontFamily => ({ chain }) => {
|
||||||
return chain()
|
return chain()
|
||||||
.setMark('textStyle', { fontFamily })
|
.setMark('textStyle', { fontFamily })
|
||||||
.run()
|
.run()
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Unset the font family
|
|
||||||
*/
|
|
||||||
unsetFontFamily: () => ({ chain }) => {
|
unsetFontFamily: () => ({ chain }) => {
|
||||||
return chain()
|
return chain()
|
||||||
.setMark('textStyle', { fontFamily: null })
|
.setMark('textStyle', { fontFamily: null })
|
||||||
|
@ -9,6 +9,9 @@ export interface HardBreakOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Add a hard break
|
||||||
|
*/
|
||||||
setHardBreak: () => Command,
|
setHardBreak: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -39,9 +42,6 @@ export const HardBreak = Node.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Add a hard break
|
|
||||||
*/
|
|
||||||
setHardBreak: () => ({ commands, state, dispatch }) => {
|
setHardBreak: () => ({ commands, state, dispatch }) => {
|
||||||
return commands.first([
|
return commands.first([
|
||||||
() => exitCode(state, dispatch),
|
() => exitCode(state, dispatch),
|
||||||
|
@ -12,7 +12,13 @@ export interface HeadingOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Set a heading node
|
||||||
|
*/
|
||||||
setHeading: (attributes: { level: Level }) => Command,
|
setHeading: (attributes: { level: Level }) => Command,
|
||||||
|
/**
|
||||||
|
* Toggle a heading node
|
||||||
|
*/
|
||||||
toggleHeading: (attributes: { level: Level }) => Command,
|
toggleHeading: (attributes: { level: Level }) => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,9 +65,6 @@ export const Heading = Node.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Set a heading node
|
|
||||||
*/
|
|
||||||
setHeading: attributes => ({ commands }) => {
|
setHeading: attributes => ({ commands }) => {
|
||||||
if (!this.options.levels.includes(attributes.level)) {
|
if (!this.options.levels.includes(attributes.level)) {
|
||||||
return false
|
return false
|
||||||
@ -69,9 +72,6 @@ export const Heading = Node.create({
|
|||||||
|
|
||||||
return commands.setNode('heading', attributes)
|
return commands.setNode('heading', attributes)
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Toggle a heading node
|
|
||||||
*/
|
|
||||||
toggleHeading: attributes => ({ commands }) => {
|
toggleHeading: attributes => ({ commands }) => {
|
||||||
if (!this.options.levels.includes(attributes.level)) {
|
if (!this.options.levels.includes(attributes.level)) {
|
||||||
return false
|
return false
|
||||||
|
@ -15,8 +15,17 @@ export interface HighlightOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Set a highlight mark
|
||||||
|
*/
|
||||||
setHighlight: (attributes?: { color: string }) => Command,
|
setHighlight: (attributes?: { color: string }) => Command,
|
||||||
|
/**
|
||||||
|
* Toggle a highlight mark
|
||||||
|
*/
|
||||||
toggleHighlight: (attributes?: { color: string }) => Command,
|
toggleHighlight: (attributes?: { color: string }) => Command,
|
||||||
|
/**
|
||||||
|
* Unset a highlight mark
|
||||||
|
*/
|
||||||
unsetHighlight: () => Command,
|
unsetHighlight: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,21 +82,12 @@ export const Highlight = Mark.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Set a highlight mark
|
|
||||||
*/
|
|
||||||
setHighlight: attributes => ({ commands }) => {
|
setHighlight: attributes => ({ commands }) => {
|
||||||
return commands.setMark('highlight', attributes)
|
return commands.setMark('highlight', attributes)
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Toggle a highlight mark
|
|
||||||
*/
|
|
||||||
toggleHighlight: attributes => ({ commands }) => {
|
toggleHighlight: attributes => ({ commands }) => {
|
||||||
return commands.toggleMark('highlight', attributes)
|
return commands.toggleMark('highlight', attributes)
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Unset a highlight mark
|
|
||||||
*/
|
|
||||||
unsetHighlight: () => ({ commands }) => {
|
unsetHighlight: () => ({ commands }) => {
|
||||||
return commands.unsetMark('highlight')
|
return commands.unsetMark('highlight')
|
||||||
},
|
},
|
||||||
|
@ -8,7 +8,13 @@ export interface HistoryOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Undo recent changes
|
||||||
|
*/
|
||||||
undo: () => Command,
|
undo: () => Command,
|
||||||
|
/**
|
||||||
|
* Reapply reverted changes
|
||||||
|
*/
|
||||||
redo: () => Command,
|
redo: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -23,15 +29,9 @@ export const History = Extension.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Undo recent changes
|
|
||||||
*/
|
|
||||||
undo: () => ({ state, dispatch }) => {
|
undo: () => ({ state, dispatch }) => {
|
||||||
return undo(state, dispatch)
|
return undo(state, dispatch)
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Reapply reverted changes
|
|
||||||
*/
|
|
||||||
redo: () => ({ state, dispatch }) => {
|
redo: () => ({ state, dispatch }) => {
|
||||||
return redo(state, dispatch)
|
return redo(state, dispatch)
|
||||||
},
|
},
|
||||||
|
@ -13,6 +13,9 @@ export interface HorizontalRuleOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Add a horizontal rule
|
||||||
|
*/
|
||||||
setHorizontalRule: () => Command,
|
setHorizontalRule: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -38,9 +41,6 @@ export const HorizontalRule = Node.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Add a horizontal rule
|
|
||||||
*/
|
|
||||||
setHorizontalRule: () => ({ tr, dispatch }) => {
|
setHorizontalRule: () => ({ tr, dispatch }) => {
|
||||||
if (dispatch) {
|
if (dispatch) {
|
||||||
tr.replaceSelectionWith(this.type.create())
|
tr.replaceSelectionWith(this.type.create())
|
||||||
|
@ -14,6 +14,9 @@ export interface ImageOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Add an image
|
||||||
|
*/
|
||||||
setImage: (options: { src: string, alt?: string, title?: string }) => Command,
|
setImage: (options: { src: string, alt?: string, title?: string }) => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,9 +69,6 @@ export const Image = Node.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Add an image
|
|
||||||
*/
|
|
||||||
setImage: options => ({ tr, dispatch }) => {
|
setImage: options => ({ tr, dispatch }) => {
|
||||||
const { selection } = tr
|
const { selection } = tr
|
||||||
const node = this.type.create(options)
|
const node = this.type.create(options)
|
||||||
|
@ -14,8 +14,17 @@ export interface ItalicOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Set an italic mark
|
||||||
|
*/
|
||||||
setItalic: () => Command,
|
setItalic: () => Command,
|
||||||
|
/**
|
||||||
|
* Toggle an italic mark
|
||||||
|
*/
|
||||||
toggleItalic: () => Command,
|
toggleItalic: () => Command,
|
||||||
|
/**
|
||||||
|
* Unset an italic mark
|
||||||
|
*/
|
||||||
unsetItalic: () => Command,
|
unsetItalic: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,21 +62,12 @@ export const Italic = Mark.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Set an italic mark
|
|
||||||
*/
|
|
||||||
setItalic: () => ({ commands }) => {
|
setItalic: () => ({ commands }) => {
|
||||||
return commands.setMark('italic')
|
return commands.setMark('italic')
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Toggle an italic mark
|
|
||||||
*/
|
|
||||||
toggleItalic: () => ({ commands }) => {
|
toggleItalic: () => ({ commands }) => {
|
||||||
return commands.toggleMark('italic')
|
return commands.toggleMark('italic')
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Unset an italic mark
|
|
||||||
*/
|
|
||||||
unsetItalic: () => ({ commands }) => {
|
unsetItalic: () => ({ commands }) => {
|
||||||
return commands.unsetMark('italic')
|
return commands.unsetMark('italic')
|
||||||
},
|
},
|
||||||
|
@ -15,8 +15,17 @@ export interface LinkOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Set a link mark
|
||||||
|
*/
|
||||||
setLink: (attributes: { href: string, target?: string }) => Command,
|
setLink: (attributes: { href: string, target?: string }) => Command,
|
||||||
|
/**
|
||||||
|
* Toggle a link mark
|
||||||
|
*/
|
||||||
toggleLink: (attributes: { href: string, target?: string }) => Command,
|
toggleLink: (attributes: { href: string, target?: string }) => Command,
|
||||||
|
/**
|
||||||
|
* Unset a link mark
|
||||||
|
*/
|
||||||
unsetLink: () => Command,
|
unsetLink: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,21 +69,12 @@ export const Link = Mark.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Set a link mark
|
|
||||||
*/
|
|
||||||
setLink: attributes => ({ commands }) => {
|
setLink: attributes => ({ commands }) => {
|
||||||
return commands.setMark('link', attributes)
|
return commands.setMark('link', attributes)
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Toggle a link mark
|
|
||||||
*/
|
|
||||||
toggleLink: attributes => ({ commands }) => {
|
toggleLink: attributes => ({ commands }) => {
|
||||||
return commands.toggleMark('link', attributes)
|
return commands.toggleMark('link', attributes)
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Unset a link mark
|
|
||||||
*/
|
|
||||||
unsetLink: () => ({ commands }) => {
|
unsetLink: () => ({ commands }) => {
|
||||||
return commands.unsetMark('link')
|
return commands.unsetMark('link')
|
||||||
},
|
},
|
||||||
|
@ -9,6 +9,9 @@ export interface OrderedListOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Toggle an ordered list
|
||||||
|
*/
|
||||||
toggleOrderedList: () => Command,
|
toggleOrderedList: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,9 +60,6 @@ export const OrderedList = Node.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Toggle an ordered list
|
|
||||||
*/
|
|
||||||
toggleOrderedList: () => ({ commands }) => {
|
toggleOrderedList: () => ({ commands }) => {
|
||||||
return commands.toggleList('orderedList', 'listItem')
|
return commands.toggleList('orderedList', 'listItem')
|
||||||
},
|
},
|
||||||
|
@ -8,6 +8,9 @@ export interface ParagraphOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Toggle a paragraph
|
||||||
|
*/
|
||||||
setParagraph: () => Command,
|
setParagraph: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,9 +38,6 @@ export const Paragraph = Node.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Toggle a paragraph
|
|
||||||
*/
|
|
||||||
setParagraph: () => ({ commands }) => {
|
setParagraph: () => ({ commands }) => {
|
||||||
return commands.toggleNode('paragraph', 'paragraph')
|
return commands.toggleNode('paragraph', 'paragraph')
|
||||||
},
|
},
|
||||||
|
@ -14,8 +14,17 @@ export interface StrikeOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Set a strike mark
|
||||||
|
*/
|
||||||
setStrike: () => Command,
|
setStrike: () => Command,
|
||||||
|
/**
|
||||||
|
* Toggle a strike mark
|
||||||
|
*/
|
||||||
toggleStrike: () => Command,
|
toggleStrike: () => Command,
|
||||||
|
/**
|
||||||
|
* Unset a strike mark
|
||||||
|
*/
|
||||||
unsetStrike: () => Command,
|
unsetStrike: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,21 +62,12 @@ export const Strike = Mark.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Set a strike mark
|
|
||||||
*/
|
|
||||||
setStrike: () => ({ commands }) => {
|
setStrike: () => ({ commands }) => {
|
||||||
return commands.setMark('strike')
|
return commands.setMark('strike')
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Toggle a strike mark
|
|
||||||
*/
|
|
||||||
toggleStrike: () => ({ commands }) => {
|
toggleStrike: () => ({ commands }) => {
|
||||||
return commands.toggleMark('strike')
|
return commands.toggleMark('strike')
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Unset a strike mark
|
|
||||||
*/
|
|
||||||
unsetStrike: () => ({ commands }) => {
|
unsetStrike: () => ({ commands }) => {
|
||||||
return commands.unsetMark('strike')
|
return commands.unsetMark('strike')
|
||||||
},
|
},
|
||||||
|
@ -8,6 +8,9 @@ export interface TaskListOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Toggle a task list
|
||||||
|
*/
|
||||||
toggleTaskList: () => Command,
|
toggleTaskList: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -38,9 +41,6 @@ export const TaskList = Node.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Toggle a task list
|
|
||||||
*/
|
|
||||||
toggleTaskList: () => ({ commands }) => {
|
toggleTaskList: () => ({ commands }) => {
|
||||||
return commands.toggleList('taskList', 'taskItem')
|
return commands.toggleList('taskList', 'taskItem')
|
||||||
},
|
},
|
||||||
|
@ -8,7 +8,13 @@ type TextAlignOptions = {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Set the text align attribute
|
||||||
|
*/
|
||||||
setTextAlign: (alignment: string) => Command,
|
setTextAlign: (alignment: string) => Command,
|
||||||
|
/**
|
||||||
|
* Unset the text align attribute
|
||||||
|
*/
|
||||||
unsetTextAlign: () => Command,
|
unsetTextAlign: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,9 +49,6 @@ export const TextAlign = Extension.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Set the text align attribute
|
|
||||||
*/
|
|
||||||
setTextAlign: (alignment: string) => ({ commands }) => {
|
setTextAlign: (alignment: string) => ({ commands }) => {
|
||||||
if (!this.options.alignments.includes(alignment)) {
|
if (!this.options.alignments.includes(alignment)) {
|
||||||
return false
|
return false
|
||||||
@ -53,9 +56,6 @@ export const TextAlign = Extension.create({
|
|||||||
|
|
||||||
return this.options.types.every(type => commands.updateNodeAttributes(type, { textAlign: alignment }))
|
return this.options.types.every(type => commands.updateNodeAttributes(type, { textAlign: alignment }))
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Unset the text align attribute
|
|
||||||
*/
|
|
||||||
unsetTextAlign: () => ({ commands }) => {
|
unsetTextAlign: () => ({ commands }) => {
|
||||||
return this.options.types.every(type => commands.resetNodeAttributes(type, 'textAlign'))
|
return this.options.types.every(type => commands.resetNodeAttributes(type, 'textAlign'))
|
||||||
},
|
},
|
||||||
|
@ -13,6 +13,9 @@ export interface TextStyleOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Remove spans without inline style attributes.
|
||||||
|
*/
|
||||||
removeEmptyTextStyle: () => Command,
|
removeEmptyTextStyle: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,9 +50,6 @@ export const TextStyle = Mark.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Remove spans without inline style attributes.
|
|
||||||
*/
|
|
||||||
removeEmptyTextStyle: () => ({ state, commands }) => {
|
removeEmptyTextStyle: () => ({ state, commands }) => {
|
||||||
const attributes = getMarkAttributes(state, this.type)
|
const attributes = getMarkAttributes(state, this.type)
|
||||||
const hasStyles = Object.entries(attributes).every(([, value]) => !!value)
|
const hasStyles = Object.entries(attributes).every(([, value]) => !!value)
|
||||||
|
@ -8,8 +8,17 @@ export interface UnderlineOptions {
|
|||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
interface Commands {
|
interface Commands {
|
||||||
|
/**
|
||||||
|
* Set an underline mark
|
||||||
|
*/
|
||||||
setUnderline: () => Command,
|
setUnderline: () => Command,
|
||||||
|
/**
|
||||||
|
* Toggle an underline mark
|
||||||
|
*/
|
||||||
toggleUnderline: () => Command,
|
toggleUnderline: () => Command,
|
||||||
|
/**
|
||||||
|
* Unset an underline mark
|
||||||
|
*/
|
||||||
unsetUnderline: () => Command,
|
unsetUnderline: () => Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -38,21 +47,12 @@ export const Underline = Mark.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
|
||||||
* Set an underline mark
|
|
||||||
*/
|
|
||||||
setUnderline: () => ({ commands }) => {
|
setUnderline: () => ({ commands }) => {
|
||||||
return commands.setMark('underline')
|
return commands.setMark('underline')
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Toggle an underline mark
|
|
||||||
*/
|
|
||||||
toggleUnderline: () => ({ commands }) => {
|
toggleUnderline: () => ({ commands }) => {
|
||||||
return commands.toggleMark('underline')
|
return commands.toggleMark('underline')
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Unset an underline mark
|
|
||||||
*/
|
|
||||||
unsetUnderline: () => ({ commands }) => {
|
unsetUnderline: () => ({ commands }) => {
|
||||||
return commands.unsetMark('underline')
|
return commands.unsetMark('underline')
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user