@rc-component/trigger 1.5.8 → 1.6.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,4 +1,4 @@
1
1
  import type { ActionType } from '../interface';
2
2
  declare type ActionTypes = ActionType | ActionType[];
3
- export default function useAction(action: ActionTypes, showAction?: ActionTypes, hideAction?: ActionTypes): [showAction: Set<ActionType>, hideAction: Set<ActionType>];
3
+ export default function useAction(mobile: boolean, action: ActionTypes, showAction?: ActionTypes, hideAction?: ActionTypes): [showAction: Set<ActionType>, hideAction: Set<ActionType>];
4
4
  export {};
@@ -1,8 +1,23 @@
1
+ import * as React from 'react';
1
2
  function toArray(val) {
2
3
  return val ? Array.isArray(val) ? val : [val] : [];
3
4
  }
4
- export default function useAction(action, showAction, hideAction) {
5
- var mergedShowAction = toArray(showAction !== null && showAction !== void 0 ? showAction : action);
6
- var mergedHideAction = toArray(hideAction !== null && hideAction !== void 0 ? hideAction : action);
7
- return [new Set(mergedShowAction), new Set(mergedHideAction)];
5
+ export default function useAction(mobile, action, showAction, hideAction) {
6
+ return React.useMemo(function () {
7
+ var mergedShowAction = toArray(showAction !== null && showAction !== void 0 ? showAction : action);
8
+ var mergedHideAction = toArray(hideAction !== null && hideAction !== void 0 ? hideAction : action);
9
+ var showActionSet = new Set(mergedShowAction);
10
+ var hideActionSet = new Set(mergedHideAction);
11
+ if (mobile) {
12
+ if (showActionSet.has('hover')) {
13
+ showActionSet.delete('hover');
14
+ showActionSet.add('click');
15
+ }
16
+ if (hideActionSet.has('hover')) {
17
+ hideActionSet.delete('hover');
18
+ hideActionSet.add('click');
19
+ }
20
+ }
21
+ return [showActionSet, hideActionSet];
22
+ }, [mobile, action, showAction, hideAction]);
8
23
  }
@@ -210,6 +210,19 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
210
210
  var nextOffsetX = targetAlignPoint.x - popupAlignPoint.x + popupOffsetX;
211
211
  var nextOffsetY = targetAlignPoint.y - popupAlignPoint.y + popupOffsetY;
212
212
 
213
+ // ============== Intersection ===============
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);
220
+ var visibleR = Math.min(r, visibleArea.right);
221
+ var visibleB = Math.min(b, visibleArea.bottom);
222
+ return (visibleR - visibleX) * (visibleB - visibleY);
223
+ }
224
+ var originIntersectionVisibleArea = getIntersectionVisibleArea(nextOffsetX, nextOffsetY);
225
+
213
226
  // ================ Overflow =================
214
227
  var targetAlignPointTL = getAlignPoint(targetRect, ['t', 'l']);
215
228
  var popupAlignPointTL = getAlignPoint(popupRect, ['t', 'l']);
@@ -235,22 +248,30 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
235
248
 
236
249
  // Bottom to Top
237
250
  if (needAdjustY && popupPoints[0] === 't' && nextPopupBottom > visibleArea.bottom) {
251
+ var tmpNextOffsetY;
238
252
  if (sameTB) {
239
- nextOffsetY -= popupHeight - targetHeight;
253
+ tmpNextOffsetY -= popupHeight - targetHeight;
240
254
  } else {
241
- nextOffsetY = targetAlignPointTL.y - popupAlignPointBR.y - popupOffsetY;
255
+ tmpNextOffsetY = targetAlignPointTL.y - popupAlignPointBR.y - popupOffsetY;
256
+ }
257
+ if (getIntersectionVisibleArea(nextOffsetX, tmpNextOffsetY) > originIntersectionVisibleArea) {
258
+ nextOffsetY = tmpNextOffsetY;
259
+ nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
242
260
  }
243
- nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
244
261
  }
245
262
 
246
263
  // Top to Bottom
