prosemirror-flat-list
Advanced tools
Comparing version 0.3.3 to 0.3.4
@@ -22,2 +22,16 @@ // src/commands/dedent-list.ts | ||
{ | ||
tag: "div[data-list-kind]", | ||
getAttrs: (element) => { | ||
if (typeof element === "string") { | ||
return {}; | ||
} | ||
return { | ||
kind: element.getAttribute("data-list-kind") || "bullet", | ||
order: parseInteger(element.getAttribute("data-list-order")), | ||
checked: element.hasAttribute("data-list-checked"), | ||
collapsed: element.hasAttribute("data-list-collapsed") | ||
}; | ||
} | ||
}, | ||
{ | ||
tag: "div[data-list]", | ||
@@ -448,33 +462,33 @@ getAttrs: (element) => { | ||
if (isListNode(range.parent)) { | ||
return safeLift(tr, range); | ||
return safeLiftRange(tr, range); | ||
} else if (isListsRange(range)) { | ||
return dedentOutOfList(tr, range); | ||
} else { | ||
return safeLift(tr, range); | ||
return safeLiftRange(tr, range); | ||
} | ||
} | ||
function fixEndBoundary(range, tr) { | ||
function safeLiftRange(tr, range) { | ||
if (moveRangeSiblings(tr, range)) { | ||
const $from = tr.doc.resolve(range.$from.pos); | ||
const $to = tr.doc.resolve(range.$to.pos); | ||
range = new NodeRange2($from, $to, range.depth); | ||
} | ||
return safeLift(tr, range); | ||
} | ||
function moveRangeSiblings(tr, range) { | ||
const listType = getListType(tr.doc.type.schema); | ||
if (range.endIndex - range.startIndex >= 2) { | ||
range = new NodeRange2( | ||
range.$to.doc.resolve( | ||
range.$to.posAtIndex(range.endIndex - 1, range.depth) | ||
), | ||
range.$to, | ||
range.depth | ||
); | ||
} | ||
const contentRange = zoomInRange(range); | ||
if (contentRange) { | ||
fixEndBoundary(contentRange, tr); | ||
range = new NodeRange2( | ||
tr.doc.resolve(range.$from.pos), | ||
tr.doc.resolve(range.$to.pos), | ||
range.depth | ||
); | ||
} | ||
const { $to, depth, end, parent, endIndex } = range; | ||
const endOfParent = $to.end(depth); | ||
if (end < endOfParent) { | ||
if (isListNode(parent.maybeChild(endIndex - 1))) { | ||
const lastChild = parent.maybeChild(endIndex - 1); | ||
if (!lastChild) | ||
return false; | ||
const canAppend = endIndex < parent.childCount && lastChild.canReplace( | ||
lastChild.childCount, | ||
lastChild.childCount, | ||
parent.content, | ||
endIndex, | ||
parent.childCount | ||
); | ||
if (canAppend) { | ||
tr.step( | ||
@@ -491,2 +505,3 @@ new ReplaceAroundStep( | ||
); | ||
return true; | ||
} else { | ||
@@ -504,5 +519,28 @@ tr.step( | ||
); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
function fixEndBoundary(range, tr) { | ||
if (range.endIndex - range.startIndex >= 2) { | ||
range = new NodeRange2( | ||
range.$to.doc.resolve( | ||
range.$to.posAtIndex(range.endIndex - 1, range.depth) | ||
), | ||
range.$to, | ||
range.depth | ||
); | ||
} | ||
const contentRange = zoomInRange(range); | ||
if (contentRange) { | ||
fixEndBoundary(contentRange, tr); | ||
range = new NodeRange2( | ||
tr.doc.resolve(range.$from.pos), | ||
tr.doc.resolve(range.$to.pos), | ||
range.depth | ||
); | ||
} | ||
moveRangeSiblings(tr, range); | ||
} | ||
function dedentOutOfList(tr, range) { | ||
@@ -509,0 +547,0 @@ const { startIndex, endIndex, parent } = range; |
@@ -22,2 +22,16 @@ // src/commands/dedent-list.ts | ||
{ | ||
tag: "div[data-list-kind]", | ||
getAttrs: (element) => { | ||
if (typeof element === "string") { | ||
return {}; | ||
} | ||
return { | ||
kind: element.getAttribute("data-list-kind") || "bullet", | ||
order: parseInteger(element.getAttribute("data-list-order")), | ||
checked: element.hasAttribute("data-list-checked"), | ||
collapsed: element.hasAttribute("data-list-collapsed") | ||
}; | ||
} | ||
}, | ||
{ | ||
tag: "div[data-list]", | ||
@@ -448,33 +462,33 @@ getAttrs: (element) => { | ||
if (isListNode(range.parent)) { | ||
return safeLift(tr, range); | ||
return safeLiftRange(tr, range); | ||
} else if (isListsRange(range)) { | ||
return dedentOutOfList(tr, range); | ||
} else { | ||
return safeLift(tr, range); | ||
return safeLiftRange(tr, range); | ||
} | ||
} | ||
function fixEndBoundary(range, tr) { | ||
function safeLiftRange(tr, range) { | ||
if (moveRangeSiblings(tr, range)) { | ||
const $from = tr.doc.resolve(range.$from.pos); | ||
const $to = tr.doc.resolve(range.$to.pos); | ||
range = new NodeRange2($from, $to, range.depth); | ||
} | ||
return safeLift(tr, range); | ||
} | ||
function moveRangeSiblings(tr, range) { | ||
const listType = getListType(tr.doc.type.schema); | ||
if (range.endIndex - range.startIndex >= 2) { | ||
range = new NodeRange2( | ||
range.$to.doc.resolve( | ||
range.$to.posAtIndex(range.endIndex - 1, range.depth) | ||
), | ||
range.$to, | ||
range.depth | ||
); | ||
} | ||
const contentRange = zoomInRange(range); | ||
if (contentRange) { | ||
fixEndBoundary(contentRange, tr); | ||
range = new NodeRange2( | ||
tr.doc.resolve(range.$from.pos), | ||
tr.doc.resolve(range.$to.pos), | ||
range.depth | ||
); | ||
} | ||
const { $to, depth, end, parent, endIndex } = range; | ||
const endOfParent = $to.end(depth); | ||
if (end < endOfParent) { | ||
if (isListNode(parent.maybeChild(endIndex - 1))) { | ||
const lastChild = parent.maybeChild(endIndex - 1); | ||
if (!lastChild) | ||
return false; | ||
const canAppend = endIndex < parent.childCount && lastChild.canReplace( | ||
lastChild.childCount, | ||
lastChild.childCount, | ||
parent.content, | ||
endIndex, | ||
parent.childCount | ||
); | ||
if (canAppend) { | ||
tr.step( | ||
@@ -491,2 +505,3 @@ new ReplaceAroundStep( | ||
); | ||
return true; | ||
} else { | ||
@@ -504,5 +519,28 @@ tr.step( | ||
); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
function fixEndBoundary(range, tr) { | ||
if (range.endIndex - range.startIndex >= 2) { | ||
range = new NodeRange2( | ||
range.$to.doc.resolve( | ||
range.$to.posAtIndex(range.endIndex - 1, range.depth) | ||
), | ||
range.$to, | ||
range.depth | ||
); | ||
} | ||
const contentRange = zoomInRange(range); | ||
if (contentRange) { | ||
fixEndBoundary(contentRange, tr); | ||
range = new NodeRange2( | ||
tr.doc.resolve(range.$from.pos), | ||
tr.doc.resolve(range.$to.pos), | ||
range.depth | ||
); | ||
} | ||
moveRangeSiblings(tr, range); | ||
} | ||
function dedentOutOfList(tr, range) { | ||
@@ -509,0 +547,0 @@ const { startIndex, endIndex, parent } = range; |
{ | ||
"name": "prosemirror-flat-list", | ||
"type": "module", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"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
159866
5054