prosemirror-model
Advanced tools
Comparing version 1.4.3 to 1.4.4
@@ -0,1 +1,7 @@ | ||
## 1.4.4 (2018-05-03) | ||
### Bug fixes | ||
Fix a regression where `DOMParser.parse` would fail to apply mark nodes directly at the start of the input. | ||
## 1.4.3 (2018-04-27) | ||
@@ -2,0 +8,0 @@ |
{ | ||
"name": "prosemirror-model", | ||
"version": "1.4.3", | ||
"version": "1.4.4", | ||
"description": "ProseMirror's document model", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -324,11 +324,2 @@ import {Fragment} from "./fragment" | ||
} | ||
// : (Mark) → [Mark] | ||
// Add a mark to the current set of marks, return the old set. | ||
addMark(mark) { | ||
let old = this.activeMarks | ||
if (!this.type || this.type.allowsMarkType(mark.type)) | ||
this.activeMarks = mark.addToSet(old) | ||
return old | ||
} | ||
} | ||
@@ -344,2 +335,3 @@ | ||
this.isOpen = open | ||
this.pendingMarks = [] | ||
let topNode = options.topNode, topContext | ||
@@ -373,8 +365,13 @@ let topOptions = wsOptionsFor(options.preserveWhitespace) | (open ? OPT_OPEN_LEFT : 0) | ||
} else if (dom.nodeType == 1) { | ||
let style = dom.getAttribute("style"), marks = Mark.none | ||
if (style) { | ||
marks = this.readStyles(parseStyles(style)) | ||
if (marks == null) return | ||
let style = dom.getAttribute("style") | ||
if (!style) { | ||
this.addElement(dom) | ||
} else { | ||
let marks = this.readStyles(parseStyles(style)) | ||
if (marks != null) { | ||
for (let i = 0; i < marks.length; i++) this.addPendingMark(marks[i]) | ||
this.addElement(dom) | ||
for (let i = 0; i < marks.length; i++) this.removePendingMark(marks[i]) | ||
} | ||
} | ||
this.addElement(dom, marks) | ||
} | ||
@@ -400,3 +397,3 @@ } | ||
} | ||
if (value) this.insertNode(this.parser.schema.text(value, this.top.activeMarks)) | ||
if (value) this.insertNode(this.parser.schema.text(value)) | ||
this.findInText(dom) | ||
@@ -411,3 +408,3 @@ } else { | ||
// none is found, the element's content nodes are added directly. | ||
addElement(dom, marks) { | ||
addElement(dom) { | ||
let name = dom.nodeName.toLowerCase() | ||
@@ -425,3 +422,2 @@ if (listTags.hasOwnProperty(name)) normalizeList(dom) | ||
} | ||
for (let i = 0; i < marks.length; i++) top.addMark(marks[i]) | ||
this.addAll(dom) | ||
@@ -432,3 +428,3 @@ if (sync) this.sync(top) | ||
} else { | ||
this.addElementByRule(dom, rule, marks) | ||
this.addElementByRule(dom, rule) | ||
} | ||
@@ -455,14 +451,14 @@ } | ||
// the node's content is wrapped, and return true. | ||
addElementByRule(dom, rule, marks) { | ||
let sync, before, nodeType, markType, mark | ||
addElementByRule(dom, rule) { | ||
let sync, nodeType, markType, mark | ||
if (rule.node) { | ||
nodeType = this.parser.schema.nodes[rule.node] | ||
if (nodeType.isLeaf) this.insertNode(nodeType.create(rule.attrs, null, this.top.activeMarks)) | ||
if (nodeType.isLeaf) this.insertNode(nodeType.create(rule.attrs)) | ||
else sync = this.enter(nodeType, rule.attrs, rule.preserveWhitespace) | ||
} else { | ||
markType = this.parser.schema.marks[rule.mark] | ||
before = this.top.addMark(mark = markType.create(rule.attrs)) | ||
mark = markType.create(rule.attrs) | ||
this.addPendingMark(mark) | ||
} | ||
let startIn = this.top | ||
for (let i = 0; i < marks.length; i++) before = before || startIn.addMark(marks[i]) | ||
@@ -473,3 +469,3 @@ if (nodeType && nodeType.isLeaf) { | ||
this.findInside(dom) | ||
rule.getContent(dom).forEach(node => this.insertNode(mark ? node.mark(mark.addToSet(node.marks)) : node)) | ||
rule.getContent(dom).forEach(node => this.insertNode(node)) | ||
} else { | ||
@@ -484,3 +480,3 @@ let contentDOM = rule.contentElement | ||
if (sync) { this.sync(startIn); this.open-- } | ||
if (before) startIn.activeMarks = before | ||
if (mark) this.removePendingMark(mark) | ||
return true | ||
@@ -538,7 +534,19 @@ } | ||
let top = this.top | ||
if (top.match) { | ||
top.match = top.match.matchType(node.type) | ||
if (top.type) node = node.mark(top.type.allowedMarks(node.marks)) | ||
this.applyPendingMarks(top) | ||
if (top.match) top.match = top.match.matchType(node.type) | ||
let marks = top.activeMarks | ||
for (let i = 0; i < node.marks.length; i++) | ||
if (!top.type || top.type.allowsMarkType(node.marks[i].type)) | ||
marks = node.marks[i].addToSet(marks) | ||
top.content.push(node.mark(marks)) | ||
} | ||
} | ||
applyPendingMarks(top) { | ||
for (let i = 0; i < this.pendingMarks.length; i++) { | ||
let mark = this.pendingMarks[i] | ||
if ((!top.type || top.type.allowsMarkType(mark.type)) && !mark.type.isInSet(top.activeMarks)) { | ||
top.activeMarks = mark.addToSet(top.activeMarks) | ||
this.pendingMarks.splice(i--, 1) | ||
} | ||
top.content.push(node) | ||
} | ||
@@ -552,3 +560,6 @@ } | ||
let ok = this.findPlace(type.create(attrs)) | ||
if (ok) this.enterInner(type, attrs, true, preserveWS) | ||
if (ok) { | ||
this.applyPendingMarks(this.top) | ||
this.enterInner(type, attrs, true, preserveWS) | ||
} | ||
return ok | ||
@@ -591,2 +602,16 @@ } | ||
addPendingMark(mark) { | ||
this.pendingMarks.push(mark) | ||
} | ||
removePendingMark(mark) { | ||
let found = this.pendingMarks.lastIndexOf(mark) | ||
if (found > -1) { | ||
this.pendingMarks.splice(mark, 1) | ||
} else { | ||
let top = this.top | ||
top.activeMarks = mark.removeFromSet(top.activeMarks) | ||
} | ||
} | ||
get currentPos() { | ||
@@ -593,0 +618,0 @@ this.closeExtra() |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
489929
5940