@react-aria/interactions 3.27.1 → 3.28.0

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 (118) hide show
  1. package/dist/import.mjs +21 -15
  2. package/dist/main.js +45 -39
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +21 -15
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +31 -0
  7. package/package.json +16 -15
  8. package/src/index.ts +30 -34
  9. package/dist/PressResponder.main.js +0 -61
  10. package/dist/PressResponder.main.js.map +0 -1
  11. package/dist/PressResponder.mjs +0 -51
  12. package/dist/PressResponder.module.js +0 -51
  13. package/dist/PressResponder.module.js.map +0 -1
  14. package/dist/Pressable.main.js +0 -69
  15. package/dist/Pressable.main.js.map +0 -1
  16. package/dist/Pressable.mjs +0 -60
  17. package/dist/Pressable.module.js +0 -60
  18. package/dist/Pressable.module.js.map +0 -1
  19. package/dist/context.main.js +0 -30
  20. package/dist/context.main.js.map +0 -1
  21. package/dist/context.mjs +0 -21
  22. package/dist/context.module.js +0 -21
  23. package/dist/context.module.js.map +0 -1
  24. package/dist/createEventHandler.main.js +0 -46
  25. package/dist/createEventHandler.main.js.map +0 -1
  26. package/dist/createEventHandler.mjs +0 -41
  27. package/dist/createEventHandler.module.js +0 -41
  28. package/dist/createEventHandler.module.js.map +0 -1
  29. package/dist/focusSafely.main.js +0 -41
  30. package/dist/focusSafely.main.js.map +0 -1
  31. package/dist/focusSafely.mjs +0 -36
  32. package/dist/focusSafely.module.js +0 -36
  33. package/dist/focusSafely.module.js.map +0 -1
  34. package/dist/textSelection.main.js +0 -77
  35. package/dist/textSelection.main.js.map +0 -1
  36. package/dist/textSelection.mjs +0 -71
  37. package/dist/textSelection.module.js +0 -71
  38. package/dist/textSelection.module.js.map +0 -1
  39. package/dist/types.d.ts +0 -255
  40. package/dist/types.d.ts.map +0 -1
  41. package/dist/useFocus.main.js +0 -66
  42. package/dist/useFocus.main.js.map +0 -1
  43. package/dist/useFocus.mjs +0 -61
  44. package/dist/useFocus.module.js +0 -61
  45. package/dist/useFocus.module.js.map +0 -1
  46. package/dist/useFocusVisible.main.js +0 -267
  47. package/dist/useFocusVisible.main.js.map +0 -1
  48. package/dist/useFocusVisible.mjs +0 -255
  49. package/dist/useFocusVisible.module.js +0 -255
  50. package/dist/useFocusVisible.module.js.map +0 -1
  51. package/dist/useFocusWithin.main.js +0 -107
  52. package/dist/useFocusWithin.main.js.map +0 -1
  53. package/dist/useFocusWithin.mjs +0 -102
  54. package/dist/useFocusWithin.module.js +0 -102
  55. package/dist/useFocusWithin.module.js.map +0 -1
  56. package/dist/useFocusable.main.js +0 -113
  57. package/dist/useFocusable.main.js.map +0 -1
  58. package/dist/useFocusable.mjs +0 -101
  59. package/dist/useFocusable.module.js +0 -101
  60. package/dist/useFocusable.module.js.map +0 -1
  61. package/dist/useHover.main.js +0 -159
  62. package/dist/useHover.main.js.map +0 -1
  63. package/dist/useHover.mjs +0 -154
  64. package/dist/useHover.module.js +0 -154
  65. package/dist/useHover.module.js.map +0 -1
  66. package/dist/useInteractOutside.main.js +0 -107
  67. package/dist/useInteractOutside.main.js.map +0 -1
  68. package/dist/useInteractOutside.mjs +0 -102
  69. package/dist/useInteractOutside.module.js +0 -102
  70. package/dist/useInteractOutside.module.js.map +0 -1
  71. package/dist/useKeyboard.main.js +0 -30
  72. package/dist/useKeyboard.main.js.map +0 -1
  73. package/dist/useKeyboard.mjs +0 -25
  74. package/dist/useKeyboard.module.js +0 -25
  75. package/dist/useKeyboard.module.js.map +0 -1
  76. package/dist/useLongPress.main.js +0 -86
  77. package/dist/useLongPress.main.js.map +0 -1
  78. package/dist/useLongPress.mjs +0 -81
  79. package/dist/useLongPress.module.js +0 -81
  80. package/dist/useLongPress.module.js.map +0 -1
  81. package/dist/useMove.main.js +0 -272
  82. package/dist/useMove.main.js.map +0 -1
  83. package/dist/useMove.mjs +0 -267
  84. package/dist/useMove.module.js +0 -267
  85. package/dist/useMove.module.js.map +0 -1
  86. package/dist/usePress.main.js +0 -763
  87. package/dist/usePress.main.js.map +0 -1
  88. package/dist/usePress.mjs +0 -758
  89. package/dist/usePress.module.js +0 -758
  90. package/dist/usePress.module.js.map +0 -1
  91. package/dist/useScrollWheel.main.js +0 -41
  92. package/dist/useScrollWheel.main.js.map +0 -1
  93. package/dist/useScrollWheel.mjs +0 -36
  94. package/dist/useScrollWheel.module.js +0 -36
  95. package/dist/useScrollWheel.module.js.map +0 -1
  96. package/dist/utils.main.js +0 -164
  97. package/dist/utils.main.js.map +0 -1
  98. package/dist/utils.mjs +0 -155
  99. package/dist/utils.module.js +0 -155
  100. package/dist/utils.module.js.map +0 -1
  101. package/src/PressResponder.tsx +0 -67
  102. package/src/Pressable.tsx +0 -97
  103. package/src/context.ts +0 -23
  104. package/src/createEventHandler.ts +0 -55
  105. package/src/focusSafely.ts +0 -49
  106. package/src/textSelection.ts +0 -101
  107. package/src/useFocus.ts +0 -88
  108. package/src/useFocusVisible.ts +0 -359
  109. package/src/useFocusWithin.ts +0 -134
  110. package/src/useFocusable.tsx +0 -191
  111. package/src/useHover.ts +0 -222
  112. package/src/useInteractOutside.ts +0 -143
  113. package/src/useKeyboard.ts +0 -36
  114. package/src/useLongPress.ts +0 -135
  115. package/src/useMove.ts +0 -259
  116. package/src/usePress.ts +0 -1095
  117. package/src/useScrollWheel.ts +0 -41
  118. package/src/utils.ts +0 -175
