mobiledoc-kit
Advanced tools
Comparing version 0.9.7 to 0.9.8
@@ -1046,2 +1046,3 @@ 'use strict'; | ||
* @param {Object} [atomPayload={}] | ||
* @return {Atom} The inserted atom. | ||
* @public | ||
@@ -1061,2 +1062,4 @@ */ | ||
} | ||
var atom = undefined; | ||
var range = this.range; | ||
@@ -1067,3 +1070,3 @@ | ||
var atom = postEditor.builder.createAtom(atomName, atomText, atomPayload); | ||
atom = postEditor.builder.createAtom(atomName, atomText, atomPayload); | ||
if (!range.isCollapsed) { | ||
@@ -1075,2 +1078,3 @@ position = postEditor.deleteRange(range); | ||
}); | ||
return atom; | ||
} | ||
@@ -1087,2 +1091,3 @@ | ||
* @param {Boolean} [inEditMode=false] Whether the card should be inserted in edit mode. | ||
* @return {Card} The inserted Card section. | ||
* @public | ||
@@ -1105,2 +1110,3 @@ */ | ||
var card = undefined; | ||
var range = this.range; | ||
@@ -1110,3 +1116,3 @@ | ||
var position = range.tail; | ||
var card = postEditor.builder.createCardSection(cardName, cardPayload); | ||
card = postEditor.builder.createCardSection(cardName, cardPayload); | ||
if (inEditMode) { | ||
@@ -1142,2 +1148,3 @@ _this7.editCard(card); | ||
}); | ||
return card; | ||
} | ||
@@ -1144,0 +1151,0 @@ |
@@ -985,5 +985,2 @@ 'use strict'; | ||
* | ||
* The return value will be all markers between the split, the same return | ||
* value as `splitMarkers`. | ||
* | ||
* @param {Range} range | ||
@@ -1001,6 +998,27 @@ * @param {Markup} markup A markup post abstract node | ||
} | ||
this.splitMarkers(range).forEach(function (marker) { | ||
marker.addMarkup(markup); | ||
_this11._markDirty(marker); | ||
}); | ||
var markers = this.splitMarkers(range); | ||
if (markers.length) { | ||
(function () { | ||
// We insert the new markup at a consistent index across the range. | ||
// If we just push on the end of the list, it can end up in different positions | ||
// of the markup stack. This results in unnecessary closing and re-opening of | ||
// the markup each time it changes position. | ||
// If we just push it at the beginning of the list, this causes unnecessary closing | ||
// and re-opening of surrounding tags. | ||
// So, we look for any tags open across the whole range, and push into the stack | ||
// at the end of those. | ||
// Prompted by https://github.com/bustlelabs/mobiledoc-kit/issues/360 | ||
var markupsOpenAcrossRange = (0, _utilsArrayUtils.reduce)(markers, function (soFar, marker) { | ||
return (0, _utilsArrayUtils.commonItems)(soFar, marker.markups); | ||
}, markers[0].markups); | ||
var indexToInsert = markupsOpenAcrossRange.length; | ||
markers.forEach(function (marker) { | ||
marker.addMarkupAtIndex(markup, indexToInsert); | ||
_this11._markDirty(marker); | ||
}); | ||
})(); | ||
} | ||
} | ||
@@ -1227,3 +1245,3 @@ | ||
} else { | ||
var _ret2 = (function () { | ||
var _ret3 = (function () { | ||
var preList = _this14.builder.createListSection(list.tagName), | ||
@@ -1246,3 +1264,3 @@ postList = _this14.builder.createListSection(list.tagName); | ||
if (typeof _ret2 === 'object') return _ret2.v; | ||
if (typeof _ret3 === 'object') return _ret3.v; | ||
} | ||
@@ -1249,0 +1267,0 @@ } |
@@ -86,2 +86,17 @@ "use strict"; | ||
/** | ||
* @return {Array} the items that are the same, starting from the 0th index, in a and b | ||
* @private | ||
*/ | ||
function commonItems(listA, listB) { | ||
var offset = 0; | ||
while (offset < listA.length && offset < listB.length) { | ||
if (listA[offset] !== listB[offset]) { | ||
break; | ||
} | ||
offset++; | ||
} | ||
return listA.slice(0, offset); | ||
} | ||
// return new array without falsy items like ruby's `compact` | ||
@@ -173,2 +188,3 @@ function compact(enumerable) { | ||
exports.commonItemLength = commonItemLength; | ||
exports.commonItems = commonItems; | ||
exports.compact = compact; | ||
@@ -175,0 +191,0 @@ exports.reduce = reduce; |
@@ -27,2 +27,7 @@ 'use strict'; | ||
}, { | ||
key: 'addMarkupAtIndex', | ||
value: function addMarkupAtIndex(markup, index) { | ||
this.markups.splice(index, 0, markup); | ||
} | ||
}, { | ||
key: 'removeMarkup', | ||
@@ -29,0 +34,0 @@ value: function removeMarkup(markupOrMarkupCallback) { |
'use strict'; | ||
exports['default'] = '0.9.7'; | ||
exports['default'] = '0.9.8'; |
{ | ||
"name": "mobiledoc-kit", | ||
"version": "0.9.7", | ||
"version": "0.9.8", | ||
"description": "A toolkit for building WYSIWYG editors with Mobiledoc", | ||
@@ -53,3 +53,3 @@ "repository": "https://github.com/bustlelabs/mobiledoc-kit", | ||
"conventional-changelog-cli": "^1.2.0", | ||
"jquery": "^2.2.2", | ||
"jquery": "^3.0.0", | ||
"jsdoc": "^3.4.0", | ||
@@ -56,0 +56,0 @@ "saucie": "^1.4.0", |
@@ -74,2 +74,3 @@ ## Mobiledoc Kit | ||
* `modiledoc` - [object] A mobiledoc object to load and edit. | ||
* `placeholder` - [string] default text to show before a user starts typing. | ||
@@ -87,2 +88,3 @@ * `spellcheck` - [boolean] whether to enable spellcheck. Defaults to true. | ||
whenever it encounters an unknown atom | ||
* `parserPlugins` - [array] See [DOM Parsing Hooks](https://github.com/bustlelabs/mobiledoc-kit#dom-parsing-hooks) | ||
@@ -271,3 +273,3 @@ ### Editor API | ||
Parser hooks are called with two arguments: | ||
Parser hooks are called with three arguments: | ||
@@ -321,3 +323,3 @@ * `node` - The node of DOM being parsed. This may be a text node or an element. | ||
If you notice an bug or have a feature request please [open an issue on github](https://github.com/bustlelabs/mobiledoc-kit/issues). | ||
If you notice a bug or have a feature request please [open an issue on github](https://github.com/bustlelabs/mobiledoc-kit/issues). | ||
If you have a question about usage you can post in the [gitter channel](https://gitter.im/bustlelabs/mobiledoc-kit) or on StackOverflow using the [`mobiledoc-kit` tag](http://stackoverflow.com/questions/tagged/mobiledoc-kit). | ||
@@ -324,0 +326,0 @@ |
@@ -911,2 +911,3 @@ import Tooltip from '../views/tooltip'; | ||
* @param {Object} [atomPayload={}] | ||
* @return {Atom} The inserted atom. | ||
* @public | ||
@@ -919,2 +920,4 @@ */ | ||
} | ||
let atom; | ||
let { range } = this; | ||
@@ -924,3 +927,3 @@ this.run(postEditor => { | ||
let atom = postEditor.builder.createAtom(atomName, atomText, atomPayload); | ||
atom = postEditor.builder.createAtom(atomName, atomText, atomPayload); | ||
if (!range.isCollapsed) { | ||
@@ -932,2 +935,3 @@ position = postEditor.deleteRange(range); | ||
}); | ||
return atom; | ||
} | ||
@@ -944,2 +948,3 @@ | ||
* @param {Boolean} [inEditMode=false] Whether the card should be inserted in edit mode. | ||
* @return {Card} The inserted Card section. | ||
* @public | ||
@@ -953,6 +958,7 @@ */ | ||
let card; | ||
let { range } = this; | ||
this.run(postEditor => { | ||
let position = range.tail; | ||
let card = postEditor.builder.createCardSection(cardName, cardPayload); | ||
card = postEditor.builder.createCardSection(cardName, cardPayload); | ||
if (inEditMode) { | ||
@@ -986,2 +992,3 @@ this.editCard(card); | ||
}); | ||
return card; | ||
} | ||
@@ -988,0 +995,0 @@ |
import Position from '../utils/cursor/position'; | ||
import { forEach, filter, values } from '../utils/array-utils'; | ||
import { forEach, reduce, filter, values, commonItems } from '../utils/array-utils'; | ||
import { DIRECTION } from '../utils/key'; | ||
@@ -839,5 +839,2 @@ import LifecycleCallbacks from '../models/lifecycle-callbacks'; | ||
* | ||
* The return value will be all markers between the split, the same return | ||
* value as `splitMarkers`. | ||
* | ||
* @param {Range} range | ||
@@ -851,6 +848,25 @@ * @param {Markup} markup A markup post abstract node | ||
} | ||
this.splitMarkers(range).forEach(marker => { | ||
marker.addMarkup(markup); | ||
this._markDirty(marker); | ||
}); | ||
let markers = this.splitMarkers(range); | ||
if (markers.length) { | ||
// We insert the new markup at a consistent index across the range. | ||
// If we just push on the end of the list, it can end up in different positions | ||
// of the markup stack. This results in unnecessary closing and re-opening of | ||
// the markup each time it changes position. | ||
// If we just push it at the beginning of the list, this causes unnecessary closing | ||
// and re-opening of surrounding tags. | ||
// So, we look for any tags open across the whole range, and push into the stack | ||
// at the end of those. | ||
// Prompted by https://github.com/bustlelabs/mobiledoc-kit/issues/360 | ||
let markupsOpenAcrossRange = reduce(markers, function (soFar, marker) { | ||
return commonItems(soFar, marker.markups); | ||
}, markers[0].markups); | ||
let indexToInsert = markupsOpenAcrossRange.length; | ||
markers.forEach(marker => { | ||
marker.addMarkupAtIndex(markup, indexToInsert); | ||
this._markDirty(marker); | ||
}); | ||
} | ||
} | ||
@@ -857,0 +873,0 @@ |
@@ -78,2 +78,17 @@ function detect(enumerable, callback) { | ||
/** | ||
* @return {Array} the items that are the same, starting from the 0th index, in a and b | ||
* @private | ||
*/ | ||
function commonItems(listA, listB) { | ||
let offset = 0; | ||
while (offset < listA.length && offset < listB.length) { | ||
if (listA[offset] !== listB[offset]) { | ||
break; | ||
} | ||
offset++; | ||
} | ||
return listA.slice(0, offset); | ||
} | ||
// return new array without falsy items like ruby's `compact` | ||
@@ -152,2 +167,3 @@ function compact(enumerable) { | ||
commonItemLength, | ||
commonItems, | ||
compact, | ||
@@ -154,0 +170,0 @@ reduce, |
@@ -14,2 +14,6 @@ import { normalizeTagName } from '../utils/dom-utils'; | ||
addMarkupAtIndex(markup, index) { | ||
this.markups.splice(index, 0, markup); | ||
} | ||
removeMarkup(markupOrMarkupCallback) { | ||
@@ -16,0 +20,0 @@ let callback; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
2979529
42740
344