@zag-js/interact-outside 0.1.6 → 0.2.1
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 +29 -14
- package/dist/index.mjs +29 -14
- 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,20 +24,32 @@ __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 != null ? res : void 0;
|
|
31
31
|
};
|
|
32
|
+
var callAll = (...fns) => (...a) => {
|
|
33
|
+
fns.forEach(function(fn) {
|
|
34
|
+
fn == null ? void 0 : 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() {
|
|
44
|
+
var _a;
|
|
35
45
|
const agent = navigator.userAgentData;
|
|
36
|
-
return (agent == null ? void 0 : agent.platform)
|
|
46
|
+
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
37
47
|
}
|
|
38
48
|
var pt = (v) => isDom() && v.test(getPlatform());
|
|
39
49
|
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
40
50
|
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
51
|
+
|
|
52
|
+
// ../dom/src/query.ts
|
|
41
53
|
function isDocument(el) {
|
|
42
54
|
return el.nodeType === Node.DOCUMENT_NODE;
|
|
43
55
|
}
|
|
@@ -45,18 +57,20 @@ function isWindow(value) {
|
|
|
45
57
|
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
46
58
|
}
|
|
47
59
|
function getDocument(el) {
|
|
60
|
+
var _a;
|
|
48
61
|
if (isWindow(el))
|
|
49
62
|
return el.document;
|
|
50
63
|
if (isDocument(el))
|
|
51
64
|
return el;
|
|
52
|
-
return (el == null ? void 0 : el.ownerDocument)
|
|
65
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
53
66
|
}
|
|
54
67
|
function getWindow(el) {
|
|
55
|
-
|
|
68
|
+
var _a;
|
|
69
|
+
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
56
70
|
}
|
|
57
71
|
function getEventTarget(event) {
|
|
58
|
-
var _a;
|
|
59
|
-
return ((_a = event.composedPath) == null ? void 0 : _a.call(event)[0])
|
|
72
|
+
var _a, _b;
|
|
73
|
+
return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
|
|
60
74
|
}
|
|
61
75
|
function contains(parent, child) {
|
|
62
76
|
if (!parent)
|
|
@@ -71,10 +85,14 @@ function isVisible(el) {
|
|
|
71
85
|
return false;
|
|
72
86
|
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
|
|
73
87
|
}
|
|
88
|
+
|
|
89
|
+
// ../dom/src/event.ts
|
|
74
90
|
var isContextMenuEvent = (e) => {
|
|
75
91
|
return e.button === 2 || isCtrlKey(e) && e.button === 0;
|
|
76
92
|
};
|
|
77
93
|
var isCtrlKey = (v) => isMac() ? v.metaKey && !v.ctrlKey : v.ctrlKey && !v.metaKey;
|
|
94
|
+
|
|
95
|
+
// ../dom/src/fire-event.ts
|
|
78
96
|
function fireCustomEvent(el, type, init) {
|
|
79
97
|
if (!el)
|
|
80
98
|
return;
|
|
@@ -82,12 +100,16 @@ function fireCustomEvent(el, type, init) {
|
|
|
82
100
|
const event = new win.CustomEvent(type, init);
|
|
83
101
|
return el.dispatchEvent(event);
|
|
84
102
|
}
|
|
103
|
+
|
|
104
|
+
// ../dom/src/focusable.ts
|
|
85
105
|
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";
|
|
86
106
|
function isFocusable(element) {
|
|
87
107
|
if (!element)
|
|
88
108
|
return false;
|
|
89
109
|
return element.matches(focusableSelector) && isVisible(element);
|
|
90
110
|
}
|
|
111
|
+
|
|
112
|
+
// ../dom/src/listener.ts
|
|
91
113
|
var isRef = (v) => hasProp(v, "current");
|
|
92
114
|
function addDomEvent(target, eventName, handler, options) {
|
|
93
115
|
const node = isRef(target) ? target.current : runIfFn(target);
|
|
@@ -97,13 +119,6 @@ function addDomEvent(target, eventName, handler, options) {
|
|
|
97
119
|
};
|
|
98
120
|
}
|
|
99
121
|
|
|
100
|
-
// ../core/dist/index.mjs
|
|
101
|
-
var callAll = (...fns) => (...a) => {
|
|
102
|
-
fns.forEach(function(fn) {
|
|
103
|
-
fn == null ? void 0 : fn(...a);
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
|
|
107
122
|
// src/index.ts
|
|
108
123
|
var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
|
|
109
124
|
var FOCUS_OUTSIDE_EVENT = "focus.outside";
|
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
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 != null ? res : void 0;
|
|
5
5
|
};
|
|
6
|
+
var callAll = (...fns) => (...a) => {
|
|
7
|
+
fns.forEach(function(fn) {
|
|
8
|
+
fn == null ? void 0 : 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() {
|
|
18
|
+
var _a;
|
|
9
19
|
const agent = navigator.userAgentData;
|
|
10
|
-
return (agent == null ? void 0 : agent.platform)
|
|
20
|
+
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
11
21
|
}
|
|
12
22
|
var pt = (v) => isDom() && v.test(getPlatform());
|
|
13
23
|
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
14
24
|
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
25
|
+
|
|
26
|
+
// ../dom/src/query.ts
|
|
15
27
|
function isDocument(el) {
|
|
16
28
|
return el.nodeType === Node.DOCUMENT_NODE;
|
|
17
29
|
}
|
|
@@ -19,18 +31,20 @@ function isWindow(value) {
|
|
|
19
31
|
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
20
32
|
}
|
|
21
33
|
function getDocument(el) {
|
|
34
|
+
var _a;
|
|
22
35
|
if (isWindow(el))
|
|
23
36
|
return el.document;
|
|
24
37
|
if (isDocument(el))
|
|
25
38
|
return el;
|
|
26
|
-
return (el == null ? void 0 : el.ownerDocument)
|
|
39
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
27
40
|
}
|
|
28
41
|
function getWindow(el) {
|
|
29
|
-
|
|
42
|
+
var _a;
|
|
43
|
+
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
30
44
|
}
|
|
31
45
|
function getEventTarget(event) {
|
|
32
|
-
var _a;
|
|
33
|
-
return ((_a = event.composedPath) == null ? void 0 : _a.call(event)[0])
|
|
46
|
+
var _a, _b;
|
|
47
|
+
return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
|
|
34
48
|
}
|
|
35
49
|
function contains(parent, child) {
|
|
36
50
|
if (!parent)
|
|
@@ -45,10 +59,14 @@ function isVisible(el) {
|
|
|
45
59
|
return false;
|
|
46
60
|
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
|
|
47
61
|
}
|
|
62
|
+
|
|
63
|
+
// ../dom/src/event.ts
|
|
48
64
|
var isContextMenuEvent = (e) => {
|
|
49
65
|
return e.button === 2 || isCtrlKey(e) && e.button === 0;
|
|
50
66
|
};
|
|
51
67
|
var isCtrlKey = (v) => isMac() ? v.metaKey && !v.ctrlKey : v.ctrlKey && !v.metaKey;
|
|
68
|
+
|
|
69
|
+
// ../dom/src/fire-event.ts
|
|
52
70
|
function fireCustomEvent(el, type, init) {
|
|
53
71
|
if (!el)
|
|
54
72
|
return;
|
|
@@ -56,12 +74,16 @@ function fireCustomEvent(el, type, init) {
|
|
|
56
74
|
const event = new win.CustomEvent(type, init);
|
|
57
75
|
return el.dispatchEvent(event);
|
|
58
76
|
}
|
|
77
|
+
|
|
78
|
+
// ../dom/src/focusable.ts
|
|
59
79
|
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";
|
|
60
80
|
function isFocusable(element) {
|
|
61
81
|
if (!element)
|
|
62
82
|
return false;
|
|
63
83
|
return element.matches(focusableSelector) && isVisible(element);
|
|
64
84
|
}
|
|
85
|
+
|
|
86
|
+
// ../dom/src/listener.ts
|
|
65
87
|
var isRef = (v) => hasProp(v, "current");
|
|
66
88
|
function addDomEvent(target, eventName, handler, options) {
|
|
67
89
|
const node = isRef(target) ? target.current : runIfFn(target);
|
|
@@ -71,13 +93,6 @@ function addDomEvent(target, eventName, handler, options) {
|
|
|
71
93
|
};
|
|
72
94
|
}
|
|
73
95
|
|
|
74
|
-
// ../core/dist/index.mjs
|
|
75
|
-
var callAll = (...fns) => (...a) => {
|
|
76
|
-
fns.forEach(function(fn) {
|
|
77
|
-
fn == null ? void 0 : fn(...a);
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
|
|
81
96
|
// src/index.ts
|
|
82
97
|
var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
|
|
83
98
|
var FOCUS_OUTSIDE_EVENT = "focus.outside";
|
package/package.json
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/interact-outside",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
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.
|
|
19
|
+
"clean-package": "2.2.0",
|
|
20
|
+
"@zag-js/dom-utils": "0.2.2",
|
|
21
|
+
"@zag-js/utils": "0.3.2"
|
|
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",
|