@react-types/shared 3.0.0-nightly-cce1ec97a-260721 → 3.0.0-nightly-c1d8023d1-260723

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/events.d.ts +14 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-types/shared",
3
- "version": "3.0.0-nightly-cce1ec97a-260721",
3
+ "version": "3.0.0-nightly-c1d8023d1-260723",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
package/src/events.d.ts CHANGED
@@ -13,6 +13,20 @@
13
13
  import {FocusableElement} from './dom';
14
14
  import {FocusEvent, MouseEvent, KeyboardEvent as ReactKeyboardEvent, SyntheticEvent} from 'react';
15
15
 
16
+ // Type helper to extract the target element type from an event
17
+ export type EventTargetType<T> = T extends SyntheticEvent<infer E, any> ? E : EventTarget;
18
+
19
+ // Type helper to extract the event map from a target
20
+ export type EventMapType<T extends EventTarget> = T extends Window
21
+ ? WindowEventMap
22
+ : T extends Document
23
+ ? DocumentEventMap
24
+ : T extends Element
25
+ ? HTMLElementEventMap
26
+ : T extends VisualViewport
27
+ ? VisualViewportEventMap
28
+ : GlobalEventHandlersEventMap;
29
+
16
30
  // Event bubbling can be problematic in real-world applications, so the default for React Spectrum components
17
31
  // is not to propagate. This can be overridden by calling continuePropagation() on the event.
18
32
  export type BaseEvent<T extends SyntheticEvent> = T & {