add commands and utils packages
This commit is contained in:
@@ -83,6 +83,62 @@ export default [
|
|||||||
format: 'es',
|
format: 'es',
|
||||||
external: ['vue'],
|
external: ['vue'],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
input: resolve('packages/tiptap-commands/src/index.js'),
|
||||||
|
file: resolve('packages/tiptap-commands/dist/commands.js'),
|
||||||
|
format: 'umd',
|
||||||
|
env: 'development',
|
||||||
|
external: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: resolve('packages/tiptap-commands/src/index.js'),
|
||||||
|
file: resolve('packages/tiptap-commands/dist/commands.min.js'),
|
||||||
|
format: 'umd',
|
||||||
|
env: 'production',
|
||||||
|
external: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: resolve('packages/tiptap-commands/src/index.js'),
|
||||||
|
file: resolve('packages/tiptap-commands/dist/commands.common.js'),
|
||||||
|
format: 'cjs',
|
||||||
|
external: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: resolve('packages/tiptap-commands/src/index.js'),
|
||||||
|
file: resolve('packages/tiptap-commands/dist/commands.esm.js'),
|
||||||
|
format: 'es',
|
||||||
|
external: [],
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
input: resolve('packages/tiptap-utils/src/index.js'),
|
||||||
|
file: resolve('packages/tiptap-utils/dist/utils.js'),
|
||||||
|
format: 'umd',
|
||||||
|
env: 'development',
|
||||||
|
external: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: resolve('packages/tiptap-utils/src/index.js'),
|
||||||
|
file: resolve('packages/tiptap-utils/dist/utils.min.js'),
|
||||||
|
format: 'umd',
|
||||||
|
env: 'production',
|
||||||
|
external: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: resolve('packages/tiptap-utils/src/index.js'),
|
||||||
|
file: resolve('packages/tiptap-utils/dist/utils.common.js'),
|
||||||
|
format: 'cjs',
|
||||||
|
external: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: resolve('packages/tiptap-utils/src/index.js'),
|
||||||
|
file: resolve('packages/tiptap-utils/dist/utils.esm.js'),
|
||||||
|
format: 'es',
|
||||||
|
external: [],
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
// {
|
// {
|
||||||
// input: resolve('packages/tiptap/src/helpers/index.js'),
|
// input: resolve('packages/tiptap/src/helpers/index.js'),
|
||||||
// file: resolve('packages/tiptap/dist/helpers.min.js'),
|
// file: resolve('packages/tiptap/dist/helpers.min.js'),
|
||||||
|
|||||||
27
packages/tiptap-commands/package.json
Normal file
27
packages/tiptap-commands/package.json
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"name": "tiptap-commands",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "Commands for tiptap",
|
||||||
|
"homepage": "https://tiptap.scrumpy.io",
|
||||||
|
"license": "MIT",
|
||||||
|
"main": "dist/commands.common.js",
|
||||||
|
"module": "dist/commands.esm.js",
|
||||||
|
"unpkg": "dist/commands.js",
|
||||||
|
"jsdelivr": "dist/commands.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-commands": "^1.0.7",
|
||||||
|
"prosemirror-inputrules": "^1.0.1",
|
||||||
|
"prosemirror-schema-list": "^1.0.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
6
packages/tiptap-commands/src/commands/removeMark.js
Normal file
6
packages/tiptap-commands/src/commands/removeMark.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
export default function (type) {
|
||||||
|
return (state, dispatch) => {
|
||||||
|
const { from, to } = state.selection
|
||||||
|
return dispatch(state.tr.removeMark(from, to, type))
|
||||||
|
}
|
||||||
|
}
|
||||||
14
packages/tiptap-commands/src/commands/toggleBlockType.js
Normal file
14
packages/tiptap-commands/src/commands/toggleBlockType.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { setBlockType } from 'prosemirror-commands'
|
||||||
|
import { nodeIsActive } from '../utils'
|
||||||
|
|
||||||
|
export default function (type, toggletype, attrs = {}) {
|
||||||
|
return (state, dispatch, view) => {
|
||||||
|
const isActive = nodeIsActive(state, type, attrs)
|
||||||
|
|
||||||
|
if (isActive) {
|
||||||
|
return setBlockType(toggletype)(state, dispatch, view)
|
||||||
|
}
|
||||||
|
|
||||||
|
return setBlockType(type, attrs)(state, dispatch, view)
|
||||||
|
}
|
||||||
|
}
|
||||||
49
packages/tiptap-commands/src/commands/toggleList.js
Normal file
49
packages/tiptap-commands/src/commands/toggleList.js
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import { nodeIsActive } from '../utils'
|
||||||
|
import { wrapInList, liftListItem } from '..'
|
||||||
|
|
||||||
|
export default function toggleList(type, itemType) {
|
||||||
|
return (state, dispatch, view) => {
|
||||||
|
const isActive = nodeIsActive(state, type)
|
||||||
|
|
||||||
|
if (isActive) {
|
||||||
|
return liftListItem(itemType)(state, dispatch, view)
|
||||||
|
}
|
||||||
|
|
||||||
|
return wrapInList(type)(state, dispatch, view)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://discuss.prosemirror.net/t/list-type-toggle/948
|
||||||
|
|
||||||
|
// import { wrapInList, liftListItem } from 'prosemirror-schema-list'
|
||||||
|
|
||||||
|
// function isList(node, schema) {
|
||||||
|
// return (node.type === schema.nodes.bullet_list || node.type === schema.nodes.ordered_list)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// export default function toggleList(listType, schema) {
|
||||||
|
// const lift = liftListItem(schema.nodes.list_item)
|
||||||
|
// const wrap = wrapInList(listType)
|
||||||
|
|
||||||
|
// return (state, dispatch) => {
|
||||||
|
// const { $from, $to } = state.selection
|
||||||
|
// const range = $from.blockRange($to)
|
||||||
|
// if (!range) {
|
||||||
|
// return false
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (range.depth >= 2 && $from.node(range.depth - 1).type === listType) {
|
||||||
|
// return lift(state, dispatch)
|
||||||
|
// } else if (range.depth >= 2 && isList($from.node(range.depth - 1), schema)) {
|
||||||
|
// const tr = state.tr
|
||||||
|
// const node = $from.before(range.depth - 1)
|
||||||
|
// console.log({node})
|
||||||
|
// // TODO: how do I pass the node above to `setNodeType`?
|
||||||
|
// // tr.setNodeType(range.start, listType);
|
||||||
|
// if (dispatch) dispatch(tr)
|
||||||
|
// return false
|
||||||
|
// } else {
|
||||||
|
// return wrap(state, dispatch)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
6
packages/tiptap-commands/src/commands/updateMark.js
Normal file
6
packages/tiptap-commands/src/commands/updateMark.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
export default function (type, attrs) {
|
||||||
|
return (state, dispatch) => {
|
||||||
|
const { from, to } = state.selection
|
||||||
|
return dispatch(state.tr.addMark(from, to, type.create(attrs)))
|
||||||
|
}
|
||||||
|
}
|
||||||
89
packages/tiptap-commands/src/index.js
Normal file
89
packages/tiptap-commands/src/index.js
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
import {
|
||||||
|
chainCommands,
|
||||||
|
deleteSelection,
|
||||||
|
joinBackward,
|
||||||
|
selectNodeBackward,
|
||||||
|
joinForward,
|
||||||
|
selectNodeForward,
|
||||||
|
joinUp,
|
||||||
|
joinDown,
|
||||||
|
lift,
|
||||||
|
newlineInCode,
|
||||||
|
exitCode,
|
||||||
|
createParagraphNear,
|
||||||
|
liftEmptyBlock,
|
||||||
|
splitBlock,
|
||||||
|
splitBlockKeepMarks,
|
||||||
|
selectParentNode,
|
||||||
|
selectAll,
|
||||||
|
wrapIn,
|
||||||
|
setBlockType,
|
||||||
|
toggleMark,
|
||||||
|
autoJoin,
|
||||||
|
baseKeymap,
|
||||||
|
pcBaseKeymap,
|
||||||
|
macBaseKeymap,
|
||||||
|
} from 'prosemirror-commands'
|
||||||
|
|
||||||
|
import {
|
||||||
|
addListNodes,
|
||||||
|
wrapInList,
|
||||||
|
splitListItem,
|
||||||
|
liftListItem,
|
||||||
|
sinkListItem,
|
||||||
|
} from 'prosemirror-schema-list'
|
||||||
|
|
||||||
|
import {
|
||||||
|
wrappingInputRule,
|
||||||
|
textblockTypeInputRule,
|
||||||
|
} from 'prosemirror-inputrules'
|
||||||
|
|
||||||
|
import removeMark from './helpers/removeMark'
|
||||||
|
import toggleBlockType from './helpers/toggleBlockType'
|
||||||
|
import toggleList from './helpers/toggleList'
|
||||||
|
import updateMark from './helpers/updateMark'
|
||||||
|
|
||||||
|
export {
|
||||||
|
// prosemirror-commands
|
||||||
|
chainCommands,
|
||||||
|
deleteSelection,
|
||||||
|
joinBackward,
|
||||||
|
selectNodeBackward,
|
||||||
|
joinForward,
|
||||||
|
selectNodeForward,
|
||||||
|
joinUp,
|
||||||
|
joinDown,
|
||||||
|
lift,
|
||||||
|
newlineInCode,
|
||||||
|
exitCode,
|
||||||
|
createParagraphNear,
|
||||||
|
liftEmptyBlock,
|
||||||
|
splitBlock,
|
||||||
|
splitBlockKeepMarks,
|
||||||
|
selectParentNode,
|
||||||
|
selectAll,
|
||||||
|
wrapIn,
|
||||||
|
setBlockType,
|
||||||
|
toggleMark,
|
||||||
|
autoJoin,
|
||||||
|
baseKeymap,
|
||||||
|
pcBaseKeymap,
|
||||||
|
macBaseKeymap,
|
||||||
|
|
||||||
|
// prosemirror-schema-list
|
||||||
|
addListNodes,
|
||||||
|
wrapInList,
|
||||||
|
splitListItem,
|
||||||
|
liftListItem,
|
||||||
|
sinkListItem,
|
||||||
|
|
||||||
|
// prosemirror-inputrules
|
||||||
|
wrappingInputRule,
|
||||||
|
textblockTypeInputRule,
|
||||||
|
|
||||||
|
// custom
|
||||||
|
removeMark,
|
||||||
|
toggleBlockType,
|
||||||
|
toggleList,
|
||||||
|
updateMark,
|
||||||
|
}
|
||||||
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)
|
||||||
|
}
|
||||||
8077
packages/tiptap/dist/tiptap.esm.js
vendored
8077
packages/tiptap/dist/tiptap.esm.js
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user