@rc-component/trigger 2.2.6 → 3.0.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/es/Popup/Arrow.js +23 -20
- package/es/Popup/Mask.d.ts +1 -1
- package/es/Popup/Mask.js +17 -16
- package/es/Popup/PopupContent.js +3 -6
- package/es/Popup/index.d.ts +1 -1
- package/es/Popup/index.js +83 -78
- package/es/TriggerWrapper.js +9 -7
- package/es/context.js +1 -1
- package/es/hooks/useAction.js +5 -5
- package/es/hooks/useAlign.js +205 -215
- package/es/hooks/useWatch.js +11 -12
- package/es/hooks/useWinClick.js +14 -16
- package/es/index.d.ts +2 -14
- package/es/index.js +167 -244
- package/es/interface.d.ts +1 -1
- package/es/mock.js +10 -13
- package/es/util.d.ts +1 -4
- package/es/util.js +57 -75
- package/lib/Popup/Arrow.js +26 -22
- package/lib/Popup/Mask.d.ts +1 -1
- package/lib/Popup/Mask.js +21 -19
- package/lib/Popup/PopupContent.js +5 -7
- package/lib/Popup/index.d.ts +1 -1
- package/lib/Popup/index.js +89 -83
- package/lib/TriggerWrapper.js +11 -8
- package/lib/context.js +3 -2
- package/lib/hooks/useAction.js +7 -6
- package/lib/hooks/useAlign.js +208 -217
- package/lib/hooks/useWatch.js +12 -13
- package/lib/hooks/useWinClick.js +16 -17
- package/lib/index.d.ts +2 -14
- package/lib/index.js +172 -248
- package/lib/interface.d.ts +1 -1
- package/lib/mock.js +12 -15
- package/lib/util.d.ts +1 -4
- package/lib/util.js +57 -77
- package/package.json +10 -11
package/es/hooks/useWatch.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import useLayoutEffect from "rc-util/es/hooks/useLayoutEffect";
|
|
1
|
+
import useLayoutEffect from "@rc-component/util/es/hooks/useLayoutEffect";
|
|
3
2
|
import { collectScroller, getWin } from "../util";
|
|
4
3
|
export default function useWatch(open, target, popup, onAlign, onScroll) {
|
|
5
|
-
useLayoutEffect(
|
|
4
|
+
useLayoutEffect(() => {
|
|
6
5
|
if (open && target && popup) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
const targetElement = target;
|
|
7
|
+
const popupElement = popup;
|
|
8
|
+
const targetScrollList = collectScroller(targetElement);
|
|
9
|
+
const popupScrollList = collectScroller(popupElement);
|
|
10
|
+
const win = getWin(popupElement);
|
|
11
|
+
const mergedList = new Set([win, ...targetScrollList, ...popupScrollList]);
|
|
13
12
|
function notifyScroll() {
|
|
14
13
|
onAlign();
|
|
15
14
|
onScroll();
|
|
16
15
|
}
|
|
17
|
-
mergedList.forEach(
|
|
16
|
+
mergedList.forEach(scroller => {
|
|
18
17
|
scroller.addEventListener('scroll', notifyScroll, {
|
|
19
18
|
passive: true
|
|
20
19
|
});
|
|
@@ -25,8 +24,8 @@ export default function useWatch(open, target, popup, onAlign, onScroll) {
|
|
|
25
24
|
|
|
26
25
|
// First time always do align
|
|
27
26
|
onAlign();
|
|
28
|
-
return
|
|
29
|
-
mergedList.forEach(
|
|
27
|
+
return () => {
|
|
28
|
+
mergedList.forEach(scroller => {
|
|
30
29
|
scroller.removeEventListener('scroll', notifyScroll);
|
|
31
30
|
win.removeEventListener('resize', notifyScroll);
|
|
32
31
|
});
|
package/es/hooks/useWinClick.js
CHANGED
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
import { getShadowRoot } from "rc-util/es/Dom/shadow";
|
|
2
|
-
import { warning } from "rc-util/es/warning";
|
|
1
|
+
import { getShadowRoot } from "@rc-component/util/es/Dom/shadow";
|
|
2
|
+
import { warning } from "@rc-component/util/es/warning";
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { getWin } from "../util";
|
|
5
5
|
export default function useWinClick(open, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen) {
|
|
6
|
-
|
|
6
|
+
const openRef = React.useRef(open);
|
|
7
7
|
openRef.current = open;
|
|
8
|
-
|
|
8
|
+
const popupPointerDownRef = React.useRef(false);
|
|
9
9
|
|
|
10
10
|
// Click to hide is special action since click popup element should not hide
|
|
11
|
-
React.useEffect(
|
|
11
|
+
React.useEffect(() => {
|
|
12
12
|
if (clickToHide && popupEle && (!mask || maskClosable)) {
|
|
13
|
-
|
|
13
|
+
const onPointerDown = () => {
|
|
14
14
|
popupPointerDownRef.current = false;
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
|
|
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) {
|
|
16
|
+
const onTriggerClose = e => {
|
|
17
|
+
if (openRef.current && !inPopupOrChild(e.composedPath?.()?.[0] || e.target) && !popupPointerDownRef.current) {
|
|
19
18
|
triggerOpen(false);
|
|
20
19
|
}
|
|
21
20
|
};
|
|
22
|
-
|
|
21
|
+
const win = getWin(popupEle);
|
|
23
22
|
win.addEventListener('pointerdown', onPointerDown, true);
|
|
24
23
|
win.addEventListener('mousedown', onTriggerClose, true);
|
|
25
24
|
win.addEventListener('contextmenu', onTriggerClose, true);
|
|
26
25
|
|
|
27
26
|
// shadow root
|
|
28
|
-
|
|
27
|
+
const targetShadowRoot = getShadowRoot(targetEle);
|
|
29
28
|
if (targetShadowRoot) {
|
|
30
29
|
targetShadowRoot.addEventListener('mousedown', onTriggerClose, true);
|
|
31
30
|
targetShadowRoot.addEventListener('contextmenu', onTriggerClose, true);
|
|
@@ -33,12 +32,11 @@ export default function useWinClick(open, clickToHide, targetEle, popupEle, mask
|
|
|
33
32
|
|
|
34
33
|
// Warning if target and popup not in same root
|
|
35
34
|
if (process.env.NODE_ENV !== 'production') {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
warning(targetRoot === popupRoot, "trigger element and popup element should in same shadow root.");
|
|
35
|
+
const targetRoot = targetEle?.getRootNode?.();
|
|
36
|
+
const popupRoot = popupEle.getRootNode?.();
|
|
37
|
+
warning(targetRoot === popupRoot, `trigger element and popup element should in same shadow root.`);
|
|
40
38
|
}
|
|
41
|
-
return
|
|
39
|
+
return () => {
|
|
42
40
|
win.removeEventListener('pointerdown', onPointerDown, true);
|
|
43
41
|
win.removeEventListener('mousedown', onTriggerClose, true);
|
|
44
42
|
win.removeEventListener('contextmenu', onTriggerClose, true);
|
package/es/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { CSSMotionProps } from 'rc-motion';
|
|
1
|
+
import type { CSSMotionProps } from '@rc-component/motion';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import type { ActionType, AlignType,
|
|
3
|
+
import type { ActionType, AlignType, ArrowTypeOuter, BuildInPlacements } from './interface';
|
|
4
4
|
export type { ActionType, AlignType, ArrowTypeOuter as ArrowType, BuildInPlacements, };
|
|
5
5
|
export interface TriggerRef {
|
|
6
6
|
nativeElement: HTMLElement;
|
|
@@ -23,22 +23,12 @@ export interface TriggerProps {
|
|
|
23
23
|
getPopupContainer?: (node: HTMLElement) => HTMLElement;
|
|
24
24
|
forceRender?: boolean;
|
|
25
25
|
autoDestroy?: boolean;
|
|
26
|
-
/** @deprecated Please use `autoDestroy` instead */
|
|
27
|
-
destroyPopupOnHide?: boolean;
|
|
28
26
|
mask?: boolean;
|
|
29
27
|
maskClosable?: boolean;
|
|
30
28
|
/** Set popup motion. You can ref `rc-motion` for more info. */
|
|
31
29
|
popupMotion?: CSSMotionProps;
|
|
32
30
|
/** Set mask motion. You can ref `rc-motion` for more info. */
|
|
33
31
|
maskMotion?: CSSMotionProps;
|
|
34
|
-
/** @deprecated Please us `popupMotion` instead. */
|
|
35
|
-
popupTransitionName?: TransitionNameType;
|
|
36
|
-
/** @deprecated Please us `popupMotion` instead. */
|
|
37
|
-
popupAnimation?: AnimationType;
|
|
38
|
-
/** @deprecated Please us `maskMotion` instead. */
|
|
39
|
-
maskTransitionName?: TransitionNameType;
|
|
40
|
-
/** @deprecated Please us `maskMotion` instead. */
|
|
41
|
-
maskAnimation?: AnimationType;
|
|
42
32
|
mouseEnterDelay?: number;
|
|
43
33
|
mouseLeaveDelay?: number;
|
|
44
34
|
focusDelay?: number;
|
|
@@ -59,8 +49,6 @@ export interface TriggerProps {
|
|
|
59
49
|
*/
|
|
60
50
|
fresh?: boolean;
|
|
61
51
|
arrow?: boolean | ArrowTypeOuter;
|
|
62
|
-
/** @deprecated Add `className` on `children`. Please add `className` directly instead. */
|
|
63
|
-
className?: string;
|
|
64
52
|
/**
|
|
65
53
|
* @private Get trigger DOM node.
|
|
66
54
|
* Used for some component is function component which can not access by `findDOMNode`
|