@rc-component/trigger 2.2.4 → 2.2.5
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.d.ts +1 -1
- package/es/Popup/index.js +2 -2
- package/es/hooks/useWinClick.d.ts +1 -1
- package/es/hooks/useWinClick.js +11 -1
- package/es/index.js +2 -9
- package/lib/Popup/index.d.ts +1 -1
- package/lib/Popup/index.js +2 -2
- package/lib/hooks/useWinClick.d.ts +1 -1
- package/lib/hooks/useWinClick.js +11 -1
- package/lib/index.js +2 -9
- package/package.json +2 -2
package/es/Popup/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface PopupProps {
|
|
|
11
11
|
onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
|
|
12
12
|
onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
|
|
13
13
|
onPointerEnter?: React.MouseEventHandler<HTMLDivElement>;
|
|
14
|
-
|
|
14
|
+
onPointerDownCapture?: React.MouseEventHandler<HTMLDivElement>;
|
|
15
15
|
zIndex?: number;
|
|
16
16
|
mask?: boolean;
|
|
17
17
|
onVisibleChanged: (visible: boolean) => void;
|
package/es/Popup/index.js
CHANGED
|
@@ -35,7 +35,7 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
35
35
|
onMouseEnter = props.onMouseEnter,
|
|
36
36
|
onMouseLeave = props.onMouseLeave,
|
|
37
37
|
onPointerEnter = props.onPointerEnter,
|
|
38
|
-
|
|
38
|
+
onPointerDownCapture = props.onPointerDownCapture,
|
|
39
39
|
ready = props.ready,
|
|
40
40
|
offsetX = props.offsetX,
|
|
41
41
|
offsetY = props.offsetY,
|
|
@@ -169,7 +169,7 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
169
169
|
onMouseLeave: onMouseLeave,
|
|
170
170
|
onPointerEnter: onPointerEnter,
|
|
171
171
|
onClick: onClick,
|
|
172
|
-
|
|
172
|
+
onPointerDownCapture: onPointerDownCapture
|
|
173
173
|
}, arrow && /*#__PURE__*/React.createElement(Arrow, {
|
|
174
174
|
prefixCls: prefixCls,
|
|
175
175
|
arrow: arrow,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function useWinClick(open: boolean, clickToHide: boolean, targetEle: HTMLElement, popupEle: HTMLElement, mask: boolean, maskClosable: boolean, inPopupOrChild: (target: EventTarget) => boolean, triggerOpen: (open: boolean) => void): void;
|
|
1
|
+
export default function useWinClick(open: boolean, clickToHide: boolean, targetEle: HTMLElement, popupEle: HTMLElement, mask: boolean, maskClosable: boolean, inPopupOrChild: (target: EventTarget) => boolean, triggerOpen: (open: boolean) => void): () => void;
|
package/es/hooks/useWinClick.js
CHANGED
|
@@ -5,17 +5,22 @@ import { getWin } from "../util";
|
|
|
5
5
|
export default function useWinClick(open, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen) {
|
|
6
6
|
var openRef = React.useRef(open);
|
|
7
7
|
openRef.current = open;
|
|
8
|
+
var popupPointerDownRef = React.useRef(false);
|
|
8
9
|
|
|
9
10
|
// Click to hide is special action since click popup element should not hide
|
|
10
11
|
React.useEffect(function () {
|
|
11
12
|
if (clickToHide && popupEle && (!mask || maskClosable)) {
|
|
13
|
+
var onPointerDown = function onPointerDown() {
|
|
14
|
+
popupPointerDownRef.current = false;
|
|
15
|
+
};
|
|
12
16
|
var onTriggerClose = function onTriggerClose(e) {
|
|
13
17
|
var _e$composedPath;
|
|
14
|
-
if (openRef.current && !inPopupOrChild(((_e$composedPath = e.composedPath) === null || _e$composedPath === void 0 || (_e$composedPath = _e$composedPath.call(e)) === null || _e$composedPath === void 0 ? void 0 : _e$composedPath[0]) || e.target)) {
|
|
18
|
+
if (openRef.current && !inPopupOrChild(((_e$composedPath = e.composedPath) === null || _e$composedPath === void 0 || (_e$composedPath = _e$composedPath.call(e)) === null || _e$composedPath === void 0 ? void 0 : _e$composedPath[0]) || e.target) && !popupPointerDownRef.current) {
|
|
15
19
|
triggerOpen(false);
|
|
16
20
|
}
|
|
17
21
|
};
|
|
18
22
|
var win = getWin(popupEle);
|
|
23
|
+
win.addEventListener('pointerdown', onPointerDown, true);
|
|
19
24
|
win.addEventListener('mousedown', onTriggerClose, true);
|
|
20
25
|
win.addEventListener('contextmenu', onTriggerClose, true);
|
|
21
26
|
|
|
@@ -34,6 +39,7 @@ export default function useWinClick(open, clickToHide, targetEle, popupEle, mask
|
|
|
34
39
|
warning(targetRoot === popupRoot, "trigger element and popup element should in same shadow root.");
|
|
35
40
|
}
|
|
36
41
|
return function () {
|
|
42
|
+
win.removeEventListener('pointerdown', onPointerDown, true);
|
|
37
43
|
win.removeEventListener('mousedown', onTriggerClose, true);
|
|
38
44
|
win.removeEventListener('contextmenu', onTriggerClose, true);
|
|
39
45
|
if (targetShadowRoot) {
|
|
@@ -43,4 +49,8 @@ export default function useWinClick(open, clickToHide, targetEle, popupEle, mask
|
|
|
43
49
|
};
|
|
44
50
|
}
|
|
45
51
|
}, [clickToHide, targetEle, popupEle, mask, maskClosable]);
|
|
52
|
+
function onPopupPointerDown() {
|
|
53
|
+
popupPointerDownRef.current = true;
|
|
54
|
+
}
|
|
55
|
+
return onPopupPointerDown;
|
|
46
56
|
}
|
package/es/index.js
CHANGED
|
@@ -364,7 +364,7 @@ export function generateTrigger() {
|
|
|
364
364
|
}
|
|
365
365
|
|
|
366
366
|
// Click to hide is special action since click popup element should not hide
|
|
367
|
-
useWinClick(mergedOpen, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen);
|
|
367
|
+
var onPopupPointerDown = useWinClick(mergedOpen, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen);
|
|
368
368
|
|
|
369
369
|
// ======================= Action: Hover ========================
|
|
370
370
|
var hoverToShow = showActions.has('hover');
|
|
@@ -494,14 +494,7 @@ export function generateTrigger() {
|
|
|
494
494
|
// Click
|
|
495
495
|
,
|
|
496
496
|
onClick: onPopupClick,
|
|
497
|
-
|
|
498
|
-
// Additional check for click to hide
|
|
499
|
-
// Since `createPortal` will not included in the popup element
|
|
500
|
-
// So we use capture to handle this
|
|
501
|
-
if (clickToHide) {
|
|
502
|
-
triggerOpen(true);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
497
|
+
onPointerDownCapture: onPopupPointerDown
|
|
505
498
|
// Mask
|
|
506
499
|
,
|
|
507
500
|
mask: mask
|
package/lib/Popup/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface PopupProps {
|
|
|
11
11
|
onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
|
|
12
12
|
onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
|
|
13
13
|
onPointerEnter?: React.MouseEventHandler<HTMLDivElement>;
|
|
14
|
-
|
|
14
|
+
onPointerDownCapture?: React.MouseEventHandler<HTMLDivElement>;
|
|
15
15
|
zIndex?: number;
|
|
16
16
|
mask?: boolean;
|
|
17
17
|
onVisibleChanged: (visible: boolean) => void;
|
package/lib/Popup/index.js
CHANGED
|
@@ -43,7 +43,7 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
43
43
|
onMouseEnter = props.onMouseEnter,
|
|
44
44
|
onMouseLeave = props.onMouseLeave,
|
|
45
45
|
onPointerEnter = props.onPointerEnter,
|
|
46
|
-
|
|
46
|
+
onPointerDownCapture = props.onPointerDownCapture,
|
|
47
47
|
ready = props.ready,
|
|
48
48
|
offsetX = props.offsetX,
|
|
49
49
|
offsetY = props.offsetY,
|
|
@@ -177,7 +177,7 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
177
177
|
onMouseLeave: onMouseLeave,
|
|
178
178
|
onPointerEnter: onPointerEnter,
|
|
179
179
|
onClick: onClick,
|
|
180
|
-
|
|
180
|
+
onPointerDownCapture: onPointerDownCapture
|
|
181
181
|
}, arrow && /*#__PURE__*/React.createElement(_Arrow.default, {
|
|
182
182
|
prefixCls: prefixCls,
|
|
183
183
|
arrow: arrow,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function useWinClick(open: boolean, clickToHide: boolean, targetEle: HTMLElement, popupEle: HTMLElement, mask: boolean, maskClosable: boolean, inPopupOrChild: (target: EventTarget) => boolean, triggerOpen: (open: boolean) => void): void;
|
|
1
|
+
export default function useWinClick(open: boolean, clickToHide: boolean, targetEle: HTMLElement, popupEle: HTMLElement, mask: boolean, maskClosable: boolean, inPopupOrChild: (target: EventTarget) => boolean, triggerOpen: (open: boolean) => void): () => void;
|
package/lib/hooks/useWinClick.js
CHANGED
|
@@ -12,17 +12,22 @@ var _util = require("../util");
|
|
|
12
12
|
function useWinClick(open, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen) {
|
|
13
13
|
var openRef = React.useRef(open);
|
|
14
14
|
openRef.current = open;
|
|
15
|
+
var popupPointerDownRef = React.useRef(false);
|
|
15
16
|
|
|
16
17
|
// Click to hide is special action since click popup element should not hide
|
|
17
18
|
React.useEffect(function () {
|
|
18
19
|
if (clickToHide && popupEle && (!mask || maskClosable)) {
|
|
20
|
+
var onPointerDown = function onPointerDown() {
|
|
21
|
+
popupPointerDownRef.current = false;
|
|
22
|
+
};
|
|
19
23
|
var onTriggerClose = function onTriggerClose(e) {
|
|
20
24
|
var _e$composedPath;
|
|
21
|
-
if (openRef.current && !inPopupOrChild(((_e$composedPath = e.composedPath) === null || _e$composedPath === void 0 || (_e$composedPath = _e$composedPath.call(e)) === null || _e$composedPath === void 0 ? void 0 : _e$composedPath[0]) || e.target)) {
|
|
25
|
+
if (openRef.current && !inPopupOrChild(((_e$composedPath = e.composedPath) === null || _e$composedPath === void 0 || (_e$composedPath = _e$composedPath.call(e)) === null || _e$composedPath === void 0 ? void 0 : _e$composedPath[0]) || e.target) && !popupPointerDownRef.current) {
|
|
22
26
|
triggerOpen(false);
|
|
23
27
|
}
|
|
24
28
|
};
|
|
25
29
|
var win = (0, _util.getWin)(popupEle);
|
|
30
|
+
win.addEventListener('pointerdown', onPointerDown, true);
|
|
26
31
|
win.addEventListener('mousedown', onTriggerClose, true);
|
|
27
32
|
win.addEventListener('contextmenu', onTriggerClose, true);
|
|
28
33
|
|
|
@@ -41,6 +46,7 @@ function useWinClick(open, clickToHide, targetEle, popupEle, mask, maskClosable,
|
|
|
41
46
|
(0, _warning.warning)(targetRoot === popupRoot, "trigger element and popup element should in same shadow root.");
|
|
42
47
|
}
|
|
43
48
|
return function () {
|
|
49
|
+
win.removeEventListener('pointerdown', onPointerDown, true);
|
|
44
50
|
win.removeEventListener('mousedown', onTriggerClose, true);
|
|
45
51
|
win.removeEventListener('contextmenu', onTriggerClose, true);
|
|
46
52
|
if (targetShadowRoot) {
|
|
@@ -50,4 +56,8 @@ function useWinClick(open, clickToHide, targetEle, popupEle, mask, maskClosable,
|
|
|
50
56
|
};
|
|
51
57
|
}
|
|
52
58
|
}, [clickToHide, targetEle, popupEle, mask, maskClosable]);
|
|
59
|
+
function onPopupPointerDown() {
|
|
60
|
+
popupPointerDownRef.current = true;
|
|
61
|
+
}
|
|
62
|
+
return onPopupPointerDown;
|
|
53
63
|
}
|
package/lib/index.js
CHANGED
|
@@ -372,7 +372,7 @@ function generateTrigger() {
|
|
|
372
372
|
}
|
|
373
373
|
|
|
374
374
|
// Click to hide is special action since click popup element should not hide
|
|
375
|
-
(0, _useWinClick.default)(mergedOpen, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen);
|
|
375
|
+
var onPopupPointerDown = (0, _useWinClick.default)(mergedOpen, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen);
|
|
376
376
|
|
|
377
377
|
// ======================= Action: Hover ========================
|
|
378
378
|
var hoverToShow = showActions.has('hover');
|
|
@@ -502,14 +502,7 @@ function generateTrigger() {
|
|
|
502
502
|
// Click
|
|
503
503
|
,
|
|
504
504
|
onClick: onPopupClick,
|
|
505
|
-
|
|
506
|
-
// Additional check for click to hide
|
|
507
|
-
// Since `createPortal` will not included in the popup element
|
|
508
|
-
// So we use capture to handle this
|
|
509
|
-
if (clickToHide) {
|
|
510
|
-
triggerOpen(true);
|
|
511
|
-
}
|
|
512
|
-
}
|
|
505
|
+
onPointerDownCapture: onPopupPointerDown
|
|
513
506
|
// Mask
|
|
514
507
|
,
|
|
515
508
|
mask: mask
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rc-component/trigger",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.5",
|
|
4
4
|
"description": "base abstract trigger component for react",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=8.x"
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"start": "dumi dev",
|
|
34
34
|
"build": "dumi build",
|
|
35
35
|
"compile": "father build && lessc assets/index.less assets/index.css",
|
|
36
|
-
"prepublishOnly": "npm run compile ",
|
|
36
|
+
"prepublishOnly": "npm run compile && np --yolo --no-publish",
|
|
37
37
|
"lint": "eslint src/ docs/examples/ --ext .tsx,.ts,.jsx,.js",
|
|
38
38
|
"test": "rc-test",
|
|
39
39
|
"prettier": "prettier --write .",
|