zero-tooltip 1.3.1 → 1.4.0
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/README.md +150 -148
- package/dist/composables/useHideOnResize.d.ts +2 -2
- package/dist/composables/useHideOnScroll.d.ts +1 -0
- package/dist/types/scrollContainer.d.ts +5 -0
- package/dist/types/tooltipLocalConfig.d.ts +1 -0
- package/dist/zero-tooltip.js +198 -181
- package/dist/zero-tooltip.umd.cjs +1 -1
- package/package.json +65 -65
- package/src/composables/useHideOnResize.ts +38 -36
- package/src/composables/useHideOnScroll.ts +60 -49
- package/src/index.ts +27 -27
- package/src/tooltip.ts +626 -576
- package/src/types/scrollContainer.ts +6 -0
- package/src/types/tooltipConfig.ts +23 -23
- package/src/types/tooltipLocalConfig.ts +8 -7
- package/src/types/tooltipPosition.ts +4 -4
- package/src/types/tooltipPositions.ts +10 -10
package/package.json
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "zero-tooltip",
|
|
3
|
-
"description": "Tooltip component",
|
|
4
|
-
"main": "./dist/zero-tooltip.umd.cjs",
|
|
5
|
-
"module": "./dist/zero-tooltip.js",
|
|
6
|
-
"types": "./dist/index.d.ts",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": {
|
|
9
|
-
"import": "./dist/zero-tooltip.js",
|
|
10
|
-
"require": "./dist/zero-tooltip.umd.cjs",
|
|
11
|
-
"types": "./dist/index.d.ts"
|
|
12
|
-
},
|
|
13
|
-
"./dist/style.css": "./dist/style.css",
|
|
14
|
-
"./style.css": "./dist/style.css"
|
|
15
|
-
},
|
|
16
|
-
"./package.json": "./package.json",
|
|
17
|
-
"files": [
|
|
18
|
-
"dist",
|
|
19
|
-
"src"
|
|
20
|
-
],
|
|
21
|
-
"version": "1.
|
|
22
|
-
"type": "module",
|
|
23
|
-
"scripts": {
|
|
24
|
-
"dev": "vite",
|
|
25
|
-
"build": "npx tailwindcss -o ./src/style.css && vite build && vue-tsc -d --emitDeclarationOnly",
|
|
26
|
-
"preview": "vite preview"
|
|
27
|
-
},
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"@rollup/plugin-typescript": "^11.1.4",
|
|
30
|
-
"@types/node": "20.6.2",
|
|
31
|
-
"@vitejs/plugin-vue": "4.2.3",
|
|
32
|
-
"autoprefixer": "10.4.15",
|
|
33
|
-
"postcss": "8.4.29",
|
|
34
|
-
"tailwindcss": "3.3.3",
|
|
35
|
-
"typescript": "5.0.2",
|
|
36
|
-
"vite": "4.4.5",
|
|
37
|
-
"vite-plugin-dts": "3.5.3",
|
|
38
|
-
"vue": "^3.0.0",
|
|
39
|
-
"vue-tsc": "1.8.5",
|
|
40
|
-
"primevue": "3.53.0"
|
|
41
|
-
},
|
|
42
|
-
"repository": {
|
|
43
|
-
"type": "git",
|
|
44
|
-
"url": "git+https://github.com/TheAliter/zero-tooltip.git"
|
|
45
|
-
},
|
|
46
|
-
"keywords": [
|
|
47
|
-
"tooltip",
|
|
48
|
-
"vue3",
|
|
49
|
-
"typescript",
|
|
50
|
-
"zero-tooltip"
|
|
51
|
-
],
|
|
52
|
-
"author": "Andris Paškovskis",
|
|
53
|
-
"license": "MIT",
|
|
54
|
-
"bugs": {
|
|
55
|
-
"url": "https://github.com/TheAliter/zero-tooltip/issues"
|
|
56
|
-
},
|
|
57
|
-
"homepage": "https://github.com/TheAliter/zero-tooltip#readme",
|
|
58
|
-
"dependencies": {
|
|
59
|
-
"@types/uuid": "^9.0.7",
|
|
60
|
-
"uuid": "^9.0.1"
|
|
61
|
-
},
|
|
62
|
-
"peerDependencies": {
|
|
63
|
-
"vue": "^3.0.0"
|
|
64
|
-
}
|
|
65
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "zero-tooltip",
|
|
3
|
+
"description": "Tooltip component",
|
|
4
|
+
"main": "./dist/zero-tooltip.umd.cjs",
|
|
5
|
+
"module": "./dist/zero-tooltip.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/zero-tooltip.js",
|
|
10
|
+
"require": "./dist/zero-tooltip.umd.cjs",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./dist/style.css": "./dist/style.css",
|
|
14
|
+
"./style.css": "./dist/style.css"
|
|
15
|
+
},
|
|
16
|
+
"./package.json": "./package.json",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"src"
|
|
20
|
+
],
|
|
21
|
+
"version": "1.4.0",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"scripts": {
|
|
24
|
+
"dev": "vite",
|
|
25
|
+
"build": "npx tailwindcss -o ./src/style.css && vite build && vue-tsc -d --emitDeclarationOnly",
|
|
26
|
+
"preview": "vite preview"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@rollup/plugin-typescript": "^11.1.4",
|
|
30
|
+
"@types/node": "20.6.2",
|
|
31
|
+
"@vitejs/plugin-vue": "4.2.3",
|
|
32
|
+
"autoprefixer": "10.4.15",
|
|
33
|
+
"postcss": "8.4.29",
|
|
34
|
+
"tailwindcss": "3.3.3",
|
|
35
|
+
"typescript": "5.0.2",
|
|
36
|
+
"vite": "4.4.5",
|
|
37
|
+
"vite-plugin-dts": "3.5.3",
|
|
38
|
+
"vue": "^3.0.0",
|
|
39
|
+
"vue-tsc": "1.8.5",
|
|
40
|
+
"primevue": "3.53.0"
|
|
41
|
+
},
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/TheAliter/zero-tooltip.git"
|
|
45
|
+
},
|
|
46
|
+
"keywords": [
|
|
47
|
+
"tooltip",
|
|
48
|
+
"vue3",
|
|
49
|
+
"typescript",
|
|
50
|
+
"zero-tooltip"
|
|
51
|
+
],
|
|
52
|
+
"author": "Andris Paškovskis",
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/TheAliter/zero-tooltip/issues"
|
|
56
|
+
},
|
|
57
|
+
"homepage": "https://github.com/TheAliter/zero-tooltip#readme",
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@types/uuid": "^9.0.7",
|
|
60
|
+
"uuid": "^9.0.1"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"vue": "^3.0.0"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -1,36 +1,38 @@
|
|
|
1
|
-
export default function useHideOnResize() {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const handleHideOnResize = (anchorElement: HTMLElement, hideOverlay: () => void) => {
|
|
6
|
-
anchorElementResizeObserver = new ResizeObserver((entries) => {
|
|
7
|
-
const targetElement = entries[0].target
|
|
8
|
-
|
|
9
|
-
if (
|
|
10
|
-
// On initial trigger set initial values
|
|
11
|
-
|
|
12
|
-
} else {
|
|
13
|
-
const targetElementRect = targetElement.getBoundingClientRect()
|
|
14
|
-
|
|
15
|
-
// Check if anchor element has moved or resized
|
|
16
|
-
if (targetElementRect.left !==
|
|
17
|
-
|| targetElementRect.top !==
|
|
18
|
-
|| targetElementRect.width !==
|
|
19
|
-
|| targetElementRect.height !==
|
|
20
|
-
hideOverlay()
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
anchorElementResizeObserver
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
export default function useHideOnResize() {
|
|
2
|
+
const anchorElementResizeObservers: Record<string, ResizeObserver> = {}
|
|
3
|
+
const anchorElementRects: Record<string, DOMRect> = {}
|
|
4
|
+
|
|
5
|
+
const handleHideOnResize = (tooltipUuid: string, anchorElement: HTMLElement, hideOverlay: () => void) => {
|
|
6
|
+
let anchorElementResizeObserver = new ResizeObserver((entries) => {
|
|
7
|
+
const targetElement = entries[0].target
|
|
8
|
+
|
|
9
|
+
if (!anchorElementRects[tooltipUuid]) {
|
|
10
|
+
// On initial trigger set initial values
|
|
11
|
+
anchorElementRects[tooltipUuid] = anchorElement.getBoundingClientRect()
|
|
12
|
+
} else {
|
|
13
|
+
const targetElementRect = targetElement.getBoundingClientRect()
|
|
14
|
+
|
|
15
|
+
// Check if anchor element has moved or resized
|
|
16
|
+
if (targetElementRect.left !== anchorElementRects[tooltipUuid].left
|
|
17
|
+
|| targetElementRect.top !== anchorElementRects[tooltipUuid].top
|
|
18
|
+
|| targetElementRect.width !== anchorElementRects[tooltipUuid].width
|
|
19
|
+
|| targetElementRect.height !== anchorElementRects[tooltipUuid].height) {
|
|
20
|
+
hideOverlay()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
anchorElementResizeObservers[tooltipUuid] = anchorElementResizeObserver
|
|
26
|
+
|
|
27
|
+
anchorElementResizeObserver.observe(anchorElement)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const resetResizeReferences = (tooltipUuid: string) => {
|
|
31
|
+
if (anchorElementResizeObservers[tooltipUuid]) anchorElementResizeObservers[tooltipUuid].disconnect()
|
|
32
|
+
|
|
33
|
+
delete anchorElementResizeObservers[tooltipUuid]
|
|
34
|
+
delete anchorElementRects[tooltipUuid]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return { handleHideOnResize, resetResizeReferences }
|
|
38
|
+
}
|
|
@@ -1,49 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
1
|
+
|
|
2
|
+
import type { ScrollContainers, ScrollContainer } from '@/types/scrollContainer'
|
|
3
|
+
|
|
4
|
+
export default function useHideOnScroll() {
|
|
5
|
+
let scrollContainers: ScrollContainers = []
|
|
6
|
+
|
|
7
|
+
const handleHideOnScroll = (anchorElement: HTMLElement, hideOverlay: () => void) => {
|
|
8
|
+
getScrollContainers(anchorElement)
|
|
9
|
+
|
|
10
|
+
for (const scrollContainer of scrollContainers) {
|
|
11
|
+
scrollContainer.element.addEventListener(
|
|
12
|
+
'scroll',
|
|
13
|
+
() => {
|
|
14
|
+
hideOverlay()
|
|
15
|
+
removeHideOnScrollListeners()
|
|
16
|
+
},
|
|
17
|
+
{ signal: scrollContainer.eventController.signal }
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const getScrollContainers = (anchorElement: HTMLElement) => {
|
|
23
|
+
let currentElement: HTMLElement | null = anchorElement
|
|
24
|
+
|
|
25
|
+
while (currentElement !== null && currentElement.tagName !== 'HTML') {
|
|
26
|
+
if (currentElement.scrollHeight !== currentElement.clientHeight) {
|
|
27
|
+
const computedStyle = window.getComputedStyle(currentElement)
|
|
28
|
+
|
|
29
|
+
if (computedStyle.overflow === 'auto' || computedStyle.overflow === 'scroll') {
|
|
30
|
+
const scrollContainer: ScrollContainer = {
|
|
31
|
+
element: currentElement,
|
|
32
|
+
eventController: new AbortController()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
scrollContainers.push(scrollContainer)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
currentElement = currentElement.parentElement
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Add window as a scroll container
|
|
43
|
+
const scrollContainer: ScrollContainer = {
|
|
44
|
+
element: window,
|
|
45
|
+
eventController: new AbortController()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
scrollContainers.push(scrollContainer)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const removeHideOnScrollListeners = () => {
|
|
52
|
+
for (const scrollContainer of scrollContainers) {
|
|
53
|
+
scrollContainer.eventController.abort()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
scrollContainers = []
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return { handleHideOnScroll, removeHideOnScrollListeners }
|
|
60
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import './style.css'
|
|
2
|
-
import { App, FunctionDirective } from 'vue'
|
|
3
|
-
|
|
4
|
-
import ZeroTooltip from "./tooltip"
|
|
5
|
-
import TooltipConfig from "./types/tooltipConfig"
|
|
6
|
-
import TooltipLocalConfig from "./types/tooltipLocalConfig"
|
|
7
|
-
import TooltipPosition from "./types/tooltipPosition"
|
|
8
|
-
import TooltipPositions from "./types/tooltipPositions"
|
|
9
|
-
|
|
10
|
-
export default {
|
|
11
|
-
install: (app: App, options: TooltipConfig = {}) => {
|
|
12
|
-
app.directive('tooltip', ZeroTooltip(options))
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type {
|
|
17
|
-
TooltipConfig as ZeroTooltipConfig,
|
|
18
|
-
TooltipPosition as ZeroTooltipPosition,
|
|
19
|
-
TooltipPositions as ZeroTooltipPositions,
|
|
20
|
-
TooltipLocalConfig as ZeroTooltipLocalConfig
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
declare module 'vue' {
|
|
24
|
-
interface ComponentCustomProperties {
|
|
25
|
-
vTooltip: FunctionDirective<HTMLElement, TooltipLocalConfig | string>
|
|
26
|
-
}
|
|
27
|
-
}
|
|
1
|
+
import './style.css'
|
|
2
|
+
import { App, FunctionDirective } from 'vue'
|
|
3
|
+
|
|
4
|
+
import ZeroTooltip from "./tooltip"
|
|
5
|
+
import TooltipConfig from "./types/tooltipConfig"
|
|
6
|
+
import TooltipLocalConfig from "./types/tooltipLocalConfig"
|
|
7
|
+
import TooltipPosition from "./types/tooltipPosition"
|
|
8
|
+
import TooltipPositions from "./types/tooltipPositions"
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
install: (app: App, options: TooltipConfig = {}) => {
|
|
12
|
+
app.directive('tooltip', ZeroTooltip(options))
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type {
|
|
17
|
+
TooltipConfig as ZeroTooltipConfig,
|
|
18
|
+
TooltipPosition as ZeroTooltipPosition,
|
|
19
|
+
TooltipPositions as ZeroTooltipPositions,
|
|
20
|
+
TooltipLocalConfig as ZeroTooltipLocalConfig
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare module 'vue' {
|
|
24
|
+
interface ComponentCustomProperties {
|
|
25
|
+
vTooltip: FunctionDirective<HTMLElement, TooltipLocalConfig | string>
|
|
26
|
+
}
|
|
27
|
+
}
|