react-tooltip 5.26.1-beta.1169.0 → 5.26.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.
@@ -344,28 +344,6 @@ const cssTimeToMs = (time) => {
344
344
  return Number(amount) * (unit === 'ms' ? 1 : 1000);
345
345
  };
346
346
 
347
- const isObject = (object) => {
348
- return object !== null && typeof object === 'object';
349
- };
350
- const deepEqual = (object1, object2) => {
351
- if (!isObject(object1) || !isObject(object2)) {
352
- return object1 === object2;
353
- }
354
- const keys1 = Object.keys(object1);
355
- const keys2 = Object.keys(object2);
356
- if (keys1.length !== keys2.length) {
357
- return false;
358
- }
359
- return keys1.every((key) => {
360
- const val1 = object1[key];
361
- const val2 = object2[key];
362
- if (isObject(val1) && isObject(val2)) {
363
- return deepEqual(val1, val2);
364
- }
365
- return val1 === val2;
366
- });
367
- };
368
-
369
347
  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"};
370
348
 
371
349
  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"};
@@ -376,17 +354,14 @@ forwardRef, id, className, classNameArrow, variant = 'dark', anchorId, anchorSel
376
354
  // props handled by controller
377
355
  content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, role = 'tooltip', }) => {
378
356
  var _a;
379
- console.log('render');
380
357
  const tooltipRef = useRef(null);
381
358
  const tooltipArrowRef = useRef(null);
382
359
  const tooltipShowDelayTimerRef = useRef(null);
383
360
  const tooltipHideDelayTimerRef = useRef(null);
384
361
  const missedTransitionTimerRef = useRef(null);
385
- const [computedPosition, setComputedPosition] = useState({
386
- tooltipStyles: {},
387
- tooltipArrowStyles: {},
388
- place,
389
- });
362
+ const [actualPlacement, setActualPlacement] = useState(place);
363
+ const [inlineStyles, setInlineStyles] = useState({});
364
+ const [inlineArrowStyles, setInlineArrowStyles] = useState({});
390
365
  const [show, setShow] = useState(false);
391
366
  const [rendered, setRendered] = useState(false);
392
367
  const [imperativeOptions, setImperativeOptions] = useState(null);
@@ -544,15 +519,15 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
544
519
  }, transitionShowDelay + 25);
545
520
  }
546
521
  }, [show]);
547
- const handleComputedPosition = (newComputedPosition) => {
548
- setComputedPosition((oldComputedPosition) => deepEqual(oldComputedPosition, newComputedPosition)
549
- ? oldComputedPosition
550
- : newComputedPosition);
551
- };
552
522
  const handleShowTooltipDelayed = (delay = delayShow) => {
553
523
  if (tooltipShowDelayTimerRef.current) {
554
524
  clearTimeout(tooltipShowDelayTimerRef.current);
555
525
  }
526
+ if (rendered) {
527
+ // if the tooltip is already rendered, ignore delay
528
+ handleShow(true);
529
+ return;
530
+ }
556
531
  tooltipShowDelayTimerRef.current = setTimeout(() => {
557
532
  handleShow(true);
558
533
  }, delay);
@@ -636,7 +611,13 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
636
611
  middlewares,
637
612
  border,
638
613
  }).then((computedStylesData) => {
639
- handleComputedPosition(computedStylesData);
614
+ if (Object.keys(computedStylesData.tooltipStyles).length) {
615
+ setInlineStyles(computedStylesData.tooltipStyles);
616
+ }
617
+ if (Object.keys(computedStylesData.tooltipArrowStyles).length) {
618
+ setInlineArrowStyles(computedStylesData.tooltipArrowStyles);
619
+ }
620
+ setActualPlacement(computedStylesData.place);
640
621
  });
641
622
  };
642
623
  const handlePointerMove = (event) => {
@@ -657,6 +638,9 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
657
638
  return;
658
639
  }
659
640
  const target = event.target;
641
+ if (!target.isConnected) {
642
+ return;
643
+ }
660
644
  if ((_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.contains(target)) {
661
645
  return;
662
646
  }
@@ -726,7 +710,13 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
726
710
  // invalidate computed positions after remount
727
711
  return;
728
712
  }
