2 lines
13 KiB
JavaScript
2 lines
13 KiB
JavaScript
this.primereact=this.primereact||{},this.primereact.tooltip=function(t,e,n,i,o,r){"use strict";function s(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var a=s(e),l=s(n),u=s(r);function c(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function p(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}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 f(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 v(t){return v="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},v(t)}function g(t,e){if(e&&("object"===v(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 y(t){return y=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},y(t)}function m(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function T(){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}}function b(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function E(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?b(Object(n),!0).forEach((function(e){m(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):b(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var w=function(t){f(b,t);var e,n,r,s,d,v=(e=b,n=T(),function(){var t,i=y(e);if(n){var o=y(this).constructor;t=Reflect.construct(i,arguments,o)}else t=i.apply(this,arguments);return g(this,t)});function b(t){var e;return c(this,b),(e=v.call(this,t)).state={visible:!1,position:e.props.position},e.show=e.show.bind(h(e)),e.hide=e.hide.bind(h(e)),e.onMouseEnter=e.onMouseEnter.bind(h(e)),e.onMouseLeave=e.onMouseLeave.bind(h(e)),e}return r=b,s=[{key:"isTargetContentEmpty",value:function(t){return!(this.props.content||this.getTargetOption(t,"tooltip"))}},{key:"isContentEmpty",value:function(t){return!(this.props.content||this.getTargetOption(t,"tooltip")||this.props.children)}},{key:"isMouseTrack",value:function(t){return this.getTargetOption(t,"mousetrack")||this.props.mouseTrack}},{key:"isDisabled",value:function(t){return"true"===this.getTargetOption(t,"disabled")||this.hasTargetOption(t,"disabled")||this.props.disabled}},{key:"isShowOnDisabled",value:function(t){return this.getTargetOption(t,"showondisabled")||this.props.showOnDisabled}},{key:"isAutoHide",value:function(){return this.getTargetOption(this.currentTarget,"autohide")||this.props.autoHide}},{key:"getTargetOption",value:function(t,e){return this.hasTargetOption(t,"data-pr-".concat(e))?t.getAttribute("data-pr-".concat(e)):null}},{key:"hasTargetOption",value:function(t,e){return t&&t.hasAttribute(e)}},{key:"getEvents",value:function(t){var e=this.getTargetOption(t,"showevent")||this.props.showEvent,n=this.getTargetOption(t,"hideevent")||this.props.hideEvent;return this.isMouseTrack(t)?(e="mousemove",n="mouseleave"):"focus"===(this.getTargetOption(t,"event")||this.props.event)&&(e="focus",n="blur"),{showEvent:e,hideEvent:n}}},{key:"getPosition",value:function(t){return this.getTargetOption(t,"position")||this.state.position}},{key:"getMouseTrackPosition",value:function(t){return{top:this.getTargetOption(t,"mousetracktop")||this.props.mouseTrackTop,left:this.getTargetOption(t,"mousetrackleft")||this.props.mouseTrackLeft}}},{key:"updateText",value:function(t,e){if(this.tooltipTextEl){var n=this.getTargetOption(t,"tooltip")||this.props.content;n?(this.tooltipTextEl.innerHTML="",this.tooltipTextEl.appendChild(document.createTextNode(n)),e()):this.props.children&&e()}}},{key:"show",value:function(t){var e=this;this.currentTarget=t.currentTarget;var n=this.isDisabled(this.currentTarget);if(!this.isContentEmpty(this.isShowOnDisabled(this.currentTarget)&&n?this.currentTarget.firstChild:this.currentTarget)&&!n){var o=function(){e.updateText(e.currentTarget,(function(){e.props.autoZIndex&&!i.ZIndexUtils.get(e.containerEl)&&i.ZIndexUtils.set("tooltip",e.containerEl,u.default.autoZIndex,e.props.baseZIndex||u.default.zIndex.tooltip),e.containerEl.style.left="",e.containerEl.style.top="",e.isMouseTrack(e.currentTarget)&&!e.containerSize&&(e.containerSize={width:i.DomHandler.getOuterWidth(e.containerEl),height:i.DomHandler.getOuterHeight(e.containerEl)}),e.align(e.currentTarget,{x:t.pageX,y:t.pageY})}))};this.state.visible?this.applyDelay("updateDelay",o):(this.sendCallback(this.props.onBeforeShow,{originalEvent:t,target:this.currentTarget}),this.applyDelay("showDelay",(function(){e.setState({visible:!0,position:e.getPosition(e.currentTarget)},(function(){o(),e.sendCallback(e.props.onShow,{originalEvent:t,target:e.currentTarget})})),e.bindDocumentResizeListener(),e.bindScrollListener(),i.DomHandler.addClass(e.currentTarget,e.getTargetOption(e.currentTarget,"classname"))})))}}},{key:"hide",value:function(t){var e=this;this.clearTimeouts(),this.state.visible&&(i.DomHandler.removeClass(this.currentTarget,this.getTargetOption(this.currentTarget,"classname")),this.sendCallback(this.props.onBeforeHide,{originalEvent:t,target:this.currentTarget}),this.applyDelay("hideDelay",(function(){i.ZIndexUtils.clear(e.containerEl),i.DomHandler.removeClass(e.containerEl,"p-tooltip-active"),(e.isAutoHide()||!1!==e.allowHide)&&e.setState({visible:!1,position:e.props.position},(function(){e.tooltipTextEl&&l.default.unmountComponentAtNode(e.tooltipTextEl),e.unbindDocumentResizeListener(),e.unbindScrollListener(),e.currentTarget=null,e.scrollHandler=null,e.containerSize=null,e.allowHide=!0,e.sendCallback(e.props.onHide,{originalEvent:t,target:e.currentTarget})}))})))}},{key:"align",value:function(t,e){var n=this,o=0,r=0;if(this.isMouseTrack(t)&&e){var s={width:i.DomHandler.getOuterWidth(this.containerEl),height:i.DomHandler.getOuterHeight(this.containerEl)};o=e.x,r=e.y;var a=this.getMouseTrackPosition(t),l=a.top,u=a.left;switch(this.state.position){case"left":o-=s.width+u,r-=s.height/2-l;break;case"right":o+=u,r-=s.height/2-l;break;case"top":o-=s.width/2-u,r-=s.height+l;break;case"bottom":o-=s.width/2-u,r+=l}o<=0||this.containerSize.width>s.width?(this.containerEl.style.left="0px",this.containerEl.style.right=window.innerWidth-s.width-o+"px"):(this.containerEl.style.right="",this.containerEl.style.left=o+"px"),this.containerEl.style.top=r+"px",i.DomHandler.addClass(this.containerEl,"p-tooltip-active")}else{var c=i.DomHandler.findCollisionPosition(this.state.position),p=this.getTargetOption(t,"my")||this.props.my||c.my,h=this.getTargetOption(t,"at")||this.props.at||c.at;this.containerEl.style.padding="0px",i.DomHandler.flipfitCollision(this.containerEl,t,p,h,(function(t){var e=t.at,o=e.x,r=n.props.at?"center"!==o&&o!==t.my.x?o:e.y:t.at["".concat(c.axis)];n.containerEl.style.padding="",n.setState({position:r},(function(){n.updateContainerPosition(),i.DomHandler.addClass(n.containerEl,"p-tooltip-active")}))}))}}},{key:"updateContainerPosition",value:function(){if(this.containerEl){var t=getComputedStyle(this.containerEl);"left"===this.state.position?this.containerEl.style.left=parseFloat(t.left)-2*parseFloat(t.paddingLeft)+"px":"top"===this.state.position&&(this.containerEl.style.top=parseFloat(t.top)-2*parseFloat(t.paddingTop)+"px")}}},{key:"onMouseEnter",value:function(){this.isAutoHide()||(this.allowHide=!1)}},{key:"onMouseLeave",value:function(t){this.isAutoHide()||(this.allowHide=!0,this.hide(t))}},{key:"bindDocumentResizeListener",value:function(){var t=this;this.documentResizeListener=function(e){i.DomHandler.isTouchDevice()||t.hide(e)},window.addEventListener("resize",this.documentResizeListener)}},{key:"unbindDocumentResizeListener",value:function(){this.documentResizeListener&&(window.removeEventListener("resize",this.documentResizeListener),this.documentResizeListener=null)}},{key:"bindScrollListener",value:function(){var t=this;this.scrollHandler||(this.scrollHandler=new i.ConnectedOverlayScrollHandler(this.currentTarget,(function(e){t.state.visible&&t.hide(e)}))),this.scrollHandler.bindScrollListener()}},{key:"unbindScrollListener",value:function(){this.scrollHandler&&this.scrollHandler.unbindScrollListener()}},{key:"bindTargetEvent",value:function(t){if(t){var e=this.getEvents(t),n=e.showEvent,i=e.hideEvent,o=this.getTarget(t);o.addEventListener(n,this.show),o.addEventListener(i,this.hide)}}},{key:"unbindTargetEvent",value:function(t){if(t){var e=this.getEvents(t),n=e.showEvent,i=e.hideEvent,o=this.getTarget(t);o.removeEventListener(n,this.show),o.removeEventListener(i,this.hide)}}},{key:"applyDelay",value:function(t,e){this.clearTimeouts();var n=this.getTargetOption(this.currentTarget,t.toLowerCase())||this.props[t];n?this["".concat(t,"Timeout")]=setTimeout((function(){return e()}),n):e()}},{key:"sendCallback",value:function(t){if(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),i=1;i<e;i++)n[i-1]=arguments[i];t.apply(void 0,n)}}},{key:"clearTimeouts",value:function(){clearTimeout(this.showDelayTimeout),clearTimeout(this.updateDelayTimeout),clearTimeout(this.hideDelayTimeout)}},{key:"getTarget",value:function(t){if(t){if(this.isShowOnDisabled(t)){var e=document.createElement("span");return t.parentNode.insertBefore(e,t),e.appendChild(t),e}return t}return null}},{key:"updateTargetEvents",value:function(t){this.unloadTargetEvents(t),this.loadTargetEvents(t)}},{key:"loadTargetEvents",value:function(t){this.setTargetEventOperations(t||this.props.target,"bindTargetEvent")}},{key:"unloadTargetEvents",value:function(t){this.setTargetEventOperations(t||this.props.target,"unbindTargetEvent")}},{key:"setTargetEventOperations",value:function(t,e){var n=this;if(t)if(i.DomHandler.isElement(t))this[e](t);else{var o=function(t){i.DomHandler.find(document,t).forEach((function(t){n[e](t)}))};t instanceof Array?t.forEach((function(t){o(t)})):o(t)}}},{key:"componentDidMount",value:function(){this.props.target&&this.loadTargetEvents()}},{key:"componentDidUpdate",value:function(t,e){var n=this;t.target!==this.props.target&&(this.unloadTargetEvents(t.target),this.loadTargetEvents()),this.state.visible&&(t.content!==this.props.content&&this.applyDelay("updateDelay",(function(){n.updateText(n.currentTarget,(function(){n.align(n.currentTarget)}))})),this.currentTarget&&this.isDisabled(this.currentTarget)&&this.hide())}},{key:"componentWillUnmount",value:function(){this.clearTimeouts(),this.unbindDocumentResizeListener(),this.unloadTargetEvents(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),i.ZIndexUtils.clear(this.containerEl)}},{key:"renderElement",value:function(){var t=this,e=i.classNames("p-tooltip p-component",m({},"p-tooltip-".concat(this.state.position),!0),this.props.className),n=this.isTargetContentEmpty(this.currentTarget);return a.default.createElement("div",{id:this.props.id,ref:function(e){return t.containerEl=e},className:e,style:this.props.style,role:"tooltip","aria-hidden":this.state.visible,onMouseEnter:this.onMouseEnter,onMouseLeave:this.onMouseLeave},a.default.createElement("div",{className:"p-tooltip-arrow"}),a.default.createElement("div",{ref:function(e){return t.tooltipTextEl=e},className:"p-tooltip-text"},n&&this.props.children))}},{key:"render",value:function(){if(this.state.visible){var t=this.renderElement();return a.default.createElement(o.Portal,{element:t,appendTo:this.props.appendTo,visible:!0})}return null}}],s&&p(r.prototype,s),d&&p(r,d),Object.defineProperty(r,"prototype",{writable:!1}),b}(e.Component);return m(w,"defaultProps",{id:null,target:null,content:null,disabled:!1,className:null,style:null,appendTo:null,position:"right",my:null,at:null,event:null,showEvent:"mouseenter",hideEvent:"mouseleave",autoZIndex:!0,baseZIndex:0,mouseTrack:!1,mouseTrackTop:5,mouseTrackLeft:5,showDelay:0,updateDelay:0,hideDelay:0,autoHide:!0,showOnDisabled:!1,onBeforeShow:null,onBeforeHide:null,onShow:null,onHide:null}),t.Tooltip=w,t.tip=function(t){var e=t.appendTo||document.body,n=document.createDocumentFragment();i.DomHandler.appendChild(n,e),t=E(E({},t),t.options);var o=a.default.createElement(w,t);l.default.render(o,n);var r=function(e){t=E(E({},t),e),l.default.render(a.default.cloneElement(o,t),n)};return{destroy:function(){l.default.unmountComponentAtNode(n)},updateContent:function(t){console.warn("The 'updateContent' method has been deprecated on Tooltip. Use update(newProps) method."),r({content:t})},update:function(t){r(t)}}},Object.defineProperty(t,"__esModule",{value:!0}),t}({},React,ReactDOM,primereact.utils,primereact.portal,primereact.api);
|