a
    Cg                     @   s   d dl mZmZmZmZ d dlmZ d dlmZ d dl	m
Z
mZ d dlmZmZmZmZ G dd dZG dd	 d	ZG d
d dZdS )    )ListOptionalSequenceUnion)BLOCK_TYPES)DOM)Options
OptionsMap)BlockElementPropsRenderableTypec                   @   sD   e Zd ZdZdZd
eee ddddZee	ee
 eddd	ZdS )Wrapperz
    A wrapper is an element that wraps other nodes. It gets created
    when the depth of a block is different than 0, so the DOM elements
    have the appropriate amount of nesting.
    )depth
last_childtypepropseltN)r   optionsreturnc                 C   sp   || _ d | _|rV|j| _|j| _| jr0t| jni }|j|d|d< t| j|| _	nd | _d | _t | _	d S )N)r   r   block)
r   r   wrapperr   wrapper_propsr   dictr   create_elementr   )selfr   r   r    r   ]/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/draftjs_exporter/wrapper_state.py__init__   s    zWrapper.__init__)r   type_r   r   c                 C   s   || j kp|| jkp|| jkS N)r   r   r   )r   r   r   r   r   r   r   is_different#   s    zWrapper.is_different)N)__name__
__module____qualname____doc__	__slots__intr   r   r   r   r   boolr!   r   r   r   r   r   	   s   
r   c                   @   s   e Zd ZdZdZddddZedddZedd	d
Z	e
ddddZee
dddZeddddZe
dddZe
dddZdS )WrapperStackz
    Stack data structure for element wrappers.
    The bottom of the stack contains the elements closest to the page body.
    The top of the stack contains the most nested nodes.
    stackNr   c                 C   s
   g | _ d S r    r*   r   r   r   r   r   2   s    zWrapperStack.__init__c                 C   s
   t | jS r    )strr*   r-   r   r   r   __str__5   s    zWrapperStack.__str__c                 C   s
   t | jS r    )lenr*   r-   r   r   r   length8   s    zWrapperStack.length)r   r   c                 C   s   | j |S r    )r*   appendr   r   r   r   r   r2   ;   s    zWrapperStack.append)indexr   c                 C   s
   | j | S r    r,   )r   r4   r   r   r   get>   s    zWrapperStack.get)r1   r   c                 C   s   | j d | | _ d S r    r,   )r   r1   r   r   r   sliceA   s    zWrapperStack.slicec                 C   s$   |   dkr| jd }ntd}|S )Nr   )r1   r*   r   r3   r   r   r   headD   s    zWrapperStack.headc                 C   s
   | j d S )Nr   r,   r-   r   r   r   tailL   s    zWrapperStack.tail)r"   r#   r$   r%   r&   r   r.   r/   r'   r1   r   r2   r5   r6   r8   r9   r   r   r   r   r)   )   s   r)   c                   @   s   e Zd ZdZdZeee ddddZe	ddd	Z
eeeee f ed
ddZeeeedddZeeedddZeeddddZdS )WrapperStatez
    This class does the initial node building for the tree.
    It sets elements with the right tag, text content, and props.
    It adds a wrapper element around elements, if required.
    )block_optionsblocksr*   N)r;   r<   r   c                 C   s   || _ || _t | _d S r    )r;   r<   r)   r*   )r   r;   r<   r   r   r   r   Y   s    zWrapperState.__init__r+   c                 C   s   d| j  dS )Nz<WrapperState: >r,   r-   r   r   r   r/   ^   s    zWrapperState.__str__)r   block_contentr   c           	      C   sx   d|v r|d nd}d|v r$|d nd}t | j|tj}t|j}||d< | j|d< t	|j
||}| |||}|S )Nr   Zunstyledr   r   r   r<   )r   r5   r;   r   ZFALLBACKr   r   r<   r   r   element
parent_for)	r   r   r>   r   r   r   r   r   parentr   r   r   element_fora   s    

zWrapperState.element_for)r   r   r   r   c                 C   sL   |j r.| ||}t|| || jjd _n| j dkrDt | _|}|S )Nr7   r   )r   get_wrapper_eltr   append_childr*   r   r1   r)   )r   r   r   r   rA   r   r   r   r@   r   s    zWrapperState.parent_for)r   r   r   c                 C   sP   | j  }|||j|jr(| || ||jk rB| j |d  | j |j	S )N   )
r*   r8   r!   r   r   update_stackr   r6   r5   r   )r   r   r   r8   r   r   r   rC      s    

zWrapperState.get_wrapper_eltc                 C   s   || j  krt| j  |d }|D ]}t||}| j  jd u rt|j}|j|i d|d< | j	|d< t
|j|}t
| j  j| n| j  j}t
||j | j | q&n| j | | j t|| d S )NrE   )r   r   datar   r<   )r*   r1   ranger   r8   r   r   r   r   r<   r   r   r?   rD   r   r2   r6   )r   r   r   Zdepth_levelslevelZnew_wrapperr   Zwrapper_parentr   r   r   rF      s$    



zWrapperState.update_stack)r"   r#   r$   r%   r&   r	   r   r
   r   r.   r/   r   r   rB   r   r'   r@   rC   rF   r   r   r   r   r:   P   s   r:   N)typingr   r   r   r   Zdraftjs_exporter.constantsr   Zdraftjs_exporter.domr   Zdraftjs_exporter.optionsr   r	   Zdraftjs_exporter.typesr
   r   r   r   r   r)   r:   r   r   r   r   <module>   s    '