Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prosemirror-model

Package Overview
Dependencies
Maintainers
1
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prosemirror-model - npm Package Compare versions

Comparing version 0.11.1 to 0.12.0

14

dist/comparedeep.js
function compareDeep(a, b) {
if (a === b) return true
if (a === b) { return true }
if (!(a && typeof a == "object") ||
!(b && typeof b == "object")) return false
!(b && typeof b == "object")) { return false }
var array = Array.isArray(a)
if (Array.isArray(b) != array) return false
if (Array.isArray(b) != array) { return false }
if (array) {
if (a.length != b.length) return false
for (var i = 0; i < a.length; i++) if (!compareDeep(a[i], b[i])) return false
if (a.length != b.length) { return false }
for (var i = 0; i < a.length; i++) { if (!compareDeep(a[i], b[i])) { return false } }
} else {
for (var p in a) if (!(p in b) || !compareDeep(a[p], b[p])) return false
for (var p$1 in b) if (!(p$1 in a)) return false
for (var p in a) { if (!(p in b) || !compareDeep(a[p], b[p])) { return false } }
for (var p$1 in b) { if (!(p$1 in a)) { return false } }
}

@@ -14,0 +14,0 @@ return true

@@ -33,5 +33,5 @@ var ref = require("./fragment");

if (this.elements.length == 1)
return new ContentMatch(this, attrs, 0, index)
{ return new ContentMatch(this, attrs, 0, index) }
else
return this.start(attrs).matchFragment(fragment, 0, index)
{ return this.start(attrs).matchFragment(fragment, 0, index) }
};

@@ -49,4 +49,4 @@

var elt = this.elements[0]
if (!checkCount(elt, content.childCount - (to - from) + (end - start), attrs, this)) return false
for (var i = start; i < end; i++) if (!elt.matches(replacement.child(i), attrs, this$1)) return false
if (!checkCount(elt, content.childCount - (to - from) + (end - start), attrs, this)) { return false }
for (var i = start; i < end; i++) { if (!elt.matches(replacement.child(i), attrs, this$1)) { return false } }
return true

@@ -62,3 +62,3 @@ }

var elt = this.elements[0]
if (!checkCount(elt, content.childCount - (to - from) + 1, attrs, this)) return false
if (!checkCount(elt, content.childCount - (to - from) + 1, attrs, this)) { return false }
return elt.matchesType(type, typeAttrs, marks, attrs, this)

@@ -77,3 +77,3 @@ }

for (var j = 0; j < other.elements.length; j++)
if (other.elements[j].compatible(elt)) return true
{ if (other.elements[j].compatible(elt)) { return true } }
}

@@ -91,18 +91,18 @@ return false

pos += /^\s*/.exec(expr.slice(pos))[0].length
if (pos == expr.length) break
if (pos == expr.length) { break }
var types = /^(?:(\w+)|\(\s*(\w+(?:\s*\|\s*\w+)*)\s*\))/.exec(expr.slice(pos))
if (!types) throw new SyntaxError("Invalid content expression '" + expr + "' at " + pos)
if (!types) { throw new SyntaxError("Invalid content expression '" + expr + "' at " + pos) }
pos += types[0].length
var attrs = /^\[([^\]]+)\]/.exec(expr.slice(pos))
if (attrs) pos += attrs[0].length
if (attrs) { pos += attrs[0].length }
var marks = /^<(?:(_)|\s*(\w+(?:\s+\w+)*)\s*)>/.exec(expr.slice(pos))
if (marks) pos += marks[0].length
if (marks) { pos += marks[0].length }
var repeat = /^(?:([+*?])|\{\s*(\d+|\.\w+)\s*(,\s*(\d+|\.\w+)?)?\s*\})/.exec(expr.slice(pos))
if (repeat) pos += repeat[0].length
if (repeat) { pos += repeat[0].length }
var nodeTypes = expandTypes(nodeType.schema, specs, types[1] ? [types[1]] : types[2].split(/\s*\|\s*/))
for (var i = 0; i < nodeTypes.length; i++) {
if (inline == null) inline = nodeTypes[i].isInline
else if (inline != nodeTypes[i].isInline) throw new SyntaxError("Mixing inline and block content in a single node")
if (inline == null) { inline = nodeTypes[i].isInline }
else if (inline != nodeTypes[i].isInline) { throw new SyntaxError("Mixing inline and block content in a single node") }
}

@@ -115,4 +115,4 @@ var attrSet = !attrs ? null : parseAttrs(nodeType, attrs[1])

if (min != 0 && nodeTypes[0].hasRequiredAttrs(attrSet))
throw new SyntaxError("Node type " + types[0] + " in type " + nodeType.name +
" is required, but has non-optional attributes")
{ throw new SyntaxError("Node type " + types[0] + " in type " + nodeType.name +
" is required, but has non-optional attributes") }
var newElt = new ContentElement(nodeTypes, attrSet, markSet, min, max)

@@ -122,4 +122,4 @@ for (var i$1 = elements.length - 1; i$1 >= 0; i$1--) {

if (prev.min != prev.max && prev.overlaps(newElt))
throw new SyntaxError("Possibly ambiguous overlapping adjacent content expressions in '" + expr + "'")
if (prev.min != 0) break
{ throw new SyntaxError("Possibly ambiguous overlapping adjacent content expressions in '" + expr + "'") }
if (prev.min != 0) { break }
}

@@ -146,12 +146,12 @@ elements.push(newElt)

if (this.nodeTypes.indexOf(type) == -1) return false
if (this.nodeTypes.indexOf(type) == -1) { return false }
if (this.attrs) {
if (!attrs) return false
if (!attrs) { return false }
for (var prop in this.attrs)
if (attrs[prop] != resolveValue(this$1.attrs[prop], parentAttrs, parentExpr)) return false
{ if (attrs[prop] != resolveValue(this$1.attrs[prop], parentAttrs, parentExpr)) { return false } }
}
if (this.marks === true) return true
if (this.marks === false) return marks.length == 0
if (this.marks === true) { return true }
if (this.marks === false) { return marks.length == 0 }
for (var i = 0; i < marks.length; i++)
if (this$1.marks.indexOf(marks[i].type) == -1) return false
{ if (this$1.marks.indexOf(marks[i].type) == -1) { return false } }
return true

@@ -168,3 +168,3 @@ };

for (var i = 0; i < this.nodeTypes.length; i++)
if (other.nodeTypes.indexOf(this$1.nodeTypes[i]) != -1) return true
{ if (other.nodeTypes.indexOf(this$1.nodeTypes[i]) != -1) { return true } }
return false

@@ -176,6 +176,6 @@ };

if (!this.attrs) return null
if (!this.attrs) { return null }
var attrs = Object.create(null)
for (var prop in this.attrs)
attrs[prop] = resolveValue(this$1.attrs[prop], parentAttrs, expr)
{ attrs[prop] = resolveValue(this$1.attrs[prop], parentAttrs, expr) }
return attrs

@@ -221,3 +221,3 @@ };

var element = this$1.expr.elements[i]
if (this$1.resolveValue(element.max) > count) return element
if (this$1.resolveValue(element.max) > count) { return element }
count = 0

@@ -255,3 +255,3 @@ }

}
if (count < this$1.resolveValue(elt.min)) return null
if (count < this$1.resolveValue(elt.min)) { return null }
}

@@ -270,3 +270,3 @@ };

if (from == to) return this
if (from == to) { return this }
var fragPos = from, end = this.expr.elements.length

@@ -279,3 +279,3 @@ for (var ref = this, index = ref.index, count = ref.count; index < end; index++, count = 0) {

count++
if (++fragPos == to) return this$1.move(index, count)
if (++fragPos == to) { return this$1.move(index, count) }
} else {

@@ -285,3 +285,3 @@ break

}
if (count < this$1.resolveValue(elt.min)) return null
if (count < this$1.resolveValue(elt.min)) { return null }
}

@@ -306,3 +306,3 @@ return false

for (var i = this.index, count = this.count; i < this.expr.elements.length; i++, count = 0)
if (count < this$1.resolveValue(this$1.expr.elements[i].min)) return false
{ if (count < this$1.resolveValue(this$1.expr.elements[i].min)) { return false } }
return true

@@ -324,4 +324,4 @@ };

var fits = match.matchFragment(after, index)
if (fits && (!toEnd || fits.validEnd())) return Fragment.from(added)
if (fits === false) return null // Matched to end with content remaining
if (fits && (!toEnd || fits.validEnd())) { return Fragment.from(added) }
if (fits === false) { return null } // Matched to end with content remaining

@@ -348,7 +348,7 @@ var elt = match.element

var elt = this$1.expr.elements[i], attrs = elt.constrainedAttrs(this$1.attrs, this$1.expr)
if (count < this$1.resolveValue(elt.max)) for (var j = 0; j < elt.nodeTypes.length; j++) {
if (count < this$1.resolveValue(elt.max)) { for (var j = 0; j < elt.nodeTypes.length; j++) {
var type = elt.nodeTypes[j]
if (!type.hasRequiredAttrs(attrs)) found.push({type: type, attrs: attrs})
}
if (this$1.resolveValue(elt.min) > count) break
if (!type.hasRequiredAttrs(attrs)) { found.push({type: type, attrs: attrs}) }
} }
if (this$1.resolveValue(elt.min) > count) { break }
}

@@ -378,3 +378,3 @@ return found

for (var obj = current; obj != first; obj = obj.via)
result.push({type: obj.match.expr.nodeType, attrs: obj.match.attrs})
{ result.push({type: obj.match.expr.nodeType, attrs: obj.match.attrs}) }
return result.reverse()

@@ -405,3 +405,3 @@ }

var attr = value.slice(1)
if (!nodeType.attrs[attr]) throw new SyntaxError("Node type " + nodeType.name + " has no attribute " + attr)
if (!nodeType.attrs[attr]) { throw new SyntaxError("Node type " + nodeType.name + " has no attribute " + attr) }
return new AttrValue(attr)

@@ -417,4 +417,4 @@ } else {

var mark = schema.marks[marks[i]]
if (mark) found.push(mark)
else throw new SyntaxError("Unknown mark type: '" + marks[i] + "'")
if (mark) { found.push(mark) }
else { throw new SyntaxError("Unknown mark type: '" + marks[i] + "'") }
}

@@ -425,3 +425,3 @@ return found

function resolveValue(value, attrs, expr) {
if (!(value instanceof AttrValue)) return value
if (!(value instanceof AttrValue)) { return value }
var attrVal = attrs && attrs[value.attr]

@@ -441,3 +441,3 @@ return attrVal !== undefined ? attrVal : expr.nodeType.defaultAttrs[value.attr]

if (found) {
if (result.indexOf(found) == -1) result.push(found)
if (result.indexOf(found) == -1) { result.push(found) }
} else {

@@ -447,3 +447,3 @@ specs.forEach(function (name, spec) {

found = schema.nodes[name]
if (result.indexOf(found) == -1) result.push(found)
if (result.indexOf(found) == -1) { result.push(found) }
}

@@ -453,3 +453,3 @@ })

if (!found)
throw new SyntaxError("Node type or group '" + type + "' does not exist")
{ throw new SyntaxError("Node type or group '" + type + "' does not exist") }
})

@@ -474,8 +474,8 @@ return result

if (match[3])
max = match[4] ? parseValue(nodeType, match[4]) : many
{ max = match[4] ? parseValue(nodeType, match[4]) : many }
else
max = min
{ max = min }
}
if (max == 0 || min > max)
throw new SyntaxError("Invalid repeat count in '" + match[0] + "'")
{ throw new SyntaxError("Invalid repeat count in '" + match[0] + "'") }
}

@@ -490,3 +490,3 @@ return {min: min, max: max}

var match = /^(\w+)=(\w+|\"(?:\\.|[^\\])*\"|\.\w+)$/.exec(parts[i])
if (!match) throw new SyntaxError("Invalid attribute syntax: " + parts[i])
if (!match) { throw new SyntaxError("Invalid attribute syntax: " + parts[i]) }
attrs[match[1]] = parseValue(nodeType, match[2])

@@ -493,0 +493,0 @@ }

function findDiffStart(a, b, pos) {
for (var i = 0;; i++) {
if (i == a.childCount || i == b.childCount)
return a.childCount == b.childCount ? null : pos
{ return a.childCount == b.childCount ? null : pos }

@@ -9,7 +9,7 @@ var childA = a.child(i), childB = b.child(i)

if (!childA.sameMarkup(childB)) return pos
if (!childA.sameMarkup(childB)) { return pos }
if (childA.isText && childA.text != childB.text) {
for (var j = 0; childA.text[j] == childB.text[j]; j++)
pos++
{ pos++ }
return pos

@@ -19,3 +19,3 @@ }

var inner = findDiffStart(childA.content, childB.content, pos + 1)
if (inner != null) return inner
if (inner != null) { return inner }
}

@@ -30,3 +30,3 @@ pos += childA.nodeSize

if (iA == 0 || iB == 0)
return iA == iB ? null : {a: posA, b: posB}
{ return iA == iB ? null : {a: posA, b: posB} }

@@ -39,3 +39,3 @@ var childA = a.child(--iA), childB = b.child(--iB), size = childA.nodeSize

if (!childA.sameMarkup(childB)) return {a: posA, b: posB}
if (!childA.sameMarkup(childB)) { return {a: posA, b: posB} }

@@ -51,3 +51,3 @@ if (childA.isText && childA.text != childB.text) {

var inner = findDiffEnd(childA.content, childB.content, posA - 1, posB - 1)
if (inner) return inner
if (inner) { return inner }
}

@@ -54,0 +54,0 @@ posA -= size; posB -= size

@@ -16,4 +16,4 @@ var ref = require("./diff");

this.size = size || 0
if (size == null) for (var i = 0; i < content.length; i++)
this$1.size += content[i].nodeSize
if (size == null) { for (var i = 0; i < content.length; i++)
{ this$1.size += content[i].nodeSize } }
};

@@ -60,4 +60,4 @@

Fragment.prototype.append = function append (other) {
if (!other.size) return this
if (!this.size) return other
if (!other.size) { return this }
if (!this.size) { return other }
var last = this.lastChild, first = other.firstChild, content = this.content.slice(), i = 0

@@ -68,3 +68,3 @@ if (last.isText && last.sameMarkup(first)) {

}
for (; i < other.content.length; i++) content.push(other.content[i])
for (; i < other.content.length; i++) { content.push(other.content[i]) }
return new Fragment(content, this.size + other.size)

@@ -78,6 +78,6 @@ };

if (to == null) to = this.size
if (from == 0 && to == this.size) return this
if (to == null) { to = this.size }
if (from == 0 && to == this.size) { return this }
var result = [], size = 0
if (to > from) for (var i = 0, pos = 0; pos < to; i++) {
if (to > from) { for (var i = 0, pos = 0; pos < to; i++) {
var child = this$1.content[i], end = pos + child.nodeSize

@@ -87,5 +87,5 @@ if (end > from) {

if (child.isText)
child = child.cut(Math.max(0, from - pos), Math.min(child.text.length, to - pos))
{ child = child.cut(Math.max(0, from - pos), Math.min(child.text.length, to - pos)) }
else
child = child.cut(Math.max(0, from - pos - 1), Math.min(child.content.size, to - pos - 1))
{ child = child.cut(Math.max(0, from - pos - 1), Math.min(child.content.size, to - pos - 1)) }
}

@@ -96,3 +96,3 @@ result.push(child)

pos = end
}
} }
return new Fragment(result, size)

@@ -102,4 +102,4 @@ };

Fragment.prototype.cutByIndex = function cutByIndex (from, to) {
if (from == to) return Fragment.empty
if (from == 0 && to == this.content.length) return this
if (from == to) { return Fragment.empty }
if (from == 0 && to == this.content.length) { return this }
return new Fragment(this.content.slice(from, to))

@@ -113,3 +113,3 @@ };

var current = this.content[index]
if (current == node) return this
if (current == node) { return this }
var copy = this.content.slice()

@@ -140,5 +140,5 @@ var size = this.size + node.nodeSize - current.nodeSize

