react-tooltip 5.26.4 → 6.0.0-beta.1179.rc.0

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.
@@ -7,16 +7,9 @@
7
7
  */
8
8
  'use strict';
9
9
 
10
- Object.defineProperty(exports, '__esModule', { value: true });
11
-
12
10
  var React = require('react');
13
11
  var dom = require('@floating-ui/dom');
14
- var classNames = require('classnames');
15
-
16
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
-
18
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
19
- var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames);
12
+ var clsx = require('clsx');
20
13
 
21
14
  // This is the ID for the core styles of ReactTooltip
22
15
  const REACT_TOOLTIP_CORE_STYLES_ID = 'react-tooltip-core-styles';
@@ -82,28 +75,6 @@ function injectStyle({ css, id = REACT_TOOLTIP_BASE_STYLES_ID, type = 'base', re
82
75
  }
83
76
  injected[type] = true;
84
77
  }
85
- /**
86
- * @deprecated Use the `disableStyleInjection` tooltip prop instead.
87
- * See https://react-tooltip.com/docs/examples/styling#disabling-reacttooltip-css
88
- */
89
- function removeStyle({ type = 'base', id = REACT_TOOLTIP_BASE_STYLES_ID, } = {}) {
90
- if (!injected[type]) {
91
- return;
92
- }
93
- if (type === 'core') {
94
- // eslint-disable-next-line no-param-reassign
95
- id = REACT_TOOLTIP_CORE_STYLES_ID;
96
- }
97
- const style = document.getElementById(id);
98
- if ((style === null || style === void 0 ? void 0 : style.tagName) === 'style') {
99
- style === null || style === void 0 ? void 0 : style.remove();
100
- }
101
- else {
102
- // eslint-disable-next-line no-console
103
- console.warn(`[react-tooltip] Failed to remove 'style' element with id '${id}'. Call \`injectStyle()\` first`);
104
- }
105
- injected[type] = false;
106
- }
107
78
 
