react-maskedinput
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -0,1 +1,11 @@ | ||
## 4.0.1 / 2018-01-26 🇦🇺 | ||
* Fix auto-fill scenarios by using data from `onChange` events [[#112]((https://github.com/insin/react-maskedinput/pull/112)] | ||
* Fix wrong scope in `onPaste` event [[#108]((https://github.com/insin/react-maskedinput/pull/108)] | ||
* Include React 16 in `peerDependencies` [[#115]((https://github.com/insin/react-maskedinput/pull/115)] | ||
* Update nwb to 0.21.x to fix UMD build, which was exporting an object with a `default` property | ||
## 4.0.0 / 2017-07-04 | ||
@@ -2,0 +12,0 @@ |
229
es/index.js
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _class, _temp2; | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
@@ -27,4 +29,4 @@ | ||
function getSelection(el) { | ||
var start, end, rangeEl, clone; | ||
var start = void 0, | ||
end = void 0; | ||
if (el.selectionStart !== undefined) { | ||
@@ -36,4 +38,4 @@ start = el.selectionStart; | ||
el.focus(); | ||
rangeEl = el.createTextRange(); | ||
clone = rangeEl.duplicate(); | ||
var rangeEl = el.createTextRange(); | ||
var clone = rangeEl.duplicate(); | ||
@@ -52,4 +54,2 @@ rangeEl.moveToBookmark(document.selection.createRange().getBookmark()); | ||
function setSelection(el, selection) { | ||
var rangeEl; | ||
try { | ||
@@ -61,3 +61,3 @@ if (el.selectionStart !== undefined) { | ||
el.focus(); | ||
rangeEl = el.createTextRange(); | ||
var rangeEl = el.createTextRange(); | ||
rangeEl.collapse(true); | ||
@@ -71,15 +71,104 @@ rangeEl.moveStart('character', selection.start); | ||
var MaskedInput = function (_React$Component) { | ||
var MaskedInput = (_temp2 = _class = function (_React$Component) { | ||
_inherits(MaskedInput, _React$Component); | ||
function MaskedInput(props) { | ||
function MaskedInput() { | ||
var _temp, _this, _ret; | ||
_classCallCheck(this, MaskedInput); | ||
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this._onChange = _this._onChange.bind(_this); | ||
_this._onKeyDown = _this._onKeyDown.bind(_this); | ||
_this._onPaste = _this._onPaste.bind(_this); | ||
_this._onKeyPress = _this._onKeyPress.bind(_this); | ||
return _this; | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this._onChange = function (e) { | ||
// console.log('onChange', JSON.stringify(getSelection(this.input)), e.target.value) | ||
var maskValue = _this.mask.getValue(); | ||
var incomingValue = e.target.value; | ||
if (incomingValue !== maskValue) { | ||
// only modify mask if form contents actually changed | ||
_this._updateMaskSelection(); | ||
_this.mask.setValue(incomingValue); // write the whole updated value into the mask | ||
e.target.value = _this._getDisplayValue(); // update the form with pattern applied to the value | ||
_this._updateInputSelection(); | ||
} | ||
if (_this.props.onChange) { | ||
_this.props.onChange(e); | ||
} | ||
}, _this._onKeyDown = function (e) { | ||
// console.log('onKeyDown', JSON.stringify(getSelection(this.input)), e.key, e.target.value) | ||
if (isUndo(e)) { | ||
e.preventDefault(); | ||
if (_this.mask.undo()) { | ||
e.target.value = _this._getDisplayValue(); | ||
_this._updateInputSelection(); | ||
if (_this.props.onChange) { | ||
_this.props.onChange(e); | ||
} | ||
} | ||
return; | ||
} else if (isRedo(e)) { | ||
e.preventDefault(); | ||
if (_this.mask.redo()) { | ||
e.target.value = _this._getDisplayValue(); | ||
_this._updateInputSelection(); | ||
if (_this.props.onChange) { | ||
_this.props.onChange(e); | ||
} | ||
} | ||
return; | ||
} | ||
if (e.key === 'Backspace') { | ||
e.preventDefault(); | ||
_this._updateMaskSelection(); | ||
if (_this.mask.backspace()) { | ||
var value = _this._getDisplayValue(); | ||
e.target.value = value; | ||
if (value) { | ||
_this._updateInputSelection(); | ||
} | ||
if (_this.props.onChange) { | ||
_this.props.onChange(e); | ||
} | ||
} | ||
} | ||
}, _this._onKeyPress = function (e) { | ||
// console.log('onKeyPress', JSON.stringify(getSelection(this.input)), e.key, e.target.value) | ||
// Ignore modified key presses | ||
// Ignore enter key to allow form submission | ||
if (e.metaKey || e.altKey || e.ctrlKey || e.key === 'Enter') { | ||
return; | ||
} | ||
e.preventDefault(); | ||
_this._updateMaskSelection(); | ||
if (_this.mask.input(e.key || e.data)) { | ||
e.target.value = _this.mask.getValue(); | ||
_this._updateInputSelection(); | ||
if (_this.props.onChange) { | ||
_this.props.onChange(e); | ||
} | ||
} | ||
}, _this._onPaste = function (e) { | ||
// console.log('onPaste', JSON.stringify(getSelection(this.input)), e.clipboardData.getData('Text'), e.target.value) | ||
e.preventDefault(); | ||
_this._updateMaskSelection(); | ||
// getData value needed for IE also works in FF & Chrome | ||
if (_this.mask.paste(e.clipboardData.getData('Text'))) { | ||
e.target.value = _this.mask.getValue(); | ||
// Timeout needed for IE | ||
setTimeout(function () { | ||
return _this._updateInputSelection(); | ||
}, 0); | ||
if (_this.props.onChange) { | ||
_this.props.onChange(e); | ||
} | ||
} | ||
}, _temp), _possibleConstructorReturn(_this, _ret); | ||
} | ||
@@ -144,102 +233,2 @@ | ||
MaskedInput.prototype._onChange = function _onChange(e) { | ||
// console.log('onChange', JSON.stringify(getSelection(this.input)), e.target.value) | ||
var maskValue = this.mask.getValue(); | ||
if (e.target.value !== maskValue) { | ||
// Cut or delete operations will have shortened the value | ||
if (e.target.value.length < maskValue.length) { | ||
var sizeDiff = maskValue.length - e.target.value.length; | ||
this._updateMaskSelection(); | ||
this.mask.selection.end = this.mask.selection.start + sizeDiff; | ||
this.mask.backspace(); | ||
} | ||
var value = this._getDisplayValue(); | ||
e.target.value = value; | ||
if (value) { | ||
this._updateInputSelection(); | ||
} | ||
} | ||
if (this.props.onChange) { | ||
this.props.onChange(e); | ||
} | ||
}; | ||
MaskedInput.prototype._onKeyDown = function _onKeyDown(e) { | ||
// console.log('onKeyDown', JSON.stringify(getSelection(this.input)), e.key, e.target.value) | ||
if (isUndo(e)) { | ||
e.preventDefault(); | ||
if (this.mask.undo()) { | ||
e.target.value = this._getDisplayValue(); | ||
this._updateInputSelection(); | ||
if (this.props.onChange) { | ||
this.props.onChange(e); | ||
} | ||
} | ||
return; | ||
} else if (isRedo(e)) { | ||
e.preventDefault(); | ||
if (this.mask.redo()) { | ||
e.target.value = this._getDisplayValue(); | ||
this._updateInputSelection(); | ||
if (this.props.onChange) { | ||
this.props.onChange(e); | ||
} | ||
} | ||
return; | ||
} | ||
if (e.key === 'Backspace') { | ||
e.preventDefault(); | ||
this._updateMaskSelection(); | ||
if (this.mask.backspace()) { | ||
var value = this._getDisplayValue(); | ||
e.target.value = value; | ||
if (value) { | ||
this._updateInputSelection(); | ||
} | ||
if (this.props.onChange) { | ||
this.props.onChange(e); | ||
} | ||
} | ||
} | ||
}; | ||
MaskedInput.prototype._onKeyPress = function _onKeyPress(e) { | ||
// console.log('onKeyPress', JSON.stringify(getSelection(this.input)), e.key, e.target.value) | ||
// Ignore modified key presses | ||
// Ignore enter key to allow form submission | ||
if (e.metaKey || e.altKey || e.ctrlKey || e.key === 'Enter') { | ||
return; | ||
} | ||
e.preventDefault(); | ||
this._updateMaskSelection(); | ||
if (this.mask.input(e.key || e.data)) { | ||
e.target.value = this.mask.getValue(); | ||
this._updateInputSelection(); | ||
if (this.props.onChange) { | ||
this.props.onChange(e); | ||
} | ||
} | ||
}; | ||
MaskedInput.prototype._onPaste = function _onPaste(e) { | ||
// console.log('onPaste', JSON.stringify(getSelection(this.input)), e.clipboardData.getData('Text'), e.target.value) | ||
e.preventDefault(); | ||
this._updateMaskSelection(); | ||
// getData value needed for IE also works in FF & Chrome | ||
if (this.mask.paste(e.clipboardData.getData('Text'))) { | ||
e.target.value = this.mask.getValue(); | ||
// Timeout needed for IE | ||
setTimeout(this._updateInputSelection, 0); | ||
if (this.props.onChange) { | ||
this.props.onChange(e); | ||
} | ||
} | ||
}; | ||
MaskedInput.prototype._getDisplayValue = function _getDisplayValue() { | ||
@@ -293,3 +282,3 @@ var value = this.mask.getValue(); | ||
formatCharacters = _props2.formatCharacters, | ||
cleanedProps = _objectWithoutProperties(_props2, ['placeholderChar', 'formatCharacters']); // eslint-disable-line | ||
cleanedProps = _objectWithoutProperties(_props2, ['placeholderChar', 'formatCharacters']); // eslint-disable-line no-unused-vars | ||
@@ -302,4 +291,5 @@ | ||
return MaskedInput; | ||
}(React.Component); | ||
}(React.Component), _class.defaultProps = { | ||
value: '' | ||
}, _temp2); | ||
MaskedInput.propTypes = process.env.NODE_ENV !== "production" ? { | ||
@@ -312,6 +302,3 @@ mask: PropTypes.string.isRequired, | ||
MaskedInput.defaultProps = { | ||
value: '' | ||
}; | ||
export default MaskedInput; |
231
lib/index.js
@@ -7,2 +7,4 @@ 'use strict'; | ||
var _class, _temp2; | ||
var _react = require('react'); | ||
@@ -42,4 +44,4 @@ | ||
function getSelection(el) { | ||
var start, end, rangeEl, clone; | ||
var start = void 0, | ||
end = void 0; | ||
if (el.selectionStart !== undefined) { | ||
@@ -51,4 +53,4 @@ start = el.selectionStart; | ||
el.focus(); | ||
rangeEl = el.createTextRange(); | ||
clone = rangeEl.duplicate(); | ||
var rangeEl = el.createTextRange(); | ||
var clone = rangeEl.duplicate(); | ||
@@ -67,4 +69,2 @@ rangeEl.moveToBookmark(document.selection.createRange().getBookmark()); | ||
function setSelection(el, selection) { | ||
var rangeEl; | ||
try { | ||
@@ -76,3 +76,3 @@ if (el.selectionStart !== undefined) { | ||
el.focus(); | ||
rangeEl = el.createTextRange(); | ||
var rangeEl = el.createTextRange(); | ||
rangeEl.collapse(true); | ||
@@ -86,15 +86,104 @@ rangeEl.moveStart('character', selection.start); | ||
var MaskedInput = function (_React$Component) { | ||
var MaskedInput = (_temp2 = _class = function (_React$Component) { | ||
_inherits(MaskedInput, _React$Component); | ||
function MaskedInput(props) { | ||
function MaskedInput() { | ||
var _temp, _this, _ret; | ||
_classCallCheck(this, MaskedInput); | ||
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this._onChange = _this._onChange.bind(_this); | ||
_this._onKeyDown = _this._onKeyDown.bind(_this); | ||
_this._onPaste = _this._onPaste.bind(_this); | ||
_this._onKeyPress = _this._onKeyPress.bind(_this); | ||
return _this; | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this._onChange = function (e) { | ||
// console.log('onChange', JSON.stringify(getSelection(this.input)), e.target.value) | ||
var maskValue = _this.mask.getValue(); | ||
var incomingValue = e.target.value; | ||
if (incomingValue !== maskValue) { | ||
// only modify mask if form contents actually changed | ||
_this._updateMaskSelection(); | ||
_this.mask.setValue(incomingValue); // write the whole updated value into the mask | ||
e.target.value = _this._getDisplayValue(); // update the form with pattern applied to the value | ||
_this._updateInputSelection(); | ||
} | ||
if (_this.props.onChange) { | ||
_this.props.onChange(e); | ||
} | ||
}, _this._onKeyDown = function (e) { | ||
// console.log('onKeyDown', JSON.stringify(getSelection(this.input)), e.key, e.target.value) | ||
if (isUndo(e)) { | ||
e.preventDefault(); | ||
if (_this.mask.undo()) { | ||
e.target.value = _this._getDisplayValue(); | ||
_this._updateInputSelection(); | ||
if (_this.props.onChange) { | ||
_this.props.onChange(e); | ||
} | ||
} | ||
return; | ||
} else if (isRedo(e)) { | ||
e.preventDefault(); | ||
if (_this.mask.redo()) { | ||
e.target.value = _this._getDisplayValue(); | ||
_this._updateInputSelection(); | ||
if (_this.props.onChange) { | ||
_this.props.onChange(e); | ||
} | ||
} | ||
return; | ||
} | ||
if (e.key === 'Backspace') { | ||
e.preventDefault(); | ||
_this._updateMaskSelection(); | ||
if (_this.mask.backspace()) { | ||
var value = _this._getDisplayValue(); | ||
e.target.value = value; | ||
if (value) { | ||
_this._updateInputSelection(); | ||
} | ||
if (_this.props.onChange) { | ||
_this.props.onChange(e); | ||
} | ||
} | ||
} | ||
}, _this._onKeyPress = function (e) { | ||
// console.log('onKeyPress', JSON.stringify(getSelection(this.input)), e.key, e.target.value) | ||
// Ignore modified key presses | ||
// Ignore enter key to allow form submission | ||
if (e.metaKey || e.altKey || e.ctrlKey || e.key === 'Enter') { | ||
return; | ||
} | ||
e.preventDefault(); | ||
_this._updateMaskSelection(); | ||
if (_this.mask.input(e.key || e.data)) { | ||
e.target.value = _this.mask.getValue(); | ||
_this._updateInputSelection(); | ||
if (_this.props.onChange) { | ||
_this.props.onChange(e); | ||
} | ||
} | ||
}, _this._onPaste = function (e) { | ||
// console.log('onPaste', JSON.stringify(getSelection(this.input)), e.clipboardData.getData('Text'), e.target.value) | ||
e.preventDefault(); | ||
_this._updateMaskSelection(); | ||
// getData value needed for IE also works in FF & Chrome | ||
if (_this.mask.paste(e.clipboardData.getData('Text'))) { | ||
e.target.value = _this.mask.getValue(); | ||
// Timeout needed for IE | ||
setTimeout(function () { | ||
return _this._updateInputSelection(); | ||
}, 0); | ||
if (_this.props.onChange) { | ||
_this.props.onChange(e); | ||
} | ||
} | ||
}, _temp), _possibleConstructorReturn(_this, _ret); | ||
} | ||
@@ -159,102 +248,2 @@ | ||
MaskedInput.prototype._onChange = function _onChange(e) { | ||
// console.log('onChange', JSON.stringify(getSelection(this.input)), e.target.value) | ||
var maskValue = this.mask.getValue(); | ||
if (e.target.value !== maskValue) { | ||
// Cut or delete operations will have shortened the value | ||
if (e.target.value.length < maskValue.length) { | ||
var sizeDiff = maskValue.length - e.target.value.length; | ||
this._updateMaskSelection(); | ||
this.mask.selection.end = this.mask.selection.start + sizeDiff; | ||
this.mask.backspace(); | ||
} | ||
var value = this._getDisplayValue(); | ||
e.target.value = value; | ||
if (value) { | ||
this._updateInputSelection(); | ||
} | ||
} | ||
if (this.props.onChange) { | ||
this.props.onChange(e); | ||
} | ||
}; | ||
MaskedInput.prototype._onKeyDown = function _onKeyDown(e) { | ||
// console.log('onKeyDown', JSON.stringify(getSelection(this.input)), e.key, e.target.value) | ||
if (isUndo(e)) { | ||
e.preventDefault(); | ||
if (this.mask.undo()) { | ||
e.target.value = this._getDisplayValue(); | ||
this._updateInputSelection(); | ||
if (this.props.onChange) { | ||
this.props.onChange(e); | ||
} | ||
} | ||
return; | ||
} else if (isRedo(e)) { | ||
e.preventDefault(); | ||
if (this.mask.redo()) { | ||
e.target.value = this._getDisplayValue(); | ||
this._updateInputSelection(); | ||
if (this.props.onChange) { | ||
this.props.onChange(e); | ||
} | ||
} | ||
return; | ||
} | ||
if (e.key === 'Backspace') { | ||
e.preventDefault(); | ||
this._updateMaskSelection(); | ||
if (this.mask.backspace()) { | ||
var value = this._getDisplayValue(); | ||
e.target.value = value; | ||
if (value) { | ||
this._updateInputSelection(); | ||
} | ||
if (this.props.onChange) { | ||
this.props.onChange(e); | ||
} | ||
} | ||
} | ||
}; | ||
MaskedInput.prototype._onKeyPress = function _onKeyPress(e) { | ||
// console.log('onKeyPress', JSON.stringify(getSelection(this.input)), e.key, e.target.value) | ||
// Ignore modified key presses | ||
// Ignore enter key to allow form submission | ||
if (e.metaKey || e.altKey || e.ctrlKey || e.key === 'Enter') { | ||
return; | ||
} | ||
e.preventDefault(); | ||
this._updateMaskSelection(); | ||
if (this.mask.input(e.key || e.data)) { | ||
e.target.value = this.mask.getValue(); | ||
this._updateInputSelection(); | ||
if (this.props.onChange) { | ||
this.props.onChange(e); | ||
} | ||
} | ||
}; | ||
MaskedInput.prototype._onPaste = function _onPaste(e) { | ||
// console.log('onPaste', JSON.stringify(getSelection(this.input)), e.clipboardData.getData('Text'), e.target.value) | ||
e.preventDefault(); | ||
this._updateMaskSelection(); | ||
// getData value needed for IE also works in FF & Chrome | ||
if (this.mask.paste(e.clipboardData.getData('Text'))) { | ||
e.target.value = this.mask.getValue(); | ||
// Timeout needed for IE | ||
setTimeout(this._updateInputSelection, 0); | ||
if (this.props.onChange) { | ||
this.props.onChange(e); | ||
} | ||
} | ||
}; | ||
MaskedInput.prototype._getDisplayValue = function _getDisplayValue() { | ||
@@ -308,3 +297,3 @@ var value = this.mask.getValue(); | ||
formatCharacters = _props2.formatCharacters, | ||
cleanedProps = _objectWithoutProperties(_props2, ['placeholderChar', 'formatCharacters']); // eslint-disable-line | ||
cleanedProps = _objectWithoutProperties(_props2, ['placeholderChar', 'formatCharacters']); // eslint-disable-line no-unused-vars | ||
@@ -317,4 +306,5 @@ | ||
return MaskedInput; | ||
}(_react2.default.Component); | ||
}(_react2.default.Component), _class.defaultProps = { | ||
value: '' | ||
}, _temp2); | ||
MaskedInput.propTypes = process.env.NODE_ENV !== "production" ? { | ||
@@ -326,8 +316,3 @@ mask: _propTypes2.default.string.isRequired, | ||
} : {}; | ||
MaskedInput.defaultProps = { | ||
value: '' | ||
}; | ||
exports.default = MaskedInput; | ||
module.exports = exports['default']; |
{ | ||
"name": "react-maskedinput", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "Masked <input/> React component", | ||
@@ -26,9 +26,9 @@ "main": "lib/index.js", | ||
"peerDependencies": { | ||
"react": "^0.14.9 || ^15.3.0" | ||
"react": "^0.14.9 || ^15.3.0 || ^16.0.0" | ||
}, | ||
"devDependencies": { | ||
"eslint-config-jonnybuchanan": "5.0.x", | ||
"nwb": "0.17.x", | ||
"react": "15.x", | ||
"react-dom": "15.x" | ||
"nwb": "0.21.x", | ||
"react": "16.x", | ||
"react-dom": "16.x" | ||
}, | ||
@@ -35,0 +35,0 @@ "author": "Jonny Buchanan <jonathan.buchanan@gmail.com>", |
@@ -13,4 +13,2 @@ # `MaskedInput` | ||
`MaskedInput` can be used on the server, or bundled for the client using an npm-compatible packaging system such as [Browserify](http://browserify.org/) or [webpack](http://webpack.github.io/). | ||
``` | ||
@@ -22,3 +20,3 @@ npm install react-maskedinput --save | ||
The browser bundle exposes a global `MaskedInput` variable and expects to find a global `React` (>= 0.14.0) variable to work with. | ||
The browser bundle exposes a global `MaskedInput` variable and expects to find a global `React` variable to work with. | ||
@@ -33,17 +31,15 @@ * [react-maskedinput.js](https://unpkg.com/react-maskedinput/umd/react-maskedinput.js) (development version) | ||
```javascript | ||
var React = require('react') | ||
var MaskedInput = require('react-maskedinput') | ||
import React from 'react' | ||
import MaskedInput from 'react-maskedinput' | ||
var CreditCardDetails = React.createClass({ | ||
state: { | ||
class CreditCardDetails extends React.Component { | ||
state = { | ||
card: '', | ||
expiry: '', | ||
ccv: '' | ||
}, | ||
} | ||
_onChange(e) { | ||
var stateChange = {} | ||
stateChange[e.target.name] = e.target.value | ||
this.setState(stateChange) | ||
}, | ||
_onChange = (e) => { | ||
this.setState({[e.target.name]: e.target.value}) | ||
} | ||
@@ -66,3 +62,3 @@ render() { | ||
} | ||
}) | ||
} | ||
``` | ||
@@ -73,18 +69,16 @@ | ||
```javascript | ||
var CustomInput = React.createClass({ | ||
render() { | ||
return <MaskedInput | ||
mask="1111-WW-11" | ||
placeholder="1234-WW-12" | ||
size="11" | ||
{...this.props} | ||
formatCharacters={{ | ||
'W': { | ||
validate(char) { return /\w/.test(char ) }, | ||
transform(char) { return char.toUpperCase() } | ||
} | ||
function CustomInput(props) { | ||
return <MaskedInput | ||
mask="1111-WW-11" | ||
placeholder="1234-WW-12" | ||
size="11" | ||
{...props} | ||
formatCharacters={{ | ||
'W': { | ||
validate(char) { return /\w/.test(char ) }, | ||
transform(char) { return char.toUpperCase() } | ||
} | ||
}/> | ||
} | ||
}) | ||
}} | ||
/> | ||
} | ||
``` | ||
@@ -91,0 +85,0 @@ |
/*! | ||
* react-maskedinput v4.0.0 - https://github.com/insin/react-maskedinput | ||
* react-maskedinput v4.0.1 - https://github.com/insin/react-maskedinput | ||
* MIT Licensed | ||
@@ -14,3 +14,3 @@ */ | ||
root["MaskedInput"] = factory(root["React"]); | ||
})(this, function(__WEBPACK_EXTERNAL_MODULE_9__) { | ||
})(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE_6__) { | ||
return /******/ (function(modules) { // webpackBootstrap | ||
@@ -51,5 +51,2 @@ /******/ // The module cache | ||
/******/ | ||
/******/ // identity function for calling harmony imports with the correct context | ||
/******/ __webpack_require__.i = function(value) { return value; }; | ||
/******/ | ||
/******/ // define getter function for harmony exports | ||
@@ -82,3 +79,3 @@ /******/ __webpack_require__.d = function(exports, name, getter) { | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 10); | ||
/******/ return __webpack_require__(__webpack_require__.s = 4); | ||
/******/ }) | ||
@@ -286,2 +283,9 @@ /************************************************************************/ | ||
/* 4 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(5); | ||
/***/ }), | ||
/* 5 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
@@ -291,10 +295,12 @@ | ||
Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_react__ = __webpack_require__(9); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_react__ = __webpack_require__(6); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_react___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_react__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_prop_types__ = __webpack_require__(8); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_prop_types__ = __webpack_require__(7); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_prop_types___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_prop_types__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_inputmask_core__ = __webpack_require__(5); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_inputmask_core__ = __webpack_require__(10); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_inputmask_core___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_inputmask_core__); | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _class, _temp2; | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
@@ -324,4 +330,4 @@ | ||
function getSelection(el) { | ||
var start, end, rangeEl, clone; | ||
var start = void 0, | ||
end = void 0; | ||
if (el.selectionStart !== undefined) { | ||
@@ -333,4 +339,4 @@ start = el.selectionStart; | ||
el.focus(); | ||
rangeEl = el.createTextRange(); | ||
clone = rangeEl.duplicate(); | ||
var rangeEl = el.createTextRange(); | ||
var clone = rangeEl.duplicate(); | ||
@@ -349,4 +355,2 @@ rangeEl.moveToBookmark(document.selection.createRange().getBookmark()); | ||
function setSelection(el, selection) { | ||
var rangeEl; | ||
try { | ||
@@ -358,3 +362,3 @@ if (el.selectionStart !== undefined) { | ||
el.focus(); | ||
rangeEl = el.createTextRange(); | ||
var rangeEl = el.createTextRange(); | ||
rangeEl.collapse(true); | ||
@@ -368,15 +372,104 @@ rangeEl.moveStart('character', selection.start); | ||
var MaskedInput = function (_React$Component) { | ||
var MaskedInput = (_temp2 = _class = function (_React$Component) { | ||
_inherits(MaskedInput, _React$Component); | ||
function MaskedInput(props) { | ||
function MaskedInput() { | ||
var _temp, _this, _ret; | ||
_classCallCheck(this, MaskedInput); | ||
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this._onChange = _this._onChange.bind(_this); | ||
_this._onKeyDown = _this._onKeyDown.bind(_this); | ||
_this._onPaste = _this._onPaste.bind(_this); | ||
_this._onKeyPress = _this._onKeyPress.bind(_this); | ||
return _this; | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this._onChange = function (e) { | ||
// console.log('onChange', JSON.stringify(getSelection(this.input)), e.target.value) | ||
var maskValue = _this.mask.getValue(); | ||
var incomingValue = e.target.value; | ||
if (incomingValue !== maskValue) { | ||
// only modify mask if form contents actually changed | ||
_this._updateMaskSelection(); | ||
_this.mask.setValue(incomingValue); // write the whole updated value into the mask | ||
e.target.value = _this._getDisplayValue(); // update the form with pattern applied to the value | ||
_this._updateInputSelection(); | ||
} | ||
if (_this.props.onChange) { | ||
_this.props.onChange(e); | ||
} | ||
}, _this._onKeyDown = function (e) { | ||
// console.log('onKeyDown', JSON.stringify(getSelection(this.input)), e.key, e.target.value) | ||
if (isUndo(e)) { | ||
e.preventDefault(); | ||
if (_this.mask.undo()) { | ||
e.target.value = _this._getDisplayValue(); | ||
_this._updateInputSelection(); | ||
if (_this.props.onChange) { | ||
_this.props.onChange(e); | ||
} | ||
} | ||
return; | ||
} else if (isRedo(e)) { | ||
e.preventDefault(); | ||
if (_this.mask.redo()) { | ||
e.target.value = _this._getDisplayValue(); | ||
_this._updateInputSelection(); | ||
if (_this.props.onChange) { | ||
_this.props.onChange(e); | ||
} | ||
} | ||
return; | ||
} | ||
if (e.key === 'Backspace') { | ||
e.preventDefault(); | ||
_this._updateMaskSelection(); | ||
if (_this.mask.backspace()) { | ||
var value = _this._getDisplayValue(); | ||
e.target.value = value; | ||
if (value) { | ||
_this._updateInputSelection(); | ||
} | ||
if (_this.props.onChange) { | ||
_this.props.onChange(e); | ||
} | ||
} | ||
} | ||
}, _this._onKeyPress = function (e) { | ||
// console.log('onKeyPress', JSON.stringify(getSelection(this.input)), e.key, e.target.value) | ||
// Ignore modified key presses | ||
// Ignore enter key to allow form submission | ||
if (e.metaKey || e.altKey || e.ctrlKey || e.key === 'Enter') { | ||
return; | ||
} | ||
e.preventDefault(); | ||
_this._updateMaskSelection(); | ||
if (_this.mask.input(e.key || e.data)) { | ||
e.target.value = _this.mask.getValue(); | ||
_this._updateInputSelection(); | ||
if (_this.props.onChange) { | ||
_this.props.onChange(e); | ||
} | ||
} | ||
}, _this._onPaste = function (e) { | ||
// console.log('onPaste', JSON.stringify(getSelection(this.input)), e.clipboardData.getData('Text'), e.target.value) | ||
e.preventDefault(); | ||
_this._updateMaskSelection(); | ||
// getData value needed for IE also works in FF & Chrome | ||
if (_this.mask.paste(e.clipboardData.getData('Text'))) { | ||
e.target.value = _this.mask.getValue(); | ||
// Timeout needed for IE | ||
setTimeout(function () { | ||
return _this._updateInputSelection(); | ||
}, 0); | ||
if (_this.props.onChange) { | ||
_this.props.onChange(e); | ||
} | ||
} | ||
}, _temp), _possibleConstructorReturn(_this, _ret); | ||
} | ||
@@ -441,102 +534,2 @@ | ||
MaskedInput.prototype._onChange = function _onChange(e) { | ||
// console.log('onChange', JSON.stringify(getSelection(this.input)), e.target.value) | ||
var maskValue = this.mask.getValue(); | ||
if (e.target.value !== maskValue) { | ||
// Cut or delete operations will have shortened the value | ||
if (e.target.value.length < maskValue.length) { | ||
var sizeDiff = maskValue.length - e.target.value.length; | ||
this._updateMaskSelection(); | ||
this.mask.selection.end = this.mask.selection.start + sizeDiff; | ||
this.mask.backspace(); | ||
} | ||
var value = this._getDisplayValue(); | ||
e.target.value = value; | ||
if (value) { | ||
this._updateInputSelection(); | ||
} | ||
} | ||
if (this.props.onChange) { | ||
this.props.onChange(e); | ||
} | ||
}; | ||
MaskedInput.prototype._onKeyDown = function _onKeyDown(e) { | ||
// console.log('onKeyDown', JSON.stringify(getSelection(this.input)), e.key, e.target.value) | ||
if (isUndo(e)) { | ||
e.preventDefault(); | ||
if (this.mask.undo()) { | ||
e.target.value = this._getDisplayValue(); | ||
this._updateInputSelection(); | ||
if (this.props.onChange) { | ||
this.props.onChange(e); | ||
} | ||
} | ||
return; | ||
} else if (isRedo(e)) { | ||
e.preventDefault(); | ||
if (this.mask.redo()) { | ||
e.target.value = this._getDisplayValue(); | ||
this._updateInputSelection(); | ||
if (this.props.onChange) { | ||
this.props.onChange(e); | ||
} | ||
} | ||
return; | ||
} | ||
if (e.key === 'Backspace') { | ||
e.preventDefault(); | ||
this._updateMaskSelection(); | ||
if (this.mask.backspace()) { | ||
var value = this._getDisplayValue(); | ||
e.target.value = value; | ||
if (value) { | ||
this._updateInputSelection(); | ||
} | ||
if (this.props.onChange) { | ||
this.props.onChange(e); | ||
} | ||
} | ||
} | ||
}; | ||
MaskedInput.prototype._onKeyPress = function _onKeyPress(e) { | ||
// console.log('onKeyPress', JSON.stringify(getSelection(this.input)), e.key, e.target.value) | ||
// Ignore modified key presses | ||
// Ignore enter key to allow form submission | ||
if (e.metaKey || e.altKey || e.ctrlKey || e.key === 'Enter') { | ||
return; | ||
} | ||
e.preventDefault(); | ||
this._updateMaskSelection(); | ||
if (this.mask.input(e.key || e.data)) { | ||
e.target.value = this.mask.getValue(); | ||
this._updateInputSelection(); | ||
if (this.props.onChange) { | ||
this.props.onChange(e); | ||
} | ||
} | ||
}; | ||
MaskedInput.prototype._onPaste = function _onPaste(e) { | ||
// console.log('onPaste', JSON.stringify(getSelection(this.input)), e.clipboardData.getData('Text'), e.target.value) | ||
e.preventDefault(); | ||
this._updateMaskSelection(); | ||
// getData value needed for IE also works in FF & Chrome | ||
if (this.mask.paste(e.clipboardData.getData('Text'))) { | ||
e.target.value = this.mask.getValue(); | ||
// Timeout needed for IE | ||
setTimeout(this._updateInputSelection, 0); | ||
if (this.props.onChange) { | ||
this.props.onChange(e); | ||
} | ||
} | ||
}; | ||
MaskedInput.prototype._getDisplayValue = function _getDisplayValue() { | ||
@@ -590,3 +583,3 @@ var value = this.mask.getValue(); | ||
formatCharacters = _props2.formatCharacters, | ||
cleanedProps = _objectWithoutProperties(_props2, ['placeholderChar', 'formatCharacters']); // eslint-disable-line | ||
cleanedProps = _objectWithoutProperties(_props2, ['placeholderChar', 'formatCharacters']); // eslint-disable-line no-unused-vars | ||
@@ -599,5 +592,3 @@ | ||
return MaskedInput; | ||
}(__WEBPACK_IMPORTED_MODULE_0_react___default.a.Component); | ||
MaskedInput.propTypes = { | ||
}(__WEBPACK_IMPORTED_MODULE_0_react___default.a.Component), _class.propTypes = { | ||
mask: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.string.isRequired, | ||
@@ -607,539 +598,19 @@ | ||
placeholderChar: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.string | ||
}; | ||
MaskedInput.defaultProps = { | ||
}, _class.defaultProps = { | ||
value: '' | ||
}; | ||
}, _temp2); | ||
/* harmony default export */ __webpack_exports__["default"] = (MaskedInput); | ||
/***/ }), | ||
/* 5 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
/* 6 */ | ||
/***/ (function(module, exports) { | ||
"use strict"; | ||
module.exports = __WEBPACK_EXTERNAL_MODULE_6__; | ||
function extend(dest, src) { | ||
if (src) { | ||
var props = Object.keys(src) | ||
for (var i = 0, l = props.length; i < l ; i++) { | ||
dest[props[i]] = src[props[i]] | ||
} | ||
} | ||
return dest | ||
} | ||
function copy(obj) { | ||
return extend({}, obj) | ||
} | ||
/** | ||
* Merge an object defining format characters into the defaults. | ||
* Passing null/undefined for en existing format character removes it. | ||
* Passing a definition for an existing format character overrides it. | ||
* @param {?Object} formatCharacters. | ||
*/ | ||
function mergeFormatCharacters(formatCharacters) { | ||
var merged = copy(DEFAULT_FORMAT_CHARACTERS) | ||
if (formatCharacters) { | ||
var chars = Object.keys(formatCharacters) | ||
for (var i = 0, l = chars.length; i < l ; i++) { | ||
var char = chars[i] | ||
if (formatCharacters[char] == null) { | ||
delete merged[char] | ||
} | ||
else { | ||
merged[char] = formatCharacters[char] | ||
} | ||
} | ||
} | ||
return merged | ||
} | ||
var ESCAPE_CHAR = '\\' | ||
var DIGIT_RE = /^\d$/ | ||
var LETTER_RE = /^[A-Za-z]$/ | ||
var ALPHANNUMERIC_RE = /^[\dA-Za-z]$/ | ||
var DEFAULT_PLACEHOLDER_CHAR = '_' | ||
var DEFAULT_FORMAT_CHARACTERS = { | ||
'*': { | ||
validate: function(char) { return ALPHANNUMERIC_RE.test(char) } | ||
}, | ||
'1': { | ||
validate: function(char) { return DIGIT_RE.test(char) } | ||
}, | ||
'a': { | ||
validate: function(char) { return LETTER_RE.test(char) } | ||
}, | ||
'A': { | ||
validate: function(char) { return LETTER_RE.test(char) }, | ||
transform: function(char) { return char.toUpperCase() } | ||
}, | ||
'#': { | ||
validate: function(char) { return ALPHANNUMERIC_RE.test(char) }, | ||
transform: function(char) { return char.toUpperCase() } | ||
} | ||
} | ||
/** | ||
* @param {string} source | ||
* @patam {?Object} formatCharacters | ||
*/ | ||
function Pattern(source, formatCharacters, placeholderChar, isRevealingMask) { | ||
if (!(this instanceof Pattern)) { | ||
return new Pattern(source, formatCharacters, placeholderChar) | ||
} | ||
/** Placeholder character */ | ||
this.placeholderChar = placeholderChar || DEFAULT_PLACEHOLDER_CHAR | ||
/** Format character definitions. */ | ||
this.formatCharacters = formatCharacters || DEFAULT_FORMAT_CHARACTERS | ||
/** Pattern definition string with escape characters. */ | ||
this.source = source | ||
/** Pattern characters after escape characters have been processed. */ | ||
this.pattern = [] | ||
/** Length of the pattern after escape characters have been processed. */ | ||
this.length = 0 | ||
/** Index of the first editable character. */ | ||
this.firstEditableIndex = null | ||
/** Index of the last editable character. */ | ||
this.lastEditableIndex = null | ||
/** Lookup for indices of editable characters in the pattern. */ | ||
this._editableIndices = {} | ||
/** If true, only the pattern before the last valid value character shows. */ | ||
this.isRevealingMask = isRevealingMask || false | ||
this._parse() | ||
} | ||
Pattern.prototype._parse = function parse() { | ||
var sourceChars = this.source.split('') | ||
var patternIndex = 0 | ||
var pattern = [] | ||
for (var i = 0, l = sourceChars.length; i < l; i++) { | ||
var char = sourceChars[i] | ||
if (char === ESCAPE_CHAR) { | ||
if (i === l - 1) { | ||
throw new Error('InputMask: pattern ends with a raw ' + ESCAPE_CHAR) | ||
} | ||
char = sourceChars[++i] | ||
} | ||
else if (char in this.formatCharacters) { | ||
if (this.firstEditableIndex === null) { | ||
this.firstEditableIndex = patternIndex | ||
} | ||
this.lastEditableIndex = patternIndex | ||
this._editableIndices[patternIndex] = true | ||
} | ||
pattern.push(char) | ||
patternIndex++ | ||
} | ||
if (this.firstEditableIndex === null) { | ||
throw new Error( | ||
'InputMask: pattern "' + this.source + '" does not contain any editable characters.' | ||
) | ||
} | ||
this.pattern = pattern | ||
this.length = pattern.length | ||
} | ||
/** | ||
* @param {Array<string>} value | ||
* @return {Array<string>} | ||
*/ | ||
Pattern.prototype.formatValue = function format(value) { | ||
var valueBuffer = new Array(this.length) | ||
var valueIndex = 0 | ||
for (var i = 0, l = this.length; i < l ; i++) { | ||
if (this.isEditableIndex(i)) { | ||
if (this.isRevealingMask && | ||
value.length <= valueIndex && | ||
!this.isValidAtIndex(value[valueIndex], i)) { | ||
break | ||
} | ||
valueBuffer[i] = (value.length > valueIndex && this.isValidAtIndex(value[valueIndex], i) | ||
? this.transform(value[valueIndex], i) | ||
: this.placeholderChar) | ||
valueIndex++ | ||
} | ||
else { | ||
valueBuffer[i] = this.pattern[i] | ||
// Also allow the value to contain static values from the pattern by | ||
// advancing its index. | ||
if (value.length > valueIndex && value[valueIndex] === this.pattern[i]) { | ||
valueIndex++ | ||
} | ||
} | ||
} | ||
return valueBuffer | ||
} | ||
/** | ||
* @param {number} index | ||
* @return {boolean} | ||
*/ | ||
Pattern.prototype.isEditableIndex = function isEditableIndex(index) { | ||
return !!this._editableIndices[index] | ||
} | ||
/** | ||
* @param {string} char | ||
* @param {number} index | ||
* @return {boolean} | ||
*/ | ||
Pattern.prototype.isValidAtIndex = function isValidAtIndex(char, index) { | ||
return this.formatCharacters[this.pattern[index]].validate(char) | ||
} | ||
Pattern.prototype.transform = function transform(char, index) { | ||
var format = this.formatCharacters[this.pattern[index]] | ||
return typeof format.transform == 'function' ? format.transform(char) : char | ||
} | ||
function InputMask(options) { | ||
if (!(this instanceof InputMask)) { return new InputMask(options) } | ||
options = extend({ | ||
formatCharacters: null, | ||
pattern: null, | ||
isRevealingMask: false, | ||
placeholderChar: DEFAULT_PLACEHOLDER_CHAR, | ||
selection: {start: 0, end: 0}, | ||
value: '' | ||
}, options) | ||
if (options.pattern == null) { | ||
throw new Error('InputMask: you must provide a pattern.') | ||
} | ||
if (typeof options.placeholderChar !== 'string' || options.placeholderChar.length > 1) { | ||
throw new Error('InputMask: placeholderChar should be a single character or an empty string.') | ||
} | ||
this.placeholderChar = options.placeholderChar | ||
this.formatCharacters = mergeFormatCharacters(options.formatCharacters) | ||
this.setPattern(options.pattern, { | ||
value: options.value, | ||
selection: options.selection, | ||
isRevealingMask: options.isRevealingMask | ||
}) | ||
} | ||
// Editing | ||
/** | ||
* Applies a single character of input based on the current selection. | ||
* @param {string} char | ||
* @return {boolean} true if a change has been made to value or selection as a | ||
* result of the input, false otherwise. | ||
*/ | ||
InputMask.prototype.input = function input(char) { | ||
// Ignore additional input if the cursor's at the end of the pattern | ||
if (this.selection.start === this.selection.end && | ||
this.selection.start === this.pattern.length) { | ||
return false | ||
} | ||
var selectionBefore = copy(this.selection) | ||
var valueBefore = this.getValue() | ||
var inputIndex = this.selection.start | ||
// If the cursor or selection is prior to the first editable character, make | ||
// sure any input given is applied to it. | ||
if (inputIndex < this.pattern.firstEditableIndex) { | ||
inputIndex = this.pattern.firstEditableIndex | ||
} | ||
// Bail out or add the character to input | ||
if (this.pattern.isEditableIndex(inputIndex)) { | ||
if (!this.pattern.isValidAtIndex(char, inputIndex)) { | ||
return false | ||
} | ||
this.value[inputIndex] = this.pattern.transform(char, inputIndex) | ||
} | ||
// If multiple characters were selected, blank the remainder out based on the | ||
// pattern. | ||
var end = this.selection.end - 1 | ||
while (end > inputIndex) { | ||
if (this.pattern.isEditableIndex(end)) { | ||
this.value[end] = this.placeholderChar | ||
} | ||
end-- | ||
} | ||
// Advance the cursor to the next character | ||
this.selection.start = this.selection.end = inputIndex + 1 | ||
// Skip over any subsequent static characters | ||
while (this.pattern.length > this.selection.start && | ||
!this.pattern.isEditableIndex(this.selection.start)) { | ||
this.selection.start++ | ||
this.selection.end++ | ||
} | ||
// History | ||
if (this._historyIndex != null) { | ||
// Took more input after undoing, so blow any subsequent history away | ||
this._history.splice(this._historyIndex, this._history.length - this._historyIndex) | ||
this._historyIndex = null | ||
} | ||
if (this._lastOp !== 'input' || | ||
selectionBefore.start !== selectionBefore.end || | ||
this._lastSelection !== null && selectionBefore.start !== this._lastSelection.start) { | ||
this._history.push({value: valueBefore, selection: selectionBefore, lastOp: this._lastOp}) | ||
} | ||
this._lastOp = 'input' | ||
this._lastSelection = copy(this.selection) | ||
return true | ||
} | ||
/** | ||
* Attempts to delete from the value based on the current cursor position or | ||
* selection. | ||
* @return {boolean} true if the value or selection changed as the result of | ||
* backspacing, false otherwise. | ||
*/ | ||
InputMask.prototype.backspace = function backspace() { | ||
// If the cursor is at the start there's nothing to do | ||
if (this.selection.start === 0 && this.selection.end === 0) { | ||
return false | ||
} | ||
var selectionBefore = copy(this.selection) | ||
var valueBefore = this.getValue() | ||
// No range selected - work on the character preceding the cursor | ||
if (this.selection.start === this.selection.end) { | ||
if (this.pattern.isEditableIndex(this.selection.start - 1)) { | ||
this.value[this.selection.start - 1] = this.placeholderChar | ||
} | ||
this.selection.start-- | ||
this.selection.end-- | ||
} | ||
// Range selected - delete characters and leave the cursor at the start of the selection | ||
else { | ||
var end = this.selection.end - 1 | ||
while (end >= this.selection.start) { | ||
if (this.pattern.isEditableIndex(end)) { | ||
this.value[end] = this.placeholderChar | ||
} | ||
end-- | ||
} | ||
this.selection.end = this.selection.start | ||
} | ||
// History | ||
if (this._historyIndex != null) { | ||
// Took more input after undoing, so blow any subsequent history away | ||
this._history.splice(this._historyIndex, this._history.length - this._historyIndex) | ||
} | ||
if (this._lastOp !== 'backspace' || | ||
selectionBefore.start !== selectionBefore.end || | ||
this._lastSelection !== null && selectionBefore.start !== this._lastSelection.start) { | ||
this._history.push({value: valueBefore, selection: selectionBefore, lastOp: this._lastOp}) | ||
} | ||
this._lastOp = 'backspace' | ||
this._lastSelection = copy(this.selection) | ||
return true | ||
} | ||
/** | ||
* Attempts to paste a string of input at the current cursor position or over | ||
* the top of the current selection. | ||
* Invalid content at any position will cause the paste to be rejected, and it | ||
* may contain static parts of the mask's pattern. | ||
* @param {string} input | ||
* @return {boolean} true if the paste was successful, false otherwise. | ||
*/ | ||
InputMask.prototype.paste = function paste(input) { | ||
// This is necessary because we're just calling input() with each character | ||
// and rolling back if any were invalid, rather than checking up-front. | ||
var initialState = { | ||
value: this.value.slice(), | ||
selection: copy(this.selection), | ||
_lastOp: this._lastOp, | ||
_history: this._history.slice(), | ||
_historyIndex: this._historyIndex, | ||
_lastSelection: copy(this._lastSelection) | ||
} | ||
// If there are static characters at the start of the pattern and the cursor | ||
// or selection is within them, the static characters must match for a valid | ||
// paste. | ||
if (this.selection.start < this.pattern.firstEditableIndex) { | ||
for (var i = 0, l = this.pattern.firstEditableIndex - this.selection.start; i < l; i++) { | ||
if (input.charAt(i) !== this.pattern.pattern[i]) { | ||
return false | ||
} | ||
} | ||
// Continue as if the selection and input started from the editable part of | ||
// the pattern. | ||
input = input.substring(this.pattern.firstEditableIndex - this.selection.start) | ||
this.selection.start = this.pattern.firstEditableIndex | ||
} | ||
for (i = 0, l = input.length; | ||
i < l && this.selection.start <= this.pattern.lastEditableIndex; | ||
i++) { | ||
var valid = this.input(input.charAt(i)) | ||
// Allow static parts of the pattern to appear in pasted input - they will | ||
// already have been stepped over by input(), so verify that the value | ||
// deemed invalid by input() was the expected static character. | ||
if (!valid) { | ||
if (this.selection.start > 0) { | ||
// XXX This only allows for one static character to be skipped | ||
var patternIndex = this.selection.start - 1 | ||
if (!this.pattern.isEditableIndex(patternIndex) && | ||
input.charAt(i) === this.pattern.pattern[patternIndex]) { | ||
continue | ||
} | ||
} | ||
extend(this, initialState) | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
// History | ||
InputMask.prototype.undo = function undo() { | ||
// If there is no history, or nothing more on the history stack, we can't undo | ||
if (this._history.length === 0 || this._historyIndex === 0) { | ||
return false | ||
} | ||
var historyItem | ||
if (this._historyIndex == null) { | ||
// Not currently undoing, set up the initial history index | ||
this._historyIndex = this._history.length - 1 | ||
historyItem = this._history[this._historyIndex] | ||
// Add a new history entry if anything has changed since the last one, so we | ||
// can redo back to the initial state we started undoing from. | ||
var value = this.getValue() | ||
if (historyItem.value !== value || | ||
historyItem.selection.start !== this.selection.start || | ||
historyItem.selection.end !== this.selection.end) { | ||
this._history.push({value: value, selection: copy(this.selection), lastOp: this._lastOp, startUndo: true}) | ||
} | ||
} | ||
else { | ||
historyItem = this._history[--this._historyIndex] | ||
} | ||
this.value = historyItem.value.split('') | ||
this.selection = historyItem.selection | ||
this._lastOp = historyItem.lastOp | ||
return true | ||
} | ||
InputMask.prototype.redo = function redo() { | ||
if (this._history.length === 0 || this._historyIndex == null) { | ||
return false | ||
} | ||
var historyItem = this._history[++this._historyIndex] | ||
// If this is the last history item, we're done redoing | ||
if (this._historyIndex === this._history.length - 1) { | ||
this._historyIndex = null | ||
// If the last history item was only added to start undoing, remove it | ||
if (historyItem.startUndo) { | ||
this._history.pop() | ||
} | ||
} | ||
this.value = historyItem.value.split('') | ||
this.selection = historyItem.selection | ||
this._lastOp = historyItem.lastOp | ||
return true | ||
} | ||
// Getters & setters | ||
InputMask.prototype.setPattern = function setPattern(pattern, options) { | ||
options = extend({ | ||
selection: {start: 0, end: 0}, | ||
value: '' | ||
}, options) | ||
this.pattern = new Pattern(pattern, this.formatCharacters, this.placeholderChar, options.isRevealingMask) | ||
this.setValue(options.value) | ||
this.emptyValue = this.pattern.formatValue([]).join('') | ||
this.selection = options.selection | ||
this._resetHistory() | ||
} | ||
InputMask.prototype.setSelection = function setSelection(selection) { | ||
this.selection = copy(selection) | ||
if (this.selection.start === this.selection.end) { | ||
if (this.selection.start < this.pattern.firstEditableIndex) { | ||
this.selection.start = this.selection.end = this.pattern.firstEditableIndex | ||
return true | ||
} | ||
// Set selection to the first editable, non-placeholder character before the selection | ||
// OR to the beginning of the pattern | ||
var index = this.selection.start | ||
while (index >= this.pattern.firstEditableIndex) { | ||
if (this.pattern.isEditableIndex(index - 1) && | ||
this.value[index - 1] !== this.placeholderChar || | ||
index === this.pattern.firstEditableIndex) { | ||
this.selection.start = this.selection.end = index | ||
break | ||
} | ||
index-- | ||
} | ||
return true | ||
} | ||
return false | ||
} | ||
InputMask.prototype.setValue = function setValue(value) { | ||
if (value == null) { | ||
value = '' | ||
} | ||
this.value = this.pattern.formatValue(value.split('')) | ||
} | ||
InputMask.prototype.getValue = function getValue() { | ||
return this.value.join('') | ||
} | ||
InputMask.prototype.getRawValue = function getRawValue() { | ||
var rawValue = [] | ||
for (var i = 0; i < this.value.length; i++) { | ||
if (this.pattern._editableIndices[i] === true) { | ||
rawValue.push(this.value[i]) | ||
} | ||
} | ||
return rawValue.join('') | ||
} | ||
InputMask.prototype._resetHistory = function _resetHistory() { | ||
this._history = [] | ||
this._historyIndex = null | ||
this._lastOp = null | ||
this._lastSelection = copy(this.selection) | ||
} | ||
InputMask.Pattern = Pattern | ||
module.exports = InputMask | ||
/***/ }), | ||
/* 6 */ | ||
/* 7 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
/** | ||
@@ -1154,58 +625,27 @@ * Copyright 2013-present, Facebook, Inc. | ||
if (true) { | ||
var invariant = __webpack_require__(1); | ||
var warning = __webpack_require__(2); | ||
var ReactPropTypesSecret = __webpack_require__(3); | ||
var loggedTypeFailures = {}; | ||
} | ||
var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' && | ||
Symbol.for && | ||
Symbol.for('react.element')) || | ||
0xeac7; | ||
/** | ||
* Assert that the values match with the type specs. | ||
* Error messages are memorized and will only be shown once. | ||
* | ||
* @param {object} typeSpecs Map of name to a ReactPropType | ||
* @param {object} values Runtime values that need to be type-checked | ||
* @param {string} location e.g. "prop", "context", "child context" | ||
* @param {string} componentName Name of the component for error messages. | ||
* @param {?Function} getStack Returns the component stack. | ||
* @private | ||
*/ | ||
function checkPropTypes(typeSpecs, values, location, componentName, getStack) { | ||
if (true) { | ||
for (var typeSpecName in typeSpecs) { | ||
if (typeSpecs.hasOwnProperty(typeSpecName)) { | ||
var error; | ||
// Prop type validation may throw. In case they do, we don't want to | ||
// fail the render phase where it didn't fail before. So we log it. | ||
// After these have been cleaned up, we'll let them throw. | ||
try { | ||
// This is intentionally an invariant that gets caught. It's the same | ||
// behavior as without this statement except with a better message. | ||
invariant(typeof typeSpecs[typeSpecName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'React.PropTypes.', componentName || 'React class', location, typeSpecName); | ||
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret); | ||
} catch (ex) { | ||
error = ex; | ||
} | ||
warning(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error); | ||
if (error instanceof Error && !(error.message in loggedTypeFailures)) { | ||
// Only monitor this failure once because there tends to be a lot of the | ||
// same error. | ||
loggedTypeFailures[error.message] = true; | ||
var isValidElement = function(object) { | ||
return typeof object === 'object' && | ||
object !== null && | ||
object.$$typeof === REACT_ELEMENT_TYPE; | ||
}; | ||
var stack = getStack ? getStack() : ''; | ||
warning(false, 'Failed %s type: %s%s', location, error.message, stack != null ? stack : ''); | ||
} | ||
} | ||
} | ||
} | ||
// By explicitly using `prop-types` you are opting into new development behavior. | ||
// http://fb.me/prop-types-in-prod | ||
var throwOnDirectAccess = true; | ||
module.exports = __webpack_require__(8)(isValidElement, throwOnDirectAccess); | ||
} else { | ||
// By explicitly using `prop-types` you are opting into new production behavior. | ||
// http://fb.me/prop-types-in-prod | ||
module.exports = require('./factoryWithThrowingShims')(); | ||
} | ||
module.exports = checkPropTypes; | ||
/***/ }), | ||
/* 7 */ | ||
/* 8 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -1230,3 +670,3 @@ | ||
var ReactPropTypesSecret = __webpack_require__(3); | ||
var checkPropTypes = __webpack_require__(6); | ||
var checkPropTypes = __webpack_require__(9); | ||
@@ -1730,5 +1170,6 @@ module.exports = function(isValidElement, throwOnDirectAccess) { | ||
/***/ }), | ||
/* 8 */ | ||
/* 9 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
/** | ||
@@ -1743,31 +1184,56 @@ * Copyright 2013-present, Facebook, Inc. | ||
if (true) { | ||
var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' && | ||
Symbol.for && | ||
Symbol.for('react.element')) || | ||
0xeac7; | ||
var invariant = __webpack_require__(1); | ||
var warning = __webpack_require__(2); | ||
var ReactPropTypesSecret = __webpack_require__(3); | ||
var loggedTypeFailures = {}; | ||
} | ||
var isValidElement = function(object) { | ||
return typeof object === 'object' && | ||
object !== null && | ||
object.$$typeof === REACT_ELEMENT_TYPE; | ||
}; | ||
/** | ||
* Assert that the values match with the type specs. | ||
* Error messages are memorized and will only be shown once. | ||
* | ||
* @param {object} typeSpecs Map of name to a ReactPropType | ||
* @param {object} values Runtime values that need to be type-checked | ||
* @param {string} location e.g. "prop", "context", "child context" | ||
* @param {string} componentName Name of the component for error messages. | ||
* @param {?Function} getStack Returns the component stack. | ||
* @private | ||
*/ | ||
function checkPropTypes(typeSpecs, values, location, componentName, getStack) { | ||
if (true) { | ||
for (var typeSpecName in typeSpecs) { | ||
if (typeSpecs.hasOwnProperty(typeSpecName)) { | ||
var error; | ||
// Prop type validation may throw. In case they do, we don't want to | ||
// fail the render phase where it didn't fail before. So we log it. | ||
// After these have been cleaned up, we'll let them throw. | ||
try { | ||
// This is intentionally an invariant that gets caught. It's the same | ||
// behavior as without this statement except with a better message. | ||
invariant(typeof typeSpecs[typeSpecName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'React.PropTypes.', componentName || 'React class', location, typeSpecName); | ||
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret); | ||
} catch (ex) { | ||
error = ex; | ||
} | ||
warning(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error); | ||
if (error instanceof Error && !(error.message in loggedTypeFailures)) { | ||
// Only monitor this failure once because there tends to be a lot of the | ||
// same error. | ||
loggedTypeFailures[error.message] = true; | ||
// By explicitly using `prop-types` you are opting into new development behavior. | ||
// http://fb.me/prop-types-in-prod | ||
var throwOnDirectAccess = true; | ||
module.exports = __webpack_require__(7)(isValidElement, throwOnDirectAccess); | ||
} else { | ||
// By explicitly using `prop-types` you are opting into new production behavior. | ||
// http://fb.me/prop-types-in-prod | ||
module.exports = require('./factoryWithThrowingShims')(); | ||
var stack = getStack ? getStack() : ''; | ||
warning(false, 'Failed %s type: %s%s', location, error.message, stack != null ? stack : ''); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
module.exports = checkPropTypes; | ||
/***/ }), | ||
/* 9 */ | ||
/***/ (function(module, exports) { | ||
module.exports = __WEBPACK_EXTERNAL_MODULE_9__; | ||
/***/ }), | ||
@@ -1777,7 +1243,524 @@ /* 10 */ | ||
module.exports = __webpack_require__(4); | ||
"use strict"; | ||
function extend(dest, src) { | ||
if (src) { | ||
var props = Object.keys(src) | ||
for (var i = 0, l = props.length; i < l ; i++) { | ||
dest[props[i]] = src[props[i]] | ||
} | ||
} | ||
return dest | ||
} | ||
function copy(obj) { | ||
return extend({}, obj) | ||
} | ||
/** | ||
* Merge an object defining format characters into the defaults. | ||
* Passing null/undefined for en existing format character removes it. | ||
* Passing a definition for an existing format character overrides it. | ||
* @param {?Object} formatCharacters. | ||
*/ | ||
function mergeFormatCharacters(formatCharacters) { | ||
var merged = copy(DEFAULT_FORMAT_CHARACTERS) | ||
if (formatCharacters) { | ||
var chars = Object.keys(formatCharacters) | ||
for (var i = 0, l = chars.length; i < l ; i++) { | ||
var char = chars[i] | ||
if (formatCharacters[char] == null) { | ||
delete merged[char] | ||
} | ||
else { | ||
merged[char] = formatCharacters[char] | ||
} | ||
} | ||
} | ||
return merged | ||
} | ||
var ESCAPE_CHAR = '\\' | ||
var DIGIT_RE = /^\d$/ | ||
var LETTER_RE = /^[A-Za-z]$/ | ||
var ALPHANNUMERIC_RE = /^[\dA-Za-z]$/ | ||
var DEFAULT_PLACEHOLDER_CHAR = '_' | ||
var DEFAULT_FORMAT_CHARACTERS = { | ||
'*': { | ||
validate: function(char) { return ALPHANNUMERIC_RE.test(char) } | ||
}, | ||
'1': { | ||
validate: function(char) { return DIGIT_RE.test(char) } | ||
}, | ||
'a': { | ||
validate: function(char) { return LETTER_RE.test(char) } | ||
}, | ||
'A': { | ||
validate: function(char) { return LETTER_RE.test(char) }, | ||
transform: function(char) { return char.toUpperCase() } | ||
}, | ||
'#': { | ||
validate: function(char) { return ALPHANNUMERIC_RE.test(char) }, | ||
transform: function(char) { return char.toUpperCase() } | ||
} | ||
} | ||
/** | ||
* @param {string} source | ||
* @patam {?Object} formatCharacters | ||
*/ | ||
function Pattern(source, formatCharacters, placeholderChar, isRevealingMask) { | ||
if (!(this instanceof Pattern)) { | ||
return new Pattern(source, formatCharacters, placeholderChar) | ||
} | ||
/** Placeholder character */ | ||
this.placeholderChar = placeholderChar || DEFAULT_PLACEHOLDER_CHAR | ||
/** Format character definitions. */ | ||
this.formatCharacters = formatCharacters || DEFAULT_FORMAT_CHARACTERS | ||
/** Pattern definition string with escape characters. */ | ||
this.source = source | ||
/** Pattern characters after escape characters have been processed. */ | ||
this.pattern = [] | ||
/** Length of the pattern after escape characters have been processed. */ | ||
this.length = 0 | ||
/** Index of the first editable character. */ | ||
this.firstEditableIndex = null | ||
/** Index of the last editable character. */ | ||
this.lastEditableIndex = null | ||
/** Lookup for indices of editable characters in the pattern. */ | ||
this._editableIndices = {} | ||
/** If true, only the pattern before the last valid value character shows. */ | ||
this.isRevealingMask = isRevealingMask || false | ||
this._parse() | ||
} | ||
Pattern.prototype._parse = function parse() { | ||
var sourceChars = this.source.split('') | ||
var patternIndex = 0 | ||
var pattern = [] | ||
for (var i = 0, l = sourceChars.length; i < l; i++) { | ||
var char = sourceChars[i] | ||
if (char === ESCAPE_CHAR) { | ||
if (i === l - 1) { | ||
throw new Error('InputMask: pattern ends with a raw ' + ESCAPE_CHAR) | ||
} | ||
char = sourceChars[++i] | ||
} | ||
else if (char in this.formatCharacters) { | ||
if (this.firstEditableIndex === null) { | ||
this.firstEditableIndex = patternIndex | ||
} | ||
this.lastEditableIndex = patternIndex | ||
this._editableIndices[patternIndex] = true | ||
} | ||
pattern.push(char) | ||
patternIndex++ | ||
} | ||
if (this.firstEditableIndex === null) { | ||
throw new Error( | ||
'InputMask: pattern "' + this.source + '" does not contain any editable characters.' | ||
) | ||
} | ||
this.pattern = pattern | ||
this.length = pattern.length | ||
} | ||
/** | ||
* @param {Array<string>} value | ||
* @return {Array<string>} | ||
*/ | ||
Pattern.prototype.formatValue = function format(value) { | ||
var valueBuffer = new Array(this.length) | ||
var valueIndex = 0 | ||
for (var i = 0, l = this.length; i < l ; i++) { | ||
if (this.isEditableIndex(i)) { | ||
if (this.isRevealingMask && | ||
value.length <= valueIndex && | ||
!this.isValidAtIndex(value[valueIndex], i)) { | ||
break | ||
} | ||
valueBuffer[i] = (value.length > valueIndex && this.isValidAtIndex(value[valueIndex], i) | ||
? this.transform(value[valueIndex], i) | ||
: this.placeholderChar) | ||
valueIndex++ | ||
} | ||
else { | ||
valueBuffer[i] = this.pattern[i] | ||
// Also allow the value to contain static values from the pattern by | ||
// advancing its index. | ||
if (value.length > valueIndex && value[valueIndex] === this.pattern[i]) { | ||
valueIndex++ | ||
} | ||
} | ||
} | ||
return valueBuffer | ||
} | ||
/** | ||
* @param {number} index | ||
* @return {boolean} | ||
*/ | ||
Pattern.prototype.isEditableIndex = function isEditableIndex(index) { | ||
return !!this._editableIndices[index] | ||
} | ||
/** | ||
* @param {string} char | ||
* @param {number} index | ||
* @return {boolean} | ||
*/ | ||
Pattern.prototype.isValidAtIndex = function isValidAtIndex(char, index) { | ||
return this.formatCharacters[this.pattern[index]].validate(char) | ||
} | ||
Pattern.prototype.transform = function transform(char, index) { | ||
var format = this.formatCharacters[this.pattern[index]] | ||
return typeof format.transform == 'function' ? format.transform(char) : char | ||
} | ||
function InputMask(options) { | ||
if (!(this instanceof InputMask)) { return new InputMask(options) } | ||
options = extend({ | ||
formatCharacters: null, | ||
pattern: null, | ||
isRevealingMask: false, | ||
placeholderChar: DEFAULT_PLACEHOLDER_CHAR, | ||
selection: {start: 0, end: 0}, | ||
value: '' | ||
}, options) | ||
if (options.pattern == null) { | ||
throw new Error('InputMask: you must provide a pattern.') | ||
} | ||
if (typeof options.placeholderChar !== 'string' || options.placeholderChar.length > 1) { | ||
throw new Error('InputMask: placeholderChar should be a single character or an empty string.') | ||
} | ||
this.placeholderChar = options.placeholderChar | ||
this.formatCharacters = mergeFormatCharacters(options.formatCharacters) | ||
this.setPattern(options.pattern, { | ||
value: options.value, | ||
selection: options.selection, | ||
isRevealingMask: options.isRevealingMask | ||
}) | ||
} | ||
// Editing | ||
/** | ||
* Applies a single character of input based on the current selection. | ||
* @param {string} char | ||
* @return {boolean} true if a change has been made to value or selection as a | ||
* result of the input, false otherwise. | ||
*/ | ||
InputMask.prototype.input = function input(char) { | ||
// Ignore additional input if the cursor's at the end of the pattern | ||
if (this.selection.start === this.selection.end && | ||
this.selection.start === this.pattern.length) { | ||
return false | ||
} | ||
var selectionBefore = copy(this.selection) | ||
var valueBefore = this.getValue() | ||
var inputIndex = this.selection.start | ||
// If the cursor or selection is prior to the first editable character, make | ||
// sure any input given is applied to it. | ||
if (inputIndex < this.pattern.firstEditableIndex) { | ||
inputIndex = this.pattern.firstEditableIndex | ||
} | ||
// Bail out or add the character to input | ||
if (this.pattern.isEditableIndex(inputIndex)) { | ||
if (!this.pattern.isValidAtIndex(char, inputIndex)) { | ||
return false | ||
} | ||
this.value[inputIndex] = this.pattern.transform(char, inputIndex) | ||
} | ||
// If multiple characters were selected, blank the remainder out based on the | ||
// pattern. | ||
var end = this.selection.end - 1 | ||
while (end > inputIndex) { | ||
if (this.pattern.isEditableIndex(end)) { | ||
this.value[end] = this.placeholderChar | ||
} | ||
end-- | ||
} | ||
// Advance the cursor to the next character | ||
this.selection.start = this.selection.end = inputIndex + 1 | ||
// Skip over any subsequent static characters | ||
while (this.pattern.length > this.selection.start && | ||
!this.pattern.isEditableIndex(this.selection.start)) { | ||
this.selection.start++ | ||
this.selection.end++ | ||
} | ||
// History | ||
if (this._historyIndex != null) { | ||
// Took more input after undoing, so blow any subsequent history away | ||
this._history.splice(this._historyIndex, this._history.length - this._historyIndex) | ||
this._historyIndex = null | ||
} | ||
if (this._lastOp !== 'input' || | ||
selectionBefore.start !== selectionBefore.end || | ||
this._lastSelection !== null && selectionBefore.start !== this._lastSelection.start) { | ||
this._history.push({value: valueBefore, selection: selectionBefore, lastOp: this._lastOp}) | ||
} | ||
this._lastOp = 'input' | ||
this._lastSelection = copy(this.selection) | ||
return true | ||
} | ||
/** | ||
* Attempts to delete from the value based on the current cursor position or | ||
* selection. | ||
* @return {boolean} true if the value or selection changed as the result of | ||
* backspacing, false otherwise. | ||
*/ | ||
InputMask.prototype.backspace = function backspace() { | ||
// If the cursor is at the start there's nothing to do | ||
if (this.selection.start === 0 && this.selection.end === 0) { | ||
return false | ||
} | ||
var selectionBefore = copy(this.selection) | ||
var valueBefore = this.getValue() | ||
// No range selected - work on the character preceding the cursor | ||
if (this.selection.start === this.selection.end) { | ||
if (this.pattern.isEditableIndex(this.selection.start - 1)) { | ||
this.value[this.selection.start - 1] = this.placeholderChar | ||
} | ||
this.selection.start-- | ||
this.selection.end-- | ||
} | ||
// Range selected - delete characters and leave the cursor at the start of the selection | ||
else { | ||
var end = this.selection.end - 1 | ||
while (end >= this.selection.start) { | ||
if (this.pattern.isEditableIndex(end)) { | ||
this.value[end] = this.placeholderChar | ||
} | ||
end-- | ||
} | ||
this.selection.end = this.selection.start | ||
} | ||
// History | ||
if (this._historyIndex != null) { | ||
// Took more input after undoing, so blow any subsequent history away | ||
this._history.splice(this._historyIndex, this._history.length - this._historyIndex) | ||
} | ||
if (this._lastOp !== 'backspace' || | ||
selectionBefore.start !== selectionBefore.end || | ||
this._lastSelection !== null && selectionBefore.start !== this._lastSelection.start) { | ||
this._history.push({value: valueBefore, selection: selectionBefore, lastOp: this._lastOp}) | ||
} | ||
this._lastOp = 'backspace' | ||
this._lastSelection = copy(this.selection) | ||
return true | ||
} | ||
/** | ||
* Attempts to paste a string of input at the current cursor position or over | ||
* the top of the current selection. | ||
* Invalid content at any position will cause the paste to be rejected, and it | ||
* may contain static parts of the mask's pattern. | ||
* @param {string} input | ||
* @return {boolean} true if the paste was successful, false otherwise. | ||
*/ | ||
InputMask.prototype.paste = function paste(input) { | ||
// This is necessary because we're just calling input() with each character | ||
// and rolling back if any were invalid, rather than checking up-front. | ||
var initialState = { | ||
value: this.value.slice(), | ||
selection: copy(this.selection), | ||
_lastOp: this._lastOp, | ||
_history: this._history.slice(), | ||
_historyIndex: this._historyIndex, | ||
_lastSelection: copy(this._lastSelection) | ||
} | ||
// If there are static characters at the start of the pattern and the cursor | ||
// or selection is within them, the static characters must match for a valid | ||
// paste. | ||
if (this.selection.start < this.pattern.firstEditableIndex) { | ||
for (var i = 0, l = this.pattern.firstEditableIndex - this.selection.start; i < l; i++) { | ||
if (input.charAt(i) !== this.pattern.pattern[i]) { | ||
return false | ||
} | ||
} | ||
// Continue as if the selection and input started from the editable part of | ||
// the pattern. | ||
input = input.substring(this.pattern.firstEditableIndex - this.selection.start) | ||
this.selection.start = this.pattern.firstEditableIndex | ||
} | ||
for (i = 0, l = input.length; | ||
i < l && this.selection.start <= this.pattern.lastEditableIndex; | ||
i++) { | ||
var valid = this.input(input.charAt(i)) | ||
// Allow static parts of the pattern to appear in pasted input - they will | ||
// already have been stepped over by input(), so verify that the value | ||
// deemed invalid by input() was the expected static character. | ||
if (!valid) { | ||
if (this.selection.start > 0) { | ||
// XXX This only allows for one static character to be skipped | ||
var patternIndex = this.selection.start - 1 | ||
if (!this.pattern.isEditableIndex(patternIndex) && | ||
input.charAt(i) === this.pattern.pattern[patternIndex]) { | ||
continue | ||
} | ||
} | ||
extend(this, initialState) | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
// History | ||
InputMask.prototype.undo = function undo() { | ||
// If there is no history, or nothing more on the history stack, we can't undo | ||
if (this._history.length === 0 || this._historyIndex === 0) { | ||
return false | ||
} | ||
var historyItem | ||
if (this._historyIndex == null) { | ||
// Not currently undoing, set up the initial history index | ||
this._historyIndex = this._history.length - 1 | ||
historyItem = this._history[this._historyIndex] | ||
// Add a new history entry if anything has changed since the last one, so we | ||
// can redo back to the initial state we started undoing from. | ||
var value = this.getValue() | ||
if (historyItem.value !== value || | ||
historyItem.selection.start !== this.selection.start || | ||
historyItem.selection.end !== this.selection.end) { | ||
this._history.push({value: value, selection: copy(this.selection), lastOp: this._lastOp, startUndo: true}) | ||
} | ||
} | ||
else { | ||
historyItem = this._history[--this._historyIndex] | ||
} | ||
this.value = historyItem.value.split('') | ||
this.selection = historyItem.selection | ||
this._lastOp = historyItem.lastOp | ||
return true | ||
} | ||
InputMask.prototype.redo = function redo() { | ||
if (this._history.length === 0 || this._historyIndex == null) { | ||
return false | ||
} | ||
var historyItem = this._history[++this._historyIndex] | ||
// If this is the last history item, we're done redoing | ||
if (this._historyIndex === this._history.length - 1) { | ||
this._historyIndex = null | ||
// If the last history item was only added to start undoing, remove it | ||
if (historyItem.startUndo) { | ||
this._history.pop() | ||
} | ||
} | ||
this.value = historyItem.value.split('') | ||
this.selection = historyItem.selection | ||
this._lastOp = historyItem.lastOp | ||
return true | ||
} | ||
// Getters & setters | ||
InputMask.prototype.setPattern = function setPattern(pattern, options) { | ||
options = extend({ | ||
selection: {start: 0, end: 0}, | ||
value: '' | ||
}, options) | ||
this.pattern = new Pattern(pattern, this.formatCharacters, this.placeholderChar, options.isRevealingMask) | ||
this.setValue(options.value) | ||
this.emptyValue = this.pattern.formatValue([]).join('') | ||
this.selection = options.selection | ||
this._resetHistory() | ||
} | ||
InputMask.prototype.setSelection = function setSelection(selection) { | ||
this.selection = copy(selection) | ||
if (this.selection.start === this.selection.end) { | ||
if (this.selection.start < this.pattern.firstEditableIndex) { | ||
this.selection.start = this.selection.end = this.pattern.firstEditableIndex | ||
return true | ||
} | ||
// Set selection to the first editable, non-placeholder character before the selection | ||
// OR to the beginning of the pattern | ||
var index = this.selection.start | ||
while (index >= this.pattern.firstEditableIndex) { | ||
if (this.pattern.isEditableIndex(index - 1) && | ||
this.value[index - 1] !== this.placeholderChar || | ||
index === this.pattern.firstEditableIndex) { | ||
this.selection.start = this.selection.end = index | ||
break | ||
} | ||
index-- | ||
} | ||
return true | ||
} | ||
return false | ||
} | ||
InputMask.prototype.setValue = function setValue(value) { | ||
if (value == null) { | ||
value = '' | ||
} | ||
this.value = this.pattern.formatValue(value.split('')) | ||
} | ||
InputMask.prototype.getValue = function getValue() { | ||
return this.value.join('') | ||
} | ||
InputMask.prototype.getRawValue = function getRawValue() { | ||
var rawValue = [] | ||
for (var i = 0; i < this.value.length; i++) { | ||
if (this.pattern._editableIndices[i] === true) { | ||
rawValue.push(this.value[i]) | ||
} | ||
} | ||
return rawValue.join('') | ||
} | ||
InputMask.prototype._resetHistory = function _resetHistory() { | ||
this._history = [] | ||
this._historyIndex = null | ||
this._lastOp = null | ||
this._lastSelection = copy(this.selection) | ||
} | ||
InputMask.Pattern = Pattern | ||
module.exports = InputMask | ||
/***/ }) | ||
/******/ ]); | ||
/******/ ])["default"]; | ||
}); |
/*! | ||
* react-maskedinput v4.0.0 - https://github.com/insin/react-maskedinput | ||
* react-maskedinput v4.0.1 - https://github.com/insin/react-maskedinput | ||
* MIT Licensed | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports.MaskedInput=e(require("react")):t.MaskedInput=e(t.React)}(this,function(t){return function(t){function e(i){if(s[i])return s[i].exports;var n=s[i]={i:i,l:!1,exports:{}};return t[i].call(n.exports,n,n.exports,e),n.l=!0,n.exports}var s={};return e.m=t,e.c=s,e.i=function(t){return t},e.d=function(t,s,i){e.o(t,s)||Object.defineProperty(t,s,{configurable:!1,enumerable:!0,get:i})},e.n=function(t){var s=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(s,"a",s),s},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=3)}([function(t,e,s){"use strict";function i(t,e){var s={};for(var i in t)e.indexOf(i)>=0||Object.prototype.hasOwnProperty.call(t,i)&&(s[i]=t[i]);return s}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function o(t){return(t.ctrlKey||t.metaKey)&&t.keyCode===(t.shiftKey?_:v)}function h(t){return(t.ctrlKey||t.metaKey)&&t.keyCode===(t.shiftKey?v:_)}function l(t){var e,s,i,n;if(void 0!==t.selectionStart)e=t.selectionStart,s=t.selectionEnd;else try{t.focus(),i=t.createTextRange(),n=i.duplicate(),i.moveToBookmark(document.selection.createRange().getBookmark()),n.setEndPoint("EndToStart",i),e=n.text.length,s=e+i.text.length}catch(t){}return{start:e,end:s}}function p(t,e){var s;try{void 0!==t.selectionStart?(t.focus(),t.setSelectionRange(e.start,e.end)):(t.focus(),s=t.createTextRange(),s.collapse(!0),s.moveStart("character",e.start),s.moveEnd("character",e.end-e.start),s.select())}catch(t){}}Object.defineProperty(e,"__esModule",{value:!0});var u=s(2),c=s.n(u),d=s(1),f=s.n(d),y=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(t[i]=s[i])}return t},v=90,_=89,g=function(t){function e(s){n(this,e);var i=r(this,t.call(this,s));return i._onChange=i._onChange.bind(i),i._onKeyDown=i._onKeyDown.bind(i),i._onPaste=i._onPaste.bind(i),i._onKeyPress=i._onKeyPress.bind(i),i}return a(e,t),e.prototype.componentWillMount=function(){var t={pattern:this.props.mask,value:this.props.value,formatCharacters:this.props.formatCharacters};this.props.placeholderChar&&(t.placeholderChar=this.props.placeholderChar),this.mask=new f.a(t)},e.prototype.componentWillReceiveProps=function(t){this.props.mask!==t.mask&&this.props.value!==t.mask?this.mask.getValue()===this.mask.emptyValue?this.mask.setPattern(t.mask,{value:t.value}):this.mask.setPattern(t.mask,{value:this.mask.getRawValue()}):this.props.mask!==t.mask?this.mask.setPattern(t.mask,{value:this.mask.getRawValue()}):this.props.value!==t.value&&this.mask.setValue(t.value)},e.prototype.componentWillUpdate=function(t,e){t.mask!==this.props.mask&&this._updatePattern(t)},e.prototype.componentDidUpdate=function(t){t.mask!==this.props.mask&&this.mask.selection.start&&this._updateInputSelection()},e.prototype._updatePattern=function(t){this.mask.setPattern(t.mask,{value:this.mask.getRawValue(),selection:l(this.input)})},e.prototype._updateMaskSelection=function(){this.mask.selection=l(this.input)},e.prototype._updateInputSelection=function(){p(this.input,this.mask.selection)},e.prototype._onChange=function(t){var e=this.mask.getValue();if(t.target.value!==e){if(t.target.value.length<e.length){var s=e.length-t.target.value.length;this._updateMaskSelection(),this.mask.selection.end=this.mask.selection.start+s,this.mask.backspace()}var i=this._getDisplayValue();t.target.value=i,i&&this._updateInputSelection()}this.props.onChange&&this.props.onChange(t)},e.prototype._onKeyDown=function(t){if(o(t))return t.preventDefault(),void(this.mask.undo()&&(t.target.value=this._getDisplayValue(),this._updateInputSelection(),this.props.onChange&&this.props.onChange(t)));if(h(t))return t.preventDefault(),void(this.mask.redo()&&(t.target.value=this._getDisplayValue(),this._updateInputSelection(),this.props.onChange&&this.props.onChange(t)));if("Backspace"===t.key&&(t.preventDefault(),this._updateMaskSelection(),this.mask.backspace())){var e=this._getDisplayValue();t.target.value=e,e&&this._updateInputSelection(),this.props.onChange&&this.props.onChange(t)}},e.prototype._onKeyPress=function(t){t.metaKey||t.altKey||t.ctrlKey||"Enter"===t.key||(t.preventDefault(),this._updateMaskSelection(),this.mask.input(t.key||t.data)&&(t.target.value=this.mask.getValue(),this._updateInputSelection(),this.props.onChange&&this.props.onChange(t)))},e.prototype._onPaste=function(t){t.preventDefault(),this._updateMaskSelection(),this.mask.paste(t.clipboardData.getData("Text"))&&(t.target.value=this.mask.getValue(),setTimeout(this._updateInputSelection,0),this.props.onChange&&this.props.onChange(t))},e.prototype._getDisplayValue=function(){var t=this.mask.getValue();return t===this.mask.emptyValue?"":t},e.prototype._keyPressPropName=function(){return"undefined"!=typeof navigator&&navigator.userAgent.match(/Android/i)?"onBeforeInput":"onKeyPress"},e.prototype._getEventHandlers=function(){var t;return t={onChange:this._onChange,onKeyDown:this._onKeyDown,onPaste:this._onPaste},t[this._keyPressPropName()]=this._onKeyPress,t},e.prototype.focus=function(){this.input.focus()},e.prototype.blur=function(){this.input.blur()},e.prototype.render=function(){var t=this,e=function(e){t.input=e},s=this.mask.pattern.length,n=this._getDisplayValue(),r=this._getEventHandlers(),a=this.props,o=a.size,h=void 0===o?s:o,l=a.placeholder,p=void 0===l?this.mask.emptyValue:l,u=this.props,d=(u.placeholderChar,u.formatCharacters,i(u,["placeholderChar","formatCharacters"])),f=y({},d,r,{ref:e,maxLength:s,value:n,size:h,placeholder:p});return c.a.createElement("input",f)},e}(c.a.Component);g.defaultProps={value:""},e.default=g},function(t,e,s){"use strict";function i(t,e){if(e)for(var s=Object.keys(e),i=0,n=s.length;i<n;i++)t[s[i]]=e[s[i]];return t}function n(t){return i({},t)}function r(t){var e=n(c);if(t)for(var s=Object.keys(t),i=0,r=s.length;i<r;i++){var a=s[i];null==t[a]?delete e[a]:e[a]=t[a]}return e}function a(t,e,s,i){if(!(this instanceof a))return new a(t,e,s);this.placeholderChar=s||u,this.formatCharacters=e||c,this.source=t,this.pattern=[],this.length=0,this.firstEditableIndex=null,this.lastEditableIndex=null,this._editableIndices={},this.isRevealingMask=i||!1,this._parse()}function o(t){if(!(this instanceof o))return new o(t);if(t=i({formatCharacters:null,pattern:null,isRevealingMask:!1,placeholderChar:u,selection:{start:0,end:0},value:""},t),null==t.pattern)throw new Error("InputMask: you must provide a pattern.");if("string"!=typeof t.placeholderChar||t.placeholderChar.length>1)throw new Error("InputMask: placeholderChar should be a single character or an empty string.");this.placeholderChar=t.placeholderChar,this.formatCharacters=r(t.formatCharacters),this.setPattern(t.pattern,{value:t.value,selection:t.selection,isRevealingMask:t.isRevealingMask})}var h=/^\d$/,l=/^[A-Za-z]$/,p=/^[\dA-Za-z]$/,u="_",c={"*":{validate:function(t){return p.test(t)}},1:{validate:function(t){return h.test(t)}},a:{validate:function(t){return l.test(t)}},A:{validate:function(t){return l.test(t)},transform:function(t){return t.toUpperCase()}},"#":{validate:function(t){return p.test(t)},transform:function(t){return t.toUpperCase()}}};a.prototype._parse=function(){for(var t=this.source.split(""),e=0,s=[],i=0,n=t.length;i<n;i++){var r=t[i];if("\\"===r){if(i===n-1)throw new Error("InputMask: pattern ends with a raw \\");r=t[++i]}else r in this.formatCharacters&&(null===this.firstEditableIndex&&(this.firstEditableIndex=e),this.lastEditableIndex=e,this._editableIndices[e]=!0);s.push(r),e++}if(null===this.firstEditableIndex)throw new Error('InputMask: pattern "'+this.source+'" does not contain any editable characters.');this.pattern=s,this.length=s.length},a.prototype.formatValue=function(t){for(var e=new Array(this.length),s=0,i=0,n=this.length;i<n;i++)if(this.isEditableIndex(i)){if(this.isRevealingMask&&t.length<=s&&!this.isValidAtIndex(t[s],i))break;e[i]=t.length>s&&this.isValidAtIndex(t[s],i)?this.transform(t[s],i):this.placeholderChar,s++}else e[i]=this.pattern[i],t.length>s&&t[s]===this.pattern[i]&&s++;return e},a.prototype.isEditableIndex=function(t){return!!this._editableIndices[t]},a.prototype.isValidAtIndex=function(t,e){return this.formatCharacters[this.pattern[e]].validate(t)},a.prototype.transform=function(t,e){var s=this.formatCharacters[this.pattern[e]];return"function"==typeof s.transform?s.transform(t):t},o.prototype.input=function(t){if(this.selection.start===this.selection.end&&this.selection.start===this.pattern.length)return!1;var e=n(this.selection),s=this.getValue(),i=this.selection.start;if(i<this.pattern.firstEditableIndex&&(i=this.pattern.firstEditableIndex),this.pattern.isEditableIndex(i)){if(!this.pattern.isValidAtIndex(t,i))return!1;this.value[i]=this.pattern.transform(t,i)}for(var r=this.selection.end-1;r>i;)this.pattern.isEditableIndex(r)&&(this.value[r]=this.placeholderChar),r--;for(this.selection.start=this.selection.end=i+1;this.pattern.length>this.selection.start&&!this.pattern.isEditableIndex(this.selection.start);)this.selection.start++,this.selection.end++;return null!=this._historyIndex&&(this._history.splice(this._historyIndex,this._history.length-this._historyIndex),this._historyIndex=null),("input"!==this._lastOp||e.start!==e.end||null!==this._lastSelection&&e.start!==this._lastSelection.start)&&this._history.push({value:s,selection:e,lastOp:this._lastOp}),this._lastOp="input",this._lastSelection=n(this.selection),!0},o.prototype.backspace=function(){if(0===this.selection.start&&0===this.selection.end)return!1;var t=n(this.selection),e=this.getValue();if(this.selection.start===this.selection.end)this.pattern.isEditableIndex(this.selection.start-1)&&(this.value[this.selection.start-1]=this.placeholderChar),this.selection.start--,this.selection.end--;else{for(var s=this.selection.end-1;s>=this.selection.start;)this.pattern.isEditableIndex(s)&&(this.value[s]=this.placeholderChar),s--;this.selection.end=this.selection.start}return null!=this._historyIndex&&this._history.splice(this._historyIndex,this._history.length-this._historyIndex),("backspace"!==this._lastOp||t.start!==t.end||null!==this._lastSelection&&t.start!==this._lastSelection.start)&&this._history.push({value:e,selection:t,lastOp:this._lastOp}),this._lastOp="backspace",this._lastSelection=n(this.selection),!0},o.prototype.paste=function(t){var e={value:this.value.slice(),selection:n(this.selection),_lastOp:this._lastOp,_history:this._history.slice(),_historyIndex:this._historyIndex,_lastSelection:n(this._lastSelection)};if(this.selection.start<this.pattern.firstEditableIndex){for(var s=0,r=this.pattern.firstEditableIndex-this.selection.start;s<r;s++)if(t.charAt(s)!==this.pattern.pattern[s])return!1;t=t.substring(this.pattern.firstEditableIndex-this.selection.start),this.selection.start=this.pattern.firstEditableIndex}for(s=0,r=t.length;s<r&&this.selection.start<=this.pattern.lastEditableIndex;s++){if(!this.input(t.charAt(s))){if(this.selection.start>0){var a=this.selection.start-1;if(!this.pattern.isEditableIndex(a)&&t.charAt(s)===this.pattern.pattern[a])continue}return i(this,e),!1}}return!0},o.prototype.undo=function(){if(0===this._history.length||0===this._historyIndex)return!1;var t;if(null==this._historyIndex){this._historyIndex=this._history.length-1,t=this._history[this._historyIndex];var e=this.getValue();t.value===e&&t.selection.start===this.selection.start&&t.selection.end===this.selection.end||this._history.push({value:e,selection:n(this.selection),lastOp:this._lastOp,startUndo:!0})}else t=this._history[--this._historyIndex];return this.value=t.value.split(""),this.selection=t.selection,this._lastOp=t.lastOp,!0},o.prototype.redo=function(){if(0===this._history.length||null==this._historyIndex)return!1;var t=this._history[++this._historyIndex];return this._historyIndex===this._history.length-1&&(this._historyIndex=null,t.startUndo&&this._history.pop()),this.value=t.value.split(""),this.selection=t.selection,this._lastOp=t.lastOp,!0},o.prototype.setPattern=function(t,e){e=i({selection:{start:0,end:0},value:""},e),this.pattern=new a(t,this.formatCharacters,this.placeholderChar,e.isRevealingMask),this.setValue(e.value),this.emptyValue=this.pattern.formatValue([]).join(""),this.selection=e.selection,this._resetHistory()},o.prototype.setSelection=function(t){if(this.selection=n(t),this.selection.start===this.selection.end){if(this.selection.start<this.pattern.firstEditableIndex)return this.selection.start=this.selection.end=this.pattern.firstEditableIndex,!0;for(var e=this.selection.start;e>=this.pattern.firstEditableIndex;){if(this.pattern.isEditableIndex(e-1)&&this.value[e-1]!==this.placeholderChar||e===this.pattern.firstEditableIndex){this.selection.start=this.selection.end=e;break}e--}return!0}return!1},o.prototype.setValue=function(t){null==t&&(t=""),this.value=this.pattern.formatValue(t.split(""))},o.prototype.getValue=function(){return this.value.join("")},o.prototype.getRawValue=function(){for(var t=[],e=0;e<this.value.length;e++)!0===this.pattern._editableIndices[e]&&t.push(this.value[e]);return t.join("")},o.prototype._resetHistory=function(){this._history=[],this._historyIndex=null,this._lastOp=null,this._lastSelection=n(this.selection)},o.Pattern=a,t.exports=o},function(e,s){e.exports=t},function(t,e,s){t.exports=s(0)}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports.MaskedInput=e(require("react")):t.MaskedInput=e(t.React)}("undefined"!=typeof self?self:this,function(t){return function(t){var e={};function s(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,s),i.l=!0,i.exports}return s.m=t,s.c=e,s.d=function(t,e,n){s.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},s.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return s.d(e,"a",e),e},s.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},s.p="",s(s.s=0)}([function(t,e,s){t.exports=s(1)},function(t,e,s){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,i,r=s(2),a=s.n(r),o=s(3),l=s.n(o),h=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&(t[n]=s[n])}return t};function p(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}var u=90,c=89;function d(t){var e=void 0,s=void 0;if(void 0!==t.selectionStart)e=t.selectionStart,s=t.selectionEnd;else try{t.focus();var n=t.createTextRange(),i=n.duplicate();n.moveToBookmark(document.selection.createRange().getBookmark()),i.setEndPoint("EndToStart",n),s=(e=i.text.length)+n.text.length}catch(t){}return{start:e,end:s}}var f=(i=n=function(t){function e(){var s,n;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);for(var i=arguments.length,r=Array(i),a=0;a<i;a++)r[a]=arguments[a];return s=n=p(this,t.call.apply(t,[this].concat(r))),n._onChange=function(t){var e=n.mask.getValue(),s=t.target.value;s!==e&&(n._updateMaskSelection(),n.mask.setValue(s),t.target.value=n._getDisplayValue(),n._updateInputSelection()),n.props.onChange&&n.props.onChange(t)},n._onKeyDown=function(t){if(function(t){return(t.ctrlKey||t.metaKey)&&t.keyCode===(t.shiftKey?c:u)}(t))return t.preventDefault(),void(n.mask.undo()&&(t.target.value=n._getDisplayValue(),n._updateInputSelection(),n.props.onChange&&n.props.onChange(t)));if(function(t){return(t.ctrlKey||t.metaKey)&&t.keyCode===(t.shiftKey?u:c)}(t))return t.preventDefault(),void(n.mask.redo()&&(t.target.value=n._getDisplayValue(),n._updateInputSelection(),n.props.onChange&&n.props.onChange(t)));if("Backspace"===t.key&&(t.preventDefault(),n._updateMaskSelection(),n.mask.backspace())){var e=n._getDisplayValue();t.target.value=e,e&&n._updateInputSelection(),n.props.onChange&&n.props.onChange(t)}},n._onKeyPress=function(t){t.metaKey||t.altKey||t.ctrlKey||"Enter"===t.key||(t.preventDefault(),n._updateMaskSelection(),n.mask.input(t.key||t.data)&&(t.target.value=n.mask.getValue(),n._updateInputSelection(),n.props.onChange&&n.props.onChange(t)))},n._onPaste=function(t){t.preventDefault(),n._updateMaskSelection(),n.mask.paste(t.clipboardData.getData("Text"))&&(t.target.value=n.mask.getValue(),setTimeout(function(){return n._updateInputSelection()},0),n.props.onChange&&n.props.onChange(t))},p(n,s)}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e.prototype.componentWillMount=function(){var t={pattern:this.props.mask,value:this.props.value,formatCharacters:this.props.formatCharacters};this.props.placeholderChar&&(t.placeholderChar=this.props.placeholderChar),this.mask=new l.a(t)},e.prototype.componentWillReceiveProps=function(t){this.props.mask!==t.mask&&this.props.value!==t.mask?this.mask.getValue()===this.mask.emptyValue?this.mask.setPattern(t.mask,{value:t.value}):this.mask.setPattern(t.mask,{value:this.mask.getRawValue()}):this.props.mask!==t.mask?this.mask.setPattern(t.mask,{value:this.mask.getRawValue()}):this.props.value!==t.value&&this.mask.setValue(t.value)},e.prototype.componentWillUpdate=function(t,e){t.mask!==this.props.mask&&this._updatePattern(t)},e.prototype.componentDidUpdate=function(t){t.mask!==this.props.mask&&this.mask.selection.start&&this._updateInputSelection()},e.prototype._updatePattern=function(t){this.mask.setPattern(t.mask,{value:this.mask.getRawValue(),selection:d(this.input)})},e.prototype._updateMaskSelection=function(){this.mask.selection=d(this.input)},e.prototype._updateInputSelection=function(){!function(t,e){try{if(void 0!==t.selectionStart)t.focus(),t.setSelectionRange(e.start,e.end);else{t.focus();var s=t.createTextRange();s.collapse(!0),s.moveStart("character",e.start),s.moveEnd("character",e.end-e.start),s.select()}}catch(t){}}(this.input,this.mask.selection)},e.prototype._getDisplayValue=function(){var t=this.mask.getValue();return t===this.mask.emptyValue?"":t},e.prototype._keyPressPropName=function(){return"undefined"!=typeof navigator&&navigator.userAgent.match(/Android/i)?"onBeforeInput":"onKeyPress"},e.prototype._getEventHandlers=function(){var t;return(t={onChange:this._onChange,onKeyDown:this._onKeyDown,onPaste:this._onPaste})[this._keyPressPropName()]=this._onKeyPress,t},e.prototype.focus=function(){this.input.focus()},e.prototype.blur=function(){this.input.blur()},e.prototype.render=function(){var t=this,e=this.mask.pattern.length,s=this._getDisplayValue(),n=this._getEventHandlers(),i=this.props,r=i.size,o=void 0===r?e:r,l=i.placeholder,p=void 0===l?this.mask.emptyValue:l,u=this.props,c=(u.placeholderChar,u.formatCharacters,function(t,e){var s={};for(var n in t)e.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(t,n)&&(s[n]=t[n]);return s}(u,["placeholderChar","formatCharacters"])),d=h({},c,n,{ref:function(e){t.input=e},maxLength:e,value:s,size:o,placeholder:p});return a.a.createElement("input",d)},e}(a.a.Component),n.defaultProps={value:""},i);e.default=f},function(e,s){e.exports=t},function(t,e,s){"use strict";function n(t,e){if(e)for(var s=Object.keys(e),n=0,i=s.length;n<i;n++)t[s[n]]=e[s[n]];return t}function i(t){return n({},t)}var r=/^\d$/,a=/^[A-Za-z]$/,o=/^[\dA-Za-z]$/,l="_",h={"*":{validate:function(t){return o.test(t)}},1:{validate:function(t){return r.test(t)}},a:{validate:function(t){return a.test(t)}},A:{validate:function(t){return a.test(t)},transform:function(t){return t.toUpperCase()}},"#":{validate:function(t){return o.test(t)},transform:function(t){return t.toUpperCase()}}};function p(t,e,s,n){if(!(this instanceof p))return new p(t,e,s);this.placeholderChar=s||l,this.formatCharacters=e||h,this.source=t,this.pattern=[],this.length=0,this.firstEditableIndex=null,this.lastEditableIndex=null,this._editableIndices={},this.isRevealingMask=n||!1,this._parse()}function u(t){if(!(this instanceof u))return new u(t);if(null==(t=n({formatCharacters:null,pattern:null,isRevealingMask:!1,placeholderChar:l,selection:{start:0,end:0},value:""},t)).pattern)throw new Error("InputMask: you must provide a pattern.");if("string"!=typeof t.placeholderChar||t.placeholderChar.length>1)throw new Error("InputMask: placeholderChar should be a single character or an empty string.");this.placeholderChar=t.placeholderChar,this.formatCharacters=function(t){var e=i(h);if(t)for(var s=Object.keys(t),n=0,r=s.length;n<r;n++){var a=s[n];null==t[a]?delete e[a]:e[a]=t[a]}return e}(t.formatCharacters),this.setPattern(t.pattern,{value:t.value,selection:t.selection,isRevealingMask:t.isRevealingMask})}p.prototype._parse=function(){for(var t=this.source.split(""),e=0,s=[],n=0,i=t.length;n<i;n++){var r=t[n];if("\\"===r){if(n===i-1)throw new Error("InputMask: pattern ends with a raw \\");r=t[++n]}else r in this.formatCharacters&&(null===this.firstEditableIndex&&(this.firstEditableIndex=e),this.lastEditableIndex=e,this._editableIndices[e]=!0);s.push(r),e++}if(null===this.firstEditableIndex)throw new Error('InputMask: pattern "'+this.source+'" does not contain any editable characters.');this.pattern=s,this.length=s.length},p.prototype.formatValue=function(t){for(var e=new Array(this.length),s=0,n=0,i=this.length;n<i;n++)if(this.isEditableIndex(n)){if(this.isRevealingMask&&t.length<=s&&!this.isValidAtIndex(t[s],n))break;e[n]=t.length>s&&this.isValidAtIndex(t[s],n)?this.transform(t[s],n):this.placeholderChar,s++}else e[n]=this.pattern[n],t.length>s&&t[s]===this.pattern[n]&&s++;return e},p.prototype.isEditableIndex=function(t){return!!this._editableIndices[t]},p.prototype.isValidAtIndex=function(t,e){return this.formatCharacters[this.pattern[e]].validate(t)},p.prototype.transform=function(t,e){var s=this.formatCharacters[this.pattern[e]];return"function"==typeof s.transform?s.transform(t):t},u.prototype.input=function(t){if(this.selection.start===this.selection.end&&this.selection.start===this.pattern.length)return!1;var e=i(this.selection),s=this.getValue(),n=this.selection.start;if(n<this.pattern.firstEditableIndex&&(n=this.pattern.firstEditableIndex),this.pattern.isEditableIndex(n)){if(!this.pattern.isValidAtIndex(t,n))return!1;this.value[n]=this.pattern.transform(t,n)}for(var r=this.selection.end-1;r>n;)this.pattern.isEditableIndex(r)&&(this.value[r]=this.placeholderChar),r--;for(this.selection.start=this.selection.end=n+1;this.pattern.length>this.selection.start&&!this.pattern.isEditableIndex(this.selection.start);)this.selection.start++,this.selection.end++;return null!=this._historyIndex&&(this._history.splice(this._historyIndex,this._history.length-this._historyIndex),this._historyIndex=null),("input"!==this._lastOp||e.start!==e.end||null!==this._lastSelection&&e.start!==this._lastSelection.start)&&this._history.push({value:s,selection:e,lastOp:this._lastOp}),this._lastOp="input",this._lastSelection=i(this.selection),!0},u.prototype.backspace=function(){if(0===this.selection.start&&0===this.selection.end)return!1;var t=i(this.selection),e=this.getValue();if(this.selection.start===this.selection.end)this.pattern.isEditableIndex(this.selection.start-1)&&(this.value[this.selection.start-1]=this.placeholderChar),this.selection.start--,this.selection.end--;else{for(var s=this.selection.end-1;s>=this.selection.start;)this.pattern.isEditableIndex(s)&&(this.value[s]=this.placeholderChar),s--;this.selection.end=this.selection.start}return null!=this._historyIndex&&this._history.splice(this._historyIndex,this._history.length-this._historyIndex),("backspace"!==this._lastOp||t.start!==t.end||null!==this._lastSelection&&t.start!==this._lastSelection.start)&&this._history.push({value:e,selection:t,lastOp:this._lastOp}),this._lastOp="backspace",this._lastSelection=i(this.selection),!0},u.prototype.paste=function(t){var e={value:this.value.slice(),selection:i(this.selection),_lastOp:this._lastOp,_history:this._history.slice(),_historyIndex:this._historyIndex,_lastSelection:i(this._lastSelection)};if(this.selection.start<this.pattern.firstEditableIndex){for(var s=0,r=this.pattern.firstEditableIndex-this.selection.start;s<r;s++)if(t.charAt(s)!==this.pattern.pattern[s])return!1;t=t.substring(this.pattern.firstEditableIndex-this.selection.start),this.selection.start=this.pattern.firstEditableIndex}for(s=0,r=t.length;s<r&&this.selection.start<=this.pattern.lastEditableIndex;s++){if(!this.input(t.charAt(s))){if(this.selection.start>0){var a=this.selection.start-1;if(!this.pattern.isEditableIndex(a)&&t.charAt(s)===this.pattern.pattern[a])continue}return n(this,e),!1}}return!0},u.prototype.undo=function(){if(0===this._history.length||0===this._historyIndex)return!1;var t;if(null==this._historyIndex){this._historyIndex=this._history.length-1,t=this._history[this._historyIndex];var e=this.getValue();t.value===e&&t.selection.start===this.selection.start&&t.selection.end===this.selection.end||this._history.push({value:e,selection:i(this.selection),lastOp:this._lastOp,startUndo:!0})}else t=this._history[--this._historyIndex];return this.value=t.value.split(""),this.selection=t.selection,this._lastOp=t.lastOp,!0},u.prototype.redo=function(){if(0===this._history.length||null==this._historyIndex)return!1;var t=this._history[++this._historyIndex];return this._historyIndex===this._history.length-1&&(this._historyIndex=null,t.startUndo&&this._history.pop()),this.value=t.value.split(""),this.selection=t.selection,this._lastOp=t.lastOp,!0},u.prototype.setPattern=function(t,e){e=n({selection:{start:0,end:0},value:""},e),this.pattern=new p(t,this.formatCharacters,this.placeholderChar,e.isRevealingMask),this.setValue(e.value),this.emptyValue=this.pattern.formatValue([]).join(""),this.selection=e.selection,this._resetHistory()},u.prototype.setSelection=function(t){if(this.selection=i(t),this.selection.start===this.selection.end){if(this.selection.start<this.pattern.firstEditableIndex)return this.selection.start=this.selection.end=this.pattern.firstEditableIndex,!0;for(var e=this.selection.start;e>=this.pattern.firstEditableIndex;){if(this.pattern.isEditableIndex(e-1)&&this.value[e-1]!==this.placeholderChar||e===this.pattern.firstEditableIndex){this.selection.start=this.selection.end=e;break}e--}return!0}return!1},u.prototype.setValue=function(t){null==t&&(t=""),this.value=this.pattern.formatValue(t.split(""))},u.prototype.getValue=function(){return this.value.join("")},u.prototype.getRawValue=function(){for(var t=[],e=0;e<this.value.length;e++)!0===this.pattern._editableIndices[e]&&t.push(this.value[e]);return t.join("")},u.prototype._resetHistory=function(){this._history=[],this._historyIndex=null,this._lastOp=null,this._lastSelection=i(this.selection)},u.Pattern=p,t.exports=u}]).default}); | ||
//# sourceMappingURL=react-maskedinput.min.js.map |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
147690
2081
129