@tiptap/core 2.0.0-beta.204 → 2.0.0-beta.206

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ import { EditorView } from 'prosemirror-view';
3
3
  import { keymap } from 'prosemirror-keymap';
4
4
  import { Schema, Fragment, DOMParser, DOMSerializer, Node as Node$1, Slice } from 'prosemirror-model';
5
5
  import { liftTarget, ReplaceStep, ReplaceAroundStep, Transform, canSplit, canJoin, findWrapping } from 'prosemirror-transform';
6
- import { createParagraphNear as createParagraphNear$1, deleteSelection as deleteSelection$1, exitCode as exitCode$1, joinBackward as joinBackward$1, joinForward as joinForward$1, lift as lift$1, liftEmptyBlock as liftEmptyBlock$1, newlineInCode as newlineInCode$1, selectNodeBackward as selectNodeBackward$1, selectNodeForward as selectNodeForward$1, selectParentNode as selectParentNode$1, selectTextblockEnd as selectTextblockEnd$1, selectTextblockStart as selectTextblockStart$1, setBlockType, wrapIn as wrapIn$1 } from 'prosemirror-commands';
6
+ import { createParagraphNear as createParagraphNear$1, deleteSelection as deleteSelection$1, exitCode as exitCode$1, joinUp as joinUp$1, joinDown as joinDown$1, joinBackward as joinBackward$1, joinForward as joinForward$1, lift as lift$1, liftEmptyBlock as liftEmptyBlock$1, newlineInCode as newlineInCode$1, selectNodeBackward as selectNodeBackward$1, selectNodeForward as selectNodeForward$1, selectParentNode as selectParentNode$1, selectTextblockEnd as selectTextblockEnd$1, selectTextblockStart as selectTextblockStart$1, setBlockType, wrapIn as wrapIn$1 } from 'prosemirror-commands';
7
7
  import { liftListItem as liftListItem$1, sinkListItem as sinkListItem$1, wrapInList as wrapInList$1 } from 'prosemirror-schema-list';
8
8
 
9
9
  function createChainableState(config) {
@@ -1318,6 +1318,28 @@ const createParagraphNear = () => ({ state, dispatch }) => {
1318
1318
  return createParagraphNear$1(state, dispatch);
1319
1319
  };
1320
1320
 
1321
+ const deleteCurrentNode = () => ({ tr, dispatch }) => {
1322
+ const { selection } = tr;
1323
+ const currentNode = selection.$anchor.node();
1324
+ // if there is content inside the current node, break out of this command
1325
+ if (currentNode.content.size > 0) {
1326
+ return false;
1327
+ }
1328
+ const $pos = tr.selection.$anchor;
1329
+ for (let depth = $pos.depth; depth > 0; depth -= 1) {
1330
+ const node = $pos.node(depth);
1331
+ if (node.type === currentNode.type) {
1332
+ if (dispatch) {
1333
+ const from = $pos.before(depth);
1334
+ const to = $pos.after(depth);
1335
+ tr.delete(from, to).scrollIntoView();
1336
+ }
1337
+ return true;
1338
+ }
1339
+ }
1340
+ return false;
1341
+ };
1342
+
1321
1343
  const deleteNode = typeOrName => ({ tr, state, dispatch }) => {
1322
1344
  const type = getNodeType(typeOrName, state.schema);
1323
1345
  const $pos = tr.selection.$anchor;
@@ -1674,10 +1696,15 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
1674
1696
  return true;
1675
1697
  };
1676
1698
 
1699
+ const joinUp = () => ({ state, dispatch }) => {
1700
+ return joinUp$1(state, dispatch);
1701
+ };
1702
+ const joinDown = () => ({ state, dispatch }) => {
1703
+ return joinDown$1(state, dispatch);
1704
+ };
1677
1705
  const joinBackward = () => ({ state, dispatch }) => {
1678
1706
  return joinBackward$1(state, dispatch);
1679
- };
1680
-
1707
+ };
1681
1708
  const joinForward = () => ({ state, dispatch }) => {
1682
1709
  return joinForward$1(state, dispatch);
1683
1710
  };
@@ -2945,6 +2972,7 @@ var commands = /*#__PURE__*/Object.freeze({
2945
2972
  clearNodes: clearNodes,
2946
2973
  command: command,
2947
2974
  createParagraphNear: createParagraphNear,
2975
+ deleteCurrentNode: deleteCurrentNode,
2948
2976
  deleteNode: deleteNode,
2949
2977
  deleteRange: deleteRange,
2950
2978
  deleteSelection: deleteSelection,
@@ -2956,6 +2984,8 @@ var commands = /*#__PURE__*/Object.freeze({
2956
2984
  forEach: forEach,
2957
2985
  insertContent: insertContent,
2958
2986
  insertContentAt: insertContentAt,
2987
+ joinUp: joinUp,
2988
+ joinDown: joinDown,
2959
2989
  joinBackward: joinBackward,
2960
2990
  joinForward: joinForward,
2961
2991
  keyboardShortcut: keyboardShortcut,
@@ -3072,6 +3102,7 @@ const Keymap = Extension.create({
3072
3102
  ]);
3073
3103
  const handleDelete = () => this.editor.commands.first(({ commands }) => [
3074
3104
  () => commands.deleteSelection(),
3105
+ () => commands.deleteCurrentNode(),
3075
3106
  () => commands.joinForward(),
3076
3107
  () => commands.selectNodeForward(),
3077
3108
  ]);