zero-tooltip 1.4.3 → 2.0.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.
@@ -1,38 +1,38 @@
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
+ 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,60 +1,60 @@
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
- }
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
+ }
@@ -1,16 +1,16 @@
1
- export default function useRepositionOnResize() {
2
- const anchorElementsRepositionControllers: Record<string, AbortController> = {}
3
-
4
- const handleRepositionOnResize = (tooltipUuid: string, onWindowResize: () => void) => {
5
- anchorElementsRepositionControllers[tooltipUuid] = new AbortController()
6
- window.addEventListener('resize', onWindowResize)
7
- }
8
-
9
- const removeRepositionOnResizeHandler = (tooltipUuid: string) => {
10
- if (anchorElementsRepositionControllers[tooltipUuid]) {
11
- anchorElementsRepositionControllers[tooltipUuid].abort()
12
- }
13
- }
14
-
15
- return { handleRepositionOnResize, removeRepositionOnResizeHandler }
16
- }
1
+ export default function useRepositionOnResize() {
2
+ const anchorElementsRepositionControllers: Record<string, AbortController> = {}
3
+
4
+ const handleRepositionOnResize = (tooltipUuid: string, onWindowResize: () => void) => {
5
+ anchorElementsRepositionControllers[tooltipUuid] = new AbortController()
6
+ window.addEventListener('resize', onWindowResize)
7
+ }
8
+
9
+ const removeRepositionOnResizeHandler = (tooltipUuid: string) => {
10
+ if (anchorElementsRepositionControllers[tooltipUuid]) {
11
+ anchorElementsRepositionControllers[tooltipUuid].abort()
12
+ }
13
+ }
14
+
15
+ return { handleRepositionOnResize, removeRepositionOnResizeHandler }
16
+ }
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
+ }