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,26 @@
{
"name": "tiptap-utils",
"version": "0.1.0",
"description": "Utility functions for tiptap",
"homepage": "https://tiptap.scrumpy.io",
"license": "MIT",
"main": "dist/utils.common.js",
"module": "dist/utils.esm.js",
"unpkg": "dist/utils.js",
"jsdelivr": "dist/utils.js",
"files": [
"src",
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/heyscrumpy/tiptap.git"
},
"bugs": {
"url": "https://github.com/heyscrumpy/tiptap/issues"
},
"dependencies": {
"prosemirror-utils": "^0.6.5",
"prosemirror-tables": "^0.7.6"
}
}

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)
}