2 lines
9.2 KiB
JavaScript
2 lines
9.2 KiB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),e=require("primereact/utils"),n=require("primereact/tooltip");function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=r(t);function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function p(t){if(Array.isArray(t))return i(t)}function s(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function l(t,e){if(t){if("string"==typeof t)return i(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(t,e):void 0}}function u(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function a(t){return p(t)||s(t)||l(t)||u()}function c(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function f(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function h(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function d(t,e){return d=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},d(t,e)}function v(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}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&d(t,e)}function y(t){return y="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},y(t)}function m(t,e){if(e&&("object"===y(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return h(t)}function b(t){return b=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},b(t)}function g(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function O(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function w(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?O(Object(n),!0).forEach((function(e){g(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):O(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function k(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}var R=function(r){v(y,t.Component);var i,p,s,l,u,d=(i=y,p=k(),function(){var t,e=b(i);if(p){var n=b(this).constructor;t=Reflect.construct(e,arguments,n)}else t=e.apply(this,arguments);return m(this,t)});function y(e){var n;return c(this,y),(n=d.call(this,e)).state={focused:!1},n.onWrapperClick=n.onWrapperClick.bind(h(n)),n.onKeyDown=n.onKeyDown.bind(h(n)),n.onPaste=n.onPaste.bind(h(n)),n.onFocus=n.onFocus.bind(h(n)),n.onBlur=n.onBlur.bind(h(n)),n.inputRef=t.createRef(n.props.inputRef),n}return s=y,(l=[{key:"removeItem",value:function(t,e){if(!this.props.disabled||!this.props.readOnly){var n=a(this.props.value),r=n.splice(e,1);this.isRemovable(r,e)&&(this.props.onRemove&&this.props.onRemove({originalEvent:t,value:r}),this.props.onChange&&this.props.onChange({originalEvent:t,value:n,stopPropagation:function(){},preventDefault:function(){},target:{name:this.props.name,id:this.props.id,value:n}}))}}},{key:"addItem",value:function(t,e,n){if(e&&e.trim().length){var r=this.props.value?a(this.props.value):[];(this.props.allowDuplicate||-1===r.indexOf(e))&&(r.push(e),this.props.onAdd&&this.props.onAdd({originalEvent:t,value:e})),this.updateInput(t,r,n)}}},{key:"onWrapperClick",value:function(){this.inputRef.current.focus()}},{key:"onKeyDown",value:function(t){var e=t.target.value,n=this.props.value||[];switch(t.which){case 8:0===this.inputRef.current.value.length&&n.length>0&&this.removeItem(t,n.length-1);break;case 13:e&&e.trim().length&&(!this.props.max||this.props.max>n.length)&&this.addItem(t,e,!0);break;default:this.isMaxedOut()?t.preventDefault():this.props.separator&&","===this.props.separator&&188===t.which&&this.addItem(t,e,!0)}}},{key:"updateInput",value:function(t,e,n){this.props.onChange&&this.props.onChange({originalEvent:t,value:e,stopPropagation:function(){},preventDefault:function(){},target:{name:this.props.name,id:this.props.id,value:e}}),this.inputRef.current.value="",n&&t.preventDefault()}},{key:"onPaste",value:function(t){var e=this;if(this.props.separator){var n=(t.clipboardData||window.clipboardData).getData("Text");if(n){var r=this.props.value||[],o=n.split(this.props.separator);o=o.filter((function(t){return(e.props.allowDuplicate||-1===r.indexOf(t))&&t.trim().length})),r=[].concat(a(r),a(o)),this.updateInput(t,r,!0)}}}},{key:"onFocus",value:function(t){var e=this;t.persist(),this.setState({focused:!0},(function(){e.props.onFocus&&e.props.onFocus(t)}))}},{key:"onBlur",value:function(t){var e=this;t.persist(),this.setState({focused:!1},(function(){e.props.onBlur&&e.props.onBlur(t)}))}},{key:"isMaxedOut",value:function(){return this.props.max&&this.props.value&&this.props.max===this.props.value.length}},{key:"isFilled",value:function(){return this.props.value&&this.props.value.length||this.inputRef&&this.inputRef.current&&this.inputRef.current.value&&this.inputRef.current.value.length}},{key:"isRemovable",value:function(t,n){return e.ObjectUtils.getPropValue(this.props.removable,{value:t,index:n,props:this.props})}},{key:"updateInputRef",value:function(){var t=this.props.inputRef;t&&("function"==typeof t?t(this.inputRef.current):t.current=this.inputRef.current)}},{key:"componentDidMount",value:function(){this.updateInputRef(),this.props.tooltip&&this.renderTooltip()}},{key:"componentDidUpdate",value:function(t){var e=this.props.value&&t.value&&t.value.length===this.props.value.length;this.props.tooltip&&(t.tooltip!==this.props.tooltip||t.tooltipOptions!==this.props.tooltipOptions?this.tooltip?this.tooltip.update(w({content:this.props.tooltip},this.props.tooltipOptions||{})):this.renderTooltip():!e&&this.tooltip&&(this.tooltip.deactivate(),this.tooltip.activate()))}},{key:"componentWillUnmount",value:function(){this.tooltip&&(this.tooltip.destroy(),this.tooltip=null)}},{key:"renderTooltip",value:function(){this.tooltip=n.tip({target:this.inputRef.current,targetContainer:this.listElement,content:this.props.tooltip,options:this.props.tooltipOptions})}},{key:"renderRemoveIcon",value:function(t,e){var n=this;return this.props.disabled||this.props.readOnly||!this.isRemovable(t,e)?null:o.default.createElement("span",{className:"p-chips-token-icon pi pi-times-circle",onClick:function(t){return n.removeItem(t,e)}})}},{key:"renderItem",value:function(t,e){var n=this.props.itemTemplate?this.props.itemTemplate(t):t,r=this.renderRemoveIcon(t,e);return o.default.createElement("li",{key:e,className:"p-chips-token p-highlight"},o.default.createElement("span",{className:"p-chips-token-label"},n),r)}},{key:"renderInputElement",value:function(){return o.default.createElement("li",{className:"p-chips-input-token"},o.default.createElement("input",{ref:this.inputRef,placeholder:this.props.placeholder,type:"text",name:this.props.name,disabled:this.props.disabled||this.isMaxedOut(),onKeyDown:this.onKeyDown,onPaste:this.onPaste,onFocus:this.onFocus,onBlur:this.onBlur,"aria-labelledby":this.props.ariaLabelledBy,readOnly:this.props.readOnly}))}},{key:"renderItems",value:function(){var t=this;return this.props.value?this.props.value.map((function(e,n){return t.renderItem(e,n)})):null}},{key:"renderList",value:function(){var t=this,n=e.classNames("p-inputtext p-chips-multiple-container",{"p-disabled":this.props.disabled,"p-focus":this.state.focused}),r=this.renderItems(),i=this.renderInputElement();return o.default.createElement("ul",{ref:function(e){return t.listElement=e},className:n,onClick:this.onWrapperClick},r,i)}},{key:"render",value:function(){var t=this,n=e.classNames("p-chips p-component p-inputwrapper",this.props.className,{"p-inputwrapper-filled":this.isFilled(),"p-inputwrapper-focus":this.state.focused}),r=this.renderList();return o.default.createElement("div",{ref:function(e){return t.element=e},id:this.props.id,className:n,style:this.props.style},r)}}])&&f(s.prototype,l),u&&f(s,u),Object.defineProperty(s,"prototype",{writable:!1}),y}();g(R,"defaultProps",{id:null,inputRef:null,name:null,placeholder:null,value:null,max:null,disabled:null,readOnly:!1,removable:!0,style:null,className:null,tooltip:null,tooltipOptions:null,ariaLabelledBy:null,separator:null,allowDuplicate:!0,itemTemplate:null,onAdd:null,onRemove:null,onChange:null,onFocus:null,onBlur:null}),exports.Chips=R;
|