mobiledoc-kit
Advanced tools
Comparing version 0.10.5 to 0.10.6
@@ -100,2 +100,4 @@ 'use strict'; | ||
DID_RENDER: 'didRender', | ||
WILL_DELETE: 'willDelete', | ||
DID_DELETE: 'didDelete', | ||
CURSOR_DID_CHANGE: 'cursorDidChange', | ||
@@ -389,2 +391,3 @@ DID_REPARSE: 'didReparse', | ||
this.runCallbacks(CALLBACK_QUEUES.WILL_DELETE, [range, direction, unit]); | ||
if (range.isCollapsed) { | ||
@@ -395,2 +398,3 @@ this.deleteAtPosition(range.head, direction, { unit: unit }); | ||
} | ||
this.runCallbacks(CALLBACK_QUEUES.DID_DELETE, [range, direction, unit]); | ||
} | ||
@@ -864,2 +868,22 @@ }, { | ||
/** | ||
* @param {Function} callback This callback will be called before deleting. | ||
* @public | ||
*/ | ||
}, { | ||
key: 'willDelete', | ||
value: function willDelete(callback) { | ||
this.addCallback(CALLBACK_QUEUES.WILL_DELETE, callback); | ||
} | ||
/** | ||
* @param {Function} callback This callback will be called after deleting. | ||
* @public | ||
*/ | ||
}, { | ||
key: 'didDelete', | ||
value: function didDelete(callback) { | ||
this.addCallback(CALLBACK_QUEUES.DID_DELETE, callback); | ||
} | ||
/** | ||
* @param {Function} callback This callback will be called every time the cursor | ||
@@ -866,0 +890,0 @@ * position (or selection) changes. |
@@ -58,4 +58,7 @@ 'use strict'; | ||
}); | ||
this._replaceSection(this.cursorSection, newSections); | ||
this.cursorPosition = newSections[newSections.length - 1].tailPosition(); | ||
newSections.forEach(function (section) { | ||
_this._replaceSection(_this.cursorSection, section); | ||
}); | ||
var lastNewSection = newSections[newSections.length - 1]; | ||
this.cursorPosition = lastNewSection.tailPosition(); | ||
} else { | ||
@@ -117,2 +120,13 @@ node.sections.forEach(function (section) { | ||
this._mergeSection(section); | ||
} else if (this._isNested && this._isMarkerable) { | ||
// If we are attaching a markerable section to a list item, | ||
// insert a linebreak then merge the section onto the resulting blank list item | ||
this._breakAtCursor(); | ||
// Advance the cursor to the head of the blank list item | ||
var nextPosition = this.cursorSection.next.headPosition(); | ||
this.cursorPosition = nextPosition; | ||
// Merge this section onto the list item | ||
this._mergeSection(section); | ||
} else { | ||
@@ -252,7 +266,4 @@ this._breakAtCursor(); | ||
key: '_replaceSection', | ||
value: function _replaceSection(section, newSections) { | ||
var _this3 = this; | ||
value: function _replaceSection(section, newSection) { | ||
(0, _utilsAssert['default'])('Cannot replace section that does not have parent.sections', section.parent && section.parent.sections); | ||
(0, _utilsAssert['default'])('Must pass enumerable to _replaceSection', !!newSections.forEach); | ||
@@ -262,5 +273,3 @@ var collection = section.parent.sections, | ||
this.postEditor.removeSection(section); | ||
newSections.forEach(function (_newSection) { | ||
_this3.postEditor.insertSectionBefore(collection, _newSection, reference); | ||
}); | ||
this.postEditor.insertSectionBefore(collection, newSection, reference); | ||
} | ||
@@ -277,5 +286,5 @@ }, { | ||
(0, _utilsAssert['default'])('Cannot insert leaf non-markerable section when cursor is nested', !(section.isMarkerable && this._isNested)); | ||
this._replaceSection(this.cursorSection, [section]); | ||
this._replaceSection(this.cursorSection, section); | ||
} else if (this.cursorSection.next && this.cursorSection.next.isBlank) { | ||
this._replaceSection(this.cursorSection.next, [section]); | ||
this._replaceSection(this.cursorSection.next, section); | ||
} else { | ||
@@ -282,0 +291,0 @@ var reference = this.cursorSection.next; |
'use strict'; | ||
exports['default'] = '0.10.5'; | ||
exports['default'] = '0.10.6'; |
{ | ||
"name": "mobiledoc-kit", | ||
"version": "0.10.5", | ||
"version": "0.10.6", | ||
"description": "A toolkit for building WYSIWYG editors with Mobiledoc", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/bustlelabs/mobiledoc-kit", |
@@ -133,2 +133,4 @@ ## Mobiledoc Kit | ||
edited post. | ||
* `editor.willDelete((range, direction, unit))` - Provides `range`, `direction` and `unit` to identify the coming deletion. | ||
* `editor.didDelete((range, direction, unit))` - Provides `range`, `direction` and `unit` to identify the completed deletion. | ||
* `editor.cursorDidChange()` - When the cursor (or selection) changes as a result of arrow-key | ||
@@ -135,0 +137,0 @@ movement or clicking in the document. |
@@ -62,2 +62,4 @@ import Tooltip from '../views/tooltip'; | ||
DID_RENDER: 'didRender', | ||
WILL_DELETE: 'willDelete', | ||
DID_DELETE: 'didDelete', | ||
CURSOR_DID_CHANGE: 'cursorDidChange', | ||
@@ -315,2 +317,3 @@ DID_REPARSE: 'didReparse', | ||
this.runCallbacks(CALLBACK_QUEUES.WILL_DELETE, [range, direction, unit]); | ||
if (range.isCollapsed) { | ||
@@ -321,2 +324,3 @@ this.deleteAtPosition(range.head, direction, {unit}); | ||
} | ||
this.runCallbacks(CALLBACK_QUEUES.DID_DELETE, [range, direction, unit]); | ||
} | ||
@@ -755,2 +759,18 @@ | ||
/** | ||
* @param {Function} callback This callback will be called before deleting. | ||
* @public | ||
*/ | ||
willDelete(callback) { | ||
this.addCallback(CALLBACK_QUEUES.WILL_DELETE, callback); | ||
} | ||
/** | ||
* @param {Function} callback This callback will be called after deleting. | ||
* @public | ||
*/ | ||
didDelete(callback) { | ||
this.addCallback(CALLBACK_QUEUES.DID_DELETE, callback); | ||
} | ||
/** | ||
* @param {Function} callback This callback will be called every time the cursor | ||
@@ -757,0 +777,0 @@ * position (or selection) changes. |
@@ -69,4 +69,7 @@ import assert from 'mobiledoc-kit/utils/assert'; | ||
let newSections = node.sections.map(s => s.clone()); | ||
this._replaceSection(this.cursorSection, newSections); | ||
this.cursorPosition = newSections[newSections.length - 1].tailPosition(); | ||
newSections.forEach(section => { | ||
this._replaceSection(this.cursorSection, section); | ||
}); | ||
let lastNewSection = newSections[newSections.length - 1]; | ||
this.cursorPosition = lastNewSection.tailPosition(); | ||
} else { | ||
@@ -115,2 +118,13 @@ node.sections.forEach(section => this.visit(section)); | ||
this._mergeSection(section); | ||
} else if (this._isNested && this._isMarkerable) { | ||
// If we are attaching a markerable section to a list item, | ||
// insert a linebreak then merge the section onto the resulting blank list item | ||
this._breakAtCursor(); | ||
// Advance the cursor to the head of the blank list item | ||
let nextPosition = this.cursorSection.next.headPosition(); | ||
this.cursorPosition = nextPosition; | ||
// Merge this section onto the list item | ||
this._mergeSection(section); | ||
} else { | ||
@@ -220,6 +234,5 @@ this._breakAtCursor(); | ||
_replaceSection(section, newSections) { | ||
_replaceSection(section, newSection) { | ||
assert('Cannot replace section that does not have parent.sections', | ||
section.parent && section.parent.sections); | ||
assert('Must pass enumerable to _replaceSection', !!newSections.forEach); | ||
@@ -229,5 +242,3 @@ let collection = section.parent.sections, | ||
this.postEditor.removeSection(section); | ||
newSections.forEach(_newSection => { | ||
this.postEditor.insertSectionBefore(collection, _newSection, reference); | ||
}); | ||
this.postEditor.insertSectionBefore(collection, newSection, reference); | ||
} | ||
@@ -245,5 +256,5 @@ | ||
!(section.isMarkerable && this._isNested)); | ||
this._replaceSection(this.cursorSection, [section]); | ||
this._replaceSection(this.cursorSection, section); | ||
} else if (this.cursorSection.next && this.cursorSection.next.isBlank) { | ||
this._replaceSection(this.cursorSection.next, [section]); | ||
this._replaceSection(this.cursorSection.next, section); | ||
} else { | ||
@@ -250,0 +261,0 @@ let reference = this.cursorSection.next; |
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
3043131
43737
342