@react-aria/utils 3.28.1 → 3.28.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 (65) hide show
  1. package/dist/DOMFunctions.main.js.map +1 -1
  2. package/dist/DOMFunctions.module.js.map +1 -1
  3. package/dist/ShadowTreeWalker.main.js.map +1 -1
  4. package/dist/ShadowTreeWalker.module.js.map +1 -1
  5. package/dist/animation.main.js.map +1 -1
  6. package/dist/animation.module.js.map +1 -1
  7. package/dist/focusWithoutScrolling.main.js.map +1 -1
  8. package/dist/focusWithoutScrolling.module.js.map +1 -1
  9. package/dist/getOffset.main.js.map +1 -1
  10. package/dist/getOffset.module.js.map +1 -1
  11. package/dist/inertValue.main.js.map +1 -1
  12. package/dist/inertValue.module.js.map +1 -1
  13. package/dist/isFocusable.main.js.map +1 -1
  14. package/dist/isFocusable.module.js.map +1 -1
  15. package/dist/isVirtualEvent.main.js.map +1 -1
  16. package/dist/isVirtualEvent.module.js.map +1 -1
  17. package/dist/keyboard.main.js.map +1 -1
  18. package/dist/keyboard.module.js.map +1 -1
  19. package/dist/openLink.main.js +1 -1
  20. package/dist/openLink.main.js.map +1 -1
  21. package/dist/openLink.mjs +1 -1
  22. package/dist/openLink.module.js +1 -1
  23. package/dist/openLink.module.js.map +1 -1
  24. package/dist/platform.main.js +1 -0
  25. package/dist/platform.main.js.map +1 -1
  26. package/dist/platform.mjs +1 -0
  27. package/dist/platform.module.js +1 -0
  28. package/dist/platform.module.js.map +1 -1
  29. package/dist/runAfterTransition.main.js.map +1 -1
  30. package/dist/runAfterTransition.module.js.map +1 -1
  31. package/dist/scrollIntoView.main.js.map +1 -1
  32. package/dist/scrollIntoView.module.js.map +1 -1
  33. package/dist/types.d.ts +9 -30
  34. package/dist/types.d.ts.map +1 -1
  35. package/dist/useEvent.main.js.map +1 -1
  36. package/dist/useEvent.module.js.map +1 -1
  37. package/dist/useFormReset.main.js.map +1 -1
  38. package/dist/useFormReset.module.js.map +1 -1
  39. package/dist/useLoadMore.main.js.map +1 -1
  40. package/dist/useLoadMore.module.js.map +1 -1
  41. package/dist/useResizeObserver.main.js.map +1 -1
  42. package/dist/useResizeObserver.module.js.map +1 -1
  43. package/dist/useSyncRef.main.js.map +1 -1
  44. package/dist/useSyncRef.module.js.map +1 -1
  45. package/dist/useUpdateLayoutEffect.main.js.map +1 -1
  46. package/dist/useUpdateLayoutEffect.module.js.map +1 -1
  47. package/package.json +6 -6
  48. package/src/animation.ts +6 -6
  49. package/src/focusWithoutScrolling.ts +1 -1
  50. package/src/getOffset.ts +3 -1
  51. package/src/inertValue.ts +1 -1
  52. package/src/isFocusable.ts +2 -2
  53. package/src/isVirtualEvent.ts +1 -1
  54. package/src/keyboard.tsx +1 -1
  55. package/src/openLink.tsx +9 -9
  56. package/src/runAfterTransition.ts +1 -1
  57. package/src/scrollIntoView.ts +2 -2
  58. package/src/shadowdom/DOMFunctions.ts +5 -5
  59. package/src/shadowdom/ShadowTreeWalker.ts +1 -1
  60. package/src/useEvent.ts +1 -1
  61. package/src/useFormReset.ts +1 -1
  62. package/src/useLoadMore.ts +2 -2
  63. package/src/useResizeObserver.ts +1 -1
  64. package/src/useSyncRef.ts +1 -1
  65. package/src/useUpdateLayoutEffect.ts +1 -1
