@tamagui/floating 2.0.0-rc.3 → 2.0.0-rc.31
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/cjs/Floating.native.js +4 -0
- package/dist/cjs/Floating.native.js.map +1 -1
- package/dist/cjs/index.cjs +33 -2
- package/dist/cjs/index.native.js +33 -2
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/interactions/PopupTriggerMap.cjs +40 -0
- package/dist/cjs/interactions/PopupTriggerMap.native.js +73 -0
- package/dist/cjs/interactions/PopupTriggerMap.native.js.map +1 -0
- package/dist/cjs/interactions/createFloatingEvents.cjs +41 -0
- package/dist/cjs/interactions/createFloatingEvents.native.js +47 -0
- package/dist/cjs/interactions/createFloatingEvents.native.js.map +1 -0
- package/dist/cjs/interactions/safePolygon.cjs +191 -0
- package/dist/cjs/interactions/safePolygon.native.js +205 -0
- package/dist/cjs/interactions/safePolygon.native.js.map +1 -0
- package/dist/cjs/interactions/types.cjs +16 -0
- package/dist/cjs/interactions/types.native.js +19 -0
- package/dist/cjs/interactions/types.native.js.map +1 -0
- package/dist/cjs/interactions/useClick.cjs +82 -0
- package/dist/cjs/interactions/useClick.native.js +90 -0
- package/dist/cjs/interactions/useClick.native.js.map +1 -0
- package/dist/cjs/interactions/useDelayGroup.cjs +96 -0
- package/dist/cjs/interactions/useDelayGroup.native.js +109 -0
- package/dist/cjs/interactions/useDelayGroup.native.js.map +1 -0
- package/dist/cjs/interactions/useFocus.cjs +101 -0
- package/dist/cjs/interactions/useFocus.native.js +113 -0
- package/dist/cjs/interactions/useFocus.native.js.map +1 -0
- package/dist/cjs/interactions/useHover.cjs +224 -0
- package/dist/cjs/interactions/useHover.native.js +248 -0
- package/dist/cjs/interactions/useHover.native.js.map +1 -0
- package/dist/cjs/interactions/useInnerOffset.cjs +104 -0
- package/dist/cjs/interactions/useInnerOffset.native.js +118 -0
- package/dist/cjs/interactions/useInnerOffset.native.js.map +1 -0
- package/dist/cjs/interactions/useInteractions.cjs +76 -0
- package/dist/cjs/interactions/useInteractions.native.js +164 -0
- package/dist/cjs/interactions/useInteractions.native.js.map +1 -0
- package/dist/cjs/interactions/useListNavigation.cjs +253 -0
- package/dist/cjs/interactions/useListNavigation.native.js +297 -0
- package/dist/cjs/interactions/useListNavigation.native.js.map +1 -0
- package/dist/cjs/interactions/useRole.cjs +112 -0
- package/dist/cjs/interactions/useRole.native.js +128 -0
- package/dist/cjs/interactions/useRole.native.js.map +1 -0
- package/dist/cjs/interactions/useTypeahead.cjs +93 -0
- package/dist/cjs/interactions/useTypeahead.native.js +114 -0
- package/dist/cjs/interactions/useTypeahead.native.js.map +1 -0
- package/dist/cjs/interactions/utils.cjs +178 -0
- package/dist/cjs/interactions/utils.native.js +188 -0
- package/dist/cjs/interactions/utils.native.js.map +1 -0
- package/dist/cjs/middleware/inner.cjs +106 -0
- package/dist/cjs/middleware/inner.native.js +120 -0
- package/dist/cjs/middleware/inner.native.js.map +1 -0
- package/dist/cjs/useFloating.cjs +21 -17
- package/dist/cjs/useFloating.native.js +2 -0
- package/dist/cjs/useFloating.native.js.map +1 -1
- package/dist/esm/Floating.native.js +4 -1
- package/dist/esm/Floating.native.js.map +1 -1
- package/dist/esm/index.js +17 -34
- package/dist/esm/index.js.map +1 -6
- package/dist/esm/index.mjs +16 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +16 -2
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/interactions/PopupTriggerMap.mjs +17 -0
- package/dist/esm/interactions/PopupTriggerMap.mjs.map +1 -0
- package/dist/esm/interactions/PopupTriggerMap.native.js +47 -0
- package/dist/esm/interactions/PopupTriggerMap.native.js.map +1 -0
- package/dist/esm/interactions/createFloatingEvents.mjs +18 -0
- package/dist/esm/interactions/createFloatingEvents.mjs.map +1 -0
- package/dist/esm/interactions/createFloatingEvents.native.js +21 -0
- package/dist/esm/interactions/createFloatingEvents.native.js.map +1 -0
- package/dist/esm/interactions/safePolygon.mjs +168 -0
- package/dist/esm/interactions/safePolygon.mjs.map +1 -0
- package/dist/esm/interactions/safePolygon.native.js +179 -0
- package/dist/esm/interactions/safePolygon.native.js.map +1 -0
- package/dist/esm/interactions/types.mjs +2 -0
- package/dist/esm/interactions/types.mjs.map +1 -0
- package/dist/esm/interactions/types.native.js +2 -0
- package/dist/esm/interactions/types.native.js.map +1 -0
- package/dist/esm/interactions/useClick.mjs +59 -0
- package/dist/esm/interactions/useClick.mjs.map +1 -0
- package/dist/esm/interactions/useClick.native.js +64 -0
- package/dist/esm/interactions/useClick.native.js.map +1 -0
- package/dist/esm/interactions/useDelayGroup.mjs +60 -0
- package/dist/esm/interactions/useDelayGroup.mjs.map +1 -0
- package/dist/esm/interactions/useDelayGroup.native.js +70 -0
- package/dist/esm/interactions/useDelayGroup.native.js.map +1 -0
- package/dist/esm/interactions/useFocus.mjs +78 -0
- package/dist/esm/interactions/useFocus.mjs.map +1 -0
- package/dist/esm/interactions/useFocus.native.js +87 -0
- package/dist/esm/interactions/useFocus.native.js.map +1 -0
- package/dist/esm/interactions/useHover.mjs +189 -0
- package/dist/esm/interactions/useHover.mjs.map +1 -0
- package/dist/esm/interactions/useHover.native.js +210 -0
- package/dist/esm/interactions/useHover.native.js.map +1 -0
- package/dist/esm/interactions/useInnerOffset.mjs +70 -0
- package/dist/esm/interactions/useInnerOffset.mjs.map +1 -0
- package/dist/esm/interactions/useInnerOffset.native.js +81 -0
- package/dist/esm/interactions/useInnerOffset.native.js.map +1 -0
- package/dist/esm/interactions/useInteractions.mjs +53 -0
- package/dist/esm/interactions/useInteractions.mjs.map +1 -0
- package/dist/esm/interactions/useInteractions.native.js +138 -0
- package/dist/esm/interactions/useInteractions.native.js.map +1 -0
- package/dist/esm/interactions/useListNavigation.mjs +230 -0
- package/dist/esm/interactions/useListNavigation.mjs.map +1 -0
- package/dist/esm/interactions/useListNavigation.native.js +271 -0
- package/dist/esm/interactions/useListNavigation.native.js.map +1 -0
- package/dist/esm/interactions/useRole.mjs +78 -0
- package/dist/esm/interactions/useRole.mjs.map +1 -0
- package/dist/esm/interactions/useRole.native.js +91 -0
- package/dist/esm/interactions/useRole.native.js.map +1 -0
- package/dist/esm/interactions/useTypeahead.mjs +70 -0
- package/dist/esm/interactions/useTypeahead.mjs.map +1 -0
- package/dist/esm/interactions/useTypeahead.native.js +88 -0
- package/dist/esm/interactions/useTypeahead.native.js.map +1 -0
- package/dist/esm/interactions/utils.mjs +134 -0
- package/dist/esm/interactions/utils.mjs.map +1 -0
- package/dist/esm/interactions/utils.native.js +141 -0
- package/dist/esm/interactions/utils.native.js.map +1 -0
- package/dist/esm/middleware/inner.mjs +72 -0
- package/dist/esm/middleware/inner.mjs.map +1 -0
- package/dist/esm/middleware/inner.native.js +83 -0
- package/dist/esm/middleware/inner.native.js.map +1 -0
- package/dist/esm/useFloating.mjs +21 -17
- package/dist/esm/useFloating.mjs.map +1 -1
- package/dist/esm/useFloating.native.js +2 -0
- package/dist/esm/useFloating.native.js.map +1 -1
- package/package.json +8 -10
- package/src/Floating.native.tsx +1 -0
- package/src/index.ts +49 -0
- package/src/interactions/PopupTriggerMap.ts +30 -0
- package/src/interactions/createFloatingEvents.ts +34 -0
- package/src/interactions/safePolygon.ts +500 -0
- package/src/interactions/types.ts +165 -0
- package/src/interactions/useClick.ts +148 -0
- package/src/interactions/useDelayGroup.ts +114 -0
- package/src/interactions/useFocus.ts +164 -0
- package/src/interactions/useHover.ts +453 -0
- package/src/interactions/useInnerOffset.ts +116 -0
- package/src/interactions/useInteractions.ts +101 -0
- package/src/interactions/useListNavigation.ts +578 -0
- package/src/interactions/useRole.ts +103 -0
- package/src/interactions/useTypeahead.ts +173 -0
- package/src/interactions/utils.ts +234 -0
- package/src/middleware/inner.ts +142 -0
- package/src/useFloating.tsx +13 -1
- package/types/Floating.native.d.ts +1 -0
- package/types/Floating.native.d.ts.map +1 -1
- package/types/index.d.ts +17 -2
- package/types/index.d.ts.map +1 -1
- package/types/interactions/PopupTriggerMap.d.ts +8 -0
- package/types/interactions/PopupTriggerMap.d.ts.map +1 -0
- package/types/interactions/createFloatingEvents.d.ts +7 -0
- package/types/interactions/createFloatingEvents.d.ts.map +1 -0
- package/types/interactions/safePolygon.d.ts +4 -0
- package/types/interactions/safePolygon.d.ts.map +1 -0
- package/types/interactions/types.d.ts +123 -0
- package/types/interactions/types.d.ts.map +1 -0
- package/types/interactions/useClick.d.ts +3 -0
- package/types/interactions/useClick.d.ts.map +1 -0
- package/types/interactions/useDelayGroup.d.ts +23 -0
- package/types/interactions/useDelayGroup.d.ts.map +1 -0
- package/types/interactions/useFocus.d.ts +3 -0
- package/types/interactions/useFocus.d.ts.map +1 -0
- package/types/interactions/useHover.d.ts +6 -0
- package/types/interactions/useHover.d.ts.map +1 -0
- package/types/interactions/useInnerOffset.d.ts +3 -0
- package/types/interactions/useInnerOffset.d.ts.map +1 -0
- package/types/interactions/useInteractions.d.ts +8 -0
- package/types/interactions/useInteractions.d.ts.map +1 -0
- package/types/interactions/useListNavigation.d.ts +3 -0
- package/types/interactions/useListNavigation.d.ts.map +1 -0
- package/types/interactions/useRole.d.ts +3 -0
- package/types/interactions/useRole.d.ts.map +1 -0
- package/types/interactions/useTypeahead.d.ts +3 -0
- package/types/interactions/useTypeahead.d.ts.map +1 -0
- package/types/interactions/utils.d.ts +46 -0
- package/types/interactions/utils.d.ts.map +1 -0
- package/types/middleware/inner.d.ts +14 -0
- package/types/middleware/inner.d.ts.map +1 -0
- package/types/useFloating.d.ts +7 -1
- package/types/useFloating.d.ts.map +1 -1
- package/dist/cjs/Floating.js +0 -15
- package/dist/cjs/Floating.js.map +0 -6
- package/dist/cjs/index.js +0 -34
- package/dist/cjs/index.js.map +0 -6
- package/dist/cjs/useFloating.js +0 -46
- package/dist/cjs/useFloating.js.map +0 -6
- package/dist/esm/Floating.js +0 -2
- package/dist/esm/Floating.js.map +0 -6
- package/dist/esm/useFloating.js +0 -23
- package/dist/esm/useFloating.js.map +0 -6
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: !0
|
|
22
|
+
}), mod);
|
|
23
|
+
var safePolygon_exports = {};
|
|
24
|
+
__export(safePolygon_exports, {
|
|
25
|
+
safePolygon: () => safePolygon
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(safePolygon_exports);
|
|
28
|
+
var import_utils = require("./utils.native.js");
|
|
29
|
+
function isPointInPolygon(point, polygon) {
|
|
30
|
+
for (var [x, y] = point, isInside2 = !1, length = polygon.length, i = 0, j = length - 1; i < length; j = i++) {
|
|
31
|
+
var [xi, yi] = polygon[i] || [0, 0],
|
|
32
|
+
[xj, yj] = polygon[j] || [0, 0],
|
|
33
|
+
intersect = yi >= y != yj >= y && x <= (xj - xi) * (y - yi) / (yj - yi) + xi;
|
|
34
|
+
intersect && (isInside2 = !isInside2);
|
|
35
|
+
}
|
|
36
|
+
return isInside2;
|
|
37
|
+
}
|
|
38
|
+
function isInside(point, rect) {
|
|
39
|
+
return point[0] >= rect.x && point[0] <= rect.x + rect.width && point[1] >= rect.y && point[1] <= rect.y + rect.height;
|
|
40
|
+
}
|
|
41
|
+
var debugSvg = null;
|
|
42
|
+
function debugDrawPolygon(polygon, trough, cursor, anchor) {
|
|
43
|
+
if (debugSvg || (debugSvg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), debugSvg.id = "__safe-polygon-debug", Object.assign(debugSvg.style, {
|
|
44
|
+
position: "fixed",
|
|
45
|
+
inset: "0",
|
|
46
|
+
width: "100vw",
|
|
47
|
+
height: "100vh",
|
|
48
|
+
pointerEvents: "none",
|
|
49
|
+
zIndex: "999999"
|
|
50
|
+
}), document.body.appendChild(debugSvg)), debugSvg.innerHTML = "", trough.length) {
|
|
51
|
+
var troughEl = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
|
|
52
|
+
troughEl.setAttribute("points", trough.map(function (p) {
|
|
53
|
+
return p.join(",");
|
|
54
|
+
}).join(" ")), troughEl.setAttribute("fill", "rgba(0,100,255,0.15)"), troughEl.setAttribute("stroke", "rgba(0,100,255,0.6)"), troughEl.setAttribute("stroke-width", "1"), debugSvg.appendChild(troughEl);
|
|
55
|
+
}
|
|
56
|
+
if (polygon.length) {
|
|
57
|
+
var polyEl = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
|
|
58
|
+
polyEl.setAttribute("points", polygon.map(function (p) {
|
|
59
|
+
return p.join(",");
|
|
60
|
+
}).join(" ")), polyEl.setAttribute("fill", "rgba(255,50,50,0.2)"), polyEl.setAttribute("stroke", "rgba(255,50,50,0.8)"), polyEl.setAttribute("stroke-width", "1.5"), debugSvg.appendChild(polyEl);
|
|
61
|
+
}
|
|
62
|
+
var anchorCircle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
63
|
+
anchorCircle.setAttribute("cx", String(anchor[0])), anchorCircle.setAttribute("cy", String(anchor[1])), anchorCircle.setAttribute("r", "5"), anchorCircle.setAttribute("fill", "lime"), anchorCircle.setAttribute("stroke", "darkgreen"), anchorCircle.setAttribute("stroke-width", "1.5"), debugSvg.appendChild(anchorCircle);
|
|
64
|
+
var cursorCircle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
65
|
+
cursorCircle.setAttribute("cx", String(cursor[0])), cursorCircle.setAttribute("cy", String(cursor[1])), cursorCircle.setAttribute("r", "4"), cursorCircle.setAttribute("fill", "yellow"), cursorCircle.setAttribute("stroke", "orange"), cursorCircle.setAttribute("stroke-width", "1.5"), debugSvg.appendChild(cursorCircle);
|
|
66
|
+
}
|
|
67
|
+
function debugClear() {
|
|
68
|
+
debugSvg && (debugSvg.remove(), debugSvg = null);
|
|
69
|
+
}
|
|
70
|
+
function safePolygon() {
|
|
71
|
+
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {},
|
|
72
|
+
{
|
|
73
|
+
buffer = 0.5,
|
|
74
|
+
blockPointerEvents = !1,
|
|
75
|
+
requireIntent = !0,
|
|
76
|
+
__debug = !1
|
|
77
|
+
} = options,
|
|
78
|
+
timeoutRef = {
|
|
79
|
+
current: -1
|
|
80
|
+
},
|
|
81
|
+
hasLanded = !1,
|
|
82
|
+
lastX = null,
|
|
83
|
+
lastY = null,
|
|
84
|
+
lastCursorTime = typeof performance < "u" ? performance.now() : 0;
|
|
85
|
+
function getCursorSpeed(x, y) {
|
|
86
|
+
var currentTime = performance.now(),
|
|
87
|
+
elapsedTime = currentTime - lastCursorTime;
|
|
88
|
+
if (lastX === null || lastY === null || elapsedTime === 0) return lastX = x, lastY = y, lastCursorTime = currentTime, null;
|
|
89
|
+
var deltaX = x - lastX,
|
|
90
|
+
deltaY = y - lastY,
|
|
91
|
+
distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY),
|
|
92
|
+
speed = distance / elapsedTime;
|
|
93
|
+
return lastX = x, lastY = y, lastCursorTime = currentTime, speed;
|
|
94
|
+
}
|
|
95
|
+
var fn = function (param) {
|
|
96
|
+
var {
|
|
97
|
+
x,
|
|
98
|
+
y,
|
|
99
|
+
placement,
|
|
100
|
+
elements,
|
|
101
|
+
onClose
|
|
102
|
+
} = param;
|
|
103
|
+
return hasLanded = !1, lastX = null, lastY = null, function (event) {
|
|
104
|
+
function close() {
|
|
105
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutRef), onClose();
|
|
106
|
+
}
|
|
107
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutRef);
|
|
108
|
+
var _elements_domReference,
|
|
109
|
+
domReference = (_elements_domReference = elements.domReference) !== null && _elements_domReference !== void 0 ? _elements_domReference : elements.reference;
|
|
110
|
+
if (!domReference || !elements.floating || placement == null || x == null || y == null) return;
|
|
111
|
+
var {
|
|
112
|
+
clientX,
|
|
113
|
+
clientY
|
|
114
|
+
} = event,
|
|
115
|
+
clientPoint = [clientX, clientY],
|
|
116
|
+
target = (0, import_utils.getTarget)(event),
|
|
117
|
+
isLeave = event.type === "mouseleave",
|
|
118
|
+
isOverFloatingEl = (0, import_utils.contains)(elements.floating, target),
|
|
119
|
+
isOverReferenceEl = (0, import_utils.contains)(domReference, target),
|
|
120
|
+
refRect = domReference.getBoundingClientRect(),
|
|
121
|
+
rect = elements.floating.getBoundingClientRect(),
|
|
122
|
+
side = placement.split("-")[0],
|
|
123
|
+
cursorLeaveFromRight = x > rect.right - rect.width / 2,
|
|
124
|
+
cursorLeaveFromBottom = y > rect.bottom - rect.height / 2,
|
|
125
|
+
isOverReferenceRect = isInside(clientPoint, refRect),
|
|
126
|
+
isFloatingWider = rect.width > refRect.width,
|
|
127
|
+
isFloatingTaller = rect.height > refRect.height,
|
|
128
|
+
left = (isFloatingWider ? refRect : rect).left,
|
|
129
|
+
right = (isFloatingWider ? refRect : rect).right,
|
|
130
|
+
top = (isFloatingTaller ? refRect : rect).top,
|
|
131
|
+
bottom = (isFloatingTaller ? refRect : rect).bottom;
|
|
132
|
+
if (isOverFloatingEl && (hasLanded = !0, !isLeave)) return;
|
|
133
|
+
if (isOverReferenceEl && (hasLanded = !1), isOverReferenceEl && !isLeave) {
|
|
134
|
+
hasLanded = !0;
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (!isOverReferenceEl && isOverReferenceRect && !isLeave || isLeave && event.relatedTarget && (0, import_utils.contains)(elements.floating, event.relatedTarget)) return;
|
|
138
|
+
if (side === "top" && y >= refRect.bottom - 1 || side === "bottom" && y <= refRect.top + 1 || side === "left" && x >= refRect.right - 1 || side === "right" && x <= refRect.left + 1) return close();
|
|
139
|
+
var rectPoly = [];
|
|
140
|
+
switch (side) {
|
|
141
|
+
case "top":
|
|
142
|
+
rectPoly = [[left, refRect.top + 1], [left, rect.bottom - 1], [right, rect.bottom - 1], [right, refRect.top + 1]];
|
|
143
|
+
break;
|
|
144
|
+
case "bottom":
|
|
145
|
+
rectPoly = [[left, rect.top + 1], [left, refRect.bottom - 1], [right, refRect.bottom - 1], [right, rect.top + 1]];
|
|
146
|
+
break;
|
|
147
|
+
case "left":
|
|
148
|
+
rectPoly = [[rect.right - 1, bottom], [rect.right - 1, top], [refRect.left + 1, top], [refRect.left + 1, bottom]];
|
|
149
|
+
break;
|
|
150
|
+
case "right":
|
|
151
|
+
rectPoly = [[refRect.right - 1, bottom], [refRect.right - 1, top], [rect.left + 1, top], [rect.left + 1, bottom]];
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
function getPolygon(param2) {
|
|
155
|
+
var [x2, y2] = param2;
|
|
156
|
+
switch (side) {
|
|
157
|
+
case "top":
|
|
158
|
+
{
|
|
159
|
+
var cursorPointOne = [isFloatingWider ? x2 + buffer / 2 : cursorLeaveFromRight ? x2 + buffer * 4 : x2 - buffer * 4, y2 + buffer + 1],
|
|
160
|
+
cursorPointTwo = [isFloatingWider ? x2 - buffer / 2 : cursorLeaveFromRight ? x2 + buffer * 4 : x2 - buffer * 4, y2 + buffer + 1],
|
|
161
|
+
commonPoints = [[rect.left, cursorLeaveFromRight || isFloatingWider ? rect.bottom - buffer : rect.top], [rect.right, cursorLeaveFromRight ? isFloatingWider ? rect.bottom - buffer : rect.top : rect.bottom - buffer]];
|
|
162
|
+
return [cursorPointOne, cursorPointTwo, ...commonPoints];
|
|
163
|
+
}
|
|
164
|
+
case "bottom":
|
|
165
|
+
{
|
|
166
|
+
var cursorPointOne1 = [isFloatingWider ? x2 + buffer / 2 : cursorLeaveFromRight ? x2 + buffer * 4 : x2 - buffer * 4, y2 - buffer],
|
|
167
|
+
cursorPointTwo1 = [isFloatingWider ? x2 - buffer / 2 : cursorLeaveFromRight ? x2 + buffer * 4 : x2 - buffer * 4, y2 - buffer],
|
|
168
|
+
commonPoints1 = [[rect.left, cursorLeaveFromRight || isFloatingWider ? rect.top + buffer : rect.bottom], [rect.right, cursorLeaveFromRight ? isFloatingWider ? rect.top + buffer : rect.bottom : rect.top + buffer]];
|
|
169
|
+
return [cursorPointOne1, cursorPointTwo1, ...commonPoints1];
|
|
170
|
+
}
|
|
171
|
+
case "left":
|
|
172
|
+
{
|
|
173
|
+
var cursorPointOne2 = [x2 + buffer + 1, isFloatingTaller ? y2 + buffer / 2 : cursorLeaveFromBottom ? y2 + buffer * 4 : y2 - buffer * 4],
|
|
174
|
+
cursorPointTwo2 = [x2 + buffer + 1, isFloatingTaller ? y2 - buffer / 2 : cursorLeaveFromBottom ? y2 + buffer * 4 : y2 - buffer * 4],
|
|
175
|
+
commonPoints2 = [[cursorLeaveFromBottom || isFloatingTaller ? rect.right - buffer : rect.left, rect.top], [cursorLeaveFromBottom ? isFloatingTaller ? rect.right - buffer : rect.left : rect.right - buffer, rect.bottom]];
|
|
176
|
+
return [...commonPoints2, cursorPointOne2, cursorPointTwo2];
|
|
177
|
+
}
|
|
178
|
+
case "right":
|
|
179
|
+
{
|
|
180
|
+
var cursorPointOne3 = [x2 - buffer, isFloatingTaller ? y2 + buffer / 2 : cursorLeaveFromBottom ? y2 + buffer * 4 : y2 - buffer * 4],
|
|
181
|
+
cursorPointTwo3 = [x2 - buffer, isFloatingTaller ? y2 - buffer / 2 : cursorLeaveFromBottom ? y2 + buffer * 4 : y2 - buffer * 4],
|
|
182
|
+
commonPoints3 = [[cursorLeaveFromBottom || isFloatingTaller ? rect.left + buffer : rect.right, rect.top], [cursorLeaveFromBottom ? isFloatingTaller ? rect.left + buffer : rect.right : rect.left + buffer, rect.bottom]];
|
|
183
|
+
return [cursorPointOne3, cursorPointTwo3, ...commonPoints3];
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
var poly = getPolygon([x, y]);
|
|
188
|
+
if (__debug && debugDrawPolygon(poly, rectPoly, clientPoint, [x, y]), !isPointInPolygon([clientX, clientY], rectPoly)) {
|
|
189
|
+
if (hasLanded && !isOverReferenceRect) return __debug && debugClear(), close();
|
|
190
|
+
if (!isPointInPolygon([clientX, clientY], poly)) {
|
|
191
|
+
if (!isLeave && requireIntent) {
|
|
192
|
+
var cursorSpeed = getCursorSpeed(clientX, clientY),
|
|
193
|
+
cursorSpeedThreshold = 0.1;
|
|
194
|
+
if (cursorSpeed !== null && cursorSpeed < cursorSpeedThreshold) return __debug && debugClear(), close();
|
|
195
|
+
}
|
|
196
|
+
__debug && debugClear(), close();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
return fn.__options = {
|
|
202
|
+
blockPointerEvents
|
|
203
|
+
}, fn;
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=safePolygon.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","safePolygon_exports","__export","safePolygon","module","exports","import_utils","require","isPointInPolygon","point","polygon","x","y","isInside2","length","i","j","xi","yi","xj","yj","intersect","isInside","rect","width","height","debugSvg","debugDrawPolygon","trough","cursor","anchor","document","createElementNS","id","Object","assign","style","position","inset","pointerEvents","zIndex","body","appendChild","innerHTML","troughEl","setAttribute","map","p","join","polyEl","anchorCircle","String","cursorCircle","debugClear","remove","options","arguments","buffer","blockPointerEvents","requireIntent","__debug","timeoutRef","current","hasLanded","lastX","lastY","lastCursorTime","performance","now","getCursorSpeed","currentTime","elapsedTime","deltaX","deltaY","distance","Math","sqrt","speed","fn","param","placement","elements","onClose","event","close","clearTimeoutIfSet","_elements_domReference","domReference","reference","floating","clientX","clientY","clientPoint","target","getTarget","isLeave","type","isOverFloatingEl","contains","isOverReferenceEl","refRect","getBoundingClientRect","side","split","cursorLeaveFromRight","right","cursorLeaveFromBottom","bottom","isOverReferenceRect","isFloatingWider","isFloatingTaller","left","top","relatedTarget","rectPoly","getPolygon","param2","x2","y2","cursorPointOne","cursorPointTwo","commonPoints","cursorPointOne1","cursorPointTwo1","commonPoints1"],"sources":["../../../src/interactions/safePolygon.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,mBAAA;AAAAC,QAAA,CAAAD,mBAAA;EAAAE,WAAA,EAAAA,CAAA,KAAAA;AAAA;AACAC,MAAA,CAAAC,OAAA,GAAAT,YAAuD,CAAAK,mBAAA;AAOvD,IAAAK,YAAS,GAAAC,OAAiB,oBAAc;AACtC,SAAOC,gBAAQA,CAAAC,KAAA,EAAAC,OAAA;EACf,KAAI,KAAAC,CAAA,EAAAC,CAAA,IAAWH,KAAA,EAAAI,SAAA,OAAAC,MAAA,GAAAJ,OAAA,CAAAI,MAAA,EAAAC,CAAA,MAAAC,CAAA,GAAAF,MAAA,MAAAC,CAAA,GAAAD,MAAA,EAAAE,CAAA,GAAAD,CAAA;IACf,IAAM,CAAAE,EAAA,EAAAC,EAAA,IAASR,OAAQ,CAAAK,CAAA,MACvB,GACE,EAEkB;MAAA,CAAAI,EAAM,EAAAC,EAAA,CAAM,GAAAV,OAAM,CAAKM,CAAA,KAAO,CAIlD,GACA,EACF;MAAAK,SAAA,GAAAH,EAAA,IAAAN,CAAA,IAAAQ,EAAA,IAAA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F,CAEA;cACF,QACF8D,cAAA,EACFC,cAAA,EAEM,GAAOC,YAAY,CAErB;YAQA;UACF,KAAI;YAAA;cAUF,IAAAC,eAAkB,IAKjBb,eAAW,GAAAQ,EAAA,GAAA5D,MAAe,OAAA+C,oBAAA,GAAAa,EAAA,GAAA5D,MAAA,OAAA4D,EAAA,GAAA5D,MAAA,MAC7B6D,EAAM,GAAA7D,MAAA,CAEN;gBAAIkE,eAAgB,IAClBd,eAAI,GAASQ,EAAA,GAAA5D,MAAW,GACjB,IAAM+C,oBAAA,GAAAa,EAAA,GAAA5D,MAAA,OAAA4D,EAAA,GAAA5D,MAAA,MAEjB6D,EAAA,GAAA7D,MAAA,CAGI;gBAAAmE,aAAS,GAAW,CAClB,CAAArG,IAAA,CAAAwF,IAAA,EACRP,oBAAA,IAAAK,eAAA,GAAAtF,IAAA,CAAAyF,GAAA,GAAAvD,MAAA,GAAAlC,IAAA,CAAAoF,MAAA,CAGC,EACD,CAGKpF,IAAA,CAAAkF,KAAA,EACTD,oBAAA,GAAAK,eAAA,GAAAtF,IAAA,CAAAyF,GAAA,GAAAvD,MAAA,GAAAlC,IAAA,CAAAoF,MAAA,GAAApF,IAAA,CAAAyF,GAAA,GAAAvD,MAAA,C","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
7
|
+
get: () => from[key],
|
|
8
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
|
+
});
|
|
10
|
+
return to;
|
|
11
|
+
};
|
|
12
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
13
|
+
value: !0
|
|
14
|
+
}), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
9
|
+
get: () => from[key],
|
|
10
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
11
|
+
});
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
15
|
+
value: !0
|
|
16
|
+
}), mod);
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
19
|
+
//# sourceMappingURL=types.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","types_exports"],"sources":["../../../src/interactions/types.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var useClick_exports = {};
|
|
22
|
+
__export(useClick_exports, {
|
|
23
|
+
useClick: () => useClick
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(useClick_exports);
|
|
26
|
+
var import_react = require("react"),
|
|
27
|
+
import_utils = require("./utils.cjs");
|
|
28
|
+
function isButtonTarget(event) {
|
|
29
|
+
return (0, import_utils.isHTMLElement)(event.target) && event.target.tagName === "BUTTON";
|
|
30
|
+
}
|
|
31
|
+
function isAnchorTarget(event) {
|
|
32
|
+
return (0, import_utils.isHTMLElement)(event.target) && event.target.tagName === "A";
|
|
33
|
+
}
|
|
34
|
+
function isSpaceIgnored(element) {
|
|
35
|
+
return (0, import_utils.isTypeableElement)(element);
|
|
36
|
+
}
|
|
37
|
+
function useClick(context, props = {}) {
|
|
38
|
+
const {
|
|
39
|
+
open,
|
|
40
|
+
onOpenChange,
|
|
41
|
+
dataRef,
|
|
42
|
+
elements: {
|
|
43
|
+
domReference
|
|
44
|
+
}
|
|
45
|
+
} = context,
|
|
46
|
+
{
|
|
47
|
+
enabled = !0,
|
|
48
|
+
event: eventOption = "click",
|
|
49
|
+
toggle = !0,
|
|
50
|
+
ignoreMouse = !1,
|
|
51
|
+
keyboardHandlers = !0,
|
|
52
|
+
stickIfOpen = !0
|
|
53
|
+
} = props,
|
|
54
|
+
pointerTypeRef = (0, import_react.useRef)(void 0),
|
|
55
|
+
didKeyDownRef = (0, import_react.useRef)(!1),
|
|
56
|
+
reference = (0, import_react.useMemo)(() => ({
|
|
57
|
+
onPointerDown(event) {
|
|
58
|
+
pointerTypeRef.current = event.pointerType;
|
|
59
|
+
},
|
|
60
|
+
onMouseDown(event) {
|
|
61
|
+
const pointerType = pointerTypeRef.current;
|
|
62
|
+
event.button === 0 && eventOption !== "click" && ((0, import_utils.isMouseLikePointerType)(pointerType, !0) && ignoreMouse || (open && toggle && (!(dataRef.current.openEvent && stickIfOpen) || dataRef.current.openEvent.type === "mousedown") ? onOpenChange(!1, event.nativeEvent || event, "click") : (event.preventDefault(), onOpenChange(!0, event.nativeEvent || event, "click"))));
|
|
63
|
+
},
|
|
64
|
+
onClick(event) {
|
|
65
|
+
const pointerType = pointerTypeRef.current;
|
|
66
|
+
if (eventOption === "mousedown" && pointerTypeRef.current) {
|
|
67
|
+
pointerTypeRef.current = void 0;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
(0, import_utils.isMouseLikePointerType)(pointerType, !0) && ignoreMouse || (open && toggle && (!(dataRef.current.openEvent && stickIfOpen) || dataRef.current.openEvent.type === "click") ? onOpenChange(!1, event.nativeEvent || event, "click") : onOpenChange(!0, event.nativeEvent || event, "click"));
|
|
71
|
+
},
|
|
72
|
+
onKeyDown(event) {
|
|
73
|
+
pointerTypeRef.current = void 0, !(event.defaultPrevented || !keyboardHandlers || isButtonTarget(event)) && (event.key === " " && !isSpaceIgnored(domReference) && (event.preventDefault(), didKeyDownRef.current = !0), !isAnchorTarget(event) && event.key === "Enter" && onOpenChange(!(open && toggle), event.nativeEvent || event, "click"));
|
|
74
|
+
},
|
|
75
|
+
onKeyUp(event) {
|
|
76
|
+
event.defaultPrevented || !keyboardHandlers || isButtonTarget(event) || isSpaceIgnored(domReference) || event.key === " " && didKeyDownRef.current && (didKeyDownRef.current = !1, onOpenChange(!(open && toggle), event.nativeEvent || event, "click"));
|
|
77
|
+
}
|
|
78
|
+
}), [dataRef, domReference, eventOption, ignoreMouse, keyboardHandlers, onOpenChange, open, stickIfOpen, toggle]);
|
|
79
|
+
return (0, import_react.useMemo)(() => enabled ? {
|
|
80
|
+
reference
|
|
81
|
+
} : {}, [enabled, reference]);
|
|
82
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: !0
|
|
22
|
+
}), mod);
|
|
23
|
+
var useClick_exports = {};
|
|
24
|
+
__export(useClick_exports, {
|
|
25
|
+
useClick: () => useClick
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(useClick_exports);
|
|
28
|
+
var import_react = require("react"),
|
|
29
|
+
import_utils = require("./utils.native.js");
|
|
30
|
+
function isButtonTarget(event) {
|
|
31
|
+
return (0, import_utils.isHTMLElement)(event.target) && event.target.tagName === "BUTTON";
|
|
32
|
+
}
|
|
33
|
+
function isAnchorTarget(event) {
|
|
34
|
+
return (0, import_utils.isHTMLElement)(event.target) && event.target.tagName === "A";
|
|
35
|
+
}
|
|
36
|
+
function isSpaceIgnored(element) {
|
|
37
|
+
return (0, import_utils.isTypeableElement)(element);
|
|
38
|
+
}
|
|
39
|
+
function useClick(context) {
|
|
40
|
+
var props = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {},
|
|
41
|
+
{
|
|
42
|
+
open,
|
|
43
|
+
onOpenChange,
|
|
44
|
+
dataRef,
|
|
45
|
+
elements: {
|
|
46
|
+
domReference
|
|
47
|
+
}
|
|
48
|
+
} = context,
|
|
49
|
+
{
|
|
50
|
+
enabled = !0,
|
|
51
|
+
event: eventOption = "click",
|
|
52
|
+
toggle = !0,
|
|
53
|
+
ignoreMouse = !1,
|
|
54
|
+
keyboardHandlers = !0,
|
|
55
|
+
stickIfOpen = !0
|
|
56
|
+
} = props,
|
|
57
|
+
pointerTypeRef = (0, import_react.useRef)(void 0),
|
|
58
|
+
didKeyDownRef = (0, import_react.useRef)(!1),
|
|
59
|
+
reference = (0, import_react.useMemo)(function () {
|
|
60
|
+
return {
|
|
61
|
+
onPointerDown(event) {
|
|
62
|
+
pointerTypeRef.current = event.pointerType;
|
|
63
|
+
},
|
|
64
|
+
onMouseDown(event) {
|
|
65
|
+
var pointerType = pointerTypeRef.current;
|
|
66
|
+
event.button === 0 && eventOption !== "click" && ((0, import_utils.isMouseLikePointerType)(pointerType, !0) && ignoreMouse || (open && toggle && (!(dataRef.current.openEvent && stickIfOpen) || dataRef.current.openEvent.type === "mousedown") ? onOpenChange(!1, event.nativeEvent || event, "click") : (event.preventDefault(), onOpenChange(!0, event.nativeEvent || event, "click"))));
|
|
67
|
+
},
|
|
68
|
+
onClick(event) {
|
|
69
|
+
var pointerType = pointerTypeRef.current;
|
|
70
|
+
if (eventOption === "mousedown" && pointerTypeRef.current) {
|
|
71
|
+
pointerTypeRef.current = void 0;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
(0, import_utils.isMouseLikePointerType)(pointerType, !0) && ignoreMouse || (open && toggle && (!(dataRef.current.openEvent && stickIfOpen) || dataRef.current.openEvent.type === "click") ? onOpenChange(!1, event.nativeEvent || event, "click") : onOpenChange(!0, event.nativeEvent || event, "click"));
|
|
75
|
+
},
|
|
76
|
+
onKeyDown(event) {
|
|
77
|
+
pointerTypeRef.current = void 0, !(event.defaultPrevented || !keyboardHandlers || isButtonTarget(event)) && (event.key === " " && !isSpaceIgnored(domReference) && (event.preventDefault(), didKeyDownRef.current = !0), !isAnchorTarget(event) && event.key === "Enter" && onOpenChange(!(open && toggle), event.nativeEvent || event, "click"));
|
|
78
|
+
},
|
|
79
|
+
onKeyUp(event) {
|
|
80
|
+
event.defaultPrevented || !keyboardHandlers || isButtonTarget(event) || isSpaceIgnored(domReference) || event.key === " " && didKeyDownRef.current && (didKeyDownRef.current = !1, onOpenChange(!(open && toggle), event.nativeEvent || event, "click"));
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}, [dataRef, domReference, eventOption, ignoreMouse, keyboardHandlers, onOpenChange, open, stickIfOpen, toggle]);
|
|
84
|
+
return (0, import_react.useMemo)(function () {
|
|
85
|
+
return enabled ? {
|
|
86
|
+
reference
|
|
87
|
+
} : {};
|
|
88
|
+
}, [enabled, reference]);
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=useClick.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useClick_exports","__export","useClick","module","exports","import_react","require","import_utils","isButtonTarget","event","isHTMLElement","target","tagName","isAnchorTarget","isSpaceIgnored","element","isTypeableElement","context","props","arguments","length","open","onOpenChange","dataRef","elements","domReference","enabled","eventOption","toggle","ignoreMouse","keyboardHandlers","stickIfOpen","pointerTypeRef","useRef","didKeyDownRef","reference","useMemo","onPointerDown","current","pointerType","onMouseDown","button","isMouseLikePointerType","openEvent","type","nativeEvent","preventDefault","onClick","onKeyDown","defaultPrevented","key","onKeyUp"],"sources":["../../../src/interactions/useClick.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,gBAAA;AAAAC,QAAA,CAAAD,gBAAA;EAAAE,QAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAAgC,CAAAK,gBAChC;AAGA,IAAAK,YAAS,GAAAC,OAAe,QAAqC;EAAAC,YAAA,GAAAD,OAAA;AAC3D,SAAAE,cAAOA,CAAAC,KAAA;EACT,WAAAF,YAAA,CAAAG,aAAA,EAAAD,KAAA,CAAAE,MAAA,KAAAF,KAAA,CAAAE,MAAA,CAAAC,OAAA;AAEA;AACE,SAAAC,cAAOA,CAAAJ,KAAA;EACT,WAAAF,YAAA,CAAAG,aAAA,EAAAD,KAAA,CAAAE,MAAA,KAAAF,KAAA,CAAAE,MAAA,CAAAC,OAAA;AAEA;AACE,SAAAE,cAAOA,CAAAC,OAAA;EACT,WAAAR,YAAA,CAAAS,iBAAA,EAAAD,OAAA;AAGO;AAIL,SAAMb,SAAAe,OAAA;EAAA,IACJC,KAAA,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,iBAAAA,SAAA;IAAA;MAAAE,IAAA;MAAAC,YAAA;MAAAC,OAAA;MAAAC,QAAA;QAAAC;MAAA;IAAA,IAAAR,OAAA;IAAA;MAAAS,OAAA;MAAAjB,KAAA,EAAAkB,WAAA;MAAAC,MAAA;MAAAC,WAAA;MAAAC,gBAAA;MAAAC,WAAA;IAAA,IAAAb,KAAA;IAAAc,cAAA,OAAA3B,YAAA,CAAA4B,MAAA;IAAAC,aAAA,OAAA7B,YAAA,CAAA4B,MAAA;IAA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ACCW,YAAQ,MAAQhB,KAAA,CAAAqC,cAAa,IAAAZ,aAClB,CAAAI,OAAQ,SAAAzB,cAAmB,CAAAJ,KAAA,KAGvCA,KAAA,CAAAyC,GAAA,KAAa,OAAO,IAAM5B,YAAA,CAAe,EAAAD,IAAA,IAAOO,MAAO,GAGvDnB,KAAA,CAAMoC,WAAA,IAAepC,KACrB,WAAa;QAEjB;QACA0C,QAAQ1C,KAAA,EAAY;UAClBA,KAAA,CAAMwC,gBAAc,KAAAnB,gBAAe,IAAAtB,cAAA,CAAAC,KAAA,KAAAK,cAAA,CAAAW,YAAA,KAAAhB,KAAA,CAAAyC,GAAA,YAAAhB,aAAA,CAAAI,OAAA,KAAAJ,aAAA,CAAAI,OAAA,OAAAhB,YAAA,GAAAD,IAAA,IAAAO,MAAA,GAAAnB,KAAA,CAAAoC,WAAA,IAAApC,KAAA;QAEnC;MACE;IACA,IAAAc,OACF,EAEAE,YAAI,EAWoDE,WAE1D,EAAAE,WACA,EAGEC,gBAFA,EAkB2DR,YAK7D,EAAAD,IACA,EACEU,WACQ,EAWmDH,MAK7D,EACF;EAAA,OACA,IAAAvB,YAAA,CAAA+B,OAAA;IAAA,OACEV,OAAA;MACAS;IAAA,IACA;EAAA,IACAT,OACA,EAAAS,SACA;AACA","ignoreList":[]}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var useDelayGroup_exports = {};
|
|
33
|
+
__export(useDelayGroup_exports, {
|
|
34
|
+
FloatingDelayGroup: () => FloatingDelayGroup,
|
|
35
|
+
useDelayGroup: () => useDelayGroup,
|
|
36
|
+
useDelayGroupContext: () => useDelayGroupContext
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(useDelayGroup_exports);
|
|
39
|
+
var React = __toESM(require("react"), 1);
|
|
40
|
+
const DelayGroupContext = React.createContext({
|
|
41
|
+
currentId: null,
|
|
42
|
+
setCurrentId: () => {},
|
|
43
|
+
delay: 0,
|
|
44
|
+
timeoutMs: 0,
|
|
45
|
+
initialDelay: 0
|
|
46
|
+
});
|
|
47
|
+
function useDelayGroupContext() {
|
|
48
|
+
return React.useContext(DelayGroupContext);
|
|
49
|
+
}
|
|
50
|
+
function FloatingDelayGroup({
|
|
51
|
+
children,
|
|
52
|
+
delay,
|
|
53
|
+
timeoutMs = 0
|
|
54
|
+
}) {
|
|
55
|
+
const [currentId, setCurrentIdRaw] = React.useState(null),
|
|
56
|
+
timeoutRef = React.useRef(void 0),
|
|
57
|
+
setCurrentId = React.useCallback(id => {
|
|
58
|
+
clearTimeout(timeoutRef.current), id == null && timeoutMs > 0 ? timeoutRef.current = setTimeout(() => {
|
|
59
|
+
setCurrentIdRaw(null);
|
|
60
|
+
}, timeoutMs) : setCurrentIdRaw(id);
|
|
61
|
+
}, [timeoutMs]);
|
|
62
|
+
React.useEffect(() => () => clearTimeout(timeoutRef.current), []);
|
|
63
|
+
const value = React.useMemo(() => ({
|
|
64
|
+
currentId,
|
|
65
|
+
setCurrentId,
|
|
66
|
+
delay,
|
|
67
|
+
timeoutMs,
|
|
68
|
+
initialDelay: delay
|
|
69
|
+
}), [currentId, setCurrentId, delay, timeoutMs]);
|
|
70
|
+
return React.createElement(DelayGroupContext.Provider, {
|
|
71
|
+
value
|
|
72
|
+
}, children);
|
|
73
|
+
}
|
|
74
|
+
function useDelayGroup(context, options = {}) {
|
|
75
|
+
const {
|
|
76
|
+
id
|
|
77
|
+
} = options,
|
|
78
|
+
groupContext = React.useContext(DelayGroupContext);
|
|
79
|
+
return React.useEffect(() => {
|
|
80
|
+
!context.open && groupContext.currentId === id && groupContext.setCurrentId(null);
|
|
81
|
+
}, [context.open, id]), React.useEffect(() => {
|
|
82
|
+
groupContext.currentId != null && groupContext.currentId !== id && context.open && context.onOpenChange(!1);
|
|
83
|
+
}, [groupContext.currentId, id, context.open]), groupContext.currentId != null ? {
|
|
84
|
+
delay: {
|
|
85
|
+
open: 1,
|
|
86
|
+
close: getClose(groupContext.initialDelay)
|
|
87
|
+
},
|
|
88
|
+
currentId: groupContext.currentId
|
|
89
|
+
} : {
|
|
90
|
+
delay: groupContext.initialDelay,
|
|
91
|
+
currentId: groupContext.currentId
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function getClose(delay) {
|
|
95
|
+
return typeof delay == "number" ? delay : delay?.close ?? 0;
|
|
96
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
8
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: !0
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
__copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: !0
|
|
30
|
+
}) : target, mod)),
|
|
31
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: !0
|
|
33
|
+
}), mod);
|
|
34
|
+
var useDelayGroup_exports = {};
|
|
35
|
+
__export(useDelayGroup_exports, {
|
|
36
|
+
FloatingDelayGroup: () => FloatingDelayGroup,
|
|
37
|
+
useDelayGroup: () => useDelayGroup,
|
|
38
|
+
useDelayGroupContext: () => useDelayGroupContext
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(useDelayGroup_exports);
|
|
41
|
+
var React = __toESM(require("react"), 1),
|
|
42
|
+
DelayGroupContext = React.createContext({
|
|
43
|
+
currentId: null,
|
|
44
|
+
setCurrentId: function () {},
|
|
45
|
+
delay: 0,
|
|
46
|
+
timeoutMs: 0,
|
|
47
|
+
initialDelay: 0
|
|
48
|
+
});
|
|
49
|
+
function useDelayGroupContext() {
|
|
50
|
+
return React.useContext(DelayGroupContext);
|
|
51
|
+
}
|
|
52
|
+
function FloatingDelayGroup(param) {
|
|
53
|
+
var {
|
|
54
|
+
children,
|
|
55
|
+
delay,
|
|
56
|
+
timeoutMs = 0
|
|
57
|
+
} = param,
|
|
58
|
+
[currentId, setCurrentIdRaw] = React.useState(null),
|
|
59
|
+
timeoutRef = React.useRef(void 0),
|
|
60
|
+
setCurrentId = React.useCallback(function (id) {
|
|
61
|
+
clearTimeout(timeoutRef.current), id == null && timeoutMs > 0 ? timeoutRef.current = setTimeout(function () {
|
|
62
|
+
setCurrentIdRaw(null);
|
|
63
|
+
}, timeoutMs) : setCurrentIdRaw(id);
|
|
64
|
+
}, [timeoutMs]);
|
|
65
|
+
React.useEffect(function () {
|
|
66
|
+
return function () {
|
|
67
|
+
return clearTimeout(timeoutRef.current);
|
|
68
|
+
};
|
|
69
|
+
}, []);
|
|
70
|
+
var value = React.useMemo(function () {
|
|
71
|
+
return {
|
|
72
|
+
currentId,
|
|
73
|
+
setCurrentId,
|
|
74
|
+
delay,
|
|
75
|
+
timeoutMs,
|
|
76
|
+
initialDelay: delay
|
|
77
|
+
};
|
|
78
|
+
}, [currentId, setCurrentId, delay, timeoutMs]);
|
|
79
|
+
return React.createElement(DelayGroupContext.Provider, {
|
|
80
|
+
value
|
|
81
|
+
}, children);
|
|
82
|
+
}
|
|
83
|
+
function useDelayGroup(context) {
|
|
84
|
+
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {},
|
|
85
|
+
{
|
|
86
|
+
id
|
|
87
|
+
} = options,
|
|
88
|
+
groupContext = React.useContext(DelayGroupContext);
|
|
89
|
+
return React.useEffect(function () {
|
|
90
|
+
!context.open && groupContext.currentId === id && groupContext.setCurrentId(null);
|
|
91
|
+
}, [context.open, id]), React.useEffect(function () {
|
|
92
|
+
groupContext.currentId != null && groupContext.currentId !== id && context.open && context.onOpenChange(!1);
|
|
93
|
+
}, [groupContext.currentId, id, context.open]), groupContext.currentId != null ? {
|
|
94
|
+
delay: {
|
|
95
|
+
open: 1,
|
|
96
|
+
close: getClose(groupContext.initialDelay)
|
|
97
|
+
},
|
|
98
|
+
currentId: groupContext.currentId
|
|
99
|
+
} : {
|
|
100
|
+
delay: groupContext.initialDelay,
|
|
101
|
+
currentId: groupContext.currentId
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function getClose(delay) {
|
|
105
|
+
if (typeof delay == "number") return delay;
|
|
106
|
+
var _delay_close;
|
|
107
|
+
return (_delay_close = delay?.close) !== null && _delay_close !== void 0 ? _delay_close : 0;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=useDelayGroup.native.js.map
|