UNPKG

@livelybone/react-input

Version:

A react input component, realized input validator, formatter. `textarea` available

10 lines (8 loc) 4.72 kB
/** * Bundle of @livelybone/react-input * Generated: 2020-05-26 * Version: 2.5.0 * License: MIT * Author: 2631541504@qq.com */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):(t=t||self).ReactInput=e(t.React)}(this,function(r){"use strict";function u(t,e){if(null==t)return{};var o,n,r=function(t,e){if(null==t)return{};var o,n,r={},i=Object.keys(t);for(n=0;n<i.length;n++)o=i[n],0<=e.indexOf(o)||(r[o]=t[o]);return r}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(n=0;n<i.length;n++)o=i[n],0<=e.indexOf(o)||Object.prototype.propertyIsEnumerable.call(t,o)&&(r[o]=t[o])}return r}function e(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),o.push.apply(o,n)}return o}function p(r){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?e(Object(i),!0).forEach(function(t){var e,o,n;e=r,n=i[o=t],o in e?Object.defineProperty(e,o,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[o]=n}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(i)):e(Object(i)).forEach(function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(i,t))})}return r}function a(t,e){for(var o=0;o<e.length;o++){var n=e[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function s(t,e){return(s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function i(t){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function c(t,e){return!e||"object"!==o(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function l(n){return function(){var t,e=i(n);if(function(){if("undefined"!=typeof Reflect&&Reflect.construct&&!Reflect.construct.sham){if("function"==typeof Proxy)return 1;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),1}catch(t){return}}}()){var o=i(this).constructor;t=Reflect.construct(e,arguments,o)}else t=e.apply(this,arguments);return c(this,t)}}return r=r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r,function(){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&s(t,e)}(i,r.Component);var t,e,o,n=l(i);function i(){var r;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,i);for(var t=arguments.length,e=new Array(t),o=0;o<t;o++)e[o]=arguments[o];return(r=n.call.apply(n,[this].concat(e))).isCompositionUpdate=!1,r.inputEl=void 0,r.onComposition=function(t,e){e.stopPropagation();var o=r.props[t];if(o&&o(e),r.isCompositionUpdate="onCompositionEnd"!==t,!r.isCompositionUpdate){var n=p({},e);setTimeout(function(){r.onChange(n)})}},r.onChange=function(t){r.props.onChange&&r.shouldCallChange&&r.props.onChange(t)},r}return t=i,(e=[{key:"componentDidUpdate",value:function(){this.shouldCallChange&&this.inputEl&&void 0!==this.props.value&&(this.inputEl.value=this.props.value)}},{key:"componentDidMount",value:function(){this.shouldCallChange&&this.inputEl&&this.props.value&&(this.inputEl.value=this.props.value)}},{key:"render",value:function(){var t=this.$props,e=this.props.type||"text";return"textarea"!==e?r.createElement("input",Object.assign({},t,{type:e})):r.createElement("textarea",t)}},{key:"$props",get:function(){var e=this,t=this.props,o=t.value,n=t.type,r=t.autoComplete;t.shouldCompositionEventTriggerChangeEvent;return p({},u(t,["value","type","autoComplete","shouldCompositionEventTriggerChangeEvent"]),{value:void 0,autoComplete:"password"===n&&"off"===r?"new-password":r,defaultValue:o,ref:function(t){e.inputEl=t},onChange:this.onChange,onCompositionEnd:this.onComposition.bind(this,"onCompositionEnd"),onCompositionStart:this.onComposition.bind(this,"onCompositionStart"),onCompositionUpdate:this.onComposition.bind(this,"onCompositionUpdate")})}},{key:"shouldCallChange",get:function(){return this.props.shouldCompositionEventTriggerChangeEvent||!this.isCompositionUpdate}}])&&a(t.prototype,e),o&&a(t,o),i}()});