@rc-component/trigger 3.7.2 → 3.8.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.d.ts +2 -0
- package/es/Popup/index.js +3 -1
- package/es/UniqueProvider/index.js +1 -0
- package/es/context.d.ts +2 -0
- package/es/index.js +19 -14
- package/lib/Popup/index.d.ts +2 -0
- package/lib/Popup/index.js +3 -1
- package/lib/UniqueProvider/index.js +1 -0
- package/lib/context.d.ts +2 -0
- package/lib/index.js +19 -14
- package/package.json +2 -2
package/es/Popup/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type ResizeObserverProps } from '@rc-component/resize-observer';
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import type { TriggerProps } from '../';
|
|
5
5
|
import type { AlignType, ArrowPos, ArrowTypeOuter } from '../interface';
|
|
6
|
+
import type { PortalProps } from '@rc-component/portal';
|
|
6
7
|
export interface MobileConfig {
|
|
7
8
|
mask?: boolean;
|
|
8
9
|
/** Set popup motion. You can ref `rc-motion` for more info. */
|
|
@@ -11,6 +12,7 @@ export interface MobileConfig {
|
|
|
11
12
|
maskMotion?: CSSMotionProps;
|
|
12
13
|
}
|
|
13
14
|
export interface PopupProps {
|
|
15
|
+
onEsc?: PortalProps['onEsc'];
|
|
14
16
|
prefixCls: string;
|
|
15
17
|
className?: string;
|
|
16
18
|
style?: React.CSSProperties;
|
package/es/Popup/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import useOffsetStyle from "../hooks/useOffsetStyle";
|
|
|
12
12
|
import { useEvent } from '@rc-component/util';
|
|
13
13
|
const Popup = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
14
14
|
const {
|
|
15
|
+
onEsc,
|
|
15
16
|
popup,
|
|
16
17
|
className,
|
|
17
18
|
prefixCls,
|
|
@@ -120,7 +121,8 @@ const Popup = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
120
121
|
return /*#__PURE__*/React.createElement(Portal, {
|
|
121
122
|
open: forceRender || isNodeVisible,
|
|
122
123
|
getContainer: getPopupContainer && (() => getPopupContainer(target)),
|
|
123
|
-
autoDestroy: autoDestroy
|
|
124
|
+
autoDestroy: autoDestroy,
|
|
125
|
+
onEsc: onEsc
|
|
124
126
|
}, /*#__PURE__*/React.createElement(Mask, {
|
|
125
127
|
prefixCls: prefixCls,
|
|
126
128
|
open: open,
|
|
@@ -119,6 +119,7 @@ const UniqueProvider = ({
|
|
|
119
119
|
}, /*#__PURE__*/React.createElement(Popup, {
|
|
120
120
|
ref: setPopupRef,
|
|
121
121
|
portal: Portal,
|
|
122
|
+
onEsc: mergedOptions.onEsc,
|
|
122
123
|
prefixCls: prefixCls,
|
|
123
124
|
popup: mergedOptions.popup,
|
|
124
125
|
className: clsx(mergedOptions.popupClassName, alignedClassName, `${prefixCls}-unique-controlled`),
|
package/es/context.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import type { CSSMotionProps } from '@rc-component/motion';
|
|
3
|
+
import type { PortalProps } from '@rc-component/portal';
|
|
3
4
|
import type { TriggerProps } from './index';
|
|
4
5
|
import type { AlignType, ArrowTypeOuter, BuildInPlacements } from './interface';
|
|
5
6
|
export interface TriggerContextProps {
|
|
@@ -28,6 +29,7 @@ export interface UniqueShowOptions {
|
|
|
28
29
|
arrow?: ArrowTypeOuter;
|
|
29
30
|
getPopupContainer?: TriggerProps['getPopupContainer'];
|
|
30
31
|
getPopupClassNameFromAlign?: (align: AlignType) => string;
|
|
32
|
+
onEsc?: PortalProps['onEsc'];
|
|
31
33
|
}
|
|
32
34
|
export interface UniqueContextProps {
|
|
33
35
|
show: (options: UniqueShowOptions, isOpen: () => boolean) => void;
|
package/es/index.js
CHANGED
|
@@ -17,6 +17,7 @@ import useWinClick from "./hooks/useWinClick";
|
|
|
17
17
|
import { getAlignPopupClassName } from "./util";
|
|
18
18
|
import UniqueProvider from "./UniqueProvider";
|
|
19
19
|
import { useControlledState } from '@rc-component/util';
|
|
20
|
+
import { flushSync } from 'react-dom';
|
|
20
21
|
export { UniqueProvider };
|
|
21
22
|
|
|
22
23
|
// Removed Props List
|
|
@@ -175,7 +176,8 @@ export function generateTrigger(PortalComponent = Portal) {
|
|
|
175
176
|
arrow: innerArrow,
|
|
176
177
|
getPopupContainer,
|
|
177
178
|
getPopupClassNameFromAlign,
|
|
178
|
-
id
|
|
179
|
+
id,
|
|
180
|
+
onEsc
|
|
179
181
|
}));
|
|
180
182
|
|
|
181
183
|
// Handle controlled state changes for UniqueProvider
|
|
@@ -192,19 +194,14 @@ export function generateTrigger(PortalComponent = Portal) {
|
|
|
192
194
|
}, [mergedOpen, targetEle]);
|
|
193
195
|
const openRef = React.useRef(mergedOpen);
|
|
194
196
|
openRef.current = mergedOpen;
|
|
195
|
-
const lastTriggerRef = React.useRef([]);
|
|
196
|
-
lastTriggerRef.current = [];
|
|
197
197
|
const internalTriggerOpen = useEvent(nextOpen => {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
onOpenChange?.(nextOpen);
|
|
206
|
-
onPopupVisibleChange?.(nextOpen);
|
|
207
|
-
}
|
|
198
|
+
flushSync(() => {
|
|
199
|
+
if (mergedOpen !== nextOpen) {
|
|
200
|
+
setInternalOpen(nextOpen);
|
|
201
|
+
onOpenChange?.(nextOpen);
|
|
202
|
+
onPopupVisibleChange?.(nextOpen);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
208
205
|
});
|
|
209
206
|
|
|
210
207
|
// Trigger for delay
|
|
@@ -233,6 +230,13 @@ export function generateTrigger(PortalComponent = Portal) {
|
|
|
233
230
|
internalTriggerOpen(nextOpen);
|
|
234
231
|
}, delay);
|
|
235
232
|
};
|
|
233
|
+
function onEsc({
|
|
234
|
+
top
|
|
235
|
+
}) {
|
|
236
|
+
if (top) {
|
|
237
|
+
triggerOpen(false);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
236
240
|
|
|
237
241
|
// ========================== Motion ============================
|
|
238
242
|
const [inMotion, setInMotion] = React.useState(false);
|
|
@@ -518,7 +522,8 @@ export function generateTrigger(PortalComponent = Portal) {
|
|
|
518
522
|
,
|
|
519
523
|
forceRender: forceRender,
|
|
520
524
|
autoDestroy: mergedAutoDestroy,
|
|
521
|
-
getPopupContainer: getPopupContainer
|
|
525
|
+
getPopupContainer: getPopupContainer,
|
|
526
|
+
onEsc: onEsc
|
|
522
527
|
// Arrow
|
|
523
528
|
,
|
|
524
529
|
align: alignInfo,
|
package/lib/Popup/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type ResizeObserverProps } from '@rc-component/resize-observer';
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import type { TriggerProps } from '../';
|
|
5
5
|
import type { AlignType, ArrowPos, ArrowTypeOuter } from '../interface';
|
|
6
|
+
import type { PortalProps } from '@rc-component/portal';
|
|
6
7
|
export interface MobileConfig {
|
|
7
8
|
mask?: boolean;
|
|
8
9
|
/** Set popup motion. You can ref `rc-motion` for more info. */
|
|
@@ -11,6 +12,7 @@ export interface MobileConfig {
|
|
|
11
12
|
maskMotion?: CSSMotionProps;
|
|
12
13
|
}
|
|
13
14
|
export interface PopupProps {
|
|
15
|
+
onEsc?: PortalProps['onEsc'];
|
|
14
16
|
prefixCls: string;
|
|
15
17
|
className?: string;
|
|
16
18
|
style?: React.CSSProperties;
|
package/lib/Popup/index.js
CHANGED
|
@@ -21,6 +21,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
21
21
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
22
22
|
const Popup = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
23
23
|
const {
|
|
24
|
+
onEsc,
|
|
24
25
|
popup,
|
|
25
26
|
className,
|
|
26
27
|
prefixCls,
|
|
@@ -129,7 +130,8 @@ const Popup = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
129
130
|
return /*#__PURE__*/React.createElement(Portal, {
|
|
130
131
|
open: forceRender || isNodeVisible,
|
|
131
132
|
getContainer: getPopupContainer && (() => getPopupContainer(target)),
|
|
132
|
-
autoDestroy: autoDestroy
|
|
133
|
+
autoDestroy: autoDestroy,
|
|
134
|
+
onEsc: onEsc
|
|
133
135
|
}, /*#__PURE__*/React.createElement(_Mask.default, {
|
|
134
136
|
prefixCls: prefixCls,
|
|
135
137
|
open: open,
|
|
@@ -128,6 +128,7 @@ const UniqueProvider = ({
|
|
|
128
128
|
}, /*#__PURE__*/React.createElement(_Popup.default, {
|
|
129
129
|
ref: setPopupRef,
|
|
130
130
|
portal: _portal.default,
|
|
131
|
+
onEsc: mergedOptions.onEsc,
|
|
131
132
|
prefixCls: prefixCls,
|
|
132
133
|
popup: mergedOptions.popup,
|
|
133
134
|
className: (0, _clsx.clsx)(mergedOptions.popupClassName, alignedClassName, `${prefixCls}-unique-controlled`),
|
package/lib/context.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import type { CSSMotionProps } from '@rc-component/motion';
|
|
3
|
+
import type { PortalProps } from '@rc-component/portal';
|
|
3
4
|
import type { TriggerProps } from './index';
|
|
4
5
|
import type { AlignType, ArrowTypeOuter, BuildInPlacements } from './interface';
|
|
5
6
|
export interface TriggerContextProps {
|
|
@@ -28,6 +29,7 @@ export interface UniqueShowOptions {
|
|
|
28
29
|
arrow?: ArrowTypeOuter;
|
|
29
30
|
getPopupContainer?: TriggerProps['getPopupContainer'];
|
|
30
31
|
getPopupClassNameFromAlign?: (align: AlignType) => string;
|
|
32
|
+
onEsc?: PortalProps['onEsc'];
|
|
31
33
|
}
|
|
32
34
|
export interface UniqueContextProps {
|
|
33
35
|
show: (options: UniqueShowOptions, isOpen: () => boolean) => void;
|
package/lib/index.js
CHANGED
|
@@ -30,6 +30,7 @@ var _useWinClick = _interopRequireDefault(require("./hooks/useWinClick"));
|
|
|
30
30
|
var _util = require("./util");
|
|
31
31
|
var _UniqueProvider = _interopRequireDefault(require("./UniqueProvider"));
|
|
32
32
|
var _util2 = require("@rc-component/util");
|
|
33
|
+
var _reactDom = require("react-dom");
|
|
33
34
|
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); }
|
|
34
35
|
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; }
|
|
35
36
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -189,7 +190,8 @@ function generateTrigger(PortalComponent = _portal.default) {
|
|
|
189
190
|
arrow: innerArrow,
|
|
190
191
|
getPopupContainer,
|
|
191
192
|
getPopupClassNameFromAlign,
|
|
192
|
-
id
|
|
193
|
+
id,
|
|
194
|
+
onEsc
|
|
193
195
|
}));
|
|
194
196
|
|
|
195
197
|
// Handle controlled state changes for UniqueProvider
|
|
@@ -206,19 +208,14 @@ function generateTrigger(PortalComponent = _portal.default) {
|
|
|
206
208
|
}, [mergedOpen, targetEle]);
|
|
207
209
|
const openRef = React.useRef(mergedOpen);
|
|
208
210
|
openRef.current = mergedOpen;
|
|
209
|
-
const lastTriggerRef = React.useRef([]);
|
|
210
|
-
lastTriggerRef.current = [];
|
|
211
211
|
const internalTriggerOpen = (0, _useEvent.default)(nextOpen => {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
onOpenChange?.(nextOpen);
|
|
220
|
-
onPopupVisibleChange?.(nextOpen);
|
|
221
|
-
}
|
|
212
|
+
(0, _reactDom.flushSync)(() => {
|
|
213
|
+
if (mergedOpen !== nextOpen) {
|
|
214
|
+
setInternalOpen(nextOpen);
|
|
215
|
+
onOpenChange?.(nextOpen);
|
|
216
|
+
onPopupVisibleChange?.(nextOpen);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
222
219
|
});
|
|
223
220
|
|
|
224
221
|
// Trigger for delay
|
|
@@ -247,6 +244,13 @@ function generateTrigger(PortalComponent = _portal.default) {
|
|
|
247
244
|
internalTriggerOpen(nextOpen);
|
|
248
245
|
}, delay);
|
|
249
246
|
};
|
|
247
|
+
function onEsc({
|
|
248
|
+
top
|
|
249
|
+
}) {
|
|
250
|
+
if (top) {
|
|
251
|
+
triggerOpen(false);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
250
254
|
|
|
251
255
|
// ========================== Motion ============================
|
|
252
256
|
const [inMotion, setInMotion] = React.useState(false);
|
|
@@ -532,7 +536,8 @@ function generateTrigger(PortalComponent = _portal.default) {
|
|
|
532
536
|
,
|
|
533
537
|
forceRender: forceRender,
|
|
534
538
|
autoDestroy: mergedAutoDestroy,
|
|
535
|
-
getPopupContainer: getPopupContainer
|
|
539
|
+
getPopupContainer: getPopupContainer,
|
|
540
|
+
onEsc: onEsc
|
|
536
541
|
// Arrow
|
|
537
542
|
,
|
|
538
543
|
align: alignInfo,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rc-component/trigger",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.1",
|
|
4
4
|
"description": "base abstract trigger component for react",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=8.x"
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@rc-component/motion": "^1.1.4",
|
|
45
|
-
"@rc-component/portal": "^2.
|
|
45
|
+
"@rc-component/portal": "^2.2.0",
|
|
46
46
|
"@rc-component/resize-observer": "^1.0.0",
|
|
47
47
|
"@rc-component/util": "^1.2.1",
|
|
48
48
|
"clsx": "^2.1.1"
|