-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathreact-tokeninput.min.js
More file actions
7 lines (7 loc) · 15.3 KB
/
react-tokeninput.min.js
File metadata and controls
7 lines (7 loc) · 15.3 KB
1
2
3
4
5
6
7
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("prop-types"),require("react")):"function"==typeof define&&define.amd?define(["prop-types","react"],t):"object"==typeof exports?exports.TokenInput=t(require("prop-types"),require("react")):e.TokenInput=t(e["prop-types"],e.react)}(this,function(e,t){return function(e){function t(o){if(n[o])return n[o].exports;var i=n[o]={exports:{},id:o,loaded:!1};return e[o].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var n={};return t.m=e,t.c=n,t.p="/",t(0)}([function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.Token=t.Option=t.Combobox=void 0;var i=n(1),r=o(i),s=n(5),u=o(s),a=n(6),c=o(a),l=n(7),p=o(l);t.Combobox=r.default,t.Option=u.default,t.Token=c.default;var f=p.default;t.default=f},function(e,t,n){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(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}function r(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)}function s(e){return e.props.label||e.props.children}var u=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),a=n(2),c=n(3),l=0,p=function(){},f=n(4),d=n(5),h=function(e){function t(){var e,n,r,u;o(this,t);for(var a=arguments.length,p=Array(a),h=0;h<a;h++)p[h]=arguments[h];return n=r=i(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(p))),r.makeMenu=function(e){var t,n=!0,o=c.Children.map(e,function(e,o){if(e.type!==d||!e.props.isFocusable)return e;n=!1;var i=e.props,r={};return this.state.value===e.props.value&&(r.id=i.id||"ic-tokeninput-selected-"+ ++l,r.isSelected=!0,t=i.id),r.onBlur=this.handleOptionBlur,r.onClick=this.selectOption.bind(this,e),r.onFocus=this.handleOptionFocus,r.onKeyDown=this.handleOptionKeyDown.bind(this,e),r.onMouseEnter=this.handleOptionMouseEnter.bind(this,o),c.cloneElement(e,r)}.bind(r));return{children:o,activedescendant:t,isEmpty:n}},r.getClassName=function(){var e=f(r.props.className,"ic-tokeninput");return r.state.isOpen&&(e=f(e,"ic-tokeninput-is-open")),e},r.clearSelectedState=function(e){r.setState({focusedIndex:null,inputValue:null,value:null,matchedAutocompleteOption:null,activedescendant:null},e)},r.handleInputChange=function(){var e=r.input.value;r.clearSelectedState(function(){this.props.onInput(e)}.bind(r))},r.handleInputFocus=function(){r.props.onFocus(),r.maybeShowList()},r.handleInputClick=function(){r.maybeShowList()},r.maybeShowList=function(){r.props.showListOnFocus&&r.showList()},r.handleInputBlur=function(){var e=null!=r.state.focusedIndex;e||(r.maybeSelectAutocompletedOption(),r.hideList())},r.handleOptionBlur=function(){r.blurTimer=setTimeout(r.hideList,0)},r.handleOptionFocus=function(){clearTimeout(r.blurTimer)},r.handleInputKeyUp=function(e){r.state.menu.isEmpty||8===e.keyCode||!r.props.autocomplete.match(/both|inline/)},r.handleButtonClick=function(){r.state.isOpen?r.hideList():r.showList(),r.focusInput()},r.showList=function(){r.state.menu.children.length&&r.setState({isOpen:!0})},r.hideList=function(){r.setState({isOpen:!1,focusedIndex:null})},r.hideOnEscape=function(e){r.hideList(),r.focusInput(),e.preventDefault()},r.focusInput=function(){r.input.focus()},r.selectInput=function(){r.input.select()},r.inputKeydownMap={8:"removeLastToken",13:"selectOnEnter",188:"selectOnEnter",27:"hideOnEscape",38:"focusPrevious",40:"focusNext"},r.optionKeydownMap={13:"selectOption",27:"hideOnEscape",38:"focusPrevious",40:"focusNext"},r.handleKeydown=function(e){var t=r.inputKeydownMap[e.keyCode];if(t)return r.setState({usingKeyboard:!0}),r[t].call(r,e)},r.handleOptionKeyDown=function(e,t){var n=r.optionKeydownMap[t.keyCode];return n?(t.preventDefault(),r.setState({usingKeyboard:!0}),void r[n].call(r,e)):void r.selectInput()},r.handleOptionMouseEnter=function(e){r.state.usingKeyboard?r.setState({usingKeyboard:!1}):r.focusOptionAtIndex(e)},r.selectOnEnter=function(e){e.preventDefault(),r.maybeSelectAutocompletedOption()},r.maybeSelectAutocompletedOption=function(){r.state.matchedAutocompleteOption?r.selectOption(r.state.matchedAutocompleteOption,{focus:!1}):r.selectText()},r.selectOption=function(e,t){t=t||{},r.setState({matchedAutocompleteOption:null},function(){this.props.onSelect(e.props.value,e),this.hideList(),this.clearSelectedState(),t.focus!==!1&&this.selectInput()}.bind(r)),r.input.value=""},r.selectText=function(){var e=r.input.value;e&&(r.props.onSelect(e),r.clearSelectedState(),r.input.value="")},r.focusNext=function(e){if(e.preventDefault&&e.preventDefault(),!r.state.menu.isEmpty){var t=r.nextFocusableIndex(r.state.focusedIndex);r.focusOptionAtIndex(t)}},r.removeLastToken=function(){return r.props.onRemoveLast&&!r.input.value&&r.props.onRemoveLast(),!0},r.focusPrevious=function(e){if(e.preventDefault&&e.preventDefault(),!r.state.menu.isEmpty){var t=r.previousFocusableIndex(r.state.focusedIndex);r.focusOptionAtIndex(t)}},r.focusSelectedOption=function(){var e;c.Children.forEach(r.props.children,function(t,n){t.props.value===this.state.value&&(e=n)}.bind(r)),r.showList(),r.setState({focusedIndex:e},r.focusOption)},r.findInitialInputValue=function(){var e;return c.Children.forEach(r.props.children,function(t){t.props.value===this.props.value&&(e=s(t))}.bind(r)),e},r.clampIndex=function(e){return e<0?r.props.children.length-1:e>=r.props.children.length?0:e},r.scanForFocusableIndex=function(e,t){null!==e&&void 0!==e||(e=t>0?r.clampIndex(-1):0);for(var n=e;;)if(n=r.clampIndex(n+t),n===e||r.props.children[n].props.isFocusable)return n},r.nextFocusableIndex=function(e){return r.scanForFocusableIndex(e,1)},r.previousFocusableIndex=function(e){return r.scanForFocusableIndex(e,-1)},r.focusOptionAtIndex=function(e){if(!r.state.isOpen&&r.state.value)return r.focusSelectedOption();r.showList();var t=r.props.children.length;e===-1?e=t-1:e===t&&(e=0),r.setState({focusedIndex:e},r.focusOption)},r.focusOption=function(){var e=r.state.focusedIndex;r.list.childNodes[e].focus()},r.state={value:r.props.value,inputValue:r.findInitialInputValue(),isOpen:!1,focusedIndex:null,matchedAutocompleteOption:null,usingKeyboard:!1,activedescendant:null,listId:"ic-tokeninput-list-"+ ++l,menu:{children:[],activedescendant:null,isEmpty:!0}},u=n,i(r,u)}return r(t,e),u(t,[{key:"componentWillMount",value:function(){this.setState({menu:this.makeMenu(this.props.children)})}},{key:"componentWillReceiveProps",value:function(e){this.setState({menu:this.makeMenu(e.children)},function(){if(e.children.length&&(this.isOpen||document.activeElement===this.input)){if(!this.state.menu.children.length)return;this.setState({isOpen:!0},function(){this.list.scrollTop=0}.bind(this))}else this.hideList()}.bind(this))}},{key:"render",value:function(){var e=this,t=this.props["aria-label"]||"Start typing to search. Press the down arrow to navigate results. If you don't find an acceptable option, you can input an alternative. Once you find or input the tag you want, press Enter or Comma to add it.";return c.createElement("div",{className:this.getClassName()},this.props.value,this.state.inputValue,c.createElement("input",{ref:function(t){return e.input=t},autoComplete:"off",spellCheck:"false","aria-label":t,"aria-expanded":this.state.isOpen+"","aria-haspopup":"true","aria-activedescendant":this.state.menu.activedescendant,"aria-autocomplete":"list","aria-owns":this.state.listId,id:this.props.id,disabled:this.props.isDisabled,className:"ic-tokeninput-input",onFocus:this.handleInputFocus,onClick:this.handleInputClick,onChange:this.handleInputChange,onBlur:this.handleInputBlur,onKeyDown:this.handleKeydown,onKeyUp:this.handleInputKeyUp,placeholder:this.props.placeholder,role:"combobox"}),c.createElement("span",{"aria-hidden":"true",className:"ic-tokeninput-button",onClick:this.handleButtonClick},"▾"),c.createElement("div",{id:this.state.listId,ref:function(t){return e.list=t},className:"ic-tokeninput-list",role:"listbox"},this.state.menu.children))}}]),t}(c.Component);h.propTypes={onFocus:a.func,onInput:a.func,onSelect:a.func,placeholder:a.string},h.defaultProps={autocomplete:"both",onFocus:p,onInput:p,onSelect:p,value:null,showListOnFocus:!1},e.exports=h},function(t,n){t.exports=e},function(e,n){e.exports=t},function(e,t){"use strict";function n(e,t){return e?e.indexOf(t)>-1?e:e+" "+t:t}e.exports=n},function(e,t,n){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(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}function r(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)}var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),u=n(2),a=n(3),c=n(4),l=function(e){function t(){return o(this,t),i(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return r(t,e),s(t,[{key:"render",value:function(){var e=this.props;return e.isSelected&&(e.className=c(e.className,"ic-tokeninput-selected"),e.ariaSelected=!0),a.createElement("div",e)}}]),t}(a.Component);l.propTypes={value:u.any.isRequired,label:u.string,isFocusable:u.bool},l.defaultProps={role:"option",tabIndex:"-1",className:"ic-tokeninput-option",isSelected:!1,isFocusable:!0},e.exports=l},function(e,t,n){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(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}function r(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)}var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),u=n(3),a=function(e){function t(){var e,n,r,s;o(this,t);for(var u=arguments.length,a=Array(u),c=0;c<u;c++)a[c]=arguments[c];return n=r=i(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(a))),r.handleClick=function(){r.props.onRemove(r.props.value)},r.handleKeyDown=function(e){var t=13;e.keyCode===t&&r.props.onRemove(r.props.value)},r.ariaLabelRemove=function(){return r.props.tokenAriaFunc?r.props.tokenAriaFunc(r.props.name):"Remove '"+r.props.name+"'"},s=n,i(r,s)}return r(t,e),s(t,[{key:"render",value:function(){return u.createElement("li",{className:"ic-token inline-flex"},u.createElement("span",{className:"ic-token-label"},this.props.name),u.createElement("span",{role:"button",onClick:this.handleClick,onFocus:this.props.onFocus,onKeyDown:this.handleKeyDown,"aria-label":this.ariaLabelRemove(),className:"ic-token-delete-button",tabIndex:0},"✕"))}}]),t}(u.Component);e.exports=a},function(e,t,n){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(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}function r(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)}var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),u=n(2),a=n(3),c=n(1),l=n(6),p=n(8),f=function(e){function t(){var e,n,r,s;o(this,t);for(var u=arguments.length,a=Array(u),c=0;c<u;c++)a[c]=arguments[c];return n=r=i(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(a))),r.state={selectedToken:null},r.handleClick=function(){r.comboLi.querySelector("input").focus()},r.handleFocus=function(){r.props.onFocus&&r.props.onFocus()},r.handleInput=function(e){r.props.onInput(e)},r.handleSelect=function(e,t){var n=r.comboLi.querySelector("input");r.props.onSelect(e,t),r.setState({selectedToken:null}),r.props.onInput(n.value)},r.handleRemove=function(e){var t=r.comboLi.querySelector("input");r.props.onRemove(e),t.focus()},r.handleRemoveLast=function(){r.props.onRemove(r.props.selected[r.props.selected.length-1])},s=n,i(r,s)}return r(t,e),s(t,[{key:"render",value:function(){var e=this,t=this.props.isDisabled,n=this.props.selected.map(function(e){return a.createElement(l,{tokenAriaFunc:this.props.tokenAriaFunc,onFocus:this.handleFocus,onRemove:this.handleRemove,value:e,name:e.name,key:e.id})}.bind(this)),o=p("ic-tokens flex",{"ic-tokens-disabled":t});return a.createElement("ul",{className:o,onClick:this.handleClick},n,a.createElement("li",{className:"inline-flex",ref:function(t){return e.comboLi=t}},a.createElement(c,{id:this.props.id,"aria-label":this.props["combobox-aria-label"],ariaDisabled:t,onFocus:this.handleFocus,onInput:this.handleInput,showListOnFocus:this.props.showListOnFocus,onSelect:this.handleSelect,onRemoveLast:this.handleRemoveLast,value:this.state.selectedToken,isDisabled:t,placeholder:this.props.placeholder},this.props.menuContent)),this.props.isLoading&&a.createElement("li",{className:"ic-tokeninput-loading flex"},this.props.loadingComponent))}}]),t}(a.Component);f.propTypes={isLoading:u.bool,loadingComponent:u.any,onFocus:u.func,onInput:u.func.isRequired,onSelect:u.func.isRequired,tokenAriaFunc:u.func,onRemove:u.func.isRequired,selected:u.array.isRequired,menuContent:u.any,showListOnFocus:u.bool,placeholder:u.string},e.exports=f},function(e,t,n){var o,i;/*!
Copyright (c) 2017 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/
!function(){"use strict";function n(){for(var e=[],t=0;t<arguments.length;t++){var o=arguments[t];if(o){var i=typeof o;if("string"===i||"number"===i)e.push(o);else if(Array.isArray(o)&&o.length){var s=n.apply(null,o);s&&e.push(s)}else if("object"===i)for(var u in o)r.call(o,u)&&o[u]&&e.push(u)}}return e.join(" ")}var r={}.hasOwnProperty;"undefined"!=typeof e&&e.exports?(n.default=n,e.exports=n):(o=[],i=function(){return n}.apply(t,o),!(void 0!==i&&(e.exports=i)))}()}])});
//# sourceMappingURL=react-tokeninput.min.js.map