@zag-js/interact-outside 0.1.1 → 0.1.2

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.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export declare type InteractOutsideHandlers = {
2
2
  onPointerDownOutside?: (event: PointerDownOutsideEvent) => void;
3
3
  onFocusOutside?: (event: FocusOutsideEvent) => void;
4
+ onInteractOutside?: (event: InteractOutsideEvent) => void;
4
5
  };
5
6
  export declare type InteractOutsideOptions = InteractOutsideHandlers & {
6
7
  exclude?: (target: HTMLElement) => boolean;
package/dist/index.js CHANGED
@@ -39,6 +39,9 @@ function getPlatform() {
39
39
  var pt = (v) => isDom() && v.test(getPlatform());
40
40
  var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
41
41
  var isMac = () => pt(/^Mac/) && !isTouchDevice;
42
+ function isDocument(el) {
43
+ return el.nodeType === Node.DOCUMENT_NODE;
44
+ }
42
45
  function isWindow(value) {
43
46
  return (value == null ? void 0 : value.toString()) === "[object Window]";
44
47
  }
@@ -46,6 +49,8 @@ function getDocument(el) {
46
49
  var _a;
47
50
  if (isWindow(el))
48
51
  return el.document;
52
+ if (isDocument(el))
53
+ return el;
49
54
  return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
50
55
  }
51
56
  function getWindow(el) {
@@ -95,11 +100,18 @@ function addDomEvent(target, eventName, handler, options) {
95
100
  };
96
101
  }
97
102
 
103
+ // ../core/dist/index.mjs
104
+ var callAll = (...fns) => (...a) => {
105
+ fns.forEach(function(fn) {
106
+ fn == null ? void 0 : fn(...a);
107
+ });
108
+ };
109
+
98
110
  // src/index.ts
99
111
  var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
100
112
  var FOCUS_OUTSIDE_EVENT = "focus.outside";
101
113
  function trackInteractOutside(node, options) {
102
- const { exclude, onFocusOutside, onPointerDownOutside } = options;
114
+ const { exclude, onFocusOutside, onPointerDownOutside, onInteractOutside } = options;
103
115
  if (!node)
104
116
  return;
105
117
  const doc = getDocument(node);
@@ -122,8 +134,9 @@ function trackInteractOutside(node, options) {
122
134
  function handler() {
123
135
  if (!node || !isEventOutside(event))
124
136
  return;
125
- if (onPointerDownOutside) {
126
- node.addEventListener(POINTER_OUTSIDE_EVENT, onPointerDownOutside, { once: true });
137
+ if (onPointerDownOutside || onInteractOutside) {
138
+ const handler2 = callAll(onPointerDownOutside, onInteractOutside);
139
+ node.addEventListener(POINTER_OUTSIDE_EVENT, handler2, { once: true });
127
140
  }
128
141
  fireCustomEvent(node, POINTER_OUTSIDE_EVENT, {
129
142
  bubbles: false,
@@ -150,8 +163,9 @@ function trackInteractOutside(node, options) {
150
163
  function onFocusin(event) {
151
164
  if (!node || !isEventOutside(event))
152
165
  return;
153
- if (onFocusOutside) {
154
- node.addEventListener(FOCUS_OUTSIDE_EVENT, onFocusOutside, { once: true });
166
+ if (onFocusOutside || onInteractOutside) {
167
+ const handler = callAll(onFocusOutside, onInteractOutside);
168
+ node.addEventListener(FOCUS_OUTSIDE_EVENT, handler, { once: true });
155
169
  }
156
170
  fireCustomEvent(node, FOCUS_OUTSIDE_EVENT, {
157
171
  bubbles: false,
package/dist/index.mjs CHANGED
@@ -13,6 +13,9 @@ function getPlatform() {
13
13
  var pt = (v) => isDom() && v.test(getPlatform());
14
14
  var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
15
15
  var isMac = () => pt(/^Mac/) && !isTouchDevice;
16
+ function isDocument(el) {
17
+ return el.nodeType === Node.DOCUMENT_NODE;
18
+ }
16
19
  function isWindow(value) {
17
20
  return (value == null ? void 0 : value.toString()) === "[object Window]";
18
21
  }
@@ -20,6 +23,8 @@ function getDocument(el) {
20
23
  var _a;
21
24
  if (isWindow(el))
22
25
  return el.document;
26
+ if (isDocument(el))
27
+ return el;
23
28
  return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
24
29
  }
25
30
  function getWindow(el) {
@@ -69,11 +74,18 @@ function addDomEvent(target, eventName, handler, options) {
69
74
  };
70
75
  }
71
76
 
77
+ // ../core/dist/index.mjs
78
+ var callAll = (...fns) => (...a) => {
79
+ fns.forEach(function(fn) {
80
+ fn == null ? void 0 : fn(...a);
81
+ });
82
+ };
83
+
72
84
  // src/index.ts
73
85
  var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
74
86
  var FOCUS_OUTSIDE_EVENT = "focus.outside";
75
87
  function trackInteractOutside(node, options) {
76
- const { exclude, onFocusOutside, onPointerDownOutside } = options;
88
+ const { exclude, onFocusOutside, onPointerDownOutside, onInteractOutside } = options;
77
89
  if (!node)
78
90
  return;
79
91
  const doc = getDocument(node);
@@ -96,8 +108,9 @@ function trackInteractOutside(node, options) {
96
108
  function handler() {
97
109
  if (!node || !isEventOutside(event))
98
110
  return;
99
- if (onPointerDownOutside) {
100
- node.addEventListener(POINTER_OUTSIDE_EVENT, onPointerDownOutside, { once: true });
111
+ if (onPointerDownOutside || onInteractOutside) {
112
+ const handler2 = callAll(onPointerDownOutside, onInteractOutside);
113
+ node.addEventListener(POINTER_OUTSIDE_EVENT, handler2, { once: true });
101
114
  }
102
115
  fireCustomEvent(node, POINTER_OUTSIDE_EVENT, {
103
116
  bubbles: false,
@@ -124,8 +137,9 @@ function trackInteractOutside(node, options) {
124
137
  function onFocusin(event) {
125
138
  if (!node || !isEventOutside(event))
126
139
  return;
127
- if (onFocusOutside) {
128
- node.addEventListener(FOCUS_OUTSIDE_EVENT, onFocusOutside, { once: true });
140
+ if (onFocusOutside || onInteractOutside) {
141
+ const handler = callAll(onFocusOutside, onInteractOutside);
142
+ node.addEventListener(FOCUS_OUTSIDE_EVENT, handler, { once: true });
129
143
  }
130
144
  fireCustomEvent(node, FOCUS_OUTSIDE_EVENT, {
131
145
  bubbles: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/interact-outside",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Track interations or focus outside an element",
5
5
  "keywords": [
6
6
  "js",
@@ -28,7 +28,7 @@
28
28
  "test:watch": "yarn test --watchAll"
29
29
  },
30
30
  "dependencies": {
31
- "@zag-js/dom-utils": "0.1.6"
31
+ "@zag-js/dom-utils": "0.1.7"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"