@zag-js/interact-outside 0.0.0-dev-20230202113057 → 0.0.0-dev-20230217074947

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.js CHANGED
@@ -118,18 +118,44 @@ function addDomEvent(target, eventName, handler, options) {
118
118
  // src/index.ts
119
119
  var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
120
120
  var FOCUS_OUTSIDE_EVENT = "focus.outside";
121
+ function getWindowFrames(win) {
122
+ const frames = {
123
+ each(cb) {
124
+ for (let i = 0; i < win.frames?.length; i += 1) {
125
+ const frame = win.frames[i];
126
+ if (frame)
127
+ cb(frame);
128
+ }
129
+ },
130
+ addEventListener(event, listener, options) {
131
+ frames.each((frame) => {
132
+ frame.document.addEventListener(event, listener, options);
133
+ });
134
+ return () => {
135
+ frames.removeEventListener(event, listener, options);
136
+ };
137
+ },
138
+ removeEventListener(event, listener, options) {
139
+ frames.each((frame) => {
140
+ frame.document.removeEventListener(event, listener, options);
141
+ });
142
+ }
143
+ };
144
+ return frames;
145
+ }
146
+ var isHTMLElement2 = (node) => {
147
+ return node !== null && typeof node === "object" && node.nodeType === 1;
148
+ };
121
149
  function trackInteractOutside(node, options) {
122
150
  const { exclude, onFocusOutside, onPointerDownOutside, onInteractOutside } = options;
123
151
  if (!node)
124
152
  return;
125
153
  const doc = getDocument(node);
126
154
  const win = getWindow(node);
155
+ const frames = getWindowFrames(win);
127
156
  function isEventOutside(event) {
128
157
  const target = getEventTarget(event);
129
- if (!(target instanceof win.HTMLElement)) {
130
- return false;
131
- }
132
- if (!contains(doc.documentElement, target)) {
158
+ if (!isHTMLElement2(target)) {
133
159
  return false;
134
160
  }
135
161
  if (contains(node, target)) {
@@ -157,15 +183,18 @@ function trackInteractOutside(node, options) {
157
183
  });
158
184
  }
159
185
  if (event.pointerType === "touch") {
186
+ frames.removeEventListener("click", handler);
160
187
  doc.removeEventListener("click", handler);
161
188
  clickHandler = handler;
162
189
  doc.addEventListener("click", handler, { once: true });
190
+ frames.addEventListener("click", handler, { once: true });
163
191
  } else {
164
192
  handler();
165
193
  }
166
194
  }
167
195
  const cleanups = /* @__PURE__ */ new Set();
168
196
  const timer = setTimeout(() => {
197
+ cleanups.add(frames.addEventListener("pointerdown", onPointerDown, true));
169
198
  cleanups.add(addDomEvent(doc, "pointerdown", onPointerDown, true));
170
199
  }, 0);
171
200
  function onFocusin(event) {
@@ -186,10 +215,13 @@ function trackInteractOutside(node, options) {
186
215
  });
187
216
  }
188
217
  cleanups.add(addDomEvent(doc, "focusin", onFocusin, true));
218
+ cleanups.add(frames.addEventListener("focusin", onFocusin, true));
189
219
  return () => {
190
220
  clearTimeout(timer);
191
- if (clickHandler)
221
+ if (clickHandler) {
222
+ frames.removeEventListener("click", clickHandler);
192
223
  doc.removeEventListener("click", clickHandler);
224
+ }
193
225
  cleanups.forEach((fn) => fn());
194
226
  };
195
227
  }
package/dist/index.mjs CHANGED
@@ -92,18 +92,44 @@ function addDomEvent(target, eventName, handler, options) {
92
92
  // src/index.ts
93
93
  var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
94
94
  var FOCUS_OUTSIDE_EVENT = "focus.outside";
95
+ function getWindowFrames(win) {
96
+ const frames = {
97
+ each(cb) {
98
+ for (let i = 0; i < win.frames?.length; i += 1) {
99
+ const frame = win.frames[i];
100
+ if (frame)
101
+ cb(frame);
102
+ }
103
+ },
104
+ addEventListener(event, listener, options) {
105
+ frames.each((frame) => {
106
+ frame.document.addEventListener(event, listener, options);
107
+ });
108
+ return () => {
109
+ frames.removeEventListener(event, listener, options);
110
+ };
111
+ },
112
+ removeEventListener(event, listener, options) {
113
+ frames.each((frame) => {
114
+ frame.document.removeEventListener(event, listener, options);
115
+ });
116
+ }
117
+ };
118
+ return frames;
119
+ }
120
+ var isHTMLElement2 = (node) => {
121
+ return node !== null && typeof node === "object" && node.nodeType === 1;
122
+ };
95
123
  function trackInteractOutside(node, options) {
96
124
  const { exclude, onFocusOutside, onPointerDownOutside, onInteractOutside } = options;
97
125
  if (!node)
98
126
  return;
99
127
  const doc = getDocument(node);
100
128
  const win = getWindow(node);
129
+ const frames = getWindowFrames(win);
101
130
  function isEventOutside(event) {
102
131
  const target = getEventTarget(event);
103
- if (!(target instanceof win.HTMLElement)) {
104
- return false;
105
- }
106
- if (!contains(doc.documentElement, target)) {
132
+ if (!isHTMLElement2(target)) {
107
133
  return false;
108
134
  }
109
135
  if (contains(node, target)) {
@@ -131,15 +157,18 @@ function trackInteractOutside(node, options) {
131
157
  });
132
158
  }
133
159
  if (event.pointerType === "touch") {
160
+ frames.removeEventListener("click", handler);
134
161
  doc.removeEventListener("click", handler);
135
162
  clickHandler = handler;
136
163
  doc.addEventListener("click", handler, { once: true });
164
+ frames.addEventListener("click", handler, { once: true });
137
165
  } else {
138
166
  handler();
139
167
  }
140
168
  }
141
169
  const cleanups = /* @__PURE__ */ new Set();
142
170
  const timer = setTimeout(() => {
171
+ cleanups.add(frames.addEventListener("pointerdown", onPointerDown, true));
143
172
  cleanups.add(addDomEvent(doc, "pointerdown", onPointerDown, true));
144
173
  }, 0);
145
174
  function onFocusin(event) {
@@ -160,10 +189,13 @@ function trackInteractOutside(node, options) {
160
189
  });
161
190
  }
162
191
  cleanups.add(addDomEvent(doc, "focusin", onFocusin, true));
192
+ cleanups.add(frames.addEventListener("focusin", onFocusin, true));
163
193
  return () => {
164
194
  clearTimeout(timer);
165
- if (clickHandler)
195
+ if (clickHandler) {
196
+ frames.removeEventListener("click", clickHandler);
166
197
  doc.removeEventListener("click", clickHandler);
198
+ }
167
199
  cleanups.forEach((fn) => fn());
168
200
  };
169
201
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/interact-outside",
3
- "version": "0.0.0-dev-20230202113057",
3
+ "version": "0.0.0-dev-20230217074947",
4
4
  "description": "Track interations or focus outside an element",
5
5
  "keywords": [
6
6
  "js",
@@ -17,8 +17,8 @@
17
17
  ],
18
18
  "devDependencies": {
19
19
  "clean-package": "2.2.0",
20
- "@zag-js/dom-utils": "0.0.0-dev-20230202113057",
21
- "@zag-js/utils": "0.0.0-dev-20230202113057"
20
+ "@zag-js/dom-utils": "0.2.4",
21
+ "@zag-js/utils": "0.3.3"
22
22
  },
23
23
  "publishConfig": {
24
24
  "access": "public"