```python
def swap_keys(names: dict) -> dict:
    """
    Given a mapping of names to codes, return the mapping from each code to a name.
    When two names share one code, the name that sorts first is kept. A name whose code is empty text is left out altogether.
    
    :param names: Mapping of names to codes
    :return: Mapping of codes to names
    """
    if not names:
        return {}
    
    # Create a dictionary to store the swapped mappings
    swapped_names = {}
    
    # Iterate over each name and code in the input dictionary
    for name, code in names.items():
        # Skip empty text codes
        if not code:
            continue
        
        # If the code is already in the swapped_names dictionary, compare the names
        if code in swapped_names:
            existing_name = swapped_names[code]
            # Sort the names and keep the one that sorts first
            if name < existing_name:
                swapped_names[code] = name
        else:
            # Add the new mapping to the swapped_names dictionary
            swapped_names[code] = name
    
    return swapped_names
```