1 | "use strict";
|
2 | "use client";
|
3 |
|
4 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
5 | exports.__esModule = true;
|
6 | exports.default = void 0;
|
7 | var _contains = _interopRequireDefault(require("dom-helpers/contains"));
|
8 | var React = _interopRequireWildcard(require("react"));
|
9 | var _useTimeout = _interopRequireDefault(require("@restart/hooks/useTimeout"));
|
10 | var _warning = _interopRequireDefault(require("warning"));
|
11 | var _uncontrollable = require("uncontrollable");
|
12 | var _useMergedRefs = _interopRequireDefault(require("@restart/hooks/useMergedRefs"));
|
13 | var _Overlay = _interopRequireDefault(require("./Overlay"));
|
14 | var _safeFindDOMNode = _interopRequireDefault(require("./safeFindDOMNode"));
|
15 | var _jsxRuntime = require("react/jsx-runtime");
|
16 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
17 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
18 | function normalizeDelay(delay) {
|
19 | return delay && typeof delay === 'object' ? delay : {
|
20 | show: delay,
|
21 | hide: delay
|
22 | };
|
23 | }
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | function handleMouseOverOut(
|
30 | // eslint-disable-next-line @typescript-eslint/no-shadow
|
31 | handler, args, relatedNative) {
|
32 | const [e] = args;
|
33 | const target = e.currentTarget;
|
34 | const related = e.relatedTarget || e.nativeEvent[relatedNative];
|
35 | if ((!related || related !== target) && !(0, _contains.default)(target, related)) {
|
36 | handler(...args);
|
37 | }
|
38 | }
|
39 | function OverlayTrigger({
|
40 | trigger = ['hover', 'focus'],
|
41 | overlay,
|
42 | children,
|
43 | popperConfig = {},
|
44 | show: propsShow,
|
45 | defaultShow = false,
|
46 | onToggle,
|
47 | delay: propsDelay,
|
48 | placement,
|
49 | flip = placement && placement.indexOf('auto') !== -1,
|
50 | ...props
|
51 | }) {
|
52 | const triggerNodeRef = (0, React.useRef)(null);
|
53 | const mergedRef = (0, _useMergedRefs.default)(triggerNodeRef, children.ref);
|
54 | const timeout = (0, _useTimeout.default)();
|
55 | const hoverStateRef = (0, React.useRef)('');
|
56 | const [show, setShow] = (0, _uncontrollable.useUncontrolledProp)(propsShow, defaultShow, onToggle);
|
57 | const delay = normalizeDelay(propsDelay);
|
58 | const {
|
59 | onFocus,
|
60 | onBlur,
|
61 | onClick
|
62 | } = typeof children !== 'function' ? React.Children.only(children).props : {};
|
63 | const attachRef = r => {
|
64 | mergedRef((0, _safeFindDOMNode.default)(r));
|
65 | };
|
66 | const handleShow = (0, React.useCallback)(() => {
|
67 | timeout.clear();
|
68 | hoverStateRef.current = 'show';
|
69 | if (!delay.show) {
|
70 | setShow(true);
|
71 | return;
|
72 | }
|
73 | timeout.set(() => {
|
74 | if (hoverStateRef.current === 'show') setShow(true);
|
75 | }, delay.show);
|
76 | }, [delay.show, setShow, timeout]);
|
77 | const handleHide = (0, React.useCallback)(() => {
|
78 | timeout.clear();
|
79 | hoverStateRef.current = 'hide';
|
80 | if (!delay.hide) {
|
81 | setShow(false);
|
82 | return;
|
83 | }
|
84 | timeout.set(() => {
|
85 | if (hoverStateRef.current === 'hide') setShow(false);
|
86 | }, delay.hide);
|
87 | }, [delay.hide, setShow, timeout]);
|
88 | const handleFocus = (0, React.useCallback)((...args) => {
|
89 | handleShow();
|
90 | onFocus == null ? void 0 : onFocus(...args);
|
91 | }, [handleShow, onFocus]);
|
92 | const handleBlur = (0, React.useCallback)((...args) => {
|
93 | handleHide();
|
94 | onBlur == null ? void 0 : onBlur(...args);
|
95 | }, [handleHide, onBlur]);
|
96 | const handleClick = (0, React.useCallback)((...args) => {
|
97 | setShow(!show);
|
98 | onClick == null ? void 0 : onClick(...args);
|
99 | }, [onClick, setShow, show]);
|
100 | const handleMouseOver = (0, React.useCallback)((...args) => {
|
101 | handleMouseOverOut(handleShow, args, 'fromElement');
|
102 | }, [handleShow]);
|
103 | const handleMouseOut = (0, React.useCallback)((...args) => {
|
104 | handleMouseOverOut(handleHide, args, 'toElement');
|
105 | }, [handleHide]);
|
106 | const triggers = trigger == null ? [] : [].concat(trigger);
|
107 | const triggerProps = {
|
108 | ref: attachRef
|
109 | };
|
110 | if (triggers.indexOf('click') !== -1) {
|
111 | triggerProps.onClick = handleClick;
|
112 | }
|
113 | if (triggers.indexOf('focus') !== -1) {
|
114 | triggerProps.onFocus = handleFocus;
|
115 | triggerProps.onBlur = handleBlur;
|
116 | }
|
117 | if (triggers.indexOf('hover') !== -1) {
|
118 | process.env.NODE_ENV !== "production" ? (0, _warning.default)(triggers.length > 1, '[react-bootstrap] Specifying only the `"hover"` trigger limits the visibility of the overlay to just mouse users. Consider also including the `"focus"` trigger so that touch and keyboard only users can see the overlay as well.') : void 0;
|
119 | triggerProps.onMouseOver = handleMouseOver;
|
120 | triggerProps.onMouseOut = handleMouseOut;
|
121 | }
|
122 | return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
123 | children: [typeof children === 'function' ? children(triggerProps) : (0, React.cloneElement)(children, triggerProps), (0, _jsxRuntime.jsx)(_Overlay.default, {
|
124 | ...props,
|
125 | show: show,
|
126 | onHide: handleHide,
|
127 | flip: flip,
|
128 | placement: placement,
|
129 | popperConfig: popperConfig,
|
130 | target: triggerNodeRef.current,
|
131 | children: overlay
|
132 | })]
|
133 | });
|
134 | }
|
135 | var _default = OverlayTrigger;
|
136 | exports.default = _default;
|
137 | module.exports = exports.default; |
\ | No newline at end of file |