@react-aria/utils 3.21.0 → 3.22.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.
- package/dist/import.mjs +19 -4
- package/dist/main.js +22 -3
- package/dist/main.js.map +1 -1
- package/dist/module.js +19 -4
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +36 -7
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/domHelpers.ts +14 -0
- package/src/index.ts +1 -0
- package/src/openLink.tsx +4 -4
- package/src/useDescription.ts +1 -1
- package/src/useEffectEvent.ts +5 -4
- package/src/useEvent.ts +1 -1
- package/src/useId.ts +10 -1
- package/src/useSyncRef.ts +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const getOwnerDocument = (el: Element | null | undefined): Document => {
|
|
2
|
+
return el?.ownerDocument ?? document;
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
export const getOwnerWindow = (
|
|
6
|
+
el: (Window & typeof global) | Element | null | undefined
|
|
7
|
+
): Window & typeof global => {
|
|
8
|
+
if (el && 'window' in el && el.window === el) {
|
|
9
|
+
return el;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const doc = getOwnerDocument(el as Element | null | undefined);
|
|
13
|
+
return doc.defaultView || window;
|
|
14
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
export {useId, mergeIds, useSlotId} from './useId';
|
|
13
13
|
export {chain} from './chain';
|
|
14
|
+
export {getOwnerDocument, getOwnerWindow} from './domHelpers';
|
|
14
15
|
export {mergeProps} from './mergeProps';
|
|
15
16
|
export {mergeRefs} from './mergeRefs';
|
|
16
17
|
export {filterDOMProps} from './filterDOMProps';
|
package/src/openLink.tsx
CHANGED
|
@@ -103,13 +103,13 @@ export function openLink(target: HTMLAnchorElement, modifiers: Modifiers, setOpe
|
|
|
103
103
|
// @ts-ignore - keyIdentifier is a non-standard property, but it's what webkit expects
|
|
104
104
|
? new KeyboardEvent('keydown', {keyIdentifier: 'Enter', metaKey, ctrlKey, altKey, shiftKey})
|
|
105
105
|
: new MouseEvent('click', {metaKey, ctrlKey, altKey, shiftKey, bubbles: true, cancelable: true});
|
|
106
|
-
openLink.isOpening = setOpening;
|
|
106
|
+
(openLink as any).isOpening = setOpening;
|
|
107
107
|
focusWithoutScrolling(target);
|
|
108
108
|
target.dispatchEvent(event);
|
|
109
|
-
openLink.isOpening = false;
|
|
109
|
+
(openLink as any).isOpening = false;
|
|
110
110
|
}
|
|
111
|
-
|
|
112
|
-
openLink.isOpening = false;
|
|
111
|
+
// https://github.com/parcel-bundler/parcel/issues/8724
|
|
112
|
+
(openLink as any).isOpening = false;
|
|
113
113
|
|
|
114
114
|
function getSyntheticLink(target: Element, open: (link: HTMLAnchorElement) => void) {
|
|
115
115
|
if (target instanceof HTMLAnchorElement) {
|
package/src/useDescription.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {useState} from 'react';
|
|
|
17
17
|
let descriptionId = 0;
|
|
18
18
|
const descriptionNodes = new Map<string, {refCount: number, element: Element}>();
|
|
19
19
|
|
|
20
|
-
export function useDescription(description
|
|
20
|
+
export function useDescription(description?: string): AriaLabelingProps {
|
|
21
21
|
let [id, setId] = useState(undefined);
|
|
22
22
|
|
|
23
23
|
useLayoutEffect(() => {
|
package/src/useEffectEvent.ts
CHANGED
|
@@ -13,13 +13,14 @@
|
|
|
13
13
|
import {useCallback, useRef} from 'react';
|
|
14
14
|
import {useLayoutEffect} from './useLayoutEffect';
|
|
15
15
|
|
|
16
|
-
export function useEffectEvent(fn) {
|
|
17
|
-
const ref = useRef(null);
|
|
16
|
+
export function useEffectEvent<T extends Function>(fn: T): T {
|
|
17
|
+
const ref = useRef<T | null>(null);
|
|
18
18
|
useLayoutEffect(() => {
|
|
19
19
|
ref.current = fn;
|
|
20
20
|
}, [fn]);
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
return useCallback<T>((...args) => {
|
|
23
|
+
const f = ref.current!;
|
|
23
24
|
return f(...args);
|
|
24
25
|
}, []);
|
|
25
26
|
}
|
package/src/useEvent.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {useEffectEvent} from './useEffectEvent';
|
|
|
16
16
|
export function useEvent<K extends keyof GlobalEventHandlersEventMap>(
|
|
17
17
|
ref: RefObject<EventTarget>,
|
|
18
18
|
event: K,
|
|
19
|
-
handler
|
|
19
|
+
handler?: (this: Document, ev: GlobalEventHandlersEventMap[K]) => any,
|
|
20
20
|
options?: boolean | AddEventListenerOptions
|
|
21
21
|
) {
|
|
22
22
|
let handleEvent = useEffectEvent(handler);
|
package/src/useId.ts
CHANGED
|
@@ -15,6 +15,13 @@ import {useLayoutEffect} from './useLayoutEffect';
|
|
|
15
15
|
import {useSSRSafeId} from '@react-aria/ssr';
|
|
16
16
|
import {useValueEffect} from './';
|
|
17
17
|
|
|
18
|
+
// copied from SSRProvider.tsx to reduce exports, if needed again, consider sharing
|
|
19
|
+
let canUseDOM = Boolean(
|
|
20
|
+
typeof window !== 'undefined' &&
|
|
21
|
+
window.document &&
|
|
22
|
+
window.document.createElement
|
|
23
|
+
);
|
|
24
|
+
|
|
18
25
|
let idsUpdaterMap: Map<string, (v: string) => void> = new Map();
|
|
19
26
|
|
|
20
27
|
/**
|
|
@@ -31,7 +38,9 @@ export function useId(defaultId?: string): string {
|
|
|
31
38
|
nextId.current = val;
|
|
32
39
|
}, []);
|
|
33
40
|
|
|
34
|
-
|
|
41
|
+
if (canUseDOM) {
|
|
42
|
+
idsUpdaterMap.set(res, updateValue);
|
|
43
|
+
}
|
|
35
44
|
|
|
36
45
|
useLayoutEffect(() => {
|
|
37
46
|
let r = res;
|
package/src/useSyncRef.ts
CHANGED
|
@@ -18,7 +18,7 @@ interface ContextValue<T> {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
// Syncs ref from context with ref passed to hook
|
|
21
|
-
export function useSyncRef<T>(context
|
|
21
|
+
export function useSyncRef<T>(context?: ContextValue<T> | null, ref?: RefObject<T>) {
|
|
22
22
|
useLayoutEffect(() => {
|
|
23
23
|
if (context && context.ref && ref) {
|
|
24
24
|
context.ref.current = ref.current;
|