@vue-interface/tooltip 1.0.0-beta.2 → 1.0.0-beta.6
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/index.d.ts +3 -0
- package/dist/src/Popper.d.ts +73 -0
- package/dist/src/Tooltip.vue.d.ts +73 -0
- package/dist/src/TooltipPlugin.d.ts +11 -0
- package/dist/tooltip.js +193 -0
- package/dist/tooltip.js.map +1 -0
- package/dist/tooltip.umd.cjs +2 -0
- package/dist/tooltip.umd.cjs.map +1 -0
- package/dist/vite.d.ts +5 -0
- package/index.ts +1 -1
- package/package.json +6 -12
- package/src/{Popper.js → Popper.ts} +69 -24
- package/src/Tooltip.vue +19 -12
- package/src/TooltipPlugin.ts +73 -23
- package/tailwindcss/{index.js → index.cjs} +8 -8
- package/dist/Tooltip.vue.d.ts +0 -4
- package/dist/TooltipPlugin.d.ts +0 -9
- package/dist/tooltip.es.js +0 -1137
- package/dist/tooltip.umd.js +0 -5
- /package/dist/{tooltip.css → style.css} +0 -0
- /package/tailwindcss/{safelist.js → safelist.cjs} +0 -0
package/src/Tooltip.vue
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="tooltip" :class="tooltipClasses" role="tooltip">
|
|
3
|
-
<div ref="arrow" class="tooltip-arrow" />
|
|
4
|
-
<div ref="inner" class="tooltip-inner">
|
|
5
|
-
<slot>{{ title }}</slot>
|
|
6
|
-
</div>
|
|
7
|
-
</div>
|
|
8
|
-
</template>
|
|
9
|
-
|
|
10
1
|
<script lang="ts">
|
|
11
|
-
|
|
2
|
+
import { defineComponent } from 'vue';
|
|
12
3
|
import Popper from './Popper';
|
|
13
4
|
|
|
14
|
-
export default {
|
|
5
|
+
export default defineComponent({
|
|
15
6
|
mixins: [
|
|
16
7
|
Popper
|
|
17
8
|
]
|
|
18
|
-
};
|
|
9
|
+
});
|
|
19
10
|
</script>
|
|
20
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
|
+
|
|
21
28
|
<style>
|
|
22
29
|
.tooltip:not(.show) {
|
|
23
30
|
z-index: -1;
|
package/src/TooltipPlugin.ts
CHANGED
|
@@ -1,29 +1,42 @@
|
|
|
1
|
-
import type { App
|
|
1
|
+
import type { App } from 'vue';
|
|
2
2
|
import { h, render } from 'vue';
|
|
3
3
|
import Tooltip from './Tooltip.vue';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
delay
|
|
7
|
-
prefix:
|
|
5
|
+
type TooltipPluginOptions = {
|
|
6
|
+
delay?: number,
|
|
7
|
+
prefix: string,
|
|
8
8
|
triggers: {
|
|
9
|
-
open: [
|
|
10
|
-
close: [
|
|
9
|
+
open: string[],
|
|
10
|
+
close: string[],
|
|
11
11
|
}
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default function (app: App, opts: Partial<TooltipPluginOptions> = {}) {
|
|
15
|
+
const tooltips: Map<string,Function> = new Map;
|
|
16
|
+
|
|
17
|
+
const options: TooltipPluginOptions = Object.assign({
|
|
18
|
+
delay: undefined,
|
|
19
|
+
prefix: 'data-tooltip',
|
|
20
|
+
triggers: {
|
|
21
|
+
open: ['mouseover:350'],
|
|
22
|
+
close: ['mouseout:100'],
|
|
23
|
+
}
|
|
24
|
+
}, opts);
|
|
25
|
+
|
|
13
26
|
const prefix = options.prefix.replace(/[-]+$/, '');
|
|
14
27
|
const prefixRegExp = new RegExp(`^${prefix}\-`);
|
|
15
28
|
|
|
16
29
|
function getAttributes(el: Element): Record<string,any> {
|
|
17
30
|
return Array.from(el.attributes)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
31
|
+
.map(a => [a.name, a.value])
|
|
32
|
+
.filter(([key]) => key === 'title' || key.match(prefixRegExp))
|
|
33
|
+
.map(([key, value]) => [key.replace(new RegExp(prefixRegExp), ''), value])
|
|
34
|
+
.reduce((carry, attr) => Object.assign(carry, { [attr[0]]: attr[1] }), {});
|
|
22
35
|
}
|
|
23
36
|
|
|
24
|
-
function createTooltip(target: Element, props: Record<string,any> = {}): Function {
|
|
37
|
+
function createTooltip(target: Element, props: Record<string,any> = {}, hash: string): Function {
|
|
25
38
|
const container = document.createElement('template');
|
|
26
|
-
|
|
39
|
+
|
|
27
40
|
const vnode = h(Tooltip, Object.assign({
|
|
28
41
|
target,
|
|
29
42
|
show: true
|
|
@@ -36,6 +49,8 @@ export default function(app: App, options = {
|
|
|
36
49
|
document.body.append(el);
|
|
37
50
|
|
|
38
51
|
return () => {
|
|
52
|
+
tooltips.delete(hash);
|
|
53
|
+
|
|
39
54
|
// @ts-ignore
|
|
40
55
|
vnode.component?.ctx.close();
|
|
41
56
|
|
|
@@ -71,7 +86,13 @@ export default function(app: App, options = {
|
|
|
71
86
|
|
|
72
87
|
if(!tooltip) {
|
|
73
88
|
timer = setTimeout(() => {
|
|
74
|
-
tooltip
|
|
89
|
+
// Do a check before creating the tooltip to ensure the dom
|
|
90
|
+
// element still exists. Its possible for the element to
|
|
91
|
+
// be removed after the timeout delay runs.
|
|
92
|
+
if(document.contains(target)) {
|
|
93
|
+
tooltip = createTooltip(target, properties, hash);
|
|
94
|
+
tooltips.set(hash, tooltip);
|
|
95
|
+
}
|
|
75
96
|
}, delay);
|
|
76
97
|
}
|
|
77
98
|
}
|
|
@@ -90,11 +111,14 @@ export default function(app: App, options = {
|
|
|
90
111
|
function addEventListener(trigger: string, fn: Function) {
|
|
91
112
|
const [ event, delayString ] = trigger.split(':');
|
|
92
113
|
|
|
93
|
-
target.addEventListener(event, () => fn(Number(delayString || 0)))
|
|
114
|
+
target.addEventListener(event, () => fn(Number(delayString || 0)));
|
|
94
115
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
116
|
+
|
|
117
|
+
(target.getAttribute(`${prefix}-trigger-open`)?.split(',') || options.triggers.open)
|
|
118
|
+
.map(trigger => addEventListener(trigger, open));
|
|
119
|
+
|
|
120
|
+
(target.getAttribute(`${prefix}-trigger-close`)?.split(',') || options.triggers.close)
|
|
121
|
+
.map(trigger => addEventListener(trigger, close));
|
|
98
122
|
}
|
|
99
123
|
|
|
100
124
|
app.mixin({
|
|
@@ -118,20 +142,46 @@ export default function(app: App, options = {
|
|
|
118
142
|
return NodeFilter.FILTER_REJECT;
|
|
119
143
|
}
|
|
120
144
|
|
|
121
|
-
return NodeFilter.FILTER_ACCEPT
|
|
145
|
+
return NodeFilter.FILTER_ACCEPT;
|
|
122
146
|
}
|
|
123
147
|
);
|
|
124
148
|
|
|
125
149
|
// Step through and alert all child nodes
|
|
126
|
-
while
|
|
150
|
+
while(walker.nextNode()) {
|
|
127
151
|
if(walker.currentNode instanceof Element) {
|
|
128
152
|
init(<Element> walker.currentNode);
|
|
129
153
|
}
|
|
130
154
|
}
|
|
155
|
+
|
|
156
|
+
const observer = new MutationObserver((changes) => {
|
|
157
|
+
for(const { removedNodes } of changes) {
|
|
158
|
+
for(const node of removedNodes) {
|
|
159
|
+
for(const el of (node as Element).querySelectorAll(`[${prefix}-id]`)) {
|
|
160
|
+
const tooltip = tooltips.get(
|
|
161
|
+
el.getAttribute(`${prefix}-id`) as string
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
tooltip && tooltip();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
observer.observe(el, { childList: true });
|
|
131
171
|
}
|
|
132
172
|
});
|
|
133
173
|
|
|
134
|
-
app.directive('tooltip',
|
|
135
|
-
target,
|
|
136
|
-
|
|
174
|
+
app.directive('tooltip', {
|
|
175
|
+
created(target, binding) {
|
|
176
|
+
init(target, Object.assign({}, binding.modifiers, binding.value));
|
|
177
|
+
},
|
|
178
|
+
beforeUnmount(target) {
|
|
179
|
+
const id = target.getAttribute(`${prefix}-id`);
|
|
180
|
+
const tooltip = tooltips.get(id);
|
|
181
|
+
|
|
182
|
+
console.log('beforeUnmount');
|
|
183
|
+
|
|
184
|
+
tooltip && tooltip();
|
|
185
|
+
}
|
|
186
|
+
});
|
|
137
187
|
}
|
|
@@ -8,11 +8,11 @@ module.exports = plugin(function({ addComponents, theme }) {
|
|
|
8
8
|
},
|
|
9
9
|
|
|
10
10
|
'.bs-tooltip-top .tooltip-arrow': {
|
|
11
|
-
bottom:
|
|
11
|
+
bottom: '1px',
|
|
12
12
|
},
|
|
13
13
|
|
|
14
14
|
'.bs-tooltip-top .tooltip-arrow::before': {
|
|
15
|
-
bottom:
|
|
15
|
+
bottom: '1px',
|
|
16
16
|
borderWidth: `${theme('tooltip.arrow.height')} calc(${theme('tooltip.arrow.width')} / 2) 0`,
|
|
17
17
|
borderTopColor: theme('tooltip.arrow.color'),
|
|
18
18
|
}
|
|
@@ -24,11 +24,11 @@ module.exports = plugin(function({ addComponents, theme }) {
|
|
|
24
24
|
},
|
|
25
25
|
|
|
26
26
|
'.bs-tooltip-bottom .tooltip-arrow': {
|
|
27
|
-
top:
|
|
27
|
+
top: '1px'
|
|
28
28
|
},
|
|
29
29
|
|
|
30
30
|
'.bs-tooltip-bottom .tooltip-arrow::before': {
|
|
31
|
-
top:
|
|
31
|
+
top: '1px',
|
|
32
32
|
borderWidth: `0 calc(${theme('tooltip.arrow.width')} / 2) ${theme('tooltip.arrow.height')}`,
|
|
33
33
|
borderBottomColor: theme('tooltip.arrow.color'),
|
|
34
34
|
},
|
|
@@ -40,13 +40,13 @@ module.exports = plugin(function({ addComponents, theme }) {
|
|
|
40
40
|
},
|
|
41
41
|
|
|
42
42
|
'.bs-tooltip-left .tooltip-arrow': {
|
|
43
|
-
right:
|
|
43
|
+
right: '1px',
|
|
44
44
|
width: theme('tooltip.arrow.height'),
|
|
45
45
|
height: theme('tooltip.arrow.width')
|
|
46
46
|
},
|
|
47
47
|
|
|
48
48
|
'.bs-tooltip-left .tooltip-arrow::before': {
|
|
49
|
-
right:
|
|
49
|
+
right: '1px',
|
|
50
50
|
borderWidth: `calc(${theme('tooltip.arrow.width')} / 2) 0 calc(${theme('tooltip.arrow.width')} / 2) ${theme('tooltip.arrow.height')}`,
|
|
51
51
|
borderLeftColor: theme('tooltip.arrow.color')
|
|
52
52
|
}
|
|
@@ -58,13 +58,13 @@ module.exports = plugin(function({ addComponents, theme }) {
|
|
|
58
58
|
},
|
|
59
59
|
|
|
60
60
|
'.bs-tooltip-right .tooltip-arrow': {
|
|
61
|
-
left:
|
|
61
|
+
left: '1px',
|
|
62
62
|
width: theme('tooltip.arrow.height'),
|
|
63
63
|
height: theme('tooltip.arrow.width'),
|
|
64
64
|
},
|
|
65
65
|
|
|
66
66
|
'.bs-tooltip-right .tooltip-arrow::before': {
|
|
67
|
-
left:
|
|
67
|
+
left: '1px',
|
|
68
68
|
borderWidth: `calc(${theme('tooltip.arrow.width')} / 2) ${theme('tooltip.arrow.height')} calc(${theme('tooltip.arrow.width')} / 2) 0`,
|
|
69
69
|
borderRightColor: theme('tooltip.arrow.color'),
|
|
70
70
|
}
|
package/dist/Tooltip.vue.d.ts
DELETED