From f52e9bfbe8123bdb012f1ad65e344dbebf53dac6 Mon Sep 17 00:00:00 2001 From: nutboltu Date: Mon, 5 Jul 2021 22:18:31 +1000 Subject: [PATCH 1/3] feat: refactor the class component with functional component and hooks --- .eslintrc | 3 +- package.json | 6 +- src/components/SearchField.jsx | 141 +++++++++++++++------------------ tests/SearchField.test.jsx | 2 +- yarn.lock | 27 +++---- 5 files changed, 83 insertions(+), 96 deletions(-) diff --git a/.eslintrc b/.eslintrc index e509776..4263973 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,7 +9,8 @@ }, "env": { "browser": true, - "es6": true + "es6": true, + "jest": true }, "plugins": [ "react" diff --git a/package.json b/package.json index a77f1c6..7bacd89 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-search-field", - "version": "1.2.1", + "version": "2.0.0", "description": "This is a simple search field component for react", "main": "dist/index.min.js", "scripts": { @@ -25,8 +25,8 @@ }, "dependencies": { "prop-types": "15.7.2", - "react": "16.6.3", - "react-dom": "16.6.3", + "react": "16.9.0", + "react-dom": "16.9.0", "react-github-btn": "1.2.0", "typeco": "1.0.0" }, diff --git a/src/components/SearchField.jsx b/src/components/SearchField.jsx index 5c37827..bd05a3e 100644 --- a/src/components/SearchField.jsx +++ b/src/components/SearchField.jsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState, useEffect, useCallback } from 'react'; import PropTypes from 'prop-types'; import TypeChecker from 'typeco'; @@ -63,90 +63,77 @@ const SearchIcon = () => { ); }; -class SearchField extends React.Component { - constructor(props) { - super(props); - this.state = { - value: this.props.searchText, - }; - - this.onChangeBound = this.onChangeBound.bind(this); - this.onEnterBound = this.onEnterBound.bind(this); - this.onSearchClick = this.onSearchClick.bind(this); - this.onBlurBound = this.onBlurBound.bind(this); - } - - componentWillReceiveProps(nextProps) { - if (this.props.searchText !== nextProps.searchText) { - this.setState({ - value: nextProps.searchText, - }); +const SearchField = ({ + classNames, + searchText, + placeholder, + onChange, + onEnter, + onSearchClick, + onBlur, +}) => { + const [value, setValue] = useState(searchText); + + useEffect(() => { + setValue(searchText); + }, [searchText, setValue]); + + const onChangeHandler = useCallback((event) => { + setValue(event.target.value); + if (TypeChecker.isFunction(onChange)) { + onChange(event.target.value, event); } - } - - onChangeBound(event) { - this.setState({ - value: event.target.value, - }); - if (TypeChecker.isFunction(this.props.onChange)) { - this.props.onChange(event.target.value, event); - } - } + }, [onChange, setValue]); - onEnterBound(event) { - const isEnterPressed = event.which === ENTER_KEY || event.keyCode === ENTER_KEY; - if (isEnterPressed && TypeChecker.isFunction(this.props.onEnter)) { - this.props.onEnter(event.target.value, event); + const onEnterHandler = useCallback((event) => { + const isEnterPressed = event.which === ENTER_KEY || + event.keyCode === ENTER_KEY; + if (isEnterPressed && TypeChecker.isFunction(onEnter)) { + onEnter(event.target.value, event); } - } + }, [onEnter]); - onSearchClick() { - if (TypeChecker.isFunction(this.props.onSearchClick)) { - this.props.onSearchClick(this.state.value); + const onSearchClickHandler = useCallback(() => { + if (TypeChecker.isFunction(onSearchClick)) { + onSearchClick(value); } - } + }, [onSearchClick]); - onBlurBound(event) { - if (TypeChecker.isFunction(this.props.onBlur)) { - this.props.onBlur(event.target.value, event); + const onBlurHandler = useCallback((event) => { + if (TypeChecker.isFunction(onBlur)) { + onBlur(event.target.value, event); } - } - - render() { - const { - classNames, - placeholder, - } = this.props; - const className = `react-search-field ${classNames}`; - - return ( -
+ + -
- ); - } -} + + + + ); +}; SearchField.propTypes = { classNames: PropTypes.string, diff --git a/tests/SearchField.test.jsx b/tests/SearchField.test.jsx index f6c5283..2faae5a 100644 --- a/tests/SearchField.test.jsx +++ b/tests/SearchField.test.jsx @@ -15,7 +15,7 @@ describe('', () => { it('should render searchText', () => { const searchText = 'testSearchText'; const component = shallow(); - expect(component.children().at(0).props().value).toEqual(searchText); + expect(component.find('input').props().value).toEqual(searchText); }); it('should render search button', () => { const component = shallow(); diff --git a/yarn.lock b/yarn.lock index 117b8b2..34cf391 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6828,15 +6828,15 @@ rc@^1.2.7: minimist "^1.2.0" strip-json-comments "~2.0.1" -react-dom@16.6.3: - version "16.6.3" - resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.6.3.tgz#8fa7ba6883c85211b8da2d0efeffc9d3825cccc0" - integrity sha512-8ugJWRCWLGXy+7PmNh8WJz3g1TaTUt1XyoIcFN+x0Zbkoz+KKdUyx1AQLYJdbFXjuF41Nmjn5+j//rxvhFjgSQ== +react-dom@16.9.0: + version "16.9.0" + resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.9.0.tgz#5e65527a5e26f22ae3701131bcccaee9fb0d3962" + integrity sha512-YFT2rxO9hM70ewk9jq0y6sQk8cL02xm4+IzYBz75CQGlClQQ1Bxq0nhHF6OtSbit+AIahujJgb/CPRibFkMNJQ== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1" prop-types "^15.6.2" - scheduler "^0.11.2" + scheduler "^0.15.0" react-github-btn@1.2.0: version "1.2.0" @@ -6871,15 +6871,14 @@ react-test-renderer@^16.0.0-0: react-is "^16.8.6" scheduler "^0.18.0" -react@16.6.3: - version "16.6.3" - resolved "https://registry.yarnpkg.com/react/-/react-16.6.3.tgz#25d77c91911d6bbdd23db41e70fb094cc1e0871c" - integrity sha512-zCvmH2vbEolgKxtqXL2wmGCUxUyNheYn/C+PD1YAjfxHC54+MhdruyhO7QieQrYsYeTxrn93PM2y0jRH1zEExw== +react@16.9.0: + version "16.9.0" + resolved "https://registry.yarnpkg.com/react/-/react-16.9.0.tgz#40ba2f9af13bc1a38d75dbf2f4359a5185c4f7aa" + integrity sha512-+7LQnFBwkiw+BobzOF6N//BdoNw0ouwmSJTEm9cglOOmsg/TMiFHZLe2sEoN5M7LgJTj9oHH0gxklfnQe66S1w== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1" prop-types "^15.6.2" - scheduler "^0.11.2" read-pkg-up@^2.0.0: version "2.0.0" @@ -7298,10 +7297,10 @@ sax@^1.2.4: resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw== -scheduler@^0.11.2: - version "0.11.3" - resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.11.3.tgz#b5769b90cf8b1464f3f3cfcafe8e3cd7555a2d6b" - integrity sha512-i9X9VRRVZDd3xZw10NY5Z2cVMbdYg6gqFecfj79USv1CFN+YrJ3gIPRKf1qlY+Sxly4djoKdfx1T+m9dnRB8kQ== +scheduler@^0.15.0: + version "0.15.0" + resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.15.0.tgz#6bfcf80ff850b280fed4aeecc6513bc0b4f17f8e" + integrity sha512-xAefmSfN6jqAa7Kuq7LIJY0bwAPG3xlCj0HMEBQk1lxYiDKZscY2xJ5U/61ZTrYbmNQbXa+gc7czPkVo11tnCg== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1" From 5521e014a83e06bac365e16d83a6f6a084cc1ecf Mon Sep 17 00:00:00 2001 From: nutboltu Date: Mon, 5 Jul 2021 23:13:10 +1000 Subject: [PATCH 2/3] chore: build docs and the component --- README.md | 2 +- dist/index.min.js | 2 +- docs/bundle.min.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d15f857..a7ee66c 100644 --- a/README.md +++ b/README.md @@ -54,4 +54,4 @@ npm start ## License -MIT Licensed. Copyright (c) Farhad Yasir 2018. +MIT Licensed. Copyright (c) Farhad Yasir 2021. diff --git a/dist/index.min.js b/dist/index.min.js index 8e11805..0973c2d 100644 --- a/dist/index.min.js +++ b/dist/index.min.js @@ -1 +1 @@ -!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.ReactSearch=t(require("react")):e.ReactSearch=t(e.react)}(this,(function(e){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=3)}([function(t,n){t.exports=e},function(e,t,n){e.exports=n(4)()},function(e,t,n){"use strict";const r=e=>Object.prototype.toString.call(e).slice(8,-1),o=e=>"Array"===r(e),a=e=>"Object"===r(e),i=e=>"String"===r(e),c=e=>"Number"===r(e)&&!Number.isNaN(e),u=e=>"Null"===r(e)||"Undefined"===r(e),s=e=>i(e)?""===e.trim():o(e)?0===e.length:a(e)?0===Object.keys(e).length:u(e);e.exports={isArray:o,isObject:a,isString:i,isDate:e=>"Date"===r(e),isRegExp:e=>"RegExp"===r(e),isFunction:e=>"Function"===r(e),isBoolean:e=>"Boolean"===r(e)||i(e)&&("true"===e||"false"===e),isNumber:c,isNull:u,isEmpty:s,isEmptyOrZero:e=>s(e)||c(e)&&0===e}},function(e,t,n){"use strict";n.r(t);var r=n(0),o=n.n(r),a=n(1),i=n.n(a),c=n(2),u=n.n(c);function s(e){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function l(e,t){for(var n=0;nObject.prototype.toString.call(e).slice(8,-1),o=e=>"Array"===r(e),a=e=>"Object"===r(e),c=e=>"String"===r(e),i=e=>"Number"===r(e)&&!Number.isNaN(e),l=e=>"Null"===r(e)||"Undefined"===r(e),u=e=>c(e)?""===e.trim():o(e)?0===e.length:a(e)?0===Object.keys(e).length:l(e);e.exports={isArray:o,isObject:a,isString:c,isDate:e=>"Date"===r(e),isRegExp:e=>"RegExp"===r(e),isFunction:e=>"Function"===r(e),isBoolean:e=>"Boolean"===r(e)||c(e)&&("true"===e||"false"===e),isNumber:i,isNull:l,isEmpty:u,isEmptyOrZero:e=>u(e)||i(e)&&0===e}},function(e,t,n){"use strict";n.r(t);var r=n(0),o=n.n(r),a=n(1),c=n.n(a),i=n(2),l=n.n(i);var u={border:"1px #ddd solid",display:"inline-flex",justifyContent:"space-between",height:35},s={height:33,width:33,outline:"none",backgroundColor:"white",cursor:"pointer",padding:5,boxSizing:"border-box",appearance:"none",border:"none",borderLeft:"1px #ddd solid"},f={outline:"none",border:"none",fontSize:14,padding:10,flex:1,color:"#5a5a5a",fontWeight:100,height:33},p=function(){var e=Math.ceil(21);return o.a.createElement("svg",{version:"1.1",x:"0px",y:"0px",width:e,height:e,viewBox:"0 0 635 635",style:{fill:"#727272"}},o.a.createElement("g",null,o.a.createElement("path",{d:"M255.108,0C119.863,0,10.204,109.66,10.204,244.904c0,135.245,109.659,244.905,244.904,244.905 c52.006,0,100.238-16.223,139.883-43.854l185.205,185.176c1.671,1.672,4.379,1.672,5.964,0.115l34.892-34.891 c1.613-1.613,1.47-4.379-0.115-5.965L438.151,407.605c38.493-43.246,61.86-100.237,61.86-162.702 C500.012,109.66,390.353,0,255.108,0z M255.108,460.996c-119.34,0-216.092-96.752-216.092-216.092 c0-119.34,96.751-216.091,216.092-216.091s216.091,96.751,216.091,216.091C471.199,364.244,374.448,460.996,255.108,460.996z"})))},d=function(e){var t=e.classNames,n=e.searchText,a=e.placeholder,c=e.onChange,i=e.onEnter,d=e.onSearchClick,b=e.onBlur,y=function(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var n=[],r=!0,o=!1,a=void 0;try{for(var c,i=e[Symbol.iterator]();!(r=(c=i.next()).done)&&(n.push(c.value),!t||n.length!==t);r=!0);}catch(e){o=!0,a=e}finally{try{r||null==i.return||i.return()}finally{if(o)throw a}}return n}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}(Object(r.useState)(n),2),h=y[0],g=y[1];Object(r.useEffect)((function(){g(n)}),[n,g]);var m=Object(r.useCallback)((function(e){g(e.target.value),l.a.isFunction(c)&&c(e.target.value,e)}),[c,g]),v=Object(r.useCallback)((function(e){(13===e.which||13===e.keyCode)&&l.a.isFunction(i)&&i(e.target.value,e)}),[i]),x=Object(r.useCallback)((function(){l.a.isFunction(d)&&d(h)}),[d]),O=Object(r.useCallback)((function(e){l.a.isFunction(b)&&b(e.target.value,e)}),[b]),j="react-search-field ".concat(t);return o.a.createElement("div",{className:j,style:u},o.a.createElement("input",{className:"react-search-field-input",style:f,onChange:m,onKeyPress:v,onBlur:O,placeholder:a,type:"text",value:h}),o.a.createElement("button",{className:"react-search-field-button",type:"button","aria-label":"search button",style:s,onClick:x},o.a.createElement(p,null)))};d.propTypes={classNames:c.a.string,searchText:c.a.string,placeholder:c.a.string,onChange:c.a.func,onEnter:c.a.func,onSearchClick:c.a.func,onBlur:c.a.func},d.defaultProps={classNames:"",searchText:"",placeholder:"Search",onChange:null,onEnter:null,onSearchClick:null,onBlur:null},t.default=d},function(e,t,n){"use strict";var r=n(5);function o(){}function a(){}a.resetWarningCache=o,e.exports=function(){function e(e,t,n,o,a,c){if(c!==r){var i=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw i.name="Invariant Violation",i}}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:a,resetWarningCache:o};return n.PropTypes=n,n}},function(e,t,n){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"}])})); \ No newline at end of file diff --git a/docs/bundle.min.js b/docs/bundle.min.js index 85ae007..259801e 100644 --- a/docs/bundle.min.js +++ b/docs/bundle.min.js @@ -1,2 +1,2 @@ /*! For license information please see bundle.min.js.LICENSE.txt */ -!function(e){var t={};function n(r){if(t[r])return t[r].exports;var a=t[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,n),a.l=!0,a.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(r,a,function(t){return e[t]}.bind(null,a));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=312)}([function(e,t,n){"use strict";e.exports=n(10)},function(e,t,n){e.exports=n(16)()},function(e,t,n){"use strict";const r=e=>Object.prototype.toString.call(e).slice(8,-1),a=e=>"Array"===r(e),o=e=>"Object"===r(e),i=e=>"String"===r(e),l=e=>"Number"===r(e)&&!Number.isNaN(e),s=e=>"Null"===r(e)||"Undefined"===r(e),c=e=>i(e)?""===e.trim():a(e)?0===e.length:o(e)?0===Object.keys(e).length:s(e);e.exports={isArray:a,isObject:o,isString:i,isDate:e=>"Date"===r(e),isRegExp:e=>"RegExp"===r(e),isFunction:e=>"Function"===r(e),isBoolean:e=>"Boolean"===r(e)||i(e)&&("true"===e||"false"===e),isNumber:l,isNull:s,isEmpty:c,isEmptyOrZero:e=>c(e)||l(e)&&0===e}},function(e,t,n){var r=n(216);e.exports=function(e){for(var t=1;t=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}},function(e,t){function n(){return e.exports=n=Object.assign||function(e){for(var t=1;tx.length&&x.push(e)}function L(e,t,n){return null==e?0:function e(t,n,r,a){var l=typeof t;"undefined"!==l&&"boolean"!==l||(t=null);var s=!1;if(null===t)s=!0;else switch(l){case"string":case"number":s=!0;break;case"object":switch(t.$$typeof){case o:case i:s=!0}}if(s)return r(a,t,""===n?"."+P(t,0):n),1;if(s=0,n=""===n?".":n+":",Array.isArray(t))for(var c=0;cthis.eventPool.length&&this.eventPool.push(e)}function ue(e){e.eventPool=[],e.getPooled=de,e.release=_e}a(ce.prototype,{preventDefault:function(){this.defaultPrevented=!0;var e=this.nativeEvent;e&&(e.preventDefault?e.preventDefault():"unknown"!=typeof e.returnValue&&(e.returnValue=!1),this.isDefaultPrevented=le)},stopPropagation:function(){var e=this.nativeEvent;e&&(e.stopPropagation?e.stopPropagation():"unknown"!=typeof e.cancelBubble&&(e.cancelBubble=!0),this.isPropagationStopped=le)},persist:function(){this.isPersistent=le},isPersistent:se,destructor:function(){var e,t=this.constructor.Interface;for(e in t)this[e]=null;this.nativeEvent=this._targetInst=this.dispatchConfig=null,this.isPropagationStopped=this.isDefaultPrevented=se,this._dispatchInstances=this._dispatchListeners=null}}),ce.Interface={type:null,target:null,currentTarget:function(){return null},eventPhase:null,bubbles:null,cancelable:null,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:null,isTrusted:null},ce.extend=function(e){function t(){}function n(){return r.apply(this,arguments)}var r=this;t.prototype=r.prototype;var o=new t;return a(o,n.prototype),n.prototype=o,n.prototype.constructor=n,n.Interface=a({},r.Interface,e),n.extend=r.extend,ue(n),n},ue(ce);var pe=ce.extend({data:null}),me=ce.extend({data:null}),ge=[9,13,27,32],Ee=W&&"CompositionEvent"in window,fe=null;W&&"documentMode"in document&&(fe=document.documentMode);var be=W&&"TextEvent"in window&&!fe,Se=W&&(!Ee||fe&&8=fe),he=String.fromCharCode(32),Te={beforeInput:{phasedRegistrationNames:{bubbled:"onBeforeInput",captured:"onBeforeInputCapture"},dependencies:["compositionend","keypress","textInput","paste"]},compositionEnd:{phasedRegistrationNames:{bubbled:"onCompositionEnd",captured:"onCompositionEndCapture"},dependencies:"blur compositionend keydown keypress keyup mousedown".split(" ")},compositionStart:{phasedRegistrationNames:{bubbled:"onCompositionStart",captured:"onCompositionStartCapture"},dependencies:"blur compositionstart keydown keypress keyup mousedown".split(" ")},compositionUpdate:{phasedRegistrationNames:{bubbled:"onCompositionUpdate",captured:"onCompositionUpdateCapture"},dependencies:"blur compositionupdate keydown keypress keyup mousedown".split(" ")}},Ce=!1;function ve(e,t){switch(e){case"keyup":return-1!==ge.indexOf(t.keyCode);case"keydown":return 229!==t.keyCode;case"keypress":case"mousedown":case"blur":return!0;default:return!1}}function ye(e){return"object"==typeof(e=e.detail)&&"data"in e?e.data:null}var Ne=!1,Oe={eventTypes:Te,extractEvents:function(e,t,n,r){var a=void 0,o=void 0;if(Ee)e:{switch(e){case"compositionstart":a=Te.compositionStart;break e;case"compositionend":a=Te.compositionEnd;break e;case"compositionupdate":a=Te.compositionUpdate;break e}a=void 0}else Ne?ve(e,n)&&(a=Te.compositionEnd):"keydown"===e&&229===n.keyCode&&(a=Te.compositionStart);return a?(Se&&"ko"!==n.locale&&(Ne||a!==Te.compositionStart?a===Te.compositionEnd&&Ne&&(o=ie()):(ae="value"in(re=r)?re.value:re.textContent,Ne=!0)),a=pe.getPooled(a,t,n,r),o?a.data=o:null!==(o=ye(n))&&(a.data=o),q(a),o=a):o=null,(e=be?function(e,t){switch(e){case"compositionend":return ye(t);case"keypress":return 32!==t.which?null:(Ce=!0,he);case"textInput":return(e=t.data)===he&&Ce?null:e;default:return null}}(e,n):function(e,t){if(Ne)return"compositionend"===e||!Ee&&ve(e,t)?(e=ie(),oe=ae=re=null,Ne=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1