@zag-js/interact-outside 0.2.0 → 0.2.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 +6 -6
- package/dist/index.js +30 -22
- package/dist/index.mjs +30 -22
- package/package.json +18 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
type InteractOutsideHandlers = {
|
|
2
2
|
onPointerDownOutside?: (event: PointerDownOutsideEvent) => void;
|
|
3
3
|
onFocusOutside?: (event: FocusOutsideEvent) => void;
|
|
4
4
|
onInteractOutside?: (event: InteractOutsideEvent) => void;
|
|
5
5
|
};
|
|
6
|
-
|
|
6
|
+
type InteractOutsideOptions = InteractOutsideHandlers & {
|
|
7
7
|
exclude?: (target: HTMLElement) => boolean;
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
type EventDetails<T> = {
|
|
10
10
|
originalEvent: T;
|
|
11
11
|
contextmenu: boolean;
|
|
12
12
|
focusable: boolean;
|
|
13
13
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
type PointerDownOutsideEvent = CustomEvent<EventDetails<PointerEvent>>;
|
|
15
|
+
type FocusOutsideEvent = CustomEvent<EventDetails<FocusEvent>>;
|
|
16
|
+
type InteractOutsideEvent = PointerDownOutsideEvent | FocusOutsideEvent;
|
|
17
17
|
declare function trackInteractOutside(node: HTMLElement | null, options: InteractOutsideOptions): (() => void) | undefined;
|
|
18
18
|
|
|
19
19
|
export { FocusOutsideEvent, InteractOutsideEvent, InteractOutsideHandlers, InteractOutsideOptions, PointerDownOutsideEvent, trackInteractOutside };
|
package/dist/index.js
CHANGED
|
@@ -24,42 +24,49 @@ __export(src_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(src_exports);
|
|
26
26
|
|
|
27
|
-
// ../
|
|
27
|
+
// ../core/src/functions.ts
|
|
28
28
|
var runIfFn = (v, ...a) => {
|
|
29
29
|
const res = typeof v === "function" ? v(...a) : v;
|
|
30
|
-
return res
|
|
30
|
+
return res ?? void 0;
|
|
31
31
|
};
|
|
32
|
+
var callAll = (...fns) => (...a) => {
|
|
33
|
+
fns.forEach(function(fn) {
|
|
34
|
+
fn?.(...a);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// ../core/src/guard.ts
|
|
32
39
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
40
|
+
|
|
41
|
+
// ../dom/src/platform.ts
|
|
33
42
|
var isDom = () => typeof window !== "undefined";
|
|
34
43
|
function getPlatform() {
|
|
35
|
-
var _a;
|
|
36
44
|
const agent = navigator.userAgentData;
|
|
37
|
-
return
|
|
45
|
+
return agent?.platform ?? navigator.platform;
|
|
38
46
|
}
|
|
39
47
|
var pt = (v) => isDom() && v.test(getPlatform());
|
|
40
48
|
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
41
49
|
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
50
|
+
|
|
51
|
+
// ../dom/src/query.ts
|
|
42
52
|
function isDocument(el) {
|
|
43
53
|
return el.nodeType === Node.DOCUMENT_NODE;
|
|
44
54
|
}
|
|
45
55
|
function isWindow(value) {
|
|
46
|
-
return
|
|
56
|
+
return value?.toString() === "[object Window]";
|
|
47
57
|
}
|
|
48
58
|
function getDocument(el) {
|
|
49
|
-
var _a;
|
|
50
59
|
if (isWindow(el))
|
|
51
60
|
return el.document;
|
|
52
61
|
if (isDocument(el))
|
|
53
62
|
return el;
|
|
54
|
-
return
|
|
63
|
+
return el?.ownerDocument ?? document;
|
|
55
64
|
}
|
|
56
65
|
function getWindow(el) {
|
|
57
|
-
|
|
58
|
-
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
66
|
+
return el?.ownerDocument.defaultView ?? window;
|
|
59
67
|
}
|
|
60
68
|
function getEventTarget(event) {
|
|
61
|
-
|
|
62
|
-
return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
|
|
69
|
+
return event.composedPath?.()[0] ?? event.target;
|
|
63
70
|
}
|
|
64
71
|
function contains(parent, child) {
|
|
65
72
|
if (!parent)
|
|
@@ -67,17 +74,21 @@ function contains(parent, child) {
|
|
|
67
74
|
return parent === child || isHTMLElement(parent) && isHTMLElement(child) && parent.contains(child);
|
|
68
75
|
}
|
|
69
76
|
function isHTMLElement(v) {
|
|
70
|
-
return typeof v === "object" &&
|
|
77
|
+
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
|
|
71
78
|
}
|
|
72
79
|
function isVisible(el) {
|
|
73
80
|
if (!isHTMLElement(el))
|
|
74
81
|
return false;
|
|
75
82
|
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
|
|
76
83
|
}
|
|
84
|
+
|
|
85
|
+
// ../dom/src/event.ts
|
|
77
86
|
var isContextMenuEvent = (e) => {
|
|
78
87
|
return e.button === 2 || isCtrlKey(e) && e.button === 0;
|
|
79
88
|
};
|
|
80
89
|
var isCtrlKey = (v) => isMac() ? v.metaKey && !v.ctrlKey : v.ctrlKey && !v.metaKey;
|
|
90
|
+
|
|
91
|
+
// ../dom/src/fire-event.ts
|
|
81
92
|
function fireCustomEvent(el, type, init) {
|
|
82
93
|
if (!el)
|
|
83
94
|
return;
|
|
@@ -85,28 +96,25 @@ function fireCustomEvent(el, type, init) {
|
|
|
85
96
|
const event = new win.CustomEvent(type, init);
|
|
86
97
|
return el.dispatchEvent(event);
|
|
87
98
|
}
|
|
99
|
+
|
|
100
|
+
// ../dom/src/focusable.ts
|
|
88
101
|
var focusableSelector = "input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), details > summary:first-of-type";
|
|
89
102
|
function isFocusable(element) {
|
|
90
103
|
if (!element)
|
|
91
104
|
return false;
|
|
92
105
|
return element.matches(focusableSelector) && isVisible(element);
|
|
93
106
|
}
|
|
107
|
+
|
|
108
|
+
// ../dom/src/listener.ts
|
|
94
109
|
var isRef = (v) => hasProp(v, "current");
|
|
95
110
|
function addDomEvent(target, eventName, handler, options) {
|
|
96
111
|
const node = isRef(target) ? target.current : runIfFn(target);
|
|
97
|
-
node
|
|
112
|
+
node?.addEventListener(eventName, handler, options);
|
|
98
113
|
return () => {
|
|
99
|
-
node
|
|
114
|
+
node?.removeEventListener(eventName, handler, options);
|
|
100
115
|
};
|
|
101
116
|
}
|
|
102
117
|
|
|
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
|
-
|
|
110
118
|
// src/index.ts
|
|
111
119
|
var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
|
|
112
120
|
var FOCUS_OUTSIDE_EVENT = "focus.outside";
|
|
@@ -127,7 +135,7 @@ function trackInteractOutside(node, options) {
|
|
|
127
135
|
if (contains(node, target)) {
|
|
128
136
|
return false;
|
|
129
137
|
}
|
|
130
|
-
return !
|
|
138
|
+
return !exclude?.(target);
|
|
131
139
|
}
|
|
132
140
|
let clickHandler;
|
|
133
141
|
function onPointerDown(event) {
|
package/dist/index.mjs
CHANGED
|
@@ -1,39 +1,46 @@
|
|
|
1
|
-
// ../
|
|
1
|
+
// ../core/src/functions.ts
|
|
2
2
|
var runIfFn = (v, ...a) => {
|
|
3
3
|
const res = typeof v === "function" ? v(...a) : v;
|
|
4
|
-
return res
|
|
4
|
+
return res ?? void 0;
|
|
5
5
|
};
|
|
6
|
+
var callAll = (...fns) => (...a) => {
|
|
7
|
+
fns.forEach(function(fn) {
|
|
8
|
+
fn?.(...a);
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// ../core/src/guard.ts
|
|
6
13
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
14
|
+
|
|
15
|
+
// ../dom/src/platform.ts
|
|
7
16
|
var isDom = () => typeof window !== "undefined";
|
|
8
17
|
function getPlatform() {
|
|
9
|
-
var _a;
|
|
10
18
|
const agent = navigator.userAgentData;
|
|
11
|
-
return
|
|
19
|
+
return agent?.platform ?? navigator.platform;
|
|
12
20
|
}
|
|
13
21
|
var pt = (v) => isDom() && v.test(getPlatform());
|
|
14
22
|
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
15
23
|
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
24
|
+
|
|
25
|
+
// ../dom/src/query.ts
|
|
16
26
|
function isDocument(el) {
|
|
17
27
|
return el.nodeType === Node.DOCUMENT_NODE;
|
|
18
28
|
}
|
|
19
29
|
function isWindow(value) {
|
|
20
|
-
return
|
|
30
|
+
return value?.toString() === "[object Window]";
|
|
21
31
|
}
|
|
22
32
|
function getDocument(el) {
|
|
23
|
-
var _a;
|
|
24
33
|
if (isWindow(el))
|
|
25
34
|
return el.document;
|
|
26
35
|
if (isDocument(el))
|
|
27
36
|
return el;
|
|
28
|
-
return
|
|
37
|
+
return el?.ownerDocument ?? document;
|
|
29
38
|
}
|
|
30
39
|
function getWindow(el) {
|
|
31
|
-
|
|
32
|
-
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
40
|
+
return el?.ownerDocument.defaultView ?? window;
|
|
33
41
|
}
|
|
34
42
|
function getEventTarget(event) {
|
|
35
|
-
|
|
36
|
-
return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
|
|
43
|
+
return event.composedPath?.()[0] ?? event.target;
|
|
37
44
|
}
|
|
38
45
|
function contains(parent, child) {
|
|
39
46
|
if (!parent)
|
|
@@ -41,17 +48,21 @@ function contains(parent, child) {
|
|
|
41
48
|
return parent === child || isHTMLElement(parent) && isHTMLElement(child) && parent.contains(child);
|
|
42
49
|
}
|
|
43
50
|
function isHTMLElement(v) {
|
|
44
|
-
return typeof v === "object" &&
|
|
51
|
+
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
|
|
45
52
|
}
|
|
46
53
|
function isVisible(el) {
|
|
47
54
|
if (!isHTMLElement(el))
|
|
48
55
|
return false;
|
|
49
56
|
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
|
|
50
57
|
}
|
|
58
|
+
|
|
59
|
+
// ../dom/src/event.ts
|
|
51
60
|
var isContextMenuEvent = (e) => {
|
|
52
61
|
return e.button === 2 || isCtrlKey(e) && e.button === 0;
|
|
53
62
|
};
|
|
54
63
|
var isCtrlKey = (v) => isMac() ? v.metaKey && !v.ctrlKey : v.ctrlKey && !v.metaKey;
|
|
64
|
+
|
|
65
|
+
// ../dom/src/fire-event.ts
|
|
55
66
|
function fireCustomEvent(el, type, init) {
|
|
56
67
|
if (!el)
|
|
57
68
|
return;
|
|
@@ -59,28 +70,25 @@ function fireCustomEvent(el, type, init) {
|
|
|
59
70
|
const event = new win.CustomEvent(type, init);
|
|
60
71
|
return el.dispatchEvent(event);
|
|
61
72
|
}
|
|
73
|
+
|
|
74
|
+
// ../dom/src/focusable.ts
|
|
62
75
|
var focusableSelector = "input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), details > summary:first-of-type";
|
|
63
76
|
function isFocusable(element) {
|
|
64
77
|
if (!element)
|
|
65
78
|
return false;
|
|
66
79
|
return element.matches(focusableSelector) && isVisible(element);
|
|
67
80
|
}
|
|
81
|
+
|
|
82
|
+
// ../dom/src/listener.ts
|
|
68
83
|
var isRef = (v) => hasProp(v, "current");
|
|
69
84
|
function addDomEvent(target, eventName, handler, options) {
|
|
70
85
|
const node = isRef(target) ? target.current : runIfFn(target);
|
|
71
|
-
node
|
|
86
|
+
node?.addEventListener(eventName, handler, options);
|
|
72
87
|
return () => {
|
|
73
|
-
node
|
|
88
|
+
node?.removeEventListener(eventName, handler, options);
|
|
74
89
|
};
|
|
75
90
|
}
|
|
76
91
|
|
|
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
|
-
|
|
84
92
|
// src/index.ts
|
|
85
93
|
var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
|
|
86
94
|
var FOCUS_OUTSIDE_EVENT = "focus.outside";
|
|
@@ -101,7 +109,7 @@ function trackInteractOutside(node, options) {
|
|
|
101
109
|
if (contains(node, target)) {
|
|
102
110
|
return false;
|
|
103
111
|
}
|
|
104
|
-
return !
|
|
112
|
+
return !exclude?.(target);
|
|
105
113
|
}
|
|
106
114
|
let clickHandler;
|
|
107
115
|
function onPointerDown(event) {
|
package/package.json
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/interact-outside",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Track interations or focus outside an element",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
5
|
"keywords": [
|
|
9
6
|
"js",
|
|
10
7
|
"utils",
|
|
@@ -19,8 +16,9 @@
|
|
|
19
16
|
"dist/**/*"
|
|
20
17
|
],
|
|
21
18
|
"devDependencies": {
|
|
22
|
-
"
|
|
23
|
-
"@zag-js/utils": "0.2.
|
|
19
|
+
"clean-package": "2.2.0",
|
|
20
|
+
"@zag-js/dom-utils": "0.2.4",
|
|
21
|
+
"@zag-js/utils": "0.3.3"
|
|
24
22
|
},
|
|
25
23
|
"publishConfig": {
|
|
26
24
|
"access": "public"
|
|
@@ -28,10 +26,22 @@
|
|
|
28
26
|
"bugs": {
|
|
29
27
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
28
|
},
|
|
29
|
+
"clean-package": "../../../clean-package.config.json",
|
|
30
|
+
"main": "dist/index.js",
|
|
31
|
+
"module": "dist/index.mjs",
|
|
32
|
+
"types": "dist/index.d.ts",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"import": "./dist/index.mjs",
|
|
37
|
+
"require": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
31
41
|
"scripts": {
|
|
32
|
-
"build-fast": "tsup src
|
|
42
|
+
"build-fast": "tsup src",
|
|
33
43
|
"start": "pnpm build --watch",
|
|
34
|
-
"build": "tsup src
|
|
44
|
+
"build": "tsup src --dts",
|
|
35
45
|
"test": "jest --config ../../../jest.config.js --rootDir tests",
|
|
36
46
|
"lint": "eslint src --ext .ts,.tsx",
|
|
37
47
|
"test-ci": "pnpm test --ci --runInBand -u",
|