add blockquote commands
This commit is contained in:
16
packages/core/src/commands/lift.ts
Normal file
16
packages/core/src/commands/lift.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { lift } from 'prosemirror-commands'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import nodeIsActive from '../utils/nodeIsActive'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
|
||||
export default (typeOrName: string | NodeType, attributes = {}): Command => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const isActive = nodeIsActive(state, type, attributes)
|
||||
|
||||
if (!isActive) {
|
||||
return false
|
||||
}
|
||||
|
||||
return lift(state, dispatch)
|
||||
}
|
||||
@@ -4,13 +4,13 @@ import { Command } from '../types'
|
||||
import nodeIsActive from '../utils/nodeIsActive'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
|
||||
export default (typeOrName: string | NodeType, attrs = {}): Command => ({ state, dispatch }) => {
|
||||
export default (typeOrName: string | NodeType, attributes = {}): Command => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const isActive = nodeIsActive(state, type, attrs)
|
||||
const isActive = nodeIsActive(state, type, attributes)
|
||||
|
||||
if (isActive) {
|
||||
return lift(state, dispatch)
|
||||
}
|
||||
|
||||
return wrapIn(type, attrs)(state, dispatch)
|
||||
return wrapIn(type, attributes)(state, dispatch)
|
||||
}
|
||||
|
||||
16
packages/core/src/commands/wrapIn.ts
Normal file
16
packages/core/src/commands/wrapIn.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { wrapIn } from 'prosemirror-commands'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import nodeIsActive from '../utils/nodeIsActive'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
|
||||
export default (typeOrName: string | NodeType, attributes = {}): Command => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const isActive = nodeIsActive(state, type, attributes)
|
||||
|
||||
if (isActive) {
|
||||
return false
|
||||
}
|
||||
|
||||
return wrapIn(type, attributes)(state, dispatch)
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import extendMarkRange from '../commands/extendMarkRange'
|
||||
import focus from '../commands/focus'
|
||||
import insertHTML from '../commands/insertHTML'
|
||||
import insertText from '../commands/insertText'
|
||||
import lift from '../commands/lift'
|
||||
import liftListItem from '../commands/liftListItem'
|
||||
import removeMark from '../commands/removeMark'
|
||||
import removeMarks from '../commands/removeMarks'
|
||||
@@ -27,6 +28,7 @@ import toggleMark from '../commands/toggleMark'
|
||||
import toggleWrap from '../commands/toggleWrap'
|
||||
import tryCommand from '../commands/try'
|
||||
import updateNodeAttributes from '../commands/updateNodeAttributes'
|
||||
import wrapIn from '../commands/wrapIn'
|
||||
import wrapInList from '../commands/wrapInList'
|
||||
|
||||
export const Commands = Extension.create({
|
||||
@@ -72,6 +74,10 @@ export const Commands = Extension.create({
|
||||
* Insert a string of text at the current position.
|
||||
*/
|
||||
insertText,
|
||||
/**
|
||||
* Removes an existing wrap.
|
||||
*/
|
||||
lift,
|
||||
/**
|
||||
* Lift the list item into a wrapping list.
|
||||
*/
|
||||
@@ -144,6 +150,10 @@ export const Commands = Extension.create({
|
||||
* Update attributes of a node.
|
||||
*/
|
||||
updateNodeAttributes,
|
||||
/**
|
||||
* Wraps nodes in another node.
|
||||
*/
|
||||
wrapIn,
|
||||
/**
|
||||
* Wrap a node in a list.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user