729
- handleComputedPosition(computedStylesData);
713
+ if (Object.keys(computedStylesData.tooltipStyles).length) {
714
+ setInlineStyles(computedStylesData.tooltipStyles);
715
+ }
716
+ if (Object.keys(computedStylesData.tooltipArrowStyles).length) {
717
+ setInlineArrowStyles(computedStylesData.tooltipArrowStyles);
718
+ }
719
+ setActualPlacement(computedStylesData.place);
730
720
  });
731
721
  }, [
732
722
  show,
@@ -902,6 +892,8 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
902
892
  closeEvents,
903
893
  globalCloseEvents,
904
894
  shouldOpenOnClick,
895
+ delayShow,
896
+ delayHide,
905
897
  ]);
906
898
  useEffect(() => {
907
899
  var _a, _b;
@@ -1060,8 +1052,14 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1060
1052
  setAnchorsBySelect([]);
1061
1053
  }
1062
1054
  }, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect]);
1055
+ useEffect(() => {
1056
+ if (tooltipShowDelayTimerRef.current) {
1057
+ clearTimeout(tooltipShowDelayTimerRef.current);
1058
+ handleShowTooltipDelayed(delayShow);
1059
+ }
1060
+ }, [delayShow]);
1063
1061
  const actualContent = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.content) !== null && _a !== void 0 ? _a : content;
1064
- const canShow = show && Object.keys(computedPosition.tooltipStyles).length > 0;
1062
+ const canShow = show && Object.keys(inlineStyles).length > 0;
1065
1063
  useImperativeHandle(forwardRef, () => ({
1066
1064
  open: (options) => {
1067
1065
  if (options === null || options === void 0 ? void 0 : options.anchorSelect) {
@@ -1093,10 +1091,10 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1093
1091
  }
1094
1092
  },
1095
1093
  activeAnchor,
1096
- place: computedPosition.place,
1094
+ place: actualPlacement,
1097
1095
  isOpen: Boolean(rendered && !hidden && actualContent && canShow),
1098
1096
  }));
1099
- return rendered && !hidden && actualContent ? (React.createElement(WrapperElement, { id: id, role: role, className: classNames('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) => {
1097
+ return rendered && !hidden && actualContent ? (React.createElement(WrapperElement, { id: id, role: role, className: classNames('react-tooltip', coreStyles['tooltip'], styles['tooltip'], styles[variant], className, `react-tooltip__place-${actualPlacement}`, coreStyles[canShow ? 'show' : 'closing'], canShow ? 'react-tooltip__show' : 'react-tooltip__closing', positionStrategy === 'fixed' && coreStyles['fixed'], clickable && coreStyles['clickable']), onTransitionEnd: (event) => {
1100
1098
  if (missedTransitionTimerRef.current) {
1101
1099
  clearTimeout(missedTransitionTimerRef.current);
1102
1100
  }
@@ -1108,12 +1106,12 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1108
1106
  afterHide === null || afterHide === void 0 ? void 0 : afterHide();
1109
1107
  }, style: {
1110
1108
  ...externalStyles,
1111
- ...computedPosition.tooltipStyles,
1109
+ ...inlineStyles,
1112
1110
  opacity: opacity !== undefined && canShow ? opacity : undefined,
1113
1111
  }, ref: tooltipRef },
1114
1112
  actualContent,
1115
1113
  React.createElement(WrapperElement, { className: classNames('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, noArrow && coreStyles['noArrow']), style: {
1116
- ...computedPosition.tooltipArrowStyles,
1114
+ ...inlineArrowStyles,
1117
1115
  background: arrowColor
1118
1116
  ? `linear-gradient(to right bottom, transparent 50%, ${arrowColor} 50%)`
1119
1117
  : undefined,
@@ -1348,7 +1346,8 @@ const TooltipController = React.forwardRef(({ id, anchorId, anchorSelect, conten
1348
1346
  let renderedContent = children;
1349
1347
  const contentWrapperRef = useRef(null);
1350
1348
  if (render) {
1351
- const rendered = render({ content: tooltipContent !== null && tooltipContent !== void 0 ? tooltipContent : null, activeAnchor });
1349
+ const actualContent = (activeAnchor === null || activeAnchor === void 0 ? void 0 : activeAnchor.getAttribute('data-tooltip-content')) || tooltipContent || null;
1350
+ const rendered = render({ content: actualContent, activeAnchor });
1352
1351
  renderedContent = rendered ? (React.createElement("div", { ref: contentWrapperRef, className: "react-tooltip-content-wrapper" }, rendered)) : null;
1353
1352
  }
1354
1353
  else if (tooltipContent) {