@vue-interface/tooltip 1.0.0-beta.9 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- (function(l,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("vue"),require("@popperjs/core")):typeof define=="function"&&define.amd?define(["exports","vue","@popperjs/core"],o):(l=typeof globalThis<"u"?globalThis:l||self,o(l.Tooltip={},l.Vue,l.PopperjsCore))})(this,function(l,o,w){"use strict";const y=o.defineComponent({props:{offset:{type:Array,default:void 0},popper:{type:Object,default:void 0},placement:{type:String,default:void 0},target:{type:Element,required:!0},title:{type:String,default:void 0},show:Boolean,top:Boolean,bottom:Boolean,left:Boolean,right:Boolean},data(){return{currentShow:!1,popperInstance:null}},computed:{computedPlacement(){return this.placement?this.placement:this.bottom?"bottom":this.left?"left":this.right?"right":"top"},tooltipClasses(){return{show:this.currentShow,[`bs-tooltip-${this.computedPlacement}`]:!0}}},mounted(){this.popperInstance=w.createPopper(this.target,this.$el,Object.assign({placement:this.computedPlacement,modifiers:[{name:"offset",options:{offset:[0,6]}},{name:"arrow",options:{element:this.$refs.arrow}}]},this.popper)),this.$nextTick(()=>{this.currentShow=this.show})},beforeUnmount(){this.popperInstance&&this.popperInstance.destroy()},methods:{open(){this.currentShow=!0},close(){this.currentShow=!1}}}),E=o.defineComponent({mixins:[y]}),M="",x=(c,m)=>{const a=c.__vccOpts||c;for(const[d,i]of m)a[d]=i;return a},S={ref:"arrow",class:"tooltip-arrow"},A={ref:"inner",class:"tooltip-inner"};function j(c,m,a,d,i,g){return o.openBlock(),o.createElementBlock("div",{class:o.normalizeClass(["tooltip",c.tooltipClasses]),role:"tooltip"},[o.createElementVNode("div",S,null,512),o.createElementVNode("div",A,[o.renderSlot(c.$slots,"default",{},()=>[o.createTextVNode(o.toDisplayString(c.title),1)])],512)],2)}const T=x(E,[["render",j]]);function N(c,m={}){const a=new Map,d=Object.assign({delay:void 0,prefix:"data-tooltip",triggers:{open:["mouseover:350"],close:["mouseout:100"]}},m),i=d.prefix.replace(/[-]+$/,""),g=new RegExp(`^${i}-`);function O(e){return Array.from(e.attributes).map(t=>[t.name,t.value]).filter(([t])=>t==="title"||t.match(g)).map(([t,n])=>[t.replace(new RegExp(g),""),n]).reduce((t,n)=>Object.assign(t,{[n[0]]:n[1]}),{})}function P(e,t={},n){const s=document.createElement("template"),r=o.h(T,Object.assign({target:e,show:!0},t));o.render(r,s);const[p]=[...s.children];return document.body.append(p),()=>{var f;a.delete(n),(f=r.component)==null||f.ctx.close(),setTimeout(()=>p.remove(),150)}}function b(e,t={}){var $,v;const n=Object.assign({title:e.getAttribute(i)||e.getAttribute("title")},t,O(e));if(!n.title||e.hasAttribute(`${i}-id`))return;const s=Math.random().toString(36).slice(2,7);let r,p;e.setAttribute(`${i}-id`,s);function f(u=0){clearTimeout(p),r||(p=setTimeout(()=>{document.contains(e)&&(r=P(e,n,s),a.set(s,r))},u))}function h(u=0){clearTimeout(p),r&&(p=setTimeout(()=>{r&&r(),r=null},u))}function _(u,C){const[L,B]=u.split(":");e.addEventListener(L,()=>C(Number(B||0)))}((($=e.getAttribute(`${i}-trigger-open`))==null?void 0:$.split(","))||d.triggers.open).map(u=>_(u,f)),(((v=e.getAttribute(`${i}-trigger-close`))==null?void 0:v.split(","))||d.triggers.close).map(u=>_(u,h))}c.mixin({mounted(){let e=this.$el;this.$el instanceof Text&&(e=this.$el.parentNode),e instanceof HTMLElement&&b(e);const t=document.createTreeWalker(e,NodeFilter.SHOW_ALL,s=>s instanceof Element?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT);for(;t.nextNode();)t.currentNode instanceof Element&&b(t.currentNode);new MutationObserver(s=>{for(const{removedNodes:r}of s)for(const p of r)for(const f of p.querySelectorAll(`[${i}-id]`)){const h=a.get(f.getAttribute(`${i}-id`));h&&h()}}).observe(e,{childList:!0})}}),c.directive("tooltip",{beforeMount(e,t){b(e,Object.assign({},t.modifiers,t.value))},beforeUnmount(e){const t=e.getAttribute(`${i}-id`),n=a.get(t);n&&n()}})}l.Tooltip=T,l.TooltipPlugin=N,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(a,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("@floating-ui/vue")):typeof define=="function"&&define.amd?define(["exports","vue","@floating-ui/vue"],t):(a=typeof globalThis<"u"?globalThis:a||self,t(a.Tooltip={},a.Vue,a.FloatingUiVue))})(this,(function(a,t,c){"use strict";const A=["data-tooltip-id"],N={ref:"inner",class:"tooltip-inner"},h=t.defineComponent({__name:"Tooltip",props:{title:{default:void 0},show:{type:Boolean},target:{default:void 0},placement:{default:"top"},strategy:{default:void 0},middleware:{type:Function,default:void 0},flip:{default:void 0},offset:{type:[Number,Object,Function],default:void 0}},setup(e,{expose:o}){const i=e,n=t.useTemplateRef("tooltipEl"),l=t.useTemplateRef("arrowEl"),r=t.ref(!1),p=Math.random().toString(36).slice(2,12),s=t.isRef(i.target)?i.target:t.shallowReadonly(t.ref(i.target)),_=t.computed(()=>{if(s.value instanceof Element)return s.value.getAttribute("data-tooltip-id")});t.watchEffect(()=>{!s.value||_.value||s.value instanceof Element&&(s.value.setAttribute("data-tooltip-id",p),s.value.addEventListener("mouseover",v),s.value.addEventListener("mouseout",x))}),t.watchEffect(()=>{r.value=i.show});const $=t.computed(()=>i.offset?i.offset:()=>{const{height:m}=l.value?getComputedStyle(l.value):{height:"0px"};return{mainAxis:parseInt(m.replace("px",""))}}),{floatingStyles:F,middlewareData:d,placement:C}=c.useFloating(s,n,{placement:i.placement,middleware:i.middleware?.(l)??[c.flip(i.flip),c.offset($.value),c.arrow({element:l})],whileElementsMounted:c.autoUpdate}),O=t.computed(()=>({show:r.value})),L=t.computed(()=>C.value.split("-")[0]),T=t.computed(()=>({top:"bottom",right:"left",bottom:"top",left:"right"})[L.value]),j=t.computed(()=>({top:"rotate(225deg)",right:"rotate(-45deg)",bottom:"rotate(45deg)",left:"rotate(135deg)"}));function v(){r.value=!0}function x(){r.value=!1}return t.onUnmounted(()=>{s.value instanceof Element&&s.value.removeAttribute("data-tooltip-id")}),o({open:v,close:x,tooltipEl:n,arrowEl:l,isShowing:r,hash:p}),(m,M)=>(t.openBlock(),t.createBlock(t.Teleport,{to:"body"},[t.createElementVNode("div",{ref_key:"tooltipEl",ref:n,class:t.normalizeClass(["tooltip",O.value]),role:"tooltip","data-tooltip-id":t.unref(p),style:t.normalizeStyle(t.unref(F))},[t.createElementVNode("div",{ref_key:"arrowEl",ref:l,class:"tooltip-arrow",style:t.normalizeStyle({transform:j.value[T.value],...Object.assign({left:t.unref(d).arrow?.x!=null?`${t.unref(d).arrow.x}px`:"",top:t.unref(d).arrow?.y!=null?`${t.unref(d).arrow.y}px`:""},{[T.value]:`calc(${-(l.value?.offsetWidth??0)/2}px)`})})},null,4),t.createElementVNode("div",N,[t.renderSlot(m.$slots,"default",{},()=>[t.createTextVNode(t.toDisplayString(e.title),1)])],512)],14,A)]))}}),f="data-tooltip",E=new RegExp(`^${f}-`);function b(e){return Array.from(e.attributes).map(o=>[o.name,o.value]).filter(([o])=>o==="title"||o.match(E)).map(([o,i])=>[o.replace(new RegExp(E),""),i]).reduce((o,i)=>Object.assign(o,{[i[0]]:i[1]}),{})}function u(e,o){const i=document.createElement("template"),n=t.h(h,Object.assign({target:e},b(e),o));t.render(n,i);const l=e.getAttribute("title");return l&&(e.setAttribute(`${f}-og-title`,l),e.removeAttribute("title")),()=>{n.component&&n.component.exposed?.tooltipEl.value?.remove()}}function g(e){const o=document.querySelectorAll(`[${f}-id="${e.getAttribute(`${f}-id`)}"]`);for(const n of o)n.remove();e.removeAttribute(`${f}-id`);const i=e.getAttribute(`${f}-og-title`);i&&e.setAttribute("title",i)}function w(e){if(!(e instanceof Element))return!1;const o=b(e);return!o.id&&!!o.title}function R(e){return e instanceof Element?e.hasAttribute(`${f}-id`):!1}const y={beforeMount(e,o){u(e,typeof o.value=="string"?{title:o.value}:o.value)},beforeUnmount(e){g(e)}};function S(e){e.mixin({beforeMount(){new MutationObserver(i=>{for(const{addedNodes:n,removedNodes:l}of i)n.forEach(r=>{w(r)&&u(r)}),l.forEach(r=>{R(r)&&g(r)})}).observe(document.body,{childList:!0,subtree:!0})},mounted(){let o=this.$el;this.$el instanceof Text&&(o=this.$el.parentNode);const i=document.createTreeWalker(o,NodeFilter.SHOW_ALL,n=>n instanceof Element?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT);for(;i.nextNode();)w(i.currentNode)&&u(i.currentNode)}}),e.directive("tooltip",y)}a.Tooltip=h,a.TooltipDirective=y,a.TooltipPlugin=S,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
2
2
  //# sourceMappingURL=tooltip.umd.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip.umd.cjs","sources":["../src/Popper.ts","../src/Tooltip.vue","../src/TooltipPlugin.ts"],"sourcesContent":["import { createPopper } from '@popperjs/core';\nimport { defineComponent } from 'vue';\n\nexport default defineComponent({\n\n props: {\n offset: {\n type: Array,\n default: undefined\n },\n\n popper: {\n type: Object,\n default: undefined\n },\n\n placement: {\n type: String,\n default: undefined\n },\n\n target: {\n type: Element,\n required: true\n },\n\n title: {\n type: String,\n default: undefined\n },\n \n show: Boolean,\n \n top: Boolean,\n\n bottom: Boolean,\n\n left: Boolean,\n\n right: Boolean,\n },\n\n data() {\n return {\n currentShow: false,\n popperInstance: null\n };\n },\n\n computed: {\n computedPlacement() {\n if(this.placement) {\n return this.placement;\n }\n\n if(this.bottom) {\n return 'bottom';\n }\n\n if(this.left) {\n return 'left';\n }\n\n if(this.right) {\n return 'right';\n }\n\n return 'top';\n },\n tooltipClasses() {\n return {\n show: this.currentShow,\n [`bs-tooltip-${this.computedPlacement}`]: true\n };\n }\n },\n\n mounted() {\n this.popperInstance = createPopper(this.target, this.$el, Object.assign({\n placement: this.computedPlacement,\n modifiers: [\n {\n name: 'offset',\n options: {\n offset: [0, 6]\n },\n },\n {\n name: 'arrow',\n options: {\n element: this.$refs.arrow,\n },\n },\n ],\n }, this.popper));\n\n this.$nextTick(() => {\n this.currentShow = this.show;\n });\n },\n\n beforeUnmount() {\n this.popperInstance && this.popperInstance.destroy();\n },\n\n methods: {\n\n open() {\n this.currentShow = true;\n },\n\n close() {\n this.currentShow = false;\n }\n\n }\n\n});","<script lang=\"ts\">\nimport { defineComponent } from 'vue';\nimport Popper from './Popper';\n\nexport default defineComponent({\n mixins: [\n Popper\n ]\n});\n</script>\n\n<template>\n <div\n class=\"tooltip\"\n :class=\"tooltipClasses\"\n role=\"tooltip\">\n <div\n ref=\"arrow\"\n class=\"tooltip-arrow\" />\n <div\n ref=\"inner\"\n class=\"tooltip-inner\">\n <slot>{{ title }}</slot>\n </div>\n </div>\n</template>\n\n<style>\n.tooltip:not(.show) {\n z-index: -1;\n}\n</style>","import type { App } from 'vue';\nimport { h, render } from 'vue';\nimport Tooltip from './Tooltip.vue';\n\ntype TooltipPluginOptions = {\n delay?: number,\n prefix: string,\n triggers: {\n open: string[],\n close: string[],\n }\n}\n\nexport default function (app: App, opts: Partial<TooltipPluginOptions> = {}) {\n const tooltips: Map<string,Function> = new Map;\n\n const options: TooltipPluginOptions = Object.assign({\n delay: undefined,\n prefix: 'data-tooltip',\n triggers: {\n open: ['mouseover:350'],\n close: ['mouseout:100'],\n }\n }, opts);\n \n const prefix = options.prefix.replace(/[-]+$/, '');\n const prefixRegExp = new RegExp(`^${prefix}\\-`);\n\n function getAttributes(el: Element): Record<string,any> {\n return Array.from(el.attributes)\n .map(a => [a.name, a.value])\n .filter(([key]) => key === 'title' || key.match(prefixRegExp))\n .map(([key, value]) => [key.replace(new RegExp(prefixRegExp), ''), value])\n .reduce((carry, attr) => Object.assign(carry, { [attr[0]]: attr[1] }), {});\n }\n\n function createTooltip(target: Element, props: Record<string,any> = {}, hash: string): Function {\n const container = document.createElement('template');\n \n const vnode = h(Tooltip, Object.assign({\n target,\n show: true\n }, props));\n \n render(vnode, container);\n \n const [el] = [...container.children];\n \n document.body.append(el);\n \n return () => {\n tooltips.delete(hash);\n\n // @ts-ignore\n vnode.component?.ctx.close();\n \n // @todo: Make the animation rate (150) dynamic. Should get value \n // from the CSS transition duration.\n setTimeout(() => el.remove(), 150);\n };\n }\n\n function init(target: Element, props = {}) {\n const properties: Record<string,any> = Object.assign({\n title: target.getAttribute(prefix) || target.getAttribute('title')\n }, props, getAttributes(target));\n\n // If the properties don't have a title, ignore this target.\n if(!properties.title || target.hasAttribute(`${prefix}-id`)) {\n return;\n }\n\n // Create a unique \"hash\" to show the node has been initialized.\n // This prevents double initializing on the same element.\n const hash = Math.random().toString(36).slice(2, 7);\n \n // Create the instance vars.\n let tooltip: Function|null, timer: number;\n\n //target.setAttribute(prefix, properties.title);\n target.setAttribute(`${prefix}-id`, hash);\n // target.removeAttribute('title');\n\n function open(delay = 0) {\n clearTimeout(timer);\n\n if(!tooltip) {\n timer = setTimeout(() => {\n // Do a check before creating the tooltip to ensure the dom\n // element still exists. Its possible for the element to\n // be removed after the timeout delay runs.\n if(document.contains(target)) {\n tooltip = createTooltip(target, properties, hash);\n tooltips.set(hash, tooltip);\n }\n }, delay);\n }\n }\n\n function close(delay = 0) {\n clearTimeout(timer);\n\n if(tooltip) {\n timer = setTimeout(() => {\n tooltip && tooltip();\n tooltip = null;\n }, delay);\n } \n }\n\n function addEventListener(trigger: string, fn: Function) {\n const [ event, delayString ] = trigger.split(':');\n\n target.addEventListener(event, () => fn(Number(delayString || 0)));\n }\n\n (target.getAttribute(`${prefix}-trigger-open`)?.split(',') || options.triggers.open)\n .map(trigger => addEventListener(trigger, open));\n \n (target.getAttribute(`${prefix}-trigger-close`)?.split(',') || options.triggers.close)\n .map(trigger => addEventListener(trigger, close));\n }\n \n app.mixin({\n mounted() {\n let el = this.$el;\n\n if(this.$el instanceof Text) {\n el = this.$el.parentNode;\n }\n\n if(el instanceof HTMLElement) {\n init(el);\n }\n\n // Create the tree walker.\n const walker = document.createTreeWalker(\n el,\n NodeFilter.SHOW_ALL,\n (node: Node) => {\n if(!(node instanceof Element)) {\n return NodeFilter.FILTER_REJECT;\n }\n \n return NodeFilter.FILTER_ACCEPT;\n }\n );\n\n // Step through and alert all child nodes\n while(walker.nextNode()) {\n if(walker.currentNode instanceof Element) {\n init(<Element> walker.currentNode);\n }\n }\n\n const observer = new MutationObserver((changes) => {\n for(const { removedNodes } of changes) {\n for(const node of removedNodes) {\n for(const el of (node as Element).querySelectorAll(`[${prefix}-id]`)) {\n const tooltip = tooltips.get(\n el.getAttribute(`${prefix}-id`) as string\n );\n\n tooltip && tooltip();\n }\n } \n }\n });\n\n observer.observe(el, { childList: true });\n }\n });\n\n app.directive('tooltip', {\n beforeMount(target, binding) {\n init(target, Object.assign({}, binding.modifiers, binding.value));\n },\n beforeUnmount(target) {\n const id = target.getAttribute(`${prefix}-id`);\n const tooltip = tooltips.get(id);\n\n tooltip && tooltip();\n }\n });\n}"],"names":["Popper","defineComponent","createPopper","_sfc_main","_hoisted_1","_hoisted_2","_sfc_render","_ctx","_cache","$props","$setup","$data","$options","_openBlock","_createElementBlock","_normalizeClass","_createElementVNode","_renderSlot","TooltipPlugin","app","opts","tooltips","options","prefix","prefixRegExp","getAttributes","el","a","key","value","carry","attr","createTooltip","target","props","hash","container","vnode","h","Tooltip","render","_a","init","properties","tooltip","timer","open","delay","close","addEventListener","trigger","fn","event","delayString","_b","walker","node","changes","removedNodes","binding","id"],"mappings":"wTAGA,MAAAA,EAAeC,kBAAgB,CAE3B,MAAO,CACH,OAAQ,CACJ,KAAM,MACN,QAAS,MACb,EAEA,OAAQ,CACJ,KAAM,OACN,QAAS,MACb,EAEA,UAAW,CACP,KAAM,OACN,QAAS,MACb,EAEA,OAAQ,CACJ,KAAM,QACN,SAAU,EACd,EAEA,MAAO,CACH,KAAM,OACN,QAAS,MACb,EAEA,KAAM,QAEN,IAAK,QAEL,OAAQ,QAER,KAAM,QAEN,MAAO,OACX,EA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AM6B,EAAS,SAAS,iBACpB7B,EACA,WAAW,SACV8B,GACQA,aAAgB,QAId,WAAW,cAHP,WAAW,aAI1B,EAIE,KAAAD,EAAO,YACNA,EAAO,uBAAuB,SAC7Bb,EAAea,EAAO,WAAW,EAIxB,IAAI,iBAAkBE,GAAY,CACrC,SAAA,CAAE,aAAAC,CAAa,IAAKD,EAC1B,UAAUD,KAAQE,EACd,UAAUhC,KAAO8B,EAAiB,iBAAiB,IAAIjC,OAAY,EAAG,CAClE,MAAMqB,EAAUvB,EAAS,IACrBK,EAAG,aAAa,GAAGH,MAAW,CAAA,EAGlCqB,GAAWA,EAAQ,CACvB,CAER,CACH,EAEQ,QAAQlB,EAAI,CAAE,UAAW,EAAM,CAAA,CAC5C,CAAA,CACH,EAEDP,EAAI,UAAU,UAAW,CACrB,YAAYc,EAAQ0B,EAAS,CACpBjB,EAAAT,EAAQ,OAAO,OAAO,CAAA,EAAI0B,EAAQ,UAAWA,EAAQ,KAAK,CAAC,CACpE,EACA,cAAc1B,EAAQ,CAClB,MAAM2B,EAAK3B,EAAO,aAAa,GAAGV,MAAW,EACvCqB,EAAUvB,EAAS,IAAIuC,CAAE,EAE/BhB,GAAWA,EAAQ,CACvB,CAAA,CACH,CACL"}
1
+ {"version":3,"file":"tooltip.umd.cjs","sources":["../src/Tooltip.vue","../src/TooltipPlugin.ts"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { arrow, autoUpdate, flip as flipFn, FlipOptions, MaybeElement, offset as offsetFn, OffsetOptions, ReferenceElement, useFloating, UseFloatingOptions } from '@floating-ui/vue';\nimport { computed, isRef, onUnmounted, Ref, ref, shallowReadonly, ShallowRef, useTemplateRef, watchEffect } from 'vue';\n\nexport type TooltipProps = {\n title?: string;\n show?: boolean;\n target?: Ref<MaybeElement<ReferenceElement>> | ReferenceElement;\n placement?: UseFloatingOptions['placement'];\n strategy?: UseFloatingOptions['strategy'];\n middleware?: (arrow: Readonly<ShallowRef<HTMLDivElement | null>>) => UseFloatingOptions['middleware'];\n flip?: FlipOptions;\n offset?: OffsetOptions;\n};\n\nconst props = withDefaults(defineProps<TooltipProps>(), {\n title: undefined,\n target: undefined,\n placement: 'top',\n middleware: undefined,\n strategy: undefined,\n flip: undefined,\n offset: undefined,\n});\n\ndefineSlots<{\n default: () => void\n}>();\n\nconst tooltipEl = useTemplateRef<HTMLDivElement>('tooltipEl');\nconst arrowEl = useTemplateRef<HTMLDivElement>('arrowEl');\nconst isShowing = ref(false);\nconst hash = Math.random().toString(36).slice(2, 12);\n\nconst targetEl = isRef(props.target)\n ? props.target\n : shallowReadonly(ref(props.target));\n\nconst id = computed(() => {\n if(!(targetEl.value instanceof Element)) {\n return;\n }\n\n return targetEl.value.getAttribute('data-tooltip-id');\n});\n\n\nwatchEffect(() => {\n if(!targetEl.value || id.value) {\n return;\n }\n\n if(targetEl.value instanceof Element) {\n targetEl.value.setAttribute('data-tooltip-id', hash);\n targetEl.value.addEventListener('mouseover', open);\n targetEl.value.addEventListener('mouseout', close);\n }\n});\n\nwatchEffect(() => {\n isShowing.value = props.show;\n});\n\nconst dynamicOffset = computed<OffsetOptions>(() => {\n if(props.offset) {\n return props.offset;\n }\n\n return () => {\n const { height } = arrowEl.value ? getComputedStyle(arrowEl.value) : { height: '0px' };\n\n return {\n mainAxis: parseInt(height.replace('px', '')),\n };\n };\n});\n\nconst { floatingStyles, middlewareData, placement } = useFloating(targetEl, tooltipEl, {\n placement: props.placement,\n middleware: props.middleware?.(arrowEl) ?? [\n flipFn(props.flip),\n offsetFn(dynamicOffset.value),\n arrow({\n element: arrowEl\n }),\n ],\n whileElementsMounted: autoUpdate\n});\n\nconst tooltipClasses = computed(() => {\n return {\n show: isShowing.value\n };\n});\n\ntype Side = 'bottom' | 'left' | 'top' | 'right';\n\nconst side = computed(() => placement.value.split('-')[0] as Side);\n\nconst arrowPosition = computed(() => {\n return {\n top: 'bottom',\n right: 'left',\n bottom: 'top',\n left: 'right'\n }[side.value] as Side;\n});\n\nconst arrowRotation = computed<Record<Side,string>>(() => ({\n top: 'rotate(225deg)',\n right: 'rotate(-45deg)',\n bottom: 'rotate(45deg)',\n left: 'rotate(135deg)',\n}));\n\nfunction open() {\n isShowing.value = true;\n}\n\nfunction close() {\n isShowing.value = false;\n}\n\nonUnmounted(() => {\n if(targetEl.value instanceof Element) {\n targetEl.value.removeAttribute('data-tooltip-id');\n }\n});\n\ndefineExpose({\n open,\n close,\n tooltipEl,\n arrowEl,\n isShowing,\n hash,\n});\n</script>\n\n<template>\n <Teleport to=\"body\">\n <div\n ref=\"tooltipEl\"\n class=\"tooltip\"\n role=\"tooltip\"\n :data-tooltip-id=\"hash\"\n :class=\"tooltipClasses\"\n :style=\"floatingStyles\">\n <div\n ref=\"arrowEl\"\n class=\"tooltip-arrow\"\n :style=\"{\n transform: arrowRotation[arrowPosition],\n ...Object.assign({\n left:\n middlewareData.arrow?.x != null\n ? `${middlewareData.arrow.x}px`\n : '',\n top:\n middlewareData.arrow?.y != null\n ? `${middlewareData.arrow.y}px`\n : ''\n }, {\n [arrowPosition]: `calc(${-(arrowEl?.offsetWidth ?? 0) / 2}px)`\n })\n }\" />\n <div\n ref=\"inner\"\n class=\"tooltip-inner\">\n <slot>{{ title }}</slot>\n </div>\n </div>\n </Teleport>\n</template>","import { h, render, type App, type Directive } from 'vue';\nimport Tooltip, { type TooltipProps } from './Tooltip.vue';\n\nconst prefix = 'data-tooltip';\nconst prefixRegExp = new RegExp(`^${prefix}\\-`);\n\nfunction getAttributes(el: Element): Record<string,string> {\n return Array.from(el.attributes)\n .map(a => [a.name, a.value])\n .filter(([key]) => key === 'title' || key.match(prefixRegExp))\n .map(([key, value]) => [key.replace(new RegExp(prefixRegExp), ''), value])\n .reduce((carry, attr) => Object.assign(carry, { [attr[0]]: attr[1] }), {});\n}\n\nfunction createTooltip(target: Element, props?: TooltipProps) {\n const container = document.createElement('template');\n \n const vnode = h(Tooltip, Object.assign({\n target\n }, getAttributes(target), props));\n\n render(vnode, container);\n\n const title = target.getAttribute('title');\n\n if(title) {\n target.setAttribute(`${prefix}-og-title`, title);\n target.removeAttribute('title');\n }\n\n return () => {\n if(vnode.component) {\n vnode.component.exposed?.tooltipEl.value?.remove();\n }\n };\n}\n\nfunction destroyTooltip(target: Element) {\n const tooltips = document.querySelectorAll(\n `[${prefix}-id=\"${target.getAttribute(`${prefix}-id`)}\"]`\n );\n\n for(const tooltip of tooltips) {\n tooltip.remove();\n }\n\n target.removeAttribute(`${prefix}-id`);\n\n const title = target.getAttribute(`${prefix}-og-title`);\n\n if(title) {\n target.setAttribute('title', title);\n }\n}\n\nfunction shouldCreateTooltip(target: Node): target is Element {\n if(!(target instanceof Element)) {\n return false;\n }\n\n const attrs = getAttributes(target);\n\n return !attrs.id && !!attrs.title;\n}\n\nfunction shouldRemoveTooltip(target: Node): target is Element {\n if(!(target instanceof Element)) {\n return false;\n }\n\n return target.hasAttribute(`${prefix}-id`);\n}\n\nexport const TooltipDirective: Directive<Element, string|TooltipProps> = {\n beforeMount(target, binding) {\n createTooltip(target, typeof binding.value === 'string' ? {\n title: binding.value\n }: binding.value);\n },\n beforeUnmount(target) {\n destroyTooltip(target);\n }\n};\n\nexport function TooltipPlugin(app: App<Element>) {\n app.mixin({\n beforeMount() {\n const observer = new MutationObserver((mutations) => {\n for(const { addedNodes, removedNodes } of mutations) {\n addedNodes.forEach((node) => {\n if(shouldCreateTooltip(node)) {\n createTooltip(node);\n }\n });\n\n removedNodes.forEach((node) => {\n if(shouldRemoveTooltip(node)) {\n destroyTooltip(node);\n }\n });\n }\n });\n \n observer.observe(document.body, {\n childList: true,\n subtree: true\n });\n },\n mounted() {\n let el = this.$el;\n\n if(this.$el instanceof Text) {\n el = this.$el.parentNode;\n }\n\n const walker = document.createTreeWalker(\n el,\n NodeFilter.SHOW_ALL,\n (node: Node) => {\n if(!(node instanceof Element)) {\n return NodeFilter.FILTER_REJECT;\n }\n \n return NodeFilter.FILTER_ACCEPT;\n }\n );\n\n while(walker.nextNode()) {\n if(shouldCreateTooltip(walker.currentNode)) {\n createTooltip(walker.currentNode);\n }\n }\n }\n });\n\n app.directive<Element, string|TooltipProps>('tooltip', TooltipDirective);\n}"],"names":["props","__props","tooltipEl","useTemplateRef","arrowEl","isShowing","ref","hash","targetEl","isRef","shallowReadonly","id","computed","watchEffect","open","close","dynamicOffset","height","floatingStyles","middlewareData","placement","useFloating","flipFn","offsetFn","arrow","autoUpdate","tooltipClasses","side","arrowPosition","arrowRotation","onUnmounted","__expose","_createBlock","_Teleport","_createElementVNode","_normalizeClass","_unref","_normalizeStyle","_hoisted_2","_renderSlot","_ctx","prefix","prefixRegExp","getAttributes","el","a","key","value","carry","attr","createTooltip","target","container","vnode","h","Tooltip","render","title","destroyTooltip","tooltips","tooltip","shouldCreateTooltip","attrs","shouldRemoveTooltip","TooltipDirective","binding","TooltipPlugin","app","mutations","addedNodes","removedNodes","node","walker"],"mappings":"+qBAeA,MAAMA,EAAQC,EAcRC,EAAYC,EAAAA,eAA+B,WAAW,EACtDC,EAAUD,EAAAA,eAA+B,SAAS,EAClDE,EAAYC,EAAAA,IAAI,EAAK,EACrBC,EAAO,KAAK,SAAS,SAAS,EAAE,EAAE,MAAM,EAAG,EAAE,EAE7CC,EAAWC,EAAAA,MAAMT,EAAM,MAAM,EAC7BA,EAAM,OACNU,kBAAgBJ,EAAAA,IAAIN,EAAM,MAAM,CAAC,EAEjCW,EAAKC,EAAAA,SAAS,IAAM,CACtB,GAAKJ,EAAS,iBAAiB,QAI/B,OAAOA,EAAS,MAAM,aAAa,iBAAiB,CACxD,CAAC,EAGDK,EAAAA,YAAY,IAAM,CACX,CAACL,EAAS,OAASG,EAAG,OAItBH,EAAS,iBAAiB,UACzBA,EAAS,MAAM,aAAa,kBAAmBD,CAAI,EACnDC,EAAS,MAAM,iBAAiB,YAAaM,CAAI,EACjDN,EAAS,MAAM,iBAAiB,WAAYO,CAAK,EAEzD,CAAC,EAEDF,EAAAA,YAAY,IAAM,CACdR,EAAU,MAAQL,EAAM,IAC5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Q,CAClBO,EAAeP,CAAM,CACzB,CACJ,EAEO,SAASe,EAAcC,EAAmB,CAC7CA,EAAI,MAAM,CACN,aAAc,CACO,IAAI,iBAAkBC,GAAc,CACjD,SAAU,CAAE,WAAAC,EAAY,aAAAC,CAAA,IAAkBF,EACtCC,EAAW,QAASE,GAAS,CACtBV,EAAoBU,CAAI,GACvBrB,EAAcqB,CAAI,CAE1B,CAAC,EAEDD,EAAa,QAASC,GAAS,CACxBR,EAAoBQ,CAAI,GACvBb,EAAea,CAAI,CAE3B,CAAC,CAET,CAAC,EAEQ,QAAQ,SAAS,KAAM,CAC5B,UAAW,GACX,QAAS,EAAA,CACZ,CACL,EACA,SAAU,CACN,IAAI3B,EAAK,KAAK,IAEX,KAAK,eAAe,OACnBA,EAAK,KAAK,IAAI,YAGlB,MAAM4B,EAAS,SAAS,iBACpB5B,EACA,WAAW,SACV2B,GACQA,aAAgB,QAId,WAAW,cAHP,WAAW,aAI1B,EAGJ,KAAMC,EAAO,YACNX,EAAoBW,EAAO,WAAW,GACrCtB,EAAcsB,EAAO,WAAW,CAG5C,CAAA,CACH,EAEDL,EAAI,UAAwC,UAAWH,CAAgB,CAC3E"}
package/index.css ADDED
@@ -0,0 +1,71 @@
1
+ @import "tailwindcss";
2
+
3
+ @theme {
4
+ --tooltip-position: absolute;
5
+ --tooltip-hiding-z-index: -1;
6
+ --tooltip-showing-z-index: 100;
7
+ --tooltip-display: block;
8
+ --tooltip-font-size: .875rem;
9
+ --tooltip-word-wrap: break-word;
10
+ --tooltip-opacity-hidden: 0;
11
+ --tooltip-opacity-visible: .9;
12
+ --tooltip-transition: opacity .15s ease-out;
13
+ --tooltip-pointer-events: none;
14
+
15
+ --tooltip-inner-position: relative;
16
+ --tooltip-inner-max-width: 200px;
17
+ --tooltip-inner-padding-y: .25em;
18
+ --tooltip-inner-padding-x: .5em;
19
+ --tooltip-inner-background-color: var(--colors-black, black);
20
+ --tooltip-inner-color: var(--color-white, white);
21
+ --tooltip-inner-text-align: center;
22
+ --tooltip-inner-border-radius: .333em;
23
+ --tooltip-inner-z-index: 2;
24
+ --tooltip-inner-dark-color: var(--color-white, white);
25
+ --tooltip-inner-dark-background-color: var(--colors-black, black);
26
+
27
+ --tooltip-arrow-position: absolute;
28
+ --tooltip-arrow-display: block;
29
+ --tooltip-arrow-width: .5em;
30
+ --tooltip-arrow-height: .5em;
31
+ --tooltip-arrow-z-index: 1;
32
+ --tooltip-color: var(--colors-black, black);
33
+ --tooltip-arrow-background-color: var(--tooltip-inner-background-color);
34
+ --tooltip-arrow-dark-background-color: var(--tooltip-inner-dark-background-color);
35
+ }
36
+
37
+ @utility tooltip {
38
+ position: var(--tooltip-position);
39
+ z-index: var(--tooltip-z-hiding-index);
40
+ display: var(--tooltip-display);
41
+ font-size: var(--tooltip-font-size);
42
+ word-wrap: var(--tooltip-word-wrap);
43
+ opacity: var(--tooltip-opacity-hidden);
44
+ transition: var(--tooltip-transition);
45
+ pointer-events: var(--tooltip-pointer-events);
46
+
47
+ &.show {
48
+ opacity: var(--tooltip-opacity-visible);
49
+ z-index: var(--tooltip-z-showing-index);
50
+ }
51
+
52
+ .tooltip-inner {
53
+ position: var(--tooltip-inner-position);
54
+ max-width: var(--tooltip-inner-max-width);
55
+ padding: var(--tooltip-inner-padding-y) var(--tooltip-inner-padding-x);
56
+ background-color: var(--tooltip-inner-background-color);
57
+ color: var(--tooltip-inner-color);
58
+ text-align: var(--tooltip-inner-text-align);
59
+ border-radius: var(--tooltip-inner-border-radius);
60
+ z-index: var(--tooltip-inner-z-index);
61
+ }
62
+
63
+ .tooltip-arrow {
64
+ position: var(--tooltip-arrow-position);
65
+ display: var(--tooltip-arrow-display);
66
+ width: var(--tooltip-arrow-width);
67
+ height: var(--tooltip-arrow-height);
68
+ background-color: var(--tooltip-arrow-background-color);
69
+ z-index: var(--tooltip-arrow-index);
70
+ }
71
+ }
package/index.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import Tooltip from './src/Tooltip.vue';
2
- import TooltipPlugin from './src/TooltipPlugin';
2
+ import { TooltipDirective, TooltipPlugin } from './src/TooltipPlugin';
3
3
 
4
4
  export {
5
5
  Tooltip,
6
+ TooltipDirective,
6
7
  TooltipPlugin
7
8
  };
package/package.json CHANGED
@@ -1,34 +1,24 @@
1
1
  {
2
2
  "name": "@vue-interface/tooltip",
3
- "version": "1.0.0-beta.9",
3
+ "version": "2.0.1",
4
4
  "description": "A Vue tooltip component.",
5
- "files": [
6
- "index.ts",
7
- "dist",
8
- "src",
9
- "tailwindcss"
10
- ],
11
5
  "type": "module",
12
6
  "main": "./dist/tooltip.umd.js",
13
7
  "module": "./dist/tooltip.js",
14
- "browserslist": "last 2 versions, > 0.5%, ie >= 11",
8
+ "types": "./dist/index.d.ts",
15
9
  "exports": {
16
10
  ".": {
11
+ "source": "./index.ts",
12
+ "types": "./dist/index.d.ts",
17
13
  "import": "./dist/tooltip.js",
18
- "require": "./dist/tooltip.umd.js",
19
- "types": "./index.ts"
14
+ "require": "./dist/tooltip.umd.js"
20
15
  },
21
- "./tailwindcss": "./tailwindcss/index.cjs",
22
- "./tailwindcss/safelist": "./tailwindcss/safelist.cjs"
23
- },
24
- "scripts": {
25
- "dev": "vite",
26
- "build": "vite build",
27
- "preview": "vite preview"
16
+ "./css": "./index.css"
28
17
  },
18
+ "browserslist": "last 2 versions, > 0.5%, ie >= 11",
29
19
  "repository": {
30
20
  "type": "git",
31
- "url": "git+https://github.com/vue-interface/tooltip.git"
21
+ "url": "git+https://github.com/vue-interface/vue-interface.github.io"
32
22
  },
33
23
  "keywords": [
34
24
  "Tooltip",
@@ -40,27 +30,30 @@
40
30
  "author": "Justin Kimbrell",
41
31
  "license": "ISC",
42
32
  "bugs": {
43
- "url": "https://github.com/vue-interface/tooltip/issues"
33
+ "url": "https://github.com/vue-interface/vue-interface.github.io"
44
34
  },
45
- "homepage": "https://github.com/vue-interface/tooltip",
35
+ "homepage": "https://github.com/vue-interface/vue-interface.github.io",
46
36
  "dependencies": {
47
37
  "@popperjs/core": "^2.4.4"
48
38
  },
49
39
  "peerDependencies": {
50
- "vue": "^3.0.0"
40
+ "@floating-ui/vue": "^1.1.7",
41
+ "vue": "^3.3.4"
51
42
  },
52
43
  "devDependencies": {
53
- "@vitejs/plugin-vue": "^3.0.1",
54
- "@vue-interface/eslint-config": "^1.0.0-beta.0",
55
- "autoprefixer": "^10.4.2",
56
- "change-case": "^4.1.2",
57
- "eslint": "^8.27.0",
58
- "pascalcase": "^2.0.0",
59
- "postcss": "^8.4.6",
60
- "tailwindcss": "^3.0.18",
61
- "typescript": "^5.0.2",
62
- "vite": "^3.0.0",
63
- "vite-plugin-dts": "^1.7.1",
64
- "vue": "^3.2.37"
44
+ "@floating-ui/dom": "^1.7.2"
45
+ },
46
+ "files": [
47
+ "dist",
48
+ "index.css",
49
+ "index.ts"
50
+ ],
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "scripts": {
55
+ "dev": "vite",
56
+ "build": "vue-tsc && vite build",
57
+ "preview": "vite preview"
65
58
  }
66
- }
59
+ }
@@ -1,82 +0,0 @@
1
- declare const _default: import("vue").DefineComponent<{
2
- offset: {
3
- type: ArrayConstructor;
4
- default: undefined;
5
- };
6
- popper: {
7
- type: ObjectConstructor;
8
- default: undefined;
9
- };
10
- placement: {
11
- type: StringConstructor;
12
- default: undefined;
13
- };
14
- target: {
15
- type: {
16
- new (): Element;
17
- prototype: Element;
18
- };
19
- required: true;
20
- };
21
- title: {
22
- type: StringConstructor;
23
- default: undefined;
24
- };
25
- show: BooleanConstructor;
26
- top: BooleanConstructor;
27
- bottom: BooleanConstructor;
28
- left: BooleanConstructor;
29
- right: BooleanConstructor;
30
- }, unknown, {
31
- currentShow: boolean;
32
- popperInstance: null;
33
- }, {
34
- computedPlacement(): any;
35
- tooltipClasses(): {
36
- [x: string]: any;
37
- show: any;
38
- };
39
- }, {
40
- open(): void;
41
- close(): void;
42
- }, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
43
- offset: {
44
- type: ArrayConstructor;
45
- default: undefined;
46
- };
47
- popper: {
48
- type: ObjectConstructor;
49
- default: undefined;
50
- };
51
- placement: {
52
- type: StringConstructor;
53
- default: undefined;
54
- };
55
- target: {
56
- type: {
57
- new (): Element;
58
- prototype: Element;
59
- };
60
- required: true;
61
- };
62
- title: {
63
- type: StringConstructor;
64
- default: undefined;
65
- };
66
- show: BooleanConstructor;
67
- top: BooleanConstructor;
68
- bottom: BooleanConstructor;
69
- left: BooleanConstructor;
70
- right: BooleanConstructor;
71
- }>>, {
72
- offset: unknown[];
73
- popper: Record<string, any>;
74
- placement: string;
75
- title: string;
76
- show: boolean;
77
- top: boolean;
78
- bottom: boolean;
79
- left: boolean;
80
- right: boolean;
81
- }>;
82
- export default _default;
package/dist/style.css DELETED
@@ -1 +0,0 @@
1
- .tooltip:not(.show){z-index:-1}
package/dist/vite.d.ts DELETED
@@ -1,5 +0,0 @@
1
- declare module '*.vue' {
2
- import { DefineComponent } from 'vue';
3
- const component: DefineComponent;
4
- export default component;
5
- }
package/src/Popper.ts DELETED
@@ -1,118 +0,0 @@
1
- import { createPopper } from '@popperjs/core';
2
- import { defineComponent } from 'vue';
3
-
4
- export default defineComponent({
5
-
6
- props: {
7
- offset: {
8
- type: Array,
9
- default: undefined
10
- },
11
-
12
- popper: {
13
- type: Object,
14
- default: undefined
15
- },
16
-
17
- placement: {
18
- type: String,
19
- default: undefined
20
- },
21
-
22
- target: {
23
- type: Element,
24
- required: true
25
- },
26
-
27
- title: {
28
- type: String,
29
- default: undefined
30
- },
31
-
32
- show: Boolean,
33
-
34
- top: Boolean,
35
-
36
- bottom: Boolean,
37
-
38
- left: Boolean,
39
-
40
- right: Boolean,
41
- },
42
-
43
- data() {
44
- return {
45
- currentShow: false,
46
- popperInstance: null
47
- };
48
- },
49
-
50
- computed: {
51
- computedPlacement() {
52
- if(this.placement) {
53
- return this.placement;
54
- }
55
-
56
- if(this.bottom) {
57
- return 'bottom';
58
- }
59
-
60
- if(this.left) {
61
- return 'left';
62
- }
63
-
64
- if(this.right) {
65
- return 'right';
66
- }
67
-
68
- return 'top';
69
- },
70
- tooltipClasses() {
71
- return {
72
- show: this.currentShow,
73
- [`bs-tooltip-${this.computedPlacement}`]: true
74
- };
75
- }
76
- },
77
-
78
- mounted() {
79
- this.popperInstance = createPopper(this.target, this.$el, Object.assign({
80
- placement: this.computedPlacement,
81
- modifiers: [
82
- {
83
- name: 'offset',
84
- options: {
85
- offset: [0, 6]
86
- },
87
- },
88
- {
89
- name: 'arrow',
90
- options: {
91
- element: this.$refs.arrow,
92
- },
93
- },
94
- ],
95
- }, this.popper));
96
-
97
- this.$nextTick(() => {
98
- this.currentShow = this.show;
99
- });
100
- },
101
-
102
- beforeUnmount() {
103
- this.popperInstance && this.popperInstance.destroy();
104
- },
105
-
106
- methods: {
107
-
108
- open() {
109
- this.currentShow = true;
110
- },
111
-
112
- close() {
113
- this.currentShow = false;
114
- }
115
-
116
- }
117
-
118
- });
package/src/Tooltip.vue DELETED
@@ -1,32 +0,0 @@
1
- <script lang="ts">
2
- import { defineComponent } from 'vue';
3
- import Popper from './Popper';
4
-
5
- export default defineComponent({
6
- mixins: [
7
- Popper
8
- ]
9
- });
10
- </script>
11
-
12
- <template>
13
- <div
14
- class="tooltip"
15
- :class="tooltipClasses"
16
- role="tooltip">
17
- <div
18
- ref="arrow"
19
- class="tooltip-arrow" />
20
- <div
21
- ref="inner"
22
- class="tooltip-inner">
23
- <slot>{{ title }}</slot>
24
- </div>
25
- </div>
26
- </template>
27
-
28
- <style>
29
- .tooltip:not(.show) {
30
- z-index: -1;
31
- }
32
- </style>