add commands and utils packages

This commit is contained in:
Philipp Kühn
2018-08-23 10:33:49 +02:00
parent 14cb2ef085
commit d5039489dd
12 changed files with 8354 additions and 24 deletions

View File

@@ -0,0 +1,2 @@
export { default as markIsActive } from './utils/markIsActive'
export { default as nodeIsActive } from './utils/nodeIsActive'

View File

@@ -0,0 +1,14 @@
export default function (state, type) {
const {
from,
$from,
to,
empty,
} = state.selection
if (empty) {
return !!type.isInSet(state.storedMarks || $from.marks())
}
return !!state.doc.rangeHasMark(from, to, type)
}

View File

@@ -0,0 +1,12 @@
import { findParentNode } from 'prosemirror-utils'
export default function (state, type, attrs) {
const predicate = node => node.type === type
const parent = findParentNode(predicate)(state.selection)
if (attrs === {} || !parent) {
return !!parent
}
return parent.node.hasMarkup(type, attrs)
}