import * as React from 'react'; import { Tooltip, TooltipContent, TooltipTrigger } from '@renderer/components/ui/tooltip'; import { calculateInlineMatchPositions } from '@renderer/utils/chipUtils'; import type { KnownSlashCommandDefinition, ParsedStandaloneSlashCommand, } from '@shared/utils/slashCommands'; interface SlashCommandInteractionLayerProps { command: ParsedStandaloneSlashCommand; definition: KnownSlashCommandDefinition | null; value: string; textareaRef: React.RefObject; scrollTop: number; } export const SlashCommandInteractionLayer = ({ command, definition, value, textareaRef, scrollTop, }: SlashCommandInteractionLayerProps): React.JSX.Element | null => { const [position, setPosition] = React.useState<{ top: number; left: number; width: number; height: number; } | null>(null); React.useLayoutEffect(() => { const textarea = textareaRef.current; if (!textarea) return; const [match] = calculateInlineMatchPositions(textarea, value, [ { item: command, start: command.startIndex, end: command.endIndex, token: command.raw, }, ]); if (!match) { setPosition(null); return; } setPosition({ top: match.top, left: match.left, width: match.width, height: match.height, }); }, [command, textareaRef, value]); if (!definition || !position) return null; return (
{definition.command}
{definition.description}
); };