prosemirror
Advanced tools
Comparing version 0.8.2 to 0.8.3
@@ -0,1 +1,14 @@ | ||
## 0.8.3 (2016-06-28) | ||
### Bug fixes | ||
When pasting text, assign some basic structure to it by inserting | ||
`<p>` and `<br>` tags. | ||
Fix a bug in `EditorTranform.selection`. | ||
Disable the `setBlockType` command for non-textblock blocks. | ||
Make `splitBlock` handle content restrictions better. | ||
## 0.8.2 (2016-06-21) | ||
@@ -2,0 +15,0 @@ |
@@ -301,11 +301,10 @@ "use strict"; | ||
var $from = _pm$selection10.$from; | ||
var from = _pm$selection10.from; | ||
var to = _pm$selection10.to; | ||
var $to = _pm$selection10.$to; | ||
var node = _pm$selection10.node; | ||
if (!node || !node.isBlock) return false; | ||
var type = $from.parent.defaultContentType($from.indexAfter()); | ||
if (!type.isTextblock) return false; | ||
var type = $from.parent.defaultContentType($to.indexAfter()); | ||
if (!type || !type.isTextblock) return false; | ||
if (apply !== false) { | ||
var side = $from.parentOffset ? to : from; | ||
var side = ($from.parentOffset ? $to : $from).pos; | ||
var tr = pm.tr.insert(side, type.createAndFill()); | ||
@@ -358,5 +357,10 @@ tr.setSelection(new TextSelection(tr.doc.resolve(side + 1))); | ||
var tr = pm.tr.delete($from.pos, $to.pos); | ||
var deflt = $from.node(-1).defaultContentType($from.indexAfter(-1)), | ||
type = atEnd ? deflt : null; | ||
if (canSplit(tr.doc, $from.pos, 1, type)) { | ||
var deflt = $from.depth == 0 ? null : $from.node(-1).defaultContentType($from.indexAfter(-1)); | ||
var type = atEnd ? deflt : null; | ||
var can = canSplit(tr.doc, $from.pos, 1, type); | ||
if (!type && !can && canSplit(tr.doc, $from.pos, 1, deflt)) { | ||
type = deflt; | ||
can = true; | ||
} | ||
if (can) { | ||
tr.split($from.pos, 1, type); | ||
@@ -562,6 +566,7 @@ if (!atEnd && !$from.parentOffset && $from.parent.type != deflt) tr.setNodeType($from.before(), deflt); | ||
} else { | ||
if ($to.pos > $from.end()) return false; | ||
if (!$from.depth || $to.pos > $from.end()) return false; | ||
depth = $from.depth - 1; | ||
} | ||
if ((node || $from.parent).hasMarkup(nodeType, attrs)) return false; | ||
var target = node || $from.parent; | ||
if (!target.isTextblock || target.hasMarkup(nodeType, attrs)) return false; | ||
var index = $from.index(depth); | ||
@@ -568,0 +573,0 @@ if (!$from.node(depth).canReplaceWith(index, index + 1, nodeType)) return false; |
@@ -463,4 +463,8 @@ "use strict"; | ||
dom = document.createElement("div"); | ||
pm.on.transformPastedText.dispatch(txt).split(/\n{2,}/).forEach(function (para) { | ||
dom.appendChild(document.createElement("paragraph")).textContent = para; | ||
pm.on.transformPastedText.dispatch(txt).split(/(?:\r\n?|\n){2,}/).forEach(function (block) { | ||
var para = dom.appendChild(document.createElement("p")); | ||
block.split(/\r\n?|\n/).forEach(function (line, i) { | ||
if (i) para.appendChild(document.createElement("br")); | ||
para.appendChild(document.createTextNode(line)); | ||
}); | ||
}); | ||
@@ -467,0 +471,0 @@ } else { |
@@ -152,3 +152,3 @@ "use strict"; | ||
for (var i = this.curSelectionAt; i < this.steps.length; i++) { | ||
this.curSelection = this.curSelection.map(i == this.steps.length ? this.doc : this.docs[i + 1], this.maps[i]); | ||
this.curSelection = this.curSelection.map(i == this.steps.length - 1 ? this.doc : this.docs[i + 1], this.maps[i]); | ||
} | ||
@@ -155,0 +155,0 @@ } else { |
@@ -441,2 +441,11 @@ "use strict"; | ||
} | ||
}, { | ||
key: "nextElement", | ||
get: function get() { | ||
for (var i = this.index, count = this.count; i < this.expr.elements.length; i++) { | ||
var element = this.expr.elements[i]; | ||
if (this.resolveValue(element.max) > count) return element; | ||
count = 0; | ||
} | ||
} | ||
}]); | ||
@@ -443,0 +452,0 @@ |
@@ -429,3 +429,4 @@ "use strict"; | ||
value: function defaultContentType(at) { | ||
return this.contentMatchAt(at).element.defaultType(); | ||
var elt = this.contentMatchAt(at).nextElement; | ||
return elt && elt.defaultType(); | ||
} | ||
@@ -432,0 +433,0 @@ |
@@ -29,3 +29,3 @@ "use strict"; | ||
options.place = space; | ||
options.schema = schema; | ||
if (!options.doc) options.schema = schema; | ||
var pm = new ProseMirror(options); | ||
@@ -32,0 +32,0 @@ var a = options.doc && options.doc.tag && options.doc.tag.a; |
@@ -35,7 +35,13 @@ "use strict"; | ||
var _require6 = require("../../schema-basic"); | ||
var _require6 = require("../../model"); | ||
var schema = _require6.schema; | ||
var Schema = _require6.Schema; | ||
var _require7 = require("../../schema-basic"); | ||
var schema = _require7.schema; | ||
var Heading = _require7.Heading; | ||
var Doc = _require7.Doc; | ||
var used = Object.create(null); | ||
@@ -165,2 +171,14 @@ var n = schema.nodes; | ||
var hSchema = new Schema({ | ||
nodes: schema.nodeSpec.update("heading", { type: Heading, content: "inline<_>*" }).update("doc", { type: Doc, content: "heading block*" }) | ||
}); | ||
function hDoc(a) { | ||
var hDoc = hSchema.node("doc", null, [hSchema.node("heading", { level: 1 }, hSchema.text("foobar"))]); | ||
hDoc.tag = { a: a }; | ||
return hDoc; | ||
} | ||
test("splitBlock", hDoc(7), hSchema.node("doc", null, [hSchema.node("heading", { level: 1 }, hSchema.text("foobar")), hSchema.node("paragraph")])); | ||
test("splitBlock", hDoc(4), hSchema.node("doc", null, [hSchema.node("heading", { level: 1 }, hSchema.text("foo")), hSchema.node("paragraph", null, hSchema.text("bar"))])); | ||
test("splitListItem", n.list_item, doc(p("foo<a>bar")), doc(p("foobar"))); | ||
@@ -167,0 +185,0 @@ test("splitListItem", n.list_item, doc("<a>", p("foobar")), doc(p("foobar"))); |
{ | ||
"name": "prosemirror", | ||
"version": "0.8.2", | ||
"version": "0.8.3", | ||
"description": "Well-defined WYSIWYG editor", | ||
@@ -5,0 +5,0 @@ "main": "dist/edit/index.js", |
@@ -239,8 +239,8 @@ const {joinPoint, joinable, findWrapping, liftTarget, canSplit, ReplaceAroundStep} = require("../transform") | ||
commands.createParagraphNear = function(pm, apply) { | ||
let {$from, from, to, node} = pm.selection | ||
let {$from, $to, node} = pm.selection | ||
if (!node || !node.isBlock) return false | ||
let type = $from.parent.defaultContentType($from.indexAfter()) | ||
if (!type.isTextblock) return false | ||
let type = $from.parent.defaultContentType($to.indexAfter()) | ||
if (!type || !type.isTextblock) return false | ||
if (apply !== false) { | ||
let side = $from.parentOffset ? to : from | ||
let side = ($from.parentOffset ? $to : $from).pos | ||
let tr = pm.tr.insert(side, type.createAndFill()) | ||
@@ -285,4 +285,10 @@ tr.setSelection(new TextSelection(tr.doc.resolve(side + 1))) | ||
let tr = pm.tr.delete($from.pos, $to.pos) | ||
let deflt = $from.node(-1).defaultContentType($from.indexAfter(-1)), type = atEnd ? deflt : null | ||
if (canSplit(tr.doc, $from.pos, 1, type)) { | ||
let deflt = $from.depth == 0 ? null : $from.node(-1).defaultContentType($from.indexAfter(-1)) | ||
let type = atEnd ? deflt : null | ||
let can = canSplit(tr.doc, $from.pos, 1, type) | ||
if (!type && !can && canSplit(tr.doc, $from.pos, 1, deflt)) { | ||
type = deflt | ||
can = true | ||
} | ||
if (can) { | ||
tr.split($from.pos, 1, type) | ||
@@ -468,6 +474,7 @@ if (!atEnd && !$from.parentOffset && $from.parent.type != deflt) | ||
} else { | ||
if ($to.pos > $from.end()) return false | ||
if (!$from.depth || $to.pos > $from.end()) return false | ||
depth = $from.depth - 1 | ||
} | ||
if ((node || $from.parent).hasMarkup(nodeType, attrs)) return false | ||
let target = node || $from.parent | ||
if (!target.isTextblock || target.hasMarkup(nodeType, attrs)) return false | ||
let index = $from.index(depth) | ||
@@ -474,0 +481,0 @@ if (!$from.node(depth).canReplaceWith(index, index + 1, nodeType)) return false |
@@ -413,4 +413,8 @@ const Keymap = require("browserkeymap") | ||
dom = document.createElement("div") | ||
pm.on.transformPastedText.dispatch(txt).split(/\n{2,}/).forEach(para => { | ||
dom.appendChild(document.createElement("paragraph")).textContent = para | ||
pm.on.transformPastedText.dispatch(txt).split(/(?:\r\n?|\n){2,}/).forEach(block => { | ||
let para = dom.appendChild(document.createElement("p")) | ||
block.split(/\r\n?|\n/).forEach((line, i) => { | ||
if (i) para.appendChild(document.createElement("br")) | ||
para.appendChild(document.createTextNode(line)) | ||
}) | ||
}) | ||
@@ -417,0 +421,0 @@ } else { |
@@ -39,3 +39,3 @@ const {Fragment} = require("../model") | ||
for (let i = this.curSelectionAt; i < this.steps.length; i++) | ||
this.curSelection = this.curSelection.map(i == this.steps.length ? this.doc : this.docs[i + 1], this.maps[i]) | ||
this.curSelection = this.curSelection.map(i == this.steps.length - 1 ? this.doc : this.docs[i + 1], this.maps[i]) | ||
} else { | ||
@@ -42,0 +42,0 @@ this.curSelection = this.curSelection.map(this.doc, this) |
@@ -186,2 +186,10 @@ const {Fragment} = require("./fragment") | ||
get nextElement() { | ||
for (let i = this.index, count = this.count; i < this.expr.elements.length; i++) { | ||
let element = this.expr.elements[i] | ||
if (this.resolveValue(element.max) > count) return element | ||
count = 0 | ||
} | ||
} | ||
move(index, count) { | ||
@@ -188,0 +196,0 @@ return new ContentMatch(this.expr, this.attrs, index, count) |
@@ -308,3 +308,4 @@ const {Fragment} = require("./fragment") | ||
defaultContentType(at) { | ||
return this.contentMatchAt(at).element.defaultType() | ||
let elt = this.contentMatchAt(at).nextElement | ||
return elt && elt.defaultType() | ||
} | ||
@@ -311,0 +312,0 @@ |
@@ -16,3 +16,3 @@ const {defTest} = require("../tests") | ||
options.place = space | ||
options.schema = schema | ||
if (!options.doc) options.schema = schema | ||
let pm = new ProseMirror(options) | ||
@@ -19,0 +19,0 @@ let a = options.doc && options.doc.tag && options.doc.tag.a |
@@ -7,3 +7,4 @@ const {defTest} = require("../tests") | ||
const {commands} = require("../../edit") | ||
const {schema} = require("../../schema-basic") | ||
const {Schema} = require("../../model") | ||
const {schema, Heading, Doc} = require("../../schema-basic") | ||
@@ -299,2 +300,27 @@ const used = Object.create(null) | ||
const hSchema = new Schema({ | ||
nodes: schema.nodeSpec.update("heading", {type: Heading, content: "inline<_>*"}) | ||
.update("doc", {type: Doc, content: "heading block*"}) | ||
}) | ||
function hDoc(a) { | ||
const hDoc = hSchema.node("doc", null, [ | ||
hSchema.node("heading", {level: 1}, hSchema.text("foobar")) | ||
]) | ||
hDoc.tag = {a} | ||
return hDoc | ||
} | ||
test("splitBlock", | ||
hDoc(7), | ||
hSchema.node("doc", null, [ | ||
hSchema.node("heading", {level: 1}, hSchema.text("foobar")), | ||
hSchema.node("paragraph") | ||
])) | ||
test("splitBlock", | ||
hDoc(4), | ||
hSchema.node("doc", null, [ | ||
hSchema.node("heading", {level: 1}, hSchema.text("foo")), | ||
hSchema.node("paragraph", null, hSchema.text("bar")) | ||
])) | ||
test("splitListItem", n.list_item, | ||
@@ -301,0 +327,0 @@ doc(p("foo<a>bar")), |
1262084
29942