import { useEffect, useState } from 'react'; import type { InsertPayload } from './types'; import { extractVoltaxContentId, isAllowedShortcodeInput, resolveShortcodeInput } from './utils'; type ShortcodeTabProps = { onSelect: ( payload: InsertPayload | null ) => void; }; export function ShortcodeTab( { onSelect }: ShortcodeTabProps ) { const config = window.voltaxModalConfig!; // Inject-only: never prefill from an existing selection. const [ value, setValue ] = useState( '' ); const trimmed = value.trim(); const isInvalid = trimmed.length > 0 && ! isAllowedShortcodeInput( value ); useEffect( () => { const shortcode = resolveShortcodeInput( value ); if ( ! shortcode ) { onSelect( null ); return; } const contentId = extractVoltaxContentId( shortcode ); onSelect( { shortcode, // Only set id for Voltax/mm-video content IDs — STN keys stay shortcode-only. id: contentId, type: contentId ? 'video' : undefined, title: contentId || shortcode, } ); }, [ value, onSelect ] ); return (
setValue( event.target.value ) } />
{ isInvalid ? ({ config.i18n.invalidShortcode }
) : null }{ config.i18n.shortcodeHelp }