""" Textbox Layout Supports enhanced rationale/justification features: - min_chars: Minimum character count with counter display - show_char_count: Show character counter below textarea - collapsible: Start collapsed, expand on click - target_schema: Visual grouping with a preceding schema - placeholder: Placeholder text in the input """ import logging from potato.ai.ai_help_wrapper import get_ai_wrapper, get_dynamic_ai_help from .identifier_utils import ( safe_generate_layout, generate_element_identifier, generate_validation_attribute, escape_html_content, generate_layout_attributes ) logger = logging.getLogger(__name__) def generate_textbox_layout(annotation_scheme): """ Generate HTML for a textbox input interface. Args: annotation_scheme (dict): Configuration including: - name: Schema identifier - description: Display description - labels: Optional list of labels for multiple textboxes - label_requirement (dict): Optional validation settings - required (bool): Whether input is mandatory - textarea (dict): Optional textarea configuration - on (bool): Whether to use textarea instead of input - rows (int): Number of rows for textarea - cols (int): Number of columns for textarea - allow_paste (bool): Whether to allow pasting text - custom_css (dict): Optional CSS styling - min_chars (int): Minimum characters required - show_char_count (bool): Show character counter - collapsible (bool): Start collapsed, expand on click - target_schema (str): Name of schema this is a rationale for - placeholder (str): Placeholder text Returns: tuple: (html_string, key_bindings) html_string: Complete HTML for the textbox interface key_bindings: Empty list (no keyboard shortcuts) """ return safe_generate_layout(annotation_scheme, _generate_textbox_layout_internal) def _generate_textbox_layout_internal(annotation_scheme): """ Internal function to generate textbox layout after validation. """ logger.debug(f"Generating textbox layout for schema: {annotation_scheme['name']}") # Layout attributes for grid positioning layout_attrs = generate_layout_attributes(annotation_scheme) # Enhanced features min_chars = annotation_scheme.get("min_chars", 0) show_char_count = annotation_scheme.get("show_char_count", False) collapsible = annotation_scheme.get("collapsible", False) target_schema = annotation_scheme.get("target_schema", "") placeholder = escape_html_content(annotation_scheme.get("placeholder", "")) # CSS classes for target_schema grouping target_class = "shadcn-textbox-target-grouped" if target_schema else "" # Initialize form wrapper schema_name = annotation_scheme['name'] schematic = f"""
" logger.debug(f"Generated textbox schematic for {annotation_scheme['name']}") logger.info(f"Successfully generated textbox layout for {annotation_scheme['name']} with {len(labels)} fields") return schematic, []