react-tooltip 5.10.5-beta.996.1 → 5.10.5

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