react-tooltip 5.10.2-beta.4 → 5.10.2-beta.994.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/dist/react-tooltip.cjs.js +941 -0
- package/dist/react-tooltip.cjs.js.map +7 -0
- package/dist/react-tooltip.cjs.min.js +2 -0
- package/dist/react-tooltip.cjs.min.js.map +7 -0
- package/dist/react-tooltip.css +71 -0
- package/dist/react-tooltip.css.map +7 -0
- package/dist/react-tooltip.esm.js +914 -0
- package/dist/react-tooltip.esm.js.map +7 -0
- package/dist/react-tooltip.esm.min.js +2 -0
- package/dist/react-tooltip.esm.min.js.map +7 -0
- package/dist/react-tooltip.iife.js +936 -0
- package/dist/react-tooltip.iife.js.map +7 -0
- package/dist/react-tooltip.iife.min.js +2 -0
- package/dist/react-tooltip.iife.min.js.map +7 -0
- package/dist/react-tooltip.min.js +2 -0
- package/dist/react-tooltip.min.js.map +7 -0
- package/jest.config.ts +1 -1
- package/package.json +4 -14
- package/tsconfig.json +3 -4
- package/dist/react-tooltip.cjs +0 -843
- package/dist/react-tooltip.cjs.map +0 -1
- package/dist/react-tooltip.min.cjs +0 -2
- package/dist/react-tooltip.min.cjs.map +0 -1
- package/dist/react-tooltip.min.css +0 -1
- package/dist/react-tooltip.min.mjs +0 -2
- package/dist/react-tooltip.min.mjs.map +0 -1
- package/dist/react-tooltip.mjs +0 -832
- package/dist/react-tooltip.mjs.map +0 -1
- package/dist/react-tooltip.umd.js +0 -845
- package/dist/react-tooltip.umd.js.map +0 -1
- package/dist/react-tooltip.umd.min.js +0 -2
- package/dist/react-tooltip.umd.min.js.map +0 -1
|
@@ -0,0 +1,941 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.tsx
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
Tooltip: () => TooltipController_default,
|
|
34
|
+
TooltipProvider: () => TooltipProvider_default,
|
|
35
|
+
TooltipWrapper: () => TooltipWrapper_default
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(src_exports);
|
|
38
|
+
|
|
39
|
+
// src/components/TooltipController/TooltipController.tsx
|
|
40
|
+
var import_react5 = require("react");
|
|
41
|
+
|
|
42
|
+
// src/components/Tooltip/Tooltip.tsx
|
|
43
|
+
var import_react4 = require("react");
|
|
44
|
+
var import_classnames2 = __toESM(require("classnames"));
|
|
45
|
+
|
|
46
|
+
// src/utils/debounce.ts
|
|
47
|
+
var debounce = (func, wait, immediate) => {
|
|
48
|
+
let timeout = null;
|
|
49
|
+
return function debounced(...args) {
|
|
50
|
+
const later = () => {
|
|
51
|
+
timeout = null;
|
|
52
|
+
if (!immediate) {
|
|
53
|
+
func.apply(this, args);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
if (timeout) {
|
|
57
|
+
clearTimeout(timeout);
|
|
58
|
+
}
|
|
59
|
+
timeout = setTimeout(later, wait);
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
var debounce_default = debounce;
|
|
63
|
+
|
|
64
|
+
// src/components/TooltipProvider/TooltipProvider.tsx
|
|
65
|
+
var import_react = require("react");
|
|
66
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
67
|
+
var DEFAULT_TOOLTIP_ID = "DEFAULT_TOOLTIP_ID";
|
|
68
|
+
var DEFAULT_CONTEXT_DATA = {
|
|
69
|
+
anchorRefs: /* @__PURE__ */ new Set(),
|
|
70
|
+
activeAnchor: { current: null },
|
|
71
|
+
attach: () => {
|
|
72
|
+
},
|
|
73
|
+
detach: () => {
|
|
74
|
+
},
|
|
75
|
+
setActiveAnchor: () => {
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var DEFAULT_CONTEXT_DATA_WRAPPER = {
|
|
79
|
+
getTooltipData: () => DEFAULT_CONTEXT_DATA
|
|
80
|
+
};
|
|
81
|
+
var TooltipContext = (0, import_react.createContext)(DEFAULT_CONTEXT_DATA_WRAPPER);
|
|
82
|
+
var TooltipProvider = ({ children }) => {
|
|
83
|
+
const [anchorRefMap, setAnchorRefMap] = (0, import_react.useState)({
|
|
84
|
+
[DEFAULT_TOOLTIP_ID]: /* @__PURE__ */ new Set()
|
|
85
|
+
});
|
|
86
|
+
const [activeAnchorMap, setActiveAnchorMap] = (0, import_react.useState)({
|
|
87
|
+
[DEFAULT_TOOLTIP_ID]: { current: null }
|
|
88
|
+
});
|
|
89
|
+
const attach = (tooltipId, ...refs) => {
|
|
90
|
+
setAnchorRefMap((oldMap) => {
|
|
91
|
+
var _a;
|
|
92
|
+
const tooltipRefs = (_a = oldMap[tooltipId]) != null ? _a : /* @__PURE__ */ new Set();
|
|
93
|
+
refs.forEach((ref) => tooltipRefs.add(ref));
|
|
94
|
+
return { ...oldMap, [tooltipId]: new Set(tooltipRefs) };
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
const detach = (tooltipId, ...refs) => {
|
|
98
|
+
setAnchorRefMap((oldMap) => {
|
|
99
|
+
const tooltipRefs = oldMap[tooltipId];
|
|
100
|
+
if (!tooltipRefs) {
|
|
101
|
+
return oldMap;
|
|
102
|
+
}
|
|
103
|
+
refs.forEach((ref) => tooltipRefs.delete(ref));
|
|
104
|
+
return { ...oldMap };
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
const setActiveAnchor = (tooltipId, ref) => {
|
|
108
|
+
setActiveAnchorMap((oldMap) => {
|
|
109
|
+
var _a;
|
|
110
|
+
if (((_a = oldMap[tooltipId]) == null ? void 0 : _a.current) === ref.current) {
|
|
111
|
+
return oldMap;
|
|
112
|
+
}
|
|
113
|
+
return { ...oldMap, [tooltipId]: ref };
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
const getTooltipData = (0, import_react.useCallback)(
|
|
117
|
+
(tooltipId = DEFAULT_TOOLTIP_ID) => {
|
|
118
|
+
var _a, _b;
|
|
119
|
+
return {
|
|
120
|
+
anchorRefs: (_a = anchorRefMap[tooltipId]) != null ? _a : /* @__PURE__ */ new Set(),
|
|
121
|
+
activeAnchor: (_b = activeAnchorMap[tooltipId]) != null ? _b : { current: null },
|
|
122
|
+
attach: (...refs) => attach(tooltipId, ...refs),
|
|
123
|
+
detach: (...refs) => detach(tooltipId, ...refs),
|
|
124
|
+
setActiveAnchor: (ref) => setActiveAnchor(tooltipId, ref)
|
|
125
|
+
};
|
|
126
|
+
},
|
|
127
|
+
[anchorRefMap, activeAnchorMap, attach, detach]
|
|
128
|
+
);
|
|
129
|
+
const context = (0, import_react.useMemo)(() => {
|
|
130
|
+
return {
|
|
131
|
+
getTooltipData
|
|
132
|
+
};
|
|
133
|
+
}, [getTooltipData]);
|
|
134
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContext.Provider, { value: context, children });
|
|
135
|
+
};
|
|
136
|
+
function useTooltip(tooltipId = DEFAULT_TOOLTIP_ID) {
|
|
137
|
+
return (0, import_react.useContext)(TooltipContext).getTooltipData(tooltipId);
|
|
138
|
+
}
|
|
139
|
+
var TooltipProvider_default = TooltipProvider;
|
|
140
|
+
|
|
141
|
+
// src/components/TooltipProvider/TooltipWrapper.tsx
|
|
142
|
+
var import_react2 = require("react");
|
|
143
|
+
var import_classnames = __toESM(require("classnames"));
|
|
144
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
145
|
+
var TooltipWrapper = ({
|
|
146
|
+
tooltipId,
|
|
147
|
+
children,
|
|
148
|
+
className,
|
|
149
|
+
place,
|
|
150
|
+
content,
|
|
151
|
+
html,
|
|
152
|
+
variant,
|
|
153
|
+
offset: offset2,
|
|
154
|
+
wrapper,
|
|
155
|
+
events,
|
|
156
|
+
positionStrategy,
|
|
157
|
+
delayShow,
|
|
158
|
+
delayHide
|
|
159
|
+
}) => {
|
|
160
|
+
const { attach, detach } = useTooltip(tooltipId);
|
|
161
|
+
const anchorRef = (0, import_react2.useRef)(null);
|
|
162
|
+
(0, import_react2.useEffect)(() => {
|
|
163
|
+
attach(anchorRef);
|
|
164
|
+
return () => {
|
|
165
|
+
detach(anchorRef);
|
|
166
|
+
};
|
|
167
|
+
}, []);
|
|
168
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
169
|
+
"span",
|
|
170
|
+
{
|
|
171
|
+
ref: anchorRef,
|
|
172
|
+
className: (0, import_classnames.default)("react-tooltip-wrapper", className),
|
|
173
|
+
"data-tooltip-place": place,
|
|
174
|
+
"data-tooltip-content": content,
|
|
175
|
+
"data-tooltip-html": html,
|
|
176
|
+
"data-tooltip-variant": variant,
|
|
177
|
+
"data-tooltip-offset": offset2,
|
|
178
|
+
"data-tooltip-wrapper": wrapper,
|
|
179
|
+
"data-tooltip-events": events,
|
|
180
|
+
"data-tooltip-position-strategy": positionStrategy,
|
|
181
|
+
"data-tooltip-delay-show": delayShow,
|
|
182
|
+
"data-tooltip-delay-hide": delayHide,
|
|
183
|
+
children
|
|
184
|
+
}
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
var TooltipWrapper_default = TooltipWrapper;
|
|
188
|
+
|
|
189
|
+
// src/utils/use-isomorphic-layout-effect.ts
|
|
190
|
+
var import_react3 = require("react");
|
|
191
|
+
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? import_react3.useLayoutEffect : import_react3.useEffect;
|
|
192
|
+
var use_isomorphic_layout_effect_default = useIsomorphicLayoutEffect;
|
|
193
|
+
|
|
194
|
+
// src/utils/compute-positions.ts
|
|
195
|
+
var import_dom = require("@floating-ui/dom");
|
|
196
|
+
var computeTooltipPosition = async ({
|
|
197
|
+
elementReference = null,
|
|
198
|
+
tooltipReference = null,
|
|
199
|
+
tooltipArrowReference = null,
|
|
200
|
+
place = "top",
|
|
201
|
+
offset: offsetValue = 10,
|
|
202
|
+
strategy = "absolute",
|
|
203
|
+
middlewares = [(0, import_dom.offset)(Number(offsetValue)), (0, import_dom.flip)(), (0, import_dom.shift)({ padding: 5 })]
|
|
204
|
+
}) => {
|
|
205
|
+
if (!elementReference) {
|
|
206
|
+
return { tooltipStyles: {}, tooltipArrowStyles: {}, place };
|
|
207
|
+
}
|
|
208
|
+
if (tooltipReference === null) {
|
|
209
|
+
return { tooltipStyles: {}, tooltipArrowStyles: {}, place };
|
|
210
|
+
}
|
|
211
|
+
const middleware = middlewares;
|
|
212
|
+
if (tooltipArrowReference) {
|
|
213
|
+
middleware.push((0, import_dom.arrow)({ element: tooltipArrowReference, padding: 5 }));
|
|
214
|
+
return (0, import_dom.computePosition)(elementReference, tooltipReference, {
|
|
215
|
+
placement: place,
|
|
216
|
+
strategy,
|
|
217
|
+
middleware
|
|
218
|
+
}).then(({ x, y, placement, middlewareData }) => {
|
|
219
|
+
var _a, _b;
|
|
220
|
+
const styles = { left: `${x}px`, top: `${y}px` };
|
|
221
|
+
const { x: arrowX, y: arrowY } = (_a = middlewareData.arrow) != null ? _a : { x: 0, y: 0 };
|
|
222
|
+
const staticSide = (_b = {
|
|
223
|
+
top: "bottom",
|
|
224
|
+
right: "left",
|
|
225
|
+
bottom: "top",
|
|
226
|
+
left: "right"
|
|
227
|
+
}[placement.split("-")[0]]) != null ? _b : "bottom";
|
|
228
|
+
const arrowStyle = {
|
|
229
|
+
left: arrowX != null ? `${arrowX}px` : "",
|
|
230
|
+
top: arrowY != null ? `${arrowY}px` : "",
|
|
231
|
+
right: "",
|
|
232
|
+
bottom: "",
|
|
233
|
+
[staticSide]: "-4px"
|
|
234
|
+
};
|
|
235
|
+
return { tooltipStyles: styles, tooltipArrowStyles: arrowStyle, place: placement };
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
return (0, import_dom.computePosition)(elementReference, tooltipReference, {
|
|
239
|
+
placement: "bottom",
|
|
240
|
+
strategy,
|
|
241
|
+
middleware
|
|
242
|
+
}).then(({ x, y, placement }) => {
|
|
243
|
+
const styles = { left: `${x}px`, top: `${y}px` };
|
|
244
|
+
return { tooltipStyles: styles, tooltipArrowStyles: {}, place: placement };
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
// esbuild-css-modules-plugin-namespace:./src/components/Tooltip/styles.module.css?esbuild-css-modules-plugin-building
|
|
249
|
+
var styles_module_default = { "arrow": "react-tooltip__arrow_KtSkBq", "clickable": "react-tooltip__clickable_KtSkBq", "dark": "react-tooltip__dark_KtSkBq", "error": "react-tooltip__error_KtSkBq", "fixed": "react-tooltip__fixed_KtSkBq", "info": "react-tooltip__info_KtSkBq", "light": "react-tooltip__light_KtSkBq", "noArrow": "react-tooltip__no-arrow_KtSkBq", "show": "react-tooltip__show_KtSkBq", "success": "react-tooltip__success_KtSkBq", "tooltip": "react-tooltip__tooltip_KtSkBq", "warning": "react-tooltip__warning_KtSkBq" };
|
|
250
|
+
|
|
251
|
+
// src/components/Tooltip/Tooltip.tsx
|
|
252
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
253
|
+
var Tooltip = ({
|
|
254
|
+
// props
|
|
255
|
+
id,
|
|
256
|
+
className,
|
|
257
|
+
classNameArrow,
|
|
258
|
+
variant = "dark",
|
|
259
|
+
anchorId,
|
|
260
|
+
anchorSelect,
|
|
261
|
+
place = "top",
|
|
262
|
+
offset: offset2 = 10,
|
|
263
|
+
events = ["hover"],
|
|
264
|
+
openOnClick = false,
|
|
265
|
+
positionStrategy = "absolute",
|
|
266
|
+
middlewares,
|
|
267
|
+
wrapper: WrapperElement,
|
|
268
|
+
delayShow = 0,
|
|
269
|
+
delayHide = 0,
|
|
270
|
+
float = false,
|
|
271
|
+
noArrow = false,
|
|
272
|
+
clickable = false,
|
|
273
|
+
closeOnEsc = false,
|
|
274
|
+
style: externalStyles,
|
|
275
|
+
position,
|
|
276
|
+
afterShow,
|
|
277
|
+
afterHide,
|
|
278
|
+
// props handled by controller
|
|
279
|
+
content,
|
|
280
|
+
contentWrapperRef,
|
|
281
|
+
isOpen,
|
|
282
|
+
setIsOpen,
|
|
283
|
+
activeAnchor,
|
|
284
|
+
setActiveAnchor
|
|
285
|
+
}) => {
|
|
286
|
+
const tooltipRef = (0, import_react4.useRef)(null);
|
|
287
|
+
const tooltipArrowRef = (0, import_react4.useRef)(null);
|
|
288
|
+
const tooltipShowDelayTimerRef = (0, import_react4.useRef)(null);
|
|
289
|
+
const tooltipHideDelayTimerRef = (0, import_react4.useRef)(null);
|
|
290
|
+
const [actualPlacement, setActualPlacement] = (0, import_react4.useState)(place);
|
|
291
|
+
const [inlineStyles, setInlineStyles] = (0, import_react4.useState)({});
|
|
292
|
+
const [inlineArrowStyles, setInlineArrowStyles] = (0, import_react4.useState)({});
|
|
293
|
+
const [show, setShow] = (0, import_react4.useState)(false);
|
|
294
|
+
const [rendered, setRendered] = (0, import_react4.useState)(false);
|
|
295
|
+
const wasShowing = (0, import_react4.useRef)(false);
|
|
296
|
+
const lastFloatPosition = (0, import_react4.useRef)(null);
|
|
297
|
+
const { anchorRefs, setActiveAnchor: setProviderActiveAnchor } = useTooltip(id);
|
|
298
|
+
const hoveringTooltip = (0, import_react4.useRef)(false);
|
|
299
|
+
const [anchorsBySelect, setAnchorsBySelect] = (0, import_react4.useState)([]);
|
|
300
|
+
const mounted = (0, import_react4.useRef)(false);
|
|
301
|
+
const shouldOpenOnClick = openOnClick || events.includes("click");
|
|
302
|
+
use_isomorphic_layout_effect_default(() => {
|
|
303
|
+
mounted.current = true;
|
|
304
|
+
return () => {
|
|
305
|
+
mounted.current = false;
|
|
306
|
+
};
|
|
307
|
+
}, []);
|
|
308
|
+
(0, import_react4.useEffect)(() => {
|
|
309
|
+
if (!show) {
|
|
310
|
+
const timeout = setTimeout(() => {
|
|
311
|
+
setRendered(false);
|
|
312
|
+
}, 150);
|
|
313
|
+
return () => {
|
|
314
|
+
clearTimeout(timeout);
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
return () => null;
|
|
318
|
+
}, [show]);
|
|
319
|
+
const handleShow = (value) => {
|
|
320
|
+
if (!mounted.current) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (value) {
|
|
324
|
+
setRendered(true);
|
|
325
|
+
}
|
|
326
|
+
setTimeout(() => {
|
|
327
|
+
if (!mounted.current) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
setIsOpen == null ? void 0 : setIsOpen(value);
|
|
331
|
+
if (isOpen === void 0) {
|
|
332
|
+
setShow(value);
|
|
333
|
+
}
|
|
334
|
+
}, 10);
|
|
335
|
+
};
|
|
336
|
+
(0, import_react4.useEffect)(() => {
|
|
337
|
+
if (isOpen === void 0) {
|
|
338
|
+
return () => null;
|
|
339
|
+
}
|
|
340
|
+
if (isOpen) {
|
|
341
|
+
setRendered(true);
|
|
342
|
+
}
|
|
343
|
+
const timeout = setTimeout(() => {
|
|
344
|
+
setShow(isOpen);
|
|
345
|
+
}, 10);
|
|
346
|
+
return () => {
|
|
347
|
+
clearTimeout(timeout);
|
|
348
|
+
};
|
|
349
|
+
}, [isOpen]);
|
|
350
|
+
(0, import_react4.useEffect)(() => {
|
|
351
|
+
if (show === wasShowing.current) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
wasShowing.current = show;
|
|
355
|
+
if (show) {
|
|
356
|
+
afterShow == null ? void 0 : afterShow();
|
|
357
|
+
} else {
|
|
358
|
+
afterHide == null ? void 0 : afterHide();
|
|
359
|
+
}
|
|
360
|
+
}, [show]);
|
|
361
|
+
const handleShowTooltipDelayed = () => {
|
|
362
|
+
if (tooltipShowDelayTimerRef.current) {
|
|
363
|
+
clearTimeout(tooltipShowDelayTimerRef.current);
|
|
364
|
+
}
|
|
365
|
+
tooltipShowDelayTimerRef.current = setTimeout(() => {
|
|
366
|
+
handleShow(true);
|
|
367
|
+
}, delayShow);
|
|
368
|
+
};
|
|
369
|
+
const handleHideTooltipDelayed = (delay = delayHide) => {
|
|
370
|
+
if (tooltipHideDelayTimerRef.current) {
|
|
371
|
+
clearTimeout(tooltipHideDelayTimerRef.current);
|
|
372
|
+
}
|
|
373
|
+
tooltipHideDelayTimerRef.current = setTimeout(() => {
|
|
374
|
+
if (hoveringTooltip.current) {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
handleShow(false);
|
|
378
|
+
}, delay);
|
|
379
|
+
};
|
|
380
|
+
const handleShowTooltip = (event) => {
|
|
381
|
+
var _a;
|
|
382
|
+
if (!event) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
if (delayShow) {
|
|
386
|
+
handleShowTooltipDelayed();
|
|
387
|
+
} else {
|
|
388
|
+
handleShow(true);
|
|
389
|
+
}
|
|
390
|
+
const target = (_a = event.currentTarget) != null ? _a : event.target;
|
|
391
|
+
setActiveAnchor(target);
|
|
392
|
+
setProviderActiveAnchor({ current: target });
|
|
393
|
+
if (tooltipHideDelayTimerRef.current) {
|
|
394
|
+
clearTimeout(tooltipHideDelayTimerRef.current);
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
const handleHideTooltip = () => {
|
|
398
|
+
if (clickable) {
|
|
399
|
+
handleHideTooltipDelayed(delayHide || 100);
|
|
400
|
+
} else if (delayHide) {
|
|
401
|
+
handleHideTooltipDelayed();
|
|
402
|
+
} else {
|
|
403
|
+
handleShow(false);
|
|
404
|
+
}
|
|
405
|
+
if (tooltipShowDelayTimerRef.current) {
|
|
406
|
+
clearTimeout(tooltipShowDelayTimerRef.current);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
const handleTooltipPosition = ({ x, y }) => {
|
|
410
|
+
const virtualElement = {
|
|
411
|
+
getBoundingClientRect() {
|
|
412
|
+
return {
|
|
413
|
+
x,
|
|
414
|
+
y,
|
|
415
|
+
width: 0,
|
|
416
|
+
height: 0,
|
|
417
|
+
top: y,
|
|
418
|
+
left: x,
|
|
419
|
+
right: x,
|
|
420
|
+
bottom: y
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
computeTooltipPosition({
|
|
425
|
+
place,
|
|
426
|
+
offset: offset2,
|
|
427
|
+
elementReference: virtualElement,
|
|
428
|
+
tooltipReference: tooltipRef.current,
|
|
429
|
+
tooltipArrowReference: tooltipArrowRef.current,
|
|
430
|
+
strategy: positionStrategy,
|
|
431
|
+
middlewares
|
|
432
|
+
}).then((computedStylesData) => {
|
|
433
|
+
if (Object.keys(computedStylesData.tooltipStyles).length) {
|
|
434
|
+
setInlineStyles(computedStylesData.tooltipStyles);
|
|
435
|
+
}
|
|
436
|
+
if (Object.keys(computedStylesData.tooltipArrowStyles).length) {
|
|
437
|
+
setInlineArrowStyles(computedStylesData.tooltipArrowStyles);
|
|
438
|
+
}
|
|
439
|
+
setActualPlacement(computedStylesData.place);
|
|
440
|
+
});
|
|
441
|
+
};
|
|
442
|
+
const handleMouseMove = (event) => {
|
|
443
|
+
if (!event) {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
const mouseEvent = event;
|
|
447
|
+
const mousePosition = {
|
|
448
|
+
x: mouseEvent.clientX,
|
|
449
|
+
y: mouseEvent.clientY
|
|
450
|
+
};
|
|
451
|
+
handleTooltipPosition(mousePosition);
|
|
452
|
+
lastFloatPosition.current = mousePosition;
|
|
453
|
+
};
|
|
454
|
+
const handleClickTooltipAnchor = (event) => {
|
|
455
|
+
handleShowTooltip(event);
|
|
456
|
+
if (delayHide) {
|
|
457
|
+
handleHideTooltipDelayed();
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
const handleClickOutsideAnchors = (event) => {
|
|
461
|
+
var _a;
|
|
462
|
+
const anchorById = document.querySelector(`[id='${anchorId}']`);
|
|
463
|
+
const anchors = [anchorById, ...anchorsBySelect];
|
|
464
|
+
if (anchors.some((anchor) => anchor == null ? void 0 : anchor.contains(event.target))) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
if ((_a = tooltipRef.current) == null ? void 0 : _a.contains(event.target)) {
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
handleShow(false);
|
|
471
|
+
};
|
|
472
|
+
const handleEsc = (event) => {
|
|
473
|
+
if (event.key !== "Escape") {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
handleShow(false);
|
|
477
|
+
};
|
|
478
|
+
const debouncedHandleShowTooltip = debounce_default(handleShowTooltip, 50);
|
|
479
|
+
const debouncedHandleHideTooltip = debounce_default(handleHideTooltip, 50);
|
|
480
|
+
(0, import_react4.useEffect)(() => {
|
|
481
|
+
var _a, _b;
|
|
482
|
+
const elementRefs = new Set(anchorRefs);
|
|
483
|
+
anchorsBySelect.forEach((anchor) => {
|
|
484
|
+
elementRefs.add({ current: anchor });
|
|
485
|
+
});
|
|
486
|
+
const anchorById = document.querySelector(`[id='${anchorId}']`);
|
|
487
|
+
if (anchorById) {
|
|
488
|
+
elementRefs.add({ current: anchorById });
|
|
489
|
+
}
|
|
490
|
+
if (closeOnEsc) {
|
|
491
|
+
window.addEventListener("keydown", handleEsc);
|
|
492
|
+
}
|
|
493
|
+
const enabledEvents = [];
|
|
494
|
+
if (shouldOpenOnClick) {
|
|
495
|
+
window.addEventListener("click", handleClickOutsideAnchors);
|
|
496
|
+
enabledEvents.push({ event: "click", listener: handleClickTooltipAnchor });
|
|
497
|
+
} else {
|
|
498
|
+
enabledEvents.push(
|
|
499
|
+
{ event: "mouseenter", listener: debouncedHandleShowTooltip },
|
|
500
|
+
{ event: "mouseleave", listener: debouncedHandleHideTooltip },
|
|
501
|
+
{ event: "focus", listener: debouncedHandleShowTooltip },
|
|
502
|
+
{ event: "blur", listener: debouncedHandleHideTooltip }
|
|
503
|
+
);
|
|
504
|
+
if (float) {
|
|
505
|
+
enabledEvents.push({
|
|
506
|
+
event: "mousemove",
|
|
507
|
+
listener: handleMouseMove
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
const handleMouseEnterTooltip = () => {
|
|
512
|
+
hoveringTooltip.current = true;
|
|
513
|
+
};
|
|
514
|
+
const handleMouseLeaveTooltip = () => {
|
|
515
|
+
hoveringTooltip.current = false;
|
|
516
|
+
handleHideTooltip();
|
|
517
|
+
};
|
|
518
|
+
if (clickable && !shouldOpenOnClick) {
|
|
519
|
+
(_a = tooltipRef.current) == null ? void 0 : _a.addEventListener("mouseenter", handleMouseEnterTooltip);
|
|
520
|
+
(_b = tooltipRef.current) == null ? void 0 : _b.addEventListener("mouseleave", handleMouseLeaveTooltip);
|
|
521
|
+
}
|
|
522
|
+
enabledEvents.forEach(({ event, listener }) => {
|
|
523
|
+
elementRefs.forEach((ref) => {
|
|
524
|
+
var _a2;
|
|
525
|
+
(_a2 = ref.current) == null ? void 0 : _a2.addEventListener(event, listener);
|
|
526
|
+
});
|
|
527
|
+
});
|
|
528
|
+
return () => {
|
|
529
|
+
var _a2, _b2;
|
|
530
|
+
if (shouldOpenOnClick) {
|
|
531
|
+
window.removeEventListener("click", handleClickOutsideAnchors);
|
|
532
|
+
}
|
|
533
|
+
if (closeOnEsc) {
|
|
534
|
+
window.removeEventListener("keydown", handleEsc);
|
|
535
|
+
}
|
|
536
|
+
if (clickable && !shouldOpenOnClick) {
|
|
537
|
+
(_a2 = tooltipRef.current) == null ? void 0 : _a2.removeEventListener("mouseenter", handleMouseEnterTooltip);
|
|
538
|
+
(_b2 = tooltipRef.current) == null ? void 0 : _b2.removeEventListener("mouseleave", handleMouseLeaveTooltip);
|
|
539
|
+
}
|
|
540
|
+
enabledEvents.forEach(({ event, listener }) => {
|
|
541
|
+
elementRefs.forEach((ref) => {
|
|
542
|
+
var _a3;
|
|
543
|
+
(_a3 = ref.current) == null ? void 0 : _a3.removeEventListener(event, listener);
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
};
|
|
547
|
+
}, [rendered, anchorRefs, anchorsBySelect, closeOnEsc, events]);
|
|
548
|
+
(0, import_react4.useEffect)(() => {
|
|
549
|
+
let selector = anchorSelect != null ? anchorSelect : "";
|
|
550
|
+
if (!selector && id) {
|
|
551
|
+
selector = `[data-tooltip-id='${id}']`;
|
|
552
|
+
}
|
|
553
|
+
const documentObserverCallback = (mutationList) => {
|
|
554
|
+
const newAnchors = [];
|
|
555
|
+
mutationList.forEach((mutation) => {
|
|
556
|
+
if (mutation.type === "attributes" && mutation.attributeName === "data-tooltip-id") {
|
|
557
|
+
const newId = mutation.target.getAttribute("data-tooltip-id");
|
|
558
|
+
if (newId === id) {
|
|
559
|
+
newAnchors.push(mutation.target);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
if (mutation.type !== "childList") {
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
if (activeAnchor) {
|
|
566
|
+
;
|
|
567
|
+
[...mutation.removedNodes].some((node) => {
|
|
568
|
+
var _a;
|
|
569
|
+
if ((_a = node == null ? void 0 : node.contains) == null ? void 0 : _a.call(node, activeAnchor)) {
|
|
570
|
+
setRendered(false);
|
|
571
|
+
handleShow(false);
|
|
572
|
+
setActiveAnchor(null);
|
|
573
|
+
return true;
|
|
574
|
+
}
|
|
575
|
+
return false;
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
if (!selector) {
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
try {
|
|
582
|
+
const elements = [...mutation.addedNodes].filter((node) => node.nodeType === 1);
|
|
583
|
+
newAnchors.push(
|
|
584
|
+
...elements.filter(
|
|
585
|
+
(element) => element.matches(selector)
|
|
586
|
+
)
|
|
587
|
+
);
|
|
588
|
+
newAnchors.push(
|
|
589
|
+
...elements.flatMap(
|
|
590
|
+
(element) => [...element.querySelectorAll(selector)]
|
|
591
|
+
)
|
|
592
|
+
);
|
|
593
|
+
} catch (e) {
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
if (newAnchors.length) {
|
|
597
|
+
setAnchorsBySelect((anchors) => [...anchors, ...newAnchors]);
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
const documentObserver = new MutationObserver(documentObserverCallback);
|
|
601
|
+
documentObserver.observe(document.body, {
|
|
602
|
+
childList: true,
|
|
603
|
+
subtree: true,
|
|
604
|
+
attributes: true,
|
|
605
|
+
attributeFilter: ["data-tooltip-id"]
|
|
606
|
+
});
|
|
607
|
+
return () => {
|
|
608
|
+
documentObserver.disconnect();
|
|
609
|
+
};
|
|
610
|
+
}, [id, anchorSelect, activeAnchor]);
|
|
611
|
+
const updateTooltipPosition = () => {
|
|
612
|
+
if (position) {
|
|
613
|
+
handleTooltipPosition(position);
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
if (float) {
|
|
617
|
+
if (lastFloatPosition.current) {
|
|
618
|
+
handleTooltipPosition(lastFloatPosition.current);
|
|
619
|
+
}
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
computeTooltipPosition({
|
|
623
|
+
place,
|
|
624
|
+
offset: offset2,
|
|
625
|
+
elementReference: activeAnchor,
|
|
626
|
+
tooltipReference: tooltipRef.current,
|
|
627
|
+
tooltipArrowReference: tooltipArrowRef.current,
|
|
628
|
+
strategy: positionStrategy,
|
|
629
|
+
middlewares
|
|
630
|
+
}).then((computedStylesData) => {
|
|
631
|
+
if (!mounted.current) {
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
if (Object.keys(computedStylesData.tooltipStyles).length) {
|
|
635
|
+
setInlineStyles(computedStylesData.tooltipStyles);
|
|
636
|
+
}
|
|
637
|
+
if (Object.keys(computedStylesData.tooltipArrowStyles).length) {
|
|
638
|
+
setInlineArrowStyles(computedStylesData.tooltipArrowStyles);
|
|
639
|
+
}
|
|
640
|
+
setActualPlacement(computedStylesData.place);
|
|
641
|
+
});
|
|
642
|
+
};
|
|
643
|
+
(0, import_react4.useEffect)(() => {
|
|
644
|
+
updateTooltipPosition();
|
|
645
|
+
}, [show, activeAnchor, content, externalStyles, place, offset2, positionStrategy, position]);
|
|
646
|
+
(0, import_react4.useEffect)(() => {
|
|
647
|
+
if (!(contentWrapperRef == null ? void 0 : contentWrapperRef.current)) {
|
|
648
|
+
return () => null;
|
|
649
|
+
}
|
|
650
|
+
const contentObserver = new ResizeObserver(() => {
|
|
651
|
+
updateTooltipPosition();
|
|
652
|
+
});
|
|
653
|
+
contentObserver.observe(contentWrapperRef.current);
|
|
654
|
+
return () => {
|
|
655
|
+
contentObserver.disconnect();
|
|
656
|
+
};
|
|
657
|
+
}, [content, contentWrapperRef == null ? void 0 : contentWrapperRef.current]);
|
|
658
|
+
(0, import_react4.useEffect)(() => {
|
|
659
|
+
var _a;
|
|
660
|
+
const anchorById = document.querySelector(`[id='${anchorId}']`);
|
|
661
|
+
const anchors = [...anchorsBySelect, anchorById];
|
|
662
|
+
if (!activeAnchor || !anchors.includes(activeAnchor)) {
|
|
663
|
+
setActiveAnchor((_a = anchorsBySelect[0]) != null ? _a : anchorById);
|
|
664
|
+
}
|
|
665
|
+
}, [anchorId, anchorsBySelect, activeAnchor]);
|
|
666
|
+
(0, import_react4.useEffect)(() => {
|
|
667
|
+
return () => {
|
|
668
|
+
if (tooltipShowDelayTimerRef.current) {
|
|
669
|
+
clearTimeout(tooltipShowDelayTimerRef.current);
|
|
670
|
+
}
|
|
671
|
+
if (tooltipHideDelayTimerRef.current) {
|
|
672
|
+
clearTimeout(tooltipHideDelayTimerRef.current);
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
}, []);
|
|
676
|
+
(0, import_react4.useEffect)(() => {
|
|
677
|
+
let selector = anchorSelect;
|
|
678
|
+
if (!selector && id) {
|
|
679
|
+
selector = `[data-tooltip-id='${id}']`;
|
|
680
|
+
}
|
|
681
|
+
if (!selector) {
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
try {
|
|
685
|
+
const anchors = Array.from(document.querySelectorAll(selector));
|
|
686
|
+
setAnchorsBySelect(anchors);
|
|
687
|
+
} catch (e) {
|
|
688
|
+
setAnchorsBySelect([]);
|
|
689
|
+
}
|
|
690
|
+
}, [id, anchorSelect]);
|
|
691
|
+
const canShow = content && show && Object.keys(inlineStyles).length > 0;
|
|
692
|
+
return rendered ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
693
|
+
WrapperElement,
|
|
694
|
+
{
|
|
695
|
+
id,
|
|
696
|
+
role: "tooltip",
|
|
697
|
+
className: (0, import_classnames2.default)(
|
|
698
|
+
"react-tooltip",
|
|
699
|
+
styles_module_default["tooltip"],
|
|
700
|
+
styles_module_default[variant],
|
|
701
|
+
className,
|
|
702
|
+
`react-tooltip__place-${actualPlacement}`,
|
|
703
|
+
{
|
|
704
|
+
[styles_module_default["show"]]: canShow,
|
|
705
|
+
[styles_module_default["fixed"]]: positionStrategy === "fixed",
|
|
706
|
+
[styles_module_default["clickable"]]: clickable
|
|
707
|
+
}
|
|
708
|
+
),
|
|
709
|
+
style: { ...externalStyles, ...inlineStyles },
|
|
710
|
+
ref: tooltipRef,
|
|
711
|
+
children: [
|
|
712
|
+
content,
|
|
713
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
714
|
+
WrapperElement,
|
|
715
|
+
{
|
|
716
|
+
className: (0, import_classnames2.default)("react-tooltip-arrow", styles_module_default["arrow"], classNameArrow, {
|
|
717
|
+
/**
|
|
718
|
+
* changed from dash `no-arrow` to camelcase because of:
|
|
719
|
+
* https://github.com/indooorsman/esbuild-css-modules-plugin/issues/42
|
|
720
|
+
*/
|
|
721
|
+
[styles_module_default["noArrow"]]: noArrow
|
|
722
|
+
}),
|
|
723
|
+
style: inlineArrowStyles,
|
|
724
|
+
ref: tooltipArrowRef
|
|
725
|
+
}
|
|
726
|
+
)
|
|
727
|
+
]
|
|
728
|
+
}
|
|
729
|
+
) : null;
|
|
730
|
+
};
|
|
731
|
+
var Tooltip_default = Tooltip;
|
|
732
|
+
|
|
733
|
+
// src/components/TooltipContent/TooltipContent.tsx
|
|
734
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
735
|
+
var TooltipContent = ({ content }) => {
|
|
736
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { dangerouslySetInnerHTML: { __html: content } });
|
|
737
|
+
};
|
|
738
|
+
var TooltipContent_default = TooltipContent;
|
|
739
|
+
|
|
740
|
+
// src/components/TooltipController/TooltipController.tsx
|
|
741
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
742
|
+
var TooltipController = ({
|
|
743
|
+
id,
|
|
744
|
+
anchorId,
|
|
745
|
+
anchorSelect,
|
|
746
|
+
content,
|
|
747
|
+
html,
|
|
748
|
+
render,
|
|
749
|
+
className,
|
|
750
|
+
classNameArrow,
|
|
751
|
+
variant = "dark",
|
|
752
|
+
place = "top",
|
|
753
|
+
offset: offset2 = 10,
|
|
754
|
+
wrapper = "div",
|
|
755
|
+
children = null,
|
|
756
|
+
events = ["hover"],
|
|
757
|
+
openOnClick = false,
|
|
758
|
+
positionStrategy = "absolute",
|
|
759
|
+
middlewares,
|
|
760
|
+
delayShow = 0,
|
|
761
|
+
delayHide = 0,
|
|
762
|
+
float = false,
|
|
763
|
+
noArrow = false,
|
|
764
|
+
clickable = false,
|
|
765
|
+
closeOnEsc = false,
|
|
766
|
+
style,
|
|
767
|
+
position,
|
|
768
|
+
isOpen,
|
|
769
|
+
setIsOpen,
|
|
770
|
+
afterShow,
|
|
771
|
+
afterHide
|
|
772
|
+
}) => {
|
|
773
|
+
const [tooltipContent, setTooltipContent] = (0, import_react5.useState)(content);
|
|
774
|
+
const [tooltipHtml, setTooltipHtml] = (0, import_react5.useState)(html);
|
|
775
|
+
const [tooltipPlace, setTooltipPlace] = (0, import_react5.useState)(place);
|
|
776
|
+
const [tooltipVariant, setTooltipVariant] = (0, import_react5.useState)(variant);
|
|
777
|
+
const [tooltipOffset, setTooltipOffset] = (0, import_react5.useState)(offset2);
|
|
778
|
+
const [tooltipDelayShow, setTooltipDelayShow] = (0, import_react5.useState)(delayShow);
|
|
779
|
+
const [tooltipDelayHide, setTooltipDelayHide] = (0, import_react5.useState)(delayHide);
|
|
780
|
+
const [tooltipFloat, setTooltipFloat] = (0, import_react5.useState)(float);
|
|
781
|
+
const [tooltipWrapper, setTooltipWrapper] = (0, import_react5.useState)(wrapper);
|
|
782
|
+
const [tooltipEvents, setTooltipEvents] = (0, import_react5.useState)(events);
|
|
783
|
+
const [tooltipPositionStrategy, setTooltipPositionStrategy] = (0, import_react5.useState)(positionStrategy);
|
|
784
|
+
const [activeAnchor, setActiveAnchor] = (0, import_react5.useState)(null);
|
|
785
|
+
const { anchorRefs, activeAnchor: providerActiveAnchor } = useTooltip(id);
|
|
786
|
+
const getDataAttributesFromAnchorElement = (elementReference) => {
|
|
787
|
+
const dataAttributes = elementReference == null ? void 0 : elementReference.getAttributeNames().reduce((acc, name) => {
|
|
788
|
+
var _a;
|
|
789
|
+
if (name.startsWith("data-tooltip-")) {
|
|
790
|
+
const parsedAttribute = name.replace(/^data-tooltip-/, "");
|
|
791
|
+
acc[parsedAttribute] = (_a = elementReference == null ? void 0 : elementReference.getAttribute(name)) != null ? _a : null;
|
|
792
|
+
}
|
|
793
|
+
return acc;
|
|
794
|
+
}, {});
|
|
795
|
+
return dataAttributes;
|
|
796
|
+
};
|
|
797
|
+
const applyAllDataAttributesFromAnchorElement = (dataAttributes) => {
|
|
798
|
+
const handleDataAttributes = {
|
|
799
|
+
place: (value) => {
|
|
800
|
+
setTooltipPlace(value != null ? value : place);
|
|
801
|
+
},
|
|
802
|
+
content: (value) => {
|
|
803
|
+
setTooltipContent(value != null ? value : content);
|
|
804
|
+
},
|
|
805
|
+
html: (value) => {
|
|
806
|
+
setTooltipHtml(value != null ? value : html);
|
|
807
|
+
},
|
|
808
|
+
variant: (value) => {
|
|
809
|
+
setTooltipVariant(value != null ? value : variant);
|
|
810
|
+
},
|
|
811
|
+
offset: (value) => {
|
|
812
|
+
setTooltipOffset(value === null ? offset2 : Number(value));
|
|
813
|
+
},
|
|
814
|
+
wrapper: (value) => {
|
|
815
|
+
setTooltipWrapper(value != null ? value : wrapper);
|
|
816
|
+
},
|
|
817
|
+
events: (value) => {
|
|
818
|
+
const parsed = value == null ? void 0 : value.split(" ");
|
|
819
|
+
setTooltipEvents(parsed != null ? parsed : events);
|
|
820
|
+
},
|
|
821
|
+
"position-strategy": (value) => {
|
|
822
|
+
setTooltipPositionStrategy(value != null ? value : positionStrategy);
|
|
823
|
+
},
|
|
824
|
+
"delay-show": (value) => {
|
|
825
|
+
setTooltipDelayShow(value === null ? delayShow : Number(value));
|
|
826
|
+
},
|
|
827
|
+
"delay-hide": (value) => {
|
|
828
|
+
setTooltipDelayHide(value === null ? delayHide : Number(value));
|
|
829
|
+
},
|
|
830
|
+
float: (value) => {
|
|
831
|
+
setTooltipFloat(value === null ? float : value === "true");
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
Object.values(handleDataAttributes).forEach((handler) => handler(null));
|
|
835
|
+
Object.entries(dataAttributes).forEach(([key, value]) => {
|
|
836
|
+
var _a;
|
|
837
|
+
(_a = handleDataAttributes[key]) == null ? void 0 : _a.call(handleDataAttributes, value);
|
|
838
|
+
});
|
|
839
|
+
};
|
|
840
|
+
(0, import_react5.useEffect)(() => {
|
|
841
|
+
setTooltipContent(content);
|
|
842
|
+
}, [content]);
|
|
843
|
+
(0, import_react5.useEffect)(() => {
|
|
844
|
+
setTooltipHtml(html);
|
|
845
|
+
}, [html]);
|
|
846
|
+
(0, import_react5.useEffect)(() => {
|
|
847
|
+
setTooltipPlace(place);
|
|
848
|
+
}, [place]);
|
|
849
|
+
(0, import_react5.useEffect)(() => {
|
|
850
|
+
var _a;
|
|
851
|
+
const elementRefs = new Set(anchorRefs);
|
|
852
|
+
let selector = anchorSelect;
|
|
853
|
+
if (!selector && id) {
|
|
854
|
+
selector = `[data-tooltip-id='${id}']`;
|
|
855
|
+
}
|
|
856
|
+
if (selector) {
|
|
857
|
+
try {
|
|
858
|
+
const anchorsBySelect = document.querySelectorAll(selector);
|
|
859
|
+
anchorsBySelect.forEach((anchor) => {
|
|
860
|
+
elementRefs.add({ current: anchor });
|
|
861
|
+
});
|
|
862
|
+
} catch (e) {
|
|
863
|
+
if (true) {
|
|
864
|
+
console.warn(`[react-tooltip] "${anchorSelect}" is not a valid CSS selector`);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
const anchorById = document.querySelector(`[id='${anchorId}']`);
|
|
869
|
+
if (anchorById) {
|
|
870
|
+
elementRefs.add({ current: anchorById });
|
|
871
|
+
}
|
|
872
|
+
if (!elementRefs.size) {
|
|
873
|
+
return () => null;
|
|
874
|
+
}
|
|
875
|
+
const anchorElement = (_a = activeAnchor != null ? activeAnchor : anchorById) != null ? _a : providerActiveAnchor.current;
|
|
876
|
+
const observerCallback = (mutationList) => {
|
|
877
|
+
mutationList.forEach((mutation) => {
|
|
878
|
+
var _a2;
|
|
879
|
+
if (!anchorElement || mutation.type !== "attributes" || !((_a2 = mutation.attributeName) == null ? void 0 : _a2.startsWith("data-tooltip-"))) {
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
882
|
+
const dataAttributes = getDataAttributesFromAnchorElement(anchorElement);
|
|
883
|
+
applyAllDataAttributesFromAnchorElement(dataAttributes);
|
|
884
|
+
});
|
|
885
|
+
};
|
|
886
|
+
const observer = new MutationObserver(observerCallback);
|
|
887
|
+
const observerConfig = { attributes: true, childList: false, subtree: false };
|
|
888
|
+
if (anchorElement) {
|
|
889
|
+
const dataAttributes = getDataAttributesFromAnchorElement(anchorElement);
|
|
890
|
+
applyAllDataAttributesFromAnchorElement(dataAttributes);
|
|
891
|
+
observer.observe(anchorElement, observerConfig);
|
|
892
|
+
}
|
|
893
|
+
return () => {
|
|
894
|
+
observer.disconnect();
|
|
895
|
+
};
|
|
896
|
+
}, [anchorRefs, providerActiveAnchor, activeAnchor, anchorId, anchorSelect]);
|
|
897
|
+
let renderedContent = children;
|
|
898
|
+
const contentWrapperRef = (0, import_react5.useRef)(null);
|
|
899
|
+
if (render) {
|
|
900
|
+
renderedContent = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { ref: contentWrapperRef, className: "react-tooltip-content-wrapper", children: render({ content: tooltipContent != null ? tooltipContent : null, activeAnchor }) });
|
|
901
|
+
} else if (tooltipContent) {
|
|
902
|
+
renderedContent = tooltipContent;
|
|
903
|
+
}
|
|
904
|
+
if (tooltipHtml) {
|
|
905
|
+
renderedContent = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(TooltipContent_default, { content: tooltipHtml });
|
|
906
|
+
}
|
|
907
|
+
const props = {
|
|
908
|
+
id,
|
|
909
|
+
anchorId,
|
|
910
|
+
anchorSelect,
|
|
911
|
+
className,
|
|
912
|
+
classNameArrow,
|
|
913
|
+
content: renderedContent,
|
|
914
|
+
contentWrapperRef,
|
|
915
|
+
place: tooltipPlace,
|
|
916
|
+
variant: tooltipVariant,
|
|
917
|
+
offset: tooltipOffset,
|
|
918
|
+
wrapper: tooltipWrapper,
|
|
919
|
+
events: tooltipEvents,
|
|
920
|
+
openOnClick,
|
|
921
|
+
positionStrategy: tooltipPositionStrategy,
|
|
922
|
+
middlewares,
|
|
923
|
+
delayShow: tooltipDelayShow,
|
|
924
|
+
delayHide: tooltipDelayHide,
|
|
925
|
+
float: tooltipFloat,
|
|
926
|
+
noArrow,
|
|
927
|
+
clickable,
|
|
928
|
+
closeOnEsc,
|
|
929
|
+
style,
|
|
930
|
+
position,
|
|
931
|
+
isOpen,
|
|
932
|
+
setIsOpen,
|
|
933
|
+
afterShow,
|
|
934
|
+
afterHide,
|
|
935
|
+
activeAnchor,
|
|
936
|
+
setActiveAnchor: (anchor) => setActiveAnchor(anchor)
|
|
937
|
+
};
|
|
938
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Tooltip_default, { ...props });
|
|
939
|
+
};
|
|
940
|
+
var TooltipController_default = TooltipController;
|
|
941
|
+
//# sourceMappingURL=react-tooltip.cjs.js.map
|