prosemirror-flat-list
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -664,4 +664,4 @@ // src/commands/dedent-list.ts | ||
// src/commands/join-list-backward.ts | ||
import { NodeRange as NodeRange4 } from "prosemirror-model"; | ||
// src/commands/join-collapsed-backward.ts | ||
import { TextSelection as TextSelection2 } from "prosemirror-state"; | ||
@@ -676,7 +676,76 @@ // src/utils/at-textblock-start.ts | ||
// src/commands/join-list-backward.ts | ||
var joinListBackward = (state, dispatch, view) => { | ||
// src/commands/join-textblocks-around.ts | ||
import { Slice as Slice3 } from "prosemirror-model"; | ||
import { TextSelection } from "prosemirror-state"; | ||
import { replaceStep, ReplaceStep } from "prosemirror-transform"; | ||
function joinTextblocksAround(tr, $cut, dispatch) { | ||
let before = $cut.nodeBefore, beforeText = before, beforePos = $cut.pos - 1; | ||
for (; !beforeText.isTextblock; beforePos--) { | ||
if (beforeText.type.spec.isolating) | ||
return false; | ||
let child = beforeText.lastChild; | ||
if (!child) | ||
return false; | ||
beforeText = child; | ||
} | ||
let after = $cut.nodeAfter, afterText = after, afterPos = $cut.pos + 1; | ||
for (; !afterText.isTextblock; afterPos++) { | ||
if (afterText.type.spec.isolating) | ||
return false; | ||
let child = afterText.firstChild; | ||
if (!child) | ||
return false; | ||
afterText = child; | ||
} | ||
let step = replaceStep(tr.doc, beforePos, afterPos, Slice3.empty); | ||
if (!step || step.from != beforePos || step instanceof ReplaceStep && step.slice.size >= afterPos - beforePos) | ||
return false; | ||
if (dispatch) { | ||
tr.step(step); | ||
tr.setSelection(TextSelection.create(tr.doc, beforePos)); | ||
dispatch(tr.scrollIntoView()); | ||
} | ||
return true; | ||
} | ||
// src/commands/join-collapsed-backward.ts | ||
var joinCollapsedListBackward = (state, dispatch, view) => { | ||
const $cursor = atTextblockStart(state, view); | ||
if (!$cursor) | ||
return false; | ||
const $cut = findCutBefore($cursor); | ||
if (!$cut) | ||
return false; | ||
const { nodeBefore, nodeAfter } = $cut; | ||
if (nodeBefore && nodeAfter && isListNode(nodeBefore) && nodeBefore.attrs.collapsed && nodeAfter.isBlock) { | ||
const tr = state.tr; | ||
const listPos = $cut.pos - nodeBefore.nodeSize; | ||
tr.delete($cut.pos, $cut.pos + nodeAfter.nodeSize); | ||
const insert = listPos + 1 + nodeBefore.child(0).nodeSize; | ||
tr.insert(insert, nodeAfter); | ||
const $insert = tr.doc.resolve(insert); | ||
tr.setSelection(TextSelection2.near($insert)); | ||
if (joinTextblocksAround(tr, $insert, dispatch)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
function findCutBefore($pos) { | ||
if (!$pos.parent.type.spec.isolating) | ||
for (let i = $pos.depth - 1; i >= 0; i--) { | ||
if ($pos.index(i) > 0) | ||
return $pos.doc.resolve($pos.before(i + 1)); | ||
if ($pos.node(i).type.spec.isolating) | ||
break; | ||
} | ||
return null; | ||
} | ||
// src/commands/join-list-up.ts | ||
import { NodeRange as NodeRange4 } from "prosemirror-model"; | ||
var joinListUp = (state, dispatch, view) => { | ||
const $cursor = atTextblockStart(state, view); | ||
if (!$cursor) | ||
return false; | ||
const { depth } = $cursor; | ||
@@ -723,2 +792,3 @@ if (depth < 2) | ||
} | ||
var joinListBackward = joinListUp; | ||
@@ -871,3 +941,4 @@ // src/commands/keymap.ts | ||
deleteSelection, | ||
joinListBackward, | ||
joinListUp, | ||
joinCollapsedListBackward, | ||
joinTextblockBackward, | ||
@@ -959,3 +1030,3 @@ selectNodeBackward | ||
// src/commands/set-safe-selection.ts | ||
import { TextSelection } from "prosemirror-state"; | ||
import { TextSelection as TextSelection3 } from "prosemirror-state"; | ||
function moveOutOfCollapsed($pos, minDepth) { | ||
@@ -966,3 +1037,3 @@ for (let depth = minDepth; depth <= $pos.depth; depth++) { | ||
const $before = $pos.doc.resolve(before); | ||
return TextSelection.near($before, -1); | ||
return TextSelection3.near($before, -1); | ||
} | ||
@@ -1438,4 +1509,6 @@ } | ||
isListsRange, | ||
joinCollapsedListBackward, | ||
joinListBackward, | ||
joinListElements, | ||
joinListUp, | ||
listKeymap, | ||
@@ -1442,0 +1515,0 @@ listToDOM, |
@@ -34,3 +34,4 @@ import { Command } from 'prosemirror-state'; | ||
* - [deleteSelection](https://prosemirror.net/docs/ref/#commands.deleteSelection) | ||
* - {@link joinListBackward} | ||
* - {@link joinListUp} | ||
* - {@link joinCollapsedListBackward} | ||
* - [joinTextblockBackward](https://prosemirror.net/docs/ref/#commands.joinTextblockBackward) | ||
@@ -300,8 +301,17 @@ * - [selectNodeBackward](https://prosemirror.net/docs/ref/#commands.selectNodeBackward) | ||
/** | ||
* 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. | ||
* If the selection is empty and at the start of a block, and there is a | ||
* collapsed list node right before the cursor, move current block and append it | ||
* to the first child of the collapsed list node (i.e. skip the hidden content). | ||
* | ||
* @public | ||
*/ | ||
export declare const joinCollapsedListBackward: Command; | ||
/** | ||
* An alias to {@link joinListUp} | ||
* | ||
* @deprecated use joinListUp instead | ||
* | ||
* @public | ||
*/ | ||
export declare const joinListBackward: Command; | ||
@@ -316,2 +326,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 joinListUp: Command; | ||
/** @public */ | ||
@@ -318,0 +337,0 @@ export declare interface ListAttributes { |
@@ -664,4 +664,4 @@ // src/commands/dedent-list.ts | ||
// src/commands/join-list-backward.ts | ||
import { NodeRange as NodeRange4 } from "prosemirror-model"; | ||
// src/commands/join-collapsed-backward.ts | ||
import { TextSelection as TextSelection2 } from "prosemirror-state"; | ||
@@ -676,7 +676,76 @@ // src/utils/at-textblock-start.ts | ||
// src/commands/join-list-backward.ts | ||
var joinListBackward = (state, dispatch, view) => { | ||
// src/commands/join-textblocks-around.ts | ||
import { Slice as Slice3 } from "prosemirror-model"; | ||
import { TextSelection } from "prosemirror-state"; | ||
import { replaceStep, ReplaceStep } from "prosemirror-transform"; | ||
function joinTextblocksAround(tr, $cut, dispatch) { | ||
let before = $cut.nodeBefore, beforeText = before, beforePos = $cut.pos - 1; | ||
for (; !beforeText.isTextblock; beforePos--) { | ||
if (beforeText.type.spec.isolating) | ||
return false; | ||
let child = beforeText.lastChild; | ||
if (!child) | ||
return false; | ||
beforeText = child; | ||
} | ||
let after = $cut.nodeAfter, afterText = after, afterPos = $cut.pos + 1; | ||
for (; !afterText.isTextblock; afterPos++) { | ||
if (afterText.type.spec.isolating) | ||
return false; | ||
let child = afterText.firstChild; | ||
if (!child) | ||
return false; | ||
afterText = child; | ||
} | ||
let step = replaceStep(tr.doc, beforePos, afterPos, Slice3.empty); | ||
if (!step || step.from != beforePos || step instanceof ReplaceStep && step.slice.size >= afterPos - beforePos) | ||
return false; | ||
if (dispatch) { | ||
tr.step(step); | ||
tr.setSelection(TextSelection.create(tr.doc, beforePos)); | ||
dispatch(tr.scrollIntoView()); | ||
} | ||
return true; | ||
} | ||
// src/commands/join-collapsed-backward.ts | ||
var joinCollapsedListBackward = (state, dispatch, view) => { | ||
const $cursor = atTextblockStart(state, view); | ||
if (!$cursor) | ||
return false; | ||
const $cut = findCutBefore($cursor); | ||
if (!$cut) | ||
return false; | ||
const { nodeBefore, nodeAfter } = $cut; | ||
if (nodeBefore && nodeAfter && isListNode(nodeBefore) && nodeBefore.attrs.collapsed && nodeAfter.isBlock) { | ||
const tr = state.tr; | ||
const listPos = $cut.pos - nodeBefore.nodeSize; | ||
tr.delete($cut.pos, $cut.pos + nodeAfter.nodeSize); | ||
const insert = listPos + 1 + nodeBefore.child(0).nodeSize; | ||
tr.insert(insert, nodeAfter); | ||
const $insert = tr.doc.resolve(insert); | ||
tr.setSelection(TextSelection2.near($insert)); | ||
if (joinTextblocksAround(tr, $insert, dispatch)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
function findCutBefore($pos) { | ||
if (!$pos.parent.type.spec.isolating) | ||
for (let i = $pos.depth - 1; i >= 0; i--) { | ||
if ($pos.index(i) > 0) | ||
return $pos.doc.resolve($pos.before(i + 1)); | ||
if ($pos.node(i).type.spec.isolating) | ||
break; | ||
} | ||
return null; | ||
} | ||
// src/commands/join-list-up.ts | ||
import { NodeRange as NodeRange4 } from "prosemirror-model"; | ||
var joinListUp = (state, dispatch, view) => { | ||
const $cursor = atTextblockStart(state, view); | ||
if (!$cursor) | ||
return false; | ||
const { depth } = $cursor; | ||
@@ -723,2 +792,3 @@ if (depth < 2) | ||
} | ||
var joinListBackward = joinListUp; | ||
@@ -871,3 +941,4 @@ // src/commands/keymap.ts | ||
deleteSelection, | ||
joinListBackward, | ||
joinListUp, | ||
joinCollapsedListBackward, | ||
joinTextblockBackward, | ||
@@ -959,3 +1030,3 @@ selectNodeBackward | ||
// src/commands/set-safe-selection.ts | ||
import { TextSelection } from "prosemirror-state"; | ||
import { TextSelection as TextSelection3 } from "prosemirror-state"; | ||
function moveOutOfCollapsed($pos, minDepth) { | ||
@@ -966,3 +1037,3 @@ for (let depth = minDepth; depth <= $pos.depth; depth++) { | ||
const $before = $pos.doc.resolve(before); | ||
return TextSelection.near($before, -1); | ||
return TextSelection3.near($before, -1); | ||
} | ||
@@ -1438,4 +1509,6 @@ } | ||
isListsRange, | ||
joinCollapsedListBackward, | ||
joinListBackward, | ||
joinListElements, | ||
joinListUp, | ||
listKeymap, | ||
@@ -1442,0 +1515,0 @@ listToDOM, |
{ | ||
"name": "prosemirror-flat-list", | ||
"type": "module", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Powerful list support for ProseMirror", | ||
@@ -6,0 +6,0 @@ "author": "ocavue <ocavue@gmail.com>", |
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
156602
4978