mobiledoc-kit
Advanced tools
Comparing version 0.10.8 to 0.10.9
@@ -462,5 +462,2 @@ 'use strict'; | ||
value: function _readRangeFromDOM() { | ||
if (!this.isEditable) { | ||
return; | ||
} | ||
this.range = this.cursor.offsets; | ||
@@ -467,0 +464,0 @@ } |
@@ -17,4 +17,2 @@ 'use strict'; | ||
var _utilsCharacters = require('../utils/characters'); | ||
var _editorTextInputHandler = require('../editor/text-input-handler'); | ||
@@ -235,4 +233,5 @@ | ||
case key.isTab(): | ||
// Handle tab here because it does not fire a `keypress` event | ||
event.preventDefault(); | ||
editor.insertText(_utilsCharacters.TAB); | ||
this._textInputHandler.handle(key.toString()); | ||
break; | ||
@@ -239,0 +238,0 @@ } |
@@ -5,3 +5,3 @@ 'use strict'; | ||
var _get = function get(_x5, _x6, _x7) { var _again = true; _function: while (_again) { var object = _x5, property = _x6, receiver = _x7; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x5 = parent; _x6 = property; _x7 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
var _get = function get(_x4, _x5, _x6) { var _again = true; _function: while (_again) { var object = _x4, property = _x5, receiver = _x6; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x4 = parent; _x5 = property; _x6 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
@@ -115,21 +115,2 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } } | ||
/** | ||
* Splits the marker at the offset, filters empty markers from the result, | ||
* and replaces this marker with the new non-empty ones | ||
* @param {Marker} marker the marker to split | ||
* @return {Array} the new markers that replaced `marker` | ||
*/ | ||
}, { | ||
key: 'splitMarker', | ||
value: function splitMarker(marker, offset) { | ||
var endOffset = arguments.length <= 2 || arguments[2] === undefined ? marker.length : arguments[2]; | ||
return (function () { | ||
var newMarkers = (0, _utilsArrayUtils.filter)(marker.split(offset, endOffset), function (m) { | ||
return !m.isBlank; | ||
}); | ||
this.markers.splice(marker, 1, newMarkers); | ||
return newMarkers; | ||
}).apply(this, arguments); | ||
} | ||
// puts clones of this.markers into beforeSection and afterSection, | ||
@@ -136,0 +117,0 @@ // all markers before the marker/offset split go in beforeSection, and all |
@@ -17,2 +17,4 @@ 'use strict'; | ||
var _utilsAssert = require('../utils/assert'); | ||
/** | ||
@@ -110,58 +112,2 @@ * The Post is an in-memory representation of an editor's document. | ||
}, { | ||
key: 'cutMarkers', | ||
value: function cutMarkers(markers) { | ||
var firstSection = markers.length && markers[0].section, | ||
lastSection = markers.length && markers[markers.length - 1].section; | ||
var currentSection = firstSection; | ||
var removedSections = [], | ||
changedSections = (0, _utilsArrayUtils.compact)([firstSection, lastSection]); | ||
if (markers.length !== 0) { | ||
markers.forEach(function (marker) { | ||
if (marker.section !== currentSection) { | ||
// this marker is in a section we haven't seen yet | ||
if (marker.section !== firstSection && marker.section !== lastSection) { | ||
// section is wholly contained by markers, and can be removed | ||
removedSections.push(marker.section); | ||
} | ||
} | ||
currentSection = marker.section; | ||
currentSection.markers.remove(marker); | ||
}); | ||
if (firstSection !== lastSection) { | ||
firstSection.join(lastSection); | ||
removedSections.push(lastSection); | ||
} | ||
} | ||
return { changedSections: changedSections, removedSections: removedSections }; | ||
} | ||
/** | ||
* Invoke `callbackFn` for all markers between the headMarker and tailMarker (inclusive), | ||
* across sections | ||
* @private | ||
*/ | ||
}, { | ||
key: 'markersFrom', | ||
value: function markersFrom(headMarker, tailMarker, callbackFn) { | ||
var currentMarker = headMarker; | ||
while (currentMarker) { | ||
callbackFn(currentMarker); | ||
if (currentMarker === tailMarker) { | ||
currentMarker = null; | ||
} else if (currentMarker.next) { | ||
currentMarker = currentMarker.next; | ||
} else { | ||
var nextSection = this._nextMarkerableSection(currentMarker.section); | ||
// FIXME: This will fail across cards | ||
currentMarker = nextSection && nextSection.markers.head; | ||
} | ||
} | ||
} | ||
}, { | ||
key: 'markupsInRange', | ||
@@ -244,14 +190,3 @@ value: function markupsInRange(range) { | ||
} | ||
}, { | ||
key: '_nextMarkerableSection', | ||
value: function _nextMarkerableSection(section) { | ||
var nextSection = this._nextLeafSection(section); | ||
while (nextSection && !nextSection.isMarkerable) { | ||
nextSection = this._nextLeafSection(nextSection); | ||
} | ||
return nextSection; | ||
} | ||
// return the next section that has markers after this one, | ||
@@ -265,17 +200,11 @@ // possibly skipping non-markerable sections | ||
} | ||
var hasChildren = function hasChildren(s) { | ||
return !!s.items; | ||
}; | ||
var firstChild = function firstChild(s) { | ||
return s.items.head; | ||
}; | ||
// FIXME this can be refactored to use `isLeafSection` | ||
var next = section.next; | ||
if (next) { | ||
if (hasChildren(next)) { | ||
// e.g. a ListSection | ||
return firstChild(next); | ||
if (next.isLeafSection) { | ||
return next; | ||
} else if (!!next.items) { | ||
return next.items.head; | ||
} else { | ||
return next; | ||
(0, _utilsAssert['default'])('Cannot determine next section from non-leaf-section', false); | ||
} | ||
@@ -282,0 +211,0 @@ } else if (section.isNested) { |
@@ -29,2 +29,8 @@ 'use strict'; | ||
var NEWLINES = /\n/g; | ||
function sanitize(text) { | ||
text = text.replace(NEWLINES, ''); | ||
return text; | ||
} | ||
/** | ||
@@ -174,3 +180,3 @@ * parses an element into a section, ignoring any non-markup | ||
state.text += textNode.textContent; | ||
state.text += sanitize(textNode.textContent); | ||
} | ||
@@ -177,0 +183,0 @@ }, { |
@@ -97,3 +97,2 @@ 'use strict'; | ||
function addClassName(element, className) { | ||
// FIXME-IE IE10+ | ||
element.classList.add(className); | ||
@@ -100,0 +99,0 @@ } |
@@ -11,2 +11,4 @@ 'use strict'; | ||
var _utilsCharacters = require('../utils/characters'); | ||
/** | ||
@@ -90,2 +92,5 @@ * @typedef Direction | ||
value: function toString() { | ||
if (this.isTab()) { | ||
return _utilsCharacters.TAB; | ||
} | ||
return String.fromCharCode(this.charCode); | ||
@@ -92,0 +97,0 @@ } |
'use strict'; | ||
exports['default'] = '0.10.8'; | ||
exports['default'] = '0.10.9'; |
{ | ||
"name": "mobiledoc-kit", | ||
"version": "0.10.8", | ||
"version": "0.10.9", | ||
"description": "A toolkit for building WYSIWYG editors with Mobiledoc", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/bustlelabs/mobiledoc-kit", |
@@ -398,5 +398,2 @@ import Tooltip from '../views/tooltip'; | ||
_readRangeFromDOM() { | ||
if (!this.isEditable) { | ||
return; | ||
} | ||
this.range = this.cursor.offsets; | ||
@@ -403,0 +400,0 @@ } |
@@ -9,3 +9,2 @@ import assert from 'mobiledoc-kit/utils/assert'; | ||
import Key from 'mobiledoc-kit/utils/key'; | ||
import { TAB } from 'mobiledoc-kit/utils/characters'; | ||
import TextInputHandler from 'mobiledoc-kit/editor/text-input-handler'; | ||
@@ -177,4 +176,5 @@ import SelectionManager from 'mobiledoc-kit/editor/selection-manager'; | ||
case key.isTab(): | ||
// Handle tab here because it does not fire a `keypress` event | ||
event.preventDefault(); | ||
editor.insertText(TAB); | ||
this._textInputHandler.handle(key.toString()); | ||
break; | ||
@@ -181,0 +181,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { forEach, filter, reduce } from '../utils/array-utils'; | ||
import { forEach, reduce } from '../utils/array-utils'; | ||
import Set from '../utils/set'; | ||
@@ -86,14 +86,2 @@ | ||
/** | ||
* Splits the marker at the offset, filters empty markers from the result, | ||
* and replaces this marker with the new non-empty ones | ||
* @param {Marker} marker the marker to split | ||
* @return {Array} the new markers that replaced `marker` | ||
*/ | ||
splitMarker(marker, offset, endOffset=marker.length) { | ||
const newMarkers = filter(marker.split(offset, endOffset), m => !m.isBlank); | ||
this.markers.splice(marker, 1, newMarkers); | ||
return newMarkers; | ||
} | ||
// puts clones of this.markers into beforeSection and afterSection, | ||
@@ -100,0 +88,0 @@ // all markers before the marker/offset split go in beforeSection, and all |
import { POST_TYPE } from './types'; | ||
import LinkedList from 'mobiledoc-kit/utils/linked-list'; | ||
import { forEach, compact } from 'mobiledoc-kit/utils/array-utils'; | ||
import { forEach } from 'mobiledoc-kit/utils/array-utils'; | ||
import Set from 'mobiledoc-kit/utils/set'; | ||
import Position from 'mobiledoc-kit/utils/cursor/position'; | ||
import assert from 'mobiledoc-kit/utils/assert'; | ||
@@ -97,55 +98,2 @@ /** | ||
cutMarkers(markers) { | ||
let firstSection = markers.length && markers[0].section, | ||
lastSection = markers.length && markers[markers.length - 1].section; | ||
let currentSection = firstSection; | ||
let removedSections = [], | ||
changedSections = compact([firstSection, lastSection]); | ||
if (markers.length !== 0) { | ||
markers.forEach(marker => { | ||
if (marker.section !== currentSection) { // this marker is in a section we haven't seen yet | ||
if (marker.section !== firstSection && | ||
marker.section !== lastSection) { | ||
// section is wholly contained by markers, and can be removed | ||
removedSections.push(marker.section); | ||
} | ||
} | ||
currentSection = marker.section; | ||
currentSection.markers.remove(marker); | ||
}); | ||
if (firstSection !== lastSection) { | ||
firstSection.join(lastSection); | ||
removedSections.push(lastSection); | ||
} | ||
} | ||
return {changedSections, removedSections}; | ||
} | ||
/** | ||
* Invoke `callbackFn` for all markers between the headMarker and tailMarker (inclusive), | ||
* across sections | ||
* @private | ||
*/ | ||
markersFrom(headMarker, tailMarker, callbackFn) { | ||
let currentMarker = headMarker; | ||
while (currentMarker) { | ||
callbackFn(currentMarker); | ||
if (currentMarker === tailMarker) { | ||
currentMarker = null; | ||
} else if (currentMarker.next) { | ||
currentMarker = currentMarker.next; | ||
} else { | ||
let nextSection = this._nextMarkerableSection(currentMarker.section); | ||
// FIXME: This will fail across cards | ||
currentMarker = nextSection && nextSection.markers.head; | ||
} | ||
} | ||
} | ||
markupsInRange(range) { | ||
@@ -220,12 +168,2 @@ const markups = new Set(); | ||
_nextMarkerableSection(section) { | ||
let nextSection = this._nextLeafSection(section); | ||
while (nextSection && !nextSection.isMarkerable) { | ||
nextSection = this._nextLeafSection(nextSection); | ||
} | ||
return nextSection; | ||
} | ||
// return the next section that has markers after this one, | ||
@@ -235,12 +173,11 @@ // possibly skipping non-markerable sections | ||
if (!section) { return null; } | ||
const hasChildren = s => !!s.items; | ||
const firstChild = s => s.items.head; | ||
// FIXME this can be refactored to use `isLeafSection` | ||
const next = section.next; | ||
if (next) { | ||
if (hasChildren(next)) { // e.g. a ListSection | ||
return firstChild(next); | ||
if (next.isLeafSection) { | ||
return next; | ||
} else if (!!next.items) { | ||
return next.items.head; | ||
} else { | ||
return next; | ||
assert('Cannot determine next section from non-leaf-section', false); | ||
} | ||
@@ -247,0 +184,0 @@ } else if (section.isNested) { |
@@ -47,2 +47,8 @@ import { | ||
const NEWLINES = /\n/g; | ||
function sanitize(text) { | ||
text = text.replace(NEWLINES, ''); | ||
return text; | ||
} | ||
/** | ||
@@ -171,3 +177,3 @@ * parses an element into a section, ignoring any non-markup | ||
let { state } = this; | ||
state.text += textNode.textContent; | ||
state.text += sanitize(textNode.textContent); | ||
} | ||
@@ -174,0 +180,0 @@ |
@@ -83,3 +83,2 @@ import { forEach } from './array-utils'; | ||
function addClassName(element, className) { | ||
// FIXME-IE IE10+ | ||
element.classList.add(className); | ||
@@ -86,0 +85,0 @@ } |
import Keycodes from './keycodes'; | ||
import { TAB } from 'mobiledoc-kit/utils/characters'; | ||
/** | ||
@@ -77,2 +79,3 @@ * @typedef Direction | ||
toString() { | ||
if (this.isTab()) { return TAB; } | ||
return String.fromCharCode(this.charCode); | ||
@@ -79,0 +82,0 @@ } |
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
3040969
43661