@zag-js/dismissable 1.45.0 → 1.47.0

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,4 +1,4 @@
1
- import { InteractOutsideHandlers } from '@zag-js/interact-outside';
1
+ import { InteractOutsideHandlers, PointerDownOutsideEvent, FocusOutsideEvent } from '@zag-js/interact-outside';
2
2
  import { MaybeFunction } from '@zag-js/utils';
3
3
  import { LayerDismissEvent, LayerStyleTarget, LayerType } from './layer-stack.mjs';
4
4
 
@@ -39,9 +39,9 @@ interface DismissableElementOptions extends DismissableElementHandlers, Persiste
39
39
  */
40
40
  pointerBlocking?: boolean | undefined;
41
41
  /**
42
- * Function called when the dismissable element is dismissed
42
+ * Function called when the dismissable element is dismissed, with the event that caused it
43
43
  */
44
- onDismiss: VoidFunction;
44
+ onDismiss: (event?: KeyboardEvent | PointerDownOutsideEvent | FocusOutsideEvent) => void;
45
45
  /**
46
46
  * Exclude containers from the interact outside event
47
47
  */
@@ -50,6 +50,10 @@ interface DismissableElementOptions extends DismissableElementHandlers, Persiste
50
50
  * Defer the interact outside event to the next frame
51
51
  */
52
52
  defer?: boolean | undefined;
53
+ /**
54
+ * The root the node is queried from, observed while the node is deferred
55
+ */
56
+ getRootNode?: (() => Node) | undefined;
53
57
  /**
54
58
  * Whether to warn when the node is `null` or `undefined`
55
59
  */
@@ -60,8 +64,6 @@ interface DismissableElementOptions extends DismissableElementHandlers, Persiste
60
64
  type?: LayerType | undefined;
61
65
  }
62
66
  declare function trackDismissableElement(nodeOrFn: NodeOrFn, options: DismissableElementOptions): VoidFunction;
63
- declare function trackDismissableBranch(nodeOrFn: NodeOrFn, options?: {
64
- defer?: boolean | undefined;
65
- }): VoidFunction;
67
+ declare function trackDismissableBranch(nodeOrFn: NodeOrFn, options?: Pick<DismissableElementOptions, "defer" | "getRootNode">): VoidFunction;
66
68
 
67
69
  export { type DismissableElementHandlers, type DismissableElementOptions, type PersistentElementOptions, trackDismissableBranch, trackDismissableElement };
@@ -1,4 +1,4 @@
1
- import { InteractOutsideHandlers } from '@zag-js/interact-outside';
1
+ import { InteractOutsideHandlers, PointerDownOutsideEvent, FocusOutsideEvent } from '@zag-js/interact-outside';
2
2
  import { MaybeFunction } from '@zag-js/utils';
3
3
  import { LayerDismissEvent, LayerStyleTarget, LayerType } from './layer-stack.js';
4
4
 
@@ -39,9 +39,9 @@ interface DismissableElementOptions extends DismissableElementHandlers, Persiste
39
39
  */
40
40
  pointerBlocking?: boolean | undefined;
41
41
  /**
42
- * Function called when the dismissable element is dismissed
42
+ * Function called when the dismissable element is dismissed, with the event that caused it
43
43
  */
44
- onDismiss: VoidFunction;
44
+ onDismiss: (event?: KeyboardEvent | PointerDownOutsideEvent | FocusOutsideEvent) => void;
45
45
  /**
46
46
  * Exclude containers from the interact outside event
47
47
  */
@@ -50,6 +50,10 @@ interface DismissableElementOptions extends DismissableElementHandlers, Persiste
50
50
  * Defer the interact outside event to the next frame
51
51
  */
52
52
  defer?: boolean | undefined;
53
+ /**
54
+ * The root the node is queried from, observed while the node is deferred
55
+ */
56
+ getRootNode?: (() => Node) | undefined;
53
57
  /**
54
58
  * Whether to warn when the node is `null` or `undefined`
55
59
  */
@@ -60,8 +64,6 @@ interface DismissableElementOptions extends DismissableElementHandlers, Persiste
60
64
  type?: LayerType | undefined;
61
65
  }
62
66
  declare function trackDismissableElement(nodeOrFn: NodeOrFn, options: DismissableElementOptions): VoidFunction;
63
- declare function trackDismissableBranch(nodeOrFn: NodeOrFn, options?: {
64
- defer?: boolean | undefined;
65
- }): VoidFunction;
67
+ declare function trackDismissableBranch(nodeOrFn: NodeOrFn, options?: Pick<DismissableElementOptions, "defer" | "getRootNode">): VoidFunction;
66
68
 
67
69
  export { type DismissableElementHandlers, type DismissableElementOptions, type PersistentElementOptions, trackDismissableBranch, trackDismissableElement };
@@ -59,7 +59,7 @@ function trackDismissableElementImpl(node, options) {
59
59
  if (debug) {
60
60
  console.log("onPointerDownOutside:", event.detail.originalEvent);
61
61
  }
62
- onDismiss?.();
62
+ onDismiss?.(event);
63
63
  }
