@zag-js/interact-outside 0.1.1 → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +2 -5
- package/dist/index.d.ts +9 -7
- package/dist/index.js +29 -14
- package/dist/index.mjs +25 -14
- package/package.json +14 -13
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Chakra UI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -12,11 +12,8 @@ npm i @zag-js/interact-outside
|
|
|
12
12
|
|
|
13
13
|
## Contribution
|
|
14
14
|
|
|
15
|
-
Yes please! See the
|
|
16
|
-
[contributing guidelines](https://github.com/chakra-ui/zag/blob/main/CONTRIBUTING.md)
|
|
17
|
-
for details.
|
|
15
|
+
Yes please! See the [contributing guidelines](https://github.com/chakra-ui/zag/blob/main/CONTRIBUTING.md) for details.
|
|
18
16
|
|
|
19
17
|
## Licence
|
|
20
18
|
|
|
21
|
-
This project is licensed under the terms of the
|
|
22
|
-
[MIT license](https://github.com/chakra-ui/zag/blob/main/LICENSE).
|
|
19
|
+
This project is licensed under the terms of the [MIT license](https://github.com/chakra-ui/zag/blob/main/LICENSE).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
declare type InteractOutsideHandlers = {
|
|
2
2
|
onPointerDownOutside?: (event: PointerDownOutsideEvent) => void;
|
|
3
3
|
onFocusOutside?: (event: FocusOutsideEvent) => void;
|
|
4
|
+
onInteractOutside?: (event: InteractOutsideEvent) => void;
|
|
4
5
|
};
|
|
5
|
-
|
|
6
|
+
declare type InteractOutsideOptions = InteractOutsideHandlers & {
|
|
6
7
|
exclude?: (target: HTMLElement) => boolean;
|
|
7
8
|
};
|
|
8
9
|
declare type EventDetails<T> = {
|
|
@@ -10,8 +11,9 @@ declare type EventDetails<T> = {
|
|
|
10
11
|
contextmenu: boolean;
|
|
11
12
|
focusable: boolean;
|
|
12
13
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
declare type PointerDownOutsideEvent = CustomEvent<EventDetails<PointerEvent>>;
|
|
15
|
+
declare type FocusOutsideEvent = CustomEvent<EventDetails<FocusEvent>>;
|
|
16
|
+
declare type InteractOutsideEvent = PointerDownOutsideEvent | FocusOutsideEvent;
|
|
17
|
+
declare function trackInteractOutside(node: HTMLElement | null, options: InteractOutsideOptions): (() => void) | undefined;
|
|
18
|
+
|
|
19
|
+
export { FocusOutsideEvent, InteractOutsideEvent, InteractOutsideHandlers, InteractOutsideOptions, PointerDownOutsideEvent, trackInteractOutside };
|
package/dist/index.js
CHANGED
|
@@ -27,34 +27,36 @@ module.exports = __toCommonJS(src_exports);
|
|
|
27
27
|
// ../dom/dist/index.mjs
|
|
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
32
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
33
33
|
var isDom = () => typeof window !== "undefined";
|
|
34
34
|
function getPlatform() {
|
|
35
|
-
var _a;
|
|
36
35
|
const agent = navigator.userAgentData;
|
|
37
|
-
return (
|
|
36
|
+
return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
|
|
38
37
|
}
|
|
39
38
|
var pt = (v) => isDom() && v.test(getPlatform());
|
|
40
39
|
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
41
40
|
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
41
|
+
function isDocument(el) {
|
|
42
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
43
|
+
}
|
|
42
44
|
function isWindow(value) {
|
|
43
45
|
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
44
46
|
}
|
|
45
47
|
function getDocument(el) {
|
|
46
|
-
var _a;
|
|
47
48
|
if (isWindow(el))
|
|
48
49
|
return el.document;
|
|
49
|
-
|
|
50
|
+
if (isDocument(el))
|
|
51
|
+
return el;
|
|
52
|
+
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
50
53
|
}
|
|
51
54
|
function getWindow(el) {
|
|
52
|
-
|
|
53
|
-
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
55
|
+
return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
|
|
54
56
|
}
|
|
55
57
|
function getEventTarget(event) {
|
|
56
|
-
var _a
|
|
57
|
-
return (
|
|
58
|
+
var _a;
|
|
59
|
+
return ((_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) ?? event.target;
|
|
58
60
|
}
|
|
59
61
|
function contains(parent, child) {
|
|
60
62
|
if (!parent)
|
|
@@ -95,11 +97,18 @@ function addDomEvent(target, eventName, handler, options) {
|
|
|
95
97
|
};
|
|
96
98
|
}
|
|
97
99
|
|
|
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
|
+
|
|
98
107
|
// src/index.ts
|
|
99
108
|
var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
|
|
100
109
|
var FOCUS_OUTSIDE_EVENT = "focus.outside";
|
|
101
110
|
function trackInteractOutside(node, options) {
|
|
102
|
-
const { exclude, onFocusOutside, onPointerDownOutside } = options;
|
|
111
|
+
const { exclude, onFocusOutside, onPointerDownOutside, onInteractOutside } = options;
|
|
103
112
|
if (!node)
|
|
104
113
|
return;
|
|
105
114
|
const doc = getDocument(node);
|
|
@@ -122,8 +131,9 @@ function trackInteractOutside(node, options) {
|
|
|
122
131
|
function handler() {
|
|
123
132
|
if (!node || !isEventOutside(event))
|
|
124
133
|
return;
|
|
125
|
-
if (onPointerDownOutside) {
|
|
126
|
-
|
|
134
|
+
if (onPointerDownOutside || onInteractOutside) {
|
|
135
|
+
const handler2 = callAll(onPointerDownOutside, onInteractOutside);
|
|
136
|
+
node.addEventListener(POINTER_OUTSIDE_EVENT, handler2, { once: true });
|
|
127
137
|
}
|
|
128
138
|
fireCustomEvent(node, POINTER_OUTSIDE_EVENT, {
|
|
129
139
|
bubbles: false,
|
|
@@ -150,8 +160,9 @@ function trackInteractOutside(node, options) {
|
|
|
150
160
|
function onFocusin(event) {
|
|
151
161
|
if (!node || !isEventOutside(event))
|
|
152
162
|
return;
|
|
153
|
-
if (onFocusOutside) {
|
|
154
|
-
|
|
163
|
+
if (onFocusOutside || onInteractOutside) {
|
|
164
|
+
const handler = callAll(onFocusOutside, onInteractOutside);
|
|
165
|
+
node.addEventListener(FOCUS_OUTSIDE_EVENT, handler, { once: true });
|
|
155
166
|
}
|
|
156
167
|
fireCustomEvent(node, FOCUS_OUTSIDE_EVENT, {
|
|
157
168
|
bubbles: false,
|
|
@@ -171,3 +182,7 @@ function trackInteractOutside(node, options) {
|
|
|
171
182
|
cleanups.forEach((fn) => fn());
|
|
172
183
|
};
|
|
173
184
|
}
|
|
185
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
186
|
+
0 && (module.exports = {
|
|
187
|
+
trackInteractOutside
|
|
188
|
+
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,34 +1,36 @@
|
|
|
1
1
|
// ../dom/dist/index.mjs
|
|
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
6
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
7
7
|
var isDom = () => typeof window !== "undefined";
|
|
8
8
|
function getPlatform() {
|
|
9
|
-
var _a;
|
|
10
9
|
const agent = navigator.userAgentData;
|
|
11
|
-
return (
|
|
10
|
+
return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
|
|
12
11
|
}
|
|
13
12
|
var pt = (v) => isDom() && v.test(getPlatform());
|
|
14
13
|
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
15
14
|
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
15
|
+
function isDocument(el) {
|
|
16
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
17
|
+
}
|
|
16
18
|
function isWindow(value) {
|
|
17
19
|
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
18
20
|
}
|
|
19
21
|
function getDocument(el) {
|
|
20
|
-
var _a;
|
|
21
22
|
if (isWindow(el))
|
|
22
23
|
return el.document;
|
|
23
|
-
|
|
24
|
+
if (isDocument(el))
|
|
25
|
+
return el;
|
|
26
|
+
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
24
27
|
}
|
|
25
28
|
function getWindow(el) {
|
|
26
|
-
|
|
27
|
-
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
29
|
+
return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
|
|
28
30
|
}
|
|
29
31
|
function getEventTarget(event) {
|
|
30
|
-
var _a
|
|
31
|
-
return (
|
|
32
|
+
var _a;
|
|
33
|
+
return ((_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) ?? event.target;
|
|
32
34
|
}
|
|
33
35
|
function contains(parent, child) {
|
|
34
36
|
if (!parent)
|
|
@@ -69,11 +71,18 @@ function addDomEvent(target, eventName, handler, options) {
|
|
|
69
71
|
};
|
|
70
72
|
}
|
|
71
73
|
|
|
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
|
+
|
|
72
81
|
// src/index.ts
|
|
73
82
|
var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
|
|
74
83
|
var FOCUS_OUTSIDE_EVENT = "focus.outside";
|
|
75
84
|
function trackInteractOutside(node, options) {
|
|
76
|
-
const { exclude, onFocusOutside, onPointerDownOutside } = options;
|
|
85
|
+
const { exclude, onFocusOutside, onPointerDownOutside, onInteractOutside } = options;
|
|
77
86
|
if (!node)
|
|
78
87
|
return;
|
|
79
88
|
const doc = getDocument(node);
|
|
@@ -96,8 +105,9 @@ function trackInteractOutside(node, options) {
|
|
|
96
105
|
function handler() {
|
|
97
106
|
if (!node || !isEventOutside(event))
|
|
98
107
|
return;
|
|
99
|
-
if (onPointerDownOutside) {
|
|
100
|
-
|
|
108
|
+
if (onPointerDownOutside || onInteractOutside) {
|
|
109
|
+
const handler2 = callAll(onPointerDownOutside, onInteractOutside);
|
|
110
|
+
node.addEventListener(POINTER_OUTSIDE_EVENT, handler2, { once: true });
|
|
101
111
|
}
|
|
102
112
|
fireCustomEvent(node, POINTER_OUTSIDE_EVENT, {
|
|
103
113
|
bubbles: false,
|
|
@@ -124,8 +134,9 @@ function trackInteractOutside(node, options) {
|
|
|
124
134
|
function onFocusin(event) {
|
|
125
135
|
if (!node || !isEventOutside(event))
|
|
126
136
|
return;
|
|
127
|
-
if (onFocusOutside) {
|
|
128
|
-
|
|
137
|
+
if (onFocusOutside || onInteractOutside) {
|
|
138
|
+
const handler = callAll(onFocusOutside, onInteractOutside);
|
|
139
|
+
node.addEventListener(FOCUS_OUTSIDE_EVENT, handler, { once: true });
|
|
129
140
|
}
|
|
130
141
|
fireCustomEvent(node, FOCUS_OUTSIDE_EVENT, {
|
|
131
142
|
bubbles: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/interact-outside",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Track interations or focus outside an element",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -18,22 +18,23 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"dist/**/*"
|
|
20
20
|
],
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"build": "yarn zag build --prod",
|
|
25
|
-
"test": "jest --config ../../../jest.config.js --rootDir tests",
|
|
26
|
-
"lint": "eslint src --ext .ts,.tsx",
|
|
27
|
-
"test:ci": "yarn test --ci --runInBand --updateSnapshot",
|
|
28
|
-
"test:watch": "yarn test --watchAll"
|
|
29
|
-
},
|
|
30
|
-
"dependencies": {
|
|
31
|
-
"@zag-js/dom-utils": "0.1.6"
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@zag-js/dom-utils": "0.1.11",
|
|
23
|
+
"@zag-js/utils": "0.1.4"
|
|
32
24
|
},
|
|
33
25
|
"publishConfig": {
|
|
34
26
|
"access": "public"
|
|
35
27
|
},
|
|
36
28
|
"bugs": {
|
|
37
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build-fast": "tsup src/index.ts --format=esm,cjs",
|
|
33
|
+
"start": "pnpm build --watch",
|
|
34
|
+
"build": "tsup src/index.ts --format=esm,cjs --dts",
|
|
35
|
+
"test": "jest --config ../../../jest.config.js --rootDir tests",
|
|
36
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
37
|
+
"test-ci": "pnpm test --ci --runInBand -u",
|
|
38
|
+
"test-watch": "pnpm test --watchAll"
|
|
38
39
|
}
|
|
39
|
-
}
|
|
40
|
+
}
|