if (this.content.length != other.content.length) return false
if (this.content.length != other.content.length) { return false }
for (var i = 0; i < this.content.length; i++)
if (!this$1.content[i].eq(other.content[i])) return false
{ if (!this$1.content[i].eq(other.content[i])) { return false } }
return true

@@ -164,3 +164,3 @@ };

var found = this.content[index]
if (!found) throw new RangeError("Index " + index + " out of range for " + this)
if (!found) { throw new RangeError("Index " + index + " out of range for " + this) }
return found

@@ -175,3 +175,3 @@ };

var offset = 0
for (var i = 0; i < index; i++) offset += this$1.content[i].nodeSize
for (var i = 0; i < index; i++) { offset += this$1.content[i].nodeSize }
return offset

@@ -228,9 +228,9 @@ };

if (pos == 0) return retIndex(0, pos)
if (pos == this.size) return retIndex(this.content.length, pos)
if (pos > this.size || pos < 0) throw new RangeError(("Position " + pos + " outside of fragment (" + (this) + ")"))
if (pos == 0) { return retIndex(0, pos) }
if (pos == this.size) { return retIndex(this.content.length, pos) }
if (pos > this.size || pos < 0) { throw new RangeError(("Position " + pos + " outside of fragment (" + (this) + ")")) }
for (var i = 0, curPos = 0;; i++) {
var cur = this$1.child(i), end = curPos + cur.nodeSize
if (end >= pos) {
if (end == pos || round > 0) return retIndex(i + 1, end)
if (end == pos || round > 0) { return retIndex(i + 1, end) }
return retIndex(i, curPos)

@@ -264,3 +264,3 @@ }

Fragment.fromArray = function fromArray (array) {
if (!array.length) return Fragment.empty
if (!array.length) { return Fragment.empty }
var joined, size = 0

@@ -271,3 +271,3 @@ for (var i = 0; i < array.length; i++) {

if (i && node.isText && array[i - 1].sameMarkup(node)) {
if (!joined) joined = array.slice(0, i)
if (!joined) { joined = array.slice(0, i) }
joined[joined.length - 1] = node.withText(joined[joined.length - 1].text + node.text)

@@ -287,5 +287,5 @@ } else if (joined) {

Fragment.from = function from (nodes) {
if (!nodes) return Fragment.empty
if (nodes instanceof Fragment) return nodes
if (Array.isArray(nodes)) return this.fromArray(nodes)
if (!nodes) { return Fragment.empty }
if (nodes instanceof Fragment) { return nodes }
if (Array.isArray(nodes)) { return this.fromArray(nodes) }
return new Fragment([nodes], nodes.nodeSize)

@@ -292,0 +292,0 @@ };

@@ -71,4 +71,4 @@ var ref = require("./fragment");

rules.forEach(function (rule) {
if (rule.tag) this$1.tags.push(rule)
else if (rule.style) this$1.styles.push(rule)
if (rule.tag) { this$1.tags.push(rule) }
else if (rule.style) { this$1.styles.push(rule) }
})

@@ -115,5 +115,5 @@ };

anonymous.prototype.enter = function enter (type, attrs, preserveWhitespace) {
if (openLeft == null) openLeft = type.isTextblock ? 1 : 0
if (openLeft > 0 && this.top.match.matchType(type, attrs)) openLeft = 0
if (openLeft == 0) return DOMParseState.prototype.enter.call(this, type, attrs, preserveWhitespace)
if (openLeft == null) { openLeft = type.isTextblock ? 1 : 0 }
if (openLeft > 0 && this.top.match.matchType(type, attrs)) { openLeft = 0 }
if (openLeft == 0) { return DOMParseState.prototype.enter.call(this, type, attrs, preserveWhitespace) }

@@ -128,3 +128,3 @@ openLeft--

var openTo = top.openDepth, doc = top.finish(openTo), $startPos = doc.resolve(startPos)
for (var d = $startPos.depth; d >= 0 && startPos == $startPos.end(d); d--) ++startPos
for (var d = $startPos.depth; d >= 0 && startPos == $startPos.end(d); d--) { ++startPos }
return doc.slice(startPos, doc.content.size - openTo)

@@ -141,3 +141,3 @@ };

var result = rule.getAttrs(dom)
if (result === false) continue
if (result === false) { continue }
rule.attrs = result

@@ -158,3 +158,3 @@ }

var result = rule.getAttrs(value)
if (result === false) continue
if (result === false) { continue }
rule.attrs = result

@@ -174,6 +174,6 @@ }

var rules = schema.marks[name].spec.parseDOM
if (rules) rules.forEach(function (rule) {
if (rules) { rules.forEach(function (rule) {
result.push(rule = copy(rule))
rule.mark = name
})
}) }
};

@@ -184,6 +184,6 @@

var rules$1 = schema.nodes[name$1].spec.parseDOM
if (rules$1) rules$1.forEach(function (rule) {
if (rules$1) { rules$1.forEach(function (rule) {
result.push(rule = copy(rule))
rule.node = name$1
})
}) }
};

@@ -209,5 +209,5 @@

if (i == 0)
builder = top = new NodeBuilder(node.type, node.attrs, true, null, match, preserveWhitespace)
{ builder = top = new NodeBuilder(node.type, node.attrs, true, null, match, preserveWhitespace) }
else
builder = builder.start(node.type, node.attrs, false, match, preserveWhitespace)
{ builder = builder.start(node.type, node.attrs, false, match, preserveWhitespace) }
}

@@ -257,3 +257,3 @@ return {builder: builder, top: top}

}
if (!matched) return null
if (!matched) { return null }
this.closeChild()

@@ -269,3 +269,3 @@ this.content.push(node)

var matched = this.match.matchType(type, attrs)
if (!matched) return null
if (!matched) { return null }
this.closeChild()

@@ -286,7 +286,7 @@ this.match = matched

NodeBuilder.prototype.stripTrailingSpace = function stripTrailingSpace () {
if (this.openChild) return
if (this.openChild) { return }
var last = this.content[this.content.length - 1], m
if (last && last.isText && (m = /\s+$/.exec(last.text))) {
if (last.text.length == m[0].length) this.content.pop()
else this.content[this.content.length - 1] = last.withText(last.text.slice(0, last.text.length - m[0].length))
if (last.text.length == m[0].length) { this.content.pop() }
else { this.content[this.content.length - 1] = last.withText(last.text.slice(0, last.text.length - m[0].length)) }
}

@@ -300,6 +300,6 @@ };

NodeBuilder.prototype.finish = function finish (openRight) {
if (!openRight && !this.preserveWhitespace) this.stripTrailingSpace()
if (!openRight && !this.preserveWhitespace) { this.stripTrailingSpace() }
this.closeChild(openRight)
var content = Fragment.from(this.content)
if (!openRight) content = content.append(this.match.fillBefore(Fragment.empty, true))
if (!openRight) { content = content.append(this.match.fillBefore(Fragment.empty, true)) }
return this.type.create(this.match.attrs, content)

@@ -320,10 +320,10 @@ };

builder = top
if (!found.length) break
if (!found.length) { break }
}
if (top.solid) break
if (top.solid) { break }
}
if (!route) return null
if (!route) { return null }
for (var i = 0; i < route.length; i++)
builder = builder.start(route[i].type, route[i].attrs, false)
{ builder = builder.start(route[i].type, route[i].attrs, false) }
return node ? builder.add(node) && builder : builder.start(type, attrs, true, null, preserveWhitespace)

@@ -334,3 +334,3 @@ };

var d = 0
for (var b = this.prev; b; b = b.prev) d++
for (var b = this.prev; b; b = b.prev) { d++ }
return d

@@ -341,3 +341,3 @@ };

var d = 0
for (var c = this.openChild; c; c = c.openChild) d++
for (var c = this.openChild; c; c = c.openChild) { d++ }
return d

@@ -351,3 +351,3 @@ };

for (var i = 0; i < this.content.length; i++)
pos += this$1.content[i].nodeSize
{ pos += this$1.content[i].nodeSize }
return pos

@@ -405,2 +405,4 @@ };

