prosemirror-flat-list
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -659,2 +659,60 @@ // src/commands/dedent-list.ts | ||
// src/commands/join-list-backward.ts | ||
import { NodeRange as NodeRange4 } from "prosemirror-model"; | ||
// src/utils/at-textblock-start.ts | ||
function atTextblockStart(state, view) { | ||
const { $cursor } = state.selection; | ||
if (!$cursor || (view ? !view.endOfTextblock("backward", state) : $cursor.parentOffset > 0)) | ||
return null; | ||
return $cursor; | ||
} | ||
// src/commands/join-list-backward.ts | ||
var joinListBackward = (state, dispatch, view) => { | ||
const $cursor = atTextblockStart(state, view); | ||
if (!$cursor) | ||
return false; | ||
const { depth } = $cursor; | ||
if (depth < 2) | ||
return false; | ||
const listDepth = depth - 1; | ||
const listNode = $cursor.node(listDepth); | ||
if (!isListNode(listNode)) | ||
return false; | ||
const indexInList = $cursor.index(listDepth); | ||
if (indexInList === 0) { | ||
if (dispatch) { | ||
liftListContent(state, dispatch, $cursor); | ||
} | ||
return true; | ||
} | ||
if (indexInList === listNode.childCount - 1) { | ||
if (dispatch) { | ||
liftParent(state, dispatch, $cursor); | ||
} | ||
return true; | ||
} | ||
return false; | ||
}; | ||
function liftListContent(state, dispatch, $cursor) { | ||
const tr = state.tr; | ||
const listDepth = $cursor.depth - 1; | ||
const range = new NodeRange4( | ||
$cursor, | ||
tr.doc.resolve($cursor.end(listDepth)), | ||
listDepth | ||
); | ||
if (safeLift(tr, range)) { | ||
dispatch(tr); | ||
} | ||
} | ||
function liftParent(state, dispatch, $cursor) { | ||
const tr = state.tr; | ||
const range = $cursor.blockRange(); | ||
if (range && safeLift(tr, range)) { | ||
dispatch(tr); | ||
} | ||
} | ||
// src/commands/keymap.ts | ||
@@ -779,2 +837,9 @@ import { | ||
// src/commands/keymap.ts | ||
var backspaceCommand = chainCommands3( | ||
protectCollapsed, | ||
deleteSelection, | ||
joinListBackward, | ||
joinTextblockBackward, | ||
selectNodeBackward | ||
); | ||
var deleteCommand = chainCommands3( | ||
@@ -786,8 +851,2 @@ protectCollapsed, | ||
); | ||
var backspaceCommand = chainCommands3( | ||
protectCollapsed, | ||
deleteSelection, | ||
joinTextblockBackward, | ||
selectNodeBackward | ||
); | ||
var listKeymap = { | ||
@@ -797,4 +856,4 @@ Enter: createSplitListCommand(), | ||
"Mod-]": createIndentListCommand(), | ||
Delete: deleteCommand, | ||
Backspace: backspaceCommand | ||
Backspace: backspaceCommand, | ||
Delete: deleteCommand | ||
}; | ||
@@ -905,3 +964,3 @@ | ||
// src/commands/wrap-in-list.ts | ||
import { NodeRange as NodeRange4 } from "prosemirror-model"; | ||
import { NodeRange as NodeRange5 } from "prosemirror-model"; | ||
import { findWrapping } from "prosemirror-transform"; | ||
@@ -930,3 +989,3 @@ | ||
if (rangeAllowInlineContent(range) && isListNode(range.parent) && range.depth > 0) { | ||
range = new NodeRange4($from, $to, range.depth - 1); | ||
range = new NodeRange5($from, $to, range.depth - 1); | ||
} | ||
@@ -947,3 +1006,3 @@ const attrs = typeof getAttrs === "function" ? getAttrs(range) : getAttrs; | ||
} else { | ||
const range2 = new NodeRange4( | ||
const range2 = new NodeRange5( | ||
tr.doc.resolve($from.posAtIndex(i, depth) + 1), | ||
@@ -1271,2 +1330,3 @@ tr.doc.resolve($from.posAtIndex(i + 1, depth) - 1), | ||
alwaysTrue, | ||
backspaceCommand, | ||
createDedentListCommand, | ||
@@ -1287,2 +1347,3 @@ createIndentListCommand, | ||
defaultMarkerGetter, | ||
deleteCommand, | ||
doSplitList, | ||
@@ -1297,2 +1358,3 @@ enterWithoutLift, | ||
isListsRange, | ||
joinListBackward, | ||
joinListElements, | ||
@@ -1299,0 +1361,0 @@ listKeymap, |
@@ -30,2 +30,15 @@ import { Command } from 'prosemirror-state'; | ||
/** | ||
* Keybinding for `Backspace`. It's chained with following commands: | ||
* | ||
* - {@link protectCollapsed} | ||
* - [deleteSelection](https://prosemirror.net/docs/ref/#commands.deleteSelection) | ||
* - {@link joinListBackward} | ||
* - [joinTextblockBackward](https://prosemirror.net/docs/ref/#commands.joinTextblockBackward) | ||
* - [selectNodeBackward](https://prosemirror.net/docs/ref/#commands.selectNodeBackward) | ||
* | ||
* @public | ||
*/ | ||
export declare const backspaceCommand: Command; | ||
/** | ||
* Returns a command function that decreases the indentation of selected list nodes. | ||
@@ -173,2 +186,14 @@ * | ||
/** | ||
* Keybinding for `Delete`. It's chained with following commands: | ||
* | ||
* - {@link protectCollapsed} | ||
* - [deleteSelection](https://prosemirror.net/docs/ref/#commands.deleteSelection) | ||
* - [joinTextblockForward](https://prosemirror.net/docs/ref/#commands.joinTextblockForward) | ||
* - [selectNodeForward](https://prosemirror.net/docs/ref/#commands.selectNodeForward) | ||
* | ||
* @public | ||
*/ | ||
export declare const deleteCommand: Command; | ||
/** | ||
* @internal | ||
@@ -239,2 +264,11 @@ */ | ||
/** | ||
* If the text cursor is at the start of the first child of a list node, lift | ||
* all content inside the list. If the text cursor is at the start of the last | ||
* child of a list node, lift this child. | ||
* | ||
* @public | ||
*/ | ||
export declare const joinListBackward: Command; | ||
/** | ||
* Merge adjacent <ul> elements or adjacent <ol> elements into a single list element. | ||
@@ -276,10 +310,8 @@ * | ||
* | ||
* - `Enter`: Split current list item or create a new paragraph. | ||
* - `Mod-[`: Decrease indentation. | ||
* - `Mod-]`: Increase indentation. | ||
* - `Delete`: Expand selected collapsed content, or fall back to the usually delete command. | ||
* - `Backspace`: Expand selected collapsed content, or fall back to the usually Backspace command. | ||
* - `Enter`: Split current list item or create a new paragraph. See {@link createSplitListCommand}. | ||
* - `Mod-[`: Decrease indentation. See {@link createDedentListCommand}. | ||
* - `Mod-]`: Increase indentation. See {@link createIndentListCommand}. | ||
* - `Backspace`: See {@link backspaceCommand}. | ||
* - `Delete`: See {@link deleteCommand}. | ||
* | ||
* Notice that `Delete` and `Backspace` use [`joinTextblockForward`](https://prosemirror.net/docs/ref/#commands.joinTextblockForward) and [`joinTextblockBackward`](https://prosemirror.net/docs/ref/#commands.joinTextblockBackward) under the hood, which have slightly different behavior than the default [`joinForward`](https://prosemirror.net/docs/ref/#commands.joinForward) and [`joinBackward`](https://prosemirror.net/docs/ref/#commands.joinBackward) commands in the `prosemirror-commands` package. | ||
* | ||
* @public | ||
@@ -291,4 +323,4 @@ */ | ||
'Mod-]': Command; | ||
Backspace: Command; | ||
Delete: Command; | ||
Backspace: Command; | ||
}; | ||
@@ -295,0 +327,0 @@ |
@@ -659,2 +659,60 @@ // src/commands/dedent-list.ts | ||
// src/commands/join-list-backward.ts | ||
import { NodeRange as NodeRange4 } from "prosemirror-model"; | ||
// src/utils/at-textblock-start.ts | ||
function atTextblockStart(state, view) { | ||
const { $cursor } = state.selection; | ||
if (!$cursor || (view ? !view.endOfTextblock("backward", state) : $cursor.parentOffset > 0)) | ||
return null; | ||
return $cursor; | ||
} | ||
// src/commands/join-list-backward.ts | ||
var joinListBackward = (state, dispatch, view) => { | ||
const $cursor = atTextblockStart(state, view); | ||
if (!$cursor) | ||
return false; | ||
const { depth } = $cursor; | ||
if (depth < 2) | ||
return false; | ||
const listDepth = depth - 1; | ||
const listNode = $cursor.node(listDepth); | ||
if (!isListNode(listNode)) | ||
return false; | ||
const indexInList = $cursor.index(listDepth); | ||
if (indexInList === 0) { | ||
if (dispatch) { | ||
liftListContent(state, dispatch, $cursor); | ||
} | ||
return true; | ||
} | ||
if (indexInList === listNode.childCount - 1) { | ||
if (dispatch) { | ||
liftParent(state, dispatch, $cursor); | ||
} | ||
return true; | ||
} | ||
return false; | ||
}; | ||
function liftListContent(state, dispatch, $cursor) { | ||
const tr = state.tr; | ||
const listDepth = $cursor.depth - 1; | ||
const range = new NodeRange4( | ||
$cursor, | ||
tr.doc.resolve($cursor.end(listDepth)), | ||
listDepth | ||
); | ||
if (safeLift(tr, range)) { | ||
dispatch(tr); | ||
} | ||
} | ||
function liftParent(state, dispatch, $cursor) { | ||
const tr = state.tr; | ||
const range = $cursor.blockRange(); | ||
if (range && safeLift(tr, range)) { | ||
dispatch(tr); | ||
} | ||
} | ||
// src/commands/keymap.ts | ||
@@ -779,2 +837,9 @@ import { | ||
// src/commands/keymap.ts | ||
var backspaceCommand = chainCommands3( | ||
protectCollapsed, | ||
deleteSelection, | ||
joinListBackward, | ||
joinTextblockBackward, | ||
selectNodeBackward | ||
); | ||
var deleteCommand = chainCommands3( | ||
@@ -786,8 +851,2 @@ protectCollapsed, | ||
); | ||
var backspaceCommand = chainCommands3( | ||
protectCollapsed, | ||
deleteSelection, | ||
joinTextblockBackward, | ||
selectNodeBackward | ||
); | ||
var listKeymap = { | ||
@@ -797,4 +856,4 @@ Enter: createSplitListCommand(), | ||
"Mod-]": createIndentListCommand(), | ||
Delete: deleteCommand, | ||
Backspace: backspaceCommand | ||
Backspace: backspaceCommand, | ||
Delete: deleteCommand | ||
}; | ||
@@ -905,3 +964,3 @@ | ||
// src/commands/wrap-in-list.ts | ||
import { NodeRange as NodeRange4 } from "prosemirror-model"; | ||
import { NodeRange as NodeRange5 } from "prosemirror-model"; | ||
import { findWrapping } from "prosemirror-transform"; | ||
@@ -930,3 +989,3 @@ | ||
if (rangeAllowInlineContent(range) && isListNode(range.parent) && range.depth > 0) { | ||
range = new NodeRange4($from, $to, range.depth - 1); | ||
range = new NodeRange5($from, $to, range.depth - 1); | ||
} | ||
@@ -947,3 +1006,3 @@ const attrs = typeof getAttrs === "function" ? getAttrs(range) : getAttrs; | ||
} else { | ||
const range2 = new NodeRange4( | ||
const range2 = new NodeRange5( | ||
tr.doc.resolve($from.posAtIndex(i, depth) + 1), | ||
@@ -1271,2 +1330,3 @@ tr.doc.resolve($from.posAtIndex(i + 1, depth) - 1), | ||
alwaysTrue, | ||
backspaceCommand, | ||
createDedentListCommand, | ||
@@ -1287,2 +1347,3 @@ createIndentListCommand, | ||
defaultMarkerGetter, | ||
deleteCommand, | ||
doSplitList, | ||
@@ -1297,2 +1358,3 @@ enterWithoutLift, | ||
isListsRange, | ||
joinListBackward, | ||
joinListElements, | ||
@@ -1299,0 +1361,0 @@ listKeymap, |
{ | ||
"name": "prosemirror-flat-list", | ||
"type": "module", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Powerful list support for ProseMirror", | ||
@@ -37,3 +37,3 @@ "author": "ocavue <ocavue@gmail.com>", | ||
"dependencies": { | ||
"prosemirror-commands": "^1.5.0", | ||
"prosemirror-commands": "^1.5.1", | ||
"prosemirror-inputrules": "^1.2.0", | ||
@@ -53,4 +53,4 @@ "prosemirror-model": "^1.19.0", | ||
"@types/dedent": "^0.7.0", | ||
"@types/node": "^18.13.0", | ||
"@vitest/coverage-c8": "^0.28.5", | ||
"@types/node": "^18.14.2", | ||
"@vitest/coverage-c8": "^0.29.1", | ||
"dedent": "^0.7.0", | ||
@@ -74,4 +74,4 @@ "execa": "^7.0.0", | ||
"unified": "^10.1.2", | ||
"vite": "^4.1.1", | ||
"vitest": "^0.28.5" | ||
"vite": "^4.1.4", | ||
"vitest": "^0.29.1" | ||
}, | ||
@@ -78,0 +78,0 @@ "typedoc": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
138880
4471
Updatedprosemirror-commands@^1.5.1