Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-datalist-input

Package Overview
Dependencies
Maintainers
1
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-datalist-input - npm Package Compare versions

Comparing version 1.3.9 to 1.3.10

2

lib/DataListInput.js

@@ -1,1 +0,1 @@

module.exports=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=0)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r="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},o=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=s(n(1)),a=s(n(2));function s(e){return e&&e.__esModule?e:{default:e}}n(5);var u=function(e){function t(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var n=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));l.call(n);var r=n.props.initialValue;return n.state={lastValidItem:void 0,currentInput:r,matchingItems:[],visible:!1,focusIndex:0,interactionHappened:!1,isMatchingDebounced:!1},n.inputHappenedTimeout=void 0,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),o(t,[{key:"render",value:function(){var e=this.state,t=e.currentInput,n=e.matchingItems,r=e.focusIndex,o=e.visible,a=e.isMatchingDebounced,s=this.props,u=s.placeholder,l=s.inputClassName,c=s.activeItemClassName,d=s.itemClassName,f=s.requiredInputLength,p=s.dropdownClassName,m=s.debounceLoader,h=t.length>=f,v=void 0;return h&&a?v=this.renderLoader(m,d,p):h&&o&&(v=this.renderItems(t,n,r,c,d,p)),i.default.createElement("div",{className:"datalist-input"},this.renderInputField(u,t,l),v)}}]),t}(i.default.Component),l=function(){var e=this;this.componentDidMount=function(){"undefined"!=typeof window&&window.addEventListener("click",e.onClickCloseMenu,!1)},this.componentDidUpdate=function(){var t=e.state,n=t.currentInput,r=t.visible,o=t.isMatchingDebounced,i=e.props.initialValue;n||!i||r||o||e.setState({currentInput:i})},this.componentWillUnmount=function(){"undefined"!=typeof window&&window.removeEventListener("click",e.onClickCloseMenu)},this.onClickCloseMenu=function(t){var n=document.getElementsByClassName("datalist-items");if(n&&n.length)if(e.state.interactionHappened)e.setState({interactionHappened:!1});else{var r=document.getElementsByClassName("autocomplete-input");if(r){for(var o=0;o<r.length;o+=1){var i=t.target===r[o],a=r[o].contains(t.target);if(i||a)return}for(var s=0;s<n.length;s+=1){var u=n[s].contains(t.target),l=t.target===n[s];if(u||l)return}var c=e.state.visible,d=e.props.onDropdownClose;c&&e.setState({visible:!1,focusIndex:-1},d)}}},this.match=function(e,t){return t.label.substr(0,e.length).toUpperCase()===e.toUpperCase()},this.matching=function(t,n,o){return n.filter((function(n){return(void 0===o?"undefined":r(o))===("undefined"==typeof Function?"undefined":r(Function))?o(t,n):e.match(t,n)}))},this.indexOfMatch=function(e,t){return t.label.toUpperCase().indexOf(e.toUpperCase())},this.indexOfItem=function(e,t){return t.indexOf(t.find((function(t){return t.key===e.key})))},this.debouncedMatchingUpdateStep=function(t){var n=e.state.lastValidItem,r=e.props,o=r.items,i=r.match,a=r.debounceTime,s=r.dropDownLength,u=r.requiredInputLength,l=r.clearInputOnSelect,c=r.onDropdownOpen,d=r.onDropdownClose;e.inputHappenedTimeout&&"undefined"!=typeof window&&(window.clearTimeout(e.inputHappenedTimeout),e.inputHappenedTimeout=null);var f=t.length>=u,p=a>=0&&f;if(e.setState({currentInput:t,isMatchingDebounced:p}),f){var m=function(){var r=e.matching(t,o,i),a=r.slice(0,s),u=n&&!l?e.indexOfItem(n,a):0;r.length>0?e.setState({matchingItems:a,focusIndex:u>0?u:0,visible:!0,isMatchingDebounced:!1},c):e.setState({matchingItems:a,visible:!1,focusIndex:-1,isMatchingDebounced:!1},d)};a<=0?m():"undefined"!=typeof window&&(e.inputHappenedTimeout=window.setTimeout(m,a))}},this.onHandleInput=function(t){var n=e.props.onInput,r=t.target.value;e.debouncedMatchingUpdateStep(r),n(r)},this.onClickInput=function(){var t=e.state.visible,n=e.state.currentInput,r=e.props,o=r.requiredInputLength,i=r.initialValue;i&&n===i&&(e.setState({currentInput:""}),n=""),n.length>=o&&!t&&e.debouncedMatchingUpdateStep(n)},this.onHandleKeydown=function(t){var n=e.state,r=n.visible,o=n.focusIndex,i=n.matchingItems;if(r){var a=o;if(40===t.keyCode||9===t.keyCode)(a+=1)>=i.length&&(a=0),e.setState({focusIndex:a}),t.preventDefault();else if(38===t.keyCode)(a-=1)<=-1&&(a=i.length-1),e.setState({focusIndex:a});else if(13===t.keyCode&&o>-1){var s=i[a];e.onSelect(s)}}},this.onClickItem=function(t){for(var n=e.state.matchingItems,r=t.currentTarget.children,o=void 0,i=0;i<r.length;i+=1)if("INPUT"===r[i].tagName){o=r[i].value;break}var a=n.find((function(e){return e.key==o}));e.onSelect(a)},this.onSelect=function(t){var n=e.props,r=n.suppressReselect,o=n.clearInputOnSelect,i=n.onDropdownClose,a=e.state,s=a.lastValidItem;a.isMatchingDebounced||(r&&s&&t.key===s.key?e.setState({currentInput:o?"":t.label,visible:!1,focusIndex:-1,interactionHappened:!0},i):(e.setState({currentInput:o?"":t.label,lastValidItem:t,visible:!1,focusIndex:-1,interactionHappened:!0},i),(0,e.props.onSelect)(t)))},this.renderMatchingLabel=function(e,t,n){return i.default.createElement(i.default.Fragment,null,t.label.substr(0,n),i.default.createElement("strong",null,t.label.substr(n,e.length)),t.label.substr(n+e.length,t.label.length))},this.renderItemLabel=function(t,n,r){return i.default.createElement(i.default.Fragment,null,r>=0&&t.length?e.renderMatchingLabel(t,n,r):n.label)},this.renderItems=function(t,n,r,o,a,s){return i.default.createElement("div",{className:"datalist-items "+(s||"default-datalist-items")},n.map((function(n,s){var u=a+" "+(r===s?"datalist-active-item "+(o||"datalist-active-item-default"):"");return i.default.createElement("div",{onClick:e.onClickItem,className:u,key:n.key,tabIndex:0,role:"button",onKeyUp:function(e){return e.preventDefault()}},e.renderItemLabel(t,n,e.indexOfMatch(t,n)),i.default.createElement("input",{type:"hidden",value:n.key,readOnly:!0}))})))},this.renderLoader=function(e,t,n){return i.default.createElement("div",{className:"datalist-items "+(t||"default-datalist-items")},i.default.createElement("div",{className:n},e||"loading..."))},this.renderInputField=function(t,n,r){return i.default.createElement("input",{onChange:e.onHandleInput,onClick:e.onClickInput,onKeyDown:e.onHandleKeydown,type:"text",className:"autocomplete-input "+r,placeholder:t,value:n})}};u.propTypes={items:a.default.arrayOf(a.default.shape({label:a.default.string.isRequired,key:a.default.oneOfType([a.default.string,a.default.number]).isRequired})).isRequired,placeholder:a.default.string,onSelect:a.default.func.isRequired,onDropdownOpen:a.default.func,onDropdownClose:a.default.func,match:a.default.func,inputClassName:a.default.string,dropdownClassName:a.default.string,itemClassName:a.default.string,activeItemClassName:a.default.string,requiredInputLength:a.default.number,clearInputOnSelect:a.default.bool,suppressReselect:a.default.bool,dropDownLength:a.default.number,initialValue:a.default.string,debounceTime:a.default.number,debounceLoader:a.default.node,onInput:a.default.func},u.defaultProps={placeholder:"",match:void 0,inputClassName:"",dropdownClassName:"",itemClassName:"",activeItemClassName:"",requiredInputLength:0,clearInputOnSelect:!1,suppressReselect:!0,dropDownLength:1/0,initialValue:"",debounceTime:0,debounceLoader:void 0,onDropdownOpen:function(){},onDropdownClose:function(){},onInput:function(){}},t.default=u},function(e,t){e.exports=__WEBPACK_EXTERNAL_MODULE__1__},function(e,t,n){e.exports=n(3)()},function(e,t,n){"use strict";var r=n(4);function o(){}function i(){}i.resetWarningCache=o,e.exports=function(){function e(e,t,n,o,i,a){if(a!==r){var s=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 s.name="Invariant Violation",s}}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:i,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"},function(e,t,n){var r=n(6);"string"==typeof r&&(r=[[e.i,r,""]]);var o={hmr:!0,transform:void 0,insertInto:void 0};n(8)(r,o);r.locals&&(e.exports=r.locals)},function(e,t,n){(t=n(7)(!1)).push([e.i,".datalist-input {\n /*the container must be positioned relative:*/\n position: relative;\n display: inline-block;\n width: 100%;\n}\n\n.datalist-input .autocomplete-input {\n width: 100%;\n}\n\n.datalist-input .datalist-items {\n position: absolute;\n z-index: 99;\n /*position the autocomplete items to be the same width as the container:*/\n top: 100%;\n left: 0;\n right: 0;\n}\n\n.datalist-input .default-datalist-items {\n border: 1px solid #d4d4d4;\n border-bottom: none;\n border-top: none;\n}\n\n.datalist-input .default-datalist-items div:not(.datalist-active-item) {\n padding: 10px;\n cursor: pointer;\n background-color: #fff;\n border-bottom: 1px solid #d4d4d4;\n}\n\n.datalist-input .default-datalist-items div:not(.datalist-active-item):hover {\n /*when hovering an item:*/\n background-color: #e9e9e9;\n}\n\n.datalist-input .datalist-active-item {\n /*when navigating through the items using the arrow keys:*/\n cursor: pointer;\n}\n\n.datalist-input .datalist-active-item-default {\n background-color: DodgerBlue;\n color: #ffffff;\n border-bottom: 1px solid #d4d4d4;\n padding: 10px;\n}",""]),e.exports=t},function(e,t,n){"use strict";e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var n=function(e,t){var n=e[1]||"",r=e[3];if(!r)return n;if(t&&"function"==typeof btoa){var o=(a=r,s=btoa(unescape(encodeURIComponent(JSON.stringify(a)))),u="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(s),"/*# ".concat(u," */")),i=r.sources.map((function(e){return"/*# sourceURL=".concat(r.sourceRoot||"").concat(e," */")}));return[n].concat(i).concat([o]).join("\n")}var a,s,u;return[n].join("\n")}(t,e);return t[2]?"@media ".concat(t[2]," {").concat(n,"}"):n})).join("")},t.i=function(e,n,r){"string"==typeof e&&(e=[[null,e,""]]);var o={};if(r)for(var i=0;i<this.length;i++){var a=this[i][0];null!=a&&(o[a]=!0)}for(var s=0;s<e.length;s++){var u=[].concat(e[s]);r&&o[u[0]]||(n&&(u[2]?u[2]="".concat(n," and ").concat(u[2]):u[2]=n),t.push(u))}},t}},function(e,t,n){var r,o,i={},a=(r=function(){return window&&document&&document.all&&!window.atob},function(){return void 0===o&&(o=r.apply(this,arguments)),o}),s=function(e,t){return t?t.querySelector(e):document.querySelector(e)},u=function(e){var t={};return function(e,n){if("function"==typeof e)return e();if(void 0===t[e]){var r=s.call(this,e,n);if(window.HTMLIFrameElement&&r instanceof window.HTMLIFrameElement)try{r=r.contentDocument.head}catch(e){r=null}t[e]=r}return t[e]}}(),l=null,c=0,d=[],f=n(9);function p(e,t){for(var n=0;n<e.length;n++){var r=e[n],o=i[r.id];if(o){o.refs++;for(var a=0;a<o.parts.length;a++)o.parts[a](r.parts[a]);for(;a<r.parts.length;a++)o.parts.push(g(r.parts[a],t))}else{var s=[];for(a=0;a<r.parts.length;a++)s.push(g(r.parts[a],t));i[r.id]={id:r.id,refs:1,parts:s}}}}function m(e,t){for(var n=[],r={},o=0;o<e.length;o++){var i=e[o],a=t.base?i[0]+t.base:i[0],s={css:i[1],media:i[2],sourceMap:i[3]};r[a]?r[a].parts.push(s):n.push(r[a]={id:a,parts:[s]})}return n}function h(e,t){var n=u(e.insertInto);if(!n)throw new Error("Couldn't find a style target. This probably means that the value for the 'insertInto' parameter is invalid.");var r=d[d.length-1];if("top"===e.insertAt)r?r.nextSibling?n.insertBefore(t,r.nextSibling):n.appendChild(t):n.insertBefore(t,n.firstChild),d.push(t);else if("bottom"===e.insertAt)n.appendChild(t);else{if("object"!=typeof e.insertAt||!e.insertAt.before)throw new Error("[Style Loader]\n\n Invalid value for parameter 'insertAt' ('options.insertAt') found.\n Must be 'top', 'bottom', or Object.\n (https://github.com/webpack-contrib/style-loader#insertat)\n");var o=u(e.insertAt.before,n);n.insertBefore(t,o)}}function v(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e);var t=d.indexOf(e);t>=0&&d.splice(t,1)}function b(e){var t=document.createElement("style");if(void 0===e.attrs.type&&(e.attrs.type="text/css"),void 0===e.attrs.nonce){var r=function(){0;return n.nc}();r&&(e.attrs.nonce=r)}return y(t,e.attrs),h(e,t),t}function y(e,t){Object.keys(t).forEach((function(n){e.setAttribute(n,t[n])}))}function g(e,t){var n,r,o,i;if(t.transform&&e.css){if(!(i="function"==typeof t.transform?t.transform(e.css):t.transform.default(e.css)))return function(){};e.css=i}if(t.singleton){var a=c++;n=l||(l=b(t)),r=C.bind(null,n,a,!1),o=C.bind(null,n,a,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=function(e){var t=document.createElement("link");return void 0===e.attrs.type&&(e.attrs.type="text/css"),e.attrs.rel="stylesheet",y(t,e.attrs),h(e,t),t}(t),r=x.bind(null,n,t),o=function(){v(n),n.href&&URL.revokeObjectURL(n.href)}):(n=b(t),r=O.bind(null,n),o=function(){v(n)});return r(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;r(e=t)}else o()}}e.exports=function(e,t){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(t=t||{}).attrs="object"==typeof t.attrs?t.attrs:{},t.singleton||"boolean"==typeof t.singleton||(t.singleton=a()),t.insertInto||(t.insertInto="head"),t.insertAt||(t.insertAt="bottom");var n=m(e,t);return p(n,t),function(e){for(var r=[],o=0;o<n.length;o++){var a=n[o];(s=i[a.id]).refs--,r.push(s)}e&&p(m(e,t),t);for(o=0;o<r.length;o++){var s;if(0===(s=r[o]).refs){for(var u=0;u<s.parts.length;u++)s.parts[u]();delete i[s.id]}}}};var w,I=(w=[],function(e,t){return w[e]=t,w.filter(Boolean).join("\n")});function C(e,t,n,r){var o=n?"":r.css;if(e.styleSheet)e.styleSheet.cssText=I(t,o);else{var i=document.createTextNode(o),a=e.childNodes;a[t]&&e.removeChild(a[t]),a.length?e.insertBefore(i,a[t]):e.appendChild(i)}}function O(e,t){var n=t.css,r=t.media;if(r&&e.setAttribute("media",r),e.styleSheet)e.styleSheet.cssText=n;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(n))}}function x(e,t,n){var r=n.css,o=n.sourceMap,i=void 0===t.convertToAbsoluteUrls&&o;(t.convertToAbsoluteUrls||i)&&(r=f(r)),o&&(r+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(o))))+" */");var a=new Blob([r],{type:"text/css"}),s=e.href;e.href=URL.createObjectURL(a),s&&URL.revokeObjectURL(s)}},function(e,t){e.exports=function(e){var t="undefined"!=typeof window&&window.location;if(!t)throw new Error("fixUrls requires window.location");if(!e||"string"!=typeof e)return e;var n=t.protocol+"//"+t.host,r=n+t.pathname.replace(/\/[^\/]*$/,"/");return e.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi,(function(e,t){var o,i=t.trim().replace(/^"(.*)"$/,(function(e,t){return t})).replace(/^'(.*)'$/,(function(e,t){return t}));return/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(i)?e:(o=0===i.indexOf("//")?i:0===i.indexOf("/")?n+i:r+i.replace(/^\.\//,""),"url("+JSON.stringify(o)+")")}))}}]);
!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.DataListInput=t(require("react")):e.DataListInput=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=0)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r="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},o=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=u(n(1)),a=u(n(2));function u(e){return e&&e.__esModule?e:{default:e}}n(5);var s=function(e){function t(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var n=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));l.call(n);var r=n.props.initialValue;return n.state={lastValidItem:void 0,currentInput:r,matchingItems:[],visible:!1,focusIndex:0,interactionHappened:!1,isMatchingDebounced:!1},n.inputHappenedTimeout=void 0,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),o(t,[{key:"render",value:function(){var e=this.state,t=e.currentInput,n=e.matchingItems,r=e.focusIndex,o=e.visible,a=e.isMatchingDebounced,u=this.props,s=u.placeholder,l=u.inputClassName,c=u.activeItemClassName,d=u.itemClassName,f=u.requiredInputLength,p=u.dropdownClassName,m=u.debounceLoader,h=t.length>=f,b=void 0;return h&&a?b=this.renderLoader(m,d,p):h&&o&&(b=this.renderItems(t,n,r,c,d,p)),i.default.createElement("div",{className:"datalist-input"},this.renderInputField(s,t,l),b)}}]),t}(i.default.Component),l=function(){var e=this;this.componentDidMount=function(){"undefined"!=typeof window&&window.addEventListener("click",e.onClickCloseMenu,!1)},this.componentDidUpdate=function(){var t=e.state,n=t.currentInput,r=t.visible,o=t.isMatchingDebounced,i=e.props.initialValue;n||!i||r||o||e.setState({currentInput:i})},this.componentWillUnmount=function(){"undefined"!=typeof window&&window.removeEventListener("click",e.onClickCloseMenu)},this.onClickCloseMenu=function(t){var n=document.getElementsByClassName("datalist-items");if(n&&n.length)if(e.state.interactionHappened)e.setState({interactionHappened:!1});else{var r=document.getElementsByClassName("autocomplete-input");if(r){for(var o=0;o<r.length;o+=1){var i=t.target===r[o],a=r[o].contains(t.target);if(i||a)return}for(var u=0;u<n.length;u+=1){var s=n[u].contains(t.target),l=t.target===n[u];if(s||l)return}var c=e.state.visible,d=e.props.onDropdownClose;c&&e.setState({visible:!1,focusIndex:-1},d)}}},this.match=function(e,t){return t.label.substr(0,e.length).toUpperCase()===e.toUpperCase()},this.matching=function(t,n,o){return n.filter((function(n){return(void 0===o?"undefined":r(o))===("undefined"==typeof Function?"undefined":r(Function))?o(t,n):e.match(t,n)}))},this.indexOfMatch=function(e,t){return t.label.toUpperCase().indexOf(e.toUpperCase())},this.indexOfItem=function(e,t){return t.indexOf(t.find((function(t){return t.key===e.key})))},this.debouncedMatchingUpdateStep=function(t){var n=e.state.lastValidItem,r=e.props,o=r.items,i=r.match,a=r.debounceTime,u=r.dropDownLength,s=r.requiredInputLength,l=r.clearInputOnSelect,c=r.onDropdownOpen,d=r.onDropdownClose;e.inputHappenedTimeout&&"undefined"!=typeof window&&(window.clearTimeout(e.inputHappenedTimeout),e.inputHappenedTimeout=null);var f=t.length>=s,p=a>=0&&f;if(e.setState({currentInput:t,isMatchingDebounced:p}),f){var m=function(){var r=e.matching(t,o,i),a=r.slice(0,u),s=n&&!l?e.indexOfItem(n,a):0;r.length>0?e.setState({matchingItems:a,focusIndex:s>0?s:0,visible:!0,isMatchingDebounced:!1},c):e.setState({matchingItems:a,visible:!1,focusIndex:-1,isMatchingDebounced:!1},d)};a<=0?m():"undefined"!=typeof window&&(e.inputHappenedTimeout=window.setTimeout(m,a))}},this.onHandleInput=function(t){var n=e.props.onInput,r=t.target.value;e.debouncedMatchingUpdateStep(r),n(r)},this.onClickInput=function(){var t=e.state.visible,n=e.state.currentInput,r=e.props,o=r.requiredInputLength,i=r.initialValue;i&&n===i&&(e.setState({currentInput:""}),n=""),n.length>=o&&!t&&e.debouncedMatchingUpdateStep(n)},this.onHandleKeydown=function(t){var n=e.state,r=n.visible,o=n.focusIndex,i=n.matchingItems;if(r){var a=o;if(40===t.keyCode||9===t.keyCode)(a+=1)>=i.length&&(a=0),e.setState({focusIndex:a}),t.preventDefault();else if(38===t.keyCode)(a-=1)<=-1&&(a=i.length-1),e.setState({focusIndex:a});else if(13===t.keyCode&&o>-1){var u=i[a];e.onSelect(u)}}},this.onClickItem=function(t){for(var n=e.state.matchingItems,r=t.currentTarget.children,o=void 0,i=0;i<r.length;i+=1)if("INPUT"===r[i].tagName){o=r[i].value;break}var a=n.find((function(e){return e.key==o}));e.onSelect(a)},this.onSelect=function(t){var n=e.props,r=n.suppressReselect,o=n.clearInputOnSelect,i=n.onDropdownClose,a=e.state,u=a.lastValidItem;a.isMatchingDebounced||(r&&u&&t.key===u.key?e.setState({currentInput:o?"":t.label,visible:!1,focusIndex:-1,interactionHappened:!0},i):(e.setState({currentInput:o?"":t.label,lastValidItem:t,visible:!1,focusIndex:-1,interactionHappened:!0},i),(0,e.props.onSelect)(t)))},this.renderMatchingLabel=function(e,t,n){return i.default.createElement(i.default.Fragment,null,t.label.substr(0,n),i.default.createElement("strong",null,t.label.substr(n,e.length)),t.label.substr(n+e.length,t.label.length))},this.renderItemLabel=function(t,n,r){return i.default.createElement(i.default.Fragment,null,r>=0&&t.length?e.renderMatchingLabel(t,n,r):n.label)},this.renderItems=function(t,n,r,o,a,u){return i.default.createElement("div",{className:"datalist-items "+(u||"default-datalist-items")},n.map((function(n,u){var s=a+" "+(r===u?"datalist-active-item "+(o||"datalist-active-item-default"):"");return i.default.createElement("div",{onClick:e.onClickItem,className:s,key:n.key,tabIndex:0,role:"button",onKeyUp:function(e){return e.preventDefault()}},e.renderItemLabel(t,n,e.indexOfMatch(t,n)),i.default.createElement("input",{type:"hidden",value:n.key,readOnly:!0}))})))},this.renderLoader=function(e,t,n){return i.default.createElement("div",{className:"datalist-items "+(t||"default-datalist-items")},i.default.createElement("div",{className:n},e||"loading..."))},this.renderInputField=function(t,n,r){return i.default.createElement("input",{onChange:e.onHandleInput,onClick:e.onClickInput,onKeyDown:e.onHandleKeydown,type:"text",className:"autocomplete-input "+r,placeholder:t,value:n})}};s.propTypes={items:a.default.arrayOf(a.default.shape({label:a.default.string.isRequired,key:a.default.oneOfType([a.default.string,a.default.number]).isRequired})).isRequired,placeholder:a.default.string,onSelect:a.default.func.isRequired,onDropdownOpen:a.default.func,onDropdownClose:a.default.func,match:a.default.func,inputClassName:a.default.string,dropdownClassName:a.default.string,itemClassName:a.default.string,activeItemClassName:a.default.string,requiredInputLength:a.default.number,clearInputOnSelect:a.default.bool,suppressReselect:a.default.bool,dropDownLength:a.default.number,initialValue:a.default.string,debounceTime:a.default.number,debounceLoader:a.default.node,onInput:a.default.func},s.defaultProps={placeholder:"",match:void 0,inputClassName:"",dropdownClassName:"",itemClassName:"",activeItemClassName:"",requiredInputLength:0,clearInputOnSelect:!1,suppressReselect:!0,dropDownLength:1/0,initialValue:"",debounceTime:0,debounceLoader:void 0,onDropdownOpen:function(){},onDropdownClose:function(){},onInput:function(){}},t.default=s},function(t,n){t.exports=e},function(e,t,n){e.exports=n(3)()},function(e,t,n){"use strict";var r=n(4);function o(){}function i(){}i.resetWarningCache=o,e.exports=function(){function e(e,t,n,o,i,a){if(a!==r){var u=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 u.name="Invariant Violation",u}}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:i,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"},function(e,t,n){var r=n(6);"string"==typeof r&&(r=[[e.i,r,""]]);var o={hmr:!0,transform:void 0,insertInto:void 0};n(8)(r,o);r.locals&&(e.exports=r.locals)},function(e,t,n){(t=n(7)(!1)).push([e.i,".datalist-input {\n /*the container must be positioned relative:*/\n position: relative;\n display: inline-block;\n width: 100%;\n}\n\n.datalist-input .autocomplete-input {\n width: 100%;\n}\n\n.datalist-input .datalist-items {\n position: absolute;\n z-index: 99;\n /*position the autocomplete items to be the same width as the container:*/\n top: 100%;\n left: 0;\n right: 0;\n}\n\n.datalist-input .default-datalist-items {\n border: 1px solid #d4d4d4;\n border-bottom: none;\n border-top: none;\n}\n\n.datalist-input .default-datalist-items div:not(.datalist-active-item) {\n padding: 10px;\n cursor: pointer;\n background-color: #fff;\n border-bottom: 1px solid #d4d4d4;\n}\n\n.datalist-input .default-datalist-items div:not(.datalist-active-item):hover {\n /*when hovering an item:*/\n background-color: #e9e9e9;\n}\n\n.datalist-input .datalist-active-item {\n /*when navigating through the items using the arrow keys:*/\n cursor: pointer;\n}\n\n.datalist-input .datalist-active-item-default {\n background-color: DodgerBlue;\n color: #ffffff;\n border-bottom: 1px solid #d4d4d4;\n padding: 10px;\n}",""]),e.exports=t},function(e,t,n){"use strict";e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var n=function(e,t){var n=e[1]||"",r=e[3];if(!r)return n;if(t&&"function"==typeof btoa){var o=(a=r,u=btoa(unescape(encodeURIComponent(JSON.stringify(a)))),s="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(u),"/*# ".concat(s," */")),i=r.sources.map((function(e){return"/*# sourceURL=".concat(r.sourceRoot||"").concat(e," */")}));return[n].concat(i).concat([o]).join("\n")}var a,u,s;return[n].join("\n")}(t,e);return t[2]?"@media ".concat(t[2]," {").concat(n,"}"):n})).join("")},t.i=function(e,n,r){"string"==typeof e&&(e=[[null,e,""]]);var o={};if(r)for(var i=0;i<this.length;i++){var a=this[i][0];null!=a&&(o[a]=!0)}for(var u=0;u<e.length;u++){var s=[].concat(e[u]);r&&o[s[0]]||(n&&(s[2]?s[2]="".concat(n," and ").concat(s[2]):s[2]=n),t.push(s))}},t}},function(e,t,n){var r,o,i={},a=(r=function(){return window&&document&&document.all&&!window.atob},function(){return void 0===o&&(o=r.apply(this,arguments)),o}),u=function(e,t){return t?t.querySelector(e):document.querySelector(e)},s=function(e){var t={};return function(e,n){if("function"==typeof e)return e();if(void 0===t[e]){var r=u.call(this,e,n);if(window.HTMLIFrameElement&&r instanceof window.HTMLIFrameElement)try{r=r.contentDocument.head}catch(e){r=null}t[e]=r}return t[e]}}(),l=null,c=0,d=[],f=n(9);function p(e,t){for(var n=0;n<e.length;n++){var r=e[n],o=i[r.id];if(o){o.refs++;for(var a=0;a<o.parts.length;a++)o.parts[a](r.parts[a]);for(;a<r.parts.length;a++)o.parts.push(g(r.parts[a],t))}else{var u=[];for(a=0;a<r.parts.length;a++)u.push(g(r.parts[a],t));i[r.id]={id:r.id,refs:1,parts:u}}}}function m(e,t){for(var n=[],r={},o=0;o<e.length;o++){var i=e[o],a=t.base?i[0]+t.base:i[0],u={css:i[1],media:i[2],sourceMap:i[3]};r[a]?r[a].parts.push(u):n.push(r[a]={id:a,parts:[u]})}return n}function h(e,t){var n=s(e.insertInto);if(!n)throw new Error("Couldn't find a style target. This probably means that the value for the 'insertInto' parameter is invalid.");var r=d[d.length-1];if("top"===e.insertAt)r?r.nextSibling?n.insertBefore(t,r.nextSibling):n.appendChild(t):n.insertBefore(t,n.firstChild),d.push(t);else if("bottom"===e.insertAt)n.appendChild(t);else{if("object"!=typeof e.insertAt||!e.insertAt.before)throw new Error("[Style Loader]\n\n Invalid value for parameter 'insertAt' ('options.insertAt') found.\n Must be 'top', 'bottom', or Object.\n (https://github.com/webpack-contrib/style-loader#insertat)\n");var o=s(e.insertAt.before,n);n.insertBefore(t,o)}}function b(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e);var t=d.indexOf(e);t>=0&&d.splice(t,1)}function v(e){var t=document.createElement("style");if(void 0===e.attrs.type&&(e.attrs.type="text/css"),void 0===e.attrs.nonce){var r=function(){0;return n.nc}();r&&(e.attrs.nonce=r)}return y(t,e.attrs),h(e,t),t}function y(e,t){Object.keys(t).forEach((function(n){e.setAttribute(n,t[n])}))}function g(e,t){var n,r,o,i;if(t.transform&&e.css){if(!(i="function"==typeof t.transform?t.transform(e.css):t.transform.default(e.css)))return function(){};e.css=i}if(t.singleton){var a=c++;n=l||(l=v(t)),r=C.bind(null,n,a,!1),o=C.bind(null,n,a,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=function(e){var t=document.createElement("link");return void 0===e.attrs.type&&(e.attrs.type="text/css"),e.attrs.rel="stylesheet",y(t,e.attrs),h(e,t),t}(t),r=O.bind(null,n,t),o=function(){b(n),n.href&&URL.revokeObjectURL(n.href)}):(n=v(t),r=x.bind(null,n),o=function(){b(n)});return r(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;r(e=t)}else o()}}e.exports=function(e,t){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(t=t||{}).attrs="object"==typeof t.attrs?t.attrs:{},t.singleton||"boolean"==typeof t.singleton||(t.singleton=a()),t.insertInto||(t.insertInto="head"),t.insertAt||(t.insertAt="bottom");var n=m(e,t);return p(n,t),function(e){for(var r=[],o=0;o<n.length;o++){var a=n[o];(u=i[a.id]).refs--,r.push(u)}e&&p(m(e,t),t);for(o=0;o<r.length;o++){var u;if(0===(u=r[o]).refs){for(var s=0;s<u.parts.length;s++)u.parts[s]();delete i[u.id]}}}};var I,w=(I=[],function(e,t){return I[e]=t,I.filter(Boolean).join("\n")});function C(e,t,n,r){var o=n?"":r.css;if(e.styleSheet)e.styleSheet.cssText=w(t,o);else{var i=document.createTextNode(o),a=e.childNodes;a[t]&&e.removeChild(a[t]),a.length?e.insertBefore(i,a[t]):e.appendChild(i)}}function x(e,t){var n=t.css,r=t.media;if(r&&e.setAttribute("media",r),e.styleSheet)e.styleSheet.cssText=n;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(n))}}function O(e,t,n){var r=n.css,o=n.sourceMap,i=void 0===t.convertToAbsoluteUrls&&o;(t.convertToAbsoluteUrls||i)&&(r=f(r)),o&&(r+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(o))))+" */");var a=new Blob([r],{type:"text/css"}),u=e.href;e.href=URL.createObjectURL(a),u&&URL.revokeObjectURL(u)}},function(e,t){e.exports=function(e){var t="undefined"!=typeof window&&window.location;if(!t)throw new Error("fixUrls requires window.location");if(!e||"string"!=typeof e)return e;var n=t.protocol+"//"+t.host,r=n+t.pathname.replace(/\/[^\/]*$/,"/");return e.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi,(function(e,t){var o,i=t.trim().replace(/^"(.*)"$/,(function(e,t){return t})).replace(/^'(.*)'$/,(function(e,t){return t}));return/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(i)?e:(o=0===i.indexOf("//")?i:0===i.indexOf("/")?n+i:r+i.replace(/^\.\//,""),"url("+JSON.stringify(o)+")")}))}}])}));
{
"name": "react-datalist-input",
"version": "1.3.9",
"version": "1.3.10",
"description": "This package provides a react component as follows: an input field with a drop down menu to pick a possible option based on the current input.",

@@ -5,0 +5,0 @@ "main": "./lib/DataListInput.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc