prosemirror-flat-list
Advanced tools
Comparing version 0.0.16 to 0.0.17
@@ -650,73 +650,12 @@ // src/commands/dedent-list.ts | ||
// src/utils/cut-by-index.ts | ||
function cutByIndex(fragment, from, to) { | ||
return fragment.cutByIndex(from, to); | ||
} | ||
// src/commands/keymap.ts | ||
import { | ||
chainCommands as chainCommands3, | ||
deleteSelection, | ||
joinTextblockBackward, | ||
joinTextblockForward, | ||
selectNodeBackward, | ||
selectNodeForward | ||
} from "prosemirror-commands"; | ||
// src/commands/move-list.ts | ||
function createMoveListCommand(direction) { | ||
const moveList = (state, dispatch) => { | ||
const tr = state.tr; | ||
if (doMoveList(state.tr, direction, true, !!dispatch)) { | ||
if (dispatch) { | ||
autoJoinList(tr); | ||
dispatch(tr); | ||
} | ||
return true; | ||
} | ||
return false; | ||
}; | ||
return moveList; | ||
} | ||
function doMoveList(tr, direction, canDedent, dispatch) { | ||
const { $from, $to } = tr.selection; | ||
const range = findListsRange($from, $to); | ||
if (!range) | ||
return false; | ||
const { parent, depth, startIndex, endIndex } = range; | ||
if (direction === "up") { | ||
if (startIndex >= 2 || startIndex === 1 && isListNode(parent.child(0))) { | ||
const before = cutByIndex(parent.content, startIndex - 1, startIndex); | ||
const selected = cutByIndex(parent.content, startIndex, endIndex); | ||
if (parent.canReplace(startIndex - 1, endIndex, selected.append(before))) { | ||
if (dispatch) { | ||
tr.insert($from.posAtIndex(endIndex, depth), before); | ||
tr.delete( | ||
$from.posAtIndex(startIndex - 1, depth), | ||
$from.posAtIndex(startIndex, depth) | ||
); | ||
} | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} else if (canDedent && isListNode(parent)) { | ||
return safeLift(tr, range) && doMoveList(tr, direction, false, dispatch); | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
if (endIndex < parent.childCount) { | ||
const selected = cutByIndex(parent.content, startIndex, endIndex); | ||
const after = cutByIndex(parent.content, endIndex, endIndex + 1); | ||
if (parent.canReplace(startIndex, endIndex + 1, after.append(selected))) { | ||
if (dispatch) { | ||
tr.delete( | ||
$from.posAtIndex(endIndex, depth), | ||
$from.posAtIndex(endIndex + 1, depth) | ||
); | ||
tr.insert($from.posAtIndex(startIndex, depth), after); | ||
} | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} else if (canDedent && isListNode(parent)) { | ||
return safeLift(tr, range) && doMoveList(tr, direction, false, dispatch); | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
// src/commands/protect-collapsed.ts | ||
@@ -825,2 +764,94 @@ var protectCollapsed = (state, dispatch) => { | ||
// src/commands/keymap.ts | ||
var deleteCommand = chainCommands3( | ||
protectCollapsed, | ||
deleteSelection, | ||
joinTextblockForward, | ||
selectNodeForward | ||
); | ||
var backspaceCommand = chainCommands3( | ||
protectCollapsed, | ||
deleteSelection, | ||
joinTextblockBackward, | ||
selectNodeBackward | ||
); | ||
var listKeymap = { | ||
Enter: createSplitListCommand(), | ||
"Mod-[": createDedentListCommand(), | ||
"Mod-]": createIndentListCommand(), | ||
Delete: deleteCommand, | ||
Backspace: backspaceCommand | ||
}; | ||
// src/utils/cut-by-index.ts | ||
function cutByIndex(fragment, from, to) { | ||
return fragment.cutByIndex(from, to); | ||
} | ||
// src/commands/move-list.ts | ||
function createMoveListCommand(direction) { | ||
const moveList = (state, dispatch) => { | ||
const tr = state.tr; | ||
if (doMoveList(state.tr, direction, true, !!dispatch)) { | ||
if (dispatch) { | ||
autoJoinList(tr); | ||
dispatch(tr); | ||
} | ||
return true; | ||
} | ||
return false; | ||
}; | ||
return moveList; | ||
} | ||
function doMoveList(tr, direction, canDedent, dispatch) { | ||
const { $from, $to } = tr.selection; | ||
const range = findListsRange($from, $to); | ||
if (!range) | ||
return false; | ||
const { parent, depth, startIndex, endIndex } = range; | ||
if (direction === "up") { | ||
if (startIndex >= 2 || startIndex === 1 && isListNode(parent.child(0))) { | ||
const before = cutByIndex(parent.content, startIndex - 1, startIndex); | ||
const selected = cutByIndex(parent.content, startIndex, endIndex); | ||
if (parent.canReplace(startIndex - 1, endIndex, selected.append(before))) { | ||
if (dispatch) { | ||
tr.insert($from.posAtIndex(endIndex, depth), before); | ||
tr.delete( | ||
$from.posAtIndex(startIndex - 1, depth), | ||
$from.posAtIndex(startIndex, depth) | ||
); | ||
} | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} else if (canDedent && isListNode(parent)) { | ||
return safeLift(tr, range) && doMoveList(tr, direction, false, dispatch); | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
if (endIndex < parent.childCount) { | ||
const selected = cutByIndex(parent.content, startIndex, endIndex); | ||
const after = cutByIndex(parent.content, endIndex, endIndex + 1); | ||
if (parent.canReplace(startIndex, endIndex + 1, after.append(selected))) { | ||
if (dispatch) { | ||
tr.delete( | ||
$from.posAtIndex(endIndex, depth), | ||
$from.posAtIndex(endIndex + 1, depth) | ||
); | ||
tr.insert($from.posAtIndex(startIndex, depth), after); | ||
} | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} else if (canDedent && isListNode(parent)) { | ||
return safeLift(tr, range) && doMoveList(tr, direction, false, dispatch); | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
// src/commands/wrap-in-list.ts | ||
@@ -1133,2 +1164,3 @@ import { NodeRange as NodeRange4 } from "prosemirror-model"; | ||
isListType, | ||
listKeymap, | ||
listToDOM, | ||
@@ -1135,0 +1167,0 @@ migrateDocJSON, |
@@ -140,2 +140,23 @@ import { Attrs } from 'prosemirror-model'; | ||
/** | ||
* Returns an object containing the keymap for the list commands. | ||
* | ||
* - `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. | ||
* | ||
* 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 | ||
*/ | ||
export declare const listKeymap: { | ||
Enter: Command; | ||
'Mod-[': Command; | ||
'Mod-]': Command; | ||
Delete: Command; | ||
Backspace: Command; | ||
}; | ||
/** @public */ | ||
@@ -142,0 +163,0 @@ export declare function listToDOM({ node, nativeList, markerToDOM, }: ListToDOMProps): DOMOutputSpec; |
@@ -650,73 +650,12 @@ // src/commands/dedent-list.ts | ||
// src/utils/cut-by-index.ts | ||
function cutByIndex(fragment, from, to) { | ||
return fragment.cutByIndex(from, to); | ||
} | ||
// src/commands/keymap.ts | ||
import { | ||
chainCommands as chainCommands3, | ||
deleteSelection, | ||
joinTextblockBackward, | ||
joinTextblockForward, | ||
selectNodeBackward, | ||
selectNodeForward | ||
} from "prosemirror-commands"; | ||
// src/commands/move-list.ts | ||
function createMoveListCommand(direction) { | ||
const moveList = (state, dispatch) => { | ||
const tr = state.tr; | ||
if (doMoveList(state.tr, direction, true, !!dispatch)) { | ||
if (dispatch) { | ||
autoJoinList(tr); | ||
dispatch(tr); | ||
} | ||
return true; | ||
} | ||
return false; | ||
}; | ||
return moveList; | ||
} | ||
function doMoveList(tr, direction, canDedent, dispatch) { | ||
const { $from, $to } = tr.selection; | ||
const range = findListsRange($from, $to); | ||
if (!range) | ||
return false; | ||
const { parent, depth, startIndex, endIndex } = range; | ||
if (direction === "up") { | ||
if (startIndex >= 2 || startIndex === 1 && isListNode(parent.child(0))) { | ||
const before = cutByIndex(parent.content, startIndex - 1, startIndex); | ||
const selected = cutByIndex(parent.content, startIndex, endIndex); | ||
if (parent.canReplace(startIndex - 1, endIndex, selected.append(before))) { | ||
if (dispatch) { | ||
tr.insert($from.posAtIndex(endIndex, depth), before); | ||
tr.delete( | ||
$from.posAtIndex(startIndex - 1, depth), | ||
$from.posAtIndex(startIndex, depth) | ||
); | ||
} | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} else if (canDedent && isListNode(parent)) { | ||
return safeLift(tr, range) && doMoveList(tr, direction, false, dispatch); | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
if (endIndex < parent.childCount) { | ||
const selected = cutByIndex(parent.content, startIndex, endIndex); | ||
const after = cutByIndex(parent.content, endIndex, endIndex + 1); | ||
if (parent.canReplace(startIndex, endIndex + 1, after.append(selected))) { | ||
if (dispatch) { | ||
tr.delete( | ||
$from.posAtIndex(endIndex, depth), | ||
$from.posAtIndex(endIndex + 1, depth) | ||
); | ||
tr.insert($from.posAtIndex(startIndex, depth), after); | ||
} | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} else if (canDedent && isListNode(parent)) { | ||
return safeLift(tr, range) && doMoveList(tr, direction, false, dispatch); | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
// src/commands/protect-collapsed.ts | ||
@@ -825,2 +764,94 @@ var protectCollapsed = (state, dispatch) => { | ||
// src/commands/keymap.ts | ||
var deleteCommand = chainCommands3( | ||
protectCollapsed, | ||
deleteSelection, | ||
joinTextblockForward, | ||
selectNodeForward | ||
); | ||
var backspaceCommand = chainCommands3( | ||
protectCollapsed, | ||
deleteSelection, | ||
joinTextblockBackward, | ||
selectNodeBackward | ||
); | ||
var listKeymap = { | ||
Enter: createSplitListCommand(), | ||
"Mod-[": createDedentListCommand(), | ||
"Mod-]": createIndentListCommand(), | ||
Delete: deleteCommand, | ||
Backspace: backspaceCommand | ||
}; | ||
// src/utils/cut-by-index.ts | ||
function cutByIndex(fragment, from, to) { | ||
return fragment.cutByIndex(from, to); | ||
} | ||
// src/commands/move-list.ts | ||
function createMoveListCommand(direction) { | ||
const moveList = (state, dispatch) => { | ||
const tr = state.tr; | ||
if (doMoveList(state.tr, direction, true, !!dispatch)) { | ||
if (dispatch) { | ||
autoJoinList(tr); | ||
dispatch(tr); | ||
} | ||
return true; | ||
} | ||
return false; | ||
}; | ||
return moveList; | ||
} | ||
function doMoveList(tr, direction, canDedent, dispatch) { | ||
const { $from, $to } = tr.selection; | ||
const range = findListsRange($from, $to); | ||
if (!range) | ||
return false; | ||
const { parent, depth, startIndex, endIndex } = range; | ||
if (direction === "up") { | ||
if (startIndex >= 2 || startIndex === 1 && isListNode(parent.child(0))) { | ||
const before = cutByIndex(parent.content, startIndex - 1, startIndex); | ||
const selected = cutByIndex(parent.content, startIndex, endIndex); | ||
if (parent.canReplace(startIndex - 1, endIndex, selected.append(before))) { | ||
if (dispatch) { | ||
tr.insert($from.posAtIndex(endIndex, depth), before); | ||
tr.delete( | ||
$from.posAtIndex(startIndex - 1, depth), | ||
$from.posAtIndex(startIndex, depth) | ||
); | ||
} | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} else if (canDedent && isListNode(parent)) { | ||
return safeLift(tr, range) && doMoveList(tr, direction, false, dispatch); | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
if (endIndex < parent.childCount) { | ||
const selected = cutByIndex(parent.content, startIndex, endIndex); | ||
const after = cutByIndex(parent.content, endIndex, endIndex + 1); | ||
if (parent.canReplace(startIndex, endIndex + 1, after.append(selected))) { | ||
if (dispatch) { | ||
tr.delete( | ||
$from.posAtIndex(endIndex, depth), | ||
$from.posAtIndex(endIndex + 1, depth) | ||
); | ||
tr.insert($from.posAtIndex(startIndex, depth), after); | ||
} | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} else if (canDedent && isListNode(parent)) { | ||
return safeLift(tr, range) && doMoveList(tr, direction, false, dispatch); | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
// src/commands/wrap-in-list.ts | ||
@@ -1133,2 +1164,3 @@ import { NodeRange as NodeRange4 } from "prosemirror-model"; | ||
isListType, | ||
listKeymap, | ||
listToDOM, | ||
@@ -1135,0 +1167,0 @@ migrateDocJSON, |
{ | ||
"name": "prosemirror-flat-list", | ||
"type": "module", | ||
"version": "0.0.16", | ||
"version": "0.0.17", | ||
"description": "", | ||
@@ -64,3 +64,3 @@ "author": "ocavue <ocavue@gmail.com>", | ||
"remirror": "^2.0.24", | ||
"tsup": "^6.6.2", | ||
"tsup": "^6.6.3", | ||
"typescript": "^4.9.5", | ||
@@ -67,0 +67,0 @@ "unified": "^10.1.2", |
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
116007
3698