New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tiptap-commands

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiptap-commands - npm Package Compare versions

Comparing version

to
1.10.5

72

dist/commands.common.js
/*!
* tiptap-commands v1.10.3
* tiptap-commands v1.10.4
* (c) 2019 Scrumpy UG (limited liability)

@@ -18,2 +18,3 @@ * @license MIT

var tiptapUtils = require('tiptap-utils');
var prosemirrorUtils = require('prosemirror-utils');

@@ -378,41 +379,42 @@ function insertText () {

function toggleList(type, itemType) {
function isList(node, schema) {
return node.type === schema.nodes.bullet_list || node.type === schema.nodes.ordered_list || node.type === schema.nodes.todo_list;
}
function toggleList(listType, itemType) {
return function (state, dispatch, view) {
var isActive = tiptapUtils.nodeIsActive(state, type);
var schema = state.schema,
selection = state.selection;
var $from = selection.$from,
$to = selection.$to;
var range = $from.blockRange($to);
if (isActive) {
return prosemirrorSchemaList.liftListItem(itemType)(state, dispatch, view);
if (!range) {
return false;
}
return prosemirrorSchemaList.wrapInList(type)(state, dispatch, view);
var parentList = prosemirrorUtils.findParentNode(function (node) {
return isList(node, schema);
})(selection);
if (range.depth >= 1 && parentList && range.depth - parentList.depth <= 1) {
if (parentList.node.type === listType) {
return prosemirrorSchemaList.liftListItem(itemType)(state, dispatch, view);
}
if (isList(parentList.node, schema) && listType.validContent(parentList.node.content)) {
var tr = state.tr;
tr.setNodeMarkup(parentList.pos, listType);
if (dispatch) {
dispatch(tr);
}
return false;
}
}
return prosemirrorSchemaList.wrapInList(listType)(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)
// }
// }
// }
}

@@ -419,0 +421,0 @@ function toggleWrap (type) {

/*!
* tiptap-commands v1.10.3
* tiptap-commands v1.10.4
* (c) 2019 Scrumpy UG (limited liability)

@@ -17,2 +17,3 @@ * @license MIT

import { nodeIsActive } from 'tiptap-utils';
import { findParentNode } from 'prosemirror-utils';

@@ -377,41 +378,42 @@ function insertText () {

function toggleList(type, itemType) {
function isList(node, schema) {
return node.type === schema.nodes.bullet_list || node.type === schema.nodes.ordered_list || node.type === schema.nodes.todo_list;
}
function toggleList(listType, itemType) {
return function (state, dispatch, view) {
var isActive = nodeIsActive(state, type);
var schema = state.schema,
selection = state.selection;
var $from = selection.$from,
$to = selection.$to;
var range = $from.blockRange($to);
if (isActive) {
return liftListItem(itemType)(state, dispatch, view);
if (!range) {
return false;
}
return wrapInList(type)(state, dispatch, view);
var parentList = findParentNode(function (node) {
return isList(node, schema);
})(selection);
if (range.depth >= 1 && parentList && range.depth - parentList.depth <= 1) {
if (parentList.node.type === listType) {
return liftListItem(itemType)(state, dispatch, view);
}
if (isList(parentList.node, schema) && listType.validContent(parentList.node.content)) {
var tr = state.tr;
tr.setNodeMarkup(parentList.pos, listType);
if (dispatch) {
dispatch(tr);
}
return false;
}
}
return wrapInList(listType)(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)
// }
// }
// }
}

@@ -418,0 +420,0 @@ function toggleWrap (type) {

/*!
* tiptap-commands v1.10.3
* tiptap-commands v1.10.4
* (c) 2019 Scrumpy UG (limited liability)

@@ -9,6 +9,6 @@ * @license MIT

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('prosemirror-commands'), require('prosemirror-schema-list'), require('prosemirror-inputrules'), require('prosemirror-state'), require('prosemirror-model'), require('tiptap-utils')) :
typeof define === 'function' && define.amd ? define(['exports', 'prosemirror-commands', 'prosemirror-schema-list', 'prosemirror-inputrules', 'prosemirror-state', 'prosemirror-model', 'tiptap-utils'], factory) :
(global = global || self, factory(global.tiptapCommands = {}, global.prosemirrorCommands, global.prosemirrorSchemaList, global.prosemirrorInputrules, global.prosemirrorState, global.prosemirrorModel, global.tiptapUtils));
}(this, function (exports, prosemirrorCommands, prosemirrorSchemaList, prosemirrorInputrules, prosemirrorState, prosemirrorModel, tiptapUtils) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('prosemirror-commands'), require('prosemirror-schema-list'), require('prosemirror-inputrules'), require('prosemirror-state'), require('prosemirror-model'), require('tiptap-utils'), require('prosemirror-utils')) :
typeof define === 'function' && define.amd ? define(['exports', 'prosemirror-commands', 'prosemirror-schema-list', 'prosemirror-inputrules', 'prosemirror-state', 'prosemirror-model', 'tiptap-utils', 'prosemirror-utils'], factory) :
(global = global || self, factory(global.tiptapCommands = {}, global.prosemirrorCommands, global.prosemirrorSchemaList, global.prosemirrorInputrules, global.prosemirrorState, global.prosemirrorModel, global.tiptapUtils, global.prosemirrorUtils));
}(this, function (exports, prosemirrorCommands, prosemirrorSchemaList, prosemirrorInputrules, prosemirrorState, prosemirrorModel, tiptapUtils, prosemirrorUtils) { 'use strict';

@@ -373,41 +373,42 @@ function insertText () {

function toggleList(type, itemType) {
function isList(node, schema) {
return node.type === schema.nodes.bullet_list || node.type === schema.nodes.ordered_list || node.type === schema.nodes.todo_list;
}
function toggleList(listType, itemType) {
return function (state, dispatch, view) {
var isActive = tiptapUtils.nodeIsActive(state, type);
var schema = state.schema,
selection = state.selection;
var $from = selection.$from,
$to = selection.$to;
var range = $from.blockRange($to);
if (isActive) {
return prosemirrorSchemaList.liftListItem(itemType)(state, dispatch, view);
if (!range) {
return false;
}
return prosemirrorSchemaList.wrapInList(type)(state, dispatch, view);
var parentList = prosemirrorUtils.findParentNode(function (node) {
return isList(node, schema);
})(selection);
if (range.depth >= 1 && parentList && range.depth - parentList.depth <= 1) {
if (parentList.node.type === listType) {
return prosemirrorSchemaList.liftListItem(itemType)(state, dispatch, view);
}
if (isList(parentList.node, schema) && listType.validContent(parentList.node.content)) {
var tr = state.tr;
tr.setNodeMarkup(parentList.pos, listType);
if (dispatch) {
dispatch(tr);
}
return false;
}
}
return prosemirrorSchemaList.wrapInList(listType)(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)
// }
// }
// }
}

@@ -414,0 +415,0 @@ function toggleWrap (type) {

/*!
* tiptap-commands v1.10.3
* tiptap-commands v1.10.4
* (c) 2019 Scrumpy UG (limited liability)

@@ -9,2 +9,2 @@ * @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")):"function"==typeof define&&define.amd?define(["exports","prosemirror-commands","prosemirror-schema-list","prosemirror-inputrules","prosemirror-state","prosemirror-model","tiptap-utils"],t):t((e=e||self).tiptapCommands={},e.prosemirrorCommands,e.prosemirrorSchemaList,e.prosemirrorInputrules,e.prosemirrorState,e.prosemirrorModel,e.tiptapUtils)}(this,function(e,t,n,r,o,i,u){"use strict";function c(e){return function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}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(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return function(t,n){var r=t.selection.$from.pos.pos;return n(t.tr.insertText(e,r)),!0}},e.markInputRule=function(e,t,n){return new r.InputRule(e,function(e,r,o,i){var u=n instanceof Function?n(r):n,a=e.tr,l=r.length-1,p=i,f=o;if(r[l]){var s=o+r[0].indexOf(r[l-1]),d=s+r[l-1].length,m=s+r[l-1].lastIndexOf(r[l]),y=m+r[l].length;if(function(e,t,n){var r=[];return n.doc.nodesBetween(e,t,function(e,t){r=[].concat(c(r),c(e.marks.map(function(n){return{start:t,end:t+e.nodeSize,mark:n}})))}),r}(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)+r[l].length}return a.addMark(f,p,t.create(u)),a.removeStoredMark(t),a})},e.markPasteRule=function(e,t,n){return new o.Plugin({props:{transformPasted:function(r){return new i.Slice(function r(o){var u=[];return o.forEach(function(o){if(o.isText){for(var i,c=o.text,a=0,l=!!o.marks.filter(function(e){return"link"===e.type.name})[0];!l&&null!==(i=e.exec(c));)if(i[1]){var p=i.index,f=p+i[0].length,s=p+i[0].indexOf(i[1]),d=s+i[1].length,m=n instanceof Function?n(i):n;p>0&&u.push(o.cut(a,p)),u.push(o.cut(s,d).mark(t.create(m).addToSet(o.marks))),a=f}a<c.length&&u.push(o.cut(a))}else u.push(o.copy(r(o.content)))}),i.Fragment.fromArray(u)}(r.content),r.openStart,r.openEnd)}}})},e.nodeInputRule=function(e,t,n){return new r.InputRule(e,function(e,r,o,i){var u=n instanceof Function?n(r):n,c=e.tr;return r[0]&&c.replaceWith(o-1,i,t.create(u)),c})},e.pasteRule=function(e,t,n){return new o.Plugin({props:{transformPasted:function(r){return new i.Slice(function r(o){var u=[];return o.forEach(function(o){if(o.isText){var i,c=o.text,a=0;do{if(i=e.exec(c)){var l=i.index,p=l+i[0].length,f=n instanceof Function?n(i[0]):n;l>0&&u.push(o.cut(a,l)),u.push(o.cut(l,p).mark(t.create(f).addToSet(o.marks))),a=p}}while(i);a<c.length&&u.push(o.cut(a))}else u.push(o.copy(r(o.content)))}),i.Fragment.fromArray(u)}(r.content),r.openStart,r.openEnd)}}})},e.removeMark=function(e){return function(t,n){var r=t.selection,o=r.from,i=r.to;return n(t.tr.removeMark(o,i,e))}},e.replaceText=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return function(r,o){var i=r.selection,u=i.$from,c=i.$to,a=u.index(),l=e?e.from:u.pos,p=e?e.to:c.pos;return!!u.parent.canReplaceWith(a,a,t)&&(o&&o(r.tr.replaceWith(l,p,t.create(n))),!0)}},e.setInlineBlockType=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(n,r){var o=n.selection.$from,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){var r=t.selection,o=r.$from,u=r.$to,c=r.node;if(c&&c.isBlock||o.depth<2||!o.sameParent(u))return!1;var a=o.node(-1);if(a.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(n){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)))),n(s.scrollIntoView())}return!0}var d=u.pos==o.end()?a.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 n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,r=arguments.length>3?arguments[3]:void 0,o=e.resolve(t),i=o.depth-n,u=r&&r[r.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 c=o.depth-1,a=n-2;c>i;c--,a--){var l=o.node(c),p=o.index(c);if(l.type.spec.isolating)return!1;var f=l.content.cutByIndex(p,l.childCount),s=r&&r[a]||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=r&&r[0];return o.node(i).canReplaceWith(d,d,m?m.type:o.node(i+1).type)}(m.doc,o.pos,2,y)&&(n&&n(m.split(o.pos,2,y).scrollIntoView()),!0)}},e.toggleBlockType=function(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return function(o,i,c){return u.nodeIsActive(o,e,r)?t.setBlockType(n)(o,i,c):t.setBlockType(e,r)(o,i,c)}},e.toggleList=function(e,t){return function(r,o,i){return u.nodeIsActive(r,e)?n.liftListItem(t)(r,o,i):n.wrapInList(e)(r,o,i)}},e.toggleWrap=function(e){return function(n,r,o){return u.nodeIsActive(n,e)?t.lift(n,r):t.wrapIn(e)(n,r,o)}},e.updateMark=function(e,t){return function(n,r){var o=n.selection,i=o.from,u=o.to;return r(n.tr.addMark(i,u,e.create(t)))}},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,r,n,o,i,u,c){"use strict";function a(e){return function(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t<e.length;t++)r[t]=e[t];return r}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function l(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,c=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,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(a(n),a(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&&c.delete(y,d),m>s&&c.delete(s,m),p=(f=s)+n[l].length}return c.addMark(f,p,t.create(u)),c.removeStoredMark(t),c})},e.markPasteRule=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){for(var i,c=o.text,a=0,l=!!o.marks.filter(function(e){return"link"===e.type.name})[0];!l&&null!==(i=e.exec(c));)if(i[1]){var p=i.index,f=p+i[0].length,s=p+i[0].indexOf(i[1]),d=s+i[1].length,m=r instanceof Function?r(i):r;p>0&&u.push(o.cut(a,p)),u.push(o.cut(s,d).mark(t.create(m).addToSet(o.marks))),a=f}a<c.length&&u.push(o.cut(a))}else u.push(o.copy(n(o.content)))}),i.Fragment.fromArray(u)}(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,c=e.tr;return n[0]&&c.replaceWith(o-1,i,t.create(u)),c})},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,c=o.text,a=0;do{if(i=e.exec(c)){var l=i.index,p=l+i[0].length,f=r instanceof Function?r(i[0]):r;l>0&&u.push(o.cut(a,l)),u.push(o.cut(l,p).mark(t.create(f).addToSet(o.marks))),a=p}}while(i);a<c.length&&u.push(o.cut(a))}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.selection,o=n.from,i=n.to;return r(t.tr.removeMark(o,i,e))}},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,c=i.$to,a=u.index(),l=e?e.from:u.pos,p=e?e.to:c.pos;return!!u.parent.canReplaceWith(a,a,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,c=n.node;if(c&&c.isBlock||o.depth<2||!o.sameParent(u))return!1;var a=o.node(-1);if(a.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()?a.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 c=o.depth-1,a=r-2;c>i;c--,a--){var l=o.node(c),p=o.index(c);if(l.type.spec.isolating)return!1;var f=l.content.cutByIndex(p,l.childCount),s=n&&n[a]||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,c){return u.nodeIsActive(o,e,n)?t.setBlockType(r)(o,i,c):t.setBlockType(e,n)(o,i,c)}},e.toggleList=function(e,t){return function(n,o,i){var u=n.schema,a=n.selection,p=a.$from,f=a.$to,s=p.blockRange(f);if(!s)return!1;var d=c.findParentNode(function(e){return l(e,u)})(a);if(s.depth>=1&&d&&s.depth-d.depth<=1){if(d.node.type===e)return r.liftListItem(t)(n,o,i);if(l(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){return function(r,n,o){return u.nodeIsActive(r,e)?t.lift(r,n):t.wrapIn(e)(r,n,o)}},e.updateMark=function(e,t){return function(r,n){var o=r.selection,i=o.from,u=o.to;return n(r.tr.addMark(i,u,e.create(t)))}},Object.defineProperty(e,"__esModule",{value:!0})});
{
"name": "tiptap-commands",
"version": "1.10.4",
"version": "1.10.5",
"description": "Commands for tiptap",

@@ -28,5 +28,7 @@ "homepage": "https://tiptap.scrumpy.io",

"prosemirror-state": "^1.2.3",
"tiptap-utils": "^1.5.2"
"prosemirror-tables": "^0.8.0",
"prosemirror-utils": "^0.8.2",
"tiptap-utils": "^1.5.3"
},
"gitHead": "78e6b703ff5941fa53f77a20ec61c8c95256b447"
"gitHead": "17c06eac802e4fed6842d55c9ca5ace598f5acd5"
}

@@ -1,49 +0,41 @@

import { nodeIsActive } from 'tiptap-utils'
import { wrapInList, liftListItem } from 'prosemirror-schema-list'
import { findParentNode } from 'prosemirror-utils'
export default function toggleList(type, itemType) {
function isList(node, schema) {
return (node.type === schema.nodes.bullet_list
|| node.type === schema.nodes.ordered_list
|| node.type === schema.nodes.todo_list)
}
export default function toggleList(listType, itemType) {
return (state, dispatch, view) => {
const isActive = nodeIsActive(state, type)
const { schema, selection } = state
const { $from, $to } = selection
const range = $from.blockRange($to)
if (isActive) {
return liftListItem(itemType)(state, dispatch, view)
}
if (!range) {
return false
}
return wrapInList(type)(state, dispatch, view)
}
}
const parentList = findParentNode(node => isList(node, schema))(selection)
// https://discuss.prosemirror.net/t/list-type-toggle/948
if (range.depth >= 1 && parentList && range.depth - parentList.depth <= 1) {
if (parentList.node.type === listType) {
return liftListItem(itemType)(state, dispatch, view)
}
// import { wrapInList, liftListItem } from 'prosemirror-schema-list'
if (isList(parentList.node, schema) && listType.validContent(parentList.node.content)) {
const { tr } = state
tr.setNodeMarkup(parentList.pos, listType)
// function isList(node, schema) {
// return (node.type === schema.nodes.bullet_list || node.type === schema.nodes.ordered_list)
// }
if (dispatch) {
dispatch(tr)
}
// export default function toggleList(listType, schema) {
// const lift = liftListItem(schema.nodes.list_item)
// const wrap = wrapInList(listType)
return false
}
}
// 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)
// }
// }
// }
return wrapInList(listType)(state, dispatch, view)
}
}