a
    Cgh                     @   s   d dl mZmZ d dlmZmZ d dlmZ d dlm	Z	 er`d dl m
Z
 d dlmZ d dlmZ G dd	 d	ed
ZG dd dee	 ZdS )    )TYPE_CHECKINGList)MediaMediaDefiningClass)get_template)HasMediaProperty)Optional)
SafeString)RenderContextc                   @   sT   e Zd ZU dZeed< ddddddZddddd	d
ZerPe	e
dddZdS )	Componenta  
    A class that knows how to render itself.

    Extracted from Wagtail. See:
    https://github.com/wagtail/wagtail/blob/094834909d5c4b48517fd2703eb1f6d386572ffa/wagtail/admin/ui/components.py#L8-L22  # noqa: E501

    A component uses the `MetaDefiningClass` metaclass to add a `media` property, which
    allows the definitions of CSS and JavaScript assets that are associated with the
    component. This works the same as `Media` class used by Django forms.
    See also: https://docs.djangoproject.com/en/4.2/topics/forms/media/
    template_nameNzOptional[RenderContext]r	   )parent_contextreturnc                 C   s   |  |}t| j}||S )a  
        Return string representation of the object.

        Given a context dictionary from the calling template (which may be a
        `django.template.Context` object or a plain `dict` of context variables),
        returns the string representation to be rendered.

        This will be subject to Django's HTML escaping rules, so a return value
        consisting of HTML should typically be returned as a
        `django.utils.safestring.SafeString` instance.
        )get_context_datar   r   render)selfr   Zcontext_datatemplate r   O/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/laces/components.pyrender_html    s    

zComponent.render_htmlc                 C   s   i S )z6Return the context data to render this component with.r   )r   r   r   r   r   r   3   s    zComponent.get_context_datar   c                 C   s   d S )Nr   )r   r   r   r   mediaB   s    zComponent.media)N)N)__name__
__module____qualname____doc__str__annotations__r   r   r   propertyr   r   r   r   r   r   r      s   
  r   )	metaclassc                   @   s"   e Zd ZdZeedddZdS )MediaContainera  
    A list that provides a `media` property that combines the media definitions
    of its members.

    Extracted from Wagtail. See:
    https://github.com/wagtail/wagtail/blob/ca8a87077b82e20397e5a5b80154d923995e6ca9/wagtail/admin/ui/components.py#L25-L36  # noqa: E501

    The `MediaContainer` functionality depends on the `django.forms.widgets.Media`
    class. The `Media` class provides the logic to combine the media definitions of
    multiple objects through its `__add__` method. The `MediaContainer` relies on this
    functionality to provide a `media` property that combines the media definitions of
    its members.

    See also:
    https://docs.djangoproject.com/en/4.2/topics/forms/media
    r   c                 C   s   t  }| D ]}||j7 }q
|S )z
        Return a `Media` object containing the media definitions of all members.

        This makes use of the `Media.__add__` method, which combines the media
        definitions of two `Media` objects.

        )r   r   )r   r   itemr   r   r   r   Y   s    	zMediaContainer.mediaN)r   r   r   r   r   r   r   r   r   r   r   r    G   s   r    N)typingr   r   Zdjango.forms.widgetsr   r   Zdjango.template.loaderr   Zlaces.typingr   r   Zdjango.utils.safestringr	   r
   r   r    r   r   r   r   <module>   s   6