o
    h                     @   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                   @   sN   e Zd ZdZdZddedee ddfddZded	e	d
ee
 def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eltNr   optionsreturnc                 C   sr   || _ d | _|r,|j| _|j| _| jrt| jni }|j|d|d< t| j|| _	d S d | _d | _t | _	d S )N)r   r   block)
r   r   wrapperr   wrapper_propsr   dictr   create_elementr   )selfr   r   r    r   ^/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/draftjs_exporter/wrapper_state.py__init__   s   zWrapper.__init__type_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_differentr    )__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ZdefddZdefd	d
Z	de
ddfddZdede
fddZdeddfddZde
fddZde
f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.
    stackr   Nc                 C   s
   g | _ d S r    r*   r   r   r   r   r   2      
zWrapperStack.__init__c                 C   
   t | jS r    )strr*   r,   r   r   r   __str__5   r-   zWrapperStack.__str__c                 C   r.   r    )lenr*   r,   r   r   r   length8   r-   zWrapperStack.lengthr   c                 C   s   | j |S r    )r*   appendr   r   r   r   r   r3   ;   s   zWrapperStack.appendindexc                 C   s
   | j | S r    r+   )r   r5   r   r   r   get>   r-   zWrapperStack.getr2   c                 C   s   | j d | | _ d S r    r+   )r   r2   r   r   r   sliceA   s   zWrapperStack.slicec                 C   s&   |   dkr| jd }|S td}|S )Nr   )r2   r*   r   r4   r   r   r   headD   s
   
zWrapperStack.headc                 C   s
   | j d S )Nr   r+   r,   r   r   r   tailL   r-   zWrapperStack.tail)r   N)r"   r#   r$   r%   r&   r   r/   r0   r'   r2   r   r3   r6   r7   r9   r:   r   r   r   r   r)   )   s    
r)   c                   @   s   e Zd ZdZdZdedee ddfddZde	fd	d
Z
dedeeee f defddZdedededefddZdededefddZdededdf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*   r<   r=   r   Nc                 C   s   || _ || _t | _d S r    )r<   r=   r)   r*   )r   r<   r=   r   r   r   r   Y   s   zWrapperState.__init__c                 C   s   d| j  dS )Nz<WrapperState: >r+   r,   r   r   r   r0   ^   s   zWrapperState.__str__r   block_contentc           	      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   unstyledr   r   r   r=   )r   r6   r<   r   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_forr   r   r   c                 C   sN   |j r| ||}t|| || jjd _|S | j dkr#t | _|}|S )Nr8   r   )r   get_wrapper_eltr   append_childr*   r   r2   r)   )r   r   r   r   rD   r   r   r   rC   r   s   zWrapperState.parent_forc                 C   sP   | j  }|||j|jr| || ||jk r!| j |d  | j |j	S )N   )
r*   r9   r!   r   r   update_stackr   r7   r6   r   )r   r   r   r9   r   r   r   rF      s   

zWrapperState.get_wrapper_eltc                 C   s   || j  kr]t| j  |d }|D ]G}t||}| j  jd u rGt|j}|j|i d|d< | j	|d< t
|j|}t
| j  j| n| j  j}t
||j | j | qd S | j | | j t|| d S )NrH   )r   r   datar   r=   )r*   r2   ranger   r9   r   r   r   r   r=   r   r   rB   rG   r   r3   r7   )r   r   r   depth_levelslevelnew_wrapperr   wrapper_parentr   r   r   rI      s&   



zWrapperState.update_stack)r"   r#   r$   r%   r&   r	   r   r
   r   r/   r0   r   r   rE   r   r'   rC   rF   rI   r   r   r   r   r;   P   s    
r;   N)typingr   r   r   r   draftjs_exporter.constantsr   draftjs_exporter.domr   draftjs_exporter.optionsr   r	   draftjs_exporter.typesr
   r   r   r   r   r)   r;   r   r   r   r   <module>   s     '