a
    Df/                     @  s~   d dl mZ d dlmZmZmZ d dlZddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZ d	d
lmZ G dd deeZdS )    )annotations)ClassVarListMappingN   )config)CDN_DISTbundled_files)ReactiveHTML)classproperty   )GridSpecc                   @  s0  e Zd ZU dZejdddZejdddZejddZ	ej
dd	Zej
dd	Zd
ZdZddddddddZej dej dgZej dgZd
ej did
d id
dd iidZddddZded< e d gZd!ed"< ed#d$ Zed%d& Zed'd( Zejd)dd*d+d, Zejddd*d-d. ZdS )/	GridStacka~  
    The `GridStack` layout allows arranging multiple Panel objects in a grid
    using a simple API to assign objects to individual grid cells or to a grid
    span.

    Other layout containers function like lists, but a `GridSpec` has an API
    similar to a 2D array, making it possible to use 2D assignment to populate,
    index, and slice the grid.

    Reference: https://panel.holoviz.org/reference/layouts/GridStack.html

    :Example:

    >>> pn.extension('gridstack')
    >>> gstack = GridStack(sizing_mode='stretch_both')
    >>> gstack[ : , 0: 3] = pn.Spacer(styles=dict(background='red'))
    >>> gstack[0:2, 3: 9] = pn.Spacer(styles=dict(background='green'))
    >>> gstack[2:4, 6:12] = pn.Spacer(styles=dict(background='orange'))
    >>> gstack[4:6, 3:12] = pn.Spacer(styles=dict(background='blue'))
    >>> gstack[0:2, 9:12] = pn.Spacer(styles=dict(background='purple'))
    Tz'
        Allow resizing the grid cells.)defaultdocz'
        Allow dragging the grid cells.zV
        Current state of the grid (updated as items are resized and
        dragged).)r   N)r   Z	gridstacka  
    <div id="grid" class="grid-stack" style="width: 100%; height: 100%">
    {% for key, obj in objects.items() %}
      <div data-id="{{ id(obj) }}" class="grid-stack-item" gs-h="{{ (key[2] or nrows)-(key[0] or 0) }}" gs-w="{{ (key[3] or ncols)-(key[1] or 0) }}" gs-y="{{ (key[0] or 0) }}" gs-x="{{ (key[1] or 0) }}">
        <div id="content" class="grid-stack-item-content">${obj}</div>
      </div>
    {% endfor %}
    </div>
    a  
        const options = {
          column: data.ncols,
          disableResize: !data.allow_resize,
          disableDrag: !data.allow_drag,
          margin: 0
        }
        if (data.nrows) {
          options.row = data.nrows
          const height = model.height || grid.offsetHeight;
          options.cellHeight = Math.floor(height/data.nrows);
        }
        const gridstack = GridStack.init(options, grid);
        function sync_state(load=false) {
          const items = []
          for (const node of gridstack.engine.nodes) {
            items.push({id: node.el.getAttribute('data-id'), x0: node.x, y0: node.y, x1: node.x+node.w, y1: node.y+node.h})
          }
          data.state = items
        }
        gridstack.on('resizestop', (event, el) => {
          sync_state()
          view.invalidate_layout()
        })
        gridstack.on('dragstop', (event, el) => {
          sync_state()
        })
        sync_state()
        state.gridstack = gridstack
        state.init = false
        z
        self.nrows()
        if (!state.init) {
          state.init = true
          view.invalidate_layout()
        }
        state.gridstack.engine._notify()
        z+state.gridstack.enableMove(data.allow_drag)z/state.gridstack.enableResize(data.allow_resize)z"state.gridstack.column(data.ncols)a-  
        state.gridstack.opts.row = data.nrows
        if (data.nrows) {
          const height = model.height || grid.offsetHeight || model.min_height;
          state.gridstack.cellHeight(Math.floor(height/data.nrows))
        } else {
          state.gridstack.cellHeight('auto')
        }
        zstate.gridstack.destroy())renderZafter_layout
allow_dragallow_resizencolsnrowsremovez'/gridstack@7.2.3/dist/gridstack.min.cssz-/gridstack@7.2.3/dist/gridstack-extra.min.cssz&/gridstack@7.2.3/dist/gridstack-all.jsz#/gridstack@7.2.3/dist/gridstack-allexports)pathsr   shimr   r   objects)r   r   r   z"ClassVar[Mapping[str, str | None]]_renamezcss/gridstack.csszClassVar[List[str]]_stylesheetsc                 C  s   d| j dd iS )Nr   r   r   )__javascript__cls r    c/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/panel/layout/gridstack.py__js_skip__   s    zGridStack.__js_skip__c                 C  s   t | S )Nr	   r   r    r    r!   r      s    zGridStack.__javascript__c                 C  s
   t | dS )Ncssr#   r   r    r    r!   __css__   s    zGridStack.__css__state)Zwatchc                 C  sh   i }dd | D }| j D ],}||d  ||d |d |d |d f< q| j  | j| |   d S )Nc                 S  s   i | ]}t t||qS r    )strid).0objr    r    r!   
<dictcomp>       z-GridStack._update_objects.<locals>.<dictcomp>r(   y0x0y1x1)r&   r   clearupdate_update_sizing)selfr   Z
object_idspr    r    r!   _update_objects   s    
*
zGridStack._update_objectsc           
        s`  | j r| jr| j| j  }nd}| jr8| jr8| j| j }nd}| j D ]\\}}}} |d u rddn|}|d u rv| j n|}|d u rdn|}|d u r| jn|}|| ||  }}i }	| jdv r|rt|| |	d< |rt|| |	d< nP| j|	d< d| jv r|rt|| |	d< n"d| jv r6|r6t|| |	d<  jj	f i  fdd|	 D  qFd S )Nr   )fixedNwidthheightsizing_modec                   s"   i | ]\}} j | js||qS r    )paramreadonly)r)   kvr*   r    r!   r+      s   z,GridStack._update_sizing.<locals>.<dictcomp>)
r   r8   r   r9   r   itemsr:   intr;   r2   )
r4   r8   r9   r-   r.   r/   r0   hwZ
propertiesr    r?   r!   r3      s4    

zGridStack._update_sizing) __name__
__module____qualname____doc__r;   Booleanr   r   r   r&   ZIntegerr8   r9   Z_extension_name	_templateZ_scriptsr   Znpm_cdnZ__css_raw__Z__javascript_raw__Z__js_require__r   __annotations__r   r   r   r"   r   r%   dependsr6   r3   r    r    r    r!   r      sX   
	8






	r   )
__future__r   typingr   r   r   r;   r   Zio.resourcesr   r	   Zreactiver
   utilr   Zgridr   r   r    r    r    r!   <module>   s   