prosemirror-model
Advanced tools
Comparing version 1.4.0 to 1.4.1
@@ -0,1 +1,7 @@ | ||
## 1.4.1 (2018-04-13) | ||
### Bug fixes | ||
`DOMParser` can now parse marks on block nodes. | ||
## 1.4.0 (2018-03-22) | ||
@@ -2,0 +8,0 @@ |
{ | ||
"name": "prosemirror-model", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "ProseMirror's document model", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -281,3 +281,3 @@ import {Fragment} from "./fragment" | ||
class NodeContext { | ||
constructor(type, attrs, solid, match, options) { | ||
constructor(type, attrs, marks, solid, match, options) { | ||
this.type = type | ||
@@ -289,2 +289,4 @@ this.attrs = attrs | ||
this.content = [] | ||
this.marks = marks | ||
this.activeMarks = Mark.none | ||
} | ||
@@ -322,4 +324,13 @@ | ||
content = content.append(this.match.fillBefore(Fragment.empty, true)) | ||
return this.type ? this.type.create(this.attrs, content) : content | ||
return this.type ? this.type.create(this.attrs, content, this.marks) : content | ||
} | ||
// : (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 | ||
} | ||
} | ||
@@ -338,11 +349,10 @@ | ||
if (topNode) | ||
topContext = new NodeContext(topNode.type, topNode.attrs, true, | ||
topContext = new NodeContext(topNode.type, topNode.attrs, Mark.none, true, | ||
options.topMatch || topNode.type.contentMatch, topOptions) | ||
else if (open) | ||
topContext = new NodeContext(null, null, true, null, topOptions) | ||
topContext = new NodeContext(null, null, Mark.none, true, null, topOptions) | ||
else | ||
topContext = new NodeContext(parser.schema.topNodeType, null, true, null, topOptions) | ||
topContext = new NodeContext(parser.schema.topNodeType, null, Mark.none, true, null, topOptions) | ||
this.nodes = [topContext] | ||
// : [Mark] The current set of marks | ||
this.marks = Mark.none | ||
this.open = 0 | ||
@@ -357,10 +367,2 @@ this.find = options.findPositions | ||
// : (Mark) → [Mark] | ||
// Add a mark to the current set of marks, return the old set. | ||
addMark(mark) { | ||
let old = this.marks | ||
this.marks = mark.addToSet(this.marks) | ||
return old | ||
} | ||
// : (dom.Node) | ||
@@ -374,5 +376,8 @@ // Add a DOM node to the content. Text is inserted as text node, | ||
} else if (dom.nodeType == 1) { | ||
let style = dom.getAttribute("style") | ||
if (style) this.addElementWithStyles(parseStyles(style), dom) | ||
else this.addElement(dom) | ||
let style = dom.getAttribute("style"), marks = Mark.none | ||
if (style) { | ||
marks = this.readStyles(parseStyles(style)) | ||
if (marks == null) return | ||
} | ||
this.addElement(dom, marks) | ||
} | ||
@@ -398,3 +403,3 @@ } | ||
} | ||
if (value) this.insertNode(this.parser.schema.text(value, this.marks)) | ||
if (value) this.insertNode(this.parser.schema.text(value, this.top.activeMarks)) | ||
this.findInText(dom) | ||
@@ -409,3 +414,3 @@ } else { | ||
// none is found, the element's content nodes are added directly. | ||
addElement(dom) { | ||
addElement(dom, marks) { | ||
let name = dom.nodeName.toLowerCase() | ||
@@ -418,28 +423,29 @@ if (listTags.hasOwnProperty(name)) normalizeList(dom) | ||
if (rule && rule.skip.nodeType) dom = rule.skip | ||
let sync, oldNeedsBlock = this.needsBlock | ||
let sync, top = this.top, oldMarks = top.activeMarks, oldNeedsBlock = this.needsBlock | ||
if (blockTags.hasOwnProperty(name)) { | ||
sync = this.top | ||
if (!sync.type) this.needsBlock = true | ||
sync = true | ||
if (!top.type) this.needsBlock = true | ||
} | ||
for (let i = 0; i < marks.length; i++) top.addMark(marks[i]) | ||
this.addAll(dom) | ||
if (sync) this.sync(sync) | ||
if (sync) this.sync(top) | ||
top.activeMarks = oldMarks | ||
this.needsBlock = oldNeedsBlock | ||
} else { | ||
this.addElementByRule(dom, rule) | ||
this.addElementByRule(dom, rule, marks) | ||
} | ||
} | ||
// Run any style parser associated with the node's styles. After | ||
// that, if no style parser suppressed the node's content, pass it | ||
// through to `addElement`. | ||
addElementWithStyles(styles, dom) { | ||
let oldMarks = this.marks, ignore = false | ||
// Run any style parser associated with the node's styles. Either | ||
// return an array of marks, or null to indicate some of the styles | ||
// had a rule with `ignore` set. | ||
readStyles(styles) { | ||
let marks = Mark.none | ||
for (let i = 0; i < styles.length; i += 2) { | ||
let rule = this.parser.matchStyle(styles[i], styles[i + 1], this) | ||
if (!rule) continue | ||
if (rule.ignore) { ignore = true; break } | ||
this.addMark(this.parser.schema.marks[rule.mark].create(rule.attrs)) | ||
if (rule.ignore) return null | ||
marks = this.parser.schema.marks[rule.mark].create(rule.attrs).addToSet(marks) | ||
} | ||
if (!ignore) this.addElement(dom) | ||
this.marks = oldMarks | ||
return marks | ||
} | ||
@@ -451,12 +457,15 @@ | ||
// the node's content is wrapped, and return true. | ||
addElementByRule(dom, rule) { | ||
addElementByRule(dom, rule, marks) { | ||
let sync, before, nodeType, markType, mark | ||
if (rule.node) { | ||
nodeType = this.parser.schema.nodes[rule.node] | ||
if (nodeType.isLeaf) this.insertNode(nodeType.create(rule.attrs, null, this.marks)) | ||
else sync = this.enter(nodeType, rule.attrs, rule.preserveWhitespace) && this.top | ||
if (nodeType.isLeaf) this.insertNode(nodeType.create(rule.attrs, null, this.top.activeMarks)) | ||
else sync = this.enter(nodeType, rule.attrs, rule.preserveWhitespace) | ||
} else { | ||
markType = this.parser.schema.marks[rule.mark] | ||
before = this.addMark(mark = markType.create(rule.attrs)) | ||
if (markType.name == "comment") console.log("adding a comment") | ||
before = this.top.addMark(mark = markType.create(rule.attrs)) | ||
} | ||
let startIn = this.top | ||
for (let i = 0; i < marks.length; i++) before = before || startIn.addMark(marks[i]) | ||
@@ -476,4 +485,4 @@ if (nodeType && nodeType.isLeaf) { | ||
} | ||
if (sync) { this.sync(sync); this.open-- } | ||
else if (before) this.marks = before | ||
if (sync) { this.sync(startIn); this.open-- } | ||
if (before) startIn.activeMarks = before | ||
return true | ||
@@ -555,3 +564,3 @@ } | ||
if ((top.options & OPT_OPEN_LEFT) && top.content.length == 0) options |= OPT_OPEN_LEFT | ||
this.nodes.push(new NodeContext(type, attrs, solid, null, options)) | ||
this.nodes.push(new NodeContext(type, attrs, top.activeMarks, solid, null, options)) | ||
this.open++ | ||
@@ -565,3 +574,2 @@ } | ||
if (i > this.open) { | ||
this.marks = Mark.none | ||
for (; i > this.open; i--) this.nodes[i - 1].content.push(this.nodes[i].finish(openEnd)) | ||
@@ -568,0 +576,0 @@ this.nodes.length = this.open + 1 |
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
487186
5894