prosemirror-model
Advanced tools
Comparing version 0.20.0 to 0.21.0
@@ -24,3 +24,4 @@ var ref = require("./diff"); | ||
// Invoke a callback for all descendant nodes between the given two | ||
// positions (relative to start of this fragment). | ||
// positions (relative to start of this fragment). Doesn't descend | ||
// into a node when the callback returns `false`. | ||
Fragment.prototype.nodesBetween = function (from, to, f, nodeStart, parent) { | ||
@@ -42,4 +43,5 @@ var this$1 = this; | ||
// :: ((node: Node, pos: number, parent: Node)) | ||
// Call the given callback for every descendant node. | ||
// :: ((node: Node, pos: number, parent: Node) → ?bool) | ||
// Call the given callback for every descendant node. The callback | ||
// may return `false` to prevent traversal of its child nodes. | ||
Fragment.prototype.descendants = function (f) { | ||
@@ -46,0 +48,0 @@ this.nodesBetween(0, this.size, f) |
@@ -295,3 +295,3 @@ var ref = require("./fragment"); | ||
NodeContext.prototype.finish = function (openRight) { | ||
NodeContext.prototype.finish = function (openEnd) { | ||
if (!(this.options & OPT_PRESERVE_WS)) { // Strip trailing whitespace | ||
@@ -305,3 +305,3 @@ var last = this.content[this.content.length - 1], m | ||
var content = Fragment.from(this.content) | ||
if (!openRight && this.match) | ||
if (!openEnd && this.match) | ||
{ content = content.append(this.match.fillBefore(Fragment.empty, true)) } | ||
@@ -538,3 +538,3 @@ return this.type ? this.type.create(this.attrs, content) : content | ||
// their parents | ||
ParseContext.prototype.closeExtra = function (openRight) { | ||
ParseContext.prototype.closeExtra = function (openEnd) { | ||
var this$1 = this; | ||
@@ -545,3 +545,3 @@ | ||
this.marks = Mark.none | ||
for (; i > this.open; i--) { this$1.nodes[i - 1].content.push(this$1.nodes[i].finish(openRight)) } | ||
for (; i > this.open; i--) { this$1.nodes[i - 1].content.push(this$1.nodes[i].finish(openEnd)) } | ||
this.nodes.length = this.open + 1 | ||
@@ -621,3 +621,3 @@ } | ||
// Determines whether the given [context | ||
// string](##ParseRule.context) matches this context. | ||
// string](#ParseRule.context) matches this context. | ||
ParseContext.prototype.matchesContext = function (context) { | ||
@@ -624,0 +624,0 @@ var this$1 = this; |
exports.Node = require("./node").Node | ||
;var assign; | ||
((assign = require("./resolvedpos"), exports.ResolvedPos = assign.ResolvedPos, exports.NodeRange = assign.NodeRange, assign)) | ||
((assign = require("./resolvedpos"), exports.ResolvedPos = assign.ResolvedPos, exports.NodeRange = assign.NodeRange)) | ||
exports.Fragment = require("./fragment").Fragment | ||
;var assign$1; | ||
((assign$1 = require("./replace"), exports.Slice = assign$1.Slice, exports.ReplaceError = assign$1.ReplaceError, assign$1)) | ||
((assign$1 = require("./replace"), exports.Slice = assign$1.Slice, exports.ReplaceError = assign$1.ReplaceError)) | ||
exports.Mark = require("./mark").Mark | ||
;var assign$2; | ||
((assign$2 = require("./schema"), exports.Schema = assign$2.Schema, exports.NodeType = assign$2.NodeType, exports.MarkType = assign$2.MarkType, assign$2)) | ||
((assign$2 = require("./schema"), exports.Schema = assign$2.Schema, exports.NodeType = assign$2.NodeType, exports.MarkType = assign$2.MarkType)) | ||
;var assign$3; | ||
((assign$3 = require("./content"), exports.ContentMatch = assign$3.ContentMatch, assign$3)) | ||
((assign$3 = require("./content"), exports.ContentMatch = assign$3.ContentMatch)) | ||
exports.DOMParser = require("./from_dom").DOMParser | ||
exports.DOMSerializer = require("./to_dom").DOMSerializer |
@@ -79,3 +79,3 @@ var ref = require("./fragment"); | ||
// :: (?number, ?number, (node: Node, pos: number, parent: Node, index: number)) | ||
// :: (?number, ?number, (node: Node, pos: number, parent: Node, index: number) → ?bool) | ||
// Invoke a callback for all descendant nodes recursively between | ||
@@ -92,4 +92,5 @@ // the given two positions that are relative to start of this node's content. | ||
// :: ((node: Node, pos: number, parent: Node)) | ||
// Call the given callback for every descendant node. | ||
// :: ((node: Node, pos: number, parent: Node) → ?bool) | ||
// Call the given callback for every descendant node. If doesn't | ||
// descend into a child node when the callback returns `false`. | ||
Node.prototype.descendants = function (f) { | ||
@@ -96,0 +97,0 @@ this.nodesBetween(0, this.content.size, f) |
@@ -25,29 +25,40 @@ var ref = require("./fragment"); | ||
var warnedAboutOpen = false | ||
function warnAboutOpen() { | ||
if (!warnedAboutOpen && typeof console != "undefined" && console.warn) { | ||
warnedAboutOpen = true | ||
console.warn("Slice.openLeft has been renamed to openStart, and Slice.openRight to openEnd") | ||
} | ||
} | ||
// ::- A slice represents a piece cut out of a larger document. It | ||
// stores not only a fragment, but also the depth up to which nodes on | ||
// both side are 'open' / cut through. | ||
var Slice = function(content, openLeft, openRight) { | ||
var Slice = function(content, openStart, openEnd) { | ||
// :: Fragment The slice's content nodes. | ||
this.content = content | ||
// :: number The open depth at the start. | ||
this.openLeft = openLeft | ||
this.openStart = openStart | ||
// :: number The open depth at the end. | ||
this.openRight = openRight | ||
this.openEnd = openEnd | ||
}; | ||
var prototypeAccessors$1 = { size: {} }; | ||
var prototypeAccessors$1 = { openLeft: {},openRight: {},size: {} }; | ||
prototypeAccessors$1.openLeft.get = function () { warnAboutOpen(); return this.openStart }; | ||
prototypeAccessors$1.openRight.get = function () { warnAboutOpen(); return this.openEnd }; | ||
// :: number | ||
// The size this slice would add when inserted into a document. | ||
prototypeAccessors$1.size.get = function () { | ||
return this.content.size - this.openLeft - this.openRight | ||
return this.content.size - this.openStart - this.openEnd | ||
}; | ||
Slice.prototype.insertAt = function (pos, fragment) { | ||
var content = insertInto(this.content, pos + this.openLeft, fragment, null) | ||
return content && new Slice(content, this.openLeft, this.openRight) | ||
var content = insertInto(this.content, pos + this.openStart, fragment, null) | ||
return content && new Slice(content, this.openStart, this.openEnd) | ||
}; | ||
Slice.prototype.removeBetween = function (from, to) { | ||
return new Slice(removeRange(this.content, from + this.openLeft, to + this.openLeft), this.openLeft, this.openRight) | ||
return new Slice(removeRange(this.content, from + this.openStart, to + this.openStart), this.openStart, this.openEnd) | ||
}; | ||
@@ -58,7 +69,7 @@ | ||
Slice.prototype.eq = function (other) { | ||
return this.content.eq(other.content) && this.openLeft == other.openLeft && this.openRight == other.openRight | ||
return this.content.eq(other.content) && this.openStart == other.openStart && this.openEnd == other.openEnd | ||
}; | ||
Slice.prototype.toString = function () { | ||
return this.content + "(" + this.openLeft + "," + this.openRight + ")" | ||
return this.content + "(" + this.openStart + "," + this.openEnd + ")" | ||
}; | ||
@@ -70,5 +81,6 @@ | ||
if (!this.content.size) { return null } | ||
return {content: this.content.toJSON(), | ||
openLeft: this.openLeft, | ||
openRight: this.openRight} | ||
var json = {content: this.content.toJSON()} | ||
if (this.openStart > 0) { json.openStart = this.openStart } | ||
if (this.openEnd > 0) { json.openEnd = this.openEnd } | ||
return json | ||
}; | ||
@@ -80,3 +92,3 @@ | ||
if (!json) { return Slice.empty } | ||
return new Slice(Fragment.fromJSON(schema, json.content), json.openLeft, json.openRight) | ||
return new Slice(Fragment.fromJSON(schema, json.content), json.openStart || 0, json.openEnd || 0) | ||
}; | ||
@@ -88,6 +100,6 @@ | ||
Slice.maxOpen = function (fragment) { | ||
var openLeft = 0, openRight = 0 | ||
for (var n = fragment.firstChild; n && !n.isLeaf; n = n.firstChild) { openLeft++ } | ||
for (var n$1 = fragment.lastChild; n$1 && !n$1.isLeaf; n$1 = n$1.lastChild) { openRight++ } | ||
return new Slice(fragment, openLeft, openRight) | ||
var openStart = 0, openEnd = 0 | ||
for (var n = fragment.firstChild; n && !n.isLeaf; n = n.firstChild) { openStart++ } | ||
for (var n$1 = fragment.lastChild; n$1 && !n$1.isLeaf; n$1 = n$1.lastChild) { openEnd++ } | ||
return new Slice(fragment, openStart, openEnd) | ||
}; | ||
@@ -132,5 +144,5 @@ | ||
function replace($from, $to, slice) { | ||
if (slice.openLeft > $from.depth) | ||
if (slice.openStart > $from.depth) | ||
{ throw new ReplaceError("Inserted content deeper than insertion position") } | ||
if ($from.depth - slice.openLeft != $to.depth - slice.openRight) | ||
if ($from.depth - slice.openStart != $to.depth - slice.openEnd) | ||
{ throw new ReplaceError("Inconsistent open depths") } | ||
@@ -143,3 +155,3 @@ return replaceOuter($from, $to, slice, 0) | ||
var index = $from.index(depth), node = $from.node(depth) | ||
if (index == $to.index(depth) && depth < $from.depth - slice.openLeft) { | ||
if (index == $to.index(depth) && depth < $from.depth - slice.openStart) { | ||
var inner = replaceOuter($from, $to, slice, depth + 1) | ||
@@ -149,3 +161,3 @@ return node.copy(node.content.replaceChild(index, inner)) | ||
return close(node, replaceTwoWay($from, $to, depth)) | ||
} else if (!slice.openLeft && !slice.openRight && $from.depth == depth && $to.depth == depth) { // Simple, flat case | ||
} else if (!slice.openStart && !slice.openEnd && $from.depth == depth && $to.depth == depth) { // Simple, flat case | ||
var parent = $from.parent, content = parent.content | ||
@@ -204,16 +216,16 @@ return close(parent, content.cut(0, $from.parentOffset).append(slice.content).append(content.cut($to.parentOffset))) | ||
function replaceThreeWay($from, $start, $end, $to, depth) { | ||
var openLeft = $from.depth > depth && joinable($from, $start, depth + 1) | ||
var openRight = $to.depth > depth && joinable($end, $to, depth + 1) | ||
var openStart = $from.depth > depth && joinable($from, $start, depth + 1) | ||
var openEnd = $to.depth > depth && joinable($end, $to, depth + 1) | ||
var content = [] | ||
addRange(null, $from, depth, content) | ||
if (openLeft && openRight && $start.index(depth) == $end.index(depth)) { | ||
checkJoin(openLeft, openRight) | ||
addNode(close(openLeft, replaceThreeWay($from, $start, $end, $to, depth + 1)), content) | ||
if (openStart && openEnd && $start.index(depth) == $end.index(depth)) { | ||
checkJoin(openStart, openEnd) | ||
addNode(close(openStart, replaceThreeWay($from, $start, $end, $to, depth + 1)), content) | ||
} else { | ||
if (openLeft) | ||
{ addNode(close(openLeft, replaceTwoWay($from, $start, depth + 1)), content) } | ||
if (openStart) | ||
{ addNode(close(openStart, replaceTwoWay($from, $start, depth + 1)), content) } | ||
addRange($start, $end, depth, content) | ||
if (openRight) | ||
{ addNode(close(openRight, replaceTwoWay($end, $to, depth + 1)), content) } | ||
if (openEnd) | ||
{ addNode(close(openEnd, replaceTwoWay($end, $to, depth + 1)), content) } | ||
} | ||
@@ -236,8 +248,8 @@ addRange($to, null, depth, content) | ||
function prepareSliceForReplace(slice, $along) { | ||
var extra = $along.depth - slice.openLeft, parent = $along.node(extra) | ||
var extra = $along.depth - slice.openStart, parent = $along.node(extra) | ||
var node = parent.copy(slice.content) | ||
for (var i = extra - 1; i >= 0; i--) | ||
{ node = $along.node(i).copy(Fragment.from(node)) } | ||
return {start: node.resolveNoCache(slice.openLeft + extra), | ||
end: node.resolveNoCache(node.content.size - slice.openRight - extra)} | ||
return {start: node.resolveNoCache(slice.openStart + extra), | ||
end: node.resolveNoCache(node.content.size - slice.openEnd - extra)} | ||
} |
@@ -76,3 +76,3 @@ var ref = require("./mark"); | ||
// The (absolute) position directly before the node at the given | ||
// level, or, when `level` is `this.level + 1`, the original | ||
// level, or, when `level` is `this.depth + 1`, the original | ||
// position. | ||
@@ -87,3 +87,3 @@ ResolvedPos.prototype.before = function (depth) { | ||
// The (absolute) position directly after the node at the given | ||
// level, or, when `level` is `this.level + 1`, the original | ||
// level, or, when `level` is `this.depth + 1`, the original | ||
// position. | ||
@@ -126,3 +126,3 @@ ResolvedPos.prototype.after = function (depth) { | ||
// Get the marks at this position, factoring in the surrounding | ||
// marks' [`inclusive`](##model.MarkSpec.inclusive) property. If the | ||
// marks' [`inclusive`](#model.MarkSpec.inclusive) property. If the | ||
// position is at the start of a non-empty node, or `after` is true, | ||
@@ -129,0 +129,0 @@ // the marks of the node after it (if any) are returned. |
@@ -336,3 +336,9 @@ var OrderedMap = require("orderedmap") | ||
// | ||
// toDOM:: ?(Node) → DOMOutputSpec | ||
// isolating:: ?bool | ||
// When enabled (default is false), the sides of nodes of this type | ||
// count as boundaries that regular editing operations, like | ||
// backspacing or lifting, won't cross. An example of a node that | ||
// should probably have this set is a table cell. | ||
// | ||
// toDOM:: ?(node: Node) → DOMOutputSpec | ||
// Defines the default way a node of this type should be serialized | ||
@@ -386,3 +392,3 @@ // to DOM/HTML (as used by | ||
// | ||
// toDOM:: ?(mark: Mark) → DOMOutputSpec | ||
// toDOM:: ?(mark: Mark, inline: bool) → DOMOutputSpec | ||
// Defines the default way marks of this type should be serialized | ||
@@ -389,0 +395,0 @@ // to DOM/HTML. |
@@ -45,4 +45,4 @@ // DOMOutputSpec:: interface | ||
while (keep < active.length) { | ||
active.pop() | ||
top = top.parentNode | ||
var removed = active.pop() | ||
if (this$1.marks[removed.type.name]) { top = top.parentNode } | ||
} | ||
@@ -52,3 +52,4 @@ while (active.length < node.marks.length) { | ||
active.push(add) | ||
top = top.appendChild(this$1.serializeMark(add, options)) | ||
var markDOM = this$1.serializeMark(add, node.isInline, options) | ||
if (markDOM) { top = top.appendChild(markDOM) } | ||
} | ||
@@ -80,5 +81,7 @@ } | ||
for (var i = node.marks.length - 1; i >= 0; i--) { | ||
var wrap = this$1.serializeMark(node.marks[i], options) | ||
wrap.appendChild(dom) | ||
dom = wrap | ||
var wrap = this$1.serializeMark(node.marks[i], node.isInline, options) | ||
if (wrap) { | ||
wrap.appendChild(dom) | ||
dom = wrap | ||
} | ||
} | ||
@@ -88,10 +91,11 @@ return dom | ||
DOMSerializer.prototype.serializeMark = function (mark, options) { | ||
DOMSerializer.prototype.serializeMark = function (mark, inline, options) { | ||
if ( options === void 0 ) options = {}; | ||
return this.renderStructure(this.marks[mark.type.name](mark), null, options) | ||
var toDOM = this.marks[mark.type.name] | ||
return toDOM && this.renderStructure(toDOM(mark, inline), null, options) | ||
}; | ||
// :: (dom.Document, DOMOutputSpec) → {dom: dom.Node, contentDOM: ?dom.Node} | ||
// Render an [output spec](##model.DOMOutputSpec). | ||
// Render an [output spec](#model.DOMOutputSpec). | ||
DOMSerializer.renderSpec = function (doc, structure) { | ||
@@ -98,0 +102,0 @@ if (typeof structure == "string") |
{ | ||
"name": "prosemirror-model", | ||
"version": "0.20.0", | ||
"version": "0.21.0", | ||
"description": "ProseMirror's document model", | ||
@@ -27,3 +27,3 @@ "main": "dist/index.js", | ||
"rimraf": "^2.5.4", | ||
"prosemirror-test-builder": "^0.20.0" | ||
"prosemirror-test-builder": "^0.21.0" | ||
}, | ||
@@ -30,0 +30,0 @@ "scripts": { |
@@ -19,3 +19,4 @@ const {findDiffStart, findDiffEnd} = require("./diff") | ||
// Invoke a callback for all descendant nodes between the given two | ||
// positions (relative to start of this fragment). | ||
// positions (relative to start of this fragment). Doesn't descend | ||
// into a node when the callback returns `false`. | ||
nodesBetween(from, to, f, nodeStart = 0, parent) { | ||
@@ -34,4 +35,5 @@ for (let i = 0, pos = 0; pos < to; i++) { | ||
// :: ((node: Node, pos: number, parent: Node)) | ||
// Call the given callback for every descendant node. | ||
// :: ((node: Node, pos: number, parent: Node) → ?bool) | ||
// Call the given callback for every descendant node. The callback | ||
// may return `false` to prevent traversal of its child nodes. | ||
descendants(f) { | ||
@@ -38,0 +40,0 @@ this.nodesBetween(0, this.size, f) |
@@ -284,3 +284,3 @@ const {Fragment} = require("./fragment") | ||
finish(openRight) { | ||
finish(openEnd) { | ||
if (!(this.options & OPT_PRESERVE_WS)) { // Strip trailing whitespace | ||
@@ -294,3 +294,3 @@ let last = this.content[this.content.length - 1], m | ||
let content = Fragment.from(this.content) | ||
if (!openRight && this.match) | ||
if (!openEnd && this.match) | ||
content = content.append(this.match.fillBefore(Fragment.empty, true)) | ||
@@ -520,7 +520,7 @@ return this.type ? this.type.create(this.attrs, content) : content | ||
// their parents | ||
closeExtra(openRight) { | ||
closeExtra(openEnd) { | ||
let i = this.nodes.length - 1 | ||
if (i > this.open) { | ||
this.marks = Mark.none | ||
for (; i > this.open; i--) this.nodes[i - 1].content.push(this.nodes[i].finish(openRight)) | ||
for (; i > this.open; i--) this.nodes[i - 1].content.push(this.nodes[i].finish(openEnd)) | ||
this.nodes.length = this.open + 1 | ||
@@ -588,3 +588,3 @@ } | ||
// Determines whether the given [context | ||
// string](##ParseRule.context) matches this context. | ||
// string](#ParseRule.context) matches this context. | ||
matchesContext(context) { | ||
@@ -591,0 +591,0 @@ let parts = context.split("/") |
@@ -72,3 +72,3 @@ const {Fragment} = require("./fragment") | ||
// :: (?number, ?number, (node: Node, pos: number, parent: Node, index: number)) | ||
// :: (?number, ?number, (node: Node, pos: number, parent: Node, index: number) → ?bool) | ||
// Invoke a callback for all descendant nodes recursively between | ||
@@ -83,4 +83,5 @@ // the given two positions that are relative to start of this node's content. | ||
// :: ((node: Node, pos: number, parent: Node)) | ||
// Call the given callback for every descendant node. | ||
// :: ((node: Node, pos: number, parent: Node) → ?bool) | ||
// Call the given callback for every descendant node. If doesn't | ||
// descend into a child node when the callback returns `false`. | ||
descendants(f) { | ||
@@ -87,0 +88,0 @@ this.nodesBetween(0, this.content.size, f) |
@@ -14,2 +14,10 @@ const {Fragment} = require("./fragment") | ||
let warnedAboutOpen = false | ||
function warnAboutOpen() { | ||
if (!warnedAboutOpen && typeof console != "undefined" && console.warn) { | ||
warnedAboutOpen = true | ||
console.warn("Slice.openLeft has been renamed to openStart, and Slice.openRight to openEnd") | ||
} | ||
} | ||
// ::- A slice represents a piece cut out of a larger document. It | ||
@@ -20,24 +28,27 @@ // stores not only a fragment, but also the depth up to which nodes on | ||
// :: (Fragment, number, number) | ||
constructor(content, openLeft, openRight) { | ||
constructor(content, openStart, openEnd) { | ||
// :: Fragment The slice's content nodes. | ||
this.content = content | ||
// :: number The open depth at the start. | ||
this.openLeft = openLeft | ||
this.openStart = openStart | ||
// :: number The open depth at the end. | ||
this.openRight = openRight | ||
this.openEnd = openEnd | ||
} | ||
get openLeft() { warnAboutOpen(); return this.openStart } | ||
get openRight() { warnAboutOpen(); return this.openEnd } | ||
// :: number | ||
// The size this slice would add when inserted into a document. | ||
get size() { | ||
return this.content.size - this.openLeft - this.openRight | ||
return this.content.size - this.openStart - this.openEnd | ||
} | ||
insertAt(pos, fragment) { | ||
let content = insertInto(this.content, pos + this.openLeft, fragment, null) | ||
return content && new Slice(content, this.openLeft, this.openRight) | ||
let content = insertInto(this.content, pos + this.openStart, fragment, null) | ||
return content && new Slice(content, this.openStart, this.openEnd) | ||
} | ||
removeBetween(from, to) { | ||
return new Slice(removeRange(this.content, from + this.openLeft, to + this.openLeft), this.openLeft, this.openRight) | ||
return new Slice(removeRange(this.content, from + this.openStart, to + this.openStart), this.openStart, this.openEnd) | ||
} | ||
@@ -48,7 +59,7 @@ | ||
eq(other) { | ||
return this.content.eq(other.content) && this.openLeft == other.openLeft && this.openRight == other.openRight | ||
return this.content.eq(other.content) && this.openStart == other.openStart && this.openEnd == other.openEnd | ||
} | ||
toString() { | ||
return this.content + "(" + this.openLeft + "," + this.openRight + ")" | ||
return this.content + "(" + this.openStart + "," + this.openEnd + ")" | ||
} | ||
@@ -60,5 +71,6 @@ | ||
if (!this.content.size) return null | ||
return {content: this.content.toJSON(), | ||
openLeft: this.openLeft, | ||
openRight: this.openRight} | ||
let json = {content: this.content.toJSON()} | ||
if (this.openStart > 0) json.openStart = this.openStart | ||
if (this.openEnd > 0) json.openEnd = this.openEnd | ||
return json | ||
} | ||
@@ -70,3 +82,3 @@ | ||
if (!json) return Slice.empty | ||
return new Slice(Fragment.fromJSON(schema, json.content), json.openLeft, json.openRight) | ||
return new Slice(Fragment.fromJSON(schema, json.content), json.openStart || 0, json.openEnd || 0) | ||
} | ||
@@ -78,6 +90,6 @@ | ||
static maxOpen(fragment) { | ||
let openLeft = 0, openRight = 0 | ||
for (let n = fragment.firstChild; n && !n.isLeaf; n = n.firstChild) openLeft++ | ||
for (let n = fragment.lastChild; n && !n.isLeaf; n = n.lastChild) openRight++ | ||
return new Slice(fragment, openLeft, openRight) | ||
let openStart = 0, openEnd = 0 | ||
for (let n = fragment.firstChild; n && !n.isLeaf; n = n.firstChild) openStart++ | ||
for (let n = fragment.lastChild; n && !n.isLeaf; n = n.lastChild) openEnd++ | ||
return new Slice(fragment, openStart, openEnd) | ||
} | ||
@@ -113,5 +125,5 @@ } | ||
function replace($from, $to, slice) { | ||
if (slice.openLeft > $from.depth) | ||
if (slice.openStart > $from.depth) | ||
throw new ReplaceError("Inserted content deeper than insertion position") | ||
if ($from.depth - slice.openLeft != $to.depth - slice.openRight) | ||
if ($from.depth - slice.openStart != $to.depth - slice.openEnd) | ||
throw new ReplaceError("Inconsistent open depths") | ||
@@ -124,3 +136,3 @@ return replaceOuter($from, $to, slice, 0) | ||
let index = $from.index(depth), node = $from.node(depth) | ||
if (index == $to.index(depth) && depth < $from.depth - slice.openLeft) { | ||
if (index == $to.index(depth) && depth < $from.depth - slice.openStart) { | ||
let inner = replaceOuter($from, $to, slice, depth + 1) | ||
@@ -130,3 +142,3 @@ return node.copy(node.content.replaceChild(index, inner)) | ||
return close(node, replaceTwoWay($from, $to, depth)) | ||
} else if (!slice.openLeft && !slice.openRight && $from.depth == depth && $to.depth == depth) { // Simple, flat case | ||
} else if (!slice.openStart && !slice.openEnd && $from.depth == depth && $to.depth == depth) { // Simple, flat case | ||
let parent = $from.parent, content = parent.content | ||
@@ -183,16 +195,16 @@ return close(parent, content.cut(0, $from.parentOffset).append(slice.content).append(content.cut($to.parentOffset))) | ||
function replaceThreeWay($from, $start, $end, $to, depth) { | ||
let openLeft = $from.depth > depth && joinable($from, $start, depth + 1) | ||
let openRight = $to.depth > depth && joinable($end, $to, depth + 1) | ||
let openStart = $from.depth > depth && joinable($from, $start, depth + 1) | ||
let openEnd = $to.depth > depth && joinable($end, $to, depth + 1) | ||
let content = [] | ||
addRange(null, $from, depth, content) | ||
if (openLeft && openRight && $start.index(depth) == $end.index(depth)) { | ||
checkJoin(openLeft, openRight) | ||
addNode(close(openLeft, replaceThreeWay($from, $start, $end, $to, depth + 1)), content) | ||
if (openStart && openEnd && $start.index(depth) == $end.index(depth)) { | ||
checkJoin(openStart, openEnd) | ||
addNode(close(openStart, replaceThreeWay($from, $start, $end, $to, depth + 1)), content) | ||
} else { | ||
if (openLeft) | ||
addNode(close(openLeft, replaceTwoWay($from, $start, depth + 1)), content) | ||
if (openStart) | ||
addNode(close(openStart, replaceTwoWay($from, $start, depth + 1)), content) | ||
addRange($start, $end, depth, content) | ||
if (openRight) | ||
addNode(close(openRight, replaceTwoWay($end, $to, depth + 1)), content) | ||
if (openEnd) | ||
addNode(close(openEnd, replaceTwoWay($end, $to, depth + 1)), content) | ||
} | ||
@@ -215,8 +227,8 @@ addRange($to, null, depth, content) | ||
function prepareSliceForReplace(slice, $along) { | ||
let extra = $along.depth - slice.openLeft, parent = $along.node(extra) | ||
let extra = $along.depth - slice.openStart, parent = $along.node(extra) | ||
let node = parent.copy(slice.content) | ||
for (let i = extra - 1; i >= 0; i--) | ||
node = $along.node(i).copy(Fragment.from(node)) | ||
return {start: node.resolveNoCache(slice.openLeft + extra), | ||
end: node.resolveNoCache(node.content.size - slice.openRight - extra)} | ||
return {start: node.resolveNoCache(slice.openStart + extra), | ||
end: node.resolveNoCache(node.content.size - slice.openEnd - extra)} | ||
} |
@@ -74,3 +74,3 @@ const {Mark} = require("./mark") | ||
// The (absolute) position directly before the node at the given | ||
// level, or, when `level` is `this.level + 1`, the original | ||
// level, or, when `level` is `this.depth + 1`, the original | ||
// position. | ||
@@ -85,3 +85,3 @@ before(depth) { | ||
// The (absolute) position directly after the node at the given | ||
// level, or, when `level` is `this.level + 1`, the original | ||
// level, or, when `level` is `this.depth + 1`, the original | ||
// position. | ||
@@ -124,3 +124,3 @@ after(depth) { | ||
// Get the marks at this position, factoring in the surrounding | ||
// marks' [`inclusive`](##model.MarkSpec.inclusive) property. If the | ||
// marks' [`inclusive`](#model.MarkSpec.inclusive) property. If the | ||
// position is at the start of a non-empty node, or `after` is true, | ||
@@ -127,0 +127,0 @@ // the marks of the node after it (if any) are returned. |
@@ -323,3 +323,9 @@ const OrderedMap = require("orderedmap") | ||
// | ||
// toDOM:: ?(Node) → DOMOutputSpec | ||
// isolating:: ?bool | ||
// When enabled (default is false), the sides of nodes of this type | ||
// count as boundaries that regular editing operations, like | ||
// backspacing or lifting, won't cross. An example of a node that | ||
// should probably have this set is a table cell. | ||
// | ||
// toDOM:: ?(node: Node) → DOMOutputSpec | ||
// Defines the default way a node of this type should be serialized | ||
@@ -373,3 +379,3 @@ // to DOM/HTML (as used by | ||
// | ||
// toDOM:: ?(mark: Mark) → DOMOutputSpec | ||
// toDOM:: ?(mark: Mark, inline: bool) → DOMOutputSpec | ||
// Defines the default way marks of this type should be serialized | ||
@@ -376,0 +382,0 @@ // to DOM/HTML. |
@@ -20,6 +20,10 @@ // DOMOutputSpec:: interface | ||
class DOMSerializer { | ||
// :: (Object<(node: Node) → DOMOutputSpec>, Object<(mark: Mark) → DOMOutputSpec>) | ||
// :: (Object<(node: Node) → DOMOutputSpec>, Object<?(mark: Mark, inline: bool) → DOMOutputSpec>) | ||
// Create a serializer. `nodes` should map node names to functions | ||
// that take a node and return a description of the corresponding | ||
// DOM. `marks` does the same for mark names. | ||
// DOM. `marks` does the same for mark names, but also gets an | ||
// argument that tells it whether the mark's content is block or | ||
// inline content (for typical use, it'll always be inline). A mark | ||
// serializer may be `null` to indicate that marks of that type | ||
// should not be serialized. | ||
constructor(nodes, marks) { | ||
@@ -48,4 +52,4 @@ // :: Object<(node: Node) → DOMOutputSpec> | ||
while (keep < active.length) { | ||
active.pop() | ||
top = top.parentNode | ||
let removed = active.pop() | ||
if (this.marks[removed.type.name]) top = top.parentNode | ||
} | ||
@@ -55,3 +59,4 @@ while (active.length < node.marks.length) { | ||
active.push(add) | ||
top = top.appendChild(this.serializeMark(add, options)) | ||
let markDOM = this.serializeMark(add, node.isInline, options) | ||
if (markDOM) top = top.appendChild(markDOM) | ||
} | ||
@@ -78,5 +83,7 @@ } | ||
for (let i = node.marks.length - 1; i >= 0; i--) { | ||
let wrap = this.serializeMark(node.marks[i], options) | ||
wrap.appendChild(dom) | ||
dom = wrap | ||
let wrap = this.serializeMark(node.marks[i], node.isInline, options) | ||
if (wrap) { | ||
wrap.appendChild(dom) | ||
dom = wrap | ||
} | ||
} | ||
@@ -86,8 +93,9 @@ return dom | ||
serializeMark(mark, options = {}) { | ||
return this.renderStructure(this.marks[mark.type.name](mark), null, options) | ||
serializeMark(mark, inline, options = {}) { | ||
let toDOM = this.marks[mark.type.name] | ||
return toDOM && this.renderStructure(toDOM(mark, inline), null, options) | ||
} | ||
// :: (dom.Document, DOMOutputSpec) → {dom: dom.Node, contentDOM: ?dom.Node} | ||
// Render an [output spec](##model.DOMOutputSpec). | ||
// Render an [output spec](#model.DOMOutputSpec). | ||
static renderSpec(doc, structure) { | ||
@@ -94,0 +102,0 @@ if (typeof structure == "string") |
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
243182
5728