@hanzogui/floating 2.0.0-rc.41-hanzoai.5

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.
Files changed (187) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/Floating.cjs +20 -0
  3. package/dist/cjs/Floating.native.js +39 -0
  4. package/dist/cjs/Floating.native.js.map +1 -0
  5. package/dist/cjs/index.cjs +73 -0
  6. package/dist/cjs/index.native.js +76 -0
  7. package/dist/cjs/index.native.js.map +1 -0
  8. package/dist/cjs/interactions/PopupTriggerMap.cjs +49 -0
  9. package/dist/cjs/interactions/PopupTriggerMap.native.js +97 -0
  10. package/dist/cjs/interactions/PopupTriggerMap.native.js.map +1 -0
  11. package/dist/cjs/interactions/createFloatingEvents.cjs +50 -0
  12. package/dist/cjs/interactions/createFloatingEvents.native.js +56 -0
  13. package/dist/cjs/interactions/createFloatingEvents.native.js.map +1 -0
  14. package/dist/cjs/interactions/safePolygon.cjs +273 -0
  15. package/dist/cjs/interactions/safePolygon.native.js +284 -0
  16. package/dist/cjs/interactions/safePolygon.native.js.map +1 -0
  17. package/dist/cjs/interactions/types.cjs +18 -0
  18. package/dist/cjs/interactions/types.native.js +21 -0
  19. package/dist/cjs/interactions/types.native.js.map +1 -0
  20. package/dist/cjs/interactions/useClick.cjs +124 -0
  21. package/dist/cjs/interactions/useClick.native.js +132 -0
  22. package/dist/cjs/interactions/useClick.native.js.map +1 -0
  23. package/dist/cjs/interactions/useDelayGroup.cjs +115 -0
  24. package/dist/cjs/interactions/useDelayGroup.native.js +125 -0
  25. package/dist/cjs/interactions/useDelayGroup.native.js.map +1 -0
  26. package/dist/cjs/interactions/useFocus.cjs +130 -0
  27. package/dist/cjs/interactions/useFocus.native.js +139 -0
  28. package/dist/cjs/interactions/useFocus.native.js.map +1 -0
  29. package/dist/cjs/interactions/useHover.cjs +357 -0
  30. package/dist/cjs/interactions/useHover.native.js +373 -0
  31. package/dist/cjs/interactions/useHover.native.js.map +1 -0
  32. package/dist/cjs/interactions/useInnerOffset.cjs +128 -0
  33. package/dist/cjs/interactions/useInnerOffset.native.js +141 -0
  34. package/dist/cjs/interactions/useInnerOffset.native.js.map +1 -0
  35. package/dist/cjs/interactions/useInteractions.cjs +105 -0
  36. package/dist/cjs/interactions/useInteractions.native.js +216 -0
  37. package/dist/cjs/interactions/useInteractions.native.js.map +1 -0
  38. package/dist/cjs/interactions/useListNavigation.cjs +418 -0
  39. package/dist/cjs/interactions/useListNavigation.native.js +433 -0
  40. package/dist/cjs/interactions/useListNavigation.native.js.map +1 -0
  41. package/dist/cjs/interactions/useRole.cjs +122 -0
  42. package/dist/cjs/interactions/useRole.native.js +136 -0
  43. package/dist/cjs/interactions/useRole.native.js.map +1 -0
  44. package/dist/cjs/interactions/useTypeahead.cjs +143 -0
  45. package/dist/cjs/interactions/useTypeahead.native.js +159 -0
  46. package/dist/cjs/interactions/useTypeahead.native.js.map +1 -0
  47. package/dist/cjs/interactions/utils.cjs +208 -0
  48. package/dist/cjs/interactions/utils.native.js +227 -0
  49. package/dist/cjs/interactions/utils.native.js.map +1 -0
  50. package/dist/cjs/middleware/inner.cjs +118 -0
  51. package/dist/cjs/middleware/inner.native.js +130 -0
  52. package/dist/cjs/middleware/inner.native.js.map +1 -0
  53. package/dist/cjs/useFloating.cjs +64 -0
  54. package/dist/cjs/useFloating.native.js +69 -0
  55. package/dist/cjs/useFloating.native.js.map +1 -0
  56. package/dist/esm/Floating.mjs +2 -0
  57. package/dist/esm/Floating.mjs.map +1 -0
  58. package/dist/esm/Floating.native.js +8 -0
  59. package/dist/esm/Floating.native.js.map +1 -0
  60. package/dist/esm/index.js +18 -0
  61. package/dist/esm/index.js.map +1 -0
  62. package/dist/esm/index.mjs +18 -0
  63. package/dist/esm/index.mjs.map +1 -0
  64. package/dist/esm/index.native.js +18 -0
  65. package/dist/esm/index.native.js.map +1 -0
  66. package/dist/esm/interactions/PopupTriggerMap.mjs +24 -0
  67. package/dist/esm/interactions/PopupTriggerMap.mjs.map +1 -0
  68. package/dist/esm/interactions/PopupTriggerMap.native.js +69 -0
  69. package/dist/esm/interactions/PopupTriggerMap.native.js.map +1 -0
  70. package/dist/esm/interactions/createFloatingEvents.mjs +25 -0
  71. package/dist/esm/interactions/createFloatingEvents.mjs.map +1 -0
  72. package/dist/esm/interactions/createFloatingEvents.native.js +28 -0
  73. package/dist/esm/interactions/createFloatingEvents.native.js.map +1 -0
  74. package/dist/esm/interactions/safePolygon.mjs +248 -0
  75. package/dist/esm/interactions/safePolygon.mjs.map +1 -0
  76. package/dist/esm/interactions/safePolygon.native.js +256 -0
  77. package/dist/esm/interactions/safePolygon.native.js.map +1 -0
  78. package/dist/esm/interactions/types.mjs +2 -0
  79. package/dist/esm/interactions/types.mjs.map +1 -0
  80. package/dist/esm/interactions/types.native.js +2 -0
  81. package/dist/esm/interactions/types.native.js.map +1 -0
  82. package/dist/esm/interactions/useClick.mjs +99 -0
  83. package/dist/esm/interactions/useClick.mjs.map +1 -0
  84. package/dist/esm/interactions/useClick.native.js +104 -0
  85. package/dist/esm/interactions/useClick.native.js.map +1 -0
  86. package/dist/esm/interactions/useDelayGroup.mjs +77 -0
  87. package/dist/esm/interactions/useDelayGroup.mjs.map +1 -0
  88. package/dist/esm/interactions/useDelayGroup.native.js +84 -0
  89. package/dist/esm/interactions/useDelayGroup.native.js.map +1 -0
  90. package/dist/esm/interactions/useFocus.mjs +105 -0
  91. package/dist/esm/interactions/useFocus.mjs.map +1 -0
  92. package/dist/esm/interactions/useFocus.native.js +111 -0
  93. package/dist/esm/interactions/useFocus.native.js.map +1 -0
  94. package/dist/esm/interactions/useHover.mjs +320 -0
  95. package/dist/esm/interactions/useHover.mjs.map +1 -0
  96. package/dist/esm/interactions/useHover.native.js +333 -0
  97. package/dist/esm/interactions/useHover.native.js.map +1 -0
  98. package/dist/esm/interactions/useInnerOffset.mjs +92 -0
  99. package/dist/esm/interactions/useInnerOffset.mjs.map +1 -0
  100. package/dist/esm/interactions/useInnerOffset.native.js +102 -0
  101. package/dist/esm/interactions/useInnerOffset.native.js.map +1 -0
  102. package/dist/esm/interactions/useInteractions.mjs +80 -0
  103. package/dist/esm/interactions/useInteractions.mjs.map +1 -0
  104. package/dist/esm/interactions/useInteractions.native.js +188 -0
  105. package/dist/esm/interactions/useInteractions.native.js.map +1 -0
  106. package/dist/esm/interactions/useListNavigation.mjs +393 -0
  107. package/dist/esm/interactions/useListNavigation.mjs.map +1 -0
  108. package/dist/esm/interactions/useListNavigation.native.js +405 -0
  109. package/dist/esm/interactions/useListNavigation.native.js.map +1 -0
  110. package/dist/esm/interactions/useRole.mjs +86 -0
  111. package/dist/esm/interactions/useRole.mjs.map +1 -0
  112. package/dist/esm/interactions/useRole.native.js +97 -0
  113. package/dist/esm/interactions/useRole.native.js.map +1 -0
  114. package/dist/esm/interactions/useTypeahead.mjs +118 -0
  115. package/dist/esm/interactions/useTypeahead.mjs.map +1 -0
  116. package/dist/esm/interactions/useTypeahead.native.js +131 -0
  117. package/dist/esm/interactions/useTypeahead.native.js.map +1 -0
  118. package/dist/esm/interactions/utils.mjs +162 -0
  119. package/dist/esm/interactions/utils.mjs.map +1 -0
  120. package/dist/esm/interactions/utils.native.js +178 -0
  121. package/dist/esm/interactions/utils.native.js.map +1 -0
  122. package/dist/esm/middleware/inner.mjs +82 -0
  123. package/dist/esm/middleware/inner.mjs.map +1 -0
  124. package/dist/esm/middleware/inner.native.js +91 -0
  125. package/dist/esm/middleware/inner.native.js.map +1 -0
  126. package/dist/esm/useFloating.mjs +27 -0
  127. package/dist/esm/useFloating.mjs.map +1 -0
  128. package/dist/esm/useFloating.native.js +29 -0
  129. package/dist/esm/useFloating.native.js.map +1 -0
  130. package/package.json +50 -0
  131. package/src/Floating.native.tsx +45 -0
  132. package/src/Floating.tsx +1 -0
  133. package/src/index.ts +116 -0
  134. package/src/interactions/PopupTriggerMap.ts +30 -0
  135. package/src/interactions/createFloatingEvents.ts +34 -0
  136. package/src/interactions/safePolygon.ts +500 -0
  137. package/src/interactions/types.ts +165 -0
  138. package/src/interactions/useClick.ts +148 -0
  139. package/src/interactions/useDelayGroup.ts +114 -0
  140. package/src/interactions/useFocus.ts +164 -0
  141. package/src/interactions/useHover.ts +453 -0
  142. package/src/interactions/useInnerOffset.ts +116 -0
  143. package/src/interactions/useInteractions.ts +101 -0
  144. package/src/interactions/useListNavigation.ts +578 -0
  145. package/src/interactions/useRole.ts +103 -0
  146. package/src/interactions/useTypeahead.ts +173 -0
  147. package/src/interactions/utils.ts +234 -0
  148. package/src/middleware/inner.ts +141 -0
  149. package/src/useFloating.tsx +53 -0
  150. package/types/Floating.d.ts +2 -0
  151. package/types/Floating.d.ts.map +1 -0
  152. package/types/Floating.native.d.ts +41 -0
  153. package/types/Floating.native.d.ts.map +1 -0
  154. package/types/index.d.ts +19 -0
  155. package/types/index.d.ts.map +1 -0
  156. package/types/interactions/PopupTriggerMap.d.ts +8 -0
  157. package/types/interactions/PopupTriggerMap.d.ts.map +1 -0
  158. package/types/interactions/createFloatingEvents.d.ts +7 -0
  159. package/types/interactions/createFloatingEvents.d.ts.map +1 -0
  160. package/types/interactions/safePolygon.d.ts +4 -0
  161. package/types/interactions/safePolygon.d.ts.map +1 -0
  162. package/types/interactions/types.d.ts +123 -0
  163. package/types/interactions/types.d.ts.map +1 -0
  164. package/types/interactions/useClick.d.ts +3 -0
  165. package/types/interactions/useClick.d.ts.map +1 -0
  166. package/types/interactions/useDelayGroup.d.ts +23 -0
  167. package/types/interactions/useDelayGroup.d.ts.map +1 -0
  168. package/types/interactions/useFocus.d.ts +3 -0
  169. package/types/interactions/useFocus.d.ts.map +1 -0
  170. package/types/interactions/useHover.d.ts +6 -0
  171. package/types/interactions/useHover.d.ts.map +1 -0
  172. package/types/interactions/useInnerOffset.d.ts +3 -0
  173. package/types/interactions/useInnerOffset.d.ts.map +1 -0
  174. package/types/interactions/useInteractions.d.ts +8 -0
  175. package/types/interactions/useInteractions.d.ts.map +1 -0
  176. package/types/interactions/useListNavigation.d.ts +3 -0
  177. package/types/interactions/useListNavigation.d.ts.map +1 -0
  178. package/types/interactions/useRole.d.ts +3 -0
  179. package/types/interactions/useRole.d.ts.map +1 -0
  180. package/types/interactions/useTypeahead.d.ts +3 -0
  181. package/types/interactions/useTypeahead.d.ts.map +1 -0
  182. package/types/interactions/utils.d.ts +46 -0
  183. package/types/interactions/utils.d.ts.map +1 -0
  184. package/types/middleware/inner.d.ts +14 -0
  185. package/types/middleware/inner.d.ts.map +1 -0
  186. package/types/useFloating.d.ts +28 -0
  187. package/types/useFloating.d.ts.map +1 -0