247
264
  if (needAdjustY && popupPoints[0] === 'b' && nextPopupY < visibleArea.top) {
265
+ var _tmpNextOffsetY;
248
266
  if (sameTB) {
249
- nextOffsetY += popupHeight - targetHeight;
267
+ _tmpNextOffsetY += popupHeight - targetHeight;
250
268
  } else {
251
- nextOffsetY = targetAlignPointBR.y - popupAlignPointTL.y - popupOffsetY;
269
+ _tmpNextOffsetY = targetAlignPointBR.y - popupAlignPointTL.y - popupOffsetY;
270
+ }
271
+ if (getIntersectionVisibleArea(nextOffsetX, _tmpNextOffsetY) > originIntersectionVisibleArea) {
272
+ nextOffsetY = _tmpNextOffsetY;
273
+ nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
252
274
  }
253
- nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
254
275
  }
255
276
 
256
277
  // >>>>>>>>>> Left & Right
@@ -263,22 +284,30 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
263
284
 
264
285
  // Right to Left
265
286
  if (needAdjustX && popupPoints[1] === 'l' && nextPopupRight > visibleArea.right) {
287
+ var tmpNextOffsetX;
266
288
  if (sameLR) {
267
- nextOffsetX -= popupWidth - targetWidth;
289
+ tmpNextOffsetX -= popupWidth - targetWidth;
268
290
  } else {
269
- nextOffsetX = targetAlignPointTL.x - popupAlignPointBR.x - popupOffsetX;
291
+ tmpNextOffsetX = targetAlignPointTL.x - popupAlignPointBR.x - popupOffsetX;
292
+ }
293
+ if (getIntersectionVisibleArea(tmpNextOffsetX, nextOffsetY) > originIntersectionVisibleArea) {
294
+ nextOffsetX = tmpNextOffsetX;
295
+ nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
270
296
  }
271
- nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
272
297
  }
273
298
 
274
299
  // Left to Right
275
300
  if (needAdjustX && popupPoints[1] === 'r' && nextPopupX < visibleArea.left) {
301
+ var _tmpNextOffsetX;
276
302
  if (sameLR) {
277
- nextOffsetX += popupWidth - targetWidth;
303
+ _tmpNextOffsetX += popupWidth - targetWidth;
278
304
  } else {
279
- nextOffsetX = targetAlignPointBR.x - popupAlignPointTL.x - popupOffsetX;
305
+ _tmpNextOffsetX = targetAlignPointBR.x - popupAlignPointTL.x - popupOffsetX;
306
+ }
307
+ if (getIntersectionVisibleArea(_tmpNextOffsetX, nextOffsetY) > originIntersectionVisibleArea) {
308
+ nextOffsetX = _tmpNextOffsetX;
309
+ nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
280
310
  }
281
- nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
282
311
  }
283
312
 
284
313
  // >>>>> Shift
package/es/index.js CHANGED
@@ -9,6 +9,7 @@ import { isDOM } from "rc-util/es/Dom/findDOMNode";
9
9
  import useEvent from "rc-util/es/hooks/useEvent";
10
10
  import useId from "rc-util/es/hooks/useId";
11
11
  import useLayoutEffect from "rc-util/es/hooks/useLayoutEffect";
12
+ import isMobile from "rc-util/es/isMobile";
12
13
  import * as React from 'react';
13
14
  import TriggerContext from "./context";
14
15
  import useAction from "./hooks/useAction";
