@zag-js/interact-outside 0.0.0-dev-20220709181637 → 0.0.0-dev-20220710093812

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
@@ -100,11 +100,18 @@ function addDomEvent(target, eventName, handler, options) {
100
100
  };
101
101
  }
102
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
+
103
110
  // src/index.ts
104
111
  var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
105
112
  var FOCUS_OUTSIDE_EVENT = "focus.outside";
106
113
  function trackInteractOutside(node, options) {
107
- const { exclude, onFocusOutside, onPointerDownOutside } = options;
114
+ const { exclude, onFocusOutside, onPointerDownOutside, onInteractOutside } = options;
108
115
  if (!node)
109
116
  return;
110
117
  const doc = getDocument(node);
@@ -127,8 +134,9 @@ function trackInteractOutside(node, options) {
127
134
  function handler() {
128
135
  if (!node || !isEventOutside(event))
129
136
  return;
130
- if (onPointerDownOutside) {
131
- 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 });
132
140
  }
133
141
  fireCustomEvent(node, POINTER_OUTSIDE_EVENT, {
134
142
  bubbles: false,
@@ -155,8 +163,9 @@ function trackInteractOutside(node, options) {
155
163
  function onFocusin(event) {
156
164
  if (!node || !isEventOutside(event))
157
165
  return;
158
- if (onFocusOutside) {
159
- 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 });
160
169
  }
161
170
  fireCustomEvent(node, FOCUS_OUTSIDE_EVENT, {
162
171
  bubbles: false,
package/dist/index.mjs CHANGED
@@ -74,11 +74,18 @@ function addDomEvent(target, eventName, handler, options) {
74
74
  };
75
75
  }
76
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
+
77
84
  // src/index.ts
78
85
  var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
79
86
  var FOCUS_OUTSIDE_EVENT = "focus.outside";
80
87
  function trackInteractOutside(node, options) {
81
- const { exclude, onFocusOutside, onPointerDownOutside } = options;
88
+ const { exclude, onFocusOutside, onPointerDownOutside, onInteractOutside } = options;
82
89
  if (!node)
83
90
  return;
84
91
  const doc = getDocument(node);
@@ -101,8 +108,9 @@ function trackInteractOutside(node, options) {
101
108
  function handler() {
102
109
  if (!node || !isEventOutside(event))
103
110
  return;
104
- if (onPointerDownOutside) {
105
- 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 });
106
114
  }
107
115
  fireCustomEvent(node, POINTER_OUTSIDE_EVENT, {
108
116
  bubbles: false,
@@ -129,8 +137,9 @@ function trackInteractOutside(node, options) {
129
137
  function onFocusin(event) {
130
138
  if (!node || !isEventOutside(event))
131
139
  return;
132
- if (onFocusOutside) {
133
- 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 });
134
143
  }
135
144
  fireCustomEvent(node, FOCUS_OUTSIDE_EVENT, {
136
145
  bubbles: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/interact-outside",
3
- "version": "0.0.0-dev-20220709181637",
3
+ "version": "0.0.0-dev-20220710093812",
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.0.0-dev-20220709181637"
31
+ "@zag-js/dom-utils": "0.0.0-dev-20220710093812"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"