refactoring
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { lift as originalLift } from 'prosemirror-commands'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import nodeIsActive from '../helpers/nodeIsActive'
|
||||
import isNodeActive from '../helpers/isNodeActive'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
@@ -9,7 +9,7 @@ import getNodeType from '../helpers/getNodeType'
|
||||
*/
|
||||
export const lift = (typeOrName: string | NodeType, attributes = {}): Command => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const isActive = nodeIsActive(state, type, attributes)
|
||||
const isActive = isNodeActive(state, type, attributes)
|
||||
|
||||
if (!isActive) {
|
||||
return false
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import getMarkType from '../helpers/getMarkType'
|
||||
import markIsActive from '../helpers/markIsActive'
|
||||
import isMarkActive from '../helpers/isMarkActive'
|
||||
|
||||
/**
|
||||
* Toggle a mark on and off.
|
||||
*/
|
||||
export const toggleMark = (typeOrName: string | MarkType, attributes?: {}): Command => ({ state, commands }) => {
|
||||
const type = getMarkType(typeOrName, state.schema)
|
||||
const isActive = markIsActive(state, type, attributes)
|
||||
const isActive = isMarkActive(state, type, attributes)
|
||||
|
||||
if (isActive) {
|
||||
return commands.unsetMark(type)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import nodeIsActive from '../helpers/nodeIsActive'
|
||||
import isNodeActive from '../helpers/isNodeActive'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
@@ -9,7 +9,7 @@ import getNodeType from '../helpers/getNodeType'
|
||||
export const toggleNode = (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attrs = {}): Command => ({ state, commands }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const toggleType = getNodeType(toggleTypeOrName, state.schema)
|
||||
const isActive = nodeIsActive(state, type, attrs)
|
||||
const isActive = isNodeActive(state, type, attrs)
|
||||
|
||||
if (isActive) {
|
||||
return commands.setNode(toggleType)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { wrapIn, lift } from 'prosemirror-commands'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import nodeIsActive from '../helpers/nodeIsActive'
|
||||
import isNodeActive from '../helpers/isNodeActive'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
@@ -9,7 +9,7 @@ import getNodeType from '../helpers/getNodeType'
|
||||
*/
|
||||
export const toggleWrap = (typeOrName: string | NodeType, attributes = {}): Command => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const isActive = nodeIsActive(state, type, attributes)
|
||||
const isActive = isNodeActive(state, type, attributes)
|
||||
|
||||
if (isActive) {
|
||||
return lift(state, dispatch)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { wrapIn as originalWrapIn } from 'prosemirror-commands'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import nodeIsActive from '../helpers/nodeIsActive'
|
||||
import isNodeActive from '../helpers/isNodeActive'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
@@ -9,7 +9,7 @@ import getNodeType from '../helpers/getNodeType'
|
||||
*/
|
||||
export const wrapIn = (typeOrName: string | NodeType, attributes = {}): Command => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const isActive = nodeIsActive(state, type, attributes)
|
||||
const isActive = isNodeActive(state, type, attributes)
|
||||
|
||||
if (isActive) {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user