@@ -68,6 +69,15 @@ export function generateTrigger() {
68
69
  restProps = _objectWithoutProperties(props, _excluded);
69
70
  var mergedAutoDestroy = autoDestroy || destroyPopupOnHide || false;
70
71
 
72
+ // =========================== Mobile ===========================
73
+ var _React$useState = React.useState(false),
74
+ _React$useState2 = _slicedToArray(_React$useState, 2),
75
+ mobile = _React$useState2[0],
76
+ setMobile = _React$useState2[1];
77
+ useLayoutEffect(function () {
78
+ setMobile(isMobile());
79
+ }, []);
80
+
71
81
  // ========================== Context ===========================
72
82
  var subPopupElements = React.useRef({});
73
83
  var parentContext = React.useContext(TriggerContext);
@@ -82,10 +92,10 @@ export function generateTrigger() {
82
92
 
83
93
  // =========================== Popup ============================
84
94
  var id = useId();
85
- var _React$useState = React.useState(null),
86
- _React$useState2 = _slicedToArray(_React$useState, 2),
87
- popupEle = _React$useState2[0],
88
- setPopupEle = _React$useState2[1];
95
+ var _React$useState3 = React.useState(null),
96
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
97
+ popupEle = _React$useState4[0],
98
+ setPopupEle = _React$useState4[1];
89
99
  var setPopupRef = useEvent(function (node) {
90
100
  if (isDOM(node) && popupEle !== node) {
91
101
  setPopupEle(node);
@@ -95,10 +105,10 @@ export function generateTrigger() {
95
105
 
96
106
  // =========================== Target ===========================
97
107
  // Use state to control here since `useRef` update not trigger render
98
- var _React$useState3 = React.useState(null),
99
- _React$useState4 = _slicedToArray(_React$useState3, 2),
100
- targetEle = _React$useState4[0],
101
- setTargetEle = _React$useState4[1];
108
+ var _React$useState5 = React.useState(null),
109
+ _React$useState6 = _slicedToArray(_React$useState5, 2),
110
+ targetEle = _React$useState6[0],
111
+ setTargetEle = _React$useState6[1];
102
112
  var setTargetRef = useEvent(function (node) {
103
113
  if (isDOM(node) && targetEle !== node) {
104
114
  setTargetEle(node);
@@ -121,10 +131,10 @@ export function generateTrigger() {
121
131
  var mergeMaskMotion = getMotion(prefixCls, maskMotion, maskAnimation, maskTransitionName);
122
132
 
123
133
  // ============================ Open ============================
124
- var _React$useState5 = React.useState(defaultPopupVisible || false),
125
- _React$useState6 = _slicedToArray(_React$useState5, 2),
126
- internalOpen = _React$useState6[0],
127
- setInternalOpen = _React$useState6[1];
134
+ var _React$useState7 = React.useState(defaultPopupVisible || false),
135
+ _React$useState8 = _slicedToArray(_React$useState7, 2),
136
+ internalOpen = _React$useState8[0],
137
+ setInternalOpen = _React$useState8[1];
128
138
 
129
139
  // Render still use props as first priority
130
140
  var mergedOpen = popupVisible !== null && popupVisible !== void 0 ? popupVisible : internalOpen;
@@ -168,10 +178,10 @@ export function generateTrigger() {
168
178
  }, []);
169
179
 
170
180
  // ========================== Motion ============================
171
- var _React$useState7 = React.useState(false),
172
- _React$useState8 = _slicedToArray(_React$useState7, 2),
173
- inMotion = _React$useState8[0],
174
- setInMotion = _React$useState8[1];
181
+ var _React$useState9 = React.useState(false),
182
+ _React$useState10 = _slicedToArray(_React$useState9, 2),
183
+ inMotion = _React$useState10[0],
184
+ setInMotion = _React$useState10[1];
175
185
  var mountRef = React.useRef(true);
176
186
  useLayoutEffect(function () {
177
187
  if (!mountRef.current || mergedOpen) {
@@ -179,16 +189,16 @@ export function generateTrigger() {
179
189
  }
180
190
  mountRef.current = true;
181
191
  }, [mergedOpen]);
182
- var _React$useState9 = React.useState(null),
183
- _React$useState10 = _slicedToArray(_React$useState9, 2),
184
- motionPrepareResolve = _React$useState10[0],
185
- setMotionPrepareResolve = _React$useState10[1];
192
+ var _React$useState11 = React.useState(null),
193
+ _React$useState12 = _slicedToArray(_React$useState11, 2),
194
+ motionPrepareResolve = _React$useState12[0],
195
+ setMotionPrepareResolve = _React$useState12[1];
186
196
 
187
197
  // =========================== Align ============================
188
- var _React$useState11 = React.useState([0, 0]),
189
- _React$useState12 = _slicedToArray(_React$useState11, 2),
190
- mousePos = _React$useState12[0],
191
- setMousePos = _React$useState12[1];
198
+ var _React$useState13 = React.useState([0, 0]),
199
+ _React$useState14 = _slicedToArray(_React$useState13, 2),
200
+ mousePos = _React$useState14[0],
201
+ setMousePos = _React$useState14[1];
192
202
  var setMousePosByEvent = function setMousePosByEvent(event) {
193
203
  setMousePos([event.clientX, event.clientY]);
194
204
  };
@@ -253,14 +263,14 @@ export function generateTrigger() {
253
263
  }, [motionPrepareResolve]);
254
264
 
255
265
  // ========================== Stretch ===========================
256
- var _React$useState13 = React.useState(0),
257
- _React$useState14 = _slicedToArray(_React$useState13, 2),
258
- targetWidth = _React$useState14[0],
259
- setTargetWidth = _React$useState14[1];
260
266
  var _React$useState15 = React.useState(0),
261
267
  _React$useState16 = _slicedToArray(_React$useState15, 2),
262
- targetHeight = _React$useState16[0],
263
- setTargetHeight = _React$useState16[1];
268
+ targetWidth = _React$useState16[0],
269
+ setTargetWidth = _React$useState16[1];
270
+ var _React$useState17 = React.useState(0),
271
+ _React$useState18 = _slicedToArray(_React$useState17, 2),
272
+ targetHeight = _React$useState18[0],
273
+ setTargetHeight = _React$useState18[1];
264
274
  var onTargetResize = function onTargetResize(_, ele) {
265
275
  triggerAlign();
266
276
  if (stretch) {
@@ -271,7 +281,7 @@ export function generateTrigger() {
271
281
  };
272
282
 
273
283
  // =========================== Action ===========================
274
- var _useAction = useAction(action, showAction, hideAction),
284
+ var _useAction = useAction(mobile, action, showAction, hideAction),
275
285
  _useAction2 = _slicedToArray(_useAction, 2),
276
286
  showActions = _useAction2[0],
277
287
  hideActions = _useAction2[1];
@@ -1,4 +1,4 @@
1
1
  import type { ActionType } from '../interface';
2
2
  declare type ActionTypes = ActionType | ActionType[];
3
- export default function useAction(action: ActionTypes, showAction?: ActionTypes, hideAction?: ActionTypes): [showAction: Set<ActionType>, hideAction: Set<ActionType>];
3
+ export default function useAction(mobile: boolean, action: ActionTypes, showAction?: ActionTypes, hideAction?: ActionTypes): [showAction: Set<ActionType>, hideAction: Set<ActionType>];
4
4
  export {};
@@ -1,14 +1,30 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.default = useAction;
8
+ var React = _interopRequireWildcard(require("react"));
7
9
  function toArray(val) {
8
10
  return val ? Array.isArray(val) ? val : [val] : [];
9
11
  }
10
- function useAction(action, showAction, hideAction) {
11
- var mergedShowAction = toArray(showAction !== null && showAction !== void 0 ? showAction : action);
12
- var mergedHideAction = toArray(hideAction !== null && hideAction !== void 0 ? hideAction : action);
13
- return [new Set(mergedShowAction), new Set(mergedHideAction)];
12
+ function useAction(mobile, action, showAction, hideAction) {
13
+ return React.useMemo(function () {
14
+ var mergedShowAction = toArray(showAction !== null && showAction !== void 0 ? showAction : action);
15
+ var mergedHideAction = toArray(hideAction !== null && hideAction !== void 0 ? hideAction : action);
16
+ var showActionSet = new Set(mergedShowAction);
17
+ var hideActionSet = new Set(mergedHideAction);
18
+ if (mobile) {
19
+ if (showActionSet.has('hover')) {
20
+ showActionSet.delete('hover');
21
+ showActionSet.add('click');
22
+ }
23
+ if (hideActionSet.has('hover')) {
24
+ hideActionSet.delete('hover');
25
+ hideActionSet.add('click');
26
+ }
27
+ }
28
+ return [showActionSet, hideActionSet];
29
+ }, [mobile, action, showAction, hideAction]);
14
30
  }
@@ -218,6 +218,19 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
218
218
  var nextOffsetX = targetAlignPoint.x - popupAlignPoint.x + popupOffsetX;
219
219
  var nextOffsetY = targetAlignPoint.y - popupAlignPoint.y + popupOffsetY;
220
220
 
221
+ // ============== Intersection ===============
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);
228
+ var visibleR = Math.min(r, visibleArea.right);
229
+ var visibleB = Math.min(b, visibleArea.bottom);
230
+ return (visibleR - visibleX) * (visibleB - visibleY);
231
+ }
232
+ var originIntersectionVisibleArea = getIntersectionVisibleArea(nextOffsetX, nextOffsetY);
233
+
221
234
  // ================ Overflow =================
222
235
  var targetAlignPointTL = getAlignPoint(targetRect, ['t', 'l']);
223
236
  var popupAlignPointTL = getAlignPoint(popupRect, ['t', 'l']);
@@ -243,22 +256,30 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
243
256
 
244
257
  // Bottom to Top
245
258
  if (needAdjustY && popupPoints[0] === 't' && nextPopupBottom > visibleArea.bottom) {
259
+ var tmpNextOffsetY;
246
260
  if (sameTB) {
247
- nextOffsetY -= popupHeight - targetHeight;
261
+ tmpNextOffsetY -= popupHeight - targetHeight;
248
262
  } else {
249
- nextOffsetY = targetAlignPointTL.y - popupAlignPointBR.y - popupOffsetY;
263
+ tmpNextOffsetY = targetAlignPointTL.y - popupAlignPointBR.y - popupOffsetY;
264
+ }
265
+ if (getIntersectionVisibleArea(nextOffsetX, tmpNextOffsetY) > originIntersectionVisibleArea) {
266
+ nextOffsetY = tmpNextOffsetY;
267
+ nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
250
268
  }
251
- nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
252
269
  }
253
270
 
254
271
  // Top to Bottom
255
272
  if (needAdjustY && popupPoints[0] === 'b' && nextPopupY < visibleArea.top) {
273
+ var _tmpNextOffsetY;
256
274
  if (sameTB) {
257
- nextOffsetY += popupHeight - targetHeight;
275
+ _tmpNextOffsetY += popupHeight - targetHeight;
258
276
  } else {
259
- nextOffsetY = targetAlignPointBR.y - popupAlignPointTL.y - popupOffsetY;
277
+ _tmpNextOffsetY = targetAlignPointBR.y - popupAlignPointTL.y - popupOffsetY;
278
+ }
279
+ if (getIntersectionVisibleArea(nextOffsetX, _tmpNextOffsetY) > originIntersectionVisibleArea) {
280
+ nextOffsetY = _tmpNextOffsetY;
281
+ nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
260
282
  }
261
- nextAlignInfo.points = [reversePoints(popupPoints, 0), reversePoints(targetPoints, 0)];
262
283
  }
263
284
 
264
285
  // >>>>>>>>>> Left & Right
@@ -271,22 +292,30 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
271
292
 
272
293
  // Right to Left
273
294
  if (needAdjustX && popupPoints[1] === 'l' && nextPopupRight > visibleArea.right) {
295
+ var tmpNextOffsetX;
274
296
  if (sameLR) {
275
- nextOffsetX -= popupWidth - targetWidth;
297
+ tmpNextOffsetX -= popupWidth - targetWidth;
276
298
  } else {
277
- nextOffsetX = targetAlignPointTL.x - popupAlignPointBR.x - popupOffsetX;
299
+ tmpNextOffsetX = targetAlignPointTL.x - popupAlignPointBR.x - popupOffsetX;
300
+ }
301
+ if (getIntersectionVisibleArea(tmpNextOffsetX, nextOffsetY) > originIntersectionVisibleArea) {
302
+ nextOffsetX = tmpNextOffsetX;
303
+ nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
278
304
  }
279
- nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
280
305
  }
281
306
 
282
307
  // Left to Right
283
308
  if (needAdjustX && popupPoints[1] === 'r' && nextPopupX < visibleArea.left) {
309
+ var _tmpNextOffsetX;
284
310
  if (sameLR) {
285
- nextOffsetX += popupWidth - targetWidth;
311
+ _tmpNextOffsetX += popupWidth - targetWidth;
286
312
  } else {
287
- nextOffsetX = targetAlignPointBR.x - popupAlignPointTL.x - popupOffsetX;
313
+ _tmpNextOffsetX = targetAlignPointBR.x - popupAlignPointTL.x - popupOffsetX;
314
+ }
315
+ if (getIntersectionVisibleArea(_tmpNextOffsetX, nextOffsetY) > originIntersectionVisibleArea) {
316
+ nextOffsetX = _tmpNextOffsetX;
317
+ nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
288
318
  }
289
- nextAlignInfo.points = [reversePoints(popupPoints, 1), reversePoints(targetPoints, 1)];
290
319
  }
291
320
 
292
321
  // >>>>> Shift
package/lib/index.js CHANGED
@@ -17,6 +17,7 @@ var _findDOMNode = require("rc-util/lib/Dom/findDOMNode");
17
17
  var _useEvent = _interopRequireDefault(require("rc-util/lib/hooks/useEvent"));
18
18
  var _useId = _interopRequireDefault(require("rc-util/lib/hooks/useId"));
19
19
  var _useLayoutEffect = _interopRequireDefault(require("rc-util/lib/hooks/useLayoutEffect"));
20
+ var _isMobile = _interopRequireDefault(require("rc-util/lib/isMobile"));
20
21
  var React = _interopRequireWildcard(require("react"));
21
22
  var _context = _interopRequireDefault(require("./context"));
22
23
  var _useAction3 = _interopRequireDefault(require("./hooks/useAction"));
@@ -77,6 +78,15 @@ function generateTrigger() {
77
78
  restProps = (0, _objectWithoutProperties2.default)(props, _excluded);
78
79
  var mergedAutoDestroy = autoDestroy || destroyPopupOnHide || false;
79
80
 
81
+ // =========================== Mobile ===========================
82
+ var _React$useState = React.useState(false),
83
+ _React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
84
+ mobile = _React$useState2[0],
85
+ setMobile = _React$useState2[1];
86
+ (0, _useLayoutEffect.default)(function () {
87
+ setMobile((0, _isMobile.default)());
88
+ }, []);
89
+
80
90
  // ========================== Context ===========================
81
91
  var subPopupElements = React.useRef({});
82
92
  var parentContext = React.useContext(_context.default);
@@ -91,10 +101,10 @@ function generateTrigger() {
91
101
 
92
102
  // =========================== Popup ============================
93
103
  var id = (0, _useId.default)();
94
- var _React$useState = React.useState(null),
95
- _React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
96
- popupEle = _React$useState2[0],
97
- setPopupEle = _React$useState2[1];
104
+ var _React$useState3 = React.useState(null),
105
+ _React$useState4 = (0, _slicedToArray2.default)(_React$useState3, 2),
106
+ popupEle = _React$useState4[0],
107
+ setPopupEle = _React$useState4[1];
98
108
  var setPopupRef = (0, _useEvent.default)(function (node) {
99
109
  if ((0, _findDOMNode.isDOM)(node) && popupEle !== node) {
100
110
  setPopupEle(node);
@@ -104,10 +114,10 @@ function generateTrigger() {
104
114
 
105
115
  // =========================== Target ===========================
106
116
  // Use state to control here since `useRef` update not trigger render
107
- var _React$useState3 = React.useState(null),
108
- _React$useState4 = (0, _slicedToArray2.default)(_React$useState3, 2),
109
- targetEle = _React$useState4[0],
110
- setTargetEle = _React$useState4[1];
117
+ var _React$useState5 = React.useState(null),
118
+ _React$useState6 = (0, _slicedToArray2.default)(_React$useState5, 2),
119
+ targetEle = _React$useState6[0],
120
+ setTargetEle = _React$useState6[1];
111
121
  var setTargetRef = (0, _useEvent.default)(function (node) {
112
122
  if ((0, _findDOMNode.isDOM)(node) && targetEle !== node) {
113
123
  setTargetEle(node);
@@ -130,10 +140,10 @@ function generateTrigger() {
130
140
  var mergeMaskMotion = (0, _util.getMotion)(prefixCls, maskMotion, maskAnimation, maskTransitionName);
131
141
 
132
142
  // ============================ Open ============================
133
- var _React$useState5 = React.useState(defaultPopupVisible || false),
134
- _React$useState6 = (0, _slicedToArray2.default)(_React$useState5, 2),
135
- internalOpen = _React$useState6[0],
136
- setInternalOpen = _React$useState6[1];
143
+ var _React$useState7 = React.useState(defaultPopupVisible || false),
144
+ _React$useState8 = (0, _slicedToArray2.default)(_React$useState7, 2),
145
+ internalOpen = _React$useState8[0],
146
+ setInternalOpen = _React$useState8[1];
137
147
 
138
148
  // Render still use props as first priority
139
149
  var mergedOpen = popupVisible !== null && popupVisible !== void 0 ? popupVisible : internalOpen;
@@ -177,10 +187,10 @@ function generateTrigger() {
177
187
  }, []);
178
188
 
179
189
  // ========================== Motion ============================
180
- var _React$useState7 = React.useState(false),
181
- _React$useState8 = (0, _slicedToArray2.default)(_React$useState7, 2),
182
- inMotion = _React$useState8[0],
183
- setInMotion = _React$useState8[1];
190
+ var _React$useState9 = React.useState(false),
191
+ _React$useState10 = (0, _slicedToArray2.default)(_React$useState9, 2),
192
+ inMotion = _React$useState10[0],
193
+ setInMotion = _React$useState10[1];
184
194
  var mountRef = React.useRef(true);
185
195
  (0, _useLayoutEffect.default)(function () {
186
196
  if (!mountRef.current || mergedOpen) {
@@ -188,16 +198,16 @@ function generateTrigger() {
188
198
  }
189
199
  mountRef.current = true;
190
200
  }, [mergedOpen]);
191
- var _React$useState9 = React.useState(null),
192
- _React$useState10 = (0, _slicedToArray2.default)(_React$useState9, 2),
193
- motionPrepareResolve = _React$useState10[0],
194
- setMotionPrepareResolve = _React$useState10[1];
201
+ var _React$useState11 = React.useState(null),
202
+ _React$useState12 = (0, _slicedToArray2.default)(_React$useState11, 2),
203
+ motionPrepareResolve = _React$useState12[0],
204
+ setMotionPrepareResolve = _React$useState12[1];
195
205
 
196
206
  // =========================== Align ============================
197
- var _React$useState11 = React.useState([0, 0]),
198
- _React$useState12 = (0, _slicedToArray2.default)(_React$useState11, 2),
199
- mousePos = _React$useState12[0],
200
- setMousePos = _React$useState12[1];
207
+ var _React$useState13 = React.useState([0, 0]),
208
+ _React$useState14 = (0, _slicedToArray2.default)(_React$useState13, 2),
209
+ mousePos = _React$useState14[0],
210
+ setMousePos = _React$useState14[1];
201
211
  var setMousePosByEvent = function setMousePosByEvent(event) {
202
212
  setMousePos([event.clientX, event.clientY]);
203
213
  };
@@ -262,14 +272,14 @@ function generateTrigger() {
262
272
  }, [motionPrepareResolve]);
263
273
 
264
274
  // ========================== Stretch ===========================
265
- var _React$useState13 = React.useState(0),
266
- _React$useState14 = (0, _slicedToArray2.default)(_React$useState13, 2),
267
- targetWidth = _React$useState14[0],
268
- setTargetWidth = _React$useState14[1];
269
275
  var _React$useState15 = React.useState(0),
270
276
  _React$useState16 = (0, _slicedToArray2.default)(_React$useState15, 2),
271
- targetHeight = _React$useState16[0],
272
- setTargetHeight = _React$useState16[1];
277
+ targetWidth = _React$useState16[0],
278
+ setTargetWidth = _React$useState16[1];
279
+ var _React$useState17 = React.useState(0),
280
+ _React$useState18 = (0, _slicedToArray2.default)(_React$useState17, 2),
281
+ targetHeight = _React$useState18[0],
282
+ setTargetHeight = _React$useState18[1];
273
283
  var onTargetResize = function onTargetResize(_, ele) {
274
284
  triggerAlign();
275
285
  if (stretch) {
@@ -280,7 +290,7 @@ function generateTrigger() {
280
290
  };
281
291
 
282
292
  // =========================== Action ===========================
283
- var _useAction = (0, _useAction3.default)(action, showAction, hideAction),
293
+ var _useAction = (0, _useAction3.default)(mobile, action, showAction, hideAction),
284
294
  _useAction2 = (0, _slicedToArray2.default)(_useAction, 2),
285
295
  showActions = _useAction2[0],
286
296
  hideActions = _useAction2[1];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/trigger",
3
- "version": "1.5.8",
3
+ "version": "1.6.0",
4
4
  "description": "base abstract trigger component for react",
5
5
  "engines": {
6
6
  "node": ">=8.x"