prosemirror-model
Advanced tools
Comparing version 0.14.1 to 0.15.0
@@ -113,3 +113,3 @@ var ref = require("./diff"); | ||
// (Node) → Fragment | ||
// : (Node) → Fragment | ||
// Create a new fragment by prepending the given node to this | ||
@@ -121,3 +121,3 @@ // fragment. | ||
// (Node) → Fragment | ||
// : (Node) → Fragment | ||
// Create a new fragment by appending the given node to this | ||
@@ -124,0 +124,0 @@ // fragment. |
@@ -31,2 +31,9 @@ var ref = require("./fragment"); | ||
// | ||
// priority:: ?number | ||
// Can be used to change the order in which the parse rules in a | ||
// schema are tried. Those with higher priority come first. Rules | ||
// without a priority are counted as having priority 50. This | ||
// property is only meaningful in a schema—when directly | ||
// constructing a parser, the order of the rule array is used. | ||
// | ||
// ignore:: ?bool | ||
@@ -179,6 +186,15 @@ // When true, ignore content that matches this rule. | ||
var result = [] | ||
function insert(rule) { | ||
var priority = rule.priority == null ? 50 : rule.priority, i = 0 | ||
for (; i < result.length; i++) { | ||
var next = result[i], nextPriority = next.priority == null ? 50 : next.priority | ||
if (nextPriority < priority) { break } | ||
} | ||
result.splice(i, 0, rule) | ||
} | ||
var loop = function ( name ) { | ||
var rules = schema.marks[name].spec.parseDOM | ||
if (rules) { rules.forEach(function (rule) { | ||
result.push(rule = copy(rule)) | ||
insert(rule = copy(rule)) | ||
rule.mark = name | ||
@@ -192,3 +208,3 @@ }) } | ||
if (rules$1) { rules$1.forEach(function (rule) { | ||
result.push(rule = copy(rule)) | ||
insert(rule = copy(rule)) | ||
rule.node = name$1 | ||
@@ -195,0 +211,0 @@ }) } |
@@ -253,3 +253,3 @@ var ref = require("./fragment"); | ||
// When inside a text node or at the start of the parent node, return the node's marks | ||
if (useAfter || index == 0 || !$pos.atNodeBoundary) { return parent.child(index).marks } | ||
if (useAfter || index == 0 || $pos.textOffset) { return parent.child(index).marks } | ||
@@ -256,0 +256,0 @@ var marks = parent.child(index - 1).marks |
@@ -133,3 +133,8 @@ var ref = require("./fragment"); | ||
return node.copy(node.content.replaceChild(index, inner)) | ||
} else if (slice.content.size) { | ||
} else if (!slice.content.size) { | ||
return close(node, replaceTwoWay($from, $to, depth)) | ||
} else if (!slice.openLeft && !slice.openRight && $from.depth == depth && $to.depth == depth) { // Simple, flat case | ||
var parent = $from.parent, content = parent.content | ||
return close(parent, content.cut(0, $from.parentOffset).append(slice.content).append(content.cut($to.parentOffset))) | ||
} else { | ||
var ref = prepareSliceForReplace(slice, $from); | ||
@@ -139,4 +144,2 @@ var start = ref.start; | ||
return close(node, replaceThreeWay($from, start, end, $to, depth)) | ||
} else { | ||
return close(node, replaceTwoWay($from, $to, depth)) | ||
} | ||
@@ -171,3 +174,3 @@ } | ||
startIndex++ | ||
} else if (!$start.atNodeBoundary) { | ||
} else if ($start.textOffset) { | ||
addNode($start.nodeAfter, target) | ||
@@ -178,3 +181,3 @@ startIndex++ | ||
for (var i = startIndex; i < endIndex; i++) { addNode(node.child(i), target) } | ||
if ($end && $end.depth == depth && !$end.atNodeBoundary) | ||
if ($end && $end.depth == depth && $end.textOffset) | ||
{ addNode($end.nodeBefore, target) } | ||
@@ -181,0 +184,0 @@ } |
@@ -0,1 +1,3 @@ | ||
var warnedAboutBoundary = false | ||
// ::- You'll often have to '[resolve](#model.Node.resolve)' a | ||
@@ -22,3 +24,3 @@ // position to get the context you need. Objects of this class | ||
var prototypeAccessors = { parent: {},atNodeBoundary: {},nodeAfter: {},nodeBefore: {} }; | ||
var prototypeAccessors = { parent: {},atNodeBoundary: {},textOffset: {},nodeAfter: {},nodeBefore: {} }; | ||
@@ -53,3 +55,3 @@ ResolvedPos.prototype.resolveDepth = function resolveDepth (val) { | ||
depth = this.resolveDepth(depth) | ||
return this.index(depth) + (depth == this.depth && this.atNodeBoundary ? 0 : 1) | ||
return this.index(depth) + (depth == this.depth && !this.textOffset ? 0 : 1) | ||
}; | ||
@@ -93,7 +95,16 @@ | ||
// :: bool | ||
// True if this position points at a node boundary, false if it | ||
// points into a text node. | ||
prototypeAccessors.atNodeBoundary.get = function () { return this.path[this.path.length - 1] == this.pos }; | ||
prototypeAccessors.atNodeBoundary.get = function () { | ||
if (!warnedAboutBoundary && typeof console != "undefined") { | ||
warnedAboutBoundary = true | ||
console.warn("ResolvedPos.atNodeBoundary is deprecated. Use textOffset > 0 instead") | ||
} | ||
return !this.textOffset | ||
}; | ||
// :: number | ||
// When this position points into a text node, this returns the | ||
// distance between the position and the start of the text node. | ||
// Will be zero for positions that point between nodes. | ||
prototypeAccessors.textOffset.get = function () { return this.pos - this.path[this.path.length - 1] }; | ||
// :: ?Node | ||
@@ -100,0 +111,0 @@ // Get the node directly after the position, if any. If the position |
@@ -368,3 +368,3 @@ var ref = require("./node"); | ||
this.nodeSpec = OrderedMap.from(spec.nodes) | ||
// :: OrderedMap<constructor<MarkType>> The mark spec that the schema is based on. | ||
// :: OrderedMap<MarkSpec> The mark spec that the schema is based on. | ||
this.markSpec = OrderedMap.from(spec.marks) | ||
@@ -371,0 +371,0 @@ |
{ | ||
"name": "prosemirror-model", | ||
"version": "0.14.1", | ||
"version": "0.15.0", | ||
"description": "ProseMirror's document model", | ||
@@ -28,5 +28,4 @@ "main": "dist/index.js", | ||
"build": "rimraf dist && buble -i src -o dist", | ||
"link-src": "rimraf dist && ln -s src dist", | ||
"prepublish": "npm run build" | ||
} | ||
} |
@@ -104,3 +104,3 @@ const {findDiffStart, findDiffEnd} = require("./diff") | ||
// (Node) → Fragment | ||
// : (Node) → Fragment | ||
// Create a new fragment by prepending the given node to this | ||
@@ -112,3 +112,3 @@ // fragment. | ||
// (Node) → Fragment | ||
// : (Node) → Fragment | ||
// Create a new fragment by appending the given node to this | ||
@@ -115,0 +115,0 @@ // fragment. |
@@ -28,2 +28,9 @@ const {Fragment} = require("./fragment") | ||
// | ||
// priority:: ?number | ||
// Can be used to change the order in which the parse rules in a | ||
// schema are tried. Those with higher priority come first. Rules | ||
// without a priority are counted as having priority 50. This | ||
// property is only meaningful in a schema—when directly | ||
// constructing a parser, the order of the rule array is used. | ||
// | ||
// ignore:: ?bool | ||
@@ -170,6 +177,15 @@ // When true, ignore content that matches this rule. | ||
let result = [] | ||
function insert(rule) { | ||
let priority = rule.priority == null ? 50 : rule.priority, i = 0 | ||
for (; i < result.length; i++) { | ||
let next = result[i], nextPriority = next.priority == null ? 50 : next.priority | ||
if (nextPriority < priority) break | ||
} | ||
result.splice(i, 0, rule) | ||
} | ||
for (let name in schema.marks) { | ||
let rules = schema.marks[name].spec.parseDOM | ||
if (rules) rules.forEach(rule => { | ||
result.push(rule = copy(rule)) | ||
insert(rule = copy(rule)) | ||
rule.mark = name | ||
@@ -181,3 +197,3 @@ }) | ||
if (rules) rules.forEach(rule => { | ||
result.push(rule = copy(rule)) | ||
insert(rule = copy(rule)) | ||
rule.node = name | ||
@@ -184,0 +200,0 @@ }) |
@@ -233,3 +233,3 @@ const {Fragment} = require("./fragment") | ||
// When inside a text node or at the start of the parent node, return the node's marks | ||
if (useAfter || index == 0 || !$pos.atNodeBoundary) return parent.child(index).marks | ||
if (useAfter || index == 0 || $pos.textOffset) return parent.child(index).marks | ||
@@ -236,0 +236,0 @@ let marks = parent.child(index - 1).marks |
@@ -117,7 +117,10 @@ const {Fragment} = require("./fragment") | ||
return node.copy(node.content.replaceChild(index, inner)) | ||
} else if (slice.content.size) { | ||
} else if (!slice.content.size) { | ||
return close(node, replaceTwoWay($from, $to, depth)) | ||
} else if (!slice.openLeft && !slice.openRight && $from.depth == depth && $to.depth == depth) { // Simple, flat case | ||
let parent = $from.parent, content = parent.content | ||
return close(parent, content.cut(0, $from.parentOffset).append(slice.content).append(content.cut($to.parentOffset))) | ||
} else { | ||
let {start, end} = prepareSliceForReplace(slice, $from) | ||
return close(node, replaceThreeWay($from, start, end, $to, depth)) | ||
} else { | ||
return close(node, replaceTwoWay($from, $to, depth)) | ||
} | ||
@@ -152,3 +155,3 @@ } | ||
startIndex++ | ||
} else if (!$start.atNodeBoundary) { | ||
} else if ($start.textOffset) { | ||
addNode($start.nodeAfter, target) | ||
@@ -159,3 +162,3 @@ startIndex++ | ||
for (let i = startIndex; i < endIndex; i++) addNode(node.child(i), target) | ||
if ($end && $end.depth == depth && !$end.atNodeBoundary) | ||
if ($end && $end.depth == depth && $end.textOffset) | ||
addNode($end.nodeBefore, target) | ||
@@ -162,0 +165,0 @@ } |
@@ -0,1 +1,3 @@ | ||
let warnedAboutBoundary = false | ||
// ::- You'll often have to '[resolve](#model.Node.resolve)' a | ||
@@ -51,3 +53,3 @@ // position to get the context you need. Objects of this class | ||
depth = this.resolveDepth(depth) | ||
return this.index(depth) + (depth == this.depth && this.atNodeBoundary ? 0 : 1) | ||
return this.index(depth) + (depth == this.depth && !this.textOffset ? 0 : 1) | ||
} | ||
@@ -91,7 +93,16 @@ | ||
// :: bool | ||
// True if this position points at a node boundary, false if it | ||
// points into a text node. | ||
get atNodeBoundary() { return this.path[this.path.length - 1] == this.pos } | ||
get atNodeBoundary() { | ||
if (!warnedAboutBoundary && typeof console != "undefined") { | ||
warnedAboutBoundary = true | ||
console.warn("ResolvedPos.atNodeBoundary is deprecated. Use textOffset > 0 instead") | ||
} | ||
return !this.textOffset | ||
} | ||
// :: number | ||
// When this position points into a text node, this returns the | ||
// distance between the position and the start of the text node. | ||
// Will be zero for positions that point between nodes. | ||
get textOffset() { return this.pos - this.path[this.path.length - 1] } | ||
// :: ?Node | ||
@@ -98,0 +109,0 @@ // Get the node directly after the position, if any. If the position |
@@ -355,3 +355,3 @@ const {Node, TextNode} = require("./node") | ||
this.nodeSpec = OrderedMap.from(spec.nodes) | ||
// :: OrderedMap<constructor<MarkType>> The mark spec that the schema is based on. | ||
// :: OrderedMap<MarkSpec> The mark spec that the schema is based on. | ||
this.markSpec = OrderedMap.from(spec.marks) | ||
@@ -358,0 +358,0 @@ |
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
235388
5575