Skip to content

Commit

Permalink
Merge pull requests
Browse files Browse the repository at this point in the history
  • Loading branch information
nosir committed May 27, 2018
1 parent c9cb5a7 commit b04d5ae
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 51 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"form",
"input"
],
"version": "1.3.3",
"version": "1.3.4",
"author": {
"name": "Max Huang",
"email": "[email protected]",
Expand Down
45 changes: 35 additions & 10 deletions dist/cleave-angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ return /******/ (function(modules) { // webpackBootstrap
value = Util.stripDelimiters(value, pps.delimiter, pps.delimiters);

// strip prefix
value = Util.getPrefixStrippedValue(value, pps.prefix, pps.prefixLength);
value = Util.getPrefixStrippedValue(value, pps.prefix, pps.prefixLength, pps.result);

// strip non-numeric characters
value = pps.numericOnly ? Util.strip(value, /[^\d]/g) : value;
Expand Down Expand Up @@ -351,13 +351,16 @@ return /******/ (function(modules) { // webpackBootstrap
},

setCurrentSelection: function (endPos, oldValue) {
var owner = this,
pps = owner.properties;

// If cursor was at the end of value, just place it back.
// Because new value could contain additional chars.
if (oldValue.length === endPos) {
return;
}

Cleave.Util.setSelection(this.element, endPos);
Cleave.Util.setSelection(owner.element, endPos, pps.document);
},

updateValueState: function () {
Expand Down Expand Up @@ -413,7 +416,7 @@ return /******/ (function(modules) { // webpackBootstrap
}

pps.backspace = false;

owner.element.value = value;
owner.onInput(value);
},
Expand All @@ -425,7 +428,7 @@ return /******/ (function(modules) { // webpackBootstrap
rawValue = owner.element.value;

if (pps.rawValueTrimPrefix) {
rawValue = Util.getPrefixStrippedValue(rawValue, pps.prefix, pps.prefixLength);
rawValue = Util.getPrefixStrippedValue(rawValue, pps.prefix, pps.prefixLength, pps.result);
}

if (pps.numeral) {
Expand Down Expand Up @@ -511,6 +514,22 @@ return /******/ (function(modules) { // webpackBootstrap

return $scope.instance.getRawValue();
});

// Recreate cleave instance if any cleave options change
$scope.$watch(function() {
return $scope.cleave();
// eslint-disable-next-line
}, function (newOptions, oldOptions) {
$scope.instance.destroy();
// eslint-disable-next-line
$scope.instance = new Cleave($element[0], newOptions);
}, true);

$scope.$on('$destroy', function () {

$scope.instance.destroy();
$scope.instance = null;
});
}
};
}
Expand Down Expand Up @@ -1032,11 +1051,16 @@ return /******/ (function(modules) { // webpackBootstrap
// for prefix: PRE
// (PRE123, 3) -> 123
// (PR123, 3) -> 23 this happens when user hits backspace in front of "PRE"
getPrefixStrippedValue: function (value, prefix, prefixLength) {
getPrefixStrippedValue: function (value, prefix, prefixLength, prevValue) {
if (value.slice(0, prefixLength) !== prefix) {
var diffIndex = this.getFirstDiffIndex(prefix, value.slice(0, prefixLength));

value = prefix + value.slice(diffIndex, diffIndex + 1) + value.slice(prefixLength + 1);
// Check whether if it is a deletion
if (value.length < prevValue.length) {
value = value.length > prefixLength ? prevValue : prefix;
} else {
var diffIndex = this.getFirstDiffIndex(prefix, value.slice(0, prefixLength));
value = prefix + value.slice(diffIndex, diffIndex + 1) + value.slice(prefixLength + 1);
}
}

return value.slice(prefixLength);
Expand Down Expand Up @@ -1119,8 +1143,8 @@ return /******/ (function(modules) { // webpackBootstrap
}, 1);
},

setSelection: function (element, position) {
if (element !== document.activeElement) {
setSelection: function (element, position, doc) {
if (element !== doc.activeElement) {
return;
}

Expand Down Expand Up @@ -1228,7 +1252,8 @@ return /******/ (function(modules) { // webpackBootstrap

target.blocks = opts.blocks || [];
target.blocksLength = target.blocks.length;


target.document = opts.document || document;
target.root = (typeof global === 'object' && global) ? global : window;

target.maxLength = 0;
Expand Down
4 changes: 2 additions & 2 deletions dist/cleave-angular.min.js

Large diffs are not rendered by default.

25 changes: 17 additions & 8 deletions dist/cleave-react-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ return /******/ (function(modules) { // webpackBootstrap
rawValue = pps.result;

if (pps.rawValueTrimPrefix) {
rawValue = Util.getPrefixStrippedValue(rawValue, pps.prefix, pps.prefixLength);
rawValue = Util.getPrefixStrippedValue(rawValue, pps.prefix, pps.prefixLength, pps.result);
}

if (pps.numeral) {
Expand Down Expand Up @@ -358,7 +358,7 @@ return /******/ (function(modules) { // webpackBootstrap
value = Util.stripDelimiters(value, pps.delimiter, pps.delimiters);

// strip prefix
value = Util.getPrefixStrippedValue(value, pps.prefix, pps.prefixLength);
value = Util.getPrefixStrippedValue(value, pps.prefix, pps.prefixLength, pps.result);

// strip non-numeric characters
value = pps.numericOnly ? Util.strip(value, /[^\d]/g) : value;
Expand Down Expand Up @@ -429,11 +429,14 @@ return /******/ (function(modules) { // webpackBootstrap
},

setCurrentSelection: function setCurrentSelection(cursorPosition) {
var owner = this,
pps = owner.properties;

this.setState({
updateCursorPosition: false
});

Util.setSelection(this.element, cursorPosition);
Util.setSelection(owner.element, cursorPosition, pps.document);
},

updateValueState: function updateValueState() {
Expand Down Expand Up @@ -2233,11 +2236,16 @@ return /******/ (function(modules) { // webpackBootstrap
// for prefix: PRE
// (PRE123, 3) -> 123
// (PR123, 3) -> 23 this happens when user hits backspace in front of "PRE"
getPrefixStrippedValue: function getPrefixStrippedValue(value, prefix, prefixLength) {
getPrefixStrippedValue: function getPrefixStrippedValue(value, prefix, prefixLength, prevValue) {
if (value.slice(0, prefixLength) !== prefix) {
var diffIndex = this.getFirstDiffIndex(prefix, value.slice(0, prefixLength));

value = prefix + value.slice(diffIndex, diffIndex + 1) + value.slice(prefixLength + 1);
// Check whether if it is a deletion
if (value.length < prevValue.length) {
value = value.length > prefixLength ? prevValue : prefix;
} else {
var diffIndex = this.getFirstDiffIndex(prefix, value.slice(0, prefixLength));
value = prefix + value.slice(diffIndex, diffIndex + 1) + value.slice(prefixLength + 1);
}
}

return value.slice(prefixLength);
Expand Down Expand Up @@ -2320,8 +2328,8 @@ return /******/ (function(modules) { // webpackBootstrap
}, 1);
},

setSelection: function setSelection(element, position) {
if (element !== document.activeElement) {
setSelection: function setSelection(element, position, doc) {
if (element !== doc.activeElement) {
return;
}

Expand Down Expand Up @@ -2427,6 +2435,7 @@ return /******/ (function(modules) { // webpackBootstrap
target.blocks = opts.blocks || [];
target.blocksLength = target.blocks.length;

target.document = opts.document || document;
target.root = (typeof global === 'undefined' ? 'undefined' : _typeof(global)) === 'object' && global ? global : window;

target.maxLength = 0;
Expand Down
4 changes: 2 additions & 2 deletions dist/cleave-react-node.min.js

Large diffs are not rendered by default.

25 changes: 17 additions & 8 deletions dist/cleave-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ return /******/ (function(modules) { // webpackBootstrap
rawValue = pps.result;

if (pps.rawValueTrimPrefix) {
rawValue = Util.getPrefixStrippedValue(rawValue, pps.prefix, pps.prefixLength);
rawValue = Util.getPrefixStrippedValue(rawValue, pps.prefix, pps.prefixLength, pps.result);
}

if (pps.numeral) {
Expand Down Expand Up @@ -358,7 +358,7 @@ return /******/ (function(modules) { // webpackBootstrap
value = Util.stripDelimiters(value, pps.delimiter, pps.delimiters);

// strip prefix
value = Util.getPrefixStrippedValue(value, pps.prefix, pps.prefixLength);
value = Util.getPrefixStrippedValue(value, pps.prefix, pps.prefixLength, pps.result);

// strip non-numeric characters
value = pps.numericOnly ? Util.strip(value, /[^\d]/g) : value;
Expand Down Expand Up @@ -429,11 +429,14 @@ return /******/ (function(modules) { // webpackBootstrap
},

setCurrentSelection: function setCurrentSelection(cursorPosition) {
var owner = this,
pps = owner.properties;

this.setState({
updateCursorPosition: false
});

Util.setSelection(this.element, cursorPosition);
Util.setSelection(owner.element, cursorPosition, pps.document);
},

updateValueState: function updateValueState() {
Expand Down Expand Up @@ -2427,11 +2430,16 @@ return /******/ (function(modules) { // webpackBootstrap
// for prefix: PRE
// (PRE123, 3) -> 123
// (PR123, 3) -> 23 this happens when user hits backspace in front of "PRE"
getPrefixStrippedValue: function getPrefixStrippedValue(value, prefix, prefixLength) {
getPrefixStrippedValue: function getPrefixStrippedValue(value, prefix, prefixLength, prevValue) {
if (value.slice(0, prefixLength) !== prefix) {
var diffIndex = this.getFirstDiffIndex(prefix, value.slice(0, prefixLength));

value = prefix + value.slice(diffIndex, diffIndex + 1) + value.slice(prefixLength + 1);
// Check whether if it is a deletion
if (value.length < prevValue.length) {
value = value.length > prefixLength ? prevValue : prefix;
} else {
var diffIndex = this.getFirstDiffIndex(prefix, value.slice(0, prefixLength));
value = prefix + value.slice(diffIndex, diffIndex + 1) + value.slice(prefixLength + 1);
}
}

return value.slice(prefixLength);
Expand Down Expand Up @@ -2514,8 +2522,8 @@ return /******/ (function(modules) { // webpackBootstrap
}, 1);
},

setSelection: function setSelection(element, position) {
if (element !== document.activeElement) {
setSelection: function setSelection(element, position, doc) {
if (element !== doc.activeElement) {
return;
}

Expand Down Expand Up @@ -2621,6 +2629,7 @@ return /******/ (function(modules) { // webpackBootstrap
target.blocks = opts.blocks || [];
target.blocksLength = target.blocks.length;

target.document = opts.document || document;
target.root = (typeof global === 'undefined' ? 'undefined' : _typeof(global)) === 'object' && global ? global : window;

target.maxLength = 0;
Expand Down
4 changes: 2 additions & 2 deletions dist/cleave-react.min.js

Large diffs are not rendered by default.

29 changes: 19 additions & 10 deletions dist/cleave.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ return /******/ (function(modules) { // webpackBootstrap
value = Util.stripDelimiters(value, pps.delimiter, pps.delimiters);

// strip prefix
value = Util.getPrefixStrippedValue(value, pps.prefix, pps.prefixLength);
value = Util.getPrefixStrippedValue(value, pps.prefix, pps.prefixLength, pps.result);

// strip non-numeric characters
value = pps.numericOnly ? Util.strip(value, /[^\d]/g) : value;
Expand Down Expand Up @@ -351,13 +351,16 @@ return /******/ (function(modules) { // webpackBootstrap
},

setCurrentSelection: function (endPos, oldValue) {
var owner = this,
pps = owner.properties;

// If cursor was at the end of value, just place it back.
// Because new value could contain additional chars.
if (oldValue.length === endPos) {
return;
}

Cleave.Util.setSelection(this.element, endPos);
Cleave.Util.setSelection(owner.element, endPos, pps.document);
},

updateValueState: function () {
Expand Down Expand Up @@ -413,7 +416,7 @@ return /******/ (function(modules) { // webpackBootstrap
}

pps.backspace = false;

owner.element.value = value;
owner.onInput(value);
},
Expand All @@ -425,7 +428,7 @@ return /******/ (function(modules) { // webpackBootstrap
rawValue = owner.element.value;

if (pps.rawValueTrimPrefix) {
rawValue = Util.getPrefixStrippedValue(rawValue, pps.prefix, pps.prefixLength);
rawValue = Util.getPrefixStrippedValue(rawValue, pps.prefix, pps.prefixLength, pps.result);
}

if (pps.numeral) {
Expand Down Expand Up @@ -991,11 +994,16 @@ return /******/ (function(modules) { // webpackBootstrap
// for prefix: PRE
// (PRE123, 3) -> 123
// (PR123, 3) -> 23 this happens when user hits backspace in front of "PRE"
getPrefixStrippedValue: function (value, prefix, prefixLength) {
getPrefixStrippedValue: function (value, prefix, prefixLength, prevValue) {
if (value.slice(0, prefixLength) !== prefix) {
var diffIndex = this.getFirstDiffIndex(prefix, value.slice(0, prefixLength));

value = prefix + value.slice(diffIndex, diffIndex + 1) + value.slice(prefixLength + 1);
// Check whether if it is a deletion
if (value.length < prevValue.length) {
value = value.length > prefixLength ? prevValue : prefix;
} else {
var diffIndex = this.getFirstDiffIndex(prefix, value.slice(0, prefixLength));
value = prefix + value.slice(diffIndex, diffIndex + 1) + value.slice(prefixLength + 1);
}
}

return value.slice(prefixLength);
Expand Down Expand Up @@ -1078,8 +1086,8 @@ return /******/ (function(modules) { // webpackBootstrap
}, 1);
},

setSelection: function (element, position) {
if (element !== document.activeElement) {
setSelection: function (element, position, doc) {
if (element !== doc.activeElement) {
return;
}

Expand Down Expand Up @@ -1187,7 +1195,8 @@ return /******/ (function(modules) { // webpackBootstrap

target.blocks = opts.blocks || [];
target.blocksLength = target.blocks.length;


target.document = opts.document || document;
target.root = (typeof global === 'object' && global) ? global : window;

target.maxLength = 0;
Expand Down
Loading

0 comments on commit b04d5ae

Please sign in to comment.