📄 index.ts¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 2 |
| 📦 Imports | 4 |
| 📊 Variables & Constants | 2 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/core/usePageLeave/index.ts
📦 Imports¶
| Name | Source |
|---|---|
ConfigurableWindow |
../_configurable |
shallowRef |
vue |
defaultWindow |
../_configurable |
useEventListener |
../useEventListener |
Variables & Constants¶
| Name | Type | Kind | Value | Exported |
|---|---|---|---|---|
from |
any |
const | event.relatedTarget || event.toElement |
✗ |
listenerOptions |
{ passive: boolean; } |
const | { passive: true } |
✗ |
Functions¶
usePageLeave(options: ConfigurableWindow): any¶
Code
export function usePageLeave(options: ConfigurableWindow = {}) {
const { window = defaultWindow } = options
const isLeft = shallowRef(false)
const handler = (event: MouseEvent) => {
if (!window)
return
event = event || (window.event as any)
// @ts-expect-error missing types
const from = event.relatedTarget || event.toElement
isLeft.value = !from
}
if (window) {
const listenerOptions = { passive: true }
useEventListener(window, 'mouseout', handler, listenerOptions)
useEventListener(window.document, 'mouseleave', handler, listenerOptions)
useEventListener(window.document, 'mouseenter', handler, listenerOptions)
}
return isLeft
}
-
JSDoc:
-
Parameters:
options: ConfigurableWindow- Return Type:
any - Calls:
shallowRef (from vue)useEventListener (from ../useEventListener)- Internal Comments:
handler(event: MouseEvent): void¶
Code
- Parameters:
event: MouseEvent- Return Type:
void - Internal Comments: