@zag-js/form-utils
Advanced tools
Comparing version 0.0.0-dev-20221229205502 to 0.0.0-dev-20230201181615
@@ -60,9 +60,9 @@ "use strict"; | ||
const form = getClosestForm(el); | ||
form == null ? void 0 : form.addEventListener("reset", callback, { passive: true }); | ||
form?.addEventListener("reset", callback, { passive: true }); | ||
return () => { | ||
form == null ? void 0 : form.removeEventListener("reset", callback); | ||
form?.removeEventListener("reset", callback); | ||
}; | ||
} | ||
function trackFieldsetDisabled(el, callback) { | ||
const fieldset = el == null ? void 0 : el.closest("fieldset"); | ||
const fieldset = el?.closest("fieldset"); | ||
if (!fieldset) | ||
@@ -88,3 +88,3 @@ return; | ||
return () => { | ||
cleanups.forEach((cleanup) => cleanup == null ? void 0 : cleanup()); | ||
cleanups.forEach((cleanup) => cleanup?.()); | ||
}; | ||
@@ -91,0 +91,0 @@ } |
@@ -34,4 +34,3 @@ "use strict"; | ||
function getWindow(el) { | ||
var _a; | ||
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window; | ||
return el?.ownerDocument.defaultView ?? window; | ||
} | ||
@@ -58,14 +57,11 @@ | ||
function getDescriptor(el, options) { | ||
var _a; | ||
const { type, property = "value" } = options; | ||
const proto = getWindow(el)[type].prototype; | ||
return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {}; | ||
return Object.getOwnPropertyDescriptor(proto, property) ?? {}; | ||
} | ||
function setElementValue(el, value, option) { | ||
var _a; | ||
const descriptor = getDescriptor(el, option); | ||
(_a = descriptor.set) == null ? void 0 : _a.call(el, value); | ||
descriptor.set?.call(el, value); | ||
} | ||
function dispatchInputValueEvent(el, value) { | ||
var _a; | ||
if (!el) | ||
@@ -77,3 +73,3 @@ return; | ||
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" }); | ||
(_a = desc.set) == null ? void 0 : _a.call(el, value); | ||
desc.set?.call(el, value); | ||
const event = new win.Event("input", { bubbles: true }); | ||
@@ -83,3 +79,2 @@ el.dispatchEvent(event); | ||
function dispatchInputCheckedEvent(el, checked) { | ||
var _a; | ||
if (!el) | ||
@@ -91,3 +86,3 @@ return; | ||
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "checked" }); | ||
(_a = desc.set) == null ? void 0 : _a.call(el, checked); | ||
desc.set?.call(el, checked); | ||
const event = new win.Event("click", { bubbles: true }); | ||
@@ -111,9 +106,9 @@ el.dispatchEvent(event); | ||
const form = getClosestForm(el); | ||
form == null ? void 0 : form.addEventListener("reset", callback, { passive: true }); | ||
form?.addEventListener("reset", callback, { passive: true }); | ||
return () => { | ||
form == null ? void 0 : form.removeEventListener("reset", callback); | ||
form?.removeEventListener("reset", callback); | ||
}; | ||
} | ||
function trackFieldsetDisabled(el, callback) { | ||
const fieldset = el == null ? void 0 : el.closest("fieldset"); | ||
const fieldset = el?.closest("fieldset"); | ||
if (!fieldset) | ||
@@ -139,3 +134,3 @@ return; | ||
return () => { | ||
cleanups.forEach((cleanup) => cleanup == null ? void 0 : cleanup()); | ||
cleanups.forEach((cleanup) => cleanup?.()); | ||
}; | ||
@@ -142,0 +137,0 @@ } |
@@ -31,4 +31,3 @@ "use strict"; | ||
function getWindow(el) { | ||
var _a; | ||
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window; | ||
return el?.ownerDocument.defaultView ?? window; | ||
} | ||
@@ -38,14 +37,11 @@ | ||
function getDescriptor(el, options) { | ||
var _a; | ||
const { type, property = "value" } = options; | ||
const proto = getWindow(el)[type].prototype; | ||
return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {}; | ||
return Object.getOwnPropertyDescriptor(proto, property) ?? {}; | ||
} | ||
function setElementValue(el, value, option) { | ||
var _a; | ||
const descriptor = getDescriptor(el, option); | ||
(_a = descriptor.set) == null ? void 0 : _a.call(el, value); | ||
descriptor.set?.call(el, value); | ||
} | ||
function dispatchInputValueEvent(el, value) { | ||
var _a; | ||
if (!el) | ||
@@ -57,3 +53,3 @@ return; | ||
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" }); | ||
(_a = desc.set) == null ? void 0 : _a.call(el, value); | ||
desc.set?.call(el, value); | ||
const event = new win.Event("input", { bubbles: true }); | ||
@@ -63,3 +59,2 @@ el.dispatchEvent(event); | ||
function dispatchInputCheckedEvent(el, checked) { | ||
var _a; | ||
if (!el) | ||
@@ -71,3 +66,3 @@ return; | ||
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "checked" }); | ||
(_a = desc.set) == null ? void 0 : _a.call(el, checked); | ||
desc.set?.call(el, checked); | ||
const event = new win.Event("click", { bubbles: true }); | ||
@@ -74,0 +69,0 @@ el.dispatchEvent(event); |
{ | ||
"name": "@zag-js/form-utils", | ||
"version": "0.0.0-dev-20221229205502", | ||
"version": "0.0.0-dev-20230201181615", | ||
"description": "", | ||
@@ -20,3 +20,3 @@ "keywords": [ | ||
"clean-package": "2.2.0", | ||
"@zag-js/dom-utils": "0.0.0-dev-20221229205502" | ||
"@zag-js/dom-utils": "0.0.0-dev-20230201181615" | ||
}, | ||
@@ -23,0 +23,0 @@ "publishConfig": { |
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
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
17294
456