UNPKG

5.35 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../src/index.js"],"names":["DEFAULT_DELAY","debounceTimeout","getEventValue","target","value","event","undefined","EMPTY_VALUE","debounceInputDecorator","delay","props","state","_notify","onChange","setState","_onBlur","flush","onBlur","_onChange","persist","_onKeyDown","key","onKeyDown","_wrappedInstance","_onRef","ref","componentWillReceiveProps","cancel","componentWillUnmount","getWrappedInstance","render","Object","assign","React","createElement","Input","Component","Textarea"],"mappings":";;;;;AAAA;;AACA;;;;;;AAEA,IAAMA,gBAAgB,SAAhBA,aAAgB;AAAA,kCAAGC,eAAH;AAAA,MAAGA,eAAH,qCAAqB,GAArB;AAAA,SAA+BA,eAA/B;AAAA,CAAtB;;AAEA,IAAMC,gBAAgB,SAAhBA,aAAgB,QAAS;AAC7B,MAAIC,MAAJ,EAAYC,KAAZ;AACA,SACEC,SAAS,IAAT,IACA,CAACF,SAASE,MAAMF,MAAhB,KAA2B,IAD3B,IAEA,CAACC,QAAQD,OAAOC,KAAhB,MAA2BE,SAHtB,GAIHF,KAJG,GAIKC,KAJZ;AAKD,CAPD;;AASA,IAAME,cAAc;AAAEH,SAAOE;AAAT,CAApB;;AAEA,IAAME,yBAAyB,SAAzBA,sBAAyB,CAACC,KAAD;AAAA,MAACA,KAAD;AAACA,SAAD,GAAST,aAAT;AAAA;;AAAA,SAA2B;AAAA;AAAA;;AAEtD,8BAAaU,KAAb,EAAoB;AAAA;;AAClB;AACA,cAAKC,KAAL,GAAa,EAAb;AAEA,cAAKC,OAAL,GAAe,uBAAS,iBAAS;AAC/B,gBAAKF,KAAL,CAAWG,QAAX,CAAoBR,KAApB;;AACA,gBAAKS,QAAL,CAAcP,WAAd;AACD,SAHc,EAGZ,OAAOE,KAAP,KAAiB,UAAjB,GAA8BA,MAAMC,KAAN,CAA9B,GAA6CD,KAHjC,CAAf;;AAKA,cAAKM,OAAL,GAAe,iBAAS;AACtB,gBAAKH,OAAL,CAAaI,KAAb;;AADsB,cAEdC,MAFc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kB,KAAKtB,KAAvB,EAA8B;AAC1CO,kBAAQ,KAAKF,OAD6B;AAE1CF,oBAAU,KAAKK,SAF2B;AAG1CI,qBAAW,KAAKF,UAH0B;AAI1CK,eAAK,KAAKD;AAJgC,SAA9B,CAAd;AAMA,eAAOd,MAAMT,eAAb;AAPQ,YAQAG,KARA,GAQU,KAAKO,KARf,CAQAP,KARA;;AASR,YAAIA,UAAUE,SAAd,EAAyB;AACvBI,gBAAMN,KAAN,GAAcA,KAAd;AACD;;AACD,eAAO6B,eAAMC,aAAN,CAAoBC,KAApB,EAA2BzB,KAA3B,CAAP;AACD,OAxEqD;;AAAA;AAAA,MAC3BuB,eAAMG,SADqB;AAAA,GAA3B;AAAA,CAA/B;;;AA6EO,IAAMD,QAAQ3B,yBAAyB,OAAzB,CAAd;;AACA,IAAM6B,WAAW7B,yBAAyB,UAAzB,CAAjB","sourcesContent":["import debounce from 'lodash/debounce'\nimport React from 'react'\n\nconst DEFAULT_DELAY = ({ debounceTimeout = 250 }) => debounceTimeout\n\nconst getEventValue = event => {\n let target, value\n return (\n event != null &&\n (target = event.target) != null &&\n (value = target.value) !== undefined\n ) ? value : event\n}\n\nconst EMPTY_VALUE = { value: undefined }\n\nconst debounceInputDecorator = (delay = DEFAULT_DELAY) => Input =>\n class DebouncedInput extends React.Component {\n constructor (props) {\n super()\n this.state = {}\n\n this._notify = debounce(event => {\n this.props.onChange(event)\n this.setState(EMPTY_VALUE)\n }, typeof delay === 'function' ? delay(props) : delay)\n\n this._onBlur = event => {\n this._notify.flush()\n const { onBlur } = this.props\n if (onBlur !== undefined) {\n onBlur(event)\n }\n }\n\n this._onChange = event => {\n this.setState({ value: getEventValue(event) })\n\n if (event != null && typeof event.persist === 'function') {\n event.persist()\n }\n this._notify(event)\n }\n\n this._onKeyDown = event => {\n if (event != null && event.key === 'Enter') {\n this._notify.flush()\n }\n const { onKeyDown } = this.props\n if (onKeyDown !== undefined) {\n onKeyDown(event)\n }\n }\n\n this._wrappedInstance = null\n this._onRef = ref => {\n this._wrappedInstance = ref\n }\n }\n\n componentWillReceiveProps ({ value }) {\n if (value !== this.props.value) {\n this._notify.cancel()\n this.setState(EMPTY_VALUE)\n }\n }\n\n componentWillUnmount () {\n this._notify.flush()\n }\n\n getWrappedInstance () {\n return this._wrappedInstance\n }\n\n render () {\n const props = Object.assign({}, this.props, {\n onBlur: this._onBlur,\n onChange: this._onChange,\n onKeyDown: this._onKeyDown,\n ref: this._onRef,\n })\n delete props.debounceTimeout\n const { value } = this.state\n if (value !== undefined) {\n props.value = value\n }\n return React.createElement(Input, props)\n }\n }\nexport { debounceInputDecorator as default }\n\n// common components\nexport const Input = debounceInputDecorator()('input')\nexport const Textarea = debounceInputDecorator()('textarea')\n"],"file":"index.js"}
\No newline at end of file