DOMParseState.prototype.addDOM = function addDOM (dom) {
var this$1 = this;
if (dom.nodeType == 3) {

@@ -415,6 +417,6 @@ var value = dom.nodeValue

// leading space.
if (/^\s/.test(value)) top.stripTrailingSpace()
if (/^\s/.test(value)) { top.stripTrailingSpace() }
}
if (value)
this.insertNode(this.parser.schema.text(value, this.marks))
{ this.insertNode(this.parser.schema.text(value, this.marks)) }
this.findInText(dom)

@@ -425,5 +427,10 @@ } else {

} else if (dom.nodeType == 1 && !dom.hasAttribute("pm-ignore")) {
var style = dom.getAttribute("style")
if (style) this.addElementWithStyles(parseStyles(style), dom)
else this.addElement(dom)
if (dom.hasAttribute("pm-decoration")) {
for (var child = dom.firstChild; child; child = child.nextSibling)
{ this$1.addDOM(child) }
} else {
var style = dom.getAttribute("style")
if (style) { this.addElementWithStyles(parseStyles(style), dom) }
else { this.addElement(dom) }
}
}

@@ -437,5 +444,5 @@ };

var name = dom.nodeName.toLowerCase()
if (listTags.hasOwnProperty(name)) this.normalizeList(dom)
if (listTags.hasOwnProperty(name)) { this.normalizeList(dom) }
// Ignore trailing BR nodes, which browsers create during editing
if (this.options.editableContent && name == "br" && !dom.nextSibling) return
if (this.options.editableContent && name == "br" && !dom.nextSibling) { return }
if (!this.parseNodeType(dom, name)) {

@@ -447,3 +454,3 @@ if (ignoreTags.hasOwnProperty(name)) {

this.addAll(dom)
if (sync) this.sync(sync)
if (sync) { this.sync(sync) }
}

@@ -462,4 +469,4 @@ }

var rule = this$1.parser.matchStyle(styles[i], styles[i + 1])
if (!rule) continue
if (rule.ignore) return
if (!rule) { continue }
if (rule.ignore) { return }
marks = this$1.parser.schema.marks[rule.mark].create(rule.attrs).addToSet(marks)

@@ -478,4 +485,4 @@ }

var rule = this.parser.matchTag(dom)
if (!rule) return false
if (rule.ignore) return true
if (!rule) { return false }
if (rule.ignore) { return true }

@@ -487,4 +494,4 @@ var sync, before, nodeType, markType

nodeType = this.parser.schema.nodes[rule.node]
if (nodeType.isLeaf) this.insertNode(nodeType.create(rule.attrs))
else sync = this.enter(nodeType, rule.attrs, rule.preserveWhitespace)
if (nodeType.isLeaf) { this.insertNode(nodeType.create(rule.attrs)) }
else { sync = this.enter(nodeType, rule.attrs, rule.preserveWhitespace) }
} else {

@@ -498,4 +505,4 @@ markType = this.parser.schema.marks[rule.mark]

this.addAll(contentDOM, sync)
if (sync) this.sync(sync.prev)
else if (before) this.marks = before
if (sync) { this.sync(sync.prev) }
else if (before) { this.marks = before }
this.findAround(dom, contentDOM, true)

@@ -522,3 +529,3 @@ } else {

if (sync && blockTags.hasOwnProperty(dom.nodeName.toLowerCase()))
this$1.sync(sync)
{ this$1.sync(sync) }
}

@@ -559,6 +566,6 @@ this.findAtPoint(parent, index)

for (;;) {
for (var cur = to; cur; cur = cur.prev) if (cur == this$1.top) {
for (var cur = to; cur; cur = cur.prev) { if (cur == this$1.top) {
this$1.top = to
return
}
} }
this$1.leave()

@@ -588,6 +595,6 @@ }

if (this.find) for (var i = 0; i < this.find.length; i++) {
if (this.find) { for (var i = 0; i < this.find.length; i++) {
if (this$1.find[i].node == parent && this$1.find[i].offset == offset)
this$1.find[i].pos = this$1.top.currentPos
}
{ this$1.find[i].pos = this$1.top.currentPos }
} }
};

@@ -598,6 +605,6 @@

if (this.find) for (var i = 0; i < this.find.length; i++) {
if (this.find) { for (var i = 0; i < this.find.length; i++) {
if (this$1.find[i].pos == null && parent.contains(this$1.find[i].node))
this$1.find[i].pos = this$1.top.currentPos
}
{ this$1.find[i].pos = this$1.top.currentPos }
} }
};

@@ -608,9 +615,9 @@

if (parent != content && this.find) for (var i = 0; i < this.find.length; i++) {
if (parent != content && this.find) { for (var i = 0; i < this.find.length; i++) {
if (this$1.find[i].pos == null && parent.contains(this$1.find[i].node)) {
var pos = content.compareDocumentPosition(this$1.find[i].node)
if (pos & (before ? 2 : 4))
this$1.find[i].pos = this$1.top.currentPos
{ this$1.find[i].pos = this$1.top.currentPos }
}
}
} }
};

@@ -621,6 +628,6 @@

if (this.find) for (var i = 0; i < this.find.length; i++) {
if (this.find) { for (var i = 0; i < this.find.length; i++) {
if (this$1.find[i].node == textNode)
this$1.find[i].pos = this$1.top.currentPos - (textNode.nodeValue.length - this$1.find[i].offset)
}
{ this$1.find[i].pos = this$1.top.currentPos - (textNode.nodeValue.length - this$1.find[i].offset) }
} }
};

@@ -637,3 +644,3 @@

var re = /\s*([\w-]+)\s*:\s*([^;]+)/g, m, result = []
while (m = re.exec(style)) result.push(m[1], m[2].trim())
while (m = re.exec(style)) { result.push(m[1], m[2].trim()) }
return result

@@ -644,4 +651,4 @@ }

var copy = {}
for (var prop in obj) copy[prop] = obj[prop]
for (var prop in obj) { copy[prop] = obj[prop] }
return copy
}

@@ -31,3 +31,3 @@ var ref = require("./comparedeep");

if (other.type == this$1.type) {
if (this$1.eq(other)) return set
if (this$1.eq(other)) { return set }
var copy = set.slice()

@@ -38,3 +38,3 @@ copy[i] = this$1

if (other.type.rank > this$1.type.rank)
return set.slice(0, i).concat(this$1).concat(set.slice(i))
{ return set.slice(0, i).concat(this$1).concat(set.slice(i)) }
}

@@ -51,4 +51,4 @@ return set.concat(this)

for (var i = 0; i < set.length; i++)
if (this$1.eq(set[i]))
return set.slice(0, i).concat(set.slice(i + 1))
{ if (this$1.eq(set[i]))
{ return set.slice(0, i).concat(set.slice(i + 1)) } }
return set

@@ -63,3 +63,3 @@ };

for (var i = 0; i < set.length; i++)
if (this$1.eq(set[i])) return true
{ if (this$1.eq(set[i])) { return true } }
return false

@@ -72,5 +72,5 @@ };

Mark.prototype.eq = function eq (other) {
if (this == other) return true
if (this.type != other.type) return false
if (!compareDeep(other.attrs, this.attrs)) return false
if (this == other) { return true }
if (this.type != other.type) { return false }
if (!compareDeep(other.attrs, this.attrs)) { return false }
return true

@@ -100,6 +100,6 @@ };

Mark.sameSet = function sameSet (a, b) {
if (a == b) return true
if (a.length != b.length) return false
if (a == b) { return true }
if (a.length != b.length) { return false }
for (var i = 0; i < a.length; i++)
if (!a[i].eq(b[i])) return false
{ if (!a[i].eq(b[i])) { return false } }
return true

@@ -112,4 +112,4 @@ };

Mark.setFrom = function setFrom (marks) {
if (!marks || marks.length == 0) return Mark.none
if (marks instanceof Mark) return [marks]
if (!marks || marks.length == 0) { return Mark.none }
if (marks instanceof Mark) { return [marks] }
var copy = marks.slice()

@@ -116,0 +116,0 @@ copy.sort(function (a, b) { return a.type.rank - b.type.rank; })

@@ -147,3 +147,3 @@ var ref = require("./fragment");

if (content == this.content) return this
if (content == this.content) { return this }
return new this.constructor(this.type, this.attrs, content, this.marks)

@@ -164,3 +164,3 @@ };

