@@ -69,22 +69,21 @@ function getAlignPoint(rect: Rect, points: Points) {
6969 return { x, y } ;
7070}
7171
72- function reversePoints ( points : Points , index : number ) : string {
72+ function reversePoints ( points : Points , index : number ) : Points {
7373 const reverseMap = {
7474 t : 'b' ,
7575 b : 't' ,
7676 l : 'r' ,
7777 r : 'l' ,
7878 } ;
7979
80- return points
81- . map ( ( point , i ) => {
82- if ( i === index ) {
83- return reverseMap [ point ] || 'c' ;
84- }
85- return point ;
86- } )
87- . join ( '' ) ;
80+ const clone = [ ...points ] as Points ;
81+ clone [ index ] = reverseMap [ points [ index ] ] || 'c' ;
82+ return clone ;
83+ }
84+
85+ function flatPoints ( points : Points ) : string {
86+ return points . join ( '' ) ;
8887}
8988
9089export default function useAlign (
@@ -340,6 +339,8 @@ export default function useAlign(
340339 ...placementInfo ,
341340 } ;
342341
342+ let nextPoints = [ popupPoints , targetPoints ] ;
343+
343344 // Next Offset
344345 let nextOffsetX = targetAlignPoint . x - popupAlignPoint . x + popupOffsetX ;
345346 let nextOffsetY = targetAlignPoint . y - popupAlignPoint . y + popupOffsetY ;
@@ -450,9 +451,9 @@ export default function useAlign(
450451 nextOffsetY = tmpNextOffsetY ;
451452 popupOffsetY = - popupOffsetY ;
452453
453- nextAlignInfo . points = [
454- reversePoints ( popupPoints , 0 ) ,
455- reversePoints ( targetPoints , 0 ) ,
454+ nextPoints = [
455+ reversePoints ( nextPoints [ 0 ] , 0 ) ,
456+ reversePoints ( nextPoints [ 1 ] , 0 ) ,
456457 ] ;
457458 } else {
458459 prevFlipRef . current . bt = false ;
@@ -496,9 +497,9 @@ export default function useAlign(
496497 nextOffsetY = tmpNextOffsetY ;
497498 popupOffsetY = - popupOffsetY ;
498499
499- nextAlignInfo . points = [
500- reversePoints ( popupPoints , 0 ) ,
501- reversePoints ( targetPoints , 0 ) ,
500+ nextPoints = [
501+ reversePoints ( nextPoints [ 0 ] , 0 ) ,
502+ reversePoints ( nextPoints [ 1 ] , 0 ) ,
502503 ] ;
503504 } else {
504505 prevFlipRef . current . tb = false ;
@@ -549,9 +550,9 @@ export default function useAlign(
549550 nextOffsetX = tmpNextOffsetX ;
550551 popupOffsetX = - popupOffsetX ;
551552
552- nextAlignInfo . points = [
553- reversePoints ( popupPoints , 1 ) ,
554- reversePoints ( targetPoints , 1 ) ,
553+ nextPoints = [
554+ reversePoints ( nextPoints [ 0 ] , 1 ) ,
555+ reversePoints ( nextPoints [ 1 ] , 1 ) ,
555556 ] ;
556557 } else {
557558 prevFlipRef . current . rl = false ;
@@ -595,15 +596,20 @@ export default function useAlign(
595596 nextOffsetX = tmpNextOffsetX ;
596597 popupOffsetX = - popupOffsetX ;
597598
598- nextAlignInfo . points = [
599- reversePoints ( popupPoints , 1 ) ,
600- reversePoints ( targetPoints , 1 ) ,
599+ nextPoints = [
600+ reversePoints ( nextPoints [ 0 ] , 1 ) ,
601+ reversePoints ( nextPoints [ 1 ] , 1 ) ,
601602 ] ;
602603 } else {
603604 prevFlipRef . current . lr = false ;
604605 }
605606 }
606607
608+ nextAlignInfo . points = [
609+ flatPoints ( nextPoints [ 0 ] ) ,
610+ flatPoints ( nextPoints [ 1 ] ) ,
611+ ] ;
612+
607613 // ============================ Shift ============================
608614 syncNextPopupPosition ( ) ;
609615
0 commit comments