108
79
  const computeTooltipPosition = async ({ elementReference = null, tooltipReference = null, tooltipArrowReference = null, place = 'top', offset: offsetValue = 10, strategy = 'absolute', middlewares = [
109
80
  dom.offset(Number(offsetValue)),
@@ -187,7 +158,7 @@ const cssSupports = (property, value) => {
187
158
  };
188
159
 
189
160
  const cssTimeToMs = (time) => {
190
- const match = time.match(/^([\d.]+)(ms|s)$/);
161
+ const match = time.match(/^([\d.]+)(m?s)$/);
191
162
  if (!match) {
192
163
  return 0;
193
164
  }
@@ -291,111 +262,13 @@ const getScrollParent = (node) => {
291
262
 
292
263
  const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
293
264
 
294
- const DEFAULT_TOOLTIP_ID = 'DEFAULT_TOOLTIP_ID';
295
- const DEFAULT_CONTEXT_DATA = {
296
- anchorRefs: new Set(),
297
- activeAnchor: { current: null },
298
- attach: () => {
299
- /* attach anchor element */
300
- },
301
- detach: () => {
302
- /* detach anchor element */
303
- },
304
- setActiveAnchor: () => {
305
- /* set active anchor */
306
- },
307
- };
308
- const DEFAULT_CONTEXT_DATA_WRAPPER = {
309
- getTooltipData: () => DEFAULT_CONTEXT_DATA,
310
- };
311
- const TooltipContext = React.createContext(DEFAULT_CONTEXT_DATA_WRAPPER);
312
- /**
313
- * @deprecated Use the `data-tooltip-id` attribute, or the `anchorSelect` prop instead.
314
- * See https://react-tooltip.com/docs/getting-started
315
- */
316
- const TooltipProvider = ({ children }) => {
317
- const [anchorRefMap, setAnchorRefMap] = React.useState({
318
- [DEFAULT_TOOLTIP_ID]: new Set(),
319
- });
320
- const [activeAnchorMap, setActiveAnchorMap] = React.useState({
321
- [DEFAULT_TOOLTIP_ID]: { current: null },
322
- });
323
- const attach = (tooltipId, ...refs) => {
324
- setAnchorRefMap((oldMap) => {
325
- var _a;
326
- const tooltipRefs = (_a = oldMap[tooltipId]) !== null && _a !== void 0 ? _a : new Set();
327
- refs.forEach((ref) => tooltipRefs.add(ref));
328
- // create new object to trigger re-render
329
- return { ...oldMap, [tooltipId]: new Set(tooltipRefs) };
330
- });
331
- };
332
- const detach = (tooltipId, ...refs) => {
333
- setAnchorRefMap((oldMap) => {
334
- const tooltipRefs = oldMap[tooltipId];
335
- if (!tooltipRefs) {
336
- // tooltip not found
337
- // maybe thow error?
338
- return oldMap;
339
- }
340
- refs.forEach((ref) => tooltipRefs.delete(ref));
341
- // create new object to trigger re-render
342
- return { ...oldMap };
343
- });
344
- };
345
- const setActiveAnchor = (tooltipId, ref) => {
346
- setActiveAnchorMap((oldMap) => {
347
- var _a;
348
- if (((_a = oldMap[tooltipId]) === null || _a === void 0 ? void 0 : _a.current) === ref.current) {
349
- return oldMap;
350
- }
351
- // create new object to trigger re-render
352
- return { ...oldMap, [tooltipId]: ref };
353
- });
354
- };
355
- const getTooltipData = React.useCallback((tooltipId = DEFAULT_TOOLTIP_ID) => {
356
- var _a, _b;
357
- return ({
358
- anchorRefs: (_a = anchorRefMap[tooltipId]) !== null && _a !== void 0 ? _a : new Set(),
359
- activeAnchor: (_b = activeAnchorMap[tooltipId]) !== null && _b !== void 0 ? _b : { current: null },
360
- attach: (...refs) => attach(tooltipId, ...refs),
361
- detach: (...refs) => detach(tooltipId, ...refs),
362
- setActiveAnchor: (ref) => setActiveAnchor(tooltipId, ref),
363
- });
364
- }, [anchorRefMap, activeAnchorMap, attach, detach]);
365
- const context = React.useMemo(() => {
366
- return {
367
- getTooltipData,
368
- };
369
- }, [getTooltipData]);
370
- return React__default["default"].createElement(TooltipContext.Provider, { value: context }, children);
371
- };
372
- function useTooltip(tooltipId = DEFAULT_TOOLTIP_ID) {
373
- return React.useContext(TooltipContext).getTooltipData(tooltipId);
374
- }
375
-
376
- /**
377
- * @deprecated Use the `data-tooltip-id` attribute, or the `anchorSelect` prop instead.
378
- * See https://react-tooltip.com/docs/getting-started
379
- */
380
- const TooltipWrapper = ({ tooltipId, children, className, place, content, html, variant, offset, wrapper, events, positionStrategy, delayShow, delayHide, }) => {
381
- const { attach, detach } = useTooltip(tooltipId);
382
- const anchorRef = React.useRef(null);
383
- React.useEffect(() => {
384
- attach(anchorRef);
385
- return () => {
386
- detach(anchorRef);
387
- };
388
- }, []);
389
- return (React__default["default"].createElement("span", { ref: anchorRef, className: classNames__default["default"]('react-tooltip-wrapper', className), "data-tooltip-place": place, "data-tooltip-content": content, "data-tooltip-html": html, "data-tooltip-variant": variant, "data-tooltip-offset": offset, "data-tooltip-wrapper": wrapper, "data-tooltip-events": events, "data-tooltip-position-strategy": positionStrategy, "data-tooltip-delay-show": delayShow, "data-tooltip-delay-hide": delayHide }, children));
390
- };
391
-
392
265
  var coreStyles = {"tooltip":"core-styles-module_tooltip__3vRRp","fixed":"core-styles-module_fixed__pcSol","arrow":"core-styles-module_arrow__cvMwQ","noArrow":"core-styles-module_noArrow__xock6","clickable":"core-styles-module_clickable__ZuTTB","show":"core-styles-module_show__Nt9eE","closing":"core-styles-module_closing__sGnxF"};
393
266
 
394
267
  var styles = {"tooltip":"styles-module_tooltip__mnnfp","arrow":"styles-module_arrow__K0L3T","dark":"styles-module_dark__xNqje","light":"styles-module_light__Z6W-X","success":"styles-module_success__A2AKt","warning":"styles-module_warning__SCK0X","error":"styles-module_error__JvumD","info":"styles-module_info__BWdHW"};
395
268
 
396
269
  const Tooltip = ({
397
270
  // props
398
- forwardRef, id, className, classNameArrow, variant = 'dark', anchorId, anchorSelect, place = 'top', offset = 10, events = ['hover'], openOnClick = false, positionStrategy = 'absolute', middlewares, wrapper: WrapperElement, delayShow = 0, delayHide = 0, float = false, hidden = false, noArrow = false, clickable = false, closeOnEsc = false, closeOnScroll = false, closeOnResize = false, openEvents, closeEvents, globalCloseEvents, imperativeModeOnly, style: externalStyles, position, afterShow, afterHide,
271
+ forwardRef, id, className, classNameArrow, variant = 'dark', anchorSelect, place = 'top', offset = 10, openOnClick = false, positionStrategy = 'absolute', middlewares, wrapper: WrapperElement, delayShow = 0, delayHide = 0, float = false, hidden = false, noArrow = false, clickable = false, openEvents, closeEvents, globalCloseEvents, imperativeModeOnly, style: externalStyles, position, afterShow, afterHide,
399
272
  // props handled by controller
400
273
  content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, role = 'tooltip', }) => {
401
274
  var _a;
@@ -414,79 +287,9 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
414
287
  const [imperativeOptions, setImperativeOptions] = React.useState(null);
415
288
  const wasShowing = React.useRef(false);
416
289
  const lastFloatPosition = React.useRef(null);
417
- /**
418
- * @todo Remove this in a future version (provider/wrapper method is deprecated)
419
- */
420
- const { anchorRefs, setActiveAnchor: setProviderActiveAnchor } = useTooltip(id);
421
290
  const hoveringTooltip = React.useRef(false);
422
- const [anchorsBySelect, setAnchorsBySelect] = React.useState([]);
291
+ const [anchorElements, setAnchorElements] = React.useState([]);
423
292
  const mounted = React.useRef(false);
424
- /**
425
- * @todo Update when deprecated stuff gets removed.
426
- */
427
- const shouldOpenOnClick = openOnClick || events.includes('click');
428
- const hasClickEvent = shouldOpenOnClick || (openEvents === null || openEvents === void 0 ? void 0 : openEvents.click) || (openEvents === null || openEvents === void 0 ? void 0 : openEvents.dblclick) || (openEvents === null || openEvents === void 0 ? void 0 : openEvents.mousedown);
429
- const actualOpenEvents = openEvents
430
- ? { ...openEvents }
431
- : {
432
- mouseenter: true,
433
- focus: true,
434
- click: false,
435
- dblclick: false,
436
- mousedown: false,
437
- };
438
- if (!openEvents && shouldOpenOnClick) {
439
- Object.assign(actualOpenEvents, {
440
- mouseenter: false,
441
- focus: false,
442
- click: true,
443
- });
444
- }
445
- const actualCloseEvents = closeEvents
446
- ? { ...closeEvents }
447
- : {
448
- mouseleave: true,
449
- blur: true,
450
- click: false,
451
- dblclick: false,
452
- mouseup: false,
453
- };
454
- if (!closeEvents && shouldOpenOnClick) {
455
- Object.assign(actualCloseEvents, {
456
- mouseleave: false,
457
- blur: false,
458
- });
459
- }
460
- const actualGlobalCloseEvents = globalCloseEvents
461
- ? { ...globalCloseEvents }
462
- : {
463
- escape: closeOnEsc || false,
464
- scroll: closeOnScroll || false,
465
- resize: closeOnResize || false,
466
- clickOutsideAnchor: hasClickEvent || false,
467
- };
468
- if (imperativeModeOnly) {
469
- Object.assign(actualOpenEvents, {
470
- mouseenter: false,
471
- focus: false,
472
- click: false,
473
- dblclick: false,
474
- mousedown: false,
475
- });
476
- Object.assign(actualCloseEvents, {
477
- mouseleave: false,
478
- blur: false,
479
- click: false,
480
- dblclick: false,
481
- mouseup: false,
482
- });
483
- Object.assign(actualGlobalCloseEvents, {
484
- escape: false,
485
- scroll: false,
486
- resize: false,
487
- clickOutsideAnchor: false,
488
- });
489
- }
490
293
  /**
491
294
  * useLayoutEffect runs before useEffect,
492
295
  * but should be used carefully because of caveats
@@ -498,7 +301,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
498
301
  mounted.current = false;
499
302
  };
500
303
  }, []);
501
- const handleShow = (value) => {
304
+ const handleShow = React.useCallback((value) => {
502
305
  if (!mounted.current) {
503
306
  return;
504
307
  }
@@ -518,7 +321,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
518
321
  setShow(value);
519
322
  }
520
323
  }, 10);
521
- };
324
+ }, [isOpen, setIsOpen]);
522
325
  /**
523
326
  * this replicates the effect from `handleShow()`
524
327
  * when `isOpen` is changed from outside
@@ -565,13 +368,13 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
565
368
  // +25ms just to make sure `onTransitionEnd` (if it gets fired) has time to run
566
369
  }, transitionShowDelay + 25);
567
370
  }
568
- }, [show]);
371
+ }, [afterHide, afterShow, show]);
569
372
  const handleComputedPosition = (newComputedPosition) => {
570
373
  setComputedPosition((oldComputedPosition) => deepEqual(oldComputedPosition, newComputedPosition)
571
374
  ? oldComputedPosition
572
375
  : newComputedPosition);
573
376
  };
574
- const handleShowTooltipDelayed = (delay = delayShow) => {
377
+ const handleShowTooltipDelayed = React.useCallback((delay = delayShow) => {
575
378
  if (tooltipShowDelayTimerRef.current) {
576
379
  clearTimeout(tooltipShowDelayTimerRef.current);
577
380
  }
@@ -583,8 +386,8 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
583
386
  tooltipShowDelayTimerRef.current = setTimeout(() => {
584
387
  handleShow(true);
585
388
  }, delay);
586
- };
587
- const handleHideTooltipDelayed = (delay = delayHide) => {
389
+ }, [delayShow, handleShow, rendered]);
390
+ const handleHideTooltipDelayed = React.useCallback((delay = delayHide) => {
588
391
  if (tooltipHideDelayTimerRef.current) {
589
392
  clearTimeout(tooltipHideDelayTimerRef.current);
590
393
  }
@@ -594,50 +397,8 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
594
397
  }
595
398
  handleShow(false);
596
399
  }, delay);
597
- };
598
- const handleShowTooltip = (event) => {
599
- var _a;
600
- if (!event) {
601
- return;
602
- }
603
- const target = ((_a = event.currentTarget) !== null && _a !== void 0 ? _a : event.target);
604
- if (!(target === null || target === void 0 ? void 0 : target.isConnected)) {
605
- /**
606
- * this happens when the target is removed from the DOM
607
- * at the same time the tooltip gets triggered
608
- */
609
- setActiveAnchor(null);
610
- setProviderActiveAnchor({ current: null });
611
- return;
612
- }
613
- if (delayShow) {
614
- handleShowTooltipDelayed();
615
- }
616
- else {
617
- handleShow(true);
618
- }
619
- setActiveAnchor(target);
620
- setProviderActiveAnchor({ current: target });
621
- if (tooltipHideDelayTimerRef.current) {
622
- clearTimeout(tooltipHideDelayTimerRef.current);
623
- }
624
- };
625
- const handleHideTooltip = () => {
626
- if (clickable) {
627
- // allow time for the mouse to reach the tooltip, in case there's a gap
628
- handleHideTooltipDelayed(delayHide || 100);
629
- }
630
- else if (delayHide) {
631
- handleHideTooltipDelayed();
632
- }
633
- else {
634
- handleShow(false);
635
- }
636
- if (tooltipShowDelayTimerRef.current) {
637
- clearTimeout(tooltipShowDelayTimerRef.current);
638
- }
639
- };
640
- const handleTooltipPosition = ({ x, y }) => {
400
+ }, [delayHide, handleShow]);
401
+ const handleTooltipPosition = React.useCallback(({ x, y }) => {
641
402
  var _a;
642
403
  const virtualElement = {
643
404
  getBoundingClientRect() {
@@ -665,58 +426,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
665
426
  }).then((computedStylesData) => {
666
427
  handleComputedPosition(computedStylesData);
667
428
  });
668
- };
669
- const handlePointerMove = (event) => {
670
- if (!event) {
671
- return;
672
- }
673
- const mouseEvent = event;
674
- const mousePosition = {
675
- x: mouseEvent.clientX,
676
- y: mouseEvent.clientY,
677
- };
678
- handleTooltipPosition(mousePosition);
679
- lastFloatPosition.current = mousePosition;
680
- };
681
- const handleClickOutsideAnchors = (event) => {
682
- var _a;
683
- if (!show) {
684
- return;
685
- }
686
- const target = event.target;
687
- if (!target.isConnected) {
688
- return;
689
- }
690
- if ((_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.contains(target)) {
691
- return;
692
- }
693
- const anchorById = document.querySelector(`[id='${anchorId}']`);
694
- const anchors = [anchorById, ...anchorsBySelect];
695
- if (anchors.some((anchor) => anchor === null || anchor === void 0 ? void 0 : anchor.contains(target))) {
696
- return;
697
- }
698
- handleShow(false);
699
- if (tooltipShowDelayTimerRef.current) {
700
- clearTimeout(tooltipShowDelayTimerRef.current);
701
- }
702
- };
703
- // debounce handler to prevent call twice when
704
- // mouse enter and focus events being triggered toggether
705
- const internalDebouncedHandleShowTooltip = debounce(handleShowTooltip, 50, true);
706
- const internalDebouncedHandleHideTooltip = debounce(handleHideTooltip, 50, true);
707
- // If either of the functions is called while the other is still debounced,
708
- // reset the timeout. Otherwise if there is a sub-50ms (leave A, enter B, leave B)
709
- // sequence of events, the tooltip will stay open because the hide debounce
710
- // from leave A prevented the leave B event from calling it, leaving the
711
- // tooltip visible.
712
- const debouncedHandleShowTooltip = (e) => {
713
- internalDebouncedHandleHideTooltip.cancel();
714
- internalDebouncedHandleShowTooltip(e);
715
- };
716
- const debouncedHandleHideTooltip = () => {
717
- internalDebouncedHandleShowTooltip.cancel();
718
- internalDebouncedHandleHideTooltip();
719
- };
429
+ }, [imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.place, place, offset, positionStrategy, middlewares, border]);
720
430
  const updateTooltipPosition = React.useCallback(() => {
721
431
  var _a, _b;
722
432
  const actualPosition = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.position) !== null && _a !== void 0 ? _a : position;
@@ -759,33 +469,184 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
759
469
  handleComputedPosition(computedStylesData);
760
470
  });
761
471
  }, [
762
- show,
472
+ imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.position,
473
+ imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.place,
474
+ position,
475
+ float,
763
476
  activeAnchor,
764
- content,
765
- externalStyles,
766
477
  place,
767
- imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.place,
768
478
  offset,
769
479
  positionStrategy,
770
- position,
771
- imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.position,
772
- float,
480
+ middlewares,
481
+ border,
482
+ handleTooltipPosition,
773
483
  ]);
