@react-aria/interactions 3.21.1 → 3.21.2

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 (88) hide show
  1. package/dist/PressResponder.main.js +62 -0
  2. package/dist/PressResponder.main.js.map +1 -0
  3. package/dist/PressResponder.mjs +52 -0
  4. package/dist/PressResponder.module.js +52 -0
  5. package/dist/PressResponder.module.js.map +1 -0
  6. package/dist/Pressable.main.js +43 -0
  7. package/dist/Pressable.main.js.map +1 -0
  8. package/dist/Pressable.mjs +34 -0
  9. package/dist/Pressable.module.js +34 -0
  10. package/dist/Pressable.module.js.map +1 -0
  11. package/dist/context.main.js +30 -0
  12. package/dist/context.main.js.map +1 -0
  13. package/dist/context.mjs +21 -0
  14. package/dist/context.module.js +21 -0
  15. package/dist/context.module.js.map +1 -0
  16. package/dist/createEventHandler.main.js +42 -0
  17. package/dist/createEventHandler.main.js.map +1 -0
  18. package/dist/createEventHandler.mjs +37 -0
  19. package/dist/createEventHandler.module.js +37 -0
  20. package/dist/createEventHandler.module.js.map +1 -0
  21. package/dist/import.mjs +12 -1771
  22. package/dist/main.js +31 -1794
  23. package/dist/main.js.map +1 -1
  24. package/dist/module.js +12 -1771
  25. package/dist/module.js.map +1 -1
  26. package/dist/textSelection.main.js +77 -0
  27. package/dist/textSelection.main.js.map +1 -0
  28. package/dist/textSelection.mjs +71 -0
  29. package/dist/textSelection.module.js +71 -0
  30. package/dist/textSelection.module.js.map +1 -0
  31. package/dist/types.d.ts.map +1 -1
  32. package/dist/useFocus.main.js +64 -0
  33. package/dist/useFocus.main.js.map +1 -0
  34. package/dist/useFocus.mjs +59 -0
  35. package/dist/useFocus.module.js +59 -0
  36. package/dist/useFocus.module.js.map +1 -0
  37. package/dist/useFocusVisible.main.js +248 -0
  38. package/dist/useFocusVisible.main.js.map +1 -0
  39. package/dist/useFocusVisible.mjs +237 -0
  40. package/dist/useFocusVisible.module.js +237 -0
  41. package/dist/useFocusVisible.module.js.map +1 -0
  42. package/dist/useFocusWithin.main.js +76 -0
  43. package/dist/useFocusWithin.main.js.map +1 -0
  44. package/dist/useFocusWithin.mjs +71 -0
  45. package/dist/useFocusWithin.module.js +71 -0
  46. package/dist/useFocusWithin.module.js.map +1 -0
  47. package/dist/useHover.main.js +142 -0
  48. package/dist/useHover.main.js.map +1 -0
  49. package/dist/useHover.mjs +137 -0
  50. package/dist/useHover.module.js +137 -0
  51. package/dist/useHover.module.js.map +1 -0
  52. package/dist/useInteractOutside.main.js +101 -0
  53. package/dist/useInteractOutside.main.js.map +1 -0
  54. package/dist/useInteractOutside.mjs +96 -0
  55. package/dist/useInteractOutside.module.js +96 -0
  56. package/dist/useInteractOutside.module.js.map +1 -0
  57. package/dist/useKeyboard.main.js +30 -0
  58. package/dist/useKeyboard.main.js.map +1 -0
  59. package/dist/useKeyboard.mjs +25 -0
  60. package/dist/useKeyboard.module.js +25 -0
  61. package/dist/useKeyboard.module.js.map +1 -0
  62. package/dist/useLongPress.main.js +84 -0
  63. package/dist/useLongPress.main.js.map +1 -0
  64. package/dist/useLongPress.mjs +79 -0
  65. package/dist/useLongPress.module.js +79 -0
  66. package/dist/useLongPress.module.js.map +1 -0
  67. package/dist/useMove.main.js +236 -0
  68. package/dist/useMove.main.js.map +1 -0
  69. package/dist/useMove.mjs +231 -0
  70. package/dist/useMove.module.js +231 -0
  71. package/dist/useMove.module.js.map +1 -0
  72. package/dist/usePress.main.js +571 -0
  73. package/dist/usePress.main.js.map +1 -0
  74. package/dist/usePress.mjs +566 -0
  75. package/dist/usePress.module.js +566 -0
  76. package/dist/usePress.module.js.map +1 -0
  77. package/dist/useScrollWheel.main.js +41 -0
  78. package/dist/useScrollWheel.main.js.map +1 -0
  79. package/dist/useScrollWheel.mjs +36 -0
  80. package/dist/useScrollWheel.module.js +36 -0
  81. package/dist/useScrollWheel.module.js.map +1 -0
  82. package/dist/utils.main.js +120 -0
  83. package/dist/utils.main.js.map +1 -0
  84. package/dist/utils.mjs +115 -0
  85. package/dist/utils.module.js +115 -0
  86. package/dist/utils.module.js.map +1 -0
  87. package/package.json +5 -5
  88. package/src/useFocus.ts +5 -1
