@vue-interface/tooltip 1.0.0-beta.14 → 1.0.0-beta.15
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.
- package/dist/tooltip.js +9 -9
- package/dist/tooltip.js.map +1 -1
- package/dist/tooltip.umd.cjs +1 -1
- package/dist/tooltip.umd.cjs.map +1 -1
- package/package.json +1 -1
- package/src/TooltipPlugin.ts +2 -2
package/dist/tooltip.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent as B, ref as b, computed as
|
|
1
|
+
import { defineComponent as B, ref as b, computed as y, onMounted as L, nextTick as O, onBeforeUnmount as S, openBlock as j, createElementBlock as k, normalizeClass as C, createElementVNode as x, renderSlot as F, createTextVNode as M, toDisplayString as R, h as I, render as P } from "vue";
|
|
2
2
|
import { createPopper as H } from "@popperjs/core";
|
|
3
3
|
const U = {
|
|
4
4
|
ref: "inner",
|
|
@@ -18,7 +18,7 @@ const U = {
|
|
|
18
18
|
right: { type: Boolean }
|
|
19
19
|
},
|
|
20
20
|
setup(d, { expose: h }) {
|
|
21
|
-
const n = d, u = b(), r = b(), a = b(!1), p = b(), v =
|
|
21
|
+
const n = d, u = b(), r = b(), a = b(!1), p = b(), v = y(() => n.placement ? n.placement : n.bottom ? "bottom" : n.left ? "left" : n.right ? "right" : "top"), T = y(() => ({
|
|
22
22
|
show: a,
|
|
23
23
|
[`bs-tooltip-${v.value}`]: !0
|
|
24
24
|
}));
|
|
@@ -94,7 +94,7 @@ function z(d, h = {}) {
|
|
|
94
94
|
P(i, l);
|
|
95
95
|
const [s] = [...l.children];
|
|
96
96
|
return document.body.append(s), () => {
|
|
97
|
-
n.delete(o), setTimeout(() => s.remove(), 150);
|
|
97
|
+
n.delete(o), window.setTimeout(() => s.remove(), 150);
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
100
|
function T(e) {
|
|
@@ -105,7 +105,7 @@ function z(d, h = {}) {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
function f(e, t = {}) {
|
|
108
|
-
var
|
|
108
|
+
var E, _;
|
|
109
109
|
const o = Object.assign({
|
|
110
110
|
title: e.getAttribute(r) || e.getAttribute("title")
|
|
111
111
|
}, t, p(e));
|
|
@@ -115,11 +115,11 @@ function z(d, h = {}) {
|
|
|
115
115
|
let i, s;
|
|
116
116
|
e.setAttribute(`${r}-id`, l), e.removeAttribute("title");
|
|
117
117
|
function g(c = 0) {
|
|
118
|
-
clearTimeout(s), i || (s = setTimeout(() => {
|
|
118
|
+
clearTimeout(s), i || (s = window.setTimeout(() => {
|
|
119
119
|
document.contains(e) && (i = v(e, o, l), n.set(l, i));
|
|
120
120
|
}, c));
|
|
121
121
|
}
|
|
122
|
-
function
|
|
122
|
+
function w(c = 0) {
|
|
123
123
|
clearTimeout(s), i && (s = setTimeout(() => {
|
|
124
124
|
i && i(), i = null;
|
|
125
125
|
}, c));
|
|
@@ -128,7 +128,7 @@ function z(d, h = {}) {
|
|
|
128
128
|
const [$, N] = c.split(":");
|
|
129
129
|
e.addEventListener($, () => A(Number(N || 0)));
|
|
130
130
|
}
|
|
131
|
-
(((
|
|
131
|
+
(((E = e.getAttribute(`${r}-trigger-open`)) == null ? void 0 : E.split(",")) || u.triggers.open).map((c) => m(c, g)), (((_ = e.getAttribute(`${r}-trigger-close`)) == null ? void 0 : _.split(",")) || u.triggers.close).map((c) => m(c, w));
|
|
132
132
|
}
|
|
133
133
|
d.mixin({
|
|
134
134
|
mounted() {
|
|
@@ -148,9 +148,9 @@ function z(d, h = {}) {
|
|
|
148
148
|
for (const { removedNodes: s } of l)
|
|
149
149
|
for (const g of s)
|
|
150
150
|
if (g instanceof Element)
|
|
151
|
-
for (const
|
|
151
|
+
for (const w of g.querySelectorAll(`[${r}-id]`)) {
|
|
152
152
|
const m = n.get(
|
|
153
|
-
|
|
153
|
+
w.getAttribute(`${r}-id`)
|
|
154
154
|
);
|
|
155
155
|
m && (i = !0, m());
|
|
156
156
|
}
|
package/dist/tooltip.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.js","sources":["../src/Tooltip.vue","../src/TooltipPlugin.ts"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { Instance, Offsets, OptionsGeneric, createPopper } from '@popperjs/core';\nimport { computed, nextTick, onBeforeUnmount, onMounted, ref } from 'vue';\n\nconst props = defineProps<{\n offset?: Offsets,\n popper?: OptionsGeneric<unknown>,\n placement?: string,\n target: Element,\n title?: string,\n show?: boolean,\n top?: boolean,\n bottom?: boolean,\n left?: boolean,\n right?: boolean\n}>();\n\nconst el = ref<HTMLElement>();\nconst arrow = ref<HTMLElement>();\nconst currentShow = ref(false);\nconst popperInstance = ref<Instance>();\n\nconst placement = computed(() => {\n if(props.placement) {\n return props.placement;\n }\n\n if(props.bottom) {\n return 'bottom';\n }\n\n if(props.left) {\n return 'left';\n }\n\n if(props.right) {\n return 'right';\n }\n\n return 'top';\n});\n\nconst tooltipClasses = computed(() => {\n return {\n show: currentShow,\n [`bs-tooltip-${placement.value}`]: true\n };\n});\n\nfunction open() {\n currentShow.value = true;\n}\n\nfunction close() {\n currentShow.value = false;\n}\n\ndefineExpose({\n open, close\n});\n\nonMounted(() => {\n if(!el.value) {\n return;\n }\n\n popperInstance.value = createPopper(props.target, el.value, Object.assign({\n placement: placement.value,\n modifiers: [\n {\n name: 'offset',\n options: {\n offset: [props.offset?.x ?? 0, props.offset?.y ?? 6]\n },\n },\n {\n name: 'arrow',\n options: {\n element: arrow.value,\n },\n },\n ],\n }, props.popper));\n\n nextTick(() => {\n currentShow.value = props.show;\n });\n});\n\nonBeforeUnmount(()=> {\n popperInstance.value && popperInstance.value.destroy();\n});\n</script>\n\n<template>\n <div\n ref=\"el\"\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 progressiveEnhancement: boolean,\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 progressiveEnhancement: true,\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,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\n function createTooltip(target: Element, props: Record<string,string> = {}, 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 // vnode.component?.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 destroyTooltip(target: Element) {\n const id = target.getAttribute(`${prefix}-id`);\n if(id) {\n const tooltip = tooltips.get(id);\n tooltip?.();\n }\n }\n\n function init(target: Element, props = {}) {\n const properties: Record<string,string> = 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 if(!options.progressiveEnhancement) {\n return;\n }\n \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\n let tooltipFound = false;\n for(const { removedNodes } of changes) {\n for(const node of removedNodes) {\n if(!(node instanceof Element)) {\n continue;\n }\n for(const el of node.querySelectorAll(`[${prefix}-id]`)) {\n const tooltip = tooltips.get(\n el.getAttribute(`${prefix}-id`) as string\n );\n if(tooltip) {\n tooltipFound = true;\n tooltip();\n }\n }\n } \n }\n\n // @experimental\n // In some cases in Inertia.js, not all tooltips are removed on certain actions.\n // remove all tooltips if no tooltip was found.\n if(!tooltipFound) {\n for(const tooltip of tooltips.values()) {\n tooltip();\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 destroyTooltip(target);\n }\n });\n}"],"names":["el","ref","arrow","currentShow","popperInstance","placement","computed","props","tooltipClasses","open","close","__expose","onMounted","createPopper","_a","_b","nextTick","onBeforeUnmount","TooltipPlugin","app","opts","tooltips","options","prefix","prefixRegExp","getAttributes","a","key","value","carry","attr","createTooltip","target","hash","container","vnode","h","Tooltip","render","destroyTooltip","id","tooltip","init","properties","timer","delay","addEventListener","trigger","fn","event","delayString","walker","node","changes","tooltipFound","removedNodes","binding"],"mappings":";;;;;;;;;;;;;;;;;;;;iBAiBMA,IAAKC,KACLC,IAAQD,KACRE,IAAcF,EAAI,EAAK,GACvBG,IAAiBH,KAEjBI,IAAYC,EAAS,MACpBC,EAAM,YACEA,EAAM,YAGdA,EAAM,SACE,WAGRA,EAAM,OACE,SAGRA,EAAM,QACE,UAGJ,KACV,GAEKC,IAAiBF,EAAS,OACrB;AAAA,MACH,MAAMH;AAAA,MACN,CAAC,cAAcE,EAAU,KAAK,EAAE,GAAG;AAAA,IAAA,EAE1C;AAED,aAASI,IAAO;AACZ,MAAAN,EAAY,QAAQ;AAAA,IACxB;AAEA,aAASO,IAAQ;AACb,MAAAP,EAAY,QAAQ;AAAA,IACxB;AAEa,WAAAQ,EAAA;AAAA,MACT,MAAAF;AAAA,MAAM,OAAAC;AAAA,IAAA,CACT,GAEDE,EAAU,MAAM;;AACT,MAACZ,EAAG,UAIPI,EA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;AAIE,aAAAD,EAAO;AACN,QAAAA,EAAO,uBAAuB,WAC7BT,EAAeS,EAAO,WAAW;AAkCzC,MA9BiB,IAAI,iBAAiB,CAACE,MAAY;AAE/C,YAAIC,IAAe;AACT,mBAAA,EAAE,cAAAC,EAAa,KAAKF;AAC1B,qBAAUD,KAAQG;AACX,gBAAEH,aAAgB;AAGrB,yBAAUpD,KAAMoD,EAAK,iBAAiB,IAAI7B,CAAM,MAAM,GAAG;AACrD,sBAAMkB,IAAUpB,EAAS;AAAA,kBACrBrB,EAAG,aAAa,GAAGuB,CAAM,KAAK;AAAA,gBAAA;AAElC,gBAAGkB,MACgBa,IAAA,IACPb;cAEhB;AAOR,YAAG,CAACa;AACU,qBAAAb,KAAWpB,EAAS;AAClB,YAAAoB;MAEhB,CACH,EAEQ,QAAQzC,GAAI,EAAE,WAAW,GAAM,CAAA;AAAA,IAC5C;AAAA,EAAA,CACH,GAEDmB,EAAI,UAAU,WAAW;AAAA,IACrB,YAAYa,GAAQwB,GAAS;AACpB,MAAAd,EAAAV,GAAQ,OAAO,OAAO,CAAA,GAAIwB,EAAQ,WAAWA,EAAQ,KAAK,CAAC;AAAA,IACpE;AAAA,IACA,cAAcxB,GAAQ;AAClB,MAAAO,EAAeP,CAAM;AAAA,IACzB;AAAA,EAAA,CACH;AACL;"}
|
|
1
|
+
{"version":3,"file":"tooltip.js","sources":["../src/Tooltip.vue","../src/TooltipPlugin.ts"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { Instance, Offsets, OptionsGeneric, createPopper } from '@popperjs/core';\nimport { computed, nextTick, onBeforeUnmount, onMounted, ref } from 'vue';\n\nconst props = defineProps<{\n offset?: Offsets,\n popper?: OptionsGeneric<unknown>,\n placement?: string,\n target: Element,\n title?: string,\n show?: boolean,\n top?: boolean,\n bottom?: boolean,\n left?: boolean,\n right?: boolean\n}>();\n\nconst el = ref<HTMLElement>();\nconst arrow = ref<HTMLElement>();\nconst currentShow = ref(false);\nconst popperInstance = ref<Instance>();\n\nconst placement = computed(() => {\n if(props.placement) {\n return props.placement;\n }\n\n if(props.bottom) {\n return 'bottom';\n }\n\n if(props.left) {\n return 'left';\n }\n\n if(props.right) {\n return 'right';\n }\n\n return 'top';\n});\n\nconst tooltipClasses = computed(() => {\n return {\n show: currentShow,\n [`bs-tooltip-${placement.value}`]: true\n };\n});\n\nfunction open() {\n currentShow.value = true;\n}\n\nfunction close() {\n currentShow.value = false;\n}\n\ndefineExpose({\n open, close\n});\n\nonMounted(() => {\n if(!el.value) {\n return;\n }\n\n popperInstance.value = createPopper(props.target, el.value, Object.assign({\n placement: placement.value,\n modifiers: [\n {\n name: 'offset',\n options: {\n offset: [props.offset?.x ?? 0, props.offset?.y ?? 6]\n },\n },\n {\n name: 'arrow',\n options: {\n element: arrow.value,\n },\n },\n ],\n }, props.popper));\n\n nextTick(() => {\n currentShow.value = props.show;\n });\n});\n\nonBeforeUnmount(()=> {\n popperInstance.value && popperInstance.value.destroy();\n});\n</script>\n\n<template>\n <div\n ref=\"el\"\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 progressiveEnhancement: boolean,\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 progressiveEnhancement: true,\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,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\n function createTooltip(target: Element, props: Record<string,string> = {}, 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 // vnode.component?.close();\n \n // @todo: Make the animation rate (150) dynamic. Should get value \n // from the CSS transition duration.\n window.setTimeout(() => el.remove(), 150);\n };\n }\n\n function destroyTooltip(target: Element) {\n const id = target.getAttribute(`${prefix}-id`);\n if(id) {\n const tooltip = tooltips.get(id);\n tooltip?.();\n }\n }\n\n function init(target: Element, props = {}) {\n const properties: Record<string,string> = 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 = window.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 if(!options.progressiveEnhancement) {\n return;\n }\n \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\n let tooltipFound = false;\n for(const { removedNodes } of changes) {\n for(const node of removedNodes) {\n if(!(node instanceof Element)) {\n continue;\n }\n for(const el of node.querySelectorAll(`[${prefix}-id]`)) {\n const tooltip = tooltips.get(\n el.getAttribute(`${prefix}-id`) as string\n );\n if(tooltip) {\n tooltipFound = true;\n tooltip();\n }\n }\n } \n }\n\n // @experimental\n // In some cases in Inertia.js, not all tooltips are removed on certain actions.\n // remove all tooltips if no tooltip was found.\n if(!tooltipFound) {\n for(const tooltip of tooltips.values()) {\n tooltip();\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 destroyTooltip(target);\n }\n });\n}"],"names":["el","ref","arrow","currentShow","popperInstance","placement","computed","props","tooltipClasses","open","close","__expose","onMounted","createPopper","_a","_b","nextTick","onBeforeUnmount","TooltipPlugin","app","opts","tooltips","options","prefix","prefixRegExp","getAttributes","a","key","value","carry","attr","createTooltip","target","hash","container","vnode","h","Tooltip","render","destroyTooltip","id","tooltip","init","properties","timer","delay","addEventListener","trigger","fn","event","delayString","walker","node","changes","tooltipFound","removedNodes","binding"],"mappings":";;;;;;;;;;;;;;;;;;;;iBAiBMA,IAAKC,KACLC,IAAQD,KACRE,IAAcF,EAAI,EAAK,GACvBG,IAAiBH,KAEjBI,IAAYC,EAAS,MACpBC,EAAM,YACEA,EAAM,YAGdA,EAAM,SACE,WAGRA,EAAM,OACE,SAGRA,EAAM,QACE,UAGJ,KACV,GAEKC,IAAiBF,EAAS,OACrB;AAAA,MACH,MAAMH;AAAA,MACN,CAAC,cAAcE,EAAU,KAAK,EAAE,GAAG;AAAA,IAAA,EAE1C;AAED,aAASI,IAAO;AACZ,MAAAN,EAAY,QAAQ;AAAA,IACxB;AAEA,aAASO,IAAQ;AACb,MAAAP,EAAY,QAAQ;AAAA,IACxB;AAEa,WAAAQ,EAAA;AAAA,MACT,MAAAF;AAAA,MAAM,OAAAC;AAAA,IAAA,CACT,GAEDE,EAAU,MAAM;;AACT,MAACZ,EAAG,UAIPI,EAAe,QAAQS,EAAaN,EAAM,QAAQP,EAAG,OAAO,OAAO,OAAO;AAAA,QACtE,WAAWK,EAAU;AAAA,QACrB,WAAW;AAAA,UACP;AAAA,YACI,MAAM;AAAA,YACN,SAAS;AAAA,cACL,QAAQ,GAACS,IAAAP,EAAM,WAAN,gBAAAO,EAAc,MAAK,KAAGC,IAAAR,EAAM,WAAN,gBAAAQ,EAAc,MAAK,CAAC;AAAA,YACvD;AAAA,UACJ;AAAA,UACA;AAAA,YACI,MAAM;AAAA,YACN,SAAS;AAAA,cACL,SAASb,EAAM;AAAA,YACnB;AAAA,UACJ;AAAA,QACJ;AAAA,MAAA,GACDK,EAAM,MAAM,CAAC,GAEhBS,EAAS,MAAM;AACX,QAAAb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KAAWpB,EAAS;AAClB,YAAAoB;MAEhB,CACH,EAEQ,QAAQzC,GAAI,EAAE,WAAW,GAAM,CAAA;AAAA,IAC5C;AAAA,EAAA,CACH,GAEDmB,EAAI,UAAU,WAAW;AAAA,IACrB,YAAYa,GAAQwB,GAAS;AACpB,MAAAd,EAAAV,GAAQ,OAAO,OAAO,CAAA,GAAIwB,EAAQ,WAAWA,EAAQ,KAAK,CAAC;AAAA,IACpE;AAAA,IACA,cAAcxB,GAAQ;AAClB,MAAAO,EAAeP,CAAM;AAAA,IACzB;AAAA,EAAA,CACH;AACL;"}
|
package/dist/tooltip.umd.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(p,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):(p=typeof globalThis<"u"?globalThis:p||self,o(p.Tooltip={},p.Vue,p.PopperjsCore))})(this,function(p,o,A){"use strict";const $={ref:"inner",class:"tooltip-inner"},
|
|
1
|
+
(function(p,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):(p=typeof globalThis<"u"?globalThis:p||self,o(p.Tooltip={},p.Vue,p.PopperjsCore))})(this,function(p,o,A){"use strict";const $={ref:"inner",class:"tooltip-inner"},w=o.defineComponent({__name:"Tooltip",props:{offset:{},popper:{},placement:{},target:{},title:{},show:{type:Boolean},top:{type:Boolean},bottom:{type:Boolean},left:{type:Boolean},right:{type:Boolean}},setup(b,{expose:y}){const i=b,u=o.ref(),r=o.ref(),a=o.ref(!1),d=o.ref(),h=o.computed(()=>i.placement?i.placement:i.bottom?"bottom":i.left?"left":i.right?"right":"top"),v=o.computed(()=>({show:a,[`bs-tooltip-${h.value}`]:!0}));function m(){a.value=!0}function e(){a.value=!1}return y({open:m,close:e}),o.onMounted(()=>{var t,n;u.value&&(d.value=A.createPopper(i.target,u.value,Object.assign({placement:h.value,modifiers:[{name:"offset",options:{offset:[((t=i.offset)==null?void 0:t.x)??0,((n=i.offset)==null?void 0:n.y)??6]}},{name:"arrow",options:{element:r.value}}]},i.popper)),o.nextTick(()=>{a.value=i.show}))}),o.onBeforeUnmount(()=>{d.value&&d.value.destroy()}),(t,n)=>(o.openBlock(),o.createElementBlock("div",{ref_key:"el",ref:u,class:o.normalizeClass(["tooltip",v.value]),role:"tooltip"},[o.createElementVNode("div",{ref_key:"arrow",ref:r,class:"tooltip-arrow"},null,512),o.createElementVNode("div",$,[o.renderSlot(t.$slots,"default",{},()=>[o.createTextVNode(o.toDisplayString(t.title),1)])],512)],2))}}),B="";function N(b,y={}){const i=new Map,u=Object.assign({delay:void 0,prefix:"data-tooltip",progressiveEnhancement:!0,triggers:{open:["mouseover:350"],close:["mouseout:100"]}},y),r=u.prefix.replace(/[-]+$/,""),a=new RegExp(`^${r}-`);function d(e){return Array.from(e.attributes).map(t=>[t.name,t.value]).filter(([t])=>t==="title"||t.match(a)).map(([t,n])=>[t.replace(new RegExp(a),""),n]).reduce((t,n)=>Object.assign(t,{[n[0]]:n[1]}),{})}function h(e,t={},n){const c=document.createElement("template"),s=o.h(w,Object.assign({target:e,show:!0},t));o.render(s,c);const[l]=[...c.children];return document.body.append(l),()=>{i.delete(n),window.setTimeout(()=>l.remove(),150)}}function v(e){const t=e.getAttribute(`${r}-id`);if(t){const n=i.get(t);n==null||n()}}function m(e,t={}){var _,x;const n=Object.assign({title:e.getAttribute(r)||e.getAttribute("title")},t,d(e));if(!n.title||e.hasAttribute(`${r}-id`))return;const c=Math.random().toString(36).slice(2,7);let s,l;e.setAttribute(`${r}-id`,c),e.removeAttribute("title");function T(f=0){clearTimeout(l),s||(l=window.setTimeout(()=>{document.contains(e)&&(s=h(e,n,c),i.set(c,s))},f))}function E(f=0){clearTimeout(l),s&&(l=setTimeout(()=>{s&&s(),s=null},f))}function g(f,j){const[O,S]=f.split(":");e.addEventListener(O,()=>j(Number(S||0)))}(((_=e.getAttribute(`${r}-trigger-open`))==null?void 0:_.split(","))||u.triggers.open).map(f=>g(f,T)),(((x=e.getAttribute(`${r}-trigger-close`))==null?void 0:x.split(","))||u.triggers.close).map(f=>g(f,E))}b.mixin({mounted(){if(!u.progressiveEnhancement)return;let e=this.$el;this.$el instanceof Text&&(e=this.$el.parentNode),e instanceof HTMLElement&&m(e);const t=document.createTreeWalker(e,NodeFilter.SHOW_ALL,c=>c instanceof Element?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT);for(;t.nextNode();)t.currentNode instanceof Element&&m(t.currentNode);new MutationObserver(c=>{let s=!1;for(const{removedNodes:l}of c)for(const T of l)if(T instanceof Element)for(const E of T.querySelectorAll(`[${r}-id]`)){const g=i.get(E.getAttribute(`${r}-id`));g&&(s=!0,g())}if(!s)for(const l of i.values())l()}).observe(e,{childList:!0})}}),b.directive("tooltip",{beforeMount(e,t){m(e,Object.assign({},t.modifiers,t.value))},beforeUnmount(e){v(e)}})}p.Tooltip=w,p.TooltipPlugin=N,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
|
|
2
2
|
//# sourceMappingURL=tooltip.umd.cjs.map
|
package/dist/tooltip.umd.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.umd.cjs","sources":["../src/Tooltip.vue","../src/TooltipPlugin.ts"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { Instance, Offsets, OptionsGeneric, createPopper } from '@popperjs/core';\nimport { computed, nextTick, onBeforeUnmount, onMounted, ref } from 'vue';\n\nconst props = defineProps<{\n offset?: Offsets,\n popper?: OptionsGeneric<unknown>,\n placement?: string,\n target: Element,\n title?: string,\n show?: boolean,\n top?: boolean,\n bottom?: boolean,\n left?: boolean,\n right?: boolean\n}>();\n\nconst el = ref<HTMLElement>();\nconst arrow = ref<HTMLElement>();\nconst currentShow = ref(false);\nconst popperInstance = ref<Instance>();\n\nconst placement = computed(() => {\n if(props.placement) {\n return props.placement;\n }\n\n if(props.bottom) {\n return 'bottom';\n }\n\n if(props.left) {\n return 'left';\n }\n\n if(props.right) {\n return 'right';\n }\n\n return 'top';\n});\n\nconst tooltipClasses = computed(() => {\n return {\n show: currentShow,\n [`bs-tooltip-${placement.value}`]: true\n };\n});\n\nfunction open() {\n currentShow.value = true;\n}\n\nfunction close() {\n currentShow.value = false;\n}\n\ndefineExpose({\n open, close\n});\n\nonMounted(() => {\n if(!el.value) {\n return;\n }\n\n popperInstance.value = createPopper(props.target, el.value, Object.assign({\n placement: placement.value,\n modifiers: [\n {\n name: 'offset',\n options: {\n offset: [props.offset?.x ?? 0, props.offset?.y ?? 6]\n },\n },\n {\n name: 'arrow',\n options: {\n element: arrow.value,\n },\n },\n ],\n }, props.popper));\n\n nextTick(() => {\n currentShow.value = props.show;\n });\n});\n\nonBeforeUnmount(()=> {\n popperInstance.value && popperInstance.value.destroy();\n});\n</script>\n\n<template>\n <div\n ref=\"el\"\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 progressiveEnhancement: boolean,\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 progressiveEnhancement: true,\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,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\n function createTooltip(target: Element, props: Record<string,string> = {}, 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 // vnode.component?.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 destroyTooltip(target: Element) {\n const id = target.getAttribute(`${prefix}-id`);\n if(id) {\n const tooltip = tooltips.get(id);\n tooltip?.();\n }\n }\n\n function init(target: Element, props = {}) {\n const properties: Record<string,string> = 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 if(!options.progressiveEnhancement) {\n return;\n }\n \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\n let tooltipFound = false;\n for(const { removedNodes } of changes) {\n for(const node of removedNodes) {\n if(!(node instanceof Element)) {\n continue;\n }\n for(const el of node.querySelectorAll(`[${prefix}-id]`)) {\n const tooltip = tooltips.get(\n el.getAttribute(`${prefix}-id`) as string\n );\n if(tooltip) {\n tooltipFound = true;\n tooltip();\n }\n }\n } \n }\n\n // @experimental\n // In some cases in Inertia.js, not all tooltips are removed on certain actions.\n // remove all tooltips if no tooltip was found.\n if(!tooltipFound) {\n for(const tooltip of tooltips.values()) {\n tooltip();\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 destroyTooltip(target);\n }\n });\n}"],"names":["el","ref","arrow","currentShow","popperInstance","placement","computed","props","tooltipClasses","open","close","__expose","onMounted","createPopper","_a","_b","nextTick","onBeforeUnmount","TooltipPlugin","app","opts","tooltips","options","prefix","prefixRegExp","getAttributes","a","key","value","carry","attr","createTooltip","target","hash","container","vnode","h","Tooltip","render","destroyTooltip","id","tooltip","init","properties","timer","delay","addEventListener","trigger","fn","event","delayString","walker","node","changes","tooltipFound","removedNodes","binding"],"mappings":"0kBAiBMA,EAAKC,EAAAA,MACLC,EAAQD,EAAAA,MACRE,EAAcF,MAAI,EAAK,EACvBG,EAAiBH,EAAAA,MAEjBI,EAAYC,EAAAA,SAAS,IACpBC,EAAM,UACEA,EAAM,UAGdA,EAAM,OACE,SAGRA,EAAM,KACE,OAGRA,EAAM,MACE,QAGJ,KACV,EAEKC,EAAiBF,EAAAA,SAAS,KACrB,CACH,KAAMH,EACN,CAAC,cAAcE,EAAU,KAAK,EAAE,EAAG,EAAA,EAE1C,EAED,SAASI,GAAO,CACZN,EAAY,MAAQ,EACxB,CAEA,SAASO,GAAQ,CACbP,EAAY,MAAQ,EACxB,CAEa,OAAAQ,EAAA,CACT,KAAAF,EAAM,MAAAC,CAAA,CACT,EAEDE,EAAAA,UAAU,IAAM,SACRZ,EAAG,QAIPI,EAAe,MAAQS,EAAAA,aAAaN,EAAM,OAAQP,EAAG,MAAO,OAAO,OAAO,CACtE,UAAWK,EAAU,MACrB,UAAW,CACP,CACI,KAAM,SACN,QAAS,CACL,OAAQ,GAACS,EAAAP,EAAM,SAAN,YAAAO,EAAc,IAAK,IAAGC,EAAAR,EAAM,SAAN,YAAAQ,EAAc,IAAK,CAAC,CACvD,CACJ,EACA,CACI,KAAM,QACN,QAAS,CACL,QAASb,EAAM,KACnB,CACJ,CACJ,CAAA,EACDK,EAAM,MAAM,CAAC,EAEhBS,EAAAA,SAAS,IAAM,CACXb,EAAY,MAAQI,EAAM,IAAA,CAC7B,EAAA,CACJ,EAEDU,EAAAA,gBAAgB,IAAK,CACFb,EAAA,OAASA,EAAe,MAAM,QAAQ,CAAA,CACxD,kWC7EwB,SAAAc,EAAAC,EAAUC,EAAsC,GAA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AAS,OAC3E,OAAewB,EAAiBC,EAASrC,CAAK,CAAC,CACxD,CAEAS,EAAI,MAAM,CACN,SAAU,CACH,GAAA,CAACG,EAAQ,uBACR,OAGJ,IAAItB,EAAK,KAAK,IAEX,KAAK,eAAe,OACnBA,EAAK,KAAK,IAAI,YAGfA,aAAc,aACb0C,EAAK1C,CAAE,EAIX,MAAMmD,EAAS,SAAS,iBACpBnD,EACA,WAAW,SACVoD,GACQA,aAAgB,QAId,WAAW,cAHP,WAAW,aAI1B,EAIE,KAAAD,EAAO,YACNA,EAAO,uBAAuB,SAC7BT,EAAeS,EAAO,WAAW,EAIxB,IAAI,iBAAkBE,GAAY,CAE/C,IAAIC,EAAe,GACT,SAAA,CAAE,aAAAC,CAAa,IAAKF,EAC1B,UAAUD,KAAQG,EACX,GAAEH,aAAgB,QAGrB,UAAUpD,KAAMoD,EAAK,iBAAiB,IAAI7B,CAAM,MAAM,EAAG,CACrD,MAAMkB,EAAUpB,EAAS,IACrBrB,EAAG,aAAa,GAAGuB,CAAM,KAAK,CAAA,EAE/BkB,IACgBa,EAAA,GACPb,IAEhB,CAOR,GAAG,CAACa,EACU,UAAAb,KAAWpB,EAAS,SAClBoB,GAEhB,CACH,EAEQ,QAAQzC,EAAI,CAAE,UAAW,EAAM,CAAA,CAC5C,CAAA,CACH,EAEDmB,EAAI,UAAU,UAAW,CACrB,YAAYa,EAAQwB,EAAS,CACpBd,EAAAV,EAAQ,OAAO,OAAO,CAAA,EAAIwB,EAAQ,UAAWA,EAAQ,KAAK,CAAC,CACpE,EACA,cAAcxB,EAAQ,CAClBO,EAAeP,CAAM,CACzB,CAAA,CACH,CACL"}
|
|
1
|
+
{"version":3,"file":"tooltip.umd.cjs","sources":["../src/Tooltip.vue","../src/TooltipPlugin.ts"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { Instance, Offsets, OptionsGeneric, createPopper } from '@popperjs/core';\nimport { computed, nextTick, onBeforeUnmount, onMounted, ref } from 'vue';\n\nconst props = defineProps<{\n offset?: Offsets,\n popper?: OptionsGeneric<unknown>,\n placement?: string,\n target: Element,\n title?: string,\n show?: boolean,\n top?: boolean,\n bottom?: boolean,\n left?: boolean,\n right?: boolean\n}>();\n\nconst el = ref<HTMLElement>();\nconst arrow = ref<HTMLElement>();\nconst currentShow = ref(false);\nconst popperInstance = ref<Instance>();\n\nconst placement = computed(() => {\n if(props.placement) {\n return props.placement;\n }\n\n if(props.bottom) {\n return 'bottom';\n }\n\n if(props.left) {\n return 'left';\n }\n\n if(props.right) {\n return 'right';\n }\n\n return 'top';\n});\n\nconst tooltipClasses = computed(() => {\n return {\n show: currentShow,\n [`bs-tooltip-${placement.value}`]: true\n };\n});\n\nfunction open() {\n currentShow.value = true;\n}\n\nfunction close() {\n currentShow.value = false;\n}\n\ndefineExpose({\n open, close\n});\n\nonMounted(() => {\n if(!el.value) {\n return;\n }\n\n popperInstance.value = createPopper(props.target, el.value, Object.assign({\n placement: placement.value,\n modifiers: [\n {\n name: 'offset',\n options: {\n offset: [props.offset?.x ?? 0, props.offset?.y ?? 6]\n },\n },\n {\n name: 'arrow',\n options: {\n element: arrow.value,\n },\n },\n ],\n }, props.popper));\n\n nextTick(() => {\n currentShow.value = props.show;\n });\n});\n\nonBeforeUnmount(()=> {\n popperInstance.value && popperInstance.value.destroy();\n});\n</script>\n\n<template>\n <div\n ref=\"el\"\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 progressiveEnhancement: boolean,\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 progressiveEnhancement: true,\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,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\n function createTooltip(target: Element, props: Record<string,string> = {}, 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 // vnode.component?.close();\n \n // @todo: Make the animation rate (150) dynamic. Should get value \n // from the CSS transition duration.\n window.setTimeout(() => el.remove(), 150);\n };\n }\n\n function destroyTooltip(target: Element) {\n const id = target.getAttribute(`${prefix}-id`);\n if(id) {\n const tooltip = tooltips.get(id);\n tooltip?.();\n }\n }\n\n function init(target: Element, props = {}) {\n const properties: Record<string,string> = 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 = window.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 if(!options.progressiveEnhancement) {\n return;\n }\n \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\n let tooltipFound = false;\n for(const { removedNodes } of changes) {\n for(const node of removedNodes) {\n if(!(node instanceof Element)) {\n continue;\n }\n for(const el of node.querySelectorAll(`[${prefix}-id]`)) {\n const tooltip = tooltips.get(\n el.getAttribute(`${prefix}-id`) as string\n );\n if(tooltip) {\n tooltipFound = true;\n tooltip();\n }\n }\n } \n }\n\n // @experimental\n // In some cases in Inertia.js, not all tooltips are removed on certain actions.\n // remove all tooltips if no tooltip was found.\n if(!tooltipFound) {\n for(const tooltip of tooltips.values()) {\n tooltip();\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 destroyTooltip(target);\n }\n });\n}"],"names":["el","ref","arrow","currentShow","popperInstance","placement","computed","props","tooltipClasses","open","close","__expose","onMounted","createPopper","_a","_b","nextTick","onBeforeUnmount","TooltipPlugin","app","opts","tooltips","options","prefix","prefixRegExp","getAttributes","a","key","value","carry","attr","createTooltip","target","hash","container","vnode","h","Tooltip","render","destroyTooltip","id","tooltip","init","properties","timer","delay","addEventListener","trigger","fn","event","delayString","walker","node","changes","tooltipFound","removedNodes","binding"],"mappings":"0kBAiBMA,EAAKC,EAAAA,MACLC,EAAQD,EAAAA,MACRE,EAAcF,MAAI,EAAK,EACvBG,EAAiBH,EAAAA,MAEjBI,EAAYC,EAAAA,SAAS,IACpBC,EAAM,UACEA,EAAM,UAGdA,EAAM,OACE,SAGRA,EAAM,KACE,OAGRA,EAAM,MACE,QAGJ,KACV,EAEKC,EAAiBF,EAAAA,SAAS,KACrB,CACH,KAAMH,EACN,CAAC,cAAcE,EAAU,KAAK,EAAE,EAAG,EAAA,EAE1C,EAED,SAASI,GAAO,CACZN,EAAY,MAAQ,EACxB,CAEA,SAASO,GAAQ,CACbP,EAAY,MAAQ,EACxB,CAEa,OAAAQ,EAAA,CACT,KAAAF,EAAM,MAAAC,CAAA,CACT,EAEDE,EAAAA,UAAU,IAAM,SACRZ,EAAG,QAIPI,EAAe,MAAQS,EAAAA,aAAaN,EAAM,OAAQP,EAAG,MAAO,OAAO,OAAO,CACtE,UAAWK,EAAU,MACrB,UAAW,CACP,CACI,KAAM,SACN,QAAS,CACL,OAAQ,GAACS,EAAAP,EAAM,SAAN,YAAAO,EAAc,IAAK,IAAGC,EAAAR,EAAM,SAAN,YAAAQ,EAAc,IAAK,CAAC,CACvD,CACJ,EACA,CACI,KAAM,QACN,QAAS,CACL,QAASb,EAAM,KACnB,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AAeP,CAAM,CACzB,CAAA,CACH,CACL"}
|
package/package.json
CHANGED
package/src/TooltipPlugin.ts
CHANGED
|
@@ -57,7 +57,7 @@ export default function (app: App, opts: Partial<TooltipPluginOptions> = {}) {
|
|
|
57
57
|
|
|
58
58
|
// @todo: Make the animation rate (150) dynamic. Should get value
|
|
59
59
|
// from the CSS transition duration.
|
|
60
|
-
setTimeout(() => el.remove(), 150);
|
|
60
|
+
window.setTimeout(() => el.remove(), 150);
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -94,7 +94,7 @@ export default function (app: App, opts: Partial<TooltipPluginOptions> = {}) {
|
|
|
94
94
|
clearTimeout(timer);
|
|
95
95
|
|
|
96
96
|
if(!tooltip) {
|
|
97
|
-
timer = setTimeout(() => {
|
|
97
|
+
timer = window.setTimeout(() => {
|
|
98
98
|
// Do a check before creating the tooltip to ensure the dom
|
|
99
99
|
// element still exists. Its possible for the element to
|
|
100
100
|
// be removed after the timeout delay runs.
|