primevue
Version:
PrimeVue is an open source UI library for Vue featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBloc
2 lines (1 loc) • 10.8 kB
JavaScript
import{UniqueComponentId as t,ObjectUtils as e,ConnectedOverlayScrollHandler as i,DomHandler as o,ZIndexUtils as n}from"primevue/utils";import l from"primevue/basedirective";import s from"primevue/tooltip/style";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 u(t,e){if(t){if("string"==typeof t)return a(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?a(t,e):void 0}}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,o=new Array(e);i<e;i++)o[i]=t[i];return o}function p(t,e){var i=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=i){var o,n,l,s,r=[],u=!0,a=!1;try{if(l=(i=i.call(t)).next,0===e){if(Object(i)!==i)return;u=!1}else for(;!(u=(o=l.call(i)).done)&&(r.push(o.value),r.length!==e);u=!0);}catch(t){a=!0,n=t}finally{try{if(!u&&null!=i.return&&(s=i.return(),Object(s)!==s))return}finally{if(a)throw n}}return r}}function d(t){if(Array.isArray(t))return t}function c(t){return c="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},c(t)}var h=l.extend({style:s}).extend("tooltip",{beforeMount:function(i,o){var n,l=this.getTarget(i);if(l.$_ptooltipModifiers=this.getModifiers(o),o.value){if("string"==typeof o.value)l.$_ptooltipValue=o.value,l.$_ptooltipDisabled=!1,l.$_ptooltipEscape=!0,l.$_ptooltipClass=null,l.$_ptooltipFitContent=!0,l.$_ptooltipIdAttr=t()+"_tooltip",l.$_ptooltipShowDelay=0,l.$_ptooltipHideDelay=0,l.$_ptooltipAutoHide=!0;else if("object"===c(o.value)&&o.value){if(e.isEmpty(o.value.value)||""===o.value.value.trim())return;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||t()+"_tooltip",l.$_ptooltipShowDelay=o.value.showDelay||0,l.$_ptooltipHideDelay=o.value.hideDelay||0,l.$_ptooltipAutoHide=!!o.value.autoHide!==o.value.autoHide||o.value.autoHide}l.$_ptooltipZIndex=null===(n=o.instance.$primevue)||void 0===n||null===(n=n.config)||void 0===n||null===(n=n.zIndex)||void 0===n?void 0:n.tooltip,this.bindEvents(l,o),i.setAttribute("data-pd-tooltip",!0)}},updated:function(i,o){var n=this.getTarget(i);if(n.$_ptooltipModifiers=this.getModifiers(o),this.unbindEvents(n),o.value)if("string"==typeof o.value)n.$_ptooltipValue=o.value,n.$_ptooltipDisabled=!1,n.$_ptooltipEscape=!0,n.$_ptooltipClass=null,n.$_ptooltipIdAttr=n.$_ptooltipIdAttr||t()+"_tooltip",n.$_ptooltipShowDelay=0,n.$_ptooltipHideDelay=0,n.$_ptooltipAutoHide=!0,this.bindEvents(n,o);else if("object"===c(o.value)&&o.value){if(e.isEmpty(o.value.value)||""===o.value.value.trim())return void this.unbindEvents(n,o);n.$_ptooltipValue=o.value.value,n.$_ptooltipDisabled=!!o.value.disabled===o.value.disabled&&o.value.disabled,n.$_ptooltipEscape=!!o.value.escape!==o.value.escape||o.value.escape,n.$_ptooltipClass=o.value.class||"",n.$_ptooltipFitContent=!!o.value.fitContent!==o.value.fitContent||o.value.fitContent,n.$_ptooltipIdAttr=o.value.id||n.$_ptooltipIdAttr||t()+"_tooltip",n.$_ptooltipShowDelay=o.value.showDelay||0,n.$_ptooltipHideDelay=o.value.hideDelay||0,n.$_ptooltipAutoHide=!!o.value.autoHide!==o.value.autoHide||o.value.autoHide,this.bindEvents(n,o)}},unmounted:function(t,e){var i=this.getTarget(t);this.remove(i),this.unbindEvents(i,e),i.$_ptooltipScrollHandler&&(i.$_ptooltipScrollHandler.destroy(),i.$_ptooltipScrollHandler=null)},timer:void 0,methods:{bindEvents:function(t,e){var i=this;t.$_ptooltipModifiers.focus?(t.$_focusevent=function(t){return i.onFocus(t,e)},t.addEventListener("focus",t.$_focusevent),t.addEventListener("blur",this.onBlur.bind(this))):(t.$_mouseenterevent=function(t){return i.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 i(t,(function(){e.hide(t)}))),t.$_ptooltipScrollHandler.bindScrollListener()},unbindScrollListener:function(t){t.$_ptooltipScrollHandler&&t.$_ptooltipScrollHandler.unbindScrollListener()},onMouseEnter:function(t,e){var i=t.currentTarget;this.show(i,e,i.$_ptooltipShowDelay)},onMouseLeave:function(t){var e=t.currentTarget,i=e.$_ptooltipHideDelay;e.$_ptooltipAutoHide?this.hide(e,i):!("tooltip"===o.getAttribute(t.target,"data-pc-name")||"arrow"===o.getAttribute(t.target,"data-pc-section")||"text"===o.getAttribute(t.target,"data-pc-section")||"tooltip"===o.getAttribute(t.relatedTarget,"data-pc-name")||"arrow"===o.getAttribute(t.relatedTarget,"data-pc-section")||"text"===o.getAttribute(t.relatedTarget,"data-pc-section"))&&this.hide(e,i)},onFocus:function(t,e){var i=t.currentTarget;this.show(i,e,i.$_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&&o.isExist(t)){var i=this.create(t,e);this.align(t),!this.isUnstyled()&&o.fadeIn(i,250);var l=this;window.addEventListener("resize",(function e(){o.isTouchDevice()||l.hide(t),window.removeEventListener("resize",e)})),i.addEventListener("mouseleave",(function e(){l.hide(t),i.removeEventListener("mouseleave",e)})),this.bindScrollListener(t),n.set("tooltip",i,t.$_ptooltipZIndex)}},show:function(t,e,i){var o=this;void 0!==i?this.timer=setTimeout((function(){return o.tooltipActions(t,e)}),i):this.tooltipActions(t,e)},tooltipRemoval:function(t){this.remove(t),this.unbindScrollListener(t)},hide:function(t,e){var i=this;clearTimeout(this.timer),void 0!==e?setTimeout((function(){return i.tooltipRemoval(t)}),e):this.tooltipRemoval(t)},getTooltipElement:function(t){return document.getElementById(t.$_ptooltipId)},create:function(t,e){var i=t.$_ptooltipModifiers,n=o.createElement("div",{class:!this.isUnstyled()&&this.cx("arrow"),style:{top:null!=i&&i.bottom?"0":!(null!=i&&i.right||null!=i&&i.left)&&(null!=i&&i.right||null!=i&&i.left||null!=i&&i.top||null!=i&&i.bottom)?null:"50%",bottom:null!=i&&i.top?"0":null,left:(null==i||!i.right)&&(null!=i&&i.right||null!=i&&i.left||null!=i&&i.top||null!=i&&i.bottom)?null!=i&&i.top||null!=i&&i.bottom?"50%":null:"0",right:null!=i&&i.left?"0":null},"p-bind":this.ptm("arrow",{context:i})}),l=o.createElement("div",{class:!this.isUnstyled()&&this.cx("text"),"p-bind":this.ptm("text",{context:i})});t.$_ptooltipEscape?(l.innerHTML="",l.appendChild(document.createTextNode(t.$_ptooltipValue))):l.innerHTML=t.$_ptooltipValue;var s=o.createElement("div",{id:t.$_ptooltipIdAttr,role:"tooltip",style:{display:"inline-block",width:t.$_ptooltipFitContent?"fit-content":void 0,pointerEvents:!this.isUnstyled()&&t.$_ptooltipAutoHide&&"none"},class:[!this.isUnstyled()&&this.cx("root"),t.$_ptooltipClass],"p-bind":this.ptm("root",{context:i})},n,l);return document.body.appendChild(s),t.$_ptooltipId=s.id,this.$el=s,s},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+o.getWindowScrollLeft(),top:e.top+o.getWindowScrollTop()}},alignRight:function(t){this.preAlign(t,"right");var e=this.getTooltipElement(t),i=this.getHostOffset(t),n=i.left+o.getOuterWidth(t),l=i.top+(o.getOuterHeight(t)-o.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),i=this.getHostOffset(t),n=i.left-o.getOuterWidth(e),l=i.top+(o.getOuterHeight(t)-o.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),i=this.getHostOffset(t),n=i.left+(o.getOuterWidth(t)-o.getOuterWidth(e))/2,l=i.top-o.getOuterHeight(e);e.style.left=n+"px",e.style.top=l+"px"},alignBottom:function(t){this.preAlign(t,"bottom");var e=this.getTooltipElement(t),i=this.getHostOffset(t),n=i.left+(o.getOuterWidth(t)-o.getOuterWidth(e))/2,l=i.top+o.getOuterHeight(t);e.style.left=n+"px",e.style.top=l+"px"},preAlign:function(t,e){var i=this.getTooltipElement(t);i.style.left="-999px",i.style.top="-999px",o.removeClass(i,"p-tooltip-".concat(i.$_ptooltipPosition)),!this.isUnstyled()&&o.addClass(i,"p-tooltip-".concat(e)),i.$_ptooltipPosition=e,i.setAttribute("data-p-position",e)},isOutOfBounds:function(t){var e=this.getTooltipElement(t),i=e.getBoundingClientRect(),n=i.top,l=i.left,s=o.getOuterWidth(e),r=o.getOuterHeight(e),u=o.getViewport();return l+s>u.width||l<0||n<0||n+r>u.height},getTarget:function(t){return o.hasClass(t,"p-inputwrapper")?o.findSingle(t,"input"):t},getModifiers:function(t){return t.modifiers&&Object.keys(t.modifiers).length?t.modifiers:t.arg&&"object"===c(t.arg)?Object.entries(t.arg).reduce((function(t,e){var i,o,n=(o=2,d(i=e)||p(i,o)||u(i,o)||r()),l=n[0];return"event"!==l&&"position"!==l||(t[n[1]]=!0),t}),{}):{}}}});export{h as default};