@tiptap/extension-list-keymap 3.0.0-next.1 → 3.0.0-next.3

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.
package/dist/index.cjs CHANGED
@@ -128,6 +128,9 @@ var handleBackspace = (editor, name, parentListTypes) => {
128
128
  if (editor.commands.undoInputRule()) {
129
129
  return true;
130
130
  }
131
+ if (editor.state.selection.from !== editor.state.selection.to) {
132
+ return false;
133
+ }
131
134
  if (!(0, import_core4.isNodeActive)(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {
132
135
  const { $anchor } = editor.state.selection;
133
136
  const $listPos = editor.state.doc.resolve($anchor.before() - 1);
@@ -200,6 +203,11 @@ var handleDelete = (editor, name) => {
200
203
  if (!(0, import_core5.isAtEndOfNode)(editor.state, name)) {
201
204
  return false;
202
205
  }
206
+ const { selection } = editor.state;
207
+ const { $from, $to } = selection;
208
+ if (!selection.empty && $from.sameParent($to)) {
209
+ return false;
210
+ }
203
211
  if (nextListIsDeeper(name, editor.state)) {
204
212
  return editor.chain().focus(editor.state.selection.from + 4).lift(name).joinBackward().run();
205
213
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/list-keymap.ts","../src/listHelpers/index.ts","../src/listHelpers/findListItemPos.ts","../src/listHelpers/getNextListDepth.ts","../src/listHelpers/handleBackspace.ts","../src/listHelpers/hasListBefore.ts","../src/listHelpers/hasListItemBefore.ts","../src/listHelpers/listItemHasSubList.ts","../src/listHelpers/handleDelete.ts","../src/listHelpers/nextListIsDeeper.ts","../src/listHelpers/nextListIsHigher.ts","../src/listHelpers/hasListItemAfter.ts"],"sourcesContent":["import { ListKeymap } from './list-keymap.js'\n\nexport * from './list-keymap.js'\nexport * as listHelpers from './listHelpers/index.js'\n\nexport default ListKeymap\n","import { Extension } from '@tiptap/core'\n\nimport { handleBackspace, handleDelete } from './listHelpers/index.js'\n\nexport type ListKeymapOptions = {\n /**\n * An array of list types. This is used for item and wrapper list matching.\n * @default []\n * @example [{ itemName: 'listItem', wrapperNames: ['bulletList', 'orderedList'] }]\n */\n listTypes: Array<{\n itemName: string,\n wrapperNames: string[],\n }>\n}\n\n/**\n * This extension registers custom keymaps to change the behaviour of the backspace and delete keys.\n * By default Prosemirror keyhandling will always lift or sink items so paragraphs are joined into\n * the adjacent or previous list item. This extension will prevent this behaviour and instead will\n * try to join paragraphs from two list items into a single list item.\n * @see https://www.tiptap.dev/api/extensions/list-keymap\n */\nexport const ListKeymap = Extension.create<ListKeymapOptions>({\n name: 'listKeymap',\n\n addOptions() {\n return {\n listTypes: [\n {\n itemName: 'listItem',\n wrapperNames: ['bulletList', 'orderedList'],\n },\n {\n itemName: 'taskItem',\n wrapperNames: ['taskList'],\n },\n ],\n }\n },\n\n addKeyboardShortcuts() {\n return {\n Delete: ({ editor }) => {\n let handled = false\n\n this.options.listTypes.forEach(({ itemName }) => {\n if (editor.state.schema.nodes[itemName] === undefined) {\n return\n }\n\n if (handleDelete(editor, itemName)) {\n handled = true\n }\n })\n\n return handled\n },\n 'Mod-Delete': ({ editor }) => {\n let handled = false\n\n this.options.listTypes.forEach(({ itemName }) => {\n if (editor.state.schema.nodes[itemName] === undefined) {\n return\n }\n\n if (handleDelete(editor, itemName)) {\n handled = true\n }\n })\n\n return handled\n },\n Backspace: ({ editor }) => {\n let handled = false\n\n this.options.listTypes.forEach(({ itemName, wrapperNames }) => {\n if (editor.state.schema.nodes[itemName] === undefined) {\n return\n }\n\n if (handleBackspace(editor, itemName, wrapperNames)) {\n handled = true\n }\n })\n\n return handled\n },\n 'Mod-Backspace': ({ editor }) => {\n let handled = false\n\n this.options.listTypes.forEach(({ itemName, wrapperNames }) => {\n if (editor.state.schema.nodes[itemName] === undefined) {\n return\n }\n\n if (handleBackspace(editor, itemName, wrapperNames)) {\n handled = true\n }\n })\n\n return handled\n },\n }\n },\n})\n","export * from './findListItemPos.js'\nexport * from './getNextListDepth.js'\nexport * from './handleBackspace.js'\nexport * from './handleDelete.js'\nexport * from './hasListBefore.js'\nexport * from './hasListItemAfter.js'\nexport * from './hasListItemBefore.js'\nexport * from './listItemHasSubList.js'\nexport * from './nextListIsDeeper.js'\nexport * from './nextListIsHigher.js'\n","import { getNodeType } from '@tiptap/core'\nimport { NodeType } from '@tiptap/pm/model'\nimport { EditorState } from '@tiptap/pm/state'\n\nexport const findListItemPos = (typeOrName: string | NodeType, state: EditorState) => {\n const { $from } = state.selection\n const nodeType = getNodeType(typeOrName, state.schema)\n\n let currentNode = null\n let currentDepth = $from.depth\n let currentPos = $from.pos\n let targetDepth: number | null = null\n\n while (currentDepth > 0 && targetDepth === null) {\n currentNode = $from.node(currentDepth)\n\n if (currentNode.type === nodeType) {\n targetDepth = currentDepth\n } else {\n currentDepth -= 1\n currentPos -= 1\n }\n }\n\n if (targetDepth === null) {\n return null\n }\n\n return { $pos: state.doc.resolve(currentPos), depth: targetDepth }\n}\n","import { getNodeAtPosition } from '@tiptap/core'\nimport { EditorState } from '@tiptap/pm/state'\n\nimport { findListItemPos } from './findListItemPos.js'\n\nexport const getNextListDepth = (typeOrName: string, state: EditorState) => {\n const listItemPos = findListItemPos(typeOrName, state)\n\n if (!listItemPos) {\n return false\n }\n\n const [, depth] = getNodeAtPosition(state, typeOrName, listItemPos.$pos.pos + 4)\n\n return depth\n}\n","import { Editor, isAtStartOfNode, isNodeActive } from '@tiptap/core'\nimport { Node } from '@tiptap/pm/model'\n\nimport { findListItemPos } from './findListItemPos.js'\nimport { hasListBefore } from './hasListBefore.js'\nimport { hasListItemBefore } from './hasListItemBefore.js'\nimport { listItemHasSubList } from './listItemHasSubList.js'\n\nexport const handleBackspace = (editor: Editor, name: string, parentListTypes: string[]) => {\n // this is required to still handle the undo handling\n if (editor.commands.undoInputRule()) {\n return true\n }\n\n // if the current item is NOT inside a list item &\n // the previous item is a list (orderedList or bulletList)\n // move the cursor into the list and delete the current item\n if (!isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {\n const { $anchor } = editor.state.selection\n\n const $listPos = editor.state.doc.resolve($anchor.before() - 1)\n\n const listDescendants: Array<{ node: Node, pos: number }> = []\n\n $listPos.node().descendants((node, pos) => {\n if (node.type.name === name) {\n listDescendants.push({ node, pos })\n }\n })\n\n const lastItem = listDescendants.at(-1)\n\n if (!lastItem) {\n return false\n }\n\n const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1)\n\n return editor.chain().cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end()).joinForward().run()\n }\n\n // if the cursor is not inside the current node type\n // do nothing and proceed\n if (!isNodeActive(editor.state, name)) {\n return false\n }\n\n // if the cursor is not at the start of a node\n // do nothing and proceed\n if (!isAtStartOfNode(editor.state)) {\n return false\n }\n\n const listItemPos = findListItemPos(name, editor.state)\n\n if (!listItemPos) {\n return false\n }\n\n const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2)\n const prevNode = $prev.node(listItemPos.depth)\n\n const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode)\n\n // if the previous item is a list item and doesn't have a sublist, join the list items\n if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) {\n return editor.commands.joinItemBackward()\n }\n\n // otherwise in the end, a backspace should\n // always just lift the list item if\n // joining / merging is not possible\n return editor.chain().liftListItem(name).run()\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nexport const hasListBefore = (editorState: EditorState, name: string, parentListTypes: string[]) => {\n const { $anchor } = editorState.selection\n\n const previousNodePos = Math.max(0, $anchor.pos - 2)\n\n const previousNode = editorState.doc.resolve(previousNodePos).node()\n\n if (!previousNode || !parentListTypes.includes(previousNode.type.name)) {\n return false\n }\n\n return true\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nexport const hasListItemBefore = (typeOrName: string, state: EditorState): boolean => {\n const { $anchor } = state.selection\n\n const $targetPos = state.doc.resolve($anchor.pos - 2)\n\n if ($targetPos.index() === 0) {\n return false\n }\n\n if ($targetPos.nodeBefore?.type.name !== typeOrName) {\n return false\n }\n\n return true\n}\n","import { getNodeType } from '@tiptap/core'\nimport { Node } from '@tiptap/pm/model'\nimport { EditorState } from '@tiptap/pm/state'\n\nexport const listItemHasSubList = (typeOrName: string, state: EditorState, node?: Node) => {\n if (!node) {\n return false\n }\n\n const nodeType = getNodeType(typeOrName, state.schema)\n\n let hasSubList = false\n\n node.descendants(child => {\n if (child.type === nodeType) {\n hasSubList = true\n }\n })\n\n return hasSubList\n}\n","import { Editor, isAtEndOfNode, isNodeActive } from '@tiptap/core'\n\nimport { nextListIsDeeper } from './nextListIsDeeper.js'\nimport { nextListIsHigher } from './nextListIsHigher.js'\n\nexport const handleDelete = (editor: Editor, name: string) => {\n // if the cursor is not inside the current node type\n // do nothing and proceed\n if (!isNodeActive(editor.state, name)) {\n return false\n }\n\n // if the cursor is not at the end of a node\n // do nothing and proceed\n if (!isAtEndOfNode(editor.state, name)) {\n return false\n }\n\n // check if the next node is a list with a deeper depth\n if (nextListIsDeeper(name, editor.state)) {\n return editor\n .chain()\n .focus(editor.state.selection.from + 4)\n .lift(name)\n .joinBackward()\n .run()\n }\n\n if (nextListIsHigher(name, editor.state)) {\n return editor.chain()\n .joinForward()\n .joinBackward()\n .run()\n }\n\n return editor.commands.joinItemForward()\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nimport { findListItemPos } from './findListItemPos.js'\nimport { getNextListDepth } from './getNextListDepth.js'\n\nexport const nextListIsDeeper = (typeOrName: string, state: EditorState) => {\n const listDepth = getNextListDepth(typeOrName, state)\n const listItemPos = findListItemPos(typeOrName, state)\n\n if (!listItemPos || !listDepth) {\n return false\n }\n\n if (listDepth > listItemPos.depth) {\n return true\n }\n\n return false\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nimport { findListItemPos } from './findListItemPos.js'\nimport { getNextListDepth } from './getNextListDepth.js'\n\nexport const nextListIsHigher = (typeOrName: string, state: EditorState) => {\n const listDepth = getNextListDepth(typeOrName, state)\n const listItemPos = findListItemPos(typeOrName, state)\n\n if (!listItemPos || !listDepth) {\n return false\n }\n\n if (listDepth < listItemPos.depth) {\n return true\n }\n\n return false\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nexport const hasListItemAfter = (typeOrName: string, state: EditorState): boolean => {\n const { $anchor } = state.selection\n\n const $targetPos = state.doc.resolve($anchor.pos - $anchor.parentOffset - 2)\n\n if ($targetPos.index() === $targetPos.parent.childCount - 1) {\n return false\n }\n\n if ($targetPos.nodeAfter?.type.name !== typeOrName) {\n return false\n }\n\n return true\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,eAA0B;;;ACA1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA4B;AAIrB,IAAM,kBAAkB,CAAC,YAA+B,UAAuB;AACpF,QAAM,EAAE,MAAM,IAAI,MAAM;AACxB,QAAM,eAAW,yBAAY,YAAY,MAAM,MAAM;AAErD,MAAI,cAAc;AAClB,MAAI,eAAe,MAAM;AACzB,MAAI,aAAa,MAAM;AACvB,MAAI,cAA6B;AAEjC,SAAO,eAAe,KAAK,gBAAgB,MAAM;AAC/C,kBAAc,MAAM,KAAK,YAAY;AAErC,QAAI,YAAY,SAAS,UAAU;AACjC,oBAAc;AAAA,IAChB,OAAO;AACL,sBAAgB;AAChB,oBAAc;AAAA,IAChB;AAAA,EACF;AAEA,MAAI,gBAAgB,MAAM;AACxB,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,MAAM,MAAM,IAAI,QAAQ,UAAU,GAAG,OAAO,YAAY;AACnE;;;AC7BA,IAAAC,eAAkC;AAK3B,IAAM,mBAAmB,CAAC,YAAoB,UAAuB;AAC1E,QAAM,cAAc,gBAAgB,YAAY,KAAK;AAErD,MAAI,CAAC,aAAa;AAChB,WAAO;AAAA,EACT;AAEA,QAAM,CAAC,EAAE,KAAK,QAAI,gCAAkB,OAAO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MACT;AAAA,MACA,iBAAiB,CAAC,EAAE,OAAO,MAAM;AAC/B,YAAI,UAAU;AAEd,aAAK,QAAQ,UAAU,QAAQ,CAAC,EAAE,UAAU,aAAa,MAAM;AAC7D,cAAI,OAAO,MAAM,OAAO,MAAM,QAAQ,MAAM,QAAW;AACrD;AAAA,UACF;AAEA,cAAI,gBAAgB,QAAQ,UAAU,YAAY,GAAG;AACnD,sBAAU;AAAA,UACZ;AAAA,QACF,CAAC;AAED,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF,CAAC;;;ADpGD,IAAO,cAAQ;","names":["import_core","import_core","import_core","import_core","import_core"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/list-keymap.ts","../src/listHelpers/index.ts","../src/listHelpers/findListItemPos.ts","../src/listHelpers/getNextListDepth.ts","../src/listHelpers/handleBackspace.ts","../src/listHelpers/hasListBefore.ts","../src/listHelpers/hasListItemBefore.ts","../src/listHelpers/listItemHasSubList.ts","../src/listHelpers/handleDelete.ts","../src/listHelpers/nextListIsDeeper.ts","../src/listHelpers/nextListIsHigher.ts","../src/listHelpers/hasListItemAfter.ts"],"sourcesContent":["import { ListKeymap } from './list-keymap.js'\n\nexport * from './list-keymap.js'\nexport * as listHelpers from './listHelpers/index.js'\n\nexport default ListKeymap\n","import { Extension } from '@tiptap/core'\n\nimport { handleBackspace, handleDelete } from './listHelpers/index.js'\n\nexport type ListKeymapOptions = {\n /**\n * An array of list types. This is used for item and wrapper list matching.\n * @default []\n * @example [{ itemName: 'listItem', wrapperNames: ['bulletList', 'orderedList'] }]\n */\n listTypes: Array<{\n itemName: string,\n wrapperNames: string[],\n }>\n}\n\n/**\n * This extension registers custom keymaps to change the behaviour of the backspace and delete keys.\n * By default Prosemirror keyhandling will always lift or sink items so paragraphs are joined into\n * the adjacent or previous list item. This extension will prevent this behaviour and instead will\n * try to join paragraphs from two list items into a single list item.\n * @see https://www.tiptap.dev/api/extensions/list-keymap\n */\nexport const ListKeymap = Extension.create<ListKeymapOptions>({\n name: 'listKeymap',\n\n addOptions() {\n return {\n listTypes: [\n {\n itemName: 'listItem',\n wrapperNames: ['bulletList', 'orderedList'],\n },\n {\n itemName: 'taskItem',\n wrapperNames: ['taskList'],\n },\n ],\n }\n },\n\n addKeyboardShortcuts() {\n return {\n Delete: ({ editor }) => {\n let handled = false\n\n this.options.listTypes.forEach(({ itemName }) => {\n if (editor.state.schema.nodes[itemName] === undefined) {\n return\n }\n\n if (handleDelete(editor, itemName)) {\n handled = true\n }\n })\n\n return handled\n },\n 'Mod-Delete': ({ editor }) => {\n let handled = false\n\n this.options.listTypes.forEach(({ itemName }) => {\n if (editor.state.schema.nodes[itemName] === undefined) {\n return\n }\n\n if (handleDelete(editor, itemName)) {\n handled = true\n }\n })\n\n return handled\n },\n Backspace: ({ editor }) => {\n let handled = false\n\n this.options.listTypes.forEach(({ itemName, wrapperNames }) => {\n if (editor.state.schema.nodes[itemName] === undefined) {\n return\n }\n\n if (handleBackspace(editor, itemName, wrapperNames)) {\n handled = true\n }\n })\n\n return handled\n },\n 'Mod-Backspace': ({ editor }) => {\n let handled = false\n\n this.options.listTypes.forEach(({ itemName, wrapperNames }) => {\n if (editor.state.schema.nodes[itemName] === undefined) {\n return\n }\n\n if (handleBackspace(editor, itemName, wrapperNames)) {\n handled = true\n }\n })\n\n return handled\n },\n }\n },\n})\n","export * from './findListItemPos.js'\nexport * from './getNextListDepth.js'\nexport * from './handleBackspace.js'\nexport * from './handleDelete.js'\nexport * from './hasListBefore.js'\nexport * from './hasListItemAfter.js'\nexport * from './hasListItemBefore.js'\nexport * from './listItemHasSubList.js'\nexport * from './nextListIsDeeper.js'\nexport * from './nextListIsHigher.js'\n","import { getNodeType } from '@tiptap/core'\nimport { NodeType } from '@tiptap/pm/model'\nimport { EditorState } from '@tiptap/pm/state'\n\nexport const findListItemPos = (typeOrName: string | NodeType, state: EditorState) => {\n const { $from } = state.selection\n const nodeType = getNodeType(typeOrName, state.schema)\n\n let currentNode = null\n let currentDepth = $from.depth\n let currentPos = $from.pos\n let targetDepth: number | null = null\n\n while (currentDepth > 0 && targetDepth === null) {\n currentNode = $from.node(currentDepth)\n\n if (currentNode.type === nodeType) {\n targetDepth = currentDepth\n } else {\n currentDepth -= 1\n currentPos -= 1\n }\n }\n\n if (targetDepth === null) {\n return null\n }\n\n return { $pos: state.doc.resolve(currentPos), depth: targetDepth }\n}\n","import { getNodeAtPosition } from '@tiptap/core'\nimport { EditorState } from '@tiptap/pm/state'\n\nimport { findListItemPos } from './findListItemPos.js'\n\nexport const getNextListDepth = (typeOrName: string, state: EditorState) => {\n const listItemPos = findListItemPos(typeOrName, state)\n\n if (!listItemPos) {\n return false\n }\n\n const [, depth] = getNodeAtPosition(state, typeOrName, listItemPos.$pos.pos + 4)\n\n return depth\n}\n","import { Editor, isAtStartOfNode, isNodeActive } from '@tiptap/core'\nimport { Node } from '@tiptap/pm/model'\n\nimport { findListItemPos } from './findListItemPos.js'\nimport { hasListBefore } from './hasListBefore.js'\nimport { hasListItemBefore } from './hasListItemBefore.js'\nimport { listItemHasSubList } from './listItemHasSubList.js'\n\nexport const handleBackspace = (editor: Editor, name: string, parentListTypes: string[]) => {\n // this is required to still handle the undo handling\n if (editor.commands.undoInputRule()) {\n return true\n }\n\n // if the selection is not collapsed\n // we can rely on the default backspace behavior\n if (editor.state.selection.from !== editor.state.selection.to) {\n return false\n }\n\n // if the current item is NOT inside a list item &\n // the previous item is a list (orderedList or bulletList)\n // move the cursor into the list and delete the current item\n if (!isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {\n const { $anchor } = editor.state.selection\n\n const $listPos = editor.state.doc.resolve($anchor.before() - 1)\n\n const listDescendants: Array<{ node: Node, pos: number }> = []\n\n $listPos.node().descendants((node, pos) => {\n if (node.type.name === name) {\n listDescendants.push({ node, pos })\n }\n })\n\n const lastItem = listDescendants.at(-1)\n\n if (!lastItem) {\n return false\n }\n\n const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1)\n\n return editor.chain().cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end()).joinForward().run()\n }\n\n // if the cursor is not inside the current node type\n // do nothing and proceed\n if (!isNodeActive(editor.state, name)) {\n return false\n }\n\n // if the cursor is not at the start of a node\n // do nothing and proceed\n if (!isAtStartOfNode(editor.state)) {\n return false\n }\n\n const listItemPos = findListItemPos(name, editor.state)\n\n if (!listItemPos) {\n return false\n }\n\n const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2)\n const prevNode = $prev.node(listItemPos.depth)\n\n const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode)\n\n // if the previous item is a list item and doesn't have a sublist, join the list items\n if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) {\n return editor.commands.joinItemBackward()\n }\n\n // otherwise in the end, a backspace should\n // always just lift the list item if\n // joining / merging is not possible\n return editor.chain().liftListItem(name).run()\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nexport const hasListBefore = (editorState: EditorState, name: string, parentListTypes: string[]) => {\n const { $anchor } = editorState.selection\n\n const previousNodePos = Math.max(0, $anchor.pos - 2)\n\n const previousNode = editorState.doc.resolve(previousNodePos).node()\n\n if (!previousNode || !parentListTypes.includes(previousNode.type.name)) {\n return false\n }\n\n return true\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nexport const hasListItemBefore = (typeOrName: string, state: EditorState): boolean => {\n const { $anchor } = state.selection\n\n const $targetPos = state.doc.resolve($anchor.pos - 2)\n\n if ($targetPos.index() === 0) {\n return false\n }\n\n if ($targetPos.nodeBefore?.type.name !== typeOrName) {\n return false\n }\n\n return true\n}\n","import { getNodeType } from '@tiptap/core'\nimport { Node } from '@tiptap/pm/model'\nimport { EditorState } from '@tiptap/pm/state'\n\nexport const listItemHasSubList = (typeOrName: string, state: EditorState, node?: Node) => {\n if (!node) {\n return false\n }\n\n const nodeType = getNodeType(typeOrName, state.schema)\n\n let hasSubList = false\n\n node.descendants(child => {\n if (child.type === nodeType) {\n hasSubList = true\n }\n })\n\n return hasSubList\n}\n","import { Editor, isAtEndOfNode, isNodeActive } from '@tiptap/core'\n\nimport { nextListIsDeeper } from './nextListIsDeeper.js'\nimport { nextListIsHigher } from './nextListIsHigher.js'\n\nexport const handleDelete = (editor: Editor, name: string) => {\n // if the cursor is not inside the current node type\n // do nothing and proceed\n if (!isNodeActive(editor.state, name)) {\n return false\n }\n\n // if the cursor is not at the end of a node\n // do nothing and proceed\n if (!isAtEndOfNode(editor.state, name)) {\n return false\n }\n\n // if the selection is not collapsed, or not within a single node\n // do nothing and proceed\n const { selection } = editor.state\n const { $from, $to } = selection\n\n if (!selection.empty && $from.sameParent($to)) {\n return false\n }\n\n // check if the next node is a list with a deeper depth\n if (nextListIsDeeper(name, editor.state)) {\n return editor\n .chain()\n .focus(editor.state.selection.from + 4)\n .lift(name)\n .joinBackward()\n .run()\n }\n\n if (nextListIsHigher(name, editor.state)) {\n return editor.chain()\n .joinForward()\n .joinBackward()\n .run()\n }\n\n return editor.commands.joinItemForward()\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nimport { findListItemPos } from './findListItemPos.js'\nimport { getNextListDepth } from './getNextListDepth.js'\n\nexport const nextListIsDeeper = (typeOrName: string, state: EditorState) => {\n const listDepth = getNextListDepth(typeOrName, state)\n const listItemPos = findListItemPos(typeOrName, state)\n\n if (!listItemPos || !listDepth) {\n return false\n }\n\n if (listDepth > listItemPos.depth) {\n return true\n }\n\n return false\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nimport { findListItemPos } from './findListItemPos.js'\nimport { getNextListDepth } from './getNextListDepth.js'\n\nexport const nextListIsHigher = (typeOrName: string, state: EditorState) => {\n const listDepth = getNextListDepth(typeOrName, state)\n const listItemPos = findListItemPos(typeOrName, state)\n\n if (!listItemPos || !listDepth) {\n return false\n }\n\n if (listDepth < listItemPos.depth) {\n return true\n }\n\n return false\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nexport const hasListItemAfter = (typeOrName: string, state: EditorState): boolean => {\n const { $anchor } = state.selection\n\n const $targetPos = state.doc.resolve($anchor.pos - $anchor.parentOffset - 2)\n\n if ($targetPos.index() === $targetPos.parent.childCount - 1) {\n return false\n }\n\n if ($targetPos.nodeAfter?.type.name !== typeOrName) {\n return false\n }\n\n return true\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,eAA0B;;;ACA1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA4B;AAIrB,IAAM,kBAAkB,CAAC,YAA+B,UAAuB;AACpF,QAAM,EAAE,MAAM,IAAI,MAAM;AACxB,QAAM,eAAW,yBAAY,YAAY,MAAM,MAAM;AAErD,MAAI,cAAc;AAClB,MAAI,eAAe,MAAM;AACzB,MAAI,aAAa,MAAM;AACvB,MAAI,cAA6B;AAEjC,SAAO,eAAe,KAAK,gBAAgB,MAAM;AAC/C,kBAAc,MAAM,KAAK,YAAY;AAErC,QAAI,YAAY,SAAS,UAAU;AACjC,oBAAc;AAAA,IAChB,OAAO;AACL,sBAAgB;AAChB,oBAAc;AAAA,IAChB;AAAA,EACF;AAEA,MAAI,gBAAgB,MAAM;AACxB,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,MAAM,MAAM,IAAI,QAAQ,UAAU,GAAG,OAAO,YAAY;AACnE;;;AC7BA,IAAAC,eAAkC;AAK3B,IAAM,mBAAmB,CAAC,YAAoB,UAAuB;AAC1E,QAAM,cAAc,gBAAgB,YAAY,KAAK;AAErD,MAAI,CAAC,aAAa;AAChB,WAAO;AAAA,EACT;AAEA,QAAM,CAAC,EAAE,KAAK,QAAI,gCAAkB,OAAO,YAAY,YAAY,KAAK,MAAM,CAAC;AAE/E,SAAO;AACT;;;ACfA,IAAAC,eAAsD;;;ACE/C,IAAM,gBAAgB,CAAC,aAA0B,MAAc,oBAA8B;AAClG,QAAM,E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,cAAI,gBAAgB,QAAQ,UAAU,YAAY,GAAG;AACnD,sBAAU;AAAA,UACZ;AAAA,QACF,CAAC;AAED,eAAO;AAAA,MACT;AAAA,MACA,iBAAiB,CAAC,EAAE,OAAO,MAAM;AAC/B,YAAI,UAAU;AAEd,aAAK,QAAQ,UAAU,QAAQ,CAAC,EAAE,UAAU,aAAa,MAAM;AAC7D,cAAI,OAAO,MAAM,OAAO,MAAM,QAAQ,MAAM,QAAW;AACrD;AAAA,UACF;AAEA,cAAI,gBAAgB,QAAQ,UAAU,YAAY,GAAG;AACnD,sBAAU;AAAA,UACZ;AAAA,QACF,CAAC;AAED,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF,CAAC;;;ADpGD,IAAO,cAAQ;","names":["import_core","import_core","import_core","import_core","import_core"]}
package/dist/index.js CHANGED
@@ -106,6 +106,9 @@ var handleBackspace = (editor, name, parentListTypes) => {
106
106
  if (editor.commands.undoInputRule()) {
107
107
  return true;
108
108
  }
109
+ if (editor.state.selection.from !== editor.state.selection.to) {
110
+ return false;
111
+ }
109
112
  if (!isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {
110
113
  const { $anchor } = editor.state.selection;
111
114
  const $listPos = editor.state.doc.resolve($anchor.before() - 1);
@@ -178,6 +181,11 @@ var handleDelete = (editor, name) => {
178
181
  if (!isAtEndOfNode(editor.state, name)) {
179
182
  return false;
180
183
  }
184
+ const { selection } = editor.state;
185
+ const { $from, $to } = selection;
186
+ if (!selection.empty && $from.sameParent($to)) {
187
+ return false;
188
+ }
181
189
  if (nextListIsDeeper(name, editor.state)) {
182
190
  return editor.chain().focus(editor.state.selection.from + 4).lift(name).joinBackward().run();
183
191
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/list-keymap.ts","../src/listHelpers/index.ts","../src/listHelpers/findListItemPos.ts","../src/listHelpers/getNextListDepth.ts","../src/listHelpers/handleBackspace.ts","../src/listHelpers/hasListBefore.ts","../src/listHelpers/hasListItemBefore.ts","../src/listHelpers/listItemHasSubList.ts","../src/listHelpers/handleDelete.ts","../src/listHelpers/nextListIsDeeper.ts","../src/listHelpers/nextListIsHigher.ts","../src/listHelpers/hasListItemAfter.ts","../src/index.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\n\nimport { handleBackspace, handleDelete } from './listHelpers/index.js'\n\nexport type ListKeymapOptions = {\n /**\n * An array of list types. This is used for item and wrapper list matching.\n * @default []\n * @example [{ itemName: 'listItem', wrapperNames: ['bulletList', 'orderedList'] }]\n */\n listTypes: Array<{\n itemName: string,\n wrapperNames: string[],\n }>\n}\n\n/**\n * This extension registers custom keymaps to change the behaviour of the backspace and delete keys.\n * By default Prosemirror keyhandling will always lift or sink items so paragraphs are joined into\n * the adjacent or previous list item. This extension will prevent this behaviour and instead will\n * try to join paragraphs from two list items into a single list item.\n * @see https://www.tiptap.dev/api/extensions/list-keymap\n */\nexport const ListKeymap = Extension.create<ListKeymapOptions>({\n name: 'listKeymap',\n\n addOptions() {\n return {\n listTypes: [\n {\n itemName: 'listItem',\n wrapperNames: ['bulletList', 'orderedList'],\n },\n {\n itemName: 'taskItem',\n wrapperNames: ['taskList'],\n },\n ],\n }\n },\n\n addKeyboardShortcuts() {\n return {\n Delete: ({ editor }) => {\n let handled = false\n\n this.options.listTypes.forEach(({ itemName }) => {\n if (editor.state.schema.nodes[itemName] === undefined) {\n return\n }\n\n if (handleDelete(editor, itemName)) {\n handled = true\n }\n })\n\n return handled\n },\n 'Mod-Delete': ({ editor }) => {\n let handled = false\n\n this.options.listTypes.forEach(({ itemName }) => {\n if (editor.state.schema.nodes[itemName] === undefined) {\n return\n }\n\n if (handleDelete(editor, itemName)) {\n handled = true\n }\n })\n\n return handled\n },\n Backspace: ({ editor }) => {\n let handled = false\n\n this.options.listTypes.forEach(({ itemName, wrapperNames }) => {\n if (editor.state.schema.nodes[itemName] === undefined) {\n return\n }\n\n if (handleBackspace(editor, itemName, wrapperNames)) {\n handled = true\n }\n })\n\n return handled\n },\n 'Mod-Backspace': ({ editor }) => {\n let handled = false\n\n this.options.listTypes.forEach(({ itemName, wrapperNames }) => {\n if (editor.state.schema.nodes[itemName] === undefined) {\n return\n }\n\n if (handleBackspace(editor, itemName, wrapperNames)) {\n handled = true\n }\n })\n\n return handled\n },\n }\n },\n})\n","export * from './findListItemPos.js'\nexport * from './getNextListDepth.js'\nexport * from './handleBackspace.js'\nexport * from './handleDelete.js'\nexport * from './hasListBefore.js'\nexport * from './hasListItemAfter.js'\nexport * from './hasListItemBefore.js'\nexport * from './listItemHasSubList.js'\nexport * from './nextListIsDeeper.js'\nexport * from './nextListIsHigher.js'\n","import { getNodeType } from '@tiptap/core'\nimport { NodeType } from '@tiptap/pm/model'\nimport { EditorState } from '@tiptap/pm/state'\n\nexport const findListItemPos = (typeOrName: string | NodeType, state: EditorState) => {\n const { $from } = state.selection\n const nodeType = getNodeType(typeOrName, state.schema)\n\n let currentNode = null\n let currentDepth = $from.depth\n let currentPos = $from.pos\n let targetDepth: number | null = null\n\n while (currentDepth > 0 && targetDepth === null) {\n currentNode = $from.node(currentDepth)\n\n if (currentNode.type === nodeType) {\n targetDepth = currentDepth\n } else {\n currentDepth -= 1\n currentPos -= 1\n }\n }\n\n if (targetDepth === null) {\n return null\n }\n\n return { $pos: state.doc.resolve(currentPos), depth: targetDepth }\n}\n","import { getNodeAtPosition } from '@tiptap/core'\nimport { EditorState } from '@tiptap/pm/state'\n\nimport { findListItemPos } from './findListItemPos.js'\n\nexport const getNextListDepth = (typeOrName: string, state: EditorState) => {\n const listItemPos = findListItemPos(typeOrName, state)\n\n if (!listItemPos) {\n return false\n }\n\n const [, depth] = getNodeAtPosition(state, typeOrName, listItemPos.$pos.pos + 4)\n\n return depth\n}\n","import { Editor, isAtStartOfNode, isNodeActive } from '@tiptap/core'\nimport { Node } from '@tiptap/pm/model'\n\nimport { findListItemPos } from './findListItemPos.js'\nimport { hasListBefore } from './hasListBefore.js'\nimport { hasListItemBefore } from './hasListItemBefore.js'\nimport { listItemHasSubList } from './listItemHasSubList.js'\n\nexport const handleBackspace = (editor: Editor, name: string, parentListTypes: string[]) => {\n // this is required to still handle the undo handling\n if (editor.commands.undoInputRule()) {\n return true\n }\n\n // if the current item is NOT inside a list item &\n // the previous item is a list (orderedList or bulletList)\n // move the cursor into the list and delete the current item\n if (!isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {\n const { $anchor } = editor.state.selection\n\n const $listPos = editor.state.doc.resolve($anchor.before() - 1)\n\n const listDescendants: Array<{ node: Node, pos: number }> = []\n\n $listPos.node().descendants((node, pos) => {\n if (node.type.name === name) {\n listDescendants.push({ node, pos })\n }\n })\n\n const lastItem = listDescendants.at(-1)\n\n if (!lastItem) {\n return false\n }\n\n const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1)\n\n return editor.chain().cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end()).joinForward().run()\n }\n\n // if the cursor is not inside the current node type\n // do nothing and proceed\n if (!isNodeActive(editor.state, name)) {\n return false\n }\n\n // if the cursor is not at the start of a node\n // do nothing and proceed\n if (!isAtStartOfNode(editor.state)) {\n return false\n }\n\n const listItemPos = findListItemPos(name, editor.state)\n\n if (!listItemPos) {\n return false\n }\n\n const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2)\n const prevNode = $prev.node(listItemPos.depth)\n\n const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode)\n\n // if the previous item is a list item and doesn't have a sublist, join the list items\n if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) {\n return editor.commands.joinItemBackward()\n }\n\n // otherwise in the end, a backspace should\n // always just lift the list item if\n // joining / merging is not possible\n return editor.chain().liftListItem(name).run()\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nexport const hasListBefore = (editorState: EditorState, name: string, parentListTypes: string[]) => {\n const { $anchor } = editorState.selection\n\n const previousNodePos = Math.max(0, $anchor.pos - 2)\n\n const previousNode = editorState.doc.resolve(previousNodePos).node()\n\n if (!previousNode || !parentListTypes.includes(previousNode.type.name)) {\n return false\n }\n\n return true\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nexport const hasListItemBefore = (typeOrName: string, state: EditorState): boolean => {\n const { $anchor } = state.selection\n\n const $targetPos = state.doc.resolve($anchor.pos - 2)\n\n if ($targetPos.index() === 0) {\n return false\n }\n\n if ($targetPos.nodeBefore?.type.name !== typeOrName) {\n return false\n }\n\n return true\n}\n","import { getNodeType } from '@tiptap/core'\nimport { Node } from '@tiptap/pm/model'\nimport { EditorState } from '@tiptap/pm/state'\n\nexport const listItemHasSubList = (typeOrName: string, state: EditorState, node?: Node) => {\n if (!node) {\n return false\n }\n\n const nodeType = getNodeType(typeOrName, state.schema)\n\n let hasSubList = false\n\n node.descendants(child => {\n if (child.type === nodeType) {\n hasSubList = true\n }\n })\n\n return hasSubList\n}\n","import { Editor, isAtEndOfNode, isNodeActive } from '@tiptap/core'\n\nimport { nextListIsDeeper } from './nextListIsDeeper.js'\nimport { nextListIsHigher } from './nextListIsHigher.js'\n\nexport const handleDelete = (editor: Editor, name: string) => {\n // if the cursor is not inside the current node type\n // do nothing and proceed\n if (!isNodeActive(editor.state, name)) {\n return false\n }\n\n // if the cursor is not at the end of a node\n // do nothing and proceed\n if (!isAtEndOfNode(editor.state, name)) {\n return false\n }\n\n // check if the next node is a list with a deeper depth\n if (nextListIsDeeper(name, editor.state)) {\n return editor\n .chain()\n .focus(editor.state.selection.from + 4)\n .lift(name)\n .joinBackward()\n .run()\n }\n\n if (nextListIsHigher(name, editor.state)) {\n return editor.chain()\n .joinForward()\n .joinBackward()\n .run()\n }\n\n return editor.commands.joinItemForward()\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nimport { findListItemPos } from './findListItemPos.js'\nimport { getNextListDepth } from './getNextListDepth.js'\n\nexport const nextListIsDeeper = (typeOrName: string, state: EditorState) => {\n const listDepth = getNextListDepth(typeOrName, state)\n const listItemPos = findListItemPos(typeOrName, state)\n\n if (!listItemPos || !listDepth) {\n return false\n }\n\n if (listDepth > listItemPos.depth) {\n return true\n }\n\n return false\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nimport { findListItemPos } from './findListItemPos.js'\nimport { getNextListDepth } from './getNextListDepth.js'\n\nexport const nextListIsHigher = (typeOrName: string, state: EditorState) => {\n const listDepth = getNextListDepth(typeOrName, state)\n const listItemPos = findListItemPos(typeOrName, state)\n\n if (!listItemPos || !listDepth) {\n return false\n }\n\n if (listDepth < listItemPos.depth) {\n return true\n }\n\n return false\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nexport const hasListItemAfter = (typeOrName: string, state: EditorState): boolean => {\n const { $anchor } = state.selection\n\n const $targetPos = state.doc.resolve($anchor.pos - $anchor.parentOffset - 2)\n\n if ($targetPos.index() === $targetPos.parent.childCount - 1) {\n return false\n }\n\n if ($targetPos.nodeAfter?.type.name !== typeOrName) {\n return false\n }\n\n return true\n}\n","import { ListKeymap } from './list-keymap.js'\n\nexport * from './list-keymap.js'\nexport * as listHelpers from './listHelpers/index.js'\n\nexport default ListKeymap\n"],"mappings":";;;;;;;AAAA,SAAS,iBAAiB;;;ACA1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,SAAS,mBAAmB;AAIrB,IAAM,kBAAkB,CAAC,YAA+B,UAAuB;AACpF,QAAM,EAAE,MAAM,IAAI,MAAM;AACxB,QAAM,WAAW,YAAY,YAAY,MAAM,MAAM;AAErD,MAAI,cAAc;AAClB,MAAI,eAAe,MAAM;AACzB,MAAI,aAAa,MAAM;AACvB,MAAI,cAA6B;AAEjC,SAAO,eAAe,KAAK,gBAAgB,MAAM;AAC/C,kBAAc,MAAM,KAAK,YAAY;AAErC,QAAI,YAAY,SAAS,UAAU;AACjC,oBAAc;AAAA,IAChB,OAAO;AACL,sBAAgB;AAChB,oBAAc;AAAA,IAChB;AAAA,EACF;AAEA,MAAI,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;AAAA,QACF,CAAC;AAED,eAAO;AAAA,MACT;AAAA,MACA,WAAW,CAAC,EAAE,OAAO,MAAM;AACzB,YAAI,UAAU;AAEd,aAAK,QAAQ,UAAU,QAAQ,CAAC,EAAE,UAAU,aAAa,MAAM;AAC7D,cAAI,OAAO,MAAM,OAAO,MAAM,QAAQ,MAAM,QAAW;AACrD;AAAA,UACF;AAEA,cAAI,gBAAgB,QAAQ,UAAU,YAAY,GAAG;AACnD,sBAAU;AAAA,UACZ;AAAA,QACF,CAAC;AAED,eAAO;AAAA,MACT;AAAA,MACA,iBAAiB,CAAC,EAAE,OAAO,MAAM;AAC/B,YAAI,UAAU;AAEd,aAAK,QAAQ,UAAU,QAAQ,CAAC,EAAE,UAAU,aAAa,MAAM;AAC7D,cAAI,OAAO,MAAM,OAAO,MAAM,QAAQ,MAAM,QAAW;AACrD;AAAA,UACF;AAEA,cAAI,gBAAgB,QAAQ,UAAU,YAAY,GAAG;AACnD,sBAAU;AAAA,UACZ;AAAA,QACF,CAAC;AAED,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF,CAAC;;;AYpGD,IAAO,cAAQ;","names":["getNodeType","isNodeActive","isNodeActive"]}
1
+ {"version":3,"sources":["../src/list-keymap.ts","../src/listHelpers/index.ts","../src/listHelpers/findListItemPos.ts","../src/listHelpers/getNextListDepth.ts","../src/listHelpers/handleBackspace.ts","../src/listHelpers/hasListBefore.ts","../src/listHelpers/hasListItemBefore.ts","../src/listHelpers/listItemHasSubList.ts","../src/listHelpers/handleDelete.ts","../src/listHelpers/nextListIsDeeper.ts","../src/listHelpers/nextListIsHigher.ts","../src/listHelpers/hasListItemAfter.ts","../src/index.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\n\nimport { handleBackspace, handleDelete } from './listHelpers/index.js'\n\nexport type ListKeymapOptions = {\n /**\n * An array of list types. This is used for item and wrapper list matching.\n * @default []\n * @example [{ itemName: 'listItem', wrapperNames: ['bulletList', 'orderedList'] }]\n */\n listTypes: Array<{\n itemName: string,\n wrapperNames: string[],\n }>\n}\n\n/**\n * This extension registers custom keymaps to change the behaviour of the backspace and delete keys.\n * By default Prosemirror keyhandling will always lift or sink items so paragraphs are joined into\n * the adjacent or previous list item. This extension will prevent this behaviour and instead will\n * try to join paragraphs from two list items into a single list item.\n * @see https://www.tiptap.dev/api/extensions/list-keymap\n */\nexport const ListKeymap = Extension.create<ListKeymapOptions>({\n name: 'listKeymap',\n\n addOptions() {\n return {\n listTypes: [\n {\n itemName: 'listItem',\n wrapperNames: ['bulletList', 'orderedList'],\n },\n {\n itemName: 'taskItem',\n wrapperNames: ['taskList'],\n },\n ],\n }\n },\n\n addKeyboardShortcuts() {\n return {\n Delete: ({ editor }) => {\n let handled = false\n\n this.options.listTypes.forEach(({ itemName }) => {\n if (editor.state.schema.nodes[itemName] === undefined) {\n return\n }\n\n if (handleDelete(editor, itemName)) {\n handled = true\n }\n })\n\n return handled\n },\n 'Mod-Delete': ({ editor }) => {\n let handled = false\n\n this.options.listTypes.forEach(({ itemName }) => {\n if (editor.state.schema.nodes[itemName] === undefined) {\n return\n }\n\n if (handleDelete(editor, itemName)) {\n handled = true\n }\n })\n\n return handled\n },\n Backspace: ({ editor }) => {\n let handled = false\n\n this.options.listTypes.forEach(({ itemName, wrapperNames }) => {\n if (editor.state.schema.nodes[itemName] === undefined) {\n return\n }\n\n if (handleBackspace(editor, itemName, wrapperNames)) {\n handled = true\n }\n })\n\n return handled\n },\n 'Mod-Backspace': ({ editor }) => {\n let handled = false\n\n this.options.listTypes.forEach(({ itemName, wrapperNames }) => {\n if (editor.state.schema.nodes[itemName] === undefined) {\n return\n }\n\n if (handleBackspace(editor, itemName, wrapperNames)) {\n handled = true\n }\n })\n\n return handled\n },\n }\n },\n})\n","export * from './findListItemPos.js'\nexport * from './getNextListDepth.js'\nexport * from './handleBackspace.js'\nexport * from './handleDelete.js'\nexport * from './hasListBefore.js'\nexport * from './hasListItemAfter.js'\nexport * from './hasListItemBefore.js'\nexport * from './listItemHasSubList.js'\nexport * from './nextListIsDeeper.js'\nexport * from './nextListIsHigher.js'\n","import { getNodeType } from '@tiptap/core'\nimport { NodeType } from '@tiptap/pm/model'\nimport { EditorState } from '@tiptap/pm/state'\n\nexport const findListItemPos = (typeOrName: string | NodeType, state: EditorState) => {\n const { $from } = state.selection\n const nodeType = getNodeType(typeOrName, state.schema)\n\n let currentNode = null\n let currentDepth = $from.depth\n let currentPos = $from.pos\n let targetDepth: number | null = null\n\n while (currentDepth > 0 && targetDepth === null) {\n currentNode = $from.node(currentDepth)\n\n if (currentNode.type === nodeType) {\n targetDepth = currentDepth\n } else {\n currentDepth -= 1\n currentPos -= 1\n }\n }\n\n if (targetDepth === null) {\n return null\n }\n\n return { $pos: state.doc.resolve(currentPos), depth: targetDepth }\n}\n","import { getNodeAtPosition } from '@tiptap/core'\nimport { EditorState } from '@tiptap/pm/state'\n\nimport { findListItemPos } from './findListItemPos.js'\n\nexport const getNextListDepth = (typeOrName: string, state: EditorState) => {\n const listItemPos = findListItemPos(typeOrName, state)\n\n if (!listItemPos) {\n return false\n }\n\n const [, depth] = getNodeAtPosition(state, typeOrName, listItemPos.$pos.pos + 4)\n\n return depth\n}\n","import { Editor, isAtStartOfNode, isNodeActive } from '@tiptap/core'\nimport { Node } from '@tiptap/pm/model'\n\nimport { findListItemPos } from './findListItemPos.js'\nimport { hasListBefore } from './hasListBefore.js'\nimport { hasListItemBefore } from './hasListItemBefore.js'\nimport { listItemHasSubList } from './listItemHasSubList.js'\n\nexport const handleBackspace = (editor: Editor, name: string, parentListTypes: string[]) => {\n // this is required to still handle the undo handling\n if (editor.commands.undoInputRule()) {\n return true\n }\n\n // if the selection is not collapsed\n // we can rely on the default backspace behavior\n if (editor.state.selection.from !== editor.state.selection.to) {\n return false\n }\n\n // if the current item is NOT inside a list item &\n // the previous item is a list (orderedList or bulletList)\n // move the cursor into the list and delete the current item\n if (!isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {\n const { $anchor } = editor.state.selection\n\n const $listPos = editor.state.doc.resolve($anchor.before() - 1)\n\n const listDescendants: Array<{ node: Node, pos: number }> = []\n\n $listPos.node().descendants((node, pos) => {\n if (node.type.name === name) {\n listDescendants.push({ node, pos })\n }\n })\n\n const lastItem = listDescendants.at(-1)\n\n if (!lastItem) {\n return false\n }\n\n const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1)\n\n return editor.chain().cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end()).joinForward().run()\n }\n\n // if the cursor is not inside the current node type\n // do nothing and proceed\n if (!isNodeActive(editor.state, name)) {\n return false\n }\n\n // if the cursor is not at the start of a node\n // do nothing and proceed\n if (!isAtStartOfNode(editor.state)) {\n return false\n }\n\n const listItemPos = findListItemPos(name, editor.state)\n\n if (!listItemPos) {\n return false\n }\n\n const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2)\n const prevNode = $prev.node(listItemPos.depth)\n\n const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode)\n\n // if the previous item is a list item and doesn't have a sublist, join the list items\n if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) {\n return editor.commands.joinItemBackward()\n }\n\n // otherwise in the end, a backspace should\n // always just lift the list item if\n // joining / merging is not possible\n return editor.chain().liftListItem(name).run()\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nexport const hasListBefore = (editorState: EditorState, name: string, parentListTypes: string[]) => {\n const { $anchor } = editorState.selection\n\n const previousNodePos = Math.max(0, $anchor.pos - 2)\n\n const previousNode = editorState.doc.resolve(previousNodePos).node()\n\n if (!previousNode || !parentListTypes.includes(previousNode.type.name)) {\n return false\n }\n\n return true\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nexport const hasListItemBefore = (typeOrName: string, state: EditorState): boolean => {\n const { $anchor } = state.selection\n\n const $targetPos = state.doc.resolve($anchor.pos - 2)\n\n if ($targetPos.index() === 0) {\n return false\n }\n\n if ($targetPos.nodeBefore?.type.name !== typeOrName) {\n return false\n }\n\n return true\n}\n","import { getNodeType } from '@tiptap/core'\nimport { Node } from '@tiptap/pm/model'\nimport { EditorState } from '@tiptap/pm/state'\n\nexport const listItemHasSubList = (typeOrName: string, state: EditorState, node?: Node) => {\n if (!node) {\n return false\n }\n\n const nodeType = getNodeType(typeOrName, state.schema)\n\n let hasSubList = false\n\n node.descendants(child => {\n if (child.type === nodeType) {\n hasSubList = true\n }\n })\n\n return hasSubList\n}\n","import { Editor, isAtEndOfNode, isNodeActive } from '@tiptap/core'\n\nimport { nextListIsDeeper } from './nextListIsDeeper.js'\nimport { nextListIsHigher } from './nextListIsHigher.js'\n\nexport const handleDelete = (editor: Editor, name: string) => {\n // if the cursor is not inside the current node type\n // do nothing and proceed\n if (!isNodeActive(editor.state, name)) {\n return false\n }\n\n // if the cursor is not at the end of a node\n // do nothing and proceed\n if (!isAtEndOfNode(editor.state, name)) {\n return false\n }\n\n // if the selection is not collapsed, or not within a single node\n // do nothing and proceed\n const { selection } = editor.state\n const { $from, $to } = selection\n\n if (!selection.empty && $from.sameParent($to)) {\n return false\n }\n\n // check if the next node is a list with a deeper depth\n if (nextListIsDeeper(name, editor.state)) {\n return editor\n .chain()\n .focus(editor.state.selection.from + 4)\n .lift(name)\n .joinBackward()\n .run()\n }\n\n if (nextListIsHigher(name, editor.state)) {\n return editor.chain()\n .joinForward()\n .joinBackward()\n .run()\n }\n\n return editor.commands.joinItemForward()\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nimport { findListItemPos } from './findListItemPos.js'\nimport { getNextListDepth } from './getNextListDepth.js'\n\nexport const nextListIsDeeper = (typeOrName: string, state: EditorState) => {\n const listDepth = getNextListDepth(typeOrName, state)\n const listItemPos = findListItemPos(typeOrName, state)\n\n if (!listItemPos || !listDepth) {\n return false\n }\n\n if (listDepth > listItemPos.depth) {\n return true\n }\n\n return false\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nimport { findListItemPos } from './findListItemPos.js'\nimport { getNextListDepth } from './getNextListDepth.js'\n\nexport const nextListIsHigher = (typeOrName: string, state: EditorState) => {\n const listDepth = getNextListDepth(typeOrName, state)\n const listItemPos = findListItemPos(typeOrName, state)\n\n if (!listItemPos || !listDepth) {\n return false\n }\n\n if (listDepth < listItemPos.depth) {\n return true\n }\n\n return false\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nexport const hasListItemAfter = (typeOrName: string, state: EditorState): boolean => {\n const { $anchor } = state.selection\n\n const $targetPos = state.doc.resolve($anchor.pos - $anchor.parentOffset - 2)\n\n if ($targetPos.index() === $targetPos.parent.childCount - 1) {\n return false\n }\n\n if ($targetPos.nodeAfter?.type.name !== typeOrName) {\n return false\n }\n\n return true\n}\n","import { ListKeymap } from './list-keymap.js'\n\nexport * from './list-keymap.js'\nexport * as listHelpers from './listHelpers/index.js'\n\nexport default ListKeymap\n"],"mappings":";;;;;;;AAAA,SAAS,iBAAiB;;;ACA1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,SAAS,mBAAmB;AAIrB,IAAM,kBAAkB,CAAC,YAA+B,UAAuB;AACpF,QAAM,EAAE,MAAM,IAAI,MAAM;AACxB,QAAM,WAAW,YAAY,YAAY,MAAM,MAAM;AAErD,MAAI,cAAc;AAClB,MAAI,eAAe,MAAM;AACzB,MAAI,aAAa,MAAM;AACvB,MAAI,cAA6B;AAEjC,SAAO,eAAe,KAAK,gBAAgB,MAAM;AAC/C,kBAAc,MAAM,KAAK,YAAY;AAErC,QAAI,YAAY,SAAS,UAAU;AACjC,oBAAc;AAAA,IAChB,OAAO;AACL,sBAAgB;AAChB,oBAAc;AAAA,IAChB;AAAA,EACF;AAEA,MAAI,gBAAgB,MAAM;AACxB,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,MAAM,MAAM,IAAI,QAAQ,UAAU,GAAG,OAAO,YAAY;AACnE;;;AC7BA,SAAS,yBAAyB;AAK3B,IAAM,mBAAmB,CAAC,YAA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AA,UACF;AAEA,cAAI,aAAa,QAAQ,QAAQ,GAAG;AAClC,sBAAU;AAAA,UACZ;AAAA,QACF,CAAC;AAED,eAAO;AAAA,MACT;AAAA,MACA,WAAW,CAAC,EAAE,OAAO,MAAM;AACzB,YAAI,UAAU;AAEd,aAAK,QAAQ,UAAU,QAAQ,CAAC,EAAE,UAAU,aAAa,MAAM;AAC7D,cAAI,OAAO,MAAM,OAAO,MAAM,QAAQ,MAAM,QAAW;AACrD;AAAA,UACF;AAEA,cAAI,gBAAgB,QAAQ,UAAU,YAAY,GAAG;AACnD,sBAAU;AAAA,UACZ;AAAA,QACF,CAAC;AAED,eAAO;AAAA,MACT;AAAA,MACA,iBAAiB,CAAC,EAAE,OAAO,MAAM;AAC/B,YAAI,UAAU;AAEd,aAAK,QAAQ,UAAU,QAAQ,CAAC,EAAE,UAAU,aAAa,MAAM;AAC7D,cAAI,OAAO,MAAM,OAAO,MAAM,QAAQ,MAAM,QAAW;AACrD;AAAA,UACF;AAEA,cAAI,gBAAgB,QAAQ,UAAU,YAAY,GAAG;AACnD,sBAAU;AAAA,UACZ;AAAA,QACF,CAAC;AAED,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF,CAAC;;;AYpGD,IAAO,cAAQ;","names":["getNodeType","isNodeActive","isNodeActive"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/extension-list-keymap",
3
3
  "description": "list keymap extension for tiptap",
4
- "version": "3.0.0-next.1",
4
+ "version": "3.0.0-next.3",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -28,7 +28,7 @@
28
28
  "dist"
29
29
  ],
30
30
  "devDependencies": {
31
- "@tiptap/core": "^3.0.0-next.1"
31
+ "@tiptap/core": "^3.0.0-next.3"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "@tiptap/core": "^3.0.0-next.1"
@@ -12,6 +12,12 @@ export const handleBackspace = (editor: Editor, name: string, parentListTypes: s
12
12
  return true
13
13
  }
14
14
 
15
+ // if the selection is not collapsed
16
+ // we can rely on the default backspace behavior
17
+ if (editor.state.selection.from !== editor.state.selection.to) {
18
+ return false
19
+ }
20
+
15
21
  // if the current item is NOT inside a list item &
16
22
  // the previous item is a list (orderedList or bulletList)
17
23
  // move the cursor into the list and delete the current item
@@ -16,6 +16,15 @@ export const handleDelete = (editor: Editor, name: string) => {
16
16
  return false
17
17
  }
18
18
 
19
+ // if the selection is not collapsed, or not within a single node
20
+ // do nothing and proceed
21
+ const { selection } = editor.state
22
+ const { $from, $to } = selection
23
+
24
+ if (!selection.empty && $from.sameParent($to)) {
25
+ return false
26
+ }
27
+
19
28
  // check if the next node is a list with a deeper depth
20
29
  if (nextListIsDeeper(name, editor.state)) {
21
30
  return editor