@geomak/ui 7.17.0 → 7.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -5056,12 +5056,52 @@ function useTargetBbox(ref) {
5056
5056
  }
5057
5057
  var TOOLTIP_WIDTH = 280;
5058
5058
  var TOOLTIP_GAP = 12;
5059
- function tooltipStyleFor(bbox, placement) {
5060
- const pl = placement ?? "right";
5061
- if (pl === "right") return { left: bbox.right + TOOLTIP_GAP, top: bbox.top + bbox.height / 2, transform: "translateY(-50%)", width: TOOLTIP_WIDTH };
5062
- if (pl === "left") return { left: bbox.left - TOOLTIP_WIDTH - TOOLTIP_GAP, top: bbox.top + bbox.height / 2, transform: "translateY(-50%)", width: TOOLTIP_WIDTH };
5063
- if (pl === "bottom") return { left: bbox.left + bbox.width / 2, top: bbox.bottom + TOOLTIP_GAP, transform: "translateX(-50%)", width: TOOLTIP_WIDTH };
5064
- return { left: bbox.left + bbox.width / 2, top: bbox.top - TOOLTIP_GAP, transform: "translate(-50%, -100%)", width: TOOLTIP_WIDTH };
5059
+ function tooltipStyleFor(bbox, placement, tooltipHeight) {
5060
+ const GAP2 = TOOLTIP_GAP;
5061
+ const W = TOOLTIP_WIDTH;
5062
+ const H = tooltipHeight;
5063
+ const vw = window.innerWidth;
5064
+ const vh = window.innerHeight;
5065
+ let side = placement ?? "right";
5066
+ if (side === "right" && bbox.right + GAP2 + W > vw) side = "left";
5067
+ if (side === "left" && bbox.left - W - GAP2 < 0) side = "right";
5068
+ if (side === "bottom" && bbox.bottom + GAP2 + H > vh) side = "top";
5069
+ if (side === "top" && bbox.top - GAP2 - H < 0) side = "bottom";
5070
+ let left;
5071
+ let top;
5072
+ let transform;
5073
+ if (side === "right") {
5074
+ left = bbox.right + GAP2;
5075
+ top = bbox.top + bbox.height / 2;
5076
+ transform = "translateY(-50%)";
5077
+ } else if (side === "left") {
5078
+ left = bbox.left - W - GAP2;
5079
+ top = bbox.top + bbox.height / 2;
5080
+ transform = "translateY(-50%)";
5081
+ } else if (side === "bottom") {
5082
+ left = bbox.left + bbox.width / 2;
5083
+ top = bbox.bottom + GAP2;
5084
+ transform = "translateX(-50%)";
5085
+ } else {
5086
+ left = bbox.left + bbox.width / 2;
5087
+ top = bbox.top - GAP2;
5088
+ transform = "translate(-50%, -100%)";
5089
+ }
5090
+ if (side === "top" || side === "bottom") {
5091
+ left = Math.max(GAP2 + W / 2, Math.min(left, vw - W / 2 - GAP2));
5092
+ } else {
5093
+ left = Math.max(GAP2, Math.min(left, vw - W - GAP2));
5094
+ }
5095
+ if (H > 0) {
5096
+ if (side === "right" || side === "left") {
5097
+ top = Math.max(GAP2 + H / 2, Math.min(top, vh - GAP2 - H / 2));
5098
+ } else if (side === "bottom") {
5099
+ top = Math.max(GAP2, Math.min(top, vh - GAP2 - H));
5100
+ } else {
5101
+ top = Math.max(GAP2 + H, Math.min(top, vh - GAP2));
5102
+ }
5103
+ }
5104
+ return { left, top, transform, width: W };
5065
5105
  }
5066
5106
  function useFocusTrap(containerRef, active) {
5067
5107
  useEffect(() => {
@@ -5109,6 +5149,11 @@ function Wizard({
5109
5149
  const reduced = useReducedMotion();
5110
5150
  const [open, setOpen] = useState(() => steps.length > 0 && !readDismissed(storageKey));
5111
5151
  const [activeIndex, setActiveIndex] = useState(0);
5152
+ const [tooltipHeight, setTooltipHeight] = useState(0);
5153
+ useLayoutEffect(() => {
5154
+ const h = tooltipRef.current?.offsetHeight ?? 0;
5155
+ if (h > 0) setTooltipHeight((prev) => prev === h ? prev : h);
5156
+ }, [activeIndex, open]);
5112
5157
  const step = steps[activeIndex];
5113
5158
  const bbox = useTargetBbox(step?.stepRef);
5114
5159
  useFocusTrap(tooltipRef, open);
@@ -5161,7 +5206,7 @@ function Wizard({
5161
5206
  right: 0,
5162
5207
  height: bbox.height + SPOT_PAD * 2
5163
5208
  } : { display: "none" };
5164
- const tooltipStyle = bbox ? tooltipStyleFor(bbox, step?.placement) : { display: "none" };
5209
+ const tooltipStyle = bbox ? tooltipStyleFor(bbox, step?.placement, tooltipHeight) : { display: "none" };
5165
5210
  const isLast = activeIndex === steps.length - 1;
5166
5211
  return /* @__PURE__ */ jsxs(Fragment, { children: [
5167
5212
  children,