@zag-js/dismissable 2.0.0-next.3 → 2.0.0-next.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,56 +1,55 @@
1
- // src/pointer-event-outside.ts
2
- import { getDocument, isHTMLElement, setStyle, waitForElement } from "@zag-js/dom-query";
3
1
  import { layerStack } from "./layer-stack.mjs";
4
- var originalBodyPointerEvents = /* @__PURE__ */ new WeakMap();
2
+ import { getDocument, isHTMLElement, setStyle, waitForElement } from "@zag-js/dom-query";
3
+ // src/pointer-event-outside.ts
4
+ const originalBodyPointerEvents = /* @__PURE__ */ new WeakMap();
5
+ const scheduled = /* @__PURE__ */ new WeakSet();
6
+ /** Applies or restores body blocking from the current stack state, once per microtask. */
5
7
  function syncBodyPointerEvents(doc) {
6
- const body = doc.body;
7
- if (!body) return;
8
- const shouldBlock = layerStack.hasPointerBlockingLayer();
9
- if (shouldBlock === body.hasAttribute("data-inert")) return;
10
- if (shouldBlock) {
11
- originalBodyPointerEvents.set(body, body.style.pointerEvents);
12
- queueMicrotask(() => {
13
- if (!layerStack.hasPointerBlockingLayer()) return;
14
- body.style.pointerEvents = "none";
15
- body.setAttribute("data-inert", "");
16
- });
17
- return;
18
- }
19
- queueMicrotask(() => {
20
- if (layerStack.hasPointerBlockingLayer()) return;
21
- const original = originalBodyPointerEvents.get(body);
22
- if (original !== void 0) {
23
- body.style.pointerEvents = original;
24
- originalBodyPointerEvents.delete(body);
25
- }
26
- body.removeAttribute("data-inert");
27
- if (body.style.length === 0) body.removeAttribute("style");
28
- });
8
+ if (scheduled.has(doc)) return;
9
+ scheduled.add(doc);
10
+ queueMicrotask(() => {
11
+ scheduled.delete(doc);
12
+ const body = doc.body;
13
+ if (!body) return;
14
+ const shouldBlock = layerStack.hasPointerBlockingLayer();
15
+ if (shouldBlock === body.hasAttribute("data-inert")) return;
16
+ if (shouldBlock) {
17
+ originalBodyPointerEvents.set(body, body.style.pointerEvents);
18
+ body.style.pointerEvents = "none";
19
+ body.setAttribute("data-inert", "");
20
+ return;
21
+ }
22
+ const original = originalBodyPointerEvents.get(body);
23
+ if (original !== void 0) {
24
+ body.style.pointerEvents = original;
25
+ originalBodyPointerEvents.delete(body);
26
+ }
27
+ body.removeAttribute("data-inert");
28
+ if (body.style.length === 0) body.removeAttribute("style");
29
+ });
29
30
  }
31
+ /**
32
+ * Re-derives pointer blocking from the stack. Needed after a layer's `pointerBlocking` getter
33
+ * changes value, since nothing was added or removed to trigger the usual sync.
34
+ */
30
35
  function syncPointerEvents(node) {
31
- syncBodyPointerEvents(getDocument(node));
36
+ syncBodyPointerEvents(getDocument(node));
32
37
  }
33
38
  function disablePointerEventsOutside(node, persistentElements) {
34
- const doc = getDocument(node);
35
- const cleanups = [];
36
- syncBodyPointerEvents(doc);
37
- persistentElements?.forEach((el) => {
38
- const [promise, abort] = waitForElement(
39
- () => {
40
- const node2 = el();
41
- return isHTMLElement(node2) ? node2 : null;
42
- },
43
- { timeout: 1e3 }
44
- );
45
- promise.then((el2) => cleanups.push(setStyle(el2, { pointerEvents: "auto" })));
46
- cleanups.push(abort);
47
- });
48
- return () => {
49
- syncBodyPointerEvents(doc);
50
- cleanups.forEach((fn) => fn());
51
- };
39
+ const doc = getDocument(node);
40
+ const cleanups = [];
41
+ syncBodyPointerEvents(doc);
42
+ persistentElements?.forEach((el) => {
43
+ const [promise, abort] = waitForElement(() => {
44
+ const node = el();
45
+ return isHTMLElement(node) ? node : null;
46
+ }, { timeout: 1e3 });
47
+ promise.then((el) => cleanups.push(setStyle(el, { pointerEvents: "auto" })));
48
+ cleanups.push(abort);
49
+ });
50
+ return () => {
51
+ syncBodyPointerEvents(doc);
52
+ cleanups.forEach((fn) => fn());
53
+ };
52
54
  }
53
- export {
54
- disablePointerEventsOutside,
55
- syncPointerEvents
56
- };
55
+ export { disablePointerEventsOutside, syncPointerEvents };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/dismissable",
3
- "version": "2.0.0-next.3",
3
+ "version": "2.0.0-next.4",
4
4
  "description": "Dismissable layer utilities for the DOM",
5
5
  "keywords": [
6
6
  "js",
@@ -26,9 +26,9 @@
26
26
  "access": "public"
27
27
  },
28
28
  "dependencies": {
29
- "@zag-js/interact-outside": "2.0.0-next.3",
30
- "@zag-js/dom-query": "2.0.0-next.3",
31
- "@zag-js/utils": "2.0.0-next.3"
29
+ "@zag-js/interact-outside": "2.0.0-next.4",
30
+ "@zag-js/dom-query": "2.0.0-next.4",
31
+ "@zag-js/utils": "2.0.0-next.4"
32
32
  },
33
33
  "devDependencies": {
34
34
  "clean-package": "2.2.0"
@@ -54,7 +54,7 @@
54
54
  "./package.json": "./package.json"
55
55
  },
56
56
  "scripts": {
57
- "build": "tsup",
57
+ "build": "tsdown",
58
58
  "test": "vitest",
59
59
  "lint": "oxlint src",
60
60
  "test-ci": "pnpm test --ci --runInBand -u",