@zag-js/interact-outside 0.10.2 → 0.10.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,7 +1,5 @@
1
- declare function getWindowFrames(win: Window): {
1
+ export declare function getWindowFrames(win: Window): {
2
2
  each(cb: (win: Window) => void): void;
3
3
  addEventListener(event: string, listener: any, options?: any): () => void;
4
4
  removeEventListener(event: string, listener: any, options?: any): void;
5
5
  };
6
-
7
- export { getWindowFrames };
@@ -1,28 +1,7 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
19
4
 
20
- // src/get-window-frames.ts
21
- var get_window_frames_exports = {};
22
- __export(get_window_frames_exports, {
23
- getWindowFrames: () => getWindowFrames
24
- });
25
- module.exports = __toCommonJS(get_window_frames_exports);
26
5
  function getWindowFrames(win) {
27
6
  const frames = {
28
7
  each(cb) {
@@ -60,7 +39,5 @@ function getWindowFrames(win) {
60
39
  };
61
40
  return frames;
62
41
  }
63
- // Annotate the CommonJS export names for ESM import in node:
64
- 0 && (module.exports = {
65
- getWindowFrames
66
- });
42
+
43
+ exports.getWindowFrames = getWindowFrames;
@@ -1,6 +1,39 @@
1
- import {
2
- getWindowFrames
3
- } from "./chunk-UQ6OADW7.mjs";
4
- export {
5
- getWindowFrames
6
- };
1
+ function getWindowFrames(win) {
2
+ const frames = {
3
+ each(cb) {
4
+ for (let i = 0; i < win.frames?.length; i += 1) {
5
+ const frame = win.frames[i];
6
+ if (frame)
7
+ cb(frame);
8
+ }
9
+ },
10
+ addEventListener(event, listener, options) {
11
+ frames.each((frame) => {
12
+ try {
13
+ frame.document.addEventListener(event, listener, options);
14
+ } catch (err) {
15
+ console.warn(err);
16
+ }
17
+ });
18
+ return () => {
19
+ try {
20
+ frames.removeEventListener(event, listener, options);
21
+ } catch (err) {
22
+ console.warn(err);
23
+ }
24
+ };
25
+ },
26
+ removeEventListener(event, listener, options) {
27
+ frames.each((frame) => {
28
+ try {
29
+ frame.document.removeEventListener(event, listener, options);
30
+ } catch (err) {
31
+ console.warn(err);
32
+ }
33
+ });
34
+ }
35
+ };
36
+ return frames;
37
+ }
38
+
39
+ export { getWindowFrames };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- type InteractOutsideHandlers = {
1
+ export type InteractOutsideHandlers = {
2
2
  onPointerDownOutside?: (event: PointerDownOutsideEvent) => void;
3
3
  onFocusOutside?: (event: FocusOutsideEvent) => void;
4
4
  onInteractOutside?: (event: InteractOutsideEvent) => void;
5
5
  };
6
- type InteractOutsideOptions = InteractOutsideHandlers & {
6
+ export type InteractOutsideOptions = InteractOutsideHandlers & {
7
7
  exclude?: (target: HTMLElement) => boolean;
8
8
  defer?: boolean;
9
9
  };
@@ -12,11 +12,10 @@ type EventDetails<T> = {
12
12
  contextmenu: boolean;
13
13
  focusable: boolean;
14
14
  };
15
- type PointerDownOutsideEvent = CustomEvent<EventDetails<PointerEvent>>;
16
- type FocusOutsideEvent = CustomEvent<EventDetails<FocusEvent>>;
17
- type InteractOutsideEvent = PointerDownOutsideEvent | FocusOutsideEvent;
15
+ export type PointerDownOutsideEvent = CustomEvent<EventDetails<PointerEvent>>;
16
+ export type FocusOutsideEvent = CustomEvent<EventDetails<FocusEvent>>;
17
+ export type InteractOutsideEvent = PointerDownOutsideEvent | FocusOutsideEvent;
18
18
  type MaybeElement = HTMLElement | null | undefined;
19
19
  type NodeOrFn = MaybeElement | (() => MaybeElement);
20
- declare function trackInteractOutside(nodeOrFn: NodeOrFn, options: InteractOutsideOptions): () => void;
21
-
22
- export { FocusOutsideEvent, InteractOutsideEvent, InteractOutsideHandlers, InteractOutsideOptions, PointerDownOutsideEvent, trackInteractOutside };
20
+ export declare function trackInteractOutside(nodeOrFn: NodeOrFn, options: InteractOutsideOptions): () => void;
21
+ export {};
package/dist/index.js CHANGED
@@ -1,79 +1,19 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
19
2
 
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- trackInteractOutside: () => trackInteractOutside
24
- });
25
- module.exports = __toCommonJS(src_exports);
26
- var import_dom_event = require("@zag-js/dom-event");
27
- var import_dom_query = require("@zag-js/dom-query");
28
- var import_tabbable = require("@zag-js/tabbable");
29
- var import_utils = require("@zag-js/utils");
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
30
4
 
31
- // src/get-window-frames.ts
32
- function getWindowFrames(win) {
33
- const frames = {
34
- each(cb) {
35
- for (let i = 0; i < win.frames?.length; i += 1) {
36
- const frame = win.frames[i];
37
- if (frame)
38
- cb(frame);
39
- }
40
- },
41
- addEventListener(event, listener, options) {
42
- frames.each((frame) => {
43
- try {
44
- frame.document.addEventListener(event, listener, options);
45
- } catch (err) {
46
- console.warn(err);
47
- }
48
- });
49
- return () => {
50
- try {
51
- frames.removeEventListener(event, listener, options);
52
- } catch (err) {
53
- console.warn(err);
54
- }
55
- };
56
- },
57
- removeEventListener(event, listener, options) {
58
- frames.each((frame) => {
59
- try {
60
- frame.document.removeEventListener(event, listener, options);
61
- } catch (err) {
62
- console.warn(err);
63
- }
64
- });
65
- }
66
- };
67
- return frames;
68
- }
5
+ const domEvent = require('@zag-js/dom-event');
6
+ const domQuery = require('@zag-js/dom-query');
7
+ const tabbable = require('@zag-js/tabbable');
8
+ const utils = require('@zag-js/utils');
9
+ const getWindowFrames = require('./get-window-frames.js');
69
10
 
70
- // src/index.ts
71
- var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
72
- var FOCUS_OUTSIDE_EVENT = "focus.outside";
11
+ const POINTER_OUTSIDE_EVENT = "pointerdown.outside";
12
+ const FOCUS_OUTSIDE_EVENT = "focus.outside";
73
13
  function isComposedPathFocusable(event) {
74
14
  const composedPath = event.composedPath() ?? [event.target];
75
15
  for (const node of composedPath) {
76
- if ((0, import_dom_query.isHTMLElement)(node) && (0, import_tabbable.isFocusable)(node))
16
+ if (domQuery.isHTMLElement(node) && tabbable.isFocusable(node))
77
17
  return true;
78
18
  }
79
19
  return false;
@@ -82,15 +22,15 @@ function trackInteractOutsideImpl(node, options) {
82
22
  const { exclude, onFocusOutside, onPointerDownOutside, onInteractOutside } = options;
83
23
  if (!node)
84
24
  return;
85
- const doc = (0, import_dom_query.getDocument)(node);
86
- const win = (0, import_dom_query.getWindow)(node);
87
- const frames = getWindowFrames(win);
25
+ const doc = domQuery.getDocument(node);
26
+ const win = domQuery.getWindow(node);
27
+ const frames = getWindowFrames.getWindowFrames(win);
88
28
  function isEventOutside(event) {
89
- const target = (0, import_dom_query.getEventTarget)(event);
90
- if (!(0, import_dom_query.isHTMLElement)(target)) {
29
+ const target = domQuery.getEventTarget(event);
30
+ if (!domQuery.isHTMLElement(target)) {
91
31
  return false;
92
32
  }
93
- if ((0, import_dom_query.contains)(node, target)) {
33
+ if (domQuery.contains(node, target)) {
94
34
  return false;
95
35
  }
96
36
  return !exclude?.(target);
@@ -101,15 +41,15 @@ function trackInteractOutsideImpl(node, options) {
101
41
  if (!node || !isEventOutside(event))
102
42
  return;
103
43
  if (onPointerDownOutside || onInteractOutside) {
104
- const handler2 = (0, import_utils.callAll)(onPointerDownOutside, onInteractOutside);
44
+ const handler2 = utils.callAll(onPointerDownOutside, onInteractOutside);
105
45
  node.addEventListener(POINTER_OUTSIDE_EVENT, handler2, { once: true });
106
46
  }
107
- (0, import_dom_event.fireCustomEvent)(node, POINTER_OUTSIDE_EVENT, {
47
+ domEvent.fireCustomEvent(node, POINTER_OUTSIDE_EVENT, {
108
48
  bubbles: false,
109
49
  cancelable: true,
110
50
  detail: {
111
51
  originalEvent: event,
112
- contextmenu: (0, import_dom_event.isContextMenuEvent)(event),
52
+ contextmenu: domEvent.isContextMenuEvent(event),
113
53
  focusable: isComposedPathFocusable(event)
114
54
  }
115
55
  });
@@ -127,26 +67,26 @@ function trackInteractOutsideImpl(node, options) {
127
67
  const cleanups = /* @__PURE__ */ new Set();
128
68
  const timer = setTimeout(() => {
129
69
  cleanups.add(frames.addEventListener("pointerdown", onPointerDown, true));
130
- cleanups.add((0, import_dom_event.addDomEvent)(doc, "pointerdown", onPointerDown, true));
70
+ cleanups.add(domEvent.addDomEvent(doc, "pointerdown", onPointerDown, true));
131
71
  }, 0);
132
72
  function onFocusin(event) {
133
73
  if (!node || !isEventOutside(event))
134
74
  return;
135
75
  if (onFocusOutside || onInteractOutside) {
136
- const handler = (0, import_utils.callAll)(onFocusOutside, onInteractOutside);
76
+ const handler = utils.callAll(onFocusOutside, onInteractOutside);
137
77
  node.addEventListener(FOCUS_OUTSIDE_EVENT, handler, { once: true });
138
78
  }
139
- (0, import_dom_event.fireCustomEvent)(node, FOCUS_OUTSIDE_EVENT, {
79
+ domEvent.fireCustomEvent(node, FOCUS_OUTSIDE_EVENT, {
140
80
  bubbles: false,
141
81
  cancelable: true,
142
82
  detail: {
143
83
  originalEvent: event,
144
84
  contextmenu: false,
145
- focusable: (0, import_tabbable.isFocusable)((0, import_dom_query.getEventTarget)(event))
85
+ focusable: tabbable.isFocusable(domQuery.getEventTarget(event))
146
86
  }
147
87
  });
148
88
  }
149
- cleanups.add((0, import_dom_event.addDomEvent)(doc, "focusin", onFocusin, true));
89
+ cleanups.add(domEvent.addDomEvent(doc, "focusin", onFocusin, true));
150
90
  cleanups.add(frames.addEventListener("focusin", onFocusin, true));
151
91
  return () => {
152
92
  clearTimeout(timer);
@@ -159,7 +99,7 @@ function trackInteractOutsideImpl(node, options) {
159
99
  }
160
100
  function trackInteractOutside(nodeOrFn, options) {
161
101
  const { defer } = options;
162
- const func = defer ? import_dom_query.raf : (v) => v();
102
+ const func = defer ? domQuery.raf : (v) => v();
163
103
  const cleanups = [];
164
104
  cleanups.push(
165
105
  func(() => {
@@ -171,7 +111,5 @@ function trackInteractOutside(nodeOrFn, options) {
171
111
  cleanups.forEach((fn) => fn?.());
172
112
  };
173
113
  }
174
- // Annotate the CommonJS export names for ESM import in node:
175
- 0 && (module.exports = {
176
- trackInteractOutside
177
- });
114
+
115
+ exports.trackInteractOutside = trackInteractOutside;
package/dist/index.mjs CHANGED
@@ -1,14 +1,11 @@
1
- import {
2
- getWindowFrames
3
- } from "./chunk-UQ6OADW7.mjs";
1
+ import { addDomEvent, fireCustomEvent, isContextMenuEvent } from '@zag-js/dom-event';
2
+ import { getDocument, getWindow, raf, getEventTarget, isHTMLElement, contains } from '@zag-js/dom-query';
3
+ import { isFocusable } from '@zag-js/tabbable';
4
+ import { callAll } from '@zag-js/utils';
5
+ import { getWindowFrames } from './get-window-frames.mjs';
4
6
 
5
- // src/index.ts
6
- import { addDomEvent, fireCustomEvent, isContextMenuEvent } from "@zag-js/dom-event";
7
- import { contains, getDocument, getEventTarget, getWindow, isHTMLElement, raf } from "@zag-js/dom-query";
8
- import { isFocusable } from "@zag-js/tabbable";
9
- import { callAll } from "@zag-js/utils";
10
- var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
11
- var FOCUS_OUTSIDE_EVENT = "focus.outside";
7
+ const POINTER_OUTSIDE_EVENT = "pointerdown.outside";
8
+ const FOCUS_OUTSIDE_EVENT = "focus.outside";
12
9
  function isComposedPathFocusable(event) {
13
10
  const composedPath = event.composedPath() ?? [event.target];
14
11
  for (const node of composedPath) {
@@ -110,6 +107,5 @@ function trackInteractOutside(nodeOrFn, options) {
110
107
  cleanups.forEach((fn) => fn?.());
111
108
  };
112
109
  }
113
- export {
114
- trackInteractOutside
115
- };
110
+
111
+ export { trackInteractOutside };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/interact-outside",
3
- "version": "0.10.2",
3
+ "version": "0.10.4",
4
4
  "description": "Track interations or focus outside an element",
5
5
  "keywords": [
6
6
  "js",
@@ -17,10 +17,10 @@
17
17
  "src"
18
18
  ],
19
19
  "dependencies": {
20
- "@zag-js/dom-query": "0.10.2",
21
- "@zag-js/dom-event": "0.10.2",
22
- "@zag-js/tabbable": "0.10.2",
23
- "@zag-js/utils": "0.10.2"
20
+ "@zag-js/dom-query": "0.10.4",
21
+ "@zag-js/dom-event": "0.10.4",
22
+ "@zag-js/tabbable": "0.10.4",
23
+ "@zag-js/utils": "0.10.4"
24
24
  },
25
25
  "devDependencies": {
26
26
  "clean-package": "2.2.0"
@@ -44,9 +44,7 @@
44
44
  "./package.json": "./package.json"
45
45
  },
46
46
  "scripts": {
47
- "build-fast": "tsup src",
48
- "start": "pnpm build --watch",
49
- "build": "tsup src --dts",
47
+ "build": "vite build -c ../../../vite.config.ts",
50
48
  "test": "jest --config ../../../jest.config.js --rootDir tests",
51
49
  "lint": "eslint src --ext .ts,.tsx",
52
50
  "test-ci": "pnpm test --ci --runInBand -u",
@@ -1,42 +0,0 @@
1
- // src/get-window-frames.ts
2
- function getWindowFrames(win) {
3
- const frames = {
4
- each(cb) {
5
- for (let i = 0; i < win.frames?.length; i += 1) {
6
- const frame = win.frames[i];
7
- if (frame)
8
- cb(frame);
9
- }
10
- },
11
- addEventListener(event, listener, options) {
12
- frames.each((frame) => {
13
- try {
14
- frame.document.addEventListener(event, listener, options);
15
- } catch (err) {
16
- console.warn(err);
17
- }
18
- });
19
- return () => {
20
- try {
21
- frames.removeEventListener(event, listener, options);
22
- } catch (err) {
23
- console.warn(err);
24
- }
25
- };
26
- },
27
- removeEventListener(event, listener, options) {
28
- frames.each((frame) => {
29
- try {
30
- frame.document.removeEventListener(event, listener, options);
31
- } catch (err) {
32
- console.warn(err);
33
- }
34
- });
35
- }
36
- };
37
- return frames;
38
- }
39
-
40
- export {
41
- getWindowFrames
42
- };