@@ -0,0 +1,79 @@
1
+ import {usePress as $f6c31cce2adf654f$export$45712eceda6fad21} from "./usePress.module.js";
2
+ import {useGlobalListeners as $4k2kv$useGlobalListeners, useDescription as $4k2kv$useDescription, mergeProps as $4k2kv$mergeProps} from "@react-aria/utils";
3
+ import {useRef as $4k2kv$useRef} from "react";
4
+
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ const $8a26561d2877236e$var$DEFAULT_THRESHOLD = 500;
19
+ function $8a26561d2877236e$export$c24ed0104d07eab9(props) {
20
+ let { isDisabled: isDisabled, onLongPressStart: onLongPressStart, onLongPressEnd: onLongPressEnd, onLongPress: onLongPress, threshold: threshold = $8a26561d2877236e$var$DEFAULT_THRESHOLD, accessibilityDescription: accessibilityDescription } = props;
21
+ const timeRef = (0, $4k2kv$useRef)();
22
+ let { addGlobalListener: addGlobalListener, removeGlobalListener: removeGlobalListener } = (0, $4k2kv$useGlobalListeners)();
23
+ let { pressProps: pressProps } = (0, $f6c31cce2adf654f$export$45712eceda6fad21)({
24
+ isDisabled: isDisabled,
25
+ onPressStart (e) {
26
+ e.continuePropagation();
27
+ if (e.pointerType === "mouse" || e.pointerType === "touch") {
28
+ if (onLongPressStart) onLongPressStart({
29
+ ...e,
30
+ type: "longpressstart"
31
+ });
32
+ timeRef.current = setTimeout(()=>{
33
+ // Prevent other usePress handlers from also handling this event.
34
+ e.target.dispatchEvent(new PointerEvent("pointercancel", {
35
+ bubbles: true
36
+ }));
37
+ if (onLongPress) onLongPress({
38
+ ...e,
39
+ type: "longpress"
40
+ });
41
+ timeRef.current = undefined;
42
+ }, threshold);
43
+ // Prevent context menu, which may be opened on long press on touch devices
44
+ if (e.pointerType === "touch") {
45
+ let onContextMenu = (e)=>{
46
+ e.preventDefault();
47
+ };
48
+ addGlobalListener(e.target, "contextmenu", onContextMenu, {
49
+ once: true
50
+ });
51
+ addGlobalListener(window, "pointerup", ()=>{
52
+ // If no contextmenu event is fired quickly after pointerup, remove the handler
53
+ // so future context menu events outside a long press are not prevented.
54
+ setTimeout(()=>{
55
+ removeGlobalListener(e.target, "contextmenu", onContextMenu);
56
+ }, 30);
57
+ }, {
58
+ once: true
59
+ });
60
+ }
61
+ }
62
+ },
63
+ onPressEnd (e) {
64
+ if (timeRef.current) clearTimeout(timeRef.current);
65
+ if (onLongPressEnd && (e.pointerType === "mouse" || e.pointerType === "touch")) onLongPressEnd({
66
+ ...e,
67
+ type: "longpressend"
68
+ });
69
+ }
70
+ });
71
+ let descriptionProps = (0, $4k2kv$useDescription)(onLongPress && !isDisabled ? accessibilityDescription : undefined);
72
+ return {
73
+ longPressProps: (0, $4k2kv$mergeProps)(pressProps, descriptionProps)
74
+ };
75
+ }
76
+
77
+
78
+ export {$8a26561d2877236e$export$c24ed0104d07eab9 as useLongPress};
79
+ //# sourceMappingURL=useLongPress.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAuCD,MAAM,0CAAoB;AAMnB,SAAS,0CAAa,KAAqB;IAChD,IAAI,cACF,UAAU,oBACV,gBAAgB,kBAChB,cAAc,eACd,WAAW,aACX,YAAY,mEACZ,wBAAwB,EACzB,GAAG;IAEJ,MAAM,UAAU,CAAA,GAAA,aAAK;IACrB,IAAI,qBAAC,iBAAiB,wBAAE,oBAAoB,EAAC,GAAG,CAAA,GAAA,yBAAiB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served.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DOMAttributes, LongPressEvent} from '@react-types/shared';\nimport {mergeProps, useDescription, useGlobalListeners} from '@react-aria/utils';\nimport {usePress} from './usePress';\nimport {useRef} from 'react';\n\nexport interface LongPressProps {\n /** Whether long press events should be disabled. */\n isDisabled?: boolean,\n /** Handler that is called when a long press interaction starts. */\n onLongPressStart?: (e: LongPressEvent) => void,\n /**\n * Handler that is called when a long press interaction ends, either\n * over the target or when the pointer leaves the target.\n */\n onLongPressEnd?: (e: LongPressEvent) => void,\n /**\n * Handler that is called when the threshold time is met while\n * the press is over the target.\n */\n onLongPress?: (e: LongPressEvent) => void,\n /**\n * The amount of time in milliseconds to wait before triggering a long press.\n * @default 500ms\n */\n threshold?: number,\n /**\n * A description for assistive techology users indicating that a long press\n * action is available, e.g. \"Long press to open menu\".\n */\n accessibilityDescription?: string\n}\n\nexport interface LongPressResult {\n /** Props to spread on the target element. */\n longPressProps: DOMAttributes\n}\n\nconst DEFAULT_THRESHOLD = 500;\n\n/**\n * Handles long press interactions across mouse and touch devices. Supports a customizable time threshold,\n * accessibility description, and normalizes behavior across browsers and devices.\n */\nexport function useLongPress(props: LongPressProps): LongPressResult {\n let {\n isDisabled,\n onLongPressStart,\n onLongPressEnd,\n onLongPress,\n threshold = DEFAULT_THRESHOLD,\n accessibilityDescription\n } = props;\n\n const timeRef = useRef<ReturnType<typeof setTimeout> | undefined>();\n let {addGlobalListener, removeGlobalListener} = useGlobalListeners();\n\n let {pressProps} = usePress({\n isDisabled,\n onPressStart(e) {\n e.continuePropagation();\n if (e.pointerType === 'mouse' || e.pointerType === 'touch') {\n if (onLongPressStart) {\n onLongPressStart({\n ...e,\n type: 'longpressstart'\n });\n }\n\n timeRef.current = setTimeout(() => {\n // Prevent other usePress handlers from also handling this event.\n e.target.dispatchEvent(new PointerEvent('pointercancel', {bubbles: true}));\n if (onLongPress) {\n onLongPress({\n ...e,\n type: 'longpress'\n });\n }\n timeRef.current = undefined;\n }, threshold);\n\n // Prevent context menu, which may be opened on long press on touch devices\n if (e.pointerType === 'touch') {\n let onContextMenu = e => {\n e.preventDefault();\n };\n\n addGlobalListener(e.target, 'contextmenu', onContextMenu, {once: true});\n addGlobalListener(window, 'pointerup', () => {\n // If no contextmenu event is fired quickly after pointerup, remove the handler\n // so future context menu events outside a long press are not prevented.\n setTimeout(() => {\n removeGlobalListener(e.target, 'contextmenu', onContextMenu);\n }, 30);\n }, {once: true});\n }\n }\n },\n onPressEnd(e) {\n if (timeRef.current) {\n clearTimeout(timeRef.current);\n }\n\n if (onLongPressEnd && (e.pointerType === 'mouse' || e.pointerType === 'touch')) {\n onLongPressEnd({\n ...e,\n type: 'longpressend'\n });\n }\n }\n });\n\n let descriptionProps = useDescription(onLongPress && !isDisabled ? accessibilityDescription : undefined);\n\n return {\n longPressProps: mergeProps(pressProps, descriptionProps)\n };\n}\n"],"names":[],"version":3,"file":"useLongPress.module.js.map"}
@@ -0,0 +1,236 @@
1
+ var $f7e14e656343df57$exports = require("./textSelection.main.js");
2
+ var $cvDGj$react = require("react");
3
+ var $cvDGj$reactariautils = require("@react-aria/utils");
4
+
5
+
6
+ function $parcel$export(e, n, v, s) {
7
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
+ }
9
+
10
+ $parcel$export(module.exports, "useMove", () => $c09386fc48fa427d$export$36da96379f79f245);
11
+ /*
12
+ * Copyright 2020 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */
22
+
23
+
24
+ function $c09386fc48fa427d$export$36da96379f79f245(props) {
25
+ let { onMoveStart: onMoveStart, onMove: onMove, onMoveEnd: onMoveEnd } = props;
26
+ let state = (0, $cvDGj$react.useRef)({
27
+ didMove: false,
28
+ lastPosition: null,
29
+ id: null
30
+ });
31
+ let { addGlobalListener: addGlobalListener, removeGlobalListener: removeGlobalListener } = (0, $cvDGj$reactariautils.useGlobalListeners)();
32
+ let move = (0, $cvDGj$reactariautils.useEffectEvent)((originalEvent, pointerType, deltaX, deltaY)=>{
33
+ if (deltaX === 0 && deltaY === 0) return;
34
+ if (!state.current.didMove) {
35
+ state.current.didMove = true;
36
+ onMoveStart === null || onMoveStart === void 0 ? void 0 : onMoveStart({
37
+ type: "movestart",
38
+ pointerType: pointerType,
39
+ shiftKey: originalEvent.shiftKey,
40
+ metaKey: originalEvent.metaKey,
41
+ ctrlKey: originalEvent.ctrlKey,
42
+ altKey: originalEvent.altKey
43
+ });
44
+ }
45
+ onMove === null || onMove === void 0 ? void 0 : onMove({
46
+ type: "move",
47
+ pointerType: pointerType,
48
+ deltaX: deltaX,
49
+ deltaY: deltaY,
50
+ shiftKey: originalEvent.shiftKey,
51
+ metaKey: originalEvent.metaKey,
52
+ ctrlKey: originalEvent.ctrlKey,
53
+ altKey: originalEvent.altKey
54
+ });
55
+ });
56
+ let end = (0, $cvDGj$reactariautils.useEffectEvent)((originalEvent, pointerType)=>{
57
+ (0, $f7e14e656343df57$exports.restoreTextSelection)();
58
+ if (state.current.didMove) onMoveEnd === null || onMoveEnd === void 0 ? void 0 : onMoveEnd({
59
+ type: "moveend",
60
+ pointerType: pointerType,
61
+ shiftKey: originalEvent.shiftKey,
62
+ metaKey: originalEvent.metaKey,
63
+ ctrlKey: originalEvent.ctrlKey,
64
+ altKey: originalEvent.altKey
65
+ });
66
+ });
67
+ let moveProps = (0, $cvDGj$react.useMemo)(()=>{
68
+ let moveProps = {};
69
+ let start = ()=>{
70
+ (0, $f7e14e656343df57$exports.disableTextSelection)();
71
+ state.current.didMove = false;
72
+ };
73
+ if (typeof PointerEvent === "undefined") {
74
+ let onMouseMove = (e)=>{
75
+ if (e.button === 0) {
76
+ var _state_current_lastPosition, _state_current_lastPosition1;
77
+ var _state_current_lastPosition_pageX, _state_current_lastPosition_pageY;
78
+ move(e, "mouse", e.pageX - ((_state_current_lastPosition_pageX = (_state_current_lastPosition = state.current.lastPosition) === null || _state_current_lastPosition === void 0 ? void 0 : _state_current_lastPosition.pageX) !== null && _state_current_lastPosition_pageX !== void 0 ? _state_current_lastPosition_pageX : 0), e.pageY - ((_state_current_lastPosition_pageY = (_state_current_lastPosition1 = state.current.lastPosition) === null || _state_current_lastPosition1 === void 0 ? void 0 : _state_current_lastPosition1.pageY) !== null && _state_current_lastPosition_pageY !== void 0 ? _state_current_lastPosition_pageY : 0));
79
+ state.current.lastPosition = {
80
+ pageX: e.pageX,
81
+ pageY: e.pageY
82
+ };
83
+ }
84
+ };
85
+ let onMouseUp = (e)=>{
86
+ if (e.button === 0) {
87
+ end(e, "mouse");
88
+ removeGlobalListener(window, "mousemove", onMouseMove, false);
89
+ removeGlobalListener(window, "mouseup", onMouseUp, false);
90
+ }
91
+ };
92
+ moveProps.onMouseDown = (e)=>{
93
+ if (e.button === 0) {
94
+ start();
95
+ e.stopPropagation();
96
+ e.preventDefault();
97
+ state.current.lastPosition = {
98
+ pageX: e.pageX,
99
+ pageY: e.pageY
100
+ };
101
+ addGlobalListener(window, "mousemove", onMouseMove, false);
102
+ addGlobalListener(window, "mouseup", onMouseUp, false);
103
+ }
104
+ };
105
+ let onTouchMove = (e)=>{
106
+ let touch = [
107
+ ...e.changedTouches
108
+ ].findIndex(({ identifier: identifier })=>identifier === state.current.id);
109
+ if (touch >= 0) {
110
+ var _state_current_lastPosition, _state_current_lastPosition1;
111
+ let { pageX: pageX, pageY: pageY } = e.changedTouches[touch];
112
+ var _state_current_lastPosition_pageX, _state_current_lastPosition_pageY;
113
+ move(e, "touch", pageX - ((_state_current_lastPosition_pageX = (_state_current_lastPosition = state.current.lastPosition) === null || _state_current_lastPosition === void 0 ? void 0 : _state_current_lastPosition.pageX) !== null && _state_current_lastPosition_pageX !== void 0 ? _state_current_lastPosition_pageX : 0), pageY - ((_state_current_lastPosition_pageY = (_state_current_lastPosition1 = state.current.lastPosition) === null || _state_current_lastPosition1 === void 0 ? void 0 : _state_current_lastPosition1.pageY) !== null && _state_current_lastPosition_pageY !== void 0 ? _state_current_lastPosition_pageY : 0));
114
+ state.current.lastPosition = {
115
+ pageX: pageX,
116
+ pageY: pageY
117
+ };
118
+ }
119
+ };
120
+ let onTouchEnd = (e)=>{
121
+ let touch = [
122
+ ...e.changedTouches
123
+ ].findIndex(({ identifier: identifier })=>identifier === state.current.id);
124
+ if (touch >= 0) {
125
+ end(e, "touch");
126
+ state.current.id = null;
127
+ removeGlobalListener(window, "touchmove", onTouchMove);
128
+ removeGlobalListener(window, "touchend", onTouchEnd);
129
+ removeGlobalListener(window, "touchcancel", onTouchEnd);
130
+ }
131
+ };
132
+ moveProps.onTouchStart = (e)=>{
133
+ if (e.changedTouches.length === 0 || state.current.id != null) return;
134
+ let { pageX: pageX, pageY: pageY, identifier: identifier } = e.changedTouches[0];
135
+ start();
136
+ e.stopPropagation();
137
+ e.preventDefault();
138
+ state.current.lastPosition = {
139
+ pageX: pageX,
140
+ pageY: pageY
141
+ };
142
+ state.current.id = identifier;
143
+ addGlobalListener(window, "touchmove", onTouchMove, false);
144
+ addGlobalListener(window, "touchend", onTouchEnd, false);
145
+ addGlobalListener(window, "touchcancel", onTouchEnd, false);
146
+ };
147
+ } else {
148
+ let onPointerMove = (e)=>{
149
+ if (e.pointerId === state.current.id) {
150
+ var _state_current_lastPosition, _state_current_lastPosition1;
151
+ let pointerType = e.pointerType || "mouse";
152
+ var _state_current_lastPosition_pageX, _state_current_lastPosition_pageY;
153
+ // Problems with PointerEvent#movementX/movementY:
154
+ // 1. it is always 0 on macOS Safari.
155
+ // 2. On Chrome Android, it's scaled by devicePixelRatio, but not on Chrome macOS
156
+ move(e, pointerType, e.pageX - ((_state_current_lastPosition_pageX = (_state_current_lastPosition = state.current.lastPosition) === null || _state_current_lastPosition === void 0 ? void 0 : _state_current_lastPosition.pageX) !== null && _state_current_lastPosition_pageX !== void 0 ? _state_current_lastPosition_pageX : 0), e.pageY - ((_state_current_lastPosition_pageY = (_state_current_lastPosition1 = state.current.lastPosition) === null || _state_current_lastPosition1 === void 0 ? void 0 : _state_current_lastPosition1.pageY) !== null && _state_current_lastPosition_pageY !== void 0 ? _state_current_lastPosition_pageY : 0));
157
+ state.current.lastPosition = {
158
+ pageX: e.pageX,
159
+ pageY: e.pageY
160
+ };
161
+ }
162
+ };
163
+ let onPointerUp = (e)=>{
164
+ if (e.pointerId === state.current.id) {
165
+ let pointerType = e.pointerType || "mouse";
166
+ end(e, pointerType);
167
+ state.current.id = null;
168
+ removeGlobalListener(window, "pointermove", onPointerMove, false);
169
+ removeGlobalListener(window, "pointerup", onPointerUp, false);
170
+ removeGlobalListener(window, "pointercancel", onPointerUp, false);
171
+ }
172
+ };
173
+ moveProps.onPointerDown = (e)=>{
174
+ if (e.button === 0 && state.current.id == null) {
175
+ start();
176
+ e.stopPropagation();
177
+ e.preventDefault();
178
+ state.current.lastPosition = {
179
+ pageX: e.pageX,
180
+ pageY: e.pageY
181
+ };
182
+ state.current.id = e.pointerId;
183
+ addGlobalListener(window, "pointermove", onPointerMove, false);
184
+ addGlobalListener(window, "pointerup", onPointerUp, false);
185
+ addGlobalListener(window, "pointercancel", onPointerUp, false);
186
+ }
187
+ };
188
+ }
189
+ let triggerKeyboardMove = (e, deltaX, deltaY)=>{
190
+ start();
191
+ move(e, "keyboard", deltaX, deltaY);
192
+ end(e, "keyboard");
193
+ };
194
+ moveProps.onKeyDown = (e)=>{
195
+ switch(e.key){
196
+ case "Left":
197
+ case "ArrowLeft":
198
+ e.preventDefault();
199
+ e.stopPropagation();
200
+ triggerKeyboardMove(e, -1, 0);
201
+ break;
202
+ case "Right":
203
+ case "ArrowRight":
204
+ e.preventDefault();
205
+ e.stopPropagation();
206
+ triggerKeyboardMove(e, 1, 0);
207
+ break;
208
+ case "Up":
209
+ case "ArrowUp":
210
+ e.preventDefault();
211
+ e.stopPropagation();
212
+ triggerKeyboardMove(e, 0, -1);
213
+ break;
214
+ case "Down":
215
+ case "ArrowDown":
216
+ e.preventDefault();
217
+ e.stopPropagation();
218
+ triggerKeyboardMove(e, 0, 1);
219
+ break;
220
+ }
221
+ };
222
+ return moveProps;
223
+ }, [
224
+ state,
225
+ addGlobalListener,
226
+ removeGlobalListener,
227
+ move,
228
+ end
229
+ ]);
230
+ return {
231
+ moveProps: moveProps
232
+ };
233
+ }
234
+
235
+
236
+ //# sourceMappingURL=useMove.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AAwBM,SAAS,0CAAQ,KAAiB;IACvC,IAAI,eAAC,WAAW,UAAE,MAAM,aAAE,SAAS,EAAC,GAAG;IAEvC,IAAI,QAAQ,CAAA,GAAA,mBAAK,EAId;QAAC,SAAS;QAAO,cAAc;QAAM,IAAI;IAAI;IAEhD,IAAI,qBAAC,iBAAiB,wBAAE,oBAAoB,EAAC,GAAG,CAAA,GAAA,wCAAiB;IAEjE,IAAI,OAAO,CAAA,GAAA,oCAAa,EAAE,CAAC,eAA0B,aAA0B,QAAgB;QAC7F,IAAI,WAAW,KAAK,WAAW,GAC7B;QAGF,IAAI,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE;YAC1B,MAAM,OAAO,CAAC,OAAO,GAAG;YACxB,wBAAA,kCAAA,YAAc;gBACZ,MAAM;6BACN;gBACA,UAAU,cAAc,QAAQ;gBACh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BAC1B;YACJ;QACF;QAEA,OAAO;IACT,GAAG;QAAC;QAAO;QAAmB;QAAsB;QAAM;KAAI;IAE9D,OAAO;mBAAC;IAAS;AACnB","sources":["packages/@react-aria/interactions/src/useMove.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {disableTextSelection, restoreTextSelection} from './textSelection';\nimport {DOMAttributes, MoveEvents, PointerType} from '@react-types/shared';\nimport React, {useMemo, useRef} from 'react';\nimport {useEffectEvent, useGlobalListeners} from '@react-aria/utils';\n\nexport interface MoveResult {\n /** Props to spread on the target element. */\n moveProps: DOMAttributes\n}\n\ninterface EventBase {\n shiftKey: boolean,\n ctrlKey: boolean,\n metaKey: boolean,\n altKey: boolean\n}\n\n/**\n * Handles move interactions across mouse, touch, and keyboard, including dragging with\n * the mouse or touch, and using the arrow keys. Normalizes behavior across browsers and\n * platforms, and ignores emulated mouse events on touch devices.\n */\nexport function useMove(props: MoveEvents): MoveResult {\n let {onMoveStart, onMove, onMoveEnd} = props;\n\n let state = useRef<{\n didMove: boolean,\n lastPosition: {pageX: number, pageY: number} | null,\n id: number | null\n }>({didMove: false, lastPosition: null, id: null});\n\n let {addGlobalListener, removeGlobalListener} = useGlobalListeners();\n\n let move = useEffectEvent((originalEvent: EventBase, pointerType: PointerType, deltaX: number, deltaY: number) => {\n if (deltaX === 0 && deltaY === 0) {\n return;\n }\n\n if (!state.current.didMove) {\n state.current.didMove = true;\n onMoveStart?.({\n type: 'movestart',\n pointerType,\n shiftKey: originalEvent.shiftKey,\n metaKey: originalEvent.metaKey,\n ctrlKey: originalEvent.ctrlKey,\n altKey: originalEvent.altKey\n });\n }\n onMove?.({\n type: 'move',\n pointerType,\n deltaX: deltaX,\n deltaY: deltaY,\n shiftKey: originalEvent.shiftKey,\n metaKey: originalEvent.metaKey,\n ctrlKey: originalEvent.ctrlKey,\n altKey: originalEvent.altKey\n });\n });\n\n let end = useEffectEvent((originalEvent: EventBase, pointerType: PointerType) => {\n restoreTextSelection();\n if (state.current.didMove) {\n onMoveEnd?.({\n type: 'moveend',\n pointerType,\n shiftKey: originalEvent.shiftKey,\n metaKey: originalEvent.metaKey,\n ctrlKey: originalEvent.ctrlKey,\n altKey: originalEvent.altKey\n });\n }\n });\n\n let moveProps = useMemo(() => {\n let moveProps: DOMAttributes = {};\n\n let start = () => {\n disableTextSelection();\n state.current.didMove = false;\n };\n\n if (typeof PointerEvent === 'undefined') {\n let onMouseMove = (e: MouseEvent) => {\n if (e.button === 0) {\n move(e, 'mouse', e.pageX - (state.current.lastPosition?.pageX ?? 0), e.pageY - (state.current.lastPosition?.pageY ?? 0));\n state.current.lastPosition = {pageX: e.pageX, pageY: e.pageY};\n }\n };\n let onMouseUp = (e: MouseEvent) => {\n if (e.button === 0) {\n end(e, 'mouse');\n removeGlobalListener(window, 'mousemove', onMouseMove, false);\n removeGlobalListener(window, 'mouseup', onMouseUp, false);\n }\n };\n moveProps.onMouseDown = (e: React.MouseEvent) => {\n if (e.button === 0) {\n start();\n e.stopPropagation();\n e.preventDefault();\n state.current.lastPosition = {pageX: e.pageX, pageY: e.pageY};\n addGlobalListener(window, 'mousemove', onMouseMove, false);\n addGlobalListener(window, 'mouseup', onMouseUp, false);\n }\n };\n\n let onTouchMove = (e: TouchEvent) => {\n let touch = [...e.changedTouches].findIndex(({identifier}) => identifier === state.current.id);\n if (touch >= 0) {\n let {pageX, pageY} = e.changedTouches[touch];\n move(e, 'touch', pageX - (state.current.lastPosition?.pageX ?? 0), pageY - (state.current.lastPosition?.pageY ?? 0));\n state.current.lastPosition = {pageX, pageY};\n }\n };\n let onTouchEnd = (e: TouchEvent) => {\n let touch = [...e.changedTouches].findIndex(({identifier}) => identifier === state.current.id);\n if (touch >= 0) {\n end(e, 'touch');\n state.current.id = null;\n removeGlobalListener(window, 'touchmove', onTouchMove);\n removeGlobalListener(window, 'touchend', onTouchEnd);\n removeGlobalListener(window, 'touchcancel', onTouchEnd);\n }\n };\n moveProps.onTouchStart = (e: React.TouchEvent) => {\n if (e.changedTouches.length === 0 || state.current.id != null) {\n return;\n }\n\n let {pageX, pageY, identifier} = e.changedTouches[0];\n start();\n e.stopPropagation();\n e.preventDefault();\n state.current.lastPosition = {pageX, pageY};\n state.current.id = identifier;\n addGlobalListener(window, 'touchmove', onTouchMove, false);\n addGlobalListener(window, 'touchend', onTouchEnd, false);\n addGlobalListener(window, 'touchcancel', onTouchEnd, false);\n };\n } else {\n let onPointerMove = (e: PointerEvent) => {\n if (e.pointerId === state.current.id) {\n let pointerType = (e.pointerType || 'mouse') as PointerType;\n\n // Problems with PointerEvent#movementX/movementY:\n // 1. it is always 0 on macOS Safari.\n // 2. On Chrome Android, it's scaled by devicePixelRatio, but not on Chrome macOS\n move(e, pointerType, e.pageX - (state.current.lastPosition?.pageX ?? 0), e.pageY - (state.current.lastPosition?.pageY ?? 0));\n state.current.lastPosition = {pageX: e.pageX, pageY: e.pageY};\n }\n };\n\n let onPointerUp = (e: PointerEvent) => {\n if (e.pointerId === state.current.id) {\n let pointerType = (e.pointerType || 'mouse') as PointerType;\n end(e, pointerType);\n state.current.id = null;\n removeGlobalListener(window, 'pointermove', onPointerMove, false);\n removeGlobalListener(window, 'pointerup', onPointerUp, false);\n removeGlobalListener(window, 'pointercancel', onPointerUp, false);\n }\n };\n\n moveProps.onPointerDown = (e: React.PointerEvent) => {\n if (e.button === 0 && state.current.id == null) {\n start();\n e.stopPropagation();\n e.preventDefault();\n state.current.lastPosition = {pageX: e.pageX, pageY: e.pageY};\n state.current.id = e.pointerId;\n addGlobalListener(window, 'pointermove', onPointerMove, false);\n addGlobalListener(window, 'pointerup', onPointerUp, false);\n addGlobalListener(window, 'pointercancel', onPointerUp, false);\n }\n };\n }\n\n let triggerKeyboardMove = (e: EventBase, deltaX: number, deltaY: number) => {\n start();\n move(e, 'keyboard', deltaX, deltaY);\n end(e, 'keyboard');\n };\n\n moveProps.onKeyDown = (e) => {\n switch (e.key) {\n case 'Left':\n case 'ArrowLeft':\n e.preventDefault();\n e.stopPropagation();\n triggerKeyboardMove(e, -1, 0);\n break;\n case 'Right':\n case 'ArrowRight':\n e.preventDefault();\n e.stopPropagation();\n triggerKeyboardMove(e, 1, 0);\n break;\n case 'Up':\n case 'ArrowUp':\n e.preventDefault();\n e.stopPropagation();\n triggerKeyboardMove(e, 0, -1);\n break;\n case 'Down':\n case 'ArrowDown':\n e.preventDefault();\n e.stopPropagation();\n triggerKeyboardMove(e, 0, 1);\n break;\n }\n };\n\n return moveProps;\n }, [state, addGlobalListener, removeGlobalListener, move, end]);\n\n return {moveProps};\n}\n"],"names":[],"version":3,"file":"useMove.main.js.map"}
@@ -0,0 +1,231 @@
1
+ import {disableTextSelection as $14c0b72509d70225$export$16a4697467175487, restoreTextSelection as $14c0b72509d70225$export$b0d6fa1ab32e3295} from "./textSelection.mjs";
2
+ import {useRef as $5GN7j$useRef, useMemo as $5GN7j$useMemo} from "react";
3
+ import {useGlobalListeners as $5GN7j$useGlobalListeners, useEffectEvent as $5GN7j$useEffectEvent} from "@react-aria/utils";
4
+
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ function $e8a7022cf87cba2a$export$36da96379f79f245(props) {
19
+ let { onMoveStart: onMoveStart, onMove: onMove, onMoveEnd: onMoveEnd } = props;
20
+ let state = (0, $5GN7j$useRef)({
21
+ didMove: false,
22
+ lastPosition: null,
23
+ id: null
24
+ });
25
+ let { addGlobalListener: addGlobalListener, removeGlobalListener: removeGlobalListener } = (0, $5GN7j$useGlobalListeners)();
26
+ let move = (0, $5GN7j$useEffectEvent)((originalEvent, pointerType, deltaX, deltaY)=>{
27
+ if (deltaX === 0 && deltaY === 0) return;
28
+ if (!state.current.didMove) {
29
+ state.current.didMove = true;
30
+ onMoveStart === null || onMoveStart === void 0 ? void 0 : onMoveStart({
31
+ type: "movestart",
32
+ pointerType: pointerType,
33
+ shiftKey: originalEvent.shiftKey,
34
+ metaKey: originalEvent.metaKey,
35
+ ctrlKey: originalEvent.ctrlKey,
36
+ altKey: originalEvent.altKey
37
+ });
38
+ }
39
+ onMove === null || onMove === void 0 ? void 0 : onMove({
40
+ type: "move",
41
+ pointerType: pointerType,
42
+ deltaX: deltaX,
43
+ deltaY: deltaY,
44
+ shiftKey: originalEvent.shiftKey,
45
+ metaKey: originalEvent.metaKey,
46
+ ctrlKey: originalEvent.ctrlKey,
47
+ altKey: originalEvent.altKey
48
+ });
49
+ });
50
+ let end = (0, $5GN7j$useEffectEvent)((originalEvent, pointerType)=>{
51
+ (0, $14c0b72509d70225$export$b0d6fa1ab32e3295)();
52
+ if (state.current.didMove) onMoveEnd === null || onMoveEnd === void 0 ? void 0 : onMoveEnd({
53
+ type: "moveend",
54
+ pointerType: pointerType,
55
+ shiftKey: originalEvent.shiftKey,
56
+ metaKey: originalEvent.metaKey,
57
+ ctrlKey: originalEvent.ctrlKey,
58
+ altKey: originalEvent.altKey
59
+ });
60
+ });
61
+ let moveProps = (0, $5GN7j$useMemo)(()=>{
62
+ let moveProps = {};
63
+ let start = ()=>{
64
+ (0, $14c0b72509d70225$export$16a4697467175487)();
65
+ state.current.didMove = false;
66
+ };
67
+ if (typeof PointerEvent === "undefined") {
68
+ let onMouseMove = (e)=>{
69
+ if (e.button === 0) {
70
+ var _state_current_lastPosition, _state_current_lastPosition1;
71
+ var _state_current_lastPosition_pageX, _state_current_lastPosition_pageY;
72
+ move(e, "mouse", e.pageX - ((_state_current_lastPosition_pageX = (_state_current_lastPosition = state.current.lastPosition) === null || _state_current_lastPosition === void 0 ? void 0 : _state_current_lastPosition.pageX) !== null && _state_current_lastPosition_pageX !== void 0 ? _state_current_lastPosition_pageX : 0), e.pageY - ((_state_current_lastPosition_pageY = (_state_current_lastPosition1 = state.current.lastPosition) === null || _state_current_lastPosition1 === void 0 ? void 0 : _state_current_lastPosition1.pageY) !== null && _state_current_lastPosition_pageY !== void 0 ? _state_current_lastPosition_pageY : 0));
73
+ state.current.lastPosition = {
74
+ pageX: e.pageX,
75
+ pageY: e.pageY
76
+ };
77
+ }
78
+ };
79
+ let onMouseUp = (e)=>{
80
+ if (e.button === 0) {
81
+ end(e, "mouse");
82
+ removeGlobalListener(window, "mousemove", onMouseMove, false);
83
+ removeGlobalListener(window, "mouseup", onMouseUp, false);
84
+ }
85
+ };
86
+ moveProps.onMouseDown = (e)=>{
87
+ if (e.button === 0) {
88
+ start();
89
+ e.stopPropagation();
90
+ e.preventDefault();
91
+ state.current.lastPosition = {
92
+ pageX: e.pageX,
93
+ pageY: e.pageY
94
+ };
95
+ addGlobalListener(window, "mousemove", onMouseMove, false);
96
+ addGlobalListener(window, "mouseup", onMouseUp, false);
97
+ }
98
+ };
99
+ let onTouchMove = (e)=>{
100
+ let touch = [
101
+ ...e.changedTouches
102
+ ].findIndex(({ identifier: identifier })=>identifier === state.current.id);
103
+ if (touch >= 0) {
104
+ var _state_current_lastPosition, _state_current_lastPosition1;
105
+ let { pageX: pageX, pageY: pageY } = e.changedTouches[touch];
106
+ var _state_current_lastPosition_pageX, _state_current_lastPosition_pageY;
107
+ move(e, "touch", pageX - ((_state_current_lastPosition_pageX = (_state_current_lastPosition = state.current.lastPosition) === null || _state_current_lastPosition === void 0 ? void 0 : _state_current_lastPosition.pageX) !== null && _state_current_lastPosition_pageX !== void 0 ? _state_current_lastPosition_pageX : 0), pageY - ((_state_current_lastPosition_pageY = (_state_current_lastPosition1 = state.current.lastPosition) === null || _state_current_lastPosition1 === void 0 ? void 0 : _state_current_lastPosition1.pageY) !== null && _state_current_lastPosition_pageY !== void 0 ? _state_current_lastPosition_pageY : 0));
108
+ state.current.lastPosition = {
109
+ pageX: pageX,
110
+ pageY: pageY
111
+ };
112
+ }
113
+ };
114
+ let onTouchEnd = (e)=>{
115
+ let touch = [
116
+ ...e.changedTouches
117
+ ].findIndex(({ identifier: identifier })=>identifier === state.current.id);
118
+ if (touch >= 0) {
119
+ end(e, "touch");
120
+ state.current.id = null;
121
+ removeGlobalListener(window, "touchmove", onTouchMove);
122
+ removeGlobalListener(window, "touchend", onTouchEnd);
123
+ removeGlobalListener(window, "touchcancel", onTouchEnd);
124
+ }
125
+ };
126
+ moveProps.onTouchStart = (e)=>{
127
+ if (e.changedTouches.length === 0 || state.current.id != null) return;
128
+ let { pageX: pageX, pageY: pageY, identifier: identifier } = e.changedTouches[0];
129
+ start();
130
+ e.stopPropagation();
131
+ e.preventDefault();
132
+ state.current.lastPosition = {
133
+ pageX: pageX,
134
+ pageY: pageY
135
+ };
136
+ state.current.id = identifier;
137
+ addGlobalListener(window, "touchmove", onTouchMove, false);
138
+ addGlobalListener(window, "touchend", onTouchEnd, false);
139
+ addGlobalListener(window, "touchcancel", onTouchEnd, false);
140
+ };
141
+ } else {
142
+ let onPointerMove = (e)=>{
143
+ if (e.pointerId === state.current.id) {
144
+ var _state_current_lastPosition, _state_current_lastPosition1;
145
+ let pointerType = e.pointerType || "mouse";
146
+ var _state_current_lastPosition_pageX, _state_current_lastPosition_pageY;
147
+ // Problems with PointerEvent#movementX/movementY:
148
+ // 1. it is always 0 on macOS Safari.
149
+ // 2. On Chrome Android, it's scaled by devicePixelRatio, but not on Chrome macOS
150
+ move(e, pointerType, e.pageX - ((_state_current_lastPosition_pageX = (_state_current_lastPosition = state.current.lastPosition) === null || _state_current_lastPosition === void 0 ? void 0 : _state_current_lastPosition.pageX) !== null && _state_current_lastPosition_pageX !== void 0 ? _state_current_lastPosition_pageX : 0), e.pageY - ((_state_current_lastPosition_pageY = (_state_current_lastPosition1 = state.current.lastPosition) === null || _state_current_lastPosition1 === void 0 ? void 0 : _state_current_lastPosition1.pageY) !== null && _state_current_lastPosition_pageY !== void 0 ? _state_current_lastPosition_pageY : 0));
151
+ state.current.lastPosition = {
152
+ pageX: e.pageX,
153
+ pageY: e.pageY
154
+ };
155
+ }
156
+ };
157
+ let onPointerUp = (e)=>{
158
+ if (e.pointerId === state.current.id) {
159
+ let pointerType = e.pointerType || "mouse";
160
+ end(e, pointerType);
161
+ state.current.id = null;
162
+ removeGlobalListener(window, "pointermove", onPointerMove, false);
163
+ removeGlobalListener(window, "pointerup", onPointerUp, false);
164
+ removeGlobalListener(window, "pointercancel", onPointerUp, false);
165
+ }
166
+ };
167
+ moveProps.onPointerDown = (e)=>{
168
+ if (e.button === 0 && state.current.id == null) {
169
+ start();
170
+ e.stopPropagation();
171
+ e.preventDefault();
172
+ state.current.lastPosition = {
173
+ pageX: e.pageX,
174
+ pageY: e.pageY
175
+ };
176
+ state.current.id = e.pointerId;
177
+ addGlobalListener(window, "pointermove", onPointerMove, false);
178
+ addGlobalListener(window, "pointerup", onPointerUp, false);
179
+ addGlobalListener(window, "pointercancel", onPointerUp, false);
180
+ }
181
+ };
182
+ }
183
+ let triggerKeyboardMove = (e, deltaX, deltaY)=>{
184
+ start();
185
+ move(e, "keyboard", deltaX, deltaY);
186
+ end(e, "keyboard");
187
+ };
188
+ moveProps.onKeyDown = (e)=>{
189
+ switch(e.key){
190
+ case "Left":
191
+ case "ArrowLeft":
192
+ e.preventDefault();
193
+ e.stopPropagation();
194
+ triggerKeyboardMove(e, -1, 0);
195
+ break;
196
+ case "Right":
197
+ case "ArrowRight":
198
+ e.preventDefault();
199
+ e.stopPropagation();
200
+ triggerKeyboardMove(e, 1, 0);
201
+ break;
202
+ case "Up":
203
+ case "ArrowUp":
204
+ e.preventDefault();
205
+ e.stopPropagation();
206
+ triggerKeyboardMove(e, 0, -1);
207
+ break;
208
+ case "Down":
209
+ case "ArrowDown":
210
+ e.preventDefault();
211
+ e.stopPropagation();
212
+ triggerKeyboardMove(e, 0, 1);
213
+ break;
214
+ }
215
+ };
216
+ return moveProps;
217
+ }, [
218
+ state,
219
+ addGlobalListener,
220
+ removeGlobalListener,
221
+ move,
222
+ end
223
+ ]);
224
+ return {
225
+ moveProps: moveProps
226
+ };
227
+ }
228
+
229
+
230
+ export {$e8a7022cf87cba2a$export$36da96379f79f245 as useMove};
231
+ //# sourceMappingURL=useMove.mjs.map