@melt-ui/svelte
Advanced tools
Comparing version 0.26.2 to 0.26.3
@@ -24,12 +24,11 @@ import { addEventListener, builder, createElHelpers, effect, executeCallbacks, generateId, makeHullFromElements, noop, omit, pointInPolygon, styleToString, } from '../../internal/helpers'; | ||
}; | ||
let openTimeout = null; | ||
let closeTimeout = null; | ||
let timeout = null; | ||
let clickedTrigger = false; | ||
const openTooltip = () => { | ||
const $options = get(options); | ||
if (openTimeout) { | ||
window.clearTimeout(openTimeout); | ||
openTimeout = null; | ||
if (timeout) { | ||
window.clearTimeout(timeout); | ||
timeout = null; | ||
} | ||
openTimeout = window.setTimeout(() => { | ||
timeout = window.setTimeout(() => { | ||
open.set(true); | ||
@@ -40,7 +39,9 @@ }, $options.openDelay); | ||
const $options = get(options); | ||
if (closeTimeout) { | ||
window.clearTimeout(closeTimeout); | ||
closeTimeout = null; | ||
if (timeout) { | ||
window.clearTimeout(timeout); | ||
timeout = null; | ||
} | ||
closeTimeout = window.setTimeout(() => { | ||
if (isBlur && isMouseInTooltipArea) | ||
return; | ||
timeout = window.setTimeout(() => { | ||
open.set(false); | ||
@@ -65,14 +66,16 @@ if (isBlur) | ||
clickedTrigger = true; | ||
if (openTimeout) { | ||
window.clearTimeout(openTimeout); | ||
openTimeout = null; | ||
if (timeout) { | ||
window.clearTimeout(timeout); | ||
timeout = null; | ||
} | ||
}), addEventListener(node, 'pointerover', (e) => { | ||
}), addEventListener(node, 'pointerenter', (e) => { | ||
if (e.pointerType === 'touch') | ||
return; | ||
openTooltip(); | ||
}), addEventListener(node, 'pointerleave', () => { | ||
if (openTimeout) { | ||
window.clearTimeout(openTimeout); | ||
openTimeout = null; | ||
}), addEventListener(node, 'pointerleave', (e) => { | ||
if (e.pointerType === 'touch') | ||
return; | ||
if (timeout) { | ||
window.clearTimeout(timeout); | ||
timeout = null; | ||
} | ||
@@ -85,10 +88,6 @@ }), addEventListener(node, 'focus', () => { | ||
if (e.key === 'Escape') { | ||
if (openTimeout) { | ||
window.clearTimeout(openTimeout); | ||
openTimeout = null; | ||
if (timeout) { | ||
window.clearTimeout(timeout); | ||
timeout = null; | ||
} | ||
if (closeTimeout) { | ||
window.clearTimeout(closeTimeout); | ||
closeTimeout = null; | ||
} | ||
open.set(false); | ||
@@ -134,3 +133,3 @@ } | ||
}); | ||
unsub = executeCallbacks(addEventListener(node, 'mouseover', openTooltip), portalReturn && portalReturn.destroy ? portalReturn.destroy : noop, unsubOpen); | ||
unsub = executeCallbacks(addEventListener(node, 'pointerenter', openTooltip), addEventListener(node, 'pointerdown', openTooltip), portalReturn && portalReturn.destroy ? portalReturn.destroy : noop, unsubOpen); | ||
return { | ||
@@ -155,2 +154,3 @@ destroy() { | ||
}); | ||
let isMouseInTooltipArea = false; | ||
effect(open, ($open) => { | ||
@@ -160,3 +160,3 @@ if ($open) { | ||
const triggerEl = document.getElementById(ids.trigger); | ||
if (!triggerEl || (document.activeElement === triggerEl && !clickedTrigger)) | ||
if (!triggerEl) | ||
return; | ||
@@ -167,11 +167,12 @@ const contentEl = document.getElementById(ids.content); | ||
const polygon = makeHullFromElements([triggerEl, contentEl]); | ||
const isMouseInTooltipArea = pointInPolygon({ | ||
isMouseInTooltipArea = pointInPolygon({ | ||
x: e.clientX, | ||
y: e.clientY, | ||
}, polygon); | ||
if (isMouseInTooltipArea) { | ||
closeTimeout = null; | ||
return; | ||
if (isMouseInTooltipArea || (document.activeElement === triggerEl && !clickedTrigger)) { | ||
openTooltip(); | ||
} | ||
closeTooltip(); | ||
else { | ||
closeTooltip(); | ||
} | ||
})); | ||
@@ -178,0 +179,0 @@ } |
{ | ||
"name": "@melt-ui/svelte", | ||
"version": "0.26.2", | ||
"version": "0.26.3", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "exports": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10296
419088