import * as React from 'react'; import { api } from '@renderer/api'; import { calculateInlineMatchPositions } from '@renderer/utils/chipUtils'; import { findUrlMatches } from '@renderer/utils/urlMatchUtils'; import { X } from 'lucide-react'; import type { InlineMatchPosition } from '@renderer/utils/chipUtils'; import type { TextMatch } from '@renderer/utils/urlMatchUtils'; interface UrlInteractionLayerProps { value: string; textareaRef: React.RefObject; scrollTop: number; onRemove: (match: TextMatch) => void; } type PositionedUrlReference = InlineMatchPosition; export const UrlInteractionLayer = ({ value, textareaRef, scrollTop, onRemove, }: UrlInteractionLayerProps): React.JSX.Element | null => { const [positions, setPositions] = React.useState([]); React.useLayoutEffect(() => { if (!value.includes('http://') && !value.includes('https://')) { setPositions([]); return; } const textarea = textareaRef.current; if (!textarea) return; const matches = findUrlMatches(value).map((match) => ({ item: match, start: match.start, end: match.end, token: match.value, })); setPositions(calculateInlineMatchPositions(textarea, value, matches)); }, [textareaRef, value]); if (positions.length === 0) return null; return (
{positions.map((position, index) => (
))}
); };