@rc-component/trigger 3.6.2 → 3.6.4
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/UniqueProvider/index.js +11 -10
- package/es/context.d.ts +1 -1
- package/es/index.js +5 -4
- package/lib/UniqueProvider/index.js +11 -10
- package/lib/context.d.ts +1 -1
- package/lib/index.js +5 -4
- package/package.json +1 -1
- package/es/UniqueProvider/MotionContent.d.ts +0 -11
- package/es/UniqueProvider/MotionContent.js +0 -32
- package/lib/UniqueProvider/MotionContent.d.ts +0 -11
- package/lib/UniqueProvider/MotionContent.js +0 -41
|
@@ -9,7 +9,6 @@ import useTargetState from "./useTargetState";
|
|
|
9
9
|
import { isDOM } from "@rc-component/util/es/Dom/findDOMNode";
|
|
10
10
|
import FloatBg from "./FloatBg";
|
|
11
11
|
import classNames from 'classnames';
|
|
12
|
-
import MotionContent from "./MotionContent";
|
|
13
12
|
import { getAlignPopupClassName } from "../util";
|
|
14
13
|
const UniqueProvider = ({
|
|
15
14
|
children
|
|
@@ -30,18 +29,23 @@ const UniqueProvider = ({
|
|
|
30
29
|
});
|
|
31
30
|
|
|
32
31
|
// ========================== Register ==========================
|
|
33
|
-
|
|
32
|
+
// Store the isOpen function from the latest show call
|
|
33
|
+
const isOpenRef = React.useRef(null);
|
|
34
34
|
const delayInvoke = useDelay();
|
|
35
|
-
const show = useEvent(showOptions => {
|
|
35
|
+
const show = useEvent((showOptions, isOpen) => {
|
|
36
|
+
// Store the isOpen function for later use in hide
|
|
37
|
+
isOpenRef.current = isOpen;
|
|
36
38
|
delayInvoke(() => {
|
|
37
|
-
if (showOptions.id !== options?.id) {
|
|
38
|
-
setPopupId(i => i + 1);
|
|
39
|
-
}
|
|
40
39
|
trigger(showOptions);
|
|
41
40
|
}, showOptions.delay);
|
|
42
41
|
});
|
|
43
42
|
const hide = delay => {
|
|
44
43
|
delayInvoke(() => {
|
|
44
|
+
// Check if we should still hide by calling the isOpen function
|
|
45
|
+
// If isOpen returns true, it means another trigger wants to keep it open
|
|
46
|
+
if (isOpenRef.current?.()) {
|
|
47
|
+
return; // Don't hide if something else wants it open
|
|
48
|
+
}
|
|
45
49
|
trigger(false);
|
|
46
50
|
// Don't clear target, currentNode, options immediately, wait until animation completes
|
|
47
51
|
}, delay);
|
|
@@ -102,10 +106,7 @@ const UniqueProvider = ({
|
|
|
102
106
|
ref: setPopupRef,
|
|
103
107
|
portal: Portal,
|
|
104
108
|
prefixCls: prefixCls,
|
|
105
|
-
popup:
|
|
106
|
-
prefixCls: prefixCls,
|
|
107
|
-
key: popupId
|
|
108
|
-
}, options.popup),
|
|
109
|
+
popup: options.popup,
|
|
109
110
|
className: classNames(options.popupClassName, alignedClassName, `${prefixCls}-unique-controlled`),
|
|
110
111
|
style: options.popupStyle,
|
|
111
112
|
target: options.target,
|
package/es/context.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export interface UniqueShowOptions {
|
|
|
28
28
|
getPopupClassNameFromAlign?: (align: AlignType) => string;
|
|
29
29
|
}
|
|
30
30
|
export interface UniqueContextProps {
|
|
31
|
-
show: (options: UniqueShowOptions) => void;
|
|
31
|
+
show: (options: UniqueShowOptions, isOpen: () => boolean) => void;
|
|
32
32
|
hide: (delay: number) => void;
|
|
33
33
|
}
|
|
34
34
|
export declare const UniqueContext: React.Context<UniqueContextProps>;
|
package/es/index.js
CHANGED
|
@@ -150,6 +150,9 @@ export function generateTrigger(PortalComponent = Portal) {
|
|
|
150
150
|
setInternalOpen(nextOpen);
|
|
151
151
|
}
|
|
152
152
|
});
|
|
153
|
+
|
|
154
|
+
// Support ref
|
|
155
|
+
const isOpen = useEvent(() => mergedOpen);
|
|
153
156
|
useLayoutEffect(() => {
|
|
154
157
|
setInternalOpen(popupVisible || false);
|
|
155
158
|
}, [popupVisible]);
|
|
@@ -182,9 +185,7 @@ export function generateTrigger(PortalComponent = Portal) {
|
|
|
182
185
|
useLayoutEffect(() => {
|
|
183
186
|
if (uniqueContext && unique && targetEle && !openUncontrolled && !parentContext) {
|
|
184
187
|
if (mergedOpen) {
|
|
185
|
-
|
|
186
|
-
uniqueContext.show(getUniqueOptions(0));
|
|
187
|
-
});
|
|
188
|
+
uniqueContext.show(getUniqueOptions(0), isOpen);
|
|
188
189
|
} else {
|
|
189
190
|
uniqueContext.hide(0);
|
|
190
191
|
}
|
|
@@ -223,7 +224,7 @@ export function generateTrigger(PortalComponent = Portal) {
|
|
|
223
224
|
// If there is a parentContext, don't call uniqueContext methods
|
|
224
225
|
if (uniqueContext && unique && openUncontrolled && !parentContext) {
|
|
225
226
|
if (nextOpen) {
|
|
226
|
-
uniqueContext.show(getUniqueOptions(delay));
|
|
227
|
+
uniqueContext.show(getUniqueOptions(delay), isOpen);
|
|
227
228
|
} else {
|
|
228
229
|
uniqueContext.hide(delay);
|
|
229
230
|
}
|
|
@@ -15,7 +15,6 @@ var _useTargetState = _interopRequireDefault(require("./useTargetState"));
|
|
|
15
15
|
var _findDOMNode = require("@rc-component/util/lib/Dom/findDOMNode");
|
|
16
16
|
var _FloatBg = _interopRequireDefault(require("./FloatBg"));
|
|
17
17
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
18
|
-
var _MotionContent = _interopRequireDefault(require("./MotionContent"));
|
|
19
18
|
var _util2 = require("../util");
|
|
20
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
20
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
@@ -39,18 +38,23 @@ const UniqueProvider = ({
|
|
|
39
38
|
});
|
|
40
39
|
|
|
41
40
|
// ========================== Register ==========================
|
|
42
|
-
|
|
41
|
+
// Store the isOpen function from the latest show call
|
|
42
|
+
const isOpenRef = React.useRef(null);
|
|
43
43
|
const delayInvoke = (0, _useDelay.default)();
|
|
44
|
-
const show = (0, _util.useEvent)(showOptions => {
|
|
44
|
+
const show = (0, _util.useEvent)((showOptions, isOpen) => {
|
|
45
|
+
// Store the isOpen function for later use in hide
|
|
46
|
+
isOpenRef.current = isOpen;
|
|
45
47
|
delayInvoke(() => {
|
|
46
|
-
if (showOptions.id !== options?.id) {
|
|
47
|
-
setPopupId(i => i + 1);
|
|
48
|
-
}
|
|
49
48
|
trigger(showOptions);
|
|
50
49
|
}, showOptions.delay);
|
|
51
50
|
});
|
|
52
51
|
const hide = delay => {
|
|
53
52
|
delayInvoke(() => {
|
|
53
|
+
// Check if we should still hide by calling the isOpen function
|
|
54
|
+
// If isOpen returns true, it means another trigger wants to keep it open
|
|
55
|
+
if (isOpenRef.current?.()) {
|
|
56
|
+
return; // Don't hide if something else wants it open
|
|
57
|
+
}
|
|
54
58
|
trigger(false);
|
|
55
59
|
// Don't clear target, currentNode, options immediately, wait until animation completes
|
|
56
60
|
}, delay);
|
|
@@ -111,10 +115,7 @@ const UniqueProvider = ({
|
|
|
111
115
|
ref: setPopupRef,
|
|
112
116
|
portal: _portal.default,
|
|
113
117
|
prefixCls: prefixCls,
|
|
114
|
-
popup:
|
|
115
|
-
prefixCls: prefixCls,
|
|
116
|
-
key: popupId
|
|
117
|
-
}, options.popup),
|
|
118
|
+
popup: options.popup,
|
|
118
119
|
className: (0, _classnames.default)(options.popupClassName, alignedClassName, `${prefixCls}-unique-controlled`),
|
|
119
120
|
style: options.popupStyle,
|
|
120
121
|
target: options.target,
|
package/lib/context.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export interface UniqueShowOptions {
|
|
|
28
28
|
getPopupClassNameFromAlign?: (align: AlignType) => string;
|
|
29
29
|
}
|
|
30
30
|
export interface UniqueContextProps {
|
|
31
|
-
show: (options: UniqueShowOptions) => void;
|
|
31
|
+
show: (options: UniqueShowOptions, isOpen: () => boolean) => void;
|
|
32
32
|
hide: (delay: number) => void;
|
|
33
33
|
}
|
|
34
34
|
export declare const UniqueContext: React.Context<UniqueContextProps>;
|
package/lib/index.js
CHANGED
|
@@ -165,6 +165,9 @@ function generateTrigger(PortalComponent = _portal.default) {
|
|
|
165
165
|
setInternalOpen(nextOpen);
|
|
166
166
|
}
|
|
167
167
|
});
|
|
168
|
+
|
|
169
|
+
// Support ref
|
|
170
|
+
const isOpen = (0, _useEvent.default)(() => mergedOpen);
|
|
168
171
|
(0, _useLayoutEffect.default)(() => {
|
|
169
172
|
setInternalOpen(popupVisible || false);
|
|
170
173
|
}, [popupVisible]);
|
|
@@ -197,9 +200,7 @@ function generateTrigger(PortalComponent = _portal.default) {
|
|
|
197
200
|
(0, _useLayoutEffect.default)(() => {
|
|
198
201
|
if (uniqueContext && unique && targetEle && !openUncontrolled && !parentContext) {
|
|
199
202
|
if (mergedOpen) {
|
|
200
|
-
|
|
201
|
-
uniqueContext.show(getUniqueOptions(0));
|
|
202
|
-
});
|
|
203
|
+
uniqueContext.show(getUniqueOptions(0), isOpen);
|
|
203
204
|
} else {
|
|
204
205
|
uniqueContext.hide(0);
|
|
205
206
|
}
|
|
@@ -238,7 +239,7 @@ function generateTrigger(PortalComponent = _portal.default) {
|
|
|
238
239
|
// If there is a parentContext, don't call uniqueContext methods
|
|
239
240
|
if (uniqueContext && unique && openUncontrolled && !parentContext) {
|
|
240
241
|
if (nextOpen) {
|
|
241
|
-
uniqueContext.show(getUniqueOptions(delay));
|
|
242
|
+
uniqueContext.show(getUniqueOptions(delay), isOpen);
|
|
242
243
|
} else {
|
|
243
244
|
uniqueContext.hide(delay);
|
|
244
245
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import type { TriggerProps } from '..';
|
|
3
|
-
export interface MotionContentProps {
|
|
4
|
-
prefixCls: string;
|
|
5
|
-
children: TriggerProps['popup'];
|
|
6
|
-
}
|
|
7
|
-
declare const MotionContent: {
|
|
8
|
-
(props: MotionContentProps): React.JSX.Element;
|
|
9
|
-
displayName: string;
|
|
10
|
-
};
|
|
11
|
-
export default MotionContent;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import CSSMotion from '@rc-component/motion';
|
|
3
|
-
import classNames from 'classnames';
|
|
4
|
-
const MotionContent = props => {
|
|
5
|
-
const {
|
|
6
|
-
prefixCls,
|
|
7
|
-
children
|
|
8
|
-
} = props;
|
|
9
|
-
const childNode = typeof children === 'function' ? children() : children;
|
|
10
|
-
|
|
11
|
-
// motion name: `${prefixCls}-motion-content-fade`, apply in index.less
|
|
12
|
-
const motionName = `${prefixCls}-motion-content-fade`;
|
|
13
|
-
return /*#__PURE__*/React.createElement(CSSMotion, {
|
|
14
|
-
motionAppear: true,
|
|
15
|
-
motionLeave: false,
|
|
16
|
-
visible: true,
|
|
17
|
-
motionName: motionName
|
|
18
|
-
}, ({
|
|
19
|
-
className: motionClassName,
|
|
20
|
-
style: motionStyle
|
|
21
|
-
}) => {
|
|
22
|
-
const cls = classNames(`${prefixCls}-motion-content`, motionClassName);
|
|
23
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
24
|
-
className: cls,
|
|
25
|
-
style: motionStyle
|
|
26
|
-
}, childNode);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
30
|
-
MotionContent.displayName = 'MotionContent';
|
|
31
|
-
}
|
|
32
|
-
export default MotionContent;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import type { TriggerProps } from '..';
|
|
3
|
-
export interface MotionContentProps {
|
|
4
|
-
prefixCls: string;
|
|
5
|
-
children: TriggerProps['popup'];
|
|
6
|
-
}
|
|
7
|
-
declare const MotionContent: {
|
|
8
|
-
(props: MotionContentProps): React.JSX.Element;
|
|
9
|
-
displayName: string;
|
|
10
|
-
};
|
|
11
|
-
export default MotionContent;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var React = _interopRequireWildcard(require("react"));
|
|
8
|
-
var _motion = _interopRequireDefault(require("@rc-component/motion"));
|
|
9
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
|
-
const MotionContent = props => {
|
|
14
|
-
const {
|
|
15
|
-
prefixCls,
|
|
16
|
-
children
|
|
17
|
-
} = props;
|
|
18
|
-
const childNode = typeof children === 'function' ? children() : children;
|
|
19
|
-
|
|
20
|
-
// motion name: `${prefixCls}-motion-content-fade`, apply in index.less
|
|
21
|
-
const motionName = `${prefixCls}-motion-content-fade`;
|
|
22
|
-
return /*#__PURE__*/React.createElement(_motion.default, {
|
|
23
|
-
motionAppear: true,
|
|
24
|
-
motionLeave: false,
|
|
25
|
-
visible: true,
|
|
26
|
-
motionName: motionName
|
|
27
|
-
}, ({
|
|
28
|
-
className: motionClassName,
|
|
29
|
-
style: motionStyle
|
|
30
|
-
}) => {
|
|
31
|
-
const cls = (0, _classnames.default)(`${prefixCls}-motion-content`, motionClassName);
|
|
32
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
33
|
-
className: cls,
|
|
34
|
-
style: motionStyle
|
|
35
|
-
}, childNode);
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
39
|
-
MotionContent.displayName = 'MotionContent';
|
|
40
|
-
}
|
|
41
|
-
var _default = exports.default = MotionContent;
|