@zag-js/dom-query
Advanced tools
Comparing version
@@ -282,5 +282,6 @@ import { JSX, MaybeFn, Nullable } from '@zag-js/types'; | ||
declare function setAttribute(element: Element, attr: string, value: string): () => void; | ||
declare function setProperty<T extends Element, K extends keyof T & string>(element: T, property: K, value: T[K]): () => void; | ||
declare function setStyle(element: HTMLElement | null | undefined, style: Partial<CSSStyleDeclaration>): () => void; | ||
declare function setAttribute(el: Element, attr: string, v: string): () => void; | ||
declare function setProperty<T extends Element, K extends keyof T & string>(el: T, prop: K, v: T[K]): () => void; | ||
declare function setStyle(el: HTMLElement | null | undefined, style: Partial<CSSStyleDeclaration>): () => void; | ||
declare function setStyleProperty(el: HTMLElement | null | undefined, prop: string, value: string): () => void; | ||
@@ -358,2 +359,2 @@ declare const MAX_Z_INDEX = 2147483647; | ||
export { type CheckedEventOptions, type DataUrlOptions, type DataUrlType, type DisableTextSelectionOptions, type InitialFocusOptions, type InputValueEventOptions, type ItemToId, MAX_Z_INDEX, type ObserveAttributeOptions, type ObserveChildrenOptions, type OverflowAncestor, type PercentValueOptions, type PointerMoveDetails, type PointerMoveHandlers, type PressDetails, type ProxyTabFocusOptions, type ScopeContext, type ScrollOptions, type ScrollPosition, type SearchableItem, type TrackFormControlOptions, type TrackPressOptions, type TypeaheadOptions, type TypeaheadState, type ViewportSize, addDomEvent, ariaAttr, clickIfLink, contains, createScope, dataAttr, defaultItemToId, disableTextSelection, dispatchInputCheckedEvent, dispatchInputValueEvent, getActiveElement, getBeforeInputValue, getByText, getByTypeahead, getComputedStyle, getDataUrl, getDocument, getDocumentElement, getEventKey, getEventPoint, getEventStep, getEventTarget, getFirstFocusable, getFirstTabbable, getFocusables, getInitialFocus, getLastTabbable, getNativeEvent, getNearestOverflowAncestor, getNextTabbable, getNodeName, getOverflowAncestors, getParentNode, getPlatform, getRelativePoint, getScrollPosition, getTabIndex, getTabbableEdges, getTabbables, getUserAgent, getWindow, indexOfId, isAnchorElement, isAndroid, isApple, isCaretAtStart, isComposingEvent, isContextMenuEvent, isDocument, isDom, isDownloadingEvent, isEditableElement, isElementVisible, isFirefox, isFocusable, isHTMLElement, isInView, isInputElement, isIos, isKeyboardClick, isLeftClick, isMac, isModifierKey, isNode, isOpeningInNewTab, isOverflowElement, isPrintableKey, isRootElement, isSafari, isSelfTarget, isShadowRoot, isTabbable, isTouchDevice, isTouchEvent, isValidTabEvent, isVirtualClick, isVirtualPointerEvent, isVisualViewport, isWebKit, isWindow, itemById, nextById, nextTick, observeAttributes, observeChildren, prevById, proxyTabFocus, query, queryAll, queueBeforeEvent, raf, requestPointerLock, restoreTextSelection, scrollIntoView, setAttribute, setCaretToEnd, setElementChecked, setElementValue, setProperty, setStyle, setVisuallyHidden, trackFormControl, trackPointerMove, trackPress, trackVisualViewport, visuallyHiddenStyle, waitForElement, waitForElements }; | ||
export { type CheckedEventOptions, type DataUrlOptions, type DataUrlType, type DisableTextSelectionOptions, type InitialFocusOptions, type InputValueEventOptions, type ItemToId, MAX_Z_INDEX, type ObserveAttributeOptions, type ObserveChildrenOptions, type OverflowAncestor, type PercentValueOptions, type PointerMoveDetails, type PointerMoveHandlers, type PressDetails, type ProxyTabFocusOptions, type ScopeContext, type ScrollOptions, type ScrollPosition, type SearchableItem, type TrackFormControlOptions, type TrackPressOptions, type TypeaheadOptions, type TypeaheadState, type ViewportSize, addDomEvent, ariaAttr, clickIfLink, contains, createScope, dataAttr, defaultItemToId, disableTextSelection, dispatchInputCheckedEvent, dispatchInputValueEvent, getActiveElement, getBeforeInputValue, getByText, getByTypeahead, getComputedStyle, getDataUrl, getDocument, getDocumentElement, getEventKey, getEventPoint, getEventStep, getEventTarget, getFirstFocusable, getFirstTabbable, getFocusables, getInitialFocus, getLastTabbable, getNativeEvent, getNearestOverflowAncestor, getNextTabbable, getNodeName, getOverflowAncestors, getParentNode, getPlatform, getRelativePoint, getScrollPosition, getTabIndex, getTabbableEdges, getTabbables, getUserAgent, getWindow, indexOfId, isAnchorElement, isAndroid, isApple, isCaretAtStart, isComposingEvent, isContextMenuEvent, isDocument, isDom, isDownloadingEvent, isEditableElement, isElementVisible, isFirefox, isFocusable, isHTMLElement, isInView, isInputElement, isIos, isKeyboardClick, isLeftClick, isMac, isModifierKey, isNode, isOpeningInNewTab, isOverflowElement, isPrintableKey, isRootElement, isSafari, isSelfTarget, isShadowRoot, isTabbable, isTouchDevice, isTouchEvent, isValidTabEvent, isVirtualClick, isVirtualPointerEvent, isVisualViewport, isWebKit, isWindow, itemById, nextById, nextTick, observeAttributes, observeChildren, prevById, proxyTabFocus, query, queryAll, queueBeforeEvent, raf, requestPointerLock, restoreTextSelection, scrollIntoView, setAttribute, setCaretToEnd, setElementChecked, setElementValue, setProperty, setStyle, setStyleProperty, setVisuallyHidden, trackFormControl, trackPointerMove, trackPress, trackVisualViewport, visuallyHiddenStyle, waitForElement, waitForElements }; |
@@ -369,4 +369,4 @@ 'use strict'; | ||
const { onFieldsetDisabledChange, onFormReset } = options; | ||
const cleanups2 = [trackFormReset(el, onFormReset), trackFieldsetDisabled(el, onFieldsetDisabledChange)]; | ||
return () => cleanups2.forEach((cleanup) => cleanup?.()); | ||
const cleanups = [trackFormReset(el, onFormReset), trackFieldsetDisabled(el, onFieldsetDisabledChange)]; | ||
return () => cleanups.forEach((cleanup) => cleanup?.()); | ||
} | ||
@@ -483,10 +483,10 @@ | ||
function nextTick(fn) { | ||
const set2 = /* @__PURE__ */ new Set(); | ||
const set = /* @__PURE__ */ new Set(); | ||
function raf2(fn2) { | ||
const id = globalThis.requestAnimationFrame(fn2); | ||
set2.add(() => globalThis.cancelAnimationFrame(id)); | ||
set.add(() => globalThis.cancelAnimationFrame(id)); | ||
} | ||
raf2(() => raf2(fn)); | ||
return function cleanup() { | ||
set2.forEach((fn2) => fn2()); | ||
set.forEach((fn2) => fn2()); | ||
}; | ||
@@ -535,11 +535,11 @@ } | ||
const func = defer ? raf : (v) => v(); | ||
const cleanups2 = []; | ||
cleanups2.push( | ||
const cleanups = []; | ||
cleanups.push( | ||
func(() => { | ||
const node = typeof nodeOrFn === "function" ? nodeOrFn() : nodeOrFn; | ||
cleanups2.push(observeAttributesImpl(node, options)); | ||
cleanups.push(observeAttributesImpl(node, options)); | ||
}) | ||
); | ||
return () => { | ||
cleanups2.forEach((fn) => fn?.()); | ||
cleanups.forEach((fn) => fn?.()); | ||
}; | ||
@@ -558,11 +558,11 @@ } | ||
const func = defer ? raf : (v) => v(); | ||
const cleanups2 = []; | ||
cleanups2.push( | ||
const cleanups = []; | ||
cleanups.push( | ||
func(() => { | ||
const node = typeof nodeOrFn === "function" ? nodeOrFn() : nodeOrFn; | ||
cleanups2.push(observeChildrenImpl(node, options)); | ||
cleanups.push(observeChildrenImpl(node, options)); | ||
}) | ||
); | ||
return () => { | ||
cleanups2.forEach((fn) => fn?.()); | ||
cleanups.forEach((fn) => fn?.()); | ||
}; | ||
@@ -729,11 +729,11 @@ } | ||
const func = defer ? raf : (v) => v(); | ||
const cleanups2 = []; | ||
cleanups2.push( | ||
const cleanups = []; | ||
cleanups.push( | ||
func(() => { | ||
const node = typeof target === "function" ? target() : target; | ||
cleanups2.push(disableTextSelectionImpl({ ...restOptions, target: node })); | ||
cleanups.push(disableTextSelectionImpl({ ...restOptions, target: node })); | ||
}) | ||
); | ||
return () => { | ||
cleanups2.forEach((fn) => fn?.()); | ||
cleanups.forEach((fn) => fn?.()); | ||
}; | ||
@@ -756,3 +756,3 @@ } | ||
}; | ||
const cleanups2 = [ | ||
const cleanups = [ | ||
addDomEvent(doc, "pointermove", handleMove, false), | ||
@@ -765,3 +765,3 @@ addDomEvent(doc, "pointerup", onPointerUp, false), | ||
return () => { | ||
cleanups2.forEach((cleanup) => cleanup()); | ||
cleanups.forEach((cleanup) => cleanup()); | ||
}; | ||
@@ -885,12 +885,12 @@ } | ||
const func = defer ? raf : (v) => v(); | ||
const cleanups2 = []; | ||
cleanups2.push( | ||
const cleanups = []; | ||
cleanups.push( | ||
func(() => { | ||
const node = typeof container === "function" ? container() : container; | ||
const trigger = typeof triggerElement === "function" ? triggerElement() : triggerElement; | ||
cleanups2.push(proxyTabFocusImpl(node, { triggerElement: trigger, ...restOptions })); | ||
cleanups.push(proxyTabFocusImpl(node, { triggerElement: trigger, ...restOptions })); | ||
}) | ||
); | ||
return () => { | ||
cleanups2.forEach((fn) => fn?.()); | ||
cleanups.forEach((fn) => fn?.()); | ||
}; | ||
@@ -967,70 +967,50 @@ } | ||
// src/set.ts | ||
var cleanups = /* @__PURE__ */ new WeakMap(); | ||
function set(element, key, setup) { | ||
if (!cleanups.has(element)) { | ||
cleanups.set(element, /* @__PURE__ */ new Map()); | ||
} | ||
const elementCleanups = cleanups.get(element); | ||
const prevCleanup = elementCleanups.get(key); | ||
if (!prevCleanup) { | ||
elementCleanups.set(key, setup()); | ||
return () => { | ||
elementCleanups.get(key)?.(); | ||
elementCleanups.delete(key); | ||
}; | ||
} | ||
const cleanup = setup(); | ||
const nextCleanup = () => { | ||
cleanup(); | ||
prevCleanup(); | ||
elementCleanups.delete(key); | ||
}; | ||
elementCleanups.set(key, nextCleanup); | ||
function setAttribute(el, attr, v) { | ||
const prev = el.getAttribute(attr); | ||
const exists = prev != null; | ||
el.setAttribute(attr, v); | ||
return () => { | ||
const isCurrent = elementCleanups.get(key) === nextCleanup; | ||
if (!isCurrent) return; | ||
cleanup(); | ||
elementCleanups.set(key, prevCleanup); | ||
if (!exists) { | ||
el.removeAttribute(attr); | ||
} else { | ||
el.setAttribute(attr, prev); | ||
} | ||
}; | ||
} | ||
function setAttribute(element, attr, value) { | ||
const setup = () => { | ||
const previousValue = element.getAttribute(attr); | ||
element.setAttribute(attr, value); | ||
return () => { | ||
if (previousValue == null) { | ||
element.removeAttribute(attr); | ||
} else { | ||
element.setAttribute(attr, previousValue); | ||
} | ||
}; | ||
function setProperty(el, prop, v) { | ||
const exists = prop in el; | ||
const prev = el[prop]; | ||
el[prop] = v; | ||
return () => { | ||
if (!exists) { | ||
delete el[prop]; | ||
} else { | ||
el[prop] = prev; | ||
} | ||
}; | ||
return set(element, attr, setup); | ||
} | ||
function setProperty(element, property, value) { | ||
const setup = () => { | ||
const exists = property in element; | ||
const previousValue = element[property]; | ||
element[property] = value; | ||
return () => { | ||
if (!exists) { | ||
delete element[property]; | ||
} else { | ||
element[property] = previousValue; | ||
} | ||
}; | ||
function setStyle(el, style) { | ||
if (!el) return noop; | ||
const prev = Object.keys(style).reduce((acc, key) => { | ||
acc[key] = el.style.getPropertyValue(key); | ||
return acc; | ||
}, {}); | ||
Object.assign(el.style, style); | ||
return () => { | ||
Object.assign(el.style, prev); | ||
if (el.style.length === 0) { | ||
el.removeAttribute("style"); | ||
} | ||
}; | ||
return set(element, property, setup); | ||
} | ||
function setStyle(element, style) { | ||
if (!element) return () => { | ||
function setStyleProperty(el, prop, value) { | ||
if (!el) return noop; | ||
const prev = el.style.getPropertyValue(prop); | ||
el.style.setProperty(prop, value); | ||
return () => { | ||
el.style.setProperty(prop, prev); | ||
if (el.style.length === 0) { | ||
el.removeAttribute("style"); | ||
} | ||
}; | ||
const setup = () => { | ||
const prevStyle = element.style.cssText; | ||
Object.assign(element.style, style); | ||
return () => { | ||
element.style.cssText = prevStyle; | ||
}; | ||
}; | ||
return set(element, "style", setup); | ||
} | ||
@@ -1123,9 +1103,9 @@ | ||
function waitForElements(queries, cb) { | ||
const cleanups2 = []; | ||
const cleanups = []; | ||
queries?.forEach((query2) => { | ||
const clean = waitForElement(query2, cb); | ||
cleanups2.push(clean); | ||
cleanups.push(clean); | ||
}); | ||
return () => { | ||
cleanups2.forEach((fn) => fn()); | ||
cleanups.forEach((fn) => fn()); | ||
}; | ||
@@ -1235,2 +1215,3 @@ } | ||
exports.setStyle = setStyle; | ||
exports.setStyleProperty = setStyleProperty; | ||
exports.setVisuallyHidden = setVisuallyHidden; | ||
@@ -1237,0 +1218,0 @@ exports.trackFormControl = trackFormControl; |
{ | ||
"name": "@zag-js/dom-query", | ||
"version": "1.6.1", | ||
"version": "1.6.2", | ||
"description": "The dom helper library for zag.js machines", | ||
@@ -31,3 +31,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@zag-js/types": "1.6.1" | ||
"@zag-js/types": "1.6.2" | ||
}, | ||
@@ -34,0 +34,0 @@ "module": "dist/index.mjs", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
119554
-1%2602
-1.44%+ Added
- Removed
Updated