2 lines
18 KiB
JavaScript
2 lines
18 KiB
JavaScript
this.primereact=this.primereact||{},this.primereact.mention=function(e,t,n,r,i,o,s,l,a){"use strict";function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var p=u(t),c=u(a);function h(){return h=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},h.apply(this,arguments)}function f(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function d(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)}}function y(e,t,n){return t&&d(e.prototype,t),n&&d(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function v(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function g(e,t){return g=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},g(e,t)}function m(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&g(e,t)}function b(e){return b="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},b(e)}function O(e,t){if(t&&("object"===b(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return v(e)}function k(e){return k=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},k(e)}function R(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function w(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function S(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?w(Object(n),!0).forEach((function(t){R(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):w(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function E(){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(e){return!1}}var C=function(e){m(s,e);var r,i,o=(r=s,i=E(),function(){var e,t=k(r);if(i){var n=k(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return O(this,e)});function s(e){var n;return f(this,s),(n=o.call(this,e)).onFocus=n.onFocus.bind(v(n)),n.onBlur=n.onBlur.bind(v(n)),n.onKeyUp=n.onKeyUp.bind(v(n)),n.onInput=n.onInput.bind(v(n)),n.elementRef=t.createRef(n.props.forwardRef),n}return y(s,[{key:"onFocus",value:function(e){this.props.autoResize&&this.resize(),this.props.onFocus&&this.props.onFocus(e)}},{key:"onBlur",value:function(e){this.props.autoResize&&this.resize(),this.props.onBlur&&this.props.onBlur(e)}},{key:"onKeyUp",value:function(e){this.props.autoResize&&this.resize(),this.props.onKeyUp&&this.props.onKeyUp(e)}},{key:"onInput",value:function(e){this.props.autoResize&&this.resize(),e.target.value.length>0?n.DomHandler.addClass(e.target,"p-filled"):n.DomHandler.removeClass(e.target,"p-filled"),this.props.onInput&&this.props.onInput(e)}},{key:"resize",value:function(e){var t=this.elementRef&&this.elementRef.current;t&&n.DomHandler.isVisible(t)&&(this.cachedScrollHeight||(this.cachedScrollHeight=t.scrollHeight,t.style.overflow="hidden"),(this.cachedScrollHeight!==t.scrollHeight||e)&&(t.style.height="",t.style.height=t.scrollHeight+"px",parseFloat(t.style.height)>=parseFloat(t.style.maxHeight)?(t.style.overflowY="scroll",t.style.height=t.style.maxHeight):t.style.overflow="hidden",this.cachedScrollHeight=t.scrollHeight))}},{key:"isFilled",value:function(){return null!=this.props.value&&this.props.value.toString().length>0||null!=this.props.defaultValue&&this.props.defaultValue.toString().length>0||this.elementRef&&this.elementRef.current&&this.elementRef.current.value.toString().length>0}},{key:"updateForwardRef",value:function(){var e=this.props.forwardRef;e&&("function"==typeof e?e(this.elementRef.current):e.current=this.elementRef.current)}},{key:"componentDidMount",value:function(){this.updateForwardRef(),this.props.tooltip&&this.renderTooltip(),this.props.autoResize&&this.resize(!0)}},{key:"componentDidUpdate",value:function(e){e.tooltip===this.props.tooltip&&e.tooltipOptions===this.props.tooltipOptions||(this.tooltip?this.tooltip.update(S({content:this.props.tooltip},this.props.tooltipOptions||{})):this.renderTooltip()),this.props.autoResize&&this.resize(!0)}},{key:"componentWillUnmount",value:function(){this.tooltip&&(this.tooltip.destroy(),this.tooltip=null)}},{key:"renderTooltip",value:function(){this.tooltip=l.tip({target:this.elementRef.current,content:this.props.tooltip,options:this.props.tooltipOptions})}},{key:"render",value:function(){var e=n.classNames("p-inputtextarea p-inputtext p-component",{"p-disabled":this.props.disabled,"p-filled":this.isFilled(),"p-inputtextarea-resizable":this.props.autoResize},this.props.className),t=n.ObjectUtils.findDiffKeys(this.props,s.defaultProps);return p.default.createElement("textarea",h({ref:this.elementRef},t,{className:e,onFocus:this.onFocus,onBlur:this.onBlur,onKeyUp:this.onKeyUp,onInput:this.onInput}))}}]),s}(t.Component);R(C,"defaultProps",{autoResize:!1,tooltip:null,tooltipOptions:null,onInput:null,forwardRef:null});var x=p.default.forwardRef((function(e,t){return p.default.createElement(C,h({forwardRef:t},e))}));function D(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function H(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?D(Object(n),!0).forEach((function(t){R(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):D(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function j(){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(e){return!1}}var P=function(e){m(d,e);var l,a,u=(l=d,a=j(),function(){var e,t=k(l);if(a){var n=k(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return O(this,e)});function d(e){var n;return f(this,d),(n=u.call(this,e)).state={overlayVisible:!1,focused:!1,searching:!1,trigger:null},n.onOverlayEnter=n.onOverlayEnter.bind(v(n)),n.onOverlayEntering=n.onOverlayEntering.bind(v(n)),n.onOverlayEntered=n.onOverlayEntered.bind(v(n)),n.onOverlayExit=n.onOverlayExit.bind(v(n)),n.onOverlayExited=n.onOverlayExited.bind(v(n)),n.onFocus=n.onFocus.bind(v(n)),n.onBlur=n.onBlur.bind(v(n)),n.onKeyDown=n.onKeyDown.bind(v(n)),n.onChange=n.onChange.bind(v(n)),n.onInput=n.onInput.bind(v(n)),n.onKeyUp=n.onKeyUp.bind(v(n)),n.onPanelClick=n.onPanelClick.bind(v(n)),n.overlayRef=t.createRef(),n.inputRef=t.createRef(n.props.inputRef),n}return y(d,[{key:"showOverlay",value:function(){this.setState({overlayVisible:!0})}},{key:"hideOverlay",value:function(){this.setState({overlayVisible:!1,searching:!1,trigger:null})}},{key:"onOverlayEnter",value:function(){n.ZIndexUtils.set("overlay",this.overlayRef.current,c.default.autoZIndex,c.default.zIndex.overlay),this.alignOverlay()}},{key:"onOverlayEntering",value:function(){this.props.autoHighlight&&this.props.suggestions&&this.props.suggestions.length&&n.DomHandler.addClass(this.list.firstChild,"p-highlight")}},{key:"onOverlayEntered",value:function(){this.bindDocumentClickListener(),this.bindScrollListener(),this.bindResizeListener(),this.props.onShow&&this.props.onShow()}},{key:"onOverlayExit",value:function(){this.unbindDocumentClickListener(),this.unbindScrollListener(),this.unbindResizeListener()}},{key:"onOverlayExited",value:function(){n.ZIndexUtils.clear(this.overlayRef.current),this.props.onHide&&this.props.onHide()}},{key:"alignOverlay",value:function(){var e=this.state.trigger,t=e.key,r=e.index,i=this.inputRef.current.value,o=n.DomHandler.getCursorOffset(this.inputRef.current,i.substring(0,r-1),i.substring(r),t);this.overlayRef.current.style.transformOrigin="top",this.overlayRef.current.style.left="calc(".concat(o.left,"px + 1rem)"),this.overlayRef.current.style.top="calc(".concat(o.top,"px + 1.2rem)")}},{key:"onPanelClick",value:function(e){i.OverlayService.emit("overlay-click",{originalEvent:e,target:this.container})}},{key:"getTrigger",value:function(e,t,n){if(!this.state.trigger){var r=Array.isArray(this.props.trigger)?this.props.trigger.find((function(e){return e===t})):this.props.trigger===t?this.props.trigger:null;if(r)return{key:r,index:n};var i=e.substring(0,n).lastIndexOf(" "),o=this.getLatestTrigger(e,n);if(o.index>i)return o}return this.state.trigger}},{key:"getLatestTrigger",value:function(e,t){if(Array.isArray(this.props.trigger)){var n={};return this.props.trigger.forEach((function(r){var i=e.substring(0,t).lastIndexOf(r);-1!==i&&(i>n.index||!n.index)&&(n={key:r,index:-1!==i?i+1:-1})})),n}var r=e.substring(0,t).lastIndexOf(this.props.trigger);return{key:this.props.trigger,index:-1!==r?r+1:-1}}},{key:"onSearch",value:function(e){var t=this;this.timeout&&clearTimeout(this.timeout);var n=e.target,r=n.value,i=n.selectionStart,o=r.substring(i-1,i);if(" "!==o){var s=this.getTrigger(r,o,i);if(s&&s.index>-1){var l=r.substring(s.index,i);this.timeout=setTimeout((function(){t.search(e,l,s)}),this.props.delay)}}else this.hideOverlay()}},{key:"search",value:function(e,t,n){this.props.onSearch&&(this.setState({searching:!0,trigger:n}),this.props.onSearch({originalEvent:e,trigger:n.key,query:t}))}},{key:"selectItem",value:function(e,t){var n=this.inputRef.current.value,r=e.target.selectionStart,i=this.state.trigger,o=n.indexOf(" ",i.index),s=n.substring(i.index,o>-1?o:r),l=this.formatValue(t).replace(/\s+/g,"");if(s.trim()!==l){for(var a=0;a<l.length;){var u=l.charAt(a),p=s.charAt(a);if(u!==p&&" "!==p)break;a++}var c=n.substring(0,i.index),h=n.substring(i.index+a);this.inputRef.current.value="".concat(c).concat(l," ").concat(h),this.props.onChange&&this.props.onChange(e)}var f=i.index+l.length+1;this.inputRef.current.setSelectionRange(f,f),this.hideOverlay(),this.props.onSelect&&this.props.onSelect({originalEvent:e,suggestion:t})}},{key:"formatValue",value:function(e){var t=this;if(e){var r=Array.isArray(this.props.field)?this.props.field[this.props.trigger.findIndex((function(e){return e===t.state.trigger.key}))]:this.props.field;return r?n.ObjectUtils.resolveFieldData(e,r):e}return""}},{key:"onItemClick",value:function(e,t){this.inputRef.current.focus(),this.selectItem(e,t)}},{key:"onFocus",value:function(e){var t=this;e.persist(),this.setState({focused:!0},(function(){t.props.onFocus&&t.props.onFocus(e)}))}},{key:"onBlur",value:function(e){var t=this;e.persist(),this.setState({focused:!1},(function(){t.props.onBlur&&t.props.onBlur(e)}))}},{key:"onInput",value:function(e){this.props.onInput&&this.props.onInput(e),e.target.value.length>0?n.DomHandler.addClass(this.container,"p-inputwrapper-filled"):n.DomHandler.removeClass(this.container,"p-inputwrapper-filled")}},{key:"onKeyUp",value:function(e){37!==e.which&&39!==e.which||this.onSearch(e)}},{key:"onChange",value:function(e){this.props.onChange&&this.props.onChange(e),this.onSearch(e)}},{key:"onKeyDown",value:function(e){if(this.state.overlayVisible){var t=n.DomHandler.findSingle(this.overlayRef.current,"li.p-highlight");switch(e.which){case 40:if(t){var r=t.nextElementSibling;r&&(n.DomHandler.addClass(r,"p-highlight"),n.DomHandler.removeClass(t,"p-highlight"),n.DomHandler.scrollInView(this.overlayRef.current,r))}else(t=n.DomHandler.findSingle(this.overlayRef.current,"li"))&&n.DomHandler.addClass(t,"p-highlight");e.preventDefault();break;case 38:if(t){var i=t.previousElementSibling;i&&(n.DomHandler.addClass(i,"p-highlight"),n.DomHandler.removeClass(t,"p-highlight"),n.DomHandler.scrollInView(this.overlayRef.current,i))}e.preventDefault();break;case 8:var o=e.target,s=o.selectionStart;o.value.substring(s-1,s)===this.state.trigger.key&&this.hideOverlay();break;case 13:t&&this.selectItem(e,this.props.suggestions[n.DomHandler.index(t)]),e.preventDefault();break;case 27:this.hideOverlay(),e.preventDefault()}}}},{key:"bindDocumentClickListener",value:function(){var e=this;this.documentClickListener||(this.documentClickListener=function(t){3!==t.which&&e.state.overlayVisible&&e.isOutsideClicked(t)&&e.hideOverlay()},document.addEventListener("click",this.documentClickListener))}},{key:"unbindDocumentClickListener",value:function(){this.documentClickListener&&(document.removeEventListener("click",this.documentClickListener),this.documentClickListener=null)}},{key:"bindScrollListener",value:function(){var e=this;this.scrollHandler||(this.scrollHandler=new n.ConnectedOverlayScrollHandler(this.container,(function(){e.state.overlayVisible&&e.hideOverlay()}))),this.scrollHandler.bindScrollListener()}},{key:"unbindScrollListener",value:function(){this.scrollHandler&&this.scrollHandler.unbindScrollListener()}},{key:"bindResizeListener",value:function(){var e=this;this.resizeListener||(this.resizeListener=function(){e.state.overlayVisible&&!n.DomHandler.isTouchDevice()&&e.hideOverlay()},window.addEventListener("resize",this.resizeListener))}},{key:"unbindResizeListener",value:function(){this.resizeListener&&(window.removeEventListener("resize",this.resizeListener),this.resizeListener=null)}},{key:"isOutsideClicked",value:function(e){return this.container&&this.overlayRef&&this.overlayRef.current&&!this.overlayRef.current.contains(e.target)}},{key:"isFilled",value:function(){return null!=this.props.value&&this.props.value.toString().length>0||null!=this.props.defaultValue&&this.props.defaultValue.toString().length>0||this.inputRef&&this.inputRef.current&&this.inputRef.current.value.toString().length>0}},{key:"updateInputRef",value:function(){var e=this.props.inputRef;e&&("function"==typeof e?e(this.inputRef.current):e.current=this.inputRef.current)}},{key:"componentDidMount",value:function(){this.updateInputRef()}},{key:"componentDidUpdate",value:function(e){e.suggestions!==this.props.suggestions&&this.state.searching&&(this.props.suggestions&&this.props.suggestions.length?this.showOverlay():this.hideOverlay(),this.state.overlayVisible&&this.alignOverlay(),this.setState({searching:!1})),!this.isFilled()&&n.DomHandler.hasClass(this.container,"p-inputwrapper-filled")&&n.DomHandler.removeClass(this.container,"p-inputwrapper-filled")}},{key:"componentWillUnmount",value:function(){this.unbindDocumentClickListener(),this.unbindResizeListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),n.ZIndexUtils.clear(this.overlayRef.current)}},{key:"renderItem",value:function(e,t){var i=this,o=this.props.itemTemplate?n.ObjectUtils.getJSXElement(this.props.itemTemplate,e,{trigger:this.state.trigger?this.state.trigger.key:"",index:t}):this.formatValue(e);return p.default.createElement("li",{key:t+"_item",className:"p-mention-item",onClick:function(t){return i.onItemClick(t,e)}},o,p.default.createElement(r.Ripple,null))}},{key:"renderList",value:function(){var e=this;if(this.props.suggestions){var t=this.props.suggestions.map((function(t,n){return e.renderItem(t,n)}));return p.default.createElement("ul",{ref:function(t){return e.list=t},className:"p-mention-items"},t)}return null}},{key:"renderPanel",value:function(){var e=n.classNames("p-mention-panel p-component",this.props.panelClassName),t=H({maxHeight:this.props.scrollHeight},this.props.panelStyle),r=n.ObjectUtils.getJSXElement(this.props.headerTemplate,this.props),i=n.ObjectUtils.getJSXElement(this.props.footerTemplate,this.props),l=this.renderList();return p.default.createElement(s.Portal,{element:p.default.createElement(o.CSSTransition,{nodeRef:this.overlayRef,classNames:"p-connected-overlay",in:this.state.overlayVisible,timeout:{enter:120,exit:100},options:this.props.transitionOptions,unmountOnExit:!0,onEnter:this.onOverlayEnter,onEntering:this.onOverlayEntering,onEntered:this.onOverlayEntered,onExit:this.onOverlayExit,onExited:this.onOverlayExited},p.default.createElement("div",{ref:this.overlayRef,className:e,style:t,onClick:this.onPanelClick},r,l,i)),appendTo:"self"})}},{key:"render",value:function(){var e=this,t=n.classNames("p-mention p-component p-inputwrapper",{"p-inputwrapper-filled":this.isFilled(),"p-inputwrapper-focus":this.state.focused},this.props.className),r=n.classNames("p-mention-input",this.props.inputClassName),i=n.ObjectUtils.findDiffKeys(this.props,d.defaultProps),o=this.renderPanel();return p.default.createElement("div",{ref:function(t){return e.container=t},id:this.props.id,className:t,style:this.props.style},p.default.createElement(x,h({ref:this.inputRef,id:this.props.inputId},i,{className:r,style:this.props.inputStyle,onFocus:this.onFocus,onBlur:this.onBlur,onKeyDown:this.onKeyDown,onInput:this.onInput,onKeyUp:this.onKeyUp,onChange:this.onChange})),o)}}]),d}(t.Component);return R(P,"defaultProps",{id:null,inputId:null,inputRef:null,style:null,className:null,trigger:"@",suggestions:null,field:null,inputStyle:null,inputClassName:null,panelClassName:null,panelStyle:null,scrollHeight:"200px",autoHighlight:!0,delay:0,headerTemplate:null,footerTemplate:null,itemTemplate:null,transitionOptions:null,onChange:null,onInput:null,onSearch:null,onSelect:null,onFocus:null,onBlur:null,onShow:null,onHide:null}),e.Mention=P,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.utils,primereact.ripple,primereact.overlayservice,primereact.csstransition,primereact.portal,primereact.tooltip,primereact.api);
|