@@ -12,7 +12,7 @@ export interface MultiSelectionOverlayProps {
1212 selectedElements : HTMLElement [ ]
1313}
1414
15- function dedupeConnectedElements ( elements : HTMLElement [ ] ) : HTMLElement [ ] {
15+ export function dedupeConnectedElements ( elements : HTMLElement [ ] ) : HTMLElement [ ] {
1616 const seen = new Set < HTMLElement > ( )
1717 const result : HTMLElement [ ] = [ ]
1818
@@ -25,35 +25,40 @@ function dedupeConnectedElements(elements: HTMLElement[]): HTMLElement[] {
2525 return result
2626}
2727
28- function getGroupBounds ( rects : DOMRect [ ] ) {
28+ export function getGroupBounds ( rects : DOMRect [ ] ) {
2929 if ( rects . length === 0 ) {
3030 return { left : 0 , top : 0 , right : 0 , bottom : 0 }
3131 }
32- return rects . reduce ( ( bounds , rect ) => ( {
33- left : Math . min ( bounds . left , rect . left ) ,
34- top : Math . min ( bounds . top , rect . top ) ,
35- right : Math . max ( bounds . right , rect . right ) ,
36- bottom : Math . max ( bounds . bottom , rect . bottom ) ,
37- } ) , {
38- left : rects [ 0 ] . left ,
39- top : rects [ 0 ] . top ,
40- right : rects [ 0 ] . right ,
41- bottom : rects [ 0 ] . bottom ,
42- } )
32+ return rects . reduce (
33+ ( bounds , rect ) => ( {
34+ left : Math . min ( bounds . left , rect . left ) ,
35+ top : Math . min ( bounds . top , rect . top ) ,
36+ right : Math . max ( bounds . right , rect . right ) ,
37+ bottom : Math . max ( bounds . bottom , rect . bottom ) ,
38+ } ) ,
39+ {
40+ left : rects [ 0 ] . left ,
41+ top : rects [ 0 ] . top ,
42+ right : rects [ 0 ] . right ,
43+ bottom : rects [ 0 ] . bottom ,
44+ }
45+ )
4346}
4447
4548export function MultiSelectionOverlay ( { selectedElements } : MultiSelectionOverlayProps ) {
4649 const elements = React . useMemo (
4750 ( ) => dedupeConnectedElements ( selectedElements ) ,
48- [ selectedElements ] ,
51+ [ selectedElements ]
4952 )
5053 const [ selectionRects , setSelectionRects ] = React . useState < SelectionRect [ ] > ( [ ] )
5154
5255 const updateRects = React . useCallback ( ( ) => {
53- setSelectionRects ( elements . map ( ( element ) => ( {
54- element,
55- rect : element . getBoundingClientRect ( ) ,
56- } ) ) )
56+ setSelectionRects (
57+ elements . map ( ( element ) => ( {
58+ element,
59+ rect : element . getBoundingClientRect ( ) ,
60+ } ) )
61+ )
5762 } , [ elements ] )
5863
5964 React . useLayoutEffect ( ( ) => {
0 commit comments