774
484
  React.useEffect(() => {
775
- var _a, _b;
776
- const elementRefs = new Set(anchorRefs);
777
- anchorsBySelect.forEach((anchor) => {
778
- elementRefs.add({ current: anchor });
779
- });
780
- const anchorById = document.querySelector(`[id='${anchorId}']`);
781
- if (anchorById) {
782
- elementRefs.add({ current: anchorById });
783
- }
485
+ /**
486
+ * TODO(V6): break this effect down into callbacks for clarity
487
+ * - `handleKeyboardEvents()`
488
+ * - `handleMouseEvents()`
489
+ * - `handleGlobalCloseEvents()`
490
+ * - `handleAnchorEvents()`
491
+ * - ...
492
+ */
493
+ const handlePointerMove = (event) => {
494
+ if (!event) {
495
+ return;
496
+ }
497
+ const mouseEvent = event;
498
+ const mousePosition = {
499
+ x: mouseEvent.clientX,
500
+ y: mouseEvent.clientY,
501
+ };
502
+ handleTooltipPosition(mousePosition);
503
+ lastFloatPosition.current = mousePosition;
504
+ };
505
+ const handleClickOutsideAnchors = (event) => {
506
+ var _a;
507
+ if (!show) {
508
+ return;
509
+ }
510
+ const target = event.target;
511
+ if (!target.isConnected) {
512
+ return;
513
+ }
514
+ if ((_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.contains(target)) {
515
+ return;
516
+ }
517
+ if (anchorElements.some((anchor) => anchor === null || anchor === void 0 ? void 0 : anchor.contains(target))) {
518
+ return;
519
+ }
520
+ handleShow(false);
521
+ if (tooltipShowDelayTimerRef.current) {
522
+ clearTimeout(tooltipShowDelayTimerRef.current);
523
+ }
524
+ };
525
+ const handleShowTooltip = (event) => {
526
+ var _a;
527
+ if (!event) {
528
+ return;
529
+ }
530
+ const target = ((_a = event.currentTarget) !== null && _a !== void 0 ? _a : event.target);
531
+ if (!(target === null || target === void 0 ? void 0 : target.isConnected)) {
532
+ /**
533
+ * this happens when the target is removed from the DOM
534
+ * at the same time the tooltip gets triggered
535
+ */
536
+ setActiveAnchor(null);
537
+ return;
538
+ }
539
+ if (delayShow) {
540
+ handleShowTooltipDelayed();
541
+ }
542
+ else {
543
+ handleShow(true);
544
+ }
545
+ setActiveAnchor(target);
546
+ if (tooltipHideDelayTimerRef.current) {
547
+ clearTimeout(tooltipHideDelayTimerRef.current);
548
+ }
549
+ };
550
+ const handleHideTooltip = () => {
551
+ if (clickable) {
552
+ // allow time for the mouse to reach the tooltip, in case there's a gap
553
+ handleHideTooltipDelayed(delayHide || 100);
554
+ }
555
+ else if (delayHide) {
556
+ handleHideTooltipDelayed();
557
+ }
558
+ else {
559
+ handleShow(false);
560
+ }
561
+ if (tooltipShowDelayTimerRef.current) {
562
+ clearTimeout(tooltipShowDelayTimerRef.current);
563
+ }
564
+ };
565
+ // debounce handler to prevent call twice when
566
+ // mouse enter and focus events being triggered toggether
567
+ const internalDebouncedHandleShowTooltip = debounce(handleShowTooltip, 50, true);
568
+ const internalDebouncedHandleHideTooltip = debounce(handleHideTooltip, 50, true);
569
+ // If either of the functions is called while the other is still debounced,
570
+ // reset the timeout. Otherwise if there is a sub-50ms (leave A, enter B, leave B)
571
+ // sequence of events, the tooltip will stay open because the hide debounce
572
+ // from leave A prevented the leave B event from calling it, leaving the
573
+ // tooltip visible.
574
+ const debouncedHandleShowTooltip = (e) => {
575
+ internalDebouncedHandleHideTooltip.cancel();
576
+ internalDebouncedHandleShowTooltip(e);
577
+ };
578
+ const debouncedHandleHideTooltip = () => {
579
+ internalDebouncedHandleShowTooltip.cancel();
580
+ internalDebouncedHandleHideTooltip();
581
+ };
784
582
  const handleScrollResize = () => {
785
583
  handleShow(false);
786
584
  };
787
- const anchorScrollParent = getScrollParent(activeAnchor);
585
+ const hasClickEvent = openOnClick || (openEvents === null || openEvents === void 0 ? void 0 : openEvents.click) || (openEvents === null || openEvents === void 0 ? void 0 : openEvents.dblclick) || (openEvents === null || openEvents === void 0 ? void 0 : openEvents.mousedown);
586
+ const actualOpenEvents = openEvents
587
+ ? { ...openEvents }
588
+ : {
589
+ mouseenter: true,
590
+ focus: true,
591
+ click: false,
592
+ dblclick: false,
593
+ mousedown: false,
594
+ };
595
+ if (!openEvents && openOnClick) {
596
+ Object.assign(actualOpenEvents, {
597
+ mouseenter: false,
598
+ focus: false,
599
+ click: true,
600
+ });
601
+ }
602
+ const actualCloseEvents = closeEvents
603
+ ? { ...closeEvents }
604
+ : {
605
+ mouseleave: true,
606
+ blur: true,
607
+ click: false,
608
+ dblclick: false,
609
+ mouseup: false,
610
+ };
611
+ if (!closeEvents && openOnClick) {
612
+ Object.assign(actualCloseEvents, {
613
+ mouseleave: false,
614
+ blur: false,
615
+ });
616
+ }
617
+ const actualGlobalCloseEvents = globalCloseEvents
618
+ ? { ...globalCloseEvents }
619
+ : {
620
+ escape: false,
621
+ scroll: false,
622
+ resize: false,
623
+ clickOutsideAnchor: hasClickEvent || false,
624
+ };
625
+ if (imperativeModeOnly) {
626
+ Object.assign(actualOpenEvents, {
627
+ mouseenter: false,
628
+ focus: false,
629
+ click: false,
630
+ dblclick: false,
631
+ mousedown: false,
632
+ });
633
+ Object.assign(actualCloseEvents, {
634
+ mouseleave: false,
635
+ blur: false,
636
+ click: false,
637
+ dblclick: false,
638
+ mouseup: false,
639
+ });
640
+ Object.assign(actualGlobalCloseEvents, {
641
+ escape: false,
642
+ scroll: false,
643
+ resize: false,
644
+ clickOutsideAnchor: false,
645
+ });
646
+ }
647
+ const tooltipElement = tooltipRef.current;
788
648
  const tooltipScrollParent = getScrollParent(tooltipRef.current);
649
+ const anchorScrollParent = getScrollParent(activeAnchor);
789
650
  if (actualGlobalCloseEvents.scroll) {
790
651
  window.addEventListener('scroll', handleScrollResize);
791
652
  anchorScrollParent === null || anchorScrollParent === void 0 ? void 0 : anchorScrollParent.addEventListener('scroll', handleScrollResize);
@@ -878,17 +739,15 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
878
739
  if (clickable && !hasClickEvent) {
879
740
  // used to keep the tooltip open when hovering content.
880
741
  // not needed if using click events.
881
- (_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener('mouseenter', handleMouseEnterTooltip);
882
- (_b = tooltipRef.current) === null || _b === void 0 ? void 0 : _b.addEventListener('mouseleave', handleMouseLeaveTooltip);
742
+ tooltipElement === null || tooltipElement === void 0 ? void 0 : tooltipElement.addEventListener('mouseenter', handleMouseEnterTooltip);
743
+ tooltipElement === null || tooltipElement === void 0 ? void 0 : tooltipElement.addEventListener('mouseleave', handleMouseLeaveTooltip);
883
744
  }
884
745
  enabledEvents.forEach(({ event, listener }) => {
885
- elementRefs.forEach((ref) => {
886
- var _a;
887
- (_a = ref.current) === null || _a === void 0 ? void 0 : _a.addEventListener(event, listener);
746
+ anchorElements.forEach((anchor) => {
747
+ anchor.addEventListener(event, listener);
888
748
  });
889
749
  });
890
750
  return () => {
891
- var _a, _b;
892
751
  if (actualGlobalCloseEvents.scroll) {
893
752
  window.removeEventListener('scroll', handleScrollResize);
894
753
  anchorScrollParent === null || anchorScrollParent === void 0 ? void 0 : anchorScrollParent.removeEventListener('scroll', handleScrollResize);
@@ -907,13 +766,12 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
907
766
  window.removeEventListener('keydown', handleEsc);
908
767
  }
909
768
  if (clickable && !hasClickEvent) {
910
- (_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('mouseenter', handleMouseEnterTooltip);
911
- (_b = tooltipRef.current) === null || _b === void 0 ? void 0 : _b.removeEventListener('mouseleave', handleMouseLeaveTooltip);
769
+ tooltipElement === null || tooltipElement === void 0 ? void 0 : tooltipElement.removeEventListener('mouseenter', handleMouseEnterTooltip);
770
+ tooltipElement === null || tooltipElement === void 0 ? void 0 : tooltipElement.removeEventListener('mouseleave', handleMouseLeaveTooltip);
912
771
  }
913
772
  enabledEvents.forEach(({ event, listener }) => {
914
- elementRefs.forEach((ref) => {
915
- var _a;
916
- (_a = ref.current) === null || _a === void 0 ? void 0 : _a.removeEventListener(event, listener);
773
+ anchorElements.forEach((anchor) => {
774
+ anchor.removeEventListener(event, listener);
917
775
  });
918
776
  });
919
777
  };
@@ -923,61 +781,62 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
923
781
  */
924
782
  }, [
925
783
  activeAnchor,
926
- updateTooltipPosition,
927
- rendered,
928
- anchorRefs,
929
- anchorsBySelect,
930
- // the effect uses the `actual*Events` objects, but this should work
931
- openEvents,
784
+ anchorElements,
785
+ clickable,
932
786
  closeEvents,
933
- globalCloseEvents,
934
- shouldOpenOnClick,
935
- delayShow,
936
787
  delayHide,
788
+ delayShow,
789
+ float,
790
+ globalCloseEvents,
791
+ handleHideTooltipDelayed,
792
+ handleShow,
793
+ handleShowTooltipDelayed,
794
+ handleTooltipPosition,
795
+ imperativeModeOnly,
796
+ openEvents,
797
+ openOnClick,
798
+ setActiveAnchor,
799
+ show,
800
+ updateTooltipPosition,
937
801
  ]);
938
802
  React.useEffect(() => {
939
803
  var _a, _b;
804
+ /**
805
+ * TODO(V6): break down observer callback for clarity
806
+ * - `handleAddedAnchors()`
807
+ * - `handleRemovedAnchors()`
808
+ */
940
809
  let selector = (_b = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect) !== null && _a !== void 0 ? _a : anchorSelect) !== null && _b !== void 0 ? _b : '';
941
810
  if (!selector && id) {
942
811
  selector = `[data-tooltip-id='${id.replace(/'/g, "\\'")}']`;
943
812
  }
944
813
  const documentObserverCallback = (mutationList) => {
945
- const newAnchors = [];
946
- const removedAnchors = [];
814
+ const addedAnchors = new Set();
815
+ const removedAnchors = new Set();
947
816
  mutationList.forEach((mutation) => {
948
817
  if (mutation.type === 'attributes' && mutation.attributeName === 'data-tooltip-id') {
949
- const newId = mutation.target.getAttribute('data-tooltip-id');
818
+ const target = mutation.target;
819
+ const newId = target.getAttribute('data-tooltip-id');
950
820
  if (newId === id) {
951
- newAnchors.push(mutation.target);
821
+ addedAnchors.add(target);
952
822
  }
953
823
  else if (mutation.oldValue === id) {
954
824
  // data-tooltip-id has now been changed, so we need to remove this anchor
955
- removedAnchors.push(mutation.target);
825
+ removedAnchors.add(target);
956
826
  }
957
827
  }
958
828
  if (mutation.type !== 'childList') {
959
829
  return;
960
830
  }
831
+ const removedNodes = [...mutation.removedNodes].filter((node) => node.nodeType === 1);
961
832
  if (activeAnchor) {
962
- const elements = [...mutation.removedNodes].filter((node) => node.nodeType === 1);
963
- if (selector) {
964
- try {
965
- removedAnchors.push(
966
- // the element itself is an anchor
967
- ...elements.filter((element) => element.matches(selector)));
968
- removedAnchors.push(
969
- // the element has children which are anchors
970
- ...elements.flatMap((element) => [...element.querySelectorAll(selector)]));
971
- }
972
- catch (_a) {
973
- /**
974
- * invalid CSS selector.
975
- * already warned on tooltip controller
976
- */
977
- }
978
- }
979
- elements.some((node) => {
833
+ removedNodes.some((node) => {
980
834
  var _a;
835
+ /**
836
+ * TODO(V6)
837
+ * - isn't `!activeAnchor.isConnected` better?
838
+ * - maybe move to `handleDisconnectedAnchor()`
839
+ */
981
840
  if ((_a = node === null || node === void 0 ? void 0 : node.contains) === null || _a === void 0 ? void 0 : _a.call(node, activeAnchor)) {
982
841
  setRendered(false);
983
842
  handleShow(false);
@@ -997,25 +856,67 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
997
856
  return;
998
857
  }
999
858
  try {
1000
- const elements = [...mutation.addedNodes].filter((node) => node.nodeType === 1);
1001
- newAnchors.push(
1002
- // the element itself is an anchor
1003
- ...elements.filter((element) => element.matches(selector)));
1004
- newAnchors.push(
1005
- // the element has children which are anchors
1006
- ...elements.flatMap((element) => [...element.querySelectorAll(selector)]));
859
+ removedNodes.forEach((node) => {
860
+ const element = node;
861
+ if (element.matches(selector)) {
862
+ // the element itself is an anchor
863
+ removedAnchors.add(element);
864
+ }
865
+ else {
866
+ /**
867
+ * TODO(V6): do we care if an element which is an anchor,
868
+ * has children which are also anchors?
869
+ * (i.e. should we remove `else` and always do this)
870
+ */
871
+ // the element has children which are anchors
872
+ element
873
+ .querySelectorAll(selector)
874
+ .forEach((innerNode) => removedAnchors.add(innerNode));
875
+ }
876
+ });
877
+ }
878
+ catch (_a) {
879
+ /* c8 ignore start */
880
+ {
881
+ // eslint-disable-next-line no-console
882
+ console.warn(`[react-tooltip] "${selector}" is not a valid CSS selector`);
883
+ }
884
+ /* c8 ignore end */
885
+ }
886
+ try {
887
+ const addedNodes = [...mutation.addedNodes].filter((node) => node.nodeType === 1);
888
+ addedNodes.forEach((node) => {
889
+ const element = node;
890
+ if (element.matches(selector)) {
891
+ // the element itself is an anchor
892
+ addedAnchors.add(element);
893
+ }
894
+ else {
895
+ /**
896
+ * TODO(V6): do we care if an element which is an anchor,
897
+ * has children which are also anchors?
898
+ * (i.e. should we remove `else` and always do this)
899
+ */
900
+ // the element has children which are anchors
901
+ element
902
+ .querySelectorAll(selector)
903
+ .forEach((innerNode) => addedAnchors.add(innerNode));
904
+ }
905
+ });
1007
906
  }
1008
907
  catch (_b) {
1009
- /**
1010
- * invalid CSS selector.
1011
- * already warned on tooltip controller
1012
- */
908
+ /* c8 ignore start */
909
+ {
910
+ // eslint-disable-next-line no-console
911
+ console.warn(`[react-tooltip] "${selector}" is not a valid CSS selector`);
912
+ }
913
+ /* c8 ignore end */
1013
914
  }
1014
915
  });
1015
- if (newAnchors.length || removedAnchors.length) {
1016
- setAnchorsBySelect((anchors) => [
1017
- ...anchors.filter((anchor) => !removedAnchors.includes(anchor)),
1018
- ...newAnchors,
916
+ if (addedAnchors.size || removedAnchors.size) {
917
+ setAnchorElements((anchors) => [
918
+ ...anchors.filter((anchor) => !removedAnchors.has(anchor)),
919
+ ...addedAnchors,
1019
920
  ]);
1020
921
  }
1021
922
  };
@@ -1032,7 +933,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1032
933
  return () => {
1033
934
  documentObserver.disconnect();
1034
935
  };
1035
- }, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect, activeAnchor]);
936
+ }, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect, activeAnchor, handleShow, setActiveAnchor]);
1036
937
  React.useEffect(() => {
1037
938
  updateTooltipPosition();
1038
939
  }, [updateTooltipPosition]);
@@ -1047,20 +948,18 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1047
948
  return () => {
1048
949
  contentObserver.disconnect();
1049
950
  };
1050
- }, [content, contentWrapperRef === null || contentWrapperRef === void 0 ? void 0 : contentWrapperRef.current]);
951
+ }, [content, contentWrapperRef, updateTooltipPosition]);
1051
952
  React.useEffect(() => {
1052
953
  var _a;
1053
- const anchorById = document.querySelector(`[id='${anchorId}']`);
1054
- const anchors = [...anchorsBySelect, anchorById];
1055
- if (!activeAnchor || !anchors.includes(activeAnchor)) {
954
+ if (!activeAnchor || !anchorElements.includes(activeAnchor)) {
1056
955
  /**
1057
956
  * if there is no active anchor,
1058
957
  * or if the current active anchor is not amongst the allowed ones,
1059
958
  * reset it
1060
959
  */
1061
- setActiveAnchor((_a = anchorsBySelect[0]) !== null && _a !== void 0 ? _a : anchorById);
960
+ setActiveAnchor((_a = anchorElements[0]) !== null && _a !== void 0 ? _a : null);
1062
961
  }
1063
- }, [anchorId, anchorsBySelect, activeAnchor]);
962
+ }, [anchorElements, activeAnchor, setActiveAnchor]);
1064
963
  React.useEffect(() => {
1065
964
  if (defaultIsOpen) {
1066
965
  handleShow(true);
@@ -1073,7 +972,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1073
972
  clearTimeout(tooltipHideDelayTimerRef.current);
1074
973
  }
1075
974
  };
1076
- }, []);
975
+ }, [defaultIsOpen, handleShow]);
1077
976
  React.useEffect(() => {
1078
977
  var _a;
1079
978
  let selector = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect) !== null && _a !== void 0 ? _a : anchorSelect;
@@ -1085,11 +984,11 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1085
984
  }
1086
985
  try {
1087
986
  const anchors = Array.from(document.querySelectorAll(selector));
1088
- setAnchorsBySelect(anchors);
987
+ setAnchorElements(anchors);
1089
988
  }
1090
989
  catch (_b) {
1091
990
  // warning was already issued in the controller
1092
- setAnchorsBySelect([]);
991
+ setAnchorElements([]);
1093
992
  }
1094
993
  }, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect]);
