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/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.3.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
- let anchorElementResizeObserver: ResizeObserver | null = null
3
- let anchorElementRect: DOMRect | null = null
4
-
5
- const handleHideOnResize = (anchorElement: HTMLElement, hideOverlay: () => void) => {
6
- anchorElementResizeObserver = new ResizeObserver((entries) => {
7
- const targetElement = entries[0].target
8
-
9
- if (anchorElementRect === null) {
10
- // On initial trigger set initial values
11
- anchorElementRect = anchorElement.getBoundingClientRect()
12
- } else {
13
- const targetElementRect = targetElement.getBoundingClientRect()
14
-
15
- // Check if anchor element has moved or resized
16
- if (targetElementRect.left !== anchorElementRect.left
17
- || targetElementRect.top !== anchorElementRect.top
18
- || targetElementRect.width !== anchorElementRect.width
19
- || targetElementRect.height !== anchorElementRect.height) {
20
- hideOverlay()
21
- }
22
- }
23
- })
24
-
25
- anchorElementResizeObserver.observe(anchorElement)
26
- }
27
-
28
- const resetResizeReferences = () => {
29
- if (anchorElementResizeObserver !== null) anchorElementResizeObserver.disconnect()
30
-
31
- anchorElementResizeObserver = null
32
- anchorElementRect = null
33
- }
34
-
35
- return { handleHideOnResize, resetResizeReferences }
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
- export default function useHideOnScroll() {
3
- let scrollContainers: Array<HTMLElement> = []
4
-
5
- const handleHideOnScroll = (anchorElement: HTMLElement, hideOverlay: () => void) => {
6
- getScrollContainers(anchorElement)
7
-
8
- if (scrollContainers.length > 0) {
9
- for (const scrollContainer of scrollContainers) {
10
- scrollContainer.addEventListener('scroll', hideOverlay)
11
- }
12
- }
13
-
14
- window.addEventListener('scroll', () => {
15
- hideOverlay()
16
- removeHideOnScrollListeners(hideOverlay)
17
- })
18
- }
19
-
20
- const getScrollContainers = (anchorElement: HTMLElement) => {
21
- let currentElement: HTMLElement | null = anchorElement
22
-
23
- while (currentElement !== null && currentElement.tagName !== 'HTML') {
24
- if (currentElement.scrollHeight !== currentElement.clientHeight) {
25
- const computedStyle = window.getComputedStyle(currentElement)
26
-
27
- if (computedStyle.overflow === 'auto' || computedStyle.overflow === 'scroll') {
28
- scrollContainers.push(currentElement)
29
- }
30
- }
31
-
32
- currentElement = currentElement.parentElement
33
- }
34
- }
35
-
36
- const removeHideOnScrollListeners = (hideOverlay: () => void) => {
37
- if (scrollContainers.length > 0) {
38
- for (const scrollContainer of scrollContainers) {
39
- scrollContainer.removeEventListener('scroll', hideOverlay)
40
- }
41
-
42
- scrollContainers = []
43
- }
44
-
45
- window.removeEventListener('scroll', hideOverlay)
46
- }
47
-
48
- return { handleHideOnScroll }
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
+ }