@@ -0,0 +1,130 @@
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: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: true
22
+ }), mod);
23
+ var useFocus_exports = {};
24
+ __export(useFocus_exports, {
25
+ useFocus: () => useFocus
26
+ });
27
+ module.exports = __toCommonJS(useFocus_exports);
28
+ var import_react = require("react");
29
+ var import_utils = require("./utils.cjs");
30
+ function isMacSafari() {
31
+ return (0, import_utils.isMac)() && (0, import_utils.isSafari)();
32
+ }
33
+ function useFocus(context, props = {}) {
34
+ const {
35
+ open,
36
+ onOpenChange,
37
+ events,
38
+ dataRef,
39
+ elements
40
+ } = context;
41
+ const {
42
+ enabled = true,
43
+ visibleOnly = true
44
+ } = props;
45
+ const blockFocusRef = (0, import_react.useRef)(false);
46
+ const timeoutRef = (0, import_react.useRef)(-1);
47
+ const keyboardModalityRef = (0, import_react.useRef)(true);
48
+ (0, import_react.useEffect)(() => {
49
+ if (!enabled) return;
50
+ const win = (0, import_utils.getDocument)(elements.domReference).defaultView || window;
51
+ function onBlur() {
52
+ if (!open && (0, import_utils.isHTMLElement)(elements.domReference) && elements.domReference === (0, import_utils.activeElement)((0, import_utils.getDocument)(elements.domReference))) {
53
+ blockFocusRef.current = true;
54
+ }
55
+ }
56
+ function onKeyDown() {
57
+ keyboardModalityRef.current = true;
58
+ }
59
+ function onPointerDown() {
60
+ keyboardModalityRef.current = false;
61
+ }
62
+ win.addEventListener("blur", onBlur);
63
+ if (isMacSafari()) {
64
+ win.addEventListener("keydown", onKeyDown, true);
65
+ win.addEventListener("pointerdown", onPointerDown, true);
66
+ }
67
+ return () => {
68
+ win.removeEventListener("blur", onBlur);
69
+ if (isMacSafari()) {
70
+ win.removeEventListener("keydown", onKeyDown, true);
71
+ win.removeEventListener("pointerdown", onPointerDown, true);
72
+ }
73
+ };
74
+ }, [elements.domReference, open, enabled]);
75
+ (0, import_react.useEffect)(() => {
76
+ if (!enabled) return;
77
+ if (!events) return;
78
+ function handleOpenChange({
79
+ reason
80
+ }) {
81
+ if (reason === "reference-press" || reason === "escape-key") {
82
+ blockFocusRef.current = true;
83
+ }
84
+ }
85
+ events.on("openchange", handleOpenChange);
86
+ return () => {
87
+ events.off("openchange", handleOpenChange);
88
+ };
89
+ }, [events, enabled]);
90
+ (0, import_react.useEffect)(() => {
91
+ return () => {
92
+ (0, import_utils.clearTimeoutIfSet)(timeoutRef);
93
+ };
94
+ }, []);
95
+ const reference = (0, import_react.useMemo)(() => ({
96
+ onMouseLeave() {
97
+ blockFocusRef.current = false;
98
+ },
99
+ onFocus(event) {
100
+ if (blockFocusRef.current) return;
101
+ const target = (0, import_utils.getTarget)(event.nativeEvent);
102
+ if (visibleOnly && (0, import_utils.isElement)(target)) {
103
+ if (isMacSafari() && !event.relatedTarget) {
104
+ if (!keyboardModalityRef.current && !(0, import_utils.isTypeableElement)(target)) {
105
+ return;
106
+ }
107
+ } else if (!(0, import_utils.matchesFocusVisible)(target)) {
108
+ return;
109
+ }
110
+ }
111
+ onOpenChange(true, event.nativeEvent, "focus");
112
+ },
113
+ onBlur(event) {
114
+ blockFocusRef.current = false;
115
+ const relatedTarget = event.relatedTarget;
116
+ const nativeEvent = event.nativeEvent;
117
+ timeoutRef.current = window.setTimeout(() => {
118
+ const activeEl = (0, import_utils.activeElement)(elements.domReference ? elements.domReference.ownerDocument : document);
119
+ if (!relatedTarget && activeEl === elements.domReference) return;
120
+ if ((0, import_utils.contains)(context.refs.floating.current, activeEl) || (0, import_utils.contains)(elements.domReference, activeEl)) {
121
+ return;
122
+ }
123
+ onOpenChange(false, nativeEvent, "focus");
124
+ });
125
+ }
126
+ }), [context.refs.floating, elements.domReference, onOpenChange, visibleOnly]);
127
+ return (0, import_react.useMemo)(() => enabled ? {
128
+ reference
129
+ } : {}, [enabled, reference]);
130
+ }
@@ -0,0 +1,139 @@
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: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
+ value: true
24
+ }), mod);
25
+ var useFocus_exports = {};
26
+ __export(useFocus_exports, {
27
+ useFocus: () => useFocus
28
+ });
29
+ module.exports = __toCommonJS(useFocus_exports);
30
+ var import_react = require("react");
31
+ var import_utils = require("./utils.native.js");
32
+ function isMacSafari() {
33
+ return (0, import_utils.isMac)() && (0, import_utils.isSafari)();
34
+ }
35
+ function useFocus(context) {
36
+ var props = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
37
+ var {
38
+ open,
39
+ onOpenChange,
40
+ events,
41
+ dataRef,
42
+ elements
43
+ } = context;
44
+ var {
45
+ enabled = true,
46
+ visibleOnly = true
47
+ } = props;
48
+ var blockFocusRef = (0, import_react.useRef)(false);
49
+ var timeoutRef = (0, import_react.useRef)(-1);
50
+ var keyboardModalityRef = (0, import_react.useRef)(true);
51
+ (0, import_react.useEffect)(function () {
52
+ if (!enabled) return;
53
+ var win = (0, import_utils.getDocument)(elements.domReference).defaultView || window;
54
+ function onBlur() {
55
+ if (!open && (0, import_utils.isHTMLElement)(elements.domReference) && elements.domReference === (0, import_utils.activeElement)((0, import_utils.getDocument)(elements.domReference))) {
56
+ blockFocusRef.current = true;
57
+ }
58
+ }
59
+ function onKeyDown() {
60
+ keyboardModalityRef.current = true;
61
+ }
62
+ function onPointerDown() {
63
+ keyboardModalityRef.current = false;
64
+ }
65
+ win.addEventListener("blur", onBlur);
66
+ if (isMacSafari()) {
67
+ win.addEventListener("keydown", onKeyDown, true);
68
+ win.addEventListener("pointerdown", onPointerDown, true);
69
+ }
70
+ return function () {
71
+ win.removeEventListener("blur", onBlur);
72
+ if (isMacSafari()) {
73
+ win.removeEventListener("keydown", onKeyDown, true);
74
+ win.removeEventListener("pointerdown", onPointerDown, true);
75
+ }
76
+ };
77
+ }, [elements.domReference, open, enabled]);
78
+ (0, import_react.useEffect)(function () {
79
+ if (!enabled) return;
80
+ if (!events) return;
81
+ function handleOpenChange(param) {
82
+ var {
83
+ reason
84
+ } = param;
85
+ if (reason === "reference-press" || reason === "escape-key") {
86
+ blockFocusRef.current = true;
87
+ }
88
+ }
89
+ events.on("openchange", handleOpenChange);
90
+ return function () {
91
+ events.off("openchange", handleOpenChange);
92
+ };
93
+ }, [events, enabled]);
94
+ (0, import_react.useEffect)(function () {
95
+ return function () {
96
+ (0, import_utils.clearTimeoutIfSet)(timeoutRef);
97
+ };
98
+ }, []);
99
+ var reference = (0, import_react.useMemo)(function () {
100
+ return {
101
+ onMouseLeave() {
102
+ blockFocusRef.current = false;
103
+ },
104
+ onFocus(event) {
105
+ if (blockFocusRef.current) return;
106
+ var target = (0, import_utils.getTarget)(event.nativeEvent);
107
+ if (visibleOnly && (0, import_utils.isElement)(target)) {
108
+ if (isMacSafari() && !event.relatedTarget) {
109
+ if (!keyboardModalityRef.current && !(0, import_utils.isTypeableElement)(target)) {
110
+ return;
111
+ }
112
+ } else if (!(0, import_utils.matchesFocusVisible)(target)) {
113
+ return;
114
+ }
115
+ }
116
+ onOpenChange(true, event.nativeEvent, "focus");
117
+ },
118
+ onBlur(event) {
119
+ blockFocusRef.current = false;
120
+ var relatedTarget = event.relatedTarget;
121
+ var nativeEvent = event.nativeEvent;
122
+ timeoutRef.current = window.setTimeout(function () {
123
+ var activeEl = (0, import_utils.activeElement)(elements.domReference ? elements.domReference.ownerDocument : document);
124
+ if (!relatedTarget && activeEl === elements.domReference) return;
125
+ if ((0, import_utils.contains)(context.refs.floating.current, activeEl) || (0, import_utils.contains)(elements.domReference, activeEl)) {
126
+ return;
127
+ }
128
+ onOpenChange(false, nativeEvent, "focus");
129
+ });
130
+ }
131
+ };
132
+ }, [context.refs.floating, elements.domReference, onOpenChange, visibleOnly]);
133
+ return (0, import_react.useMemo)(function () {
134
+ return enabled ? {
135
+ reference
136
+ } : {};
137
+ }, [enabled, reference]);
138
+ }
139
+ //# sourceMappingURL=useFocus.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toCommonJS","mod","value","useFocus_exports","useFocus","module","exports","import_react","require","import_utils","isMacSafari","isMac","isSafari","context","props","arguments","length","open","onOpenChange","events","dataRef","elements","enabled","visibleOnly","blockFocusRef","useRef","timeoutRef","keyboardModalityRef","useEffect","win","getDocument","domReference","defaultView","window","onBlur","isHTMLElement","activeElement","current","onKeyDown","onPointerDown","addEventListener","removeEventListener","handleOpenChange","param","reason","on","off","clearTimeoutIfSet","reference","useMemo","onMouseLeave","onFocus","event","getTarget","nativeEvent","isElement","relatedTarget","isTypeableElement","matchesFocusVisible","setTimeout","activeEl","ownerDocument","document","contains","refs","floating"],"sources":["useFocus.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useFocus_exports = {};\n__export(useFocus_exports, {\n useFocus: () => useFocus\n});\nmodule.exports = __toCommonJS(useFocus_exports);\nvar import_react = require(\"react\");\nvar import_utils = require(\"./utils\");\nfunction isMacSafari() {\n return (0, import_utils.isMac)() && (0, import_utils.isSafari)();\n}\nfunction useFocus(context) {\n var props = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};\n var { open, onOpenChange, events, dataRef, elements } = context;\n var { enabled = true, visibleOnly = true } = props;\n var blockFocusRef = (0, import_react.useRef)(false);\n var timeoutRef = (0, import_react.useRef)(-1);\n var keyboardModalityRef = (0, import_react.useRef)(true);\n (0, import_react.useEffect)(function() {\n if (!enabled) return;\n var win = (0, import_utils.getDocument)(elements.domReference).defaultView || window;\n function onBlur() {\n if (!open && (0, import_utils.isHTMLElement)(elements.domReference) && elements.domReference === (0, import_utils.activeElement)((0, import_utils.getDocument)(elements.domReference))) {\n blockFocusRef.current = true;\n }\n }\n function onKeyDown() {\n keyboardModalityRef.current = true;\n }\n function onPointerDown() {\n keyboardModalityRef.current = false;\n }\n win.addEventListener(\"blur\", onBlur);\n if (isMacSafari()) {\n win.addEventListener(\"keydown\", onKeyDown, true);\n win.addEventListener(\"pointerdown\", onPointerDown, true);\n }\n return function() {\n win.removeEventListener(\"blur\", onBlur);\n if (isMacSafari()) {\n win.removeEventListener(\"keydown\", onKeyDown, true);\n win.removeEventListener(\"pointerdown\", onPointerDown, true);\n }\n };\n }, [\n elements.domReference,\n open,\n enabled\n ]);\n (0, import_react.useEffect)(function() {\n if (!enabled) return;\n if (!events) return;\n function handleOpenChange(param) {\n var { reason } = param;\n if (reason === \"reference-press\" || reason === \"escape-key\") {\n blockFocusRef.current = true;\n }\n }\n events.on(\"openchange\", handleOpenChange);\n return function() {\n events.off(\"openchange\", handleOpenChange);\n };\n }, [\n events,\n enabled\n ]);\n (0, import_react.useEffect)(function() {\n return function() {\n (0, import_utils.clearTimeoutIfSet)(timeoutRef);\n };\n }, []);\n var reference = (0, import_react.useMemo)(function() {\n return {\n onMouseLeave() {\n blockFocusRef.current = false;\n },\n onFocus(event) {\n if (blockFocusRef.current) return;\n var target = (0, import_utils.getTarget)(event.nativeEvent);\n if (visibleOnly && (0, import_utils.isElement)(target)) {\n if (isMacSafari() && !event.relatedTarget) {\n if (!keyboardModalityRef.current && !(0, import_utils.isTypeableElement)(target)) {\n return;\n }\n } else if (!(0, import_utils.matchesFocusVisible)(target)) {\n return;\n }\n }\n onOpenChange(true, event.nativeEvent, \"focus\");\n },\n onBlur(event) {\n blockFocusRef.current = false;\n var relatedTarget = event.relatedTarget;\n var nativeEvent = event.nativeEvent;\n timeoutRef.current = window.setTimeout(function() {\n var activeEl = (0, import_utils.activeElement)(elements.domReference ? elements.domReference.ownerDocument : document);\n if (!relatedTarget && activeEl === elements.domReference) return;\n if ((0, import_utils.contains)(context.refs.floating.current, activeEl) || (0, import_utils.contains)(elements.domReference, activeEl)) {\n return;\n }\n onOpenChange(false, nativeEvent, \"focus\");\n });\n }\n };\n }, [\n context.refs.floating,\n elements.domReference,\n onOpenChange,\n visibleOnly\n ]);\n return (0, import_react.useMemo)(function() {\n return enabled ? {\n reference\n } : {};\n }, [\n enabled,\n reference\n ]);\n}\n//# sourceMappingURL=useFocus.js.map\n"],"mappings":"AAAA,YAAY;;AACZ,IAAIA,SAAS,GAAGC,MAAM,CAACC,cAAc;AACrC,IAAIC,gBAAgB,GAAGF,MAAM,CAACG,wBAAwB;AACtD,IAAIC,iBAAiB,GAAGJ,MAAM,CAACK,mBAAmB;AAClD,IAAIC,YAAY,GAAGN,MAAM,CAACO,SAAS,CAACC,cAAc;AAClD,IAAIC,QAAQ,GAAGA,CAACC,MAAM,EAAEC,GAAG,KAAK;EAC9B,KAAK,IAAIC,IAAI,IAAID,GAAG,EAClBZ,SAAS,CAACW,MAAM,EAAEE,IAAI,EAAE;IAAEC,GAAG,EAAEF,GAAG,CAACC,IAAI,CAAC;IAAEE,UAAU,EAAE;EAAK,CAAC,CAAC;AACjE,CAAC;AACD,IAAIC,WAAW,GAAGA,CAACC,EAAE,EAAEC,IAAI,EAAEC,MAAM,EAAEC,IAAI,KAAK;EAC5C,IAAIF,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,IAAI,OAAOA,IAAI,KAAK,UAAU,EAAE;IAClE,KAAK,IAAIG,GAAG,IAAIhB,iBAAiB,CAACa,IAAI,CAAC,EACrC,IAAI,CAACX,YAAY,CAACe,IAAI,CAACL,EAAE,EAAE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O,EAAEuB,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAEnD,YAAY,CAACsD,QAAQ,EAAE1C,QAAQ,CAACU,YAAY,EAAE6B,QAAQ,CAAC,EAAE;YACtI;UACF;UACA1C,YAAY,CAAC,KAAK,EAAEoC,WAAW,EAAE,OAAO,CAAC;QAC3C,CAAC,CAAC;MACJ;IACF,CAAC;EACH,CAAC,EAAE,CACDzC,OAAO,CAACmD,IAAI,CAACC,QAAQ,EACrB5C,QAAQ,CAACU,YAAY,EACrBb,YAAY,EACZK,WAAW,CACZ,CAAC;EACF,OAAO,CAAC,CAAC,EAAEhB,YAAY,CAAC0C,OAAO,EAAE,YAAW;IAC1C,OAAO3B,OAAO,GAAG;MACf0B;IACF,CAAC,GAAG,CAAC,CAAC;EACR,CAAC,EAAE,CACD1B,OAAO,EACP0B,SAAS,CACV,CAAC;AACJ","ignoreList":[]}
@@ -0,0 +1,357 @@
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
+ 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: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
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: true
30
+ }) : target, mod));
31
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: true
33
+ }), mod);
34
+ var useHover_exports = {};
35
+ __export(useHover_exports, {
36
+ getDelay: () => getDelay,
37
+ useHover: () => useHover
38
+ });
39
+ module.exports = __toCommonJS(useHover_exports);
40
+ var React = __toESM(require("react"), 1);
41
+ var import_use_event = require("@hanzogui/use-event");
42
+ var import_utils = require("./utils.cjs");
43
+ const safePolygonIdentifier = "data-floating-ui-safe-polygon";
44
+ function getDelay(value, prop, pointerType) {
45
+ if (pointerType && !(0, import_utils.isMouseLikePointerType)(pointerType)) {
46
+ return 0;
47
+ }
48
+ if (typeof value === "number") {
49
+ return value;
50
+ }
51
+ return value?.[prop];
52
+ }
53
+ function useHover(context, props = {}) {
54
+ const {
55
+ open,
56
+ onOpenChange,
57
+ dataRef,
58
+ events,
59
+ elements
60
+ } = context;
61
+ const {
62
+ enabled = true,
63
+ delay = 0,
64
+ handleClose = null,
65
+ mouseOnly = false,
66
+ restMs = 0,
67
+ move = true
68
+ } = props;
69
+ const handleCloseRef = React.useRef(handleClose);
70
+ handleCloseRef.current = handleClose;
71
+ const delayRef = React.useRef(delay);
72
+ delayRef.current = delay;
73
+ const openRef = React.useRef(open);
74
+ openRef.current = open;
75
+ const restMsRef = React.useRef(restMs);
76
+ restMsRef.current = restMs;
77
+ const stableOnOpenChange = (0, import_use_event.useEvent)(onOpenChange);
78
+ const pointerTypeRef = React.useRef(void 0);
79
+ const timeoutRef = React.useRef(-1);
80
+ const handlerRef = React.useRef(void 0);
81
+ const restTimeoutRef = React.useRef(-1);
82
+ const blockMouseMoveRef = React.useRef(true);
83
+ const performedPointerEventsMutationRef = React.useRef(false);
84
+ const unbindMouseMoveRef = React.useRef(() => {});
85
+ const restTimeoutPendingRef = React.useRef(false);
86
+ const isHoverOpen = (0, import_use_event.useEvent)(() => {
87
+ const type = dataRef.current.openEvent?.type;
88
+ return type?.includes("mouse") && type !== "mousedown";
89
+ });
90
+ React.useEffect(() => {
91
+ if (!enabled) return;
92
+ if (!events) return;
93
+ function onOpenChange2({
94
+ open: open2
95
+ }) {
96
+ if (!open2) {
97
+ (0, import_utils.clearTimeoutIfSet)(timeoutRef);
98
+ (0, import_utils.clearTimeoutIfSet)(restTimeoutRef);
99
+ blockMouseMoveRef.current = true;
100
+ restTimeoutPendingRef.current = false;
101
+ }
102
+ }
103
+ events.on("openchange", onOpenChange2);
104
+ return () => {
105
+ events.off("openchange", onOpenChange2);
106
+ };
107
+ }, [enabled, events]);
108
+ const closeWithDelay = (0, import_use_event.useEvent)((event, runElseBranch = true, reason = "hover") => {
109
+ const closeDelay = getDelay(delayRef.current, "close", pointerTypeRef.current);
110
+ if (closeDelay && !handlerRef.current) {
111
+ (0, import_utils.clearTimeoutIfSet)(timeoutRef);
112
+ timeoutRef.current = window.setTimeout(() => stableOnOpenChange(false, event, reason), closeDelay);
113
+ } else if (runElseBranch) {
114
+ (0, import_utils.clearTimeoutIfSet)(timeoutRef);
115
+ stableOnOpenChange(false, event, reason);
116
+ }
117
+ });
118
+ const cleanupMouseMoveHandler = (0, import_use_event.useEvent)(() => {
119
+ unbindMouseMoveRef.current();
120
+ handlerRef.current = void 0;
121
+ if (context.handleCloseActiveRef) {
122
+ context.handleCloseActiveRef.current = false;
123
+ }
124
+ });
125
+ const clearPointerEvents = (0, import_use_event.useEvent)(() => {
126
+ if (performedPointerEventsMutationRef.current) {
127
+ const body = (0, import_utils.getDocument)(elements.floating).body;
128
+ body.style.pointerEvents = "";
129
+ body.removeAttribute(safePolygonIdentifier);
130
+ performedPointerEventsMutationRef.current = false;
131
+ }
132
+ });
133
+ const isClickLikeOpenEvent = (0, import_use_event.useEvent)(() => {
134
+ return dataRef.current.openEvent ? ["click", "mousedown"].includes(dataRef.current.openEvent.type) : false;
135
+ });
136
+ React.useEffect(() => {
137
+ if (!enabled) return;
138
+ function onReferenceMouseEnter(event) {
139
+ (0, import_utils.clearTimeoutIfSet)(timeoutRef);
140
+ blockMouseMoveRef.current = false;
141
+ if (mouseOnly && !(0, import_utils.isMouseLikePointerType)(pointerTypeRef.current) || restMsRef.current > 0 && !getDelay(delayRef.current, "open")) {
142
+ return;
143
+ }
144
+ const openDelay = getDelay(delayRef.current, "open", pointerTypeRef.current);
145
+ if (openDelay) {
146
+ timeoutRef.current = window.setTimeout(() => {
147
+ if (!openRef.current) {
148
+ stableOnOpenChange(true, event, "hover");
149
+ }
150
+ }, openDelay);
151
+ } else if (!open) {
152
+ stableOnOpenChange(true, event, "hover");
153
+ }
154
+ }
155
+ function onReferenceMouseLeave(event) {
156
+ if (isClickLikeOpenEvent()) {
157
+ clearPointerEvents();
158
+ return;
159
+ }
160
+ if (context.triggerElements?.hasElement(event.relatedTarget)) {
161
+ return;
162
+ }
163
+ unbindMouseMoveRef.current();
164
+ const doc = (0, import_utils.getDocument)(elements.floating);
165
+ (0, import_utils.clearTimeoutIfSet)(restTimeoutRef);
166
+ restTimeoutPendingRef.current = false;
167
+ if (handleCloseRef.current) {
168
+ if (!open) {
169
+ (0, import_utils.clearTimeoutIfSet)(timeoutRef);
170
+ }
171
+ const placement = dataRef.current.placement || "bottom";
172
+ const reference2 = elements.domReference;
173
+ const floating = elements.floating;
174
+ if (!reference2 || !floating) return;
175
+ handlerRef.current = handleCloseRef.current({
176
+ x: event.clientX,
177
+ y: event.clientY,
178
+ placement,
179
+ elements: {
180
+ reference: reference2,
181
+ floating,
182
+ domReference: reference2
183
+ },
184
+ onClose() {
185
+ if (context.handleCloseActiveRef) {
186
+ context.handleCloseActiveRef.current = false;
187
+ }
188
+ clearPointerEvents();
189
+ cleanupMouseMoveHandler();
190
+ if (!isClickLikeOpenEvent()) {
191
+ closeWithDelay(event, true, "safe-polygon");
192
+ }
193
+ }
194
+ });
195
+ if (context.handleCloseActiveRef) {
196
+ context.handleCloseActiveRef.current = true;
197
+ }
198
+ const handler = handlerRef.current;
199
+ doc.addEventListener("mousemove", handler);
200
+ unbindMouseMoveRef.current = () => {
201
+ doc.removeEventListener("mousemove", handler);
202
+ };
203
+ return;
204
+ }
205
+ const shouldClose = pointerTypeRef.current === "touch" ? !(0, import_utils.contains)(elements.floating, event.relatedTarget) : true;
206
+ if (shouldClose) {
207
+ closeWithDelay(event);
208
+ }
209
+ }
210
+ function onScrollMouseLeave(event) {
211
+ if (isClickLikeOpenEvent()) return;
212
+ if (context.triggerElements?.hasElement(event.relatedTarget)) {
213
+ return;
214
+ }
215
+ const placement = dataRef.current.placement || "bottom";
216
+ const reference2 = elements.domReference;
217
+ const floating = elements.floating;
218
+ if (!reference2 || !floating) return;
219
+ handleCloseRef.current?.({
220
+ x: event.clientX,
221
+ y: event.clientY,
222
+ placement,
223
+ elements: {
224
+ reference: reference2,
225
+ floating,
226
+ domReference: reference2
227
+ },
228
+ onClose() {
229
+ clearPointerEvents();
230
+ cleanupMouseMoveHandler();
231
+ if (!isClickLikeOpenEvent()) {
232
+ closeWithDelay(event);
233
+ }
234
+ }
235
+ })(event);
236
+ }
237
+ function onFloatingMouseEnter() {
238
+ (0, import_utils.clearTimeoutIfSet)(timeoutRef);
239
+ }
240
+ function onFloatingMouseLeave(event) {
241
+ if (isClickLikeOpenEvent()) return;
242
+ if (context.triggerElements?.hasElement(event.relatedTarget)) {
243
+ return;
244
+ }
245
+ closeWithDelay(event, false);
246
+ }
247
+ if ((0, import_utils.isElement)(elements.domReference)) {
248
+ const reference2 = elements.domReference;
249
+ const floating = elements.floating;
250
+ if (open) {
251
+ reference2.addEventListener("mouseleave", onScrollMouseLeave);
252
+ }
253
+ if (move) {
254
+ reference2.addEventListener("mousemove", onReferenceMouseEnter, {
255
+ once: true
256
+ });
257
+ }
258
+ reference2.addEventListener("mouseenter", onReferenceMouseEnter);
259
+ reference2.addEventListener("mouseleave", onReferenceMouseLeave);
260
+ if (floating) {
261
+ floating.addEventListener("mouseleave", onScrollMouseLeave);
262
+ floating.addEventListener("mouseenter", onFloatingMouseEnter);
263
+ floating.addEventListener("mouseleave", onFloatingMouseLeave);
264
+ }
265
+ return () => {
266
+ if (open) {
267
+ reference2.removeEventListener("mouseleave", onScrollMouseLeave);
268
+ }
269
+ if (move) {
270
+ reference2.removeEventListener("mousemove", onReferenceMouseEnter);
271
+ }
272
+ reference2.removeEventListener("mouseenter", onReferenceMouseEnter);
273
+ reference2.removeEventListener("mouseleave", onReferenceMouseLeave);
274
+ if (floating) {
275
+ floating.removeEventListener("mouseleave", onScrollMouseLeave);
276
+ floating.removeEventListener("mouseenter", onFloatingMouseEnter);
277
+ floating.removeEventListener("mouseleave", onFloatingMouseLeave);
278
+ }
279
+ cleanupMouseMoveHandler();
280
+ };
281
+ }
282
+ }, [elements, enabled, context, mouseOnly, move, open, dataRef]);
283
+ React.useLayoutEffect(() => {
284
+ if (!enabled) return;
285
+ if (open && handleCloseRef.current?.__options?.blockPointerEvents && isHoverOpen()) {
286
+ performedPointerEventsMutationRef.current = true;
287
+ const floatingEl = elements.floating;
288
+ if ((0, import_utils.isElement)(elements.domReference) && floatingEl) {
289
+ const body = (0, import_utils.getDocument)(elements.floating).body;
290
+ body.setAttribute(safePolygonIdentifier, "");
291
+ const ref = elements.domReference;
292
+ body.style.pointerEvents = "none";
293
+ ref.style.pointerEvents = "auto";
294
+ floatingEl.style.pointerEvents = "auto";
295
+ return () => {
296
+ body.style.pointerEvents = "";
297
+ ref.style.pointerEvents = "";
298
+ floatingEl.style.pointerEvents = "";
299
+ };
300
+ }
301
+ }
302
+ }, [enabled, open, elements, isHoverOpen]);
303
+ React.useLayoutEffect(() => {
304
+ if (!open) {
305
+ pointerTypeRef.current = void 0;
306
+ restTimeoutPendingRef.current = false;
307
+ cleanupMouseMoveHandler();
308
+ clearPointerEvents();
309
+ }
310
+ }, [open]);
311
+ React.useEffect(() => {
312
+ return () => {
313
+ cleanupMouseMoveHandler();
314
+ (0, import_utils.clearTimeoutIfSet)(timeoutRef);
315
+ (0, import_utils.clearTimeoutIfSet)(restTimeoutRef);
316
+ clearPointerEvents();
317
+ };
318
+ }, [enabled, elements.domReference]);
319
+ const reference = React.useMemo(() => {
320
+ function setPointerRef(event) {
321
+ pointerTypeRef.current = event.pointerType;
322
+ }
323
+ return {
324
+ onPointerDown: setPointerRef,
325
+ onPointerEnter: setPointerRef,
326
+ onMouseMove(event) {
327
+ const {
328
+ nativeEvent
329
+ } = event;
330
+ function handleMouseMove() {
331
+ if (!blockMouseMoveRef.current && !openRef.current) {
332
+ stableOnOpenChange(true, nativeEvent, "hover");
333
+ }
334
+ }
335
+ if (mouseOnly && !(0, import_utils.isMouseLikePointerType)(pointerTypeRef.current)) {
336
+ return;
337
+ }
338
+ if (open || restMsRef.current === 0) {
339
+ return;
340
+ }
341
+ if (restTimeoutPendingRef.current && event.movementX ** 2 + event.movementY ** 2 < 2) {
342
+ return;
343
+ }
344
+ (0, import_utils.clearTimeoutIfSet)(restTimeoutRef);
345
+ if (pointerTypeRef.current === "touch") {
346
+ handleMouseMove();
347
+ } else {
348
+ restTimeoutPendingRef.current = true;
349
+ restTimeoutRef.current = window.setTimeout(handleMouseMove, restMsRef.current);
350
+ }
351
+ }
352
+ };
353
+ }, [mouseOnly, open]);
354
+ return React.useMemo(() => enabled ? {
355
+ reference
356
+ } : {}, [enabled, reference]);
357
+ }