prosemirror-transform
Advanced tools
Comparing version 0.21.1 to 0.22.0
@@ -38,3 +38,3 @@ var ref = require("prosemirror-model"); | ||
var slice = new Slice(mapFragment(oldSlice.content, function (node, parent, index) { | ||
if (!parent.contentMatchAt(index + 1).allowsMark(this$1.mark.type)) { return node } | ||
if (!parent.contentMatchAt(index).allowsMark(this$1.mark.type)) { return node } | ||
return node.mark(this$1.mark.addToSet(node.marks)) | ||
@@ -41,0 +41,0 @@ }, parent), oldSlice.openStart, oldSlice.openEnd) |
@@ -14,3 +14,3 @@ var ref = require("prosemirror-model"); | ||
// :: (number, number, Mark) → Transform | ||
// :: (number, number, Mark) → this | ||
// Add the given mark to the inline content between `from` and `to`. | ||
@@ -24,3 +24,3 @@ Transform.prototype.addMark = function(from, to, mark) { | ||
var marks = node.marks | ||
if (!mark.isInSet(marks) && parent.contentMatchAt(index + 1).allowsMark(mark.type)) { | ||
if (!mark.isInSet(marks) && parent.contentMatchAt(index).allowsMark(mark.type)) { | ||
var start = Math.max(pos, from), end = Math.min(pos + node.nodeSize, to) | ||
@@ -50,3 +50,3 @@ var newSet = mark.addToSet(marks) | ||
// :: (number, number, ?union<Mark, MarkType>) → Transform | ||
// :: (number, number, ?union<Mark, MarkType>) → this | ||
// Remove the given mark, or all marks of the given type, from inline | ||
@@ -92,3 +92,3 @@ // nodes between `from` and `to`. | ||
// :: (number, number) → Transform | ||
// :: (number, number) → this | ||
// Remove all marks and non-text inline nodes from the given range. | ||
@@ -95,0 +95,0 @@ Transform.prototype.clearMarkup = function(from, to) { |
@@ -13,3 +13,3 @@ var ref = require("prosemirror-model"); | ||
// :: (number, number, Slice) → Transform | ||
// :: (number, number, Slice) → this | ||
// Replace a range of the document with a given slice, using `from`, | ||
@@ -91,3 +91,3 @@ // `to`, and the slice's [`openStart`](#model.Slice.openStart) property | ||
// :: (number, number, Node) → Transform | ||
// :: (number, number, Node) → this | ||
// Replace the given range with a node, but use `from` and `to` as | ||
@@ -108,3 +108,3 @@ // hints, rather than precise positions. When from and to are the same | ||
// :: (number, number) → Transform | ||
// :: (number, number) → this | ||
// Delete the given range, expanding it to cover fully covered | ||
@@ -147,3 +147,3 @@ // parent nodes until a valid replace is found. | ||
// :: (number, number) → Transform | ||
// :: (number, number) → this | ||
// Delete the content between the given positions. | ||
@@ -182,3 +182,3 @@ Transform.prototype.delete = function(from, to) { | ||
// :: (number, ?number, ?Slice) → Transform | ||
// :: (number, ?number, ?Slice) → this | ||
// Replace the part of the document between `from` and `to` with the | ||
@@ -195,3 +195,3 @@ // given `slice`. | ||
// :: (number, number, union<Fragment, Node, [Node]>) → Transform | ||
// :: (number, number, union<Fragment, Node, [Node]>) → this | ||
// Replace the given range with the given content, which may be a | ||
@@ -203,3 +203,3 @@ // fragment, node, or array of nodes. | ||
// :: (number, union<Fragment, Node, [Node]>) → Transform | ||
// :: (number, union<Fragment, Node, [Node]>) → this | ||
// Insert the given content at the given position. | ||
@@ -206,0 +206,0 @@ Transform.prototype.insert = function(pos, content) { |
@@ -25,7 +25,6 @@ var ref = require("prosemirror-model"); | ||
var node = range.$from.node(depth) | ||
if (node.type.spec.isolating) { break } | ||
var index = range.$from.index(depth), endIndex = range.$to.indexAfter(depth) | ||
if (depth < range.depth && node.canReplace(index, endIndex, content)) | ||
{ return depth } | ||
if (depth == 0 || !canCut(node, index, endIndex)) { break } | ||
if (depth == 0 || node.type.spec.isolating || !canCut(node, index, endIndex)) { break } | ||
} | ||
@@ -35,3 +34,3 @@ } | ||
// :: (NodeRange, number) → Transform | ||
// :: (NodeRange, number) → this | ||
// Split the content in the given range off from its parent, if there | ||
@@ -117,3 +116,3 @@ // is sibling content before or after it, and move it up the tree to | ||
// :: (NodeRange, [{type: NodeType, attrs: ?Object}]) → Transform | ||
// :: (NodeRange, [{type: NodeType, attrs: ?Object}]) → this | ||
// Wrap the given [range](#model.NodeRange) in the given set of wrappers. | ||
@@ -131,3 +130,3 @@ // The wrappers are assumed to be valid in this position, and should | ||
// :: (number, ?number, NodeType, ?Object) → Transform | ||
// :: (number, ?number, NodeType, ?Object) → this | ||
// Set the type of all textblocks (partly) between `from` and `to` to | ||
@@ -155,3 +154,3 @@ // the given node type with the given attributes. | ||
// :: (number, ?NodeType, ?Object, ?[Mark]) → Transform | ||
// :: (number, ?NodeType, ?Object, ?[Mark]) → this | ||
// Change the type and attributes of the node after `pos`. | ||
@@ -179,12 +178,13 @@ Transform.prototype.setNodeType = function(pos, type, attrs, marks) { | ||
var $pos = doc.resolve(pos), base = $pos.depth - depth | ||
var innerType = typesAfter ? typesAfter[typesAfter.length - 1] : $pos.parent | ||
if (base < 0 || | ||
!$pos.parent.canReplace($pos.index(), $pos.parent.childCount) || | ||
!$pos.parent.canReplace(0, $pos.indexAfter())) | ||
!innerType.type.validContent($pos.parent.content.cutByIndex($pos.index(), $pos.parent.childCount), innerType.attrs)) | ||
{ return false } | ||
for (var d = $pos.depth - 1, i = depth - 1; d > base; d--, i--) { | ||
for (var d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) { | ||
var node = $pos.node(d), index$1 = $pos.index(d) | ||
var typeAfter = typesAfter && typesAfter[i] | ||
if (!node.canReplace(0, index$1) || | ||
!node.canReplaceWith(index$1, node.childCount, typeAfter ? typeAfter.type : $pos.node(d + 1).type, | ||
typeAfter ? typeAfter.attrs : $pos.node(d + 1).attrs)) | ||
var rest = node.content.cutByIndex(index$1, node.childCount) | ||
if (typesAfter) { rest = rest.replaceChild(0, typesAfter[i + 1].type.create(typesAfter[i].attrs)) } | ||
var after = typesAfter ? typesAfter[i] : node | ||
if (!node.canReplace(index$1 + 1, node.childCount) || !after.type.validContent(rest, after.attrs)) | ||
{ return false } | ||
@@ -199,3 +199,3 @@ } | ||
// :: (number, ?number, ?[?{type: NodeType, attrs: ?Object}]) → Transform | ||
// :: (number, ?number, ?[?{type: NodeType, attrs: ?Object}]) → this | ||
// Split the node at the given position, and optionally, if `depth` is | ||
@@ -259,3 +259,3 @@ // greater than one, any number of nodes above that. By default, the | ||
// :: (number, ?number, ?bool) → Transform | ||
// :: (number, ?number, ?bool) → this | ||
// Join the blocks around the given position. If depth is 2, their | ||
@@ -262,0 +262,0 @@ // last and first siblings are also joined, and so on. |
@@ -46,3 +46,3 @@ var ref = require("./map"); | ||
// :: (step: Step) → Transform | ||
// :: (step: Step) → this | ||
// Apply a new step in this transformation, saving the result. | ||
@@ -49,0 +49,0 @@ // Throws an error when the step fails. |
{ | ||
"name": "prosemirror-transform", | ||
"version": "0.21.1", | ||
"version": "0.22.0", | ||
"description": "ProseMirror document transformations", | ||
@@ -19,3 +19,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"prosemirror-model": "^0.21.0" | ||
"prosemirror-model": "^0.22.0" | ||
}, | ||
@@ -27,3 +27,3 @@ "devDependencies": { | ||
"rimraf": "^2.5.4", | ||
"prosemirror-test-builder": "^0.21.0" | ||
"prosemirror-test-builder": "^0.22.0" | ||
}, | ||
@@ -30,0 +30,0 @@ "scripts": { |
@@ -29,3 +29,3 @@ const {Fragment, Slice} = require("prosemirror-model") | ||
let slice = new Slice(mapFragment(oldSlice.content, (node, parent, index) => { | ||
if (!parent.contentMatchAt(index + 1).allowsMark(this.mark.type)) return node | ||
if (!parent.contentMatchAt(index).allowsMark(this.mark.type)) return node | ||
return node.mark(this.mark.addToSet(node.marks)) | ||
@@ -32,0 +32,0 @@ }, parent), oldSlice.openStart, oldSlice.openEnd) |
@@ -7,3 +7,3 @@ const {MarkType, Slice, Fragment} = require("prosemirror-model") | ||
// :: (number, number, Mark) → Transform | ||
// :: (number, number, Mark) → this | ||
// Add the given mark to the inline content between `from` and `to`. | ||
@@ -15,3 +15,3 @@ Transform.prototype.addMark = function(from, to, mark) { | ||
let marks = node.marks | ||
if (!mark.isInSet(marks) && parent.contentMatchAt(index + 1).allowsMark(mark.type)) { | ||
if (!mark.isInSet(marks) && parent.contentMatchAt(index).allowsMark(mark.type)) { | ||
let start = Math.max(pos, from), end = Math.min(pos + node.nodeSize, to) | ||
@@ -41,3 +41,3 @@ let newSet = mark.addToSet(marks) | ||
// :: (number, number, ?union<Mark, MarkType>) → Transform | ||
// :: (number, number, ?union<Mark, MarkType>) → this | ||
// Remove the given mark, or all marks of the given type, from inline | ||
@@ -80,3 +80,3 @@ // nodes between `from` and `to`. | ||
// :: (number, number) → Transform | ||
// :: (number, number) → this | ||
// Remove all marks and non-text inline nodes from the given range. | ||
@@ -83,0 +83,0 @@ Transform.prototype.clearMarkup = function(from, to) { |
@@ -7,3 +7,3 @@ const {Fragment, Slice} = require("prosemirror-model") | ||
// :: (number, number, Slice) → Transform | ||
// :: (number, number, Slice) → this | ||
// Replace a range of the document with a given slice, using `from`, | ||
@@ -83,3 +83,3 @@ // `to`, and the slice's [`openStart`](#model.Slice.openStart) property | ||
// :: (number, number, Node) → Transform | ||
// :: (number, number, Node) → this | ||
// Replace the given range with a node, but use `from` and `to` as | ||
@@ -100,3 +100,3 @@ // hints, rather than precise positions. When from and to are the same | ||
// :: (number, number) → Transform | ||
// :: (number, number) → this | ||
// Delete the given range, expanding it to cover fully covered | ||
@@ -139,3 +139,3 @@ // parent nodes until a valid replace is found. | ||
// :: (number, number) → Transform | ||
// :: (number, number) → this | ||
// Delete the content between the given positions. | ||
@@ -171,3 +171,3 @@ Transform.prototype.delete = function(from, to) { | ||
// :: (number, ?number, ?Slice) → Transform | ||
// :: (number, ?number, ?Slice) → this | ||
// Replace the part of the document between `from` and `to` with the | ||
@@ -181,3 +181,3 @@ // given `slice`. | ||
// :: (number, number, union<Fragment, Node, [Node]>) → Transform | ||
// :: (number, number, union<Fragment, Node, [Node]>) → this | ||
// Replace the given range with the given content, which may be a | ||
@@ -189,3 +189,3 @@ // fragment, node, or array of nodes. | ||
// :: (number, union<Fragment, Node, [Node]>) → Transform | ||
// :: (number, union<Fragment, Node, [Node]>) → this | ||
// Insert the given content at the given position. | ||
@@ -192,0 +192,0 @@ Transform.prototype.insert = function(pos, content) { |
@@ -20,7 +20,6 @@ const {Slice, Fragment} = require("prosemirror-model") | ||
let node = range.$from.node(depth) | ||
if (node.type.spec.isolating) break | ||
let index = range.$from.index(depth), endIndex = range.$to.indexAfter(depth) | ||
if (depth < range.depth && node.canReplace(index, endIndex, content)) | ||
return depth | ||
if (depth == 0 || !canCut(node, index, endIndex)) break | ||
if (depth == 0 || node.type.spec.isolating || !canCut(node, index, endIndex)) break | ||
} | ||
@@ -30,3 +29,3 @@ } | ||
// :: (NodeRange, number) → Transform | ||
// :: (NodeRange, number) → this | ||
// Split the content in the given range off from its parent, if there | ||
@@ -104,3 +103,3 @@ // is sibling content before or after it, and move it up the tree to | ||
// :: (NodeRange, [{type: NodeType, attrs: ?Object}]) → Transform | ||
// :: (NodeRange, [{type: NodeType, attrs: ?Object}]) → this | ||
// Wrap the given [range](#model.NodeRange) in the given set of wrappers. | ||
@@ -118,3 +117,3 @@ // The wrappers are assumed to be valid in this position, and should | ||
// :: (number, ?number, NodeType, ?Object) → Transform | ||
// :: (number, ?number, NodeType, ?Object) → this | ||
// Set the type of all textblocks (partly) between `from` and `to` to | ||
@@ -139,3 +138,3 @@ // the given node type with the given attributes. | ||
// :: (number, ?NodeType, ?Object, ?[Mark]) → Transform | ||
// :: (number, ?NodeType, ?Object, ?[Mark]) → this | ||
// Change the type and attributes of the node after `pos`. | ||
@@ -161,12 +160,13 @@ Transform.prototype.setNodeType = function(pos, type, attrs, marks) { | ||
let $pos = doc.resolve(pos), base = $pos.depth - depth | ||
let innerType = typesAfter ? typesAfter[typesAfter.length - 1] : $pos.parent | ||
if (base < 0 || | ||
!$pos.parent.canReplace($pos.index(), $pos.parent.childCount) || | ||
!$pos.parent.canReplace(0, $pos.indexAfter())) | ||
!innerType.type.validContent($pos.parent.content.cutByIndex($pos.index(), $pos.parent.childCount), innerType.attrs)) | ||
return false | ||
for (let d = $pos.depth - 1, i = depth - 1; d > base; d--, i--) { | ||
for (let d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) { | ||
let node = $pos.node(d), index = $pos.index(d) | ||
let typeAfter = typesAfter && typesAfter[i] | ||
if (!node.canReplace(0, index) || | ||
!node.canReplaceWith(index, node.childCount, typeAfter ? typeAfter.type : $pos.node(d + 1).type, | ||
typeAfter ? typeAfter.attrs : $pos.node(d + 1).attrs)) | ||
let rest = node.content.cutByIndex(index, node.childCount) | ||
if (typesAfter) rest = rest.replaceChild(0, typesAfter[i + 1].type.create(typesAfter[i].attrs)) | ||
let after = typesAfter ? typesAfter[i] : node | ||
if (!node.canReplace(index + 1, node.childCount) || !after.type.validContent(rest, after.attrs)) | ||
return false | ||
@@ -181,3 +181,3 @@ } | ||
// :: (number, ?number, ?[?{type: NodeType, attrs: ?Object}]) → Transform | ||
// :: (number, ?number, ?[?{type: NodeType, attrs: ?Object}]) → this | ||
// Split the node at the given position, and optionally, if `depth` is | ||
@@ -237,3 +237,3 @@ // greater than one, any number of nodes above that. By default, the | ||
// :: (number, ?number, ?bool) → Transform | ||
// :: (number, ?number, ?bool) → this | ||
// Join the blocks around the given position. If depth is 2, their | ||
@@ -240,0 +240,0 @@ // last and first siblings are also joined, and so on. |
@@ -36,3 +36,3 @@ const {Mapping} = require("./map") | ||
// :: (step: Step) → Transform | ||
// :: (step: Step) → this | ||
// Apply a new step in this transformation, saving the result. | ||
@@ -39,0 +39,0 @@ // Throws an error when the step fails. |
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
136571
+ Addedprosemirror-model@0.22.0(transitive)
- Removedprosemirror-model@0.21.0(transitive)
Updatedprosemirror-model@^0.22.0