tiptap-commands
Advanced tools
Comparing version 1.14.4 to 1.14.5
/*! | ||
* tiptap-commands v1.14.0 | ||
* (c) 2020 Scrumpy UG (limited liability) | ||
* tiptap-commands v1.14.4 | ||
* (c) 2020 überdosis GbR (limited liability) | ||
* @license MIT | ||
@@ -20,7 +20,10 @@ */ | ||
function insertText () { | ||
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; | ||
return function (state, dispatch) { | ||
var $from = state.selection.$from; | ||
var pos = $from.pos.pos; | ||
function insertText (text = '') { | ||
return (state, dispatch) => { | ||
const { | ||
$from | ||
} = state.selection; | ||
const { | ||
pos | ||
} = $from.pos; | ||
dispatch(state.tr.insertText(text, pos)); | ||
@@ -31,45 +34,10 @@ return true; | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) return _arrayLikeToArray(arr); | ||
} | ||
function _iterableToArray(iter) { | ||
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
function getMarksBetween(start, end, state) { | ||
var marks = []; | ||
state.doc.nodesBetween(start, end, function (node, pos) { | ||
marks = [].concat(_toConsumableArray(marks), _toConsumableArray(node.marks.map(function (mark) { | ||
return { | ||
start: pos, | ||
end: pos + node.nodeSize, | ||
mark: mark | ||
}; | ||
}))); | ||
let marks = []; | ||
state.doc.nodesBetween(start, end, (node, pos) => { | ||
marks = [...marks, ...node.marks.map(mark => ({ | ||
start: pos, | ||
end: pos + node.nodeSize, | ||
mark | ||
}))]; | ||
}); | ||
@@ -80,22 +48,22 @@ return marks; | ||
function markInputRule (regexp, markType, getAttrs) { | ||
return new prosemirrorInputrules.InputRule(regexp, function (state, match, start, end) { | ||
var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; | ||
var tr = state.tr; | ||
var m = match.length - 1; | ||
var markEnd = end; | ||
var markStart = start; | ||
return new prosemirrorInputrules.InputRule(regexp, (state, match, start, end) => { | ||
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; | ||
const { | ||
tr | ||
} = state; | ||
const m = match.length - 1; | ||
let markEnd = end; | ||
let markStart = start; | ||
if (match[m]) { | ||
var matchStart = start + match[0].indexOf(match[m - 1]); | ||
var matchEnd = matchStart + match[m - 1].length - 1; | ||
var textStart = matchStart + match[m - 1].lastIndexOf(match[m]); | ||
var textEnd = textStart + match[m].length; | ||
var excludedMarks = getMarksBetween(start, end, state).filter(function (item) { | ||
var excluded = item.mark.type.excluded; | ||
return excluded.find(function (type) { | ||
return type.name === markType.name; | ||
}); | ||
}).filter(function (item) { | ||
return item.end > matchStart; | ||
}); | ||
const matchStart = start + match[0].indexOf(match[m - 1]); | ||
const matchEnd = matchStart + match[m - 1].length - 1; | ||
const textStart = matchStart + match[m - 1].lastIndexOf(match[m]); | ||
const textEnd = textStart + match[m].length; | ||
const excludedMarks = getMarksBetween(start, end, state).filter(item => { | ||
const { | ||
excluded | ||
} = item.mark.type; | ||
return excluded.find(type => type.name === markType.name); | ||
}).filter(item => item.end > matchStart); | ||
@@ -125,5 +93,7 @@ if (excludedMarks.length) { | ||
function nodeInputRule (regexp, type, getAttrs) { | ||
return new prosemirrorInputrules.InputRule(regexp, function (state, match, start, end) { | ||
var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; | ||
var tr = state.tr; | ||
return new prosemirrorInputrules.InputRule(regexp, (state, match, start, end) => { | ||
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; | ||
const { | ||
tr | ||
} = state; | ||
@@ -139,9 +109,11 @@ if (match[0]) { | ||
function pasteRule (regexp, type, getAttrs) { | ||
var handler = function handler(fragment) { | ||
var nodes = []; | ||
fragment.forEach(function (child) { | ||
const handler = fragment => { | ||
const nodes = []; | ||
fragment.forEach(child => { | ||
if (child.isText) { | ||
var text = child.text; | ||
var pos = 0; | ||
var match; | ||
const { | ||
text | ||
} = child; | ||
let pos = 0; | ||
let match; | ||
@@ -152,5 +124,5 @@ do { | ||
if (match) { | ||
var start = match.index; | ||
var end = start + match[0].length; | ||
var attrs = getAttrs instanceof Function ? getAttrs(match[0]) : getAttrs; | ||
const start = match.index; | ||
const end = start + match[0].length; | ||
const attrs = getAttrs instanceof Function ? getAttrs(match[0]) : getAttrs; | ||
@@ -178,5 +150,3 @@ if (start > 0) { | ||
props: { | ||
transformPasted: function transformPasted(slice) { | ||
return new prosemirrorModel.Slice(handler(slice.content), slice.openStart, slice.openEnd); | ||
} | ||
transformPasted: slice => new prosemirrorModel.Slice(handler(slice.content), slice.openStart, slice.openEnd) | ||
} | ||
@@ -187,21 +157,21 @@ }); | ||
function markPasteRule (regexp, type, getAttrs) { | ||
var handler = function handler(fragment, parent) { | ||
var nodes = []; | ||
fragment.forEach(function (child) { | ||
const handler = (fragment, parent) => { | ||
const nodes = []; | ||
fragment.forEach(child => { | ||
if (child.isText) { | ||
var text = child.text, | ||
marks = child.marks; | ||
var pos = 0; | ||
var match; | ||
var isLink = !!marks.filter(function (x) { | ||
return x.type.name === 'link'; | ||
})[0]; // eslint-disable-next-line | ||
const { | ||
text, | ||
marks | ||
} = child; | ||
let pos = 0; | ||
let match; | ||
const isLink = !!marks.filter(x => x.type.name === 'link')[0]; // eslint-disable-next-line | ||
while (!isLink && (match = regexp.exec(text)) !== null) { | ||
if (parent && parent.type.allowsMarkType(type) && match[1]) { | ||
var start = match.index; | ||
var end = start + match[0].length; | ||
var textStart = start + match[0].indexOf(match[1]); | ||
var textEnd = textStart + match[1].length; | ||
var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; // adding text before markdown to nodes | ||
const start = match.index; | ||
const end = start + match[0].length; | ||
const textStart = start + match[0].indexOf(match[1]); | ||
const textEnd = textStart + match[1].length; | ||
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; // adding text before markdown to nodes | ||
@@ -231,5 +201,3 @@ if (start > 0) { | ||
props: { | ||
transformPasted: function transformPasted(slice) { | ||
return new prosemirrorModel.Slice(handler(slice.content), slice.openStart, slice.openEnd); | ||
} | ||
transformPasted: slice => new prosemirrorModel.Slice(handler(slice.content), slice.openStart, slice.openEnd) | ||
} | ||
@@ -240,12 +208,18 @@ }); | ||
function removeMark (type) { | ||
return function (state, dispatch) { | ||
var tr = state.tr, | ||
selection = state.selection; | ||
var from = selection.from, | ||
to = selection.to; | ||
var $from = selection.$from, | ||
empty = selection.empty; | ||
return (state, dispatch) => { | ||
const { | ||
tr, | ||
selection | ||
} = state; | ||
let { | ||
from, | ||
to | ||
} = selection; | ||
const { | ||
$from, | ||
empty | ||
} = selection; | ||
if (empty) { | ||
var range = tiptapUtils.getMarkRange($from, type); | ||
const range = tiptapUtils.getMarkRange($from, type); | ||
from = range.from; | ||
@@ -260,13 +234,11 @@ to = range.to; | ||
function replaceText () { | ||
var range = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
var type = arguments.length > 1 ? arguments[1] : undefined; | ||
var attrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
return function (state, dispatch) { | ||
var _state$selection = state.selection, | ||
$from = _state$selection.$from, | ||
$to = _state$selection.$to; | ||
var index = $from.index(); | ||
var from = range ? range.from : $from.pos; | ||
var to = range ? range.to : $to.pos; | ||
function replaceText (range = null, type, attrs = {}) { | ||
return (state, dispatch) => { | ||
const { | ||
$from, | ||
$to | ||
} = state.selection; | ||
const index = $from.index(); | ||
const from = range ? range.from : $from.pos; | ||
const to = range ? range.to : $to.pos; | ||
@@ -285,7 +257,8 @@ if (!$from.parent.canReplaceWith(index, index, type)) { | ||
function setInlineBlockType (type) { | ||
var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return function (state, dispatch) { | ||
var $from = state.selection.$from; | ||
var index = $from.index(); | ||
function setInlineBlockType (type, attrs = {}) { | ||
return (state, dispatch) => { | ||
const { | ||
$from | ||
} = state.selection; | ||
const index = $from.index(); | ||
@@ -304,3 +277,3 @@ if (!$from.parent.canReplaceWith(index, index, type)) { | ||
// see https://github.com/ProseMirror/prosemirror-transform/blob/master/src/structure.js | ||
// see https://github.com/ProseMirror/prosemirror-transform/blob/main/src/structure.js | ||
// Since this piece of code was "borrowed" from prosemirror, ESLint rules are ignored. | ||
@@ -310,18 +283,14 @@ | ||
function canSplit(doc, pos) { | ||
var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; | ||
var typesAfter = arguments.length > 3 ? arguments[3] : undefined; | ||
var $pos = doc.resolve(pos); | ||
var base = $pos.depth - depth; | ||
var innerType = typesAfter && typesAfter[typesAfter.length - 1] || $pos.parent; | ||
function canSplit(doc, pos, depth = 1, typesAfter) { | ||
const $pos = doc.resolve(pos); | ||
const base = $pos.depth - depth; | ||
const innerType = typesAfter && typesAfter[typesAfter.length - 1] || $pos.parent; | ||
if (base < 0 || $pos.parent.type.spec.isolating || !$pos.parent.canReplace($pos.index(), $pos.parent.childCount) || !innerType.type.validContent($pos.parent.content.cutByIndex($pos.index(), $pos.parent.childCount))) return false; | ||
for (var d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) { | ||
var node = $pos.node(d); | ||
var _index = $pos.index(d); | ||
for (let d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) { | ||
const node = $pos.node(d); | ||
const index = $pos.index(d); | ||
if (node.type.spec.isolating) return false; | ||
var rest = node.content.cutByIndex(_index, node.childCount); | ||
var after = typesAfter && typesAfter[i] || node; | ||
let rest = node.content.cutByIndex(index, node.childCount); | ||
const after = typesAfter && typesAfter[i] || node; | ||
if (after != node) rest = rest.replaceChild(0, after.type.create(after.attrs)); | ||
@@ -332,11 +301,11 @@ /* Change starts from here */ | ||
if (!node.canReplace(_index + 1, node.childCount)) return false; | ||
if (!node.canReplace(index + 1, node.childCount)) return false; | ||
/* Change ends here */ | ||
} | ||
var index = $pos.indexAfter(base); | ||
var baseType = typesAfter && typesAfter[0]; | ||
const index = $pos.indexAfter(base); | ||
const baseType = typesAfter && typesAfter[0]; | ||
return $pos.node(base).canReplaceWith(index, index, baseType ? baseType.type : $pos.node(base + 1).type); | ||
} // this is a copy of splitListItem | ||
// see https://github.com/ProseMirror/prosemirror-schema-list/blob/master/src/schema-list.js | ||
// see https://github.com/ProseMirror/prosemirror-schema-list/blob/main/src/schema-list.js | ||
@@ -346,8 +315,9 @@ | ||
return function (state, dispatch) { | ||
var _state$selection = state.selection, | ||
$from = _state$selection.$from, | ||
$to = _state$selection.$to, | ||
node = _state$selection.node; | ||
const { | ||
$from, | ||
$to, | ||
node | ||
} = state.selection; | ||
if (node && node.isBlock || $from.depth < 2 || !$from.sameParent($to)) return false; | ||
var grandParent = $from.node(-1); | ||
const grandParent = $from.node(-1); | ||
if (grandParent.type != itemType) return false; | ||
@@ -362,18 +332,13 @@ | ||
if (dispatch) { | ||
var wrap = prosemirrorModel.Fragment.empty; | ||
var keepItem = $from.index(-1) > 0; // Build a fragment containing empty versions of the structure | ||
let wrap = prosemirrorModel.Fragment.empty; | ||
const keepItem = $from.index(-1) > 0; // Build a fragment containing empty versions of the structure | ||
// from the outer list item to the parent node of the cursor | ||
for (var d = $from.depth - (keepItem ? 1 : 2); d >= $from.depth - 3; d--) { | ||
wrap = prosemirrorModel.Fragment.from($from.node(d).copy(wrap)); | ||
} // Add a second list item with an empty default start node | ||
for (let d = $from.depth - (keepItem ? 1 : 2); d >= $from.depth - 3; d--) wrap = prosemirrorModel.Fragment.from($from.node(d).copy(wrap)); // Add a second list item with an empty default start node | ||
wrap = wrap.append(prosemirrorModel.Fragment.from(itemType.createAndFill())); | ||
var _tr = state.tr.replace($from.before(keepItem ? null : -1), $from.after(-3), new prosemirrorModel.Slice(wrap, keepItem ? 3 : 2, 2)); | ||
_tr.setSelection(state.selection.constructor.near(_tr.doc.resolve($from.pos + (keepItem ? 3 : 2)))); | ||
dispatch(_tr.scrollIntoView()); | ||
const tr = state.tr.replace($from.before(keepItem ? null : -1), $from.after(-3), new prosemirrorModel.Slice(wrap, keepItem ? 3 : 2, 2)); | ||
tr.setSelection(state.selection.constructor.near(tr.doc.resolve($from.pos + (keepItem ? 3 : 2)))); | ||
dispatch(tr.scrollIntoView()); | ||
} | ||
@@ -384,8 +349,8 @@ | ||
var nextType = $to.pos == $from.end() ? grandParent.contentMatchAt($from.indexAfter(-1)).defaultType : null; | ||
var tr = state.tr.delete($from.pos, $to.pos); | ||
const nextType = $to.pos == $from.end() ? grandParent.contentMatchAt($from.indexAfter(-1)).defaultType : null; | ||
const tr = state.tr.delete($from.pos, $to.pos); | ||
/* Change starts from here */ | ||
// let types = nextType && [null, {type: nextType}] | ||
var types = nextType && [{ | ||
let types = nextType && [{ | ||
type: itemType | ||
@@ -407,6 +372,5 @@ }, { | ||
function toggleBlockType (type, toggletype) { | ||
var attrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
return function (state, dispatch, view) { | ||
var isActive = tiptapUtils.nodeIsActive(state, type, attrs); | ||
function toggleBlockType (type, toggletype, attrs = {}) { | ||
return (state, dispatch, view) => { | ||
const isActive = tiptapUtils.nodeIsActive(state, type, attrs); | ||
@@ -426,8 +390,12 @@ if (isActive) { | ||
function toggleList(listType, itemType) { | ||
return function (state, dispatch, view) { | ||
var schema = state.schema, | ||
selection = state.selection; | ||
var $from = selection.$from, | ||
$to = selection.$to; | ||
var range = $from.blockRange($to); | ||
return (state, dispatch, view) => { | ||
const { | ||
schema, | ||
selection | ||
} = state; | ||
const { | ||
$from, | ||
$to | ||
} = selection; | ||
const range = $from.blockRange($to); | ||
@@ -438,5 +406,3 @@ if (!range) { | ||
var parentList = prosemirrorUtils.findParentNode(function (node) { | ||
return isList(node, schema); | ||
})(selection); | ||
const parentList = prosemirrorUtils.findParentNode(node => isList(node, schema))(selection); | ||
@@ -449,3 +415,5 @@ if (range.depth >= 1 && parentList && range.depth - parentList.depth <= 1) { | ||
if (isList(parentList.node, schema) && listType.validContent(parentList.node.content)) { | ||
var tr = state.tr; | ||
const { | ||
tr | ||
} = state; | ||
tr.setNodeMarkup(parentList.pos, listType); | ||
@@ -465,6 +433,5 @@ | ||
function toggleWrap (type) { | ||
var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return function (state, dispatch, view) { | ||
var isActive = tiptapUtils.nodeIsActive(state, type, attrs); | ||
function toggleWrap (type, attrs = {}) { | ||
return (state, dispatch, view) => { | ||
const isActive = tiptapUtils.nodeIsActive(state, type, attrs); | ||
@@ -480,13 +447,19 @@ if (isActive) { | ||
function updateMark (type, attrs) { | ||
return function (state, dispatch) { | ||
var tr = state.tr, | ||
selection = state.selection, | ||
doc = state.doc; | ||
var from = selection.from, | ||
to = selection.to; | ||
var $from = selection.$from, | ||
empty = selection.empty; | ||
return (state, dispatch) => { | ||
const { | ||
tr, | ||
selection, | ||
doc | ||
} = state; | ||
let { | ||
from, | ||
to | ||
} = selection; | ||
const { | ||
$from, | ||
empty | ||
} = selection; | ||
if (empty) { | ||
var range = tiptapUtils.getMarkRange($from, type); | ||
const range = tiptapUtils.getMarkRange($from, type); | ||
from = range.from; | ||
@@ -496,3 +469,3 @@ to = range.to; | ||
var hasMark = doc.rangeHasMark(from, to, type); | ||
const hasMark = doc.rangeHasMark(from, to, type); | ||
@@ -499,0 +472,0 @@ if (hasMark) { |
/*! | ||
* tiptap-commands v1.14.0 | ||
* (c) 2020 Scrumpy UG (limited liability) | ||
* tiptap-commands v1.14.4 | ||
* (c) 2020 überdosis GbR (limited liability) | ||
* @license MIT | ||
@@ -19,7 +19,10 @@ */ | ||
function insertText () { | ||
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; | ||
return function (state, dispatch) { | ||
var $from = state.selection.$from; | ||
var pos = $from.pos.pos; | ||
function insertText (text = '') { | ||
return (state, dispatch) => { | ||
const { | ||
$from | ||
} = state.selection; | ||
const { | ||
pos | ||
} = $from.pos; | ||
dispatch(state.tr.insertText(text, pos)); | ||
@@ -30,45 +33,10 @@ return true; | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) return _arrayLikeToArray(arr); | ||
} | ||
function _iterableToArray(iter) { | ||
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
function getMarksBetween(start, end, state) { | ||
var marks = []; | ||
state.doc.nodesBetween(start, end, function (node, pos) { | ||
marks = [].concat(_toConsumableArray(marks), _toConsumableArray(node.marks.map(function (mark) { | ||
return { | ||
start: pos, | ||
end: pos + node.nodeSize, | ||
mark: mark | ||
}; | ||
}))); | ||
let marks = []; | ||
state.doc.nodesBetween(start, end, (node, pos) => { | ||
marks = [...marks, ...node.marks.map(mark => ({ | ||
start: pos, | ||
end: pos + node.nodeSize, | ||
mark | ||
}))]; | ||
}); | ||
@@ -79,22 +47,22 @@ return marks; | ||
function markInputRule (regexp, markType, getAttrs) { | ||
return new InputRule(regexp, function (state, match, start, end) { | ||
var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; | ||
var tr = state.tr; | ||
var m = match.length - 1; | ||
var markEnd = end; | ||
var markStart = start; | ||
return new InputRule(regexp, (state, match, start, end) => { | ||
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; | ||
const { | ||
tr | ||
} = state; | ||
const m = match.length - 1; | ||
let markEnd = end; | ||
let markStart = start; | ||
if (match[m]) { | ||
var matchStart = start + match[0].indexOf(match[m - 1]); | ||
var matchEnd = matchStart + match[m - 1].length - 1; | ||
var textStart = matchStart + match[m - 1].lastIndexOf(match[m]); | ||
var textEnd = textStart + match[m].length; | ||
var excludedMarks = getMarksBetween(start, end, state).filter(function (item) { | ||
var excluded = item.mark.type.excluded; | ||
return excluded.find(function (type) { | ||
return type.name === markType.name; | ||
}); | ||
}).filter(function (item) { | ||
return item.end > matchStart; | ||
}); | ||
const matchStart = start + match[0].indexOf(match[m - 1]); | ||
const matchEnd = matchStart + match[m - 1].length - 1; | ||
const textStart = matchStart + match[m - 1].lastIndexOf(match[m]); | ||
const textEnd = textStart + match[m].length; | ||
const excludedMarks = getMarksBetween(start, end, state).filter(item => { | ||
const { | ||
excluded | ||
} = item.mark.type; | ||
return excluded.find(type => type.name === markType.name); | ||
}).filter(item => item.end > matchStart); | ||
@@ -124,5 +92,7 @@ if (excludedMarks.length) { | ||
function nodeInputRule (regexp, type, getAttrs) { | ||
return new InputRule(regexp, function (state, match, start, end) { | ||
var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; | ||
var tr = state.tr; | ||
return new InputRule(regexp, (state, match, start, end) => { | ||
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; | ||
const { | ||
tr | ||
} = state; | ||
@@ -138,9 +108,11 @@ if (match[0]) { | ||
function pasteRule (regexp, type, getAttrs) { | ||
var handler = function handler(fragment) { | ||
var nodes = []; | ||
fragment.forEach(function (child) { | ||
const handler = fragment => { | ||
const nodes = []; | ||
fragment.forEach(child => { | ||
if (child.isText) { | ||
var text = child.text; | ||
var pos = 0; | ||
var match; | ||
const { | ||
text | ||
} = child; | ||
let pos = 0; | ||
let match; | ||
@@ -151,5 +123,5 @@ do { | ||
if (match) { | ||
var start = match.index; | ||
var end = start + match[0].length; | ||
var attrs = getAttrs instanceof Function ? getAttrs(match[0]) : getAttrs; | ||
const start = match.index; | ||
const end = start + match[0].length; | ||
const attrs = getAttrs instanceof Function ? getAttrs(match[0]) : getAttrs; | ||
@@ -177,5 +149,3 @@ if (start > 0) { | ||
props: { | ||
transformPasted: function transformPasted(slice) { | ||
return new Slice(handler(slice.content), slice.openStart, slice.openEnd); | ||
} | ||
transformPasted: slice => new Slice(handler(slice.content), slice.openStart, slice.openEnd) | ||
} | ||
@@ -186,21 +156,21 @@ }); | ||
function markPasteRule (regexp, type, getAttrs) { | ||
var handler = function handler(fragment, parent) { | ||
var nodes = []; | ||
fragment.forEach(function (child) { | ||
const handler = (fragment, parent) => { | ||
const nodes = []; | ||
fragment.forEach(child => { | ||
if (child.isText) { | ||
var text = child.text, | ||
marks = child.marks; | ||
var pos = 0; | ||
var match; | ||
var isLink = !!marks.filter(function (x) { | ||
return x.type.name === 'link'; | ||
})[0]; // eslint-disable-next-line | ||
const { | ||
text, | ||
marks | ||
} = child; | ||
let pos = 0; | ||
let match; | ||
const isLink = !!marks.filter(x => x.type.name === 'link')[0]; // eslint-disable-next-line | ||
while (!isLink && (match = regexp.exec(text)) !== null) { | ||
if (parent && parent.type.allowsMarkType(type) && match[1]) { | ||
var start = match.index; | ||
var end = start + match[0].length; | ||
var textStart = start + match[0].indexOf(match[1]); | ||
var textEnd = textStart + match[1].length; | ||
var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; // adding text before markdown to nodes | ||
const start = match.index; | ||
const end = start + match[0].length; | ||
const textStart = start + match[0].indexOf(match[1]); | ||
const textEnd = textStart + match[1].length; | ||
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; // adding text before markdown to nodes | ||
@@ -230,5 +200,3 @@ if (start > 0) { | ||
props: { | ||
transformPasted: function transformPasted(slice) { | ||
return new Slice(handler(slice.content), slice.openStart, slice.openEnd); | ||
} | ||
transformPasted: slice => new Slice(handler(slice.content), slice.openStart, slice.openEnd) | ||
} | ||
@@ -239,12 +207,18 @@ }); | ||
function removeMark (type) { | ||
return function (state, dispatch) { | ||
var tr = state.tr, | ||
selection = state.selection; | ||
var from = selection.from, | ||
to = selection.to; | ||
var $from = selection.$from, | ||
empty = selection.empty; | ||
return (state, dispatch) => { | ||
const { | ||
tr, | ||
selection | ||
} = state; | ||
let { | ||
from, | ||
to | ||
} = selection; | ||
const { | ||
$from, | ||
empty | ||
} = selection; | ||
if (empty) { | ||
var range = getMarkRange($from, type); | ||
const range = getMarkRange($from, type); | ||
from = range.from; | ||
@@ -259,13 +233,11 @@ to = range.to; | ||
function replaceText () { | ||
var range = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
var type = arguments.length > 1 ? arguments[1] : undefined; | ||
var attrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
return function (state, dispatch) { | ||
var _state$selection = state.selection, | ||
$from = _state$selection.$from, | ||
$to = _state$selection.$to; | ||
var index = $from.index(); | ||
var from = range ? range.from : $from.pos; | ||
var to = range ? range.to : $to.pos; | ||
function replaceText (range = null, type, attrs = {}) { | ||
return (state, dispatch) => { | ||
const { | ||
$from, | ||
$to | ||
} = state.selection; | ||
const index = $from.index(); | ||
const from = range ? range.from : $from.pos; | ||
const to = range ? range.to : $to.pos; | ||
@@ -284,7 +256,8 @@ if (!$from.parent.canReplaceWith(index, index, type)) { | ||
function setInlineBlockType (type) { | ||
var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return function (state, dispatch) { | ||
var $from = state.selection.$from; | ||
var index = $from.index(); | ||
function setInlineBlockType (type, attrs = {}) { | ||
return (state, dispatch) => { | ||
const { | ||
$from | ||
} = state.selection; | ||
const index = $from.index(); | ||
@@ -303,3 +276,3 @@ if (!$from.parent.canReplaceWith(index, index, type)) { | ||
// see https://github.com/ProseMirror/prosemirror-transform/blob/master/src/structure.js | ||
// see https://github.com/ProseMirror/prosemirror-transform/blob/main/src/structure.js | ||
// Since this piece of code was "borrowed" from prosemirror, ESLint rules are ignored. | ||
@@ -309,18 +282,14 @@ | ||
function canSplit(doc, pos) { | ||
var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; | ||
var typesAfter = arguments.length > 3 ? arguments[3] : undefined; | ||
var $pos = doc.resolve(pos); | ||
var base = $pos.depth - depth; | ||
var innerType = typesAfter && typesAfter[typesAfter.length - 1] || $pos.parent; | ||
function canSplit(doc, pos, depth = 1, typesAfter) { | ||
const $pos = doc.resolve(pos); | ||
const base = $pos.depth - depth; | ||
const innerType = typesAfter && typesAfter[typesAfter.length - 1] || $pos.parent; | ||
if (base < 0 || $pos.parent.type.spec.isolating || !$pos.parent.canReplace($pos.index(), $pos.parent.childCount) || !innerType.type.validContent($pos.parent.content.cutByIndex($pos.index(), $pos.parent.childCount))) return false; | ||
for (var d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) { | ||
var node = $pos.node(d); | ||
var _index = $pos.index(d); | ||
for (let d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) { | ||
const node = $pos.node(d); | ||
const index = $pos.index(d); | ||
if (node.type.spec.isolating) return false; | ||
var rest = node.content.cutByIndex(_index, node.childCount); | ||
var after = typesAfter && typesAfter[i] || node; | ||
let rest = node.content.cutByIndex(index, node.childCount); | ||
const after = typesAfter && typesAfter[i] || node; | ||
if (after != node) rest = rest.replaceChild(0, after.type.create(after.attrs)); | ||
@@ -331,11 +300,11 @@ /* Change starts from here */ | ||
if (!node.canReplace(_index + 1, node.childCount)) return false; | ||
if (!node.canReplace(index + 1, node.childCount)) return false; | ||
/* Change ends here */ | ||
} | ||
var index = $pos.indexAfter(base); | ||
var baseType = typesAfter && typesAfter[0]; | ||
const index = $pos.indexAfter(base); | ||
const baseType = typesAfter && typesAfter[0]; | ||
return $pos.node(base).canReplaceWith(index, index, baseType ? baseType.type : $pos.node(base + 1).type); | ||
} // this is a copy of splitListItem | ||
// see https://github.com/ProseMirror/prosemirror-schema-list/blob/master/src/schema-list.js | ||
// see https://github.com/ProseMirror/prosemirror-schema-list/blob/main/src/schema-list.js | ||
@@ -345,8 +314,9 @@ | ||
return function (state, dispatch) { | ||
var _state$selection = state.selection, | ||
$from = _state$selection.$from, | ||
$to = _state$selection.$to, | ||
node = _state$selection.node; | ||
const { | ||
$from, | ||
$to, | ||
node | ||
} = state.selection; | ||
if (node && node.isBlock || $from.depth < 2 || !$from.sameParent($to)) return false; | ||
var grandParent = $from.node(-1); | ||
const grandParent = $from.node(-1); | ||
if (grandParent.type != itemType) return false; | ||
@@ -361,18 +331,13 @@ | ||
if (dispatch) { | ||
var wrap = Fragment.empty; | ||
var keepItem = $from.index(-1) > 0; // Build a fragment containing empty versions of the structure | ||
let wrap = Fragment.empty; | ||
const keepItem = $from.index(-1) > 0; // Build a fragment containing empty versions of the structure | ||
// from the outer list item to the parent node of the cursor | ||
for (var d = $from.depth - (keepItem ? 1 : 2); d >= $from.depth - 3; d--) { | ||
wrap = Fragment.from($from.node(d).copy(wrap)); | ||
} // Add a second list item with an empty default start node | ||
for (let d = $from.depth - (keepItem ? 1 : 2); d >= $from.depth - 3; d--) wrap = Fragment.from($from.node(d).copy(wrap)); // Add a second list item with an empty default start node | ||
wrap = wrap.append(Fragment.from(itemType.createAndFill())); | ||
var _tr = state.tr.replace($from.before(keepItem ? null : -1), $from.after(-3), new Slice(wrap, keepItem ? 3 : 2, 2)); | ||
_tr.setSelection(state.selection.constructor.near(_tr.doc.resolve($from.pos + (keepItem ? 3 : 2)))); | ||
dispatch(_tr.scrollIntoView()); | ||
const tr = state.tr.replace($from.before(keepItem ? null : -1), $from.after(-3), new Slice(wrap, keepItem ? 3 : 2, 2)); | ||
tr.setSelection(state.selection.constructor.near(tr.doc.resolve($from.pos + (keepItem ? 3 : 2)))); | ||
dispatch(tr.scrollIntoView()); | ||
} | ||
@@ -383,8 +348,8 @@ | ||
var nextType = $to.pos == $from.end() ? grandParent.contentMatchAt($from.indexAfter(-1)).defaultType : null; | ||
var tr = state.tr.delete($from.pos, $to.pos); | ||
const nextType = $to.pos == $from.end() ? grandParent.contentMatchAt($from.indexAfter(-1)).defaultType : null; | ||
const tr = state.tr.delete($from.pos, $to.pos); | ||
/* Change starts from here */ | ||
// let types = nextType && [null, {type: nextType}] | ||
var types = nextType && [{ | ||
let types = nextType && [{ | ||
type: itemType | ||
@@ -406,6 +371,5 @@ }, { | ||
function toggleBlockType (type, toggletype) { | ||
var attrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
return function (state, dispatch, view) { | ||
var isActive = nodeIsActive(state, type, attrs); | ||
function toggleBlockType (type, toggletype, attrs = {}) { | ||
return (state, dispatch, view) => { | ||
const isActive = nodeIsActive(state, type, attrs); | ||
@@ -425,8 +389,12 @@ if (isActive) { | ||
function toggleList(listType, itemType) { | ||
return function (state, dispatch, view) { | ||
var schema = state.schema, | ||
selection = state.selection; | ||
var $from = selection.$from, | ||
$to = selection.$to; | ||
var range = $from.blockRange($to); | ||
return (state, dispatch, view) => { | ||
const { | ||
schema, | ||
selection | ||
} = state; | ||
const { | ||
$from, | ||
$to | ||
} = selection; | ||
const range = $from.blockRange($to); | ||
@@ -437,5 +405,3 @@ if (!range) { | ||
var parentList = findParentNode(function (node) { | ||
return isList(node, schema); | ||
})(selection); | ||
const parentList = findParentNode(node => isList(node, schema))(selection); | ||
@@ -448,3 +414,5 @@ if (range.depth >= 1 && parentList && range.depth - parentList.depth <= 1) { | ||
if (isList(parentList.node, schema) && listType.validContent(parentList.node.content)) { | ||
var tr = state.tr; | ||
const { | ||
tr | ||
} = state; | ||
tr.setNodeMarkup(parentList.pos, listType); | ||
@@ -464,6 +432,5 @@ | ||
function toggleWrap (type) { | ||
var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return function (state, dispatch, view) { | ||
var isActive = nodeIsActive(state, type, attrs); | ||
function toggleWrap (type, attrs = {}) { | ||
return (state, dispatch, view) => { | ||
const isActive = nodeIsActive(state, type, attrs); | ||
@@ -479,13 +446,19 @@ if (isActive) { | ||
function updateMark (type, attrs) { | ||
return function (state, dispatch) { | ||
var tr = state.tr, | ||
selection = state.selection, | ||
doc = state.doc; | ||
var from = selection.from, | ||
to = selection.to; | ||
var $from = selection.$from, | ||
empty = selection.empty; | ||
return (state, dispatch) => { | ||
const { | ||
tr, | ||
selection, | ||
doc | ||
} = state; | ||
let { | ||
from, | ||
to | ||
} = selection; | ||
const { | ||
$from, | ||
empty | ||
} = selection; | ||
if (empty) { | ||
var range = getMarkRange($from, type); | ||
const range = getMarkRange($from, type); | ||
from = range.from; | ||
@@ -495,3 +468,3 @@ to = range.to; | ||
var hasMark = doc.rangeHasMark(from, to, type); | ||
const hasMark = doc.rangeHasMark(from, to, type); | ||
@@ -498,0 +471,0 @@ if (hasMark) { |
/*! | ||
* tiptap-commands v1.14.0 | ||
* (c) 2020 Scrumpy UG (limited liability) | ||
* tiptap-commands v1.14.4 | ||
* (c) 2020 überdosis GbR (limited liability) | ||
* @license MIT | ||
@@ -14,7 +14,10 @@ */ | ||
function insertText () { | ||
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; | ||
return function (state, dispatch) { | ||
var $from = state.selection.$from; | ||
var pos = $from.pos.pos; | ||
function insertText (text = '') { | ||
return (state, dispatch) => { | ||
const { | ||
$from | ||
} = state.selection; | ||
const { | ||
pos | ||
} = $from.pos; | ||
dispatch(state.tr.insertText(text, pos)); | ||
@@ -25,45 +28,10 @@ return true; | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) return _arrayLikeToArray(arr); | ||
} | ||
function _iterableToArray(iter) { | ||
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
function getMarksBetween(start, end, state) { | ||
var marks = []; | ||
state.doc.nodesBetween(start, end, function (node, pos) { | ||
marks = [].concat(_toConsumableArray(marks), _toConsumableArray(node.marks.map(function (mark) { | ||
return { | ||
start: pos, | ||
end: pos + node.nodeSize, | ||
mark: mark | ||
}; | ||
}))); | ||
let marks = []; | ||
state.doc.nodesBetween(start, end, (node, pos) => { | ||
marks = [...marks, ...node.marks.map(mark => ({ | ||
start: pos, | ||
end: pos + node.nodeSize, | ||
mark | ||
}))]; | ||
}); | ||
@@ -74,22 +42,22 @@ return marks; | ||
function markInputRule (regexp, markType, getAttrs) { | ||
return new prosemirrorInputrules.InputRule(regexp, function (state, match, start, end) { | ||
var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; | ||
var tr = state.tr; | ||
var m = match.length - 1; | ||
var markEnd = end; | ||
var markStart = start; | ||
return new prosemirrorInputrules.InputRule(regexp, (state, match, start, end) => { | ||
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; | ||
const { | ||
tr | ||
} = state; | ||
const m = match.length - 1; | ||
let markEnd = end; | ||
let markStart = start; | ||
if (match[m]) { | ||
var matchStart = start + match[0].indexOf(match[m - 1]); | ||
var matchEnd = matchStart + match[m - 1].length - 1; | ||
var textStart = matchStart + match[m - 1].lastIndexOf(match[m]); | ||
var textEnd = textStart + match[m].length; | ||
var excludedMarks = getMarksBetween(start, end, state).filter(function (item) { | ||
var excluded = item.mark.type.excluded; | ||
return excluded.find(function (type) { | ||
return type.name === markType.name; | ||
}); | ||
}).filter(function (item) { | ||
return item.end > matchStart; | ||
}); | ||
const matchStart = start + match[0].indexOf(match[m - 1]); | ||
const matchEnd = matchStart + match[m - 1].length - 1; | ||
const textStart = matchStart + match[m - 1].lastIndexOf(match[m]); | ||
const textEnd = textStart + match[m].length; | ||
const excludedMarks = getMarksBetween(start, end, state).filter(item => { | ||
const { | ||
excluded | ||
} = item.mark.type; | ||
return excluded.find(type => type.name === markType.name); | ||
}).filter(item => item.end > matchStart); | ||
@@ -119,5 +87,7 @@ if (excludedMarks.length) { | ||
function nodeInputRule (regexp, type, getAttrs) { | ||
return new prosemirrorInputrules.InputRule(regexp, function (state, match, start, end) { | ||
var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; | ||
var tr = state.tr; | ||
return new prosemirrorInputrules.InputRule(regexp, (state, match, start, end) => { | ||
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; | ||
const { | ||
tr | ||
} = state; | ||
@@ -133,9 +103,11 @@ if (match[0]) { | ||
function pasteRule (regexp, type, getAttrs) { | ||
var handler = function handler(fragment) { | ||
var nodes = []; | ||
fragment.forEach(function (child) { | ||
const handler = fragment => { | ||
const nodes = []; | ||
fragment.forEach(child => { | ||
if (child.isText) { | ||
var text = child.text; | ||
var pos = 0; | ||
var match; | ||
const { | ||
text | ||
} = child; | ||
let pos = 0; | ||
let match; | ||
@@ -146,5 +118,5 @@ do { | ||
if (match) { | ||
var start = match.index; | ||
var end = start + match[0].length; | ||
var attrs = getAttrs instanceof Function ? getAttrs(match[0]) : getAttrs; | ||
const start = match.index; | ||
const end = start + match[0].length; | ||
const attrs = getAttrs instanceof Function ? getAttrs(match[0]) : getAttrs; | ||
@@ -172,5 +144,3 @@ if (start > 0) { | ||
props: { | ||
transformPasted: function transformPasted(slice) { | ||
return new prosemirrorModel.Slice(handler(slice.content), slice.openStart, slice.openEnd); | ||
} | ||
transformPasted: slice => new prosemirrorModel.Slice(handler(slice.content), slice.openStart, slice.openEnd) | ||
} | ||
@@ -181,21 +151,21 @@ }); | ||
function markPasteRule (regexp, type, getAttrs) { | ||
var handler = function handler(fragment, parent) { | ||
var nodes = []; | ||
fragment.forEach(function (child) { | ||
const handler = (fragment, parent) => { | ||
const nodes = []; | ||
fragment.forEach(child => { | ||
if (child.isText) { | ||
var text = child.text, | ||
marks = child.marks; | ||
var pos = 0; | ||
var match; | ||
var isLink = !!marks.filter(function (x) { | ||
return x.type.name === 'link'; | ||
})[0]; // eslint-disable-next-line | ||
const { | ||
text, | ||
marks | ||
} = child; | ||
let pos = 0; | ||
let match; | ||
const isLink = !!marks.filter(x => x.type.name === 'link')[0]; // eslint-disable-next-line | ||
while (!isLink && (match = regexp.exec(text)) !== null) { | ||
if (parent && parent.type.allowsMarkType(type) && match[1]) { | ||
var start = match.index; | ||
var end = start + match[0].length; | ||
var textStart = start + match[0].indexOf(match[1]); | ||
var textEnd = textStart + match[1].length; | ||
var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; // adding text before markdown to nodes | ||
const start = match.index; | ||
const end = start + match[0].length; | ||
const textStart = start + match[0].indexOf(match[1]); | ||
const textEnd = textStart + match[1].length; | ||
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs; // adding text before markdown to nodes | ||
@@ -225,5 +195,3 @@ if (start > 0) { | ||
props: { | ||
transformPasted: function transformPasted(slice) { | ||
return new prosemirrorModel.Slice(handler(slice.content), slice.openStart, slice.openEnd); | ||
} | ||
transformPasted: slice => new prosemirrorModel.Slice(handler(slice.content), slice.openStart, slice.openEnd) | ||
} | ||
@@ -234,12 +202,18 @@ }); | ||
function removeMark (type) { | ||
return function (state, dispatch) { | ||
var tr = state.tr, | ||
selection = state.selection; | ||
var from = selection.from, | ||
to = selection.to; | ||
var $from = selection.$from, | ||
empty = selection.empty; | ||
return (state, dispatch) => { | ||
const { | ||
tr, | ||
selection | ||
} = state; | ||
let { | ||
from, | ||
to | ||
} = selection; | ||
const { | ||
$from, | ||
empty | ||
} = selection; | ||
if (empty) { | ||
var range = tiptapUtils.getMarkRange($from, type); | ||
const range = tiptapUtils.getMarkRange($from, type); | ||
from = range.from; | ||
@@ -254,13 +228,11 @@ to = range.to; | ||
function replaceText () { | ||
var range = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
var type = arguments.length > 1 ? arguments[1] : undefined; | ||
var attrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
return function (state, dispatch) { | ||
var _state$selection = state.selection, | ||
$from = _state$selection.$from, | ||
$to = _state$selection.$to; | ||
var index = $from.index(); | ||
var from = range ? range.from : $from.pos; | ||
var to = range ? range.to : $to.pos; | ||
function replaceText (range = null, type, attrs = {}) { | ||
return (state, dispatch) => { | ||
const { | ||
$from, | ||
$to | ||
} = state.selection; | ||
const index = $from.index(); | ||
const from = range ? range.from : $from.pos; | ||
const to = range ? range.to : $to.pos; | ||
@@ -279,7 +251,8 @@ if (!$from.parent.canReplaceWith(index, index, type)) { | ||
function setInlineBlockType (type) { | ||
var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return function (state, dispatch) { | ||
var $from = state.selection.$from; | ||
var index = $from.index(); | ||
function setInlineBlockType (type, attrs = {}) { | ||
return (state, dispatch) => { | ||
const { | ||
$from | ||
} = state.selection; | ||
const index = $from.index(); | ||
@@ -298,3 +271,3 @@ if (!$from.parent.canReplaceWith(index, index, type)) { | ||
// see https://github.com/ProseMirror/prosemirror-transform/blob/master/src/structure.js | ||
// see https://github.com/ProseMirror/prosemirror-transform/blob/main/src/structure.js | ||
// Since this piece of code was "borrowed" from prosemirror, ESLint rules are ignored. | ||
@@ -304,18 +277,14 @@ | ||
function canSplit(doc, pos) { | ||
var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; | ||
var typesAfter = arguments.length > 3 ? arguments[3] : undefined; | ||
var $pos = doc.resolve(pos); | ||
var base = $pos.depth - depth; | ||
var innerType = typesAfter && typesAfter[typesAfter.length - 1] || $pos.parent; | ||
function canSplit(doc, pos, depth = 1, typesAfter) { | ||
const $pos = doc.resolve(pos); | ||
const base = $pos.depth - depth; | ||
const innerType = typesAfter && typesAfter[typesAfter.length - 1] || $pos.parent; | ||
if (base < 0 || $pos.parent.type.spec.isolating || !$pos.parent.canReplace($pos.index(), $pos.parent.childCount) || !innerType.type.validContent($pos.parent.content.cutByIndex($pos.index(), $pos.parent.childCount))) return false; | ||
for (var d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) { | ||
var node = $pos.node(d); | ||
var _index = $pos.index(d); | ||
for (let d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) { | ||
const node = $pos.node(d); | ||
const index = $pos.index(d); | ||
if (node.type.spec.isolating) return false; | ||
var rest = node.content.cutByIndex(_index, node.childCount); | ||
var after = typesAfter && typesAfter[i] || node; | ||
let rest = node.content.cutByIndex(index, node.childCount); | ||
const after = typesAfter && typesAfter[i] || node; | ||
if (after != node) rest = rest.replaceChild(0, after.type.create(after.attrs)); | ||
@@ -326,11 +295,11 @@ /* Change starts from here */ | ||
if (!node.canReplace(_index + 1, node.childCount)) return false; | ||
if (!node.canReplace(index + 1, node.childCount)) return false; | ||
/* Change ends here */ | ||
} | ||
var index = $pos.indexAfter(base); | ||
var baseType = typesAfter && typesAfter[0]; | ||
const index = $pos.indexAfter(base); | ||
const baseType = typesAfter && typesAfter[0]; | ||
return $pos.node(base).canReplaceWith(index, index, baseType ? baseType.type : $pos.node(base + 1).type); | ||
} // this is a copy of splitListItem | ||
// see https://github.com/ProseMirror/prosemirror-schema-list/blob/master/src/schema-list.js | ||
// see https://github.com/ProseMirror/prosemirror-schema-list/blob/main/src/schema-list.js | ||
@@ -340,8 +309,9 @@ | ||
return function (state, dispatch) { | ||
var _state$selection = state.selection, | ||
$from = _state$selection.$from, | ||
$to = _state$selection.$to, | ||
node = _state$selection.node; | ||
const { | ||
$from, | ||
$to, | ||
node | ||
} = state.selection; | ||
if (node && node.isBlock || $from.depth < 2 || !$from.sameParent($to)) return false; | ||
var grandParent = $from.node(-1); | ||
const grandParent = $from.node(-1); | ||
if (grandParent.type != itemType) return false; | ||
@@ -356,18 +326,13 @@ | ||
if (dispatch) { | ||
var wrap = prosemirrorModel.Fragment.empty; | ||
var keepItem = $from.index(-1) > 0; // Build a fragment containing empty versions of the structure | ||
let wrap = prosemirrorModel.Fragment.empty; | ||
const keepItem = $from.index(-1) > 0; // Build a fragment containing empty versions of the structure | ||
// from the outer list item to the parent node of the cursor | ||
for (var d = $from.depth - (keepItem ? 1 : 2); d >= $from.depth - 3; d--) { | ||
wrap = prosemirrorModel.Fragment.from($from.node(d).copy(wrap)); | ||
} // Add a second list item with an empty default start node | ||
for (let d = $from.depth - (keepItem ? 1 : 2); d >= $from.depth - 3; d--) wrap = prosemirrorModel.Fragment.from($from.node(d).copy(wrap)); // Add a second list item with an empty default start node | ||
wrap = wrap.append(prosemirrorModel.Fragment.from(itemType.createAndFill())); | ||
var _tr = state.tr.replace($from.before(keepItem ? null : -1), $from.after(-3), new prosemirrorModel.Slice(wrap, keepItem ? 3 : 2, 2)); | ||
_tr.setSelection(state.selection.constructor.near(_tr.doc.resolve($from.pos + (keepItem ? 3 : 2)))); | ||
dispatch(_tr.scrollIntoView()); | ||
const tr = state.tr.replace($from.before(keepItem ? null : -1), $from.after(-3), new prosemirrorModel.Slice(wrap, keepItem ? 3 : 2, 2)); | ||
tr.setSelection(state.selection.constructor.near(tr.doc.resolve($from.pos + (keepItem ? 3 : 2)))); | ||
dispatch(tr.scrollIntoView()); | ||
} | ||
@@ -378,8 +343,8 @@ | ||
var nextType = $to.pos == $from.end() ? grandParent.contentMatchAt($from.indexAfter(-1)).defaultType : null; | ||
var tr = state.tr.delete($from.pos, $to.pos); | ||
const nextType = $to.pos == $from.end() ? grandParent.contentMatchAt($from.indexAfter(-1)).defaultType : null; | ||
const tr = state.tr.delete($from.pos, $to.pos); | ||
/* Change starts from here */ | ||
// let types = nextType && [null, {type: nextType}] | ||
var types = nextType && [{ | ||
let types = nextType && [{ | ||
type: itemType | ||
@@ -401,6 +366,5 @@ }, { | ||
function toggleBlockType (type, toggletype) { | ||
var attrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
return function (state, dispatch, view) { | ||
var isActive = tiptapUtils.nodeIsActive(state, type, attrs); | ||
function toggleBlockType (type, toggletype, attrs = {}) { | ||
return (state, dispatch, view) => { | ||
const isActive = tiptapUtils.nodeIsActive(state, type, attrs); | ||
@@ -420,8 +384,12 @@ if (isActive) { | ||
function toggleList(listType, itemType) { | ||
return function (state, dispatch, view) { | ||
var schema = state.schema, | ||
selection = state.selection; | ||
var $from = selection.$from, | ||
$to = selection.$to; | ||
var range = $from.blockRange($to); | ||
return (state, dispatch, view) => { | ||
const { | ||
schema, | ||
selection | ||
} = state; | ||
const { | ||
$from, | ||
$to | ||
} = selection; | ||
const range = $from.blockRange($to); | ||
@@ -432,5 +400,3 @@ if (!range) { | ||
var parentList = prosemirrorUtils.findParentNode(function (node) { | ||
return isList(node, schema); | ||
})(selection); | ||
const parentList = prosemirrorUtils.findParentNode(node => isList(node, schema))(selection); | ||
@@ -443,3 +409,5 @@ if (range.depth >= 1 && parentList && range.depth - parentList.depth <= 1) { | ||
if (isList(parentList.node, schema) && listType.validContent(parentList.node.content)) { | ||
var tr = state.tr; | ||
const { | ||
tr | ||
} = state; | ||
tr.setNodeMarkup(parentList.pos, listType); | ||
@@ -459,6 +427,5 @@ | ||
function toggleWrap (type) { | ||
var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return function (state, dispatch, view) { | ||
var isActive = tiptapUtils.nodeIsActive(state, type, attrs); | ||
function toggleWrap (type, attrs = {}) { | ||
return (state, dispatch, view) => { | ||
const isActive = tiptapUtils.nodeIsActive(state, type, attrs); | ||
@@ -474,13 +441,19 @@ if (isActive) { | ||
function updateMark (type, attrs) { | ||
return function (state, dispatch) { | ||
var tr = state.tr, | ||
selection = state.selection, | ||
doc = state.doc; | ||
var from = selection.from, | ||
to = selection.to; | ||
var $from = selection.$from, | ||
empty = selection.empty; | ||
return (state, dispatch) => { | ||
const { | ||
tr, | ||
selection, | ||
doc | ||
} = state; | ||
let { | ||
from, | ||
to | ||
} = selection; | ||
const { | ||
$from, | ||
empty | ||
} = selection; | ||
if (empty) { | ||
var range = tiptapUtils.getMarkRange($from, type); | ||
const range = tiptapUtils.getMarkRange($from, type); | ||
from = range.from; | ||
@@ -490,3 +463,3 @@ to = range.to; | ||
var hasMark = doc.rangeHasMark(from, to, type); | ||
const hasMark = doc.rangeHasMark(from, to, type); | ||
@@ -493,0 +466,0 @@ if (hasMark) { |
/*! | ||
* tiptap-commands v1.14.0 | ||
* (c) 2020 Scrumpy UG (limited liability) | ||
* tiptap-commands v1.14.4 | ||
* (c) 2020 überdosis GbR (limited liability) | ||
* @license MIT | ||
@@ -10,6 +10,6 @@ */ | ||
/*! | ||
* tiptap-commands v1.14.0 | ||
* (c) 2020 Scrumpy UG (limited liability) | ||
* tiptap-commands v1.14.4 | ||
* (c) 2020 überdosis GbR (limited liability) | ||
* @license MIT | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("prosemirror-commands"),require("prosemirror-schema-list"),require("prosemirror-inputrules"),require("prosemirror-state"),require("prosemirror-model"),require("tiptap-utils"),require("prosemirror-utils")):"function"==typeof define&&define.amd?define(["exports","prosemirror-commands","prosemirror-schema-list","prosemirror-inputrules","prosemirror-state","prosemirror-model","tiptap-utils","prosemirror-utils"],t):t((e=e||self).tiptapCommands={},e.prosemirrorCommands,e.prosemirrorSchemaList,e.prosemirrorInputrules,e.prosemirrorState,e.prosemirrorModel,e.tiptapUtils,e.prosemirrorUtils)}(this,(function(e,t,r,n,o,i,u,a){"use strict";function c(e){return function(e){if(Array.isArray(e))return l(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return l(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return l(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function p(e,t){return e.type===t.nodes.bullet_list||e.type===t.nodes.ordered_list||e.type===t.nodes.todo_list}Object.defineProperty(e,"autoJoin",{enumerable:!0,get:function(){return t.autoJoin}}),Object.defineProperty(e,"baseKeymap",{enumerable:!0,get:function(){return t.baseKeymap}}),Object.defineProperty(e,"chainCommands",{enumerable:!0,get:function(){return t.chainCommands}}),Object.defineProperty(e,"createParagraphNear",{enumerable:!0,get:function(){return t.createParagraphNear}}),Object.defineProperty(e,"deleteSelection",{enumerable:!0,get:function(){return t.deleteSelection}}),Object.defineProperty(e,"exitCode",{enumerable:!0,get:function(){return t.exitCode}}),Object.defineProperty(e,"joinBackward",{enumerable:!0,get:function(){return t.joinBackward}}),Object.defineProperty(e,"joinDown",{enumerable:!0,get:function(){return t.joinDown}}),Object.defineProperty(e,"joinForward",{enumerable:!0,get:function(){return t.joinForward}}),Object.defineProperty(e,"joinUp",{enumerable:!0,get:function(){return t.joinUp}}),Object.defineProperty(e,"lift",{enumerable:!0,get:function(){return t.lift}}),Object.defineProperty(e,"liftEmptyBlock",{enumerable:!0,get:function(){return t.liftEmptyBlock}}),Object.defineProperty(e,"macBaseKeymap",{enumerable:!0,get:function(){return t.macBaseKeymap}}),Object.defineProperty(e,"newlineInCode",{enumerable:!0,get:function(){return t.newlineInCode}}),Object.defineProperty(e,"pcBaseKeymap",{enumerable:!0,get:function(){return t.pcBaseKeymap}}),Object.defineProperty(e,"selectAll",{enumerable:!0,get:function(){return t.selectAll}}),Object.defineProperty(e,"selectNodeBackward",{enumerable:!0,get:function(){return t.selectNodeBackward}}),Object.defineProperty(e,"selectNodeForward",{enumerable:!0,get:function(){return t.selectNodeForward}}),Object.defineProperty(e,"selectParentNode",{enumerable:!0,get:function(){return t.selectParentNode}}),Object.defineProperty(e,"setBlockType",{enumerable:!0,get:function(){return t.setBlockType}}),Object.defineProperty(e,"splitBlock",{enumerable:!0,get:function(){return t.splitBlock}}),Object.defineProperty(e,"splitBlockKeepMarks",{enumerable:!0,get:function(){return t.splitBlockKeepMarks}}),Object.defineProperty(e,"toggleMark",{enumerable:!0,get:function(){return t.toggleMark}}),Object.defineProperty(e,"wrapIn",{enumerable:!0,get:function(){return t.wrapIn}}),Object.defineProperty(e,"addListNodes",{enumerable:!0,get:function(){return r.addListNodes}}),Object.defineProperty(e,"liftListItem",{enumerable:!0,get:function(){return r.liftListItem}}),Object.defineProperty(e,"sinkListItem",{enumerable:!0,get:function(){return r.sinkListItem}}),Object.defineProperty(e,"splitListItem",{enumerable:!0,get:function(){return r.splitListItem}}),Object.defineProperty(e,"wrapInList",{enumerable:!0,get:function(){return r.wrapInList}}),Object.defineProperty(e,"textblockTypeInputRule",{enumerable:!0,get:function(){return n.textblockTypeInputRule}}),Object.defineProperty(e,"wrappingInputRule",{enumerable:!0,get:function(){return n.wrappingInputRule}}),e.insertText=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return function(t,r){var n=t.selection.$from.pos.pos;return r(t.tr.insertText(e,n)),!0}},e.markInputRule=function(e,t,r){return new n.InputRule(e,(function(e,n,o,i){var u=r instanceof Function?r(n):r,a=e.tr,l=n.length-1,p=i,f=o;if(n[l]){var s=o+n[0].indexOf(n[l-1]),d=s+n[l-1].length-1,m=s+n[l-1].lastIndexOf(n[l]),y=m+n[l].length;if(function(e,t,r){var n=[];return r.doc.nodesBetween(e,t,(function(e,t){n=[].concat(c(n),c(e.marks.map((function(r){return{start:t,end:t+e.nodeSize,mark:r}}))))})),n}(o,i,e).filter((function(e){return e.mark.type.excluded.find((function(e){return e.name===t.name}))})).filter((function(e){return e.end>s})).length)return!1;y<d&&a.delete(y,d),m>s&&a.delete(s,m),p=(f=s)+n[l].length}return a.addMark(f,p,t.create(u)),a.removeStoredMark(t),a}))},e.markPasteRule=function(e,t,r){return new o.Plugin({props:{transformPasted:function(n){return new i.Slice(function n(o,u){var a=[];return o.forEach((function(o){if(o.isText){for(var i,c=o.text,l=0,p=!!o.marks.filter((function(e){return"link"===e.type.name}))[0];!p&&null!==(i=e.exec(c));)if(u&&u.type.allowsMarkType(t)&&i[1]){var f=i.index,s=f+i[0].length,d=f+i[0].indexOf(i[1]),m=d+i[1].length,y=r instanceof Function?r(i):r;f>0&&a.push(o.cut(l,f)),a.push(o.cut(d,m).mark(t.create(y).addToSet(o.marks))),l=s}l<c.length&&a.push(o.cut(l))}else a.push(o.copy(n(o.content,o)))})),i.Fragment.fromArray(a)}(n.content),n.openStart,n.openEnd)}}})},e.nodeInputRule=function(e,t,r){return new n.InputRule(e,(function(e,n,o,i){var u=r instanceof Function?r(n):r,a=e.tr;return n[0]&&a.replaceWith(o-1,i,t.create(u)),a}))},e.pasteRule=function(e,t,r){return new o.Plugin({props:{transformPasted:function(n){return new i.Slice(function n(o){var u=[];return o.forEach((function(o){if(o.isText){var i,a=o.text,c=0;do{if(i=e.exec(a)){var l=i.index,p=l+i[0].length,f=r instanceof Function?r(i[0]):r;l>0&&u.push(o.cut(c,l)),u.push(o.cut(l,p).mark(t.create(f).addToSet(o.marks))),c=p}}while(i);c<a.length&&u.push(o.cut(c))}else u.push(o.copy(n(o.content)))})),i.Fragment.fromArray(u)}(n.content),n.openStart,n.openEnd)}}})},e.removeMark=function(e){return function(t,r){var n=t.tr,o=t.selection,i=o.from,a=o.to,c=o.$from;if(o.empty){var l=u.getMarkRange(c,e);i=l.from,a=l.to}return n.removeMark(i,a,e),r(n)}},e.replaceText=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1?arguments[1]:void 0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return function(n,o){var i=n.selection,u=i.$from,a=i.$to,c=u.index(),l=e?e.from:u.pos,p=e?e.to:a.pos;return!!u.parent.canReplaceWith(c,c,t)&&(o&&o(n.tr.replaceWith(l,p,t.create(r))),!0)}},e.setInlineBlockType=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r,n){var o=r.selection.$from,i=o.index();return!!o.parent.canReplaceWith(i,i,e)&&(n&&n(r.tr.replaceSelectionWith(e.create(t))),!0)}},e.splitToDefaultListItem=function(e){return function(t,r){var n=t.selection,o=n.$from,u=n.$to,a=n.node;if(a&&a.isBlock||o.depth<2||!o.sameParent(u))return!1;var c=o.node(-1);if(c.type!=e)return!1;if(0==o.parent.content.size){if(2==o.depth||o.node(-3).type!=e||o.index(-2)!=o.node(-2).childCount-1)return!1;if(r){for(var l=i.Fragment.empty,p=o.index(-1)>0,f=o.depth-(p?1:2);f>=o.depth-3;f--)l=i.Fragment.from(o.node(f).copy(l));l=l.append(i.Fragment.from(e.createAndFill()));var s=t.tr.replace(o.before(p?null:-1),o.after(-3),new i.Slice(l,p?3:2,2));s.setSelection(t.selection.constructor.near(s.doc.resolve(o.pos+(p?3:2)))),r(s.scrollIntoView())}return!0}var d=u.pos==o.end()?c.contentMatchAt(o.indexAfter(-1)).defaultType:null,m=t.tr.delete(o.pos,u.pos),y=d&&[{type:e},{type:d}];return y||(y=[{type:e},null]),!!function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,n=arguments.length>3?arguments[3]:void 0,o=e.resolve(t),i=o.depth-r,u=n&&n[n.length-1]||o.parent;if(i<0||o.parent.type.spec.isolating||!o.parent.canReplace(o.index(),o.parent.childCount)||!u.type.validContent(o.parent.content.cutByIndex(o.index(),o.parent.childCount)))return!1;for(var a=o.depth-1,c=r-2;a>i;a--,c--){var l=o.node(a),p=o.index(a);if(l.type.spec.isolating)return!1;var f=l.content.cutByIndex(p,l.childCount),s=n&&n[c]||l;if(s!=l&&(f=f.replaceChild(0,s.type.create(s.attrs))),!l.canReplace(p+1,l.childCount))return!1}var d=o.indexAfter(i),m=n&&n[0];return o.node(i).canReplaceWith(d,d,m?m.type:o.node(i+1).type)}(m.doc,o.pos,2,y)&&(r&&r(m.split(o.pos,2,y).scrollIntoView()),!0)}},e.toggleBlockType=function(e,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return function(o,i,a){return u.nodeIsActive(o,e,n)?t.setBlockType(r)(o,i,a):t.setBlockType(e,n)(o,i,a)}},e.toggleList=function(e,t){return function(n,o,i){var u=n.schema,c=n.selection,l=c.$from,f=c.$to,s=l.blockRange(f);if(!s)return!1;var d=a.findParentNode((function(e){return p(e,u)}))(c);if(s.depth>=1&&d&&s.depth-d.depth<=1){if(d.node.type===e)return r.liftListItem(t)(n,o,i);if(p(d.node,u)&&e.validContent(d.node.content)){var m=n.tr;return m.setNodeMarkup(d.pos,e),o&&o(m),!1}}return r.wrapInList(e)(n,o,i)}},e.toggleWrap=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(n,o,i){return u.nodeIsActive(n,e,r)?t.lift(n,o):t.wrapIn(e,r)(n,o,i)}},e.updateMark=function(e,t){return function(r,n){var o=r.tr,i=r.selection,a=r.doc,c=i.from,l=i.to,p=i.$from;if(i.empty){var f=u.getMarkRange(p,e);c=f.from,l=f.to}return a.rangeHasMark(c,l,e)&&o.removeMark(c,l,e),o.addMark(c,l,e.create(t)),n(o)}},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("prosemirror-commands"),require("prosemirror-schema-list"),require("prosemirror-inputrules"),require("prosemirror-state"),require("prosemirror-model"),require("tiptap-utils"),require("prosemirror-utils")):"function"==typeof define&&define.amd?define(["exports","prosemirror-commands","prosemirror-schema-list","prosemirror-inputrules","prosemirror-state","prosemirror-model","tiptap-utils","prosemirror-utils"],t):t((e=e||self).tiptapCommands={},e.prosemirrorCommands,e.prosemirrorSchemaList,e.prosemirrorInputrules,e.prosemirrorState,e.prosemirrorModel,e.tiptapUtils,e.prosemirrorUtils)}(this,(function(e,t,n,r,o,i,c,u){"use strict";function a(e,t){return e.type===t.nodes.bullet_list||e.type===t.nodes.ordered_list||e.type===t.nodes.todo_list}Object.defineProperty(e,"autoJoin",{enumerable:!0,get:function(){return t.autoJoin}}),Object.defineProperty(e,"baseKeymap",{enumerable:!0,get:function(){return t.baseKeymap}}),Object.defineProperty(e,"chainCommands",{enumerable:!0,get:function(){return t.chainCommands}}),Object.defineProperty(e,"createParagraphNear",{enumerable:!0,get:function(){return t.createParagraphNear}}),Object.defineProperty(e,"deleteSelection",{enumerable:!0,get:function(){return t.deleteSelection}}),Object.defineProperty(e,"exitCode",{enumerable:!0,get:function(){return t.exitCode}}),Object.defineProperty(e,"joinBackward",{enumerable:!0,get:function(){return t.joinBackward}}),Object.defineProperty(e,"joinDown",{enumerable:!0,get:function(){return t.joinDown}}),Object.defineProperty(e,"joinForward",{enumerable:!0,get:function(){return t.joinForward}}),Object.defineProperty(e,"joinUp",{enumerable:!0,get:function(){return t.joinUp}}),Object.defineProperty(e,"lift",{enumerable:!0,get:function(){return t.lift}}),Object.defineProperty(e,"liftEmptyBlock",{enumerable:!0,get:function(){return t.liftEmptyBlock}}),Object.defineProperty(e,"macBaseKeymap",{enumerable:!0,get:function(){return t.macBaseKeymap}}),Object.defineProperty(e,"newlineInCode",{enumerable:!0,get:function(){return t.newlineInCode}}),Object.defineProperty(e,"pcBaseKeymap",{enumerable:!0,get:function(){return t.pcBaseKeymap}}),Object.defineProperty(e,"selectAll",{enumerable:!0,get:function(){return t.selectAll}}),Object.defineProperty(e,"selectNodeBackward",{enumerable:!0,get:function(){return t.selectNodeBackward}}),Object.defineProperty(e,"selectNodeForward",{enumerable:!0,get:function(){return t.selectNodeForward}}),Object.defineProperty(e,"selectParentNode",{enumerable:!0,get:function(){return t.selectParentNode}}),Object.defineProperty(e,"setBlockType",{enumerable:!0,get:function(){return t.setBlockType}}),Object.defineProperty(e,"splitBlock",{enumerable:!0,get:function(){return t.splitBlock}}),Object.defineProperty(e,"splitBlockKeepMarks",{enumerable:!0,get:function(){return t.splitBlockKeepMarks}}),Object.defineProperty(e,"toggleMark",{enumerable:!0,get:function(){return t.toggleMark}}),Object.defineProperty(e,"wrapIn",{enumerable:!0,get:function(){return t.wrapIn}}),Object.defineProperty(e,"addListNodes",{enumerable:!0,get:function(){return n.addListNodes}}),Object.defineProperty(e,"liftListItem",{enumerable:!0,get:function(){return n.liftListItem}}),Object.defineProperty(e,"sinkListItem",{enumerable:!0,get:function(){return n.sinkListItem}}),Object.defineProperty(e,"splitListItem",{enumerable:!0,get:function(){return n.splitListItem}}),Object.defineProperty(e,"wrapInList",{enumerable:!0,get:function(){return n.wrapInList}}),Object.defineProperty(e,"textblockTypeInputRule",{enumerable:!0,get:function(){return r.textblockTypeInputRule}}),Object.defineProperty(e,"wrappingInputRule",{enumerable:!0,get:function(){return r.wrappingInputRule}}),e.insertText=function(e=""){return(t,n)=>{const{$from:r}=t.selection,{pos:o}=r.pos;return n(t.tr.insertText(e,o)),!0}},e.markInputRule=function(e,t,n){return new r.InputRule(e,(e,r,o,i)=>{const c=n instanceof Function?n(r):n,{tr:u}=e,a=r.length-1;let l=i,p=o;if(r[a]){const n=o+r[0].indexOf(r[a-1]),c=n+r[a-1].length-1,s=n+r[a-1].lastIndexOf(r[a]),d=s+r[a].length;if(function(e,t,n){let r=[];return n.doc.nodesBetween(e,t,(e,t)=>{r=[...r,...e.marks.map(n=>({start:t,end:t+e.nodeSize,mark:n}))]}),r}(o,i,e).filter(e=>{const{excluded:n}=e.mark.type;return n.find(e=>e.name===t.name)}).filter(e=>e.end>n).length)return!1;d<c&&u.delete(d,c),s>n&&u.delete(n,s),p=n,l=p+r[a].length}return u.addMark(p,l,t.create(c)),u.removeStoredMark(t),u})},e.markPasteRule=function(e,t,n){const r=(o,c)=>{const u=[];return o.forEach(o=>{if(o.isText){const{text:r,marks:i}=o;let a,l=0;const p=!!i.filter(e=>"link"===e.type.name)[0];for(;!p&&null!==(a=e.exec(r));)if(c&&c.type.allowsMarkType(t)&&a[1]){const e=a.index,r=e+a[0].length,i=e+a[0].indexOf(a[1]),c=i+a[1].length,p=n instanceof Function?n(a):n;e>0&&u.push(o.cut(l,e)),u.push(o.cut(i,c).mark(t.create(p).addToSet(o.marks))),l=r}l<r.length&&u.push(o.cut(l))}else u.push(o.copy(r(o.content,o)))}),i.Fragment.fromArray(u)};return new o.Plugin({props:{transformPasted:e=>new i.Slice(r(e.content),e.openStart,e.openEnd)}})},e.nodeInputRule=function(e,t,n){return new r.InputRule(e,(e,r,o,i)=>{const c=n instanceof Function?n(r):n,{tr:u}=e;return r[0]&&u.replaceWith(o-1,i,t.create(c)),u})},e.pasteRule=function(e,t,n){const r=o=>{const c=[];return o.forEach(o=>{if(o.isText){const{text:r}=o;let i,u=0;do{if(i=e.exec(r),i){const e=i.index,r=e+i[0].length,a=n instanceof Function?n(i[0]):n;e>0&&c.push(o.cut(u,e)),c.push(o.cut(e,r).mark(t.create(a).addToSet(o.marks))),u=r}}while(i);u<r.length&&c.push(o.cut(u))}else c.push(o.copy(r(o.content)))}),i.Fragment.fromArray(c)};return new o.Plugin({props:{transformPasted:e=>new i.Slice(r(e.content),e.openStart,e.openEnd)}})},e.removeMark=function(e){return(t,n)=>{const{tr:r,selection:o}=t;let{from:i,to:u}=o;const{$from:a,empty:l}=o;if(l){const t=c.getMarkRange(a,e);i=t.from,u=t.to}return r.removeMark(i,u,e),n(r)}},e.replaceText=function(e=null,t,n={}){return(r,o)=>{const{$from:i,$to:c}=r.selection,u=i.index(),a=e?e.from:i.pos,l=e?e.to:c.pos;return!!i.parent.canReplaceWith(u,u,t)&&(o&&o(r.tr.replaceWith(a,l,t.create(n))),!0)}},e.setInlineBlockType=function(e,t={}){return(n,r)=>{const{$from:o}=n.selection,i=o.index();return!!o.parent.canReplaceWith(i,i,e)&&(r&&r(n.tr.replaceSelectionWith(e.create(t))),!0)}},e.splitToDefaultListItem=function(e){return function(t,n){const{$from:r,$to:o,node:c}=t.selection;if(c&&c.isBlock||r.depth<2||!r.sameParent(o))return!1;const u=r.node(-1);if(u.type!=e)return!1;if(0==r.parent.content.size){if(2==r.depth||r.node(-3).type!=e||r.index(-2)!=r.node(-2).childCount-1)return!1;if(n){let o=i.Fragment.empty;const c=r.index(-1)>0;for(let e=r.depth-(c?1:2);e>=r.depth-3;e--)o=i.Fragment.from(r.node(e).copy(o));o=o.append(i.Fragment.from(e.createAndFill()));const u=t.tr.replace(r.before(c?null:-1),r.after(-3),new i.Slice(o,c?3:2,2));u.setSelection(t.selection.constructor.near(u.doc.resolve(r.pos+(c?3:2)))),n(u.scrollIntoView())}return!0}const a=o.pos==r.end()?u.contentMatchAt(r.indexAfter(-1)).defaultType:null,l=t.tr.delete(r.pos,o.pos);let p=a&&[{type:e},{type:a}];return p||(p=[{type:e},null]),!!function(e,t,n=1,r){const o=e.resolve(t),i=o.depth-n,c=r&&r[r.length-1]||o.parent;if(i<0||o.parent.type.spec.isolating||!o.parent.canReplace(o.index(),o.parent.childCount)||!c.type.validContent(o.parent.content.cutByIndex(o.index(),o.parent.childCount)))return!1;for(let e=o.depth-1,t=n-2;e>i;e--,t--){const n=o.node(e),i=o.index(e);if(n.type.spec.isolating)return!1;let c=n.content.cutByIndex(i,n.childCount);const u=r&&r[t]||n;if(u!=n&&(c=c.replaceChild(0,u.type.create(u.attrs))),!n.canReplace(i+1,n.childCount))return!1}const u=o.indexAfter(i),a=r&&r[0];return o.node(i).canReplaceWith(u,u,a?a.type:o.node(i+1).type)}(l.doc,r.pos,2,p)&&(n&&n(l.split(r.pos,2,p).scrollIntoView()),!0)}},e.toggleBlockType=function(e,n,r={}){return(o,i,u)=>c.nodeIsActive(o,e,r)?t.setBlockType(n)(o,i,u):t.setBlockType(e,r)(o,i,u)},e.toggleList=function(e,t){return(r,o,i)=>{const{schema:c,selection:l}=r,{$from:p,$to:s}=l,d=p.blockRange(s);if(!d)return!1;const f=u.findParentNode(e=>a(e,c))(l);if(d.depth>=1&&f&&d.depth-f.depth<=1){if(f.node.type===e)return n.liftListItem(t)(r,o,i);if(a(f.node,c)&&e.validContent(f.node.content)){const{tr:t}=r;return t.setNodeMarkup(f.pos,e),o&&o(t),!1}}return n.wrapInList(e)(r,o,i)}},e.toggleWrap=function(e,n={}){return(r,o,i)=>c.nodeIsActive(r,e,n)?t.lift(r,o):t.wrapIn(e,n)(r,o,i)},e.updateMark=function(e,t){return(n,r)=>{const{tr:o,selection:i,doc:u}=n;let{from:a,to:l}=i;const{$from:p,empty:s}=i;if(s){const t=c.getMarkRange(p,e);a=t.from,l=t.to}return u.rangeHasMark(a,l,e)&&o.removeMark(a,l,e),o.addMark(a,l,e.create(t)),r(o)}},Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "tiptap-commands", | ||
"version": "1.14.4", | ||
"version": "1.14.5", | ||
"description": "Commands for tiptap", | ||
@@ -32,3 +32,3 @@ "homepage": "https://tiptap.dev", | ||
}, | ||
"gitHead": "a031370f4cdbf990311373bbe14ba80cd7deae5f" | ||
"gitHead": "01ec8b2bf4c3ac0fb6a31992656f5c8d4ed0f25e" | ||
} |
import { Fragment, Slice } from 'prosemirror-model' | ||
// this is a copy of canSplit | ||
// see https://github.com/ProseMirror/prosemirror-transform/blob/master/src/structure.js | ||
// see https://github.com/ProseMirror/prosemirror-transform/blob/main/src/structure.js | ||
@@ -35,3 +35,3 @@ // Since this piece of code was "borrowed" from prosemirror, ESLint rules are ignored. | ||
// this is a copy of splitListItem | ||
// see https://github.com/ProseMirror/prosemirror-schema-list/blob/master/src/schema-list.js | ||
// see https://github.com/ProseMirror/prosemirror-schema-list/blob/main/src/schema-list.js | ||
@@ -38,0 +38,0 @@ export default function splitToDefaultListItem(itemType) { |
77070
1975