Node.prototype.cut = function cut (from, to) {
if (from == 0 && to == this.content.size) return this
if (from == 0 && to == this.content.size) { return this }
return this.copy(this.content.cut(from, to))

@@ -175,3 +175,3 @@ };

if (from == to) return Slice.empty
if (from == to) { return Slice.empty }

@@ -203,4 +203,4 @@ var $from = this.resolve(from), $to = this.resolve(to)

node = node.maybeChild(index)
if (!node) return null
if (offset == pos || node.isText) return node
if (!node) { return null }
if (offset == pos || node.isText) { return node }
pos -= offset + 1

@@ -226,7 +226,7 @@ }

Node.prototype.childBefore = function childBefore (pos) {
if (pos == 0) return {node: null, index: 0, offset: 0}
if (pos == 0) { return {node: null, index: 0, offset: 0} }
var ref = this.content.findIndex(pos);
var index = ref.index;
var offset = ref.offset;
if (offset < pos) return {node: this.content.child(index), index: index, offset: offset}
if (offset < pos) { return {node: this.content.child(index), index: index, offset: offset} }
var node = this.content.child(index - 1)

@@ -252,9 +252,9 @@ return {node: node, index: index - 1, offset: offset - node.nodeSize}

// In an empty parent, return the empty array
if (parent.content.size == 0) return Mark.none
if (parent.content.size == 0) { return Mark.none }
// 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.atNodeBoundary) { return parent.child(index).marks }
var marks = parent.child(index - 1).marks
for (var i = 0; i < marks.length; i++) if (marks[i].type.inclusiveRight === false)
marks = marks[i--].removeFromSet(marks)
for (var i = 0; i < marks.length; i++) { if (marks[i].type.inclusiveRight === false)
{ marks = marks[i--].removeFromSet(marks) } }
return marks

@@ -269,3 +269,3 @@ };

this.nodesBetween(from, to, function (node) {
if (type.isInSet(node.marks)) found = true
if (type.isInSet(node.marks)) { found = true }
return !found

@@ -304,3 +304,3 @@ })

if (this.content.size)
name += "(" + this.content.toStringInner() + ")"
{ name += "(" + this.content.toStringInner() + ")" }
return wrapMarks(this.marks, name)

@@ -339,4 +339,4 @@ };

Node.prototype.canAppend = function canAppend (other) {
if (other.content.size) return this.canReplace(this.childCount, this.childCount, other.content)
else return this.type.compatibleContent(other.type)
if (other.content.size) { return this.canReplace(this.childCount, this.childCount, other.content) }
else { return this.type.compatibleContent(other.type) }
};

@@ -360,5 +360,5 @@

if (this.content.size)
obj.content = this.content.toJSON()
{ obj.content = this.content.toJSON() }
if (this.marks.length)
obj.marks = this.marks.map(function (n) { return n.toJSON(); })
{ obj.marks = this.marks.map(function (n) { return n.toJSON(); }) }
return obj

@@ -371,3 +371,3 @@ };

var marks = json.marks && json.marks.map(schema.markFromJSON)
if (json.type == "text") return schema.text(json.text, marks)
if (json.type == "text") { return schema.text(json.text, marks) }
return schema.nodeType(json.type).create(json.attrs, Fragment.fromJSON(schema, json.content), marks)

@@ -383,3 +383,3 @@ };

if (!content) throw new RangeError("Empty text nodes are not allowed")
if (!content) { throw new RangeError("Empty text nodes are not allowed") }

@@ -408,3 +408,3 @@ this.text = content

TextNode.prototype.withText = function withText (text) {
if (text == this.text) return this
if (text == this.text) { return this }
return new TextNode(this.type, this.attrs, text, this.marks)

@@ -417,3 +417,3 @@ };

if (from == 0 && to == this.text.length) return this
if (from == 0 && to == this.text.length) { return this }
return this.withText(this.text.slice(from, to))

@@ -440,4 +440,4 @@ };

for (var i = marks.length - 1; i >= 0; i--)
str = marks[i].type.name + "(" + str + ")"
{ str = marks[i].type.name + "(" + str + ")" }
return str
}

@@ -13,3 +13,3 @@ // ::- Persistent data structure representing an ordered mapping from

for (var i = 0; i < this.content.length; i += 2)
if (this$1.content[i] == key) return i
{ if (this$1.content[i] == key) { return i } }
return -1

@@ -37,3 +37,3 @@ };

content[found + 1] = value
if (newKey) content[found] = newKey
if (newKey) { content[found] = newKey }
}

@@ -47,3 +47,3 @@ return new OrderedMap(content)

var found = this.find(key)
if (found == -1) return this
if (found == -1) { return this }
var content = this.content.slice()

@@ -85,3 +85,3 @@ content.splice(found, 2)

for (var i = 0; i < this.content.length; i += 2)
f(this$1.content[i], this$1.content[i + 1])
{ f(this$1.content[i], this$1.content[i + 1]) }
};

@@ -94,3 +94,3 @@

map = OrderedMap.from(map)
if (!map.size) return this
if (!map.size) { return this }
return new OrderedMap(map.content.concat(this.subtract(map).content))

@@ -104,3 +104,3 @@ };

map = OrderedMap.from(map)
if (!map.size) return this
if (!map.size) { return this }
return new OrderedMap(this.subtract(map).content.concat(map.content))

@@ -129,5 +129,5 @@ };

OrderedMap.from = function from (value) {
if (value instanceof OrderedMap) return value
if (value instanceof OrderedMap) { return value }
var content = []
if (value) for (var prop in value) content.push(prop, value[prop])
if (value) { for (var prop in value) { content.push(prop, value[prop]) } }
return new OrderedMap(content)

@@ -134,0 +134,0 @@ };

@@ -48,3 +48,3 @@ var ref = require("./fragment");

if (offset == dist || child.isText) {
if (parent && !parent.canReplace(index, index, insert)) return null
if (parent && !parent.canReplace(index, index, insert)) { return null }
return content.cut(0, dist).append(insert).append(content.cut(dist))

@@ -69,6 +69,6 @@ }

if (offset == from || child.isText) {
if (offsetTo != to && !content.child(indexTo).isText) throw new RangeError("Removing non-flat range")
if (offsetTo != to && !content.child(indexTo).isText) { throw new RangeError("Removing non-flat range") }
return content.cut(0, from).append(content.cut(to))
}
if (index != indexTo) throw new RangeError("Removing non-flat range")
if (index != indexTo) { throw new RangeError("Removing non-flat range") }
return content.replaceChild(index, child.copy(removeRange(child.content, from - offset - 1, to - offset - 1)))

@@ -90,3 +90,3 @@ }

Slice.prototype.toJSON = function toJSON () {
if (!this.content.size) return null
if (!this.content.size) { return null }
return {content: this.content.toJSON(),

@@ -100,3 +100,3 @@ openLeft: this.openLeft,

Slice.fromJSON = function fromJSON (schema, json) {
if (!json) return Slice.empty
if (!json) { return Slice.empty }
return new Slice(Fragment.fromJSON(schema, json.content), json.openLeft, json.openRight)

@@ -114,5 +114,5 @@ };

if (slice.openLeft > $from.depth)
throw new ReplaceError("Inserted content deeper than insertion position")
{ throw new ReplaceError("Inserted content deeper than insertion position") }
if ($from.depth - slice.openLeft != $to.depth - slice.openRight)
throw new ReplaceError("Inconsistent open depths")
{ throw new ReplaceError("Inconsistent open depths") }
return replaceOuter($from, $to, slice, 0)

@@ -139,3 +139,3 @@ }

if (!sub.type.compatibleContent(main.type))
throw new ReplaceError("Cannot join " + sub.type.name + " onto " + main.type.name)
{ throw new ReplaceError("Cannot join " + sub.type.name + " onto " + main.type.name) }
}

@@ -152,5 +152,5 @@

if (last >= 0 && child.isText && child.sameMarkup(target[last]))
target[last] = child.withText(target[last].text + child.text)
{ target[last] = child.withText(target[last].text + child.text) }
else
target.push(child)
{ target.push(child) }
}

@@ -170,5 +170,5 @@

}
for (var i = startIndex; i < endIndex; i++) addNode(node.child(i), target)
for (var i = startIndex; i < endIndex; i++) { addNode(node.child(i), target) }
if ($end && $end.depth == depth && !$end.atNodeBoundary)
addNode($end.nodeBefore, target)
{ addNode($end.nodeBefore, target) }
}

