File tree Expand file tree Collapse file tree 4 files changed +37
-4
lines changed Expand file tree Collapse file tree 4 files changed +37
-4
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @radix-ui/primitive ' : patch
3
+ ---
4
+
5
+ Added DOM utilities
Original file line number Diff line number Diff line change 1
1
// @ts -check
2
2
import { configs } from '@repo/eslint-config/react-package' ;
3
3
4
- export default configs ;
4
+ /** @type {import("eslint").Linter.Config[] } */
5
+ export default [
6
+ ...configs ,
7
+ {
8
+ linterOptions : { reportUnusedDisableDirectives : false } ,
9
+ } ,
10
+ ] ;
Original file line number Diff line number Diff line change 1
- export { composeEventHandlers } from './primitive' ;
1
+ export * from './primitive' ;
Original file line number Diff line number Diff line change 1
- function composeEventHandlers < E extends { defaultPrevented : boolean } > (
1
+ /* eslint-disable no-restricted-globals */
2
+ export const canUseDOM = ! ! (
3
+ typeof window !== 'undefined' &&
4
+ window . document &&
5
+ window . document . createElement
6
+ ) ;
7
+ /* eslint-enable no-restricted-globals */
8
+
9
+ export function composeEventHandlers < E extends { defaultPrevented : boolean } > (
2
10
originalEventHandler ?: ( event : E ) => void ,
3
11
ourEventHandler ?: ( event : E ) => void ,
4
12
{ checkForDefaultPrevented = true } = { }
@@ -12,4 +20,18 @@ function composeEventHandlers<E extends { defaultPrevented: boolean }>(
12
20
} ;
13
21
}
14
22
15
- export { composeEventHandlers } ;
23
+ export function getOwnerWindow ( element : Element | null | undefined ) {
24
+ if ( ! canUseDOM ) {
25
+ throw new Error ( 'Cannot access window outside of the DOM' ) ;
26
+ }
27
+ // eslint-disable-next-line no-restricted-globals
28
+ return element ?. ownerDocument ?. defaultView ?? window ;
29
+ }
30
+
31
+ export function getOwnerDocument ( element : Element | null | undefined ) {
32
+ if ( ! canUseDOM ) {
33
+ throw new Error ( 'Cannot access document outside of the DOM' ) ;
34
+ }
35
+ // eslint-disable-next-line no-restricted-globals
36
+ return element ?. ownerDocument ?? document ;
37
+ }
You can’t perform that action at this time.
0 commit comments