package/src/animation.ts CHANGED
@@ -14,10 +14,10 @@ import {flushSync} from 'react-dom';
14
14
  import {RefObject, useCallback, useState} from 'react';
15
15
  import {useLayoutEffect} from './useLayoutEffect';
16
16
 
17
- export function useEnterAnimation(ref: RefObject<HTMLElement | null>, isReady: boolean = true) {
17
+ export function useEnterAnimation(ref: RefObject<HTMLElement | null>, isReady: boolean = true): boolean {
18
18
  let [isEntering, setEntering] = useState(true);
19
19
  let isAnimationReady = isEntering && isReady;
20
-
20
+
21
21
  // There are two cases for entry animations:
22
22
  // 1. CSS @keyframes. The `animation` property is set during the isEntering state, and it is removed after the animation finishes.
23
23
  // 2. CSS transitions. The initial styles are applied during the isEntering state, and removed immediately, causing the transition to occur.
@@ -38,7 +38,7 @@ export function useEnterAnimation(ref: RefObject<HTMLElement | null>, isReady: b
38
38
  return isAnimationReady;
39
39
  }
40
40
 
41
- export function useExitAnimation(ref: RefObject<HTMLElement | null>, isOpen: boolean) {
41
+ export function useExitAnimation(ref: RefObject<HTMLElement | null>, isOpen: boolean): boolean {
42
42
  let [exitState, setExitState] = useState<'closed' | 'open' | 'exiting'>(isOpen ? 'open' : 'closed');
43
43
 
44
44
  switch (exitState) {
@@ -71,7 +71,7 @@ export function useExitAnimation(ref: RefObject<HTMLElement | null>, isOpen: boo
71
71
  return isExiting;
72
72
  }
73
73
 
74
- function useAnimation(ref: RefObject<HTMLElement | null>, isActive: boolean, onEnd: () => void) {
74
+ function useAnimation(ref: RefObject<HTMLElement | null>, isActive: boolean, onEnd: () => void): void {
75
75
  useLayoutEffect(() => {
76
76
  if (isActive && ref.current) {
77
77
  if (!('getAnimations' in ref.current)) {
@@ -79,7 +79,7 @@ function useAnimation(ref: RefObject<HTMLElement | null>, isActive: boolean, onE
79
79
  onEnd();
80
80
  return;
81
81
  }
82
-
82
+
83
83
  let animations = ref.current.getAnimations();
84
84
  if (animations.length === 0) {
85
85
  onEnd();
@@ -94,7 +94,7 @@ function useAnimation(ref: RefObject<HTMLElement | null>, isActive: boolean, onE
94
94
  });
95
95
  }
96
96
  }).catch(() => {});
97
-
97
+
98
98
  return () => {
99
99
  canceled = true;
100
100
  };
@@ -28,7 +28,7 @@ interface ScrollableElement {
28
28
  scrollLeft: number
29
29
  }
30
30
 
31
- export function focusWithoutScrolling(element: FocusableElement) {
31
+ export function focusWithoutScrolling(element: FocusableElement): void {
32
32
  if (supportsPreventScroll()) {
33
33
  element.focus({preventScroll: true});
34
34
  } else {
package/src/getOffset.ts CHANGED
@@ -10,7 +10,9 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- export function getOffset(element, reverse, orientation = 'horizontal') {
13
+ import {Orientation} from '@react-types/shared';
14
+
15
+ export function getOffset(element: HTMLElement, reverse?: boolean, orientation: Orientation = 'horizontal'): number {
14
16
  let rect = element.getBoundingClientRect();
15
17
  if (reverse) {
16
18
  return orientation === 'horizontal' ? rect.right : rect.bottom;
package/src/inertValue.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import {version} from 'react';
2
2
 
3
- export function inertValue(value?: boolean) {
3
+ export function inertValue(value?: boolean): string | boolean | undefined {
4
4
  const pieces = version.split('.');
5
5
  const major = parseInt(pieces[0], 10);
6
6
  if (major >= 19) {
@@ -19,10 +19,10 @@ const FOCUSABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]),') + '
19
19
  focusableElements.push('[tabindex]:not([tabindex="-1"]):not([disabled])');
20
20
  const TABBABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]):not([tabindex="-1"]),');
21
21
 
22
- export function isFocusable(element: Element) {
22
+ export function isFocusable(element: Element): boolean {
23
23
  return element.matches(FOCUSABLE_ELEMENT_SELECTOR);
24
24
  }
25
25
 
26
- export function isTabbable(element: Element) {
26
+ export function isTabbable(element: Element): boolean {
27
27
  return element.matches(TABBABLE_ELEMENT_SELECTOR);
28
28
  }
@@ -39,7 +39,7 @@ export function isVirtualClick(event: MouseEvent | PointerEvent): boolean {
39
39
  return event.detail === 0 && !(event as PointerEvent).pointerType;
40
40
  }
41
41
 
42
- export function isVirtualPointerEvent(event: PointerEvent) {
42
+ export function isVirtualPointerEvent(event: PointerEvent): boolean {
43
43
  // If the pointer size is zero, then we assume it's from a screen reader.
44
44
  // Android TalkBack double tap will sometimes return a event with width and height of 1
45
45
  // and pointerType === 'mouse' so we need to check for a specific combination of event attributes.
package/src/keyboard.tsx CHANGED
@@ -18,7 +18,7 @@ interface Event {
18
18
  metaKey: boolean
19
19
  }
20
20
 
21
- export function isCtrlKeyPressed(e: Event) {
21
+ export function isCtrlKeyPressed(e: Event): boolean {
22
22
  if (isMac()) {
23
23
  return e.metaKey;
24
24
  }
package/src/openLink.tsx CHANGED
@@ -13,7 +13,7 @@
13
13
  import {focusWithoutScrolling, isMac, isWebKit} from './index';
14
14
  import {Href, LinkDOMProps, RouterOptions} from '@react-types/shared';
15
15
  import {isFirefox, isIPad} from './platform';
16
- import React, {createContext, ReactNode, useContext, useMemo} from 'react';
16
+ import React, {createContext, DOMAttributes, ReactNode, useContext, useMemo} from 'react';
17
17
 
18
18
  interface Router {
19
19
  isNative: boolean,
@@ -37,7 +37,7 @@ interface RouterProviderProps {
37
37
  * A RouterProvider accepts a `navigate` function from a framework or client side router,
38
38
  * and provides it to all nested React Aria links to enable client side navigation.
39
39
  */
40
- export function RouterProvider(props: RouterProviderProps) {
40
+ export function RouterProvider(props: RouterProviderProps): ReactNode {
41
41
  let {children, navigate, useHref} = props;
42
42
 
43
43
  let ctx = useMemo(() => ({
@@ -72,7 +72,7 @@ interface Modifiers {
72
72
  shiftKey?: boolean
73
73
  }
74
74
 
75
- export function shouldClientNavigate(link: HTMLAnchorElement, modifiers: Modifiers) {
75
+ export function shouldClientNavigate(link: HTMLAnchorElement, modifiers: Modifiers): boolean {
76
76
  // Use getAttribute here instead of link.target. Firefox will default link.target to "_parent" when inside an iframe.
77
77
  let target = link.getAttribute('target');
78
78
  return (
@@ -86,7 +86,7 @@ export function shouldClientNavigate(link: HTMLAnchorElement, modifiers: Modifie
86
86
  );
87
87
  }
88
88
 
89
- export function openLink(target: HTMLAnchorElement, modifiers: Modifiers, setOpening = true) {
89
+ export function openLink(target: HTMLAnchorElement, modifiers: Modifiers, setOpening = true): void {
90
90
  let {metaKey, ctrlKey, altKey, shiftKey} = modifiers;
91
91
 
92
92
  // Firefox does not recognize keyboard events as a user action by default, and the popup blocker
@@ -146,7 +146,7 @@ function openSyntheticLink(target: Element, modifiers: Modifiers) {
146
146
  getSyntheticLink(target, link => openLink(link, modifiers));
147
147
  }
148
148
 
149
- export function useSyntheticLinkProps(props: LinkDOMProps) {
149
+ export function useSyntheticLinkProps(props: LinkDOMProps): DOMAttributes<HTMLElement> {
150
150
  let router = useRouter();
151
151
  const href = router.useHref(props.href ?? '');
152
152
  return {
@@ -156,11 +156,11 @@ export function useSyntheticLinkProps(props: LinkDOMProps) {
156
156
  'data-download': props.download,
157
157
  'data-ping': props.ping,
158
158
  'data-referrer-policy': props.referrerPolicy
159
- };
159
+ } as DOMAttributes<HTMLElement>;
160
160
  }
161
161
 
162
162
  /** @deprecated - For backward compatibility. */
163
- export function getSyntheticLinkProps(props: LinkDOMProps) {
163
+ export function getSyntheticLinkProps(props: LinkDOMProps): DOMAttributes<HTMLElement> {
164
164
  return {
165
165
  'data-href': props.href,
166
166
  'data-target': props.target,
@@ -168,10 +168,10 @@ export function getSyntheticLinkProps(props: LinkDOMProps) {
168
168
  'data-download': props.download,
169
169
  'data-ping': props.ping,
170
170
  'data-referrer-policy': props.referrerPolicy
171
- };
171
+ } as DOMAttributes<HTMLElement>;
172
172
  }
173
173
 
174
- export function useLinkProps(props?: LinkDOMProps) {
174
+ export function useLinkProps(props?: LinkDOMProps): LinkDOMProps {
175
175
  let router = useRouter();
176
176
  const href = router.useHref(props?.href ?? '');
177
177
  return {
@@ -91,7 +91,7 @@ if (typeof document !== 'undefined') {
91
91
  }
92
92
  }
93
93
 
94
- export function runAfterTransition(fn: () => void) {
94
+ export function runAfterTransition(fn: () => void): void {
95
95
  // Wait one frame to see if an animation starts, e.g. a transition on mount.
96
96
  requestAnimationFrame(() => {
97
97
  // If no transitions are running, call the function immediately.
@@ -22,7 +22,7 @@ interface ScrollIntoViewportOpts {
22
22
  * Similar to `element.scrollIntoView({block: 'nearest'})` (not supported in Edge),
23
23
  * but doesn't affect parents above `scrollView`.
24
24
  */
25
- export function scrollIntoView(scrollView: HTMLElement, element: HTMLElement) {
25
+ export function scrollIntoView(scrollView: HTMLElement, element: HTMLElement): void {
26
26
  let offsetX = relativeOffset(scrollView, element, 'left');
27
27
  let offsetY = relativeOffset(scrollView, element, 'top');
28
28
  let width = element.offsetWidth;
@@ -97,7 +97,7 @@ function relativeOffset(ancestor: HTMLElement, child: HTMLElement, axis: 'left'|
97
97
  * that will be centered in the viewport prior to scrolling the targetElement into view. If scrolling is prevented on
98
98
  * the body (e.g. targetElement is in a popover), this will only scroll the scroll parents of the targetElement up to but not including the body itself.
99
99
  */
100
- export function scrollIntoViewport(targetElement: Element | null, opts?: ScrollIntoViewportOpts) {
100
+ export function scrollIntoViewport(targetElement: Element | null, opts?: ScrollIntoViewportOpts): void {
101
101
  if (targetElement && document.contains(targetElement)) {
102
102
  let root = document.scrollingElement || document.documentElement;
103
103
  let isScrollPrevented = window.getComputedStyle(root).overflow === 'hidden';
@@ -43,7 +43,7 @@ export function nodeContains(
43
43
  /**
44
44
  * ShadowDOM safe version of document.activeElement.
45
45
  */
46
- export const getActiveElement = (doc: Document = document) => {
46
+ export const getActiveElement = (doc: Document = document): Element | null => {
47
47
  if (!shadowDOM()) {
48
48
  return doc.activeElement;
49
49
  }
@@ -60,11 +60,11 @@ export const getActiveElement = (doc: Document = document) => {
60
60
  /**
61
61
  * ShadowDOM safe version of event.target.
62
62
  */
63
- export function getEventTarget(event): Element {
64
- if (shadowDOM() && event.target.shadowRoot) {
63
+ export function getEventTarget<T extends Event>(event: T): Element {
64
+ if (shadowDOM() && (event.target as HTMLElement).shadowRoot) {
65
65
  if (event.composedPath) {
66
- return event.composedPath()[0];
66
+ return event.composedPath()[0] as Element;
67
67
  }
68
68
  }
69
- return event.target;
69
+ return event.target as Element;
70
70
  }
@@ -311,7 +311,7 @@ export function createShadowTreeWalker(
311
311
  root: Node,
312
312
  whatToShow?: number,
313
313
  filter?: NodeFilter | null
314
- ) {
314
+ ): TreeWalker {
315
315
  if (shadowDOM()) {
316
316
  return new ShadowTreeWalker(doc, root, whatToShow, filter);
317
317
  }
package/src/useEvent.ts CHANGED
@@ -19,7 +19,7 @@ export function useEvent<K extends keyof GlobalEventHandlersEventMap>(
19
19
  event: K | (string & {}),
20
20
  handler?: (this: Document, ev: GlobalEventHandlersEventMap[K]) => any,
21
21
  options?: boolean | AddEventListenerOptions
22
- ) {
22
+ ): void {
23
23
  let handleEvent = useEffectEvent(handler);
24
24
  let isDisabled = handler == null;
25
25
 
@@ -18,7 +18,7 @@ export function useFormReset<T>(
18
18
  ref: RefObject<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | null> | undefined,
19
19
  initialValue: T,
20
20
  onReset: (value: T) => void
21
- ) {
21
+ ): void {
22
22
  let resetValue = useRef(initialValue);
23
23
  let handleReset = useEffectEvent(() => {
24
24
  if (onReset) {
@@ -12,7 +12,7 @@
12
12
 
13
13
  import {RefObject, useCallback, useRef} from 'react';
14
14
  import {useEvent} from './useEvent';
15
-
15
+
16
16
  import {useLayoutEffect} from './useLayoutEffect';
17
17
 
18
18
  export interface LoadMoreProps {
@@ -32,7 +32,7 @@ export interface LoadMoreProps {
32
32
  items?: any
33
33
  }
34
34
 
35
- export function useLoadMore(props: LoadMoreProps, ref: RefObject<HTMLElement | null>) {
35
+ export function useLoadMore(props: LoadMoreProps, ref: RefObject<HTMLElement | null>): void {
36
36
  let {isLoading, onLoadMore, scrollOffset = 1, items} = props;
37
37
 
38
38
  // Handle scrolling, and call onLoadMore when nearing the bottom.
@@ -12,7 +12,7 @@ type useResizeObserverOptionsType<T> = {
12
12
  onResize: () => void
13
13
  }
14
14
 
15
- export function useResizeObserver<T extends Element>(options: useResizeObserverOptionsType<T>) {
15
+ export function useResizeObserver<T extends Element>(options: useResizeObserverOptionsType<T>): void {
16
16
  const {ref, box, onResize} = options;
17
17
 
18
18
  useEffect(() => {
package/src/useSyncRef.ts CHANGED
@@ -19,7 +19,7 @@ interface ContextValue<T> {
19
19
  }
20
20
 
21
21
  // Syncs ref from context with ref passed to hook
22
- export function useSyncRef<T>(context?: ContextValue<T> | null, ref?: RefObject<T | null>) {
22
+ export function useSyncRef<T>(context?: ContextValue<T> | null, ref?: RefObject<T | null>): void {
23
23
  useLayoutEffect(() => {
24
24
  if (context && context.ref && ref) {
25
25
  context.ref.current = ref.current;
@@ -14,7 +14,7 @@ import {EffectCallback, useRef} from 'react';
14
14
  import {useLayoutEffect} from './useLayoutEffect';
15
15
 
16
16
  // Like useLayoutEffect, but only called for updates after the initial render.
17
- export function useUpdateLayoutEffect(effect: EffectCallback, dependencies: any[]) {
17
+ export function useUpdateLayoutEffect(effect: EffectCallback, dependencies: any[]): void {
18
18
  const isInitialMount = useRef(true);
19
19
  const lastDeps = useRef<any[] | null>(null);
20
20