@@ -178,3 +178,3 @@

if (!node.type.validContent(content, node.attrs))
throw new ReplaceError("Invalid content for node " + node.type.name)
{ throw new ReplaceError("Invalid content for node " + node.type.name) }
return node.copy(content)

@@ -194,6 +194,6 @@ }

if (openLeft)
addNode(close(openLeft, replaceTwoWay($from, $start, depth + 1)), content)
{ addNode(close(openLeft, replaceTwoWay($from, $start, depth + 1)), content) }
addRange($start, $end, depth, content)
if (openRight)
addNode(close(openRight, replaceTwoWay($end, $to, depth + 1)), content)
{ addNode(close(openRight, replaceTwoWay($end, $to, depth + 1)), content) }
}

@@ -219,5 +219,5 @@ addRange($to, null, depth, content)

for (var i = extra - 1; i >= 0; i--)
node = $along.node(i).copy(Fragment.from(node))
{ node = $along.node(i).copy(Fragment.from(node)) }
return {start: node.resolveNoCache(slice.openLeft + extra),
end: node.resolveNoCache(node.content.size - slice.openRight - extra)}
}

@@ -25,4 +25,4 @@ // ::- You'll often have to '[resolve](#model.Node.resolve)' a

ResolvedPos.prototype.resolveDepth = function resolveDepth (val) {
if (val == null) return this.depth
if (val < 0) return this.depth + val
if (val == null) { return this.depth }
if (val < 0) { return this.depth + val }
return val

@@ -78,3 +78,3 @@ };

depth = this.resolveDepth(depth)
if (!depth) throw new RangeError("There is no position before the top-level node")
if (!depth) { throw new RangeError("There is no position before the top-level node") }
return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1]

@@ -89,3 +89,3 @@ };

depth = this.resolveDepth(depth)
if (!depth) throw new RangeError("There is no position after the top-level node")
if (!depth) { throw new RangeError("There is no position after the top-level node") }
return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1] + this.path[depth * 3].nodeSize

@@ -105,3 +105,3 @@ };

var parent = this.parent, index = this.index(this.depth)
if (index == parent.childCount) return null
if (index == parent.childCount) { return null }
var dOff = this.pos - this.path[this.path.length - 1], child = parent.child(index)

@@ -118,3 +118,3 @@ return dOff ? parent.child(index).cut(dOff) : child

var dOff = this.pos - this.path[this.path.length - 1]
if (dOff) return this.parent.child(index).cut(0, dOff)
if (dOff) { return this.parent.child(index).cut(0, dOff) }
return index == 0 ? null : this.parent.child(index - 1)

@@ -128,3 +128,3 @@ };

var depth = 0, max = Math.min(this.depth, other.depth)
while (depth < max && this.index(depth) == other.index(depth)) ++depth
while (depth < max && this.index(depth) == other.index(depth)) { ++depth }
return depth

@@ -146,6 +146,6 @@ };

if (other.pos < this.pos) return other.blockRange(this)
if (other.pos < this.pos) { return other.blockRange(this) }
for (var d = this.depth - (this.parent.isTextblock || this.pos == other.pos ? 1 : 0); d >= 0; d--)
if (other.pos <= this$1.end(d) && (!pred || pred(this$1.node(d))))
return new NodeRange(this$1, other, d)
{ if (other.pos <= this$1.end(d) && (!pred || pred(this$1.node(d))))
{ return new NodeRange(this$1, other, d) } }
};

@@ -164,3 +164,3 @@

for (var i = 1; i <= this.depth; i++)
str += (str ? "/" : "") + this$1.node(i).type.name + "_" + this$1.index(i - 1)
{ str += (str ? "/" : "") + this$1.node(i).type.name + "_" + this$1.index(i - 1) }
return str + ":" + this.parentOffset

@@ -177,3 +177,3 @@ };

ResolvedPos.resolve = function resolve (doc, pos) {
if (!(pos >= 0 && pos <= doc.content.size)) throw new RangeError("Position " + pos + " out of range")
if (!(pos >= 0 && pos <= doc.content.size)) { throw new RangeError("Position " + pos + " out of range") }
var path = []

@@ -187,5 +187,5 @@ var start = 0, parentOffset = pos

path.push(node, index, start + offset)
if (!rem) break
if (!rem) { break }
node = node.child(index)
if (node.isText) break
if (node.isText) { break }
parentOffset = rem - 1

@@ -200,3 +200,3 @@ start += offset + 1

var cached = resolveCache[i]
if (cached.pos == pos && cached.node(0) == doc) return cached
if (cached.pos == pos && cached.node(0) == doc) { return cached }
}

@@ -203,0 +203,0 @@ var result = resolveCache[resolveCachePos] = ResolvedPos.resolve(doc, pos)

@@ -21,3 +21,3 @@ var ref = require("./node");

var attr = attrs[attrName]
if (attr.default === undefined) return null
if (attr.default === undefined) { return null }
defaults[attrName] = attr.default

@@ -35,7 +35,7 @@ }

if (attr.default !== undefined)
given = attr.default
{ given = attr.default }
else if (attr.compute)
given = attr.compute()
{ given = attr.compute() }
else
throw new RangeError("No value supplied for attribute " + name)
{ throw new RangeError("No value supplied for attribute " + name) }
}

@@ -49,3 +49,3 @@ built[name] = given

var result = Object.create(null)
if (attrs) for (var name in attrs) result[name] = new Attribute(attrs[name])
if (attrs) { for (var name in attrs) { result[name] = new Attribute(attrs[name]) } }
return result

@@ -104,3 +104,3 @@ }

for (var n in this.attrs)
if (this$1.attrs[n].isRequired && (!ignore || !(n in ignore))) return true
{ if (this$1.attrs[n].isRequired && (!ignore || !(n in ignore))) { return true } }
return false

@@ -114,4 +114,4 @@ };

NodeType.prototype.computeAttrs = function computeAttrs$1 (attrs) {
if (!attrs && this.defaultAttrs) return this.defaultAttrs
else return computeAttrs(this.attrs, attrs)
if (!attrs && this.defaultAttrs) { return this.defaultAttrs }
else { return computeAttrs(this.attrs, attrs) }
};

@@ -127,3 +127,3 @@

NodeType.prototype.create = function create (attrs, content, marks) {
if (typeof content == "string") throw new Error("Calling create with string")
if (typeof content == "string") { throw new Error("Calling create with string") }
return new Node(this, this.computeAttrs(attrs), Fragment.from(content), Mark.setFrom(marks))

@@ -140,3 +140,3 @@ };

if (!this.validContent(content, attrs))
throw new RangeError("Invalid content for node " + this.name)
{ throw new RangeError("Invalid content for node " + this.name) }
return new Node(this, attrs, content, Mark.setFrom(marks))

@@ -157,7 +157,7 @@ };

var before = this.contentExpr.start(attrs).fillBefore(content)
if (!before) return null
if (!before) { return null }
content = before.append(content)
}
var after = this.contentExpr.getMatchAt(attrs, content).fillBefore(Fragment.empty, true)
if (!after) return null
if (!after) { return null }
return new Node(this, attrs, content.append(after), Mark.setFrom(marks))

@@ -177,4 +177,4 @@ };

if (!result.doc) throw new RangeError("Every schema needs a 'doc' type")
if (!result.text) throw new RangeError("Every schema needs a 'text' type")
if (!result.doc) { throw new RangeError("Every schema needs a 'doc' type") }
if (!result.text) { throw new RangeError("Every schema needs a 'text' type") }

@@ -232,3 +232,3 @@ return result

MarkType.prototype.create = function create (attrs) {
if (!attrs && this.instance) return this.instance
if (!attrs && this.instance) { return this.instance }
return new Mark(this, computeAttrs(this.attrs, attrs))

@@ -250,4 +250,4 @@ };

for (var i = 0; i < set.length; i++)
if (set[i].type == this$1)
return set.slice(0, i).concat(set.slice(i + 1))
{ if (set[i].type == this$1)
{ return set.slice(0, i).concat(set.slice(i + 1)) } }
return set

