diff --git a/bower.json b/bower.json index fcb3ee75..67088215 100644 --- a/bower.json +++ b/bower.json @@ -8,7 +8,7 @@ "form", "input" ], - "version": "1.0.8", + "version": "1.0.9", "author": { "name": "Max Huang", "email": "risonhuang@gmail.com", diff --git a/dist/cleave-angular.min.js b/dist/cleave-angular.min.js index 0c1ade2d..407f4ca7 100644 --- a/dist/cleave-angular.min.js +++ b/dist/cleave-angular.min.js @@ -1,5 +1,5 @@ /*! - * cleave.js - 1.0.7 + * cleave.js - 1.0.9 * https://github.com/nosir/cleave.js * Apache License Version 2.0 * diff --git a/dist/cleave-react-node.js b/dist/cleave-react-node.js new file mode 100644 index 00000000..85b3f8f4 --- /dev/null +++ b/dist/cleave-react-node.js @@ -0,0 +1,2357 @@ +(function webpackUniversalModuleDefinition(root, factory) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports = factory(require("react")); + else if(typeof define === 'function' && define.amd) + define(["react"], factory); + else if(typeof exports === 'object') + exports["Cleave"] = factory(require("react")); + else + root["Cleave"] = factory(root["React"]); +})(this, function(__WEBPACK_EXTERNAL_MODULE_1__) { +return /******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; + +/******/ // The require function +/******/ function __webpack_require__(moduleId) { + +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; + +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; + +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); + +/******/ // Flag the module as loaded +/******/ module.loaded = true; + +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } + + +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; + +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; + +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; + +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ (function(module, exports, __webpack_require__) { + + 'use strict'; + + 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; }; + + 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; } + + var React = __webpack_require__(1); // eslint-disable-line no-unused-vars + var CreateReactClass = __webpack_require__(2); + + var NumeralFormatter = __webpack_require__(9); + var DateFormatter = __webpack_require__(10); + var PhoneFormatter = __webpack_require__(11); + var CreditCardDetector = __webpack_require__(12); + var Util = __webpack_require__(13); + var DefaultProperties = __webpack_require__(14); + + var Cleave = CreateReactClass({ + componentDidMount: function componentDidMount() { + this.init(); + }, + + componentDidUpdate: function componentDidUpdate() { + var owner = this; + + if (!owner.state.updateCursorPosition) { + return; + } + + owner.setCurrentSelection(owner.state.cursorPosition); + }, + + componentWillReceiveProps: function componentWillReceiveProps(nextProps) { + var owner = this, + phoneRegionCode = (nextProps.options || {}).phoneRegionCode, + newValue = nextProps.value; + + if (newValue !== undefined) { + newValue = newValue.toString(); + + if (newValue !== owner.state.value && newValue !== owner.properties.result) { + owner.properties.initValue = newValue; + owner.onInput(newValue, true); + } + } + + // update phone region code + if (phoneRegionCode && phoneRegionCode !== owner.properties.phoneRegionCode) { + owner.properties.phoneRegionCode = phoneRegionCode; + owner.initPhoneFormatter(); + owner.onInput(owner.properties.result); + } + }, + + getInitialState: function getInitialState() { + var owner = this, + _owner$props = owner.props, + value = _owner$props.value, + options = _owner$props.options, + onKeyDown = _owner$props.onKeyDown, + onChange = _owner$props.onChange, + onFocus = _owner$props.onFocus, + onBlur = _owner$props.onBlur, + onInit = _owner$props.onInit; + + + owner.registeredEvents = { + onInit: onInit || Util.noop, + onChange: onChange || Util.noop, + onFocus: onFocus || Util.noop, + onBlur: onBlur || Util.noop, + onKeyDown: onKeyDown || Util.noop + }; + + if (!options) { + options = {}; + } + options.initValue = value; + + owner.properties = DefaultProperties.assign({}, options); + + return { + value: owner.properties.result, + cursorPosition: 0, + updateCursorPosition: false + }; + }, + + init: function init() { + var owner = this, + pps = owner.properties; + + // so no need for this lib at all + if (!pps.numeral && !pps.phone && !pps.creditCard && !pps.date && pps.blocksLength === 0 && !pps.prefix) { + owner.onInput(pps.initValue); + owner.registeredEvents.onInit(owner); + + return; + } + + pps.maxLength = Util.getMaxLength(pps.blocks); + + owner.isAndroid = Util.isAndroid(); + + owner.initPhoneFormatter(); + owner.initDateFormatter(); + owner.initNumeralFormatter(); + + owner.onInput(pps.initValue); + + owner.registeredEvents.onInit(owner); + }, + + initNumeralFormatter: function initNumeralFormatter() { + var owner = this, + pps = owner.properties; + + if (!pps.numeral) { + return; + } + + pps.numeralFormatter = new NumeralFormatter(pps.numeralDecimalMark, pps.numeralIntegerScale, pps.numeralDecimalScale, pps.numeralThousandsGroupStyle, pps.numeralPositiveOnly, pps.stripLeadingZeroes, pps.delimiter); + }, + + initDateFormatter: function initDateFormatter() { + var owner = this, + pps = owner.properties; + + if (!pps.date) { + return; + } + + pps.dateFormatter = new DateFormatter(pps.datePattern); + pps.blocks = pps.dateFormatter.getBlocks(); + pps.blocksLength = pps.blocks.length; + pps.maxLength = Util.getMaxLength(pps.blocks); + }, + + initPhoneFormatter: function initPhoneFormatter() { + var owner = this, + pps = owner.properties; + + if (!pps.phone) { + return; + } + + // Cleave.AsYouTypeFormatter should be provided by + // external google closure lib + try { + pps.phoneFormatter = new PhoneFormatter(new pps.root.Cleave.AsYouTypeFormatter(pps.phoneRegionCode), pps.delimiter); + } catch (ex) { + throw new Error('Please include phone-type-formatter.{country}.js lib'); + } + }, + + setRawValue: function setRawValue(value) { + var owner = this, + pps = owner.properties; + + value = value !== undefined && value !== null ? value.toString() : ''; + + if (pps.numeral) { + value = value.replace('.', pps.numeralDecimalMark); + } + + pps.backspace = false; + + owner.onChange({ target: { value: value } }); + }, + + getRawValue: function getRawValue() { + var owner = this, + pps = owner.properties, + rawValue = pps.result; + + if (pps.rawValueTrimPrefix) { + rawValue = Util.getPrefixStrippedValue(rawValue, pps.prefix, pps.prefixLength); + } + + if (pps.numeral) { + rawValue = pps.numeralFormatter.getRawValue(rawValue); + } else { + rawValue = Util.stripDelimiters(rawValue, pps.delimiter, pps.delimiters); + } + + return rawValue; + }, + + getISOFormatDate: function getISOFormatDate() { + var owner = this, + pps = owner.properties; + + return pps.date ? pps.dateFormatter.getISOFormatDate() : ''; + }, + + onInit: function onInit(owner) { + return owner; + }, + + onKeyDown: function onKeyDown(event) { + var owner = this, + pps = owner.properties, + charCode = event.which || event.keyCode; + + // hit backspace when last character is delimiter + if (charCode === 8 && Util.isDelimiter(pps.result.slice(-pps.delimiterLength), pps.delimiter, pps.delimiters)) { + pps.backspace = true; + } else { + pps.backspace = false; + } + + owner.registeredEvents.onKeyDown(event); + }, + + onFocus: function onFocus(event) { + var owner = this, + pps = owner.properties; + + event.target.rawValue = owner.getRawValue(); + event.target.value = pps.result; + + owner.registeredEvents.onFocus(event); + }, + + onBlur: function onBlur(event) { + var owner = this, + pps = owner.properties; + + event.target.rawValue = owner.getRawValue(); + event.target.value = pps.result; + + owner.registeredEvents.onBlur(event); + }, + + onChange: function onChange(event) { + var owner = this, + pps = owner.properties; + + owner.onInput(event.target.value); + + event.target.rawValue = owner.getRawValue(); + event.target.value = pps.result; + + owner.registeredEvents.onChange(event); + }, + + onInput: function onInput(value, fromProps) { + var owner = this, + pps = owner.properties; + + if (Util.isAndroidBackspaceKeydown(owner.lastInputValue, owner.element.value) && Util.isDelimiter(pps.result.slice(-pps.delimiterLength), pps.delimiter, pps.delimiters)) { + pps.backspace = true; + } + + // case 1: delete one more character "4" + // 1234*| -> hit backspace -> 123| + // case 2: last character is not delimiter which is: + // 12|34* -> hit backspace -> 1|34* + + if (!fromProps && !pps.numeral && pps.backspace && !Util.isDelimiter(value.slice(-pps.delimiterLength), pps.delimiter, pps.delimiters)) { + value = Util.headStr(value, value.length - pps.delimiterLength); + } + + // phone formatter + if (pps.phone) { + pps.result = pps.phoneFormatter.format(value); + owner.updateValueState(); + + return; + } + + // numeral formatter + if (pps.numeral) { + if (pps.prefix && (!pps.noImmediatePrefix || value.length)) { + pps.result = pps.prefix + pps.numeralFormatter.format(value); + } else { + pps.result = pps.numeralFormatter.format(value); + } + owner.updateValueState(); + + return; + } + + // date + if (pps.date) { + value = pps.dateFormatter.getValidatedDate(value); + } + + // strip delimiters + value = Util.stripDelimiters(value, pps.delimiter, pps.delimiters); + + // strip prefix + value = Util.getPrefixStrippedValue(value, pps.prefix, pps.prefixLength); + + // strip non-numeric characters + value = pps.numericOnly ? Util.strip(value, /[^\d]/g) : value; + + // convert case + value = pps.uppercase ? value.toUpperCase() : value; + value = pps.lowercase ? value.toLowerCase() : value; + + // prefix + if (pps.prefix && (!pps.noImmediatePrefix || value.length)) { + value = pps.prefix + value; + + // no blocks specified, no need to do formatting + if (pps.blocksLength === 0) { + pps.result = value; + owner.updateValueState(); + + return; + } + } + + // update credit card props + if (pps.creditCard) { + owner.updateCreditCardPropsByValue(value); + } + + // strip over length characters + value = pps.maxLength > 0 ? Util.headStr(value, pps.maxLength) : value; + + // apply blocks + pps.result = Util.getFormattedValue(value, pps.blocks, pps.blocksLength, pps.delimiter, pps.delimiters); + + owner.updateValueState(); + }, + + updateCreditCardPropsByValue: function updateCreditCardPropsByValue(value) { + var owner = this, + pps = owner.properties, + creditCardInfo; + + // At least one of the first 4 characters has changed + if (Util.headStr(pps.result, 4) === Util.headStr(value, 4)) { + return; + } + + creditCardInfo = CreditCardDetector.getInfo(value, pps.creditCardStrictMode); + + pps.blocks = creditCardInfo.blocks; + pps.blocksLength = pps.blocks.length; + pps.maxLength = Util.getMaxLength(pps.blocks); + + // credit card type changed + if (pps.creditCardType !== creditCardInfo.type) { + pps.creditCardType = creditCardInfo.type; + + pps.onCreditCardTypeChanged.call(owner, pps.creditCardType); + } + }, + + getNextCursorPosition: function getNextCursorPosition(endPos, oldValue, newValue) { + // If cursor was at the end of value, just place it back. + // Because new value could contain additional chars. + if (oldValue.length === endPos) { + return newValue.length; + } + + return endPos; + }, + + setCurrentSelection: function setCurrentSelection(cursorPosition) { + var elem = this.element; + + this.setState({ + updateCursorPosition: false + }); + + if (elem === document.activeElement) { + if (elem.createTextRange) { + var range = elem.createTextRange(); + range.move('character', cursorPosition); + range.select(); + } else { + elem.setSelectionRange(cursorPosition, cursorPosition); + } + } + }, + + updateValueState: function updateValueState() { + var owner = this; + var endPos = owner.element.selectionEnd; + var oldValue = owner.element.value; + var newValue = owner.properties.result; + var nextCursorPosition = owner.getNextCursorPosition(endPos, oldValue, newValue); + + owner.lastInputValue = owner.properties.result; + + if (owner.isAndroid) { + window.setTimeout(function () { + owner.setState({ + value: owner.properties.result, + cursorPosition: nextCursorPosition, + updateCursorPosition: true + }); + }, 1); + + return; + } + + owner.setState({ + value: owner.properties.result, + cursorPosition: nextCursorPosition, + updateCursorPosition: true + }); + }, + + render: function render() { + var owner = this; + // eslint-disable-next-line + + var _owner$props2 = owner.props, + value = _owner$props2.value, + options = _owner$props2.options, + onKeyDown = _owner$props2.onKeyDown, + onFocus = _owner$props2.onFocus, + onBlur = _owner$props2.onBlur, + onChange = _owner$props2.onChange, + onInit = _owner$props2.onInit, + htmlRef = _owner$props2.htmlRef, + propsToTransfer = _objectWithoutProperties(_owner$props2, ['value', 'options', 'onKeyDown', 'onFocus', 'onBlur', 'onChange', 'onInit', 'htmlRef']); + + return React.createElement('input', _extends({ + type: 'text', + ref: function ref(_ref) { + owner.element = _ref; + + if (!htmlRef) { + return; + } + + htmlRef.apply(this, arguments); + }, + value: owner.state.value, + onKeyDown: owner.onKeyDown, + onChange: owner.onChange, + onFocus: owner.onFocus, + onBlur: owner.onBlur + }, propsToTransfer)); + } + }); + + module.exports = Cleave; + +/***/ }), +/* 1 */ +/***/ (function(module, exports) { + + module.exports = __WEBPACK_EXTERNAL_MODULE_1__; + +/***/ }), +/* 2 */ +/***/ (function(module, exports, __webpack_require__) { + + /** + * Copyright 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + */ + + 'use strict'; + + var React = __webpack_require__(1); + var factory = __webpack_require__(3); + + if (typeof React === 'undefined') { + throw Error( + 'create-react-class could not find the React object. If you are using script tags, ' + + 'make sure that React is being loaded before create-react-class.' + ); + } + + // Hack to grab NoopUpdateQueue from isomorphic React + var ReactNoopUpdateQueue = new React.Component().updater; + + module.exports = factory( + React.Component, + React.isValidElement, + ReactNoopUpdateQueue + ); + + +/***/ }), +/* 3 */ +/***/ (function(module, exports, __webpack_require__) { + + /** + * Copyright 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + */ + + 'use strict'; + + var _assign = __webpack_require__(4); + + var emptyObject = __webpack_require__(5); + var _invariant = __webpack_require__(6); + + if (process.env.NODE_ENV !== 'production') { + var warning = __webpack_require__(7); + } + + var MIXINS_KEY = 'mixins'; + + // Helper function to allow the creation of anonymous functions which do not + // have .name set to the name of the variable being assigned to. + function identity(fn) { + return fn; + } + + var ReactPropTypeLocationNames; + if (process.env.NODE_ENV !== 'production') { + ReactPropTypeLocationNames = { + prop: 'prop', + context: 'context', + childContext: 'child context' + }; + } else { + ReactPropTypeLocationNames = {}; + } + + function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) { + /** + * Policies that describe methods in `ReactClassInterface`. + */ + + var injectedMixins = []; + + /** + * Composite components are higher-level components that compose other composite + * or host components. + * + * To create a new type of `ReactClass`, pass a specification of + * your new class to `React.createClass`. The only requirement of your class + * specification is that you implement a `render` method. + * + * var MyComponent = React.createClass({ + * render: function() { + * return
Hello World
; + * } + * }); + * + * The class specification supports a specific protocol of methods that have + * special meaning (e.g. `render`). See `ReactClassInterface` for + * more the comprehensive protocol. Any other properties and methods in the + * class specification will be available on the prototype. + * + * @interface ReactClassInterface + * @internal + */ + var ReactClassInterface = { + /** + * An array of Mixin objects to include when defining your component. + * + * @type {array} + * @optional + */ + mixins: 'DEFINE_MANY', + + /** + * An object containing properties and methods that should be defined on + * the component's constructor instead of its prototype (static methods). + * + * @type {object} + * @optional + */ + statics: 'DEFINE_MANY', + + /** + * Definition of prop types for this component. + * + * @type {object} + * @optional + */ + propTypes: 'DEFINE_MANY', + + /** + * Definition of context types for this component. + * + * @type {object} + * @optional + */ + contextTypes: 'DEFINE_MANY', + + /** + * Definition of context types this component sets for its children. + * + * @type {object} + * @optional + */ + childContextTypes: 'DEFINE_MANY', + + // ==== Definition methods ==== + + /** + * Invoked when the component is mounted. Values in the mapping will be set on + * `this.props` if that prop is not specified (i.e. using an `in` check). + * + * This method is invoked before `getInitialState` and therefore cannot rely + * on `this.state` or use `this.setState`. + * + * @return {object} + * @optional + */ + getDefaultProps: 'DEFINE_MANY_MERGED', + + /** + * Invoked once before the component is mounted. The return value will be used + * as the initial value of `this.state`. + * + * getInitialState: function() { + * return { + * isOn: false, + * fooBaz: new BazFoo() + * } + * } + * + * @return {object} + * @optional + */ + getInitialState: 'DEFINE_MANY_MERGED', + + /** + * @return {object} + * @optional + */ + getChildContext: 'DEFINE_MANY_MERGED', + + /** + * Uses props from `this.props` and state from `this.state` to render the + * structure of the component. + * + * No guarantees are made about when or how often this method is invoked, so + * it must not have side effects. + * + * render: function() { + * var name = this.props.name; + * return
Hello, {name}!
; + * } + * + * @return {ReactComponent} + * @required + */ + render: 'DEFINE_ONCE', + + // ==== Delegate methods ==== + + /** + * Invoked when the component is initially created and about to be mounted. + * This may have side effects, but any external subscriptions or data created + * by this method must be cleaned up in `componentWillUnmount`. + * + * @optional + */ + componentWillMount: 'DEFINE_MANY', + + /** + * Invoked when the component has been mounted and has a DOM representation. + * However, there is no guarantee that the DOM node is in the document. + * + * Use this as an opportunity to operate on the DOM when the component has + * been mounted (initialized and rendered) for the first time. + * + * @param {DOMElement} rootNode DOM element representing the component. + * @optional + */ + componentDidMount: 'DEFINE_MANY', + + /** + * Invoked before the component receives new props. + * + * Use this as an opportunity to react to a prop transition by updating the + * state using `this.setState`. Current props are accessed via `this.props`. + * + * componentWillReceiveProps: function(nextProps, nextContext) { + * this.setState({ + * likesIncreasing: nextProps.likeCount > this.props.likeCount + * }); + * } + * + * NOTE: There is no equivalent `componentWillReceiveState`. An incoming prop + * transition may cause a state change, but the opposite is not true. If you + * need it, you are probably looking for `componentWillUpdate`. + * + * @param {object} nextProps + * @optional + */ + componentWillReceiveProps: 'DEFINE_MANY', + + /** + * Invoked while deciding if the component should be updated as a result of + * receiving new props, state and/or context. + * + * Use this as an opportunity to `return false` when you're certain that the + * transition to the new props/state/context will not require a component + * update. + * + * shouldComponentUpdate: function(nextProps, nextState, nextContext) { + * return !equal(nextProps, this.props) || + * !equal(nextState, this.state) || + * !equal(nextContext, this.context); + * } + * + * @param {object} nextProps + * @param {?object} nextState + * @param {?object} nextContext + * @return {boolean} True if the component should update. + * @optional + */ + shouldComponentUpdate: 'DEFINE_ONCE', + + /** + * Invoked when the component is about to update due to a transition from + * `this.props`, `this.state` and `this.context` to `nextProps`, `nextState` + * and `nextContext`. + * + * Use this as an opportunity to perform preparation before an update occurs. + * + * NOTE: You **cannot** use `this.setState()` in this method. + * + * @param {object} nextProps + * @param {?object} nextState + * @param {?object} nextContext + * @param {ReactReconcileTransaction} transaction + * @optional + */ + componentWillUpdate: 'DEFINE_MANY', + + /** + * Invoked when the component's DOM representation has been updated. + * + * Use this as an opportunity to operate on the DOM when the component has + * been updated. + * + * @param {object} prevProps + * @param {?object} prevState + * @param {?object} prevContext + * @param {DOMElement} rootNode DOM element representing the component. + * @optional + */ + componentDidUpdate: 'DEFINE_MANY', + + /** + * Invoked when the component is about to be removed from its parent and have + * its DOM representation destroyed. + * + * Use this as an opportunity to deallocate any external resources. + * + * NOTE: There is no `componentDidUnmount` since your component will have been + * destroyed by that point. + * + * @optional + */ + componentWillUnmount: 'DEFINE_MANY', + + // ==== Advanced methods ==== + + /** + * Updates the component's currently mounted DOM representation. + * + * By default, this implements React's rendering and reconciliation algorithm. + * Sophisticated clients may wish to override this. + * + * @param {ReactReconcileTransaction} transaction + * @internal + * @overridable + */ + updateComponent: 'OVERRIDE_BASE' + }; + + /** + * Mapping from class specification keys to special processing functions. + * + * Although these are declared like instance properties in the specification + * when defining classes using `React.createClass`, they are actually static + * and are accessible on the constructor instead of the prototype. Despite + * being static, they must be defined outside of the "statics" key under + * which all other static methods are defined. + */ + var RESERVED_SPEC_KEYS = { + displayName: function(Constructor, displayName) { + Constructor.displayName = displayName; + }, + mixins: function(Constructor, mixins) { + if (mixins) { + for (var i = 0; i < mixins.length; i++) { + mixSpecIntoComponent(Constructor, mixins[i]); + } + } + }, + childContextTypes: function(Constructor, childContextTypes) { + if (process.env.NODE_ENV !== 'production') { + validateTypeDef(Constructor, childContextTypes, 'childContext'); + } + Constructor.childContextTypes = _assign( + {}, + Constructor.childContextTypes, + childContextTypes + ); + }, + contextTypes: function(Constructor, contextTypes) { + if (process.env.NODE_ENV !== 'production') { + validateTypeDef(Constructor, contextTypes, 'context'); + } + Constructor.contextTypes = _assign( + {}, + Constructor.contextTypes, + contextTypes + ); + }, + /** + * Special case getDefaultProps which should move into statics but requires + * automatic merging. + */ + getDefaultProps: function(Constructor, getDefaultProps) { + if (Constructor.getDefaultProps) { + Constructor.getDefaultProps = createMergedResultFunction( + Constructor.getDefaultProps, + getDefaultProps + ); + } else { + Constructor.getDefaultProps = getDefaultProps; + } + }, + propTypes: function(Constructor, propTypes) { + if (process.env.NODE_ENV !== 'production') { + validateTypeDef(Constructor, propTypes, 'prop'); + } + Constructor.propTypes = _assign({}, Constructor.propTypes, propTypes); + }, + statics: function(Constructor, statics) { + mixStaticSpecIntoComponent(Constructor, statics); + }, + autobind: function() {} + }; + + function validateTypeDef(Constructor, typeDef, location) { + for (var propName in typeDef) { + if (typeDef.hasOwnProperty(propName)) { + // use a warning instead of an _invariant so components + // don't show up in prod but only in __DEV__ + if (process.env.NODE_ENV !== 'production') { + warning( + typeof typeDef[propName] === 'function', + '%s: %s type `%s` is invalid; it must be a function, usually from ' + + 'React.PropTypes.', + Constructor.displayName || 'ReactClass', + ReactPropTypeLocationNames[location], + propName + ); + } + } + } + } + + function validateMethodOverride(isAlreadyDefined, name) { + var specPolicy = ReactClassInterface.hasOwnProperty(name) + ? ReactClassInterface[name] + : null; + + // Disallow overriding of base class methods unless explicitly allowed. + if (ReactClassMixin.hasOwnProperty(name)) { + _invariant( + specPolicy === 'OVERRIDE_BASE', + 'ReactClassInterface: You are attempting to override ' + + '`%s` from your class specification. Ensure that your method names ' + + 'do not overlap with React methods.', + name + ); + } + + // Disallow defining methods more than once unless explicitly allowed. + if (isAlreadyDefined) { + _invariant( + specPolicy === 'DEFINE_MANY' || specPolicy === 'DEFINE_MANY_MERGED', + 'ReactClassInterface: You are attempting to define ' + + '`%s` on your component more than once. This conflict may be due ' + + 'to a mixin.', + name + ); + } + } + + /** + * Mixin helper which handles policy validation and reserved + * specification keys when building React classes. + */ + function mixSpecIntoComponent(Constructor, spec) { + if (!spec) { + if (process.env.NODE_ENV !== 'production') { + var typeofSpec = typeof spec; + var isMixinValid = typeofSpec === 'object' && spec !== null; + + if (process.env.NODE_ENV !== 'production') { + warning( + isMixinValid, + "%s: You're attempting to include a mixin that is either null " + + 'or not an object. Check the mixins included by the component, ' + + 'as well as any mixins they include themselves. ' + + 'Expected object but got %s.', + Constructor.displayName || 'ReactClass', + spec === null ? null : typeofSpec + ); + } + } + + return; + } + + _invariant( + typeof spec !== 'function', + "ReactClass: You're attempting to " + + 'use a component class or function as a mixin. Instead, just use a ' + + 'regular object.' + ); + _invariant( + !isValidElement(spec), + "ReactClass: You're attempting to " + + 'use a component as a mixin. Instead, just use a regular object.' + ); + + var proto = Constructor.prototype; + var autoBindPairs = proto.__reactAutoBindPairs; + + // By handling mixins before any other properties, we ensure the same + // chaining order is applied to methods with DEFINE_MANY policy, whether + // mixins are listed before or after these methods in the spec. + if (spec.hasOwnProperty(MIXINS_KEY)) { + RESERVED_SPEC_KEYS.mixins(Constructor, spec.mixins); + } + + for (var name in spec) { + if (!spec.hasOwnProperty(name)) { + continue; + } + + if (name === MIXINS_KEY) { + // We have already handled mixins in a special case above. + continue; + } + + var property = spec[name]; + var isAlreadyDefined = proto.hasOwnProperty(name); + validateMethodOverride(isAlreadyDefined, name); + + if (RESERVED_SPEC_KEYS.hasOwnProperty(name)) { + RESERVED_SPEC_KEYS[name](Constructor, property); + } else { + // Setup methods on prototype: + // The following member methods should not be automatically bound: + // 1. Expected ReactClass methods (in the "interface"). + // 2. Overridden methods (that were mixed in). + var isReactClassMethod = ReactClassInterface.hasOwnProperty(name); + var isFunction = typeof property === 'function'; + var shouldAutoBind = + isFunction && + !isReactClassMethod && + !isAlreadyDefined && + spec.autobind !== false; + + if (shouldAutoBind) { + autoBindPairs.push(name, property); + proto[name] = property; + } else { + if (isAlreadyDefined) { + var specPolicy = ReactClassInterface[name]; + + // These cases should already be caught by validateMethodOverride. + _invariant( + isReactClassMethod && + (specPolicy === 'DEFINE_MANY_MERGED' || + specPolicy === 'DEFINE_MANY'), + 'ReactClass: Unexpected spec policy %s for key %s ' + + 'when mixing in component specs.', + specPolicy, + name + ); + + // For methods which are defined more than once, call the existing + // methods before calling the new property, merging if appropriate. + if (specPolicy === 'DEFINE_MANY_MERGED') { + proto[name] = createMergedResultFunction(proto[name], property); + } else if (specPolicy === 'DEFINE_MANY') { + proto[name] = createChainedFunction(proto[name], property); + } + } else { + proto[name] = property; + if (process.env.NODE_ENV !== 'production') { + // Add verbose displayName to the function, which helps when looking + // at profiling tools. + if (typeof property === 'function' && spec.displayName) { + proto[name].displayName = spec.displayName + '_' + name; + } + } + } + } + } + } + } + + function mixStaticSpecIntoComponent(Constructor, statics) { + if (!statics) { + return; + } + for (var name in statics) { + var property = statics[name]; + if (!statics.hasOwnProperty(name)) { + continue; + } + + var isReserved = name in RESERVED_SPEC_KEYS; + _invariant( + !isReserved, + 'ReactClass: You are attempting to define a reserved ' + + 'property, `%s`, that shouldn\'t be on the "statics" key. Define it ' + + 'as an instance property instead; it will still be accessible on the ' + + 'constructor.', + name + ); + + var isInherited = name in Constructor; + _invariant( + !isInherited, + 'ReactClass: You are attempting to define ' + + '`%s` on your component more than once. This conflict may be ' + + 'due to a mixin.', + name + ); + Constructor[name] = property; + } + } + + /** + * Merge two objects, but throw if both contain the same key. + * + * @param {object} one The first object, which is mutated. + * @param {object} two The second object + * @return {object} one after it has been mutated to contain everything in two. + */ + function mergeIntoWithNoDuplicateKeys(one, two) { + _invariant( + one && two && typeof one === 'object' && typeof two === 'object', + 'mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.' + ); + + for (var key in two) { + if (two.hasOwnProperty(key)) { + _invariant( + one[key] === undefined, + 'mergeIntoWithNoDuplicateKeys(): ' + + 'Tried to merge two objects with the same key: `%s`. This conflict ' + + 'may be due to a mixin; in particular, this may be caused by two ' + + 'getInitialState() or getDefaultProps() methods returning objects ' + + 'with clashing keys.', + key + ); + one[key] = two[key]; + } + } + return one; + } + + /** + * Creates a function that invokes two functions and merges their return values. + * + * @param {function} one Function to invoke first. + * @param {function} two Function to invoke second. + * @return {function} Function that invokes the two argument functions. + * @private + */ + function createMergedResultFunction(one, two) { + return function mergedResult() { + var a = one.apply(this, arguments); + var b = two.apply(this, arguments); + if (a == null) { + return b; + } else if (b == null) { + return a; + } + var c = {}; + mergeIntoWithNoDuplicateKeys(c, a); + mergeIntoWithNoDuplicateKeys(c, b); + return c; + }; + } + + /** + * Creates a function that invokes two functions and ignores their return vales. + * + * @param {function} one Function to invoke first. + * @param {function} two Function to invoke second. + * @return {function} Function that invokes the two argument functions. + * @private + */ + function createChainedFunction(one, two) { + return function chainedFunction() { + one.apply(this, arguments); + two.apply(this, arguments); + }; + } + + /** + * Binds a method to the component. + * + * @param {object} component Component whose method is going to be bound. + * @param {function} method Method to be bound. + * @return {function} The bound method. + */ + function bindAutoBindMethod(component, method) { + var boundMethod = method.bind(component); + if (process.env.NODE_ENV !== 'production') { + boundMethod.__reactBoundContext = component; + boundMethod.__reactBoundMethod = method; + boundMethod.__reactBoundArguments = null; + var componentName = component.constructor.displayName; + var _bind = boundMethod.bind; + boundMethod.bind = function(newThis) { + for ( + var _len = arguments.length, + args = Array(_len > 1 ? _len - 1 : 0), + _key = 1; + _key < _len; + _key++ + ) { + args[_key - 1] = arguments[_key]; + } + + // User is trying to bind() an autobound method; we effectively will + // ignore the value of "this" that the user is trying to use, so + // let's warn. + if (newThis !== component && newThis !== null) { + if (process.env.NODE_ENV !== 'production') { + warning( + false, + 'bind(): React component methods may only be bound to the ' + + 'component instance. See %s', + componentName + ); + } + } else if (!args.length) { + if (process.env.NODE_ENV !== 'production') { + warning( + false, + 'bind(): You are binding a component method to the component. ' + + 'React does this for you automatically in a high-performance ' + + 'way, so you can safely remove this call. See %s', + componentName + ); + } + return boundMethod; + } + var reboundMethod = _bind.apply(boundMethod, arguments); + reboundMethod.__reactBoundContext = component; + reboundMethod.__reactBoundMethod = method; + reboundMethod.__reactBoundArguments = args; + return reboundMethod; + }; + } + return boundMethod; + } + + /** + * Binds all auto-bound methods in a component. + * + * @param {object} component Component whose method is going to be bound. + */ + function bindAutoBindMethods(component) { + var pairs = component.__reactAutoBindPairs; + for (var i = 0; i < pairs.length; i += 2) { + var autoBindKey = pairs[i]; + var method = pairs[i + 1]; + component[autoBindKey] = bindAutoBindMethod(component, method); + } + } + + var IsMountedPreMixin = { + componentDidMount: function() { + this.__isMounted = true; + } + }; + + var IsMountedPostMixin = { + componentWillUnmount: function() { + this.__isMounted = false; + } + }; + + /** + * Add more to the ReactClass base class. These are all legacy features and + * therefore not already part of the modern ReactComponent. + */ + var ReactClassMixin = { + /** + * TODO: This will be deprecated because state should always keep a consistent + * type signature and the only use case for this, is to avoid that. + */ + replaceState: function(newState, callback) { + this.updater.enqueueReplaceState(this, newState, callback); + }, + + /** + * Checks whether or not this composite component is mounted. + * @return {boolean} True if mounted, false otherwise. + * @protected + * @final + */ + isMounted: function() { + if (process.env.NODE_ENV !== 'production') { + warning( + this.__didWarnIsMounted, + '%s: isMounted is deprecated. Instead, make sure to clean up ' + + 'subscriptions and pending requests in componentWillUnmount to ' + + 'prevent memory leaks.', + (this.constructor && this.constructor.displayName) || + this.name || + 'Component' + ); + this.__didWarnIsMounted = true; + } + return !!this.__isMounted; + } + }; + + var ReactClassComponent = function() {}; + _assign( + ReactClassComponent.prototype, + ReactComponent.prototype, + ReactClassMixin + ); + + /** + * Creates a composite component class given a class specification. + * See https://facebook.github.io/react/docs/top-level-api.html#react.createclass + * + * @param {object} spec Class specification (which must define `render`). + * @return {function} Component constructor function. + * @public + */ + function createClass(spec) { + // To keep our warnings more understandable, we'll use a little hack here to + // ensure that Constructor.name !== 'Constructor'. This makes sure we don't + // unnecessarily identify a class without displayName as 'Constructor'. + var Constructor = identity(function(props, context, updater) { + // This constructor gets overridden by mocks. The argument is used + // by mocks to assert on what gets mounted. + + if (process.env.NODE_ENV !== 'production') { + warning( + this instanceof Constructor, + 'Something is calling a React component directly. Use a factory or ' + + 'JSX instead. See: https://fb.me/react-legacyfactory' + ); + } + + // Wire up auto-binding + if (this.__reactAutoBindPairs.length) { + bindAutoBindMethods(this); + } + + this.props = props; + this.context = context; + this.refs = emptyObject; + this.updater = updater || ReactNoopUpdateQueue; + + this.state = null; + + // ReactClasses doesn't have constructors. Instead, they use the + // getInitialState and componentWillMount methods for initialization. + + var initialState = this.getInitialState ? this.getInitialState() : null; + if (process.env.NODE_ENV !== 'production') { + // We allow auto-mocks to proceed as if they're returning null. + if ( + initialState === undefined && + this.getInitialState._isMockFunction + ) { + // This is probably bad practice. Consider warning here and + // deprecating this convenience. + initialState = null; + } + } + _invariant( + typeof initialState === 'object' && !Array.isArray(initialState), + '%s.getInitialState(): must return an object or null', + Constructor.displayName || 'ReactCompositeComponent' + ); + + this.state = initialState; + }); + Constructor.prototype = new ReactClassComponent(); + Constructor.prototype.constructor = Constructor; + Constructor.prototype.__reactAutoBindPairs = []; + + injectedMixins.forEach(mixSpecIntoComponent.bind(null, Constructor)); + + mixSpecIntoComponent(Constructor, IsMountedPreMixin); + mixSpecIntoComponent(Constructor, spec); + mixSpecIntoComponent(Constructor, IsMountedPostMixin); + + // Initialize the defaultProps property after all mixins have been merged. + if (Constructor.getDefaultProps) { + Constructor.defaultProps = Constructor.getDefaultProps(); + } + + if (process.env.NODE_ENV !== 'production') { + // This is a tag to indicate that the use of these method names is ok, + // since it's used with createClass. If it's not, then it's likely a + // mistake so we'll warn you to use the static property, property + // initializer or constructor respectively. + if (Constructor.getDefaultProps) { + Constructor.getDefaultProps.isReactClassApproved = {}; + } + if (Constructor.prototype.getInitialState) { + Constructor.prototype.getInitialState.isReactClassApproved = {}; + } + } + + _invariant( + Constructor.prototype.render, + 'createClass(...): Class specification must implement a `render` method.' + ); + + if (process.env.NODE_ENV !== 'production') { + warning( + !Constructor.prototype.componentShouldUpdate, + '%s has a method called ' + + 'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' + + 'The name is phrased as a question because the function is ' + + 'expected to return a value.', + spec.displayName || 'A component' + ); + warning( + !Constructor.prototype.componentWillRecieveProps, + '%s has a method called ' + + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', + spec.displayName || 'A component' + ); + } + + // Reduce time spent doing lookups by setting these on the prototype. + for (var methodName in ReactClassInterface) { + if (!Constructor.prototype[methodName]) { + Constructor.prototype[methodName] = null; + } + } + + return Constructor; + } + + return createClass; + } + + module.exports = factory; + + +/***/ }), +/* 4 */ +/***/ (function(module, exports) { + + /* + object-assign + (c) Sindre Sorhus + @license MIT + */ + + 'use strict'; + /* eslint-disable no-unused-vars */ + var getOwnPropertySymbols = Object.getOwnPropertySymbols; + var hasOwnProperty = Object.prototype.hasOwnProperty; + var propIsEnumerable = Object.prototype.propertyIsEnumerable; + + function toObject(val) { + if (val === null || val === undefined) { + throw new TypeError('Object.assign cannot be called with null or undefined'); + } + + return Object(val); + } + + function shouldUseNative() { + try { + if (!Object.assign) { + return false; + } + + // Detect buggy property enumeration order in older V8 versions. + + // https://bugs.chromium.org/p/v8/issues/detail?id=4118 + var test1 = new String('abc'); // eslint-disable-line no-new-wrappers + test1[5] = 'de'; + if (Object.getOwnPropertyNames(test1)[0] === '5') { + return false; + } + + // https://bugs.chromium.org/p/v8/issues/detail?id=3056 + var test2 = {}; + for (var i = 0; i < 10; i++) { + test2['_' + String.fromCharCode(i)] = i; + } + var order2 = Object.getOwnPropertyNames(test2).map(function (n) { + return test2[n]; + }); + if (order2.join('') !== '0123456789') { + return false; + } + + // https://bugs.chromium.org/p/v8/issues/detail?id=3056 + var test3 = {}; + 'abcdefghijklmnopqrst'.split('').forEach(function (letter) { + test3[letter] = letter; + }); + if (Object.keys(Object.assign({}, test3)).join('') !== + 'abcdefghijklmnopqrst') { + return false; + } + + return true; + } catch (err) { + // We don't expect any of the above to throw, but better to be safe. + return false; + } + } + + module.exports = shouldUseNative() ? Object.assign : function (target, source) { + var from; + var to = toObject(target); + var symbols; + + for (var s = 1; s < arguments.length; s++) { + from = Object(arguments[s]); + + for (var key in from) { + if (hasOwnProperty.call(from, key)) { + to[key] = from[key]; + } + } + + if (getOwnPropertySymbols) { + symbols = getOwnPropertySymbols(from); + for (var i = 0; i < symbols.length; i++) { + if (propIsEnumerable.call(from, symbols[i])) { + to[symbols[i]] = from[symbols[i]]; + } + } + } + } + + return to; + }; + + +/***/ }), +/* 5 */ +/***/ (function(module, exports) { + + /** + * Copyright (c) 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + */ + + 'use strict'; + + var emptyObject = {}; + + if (process.env.NODE_ENV !== 'production') { + Object.freeze(emptyObject); + } + + module.exports = emptyObject; + +/***/ }), +/* 6 */ +/***/ (function(module, exports) { + + /** + * Copyright (c) 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + */ + + 'use strict'; + + /** + * Use invariant() to assert state which your program assumes to be true. + * + * Provide sprintf-style format (only %s is supported) and arguments + * to provide information about what broke and what you were + * expecting. + * + * The invariant message will be stripped in production, but the invariant + * will remain to ensure logic does not differ in production. + */ + + var validateFormat = function validateFormat(format) {}; + + if (process.env.NODE_ENV !== 'production') { + validateFormat = function validateFormat(format) { + if (format === undefined) { + throw new Error('invariant requires an error message argument'); + } + }; + } + + function invariant(condition, format, a, b, c, d, e, f) { + validateFormat(format); + + if (!condition) { + var error; + if (format === undefined) { + error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.'); + } else { + var args = [a, b, c, d, e, f]; + var argIndex = 0; + error = new Error(format.replace(/%s/g, function () { + return args[argIndex++]; + })); + error.name = 'Invariant Violation'; + } + + error.framesToPop = 1; // we don't care about invariant's own frame + throw error; + } + } + + module.exports = invariant; + +/***/ }), +/* 7 */ +/***/ (function(module, exports, __webpack_require__) { + + /** + * Copyright 2014-2015, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + */ + + 'use strict'; + + var emptyFunction = __webpack_require__(8); + + /** + * Similar to invariant but only logs a warning if the condition is not met. + * This can be used to log issues in development environments in critical + * paths. Removing the logging code for production environments will keep the + * same logic and follow the same code paths. + */ + + var warning = emptyFunction; + + if (process.env.NODE_ENV !== 'production') { + var printWarning = function printWarning(format) { + for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key]; + } + + var argIndex = 0; + var message = 'Warning: ' + format.replace(/%s/g, function () { + return args[argIndex++]; + }); + if (typeof console !== 'undefined') { + console.error(message); + } + try { + // --- Welcome to debugging React --- + // This error was thrown as a convenience so that you can use this stack + // to find the callsite that caused this warning to fire. + throw new Error(message); + } catch (x) {} + }; + + warning = function warning(condition, format) { + if (format === undefined) { + throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument'); + } + + if (format.indexOf('Failed Composite propType: ') === 0) { + return; // Ignore CompositeComponent proptype check. + } + + if (!condition) { + for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { + args[_key2 - 2] = arguments[_key2]; + } + + printWarning.apply(undefined, [format].concat(args)); + } + }; + } + + module.exports = warning; + +/***/ }), +/* 8 */ +/***/ (function(module, exports) { + + "use strict"; + + /** + * Copyright (c) 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * + */ + + function makeEmptyFunction(arg) { + return function () { + return arg; + }; + } + + /** + * This function accepts and discards inputs; it has no side effects. This is + * primarily useful idiomatically for overridable function endpoints which + * always need to be callable, since JS lacks a null-call idiom ala Cocoa. + */ + var emptyFunction = function emptyFunction() {}; + + emptyFunction.thatReturns = makeEmptyFunction; + emptyFunction.thatReturnsFalse = makeEmptyFunction(false); + emptyFunction.thatReturnsTrue = makeEmptyFunction(true); + emptyFunction.thatReturnsNull = makeEmptyFunction(null); + emptyFunction.thatReturnsThis = function () { + return this; + }; + emptyFunction.thatReturnsArgument = function (arg) { + return arg; + }; + + module.exports = emptyFunction; + +/***/ }), +/* 9 */ +/***/ (function(module, exports) { + + 'use strict'; + + var NumeralFormatter = function NumeralFormatter(numeralDecimalMark, numeralIntegerScale, numeralDecimalScale, numeralThousandsGroupStyle, numeralPositiveOnly, stripLeadingZeroes, delimiter) { + var owner = this; + + owner.numeralDecimalMark = numeralDecimalMark || '.'; + owner.numeralIntegerScale = numeralIntegerScale > 0 ? numeralIntegerScale : 0; + owner.numeralDecimalScale = numeralDecimalScale >= 0 ? numeralDecimalScale : 2; + owner.numeralThousandsGroupStyle = numeralThousandsGroupStyle || NumeralFormatter.groupStyle.thousand; + owner.numeralPositiveOnly = !!numeralPositiveOnly; + owner.stripLeadingZeroes = undefined == stripLeadingZeroes ? true : stripLeadingZeroes; + owner.delimiter = delimiter || delimiter === '' ? delimiter : ','; + owner.delimiterRE = delimiter ? new RegExp('\\' + delimiter, 'g') : ''; + }; + + NumeralFormatter.groupStyle = { + thousand: 'thousand', + lakh: 'lakh', + wan: 'wan', + none: 'none' + }; + + NumeralFormatter.prototype = { + getRawValue: function getRawValue(value) { + return value.replace(this.delimiterRE, '').replace(this.numeralDecimalMark, '.'); + }, + + format: function format(value) { + var owner = this, + parts, + partInteger, + partDecimal = ''; + + // strip alphabet letters + value = value.replace(/[A-Za-z]/g, '') + // replace the first decimal mark with reserved placeholder + .replace(owner.numeralDecimalMark, 'M') + + // strip non numeric letters except minus and "M" + // this is to ensure prefix has been stripped + .replace(/[^\dM-]/g, '') + + // replace the leading minus with reserved placeholder + .replace(/^\-/, 'N') + + // strip the other minus sign (if present) + .replace(/\-/g, '') + + // replace the minus sign (if present) + .replace('N', owner.numeralPositiveOnly ? '' : '-') + + // replace decimal mark + .replace('M', owner.numeralDecimalMark); + + // strip any leading zeros + if (owner.stripLeadingZeroes) { + value = value.replace(/^(-)?0+(?=\d)/, '$1'); + } + + partInteger = value; + + if (value.indexOf(owner.numeralDecimalMark) >= 0) { + parts = value.split(owner.numeralDecimalMark); + partInteger = parts[0]; + partDecimal = owner.numeralDecimalMark + parts[1].slice(0, owner.numeralDecimalScale); + } + + if (owner.numeralIntegerScale > 0) { + partInteger = partInteger.slice(0, owner.numeralIntegerScale + (value.slice(0, 1) === '-' ? 1 : 0)); + } + + switch (owner.numeralThousandsGroupStyle) { + case NumeralFormatter.groupStyle.lakh: + partInteger = partInteger.replace(/(\d)(?=(\d\d)+\d$)/g, '$1' + owner.delimiter); + + break; + + case NumeralFormatter.groupStyle.wan: + partInteger = partInteger.replace(/(\d)(?=(\d{4})+$)/g, '$1' + owner.delimiter); + + break; + + case NumeralFormatter.groupStyle.thousand: + partInteger = partInteger.replace(/(\d)(?=(\d{3})+$)/g, '$1' + owner.delimiter); + + break; + } + + return partInteger.toString() + (owner.numeralDecimalScale > 0 ? partDecimal.toString() : ''); + } + }; + + module.exports = NumeralFormatter; + +/***/ }), +/* 10 */ +/***/ (function(module, exports) { + + 'use strict'; + + var DateFormatter = function DateFormatter(datePattern) { + var owner = this; + + owner.date = []; + owner.blocks = []; + owner.datePattern = datePattern; + owner.initBlocks(); + }; + + DateFormatter.prototype = { + initBlocks: function initBlocks() { + var owner = this; + owner.datePattern.forEach(function (value) { + if (value === 'Y') { + owner.blocks.push(4); + } else { + owner.blocks.push(2); + } + }); + }, + + getISOFormatDate: function getISOFormatDate() { + var owner = this, + date = owner.date; + + return date[2] ? date[2] + '-' + owner.addLeadingZero(date[1]) + '-' + owner.addLeadingZero(date[0]) : ''; + }, + + getBlocks: function getBlocks() { + return this.blocks; + }, + + getValidatedDate: function getValidatedDate(value) { + var owner = this, + result = ''; + + value = value.replace(/[^\d]/g, ''); + + owner.blocks.forEach(function (length, index) { + if (value.length > 0) { + var sub = value.slice(0, length), + sub0 = sub.slice(0, 1), + rest = value.slice(length); + + switch (owner.datePattern[index]) { + case 'd': + if (sub === '00') { + sub = '01'; + } else if (parseInt(sub0, 10) > 3) { + sub = '0' + sub0; + } else if (parseInt(sub, 10) > 31) { + sub = '31'; + } + + break; + + case 'm': + if (sub === '00') { + sub = '01'; + } else if (parseInt(sub0, 10) > 1) { + sub = '0' + sub0; + } else if (parseInt(sub, 10) > 12) { + sub = '12'; + } + + break; + } + + result += sub; + + // update remaining string + value = rest; + } + }); + + return this.getFixedDateString(result); + }, + + getFixedDateString: function getFixedDateString(value) { + var owner = this, + datePattern = owner.datePattern, + date = [], + dayIndex = 0, + monthIndex = 0, + yearIndex = 0, + dayStartIndex = 0, + monthStartIndex = 0, + yearStartIndex = 0, + day, + month, + year; + + // mm-dd || dd-mm + if (value.length === 4 && datePattern[0].toLowerCase() !== 'y' && datePattern[1].toLowerCase() !== 'y') { + dayStartIndex = datePattern[0] === 'd' ? 0 : 2; + monthStartIndex = 2 - dayStartIndex; + day = parseInt(value.slice(dayStartIndex, dayStartIndex + 2), 10); + month = parseInt(value.slice(monthStartIndex, monthStartIndex + 2), 10); + + date = this.getFixedDate(day, month, 0); + } + + // yyyy-mm-dd || yyyy-dd-mm || mm-dd-yyyy || dd-mm-yyyy || dd-yyyy-mm || mm-yyyy-dd + if (value.length === 8) { + datePattern.forEach(function (type, index) { + switch (type) { + case 'd': + dayIndex = index; + break; + case 'm': + monthIndex = index; + break; + default: + yearIndex = index; + break; + } + }); + + yearStartIndex = yearIndex * 2; + dayStartIndex = dayIndex <= yearIndex ? dayIndex * 2 : dayIndex * 2 + 2; + monthStartIndex = monthIndex <= yearIndex ? monthIndex * 2 : monthIndex * 2 + 2; + + day = parseInt(value.slice(dayStartIndex, dayStartIndex + 2), 10); + month = parseInt(value.slice(monthStartIndex, monthStartIndex + 2), 10); + year = parseInt(value.slice(yearStartIndex, yearStartIndex + 4), 10); + + date = this.getFixedDate(day, month, year); + } + + owner.date = date; + + return date.length === 0 ? value : datePattern.reduce(function (previous, current) { + switch (current) { + case 'd': + return previous + owner.addLeadingZero(date[0]); + case 'm': + return previous + owner.addLeadingZero(date[1]); + default: + return previous + '' + (date[2] || ''); + } + }, ''); + }, + + getFixedDate: function getFixedDate(day, month, year) { + day = Math.min(day, 31); + month = Math.min(month, 12); + year = parseInt(year || 0, 10); + + if (month < 7 && month % 2 === 0 || month > 8 && month % 2 === 1) { + day = Math.min(day, month === 2 ? this.isLeapYear(year) ? 29 : 28 : 30); + } + + return [day, month, year]; + }, + + isLeapYear: function isLeapYear(year) { + return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0; + }, + + addLeadingZero: function addLeadingZero(number) { + return (number < 10 ? '0' : '') + number; + } + }; + + module.exports = DateFormatter; + +/***/ }), +/* 11 */ +/***/ (function(module, exports) { + + 'use strict'; + + var PhoneFormatter = function PhoneFormatter(formatter, delimiter) { + var owner = this; + + owner.delimiter = delimiter || delimiter === '' ? delimiter : ' '; + owner.delimiterRE = delimiter ? new RegExp('\\' + delimiter, 'g') : ''; + + owner.formatter = formatter; + }; + + PhoneFormatter.prototype = { + setFormatter: function setFormatter(formatter) { + this.formatter = formatter; + }, + + format: function format(phoneNumber) { + var owner = this; + + owner.formatter.clear(); + + // only keep number and + + phoneNumber = phoneNumber.replace(/[^\d+]/g, ''); + + // strip delimiter + phoneNumber = phoneNumber.replace(owner.delimiterRE, ''); + + var result = '', + current, + validated = false; + + for (var i = 0, iMax = phoneNumber.length; i < iMax; i++) { + current = owner.formatter.inputDigit(phoneNumber.charAt(i)); + + // has ()- or space inside + if (/[\s()-]/g.test(current)) { + result = current; + + validated = true; + } else { + if (!validated) { + result = current; + } + // else: over length input + // it turns to invalid number again + } + } + + // strip () + // e.g. US: 7161234567 returns (716) 123-4567 + result = result.replace(/[()]/g, ''); + // replace library delimiter with user customized delimiter + result = result.replace(/[\s-]/g, owner.delimiter); + + return result; + } + }; + + module.exports = PhoneFormatter; + +/***/ }), +/* 12 */ +/***/ (function(module, exports) { + + 'use strict'; + + var CreditCardDetector = { + blocks: { + uatp: [4, 5, 6], + amex: [4, 6, 5], + diners: [4, 6, 4], + discover: [4, 4, 4, 4], + mastercard: [4, 4, 4, 4], + dankort: [4, 4, 4, 4], + instapayment: [4, 4, 4, 4], + jcb: [4, 4, 4, 4], + maestro: [4, 4, 4, 4], + visa: [4, 4, 4, 4], + mir: [4, 4, 4, 4], + general: [4, 4, 4, 4], + unionPay: [4, 4, 4, 4], + generalStrict: [4, 4, 4, 7] + }, + + re: { + // starts with 1; 15 digits, not starts with 1800 (jcb card) + uatp: /^(?!1800)1\d{0,14}/, + + // starts with 34/37; 15 digits + amex: /^3[47]\d{0,13}/, + + // starts with 6011/65/644-649; 16 digits + discover: /^(?:6011|65\d{0,2}|64[4-9]\d?)\d{0,12}/, + + // starts with 300-305/309 or 36/38/39; 14 digits + diners: /^3(?:0([0-5]|9)|[689]\d?)\d{0,11}/, + + // starts with 51-55/2221–2720; 16 digits + mastercard: /^(5[1-5]\d{0,2}|22[2-9]\d{0,1}|2[3-7]\d{0,2})\d{0,12}/, + + // starts with 5019/4175/4571; 16 digits + dankort: /^(5019|4175|4571)\d{0,12}/, + + // starts with 637-639; 16 digits + instapayment: /^63[7-9]\d{0,13}/, + + // starts with 2131/1800/35; 16 digits + jcb: /^(?:2131|1800|35\d{0,2})\d{0,12}/, + + // starts with 50/56-58/6304/67; 16 digits + maestro: /^(?:5[0678]\d{0,2}|6304|67\d{0,2})\d{0,12}/, + + // starts with 22; 16 digits + mir: /^220[0-4]\d{0,12}/, + + // starts with 4; 16 digits + visa: /^4\d{0,15}/, + + // starts with 62; 16 digits + unionPay: /^62\d{0,14}/ + }, + + getInfo: function getInfo(value, strictMode) { + var blocks = CreditCardDetector.blocks, + re = CreditCardDetector.re; + + // In theory, visa credit card can have up to 19 digits number. + // Set strictMode to true will remove the 16 max-length restrain, + // however, I never found any website validate card number like + // this, hence probably you don't need to enable this option. + strictMode = !!strictMode; + + for (var key in re) { + if (re[key].test(value)) { + var block; + if (key === 'discover' || key === 'maestro' || key === 'visa' || key === 'mir' || key === 'unionPay') { + block = strictMode ? blocks.generalStrict : blocks[key]; + } else { + block = blocks[key]; + } + return { + type: key, + blocks: block + }; + } + } + + return { + type: 'unknown', + blocks: strictMode ? blocks.generalStrict : blocks.general + }; + } + }; + + module.exports = CreditCardDetector; + +/***/ }), +/* 13 */ +/***/ (function(module, exports) { + + 'use strict'; + + var Util = { + noop: function noop() {}, + + strip: function strip(value, re) { + return value.replace(re, ''); + }, + + isDelimiter: function isDelimiter(letter, delimiter, delimiters) { + // single delimiter + if (delimiters.length === 0) { + return letter === delimiter; + } + + // multiple delimiters + return delimiters.some(function (current) { + if (letter === current) { + return true; + } + }); + }, + + getDelimiterREByDelimiter: function getDelimiterREByDelimiter(delimiter) { + return new RegExp(delimiter.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'), 'g'); + }, + + stripDelimiters: function stripDelimiters(value, delimiter, delimiters) { + var owner = this; + + // single delimiter + if (delimiters.length === 0) { + var delimiterRE = delimiter ? owner.getDelimiterREByDelimiter(delimiter) : ''; + + return value.replace(delimiterRE, ''); + } + + // multiple delimiters + delimiters.forEach(function (current) { + value = value.replace(owner.getDelimiterREByDelimiter(current), ''); + }); + + return value; + }, + + headStr: function headStr(str, length) { + return str.slice(0, length); + }, + + getMaxLength: function getMaxLength(blocks) { + return blocks.reduce(function (previous, current) { + return previous + current; + }, 0); + }, + + // strip value by prefix length + // for prefix: PRE + // (PRE123, 3) -> 123 + // (PR123, 3) -> 23 this happens when user hits backspace in front of "PRE" + getPrefixStrippedValue: function getPrefixStrippedValue(value, prefix, prefixLength) { + if (value.slice(0, prefixLength) !== prefix) { + var diffIndex = this.getFirstDiffIndex(prefix, value.slice(0, prefixLength)); + + value = prefix + value.slice(diffIndex, diffIndex + 1) + value.slice(prefixLength + 1); + } + + return value.slice(prefixLength); + }, + + getFirstDiffIndex: function getFirstDiffIndex(prev, current) { + var index = 0; + + while (prev.charAt(index) === current.charAt(index)) { + if (prev.charAt(index++) === '') return -1; + }return index; + }, + + getFormattedValue: function getFormattedValue(value, blocks, blocksLength, delimiter, delimiters) { + var result = '', + multipleDelimiters = delimiters.length > 0, + currentDelimiter; + + // no options, normal input + if (blocksLength === 0) { + return value; + } + + blocks.forEach(function (length, index) { + if (value.length > 0) { + var sub = value.slice(0, length), + rest = value.slice(length); + + result += sub; + + currentDelimiter = multipleDelimiters ? delimiters[index] || currentDelimiter : delimiter; + + if (sub.length === length && index < blocksLength - 1) { + result += currentDelimiter; + } + + // update remaining string + value = rest; + } + }); + + return result; + }, + + isAndroid: function isAndroid() { + return navigator && /android/i.test(navigator.userAgent); + }, + + // On Android chrome, the keyup and keydown events + // always return key code 229 as a composition that + // buffers the user’s keystrokes + // see https://github.com/nosir/cleave.js/issues/147 + isAndroidBackspaceKeydown: function isAndroidBackspaceKeydown(lastInputValue, currentInputValue) { + if (!this.isAndroid() || !lastInputValue || !currentInputValue) { + return false; + } + + return currentInputValue === lastInputValue.slice(0, -1); + } + }; + + module.exports = Util; + +/***/ }), +/* 14 */ +/***/ (function(module, exports) { + + 'use strict'; + + /** + * Props Assignment + * + * Separate this, so react module can share the usage + */ + + var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + + var DefaultProperties = { + // Maybe change to object-assign + // for now just keep it as simple + assign: function assign(target, opts) { + target = target || {}; + opts = opts || {}; + + // credit card + target.creditCard = !!opts.creditCard; + target.creditCardStrictMode = !!opts.creditCardStrictMode; + target.creditCardType = ''; + target.onCreditCardTypeChanged = opts.onCreditCardTypeChanged || function () {}; + + // phone + target.phone = !!opts.phone; + target.phoneRegionCode = opts.phoneRegionCode || 'AU'; + target.phoneFormatter = {}; + + // date + target.date = !!opts.date; + target.datePattern = opts.datePattern || ['d', 'm', 'Y']; + target.dateFormatter = {}; + + // numeral + target.numeral = !!opts.numeral; + target.numeralIntegerScale = opts.numeralIntegerScale > 0 ? opts.numeralIntegerScale : 0; + target.numeralDecimalScale = opts.numeralDecimalScale >= 0 ? opts.numeralDecimalScale : 2; + target.numeralDecimalMark = opts.numeralDecimalMark || '.'; + target.numeralThousandsGroupStyle = opts.numeralThousandsGroupStyle || 'thousand'; + target.numeralPositiveOnly = !!opts.numeralPositiveOnly; + target.stripLeadingZeroes = undefined == opts.stripLeadingZeroes ? true : opts.stripLeadingZeroes; + + // others + target.numericOnly = target.creditCard || target.date || !!opts.numericOnly; + + target.uppercase = !!opts.uppercase; + target.lowercase = !!opts.lowercase; + + target.prefix = target.creditCard || target.date ? '' : opts.prefix || ''; + target.noImmediatePrefix = !!opts.noImmediatePrefix; + target.prefixLength = target.prefix.length; + target.rawValueTrimPrefix = !!opts.rawValueTrimPrefix; + target.copyDelimiter = !!opts.copyDelimiter; + + target.initValue = opts.initValue !== undefined && opts.initValue !== null ? opts.initValue.toString() : ''; + + target.delimiter = opts.delimiter || opts.delimiter === '' ? opts.delimiter : opts.date ? '/' : opts.numeral ? ',' : opts.phone ? ' ' : ' '; + target.delimiterLength = target.delimiter.length; + target.delimiters = opts.delimiters || []; + + target.blocks = opts.blocks || []; + target.blocksLength = target.blocks.length; + + target.root = (typeof global === 'undefined' ? 'undefined' : _typeof(global)) === 'object' && global ? global : window; + + target.maxLength = 0; + + target.backspace = false; + target.result = ''; + + return target; + } + }; + + module.exports = DefaultProperties; + +/***/ }) +/******/ ]) +}); +; \ No newline at end of file diff --git a/dist/cleave-react-node.min.js b/dist/cleave-react-node.min.js new file mode 100644 index 00000000..2556610f --- /dev/null +++ b/dist/cleave-react-node.min.js @@ -0,0 +1,8 @@ +/*! + * cleave.js - 1.0.9 + * https://github.com/nosir/cleave.js + * Apache License Version 2.0 + * + * Copyright (C) 2012-2017 Max Huang https://github.com/nosir/ + */ +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.Cleave=t(require("react")):e.Cleave=t(e.React)}(this,function(e){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";function n(e,t){var r={};for(var n in e)t.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n]);return r}var o=Object.assign||function(e){for(var t=1;t0?p.headStr(e,n.maxLength):e,n.result=p.getFormattedValue(e,n.blocks,n.blocksLength,n.delimiter,n.delimiters),void r.updateValueState()):(n.result=e,void r.updateValueState()))},updateCreditCardPropsByValue:function(e){var t,r=this,n=r.properties;p.headStr(n.result,4)!==p.headStr(e,4)&&(t=l.getInfo(e,n.creditCardStrictMode),n.blocks=t.blocks,n.blocksLength=n.blocks.length,n.maxLength=p.getMaxLength(n.blocks),n.creditCardType!==t.type&&(n.creditCardType=t.type,n.onCreditCardTypeChanged.call(r,n.creditCardType)))},getNextCursorPosition:function(e,t,r){return t.length===e?r.length:e},setCurrentSelection:function(e){var t=this.element;if(this.setState({updateCursorPosition:!1}),t===document.activeElement)if(t.createTextRange){var r=t.createTextRange();r.move("character",e),r.select()}else t.setSelectionRange(e,e)},updateValueState:function(){var e=this,t=e.element.selectionEnd,r=e.element.value,n=e.properties.result,o=e.getNextCursorPosition(t,r,n);return e.lastInputValue=e.properties.result,e.isAndroid?void window.setTimeout(function(){e.setState({value:e.properties.result,cursorPosition:o,updateCursorPosition:!0})},1):void e.setState({value:e.properties.result,cursorPosition:o,updateCursorPosition:!0})},render:function(){var e=this,t=e.props,r=(t.value,t.options,t.onKeyDown,t.onFocus,t.onBlur,t.onChange,t.onInit,t.htmlRef),a=n(t,["value","options","onKeyDown","onFocus","onBlur","onChange","onInit","htmlRef"]);return i.createElement("input",o({type:"text",ref:function(t){e.element=t,r&&r.apply(this,arguments)},value:e.state.value,onKeyDown:e.onKeyDown,onChange:e.onChange,onFocus:e.onFocus,onBlur:e.onBlur},a))}});e.exports=m},function(t,r){t.exports=e},function(e,t,r){"use strict";var n=r(1),o=r(3);if("undefined"==typeof n)throw Error("create-react-class could not find the React object. If you are using script tags, make sure that React is being loaded before create-react-class.");var i=(new n.Component).updater;e.exports=o(n.Component,n.isValidElement,i)},function(e,t,r){"use strict";function n(e){return e}function o(e,t,r){function o(e,t,r){for(var n in t)t.hasOwnProperty(n)&&"production"!==process.env.NODE_ENV&&c("function"==typeof t[n],"%s: %s type `%s` is invalid; it must be a function, usually from React.PropTypes.",e.displayName||"ReactClass",u[r],n)}function p(e,t){var r=b.hasOwnProperty(t)?b[t]:null;w.hasOwnProperty(t)&&s("OVERRIDE_BASE"===r,"ReactClassInterface: You are attempting to override `%s` from your class specification. Ensure that your method names do not overlap with React methods.",t),e&&s("DEFINE_MANY"===r||"DEFINE_MANY_MERGED"===r,"ReactClassInterface: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.",t)}function d(e,r){if(r){s("function"!=typeof r,"ReactClass: You're attempting to use a component class or function as a mixin. Instead, just use a regular object."),s(!t(r),"ReactClass: You're attempting to use a component as a mixin. Instead, just use a regular object.");var n=e.prototype,o=n.__reactAutoBindPairs;r.hasOwnProperty(l)&&x.mixins(e,r.mixins);for(var i in r)if(r.hasOwnProperty(i)&&i!==l){var a=r[i],u=n.hasOwnProperty(i);if(p(u,i),x.hasOwnProperty(i))x[i](e,a);else{var d=b.hasOwnProperty(i),m="function"==typeof a,f=m&&!d&&!u&&r.autobind!==!1;if(f)o.push(i,a),n[i]=a;else if(u){var y=b[i];s(d&&("DEFINE_MANY_MERGED"===y||"DEFINE_MANY"===y),"ReactClass: Unexpected spec policy %s for key %s when mixing in component specs.",y,i),"DEFINE_MANY_MERGED"===y?n[i]=h(n[i],a):"DEFINE_MANY"===y&&(n[i]=g(n[i],a))}else n[i]=a,"production"!==process.env.NODE_ENV&&"function"==typeof a&&r.displayName&&(n[i].displayName=r.displayName+"_"+i)}}}else if("production"!==process.env.NODE_ENV){var v=typeof r,E="object"===v&&null!==r;"production"!==process.env.NODE_ENV&&c(E,"%s: You're attempting to include a mixin that is either null or not an object. Check the mixins included by the component, as well as any mixins they include themselves. Expected object but got %s.",e.displayName||"ReactClass",null===r?null:v)}}function m(e,t){if(t)for(var r in t){var n=t[r];if(t.hasOwnProperty(r)){var o=r in x;s(!o,'ReactClass: You are attempting to define a reserved property, `%s`, that shouldn\'t be on the "statics" key. Define it as an instance property instead; it will still be accessible on the constructor.',r);var i=r in e;s(!i,"ReactClass: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.",r),e[r]=n}}}function f(e,t){s(e&&t&&"object"==typeof e&&"object"==typeof t,"mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.");for(var r in t)t.hasOwnProperty(r)&&(s(void 0===e[r],"mergeIntoWithNoDuplicateKeys(): Tried to merge two objects with the same key: `%s`. This conflict may be due to a mixin; in particular, this may be caused by two getInitialState() or getDefaultProps() methods returning objects with clashing keys.",r),e[r]=t[r]);return e}function h(e,t){return function(){var r=e.apply(this,arguments),n=t.apply(this,arguments);if(null==r)return n;if(null==n)return r;var o={};return f(o,r),f(o,n),o}}function g(e,t){return function(){e.apply(this,arguments),t.apply(this,arguments)}}function y(e,t){var r=t.bind(e);if("production"!==process.env.NODE_ENV){r.__reactBoundContext=e,r.__reactBoundMethod=t,r.__reactBoundArguments=null;var n=e.constructor.displayName,o=r.bind;r.bind=function(i){for(var a=arguments.length,s=Array(a>1?a-1:0),u=1;u1?t-1:0),n=1;n2?r-2:0),o=2;o0?t:0,c.numeralDecimalScale=r>=0?r:2,c.numeralThousandsGroupStyle=o||n.groupStyle.thousand,c.numeralPositiveOnly=!!i,c.stripLeadingZeroes=void 0==a||a,c.delimiter=s||""===s?s:",",c.delimiterRE=s?new RegExp("\\"+s,"g"):""};r.groupStyle={thousand:"thousand",lakh:"lakh",wan:"wan",none:"none"},r.prototype={getRawValue:function(e){return e.replace(this.delimiterRE,"").replace(this.numeralDecimalMark,".")},format:function(e){var t,n,o=this,i="";switch(e=e.replace(/[A-Za-z]/g,"").replace(o.numeralDecimalMark,"M").replace(/[^\dM-]/g,"").replace(/^\-/,"N").replace(/\-/g,"").replace("N",o.numeralPositiveOnly?"":"-").replace("M",o.numeralDecimalMark),o.stripLeadingZeroes&&(e=e.replace(/^(-)?0+(?=\d)/,"$1")),n=e,e.indexOf(o.numeralDecimalMark)>=0&&(t=e.split(o.numeralDecimalMark),n=t[0],i=o.numeralDecimalMark+t[1].slice(0,o.numeralDecimalScale)),o.numeralIntegerScale>0&&(n=n.slice(0,o.numeralIntegerScale+("-"===e.slice(0,1)?1:0))),o.numeralThousandsGroupStyle){case r.groupStyle.lakh:n=n.replace(/(\d)(?=(\d\d)+\d$)/g,"$1"+o.delimiter);break;case r.groupStyle.wan:n=n.replace(/(\d)(?=(\d{4})+$)/g,"$1"+o.delimiter);break;case r.groupStyle.thousand:n=n.replace(/(\d)(?=(\d{3})+$)/g,"$1"+o.delimiter)}return n.toString()+(o.numeralDecimalScale>0?i.toString():"")}},e.exports=r},function(e,t){"use strict";var r=function(e){var t=this;t.date=[],t.blocks=[],t.datePattern=e,t.initBlocks()};r.prototype={initBlocks:function(){var e=this;e.datePattern.forEach(function(t){"Y"===t?e.blocks.push(4):e.blocks.push(2)})},getISOFormatDate:function(){var e=this,t=e.date;return t[2]?t[2]+"-"+e.addLeadingZero(t[1])+"-"+e.addLeadingZero(t[0]):""},getBlocks:function(){return this.blocks},getValidatedDate:function(e){var t=this,r="";return e=e.replace(/[^\d]/g,""),t.blocks.forEach(function(n,o){if(e.length>0){var i=e.slice(0,n),a=i.slice(0,1),s=e.slice(n);switch(t.datePattern[o]){case"d":"00"===i?i="01":parseInt(a,10)>3?i="0"+a:parseInt(i,10)>31&&(i="31");break;case"m":"00"===i?i="01":parseInt(a,10)>1?i="0"+a:parseInt(i,10)>12&&(i="12")}r+=i,e=s}}),this.getFixedDateString(r)},getFixedDateString:function(e){var t,r,n,o=this,i=o.datePattern,a=[],s=0,c=0,u=0,l=0,p=0,d=0;return 4===e.length&&"y"!==i[0].toLowerCase()&&"y"!==i[1].toLowerCase()&&(l="d"===i[0]?0:2,p=2-l,t=parseInt(e.slice(l,l+2),10),r=parseInt(e.slice(p,p+2),10),a=this.getFixedDate(t,r,0)),8===e.length&&(i.forEach(function(e,t){switch(e){case"d":s=t;break;case"m":c=t;break;default:u=t}}),d=2*u,l=s<=u?2*s:2*s+2,p=c<=u?2*c:2*c+2,t=parseInt(e.slice(l,l+2),10),r=parseInt(e.slice(p,p+2),10),n=parseInt(e.slice(d,d+4),10),a=this.getFixedDate(t,r,n)),o.date=a,0===a.length?e:i.reduce(function(e,t){switch(t){case"d":return e+o.addLeadingZero(a[0]);case"m":return e+o.addLeadingZero(a[1]);default:return e+""+(a[2]||"")}},"")},getFixedDate:function(e,t,r){return e=Math.min(e,31),t=Math.min(t,12),r=parseInt(r||0,10),(t<7&&t%2===0||t>8&&t%2===1)&&(e=Math.min(e,2===t?this.isLeapYear(r)?29:28:30)),[e,t,r]},isLeapYear:function(e){return e%4===0&&e%100!==0||e%400===0},addLeadingZero:function(e){return(e<10?"0":"")+e}},e.exports=r},function(e,t){"use strict";var r=function(e,t){var r=this;r.delimiter=t||""===t?t:" ",r.delimiterRE=t?new RegExp("\\"+t,"g"):"",r.formatter=e};r.prototype={setFormatter:function(e){this.formatter=e},format:function(e){var t=this;t.formatter.clear(),e=e.replace(/[^\d+]/g,""),e=e.replace(t.delimiterRE,"");for(var r,n="",o=!1,i=0,a=e.length;i0;return 0===r?e:(t.forEach(function(t,c){if(e.length>0){var u=e.slice(0,t),l=e.slice(t);a+=u,i=s?o[c]||i:n,u.length===t&&c0?t.numeralIntegerScale:0,e.numeralDecimalScale=t.numeralDecimalScale>=0?t.numeralDecimalScale:2,e.numeralDecimalMark=t.numeralDecimalMark||".",e.numeralThousandsGroupStyle=t.numeralThousandsGroupStyle||"thousand",e.numeralPositiveOnly=!!t.numeralPositiveOnly,e.stripLeadingZeroes=void 0==t.stripLeadingZeroes||t.stripLeadingZeroes,e.numericOnly=e.creditCard||e.date||!!t.numericOnly,e.uppercase=!!t.uppercase,e.lowercase=!!t.lowercase,e.prefix=e.creditCard||e.date?"":t.prefix||"",e.noImmediatePrefix=!!t.noImmediatePrefix,e.prefixLength=e.prefix.length,e.rawValueTrimPrefix=!!t.rawValueTrimPrefix,e.copyDelimiter=!!t.copyDelimiter,e.initValue=void 0!==t.initValue&&null!==t.initValue?t.initValue.toString():"",e.delimiter=t.delimiter||""===t.delimiter?t.delimiter:t.date?"/":t.numeral?",":(t.phone," "),e.delimiterLength=e.delimiter.length,e.delimiters=t.delimiters||[],e.blocks=t.blocks||[],e.blocksLength=e.blocks.length,e.root="object"===("undefined"==typeof global?"undefined":r(global))&&global?global:window,e.maxLength=0,e.backspace=!1,e.result="",e}};e.exports=n}])}); \ No newline at end of file diff --git a/dist/cleave-react.js b/dist/cleave-react.js index 85b3f8f4..6283f0f7 100644 --- a/dist/cleave-react.js +++ b/dist/cleave-react.js @@ -63,12 +63,12 @@ return /******/ (function(modules) { // webpackBootstrap var React = __webpack_require__(1); // eslint-disable-line no-unused-vars var CreateReactClass = __webpack_require__(2); - var NumeralFormatter = __webpack_require__(9); - var DateFormatter = __webpack_require__(10); - var PhoneFormatter = __webpack_require__(11); - var CreditCardDetector = __webpack_require__(12); - var Util = __webpack_require__(13); - var DefaultProperties = __webpack_require__(14); + var NumeralFormatter = __webpack_require__(10); + var DateFormatter = __webpack_require__(11); + var PhoneFormatter = __webpack_require__(12); + var CreditCardDetector = __webpack_require__(13); + var Util = __webpack_require__(14); + var DefaultProperties = __webpack_require__(15); var Cleave = CreateReactClass({ componentDidMount: function componentDidMount() { @@ -544,7 +544,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 3 */ /***/ (function(module, exports, __webpack_require__) { - /** + /* WEBPACK VAR INJECTION */(function(process) {/** * Copyright 2013-present, Facebook, Inc. * All rights reserved. * @@ -556,13 +556,13 @@ return /******/ (function(modules) { // webpackBootstrap 'use strict'; - var _assign = __webpack_require__(4); + var _assign = __webpack_require__(5); - var emptyObject = __webpack_require__(5); - var _invariant = __webpack_require__(6); + var emptyObject = __webpack_require__(6); + var _invariant = __webpack_require__(7); if (process.env.NODE_ENV !== 'production') { - var warning = __webpack_require__(7); + var warning = __webpack_require__(8); } var MIXINS_KEY = 'mixins'; @@ -1417,9 +1417,200 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = factory; + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4))) /***/ }), /* 4 */ +/***/ (function(module, exports) { + + // shim for using process in browser + var process = module.exports = {}; + + // cached from whatever global is present so that test runners that stub it + // don't break things. But we need to wrap it in a try catch in case it is + // wrapped in strict mode code which doesn't define any globals. It's inside a + // function because try/catches deoptimize in certain engines. + + var cachedSetTimeout; + var cachedClearTimeout; + + function defaultSetTimout() { + throw new Error('setTimeout has not been defined'); + } + function defaultClearTimeout () { + throw new Error('clearTimeout has not been defined'); + } + (function () { + try { + if (typeof setTimeout === 'function') { + cachedSetTimeout = setTimeout; + } else { + cachedSetTimeout = defaultSetTimout; + } + } catch (e) { + cachedSetTimeout = defaultSetTimout; + } + try { + if (typeof clearTimeout === 'function') { + cachedClearTimeout = clearTimeout; + } else { + cachedClearTimeout = defaultClearTimeout; + } + } catch (e) { + cachedClearTimeout = defaultClearTimeout; + } + } ()) + function runTimeout(fun) { + if (cachedSetTimeout === setTimeout) { + //normal enviroments in sane situations + return setTimeout(fun, 0); + } + // if setTimeout wasn't available but was latter defined + if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { + cachedSetTimeout = setTimeout; + return setTimeout(fun, 0); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedSetTimeout(fun, 0); + } catch(e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedSetTimeout.call(null, fun, 0); + } catch(e){ + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error + return cachedSetTimeout.call(this, fun, 0); + } + } + + + } + function runClearTimeout(marker) { + if (cachedClearTimeout === clearTimeout) { + //normal enviroments in sane situations + return clearTimeout(marker); + } + // if clearTimeout wasn't available but was latter defined + if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { + cachedClearTimeout = clearTimeout; + return clearTimeout(marker); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedClearTimeout(marker); + } catch (e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedClearTimeout.call(null, marker); + } catch (e){ + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. + // Some versions of I.E. have different rules for clearTimeout vs setTimeout + return cachedClearTimeout.call(this, marker); + } + } + + + + } + var queue = []; + var draining = false; + var currentQueue; + var queueIndex = -1; + + function cleanUpNextTick() { + if (!draining || !currentQueue) { + return; + } + draining = false; + if (currentQueue.length) { + queue = currentQueue.concat(queue); + } else { + queueIndex = -1; + } + if (queue.length) { + drainQueue(); + } + } + + function drainQueue() { + if (draining) { + return; + } + var timeout = runTimeout(cleanUpNextTick); + draining = true; + + var len = queue.length; + while(len) { + currentQueue = queue; + queue = []; + while (++queueIndex < len) { + if (currentQueue) { + currentQueue[queueIndex].run(); + } + } + queueIndex = -1; + len = queue.length; + } + currentQueue = null; + draining = false; + runClearTimeout(timeout); + } + + process.nextTick = function (fun) { + var args = new Array(arguments.length - 1); + if (arguments.length > 1) { + for (var i = 1; i < arguments.length; i++) { + args[i - 1] = arguments[i]; + } + } + queue.push(new Item(fun, args)); + if (queue.length === 1 && !draining) { + runTimeout(drainQueue); + } + }; + + // v8 likes predictible objects + function Item(fun, array) { + this.fun = fun; + this.array = array; + } + Item.prototype.run = function () { + this.fun.apply(null, this.array); + }; + process.title = 'browser'; + process.browser = true; + process.env = {}; + process.argv = []; + process.version = ''; // empty string to avoid regexp issues + process.versions = {}; + + function noop() {} + + process.on = noop; + process.addListener = noop; + process.once = noop; + process.off = noop; + process.removeListener = noop; + process.removeAllListeners = noop; + process.emit = noop; + process.prependListener = noop; + process.prependOnceListener = noop; + + process.listeners = function (name) { return [] } + + process.binding = function (name) { + throw new Error('process.binding is not supported'); + }; + + process.cwd = function () { return '/' }; + process.chdir = function (dir) { + throw new Error('process.chdir is not supported'); + }; + process.umask = function() { return 0; }; + + +/***/ }), +/* 5 */ /***/ (function(module, exports) { /* @@ -1515,10 +1706,10 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }), -/* 5 */ -/***/ (function(module, exports) { +/* 6 */ +/***/ (function(module, exports, __webpack_require__) { - /** + /* WEBPACK VAR INJECTION */(function(process) {/** * Copyright (c) 2013-present, Facebook, Inc. * All rights reserved. * @@ -1537,12 +1728,13 @@ return /******/ (function(modules) { // webpackBootstrap } module.exports = emptyObject; + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4))) /***/ }), -/* 6 */ -/***/ (function(module, exports) { +/* 7 */ +/***/ (function(module, exports, __webpack_require__) { - /** + /* WEBPACK VAR INJECTION */(function(process) {/** * Copyright (c) 2013-present, Facebook, Inc. * All rights reserved. * @@ -1597,12 +1789,13 @@ return /******/ (function(modules) { // webpackBootstrap } module.exports = invariant; + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4))) /***/ }), -/* 7 */ +/* 8 */ /***/ (function(module, exports, __webpack_require__) { - /** + /* WEBPACK VAR INJECTION */(function(process) {/** * Copyright 2014-2015, Facebook, Inc. * All rights reserved. * @@ -1614,7 +1807,7 @@ return /******/ (function(modules) { // webpackBootstrap 'use strict'; - var emptyFunction = __webpack_require__(8); + var emptyFunction = __webpack_require__(9); /** * Similar to invariant but only logs a warning if the condition is not met. @@ -1666,9 +1859,10 @@ return /******/ (function(modules) { // webpackBootstrap } module.exports = warning; + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4))) /***/ }), -/* 8 */ +/* 9 */ /***/ (function(module, exports) { "use strict"; @@ -1711,7 +1905,7 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = emptyFunction; /***/ }), -/* 9 */ +/* 10 */ /***/ (function(module, exports) { 'use strict'; @@ -1809,7 +2003,7 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = NumeralFormatter; /***/ }), -/* 10 */ +/* 11 */ /***/ (function(module, exports) { 'use strict'; @@ -1981,7 +2175,7 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = DateFormatter; /***/ }), -/* 11 */ +/* 12 */ /***/ (function(module, exports) { 'use strict'; @@ -2045,7 +2239,7 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = PhoneFormatter; /***/ }), -/* 12 */ +/* 13 */ /***/ (function(module, exports) { 'use strict'; @@ -2141,7 +2335,7 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = CreditCardDetector; /***/ }), -/* 13 */ +/* 14 */ /***/ (function(module, exports) { 'use strict'; @@ -2272,10 +2466,10 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = Util; /***/ }), -/* 14 */ +/* 15 */ /***/ (function(module, exports) { - 'use strict'; + /* WEBPACK VAR INJECTION */(function(global) {'use strict'; /** * Props Assignment @@ -2350,6 +2544,7 @@ return /******/ (function(modules) { // webpackBootstrap }; module.exports = DefaultProperties; + /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()))) /***/ }) /******/ ]) diff --git a/dist/cleave-react.min.js b/dist/cleave-react.min.js index 175e0c62..371fa56c 100644 --- a/dist/cleave-react.min.js +++ b/dist/cleave-react.min.js @@ -1,8 +1,8 @@ /*! - * cleave.js - 1.0.7 + * cleave.js - 1.0.9 * https://github.com/nosir/cleave.js * Apache License Version 2.0 * * Copyright (C) 2012-2017 Max Huang https://github.com/nosir/ */ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.Cleave=t(require("react")):e.Cleave=t(e.React)}(this,function(e){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";function n(e,t){var r={};for(var n in e)t.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n]);return r}var o=Object.assign||function(e){for(var t=1;t0?p.headStr(e,n.maxLength):e,n.result=p.getFormattedValue(e,n.blocks,n.blocksLength,n.delimiter,n.delimiters),void r.updateValueState()):(n.result=e,void r.updateValueState()))},updateCreditCardPropsByValue:function(e){var t,r=this,n=r.properties;p.headStr(n.result,4)!==p.headStr(e,4)&&(t=l.getInfo(e,n.creditCardStrictMode),n.blocks=t.blocks,n.blocksLength=n.blocks.length,n.maxLength=p.getMaxLength(n.blocks),n.creditCardType!==t.type&&(n.creditCardType=t.type,n.onCreditCardTypeChanged.call(r,n.creditCardType)))},getNextCursorPosition:function(e,t,r){return t.length===e?r.length:e},setCurrentSelection:function(e){var t=this.element;if(this.setState({updateCursorPosition:!1}),t===document.activeElement)if(t.createTextRange){var r=t.createTextRange();r.move("character",e),r.select()}else t.setSelectionRange(e,e)},updateValueState:function(){var e=this,t=e.element.selectionEnd,r=e.element.value,n=e.properties.result,o=e.getNextCursorPosition(t,r,n);return e.lastInputValue=e.properties.result,e.isAndroid?void window.setTimeout(function(){e.setState({value:e.properties.result,cursorPosition:o,updateCursorPosition:!0})},1):void e.setState({value:e.properties.result,cursorPosition:o,updateCursorPosition:!0})},render:function(){var e=this,t=e.props,r=(t.value,t.options,t.onKeyDown,t.onFocus,t.onBlur,t.onChange,t.onInit,t.htmlRef),a=n(t,["value","options","onKeyDown","onFocus","onBlur","onChange","onInit","htmlRef"]);return i.createElement("input",o({type:"text",ref:function(t){e.element=t,r&&r.apply(this,arguments)},value:e.state.value,onKeyDown:e.onKeyDown,onChange:e.onChange,onFocus:e.onFocus,onBlur:e.onBlur},a))}});e.exports=m},function(t,r){t.exports=e},function(e,t,r){"use strict";var n=r(1),o=r(3);if("undefined"==typeof n)throw Error("create-react-class could not find the React object. If you are using script tags, make sure that React is being loaded before create-react-class.");var i=(new n.Component).updater;e.exports=o(n.Component,n.isValidElement,i)},function(e,t,r){"use strict";function n(e){return e}function o(e,t,r){function o(e,t,r){for(var n in t)t.hasOwnProperty(n)&&"production"!==process.env.NODE_ENV&&c("function"==typeof t[n],"%s: %s type `%s` is invalid; it must be a function, usually from React.PropTypes.",e.displayName||"ReactClass",u[r],n)}function p(e,t){var r=b.hasOwnProperty(t)?b[t]:null;w.hasOwnProperty(t)&&s("OVERRIDE_BASE"===r,"ReactClassInterface: You are attempting to override `%s` from your class specification. Ensure that your method names do not overlap with React methods.",t),e&&s("DEFINE_MANY"===r||"DEFINE_MANY_MERGED"===r,"ReactClassInterface: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.",t)}function d(e,r){if(r){s("function"!=typeof r,"ReactClass: You're attempting to use a component class or function as a mixin. Instead, just use a regular object."),s(!t(r),"ReactClass: You're attempting to use a component as a mixin. Instead, just use a regular object.");var n=e.prototype,o=n.__reactAutoBindPairs;r.hasOwnProperty(l)&&x.mixins(e,r.mixins);for(var i in r)if(r.hasOwnProperty(i)&&i!==l){var a=r[i],u=n.hasOwnProperty(i);if(p(u,i),x.hasOwnProperty(i))x[i](e,a);else{var d=b.hasOwnProperty(i),m="function"==typeof a,f=m&&!d&&!u&&r.autobind!==!1;if(f)o.push(i,a),n[i]=a;else if(u){var y=b[i];s(d&&("DEFINE_MANY_MERGED"===y||"DEFINE_MANY"===y),"ReactClass: Unexpected spec policy %s for key %s when mixing in component specs.",y,i),"DEFINE_MANY_MERGED"===y?n[i]=h(n[i],a):"DEFINE_MANY"===y&&(n[i]=g(n[i],a))}else n[i]=a,"production"!==process.env.NODE_ENV&&"function"==typeof a&&r.displayName&&(n[i].displayName=r.displayName+"_"+i)}}}else if("production"!==process.env.NODE_ENV){var v=typeof r,E="object"===v&&null!==r;"production"!==process.env.NODE_ENV&&c(E,"%s: You're attempting to include a mixin that is either null or not an object. Check the mixins included by the component, as well as any mixins they include themselves. Expected object but got %s.",e.displayName||"ReactClass",null===r?null:v)}}function m(e,t){if(t)for(var r in t){var n=t[r];if(t.hasOwnProperty(r)){var o=r in x;s(!o,'ReactClass: You are attempting to define a reserved property, `%s`, that shouldn\'t be on the "statics" key. Define it as an instance property instead; it will still be accessible on the constructor.',r);var i=r in e;s(!i,"ReactClass: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.",r),e[r]=n}}}function f(e,t){s(e&&t&&"object"==typeof e&&"object"==typeof t,"mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.");for(var r in t)t.hasOwnProperty(r)&&(s(void 0===e[r],"mergeIntoWithNoDuplicateKeys(): Tried to merge two objects with the same key: `%s`. This conflict may be due to a mixin; in particular, this may be caused by two getInitialState() or getDefaultProps() methods returning objects with clashing keys.",r),e[r]=t[r]);return e}function h(e,t){return function(){var r=e.apply(this,arguments),n=t.apply(this,arguments);if(null==r)return n;if(null==n)return r;var o={};return f(o,r),f(o,n),o}}function g(e,t){return function(){e.apply(this,arguments),t.apply(this,arguments)}}function y(e,t){var r=t.bind(e);if("production"!==process.env.NODE_ENV){r.__reactBoundContext=e,r.__reactBoundMethod=t,r.__reactBoundArguments=null;var n=e.constructor.displayName,o=r.bind;r.bind=function(i){for(var a=arguments.length,s=Array(a>1?a-1:0),u=1;u1?t-1:0),n=1;n2?r-2:0),o=2;o0?t:0,c.numeralDecimalScale=r>=0?r:2,c.numeralThousandsGroupStyle=o||n.groupStyle.thousand,c.numeralPositiveOnly=!!i,c.stripLeadingZeroes=void 0==a||a,c.delimiter=s||""===s?s:",",c.delimiterRE=s?new RegExp("\\"+s,"g"):""};r.groupStyle={thousand:"thousand",lakh:"lakh",wan:"wan",none:"none"},r.prototype={getRawValue:function(e){return e.replace(this.delimiterRE,"").replace(this.numeralDecimalMark,".")},format:function(e){var t,n,o=this,i="";switch(e=e.replace(/[A-Za-z]/g,"").replace(o.numeralDecimalMark,"M").replace(/[^\dM-]/g,"").replace(/^\-/,"N").replace(/\-/g,"").replace("N",o.numeralPositiveOnly?"":"-").replace("M",o.numeralDecimalMark),o.stripLeadingZeroes&&(e=e.replace(/^(-)?0+(?=\d)/,"$1")),n=e,e.indexOf(o.numeralDecimalMark)>=0&&(t=e.split(o.numeralDecimalMark),n=t[0],i=o.numeralDecimalMark+t[1].slice(0,o.numeralDecimalScale)),o.numeralIntegerScale>0&&(n=n.slice(0,o.numeralIntegerScale+("-"===e.slice(0,1)?1:0))),o.numeralThousandsGroupStyle){case r.groupStyle.lakh:n=n.replace(/(\d)(?=(\d\d)+\d$)/g,"$1"+o.delimiter);break;case r.groupStyle.wan:n=n.replace(/(\d)(?=(\d{4})+$)/g,"$1"+o.delimiter);break;case r.groupStyle.thousand:n=n.replace(/(\d)(?=(\d{3})+$)/g,"$1"+o.delimiter)}return n.toString()+(o.numeralDecimalScale>0?i.toString():"")}},e.exports=r},function(e,t){"use strict";var r=function(e){var t=this;t.date=[],t.blocks=[],t.datePattern=e,t.initBlocks()};r.prototype={initBlocks:function(){var e=this;e.datePattern.forEach(function(t){"Y"===t?e.blocks.push(4):e.blocks.push(2)})},getISOFormatDate:function(){var e=this,t=e.date;return t[2]?t[2]+"-"+e.addLeadingZero(t[1])+"-"+e.addLeadingZero(t[0]):""},getBlocks:function(){return this.blocks},getValidatedDate:function(e){var t=this,r="";return e=e.replace(/[^\d]/g,""),t.blocks.forEach(function(n,o){if(e.length>0){var i=e.slice(0,n),a=i.slice(0,1),s=e.slice(n);switch(t.datePattern[o]){case"d":"00"===i?i="01":parseInt(a,10)>3?i="0"+a:parseInt(i,10)>31&&(i="31");break;case"m":"00"===i?i="01":parseInt(a,10)>1?i="0"+a:parseInt(i,10)>12&&(i="12")}r+=i,e=s}}),this.getFixedDateString(r)},getFixedDateString:function(e){var t,r,n,o=this,i=o.datePattern,a=[],s=0,c=0,u=0,l=0,p=0,d=0;return 4===e.length&&"y"!==i[0].toLowerCase()&&"y"!==i[1].toLowerCase()&&(l="d"===i[0]?0:2,p=2-l,t=parseInt(e.slice(l,l+2),10),r=parseInt(e.slice(p,p+2),10),a=this.getFixedDate(t,r,0)),8===e.length&&(i.forEach(function(e,t){switch(e){case"d":s=t;break;case"m":c=t;break;default:u=t}}),d=2*u,l=s<=u?2*s:2*s+2,p=c<=u?2*c:2*c+2,t=parseInt(e.slice(l,l+2),10),r=parseInt(e.slice(p,p+2),10),n=parseInt(e.slice(d,d+4),10),a=this.getFixedDate(t,r,n)),o.date=a,0===a.length?e:i.reduce(function(e,t){switch(t){case"d":return e+o.addLeadingZero(a[0]);case"m":return e+o.addLeadingZero(a[1]);default:return e+""+(a[2]||"")}},"")},getFixedDate:function(e,t,r){return e=Math.min(e,31),t=Math.min(t,12),r=parseInt(r||0,10),(t<7&&t%2===0||t>8&&t%2===1)&&(e=Math.min(e,2===t?this.isLeapYear(r)?29:28:30)),[e,t,r]},isLeapYear:function(e){return e%4===0&&e%100!==0||e%400===0},addLeadingZero:function(e){return(e<10?"0":"")+e}},e.exports=r},function(e,t){"use strict";var r=function(e,t){var r=this;r.delimiter=t||""===t?t:" ",r.delimiterRE=t?new RegExp("\\"+t,"g"):"",r.formatter=e};r.prototype={setFormatter:function(e){this.formatter=e},format:function(e){var t=this;t.formatter.clear(),e=e.replace(/[^\d+]/g,""),e=e.replace(t.delimiterRE,"");for(var r,n="",o=!1,i=0,a=e.length;i0;return 0===r?e:(t.forEach(function(t,c){if(e.length>0){var u=e.slice(0,t),l=e.slice(t);a+=u,i=s?o[c]||i:n,u.length===t&&c0?t.numeralIntegerScale:0,e.numeralDecimalScale=t.numeralDecimalScale>=0?t.numeralDecimalScale:2,e.numeralDecimalMark=t.numeralDecimalMark||".",e.numeralThousandsGroupStyle=t.numeralThousandsGroupStyle||"thousand",e.numeralPositiveOnly=!!t.numeralPositiveOnly,e.stripLeadingZeroes=void 0==t.stripLeadingZeroes||t.stripLeadingZeroes,e.numericOnly=e.creditCard||e.date||!!t.numericOnly,e.uppercase=!!t.uppercase,e.lowercase=!!t.lowercase,e.prefix=e.creditCard||e.date?"":t.prefix||"",e.noImmediatePrefix=!!t.noImmediatePrefix,e.prefixLength=e.prefix.length,e.rawValueTrimPrefix=!!t.rawValueTrimPrefix,e.copyDelimiter=!!t.copyDelimiter,e.initValue=void 0!==t.initValue&&null!==t.initValue?t.initValue.toString():"",e.delimiter=t.delimiter||""===t.delimiter?t.delimiter:t.date?"/":t.numeral?",":(t.phone," "),e.delimiterLength=e.delimiter.length,e.delimiters=t.delimiters||[],e.blocks=t.blocks||[],e.blocksLength=e.blocks.length,e.root="object"===("undefined"==typeof global?"undefined":r(global))&&global?global:window,e.maxLength=0,e.backspace=!1,e.result="",e}};e.exports=n}])}); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.Cleave=t(require("react")):e.Cleave=t(e.React)}(this,function(e){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function r(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}var o=Object.assign||function(e){for(var t=1;t0?p.headStr(e,r.maxLength):e,r.result=p.getFormattedValue(e,r.blocks,r.blocksLength,r.delimiter,r.delimiters),void n.updateValueState()):(r.result=e,void n.updateValueState()))},updateCreditCardPropsByValue:function(e){var t,n=this,r=n.properties;p.headStr(r.result,4)!==p.headStr(e,4)&&(t=l.getInfo(e,r.creditCardStrictMode),r.blocks=t.blocks,r.blocksLength=r.blocks.length,r.maxLength=p.getMaxLength(r.blocks),r.creditCardType!==t.type&&(r.creditCardType=t.type,r.onCreditCardTypeChanged.call(n,r.creditCardType)))},getNextCursorPosition:function(e,t,n){return t.length===e?n.length:e},setCurrentSelection:function(e){var t=this.element;if(this.setState({updateCursorPosition:!1}),t===document.activeElement)if(t.createTextRange){var n=t.createTextRange();n.move("character",e),n.select()}else t.setSelectionRange(e,e)},updateValueState:function(){var e=this,t=e.element.selectionEnd,n=e.element.value,r=e.properties.result,o=e.getNextCursorPosition(t,n,r);return e.lastInputValue=e.properties.result,e.isAndroid?void window.setTimeout(function(){e.setState({value:e.properties.result,cursorPosition:o,updateCursorPosition:!0})},1):void e.setState({value:e.properties.result,cursorPosition:o,updateCursorPosition:!0})},render:function(){var e=this,t=e.props,n=(t.value,t.options,t.onKeyDown,t.onFocus,t.onBlur,t.onChange,t.onInit,t.htmlRef),a=r(t,["value","options","onKeyDown","onFocus","onBlur","onChange","onInit","htmlRef"]);return i.createElement("input",o({type:"text",ref:function(t){e.element=t,n&&n.apply(this,arguments)},value:e.state.value,onKeyDown:e.onKeyDown,onChange:e.onChange,onFocus:e.onFocus,onBlur:e.onBlur},a))}});e.exports=m},function(t,n){t.exports=e},function(e,t,n){"use strict";var r=n(1),o=n(3);if("undefined"==typeof r)throw Error("create-react-class could not find the React object. If you are using script tags, make sure that React is being loaded before create-react-class.");var i=(new r.Component).updater;e.exports=o(r.Component,r.isValidElement,i)},function(e,t,n){(function(t){"use strict";function r(e){return e}function o(e,n,o){function p(e,n,r){for(var o in n)n.hasOwnProperty(o)&&"production"!==t.env.NODE_ENV&&u("function"==typeof n[o],"%s: %s type `%s` is invalid; it must be a function, usually from React.PropTypes.",e.displayName||"ReactClass",c[r],o)}function d(e,t){var n=x.hasOwnProperty(t)?x[t]:null;I.hasOwnProperty(t)&&s("OVERRIDE_BASE"===n,"ReactClassInterface: You are attempting to override `%s` from your class specification. Ensure that your method names do not overlap with React methods.",t),e&&s("DEFINE_MANY"===n||"DEFINE_MANY_MERGED"===n,"ReactClassInterface: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.",t)}function m(e,r){if(r){s("function"!=typeof r,"ReactClass: You're attempting to use a component class or function as a mixin. Instead, just use a regular object."),s(!n(r),"ReactClass: You're attempting to use a component as a mixin. Instead, just use a regular object.");var o=e.prototype,i=o.__reactAutoBindPairs;r.hasOwnProperty(l)&&w.mixins(e,r.mixins);for(var a in r)if(r.hasOwnProperty(a)&&a!==l){var c=r[a],p=o.hasOwnProperty(a);if(d(p,a),w.hasOwnProperty(a))w[a](e,c);else{var m=x.hasOwnProperty(a),f="function"==typeof c,h=f&&!m&&!p&&r.autobind!==!1;if(h)i.push(a,c),o[a]=c;else if(p){var v=x[a];s(m&&("DEFINE_MANY_MERGED"===v||"DEFINE_MANY"===v),"ReactClass: Unexpected spec policy %s for key %s when mixing in component specs.",v,a),"DEFINE_MANY_MERGED"===v?o[a]=g(o[a],c):"DEFINE_MANY"===v&&(o[a]=y(o[a],c))}else o[a]=c,"production"!==t.env.NODE_ENV&&"function"==typeof c&&r.displayName&&(o[a].displayName=r.displayName+"_"+a)}}}else if("production"!==t.env.NODE_ENV){var E=typeof r,D="object"===E&&null!==r;"production"!==t.env.NODE_ENV&&u(D,"%s: You're attempting to include a mixin that is either null or not an object. Check the mixins included by the component, as well as any mixins they include themselves. Expected object but got %s.",e.displayName||"ReactClass",null===r?null:E)}}function f(e,t){if(t)for(var n in t){var r=t[n];if(t.hasOwnProperty(n)){var o=n in w;s(!o,'ReactClass: You are attempting to define a reserved property, `%s`, that shouldn\'t be on the "statics" key. Define it as an instance property instead; it will still be accessible on the constructor.',n);var i=n in e;s(!i,"ReactClass: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.",n),e[n]=r}}}function h(e,t){s(e&&t&&"object"==typeof e&&"object"==typeof t,"mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.");for(var n in t)t.hasOwnProperty(n)&&(s(void 0===e[n],"mergeIntoWithNoDuplicateKeys(): Tried to merge two objects with the same key: `%s`. This conflict may be due to a mixin; in particular, this may be caused by two getInitialState() or getDefaultProps() methods returning objects with clashing keys.",n),e[n]=t[n]);return e}function g(e,t){return function(){var n=e.apply(this,arguments),r=t.apply(this,arguments);if(null==n)return r;if(null==r)return n;var o={};return h(o,n),h(o,r),o}}function y(e,t){return function(){e.apply(this,arguments),t.apply(this,arguments)}}function v(e,n){var r=n.bind(e);if("production"!==t.env.NODE_ENV){r.__reactBoundContext=e,r.__reactBoundMethod=n,r.__reactBoundArguments=null;var o=e.constructor.displayName,i=r.bind;r.bind=function(a){for(var s=arguments.length,c=Array(s>1?s-1:0),l=1;l1)for(var n=1;n1?t-1:0),r=1;r2?n-2:0),o=2;o0?t:0,u.numeralDecimalScale=n>=0?n:2,u.numeralThousandsGroupStyle=o||r.groupStyle.thousand,u.numeralPositiveOnly=!!i,u.stripLeadingZeroes=void 0==a||a,u.delimiter=s||""===s?s:",",u.delimiterRE=s?new RegExp("\\"+s,"g"):""};n.groupStyle={thousand:"thousand",lakh:"lakh",wan:"wan",none:"none"},n.prototype={getRawValue:function(e){return e.replace(this.delimiterRE,"").replace(this.numeralDecimalMark,".")},format:function(e){var t,r,o=this,i="";switch(e=e.replace(/[A-Za-z]/g,"").replace(o.numeralDecimalMark,"M").replace(/[^\dM-]/g,"").replace(/^\-/,"N").replace(/\-/g,"").replace("N",o.numeralPositiveOnly?"":"-").replace("M",o.numeralDecimalMark),o.stripLeadingZeroes&&(e=e.replace(/^(-)?0+(?=\d)/,"$1")),r=e,e.indexOf(o.numeralDecimalMark)>=0&&(t=e.split(o.numeralDecimalMark),r=t[0],i=o.numeralDecimalMark+t[1].slice(0,o.numeralDecimalScale)),o.numeralIntegerScale>0&&(r=r.slice(0,o.numeralIntegerScale+("-"===e.slice(0,1)?1:0))),o.numeralThousandsGroupStyle){case n.groupStyle.lakh:r=r.replace(/(\d)(?=(\d\d)+\d$)/g,"$1"+o.delimiter);break;case n.groupStyle.wan:r=r.replace(/(\d)(?=(\d{4})+$)/g,"$1"+o.delimiter);break;case n.groupStyle.thousand:r=r.replace(/(\d)(?=(\d{3})+$)/g,"$1"+o.delimiter)}return r.toString()+(o.numeralDecimalScale>0?i.toString():"")}},e.exports=n},function(e,t){"use strict";var n=function(e){var t=this;t.date=[],t.blocks=[],t.datePattern=e,t.initBlocks()};n.prototype={initBlocks:function(){var e=this;e.datePattern.forEach(function(t){"Y"===t?e.blocks.push(4):e.blocks.push(2)})},getISOFormatDate:function(){var e=this,t=e.date;return t[2]?t[2]+"-"+e.addLeadingZero(t[1])+"-"+e.addLeadingZero(t[0]):""},getBlocks:function(){return this.blocks},getValidatedDate:function(e){var t=this,n="";return e=e.replace(/[^\d]/g,""),t.blocks.forEach(function(r,o){if(e.length>0){var i=e.slice(0,r),a=i.slice(0,1),s=e.slice(r);switch(t.datePattern[o]){case"d":"00"===i?i="01":parseInt(a,10)>3?i="0"+a:parseInt(i,10)>31&&(i="31");break;case"m":"00"===i?i="01":parseInt(a,10)>1?i="0"+a:parseInt(i,10)>12&&(i="12")}n+=i,e=s}}),this.getFixedDateString(n)},getFixedDateString:function(e){var t,n,r,o=this,i=o.datePattern,a=[],s=0,u=0,c=0,l=0,p=0,d=0;return 4===e.length&&"y"!==i[0].toLowerCase()&&"y"!==i[1].toLowerCase()&&(l="d"===i[0]?0:2,p=2-l,t=parseInt(e.slice(l,l+2),10),n=parseInt(e.slice(p,p+2),10),a=this.getFixedDate(t,n,0)),8===e.length&&(i.forEach(function(e,t){switch(e){case"d":s=t;break;case"m":u=t;break;default:c=t}}),d=2*c,l=s<=c?2*s:2*s+2,p=u<=c?2*u:2*u+2,t=parseInt(e.slice(l,l+2),10),n=parseInt(e.slice(p,p+2),10),r=parseInt(e.slice(d,d+4),10),a=this.getFixedDate(t,n,r)),o.date=a,0===a.length?e:i.reduce(function(e,t){switch(t){case"d":return e+o.addLeadingZero(a[0]);case"m":return e+o.addLeadingZero(a[1]);default:return e+""+(a[2]||"")}},"")},getFixedDate:function(e,t,n){return e=Math.min(e,31),t=Math.min(t,12),n=parseInt(n||0,10),(t<7&&t%2===0||t>8&&t%2===1)&&(e=Math.min(e,2===t?this.isLeapYear(n)?29:28:30)),[e,t,n]},isLeapYear:function(e){return e%4===0&&e%100!==0||e%400===0},addLeadingZero:function(e){return(e<10?"0":"")+e}},e.exports=n},function(e,t){"use strict";var n=function(e,t){var n=this;n.delimiter=t||""===t?t:" ",n.delimiterRE=t?new RegExp("\\"+t,"g"):"",n.formatter=e};n.prototype={setFormatter:function(e){this.formatter=e},format:function(e){var t=this;t.formatter.clear(),e=e.replace(/[^\d+]/g,""),e=e.replace(t.delimiterRE,"");for(var n,r="",o=!1,i=0,a=e.length;i0;return 0===n?e:(t.forEach(function(t,u){if(e.length>0){var c=e.slice(0,t),l=e.slice(t);a+=c,i=s?o[u]||i:r,c.length===t&&u0?r.numeralIntegerScale:0,e.numeralDecimalScale=r.numeralDecimalScale>=0?r.numeralDecimalScale:2,e.numeralDecimalMark=r.numeralDecimalMark||".",e.numeralThousandsGroupStyle=r.numeralThousandsGroupStyle||"thousand",e.numeralPositiveOnly=!!r.numeralPositiveOnly,e.stripLeadingZeroes=void 0==r.stripLeadingZeroes||r.stripLeadingZeroes,e.numericOnly=e.creditCard||e.date||!!r.numericOnly,e.uppercase=!!r.uppercase,e.lowercase=!!r.lowercase,e.prefix=e.creditCard||e.date?"":r.prefix||"",e.noImmediatePrefix=!!r.noImmediatePrefix,e.prefixLength=e.prefix.length,e.rawValueTrimPrefix=!!r.rawValueTrimPrefix,e.copyDelimiter=!!r.copyDelimiter,e.initValue=void 0!==r.initValue&&null!==r.initValue?r.initValue.toString():"",e.delimiter=r.delimiter||""===r.delimiter?r.delimiter:r.date?"/":r.numeral?",":(r.phone," "),e.delimiterLength=e.delimiter.length,e.delimiters=r.delimiters||[],e.blocks=r.blocks||[],e.blocksLength=e.blocks.length,e.root="object"===("undefined"==typeof t?"undefined":n(t))&&t?t:window,e.maxLength=0,e.backspace=!1,e.result="",e}};e.exports=r}).call(t,function(){return this}())}])}); \ No newline at end of file diff --git a/dist/cleave.min.js b/dist/cleave.min.js index e270868b..75e13983 100644 --- a/dist/cleave.min.js +++ b/dist/cleave.min.js @@ -1,5 +1,5 @@ /*! - * cleave.js - 1.0.7 + * cleave.js - 1.0.9 * https://github.com/nosir/cleave.js * Apache License Version 2.0 * diff --git a/gulp-tasks/build.js b/gulp-tasks/build.js index 8c4fbf1d..2cbf67c6 100644 --- a/gulp-tasks/build.js +++ b/gulp-tasks/build.js @@ -26,6 +26,7 @@ var paths = { gulp.task('min-mangle', function () { return gulp.src([ path.join(paths.dist, 'cleave.js'), + path.join(paths.dist, 'cleave-react-node.js'), path.join(paths.dist, 'cleave-react.js') ]) .pipe(uglify({mangle: true})) @@ -65,6 +66,7 @@ gulp.task('build', gulpsync.sync([ // sync 'js:vanilla', 'js:react', + 'js:react-node', 'js:angular', [ // async diff --git a/gulp-tasks/webpack.js b/gulp-tasks/webpack.js index fb49817b..12bdf6f0 100644 --- a/gulp-tasks/webpack.js +++ b/gulp-tasks/webpack.js @@ -5,58 +5,76 @@ var path = require('path'); var paths = { root: './', dist: './dist/', - src: './src/' + src: './src/' }; gulp.task('js:vanilla', function () { return gulp.src(path.join(paths.src + 'Cleave.js')) .pipe(webpack({ output: { - library: 'Cleave', + library: 'Cleave', libraryTarget: 'umd', - filename: 'cleave.js' + filename: 'cleave.js' } })) .pipe(gulp.dest(paths.dist)); }); -gulp.task('js:react', function () { +var module = { + loaders: [ + { + test: /\.(js|jsx)$/, + exclude: /node_modules/, + loader: 'babel', + query: { + presets: ['es2015', 'react', 'stage-0'] + } + } + ] +}; + +var externals = [ + { + 'react': { + root: 'React', + commonjs2: 'react', + commonjs: 'react', + amd: 'react' + }, + 'react-dom': { + root: 'ReactDOM', + commonjs2: 'react-dom', + commonjs: 'react-dom', + amd: 'react-dom' + } + } +]; + +gulp.task('js:react-node', function () { return gulp.src(path.join(paths.src, 'Cleave.react.js')) .pipe(webpack({ - output: { - library: 'Cleave', + output: { + library: 'Cleave', libraryTarget: 'umd', - filename: 'cleave-react.js' + filename: 'cleave-react-node.js' }, target: 'node', - module: { - loaders: [ - { - test: /\.(js|jsx)$/, - exclude: /node_modules/, - loader: 'babel', - query: { - presets: ['es2015', 'react', 'stage-0'] - } - } - ] + module: module, + externals: externals + })) + .pipe(gulp.dest(paths.dist)); +}); + +gulp.task('js:react', function () { + return gulp.src(path.join(paths.src, 'Cleave.react.js')) + .pipe(webpack({ + output: { + library: 'Cleave', + libraryTarget: 'umd', + filename: 'cleave-react.js' }, - externals: [ - { - 'react': { - root: 'React', - commonjs2: 'react', - commonjs: 'react', - amd: 'react' - }, - 'react-dom': { - root: 'ReactDOM', - commonjs2: 'react-dom', - commonjs: 'react-dom', - amd: 'react-dom' - } - } - ] + module: module, + externals: externals })) .pipe(gulp.dest(paths.dist)); }); diff --git a/package.json b/package.json index ba727f9b..7a8e9d2d 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "form", "input" ], - "version": "1.0.8", + "version": "1.0.9", "author": { "name": "Max Huang", "url": "http://github.com/nosir", diff --git a/react.js b/react.js index 6f447229..246e39a9 100644 --- a/react.js +++ b/react.js @@ -1 +1 @@ -module.exports = require('./dist/cleave-react.js'); +module.exports = require('./dist/cleave-react-node.js');