katoikia-app/web-ui/web-react/node_modules/primereact/mention/mention.cjs.min.js

2 lines
18 KiB
JavaScript

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils"),n=require("primereact/ripple"),r=require("primereact/overlayservice"),i=require("primereact/csstransition"),o=require("primereact/portal"),s=require("primereact/tooltip"),l=require("primereact/api");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=a(e),p=a(l);function c(){return c=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},c.apply(this,arguments)}function h(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function f(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 d(e,t,n){return t&&f(e.prototype,t),n&&f(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function y(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function v(e,t){return v=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},v(e,t)}function g(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&&v(e,t)}function m(e){return m="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},m(e)}function b(e,t){if(t&&("object"===m(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return y(e)}function O(e){return O=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},O(e)}function k(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function R(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 w(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?R(Object(n),!0).forEach((function(t){k(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):R(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function S(){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 E=function(n){g(l,e.Component);var r,i,o=(r=l,i=S(),function(){var e,t=O(r);if(i){var n=O(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return b(this,e)});function l(t){var n;return h(this,l),(n=o.call(this,t)).onFocus=n.onFocus.bind(y(n)),n.onBlur=n.onBlur.bind(y(n)),n.onKeyUp=n.onKeyUp.bind(y(n)),n.onInput=n.onInput.bind(y(n)),n.elementRef=e.createRef(n.props.forwardRef),n}return d(l,[{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?t.DomHandler.addClass(e.target,"p-filled"):t.DomHandler.removeClass(e.target,"p-filled"),this.props.onInput&&this.props.onInput(e)}},{key:"resize",value:function(e){var n=this.elementRef&&this.elementRef.current;n&&t.DomHandler.isVisible(n)&&(this.cachedScrollHeight||(this.cachedScrollHeight=n.scrollHeight,n.style.overflow="hidden"),(this.cachedScrollHeight!==n.scrollHeight||e)&&(n.style.height="",n.style.height=n.scrollHeight+"px",parseFloat(n.style.height)>=parseFloat(n.style.maxHeight)?(n.style.overflowY="scroll",n.style.height=n.style.maxHeight):n.style.overflow="hidden",this.cachedScrollHeight=n.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(w({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=s.tip({target:this.elementRef.current,content:this.props.tooltip,options:this.props.tooltipOptions})}},{key:"render",value:function(){var e=t.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),n=t.ObjectUtils.findDiffKeys(this.props,l.defaultProps);return u.default.createElement("textarea",c({ref:this.elementRef},n,{className:e,onFocus:this.onFocus,onBlur:this.onBlur,onKeyUp:this.onKeyUp,onInput:this.onInput}))}}]),l}();k(E,"defaultProps",{autoResize:!1,tooltip:null,tooltipOptions:null,onInput:null,forwardRef:null});var x=u.default.forwardRef((function(e,t){return u.default.createElement(E,c({forwardRef:t},e))}));function C(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 D(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?C(Object(n),!0).forEach((function(t){k(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):C(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function H(){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 j=function(s){g(v,e.Component);var l,a,f=(l=v,a=H(),function(){var e,t=O(l);if(a){var n=O(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return b(this,e)});function v(t){var n;return h(this,v),(n=f.call(this,t)).state={overlayVisible:!1,focused:!1,searching:!1,trigger:null},n.onOverlayEnter=n.onOverlayEnter.bind(y(n)),n.onOverlayEntering=n.onOverlayEntering.bind(y(n)),n.onOverlayEntered=n.onOverlayEntered.bind(y(n)),n.onOverlayExit=n.onOverlayExit.bind(y(n)),n.onOverlayExited=n.onOverlayExited.bind(y(n)),n.onFocus=n.onFocus.bind(y(n)),n.onBlur=n.onBlur.bind(y(n)),n.onKeyDown=n.onKeyDown.bind(y(n)),n.onChange=n.onChange.bind(y(n)),n.onInput=n.onInput.bind(y(n)),n.onKeyUp=n.onKeyUp.bind(y(n)),n.onPanelClick=n.onPanelClick.bind(y(n)),n.overlayRef=e.createRef(),n.inputRef=e.createRef(n.props.inputRef),n}return d(v,[{key:"showOverlay",value:function(){this.setState({overlayVisible:!0})}},{key:"hideOverlay",value:function(){this.setState({overlayVisible:!1,searching:!1,trigger:null})}},{key:"onOverlayEnter",value:function(){t.ZIndexUtils.set("overlay",this.overlayRef.current,p.default.autoZIndex,p.default.zIndex.overlay),this.alignOverlay()}},{key:"onOverlayEntering",value:function(){this.props.autoHighlight&&this.props.suggestions&&this.props.suggestions.length&&t.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(){t.ZIndexUtils.clear(this.overlayRef.current),this.props.onHide&&this.props.onHide()}},{key:"alignOverlay",value:function(){var e=this.state.trigger,n=e.key,r=e.index,i=this.inputRef.current.value,o=t.DomHandler.getCursorOffset(this.inputRef.current,i.substring(0,r-1),i.substring(r),n);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){r.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 n=this;if(e){var r=Array.isArray(this.props.field)?this.props.field[this.props.trigger.findIndex((function(e){return e===n.state.trigger.key}))]:this.props.field;return r?t.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?t.DomHandler.addClass(this.container,"p-inputwrapper-filled"):t.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 n=t.DomHandler.findSingle(this.overlayRef.current,"li.p-highlight");switch(e.which){case 40:if(n){var r=n.nextElementSibling;r&&(t.DomHandler.addClass(r,"p-highlight"),t.DomHandler.removeClass(n,"p-highlight"),t.DomHandler.scrollInView(this.overlayRef.current,r))}else(n=t.DomHandler.findSingle(this.overlayRef.current,"li"))&&t.DomHandler.addClass(n,"p-highlight");e.preventDefault();break;case 38:if(n){var i=n.previousElementSibling;i&&(t.DomHandler.addClass(i,"p-highlight"),t.DomHandler.removeClass(n,"p-highlight"),t.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:n&&this.selectItem(e,this.props.suggestions[t.DomHandler.index(n)]),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 t.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&&!t.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()&&t.DomHandler.hasClass(this.container,"p-inputwrapper-filled")&&t.DomHandler.removeClass(this.container,"p-inputwrapper-filled")}},{key:"componentWillUnmount",value:function(){this.unbindDocumentClickListener(),this.unbindResizeListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),t.ZIndexUtils.clear(this.overlayRef.current)}},{key:"renderItem",value:function(e,r){var i=this,o=this.props.itemTemplate?t.ObjectUtils.getJSXElement(this.props.itemTemplate,e,{trigger:this.state.trigger?this.state.trigger.key:"",index:r}):this.formatValue(e);return u.default.createElement("li",{key:r+"_item",className:"p-mention-item",onClick:function(t){return i.onItemClick(t,e)}},o,u.default.createElement(n.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 u.default.createElement("ul",{ref:function(t){return e.list=t},className:"p-mention-items"},t)}return null}},{key:"renderPanel",value:function(){var e=t.classNames("p-mention-panel p-component",this.props.panelClassName),n=D({maxHeight:this.props.scrollHeight},this.props.panelStyle),r=t.ObjectUtils.getJSXElement(this.props.headerTemplate,this.props),s=t.ObjectUtils.getJSXElement(this.props.footerTemplate,this.props),l=this.renderList();return u.default.createElement(o.Portal,{element:u.default.createElement(i.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},u.default.createElement("div",{ref:this.overlayRef,className:e,style:n,onClick:this.onPanelClick},r,l,s)),appendTo:"self"})}},{key:"render",value:function(){var e=this,n=t.classNames("p-mention p-component p-inputwrapper",{"p-inputwrapper-filled":this.isFilled(),"p-inputwrapper-focus":this.state.focused},this.props.className),r=t.classNames("p-mention-input",this.props.inputClassName),i=t.ObjectUtils.findDiffKeys(this.props,v.defaultProps),o=this.renderPanel();return u.default.createElement("div",{ref:function(t){return e.container=t},id:this.props.id,className:n,style:this.props.style},u.default.createElement(x,c({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)}}]),v}();k(j,"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}),exports.Mention=j;