@@ -1,41 +0,0 @@
1
- /*
2
- * Copyright 2021 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {RefObject, ScrollEvents} from '@react-types/shared';
14
- import {useCallback} from 'react';
15
- import {useEvent} from '@react-aria/utils';
16
-
17
- export interface ScrollWheelProps extends ScrollEvents {
18
- /** Whether the scroll listener should be disabled. */
19
- isDisabled?: boolean
20
- }
21
-
22
- // scroll wheel needs to be added not passively so it's cancelable, small helper hook to remember that
23
- export function useScrollWheel(props: ScrollWheelProps, ref: RefObject<HTMLElement | null>): void {
24
- let {onScroll, isDisabled} = props;
25
- let onScrollHandler = useCallback((e) => {
26
- // If the ctrlKey is pressed, this is a zoom event, do nothing.
27
- if (e.ctrlKey) {
28
- return;
29
- }
30
-
31
- // stop scrolling the page
32
- e.preventDefault();
33
- e.stopPropagation();
34
-
35
- if (onScroll) {
36
- onScroll({deltaX: e.deltaX, deltaY: e.deltaY});
37
- }
38
- }, [onScroll]);
39
-
40
- useEvent(ref, 'wheel', isDisabled ? undefined : onScrollHandler);
41
- }
package/src/utils.ts DELETED
@@ -1,175 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {FocusableElement} from '@react-types/shared';
14
- import {focusWithoutScrolling, getActiveElement, getEventTarget, getOwnerWindow, isFocusable, useLayoutEffect} from '@react-aria/utils';
15
- import {FocusEvent as ReactFocusEvent, SyntheticEvent, useCallback, useRef} from 'react';
16
-
17
- // Turn a native event into a React synthetic event.
18
- export function createSyntheticEvent<E extends SyntheticEvent>(nativeEvent: Event): E {
19
- let event = nativeEvent as any as E;
20
- event.nativeEvent = nativeEvent;
21
- event.isDefaultPrevented = () => event.defaultPrevented;
22
- // cancelBubble is technically deprecated in the spec, but still supported in all browsers.
23
- event.isPropagationStopped = () => (event as any).cancelBubble;
24
- event.persist = () => {};
25
- return event;
26
- }
27
-
28
- export function setEventTarget(event: Event, target: Element): void {
29
- Object.defineProperty(event, 'target', {value: target});
30
- Object.defineProperty(event, 'currentTarget', {value: target});
31
- }
32
-
33
- export function useSyntheticBlurEvent<Target extends Element = Element>(onBlur: (e: ReactFocusEvent<Target>) => void): (e: ReactFocusEvent<Target>) => void {
34
- let stateRef = useRef({
35
- isFocused: false,
36
- observer: null as MutationObserver | null
37
- });
38
-
39
- // Clean up MutationObserver on unmount. See below.
40
-
41
- useLayoutEffect(() => {
42
- const state = stateRef.current;
43
- return () => {
44
- if (state.observer) {
45
- state.observer.disconnect();
46
- state.observer = null;
47
- }
48
- };
49
- }, []);
50
-
51
- // This function is called during a React onFocus event.
52
- return useCallback((e: ReactFocusEvent<Target>) => {
53
- // React does not fire onBlur when an element is disabled. https://github.com/facebook/react/issues/9142
54
- // Most browsers fire a native focusout event in this case, except for Firefox. In that case, we use a
55
- // MutationObserver to watch for the disabled attribute, and dispatch these events ourselves.
56
- // For browsers that do, focusout fires before the MutationObserver, so onBlur should not fire twice.
57
- let eventTarget = getEventTarget(e);
58
- if (
59
- eventTarget instanceof HTMLButtonElement ||
60
- eventTarget instanceof HTMLInputElement ||
61
- eventTarget instanceof HTMLTextAreaElement ||
62
- eventTarget instanceof HTMLSelectElement
63
- ) {
64
- stateRef.current.isFocused = true;
65
-
66
- let target = eventTarget;
67
- let onBlurHandler: EventListenerOrEventListenerObject | null = (e) => {
68
- stateRef.current.isFocused = false;
69
-
70
- if (target.disabled) {
71
- // For backward compatibility, dispatch a (fake) React synthetic event.
72
- let event = createSyntheticEvent<ReactFocusEvent<Target>>(e);
73
- onBlur?.(event);
74
- }
75
-
76
- // We no longer need the MutationObserver once the target is blurred.
77
- if (stateRef.current.observer) {
78
- stateRef.current.observer.disconnect();
79
- stateRef.current.observer = null;
80
- }
81
- };
82
-
83
- target.addEventListener('focusout', onBlurHandler, {once: true});
84
-
85
- stateRef.current.observer = new MutationObserver(() => {
86
- if (stateRef.current.isFocused && target.disabled) {
87
- stateRef.current.observer?.disconnect();
88
- let relatedTargetEl = target === getActiveElement() ? null : getActiveElement();
89
- target.dispatchEvent(new FocusEvent('blur', {relatedTarget: relatedTargetEl}));
90
- target.dispatchEvent(new FocusEvent('focusout', {bubbles: true, relatedTarget: relatedTargetEl}));
91
- }
92
- });
93
-
94
- stateRef.current.observer.observe(target, {attributes: true, attributeFilter: ['disabled']});
95
- }
96
- }, [onBlur]);
97
- }
98
-
99
- export let ignoreFocusEvent = false;
100
-
101
- /**
102
- * This function prevents the next focus event fired on `target`, without using `event.preventDefault()`.
103
- * It works by waiting for the series of focus events to occur, and reverts focus back to where it was before.
104
- * It also makes these events mostly non-observable by using a capturing listener on the window and stopping propagation.
105
- */
106
- export function preventFocus(target: FocusableElement | null): (() => void) | undefined {
107
- // The browser will focus the nearest focusable ancestor of our target.
108
- while (target && !isFocusable(target)) {
109
- target = target.parentElement;
110
- }
111
-
112
- let window = getOwnerWindow(target);
113
- let activeElement = window.document.activeElement as FocusableElement | null;
114
- if (!activeElement || activeElement === target) {
115
- return;
116
- }
117
-
118
- ignoreFocusEvent = true;
119
- let isRefocusing = false;
120
- let onBlur = (e: FocusEvent) => {
121
- if (getEventTarget(e) === activeElement || isRefocusing) {
122
- e.stopImmediatePropagation();
123
- }
124
- };
125
-
126
- let onFocusOut = (e: FocusEvent) => {
127
- if (getEventTarget(e) === activeElement || isRefocusing) {
128
- e.stopImmediatePropagation();
129
-
130
- // If there was no focusable ancestor, we don't expect a focus event.
131
- // Re-focus the original active element here.
132
- if (!target && !isRefocusing) {
133
- isRefocusing = true;
134
- focusWithoutScrolling(activeElement);
135
- cleanup();
136
- }
137
- }
138
- };
139
-
140
- let onFocus = (e: FocusEvent) => {
141
- if (getEventTarget(e) === target || isRefocusing) {
142
- e.stopImmediatePropagation();
143
- }
144
- };
145
-
146
- let onFocusIn = (e: FocusEvent) => {
147
- if (getEventTarget(e) === target || isRefocusing) {
148
- e.stopImmediatePropagation();
149
-
150
- if (!isRefocusing) {
151
- isRefocusing = true;
152
- focusWithoutScrolling(activeElement);
153
- cleanup();
154
- }
155
- }
156
- };
157
-
158
- window.addEventListener('blur', onBlur, true);
159
- window.addEventListener('focusout', onFocusOut, true);
160
- window.addEventListener('focusin', onFocusIn, true);
161
- window.addEventListener('focus', onFocus, true);
162
-
163
- let cleanup = () => {
164
- cancelAnimationFrame(raf);
165
- window.removeEventListener('blur', onBlur, true);
166
- window.removeEventListener('focusout', onFocusOut, true);
167
- window.removeEventListener('focusin', onFocusIn, true);
168
- window.removeEventListener('focus', onFocus, true);
169
- ignoreFocusEvent = false;
170
- isRefocusing = false;
171
- };
172
-
173
- let raf = requestAnimationFrame(cleanup);
174
- return cleanup;
175
- }