draft-js-single-line-plugin
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -6,2 +6,6 @@ # Change Log | ||
# v2.0.1 2017-04-20 | ||
* Don’t create new state unnecessarily — [thanks to @mhssmnn](https://github.com/icelab/draft-js-single-line-plugin/pull/3) | ||
# v2.0.0 2017-03-20 | ||
@@ -8,0 +12,0 @@ |
@@ -27,3 +27,3 @@ 'use strict'; | ||
function singleLinePlugin() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
@@ -67,4 +67,5 @@ options = Object.assign({}, defaultOptions, options); | ||
var characterList = contentBlock.getCharacterList(); | ||
var hasEntitiesToStrip = options.stripEntities && (0, _utils.characterListhasEntities)(characterList); | ||
if (_utils.NEWLINE_REGEX.test(text) || (0, _utils.characterListhasEntities)(characterList)) { | ||
if (_utils.NEWLINE_REGEX.test(text) || hasEntitiesToStrip) { | ||
// Replace the text stripped of its newlines. Note that we replace | ||
@@ -94,3 +95,2 @@ // one '\n' with one ' ' so we don't need to modify the characterList | ||
editorState = _draftJs.EditorState.push(editorState, newContentState, 'insert-characters'); | ||
editorState = _draftJs.EditorState.moveFocusToEnd(editorState); | ||
} | ||
@@ -110,3 +110,3 @@ } | ||
handleReturn: function handleReturn(e) { | ||
return "handled"; | ||
return 'handled'; | ||
} | ||
@@ -113,0 +113,0 @@ }; |
@@ -29,3 +29,3 @@ 'use strict'; | ||
function replaceNewlines(str) { | ||
var replacement = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ' '; | ||
var replacement = arguments.length <= 1 || arguments[1] === undefined ? ' ' : arguments[1]; | ||
@@ -32,0 +32,0 @@ return str.replace(NEWLINE_REGEX, replacement); |
{ | ||
"name": "draft-js-single-line-plugin", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Restrict a draft-js editor to a single line of input.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
16434