@rc-component/trigger 1.12.1 → 1.13.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.
- package/README.md +14 -16
- package/es/hooks/useAlign.js +61 -21
- package/es/index.js +1 -1
- package/es/interface.d.ts +10 -3
- package/lib/hooks/useAlign.js +61 -21
- package/lib/index.js +1 -1
- package/lib/interface.d.ts +10 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,22 +9,20 @@ React Trigger Component
|
|
|
9
9
|
[![bundle size][bundlephobia-image]][bundlephobia-url]
|
|
10
10
|
[![dumi][dumi-image]][dumi-url]
|
|
11
11
|
|
|
12
|
-
[npm-image]: http://img.shields.io/npm/v
|
|
13
|
-
[npm-url]: http://npmjs.org/package
|
|
14
|
-
[github-actions-image]: https://github.com/react-component/
|
|
15
|
-
[github-actions-url]: https://github.com/react-component/
|
|
16
|
-
[
|
|
17
|
-
[
|
|
18
|
-
[
|
|
19
|
-
[
|
|
20
|
-
[david-url]: https://david-dm.org/react-component/
|
|
21
|
-
[david-image]: https://david-dm.org/react-component/
|
|
22
|
-
[
|
|
23
|
-
[
|
|
24
|
-
[
|
|
25
|
-
[
|
|
26
|
-
[bundlephobia-url]: https://bundlephobia.com/result?p=@rc-component/trigger
|
|
27
|
-
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/trigger
|
|
12
|
+
[npm-image]: http://img.shields.io/npm/v/rc-checkbox.svg?style=flat-square
|
|
13
|
+
[npm-url]: http://npmjs.org/package/rc-checkbox
|
|
14
|
+
[github-actions-image]: https://github.com/react-component/checkbox/workflows/CI/badge.svg
|
|
15
|
+
[github-actions-url]: https://github.com/react-component/checkbox/actions
|
|
16
|
+
[codecov-image]: https://img.shields.io/codecov/c/github/react-component/checkbox/master.svg?style=flat-square
|
|
17
|
+
[codecov-url]: https://codecov.io/gh/react-component/checkbox/branch/master
|
|
18
|
+
[david-url]: https://david-dm.org/react-component/checkbox
|
|
19
|
+
[david-image]: https://david-dm.org/react-component/checkbox/status.svg?style=flat-square
|
|
20
|
+
[david-dev-url]: https://david-dm.org/react-component/checkbox?type=dev
|
|
21
|
+
[david-dev-image]: https://david-dm.org/react-component/checkbox/dev-status.svg?style=flat-square
|
|
22
|
+
[download-image]: https://img.shields.io/npm/dm/rc-checkbox.svg?style=flat-square
|
|
23
|
+
[download-url]: https://npmjs.org/package/rc-checkbox
|
|
24
|
+
[bundlephobia-url]: https://bundlephobia.com/result?p=rc-checkbox
|
|
25
|
+
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-checkbox
|
|
28
26
|
[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square
|
|
29
27
|
[dumi-url]: https://github.com/umijs/dumi
|
|
30
28
|
|
package/es/hooks/useAlign.js
CHANGED
|
@@ -152,20 +152,32 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
152
152
|
var targetWidth = targetRect.width;
|
|
153
153
|
|
|
154
154
|
// Get bounding of visible area
|
|
155
|
-
var
|
|
156
|
-
// Scroll region should take scrollLeft & scrollTop into account
|
|
157
|
-
{
|
|
158
|
-
left: -scrollLeft,
|
|
159
|
-
top: -scrollTop,
|
|
160
|
-
right: scrollWidth - scrollLeft,
|
|
161
|
-
bottom: scrollHeight - scrollTop
|
|
162
|
-
} : {
|
|
155
|
+
var visibleRegion = {
|
|
163
156
|
left: 0,
|
|
164
157
|
top: 0,
|
|
165
158
|
right: clientWidth,
|
|
166
159
|
bottom: clientHeight
|
|
167
160
|
};
|
|
168
|
-
|
|
161
|
+
var scrollRegion = {
|
|
162
|
+
left: -scrollLeft,
|
|
163
|
+
top: -scrollTop,
|
|
164
|
+
right: scrollWidth - scrollLeft,
|
|
165
|
+
bottom: scrollHeight - scrollTop
|
|
166
|
+
};
|
|
167
|
+
var htmlRegion = placementInfo.htmlRegion;
|
|
168
|
+
var VISIBLE = 'visible';
|
|
169
|
+
var VISIBLE_FIRST = 'visibleFirst';
|
|
170
|
+
if (htmlRegion !== 'scroll' && htmlRegion !== VISIBLE_FIRST) {
|
|
171
|
+
htmlRegion = VISIBLE;
|
|
172
|
+
}
|
|
173
|
+
var isVisibleFirst = htmlRegion === VISIBLE_FIRST;
|
|
174
|
+
var scrollRegionArea = getVisibleArea(scrollRegion, scrollerList);
|
|
175
|
+
var visibleRegionArea = getVisibleArea(visibleRegion, scrollerList);
|
|
176
|
+
var visibleArea = htmlRegion === VISIBLE ? visibleRegionArea : scrollRegionArea;
|
|
177
|
+
|
|
178
|
+
// When set to `visibleFirst`,
|
|
179
|
+
// the check `adjust` logic will use `visibleRegion` for check first.
|
|
180
|
+
var adjustCheckVisibleArea = isVisibleFirst ? visibleRegionArea : visibleArea;
|
|
169
181
|
|
|
170
182
|
// Reset back
|
|
171
183
|
popupElement.style.left = originLeft;
|
|
@@ -214,18 +226,22 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
214
226
|
// ============== Intersection ===============
|
|
215
227
|
// Get area by position. Used for check if flip area is better
|
|
216
228
|
function getIntersectionVisibleArea(offsetX, offsetY) {
|
|
229
|
+
var area = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : visibleArea;
|
|
217
230
|
var l = popupRect.x + offsetX;
|
|
218
231
|
var t = popupRect.y + offsetY;
|
|
219
232
|
var r = l + popupWidth;
|
|
220
233
|
var b = t + popupHeight;
|
|
221
|
-
var visibleL = Math.max(l,
|
|
222
|
-
var visibleT = Math.max(t,
|
|
223
|
-
var visibleR = Math.min(r,
|
|
224
|
-
var visibleB = Math.min(b,
|
|
234
|
+
var visibleL = Math.max(l, area.left);
|
|
235
|
+
var visibleT = Math.max(t, area.top);
|
|
236
|
+
var visibleR = Math.min(r, area.right);
|
|
237
|
+
var visibleB = Math.min(b, area.bottom);
|
|
225
238
|
return Math.max(0, (visibleR - visibleL) * (visibleB - visibleT));
|
|
226
239
|
}
|
|
227
240
|
var originIntersectionVisibleArea = getIntersectionVisibleArea(nextOffsetX, nextOffsetY);
|
|
228
241
|
|
|
242
|
+
// As `visibleFirst`, we prepare this for check
|
|
243
|
+
var originIntersectionRecommendArea = getIntersectionVisibleArea(nextOffsetX, nextOffsetY, visibleRegionArea);
|
|
244
|
+
|
|
229
245
|
// ========================== Overflow ===========================
|
|
230
246
|
var targetAlignPointTL = getAlignPoint(targetRect, ['t', 'l']);
|
|
231
247
|
var popupAlignPointTL = getAlignPoint(popupRect, ['t', 'l']);
|
|
@@ -261,14 +277,20 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
261
277
|
var sameTB = popupPoints[0] === targetPoints[0];
|
|
262
278
|
|
|
263
279
|
// Bottom to Top
|
|
264
|
-
if (needAdjustY && popupPoints[0] === 't' && (nextPopupBottom >
|
|
280
|
+
if (needAdjustY && popupPoints[0] === 't' && (nextPopupBottom > adjustCheckVisibleArea.bottom || prevFlipRef.current.bt)) {
|
|
265
281
|
var tmpNextOffsetY = nextOffsetY;
|
|
266
282
|
if (sameTB) {
|
|
267
283
|
tmpNextOffsetY -= popupHeight - targetHeight;
|
|
268
284
|
} else {
|
|
269
285
|
tmpNextOffsetY = targetAlignPointTL.y - popupAlignPointBR.y - popupOffsetY;
|
|
270
286
|
}
|
|
271
|
-
|
|
287
|
+
var newVisibleArea = getIntersectionVisibleArea(nextOffsetX, tmpNextOffsetY);
|
|
288
|
+
var newVisibleRecommendArea = getIntersectionVisibleArea(nextOffsetX, tmpNextOffsetY, visibleRegionArea);
|
|
289
|
+
if (
|
|
290
|
+
// Of course use larger one
|
|
291
|
+
newVisibleArea > originIntersectionVisibleArea || newVisibleArea === originIntersectionVisibleArea && (!isVisibleFirst ||
|
|
292
|
+
// Choose recommend one
|
|
293
|
+
newVisibleRecommendArea >= originIntersectionRecommendArea)) {
|
|
272
294
|
prevFlipRef.current.bt = true;
|
|
273
295
|
nextOffsetY = tmpNextOffsetY;
|
|
274
296
|
nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
|
|
@@ -278,14 +300,20 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
278
300
|
}
|
|
279
301
|
|
|
280
302
|
// Top to Bottom
|
|
281
|
-
if (needAdjustY && popupPoints[0] === 'b' && (nextPopupY <
|
|
303
|
+
if (needAdjustY && popupPoints[0] === 'b' && (nextPopupY < adjustCheckVisibleArea.top || prevFlipRef.current.tb)) {
|
|
282
304
|
var _tmpNextOffsetY = nextOffsetY;
|
|
283
305
|
if (sameTB) {
|
|
284
306
|
_tmpNextOffsetY += popupHeight - targetHeight;
|
|
285
307
|
} else {
|
|
286
308
|
_tmpNextOffsetY = targetAlignPointBR.y - popupAlignPointTL.y - popupOffsetY;
|
|
287
309
|
}
|
|
288
|
-
|
|
310
|
+
var _newVisibleArea = getIntersectionVisibleArea(nextOffsetX, _tmpNextOffsetY);
|
|
311
|
+
var _newVisibleRecommendArea = getIntersectionVisibleArea(nextOffsetX, _tmpNextOffsetY, visibleRegionArea);
|
|
312
|
+
if (
|
|
313
|
+
// Of course use larger one
|
|
314
|
+
_newVisibleArea > originIntersectionVisibleArea || _newVisibleArea === originIntersectionVisibleArea && (!isVisibleFirst ||
|
|
315
|
+
// Choose recommend one
|
|
316
|
+
_newVisibleRecommendArea >= originIntersectionRecommendArea)) {
|
|
289
317
|
prevFlipRef.current.tb = true;
|
|
290
318
|
nextOffsetY = _tmpNextOffsetY;
|
|
291
319
|
nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
|
|
@@ -301,14 +329,20 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
301
329
|
var sameLR = popupPoints[1] === targetPoints[1];
|
|
302
330
|
|
|
303
331
|
// Right to Left
|
|
304
|
-
if (needAdjustX && popupPoints[1] === 'l' && (nextPopupRight >
|
|
332
|
+
if (needAdjustX && popupPoints[1] === 'l' && (nextPopupRight > adjustCheckVisibleArea.right || prevFlipRef.current.rl)) {
|
|
305
333
|
var tmpNextOffsetX = nextOffsetX;
|
|
306
334
|
if (sameLR) {
|
|
307
335
|
tmpNextOffsetX -= popupWidth - targetWidth;
|
|
308
336
|
} else {
|
|
309
337
|
tmpNextOffsetX = targetAlignPointTL.x - popupAlignPointBR.x - popupOffsetX;
|
|
310
338
|
}
|
|
311
|
-
|
|
339
|
+
var _newVisibleArea2 = getIntersectionVisibleArea(tmpNextOffsetX, nextOffsetY);
|
|
340
|
+
var _newVisibleRecommendArea2 = getIntersectionVisibleArea(tmpNextOffsetX, nextOffsetY, visibleRegionArea);
|
|
341
|
+
if (
|
|
342
|
+
// Of course use larger one
|
|
343
|
+
_newVisibleArea2 > originIntersectionVisibleArea || _newVisibleArea2 === originIntersectionVisibleArea && (!isVisibleFirst ||
|
|
344
|
+
// Choose recommend one
|
|
345
|
+
_newVisibleRecommendArea2 >= originIntersectionRecommendArea)) {
|
|
312
346
|
prevFlipRef.current.rl = true;
|
|
313
347
|
nextOffsetX = tmpNextOffsetX;
|
|
314
348
|
nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
|
|
@@ -318,14 +352,20 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
318
352
|
}
|
|
319
353
|
|
|
320
354
|
// Left to Right
|
|
321
|
-
if (needAdjustX && popupPoints[1] === 'r' && (nextPopupX <
|
|
355
|
+
if (needAdjustX && popupPoints[1] === 'r' && (nextPopupX < adjustCheckVisibleArea.left || prevFlipRef.current.lr)) {
|
|
322
356
|
var _tmpNextOffsetX = nextOffsetX;
|
|
323
357
|
if (sameLR) {
|
|
324
358
|
_tmpNextOffsetX += popupWidth - targetWidth;
|
|
325
359
|
} else {
|
|
326
360
|
_tmpNextOffsetX = targetAlignPointBR.x - popupAlignPointTL.x - popupOffsetX;
|
|
327
361
|
}
|
|
328
|
-
|
|
362
|
+
var _newVisibleArea3 = getIntersectionVisibleArea(_tmpNextOffsetX, nextOffsetY);
|
|
363
|
+
var _newVisibleRecommendArea3 = getIntersectionVisibleArea(_tmpNextOffsetX, nextOffsetY, visibleRegionArea);
|
|
364
|
+
if (
|
|
365
|
+
// Of course use larger one
|
|
366
|
+
_newVisibleArea3 > originIntersectionVisibleArea || _newVisibleArea3 === originIntersectionVisibleArea && (!isVisibleFirst ||
|
|
367
|
+
// Choose recommend one
|
|
368
|
+
_newVisibleRecommendArea3 >= originIntersectionRecommendArea)) {
|
|
329
369
|
prevFlipRef.current.lr = true;
|
|
330
370
|
nextOffsetX = _tmpNextOffsetX;
|
|
331
371
|
nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
|
package/es/index.js
CHANGED
|
@@ -223,7 +223,7 @@ export function generateTrigger() {
|
|
|
223
223
|
useWatch(mergedOpen, targetEle, popupEle, triggerAlign);
|
|
224
224
|
useLayoutEffect(function () {
|
|
225
225
|
triggerAlign();
|
|
226
|
-
}, [mousePos]);
|
|
226
|
+
}, [mousePos, popupPlacement]);
|
|
227
227
|
|
|
228
228
|
// When no builtinPlacements and popupAlign changed
|
|
229
229
|
useLayoutEffect(function () {
|
package/es/interface.d.ts
CHANGED
|
@@ -36,10 +36,17 @@ export interface AlignType {
|
|
|
36
36
|
autoArrow?: boolean;
|
|
37
37
|
/**
|
|
38
38
|
* Config visible region check of html node. Default `visible`:
|
|
39
|
-
* - `visible`:
|
|
40
|
-
*
|
|
39
|
+
* - `visible`:
|
|
40
|
+
* The visible region of user browser window.
|
|
41
|
+
* Use `clientHeight` for check.
|
|
42
|
+
* If `visible` region not satisfy, fallback to `scroll`.
|
|
43
|
+
* - `scroll`:
|
|
44
|
+
* The whole region of the html scroll area.
|
|
45
|
+
* Use `scrollHeight` for check.
|
|
46
|
+
* - `visibleFirst`:
|
|
47
|
+
* Similar to `visible`, but if `visible` region not satisfy, fallback to `scroll`.
|
|
41
48
|
*/
|
|
42
|
-
htmlRegion?: 'visible' | 'scroll';
|
|
49
|
+
htmlRegion?: 'visible' | 'scroll' | 'visibleFirst';
|
|
43
50
|
/**
|
|
44
51
|
* Whether use css right instead of left to position
|
|
45
52
|
*/
|
package/lib/hooks/useAlign.js
CHANGED
|
@@ -160,20 +160,32 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
160
160
|
var targetWidth = targetRect.width;
|
|
161
161
|
|
|
162
162
|
// Get bounding of visible area
|
|
163
|
-
var
|
|
164
|
-
// Scroll region should take scrollLeft & scrollTop into account
|
|
165
|
-
{
|
|
166
|
-
left: -scrollLeft,
|
|
167
|
-
top: -scrollTop,
|
|
168
|
-
right: scrollWidth - scrollLeft,
|
|
169
|
-
bottom: scrollHeight - scrollTop
|
|
170
|
-
} : {
|
|
163
|
+
var visibleRegion = {
|
|
171
164
|
left: 0,
|
|
172
165
|
top: 0,
|
|
173
166
|
right: clientWidth,
|
|
174
167
|
bottom: clientHeight
|
|
175
168
|
};
|
|
176
|
-
|
|
169
|
+
var scrollRegion = {
|
|
170
|
+
left: -scrollLeft,
|
|
171
|
+
top: -scrollTop,
|
|
172
|
+
right: scrollWidth - scrollLeft,
|
|
173
|
+
bottom: scrollHeight - scrollTop
|
|
174
|
+
};
|
|
175
|
+
var htmlRegion = placementInfo.htmlRegion;
|
|
176
|
+
var VISIBLE = 'visible';
|
|
177
|
+
var VISIBLE_FIRST = 'visibleFirst';
|
|
178
|
+
if (htmlRegion !== 'scroll' && htmlRegion !== VISIBLE_FIRST) {
|
|
179
|
+
htmlRegion = VISIBLE;
|
|
180
|
+
}
|
|
181
|
+
var isVisibleFirst = htmlRegion === VISIBLE_FIRST;
|
|
182
|
+
var scrollRegionArea = (0, _util.getVisibleArea)(scrollRegion, scrollerList);
|
|
183
|
+
var visibleRegionArea = (0, _util.getVisibleArea)(visibleRegion, scrollerList);
|
|
184
|
+
var visibleArea = htmlRegion === VISIBLE ? visibleRegionArea : scrollRegionArea;
|
|
185
|
+
|
|
186
|
+
// When set to `visibleFirst`,
|
|
187
|
+
// the check `adjust` logic will use `visibleRegion` for check first.
|
|
188
|
+
var adjustCheckVisibleArea = isVisibleFirst ? visibleRegionArea : visibleArea;
|
|
177
189
|
|
|
178
190
|
// Reset back
|
|
179
191
|
popupElement.style.left = originLeft;
|
|
@@ -222,18 +234,22 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
222
234
|
// ============== Intersection ===============
|
|
223
235
|
// Get area by position. Used for check if flip area is better
|
|
224
236
|
function getIntersectionVisibleArea(offsetX, offsetY) {
|
|
237
|
+
var area = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : visibleArea;
|
|
225
238
|
var l = popupRect.x + offsetX;
|
|
226
239
|
var t = popupRect.y + offsetY;
|
|
227
240
|
var r = l + popupWidth;
|
|
228
241
|
var b = t + popupHeight;
|
|
229
|
-
var visibleL = Math.max(l,
|
|
230
|
-
var visibleT = Math.max(t,
|
|
231
|
-
var visibleR = Math.min(r,
|
|
232
|
-
var visibleB = Math.min(b,
|
|
242
|
+
var visibleL = Math.max(l, area.left);
|
|
243
|
+
var visibleT = Math.max(t, area.top);
|
|
244
|
+
var visibleR = Math.min(r, area.right);
|
|
245
|
+
var visibleB = Math.min(b, area.bottom);
|
|
233
246
|
return Math.max(0, (visibleR - visibleL) * (visibleB - visibleT));
|
|
234
247
|
}
|
|
235
248
|
var originIntersectionVisibleArea = getIntersectionVisibleArea(nextOffsetX, nextOffsetY);
|
|
236
249
|
|
|
250
|
+
// As `visibleFirst`, we prepare this for check
|
|
251
|
+
var originIntersectionRecommendArea = getIntersectionVisibleArea(nextOffsetX, nextOffsetY, visibleRegionArea);
|
|
252
|
+
|
|
237
253
|
// ========================== Overflow ===========================
|
|
238
254
|
var targetAlignPointTL = getAlignPoint(targetRect, ['t', 'l']);
|
|
239
255
|
var popupAlignPointTL = getAlignPoint(popupRect, ['t', 'l']);
|
|
@@ -269,14 +285,20 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
269
285
|
var sameTB = popupPoints[0] === targetPoints[0];
|
|
270
286
|
|
|
271
287
|
// Bottom to Top
|
|
272
|
-
if (needAdjustY && popupPoints[0] === 't' && (nextPopupBottom >
|
|
288
|
+
if (needAdjustY && popupPoints[0] === 't' && (nextPopupBottom > adjustCheckVisibleArea.bottom || prevFlipRef.current.bt)) {
|
|
273
289
|
var tmpNextOffsetY = nextOffsetY;
|
|
274
290
|
if (sameTB) {
|
|
275
291
|
tmpNextOffsetY -= popupHeight - targetHeight;
|
|
276
292
|
} else {
|
|
277
293
|
tmpNextOffsetY = targetAlignPointTL.y - popupAlignPointBR.y - popupOffsetY;
|
|
278
294
|
}
|
|
279
|
-
|
|
295
|
+
var newVisibleArea = getIntersectionVisibleArea(nextOffsetX, tmpNextOffsetY);
|
|
296
|
+
var newVisibleRecommendArea = getIntersectionVisibleArea(nextOffsetX, tmpNextOffsetY, visibleRegionArea);
|
|
297
|
+
if (
|
|
298
|
+
// Of course use larger one
|
|
299
|
+
newVisibleArea > originIntersectionVisibleArea || newVisibleArea === originIntersectionVisibleArea && (!isVisibleFirst ||
|
|
300
|
+
// Choose recommend one
|
|
301
|
+
newVisibleRecommendArea >= originIntersectionRecommendArea)) {
|
|
280
302
|
prevFlipRef.current.bt = true;
|
|
281
303
|
nextOffsetY = tmpNextOffsetY;
|
|
282
304
|
nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
|
|
@@ -286,14 +308,20 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
286
308
|
}
|
|
287
309
|
|
|
288
310
|
// Top to Bottom
|
|
289
|
-
if (needAdjustY && popupPoints[0] === 'b' && (nextPopupY <
|
|
311
|
+
if (needAdjustY && popupPoints[0] === 'b' && (nextPopupY < adjustCheckVisibleArea.top || prevFlipRef.current.tb)) {
|
|
290
312
|
var _tmpNextOffsetY = nextOffsetY;
|
|
291
313
|
if (sameTB) {
|
|
292
314
|
_tmpNextOffsetY += popupHeight - targetHeight;
|
|
293
315
|
} else {
|
|
294
316
|
_tmpNextOffsetY = targetAlignPointBR.y - popupAlignPointTL.y - popupOffsetY;
|
|
295
317
|
}
|
|
296
|
-
|
|
318
|
+
var _newVisibleArea = getIntersectionVisibleArea(nextOffsetX, _tmpNextOffsetY);
|
|
319
|
+
var _newVisibleRecommendArea = getIntersectionVisibleArea(nextOffsetX, _tmpNextOffsetY, visibleRegionArea);
|
|
320
|
+
if (
|
|
321
|
+
// Of course use larger one
|
|
322
|
+
_newVisibleArea > originIntersectionVisibleArea || _newVisibleArea === originIntersectionVisibleArea && (!isVisibleFirst ||
|
|
323
|
+
// Choose recommend one
|
|
324
|
+
_newVisibleRecommendArea >= originIntersectionRecommendArea)) {
|
|
297
325
|
prevFlipRef.current.tb = true;
|
|
298
326
|
nextOffsetY = _tmpNextOffsetY;
|
|
299
327
|
nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
|
|
@@ -309,14 +337,20 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
309
337
|
var sameLR = popupPoints[1] === targetPoints[1];
|
|
310
338
|
|
|
311
339
|
// Right to Left
|
|
312
|
-
if (needAdjustX && popupPoints[1] === 'l' && (nextPopupRight >
|
|
340
|
+
if (needAdjustX && popupPoints[1] === 'l' && (nextPopupRight > adjustCheckVisibleArea.right || prevFlipRef.current.rl)) {
|
|
313
341
|
var tmpNextOffsetX = nextOffsetX;
|
|
314
342
|
if (sameLR) {
|
|
315
343
|
tmpNextOffsetX -= popupWidth - targetWidth;
|
|
316
344
|
} else {
|
|
317
345
|
tmpNextOffsetX = targetAlignPointTL.x - popupAlignPointBR.x - popupOffsetX;
|
|
318
346
|
}
|
|
319
|
-
|
|
347
|
+
var _newVisibleArea2 = getIntersectionVisibleArea(tmpNextOffsetX, nextOffsetY);
|
|
348
|
+
var _newVisibleRecommendArea2 = getIntersectionVisibleArea(tmpNextOffsetX, nextOffsetY, visibleRegionArea);
|
|
349
|
+
if (
|
|
350
|
+
// Of course use larger one
|
|
351
|
+
_newVisibleArea2 > originIntersectionVisibleArea || _newVisibleArea2 === originIntersectionVisibleArea && (!isVisibleFirst ||
|
|
352
|
+
// Choose recommend one
|
|
353
|
+
_newVisibleRecommendArea2 >= originIntersectionRecommendArea)) {
|
|
320
354
|
prevFlipRef.current.rl = true;
|
|
321
355
|
nextOffsetX = tmpNextOffsetX;
|
|
322
356
|
nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
|
|
@@ -326,14 +360,20 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
326
360
|
}
|
|
327
361
|
|
|
328
362
|
// Left to Right
|
|
329
|
-
if (needAdjustX && popupPoints[1] === 'r' && (nextPopupX <
|
|
363
|
+
if (needAdjustX && popupPoints[1] === 'r' && (nextPopupX < adjustCheckVisibleArea.left || prevFlipRef.current.lr)) {
|
|
330
364
|
var _tmpNextOffsetX = nextOffsetX;
|
|
331
365
|
if (sameLR) {
|
|
332
366
|
_tmpNextOffsetX += popupWidth - targetWidth;
|
|
333
367
|
} else {
|
|
334
368
|
_tmpNextOffsetX = targetAlignPointBR.x - popupAlignPointTL.x - popupOffsetX;
|
|
335
369
|
}
|
|
336
|
-
|
|
370
|
+
var _newVisibleArea3 = getIntersectionVisibleArea(_tmpNextOffsetX, nextOffsetY);
|
|
371
|
+
var _newVisibleRecommendArea3 = getIntersectionVisibleArea(_tmpNextOffsetX, nextOffsetY, visibleRegionArea);
|
|
372
|
+
if (
|
|
373
|
+
// Of course use larger one
|
|
374
|
+
_newVisibleArea3 > originIntersectionVisibleArea || _newVisibleArea3 === originIntersectionVisibleArea && (!isVisibleFirst ||
|
|
375
|
+
// Choose recommend one
|
|
376
|
+
_newVisibleRecommendArea3 >= originIntersectionRecommendArea)) {
|
|
337
377
|
prevFlipRef.current.lr = true;
|
|
338
378
|
nextOffsetX = _tmpNextOffsetX;
|
|
339
379
|
nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
|
package/lib/index.js
CHANGED
|
@@ -232,7 +232,7 @@ function generateTrigger() {
|
|
|
232
232
|
(0, _useWatch.default)(mergedOpen, targetEle, popupEle, triggerAlign);
|
|
233
233
|
(0, _useLayoutEffect.default)(function () {
|
|
234
234
|
triggerAlign();
|
|
235
|
-
}, [mousePos]);
|
|
235
|
+
}, [mousePos, popupPlacement]);
|
|
236
236
|
|
|
237
237
|
// When no builtinPlacements and popupAlign changed
|
|
238
238
|
(0, _useLayoutEffect.default)(function () {
|
package/lib/interface.d.ts
CHANGED
|
@@ -36,10 +36,17 @@ export interface AlignType {
|
|
|
36
36
|
autoArrow?: boolean;
|
|
37
37
|
/**
|
|
38
38
|
* Config visible region check of html node. Default `visible`:
|
|
39
|
-
* - `visible`:
|
|
40
|
-
*
|
|
39
|
+
* - `visible`:
|
|
40
|
+
* The visible region of user browser window.
|
|
41
|
+
* Use `clientHeight` for check.
|
|
42
|
+
* If `visible` region not satisfy, fallback to `scroll`.
|
|
43
|
+
* - `scroll`:
|
|
44
|
+
* The whole region of the html scroll area.
|
|
45
|
+
* Use `scrollHeight` for check.
|
|
46
|
+
* - `visibleFirst`:
|
|
47
|
+
* Similar to `visible`, but if `visible` region not satisfy, fallback to `scroll`.
|
|
41
48
|
*/
|
|
42
|
-
htmlRegion?: 'visible' | 'scroll';
|
|
49
|
+
htmlRegion?: 'visible' | 'scroll' | 'visibleFirst';
|
|
43
50
|
/**
|
|
44
51
|
* Whether use css right instead of left to position
|
|
45
52
|
*/
|