forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {Platform} from 'react-native'
2
3const onMouseUp = (e: React.MouseEvent & {target: HTMLElement}) => {
4 // Only handle whenever it is the middle button
5 if (e.button !== 1 || e.target.closest('a') || e.target.tagName === 'A') {
6 return
7 }
8
9 e.target.dispatchEvent(
10 new MouseEvent('click', {metaKey: true, bubbles: true}),
11 )
12}
13
14const onMouseDown = (e: React.MouseEvent) => {
15 // Prevents the middle click scroll from enabling
16 if (e.button !== 1) return
17 e.preventDefault()
18}
19
20export function WebAuxClickWrapper({children}: React.PropsWithChildren<{}>) {
21 if (Platform.OS !== 'web') return children
22
23 return (
24 // @ts-ignore web only
25 <div onMouseDown={onMouseDown} onMouseUp={onMouseUp}>
26 {children}
27 </div>
28 )
29}