@@ -262,3 +262,3 @@ };

for (var i = 0; i < set.length; i++)
if (set[i].type == this$1) return set[i]
{ if (set[i].type == this$1) { return set[i] } }
};

@@ -383,3 +383,3 @@ exports.MarkType = MarkType

if (prop in this$1.marks)
throw new RangeError(prop + " can not be both a node and a mark")
{ throw new RangeError(prop + " can not be both a node and a mark") }
var type = this$1.nodes[prop]

@@ -407,7 +407,7 @@ type.contentExpr = ContentExpr.parse(type, this$1.nodeSpec.get(prop).content || "", this$1.nodeSpec)

if (typeof type == "string")
type = this.nodeType(type)
{ type = this.nodeType(type) }
else if (!(type instanceof NodeType))
throw new RangeError("Invalid node type: " + type)
{ throw new RangeError("Invalid node type: " + type) }
else if (type.schema != this)
throw new RangeError("Node type from different schema used (" + type.name + ")")
{ throw new RangeError("Node type from different schema used (" + type.name + ")") }

@@ -428,3 +428,3 @@ return type.createChecked(attrs, content, marks)

Schema.prototype.mark = function mark (type, attrs) {
if (typeof type == "string") type = this.marks[type]
if (typeof type == "string") { type = this.marks[type] }
return type.create(attrs)

@@ -449,5 +449,5 @@ };

var found = this.nodes[name]
if (!found) throw new RangeError("Unknown node type: " + name)
if (!found) { throw new RangeError("Unknown node type: " + name) }
return found
};
exports.Schema = Schema

@@ -29,6 +29,29 @@ // DOMOutputSpec:: interface

// nodes.
DOMSerializer.prototype.serializeFragment = function serializeFragment (fragment, options) {
DOMSerializer.prototype.serializeFragment = function serializeFragment (fragment, options, target) {
var this$1 = this;
if ( options === void 0 ) options = {};
return new DOMSerialization(this, options).renderFragment(fragment, null, options.pos || 0)
if (!target) { target = doc(options).createDocumentFragment() }
var top = target, active = null
fragment.forEach(function (node) {
if (active || node.marks.length) {
if (!active) { active = [] }
var keep = 0
for (; keep < Math.min(active.length, node.marks.length); ++keep)
{ if (!node.marks[keep].eq(active[keep])) { break } }
while (keep < active.length) {
active.pop()
top = top.parentNode
}
while (active.length < node.marks.length) {
var add = node.marks[active.length]
active.push(add)
top = top.appendChild(this$1.serializeMark(add, options))
}
}
top.appendChild(this$1.serializeNode(node, options))
})
return target
};

@@ -45,8 +68,14 @@

var context = new DOMSerialization(this, options), pos = options.pos || 0
var dom = context.renderNode(node, pos, options.offset || 0)
if (node.isInline) {
dom = context.wrapInlineFlat(dom, node.marks)
if (context.options.renderInlineFlat)
dom = context.options.renderInlineFlat(node, dom, pos, options.offset || 0) || dom
return this.renderStructure(this.nodes[node.type.name](node), node, options)
};
DOMSerializer.prototype.serializeNodeAndMarks = function serializeNodeAndMarks (node, options) {
var this$1 = this;
if ( options === void 0 ) options = {};
var dom = this.serializeNode(node, options)
for (var i = node.marks.length - 1; i >= 0; i--) {
var wrap = this$1.serializeMark(node.marks[i], options)
wrap.appendChild(dom)
dom = wrap
}

@@ -56,2 +85,41 @@ return dom

DOMSerializer.prototype.serializeMark = function serializeMark (mark, options) {
if ( options === void 0 ) options = {};
return this.renderStructure(this.marks[mark.type.name](mark), null, options)
};
DOMSerializer.prototype.renderStructure = function renderStructure (structure, node, options) {
var this$1 = this;
if (typeof structure == "string")
{ return doc(options).createTextNode(structure) }
if (structure.nodeType != null)
{ return structure }
var dom = doc(options).createElement(structure[0]), attrs = structure[1], start = 1
if (attrs && typeof attrs == "object" && attrs.nodeType == null && !Array.isArray(attrs)) {
start = 2
for (var name in attrs) {
if (name == "style") { dom.style.cssText = attrs[name] }
else if (attrs[name] != null) { dom.setAttribute(name, attrs[name]) }
}
}
for (var i = start; i < structure.length; i++) {
var child = structure[i]
if (child === 0) {
if (!node || node.isLeaf)
{ throw new RangeError("Content hole not allowed in a mark or leaf node spec (must produce a single node)") }
if (i < structure.length - 1 || i > start)
{ throw new RangeError("Content hole must be the only child of its parent node") }
if (options.onContent)
{ options.onContent(node, dom, options) }
else
{ this$1.serializeFragment(node.content, options, dom) }
} else {
dom.appendChild(this$1.renderStructure(child, node, options))
}
}
return dom
};
// :: (Schema) → DOMSerializer

@@ -83,3 +151,3 @@ // Build a serializer using the [`toDOM`](#model.NodeSpec.toDOM)

var toDOM = obj[name].spec.toDOM
if (toDOM) result[name] = toDOM
if (toDOM) { result[name] = toDOM }
}

@@ -89,116 +157,5 @@ return result

// Context object used during serialization.
var DOMSerialization = function DOMSerialization(serializer, options) {
// : Object The options passed to the serializer.
this.options = options || {}
// : dom.Document The DOM document in which we are working.
function doc(options) {
// declare global: window
this.doc = this.options.document || window.document
this.nodes = serializer.nodes
this.marks = serializer.marks
};
DOMSerialization.prototype.renderNode = function renderNode (node, pos, offset) {
var dom = this.renderStructure(this.nodes[node.type.name](node), node.content, pos + 1)
if (this.options.onRender)
dom = this.options.onRender(node, dom, pos, offset) || dom
return dom
};
DOMSerialization.prototype.renderStructure = function renderStructure (structure, content, startPos) {
var this$1 = this;
if (typeof structure == "string")
return this.doc.createTextNode(structure)
if (structure.nodeType != null)
return structure
var dom = this.doc.createElement(structure[0]), attrs = structure[1], start = 1
if (attrs && typeof attrs == "object" && attrs.nodeType == null && !Array.isArray(attrs)) {
start = 2
for (var name in attrs) {
if (name == "style") dom.style.cssText = attrs[name]
else if (attrs[name]) dom.setAttribute(name, attrs[name])
}
}
for (var i = start; i < structure.length; i++) {
var child = structure[i]
if (child === 0) {
if (!content)
throw new RangeError("Content hole not allowed in a Mark spec (must produce a single node)")
if (i < structure.length - 1 || i > start)
throw new RangeError("Content hole must be the only child of its parent node")
if (this$1.options.onContainer) this$1.options.onContainer(dom)
this$1.renderFragment(content, dom, startPos)
} else {
dom.appendChild(this$1.renderStructure(child, content, startPos))
}
}
return dom
};
DOMSerialization.prototype.renderFragment = function renderFragment (fragment, where, startPos) {
if (!where) where = this.doc.createDocumentFragment()
if (fragment.size == 0) return where
if (!fragment.firstChild.isInline)
this.renderBlocksInto(fragment, where, startPos)
else if (this.options.renderInlineFlat)
this.renderInlineFlatInto(fragment, where, startPos)
else
this.renderInlineInto(fragment, where, startPos)
return where
};
DOMSerialization.prototype.renderBlocksInto = function renderBlocksInto (fragment, where, startPos) {
var this$1 = this;
fragment.forEach(function (node, offset) { return where.appendChild(this$1.renderNode(node, startPos + offset, offset)); })
};
DOMSerialization.prototype.renderInlineInto = function renderInlineInto (fragment, where, startPos) {
var this$1 = this;
var top = where
var active = []
fragment.forEach(function (node, offset) {
var keep = 0
for (; keep < Math.min(active.length, node.marks.length); ++keep)
if (!node.marks[keep].eq(active[keep])) break
while (keep < active.length) {
active.pop()
top = top.parentNode
}
while (active.length < node.marks.length) {
var add = node.marks[active.length]
active.push(add)
top = top.appendChild(this$1.renderMark(add))
}
top.appendChild(this$1.renderNode(node, startPos + offset, offset))
})
};
DOMSerialization.prototype.renderInlineFlatInto = function renderInlineFlatInto (fragment, where, startPos) {
var this$1 = this;
fragment.forEach(function (node, offset) {
var pos = startPos + offset, dom = this$1.renderNode(node, pos, offset)
dom = this$1.wrapInlineFlat(dom, node.marks)
dom = this$1.options.renderInlineFlat(node, dom, pos, offset) || dom
where.appendChild(dom)
})
};
DOMSerialization.prototype.renderMark = function renderMark (mark) {
return this.renderStructure(this.marks[mark.type.name](mark))
};
DOMSerialization.prototype.wrapInlineFlat = function wrapInlineFlat (dom, marks) {
var this$1 = this;
for (var i = marks.length - 1; i >= 0; i--) {
var wrap = this$1.renderMark(marks[i])
wrap.appendChild(dom)
dom = wrap
}
return dom
};
return options.document || window.document
}
{
"name": "prosemirror-model",
"version": "0.11.1",
"version": "0.12.0",
"description": "ProseMirror's document model",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -380,5 +380,10 @@ const {Fragment} = require("./fragment")

} else if (dom.nodeType == 1 && !dom.hasAttribute("pm-ignore")) {
let style = dom.getAttribute("style")
if (style) this.addElementWithStyles(parseStyles(style), dom)
else this.addElement(dom)
if (dom.hasAttribute("pm-decoration")) {
for (let child = dom.firstChild; child; child = child.nextSibling)
this.addDOM(child)
} else {
let style = dom.getAttribute("style")
if (style) this.addElementWithStyles(parseStyles(style), dom)
else this.addElement(dom)
}
}

@@ -385,0 +390,0 @@ }