1095
994
  React.useEffect(() => {
@@ -1097,7 +996,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1097
996
  clearTimeout(tooltipShowDelayTimerRef.current);
1098
997
  handleShowTooltipDelayed(delayShow);
1099
998
  }
1100
- }, [delayShow]);
999
+ }, [delayShow, handleShowTooltipDelayed]);
1101
1000
  const actualContent = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.content) !== null && _a !== void 0 ? _a : content;
1102
1001
  const canShow = show && Object.keys(computedPosition.tooltipStyles).length > 0;
1103
1002
  React.useImperativeHandle(forwardRef, () => ({
@@ -1134,7 +1033,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1134
1033
  place: computedPosition.place,
1135
1034
  isOpen: Boolean(rendered && !hidden && actualContent && canShow),
1136
1035
  }));
1137
- return rendered && !hidden && actualContent ? (React__default["default"].createElement(WrapperElement, { id: id, role: role, className: classNames__default["default"]('react-tooltip', coreStyles['tooltip'], styles['tooltip'], styles[variant], className, `react-tooltip__place-${computedPosition.place}`, coreStyles[canShow ? 'show' : 'closing'], canShow ? 'react-tooltip__show' : 'react-tooltip__closing', positionStrategy === 'fixed' && coreStyles['fixed'], clickable && coreStyles['clickable']), onTransitionEnd: (event) => {
1036
+ return rendered && !hidden && actualContent ? (React.createElement(WrapperElement, { id: id, role: role, className: clsx('react-tooltip', coreStyles['tooltip'], styles['tooltip'], styles[variant], className, `react-tooltip__place-${computedPosition.place}`, coreStyles[canShow ? 'show' : 'closing'], canShow ? 'react-tooltip__show' : 'react-tooltip__closing', positionStrategy === 'fixed' && coreStyles['fixed'], clickable && coreStyles['clickable']), onTransitionEnd: (event) => {
1138
1037
  if (missedTransitionTimerRef.current) {
1139
1038
  clearTimeout(missedTransitionTimerRef.current);
1140
1039
  }
@@ -1150,7 +1049,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1150
1049
  opacity: opacity !== undefined && canShow ? opacity : undefined,
1151
1050
  }, ref: tooltipRef },
1152
1051
  actualContent,
1153
- React__default["default"].createElement(WrapperElement, { className: classNames__default["default"]('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, noArrow && coreStyles['noArrow']), style: {
1052
+ React.createElement(WrapperElement, { className: clsx('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, noArrow && coreStyles['noArrow']), style: {
1154
1053
  ...computedPosition.tooltipArrowStyles,
1155
1054
  background: arrowColor
1156
1055
  ? `linear-gradient(to right bottom, transparent 50%, ${arrowColor} 50%)`
@@ -1158,14 +1057,8 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1158
1057
  }, ref: tooltipArrowRef }))) : null;
1159
1058
  };
1160
1059
 
1161
- /* eslint-disable react/no-danger */
1162
- const TooltipContent = ({ content }) => {
1163
- return React__default["default"].createElement("span", { dangerouslySetInnerHTML: { __html: content } });
1164
- };
1165
-
1166
- const TooltipController = React__default["default"].forwardRef(({ id, anchorId, anchorSelect, content, html, render, className, classNameArrow, variant = 'dark', place = 'top', offset = 10, wrapper = 'div', children = null, events = ['hover'], openOnClick = false, positionStrategy = 'absolute', middlewares, delayShow = 0, delayHide = 0, float = false, hidden = false, noArrow = false, clickable = false, closeOnEsc = false, closeOnScroll = false, closeOnResize = false, openEvents, closeEvents, globalCloseEvents, imperativeModeOnly = false, style, position, isOpen, defaultIsOpen = false, disableStyleInjection = false, border, opacity, arrowColor, setIsOpen, afterShow, afterHide, role = 'tooltip', }, ref) => {
1060
+ const TooltipController = React.forwardRef(({ id, anchorSelect, content, render, className, classNameArrow, variant = 'dark', place = 'top', offset = 10, wrapper = 'div', children = null, openOnClick = false, positionStrategy = 'absolute', middlewares, delayShow = 0, delayHide = 0, float = false, hidden = false, noArrow = false, clickable = false, openEvents, closeEvents, globalCloseEvents, imperativeModeOnly = false, style, position, isOpen, defaultIsOpen = false, disableStyleInjection = false, border, opacity, arrowColor, setIsOpen, afterShow, afterHide, role = 'tooltip', }, ref) => {
1167
1061
  const [tooltipContent, setTooltipContent] = React.useState(content);
1168
- const [tooltipHtml, setTooltipHtml] = React.useState(html);
1169
1062
  const [tooltipPlace, setTooltipPlace] = React.useState(place);
1170
1063
  const [tooltipVariant, setTooltipVariant] = React.useState(variant);
1171
1064
  const [tooltipOffset, setTooltipOffset] = React.useState(offset);
@@ -1174,15 +1067,10 @@ const TooltipController = React__default["default"].forwardRef(({ id, anchorId,
1174
1067
  const [tooltipFloat, setTooltipFloat] = React.useState(float);
1175
1068
  const [tooltipHidden, setTooltipHidden] = React.useState(hidden);
1176
1069
  const [tooltipWrapper, setTooltipWrapper] = React.useState(wrapper);
1177
- const [tooltipEvents, setTooltipEvents] = React.useState(events);
1178
1070
  const [tooltipPositionStrategy, setTooltipPositionStrategy] = React.useState(positionStrategy);
1179
1071
  const [tooltipClassName, setTooltipClassName] = React.useState(null);
1180
1072
  const [activeAnchor, setActiveAnchor] = React.useState(null);
1181
1073
  const styleInjectionRef = React.useRef(disableStyleInjection);
1182
- /**
1183
- * @todo Remove this in a future version (provider/wrapper method is deprecated)
1184
- */
1185
- const { anchorRefs, activeAnchor: providerActiveAnchor } = useTooltip(id);
1186
1074
  const getDataAttributesFromAnchorElement = (elementReference) => {
1187
1075
  const dataAttributes = elementReference === null || elementReference === void 0 ? void 0 : elementReference.getAttributeNames().reduce((acc, name) => {
1188
1076
  var _a;
@@ -1194,7 +1082,7 @@ const TooltipController = React__default["default"].forwardRef(({ id, anchorId,
1194
1082
  }, {});
1195
1083
  return dataAttributes;
1196
1084
  };
1197
- const applyAllDataAttributesFromAnchorElement = (dataAttributes) => {
1085
+ const applyAllDataAttributesFromAnchorElement = React.useCallback((dataAttributes) => {
1198
1086
  const handleDataAttributes = {
1199
1087
  place: (value) => {
1200
1088
  var _a;
@@ -1203,9 +1091,6 @@ const TooltipController = React__default["default"].forwardRef(({ id, anchorId,
1203
1091
  content: (value) => {
1204
1092
  setTooltipContent(value !== null && value !== void 0 ? value : content);
1205
1093
  },
1206
- html: (value) => {
1207
- setTooltipHtml(value !== null && value !== void 0 ? value : html);
1208
- },
1209
1094
  variant: (value) => {
1210
1095
  var _a;
1211
1096
  setTooltipVariant((_a = value) !== null && _a !== void 0 ? _a : variant);
@@ -1217,10 +1102,6 @@ const TooltipController = React__default["default"].forwardRef(({ id, anchorId,
1217
1102
  var _a;
1218
1103
  setTooltipWrapper((_a = value) !== null && _a !== void 0 ? _a : wrapper);
1219
1104
  },
1220
- events: (value) => {
1221
- const parsed = value === null || value === void 0 ? void 0 : value.split(' ');
1222
- setTooltipEvents(parsed !== null && parsed !== void 0 ? parsed : events);
1223
- },
1224
1105
  'position-strategy': (value) => {
1225
1106
  var _a;
1226
1107
  setTooltipPositionStrategy((_a = value) !== null && _a !== void 0 ? _a : positionStrategy);
@@ -1248,13 +1129,21 @@ const TooltipController = React__default["default"].forwardRef(({ id, anchorId,
1248
1129
  var _a;
1249
1130
  (_a = handleDataAttributes[key]) === null || _a === void 0 ? void 0 : _a.call(handleDataAttributes, value);
1250
1131
  });
1251
- };
1132
+ }, [
1133
+ content,
1134
+ delayHide,
1135
+ delayShow,
1136
+ float,
1137
+ hidden,
1138
+ offset,
1139
+ place,
1140
+ positionStrategy,
1141
+ variant,
1142
+ wrapper,
1143
+ ]);
1252
1144
  React.useEffect(() => {
1253
1145
  setTooltipContent(content);
1254
1146
  }, [content]);
1255
- React.useEffect(() => {
1256
- setTooltipHtml(html);
1257
- }, [html]);
1258
1147
  React.useEffect(() => {
1259
1148
  setTooltipPlace(place);
1260
1149
  }, [place]);
@@ -1299,48 +1188,19 @@ const TooltipController = React__default["default"].forwardRef(({ id, anchorId,
1299
1188
  },
1300
1189
  }));
1301
1190
  }
1191
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1302
1192
  }, []);
1303
1193
  React.useEffect(() => {
1304
- var _a;
1305
- const elementRefs = new Set(anchorRefs);
1306
- let selector = anchorSelect;
1307
- if (!selector && id) {
1308
- selector = `[data-tooltip-id='${id.replace(/'/g, "\\'")}']`;
1309
- }
1310
- if (selector) {
1311
- try {
1312
- const anchorsBySelect = document.querySelectorAll(selector);
1313
- anchorsBySelect.forEach((anchor) => {
1314
- elementRefs.add({ current: anchor });
1315
- });
1316
- }
1317
- catch (_b) {
1318
- /* c8 ignore start */
1319
- {
1320
- // eslint-disable-next-line no-console
1321
- console.warn(`[react-tooltip] "${selector}" is not a valid CSS selector`);
1322
- }
1323
- /* c8 ignore end */
1324
- }
1325
- }
1326
- const anchorById = document.querySelector(`[id='${anchorId}']`);
1327
- if (anchorById) {
1328
- elementRefs.add({ current: anchorById });
1329
- }
1330
- if (!elementRefs.size) {
1331
- return () => null;
1332
- }
1333
- const anchorElement = (_a = activeAnchor !== null && activeAnchor !== void 0 ? activeAnchor : anchorById) !== null && _a !== void 0 ? _a : providerActiveAnchor.current;
1334
1194
  const observerCallback = (mutationList) => {
1335
1195
  mutationList.forEach((mutation) => {
1336
1196
  var _a;
1337
- if (!anchorElement ||
1197
+ if (!activeAnchor ||
1338
1198
  mutation.type !== 'attributes' ||
1339
1199
  !((_a = mutation.attributeName) === null || _a === void 0 ? void 0 : _a.startsWith('data-tooltip-'))) {
1340
1200
  return;
1341
1201
  }
1342
1202
  // make sure to get all set attributes, since all unset attributes are reset
1343
- const dataAttributes = getDataAttributesFromAnchorElement(anchorElement);
1203
+ const dataAttributes = getDataAttributesFromAnchorElement(activeAnchor);
1344
1204
  applyAllDataAttributesFromAnchorElement(dataAttributes);
1345
1205
  });
1346
1206
  };
@@ -1349,17 +1209,17 @@ const TooltipController = React__default["default"].forwardRef(({ id, anchorId,
1349
1209
  // do not check for subtree and childrens, we only want to know attribute changes
1350
1210
  // to stay watching `data-attributes-*` from anchor element
1351
1211
  const observerConfig = { attributes: true, childList: false, subtree: false };
1352
- if (anchorElement) {
1353
- const dataAttributes = getDataAttributesFromAnchorElement(anchorElement);
1212
+ if (activeAnchor) {
1213
+ const dataAttributes = getDataAttributesFromAnchorElement(activeAnchor);
1354
1214
  applyAllDataAttributesFromAnchorElement(dataAttributes);
1355
1215
  // Start observing the target node for configured mutations
1356
- observer.observe(anchorElement, observerConfig);
1216
+ observer.observe(activeAnchor, observerConfig);
1357
1217
  }
1358
1218
  return () => {
1359
1219
  // Remove the observer when the tooltip is destroyed
1360
1220
  observer.disconnect();
1361
1221
  };
1362
- }, [anchorRefs, providerActiveAnchor, activeAnchor, anchorId, anchorSelect]);
1222
+ }, [activeAnchor, anchorSelect, applyAllDataAttributesFromAnchorElement]);
1363
1223
  React.useEffect(() => {
1364
1224
  /* c8 ignore end */
1365
1225
  if (style === null || style === void 0 ? void 0 : style.border) {
@@ -1378,7 +1238,7 @@ const TooltipController = React__default["default"].forwardRef(({ id, anchorId,
1378
1238
  // eslint-disable-next-line no-console
1379
1239
  console.warn(`[react-tooltip] "${opacity}" is not a valid \`opacity\`.`);
1380
1240
  }
1381
- }, []);
1241
+ }, [border, opacity, style === null || style === void 0 ? void 0 : style.border, style === null || style === void 0 ? void 0 : style.opacity]);
1382
1242
  /**
1383
1243
  * content priority: children < render or content < html
1384
1244
  * children should be lower priority so that it can be used as the "default" content
@@ -1388,20 +1248,16 @@ const TooltipController = React__default["default"].forwardRef(({ id, anchorId,
1388
1248
  if (render) {
1389
1249
  const actualContent = (activeAnchor === null || activeAnchor === void 0 ? void 0 : activeAnchor.getAttribute('data-tooltip-content')) || tooltipContent || null;
1390
1250
  const rendered = render({ content: actualContent, activeAnchor });
1391
- renderedContent = rendered ? (React__default["default"].createElement("div", { ref: contentWrapperRef, className: "react-tooltip-content-wrapper" }, rendered)) : null;
1251
+ renderedContent = rendered ? (React.createElement("div", { ref: contentWrapperRef, className: "react-tooltip-content-wrapper" }, rendered)) : null;
1392
1252
  }
1393
1253
  else if (tooltipContent) {
1394
1254
  renderedContent = tooltipContent;
1395
1255
  }
1396
- if (tooltipHtml) {
1397
- renderedContent = React__default["default"].createElement(TooltipContent, { content: tooltipHtml });
1398
- }
1399
1256
  const props = {
1400
1257
  forwardRef: ref,
1401
1258
  id,
1402
- anchorId,
1403
1259
  anchorSelect,
1404
- className: classNames__default["default"](className, tooltipClassName),
1260
+ className: clsx(className, tooltipClassName),
1405
1261
  classNameArrow,
1406
1262
  content: renderedContent,
1407
1263
  contentWrapperRef,
@@ -1409,7 +1265,6 @@ const TooltipController = React__default["default"].forwardRef(({ id, anchorId,
1409
1265
  variant: tooltipVariant,
1410
1266
  offset: tooltipOffset,
1411
1267
  wrapper: tooltipWrapper,
1412
- events: tooltipEvents,
1413
1268
  openOnClick,
1414
1269
  positionStrategy: tooltipPositionStrategy,
1415
1270
  middlewares,
@@ -1419,9 +1274,6 @@ const TooltipController = React__default["default"].forwardRef(({ id, anchorId,
1419
1274
  hidden: tooltipHidden,
1420
1275
  noArrow,
1421
1276
  clickable,
1422
- closeOnEsc,
1423
- closeOnScroll,
1424
- closeOnResize,
1425
1277
  openEvents,
1426
1278
  closeEvents,
1427
1279
  globalCloseEvents,
@@ -1437,10 +1289,10 @@ const TooltipController = React__default["default"].forwardRef(({ id, anchorId,
1437
1289
  afterShow,
1438
1290
  afterHide,
1439
1291
  activeAnchor,
1440
- setActiveAnchor: (anchor) => setActiveAnchor(anchor),
1292
+ setActiveAnchor,
1441
1293
  role,
1442
1294
  };
1443
- return React__default["default"].createElement(Tooltip, { ...props });
1295
+ return React.createElement(Tooltip, { ...props });
1444
1296
  });
1445
1297
 
1446
1298
  // those content will be replaced in build time with the `react-tooltip.css` builded content
@@ -1566,6 +1418,4 @@ if (typeof window !== 'undefined') {
1566
1418
  }
1567
1419
 
1568
1420
  exports.Tooltip = TooltipController;
1569
- exports.TooltipProvider = TooltipProvider;
1570
- exports.TooltipWrapper = TooltipWrapper;
1571
- exports.removeStyle = removeStyle;
1421
+ //# sourceMappingURL=react-tooltip.cjs.map