@zag-js/interact-outside 0.2.0 → 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 +20 -8
- package/dist/index.mjs +20 -8
- 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,12 +24,21 @@ __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
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() {
|
|
35
44
|
var _a;
|
|
@@ -39,6 +48,8 @@ function getPlatform() {
|
|
|
39
48
|
var pt = (v) => isDom() && v.test(getPlatform());
|
|
40
49
|
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
41
50
|
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
51
|
+
|
|
52
|
+
// ../dom/src/query.ts
|
|
42
53
|
function isDocument(el) {
|
|
43
54
|
return el.nodeType === Node.DOCUMENT_NODE;
|
|
44
55
|
}
|
|
@@ -74,10 +85,14 @@ function isVisible(el) {
|
|
|
74
85
|
return false;
|
|
75
86
|
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
|
|
76
87
|
}
|
|
88
|
+
|
|
89
|
+
// ../dom/src/event.ts
|
|
77
90
|
var isContextMenuEvent = (e) => {
|
|
78
91
|
return e.button === 2 || isCtrlKey(e) && e.button === 0;
|
|
79
92
|
};
|
|
80
93
|
var isCtrlKey = (v) => isMac() ? v.metaKey && !v.ctrlKey : v.ctrlKey && !v.metaKey;
|
|
94
|
+
|
|
95
|
+
// ../dom/src/fire-event.ts
|
|
81
96
|
function fireCustomEvent(el, type, init) {
|
|
82
97
|
if (!el)
|
|
83
98
|
return;
|
|
@@ -85,12 +100,16 @@ function fireCustomEvent(el, type, init) {
|
|
|
85
100
|
const event = new win.CustomEvent(type, init);
|
|
86
101
|
return el.dispatchEvent(event);
|
|
87
102
|
}
|
|
103
|
+
|
|
104
|
+
// ../dom/src/focusable.ts
|
|
88
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";
|
|
89
106
|
function isFocusable(element) {
|
|
90
107
|
if (!element)
|
|
91
108
|
return false;
|
|
92
109
|
return element.matches(focusableSelector) && isVisible(element);
|
|
93
110
|
}
|
|
111
|
+
|
|
112
|
+
// ../dom/src/listener.ts
|
|
94
113
|
var isRef = (v) => hasProp(v, "current");
|
|
95
114
|
function addDomEvent(target, eventName, handler, options) {
|
|
96
115
|
const node = isRef(target) ? target.current : runIfFn(target);
|
|
@@ -100,13 +119,6 @@ function addDomEvent(target, eventName, handler, options) {
|
|
|
100
119
|
};
|
|
101
120
|
}
|
|
102
121
|
|
|
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
122
|
// src/index.ts
|
|
111
123
|
var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
|
|
112
124
|
var FOCUS_OUTSIDE_EVENT = "focus.outside";
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
// ../
|
|
1
|
+
// ../core/src/functions.ts
|
|
2
2
|
var runIfFn = (v, ...a) => {
|
|
3
3
|
const res = typeof v === "function" ? v(...a) : v;
|
|
4
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() {
|
|
9
18
|
var _a;
|
|
@@ -13,6 +22,8 @@ function getPlatform() {
|
|
|
13
22
|
var pt = (v) => isDom() && v.test(getPlatform());
|
|
14
23
|
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
15
24
|
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
25
|
+
|
|
26
|
+
// ../dom/src/query.ts
|
|
16
27
|
function isDocument(el) {
|
|
17
28
|
return el.nodeType === Node.DOCUMENT_NODE;
|
|
18
29
|
}
|
|
@@ -48,10 +59,14 @@ function isVisible(el) {
|
|
|
48
59
|
return false;
|
|
49
60
|
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
|
|
50
61
|
}
|
|
62
|
+
|
|
63
|
+
// ../dom/src/event.ts
|
|
51
64
|
var isContextMenuEvent = (e) => {
|
|
52
65
|
return e.button === 2 || isCtrlKey(e) && e.button === 0;
|
|
53
66
|
};
|
|
54
67
|
var isCtrlKey = (v) => isMac() ? v.metaKey && !v.ctrlKey : v.ctrlKey && !v.metaKey;
|
|
68
|
+
|
|
69
|
+
// ../dom/src/fire-event.ts
|
|
55
70
|
function fireCustomEvent(el, type, init) {
|
|
56
71
|
if (!el)
|
|
57
72
|
return;
|
|
@@ -59,12 +74,16 @@ function fireCustomEvent(el, type, init) {
|
|
|
59
74
|
const event = new win.CustomEvent(type, init);
|
|
60
75
|
return el.dispatchEvent(event);
|
|
61
76
|
}
|
|
77
|
+
|
|
78
|
+
// ../dom/src/focusable.ts
|
|
62
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";
|
|
63
80
|
function isFocusable(element) {
|
|
64
81
|
if (!element)
|
|
65
82
|
return false;
|
|
66
83
|
return element.matches(focusableSelector) && isVisible(element);
|
|
67
84
|
}
|
|
85
|
+
|
|
86
|
+
// ../dom/src/listener.ts
|
|
68
87
|
var isRef = (v) => hasProp(v, "current");
|
|
69
88
|
function addDomEvent(target, eventName, handler, options) {
|
|
70
89
|
const node = isRef(target) ? target.current : runIfFn(target);
|
|
@@ -74,13 +93,6 @@ function addDomEvent(target, eventName, handler, options) {
|
|
|
74
93
|
};
|
|
75
94
|
}
|
|
76
95
|
|
|
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
96
|
// src/index.ts
|
|
85
97
|
var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
|
|
86
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.2.
|
|
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.2.
|
|
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",
|