64
64
  function onFocusOutside(event) {
65
65
  const target = (0, import_dom_query.getEventTarget)(event.detail.originalEvent);
@@ -70,14 +70,14 @@ function trackDismissableElementImpl(node, options) {
70
70
  if (debug) {
71
71
  console.log("onFocusOutside:", event.detail.originalEvent);
72
72
  }
73
- onDismiss?.();
73
+ onDismiss?.(event);
74
74
  }
75
75
  function onEscapeKeyDown(event) {
76
76
  if (!import_layer_stack.layerStack.isTopMost(node)) return;
77
77
  options.onEscapeKeyDown?.(event);
78
78
  if (!event.defaultPrevented && onDismiss) {
79
79
  event.preventDefault();
80
- onDismiss();
80
+ onDismiss(event);
81
81
  }
82
82
  }
83
83
  function exclude(target) {
@@ -103,6 +103,7 @@ function trackDismissableElement(nodeOrFn, options) {
103
103
  const { warnOnMissingNode = true } = options;
104
104
  return (0, import_dom_query.whenNode)(nodeOrFn, (node) => trackDismissableElementImpl(node, options), {
105
105
  defer: options.defer,
106
+ getRootNode: options.getRootNode,
106
107
  onMissing: warnOnMissingNode ? () => (0, import_utils.warn)("[@zag-js/dismissable] node is `null` or `undefined`") : void 0
107
108
  });
108
109
  }
@@ -117,6 +118,7 @@ function trackDismissableBranch(nodeOrFn, options = {}) {
117
118
  },
118
119
  {
119
120
  defer: options.defer,
121
+ getRootNode: options.getRootNode,
120
122
  onMissing: () => (0, import_utils.warn)("[@zag-js/dismissable] branch node is `null` or `undefined`")
121
123
  }
122
124
  );
@@ -36,7 +36,7 @@ function trackDismissableElementImpl(node, options) {
36
36
  if (debug) {
37
37
  console.log("onPointerDownOutside:", event.detail.originalEvent);
38
38
  }
39
- onDismiss?.();
39
+ onDismiss?.(event);
40
40
  }
41
41
  function onFocusOutside(event) {
42
42
  const target = getEventTarget(event.detail.originalEvent);
@@ -47,14 +47,14 @@ function trackDismissableElementImpl(node, options) {
47
47
  if (debug) {
48
48
  console.log("onFocusOutside:", event.detail.originalEvent);
49
49
  }
50
- onDismiss?.();
50
+ onDismiss?.(event);
51
51
  }
52
52
  function onEscapeKeyDown(event) {
53
53
  if (!layerStack.isTopMost(node)) return;
54
54
  options.onEscapeKeyDown?.(event);
55
55
  if (!event.defaultPrevented && onDismiss) {
56
56
  event.preventDefault();
57
- onDismiss();
57
+ onDismiss(event);
58
58
  }
59
59
  }
60
60
  function exclude(target) {
@@ -80,6 +80,7 @@ function trackDismissableElement(nodeOrFn, options) {
80
80
  const { warnOnMissingNode = true } = options;
81
81
  return whenNode(nodeOrFn, (node) => trackDismissableElementImpl(node, options), {
82
82
  defer: options.defer,
83
+ getRootNode: options.getRootNode,
83
84
  onMissing: warnOnMissingNode ? () => warn("[@zag-js/dismissable] node is `null` or `undefined`") : void 0
84
85
  });
85
86
  }
@@ -94,6 +95,7 @@ function trackDismissableBranch(nodeOrFn, options = {}) {
94
95
  },
95
96
  {
96
97
  defer: options.defer,
98
+ getRootNode: options.getRootNode,
97
99
  onMissing: () => warn("[@zag-js/dismissable] branch node is `null` or `undefined`")
98
100
  }
99
101
  );
@@ -166,7 +166,6 @@ function applyLayerStackMetadata(layer, index, el) {
166
166
  function clearLayerStyleMirror(el) {
167
167
  el.style.removeProperty("--layer-index");
168
168
  el.style.removeProperty("--nested-layer-count");
169
- el.style.removeProperty("--z-index");
170
169
  el.removeAttribute("data-nested");
171
170
  el.removeAttribute("data-has-nested");
172
171
  }
@@ -142,7 +142,6 @@ function applyLayerStackMetadata(layer, index, el) {
142
142
  function clearLayerStyleMirror(el) {
143
143
  el.style.removeProperty("--layer-index");
144
144
  el.style.removeProperty("--nested-layer-count");
145
- el.style.removeProperty("--z-index");
146
145
  el.removeAttribute("data-nested");
147
146
  el.removeAttribute("data-has-nested");
148
147
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/dismissable",
3
- "version": "1.45.0",
3
+ "version": "1.47.0",
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/dom-query": "1.45.0",
30
- "@zag-js/interact-outside": "1.45.0",
31
- "@zag-js/utils": "1.45.0"
29
+ "@zag-js/interact-outside": "1.47.0",
30
+ "@zag-js/dom-query": "1.47.0",
31
+ "@zag-js/utils": "1.47.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "clean-package": "2.2.0"