@zag-js/dismissable
Advanced tools
Comparing version 0.0.0-dev-20221229205502 to 0.0.0-dev-20230201181615
@@ -30,3 +30,3 @@ "use strict"; | ||
const res = typeof v === "function" ? v(...a) : v; | ||
return res != null ? res : void 0; | ||
return res ?? void 0; | ||
}; | ||
@@ -51,6 +51,5 @@ | ||
function isWindow(value) { | ||
return (value == null ? void 0 : value.toString()) === "[object Window]"; | ||
return value?.toString() === "[object Window]"; | ||
} | ||
function getDocument(el) { | ||
var _a; | ||
if (isWindow(el)) | ||
@@ -60,7 +59,6 @@ return el.document; | ||
return el; | ||
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document; | ||
return el?.ownerDocument ?? document; | ||
} | ||
function getEventTarget(event) { | ||
var _a, _b; | ||
return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target; | ||
return event.composedPath?.()[0] ?? event.target; | ||
} | ||
@@ -73,3 +71,3 @@ function contains(parent, child) { | ||
function isHTMLElement(v) { | ||
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string"; | ||
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string"; | ||
} | ||
@@ -81,5 +79,5 @@ | ||
const node = isRef(target) ? target.current : runIfFn(target); | ||
node == null ? void 0 : node.addEventListener(eventName, handler, options); | ||
node?.addEventListener(eventName, handler, options); | ||
return () => { | ||
node == null ? void 0 : node.removeEventListener(eventName, handler, options); | ||
node?.removeEventListener(eventName, handler, options); | ||
}; | ||
@@ -95,3 +93,3 @@ } | ||
if (event.key === "Escape") | ||
fn == null ? void 0 : fn(event); | ||
fn?.(event); | ||
}; | ||
@@ -118,5 +116,4 @@ return addDomEvent(document, "keydown", handleKeyDown); | ||
isBelowPointerBlockingLayer(node) { | ||
var _a; | ||
const index = this.indexOf(node); | ||
const highestBlockingIndex = this.topMostPointerBlockingLayer() ? this.indexOf((_a = this.topMostPointerBlockingLayer()) == null ? void 0 : _a.node) : -1; | ||
const highestBlockingIndex = this.topMostPointerBlockingLayer() ? this.indexOf(this.topMostPointerBlockingLayer()?.node) : -1; | ||
return index < highestBlockingIndex; | ||
@@ -126,3 +123,3 @@ }, | ||
const layer = this.layers[this.count() - 1]; | ||
return (layer == null ? void 0 : layer.node) === node; | ||
return layer?.node === node; | ||
}, | ||
@@ -163,4 +160,3 @@ getNestedLayers(node) { | ||
dismiss(node) { | ||
var _a; | ||
(_a = this.layers[this.indexOf(node)]) == null ? void 0 : _a.dismiss(); | ||
this.layers[this.indexOf(node)]?.dismiss(); | ||
}, | ||
@@ -211,8 +207,7 @@ clear() { | ||
function onPointerDownOutside(event) { | ||
var _a, _b; | ||
const target = getEventTarget(event.detail.originalEvent); | ||
if (layerStack.isBelowPointerBlockingLayer(node) || layerStack.isInBranch(target)) | ||
return; | ||
(_a = options.onPointerDownOutside) == null ? void 0 : _a.call(options, event); | ||
(_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event); | ||
options.onPointerDownOutside?.(event); | ||
options.onInteractOutside?.(event); | ||
if (event.defaultPrevented) | ||
@@ -223,11 +218,10 @@ return; | ||
} | ||
onDismiss == null ? void 0 : onDismiss(); | ||
onDismiss?.(); | ||
} | ||
function onFocusOutside(event) { | ||
var _a, _b; | ||
const target = getEventTarget(event.detail.originalEvent); | ||
if (layerStack.isInBranch(target)) | ||
return; | ||
(_a = options.onFocusOutside) == null ? void 0 : _a.call(options, event); | ||
(_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event); | ||
options.onFocusOutside?.(event); | ||
options.onInteractOutside?.(event); | ||
if (event.defaultPrevented) | ||
@@ -238,9 +232,8 @@ return; | ||
} | ||
onDismiss == null ? void 0 : onDismiss(); | ||
onDismiss?.(); | ||
} | ||
function onEscapeKeyDown(event) { | ||
var _a; | ||
if (!layerStack.isTopMost(node)) | ||
return; | ||
(_a = options.onEscapeKeyDown) == null ? void 0 : _a.call(options, event); | ||
options.onEscapeKeyDown?.(event); | ||
if (!event.defaultPrevented && onDismiss) { | ||
@@ -267,3 +260,3 @@ event.preventDefault(); | ||
clearPointerEvent(node); | ||
cleanups.forEach((fn) => fn == null ? void 0 : fn()); | ||
cleanups.forEach((fn) => fn?.()); | ||
}; | ||
@@ -270,0 +263,0 @@ } |
@@ -30,3 +30,3 @@ "use strict"; | ||
const res = typeof v === "function" ? v(...a) : v; | ||
return res != null ? res : void 0; | ||
return res ?? void 0; | ||
}; | ||
@@ -41,5 +41,5 @@ | ||
const node = isRef(target) ? target.current : runIfFn(target); | ||
node == null ? void 0 : node.addEventListener(eventName, handler, options); | ||
node?.addEventListener(eventName, handler, options); | ||
return () => { | ||
node == null ? void 0 : node.removeEventListener(eventName, handler, options); | ||
node?.removeEventListener(eventName, handler, options); | ||
}; | ||
@@ -52,3 +52,3 @@ } | ||
if (event.key === "Escape") | ||
fn == null ? void 0 : fn(event); | ||
fn?.(event); | ||
}; | ||
@@ -55,0 +55,0 @@ return addDomEvent(document, "keydown", handleKeyDown); |
@@ -30,3 +30,3 @@ "use strict"; | ||
const res = typeof v === "function" ? v(...a) : v; | ||
return res != null ? res : void 0; | ||
return res ?? void 0; | ||
}; | ||
@@ -51,6 +51,5 @@ | ||
function isWindow(value) { | ||
return (value == null ? void 0 : value.toString()) === "[object Window]"; | ||
return value?.toString() === "[object Window]"; | ||
} | ||
function getDocument(el) { | ||
var _a; | ||
if (isWindow(el)) | ||
@@ -60,7 +59,6 @@ return el.document; | ||
return el; | ||
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document; | ||
return el?.ownerDocument ?? document; | ||
} | ||
function getEventTarget(event) { | ||
var _a, _b; | ||
return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target; | ||
return event.composedPath?.()[0] ?? event.target; | ||
} | ||
@@ -73,3 +71,3 @@ function contains(parent, child) { | ||
function isHTMLElement(v) { | ||
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string"; | ||
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string"; | ||
} | ||
@@ -81,5 +79,5 @@ | ||
const node = isRef(target) ? target.current : runIfFn(target); | ||
node == null ? void 0 : node.addEventListener(eventName, handler, options); | ||
node?.addEventListener(eventName, handler, options); | ||
return () => { | ||
node == null ? void 0 : node.removeEventListener(eventName, handler, options); | ||
node?.removeEventListener(eventName, handler, options); | ||
}; | ||
@@ -95,3 +93,3 @@ } | ||
if (event.key === "Escape") | ||
fn == null ? void 0 : fn(event); | ||
fn?.(event); | ||
}; | ||
@@ -118,5 +116,4 @@ return addDomEvent(document, "keydown", handleKeyDown); | ||
isBelowPointerBlockingLayer(node) { | ||
var _a; | ||
const index = this.indexOf(node); | ||
const highestBlockingIndex = this.topMostPointerBlockingLayer() ? this.indexOf((_a = this.topMostPointerBlockingLayer()) == null ? void 0 : _a.node) : -1; | ||
const highestBlockingIndex = this.topMostPointerBlockingLayer() ? this.indexOf(this.topMostPointerBlockingLayer()?.node) : -1; | ||
return index < highestBlockingIndex; | ||
@@ -126,3 +123,3 @@ }, | ||
const layer = this.layers[this.count() - 1]; | ||
return (layer == null ? void 0 : layer.node) === node; | ||
return layer?.node === node; | ||
}, | ||
@@ -163,4 +160,3 @@ getNestedLayers(node) { | ||
dismiss(node) { | ||
var _a; | ||
(_a = this.layers[this.indexOf(node)]) == null ? void 0 : _a.dismiss(); | ||
this.layers[this.indexOf(node)]?.dismiss(); | ||
}, | ||
@@ -211,8 +207,7 @@ clear() { | ||
function onPointerDownOutside(event) { | ||
var _a, _b; | ||
const target = getEventTarget(event.detail.originalEvent); | ||
if (layerStack.isBelowPointerBlockingLayer(node) || layerStack.isInBranch(target)) | ||
return; | ||
(_a = options.onPointerDownOutside) == null ? void 0 : _a.call(options, event); | ||
(_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event); | ||
options.onPointerDownOutside?.(event); | ||
options.onInteractOutside?.(event); | ||
if (event.defaultPrevented) | ||
@@ -223,11 +218,10 @@ return; | ||
} | ||
onDismiss == null ? void 0 : onDismiss(); | ||
onDismiss?.(); | ||
} | ||
function onFocusOutside(event) { | ||
var _a, _b; | ||
const target = getEventTarget(event.detail.originalEvent); | ||
if (layerStack.isInBranch(target)) | ||
return; | ||
(_a = options.onFocusOutside) == null ? void 0 : _a.call(options, event); | ||
(_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event); | ||
options.onFocusOutside?.(event); | ||
options.onInteractOutside?.(event); | ||
if (event.defaultPrevented) | ||
@@ -238,9 +232,8 @@ return; | ||
} | ||
onDismiss == null ? void 0 : onDismiss(); | ||
onDismiss?.(); | ||
} | ||
function onEscapeKeyDown(event) { | ||
var _a; | ||
if (!layerStack.isTopMost(node)) | ||
return; | ||
(_a = options.onEscapeKeyDown) == null ? void 0 : _a.call(options, event); | ||
options.onEscapeKeyDown?.(event); | ||
if (!event.defaultPrevented && onDismiss) { | ||
@@ -267,3 +260,3 @@ event.preventDefault(); | ||
clearPointerEvent(node); | ||
cleanups.forEach((fn) => fn == null ? void 0 : fn()); | ||
cleanups.forEach((fn) => fn?.()); | ||
}; | ||
@@ -270,0 +263,0 @@ } |
@@ -34,3 +34,3 @@ "use strict"; | ||
function isHTMLElement(v) { | ||
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string"; | ||
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string"; | ||
} | ||
@@ -55,5 +55,4 @@ | ||
isBelowPointerBlockingLayer(node) { | ||
var _a; | ||
const index = this.indexOf(node); | ||
const highestBlockingIndex = this.topMostPointerBlockingLayer() ? this.indexOf((_a = this.topMostPointerBlockingLayer()) == null ? void 0 : _a.node) : -1; | ||
const highestBlockingIndex = this.topMostPointerBlockingLayer() ? this.indexOf(this.topMostPointerBlockingLayer()?.node) : -1; | ||
return index < highestBlockingIndex; | ||
@@ -63,3 +62,3 @@ }, | ||
const layer = this.layers[this.count() - 1]; | ||
return (layer == null ? void 0 : layer.node) === node; | ||
return layer?.node === node; | ||
}, | ||
@@ -100,4 +99,3 @@ getNestedLayers(node) { | ||
dismiss(node) { | ||
var _a; | ||
(_a = this.layers[this.indexOf(node)]) == null ? void 0 : _a.dismiss(); | ||
this.layers[this.indexOf(node)]?.dismiss(); | ||
}, | ||
@@ -104,0 +102,0 @@ clear() { |
@@ -34,6 +34,5 @@ "use strict"; | ||
function isWindow(value) { | ||
return (value == null ? void 0 : value.toString()) === "[object Window]"; | ||
return value?.toString() === "[object Window]"; | ||
} | ||
function getDocument(el) { | ||
var _a; | ||
if (isWindow(el)) | ||
@@ -43,3 +42,3 @@ return el.document; | ||
return el; | ||
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document; | ||
return el?.ownerDocument ?? document; | ||
} | ||
@@ -52,3 +51,3 @@ function contains(parent, child) { | ||
function isHTMLElement(v) { | ||
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string"; | ||
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string"; | ||
} | ||
@@ -73,5 +72,4 @@ | ||
isBelowPointerBlockingLayer(node) { | ||
var _a; | ||
const index = this.indexOf(node); | ||
const highestBlockingIndex = this.topMostPointerBlockingLayer() ? this.indexOf((_a = this.topMostPointerBlockingLayer()) == null ? void 0 : _a.node) : -1; | ||
const highestBlockingIndex = this.topMostPointerBlockingLayer() ? this.indexOf(this.topMostPointerBlockingLayer()?.node) : -1; | ||
return index < highestBlockingIndex; | ||
@@ -81,3 +79,3 @@ }, | ||
const layer = this.layers[this.count() - 1]; | ||
return (layer == null ? void 0 : layer.node) === node; | ||
return layer?.node === node; | ||
}, | ||
@@ -118,4 +116,3 @@ getNestedLayers(node) { | ||
dismiss(node) { | ||
var _a; | ||
(_a = this.layers[this.indexOf(node)]) == null ? void 0 : _a.dismiss(); | ||
this.layers[this.indexOf(node)]?.dismiss(); | ||
}, | ||
@@ -122,0 +119,0 @@ clear() { |
{ | ||
"name": "@zag-js/dismissable", | ||
"version": "0.0.0-dev-20221229205502", | ||
"version": "0.0.0-dev-20230201181615", | ||
"description": "Dismissable layer utilities for the DOM", | ||
@@ -26,8 +26,8 @@ "keywords": [ | ||
"dependencies": { | ||
"@zag-js/interact-outside": "0.0.0-dev-20221229205502" | ||
"@zag-js/interact-outside": "0.0.0-dev-20230201181615" | ||
}, | ||
"devDependencies": { | ||
"clean-package": "2.2.0", | ||
"@zag-js/dom-utils": "0.0.0-dev-20221229205502", | ||
"@zag-js/utils": "0.0.0-dev-20221229205502" | ||
"@zag-js/dom-utils": "0.0.0-dev-20230201181615", | ||
"@zag-js/utils": "0.0.0-dev-20230201181615" | ||
}, | ||
@@ -34,0 +34,0 @@ "bugs": { |
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
Sorry, the diff of this file is not supported yet
39237
1124
+ Added@zag-js/interact-outside@0.0.0-dev-20230201181615(transitive)
- Removed@zag-js/interact-outside@0.0.0-dev-20221229205502(transitive)