Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zag-js/dismissable

Package Overview
Dependencies
Maintainers
1
Versions
760
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zag-js/dismissable - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

dist/chunk-5BMACJNB.mjs

82

dist/dismissable-layer.js

@@ -26,62 +26,10 @@ "use strict";

module.exports = __toCommonJS(dismissable_layer_exports);
// ../core/src/functions.ts
var runIfFn = (v, ...a) => {
const res = typeof v === "function" ? v(...a) : v;
return res ?? void 0;
};
// ../core/src/guard.ts
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
// ../core/src/warning.ts
function warn(...a) {
const m = a.length === 1 ? a[0] : a[1];
const c = a.length === 2 ? a[0] : true;
if (c && process.env.NODE_ENV !== "production") {
console.warn(m);
}
}
// ../dom/src/query.ts
function isDocument(el) {
return el.nodeType === Node.DOCUMENT_NODE;
}
function isWindow(value) {
return value?.toString() === "[object Window]";
}
function getDocument(el) {
if (isWindow(el))
return el.document;
if (isDocument(el))
return el;
return el?.ownerDocument ?? document;
}
function getEventTarget(event) {
return event.composedPath?.()[0] ?? event.target;
}
function contains(parent, child) {
if (!parent)
return false;
return parent === child || isHTMLElement(parent) && isHTMLElement(child) && parent.contains(child);
}
function isHTMLElement(v) {
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
}
// ../dom/src/listener.ts
var isRef = (v) => hasProp(v, "current");
function addDomEvent(target, eventName, handler, options) {
const node = isRef(target) ? target.current : runIfFn(target);
node?.addEventListener(eventName, handler, options);
return () => {
node?.removeEventListener(eventName, handler, options);
};
}
// src/dismissable-layer.ts
var import_dom_query4 = require("@zag-js/dom-query");
var import_interact_outside = require("@zag-js/interact-outside");
var import_utils = require("@zag-js/utils");
// src/escape-keydown.ts
function trackEscapeKeydown(fn) {
var import_dom_event = require("@zag-js/dom-event");
var import_dom_query = require("@zag-js/dom-query");
function trackEscapeKeydown(node, fn) {
const handleKeyDown = (event) => {

@@ -91,6 +39,7 @@ if (event.key === "Escape")

};
return addDomEvent(document, "keydown", handleKeyDown);
return (0, import_dom_event.addDomEvent)((0, import_dom_query.getDocument)(node), "keydown", handleKeyDown);
}
// src/layer-stack.ts
var import_dom_query2 = require("@zag-js/dom-query");
var layerStack = {

@@ -124,6 +73,6 @@ layers: [],

isInNestedLayer(node, target) {
return this.getNestedLayers(node).some((layer) => contains(layer.node, target));
return this.getNestedLayers(node).some((layer) => (0, import_dom_query2.contains)(layer.node, target));
},
isInBranch(target) {
return Array.from(this.branches).some((branch) => contains(branch, target));
return Array.from(this.branches).some((branch) => (0, import_dom_query2.contains)(branch, target));
},

@@ -163,2 +112,3 @@ add(layer) {

// src/pointer-event-outside.ts
var import_dom_query3 = require("@zag-js/dom-query");
var originalBodyPointerEvents;

@@ -175,3 +125,3 @@ function assignPointerEventToLayers() {

function disablePointerEventsOutside(node) {
const doc = getDocument(node);
const doc = (0, import_dom_query3.getDocument)(node);
if (layerStack.hasPointerBlockingLayer() && !doc.body.hasAttribute(DATA_ATTR)) {

@@ -195,3 +145,3 @@ originalBodyPointerEvents = document.body.style.pointerEvents;

if (!node) {
warn("[@zag-js/dismissable] node is `null` or `undefined`");
(0, import_utils.warn)("[@zag-js/dismissable] node is `null` or `undefined`");
return;

@@ -204,3 +154,3 @@ }

function onPointerDownOutside(event) {
const target = getEventTarget(event.detail.originalEvent);
const target = (0, import_dom_query4.getEventTarget)(event.detail.originalEvent);
if (layerStack.isBelowPointerBlockingLayer(node) || layerStack.isInBranch(target))

@@ -218,3 +168,3 @@ return;

function onFocusOutside(event) {
const target = getEventTarget(event.detail.originalEvent);
const target = (0, import_dom_query4.getEventTarget)(event.detail.originalEvent);
if (layerStack.isInBranch(target))

@@ -245,7 +195,7 @@ return;

const _containers = Array.isArray(containers) ? containers : [containers];
return _containers.some((node2) => contains(node2, target)) || layerStack.isInNestedLayer(node, target);
return _containers.some((node2) => (0, import_dom_query4.contains)(node2, target)) || layerStack.isInNestedLayer(node, target);
}
const cleanups = [
pointerBlocking ? disablePointerEventsOutside(node) : void 0,
trackEscapeKeydown(onEscapeKeyDown),
trackEscapeKeydown(node, onEscapeKeyDown),
(0, import_interact_outside.trackInteractOutside)(node, { exclude, onFocusOutside, onPointerDownOutside })

@@ -252,0 +202,0 @@ ];

@@ -1,3 +0,3 @@

declare function trackEscapeKeydown(fn?: (event: KeyboardEvent) => void): () => void;
declare function trackEscapeKeydown(node: HTMLElement, fn?: (event: KeyboardEvent) => void): () => void;
export { trackEscapeKeydown };

@@ -26,24 +26,5 @@ "use strict";

module.exports = __toCommonJS(escape_keydown_exports);
// ../core/src/functions.ts
var runIfFn = (v, ...a) => {
const res = typeof v === "function" ? v(...a) : v;
return res ?? void 0;
};
// ../core/src/guard.ts
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
// ../dom/src/listener.ts
var isRef = (v) => hasProp(v, "current");
function addDomEvent(target, eventName, handler, options) {
const node = isRef(target) ? target.current : runIfFn(target);
node?.addEventListener(eventName, handler, options);
return () => {
node?.removeEventListener(eventName, handler, options);
};
}
// src/escape-keydown.ts
function trackEscapeKeydown(fn) {
var import_dom_event = require("@zag-js/dom-event");
var import_dom_query = require("@zag-js/dom-query");
function trackEscapeKeydown(node, fn) {
const handleKeyDown = (event) => {

@@ -53,3 +34,3 @@ if (event.key === "Escape")

};
return addDomEvent(document, "keydown", handleKeyDown);
return (0, import_dom_event.addDomEvent)((0, import_dom_query.getDocument)(node), "keydown", handleKeyDown);
}

@@ -56,0 +37,0 @@ // Annotate the CommonJS export names for ESM import in node:

@@ -27,61 +27,11 @@ "use strict";

// ../core/src/functions.ts
var runIfFn = (v, ...a) => {
const res = typeof v === "function" ? v(...a) : v;
return res ?? void 0;
};
// ../core/src/guard.ts
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
// ../core/src/warning.ts
function warn(...a) {
const m = a.length === 1 ? a[0] : a[1];
const c = a.length === 2 ? a[0] : true;
if (c && process.env.NODE_ENV !== "production") {
console.warn(m);
}
}
// ../dom/src/query.ts
function isDocument(el) {
return el.nodeType === Node.DOCUMENT_NODE;
}
function isWindow(value) {
return value?.toString() === "[object Window]";
}
function getDocument(el) {
if (isWindow(el))
return el.document;
if (isDocument(el))
return el;
return el?.ownerDocument ?? document;
}
function getEventTarget(event) {
return event.composedPath?.()[0] ?? event.target;
}
function contains(parent, child) {
if (!parent)
return false;
return parent === child || isHTMLElement(parent) && isHTMLElement(child) && parent.contains(child);
}
function isHTMLElement(v) {
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
}
// ../dom/src/listener.ts
var isRef = (v) => hasProp(v, "current");
function addDomEvent(target, eventName, handler, options) {
const node = isRef(target) ? target.current : runIfFn(target);
node?.addEventListener(eventName, handler, options);
return () => {
node?.removeEventListener(eventName, handler, options);
};
}
// src/dismissable-layer.ts
var import_dom_query4 = require("@zag-js/dom-query");
var import_interact_outside = require("@zag-js/interact-outside");
var import_utils = require("@zag-js/utils");
// src/escape-keydown.ts
function trackEscapeKeydown(fn) {
var import_dom_event = require("@zag-js/dom-event");
var import_dom_query = require("@zag-js/dom-query");
function trackEscapeKeydown(node, fn) {
const handleKeyDown = (event) => {

@@ -91,6 +41,7 @@ if (event.key === "Escape")

};
return addDomEvent(document, "keydown", handleKeyDown);
return (0, import_dom_event.addDomEvent)((0, import_dom_query.getDocument)(node), "keydown", handleKeyDown);
}
// src/layer-stack.ts
var import_dom_query2 = require("@zag-js/dom-query");
var layerStack = {

@@ -124,6 +75,6 @@ layers: [],

isInNestedLayer(node, target) {
return this.getNestedLayers(node).some((layer) => contains(layer.node, target));
return this.getNestedLayers(node).some((layer) => (0, import_dom_query2.contains)(layer.node, target));
},
isInBranch(target) {
return Array.from(this.branches).some((branch) => contains(branch, target));
return Array.from(this.branches).some((branch) => (0, import_dom_query2.contains)(branch, target));
},

@@ -163,2 +114,3 @@ add(layer) {

// src/pointer-event-outside.ts
var import_dom_query3 = require("@zag-js/dom-query");
var originalBodyPointerEvents;

@@ -175,3 +127,3 @@ function assignPointerEventToLayers() {

function disablePointerEventsOutside(node) {
const doc = getDocument(node);
const doc = (0, import_dom_query3.getDocument)(node);
if (layerStack.hasPointerBlockingLayer() && !doc.body.hasAttribute(DATA_ATTR)) {

@@ -195,3 +147,3 @@ originalBodyPointerEvents = document.body.style.pointerEvents;

if (!node) {
warn("[@zag-js/dismissable] node is `null` or `undefined`");
(0, import_utils.warn)("[@zag-js/dismissable] node is `null` or `undefined`");
return;

@@ -204,3 +156,3 @@ }

function onPointerDownOutside(event) {
const target = getEventTarget(event.detail.originalEvent);
const target = (0, import_dom_query4.getEventTarget)(event.detail.originalEvent);
if (layerStack.isBelowPointerBlockingLayer(node) || layerStack.isInBranch(target))

@@ -218,3 +170,3 @@ return;

function onFocusOutside(event) {
const target = getEventTarget(event.detail.originalEvent);
const target = (0, import_dom_query4.getEventTarget)(event.detail.originalEvent);
if (layerStack.isInBranch(target))

@@ -245,7 +197,7 @@ return;

const _containers = Array.isArray(containers) ? containers : [containers];
return _containers.some((node2) => contains(node2, target)) || layerStack.isInNestedLayer(node, target);
return _containers.some((node2) => (0, import_dom_query4.contains)(node2, target)) || layerStack.isInNestedLayer(node, target);
}
const cleanups = [
pointerBlocking ? disablePointerEventsOutside(node) : void 0,
trackEscapeKeydown(onEscapeKeyDown),
trackEscapeKeydown(node, onEscapeKeyDown),
(0, import_interact_outside.trackInteractOutside)(node, { exclude, onFocusOutside, onPointerDownOutside })

@@ -252,0 +204,0 @@ ];

@@ -26,14 +26,3 @@ "use strict";

module.exports = __toCommonJS(layer_stack_exports);
// ../dom/src/query.ts
function contains(parent, child) {
if (!parent)
return false;
return parent === child || isHTMLElement(parent) && isHTMLElement(child) && parent.contains(child);
}
function isHTMLElement(v) {
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
}
// src/layer-stack.ts
var import_dom_query = require("@zag-js/dom-query");
var layerStack = {

@@ -67,6 +56,6 @@ layers: [],

isInNestedLayer(node, target) {
return this.getNestedLayers(node).some((layer) => contains(layer.node, target));
return this.getNestedLayers(node).some((layer) => (0, import_dom_query.contains)(layer.node, target));
},
isInBranch(target) {
return Array.from(this.branches).some((branch) => contains(branch, target));
return Array.from(this.branches).some((branch) => (0, import_dom_query.contains)(branch, target));
},

@@ -73,0 +62,0 @@ add(layer) {

@@ -28,27 +28,6 @@ "use strict";

module.exports = __toCommonJS(pointer_event_outside_exports);
var import_dom_query2 = require("@zag-js/dom-query");
// ../dom/src/query.ts
function isDocument(el) {
return el.nodeType === Node.DOCUMENT_NODE;
}
function isWindow(value) {
return value?.toString() === "[object Window]";
}
function getDocument(el) {
if (isWindow(el))
return el.document;
if (isDocument(el))
return el;
return el?.ownerDocument ?? document;
}
function contains(parent, child) {
if (!parent)
return false;
return parent === child || isHTMLElement(parent) && isHTMLElement(child) && parent.contains(child);
}
function isHTMLElement(v) {
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
}
// src/layer-stack.ts
var import_dom_query = require("@zag-js/dom-query");
var layerStack = {

@@ -82,6 +61,6 @@ layers: [],

isInNestedLayer(node, target) {
return this.getNestedLayers(node).some((layer) => contains(layer.node, target));
return this.getNestedLayers(node).some((layer) => (0, import_dom_query.contains)(layer.node, target));
},
isInBranch(target) {
return Array.from(this.branches).some((branch) => contains(branch, target));
return Array.from(this.branches).some((branch) => (0, import_dom_query.contains)(branch, target));
},

@@ -132,3 +111,3 @@ add(layer) {

function disablePointerEventsOutside(node) {
const doc = getDocument(node);
const doc = (0, import_dom_query2.getDocument)(node);
if (layerStack.hasPointerBlockingLayer() && !doc.body.hasAttribute(DATA_ATTR)) {

@@ -135,0 +114,0 @@ originalBodyPointerEvents = document.body.style.pointerEvents;

{
"name": "@zag-js/dismissable",
"version": "0.2.2",
"version": "0.2.3",
"description": "Dismissable layer utilities for the DOM",

@@ -26,8 +26,9 @@ "keywords": [

"dependencies": {
"@zag-js/interact-outside": "0.2.2"
"@zag-js/interact-outside": "0.2.3",
"@zag-js/dom-event": "0.0.1",
"@zag-js/utils": "0.3.3",
"@zag-js/dom-query": "0.1.3"
},
"devDependencies": {
"clean-package": "2.2.0",
"@zag-js/dom-utils": "0.2.4",
"@zag-js/utils": "0.3.3"
"clean-package": "2.2.0"
},

@@ -34,0 +35,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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc