@rc-component/trigger 2.2.5 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,36 +1,29 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
- import { isDOM } from "rc-util/es/Dom/findDOMNode";
4
- import isVisible from "rc-util/es/Dom/isVisible";
5
- import useEvent from "rc-util/es/hooks/useEvent";
6
- import useLayoutEffect from "rc-util/es/hooks/useLayoutEffect";
1
+ import { isDOM } from "@rc-component/util/es/Dom/findDOMNode";
2
+ import isVisible from "@rc-component/util/es/Dom/isVisible";
3
+ import useEvent from "@rc-component/util/es/hooks/useEvent";
4
+ import useLayoutEffect from "@rc-component/util/es/hooks/useLayoutEffect";
7
5
  import * as React from 'react';
8
6
  import { collectScroller, getVisibleArea, getWin, toNum } from "../util";
9
- function getUnitOffset(size) {
10
- var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
11
- var offsetStr = "".concat(offset);
12
- var cells = offsetStr.match(/^(.*)\%$/);
7
+ function getUnitOffset(size, offset = 0) {
8
+ const offsetStr = `${offset}`;
9
+ const cells = offsetStr.match(/^(.*)\%$/);
13
10
  if (cells) {
14
11
  return size * (parseFloat(cells[1]) / 100);
15
12
  }
16
13
  return parseFloat(offsetStr);
17
14
  }
18
15
  function getNumberOffset(rect, offset) {
19
- var _ref = offset || [],
20
- _ref2 = _slicedToArray(_ref, 2),
21
- offsetX = _ref2[0],
22
- offsetY = _ref2[1];
16
+ const [offsetX, offsetY] = offset || [];
23
17
  return [getUnitOffset(rect.width, offsetX), getUnitOffset(rect.height, offsetY)];
24
18
  }
25
- function splitPoints() {
26
- var points = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
19
+ function splitPoints(points = '') {
27
20
  return [points[0], points[1]];
28
21
  }
29
22
  function getAlignPoint(rect, points) {
30
- var topBottom = points[0];
31
- var leftRight = points[1];
32
- var x;
33
- var y;
23
+ const topBottom = points[0];
24
+ const leftRight = points[1];
25
+ let x;
26
+ let y;
34
27
 
35
28
  // Top & Bottom
36
29
  if (topBottom === 't') {
@@ -50,18 +43,18 @@ function getAlignPoint(rect, points) {
50
43
  x = rect.x + rect.width / 2;
51
44
  }
52
45
  return {
53
- x: x,
54
- y: y
46
+ x,
47
+ y
55
48
  };
56
49
  }
57
50
  function reversePoints(points, index) {
58
- var reverseMap = {
51
+ const reverseMap = {
59
52
  t: 'b',
60
53
  b: 't',
61
54
  l: 'r',
62
55
  r: 'l'
63
56
  };
64
- return points.map(function (point, i) {
57
+ return points.map((point, i) => {
65
58
  if (i === index) {
66
59
  return reverseMap[point] || 'c';
67
60
  }
@@ -69,23 +62,20 @@ function reversePoints(points, index) {
69
62
  }).join('');
70
63
  }
71
64
  export default function useAlign(open, popupEle, target, placement, builtinPlacements, popupAlign, onPopupAlign) {
72
- var _React$useState = React.useState({
73
- ready: false,
74
- offsetX: 0,
75
- offsetY: 0,
76
- offsetR: 0,
77
- offsetB: 0,
78
- arrowX: 0,
79
- arrowY: 0,
80
- scaleX: 1,
81
- scaleY: 1,
82
- align: builtinPlacements[placement] || {}
83
- }),
84
- _React$useState2 = _slicedToArray(_React$useState, 2),
85
- offsetInfo = _React$useState2[0],
86
- setOffsetInfo = _React$useState2[1];
87
- var alignCountRef = React.useRef(0);
88
- var scrollerList = React.useMemo(function () {
65
+ const [offsetInfo, setOffsetInfo] = React.useState({
66
+ ready: false,
67
+ offsetX: 0,
68
+ offsetY: 0,
69
+ offsetR: 0,
70
+ offsetB: 0,
71
+ arrowX: 0,
72
+ arrowY: 0,
73
+ scaleX: 1,
74
+ scaleY: 1,
75
+ align: builtinPlacements[placement] || {}
76
+ });
77
+ const alignCountRef = React.useRef(0);
78
+ const scrollerList = React.useMemo(() => {
89
79
  if (!popupEle) {
90
80
  return [];
91
81
  }
@@ -95,8 +85,8 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
95
85
  // ========================= Flip ==========================
96
86
  // We will memo flip info.
97
87
  // If size change to make flip, it will memo the flip info and use it in next align.
98
- var prevFlipRef = React.useRef({});
99
- var resetFlipCache = function resetFlipCache() {
88
+ const prevFlipRef = React.useRef({});
89
+ const resetFlipCache = () => {
100
90
  prevFlipRef.current = {};
101
91
  };
102
92
  if (!open) {
@@ -104,33 +94,36 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
104
94
  }
105
95
 
106
96
  // ========================= Align =========================
107
- var onAlign = useEvent(function () {
97
+ const onAlign = useEvent(() => {
108
98
  if (popupEle && target && open) {
109
- var _popupElement$parentE, _popupRect$x, _popupRect$y, _popupElement$parentE2;
110
- var popupElement = popupEle;
111
- var doc = popupElement.ownerDocument;
112
- var win = getWin(popupElement);
113
- var _win$getComputedStyle = win.getComputedStyle(popupElement),
114
- width = _win$getComputedStyle.width,
115
- height = _win$getComputedStyle.height,
116
- popupPosition = _win$getComputedStyle.position;
117
- var originLeft = popupElement.style.left;
118
- var originTop = popupElement.style.top;
119
- var originRight = popupElement.style.right;
120
- var originBottom = popupElement.style.bottom;
121
- var originOverflow = popupElement.style.overflow;
99
+ const popupElement = popupEle;
100
+ const doc = popupElement.ownerDocument;
101
+ const win = getWin(popupElement);
102
+ const {
103
+ width,
104
+ height,
105
+ position: popupPosition
106
+ } = win.getComputedStyle(popupElement);
107
+ const originLeft = popupElement.style.left;
108
+ const originTop = popupElement.style.top;
109
+ const originRight = popupElement.style.right;
110
+ const originBottom = popupElement.style.bottom;
111
+ const originOverflow = popupElement.style.overflow;
122
112
 
123
113
  // Placement
124
- var placementInfo = _objectSpread(_objectSpread({}, builtinPlacements[placement]), popupAlign);
114
+ const placementInfo = {
115
+ ...builtinPlacements[placement],
116
+ ...popupAlign
117
+ };
125
118
 
126
119
  // placeholder element
127
- var placeholderElement = doc.createElement('div');
128
- (_popupElement$parentE = popupElement.parentElement) === null || _popupElement$parentE === void 0 || _popupElement$parentE.appendChild(placeholderElement);
129
- placeholderElement.style.left = "".concat(popupElement.offsetLeft, "px");
130
- placeholderElement.style.top = "".concat(popupElement.offsetTop, "px");
120
+ const placeholderElement = doc.createElement('div');
121
+ popupElement.parentElement?.appendChild(placeholderElement);
122
+ placeholderElement.style.left = `${popupElement.offsetLeft}px`;
123
+ placeholderElement.style.top = `${popupElement.offsetTop}px`;
131
124
  placeholderElement.style.position = popupPosition;
132
- placeholderElement.style.height = "".concat(popupElement.offsetHeight, "px");
133
- placeholderElement.style.width = "".concat(popupElement.offsetWidth, "px");
125
+ placeholderElement.style.height = `${popupElement.offsetHeight}px`;
126
+ placeholderElement.style.width = `${popupElement.offsetWidth}px`;
134
127
 
135
128
  // Reset first
136
129
  popupElement.style.left = '0';
@@ -140,7 +133,7 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
140
133
  popupElement.style.overflow = 'hidden';
141
134
 
142
135
  // Calculate align style, we should consider `transform` case
143
- var targetRect;
136
+ let targetRect;
144
137
  if (Array.isArray(target)) {
145
138
  targetRect = {
146
139
  x: target[0],
@@ -149,10 +142,9 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
149
142
  height: 0
150
143
  };
151
144
  } else {
152
- var _rect$x, _rect$y;
153
- var rect = target.getBoundingClientRect();
154
- rect.x = (_rect$x = rect.x) !== null && _rect$x !== void 0 ? _rect$x : rect.left;
155
- rect.y = (_rect$y = rect.y) !== null && _rect$y !== void 0 ? _rect$y : rect.top;
145
+ const rect = target.getBoundingClientRect();
146
+ rect.x = rect.x ?? rect.left;
147
+ rect.y = rect.y ?? rect.top;
156
148
  targetRect = {
157
149
  x: rect.x,
158
150
  y: rect.y,
@@ -160,55 +152,58 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
160
152
  height: rect.height
161
153
  };
162
154
  }
163
- var popupRect = popupElement.getBoundingClientRect();
164
- popupRect.x = (_popupRect$x = popupRect.x) !== null && _popupRect$x !== void 0 ? _popupRect$x : popupRect.left;
165
- popupRect.y = (_popupRect$y = popupRect.y) !== null && _popupRect$y !== void 0 ? _popupRect$y : popupRect.top;
166
- var _doc$documentElement = doc.documentElement,
167
- clientWidth = _doc$documentElement.clientWidth,
168
- clientHeight = _doc$documentElement.clientHeight,
169
- scrollWidth = _doc$documentElement.scrollWidth,
170
- scrollHeight = _doc$documentElement.scrollHeight,
171
- scrollTop = _doc$documentElement.scrollTop,
172
- scrollLeft = _doc$documentElement.scrollLeft;
173
- var popupHeight = popupRect.height;
174
- var popupWidth = popupRect.width;
175
- var targetHeight = targetRect.height;
176
- var targetWidth = targetRect.width;
155
+ const popupRect = popupElement.getBoundingClientRect();
156
+ popupRect.x = popupRect.x ?? popupRect.left;
157
+ popupRect.y = popupRect.y ?? popupRect.top;
158
+ const {
159
+ clientWidth,
160
+ clientHeight,
161
+ scrollWidth,
162
+ scrollHeight,
163
+ scrollTop,
164
+ scrollLeft
165
+ } = doc.documentElement;
166
+ const popupHeight = popupRect.height;
167
+ const popupWidth = popupRect.width;
168
+ const targetHeight = targetRect.height;
169
+ const targetWidth = targetRect.width;
177
170
 
178
171
  // Get bounding of visible area
179
- var visibleRegion = {
172
+ const visibleRegion = {
180
173
  left: 0,
181
174
  top: 0,
182
175
  right: clientWidth,
183
176
  bottom: clientHeight
184
177
  };
185
- var scrollRegion = {
178
+ const scrollRegion = {
186
179
  left: -scrollLeft,
187
180
  top: -scrollTop,
188
181
  right: scrollWidth - scrollLeft,
189
182
  bottom: scrollHeight - scrollTop
190
183
  };
191
- var htmlRegion = placementInfo.htmlRegion;
192
- var VISIBLE = 'visible';
193
- var VISIBLE_FIRST = 'visibleFirst';
184
+ let {
185
+ htmlRegion
186
+ } = placementInfo;
187
+ const VISIBLE = 'visible';
188
+ const VISIBLE_FIRST = 'visibleFirst';
194
189
  if (htmlRegion !== 'scroll' && htmlRegion !== VISIBLE_FIRST) {
195
190
  htmlRegion = VISIBLE;
196
191
  }
197
- var isVisibleFirst = htmlRegion === VISIBLE_FIRST;
198
- var scrollRegionArea = getVisibleArea(scrollRegion, scrollerList);
199
- var visibleRegionArea = getVisibleArea(visibleRegion, scrollerList);
200
- var visibleArea = htmlRegion === VISIBLE ? visibleRegionArea : scrollRegionArea;
192
+ const isVisibleFirst = htmlRegion === VISIBLE_FIRST;
193
+ const scrollRegionArea = getVisibleArea(scrollRegion, scrollerList);
194
+ const visibleRegionArea = getVisibleArea(visibleRegion, scrollerList);
195
+ const visibleArea = htmlRegion === VISIBLE ? visibleRegionArea : scrollRegionArea;
201
196
 
202
197
  // When set to `visibleFirst`,
203
198
  // the check `adjust` logic will use `visibleRegion` for check first.
204
- var adjustCheckVisibleArea = isVisibleFirst ? visibleRegionArea : visibleArea;
199
+ const adjustCheckVisibleArea = isVisibleFirst ? visibleRegionArea : visibleArea;
205
200
 
206
201
  // Record right & bottom align data
207
202
  popupElement.style.left = 'auto';
208
203
  popupElement.style.top = 'auto';
209
204
  popupElement.style.right = '0';
210
205
  popupElement.style.bottom = '0';
211
- var popupMirrorRect = popupElement.getBoundingClientRect();
206
+ const popupMirrorRect = popupElement.getBoundingClientRect();
212
207
 
213
208
  // Reset back
214
209
  popupElement.style.left = originLeft;
@@ -216,78 +211,74 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
216
211
  popupElement.style.right = originRight;
217
212
  popupElement.style.bottom = originBottom;
218
213
  popupElement.style.overflow = originOverflow;
219
- (_popupElement$parentE2 = popupElement.parentElement) === null || _popupElement$parentE2 === void 0 || _popupElement$parentE2.removeChild(placeholderElement);
214
+ popupElement.parentElement?.removeChild(placeholderElement);
220
215
 
221
216
  // Calculate scale
222
- var _scaleX = toNum(Math.round(popupWidth / parseFloat(width) * 1000) / 1000);
223
- var _scaleY = toNum(Math.round(popupHeight / parseFloat(height) * 1000) / 1000);
217
+ const scaleX = toNum(Math.round(popupWidth / parseFloat(width) * 1000) / 1000);
218
+ const scaleY = toNum(Math.round(popupHeight / parseFloat(height) * 1000) / 1000);
224
219
 
225
220
  // No need to align since it's not visible in view
226
- if (_scaleX === 0 || _scaleY === 0 || isDOM(target) && !isVisible(target)) {
221
+ if (scaleX === 0 || scaleY === 0 || isDOM(target) && !isVisible(target)) {
227
222
  return;
228
223
  }
229
224
 
230
225
  // Offset
231
- var offset = placementInfo.offset,
232
- targetOffset = placementInfo.targetOffset;
233
- var _getNumberOffset = getNumberOffset(popupRect, offset),
234
- _getNumberOffset2 = _slicedToArray(_getNumberOffset, 2),
235
- popupOffsetX = _getNumberOffset2[0],
236
- popupOffsetY = _getNumberOffset2[1];
237
- var _getNumberOffset3 = getNumberOffset(targetRect, targetOffset),
238
- _getNumberOffset4 = _slicedToArray(_getNumberOffset3, 2),
239
- targetOffsetX = _getNumberOffset4[0],
240
- targetOffsetY = _getNumberOffset4[1];
226
+ const {
227
+ offset,
228
+ targetOffset
229
+ } = placementInfo;
230
+ let [popupOffsetX, popupOffsetY] = getNumberOffset(popupRect, offset);
231
+ const [targetOffsetX, targetOffsetY] = getNumberOffset(targetRect, targetOffset);
241
232
  targetRect.x -= targetOffsetX;
242
233
  targetRect.y -= targetOffsetY;
243
234
 
244
235
  // Points
245
- var _ref3 = placementInfo.points || [],
246
- _ref4 = _slicedToArray(_ref3, 2),
247
- popupPoint = _ref4[0],
248
- targetPoint = _ref4[1];
249
- var targetPoints = splitPoints(targetPoint);
250
- var popupPoints = splitPoints(popupPoint);
251
- var targetAlignPoint = getAlignPoint(targetRect, targetPoints);
252
- var popupAlignPoint = getAlignPoint(popupRect, popupPoints);
236
+ const [popupPoint, targetPoint] = placementInfo.points || [];
237
+ const targetPoints = splitPoints(targetPoint);
238
+ const popupPoints = splitPoints(popupPoint);
239
+ const targetAlignPoint = getAlignPoint(targetRect, targetPoints);
240
+ const popupAlignPoint = getAlignPoint(popupRect, popupPoints);
253
241
 
254
242
  // Real align info may not same as origin one
255
- var nextAlignInfo = _objectSpread({}, placementInfo);
243
+ const nextAlignInfo = {
244
+ ...placementInfo
245
+ };
256
246
 
257
247
  // Next Offset
258
- var nextOffsetX = targetAlignPoint.x - popupAlignPoint.x + popupOffsetX;
259
- var nextOffsetY = targetAlignPoint.y - popupAlignPoint.y + popupOffsetY;
248
+ let nextOffsetX = targetAlignPoint.x - popupAlignPoint.x + popupOffsetX;
249
+ let nextOffsetY = targetAlignPoint.y - popupAlignPoint.y + popupOffsetY;
260
250
 
261
251
  // ============== Intersection ===============
262
252
  // Get area by position. Used for check if flip area is better
263
- function getIntersectionVisibleArea(offsetX, offsetY) {
264
- var area = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : visibleArea;
265
- var l = popupRect.x + offsetX;
266
- var t = popupRect.y + offsetY;
267
- var r = l + popupWidth;
268
- var b = t + popupHeight;
269
- var visibleL = Math.max(l, area.left);
270
- var visibleT = Math.max(t, area.top);
271
- var visibleR = Math.min(r, area.right);
272
- var visibleB = Math.min(b, area.bottom);
253
+ function getIntersectionVisibleArea(offsetX, offsetY, area = visibleArea) {
254
+ const l = popupRect.x + offsetX;
255
+ const t = popupRect.y + offsetY;
256
+ const r = l + popupWidth;
257
+ const b = t + popupHeight;
258
+ const visibleL = Math.max(l, area.left);
259
+ const visibleT = Math.max(t, area.top);
260
+ const visibleR = Math.min(r, area.right);
261
+ const visibleB = Math.min(b, area.bottom);
273
262
  return Math.max(0, (visibleR - visibleL) * (visibleB - visibleT));
274
263
  }
275
- var originIntersectionVisibleArea = getIntersectionVisibleArea(nextOffsetX, nextOffsetY);
264
+ const originIntersectionVisibleArea = getIntersectionVisibleArea(nextOffsetX, nextOffsetY);
276
265
 
277
266
  // As `visibleFirst`, we prepare this for check
278
- var originIntersectionRecommendArea = getIntersectionVisibleArea(nextOffsetX, nextOffsetY, visibleRegionArea);
267
+ const originIntersectionRecommendArea = getIntersectionVisibleArea(nextOffsetX, nextOffsetY, visibleRegionArea);
279
268
 
280
269
  // ========================== Overflow ===========================
281
- var targetAlignPointTL = getAlignPoint(targetRect, ['t', 'l']);
282
- var popupAlignPointTL = getAlignPoint(popupRect, ['t', 'l']);
283
- var targetAlignPointBR = getAlignPoint(targetRect, ['b', 'r']);
284
- var popupAlignPointBR = getAlignPoint(popupRect, ['b', 'r']);
285
- var overflow = placementInfo.overflow || {};
286
- var adjustX = overflow.adjustX,
287
- adjustY = overflow.adjustY,
288
- shiftX = overflow.shiftX,
289
- shiftY = overflow.shiftY;
290
- var supportAdjust = function supportAdjust(val) {
270
+ const targetAlignPointTL = getAlignPoint(targetRect, ['t', 'l']);
271
+ const popupAlignPointTL = getAlignPoint(popupRect, ['t', 'l']);
272
+ const targetAlignPointBR = getAlignPoint(targetRect, ['b', 'r']);
273
+ const popupAlignPointBR = getAlignPoint(popupRect, ['b', 'r']);
274
+ const overflow = placementInfo.overflow || {};
275
+ const {
276
+ adjustX,
277
+ adjustY,
278
+ shiftX,
279
+ shiftY
280
+ } = overflow;
281
+ const supportAdjust = val => {
291
282
  if (typeof val === 'boolean') {
292
283
  return val;
293
284
  }
@@ -295,10 +286,10 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
295
286
  };
296
287
 
297
288
  // Prepare position
298
- var nextPopupY;
299
- var nextPopupBottom;
300
- var nextPopupX;
301
- var nextPopupRight;
289
+ let nextPopupY;
290
+ let nextPopupBottom;
291
+ let nextPopupX;
292
+ let nextPopupRight;
302
293
  function syncNextPopupPosition() {
303
294
  nextPopupY = popupRect.y + nextOffsetY;
304
295
  nextPopupBottom = nextPopupY + popupHeight;
@@ -308,19 +299,19 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
308
299
  syncNextPopupPosition();
309
300
 
310
301
  // >>>>>>>>>> Top & Bottom
311
- var needAdjustY = supportAdjust(adjustY);
312
- var sameTB = popupPoints[0] === targetPoints[0];
302
+ const needAdjustY = supportAdjust(adjustY);
303
+ const sameTB = popupPoints[0] === targetPoints[0];
313
304
 
314
305
  // Bottom to Top
315
306
  if (needAdjustY && popupPoints[0] === 't' && (nextPopupBottom > adjustCheckVisibleArea.bottom || prevFlipRef.current.bt)) {
316
- var tmpNextOffsetY = nextOffsetY;
307
+ let tmpNextOffsetY = nextOffsetY;
317
308
  if (sameTB) {
318
309
  tmpNextOffsetY -= popupHeight - targetHeight;
319
310
  } else {
320
311
  tmpNextOffsetY = targetAlignPointTL.y - popupAlignPointBR.y - popupOffsetY;
321
312
  }
322
- var newVisibleArea = getIntersectionVisibleArea(nextOffsetX, tmpNextOffsetY);
323
- var newVisibleRecommendArea = getIntersectionVisibleArea(nextOffsetX, tmpNextOffsetY, visibleRegionArea);
313
+ const newVisibleArea = getIntersectionVisibleArea(nextOffsetX, tmpNextOffsetY);
314
+ const newVisibleRecommendArea = getIntersectionVisibleArea(nextOffsetX, tmpNextOffsetY, visibleRegionArea);
324
315
  if (
325
316
  // Of course use larger one
326
317
  newVisibleArea > originIntersectionVisibleArea || newVisibleArea === originIntersectionVisibleArea && (!isVisibleFirst ||
@@ -337,21 +328,21 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
337
328
 
338
329
  // Top to Bottom
339
330
  if (needAdjustY && popupPoints[0] === 'b' && (nextPopupY < adjustCheckVisibleArea.top || prevFlipRef.current.tb)) {
340
- var _tmpNextOffsetY = nextOffsetY;
331
+ let tmpNextOffsetY = nextOffsetY;
341
332
  if (sameTB) {
342
- _tmpNextOffsetY += popupHeight - targetHeight;
333
+ tmpNextOffsetY += popupHeight - targetHeight;
343
334
  } else {
344
- _tmpNextOffsetY = targetAlignPointBR.y - popupAlignPointTL.y - popupOffsetY;
335
+ tmpNextOffsetY = targetAlignPointBR.y - popupAlignPointTL.y - popupOffsetY;
345
336
  }
346
- var _newVisibleArea = getIntersectionVisibleArea(nextOffsetX, _tmpNextOffsetY);
347
- var _newVisibleRecommendArea = getIntersectionVisibleArea(nextOffsetX, _tmpNextOffsetY, visibleRegionArea);
337
+ const newVisibleArea = getIntersectionVisibleArea(nextOffsetX, tmpNextOffsetY);
338
+ const newVisibleRecommendArea = getIntersectionVisibleArea(nextOffsetX, tmpNextOffsetY, visibleRegionArea);
348
339
  if (
349
340
  // Of course use larger one
350
- _newVisibleArea > originIntersectionVisibleArea || _newVisibleArea === originIntersectionVisibleArea && (!isVisibleFirst ||
341
+ newVisibleArea > originIntersectionVisibleArea || newVisibleArea === originIntersectionVisibleArea && (!isVisibleFirst ||
351
342
  // Choose recommend one
352
- _newVisibleRecommendArea >= originIntersectionRecommendArea)) {
343
+ newVisibleRecommendArea >= originIntersectionRecommendArea)) {
353
344
  prevFlipRef.current.tb = true;
354
- nextOffsetY = _tmpNextOffsetY;
345
+ nextOffsetY = tmpNextOffsetY;
355
346
  popupOffsetY = -popupOffsetY;
356
347
  nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
357
348
  } else {
@@ -360,26 +351,26 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
360
351
  }
361
352
 
362
353
  // >>>>>>>>>> Left & Right
363
- var needAdjustX = supportAdjust(adjustX);
354
+ const needAdjustX = supportAdjust(adjustX);
364
355
 
365
356
  // >>>>> Flip
366
- var sameLR = popupPoints[1] === targetPoints[1];
357
+ const sameLR = popupPoints[1] === targetPoints[1];
367
358
 
368
359
  // Right to Left
369
360
  if (needAdjustX && popupPoints[1] === 'l' && (nextPopupRight > adjustCheckVisibleArea.right || prevFlipRef.current.rl)) {
370
- var tmpNextOffsetX = nextOffsetX;
361
+ let tmpNextOffsetX = nextOffsetX;
371
362
  if (sameLR) {
372
363
  tmpNextOffsetX -= popupWidth - targetWidth;
373
364
  } else {
374
365
  tmpNextOffsetX = targetAlignPointTL.x - popupAlignPointBR.x - popupOffsetX;
375
366
  }
376
- var _newVisibleArea2 = getIntersectionVisibleArea(tmpNextOffsetX, nextOffsetY);
377
- var _newVisibleRecommendArea2 = getIntersectionVisibleArea(tmpNextOffsetX, nextOffsetY, visibleRegionArea);
367
+ const newVisibleArea = getIntersectionVisibleArea(tmpNextOffsetX, nextOffsetY);
368
+ const newVisibleRecommendArea = getIntersectionVisibleArea(tmpNextOffsetX, nextOffsetY, visibleRegionArea);
378
369
  if (
379
370
  // Of course use larger one
380
- _newVisibleArea2 > originIntersectionVisibleArea || _newVisibleArea2 === originIntersectionVisibleArea && (!isVisibleFirst ||
371
+ newVisibleArea > originIntersectionVisibleArea || newVisibleArea === originIntersectionVisibleArea && (!isVisibleFirst ||
381
372
  // Choose recommend one
382
- _newVisibleRecommendArea2 >= originIntersectionRecommendArea)) {
373
+ newVisibleRecommendArea >= originIntersectionRecommendArea)) {
383
374
  prevFlipRef.current.rl = true;
384
375
  nextOffsetX = tmpNextOffsetX;
385
376
  popupOffsetX = -popupOffsetX;
@@ -391,21 +382,21 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
391
382
 
392
383
  // Left to Right
393
384
  if (needAdjustX && popupPoints[1] === 'r' && (nextPopupX < adjustCheckVisibleArea.left || prevFlipRef.current.lr)) {
394
- var _tmpNextOffsetX = nextOffsetX;
385
+ let tmpNextOffsetX = nextOffsetX;
395
386
  if (sameLR) {
396
- _tmpNextOffsetX += popupWidth - targetWidth;
387
+ tmpNextOffsetX += popupWidth - targetWidth;
397
388
  } else {
398
- _tmpNextOffsetX = targetAlignPointBR.x - popupAlignPointTL.x - popupOffsetX;
389
+ tmpNextOffsetX = targetAlignPointBR.x - popupAlignPointTL.x - popupOffsetX;
399
390
  }
400
- var _newVisibleArea3 = getIntersectionVisibleArea(_tmpNextOffsetX, nextOffsetY);
401
- var _newVisibleRecommendArea3 = getIntersectionVisibleArea(_tmpNextOffsetX, nextOffsetY, visibleRegionArea);
391
+ const newVisibleArea = getIntersectionVisibleArea(tmpNextOffsetX, nextOffsetY);
392
+ const newVisibleRecommendArea = getIntersectionVisibleArea(tmpNextOffsetX, nextOffsetY, visibleRegionArea);
402
393
  if (
403
394
  // Of course use larger one
404
- _newVisibleArea3 > originIntersectionVisibleArea || _newVisibleArea3 === originIntersectionVisibleArea && (!isVisibleFirst ||
395
+ newVisibleArea > originIntersectionVisibleArea || newVisibleArea === originIntersectionVisibleArea && (!isVisibleFirst ||
405
396
  // Choose recommend one
406
- _newVisibleRecommendArea3 >= originIntersectionRecommendArea)) {
397
+ newVisibleRecommendArea >= originIntersectionRecommendArea)) {
407
398
  prevFlipRef.current.lr = true;
408
- nextOffsetX = _tmpNextOffsetX;
399
+ nextOffsetX = tmpNextOffsetX;
409
400
  popupOffsetX = -popupOffsetX;
410
401
  nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
411
402
  } else {
@@ -415,7 +406,7 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
415
406
 
416
407
  // ============================ Shift ============================
417
408
  syncNextPopupPosition();
418
- var numShiftX = shiftX === true ? 0 : shiftX;
409
+ const numShiftX = shiftX === true ? 0 : shiftX;
419
410
  if (typeof numShiftX === 'number') {
420
411
  // Left
421
412
  if (nextPopupX < visibleRegionArea.left) {
@@ -433,7 +424,7 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
433
424
  }
434
425
  }
435
426
  }
436
- var numShiftY = shiftY === true ? 0 : shiftY;
427
+ const numShiftY = shiftY === true ? 0 : shiftY;
437
428
  if (typeof numShiftY === 'number') {
438
429
  // Top
439
430
  if (nextPopupY < visibleRegionArea.top) {
@@ -457,56 +448,56 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
457
448
 
458
449
  // ============================ Arrow ============================
459
450
  // Arrow center align
460
- var popupLeft = popupRect.x + nextOffsetX;
461
- var popupRight = popupLeft + popupWidth;
462
- var popupTop = popupRect.y + nextOffsetY;
463
- var popupBottom = popupTop + popupHeight;
464
- var targetLeft = targetRect.x;
465
- var targetRight = targetLeft + targetWidth;
466
- var targetTop = targetRect.y;
467
- var targetBottom = targetTop + targetHeight;
468
- var maxLeft = Math.max(popupLeft, targetLeft);
469
- var minRight = Math.min(popupRight, targetRight);
470
- var xCenter = (maxLeft + minRight) / 2;
471
- var nextArrowX = xCenter - popupLeft;
472
- var maxTop = Math.max(popupTop, targetTop);
473
- var minBottom = Math.min(popupBottom, targetBottom);
474
- var yCenter = (maxTop + minBottom) / 2;
475
- var nextArrowY = yCenter - popupTop;
476
- onPopupAlign === null || onPopupAlign === void 0 || onPopupAlign(popupEle, nextAlignInfo);
451
+ const popupLeft = popupRect.x + nextOffsetX;
452
+ const popupRight = popupLeft + popupWidth;
453
+ const popupTop = popupRect.y + nextOffsetY;
454
+ const popupBottom = popupTop + popupHeight;
455
+ const targetLeft = targetRect.x;
456
+ const targetRight = targetLeft + targetWidth;
457
+ const targetTop = targetRect.y;
458
+ const targetBottom = targetTop + targetHeight;
459
+ const maxLeft = Math.max(popupLeft, targetLeft);
460
+ const minRight = Math.min(popupRight, targetRight);
461
+ const xCenter = (maxLeft + minRight) / 2;
462
+ const nextArrowX = xCenter - popupLeft;
463
+ const maxTop = Math.max(popupTop, targetTop);
464
+ const minBottom = Math.min(popupBottom, targetBottom);
465
+ const yCenter = (maxTop + minBottom) / 2;
466
+ const nextArrowY = yCenter - popupTop;
467
+ onPopupAlign?.(popupEle, nextAlignInfo);
477
468
 
478
469
  // Additional calculate right & bottom position
479
- var offsetX4Right = popupMirrorRect.right - popupRect.x - (nextOffsetX + popupRect.width);
480
- var offsetY4Bottom = popupMirrorRect.bottom - popupRect.y - (nextOffsetY + popupRect.height);
481
- if (_scaleX === 1) {
470
+ let offsetX4Right = popupMirrorRect.right - popupRect.x - (nextOffsetX + popupRect.width);
471
+ let offsetY4Bottom = popupMirrorRect.bottom - popupRect.y - (nextOffsetY + popupRect.height);
472
+ if (scaleX === 1) {
482
473
  nextOffsetX = Math.round(nextOffsetX);
483
474
  offsetX4Right = Math.round(offsetX4Right);
484
475
  }
485
- if (_scaleY === 1) {
476
+ if (scaleY === 1) {
486
477
  nextOffsetY = Math.round(nextOffsetY);
487
478
  offsetY4Bottom = Math.round(offsetY4Bottom);
488
479
  }
489
- var nextOffsetInfo = {
480
+ const nextOffsetInfo = {
490
481
  ready: true,
491
- offsetX: nextOffsetX / _scaleX,
492
- offsetY: nextOffsetY / _scaleY,
493
- offsetR: offsetX4Right / _scaleX,
494
- offsetB: offsetY4Bottom / _scaleY,
495
- arrowX: nextArrowX / _scaleX,
496
- arrowY: nextArrowY / _scaleY,
497
- scaleX: _scaleX,
498
- scaleY: _scaleY,
482
+ offsetX: nextOffsetX / scaleX,
483
+ offsetY: nextOffsetY / scaleY,
484
+ offsetR: offsetX4Right / scaleX,
485
+ offsetB: offsetY4Bottom / scaleY,
486
+ arrowX: nextArrowX / scaleX,
487
+ arrowY: nextArrowY / scaleY,
488
+ scaleX,
489
+ scaleY,
499
490
  align: nextAlignInfo
500
491
  };
501
492
  setOffsetInfo(nextOffsetInfo);
502
493
  }
503
494
  });
504
- var triggerAlign = function triggerAlign() {
495
+ const triggerAlign = () => {
505
496
  alignCountRef.current += 1;
506
- var id = alignCountRef.current;
497
+ const id = alignCountRef.current;
507
498
 
508
499
  // Merge all align requirement into one frame
509
- Promise.resolve().then(function () {
500
+ Promise.resolve().then(() => {
510
501
  if (alignCountRef.current === id) {
511
502
  onAlign();
512
503
  }
@@ -514,15 +505,14 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
514
505
  };
515
506
 
516
507
  // Reset ready status when placement & open changed
517
- var resetReady = function resetReady() {
518
- setOffsetInfo(function (ori) {
519
- return _objectSpread(_objectSpread({}, ori), {}, {
520
- ready: false
521
- });
522
- });
508
+ const resetReady = () => {
509
+ setOffsetInfo(ori => ({
510
+ ...ori,
511
+ ready: false
512
+ }));
523
513
  };
524
514
  useLayoutEffect(resetReady, [placement]);
525
- useLayoutEffect(function () {
515
+ useLayoutEffect(() => {
526
516
  if (!open) {
527
517
  resetReady();
528
518
  }