@rc-component/trigger 1.6.3 → 1.7.1

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.
@@ -212,18 +212,20 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
212
212
 
213
213
  // ============== Intersection ===============
214
214
  // Get area by position. Used for check if flip area is better
215
- function getIntersectionVisibleArea(x, y) {
216
- var r = x + popupWidth;
217
- var b = y + popupHeight;
218
- var visibleX = Math.max(x, visibleArea.left);
219
- var visibleY = Math.max(y, visibleArea.top);
215
+ function getIntersectionVisibleArea(offsetX, offsetY) {
216
+ var l = popupRect.x + offsetX;
217
+ var t = popupRect.y + offsetY;
218
+ var r = l + popupWidth;
219
+ var b = t + popupHeight;
220
+ var visibleL = Math.max(l, visibleArea.left);
221
+ var visibleT = Math.max(t, visibleArea.top);
220
222
  var visibleR = Math.min(r, visibleArea.right);
221
223
  var visibleB = Math.min(b, visibleArea.bottom);
222
- return (visibleR - visibleX) * (visibleB - visibleY);
224
+ return (visibleR - visibleL) * (visibleB - visibleT);
223
225
  }
224
226
  var originIntersectionVisibleArea = getIntersectionVisibleArea(nextOffsetX, nextOffsetY);
225
227
 
226
- // ================ Overflow =================
228
+ // ========================== Overflow ===========================
227
229
  var targetAlignPointTL = getAlignPoint(targetRect, ['t', 'l']);
228
230
  var popupAlignPointTL = getAlignPoint(popupRect, ['t', 'l']);
229
231
  var targetAlignPointBR = getAlignPoint(targetRect, ['b', 'r']);
@@ -240,9 +242,20 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
240
242
  return val >= 0;
241
243
  };
242
244
 
245
+ // Prepare position
246
+ var nextPopupY;
247
+ var nextPopupBottom;
248
+ var nextPopupX;
249
+ var nextPopupRight;
250
+ function syncNextPopupPosition() {
251
+ nextPopupY = popupRect.y + nextOffsetY;
252
+ nextPopupBottom = nextPopupY + popupHeight;
253
+ nextPopupX = popupRect.x + nextOffsetX;
254
+ nextPopupRight = nextPopupX + popupWidth;
255
+ }
256
+ syncNextPopupPosition();
257
+
243
258
  // >>>>>>>>>> Top & Bottom
244
- var nextPopupY = popupRect.y + nextOffsetY;
245
- var nextPopupBottom = nextPopupY + popupHeight;
246
259
  var needAdjustY = supportAdjust(adjustY);
247
260
  var sameTB = popupPoints[0] === targetPoints[0];
248
261
 
@@ -275,8 +288,6 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
275
288
  }
276
289
 
277
290
  // >>>>>>>>>> Left & Right
278
- var nextPopupX = popupRect.x + nextOffsetX;
279
- var nextPopupRight = nextPopupX + popupWidth;
280
291
  var needAdjustX = supportAdjust(adjustX);
281
292
 
282
293
  // >>>>> Flip
@@ -310,7 +321,8 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
310
321
  }
311
322
  }
312
323
 
313
- // >>>>> Shift
324
+ // ============================ Shift ============================
325
+ syncNextPopupPosition();
314
326
  var numShiftX = shiftX === true ? 0 : shiftX;
315
327
  if (typeof numShiftX === 'number') {
316
328
  // Left
@@ -348,6 +360,7 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
348
360
  }
349
361
  }
350
362
 
363
+ // ============================ Arrow ============================
351
364
  // Arrow center align
352
365
  var popupLeft = popupRect.x + nextOffsetX;
353
366
  var popupRight = popupLeft + popupWidth;
@@ -220,18 +220,20 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
220
220
 
221
221
  // ============== Intersection ===============
222
222
  // Get area by position. Used for check if flip area is better
223
- function getIntersectionVisibleArea(x, y) {
224
- var r = x + popupWidth;
225
- var b = y + popupHeight;
226
- var visibleX = Math.max(x, visibleArea.left);
227
- var visibleY = Math.max(y, visibleArea.top);
223
+ function getIntersectionVisibleArea(offsetX, offsetY) {
224
+ var l = popupRect.x + offsetX;
225
+ var t = popupRect.y + offsetY;
226
+ var r = l + popupWidth;
227
+ var b = t + popupHeight;
228
+ var visibleL = Math.max(l, visibleArea.left);
229
+ var visibleT = Math.max(t, visibleArea.top);
228
230
  var visibleR = Math.min(r, visibleArea.right);
229
231
  var visibleB = Math.min(b, visibleArea.bottom);
230
- return (visibleR - visibleX) * (visibleB - visibleY);
232
+ return (visibleR - visibleL) * (visibleB - visibleT);
231
233
  }
232
234
  var originIntersectionVisibleArea = getIntersectionVisibleArea(nextOffsetX, nextOffsetY);
233
235
 
234
- // ================ Overflow =================
236
+ // ========================== Overflow ===========================
235
237
  var targetAlignPointTL = getAlignPoint(targetRect, ['t', 'l']);
236
238
  var popupAlignPointTL = getAlignPoint(popupRect, ['t', 'l']);
237
239
  var targetAlignPointBR = getAlignPoint(targetRect, ['b', 'r']);
@@ -248,9 +250,20 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
248
250
  return val >= 0;
249
251
  };
250
252
 
253
+ // Prepare position
254
+ var nextPopupY;
255
+ var nextPopupBottom;
256
+ var nextPopupX;
257
+ var nextPopupRight;
258
+ function syncNextPopupPosition() {
259
+ nextPopupY = popupRect.y + nextOffsetY;
260
+ nextPopupBottom = nextPopupY + popupHeight;
261
+ nextPopupX = popupRect.x + nextOffsetX;
262
+ nextPopupRight = nextPopupX + popupWidth;
263
+ }
264
+ syncNextPopupPosition();
265
+
251
266
  // >>>>>>>>>> Top & Bottom
252
- var nextPopupY = popupRect.y + nextOffsetY;
253
- var nextPopupBottom = nextPopupY + popupHeight;
254
267
  var needAdjustY = supportAdjust(adjustY);
255
268
  var sameTB = popupPoints[0] === targetPoints[0];
256
269
 
@@ -283,8 +296,6 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
283
296
  }
284
297
 
285
298
  // >>>>>>>>>> Left & Right
286
- var nextPopupX = popupRect.x + nextOffsetX;
287
- var nextPopupRight = nextPopupX + popupWidth;
288
299
  var needAdjustX = supportAdjust(adjustX);
289
300
 
290
301
  // >>>>> Flip
@@ -318,7 +329,8 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
318
329
  }
319
330
  }
320
331
 
321
- // >>>>> Shift
332
+ // ============================ Shift ============================
333
+ syncNextPopupPosition();
322
334
  var numShiftX = shiftX === true ? 0 : shiftX;
323
335
  if (typeof numShiftX === 'number') {
324
336
  // Left
@@ -356,6 +368,7 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
356
368
  }
357
369
  }
358
370
 
371
+ // ============================ Arrow ============================
359
372
  // Arrow center align
360
373
  var popupLeft = popupRect.x + nextOffsetX;
361
374
  var popupRight = popupLeft + popupWidth;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/trigger",
3
- "version": "1.6.3",
3
+ "version": "1.7.1",
4
4
  "description": "base abstract trigger component for react",
5
5
  "engines": {
6
6
  "node": ">=8.x"