primevue
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primevue) [ • 11.1 kB
JavaScript
import{UniqueComponentId as t,ObjectUtils as e,ConnectedOverlayScrollHandler as o,DomHandler as i,ZIndexUtils as n}from"primevue/utils";import l from"primevue/basedirective";import{useStyle as r}from"primevue/usestyle";var s=r("\n.p-tooltip {\n position:absolute;\n display:none;\n padding: .25em .5rem;\n max-width: 12.5rem;\n}\n\n.p-tooltip.p-tooltip-right,\n.p-tooltip.p-tooltip-left {\n padding: 0 .25rem;\n}\n\n.p-tooltip.p-tooltip-top,\n.p-tooltip.p-tooltip-bottom {\n padding:.25em 0;\n}\n\n.p-tooltip .p-tooltip-text {\n white-space: pre-line;\n word-break: break-word;\n}\n\n.p-tooltip-arrow {\n position: absolute;\n width: 0;\n height: 0;\n border-color: transparent;\n border-style: solid;\n}\n\n.p-tooltip-right .p-tooltip-arrow {\n top: 50%;\n left: 0;\n margin-top: -.25rem;\n border-width: .25em .25em .25em 0;\n}\n\n.p-tooltip-left .p-tooltip-arrow {\n top: 50%;\n right: 0;\n margin-top: -.25rem;\n border-width: .25em 0 .25em .25rem;\n}\n\n.p-tooltip.p-tooltip-top {\n padding: .25em 0;\n}\n\n.p-tooltip-top .p-tooltip-arrow {\n bottom: 0;\n left: 50%;\n margin-left: -.25rem;\n border-width: .25em .25em 0;\n}\n\n.p-tooltip-bottom .p-tooltip-arrow {\n top: 0;\n left: 50%;\n margin-left: -.25rem;\n border-width: 0 .25em .25rem;\n}\n",{name:"tooltip",manual:!0});function p(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function a(t,e){if(t){if("string"==typeof t)return u(t,e);var o=Object.prototype.toString.call(t).slice(8,-1);return"Object"===o&&t.constructor&&(o=t.constructor.name),"Map"===o||"Set"===o?Array.from(t):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?u(t,e):void 0}}function u(t,e){(null==e||e>t.length)&&(e=t.length);for(var o=0,i=new Array(e);o<e;o++)i[o]=t[o];return i}function d(t,e){var o=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=o){var i,n,l,r,s=[],p=!0,a=!1;try{if(l=(o=o.call(t)).next,0===e){if(Object(o)!==o)return;p=!1}else for(;!(p=(i=l.call(o)).done)&&(s.push(i.value),s.length!==e);p=!0);}catch(t){a=!0,n=t}finally{try{if(!p&&null!=o.return&&(r=o.return(),Object(r)!==r))return}finally{if(a)throw n}}return s}}function c(t){if(Array.isArray(t))return t}function h(t){return h="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},h(t)}var v=l.extend({css:{classes:{root:"p-tooltip p-component",arrow:"p-tooltip-arrow",text:"p-tooltip-text"},loadStyle:s.load}}).extend("tooltip",{beforeMount:function(o,i){var n,l,r,s=this.getTarget(o);if(s.$_ptooltipModifiers=this.getModifiers(i),i.value){if("string"==typeof i.value)s.$_ptooltipValue=i.value,s.$_ptooltipDisabled=!1,s.$_ptooltipEscape=!1,s.$_ptooltipClass=null,s.$_ptooltipFitContent=!0,s.$_ptooltipIdAttr=t()+"_tooltip",s.$_ptooltipShowDelay=0,s.$_ptooltipHideDelay=0;else if("object"===h(i.value)&&i.value){if(e.isEmpty(i.value.value)||""===i.value.value.trim())return;s.$_ptooltipValue=i.value.value,s.$_ptooltipDisabled=!!i.value.disabled===i.value.disabled&&i.value.disabled,s.$_ptooltipEscape=!!i.value.escape===i.value.escape&&i.value.escape,s.$_ptooltipClass=i.value.class||"",s.$_ptooltipFitContent=!!i.value.fitContent!==i.value.fitContent||i.value.fitContent,s.$_ptooltipIdAttr=i.value.id||t()+"_tooltip",s.$_ptooltipShowDelay=i.value.showDelay||0,s.$_ptooltipHideDelay=i.value.hideDelay||0}s.$_ptooltipZIndex=null===(n=i.instance.$primevue)||void 0===n||null===(n=n.config)||void 0===n||null===(n=n.zIndex)||void 0===n?void 0:n.tooltip,s.unstyled=(null===(l=i.instance.$primevue)||void 0===l||null===(l=l.config)||void 0===l?void 0:l.unstyled)||(null===(r=i.value)||void 0===r?void 0:r.unstyled)||!1,this.bindEvents(s,i),o.setAttribute("data-pd-tooltip",!0)}},updated:function(o,i){var n,l,r=this.getTarget(o);if(r.$_ptooltipModifiers=this.getModifiers(i),this.unbindEvents(r),i.value){if("string"==typeof i.value)r.$_ptooltipValue=i.value,r.$_ptooltipDisabled=!1,r.$_ptooltipEscape=!1,r.$_ptooltipClass=null,r.$_ptooltipIdAttr=r.$_ptooltipIdAttr||t()+"_tooltip",r.$_ptooltipShowDelay=0,r.$_ptooltipHideDelay=0,this.bindEvents(r,i);else if("object"===h(i.value)&&i.value){if(e.isEmpty(i.value.value)||""===i.value.value.trim())return void this.unbindEvents(r,i);r.$_ptooltipValue=i.value.value,r.$_ptooltipDisabled=!!i.value.disabled===i.value.disabled&&i.value.disabled,r.$_ptooltipEscape=!!i.value.escape===i.value.escape&&i.value.escape,r.$_ptooltipClass=i.value.class||"",r.$_ptooltipFitContent=!!i.value.fitContent!==i.value.fitContent||i.value.fitContent,r.$_ptooltipIdAttr=i.value.id||r.$_ptooltipIdAttr||t()+"_tooltip",r.$_ptooltipShowDelay=i.value.showDelay||0,r.$_ptooltipHideDelay=i.value.hideDelay||0,this.bindEvents(r,i)}r.unstyled=(null===(n=i.instance.$primevue)||void 0===n||null===(n=n.config)||void 0===n?void 0:n.unstyled)||(null===(l=i.value)||void 0===l?void 0:l.unstyled)||!1}},unmounted:function(t,e){var o=this.getTarget(t);this.remove(o),this.unbindEvents(o,e),o.$_ptooltipScrollHandler&&(o.$_ptooltipScrollHandler.destroy(),o.$_ptooltipScrollHandler=null)},timer:void 0,methods:{bindEvents:function(t,e){var o=this;t.$_ptooltipModifiers.focus?(t.$_focusevent=function(t){return o.onFocus(t,e)},t.addEventListener("focus",t.$_focusevent),t.addEventListener("blur",this.onBlur.bind(this))):(t.$_mouseenterevent=function(t){return o.onMouseEnter(t,e)},t.addEventListener("mouseenter",t.$_mouseenterevent),t.addEventListener("mouseleave",this.onMouseLeave.bind(this)),t.addEventListener("click",this.onClick.bind(this))),t.addEventListener("keydown",this.onKeydown.bind(this))},unbindEvents:function(t){t.$_ptooltipModifiers.focus?(t.removeEventListener("focus",t.$_focusevent),t.$_focusevent=null,t.removeEventListener("blur",this.onBlur.bind(this))):(t.removeEventListener("mouseenter",t.$_mouseenterevent),t.$_mouseenterevent=null,t.removeEventListener("mouseleave",this.onMouseLeave.bind(this)),t.removeEventListener("click",this.onClick.bind(this))),t.removeEventListener("keydown",this.onKeydown.bind(this))},bindScrollListener:function(t){var e=this;t.$_ptooltipScrollHandler||(t.$_ptooltipScrollHandler=new o(t,(function(){e.hide(t)}))),t.$_ptooltipScrollHandler.bindScrollListener()},unbindScrollListener:function(t){t.$_ptooltipScrollHandler&&t.$_ptooltipScrollHandler.unbindScrollListener()},onMouseEnter:function(t,e){var o=t.currentTarget;this.show(o,e,o.$_ptooltipShowDelay)},onMouseLeave:function(t){var e=t.currentTarget;this.hide(e,e.$_ptooltipHideDelay)},onFocus:function(t,e){var o=t.currentTarget;this.show(o,e,o.$_ptooltipShowDelay)},onBlur:function(t){var e=t.currentTarget;this.hide(e,e.$_ptooltipHideDelay)},onClick:function(t){var e=t.currentTarget;this.hide(e,e.$_ptooltipHideDelay)},onKeydown:function(t){"Escape"===t.code&&this.hide(t.currentTarget,t.currentTarget.$_ptooltipHideDelay)},tooltipActions:function(t,e){if(!t.$_ptooltipDisabled&&i.isExist(t)){var o=this.create(t,e);this.align(t),!t.unstyled&&i.fadeIn(o,250);var l=this;window.addEventListener("resize",(function e(){i.isTouchDevice()||l.hide(t),window.removeEventListener("resize",e)})),this.bindScrollListener(t),n.set("tooltip",o,t.$_ptooltipZIndex)}},show:function(t,e,o){var i=this;void 0!==o?this.timer=setTimeout((function(){return i.tooltipActions(t,e)}),o):this.tooltipActions(t,e)},tooltipRemoval:function(t){this.remove(t),this.unbindScrollListener(t)},hide:function(t,e){var o=this;clearTimeout(this.timer),void 0!==e?setTimeout((function(){return o.tooltipRemoval(t)}),e):this.tooltipRemoval(t)},getTooltipElement:function(t){return document.getElementById(t.$_ptooltipId)},create:function(t,e){var o=i.createElement("div",{class:!t.unstyled&&this.cx("arrow"),"p-bind":this.ptm("arrow")}),n=i.createElement("div",{class:!t.unstyled&&this.cx("text"),"p-bind":this.ptm("text")});t.$_ptooltipEscape?n.innerHTML=t.$_ptooltipValue:(n.innerHTML="",n.appendChild(document.createTextNode(t.$_ptooltipValue)));var l=i.createElement("div",{id:t.$_ptooltipIdAttr,role:"tooltip",style:{display:"inline-block",width:t.$_ptooltipFitContent?"fit-content":void 0},class:[!t.unstyled&&this.cx("root"),t.$_ptooltipClass],"p-bind":this.ptm("root")},o,n);return document.body.appendChild(l),t.$_ptooltipId=l.id,this.$el=l,l},remove:function(t){if(t){var e=this.getTooltipElement(t);e&&e.parentElement&&(n.clear(e),document.body.removeChild(e)),t.$_ptooltipId=null}},align:function(t){var e=t.$_ptooltipModifiers;e.top?(this.alignTop(t),this.isOutOfBounds(t)&&(this.alignBottom(t),this.isOutOfBounds(t)&&this.alignTop(t))):e.left?(this.alignLeft(t),this.isOutOfBounds(t)&&(this.alignRight(t),this.isOutOfBounds(t)&&(this.alignTop(t),this.isOutOfBounds(t)&&(this.alignBottom(t),this.isOutOfBounds(t)&&this.alignLeft(t))))):e.bottom?(this.alignBottom(t),this.isOutOfBounds(t)&&(this.alignTop(t),this.isOutOfBounds(t)&&this.alignBottom(t))):(this.alignRight(t),this.isOutOfBounds(t)&&(this.alignLeft(t),this.isOutOfBounds(t)&&(this.alignTop(t),this.isOutOfBounds(t)&&(this.alignBottom(t),this.isOutOfBounds(t)&&this.alignRight(t)))))},getHostOffset:function(t){var e=t.getBoundingClientRect();return{left:e.left+i.getWindowScrollLeft(),top:e.top+i.getWindowScrollTop()}},alignRight:function(t){this.preAlign(t,"right");var e=this.getTooltipElement(t),o=this.getHostOffset(t),n=o.left+i.getOuterWidth(t),l=o.top+(i.getOuterHeight(t)-i.getOuterHeight(e))/2;e.style.left=n+"px",e.style.top=l+"px"},alignLeft:function(t){this.preAlign(t,"left");var e=this.getTooltipElement(t),o=this.getHostOffset(t),n=o.left-i.getOuterWidth(e),l=o.top+(i.getOuterHeight(t)-i.getOuterHeight(e))/2;e.style.left=n+"px",e.style.top=l+"px"},alignTop:function(t){this.preAlign(t,"top");var e=this.getTooltipElement(t),o=this.getHostOffset(t),n=o.left+(i.getOuterWidth(t)-i.getOuterWidth(e))/2,l=o.top-i.getOuterHeight(e);e.style.left=n+"px",e.style.top=l+"px"},alignBottom:function(t){this.preAlign(t,"bottom");var e=this.getTooltipElement(t),o=this.getHostOffset(t),n=o.left+(i.getOuterWidth(t)-i.getOuterWidth(e))/2,l=o.top+i.getOuterHeight(t);e.style.left=n+"px",e.style.top=l+"px"},preAlign:function(t,e){var o=this.getTooltipElement(t);o.style.left="-999px",o.style.top="-999px",i.removeClass(o,"p-tooltip-".concat(o.$_ptooltipPosition)),i.addClass(o,"p-tooltip-".concat(e)),o.$_ptooltipPosition=e},isOutOfBounds:function(t){var e=this.getTooltipElement(t),o=e.getBoundingClientRect(),n=o.top,l=o.left,r=i.getOuterWidth(e),s=i.getOuterHeight(e),p=i.getViewport();return l+r>p.width||l<0||n<0||n+s>p.height},getTarget:function(t){return i.hasClass(t,"p-inputwrapper")?i.findSingle(t,"input"):t},getModifiers:function(t){return t.modifiers&&Object.keys(t.modifiers).length?t.modifiers:t.arg&&"object"===h(t.arg)?Object.entries(t.arg).reduce((function(t,e){var o,i,n=(i=2,c(o=e)||d(o,i)||a(o,i)||p()),l=n[0];return"event"!==l&&"position"!==l||(t[n[1]]=!0),t}),{}):{}}}});export{v as default};