UNPKG

primevue

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primevue.svg)](https://badge.fury.io/js/primevue) [![Discord Chat](https://img.shields.io/discord/55794023

2 lines (1 loc) 11.5 kB
"use strict";var t=require("primevue/utils"),e=require("primevue/basedirective"),o=require("primevue/usestyle");function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=i(e),l=o.useStyle("\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 r(){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 s(t,e){if(t){if("string"==typeof t)return p(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)?p(t,e):void 0}}function p(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 a(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 u(t){if(Array.isArray(t))return t}function d(t){return d="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},d(t)}var c=n.default.extend({css:{classes:{root:"p-tooltip p-component",arrow:"p-tooltip-arrow",text:"p-tooltip-text"},loadStyle:l.load}}).extend("tooltip",{beforeMount:function(e,o){var i,n,l,r=this.getTarget(e);if(r.$_ptooltipModifiers=this.getModifiers(o),o.value){if("string"==typeof o.value)r.$_ptooltipValue=o.value,r.$_ptooltipDisabled=!1,r.$_ptooltipEscape=!1,r.$_ptooltipClass=null,r.$_ptooltipFitContent=!0,r.$_ptooltipIdAttr=t.UniqueComponentId()+"_tooltip",r.$_ptooltipShowDelay=0,r.$_ptooltipHideDelay=0;else if("object"===d(o.value)&&o.value){if(t.ObjectUtils.isEmpty(o.value.value)||""===o.value.value.trim())return;r.$_ptooltipValue=o.value.value,r.$_ptooltipDisabled=!!o.value.disabled===o.value.disabled&&o.value.disabled,r.$_ptooltipEscape=!!o.value.escape===o.value.escape&&o.value.escape,r.$_ptooltipClass=o.value.class||"",r.$_ptooltipFitContent=!!o.value.fitContent!==o.value.fitContent||o.value.fitContent,r.$_ptooltipIdAttr=o.value.id||t.UniqueComponentId()+"_tooltip",r.$_ptooltipShowDelay=o.value.showDelay||0,r.$_ptooltipHideDelay=o.value.hideDelay||0}r.$_ptooltipZIndex=null===(i=o.instance.$primevue)||void 0===i||null===(i=i.config)||void 0===i||null===(i=i.zIndex)||void 0===i?void 0:i.tooltip,r.unstyled=(null===(n=o.instance.$primevue)||void 0===n||null===(n=n.config)||void 0===n?void 0:n.unstyled)||(null===(l=o.value)||void 0===l?void 0:l.unstyled)||!1,this.bindEvents(r,o),e.setAttribute("data-pd-tooltip",!0)}},updated:function(e,o){var i,n,l=this.getTarget(e);if(l.$_ptooltipModifiers=this.getModifiers(o),this.unbindEvents(l),o.value){if("string"==typeof o.value)l.$_ptooltipValue=o.value,l.$_ptooltipDisabled=!1,l.$_ptooltipEscape=!1,l.$_ptooltipClass=null,l.$_ptooltipIdAttr=l.$_ptooltipIdAttr||t.UniqueComponentId()+"_tooltip",l.$_ptooltipShowDelay=0,l.$_ptooltipHideDelay=0,this.bindEvents(l,o);else if("object"===d(o.value)&&o.value){if(t.ObjectUtils.isEmpty(o.value.value)||""===o.value.value.trim())return void this.unbindEvents(l,o);l.$_ptooltipValue=o.value.value,l.$_ptooltipDisabled=!!o.value.disabled===o.value.disabled&&o.value.disabled,l.$_ptooltipEscape=!!o.value.escape===o.value.escape&&o.value.escape,l.$_ptooltipClass=o.value.class||"",l.$_ptooltipFitContent=!!o.value.fitContent!==o.value.fitContent||o.value.fitContent,l.$_ptooltipIdAttr=o.value.id||l.$_ptooltipIdAttr||t.UniqueComponentId()+"_tooltip",l.$_ptooltipShowDelay=o.value.showDelay||0,l.$_ptooltipHideDelay=o.value.hideDelay||0,this.bindEvents(l,o)}l.unstyled=(null===(i=o.instance.$primevue)||void 0===i||null===(i=i.config)||void 0===i?void 0:i.unstyled)||(null===(n=o.value)||void 0===n?void 0:n.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(e){var o=this;e.$_ptooltipScrollHandler||(e.$_ptooltipScrollHandler=new t.ConnectedOverlayScrollHandler(e,(function(){o.hide(e)}))),e.$_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(e,o){if(!e.$_ptooltipDisabled&&t.DomHandler.isExist(e)){var i=this.create(e,o);this.align(e),!e.unstyled&&t.DomHandler.fadeIn(i,250);var n=this;window.addEventListener("resize",(function o(){t.DomHandler.isTouchDevice()||n.hide(e),window.removeEventListener("resize",o)})),this.bindScrollListener(e),t.ZIndexUtils.set("tooltip",i,e.$_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(e,o){var i=t.DomHandler.createElement("div",{class:!e.unstyled&&this.cx("arrow"),"p-bind":this.ptm("arrow")}),n=t.DomHandler.createElement("div",{class:!e.unstyled&&this.cx("text"),"p-bind":this.ptm("text")});e.$_ptooltipEscape?n.innerHTML=e.$_ptooltipValue:(n.innerHTML="",n.appendChild(document.createTextNode(e.$_ptooltipValue)));var l=t.DomHandler.createElement("div",{id:e.$_ptooltipIdAttr,role:"tooltip",style:{display:"inline-block",width:e.$_ptooltipFitContent?"fit-content":void 0},class:[!e.unstyled&&this.cx("root"),e.$_ptooltipClass],"p-bind":this.ptm("root")},i,n);return document.body.appendChild(l),e.$_ptooltipId=l.id,this.$el=l,l},remove:function(e){if(e){var o=this.getTooltipElement(e);o&&o.parentElement&&(t.ZIndexUtils.clear(o),document.body.removeChild(o)),e.$_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(e){var o=e.getBoundingClientRect();return{left:o.left+t.DomHandler.getWindowScrollLeft(),top:o.top+t.DomHandler.getWindowScrollTop()}},alignRight:function(e){this.preAlign(e,"right");var o=this.getTooltipElement(e),i=this.getHostOffset(e),n=i.left+t.DomHandler.getOuterWidth(e),l=i.top+(t.DomHandler.getOuterHeight(e)-t.DomHandler.getOuterHeight(o))/2;o.style.left=n+"px",o.style.top=l+"px"},alignLeft:function(e){this.preAlign(e,"left");var o=this.getTooltipElement(e),i=this.getHostOffset(e),n=i.left-t.DomHandler.getOuterWidth(o),l=i.top+(t.DomHandler.getOuterHeight(e)-t.DomHandler.getOuterHeight(o))/2;o.style.left=n+"px",o.style.top=l+"px"},alignTop:function(e){this.preAlign(e,"top");var o=this.getTooltipElement(e),i=this.getHostOffset(e),n=i.left+(t.DomHandler.getOuterWidth(e)-t.DomHandler.getOuterWidth(o))/2,l=i.top-t.DomHandler.getOuterHeight(o);o.style.left=n+"px",o.style.top=l+"px"},alignBottom:function(e){this.preAlign(e,"bottom");var o=this.getTooltipElement(e),i=this.getHostOffset(e),n=i.left+(t.DomHandler.getOuterWidth(e)-t.DomHandler.getOuterWidth(o))/2,l=i.top+t.DomHandler.getOuterHeight(e);o.style.left=n+"px",o.style.top=l+"px"},preAlign:function(e,o){var i=this.getTooltipElement(e);i.style.left="-999px",i.style.top="-999px",t.DomHandler.removeClass(i,"p-tooltip-".concat(i.$_ptooltipPosition)),t.DomHandler.addClass(i,"p-tooltip-".concat(o)),i.$_ptooltipPosition=o},isOutOfBounds:function(e){var o=this.getTooltipElement(e),i=o.getBoundingClientRect(),n=i.top,l=i.left,r=t.DomHandler.getOuterWidth(o),s=t.DomHandler.getOuterHeight(o),p=t.DomHandler.getViewport();return l+r>p.width||l<0||n<0||n+s>p.height},getTarget:function(e){return t.DomHandler.hasClass(e,"p-inputwrapper")?t.DomHandler.findSingle(e,"input"):e},getModifiers:function(t){return t.modifiers&&Object.keys(t.modifiers).length?t.modifiers:t.arg&&"object"===d(t.arg)?Object.entries(t.arg).reduce((function(t,e){var o,i,n=(i=2,u(o=e)||a(o,i)||s(o,i)||r()),l=n[0];return"event"!==l&&"position"!==l||(t[n[1]]=!0),t}),{}):{}}}});module.exports=c;