@@ -34,4 +34,26 @@ // DOMOutputSpec:: interface

// nodes.
serializeFragment(fragment, options = {}) {
return new DOMSerialization(this, options).renderFragment(fragment, null, options.pos || 0)
serializeFragment(fragment, options = {}, target) {
if (!target) target = doc(options).createDocumentFragment()
let top = target, active = null
fragment.forEach(node => {
if (active || node.marks.length) {
if (!active) active = []
let keep = 0
for (; keep < Math.min(active.length, node.marks.length); ++keep)
if (!node.marks[keep].eq(active[keep])) break
while (keep < active.length) {
active.pop()
top = top.parentNode
}
while (active.length < node.marks.length) {
let add = node.marks[active.length]
active.push(add)
top = top.appendChild(this.serializeMark(add, options))
}
}
top.appendChild(this.serializeNode(node, options))
})
return target
}

@@ -46,8 +68,11 @@

serializeNode(node, options = {}) {
let context = new DOMSerialization(this, options), pos = options.pos || 0
let dom = context.renderNode(node, pos, options.offset || 0)
if (node.isInline) {
dom = context.wrapInlineFlat(dom, node.marks)
if (context.options.renderInlineFlat)
dom = context.options.renderInlineFlat(node, dom, pos, options.offset || 0) || dom
return this.renderStructure(this.nodes[node.type.name](node), node, options)
}
serializeNodeAndMarks(node, options = {}) {
let dom = this.serializeNode(node, options)
for (let i = node.marks.length - 1; i >= 0; i--) {
let wrap = this.serializeMark(node.marks[i], options)
wrap.appendChild(dom)
dom = wrap
}

@@ -57,2 +82,37 @@ return dom

serializeMark(mark, options = {}) {
return this.renderStructure(this.marks[mark.type.name](mark), null, options)
}
renderStructure(structure, node, options) {
if (typeof structure == "string")
return doc(options).createTextNode(structure)
if (structure.nodeType != null)
return structure
let dom = doc(options).createElement(structure[0]), attrs = structure[1], start = 1
if (attrs && typeof attrs == "object" && attrs.nodeType == null && !Array.isArray(attrs)) {
start = 2
for (let name in attrs) {
if (name == "style") dom.style.cssText = attrs[name]
else if (attrs[name] != null) dom.setAttribute(name, attrs[name])
}
}
for (let i = start; i < structure.length; i++) {
let child = structure[i]
if (child === 0) {
if (!node || node.isLeaf)
throw new RangeError("Content hole not allowed in a mark or leaf node spec (must produce a single node)")
if (i < structure.length - 1 || i > start)
throw new RangeError("Content hole must be the only child of its parent node")
if (options.onContent)
options.onContent(node, dom, options)
else
this.serializeFragment(node.content, options, dom)
} else {
dom.appendChild(this.renderStructure(child, node, options))
}
}
return dom
}
// :: (Schema) → DOMSerializer

@@ -90,108 +150,5 @@ // Build a serializer using the [`toDOM`](#model.NodeSpec.toDOM)

// Context object used during serialization.
class DOMSerialization {
constructor(serializer, options) {
// : Object The options passed to the serializer.
this.options = options || {}
// : dom.Document The DOM document in which we are working.
// declare global: window
this.doc = this.options.document || window.document
this.nodes = serializer.nodes
this.marks = serializer.marks
}
renderNode(node, pos, offset) {
let dom = this.renderStructure(this.nodes[node.type.name](node), node.content, pos + 1)
if (this.options.onRender)
dom = this.options.onRender(node, dom, pos, offset) || dom
return dom
}
renderStructure(structure, content, startPos) {
if (typeof structure == "string")
return this.doc.createTextNode(structure)
if (structure.nodeType != null)
return structure
let dom = this.doc.createElement(structure[0]), attrs = structure[1], start = 1
if (attrs && typeof attrs == "object" && attrs.nodeType == null && !Array.isArray(attrs)) {
start = 2
for (let name in attrs) {
if (name == "style") dom.style.cssText = attrs[name]
else if (attrs[name]) dom.setAttribute(name, attrs[name])
}
}
for (let i = start; i < structure.length; i++) {
let child = structure[i]
if (child === 0) {
if (!content)
throw new RangeError("Content hole not allowed in a Mark spec (must produce a single node)")
if (i < structure.length - 1 || i > start)
throw new RangeError("Content hole must be the only child of its parent node")
if (this.options.onContainer) this.options.onContainer(dom)
this.renderFragment(content, dom, startPos)
} else {
dom.appendChild(this.renderStructure(child, content, startPos))
}
}
return dom
}
renderFragment(fragment, where, startPos) {
if (!where) where = this.doc.createDocumentFragment()
if (fragment.size == 0) return where
if (!fragment.firstChild.isInline)
this.renderBlocksInto(fragment, where, startPos)
else if (this.options.renderInlineFlat)
this.renderInlineFlatInto(fragment, where, startPos)
else
this.renderInlineInto(fragment, where, startPos)
return where
}
renderBlocksInto(fragment, where, startPos) {
fragment.forEach((node, offset) => where.appendChild(this.renderNode(node, startPos + offset, offset)))
}
renderInlineInto(fragment, where, startPos) {
let top = where
let active = []
fragment.forEach((node, offset) => {
let keep = 0
for (; keep < Math.min(active.length, node.marks.length); ++keep)
if (!node.marks[keep].eq(active[keep])) break
while (keep < active.length) {
active.pop()
top = top.parentNode
}
while (active.length < node.marks.length) {
let add = node.marks[active.length]
active.push(add)
top = top.appendChild(this.renderMark(add))
}
top.appendChild(this.renderNode(node, startPos + offset, offset))
})
}
renderInlineFlatInto(fragment, where, startPos) {
fragment.forEach((node, offset) => {
let pos = startPos + offset, dom = this.renderNode(node, pos, offset)
dom = this.wrapInlineFlat(dom, node.marks)
dom = this.options.renderInlineFlat(node, dom, pos, offset) || dom
where.appendChild(dom)
})
}
renderMark(mark) {
return this.renderStructure(this.marks[mark.type.name](mark))
}
wrapInlineFlat(dom, marks) {
for (let i = marks.length - 1; i >= 0; i--) {
let wrap = this.renderMark(marks[i])
wrap.appendChild(dom)
dom = wrap
}
return dom
}
function doc(options) {
// declare global: window
return options.document || window.document
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc