@zag-js/dom-utils
Advanced tools
Comparing version 0.0.0-dev-20220521182600 to 0.0.0-dev-20220522174316
@@ -1,3 +0,5 @@ | ||
export declare function getClosestFormElement(el: HTMLElement): HTMLFormElement; | ||
export declare function getClosestForm(el: HTMLElement): HTMLFormElement; | ||
export declare function trackFormReset(el: HTMLElement | null | undefined, callback: () => void): () => void; | ||
export declare function trackFieldsetDisabled(el: HTMLElement | null | undefined, callback: (disabled: boolean) => void): () => void; | ||
export declare function isNativeDisabled(el: HTMLElement): boolean; | ||
//# sourceMappingURL=form.d.ts.map |
@@ -46,3 +46,3 @@ var __create = Object.create; | ||
forceReflow: () => forceReflow, | ||
getClosestFormElement: () => getClosestFormElement, | ||
getClosestForm: () => getClosestForm, | ||
getComputedStyle: () => getComputedStyle2, | ||
@@ -71,2 +71,3 @@ getDocumentElement: () => getDocumentElement, | ||
isKeyboardClick: () => isKeyboardClick, | ||
isNativeDisabled: () => isNativeDisabled, | ||
isScrollParent: () => isScrollParent, | ||
@@ -93,2 +94,3 @@ isTabbable: () => isTabbable, | ||
trackDocumentVisibility: () => trackDocumentVisibility, | ||
trackFieldsetDisabled: () => trackFieldsetDisabled, | ||
trackFormReset: () => trackFormReset, | ||
@@ -732,4 +734,35 @@ trackInputPropertyMutation: () => trackInputPropertyMutation, | ||
// src/mutation-observer.ts | ||
function observeAttributes(node, attributes, fn) { | ||
if (!node) | ||
return noop; | ||
const attrs = Array.isArray(attributes) ? attributes : [attributes]; | ||
const win = node.ownerDocument.defaultView || window; | ||
const obs = new win.MutationObserver((changes) => { | ||
for (const change of changes) { | ||
if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) { | ||
fn(change); | ||
} | ||
} | ||
}); | ||
obs.observe(node, { attributes: true, attributeFilter: attrs }); | ||
return () => obs.disconnect(); | ||
} | ||
function observeChildren(node, fn) { | ||
if (!node) | ||
return noop; | ||
const win = node.ownerDocument.defaultView || window; | ||
const obs = new win.MutationObserver((changes) => { | ||
for (const change of changes) { | ||
if (change.type === "childList") { | ||
fn(change); | ||
} | ||
} | ||
}); | ||
obs.observe(node, { childList: true, subtree: true }); | ||
return () => obs.disconnect(); | ||
} | ||
// src/form.ts | ||
function getClosestFormElement(el) { | ||
function getClosestForm(el) { | ||
if (isFormElement(el)) | ||
@@ -741,3 +774,3 @@ return el.form; | ||
function isFormElement(el) { | ||
return ["textarea", "input", "select", "button"].includes(el.localName); | ||
return el.matches("textarea, input, select, button"); | ||
} | ||
@@ -747,3 +780,3 @@ function trackFormReset(el, callback) { | ||
return; | ||
const form = getClosestFormElement(el); | ||
const form = getClosestForm(el); | ||
form == null ? void 0 : form.addEventListener("reset", callback, { passive: true }); | ||
@@ -754,2 +787,12 @@ return () => { | ||
} | ||
function trackFieldsetDisabled(el, callback) { | ||
const fieldset = el == null ? void 0 : el.closest("fieldset"); | ||
if (!fieldset) | ||
return; | ||
callback(fieldset.disabled); | ||
return observeAttributes(fieldset, ["disabled"], () => callback(fieldset.disabled)); | ||
} | ||
function isNativeDisabled(el) { | ||
return el.matches(":disabled"); | ||
} | ||
@@ -841,33 +884,2 @@ // src/keyboard-event.ts | ||
// src/mutation-observer.ts | ||
function observeAttributes(node, attributes, fn) { | ||
if (!node) | ||
return noop; | ||
const attrs = Array.isArray(attributes) ? attributes : [attributes]; | ||
const win = node.ownerDocument.defaultView || window; | ||
const obs = new win.MutationObserver((changes) => { | ||
for (const change of changes) { | ||
if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) { | ||
fn(change); | ||
} | ||
} | ||
}); | ||
obs.observe(node, { attributes: true, attributeFilter: attrs }); | ||
return () => obs.disconnect(); | ||
} | ||
function observeChildren(node, fn) { | ||
if (!node) | ||
return noop; | ||
const win = node.ownerDocument.defaultView || window; | ||
const obs = new win.MutationObserver((changes) => { | ||
for (const change of changes) { | ||
if (change.type === "childList") { | ||
fn(change); | ||
} | ||
} | ||
}); | ||
obs.observe(node, { childList: true, subtree: true }); | ||
return () => obs.disconnect(); | ||
} | ||
// src/nodelist.ts | ||
@@ -874,0 +886,0 @@ function queryAll(root, selector) { |
{ | ||
"name": "@zag-js/dom-utils", | ||
"version": "0.0.0-dev-20220521182600", | ||
"version": "0.0.0-dev-20220522174316", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
255123
3413
2585