-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from notgiorgi/master
added build config
- Loading branch information
Showing
19 changed files
with
917 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var _maskService=require('./lib/mask-service');var _maskService2=_interopRequireDefault(_maskService); | ||
var _textInputMask=require('./lib/text-input-mask');var _textInputMask2=_interopRequireDefault(_textInputMask); | ||
var _textMask=require('./lib/text-mask');var _textMask2=_interopRequireDefault(_textMask);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};} | ||
|
||
module.exports.MaskService=_maskService2.default; | ||
module.exports.TextInputMask=_textInputMask2.default; | ||
module.exports.TextMask=_textMask2.default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _react=require('react');var _react2=_interopRequireDefault(_react); | ||
var _maskResolver=require('./mask-resolver');var _maskResolver2=_interopRequireDefault(_maskResolver);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call&&(typeof call==="object"||typeof call==="function")?call:self;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass;}var | ||
|
||
BaseTextComponent=function(_Component){_inherits(BaseTextComponent,_Component); | ||
function BaseTextComponent(props){_classCallCheck(this,BaseTextComponent);var _this=_possibleConstructorReturn(this,(BaseTextComponent.__proto__||Object.getPrototypeOf(BaseTextComponent)).call(this, | ||
props)); | ||
_this.state={ | ||
type:props.type, | ||
value:'', | ||
options:null}; | ||
|
||
|
||
_this._resolveMaskHandler();return _this; | ||
}_createClass(BaseTextComponent,[{key:'componentDidMount',value:function componentDidMount() | ||
|
||
{ | ||
this._bindProps(this.props); | ||
}},{key:'componentWillReceiveProps',value:function componentWillReceiveProps( | ||
|
||
nextProps){ | ||
this._bindProps(nextProps); | ||
}},{key:'updateValue',value:function updateValue( | ||
|
||
text){var _this2=this; | ||
var self=this; | ||
|
||
return new Promise(function(resolve,reject){ | ||
var maskedText=self._getMaskedValue(text); | ||
|
||
if(self._mustUpdateValue(maskedText)){ | ||
self.setState({ | ||
value:maskedText}, | ||
function(){ | ||
resolve(maskedText); | ||
}); | ||
}else | ||
{ | ||
resolve(_this2.state.value); | ||
} | ||
}); | ||
}},{key:'isValid',value:function isValid() | ||
|
||
{ | ||
return this._maskHandler.validate( | ||
this._getDefaultValue(this.state.value), | ||
this.state.options); | ||
|
||
}},{key:'getRawValue',value:function getRawValue() | ||
|
||
{ | ||
return this._maskHandler.getRawValue( | ||
this._getDefaultValue(this.state.value), | ||
this.state.options); | ||
|
||
}},{key:'_mustUpdateValue',value:function _mustUpdateValue( | ||
|
||
newValue){ | ||
return this.state.value!==newValue; | ||
}},{key:'_resolveMaskHandler',value:function _resolveMaskHandler() | ||
|
||
{ | ||
this._maskHandler=_maskResolver2.default.resolve(this.state.type); | ||
}},{key:'_bindProps',value:function _bindProps( | ||
|
||
props){ | ||
var self=this; | ||
var changeMaskHandler=this.state.type!==props.type; | ||
|
||
self.setState({ | ||
type:props.type, | ||
options:props.options}, | ||
function(){ | ||
if(changeMaskHandler){ | ||
self._resolveMaskHandler(); | ||
} | ||
|
||
var value=self._getDefaultMaskedValue(props.value); | ||
|
||
self.setState({ | ||
value:value}); | ||
|
||
}); | ||
}},{key:'_getDefaultMaskedValue',value:function _getDefaultMaskedValue( | ||
|
||
value){ | ||
if(this._getDefaultValue(value)===''){ | ||
return''; | ||
} | ||
|
||
return this._getMaskedValue(value); | ||
}},{key:'_getMaskedValue',value:function _getMaskedValue( | ||
|
||
value){ | ||
var oldValue=this.state.value; | ||
|
||
return this._maskHandler.getValue( | ||
this._getDefaultValue(value), | ||
this.state.options, | ||
oldValue); | ||
}},{key:'_getDefaultValue',value:function _getDefaultValue( | ||
|
||
value){ | ||
if(value===undefined||value===null){ | ||
return''; | ||
} | ||
|
||
return value; | ||
}}]);return BaseTextComponent;}(_react.Component);exports.default=BaseTextComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
(function(root,factory){ | ||
if(typeof define==='function'&&define.amd){ | ||
define(factory); | ||
}else if(typeof exports==='object'){ | ||
module.exports=factory(); | ||
}else{ | ||
root.VMasker=factory(); | ||
} | ||
})(this,function(){ | ||
var DIGIT="9", | ||
ALPHA="A", | ||
ALPHANUM="S", | ||
BY_PASS_KEYS=[9,16,17,18,36,37,38,39,40,91,92,93], | ||
isAllowedKeyCode=function isAllowedKeyCode(keyCode){ | ||
for(var i=0,len=BY_PASS_KEYS.length;i<len;i++){ | ||
if(keyCode==BY_PASS_KEYS[i]){ | ||
return false; | ||
} | ||
} | ||
return true; | ||
}, | ||
mergeMoneyOptions=function mergeMoneyOptions(opts){ | ||
opts=opts||{}; | ||
opts={ | ||
precision:opts.hasOwnProperty("precision")?opts.precision:2, | ||
separator:opts.separator||",", | ||
delimiter:opts.delimiter||".", | ||
unit:opts.unit?opts.unit+' ':"", | ||
|
||
suffixUnit:opts.suffixUnit&&" "+opts.suffixUnit.replace(/[\s]/g,'')||"", | ||
zeroCents:opts.zeroCents, | ||
lastOutput:opts.lastOutput}; | ||
|
||
opts.moneyPrecision=opts.zeroCents?0:opts.precision; | ||
return opts; | ||
}, | ||
|
||
addPlaceholdersToOutput=function addPlaceholdersToOutput(output,index,placeholder){ | ||
for(;index<output.length;index++){ | ||
if(output[index]===DIGIT||output[index]===ALPHA||output[index]===ALPHANUM){ | ||
output[index]=placeholder; | ||
} | ||
} | ||
return output; | ||
}; | ||
|
||
|
||
var VanillaMasker=function VanillaMasker(elements){ | ||
this.elements=elements; | ||
}; | ||
|
||
VanillaMasker.prototype.unbindElementToMask=function(){ | ||
for(var i=0,len=this.elements.length;i<len;i++){ | ||
this.elements[i].lastOutput=""; | ||
this.elements[i].onkeyup=false; | ||
this.elements[i].onkeydown=false; | ||
|
||
if(this.elements[i].value.length){ | ||
this.elements[i].value=this.elements[i].value.replace(/\D/g,''); | ||
} | ||
} | ||
}; | ||
|
||
VanillaMasker.prototype.bindElementToMask=function(maskFunction){ | ||
var that=this, | ||
onType=function onType(e){ | ||
e=e||window.event; | ||
var source=e.target||e.srcElement; | ||
|
||
if(isAllowedKeyCode(e.keyCode)){ | ||
setTimeout(function(){ | ||
that.opts.lastOutput=source.lastOutput; | ||
source.value=VMasker[maskFunction](source.value,that.opts); | ||
source.lastOutput=source.value; | ||
if(source.setSelectionRange&&that.opts.suffixUnit){ | ||
source.setSelectionRange(source.value.length,source.value.length-that.opts.suffixUnit.length); | ||
} | ||
},0); | ||
} | ||
}; | ||
|
||
for(var i=0,len=this.elements.length;i<len;i++){ | ||
this.elements[i].lastOutput=""; | ||
this.elements[i].onkeyup=onType; | ||
if(this.elements[i].value.length){ | ||
this.elements[i].value=VMasker[maskFunction](this.elements[i].value,this.opts); | ||
} | ||
} | ||
}; | ||
|
||
VanillaMasker.prototype.maskMoney=function(opts){ | ||
this.opts=mergeMoneyOptions(opts); | ||
this.bindElementToMask("toMoney"); | ||
}; | ||
|
||
VanillaMasker.prototype.maskNumber=function(){ | ||
this.opts={}; | ||
this.bindElementToMask("toNumber"); | ||
}; | ||
|
||
VanillaMasker.prototype.maskAlphaNum=function(){ | ||
this.opts={}; | ||
this.bindElementToMask("toAlphaNumeric"); | ||
}; | ||
|
||
VanillaMasker.prototype.maskPattern=function(pattern){ | ||
this.opts={pattern:pattern}; | ||
this.bindElementToMask("toPattern"); | ||
}; | ||
|
||
VanillaMasker.prototype.unMask=function(){ | ||
this.unbindElementToMask(); | ||
}; | ||
|
||
var VMasker=function VMasker(el){ | ||
if(!el){ | ||
throw new Error("VanillaMasker: There is no element to bind."); | ||
} | ||
var elements="length"in el?el.length?el:[]:[el]; | ||
return new VanillaMasker(elements); | ||
}; | ||
|
||
VMasker.toMoney=function(value,opts){ | ||
opts=mergeMoneyOptions(opts); | ||
if(opts.zeroCents){ | ||
opts.lastOutput=opts.lastOutput||""; | ||
var zeroMatcher="("+opts.separator+"[0]{0,"+opts.precision+"})", | ||
zeroRegExp=new RegExp(zeroMatcher,"g"), | ||
digitsLength=value.toString().replace(/[\D]/g,"").length||0, | ||
lastDigitLength=opts.lastOutput.toString().replace(/[\D]/g,"").length||0; | ||
|
||
value=value.toString().replace(zeroRegExp,""); | ||
if(digitsLength<lastDigitLength){ | ||
value=value.slice(0,value.length-1); | ||
} | ||
} | ||
var number=value.toString().replace(/[\D]/g,""), | ||
clearDelimiter=new RegExp("^(0|\\"+opts.delimiter+")"), | ||
clearSeparator=new RegExp("(\\"+opts.separator+")$"), | ||
money=number.substr(0,number.length-opts.moneyPrecision), | ||
masked=money.substr(0,money.length%3), | ||
cents=new Array(opts.precision+1).join("0"); | ||
|
||
money=money.substr(money.length%3,money.length); | ||
for(var i=0,len=money.length;i<len;i++){ | ||
if(i%3===0){ | ||
masked+=opts.delimiter; | ||
} | ||
masked+=money[i]; | ||
} | ||
masked=masked.replace(clearDelimiter,""); | ||
masked=masked.length?masked:"0"; | ||
if(!opts.zeroCents){ | ||
var beginCents=number.length-opts.precision, | ||
centsValue=number.substr(beginCents,opts.precision), | ||
centsLength=centsValue.length, | ||
centsSliced=opts.precision>centsLength?opts.precision:centsLength; | ||
|
||
cents=(cents+centsValue).slice(-centsSliced); | ||
} | ||
|
||
var unitToApply=opts.unit[opts.unit.length-1]===' '? | ||
opts.unit.substring(0,opts.unit.length-1): | ||
|
||
opts.unit; | ||
var output=unitToApply+masked+opts.separator+cents+opts.suffixUnit; | ||
return output.replace(clearSeparator,""); | ||
}; | ||
|
||
VMasker.toPattern=function(value,opts){ | ||
var pattern=typeof opts==='object'?opts.pattern:opts, | ||
patternChars=pattern.replace(/\W/g,''), | ||
output=pattern.split(""), | ||
values=value.toString().replace(/\W/g,""), | ||
charsValues=values.replace(/\W/g,''), | ||
index=0, | ||
i, | ||
outputLength=output.length, | ||
placeholder=typeof opts==='object'?opts.placeholder:undefined; | ||
|
||
|
||
for(i=0;i<outputLength;i++){ | ||
|
||
if(index>=values.length){ | ||
if(patternChars.length==charsValues.length){ | ||
return output.join(""); | ||
}else | ||
if(placeholder!==undefined&&patternChars.length>charsValues.length){ | ||
return addPlaceholdersToOutput(output,i,placeholder).join(""); | ||
}else | ||
{ | ||
break; | ||
} | ||
}else | ||
|
||
{ | ||
if(output[i]===DIGIT&&values[index].match(/[0-9]/)|| | ||
output[i]===ALPHA&&values[index].match(/[a-zA-Z]/)|| | ||
output[i]===ALPHANUM&&values[index].match(/[0-9a-zA-Z]/)){ | ||
output[i]=values[index++]; | ||
}else if(output[i]===DIGIT||output[i]===ALPHA||output[i]===ALPHANUM){ | ||
if(placeholder!==undefined){ | ||
return addPlaceholdersToOutput(output,i,placeholder).join(""); | ||
}else | ||
{ | ||
return output.slice(0,i).join(""); | ||
} | ||
} | ||
} | ||
} | ||
return output.join("").substr(0,i); | ||
}; | ||
|
||
VMasker.toNumber=function(value){ | ||
return value.toString().replace(/(?!^-)[^0-9]/g,""); | ||
}; | ||
|
||
VMasker.toAlphaNumeric=function(value){ | ||
return value.toString().replace(/[^a-z0-9 ]+/i,""); | ||
}; | ||
|
||
return VMasker; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _masks=require('./masks');var Masks=_interopRequireWildcard(_masks);function _interopRequireWildcard(obj){if(obj&&obj.__esModule){return obj;}else{var newObj={};if(obj!=null){for(var key in obj){if(Object.prototype.hasOwnProperty.call(obj,key))newObj[key]=obj[key];}}newObj.default=obj;return newObj;}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}} | ||
|
||
var maskKeys=Object.keys(Masks);var | ||
|
||
MaskResolver=function(){function MaskResolver(){_classCallCheck(this,MaskResolver);}_createClass(MaskResolver,null,[{key:'resolve',value:function resolve( | ||
type){ | ||
var maskKey=maskKeys.filter(function(m){ | ||
var handler=Masks[m]; | ||
return handler&&handler.getType&&handler.getType()===type; | ||
})[0]; | ||
|
||
var handler=Masks[maskKey]; | ||
|
||
if(!handler){ | ||
throw new Error('Mask type not supported.'); | ||
} | ||
|
||
return new handler(); | ||
}}]);return MaskResolver;}();exports.default=MaskResolver; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.