@rc-component/trigger 1.17.2 → 1.18.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.
- package/es/Popup/index.js +1 -1
- package/es/hooks/useAlign.js +3 -3
- package/es/hooks/useWinClick.js +1 -1
- package/es/index.d.ts +2 -1
- package/es/index.js +28 -18
- package/es/mock.js +1 -1
- package/lib/Popup/PopupContent.js +1 -2
- package/lib/Popup/index.js +2 -3
- package/lib/TriggerWrapper.js +1 -2
- package/lib/context.js +1 -2
- package/lib/hooks/useAlign.js +3 -3
- package/lib/hooks/useWinClick.js +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +29 -20
- package/lib/mock.js +2 -3
- package/package.json +1 -1
package/es/Popup/index.js
CHANGED
|
@@ -147,7 +147,7 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
147
147
|
visible: open,
|
|
148
148
|
onVisibleChanged: function onVisibleChanged(nextVisible) {
|
|
149
149
|
var _motion$onVisibleChan;
|
|
150
|
-
motion === null || motion === void 0
|
|
150
|
+
motion === null || motion === void 0 || (_motion$onVisibleChan = motion.onVisibleChanged) === null || _motion$onVisibleChan === void 0 || _motion$onVisibleChan.call(motion, nextVisible);
|
|
151
151
|
_onVisibleChanged(nextVisible);
|
|
152
152
|
}
|
|
153
153
|
}), function (_ref, motionRef) {
|
package/es/hooks/useAlign.js
CHANGED
|
@@ -124,7 +124,7 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
124
124
|
|
|
125
125
|
// placeholder element
|
|
126
126
|
var placeholderElement = doc.createElement('div');
|
|
127
|
-
(_popupElement$parentE = popupElement.parentElement) === null || _popupElement$parentE === void 0
|
|
127
|
+
(_popupElement$parentE = popupElement.parentElement) === null || _popupElement$parentE === void 0 || _popupElement$parentE.appendChild(placeholderElement);
|
|
128
128
|
placeholderElement.style.left = "".concat(popupElement.offsetLeft, "px");
|
|
129
129
|
placeholderElement.style.top = "".concat(popupElement.offsetTop, "px");
|
|
130
130
|
placeholderElement.style.position = popupPosition;
|
|
@@ -208,7 +208,7 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
208
208
|
popupElement.style.top = originTop;
|
|
209
209
|
popupElement.style.right = originRight;
|
|
210
210
|
popupElement.style.bottom = originBottom;
|
|
211
|
-
(_popupElement$parentE2 = popupElement.parentElement) === null || _popupElement$parentE2 === void 0
|
|
211
|
+
(_popupElement$parentE2 = popupElement.parentElement) === null || _popupElement$parentE2 === void 0 || _popupElement$parentE2.removeChild(placeholderElement);
|
|
212
212
|
|
|
213
213
|
// Calculate scale
|
|
214
214
|
var _scaleX = toNum(Math.round(popupWidth / parseFloat(width) * 1000) / 1000);
|
|
@@ -465,7 +465,7 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
465
465
|
var minBottom = Math.min(popupBottom, targetBottom);
|
|
466
466
|
var yCenter = (maxTop + minBottom) / 2;
|
|
467
467
|
var nextArrowY = yCenter - popupTop;
|
|
468
|
-
onPopupAlign === null || onPopupAlign === void 0
|
|
468
|
+
onPopupAlign === null || onPopupAlign === void 0 || onPopupAlign(popupEle, nextAlignInfo);
|
|
469
469
|
|
|
470
470
|
// Additional calculate right & bottom position
|
|
471
471
|
var offsetX4Right = popupMirrorRect.right - popupRect.x - (nextOffsetX + popupRect.width);
|
package/es/hooks/useWinClick.js
CHANGED
|
@@ -68,7 +68,7 @@ export default function useWinClick(open, clickToHide, targetEle, popupEle, mask
|
|
|
68
68
|
// Warning if target and popup not in same root
|
|
69
69
|
if (process.env.NODE_ENV !== 'production') {
|
|
70
70
|
var _targetEle$getRootNod, _popupEle$getRootNode;
|
|
71
|
-
var targetRoot = targetEle === null || targetEle === void 0
|
|
71
|
+
var targetRoot = targetEle === null || targetEle === void 0 || (_targetEle$getRootNod = targetEle.getRootNode) === null || _targetEle$getRootNod === void 0 ? void 0 : _targetEle$getRootNod.call(targetEle);
|
|
72
72
|
var popupRoot = (_popupEle$getRootNode = popupEle.getRootNode) === null || _popupEle$getRootNode === void 0 ? void 0 : _popupEle$getRootNode.call(popupEle);
|
|
73
73
|
warning(targetRoot === popupRoot, "trigger element and popup element should in same shadow root.");
|
|
74
74
|
}
|
package/es/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { CSSMotionProps } from 'rc-motion';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import type { ActionType, AlignType, AnimationType, ArrowTypeOuter, BuildInPlacements, TransitionNameType } from './interface';
|
|
4
|
-
export type {
|
|
4
|
+
export type { ActionType, AlignType, ArrowTypeOuter as ArrowType, BuildInPlacements, };
|
|
5
5
|
export interface TriggerRef {
|
|
6
|
+
nativeElement: HTMLElement;
|
|
6
7
|
forceAlign: VoidFunction;
|
|
7
8
|
}
|
|
8
9
|
export interface TriggerProps {
|
package/es/index.js
CHANGED
|
@@ -12,14 +12,13 @@ import useId from "rc-util/es/hooks/useId";
|
|
|
12
12
|
import useLayoutEffect from "rc-util/es/hooks/useLayoutEffect";
|
|
13
13
|
import isMobile from "rc-util/es/isMobile";
|
|
14
14
|
import * as React from 'react';
|
|
15
|
-
import
|
|
15
|
+
import Popup from "./Popup";
|
|
16
|
+
import TriggerWrapper from "./TriggerWrapper";
|
|
16
17
|
import TriggerContext from "./context";
|
|
17
18
|
import useAction from "./hooks/useAction";
|
|
18
19
|
import useAlign from "./hooks/useAlign";
|
|
19
20
|
import useWatch from "./hooks/useWatch";
|
|
20
21
|
import useWinClick from "./hooks/useWinClick";
|
|
21
|
-
import Popup from "./Popup";
|
|
22
|
-
import TriggerWrapper from "./TriggerWrapper";
|
|
23
22
|
import { getAlignPopupClassName, getMotion } from "./util";
|
|
24
23
|
|
|
25
24
|
// Removed Props List
|
|
@@ -94,7 +93,7 @@ export function generateTrigger() {
|
|
|
94
93
|
return {
|
|
95
94
|
registerSubPopup: function registerSubPopup(id, subPopupEle) {
|
|
96
95
|
subPopupElements.current[id] = subPopupEle;
|
|
97
|
-
parentContext === null || parentContext === void 0
|
|
96
|
+
parentContext === null || parentContext === void 0 || parentContext.registerSubPopup(id, subPopupEle);
|
|
98
97
|
}
|
|
99
98
|
};
|
|
100
99
|
}, [parentContext]);
|
|
@@ -109,7 +108,7 @@ export function generateTrigger() {
|
|
|
109
108
|
if (isDOM(node) && popupEle !== node) {
|
|
110
109
|
setPopupEle(node);
|
|
111
110
|
}
|
|
112
|
-
parentContext === null || parentContext === void 0
|
|
111
|
+
parentContext === null || parentContext === void 0 || parentContext.registerSubPopup(id, node);
|
|
113
112
|
});
|
|
114
113
|
|
|
115
114
|
// =========================== Target ===========================
|
|
@@ -118,9 +117,13 @@ export function generateTrigger() {
|
|
|
118
117
|
_React$useState6 = _slicedToArray(_React$useState5, 2),
|
|
119
118
|
targetEle = _React$useState6[0],
|
|
120
119
|
setTargetEle = _React$useState6[1];
|
|
120
|
+
|
|
121
|
+
// Used for forwardRef target. Not use internal
|
|
122
|
+
var externalForwardRef = React.useRef(null);
|
|
121
123
|
var setTargetRef = useEvent(function (node) {
|
|
122
124
|
if (isDOM(node) && targetEle !== node) {
|
|
123
125
|
setTargetEle(node);
|
|
126
|
+
externalForwardRef.current = node;
|
|
124
127
|
}
|
|
125
128
|
});
|
|
126
129
|
|
|
@@ -160,15 +163,19 @@ export function generateTrigger() {
|
|
|
160
163
|
}, [popupVisible]);
|
|
161
164
|
var openRef = React.useRef(mergedOpen);
|
|
162
165
|
openRef.current = mergedOpen;
|
|
166
|
+
var lastTriggerRef = React.useRef([]);
|
|
167
|
+
lastTriggerRef.current = [];
|
|
163
168
|
var internalTriggerOpen = useEvent(function (nextOpen) {
|
|
169
|
+
var _lastTriggerRef$curre;
|
|
170
|
+
setMergedOpen(nextOpen);
|
|
171
|
+
|
|
164
172
|
// Enter or Pointer will both trigger open state change
|
|
165
173
|
// We only need take one to avoid duplicated change event trigger
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
});
|
|
174
|
+
// Use `lastTriggerRef` to record last open type
|
|
175
|
+
if (((_lastTriggerRef$curre = lastTriggerRef.current[lastTriggerRef.current.length - 1]) !== null && _lastTriggerRef$curre !== void 0 ? _lastTriggerRef$curre : mergedOpen) !== nextOpen) {
|
|
176
|
+
lastTriggerRef.current.push(nextOpen);
|
|
177
|
+
onPopupVisibleChange === null || onPopupVisibleChange === void 0 || onPopupVisibleChange(nextOpen);
|
|
178
|
+
}
|
|
172
179
|
});
|
|
173
180
|
|
|
174
181
|
// Trigger for delay
|
|
@@ -258,8 +265,11 @@ export function generateTrigger() {
|
|
|
258
265
|
var baseClassName = getAlignPopupClassName(builtinPlacements, prefixCls, alignInfo, alignPoint);
|
|
259
266
|
return classNames(baseClassName, getPopupClassNameFromAlign === null || getPopupClassNameFromAlign === void 0 ? void 0 : getPopupClassNameFromAlign(alignInfo));
|
|
260
267
|
}, [alignInfo, getPopupClassNameFromAlign, builtinPlacements, prefixCls, alignPoint]);
|
|
268
|
+
|
|
269
|
+
// ============================ Refs ============================
|
|
261
270
|
React.useImperativeHandle(ref, function () {
|
|
262
271
|
return {
|
|
272
|
+
nativeElement: externalForwardRef.current,
|
|
263
273
|
forceAlign: triggerAlign
|
|
264
274
|
};
|
|
265
275
|
});
|
|
@@ -289,7 +299,7 @@ export function generateTrigger() {
|
|
|
289
299
|
var onVisibleChanged = function onVisibleChanged(visible) {
|
|
290
300
|
setInMotion(false);
|
|
291
301
|
onAlign();
|
|
292
|
-
afterPopupVisibleChange === null || afterPopupVisibleChange === void 0
|
|
302
|
+
afterPopupVisibleChange === null || afterPopupVisibleChange === void 0 || afterPopupVisibleChange(visible);
|
|
293
303
|
};
|
|
294
304
|
|
|
295
305
|
// We will trigger align when motion is in prepare
|
|
@@ -316,14 +326,14 @@ export function generateTrigger() {
|
|
|
316
326
|
function wrapperAction(eventName, nextOpen, delay, preEvent) {
|
|
317
327
|
cloneProps[eventName] = function (event) {
|
|
318
328
|
var _originChildProps$eve;
|
|
319
|
-
preEvent === null || preEvent === void 0
|
|
329
|
+
preEvent === null || preEvent === void 0 || preEvent(event);
|
|
320
330
|
triggerOpen(nextOpen, delay);
|
|
321
331
|
|
|
322
332
|
// Pass to origin
|
|
323
333
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
324
334
|
args[_key - 1] = arguments[_key];
|
|
325
335
|
}
|
|
326
|
-
(_originChildProps$eve = originChildProps[eventName]) === null || _originChildProps$eve === void 0
|
|
336
|
+
(_originChildProps$eve = originChildProps[eventName]) === null || _originChildProps$eve === void 0 || _originChildProps$eve.call.apply(_originChildProps$eve, [originChildProps, event].concat(args));
|
|
327
337
|
};
|
|
328
338
|
}
|
|
329
339
|
|
|
@@ -342,7 +352,7 @@ export function generateTrigger() {
|
|
|
342
352
|
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
343
353
|
args[_key2 - 1] = arguments[_key2];
|
|
344
354
|
}
|
|
345
|
-
(_originChildProps$onC = originChildProps.onClick) === null || _originChildProps$onC === void 0
|
|
355
|
+
(_originChildProps$onC = originChildProps.onClick) === null || _originChildProps$onC === void 0 || _originChildProps$onC.call.apply(_originChildProps$onC, [originChildProps, event].concat(args));
|
|
346
356
|
};
|
|
347
357
|
}
|
|
348
358
|
|
|
@@ -374,7 +384,7 @@ export function generateTrigger() {
|
|
|
374
384
|
cloneProps.onMouseMove = function (event) {
|
|
375
385
|
var _originChildProps$onM;
|
|
376
386
|
// setMousePosByEvent(event);
|
|
377
|
-
(_originChildProps$onM = originChildProps.onMouseMove) === null || _originChildProps$onM === void 0
|
|
387
|
+
(_originChildProps$onM = originChildProps.onMouseMove) === null || _originChildProps$onM === void 0 || _originChildProps$onM.call(originChildProps, event);
|
|
378
388
|
};
|
|
379
389
|
}
|
|
380
390
|
}
|
|
@@ -410,7 +420,7 @@ export function generateTrigger() {
|
|
|
410
420
|
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
411
421
|
args[_key3 - 1] = arguments[_key3];
|
|
412
422
|
}
|
|
413
|
-
(_originChildProps$onC2 = originChildProps.onContextMenu) === null || _originChildProps$onC2 === void 0
|
|
423
|
+
(_originChildProps$onC2 = originChildProps.onContextMenu) === null || _originChildProps$onC2 === void 0 || _originChildProps$onC2.call.apply(_originChildProps$onC2, [originChildProps, event].concat(args));
|
|
414
424
|
};
|
|
415
425
|
}
|
|
416
426
|
|
|
@@ -432,7 +442,7 @@ export function generateTrigger() {
|
|
|
432
442
|
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
433
443
|
args[_key4] = arguments[_key4];
|
|
434
444
|
}
|
|
435
|
-
(_mergedChildrenProps$ = mergedChildrenProps[eventName]) === null || _mergedChildrenProps$ === void 0
|
|
445
|
+
(_mergedChildrenProps$ = mergedChildrenProps[eventName]) === null || _mergedChildrenProps$ === void 0 || _mergedChildrenProps$.call.apply(_mergedChildrenProps$, [mergedChildrenProps].concat(args));
|
|
436
446
|
restProps[eventName].apply(restProps, args);
|
|
437
447
|
};
|
|
438
448
|
}
|
package/es/mock.js
CHANGED
|
@@ -11,7 +11,7 @@ var MockPortal = function MockPortal(_ref) {
|
|
|
11
11
|
visible = _React$useState2[0],
|
|
12
12
|
setVisible = _React$useState2[1];
|
|
13
13
|
React.useEffect(function () {
|
|
14
|
-
getContainer === null || getContainer === void 0
|
|
14
|
+
getContainer === null || getContainer === void 0 || getContainer();
|
|
15
15
|
});
|
|
16
16
|
React.useEffect(function () {
|
|
17
17
|
if (open) {
|
|
@@ -15,5 +15,4 @@ var PopupContent = /*#__PURE__*/React.memo(function (_ref) {
|
|
|
15
15
|
if (process.env.NODE_ENV !== 'production') {
|
|
16
16
|
PopupContent.displayName = 'PopupContent';
|
|
17
17
|
}
|
|
18
|
-
var _default = PopupContent;
|
|
19
|
-
exports.default = _default;
|
|
18
|
+
var _default = exports.default = PopupContent;
|
package/lib/Popup/index.js
CHANGED
|
@@ -155,7 +155,7 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
155
155
|
visible: open,
|
|
156
156
|
onVisibleChanged: function onVisibleChanged(nextVisible) {
|
|
157
157
|
var _motion$onVisibleChan;
|
|
158
|
-
motion === null || motion === void 0
|
|
158
|
+
motion === null || motion === void 0 || (_motion$onVisibleChan = motion.onVisibleChanged) === null || _motion$onVisibleChan === void 0 || _motion$onVisibleChan.call(motion, nextVisible);
|
|
159
159
|
_onVisibleChanged(nextVisible);
|
|
160
160
|
}
|
|
161
161
|
}), function (_ref, motionRef) {
|
|
@@ -190,5 +190,4 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
190
190
|
if (process.env.NODE_ENV !== 'production') {
|
|
191
191
|
Popup.displayName = 'Popup';
|
|
192
192
|
}
|
|
193
|
-
var _default = Popup;
|
|
194
|
-
exports.default = _default;
|
|
193
|
+
var _default = exports.default = Popup;
|
package/lib/TriggerWrapper.js
CHANGED
|
@@ -24,5 +24,4 @@ var TriggerWrapper = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
24
24
|
if (process.env.NODE_ENV !== 'production') {
|
|
25
25
|
TriggerWrapper.displayName = 'TriggerWrapper';
|
|
26
26
|
}
|
|
27
|
-
var _default = TriggerWrapper;
|
|
28
|
-
exports.default = _default;
|
|
27
|
+
var _default = exports.default = TriggerWrapper;
|
package/lib/context.js
CHANGED
|
@@ -7,5 +7,4 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var React = _interopRequireWildcard(require("react"));
|
|
9
9
|
var TriggerContext = /*#__PURE__*/React.createContext(null);
|
|
10
|
-
var _default = TriggerContext;
|
|
11
|
-
exports.default = _default;
|
|
10
|
+
var _default = exports.default = TriggerContext;
|
package/lib/hooks/useAlign.js
CHANGED
|
@@ -132,7 +132,7 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
132
132
|
|
|
133
133
|
// placeholder element
|
|
134
134
|
var placeholderElement = doc.createElement('div');
|
|
135
|
-
(_popupElement$parentE = popupElement.parentElement) === null || _popupElement$parentE === void 0
|
|
135
|
+
(_popupElement$parentE = popupElement.parentElement) === null || _popupElement$parentE === void 0 || _popupElement$parentE.appendChild(placeholderElement);
|
|
136
136
|
placeholderElement.style.left = "".concat(popupElement.offsetLeft, "px");
|
|
137
137
|
placeholderElement.style.top = "".concat(popupElement.offsetTop, "px");
|
|
138
138
|
placeholderElement.style.position = popupPosition;
|
|
@@ -216,7 +216,7 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
216
216
|
popupElement.style.top = originTop;
|
|
217
217
|
popupElement.style.right = originRight;
|
|
218
218
|
popupElement.style.bottom = originBottom;
|
|
219
|
-
(_popupElement$parentE2 = popupElement.parentElement) === null || _popupElement$parentE2 === void 0
|
|
219
|
+
(_popupElement$parentE2 = popupElement.parentElement) === null || _popupElement$parentE2 === void 0 || _popupElement$parentE2.removeChild(placeholderElement);
|
|
220
220
|
|
|
221
221
|
// Calculate scale
|
|
222
222
|
var _scaleX = (0, _util.toNum)(Math.round(popupWidth / parseFloat(width) * 1000) / 1000);
|
|
@@ -473,7 +473,7 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
473
473
|
var minBottom = Math.min(popupBottom, targetBottom);
|
|
474
474
|
var yCenter = (maxTop + minBottom) / 2;
|
|
475
475
|
var nextArrowY = yCenter - popupTop;
|
|
476
|
-
onPopupAlign === null || onPopupAlign === void 0
|
|
476
|
+
onPopupAlign === null || onPopupAlign === void 0 || onPopupAlign(popupEle, nextAlignInfo);
|
|
477
477
|
|
|
478
478
|
// Additional calculate right & bottom position
|
|
479
479
|
var offsetX4Right = popupMirrorRect.right - popupRect.x - (nextOffsetX + popupRect.width);
|
package/lib/hooks/useWinClick.js
CHANGED
|
@@ -76,7 +76,7 @@ function useWinClick(open, clickToHide, targetEle, popupEle, mask, maskClosable,
|
|
|
76
76
|
// Warning if target and popup not in same root
|
|
77
77
|
if (process.env.NODE_ENV !== 'production') {
|
|
78
78
|
var _targetEle$getRootNod, _popupEle$getRootNode;
|
|
79
|
-
var targetRoot = targetEle === null || targetEle === void 0
|
|
79
|
+
var targetRoot = targetEle === null || targetEle === void 0 || (_targetEle$getRootNod = targetEle.getRootNode) === null || _targetEle$getRootNod === void 0 ? void 0 : _targetEle$getRootNod.call(targetEle);
|
|
80
80
|
var popupRoot = (_popupEle$getRootNode = popupEle.getRootNode) === null || _popupEle$getRootNode === void 0 ? void 0 : _popupEle$getRootNode.call(popupEle);
|
|
81
81
|
(0, _warning.warning)(targetRoot === popupRoot, "trigger element and popup element should in same shadow root.");
|
|
82
82
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { CSSMotionProps } from 'rc-motion';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import type { ActionType, AlignType, AnimationType, ArrowTypeOuter, BuildInPlacements, TransitionNameType } from './interface';
|
|
4
|
-
export type {
|
|
4
|
+
export type { ActionType, AlignType, ArrowTypeOuter as ArrowType, BuildInPlacements, };
|
|
5
5
|
export interface TriggerRef {
|
|
6
|
+
nativeElement: HTMLElement;
|
|
6
7
|
forceAlign: VoidFunction;
|
|
7
8
|
}
|
|
8
9
|
export interface TriggerProps {
|
package/lib/index.js
CHANGED
|
@@ -20,14 +20,13 @@ var _useId = _interopRequireDefault(require("rc-util/lib/hooks/useId"));
|
|
|
20
20
|
var _useLayoutEffect = _interopRequireDefault(require("rc-util/lib/hooks/useLayoutEffect"));
|
|
21
21
|
var _isMobile = _interopRequireDefault(require("rc-util/lib/isMobile"));
|
|
22
22
|
var React = _interopRequireWildcard(require("react"));
|
|
23
|
-
var
|
|
23
|
+
var _Popup = _interopRequireDefault(require("./Popup"));
|
|
24
|
+
var _TriggerWrapper = _interopRequireDefault(require("./TriggerWrapper"));
|
|
24
25
|
var _context = _interopRequireDefault(require("./context"));
|
|
25
26
|
var _useAction3 = _interopRequireDefault(require("./hooks/useAction"));
|
|
26
27
|
var _useAlign3 = _interopRequireDefault(require("./hooks/useAlign"));
|
|
27
28
|
var _useWatch = _interopRequireDefault(require("./hooks/useWatch"));
|
|
28
29
|
var _useWinClick = _interopRequireDefault(require("./hooks/useWinClick"));
|
|
29
|
-
var _Popup = _interopRequireDefault(require("./Popup"));
|
|
30
|
-
var _TriggerWrapper = _interopRequireDefault(require("./TriggerWrapper"));
|
|
31
30
|
var _util = require("./util");
|
|
32
31
|
var _excluded = ["prefixCls", "children", "action", "showAction", "hideAction", "popupVisible", "defaultPopupVisible", "onPopupVisibleChange", "afterPopupVisibleChange", "mouseEnterDelay", "mouseLeaveDelay", "focusDelay", "blurDelay", "mask", "maskClosable", "getPopupContainer", "forceRender", "autoDestroy", "destroyPopupOnHide", "popup", "popupClassName", "popupStyle", "popupPlacement", "builtinPlacements", "popupAlign", "zIndex", "stretch", "getPopupClassNameFromAlign", "fresh", "alignPoint", "onPopupClick", "onPopupAlign", "arrow", "popupMotion", "maskMotion", "popupTransitionName", "popupAnimation", "maskTransitionName", "maskAnimation", "className", "getTriggerDOMNode"];
|
|
33
32
|
// Removed Props List
|
|
@@ -104,7 +103,7 @@ function generateTrigger() {
|
|
|
104
103
|
return {
|
|
105
104
|
registerSubPopup: function registerSubPopup(id, subPopupEle) {
|
|
106
105
|
subPopupElements.current[id] = subPopupEle;
|
|
107
|
-
parentContext === null || parentContext === void 0
|
|
106
|
+
parentContext === null || parentContext === void 0 || parentContext.registerSubPopup(id, subPopupEle);
|
|
108
107
|
}
|
|
109
108
|
};
|
|
110
109
|
}, [parentContext]);
|
|
@@ -119,7 +118,7 @@ function generateTrigger() {
|
|
|
119
118
|
if ((0, _findDOMNode.isDOM)(node) && popupEle !== node) {
|
|
120
119
|
setPopupEle(node);
|
|
121
120
|
}
|
|
122
|
-
parentContext === null || parentContext === void 0
|
|
121
|
+
parentContext === null || parentContext === void 0 || parentContext.registerSubPopup(id, node);
|
|
123
122
|
});
|
|
124
123
|
|
|
125
124
|
// =========================== Target ===========================
|
|
@@ -128,9 +127,13 @@ function generateTrigger() {
|
|
|
128
127
|
_React$useState6 = (0, _slicedToArray2.default)(_React$useState5, 2),
|
|
129
128
|
targetEle = _React$useState6[0],
|
|
130
129
|
setTargetEle = _React$useState6[1];
|
|
130
|
+
|
|
131
|
+
// Used for forwardRef target. Not use internal
|
|
132
|
+
var externalForwardRef = React.useRef(null);
|
|
131
133
|
var setTargetRef = (0, _useEvent.default)(function (node) {
|
|
132
134
|
if ((0, _findDOMNode.isDOM)(node) && targetEle !== node) {
|
|
133
135
|
setTargetEle(node);
|
|
136
|
+
externalForwardRef.current = node;
|
|
134
137
|
}
|
|
135
138
|
});
|
|
136
139
|
|
|
@@ -170,15 +173,19 @@ function generateTrigger() {
|
|
|
170
173
|
}, [popupVisible]);
|
|
171
174
|
var openRef = React.useRef(mergedOpen);
|
|
172
175
|
openRef.current = mergedOpen;
|
|
176
|
+
var lastTriggerRef = React.useRef([]);
|
|
177
|
+
lastTriggerRef.current = [];
|
|
173
178
|
var internalTriggerOpen = (0, _useEvent.default)(function (nextOpen) {
|
|
179
|
+
var _lastTriggerRef$curre;
|
|
180
|
+
setMergedOpen(nextOpen);
|
|
181
|
+
|
|
174
182
|
// Enter or Pointer will both trigger open state change
|
|
175
183
|
// We only need take one to avoid duplicated change event trigger
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
});
|
|
184
|
+
// Use `lastTriggerRef` to record last open type
|
|
185
|
+
if (((_lastTriggerRef$curre = lastTriggerRef.current[lastTriggerRef.current.length - 1]) !== null && _lastTriggerRef$curre !== void 0 ? _lastTriggerRef$curre : mergedOpen) !== nextOpen) {
|
|
186
|
+
lastTriggerRef.current.push(nextOpen);
|
|
187
|
+
onPopupVisibleChange === null || onPopupVisibleChange === void 0 || onPopupVisibleChange(nextOpen);
|
|
188
|
+
}
|
|
182
189
|
});
|
|
183
190
|
|
|
184
191
|
// Trigger for delay
|
|
@@ -268,8 +275,11 @@ function generateTrigger() {
|
|
|
268
275
|
var baseClassName = (0, _util.getAlignPopupClassName)(builtinPlacements, prefixCls, alignInfo, alignPoint);
|
|
269
276
|
return (0, _classnames.default)(baseClassName, getPopupClassNameFromAlign === null || getPopupClassNameFromAlign === void 0 ? void 0 : getPopupClassNameFromAlign(alignInfo));
|
|
270
277
|
}, [alignInfo, getPopupClassNameFromAlign, builtinPlacements, prefixCls, alignPoint]);
|
|
278
|
+
|
|
279
|
+
// ============================ Refs ============================
|
|
271
280
|
React.useImperativeHandle(ref, function () {
|
|
272
281
|
return {
|
|
282
|
+
nativeElement: externalForwardRef.current,
|
|
273
283
|
forceAlign: triggerAlign
|
|
274
284
|
};
|
|
275
285
|
});
|
|
@@ -299,7 +309,7 @@ function generateTrigger() {
|
|
|
299
309
|
var onVisibleChanged = function onVisibleChanged(visible) {
|
|
300
310
|
setInMotion(false);
|
|
301
311
|
onAlign();
|
|
302
|
-
afterPopupVisibleChange === null || afterPopupVisibleChange === void 0
|
|
312
|
+
afterPopupVisibleChange === null || afterPopupVisibleChange === void 0 || afterPopupVisibleChange(visible);
|
|
303
313
|
};
|
|
304
314
|
|
|
305
315
|
// We will trigger align when motion is in prepare
|
|
@@ -326,14 +336,14 @@ function generateTrigger() {
|
|
|
326
336
|
function wrapperAction(eventName, nextOpen, delay, preEvent) {
|
|
327
337
|
cloneProps[eventName] = function (event) {
|
|
328
338
|
var _originChildProps$eve;
|
|
329
|
-
preEvent === null || preEvent === void 0
|
|
339
|
+
preEvent === null || preEvent === void 0 || preEvent(event);
|
|
330
340
|
triggerOpen(nextOpen, delay);
|
|
331
341
|
|
|
332
342
|
// Pass to origin
|
|
333
343
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
334
344
|
args[_key - 1] = arguments[_key];
|
|
335
345
|
}
|
|
336
|
-
(_originChildProps$eve = originChildProps[eventName]) === null || _originChildProps$eve === void 0
|
|
346
|
+
(_originChildProps$eve = originChildProps[eventName]) === null || _originChildProps$eve === void 0 || _originChildProps$eve.call.apply(_originChildProps$eve, [originChildProps, event].concat(args));
|
|
337
347
|
};
|
|
338
348
|
}
|
|
339
349
|
|
|
@@ -352,7 +362,7 @@ function generateTrigger() {
|
|
|
352
362
|
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
353
363
|
args[_key2 - 1] = arguments[_key2];
|
|
354
364
|
}
|
|
355
|
-
(_originChildProps$onC = originChildProps.onClick) === null || _originChildProps$onC === void 0
|
|
365
|
+
(_originChildProps$onC = originChildProps.onClick) === null || _originChildProps$onC === void 0 || _originChildProps$onC.call.apply(_originChildProps$onC, [originChildProps, event].concat(args));
|
|
356
366
|
};
|
|
357
367
|
}
|
|
358
368
|
|
|
@@ -384,7 +394,7 @@ function generateTrigger() {
|
|
|
384
394
|
cloneProps.onMouseMove = function (event) {
|
|
385
395
|
var _originChildProps$onM;
|
|
386
396
|
// setMousePosByEvent(event);
|
|
387
|
-
(_originChildProps$onM = originChildProps.onMouseMove) === null || _originChildProps$onM === void 0
|
|
397
|
+
(_originChildProps$onM = originChildProps.onMouseMove) === null || _originChildProps$onM === void 0 || _originChildProps$onM.call(originChildProps, event);
|
|
388
398
|
};
|
|
389
399
|
}
|
|
390
400
|
}
|
|
@@ -420,7 +430,7 @@ function generateTrigger() {
|
|
|
420
430
|
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
421
431
|
args[_key3 - 1] = arguments[_key3];
|
|
422
432
|
}
|
|
423
|
-
(_originChildProps$onC2 = originChildProps.onContextMenu) === null || _originChildProps$onC2 === void 0
|
|
433
|
+
(_originChildProps$onC2 = originChildProps.onContextMenu) === null || _originChildProps$onC2 === void 0 || _originChildProps$onC2.call.apply(_originChildProps$onC2, [originChildProps, event].concat(args));
|
|
424
434
|
};
|
|
425
435
|
}
|
|
426
436
|
|
|
@@ -442,7 +452,7 @@ function generateTrigger() {
|
|
|
442
452
|
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
443
453
|
args[_key4] = arguments[_key4];
|
|
444
454
|
}
|
|
445
|
-
(_mergedChildrenProps$ = mergedChildrenProps[eventName]) === null || _mergedChildrenProps$ === void 0
|
|
455
|
+
(_mergedChildrenProps$ = mergedChildrenProps[eventName]) === null || _mergedChildrenProps$ === void 0 || _mergedChildrenProps$.call.apply(_mergedChildrenProps$, [mergedChildrenProps].concat(args));
|
|
446
456
|
restProps[eventName].apply(restProps, args);
|
|
447
457
|
};
|
|
448
458
|
}
|
|
@@ -526,5 +536,4 @@ function generateTrigger() {
|
|
|
526
536
|
}
|
|
527
537
|
return Trigger;
|
|
528
538
|
}
|
|
529
|
-
var _default = generateTrigger(_portal.default);
|
|
530
|
-
exports.default = _default;
|
|
539
|
+
var _default = exports.default = generateTrigger(_portal.default);
|
package/lib/mock.js
CHANGED
|
@@ -19,7 +19,7 @@ var MockPortal = function MockPortal(_ref) {
|
|
|
19
19
|
visible = _React$useState2[0],
|
|
20
20
|
setVisible = _React$useState2[1];
|
|
21
21
|
React.useEffect(function () {
|
|
22
|
-
getContainer === null || getContainer === void 0
|
|
22
|
+
getContainer === null || getContainer === void 0 || getContainer();
|
|
23
23
|
});
|
|
24
24
|
React.useEffect(function () {
|
|
25
25
|
if (open) {
|
|
@@ -30,5 +30,4 @@ var MockPortal = function MockPortal(_ref) {
|
|
|
30
30
|
}, [open, autoDestroy]);
|
|
31
31
|
return visible ? children : null;
|
|
32
32
|
};
|
|
33
|
-
var _default = (0, _index.generateTrigger)(MockPortal);
|
|
34
|
-
exports.default = _default;
|
|
33
|
+
var _default = exports.default = (0, _index.generateTrigger)(MockPortal);
|