add commands and utils packages
This commit is contained in:
26
packages/tiptap-utils/package.json
Normal file
26
packages/tiptap-utils/package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
2
packages/tiptap-utils/src/index.js
Normal file
2
packages/tiptap-utils/src/index.js
Normal file
@@ -0,0 +1,2 @@
|
||||
export { default as markIsActive } from './utils/markIsActive'
|
||||
export { default as nodeIsActive } from './utils/nodeIsActive'
|
||||
14
packages/tiptap-utils/src/utils/markIsActive.js
Normal file
14
packages/tiptap-utils/src/utils/markIsActive.js
Normal 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)
|
||||
}
|
||||
12
packages/tiptap-utils/src/utils/nodeIsActive.js
Normal file
12
packages/tiptap-utils/src/utils/nodeIsActive.js
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user