diff --git a/web/utils/tooltip-action-utils.js b/web/utils/tooltip-action-utils.js --- a/web/utils/tooltip-action-utils.js +++ b/web/utils/tooltip-action-utils.js @@ -21,16 +21,13 @@ import { type MessageTooltipAction, - findTooltipPosition, - getTooltipStyle, + getTooltipPositionStyle, calculateTooltipSize, - type TooltipSize, type TooltipPosition, } from './tooltip-utils.js'; import { getComposedMessageID } from '../chat/chat-constants.js'; import { useEditModalContext } from '../chat/edit-message-provider.js'; import MessageTooltip from '../chat/message-tooltip.react.js'; -import type { PositionInfo } from '../chat/position-types.js'; import { useTooltipContext } from '../chat/tooltip-provider.js'; import CommIcon from '../CommIcon.react.js'; import { InputStateContext } from '../input/input-state.js'; @@ -305,43 +302,6 @@ onMouseLeave: ?() => mixed, }; -type GetTooltipPositionStyleParams = { - +tooltipSourcePosition: ?PositionInfo, - +tooltipSize: TooltipSize, - +availablePositions: $ReadOnlyArray, - +preventDisplayingBelowSource?: boolean, -}; - -function getTooltipPositionStyle(params: GetTooltipPositionStyleParams) { - const { - tooltipSourcePosition, - tooltipSize, - availablePositions, - preventDisplayingBelowSource, - } = params; - if (!tooltipSourcePosition) { - return undefined; - } - const tooltipPosition = findTooltipPosition({ - sourcePositionInfo: tooltipSourcePosition, - tooltipSize, - availablePositions, - defaultPosition: availablePositions[0], - preventDisplayingBelowSource, - }); - if (!tooltipPosition) { - return undefined; - } - - const tooltipPositionStyle = getTooltipStyle({ - tooltipPosition, - sourcePositionInfo: tooltipSourcePosition, - tooltipSize, - }); - - return tooltipPositionStyle; -} - function useMessageTooltip({ availablePositions, item, diff --git a/web/utils/tooltip-utils.js b/web/utils/tooltip-utils.js --- a/web/utils/tooltip-utils.js +++ b/web/utils/tooltip-utils.js @@ -283,6 +283,45 @@ invariant(false, `Unexpected tooltip position value: ${tooltipPosition}`); } +type GetTooltipPositionStyleParams = { + +tooltipSourcePosition: ?PositionInfo, + +tooltipSize: TooltipSize, + +availablePositions: $ReadOnlyArray, + +preventDisplayingBelowSource?: boolean, +}; + +function getTooltipPositionStyle( + params: GetTooltipPositionStyleParams, +): ?TooltipPositionStyle { + const { + tooltipSourcePosition, + tooltipSize, + availablePositions, + preventDisplayingBelowSource, + } = params; + if (!tooltipSourcePosition) { + return undefined; + } + const tooltipPosition = findTooltipPosition({ + sourcePositionInfo: tooltipSourcePosition, + tooltipSize, + availablePositions, + defaultPosition: availablePositions[0], + preventDisplayingBelowSource, + }); + if (!tooltipPosition) { + return undefined; + } + + const tooltipPositionStyle = getTooltipStyle({ + tooltipPosition, + sourcePositionInfo: tooltipSourcePosition, + tooltipSize, + }); + + return tooltipPositionStyle; +} + type CalculateTooltipSizeArgs = { +tooltipLabels: $ReadOnlyArray, +timestamp: string, @@ -317,4 +356,4 @@ }; } -export { findTooltipPosition, calculateTooltipSize, getTooltipStyle }; +export { findTooltipPosition, getTooltipPositionStyle, calculateTooltipSize };