import { useEffect } from "react" ; type ClickOutsideCallback = ( event : MouseEvent ) => void ; export function useOnClickOutside < T > ( ref , handler ) { useEffect ( ( ) => { const cb = ( event ) => { if ( ! ref . current || ! ( ref . current as any ) . contains ( event . target ) ) { handler ( event ) ; } } ; document . addEventListener ( "click" , cb ) ; return ( ) => { document . removeEventListener ( "click" , cb ) ; } ; } , [ ref , handler ] ) ; } export const sortBy = ( arr , comp ) : any [ ] => { return arr . sort ( ( a , b ) => { const aComp = comp ( a ) ; const bComp = comp ( b ) ; if ( aComp < bComp ) { return - 1 ; } if ( aComp > bComp ) { return 1 ; } return 0 ; } ) ; } ; type Page = { context : { title ? : string ; sidebar_title ? : string ; sidebar_order ? : number ; } ; } ; export const sortPages = ( arr , extractor = n => n ) : any [ ] => { return arr . sort ( ( a , b ) => { a = extractor ( a ) ; b = extractor ( b ) ; const aso = a . context . sidebar_order >= 0 ? a . context . sidebar_order : 10 ; const bso = b . context . sidebar_order >= 0 ? b . context . sidebar_order : 10 ; if ( aso > bso ) return 1 ; else if ( bso > aso ) return - 1 ; return ( a . context . sidebar_title || a . context . title ) . localeCompare ( b . context . sidebar_title || b . context . title ) ; } ) ; } ;