📄 useElementOverflow¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 4 |
| 📦 Imports | 9 |
| 🟢 Vue Composition API | 1 |
| 📐 Interfaces | 1 |
| 📑 Type Aliases | 1 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/core/useElementOverflow/index.ts
📦 Imports¶
| Name | Source |
|---|---|
ConfigurableWindow |
../_configurable |
MaybeComputedElementRef |
../unrefElement |
computed |
vue |
shallowReadonly |
vue |
shallowRef |
vue |
defaultWindow |
../_configurable |
unrefElement |
../unrefElement |
useMutationObserver |
../useMutationObserver |
useResizeObserver |
../useResizeObserver |
Vue Composition API¶
| Name | Type | Reactive Variables | Composables |
|---|---|---|---|
computed |
computed | none | none |
Functions¶
useElementOverflow(target: MaybeComputedElementRef, option: UseElementOverflowOptions): { isXOverflowed: any; isYOverflowed: any; stop: () => void;…¶
react a dom's overflow state
Parameters:
targetany: No descriptionoptionany: No description
See: https://vueuse.org/useElementOverflow
Raw JSDoc
Calls:
shallowRef (from vue)computed (from vue)unrefElement (from ../unrefElement)Array.from(el.children).filteruseResizeObserver (from ../useResizeObserver)updateonResizeUpdateduseMutationObserver (from ../useMutationObserver)onMutationUpdatedshallowReadonly (from vue)
Internal Comments:
Code
export function useElementOverflow(target: MaybeComputedElementRef, option: UseElementOverflowOptions = {}) {
const { observeMutation = false, onUpdated, window = defaultWindow } = option
const isXOverflowed = shallowRef(false)
const isYOverflowed = shallowRef(false)
function update(htmlEl: HTMLElement) {
isXOverflowed.value = htmlEl.scrollWidth > htmlEl.offsetWidth
isYOverflowed.value = htmlEl.scrollHeight > htmlEl.offsetHeight
}
const onResizeUpdated = onUpdated as ResizeObserverCallback | undefined
const targetEl = computed(() => {
const el = unrefElement(target)
if (!el || el instanceof SVGElement)
return undefined
return el
})
const targets = () => {
const el = targetEl.value
if (!el || el instanceof SVGElement)
return []
return [el, ...Array.from(el.children).filter(i => i instanceof HTMLElement)]
}
useResizeObserver(targets, (entries, observer) => {
const el = targetEl.value
if (el) {
update(el)
}
onResizeUpdated?.(entries, observer)
}, { window })
if (observeMutation) {
const onMutationUpdated = onUpdated as MutationCallback | undefined
useMutationObserver(
targets,
(entries, observer) => {
const el = targetEl.value
if (el) {
update(el)
}
onMutationUpdated?.(entries, observer)
},
{
window,
...(typeof observeMutation === 'object'
? observeMutation
: { childList: true, subtree: true, characterData: true }),
},
)
}
return {
isXOverflowed: shallowReadonly(isXOverflowed),
isYOverflowed: shallowReadonly(isYOverflowed),
// stop effectScope
stop,
// update overflow state immediately
update: () => {
const el = targetEl.value
if (el && window) {
update(el)
}
},
}
}
Internal helpers¶
Declared inside another function in this file.
useElementOverflow.update(htmlEl: HTMLElement): void¶
Parameters:
htmlElHTMLElement
Returns: void
Code
targets(): any[]¶
Returns: any[]
Calls:
Array.from(el.children).filter
Code
useElementOverflow.update(): void¶
Returns: void
Calls:
update
Interfaces¶
UseElementOverflowOptions¶
Interface Code
export interface UseElementOverflowOptions extends ConfigurableWindow {
/**
* Use MutationObserver to observe the target and its children.
*
* @default false
*/
observeMutation?: boolean | MutationObserverInit
/**
* Callback when observer triggered.
*/
onUpdated?: ResizeObserverCallback | MutationCallback
}
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
observeMutation |
boolean \| MutationObserverInit |
✓ | not shown |
onUpdated |
ResizeObserverCallback \| MutationCallback |
✓ | not shown |
Type Aliases¶
UseElementOverflowReturn¶
Generated by Syntax Scribe